@mcp-b/do-runtime 0.1.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.
Files changed (52) hide show
  1. package/CHANGELOG.md +14 -0
  2. package/LICENSE +110 -0
  3. package/LICENSE.workerd +176 -0
  4. package/NOTICE +7 -0
  5. package/README.md +282 -0
  6. package/dist/backends/node-sqlite.d.ts +38 -0
  7. package/dist/backends/node-sqlite.js +335 -0
  8. package/dist/backends/node-sqlite.js.map +1 -0
  9. package/dist/backends/sqlite-wasm.d.ts +130 -0
  10. package/dist/backends/sqlite-wasm.js +259 -0
  11. package/dist/backends/sqlite-wasm.js.map +1 -0
  12. package/dist/chunks/sqlite-DFg92Tgt.js +498 -0
  13. package/dist/chunks/sqlite-DFg92Tgt.js.map +1 -0
  14. package/dist/cloudflare-workers.js +351 -0
  15. package/dist/cloudflare-workers.js.map +1 -0
  16. package/dist/conformance/host.d.ts +58 -0
  17. package/dist/conformance.js +18 -0
  18. package/dist/conformance.js.map +1 -0
  19. package/dist/index.js +7184 -0
  20. package/dist/index.js.map +1 -0
  21. package/dist/server/alarm-scheduler.js +513 -0
  22. package/dist/server/alarm-scheduler.js.map +1 -0
  23. package/dist/src/api/actor-state.d.ts +396 -0
  24. package/dist/src/api/actor.d.ts +306 -0
  25. package/dist/src/api/cloudflare-workers.d.ts +259 -0
  26. package/dist/src/api/export-loopback.d.ts +264 -0
  27. package/dist/src/api/global-scope.d.ts +262 -0
  28. package/dist/src/api/http.d.ts +52 -0
  29. package/dist/src/api/sql.d.ts +188 -0
  30. package/dist/src/api/sync-kv.d.ts +51 -0
  31. package/dist/src/api/web-socket.d.ts +93 -0
  32. package/dist/src/api/worker-loader.d.ts +354 -0
  33. package/dist/src/index.d.ts +130 -0
  34. package/dist/src/io/actor-cache.d.ts +203 -0
  35. package/dist/src/io/actor-id.d.ts +74 -0
  36. package/dist/src/io/actor-sqlite.d.ts +298 -0
  37. package/dist/src/io/io-channels.d.ts +191 -0
  38. package/dist/src/io/io-context.d.ts +451 -0
  39. package/dist/src/io/io-gate.d.ts +298 -0
  40. package/dist/src/io/worker-source.d.ts +108 -0
  41. package/dist/src/io/worker.d.ts +88 -0
  42. package/dist/src/server/actor-container.d.ts +525 -0
  43. package/dist/src/server/actor-id-impl.d.ts +118 -0
  44. package/dist/src/server/alarm-scheduler.d.ts +201 -0
  45. package/dist/src/server/facet-deletion.d.ts +156 -0
  46. package/dist/src/server/facet-tree-index.d.ts +94 -0
  47. package/dist/src/server/sha256.d.ts +39 -0
  48. package/dist/src/transport/rpc-session.d.ts +34 -0
  49. package/dist/src/util/sqlite-kv.d.ts +98 -0
  50. package/dist/src/util/sqlite-metadata.d.ts +46 -0
  51. package/dist/src/util/sqlite.d.ts +291 -0
  52. package/package.json +111 -0
@@ -0,0 +1,306 @@
1
+ /**
2
+ * ← workerd `src/workerd/api/actor.{h,c++}`
3
+ *
4
+ * Upstream's own opening comment is the best summary of why this file is named
5
+ * what it is: "'Actors' are the internal name for Durable Objects, because they
6
+ * implement a sort of actor model. We ended up not calling the product 'Actors'
7
+ * publicly because we found that people who were familiar with actor-model
8
+ * programming were more confused than helped by it."
9
+ *
10
+ * Five classes and three outgoing factories. The five are here:
11
+ * `ColoLocalActorNamespace` (`actor.h:25`), `DurableObjectId` (`:42`),
12
+ * `DurableObject` (`:87`), `DurableObjectNamespace` (`:142`) and
13
+ * `DurableObjectClass` (`:367`). The three factories — `GlobalActorOutgoingFactory`
14
+ * (`:293`), `LocalActorOutgoingFactory` (`:331`) and `ReplicaActorOutgoingFactory`
15
+ * (`:352`) — are **not**, and their absence is the whole of this file's seam:
16
+ * every one of them is a bag of addressing data plus a lazily-created actor
17
+ * channel, and `newSingleUseClient` returns a `WorkerInterface`, which is capnp
18
+ * dispatch with no port. `ActorChannelFactory` and `ColoLocalActorChannelFactory`
19
+ * below are the shape they plug into, holding exactly the fields the two
20
+ * reachable factories' constructors capture.
21
+ * `ActorRetryRequestMetadata` stays on that same omitted transport seam:
22
+ * upstream passes it from an outgoing factory to `ActorChannel`, while the
23
+ * host-provided `Fetcher` here already owns retry policy and exposes no metadata.
24
+ *
25
+ * **`ColoLocalActorNamespace` is ported, not treated as a substrate boundary**,
26
+ * and the reason is worth stating because the opposite call is easy to defend
27
+ * badly. It is the pre-SQLite, non-durable actor namespace, and this host cannot
28
+ * host one — there is no storage-less actor kind here, and `createActorContainer`
29
+ * requires a `SqlDatabaseProvider`. But *hosting* is not in this file. What is in
30
+ * this file is the JS-facing half: one argument check and one outgoing-stub
31
+ * request, which has precisely the same substrate needs as
32
+ * `DurableObjectNamespace.get()`, which nobody proposes cutting. The boundary, if
33
+ * there is one, sits in `server/` at the point something has to place an
34
+ * ephemeral actor — so there is nothing here to cut, and cutting it would be the
35
+ * feature subset the package README forbids.
36
+ *
37
+ * It is also not idle, though an earlier revision of this comment gave the wrong
38
+ * reason. It claimed `ctx.exports` surfaces a storage-less actor class as a
39
+ * `LoopbackColoLocalActorNamespace`; upstream's own comment
40
+ * (`api/export-loopback.h:111-115`) says that case is a
41
+ * `LoopbackDurableObjectClass`. `LoopbackColoLocalActorNamespace` is "for
42
+ * colo-local (ephemeral) actor namespaces" (`:191`) and is built from a
43
+ * *configured* binding, `Global::LoopbackEphemeralActorNamespace`
44
+ * (`server/workerd-api.c++:666-670`) — reachable through configuration rather
45
+ * than through a bare export. The conclusion stands; the path to it is that one.
46
+ *
47
+ * Two things are absent because there is nothing to resolve them against:
48
+ *
49
+ * - **The numbered-channel arm of every binding.** Each of upstream's
50
+ * `kj::OneOf<uint, IoOwn<...>>` keeps only its object arm. Upstream resolves a
51
+ * binding to a `uint` at configuration time; here a binding is a property of
52
+ * the `env` object the consumer supplies, and there is no channel table for a
53
+ * number to index. The object arm is upstream's own alternative, offered on
54
+ * `DurableObjectNamespace` for the case where one "is constructed dynamically
55
+ * within an execution context, rather than being a long-lived binding" — which
56
+ * is every binding here.
57
+ * - **Compatibility flags.** `getEnableVersionApi`, `getReplicaRouting`,
58
+ * `getDurableObjectGetExisting` and `getDurableObjectFetchRequiresSchemeAuthority`
59
+ * are read four times in `actor.c++`. A runtime with no deployed history takes
60
+ * the current behaviour, which is the same judgment `deleteAll()`'s
61
+ * `deleteAllDeletesAlarm` row already records. The one that is not a flag
62
+ * decision is `enableReplicaRouting`, which is `false` because replication is a
63
+ * named substrate boundary in `io/actor-cache.ts`.
64
+ *
65
+ * `serialize`/`deserialize` on `DurableObjectClass` are a boundary of their own:
66
+ * they are built on `jsg::Serializer`, `Frankenvalue`, capnp `rpc::JsValue::External`
67
+ * and channel tokens, none of which has a port. Both throw one named message.
68
+ *
69
+ * Spec: §1.10, §1.11 in docs/decisions.md.
70
+ */
71
+ import type { ActorGetMode, ActorId, ActorIdFactory, ActorRoutingMode, ActorVersion } from "../io/actor-id.js";
72
+ import type { ActorClassChannel } from "../io/io-channels.js";
73
+ /**
74
+ * ← the `[1, 2048]` bound in `ColoLocalActorNamespace::get`.
75
+ *
76
+ * Upstream compares `actorId.size()`, which for a `kj::String` is **bytes**, so
77
+ * this is measured in UTF-8 bytes rather than in UTF-16 code units. That costs
78
+ * one `TextEncoder` pass and buys an exact match on a bound a caller can hit.
79
+ */
80
+ export declare const MAX_COLO_LOCAL_ACTOR_ID_BYTES = 2048;
81
+ /**
82
+ * Upstream never faces this: JSG unwraps a `jsg::Ref<DurableObjectId>` parameter
83
+ * and throws a `TypeError` before the method body runs, so `getInner()` cannot be
84
+ * reached on something that is not one. Here the parameter type is
85
+ * workers-types' structural `DurableObjectId` interface, which any object with a
86
+ * `toString` and an `equals` satisfies — so the unwrap has to be written, and it
87
+ * fails closed rather than guessing at the string form.
88
+ */
89
+ export declare const FOREIGN_ACTOR_ID_MESSAGE: string;
90
+ /** Substrate boundary: `jsg::Serializer`, `Frankenvalue` and channel tokens have no port. */
91
+ export declare const ACTOR_CLASS_SERIALIZATION_UNIMPLEMENTED_MESSAGE: string;
92
+ /**
93
+ * ← what `GlobalActorOutgoingFactory`'s constructor captures (`actor.h:297-303`),
94
+ * one field per constructor parameter minus the channel number.
95
+ */
96
+ export type GlobalActorRequest = {
97
+ readonly id: ActorId;
98
+ readonly locationHint: string | undefined;
99
+ readonly mode: ActorGetMode;
100
+ readonly enableReplicaRouting: boolean;
101
+ readonly routingMode: ActorRoutingMode;
102
+ readonly version: ActorVersion | undefined;
103
+ };
104
+ /**
105
+ * ← `DurableObjectNamespace::ActorChannelFactory` (`actor.h:147-157`) composed
106
+ * with `IoChannelFactory::getGlobalActor`, which is what its one implementation
107
+ * forwards to.
108
+ *
109
+ * The composition is not a shortcut. Upstream's `getGlobalActor` returns an
110
+ * `ActorChannel`, and the only thing done with one is `startRequest(...)` →
111
+ * `WorkerInterface`, which the `Fetcher` then drives. `WorkerInterface` has no
112
+ * port and `Fetcher` construction is `api/http.{h,c++}`'s, which is not ported,
113
+ * so the channel and the stub it produces are one object here — the same collapse
114
+ * `io/worker.ts`'s `FacetManager.getFacet` and `server/actor-container.ts`'s
115
+ * `FacetHandle.stub` already make.
116
+ *
117
+ * Section 7 implements this. The laziness upstream's factory has — "Lazily
118
+ * initialize actorChannel" — belongs to the implementation, not to the interface,
119
+ * because upstream's own laziness is per-`newSingleUseClient` and there is no
120
+ * per-request client here to be lazy about.
121
+ */
122
+ export interface ActorChannelFactory {
123
+ getGlobalActor(request: GlobalActorRequest): Fetcher;
124
+ }
125
+ /** ← what `LocalActorOutgoingFactory`'s constructor captures (`actor.h:333-335`). */
126
+ export type ColoLocalActorRequest = {
127
+ readonly actorId: string;
128
+ };
129
+ /**
130
+ * ← `IoChannelFactory::getColoLocalActor`, reached through
131
+ * `LocalActorOutgoingFactory`.
132
+ *
133
+ * Upstream gives `ColoLocalActorNamespace` only the numbered-channel arm, because
134
+ * an ephemeral namespace is always a configured binding there. With no channel
135
+ * table the factory arm is the only one available, so this is the same
136
+ * substitution upstream itself offers `DurableObjectNamespace` — applied to the
137
+ * one constructor that did not already have it.
138
+ */
139
+ export interface ColoLocalActorChannelFactory {
140
+ getColoLocalActor(request: ColoLocalActorRequest): Fetcher;
141
+ }
142
+ /**
143
+ * ← `ColoLocalActorNamespace` (`actor.h:25-37`). "A capability to an ephemeral
144
+ * Actor namespace."
145
+ */
146
+ export declare class ColoLocalActorNamespace implements globalThis.ColoLocalActorNamespace {
147
+ #private;
148
+ constructor(channel: ColoLocalActorChannelFactory);
149
+ /** ← `ColoLocalActorNamespace::get` (`actor.c++:116-129`). */
150
+ get(actorId: string): Fetcher;
151
+ }
152
+ /**
153
+ * ← `DurableObjectId` (`actor.h:42-84`). "DurableObjectId type seen by
154
+ * JavaScript."
155
+ *
156
+ * `name` and `jurisdiction` are read from the inner id **once, at construction**,
157
+ * where upstream's are `JSG_READONLY_INSTANCE_PROPERTY`s that re-read it on every
158
+ * access. That is not a preference: `@cloudflare/workers-types` declares both
159
+ * `readonly name?: string`, and under `exactOptionalPropertyTypes` a getter
160
+ * returning `string | undefined` does not satisfy an optional `string`. An own
161
+ * property assigned only when the value exists does, and it is what keeps this
162
+ * class assignable to the interface with no cast (§2.4). The one behaviour lost
163
+ * is `ActorIdImpl::clearName()` (`server/actor-id-impl.h`) taking effect on an
164
+ * already-wrapped id — a `server/`-internal that runs before the id reaches JS.
165
+ */
166
+ export declare class DurableObjectId implements globalThis.DurableObjectId {
167
+ #private;
168
+ readonly name?: string;
169
+ readonly jurisdiction?: string;
170
+ constructor(id: ActorId);
171
+ /** ← `getInner()`. Not JS-visible upstream either; the outgoing factories take it. */
172
+ getInner(): ActorId;
173
+ /** "Converts to a string which can be passed back to the constructor to reproduce the same ID." */
174
+ toString(): string;
175
+ equals(other: globalThis.DurableObjectId): boolean;
176
+ }
177
+ /**
178
+ * ← `DurableObject` (`actor.h:87-139`). "Stub object used to send messages to a
179
+ * remote durable object."
180
+ *
181
+ * Upstream's carries its whole behaviour by `JSG_INHERIT(Fetcher)` and adds
182
+ * exactly two readonly properties. So does this: the `Fetcher` is the transport's
183
+ * and everything except `id` and `name` belongs to it. `asDurableObjectStub`
184
+ * below is where the inheritance goes.
185
+ */
186
+ export declare class DurableObject {
187
+ #private;
188
+ constructor(id: DurableObjectId, fetcher: Fetcher);
189
+ /** ← `JSG_READONLY_INSTANCE_PROPERTY(id, getId)`. */
190
+ getId(): DurableObjectId;
191
+ /** ← `JSG_READONLY_INSTANCE_PROPERTY(name, getName)`. */
192
+ getName(): string | undefined;
193
+ /** The `Fetcher` upstream inherits from rather than holds. */
194
+ getFetcher(): Fetcher;
195
+ }
196
+ /**
197
+ * ← `js.alloc<DurableObject>(...)` plus `JSG_INHERIT(Fetcher)` plus the
198
+ * `JSG_TS_OVERRIDE` that renames the resource type to `DurableObjectStub`.
199
+ *
200
+ * The named assertion is the same one `io/worker.ts`'s `asFacetStub` makes and
201
+ * for the same reason: `DurableObjectStub<T>` is `Fetcher<T, …> & { id, name }`,
202
+ * and `Fetcher<T>` for an unresolved `T` is `Rpc.Provider<T, …>`, a conditional
203
+ * type TypeScript defers until `T` is known — where `T` is the caller's claim
204
+ * about a class it named, which no value can confirm. Upstream is in the same
205
+ * position and answers it the same way, with the parameter living only inside a
206
+ * `JSG_TS_OVERRIDE`.
207
+ *
208
+ * The `Proxy` is what JSG inheritance costs in JS. Two properties have to answer
209
+ * from the id and every other property — `fetch`, `connect`, and every RPC method
210
+ * name, which are the whole point of a stub — has to reach the transport with
211
+ * `this` still bound to it. Bound methods are memoised so `stub.foo === stub.foo`,
212
+ * which upstream gets for free by there being one object rather than two.
213
+ */
214
+ export declare function asDurableObjectStub<T extends Rpc.DurableObjectBranded | undefined>(object: DurableObject): DurableObjectStub<T>;
215
+ /** ← `DurableObjectNamespace::NewUniqueIdOptions` (`actor.h:166-177`). */
216
+ export type NewUniqueIdOptions = {
217
+ /** "Restricts the new unique ID to a set of colos within a jurisdiction." */
218
+ readonly jurisdiction?: string | null;
219
+ };
220
+ /** ← `DurableObjectNamespace::GetDurableObjectOptions` (`actor.h:193-234`). */
221
+ export type GetDurableObjectOptions = {
222
+ readonly locationHint?: string;
223
+ /**
224
+ * "`routingMode` may be be of interest to applications using Durable Objects
225
+ * replicas. It can be one of the following options: none: the default,
226
+ * indicates we will pick for the application. 'primary-only': guarantees we
227
+ * route directly to the primary (skip any replicas)."
228
+ */
229
+ readonly routingMode?: string;
230
+ readonly version?: {
231
+ readonly cohort?: string;
232
+ };
233
+ };
234
+ /**
235
+ * ← `DurableObjectNamespace` (`actor.h:142-291`). "Global durable object class
236
+ * binding type."
237
+ */
238
+ export declare class DurableObjectNamespace<T extends Rpc.DurableObjectBranded | undefined = undefined> implements globalThis.DurableObjectNamespace<T> {
239
+ #private;
240
+ constructor(channel: ActorChannelFactory, idFactory: ActorIdFactory);
241
+ /**
242
+ * "Create a new unique ID for a durable object that will be allocated nearby
243
+ * the calling colo."
244
+ */
245
+ newUniqueId(options?: NewUniqueIdOptions): DurableObjectId;
246
+ /**
247
+ * "Create a name-derived ID. Passing in the same `name` (to the same class)
248
+ * will always produce the same ID."
249
+ */
250
+ idFromName(name: string): DurableObjectId;
251
+ /**
252
+ * "Create a DurableObjectId from the stringified form of the ID (as produced by
253
+ * calling `toString()` on a durable object ID). Throws if the ID is not a
254
+ * 64-digit hex number, or if the ID was not originally created for this class."
255
+ */
256
+ idFromString(id: string): DurableObjectId;
257
+ /** "Gets a durable object by ID or creates it if it doesn't already exist." */
258
+ get(id: globalThis.DurableObjectId, options?: GetDurableObjectOptions): DurableObjectStub<T>;
259
+ /**
260
+ * "Gets a durable object by name or creates it if it doesn't already exist.
261
+ * Short for `idFromName()` followed by `get()`."
262
+ */
263
+ getByName(name: string, options?: GetDurableObjectOptions): DurableObjectStub<T>;
264
+ /**
265
+ * "Experimental. Gets a durable object by ID if it already exists. Currently,
266
+ * gated for use by cloudflare only."
267
+ *
268
+ * Upstream exposes it only when the `durableObjectGetExisting` compat flag is
269
+ * on, and `@cloudflare/workers-types` 4.20260702.1 does not declare it. It is
270
+ * exposed unconditionally here, which is the current-behaviour reading every
271
+ * other compat flag in this file gets.
272
+ */
273
+ getExisting(id: globalThis.DurableObjectId, options?: GetDurableObjectOptions): DurableObjectStub<T>;
274
+ /**
275
+ * "Creates a subnamespace with the jurisdiction hardcoded."
276
+ *
277
+ * The argument is optional because upstream's is a
278
+ * `jsg::Optional<kj::Maybe<kj::String>>`, so both "omitted" and "null" mean the
279
+ * same thing — `cloneWithJurisdiction(kj::none)`, a subnamespace with none.
280
+ */
281
+ jurisdiction(jurisdiction?: string | null): DurableObjectNamespace<T>;
282
+ }
283
+ /**
284
+ * ← `DurableObjectClass` (`actor.h:367-393`). "DurableObjectClass represents a
285
+ * binding to a Durable Object class that can be used as a facet. The only use of
286
+ * this type is to pass to `ctx.facets.get()`."
287
+ *
288
+ * `getChannel()` takes no `IoContext` because the parameter existed to resolve the
289
+ * numbered-channel arm, and there is no numbered-channel arm here.
290
+ */
291
+ export declare class DurableObjectClass<_T extends Rpc.DurableObjectBranded | undefined = undefined> implements globalThis.DurableObjectClass<_T> {
292
+ #private;
293
+ constructor(channel: ActorClassChannel);
294
+ /** ← `DurableObjectClass::getChannel` (`actor.c++:232-242`). */
295
+ getChannel(): ActorClassChannel;
296
+ /**
297
+ * ← `DurableObjectClass::serialize` (`actor.c++:244-306`). Substrate boundary.
298
+ *
299
+ * `requireAllowsTransfer()` runs first, exactly as upstream's does, so a class
300
+ * that refuses transfer reports that rather than the boundary — the refusal is
301
+ * the more specific answer and it is the one upstream would give too.
302
+ */
303
+ serialize(): never;
304
+ /** ← `DurableObjectClass::deserialize` (`actor.c++:308-359`). Substrate boundary. */
305
+ static deserialize(): never;
306
+ }
@@ -0,0 +1,259 @@
1
+ /**
2
+ * ← workerd `src/cloudflare/workers.ts` — the built-in `cloudflare:workers`
3
+ * module.
4
+ *
5
+ * Upstream's own header explains the file's shape: "C++ built-in modules do not
6
+ * yet support named exports, so we must define this wrapper module that simply
7
+ * re-exports the classes from the built-in module." The classes come from
8
+ * `cloudflare-internal:workers` (`src/cloudflare/internal/workers.d.ts`); the
9
+ * behaviour this file owns is the two proxies and the three scope functions.
10
+ *
11
+ * **The export surface was re-derived, not inherited.** The extension shim this
12
+ * replaces (`offscreen/worker/host/shims/cloudflare-workers.ts`, 58 lines)
13
+ * documents its surface as the result of grepping `from "cloudflare:workers"`
14
+ * across `vendor/agents/packages/agents/src`. Re-running that grep across all of
15
+ * `vendor/agents` finds six values — `env` (178 imports), `exports` (48),
16
+ * `WorkerEntrypoint` (16), `RpcTarget` (16), `DurableObject` (13),
17
+ * `WorkflowEntrypoint` (3) — and **four types the shim does not have**:
18
+ * `WorkflowEvent` (8), `WorkflowSleepDuration` (4), `WorkflowStep` (3) and
19
+ * `WorkflowStepEvent` (2). `@cloudflare/workers-types` declares only
20
+ * `WorkflowSleepDuration` of those four globally, so the other three are
21
+ * declared here, where the module that exports them lives.
22
+ *
23
+ * Everything else upstream exports is ported too, per the package README's rule
24
+ * that consumer count is not the filter: `RpcStub`, `RpcPromise`, `RpcProperty`,
25
+ * `ServiceStub`, `waitUntil`, `cache`, `tracing` and `abortIsolate`. Each of
26
+ * those is a named throwing boundary, and each throw says which layer owns the
27
+ * thing that is missing rather than that it is missing.
28
+ *
29
+ * **The one thing to know before wiring this in.** `RpcTarget` is declared here,
30
+ * as upstream declares it — capnweb's own documentation says "on Cloudflare
31
+ * Workers, this `RpcTarget` is an alias for the one exported from the
32
+ * `cloudflare:workers` module, so they can be used interchangably." That alias is
33
+ * **unreachable** in capnweb 0.10.0: `let workersModule = globalThis[Symbol("workers-module")]`
34
+ * reads a symbol created fresh inside capnweb's own module and exported nowhere,
35
+ * so it is always `undefined` and capnweb falls back to its private `class {}`.
36
+ * `value instanceof RpcTarget` inside capnweb therefore tests capnweb's class,
37
+ * not this one, which is why today's extension shim re-exports capnweb's. The
38
+ * transport adaptation (`src/transport/`) owns reconciling the two; `api/` may not
39
+ * import a transport library, and inverting the dependency — making the module
40
+ * that defines the base class depend on the library that aliases it — is the
41
+ * layering upstream does not have.
42
+ *
43
+ * Spec: the shim-surface inventory in docs/shim-surface.md and decision 16 in
44
+ * docs/decisions.md.
45
+ */
46
+ /**
47
+ * `entrypoints.waitUntil` reaches `IoContext::current()`, a thread-local this
48
+ * package deliberately does not port — `io/io-context.ts`'s invocation stack
49
+ * replaces it, and it is reachable only from inside a gated slice rather than
50
+ * from module scope.
51
+ */
52
+ export declare const MODULE_WAIT_UNTIL_UNIMPLEMENTED_MESSAGE: string;
53
+ /**
54
+ * Upstream: "In workerd, the handler aborts the process (unless used on a
55
+ * dynamic worker). In the edge runtime it will condemn and terminate the current
56
+ * isolate." There is no isolate to condemn, which is the same absence
57
+ * `DurableObjectState.abort()` records for `js.terminateExecutionNow()`.
58
+ */
59
+ export declare const ABORT_ISOLATE_UNIMPLEMENTED_MESSAGE: string;
60
+ /** The Workers Cache API is an edge facility; `caches` in a browser is a different contract. */
61
+ export declare const CACHE_UNIMPLEMENTED_MESSAGE: string;
62
+ /** The four stub types are the RPC system's, and the RPC system here is the transport adaptation. */
63
+ export declare const RPC_STUB_UNIMPLEMENTED_MESSAGE: string;
64
+ /**
65
+ * Upstream's `exports` proxy defines no `set` trap, so an assignment lands on the
66
+ * empty proxy target and is silently lost — its comment says "This proxy is
67
+ * read-only - mutations are not supported." A silent loss is the failure mode
68
+ * this repository's fail-closed tenet exists to prevent, so it throws instead.
69
+ */
70
+ export declare const EXPORTS_READ_ONLY_MESSAGE: string;
71
+ /**
72
+ * Upstream's scopes are `AsyncContext`-propagated, so an `async` callback keeps
73
+ * its bindings across an await. Decision 8's propagation is not built (and Part 4
74
+ * records that this package needs none), so the scope here is the synchronous
75
+ * call — which is exactly what upstream's `fn: () => unknown` signature describes
76
+ * and nothing more. A callback that returns a thenable would silently read the
77
+ * wrong bindings after its first await, so it is refused: the same guard, for the
78
+ * same reason, that `transactionSync` already applies to its callback.
79
+ */
80
+ export declare const WITH_SCOPE_ASYNC_MESSAGE: string;
81
+ /**
82
+ * ← `export const env: Cloudflare.Env`. `Cloudflare.Env` is generated per project
83
+ * from a `wrangler.jsonc`, and this package has neither, so the value type is the
84
+ * open record the extension shim already used.
85
+ */
86
+ export type Bindings = Record<string, unknown>;
87
+ /**
88
+ * ← the `env` proxy (`workers.ts:41-104`). Upstream's comment, which is the whole
89
+ * reason this is a proxy rather than an object: "Since env is imported as a
90
+ * module-level reference, the object identity cannot be changed. The proxy
91
+ * provides indirection, delegating to different underlying env objects based on
92
+ * async context (see withEnv()). Mutations via this proxy modify the current
93
+ * underlying env object in-place - if you're inside a withEnv() scope, mutations
94
+ * affect the override object, not the base environment."
95
+ */
96
+ export declare const env: Bindings;
97
+ /**
98
+ * ← the `exports` proxy (`workers.ts:109-147`). Same indirection as `env`, minus
99
+ * the mutating traps — with `set` and `defineProperty` throwing where upstream
100
+ * lets them fall through to the dead proxy target.
101
+ */
102
+ export declare const exports: Bindings;
103
+ /** ← `withEnv` (`workers.ts:21-23`). */
104
+ export declare function withEnv(newEnv: unknown, fn: () => unknown): unknown;
105
+ /** ← `withExports` (`workers.ts:25-27`). */
106
+ export declare function withExports(newExports: unknown, fn: () => unknown): unknown;
107
+ /** ← `withEnvAndExports` (`workers.ts:29-34`). */
108
+ export declare function withEnvAndExports(newEnv: unknown, newExports: unknown, fn: () => unknown): unknown;
109
+ /**
110
+ * ← `RpcTarget` (`cloudflare/internal/workers.d.ts`: `export class RpcTarget {}`).
111
+ *
112
+ * Upstream's public type declares it `abstract` with one branding member; the
113
+ * implementation declaration has neither, and this follows the implementation so
114
+ * that a marker instance can exist. See this file's header for the identity
115
+ * constraint capnweb imposes on it.
116
+ */
117
+ export declare class RpcTarget {
118
+ }
119
+ /**
120
+ * ← `DurableObject` (`cloudflare/internal/workers.d.ts`; public shape in
121
+ * `@cloudflare/workers-types`).
122
+ *
123
+ * `extends RpcTarget` is this runtime's, not upstream's: workerd's RPC system
124
+ * knows the three entrypoint classes natively through `Rpc.*Branded`, and
125
+ * capnweb recognises only `RpcTarget`. Same observable behaviour — an instance
126
+ * may be passed by reference over RPC — through the mechanism the substrate has.
127
+ *
128
+ * `ctx` and `env` are `protected` because that is what the published types say,
129
+ * and upstream's comment on `WorkerEntrypoint` says why it matters rather than
130
+ * being style: "`protected` fields don't appear in `keyof`s, so can't be accessed
131
+ * over RPC." The extension shim had them public.
132
+ */
133
+ export declare class DurableObject<Env = unknown, Props = unknown> extends RpcTarget {
134
+ protected ctx: DurableObjectState<Props>;
135
+ protected env: Env;
136
+ constructor(ctx: DurableObjectState<Props>, env: Env);
137
+ }
138
+ /** ← `WorkerEntrypoint`. */
139
+ export declare class WorkerEntrypoint<Env = unknown, Props = unknown> extends RpcTarget {
140
+ protected ctx: ExecutionContext<Props>;
141
+ protected env: Env;
142
+ constructor(ctx: ExecutionContext<Props>, env: Env);
143
+ }
144
+ /**
145
+ * ← `WorkflowEntrypoint`.
146
+ *
147
+ * The extension shim threw from the constructor. That throw is dropped: the class
148
+ * is a plain base whose `run` a Workflows binding dispatches, and there is no
149
+ * Workflows binding here — so the absent thing is the binding, which nothing in
150
+ * this package offers, rather than the base class. Constructing one and never
151
+ * dispatching it is what happens today either way, and a constructor that throws
152
+ * would take down module evaluation for a consumer that merely declares a
153
+ * subclass.
154
+ */
155
+ export declare class WorkflowEntrypoint<Env = unknown, T = unknown> extends RpcTarget {
156
+ protected ctx: ExecutionContext;
157
+ protected env: Env;
158
+ constructor(ctx: ExecutionContext, env: Env);
159
+ run(_event: Readonly<WorkflowEvent<T>>, _step: WorkflowStep): Promise<unknown>;
160
+ }
161
+ /** ← `RpcStub`. */
162
+ export declare class RpcStub {
163
+ constructor(_server: object);
164
+ }
165
+ /** ← `RpcPromise`. */
166
+ export declare class RpcPromise {
167
+ constructor();
168
+ }
169
+ /** ← `RpcProperty`. */
170
+ export declare class RpcProperty {
171
+ constructor();
172
+ }
173
+ /** ← `ServiceStub`. */
174
+ export declare class ServiceStub {
175
+ constructor();
176
+ }
177
+ /** ← `export const waitUntil = entrypoints.waitUntil.bind(entrypoints)`. */
178
+ export declare function waitUntil(_promise: Promise<unknown>): never;
179
+ /** ← `abortIsolate` (`workers.ts:206-215`). */
180
+ export declare function abortIsolate(_reason?: string): never;
181
+ export declare const cache: CacheContext;
182
+ export declare const tracing: Tracing;
183
+ /**
184
+ * `@cloudflare/workers-types` also declares these two globally, and this module
185
+ * declares its own for the reason upstream's module does: `export type {}` needs
186
+ * a local declaration, and the module is where the names belong.
187
+ */
188
+ export type WorkflowDurationLabel = "second" | "minute" | "hour" | "day" | "week" | "month" | "year";
189
+ export type WorkflowSleepDuration = `${number} ${WorkflowDurationLabel}${"s" | ""}` | number;
190
+ export type WorkflowRetentionDuration = WorkflowSleepDuration;
191
+ export type WorkflowDelayDuration = WorkflowSleepDuration;
192
+ export type WorkflowTimeoutDuration = WorkflowSleepDuration;
193
+ export type WorkflowBackoff = "constant" | "linear" | "exponential";
194
+ export type WorkflowStepSensitivity = "output";
195
+ export type WorkflowStepConfig = {
196
+ retries?: {
197
+ limit: number;
198
+ delay: WorkflowDelayDuration | number;
199
+ backoff?: WorkflowBackoff;
200
+ };
201
+ timeout?: WorkflowTimeoutDuration | number;
202
+ sensitive?: WorkflowStepSensitivity;
203
+ };
204
+ export type WorkflowStepRollbackConfig = Pick<WorkflowStepConfig, "retries" | "timeout">;
205
+ export type WorkflowCronSchedule = {
206
+ /** Cron expression that triggered this event. */
207
+ cron: string;
208
+ /** Timestamp of the scheduled trigger, in milliseconds since the Unix epoch. */
209
+ scheduledTime: number;
210
+ };
211
+ export type WorkflowEvent<T> = {
212
+ payload: Readonly<T>;
213
+ timestamp: Date;
214
+ instanceId: string;
215
+ workflowName: string;
216
+ schedule?: WorkflowCronSchedule;
217
+ };
218
+ export type WorkflowStepEvent<T> = {
219
+ payload: Readonly<T>;
220
+ timestamp: Date;
221
+ type: string;
222
+ sensitive?: WorkflowStepSensitivity;
223
+ };
224
+ export type WorkflowStepContext = {
225
+ step: {
226
+ name: string;
227
+ count: number;
228
+ };
229
+ attempt: number;
230
+ config: WorkflowStepConfig;
231
+ };
232
+ export type WorkflowRollbackContext<T = unknown> = {
233
+ ctx: WorkflowStepContext;
234
+ error: Error;
235
+ output: T | undefined;
236
+ /** @deprecated Use `ctx.step.name` and `ctx.step.count` instead. */
237
+ stepName: string;
238
+ };
239
+ export type WorkflowRollbackHandler<T = unknown> = (ctx: WorkflowRollbackContext<T>) => Promise<void>;
240
+ export type WorkflowStepRollbackOptions<T = unknown> = {
241
+ rollback: WorkflowRollbackHandler<T>;
242
+ rollbackConfig?: WorkflowStepRollbackConfig;
243
+ };
244
+ /**
245
+ * ← `WorkflowStep`, an abstract class in the module declaration. Declared and
246
+ * never implemented here for the same reason `WorkflowEntrypoint.run` throws: a
247
+ * `WorkflowStep` is handed to `run()` by a Workflows binding, and there is none.
248
+ */
249
+ export declare abstract class WorkflowStep {
250
+ do<T>(name: string, callback: (ctx: WorkflowStepContext) => Promise<T>, rollbackOptions?: WorkflowStepRollbackOptions<T>): Promise<T>;
251
+ do<T>(name: string, config: WorkflowStepConfig, callback: (ctx: WorkflowStepContext) => Promise<T>, rollbackOptions?: WorkflowStepRollbackOptions<T>): Promise<T>;
252
+ sleep: (name: string, duration: WorkflowSleepDuration) => Promise<void>;
253
+ sleepUntil: (name: string, timestamp: Date | number) => Promise<void>;
254
+ waitForEvent<T>(name: string, options: {
255
+ type: string;
256
+ timeout?: WorkflowTimeoutDuration | number;
257
+ }): Promise<WorkflowStepEvent<T>>;
258
+ }
259
+ export type WorkflowInstanceStatus = "queued" | "running" | "paused" | "errored" | "terminated" | "complete" | "waiting" | "waitingForPause" | "unknown";