diff --git a/packages/capabilities/src/types.ts b/packages/capabilities/src/types.ts index 73b3b5c20..0eaf329b2 100644 --- a/packages/capabilities/src/types.ts +++ b/packages/capabilities/src/types.ts @@ -265,6 +265,8 @@ export interface StoreItemNotFound extends Ucanto.Failure { export type StoreRemoveFailure = StoreItemNotFound | Ucanto.Failure +export type StoreGetSuccess = StoreListItem + export type StoreGetFailure = StoreItemNotFound | Ucanto.Failure export interface StoreListSuccess extends ListResponse {} @@ -281,13 +283,21 @@ export interface StoreListItem { link: UnknownLink size: number origin?: UnknownLink + insertedAt: string } -export interface UploadAddSuccess { +export interface UploadListItem { root: UnknownLink shards?: CARLink[] + insertedAt: string + updatedAt: string } +// TODO: (olizilla) make this an UploadListItem too? +export type UploadAddSuccess = Omit + +export type UploadGetSuccess = UploadListItem + export type UploadRemoveSuccess = UploadDidRemove | UploadDidNotRemove export interface UploadDidRemove extends UploadAddSuccess {} @@ -299,8 +309,6 @@ export interface UploadDidNotRemove { export interface UploadListSuccess extends ListResponse {} -export interface UploadListItem extends UploadAddSuccess {} - // UCAN core events export type UCANRevoke = InferInvokedCapability diff --git a/packages/upload-api/src/store/get.js b/packages/upload-api/src/store/get.js index 2fddbd246..6ea8baca4 100644 --- a/packages/upload-api/src/store/get.js +++ b/packages/upload-api/src/store/get.js @@ -4,7 +4,7 @@ import * as API from '../types.js' /** * @param {API.StoreServiceContext} context - * @returns {API.ServiceMethod} + * @returns {API.ServiceMethod} */ export function storeGetProvider(context) { return Server.provide(Store.get, async ({ capability }) => { diff --git a/packages/upload-api/src/types.ts b/packages/upload-api/src/types.ts index 776de8737..7d23c7750 100644 --- a/packages/upload-api/src/types.ts +++ b/packages/upload-api/src/types.ts @@ -123,6 +123,8 @@ import { UCANRevoke, ListResponse, CARLink, + StoreGetSuccess, + UploadGetSuccess, } from '@web3-storage/capabilities/types' import * as Capabilities from '@web3-storage/capabilities' import { RevocationsStorage } from './types/revocations' @@ -146,13 +148,13 @@ export type { RateLimitsStorage, RateLimit } from './types/rate-limits' export interface Service { store: { add: ServiceMethod - get: ServiceMethod + get: ServiceMethod remove: ServiceMethod list: ServiceMethod } upload: { add: ServiceMethod - get: ServiceMethod + get: ServiceMethod remove: ServiceMethod list: ServiceMethod } @@ -383,13 +385,8 @@ export interface StoreTable { list: ( space: DID, options?: ListOptions - ) => Promise< - (StoreAddInput & StoreListItem & { insertedAt: string }) | undefined - > - get( - space: DID, - link: UnknownLink - ): Promise<(StoreGetItem) | undefined> + ) => Promise> + get: (space: DID,link: UnknownLink) => Promise<(StoreListItem) | undefined> } export interface UploadTable { @@ -400,13 +397,8 @@ export interface UploadTable { list: ( space: DID, options?: ListOptions - ) => Promise< - ListResponse - > - get( - space: DID, - link: UnknownLink - ): Promise<(UploadGetItem) | undefined> + ) => Promise> + get: (space: DID,link: UnknownLink) => Promise<(UploadListItem) | undefined> } export type SpaceInfoSuccess = { @@ -452,32 +444,6 @@ export interface StoreInspectOk { spaces: Array<{ did: DID; insertedAt: string }> } -export type StoreListItem = StoreAddOutput & StoreMetadata - -export type StoreGetItem = StoreAddInput & StoreMetadata - -export interface StoreListOk extends ListResponse {} - -export type StoreGetOk = StoreGetItem - -export type StoreAddOk = StoreAddDone | StoreAddUpload - -export interface StoreAddDone { - status: 'done' - with: DID - link: UnknownLink - url?: undefined - headers?: undefined -} - -export interface StoreAddUpload { - status: 'upload' - with: DID - link: UnknownLink - url: URL - headers: Record -} - export interface UploadAddInput { space: DID root: UnknownLink @@ -486,32 +452,10 @@ export interface UploadAddInput { invocation: UCANLink } -export interface UploadMetadata { - insertedAt: string - updatedAt: string -} - -export interface UploadAddOk - extends Omit {} -export type UploadRemoveOk = UploadDIDRemove | UploadDidNotRemove - -export type UploadListItem = UploadAddOk & UploadMetadata -export type UploadGetItem = UploadAddInput & UploadMetadata - -export interface UploadDIDRemove extends UploadAddOk {} -export interface UploadDidNotRemove { - root?: undefined - shards?: undefined -} - export interface UploadInspectOk { spaces: Array<{ did: DID; insertedAt: string }> } -export interface UploadListOk extends ListResponse {} - -export interface UploadGetOk extends UploadGetItem {} - export interface ListOptions { size?: number cursor?: string diff --git a/packages/upload-api/src/upload/get.js b/packages/upload-api/src/upload/get.js index 0a5537e25..e113f0358 100644 --- a/packages/upload-api/src/upload/get.js +++ b/packages/upload-api/src/upload/get.js @@ -4,7 +4,7 @@ import * as API from '../types.js' /** * @param {API.UploadServiceContext} context - * @returns {API.ServiceMethod} + * @returns {API.ServiceMethod} */ export function uploadGetProvider(context) { return Server.provide(Upload.get, async ({ capability }) => { diff --git a/packages/upload-api/test/handlers/store.js b/packages/upload-api/test/handlers/store.js index 43ce5a08f..24534f446 100644 --- a/packages/upload-api/test/handlers/store.js +++ b/packages/upload-api/test/handlers/store.js @@ -1,6 +1,5 @@ import { createServer, connect } from '../../src/lib.js' import * as API from '../../src/types.js' -import { CID } from 'multiformats' import * as CAR from '@ucanto/transport/car' import { base64pad } from 'multiformats/bases/base64' import * as StoreCapabilities from '@web3-storage/capabilities/store' @@ -80,10 +79,8 @@ export const test = { assert.deepEqual( { - space: item.space, link: item.link.toString(), size: item.size, - issuer: item.issuer, }, { space: spaceDid, @@ -93,7 +90,6 @@ export const test = { } ) - assert.equal(CID.parse(item.invocation.toString()) != null, true) assert.equal( Date.now() - new Date(item?.insertedAt).getTime() < 60_000, true @@ -304,10 +300,8 @@ export const test = { assert.deepEqual( { - space: item.space, link: item.link.toString(), size: item.size, - issuer: item.issuer, }, { space: spaceDid, @@ -739,7 +733,6 @@ export const test = { assert.deepEqual(storeGet.out.ok.link, links[0]) assert.equal(storeGet.out.ok.size, data[0].byteLength) - assert.equal(storeGet.out.ok.space, spaceDid) assert.ok(storeGet.out.ok.insertedAt) }, diff --git a/packages/upload-api/test/handlers/upload.js b/packages/upload-api/test/handlers/upload.js index 842096958..34f764be6 100644 --- a/packages/upload-api/test/handlers/upload.js +++ b/packages/upload-api/test/handlers/upload.js @@ -9,7 +9,6 @@ import { } from '../util.js' import { createServer, connect } from '../../src/lib.js' import { Upload } from '@web3-storage/capabilities' -import { uploadListProvider } from '../../src/upload/list.js' // https://docs.aws.amazon.com/AWSJavaScriptSDK/v3/latest/clients/client-dynamodb/classes/batchwriteitemcommand.html const BATCH_MAX_SAFE_LIMIT = 25 @@ -901,8 +900,6 @@ export const test = { throw new Error('invocation failed', { cause: uploadGet }) } - assert.equal(uploadGet.out.ok.issuer, alice.toDIDKey()) - assert.equal(uploadGet.out.ok.space, spaceDid) assert.equal(uploadGet.out.ok.shards?.[0].toString(), cars[0].cid.toString()) assert.equal(uploadGet.out.ok.root.toString(), cars[0].roots[0].toString()) }, diff --git a/packages/upload-api/test/helpers/context.js b/packages/upload-api/test/helpers/context.js index e2d9790bc..209efe887 100644 --- a/packages/upload-api/test/helpers/context.js +++ b/packages/upload-api/test/helpers/context.js @@ -61,7 +61,6 @@ export const createContext = async (options = {}) => { mail: /** @type {TestTypes.DebugEmail} */ (serviceContext.email), service: /** @type {TestTypes.ServiceSigner} */ (serviceContext.id), connection, - testStoreTable: storeTable, fetch, } } diff --git a/packages/upload-api/test/storage/store-table.js b/packages/upload-api/test/storage/store-table.js index 09fc0728c..576f6802f 100644 --- a/packages/upload-api/test/storage/store-table.js +++ b/packages/upload-api/test/storage/store-table.js @@ -5,7 +5,7 @@ import * as API from '../../src/types.js' */ export class StoreTable { constructor() { - /** @type {(API.StoreGetItem)[]} */ + /** @type {(API.StoreAddInput & API.StoreListItem)[]} */ this.items = [] } @@ -45,7 +45,7 @@ export class StoreTable { * Get info for a single shard or undefined if it doesn't exist * @param {API.DID} space * @param {API.UnknownLink} link - * @returns {Promise} + * @returns {Promise<(API.StoreAddInput & API.StoreListItem) | undefined>} */ async get(space, link) { return this.items.find( diff --git a/packages/upload-client/src/types.ts b/packages/upload-client/src/types.ts index 648caeda2..b1390f265 100644 --- a/packages/upload-client/src/types.ts +++ b/packages/upload-client/src/types.ts @@ -18,6 +18,8 @@ import { StoreAddSuccess, StoreAddSuccessUpload, StoreAddSuccessDone, + StoreGet, + StoreGetFailure, StoreList, StoreListSuccess, StoreListItem, @@ -34,6 +36,10 @@ import { ListResponse, CARLink, PieceLink, + StoreGetSuccess, + UploadGet, + UploadGetSuccess, + UploadGetFailure, } from '@web3-storage/capabilities/types' import * as UnixFS from '@ipld/unixfs/src/unixfs' @@ -70,11 +76,13 @@ export type ProgressFn = (status: ProgressStatus) => void export interface Service { store: { add: ServiceMethod + get: ServiceMethod remove: ServiceMethod list: ServiceMethod } upload: { add: ServiceMethod + get: ServiceMethod remove: ServiceMethod list: ServiceMethod } diff --git a/packages/upload-client/test/helpers/mocks.js b/packages/upload-client/test/helpers/mocks.js index 4d1386aae..937914bf6 100644 --- a/packages/upload-client/test/helpers/mocks.js +++ b/packages/upload-client/test/helpers/mocks.js @@ -14,11 +14,13 @@ export function mockService(impl) { return { store: { add: withCallCount(impl.store?.add ?? notImplemented), + get: withCallCount(impl.store?.get ?? notImplemented), list: withCallCount(impl.store?.list ?? notImplemented), remove: withCallCount(impl.store?.remove ?? notImplemented), }, upload: { add: withCallCount(impl.upload?.add ?? notImplemented), + get: withCallCount(impl.upload?.get ?? notImplemented), list: withCallCount(impl.upload?.list ?? notImplemented), remove: withCallCount(impl.upload?.remove ?? notImplemented), }, diff --git a/packages/upload-client/test/store.test.js b/packages/upload-client/test/store.test.js index deaccca34..35a0ca12e 100644 --- a/packages/upload-client/test/store.test.js +++ b/packages/upload-client/test/store.test.js @@ -354,6 +354,7 @@ describe('Store.list', () => { { link: car.cid, size: 123, + insertedAt: 'foo' }, ], } @@ -422,6 +423,7 @@ describe('Store.list', () => { { link: (await randomCAR(128)).cid, size: 123, + insertedAt: 'time1' }, ], } @@ -431,6 +433,7 @@ describe('Store.list', () => { { link: (await randomCAR(128)).cid, size: 123, + insertedAt: 'time1' }, ], } diff --git a/packages/upload-client/test/upload.test.js b/packages/upload-client/test/upload.test.js index 878d157b6..e9360dbcd 100644 --- a/packages/upload-client/test/upload.test.js +++ b/packages/upload-client/test/upload.test.js @@ -137,6 +137,8 @@ describe('Upload.list', () => { { root: car.roots[0], shards: [car.cid], + insertedAt: 'foo', + updatedAt: 'bar' }, ], } @@ -208,6 +210,8 @@ describe('Upload.list', () => { { root: car0.roots[0], shards: [car0.cid], + insertedAt: 'foo', + updatedAt: 'bar' }, ], } @@ -218,6 +222,8 @@ describe('Upload.list', () => { { root: car1.roots[0], shards: [car1.cid], + insertedAt: 'foo', + updatedAt: 'bar' }, ], } diff --git a/packages/w3up-client/test/capability/store.test.js b/packages/w3up-client/test/capability/store.test.js index 348f33834..fab39a5b1 100644 --- a/packages/w3up-client/test/capability/store.test.js +++ b/packages/w3up-client/test/capability/store.test.js @@ -68,6 +68,7 @@ describe('StoreClient', () => { { link: (await randomCAR(128)).cid, size: 123, + insertedAt: 'foo' }, ], } diff --git a/packages/w3up-client/test/capability/upload.test.js b/packages/w3up-client/test/capability/upload.test.js index e20acec29..11785ff8f 100644 --- a/packages/w3up-client/test/capability/upload.test.js +++ b/packages/w3up-client/test/capability/upload.test.js @@ -68,6 +68,8 @@ describe('StoreClient', () => { { root: car.roots[0], shards: [car.cid], + insertedAt: 'foo', + updatedAt: 'bar' }, ], }