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

fix(upload-api): fix incompatibilities with w3infra #504

Merged
merged 11 commits into from
Mar 8, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 12 additions & 6 deletions packages/upload-api/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,23 @@
"name": "@web3-storage/upload-api",
"version": "1.0.1",
"type": "module",
"main": "./src/lib.js",
"typesVersions": {
"*": {
"*": [
"dist/src/*"
],
"dist/src/lib.d.ts": [
"src/lib.js": [
"dist/src/lib.d.ts"
],
"store": [
"dist/src/store.d.ts"
],
"upload": [
"dist/src/upload.d.ts"
],
"types": [
"dist/src/types.d.ts"
],
"test": [
"dist/test/*"
"dist/test/lib.d.ts"
]
}
},
Expand Down Expand Up @@ -45,7 +52,6 @@
"test-watch": "pnpm build && mocha --bail --timeout 10s --watch --parallel -n no-warnings -n experimental-vm-modules --watch-files src,test"
},
"dependencies": {
"@sentry/serverless": "^7.22.0",
"@ucanto/client": "^5.1.0",
"@ucanto/interface": "^6.0.0",
"@ucanto/principal": "^5.1.0",
Expand Down
27 changes: 0 additions & 27 deletions packages/upload-api/src/index.js

This file was deleted.

1 change: 1 addition & 0 deletions packages/upload-api/src/lib.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import * as CAR from '@ucanto/transport/car'
import * as CBOR from '@ucanto/transport/cbor'
import { createService as createStoreService } from './store.js'
import { createService as createUploadService } from './upload.js'
export * from './types.js'

/**
* @param {Types.UcantoServerContext} options
Expand Down
28 changes: 12 additions & 16 deletions packages/upload-api/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ export interface Service {
upload: {
add: ServiceMethod<UploadAdd, UploadAddOk, Failure>
// @todo - Use proper type when no item was removed instead of undefined
remove: ServiceMethod<UploadRemove, UploadRemoveOk | undefined, Failure>
remove: ServiceMethod<UploadRemove, UploadRemoveOk | null, Failure>
list: ServiceMethod<UploadList, UploadListOk, Failure>
}
}
Expand Down Expand Up @@ -70,7 +70,6 @@ export interface UcantoServerTestContext

export interface StoreTestContext {
testStoreTable: TestStoreTable
testUploadTable: TestUploadTable
testSpaceRegistry: TestSpaceRegistry
}

Expand Down Expand Up @@ -129,20 +128,13 @@ export interface TestStoreTable {
export interface UploadTable {
exists: (space: DID, root: UnknownLink) => Promise<boolean>
insert: (item: UploadAddInput) => Promise<UploadAddOk>
remove: (space: DID, root: UnknownLink) => Promise<UploadRemoveOk | undefined>
remove: (space: DID, root: UnknownLink) => Promise<UploadRemoveOk | null>
list: (
space: DID,
options?: ListOptions
) => Promise<ListResponse<UploadListItem>>
}

export interface TestUploadTable {
get(
space: DID,
root: UnknownLink
): Promise<(UploadAddInput & UploadListItem) | undefined>
}

export interface StoreAddInput {
space: DID
link: UnknownLink
Expand Down Expand Up @@ -232,12 +224,16 @@ export interface SpaceUnknown extends Failure {
}

export interface Assert {
equal: (actual: unknown, expected: unknown, message?: string | Error) => void
deepEqual: (
actual: unknown,
expected: unknown,
message?: string | Error
) => void
equal: <Actual, Expected extends Actual>(
actual: Actual,
expected: Expected,
message?: string
) => unknown
deepEqual: <Actual, Expected extends Actual>(
actual: Actual,
expected: Expected,
message?: string
) => unknown
}

export type Test = (assert: Assert, context: UcantoServerTestContext) => unknown
Expand Down
2 changes: 1 addition & 1 deletion packages/upload-api/src/upload/remove.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import * as API from '../types.js'

/**
* @param {API.UploadServiceContext} context
* @returns {API.ServiceMethod<API.UploadRemove, API.UploadRemoveOk | undefined, API.Failure>}
* @returns {API.ServiceMethod<API.UploadRemove, API.UploadRemoveOk | null, API.Failure>}
*/
export function uploadRemoveProvider(context) {
return Server.provide(Upload.remove, async ({ capability }) => {
Expand Down
19 changes: 8 additions & 11 deletions packages/upload-api/test/store.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ export const test = {
assert.equal(storeAdd.with, spaceDid)
assert.deepEqual(storeAdd.link, link)

assert.deepEqual(storeAdd.headers?.['content-length'], size)
assert.equal(storeAdd.headers?.['content-length'], String(size))
assert.deepEqual(
storeAdd.headers?.['x-amz-checksum-sha256'],
base64pad.baseEncode(link.multihash.digest)
Expand Down Expand Up @@ -80,17 +80,17 @@ export const test = {
}

assert.deepEqual(
{
space: item.space,
link: item.link,
size: item.size,
issuer: item.issuer,
},
{
space: spaceDid,
link,
size: data.byteLength,
issuer: alice.did(),
},
{
space: item?.space,
link: item?.link,
size: item?.size,
issuer: item?.issuer,
}
)

Expand Down Expand Up @@ -262,10 +262,7 @@ export const test = {
}
)

assert.equal(
Link.parse(item.invocation.toString()),
item.invocation.toString()
)
assert.deepEqual(Link.parse(item.invocation.toString()), item.invocation)

assert.equal(
Date.now() - new Date(item.insertedAt).getTime() < 60_000,
Expand Down
1 change: 0 additions & 1 deletion packages/upload-api/test/store.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ describe('store/*', () => {
storeTable,
testStoreTable: storeTable,
uploadTable,
testUploadTable: uploadTable,
carStoreBucket,
dudewhereBucket,
access,
Expand Down
2 changes: 1 addition & 1 deletion packages/upload-api/test/upload-table.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ export class UploadTable {
this.items.splice(this.items.indexOf(item), 1)
}

return item
return item || null
}

/**
Expand Down
8 changes: 4 additions & 4 deletions packages/upload-api/test/upload.js
Original file line number Diff line number Diff line change
Expand Up @@ -307,15 +307,15 @@ export const test = {
)
}

if (uploadRemove.error) {
if (uploadRemove?.error) {
throw new Error(
'expected upload/remove response to include the upload object removed',
{ cause: uploadRemove.error }
)
}

assert.equal(uploadRemove.root.toString(), car.roots[0].toString())
assert.equal(uploadRemove.shards?.[0].toString(), car.cid.toString())
assert.equal(uploadRemove?.root.toString(), car.roots[0].toString())
assert.equal(uploadRemove?.shards?.[0].toString(), car.cid.toString())
},

'upload/remove does not fail for non existent upload': async (
Expand Down Expand Up @@ -345,7 +345,7 @@ export const test = {

assert.equal(
uploadRemove,
undefined,
null,
'expect falsy response when removing an upload you do not have'
)
},
Expand Down
1 change: 0 additions & 1 deletion packages/upload-api/test/upload.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ describe('upload/*', () => {
storeTable,
testStoreTable: storeTable,
uploadTable,
testUploadTable: uploadTable,
carStoreBucket,
dudewhereBucket,
access,
Expand Down
Loading