-
Notifications
You must be signed in to change notification settings - Fork 23
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
Changes from 13 commits
e9af60b
87a4c74
8e6459c
1d70111
abb0058
17a093a
5eb25f3
a47a118
df55473
9d8fece
c268076
c8c6bdc
6927e81
6544496
0cfafe1
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,7 +15,7 @@ import type { PieceLink } from '@web3-storage/data-segment' | |
import { space, info } from './space.js' | ||
import * as provider from './provider.js' | ||
import { top } from './top.js' | ||
import { add, list, remove, store } from './store.js' | ||
import * as StoreCaps from './store.js' | ||
import * as UploadCaps from './upload.js' | ||
import * as AccessCaps from './access.js' | ||
import * as CustomerCaps from './customer.js' | ||
|
@@ -221,14 +221,22 @@ export interface ChainTrackerInfoFailure extends Ucanto.Failure { | |
// Upload | ||
export type Upload = InferInvokedCapability<typeof UploadCaps.upload> | ||
export type UploadAdd = InferInvokedCapability<typeof UploadCaps.add> | ||
export type UploadGet = InferInvokedCapability<typeof UploadCaps.get> | ||
export type UploadRemove = InferInvokedCapability<typeof UploadCaps.remove> | ||
export type UploadList = InferInvokedCapability<typeof UploadCaps.list> | ||
|
||
export interface UploadNotFound extends Ucanto.Failure { | ||
name: 'UploadNotFound' | ||
} | ||
|
||
export type UploadGetFailure = UploadNotFound | Ucanto.Failure | ||
|
||
// Store | ||
export type Store = InferInvokedCapability<typeof store> | ||
export type StoreAdd = InferInvokedCapability<typeof add> | ||
export type StoreRemove = InferInvokedCapability<typeof remove> | ||
export type StoreList = InferInvokedCapability<typeof list> | ||
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> | ||
Comment on lines
+235
to
+239
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. |
||
|
||
export type StoreAddSuccess = StoreAddSuccessDone | StoreAddSuccessUpload | ||
export interface StoreAddSuccessDone { | ||
|
@@ -257,6 +265,10 @@ export interface StoreItemNotFound extends Ucanto.Failure { | |
|
||
export type StoreRemoveFailure = StoreItemNotFound | Ucanto.Failure | ||
|
||
export type StoreGetSuccess = StoreListItem | ||
|
||
export type StoreGetFailure = StoreItemNotFound | Ucanto.Failure | ||
olizilla marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
export interface StoreListSuccess extends ListResponse<StoreListItem> {} | ||
|
||
export interface ListResponse<R> { | ||
|
@@ -271,13 +283,21 @@ export interface StoreListItem { | |
link: UnknownLink | ||
size: number | ||
origin?: UnknownLink | ||
insertedAt: string | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. |
||
} | ||
|
||
export interface UploadAddSuccess { | ||
export interface UploadListItem { | ||
root: UnknownLink | ||
shards?: CARLink[] | ||
insertedAt: string | ||
updatedAt: string | ||
Comment on lines
+292
to
+293
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. |
||
} | ||
|
||
// TODO: (olizilla) make this an UploadListItem too? | ||
export type UploadAddSuccess = Omit<UploadListItem, 'insertedAt' | 'updatedAt'> | ||
|
||
export type UploadGetSuccess = UploadListItem | ||
|
||
export type UploadRemoveSuccess = UploadDidRemove | UploadDidNotRemove | ||
|
||
export interface UploadDidRemove extends UploadAddSuccess {} | ||
|
@@ -289,8 +309,6 @@ export interface UploadDidNotRemove { | |
|
||
export interface UploadListSuccess extends ListResponse<UploadListItem> {} | ||
|
||
export interface UploadListItem extends UploadAddSuccess {} | ||
|
||
// UCAN core events | ||
|
||
export type UCANRevoke = InferInvokedCapability<typeof UCANCaps.revoke> | ||
|
@@ -374,10 +392,12 @@ export type AbilitiesArray = [ | |
SpaceInfo['can'], | ||
Upload['can'], | ||
UploadAdd['can'], | ||
UploadGet['can'], | ||
UploadRemove['can'], | ||
UploadList['can'], | ||
Store['can'], | ||
StoreAdd['can'], | ||
StoreGet['can'], | ||
StoreRemove['can'], | ||
StoreList['can'], | ||
Access['can'], | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import * as Server from '@ucanto/server' | ||
import * as Store from '@web3-storage/capabilities/store' | ||
import * as API from '../types.js' | ||
|
||
/** | ||
* @param {API.StoreServiceContext} context | ||
* @returns {API.ServiceMethod<API.StoreGet, API.StoreGetSuccess, API.StoreGetFailure>} | ||
*/ | ||
export function storeGetProvider(context) { | ||
return Server.provide(Store.get, async ({ capability }) => { | ||
const { link } = capability.nb | ||
if (!link) { | ||
return Server.fail('nb.link must be set') | ||
} | ||
const space = Server.DID.parse(capability.with).did() | ||
const res = await context.storeTable.get(space, link) | ||
if (!res) { | ||
return { | ||
error: { | ||
name: 'StoreItemNotFound', | ||
message: 'Store item not found', | ||
}, | ||
} | ||
} | ||
return { | ||
ok: res, | ||
} | ||
}) | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import * as Server from '@ucanto/server' | ||
import * as Upload from '@web3-storage/capabilities/upload' | ||
import * as API from '../types.js' | ||
|
||
/** | ||
* @param {API.UploadServiceContext} context | ||
* @returns {API.ServiceMethod<API.UploadGet, API.UploadGetSuccess, API.UploadGetFailure>} | ||
*/ | ||
export function uploadGetProvider(context) { | ||
return Server.provide(Upload.get, async ({ capability }) => { | ||
const { root } = capability.nb | ||
if (!root) { | ||
return Server.fail('nb.root must be set') | ||
} | ||
const space = Server.DID.parse(capability.with).did() | ||
const res = await context.uploadTable.get(space, root) | ||
if (!res) { | ||
return { | ||
error: { | ||
name: 'UploadNotFound', | ||
message: 'Upload not found', | ||
}, | ||
} | ||
} | ||
return { | ||
ok: res, | ||
} | ||
}) | ||
} |
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.
I wonder if this should be derivable from
store/add
(similar tospace/info
)? i.e. if you were able tostore/add
you should be able to derivestore/get
capability for the samelink
.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.
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.
is interesting point, but i'm gonna leave it separate for now.