@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,160 @@
|
|
|
1
|
+
import { CLOUDFLARE_ENTRYPOINT, cloudflareApplication, isCloudflareApp, registerEntrypoint } from "../cloudflare-factory.js";
|
|
2
|
+
import { internalEntrypointError } from "../rpc/entrypoint-error.js";
|
|
3
|
+
import { HostInvoker, callRpcMethod, hostModuleId } from "../host/host-invoker.js";
|
|
4
|
+
import { hostMembers } from "../host/host-members.js";
|
|
5
|
+
import { InjectionToken, Scope } from "@velajs/vela";
|
|
6
|
+
import { WorkerEntrypoint } from "cloudflare:workers";
|
|
7
|
+
//#region src/entrypoint/vela-entrypoint.ts
|
|
8
|
+
/**
|
|
9
|
+
* The `props` of the current service entrypoint call (`ctx.props` in a
|
|
10
|
+
* hand-written `WorkerEntrypoint`): what the caller's service binding
|
|
11
|
+
* configuration (`services: [{ binding, service, entrypoint, props }]`) or a
|
|
12
|
+
* `ctx.exports` loopback stub attached. Request-scoped: it resolves only
|
|
13
|
+
* inside an RPC call of a `VelaEntrypoint()` class, and a class injecting it
|
|
14
|
+
* is built for each call. Validate it before use; it is `{}` when the caller
|
|
15
|
+
* attached none.
|
|
16
|
+
*/
|
|
17
|
+
const ENTRYPOINT_PROPS = /* @__PURE__ */ new InjectionToken("@velajs/cloudflare:entrypoint-props", {
|
|
18
|
+
scope: Scope.REQUEST,
|
|
19
|
+
factory: () => {
|
|
20
|
+
throw new Error("ENTRYPOINT_PROPS can only be resolved inside a service entrypoint RPC call: VelaEntrypoint() seeds it into each call with the caller ctx.props.");
|
|
21
|
+
}
|
|
22
|
+
});
|
|
23
|
+
/**
|
|
24
|
+
* Names an RPC method cannot take: the entrypoint's own `ctx` and `env`, the
|
|
25
|
+
* platform handlers of a `WorkerEntrypoint`, the stub members that shadow an
|
|
26
|
+
* RPC method of that name (`fetch()`, `connect()`, `dup()`), and `then`,
|
|
27
|
+
* which would make the stub and its results thenables.
|
|
28
|
+
*/
|
|
29
|
+
const SERVICE_ENTRYPOINT = {
|
|
30
|
+
label: "service entrypoint",
|
|
31
|
+
reserved: /* @__PURE__ */ new Set([
|
|
32
|
+
"ctx",
|
|
33
|
+
"env",
|
|
34
|
+
"dup",
|
|
35
|
+
"then",
|
|
36
|
+
...[
|
|
37
|
+
"fetch",
|
|
38
|
+
"connect",
|
|
39
|
+
"email",
|
|
40
|
+
"queue",
|
|
41
|
+
"scheduled",
|
|
42
|
+
"tail",
|
|
43
|
+
"tailStream",
|
|
44
|
+
"test",
|
|
45
|
+
"trace"
|
|
46
|
+
]
|
|
47
|
+
]),
|
|
48
|
+
handlers: []
|
|
49
|
+
};
|
|
50
|
+
/**
|
|
51
|
+
* @internal The RPC methods of `host` its service entrypoint class exposes:
|
|
52
|
+
* the methods `rpc` names. A hook, a reserved name, an accessor or an instance
|
|
53
|
+
* field throws, and so does a host whose prototype defines `then`. Read at
|
|
54
|
+
* class definition, without constructing the host.
|
|
55
|
+
*/
|
|
56
|
+
function entrypointHostMembers(host, rpc) {
|
|
57
|
+
return { methods: hostMembers(host, rpc, SERVICE_ENTRYPOINT).methods };
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* A service entrypoint class (a `WorkerEntrypoint`) whose JS-RPC methods are
|
|
61
|
+
* the methods of `host`, an `@Injectable()` class, that `rpc` names. Each call
|
|
62
|
+
* runs in the Worker's application for its environment: the one the app's
|
|
63
|
+
* Worker handlers use, with the host added to the root module's providers.
|
|
64
|
+
* Export a named subclass and bind it from another Worker (or this one) with
|
|
65
|
+
* `services: [{ binding, service, entrypoint: 'Billing' }]`:
|
|
66
|
+
*
|
|
67
|
+
* ```ts
|
|
68
|
+
* @Injectable()
|
|
69
|
+
* export class BillingHost {
|
|
70
|
+
* constructor(
|
|
71
|
+
* private readonly invoices: InvoicesService,
|
|
72
|
+
* @Inject(ENTRYPOINT_PROPS) private readonly props: unknown,
|
|
73
|
+
* ) {}
|
|
74
|
+
* async charge(customerId: string, cents: number): Promise<{ invoiceId: string }> {
|
|
75
|
+
* return this.invoices.charge(customerId, cents);
|
|
76
|
+
* }
|
|
77
|
+
* }
|
|
78
|
+
* export class Billing extends VelaEntrypoint(app, BillingHost, { rpc: ['charge'] }) {}
|
|
79
|
+
* // Caller: await env.BILLING.charge('customer-1', 500)
|
|
80
|
+
* ```
|
|
81
|
+
*
|
|
82
|
+
* - Exactly the host methods `rpc` names are RPC methods, typed so a
|
|
83
|
+
* `Service<typeof Billing>` binding exposes their signatures. Nothing else
|
|
84
|
+
* is reachable over RPC, even from plain JavaScript naming it on a stub. A
|
|
85
|
+
* listed name that is not a prototype method of the host, a hook, a
|
|
86
|
+
* `WorkerEntrypoint` handler (`fetch`, `connect`, `email`, `queue`,
|
|
87
|
+
* `scheduled`, `tail`, ...), `ctx`, `env`, `dup` or `then` throws here, and
|
|
88
|
+
* so does a host whose prototype defines `then()`.
|
|
89
|
+
* - Each call runs in its own execution scope, so request-scoped providers
|
|
90
|
+
* are built per call, through the host's scoped guards, pipes (the
|
|
91
|
+
* arguments), interceptors and filters (`getType()` is `'rpc'`). The
|
|
92
|
+
* caller's `ctx.props` is injectable as {@link ENTRYPOINT_PROPS}.
|
|
93
|
+
* - Failures are reported (`edge: 'rpc'`); a call rejects only with an
|
|
94
|
+
* `EntrypointError`, rendered like an HTTP response with server errors
|
|
95
|
+
* redacted.
|
|
96
|
+
*/
|
|
97
|
+
function VelaEntrypoint(app, host, options = {}) {
|
|
98
|
+
if (!isCloudflareApp(app)) throw new TypeError("VelaEntrypoint() takes the app from defineCloudflareApp(AppModule, options): each call runs in the Worker application that app builds.");
|
|
99
|
+
if (typeof host !== "function") throw new TypeError("VelaEntrypoint(app, Host, { rpc }) takes the @Injectable() host class.");
|
|
100
|
+
const members = entrypointHostMembers(host, options.rpc);
|
|
101
|
+
const methods = new Set(members.methods);
|
|
102
|
+
const rootClass = typeof app.rootModule === "function" ? app.rootModule : app.rootModule.module;
|
|
103
|
+
const invokers = /* @__PURE__ */ new WeakMap();
|
|
104
|
+
const invokerOf = (application) => {
|
|
105
|
+
const existing = invokers.get(application);
|
|
106
|
+
if (existing) return existing;
|
|
107
|
+
const container = application.getContainer();
|
|
108
|
+
const invoker = new HostInvoker({
|
|
109
|
+
container,
|
|
110
|
+
host,
|
|
111
|
+
moduleId: hostModuleId(container, host, rootClass),
|
|
112
|
+
edge: "rpc"
|
|
113
|
+
});
|
|
114
|
+
invokers.set(application, invoker);
|
|
115
|
+
return invoker;
|
|
116
|
+
};
|
|
117
|
+
/** The platform's `ctx` and `env` of each instance, readable by the methods defined below. */
|
|
118
|
+
const platform = /* @__PURE__ */ new WeakMap();
|
|
119
|
+
class VelaHostEntrypoint extends WorkerEntrypoint {
|
|
120
|
+
constructor(ctx, env) {
|
|
121
|
+
super(ctx, env);
|
|
122
|
+
platform.set(this, {
|
|
123
|
+
ctx,
|
|
124
|
+
env
|
|
125
|
+
});
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
const prototype = VelaHostEntrypoint.prototype;
|
|
129
|
+
for (const method of members.methods) Object.defineProperty(prototype, method, {
|
|
130
|
+
writable: true,
|
|
131
|
+
configurable: true,
|
|
132
|
+
value: async function(...args) {
|
|
133
|
+
const call = platform.get(this);
|
|
134
|
+
let application;
|
|
135
|
+
try {
|
|
136
|
+
if (call === void 0) throw new TypeError("Entrypoint method called on a foreign receiver.");
|
|
137
|
+
application = await cloudflareApplication(app, call.env);
|
|
138
|
+
} catch (error) {
|
|
139
|
+
console.error(`[vela] Service entrypoint ${host.name} failed to start:`, error);
|
|
140
|
+
throw internalEntrypointError();
|
|
141
|
+
}
|
|
142
|
+
const props = call.ctx.props ?? {};
|
|
143
|
+
return callRpcMethod(invokerOf(application), methods, method, args, (scope) => scope.setRequestInstance(ENTRYPOINT_PROPS, props));
|
|
144
|
+
}
|
|
145
|
+
});
|
|
146
|
+
const descriptor = {
|
|
147
|
+
rootModule: app.rootModule,
|
|
148
|
+
host,
|
|
149
|
+
methods: members.methods,
|
|
150
|
+
entrypoint: VelaHostEntrypoint
|
|
151
|
+
};
|
|
152
|
+
registerEntrypoint(app, descriptor);
|
|
153
|
+
Object.defineProperty(VelaHostEntrypoint, "name", { value: `${host.name}Entrypoint` });
|
|
154
|
+
Object.defineProperty(VelaHostEntrypoint, CLOUDFLARE_ENTRYPOINT, { value: descriptor });
|
|
155
|
+
return VelaHostEntrypoint;
|
|
156
|
+
}
|
|
157
|
+
//#endregion
|
|
158
|
+
export { ENTRYPOINT_PROPS, VelaEntrypoint, entrypointHostMembers };
|
|
159
|
+
|
|
160
|
+
//# sourceMappingURL=vela-entrypoint.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"vela-entrypoint.js","names":[],"sources":["../../src/entrypoint/vela-entrypoint.ts"],"sourcesContent":["import { WorkerEntrypoint } from 'cloudflare:workers';\nimport { InjectionToken, Scope } from '@velajs/vela';\nimport type { Type, VelaEnv } from '@velajs/vela';\nimport type { EntrypointExecutionContext } from '@velajs/vela/module-kit';\nimport type { CloudflareApplication } from '../cloudflare-application';\nimport {\n CLOUDFLARE_ENTRYPOINT,\n cloudflareApplication,\n isCloudflareApp,\n registerEntrypoint,\n type CloudflareApp,\n type CloudflareEntrypointDescriptor,\n} from '../cloudflare-factory';\nimport { HostInvoker, callRpcMethod, hostModuleId } from '../host/host-invoker';\nimport {\n hostMembers,\n type RpcMethodOf,\n type RpcMethods,\n type RpcSurface,\n} from '../host/host-members';\nimport { internalEntrypointError } from '../rpc/entrypoint-error';\n\n/**\n * The `props` of the current service entrypoint call (`ctx.props` in a\n * hand-written `WorkerEntrypoint`): what the caller's service binding\n * configuration (`services: [{ binding, service, entrypoint, props }]`) or a\n * `ctx.exports` loopback stub attached. Request-scoped: it resolves only\n * inside an RPC call of a `VelaEntrypoint()` class, and a class injecting it\n * is built for each call. Validate it before use; it is `{}` when the caller\n * attached none.\n */\nexport const ENTRYPOINT_PROPS = /* @__PURE__ */ new InjectionToken<unknown>(\n '@velajs/cloudflare:entrypoint-props',\n {\n scope: Scope.REQUEST,\n factory: () => {\n throw new Error(\n 'ENTRYPOINT_PROPS can only be resolved inside a service entrypoint RPC call: ' +\n 'VelaEntrypoint() seeds it into each call with the caller ctx.props.',\n );\n },\n },\n);\n\n/** WorkerEntrypoint handlers the platform calls, never RPC methods. */\nconst WORKER_ENTRYPOINT_HANDLERS = [\n 'fetch',\n 'connect',\n 'email',\n 'queue',\n 'scheduled',\n 'tail',\n 'tailStream',\n 'test',\n 'trace',\n] as const;\n\n/**\n * Names an RPC method cannot take: the entrypoint's own `ctx` and `env`, the\n * platform handlers of a `WorkerEntrypoint`, the stub members that shadow an\n * RPC method of that name (`fetch()`, `connect()`, `dup()`), and `then`,\n * which would make the stub and its results thenables.\n */\nconst SERVICE_ENTRYPOINT: RpcSurface<never> = {\n label: 'service entrypoint',\n reserved: new Set(['ctx', 'env', 'dup', 'then', ...WORKER_ENTRYPOINT_HANDLERS]),\n handlers: [],\n};\n\n/**\n * @internal The RPC methods of `host` its service entrypoint class exposes:\n * the methods `rpc` names. A hook, a reserved name, an accessor or an instance\n * field throws, and so does a host whose prototype defines `then`. Read at\n * class definition, without constructing the host.\n */\nexport function entrypointHostMembers(\n host: abstract new (...args: never[]) => unknown,\n rpc?: readonly string[],\n): { methods: string[] } {\n return { methods: hostMembers(host, rpc, SERVICE_ENTRYPOINT).methods };\n}\n\n/** Host members that are never RPC methods, besides hooks: the names {@link SERVICE_ENTRYPOINT} reserves. */\ntype NotRpcMethod = (typeof WORKER_ENTRYPOINT_HANDLERS)[number] | 'ctx' | 'env' | 'dup' | 'then';\n\n/**\n * The names a service entrypoint host's `rpc` list may take: its public\n * methods, less hooks, platform handlers and names the entrypoint or its\n * stubs own. TypeScript `private` and `protected` methods are not among them.\n */\nexport type EntrypointRpcMethod<Host> = RpcMethodOf<Host, NotRpcMethod>;\n\n/**\n * The RPC methods a `VelaEntrypoint(app, Host, { rpc })` class exposes: the\n * host methods `Method` names, asynchronous. A service binding to the class\n * (`Service<typeof Billing>`) calls them with these signatures.\n */\nexport type EntrypointRpc<Host, Method extends EntrypointRpcMethod<Host>> = RpcMethods<\n Host,\n Method\n>;\n\n/** Options of {@link VelaEntrypoint}. */\nexport interface VelaEntrypointOptions<Method extends string = string> {\n /**\n * The host methods callers may invoke over JS-RPC, such as\n * `['charge', 'refund']`: public methods declared in the host's class body\n * (or inherited). Nothing else is an RPC method, so TypeScript `private`\n * helpers, hooks and unlisted methods stay unreachable.\n */\n readonly rpc?: readonly Method[];\n}\n\n/**\n * The class `VelaEntrypoint(app, Host, { rpc })` returns: export a named\n * subclass of it, which service bindings name as their `entrypoint`. It also\n * carries its `CloudflareEntrypointDescriptor` under the static\n * `CLOUDFLARE_ENTRYPOINT` key, for tools.\n */\nexport type VelaEntrypointClass<Host, Method extends EntrypointRpcMethod<Host> = never> = new (\n ctx: ExecutionContext,\n env: VelaEnv,\n) => WorkerEntrypoint<VelaEnv> & EntrypointRpc<Host, Method>;\n\n/** The ExecutionContext guards, interceptors and filters receive around a service RPC call. */\nexport type EntrypointRpcExecutionContext = EntrypointExecutionContext<'rpc'>;\n\n/**\n * A service entrypoint class (a `WorkerEntrypoint`) whose JS-RPC methods are\n * the methods of `host`, an `@Injectable()` class, that `rpc` names. Each call\n * runs in the Worker's application for its environment: the one the app's\n * Worker handlers use, with the host added to the root module's providers.\n * Export a named subclass and bind it from another Worker (or this one) with\n * `services: [{ binding, service, entrypoint: 'Billing' }]`:\n *\n * ```ts\n * @Injectable()\n * export class BillingHost {\n * constructor(\n * private readonly invoices: InvoicesService,\n * @Inject(ENTRYPOINT_PROPS) private readonly props: unknown,\n * ) {}\n * async charge(customerId: string, cents: number): Promise<{ invoiceId: string }> {\n * return this.invoices.charge(customerId, cents);\n * }\n * }\n * export class Billing extends VelaEntrypoint(app, BillingHost, { rpc: ['charge'] }) {}\n * // Caller: await env.BILLING.charge('customer-1', 500)\n * ```\n *\n * - Exactly the host methods `rpc` names are RPC methods, typed so a\n * `Service<typeof Billing>` binding exposes their signatures. Nothing else\n * is reachable over RPC, even from plain JavaScript naming it on a stub. A\n * listed name that is not a prototype method of the host, a hook, a\n * `WorkerEntrypoint` handler (`fetch`, `connect`, `email`, `queue`,\n * `scheduled`, `tail`, ...), `ctx`, `env`, `dup` or `then` throws here, and\n * so does a host whose prototype defines `then()`.\n * - Each call runs in its own execution scope, so request-scoped providers\n * are built per call, through the host's scoped guards, pipes (the\n * arguments), interceptors and filters (`getType()` is `'rpc'`). The\n * caller's `ctx.props` is injectable as {@link ENTRYPOINT_PROPS}.\n * - Failures are reported (`edge: 'rpc'`); a call rejects only with an\n * `EntrypointError`, rendered like an HTTP response with server errors\n * redacted.\n */\nexport function VelaEntrypoint<\n Host extends object,\n const Method extends EntrypointRpcMethod<Host> = never,\n>(\n app: CloudflareApp,\n host: Type<Host>,\n options: VelaEntrypointOptions<Method> = {},\n): VelaEntrypointClass<Host, Method> {\n if (!isCloudflareApp(app)) {\n throw new TypeError(\n 'VelaEntrypoint() takes the app from defineCloudflareApp(AppModule, options): each call ' +\n 'runs in the Worker application that app builds.',\n );\n }\n if (typeof host !== 'function') {\n throw new TypeError('VelaEntrypoint(app, Host, { rpc }) takes the @Injectable() host class.');\n }\n const members = entrypointHostMembers(host, options.rpc);\n const methods: ReadonlySet<string> = new Set(members.methods);\n const rootClass = typeof app.rootModule === 'function' ? app.rootModule : app.rootModule.module;\n const invokers = new WeakMap<CloudflareApplication, HostInvoker>();\n const invokerOf = (application: CloudflareApplication): HostInvoker => {\n const existing = invokers.get(application);\n if (existing) return existing;\n const container = application.getContainer();\n const invoker = new HostInvoker({\n container,\n host,\n moduleId: hostModuleId(container, host, rootClass),\n edge: 'rpc',\n });\n invokers.set(application, invoker);\n return invoker;\n };\n /** The platform's `ctx` and `env` of each instance, readable by the methods defined below. */\n const platform = new WeakMap<object, { ctx: ExecutionContext; env: VelaEnv }>();\n\n class VelaHostEntrypoint extends WorkerEntrypoint<VelaEnv> {\n constructor(ctx: ExecutionContext, env: VelaEnv) {\n super(ctx, env);\n platform.set(this, { ctx, env });\n }\n }\n\n const prototype = VelaHostEntrypoint.prototype;\n for (const method of members.methods) {\n Object.defineProperty(prototype, method, {\n writable: true,\n configurable: true,\n value: async function (this: object, ...args: unknown[]): Promise<unknown> {\n const call = platform.get(this);\n let application: CloudflareApplication;\n try {\n if (call === undefined)\n throw new TypeError('Entrypoint method called on a foreign receiver.');\n application = await cloudflareApplication(app, call.env);\n } catch (error) {\n // A caller learns that the application failed to start, never why.\n console.error(`[vela] Service entrypoint ${host.name} failed to start:`, error);\n throw internalEntrypointError();\n }\n const props: unknown = call.ctx.props ?? {};\n return callRpcMethod(invokerOf(application), methods, method, args, (scope) =>\n scope.setRequestInstance(ENTRYPOINT_PROPS, props),\n );\n },\n });\n }\n\n const descriptor: CloudflareEntrypointDescriptor = {\n rootModule: app.rootModule,\n host,\n methods: members.methods,\n entrypoint: VelaHostEntrypoint,\n };\n registerEntrypoint(app, descriptor);\n Object.defineProperty(VelaHostEntrypoint, 'name', { value: `${host.name}Entrypoint` });\n Object.defineProperty(VelaHostEntrypoint, CLOUDFLARE_ENTRYPOINT, { value: descriptor });\n // The RPC methods are defined on the prototype above, at runtime, from the rpc list.\n return VelaHostEntrypoint as unknown as VelaEntrypointClass<Host, Method>;\n}\n"],"mappings":";;;;;;;;;;;;;;;;AA+BA,MAAa,mCAAmC,IAAI,eAClD,uCACA;CACE,OAAO,MAAM;CACb,eAAe;EACb,MAAM,IAAI,MACR,iJAEF;CACF;AACF,CACF;;;;;;;AAqBA,MAAM,qBAAwC;CAC5C,OAAO;CACP,0BAAU,IAAI,IAAI;EAAC;EAAO;EAAO;EAAO;EAAQ,GAAG;GAnBnD;GACA;GACA;GACA;GACA;GACA;GACA;GACA;GACA;EAW4E;CAAC,CAAC;CAC9E,UAAU,CAAC;AACb;;;;;;;AAQA,SAAgB,sBACd,MACA,KACuB;CACvB,OAAO,EAAE,SAAS,YAAY,MAAM,KAAK,kBAAkB,CAAC,CAAC,QAAQ;AACvE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAqFA,SAAgB,eAId,KACA,MACA,UAAyC,CAAC,GACP;CACnC,IAAI,CAAC,gBAAgB,GAAG,GACtB,MAAM,IAAI,UACR,wIAEF;CAEF,IAAI,OAAO,SAAS,YAClB,MAAM,IAAI,UAAU,wEAAwE;CAE9F,MAAM,UAAU,sBAAsB,MAAM,QAAQ,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AmB,KAAK,UAAU;CAClC,OAAO,eAAe,oBAAoB,QAAQ,EAAE,OAAO,GAAG,KAAK,KAAK,YAAY,CAAC;CACrF,OAAO,eAAe,oBAAoB,uBAAuB,EAAE,OAAO,WAAW,CAAC;CAEtF,OAAO;AACT"}
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
import "./vela-env-DFvyoNT3.js";
|
|
2
|
+
import { a as CloudflareApp } from "./cloudflare-factory-CuFNUJJD.js";
|
|
3
|
+
import { n as RpcMethods, t as RpcMethodOf } from "./host-members-DECj_4yz.js";
|
|
4
|
+
import { WorkerEntrypoint } from "cloudflare:workers";
|
|
5
|
+
import { InjectionToken, Type, VelaEnv } from "@velajs/vela";
|
|
6
|
+
import { EntrypointExecutionContext } from "@velajs/vela/module-kit";
|
|
7
|
+
//#region src/entrypoint/vela-entrypoint.d.ts
|
|
8
|
+
/**
|
|
9
|
+
* The `props` of the current service entrypoint call (`ctx.props` in a
|
|
10
|
+
* hand-written `WorkerEntrypoint`): what the caller's service binding
|
|
11
|
+
* configuration (`services: [{ binding, service, entrypoint, props }]`) or a
|
|
12
|
+
* `ctx.exports` loopback stub attached. Request-scoped: it resolves only
|
|
13
|
+
* inside an RPC call of a `VelaEntrypoint()` class, and a class injecting it
|
|
14
|
+
* is built for each call. Validate it before use; it is `{}` when the caller
|
|
15
|
+
* attached none.
|
|
16
|
+
*/
|
|
17
|
+
export declare const ENTRYPOINT_PROPS: InjectionToken<unknown>;
|
|
18
|
+
/** WorkerEntrypoint handlers the platform calls, never RPC methods. */
|
|
19
|
+
declare const WORKER_ENTRYPOINT_HANDLERS: readonly ['fetch', 'connect', 'email', 'queue', 'scheduled', 'tail', 'tailStream', 'test', 'trace'];
|
|
20
|
+
/** Host members that are never RPC methods, besides hooks: the names {@link SERVICE_ENTRYPOINT} reserves. */
|
|
21
|
+
type NotRpcMethod = (typeof WORKER_ENTRYPOINT_HANDLERS)[number] | 'ctx' | 'env' | 'dup' | 'then';
|
|
22
|
+
/**
|
|
23
|
+
* The names a service entrypoint host's `rpc` list may take: its public
|
|
24
|
+
* methods, less hooks, platform handlers and names the entrypoint or its
|
|
25
|
+
* stubs own. TypeScript `private` and `protected` methods are not among them.
|
|
26
|
+
*/
|
|
27
|
+
type EntrypointRpcMethod<Host> = RpcMethodOf<Host, NotRpcMethod>;
|
|
28
|
+
/**
|
|
29
|
+
* The RPC methods a `VelaEntrypoint(app, Host, { rpc })` class exposes: the
|
|
30
|
+
* host methods `Method` names, asynchronous. A service binding to the class
|
|
31
|
+
* (`Service<typeof Billing>`) calls them with these signatures.
|
|
32
|
+
*/
|
|
33
|
+
type EntrypointRpc<Host, Method extends EntrypointRpcMethod<Host>> = RpcMethods<Host, Method>;
|
|
34
|
+
/** Options of {@link VelaEntrypoint}. */
|
|
35
|
+
interface VelaEntrypointOptions<Method extends string = string> {
|
|
36
|
+
/**
|
|
37
|
+
* The host methods callers may invoke over JS-RPC, such as
|
|
38
|
+
* `['charge', 'refund']`: public methods declared in the host's class body
|
|
39
|
+
* (or inherited). Nothing else is an RPC method, so TypeScript `private`
|
|
40
|
+
* helpers, hooks and unlisted methods stay unreachable.
|
|
41
|
+
*/
|
|
42
|
+
readonly rpc?: readonly Method[];
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* The class `VelaEntrypoint(app, Host, { rpc })` returns: export a named
|
|
46
|
+
* subclass of it, which service bindings name as their `entrypoint`. It also
|
|
47
|
+
* carries its `CloudflareEntrypointDescriptor` under the static
|
|
48
|
+
* `CLOUDFLARE_ENTRYPOINT` key, for tools.
|
|
49
|
+
*/
|
|
50
|
+
type VelaEntrypointClass<Host, Method extends EntrypointRpcMethod<Host> = never> = new (ctx: ExecutionContext, env: VelaEnv) => WorkerEntrypoint<VelaEnv> & EntrypointRpc<Host, Method>;
|
|
51
|
+
/** The ExecutionContext guards, interceptors and filters receive around a service RPC call. */
|
|
52
|
+
type EntrypointRpcExecutionContext = EntrypointExecutionContext<'rpc'>;
|
|
53
|
+
/**
|
|
54
|
+
* A service entrypoint class (a `WorkerEntrypoint`) whose JS-RPC methods are
|
|
55
|
+
* the methods of `host`, an `@Injectable()` class, that `rpc` names. Each call
|
|
56
|
+
* runs in the Worker's application for its environment: the one the app's
|
|
57
|
+
* Worker handlers use, with the host added to the root module's providers.
|
|
58
|
+
* Export a named subclass and bind it from another Worker (or this one) with
|
|
59
|
+
* `services: [{ binding, service, entrypoint: 'Billing' }]`:
|
|
60
|
+
*
|
|
61
|
+
* ```ts
|
|
62
|
+
* @Injectable()
|
|
63
|
+
* export class BillingHost {
|
|
64
|
+
* constructor(
|
|
65
|
+
* private readonly invoices: InvoicesService,
|
|
66
|
+
* @Inject(ENTRYPOINT_PROPS) private readonly props: unknown,
|
|
67
|
+
* ) {}
|
|
68
|
+
* async charge(customerId: string, cents: number): Promise<{ invoiceId: string }> {
|
|
69
|
+
* return this.invoices.charge(customerId, cents);
|
|
70
|
+
* }
|
|
71
|
+
* }
|
|
72
|
+
* export class Billing extends VelaEntrypoint(app, BillingHost, { rpc: ['charge'] }) {}
|
|
73
|
+
* // Caller: await env.BILLING.charge('customer-1', 500)
|
|
74
|
+
* ```
|
|
75
|
+
*
|
|
76
|
+
* - Exactly the host methods `rpc` names are RPC methods, typed so a
|
|
77
|
+
* `Service<typeof Billing>` binding exposes their signatures. Nothing else
|
|
78
|
+
* is reachable over RPC, even from plain JavaScript naming it on a stub. A
|
|
79
|
+
* listed name that is not a prototype method of the host, a hook, a
|
|
80
|
+
* `WorkerEntrypoint` handler (`fetch`, `connect`, `email`, `queue`,
|
|
81
|
+
* `scheduled`, `tail`, ...), `ctx`, `env`, `dup` or `then` throws here, and
|
|
82
|
+
* so does a host whose prototype defines `then()`.
|
|
83
|
+
* - Each call runs in its own execution scope, so request-scoped providers
|
|
84
|
+
* are built per call, through the host's scoped guards, pipes (the
|
|
85
|
+
* arguments), interceptors and filters (`getType()` is `'rpc'`). The
|
|
86
|
+
* caller's `ctx.props` is injectable as {@link ENTRYPOINT_PROPS}.
|
|
87
|
+
* - Failures are reported (`edge: 'rpc'`); a call rejects only with an
|
|
88
|
+
* `EntrypointError`, rendered like an HTTP response with server errors
|
|
89
|
+
* redacted.
|
|
90
|
+
*/
|
|
91
|
+
export declare function VelaEntrypoint<Host extends object, const Method extends EntrypointRpcMethod<Host> = never>(app: CloudflareApp, host: Type<Host>, options?: VelaEntrypointOptions<Method>): VelaEntrypointClass<Host, Method>;
|
|
92
|
+
//#endregion
|
|
93
|
+
export type { EntrypointRpc, EntrypointRpcExecutionContext, EntrypointRpcMethod, VelaEntrypointClass, VelaEntrypointOptions };
|
|
@@ -0,0 +1,276 @@
|
|
|
1
|
+
import { EntrypointError, internalEntrypointError, renderEntrypointError } from "../rpc/entrypoint-error.js";
|
|
2
|
+
import { PipelineRunner, buildEntrypointExecutionContext, createExecutionScope, getEntrypointModuleId, getMetadata, resolveErrorReporter, resolveScopedComponentsAsync, shouldFilterCatch } from "@velajs/vela/module-kit";
|
|
3
|
+
//#region src/host/host-invoker.ts
|
|
4
|
+
/** The first scoped filter (closest first) that catches `error`. */
|
|
5
|
+
function claimingFilter(filters, error) {
|
|
6
|
+
return filters.find((filter) => shouldFilterCatch(filter, error));
|
|
7
|
+
}
|
|
8
|
+
/** A filter that throws replaces the error; its own throw is reported too. */
|
|
9
|
+
async function catchWith(filter, error, { context, reporter, report }) {
|
|
10
|
+
try {
|
|
11
|
+
return {
|
|
12
|
+
handled: true,
|
|
13
|
+
value: await filter.catch(error, context)
|
|
14
|
+
};
|
|
15
|
+
} catch (replacement) {
|
|
16
|
+
if (replacement !== error) reporter.report(replacement, {
|
|
17
|
+
...report,
|
|
18
|
+
note: "exception filter threw"
|
|
19
|
+
});
|
|
20
|
+
return {
|
|
21
|
+
handled: false,
|
|
22
|
+
error: replacement
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* A JS-RPC call: a claiming filter may recover with a result (returning
|
|
28
|
+
* nothing keeps the failure); otherwise the call rejects with the rendered
|
|
29
|
+
* {@link EntrypointError}.
|
|
30
|
+
*/
|
|
31
|
+
const rpcSettlement = {
|
|
32
|
+
success: (value) => value,
|
|
33
|
+
async failure(error, failure) {
|
|
34
|
+
const filter = claimingFilter(failure.filters, error);
|
|
35
|
+
let current = error;
|
|
36
|
+
if (filter) {
|
|
37
|
+
const caught = await catchWith(filter, error, failure);
|
|
38
|
+
if (caught.handled && caught.value !== void 0) return caught.value;
|
|
39
|
+
if (!caught.handled) current = caught.error;
|
|
40
|
+
}
|
|
41
|
+
throw renderEntrypointError(current, failure.reporter, failure.context);
|
|
42
|
+
}
|
|
43
|
+
};
|
|
44
|
+
/**
|
|
45
|
+
* A platform event: a claiming filter handles the failure (a value it returns
|
|
46
|
+
* becomes the result); otherwise the platform sees the error.
|
|
47
|
+
*/
|
|
48
|
+
function platformSettlement(completionFails) {
|
|
49
|
+
return {
|
|
50
|
+
completionFails,
|
|
51
|
+
success: (value) => value,
|
|
52
|
+
async failure(error, failure) {
|
|
53
|
+
const filter = claimingFilter(failure.filters, error);
|
|
54
|
+
if (!filter) throw error;
|
|
55
|
+
const caught = await catchWith(filter, error, failure);
|
|
56
|
+
if (!caught.handled) throw caught.error;
|
|
57
|
+
return caught.value;
|
|
58
|
+
}
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* An event whose failures must never reach the platform, such as a tail
|
|
63
|
+
* event: the failure was reported, and a claiming filter still runs.
|
|
64
|
+
*/
|
|
65
|
+
const observedSettlement = {
|
|
66
|
+
success: () => void 0,
|
|
67
|
+
async failure(error, failure) {
|
|
68
|
+
const filter = claimingFilter(failure.filters, error);
|
|
69
|
+
if (filter) await catchWith(filter, error, failure);
|
|
70
|
+
}
|
|
71
|
+
};
|
|
72
|
+
/**
|
|
73
|
+
* Runs invocations of one host's methods: each in a fresh execution scope
|
|
74
|
+
* (request-scoped providers are built per invocation) through the host's
|
|
75
|
+
* scoped guards, pipes (when asked), interceptors and exception filters.
|
|
76
|
+
* Application-wide `APP_*` components do not apply: the callers are other
|
|
77
|
+
* Workers and the platform, with no HTTP request. Failures are reported
|
|
78
|
+
* first, then settled the way the invocation's kind requires.
|
|
79
|
+
*/
|
|
80
|
+
var HostInvoker = class {
|
|
81
|
+
#container;
|
|
82
|
+
#host;
|
|
83
|
+
#moduleId;
|
|
84
|
+
#edge;
|
|
85
|
+
#waitUntil;
|
|
86
|
+
constructor(options) {
|
|
87
|
+
this.#container = options.container;
|
|
88
|
+
this.#host = options.host;
|
|
89
|
+
this.#moduleId = options.moduleId;
|
|
90
|
+
this.#edge = options.edge;
|
|
91
|
+
this.#waitUntil = options.waitUntil;
|
|
92
|
+
}
|
|
93
|
+
/** The report context of an invocation of `method`. */
|
|
94
|
+
report(kind, method) {
|
|
95
|
+
return {
|
|
96
|
+
edge: this.#edge,
|
|
97
|
+
source: `${this.#host.name}.${String(method)}`,
|
|
98
|
+
kind
|
|
99
|
+
};
|
|
100
|
+
}
|
|
101
|
+
/** Report through the application, or the console when its reporter cannot be built. */
|
|
102
|
+
reportOutside(error, report) {
|
|
103
|
+
try {
|
|
104
|
+
resolveErrorReporter(this.#container).report(error, report);
|
|
105
|
+
} catch {
|
|
106
|
+
console.error(`[vela] ${report.edge} error in ${report.source ?? "an entrypoint"}:`, error);
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
async invoke(invocation) {
|
|
110
|
+
const root = this.#container;
|
|
111
|
+
const report = this.report(invocation.kind, invocation.method);
|
|
112
|
+
const scope = createExecutionScope(root);
|
|
113
|
+
let outcome;
|
|
114
|
+
try {
|
|
115
|
+
invocation.seed?.(scope.container);
|
|
116
|
+
outcome = {
|
|
117
|
+
ok: true,
|
|
118
|
+
value: await this.#run(scope.container, invocation, report)
|
|
119
|
+
};
|
|
120
|
+
} catch (error) {
|
|
121
|
+
outcome = {
|
|
122
|
+
ok: false,
|
|
123
|
+
error
|
|
124
|
+
};
|
|
125
|
+
}
|
|
126
|
+
let transmission;
|
|
127
|
+
try {
|
|
128
|
+
transmission = outcome.ok ? invocation.transmit?.(outcome.value) : void 0;
|
|
129
|
+
} catch (error) {
|
|
130
|
+
outcome = {
|
|
131
|
+
ok: false,
|
|
132
|
+
error
|
|
133
|
+
};
|
|
134
|
+
}
|
|
135
|
+
if (transmission?.background) {
|
|
136
|
+
this.#finishLater(scope, transmission.sent, report);
|
|
137
|
+
return transmission.value;
|
|
138
|
+
}
|
|
139
|
+
try {
|
|
140
|
+
await scope.finish(transmission?.sent);
|
|
141
|
+
} catch (completion) {
|
|
142
|
+
this.reportOutside(completion, {
|
|
143
|
+
...report,
|
|
144
|
+
note: "managed work failed after the invocation"
|
|
145
|
+
});
|
|
146
|
+
if (invocation.settlement.completionFails && outcome.ok) outcome = {
|
|
147
|
+
ok: false,
|
|
148
|
+
error: completion
|
|
149
|
+
};
|
|
150
|
+
}
|
|
151
|
+
if (!outcome.ok) throw outcome.error;
|
|
152
|
+
return transmission ? transmission.value : outcome.value;
|
|
153
|
+
}
|
|
154
|
+
/** Finish `scope` after `boundary` settles, reporting a failure; the platform waits for it. */
|
|
155
|
+
#finishLater(scope, boundary, report) {
|
|
156
|
+
const completion = scope.finish(boundary).catch((error) => {
|
|
157
|
+
this.reportOutside(error, {
|
|
158
|
+
...report,
|
|
159
|
+
note: "managed work failed after the response"
|
|
160
|
+
});
|
|
161
|
+
});
|
|
162
|
+
this.#waitUntil?.(completion);
|
|
163
|
+
}
|
|
164
|
+
async #run(scope, invocation, report) {
|
|
165
|
+
const host = this.#host;
|
|
166
|
+
const moduleId = this.#moduleId;
|
|
167
|
+
const { kind, method, args, settlement } = invocation;
|
|
168
|
+
const context = buildEntrypointExecutionContext(kind, host, method, "payload" in invocation ? invocation.payload : args, moduleId, scope);
|
|
169
|
+
const reporter = resolveErrorReporter(scope);
|
|
170
|
+
let filters = [];
|
|
171
|
+
try {
|
|
172
|
+
filters = (await resolveScopedComponentsAsync("filter", host, method, scope, moduleId)).toReversed();
|
|
173
|
+
const guards = await resolveScopedComponentsAsync("guard", host, method, scope, moduleId);
|
|
174
|
+
const interceptors = await resolveScopedComponentsAsync("interceptor", host, method, scope, moduleId);
|
|
175
|
+
const value = await PipelineRunner.run({
|
|
176
|
+
context,
|
|
177
|
+
guards,
|
|
178
|
+
interceptors,
|
|
179
|
+
resolveArgs: () => invocation.pipes ? this.#transformArguments(scope, method, args) : Promise.resolve([...args]),
|
|
180
|
+
invoke: async (resolved) => {
|
|
181
|
+
const instance = await scope.resolveAsync(host, moduleId);
|
|
182
|
+
if (typeof instance !== "object" || instance === null) throw new TypeError(`${host.name} did not resolve to an object.`);
|
|
183
|
+
const handler = Reflect.get(instance, method);
|
|
184
|
+
if (typeof handler !== "function") throw new TypeError(`${host.name}.${String(method)} is not a method.`);
|
|
185
|
+
return Reflect.apply(handler, instance, resolved);
|
|
186
|
+
}
|
|
187
|
+
});
|
|
188
|
+
return settlement.success(value);
|
|
189
|
+
} catch (error) {
|
|
190
|
+
if (invocation.passthrough?.(error) === true) throw error;
|
|
191
|
+
reporter.report(error, report);
|
|
192
|
+
return settlement.failure(error, {
|
|
193
|
+
filters,
|
|
194
|
+
context,
|
|
195
|
+
reporter,
|
|
196
|
+
report
|
|
197
|
+
});
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
/** Scoped pipes transform each argument, typed by the method's parameter metadata. */
|
|
201
|
+
async #transformArguments(scope, method, args) {
|
|
202
|
+
const pipes = await resolveScopedComponentsAsync("pipe", this.#host, method, scope, this.#moduleId);
|
|
203
|
+
if (pipes.length === 0) return [...args];
|
|
204
|
+
const types = getMetadata("design:paramtypes", this.#host.prototype, method);
|
|
205
|
+
const transformed = [];
|
|
206
|
+
for (const [index, argument] of args.entries()) {
|
|
207
|
+
const metadata = {
|
|
208
|
+
type: "custom",
|
|
209
|
+
metatype: types?.[index]
|
|
210
|
+
};
|
|
211
|
+
let value = argument;
|
|
212
|
+
for (const pipe of pipes) value = await (pipe.transformAsync ? pipe.transformAsync(value, metadata) : pipe.transform(value, metadata));
|
|
213
|
+
transformed.push(value);
|
|
214
|
+
}
|
|
215
|
+
return transformed;
|
|
216
|
+
}
|
|
217
|
+
};
|
|
218
|
+
/**
|
|
219
|
+
* Call the RPC method `method` of a host through `invoker`. It rejects only
|
|
220
|
+
* with an {@link EntrypointError}: a method `methods` does not list answers
|
|
221
|
+
* `404 not_found`, and a failure outside the pipeline is reported and becomes
|
|
222
|
+
* `500 internal`.
|
|
223
|
+
*/
|
|
224
|
+
async function callRpcMethod(invoker, methods, method, args, seed) {
|
|
225
|
+
if (!methods.has(method)) throw new EntrypointError({
|
|
226
|
+
status: 404,
|
|
227
|
+
code: "not_found",
|
|
228
|
+
message: "Unknown RPC method"
|
|
229
|
+
});
|
|
230
|
+
try {
|
|
231
|
+
return await invoker.invoke({
|
|
232
|
+
kind: "rpc",
|
|
233
|
+
method,
|
|
234
|
+
args,
|
|
235
|
+
settlement: rpcSettlement,
|
|
236
|
+
pipes: true,
|
|
237
|
+
seed
|
|
238
|
+
});
|
|
239
|
+
} catch (error) {
|
|
240
|
+
if (error instanceof EntrypointError) throw error;
|
|
241
|
+
invoker.reportOutside(error, invoker.report("rpc", method));
|
|
242
|
+
throw internalEntrypointError();
|
|
243
|
+
}
|
|
244
|
+
}
|
|
245
|
+
/**
|
|
246
|
+
* An invoker of a decorated method entrypoint (`@OnEmail()`, `@OnTail()`):
|
|
247
|
+
* its class, resolved in the module that registered it.
|
|
248
|
+
*/
|
|
249
|
+
function entrypointInvoker(container, entrypoint, edge) {
|
|
250
|
+
const { token } = entrypoint;
|
|
251
|
+
if (typeof token !== "function") throw new TypeError("Entrypoint token must be a class.");
|
|
252
|
+
return new HostInvoker({
|
|
253
|
+
container,
|
|
254
|
+
host: token,
|
|
255
|
+
moduleId: getEntrypointModuleId(container, entrypoint),
|
|
256
|
+
edge
|
|
257
|
+
});
|
|
258
|
+
}
|
|
259
|
+
/** Wait for every invocation, even when one fails before its siblings; then fail with them. */
|
|
260
|
+
async function settleInvocations(work) {
|
|
261
|
+
const errors = (await Promise.allSettled(work)).flatMap((outcome) => outcome.status === "rejected" ? [outcome.reason] : []);
|
|
262
|
+
if (errors.length === 1) throw errors[0];
|
|
263
|
+
if (errors.length > 1) throw new AggregateError(errors, "Multiple entrypoint handlers failed.");
|
|
264
|
+
}
|
|
265
|
+
/**
|
|
266
|
+
* The module a host added to the root module's providers is resolved in: the
|
|
267
|
+
* root's registration when there are several.
|
|
268
|
+
*/
|
|
269
|
+
function hostModuleId(container, host, rootClass) {
|
|
270
|
+
const owners = container.getOwnerModuleIds(host);
|
|
271
|
+
return owners.find((owner) => container.getModuleScope(owner)?.moduleClass === rootClass) ?? owners[0];
|
|
272
|
+
}
|
|
273
|
+
//#endregion
|
|
274
|
+
export { HostInvoker, callRpcMethod, catchWith, claimingFilter, entrypointInvoker, hostModuleId, observedSettlement, platformSettlement, rpcSettlement, settleInvocations };
|
|
275
|
+
|
|
276
|
+
//# sourceMappingURL=host-invoker.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"host-invoker.js","names":[],"sources":["../../src/host/host-invoker.ts"],"sourcesContent":["/* eslint-disable no-await-in-loop -- Pipes and exception filters keep their declared order. */\nimport type { ErrorReportContext, ExceptionFilter, Type } from '@velajs/vela';\nimport {\n PipelineRunner,\n buildEntrypointExecutionContext,\n createExecutionScope,\n getEntrypointModuleId,\n getMetadata,\n resolveErrorReporter,\n resolveScopedComponentsAsync,\n shouldFilterCatch,\n type Container,\n type Entrypoint,\n type EntrypointExecutionContext,\n type ErrorReporter,\n type ExecutionScope,\n} from '@velajs/vela/module-kit';\nimport {\n EntrypointError,\n internalEntrypointError,\n renderEntrypointError,\n} from '../rpc/entrypoint-error';\n\n/** What a failed invocation hands its settlement, after the failure was reported. */\nexport interface InvocationFailure {\n readonly filters: readonly ExceptionFilter[];\n readonly context: EntrypointExecutionContext;\n readonly reporter: ErrorReporter;\n readonly report: ErrorReportContext;\n}\n\n/** How an invocation's result is sent after its handler returned. */\nexport interface Transmission<T> {\n /** What the invocation returns in place of the handler's result. */\n readonly value: T;\n /** Settles once the result was sent, failed or was cancelled. */\n readonly sent: Promise<unknown>;\n /** Finish the scope after the invocation returns, rather than before. */\n readonly background: boolean;\n}\n\n/** How one kind of invocation ends: its result, and what a failure becomes. */\nexport interface Settlement<T> {\n success(value: unknown): T;\n failure(error: unknown, failure: InvocationFailure): Promise<T>;\n /** Managed work that fails after a successful handler fails the invocation. */\n readonly completionFails?: boolean;\n}\n\n/** The first scoped filter (closest first) that catches `error`. */\nexport function claimingFilter(\n filters: readonly ExceptionFilter[],\n error: unknown,\n): ExceptionFilter | undefined {\n return filters.find((filter) => shouldFilterCatch(filter, error));\n}\n\n/** A filter that throws replaces the error; its own throw is reported too. */\nexport async function catchWith(\n filter: ExceptionFilter,\n error: unknown,\n { context, reporter, report }: InvocationFailure,\n): Promise<{ handled: true; value: unknown } | { handled: false; error: unknown }> {\n try {\n // eslint-disable-next-line promise/valid-params -- The Vela ExceptionFilter hook.\n return { handled: true, value: await filter.catch(error, context) };\n } catch (replacement) {\n if (replacement !== error) {\n reporter.report(replacement, { ...report, note: 'exception filter threw' });\n }\n return { handled: false, error: replacement };\n }\n}\n\n/**\n * A JS-RPC call: a claiming filter may recover with a result (returning\n * nothing keeps the failure); otherwise the call rejects with the rendered\n * {@link EntrypointError}.\n */\nexport const rpcSettlement: Settlement<unknown> = {\n success: (value) => value,\n async failure(error, failure) {\n const filter = claimingFilter(failure.filters, error);\n let current = error;\n if (filter) {\n const caught = await catchWith(filter, error, failure);\n if (caught.handled && caught.value !== undefined) return caught.value;\n if (!caught.handled) current = caught.error;\n }\n throw renderEntrypointError(current, failure.reporter, failure.context);\n },\n};\n\n/**\n * A platform event: a claiming filter handles the failure (a value it returns\n * becomes the result); otherwise the platform sees the error.\n */\nexport function platformSettlement(completionFails: boolean): Settlement<unknown> {\n return {\n completionFails,\n success: (value) => value,\n async failure(error, failure) {\n const filter = claimingFilter(failure.filters, error);\n if (!filter) throw error;\n const caught = await catchWith(filter, error, failure);\n if (!caught.handled) throw caught.error;\n return caught.value;\n },\n };\n}\n\n/**\n * An event whose failures must never reach the platform, such as a tail\n * event: the failure was reported, and a claiming filter still runs.\n */\nexport const observedSettlement: Settlement<void> = {\n success: () => undefined,\n async failure(error, failure) {\n const filter = claimingFilter(failure.filters, error);\n if (filter) await catchWith(filter, error, failure);\n },\n};\n\n/** One invocation of a host method. */\nexport interface HostInvocation<T> {\n /** `ExecutionContext.getType()`: `'rpc'`, `'cf:workflow'`, ... */\n readonly kind: string;\n readonly method: string | symbol;\n readonly args: readonly unknown[];\n /** `ExecutionContext.getPayload()`; the arguments by default. */\n readonly payload?: unknown;\n readonly settlement: Settlement<T>;\n /** Transform each argument through the scoped pipes (RPC arguments). */\n readonly pipes?: boolean;\n /** Seed request-scoped values, such as the caller's props, into the invocation scope. */\n readonly seed?: (scope: Container) => void;\n /** How a successful result is sent, such as a streamed response body. */\n readonly transmit?: (value: T) => Transmission<T> | undefined;\n /**\n * Whether `error` is the platform steering the invocation rather than a\n * failure of it, such as the Workflows engine pausing a run: it is rethrown\n * as it is, never reported or handed to an exception filter.\n */\n readonly passthrough?: (error: unknown) => boolean;\n}\n\n/** What a {@link HostInvoker} runs its invocations against. */\nexport interface HostInvokerOptions {\n /** The application container each invocation scope is a child of. */\n readonly container: Container;\n /** The class whose method each invocation calls, resolved in the invocation scope. */\n readonly host: Type;\n /** The module the host is resolved in, and its scoped components. */\n readonly moduleId: string | undefined;\n /** The `ErrorReportContext.edge` failures are reported on. */\n readonly edge: ErrorReportContext['edge'];\n /** Keeps the platform object alive for work that outlives an invocation. */\n readonly waitUntil?: (promise: Promise<unknown>) => void;\n}\n\n/**\n * Runs invocations of one host's methods: each in a fresh execution scope\n * (request-scoped providers are built per invocation) through the host's\n * scoped guards, pipes (when asked), interceptors and exception filters.\n * Application-wide `APP_*` components do not apply: the callers are other\n * Workers and the platform, with no HTTP request. Failures are reported\n * first, then settled the way the invocation's kind requires.\n */\nexport class HostInvoker {\n readonly #container: Container;\n readonly #host: Type;\n readonly #moduleId: string | undefined;\n readonly #edge: ErrorReportContext['edge'];\n readonly #waitUntil: ((promise: Promise<unknown>) => void) | undefined;\n\n constructor(options: HostInvokerOptions) {\n this.#container = options.container;\n this.#host = options.host;\n this.#moduleId = options.moduleId;\n this.#edge = options.edge;\n this.#waitUntil = options.waitUntil;\n }\n\n /** The report context of an invocation of `method`. */\n report(kind: string, method: string | symbol): ErrorReportContext {\n return { edge: this.#edge, source: `${this.#host.name}.${String(method)}`, kind };\n }\n\n /** Report through the application, or the console when its reporter cannot be built. */\n reportOutside(error: unknown, report: ErrorReportContext): void {\n try {\n resolveErrorReporter(this.#container).report(error, report);\n } catch {\n console.error(`[vela] ${report.edge} error in ${report.source ?? 'an entrypoint'}:`, error);\n }\n }\n\n async invoke<T>(invocation: HostInvocation<T>): Promise<T> {\n const root = this.#container;\n const report = this.report(invocation.kind, invocation.method);\n const scope = createExecutionScope(root);\n let outcome: { ok: true; value: T } | { ok: false; error: unknown };\n try {\n invocation.seed?.(scope.container);\n outcome = { ok: true, value: await this.#run(scope.container, invocation, report) };\n } catch (error) {\n outcome = { ok: false, error };\n }\n let transmission: Transmission<T> | undefined;\n try {\n transmission = outcome.ok ? invocation.transmit?.(outcome.value) : undefined;\n } catch (error) {\n // Such as a body another reader locked: the scope still finishes.\n outcome = { ok: false, error };\n }\n if (transmission?.background) {\n // The scope outlives the invocation until its result is sent.\n this.#finishLater(scope, transmission.sent, report);\n return transmission.value;\n }\n try {\n // Request-scoped providers and managed work (`EXECUTION_LIFETIME`)\n // settle before the invocation does.\n await scope.finish(transmission?.sent);\n } catch (completion) {\n this.reportOutside(completion, {\n ...report,\n note: 'managed work failed after the invocation',\n });\n if (invocation.settlement.completionFails && outcome.ok) {\n outcome = { ok: false, error: completion };\n }\n }\n if (!outcome.ok) throw outcome.error;\n return transmission ? transmission.value : outcome.value;\n }\n\n /** Finish `scope` after `boundary` settles, reporting a failure; the platform waits for it. */\n #finishLater(\n scope: ExecutionScope,\n boundary: Promise<unknown>,\n report: ErrorReportContext,\n ): void {\n const completion = scope.finish(boundary).catch((error: unknown) => {\n this.reportOutside(error, { ...report, note: 'managed work failed after the response' });\n });\n this.#waitUntil?.(completion);\n }\n\n async #run<T>(\n scope: Container,\n invocation: HostInvocation<T>,\n report: ErrorReportContext,\n ): Promise<T> {\n const host = this.#host;\n const moduleId = this.#moduleId;\n const { kind, method, args, settlement } = invocation;\n const context = buildEntrypointExecutionContext(\n kind,\n host,\n method,\n 'payload' in invocation ? invocation.payload : args,\n moduleId,\n scope,\n );\n const reporter = resolveErrorReporter(scope);\n let filters: ExceptionFilter[] = [];\n try {\n filters = (\n await resolveScopedComponentsAsync('filter', host, method, scope, moduleId)\n ).toReversed();\n const guards = await resolveScopedComponentsAsync('guard', host, method, scope, moduleId);\n const interceptors = await resolveScopedComponentsAsync(\n 'interceptor',\n host,\n method,\n scope,\n moduleId,\n );\n const value = await PipelineRunner.run({\n context,\n guards,\n interceptors,\n resolveArgs: () =>\n invocation.pipes\n ? this.#transformArguments(scope, method, args)\n : Promise.resolve([...args]),\n invoke: async (resolved) => {\n const instance: unknown = await scope.resolveAsync(host, moduleId);\n if (typeof instance !== 'object' || instance === null) {\n throw new TypeError(`${host.name} did not resolve to an object.`);\n }\n const handler: unknown = Reflect.get(instance, method);\n if (typeof handler !== 'function') {\n throw new TypeError(`${host.name}.${String(method)} is not a method.`);\n }\n return Reflect.apply(handler, instance, resolved);\n },\n });\n return settlement.success(value);\n } catch (error) {\n if (invocation.passthrough?.(error) === true) throw error;\n reporter.report(error, report);\n return settlement.failure(error, { filters, context, reporter, report });\n }\n }\n\n /** Scoped pipes transform each argument, typed by the method's parameter metadata. */\n async #transformArguments(\n scope: Container,\n method: string | symbol,\n args: readonly unknown[],\n ): Promise<unknown[]> {\n const pipes = await resolveScopedComponentsAsync(\n 'pipe',\n this.#host,\n method,\n scope,\n this.#moduleId,\n );\n if (pipes.length === 0) return [...args];\n const types = getMetadata<unknown[]>('design:paramtypes', this.#host.prototype, method);\n const transformed: unknown[] = [];\n for (const [index, argument] of args.entries()) {\n const metadata = { type: 'custom', metatype: types?.[index] };\n let value = argument;\n for (const pipe of pipes) {\n value = await (pipe.transformAsync\n ? pipe.transformAsync(value, metadata)\n : pipe.transform(value, metadata));\n }\n transformed.push(value);\n }\n return transformed;\n }\n}\n\n/**\n * Call the RPC method `method` of a host through `invoker`. It rejects only\n * with an {@link EntrypointError}: a method `methods` does not list answers\n * `404 not_found`, and a failure outside the pipeline is reported and becomes\n * `500 internal`.\n */\nexport async function callRpcMethod(\n invoker: HostInvoker,\n methods: ReadonlySet<string>,\n method: string,\n args: readonly unknown[],\n seed?: (scope: Container) => void,\n): Promise<unknown> {\n if (!methods.has(method)) {\n throw new EntrypointError({ status: 404, code: 'not_found', message: 'Unknown RPC method' });\n }\n try {\n return await invoker.invoke({\n kind: 'rpc',\n method,\n args,\n settlement: rpcSettlement,\n pipes: true,\n seed,\n });\n } catch (error) {\n if (error instanceof EntrypointError) throw error;\n invoker.reportOutside(error, invoker.report('rpc', method));\n throw internalEntrypointError();\n }\n}\n\n/**\n * An invoker of a decorated method entrypoint (`@OnEmail()`, `@OnTail()`):\n * its class, resolved in the module that registered it.\n */\nexport function entrypointInvoker(\n container: Container,\n entrypoint: Entrypoint,\n edge: ErrorReportContext['edge'],\n): HostInvoker {\n const { token } = entrypoint;\n if (typeof token !== 'function') throw new TypeError('Entrypoint token must be a class.');\n return new HostInvoker({\n container,\n host: token,\n moduleId: getEntrypointModuleId(container, entrypoint),\n edge,\n });\n}\n\n/** Wait for every invocation, even when one fails before its siblings; then fail with them. */\nexport async function settleInvocations(work: readonly Promise<unknown>[]): 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 * The module a host added to the root module's providers is resolved in: the\n * root's registration when there are several.\n */\nexport function hostModuleId(\n container: Container,\n host: Type,\n rootClass: Type,\n): string | undefined {\n const owners = container.getOwnerModuleIds(host);\n return (\n owners.find((owner) => container.getModuleScope(owner)?.moduleClass === rootClass) ?? owners[0]\n );\n}\n"],"mappings":";;;;AAkDA,SAAgB,eACd,SACA,OAC6B;CAC7B,OAAO,QAAQ,MAAM,WAAW,kBAAkB,QAAQ,KAAK,CAAC;AAClE;;AAGA,eAAsB,UACpB,QACA,OACA,EAAE,SAAS,UAAU,UAC4D;CACjF,IAAI;EAEF,OAAO;GAAE,SAAS;GAAM,OAAO,MAAM,OAAO,MAAM,OAAO,OAAO;EAAE;CACpE,SAAS,aAAa;EACpB,IAAI,gBAAgB,OAClB,SAAS,OAAO,aAAa;GAAE,GAAG;GAAQ,MAAM;EAAyB,CAAC;EAE5E,OAAO;GAAE,SAAS;GAAO,OAAO;EAAY;CAC9C;AACF;;;;;;AAOA,MAAa,gBAAqC;CAChD,UAAU,UAAU;CACpB,MAAM,QAAQ,OAAO,SAAS;EAC5B,MAAM,SAAS,eAAe,QAAQ,SAAS,KAAK;EACpD,IAAI,UAAU;EACd,IAAI,QAAQ;GACV,MAAM,SAAS,MAAM,UAAU,QAAQ,OAAO,OAAO;GACrD,IAAI,OAAO,WAAW,OAAO,UAAU,KAAA,GAAW,OAAO,OAAO;GAChE,IAAI,CAAC,OAAO,SAAS,UAAU,OAAO;EACxC;EACA,MAAM,sBAAsB,SAAS,QAAQ,UAAU,QAAQ,OAAO;CACxE;AACF;;;;;AAMA,SAAgB,mBAAmB,iBAA+C;CAChF,OAAO;EACL;EACA,UAAU,UAAU;EACpB,MAAM,QAAQ,OAAO,SAAS;GAC5B,MAAM,SAAS,eAAe,QAAQ,SAAS,KAAK;GACpD,IAAI,CAAC,QAAQ,MAAM;GACnB,MAAM,SAAS,MAAM,UAAU,QAAQ,OAAO,OAAO;GACrD,IAAI,CA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