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,16 +1,14 @@
1
- import { c as WorkerEnvironment, n as BindingService, r as BindingValidationError, s as WorkerEnv, t as BindingNotFoundError } from "./Binding-xJJJPmiD.mjs";
2
- import { Cause, Context, Duration, Effect, Layer, Option, Predicate, Schema, Scope } from "effect";
1
+ import { c as WorkerEnvironment, n as BindingService, r as BindingValidationError, s as WorkerEnv, t as BindingNotFoundError } from "./Binding-DKcLrQCM.mjs";
2
+ import { Cause, Context, Duration, Effect, Layer, Option, Predicate, Schema, Scope, Tracer } from "effect";
3
3
  import { HttpServerRequest, HttpServerResponse } from "effect/unstable/http";
4
4
  import { RpcStub, RpcTarget, WorkerEntrypoint } from "cloudflare:workers";
5
5
  declare namespace DurableObjectStorage_d_exports {
6
6
  export { DurableObjectStorage, DurableObjectTransaction, SchemaBackedSyncKvStorage, SqlCursor, SqlStorage, SqlStorageValue, StorageOperationError, SyncKvDefinition, SyncKvStorage, fromDurableObjectStorage };
7
7
  }
8
- /** Supported primitive value types for Durable Object SQL APIs. */
9
8
  type SqlStorageValue = globalThis.SqlStorageValue;
10
- declare const StorageOperationError_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 & {
9
+ declare const StorageOperationError_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]; }>) => Cause.YieldableError & {
11
10
  readonly _tag: "StorageOperationError";
12
11
  } & Readonly<A>;
13
- /** Error type used when a storage operation throws or rejects. */
14
12
  declare class StorageOperationError extends StorageOperationError_base<{
15
13
  readonly operation: string;
16
14
  readonly cause: unknown;
@@ -18,9 +16,6 @@ declare class StorageOperationError extends StorageOperationError_base<{
18
16
  get message(): string;
19
17
  }
20
18
  type StorageEffect<A> = Effect.Effect<A, StorageOperationError>;
21
- /**
22
- * Effect wrapper for Cloudflare SQL cursor operations.
23
- */
24
19
  interface SqlCursor<T extends Record<string, SqlStorageValue>> {
25
20
  next(): StorageEffect<{
26
21
  done?: false;
@@ -36,17 +31,10 @@ interface SqlCursor<T extends Record<string, SqlStorageValue>> {
36
31
  readonly rowsRead: StorageEffect<number>;
37
32
  readonly rowsWritten: StorageEffect<number>;
38
33
  }
39
- /**
40
- * Effect wrapper for Durable Object SQLite APIs.
41
- */
42
34
  interface SqlStorage {
43
- /** Executes a SQL statement and returns a typed cursor. */
44
35
  exec<T extends Record<string, SqlStorageValue>>(query: string, ...bindings: Array<SqlStorageValue>): StorageEffect<SqlCursor<T>>;
45
36
  readonly databaseSize: number;
46
37
  }
47
- /**
48
- * Schema pair used by `SyncKvStorage.schema(...)`.
49
- */
50
38
  interface SyncKvDefinition<Key, Value, EncodedValue> {
51
39
  readonly key: Schema.Codec<Key, string>;
52
40
  readonly value: Schema.Codec<Value, EncodedValue>;
@@ -60,9 +48,6 @@ interface SchemaBackedSyncKvStorage<Key, Value> {
60
48
  delete(key: Key): Effect.Effect<boolean, unknown>;
61
49
  list(options?: globalThis.SyncKvListOptions): Effect.Effect<Array<[Key, Value]>, unknown>;
62
50
  }
63
- /**
64
- * Effect wrapper for synchronous KV attached to Durable Object SQLite storage.
65
- */
66
51
  interface SyncKvStorage {
67
52
  get<T = unknown>(key: string): StorageEffect<T | undefined>;
68
53
  put<T>(key: string, value: T): StorageEffect<void>;
@@ -84,23 +69,9 @@ interface DurableObjectTransaction {
84
69
  rollback(): StorageEffect<void>;
85
70
  getAlarm(options?: globalThis.DurableObjectGetAlarmOptions): StorageEffect<number | null>;
86
71
  setAlarm(scheduledTime: number | Date, options?: globalThis.DurableObjectSetAlarmOptions): StorageEffect<void>;
87
- /** Schedules the alarm after a delay measured by the Effect clock. */
88
72
  setAlarmAfter(delay: Duration.Input, options?: globalThis.DurableObjectSetAlarmOptions): StorageEffect<void>;
89
73
  deleteAlarm(options?: globalThis.DurableObjectSetAlarmOptions): StorageEffect<void>;
90
74
  }
91
- /**
92
- * Effect wrapper around Cloudflare Durable Object storage.
93
- *
94
- * @example
95
- * ```ts
96
- * const program = Effect.gen(function* () {
97
- * const state = yield* DurableObjectState;
98
- * yield* state.storage.put("counter", 1);
99
- * const value = yield* state.storage.get<number>("counter");
100
- * return value;
101
- * });
102
- * ```
103
- */
104
75
  interface DurableObjectStorage {
105
76
  get<T = unknown>(key: string, options?: globalThis.DurableObjectGetOptions): StorageEffect<T | undefined>;
106
77
  put<T>(key: string, value: T, options?: globalThis.DurableObjectPutOptions): StorageEffect<void>;
@@ -112,7 +83,6 @@ interface DurableObjectStorage {
112
83
  deleteAll(options?: globalThis.DurableObjectPutOptions): StorageEffect<void>;
113
84
  getAlarm(options?: globalThis.DurableObjectGetAlarmOptions): StorageEffect<number | null>;
114
85
  setAlarm(scheduledTime: number | Date, options?: globalThis.DurableObjectSetAlarmOptions): StorageEffect<void>;
115
- /** Schedules the alarm after a delay measured by the Effect clock. */
116
86
  setAlarmAfter(delay: Duration.Input, options?: globalThis.DurableObjectSetAlarmOptions): StorageEffect<void>;
117
87
  deleteAlarm(options?: globalThis.DurableObjectSetAlarmOptions): StorageEffect<void>;
118
88
  /**
@@ -129,26 +99,21 @@ interface DurableObjectStorage {
129
99
  transaction<A, E, R>(closure: (txn: DurableObjectTransaction) => Effect.Effect<A, E, R>): Effect.Effect<A, E | StorageOperationError, R>;
130
100
  /** Flushes pending writes to disk. */
131
101
  sync(): StorageEffect<void>;
132
- /** SQLite-backed Durable Object storage point-in-time recovery API only. */
102
+ /** Requires SQLite-backed Durable Object storage. */
133
103
  getCurrentBookmark(): StorageEffect<string>;
134
- /** SQLite-backed Durable Object storage point-in-time recovery API only. */
104
+ /** Requires SQLite-backed Durable Object storage. */
135
105
  onNextSessionRestoreBookmark(bookmark: string): StorageEffect<string>;
136
106
  readonly sql: SqlStorage;
137
107
  readonly kv: SyncKvStorage;
138
108
  }
139
- /**
140
- * Wraps native Cloudflare storage APIs as Effect-returning helpers.
141
- */
142
109
  declare const fromDurableObjectStorage: (storage: globalThis.DurableObjectStorage) => DurableObjectStorage;
143
110
  declare namespace DurableObjectWebSocket_d_exports {
144
111
  export { AcceptUpgradeOptions, AcceptedUpgrade, AttachmentInvalidPolicy, AttachmentRehydrateOptions, DurableWebSocket, DurableWebSocketAttachment, DurableWebSocketAttachmentError, DurableWebSocketCloseError, DurableWebSocketHandlers, DurableWebSocketSendData, DurableWebSocketSendError, RehydratedDurableWebSocket, acceptUpgrade, attachment, fromWebSocket, handlers };
145
112
  }
146
- /** Data supported by Cloudflare websocket `send`. */
147
113
  type DurableWebSocketSendData = string | ArrayBuffer | ArrayBufferView;
148
114
  declare const DurableWebSocketSendError_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 & {
149
115
  readonly _tag: "DurableWebSocketSendError";
150
116
  } & Readonly<A>;
151
- /** Error raised when sending on a Durable Object websocket fails. */
152
117
  declare class DurableWebSocketSendError extends DurableWebSocketSendError_base<{
153
118
  readonly cause: unknown;
154
119
  }> {
@@ -157,7 +122,6 @@ declare class DurableWebSocketSendError extends DurableWebSocketSendError_base<{
157
122
  declare const DurableWebSocketCloseError_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 & {
158
123
  readonly _tag: "DurableWebSocketCloseError";
159
124
  } & Readonly<A>;
160
- /** Error raised when closing a Durable Object websocket fails. */
161
125
  declare class DurableWebSocketCloseError extends DurableWebSocketCloseError_base<{
162
126
  readonly cause: unknown;
163
127
  }> {
@@ -173,56 +137,30 @@ declare class DurableWebSocketAttachmentError extends DurableWebSocketAttachment
173
137
  }> {
174
138
  get message(): string;
175
139
  }
176
- /** Effect-native wrapper around a hibernatable Durable Object websocket. */
177
140
  interface DurableWebSocket<Attachment = unknown> {
178
- /** Underlying Cloudflare websocket. */
179
141
  readonly raw: WebSocket;
180
- /** Sends a message through the socket. */
181
142
  send(data: DurableWebSocketSendData): Effect.Effect<void, DurableWebSocketSendError>;
182
- /** Closes the socket. */
183
143
  close(code?: number, reason?: string): Effect.Effect<void, DurableWebSocketCloseError>;
184
144
  /** Serializes hibernation attachment metadata onto the socket. */
185
- serializeAttachment<A = Attachment>(value: A): Effect.Effect<void, DurableWebSocketAttachmentError>;
145
+ serializeAttachment<A extends Attachment = Attachment>(value: A): Effect.Effect<void, DurableWebSocketAttachmentError>;
186
146
  /** Deserializes hibernation attachment metadata from the socket. */
187
147
  readonly deserializeAttachment: Effect.Effect<unknown, DurableWebSocketAttachmentError>;
188
148
  }
189
- /** Wraps a native Cloudflare websocket in the Effect-native Durable Object API. */
190
149
  declare const fromWebSocket: <Attachment = unknown>(raw: WebSocket) => DurableWebSocket<Attachment>;
191
- /**
192
- * Options for accepting an incoming websocket request in a Durable Object.
193
- */
194
150
  interface AcceptUpgradeOptions<Attachment = unknown> {
195
- /** Optional websocket tags for Durable Object hibernation filtering. */
196
151
  readonly tags?: ReadonlyArray<string> | undefined;
197
152
  /** Optional attachment serialized onto the server socket. */
198
153
  readonly attachment?: Attachment | undefined;
199
154
  }
200
- /**
201
- * Result of a websocket upgrade accepted by {@link acceptUpgrade}.
202
- */
203
155
  interface AcceptedUpgrade<Attachment = unknown> {
204
156
  readonly client: WebSocket;
205
157
  readonly server: DurableWebSocket<Attachment>;
206
158
  readonly response: Response;
207
159
  }
208
- /**
209
- * Accepts a websocket upgrade and registers the server socket on `DurableObjectState`.
210
- *
211
- * @example
212
- * ```ts
213
- * const response = yield* DurableObjectWebSocket.acceptUpgrade({
214
- * tags: ["room:general"],
215
- * });
216
- *
217
- * return response.response;
218
- * ```
219
- */
220
160
  declare const acceptUpgrade: <Attachment = unknown>(options?: AcceptUpgradeOptions<Attachment> | undefined) => Effect.Effect<AcceptedUpgrade<Attachment>, DurableWebSocketAttachmentError, DurableObjectState>;
221
161
  type AttachmentInvalidPolicy = "ignore" | "ignore-and-close" | "fail";
222
162
  interface AttachmentRehydrateOptions {
223
- /** Optional Durable Object websocket tag filter. */
224
163
  readonly tag?: string | undefined;
225
- /** Invalid attachment behavior. Defaults to skipping invalid sockets. */
226
164
  readonly onInvalid?: AttachmentInvalidPolicy | undefined;
227
165
  }
228
166
  interface RehydratedDurableWebSocket<Attachment> {
@@ -235,14 +173,12 @@ interface DurableWebSocketAttachment<Attachment, Encoded> {
235
173
  rehydrate(options?: AttachmentRehydrateOptions): Effect.Effect<Array<RehydratedDurableWebSocket<Attachment>>, DurableWebSocketAttachmentError, DurableObjectState>;
236
174
  readonly schema: Schema.Codec<Attachment, Encoded, never, never>;
237
175
  }
238
- /** Creates typed attachment helpers for accepted and rehydrated sockets. */
239
176
  declare const attachment: <const AttachmentSchema extends Schema.Codec<any, any, never, never>>(schema: AttachmentSchema) => DurableWebSocketAttachment<Schema.Schema.Type<AttachmentSchema>, Schema.Codec.Encoded<AttachmentSchema>>;
240
177
  interface DurableWebSocketHandlers<R = never, E = unknown> {
241
178
  readonly message?: (socket: DurableWebSocket, message: string | ArrayBuffer) => Effect.Effect<void, E, R>;
242
179
  readonly close?: (socket: DurableWebSocket, code: number, reason: string, wasClean: boolean) => Effect.Effect<void, E, R>;
243
180
  readonly error?: (socket: DurableWebSocket, cause: unknown) => Effect.Effect<void, E, R>;
244
181
  }
245
- /** Maps compact websocket lifecycle handler names to `DurableObject.make` options. */
246
182
  declare const handlers: <R = never, E = unknown>(options: DurableWebSocketHandlers<R, E>) => {
247
183
  webSocketMessage: ((socket: DurableWebSocket, message: string | ArrayBuffer) => Effect.Effect<void, E, R>) | undefined;
248
184
  webSocketClose: ((socket: DurableWebSocket, code: number, reason: string, wasClean: boolean) => Effect.Effect<void, E, R>) | undefined;
@@ -337,10 +273,10 @@ declare const isWireError: (error: WireValue) => error is WireError;
337
273
  * survive Cloudflare RPC serialization, which drops custom error properties.
338
274
  */
339
275
  declare const encodeWireError: (error: WireValue) => WireValue;
340
- /** Restores package RPC errors from the {@link encodeWireError} envelope. */
341
276
  declare const decodeWireError: (cause: WireValue) => WireValue;
277
+ declare const reservedMethodNameValues: readonly ["constructor", "fetch", "connect", "alarm", "webSocketMessage", "webSocketClose", "webSocketError", "then", "dup", "dispose", "serialize", "deserialize"];
342
278
  declare const reservedMethodNames: Set<string>;
343
- type ReservedMethodName$3 = "constructor" | "fetch" | "connect" | "alarm" | "webSocketMessage" | "webSocketClose" | "webSocketError" | "then" | "dup" | "dispose" | "serialize" | "deserialize";
279
+ type ReservedMethodName$3 = (typeof reservedMethodNameValues)[number];
344
280
  type ServiceFreeSchema$1 = Schema.Codec<any, any, never, never>;
345
281
  interface Method$2<Args extends ReadonlyArray<ServiceFreeSchema$1> = ReadonlyArray<ServiceFreeSchema$1>, Success extends ServiceFreeSchema$1 = ServiceFreeSchema$1> {
346
282
  readonly args: Args;
@@ -349,7 +285,6 @@ interface Method$2<Args extends ReadonlyArray<ServiceFreeSchema$1> = ReadonlyArr
349
285
  declare namespace Method$2 {
350
286
  export type Any = Method$2<ReadonlyArray<ServiceFreeSchema$1>, ServiceFreeSchema$1>;
351
287
  type ArgsFromSchemas<Args extends ReadonlyArray<ServiceFreeSchema$1>> = Args extends readonly [] ? [] : Args extends readonly [infer Head extends ServiceFreeSchema$1, ...infer Tail extends ReadonlyArray<ServiceFreeSchema$1>] ? [Schema.Schema.Type<Head>, ...ArgsFromSchemas<Tail>] : Array<Schema.Schema.Type<Args[number]>>;
352
- /** Method schemas cross the wire through their canonical JSON codec. */
353
288
  type EncodedArgsFromSchemas<Args extends ReadonlyArray<ServiceFreeSchema$1>> = { [Index in keyof Args]: Schema.Json; };
354
289
  export type Args<Self extends Any> = ArgsFromSchemas<Self["args"]>;
355
290
  export type EncodedArgs<Self extends Any> = EncodedArgsFromSchemas<Self["args"]>;
@@ -395,9 +330,7 @@ type MessageSendRequest<Body> = CloudflareMessageSendRequest<Body>;
395
330
  type QueueProducer<Body> = Pick<CloudflareQueue<Body>, "send"> & Partial<Pick<CloudflareQueue<Body>, "sendBatch" | "metrics">>;
396
331
  type QueueCandidate = Parameters<typeof Predicate.isUnknown>[0];
397
332
  interface QueueBindingDefinition<Message extends ServiceFreeSchema$1> {
398
- /** Binding name as configured in `wrangler.jsonc`. */
399
333
  readonly binding: string;
400
- /** Codec used to encode messages before sending them to Cloudflare Queues. */
401
334
  readonly message: Message;
402
335
  }
403
336
  interface QueueBindingClient<Message extends ServiceFreeSchema$1> {
@@ -515,6 +448,53 @@ declare const Tag$1: <Self>() => <Id extends string, Message extends Definition$
515
448
  declare const implement$1: typeof implement$2;
516
449
  type Handler<ROut, Self extends Definition$2.Any> = Handler$1<ROut, Self>;
517
450
  type Options$1<ROut, Self extends Definition$2.Any> = Options$2<ROut, Self>;
451
+ declare namespace RpcTracing_d_exports {
452
+ export { ReceiverOptions, RpcInvocationInfo, RpcTraceContext, withRpcClientSpan, withRpcServerSpan, withRpcTraceContext };
453
+ }
454
+ /**
455
+ * Live native RPC metadata. Opted-in receivers reserve a valid trailing value
456
+ * with this tag for transport context; do not use it as a final domain argument.
457
+ * Never store this in durable messages or envelopes.
458
+ */
459
+ declare const RpcTraceContext: Schema.Struct<{
460
+ readonly _tag: Schema.Literal<"effect-cf/RpcTraceContext/v1">;
461
+ readonly traceId: Schema.String;
462
+ readonly spanId: Schema.String;
463
+ readonly sampled: Schema.Boolean;
464
+ }>;
465
+ type RpcTraceContext = typeof RpcTraceContext.Type;
466
+ interface ReceiverOptions {
467
+ /** Stable service name, never an instance id or capability URL. */
468
+ readonly service: string;
469
+ }
470
+ /** Per-invocation metadata passed to Worker and DurableObject RunSymbol overrides. */
471
+ interface RpcInvocationInfo {
472
+ readonly service: string;
473
+ readonly method: string;
474
+ /** Native arguments with valid, opted-in trace metadata removed. Do not log them. */
475
+ readonly args: ReadonlyArray<unknown>;
476
+ /**
477
+ * Set after a definition-backed receiver decodes its arguments, before its
478
+ * handler runs. Absent before decoding and when decoding fails. Do not log it.
479
+ */
480
+ readonly decodedArgs?: ReadonlyArray<unknown>;
481
+ readonly parent?: RpcTraceContext;
482
+ }
483
+ /**
484
+ * Appends the current live parent only for a receiver that has opted in.
485
+ * Call this inside the CLIENT span, immediately before the native invocation.
486
+ * With no valid propagating parent, the original argument array is returned.
487
+ */
488
+ declare const withRpcTraceContext: (args: readonly unknown[]) => Effect.Effect<readonly unknown[], never, never>;
489
+ /** Wrap the whole call, including native result resolution and success decoding. */
490
+ declare const withRpcClientSpan: <A, E, R>(effect: Effect.Effect<A, E, R>, binding: string, method: string) => Effect.Effect<A, E, Exclude<R, Tracer.ParentSpan>>;
491
+ /**
492
+ * Optional application instrumentation for the entire receiver effect.
493
+ * Use in a RunSymbol override to include argument decode, handler and encode.
494
+ * Records stable service/method attributes and failure status, not argument or
495
+ * error payloads. The original typed failure still propagates to the caller.
496
+ */
497
+ declare const withRpcServerSpan: <A, E, R>(effect: Effect.Effect<A, E, R>, invocation: RpcInvocationInfo) => Effect.Effect<A, E, Exclude<R, Tracer.ParentSpan>>;
518
498
  //#endregion
519
499
  //#region src/internal/RpcInvocation.d.ts
520
500
  type AnyArgs = Array<any>;
@@ -526,28 +506,22 @@ declare namespace ServiceBinding_d_exports {
526
506
  export { Service, ServiceBindingClient, ServiceBindingDefinition, ServiceBindingEffectClient, ServiceBindingFetchError, ServiceBindingRpcError, ServiceBindingStaticClient, ServiceFetcher, isServiceBindingClient, layer, makeClient, makeDirectMethods };
527
507
  }
528
508
  declare const TypeId: "effect-cf/ServiceBinding";
529
- /**
530
- * Minimum shape for a Cloudflare service binding.
531
- */
532
509
  interface ServiceFetcher {
533
510
  fetch(input: RequestInfo | URL, init?: RequestInit): Promise<Response>;
534
511
  }
535
512
  type RpcClient<Api> = { readonly [Key in keyof Api as Key extends string ? Api[Key] extends ((...args: Array<any>) => any) ? Key : never : never]: Api[Key]; };
536
513
  type ReservedMethodName$2 = ReservedMethodName$1 | "fetch";
537
- /**
538
- * Native Cloudflare service object including optional RPC methods.
539
- */
540
514
  type ServiceBindingClient<Api extends object> = ServiceFetcher & RpcClient<Provider<Api, ReservedMethodName$2>>;
541
515
  type ApiFromDefinition<Definition$12> = Definition$12 extends Definition.Any ? ServerApi$1<Definition$12> : never;
542
516
  type ApiOrDefinition<Api extends object, Definition> = [Api] extends [never] ? ApiFromDefinition<Definition> : Api;
543
517
  /**
544
518
  * Binding metadata used to create an Effect service from a Worker binding.
545
519
  */
546
- interface ServiceBindingDefinition<Definition$8 extends Definition.Any | undefined = undefined> {
547
- /** Binding name as configured in `wrangler.jsonc`. */
520
+ interface ServiceBindingDefinition<Definition$7 extends Definition.Any | undefined = undefined> {
548
521
  readonly binding: string;
549
- /** Optional RPC schema used for argument/result encoding. */
550
- readonly definition?: Definition$8;
522
+ readonly definition?: Definition$7;
523
+ /** Append live trace context only when the receiver also enables rpcTracing. */
524
+ readonly rpcTracing?: boolean;
551
525
  }
552
526
  declare const ServiceBindingFetchError_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 & {
553
527
  readonly _tag: "ServiceBindingFetchError";
@@ -579,25 +553,9 @@ type ServiceMethodArgs<Api, Method extends keyof Api> = AsyncMethodArgs<Api, Met
579
553
  type ServiceMethodSuccess<Api, Method extends keyof Api> = AsyncMethodSuccess<Api, Method>;
580
554
  type ServiceMethodCloudflareReturn<Api, Method extends keyof Api> = AsyncMethodCloudflareReturn<Api, Method>;
581
555
  type ServiceCall<R, Api> = <Method extends ServiceMethodKey<Api>>(method: Method, ...args: ServiceMethodArgs<Api, Method>) => Effect.Effect<ServiceMethodSuccess<Api, Method>, ServiceBindingRpcError, R>;
582
- type DefinitionDirectMethods<R, Definition$11 extends Definition.Any> = { readonly [Method in Definition$3.MethodNames<Definition$11>]: (...args: Method$2.Args<Definition$11["methods"][Method]>) => Effect.Effect<Method$2.Success<Definition$11["methods"][Method]>, ServiceBindingRpcError, R>; };
583
- type DirectMethods<R, Definition$10> = Definition$10 extends Definition.Any ? DefinitionDirectMethods<R, Definition$10> : {};
584
- type ServiceBindingEffectClient<Api extends object, Definition$4 extends Definition.Any | undefined = undefined> = DirectMethods<never, Definition$4> & {
585
- /**
586
- * Forwards an HTTP request to the bound Worker service.
587
- *
588
- * Use this when the service binding is acting as an HTTP origin rather than a
589
- * Cloudflare RPC target.
590
- *
591
- * @example
592
- * ```ts
593
- * import { Effect } from "effect";
594
- *
595
- * const program = Effect.gen(function* () {
596
- * const api = yield* ApiWorker;
597
- * return yield* api.fetch(new Request("https://internal.example/users"));
598
- * });
599
- * ```
600
- */
556
+ type DefinitionDirectMethods<R, Definition$4 extends Definition.Any> = { readonly [Method in Definition$3.MethodNames<Definition$4>]: (...args: Method$2.Args<Definition$4["methods"][Method]>) => Effect.Effect<Method$2.Success<Definition$4["methods"][Method]>, ServiceBindingRpcError, R>; };
557
+ type DirectMethods<R, Definition$13> = Definition$13 extends Definition.Any ? DefinitionDirectMethods<R, Definition$13> : {};
558
+ type ServiceBindingEffectClient<Api extends object, Definition$8 extends Definition.Any | undefined = undefined> = DirectMethods<never, Definition$8> & {
601
559
  readonly fetch: (input: RequestInfo | URL, init?: RequestInit) => Effect.Effect<globalThis.Response, ServiceBindingFetchError>;
602
560
  /**
603
561
  * Invokes a Worker RPC method and returns Cloudflare's raw RPC result.
@@ -607,20 +565,6 @@ type ServiceBindingEffectClient<Api extends object, Definition$4 extends Definit
607
565
  * promise-like value and it does not decode definition-backed success schemas.
608
566
  *
609
567
  * Most application code should use {@link call} instead.
610
- *
611
- * @example
612
- * ```ts
613
- * import { Effect } from "effect";
614
- *
615
- * const program = Effect.gen(function* () {
616
- * const counter = yield* CounterService;
617
- *
618
- * const result = yield* counter.rpc("increment", 41);
619
- * const value = yield* Effect.promise(() => result);
620
- *
621
- * return value;
622
- * });
623
- * ```
624
568
  */
625
569
  readonly rpc: <Method extends ServiceMethodKey<Api>>(method: Method, ...args: ServiceMethodArgs<Api, Method>) => Effect.Effect<ServiceMethodCloudflareReturn<Api, Method>, ServiceBindingRpcError>;
626
570
  /**
@@ -628,18 +572,6 @@ type ServiceBindingEffectClient<Api extends object, Definition$4 extends Definit
628
572
  * the success value when the binding was created from a definition.
629
573
  *
630
574
  * This is the normal choice when application code wants the final typed value.
631
- *
632
- * @example
633
- * ```ts
634
- * import { Effect } from "effect";
635
- *
636
- * const program = Effect.gen(function* () {
637
- * const counter = yield* CounterService;
638
- * const value = yield* counter.call("increment", 41);
639
- *
640
- * return value;
641
- * });
642
- * ```
643
575
  */
644
576
  readonly call: <Method extends ServiceMethodKey<Api>>(method: Method, ...args: ServiceMethodArgs<Api, Method>) => Effect.Effect<ServiceMethodSuccess<Api, Method>, ServiceBindingRpcError>;
645
577
  /**
@@ -649,71 +581,28 @@ type ServiceBindingEffectClient<Api extends object, Definition$4 extends Definit
649
581
  *
650
582
  * Use this for RPC methods that return Cloudflare RPC resources or other
651
583
  * disposable objects whose lifetime should be tied to an Effect scope.
652
- *
653
- * @example
654
- * ```ts
655
- * import { Effect } from "effect";
656
- *
657
- * const program = Effect.scoped(
658
- * Effect.gen(function* () {
659
- * const files = yield* FileService;
660
- * const handle = yield* files.scopedCall("open", "report.csv");
661
- *
662
- * return yield* handle.read();
663
- * }),
664
- * );
665
- * ```
666
584
  */
667
- readonly scopedCall: <Method extends ServiceMethodKey<Api>>(method: Method, ...args: ServiceMethodArgs<Api, Method>) => Effect.Effect<Awaited<ServiceMethodSuccess<Api, Method>>, unknown, Scope.Scope>;
585
+ readonly scopedCall: <Method extends ServiceMethodKey<Api>>(method: Method, ...args: ServiceMethodArgs<Api, Method>) => Effect.Effect<Awaited<ServiceMethodSuccess<Api, Method>>, ServiceBindingRpcError, Scope.Scope>;
668
586
  };
669
587
  type ServiceBindingStaticClient<R, Api extends object, Definition$5 extends Definition.Any | undefined = undefined> = DirectMethods<R, Definition$5> & {
670
588
  readonly fetch: (input: RequestInfo | URL, init?: RequestInit) => Effect.Effect<globalThis.Response, ServiceBindingFetchError, R>;
671
589
  readonly rpc: <Method extends ServiceMethodKey<Api>>(method: Method, ...args: ServiceMethodArgs<Api, Method>) => Effect.Effect<ServiceMethodCloudflareReturn<Api, Method>, ServiceBindingRpcError, R>;
672
590
  readonly call: <Method extends ServiceMethodKey<Api>>(method: Method, ...args: ServiceMethodArgs<Api, Method>) => Effect.Effect<ServiceMethodSuccess<Api, Method>, ServiceBindingRpcError, R>;
673
- readonly scopedCall: <Method extends ServiceMethodKey<Api>>(method: Method, ...args: ServiceMethodArgs<Api, Method>) => Effect.Effect<Awaited<ServiceMethodSuccess<Api, Method>>, unknown, Scope.Scope | R>;
591
+ readonly scopedCall: <Method extends ServiceMethodKey<Api>>(method: Method, ...args: ServiceMethodArgs<Api, Method>) => Effect.Effect<Awaited<ServiceMethodSuccess<Api, Method>>, ServiceBindingRpcError, Scope.Scope | R>;
674
592
  };
675
593
  type ServiceBindingValue = Schema.Schema.Type<typeof Schema.Unknown>;
676
594
  declare const isServiceBindingClient: <Api extends object>(value: ServiceBindingValue) => value is ServiceBindingClient<Api>;
677
- declare const makeClient: <Api extends object, const Definition$13 extends Definition.Any | undefined = undefined>(definition: ServiceBindingDefinition<Definition$13>) => ((service: ServiceBindingClient<Api>) => ServiceBindingEffectClient<Api, Definition$13>);
678
- declare const layer: <Self, Api extends object, const Definition$6 extends Definition.Any | undefined = undefined>(tag: Context.Service<Self, ServiceBindingEffectClient<Api, Definition$6>>, definition: ServiceBindingDefinition<Definition$6>) => import("effect/Layer").Layer<Self, BindingNotFoundError | BindingValidationError, WorkerEnvironment>;
679
- /**
680
- * Creates a typed Effect service for a Worker service binding.
681
- *
682
- * Returned value includes:
683
- * - a Context tag for dependency injection
684
- * - `fetch(...)` for raw HTTP forwarding
685
- * - `rpc(...)` for raw Cloudflare RPC results
686
- * - `call(...)` for resolved and decoded RPC results
687
- * - `scopedCall(...)` for scoped and decoded disposable RPC results
688
- * - direct RPC methods when `definition` is provided
689
- *
690
- * @example
691
- * ```ts
692
- * const Counter = WorkerDefinition.make("Counter", {
693
- * increment: WorkerDefinition.method({
694
- * args: [Schema.Number],
695
- * success: Schema.Number,
696
- * }),
697
- * });
698
- *
699
- * const CounterLive = Counter.layer({ binding: "COUNTER" });
700
- *
701
- * const program = Effect.gen(function* () {
702
- * const counter = yield* Counter;
703
- * const next = yield* counter.increment(1);
704
- * return next;
705
- * });
706
- * ```
707
- */
708
- declare const Service: <Self, Api extends object = never>() => <Id extends string, const Definition$9 extends Definition.Any | undefined = undefined>(id: Id, definition: ServiceBindingDefinition<Definition$9>) => BindingService<Self, Id, ServiceBindingEffectClient<ApiOrDefinition<Api, Definition$9>, Definition$9>> & DirectMethods<Self, Definition$9> & {
595
+ declare const makeClient: <Api extends object, const Definition$10 extends Definition.Any | undefined = undefined>(definition: ServiceBindingDefinition<Definition$10>) => ((service: ServiceBindingClient<Api>) => ServiceBindingEffectClient<Api, Definition$10>);
596
+ declare const layer: <Self, Api extends object, const Definition$11 extends Definition.Any | undefined = undefined>(tag: Context.Service<Self, ServiceBindingEffectClient<Api, Definition$11>>, definition: ServiceBindingDefinition<Definition$11>) => import("effect/Layer").Layer<Self, BindingNotFoundError | BindingValidationError, WorkerEnvironment>;
597
+ declare const Service: <Self, Api extends object = never>() => <Id extends string, const Definition$6 extends Definition.Any | undefined = undefined>(id: Id, definition: ServiceBindingDefinition<Definition$6>) => BindingService<Self, Id, ServiceBindingEffectClient<ApiOrDefinition<Api, Definition$6>, Definition$6>> & DirectMethods<Self, Definition$6> & {
709
598
  readonly [TypeId]: typeof TypeId;
710
- readonly definition: ServiceBindingDefinition<Definition$9>;
599
+ readonly definition: ServiceBindingDefinition<Definition$6>;
711
600
  readonly fetch: (input: URL | RequestInfo<unknown, CfProperties<unknown>>, init?: RequestInit<CfProperties<unknown>> | undefined) => Effect.Effect<Response, ServiceBindingFetchError, Self>;
712
- readonly rpc: <Method extends ServiceMethodKey<ApiOrDefinition<Api, Definition$9>>>(method: Method, ...args: AsyncMethodArgs<ApiOrDefinition<Api, Definition$9>, Method>) => Effect.Effect<Result$1<AsyncMethodSuccess<ApiOrDefinition<Api, Definition$9>, Method>>, ServiceBindingRpcError, Self>;
713
- readonly call: <Method extends ServiceMethodKey<ApiOrDefinition<Api, Definition$9>>>(method: Method, ...args: AsyncMethodArgs<ApiOrDefinition<Api, Definition$9>, Method>) => Effect.Effect<AsyncMethodSuccess<ApiOrDefinition<Api, Definition$9>, Method>, ServiceBindingRpcError, Self>;
714
- readonly scopedCall: <Method extends ServiceMethodKey<ApiOrDefinition<Api, Definition$9>>>(method: Method, ...args: AsyncMethodArgs<ApiOrDefinition<Api, Definition$9>, Method>) => Effect.Effect<Awaited<AsyncMethodSuccess<ApiOrDefinition<Api, Definition$9>, Method>>, unknown, Self | Scope.Scope>;
601
+ readonly rpc: <Method extends ServiceMethodKey<ApiOrDefinition<Api, Definition$6>>>(method: Method, ...args: AsyncMethodArgs<ApiOrDefinition<Api, Definition$6>, Method>) => Effect.Effect<Result$1<AsyncMethodSuccess<ApiOrDefinition<Api, Definition$6>, Method>>, ServiceBindingRpcError, Self>;
602
+ readonly call: <Method extends ServiceMethodKey<ApiOrDefinition<Api, Definition$6>>>(method: Method, ...args: AsyncMethodArgs<ApiOrDefinition<Api, Definition$6>, Method>) => Effect.Effect<AsyncMethodSuccess<ApiOrDefinition<Api, Definition$6>, Method>, ServiceBindingRpcError, Self>;
603
+ readonly scopedCall: <Method extends ServiceMethodKey<ApiOrDefinition<Api, Definition$6>>>(method: Method, ...args: AsyncMethodArgs<ApiOrDefinition<Api, Definition$6>, Method>) => Effect.Effect<Awaited<AsyncMethodSuccess<ApiOrDefinition<Api, Definition$6>, Method>>, ServiceBindingRpcError, Self | Scope.Scope>;
715
604
  };
716
- declare const makeDirectMethods: <R, Api, Definition$7 extends Definition.Any | undefined>(rpcDefinition: Definition$7 | undefined, call: ServiceCall<R, Api>) => DirectMethods<R, Definition$7>;
605
+ declare const makeDirectMethods: <R, Api, Definition$9 extends Definition.Any | undefined>(rpcDefinition: Definition$9 | undefined, call: ServiceCall<R, Api>) => DirectMethods<R, Definition$9>;
717
606
  declare namespace WorkerDefinition_d_exports {
718
607
  export { Api, Definition, HandlerEffect, Handlers, LayerOptions, Method$1 as Method, Methods, NoReservedMethods, Options, ReservedMethodName$1 as ReservedMethodName, ServerApi$1 as ServerApi, ServiceFreeSchema, Tag, TagClass, Worker, implement, make$1 as make, method };
719
608
  }
@@ -725,7 +614,6 @@ interface Method$1<Args extends ReadonlyArray<ServiceFreeSchema> = ReadonlyArray
725
614
  declare namespace Method$1 {
726
615
  export type Any = Method$1<ReadonlyArray<ServiceFreeSchema>, ServiceFreeSchema>;
727
616
  type ArgsFromSchemas<Args extends ReadonlyArray<ServiceFreeSchema>> = Args extends readonly [] ? [] : Args extends readonly [infer Head extends ServiceFreeSchema, ...infer Tail extends ReadonlyArray<ServiceFreeSchema>] ? [Schema.Schema.Type<Head>, ...ArgsFromSchemas<Tail>] : Array<Schema.Schema.Type<Args[number]>>;
728
- /** Method schemas cross the wire through their canonical JSON codec. */
729
617
  type EncodedArgsFromSchemas<Args extends ReadonlyArray<ServiceFreeSchema>> = { [Index in keyof Args]: Schema.Json; };
730
618
  export type Args<Self extends Any> = ArgsFromSchemas<Self["args"]>;
731
619
  export type EncodedArgs<Self extends Any> = EncodedArgsFromSchemas<Self["args"]>;
@@ -770,6 +658,7 @@ type EventLayerOptions<ROut, REvent, EventLayerError> = [REvent] extends [never]
770
658
  type Options<ROut, Self extends Definition.Any, REvent = never, EventLayerError = never> = BaseOptions<ROut, Self, REvent, EventLayerError> & EventLayerOptions<ROut, REvent, EventLayerError>;
771
659
  type LayerOptions = {
772
660
  readonly binding: string;
661
+ readonly rpcTracing?: boolean;
773
662
  };
774
663
  type TagClass<Self, Id extends string, MethodDefinitions extends Methods> = Context.ServiceClass<Self, Id, ServiceBindingEffectClient<Api<Definition<Id, MethodDefinitions>>, Definition<Id, MethodDefinitions>>> & ServiceBindingStaticClient<Self, Api<Definition<Id, MethodDefinitions>>, Definition<Id, MethodDefinitions>> & {
775
664
  readonly id: Id;
@@ -806,16 +695,10 @@ declare const implement: <ROut, const Self extends Definition.Any>(_definition:
806
695
  */
807
696
  type HandlerEffect<ROut, Self extends Definition.Any, Key extends keyof Self["methods"]> = WorkerRpcHandler<ROut, Method$1.Success<Self["methods"][Key]>>;
808
697
  declare namespace Worker_d_exports {
809
- export { Api, Definition, ExecutionContext, FetchHandler, FetchWorkerOptions, HandlerEffect, Handlers, LayerOptions, Method$1 as Method, Methods, NativeRequest, NoReservedMethods, Options, ReservedMethodName, RpcHandlers, ServerApi$1 as ServerApi, ServiceFreeSchema, Tag, TagClass, WorkerClass, WorkerContext, WorkerContextService, WorkerContextWaitUntilOptions, WorkerFetchSuccess, WorkerHandler, WorkerOptions, WorkerRpc, WorkerRpcContract, WorkerRpcHandler, WorkerRpcContract as WorkerRpcShape, implement, isWebSocketUpgrade, make, makeFetchHandler, method };
698
+ export { Api, Definition, ExecutionContext, FetchHandler, FetchWorkerOptions, HandlerEffect, Handlers, LayerOptions, Method$1 as Method, Methods, NativeRequest, NoReservedMethods, Options, ReservedMethodName, RpcHandlers, RunOptions, RunSymbol, ServerApi$1 as ServerApi, ServiceFreeSchema, Tag, TagClass, WorkerClass, WorkerContext, WorkerContextService, WorkerContextWaitUntilOptions, WorkerFetchSuccess, WorkerHandler, WorkerOptions, WorkerRpc, WorkerRpcContract, WorkerRpcHandler, WorkerRpcContract as WorkerRpcShape, implement, isWebSocketUpgrade, make, makeFetchHandler, method };
810
699
  }
811
700
  declare const ExecutionContext_base: Context.ServiceClass<ExecutionContext, "effect-cf/ExecutionContext", globalThis.ExecutionContext<unknown>>;
812
- /**
813
- * Access to Cloudflare's native `ExecutionContext`.
814
- */
815
701
  declare class ExecutionContext extends ExecutionContext_base {}
816
- /**
817
- * Options for {@link WorkerContextService.waitUntil}.
818
- */
819
702
  interface WorkerContextWaitUntilOptions<E, R> {
820
703
  /**
821
704
  * Failure mode for the background effect: `"observe"` (default) logs or
@@ -823,53 +706,32 @@ interface WorkerContextWaitUntilOptions<E, R> {
823
706
  * native `waitUntil` promise.
824
707
  */
825
708
  readonly mode?: "observe" | "propagate";
826
- /** Custom failure handler for the background effect. */
827
709
  readonly onFailure?: (cause: Cause.Cause<E>) => Effect.Effect<void, never, R>;
828
710
  }
829
- /**
830
- * Effect wrapper around `ExecutionContext` background APIs.
831
- */
832
711
  interface WorkerContextService {
833
712
  readonly raw: globalThis.ExecutionContext;
834
713
  waitUntil<A, E, R, R2 = never>(effect: Effect.Effect<A, E, R>, options?: WorkerContextWaitUntilOptions<E, R2>): Effect.Effect<void, never, R | R2>;
835
714
  waitUntilPropagating<A, E, R, R2 = never>(effect: Effect.Effect<A, E, R>, options?: Omit<WorkerContextWaitUntilOptions<E, R2>, "mode">): Effect.Effect<void, never, R | R2>;
836
715
  readonly passThroughOnException: Effect.Effect<void>;
837
- /** Abort the current stateless Worker invocation (`ExecutionContext.abort`). */
838
716
  abort(reason?: string): Effect.Effect<void>;
839
717
  }
840
718
  declare const WorkerContext_base: Context.ServiceClass<WorkerContext, "effect-cf/WorkerContext", WorkerContextService>;
841
- /**
842
- * Service used inside handlers to schedule background work via `waitUntil`.
843
- *
844
- * @example
845
- * ```ts
846
- * const handler = Effect.gen(function* () {
847
- * const ctx = yield* Worker.WorkerContext;
848
- * yield* ctx.waitUntil(Effect.log("flush analytics"));
849
- * return new Response("ok");
850
- * });
851
- * ```
852
- */
853
719
  declare class WorkerContext extends WorkerContext_base {}
854
720
  declare const NativeRequest_base: Context.ServiceClass<NativeRequest, "effect-cf/NativeRequest", Request<unknown, CfProperties<unknown>>>;
855
- /**
856
- * Access to the incoming `Request` currently handled by a worker or Durable Object fetch.
857
- */
858
721
  declare class NativeRequest extends NativeRequest_base {}
859
- /**
860
- * Returns `true` when the request is a websocket upgrade request.
861
- */
862
722
  declare const isWebSocketUpgrade: (request: Request) => boolean;
863
723
  type ReservedMethodName = ReservedMethodName$3 | "fetch" | "connect" | "queue" | "scheduled" | "tail" | "tailStream" | "test" | "trace" | "alarm" | "webSocketMessage" | "webSocketClose" | "webSocketError";
864
724
  type WorkerBaseContext<ROut> = ExecutionContext | WorkerContext | WorkerEnvironment | ROut;
865
725
  type WorkerFetchContext<ROut> = WorkerBaseContext<ROut> | NativeRequest | HttpServerRequest.HttpServerRequest | Scope.Scope;
866
726
  type WorkerRpcContext<ROut> = WorkerBaseContext<ROut> | Scope.Scope;
727
+ /** Override to instrument the whole event, then call super[RunSymbol]. */
728
+ declare const RunSymbol: unique symbol;
867
729
  declare const FetchSymbol: unique symbol;
868
- /**
869
- * Successful result of a worker fetch handler: either a native `Response`
870
- * (returned to Cloudflare untouched) or an Effect `HttpServerResponse`
871
- * (rendered through the Effect HTTP pipeline).
872
- */
730
+ /** Metadata available before an event effect or its event layer starts. */
731
+ interface RunOptions {
732
+ readonly event?: "fetch" | "rpc" | "queue";
733
+ readonly rpc?: RpcInvocationInfo;
734
+ }
873
735
  type WorkerFetchSuccess = Response | HttpServerResponse.HttpServerResponse;
874
736
  /**
875
737
  * Effect type for `fetch` handlers executed by {@link make}.
@@ -885,22 +747,19 @@ type WorkerRpcHandler<ROut, A = unknown> = Effect.Effect<A, unknown, WorkerRpcCo
885
747
  type WorkerRpc<ROut> = Record<string, (...args: Array<any>) => WorkerRpcHandler<ROut>>;
886
748
  type WorkerRpcContract<Rpc extends WorkerRpc<ROut>, ROut> = { readonly [Key in keyof Rpc]: Rpc[Key] extends ((...args: infer Args) => Effect.Effect<infer A, unknown, WorkerRpcContext<ROut>>) ? (...args: Args) => Promise<A> : never; };
887
749
  type RpcHandlers<ROut, Api> = { readonly [Key in keyof Api as Key extends keyof WorkerEntrypoint ? never : Key extends string ? Key extends ReservedMethodName ? never : [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) => WorkerRpcHandler<ROut, A> : never; };
888
- /**
889
- * Options for creating a worker class with Effect handlers.
890
- */
891
750
  interface WorkerOptions<RRuntime, REvent = never, EventLayerError = never, Rpc extends WorkerRpc<RRuntime | REvent> = Record<never, never>> {
892
751
  /**
893
752
  * Layer provided around each Cloudflare event handled by this Worker.
894
753
  *
895
- * The layer is built inside the event's Effect scope and finalized when the
896
- * event effect completes. Use this for event-scoped resources such as OTLP
897
- * trace/log exporters. Worker fetch and RPC handlers schedule a best-effort
898
- * flush capped at two seconds; queue handlers do not flush automatically.
754
+ * The layer is built inside the event's Effect scope. For fetch handlers that
755
+ * return an Effect `HttpServerResponse` stream, its scope remains open until
756
+ * the response body finishes or is canceled. Native `Response` values pass
757
+ * through unchanged, so their body streams do not carry this scoped-lifetime
758
+ * guarantee. Fetch, queue, and RPC handlers schedule a best-effort telemetry
759
+ * flush capped at two seconds.
899
760
  */
900
761
  readonly eventLayer?: Layer.Layer<REvent, EventLayerError, WorkerBaseContext<RRuntime>>;
901
- /** Main request handler. */
902
762
  readonly fetch?: Effect.Effect<WorkerFetchSuccess, unknown, WorkerFetchContext<RRuntime | REvent>>;
903
- /** Queue consumer handler invoked per message batch. */
904
763
  readonly queue?: QueueHandler<RRuntime | REvent>;
905
764
  /**
906
765
  * Optional RPC methods exposed as class instance methods.
@@ -910,6 +769,8 @@ interface WorkerOptions<RRuntime, REvent = never, EventLayerError = never, Rpc e
910
769
  * flush silently settles within two seconds even if the exporter does not.
911
770
  */
912
771
  readonly rpc?: Rpc;
772
+ /** Accept live native trace metadata. The client must also enable rpcTracing. */
773
+ readonly rpcTracing?: ReceiverOptions;
913
774
  }
914
775
  type WorkerOptionsWithEventLayer<RRuntime, REvent, EventLayerError, Rpc extends WorkerRpc<RRuntime | REvent> = Record<never, never>> = Omit<WorkerOptions<RRuntime, REvent, EventLayerError, Rpc>, "eventLayer"> & {
915
776
  readonly eventLayer: Layer.Layer<REvent, EventLayerError, WorkerBaseContext<RRuntime>>;
@@ -926,6 +787,7 @@ type FetchWorkerOptionsWithEventLayer<RRuntime, REvent, EventLayerError> = Omit<
926
787
  type WorkerClass<Rpc extends WorkerRpc<ROut>, ROut> = new (ctx: globalThis.ExecutionContext, env: WorkerEnv) => WorkerEntrypoint<WorkerEnv> & {
927
788
  fetch(request: Request): Promise<Response>;
928
789
  queue(batch: globalThis.MessageBatch): Promise<void>;
790
+ [RunSymbol]<A, E>(effect: Effect.Effect<A, E, WorkerRpcContext<ROut>>, options?: RunOptions): Promise<A>;
929
791
  [FetchSymbol](request: Request, requestContext: globalThis.ExecutionContext): Promise<Response>;
930
792
  } & WorkerRpcContract<Rpc, ROut>;
931
793
  /**
@@ -935,19 +797,10 @@ interface FetchHandler<Env extends WorkerEnv = WorkerEnv> {
935
797
  readonly fetch: (request: Request, env: Env, ctx: globalThis.ExecutionContext) => Promise<Response>;
936
798
  }
937
799
  /**
938
- * Creates a Cloudflare worker class backed by a single managed Effect runtime.
939
- *
940
- * The runtime layer is built when Cloudflare constructs the class and reused
941
- * for every event the instance handles. Layer finalizers do not run when the
942
- * isolate is evicted; Cloudflare provides no shutdown hook. Use `eventLayer`
943
- * for resources that must be finalized per event.
944
- *
945
- * @example
946
- * ```ts
947
- * export default Worker.make(Layer.empty, {
948
- * fetch: Effect.succeed(new Response("ok")),
949
- * });
950
- * ```
800
+ * Cloudflare creates a new `WorkerEntrypoint` instance for each native
801
+ * invocation, so this base layer is not shared across invocations. Its managed
802
+ * runtime has no deterministic disposal point in this adapter; use
803
+ * `eventLayer` for resources whose finalizers must run with an event.
951
804
  */
952
805
  declare function make<ROut, LayerError>(layer: Layer.Layer<ROut, LayerError, ExecutionContext | WorkerContext | WorkerEnvironment>, fetch: WorkerHandler<ROut>): WorkerClass<Record<never, never>, ROut>;
953
806
  declare function make<ROut, LayerError, REvent, EventLayerError = never, const Rpc extends WorkerRpc<ROut | REvent> = Record<never, never>>(layer: Layer.Layer<ROut, LayerError, ExecutionContext | WorkerContext | WorkerEnvironment>, options: WorkerOptionsWithEventLayer<ROut, REvent, EventLayerError, Rpc>): WorkerClass<Rpc, ROut | REvent>;
@@ -956,12 +809,13 @@ declare function make<ROut, LayerError, REvent extends never = never, EventLayer
956
809
  * Creates an `ExportedHandler`-compatible `{ fetch }` object backed by
957
810
  * {@link make}.
958
811
  *
959
- * The Effect runtime is cached per `env` identity, so the user layer builds
960
- * once per isolate instead of once per request. `ExecutionContext`-backed
961
- * services (`Worker.ExecutionContext`, `Worker.WorkerContext`) are still
962
- * provided fresh for every request. Layer finalizers do not run when the
963
- * isolate is evicted; Cloudflare provides no shutdown hook. Use `eventLayer`
964
- * for resources that must be finalized per event.
812
+ * The Effect runtime is cached per `env` identity, so the base layer builds
813
+ * once for that cached handler. Request handlers and `eventLayer` receive fresh
814
+ * `ExecutionContext` and `WorkerContext` services. A service constructed by the
815
+ * cached base layer from either context instead captures the first request's
816
+ * value, so construct invocation-bound services in `eventLayer`. Cloudflare
817
+ * provides no isolate shutdown hook, so cached base-layer finalizers are not
818
+ * guaranteed to run.
965
819
  */
966
820
  declare function makeFetchHandler<ROut, LayerError, REvent, EventLayerError = never, Env extends WorkerEnv = WorkerEnv>(layer: Layer.Layer<ROut, LayerError, ExecutionContext | WorkerContext | WorkerEnvironment>, options: FetchWorkerOptionsWithEventLayer<ROut, REvent, EventLayerError>): FetchHandler<Env>;
967
821
  declare function makeFetchHandler<ROut, LayerError, REvent extends never = never, EventLayerError = never, Env extends WorkerEnv = WorkerEnv>(layer: Layer.Layer<ROut, LayerError, ExecutionContext | WorkerContext | WorkerEnvironment>, options: FetchWorkerOptions<ROut, REvent, EventLayerError>): FetchHandler<Env>;
@@ -972,13 +826,9 @@ declare namespace DurableObjectState_d_exports {
972
826
  * Effect-friendly wrapper around Cloudflare `DurableObjectState`.
973
827
  */
974
828
  interface DurableObjectStateService {
975
- /** Underlying Cloudflare state instance. */
976
829
  readonly raw: globalThis.DurableObjectState;
977
- /** Durable Object id for the current instance. */
978
830
  readonly id: globalThis.DurableObjectId;
979
- /** Wrapped storage API. */
980
831
  readonly storage: DurableObjectStorage;
981
- /** Registers background work with Cloudflare's lifecycle. */
982
832
  waitUntil(promise: Promise<unknown>): Effect.Effect<void>;
983
833
  /**
984
834
  * Runs a background Effect via Cloudflare's `waitUntil` with the caller's
@@ -1007,21 +857,13 @@ interface DurableObjectStateService {
1007
857
  * documented timeout (currently 30 seconds).
1008
858
  */
1009
859
  blockConcurrencyWhileOrReset<A, E, R>(effect: Effect.Effect<A, E, R>): Effect.Effect<A, E, R>;
1010
- /** Accepts a websocket connection for hibernation-capable Durable Objects. */
1011
860
  acceptWebSocket(ws: DurableWebSocket, tags?: Array<string>): Effect.Effect<void>;
1012
- /** Lists active sockets, optionally filtered by tag. */
1013
861
  getWebSockets(tag?: string): Effect.Effect<Array<DurableWebSocket>>;
1014
- /** Configures automatic request/response handling for sockets. */
1015
862
  setWebSocketAutoResponse(pair?: WebSocketRequestResponsePair): Effect.Effect<void>;
1016
- /** Gets the configured websocket auto-response pair. */
1017
863
  getWebSocketAutoResponse: Effect.Effect<WebSocketRequestResponsePair | null>;
1018
- /** Timestamp of the last automatic websocket response for a socket. */
1019
864
  getWebSocketAutoResponseTimestamp(ws: DurableWebSocket): Effect.Effect<Date | null>;
1020
- /** Sets the timeout for hibernatable websocket events. */
1021
865
  setHibernatableWebSocketEventTimeout(timeoutMs?: number): Effect.Effect<void>;
1022
- /** Gets the timeout for hibernatable websocket events. */
1023
866
  getHibernatableWebSocketEventTimeout: Effect.Effect<number | null>;
1024
- /** Reads tags attached to a websocket. */
1025
867
  getTags(ws: DurableWebSocket): Effect.Effect<Array<string>>;
1026
868
  /**
1027
869
  * Forcibly resets the Durable Object. Cloudflare logs an uncaught Error using
@@ -1033,13 +875,7 @@ interface DurableObjectStateService {
1033
875
  abort(reason?: string, options?: globalThis.DurableObjectAbortOptions): Effect.Effect<void>;
1034
876
  }
1035
877
  declare const DurableObjectState_base: Context.ServiceClass<DurableObjectState, "effect-cf/DurableObjectState", DurableObjectStateService>;
1036
- /**
1037
- * Context tag for accessing the current Durable Object state service.
1038
- */
1039
878
  declare class DurableObjectState extends DurableObjectState_base {}
1040
- /**
1041
- * Wraps a native Cloudflare `DurableObjectState` as a {@link DurableObjectStateService}.
1042
- */
1043
879
  declare const fromDurableObjectState: (state: globalThis.DurableObjectState) => DurableObjectStateService;
1044
880
  //#endregion
1045
- export { StorageOperationError as A, Rpc_d_exports as C, DurableWebSocket as D, DurableObjectWebSocket_d_exports as E, DurableWebSocketAttachmentError as O, Provider as S, AcceptedUpgrade as T, Definition$3 as _, NativeRequest as a, RpcDefinition_d_exports as b, WorkerDefinition_d_exports as c, AsyncMethodCloudflareReturn as d, AsyncMethodKey as f, QueueBinding_d_exports as g, QueueDefinition_d_exports as h, ExecutionContext as i, DurableObjectStorage_d_exports as k, ServiceBinding_d_exports as l, Queue_d_exports as m, DurableObjectStateService as n, WorkerContext as o, AsyncMethodSuccess as p, DurableObjectState_d_exports as r, Worker_d_exports as s, DurableObjectState as t, AsyncMethodArgs as u, Method$2 as v, AcceptUpgradeOptions as w, ServiceFreeSchema$1 as x, ReservedMethodName$3 as y };
881
+ export { DurableWebSocket as A, RpcDefinition_d_exports as C, AcceptUpgradeOptions as D, Rpc_d_exports as E, DurableObjectStorage_d_exports as M, StorageOperationError as N, AcceptedUpgrade as O, ReservedMethodName$3 as S, Provider as T, Queue_d_exports as _, NativeRequest as a, Definition$3 as b, WorkerDefinition_d_exports as c, AsyncMethodCloudflareReturn as d, AsyncMethodKey as f, RpcTracing_d_exports as g, RpcInvocationInfo as h, ExecutionContext as i, DurableWebSocketAttachmentError as j, DurableObjectWebSocket_d_exports as k, ServiceBinding_d_exports as l, ReceiverOptions as m, DurableObjectStateService as n, WorkerContext as o, AsyncMethodSuccess as p, DurableObjectState_d_exports as r, Worker_d_exports as s, DurableObjectState as t, AsyncMethodArgs as u, QueueDefinition_d_exports as v, ServiceFreeSchema$1 as w, Method$2 as x, QueueBinding_d_exports as y };