Skip to content

Commit

Permalink
feat: add legacy handlers (#117)
Browse files Browse the repository at this point in the history
This PR adds the legacy `store/*` and `admin/store/inspect` handlers
from the `@web3-storage/upload-api` in order to support deprecated
actions for a bit longer, per storacha/RFC#38

refs storacha/project-tracking#268
  • Loading branch information
alanshaw authored Jan 15, 2025
1 parent 3ad8fc0 commit 1390106
Show file tree
Hide file tree
Showing 6 changed files with 75 additions and 5 deletions.
1 change: 1 addition & 0 deletions packages/upload-api/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,7 @@
"@ucanto/transport": "^9.1.1",
"@ucanto/validator": "^9.0.2",
"@web3-storage/content-claims": "^5.1.3",
"@web3-storage/upload-api": "^19.0.0",
"multiformats": "^12.1.2",
"uint8arrays": "^5.0.3"
},
Expand Down
11 changes: 10 additions & 1 deletion packages/upload-api/src/lib.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ import { createService as createUcanService } from './ucan.js'
import { createService as createPlanService } from './plan.js'
import { createService as createUsageService } from './usage.js'
import { createService as createFilecoinService } from '@storacha/filecoin-api/storefront/service'
import { createService as createLegacyAdminService } from '@web3-storage/upload-api/admin'
import { createService as createLegacyStoreService } from '@web3-storage/upload-api/store'
import * as AgentMessage from './utils/agent-message.js'

export * from './types.js'
Expand Down Expand Up @@ -178,7 +180,12 @@ export const createService = (context) => ({
customer: createCustomerService(context),
provider: createProviderService(context),
'rate-limit': createRateLimitService(context),
admin: createAdminService(context),
admin: {
...createAdminService(context),
// @ts-expect-error `uploadTable` items now have a `cause` field. This does
// not matter since `admin/store/inspect` handler does not use this table.
store: createLegacyAdminService(context).store
},
space: createSpaceService(context),
subscription: createSubscriptionService(context),
upload: createUploadService(context),
Expand All @@ -187,6 +194,8 @@ export const createService = (context) => ({
// storefront of filecoin pipeline
filecoin: createFilecoinService(context).filecoin,
usage: createUsageService(context),
// legacy
store: createLegacyStoreService(context),
})

/**
Expand Down
17 changes: 13 additions & 4 deletions packages/upload-api/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,11 @@ import type { ProviderInput, ConnectionView } from '@ucanto/server'

import { StorefrontService } from '@storacha/filecoin-api/types'
import { ServiceContext as FilecoinServiceContext } from '@storacha/filecoin-api/storefront/api'
import {
Service as LegacyService,
StoreServiceContext as LegacyStoreServiceContext,
AdminServiceContext as LegacyAdminServiceContext
} from '@web3-storage/upload-api'
import { DelegationsStorage as Delegations } from './types/delegations.js'
import { ProvisionsStorage as Provisions } from './types/provisions.js'
import { RateLimitsStorage as RateLimits } from './types/rate-limits.js'
Expand Down Expand Up @@ -271,7 +276,6 @@ export interface Service extends StorefrontService {
RateLimitListFailure
>
}

ucan: {
conclude: ServiceMethod<
UCANConclude,
Expand All @@ -280,8 +284,8 @@ export interface Service extends StorefrontService {
>
revoke: ServiceMethod<UCANRevoke, UCANRevokeSuccess, UCANRevokeFailure>
}

admin: {
store: LegacyService['admin']['store']
upload: {
inspect: ServiceMethod<
AdminUploadInspect,
Expand Down Expand Up @@ -337,6 +341,8 @@ export interface Service extends StorefrontService {
usage: {
report: ServiceMethod<UsageReport, UsageReportSuccess, UsageReportFailure>
}
// legacy handlers
store: LegacyService['store']
}

export type BlobServiceContext = SpaceServiceContext & {
Expand Down Expand Up @@ -382,6 +388,7 @@ export interface CustomerServiceContext {
export interface AdminServiceContext {
signer: Signer
uploadTable: UploadTable
storeTable: LegacyAdminServiceContext['storeTable']
}

export interface ConsoleServiceContext {}
Expand Down Expand Up @@ -434,7 +441,8 @@ export interface UsageServiceContext {
}

export interface ServiceContext
extends AgentContext,
extends AdminServiceContext,
AgentContext,
AccessServiceContext,
ConsoleServiceContext,
ConsumerServiceContext,
Expand All @@ -450,7 +458,8 @@ export interface ServiceContext
UploadServiceContext,
FilecoinServiceContext,
IndexServiceContext,
UsageServiceContext {}
UsageServiceContext,
LegacyStoreServiceContext {}

export interface UcantoServerContext extends ServiceContext, RevocationChecker {
id: Signer
Expand Down
8 changes: 8 additions & 0 deletions packages/upload-api/test/helpers/context.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,14 @@ export const createContext = async (
audience: dealTrackerSigner,
},
},
// Legacy dependencies.
// The following dependencies are legacy and will eventually be removed.
// @ts-expect-error legacy dependency not used or tested here
maxUploadSize: null,
// @ts-expect-error legacy dependency not used or tested here
storeTable: {},
// @ts-expect-error legacy dependency not used or tested here
carStoreBucket: {},
}

const connection = connect({
Expand Down
1 change: 1 addition & 0 deletions packages/upload-api/test/storage/agent-store.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import * as API from '../../src/types.js'
import { CAR, Invocation, Receipt } from '@ucanto/core'
import { RecordNotFound } from '../../src/errors.js'

/** @returns {API.AgentStore} */
export const memory = () => new AgentStore()

/**
Expand Down
42 changes: 42 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 1390106

Please sign in to comment.