effect-cf 0.40.0 → 0.40.2

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 (166) hide show
  1. package/CHANGELOG.md +14 -0
  2. package/README.md +2 -0
  3. package/dist/AiGateway.d.mts +86 -0
  4. package/dist/AiGateway.mjs +178 -0
  5. package/dist/AnalyticsEngine.d.mts +170 -0
  6. package/dist/AnalyticsEngine.mjs +275 -0
  7. package/dist/{Artifacts-B3r3RuTB.d.mts → Artifacts.d.mts} +8 -5
  8. package/dist/{Artifacts-CBxWGeZB.mjs → Artifacts.mjs} +9 -5
  9. package/dist/Binding.d.mts +45 -0
  10. package/dist/{Binding-C82jRhdr.mjs → Binding.mjs} +8 -4
  11. package/dist/BrowserRendering.d.mts +85 -0
  12. package/dist/BrowserRendering.mjs +81 -0
  13. package/dist/Cache.d.mts +40 -0
  14. package/dist/Cache.mjs +51 -0
  15. package/dist/CloudflareOtlp.d.mts +95 -0
  16. package/dist/CloudflareOtlp.mjs +125 -0
  17. package/dist/CloudflareTracer.d.mts +20 -0
  18. package/dist/CloudflareTracer.mjs +69 -0
  19. package/dist/ComputerArtifacts.d.mts +2 -2
  20. package/dist/ComputerArtifacts.mjs +3 -2
  21. package/dist/ComputerWorkspace.d.mts +36 -31
  22. package/dist/ComputerWorkspace.mjs +8 -3
  23. package/dist/ComputerWorkspaceHost.d.mts +1 -1
  24. package/dist/ComputerWorkspaceHost.mjs +1 -1
  25. package/dist/{ContainerNamespace-DbLaeFhN.d.mts → ContainerNamespace.d.mts} +16 -12
  26. package/dist/ContainerNamespace.mjs +165 -0
  27. package/dist/D1.d.mts +33 -0
  28. package/dist/D1.mjs +32 -0
  29. package/dist/DurableObject.d.mts +103 -0
  30. package/dist/DurableObject.mjs +77 -0
  31. package/dist/DurableObjectAlarm.d.mts +187 -0
  32. package/dist/DurableObjectAlarm.mjs +344 -0
  33. package/dist/DurableObjectDefinition.d.mts +87 -0
  34. package/dist/DurableObjectDefinition.mjs +125 -0
  35. package/dist/DurableObjectNamespace.d.mts +154 -0
  36. package/dist/DurableObjectNamespace.mjs +144 -0
  37. package/dist/DurableObjectRpcWebSocket.d.mts +112 -0
  38. package/dist/DurableObjectRpcWebSocket.mjs +547 -0
  39. package/dist/DurableObjectSqlite.d.mts +11 -0
  40. package/dist/DurableObjectSqlite.mjs +16 -0
  41. package/dist/DurableObjectState.d.mts +65 -0
  42. package/dist/DurableObjectState.mjs +47 -0
  43. package/dist/DurableObjectStorage.d.mts +112 -0
  44. package/dist/{DurableObjectState-DLL0YgBd.mjs → DurableObjectStorage.mjs} +19 -157
  45. package/dist/DurableObjectWebSocket.d.mts +83 -0
  46. package/dist/DurableObjectWebSocket.mjs +120 -0
  47. package/dist/Email.d.mts +106 -0
  48. package/dist/Email.mjs +247 -0
  49. package/dist/Environment.d.mts +59 -0
  50. package/dist/{ErrorMessage-Byx2OgNd.mjs → Environment.mjs} +7 -18
  51. package/dist/{Hyperdrive-HrwFlZ6x.d.mts → Hyperdrive.d.mts} +8 -5
  52. package/dist/Hyperdrive.mjs +32 -0
  53. package/dist/HyperdrivePg.d.mts +4 -3
  54. package/dist/HyperdrivePg.mjs +3 -1
  55. package/dist/Images.d.mts +191 -0
  56. package/dist/Images.mjs +112 -0
  57. package/dist/Kv.d.mts +84 -0
  58. package/dist/Kv.mjs +132 -0
  59. package/dist/Mcp.d.mts +5 -3
  60. package/dist/Mcp.mjs +13 -4
  61. package/dist/Queue.d.mts +64 -0
  62. package/dist/Queue.mjs +52 -0
  63. package/dist/QueueBinding.d.mts +42 -0
  64. package/dist/QueueBinding.mjs +69 -0
  65. package/dist/QueueDefinition.d.mts +48 -0
  66. package/dist/QueueDefinition.mjs +63 -0
  67. package/dist/R2.d.mts +89 -0
  68. package/dist/R2.mjs +117 -0
  69. package/dist/Rpc.d.mts +29 -0
  70. package/dist/Rpc.mjs +28 -0
  71. package/dist/RpcDefinition.d.mts +116 -0
  72. package/dist/RpcDefinition.mjs +184 -0
  73. package/dist/RpcTracing.d.mts +52 -0
  74. package/dist/RpcTracing.mjs +77 -0
  75. package/dist/Sandbox.d.mts +10 -5
  76. package/dist/Sandbox.mjs +9 -3
  77. package/dist/ServiceBinding.d.mts +112 -0
  78. package/dist/ServiceBinding.mjs +145 -0
  79. package/dist/Vectorize.d.mts +68 -0
  80. package/dist/Vectorize.mjs +76 -0
  81. package/dist/Vitest.d.mts +6 -4
  82. package/dist/Vitest.mjs +8 -4
  83. package/dist/WebTransport.d.mts +66 -0
  84. package/dist/WebTransport.mjs +63 -0
  85. package/dist/Worker.d.mts +139 -0
  86. package/dist/Worker.mjs +141 -0
  87. package/dist/WorkerDefinition.d.mts +100 -0
  88. package/dist/WorkerDefinition.mjs +103 -0
  89. package/dist/WorkersAi.d.mts +84 -0
  90. package/dist/WorkersAi.mjs +84 -0
  91. package/dist/Workflow.d.mts +86 -0
  92. package/dist/Workflow.mjs +137 -0
  93. package/dist/{WorkflowBinding-DtVykUCz.d.mts → WorkflowBinding.d.mts} +14 -10
  94. package/dist/WorkflowBinding.mjs +100 -0
  95. package/dist/WorkflowDefinition.d.mts +51 -0
  96. package/dist/WorkflowDefinition.mjs +69 -0
  97. package/dist/{rolldown-runtime-D7D4PA-g.mjs → _virtual/_rolldown/runtime.mjs} +1 -1
  98. package/dist/index.d.mts +40 -1839
  99. package/dist/index.mjs +40 -3161
  100. package/dist/{ComputerWorkspaceHostRegistry-CY5Fv4Ng.mjs → internal/ComputerWorkspaceHostRegistry.mjs} +1 -1
  101. package/dist/internal/Entrypoint.mjs +37 -0
  102. package/dist/internal/ErrorMessage.mjs +17 -0
  103. package/dist/internal/NativeCallback.mjs +33 -0
  104. package/dist/internal/RpcInvocation.d.mts +13 -0
  105. package/dist/internal/RpcInvocation.mjs +34 -0
  106. package/dist/internal/Runtime.mjs +31 -0
  107. package/dist/internal/Telemetry.mjs +20 -0
  108. package/dist/{WorkerContext-Yobnfw-K.mjs → internal/WorkerContext.mjs} +4 -31
  109. package/package.json +1 -1
  110. package/src/AiGateway.ts +5 -1
  111. package/src/AnalyticsEngine.ts +14 -19
  112. package/src/Artifacts.ts +6 -1
  113. package/src/Binding.ts +5 -1
  114. package/src/BrowserRendering.ts +5 -1
  115. package/src/Cache.ts +5 -1
  116. package/src/CloudflareOtlp.ts +12 -10
  117. package/src/CloudflareTracer.ts +7 -1
  118. package/src/ComputerArtifacts.ts +2 -1
  119. package/src/ComputerWorkspace.ts +7 -1
  120. package/src/ContainerNamespace.ts +6 -1
  121. package/src/D1.ts +4 -1
  122. package/src/DurableObject.ts +4 -1
  123. package/src/DurableObjectAlarm.ts +10 -12
  124. package/src/DurableObjectDefinition.ts +3 -1
  125. package/src/DurableObjectNamespace.ts +4 -1
  126. package/src/DurableObjectRpcWebSocket.ts +7 -1
  127. package/src/DurableObjectSqlite.ts +2 -1
  128. package/src/DurableObjectState.ts +4 -1
  129. package/src/DurableObjectStorage.ts +11 -13
  130. package/src/DurableObjectWebSocket.ts +5 -1
  131. package/src/Email.ts +5 -1
  132. package/src/Environment.ts +6 -1
  133. package/src/Hyperdrive.ts +4 -1
  134. package/src/HyperdrivePg.ts +3 -1
  135. package/src/Images.ts +7 -1
  136. package/src/Kv.ts +7 -1
  137. package/src/Mcp.ts +13 -13
  138. package/src/Queue.ts +5 -11
  139. package/src/QueueBinding.ts +5 -1
  140. package/src/QueueDefinition.ts +4 -1
  141. package/src/R2.ts +7 -1
  142. package/src/Rpc.ts +4 -1
  143. package/src/RpcDefinition.ts +4 -1
  144. package/src/RpcTracing.ts +9 -1
  145. package/src/Sandbox.ts +7 -1
  146. package/src/ServiceBinding.ts +6 -1
  147. package/src/Vectorize.ts +7 -1
  148. package/src/Vitest.ts +5 -1
  149. package/src/WebTransport.ts +6 -1
  150. package/src/Worker.ts +10 -16
  151. package/src/WorkerDefinition.ts +3 -1
  152. package/src/WorkersAi.ts +7 -1
  153. package/src/Workflow.ts +10 -25
  154. package/src/WorkflowBinding.ts +6 -1
  155. package/src/WorkflowDefinition.ts +4 -1
  156. package/src/internal/Entrypoint.ts +3 -1
  157. package/src/internal/ErrorMessage.ts +1 -1
  158. package/src/internal/NativeCallback.ts +3 -1
  159. package/src/internal/RpcInvocation.ts +5 -1
  160. package/src/internal/Runtime.ts +5 -1
  161. package/src/internal/Telemetry.ts +4 -3
  162. package/src/internal/WorkerContext.ts +3 -1
  163. package/dist/Binding-DKcLrQCM.d.mts +0 -94
  164. package/dist/DurableObjectState-DJ0K-zyd.d.mts +0 -244
  165. package/dist/Worker-XsGJsCJX.mjs +0 -885
  166. package/dist/Worker-gV4mDqIs.d.mts +0 -641
@@ -0,0 +1,165 @@
1
+ import { __exportAll } from "./_virtual/_rolldown/runtime.mjs";
2
+ import { layer as layer$1 } from "./Binding.mjs";
3
+ import { causeMessage } from "./internal/ErrorMessage.mjs";
4
+ import * as Context from "effect/Context";
5
+ import * as Data from "effect/Data";
6
+ import * as Effect from "effect/Effect";
7
+ import * as S from "effect/Schema";
8
+ import * as Predicate from "effect/Predicate";
9
+ //#region src/ContainerNamespace.ts
10
+ var ContainerNamespace_exports = /* @__PURE__ */ __exportAll({
11
+ ContainerNamespace: () => ContainerNamespace,
12
+ ContainerOperationError: () => ContainerOperationError,
13
+ ContainerState: () => ContainerState,
14
+ Tag: () => Tag,
15
+ isContainerNamespaceResource: () => isContainerNamespaceResource,
16
+ layer: () => layer,
17
+ make: () => make,
18
+ makeClient: () => makeClient
19
+ });
20
+ const expectedContainerNamespace = "Container namespace binding with getByName()";
21
+ /** Serializable state reported by a Cloudflare Container instance. */
22
+ const ContainerState = S.Union([S.Struct({
23
+ lastChange: S.Finite,
24
+ status: S.Literals([
25
+ "running",
26
+ "stopping",
27
+ "stopped",
28
+ "healthy"
29
+ ])
30
+ }), S.Struct({
31
+ lastChange: S.Finite,
32
+ status: S.Literal("stopped_with_code"),
33
+ exitCode: S.optionalKey(S.Int)
34
+ })]);
35
+ var ContainerOperationError = class extends Data.TaggedError("ContainerOperationError") {
36
+ get message() {
37
+ return `Container ${this.operation} failed for binding "${this.binding}" instance "${this.instance}": ${causeMessage(this.cause)}`;
38
+ }
39
+ };
40
+ const tryContainerPromise = (definition, instance, operation, evaluate) => Effect.tryPromise({
41
+ try: evaluate,
42
+ catch: (cause) => new ContainerOperationError({
43
+ binding: definition.binding,
44
+ instance,
45
+ operation,
46
+ cause
47
+ })
48
+ });
49
+ const makeInstanceClient = (definition, instance, stub) => {
50
+ const spanOptions = (operation) => ({ attributes: {
51
+ binding: definition.binding,
52
+ instance,
53
+ operation
54
+ } });
55
+ const hostListOperation = (operation) => Effect.fn(`ContainerNamespace.${operation}`, spanOptions(operation))(function* (hosts) {
56
+ return yield* tryContainerPromise(definition, instance, operation, () => stub[operation]([...hosts]));
57
+ });
58
+ const hostnameOperation = (operation) => Effect.fn(`ContainerNamespace.${operation}`, spanOptions(operation))(function* (hostname) {
59
+ return yield* tryContainerPromise(definition, instance, operation, () => stub[operation](hostname));
60
+ });
61
+ return {
62
+ rawUnsafe: Effect.succeed(stub),
63
+ state: tryContainerPromise(definition, instance, "state", () => stub.getState()).pipe(Effect.flatMap(S.decodeUnknownEffect(ContainerState)), Effect.mapError((cause) => cause instanceof ContainerOperationError ? cause : new ContainerOperationError({
64
+ binding: definition.binding,
65
+ instance,
66
+ operation: "state",
67
+ cause
68
+ })), Effect.withSpan("ContainerNamespace.state", spanOptions("state"))),
69
+ fetch: Effect.fn("ContainerNamespace.fetch", spanOptions("fetch"))(function* (input, init) {
70
+ return yield* tryContainerPromise(definition, instance, "fetch", () => stub.fetch(input, init));
71
+ }),
72
+ start: Effect.fn("ContainerNamespace.start", spanOptions("start"))(function* (options, waitOptions) {
73
+ return yield* tryContainerPromise(definition, instance, "start", () => stub.start(options, waitOptions));
74
+ }),
75
+ startAndWaitForPorts: Effect.fn("ContainerNamespace.startAndWaitForPorts", spanOptions("startAndWaitForPorts"))(function* (options) {
76
+ return yield* tryContainerPromise(definition, instance, "startAndWaitForPorts", () => stub.startAndWaitForPorts(options));
77
+ }),
78
+ waitForPort: Effect.fn("ContainerNamespace.waitForPort", spanOptions("waitForPort"))(function* (options) {
79
+ return yield* tryContainerPromise(definition, instance, "waitForPort", () => stub.waitForPort(options));
80
+ }),
81
+ stop: Effect.fn("ContainerNamespace.stop", spanOptions("stop"))(function* (signal) {
82
+ return yield* tryContainerPromise(definition, instance, "stop", () => stub.stop(signal));
83
+ }),
84
+ destroy: tryContainerPromise(definition, instance, "destroy", () => stub.destroy()).pipe(Effect.withSpan("ContainerNamespace.destroy", spanOptions("destroy"))),
85
+ setAllowedHosts: hostListOperation("setAllowedHosts"),
86
+ setDeniedHosts: hostListOperation("setDeniedHosts"),
87
+ allowHost: hostnameOperation("allowHost"),
88
+ denyHost: hostnameOperation("denyHost"),
89
+ removeAllowedHost: hostnameOperation("removeAllowedHost"),
90
+ removeDeniedHost: hostnameOperation("removeDeniedHost")
91
+ };
92
+ };
93
+ const isContainerNamespaceResource = (value) => Predicate.hasProperty(value, "getByName") && Predicate.isFunction(value.getByName);
94
+ const makeClient = (definition) => (namespace) => {
95
+ const getByName = (name, options) => Effect.try({
96
+ try: () => makeInstanceClient(definition, name, namespace.getByName(name, options)),
97
+ catch: (cause) => new ContainerOperationError({
98
+ binding: definition.binding,
99
+ instance: name,
100
+ operation: "getByName",
101
+ cause
102
+ })
103
+ });
104
+ const byName = (name, options) => {
105
+ const instance = getByName(name, options);
106
+ return {
107
+ rawUnsafe: Effect.flatMap(instance, (client) => client.rawUnsafe),
108
+ state: Effect.flatMap(instance, (client) => client.state),
109
+ fetch: (input, init) => Effect.flatMap(instance, (client) => client.fetch(input, init)),
110
+ start: (startOptions, waitOptions) => Effect.flatMap(instance, (client) => client.start(startOptions, waitOptions)),
111
+ startAndWaitForPorts: (startOptions) => Effect.flatMap(instance, (client) => client.startAndWaitForPorts(startOptions)),
112
+ waitForPort: (waitOptions) => Effect.flatMap(instance, (client) => client.waitForPort(waitOptions)),
113
+ stop: (signal) => Effect.flatMap(instance, (client) => client.stop(signal)),
114
+ destroy: Effect.flatMap(instance, (client) => client.destroy),
115
+ setAllowedHosts: (hosts) => Effect.flatMap(instance, (client) => client.setAllowedHosts(hosts)),
116
+ setDeniedHosts: (hosts) => Effect.flatMap(instance, (client) => client.setDeniedHosts(hosts)),
117
+ allowHost: (hostname) => Effect.flatMap(instance, (client) => client.allowHost(hostname)),
118
+ denyHost: (hostname) => Effect.flatMap(instance, (client) => client.denyHost(hostname)),
119
+ removeAllowedHost: (hostname) => Effect.flatMap(instance, (client) => client.removeAllowedHost(hostname)),
120
+ removeDeniedHost: (hostname) => Effect.flatMap(instance, (client) => client.removeDeniedHost(hostname))
121
+ };
122
+ };
123
+ return {
124
+ definition,
125
+ getByName,
126
+ byName,
127
+ rawUnsafe: Effect.succeed(namespace)
128
+ };
129
+ };
130
+ const layer = (tag, definition) => layer$1(tag, definition.binding, (value) => isContainerNamespaceResource(value), makeClient(definition), { expected: expectedContainerNamespace });
131
+ const make = (id) => Tag()(id);
132
+ const Tag = () => (id) => {
133
+ const tag = Context.Service()(`effect-cf/Container/${id}`);
134
+ const makeLayer = (definition) => layer(tag, definition);
135
+ const getByName = Effect.fnUntraced(function* (name, options) {
136
+ return yield* (yield* tag).getByName(name, options);
137
+ });
138
+ const byName = (name, options) => ({
139
+ state: Effect.flatMap(getByName(name, options), (instance) => instance.state),
140
+ fetch: (input, init) => Effect.flatMap(getByName(name, options), (instance) => instance.fetch(input, init)),
141
+ start: (startOptions, waitOptions) => Effect.flatMap(getByName(name, options), (instance) => instance.start(startOptions, waitOptions)),
142
+ startAndWaitForPorts: (startOptions) => Effect.flatMap(getByName(name, options), (instance) => instance.startAndWaitForPorts(startOptions)),
143
+ waitForPort: (waitOptions) => Effect.flatMap(getByName(name, options), (instance) => instance.waitForPort(waitOptions)),
144
+ stop: (signal) => Effect.flatMap(getByName(name, options), (instance) => instance.stop(signal)),
145
+ destroy: Effect.flatMap(getByName(name, options), (instance) => instance.destroy),
146
+ setAllowedHosts: (hosts) => Effect.flatMap(getByName(name, options), (instance) => instance.setAllowedHosts(hosts)),
147
+ setDeniedHosts: (hosts) => Effect.flatMap(getByName(name, options), (instance) => instance.setDeniedHosts(hosts)),
148
+ allowHost: (hostname) => Effect.flatMap(getByName(name, options), (instance) => instance.allowHost(hostname)),
149
+ denyHost: (hostname) => Effect.flatMap(getByName(name, options), (instance) => instance.denyHost(hostname)),
150
+ removeAllowedHost: (hostname) => Effect.flatMap(getByName(name, options), (instance) => instance.removeAllowedHost(hostname)),
151
+ removeDeniedHost: (hostname) => Effect.flatMap(getByName(name, options), (instance) => instance.removeDeniedHost(hostname)),
152
+ rawUnsafe: Effect.flatMap(getByName(name, options), (instance) => instance.rawUnsafe)
153
+ });
154
+ const rawUnsafe = Effect.flatMap(tag, (namespace) => namespace.rawUnsafe);
155
+ return Object.assign(tag, {
156
+ id,
157
+ layer: makeLayer,
158
+ getByName,
159
+ byName,
160
+ rawUnsafe
161
+ });
162
+ };
163
+ const ContainerNamespace = Tag;
164
+ //#endregion
165
+ export { ContainerNamespace, ContainerNamespace_exports, ContainerOperationError, ContainerState, Tag, isContainerNamespaceResource, layer, make, makeClient };
package/dist/D1.d.mts ADDED
@@ -0,0 +1,33 @@
1
+ import { WorkerEnvironment } from "./Environment.mjs";
2
+ import { BindingNotFoundError, BindingService, BindingValidationError } from "./Binding.mjs";
3
+ import * as Layer$1 from "effect/Layer";
4
+ import { D1Client } from "@effect/sql-d1";
5
+ import { Config } from "effect";
6
+ import { SqlClient } from "effect/unstable/sql";
7
+ declare namespace D1_d_exports {
8
+ export { D1Definition, D1Service, D1SqlLayerOptions, Service, TypeId, make };
9
+ }
10
+ declare const TypeId: "~effect-cf/D1";
11
+ type TypeId = typeof TypeId;
12
+ interface D1Definition {
13
+ readonly binding: string;
14
+ }
15
+ type D1SqlLayerOptions = Omit<D1Client.D1ClientConfig, "db">;
16
+ declare const D1ServiceTypeId: unique symbol;
17
+ interface D1Service<Id extends string> {
18
+ readonly [D1ServiceTypeId]: {
19
+ readonly id: Id;
20
+ };
21
+ }
22
+ declare const make: <Id extends string>(id: Id, definition: D1Definition) => BindingService<D1Service<Id>, Id, D1Database> & {
23
+ "~effect-cf/D1": "~effect-cf/D1";
24
+ definition: D1Definition;
25
+ sqlLayer: (options?: D1SqlLayerOptions) => Layer$1.Layer<D1Client.D1Client | SqlClient.SqlClient, Config.ConfigError | BindingNotFoundError | BindingValidationError, WorkerEnvironment>;
26
+ };
27
+ declare const Service: <Self>() => <Id extends string>(id: Id, definition: D1Definition) => BindingService<Self, Id, D1Database> & {
28
+ "~effect-cf/D1": "~effect-cf/D1";
29
+ definition: D1Definition;
30
+ sqlLayer: (options?: D1SqlLayerOptions) => Layer$1.Layer<D1Client.D1Client | SqlClient.SqlClient, Config.ConfigError | BindingNotFoundError | BindingValidationError, WorkerEnvironment>;
31
+ };
32
+ //#endregion
33
+ export { D1Definition, D1Service, D1SqlLayerOptions, D1_d_exports, Service, TypeId, make };
package/dist/D1.mjs ADDED
@@ -0,0 +1,32 @@
1
+ import { __exportAll } from "./_virtual/_rolldown/runtime.mjs";
2
+ import { Service as Service$1 } from "./Binding.mjs";
3
+ import * as Effect from "effect/Effect";
4
+ import * as Layer from "effect/Layer";
5
+ import * as Predicate from "effect/Predicate";
6
+ import { D1Client } from "@effect/sql-d1";
7
+ //#region src/D1.ts
8
+ var D1_exports = /* @__PURE__ */ __exportAll({
9
+ Service: () => Service,
10
+ make: () => make
11
+ });
12
+ const TypeId = "~effect-cf/D1";
13
+ const expectedD1Database = "D1 database binding with prepare(), batch(), and exec()";
14
+ const isD1Database = (value) => Predicate.hasProperty(value, "prepare") && Predicate.isFunction(value.prepare) && Predicate.hasProperty(value, "batch") && Predicate.isFunction(value.batch) && Predicate.hasProperty(value, "exec") && Predicate.isFunction(value.exec);
15
+ const make = (id, definition) => Service()(id, definition);
16
+ const Service = () => (id, definition) => {
17
+ const tag = Service$1()(id, definition.binding, isD1Database, void 0, { expected: expectedD1Database });
18
+ const sqlLayer = (options) => Layer.unwrap(Effect.gen(function* () {
19
+ const db = yield* tag;
20
+ return D1Client.layer({
21
+ ...options,
22
+ db
23
+ });
24
+ })).pipe(Layer.provide(tag.layer));
25
+ return Object.assign(tag, {
26
+ [TypeId]: TypeId,
27
+ definition,
28
+ sqlLayer
29
+ });
30
+ };
31
+ //#endregion
32
+ export { D1_exports, Service, make };
@@ -0,0 +1,103 @@
1
+ import { WorkerEnv, WorkerEnvironment } from "./Environment.mjs";
2
+ import { DurableWebSocket } from "./DurableObjectWebSocket.mjs";
3
+ import { ReceiverOptions, RpcInvocationInfo } from "./RpcTracing.mjs";
4
+ import { NativeRequest } from "./Worker.mjs";
5
+ import { DurableObjectState } from "./DurableObjectState.mjs";
6
+ import { AlarmRegistration, AlarmService, DurableObjectAlarm } from "./DurableObjectAlarm.mjs";
7
+ import { Api, Definition, HandlerEffect, Handlers, LayerOptions, Method, Methods, NoReservedMethods, Options, ReservedMethodName, ServerApi, ServiceFreeSchema, Tag, TagClass, implement, method } from "./DurableObjectDefinition.mjs";
8
+ import * as Effect from "effect/Effect";
9
+ import * as Layer$1 from "effect/Layer";
10
+ import { DurableObject } from "cloudflare:workers";
11
+ import { Scope } from "effect";
12
+ declare namespace DurableObject_d_exports {
13
+ export { Api, Definition, DurableObjectClass, DurableObjectHandler, DurableObjectOptions, DurableObjectRpc, DurableObjectRpcApi, DurableObjectRpcApi as DurableObjectRpcShape, HandlerEffect, Handlers, LayerOptions, Method, Methods, NoReservedMethods, Options, ReservedMethodName, RpcHandlers, RunOptions, RunSymbol, RuntimeContext, ServerApi, ServiceFreeSchema, Tag, TagClass, implement, make, method };
14
+ }
15
+ type RuntimeContext<ROut> = DurableObjectState | DurableObjectAlarm | WorkerEnvironment | ROut;
16
+ type HandlerContext<ROut> = RuntimeContext<ROut> | Scope.Scope;
17
+ type FetchContext<ROut> = HandlerContext<ROut> | NativeRequest;
18
+ /** Metadata available before an event effect or its event layer starts. */
19
+ interface RunOptions {
20
+ readonly eventLayer?: boolean;
21
+ readonly event?: "fetch" | "rpc" | "alarm" | "webSocketMessage" | "webSocketClose" | "webSocketError";
22
+ readonly rpc?: RpcInvocationInfo;
23
+ }
24
+ /** Override to instrument the whole event, then call super[RunSymbol]. */
25
+ declare const RunSymbol: unique symbol;
26
+ /**
27
+ * Effect type for Durable Object lifecycle and RPC handlers.
28
+ */
29
+ type DurableObjectHandler<ROut, A = unknown> = Effect.Effect<A, unknown, HandlerContext<ROut>>;
30
+ /**
31
+ * Shape of Durable Object RPC handlers passed to {@link make}.
32
+ */
33
+ type DurableObjectRpc<ROut> = Record<string, (...args: Array<any>) => DurableObjectHandler<ROut>>;
34
+ type DurableObjectRpcApi<Rpc extends DurableObjectRpc<ROut>, ROut> = { readonly [Key in keyof Rpc]: Rpc[Key] extends ((...args: infer Args) => Effect.Effect<infer A, unknown, HandlerContext<ROut>>) ? (...args: Args) => Promise<A> : never; };
35
+ type RpcHandlers<ROut, Api> = { readonly [Key in keyof Api as Key extends keyof DurableObject<WorkerEnv> ? never : Key extends string ? [Api[Key]] extends [never] ? never : Api[Key] extends ((...args: Array<any>) => Promise<any>) ? Key : never : never]: Api[Key] extends ((...args: infer Args) => Promise<infer A>) ? (...args: Args) => DurableObjectHandler<ROut, A> : never; };
36
+ interface DurableObjectOptionsBase<RRuntime, REvent = never, EventLayerError = never, Rpc extends DurableObjectRpc<RRuntime | REvent | RAlarm> = Record<never, never>, RAlarm = never> {
37
+ /**
38
+ * Layer provided around each Cloudflare event handled by this Durable Object.
39
+ *
40
+ * The layer is built inside the event's Effect scope and finalized when the
41
+ * event effect completes. It is not applied to `initialize`, which is an
42
+ * instance-load lifecycle hook rather than a platform event.
43
+ */
44
+ readonly eventLayer?: Layer$1.Layer<REvent, EventLayerError, RuntimeContext<NoInfer<RRuntime | RAlarm>>>;
45
+ /**
46
+ * Effect run when Cloudflare loads this Durable Object instance into memory.
47
+ *
48
+ * Use `DurableObjectState.blockConcurrencyWhile` inside this hook when
49
+ * incoming events should wait for setup to finish. Cloudflare may construct
50
+ * the same Durable Object id again after eviction or restart; use Durable
51
+ * Object storage if work must happen only once per id.
52
+ */
53
+ readonly initialize?: Effect.Effect<void, unknown, HandlerContext<NoInfer<RRuntime | RAlarm>>>;
54
+ /**
55
+ * Optional RPC methods exposed as Durable Object instance methods.
56
+ *
57
+ * After every invocation, the configured OTLP flusher is scheduled through
58
+ * `DurableObjectState.waitUntil`, including when the handler fails. The
59
+ * scheduled flush silently settles within two seconds even if the exporter
60
+ * does not.
61
+ */
62
+ readonly rpc?: Rpc;
63
+ /** Accept live native trace metadata. The client must also enable rpcTracing. */
64
+ readonly rpcTracing?: ReceiverOptions;
65
+ readonly fetch?: Effect.Effect<Response, unknown, FetchContext<NoInfer<RRuntime | REvent | RAlarm>>>;
66
+ /** Register handlers to provide their typed scheduler to application layers and all DO events. */
67
+ readonly alarms?: Effect.Effect<unknown, unknown, HandlerContext<NoInfer<RRuntime> | REvent | NoInfer<RAlarm>>> | AlarmRegistration<RAlarm, HandlerContext<NoInfer<RRuntime> | REvent | NoInfer<RAlarm>>, unknown>;
68
+ /**
69
+ * Optional raw alarm handler.
70
+ *
71
+ * After every invocation, the configured OTLP flusher is scheduled through
72
+ * `DurableObjectState.waitUntil`, including when the handler fails. The
73
+ * scheduled flush silently settles within two seconds even if the exporter
74
+ * does not.
75
+ */
76
+ readonly alarm?: (alarmInfo?: globalThis.AlarmInvocationInfo) => Effect.Effect<void, unknown, HandlerContext<NoInfer<RRuntime> | REvent | NoInfer<RAlarm>>>;
77
+ readonly webSocketMessage?: (socket: DurableWebSocket, message: string | ArrayBuffer) => Effect.Effect<void, unknown, HandlerContext<NoInfer<RRuntime> | REvent | NoInfer<RAlarm>>>;
78
+ readonly webSocketClose?: (socket: DurableWebSocket, code: number, reason: string, wasClean: boolean) => Effect.Effect<void, unknown, HandlerContext<NoInfer<RRuntime> | REvent | NoInfer<RAlarm>>>;
79
+ readonly webSocketError?: (socket: DurableWebSocket, cause: unknown) => Effect.Effect<void, unknown, HandlerContext<NoInfer<RRuntime> | REvent | NoInfer<RAlarm>>>;
80
+ }
81
+ type CheckAlarmRegistration<RProvided, RAlarm> = [Exclude<Extract<NoInfer<RProvided>, AlarmService>, NoInfer<RAlarm>>] extends [never] ? unknown : never;
82
+ /** A declared event or alarm service must have its corresponding provider. */
83
+ type DurableObjectOptions<RRuntime, REvent = never, EventLayerError = never, Rpc extends DurableObjectRpc<RRuntime | REvent | RAlarm> = Record<never, never>, RAlarm = never> = DurableObjectOptionsBase<RRuntime, REvent, EventLayerError, Rpc, RAlarm> & CheckAlarmRegistration<RRuntime | REvent, RAlarm> & ([Exclude<REvent, RuntimeContext<RRuntime | RAlarm> | Scope.Scope>] extends [never] ? unknown : {
84
+ readonly eventLayer: Layer$1.Layer<REvent, EventLayerError, RuntimeContext<NoInfer<RRuntime | RAlarm>>>;
85
+ }) & ([RAlarm] extends [never] ? unknown : {
86
+ readonly alarms: AlarmRegistration<RAlarm, HandlerContext<NoInfer<RRuntime> | REvent | NoInfer<RAlarm>>, unknown>;
87
+ });
88
+ /**
89
+ * Cloudflare `DurableObject` constructor produced by {@link make}.
90
+ */
91
+ type DurableObjectClass<Rpc extends DurableObjectRpc<ROut>, ROut> = new (state: globalThis.DurableObjectState, env: WorkerEnv) => DurableObject<WorkerEnv> & DurableObjectRpcApi<Rpc, ROut> & {
92
+ [RunSymbol]<A, E>(effect: Effect.Effect<A, E, HandlerContext<ROut>>, options?: RunOptions): Promise<A>;
93
+ };
94
+ /**
95
+ * Builds a Durable Object whose base `layer` lives for the in-memory instance.
96
+ * Cloudflare does not expose an eviction or shutdown hook, so finalizers in
97
+ * that layer are not guaranteed to run. Put resources that require timely
98
+ * release in `eventLayer`, whose scope closes after each handled event.
99
+ */
100
+ declare function make<ROut, LayerError>(layer: Layer$1.Layer<ROut, LayerError, RuntimeContext<never>> & CheckAlarmRegistration<ROut, never>): DurableObjectClass<Record<never, never>, ROut>;
101
+ declare function make<ROut, LayerError, REvent = never, EventLayerError = never, const Rpc extends DurableObjectRpc<NoInfer<ROut> | REvent | NoInfer<RAlarm>> = Record<never, never>, RAlarm = never>(layer: Layer$1.Layer<ROut, LayerError, RuntimeContext<NoInfer<RAlarm>>>, options: DurableObjectOptions<ROut, REvent, EventLayerError, Rpc, RAlarm>): DurableObjectClass<Rpc, ROut | REvent | RAlarm>;
102
+ //#endregion
103
+ export { type Api, type Definition, DurableObjectClass, DurableObjectHandler, DurableObjectOptions, DurableObjectRpc, DurableObjectRpcApi, type DurableObjectRpcApi as DurableObjectRpcShape, DurableObject_d_exports, type HandlerEffect, type Handlers, type LayerOptions, type Method, type Methods, type NoReservedMethods, type Options, type ReservedMethodName, RpcHandlers, RunOptions, RunSymbol, RuntimeContext, type ServerApi, type ServiceFreeSchema, Tag, type TagClass, implement, make, method };
@@ -0,0 +1,77 @@
1
+ import { __exportAll } from "./_virtual/_rolldown/runtime.mjs";
2
+ import { fromWebSocket } from "./DurableObjectWebSocket.mjs";
3
+ import { DurableObjectState, fromDurableObjectState } from "./DurableObjectState.mjs";
4
+ import { reservedMethodNames as reservedMethodNames$1 } from "./RpcDefinition.mjs";
5
+ import { assumeEntrypointClass, defineEntrypointRpcMethods } from "./internal/Entrypoint.mjs";
6
+ import { makeEntrypointRuntime, runEventPromise } from "./internal/Runtime.mjs";
7
+ import { scheduleTelemetryFlush as scheduleTelemetryFlush$1 } from "./internal/Telemetry.mjs";
8
+ import { NativeRequest } from "./Worker.mjs";
9
+ import { DurableObjectAlarm } from "./DurableObjectAlarm.mjs";
10
+ import { Tag, implement, method } from "./DurableObjectDefinition.mjs";
11
+ import * as Effect from "effect/Effect";
12
+ import * as Layer from "effect/Layer";
13
+ import { DurableObject } from "cloudflare:workers";
14
+ import * as Tracer from "effect/Tracer";
15
+ //#region src/DurableObject.ts
16
+ var DurableObject_exports = /* @__PURE__ */ __exportAll({
17
+ RunSymbol: () => RunSymbol,
18
+ Tag: () => Tag,
19
+ implement: () => implement,
20
+ make: () => make,
21
+ method: () => method
22
+ });
23
+ const reservedMethodNames = reservedMethodNames$1;
24
+ /** Override to instrument the whole event, then call super[RunSymbol]. */
25
+ const RunSymbol = Symbol.for("effect-cf/DurableObject/run");
26
+ const scheduleTelemetryFlush = scheduleTelemetryFlush$1((flush) => Effect.flatMap(DurableObjectState, (state) => state.waitUntil(flush)));
27
+ function make(layer, options = {}) {
28
+ const registration = options.alarms !== void 0 && !Effect.isEffect(options.alarms) ? options.alarms : void 0;
29
+ const logicalAlarms = (registration?.run ?? (Effect.isEffect(options.alarms) ? options.alarms : void 0))?.pipe(Effect.asVoid);
30
+ class EffectDurableObject extends DurableObject {
31
+ runtime;
32
+ constructor(state, env) {
33
+ super(state, env);
34
+ const baseServices = DurableObjectAlarm.layer.pipe(Layer.provideMerge(Layer.succeed(DurableObjectState, fromDurableObjectState(state))));
35
+ const services = (registration?.layer ?? Layer.empty).pipe(Layer.provideMerge(baseServices));
36
+ this.runtime = makeEntrypointRuntime(layer, env, services);
37
+ const initialize = options.initialize;
38
+ if (initialize !== void 0) state.waitUntil(this[RunSymbol](initialize, { eventLayer: false }));
39
+ }
40
+ [RunSymbol](effect, runOptions = {}) {
41
+ const eventLayer = runOptions.eventLayer === false ? void 0 : options.eventLayer;
42
+ const parent = runOptions.rpc?.parent;
43
+ const parentSpan = parent === void 0 ? void 0 : Tracer.externalSpan(parent);
44
+ if (eventLayer === void 0) return runEventPromise(this.runtime, effect, void 0, parentSpan);
45
+ return runEventPromise(this.runtime, effect, eventLayer, parentSpan);
46
+ }
47
+ fetch(request) {
48
+ const fetchHandler = options.fetch;
49
+ if (fetchHandler === void 0) return Promise.resolve(new Response("Not Found", { status: 404 }));
50
+ return this[RunSymbol](Effect.provideService(fetchHandler, NativeRequest, request), { event: "fetch" });
51
+ }
52
+ alarm(alarmInfo) {
53
+ const rawAlarm = options.alarm?.(alarmInfo);
54
+ const alarmEffect = logicalAlarms !== void 0 && rawAlarm !== void 0 ? Effect.gen(function* () {
55
+ yield* logicalAlarms;
56
+ yield* rawAlarm;
57
+ }) : logicalAlarms ?? rawAlarm;
58
+ if (alarmEffect !== void 0) return this[RunSymbol](alarmEffect.pipe(Effect.onExit(() => scheduleTelemetryFlush)), { event: "alarm" });
59
+ }
60
+ webSocketMessage(socket, message) {
61
+ if (options.webSocketMessage !== void 0) return this[RunSymbol](options.webSocketMessage(fromWebSocket(socket), message), { event: "webSocketMessage" });
62
+ }
63
+ webSocketClose(socket, code, reason, wasClean) {
64
+ if (options.webSocketClose !== void 0) return this[RunSymbol](options.webSocketClose(fromWebSocket(socket), code, reason, wasClean), { event: "webSocketClose" });
65
+ }
66
+ webSocketError(socket, cause) {
67
+ if (options.webSocketError !== void 0) return this[RunSymbol](options.webSocketError(fromWebSocket(socket), cause), { event: "webSocketError" });
68
+ }
69
+ }
70
+ defineEntrypointRpcMethods("Durable Object", EffectDurableObject.prototype, options.rpc, reservedMethodNames, (self, effect, rpc) => self[RunSymbol](effect, {
71
+ event: "rpc",
72
+ rpc
73
+ }), () => scheduleTelemetryFlush, options.rpcTracing);
74
+ return assumeEntrypointClass(EffectDurableObject);
75
+ }
76
+ //#endregion
77
+ export { DurableObject_exports, RunSymbol, Tag, implement, make, method };
@@ -0,0 +1,187 @@
1
+ import { StorageOperationError } from "./DurableObjectStorage.mjs";
2
+ import { DurableObjectState } from "./DurableObjectState.mjs";
3
+ import * as Context from "effect/Context";
4
+ import * as Effect from "effect/Effect";
5
+ import * as S from "effect/Schema";
6
+ import * as Layer from "effect/Layer";
7
+ import * as Duration from "effect/Duration";
8
+ import * as DateTime from "effect/DateTime";
9
+ declare namespace DurableObjectAlarm_d_exports {
10
+ export { AlarmDefinitionConfig, AlarmDefinitionEntry, AlarmDefinitionPayload, AlarmDefinitions, AlarmFailurePolicy, AlarmPayload, AlarmPayloadSchema, AlarmRef, AlarmRegistration, AlarmRetryPolicy, AlarmScheduler, AlarmService, AlarmTagClass, AlarmTransaction, DefinedAlarmEvent, DefinedAlarmHandlers, DefinedAlarmScheduler, DefinedAlarmTransaction, DefinedScheduleAlarmInput, DurableObjectAlarm, DurableObjectAlarmError, DurableObjectAlarmEvent, InvalidAlarmPayloadError, InvalidAlarmRefError, InvalidProcessDueAlarmsOptionsError, InvalidRepeatEveryError, ProcessDueAlarmsFailure, ProcessDueAlarmsFailureAction, ProcessDueAlarmsHandler, ProcessDueAlarmsMode, ProcessDueAlarmsOptions, ProcessDueAlarmsResult, ScheduleAlarmInput, StoredAlarmDecodeError, Tag, define, processDue };
11
+ }
12
+ type AlarmPayload = S.Json;
13
+ declare const InvalidAlarmRefError_base: new <A extends Record<string, any> = {}>(args: import("effect/Types").VoidIfEmpty<{ readonly [P in keyof A as P extends "_tag" ? never : P]: A[P]; }>) => import("effect/Cause").YieldableError & {
14
+ readonly _tag: "InvalidAlarmRefError";
15
+ } & Readonly<A>;
16
+ declare class InvalidAlarmRefError extends InvalidAlarmRefError_base<{
17
+ readonly cause: unknown;
18
+ }> {
19
+ get message(): string;
20
+ }
21
+ declare const InvalidAlarmPayloadError_base: new <A extends Record<string, any> = {}>(args: import("effect/Types").VoidIfEmpty<{ readonly [P in keyof A as P extends "_tag" ? never : P]: A[P]; }>) => import("effect/Cause").YieldableError & {
22
+ readonly _tag: "InvalidAlarmPayloadError";
23
+ } & Readonly<A>;
24
+ declare class InvalidAlarmPayloadError extends InvalidAlarmPayloadError_base<{
25
+ readonly cause: unknown;
26
+ }> {
27
+ get message(): string;
28
+ }
29
+ declare const InvalidRepeatEveryError_base: new <A extends Record<string, any> = {}>(args: import("effect/Types").VoidIfEmpty<{ readonly [P in keyof A as P extends "_tag" ? never : P]: A[P]; }>) => import("effect/Cause").YieldableError & {
30
+ readonly _tag: "InvalidRepeatEveryError";
31
+ } & Readonly<A>;
32
+ declare class InvalidRepeatEveryError extends InvalidRepeatEveryError_base<{
33
+ readonly cause: unknown;
34
+ }> {
35
+ get message(): string;
36
+ }
37
+ declare const InvalidProcessDueAlarmsOptionsError_base: new <A extends Record<string, any> = {}>(args: import("effect/Types").VoidIfEmpty<{ readonly [P in keyof A as P extends "_tag" ? never : P]: A[P]; }>) => import("effect/Cause").YieldableError & {
38
+ readonly _tag: "InvalidProcessDueAlarmsOptionsError";
39
+ } & Readonly<A>;
40
+ declare class InvalidProcessDueAlarmsOptionsError extends InvalidProcessDueAlarmsOptionsError_base<{
41
+ readonly cause: unknown;
42
+ }> {
43
+ get message(): string;
44
+ }
45
+ declare const StoredAlarmDecodeError_base: new <A extends Record<string, any> = {}>(args: import("effect/Types").VoidIfEmpty<{ readonly [P in keyof A as P extends "_tag" ? never : P]: A[P]; }>) => import("effect/Cause").YieldableError & {
46
+ readonly _tag: "StoredAlarmDecodeError";
47
+ } & Readonly<A>;
48
+ declare class StoredAlarmDecodeError extends StoredAlarmDecodeError_base<{
49
+ readonly cause: unknown;
50
+ readonly storageId: string;
51
+ }> {
52
+ get message(): string;
53
+ }
54
+ type DurableObjectAlarmError = InvalidAlarmPayloadError | InvalidAlarmRefError | InvalidProcessDueAlarmsOptionsError | InvalidRepeatEveryError | StorageOperationError | StoredAlarmDecodeError;
55
+ declare const DurableObjectAlarmEvent: S.TaggedUnion<{
56
+ readonly AlarmDue: S.TaggedStruct<"AlarmDue", {
57
+ readonly id: S.NonEmptyString;
58
+ readonly payload: S.Codec<S.Json, S.Json, never, never>;
59
+ /** Persisted due time, which can differ from the invocation time during retries. */
60
+ readonly scheduledAt: S.DateTimeUtc;
61
+ readonly tag: S.NonEmptyString;
62
+ }>;
63
+ }>;
64
+ type DurableObjectAlarmEvent = typeof DurableObjectAlarmEvent.Type;
65
+ type AlarmRef<Tag extends string = string> = {
66
+ readonly id: string;
67
+ readonly tag: Tag;
68
+ };
69
+ /** Reusing `{tag, id}` replaces an alarm. Repeats run after success, never as fixed-cadence catch-up. */
70
+ type ScheduleAlarmInput<Tag extends string = string> = AlarmRef<Tag> & {
71
+ readonly payload: AlarmPayload;
72
+ readonly repeatEvery?: Duration.Input;
73
+ readonly runAt: DateTime.Utc;
74
+ };
75
+ type ProcessDueAlarmsMode = "isolated" | "ordered";
76
+ interface ProcessDueAlarmsFailure {
77
+ readonly cause: unknown;
78
+ readonly event?: DurableObjectAlarmEvent;
79
+ readonly id: string;
80
+ readonly storageId: string;
81
+ readonly tag: string;
82
+ }
83
+ interface ProcessDueAlarmsResult {
84
+ readonly failed: readonly ProcessDueAlarmsFailure[];
85
+ readonly handled: readonly DurableObjectAlarmEvent[];
86
+ }
87
+ type ProcessDueAlarmsFailureAction = "ordered" | "retry" | "skip-and-advance-repeat" | {
88
+ readonly mode: "ordered";
89
+ } | {
90
+ readonly mode: "retry";
91
+ readonly retryFailedAfter?: Duration.Input;
92
+ } | {
93
+ readonly mode: "skip-and-advance-repeat";
94
+ };
95
+ interface ProcessDueAlarmsOptions<OnFailureR = never, OnFailureE = never> {
96
+ readonly limit?: number;
97
+ /** `isolated` retries only the failed row; `ordered` stops before later rows. */
98
+ readonly mode?: ProcessDueAlarmsMode;
99
+ readonly onFailure?: (failure: ProcessDueAlarmsFailure) => Effect.Effect<ProcessDueAlarmsFailureAction | void, OnFailureE, OnFailureR>;
100
+ readonly retryFailedAfter?: Duration.Input;
101
+ }
102
+ type ProcessDueAlarmsHandler<R = never, E = never> = (event: DurableObjectAlarmEvent) => Effect.Effect<void, E, R>;
103
+ /**
104
+ * Alarm mutations owned by one transaction callback. Run them in the callback's
105
+ * fiber; forked work and use after the callback ends fail with StorageOperationError.
106
+ */
107
+ type AlarmTransaction = Pick<AlarmScheduler, "scheduleAlarm" | "cancelAlarm">;
108
+ /** Own `storage.setAlarm()` exclusively: a Durable Object has one platform alarm timestamp. */
109
+ type AlarmScheduler = {
110
+ /**
111
+ * Commits local application storage and logical alarms in one native SQLite
112
+ * Durable Object transaction, reconciling the native alarm before commit.
113
+ * Use the supplied mutations, not standalone alarm methods or nested transactions.
114
+ * SqlClient queries must use this same Durable Object's storage.
115
+ *
116
+ * Failure, defects and interruption before commit roll back. A lost reply or
117
+ * interruption after commit does not undo committed state. Keep RPC and other
118
+ * external effects outside; atomically pre-arm a later wake before fallible work.
119
+ * Cloudflare's native retries are bounded; composition does not remove the
120
+ * pre-arm requirement or promise infinite retry liveness.
121
+ */
122
+ readonly transaction: <A, E, R>(closure: (alarms: AlarmTransaction) => Effect.Effect<A, E, R>) => Effect.Effect<A, E | StorageOperationError, R>;
123
+ readonly cancelAlarm: (input: AlarmRef) => Effect.Effect<void, InvalidAlarmRefError | StorageOperationError>;
124
+ /** Acknowledge after handling. Conditional writes preserve handler replacements; alarms are at-least-once. */
125
+ readonly processDueAlarms: <R = never, E = never, OnFailureR = never, OnFailureE = never>(handle: ProcessDueAlarmsHandler<R, E>, options?: ProcessDueAlarmsOptions<OnFailureR, OnFailureE>) => Effect.Effect<ProcessDueAlarmsResult, E | OnFailureE | DurableObjectAlarmError, R | OnFailureR>;
126
+ /** A failed platform setAlarm rolls back the logical schedule in the same transaction. */
127
+ readonly scheduleAlarm: (input: ScheduleAlarmInput) => Effect.Effect<void, InvalidAlarmPayloadError | InvalidAlarmRefError | InvalidRepeatEveryError | StorageOperationError>;
128
+ };
129
+ declare const processDue: <R = never, E = never, OnFailureR = never, OnFailureE = never>(handle: ProcessDueAlarmsHandler<R, E>, options?: ProcessDueAlarmsOptions<OnFailureR, OnFailureE>) => Effect.Effect<ProcessDueAlarmsResult, E | OnFailureE | DurableObjectAlarmError, OnFailureR | R | DurableObjectAlarm>;
130
+ type AlarmPayloadSchema = S.Codec<any, any, never, never>;
131
+ type AlarmFailurePolicy = "ordered" | "retry" | "skip-and-advance-repeat";
132
+ interface AlarmRetryPolicy {
133
+ readonly initialDelay?: Duration.Input;
134
+ }
135
+ interface AlarmDefinitionConfig<Payload extends AlarmPayloadSchema = AlarmPayloadSchema> {
136
+ readonly failure?: AlarmFailurePolicy;
137
+ readonly payload: Payload;
138
+ readonly retry?: AlarmRetryPolicy;
139
+ }
140
+ type AlarmDefinitionEntry = AlarmDefinitionConfig | AlarmPayloadSchema;
141
+ type AlarmDefinitions = Readonly<Record<string, AlarmDefinitionEntry>>;
142
+ type AlarmDefinitionSchema<Definition> = Definition extends AlarmDefinitionConfig<infer Payload> ? Payload : Definition;
143
+ type AlarmDefinitionPayload<Definition> = AlarmDefinitionSchema<Definition> extends S.Codec<infer A, any, never, never> ? A : never;
144
+ type DefinedAlarmEvent<Tag extends string, Payload> = Omit<DurableObjectAlarmEvent, "payload" | "tag"> & {
145
+ readonly payload: Payload;
146
+ readonly tag: Tag;
147
+ };
148
+ type DefinedAlarmHandlers<Definitions extends AlarmDefinitions, R = never, E = never> = { readonly [Tag in keyof Definitions & string]: (event: DefinedAlarmEvent<Tag, AlarmDefinitionPayload<Definitions[Tag]>>) => Effect.Effect<void, E, R>; };
149
+ /** A discriminated union keeps each tag paired with its decoded payload type. */
150
+ type DefinedScheduleAlarmInput<Definitions extends AlarmDefinitions> = { readonly [Tag in keyof Definitions & string]: Omit<ScheduleAlarmInput<Tag>, "payload"> & {
151
+ readonly payload: AlarmDefinitionPayload<Definitions[Tag]>;
152
+ }; }[keyof Definitions & string];
153
+ interface DefinedAlarmTransaction<Definitions extends AlarmDefinitions> {
154
+ readonly scheduleAlarm: (input: DefinedScheduleAlarmInput<Definitions>) => ReturnType<AlarmScheduler["scheduleAlarm"]>;
155
+ readonly cancelAlarm: (input: AlarmRef<keyof Definitions & string>) => ReturnType<AlarmScheduler["cancelAlarm"]>;
156
+ }
157
+ declare const TypedAlarmSchedulerTypeId: unique symbol;
158
+ /** Identifies service requirements whose scheduler needs a registered dispatcher. */
159
+ interface AlarmService {
160
+ readonly Service: {
161
+ readonly [TypedAlarmSchedulerTypeId]: typeof TypedAlarmSchedulerTypeId;
162
+ };
163
+ }
164
+ interface DefinedAlarmScheduler<Definitions extends AlarmDefinitions> extends DefinedAlarmTransaction<Definitions> {
165
+ readonly [TypedAlarmSchedulerTypeId]: typeof TypedAlarmSchedulerTypeId;
166
+ readonly transaction: <A, E, R>(closure: (alarms: DefinedAlarmTransaction<Definitions>) => Effect.Effect<A, E, R>) => Effect.Effect<A, E | StorageOperationError, R>;
167
+ }
168
+ /** Registers a dispatcher and the service authorized to schedule its alarms. */
169
+ interface AlarmRegistration<Self, R = never, E = never> {
170
+ readonly layer: Layer.Layer<Self, never, DurableObjectAlarm>;
171
+ readonly run: Effect.Effect<ProcessDueAlarmsResult, E | DurableObjectAlarmError, R | DurableObjectAlarm>;
172
+ }
173
+ interface AlarmTagClass<Self, Id extends string, Definitions extends AlarmDefinitions> extends Context.ServiceClass<Self, Id, DefinedAlarmScheduler<Definitions>> {
174
+ readonly handlers: <R = never, E = never>(handlers: DefinedAlarmHandlers<Definitions, R, E>, options?: ProcessDueAlarmsOptions<R, E>) => AlarmRegistration<Self, R, E>;
175
+ }
176
+ /** Handler-only definitions for applications using the raw scheduler. Prefer Tag for typed scheduling. */
177
+ declare const define: <const Definitions extends AlarmDefinitions>(definitions: Definitions) => {
178
+ handlers: <R = never, E = never>(handlers: DefinedAlarmHandlers<Definitions, R, E>, options?: ProcessDueAlarmsOptions<R, E> | undefined) => Effect.Effect<ProcessDueAlarmsResult, E | DurableObjectAlarmError, R | DurableObjectAlarm>;
179
+ };
180
+ /** The typed scheduler becomes available when its handlers are registered on a Durable Object. */
181
+ declare const Tag: <Self>() => <const Id extends string, const Definitions extends AlarmDefinitions>(id: Id, definitions: Definitions) => AlarmTagClass<Self, Id, Definitions>;
182
+ declare const DurableObjectAlarm_base: Context.ServiceClass<DurableObjectAlarm, "effect-cf/DurableObjectAlarm", AlarmScheduler>;
183
+ declare class DurableObjectAlarm extends DurableObjectAlarm_base {
184
+ static readonly layer: Layer.Layer<DurableObjectAlarm, never, DurableObjectState>;
185
+ }
186
+ //#endregion
187
+ export { AlarmDefinitionConfig, AlarmDefinitionEntry, AlarmDefinitionPayload, AlarmDefinitions, AlarmFailurePolicy, AlarmPayload, AlarmPayloadSchema, AlarmRef, AlarmRegistration, AlarmRetryPolicy, AlarmScheduler, AlarmService, AlarmTagClass, AlarmTransaction, DefinedAlarmEvent, DefinedAlarmHandlers, DefinedAlarmScheduler, DefinedAlarmTransaction, DefinedScheduleAlarmInput, DurableObjectAlarm, DurableObjectAlarmError, DurableObjectAlarmEvent, DurableObjectAlarm_d_exports, InvalidAlarmPayloadError, InvalidAlarmRefError, InvalidProcessDueAlarmsOptionsError, InvalidRepeatEveryError, ProcessDueAlarmsFailure, ProcessDueAlarmsFailureAction, ProcessDueAlarmsHandler, ProcessDueAlarmsMode, ProcessDueAlarmsOptions, ProcessDueAlarmsResult, ScheduleAlarmInput, StoredAlarmDecodeError, Tag, define, processDue };