@velajs/cloudflare 1.35.0 → 1.36.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 +29 -0
- package/README.md +28 -6
- package/dist/_virtual/{_@oxc-project_runtime@0.150.0 → _@oxc-project_runtime@0.160.0}/helpers/esm/decorate.js +1 -2
- package/dist/_virtual/{_@oxc-project_runtime@0.150.0 → _@oxc-project_runtime@0.160.0}/helpers/esm/decorateMetadata.js +1 -2
- package/dist/_virtual/{_@oxc-project_runtime@0.150.0 → _@oxc-project_runtime@0.160.0}/helpers/esm/decorateParam.js +1 -2
- package/dist/bindings.js +1 -2
- package/dist/{cloudflare-application-Dsscb3Mo.d.ts → cloudflare-application-Zw9th_-h.d.ts} +2 -7
- package/dist/cloudflare-application.js +2 -3
- package/dist/cloudflare-application.js.map +1 -1
- package/dist/{cloudflare-factory-DM9CBvNH.d.ts → cloudflare-factory-Ab6XoKqO.d.ts} +5 -9
- package/dist/cloudflare-factory.js +5 -6
- package/dist/cloudflare-factory.js.map +1 -1
- package/dist/decorators/queue-consumer.js +1 -2
- package/dist/diagnostics.js +1 -2
- package/dist/durable-object/boot.js +5 -6
- package/dist/durable-object/host-dispatch.js +4 -5
- package/dist/durable-object/host-dispatch.js.map +1 -1
- package/dist/durable-object/host-methods.js +1 -2
- package/dist/durable-object/tokens.js +1 -2
- package/dist/durable-object/vela-durable-object.js +3 -4
- package/dist/durable-objects.d.ts +7 -19
- package/dist/durable-objects.js +1 -1
- package/dist/email/email-dispatch.js +1 -2
- package/dist/email/on-email.js +2 -3
- package/dist/email.d.ts +2 -6
- package/dist/email.js +1 -1
- package/dist/entrypoint/vela-entrypoint.js +4 -5
- package/dist/entrypoints.d.ts +3 -5
- package/dist/entrypoints.js +1 -2
- package/dist/environment.js +1 -2
- package/dist/host/host-invoker.js +2 -3
- package/dist/host/host-invoker.js.map +1 -1
- package/dist/host/host-members.js +1 -2
- package/dist/{host-members-DECj_4yz.d.ts → host-members-bKCWuJP2.d.ts} +0 -2
- package/dist/index.d.ts +53 -42
- package/dist/index.js +6 -5
- package/dist/nonce/durable-object-nonce.store.js +1 -2
- package/dist/nonce/nonce-validation.js +1 -2
- package/dist/nonce/nonce.durable-object.js +2 -3
- package/dist/nonce/nonce.durable-object.js.map +1 -1
- package/dist/{nonce.durable-object-Bg1e0BMD.d.ts → nonce.durable-object-Csuy3U9e.d.ts} +0 -4
- package/dist/pipelines.d.ts +1 -3
- package/dist/pipelines.js +1 -2
- package/dist/platform.js +2 -3
- package/dist/queue/cloudflare-queues.js +3 -4
- package/dist/queue-events/consume.js +1 -2
- package/dist/queue-events/consume.js.map +1 -1
- package/dist/queue-events.d.ts +1 -2
- package/dist/queue-events.js +1 -2
- package/dist/queues.d.ts +1 -3
- package/dist/queues.js +1 -2
- package/dist/rate-limit/cloudflare-rate-limit.store.js +1 -2
- package/dist/rate-limit/d1-throttler.store.js +96 -0
- package/dist/rate-limit/d1-throttler.store.js.map +1 -0
- package/dist/root-module.js +1 -2
- package/dist/rpc/entrypoint-error.js +1 -2
- package/dist/rpc/entrypoint-error.js.map +1 -1
- package/dist/schedule-diagnostics.js +2 -3
- package/dist/schedule-diagnostics.js.map +1 -1
- package/dist/scheduled-event.js +1 -2
- package/dist/services/flagship-flag.driver.js +1 -2
- package/dist/services/flagship-flag.driver.js.map +1 -1
- package/dist/services/kv-cache.store.js +1 -2
- package/dist/services/kv-cache.store.js.map +1 -1
- package/dist/services/kv-flag.driver.js +1 -2
- package/dist/services/kv-flag.driver.js.map +1 -1
- package/dist/storage/r2-storage.js +2 -3
- package/dist/storage.d.ts +1 -3
- package/dist/storage.js +1 -2
- package/dist/tail/on-tail.js +2 -3
- package/dist/tail/tail-dispatch.js +2 -3
- package/dist/tail.d.ts +2 -6
- package/dist/tail.js +1 -2
- package/dist/testing.d.ts +5 -5
- package/dist/testing.js +6 -6
- package/dist/testing.js.map +1 -1
- package/dist/tracing.d.ts +1 -3
- package/dist/tracing.js +3 -4
- package/dist/{vela-env-DFvyoNT3.d.ts → vela-env-5graXefc.d.ts} +0 -1
- package/dist/websocket/binding-gateways.js +2 -3
- package/dist/websocket/cf-room-registry.js +2 -3
- package/dist/websocket/cf-room-registry.js.map +1 -1
- package/dist/websocket/cf-ws-client.js +2 -3
- package/dist/websocket/cf-ws-client.js.map +1 -1
- package/dist/websocket/do-bootstrap.js +5 -6
- package/dist/websocket/do-live.js +4 -5
- package/dist/websocket/do-live.js.map +1 -1
- package/dist/websocket/do-pitr.js +1 -2
- package/dist/websocket/do-pitr.js.map +1 -1
- package/dist/websocket/do-state.js +1 -2
- package/dist/websocket/do-websocket-host.js +3 -4
- package/dist/websocket/do-websocket-host.js.map +1 -1
- package/dist/websocket/live-driver.js +3 -4
- package/dist/websocket/live-driver.js.map +1 -1
- package/dist/websocket/room-id.js +1 -2
- package/dist/websocket/websocket.durable-object.js +5 -6
- package/dist/websocket/websocket.durable-object.js.map +1 -1
- package/dist/websocket/worker-transport.js +3 -4
- package/dist/websocket/ws-attachment.js +1 -2
- package/dist/worker-events.js +1 -2
- package/dist/workflow/portable-workflow-step.js +1 -2
- package/dist/workflow/vela-workflow-definition.js +7 -8
- package/dist/workflow/vela-workflow-definition.js.map +1 -1
- package/dist/workflow/vela-workflow.js +2 -3
- package/dist/workflow-definitions.d.ts +2 -4
- package/dist/workflow-definitions.js +1 -2
- package/dist/workflows.d.ts +2 -4
- package/dist/workflows.js +1 -2
- package/package.json +19 -19
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"host-dispatch.js","names":[],"sources":["../../src/durable-object/host-dispatch.ts"],"sourcesContent":["import { getErrorStatus } from '@velajs/vela';\nimport type { Type, VelaApplicationContext } from '@velajs/vela';\nimport { trackResponseStream, type EntrypointExecutionContext } from '@velajs/vela/module-kit';\nimport type { CloudflareRoot } from '../root-module';\nimport {\n HostInvoker,\n callRpcMethod,\n catchWith,\n claimingFilter,\n hostModuleId,\n platformSettlement,\n type Settlement,\n type Transmission,\n} from '../host/host-invoker';\nimport { internalEntrypointError, renderEntrypointResponse } from '../rpc/entrypoint-error';\nimport {\n createDurableObjectContext,\n withDurableObjectHost,\n type DurableObjectContextOptions,\n} from './boot';\nimport type { DurableObjectHostMembers } from './host-methods';\n\n/**\n * The `ExecutionContext.getType()` of a Durable Object invocation: `rpc` for\n * a host method called over RPC, `cf:do:fetch`, `cf:do:alarm` and\n * `cf:do:websocket` for the object's event handlers. `getPayload()` is the\n * invocation's arguments.\n */\nexport type DurableObjectInvocationKind = 'rpc' | 'cf:do:fetch' | 'cf:do:alarm' | 'cf:do:websocket';\n\n/** The ExecutionContext guards, interceptors and filters receive around a Durable Object invocation. */\nexport type DurableObjectExecutionContext = EntrypointExecutionContext<DurableObjectInvocationKind>;\n\n/** A WebSocket hibernation handler a host implements. */\nexport type DurableObjectWebSocketHandler =\n | 'webSocketMessage'\n | 'webSocketClose'\n | 'webSocketError';\n\nconst fetchSettlement: Settlement<Response> = {\n success(value) {\n if (!(value instanceof Response)) {\n throw new TypeError('A Durable Object host fetch() must return a Response.');\n }\n return value;\n },\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) {\n if (caught.value instanceof Response) return caught.value;\n if (caught.value !== undefined) {\n return Response.json(caught.value, { status: getErrorStatus(error) });\n }\n } else {\n current = caught.error;\n }\n }\n return renderEntrypointResponse(current, failure.reporter, failure.context);\n },\n};\n\n// Alarms are retried by the platform: managed work that fails fails the alarm too.\nconst alarmSettlement = platformSettlement(true);\nconst webSocketSettlement = platformSettlement(false);\n\n/**\n * Runs the invocations of one Durable Object instance's host: each RPC call\n * and event in a fresh execution scope (request-scoped providers are built\n * per invocation) through the host's scoped guards, pipes (RPC arguments\n * only), interceptors and exception filters. Application-wide `APP_*`\n * components do not apply: an object's callers are other Workers and the\n * platform, with no HTTP request. Failures are reported first; an RPC call\n * rejects with an `EntrypointError`, a `fetch()` renders a JSON error\n * response, and alarms and WebSocket events rethrow for the platform.\n */\nexport class DurableObjectHostDispatcher {\n readonly context: VelaApplicationContext;\n readonly #invoker: HostInvoker;\n readonly #methods: ReadonlySet<string>;\n\n constructor(\n context: VelaApplicationContext,\n host: Type,\n moduleId: string | undefined,\n members: DurableObjectHostMembers,\n waitUntil?: (promise: Promise<unknown>) => void,\n ) {\n this.context = context;\n this.#invoker = new HostInvoker({\n container: context.getContainer(),\n host,\n moduleId,\n edge: 'durable-object',\n waitUntil,\n });\n this.#methods = new Set(members.methods);\n }\n\n /**\n * Call the host's RPC method `method`. It rejects only with an\n * `EntrypointError`, also when the invocation fails before its pipeline\n * renders the error.\n */\n call(method: string, args: readonly unknown[]): Promise<unknown> {\n return callRpcMethod(this.#invoker, this.#methods, method, args);\n }\n\n /**\n * Serve the host's `fetch()`; any failure becomes a JSON error response. A\n * streamed body keeps the invocation's scope (its request-scoped providers\n * and managed work) open until it is sent.\n */\n async fetch(request: Request): Promise<Response> {\n try {\n return await this.#invoker.invoke({\n kind: 'cf:do:fetch',\n method: 'fetch',\n args: [request],\n settlement: fetchSettlement,\n transmit: (response) => this.#transmit(request, response),\n });\n } catch (error) {\n this.#invoker.reportOutside(error, this.#invoker.report('cf:do:fetch', 'fetch'));\n const failure = internalEntrypointError();\n return Response.json(\n { error: { code: failure.code, message: failure.message } },\n { status: failure.status },\n );\n }\n }\n\n async alarm(info?: AlarmInvocationInfo): Promise<void> {\n await this.#invoker.invoke({\n kind: 'cf:do:alarm',\n method: 'alarm',\n args: info === undefined ? [] : [info],\n settlement: alarmSettlement,\n });\n }\n\n async webSocket(handler: DurableObjectWebSocketHandler, args: readonly unknown[]): Promise<void> {\n await this.#invoker.invoke({\n kind: 'cf:do:websocket',\n method: handler,\n args,\n settlement: webSocketSettlement,\n });\n }\n\n /**\n * How a `fetch()` response is sent: a streamed body keeps the scope open\n * until it was read, failed or was cancelled, and the object's `waitUntil`\n * holds that completion. A HEAD response sends no body, so its body is\n * cancelled before the scope finishes. A WebSocket upgrade (101) and a\n * bodyless response need nothing.\n */\n #transmit(request: Request, response: Response): Transmission<Response> | undefined {\n if (response.body === null || response.status === 101) return undefined;\n if (request.method === 'HEAD') {\n return {\n value: new Response(null, response),\n sent: response.body.cancel(),\n background: false,\n };\n }\n const stream = trackResponseStream(response.body);\n return { value: new Response(stream.body, response), sent: stream.done, background: true };\n }\n}\n\n/** @internal Options of {@link createDurableObjectHost}. */\nexport interface DurableObjectHostOptions extends DurableObjectContextOptions {\n /** Keeps the object alive for work that outlives an invocation, such as a streamed body. */\n readonly waitUntil?: (promise: Promise<unknown>) => void;\n}\n\n/**\n * Boot one Durable Object instance's application context from `root` with\n * `host` added to the root module's providers, and return its dispatcher,\n * which serves `members`.\n */\nexport async function createDurableObjectHost(\n root: CloudflareRoot,\n host: Type,\n options: DurableObjectHostOptions,\n members: DurableObjectHostMembers,\n): Promise<DurableObjectHostDispatcher> {\n const context = await createDurableObjectContext(withDurableObjectHost(root, host), options);\n const rootClass = typeof root === 'function' ? root : root.module;\n const moduleId = hostModuleId(context.getContainer(), host, rootClass);\n return new DurableObjectHostDispatcher(context, host, moduleId, members, options.waitUntil);\n}\n"],"mappings":";;;;;;AAuCA,MAAM,kBAAwC;CAC5C,QAAQ,OAAO;EACb,IAAI,EAAE,iBAAiB,WACrB,MAAM,IAAI,UAAU,uDAAuD;EAE7E,OAAO;CACT;CACA,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,SAAS;IAClB,IAAI,OAAO,iBAAiB,UAAU,OAAO,OAAO;IACpD,IAAI,OAAO,UAAU,KAAA,GACnB,OAAO,SAAS,KAAK,OAAO,OAAO,EAAE,QAAQ,eAAe,KAAK,EAAE,CAAC;GAExE,OACE,UAAU,OAAO;EAErB;EACA,OAAO,yBAAyB,SAAS,QAAQ,UAAU,QAAQ,OAAO;CAC5E;AACF;AAGA,MAAM,kBAAkB,mBAAmB,IAAI;AAC/C,MAAM,sBAAsB,mBAAmB,KAAK;;;;;;;;;;;AAYpD,IAAa,8BAAb,MAAyC;
|
|
1
|
+
{"version":3,"file":"host-dispatch.js","names":[],"sources":["../../src/durable-object/host-dispatch.ts"],"sourcesContent":["import { getErrorStatus } from '@velajs/vela';\nimport type { Type, VelaApplicationContext } from '@velajs/vela';\nimport { trackResponseStream, type EntrypointExecutionContext } from '@velajs/vela/module-kit';\nimport type { CloudflareRoot } from '../root-module';\nimport {\n HostInvoker,\n callRpcMethod,\n catchWith,\n claimingFilter,\n hostModuleId,\n platformSettlement,\n type Settlement,\n type Transmission,\n} from '../host/host-invoker';\nimport { internalEntrypointError, renderEntrypointResponse } from '../rpc/entrypoint-error';\nimport {\n createDurableObjectContext,\n withDurableObjectHost,\n type DurableObjectContextOptions,\n} from './boot';\nimport type { DurableObjectHostMembers } from './host-methods';\n\n/**\n * The `ExecutionContext.getType()` of a Durable Object invocation: `rpc` for\n * a host method called over RPC, `cf:do:fetch`, `cf:do:alarm` and\n * `cf:do:websocket` for the object's event handlers. `getPayload()` is the\n * invocation's arguments.\n */\nexport type DurableObjectInvocationKind = 'rpc' | 'cf:do:fetch' | 'cf:do:alarm' | 'cf:do:websocket';\n\n/** The ExecutionContext guards, interceptors and filters receive around a Durable Object invocation. */\nexport type DurableObjectExecutionContext = EntrypointExecutionContext<DurableObjectInvocationKind>;\n\n/** A WebSocket hibernation handler a host implements. */\nexport type DurableObjectWebSocketHandler =\n | 'webSocketMessage'\n | 'webSocketClose'\n | 'webSocketError';\n\nconst fetchSettlement: Settlement<Response> = {\n success(value) {\n if (!(value instanceof Response)) {\n throw new TypeError('A Durable Object host fetch() must return a Response.');\n }\n return value;\n },\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) {\n if (caught.value instanceof Response) return caught.value;\n if (caught.value !== undefined) {\n return Response.json(caught.value, { status: getErrorStatus(error) });\n }\n } else {\n current = caught.error;\n }\n }\n return renderEntrypointResponse(current, failure.reporter, failure.context);\n },\n};\n\n// Alarms are retried by the platform: managed work that fails fails the alarm too.\nconst alarmSettlement = platformSettlement(true);\nconst webSocketSettlement = platformSettlement(false);\n\n/**\n * Runs the invocations of one Durable Object instance's host: each RPC call\n * and event in a fresh execution scope (request-scoped providers are built\n * per invocation) through the host's scoped guards, pipes (RPC arguments\n * only), interceptors and exception filters. Application-wide `APP_*`\n * components do not apply: an object's callers are other Workers and the\n * platform, with no HTTP request. Failures are reported first; an RPC call\n * rejects with an `EntrypointError`, a `fetch()` renders a JSON error\n * response, and alarms and WebSocket events rethrow for the platform.\n */\nexport class DurableObjectHostDispatcher {\n readonly context: VelaApplicationContext;\n readonly #invoker: HostInvoker;\n readonly #methods: ReadonlySet<string>;\n\n constructor(\n context: VelaApplicationContext,\n host: Type,\n moduleId: string | undefined,\n members: DurableObjectHostMembers,\n waitUntil?: (promise: Promise<unknown>) => void,\n ) {\n this.context = context;\n this.#invoker = new HostInvoker({\n container: context.getContainer(),\n host,\n moduleId,\n edge: 'durable-object',\n waitUntil,\n });\n this.#methods = new Set(members.methods);\n }\n\n /**\n * Call the host's RPC method `method`. It rejects only with an\n * `EntrypointError`, also when the invocation fails before its pipeline\n * renders the error.\n */\n call(method: string, args: readonly unknown[]): Promise<unknown> {\n return callRpcMethod(this.#invoker, this.#methods, method, args);\n }\n\n /**\n * Serve the host's `fetch()`; any failure becomes a JSON error response. A\n * streamed body keeps the invocation's scope (its request-scoped providers\n * and managed work) open until it is sent.\n */\n async fetch(request: Request): Promise<Response> {\n try {\n return await this.#invoker.invoke({\n kind: 'cf:do:fetch',\n method: 'fetch',\n args: [request],\n settlement: fetchSettlement,\n transmit: (response) => this.#transmit(request, response),\n });\n } catch (error) {\n this.#invoker.reportOutside(error, this.#invoker.report('cf:do:fetch', 'fetch'));\n const failure = internalEntrypointError();\n return Response.json(\n { error: { code: failure.code, message: failure.message } },\n { status: failure.status },\n );\n }\n }\n\n async alarm(info?: AlarmInvocationInfo): Promise<void> {\n await this.#invoker.invoke({\n kind: 'cf:do:alarm',\n method: 'alarm',\n args: info === undefined ? [] : [info],\n settlement: alarmSettlement,\n });\n }\n\n async webSocket(handler: DurableObjectWebSocketHandler, args: readonly unknown[]): Promise<void> {\n await this.#invoker.invoke({\n kind: 'cf:do:websocket',\n method: handler,\n args,\n settlement: webSocketSettlement,\n });\n }\n\n /**\n * How a `fetch()` response is sent: a streamed body keeps the scope open\n * until it was read, failed or was cancelled, and the object's `waitUntil`\n * holds that completion. A HEAD response sends no body, so its body is\n * cancelled before the scope finishes. A WebSocket upgrade (101) and a\n * bodyless response need nothing.\n */\n #transmit(request: Request, response: Response): Transmission<Response> | undefined {\n if (response.body === null || response.status === 101) return undefined;\n if (request.method === 'HEAD') {\n return {\n value: new Response(null, response),\n sent: response.body.cancel(),\n background: false,\n };\n }\n const stream = trackResponseStream(response.body);\n return { value: new Response(stream.body, response), sent: stream.done, background: true };\n }\n}\n\n/** @internal Options of {@link createDurableObjectHost}. */\nexport interface DurableObjectHostOptions extends DurableObjectContextOptions {\n /** Keeps the object alive for work that outlives an invocation, such as a streamed body. */\n readonly waitUntil?: (promise: Promise<unknown>) => void;\n}\n\n/**\n * Boot one Durable Object instance's application context from `root` with\n * `host` added to the root module's providers, and return its dispatcher,\n * which serves `members`.\n */\nexport async function createDurableObjectHost(\n root: CloudflareRoot,\n host: Type,\n options: DurableObjectHostOptions,\n members: DurableObjectHostMembers,\n): Promise<DurableObjectHostDispatcher> {\n const context = await createDurableObjectContext(withDurableObjectHost(root, host), options);\n const rootClass = typeof root === 'function' ? root : root.module;\n const moduleId = hostModuleId(context.getContainer(), host, rootClass);\n return new DurableObjectHostDispatcher(context, host, moduleId, members, options.waitUntil);\n}\n"],"mappings":";;;;;;AAuCA,MAAM,kBAAwC;CAC5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GACxC,OAAO,SAAS,KACd,EAAE,OAAO;IAAE,MAAM,QAAQ;IAAM,SAAS,QAAQ;GAAQ,EAAE,GAC1D,EAAE,QAAQ,QAAQ,OAAO,CAC3B;EACF;CACF;CAEA,MAAM,MAAM,MAA2C;EACrD,MAAM,KAAK,SAAS,OAAO;GACzB,MAAM;GACN,QAAQ;GACR,MAAM,SAAS,KAAA,IAAY,CAAC,IAAI,CAAC,IAAI;GACrC,YAAY;EACd,CAAC;CACH;CAEA,MAAM,UAAU,SAAwC,MAAyC;EAC/F,MAAM,KAAK,SAAS,OAAO;GACzB,MAAM;GACN,QAAQ;GACR;GACA,YAAY;EACd,CAAC;CACH;;;;;;;;CASA,UAAU,SAAkB,UAAwD;EAClF,IAAI,SAAS,SAAS,QAAQ,SAAS,WAAW,KAAK,OAAO,KAAA;EAC9D,IAAI,QAAQ,WAAW,QACrB,OAAO;GACL,OAAO,IAAI,SAAS,MAAM,QAAQ;GAClC,MAAM,SAAS,KAAK,OAAO;GAC3B,YAAY;EACd;EAEF,MAAM,SAAS,oBAAoB,SAAS,IAAI;EAChD,OAAO;GAAE,OAAO,IAAI,SAAS,OAAO,MAAM,QAAQ;GAAG,MAAM,OAAO;GAAM,YAAY;EAAK;CAC3F;AACF;;;;;;AAaA,eAAsB,wBACpB,MACA,MACA,SACA,SACsC;CACtC,MAAM,UAAU,MAAM,2BAA2B,sBAAsB,MAAM,IAAI,GAAG,OAAO;CAC3F,MAAM,YAAY,OAAO,SAAS,aAAa,OAAO,KAAK;CAE3D,OAAO,IAAI,4BAA4B,SAAS,MAD/B,aAAa,QAAQ,aAAa,GAAG,MAAM,SACN,GAAU,SAAS,QAAQ,SAAS;AAC5F"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { hostMembers } from "../host/host-members.js";
|
|
2
|
-
|
|
2
|
+
// src/durable-object/host-methods.ts
|
|
3
3
|
/** Durable Object event handlers a host may implement; the object delegates them. */
|
|
4
4
|
const DURABLE_OBJECT_HANDLERS = [
|
|
5
5
|
"fetch",
|
|
@@ -41,7 +41,6 @@ const DURABLE_OBJECT = {
|
|
|
41
41
|
function durableObjectHostMembers(host, rpc) {
|
|
42
42
|
return hostMembers(host, rpc, DURABLE_OBJECT);
|
|
43
43
|
}
|
|
44
|
-
//#endregion
|
|
45
44
|
export { DURABLE_OBJECT_HANDLERS, durableObjectHostMembers };
|
|
46
45
|
|
|
47
46
|
//# sourceMappingURL=host-methods.js.map
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { InjectionToken } from "@velajs/vela";
|
|
2
|
-
|
|
2
|
+
// src/durable-object/tokens.ts
|
|
3
3
|
/**
|
|
4
4
|
* This Durable Object's `DurableObjectState` (`ctx` in a hand-written class),
|
|
5
5
|
* injectable in the application context the object boots: storage, id,
|
|
@@ -11,7 +11,6 @@ const DO_STATE = /* @__PURE__ */ new InjectionToken("vela.DO_STATE");
|
|
|
11
11
|
const DO_STORAGE = /* @__PURE__ */ new InjectionToken("vela.DO_STORAGE");
|
|
12
12
|
/** This Durable Object's id, `DO_STATE.id` (`id.name` when addressed by name). */
|
|
13
13
|
const DO_ID = /* @__PURE__ */ new InjectionToken("vela.DO_ID");
|
|
14
|
-
//#endregion
|
|
15
14
|
export { DO_ID, DO_STATE, DO_STORAGE };
|
|
16
15
|
|
|
17
16
|
//# sourceMappingURL=tokens.js.map
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
+
import { DurableObject } from "cloudflare:workers";
|
|
1
2
|
import { CLOUDFLARE_DURABLE_OBJECT, registerDurableObject } from "../cloudflare-factory.js";
|
|
2
|
-
import { internalEntrypointError } from "../rpc/entrypoint-error.js";
|
|
3
3
|
import { durableObjectDefinition, startDurableObject } from "./boot.js";
|
|
4
|
+
import { internalEntrypointError } from "../rpc/entrypoint-error.js";
|
|
4
5
|
import { createDurableObjectHost } from "./host-dispatch.js";
|
|
5
6
|
import { durableObjectHostMembers } from "./host-methods.js";
|
|
6
|
-
|
|
7
|
-
//#region src/durable-object/vela-durable-object.ts
|
|
7
|
+
// src/durable-object/vela-durable-object.ts
|
|
8
8
|
/** The dispatcher each instance boots, readable by the methods defined outside the class body. */
|
|
9
9
|
const dispatchers = /* @__PURE__ */ new WeakMap();
|
|
10
10
|
function dispatcherOf(instance) {
|
|
@@ -115,7 +115,6 @@ function VelaDurableObject(root, host, options = {}) {
|
|
|
115
115
|
Object.defineProperty(VelaHostDurableObject, CLOUDFLARE_DURABLE_OBJECT, { value: descriptor });
|
|
116
116
|
return VelaHostDurableObject;
|
|
117
117
|
}
|
|
118
|
-
//#endregion
|
|
119
118
|
export { VelaDurableObject };
|
|
120
119
|
|
|
121
120
|
//# sourceMappingURL=vela-durable-object.js.map
|
|
@@ -1,26 +1,21 @@
|
|
|
1
|
-
import "./vela-env-
|
|
2
|
-
import { a as CloudflareApp, y as CloudflareRoot } from "./cloudflare-factory-DM9CBvNH.js";
|
|
3
|
-
import { n as RpcMethods, t as RpcMethodOf } from "./host-members-DECj_4yz.js";
|
|
4
|
-
import { l as VelaDoPitrRpc, t as VelaNonceDurableObject } from "./nonce.durable-object-Bg1e0BMD.js";
|
|
1
|
+
import "./vela-env-5graXefc.js";
|
|
5
2
|
import { DurableObject } from "cloudflare:workers";
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
3
|
+
import { InjectionToken, Type, VelaEnv } from "@velajs/vela";
|
|
4
|
+
import { a as CloudflareApp, y as CloudflareRoot } from "./cloudflare-factory-Ab6XoKqO.js";
|
|
5
|
+
import { n as RpcMethods, t as RpcMethodOf } from "./host-members-bKCWuJP2.js";
|
|
6
|
+
import { EntrypointExecutionContext } from "@velajs/vela/module-kit";
|
|
9
7
|
import { BroadcastCommand } from "@velajs/vela/websocket";
|
|
10
|
-
|
|
8
|
+
import { CommitStamp, InvalidationCommand, LiveInspection } from "@velajs/vela/live";
|
|
9
|
+
import { l as VelaDoPitrRpc, t as VelaNonceDurableObject } from "./nonce.durable-object-Csuy3U9e.js";
|
|
11
10
|
/**
|
|
12
11
|
* What a Durable Object class is built from: a static root module (a module
|
|
13
12
|
* class or a `DynamicModule`), or an app from `defineCloudflareApp`, whose
|
|
14
13
|
* root and runtime adapters the object shares with the Worker.
|
|
15
14
|
*/
|
|
16
15
|
type DurableObjectRoot = CloudflareRoot | CloudflareApp;
|
|
17
|
-
//#endregion
|
|
18
|
-
//#region src/durable-object/host-methods.d.ts
|
|
19
16
|
/** Durable Object event handlers a host may implement; the object delegates them. */
|
|
20
17
|
declare const DURABLE_OBJECT_HANDLERS: readonly ['fetch', 'alarm', 'webSocketMessage', 'webSocketClose', 'webSocketError'];
|
|
21
18
|
type DurableObjectHandlerName = (typeof DURABLE_OBJECT_HANDLERS)[number];
|
|
22
|
-
//#endregion
|
|
23
|
-
//#region src/durable-object/vela-durable-object.d.ts
|
|
24
19
|
/**
|
|
25
20
|
* Host members that are never RPC methods, besides the lifecycle, disposal and
|
|
26
21
|
* entrypoint hooks the application context calls: the object's event
|
|
@@ -98,8 +93,6 @@ type VelaDurableObjectClass<Host, Method extends DurableObjectRpcMethod<Host> =
|
|
|
98
93
|
* RPC call rejects with an `EntrypointError` and nothing else.
|
|
99
94
|
*/
|
|
100
95
|
export declare function VelaDurableObject<Host extends object, const Method extends DurableObjectRpcMethod<Host> = never>(root: DurableObjectRoot, host: Type<Host>, options?: VelaDurableObjectOptions<Method>): VelaDurableObjectClass<Host, Method>;
|
|
101
|
-
//#endregion
|
|
102
|
-
//#region src/durable-object/host-dispatch.d.ts
|
|
103
96
|
/**
|
|
104
97
|
* The `ExecutionContext.getType()` of a Durable Object invocation: `rpc` for
|
|
105
98
|
* a host method called over RPC, `cf:do:fetch`, `cf:do:alarm` and
|
|
@@ -109,8 +102,6 @@ export declare function VelaDurableObject<Host extends object, const Method exte
|
|
|
109
102
|
type DurableObjectInvocationKind = 'rpc' | 'cf:do:fetch' | 'cf:do:alarm' | 'cf:do:websocket';
|
|
110
103
|
/** The ExecutionContext guards, interceptors and filters receive around a Durable Object invocation. */
|
|
111
104
|
type DurableObjectExecutionContext = EntrypointExecutionContext<DurableObjectInvocationKind>;
|
|
112
|
-
//#endregion
|
|
113
|
-
//#region src/durable-object/tokens.d.ts
|
|
114
105
|
/**
|
|
115
106
|
* This Durable Object's `DurableObjectState` (`ctx` in a hand-written class),
|
|
116
107
|
* injectable in the application context the object boots: storage, id,
|
|
@@ -122,8 +113,6 @@ export declare const DO_STATE: InjectionToken<DurableObjectState<unknown>>;
|
|
|
122
113
|
export declare const DO_STORAGE: InjectionToken<DurableObjectStorage>;
|
|
123
114
|
/** This Durable Object's id, `DO_STATE.id` (`id.name` when addressed by name). */
|
|
124
115
|
export declare const DO_ID: InjectionToken<DurableObjectId>;
|
|
125
|
-
//#endregion
|
|
126
|
-
//#region src/websocket/websocket.durable-object.d.ts
|
|
127
116
|
/**
|
|
128
117
|
* Base class for the WebSocket Durable Object. The user exports a named subclass
|
|
129
118
|
* (matching their `wrangler.toml` `class_name`) built from their `AppModule`, a
|
|
@@ -150,5 +139,4 @@ export declare function VelaWebSocketDurableObject(root: DurableObjectRoot): new
|
|
|
150
139
|
invalidate(cmd: InvalidationCommand): Promise<CommitStamp | undefined>;
|
|
151
140
|
inspectLive(): Promise<LiveInspection>;
|
|
152
141
|
};
|
|
153
|
-
//#endregion
|
|
154
142
|
export { type DurableObjectExecutionContext, type DurableObjectInvocationKind, type DurableObjectRoot, type DurableObjectRpc, type DurableObjectRpcMethod, type VelaDurableObjectClass, type VelaDurableObjectOptions, VelaNonceDurableObject };
|
package/dist/durable-objects.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { DO_ID, DO_STATE, DO_STORAGE } from "./durable-object/tokens.js";
|
|
2
1
|
import { VelaDurableObject } from "./durable-object/vela-durable-object.js";
|
|
2
|
+
import { DO_ID, DO_STATE, DO_STORAGE } from "./durable-object/tokens.js";
|
|
3
3
|
import { VelaWebSocketDurableObject } from "./websocket/websocket.durable-object.js";
|
|
4
4
|
import { VelaNonceDurableObject } from "./nonce/nonce.durable-object.js";
|
|
5
5
|
export { DO_ID, DO_STATE, DO_STORAGE, VelaDurableObject, VelaNonceDurableObject, VelaWebSocketDurableObject };
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { entrypointInvoker, platformSettlement, settleInvocations } from "../host/host-invoker.js";
|
|
2
|
-
|
|
2
|
+
// src/email/email-dispatch.ts
|
|
3
3
|
/** The metadata key `@OnEmail()` records its handlers under (entrypoint kind `cf:email`). */
|
|
4
4
|
const EMAIL_METADATA = "cloudflare:email";
|
|
5
5
|
/**
|
|
@@ -59,7 +59,6 @@ async function dispatchEmail(application, message) {
|
|
|
59
59
|
settlement: emailSettlement
|
|
60
60
|
})));
|
|
61
61
|
}
|
|
62
|
-
//#endregion
|
|
63
62
|
export { EMAIL_METADATA, UNCLAIMED_EMAIL_REASON, dispatchEmail, parseOnEmailMetadata };
|
|
64
63
|
|
|
65
64
|
//# sourceMappingURL=email-dispatch.js.map
|
package/dist/email/on-email.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
+
import { MetadataRegistry, registerEntrypointKind } from "@velajs/vela/module-kit";
|
|
1
2
|
import { registerWorkerEvent } from "../worker-events.js";
|
|
2
3
|
import { EMAIL_METADATA, dispatchEmail } from "./email-dispatch.js";
|
|
3
|
-
|
|
4
|
-
//#region src/email/on-email.ts
|
|
4
|
+
// src/email/on-email.ts
|
|
5
5
|
registerEntrypointKind({
|
|
6
6
|
kind: "cf:email",
|
|
7
7
|
metaKey: EMAIL_METADATA,
|
|
@@ -51,7 +51,6 @@ function OnEmail(options = {}) {
|
|
|
51
51
|
});
|
|
52
52
|
};
|
|
53
53
|
}
|
|
54
|
-
//#endregion
|
|
55
54
|
export { OnEmail };
|
|
56
55
|
|
|
57
56
|
//# sourceMappingURL=on-email.js.map
|
package/dist/email.d.ts
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
|
-
import "./vela-env-
|
|
2
|
-
import "./cloudflare-application-Dsscb3Mo.js";
|
|
1
|
+
import "./vela-env-5graXefc.js";
|
|
3
2
|
import { EntrypointExecutionContext } from "@velajs/vela/module-kit";
|
|
4
|
-
|
|
3
|
+
import "./cloudflare-application-Zw9th_-h.js";
|
|
5
4
|
/** Options of {@link OnEmail}. */
|
|
6
5
|
interface OnEmailOptions {
|
|
7
6
|
/**
|
|
@@ -38,8 +37,6 @@ type OnEmailDecorator = <Handler extends (message: ForwardableEmailMessage) => u
|
|
|
38
37
|
* handles it.
|
|
39
38
|
*/
|
|
40
39
|
export declare function OnEmail(options?: OnEmailOptions): OnEmailDecorator;
|
|
41
|
-
//#endregion
|
|
42
|
-
//#region src/email/email-dispatch.d.ts
|
|
43
40
|
/** The ExecutionContext guards, interceptors and filters receive around an `@OnEmail()` handler. */
|
|
44
41
|
type EmailExecutionContext = EntrypointExecutionContext<'cf:email'>;
|
|
45
42
|
/**
|
|
@@ -47,5 +44,4 @@ type EmailExecutionContext = EntrypointExecutionContext<'cf:email'>;
|
|
|
47
44
|
* error the sending server reports to its sender.
|
|
48
45
|
*/
|
|
49
46
|
export declare const UNCLAIMED_EMAIL_REASON = "No handler accepts mail for this address.";
|
|
50
|
-
//#endregion
|
|
51
47
|
export type { EmailExecutionContext, OnEmailDecorator, OnEmailOptions };
|
package/dist/email.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
+
import { WorkerEntrypoint } from "cloudflare:workers";
|
|
2
|
+
import { InjectionToken, Scope } from "@velajs/vela";
|
|
1
3
|
import { CLOUDFLARE_ENTRYPOINT, cloudflareApplication, isCloudflareApp, registerEntrypoint } from "../cloudflare-factory.js";
|
|
2
|
-
import { internalEntrypointError } from "../rpc/entrypoint-error.js";
|
|
3
4
|
import { HostInvoker, callRpcMethod, hostModuleId } from "../host/host-invoker.js";
|
|
4
5
|
import { hostMembers } from "../host/host-members.js";
|
|
5
|
-
import {
|
|
6
|
-
|
|
7
|
-
//#region src/entrypoint/vela-entrypoint.ts
|
|
6
|
+
import { internalEntrypointError } from "../rpc/entrypoint-error.js";
|
|
7
|
+
// src/entrypoint/vela-entrypoint.ts
|
|
8
8
|
/**
|
|
9
9
|
* The `props` of the current service entrypoint call (`ctx.props` in a
|
|
10
10
|
* hand-written `WorkerEntrypoint`): what the caller's service binding
|
|
@@ -154,7 +154,6 @@ function VelaEntrypoint(app, host, options = {}) {
|
|
|
154
154
|
Object.defineProperty(VelaHostEntrypoint, CLOUDFLARE_ENTRYPOINT, { value: descriptor });
|
|
155
155
|
return VelaHostEntrypoint;
|
|
156
156
|
}
|
|
157
|
-
//#endregion
|
|
158
157
|
export { ENTRYPOINT_PROPS, VelaEntrypoint, entrypointHostMembers };
|
|
159
158
|
|
|
160
159
|
//# sourceMappingURL=vela-entrypoint.js.map
|
package/dist/entrypoints.d.ts
CHANGED
|
@@ -1,10 +1,9 @@
|
|
|
1
|
-
import "./vela-env-
|
|
2
|
-
import { a as CloudflareApp } from "./cloudflare-factory-DM9CBvNH.js";
|
|
3
|
-
import { n as RpcMethods, t as RpcMethodOf } from "./host-members-DECj_4yz.js";
|
|
1
|
+
import "./vela-env-5graXefc.js";
|
|
4
2
|
import { WorkerEntrypoint } from "cloudflare:workers";
|
|
5
3
|
import { InjectionToken, Type, VelaEnv } from "@velajs/vela";
|
|
6
4
|
import { EntrypointExecutionContext } from "@velajs/vela/module-kit";
|
|
7
|
-
|
|
5
|
+
import { a as CloudflareApp } from "./cloudflare-factory-Ab6XoKqO.js";
|
|
6
|
+
import { n as RpcMethods, t as RpcMethodOf } from "./host-members-bKCWuJP2.js";
|
|
8
7
|
/**
|
|
9
8
|
* The `props` of the current service entrypoint call (`ctx.props` in a
|
|
10
9
|
* hand-written `WorkerEntrypoint`): what the caller's service binding
|
|
@@ -89,5 +88,4 @@ type EntrypointRpcExecutionContext = EntrypointExecutionContext<'rpc'>;
|
|
|
89
88
|
* redacted.
|
|
90
89
|
*/
|
|
91
90
|
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
91
|
export type { EntrypointRpc, EntrypointRpcExecutionContext, EntrypointRpcMethod, VelaEntrypointClass, VelaEntrypointOptions };
|
package/dist/entrypoints.js
CHANGED
|
@@ -1,2 +1 @@
|
|
|
1
|
-
|
|
2
|
-
export { ENTRYPOINT_PROPS, VelaEntrypoint };
|
|
1
|
+
export { ENTRYPOINT_PROPS, VelaEntrypoint } from "./entrypoint/vela-entrypoint.js";
|
package/dist/environment.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { ENV, defineProvider } from "@velajs/vela";
|
|
2
|
-
|
|
2
|
+
// src/environment.ts
|
|
3
3
|
/**
|
|
4
4
|
* Seed the application's native environment as the global ENV before provider
|
|
5
5
|
* factories or lifecycle hooks run. No platform I/O is performed here; callers
|
|
@@ -13,7 +13,6 @@ function registerCloudflareEnvironment(container, env) {
|
|
|
13
13
|
function assertCloudflareEnvironment(expected, actual) {
|
|
14
14
|
if (actual !== expected) throw new Error("This Cloudflare application belongs to a different environment. Create an application with the current event environment.");
|
|
15
15
|
}
|
|
16
|
-
//#endregion
|
|
17
16
|
export { assertCloudflareEnvironment, registerCloudflareEnvironment };
|
|
18
17
|
|
|
19
18
|
//# sourceMappingURL=environment.js.map
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { EntrypointError, internalEntrypointError, renderEntrypointError } from "../rpc/entrypoint-error.js";
|
|
2
1
|
import { PipelineRunner, buildEntrypointExecutionContext, createExecutionScope, getEntrypointModuleId, getMetadata, resolveErrorReporter, resolveScopedComponentsAsync, shouldFilterCatch } from "@velajs/vela/module-kit";
|
|
3
|
-
|
|
2
|
+
import { EntrypointError, internalEntrypointError, renderEntrypointError } from "../rpc/entrypoint-error.js";
|
|
3
|
+
// src/host/host-invoker.ts
|
|
4
4
|
/** The first scoped filter (closest first) that catches `error`. */
|
|
5
5
|
function claimingFilter(filters, error) {
|
|
6
6
|
return filters.find((filter) => shouldFilterCatch(filter, error));
|
|
@@ -270,7 +270,6 @@ function hostModuleId(container, host, rootClass) {
|
|
|
270
270
|
const owners = container.getOwnerModuleIds(host);
|
|
271
271
|
return owners.find((owner) => container.getModuleScope(owner)?.moduleClass === rootClass) ?? owners[0];
|
|
272
272
|
}
|
|
273
|
-
//#endregion
|
|
274
273
|
export { HostInvoker, callRpcMethod, catchWith, claimingFilter, entrypointInvoker, hostModuleId, observedSettlement, platformSettlement, rpcSettlement, settleInvocations };
|
|
275
274
|
|
|
276
275
|
//# sourceMappingURL=host-invoker.js.map
|
|
@@ -1 +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":";;;;AAk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,cAAc,OAAO,QAAQ,OAAO,OAAO,MAAM,CAAC;EAC1D,MAAM,wBAAwB;CAChC;AACF;;;;;AAMA,SAAgB,kBACd,WACA,YACA,MACa;CACb,MAAM,EAAE,UAAU;CAClB,IAAI,OAAO,UAAU,YAAY,MAAM,IAAI,UAAU,mCAAmC;CACxF,OAAO,IAAI,YAAY;EACrB;EACA,MAAM;EACN,UAAU,sBAAsB,WAAW,UAAU;EACrD;CACF,CAAC;AACH;;AAGA,eAAsB,kBAAkB,MAAkD;CAExF,MAAM,UAAS,MADQ,QAAQ,WAAW,IAAI,EAAA,CACtB,SAAS,YAC/B,QAAQ,WAAW,aAAa,CAAC,QAAQ,MAAM,IAAI,CAAC,CACtD;CACA,IAAI,OAAO,WAAW,GAAG,MAAM,OAAO;CACtC,IAAI,OAAO,SAAS,GAAG,MAAM,IAAI,eAAe,QAAQ,sCAAsC;AAChG;;;;;AAMA,SAAgB,aACd,WACA,MACA,WACoB;CACpB,MAAM,SAAS,UAAU,kBAAkB,IAAI;CAC/C,OACE,OAAO,MAAM,UAAU,UAAU,eAAe,KAAK,CAAC,EAAE,gBAAgB,SAAS,KAAK,OAAO;AAEjG"}
|
|
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;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AAsB,cACpB,SACA,SACA,QACA,MACA,MACkB;CAClB,IAAI,CAAC,QAAQ,IAAI,MAAM,GACrB,MAAM,IAAI,gBAAgB;EAAE,QAAQ;EAAK,MAAM;EAAa,SAAS;CAAqB,CAAC;CAE7F,IAAI;EACF,OAAO,MAAM,QAAQ,OAAO;GAC1B,MAAM;GACN;GACA;GACA,YAAY;GACZ,OAAO;GACP;EACF,CAAC;CACH,SAAS,OAAO;EACd,IAAI,iBAAiB,iBAAiB,MAAM;EAC5C,QAAQ,cAAc,OAAO,QAAQ,OAAO,OAAO,MAAM,CAAC;EAC1D,MAAM,wBAAwB;CAChC;AACF;;;;;AAMA,SAAgB,kBACd,WACA,YACA,MACa;CACb,MAAM,EAAE,UAAU;CAClB,IAAI,OAAO,UAAU,YAAY,MAAM,IAAI,UAAU,mCAAmC;CACxF,OAAO,IAAI,YAAY;EACrB;EACA,MAAM;EACN,UAAU,sBAAsB,WAAW,UAAU;EACrD;CACF,CAAC;AACH;;AAGA,eAAsB,kBAAkB,MAAkD;CAExF,MAAM,UAAS,MADQ,QAAQ,WAAW,IAAI,EAAA,CACtB,SAAS,YAC/B,QAAQ,WAAW,aAAa,CAAC,QAAQ,MAAM,IAAI,CAAC,CACtD;CACA,IAAI,OAAO,WAAW,GAAG,MAAM,OAAO;CACtC,IAAI,OAAO,SAAS,GAAG,MAAM,IAAI,eAAe,QAAQ,sCAAsC;AAChG;;;;;AAMA,SAAgB,aACd,WACA,MACA,WACoB;CACpB,MAAM,SAAS,UAAU,kBAAkB,IAAI;CAC/C,OACE,OAAO,MAAM,UAAU,UAAU,eAAe,KAAK,CAAC,EAAE,gBAAgB,SAAS,KAAK,OAAO;AAEjG"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
|
|
1
|
+
// src/host/host-members.ts
|
|
2
2
|
/**
|
|
3
3
|
* Methods the application context calls on providers: lifecycle hooks, the
|
|
4
4
|
* container's `dispose()` disposal hook and the entrypoint contributor hook.
|
|
@@ -67,7 +67,6 @@ function hostMembers(host, rpc, surface) {
|
|
|
67
67
|
handlers: surface.handlers.filter((name) => hasPrototypeMethod(host, name))
|
|
68
68
|
};
|
|
69
69
|
}
|
|
70
|
-
//#endregion
|
|
71
70
|
export { assertNotThenable, hasPrototypeMethod, hostMembers, prototypeMember };
|
|
72
71
|
|
|
73
72
|
//# sourceMappingURL=host-members.js.map
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
//#region src/host/host-members.d.ts
|
|
2
1
|
/** Host members the application context calls, which are never RPC methods. */
|
|
3
2
|
type HostHookName = 'onModuleInit' | 'onApplicationBootstrap' | 'onModuleDestroy' | 'beforeApplicationShutdown' | 'onApplicationShutdown' | 'dispose' | 'collectEntrypoints';
|
|
4
3
|
/**
|
|
@@ -9,5 +8,4 @@ type HostHookName = 'onModuleInit' | 'onApplicationBootstrap' | 'onModuleDestroy
|
|
|
9
8
|
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
9
|
/** The RPC methods `Method` of `Host`, asynchronous, as the entrypoint's stubs call them. */
|
|
11
10
|
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
11
|
export { RpcMethods as n, RpcMethodOf as t };
|