effect-cf 0.33.0 → 0.34.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 (73) hide show
  1. package/CHANGELOG.md +12 -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 +1 -10
  10. package/dist/ComputerWorkspace.mjs +1 -2
  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-BpRjz6-q.d.mts → DurableObjectState-CrEunfQ-.d.mts} +82 -252
  14. package/dist/{DurableObjectState-CVLLse69.mjs → DurableObjectState-De4ZojhY.mjs} +1 -39
  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 +2 -17
  23. package/dist/{WorkflowBinding-lBR4_-op.d.mts → WorkflowBinding-BumVQTuW.d.mts} +2 -5
  24. package/dist/index.d.mts +34 -480
  25. package/dist/index.mjs +174 -312
  26. package/package.json +1 -1
  27. package/src/AiGateway.ts +0 -6
  28. package/src/AnalyticsEngine.ts +0 -9
  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 +3 -39
  34. package/src/ComputerArtifacts.ts +0 -2
  35. package/src/ComputerWorkspace.ts +0 -9
  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 +45 -25
  40. package/src/DurableObjectAlarm.ts +6 -210
  41. package/src/DurableObjectDefinition.ts +8 -20
  42. package/src/DurableObjectNamespace.ts +57 -112
  43. package/src/DurableObjectRpcWebSocket.ts +3 -19
  44. package/src/DurableObjectSqlite.ts +0 -12
  45. package/src/DurableObjectState.ts +0 -18
  46. package/src/DurableObjectStorage.ts +2 -35
  47. package/src/DurableObjectWebSocket.ts +0 -31
  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 +0 -2
  57. package/src/RpcTracing.ts +133 -0
  58. package/src/Sandbox.ts +0 -30
  59. package/src/ServiceBinding.ts +48 -125
  60. package/src/Vectorize.ts +0 -5
  61. package/src/Vitest.ts +0 -28
  62. package/src/WebTransport.ts +0 -15
  63. package/src/Worker.ts +36 -57
  64. package/src/WorkerDefinition.ts +5 -14
  65. package/src/WorkersAi.ts +0 -4
  66. package/src/Workflow.ts +0 -5
  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/RpcInvocation.ts +18 -1
  72. package/src/internal/Runtime.ts +12 -7
  73. package/src/internal/WorkerContext.ts +0 -11
@@ -1,12 +1,11 @@
1
1
  import { t as __exportAll } from "./rolldown-runtime-D7D4PA-g.mjs";
2
- import { t as causeMessage } from "./ErrorMessage-BM0K-Nik.mjs";
2
+ import { t as causeMessage } from "./ErrorMessage-Byx2OgNd.mjs";
3
3
  import { Cause, Clock, Context, Data, Duration, Effect, Exit, Option, Predicate, Result, Schema } from "effect";
4
4
  //#region src/DurableObjectStorage.ts
5
5
  var DurableObjectStorage_exports = /* @__PURE__ */ __exportAll({
6
6
  StorageOperationError: () => StorageOperationError,
7
7
  fromDurableObjectStorage: () => fromDurableObjectStorage
8
8
  });
9
- /** Error type used when a storage operation throws or rejects. */
10
9
  var StorageOperationError = class extends Data.TaggedError("StorageOperationError") {
11
10
  get message() {
12
11
  return `Durable Object storage ${this.operation} failed: ${causeMessage(this.cause)}`;
@@ -93,9 +92,6 @@ const fromDurableObjectTransaction = (txn) => ({
93
92
  setAlarmAfter: (delay, options) => setAlarmAfter("transaction.setAlarm", (scheduledTime, options) => txn.setAlarm(scheduledTime, options), delay, options),
94
93
  deleteAlarm: (options) => tryStoragePromise("transaction.deleteAlarm", () => txn.deleteAlarm(options))
95
94
  });
96
- /**
97
- * Wraps native Cloudflare storage APIs as Effect-returning helpers.
98
- */
99
95
  const fromDurableObjectStorage = (storage) => ({
100
96
  get: (key, options) => tryStoragePromise("get", () => storage.get(key, options)),
101
97
  put: (key, value, options) => tryStoragePromise("put", () => storage.put(key, value, options)),
@@ -148,13 +144,11 @@ var DurableObjectWebSocket_exports = /* @__PURE__ */ __exportAll({
148
144
  fromWebSocket: () => fromWebSocket,
149
145
  handlers: () => handlers
150
146
  });
151
- /** Error raised when sending on a Durable Object websocket fails. */
152
147
  var DurableWebSocketSendError = class extends Data.TaggedError("DurableWebSocketSendError") {
153
148
  get message() {
154
149
  return `Durable Object websocket send failed: ${causeMessage(this.cause)}`;
155
150
  }
156
151
  };
157
- /** Error raised when closing a Durable Object websocket fails. */
158
152
  var DurableWebSocketCloseError = class extends Data.TaggedError("DurableWebSocketCloseError") {
159
153
  get message() {
160
154
  return `Durable Object websocket close failed: ${causeMessage(this.cause)}`;
@@ -167,7 +161,6 @@ var DurableWebSocketAttachmentError = class extends Data.TaggedError("DurableWeb
167
161
  }
168
162
  };
169
163
  const wrappers = /* @__PURE__ */ new WeakMap();
170
- /** Wraps a native Cloudflare websocket in the Effect-native Durable Object API. */
171
164
  const fromWebSocket = (raw) => {
172
165
  const existing = wrappers.get(raw);
173
166
  if (existing !== void 0) return existing;
@@ -199,18 +192,6 @@ const fromWebSocket = (raw) => {
199
192
  wrappers.set(raw, socket);
200
193
  return socket;
201
194
  };
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
- */
214
195
  const acceptUpgrade = Effect.fn("DurableObjectWebSocket.acceptUpgrade")(function* (options = {}) {
215
196
  const state = yield* DurableObjectState;
216
197
  const pair = new WebSocketPair();
@@ -227,7 +208,6 @@ const acceptUpgrade = Effect.fn("DurableObjectWebSocket.acceptUpgrade")(function
227
208
  })
228
209
  };
229
210
  });
230
- /** Creates typed attachment helpers for accepted and rehydrated sockets. */
231
211
  const attachment = (schema) => {
232
212
  const serialize = (socket, value) => Schema.encodeEffect(schema)(value).pipe(Effect.mapError((cause) => new DurableWebSocketAttachmentError({
233
213
  operation: "serialize",
@@ -266,7 +246,6 @@ const attachment = (schema) => {
266
246
  schema
267
247
  };
268
248
  };
269
- /** Maps compact websocket lifecycle handler names to `DurableObject.make` options. */
270
249
  const handlers = (options) => ({
271
250
  webSocketMessage: options.message,
272
251
  webSocketClose: options.close,
@@ -279,14 +258,6 @@ const causeError = (cause) => {
279
258
  return squashed instanceof Error ? squashed : new Error(Cause.pretty(cause), { cause: squashed });
280
259
  };
281
260
  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
- */
290
261
  const makeWaitUntilScheduler = (label, register, runPromiseExit = (effect) => Effect.runPromiseExit(effect)) => {
291
262
  return (effect, options, mode) => Effect.context().pipe(Effect.flatMap((context) => Effect.sync(() => {
292
263
  const runHandler = (cause) => runPromiseExit(Effect.scoped(Effect.provideContext(failureHandler(label, cause, options), context))).then((exit) => {
@@ -299,9 +270,6 @@ const makeWaitUntilScheduler = (label, register, runPromiseExit = (effect) => Ef
299
270
  }));
300
271
  })));
301
272
  };
302
- /**
303
- * Builds the `WorkerContext` service from a native `ExecutionContext`.
304
- */
305
273
  const fromExecutionContext = (ctx, runPromiseExit = (effect) => Effect.runPromiseExit(effect)) => {
306
274
  const schedule = makeWaitUntilScheduler("WorkerContext.waitUntil", (promise) => ctx.waitUntil(promise), runPromiseExit);
307
275
  return {
@@ -318,13 +286,7 @@ var DurableObjectState_exports = /* @__PURE__ */ __exportAll({
318
286
  DurableObjectState: () => DurableObjectState,
319
287
  fromDurableObjectState: () => fromDurableObjectState
320
288
  });
321
- /**
322
- * Context tag for accessing the current Durable Object state service.
323
- */
324
289
  var DurableObjectState = class extends Context.Service()("effect-cf/DurableObjectState") {};
325
- /**
326
- * Wraps a native Cloudflare `DurableObjectState` as a {@link DurableObjectStateService}.
327
- */
328
290
  const fromDurableObjectState = (state) => {
329
291
  const scheduleWaitUntil = makeWaitUntilScheduler("DurableObjectState.waitUntil", (promise) => state.waitUntil(promise));
330
292
  const waitUntil = ((input, options) => Effect.isEffect(input) ? scheduleWaitUntil(input, options, options?.mode ?? "observe") : Effect.sync(() => state.waitUntil(input)));
@@ -40,7 +40,6 @@ const causeMessage = (cause) => {
40
40
  return "unknown cause";
41
41
  }
42
42
  };
43
- /** Renders a violation list as a single `path: message; ...` line. */
44
43
  const violationsMessage = (violations) => violations.map((violation) => `${violation.path}: ${violation.message}`).join("; ");
45
44
  //#endregion
46
45
  export { WorkerEnvironment as a, WorkerConfig as i, violationsMessage as n, Environment_exports as r, causeMessage as t };
@@ -1,11 +1,9 @@
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 } from "effect";
3
3
  declare namespace Hyperdrive_d_exports {
4
4
  export { HyperdriveClient, HyperdriveDefinition, HyperdriveService, LayerOptions, Tag, TagClass, isHyperdrive, layer, make, makeClient };
5
5
  }
6
- /** Typed Hyperdrive binding definition. */
7
6
  interface HyperdriveDefinition {
8
- /** Binding name as configured in `wrangler.jsonc`. */
9
7
  readonly binding: string;
10
8
  }
11
9
  interface HyperdriveClient {
@@ -14,7 +12,6 @@ interface HyperdriveClient {
14
12
  readonly definition: HyperdriveDefinition;
15
13
  }
16
14
  declare const HyperdriveServiceTypeId: unique symbol;
17
- /** Nominal service marker for Hyperdrive services created with {@link make}. */
18
15
  interface HyperdriveService<Id extends string> {
19
16
  readonly [HyperdriveServiceTypeId]: {
20
17
  readonly id: Id;
@@ -1,19 +1,10 @@
1
- import { c as WorkerEnvironment, r as BindingValidationError, t as BindingNotFoundError } from "./Binding-xJJJPmiD.mjs";
2
- import { n as LayerOptions, r as TagClass } from "./Hyperdrive-z-9fFz15.mjs";
1
+ import { c as WorkerEnvironment, r as BindingValidationError, t as BindingNotFoundError } from "./Binding-DKcLrQCM.mjs";
2
+ import { n as LayerOptions, r as TagClass } from "./Hyperdrive-HrwFlZ6x.mjs";
3
3
  import { Layer } from "effect";
4
4
  import { PgClient } from "@effect/sql-pg";
5
5
  import { SqlClient, SqlError } from "effect/unstable/sql";
6
6
  //#region src/HyperdrivePg.d.ts
7
- /** Hyperdrive owns database pooling, so app-side pool and connection options are not exposed. */
8
7
  type PgLayerOptions = Omit<Parameters<typeof PgClient.makeClient>[0], "url" | "host" | "port" | "path" | "ssl" | "database" | "username" | "password" | "stream">;
9
- /**
10
- * Provides `PgClient` and `SqlClient` backed by a Hyperdrive binding.
11
- *
12
- * Note: since Effect `4.0.0-beta.99`, `PgClient.makeClient` connects eagerly,
13
- * so the TCP connection to Hyperdrive is opened when this layer is built.
14
- * In per-request Workers runtimes, build the layer within the request
15
- * lifecycle rather than sharing it across requests.
16
- */
17
8
  declare const layer: <Self, Id extends string>(tag: TagClass<Self, Id>, binding: LayerOptions, options?: PgLayerOptions) => Layer.Layer<PgClient.PgClient | SqlClient.SqlClient, BindingNotFoundError | BindingValidationError | SqlError.SqlError, WorkerEnvironment>;
18
9
  //#endregion
19
10
  export { PgLayerOptions, layer };
@@ -1,14 +1,6 @@
1
1
  import { Effect, Layer, Redacted } from "effect";
2
2
  import { PgClient } from "@effect/sql-pg";
3
3
  //#region src/HyperdrivePg.ts
4
- /**
5
- * Provides `PgClient` and `SqlClient` backed by a Hyperdrive binding.
6
- *
7
- * Note: since Effect `4.0.0-beta.99`, `PgClient.makeClient` connects eagerly,
8
- * so the TCP connection to Hyperdrive is opened when this layer is built.
9
- * In per-request Workers runtimes, build the layer within the request
10
- * lifecycle rather than sharing it across requests.
11
- */
12
4
  const layer = (tag, binding, options) => PgClient.layerFrom(Effect.flatMap(tag, (hyperdrive) => PgClient.makeClient({
13
5
  ...options,
14
6
  url: Redacted.make(hyperdrive.connectionString)
@@ -1,17 +1,14 @@
1
- import { c as WorkerEnvironment, r as BindingValidationError, t as BindingNotFoundError } from "./Binding-xJJJPmiD.mjs";
2
- import { n as ContainerStartOptions, r as ContainerStopSignal } from "./ContainerNamespace-CFjiLw8b.mjs";
1
+ import { c as WorkerEnvironment, r as BindingValidationError, t as BindingNotFoundError } from "./Binding-DKcLrQCM.mjs";
2
+ import { n as ContainerStartOptions, r as ContainerStopSignal } from "./ContainerNamespace-DbLaeFhN.mjs";
3
3
  import { Context, Effect, Layer, Option, Stream } from "effect";
4
4
  import { BackupOptions, BackupOptions as BackupOptions$1, CheckChangesOptions, CheckChangesOptions as CheckChangesOptions$1, CheckChangesResult, CheckChangesResult as CheckChangesResult$1, CreateTerminalOptions, CreateTerminalOptions as CreateTerminalOptions$1, DirectoryBackup, DirectoryBackup as DirectoryBackup$1, ExecOptions, ExecOptions as ExecOptions$1, FileWatchSSEEvent, FileWatchSSEEvent as FileWatchSSEEvent$1, ISandbox, ISandbox as ISandbox$1, ListFilesOptions, ListFilesOptions as ListFilesOptions$1, MountBucketOptions, MountBucketOptions as MountBucketOptions$1, ProcessExit, ProcessExit as ProcessExit$1, ProcessLogEvent, ProcessLogEvent as ProcessLogEvent$1, ProcessLogsOptions, ProcessLogsOptions as ProcessLogsOptions$1, ProcessOutput, ProcessOutput as ProcessOutput$1, ProcessOutputOptions, ProcessOutputOptions as ProcessOutputOptions$1, ProcessStatus, ProcessStatus as ProcessStatus$1, RestoreBackupResult, RestoreBackupResult as RestoreBackupResult$1, SandboxCommand, SandboxCommand as SandboxCommand$1, SandboxOptions, SandboxOptions as SandboxOptions$1, SandboxProcess, SandboxProcess as SandboxProcess$1, Terminal, Terminal as Terminal$1, TerminalOutputCursor, TerminalOutputCursor as TerminalOutputCursor$1, TerminalOutputEvent, TerminalOutputEvent as TerminalOutputEvent$1, TerminalOutputOptions, TerminalOutputOptions as TerminalOutputOptions$1, TerminalSnapshot, TerminalSnapshot as TerminalSnapshot$1, TunnelInfo, TunnelInfo as TunnelInfo$1, TunnelOptions, TunnelOptions as TunnelOptions$1, WaitForExitOptions, WaitForExitOptions as WaitForExitOptions$1, WaitForLogOptions, WaitForLogOptions as WaitForLogOptions$1, WaitForLogResult, WaitForLogResult as WaitForLogResult$1, WaitForPortOptions, WaitForPortOptions as WaitForPortOptions$1, WatchOptions, WatchOptions as WatchOptions$1 } from "@cloudflare/sandbox";
5
5
  //#region src/Sandbox.d.ts
6
- /** Sandbox namespace binding metadata. */
7
6
  interface SandboxDefinition {
8
- /** Binding name as configured in `wrangler.jsonc`. */
9
7
  readonly binding: string;
10
8
  }
11
9
  declare const SandboxOperationError_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 & {
12
10
  readonly _tag: "SandboxOperationError";
13
11
  } & Readonly<A>;
14
- /** Failure raised when invoking a sandbox operation. */
15
12
  declare class SandboxOperationError extends SandboxOperationError_base<{
16
13
  readonly binding: string;
17
14
  readonly instance: string;
@@ -31,43 +28,30 @@ interface SandboxNamespaceResource {
31
28
  idFromName(name: string): globalThis.DurableObjectId;
32
29
  get(id: globalThis.DurableObjectId, options?: globalThis.DurableObjectNamespaceGetDurableObjectOptions): globalThis.DurableObjectStub;
33
30
  }
34
- /** Result of `writeFile` as reported by the sandbox client. */
35
31
  type WriteFileResult = Awaited<ReturnType<ISandbox$1["writeFile"]>>;
36
- /** Result of `readFile` as reported by the sandbox client. */
37
32
  type ReadFileResult = Awaited<ReturnType<ISandbox$1["readFile"]>>;
38
- /** Result of `mkdir` as reported by the sandbox client. */
39
33
  type MkdirResult = Awaited<ReturnType<ISandbox$1["mkdir"]>>;
40
- /** Result of `deleteFile` as reported by the sandbox client. */
41
34
  type DeleteFileResult = Awaited<ReturnType<ISandbox$1["deleteFile"]>>;
42
- /** Result of `renameFile` as reported by the sandbox client. */
43
35
  type RenameFileResult = Awaited<ReturnType<ISandbox$1["renameFile"]>>;
44
- /** Result of `moveFile` as reported by the sandbox client. */
45
36
  type MoveFileResult = Awaited<ReturnType<ISandbox$1["moveFile"]>>;
46
- /** Result of `listFiles` as reported by the sandbox client. */
47
37
  type ListFilesResult = Awaited<ReturnType<ISandbox$1["listFiles"]>>;
48
- /** Result of `exists` as reported by the sandbox client. */
49
38
  type FileExistsResult = Awaited<ReturnType<ISandbox$1["exists"]>>;
50
- /** Text encodings accepted by `readFile`. */
51
39
  type ReadFileEncoding = "utf-8" | "utf8" | "base64";
52
- /** Options accepted by `exposePort`. */
53
40
  interface ExposePortOptions {
54
41
  readonly name?: string;
55
42
  readonly hostname: string;
56
43
  readonly token?: string;
57
44
  }
58
- /** Preview URL information returned by `exposePort`. */
59
45
  interface ExposedPort {
60
46
  readonly url: string;
61
47
  readonly port: number;
62
48
  readonly name?: string;
63
49
  }
64
- /** Currently forwardable preview URL returned by `getExposedPorts`. */
65
50
  interface ExposedPortStatus {
66
51
  readonly url: string;
67
52
  readonly port: number;
68
53
  readonly status: "active";
69
54
  }
70
- /** Structural tunnel API surface exposed by a sandbox client. */
71
55
  interface SandboxTunnelsResource {
72
56
  get(port: number, options?: TunnelOptions$1): Promise<TunnelInfo$1>;
73
57
  list(): Promise<Array<TunnelInfo$1>>;
@@ -90,7 +74,6 @@ interface SandboxClientResource extends ISandbox$1 {
90
74
  validatePortToken(port: number, token: string): Promise<boolean>;
91
75
  readonly tunnels: SandboxTunnelsResource;
92
76
  }
93
- /** Effect-wrapped handle for one process started inside a sandbox. */
94
77
  interface SandboxProcessHandle {
95
78
  readonly id: string;
96
79
  readonly pid: number;
@@ -105,7 +88,6 @@ interface SandboxProcessHandle {
105
88
  readonly waitForPort: (port: number, options?: Omit<WaitForPortOptions$1, "signal">) => Effect.Effect<void, SandboxOperationError>;
106
89
  readonly kill: (signal?: number) => Effect.Effect<void, SandboxOperationError>;
107
90
  }
108
- /** Effect-wrapped handle for one interactive terminal inside a sandbox. */
109
91
  interface SandboxTerminalHandle {
110
92
  readonly id: string;
111
93
  readonly rawUnsafe: Effect.Effect<Terminal$1>;
@@ -122,13 +104,11 @@ interface SandboxTerminalHandle {
122
104
  readonly rows?: number;
123
105
  }) => Effect.Effect<Response, SandboxOperationError>;
124
106
  }
125
- /** Effect-wrapped tunnel operations for one sandbox instance. */
126
107
  interface SandboxTunnelsClient {
127
108
  readonly get: (port: number, options?: TunnelOptions$1) => Effect.Effect<TunnelInfo$1, SandboxOperationError>;
128
109
  readonly list: Effect.Effect<Array<TunnelInfo$1>, SandboxOperationError>;
129
110
  readonly destroy: (portOrInfo: number | TunnelInfo$1) => Effect.Effect<void, SandboxOperationError>;
130
111
  }
131
- /** Effect-wrapped client for one named sandbox instance. */
132
112
  interface SandboxInstanceClient {
133
113
  readonly rawUnsafe: Effect.Effect<SandboxClientResource>;
134
114
  readonly exec: (command: SandboxCommand$1, options?: ExecOptions$1) => Effect.Effect<SandboxProcessHandle, SandboxOperationError>;
@@ -171,7 +151,6 @@ interface SandboxInstanceClient {
171
151
  readonly stop: (signal?: ContainerStopSignal) => Effect.Effect<void, SandboxOperationError>;
172
152
  readonly destroy: Effect.Effect<void, SandboxOperationError>;
173
153
  }
174
- /** Effect client for a Sandbox Durable Object namespace binding. */
175
154
  interface SandboxNamespaceClient<Namespace extends SandboxNamespaceResource = SandboxNamespaceResource> {
176
155
  readonly definition: SandboxDefinition;
177
156
  readonly get: (name: string, options?: SandboxOptions$1) => Effect.Effect<SandboxInstanceClient, SandboxOperationError>;
@@ -186,26 +165,17 @@ interface TagClass<Self, Id extends string, Namespace extends SandboxNamespaceRe
186
165
  readonly get: (name: string, options?: SandboxOptions$1) => Effect.Effect<SandboxInstanceClient, SandboxOperationError, Self>;
187
166
  readonly rawUnsafe: Effect.Effect<Namespace, never, Self>;
188
167
  }
189
- /**
190
- * Wraps an already-created sandbox client (the value returned by
191
- * `getSandbox()` from `@cloudflare/sandbox`) into an Effect client.
192
- *
193
- * Prefer {@link Tag}/{@link make} with a layer for application code; this
194
- * entry point exists for advanced composition and testing.
195
- */
196
168
  declare const fromSandboxClient: (client: SandboxClientResource, definition: SandboxDefinition, instance: string) => SandboxInstanceClient;
197
169
  declare const isSandboxNamespaceResource: <Candidate>(value: Candidate) => value is Candidate & SandboxNamespaceResource;
198
170
  declare const makeClient: (definition: SandboxDefinition) => <Namespace extends SandboxNamespaceResource>(namespace: Namespace) => SandboxNamespaceClient<Namespace>;
199
171
  declare const layer: <Self, Namespace extends SandboxNamespaceResource>(tag: Context.Service<Self, SandboxNamespaceClient<Namespace>>, definition: SandboxDefinition) => Layer.Layer<Self, BindingNotFoundError | BindingValidationError, WorkerEnvironment>;
200
172
  declare const make: <Id extends string>(id: Id) => TagClass<SandboxNamespaceService<Id>, Id, SandboxNamespaceResource>;
201
173
  declare const SandboxNamespaceServiceTypeId: unique symbol;
202
- /** Nominal service marker for Sandbox namespaces created with {@link make}. */
203
174
  interface SandboxNamespaceService<Id extends string> {
204
175
  readonly [SandboxNamespaceServiceTypeId]: {
205
176
  readonly id: Id;
206
177
  };
207
178
  }
208
- /** Creates a typed Effect service for a Cloudflare Sandbox namespace. */
209
179
  declare const Tag: <Self, Namespace extends SandboxNamespaceResource = SandboxNamespaceResource>() => <Id extends string>(id: Id) => TagClass<Self, Id, Namespace>;
210
180
  declare const Sandbox: typeof Tag;
211
181
  /**
package/dist/Sandbox.mjs CHANGED
@@ -1,9 +1,8 @@
1
- import { a as WorkerEnvironment, t as causeMessage } from "./ErrorMessage-BM0K-Nik.mjs";
2
- import { r as layer$1 } from "./Binding-pfilNJmP.mjs";
1
+ import { a as WorkerEnvironment, t as causeMessage } from "./ErrorMessage-Byx2OgNd.mjs";
2
+ import { r as layer$1 } from "./Binding-C82jRhdr.mjs";
3
3
  import { Context, Data, Effect, Option, Predicate, Stream } from "effect";
4
4
  //#region src/Sandbox.ts
5
5
  const expectedSandboxNamespace = "Sandbox Durable Object namespace binding with idFromName() and get()";
6
- /** Failure raised when invoking a sandbox operation. */
7
6
  var SandboxOperationError = class extends Data.TaggedError("SandboxOperationError") {
8
7
  get message() {
9
8
  return `Sandbox ${this.operation} failed for binding "${this.binding}" instance "${this.instance}": ${causeMessage(this.cause)}`;
@@ -135,13 +134,6 @@ const makeTerminalHandle = (definition, instance, terminal) => {
135
134
  })
136
135
  };
137
136
  };
138
- /**
139
- * Wraps an already-created sandbox client (the value returned by
140
- * `getSandbox()` from `@cloudflare/sandbox`) into an Effect client.
141
- *
142
- * Prefer {@link Tag}/{@link make} with a layer for application code; this
143
- * entry point exists for advanced composition and testing.
144
- */
145
137
  const fromSandboxClient = (client, definition, instance) => {
146
138
  const spanOptions = (operation) => ({ attributes: {
147
139
  binding: definition.binding,
@@ -325,7 +317,6 @@ const makeClient = (definition) => (namespace) => {
325
317
  };
326
318
  const layer = (tag, definition) => layer$1(tag, definition.binding, (value) => isSandboxNamespaceResource(value), makeClient(definition), { expected: expectedSandboxNamespace });
327
319
  const make = (id) => Tag()(id);
328
- /** Creates a typed Effect service for a Cloudflare Sandbox namespace. */
329
320
  const Tag = () => (id) => {
330
321
  const tag = Context.Service()(`effect-cf/Sandbox/${id}`);
331
322
  const makeLayer = (definition) => layer(tag, definition);
package/dist/Vitest.d.mts CHANGED
@@ -1,23 +1,14 @@
1
- import { c as WorkerEnvironment, s as WorkerEnv } from "./Binding-xJJJPmiD.mjs";
2
- import { n as DurableObjectStateService, t as DurableObjectState } from "./DurableObjectState-BpRjz6-q.mjs";
3
- import { o as WorkflowInstanceStatusName } from "./WorkflowBinding-lBR4_-op.mjs";
1
+ import { c as WorkerEnvironment, s as WorkerEnv } from "./Binding-DKcLrQCM.mjs";
2
+ import { n as DurableObjectStateService, t as DurableObjectState } from "./DurableObjectState-CrEunfQ-.mjs";
3
+ import { o as WorkflowInstanceStatusName } from "./WorkflowBinding-BumVQTuW.mjs";
4
4
  import { Effect, Layer, Schema } from "effect";
5
5
  import { DurableObject } from "cloudflare:workers";
6
6
  import { adminSecretsStore as adminSecretsStore$1, getQueueResult, introspectWorkflow as introspectWorkflow$1, introspectWorkflowInstance as introspectWorkflowInstance$1 } from "cloudflare:test";
7
7
  //#region src/Vitest.d.ts
8
- /**
9
- * Provides the Workers test environment as both {@link WorkerEnvironment} and
10
- * the active Effect `ConfigProvider`.
11
- */
12
8
  declare const layer: Layer.Layer<WorkerEnvironment>;
13
- /** Constructor shape shared by Effect-backed Worker entrypoints. */
14
9
  interface WorkerConstructor<Instance> {
15
10
  new (context: globalThis.ExecutionContext, env: WorkerEnv): Instance;
16
11
  }
17
- /**
18
- * Creates an `ExecutionContext` and drains all `waitUntil` work before the
19
- * returned effect completes, including when `use` fails or is interrupted.
20
- */
21
12
  declare const withExecutionContext: <A, E, R>(use: (context: globalThis.ExecutionContext) => Effect.Effect<A, E, R>) => Effect.Effect<A, E, R>;
22
13
  interface FetchWorker {
23
14
  fetch(request: Request): Promise<Response>;
@@ -27,9 +18,7 @@ interface FetchWorker {
27
18
  * work before returning the response.
28
19
  */
29
20
  declare const fetch: <Instance extends FetchWorker>(Worker: WorkerConstructor<Instance>, request: Request<unknown, CfProperties<unknown>>, workerEnv?: Cloudflare.Env | undefined) => Effect.Effect<Response, never, never>;
30
- /** Modules-format scheduled handler accepted by {@link scheduled}. */
31
21
  type ScheduledHandler = NonNullable<globalThis.ExportedHandler<WorkerEnv>["scheduled"]>;
32
- /** Options used to construct a scheduled event controller. */
33
22
  interface ScheduledOptions {
34
23
  readonly scheduledTime?: number | Date;
35
24
  readonly cron?: string;
@@ -54,7 +43,6 @@ type PagesEventContextInitData<Context> = Context extends globalThis.EventContex
54
43
  } : {
55
44
  readonly data: Data;
56
45
  } : never;
57
- /** Initialization accepted by the Workers Vitest plugin for a Pages Function. */
58
46
  type PagesEventContextInit<Function extends AnyPagesFunction> = PagesEventContextInitBase & PagesEventContextInitParams<Parameters<Function>[0]> & PagesEventContextInitData<Parameters<Function>[0]>;
59
47
  /**
60
48
  * Invokes a Pages Function with a typed event context and drains its
@@ -64,7 +52,6 @@ declare const pages: <Function extends AnyPagesFunction>(handler: Function, init
64
52
  interface QueueWorker {
65
53
  queue(batch: globalThis.MessageBatch): Promise<void>;
66
54
  }
67
- /** Input message accepted by the Workers Vitest plugin's `createMessageBatch` helper. */
68
55
  type QueueMessage<Body> = {
69
56
  readonly id: string;
70
57
  readonly timestamp: Date;
@@ -76,7 +63,6 @@ type QueueMessage<Body> = {
76
63
  });
77
64
  /** Acknowledgement and retry result returned by the Workers Vitest plugin. */
78
65
  type QueueResult = Awaited<ReturnType<typeof getQueueResult>>;
79
- /** Result of invoking a queue consumer through {@link queue}. */
80
66
  interface QueueRunResult<Body> {
81
67
  readonly batch: globalThis.MessageBatch<Body>;
82
68
  readonly result: QueueResult;
@@ -94,28 +80,19 @@ declare const queue: <Body, Instance extends QueueWorker>(Worker: WorkerConstruc
94
80
  * passed to `use` for direct access.
95
81
  */
96
82
  declare const runInDurableObject: <Object extends DurableObject, A, E, R>(stub: DurableObjectStub<Object>, use: (instance: Object, state: DurableObjectStateService) => Effect.Effect<A, E, R>) => Effect.Effect<A, E, Exclude<R, DurableObjectState>>;
97
- /** Immediately runs and removes a scheduled Durable Object alarm. */
98
83
  declare const runDurableObjectAlarm: (stub: DurableObjectStub<DurableObject<Cloudflare.Env, {}>>) => Effect.Effect<boolean, never, never>;
99
- /** Options controlling how Durable Object eviction handles WebSockets. */
100
84
  interface DurableObjectEvictionOptions {
101
85
  readonly webSockets?: "close" | "hibernate";
102
86
  }
103
- /** Gracefully evicts one running Durable Object while preserving durable storage. */
104
87
  declare const evictDurableObject: (stub: DurableObjectStub<DurableObject<Cloudflare.Env, {}>>, options?: DurableObjectEvictionOptions | undefined) => Effect.Effect<void, never, never>;
105
- /** Lists all IDs created in a Durable Object namespace. */
106
88
  declare const listDurableObjectIds: <Object extends DurableObject | undefined>(namespace: DurableObjectNamespace<Object>) => Effect.Effect<DurableObjectId[], never, never>;
107
- /** Deletes data from all bindings attached to the current test Worker. */
108
89
  declare const reset: () => Effect.Effect<void, never, never>;
109
- /** Aborts all Durable Object instances without deleting their persisted data. */
110
90
  declare const abortAllDurableObjects: () => Effect.Effect<void, never, never>;
111
- /** Gracefully evicts all running Durable Objects while preserving durable storage. */
112
91
  declare const evictAllDurableObjects: (options?: DurableObjectEvictionOptions | undefined) => Effect.Effect<void, never, never>;
113
- /** A D1 migration accepted by the Workers Vitest plugin. */
114
92
  interface D1Migration {
115
93
  readonly name: string;
116
94
  readonly queries: ReadonlyArray<string>;
117
95
  }
118
- /** Applies all D1 migrations that have not already been recorded. */
119
96
  declare const applyD1Migrations: (database: D1Database, migrations: readonly D1Migration[], migrationsTableName?: string | undefined) => Effect.Effect<void, never, never>;
120
97
  type NativeSecretsStoreAdmin = ReturnType<typeof adminSecretsStore$1>;
121
98
  /** Secret metadata returned by {@link SecretsStoreAdmin.list}. */
@@ -141,17 +118,14 @@ declare const adminSecretsStore: (binding: {
141
118
  }) => Effect.Effect<SecretsStoreAdmin, never, never>;
142
119
  type NativeWorkflowIntrospector = Awaited<ReturnType<typeof introspectWorkflow$1>>;
143
120
  type NativeWorkflowInstanceIntrospector = Awaited<ReturnType<typeof introspectWorkflowInstance$1>>;
144
- /** Identifies one occurrence of a Workflow step or sleep. */
145
121
  interface WorkflowStepTarget {
146
122
  readonly name: string;
147
123
  readonly index?: number;
148
124
  }
149
- /** Event delivered to a mocked Workflow `waitForEvent` operation. */
150
125
  interface WorkflowMockEvent {
151
126
  readonly type: string;
152
127
  readonly payload: unknown;
153
128
  }
154
- /** Effect-native Workflow behavior modifier. */
155
129
  interface WorkflowInstanceModifier {
156
130
  readonly disableSleeps: (steps?: ReadonlyArray<WorkflowStepTarget>) => Effect.Effect<void>;
157
131
  readonly disableRetryDelays: (steps?: ReadonlyArray<WorkflowStepTarget>) => Effect.Effect<void>;
@@ -162,7 +136,6 @@ interface WorkflowInstanceModifier {
162
136
  readonly forceEventTimeout: (step: WorkflowStepTarget) => Effect.Effect<void>;
163
137
  }
164
138
  type WorkflowMockResult = Schema.Schema.Type<typeof Schema.Unknown>;
165
- /** Effect-native introspector for one Workflow instance. */
166
139
  interface WorkflowInstanceIntrospector {
167
140
  readonly raw: NativeWorkflowInstanceIntrospector;
168
141
  readonly modify: <A, E, R>(use: (modifier: WorkflowInstanceModifier) => Effect.Effect<A, E, R>) => Effect.Effect<A, E, R>;
@@ -174,7 +147,6 @@ interface WorkflowInstanceIntrospector {
174
147
  readonly message: string;
175
148
  }>;
176
149
  }
177
- /** Effect-native introspector for subsequently created Workflow instances. */
178
150
  interface WorkflowIntrospector {
179
151
  readonly raw: NativeWorkflowIntrospector;
180
152
  readonly modifyAll: <A, E, R>(use: (modifier: WorkflowInstanceModifier) => Effect.Effect<A, E, R>) => Effect.Effect<A, E, R>;
package/dist/Vitest.mjs CHANGED
@@ -1,5 +1,5 @@
1
- import { a as WorkerEnvironment, i as WorkerConfig } from "./ErrorMessage-BM0K-Nik.mjs";
2
- import { r as fromDurableObjectState, t as DurableObjectState } from "./DurableObjectState-CVLLse69.mjs";
1
+ import { a as WorkerEnvironment, i as WorkerConfig } from "./ErrorMessage-Byx2OgNd.mjs";
2
+ import { r as fromDurableObjectState, t as DurableObjectState } from "./DurableObjectState-De4ZojhY.mjs";
3
3
  import { ConfigProvider, Effect, Exit, Layer } from "effect";
4
4
  import { env } from "cloudflare:workers";
5
5
  import { abortAllDurableObjects as abortAllDurableObjects$1, adminSecretsStore as adminSecretsStore$1, applyD1Migrations as applyD1Migrations$1, createExecutionContext, createMessageBatch, createPagesEventContext, createScheduledController, evictAllDurableObjects as evictAllDurableObjects$1, evictDurableObject as evictDurableObject$1, getQueueResult, introspectWorkflow as introspectWorkflow$1, introspectWorkflowInstance as introspectWorkflowInstance$1, listDurableObjectIds as listDurableObjectIds$1, reset as reset$1, runDurableObjectAlarm as runDurableObjectAlarm$1, runInDurableObject as runInDurableObject$1, waitOnExecutionContext } from "cloudflare:test";
@@ -11,15 +11,7 @@ import { abortAllDurableObjects as abortAllDurableObjects$1, adminSecretsStore a
11
11
  * run inside the Workers test runtime, where `cloudflare:test` is available.
12
12
  */
13
13
  const currentEnv = env;
14
- /**
15
- * Provides the Workers test environment as both {@link WorkerEnvironment} and
16
- * the active Effect `ConfigProvider`.
17
- */
18
14
  const layer = Layer.mergeAll(Layer.succeed(WorkerEnvironment, currentEnv), ConfigProvider.layer(WorkerConfig.providerFromEnv(currentEnv)));
19
- /**
20
- * Creates an `ExecutionContext` and drains all `waitUntil` work before the
21
- * returned effect completes, including when `use` fails or is interrupted.
22
- */
23
15
  const withExecutionContext = Effect.fn("effect-cf/vitest/withExecutionContext")(function* (use) {
24
16
  return yield* Effect.acquireUseRelease(Effect.sync(createExecutionContext), use, (context) => Effect.promise(() => waitOnExecutionContext(context)));
25
17
  });
@@ -78,31 +70,24 @@ const runInDurableObject = Effect.fn("effect-cf/vitest/runInDurableObject")(func
78
70
  return Effect.runPromiseExitWith(context)(effect);
79
71
  }));
80
72
  });
81
- /** Immediately runs and removes a scheduled Durable Object alarm. */
82
73
  const runDurableObjectAlarm = Effect.fn("effect-cf/vitest/runDurableObjectAlarm")(function* (stub) {
83
74
  return yield* Effect.promise(() => runDurableObjectAlarm$1(stub));
84
75
  });
85
- /** Gracefully evicts one running Durable Object while preserving durable storage. */
86
76
  const evictDurableObject = Effect.fn("effect-cf/vitest/evictDurableObject")(function* (stub, options) {
87
77
  yield* Effect.promise(() => evictDurableObject$1(stub, options));
88
78
  });
89
- /** Lists all IDs created in a Durable Object namespace. */
90
79
  const listDurableObjectIds = Effect.fn("effect-cf/vitest/listDurableObjectIds")(function* (namespace) {
91
80
  return yield* Effect.promise(() => listDurableObjectIds$1(namespace));
92
81
  });
93
- /** Deletes data from all bindings attached to the current test Worker. */
94
82
  const reset = Effect.fn("effect-cf/vitest/reset")(function* () {
95
83
  yield* Effect.promise(reset$1);
96
84
  });
97
- /** Aborts all Durable Object instances without deleting their persisted data. */
98
85
  const abortAllDurableObjects = Effect.fn("effect-cf/vitest/abortAllDurableObjects")(function* () {
99
86
  yield* Effect.promise(abortAllDurableObjects$1);
100
87
  });
101
- /** Gracefully evicts all running Durable Objects while preserving durable storage. */
102
88
  const evictAllDurableObjects = Effect.fn("effect-cf/vitest/evictAllDurableObjects")(function* (options) {
103
89
  yield* Effect.promise(() => evictAllDurableObjects$1(options));
104
90
  });
105
- /** Applies all D1 migrations that have not already been recorded. */
106
91
  const applyD1Migrations = Effect.fn("effect-cf/vitest/applyD1Migrations")(function* (database, migrations, migrationsTableName) {
107
92
  yield* Effect.promise(() => applyD1Migrations$1(database, migrations.map(({ name, queries }) => ({
108
93
  name,
@@ -1,5 +1,5 @@
1
- import { c as WorkerEnvironment, r as BindingValidationError, t as BindingNotFoundError } from "./Binding-xJJJPmiD.mjs";
2
- import { x as ServiceFreeSchema } from "./DurableObjectState-BpRjz6-q.mjs";
1
+ import { c as WorkerEnvironment, r as BindingValidationError, t as BindingNotFoundError } from "./Binding-DKcLrQCM.mjs";
2
+ import { w as ServiceFreeSchema } from "./DurableObjectState-CrEunfQ-.mjs";
3
3
  import { Context, Effect, Option, Schema } from "effect";
4
4
  declare namespace WorkflowBinding_d_exports {
5
5
  export { WorkflowBindingClient, WorkflowBindingDefinition, WorkflowInstance, WorkflowInstanceCreateBatchOptions, WorkflowInstanceCreateOptions, WorkflowInstanceEvent, WorkflowInstanceLocationHint, WorkflowInstanceRestartOptions, WorkflowInstanceStatus, WorkflowInstanceStatusName, WorkflowInstanceTerminateOptions, WorkflowOperationError, WorkflowResultDecodeError, isWorkflow, layer, makeClient };
@@ -36,11 +36,8 @@ interface WorkflowInstanceEvent {
36
36
  readonly payload: unknown;
37
37
  }
38
38
  interface WorkflowBindingDefinition<Payload extends ServiceFreeSchema, Result extends ServiceFreeSchema> {
39
- /** Binding name as configured in `wrangler.jsonc`. */
40
39
  readonly binding: string;
41
- /** Codec used to encode payloads passed to `Workflow.create`. */
42
40
  readonly payload: Payload;
43
- /** Codec used to decode completed workflow status output. */
44
41
  readonly result: Result;
45
42
  }
46
43
  interface WorkflowBindingClient<Payload extends ServiceFreeSchema, Result extends ServiceFreeSchema> {