@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.
- package/CHANGELOG.md +136 -0
- package/README.md +262 -75
- package/dist/bindings.js +77 -0
- package/dist/bindings.js.map +1 -0
- package/dist/cloudflare-application.js +282 -0
- package/dist/cloudflare-application.js.map +1 -0
- package/dist/cloudflare-factory-eGiet0mg.d.ts +288 -0
- package/dist/cloudflare-factory.js +165 -0
- package/dist/cloudflare-factory.js.map +1 -0
- package/dist/decorators/queue-consumer.js +39 -0
- package/dist/decorators/queue-consumer.js.map +1 -0
- package/dist/diagnostics.js +18 -0
- package/dist/diagnostics.js.map +1 -0
- package/dist/durable-objects.d.ts +8 -5
- package/dist/durable-objects.js +2 -524
- package/dist/environment.js +19 -0
- package/dist/environment.js.map +1 -0
- package/dist/index.d.ts +163 -456
- package/dist/index.js +15 -1276
- package/dist/nonce/durable-object-nonce.store.js +33 -0
- package/dist/nonce/durable-object-nonce.store.js.map +1 -0
- package/dist/nonce/nonce-validation.js +18 -0
- package/dist/nonce/nonce-validation.js.map +1 -0
- package/dist/nonce/nonce.durable-object.js +54 -0
- package/dist/nonce/nonce.durable-object.js.map +1 -0
- package/dist/{nonce.durable-object-Df4CZi-0.d.ts → nonce.durable-object-Bg1e0BMD.d.ts} +1 -12
- package/dist/platform.js +22 -0
- package/dist/platform.js.map +1 -0
- package/dist/queue/cloudflare-queues.js +215 -0
- package/dist/queue/cloudflare-queues.js.map +1 -0
- package/dist/queues.d.ts +1 -2
- package/dist/queues.js +1 -214
- package/dist/rate-limit/cloudflare-rate-limit.store.js +79 -0
- package/dist/rate-limit/cloudflare-rate-limit.store.js.map +1 -0
- package/dist/root-module-C23bUwt_.d.ts +11 -0
- package/dist/schedule-diagnostics.js +44 -0
- package/dist/schedule-diagnostics.js.map +1 -0
- package/dist/scheduled-event.js +68 -0
- package/dist/scheduled-event.js.map +1 -0
- package/dist/services/flagship-flag.driver.js +52 -0
- package/dist/services/flagship-flag.driver.js.map +1 -0
- package/dist/services/kv-cache.store.js +108 -0
- package/dist/services/kv-cache.store.js.map +1 -0
- package/dist/services/kv-flag.driver.js +62 -0
- package/dist/services/kv-flag.driver.js.map +1 -0
- package/dist/storage/r2-storage.js +30 -0
- package/dist/storage/r2-storage.js.map +1 -0
- package/dist/storage.d.ts +28 -0
- package/dist/storage.js +2 -0
- package/dist/testing.d.ts +96 -0
- package/dist/testing.js +111 -0
- package/dist/testing.js.map +1 -0
- package/dist/vela-env-DFvyoNT3.d.ts +1 -2
- package/dist/websocket/binding-gateways.js +33 -0
- package/dist/websocket/binding-gateways.js.map +1 -0
- package/dist/websocket/cf-room-registry.js +139 -0
- package/dist/websocket/cf-room-registry.js.map +1 -0
- package/dist/websocket/cf-ws-client.js +94 -0
- package/dist/websocket/cf-ws-client.js.map +1 -0
- package/dist/websocket/do-bootstrap.js +77 -0
- package/dist/websocket/do-bootstrap.js.map +1 -0
- package/dist/websocket/do-live.js +143 -0
- package/dist/websocket/do-live.js.map +1 -0
- package/dist/websocket/do-pitr.js +81 -0
- package/dist/websocket/do-pitr.js.map +1 -0
- package/dist/websocket/do-state.js +7 -0
- package/dist/websocket/do-state.js.map +1 -0
- package/dist/websocket/do-websocket-host.js +169 -0
- package/dist/websocket/do-websocket-host.js.map +1 -0
- package/dist/websocket/live-driver.js +149 -0
- package/dist/websocket/live-driver.js.map +1 -0
- package/dist/websocket/room-id.js +37 -0
- package/dist/websocket/room-id.js.map +1 -0
- package/dist/websocket/websocket.durable-object.js +142 -0
- package/dist/websocket/websocket.durable-object.js.map +1 -0
- package/dist/websocket/worker-transport.js +80 -0
- package/dist/websocket/worker-transport.js.map +1 -0
- package/dist/websocket/ws-attachment.js +79 -0
- package/dist/websocket/ws-attachment.js.map +1 -0
- package/package.json +26 -7
- package/dist/durable-objects.js.map +0 -1
- package/dist/index.js.map +0 -1
- package/dist/nonce-validation-Dy8z05A9.js +0 -522
- package/dist/nonce-validation-Dy8z05A9.js.map +0 -1
- package/dist/queues.js.map +0 -1
package/dist/bindings.js
ADDED
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import { defineBinding } from "@velajs/vela/module-kit";
|
|
2
|
+
//#region src/bindings.ts
|
|
3
|
+
/** Whether a value exposes every named operation as a function. */
|
|
4
|
+
function hasOperations(value, operations) {
|
|
5
|
+
if (typeof value !== "object" || value === null) return false;
|
|
6
|
+
return operations.every((operation) => typeof Reflect.get(value, operation) === "function");
|
|
7
|
+
}
|
|
8
|
+
/**
|
|
9
|
+
* Name-based Workers binding factories. Each takes `{ binding }`, the name
|
|
10
|
+
* declared in the Wrangler configuration, and returns a reference that reads
|
|
11
|
+
* and validates the native binding from an application's `ENV` when called.
|
|
12
|
+
* Declaring one reads no environment, so references belong in static module
|
|
13
|
+
* options: `CacheModule.forRoot({ namespace, scope, store: kvCache({ binding: 'CACHE' }) })`.
|
|
14
|
+
*/
|
|
15
|
+
/** A KV namespace declared under `kv_namespaces`. */
|
|
16
|
+
const KV_NAMESPACE = {
|
|
17
|
+
name: "KV namespace",
|
|
18
|
+
configKey: "kv_namespaces",
|
|
19
|
+
accepts: (value) => hasOperations(value, [
|
|
20
|
+
"get",
|
|
21
|
+
"put",
|
|
22
|
+
"delete",
|
|
23
|
+
"list",
|
|
24
|
+
"getWithMetadata"
|
|
25
|
+
])
|
|
26
|
+
};
|
|
27
|
+
const kv = /* @__PURE__ */ defineBinding(KV_NAMESPACE);
|
|
28
|
+
/** An R2 bucket declared under `r2_buckets`. */
|
|
29
|
+
const R2_BUCKET = {
|
|
30
|
+
name: "R2 bucket",
|
|
31
|
+
configKey: "r2_buckets",
|
|
32
|
+
accepts: (value) => hasOperations(value, [
|
|
33
|
+
"get",
|
|
34
|
+
"put",
|
|
35
|
+
"head",
|
|
36
|
+
"delete",
|
|
37
|
+
"list",
|
|
38
|
+
"createMultipartUpload"
|
|
39
|
+
])
|
|
40
|
+
};
|
|
41
|
+
const r2 = /* @__PURE__ */ defineBinding(R2_BUCKET);
|
|
42
|
+
/** A D1 database declared under `d1_databases`. */
|
|
43
|
+
const D1_DATABASE = {
|
|
44
|
+
name: "D1 database",
|
|
45
|
+
configKey: "d1_databases",
|
|
46
|
+
accepts: (value) => hasOperations(value, [
|
|
47
|
+
"prepare",
|
|
48
|
+
"batch",
|
|
49
|
+
"exec"
|
|
50
|
+
])
|
|
51
|
+
};
|
|
52
|
+
const d1 = /* @__PURE__ */ defineBinding(D1_DATABASE);
|
|
53
|
+
/** A queue producer declared under `queues.producers`. */
|
|
54
|
+
const QUEUE_PRODUCER = {
|
|
55
|
+
name: "queue producer",
|
|
56
|
+
configKey: "queues.producers",
|
|
57
|
+
accepts: (value) => hasOperations(value, ["send"])
|
|
58
|
+
};
|
|
59
|
+
const queue = /* @__PURE__ */ defineBinding(QUEUE_PRODUCER);
|
|
60
|
+
/** A Durable Object namespace declared under `durable_objects.bindings`. */
|
|
61
|
+
const DURABLE_OBJECT_NAMESPACE = {
|
|
62
|
+
name: "Durable Object namespace",
|
|
63
|
+
configKey: "durable_objects.bindings",
|
|
64
|
+
accepts: (value) => hasOperations(value, ["idFromName", "get"])
|
|
65
|
+
};
|
|
66
|
+
const durableObject = /* @__PURE__ */ defineBinding(DURABLE_OBJECT_NAMESPACE);
|
|
67
|
+
/** A Workers Rate Limiting binding declared under `ratelimits`. */
|
|
68
|
+
const RATE_LIMITER = {
|
|
69
|
+
name: "rate limiter",
|
|
70
|
+
configKey: "ratelimits",
|
|
71
|
+
accepts: (value) => hasOperations(value, ["limit"])
|
|
72
|
+
};
|
|
73
|
+
const rateLimit = /* @__PURE__ */ defineBinding(RATE_LIMITER);
|
|
74
|
+
//#endregion
|
|
75
|
+
export { D1_DATABASE, DURABLE_OBJECT_NAMESPACE, KV_NAMESPACE, QUEUE_PRODUCER, R2_BUCKET, RATE_LIMITER, d1, durableObject, kv, queue, r2, rateLimit };
|
|
76
|
+
|
|
77
|
+
//# sourceMappingURL=bindings.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"bindings.js","names":[],"sources":["../src/bindings.ts"],"sourcesContent":["import { defineBinding, type BindingKind } from '@velajs/vela/module-kit';\n\n/** Whether a value exposes every named operation as a function. */\nfunction hasOperations(value: unknown, operations: readonly string[]): boolean {\n if (typeof value !== 'object' || value === null) return false;\n return operations.every((operation) => typeof Reflect.get(value, operation) === 'function');\n}\n\n/**\n * Name-based Workers binding factories. Each takes `{ binding }`, the name\n * declared in the Wrangler configuration, and returns a reference that reads\n * and validates the native binding from an application's `ENV` when called.\n * Declaring one reads no environment, so references belong in static module\n * options: `CacheModule.forRoot({ namespace, scope, store: kvCache({ binding: 'CACHE' }) })`.\n */\n\n/** A KV namespace declared under `kv_namespaces`. */\nexport const KV_NAMESPACE: BindingKind<KVNamespace> = {\n name: 'KV namespace',\n configKey: 'kv_namespaces',\n accepts: (value): value is KVNamespace =>\n hasOperations(value, ['get', 'put', 'delete', 'list', 'getWithMetadata']),\n};\nexport const kv = /* @__PURE__ */ defineBinding(KV_NAMESPACE);\n\n/** An R2 bucket declared under `r2_buckets`. */\nexport const R2_BUCKET: BindingKind<R2Bucket> = {\n name: 'R2 bucket',\n configKey: 'r2_buckets',\n accepts: (value): value is R2Bucket =>\n hasOperations(value, ['get', 'put', 'head', 'delete', 'list', 'createMultipartUpload']),\n};\nexport const r2 = /* @__PURE__ */ defineBinding(R2_BUCKET);\n\n/** A D1 database declared under `d1_databases`. */\nexport const D1_DATABASE: BindingKind<D1Database> = {\n name: 'D1 database',\n configKey: 'd1_databases',\n accepts: (value): value is D1Database => hasOperations(value, ['prepare', 'batch', 'exec']),\n};\nexport const d1 = /* @__PURE__ */ defineBinding(D1_DATABASE);\n\n/** A queue producer declared under `queues.producers`. */\nexport const QUEUE_PRODUCER: BindingKind<Queue> = {\n name: 'queue producer',\n configKey: 'queues.producers',\n accepts: (value): value is Queue => hasOperations(value, ['send']),\n};\nexport const queue = /* @__PURE__ */ defineBinding(QUEUE_PRODUCER);\n\n/** A Durable Object namespace declared under `durable_objects.bindings`. */\nexport const DURABLE_OBJECT_NAMESPACE: BindingKind<DurableObjectNamespace> = {\n name: 'Durable Object namespace',\n configKey: 'durable_objects.bindings',\n accepts: (value): value is DurableObjectNamespace => hasOperations(value, ['idFromName', 'get']),\n};\nexport const durableObject = /* @__PURE__ */ defineBinding(DURABLE_OBJECT_NAMESPACE);\n\n/** A Workers Rate Limiting binding declared under `ratelimits`. */\nexport const RATE_LIMITER: BindingKind<RateLimit> = {\n name: 'rate limiter',\n configKey: 'ratelimits',\n accepts: (value): value is RateLimit => hasOperations(value, ['limit']),\n};\nexport const rateLimit = /* @__PURE__ */ defineBinding(RATE_LIMITER);\n"],"mappings":";;;AAGA,SAAS,cAAc,OAAgB,YAAwC;CAC7E,IAAI,OAAO,UAAU,YAAY,UAAU,MAAM,OAAO;CACxD,OAAO,WAAW,OAAO,cAAc,OAAO,QAAQ,IAAI,OAAO,SAAS,MAAM,UAAU;AAC5F;;;;;;;;;AAWA,MAAa,eAAyC;CACpD,MAAM;CACN,WAAW;CACX,UAAU,UACR,cAAc,OAAO;EAAC;EAAO;EAAO;EAAU;EAAQ;CAAiB,CAAC;AAC5E;AACA,MAAa,KAAqB,8BAAc,YAAY;;AAG5D,MAAa,YAAmC;CAC9C,MAAM;CACN,WAAW;CACX,UAAU,UACR,cAAc,OAAO;EAAC;EAAO;EAAO;EAAQ;EAAU;EAAQ;CAAuB,CAAC;AAC1F;AACA,MAAa,KAAqB,8BAAc,SAAS;;AAGzD,MAAa,cAAuC;CAClD,MAAM;CACN,WAAW;CACX,UAAU,UAA+B,cAAc,OAAO;EAAC;EAAW;EAAS;CAAM,CAAC;AAC5F;AACA,MAAa,KAAqB,8BAAc,WAAW;;AAG3D,MAAa,iBAAqC;CAChD,MAAM;CACN,WAAW;CACX,UAAU,UAA0B,cAAc,OAAO,CAAC,MAAM,CAAC;AACnE;AACA,MAAa,QAAwB,8BAAc,cAAc;;AAGjE,MAAa,2BAAgE;CAC3E,MAAM;CACN,WAAW;CACX,UAAU,UAA2C,cAAc,OAAO,CAAC,cAAc,KAAK,CAAC;AACjG;AACA,MAAa,gBAAgC,8BAAc,wBAAwB;;AAGnF,MAAa,eAAuC;CAClD,MAAM;CACN,WAAW;CACX,UAAU,UAA8B,cAAc,OAAO,CAAC,OAAO,CAAC;AACxE;AACA,MAAa,YAA4B,8BAAc,YAAY"}
|
|
@@ -0,0 +1,282 @@
|
|
|
1
|
+
import { assertCloudflareEnvironment } from "./environment.js";
|
|
2
|
+
import { CLOUDFLARE_SCHEDULED_EVENT, cloudflareScheduledEvent } from "./scheduled-event.js";
|
|
3
|
+
import { PipelineRunner, buildEntrypointExecutionContext, getEntrypointModuleId, invokeScheduledJob, parseCronMetadata, resolveEntrypoint, resolveErrorReporter, resolveScopedComponentsAsync, runInEntrypointScope, shouldFilterCatch } from "@velajs/vela/module-kit";
|
|
4
|
+
//#region src/cloudflare-application.ts
|
|
5
|
+
function invoke(instance, methodName, args) {
|
|
6
|
+
const method = Reflect.get(instance, methodName);
|
|
7
|
+
if (typeof method !== "function") throw new Error(`Method '${String(methodName)}' is not a function on ${instance.constructor.name}`);
|
|
8
|
+
return Reflect.apply(method, instance, args);
|
|
9
|
+
}
|
|
10
|
+
function entrypointString(meta, property) {
|
|
11
|
+
if (typeof meta !== "object" || meta === null) throw new Error("Invalid entrypoint metadata.");
|
|
12
|
+
const value = Reflect.get(meta, property);
|
|
13
|
+
if (typeof value !== "string") throw new Error(`Invalid entrypoint metadata: ${property} must be a string.`);
|
|
14
|
+
return value;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* `QueueModule`'s native consumer reports each failure of a batch once itself
|
|
18
|
+
* (processor failures where they ran, transport failures on settlement), so
|
|
19
|
+
* its rejection is not reported again here.
|
|
20
|
+
*/
|
|
21
|
+
const SELF_REPORTING_KINDS = /* @__PURE__ */ new Set(["cf:queue:module"]);
|
|
22
|
+
const warnedRawJobs = /* @__PURE__ */ new Set();
|
|
23
|
+
/** The logical queue of a Vela job envelope, without importing the queue subsystem. */
|
|
24
|
+
function envelopeQueue(body) {
|
|
25
|
+
if (typeof body !== "object" || body === null) return void 0;
|
|
26
|
+
const queue = Reflect.get(body, "queue");
|
|
27
|
+
if (typeof queue !== "string" || typeof Reflect.get(body, "id") !== "string" || typeof Reflect.get(body, "name") !== "string" || !("data" in body)) return;
|
|
28
|
+
return queue;
|
|
29
|
+
}
|
|
30
|
+
/** Wait for every matching handler, even when one fails before its siblings. */
|
|
31
|
+
async function settleEntrypoints(work) {
|
|
32
|
+
const errors = (await Promise.allSettled(work)).flatMap((outcome) => outcome.status === "rejected" ? [outcome.reason] : []);
|
|
33
|
+
if (errors.length === 1) throw errors[0];
|
|
34
|
+
if (errors.length > 1) throw new AggregateError(errors, "Multiple entrypoint handlers failed.");
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Wraps VelaApplication with Cloudflare-specific handlers:
|
|
38
|
+
* - `fetch` — HTTP request handler (from Hono)
|
|
39
|
+
* - `scheduled` — Cron trigger handler (runs the `@Cron()` jobs whose
|
|
40
|
+
* expression is the trigger's exact string)
|
|
41
|
+
* - `queue` — Queue consumer handler (`@QueueConsumer()` by physical queue,
|
|
42
|
+
* then `QueueModule`'s native consumer)
|
|
43
|
+
* - `mountOpenApi` — Serve an OpenAPI document (and optional Scalar UI) on
|
|
44
|
+
* the underlying Hono app
|
|
45
|
+
*
|
|
46
|
+
* @example
|
|
47
|
+
* ```ts
|
|
48
|
+
* const app = await createCloudflareApp(AppModule, { env });
|
|
49
|
+
* export default {
|
|
50
|
+
* fetch: app.fetch,
|
|
51
|
+
* scheduled: app.scheduled.bind(app),
|
|
52
|
+
* queue: app.queue.bind(app),
|
|
53
|
+
* };
|
|
54
|
+
* ```
|
|
55
|
+
*
|
|
56
|
+
* @example
|
|
57
|
+
* ```ts
|
|
58
|
+
* // Serve OpenAPI docs alongside your routes
|
|
59
|
+
* const app = await createCloudflareApp(AppModule, { env });
|
|
60
|
+
* const document = createOpenApiDocument(AppModule);
|
|
61
|
+
* app.mountOpenApi({ document, ui: 'scalar' });
|
|
62
|
+
* // GET /openapi.json -> JSON document
|
|
63
|
+
* // GET /scalar -> Scalar UI (loads from CDN)
|
|
64
|
+
* ```
|
|
65
|
+
*/
|
|
66
|
+
var CloudflareApplication = class {
|
|
67
|
+
env;
|
|
68
|
+
#app;
|
|
69
|
+
/** Scheduled triggers in flight; close() aborts their signals and awaits them. */
|
|
70
|
+
#scheduled = /* @__PURE__ */ new Map();
|
|
71
|
+
constructor(app, env) {
|
|
72
|
+
this.env = env;
|
|
73
|
+
this.#app = app;
|
|
74
|
+
this.get = app.get.bind(app);
|
|
75
|
+
}
|
|
76
|
+
fetch = async (request, env, ctx) => {
|
|
77
|
+
assertCloudflareEnvironment(this.env, env);
|
|
78
|
+
return this.#app.fetch(request, env, ctx);
|
|
79
|
+
};
|
|
80
|
+
getHonoApp() {
|
|
81
|
+
return this.#app.getHonoApp();
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* Resolve a provider from the application's DI container (delegates to
|
|
85
|
+
* `VelaApplication.get`). Handy in `createCloudflareWorker({ configure })`,
|
|
86
|
+
* which finishes the HTTP surface outside the DI request pipeline.
|
|
87
|
+
*
|
|
88
|
+
* @example
|
|
89
|
+
* ```ts
|
|
90
|
+
* const app = await createCloudflareApp(AppModule, { env });
|
|
91
|
+
* const auth = app.get(BetterAuthService);
|
|
92
|
+
* ```
|
|
93
|
+
*/
|
|
94
|
+
get;
|
|
95
|
+
get entrypoints() {
|
|
96
|
+
return this.#app.entrypoints;
|
|
97
|
+
}
|
|
98
|
+
/** Enable CORS for every route, as `VelaApplication.enableCors()`; no rebuild needed. */
|
|
99
|
+
enableCors(options) {
|
|
100
|
+
this.#app.enableCors(options);
|
|
101
|
+
return this;
|
|
102
|
+
}
|
|
103
|
+
/**
|
|
104
|
+
* Serve a pre-built OpenAPI document (and optionally a Scalar UI) on the
|
|
105
|
+
* underlying Hono app. Delegates verbatim to `VelaApplication.mountOpenApi`,
|
|
106
|
+
* so the JSON endpoint defaults to `/openapi.json` and the Scalar UI (when
|
|
107
|
+
* opted in) defaults to `/scalar`. Edge-safe — the UI HTML loads Scalar from
|
|
108
|
+
* a CDN at runtime, nothing is bundled server-side.
|
|
109
|
+
*
|
|
110
|
+
* @example
|
|
111
|
+
* ```ts
|
|
112
|
+
* import { createOpenApiDocument } from '@velajs/vela/openapi';
|
|
113
|
+
*
|
|
114
|
+
* const app = await createCloudflareApp(AppModule, { env });
|
|
115
|
+
* const document = createOpenApiDocument(AppModule, {
|
|
116
|
+
* info: { title: 'My API', version: '1.0.0' },
|
|
117
|
+
* });
|
|
118
|
+
* app.mountOpenApi({ document, ui: 'scalar' });
|
|
119
|
+
* // GET /openapi.json -> { openapi: '3.1.0', ... }
|
|
120
|
+
* // GET /scalar -> Scalar UI HTML
|
|
121
|
+
* ```
|
|
122
|
+
*/
|
|
123
|
+
mountOpenApi(options) {
|
|
124
|
+
this.#app.mountOpenApi(options);
|
|
125
|
+
return this;
|
|
126
|
+
}
|
|
127
|
+
/**
|
|
128
|
+
* Handle a Cloudflare cron trigger. Runs every core `@Cron()` job whose
|
|
129
|
+
* expression is exactly `event.cron` (the trigger string is compared as
|
|
130
|
+
* delivered, never re-evaluated) through `invokeScheduledJob`, the dispatch
|
|
131
|
+
* primitive every runtime shares. Each job receives only its
|
|
132
|
+
* `ScheduleInvocation`, runs in a fresh invocation scope seeded with
|
|
133
|
+
* {@link CLOUDFLARE_SCHEDULED_EVENT}, and honors signed `ScheduleModule`
|
|
134
|
+
* dispatch. The trigger settles after every matching job and its managed
|
|
135
|
+
* work (`EXECUTION_LIFETIME.waitUntil`/`defer`) settle; failures reject it.
|
|
136
|
+
*/
|
|
137
|
+
async scheduled(event, env, _ctx) {
|
|
138
|
+
assertCloudflareEnvironment(this.env, env);
|
|
139
|
+
const jobs = this.#app.entrypoints.ofKind("schedule:cron", parseCronMetadata).filter((entry) => entry.meta.expression === event.cron);
|
|
140
|
+
if (jobs.length === 0) return;
|
|
141
|
+
const controller = new AbortController();
|
|
142
|
+
const scheduledTime = event.scheduledTime ?? Date.now();
|
|
143
|
+
const invocation = Object.freeze({
|
|
144
|
+
kind: "cron",
|
|
145
|
+
expression: event.cron,
|
|
146
|
+
scheduledTime,
|
|
147
|
+
signal: controller.signal
|
|
148
|
+
});
|
|
149
|
+
const trigger = cloudflareScheduledEvent(event, scheduledTime);
|
|
150
|
+
const container = this.#app.getContainer();
|
|
151
|
+
const running = settleEntrypoints(jobs.map((entry) => invokeScheduledJob(container, entry, invocation, { seed: (scope) => scope.setRequestInstance(CLOUDFLARE_SCHEDULED_EVENT, trigger) })));
|
|
152
|
+
this.#scheduled.set(running, controller);
|
|
153
|
+
try {
|
|
154
|
+
await running;
|
|
155
|
+
} finally {
|
|
156
|
+
this.#scheduled.delete(running);
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
/**
|
|
160
|
+
* Run one queue consumer inside a fresh request scope, through the shared
|
|
161
|
+
* guard → interceptor pipeline (components declared with
|
|
162
|
+
* `@UseGuards`/`@UseInterceptors`/`@UseFilters` on the consumer class or
|
|
163
|
+
* method). HTTP-global components deliberately do NOT apply — an HTTP auth
|
|
164
|
+
* guard has no business rejecting a queue batch. Unclaimed errors are
|
|
165
|
+
* reported once (`QueueModule`'s consumer reports its own) and rethrow so
|
|
166
|
+
* the platform's retry semantics stay intact.
|
|
167
|
+
*/
|
|
168
|
+
async dispatchEntrypoint(ep, payload, env, platformContext) {
|
|
169
|
+
const targetClass = ep.token;
|
|
170
|
+
if (typeof targetClass !== "function") throw new Error("Entrypoint token must be a class.");
|
|
171
|
+
if (ep.methodName === void 0) throw new Error("Entrypoint must declare a handler method.");
|
|
172
|
+
const methodName = ep.methodName;
|
|
173
|
+
const reportContext = {
|
|
174
|
+
edge: "queue",
|
|
175
|
+
source: `${targetClass.name}.${String(methodName)}`
|
|
176
|
+
};
|
|
177
|
+
let reported;
|
|
178
|
+
let delegated;
|
|
179
|
+
try {
|
|
180
|
+
await runInEntrypointScope(this.#app.getContainer(), async (scope, lifetime) => {
|
|
181
|
+
const moduleId = getEntrypointModuleId(scope, ep);
|
|
182
|
+
const context = buildEntrypointExecutionContext(ep.kind, targetClass, methodName, payload, moduleId, scope);
|
|
183
|
+
const invocationContext = { waitUntil(promise) {
|
|
184
|
+
lifetime.waitUntil(promise);
|
|
185
|
+
platformContext.waitUntil(promise);
|
|
186
|
+
} };
|
|
187
|
+
let filters = [];
|
|
188
|
+
try {
|
|
189
|
+
filters = (await resolveScopedComponentsAsync("filter", targetClass, methodName, scope, moduleId)).toReversed();
|
|
190
|
+
const guards = await resolveScopedComponentsAsync("guard", targetClass, methodName, scope, moduleId);
|
|
191
|
+
const interceptors = await resolveScopedComponentsAsync("interceptor", targetClass, methodName, scope, moduleId);
|
|
192
|
+
await PipelineRunner.run({
|
|
193
|
+
context,
|
|
194
|
+
guards,
|
|
195
|
+
interceptors,
|
|
196
|
+
resolveArgs: async () => [
|
|
197
|
+
payload,
|
|
198
|
+
env,
|
|
199
|
+
invocationContext
|
|
200
|
+
],
|
|
201
|
+
invoke: async (args) => {
|
|
202
|
+
const instance = await resolveEntrypoint(scope, ep);
|
|
203
|
+
if (typeof instance !== "object" || instance === null) throw new Error("Entrypoint must resolve to an object.");
|
|
204
|
+
try {
|
|
205
|
+
return await invoke(instance, methodName, args);
|
|
206
|
+
} catch (error) {
|
|
207
|
+
if (SELF_REPORTING_KINDS.has(ep.kind)) delegated = { error };
|
|
208
|
+
throw error;
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
});
|
|
212
|
+
} catch (error) {
|
|
213
|
+
if (delegated?.error !== error) resolveErrorReporter(scope).report(error, reportContext);
|
|
214
|
+
for (const filter of filters) if (shouldFilterCatch(filter, error)) {
|
|
215
|
+
await filter.catch(error, context);
|
|
216
|
+
return;
|
|
217
|
+
}
|
|
218
|
+
reported = { error };
|
|
219
|
+
throw error;
|
|
220
|
+
}
|
|
221
|
+
});
|
|
222
|
+
} catch (error) {
|
|
223
|
+
if (!reported || reported.error !== error) {
|
|
224
|
+
const completionError = reported && error instanceof AggregateError && error.errors[0] === reported.error ? error.errors[1] : error;
|
|
225
|
+
resolveErrorReporter(this.#app.getContainer()).report(completionError, reportContext);
|
|
226
|
+
}
|
|
227
|
+
throw error;
|
|
228
|
+
}
|
|
229
|
+
}
|
|
230
|
+
/**
|
|
231
|
+
* Handle Cloudflare Queue consumer events. `@QueueConsumer()` handlers read
|
|
232
|
+
* from `app.entrypoints` claim a batch by its physical queue name and
|
|
233
|
+
* receive it whole. A batch no handler claims goes to `QueueModule`'s native
|
|
234
|
+
* consumer (`cloudflareQueues()` from `@velajs/cloudflare/queues`), which
|
|
235
|
+
* routes each job by its logical queue. Each dispatch runs inside a fresh
|
|
236
|
+
* request-scoped child (request-scoped providers rebuild per batch — no
|
|
237
|
+
* boot-time captives). A batch nothing claims rejects: resolving would let
|
|
238
|
+
* Cloudflare acknowledge every message implicitly.
|
|
239
|
+
*/
|
|
240
|
+
async queue(batch, env, ctx) {
|
|
241
|
+
assertCloudflareEnvironment(this.env, env);
|
|
242
|
+
const raw = this.#app.entrypoints.ofKind("cf:queue").filter((ep) => entrypointString(ep.meta, "queueName") === batch.queue);
|
|
243
|
+
if (raw.length > 0) this.warnRawJobs(batch);
|
|
244
|
+
const handlers = raw.length > 0 ? raw : this.#app.entrypoints.ofKind("cf:queue:module");
|
|
245
|
+
if (handlers.length === 0) throw new Error(`No consumer claims queue '${batch.queue}'. Add @QueueConsumer('${batch.queue}') to a provider, or deliver it through QueueModule.forRoot({ driver: cloudflareQueues() }) with a QueueModule.registerQueue() for each queue it carries. The batch is rejected unacknowledged, so Cloudflare retries it and then routes it to the configured dead-letter queue.`);
|
|
246
|
+
await settleEntrypoints(handlers.map((ep) => this.dispatchEntrypoint(ep, batch, env, ctx)));
|
|
247
|
+
}
|
|
248
|
+
/**
|
|
249
|
+
* A raw `@QueueConsumer` owns its physical queue's batches and must not carry
|
|
250
|
+
* jobs of a queue registered with `QueueModule`: those reach their
|
|
251
|
+
* `@Processor` only if the raw handler dispatches them itself, while
|
|
252
|
+
* `cloudflareQueues()` delivers registered queues. Warn once per physical and
|
|
253
|
+
* logical queue (unless diagnostics are silent); the raw consumer still
|
|
254
|
+
* receives and settles the batch.
|
|
255
|
+
*/
|
|
256
|
+
warnRawJobs(batch) {
|
|
257
|
+
if (this.#app.getContainer().getDiagnostics() === "silent") return;
|
|
258
|
+
const registered = new Set(this.#app.entrypoints.ofKind("queue:registration").map((entry) => typeof entry.meta === "object" && entry.meta !== null ? Reflect.get(entry.meta, "name") : void 0));
|
|
259
|
+
if (registered.size === 0) return;
|
|
260
|
+
for (const message of batch.messages) {
|
|
261
|
+
const queue = envelopeQueue(typeof message === "object" && message !== null ? Reflect.get(message, "body") : void 0);
|
|
262
|
+
if (queue === void 0 || !registered.has(queue)) continue;
|
|
263
|
+
const warning = `[vela] @QueueConsumer('${batch.queue}') received jobs of registered queue '${queue}'. The raw consumer owns '${batch.queue}' and must not carry jobs of registered queues: they reach @Processor('${queue}') only if the raw handler dispatches them itself. Deliver '${queue}' through cloudflareQueues() instead: send it to a physical queue that no @QueueConsumer claims.`;
|
|
264
|
+
if (warnedRawJobs.has(warning)) continue;
|
|
265
|
+
warnedRawJobs.add(warning);
|
|
266
|
+
console.warn(warning);
|
|
267
|
+
}
|
|
268
|
+
}
|
|
269
|
+
/**
|
|
270
|
+
* Abort the signals of scheduled jobs still running, wait for them and their
|
|
271
|
+
* managed work to settle, then close the application.
|
|
272
|
+
*/
|
|
273
|
+
async close(signal) {
|
|
274
|
+
for (const controller of this.#scheduled.values()) controller.abort();
|
|
275
|
+
await Promise.allSettled(this.#scheduled.keys());
|
|
276
|
+
return this.#app.close(signal);
|
|
277
|
+
}
|
|
278
|
+
};
|
|
279
|
+
//#endregion
|
|
280
|
+
export { CloudflareApplication };
|
|
281
|
+
|
|
282
|
+
//# sourceMappingURL=cloudflare-application.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cloudflare-application.js","names":[],"sources":["../src/cloudflare-application.ts"],"sourcesContent":["import type { ExecutionContext } from 'hono';\nimport type { CorsOptions, VelaApplication, ExceptionFilter, VelaEnv } from '@velajs/vela';\nimport {\n PipelineRunner,\n buildEntrypointExecutionContext,\n getEntrypointModuleId,\n invokeScheduledJob,\n parseCronMetadata,\n resolveEntrypoint,\n resolveScopedComponentsAsync,\n resolveErrorReporter,\n runInEntrypointScope,\n shouldFilterCatch,\n} from '@velajs/vela/module-kit';\nimport type { ScheduleInvocation } from '@velajs/vela/schedule';\nimport type { Entrypoint } from '@velajs/vela/module-kit';\nimport { assertCloudflareEnvironment } from './environment';\nimport {\n CLOUDFLARE_SCHEDULED_EVENT,\n cloudflareScheduledEvent,\n type ScheduledEvent,\n} from './scheduled-event';\n\n/**\n * Options accepted by {@link CloudflareApplication.mountOpenApi}.\n *\n * Re-exposes vela's `MountOpenApiOptions` type — derived structurally from\n * the underlying `VelaApplication.mountOpenApi` signature so consumers don't\n * have to reach into vela's internal subpaths to type the argument.\n */\nexport type MountOpenApiOptions = Parameters<VelaApplication['mountOpenApi']>[0];\n\nfunction invoke(instance: object, methodName: string | symbol, args: unknown[]): unknown {\n // Decorator metadata names an instance method; inspect it before invoking.\n const method: unknown = Reflect.get(instance, methodName);\n if (typeof method !== 'function') {\n throw new Error(\n `Method '${String(methodName)}' is not a function on ${instance.constructor.name}`,\n );\n }\n return Reflect.apply(method, instance, args);\n}\n\nfunction entrypointString(meta: unknown, property: string): string {\n if (typeof meta !== 'object' || meta === null) throw new Error('Invalid entrypoint metadata.');\n const value: unknown = Reflect.get(meta, property);\n if (typeof value !== 'string')\n throw new Error(`Invalid entrypoint metadata: ${property} must be a string.`);\n return value;\n}\n\n/**\n * `QueueModule`'s native consumer reports each failure of a batch once itself\n * (processor failures where they ran, transport failures on settlement), so\n * its rejection is not reported again here.\n */\nconst SELF_REPORTING_KINDS = new Set(['cf:queue:module']);\n\nconst warnedRawJobs = new Set<string>();\n\n/** The logical queue of a Vela job envelope, without importing the queue subsystem. */\nfunction envelopeQueue(body: unknown): string | undefined {\n if (typeof body !== 'object' || body === null) return undefined;\n const queue: unknown = Reflect.get(body, 'queue');\n if (\n typeof queue !== 'string' ||\n typeof Reflect.get(body, 'id') !== 'string' ||\n typeof Reflect.get(body, 'name') !== 'string' ||\n !('data' in body)\n ) {\n return undefined;\n }\n return queue;\n}\n\n/** Wait for every matching handler, even when one fails before its siblings. */\nasync function settleEntrypoints(work: readonly Promise<void>[]): Promise<void> {\n const outcomes = await Promise.allSettled(work);\n const errors = outcomes.flatMap((outcome) =>\n outcome.status === 'rejected' ? [outcome.reason] : [],\n );\n if (errors.length === 1) throw errors[0];\n if (errors.length > 1) throw new AggregateError(errors, 'Multiple entrypoint handlers failed.');\n}\n\n/**\n * Wraps VelaApplication with Cloudflare-specific handlers:\n * - `fetch` — HTTP request handler (from Hono)\n * - `scheduled` — Cron trigger handler (runs the `@Cron()` jobs whose\n * expression is the trigger's exact string)\n * - `queue` — Queue consumer handler (`@QueueConsumer()` by physical queue,\n * then `QueueModule`'s native consumer)\n * - `mountOpenApi` — Serve an OpenAPI document (and optional Scalar UI) on\n * the underlying Hono app\n *\n * @example\n * ```ts\n * const app = await createCloudflareApp(AppModule, { env });\n * export default {\n * fetch: app.fetch,\n * scheduled: app.scheduled.bind(app),\n * queue: app.queue.bind(app),\n * };\n * ```\n *\n * @example\n * ```ts\n * // Serve OpenAPI docs alongside your routes\n * const app = await createCloudflareApp(AppModule, { env });\n * const document = createOpenApiDocument(AppModule);\n * app.mountOpenApi({ document, ui: 'scalar' });\n * // GET /openapi.json -> JSON document\n * // GET /scalar -> Scalar UI (loads from CDN)\n * ```\n */\nexport class CloudflareApplication {\n readonly #app: VelaApplication;\n /** Scheduled triggers in flight; close() aborts their signals and awaits them. */\n readonly #scheduled = new Map<Promise<void>, AbortController>();\n\n constructor(\n app: VelaApplication,\n readonly env: VelaEnv,\n ) {\n this.#app = app;\n this.get = app.get.bind(app);\n }\n\n readonly fetch = async (\n request: Request,\n env: VelaEnv,\n ctx?: ExecutionContext,\n ): Promise<Response> => {\n assertCloudflareEnvironment(this.env, env);\n return this.#app.fetch(request, env, ctx);\n };\n\n getHonoApp(): ReturnType<VelaApplication['getHonoApp']> {\n return this.#app.getHonoApp();\n }\n\n /**\n * Resolve a provider from the application's DI container (delegates to\n * `VelaApplication.get`). Handy in `createCloudflareWorker({ configure })`,\n * which finishes the HTTP surface outside the DI request pipeline.\n *\n * @example\n * ```ts\n * const app = await createCloudflareApp(AppModule, { env });\n * const auth = app.get(BetterAuthService);\n * ```\n */\n readonly get: VelaApplication['get'];\n\n get entrypoints(): VelaApplication['entrypoints'] {\n return this.#app.entrypoints;\n }\n\n /** Enable CORS for every route, as `VelaApplication.enableCors()`; no rebuild needed. */\n enableCors(options?: CorsOptions): this {\n this.#app.enableCors(options);\n return this;\n }\n\n /**\n * Serve a pre-built OpenAPI document (and optionally a Scalar UI) on the\n * underlying Hono app. Delegates verbatim to `VelaApplication.mountOpenApi`,\n * so the JSON endpoint defaults to `/openapi.json` and the Scalar UI (when\n * opted in) defaults to `/scalar`. Edge-safe — the UI HTML loads Scalar from\n * a CDN at runtime, nothing is bundled server-side.\n *\n * @example\n * ```ts\n * import { createOpenApiDocument } from '@velajs/vela/openapi';\n *\n * const app = await createCloudflareApp(AppModule, { env });\n * const document = createOpenApiDocument(AppModule, {\n * info: { title: 'My API', version: '1.0.0' },\n * });\n * app.mountOpenApi({ document, ui: 'scalar' });\n * // GET /openapi.json -> { openapi: '3.1.0', ... }\n * // GET /scalar -> Scalar UI HTML\n * ```\n */\n mountOpenApi(options: MountOpenApiOptions): this {\n this.#app.mountOpenApi(options);\n return this;\n }\n\n /**\n * Handle a Cloudflare cron trigger. Runs every core `@Cron()` job whose\n * expression is exactly `event.cron` (the trigger string is compared as\n * delivered, never re-evaluated) through `invokeScheduledJob`, the dispatch\n * primitive every runtime shares. Each job receives only its\n * `ScheduleInvocation`, runs in a fresh invocation scope seeded with\n * {@link CLOUDFLARE_SCHEDULED_EVENT}, and honors signed `ScheduleModule`\n * dispatch. The trigger settles after every matching job and its managed\n * work (`EXECUTION_LIFETIME.waitUntil`/`defer`) settle; failures reject it.\n */\n async scheduled(\n event: ScheduledEvent,\n env: VelaEnv,\n _ctx?: { waitUntil: (promise: Promise<unknown>) => void },\n ): Promise<void> {\n assertCloudflareEnvironment(this.env, env);\n const jobs = this.#app.entrypoints\n .ofKind('schedule:cron', parseCronMetadata)\n .filter((entry) => entry.meta.expression === event.cron);\n if (jobs.length === 0) return;\n\n const controller = new AbortController();\n const scheduledTime = event.scheduledTime ?? Date.now();\n // Shared by every matching job, so none of them can alter what another sees.\n const invocation: ScheduleInvocation = Object.freeze({\n kind: 'cron' as const,\n expression: event.cron,\n scheduledTime,\n signal: controller.signal,\n });\n const trigger = cloudflareScheduledEvent(event, scheduledTime);\n const container = this.#app.getContainer();\n const running = settleEntrypoints(\n jobs.map((entry) =>\n invokeScheduledJob(container, entry, invocation, {\n seed: (scope) => scope.setRequestInstance(CLOUDFLARE_SCHEDULED_EVENT, trigger),\n }),\n ),\n );\n this.#scheduled.set(running, controller);\n try {\n await running;\n } finally {\n this.#scheduled.delete(running);\n }\n }\n\n /**\n * Run one queue consumer inside a fresh request scope, through the shared\n * guard → interceptor pipeline (components declared with\n * `@UseGuards`/`@UseInterceptors`/`@UseFilters` on the consumer class or\n * method). HTTP-global components deliberately do NOT apply — an HTTP auth\n * guard has no business rejecting a queue batch. Unclaimed errors are\n * reported once (`QueueModule`'s consumer reports its own) and rethrow so\n * the platform's retry semantics stay intact.\n */\n private async dispatchEntrypoint(\n ep: Entrypoint,\n payload: unknown,\n env: VelaEnv,\n platformContext: { waitUntil: (promise: Promise<unknown>) => void },\n ): Promise<void> {\n const targetClass = ep.token;\n if (typeof targetClass !== 'function') throw new Error('Entrypoint token must be a class.');\n if (ep.methodName === undefined) throw new Error('Entrypoint must declare a handler method.');\n const methodName = ep.methodName;\n const reportContext = {\n edge: 'queue' as const,\n source: `${targetClass.name}.${String(methodName)}`,\n };\n let reported: { error: unknown } | undefined;\n // A self-reporting handler's own rejection was already reported.\n let delegated: { error: unknown } | undefined;\n try {\n await runInEntrypointScope(this.#app.getContainer(), async (scope, lifetime) => {\n const moduleId = getEntrypointModuleId(scope, ep);\n const context = buildEntrypointExecutionContext(\n ep.kind,\n targetClass,\n methodName,\n payload,\n moduleId,\n scope,\n );\n const invocationContext = {\n waitUntil(promise: Promise<unknown>): void {\n lifetime.waitUntil(promise);\n platformContext.waitUntil(promise);\n },\n };\n let filters: ExceptionFilter[] = [];\n try {\n filters = (\n await resolveScopedComponentsAsync('filter', targetClass, methodName, scope, moduleId)\n ).toReversed();\n const guards = await resolveScopedComponentsAsync(\n 'guard',\n targetClass,\n methodName,\n scope,\n moduleId,\n );\n const interceptors = await resolveScopedComponentsAsync(\n 'interceptor',\n targetClass,\n methodName,\n scope,\n moduleId,\n );\n await PipelineRunner.run({\n context,\n guards,\n interceptors,\n resolveArgs: async () => [payload, env, invocationContext],\n invoke: async (args) => {\n const instance = await resolveEntrypoint(scope, ep);\n if (typeof instance !== 'object' || instance === null) {\n throw new Error('Entrypoint must resolve to an object.');\n }\n try {\n return await invoke(instance, methodName, args);\n } catch (error) {\n if (SELF_REPORTING_KINDS.has(ep.kind)) delegated = { error };\n throw error;\n }\n },\n });\n } catch (error) {\n if (delegated?.error !== error) {\n resolveErrorReporter(scope).report(error, reportContext);\n }\n for (const filter of filters) {\n if (shouldFilterCatch(filter, error)) {\n // Filters run closest-first; this is the framework catch hook.\n // eslint-disable-next-line no-await-in-loop, promise/valid-params\n await filter.catch(error, context);\n return;\n }\n }\n reported = { error };\n throw error;\n }\n });\n } catch (error) {\n // Managed completion happens after the handler's filter boundary. Report\n // a new completion failure without reporting an already-observed handler\n // failure twice; preserve both errors in the rejected invocation.\n if (!reported || reported.error !== error) {\n const completionError =\n reported && error instanceof AggregateError && error.errors[0] === reported.error\n ? error.errors[1]\n : error;\n resolveErrorReporter(this.#app.getContainer()).report(completionError, reportContext);\n }\n throw error;\n }\n }\n\n /**\n * Handle Cloudflare Queue consumer events. `@QueueConsumer()` handlers read\n * from `app.entrypoints` claim a batch by its physical queue name and\n * receive it whole. A batch no handler claims goes to `QueueModule`'s native\n * consumer (`cloudflareQueues()` from `@velajs/cloudflare/queues`), which\n * routes each job by its logical queue. Each dispatch runs inside a fresh\n * request-scoped child (request-scoped providers rebuild per batch — no\n * boot-time captives). A batch nothing claims rejects: resolving would let\n * Cloudflare acknowledge every message implicitly.\n */\n async queue(\n batch: { queue: string; messages: readonly unknown[] },\n env: VelaEnv,\n ctx: { waitUntil: (promise: Promise<unknown>) => void },\n ): Promise<void> {\n assertCloudflareEnvironment(this.env, env);\n const raw = this.#app.entrypoints\n .ofKind('cf:queue')\n .filter((ep) => entrypointString(ep.meta, 'queueName') === batch.queue);\n if (raw.length > 0) this.warnRawJobs(batch);\n const handlers = raw.length > 0 ? raw : this.#app.entrypoints.ofKind('cf:queue:module');\n\n if (handlers.length === 0) {\n throw new Error(\n `No consumer claims queue '${batch.queue}'. Add @QueueConsumer('${batch.queue}') to a ` +\n `provider, or deliver it through QueueModule.forRoot({ driver: cloudflareQueues() }) ` +\n `with a QueueModule.registerQueue() for each queue it carries. The batch is rejected ` +\n `unacknowledged, so Cloudflare retries it and then routes it to the configured ` +\n `dead-letter queue.`,\n );\n }\n\n await settleEntrypoints(handlers.map((ep) => this.dispatchEntrypoint(ep, batch, env, ctx)));\n }\n\n /**\n * A raw `@QueueConsumer` owns its physical queue's batches and must not carry\n * jobs of a queue registered with `QueueModule`: those reach their\n * `@Processor` only if the raw handler dispatches them itself, while\n * `cloudflareQueues()` delivers registered queues. Warn once per physical and\n * logical queue (unless diagnostics are silent); the raw consumer still\n * receives and settles the batch.\n */\n private warnRawJobs(batch: { queue: string; messages: readonly unknown[] }): void {\n if (this.#app.getContainer().getDiagnostics() === 'silent') return;\n const registered = new Set(\n this.#app.entrypoints\n .ofKind('queue:registration')\n .map((entry) =>\n typeof entry.meta === 'object' && entry.meta !== null\n ? Reflect.get(entry.meta, 'name')\n : undefined,\n ),\n );\n if (registered.size === 0) return;\n for (const message of batch.messages) {\n const body =\n typeof message === 'object' && message !== null ? Reflect.get(message, 'body') : undefined;\n const queue = envelopeQueue(body);\n if (queue === undefined || !registered.has(queue)) continue;\n const warning =\n `[vela] @QueueConsumer('${batch.queue}') received jobs of registered queue '${queue}'. ` +\n `The raw consumer owns '${batch.queue}' and must not carry jobs of registered queues: ` +\n `they reach @Processor('${queue}') only if the raw handler dispatches them itself. ` +\n `Deliver '${queue}' through cloudflareQueues() instead: send it to a physical queue ` +\n `that no @QueueConsumer claims.`;\n if (warnedRawJobs.has(warning)) continue;\n warnedRawJobs.add(warning);\n console.warn(warning);\n }\n }\n\n /**\n * Abort the signals of scheduled jobs still running, wait for them and their\n * managed work to settle, then close the application.\n */\n async close(signal?: string): Promise<void> {\n for (const controller of this.#scheduled.values()) controller.abort();\n await Promise.allSettled(this.#scheduled.keys());\n return this.#app.close(signal);\n }\n}\n"],"mappings":";;;;AAgCA,SAAS,OAAO,UAAkB,YAA6B,MAA0B;CAEvF,MAAM,SAAkB,QAAQ,IAAI,UAAU,UAAU;CACxD,IAAI,OAAO,WAAW,YACpB,MAAM,IAAI,MACR,WAAW,OAAO,UAAU,EAAE,yBAAyB,SAAS,YAAY,MAC9E;CAEF,OAAO,QAAQ,MAAM,QAAQ,UAAU,IAAI;AAC7C;AAEA,SAAS,iBAAiB,MAAe,UAA0B;CACjE,IAAI,OAAO,SAAS,YAAY,SAAS,MAAM,MAAM,IAAI,MAAM,8BAA8B;CAC7F,MAAM,QAAiB,QAAQ,IAAI,MAAM,QAAQ;CACjD,IAAI,OAAO,UAAU,UACnB,MAAM,IAAI,MAAM,gCAAgC,SAAS,mBAAmB;CAC9E,OAAO;AACT;;;;;;AAOA,MAAM,uCAAuB,IAAI,IAAI,CA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