effect-cf 0.33.0 → 0.35.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 (74) hide show
  1. package/CHANGELOG.md +22 -0
  2. package/README.md +31 -1079
  3. package/dist/{Artifacts-DnHQA-Ax.d.mts → Artifacts-B3r3RuTB.d.mts} +1 -48
  4. package/dist/{Artifacts-CSIk1Oml.mjs → Artifacts-CBxWGeZB.mjs} +2 -7
  5. package/dist/{Binding-pfilNJmP.mjs → Binding-C82jRhdr.mjs} +1 -2
  6. package/dist/{Binding-xJJJPmiD.d.mts → Binding-DKcLrQCM.d.mts} +0 -45
  7. package/dist/ComputerArtifacts.d.mts +1 -3
  8. package/dist/ComputerArtifacts.mjs +1 -2
  9. package/dist/ComputerWorkspace.d.mts +11 -12
  10. package/dist/ComputerWorkspace.mjs +31 -10
  11. package/dist/ComputerWorkspaceHost.d.mts +1 -9
  12. package/dist/{ContainerNamespace-CFjiLw8b.d.mts → ContainerNamespace-DbLaeFhN.d.mts} +1 -14
  13. package/dist/{DurableObjectState-CVLLse69.mjs → DurableObjectState-DcqElJ4e.mjs} +82 -89
  14. package/dist/{DurableObjectState-BpRjz6-q.d.mts → DurableObjectState-DpYdNZgT.d.mts} +102 -266
  15. package/dist/{ErrorMessage-BM0K-Nik.mjs → ErrorMessage-Byx2OgNd.mjs} +0 -1
  16. package/dist/{Hyperdrive-z-9fFz15.d.mts → Hyperdrive-HrwFlZ6x.d.mts} +1 -4
  17. package/dist/HyperdrivePg.d.mts +2 -11
  18. package/dist/HyperdrivePg.mjs +0 -8
  19. package/dist/Sandbox.d.mts +2 -32
  20. package/dist/Sandbox.mjs +2 -11
  21. package/dist/Vitest.d.mts +3 -31
  22. package/dist/Vitest.mjs +8 -26
  23. package/dist/{WorkflowBinding-lBR4_-op.d.mts → WorkflowBinding-Cn3AuUyP.d.mts} +2 -5
  24. package/dist/index.d.mts +42 -480
  25. package/dist/index.mjs +267 -380
  26. package/package.json +1 -1
  27. package/src/AiGateway.ts +0 -6
  28. package/src/AnalyticsEngine.ts +8 -10
  29. package/src/Artifacts.ts +0 -47
  30. package/src/Binding.ts +0 -8
  31. package/src/BrowserRendering.ts +0 -4
  32. package/src/Cache.ts +0 -19
  33. package/src/CloudflareOtlp.ts +6 -39
  34. package/src/ComputerArtifacts.ts +0 -2
  35. package/src/ComputerWorkspace.ts +53 -35
  36. package/src/ComputerWorkspaceHost.ts +0 -8
  37. package/src/ContainerNamespace.ts +0 -13
  38. package/src/D1.ts +0 -22
  39. package/src/DurableObject.ts +51 -32
  40. package/src/DurableObjectAlarm.ts +6 -210
  41. package/src/DurableObjectDefinition.ts +8 -20
  42. package/src/DurableObjectNamespace.ts +88 -115
  43. package/src/DurableObjectRpcWebSocket.ts +5 -46
  44. package/src/DurableObjectSqlite.ts +0 -12
  45. package/src/DurableObjectState.ts +18 -38
  46. package/src/DurableObjectStorage.ts +55 -70
  47. package/src/DurableObjectWebSocket.ts +23 -72
  48. package/src/Email.ts +0 -12
  49. package/src/Environment.ts +0 -37
  50. package/src/Hyperdrive.ts +0 -3
  51. package/src/HyperdrivePg.ts +0 -9
  52. package/src/Images.ts +0 -5
  53. package/src/Kv.ts +0 -15
  54. package/src/QueueBinding.ts +0 -2
  55. package/src/R2.ts +0 -5
  56. package/src/RpcDefinition.ts +5 -17
  57. package/src/RpcTracing.ts +133 -0
  58. package/src/Sandbox.ts +0 -30
  59. package/src/ServiceBinding.ts +83 -128
  60. package/src/Vectorize.ts +0 -5
  61. package/src/Vitest.ts +18 -43
  62. package/src/WebTransport.ts +0 -15
  63. package/src/Worker.ts +140 -108
  64. package/src/WorkerDefinition.ts +5 -14
  65. package/src/WorkersAi.ts +21 -18
  66. package/src/Workflow.ts +45 -54
  67. package/src/WorkflowBinding.ts +0 -3
  68. package/src/index.ts +1 -0
  69. package/src/internal/Entrypoint.ts +23 -4
  70. package/src/internal/ErrorMessage.ts +0 -1
  71. package/src/internal/NativeCallback.ts +55 -0
  72. package/src/internal/RpcInvocation.ts +18 -1
  73. package/src/internal/Runtime.ts +12 -7
  74. package/src/internal/WorkerContext.ts +5 -14
@@ -1,13 +1,10 @@
1
- import { c as WorkerEnvironment, r as BindingValidationError, t as BindingNotFoundError } from "./Binding-xJJJPmiD.mjs";
1
+ import { c as WorkerEnvironment, r as BindingValidationError, t as BindingNotFoundError } from "./Binding-DKcLrQCM.mjs";
2
2
  import { Context, Effect, Layer, Schema } from "effect";
3
3
  declare namespace ContainerNamespace_d_exports {
4
4
  export { ContainerInstanceClient, ContainerNamespace, ContainerNamespaceClient, ContainerNamespaceDefinition, ContainerNamespaceResource, ContainerNamespaceService, ContainerNamespaceStaticClient, ContainerOperationError, ContainerReadinessOptions, ContainerSignal, ContainerStartAndWaitForPortsOptions, ContainerStartOptions, ContainerState, ContainerStopSignal, ContainerStub, ContainerStubOf, ContainerWaitOptions, LayerOptions, Tag, TagClass, isContainerNamespaceResource, layer, make, makeClient };
5
5
  }
6
- /** Named signal accepted by Cloudflare Container instances. */
7
6
  type ContainerSignal = "SIGKILL" | "SIGINT" | "SIGTERM";
8
- /** Named or numeric signal accepted by Container `stop()`. */
9
7
  type ContainerStopSignal = ContainerSignal | number;
10
- /** Per-instance Container startup configuration. */
11
8
  interface ContainerStartOptions {
12
9
  readonly envVars?: Record<string, string>;
13
10
  readonly entrypoint?: Array<string>;
@@ -26,7 +23,6 @@ interface ContainerReadinessOptions {
26
23
  readonly portReadyTimeoutMS?: number;
27
24
  readonly waitInterval?: number;
28
25
  }
29
- /** Options for starting a Container and waiting for its ports. */
30
26
  interface ContainerStartAndWaitForPortsOptions {
31
27
  readonly startOptions?: ContainerStartOptions;
32
28
  readonly ports?: number | Array<number>;
@@ -63,21 +59,16 @@ interface ContainerStub {
63
59
  removeAllowedHost(hostname: string): Promise<void>;
64
60
  removeDeniedHost(hostname: string): Promise<void>;
65
61
  }
66
- /** Native Container namespace binding shape. */
67
62
  interface ContainerNamespaceResource {
68
63
  getByName(name: string, options?: globalThis.DurableObjectNamespaceGetDurableObjectOptions): ContainerStub;
69
64
  }
70
- /** Exact native stub type produced by a Container namespace binding. */
71
65
  type ContainerStubOf<Namespace extends ContainerNamespaceResource> = ReturnType<Namespace["getByName"]>;
72
- /** Container namespace binding metadata. */
73
66
  interface ContainerNamespaceDefinition {
74
- /** Binding name as configured in `wrangler.jsonc`. */
75
67
  readonly binding: string;
76
68
  }
77
69
  declare const ContainerOperationError_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 & {
78
70
  readonly _tag: "ContainerOperationError";
79
71
  } & Readonly<A>;
80
- /** Failure raised when invoking a named Container operation. */
81
72
  declare class ContainerOperationError extends ContainerOperationError_base<{
82
73
  readonly binding: string;
83
74
  readonly instance: string;
@@ -86,7 +77,6 @@ declare class ContainerOperationError extends ContainerOperationError_base<{
86
77
  }> {
87
78
  get message(): string;
88
79
  }
89
- /** Effect-wrapped client for one named Container instance. */
90
80
  interface ContainerInstanceClient<Stub extends ContainerStub = ContainerStub> {
91
81
  readonly rawUnsafe: Effect.Effect<Stub, ContainerOperationError>;
92
82
  readonly state: Effect.Effect<ContainerState, ContainerOperationError>;
@@ -103,7 +93,6 @@ interface ContainerInstanceClient<Stub extends ContainerStub = ContainerStub> {
103
93
  readonly removeAllowedHost: (hostname: string) => Effect.Effect<void, ContainerOperationError>;
104
94
  readonly removeDeniedHost: (hostname: string) => Effect.Effect<void, ContainerOperationError>;
105
95
  }
106
- /** Effect client for a Container namespace binding. */
107
96
  interface ContainerNamespaceClient<Namespace extends ContainerNamespaceResource = ContainerNamespaceResource> {
108
97
  readonly definition: ContainerNamespaceDefinition;
109
98
  readonly getByName: (name: string, options?: globalThis.DurableObjectNamespaceGetDurableObjectOptions) => Effect.Effect<ContainerInstanceClient<ContainerStubOf<Namespace>>, ContainerOperationError>;
@@ -142,13 +131,11 @@ declare const makeClient: (definition: ContainerNamespaceDefinition) => <Namespa
142
131
  declare const layer: <Self, Namespace extends ContainerNamespaceResource>(tag: Context.Service<Self, ContainerNamespaceClient<Namespace>>, definition: ContainerNamespaceDefinition) => Layer.Layer<Self, BindingNotFoundError | BindingValidationError, WorkerEnvironment>;
143
132
  declare const make: <Id extends string>(id: Id) => TagClass<ContainerNamespaceService<Id>, Id, ContainerNamespaceResource>;
144
133
  declare const ContainerNamespaceServiceTypeId: unique symbol;
145
- /** Nominal service marker for Container namespaces created with {@link make}. */
146
134
  interface ContainerNamespaceService<Id extends string> {
147
135
  readonly [ContainerNamespaceServiceTypeId]: {
148
136
  readonly id: Id;
149
137
  };
150
138
  }
151
- /** Creates a typed Effect service for a Cloudflare Container namespace. */
152
139
  declare const Tag: <Self, Namespace extends ContainerNamespaceResource = ContainerNamespaceResource>() => <Id extends string>(id: Id) => TagClass<Self, Id, Namespace>;
153
140
  declare const ContainerNamespace: typeof Tag;
154
141
  //#endregion
@@ -1,12 +1,40 @@
1
1
  import { t as __exportAll } from "./rolldown-runtime-D7D4PA-g.mjs";
2
- import { t as causeMessage } from "./ErrorMessage-BM0K-Nik.mjs";
3
- import { Cause, Clock, Context, Data, Duration, Effect, Exit, Option, Predicate, Result, Schema } from "effect";
2
+ import { t as causeMessage } from "./ErrorMessage-Byx2OgNd.mjs";
3
+ import { Cause, Clock, Context, Data, Duration, Effect, Exit, Fiber, FiberSet, Option, Predicate, Result, Schema } from "effect";
4
+ //#region src/internal/NativeCallback.ts
5
+ /**
6
+ * Runs an Effect callback owned by a native Promise operation.
7
+ *
8
+ * The callback keeps the caller's context, while a private scope owns its
9
+ * fiber. Closing that scope interrupts and joins the callback before awaiting
10
+ * the native operation's settlement.
11
+ */
12
+ const runNativeCallback = Effect.fnUntraced(function* (operation) {
13
+ const callerContext = yield* Effect.context();
14
+ return yield* Effect.scoped(Effect.gen(function* () {
15
+ let nativePromise;
16
+ yield* Effect.addFinalizer(() => {
17
+ const promise = nativePromise;
18
+ return promise === void 0 ? Effect.void : Effect.promise(() => promise.then(() => void 0, () => void 0));
19
+ });
20
+ const runPromise = yield* FiberSet.makeRuntimePromise();
21
+ return yield* Effect.callback((resume) => {
22
+ try {
23
+ nativePromise = operation((effect) => runPromise(Effect.provideContext(Effect.exit(effect), callerContext)));
24
+ } catch (cause) {
25
+ resume(Effect.fail(cause));
26
+ return;
27
+ }
28
+ nativePromise.then((value) => resume(Effect.succeed(value)), (cause) => resume(Effect.fail(cause)));
29
+ });
30
+ }));
31
+ });
32
+ //#endregion
4
33
  //#region src/DurableObjectStorage.ts
5
34
  var DurableObjectStorage_exports = /* @__PURE__ */ __exportAll({
6
35
  StorageOperationError: () => StorageOperationError,
7
36
  fromDurableObjectStorage: () => fromDurableObjectStorage
8
37
  });
9
- /** Error type used when a storage operation throws or rejects. */
10
38
  var StorageOperationError = class extends Data.TaggedError("StorageOperationError") {
11
39
  get message() {
12
40
  return `Durable Object storage ${this.operation} failed: ${causeMessage(this.cause)}`;
@@ -93,9 +121,6 @@ const fromDurableObjectTransaction = (txn) => ({
93
121
  setAlarmAfter: (delay, options) => setAlarmAfter("transaction.setAlarm", (scheduledTime, options) => txn.setAlarm(scheduledTime, options), delay, options),
94
122
  deleteAlarm: (options) => tryStoragePromise("transaction.deleteAlarm", () => txn.deleteAlarm(options))
95
123
  });
96
- /**
97
- * Wraps native Cloudflare storage APIs as Effect-returning helpers.
98
- */
99
124
  const fromDurableObjectStorage = (storage) => ({
100
125
  get: (key, options) => tryStoragePromise("get", () => storage.get(key, options)),
101
126
  put: (key, value, options) => tryStoragePromise("put", () => storage.put(key, value, options)),
@@ -107,30 +132,35 @@ const fromDurableObjectStorage = (storage) => ({
107
132
  deleteAlarm: (options) => tryStoragePromise("deleteAlarm", () => storage.deleteAlarm(options)),
108
133
  transactionSync: (closure) => Effect.context().pipe(Effect.flatMap((context) => Effect.suspend(() => {
109
134
  let aborted;
135
+ let escapedFiber;
110
136
  try {
111
137
  return Effect.succeed(storage.transactionSync(() => {
112
138
  const exit = Effect.runSyncExitWith(context)(closure());
113
139
  if (Exit.isSuccess(exit)) return exit.value;
140
+ const defect = Cause.findDefect(exit.cause);
141
+ if (Result.isSuccess(defect) && Cause.isAsyncFiberError(defect.success)) {
142
+ escapedFiber = defect.success.fiber;
143
+ escapedFiber.interruptUnsafe();
144
+ }
114
145
  aborted = exit;
115
146
  throw exit;
116
147
  }));
117
148
  } catch (cause) {
118
- if (aborted !== void 0 && cause === aborted && Exit.isFailure(aborted)) return Effect.failCause(aborted.cause);
119
- return Effect.fail(storageError("transactionSync", cause));
149
+ const failure = aborted !== void 0 && cause === aborted && Exit.isFailure(aborted) ? Effect.failCause(aborted.cause) : Effect.fail(storageError("transactionSync", cause));
150
+ const fiber = escapedFiber;
151
+ if (fiber !== void 0) return Fiber.interrupt(fiber).pipe(Effect.andThen(failure));
152
+ return failure;
120
153
  }
121
154
  }))),
122
- transaction: (closure) => Effect.context().pipe(Effect.flatMap((context) => Effect.callback((resume) => {
155
+ transaction: (closure) => Effect.suspend(() => {
123
156
  let aborted;
124
- storage.transaction(async (txn) => {
125
- const exit = await Effect.runPromiseExitWith(context)(closure(fromDurableObjectTransaction(txn)));
157
+ return runNativeCallback((run) => storage.transaction(async (txn) => {
158
+ const exit = await run(Effect.suspend(() => closure(fromDurableObjectTransaction(txn))));
126
159
  if (Exit.isSuccess(exit)) return exit.value;
127
160
  aborted = exit;
128
161
  throw exit;
129
- }).then((value) => resume(Effect.succeed(value)), (cause) => {
130
- if (aborted !== void 0 && cause === aborted && Exit.isFailure(aborted)) resume(Effect.failCause(aborted.cause));
131
- else resume(Effect.fail(storageError("transaction", cause)));
132
- });
133
- }))),
162
+ })).pipe(Effect.catch((cause) => aborted !== void 0 && cause === aborted && Exit.isFailure(aborted) ? Effect.failCause(aborted.cause) : Effect.fail(storageError("transaction", cause))));
163
+ }),
134
164
  sync: () => tryStoragePromise("sync", () => storage.sync()),
135
165
  getCurrentBookmark: () => tryStoragePromise("getCurrentBookmark", () => storage.getCurrentBookmark()),
136
166
  onNextSessionRestoreBookmark: (bookmark) => tryStoragePromise("onNextSessionRestoreBookmark", () => storage.onNextSessionRestoreBookmark(bookmark)),
@@ -148,13 +178,11 @@ var DurableObjectWebSocket_exports = /* @__PURE__ */ __exportAll({
148
178
  fromWebSocket: () => fromWebSocket,
149
179
  handlers: () => handlers
150
180
  });
151
- /** Error raised when sending on a Durable Object websocket fails. */
152
181
  var DurableWebSocketSendError = class extends Data.TaggedError("DurableWebSocketSendError") {
153
182
  get message() {
154
183
  return `Durable Object websocket send failed: ${causeMessage(this.cause)}`;
155
184
  }
156
185
  };
157
- /** Error raised when closing a Durable Object websocket fails. */
158
186
  var DurableWebSocketCloseError = class extends Data.TaggedError("DurableWebSocketCloseError") {
159
187
  get message() {
160
188
  return `Durable Object websocket close failed: ${causeMessage(this.cause)}`;
@@ -166,51 +194,31 @@ var DurableWebSocketAttachmentError = class extends Data.TaggedError("DurableWeb
166
194
  return `Durable Object websocket attachment ${this.operation} failed: ${causeMessage(this.cause)}`;
167
195
  }
168
196
  };
169
- const wrappers = /* @__PURE__ */ new WeakMap();
170
- /** Wraps a native Cloudflare websocket in the Effect-native Durable Object API. */
171
- const fromWebSocket = (raw) => {
172
- const existing = wrappers.get(raw);
173
- if (existing !== void 0) return existing;
174
- const socket = {
175
- raw,
176
- send: (data) => Effect.try({
177
- try: () => raw.send(data),
178
- catch: (cause) => new DurableWebSocketSendError({ cause })
179
- }),
180
- close: (code, reason) => Effect.try({
181
- try: () => raw.close(code, reason),
182
- catch: (cause) => new DurableWebSocketCloseError({ cause })
183
- }),
184
- serializeAttachment: (value) => Effect.try({
185
- try: () => raw.serializeAttachment(value),
186
- catch: (cause) => new DurableWebSocketAttachmentError({
187
- operation: "serialize",
188
- cause
189
- })
190
- }),
191
- deserializeAttachment: Effect.try({
192
- try: () => raw.deserializeAttachment(),
193
- catch: (cause) => new DurableWebSocketAttachmentError({
194
- operation: "deserialize",
195
- cause
196
- })
197
+ const fromWebSocket = (raw) => ({
198
+ raw,
199
+ send: (data) => Effect.try({
200
+ try: () => raw.send(data),
201
+ catch: (cause) => new DurableWebSocketSendError({ cause })
202
+ }),
203
+ close: (code, reason) => Effect.try({
204
+ try: () => raw.close(code, reason),
205
+ catch: (cause) => new DurableWebSocketCloseError({ cause })
206
+ }),
207
+ serializeAttachment: (value) => Effect.try({
208
+ try: () => raw.serializeAttachment(value),
209
+ catch: (cause) => new DurableWebSocketAttachmentError({
210
+ operation: "serialize",
211
+ cause
197
212
  })
198
- };
199
- wrappers.set(raw, socket);
200
- return socket;
201
- };
202
- /**
203
- * Accepts a websocket upgrade and registers the server socket on `DurableObjectState`.
204
- *
205
- * @example
206
- * ```ts
207
- * const response = yield* DurableObjectWebSocket.acceptUpgrade({
208
- * tags: ["room:general"],
209
- * });
210
- *
211
- * return response.response;
212
- * ```
213
- */
213
+ }),
214
+ deserializeAttachment: Effect.try({
215
+ try: () => raw.deserializeAttachment(),
216
+ catch: (cause) => new DurableWebSocketAttachmentError({
217
+ operation: "deserialize",
218
+ cause
219
+ })
220
+ })
221
+ });
214
222
  const acceptUpgrade = Effect.fn("DurableObjectWebSocket.acceptUpgrade")(function* (options = {}) {
215
223
  const state = yield* DurableObjectState;
216
224
  const pair = new WebSocketPair();
@@ -227,7 +235,6 @@ const acceptUpgrade = Effect.fn("DurableObjectWebSocket.acceptUpgrade")(function
227
235
  })
228
236
  };
229
237
  });
230
- /** Creates typed attachment helpers for accepted and rehydrated sockets. */
231
238
  const attachment = (schema) => {
232
239
  const serialize = (socket, value) => Schema.encodeEffect(schema)(value).pipe(Effect.mapError((cause) => new DurableWebSocketAttachmentError({
233
240
  operation: "serialize",
@@ -266,7 +273,6 @@ const attachment = (schema) => {
266
273
  schema
267
274
  };
268
275
  };
269
- /** Maps compact websocket lifecycle handler names to `DurableObject.make` options. */
270
276
  const handlers = (options) => ({
271
277
  webSocketMessage: options.message,
272
278
  webSocketClose: options.close,
@@ -278,30 +284,19 @@ const causeError = (cause) => {
278
284
  const squashed = Cause.squash(cause);
279
285
  return squashed instanceof Error ? squashed : new Error(Cause.pretty(cause), { cause: squashed });
280
286
  };
281
- const failureHandler = (label, cause, options) => (options?.onFailure?.(cause) ?? Effect.logError(`${label} failed`, Cause.pretty(cause))).pipe(Effect.catchCause((handlerCause) => Effect.logError(`${label} failure handler failed`, Cause.pretty(cause), Cause.pretty(handlerCause))));
282
- /**
283
- * Builds a `waitUntil` scheduler for any Cloudflare lifecycle that accepts
284
- * background promises (`ExecutionContext`, `DurableObjectState`).
285
- *
286
- * Background effects capture the calling fiber's context via `Effect.context`
287
- * before being registered, so the default module-level `Effect.runPromiseExit`
288
- * runner is sufficient; entrypoints may still pass a runtime-bound runner.
289
- */
287
+ const failureHandler = (label, cause, options) => Effect.suspend(() => options?.onFailure?.(cause) ?? Effect.logError(`${label} failed`, Cause.pretty(cause))).pipe(Effect.catchCause((handlerCause) => Effect.logError(`${label} failure handler failed`, Cause.pretty(cause), Cause.pretty(handlerCause))));
290
288
  const makeWaitUntilScheduler = (label, register, runPromiseExit = (effect) => Effect.runPromiseExit(effect)) => {
291
289
  return (effect, options, mode) => Effect.context().pipe(Effect.flatMap((context) => Effect.sync(() => {
292
- const runHandler = (cause) => runPromiseExit(Effect.scoped(Effect.provideContext(failureHandler(label, cause, options), context))).then((exit) => {
290
+ const runHandler = (cause) => runPromiseExit(Effect.provideContext(Effect.scoped(failureHandler(label, cause, options)), context)).then((exit) => {
293
291
  if (Exit.isFailure(exit)) console.error(`${label} failure handler failed`, Cause.pretty(exit.cause));
294
292
  });
295
- register(runPromiseExit(Effect.scoped(Effect.provideContext(effect, context))).then(async (exit) => {
293
+ register(runPromiseExit(Effect.provideContext(Effect.scoped(effect), context)).then(async (exit) => {
296
294
  if (Exit.isSuccess(exit)) return;
297
295
  await runHandler(exit.cause);
298
296
  if (mode === "propagate") throw causeError(exit.cause);
299
297
  }));
300
298
  })));
301
299
  };
302
- /**
303
- * Builds the `WorkerContext` service from a native `ExecutionContext`.
304
- */
305
300
  const fromExecutionContext = (ctx, runPromiseExit = (effect) => Effect.runPromiseExit(effect)) => {
306
301
  const schedule = makeWaitUntilScheduler("WorkerContext.waitUntil", (promise) => ctx.waitUntil(promise), runPromiseExit);
307
302
  return {
@@ -318,13 +313,7 @@ var DurableObjectState_exports = /* @__PURE__ */ __exportAll({
318
313
  DurableObjectState: () => DurableObjectState,
319
314
  fromDurableObjectState: () => fromDurableObjectState
320
315
  });
321
- /**
322
- * Context tag for accessing the current Durable Object state service.
323
- */
324
316
  var DurableObjectState = class extends Context.Service()("effect-cf/DurableObjectState") {};
325
- /**
326
- * Wraps a native Cloudflare `DurableObjectState` as a {@link DurableObjectStateService}.
327
- */
328
317
  const fromDurableObjectState = (state) => {
329
318
  const scheduleWaitUntil = makeWaitUntilScheduler("DurableObjectState.waitUntil", (promise) => state.waitUntil(promise));
330
319
  const waitUntil = ((input, options) => Effect.isEffect(input) ? scheduleWaitUntil(input, options, options?.mode ?? "observe") : Effect.sync(() => state.waitUntil(input)));
@@ -333,8 +322,12 @@ const fromDurableObjectState = (state) => {
333
322
  id: state.id,
334
323
  storage: fromDurableObjectStorage(state.storage),
335
324
  waitUntil,
336
- blockConcurrencyWhile: (effect) => Effect.context().pipe(Effect.flatMap((context) => Effect.promise(() => state.blockConcurrencyWhile(() => runPromiseExitPreservingTypedFailures(context, effect)))), Effect.flatten),
337
- blockConcurrencyWhileOrReset: (effect) => Effect.context().pipe(Effect.flatMap((context) => Effect.promise(() => state.blockConcurrencyWhile(() => Effect.runPromiseWith(context)(effect))))),
325
+ blockConcurrencyWhile: (effect) => runNativeCallback((run) => state.blockConcurrencyWhile(() => runExitPreservingTypedFailures(run, effect))).pipe(Effect.orDie, Effect.flatten),
326
+ blockConcurrencyWhileOrReset: (effect) => runNativeCallback((run) => state.blockConcurrencyWhile(async () => {
327
+ const exit = await run(effect);
328
+ if (Exit.isFailure(exit)) throw Cause.squash(exit.cause);
329
+ return exit.value;
330
+ })).pipe(Effect.orDie),
338
331
  acceptWebSocket: (ws, tags) => Effect.sync(() => state.acceptWebSocket(ws.raw, tags)),
339
332
  getWebSockets: (tag) => Effect.sync(() => state.getWebSockets(tag).map((socket) => fromWebSocket(socket))),
340
333
  setWebSocketAutoResponse: (pair) => Effect.sync(() => state.setWebSocketAutoResponse(pair)),
@@ -346,10 +339,10 @@ const fromDurableObjectState = (state) => {
346
339
  abort: (reason, options) => Effect.sync(() => state.abort(reason, options))
347
340
  };
348
341
  };
349
- const runPromiseExitPreservingTypedFailures = async (context, effect) => {
350
- const exit = await Effect.runPromiseExitWith(context)(effect);
342
+ const runExitPreservingTypedFailures = async (run, effect) => {
343
+ const exit = await run(effect);
351
344
  if (Exit.isFailure(exit) && (Cause.hasDies(exit.cause) || Cause.hasInterrupts(exit.cause))) throw Cause.squash(exit.cause);
352
345
  return exit;
353
346
  };
354
347
  //#endregion
355
- export { DurableObjectWebSocket_exports as a, DurableObjectStorage_exports as c, fromExecutionContext as i, DurableObjectState_exports as n, DurableWebSocketAttachmentError as o, fromDurableObjectState as r, fromWebSocket as s, DurableObjectState as t };
348
+ export { DurableObjectWebSocket_exports as a, DurableObjectStorage_exports as c, fromExecutionContext as i, runNativeCallback as l, DurableObjectState_exports as n, DurableWebSocketAttachmentError as o, fromDurableObjectState as r, fromWebSocket as s, DurableObjectState as t };