@velajs/cloudflare 1.10.0 → 1.10.1
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.
- package/CHANGELOG.md +8 -3
- package/dist/index.d.ts +805 -41
- package/dist/index.js +1645 -39
- package/dist/index.js.map +1 -0
- package/package.json +54 -40
- package/dist/binding-ref.d.ts +0 -8
- package/dist/binding-ref.js +0 -19
- package/dist/cloudflare-application.d.ts +0 -125
- package/dist/cloudflare-application.js +0 -186
- package/dist/cloudflare-factory.d.ts +0 -88
- package/dist/cloudflare-factory.js +0 -107
- package/dist/decorators/env.d.ts +0 -16
- package/dist/decorators/env.js +0 -22
- package/dist/decorators/queue-consumer.d.ts +0 -23
- package/dist/decorators/queue-consumer.js +0 -40
- package/dist/decorators/scheduled.d.ts +0 -20
- package/dist/decorators/scheduled.js +0 -36
- package/dist/env-ref.d.ts +0 -10
- package/dist/env-ref.js +0 -13
- package/dist/modules/ai.module.d.ts +0 -1
- package/dist/modules/ai.module.js +0 -8
- package/dist/modules/create-binding-module.d.ts +0 -14
- package/dist/modules/create-binding-module.js +0 -42
- package/dist/modules/d1.module.d.ts +0 -1
- package/dist/modules/d1.module.js +0 -8
- package/dist/modules/durable-object.module.d.ts +0 -1
- package/dist/modules/durable-object.module.js +0 -8
- package/dist/modules/env.module.d.ts +0 -17
- package/dist/modules/env.module.js +0 -35
- package/dist/modules/hyperdrive.module.d.ts +0 -1
- package/dist/modules/hyperdrive.module.js +0 -8
- package/dist/modules/kv.module.d.ts +0 -1
- package/dist/modules/kv.module.js +0 -8
- package/dist/modules/queue.module.d.ts +0 -1
- package/dist/modules/queue.module.js +0 -8
- package/dist/modules/r2.module.d.ts +0 -1
- package/dist/modules/r2.module.js +0 -8
- package/dist/modules/vectorize.module.d.ts +0 -1
- package/dist/modules/vectorize.module.js +0 -8
- package/dist/services/ai.service.d.ts +0 -6
- package/dist/services/ai.service.js +0 -33
- package/dist/services/d1.service.d.ts +0 -6
- package/dist/services/d1.service.js +0 -33
- package/dist/services/durable-object.service.d.ts +0 -6
- package/dist/services/durable-object.service.js +0 -33
- package/dist/services/env.service.d.ts +0 -31
- package/dist/services/env.service.js +0 -36
- package/dist/services/flagship-flag.driver.d.ts +0 -57
- package/dist/services/flagship-flag.driver.js +0 -49
- package/dist/services/hyperdrive.service.d.ts +0 -12
- package/dist/services/hyperdrive.service.js +0 -51
- package/dist/services/kv-cache.store.d.ts +0 -19
- package/dist/services/kv-cache.store.js +0 -58
- package/dist/services/kv-flag.driver.d.ts +0 -48
- package/dist/services/kv-flag.driver.js +0 -62
- package/dist/services/kv.service.d.ts +0 -11
- package/dist/services/kv.service.js +0 -33
- package/dist/services/queue.service.d.ts +0 -6
- package/dist/services/queue.service.js +0 -33
- package/dist/services/r2.service.d.ts +0 -6
- package/dist/services/r2.service.js +0 -33
- package/dist/services/vectorize.service.d.ts +0 -6
- package/dist/services/vectorize.service.js +0 -33
- package/dist/storage/index.d.ts +0 -7
- package/dist/storage/index.js +0 -6
- package/dist/storage/r2-storage.driver.d.ts +0 -19
- package/dist/storage/r2-storage.driver.js +0 -61
- package/dist/storage/storage-manager.service.d.ts +0 -16
- package/dist/storage/storage-manager.service.js +0 -56
- package/dist/storage/storage.controller.d.ts +0 -16
- package/dist/storage/storage.controller.js +0 -88
- package/dist/storage/storage.module.d.ts +0 -7
- package/dist/storage/storage.module.js +0 -37
- package/dist/storage/storage.service.d.ts +0 -20
- package/dist/storage/storage.service.js +0 -78
- package/dist/storage/storage.tokens.d.ts +0 -3
- package/dist/storage/storage.tokens.js +0 -2
- package/dist/storage/storage.types.d.ts +0 -17
- package/dist/storage/storage.types.js +0 -1
- package/dist/tokens.d.ts +0 -12
- package/dist/tokens.js +0 -12
- package/dist/types.d.ts +0 -13
- package/dist/types.js +0 -1
- package/dist/websocket/broadcast.d.ts +0 -15
- package/dist/websocket/broadcast.js +0 -26
- package/dist/websocket/cf-room-registry.d.ts +0 -23
- package/dist/websocket/cf-room-registry.js +0 -65
- package/dist/websocket/cf-ws-client.d.ts +0 -28
- package/dist/websocket/cf-ws-client.js +0 -83
- package/dist/websocket/cloudflare-websocket.module.d.ts +0 -11
- package/dist/websocket/cloudflare-websocket.module.js +0 -27
- package/dist/websocket/do-bootstrap.d.ts +0 -24
- package/dist/websocket/do-bootstrap.js +0 -55
- package/dist/websocket/do-live.d.ts +0 -81
- package/dist/websocket/do-live.js +0 -197
- package/dist/websocket/do-state.d.ts +0 -35
- package/dist/websocket/do-state.js +0 -4
- package/dist/websocket/do-websocket-host.d.ts +0 -28
- package/dist/websocket/do-websocket-host.js +0 -69
- package/dist/websocket/index.d.ts +0 -15
- package/dist/websocket/index.js +0 -15
- package/dist/websocket/room-id.d.ts +0 -6
- package/dist/websocket/room-id.js +0 -12
- package/dist/websocket/websocket-routing.d.ts +0 -14
- package/dist/websocket/websocket-routing.js +0 -45
- package/dist/websocket/websocket.durable-object.d.ts +0 -15
- package/dist/websocket/websocket.durable-object.js +0 -83
- package/dist/websocket/ws-server-holder.d.ts +0 -16
- package/dist/websocket/ws-server-holder.js +0 -34
package/dist/index.d.ts
CHANGED
|
@@ -1,41 +1,805 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
1
|
+
import { AsyncCacheStore, DynamicModule, InjectionToken, RuntimeAdapter, Type, VelaApplication } from "@velajs/vela";
|
|
2
|
+
import { ConnectedSocket, MessageBody, OnGatewayConnection, OnGatewayDisconnect, OnGatewayInit, SubscribeMessage, WebSocketGateway, WebSocketServer, WsClient, WsDispatcher, WsException, WsMessage, WsResponse, WsServer } from "@velajs/vela/websocket";
|
|
3
|
+
import { CommitStamp, CursorLog, LiveDriver, ResumeVerdict } from "@velajs/vela/live";
|
|
4
|
+
import { DownloadResult, PresignMethod, PresignedUrlResult, StorageBody, StorageDriver, UploadOptions, UploadResult } from "@velajs/vela/storage";
|
|
5
|
+
import { DurableObject } from "cloudflare:workers";
|
|
6
|
+
import { Context, Hono, MiddlewareHandler } from "hono";
|
|
7
|
+
import { FeatureFlagDriver, FlagContext } from "@velajs/feature-flags";
|
|
8
|
+
//#region src/websocket/websocket-routing.d.ts
|
|
9
|
+
interface WsGatewayRoute {
|
|
10
|
+
path: string;
|
|
11
|
+
binding: string;
|
|
12
|
+
}
|
|
13
|
+
//#endregion
|
|
14
|
+
//#region src/types.d.ts
|
|
15
|
+
interface CloudflareEnv {
|
|
16
|
+
[key: string]: unknown;
|
|
17
|
+
}
|
|
18
|
+
interface ScheduledRegistration {
|
|
19
|
+
instance: unknown;
|
|
20
|
+
methodName: string;
|
|
21
|
+
cron: string;
|
|
22
|
+
}
|
|
23
|
+
interface QueueRegistration {
|
|
24
|
+
instance: unknown;
|
|
25
|
+
methodName: string;
|
|
26
|
+
queueName: string;
|
|
27
|
+
}
|
|
28
|
+
//#endregion
|
|
29
|
+
//#region src/cloudflare-application.d.ts
|
|
30
|
+
/**
|
|
31
|
+
* Options accepted by {@link CloudflareApplication.mountOpenApi}.
|
|
32
|
+
*
|
|
33
|
+
* Re-exposes vela's `MountOpenApiOptions` type — derived structurally from
|
|
34
|
+
* the underlying `VelaApplication.mountOpenApi` signature so consumers don't
|
|
35
|
+
* have to reach into vela's internal subpaths to type the argument.
|
|
36
|
+
*/
|
|
37
|
+
type MountOpenApiOptions = Parameters<VelaApplication['mountOpenApi']>[0];
|
|
38
|
+
/**
|
|
39
|
+
* Wraps VelaApplication with Cloudflare-specific handlers:
|
|
40
|
+
* - `fetch` — HTTP request handler (from Hono)
|
|
41
|
+
* - `scheduled` — Cron trigger handler (matches `@Scheduled()` decorators
|
|
42
|
+
* AND vela's own `@Cron()` jobs)
|
|
43
|
+
* - `queue` — Queue consumer handler (matches `@QueueConsumer()` decorators)
|
|
44
|
+
* - `mountOpenApi` — Serve an OpenAPI document (and optional Scalar UI) on
|
|
45
|
+
* the underlying Hono app
|
|
46
|
+
*
|
|
47
|
+
* @example
|
|
48
|
+
* ```ts
|
|
49
|
+
* const app = await createCloudflareApp(AppModule);
|
|
50
|
+
* export default {
|
|
51
|
+
* fetch: app.fetch,
|
|
52
|
+
* scheduled: app.scheduled.bind(app),
|
|
53
|
+
* queue: app.queue.bind(app),
|
|
54
|
+
* };
|
|
55
|
+
* ```
|
|
56
|
+
*
|
|
57
|
+
* @example
|
|
58
|
+
* ```ts
|
|
59
|
+
* // Serve OpenAPI docs alongside your routes
|
|
60
|
+
* const app = await createCloudflareApp(AppModule);
|
|
61
|
+
* const document = createOpenApiDocument(AppModule);
|
|
62
|
+
* app.mountOpenApi({ document, ui: 'scalar' });
|
|
63
|
+
* // GET /openapi.json -> JSON document
|
|
64
|
+
* // GET /scalar -> Scalar UI (loads from CDN)
|
|
65
|
+
* ```
|
|
66
|
+
*/
|
|
67
|
+
declare class CloudflareApplication {
|
|
68
|
+
private app;
|
|
69
|
+
private wsGatewayRoutes;
|
|
70
|
+
constructor(app: VelaApplication);
|
|
71
|
+
get fetch(): Hono['fetch'];
|
|
72
|
+
getHonoApp(): Hono;
|
|
73
|
+
/**
|
|
74
|
+
* Resolve a provider from the application's DI container (delegates to
|
|
75
|
+
* `VelaApplication.get`). Handy for grabbing a service — e.g. an auth service —
|
|
76
|
+
* to use inside `createCloudflareApp({ middleware: [...] })` request middleware,
|
|
77
|
+
* which runs outside the DI request pipeline.
|
|
78
|
+
*
|
|
79
|
+
* @example
|
|
80
|
+
* ```ts
|
|
81
|
+
* const app = await createCloudflareApp(AppModule);
|
|
82
|
+
* const auth = app.get<BetterAuthService>(BetterAuthService);
|
|
83
|
+
* ```
|
|
84
|
+
*/
|
|
85
|
+
get<T>(token: Parameters<VelaApplication['get']>[0]): T;
|
|
86
|
+
/**
|
|
87
|
+
* Serve a pre-built OpenAPI document (and optionally a Scalar UI) on the
|
|
88
|
+
* underlying Hono app. Delegates verbatim to `VelaApplication.mountOpenApi`,
|
|
89
|
+
* so the JSON endpoint defaults to `/openapi.json` and the Scalar UI (when
|
|
90
|
+
* opted in) defaults to `/scalar`. Edge-safe — the UI HTML loads Scalar from
|
|
91
|
+
* a CDN at runtime, nothing is bundled server-side.
|
|
92
|
+
*
|
|
93
|
+
* @example
|
|
94
|
+
* ```ts
|
|
95
|
+
* import { createOpenApiDocument } from '@velajs/vela';
|
|
96
|
+
*
|
|
97
|
+
* const app = await createCloudflareApp(AppModule);
|
|
98
|
+
* const document = createOpenApiDocument(AppModule, {
|
|
99
|
+
* info: { title: 'My API', version: '1.0.0' },
|
|
100
|
+
* });
|
|
101
|
+
* app.mountOpenApi({ document, ui: 'scalar' });
|
|
102
|
+
* // GET /openapi.json -> { openapi: '3.1.0', ... }
|
|
103
|
+
* // GET /scalar -> Scalar UI HTML
|
|
104
|
+
* ```
|
|
105
|
+
*/
|
|
106
|
+
mountOpenApi(options: MountOpenApiOptions): this;
|
|
107
|
+
/**
|
|
108
|
+
* @internal — scans instances for `@WebSocketGateway({ path, binding })`
|
|
109
|
+
* upgrade routes. Queue/scheduled handlers are NOT scanned anymore: they
|
|
110
|
+
* come from `app.entrypoints` (`cf:queue` / `cf:scheduled` / `cf:vela-cron`
|
|
111
|
+
* kinds) at dispatch time.
|
|
112
|
+
*/
|
|
113
|
+
scanInstances(instances: unknown[]): void;
|
|
114
|
+
/** @internal — upgrade routes discovered from `@WebSocketGateway({ path, binding })`. */
|
|
115
|
+
getWsGatewayRoutes(): WsGatewayRoute[];
|
|
116
|
+
/**
|
|
117
|
+
* Handle Cloudflare scheduled (cron) events.
|
|
118
|
+
* Matches the event's cron expression to `@Scheduled()` and vela `@Cron()`
|
|
119
|
+
* handlers read from `app.entrypoints`; each handler runs inside a fresh
|
|
120
|
+
* request-scoped child (request-scoped providers rebuild per tick).
|
|
121
|
+
*/
|
|
122
|
+
scheduled(event: {
|
|
123
|
+
cron: string;
|
|
124
|
+
scheduledTime?: number;
|
|
125
|
+
}, env: CloudflareEnv, ctx: {
|
|
126
|
+
waitUntil: (promise: Promise<unknown>) => void;
|
|
127
|
+
}): Promise<void>;
|
|
128
|
+
/**
|
|
129
|
+
* Run one entrypoint handler inside a fresh request scope, through the
|
|
130
|
+
* shared guard → interceptor pipeline (components declared with
|
|
131
|
+
* `@UseGuards`/`@UseInterceptors`/`@UseFilters` on the consumer class or
|
|
132
|
+
* method). HTTP-global components deliberately do NOT apply — an HTTP auth
|
|
133
|
+
* guard has no business rejecting a queue batch. Unclaimed errors rethrow
|
|
134
|
+
* so the platform's retry semantics stay intact.
|
|
135
|
+
*/
|
|
136
|
+
private dispatchEntrypoint;
|
|
137
|
+
/**
|
|
138
|
+
* Handle Cloudflare Queue consumer events.
|
|
139
|
+
* Matches the batch queue name to `@QueueConsumer()` handlers read from
|
|
140
|
+
* `app.entrypoints`; each batch is processed inside a fresh request-scoped
|
|
141
|
+
* child (request-scoped providers rebuild per batch — no boot-time captives).
|
|
142
|
+
*/
|
|
143
|
+
queue(batch: {
|
|
144
|
+
queue: string;
|
|
145
|
+
messages: unknown[];
|
|
146
|
+
}, env: CloudflareEnv, ctx: {
|
|
147
|
+
waitUntil: (promise: Promise<unknown>) => void;
|
|
148
|
+
}): Promise<void>;
|
|
149
|
+
close(signal?: string): Promise<void>;
|
|
150
|
+
}
|
|
151
|
+
//#endregion
|
|
152
|
+
//#region src/cloudflare-factory.d.ts
|
|
153
|
+
/**
|
|
154
|
+
* Options for {@link createCloudflareApp}.
|
|
155
|
+
*
|
|
156
|
+
* Mirrors a tight subset of vela's `BootstrapOptions` — only the surface
|
|
157
|
+
* that makes sense for a Workers consumer is re-exposed.
|
|
158
|
+
*/
|
|
159
|
+
interface CreateCloudflareAppOptions {
|
|
160
|
+
/**
|
|
161
|
+
* Forwarded to `VelaFactory.create({ globalPrefix })`. Prepended to every
|
|
162
|
+
* route registered by `@Controller(...)` (and any other route emitter)
|
|
163
|
+
* inside the application, so a value of `'/v1'` turns `@Controller('/users')`
|
|
164
|
+
* into `/v1/users`.
|
|
165
|
+
*
|
|
166
|
+
* @example
|
|
167
|
+
* ```ts
|
|
168
|
+
* const app = await createCloudflareApp(AppModule, { globalPrefix: '/v1' });
|
|
169
|
+
* ```
|
|
170
|
+
*/
|
|
171
|
+
globalPrefix?: string;
|
|
172
|
+
/**
|
|
173
|
+
* Extra Hono middleware to register on the underlying Hono app. Runs
|
|
174
|
+
* AFTER the one-time binding-init middleware this adapter mounts
|
|
175
|
+
* internally, so any handler in `middleware` can safely read from
|
|
176
|
+
* `BindingRef` instances and Cloudflare env bindings.
|
|
177
|
+
*
|
|
178
|
+
* @example
|
|
179
|
+
* ```ts
|
|
180
|
+
* const app = await createCloudflareApp(AppModule, {
|
|
181
|
+
* middleware: [
|
|
182
|
+
* async (c, next) => {
|
|
183
|
+
* c.set('requestId', crypto.randomUUID());
|
|
184
|
+
* await next();
|
|
185
|
+
* },
|
|
186
|
+
* ],
|
|
187
|
+
* });
|
|
188
|
+
* ```
|
|
189
|
+
*/
|
|
190
|
+
middleware?: MiddlewareHandler[];
|
|
191
|
+
}
|
|
192
|
+
/**
|
|
193
|
+
* Create a Cloudflare Workers application.
|
|
194
|
+
*
|
|
195
|
+
* Sets up a one-time Hono middleware that captures `c.env` on the first
|
|
196
|
+
* request and initializes all configured binding refs. Optional
|
|
197
|
+
* {@link CreateCloudflareAppOptions} are forwarded to the underlying
|
|
198
|
+
* `VelaFactory.create` so consumers don't have to wrap the resulting
|
|
199
|
+
* application in an outer Hono just to set a `globalPrefix` or attach
|
|
200
|
+
* extra request middleware.
|
|
201
|
+
*
|
|
202
|
+
* @example
|
|
203
|
+
* ```ts
|
|
204
|
+
* // Minimal — backwards compatible
|
|
205
|
+
* const app = await createCloudflareApp(AppModule);
|
|
206
|
+
* export default app; // has .fetch, .scheduled, .queue
|
|
207
|
+
* ```
|
|
208
|
+
*
|
|
209
|
+
* @example
|
|
210
|
+
* ```ts
|
|
211
|
+
* // With a global prefix and outer middleware
|
|
212
|
+
* const app = await createCloudflareApp(AppModule, {
|
|
213
|
+
* globalPrefix: '/v1',
|
|
214
|
+
* middleware: [
|
|
215
|
+
* async (c, next) => {
|
|
216
|
+
* c.set('tenantId', c.req.header('x-tenant-id') ?? 'public');
|
|
217
|
+
* await next();
|
|
218
|
+
* },
|
|
219
|
+
* ],
|
|
220
|
+
* });
|
|
221
|
+
* ```
|
|
222
|
+
*/
|
|
223
|
+
/**
|
|
224
|
+
* The Cloudflare platform binding as a vela {@link RuntimeAdapter}: a one-time
|
|
225
|
+
* request middleware captures `c.env` on the first request and initializes
|
|
226
|
+
* every `BindingRef`/`EnvRef` (collected at `onBootstrap`, before any request
|
|
227
|
+
* can arrive). Adapter `requestMiddleware` is prepended to the global chain by
|
|
228
|
+
* `VelaFactory.create`, so user middleware can safely read binding refs.
|
|
229
|
+
*
|
|
230
|
+
* Exposed so consumers composing `VelaFactory.create` themselves can opt in:
|
|
231
|
+
*
|
|
232
|
+
* ```ts
|
|
233
|
+
* const app = await VelaFactory.create(AppModule, { adapters: [cloudflareAdapter()] });
|
|
234
|
+
* ```
|
|
235
|
+
*/
|
|
236
|
+
declare function cloudflareAdapter(): RuntimeAdapter;
|
|
237
|
+
declare function createCloudflareApp(rootModule: Type, options?: CreateCloudflareAppOptions): Promise<CloudflareApplication>;
|
|
238
|
+
//#endregion
|
|
239
|
+
//#region src/binding-ref.d.ts
|
|
240
|
+
declare class BindingRef<T = unknown> {
|
|
241
|
+
readonly bindingName: string;
|
|
242
|
+
private _value;
|
|
243
|
+
constructor(bindingName: string);
|
|
244
|
+
get value(): T;
|
|
245
|
+
/** @internal — called by createCloudflareApp middleware */
|
|
246
|
+
_initialize(value: T): void;
|
|
247
|
+
}
|
|
248
|
+
//#endregion
|
|
249
|
+
//#region src/modules/create-binding-module.d.ts
|
|
250
|
+
interface BindingModuleStatic {
|
|
251
|
+
forRoot(options: {
|
|
252
|
+
binding: string;
|
|
253
|
+
}): DynamicModule;
|
|
254
|
+
}
|
|
255
|
+
//#endregion
|
|
256
|
+
//#region src/modules/kv.module.d.ts
|
|
257
|
+
declare const KVModule: BindingModuleStatic;
|
|
258
|
+
//#endregion
|
|
259
|
+
//#region src/modules/d1.module.d.ts
|
|
260
|
+
declare const D1Module: BindingModuleStatic;
|
|
261
|
+
//#endregion
|
|
262
|
+
//#region src/modules/r2.module.d.ts
|
|
263
|
+
declare const R2Module: BindingModuleStatic;
|
|
264
|
+
//#endregion
|
|
265
|
+
//#region src/modules/queue.module.d.ts
|
|
266
|
+
declare const QueueModule: BindingModuleStatic;
|
|
267
|
+
//#endregion
|
|
268
|
+
//#region src/modules/durable-object.module.d.ts
|
|
269
|
+
declare const DurableObjectModule: BindingModuleStatic;
|
|
270
|
+
//#endregion
|
|
271
|
+
//#region src/modules/ai.module.d.ts
|
|
272
|
+
declare const AIModule: BindingModuleStatic;
|
|
273
|
+
//#endregion
|
|
274
|
+
//#region src/modules/vectorize.module.d.ts
|
|
275
|
+
declare const VectorizeModule: BindingModuleStatic;
|
|
276
|
+
//#endregion
|
|
277
|
+
//#region src/modules/hyperdrive.module.d.ts
|
|
278
|
+
declare const HyperdriveModule: BindingModuleStatic;
|
|
279
|
+
//#endregion
|
|
280
|
+
//#region src/modules/env.module.d.ts
|
|
281
|
+
/**
|
|
282
|
+
* Provides {@link EnvService} GLOBALLY so any module's provider factories can
|
|
283
|
+
* `inject: [EnvService]`. Register once on the root module:
|
|
284
|
+
*
|
|
285
|
+
* ```ts
|
|
286
|
+
* @Module({ imports: [EnvModule.forRoot(), AuthModule.forRootAsync({ ... })] })
|
|
287
|
+
* class AppModule {}
|
|
288
|
+
* ```
|
|
289
|
+
*
|
|
290
|
+
* The {@link EnvRef} it provides is collected and initialized by
|
|
291
|
+
* createCloudflareApp's binding-init middleware on the first request (the
|
|
292
|
+
* factory passes it the full `env`, not a single binding).
|
|
293
|
+
*/
|
|
294
|
+
declare class EnvModule {
|
|
295
|
+
static forRoot(): DynamicModule;
|
|
296
|
+
}
|
|
297
|
+
//#endregion
|
|
298
|
+
//#region src/storage/storage.types.d.ts
|
|
299
|
+
/** A named storage disk backed by an R2 bucket binding. */
|
|
300
|
+
interface DiskConfig {
|
|
301
|
+
disk: string;
|
|
302
|
+
/** R2Bucket binding name from wrangler.toml. */
|
|
303
|
+
binding: string;
|
|
304
|
+
/** Optional root prefix; supports path-template tokens ({date}/{year}/…). */
|
|
305
|
+
root?: string;
|
|
306
|
+
}
|
|
307
|
+
interface PresignedUrlConfig {
|
|
308
|
+
defaultExpiry: number;
|
|
309
|
+
maxExpiry: number;
|
|
310
|
+
}
|
|
311
|
+
interface StorageModuleOptions {
|
|
312
|
+
disks: DiskConfig[];
|
|
313
|
+
defaultDisk: string;
|
|
314
|
+
presignedUrl?: PresignedUrlConfig;
|
|
315
|
+
}
|
|
316
|
+
//#endregion
|
|
317
|
+
//#region src/storage/storage.module.d.ts
|
|
318
|
+
declare const ConfigurableModuleClass: import("@velajs/vela").ConfigurableModuleClassType<StorageModuleOptions, "forRoot", "create", {
|
|
319
|
+
isGlobal?: boolean;
|
|
320
|
+
}>;
|
|
321
|
+
declare class StorageModule extends ConfigurableModuleClass {}
|
|
322
|
+
//#endregion
|
|
323
|
+
//#region src/env-ref.d.ts
|
|
324
|
+
/**
|
|
325
|
+
* Holds the entire Cloudflare Worker `env` record (bindings + vars/secrets),
|
|
326
|
+
* not a single binding. Subclasses {@link BindingRef} so createCloudflareApp's
|
|
327
|
+
* binding-init middleware collects and initializes it through the same path;
|
|
328
|
+
* the factory special-cases it to pass the full `env` instead of one binding.
|
|
329
|
+
*/
|
|
330
|
+
declare class EnvRef extends BindingRef<Record<string, unknown>> {
|
|
331
|
+
constructor();
|
|
332
|
+
}
|
|
333
|
+
//#endregion
|
|
334
|
+
//#region src/services/env.service.d.ts
|
|
335
|
+
/**
|
|
336
|
+
* Injectable access to the full Cloudflare Worker `env` (bindings + vars +
|
|
337
|
+
* secrets).
|
|
338
|
+
*
|
|
339
|
+
* The per-binding services (`D1Service`, `KVService`, …) each expose a single
|
|
340
|
+
* binding, and the `@Env()` param decorator only works inside a request-scoped
|
|
341
|
+
* controller handler. `EnvService` fills the gap: it can be injected into
|
|
342
|
+
* PROVIDER FACTORIES — e.g. `SomeModule.forRootAsync({ inject: [EnvService] })`
|
|
343
|
+
* — so a factory can read secrets/origins without reaching for the request.
|
|
344
|
+
*
|
|
345
|
+
* Reads are lazy. `env` only exists per request, so a factory (which runs at
|
|
346
|
+
* bootstrap) must capture the `EnvService` and read inside its callback:
|
|
347
|
+
*
|
|
348
|
+
* ```ts
|
|
349
|
+
* AuthModule.forRootAsync({
|
|
350
|
+
* inject: [EnvService],
|
|
351
|
+
* useFactory: (env: EnvService) => buildAuth(() => env.get<string>('AUTH_SECRET')),
|
|
352
|
+
* });
|
|
353
|
+
* ```
|
|
354
|
+
*
|
|
355
|
+
* Reading eagerly at bootstrap (`env.get(...)` before any request) throws.
|
|
356
|
+
*/
|
|
357
|
+
declare class EnvService {
|
|
358
|
+
private ref;
|
|
359
|
+
constructor(ref: EnvRef);
|
|
360
|
+
/** The full env record. Throws if read before the first request. */
|
|
361
|
+
get env(): Record<string, unknown>;
|
|
362
|
+
/** Read a single env entry (binding, var, or secret) by name. */
|
|
363
|
+
get<T = unknown>(key: string): T | undefined;
|
|
364
|
+
}
|
|
365
|
+
//#endregion
|
|
366
|
+
//#region src/storage/r2-storage.driver.d.ts
|
|
367
|
+
interface R2StorageDriverConfig {
|
|
368
|
+
disk: string;
|
|
369
|
+
bucket: R2Bucket;
|
|
370
|
+
/** HMAC secret for presigned URLs (typically env.APP_SECRET). */
|
|
371
|
+
secret?: string;
|
|
372
|
+
}
|
|
373
|
+
/** {@link StorageDriver} over a Cloudflare R2 bucket. */
|
|
374
|
+
declare class R2StorageDriver implements StorageDriver {
|
|
375
|
+
private readonly config;
|
|
376
|
+
constructor(config: R2StorageDriverConfig);
|
|
377
|
+
upload(body: StorageBody, path: string, options: UploadOptions): Promise<UploadResult>;
|
|
378
|
+
download(path: string): Promise<DownloadResult>;
|
|
379
|
+
delete(path: string): Promise<void>;
|
|
380
|
+
exists(path: string): Promise<boolean>;
|
|
381
|
+
getPresignedUrl(path: string, method: PresignMethod, expiresIn: number): Promise<PresignedUrlResult>;
|
|
382
|
+
}
|
|
383
|
+
//#endregion
|
|
384
|
+
//#region src/storage/storage-manager.service.d.ts
|
|
385
|
+
/**
|
|
386
|
+
* Resolves R2 buckets by binding NAME (via {@link EnvService}) so multiple disks
|
|
387
|
+
* coexist without registering N R2Modules. Drivers are created per call — cheap,
|
|
388
|
+
* and avoids caching a per-request env value on this singleton.
|
|
389
|
+
*/
|
|
390
|
+
declare class StorageManagerService {
|
|
391
|
+
private readonly options;
|
|
392
|
+
private readonly env;
|
|
393
|
+
constructor(options: StorageModuleOptions, env: EnvService);
|
|
394
|
+
hasDisk(disk: string): boolean;
|
|
395
|
+
getDiskConfig(disk: string): DiskConfig;
|
|
396
|
+
getDriver(disk: string): R2StorageDriver;
|
|
397
|
+
}
|
|
398
|
+
//#endregion
|
|
399
|
+
//#region src/storage/storage.service.d.ts
|
|
400
|
+
/**
|
|
401
|
+
* Multi-disk storage facade. Applies each disk's (templated) root, resolves the
|
|
402
|
+
* driver, and validates presign expiry. Injectable anywhere via `StorageService`.
|
|
403
|
+
*/
|
|
404
|
+
declare class StorageService {
|
|
405
|
+
private readonly options;
|
|
406
|
+
private readonly manager;
|
|
407
|
+
constructor(options: StorageModuleOptions, manager: StorageManagerService);
|
|
408
|
+
put(relativePath: string, body: StorageBody, options?: UploadOptions, disk?: string): Promise<UploadResult>;
|
|
409
|
+
get(relativePath: string, disk?: string): Promise<DownloadResult>;
|
|
410
|
+
delete(relativePath: string, disk?: string): Promise<void>;
|
|
411
|
+
exists(relativePath: string, disk?: string): Promise<boolean>;
|
|
412
|
+
url(relativePath: string, method?: PresignMethod, expiresIn?: number, disk?: string): Promise<PresignedUrlResult>;
|
|
413
|
+
private resolveDisk;
|
|
414
|
+
private fullPath;
|
|
415
|
+
private validateExpiry;
|
|
416
|
+
}
|
|
417
|
+
//#endregion
|
|
418
|
+
//#region src/storage/storage.controller.d.ts
|
|
419
|
+
/**
|
|
420
|
+
* Presign-proxy: serves objects for HMAC-signed URLs produced by
|
|
421
|
+
* `StorageService.url()`. R2 has no native presign, so a signed URL points here;
|
|
422
|
+
* this route verifies the signature (+expiry) before streaming the object.
|
|
423
|
+
* The wildcard is the FULL object path (root already applied at sign time), so
|
|
424
|
+
* it is passed straight to the driver.
|
|
425
|
+
*/
|
|
426
|
+
declare class StorageController {
|
|
427
|
+
private readonly manager;
|
|
428
|
+
private readonly env;
|
|
429
|
+
constructor(manager: StorageManagerService, env: EnvService);
|
|
430
|
+
download(c: Context): Promise<Response>;
|
|
431
|
+
}
|
|
432
|
+
//#endregion
|
|
433
|
+
//#region src/storage/storage.tokens.d.ts
|
|
434
|
+
declare const STORAGE_OPTIONS: InjectionToken<StorageModuleOptions>;
|
|
435
|
+
//#endregion
|
|
436
|
+
//#region src/services/kv.service.d.ts
|
|
437
|
+
/**
|
|
438
|
+
* Wrapper around a Cloudflare KV namespace binding.
|
|
439
|
+
* Use `kv.namespace.get(...)`, `kv.namespace.put(...)`, etc. — the namespace
|
|
440
|
+
* is the standard @cloudflare/workers-types `KVNamespace`.
|
|
441
|
+
*/
|
|
442
|
+
declare class KVService {
|
|
443
|
+
private ref;
|
|
444
|
+
constructor(ref: BindingRef<KVNamespace>);
|
|
445
|
+
get namespace(): KVNamespace;
|
|
446
|
+
}
|
|
447
|
+
//#endregion
|
|
448
|
+
//#region src/services/kv-cache.store.d.ts
|
|
449
|
+
/**
|
|
450
|
+
* Cloudflare KV-backed {@link CacheStore}. Values are JSON-encoded. Intended as
|
|
451
|
+
* the slow tier under a `TieredCacheStore` (memory L1 → KV L2), but usable
|
|
452
|
+
* standalone as `CacheModule.forRootAsync({ inject: [KVService], useFactory: (kv) => ({ store: new KVCacheStore(kv) }) })`.
|
|
453
|
+
*
|
|
454
|
+
* Note: Cloudflare KV requires `expirationTtl >= 60s`, so sub-minute TTLs are
|
|
455
|
+
* clamped up. Keep short TTLs on the memory tier; use KV for longer-lived entries.
|
|
456
|
+
*/
|
|
457
|
+
declare class KVCacheStore implements AsyncCacheStore {
|
|
458
|
+
private readonly kv;
|
|
459
|
+
constructor(kv: KVService);
|
|
460
|
+
private get ns();
|
|
461
|
+
get<T = unknown>(key: string): Promise<T | undefined>;
|
|
462
|
+
set<T = unknown>(key: string, value: T, ttl?: number): Promise<void>;
|
|
463
|
+
del(key: string): Promise<void>;
|
|
464
|
+
clear(): Promise<void>;
|
|
465
|
+
}
|
|
466
|
+
//#endregion
|
|
467
|
+
//#region src/services/d1.service.d.ts
|
|
468
|
+
declare class D1Service {
|
|
469
|
+
private ref;
|
|
470
|
+
constructor(ref: BindingRef<D1Database>);
|
|
471
|
+
get database(): D1Database;
|
|
472
|
+
}
|
|
473
|
+
//#endregion
|
|
474
|
+
//#region src/services/r2.service.d.ts
|
|
475
|
+
declare class R2Service {
|
|
476
|
+
private ref;
|
|
477
|
+
constructor(ref: BindingRef<R2Bucket>);
|
|
478
|
+
get bucket(): R2Bucket;
|
|
479
|
+
}
|
|
480
|
+
//#endregion
|
|
481
|
+
//#region src/services/queue.service.d.ts
|
|
482
|
+
declare class QueueService<Body = unknown> {
|
|
483
|
+
private ref;
|
|
484
|
+
constructor(ref: BindingRef<Queue<Body>>);
|
|
485
|
+
get queue(): Queue<Body>;
|
|
486
|
+
}
|
|
487
|
+
//#endregion
|
|
488
|
+
//#region src/services/durable-object.service.d.ts
|
|
489
|
+
declare class DurableObjectService {
|
|
490
|
+
private ref;
|
|
491
|
+
constructor(ref: BindingRef<DurableObjectNamespace>);
|
|
492
|
+
get namespace(): DurableObjectNamespace;
|
|
493
|
+
}
|
|
494
|
+
//#endregion
|
|
495
|
+
//#region src/services/ai.service.d.ts
|
|
496
|
+
declare class AIService {
|
|
497
|
+
private ref;
|
|
498
|
+
constructor(ref: BindingRef<Ai>);
|
|
499
|
+
get binding(): Ai;
|
|
500
|
+
}
|
|
501
|
+
//#endregion
|
|
502
|
+
//#region src/services/vectorize.service.d.ts
|
|
503
|
+
declare class VectorizeService {
|
|
504
|
+
private ref;
|
|
505
|
+
constructor(ref: BindingRef<VectorizeIndex>);
|
|
506
|
+
get index(): VectorizeIndex;
|
|
507
|
+
}
|
|
508
|
+
//#endregion
|
|
509
|
+
//#region src/services/hyperdrive.service.d.ts
|
|
510
|
+
declare class HyperdriveService {
|
|
511
|
+
private ref;
|
|
512
|
+
constructor(ref: BindingRef<Hyperdrive>);
|
|
513
|
+
get binding(): Hyperdrive;
|
|
514
|
+
get connectionString(): string;
|
|
515
|
+
get host(): string;
|
|
516
|
+
get port(): number;
|
|
517
|
+
get user(): string;
|
|
518
|
+
get password(): string;
|
|
519
|
+
get database(): string;
|
|
520
|
+
}
|
|
521
|
+
//#endregion
|
|
522
|
+
//#region src/services/flagship-flag.driver.d.ts
|
|
523
|
+
/**
|
|
524
|
+
* The subset of a Cloudflare **Flagship** binding this driver evaluates against
|
|
525
|
+
* — the four typed value methods. The binding itself returns the supplied
|
|
526
|
+
* `defaultValue` on evaluation errors; transport-level failures reject and are
|
|
527
|
+
* left to propagate (never-throw is the service layer's job, not the driver's).
|
|
528
|
+
*
|
|
529
|
+
* @see https://developers.cloudflare.com/flagship/binding/
|
|
530
|
+
*/
|
|
531
|
+
interface FlagshipBinding {
|
|
532
|
+
getBooleanValue(key: string, defaultValue: boolean, context?: FlagContext): Promise<boolean>;
|
|
533
|
+
getStringValue(key: string, defaultValue: string, context?: FlagContext): Promise<string>;
|
|
534
|
+
getNumberValue(key: string, defaultValue: number, context?: FlagContext): Promise<number>;
|
|
535
|
+
getObjectValue<T extends object>(key: string, defaultValue: T, context?: FlagContext): Promise<T>;
|
|
536
|
+
}
|
|
537
|
+
interface FlagshipFlagDriverOptions {
|
|
538
|
+
/** Driver name used for `use(name)` / default-driver selection. Default `"flagship"`. */
|
|
539
|
+
name?: string;
|
|
540
|
+
}
|
|
541
|
+
/**
|
|
542
|
+
* {@link FeatureFlagDriver} backed by a Cloudflare Flagship binding.
|
|
543
|
+
*
|
|
544
|
+
* A thin, honest wrapper: each contract method maps 1:1 onto the binding's
|
|
545
|
+
* corresponding value method, forwarding the caller's `fallback` (the binding's
|
|
546
|
+
* `defaultValue`) and evaluation context. The binding resolves the fallback on
|
|
547
|
+
* evaluation errors; anything the binding *rejects* with (e.g. a `remote: true`
|
|
548
|
+
* dev-proxy tunnel dropping) propagates — `@velajs/feature-flags`'s service owns
|
|
549
|
+
* the never-throw guarantee.
|
|
550
|
+
*
|
|
551
|
+
* The binding only exists per request in a Worker, so pass a lazy accessor when
|
|
552
|
+
* wiring from a bootstrap factory (mirroring how {@link EnvService} reads are
|
|
553
|
+
* deferred); a resolved binding may be passed directly in tests.
|
|
554
|
+
*
|
|
555
|
+
* ```ts
|
|
556
|
+
* FeatureFlagsModule.forRootAsync({
|
|
557
|
+
* inject: [EnvService],
|
|
558
|
+
* useFactory: (env: EnvService) => ({
|
|
559
|
+
* drivers: [flagshipFlagDriver(() => env.get<FlagshipBinding>('FLAGS')!)],
|
|
560
|
+
* }),
|
|
561
|
+
* });
|
|
562
|
+
* ```
|
|
563
|
+
*
|
|
564
|
+
* Evaluation ergonomics (the 1:1 binding-method mapping) are ported from the
|
|
565
|
+
* Stratal feature-flags service (MIT, © Temitayo Fadojutimi), reshaped as a
|
|
566
|
+
* bare driver.
|
|
567
|
+
*/
|
|
568
|
+
declare class FlagshipFlagDriver implements FeatureFlagDriver {
|
|
569
|
+
readonly name: string;
|
|
570
|
+
private readonly resolve;
|
|
571
|
+
constructor(binding: FlagshipBinding | (() => FlagshipBinding), options?: FlagshipFlagDriverOptions);
|
|
572
|
+
getBoolean(key: string, fallback: boolean, ctx?: FlagContext): Promise<boolean>;
|
|
573
|
+
getString(key: string, fallback: string, ctx?: FlagContext): Promise<string>;
|
|
574
|
+
getNumber(key: string, fallback: number, ctx?: FlagContext): Promise<number>;
|
|
575
|
+
getObject<T extends object>(key: string, fallback: T, ctx?: FlagContext): Promise<T>;
|
|
576
|
+
}
|
|
577
|
+
/** Convenience factory for {@link FlagshipFlagDriver}. */
|
|
578
|
+
declare function flagshipFlagDriver(binding: FlagshipBinding | (() => FlagshipBinding), options?: FlagshipFlagDriverOptions): FlagshipFlagDriver;
|
|
579
|
+
//#endregion
|
|
580
|
+
//#region src/services/kv-flag.driver.d.ts
|
|
581
|
+
interface KvFlagDriverOptions {
|
|
582
|
+
/** Driver name used for `use(name)` / default-driver selection. Default `"kv"`. */
|
|
583
|
+
name?: string;
|
|
584
|
+
/** Prefix prepended to every flag key before the KV read. Default `""` (none). */
|
|
585
|
+
prefix?: string;
|
|
586
|
+
}
|
|
587
|
+
/**
|
|
588
|
+
* Cloudflare KV-backed {@link FeatureFlagDriver}. Flags are stored as JSON
|
|
589
|
+
* values under an optional key prefix and read with `get(key, 'json')`. Reads
|
|
590
|
+
* are type-checked against the requested type: a missing key or a value of the
|
|
591
|
+
* wrong JSON type returns the caller's `fallback`. KV has no targeting, so the
|
|
592
|
+
* evaluation context is ignored.
|
|
593
|
+
*
|
|
594
|
+
* The driver stays honest — it does **not** swallow errors. A KV failure (or a
|
|
595
|
+
* `SyntaxError` from a malformed stored value) propagates; the never-throw
|
|
596
|
+
* guarantee lives in `@velajs/feature-flags`'s service layer.
|
|
597
|
+
*
|
|
598
|
+
* Placed like {@link KVCacheStore}: construct it in a wiring factory over a
|
|
599
|
+
* resolved {@link KVService}.
|
|
600
|
+
*
|
|
601
|
+
* ```ts
|
|
602
|
+
* FeatureFlagsModule.forRootAsync({
|
|
603
|
+
* inject: [KVService],
|
|
604
|
+
* useFactory: (kv: KVService) => ({ drivers: [new KvFlagDriver(kv, { prefix: 'flag:' })] }),
|
|
605
|
+
* });
|
|
606
|
+
* ```
|
|
607
|
+
*/
|
|
608
|
+
declare class KvFlagDriver implements FeatureFlagDriver {
|
|
609
|
+
private readonly kv;
|
|
610
|
+
readonly name: string;
|
|
611
|
+
private readonly prefix;
|
|
612
|
+
constructor(kv: KVService, options?: KvFlagDriverOptions);
|
|
613
|
+
private get ns();
|
|
614
|
+
getBoolean(key: string, fallback: boolean, _ctx?: FlagContext): Promise<boolean>;
|
|
615
|
+
getString(key: string, fallback: string, _ctx?: FlagContext): Promise<string>;
|
|
616
|
+
getNumber(key: string, fallback: number, _ctx?: FlagContext): Promise<number>;
|
|
617
|
+
getObject<T extends object>(key: string, fallback: T, _ctx?: FlagContext): Promise<T>;
|
|
618
|
+
/**
|
|
619
|
+
* Reads and JSON-parses the (prefixed) key, returning the parsed value only
|
|
620
|
+
* when `matches` accepts its type; otherwise the caller's fallback. A missing
|
|
621
|
+
* key reads as `null` → fallback. Read/parse errors are left to propagate.
|
|
622
|
+
*/
|
|
623
|
+
private read;
|
|
624
|
+
}
|
|
625
|
+
/** Convenience factory for {@link KvFlagDriver}. */
|
|
626
|
+
declare function kvFlagDriver(kv: KVService, options?: KvFlagDriverOptions): KvFlagDriver;
|
|
627
|
+
//#endregion
|
|
628
|
+
//#region src/decorators/env.d.ts
|
|
629
|
+
/**
|
|
630
|
+
* Parameter decorator to inject Cloudflare environment bindings.
|
|
631
|
+
*
|
|
632
|
+
* Without arguments, returns the entire `env` object.
|
|
633
|
+
* With a binding name, returns that specific binding.
|
|
634
|
+
*
|
|
635
|
+
* @example
|
|
636
|
+
* ```ts
|
|
637
|
+
* @Get()
|
|
638
|
+
* handle(@Env() env: CloudflareEnv) { ... }
|
|
639
|
+
*
|
|
640
|
+
* @Get()
|
|
641
|
+
* handle(@Env('MY_KV') kv: KVNamespace) { ... }
|
|
642
|
+
* ```
|
|
643
|
+
*/
|
|
644
|
+
declare const Env: (data?: string | undefined, ...pipes: import("@velajs/vela").PipeType[]) => ParameterDecorator;
|
|
645
|
+
//#endregion
|
|
646
|
+
//#region src/decorators/scheduled.d.ts
|
|
647
|
+
interface ScheduledMetadata {
|
|
648
|
+
cron: string;
|
|
649
|
+
methodName: string;
|
|
650
|
+
}
|
|
651
|
+
/**
|
|
652
|
+
* Marks a method as a scheduled (cron) handler.
|
|
653
|
+
*
|
|
654
|
+
* @example
|
|
655
|
+
* ```ts
|
|
656
|
+
* @Injectable()
|
|
657
|
+
* class WorkerService {
|
|
658
|
+
* @Scheduled('0 * * * *')
|
|
659
|
+
* async hourlyCron() {
|
|
660
|
+
* console.log('Running hourly');
|
|
661
|
+
* }
|
|
662
|
+
* }
|
|
663
|
+
* ```
|
|
664
|
+
*/
|
|
665
|
+
declare function Scheduled(cron: string): MethodDecorator;
|
|
666
|
+
//#endregion
|
|
667
|
+
//#region src/decorators/queue-consumer.d.ts
|
|
668
|
+
interface QueueConsumerMetadata {
|
|
669
|
+
queueName: string;
|
|
670
|
+
methodName: string;
|
|
671
|
+
}
|
|
672
|
+
/**
|
|
673
|
+
* Marks a method as a queue consumer handler.
|
|
674
|
+
*
|
|
675
|
+
* @example
|
|
676
|
+
* ```ts
|
|
677
|
+
* @Injectable()
|
|
678
|
+
* class WorkerService {
|
|
679
|
+
* @QueueConsumer('email-queue')
|
|
680
|
+
* async processEmails(batch: MessageBatch) {
|
|
681
|
+
* for (const msg of batch.messages) {
|
|
682
|
+
* console.log('Processing:', msg.body);
|
|
683
|
+
* msg.ack();
|
|
684
|
+
* }
|
|
685
|
+
* }
|
|
686
|
+
* }
|
|
687
|
+
* ```
|
|
688
|
+
*/
|
|
689
|
+
declare function QueueConsumer(queueName: string): MethodDecorator;
|
|
690
|
+
//#endregion
|
|
691
|
+
//#region src/websocket/websocket.durable-object.d.ts
|
|
692
|
+
/**
|
|
693
|
+
* Base class for the WebSocket Durable Object. The user exports a named subclass
|
|
694
|
+
* (matching their `wrangler.toml` `class_name`) built from their `AppModule`:
|
|
695
|
+
*
|
|
696
|
+
* ```ts
|
|
697
|
+
* export class ChatRoom extends VelaWebSocketDurableObject(AppModule) {}
|
|
698
|
+
* ```
|
|
699
|
+
*
|
|
700
|
+
* It owns the raw hibernation socket lifecycle (Hono's `upgradeWebSocket` cannot
|
|
701
|
+
* bridge DO hibernation) and forwards every event into the runtime-agnostic
|
|
702
|
+
* `WsDispatcher` via {@link DoWebSocketHost}.
|
|
703
|
+
*/
|
|
704
|
+
declare function VelaWebSocketDurableObject(rootModule: Type): new (ctx: DurableObjectState, env: Record<string, unknown>) => DurableObject<Record<string, unknown>>;
|
|
705
|
+
//#endregion
|
|
706
|
+
//#region src/websocket/cloudflare-websocket.module.d.ts
|
|
707
|
+
/**
|
|
708
|
+
* Cloudflare counterpart to the core `WebSocketModule.forRoot()`. Import this in
|
|
709
|
+
* your `AppModule` instead: it provides the gateway dispatcher plus a late-bound
|
|
710
|
+
* `WS_SERVER` (`WsServerHolder`) that the WebSocket Durable Object wires to a
|
|
711
|
+
* ctx-backed server per instance. `useClass` ensures a fresh holder per DI
|
|
712
|
+
* container so colocated DO instances never share a server.
|
|
713
|
+
*/
|
|
714
|
+
declare class CloudflareWebSocketModule {
|
|
715
|
+
static forRoot(): DynamicModule;
|
|
716
|
+
}
|
|
717
|
+
//#endregion
|
|
718
|
+
//#region src/websocket/broadcast.d.ts
|
|
719
|
+
/**
|
|
720
|
+
* Push to a room from a Worker HTTP handler / cron / queue consumer (server-
|
|
721
|
+
* initiated emit). Resolves the room's Durable Object and calls its `broadcast`
|
|
722
|
+
* RPC method — the same canonical room→DO mapping the upgrade route uses, so it
|
|
723
|
+
* always reaches the DO holding those sockets.
|
|
724
|
+
*
|
|
725
|
+
* @example
|
|
726
|
+
* ```ts
|
|
727
|
+
* // In a controller — ns from DurableObjectService.namespace
|
|
728
|
+
* await broadcastToRoom(ns, `org:${id}`, 'order.created', order);
|
|
729
|
+
* ```
|
|
730
|
+
*/
|
|
731
|
+
declare function broadcastToRoom(ns: DurableObjectNamespace, room: string, event: string, data?: unknown, options?: {
|
|
732
|
+
exceptIds?: string[];
|
|
733
|
+
}): Promise<void>;
|
|
734
|
+
//#endregion
|
|
735
|
+
//#region src/websocket/do-state.d.ts
|
|
736
|
+
/** Structural view of the DO's SQLite handle (`ctx.storage.sql`, requires `new_sqlite_classes`). */
|
|
737
|
+
interface SqlStorageLike {
|
|
738
|
+
exec(query: string, ...bindings: unknown[]): {
|
|
739
|
+
toArray(): Record<string, unknown>[];
|
|
740
|
+
};
|
|
741
|
+
}
|
|
742
|
+
//#endregion
|
|
743
|
+
//#region src/websocket/do-live.d.ts
|
|
744
|
+
/**
|
|
745
|
+
* The durable `CursorLog`: an append-only tag-invalidation log in the DO's
|
|
746
|
+
* SQLite (`__vela_live_log`, AUTOINCREMENT seq = cursor) plus an epoch UUID in
|
|
747
|
+
* `__vela_live_meta`. Because the cursor survives hibernation AND trims (it is
|
|
748
|
+
* read from `sqlite_sequence`, lunora's `ctx-db-cdc.ts` trick), a reconnecting
|
|
749
|
+
* client whose gap the log still covers gets a tiny `resume` instead of a
|
|
750
|
+
* re-run — the real-resume half of the live protocol.
|
|
751
|
+
*
|
|
752
|
+
* Constructed un-initialized at module-composition time (the same app module
|
|
753
|
+
* bootstraps in the Worker AND in each DO); `initDoLive` wires the SQLite
|
|
754
|
+
* handle inside the DO. In the Worker isolate it stays un-initialized — and is
|
|
755
|
+
* never consulted there, because `durableObjectLive()` routes every
|
|
756
|
+
* invalidation to the room DO's log (one log scope per room, exactly the
|
|
757
|
+
* protocol's model).
|
|
758
|
+
*/
|
|
759
|
+
declare class DoCursorLog implements CursorLog {
|
|
760
|
+
private readonly maxRows;
|
|
761
|
+
private sql?;
|
|
762
|
+
private epoch?;
|
|
763
|
+
constructor(maxRows?: number);
|
|
764
|
+
/** @internal — called by `initDoLive` with the DO's `ctx.storage.sql`. */
|
|
765
|
+
_initialize(sql: SqlStorageLike): void;
|
|
766
|
+
append(tags: string[]): CommitStamp;
|
|
767
|
+
current(): CommitStamp;
|
|
768
|
+
evaluateResume(sinceCursor: number, sinceEpoch: string, subscriptionTags: string[]): ResumeVerdict;
|
|
769
|
+
private assertReady;
|
|
770
|
+
}
|
|
771
|
+
interface DurableObjectLiveOptions {
|
|
772
|
+
/** The wrangler binding name of the WebSocket DO namespace (e.g. `'CHAT_ROOM'`). */
|
|
773
|
+
binding: string;
|
|
774
|
+
/** Room used when an invalidation names none. Matches the client default. */
|
|
775
|
+
defaultRoom?: string;
|
|
776
|
+
}
|
|
777
|
+
interface CfLiveDriver extends LiveDriver {
|
|
778
|
+
/** @internal — Worker isolate: capture `env` so the namespace binding resolves per dispatch. */
|
|
779
|
+
_initializeEnv(env: Record<string, unknown>): void;
|
|
780
|
+
/** @internal — DO isolate: deliver invalidations straight to this DO's engine. */
|
|
781
|
+
_setLocalMode(): void;
|
|
782
|
+
}
|
|
783
|
+
/**
|
|
784
|
+
* The Cloudflare `LiveDriver`. Dual-mode, because the SAME app module
|
|
785
|
+
* bootstraps in both isolates:
|
|
786
|
+
*
|
|
787
|
+
* - **Worker** (HTTP mutations, queue consumers, crons): route the command to
|
|
788
|
+
* the room's Durable Object over the `invalidate` RPC — the same canonical
|
|
789
|
+
* `roomToDurableId` mapping the upgrade route and `broadcastToRoom` use —
|
|
790
|
+
* and return THAT log scope's commit stamp (what `Vela-Commit-Cursor`
|
|
791
|
+
* must carry).
|
|
792
|
+
* - **DO** (writes issued from inside the object): apply to the local engine.
|
|
793
|
+
*/
|
|
794
|
+
declare function durableObjectLive(options: DurableObjectLiveOptions): CfLiveDriver;
|
|
795
|
+
/** Ergonomic alias: the log option for `LiveModule.forRoot` on Cloudflare. */
|
|
796
|
+
declare function durableObjectCursorLog(maxRows?: number): DoCursorLog;
|
|
797
|
+
/**
|
|
798
|
+
* Invalidate live tags in a room from a Worker (controller / cron / queue
|
|
799
|
+
* consumer) — the live sibling of `broadcastToRoom`. Returns the room log
|
|
800
|
+
* scope's commit stamp for `Vela-Commit-Cursor` stamping.
|
|
801
|
+
*/
|
|
802
|
+
declare function liveInvalidateToRoom(ns: DurableObjectNamespace, room: string, tags: string[]): Promise<CommitStamp | undefined>;
|
|
803
|
+
//#endregion
|
|
804
|
+
export { AIModule, AIService, type CfLiveDriver, CloudflareApplication, type CloudflareEnv, CloudflareWebSocketModule, ConnectedSocket, type CreateCloudflareAppOptions, D1Module, D1Service, type DiskConfig, DoCursorLog, type DurableObjectLiveOptions, DurableObjectModule, DurableObjectService, Env, EnvModule, EnvService, type FlagshipBinding, FlagshipFlagDriver, type FlagshipFlagDriverOptions, HyperdriveModule, HyperdriveService, KVCacheStore, KVModule, KVService, KvFlagDriver, type KvFlagDriverOptions, MessageBody, type MountOpenApiOptions, type OnGatewayConnection, type OnGatewayDisconnect, type OnGatewayInit, type PresignedUrlConfig, QueueConsumer, type QueueConsumerMetadata, QueueModule, type QueueRegistration, QueueService, R2Module, R2Service, R2StorageDriver, STORAGE_OPTIONS, Scheduled, type ScheduledMetadata, type ScheduledRegistration, StorageController, StorageManagerService, StorageModule, type StorageModuleOptions, StorageService, SubscribeMessage, VectorizeModule, VectorizeService, VelaWebSocketDurableObject, WebSocketGateway, WebSocketServer, type WsClient, WsException, type WsGatewayRoute, type WsMessage, type WsResponse, type WsServer, broadcastToRoom, cloudflareAdapter, createCloudflareApp, durableObjectCursorLog, durableObjectLive, flagshipFlagDriver, kvFlagDriver, liveInvalidateToRoom };
|
|
805
|
+
//# sourceMappingURL=index.d.ts.map
|