Skip to content

Commit b873754

Browse files
committed
feat(freeway): upgrade dependencies, wrangler, typescript, others
1 parent 2402029 commit b873754

26 files changed

+9867
-1119
lines changed

package-lock.json

Lines changed: 716 additions & 771 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -39,41 +39,43 @@
3939
"@microlabs/otel-cf-workers": "^1.0.0-rc.48",
4040
"@opentelemetry/api": "^1.9.0",
4141
"@opentelemetry/sdk-trace-base": "^1.27.0",
42-
"@storacha/indexing-service-client": "^2.1.0",
42+
"@storacha/capabilities": "^1.7.0",
43+
"@storacha/indexing-service-client": "^2.6.4",
44+
"@types/node": "^24.9.1",
4345
"@ucanto/client": "^9.0.1",
44-
"@ucanto/principal": "^9.0.1",
45-
"@ucanto/transport": "^9.1.1",
46-
"@web3-storage/blob-fetcher": "^3.0.0",
47-
"@web3-storage/capabilities": "^17.4.1",
46+
"@ucanto/core": "^10.4.0",
47+
"@ucanto/interface": "^10.3.0",
48+
"@ucanto/principal": "^9.0.2",
49+
"@ucanto/server": "^10.2.0",
50+
"@ucanto/transport": "^9.2.0",
51+
"@ucanto/validator": "^9.1.0",
52+
"@web3-storage/blob-fetcher": "^4.1.0",
4853
"@web3-storage/gateway-lib": "^5.2.2",
4954
"dagula": "^8.0.0",
5055
"http-range-parse": "^1.0.0",
5156
"lnmap": "^2.0.0",
5257
"multiformats": "^13.0.1"
5358
},
5459
"devDependencies": {
55-
"@cloudflare/workers-types": "^4.20231218.0",
56-
"@storacha/cli": "^1.0.1",
57-
"@storacha/client": "^1.0.5",
60+
"@storacha/cli": "^1.6.2",
61+
"@storacha/client": "^1.8.2",
5862
"@types/chai": "^5.0.0",
5963
"@types/mocha": "^10.0.9",
6064
"@types/node-fetch": "^2.6.11",
6165
"@types/sinon": "^17.0.3",
62-
"@web3-storage/content-claims": "^5.0.0",
6366
"@web3-storage/public-bucket": "^1.4.0",
64-
"@web3-storage/upload-client": "^16.1.1",
65-
"carstream": "^2.1.0",
67+
"carstream": "^2.2.0",
6668
"chai": "^5.1.1",
6769
"esbuild": "^0.24.0",
6870
"files-from-path": "^0.2.6",
69-
"miniflare": "^3.20240909.5",
71+
"miniflare": "^4.20251011.1",
7072
"mocha": "^10.7.3",
7173
"multipart-byte-range": "^3.0.1",
7274
"sinon": "^19.0.2",
73-
"standard": "^17.1.0",
75+
"standard": "^17.1.2",
7476
"tree-kill": "^1.2.2",
75-
"typescript": "^5.6.3",
76-
"wrangler": "^3.90.0"
77+
"typescript": "^5.8.3",
78+
"wrangler": "^4.45.0"
7779
},
7880
"standard": {
7981
"ignore": [

scripts/delegate-serve.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import sade from 'sade'
22
import { Schema } from '@ucanto/core'
33
import { getClient } from '@storacha/cli/lib.js'
4-
import { Space } from '@web3-storage/capabilities'
4+
import { Space } from '@storacha/capabilities'
55

66
const MailtoDID =
77
/** @type {import('@ucanto/validator').StringSchema<`did:mailto:${string}:${string}`, unknown>} */ (

src/middleware/withAuthorizedSpace.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { Verifier } from '@ucanto/principal'
22
import { ok, access, Unauthorized } from '@ucanto/validator'
33
import { HttpError } from '@web3-storage/gateway-lib/util'
44
import * as serve from '../capabilities/serve.js'
5-
import { SpaceDID } from '@web3-storage/capabilities/utils'
5+
import { SpaceDID } from '@storacha/capabilities/utils'
66

77
/**
88
* @import * as Ucanto from '@ucanto/interface'
@@ -100,9 +100,9 @@ export function withAuthorizedSpace (handler) {
100100
* authorizing delegations in the
101101
* {@link DelegationsStorageContext.delegationsStorage}.
102102
*
103-
* @param {import('@web3-storage/capabilities/types').SpaceDID} space
103+
* @param {import('@storacha/capabilities/types').SpaceDID} space
104104
* @param {AuthTokenContext & DelegationsStorageContext & GatewayIdentityContext} ctx
105-
* @returns {Promise<Ucanto.Result<{space: import('@web3-storage/capabilities/types').SpaceDID, delegationProofs: Ucanto.Delegation[]}, Ucanto.Failure>>}
105+
* @returns {Promise<Ucanto.Result<{space: import('@storacha/capabilities/types').SpaceDID, delegationProofs: Ucanto.Delegation[]}, Ucanto.Failure>>}
106106
*/
107107
const authorize = async (space, ctx) => {
108108
// Look up delegations that might authorize us to serve the content.

src/middleware/withAuthorizedSpace.types.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import * as Ucanto from '@ucanto/interface'
22
import { Context as MiddlewareContext } from '@web3-storage/gateway-lib'
3-
import { SpaceDID } from '@web3-storage/capabilities/types'
3+
import { SpaceDID } from '@storacha/capabilities/types'
44
export interface DelegationProofsContext extends MiddlewareContext {
55
/**
66
* The delegation proofs to use for the egress record

src/middleware/withCarBlockHandler.js

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ import httpRangeParse from 'http-range-parse'
88
import { base58btc } from 'multiformats/bases/base58'
99

1010
/**
11-
* @import { R2Bucket, KVNamespace, RateLimit } from '@cloudflare/workers-types'
1211
* @import {
1312
* IpfsUrlContext,
1413
* Middleware,
@@ -36,11 +35,13 @@ export function withCarBlockHandler (handler) {
3635
// if not CAR codec, or if trusted gateway format has been requested...
3736
const formatParam = searchParams.get('format')
3837
const acceptHeader = request.headers.get('Accept')
39-
if (dataCid.code !== CAR_CODE ||
38+
if (
39+
dataCid.code !== CAR_CODE ||
4040
formatParam === 'car' ||
4141
acceptHeader === 'application/vnd.ipld.car' ||
4242
formatParam === 'raw' ||
43-
acceptHeader === 'application/vnd.ipld.raw') {
43+
acceptHeader === 'application/vnd.ipld.raw'
44+
) {
4445
return handler(request, env, ctx) // pass to other handlers
4546
}
4647

@@ -132,15 +133,17 @@ export async function handleCarBlock (request, env, ctx) {
132133
}
133134
headers.set('Content-Length', contentLength.toString())
134135

135-
// @ts-expect-error ReadableStream types incompatible
136-
return new Response(obj.body.pipeThrough(new FixedLengthStream(contentLength)), { status, headers })
136+
return new Response(
137+
obj.body.pipeThrough(new FixedLengthStream(contentLength)),
138+
{ status, headers }
139+
)
137140
}
138141

139142
/** @param {import('multiformats').UnknownLink} cid */
140-
const toCARKey = cid => `${cid}/${cid}.car`
143+
const toCARKey = (cid) => `${cid}/${cid}.car`
141144

142145
/** @param {import('multiformats').MultihashDigest} digest */
143-
const toBlobKey = digest => {
146+
const toBlobKey = (digest) => {
144147
const mhStr = base58btc.encode(digest.bytes)
145148
return `${mhStr}/${mhStr}.blob`
146149
}

src/middleware/withCarBlockHandler.types.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import { Environment as MiddlewareEnvironment } from '@web3-storage/gateway-lib'
2-
import { R2Bucket } from '@cloudflare/workers-types'
32

43
export interface Environment extends MiddlewareEnvironment {
54
CARPARK: R2Bucket

src/middleware/withCarParkFetch.types.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ import {
22
Environment as MiddlewareEnvironment,
33
Context as MiddlewareContext,
44
} from '@web3-storage/gateway-lib'
5-
import { R2Bucket } from '@cloudflare/workers-types'
65

76
export interface CarParkFetchEnvironment extends MiddlewareEnvironment {
87
CARPARK: R2Bucket

src/middleware/withContentClaimsDagula.types.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import { KVNamespace } from '@cloudflare/workers-types'
21
import { Environment as MiddlewareEnvironment } from '@web3-storage/gateway-lib'
32

43
export interface Environment extends MiddlewareEnvironment {

src/middleware/withDelegationsStorage.js

Lines changed: 37 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,16 @@ import { ok, error, Failure } from '@ucanto/server'
1515
* Middleware<DelegationsStorageContext, DelegationsStorageContext, DelegationsStorageEnvironment>
1616
* )}
1717
*/
18-
export const withDelegationsStorage = (handler) => async (request, env, ctx) => {
19-
if (env.FF_DELEGATIONS_STORAGE_ENABLED !== 'true') {
20-
return handler(request, env, ctx)
18+
export const withDelegationsStorage =
19+
(handler) => async (request, env, ctx) => {
20+
if (env.FF_DELEGATIONS_STORAGE_ENABLED !== 'true') {
21+
return handler(request, env, ctx)
22+
}
23+
return handler(request, env, {
24+
...ctx,
25+
delegationsStorage: createStorage(env)
26+
})
2127
}
22-
return handler(request, env, {
23-
...ctx,
24-
delegationsStorage: createStorage(env)
25-
})
26-
}
2728

2829
/**
2930
* @param {DelegationsStorageEnvironment} env
@@ -34,35 +35,46 @@ function createStorage (env) {
3435
/**
3536
* Finds the delegation proofs for the given space
3637
*
37-
* @param {import('@web3-storage/capabilities/types').SpaceDID} space
38+
* @param {import('@storacha/capabilities/types').SpaceDID} space
3839
* @returns {Promise<Ucanto.Result<Ucanto.Delegation<Ucanto.Capabilities>[], DelegationNotFound | Ucanto.Failure>>}
3940
*/
4041
find: async (space) => {
4142
/** @type {Ucanto.Delegation<Ucanto.Capabilities>[]} */
4243
const delegations = []
43-
const result = await env.CONTENT_SERVE_DELEGATIONS_STORE.list({ prefix: space })
44-
await Promise.all(result.keys.map(async (key) => {
45-
const delegation = await env.CONTENT_SERVE_DELEGATIONS_STORE.get(key.name, 'arrayBuffer')
46-
if (delegation) {
47-
const d = await Delegation.extract(new Uint8Array(delegation))
48-
if (d.ok) delegations.push(d.ok)
49-
else console.error('error while extracting delegation', d.error)
50-
}
51-
}))
44+
const result = await env.CONTENT_SERVE_DELEGATIONS_STORE.list({
45+
prefix: space
46+
})
47+
await Promise.all(
48+
result.keys.map(async (key) => {
49+
const delegation = await env.CONTENT_SERVE_DELEGATIONS_STORE.get(
50+
key.name,
51+
'arrayBuffer'
52+
)
53+
if (delegation) {
54+
const d = await Delegation.extract(new Uint8Array(delegation))
55+
if (d.ok) delegations.push(d.ok)
56+
else console.error('error while extracting delegation', d.error)
57+
}
58+
})
59+
)
5260
return ok(delegations)
5361
},
5462

5563
/**
5664
* Stores the delegation proofs for the given space.
5765
* If the delegation has an expiration, it will be stored with an expiration time in seconds since unix epoch.
5866
*
59-
* @param {import('@web3-storage/capabilities/types').SpaceDID} space
67+
* @param {import('@storacha/capabilities/types').SpaceDID} space
6068
* @param {Ucanto.Delegation<Ucanto.Capabilities>} delegation
6169
* @returns {Promise<Ucanto.Result<Ucanto.Unit, StoreOperationFailed | Ucanto.Failure>>}
6270
*/
6371
store: async (space, delegation) => {
6472
let options = {}
65-
if (delegation.expiration && delegation.expiration > 0 && delegation.expiration !== Infinity) {
73+
if (
74+
delegation.expiration &&
75+
delegation.expiration > 0 &&
76+
delegation.expiration !== Infinity
77+
) {
6678
// expire the key-value pair when the delegation expires (seconds since epoch)
6779
options = { expiration: delegation.expiration }
6880
}
@@ -74,7 +86,11 @@ function createStorage (env) {
7486
}
7587

7688
try {
77-
await env.CONTENT_SERVE_DELEGATIONS_STORE.put(`${space}:${delegation.cid.toString()}`, value.ok.buffer, options)
89+
await env.CONTENT_SERVE_DELEGATIONS_STORE.put(
90+
`${space}:${delegation.cid.toString()}`,
91+
value.ok.buffer,
92+
options
93+
)
7894
return ok({})
7995
} catch (/** @type {any} */ err) {
8096
const message = `error while storing delegation for space ${space}`

0 commit comments

Comments
 (0)