-
Notifications
You must be signed in to change notification settings - Fork 22
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: generate sharded DAG index on client and invoke w index/add
#1451
Merged
Merged
Changes from all commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
10e4dc3
feat: generate sharded DAG index on client and invoke w `index/add`
6d691de
fix: w3up-client dependency
3844083
fix: use blob-index in upload-client
888ab77
fix: more dependency fix
46c924e
chore: fml lint
8cc4017
feat: integrate in w3up-client
f78abb6
Merge branch 'main' into feat/generate-sharded-dag-index-in-client
948959d
fix: exports
047cd3b
Merge branch 'feat/generate-sharded-dag-index-in-client' of github.co…
e272d97
chore: appease linter
7f8ec15
refactor: apply suggestions from code review
44dbaa4
fix: add filecoin/offer delegation to invocation config where needed
5b9d184
refactor: apply suggestions from code review
750124e
chore: appease linter
efb8dfa
Merge branch 'feat/generate-sharded-dag-index-in-client' of github.co…
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
import * as IndexCapabilities from '@web3-storage/capabilities/index' | ||
import { SpaceDID } from '@web3-storage/capabilities/utils' | ||
import retry from 'p-retry' | ||
import { servicePrincipal, connection } from './service.js' | ||
import { REQUEST_RETRIES } from './constants.js' | ||
|
||
/** | ||
* Register an "index" with the service. The issuer needs the `index/add` | ||
* delegated capability. | ||
* | ||
* Required delegated capability proofs: `index/add` | ||
* | ||
* @param {import('./types.js').InvocationConfig} conf Configuration | ||
* for the UCAN invocation. An object with `issuer`, `with` and `proofs`. | ||
* | ||
* The `issuer` is the signing authority that is issuing the UCAN | ||
* invocation(s). It is typically the user _agent_. | ||
* | ||
* The `with` is the resource the invocation applies to. It is typically the | ||
* DID of a space. | ||
* | ||
* The `proofs` are a set of capability delegations that prove the issuer | ||
* has the capability to perform the action. | ||
* | ||
* The issuer needs the `index/add` delegated capability. | ||
* @param {import('./types.js').CARLink} index Index to store. | ||
* @param {import('./types.js').RequestOptions} [options] | ||
* @returns {Promise<import('./types.js').IndexAddSuccess>} | ||
*/ | ||
export async function add( | ||
{ issuer, with: resource, proofs, audience }, | ||
index, | ||
options = {} | ||
) { | ||
/* c8 ignore next */ | ||
const conn = options.connection ?? connection | ||
const result = await retry( | ||
async () => { | ||
return await IndexCapabilities.add | ||
.invoke({ | ||
issuer, | ||
/* c8 ignore next */ | ||
audience: audience ?? servicePrincipal, | ||
with: SpaceDID.from(resource), | ||
nb: { index }, | ||
proofs, | ||
}) | ||
.execute(conn) | ||
}, | ||
{ | ||
onFailedAttempt: console.warn, | ||
retries: options.retries ?? REQUEST_RETRIES, | ||
} | ||
) | ||
|
||
if (!result.out.ok) { | ||
throw new Error(`failed ${IndexCapabilities.add.can} invocation`, { | ||
cause: result.out.error, | ||
}) | ||
} | ||
|
||
return result.out.ok | ||
} |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🤦 FML this was wrong. Either it was wrong the whole time or
@ipld/car
started encoding the header differently.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: would be great to just export it from
@ipld/car