@rexezuge/runtime 1.15.0 → 1.17.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/README.md +2 -2
- package/dist/base/AbstractDurableObjectWorker.js +1 -1
- package/dist/base/AbstractDurableObjectWorker.js.map +3 -3
- package/dist/base/AbstractEntrypointWorker.d.ts +4 -5
- package/dist/base/AbstractEntrypointWorker.d.ts.map +1 -1
- package/dist/base/AbstractEntrypointWorker.js +1 -1
- package/dist/base/AbstractEntrypointWorker.js.map +3 -3
- package/dist/base/AbstractQueueWorker.js +1 -1
- package/dist/base/AbstractQueueWorker.js.map +3 -3
- package/dist/base/AbstractWorkflowWorker.js +1 -1
- package/dist/base/AbstractWorkflowWorker.js.map +3 -3
- package/dist/base/baseWorkerError.d.ts +9 -1
- package/dist/base/baseWorkerError.d.ts.map +1 -1
- package/dist/base/baseWorkerError.js +1 -1
- package/dist/base/baseWorkerError.js.map +3 -3
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -68,12 +68,12 @@ class DispatcherWorker extends AbstractQueueWorker<MessageBatch<EmailQueueMessag
|
|
|
68
68
|
}
|
|
69
69
|
```
|
|
70
70
|
|
|
71
|
-
**
|
|
71
|
+
**The error log is redacted by default.** Every base's catch reports through a `reportUnhandled(message, error)` hook. The default logs the static message (a literal from `BASE_WORKER_MESSAGES`) plus `{ errorName, errorCode? }`: the class name and, when the value carries a short `type` or `code`, that identifier. It never logs the message, the stack or the value, because a D1 message names tables and an upstream error can carry a token. An app that ships to a log sink it controls overrides the hook and receives the raw value there, owning what reaches the sink:
|
|
72
72
|
|
|
73
73
|
```ts
|
|
74
74
|
class TokenRefresher extends AbstractDurableObjectWorker<Env> {
|
|
75
75
|
protected override reportUnhandled(message: string, error: unknown): void {
|
|
76
|
-
|
|
76
|
+
controlledSink.error(message, error); // the open side: you decided what this sink may hold
|
|
77
77
|
}
|
|
78
78
|
}
|
|
79
79
|
```
|
|
@@ -1 +1 @@
|
|
|
1
|
-
var
|
|
1
|
+
var a=Object.defineProperty;var e=(n,t)=>a(n,"name",{value:t,configurable:!0});import{DurableObject as o}from"cloudflare:workers";import{BASE_WORKER_MESSAGES as s,reportRedacted as c}from"./baseWorkerError.js";class i extends o{static{e(this,"AbstractDurableObjectWorker")}async fetch(t){try{return await this.onRequest(t)}catch(r){return this.reportUnhandled(s.durableObjectFetch,r),Response.json({error:"Internal Error"},{status:500})}}reportUnhandled(t,r){c(t,r)}createExecutionContext(){return{waitUntil:e(t=>this.ctx.waitUntil(t),"waitUntil"),passThroughOnException:e(()=>{},"passThroughOnException")}}}export{i as AbstractDurableObjectWorker};
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/base/AbstractDurableObjectWorker.ts"],
|
|
4
|
-
"sourcesContent": ["import { DurableObject } from 'cloudflare:workers';\nimport { BASE_WORKER_MESSAGES } from './baseWorkerError.ts';\n\n/**\n * The Durable Object base: one `fetch` entry, error containment inside it.\n *\n * Converged from the `AbstractDurableObjectWorker` copies in AWS-AccessBridge,\n * CalDAV-Bridge, ChordDHT-Tracker, Edge-Git, Mail-Meow and Mail-Otter (the\n * union is exactly Mail-Meow's shape: the fetch wrapper plus\n * `createExecutionContext` for handlers that need to forward `waitUntil`).\n * Durable-DAV's DO writes more context per handler, but the *base* is the same.\n *\n * A DO has no routing layer, so an unhandled rejection here would surface as a\n * raw 500 with no JSON body and no log. The catch is the boundary: it logs the\n * sanitized error and answers `{ error: 'Internal Error' }` so a caller always\n * gets a parseable response.\n */\nabstract class AbstractDurableObjectWorker<TEnv = Env> extends DurableObject<TEnv> {\n /**\n * @final Owns the error containment; extend through {@link onRequest}. Not\n * refused at runtime in 1.x (that would break consumers), but outside the\n * contract — see `docs/design-charter.md`.\n */\n public async fetch(request: Request): Promise<Response> {\n try {\n return await this.onRequest(request);\n } catch (err: unknown) {\n this.reportUnhandled(BASE_WORKER_MESSAGES.durableObjectFetch, err);\n return Response.json({ error: 'Internal Error' }, { status: 500 });\n }\n }\n\n /**\n * The sink for an unhandled rejection at this base's boundary. See\n * `AbstractEntrypointWorker.reportUnhandled` — the base owns the static\n * message, the consumer owns whether the caught value may be logged as-is.\n */\n protected reportUnhandled(message: string, error: unknown): void {\n
|
|
5
|
-
"mappings": "+EAAA,OAAS,iBAAAA,MAAqB,qBAC9B,OAAS,wBAAAC,
|
|
6
|
-
"names": ["DurableObject", "BASE_WORKER_MESSAGES", "AbstractDurableObjectWorker", "__name", "request", "err", "message", "error", "promise"]
|
|
4
|
+
"sourcesContent": ["import { DurableObject } from 'cloudflare:workers';\nimport { BASE_WORKER_MESSAGES, reportRedacted } from './baseWorkerError.ts';\n\n/**\n * The Durable Object base: one `fetch` entry, error containment inside it.\n *\n * Converged from the `AbstractDurableObjectWorker` copies in AWS-AccessBridge,\n * CalDAV-Bridge, ChordDHT-Tracker, Edge-Git, Mail-Meow and Mail-Otter (the\n * union is exactly Mail-Meow's shape: the fetch wrapper plus\n * `createExecutionContext` for handlers that need to forward `waitUntil`).\n * Durable-DAV's DO writes more context per handler, but the *base* is the same.\n *\n * A DO has no routing layer, so an unhandled rejection here would surface as a\n * raw 500 with no JSON body and no log. The catch is the boundary: it logs the\n * sanitized error and answers `{ error: 'Internal Error' }` so a caller always\n * gets a parseable response.\n */\nabstract class AbstractDurableObjectWorker<TEnv = Env> extends DurableObject<TEnv> {\n /**\n * @final Owns the error containment; extend through {@link onRequest}. Not\n * refused at runtime in 1.x (that would break consumers), but outside the\n * contract — see `docs/design-charter.md`.\n */\n public async fetch(request: Request): Promise<Response> {\n try {\n return await this.onRequest(request);\n } catch (err: unknown) {\n this.reportUnhandled(BASE_WORKER_MESSAGES.durableObjectFetch, err);\n return Response.json({ error: 'Internal Error' }, { status: 500 });\n }\n }\n\n /**\n * The sink for an unhandled rejection at this base's boundary. See\n * `AbstractEntrypointWorker.reportUnhandled` — the base owns the static\n * message, the consumer owns whether the caught value may be logged as-is.\n */\n protected reportUnhandled(message: string, error: unknown): void {\n reportRedacted(message, error);\n }\n\n /**\n * The platform `ExecutionContext` shape, forwards `waitUntil` into the DO's\n * own `ctx` so a handler can keep a task alive past the response.\n */\n protected createExecutionContext(): ExecutionContext {\n return {\n waitUntil: (promise: Promise<unknown>): void => this.ctx.waitUntil(promise),\n passThroughOnException: (): void => undefined,\n };\n }\n\n protected abstract onRequest(request: Request): Promise<Response>;\n}\n\nexport { AbstractDurableObjectWorker };\n"],
|
|
5
|
+
"mappings": "+EAAA,OAAS,iBAAAA,MAAqB,qBAC9B,OAAS,wBAAAC,EAAsB,kBAAAC,MAAsB,uBAgBrD,MAAeC,UAAgDH,CAAmB,CAjBlF,MAiBkF,CAAAI,EAAA,oCAMzE,MAAM,MAAMC,EAAgB,CACjC,GAAI,CACF,OAAO,MAAM,KAAK,UAAUA,CAAO,CACrC,OAASC,EAAc,CACrB,YAAK,gBAAgBL,EAAqB,mBAAoBK,CAAG,EAC1D,SAAS,KAAK,CAAE,MAAO,gBAAgB,EAAI,CAAE,OAAQ,GAAG,CAAE,CACnE,CACF,CAOU,gBAAgBC,EAAiBC,EAAc,CACvDN,EAAeK,EAASC,CAAK,CAC/B,CAMU,wBAAsB,CAC9B,MAAO,CACL,UAAWJ,EAACK,GAAoC,KAAK,IAAI,UAAUA,CAAO,EAA/D,aACX,uBAAwBL,EAAA,IAAS,GAAT,0BAE5B",
|
|
6
|
+
"names": ["DurableObject", "BASE_WORKER_MESSAGES", "reportRedacted", "AbstractDurableObjectWorker", "__name", "request", "err", "message", "error", "promise"]
|
|
7
7
|
}
|
|
@@ -46,11 +46,10 @@ declare abstract class AbstractEntrypointWorker {
|
|
|
46
46
|
/**
|
|
47
47
|
* The sink for an unhandled rejection at this base's boundaries.
|
|
48
48
|
*
|
|
49
|
-
*
|
|
50
|
-
*
|
|
51
|
-
*
|
|
52
|
-
*
|
|
53
|
-
* the redaction decision stays in the consumer where the threat model lives.
|
|
49
|
+
* Redacted by default (charter: static message, never a caught value): the default logs the
|
|
50
|
+
* static message plus `errorName` and, when the value carries a short `type` or `code`, `errorCode`,
|
|
51
|
+
* and never the message or stack, which can carry a token. This is the open side: an app that ships
|
|
52
|
+
* to a log sink it controls overrides this to receive the raw `error`, and owns what reaches it.
|
|
54
53
|
*/
|
|
55
54
|
protected reportUnhandled(message: string, error: unknown): void;
|
|
56
55
|
protected abstract onRequest(request: Request, env: Env, ctx: WorkerExecutionContext): Promise<Response>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"AbstractEntrypointWorker.d.ts","sourceRoot":"","sources":["../../src/base/AbstractEntrypointWorker.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,0BAA0B,EAAE,MAAM,wCAAwC,CAAC;AAGzF;;;;;;;GAOG;AACH,UAAU,sBAAsB;IAC9B,SAAS,CAAC,OAAO,EAAE,OAAO,CAAC,OAAO,CAAC,GAAG,IAAI,CAAC;IAC3C,sBAAsB,IAAI,IAAI,CAAC;CAChC;AAED,UAAU,yBAAyB;IACjC,IAAI,EAAE,MAAM,CAAC;IACb,aAAa,EAAE,MAAM,CAAC;IACtB,OAAO,IAAI,IAAI,CAAC;CACjB;AAED,uBAAe,wBAAwB;IACrC;;;;;;;;;;;;;;;;;OAiBG;IACU,KAAK,CAAC,OAAO,EAAE,OAAO,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,sBAAsB,GAAG,OAAO,CAAC,QAAQ,CAAC;IAS9F;;;;;OAKG;IACU,SAAS,CAAC,KAAK,EAAE,yBAAyB,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,sBAAsB,GAAG,OAAO,CAAC,IAAI,CAAC;IAQ9G
|
|
1
|
+
{"version":3,"file":"AbstractEntrypointWorker.d.ts","sourceRoot":"","sources":["../../src/base/AbstractEntrypointWorker.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,0BAA0B,EAAE,MAAM,wCAAwC,CAAC;AAGzF;;;;;;;GAOG;AACH,UAAU,sBAAsB;IAC9B,SAAS,CAAC,OAAO,EAAE,OAAO,CAAC,OAAO,CAAC,GAAG,IAAI,CAAC;IAC3C,sBAAsB,IAAI,IAAI,CAAC;CAChC;AAED,UAAU,yBAAyB;IACjC,IAAI,EAAE,MAAM,CAAC;IACb,aAAa,EAAE,MAAM,CAAC;IACtB,OAAO,IAAI,IAAI,CAAC;CACjB;AAED,uBAAe,wBAAwB;IACrC;;;;;;;;;;;;;;;;;OAiBG;IACU,KAAK,CAAC,OAAO,EAAE,OAAO,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,sBAAsB,GAAG,OAAO,CAAC,QAAQ,CAAC;IAS9F;;;;;OAKG;IACU,SAAS,CAAC,KAAK,EAAE,yBAAyB,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,sBAAsB,GAAG,OAAO,CAAC,IAAI,CAAC;IAQ9G;;;;;;;OAOG;IACH,SAAS,CAAC,eAAe,CAAC,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,OAAO,GAAG,IAAI;IAIhE,SAAS,CAAC,QAAQ,CAAC,SAAS,CAAC,OAAO,EAAE,OAAO,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,sBAAsB,GAAG,OAAO,CAAC,QAAQ,CAAC;IAExG;;;;;;;;OAQG;IACH,SAAS,CAAC,WAAW,CAAC,KAAK,EAAE,yBAAyB,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,sBAAsB,GAAG,OAAO,CAAC,IAAI,CAAC;IAQ7G;;;OAGG;IACH,SAAS,CAAC,kBAAkB,CAAC,IAAI,EAAE,GAAG,GAAG,0BAA0B,GAAG,IAAI;CAG3E;AAED,OAAO,EAAE,wBAAwB,EAAE,CAAC;AACpC,YAAY,EAAE,sBAAsB,EAAE,yBAAyB,EAAE,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
var
|
|
1
|
+
var o=Object.defineProperty;var a=(s,e)=>o(s,"name",{value:e,configurable:!0});import{dispatchCronToDurableObject as d}from"../cron/dispatchCronToDurableObject.js";import{BASE_WORKER_MESSAGES as c,reportRedacted as h}from"./baseWorkerError.js";class l{static{a(this,"AbstractEntrypointWorker")}async fetch(e,r,n){try{return await this.onRequest(e,r,n)}catch(t){return this.reportUnhandled(c.fetch,t),new Response("Internal Error",{status:500})}}async scheduled(e,r,n){try{await this.onScheduled(e,r,n)}catch(t){this.reportUnhandled(c.scheduled,t)}}reportUnhandled(e,r){h(e,r)}onScheduled(e,r,n){const t=this.cronTasksNamespace(r);return t!==null&&n.waitUntil(d(t,{cron:e.cron,scheduledTime:e.scheduledTime})),Promise.resolve()}cronTasksNamespace(e){return null}}export{l as AbstractEntrypointWorker};
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/base/AbstractEntrypointWorker.ts"],
|
|
4
|
-
"sourcesContent": ["import { dispatchCronToDurableObject } from '../cron/dispatchCronToDurableObject.ts';\nimport type { DurableObjectNamespaceLike } from '../cron/dispatchCronToDurableObject.ts';\nimport { BASE_WORKER_MESSAGES } from './baseWorkerError.ts';\n\n/**\n * Minimal Workers-compatible context types so backend-runtime typechecks\n * without @cloudflare/workers-types. Apps pass the real ExecutionContext /\n * ScheduledController which satisfy these structurally.\n *\n * Converged verbatim from `backend-runtime/src/base/AbstractEntrypointWorker.ts`\n * (identical in all nine repos).\n */\ninterface WorkerExecutionContext {\n waitUntil(promise: Promise<unknown>): void;\n passThroughOnException(): void;\n}\n\ninterface WorkerScheduledController {\n cron: string;\n scheduledTime: number;\n noRetry(): void;\n}\n\nabstract class AbstractEntrypointWorker {\n /**\n * The HTTP request path.\n *\n * There is deliberately no `/__scheduled` branch here. It used to run before\n * `onRequest`, which made `GET /__scheduled` an unauthenticated, un-rated\n * trigger for the scheduled work: it bypassed the app's security headers, its\n * request scope, and its rate limits, and any caller could fire the cron\n * Durable Object on demand. `noRetry` was a `(): void => undefined` stub, so\n * the retry semantics were lost too.\n *\n * Nothing needed it — `scheduled()` is wired through the platform by the\n * `triggers.crons` entry in the wrangler config, which is how the cron\n * actually runs.\n *\n * @final Owns the error envelope; extend through {@link onRequest}. A\n * subclass override is not refused at runtime (that would break 1.x\n * consumers) but is outside the contract — see `docs/design-charter.md`.\n */\n public async fetch(request: Request, env: Env, ctx: WorkerExecutionContext): Promise<Response> {\n try {\n return await this.onRequest(request, env, ctx);\n } catch (err: unknown) {\n this.reportUnhandled(BASE_WORKER_MESSAGES.fetch, err);\n return new Response('Internal Error', { status: 500 });\n }\n }\n\n /**\n * The cron entry.\n *\n * @final Owns the error containment; extend through {@link onScheduled} or,\n * for the family's standard cron, {@link cronTasksNamespace}.\n */\n public async scheduled(event: WorkerScheduledController, env: Env, ctx: WorkerExecutionContext): Promise<void> {\n try {\n await this.onScheduled(event, env, ctx);\n } catch (err: unknown) {\n this.reportUnhandled(BASE_WORKER_MESSAGES.scheduled, err);\n }\n }\n\n /**\n * The sink for an unhandled rejection at this base's boundaries.\n *\n *
|
|
5
|
-
"mappings": "+EAAA,OAAS,+BAAAA,MAAmC,yCAE5C,OAAS,wBAAAC,
|
|
6
|
-
"names": ["dispatchCronToDurableObject", "BASE_WORKER_MESSAGES", "AbstractEntrypointWorker", "__name", "request", "env", "ctx", "err", "event", "message", "error", "namespace", "_env"]
|
|
4
|
+
"sourcesContent": ["import { dispatchCronToDurableObject } from '../cron/dispatchCronToDurableObject.ts';\nimport type { DurableObjectNamespaceLike } from '../cron/dispatchCronToDurableObject.ts';\nimport { BASE_WORKER_MESSAGES, reportRedacted } from './baseWorkerError.ts';\n\n/**\n * Minimal Workers-compatible context types so backend-runtime typechecks\n * without @cloudflare/workers-types. Apps pass the real ExecutionContext /\n * ScheduledController which satisfy these structurally.\n *\n * Converged verbatim from `backend-runtime/src/base/AbstractEntrypointWorker.ts`\n * (identical in all nine repos).\n */\ninterface WorkerExecutionContext {\n waitUntil(promise: Promise<unknown>): void;\n passThroughOnException(): void;\n}\n\ninterface WorkerScheduledController {\n cron: string;\n scheduledTime: number;\n noRetry(): void;\n}\n\nabstract class AbstractEntrypointWorker {\n /**\n * The HTTP request path.\n *\n * There is deliberately no `/__scheduled` branch here. It used to run before\n * `onRequest`, which made `GET /__scheduled` an unauthenticated, un-rated\n * trigger for the scheduled work: it bypassed the app's security headers, its\n * request scope, and its rate limits, and any caller could fire the cron\n * Durable Object on demand. `noRetry` was a `(): void => undefined` stub, so\n * the retry semantics were lost too.\n *\n * Nothing needed it — `scheduled()` is wired through the platform by the\n * `triggers.crons` entry in the wrangler config, which is how the cron\n * actually runs.\n *\n * @final Owns the error envelope; extend through {@link onRequest}. A\n * subclass override is not refused at runtime (that would break 1.x\n * consumers) but is outside the contract — see `docs/design-charter.md`.\n */\n public async fetch(request: Request, env: Env, ctx: WorkerExecutionContext): Promise<Response> {\n try {\n return await this.onRequest(request, env, ctx);\n } catch (err: unknown) {\n this.reportUnhandled(BASE_WORKER_MESSAGES.fetch, err);\n return new Response('Internal Error', { status: 500 });\n }\n }\n\n /**\n * The cron entry.\n *\n * @final Owns the error containment; extend through {@link onScheduled} or,\n * for the family's standard cron, {@link cronTasksNamespace}.\n */\n public async scheduled(event: WorkerScheduledController, env: Env, ctx: WorkerExecutionContext): Promise<void> {\n try {\n await this.onScheduled(event, env, ctx);\n } catch (err: unknown) {\n this.reportUnhandled(BASE_WORKER_MESSAGES.scheduled, err);\n }\n }\n\n /**\n * The sink for an unhandled rejection at this base's boundaries.\n *\n * Redacted by default (charter: static message, never a caught value): the default logs the\n * static message plus `errorName` and, when the value carries a short `type` or `code`, `errorCode`,\n * and never the message or stack, which can carry a token. This is the open side: an app that ships\n * to a log sink it controls overrides this to receive the raw `error`, and owns what reaches it.\n */\n protected reportUnhandled(message: string, error: unknown): void {\n reportRedacted(message, error);\n }\n\n protected abstract onRequest(request: Request, env: Env, ctx: WorkerExecutionContext): Promise<Response>;\n\n /**\n * The cron work. Optional since 1.10.\n *\n * The default implements the family pattern — `scheduled → CronTasksDurableObject\n * → TaskRegistry`: when {@link cronTasksNamespace} names a binding, the tick is\n * forwarded to its `idFromName('global')` instance inside `ctx.waitUntil`;\n * otherwise it is a no-op, which is right for a worker with no cron trigger.\n * Overriding it keeps working exactly as before.\n */\n protected onScheduled(event: WorkerScheduledController, env: Env, ctx: WorkerExecutionContext): Promise<void> {\n const namespace = this.cronTasksNamespace(env);\n if (namespace !== null) {\n ctx.waitUntil(dispatchCronToDurableObject(namespace, { cron: event.cron, scheduledTime: event.scheduledTime }));\n }\n return Promise.resolve();\n }\n\n /**\n * The cron Durable Object binding the default {@link onScheduled} forwards\n * to, or `null` (the default) for none. Typically `return env.CRON_TASKS`.\n */\n protected cronTasksNamespace(_env: Env): DurableObjectNamespaceLike | null {\n return null;\n }\n}\n\nexport { AbstractEntrypointWorker };\nexport type { WorkerExecutionContext, WorkerScheduledController };\n"],
|
|
5
|
+
"mappings": "+EAAA,OAAS,+BAAAA,MAAmC,yCAE5C,OAAS,wBAAAC,EAAsB,kBAAAC,MAAsB,uBAqBrD,MAAeC,CAAwB,CAvBvC,MAuBuC,CAAAC,EAAA,iCAmB9B,MAAM,MAAMC,EAAkBC,EAAUC,EAA2B,CACxE,GAAI,CACF,OAAO,MAAM,KAAK,UAAUF,EAASC,EAAKC,CAAG,CAC/C,OAASC,EAAc,CACrB,YAAK,gBAAgBP,EAAqB,MAAOO,CAAG,EAC7C,IAAI,SAAS,iBAAkB,CAAE,OAAQ,GAAG,CAAE,CACvD,CACF,CAQO,MAAM,UAAUC,EAAkCH,EAAUC,EAA2B,CAC5F,GAAI,CACF,MAAM,KAAK,YAAYE,EAAOH,EAAKC,CAAG,CACxC,OAASC,EAAc,CACrB,KAAK,gBAAgBP,EAAqB,UAAWO,CAAG,CAC1D,CACF,CAUU,gBAAgBE,EAAiBC,EAAc,CACvDT,EAAeQ,EAASC,CAAK,CAC/B,CAaU,YAAYF,EAAkCH,EAAUC,EAA2B,CAC3F,MAAMK,EAAY,KAAK,mBAAmBN,CAAG,EAC7C,OAAIM,IAAc,MAChBL,EAAI,UAAUP,EAA4BY,EAAW,CAAE,KAAMH,EAAM,KAAM,cAAeA,EAAM,aAAa,CAAE,CAAC,EAEzG,QAAQ,QAAO,CACxB,CAMU,mBAAmBI,EAAS,CACpC,OAAO,IACT",
|
|
6
|
+
"names": ["dispatchCronToDurableObject", "BASE_WORKER_MESSAGES", "reportRedacted", "AbstractEntrypointWorker", "__name", "request", "env", "ctx", "err", "event", "message", "error", "namespace", "_env"]
|
|
7
7
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
var
|
|
1
|
+
var c=Object.defineProperty;var o=(t,e)=>c(t,"name",{value:e,configurable:!0});import{BASE_WORKER_MESSAGES as d,reportRedacted as h}from"./baseWorkerError.js";class n{static{o(this,"AbstractQueueWorker")}async queue(e,r,u){try{await this.onQueue(e,r,u)}catch(a){throw this.reportUnhandled(d.queue,a),a}}reportUnhandled(e,r){h(e,r)}}export{n as AbstractQueueWorker};
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/base/AbstractQueueWorker.ts"],
|
|
4
|
-
"sourcesContent": ["import type { WorkerExecutionContext } from './AbstractEntrypointWorker.ts';\nimport { BASE_WORKER_MESSAGES } from './baseWorkerError.ts';\n\n/**\n * The queue consumer base, converged from the `AbstractQueueWorker` copies in\n * Edge-Git and Mail-Otter (the only two repos with queue consumers).\n *\n * It rethrows after logging: a queue message that failed must be *retried* by\n * the platform, and a base that swallowed the rejection would turn a transient\n * handler failure into an acked, dropped message.\n *\n * **The batch is a type parameter, not a modelled shape.** This base never\n * reads the batch — it forwards it — so declaring a structural stand-in for it\n * bought nothing and cost correctness: the old `WorkerMessageBatch<T>` modelled\n * `messages: T[]`, which is wrong twice over (the platform's elements are\n * `Message<T>`, and a real batch also carries `queue`, `metadata`, `ackAll` and\n * `retryAll`). A consumer subclassing against that type lost `batch.queue` and\n * every `message.ack()`/`message.retry()`, and had to cast to get them back.\n *\n * Passing the platform `MessageBatch<Body>` as `TBatch` gives the handler the\n * full surface with no cast and no duplication of the platform's own types.\n */\nabstract class AbstractQueueWorker<TBatch = unknown> {\n /**\n * @final Owns the error containment; extend through {@link onQueue}. Not\n * refused at runtime in 1.x (that would break consumers), but outside the\n * contract — see `docs/design-charter.md`.\n */\n public async queue(batch: TBatch, env: Env, ctx: WorkerExecutionContext): Promise<void> {\n try {\n await this.onQueue(batch, env, ctx);\n } catch (err: unknown) {\n this.reportUnhandled(BASE_WORKER_MESSAGES.queue, err);\n throw err;\n }\n }\n\n /**\n * The sink for an unhandled rejection at this base's boundary. See\n * `AbstractEntrypointWorker.reportUnhandled`.\n */\n protected reportUnhandled(message: string, error: unknown): void {\n
|
|
5
|
-
"mappings": "+EACA,OAAS,wBAAAA,
|
|
6
|
-
"names": ["BASE_WORKER_MESSAGES", "AbstractQueueWorker", "__name", "batch", "env", "ctx", "err", "message", "error"]
|
|
4
|
+
"sourcesContent": ["import type { WorkerExecutionContext } from './AbstractEntrypointWorker.ts';\nimport { BASE_WORKER_MESSAGES, reportRedacted } from './baseWorkerError.ts';\n\n/**\n * The queue consumer base, converged from the `AbstractQueueWorker` copies in\n * Edge-Git and Mail-Otter (the only two repos with queue consumers).\n *\n * It rethrows after logging: a queue message that failed must be *retried* by\n * the platform, and a base that swallowed the rejection would turn a transient\n * handler failure into an acked, dropped message.\n *\n * **The batch is a type parameter, not a modelled shape.** This base never\n * reads the batch — it forwards it — so declaring a structural stand-in for it\n * bought nothing and cost correctness: the old `WorkerMessageBatch<T>` modelled\n * `messages: T[]`, which is wrong twice over (the platform's elements are\n * `Message<T>`, and a real batch also carries `queue`, `metadata`, `ackAll` and\n * `retryAll`). A consumer subclassing against that type lost `batch.queue` and\n * every `message.ack()`/`message.retry()`, and had to cast to get them back.\n *\n * Passing the platform `MessageBatch<Body>` as `TBatch` gives the handler the\n * full surface with no cast and no duplication of the platform's own types.\n */\nabstract class AbstractQueueWorker<TBatch = unknown> {\n /**\n * @final Owns the error containment; extend through {@link onQueue}. Not\n * refused at runtime in 1.x (that would break consumers), but outside the\n * contract — see `docs/design-charter.md`.\n */\n public async queue(batch: TBatch, env: Env, ctx: WorkerExecutionContext): Promise<void> {\n try {\n await this.onQueue(batch, env, ctx);\n } catch (err: unknown) {\n this.reportUnhandled(BASE_WORKER_MESSAGES.queue, err);\n throw err;\n }\n }\n\n /**\n * The sink for an unhandled rejection at this base's boundary. See\n * `AbstractEntrypointWorker.reportUnhandled`.\n */\n protected reportUnhandled(message: string, error: unknown): void {\n reportRedacted(message, error);\n }\n\n protected abstract onQueue(batch: TBatch, env: Env, ctx: WorkerExecutionContext): Promise<void>;\n}\n\nexport { AbstractQueueWorker };\n"],
|
|
5
|
+
"mappings": "+EACA,OAAS,wBAAAA,EAAsB,kBAAAC,MAAsB,uBAqBrD,MAAeC,CAAmB,CArBlC,MAqBkC,CAAAC,EAAA,4BAMzB,MAAM,MAAMC,EAAeC,EAAUC,EAA2B,CACrE,GAAI,CACF,MAAM,KAAK,QAAQF,EAAOC,EAAKC,CAAG,CACpC,OAASC,EAAc,CACrB,WAAK,gBAAgBP,EAAqB,MAAOO,CAAG,EAC9CA,CACR,CACF,CAMU,gBAAgBC,EAAiBC,EAAc,CACvDR,EAAeO,EAASC,CAAK,CAC/B",
|
|
6
|
+
"names": ["BASE_WORKER_MESSAGES", "reportRedacted", "AbstractQueueWorker", "__name", "batch", "env", "ctx", "err", "message", "error"]
|
|
7
7
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
var a=Object.defineProperty;var n=(t,r)=>a(t,"name",{value:r,configurable:!0});import{WorkflowEntrypoint as
|
|
1
|
+
var a=Object.defineProperty;var n=(t,r)=>a(t,"name",{value:r,configurable:!0});import{WorkflowEntrypoint as d}from"cloudflare:workers";import{BASE_WORKER_MESSAGES as l,reportRedacted as p}from"./baseWorkerError.js";class s extends d{static{n(this,"AbstractWorkflowWorker")}async run(r,o){try{return await this.onWorkflow(r,o)}catch(e){throw this.reportUnhandled(l.workflow,e),e}}reportUnhandled(r,o){p(r,o)}}export{s as AbstractWorkflowWorker};
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/base/AbstractWorkflowWorker.ts"],
|
|
4
|
-
"sourcesContent": ["import { WorkflowEntrypoint } from 'cloudflare:workers';\nimport type { WorkflowEvent, WorkflowStep } from 'cloudflare:workers';\nimport { BASE_WORKER_MESSAGES } from './baseWorkerError.ts';\n\n/**\n * The Workflow base, converged from the `AbstractWorkflowWorker` copies in\n * Edge-Git and Mail-Otter (Edge-Sonic ships the same shape as `runWorkflow.ts`\n * with a `WorkflowEntrypoint` wrapper around it).\n *\n * It extends the platform `WorkflowEntrypoint` because a workflow handler needs\n * `this.env` — it is where the bindings come from, and every step in a real\n * workflow builds a request scope from it. An earlier version of this file\n * modelled `WorkflowEventLike`/`WorkflowStepLike` as standalone structural\n * types and dropped the parent class, which removed `this.env` and reduced\n * `step.do` to `(name, callback)`. That is not a stricter shape, it is a lossy\n * one: it took away the per-step `retries`/`timeout` config that makes a step\n * retryable under the platform rather than a bare coroutine call. Both are\n * restored here, and the structural types are gone with them — the platform\n * types are the ones that were correct all along.\n *\n * `TEnv` is last and defaulted rather than first: every consumer in the family\n * writes `AbstractWorkflowWorker<TPayload, TResult>`, so leading with the env\n * type would silently reinterpret their payload as the environment. The default\n * is the ambient `Env`, which is what a handler wants unless it has narrowed its\n * bindings deliberately.\n */\nabstract class AbstractWorkflowWorker<TPayload = unknown, TResult = unknown, TEnv = Env> extends WorkflowEntrypoint<TEnv, TPayload> {\n /**\n * @final Owns the error containment; extend through {@link onWorkflow}. Not\n * refused at runtime in 1.x (that would break consumers), but outside the\n * contract — see `docs/design-charter.md`.\n */\n public async run(event: Readonly<WorkflowEvent<TPayload>>, step: WorkflowStep): Promise<TResult> {\n try {\n return await this.onWorkflow(event, step);\n } catch (err: unknown) {\n this.reportUnhandled(BASE_WORKER_MESSAGES.workflow, err);\n throw err;\n }\n }\n\n /**\n * The sink for an unhandled rejection at this base's boundary. See\n * `AbstractEntrypointWorker.reportUnhandled`.\n */\n protected reportUnhandled(message: string, error: unknown): void {\n
|
|
5
|
-
"mappings": "+EAAA,OAAS,sBAAAA,MAA0B,qBAEnC,OAAS,wBAAAC,
|
|
6
|
-
"names": ["WorkflowEntrypoint", "BASE_WORKER_MESSAGES", "AbstractWorkflowWorker", "__name", "event", "step", "err", "message", "error"]
|
|
4
|
+
"sourcesContent": ["import { WorkflowEntrypoint } from 'cloudflare:workers';\nimport type { WorkflowEvent, WorkflowStep } from 'cloudflare:workers';\nimport { BASE_WORKER_MESSAGES, reportRedacted } from './baseWorkerError.ts';\n\n/**\n * The Workflow base, converged from the `AbstractWorkflowWorker` copies in\n * Edge-Git and Mail-Otter (Edge-Sonic ships the same shape as `runWorkflow.ts`\n * with a `WorkflowEntrypoint` wrapper around it).\n *\n * It extends the platform `WorkflowEntrypoint` because a workflow handler needs\n * `this.env` — it is where the bindings come from, and every step in a real\n * workflow builds a request scope from it. An earlier version of this file\n * modelled `WorkflowEventLike`/`WorkflowStepLike` as standalone structural\n * types and dropped the parent class, which removed `this.env` and reduced\n * `step.do` to `(name, callback)`. That is not a stricter shape, it is a lossy\n * one: it took away the per-step `retries`/`timeout` config that makes a step\n * retryable under the platform rather than a bare coroutine call. Both are\n * restored here, and the structural types are gone with them — the platform\n * types are the ones that were correct all along.\n *\n * `TEnv` is last and defaulted rather than first: every consumer in the family\n * writes `AbstractWorkflowWorker<TPayload, TResult>`, so leading with the env\n * type would silently reinterpret their payload as the environment. The default\n * is the ambient `Env`, which is what a handler wants unless it has narrowed its\n * bindings deliberately.\n */\nabstract class AbstractWorkflowWorker<TPayload = unknown, TResult = unknown, TEnv = Env> extends WorkflowEntrypoint<TEnv, TPayload> {\n /**\n * @final Owns the error containment; extend through {@link onWorkflow}. Not\n * refused at runtime in 1.x (that would break consumers), but outside the\n * contract — see `docs/design-charter.md`.\n */\n public async run(event: Readonly<WorkflowEvent<TPayload>>, step: WorkflowStep): Promise<TResult> {\n try {\n return await this.onWorkflow(event, step);\n } catch (err: unknown) {\n this.reportUnhandled(BASE_WORKER_MESSAGES.workflow, err);\n throw err;\n }\n }\n\n /**\n * The sink for an unhandled rejection at this base's boundary. See\n * `AbstractEntrypointWorker.reportUnhandled`.\n */\n protected reportUnhandled(message: string, error: unknown): void {\n reportRedacted(message, error);\n }\n\n protected abstract onWorkflow(event: Readonly<WorkflowEvent<TPayload>>, step: WorkflowStep): Promise<TResult>;\n}\n\nexport { AbstractWorkflowWorker };\n"],
|
|
5
|
+
"mappings": "+EAAA,OAAS,sBAAAA,MAA0B,qBAEnC,OAAS,wBAAAC,EAAsB,kBAAAC,MAAsB,uBAwBrD,MAAeC,UAAkFH,CAAkC,CA1BnI,MA0BmI,CAAAI,EAAA,+BAM1H,MAAM,IAAIC,EAA0CC,EAAkB,CAC3E,GAAI,CACF,OAAO,MAAM,KAAK,WAAWD,EAAOC,CAAI,CAC1C,OAASC,EAAc,CACrB,WAAK,gBAAgBN,EAAqB,SAAUM,CAAG,EACjDA,CACR,CACF,CAMU,gBAAgBC,EAAiBC,EAAc,CACvDP,EAAeM,EAASC,CAAK,CAC/B",
|
|
6
|
+
"names": ["WorkflowEntrypoint", "BASE_WORKER_MESSAGES", "reportRedacted", "AbstractWorkflowWorker", "__name", "event", "step", "err", "message", "error"]
|
|
7
7
|
}
|
|
@@ -29,6 +29,14 @@ type BaseWorkerOperation = 'fetch' | 'scheduled' | 'queue' | 'workflow' | 'durab
|
|
|
29
29
|
* introducing it.
|
|
30
30
|
*/
|
|
31
31
|
declare const BASE_WORKER_MESSAGES: Readonly<Record<BaseWorkerOperation, string>>;
|
|
32
|
-
|
|
32
|
+
/**
|
|
33
|
+
* The redacted default sink: the static message plus `errorName` (the class name, or the `typeof` of a
|
|
34
|
+
* non-object) and, when the value carries a short identifier-shaped `type` or `code`, `errorCode`. Never the
|
|
35
|
+
* message, the stack or the value itself: a D1 message names tables and an upstream error can carry a token.
|
|
36
|
+
*
|
|
37
|
+
* An app that ships to a controlled sink overrides `reportUnhandled` and receives the raw value there.
|
|
38
|
+
*/
|
|
39
|
+
declare function reportRedacted(message: string, error: unknown): void;
|
|
40
|
+
export { BASE_WORKER_MESSAGES, reportRedacted };
|
|
33
41
|
export type { BaseWorkerOperation };
|
|
34
42
|
//# sourceMappingURL=baseWorkerError.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"baseWorkerError.d.ts","sourceRoot":"","sources":["../../src/base/baseWorkerError.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAEH;;;;;;GAMG;AACH,KAAK,mBAAmB,GAAG,OAAO,GAAG,WAAW,GAAG,OAAO,GAAG,UAAU,GAAG,oBAAoB,CAAC;AAE/F;;;;;;;GAOG;AACH,QAAA,MAAM,oBAAoB,EAAE,QAAQ,CAAC,MAAM,CAAC,mBAAmB,EAAE,MAAM,CAAC,CAMvE,CAAC;
|
|
1
|
+
{"version":3,"file":"baseWorkerError.d.ts","sourceRoot":"","sources":["../../src/base/baseWorkerError.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAEH;;;;;;GAMG;AACH,KAAK,mBAAmB,GAAG,OAAO,GAAG,WAAW,GAAG,OAAO,GAAG,UAAU,GAAG,oBAAoB,CAAC;AAE/F;;;;;;;GAOG;AACH,QAAA,MAAM,oBAAoB,EAAE,QAAQ,CAAC,MAAM,CAAC,mBAAmB,EAAE,MAAM,CAAC,CAMvE,CAAC;AAIF;;;;;;GAMG;AACH,iBAAS,cAAc,CAAC,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,OAAO,GAAG,IAAI,CAiB7D;AAED,OAAO,EAAE,oBAAoB,EAAE,cAAc,EAAE,CAAC;AAChD,YAAY,EAAE,mBAAmB,EAAE,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
const
|
|
1
|
+
var l=Object.defineProperty;var c=(n,e)=>l(n,"name",{value:e,configurable:!0});const f={fetch:"Unhandled error in fetch():",scheduled:"Unhandled error in scheduled():",queue:"Unhandled error in queue():",workflow:"Unhandled error in workflow run():",durableObjectFetch:"Unhandled error in durable object fetch():"},a=/^[\w.:-]{1,64}$/;function u(n,e){const t={errorName:typeof e=="object"&&e!==null?e.constructor?.name||"Object":typeof e};if(typeof e=="object"&&e!==null){const{type:d,code:r}=e;for(const o of[d,r])if(typeof o=="string"&&a.test(o)){t.errorCode=o;break}}console.error(n,t)}c(u,"reportRedacted");export{f as BASE_WORKER_MESSAGES,u as reportRedacted};
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/base/baseWorkerError.ts"],
|
|
4
|
-
"sourcesContent": ["/**\n * The error-reporting seam shared by every worker base.\n *\n * Each base catches an unhandled rejection, reports it, and (for the\n * request-shaped ones) answers 500. What it must *not* do is decide what the\n * caught value is safe to write, because that is not the base's knowledge: the\n * base cannot know whether the value transitively carries a credential, and\n * every consumer's token-adjacent boundaries redact differently.\n *\n * So the base owns the message and the consumer owns the sink. `message` is\n * always one of the literals in `BASE_WORKER_MESSAGES` — never an interpolated\n * value — so an override can forward it without itself becoming a place where\n * untrusted text reaches a log line.\n */\n\n/**\n * Every boundary that reports an unhandled rejection.\n *\n * A member per base rather than a free-form string, because the message table\n * is keyed on it: a base that grows a new entry point cannot pick a message the\n * table does not have.\n */\ntype BaseWorkerOperation = 'fetch' | 'scheduled' | 'queue' | 'workflow' | 'durableObjectFetch';\n\n/**\n * Operator-facing text per boundary, in the shape a log line wants: a constant\n * prefix, with the caught value following it.\n *\n * Static by construction. A base interpolating anything into these is the exact\n * pattern consumer codebases are told to avoid, and it would be the kit\n * introducing it.\n */\nconst BASE_WORKER_MESSAGES: Readonly<Record<BaseWorkerOperation, string>> = {\n fetch: 'Unhandled error in fetch():',\n scheduled: 'Unhandled error in scheduled():',\n queue: 'Unhandled error in queue():',\n workflow: 'Unhandled error in workflow run():',\n durableObjectFetch: 'Unhandled error in durable object fetch():',\n};\n\nexport { BASE_WORKER_MESSAGES };\nexport type { BaseWorkerOperation };\n"],
|
|
5
|
-
"mappings": "
|
|
6
|
-
"names": ["BASE_WORKER_MESSAGES"]
|
|
4
|
+
"sourcesContent": ["/**\n * The error-reporting seam shared by every worker base.\n *\n * Each base catches an unhandled rejection, reports it, and (for the\n * request-shaped ones) answers 500. What it must *not* do is decide what the\n * caught value is safe to write, because that is not the base's knowledge: the\n * base cannot know whether the value transitively carries a credential, and\n * every consumer's token-adjacent boundaries redact differently.\n *\n * So the base owns the message and the consumer owns the sink. `message` is\n * always one of the literals in `BASE_WORKER_MESSAGES` — never an interpolated\n * value — so an override can forward it without itself becoming a place where\n * untrusted text reaches a log line.\n */\n\n/**\n * Every boundary that reports an unhandled rejection.\n *\n * A member per base rather than a free-form string, because the message table\n * is keyed on it: a base that grows a new entry point cannot pick a message the\n * table does not have.\n */\ntype BaseWorkerOperation = 'fetch' | 'scheduled' | 'queue' | 'workflow' | 'durableObjectFetch';\n\n/**\n * Operator-facing text per boundary, in the shape a log line wants: a constant\n * prefix, with the caught value following it.\n *\n * Static by construction. A base interpolating anything into these is the exact\n * pattern consumer codebases are told to avoid, and it would be the kit\n * introducing it.\n */\nconst BASE_WORKER_MESSAGES: Readonly<Record<BaseWorkerOperation, string>> = {\n fetch: 'Unhandled error in fetch():',\n scheduled: 'Unhandled error in scheduled():',\n queue: 'Unhandled error in queue():',\n workflow: 'Unhandled error in workflow run():',\n durableObjectFetch: 'Unhandled error in durable object fetch():',\n};\n\nconst SAFE_CODE = /^[\\w.:-]{1,64}$/;\n\n/**\n * The redacted default sink: the static message plus `errorName` (the class name, or the `typeof` of a\n * non-object) and, when the value carries a short identifier-shaped `type` or `code`, `errorCode`. Never the\n * message, the stack or the value itself: a D1 message names tables and an upstream error can carry a token.\n *\n * An app that ships to a controlled sink overrides `reportUnhandled` and receives the raw value there.\n */\nfunction reportRedacted(message: string, error: unknown): void {\n const fields: { errorName: string; errorCode?: string } = {\n errorName:\n typeof error === 'object' && error !== null\n ? ((error as { constructor?: { name?: unknown } }).constructor?.name as string) || 'Object'\n : typeof error,\n };\n if (typeof error === 'object' && error !== null) {\n const { type, code } = error as { type?: unknown; code?: unknown };\n for (const candidate of [type, code]) {\n if (typeof candidate === 'string' && SAFE_CODE.test(candidate)) {\n fields.errorCode = candidate;\n break;\n }\n }\n }\n console.error(message, fields);\n}\n\nexport { BASE_WORKER_MESSAGES, reportRedacted };\nexport type { BaseWorkerOperation };\n"],
|
|
5
|
+
"mappings": "+EAgCA,MAAMA,EAAsE,CAC1E,MAAO,8BACP,UAAW,kCACX,MAAO,8BACP,SAAU,qCACV,mBAAoB,8CAGhBC,EAAY,kBASlB,SAASC,EAAeC,EAAiBC,EAAc,CACrD,MAAMC,EAAoD,CACxD,UACE,OAAOD,GAAU,UAAYA,IAAU,KACjCA,EAA+C,aAAa,MAAmB,SACjF,OAAOA,GAEf,GAAI,OAAOA,GAAU,UAAYA,IAAU,KAAM,CAC/C,KAAM,CAAE,KAAAE,EAAM,KAAAC,CAAI,EAAKH,EACvB,UAAWI,IAAa,CAACF,EAAMC,CAAI,EACjC,GAAI,OAAOC,GAAc,UAAYP,EAAU,KAAKO,CAAS,EAAG,CAC9DH,EAAO,UAAYG,EACnB,KACF,CAEJ,CACA,QAAQ,MAAML,EAASE,CAAM,CAC/B,CAjBSI,EAAAP,EAAA",
|
|
6
|
+
"names": ["BASE_WORKER_MESSAGES", "SAFE_CODE", "reportRedacted", "message", "error", "fields", "type", "code", "candidate", "__name"]
|
|
7
7
|
}
|