@velajs/cloudflare 1.30.0 → 1.31.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (76) hide show
  1. package/CHANGELOG.md +112 -0
  2. package/README.md +260 -74
  3. package/dist/bindings.js +77 -0
  4. package/dist/bindings.js.map +1 -0
  5. package/dist/cloudflare-application.js +7 -34
  6. package/dist/cloudflare-application.js.map +1 -1
  7. package/dist/cloudflare-factory-eGiet0mg.d.ts +288 -0
  8. package/dist/cloudflare-factory.js +84 -28
  9. package/dist/cloudflare-factory.js.map +1 -1
  10. package/dist/diagnostics.js +18 -0
  11. package/dist/diagnostics.js.map +1 -0
  12. package/dist/durable-objects.d.ts +6 -2
  13. package/dist/index.d.ts +160 -455
  14. package/dist/index.js +7 -13
  15. package/dist/{nonce.durable-object-Ci9AGssY.d.ts → nonce.durable-object-Bg1e0BMD.d.ts} +1 -11
  16. package/dist/platform.js +22 -0
  17. package/dist/platform.js.map +1 -0
  18. package/dist/queue/cloudflare-queues.js +7 -7
  19. package/dist/queue/cloudflare-queues.js.map +1 -1
  20. package/dist/rate-limit/cloudflare-rate-limit.store.js +66 -27
  21. package/dist/rate-limit/cloudflare-rate-limit.store.js.map +1 -1
  22. package/dist/root-module-C23bUwt_.d.ts +11 -0
  23. package/dist/schedule-diagnostics.js +8 -15
  24. package/dist/schedule-diagnostics.js.map +1 -1
  25. package/dist/services/kv-cache.store.js +33 -7
  26. package/dist/services/kv-cache.store.js.map +1 -1
  27. package/dist/storage/r2-storage.js +30 -0
  28. package/dist/storage/r2-storage.js.map +1 -0
  29. package/dist/storage.d.ts +28 -0
  30. package/dist/storage.js +2 -0
  31. package/dist/testing.d.ts +96 -0
  32. package/dist/testing.js +111 -0
  33. package/dist/testing.js.map +1 -0
  34. package/dist/websocket/binding-gateways.js +33 -0
  35. package/dist/websocket/binding-gateways.js.map +1 -0
  36. package/dist/websocket/cf-room-registry.js +3 -1
  37. package/dist/websocket/cf-room-registry.js.map +1 -1
  38. package/dist/websocket/do-bootstrap.js +36 -15
  39. package/dist/websocket/do-bootstrap.js.map +1 -1
  40. package/dist/websocket/do-live.js +49 -90
  41. package/dist/websocket/do-live.js.map +1 -1
  42. package/dist/websocket/do-state.js.map +1 -1
  43. package/dist/websocket/live-driver.js +149 -0
  44. package/dist/websocket/live-driver.js.map +1 -0
  45. package/dist/websocket/room-id.js +11 -1
  46. package/dist/websocket/room-id.js.map +1 -1
  47. package/dist/websocket/websocket.durable-object.js +14 -10
  48. package/dist/websocket/websocket.durable-object.js.map +1 -1
  49. package/dist/websocket/worker-transport.js +80 -0
  50. package/dist/websocket/worker-transport.js.map +1 -0
  51. package/package.json +23 -6
  52. package/dist/_virtual/_@oxc-project_runtime@0.150.0/helpers/esm/decorate.js +0 -9
  53. package/dist/_virtual/_@oxc-project_runtime@0.150.0/helpers/esm/decorateMetadata.js +0 -6
  54. package/dist/_virtual/_@oxc-project_runtime@0.150.0/helpers/esm/decorateParam.js +0 -8
  55. package/dist/storage/r2-storage.driver.js +0 -67
  56. package/dist/storage/r2-storage.driver.js.map +0 -1
  57. package/dist/storage/storage-key-claim.js +0 -74
  58. package/dist/storage/storage-key-claim.js.map +0 -1
  59. package/dist/storage/storage-manager.service.js +0 -38
  60. package/dist/storage/storage-manager.service.js.map +0 -1
  61. package/dist/storage/storage.controller.js +0 -64
  62. package/dist/storage/storage.controller.js.map +0 -1
  63. package/dist/storage/storage.module.js +0 -25
  64. package/dist/storage/storage.module.js.map +0 -1
  65. package/dist/storage/storage.service.js +0 -64
  66. package/dist/storage/storage.service.js.map +0 -1
  67. package/dist/storage/storage.tokens.js +0 -7
  68. package/dist/storage/storage.tokens.js.map +0 -1
  69. package/dist/websocket/broadcast.js +0 -32
  70. package/dist/websocket/broadcast.js.map +0 -1
  71. package/dist/websocket/cloudflare-websocket.module.js +0 -25
  72. package/dist/websocket/cloudflare-websocket.module.js.map +0 -1
  73. package/dist/websocket/websocket-routing.js +0 -133
  74. package/dist/websocket/websocket-routing.js.map +0 -1
  75. package/dist/websocket/ws-server-holder.js +0 -38
  76. package/dist/websocket/ws-server-holder.js.map +0 -1
package/dist/index.d.ts CHANGED
@@ -1,12 +1,12 @@
1
1
  import "./vela-env-DFvyoNT3.js";
2
- import { a as DoPitrId, c as DoPitrUnavailableError, d as isDoPitrUnavailable, f as readDoPitrBookmark, i as DoPitrBookmarkRead, l as VelaDoPitrRpc, n as DoPitrArmOptions, o as DoPitrNamespace, p as CloudflareRoot, r as DoPitrArmResult, s as DoPitrStorage, t as VelaNonceDurableObject, u as armDoPitr } from "./nonce.durable-object-Ci9AGssY.js";
3
- import { DynamicModule, InjectionToken, Type, VelaApplication, VelaEnv, VelaMiddlewareHandler, VelaSecurityOptions } from "@velajs/vela";
4
- import { BroadcastCommand, WebSocketGatewayOptions } from "@velajs/vela/websocket";
2
+ import { t as CloudflareRoot } from "./root-module-C23bUwt_.js";
3
+ import { a as DoPitrId, c as DoPitrUnavailableError, d as isDoPitrUnavailable, f as readDoPitrBookmark, i as DoPitrBookmarkRead, l as VelaDoPitrRpc, n as DoPitrArmOptions, o as DoPitrNamespace, r as DoPitrArmResult, s as DoPitrStorage, t as VelaNonceDurableObject, u as armDoPitr } from "./nonce.durable-object-Bg1e0BMD.js";
4
+ import { a as CloudflareWorkerOptions, c as createCloudflareApp, d as MountOpenApiOptions, f as CLOUDFLARE_SCHEDULED_EVENT, i as CloudflareWorkerDescriptor, l as createCloudflareWorker, m as ScheduledEvent, n as CloudflareAppOptions, o as CreateCloudflareAppOptions, p as CloudflareScheduledEvent, r as CloudflareWorker, s as cloudflareAdapter, t as CLOUDFLARE_WORKER, u as CloudflareApplication } from "./cloudflare-factory-eGiet0mg.js";
5
+ import { DynamicModule, Type, VelaEnv } from "@velajs/vela";
6
+ import { BroadcastCommand } from "@velajs/vela/websocket";
5
7
  import { CommitStamp, CursorLog, InvalidationCommand, LiveDriver, LiveInvalidationSink, ResumeVerdict } from "@velajs/vela/live";
6
- import { Context, ExecutionContext } from "hono";
7
- import { RuntimeAdapter } from "@velajs/vela/module-kit";
8
- import { DownloadResult, PresignMethod, PresignedUrlResult, StorageBody, StorageDriver, UploadOptions, UploadResult } from "@velajs/vela/storage";
9
- import { AsyncCacheStore, CacheEntry, CacheEntryReader, CacheEntryWriter, CacheInvalidationStore } from "@velajs/vela/cache";
8
+ import { EnvFactory } from "@velajs/vela/module-kit";
9
+ import { CacheEntry, CacheEntryReader, CacheEntryWriter, CacheInvalidationStore, CacheStore } from "@velajs/vela/cache";
10
10
  import { FeatureFlagDriver, FlagContext } from "@velajs/feature-flags";
11
11
  import { ThrottlerStore } from "@velajs/vela/throttler";
12
12
  import { NonceStore } from "@velajs/vela/security";
@@ -14,360 +14,26 @@ import { NonceStore } from "@velajs/vela/security";
14
14
  /** Stable, collision-free Durable Object name for one gateway's room. */
15
15
  export declare function durableObjectRoomName(gatewayPath: string, roomId: string): string;
16
16
  //#endregion
17
- //#region src/websocket/websocket-routing.d.ts
18
- interface WsGatewayRoute {
19
- path: string;
20
- binding: string;
21
- options: WebSocketGatewayOptions;
22
- /** Container module that declares the gateway; its authenticator resolves from here. */
23
- moduleId?: string;
24
- }
25
- //#endregion
26
- //#region src/scheduled-event.d.ts
27
- /**
28
- * The event a Worker's `scheduled()` export receives. The native
29
- * `ScheduledController` satisfies it; direct calls (tests, scripts) may omit
30
- * `scheduledTime`, which then defaults to the current time, and `noRetry`.
31
- */
32
- interface ScheduledEvent {
33
- readonly cron: string;
34
- readonly scheduledTime?: number;
35
- noRetry?(): void;
36
- }
37
- /** The Cloudflare trigger behind the current scheduled invocation. */
38
- interface CloudflareScheduledEvent {
39
- /** The trigger's exact cron string; it equals the invocation's `expression`. */
40
- readonly cron: string;
41
- /** The platform's scheduled time in Unix milliseconds. */
42
- readonly scheduledTime: number;
43
- /**
44
- * Ask Cloudflare not to retry this trigger if the invocation fails. Already
45
- * bound to the native controller, so it can be passed around or destructured.
46
- * A no-op for direct calls that supplied no controller.
47
- */
48
- readonly noRetry: () => void;
49
- }
50
- /**
51
- * Request-scoped Cloudflare view of the scheduled trigger, seeded into each
52
- * `@Cron` job's invocation scope by the Cloudflare adapter. Inject it where a
53
- * job needs platform controls such as `noRetry()`; the job's argument stays
54
- * the portable `ScheduleInvocation`. It resolves only inside a scheduled
55
- * invocation; resolving it anywhere else throws. A cron job fired on demand
56
- * (Studio's run-now) receives a synthetic event: `cron` is the job's
57
- * expression and `noRetry()` does nothing.
58
- *
59
- * The token provides itself as request-scoped in every container, so a class
60
- * that injects it is request-scoped wherever the graph boots (a Worker, a
61
- * Durable Object, the CLI or a testing module) and is built only for an
62
- * invocation, never at bootstrap.
63
- *
64
- * @example
65
- * ```ts
66
- * @Injectable({ scope: Scope.REQUEST })
67
- * class Reports {
68
- * constructor(@Inject(CLOUDFLARE_SCHEDULED_EVENT) private readonly trigger: CloudflareScheduledEvent) {}
69
- *
70
- * @Cron('0 3 * * *', { dialect: 'cloudflare' })
71
- * async nightly(tick: CronInvocation) {
72
- * if (!(await this.upstreamAvailable(tick.signal))) this.trigger.noRetry();
73
- * }
74
- * }
75
- * ```
76
- */
77
- export declare const CLOUDFLARE_SCHEDULED_EVENT: InjectionToken<CloudflareScheduledEvent>;
78
- //#endregion
79
- //#region src/cloudflare-application.d.ts
80
- /**
81
- * Options accepted by {@link CloudflareApplication.mountOpenApi}.
82
- *
83
- * Re-exposes vela's `MountOpenApiOptions` type — derived structurally from
84
- * the underlying `VelaApplication.mountOpenApi` signature so consumers don't
85
- * have to reach into vela's internal subpaths to type the argument.
86
- */
87
- type MountOpenApiOptions = Parameters<VelaApplication['mountOpenApi']>[0];
88
- /**
89
- * Wraps VelaApplication with Cloudflare-specific handlers:
90
- * - `fetch` — HTTP request handler (from Hono)
91
- * - `scheduled` — Cron trigger handler (runs the `@Cron()` jobs whose
92
- * expression is the trigger's exact string)
93
- * - `queue` — Queue consumer handler (`@QueueConsumer()` by physical queue,
94
- * then `QueueModule`'s native consumer)
95
- * - `mountOpenApi` — Serve an OpenAPI document (and optional Scalar UI) on
96
- * the underlying Hono app
97
- *
98
- * @example
99
- * ```ts
100
- * const app = await createCloudflareApp(AppModule, { env });
101
- * export default {
102
- * fetch: app.fetch,
103
- * scheduled: app.scheduled.bind(app),
104
- * queue: app.queue.bind(app),
105
- * };
106
- * ```
107
- *
108
- * @example
109
- * ```ts
110
- * // Serve OpenAPI docs alongside your routes
111
- * const app = await createCloudflareApp(AppModule, { env });
112
- * const document = createOpenApiDocument(AppModule);
113
- * app.mountOpenApi({ document, ui: 'scalar' });
114
- * // GET /openapi.json -> JSON document
115
- * // GET /scalar -> Scalar UI (loads from CDN)
116
- * ```
117
- */
118
- export declare class CloudflareApplication {
119
- #private;
120
- readonly env: VelaEnv;
121
- constructor(app: VelaApplication, env: VelaEnv);
122
- readonly fetch: (request: Request, env: VelaEnv, ctx?: ExecutionContext) => Promise<Response>;
123
- getHonoApp(): ReturnType<VelaApplication['getHonoApp']>;
124
- /**
125
- * Resolve a provider from the application's DI container (delegates to
126
- * `VelaApplication.get`). Handy for grabbing a service — e.g. an auth service —
127
- * to use inside `createCloudflareApp({ middleware: env => [...] })` request middleware,
128
- * which runs outside the DI request pipeline.
129
- *
130
- * @example
131
- * ```ts
132
- * const app = await createCloudflareApp(AppModule, { env });
133
- * const auth = app.get(BetterAuthService);
134
- * ```
135
- */
136
- readonly get: VelaApplication['get'];
137
- get entrypoints(): VelaApplication['entrypoints'];
138
- /**
139
- * Serve a pre-built OpenAPI document (and optionally a Scalar UI) on the
140
- * underlying Hono app. Delegates verbatim to `VelaApplication.mountOpenApi`,
141
- * so the JSON endpoint defaults to `/openapi.json` and the Scalar UI (when
142
- * opted in) defaults to `/scalar`. Edge-safe — the UI HTML loads Scalar from
143
- * a CDN at runtime, nothing is bundled server-side.
144
- *
145
- * @example
146
- * ```ts
147
- * import { createOpenApiDocument } from '@velajs/vela/openapi';
148
- *
149
- * const app = await createCloudflareApp(AppModule, { env });
150
- * const document = createOpenApiDocument(AppModule, {
151
- * info: { title: 'My API', version: '1.0.0' },
152
- * });
153
- * app.mountOpenApi({ document, ui: 'scalar' });
154
- * // GET /openapi.json -> { openapi: '3.1.0', ... }
155
- * // GET /scalar -> Scalar UI HTML
156
- * ```
157
- */
158
- mountOpenApi(options: MountOpenApiOptions): this;
159
- /**
160
- * @internal Upgrade routes come from validated gateway entrypoints, including
161
- * request-scoped gateways without a bootstrap instance. Retain the instance
162
- * scan for legacy applications that only declare forwarding metadata.
163
- */
164
- scanInstances(instances: unknown[]): void;
165
- /** @internal — upgrade routes discovered from the application's gateways. */
166
- getWsGatewayRoutes(): WsGatewayRoute[];
167
- /**
168
- * Handle a Cloudflare cron trigger. Runs every core `@Cron()` job whose
169
- * expression is exactly `event.cron` (the trigger string is compared as
170
- * delivered, never re-evaluated) through `invokeScheduledJob`, the dispatch
171
- * primitive every runtime shares. Each job receives only its
172
- * `ScheduleInvocation`, runs in a fresh invocation scope seeded with
173
- * {@link CLOUDFLARE_SCHEDULED_EVENT}, and honors signed `ScheduleModule`
174
- * dispatch. The trigger settles after every matching job and its managed
175
- * work (`EXECUTION_LIFETIME.waitUntil`/`defer`) settle; failures reject it.
176
- */
177
- scheduled(event: ScheduledEvent, env: VelaEnv, _ctx?: {
178
- waitUntil: (promise: Promise<unknown>) => void;
179
- }): Promise<void>;
180
- /**
181
- * Run one queue consumer inside a fresh request scope, through the shared
182
- * guard → interceptor pipeline (components declared with
183
- * `@UseGuards`/`@UseInterceptors`/`@UseFilters` on the consumer class or
184
- * method). HTTP-global components deliberately do NOT apply — an HTTP auth
185
- * guard has no business rejecting a queue batch. Unclaimed errors are
186
- * reported once (`QueueModule`'s consumer reports its own) and rethrow so
187
- * the platform's retry semantics stay intact.
188
- */
189
- private dispatchEntrypoint;
190
- /**
191
- * Handle Cloudflare Queue consumer events. `@QueueConsumer()` handlers read
192
- * from `app.entrypoints` claim a batch by its physical queue name and
193
- * receive it whole. A batch no handler claims goes to `QueueModule`'s native
194
- * consumer (`cloudflareQueues()` from `@velajs/cloudflare/queues`), which
195
- * routes each job by its logical queue. Each dispatch runs inside a fresh
196
- * request-scoped child (request-scoped providers rebuild per batch — no
197
- * boot-time captives). A batch nothing claims rejects: resolving would let
198
- * Cloudflare acknowledge every message implicitly.
199
- */
200
- queue(batch: {
201
- queue: string;
202
- messages: readonly unknown[];
203
- }, env: VelaEnv, ctx: {
204
- waitUntil: (promise: Promise<unknown>) => void;
205
- }): Promise<void>;
206
- /**
207
- * A raw `@QueueConsumer` owns its physical queue's batches and must not carry
208
- * jobs of a queue registered with `QueueModule`: those reach their
209
- * `@Processor` only if the raw handler dispatches them itself, while
210
- * `cloudflareQueues()` delivers registered queues. Warn once per physical and
211
- * logical queue (unless diagnostics are silent); the raw consumer still
212
- * receives and settles the batch.
213
- */
214
- private warnRawJobs;
215
- /**
216
- * Abort the signals of scheduled jobs still running, wait for them and their
217
- * managed work to settle, then close the application.
218
- */
219
- close(signal?: string): Promise<void>;
220
- }
221
- //#endregion
222
- //#region src/cloudflare-factory.d.ts
223
- interface CloudflareWorkerOptions {
224
- globalPrefix?: string;
225
- security?: VelaSecurityOptions;
226
- /** Build request middleware from the same native environment DI receives as ENV. */
227
- middleware?: (env: VelaEnv) => VelaMiddlewareHandler[];
228
- /** Further runtime adapters, composed after the Cloudflare adapter for each application. */
229
- adapters?: RuntimeAdapter[];
230
- }
231
- interface CreateCloudflareAppOptions extends CloudflareWorkerOptions {
232
- /** Supply the platform environment inside fetch/queue/scheduled or a DO constructor. */
233
- env: VelaEnv;
234
- }
235
- /**
236
- * Bind an application to one environment: seeded as the global ENV before
237
- * provider factories and lifecycle hooks, and asserted on every request. The
238
- * adapter also supplies the `InternalDispatcher` transport, so signed queue and
239
- * schedule dispatch re-enter this application's routes, and reports schedule
240
- * declarations a cron trigger cannot honor through the diagnostics policy.
241
- */
242
- export declare function cloudflareAdapter(options: {
243
- env: VelaEnv;
244
- }): RuntimeAdapter;
245
- /**
246
- * Build an application for one native Workers environment. Call inside a platform event.
247
- * The root is static: a module class or a `DynamicModule` declared at module scope.
248
- * Read bindings in providers (`@InjectEnv()`) and module factories
249
- * (`forRootAsync({ inject: [ENV], useFactory })`), which run for each application.
250
- */
251
- export declare function createCloudflareApp(rootModule: CloudflareRoot, options: CreateCloudflareAppOptions): Promise<CloudflareApplication>;
252
- /**
253
- * Worker entrypoint with one bootstrap per environment identity. Concurrent cold
254
- * events share construction; failed construction is evicted so the next event
255
- * can retry. Weak keys stop this cache from retaining a replaced environment.
256
- */
257
- export declare function createCloudflareWorker(rootModule: CloudflareRoot, options?: CloudflareWorkerOptions): {
258
- fetch(request: Request, env: VelaEnv, ctx: ExecutionContext): Promise<Response>;
259
- scheduled(event: ScheduledEvent, env: VelaEnv, ctx?: {
260
- waitUntil: (promise: Promise<unknown>) => void;
261
- }): Promise<void>;
262
- queue(batch: {
263
- queue: string;
264
- messages: readonly unknown[];
265
- }, env: VelaEnv, ctx: {
266
- waitUntil: (promise: Promise<unknown>) => void;
267
- }): Promise<void>;
268
- };
269
- //#endregion
270
- //#region src/storage/storage.types.d.ts
271
- /** A named storage disk backed by an R2 bucket binding. */
272
- interface DiskConfig {
273
- disk: string;
274
- /** Native bucket supplied by a typed environment provider factory. */
275
- bucket: R2Bucket;
276
- /** Optional root prefix; supports path-template tokens ({date}/{year}/…). */
277
- root?: string;
278
- }
279
- interface PresignedUrlConfig {
280
- defaultExpiry: number;
281
- maxExpiry: number;
282
- }
283
- interface StorageModuleOptions {
284
- /** HMAC secret used for signed downloads. */
285
- secret?: string;
286
- disks: DiskConfig[];
287
- defaultDisk: string;
288
- presignedUrl?: PresignedUrlConfig;
289
- }
290
- //#endregion
291
- //#region src/storage/storage.module.d.ts
292
- declare const ConfigurableModuleClass: import("@velajs/vela").ConfigurableModuleClassType<StorageModuleOptions, "forRoot", "create", {
293
- isGlobal?: boolean;
294
- }>;
295
- export declare class StorageModule extends ConfigurableModuleClass {}
296
- //#endregion
297
- //#region src/storage/r2-storage.driver.d.ts
298
- interface R2StorageDriverConfig {
299
- disk: string;
300
- bucket: R2Bucket;
301
- /** HMAC secret for presigned URLs (typically env.APP_SECRET). */
302
- secret?: string;
303
- }
304
- /** {@link StorageDriver} over a Cloudflare R2 bucket. */
305
- export declare class R2StorageDriver implements StorageDriver {
306
- private readonly config;
307
- constructor(config: R2StorageDriverConfig);
308
- upload(body: StorageBody, path: string, options: UploadOptions): Promise<UploadResult>;
309
- download(path: string): Promise<DownloadResult>;
310
- delete(path: string): Promise<void>;
311
- exists(path: string): Promise<boolean>;
312
- getPresignedUrl(path: string, method: PresignMethod, expiresIn: number): Promise<PresignedUrlResult>;
313
- }
314
- //#endregion
315
- //#region src/storage/storage-manager.service.d.ts
316
- export declare class StorageManagerService {
317
- private readonly options;
318
- constructor(options: StorageModuleOptions);
319
- hasDisk(disk: string): boolean;
320
- getDiskConfig(disk: string): DiskConfig;
321
- getDriver(disk: string): R2StorageDriver;
322
- }
323
- //#endregion
324
- //#region src/storage/storage.service.d.ts
325
- /**
326
- * Multi-disk storage facade. Applies each disk's (templated) root, resolves the
327
- * driver, and validates presign expiry. Injectable anywhere via `StorageService`.
328
- */
329
- export declare class StorageService {
330
- private readonly options;
331
- private readonly manager;
332
- constructor(options: StorageModuleOptions, manager: StorageManagerService);
333
- put(relativePath: string, body: StorageBody, options?: UploadOptions, disk?: string): Promise<UploadResult>;
334
- get(relativePath: string, disk?: string): Promise<DownloadResult>;
335
- delete(relativePath: string, disk?: string): Promise<void>;
336
- exists(relativePath: string, disk?: string): Promise<boolean>;
337
- url(relativePath: string, method?: PresignMethod, expiresIn?: number, disk?: string): Promise<PresignedUrlResult>;
338
- private resolveDisk;
339
- private fullPath;
340
- private validateExpiry;
341
- }
342
- //#endregion
343
- //#region src/storage/storage.controller.d.ts
344
- /**
345
- * Presign-proxy: serves objects for HMAC-signed URLs produced by
346
- * `StorageService.url()`. R2 has no native presign, so a signed URL points here;
347
- * this route verifies the signature (+expiry) before streaming the object.
348
- * The FULL object key (root already applied at sign time) is carried as an
349
- * opaque base64url query claim. The signature is verified before the claim is
350
- * decoded exactly once and checked against the configured disk root.
351
- */
352
- export declare class StorageController {
353
- private readonly manager;
354
- private readonly options;
355
- constructor(manager: StorageManagerService, options: StorageModuleOptions);
356
- download(c: Context): Promise<Response>;
357
- }
358
- //#endregion
359
- //#region src/storage/storage.tokens.d.ts
360
- export declare const STORAGE_OPTIONS: InjectionToken<StorageModuleOptions>;
17
+ //#region src/bindings.d.ts
18
+ export declare const kv: (ref: import("@velajs/vela/module-kit").BindingRef) => import("@velajs/vela/module-kit").Binding<KVNamespace<string>>;
19
+ export declare const r2: (ref: import("@velajs/vela/module-kit").BindingRef) => import("@velajs/vela/module-kit").Binding<R2Bucket>;
20
+ export declare const d1: (ref: import("@velajs/vela/module-kit").BindingRef) => import("@velajs/vela/module-kit").Binding<D1Database>;
21
+ export declare const queue: (ref: import("@velajs/vela/module-kit").BindingRef) => import("@velajs/vela/module-kit").Binding<Queue<unknown>>;
22
+ export declare const durableObject: (ref: import("@velajs/vela/module-kit").BindingRef) => import("@velajs/vela/module-kit").Binding<DurableObjectNamespace<undefined>>;
23
+ export declare const rateLimit: (ref: import("@velajs/vela/module-kit").BindingRef) => import("@velajs/vela/module-kit").Binding<RateLimit>;
361
24
  //#endregion
362
25
  //#region src/services/kv-cache.store.d.ts
26
+ /** A KV namespace, or a function that reads it when an operation needs it. */
27
+ type KVNamespaceSource = KVNamespace | (() => KVNamespace);
363
28
  /**
364
29
  * Native KV JSON value store. Metadata retains logical expiry even when KV's
365
30
  * physical retention rounds up to its 60-second minimum. Legacy values without
366
31
  * metadata remain readable, but cannot safely backfill another tier.
367
32
  */
368
- export declare class KVCacheStore implements AsyncCacheStore, CacheEntryReader, CacheEntryWriter {
369
- private readonly ns;
370
- constructor(ns: KVNamespace);
33
+ export declare class KVCacheStore implements CacheStore, CacheEntryReader, CacheEntryWriter {
34
+ #private;
35
+ constructor(namespace: KVNamespaceSource);
36
+ private get ns();
371
37
  get(key: string): Promise<unknown>;
372
38
  getEntry(key: string): Promise<{
373
39
  value: unknown;
@@ -386,11 +52,28 @@ export declare class KVCacheStore implements AsyncCacheStore, CacheEntryReader,
386
52
  * this is unsuitable for strict read-after-write or authorization revocation.
387
53
  */
388
54
  export declare class KVCacheInvalidationStore implements CacheInvalidationStore {
389
- private readonly ns;
390
- constructor(ns: KVNamespace);
55
+ #private;
56
+ constructor(namespace: KVNamespaceSource);
57
+ private get ns();
391
58
  getVersion(key: string): Promise<string>;
392
59
  invalidate(key: string): Promise<void>;
393
60
  }
61
+ /**
62
+ * `CacheModule`'s value store over the KV namespace named `binding`, read from
63
+ * each application's `ENV` when an operation needs it:
64
+ * `CacheModule.forRoot({ namespace, scope, store: kvCache({ binding: 'CACHE' }) })`.
65
+ */
66
+ export declare function kvCache(ref: {
67
+ binding: string;
68
+ }): EnvFactory<CacheStore>;
69
+ /**
70
+ * `CacheModule`'s generation store over a dedicated KV namespace named
71
+ * `binding`, without TTLs or lifecycle cleanup. Eventually consistent; see
72
+ * {@link KVCacheInvalidationStore}.
73
+ */
74
+ export declare function kvCacheInvalidation(ref: {
75
+ binding: string;
76
+ }): EnvFactory<CacheInvalidationStore>;
394
77
  //#endregion
395
78
  //#region src/services/flagship-flag.driver.d.ts
396
79
  /**
@@ -517,43 +200,6 @@ interface QueueConsumerMetadata {
517
200
  */
518
201
  export declare function QueueConsumer(queueName: string): MethodDecorator;
519
202
  //#endregion
520
- //#region src/websocket/cloudflare-websocket.module.d.ts
521
- /**
522
- * Cloudflare counterpart to the core `WebSocketModule.forRoot()`. Import this in
523
- * your `AppModule` instead: it provides the gateway dispatcher plus a late-bound
524
- * `WS_SERVER` (`WsServerHolder`) that the WebSocket Durable Object wires to a
525
- * ctx-backed server per instance. `useClass` ensures a fresh holder per DI
526
- * container so colocated DO instances never share a server.
527
- */
528
- export declare class CloudflareWebSocketModule {
529
- static forRoot(): DynamicModule;
530
- }
531
- //#endregion
532
- //#region src/websocket/broadcast.d.ts
533
- interface WsBroadcastStub {
534
- broadcast(cmd: BroadcastCommand): Promise<void>;
535
- }
536
- interface BroadcastNamespace {
537
- idFromName(name: string): DurableObjectId;
538
- get(id: DurableObjectId): WsBroadcastStub;
539
- }
540
- /**
541
- * Push to a room from a Worker HTTP handler / cron / queue consumer (server-
542
- * initiated emit). Resolves the room's Durable Object and calls its `broadcast`
543
- * RPC method — the same canonical room→DO mapping the upgrade route uses, so it
544
- * always reaches the DO holding those sockets.
545
- *
546
- * @example
547
- * ```ts
548
- * // In a controller — ns from the typed Worker environment
549
- * await broadcastToRoom(ns, '/orgs/:orgId/ws', `org:${id}`, 'order.created', order);
550
- * ```
551
- */
552
- export declare function broadcastToRoom(ns: BroadcastNamespace, gatewayPath: string, room: string, event: string, data?: unknown, options?: {
553
- exceptIds?: string[];
554
- maxFrameBytes?: number;
555
- }): Promise<void>;
556
- //#endregion
557
203
  //#region src/websocket/do-state.d.ts
558
204
  /** Structural view of the DO's SQLite handle (`ctx.storage.sql`, requires `new_sqlite_classes`). */
559
205
  interface SqlStorageLike {
@@ -562,40 +208,40 @@ interface SqlStorageLike {
562
208
  };
563
209
  }
564
210
  //#endregion
565
- //#region src/websocket/do-live.d.ts
566
- /**
567
- * The durable `CursorLog`: an append-only tag-invalidation log in the DO's
568
- * SQLite (`__vela_live_log`, AUTOINCREMENT seq = cursor) plus an epoch UUID in
569
- * `__vela_live_meta`. Because the cursor survives hibernation AND trims (it is
570
- * read from `sqlite_sequence`, lunora's `ctx-db-cdc.ts` trick), a reconnecting
571
- * client whose gap the log still covers gets a tiny `resume` instead of a
572
- * re-run — the real-resume half of the live protocol.
573
- *
574
- * Constructed un-initialized at module-composition time (the same app module
575
- * bootstraps in the Worker AND in each DO); `initDoLive` wires the SQLite
576
- * handle inside the DO. In the Worker isolate it stays un-initialized — and is
577
- * never consulted there, because `durableObjectLive()` routes every
578
- * invalidation to the room DO's log (one log scope per room, exactly the
579
- * protocol's model).
580
- */
581
- export declare class DoCursorLog implements CursorLog {
582
- private readonly maxRows;
583
- private sql?;
584
- private epoch?;
585
- constructor(maxRows?: number);
586
- /** @internal — called by `initDoLive` with the DO's `ctx.storage.sql`. */
587
- _initialize(sql: SqlStorageLike): void;
588
- append(tags: string[]): CommitStamp;
589
- current(): CommitStamp;
590
- evaluateResume(sinceCursor: number, sinceEpoch: string, subscriptionTags: string[]): ResumeVerdict;
591
- private assertReady;
211
+ //#region src/websocket/binding-gateways.d.ts
212
+ /** A gateway whose rooms live in Durable Objects: its path and namespace binding. */
213
+ interface BindingGateway {
214
+ path: string;
215
+ binding: string;
216
+ /** The gateway class name, for diagnostics. */
217
+ name: string;
218
+ }
219
+ //#endregion
220
+ //#region src/websocket/worker-transport.d.ts
221
+ /** One gateway room's Durable Object: its id, and calls to its operations. */
222
+ interface GatewayRoomObject {
223
+ readonly id: unknown;
224
+ call(method: string, ...args: unknown[]): Promise<unknown>;
592
225
  }
226
+ //#endregion
227
+ //#region src/websocket/live-driver.d.ts
593
228
  interface DurableObjectLiveOptions {
594
- /** Native, RPC-typed namespace supplied by the application's environment. */
595
- namespace: LiveNamespace;
596
- /** Exact `@WebSocketGateway()` path sharing this room/log namespace. */
597
- gatewayPath: string;
598
- /** Room used when an invalidation names none. Matches the client default. */
229
+ /**
230
+ * Durable Object namespace binding that holds the gateway's rooms, read from
231
+ * the application's `ENV` when an invalidation first needs it. Defaults to
232
+ * the `binding` of the chosen gateway.
233
+ */
234
+ binding?: string;
235
+ /**
236
+ * Exact `@WebSocketGateway()` path whose rooms hold the subscriptions.
237
+ * Defaults to the single gateway backed by `binding` (or by any binding).
238
+ */
239
+ gatewayPath?: string;
240
+ /**
241
+ * Room used when an invalidation names none. Matches the client default. A
242
+ * gateway without `roomParam` has one room, its path, which every
243
+ * invalidation reaches.
244
+ */
599
245
  defaultRoom?: string;
600
246
  }
601
247
  interface LiveInvalidateStub {
@@ -606,53 +252,112 @@ interface LiveNamespace {
606
252
  idFromName(name: string): DurableObjectId;
607
253
  get(id: DurableObjectId): LiveInvalidateStub;
608
254
  }
609
- /** One driver per application; construct from a LiveModule driver factory. */
255
+ /** @internal What the Worker's live platform hands a driver. */
256
+ interface WorkerLiveContext {
257
+ env: VelaEnv;
258
+ gateways(): readonly Pick<BindingGateway, 'path' | 'binding'>[];
259
+ }
260
+ /**
261
+ * Delivers live invalidations to the room Durable Object of a
262
+ * `@WebSocketGateway({ binding })`, whose SQLite log stamps the commit. Inside
263
+ * that Durable Object the same driver applies invalidations locally.
264
+ */
610
265
  declare class CfLiveDriver implements LiveDriver {
266
+ #private;
611
267
  private readonly options;
612
268
  readonly kind = "durable-object";
613
- private sink;
614
- private localMode;
615
- constructor(options: DurableObjectLiveOptions);
269
+ constructor(options?: DurableObjectLiveOptions);
616
270
  bind(sink: LiveInvalidationSink): void;
617
- /** @internal — a DO dispatches to its own engine and SQLite log. */
271
+ /** @internal The Worker's live platform supplies its environment and gateways. */
272
+ _attach(context: WorkerLiveContext): void;
273
+ /** @internal A Durable Object dispatches to its own engine and SQLite log. */
618
274
  _setLocalMode(): void;
275
+ /**
276
+ * @internal The Durable Object that holds one room's subscriptions. As for
277
+ * upgrades and `Gateways` pushes, a gateway without `roomParam` keeps every
278
+ * socket in one room, its path, so each of its rooms is in that object.
279
+ */
280
+ _room(room: string): GatewayRoomObject;
619
281
  dispatch(cmd: InvalidationCommand): Promise<CommitStamp | undefined> | CommitStamp | undefined;
620
282
  }
621
- /** Use in LiveModule.forRootAsync: driver: () => durableObjectLive({ namespace: env.ROOMS, ... }). */
622
- export declare function durableObjectLive(options: DurableObjectLiveOptions): CfLiveDriver;
623
- /** Ergonomic alias: the log option for `LiveModule.forRoot` on Cloudflare. */
624
- export declare function durableObjectCursorLog(maxRows?: number): DoCursorLog;
283
+ /**
284
+ * The Cloudflare live driver, for `LiveModule.forRoot({ driver })`. It is the
285
+ * default on Cloudflare, so name it only to choose a gateway, binding or
286
+ * default room:
287
+ *
288
+ * ```ts
289
+ * LiveModule.forRoot({ driver: () => durableObjectLive({ gatewayPath: '/rooms/:id/ws' }) })
290
+ * ```
291
+ */
292
+ export declare function durableObjectLive(options?: DurableObjectLiveOptions): CfLiveDriver;
293
+ //#endregion
294
+ //#region src/websocket/do-live.d.ts
295
+ /**
296
+ * The durable `CursorLog`: an append-only tag-invalidation log in the DO's
297
+ * SQLite (`__vela_live_log`, AUTOINCREMENT seq = cursor) plus an epoch UUID in
298
+ * `__vela_live_meta`. Because the cursor survives hibernation AND trims (it is
299
+ * read from `sqlite_sequence`, lunora's `ctx-db-cdc.ts` trick), a reconnecting
300
+ * client whose gap the log still covers gets a tiny `resume` instead of a
301
+ * re-run — the real-resume half of the live protocol.
302
+ *
303
+ * The Cloudflare adapter gives `LiveModule` one inside every SQLite-backed
304
+ * WebSocket Durable Object (wrangler: `new_sqlite_classes`); a class without
305
+ * SQLite keeps an in-memory log. The Worker never consults a log: its
306
+ * invalidations go to the room Durable Object, one log scope per room, exactly
307
+ * the protocol's model.
308
+ */
309
+ export declare class DoCursorLog implements CursorLog {
310
+ private readonly sql;
311
+ private readonly maxRows;
312
+ private readonly epoch;
313
+ constructor(sql: SqlStorageLike, maxRows?: number);
314
+ append(tags: string[]): CommitStamp;
315
+ current(): CommitStamp;
316
+ evaluateResume(sinceCursor: number, sinceEpoch: string, subscriptionTags: string[]): ResumeVerdict;
317
+ }
625
318
  /**
626
319
  * Invalidate live tags in a room from a Worker (controller / cron / queue
627
- * consumer) — the live sibling of `broadcastToRoom`. Returns the room log
628
- * scope's commit stamp for `Vela-Commit-Cursor` stamping.
320
+ * consumer) through an explicit namespace. Returns the room log scope's
321
+ * commit stamp for `Vela-Commit-Cursor` stamping. As with the live driver, a
322
+ * gateway without roomParam keeps every room in one object, named by its path.
629
323
  */
630
324
  export declare function liveInvalidateToRoom(ns: LiveNamespace, gatewayPath: string, room: string, tags: string[]): Promise<CommitStamp | undefined>;
631
325
  //#endregion
632
326
  //#region src/rate-limit/cloudflare-rate-limit.store.d.ts
633
- /** The deliberately small surface exposed by a Workers Rate Limiting binding. */
634
- interface CloudflareRateLimitBinding {
635
- limit(input: {
636
- key: string;
637
- }): Promise<{
638
- success: boolean;
639
- }>;
640
- }
641
- interface CloudflareRateLimitStoreOptions {
642
- /** Must match the binding's configured `simple.limit`. */
643
- limit: number;
644
- /** Must match the binding's configured `simple.period`. */
645
- periodSeconds: 10 | 60;
646
- /** Bound attacker-influenced tracking keys before calling the platform. */
327
+ interface RateLimitStoreOptions {
328
+ /**
329
+ * The Workers Rate Limiting binding (declared under `ratelimits`) that
330
+ * serves every throttler, or one binding per named throttler:
331
+ * `{ burst: 'BURST_LIMITER', sustained: 'API_LIMITER' }`. Each binding's
332
+ * `simple.limit` and `simple.period` must equal its throttler's `limit` and
333
+ * `ttl`; the platform enforces them. One binding therefore serves only
334
+ * throttlers that share a limit and window: a throttler with other values,
335
+ * or one the map leaves out, fails the application's bootstrap instead of
336
+ * being enforced at the binding's.
337
+ */
338
+ binding: string | Readonly<Record<string, string>>;
339
+ /** Bound attacker-influenced tracking keys before calling the platform. Default 1024. */
647
340
  maxKeyBytes?: number;
648
341
  }
649
342
  /**
650
- * Adapt a Cloudflare Workers Rate Limiting binding to Vela's throttler store.
343
+ * `ThrottlerModule`'s storage over Workers Rate Limiting bindings, read from
344
+ * each application's `ENV` by name:
345
+ *
346
+ * ```ts
347
+ * ThrottlerModule.forRoot({
348
+ * throttlers: [{ ttl: 60_000, limit: 100 }],
349
+ * storage: rateLimitStore({ binding: 'API_LIMITER' }),
350
+ * })
351
+ * ```
651
352
  *
652
- * The platform binding makes the allow/deny decision. It does not expose exact
653
- * counters or reset timestamps, so this adapter intentionally omits `remaining`.
353
+ * The platform makes the allow/deny decision and exposes no counters or reset
354
+ * times, so the store reports no `remaining` quota. It enforces the limit and
355
+ * period configured on the binding, so it declares `fixedLimits`: a
356
+ * `@Throttle()` override that changes them fails instead of being ignored.
357
+ * Periods are 10 or 60 seconds. `ThrottlerModule` checks the declared
358
+ * throttlers against the bindings when the application starts.
654
359
  */
655
- export declare function cloudflareRateLimitStore(binding: CloudflareRateLimitBinding | (() => CloudflareRateLimitBinding), options: CloudflareRateLimitStoreOptions): ThrottlerStore;
360
+ export declare function rateLimitStore(options: RateLimitStoreOptions): EnvFactory<ThrottlerStore>;
656
361
  //#endregion
657
362
  //#region src/nonce/durable-object-nonce.store.d.ts
658
363
  /** The generated Workers binding type for {@link VelaNonceDurableObject}. */
@@ -681,4 +386,4 @@ interface DurableObjectNonceStoreOptions {
681
386
  */
682
387
  export declare function durableObjectNonceStore(options: DurableObjectNonceStoreOptions): NonceStore;
683
388
  //#endregion
684
- export { type BroadcastNamespace, type CfLiveDriver, type CloudflareRateLimitBinding, type CloudflareRateLimitStoreOptions, type CloudflareRoot, type CloudflareScheduledEvent, type CloudflareWorkerOptions, type CreateCloudflareAppOptions, type DiskConfig, type DoPitrArmOptions, type DoPitrArmResult, type DoPitrBookmarkRead, type DoPitrId, type DoPitrNamespace, type DoPitrStorage, DoPitrUnavailableError, type DurableObjectLiveOptions, type DurableObjectNonceNamespace, type DurableObjectNonceStoreOptions, type FlagshipBinding, type FlagshipFlagDriverOptions, type KvFlagDriverOptions, type LiveNamespace, type MountOpenApiOptions, type PresignedUrlConfig, type QueueConsumerMetadata, type ScheduledEvent, type StorageModuleOptions, type VelaDoPitrRpc, type WsGatewayRoute, armDoPitr, isDoPitrUnavailable, readDoPitrBookmark };
389
+ export { CLOUDFLARE_SCHEDULED_EVENT, CLOUDFLARE_WORKER, type CfLiveDriver, type CloudflareAppOptions, CloudflareApplication, type CloudflareRoot, type CloudflareScheduledEvent, type CloudflareWorker, type CloudflareWorkerDescriptor, type CloudflareWorkerOptions, type CreateCloudflareAppOptions, type DoPitrArmOptions, type DoPitrArmResult, type DoPitrBookmarkRead, type DoPitrId, type DoPitrNamespace, type DoPitrStorage, DoPitrUnavailableError, type DurableObjectLiveOptions, type DurableObjectNonceNamespace, type DurableObjectNonceStoreOptions, type FlagshipBinding, type FlagshipFlagDriverOptions, type KVNamespaceSource, type KvFlagDriverOptions, type LiveNamespace, type MountOpenApiOptions, type QueueConsumerMetadata, type RateLimitStoreOptions, type ScheduledEvent, type VelaDoPitrRpc, armDoPitr, cloudflareAdapter, createCloudflareApp, createCloudflareWorker, isDoPitrUnavailable, readDoPitrBookmark };