@velajs/cloudflare 1.30.0 → 1.32.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 +174 -0
- package/README.md +407 -77
- package/dist/bindings.js +93 -0
- package/dist/bindings.js.map +1 -0
- package/dist/cloudflare-application-CXDy9C1R.d.ts +199 -0
- package/dist/cloudflare-application.js +15 -34
- package/dist/cloudflare-application.js.map +1 -1
- package/dist/cloudflare-factory-CuFNUJJD.d.ts +241 -0
- package/dist/cloudflare-factory.js +227 -38
- package/dist/cloudflare-factory.js.map +1 -1
- package/dist/diagnostics.js +18 -0
- package/dist/diagnostics.js.map +1 -0
- package/dist/durable-object/boot.js +76 -0
- package/dist/durable-object/boot.js.map +1 -0
- package/dist/durable-object/host-dispatch.js +134 -0
- package/dist/durable-object/host-dispatch.js.map +1 -0
- package/dist/durable-object/host-methods.js +47 -0
- package/dist/durable-object/host-methods.js.map +1 -0
- package/dist/durable-object/tokens.js +17 -0
- package/dist/durable-object/tokens.js.map +1 -0
- package/dist/durable-object/vela-durable-object.js +121 -0
- package/dist/durable-object/vela-durable-object.js.map +1 -0
- package/dist/durable-objects.d.ts +136 -10
- package/dist/durable-objects.js +3 -1
- package/dist/email/email-dispatch.js +65 -0
- package/dist/email/email-dispatch.js.map +1 -0
- package/dist/email/on-email.js +57 -0
- package/dist/email/on-email.js.map +1 -0
- package/dist/email.d.ts +51 -0
- package/dist/email.js +3 -0
- package/dist/entrypoint/vela-entrypoint.js +160 -0
- package/dist/entrypoint/vela-entrypoint.js.map +1 -0
- package/dist/entrypoints.d.ts +93 -0
- package/dist/entrypoints.js +2 -0
- package/dist/host/host-invoker.js +276 -0
- package/dist/host/host-invoker.js.map +1 -0
- package/dist/host/host-members.js +73 -0
- package/dist/host/host-members.js.map +1 -0
- package/dist/host-members-DECj_4yz.d.ts +13 -0
- package/dist/index.d.ts +211 -445
- package/dist/index.js +8 -13
- package/dist/{nonce.durable-object-Ci9AGssY.d.ts → nonce.durable-object-Bg1e0BMD.d.ts} +1 -11
- package/dist/platform.js +22 -0
- package/dist/platform.js.map +1 -0
- package/dist/queue/cloudflare-queues.js +7 -7
- package/dist/queue/cloudflare-queues.js.map +1 -1
- package/dist/rate-limit/cloudflare-rate-limit.store.js +66 -27
- package/dist/rate-limit/cloudflare-rate-limit.store.js.map +1 -1
- package/dist/root-module.js +19 -0
- package/dist/root-module.js.map +1 -0
- package/dist/rpc/entrypoint-error.js +145 -0
- package/dist/rpc/entrypoint-error.js.map +1 -0
- package/dist/schedule-diagnostics.js +8 -15
- package/dist/schedule-diagnostics.js.map +1 -1
- package/dist/services/kv-cache.store.js +33 -7
- package/dist/services/kv-cache.store.js.map +1 -1
- 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/tail/on-tail.js +46 -0
- package/dist/tail/on-tail.js.map +1 -0
- package/dist/tail/tail-dispatch.js +67 -0
- package/dist/tail/tail-dispatch.js.map +1 -0
- package/dist/tail.d.ts +39 -0
- package/dist/tail.js +2 -0
- package/dist/testing.d.ts +148 -0
- package/dist/testing.js +188 -0
- package/dist/testing.js.map +1 -0
- package/dist/websocket/binding-gateways.js +33 -0
- package/dist/websocket/binding-gateways.js.map +1 -0
- package/dist/websocket/cf-room-registry.js +3 -1
- package/dist/websocket/cf-room-registry.js.map +1 -1
- package/dist/websocket/do-bootstrap.js +64 -40
- package/dist/websocket/do-bootstrap.js.map +1 -1
- package/dist/websocket/do-live.js +49 -90
- package/dist/websocket/do-live.js.map +1 -1
- package/dist/websocket/do-state.js.map +1 -1
- package/dist/websocket/live-driver.js +149 -0
- package/dist/websocket/live-driver.js.map +1 -0
- package/dist/websocket/room-id.js +11 -1
- package/dist/websocket/room-id.js.map +1 -1
- package/dist/websocket/websocket.durable-object.js +51 -18
- package/dist/websocket/websocket.durable-object.js.map +1 -1
- package/dist/websocket/worker-transport.js +80 -0
- package/dist/websocket/worker-transport.js.map +1 -0
- package/dist/worker-events.js +49 -0
- package/dist/worker-events.js.map +1 -0
- package/dist/workflow/vela-workflow.js +104 -0
- package/dist/workflow/vela-workflow.js.map +1 -0
- package/dist/workflows.d.ts +82 -0
- package/dist/workflows.js +2 -0
- package/package.json +39 -6
- package/dist/_virtual/_@oxc-project_runtime@0.150.0/helpers/esm/decorate.js +0 -9
- package/dist/_virtual/_@oxc-project_runtime@0.150.0/helpers/esm/decorateMetadata.js +0 -6
- package/dist/_virtual/_@oxc-project_runtime@0.150.0/helpers/esm/decorateParam.js +0 -8
- package/dist/storage/r2-storage.driver.js +0 -67
- package/dist/storage/r2-storage.driver.js.map +0 -1
- package/dist/storage/storage-key-claim.js +0 -74
- package/dist/storage/storage-key-claim.js.map +0 -1
- package/dist/storage/storage-manager.service.js +0 -38
- package/dist/storage/storage-manager.service.js.map +0 -1
- package/dist/storage/storage.controller.js +0 -64
- package/dist/storage/storage.controller.js.map +0 -1
- package/dist/storage/storage.module.js +0 -25
- package/dist/storage/storage.module.js.map +0 -1
- package/dist/storage/storage.service.js +0 -64
- package/dist/storage/storage.service.js.map +0 -1
- package/dist/storage/storage.tokens.js +0 -7
- package/dist/storage/storage.tokens.js.map +0 -1
- package/dist/websocket/broadcast.js +0 -32
- package/dist/websocket/broadcast.js.map +0 -1
- package/dist/websocket/cloudflare-websocket.module.js +0 -25
- package/dist/websocket/cloudflare-websocket.module.js.map +0 -1
- package/dist/websocket/websocket-routing.js +0 -133
- package/dist/websocket/websocket-routing.js.map +0 -1
- package/dist/websocket/ws-server-holder.js +0 -38
- package/dist/websocket/ws-server-holder.js.map +0 -1
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
//#region src/host/host-members.ts
|
|
2
|
+
/**
|
|
3
|
+
* Methods the application context calls on providers: lifecycle hooks, the
|
|
4
|
+
* container's `dispose()` disposal hook and the entrypoint contributor hook.
|
|
5
|
+
* Never RPC methods.
|
|
6
|
+
*/
|
|
7
|
+
const HOOKS = /* @__PURE__ */ new Set([
|
|
8
|
+
"constructor",
|
|
9
|
+
"onModuleInit",
|
|
10
|
+
"onApplicationBootstrap",
|
|
11
|
+
"onModuleDestroy",
|
|
12
|
+
"beforeApplicationShutdown",
|
|
13
|
+
"onApplicationShutdown",
|
|
14
|
+
"dispose",
|
|
15
|
+
"collectEntrypoints"
|
|
16
|
+
]);
|
|
17
|
+
/** The nearest declaration of `name` on the prototype chain of `host`, below `Object.prototype`. */
|
|
18
|
+
function prototypeMember(host, name) {
|
|
19
|
+
for (let prototype = host.prototype; typeof prototype === "object" && prototype !== null && prototype !== Object.prototype; prototype = Object.getPrototypeOf(prototype)) {
|
|
20
|
+
const descriptor = Object.getOwnPropertyDescriptor(prototype, name);
|
|
21
|
+
if (descriptor) return descriptor;
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
/** Whether `host` declares the prototype method `name` (not an accessor or an instance field). */
|
|
25
|
+
function hasPrototypeMethod(host, name) {
|
|
26
|
+
return typeof prototypeMember(host, name)?.value === "function";
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Reject a host whose prototype chain defines `then`, as a method or an
|
|
30
|
+
* accessor: an instance would be a thenable, so awaiting the resolved host
|
|
31
|
+
* would call it instead of producing the instance, and the invocation would
|
|
32
|
+
* hang. Checked when the class is defined, without constructing the host.
|
|
33
|
+
*/
|
|
34
|
+
function assertNotThenable(host) {
|
|
35
|
+
if (prototypeMember(host, "then") === void 0) return;
|
|
36
|
+
throw new TypeError(`${host.name} defines then(), which makes every instance a thenable: resolving the host would call it instead of returning the instance, and each invocation would hang. Rename the method.`);
|
|
37
|
+
}
|
|
38
|
+
/** Why `name` cannot be an RPC method of `host`, or undefined when it can. */
|
|
39
|
+
function rpcNameProblem(host, name, surface) {
|
|
40
|
+
if (typeof name !== "string") return `${host.name}: an rpc entry must be a method name, not ${String(name)}.`;
|
|
41
|
+
if (surface.reserved.has(name)) return `${host.name}.${name}() cannot be a ${surface.label} RPC method: '${name}' is reserved by the ${surface.label} class or its stubs. Rename the method.`;
|
|
42
|
+
if (HOOKS.has(name)) return `${host.name}.${name}() cannot be a ${surface.label} RPC method: the application context calls it (a lifecycle, disposal or entrypoint hook).`;
|
|
43
|
+
if (surface.handlers.includes(name)) return `${host.name}.${name}() is the ${surface.label} ${name} handler, which the platform calls: leave it out of the rpc list.`;
|
|
44
|
+
if (!hasPrototypeMethod(host, name)) return `${host.name} has no prototype method ${name}(): list methods declared in the class body, not accessors or instance fields such as arrow functions.`;
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* The members of `host` its entrypoint class exposes: the RPC methods `rpc`
|
|
48
|
+
* names, and the event handlers of `surface` it implements. Each `rpc` entry
|
|
49
|
+
* must name a string-keyed method on the host's prototype chain (below
|
|
50
|
+
* `Object.prototype`); a hook, an event handler, a reserved name, an accessor
|
|
51
|
+
* or an instance field throws, and so does a host defining `then`. Nothing
|
|
52
|
+
* else is an RPC method, TypeScript `private` and `protected` methods
|
|
53
|
+
* included. Read at class definition, without constructing the host.
|
|
54
|
+
*/
|
|
55
|
+
function hostMembers(host, rpc, surface) {
|
|
56
|
+
assertNotThenable(host);
|
|
57
|
+
const names = rpc ?? [];
|
|
58
|
+
if (!Array.isArray(names)) throw new TypeError(`${host.name}: the rpc option must be an array of method names.`);
|
|
59
|
+
const methods = [];
|
|
60
|
+
for (const name of names) {
|
|
61
|
+
const problem = rpcNameProblem(host, name, surface);
|
|
62
|
+
if (problem !== void 0) throw new TypeError(problem);
|
|
63
|
+
if (!methods.includes(name)) methods.push(name);
|
|
64
|
+
}
|
|
65
|
+
return {
|
|
66
|
+
methods,
|
|
67
|
+
handlers: surface.handlers.filter((name) => hasPrototypeMethod(host, name))
|
|
68
|
+
};
|
|
69
|
+
}
|
|
70
|
+
//#endregion
|
|
71
|
+
export { assertNotThenable, hasPrototypeMethod, hostMembers, prototypeMember };
|
|
72
|
+
|
|
73
|
+
//# sourceMappingURL=host-members.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"host-members.js","names":[],"sources":["../../src/host/host-members.ts"],"sourcesContent":["/**\n * Methods the application context calls on providers: lifecycle hooks, the\n * container's `dispose()` disposal hook and the entrypoint contributor hook.\n * Never RPC methods.\n */\nconst HOOKS = new Set([\n 'constructor',\n 'onModuleInit',\n 'onApplicationBootstrap',\n 'onModuleDestroy',\n 'beforeApplicationShutdown',\n 'onApplicationShutdown',\n 'dispose',\n 'collectEntrypoints',\n]);\n\n/** Host members the application context calls, which are never RPC methods. */\nexport type HostHookName =\n | 'onModuleInit'\n | 'onApplicationBootstrap'\n | 'onModuleDestroy'\n | 'beforeApplicationShutdown'\n | 'onApplicationShutdown'\n | 'dispose'\n | 'collectEntrypoints';\n\n/**\n * The names a host's `rpc` list may take: its public methods, less the\n * `Excluded` names. TypeScript `private` and `protected` methods are not\n * among them.\n */\nexport type RpcMethodOf<Host, Excluded extends string> = {\n [K in keyof Host]: K extends string\n ? K extends Excluded | HostHookName\n ? never\n : Host[K] extends (...args: never[]) => unknown\n ? K\n : never\n : never;\n}[keyof Host];\n\n/** The RPC methods `Method` of `Host`, asynchronous, as the entrypoint's stubs call them. */\nexport type RpcMethods<Host, Method extends keyof Host> = {\n [K in Method]: Host[K] extends (...args: infer Args) => infer Result\n ? (...args: Args) => Promise<Awaited<Result>>\n : never;\n};\n\n/** @internal A class whose prototype methods a host exposes. */\nexport type HostClass = abstract new (...args: never[]) => unknown;\n\n/** The nearest declaration of `name` on the prototype chain of `host`, below `Object.prototype`. */\nexport function prototypeMember(host: HostClass, name: string): PropertyDescriptor | undefined {\n for (\n let prototype: unknown = host.prototype;\n typeof prototype === 'object' && prototype !== null && prototype !== Object.prototype;\n prototype = Object.getPrototypeOf(prototype)\n ) {\n const descriptor = Object.getOwnPropertyDescriptor(prototype, name);\n if (descriptor) return descriptor;\n }\n return undefined;\n}\n\n/** Whether `host` declares the prototype method `name` (not an accessor or an instance field). */\nexport function hasPrototypeMethod(host: HostClass, name: string): boolean {\n return typeof prototypeMember(host, name)?.value === 'function';\n}\n\n/**\n * Reject a host whose prototype chain defines `then`, as a method or an\n * accessor: an instance would be a thenable, so awaiting the resolved host\n * would call it instead of producing the instance, and the invocation would\n * hang. Checked when the class is defined, without constructing the host.\n */\nexport function assertNotThenable(host: HostClass): void {\n if (prototypeMember(host, 'then') === undefined) return;\n throw new TypeError(\n `${host.name} defines then(), which makes every instance a thenable: resolving the host ` +\n 'would call it instead of returning the instance, and each invocation would hang. ' +\n 'Rename the method.',\n );\n}\n\n/** How one kind of host names its RPC restrictions in messages. */\nexport interface RpcSurface<Handler extends string> {\n /** What the class is, as messages name it: `'Durable Object'`, `'service entrypoint'`. */\n readonly label: string;\n /** Names the class or its stubs own, which no RPC method may take. */\n readonly reserved: ReadonlySet<string>;\n /** Event handlers the platform calls on the class, in the order the class defines them. */\n readonly handlers: readonly Handler[];\n}\n\n/** What a host class contributes to its entrypoint class. */\nexport interface HostMembers<Handler extends string> {\n /** RPC methods: the host methods its `rpc` list names. */\n readonly methods: readonly string[];\n /** Event handlers the host implements, in the surface's handler order. */\n readonly handlers: readonly Handler[];\n}\n\n/** Why `name` cannot be an RPC method of `host`, or undefined when it can. */\nfunction rpcNameProblem<Handler extends string>(\n host: HostClass,\n name: unknown,\n surface: RpcSurface<Handler>,\n): string | undefined {\n if (typeof name !== 'string') {\n return `${host.name}: an rpc entry must be a method name, not ${String(name)}.`;\n }\n if (surface.reserved.has(name)) {\n return (\n `${host.name}.${name}() cannot be a ${surface.label} RPC method: '${name}' is reserved ` +\n `by the ${surface.label} class or its stubs. Rename the method.`\n );\n }\n if (HOOKS.has(name)) {\n return (\n `${host.name}.${name}() cannot be a ${surface.label} RPC method: the application ` +\n 'context calls it (a lifecycle, disposal or entrypoint hook).'\n );\n }\n if ((surface.handlers as readonly string[]).includes(name)) {\n return (\n `${host.name}.${name}() is the ${surface.label} ${name} handler, which the platform ` +\n 'calls: leave it out of the rpc list.'\n );\n }\n if (!hasPrototypeMethod(host, name)) {\n return (\n `${host.name} has no prototype method ${name}(): list methods declared in the class ` +\n 'body, not accessors or instance fields such as arrow functions.'\n );\n }\n return undefined;\n}\n\n/**\n * The members of `host` its entrypoint class exposes: the RPC methods `rpc`\n * names, and the event handlers of `surface` it implements. Each `rpc` entry\n * must name a string-keyed method on the host's prototype chain (below\n * `Object.prototype`); a hook, an event handler, a reserved name, an accessor\n * or an instance field throws, and so does a host defining `then`. Nothing\n * else is an RPC method, TypeScript `private` and `protected` methods\n * included. Read at class definition, without constructing the host.\n */\nexport function hostMembers<Handler extends string>(\n host: HostClass,\n rpc: readonly string[] | undefined,\n surface: RpcSurface<Handler>,\n): { methods: string[]; handlers: Handler[] } {\n assertNotThenable(host);\n const names = rpc ?? [];\n if (!Array.isArray(names)) {\n throw new TypeError(`${host.name}: the rpc option must be an array of method names.`);\n }\n const methods: string[] = [];\n for (const name of names) {\n const problem = rpcNameProblem(host, name, surface);\n if (problem !== undefined) throw new TypeError(problem);\n if (!methods.includes(name)) methods.push(name);\n }\n return {\n methods,\n handlers: surface.handlers.filter((name) => hasPrototypeMethod(host, name)),\n };\n}\n"],"mappings":";;;;;;AAKA,MAAM,wBAAQ,IAAI,IAAI;CACpB;CACA;CACA;CACA;CACA;CACA;CACA;CACA;AACF,CAAC;;AAsCD,SAAgB,gBAAgB,MAAiB,MAA8C;CAC7F,KACE,IAAI,YAAqB,KAAK,WAC9B,OAAO,cAAc,YAAY,cAAc,QAAQ,cAAc,OAAO,WAC5E,YAAY,OAAO,eAAe,SAAS,GAC3C;EACA,MAAM,aAAa,OAAO,yBAAyB,WAAW,IAAI;EAClE,IAAI,YAAY,OAAO;CACzB;AAEF;;AAGA,SAAgB,mBAAmB,MAAiB,MAAuB;CACzE,OAAO,OAAO,gBAAgB,MAAM,IAAI,CAAC,EAAE,UAAU;AACvD;;;;;;;AAQA,SAAgB,kBAAkB,MAAuB;CACvD,IAAI,gBAAgB,MAAM,MAAM,MAAM,KAAA,GAAW;CACjD,MAAM,IAAI,UACR,GAAG,KAAK,KAAK,+KAGf;AACF;;AAqBA,SAAS,eACP,MACA,MACA,SACoB;CACpB,IAAI,OAAO,SAAS,UAClB,OAAO,GAAG,KAAK,KAAK,4CAA4C,OAAO,IAAI,EAAE;CAE/E,IAAI,QAAQ,SAAS,IAAI,IAAI,GAC3B,OACE,GAAG,KAAK,KAAK,GAAG,KAAK,iBAAiB,QAAQ,MAAM,gBAAgB,KAAK,uBAC/D,QAAQ,MAAM;CAG5B,IAAI,MAAM,IAAI,IAAI,GAChB,OACE,GAAG,KAAK,KAAK,GAAG,KAAK,iBAAiB,QAAQ,MAAM;CAIxD,IAAK,QAAQ,SAA+B,SAAS,IAAI,GACvD,OACE,GAAG,KAAK,KAAK,GAAG,KAAK,YAAY,QAAQ,MAAM,GAAG,KAAK;CAI3D,IAAI,CAAC,mBAAmB,MAAM,IAAI,GAChC,OACE,GAAG,KAAK,KAAK,2BAA2B,KAAK;AAKnD;;;;;;;;;;AAWA,SAAgB,YACd,MACA,KACA,SAC4C;CAC5C,kBAAkB,IAAI;CACtB,MAAM,QAAQ,OAAO,CAAC;CACtB,IAAI,CAAC,MAAM,QAAQ,KAAK,GACtB,MAAM,IAAI,UAAU,GAAG,KAAK,KAAK,mDAAmD;CAEtF,MAAM,UAAoB,CAAC;CAC3B,KAAK,MAAM,QAAQ,OAAO;EACxB,MAAM,UAAU,eAAe,MAAM,MAAM,OAAO;EAClD,IAAI,YAAY,KAAA,GAAW,MAAM,IAAI,UAAU,OAAO;EACtD,IAAI,CAAC,QAAQ,SAAS,IAAI,GAAG,QAAQ,KAAK,IAAI;CAChD;CACA,OAAO;EACL;EACA,UAAU,QAAQ,SAAS,QAAQ,SAAS,mBAAmB,MAAM,IAAI,CAAC;CAC5E;AACF"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
//#region src/host/host-members.d.ts
|
|
2
|
+
/** Host members the application context calls, which are never RPC methods. */
|
|
3
|
+
type HostHookName = 'onModuleInit' | 'onApplicationBootstrap' | 'onModuleDestroy' | 'beforeApplicationShutdown' | 'onApplicationShutdown' | 'dispose' | 'collectEntrypoints';
|
|
4
|
+
/**
|
|
5
|
+
* The names a host's `rpc` list may take: its public methods, less the
|
|
6
|
+
* `Excluded` names. TypeScript `private` and `protected` methods are not
|
|
7
|
+
* among them.
|
|
8
|
+
*/
|
|
9
|
+
type RpcMethodOf<Host, Excluded extends string> = { [K in keyof Host]: K extends string ? K extends Excluded | HostHookName ? never : Host[K] extends ((...args: never[]) => unknown) ? K : never : never; }[keyof Host];
|
|
10
|
+
/** The RPC methods `Method` of `Host`, asynchronous, as the entrypoint's stubs call them. */
|
|
11
|
+
type RpcMethods<Host, Method extends keyof Host> = { [K in Method]: Host[K] extends ((...args: infer Args) => infer Result) ? (...args: Args) => Promise<Awaited<Result>> : never; };
|
|
12
|
+
//#endregion
|
|
13
|
+
export { RpcMethods as n, RpcMethodOf as t };
|