Skip to content
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: add store/get and upload/get capabilities #942

Merged
merged 15 commits into from
Oct 19, 2023
Merged

feat: add store/get and upload/get capabilities #942

merged 15 commits into from
Oct 19, 2023

Conversation

olizilla
Copy link
Contributor

@olizilla olizilla commented Oct 4, 2023

Capability definitions to allow clients to check for inclusion of cid in store shards or upload roots. Also allows client to fetch the additional properties we store. This will, for example, let a client verify all shards for an upload have been removed before removing an upload.

I'm aiming to simplify things with this PR so that we return insertedAt info on the Upload/Store ListItem types, and return the same object shape for a single object get. If this is pleasing, then I will continue in this direction and make Remove also return the same shape if it removes something

Depends on approval of the new capabilities in storacha/specs#82

TODO:

License: MIT

License: MIT
Signed-off-by: Oli Evans <[email protected]>
olizilla added a commit to storacha/specs that referenced this pull request Oct 4, 2023
These capabilities are intended for checking inclusion and allowing users to verify all the shards for an upload have been removed when removing an upload.

see also: storacha/w3up#942

License: MIT
Signed-off-by: Oli Evans <[email protected]>
Comment on lines +235 to +239
export type Store = InferInvokedCapability<typeof StoreCaps.store>
export type StoreAdd = InferInvokedCapability<typeof StoreCaps.add>
export type StoreGet = InferInvokedCapability<typeof StoreCaps.get>
export type StoreRemove = InferInvokedCapability<typeof StoreCaps.remove>
export type StoreList = InferInvokedCapability<typeof StoreCaps.list>
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Update to pull each cap off of StoreCaps to be consistent with all the other caps in this file.

@@ -271,13 +283,21 @@ export interface StoreListItem {
link: UnknownLink
size: number
origin?: UnknownLink
insertedAt: string
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

add insertedAt to StoreListItem as we already want to return this info for list usage, and it means we can re-use the type for both list and get operations.

Comment on lines +292 to +293
insertedAt: string
updatedAt: string
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add insertedAt and updatedAt props to UploadListItem. We want to share a timestamp with the user about when this upload was added, and these are the props we have. updatedAt currently means "when did we last add a shard to this upload", while insertedAt means "when did you first add a given root cid as an upload to this space."

Comment on lines 375 to 381
inspect: (link: UnknownLink) => Promise<StoreGetOk>
inspect: (link: UnknownLink) => Promise<StoreInspectOk>
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated the response type for inspect to be StoreInspectOk as StoreGet was confusing... and even more so now I'm adding a StoreGet.

License: MIT
Signed-off-by: Oli Evans <[email protected]>
License: MIT
Signed-off-by: Oli Evans <[email protected]>
Comment on lines -75 to +74
const item = await context.testStoreTable.get(spaceDid, link)
const item = await context.storeTable.get(spaceDid, link)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

storeTable.get is now a thing, so we no longer need the testStoreTable.

Comment on lines -83 to -86
space: item.space,
link: item.link.toString(),
size: item.size,
issuer: item.issuer,
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i don't think we need to test things here that are not part of the contract

License: MIT
Signed-off-by: Oli Evans <[email protected]>
@olizilla olizilla marked this pull request as ready for review October 17, 2023 14:15
packages/capabilities/src/store.js Outdated Show resolved Hide resolved
/**
* shard CID to fetch info about.
*/
link: Link.optional(),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if this should be derivable from store/add (similar to space/info)? i.e. if you were able to store/add you should be able to derive store/get capability for the same link.

https://github.com/web3-storage/ucanto/blob/43ea497ca2200f9e1e15dbbdd033ec24895edb7d/packages/interface/src/capability.ts#L122-L126

Perhaps not, write does not imply read...just thinking out loud.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is interesting point, but i'm gonna leave it separate for now.

packages/capabilities/src/types.ts Show resolved Hide resolved
packages/upload-api/src/store/get.js Outdated Show resolved Hide resolved
packages/upload-api/src/types.ts Outdated Show resolved Hide resolved
packages/upload-api/src/upload/get.js Outdated Show resolved Hide resolved
Copy link
Member

@alanshaw alanshaw left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@olizilla olizilla merged commit 40c79eb into main Oct 19, 2023
8 checks passed
@olizilla olizilla deleted the get-caps branch October 19, 2023 10:29
olizilla pushed a commit that referenced this pull request Oct 19, 2023
🤖 I have created a release *beep* *boop*
---


##
[10.2.0](capabilities-v10.1.0...capabilities-v10.2.0)
(2023-10-19)


### Features

* add `store/get` and `upload/get` capabilities
([#942](#942))
([40c79eb](40c79eb))

---
This PR was generated with [Release
Please](https://github.com/googleapis/release-please). See
[documentation](https://github.com/googleapis/release-please#release-please).
travis pushed a commit that referenced this pull request Oct 20, 2023
🤖 I have created a release *beep* *boop*
---


##
[10.1.0](upload-client-v10.0.1...upload-client-v10.1.0)
(2023-10-20)


### Features

* add `store/get` and `upload/get` capabilities
([#942](#942))
([40c79eb](40c79eb))

---
This PR was generated with [Release
Please](https://github.com/googleapis/release-please). See
[documentation](https://github.com/googleapis/release-please#release-please).
travis added a commit that referenced this pull request Oct 20, 2023
🤖 I have created a release *beep* *boop*
---


##
[9.2.0](w3up-client-v9.1.0...w3up-client-v9.2.0)
(2023-10-20)


### Features

* add `store/get` and `upload/get` capabilities
([#942](#942))
([40c79eb](40c79eb))

---
This PR was generated with [Release
Please](https://github.com/googleapis/release-please). See
[documentation](https://github.com/googleapis/release-please#release-please).

Co-authored-by: Travis Vachon <[email protected]>
olizilla added a commit that referenced this pull request Oct 23, 2023
🤖 I have created a release *beep* *boop*
---


##
[6.2.0](upload-api-v6.1.0...upload-api-v6.2.0)
(2023-10-20)


### Features

* add `store/get` and `upload/get` capabilities
([#942](#942))
([40c79eb](40c79eb))

---
This PR was generated with [Release
Please](https://github.com/googleapis/release-please). See
[documentation](https://github.com/googleapis/release-please#release-please).

Co-authored-by: Oli Evans <[email protected]>
olizilla added a commit to storacha/specs that referenced this pull request Dec 18, 2023
These capabilities are intended for checking inclusion, or getting the
additional properties we store. This will allow clients to verify all
the shards for an upload have been removed before removing an upload.

## `store/get` delegation

```js
{
  can: "store/get",
  with: "did:key:abc...",
  nb: {
    link: "bag...",
  }
}
```

### Response

Error if `link` shard cid is not in space or...

```ts
interface StoreListItem {
  /** CID of the stored CAR. */
  link: string

  /** Size in bytes of the stored CAR */
  size: number

  /** Link to a related CAR, used for sharded uploads */
  origin?: string,

  /** ISO-8601 timestamp when CAR was added to the space */
  insertedAt: string,
}
```

## `upload/get` delegation

```js
{
  can: "upload/get",
  with: "did:key:abc...",
  nb: {
    root: "bafyabc..."
  }
}
```

### Response

`Error` if root is not in uploads for space or...

```ts
interface UploadListItem {
  /** Root CID of the uploaded data item. */
  root: string

  /** CIDs of CARs that contain the complete DAG for the uploaded data item. */
  shards: string[]

  /** ISO-8601 timestamp when the upload was added to the space. */
  insertedAt: string,

  /** ISO-8601 timestamp when the upload entry was last modified. */
  updatedAt: string,
}
```

---

see also: storacha/w3up#942

License: MIT

---------

Signed-off-by: Oli Evans <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants