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