effect-cf 0.32.1 → 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.
- package/CHANGELOG.md +18 -0
- package/README.md +31 -1072
- package/dist/{Artifacts-DnHQA-Ax.d.mts → Artifacts-B3r3RuTB.d.mts} +1 -48
- package/dist/{Artifacts-CSIk1Oml.mjs → Artifacts-CBxWGeZB.mjs} +2 -7
- package/dist/{Binding-pfilNJmP.mjs → Binding-C82jRhdr.mjs} +1 -2
- package/dist/{Binding-xJJJPmiD.d.mts → Binding-DKcLrQCM.d.mts} +0 -45
- package/dist/ComputerArtifacts.d.mts +1 -3
- package/dist/ComputerArtifacts.mjs +1 -2
- package/dist/ComputerWorkspace.d.mts +1 -10
- package/dist/ComputerWorkspace.mjs +1 -2
- package/dist/ComputerWorkspaceHost.d.mts +1 -9
- package/dist/{ContainerNamespace-CFjiLw8b.d.mts → ContainerNamespace-DbLaeFhN.d.mts} +1 -14
- package/dist/{DurableObjectState-B0A0Y1ef.d.mts → DurableObjectState-CrEunfQ-.d.mts} +86 -254
- package/dist/{DurableObjectState-D1Ibr6k0.mjs → DurableObjectState-De4ZojhY.mjs} +2 -40
- package/dist/{ErrorMessage-BM0K-Nik.mjs → ErrorMessage-Byx2OgNd.mjs} +0 -1
- package/dist/{Hyperdrive-z-9fFz15.d.mts → Hyperdrive-HrwFlZ6x.d.mts} +1 -4
- package/dist/HyperdrivePg.d.mts +2 -11
- package/dist/HyperdrivePg.mjs +0 -8
- package/dist/Sandbox.d.mts +2 -32
- package/dist/Sandbox.mjs +2 -11
- package/dist/Vitest.d.mts +3 -31
- package/dist/Vitest.mjs +2 -17
- package/dist/{WorkflowBinding-B9_S8tX2.d.mts → WorkflowBinding-BumVQTuW.d.mts} +2 -5
- package/dist/index.d.mts +34 -480
- package/dist/index.mjs +174 -312
- package/package.json +2 -2
- package/src/AiGateway.ts +0 -6
- package/src/AnalyticsEngine.ts +0 -9
- package/src/Artifacts.ts +0 -47
- package/src/Binding.ts +0 -8
- package/src/BrowserRendering.ts +0 -4
- package/src/Cache.ts +0 -19
- package/src/CloudflareOtlp.ts +3 -39
- package/src/ComputerArtifacts.ts +0 -2
- package/src/ComputerWorkspace.ts +0 -9
- package/src/ComputerWorkspaceHost.ts +0 -8
- package/src/ContainerNamespace.ts +0 -13
- package/src/D1.ts +0 -22
- package/src/DurableObject.ts +45 -25
- package/src/DurableObjectAlarm.ts +6 -210
- package/src/DurableObjectDefinition.ts +8 -20
- package/src/DurableObjectNamespace.ts +57 -112
- package/src/DurableObjectRpcWebSocket.ts +3 -19
- package/src/DurableObjectSqlite.ts +0 -12
- package/src/DurableObjectState.ts +6 -21
- package/src/DurableObjectStorage.ts +2 -35
- package/src/DurableObjectWebSocket.ts +0 -31
- package/src/Email.ts +0 -12
- package/src/Environment.ts +0 -37
- package/src/Hyperdrive.ts +0 -3
- package/src/HyperdrivePg.ts +0 -9
- package/src/Images.ts +0 -5
- package/src/Kv.ts +0 -15
- package/src/QueueBinding.ts +0 -2
- package/src/R2.ts +0 -5
- package/src/RpcDefinition.ts +0 -2
- package/src/RpcTracing.ts +133 -0
- package/src/Sandbox.ts +0 -30
- package/src/ServiceBinding.ts +48 -125
- package/src/Vectorize.ts +0 -5
- package/src/Vitest.ts +0 -28
- package/src/WebTransport.ts +0 -15
- package/src/Worker.ts +36 -57
- package/src/WorkerDefinition.ts +5 -14
- package/src/WorkersAi.ts +0 -4
- package/src/Workflow.ts +0 -5
- package/src/WorkflowBinding.ts +0 -3
- package/src/index.ts +1 -0
- package/src/internal/Entrypoint.ts +23 -4
- package/src/internal/ErrorMessage.ts +0 -1
- package/src/internal/RpcInvocation.ts +18 -1
- package/src/internal/Runtime.ts +12 -7
- package/src/internal/WorkerContext.ts +0 -11
|
@@ -1,16 +1,14 @@
|
|
|
1
|
-
import { c as WorkerEnvironment, n as BindingService, r as BindingValidationError, s as WorkerEnv, t as BindingNotFoundError } from "./Binding-
|
|
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
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]; }>) => import("effect/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
|
|
102
|
+
/** Requires SQLite-backed Durable Object storage. */
|
|
133
103
|
getCurrentBookmark(): StorageEffect<string>;
|
|
134
|
-
/** SQLite-backed Durable Object storage
|
|
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
145
|
serializeAttachment<A = 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,7 +273,6 @@ 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;
|
|
342
277
|
declare const reservedMethodNames: Set<string>;
|
|
343
278
|
type ReservedMethodName$3 = "constructor" | "fetch" | "connect" | "alarm" | "webSocketMessage" | "webSocketClose" | "webSocketError" | "then" | "dup" | "dispose" | "serialize" | "deserialize";
|
|
@@ -349,7 +284,6 @@ interface Method$2<Args extends ReadonlyArray<ServiceFreeSchema$1> = ReadonlyArr
|
|
|
349
284
|
declare namespace Method$2 {
|
|
350
285
|
export type Any = Method$2<ReadonlyArray<ServiceFreeSchema$1>, ServiceFreeSchema$1>;
|
|
351
286
|
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
287
|
type EncodedArgsFromSchemas<Args extends ReadonlyArray<ServiceFreeSchema$1>> = { [Index in keyof Args]: Schema.Json; };
|
|
354
288
|
export type Args<Self extends Any> = ArgsFromSchemas<Self["args"]>;
|
|
355
289
|
export type EncodedArgs<Self extends Any> = EncodedArgsFromSchemas<Self["args"]>;
|
|
@@ -395,9 +329,7 @@ type MessageSendRequest<Body> = CloudflareMessageSendRequest<Body>;
|
|
|
395
329
|
type QueueProducer<Body> = Pick<CloudflareQueue<Body>, "send"> & Partial<Pick<CloudflareQueue<Body>, "sendBatch" | "metrics">>;
|
|
396
330
|
type QueueCandidate = Parameters<typeof Predicate.isUnknown>[0];
|
|
397
331
|
interface QueueBindingDefinition<Message extends ServiceFreeSchema$1> {
|
|
398
|
-
/** Binding name as configured in `wrangler.jsonc`. */
|
|
399
332
|
readonly binding: string;
|
|
400
|
-
/** Codec used to encode messages before sending them to Cloudflare Queues. */
|
|
401
333
|
readonly message: Message;
|
|
402
334
|
}
|
|
403
335
|
interface QueueBindingClient<Message extends ServiceFreeSchema$1> {
|
|
@@ -515,6 +447,53 @@ declare const Tag$1: <Self>() => <Id extends string, Message extends Definition$
|
|
|
515
447
|
declare const implement$1: typeof implement$2;
|
|
516
448
|
type Handler<ROut, Self extends Definition$2.Any> = Handler$1<ROut, Self>;
|
|
517
449
|
type Options$1<ROut, Self extends Definition$2.Any> = Options$2<ROut, Self>;
|
|
450
|
+
declare namespace RpcTracing_d_exports {
|
|
451
|
+
export { ReceiverOptions, RpcInvocationInfo, RpcTraceContext, withRpcClientSpan, withRpcServerSpan, withRpcTraceContext };
|
|
452
|
+
}
|
|
453
|
+
/**
|
|
454
|
+
* Live native RPC metadata. Opted-in receivers reserve a valid trailing value
|
|
455
|
+
* with this tag for transport context; do not use it as a final domain argument.
|
|
456
|
+
* Never store this in durable messages or envelopes.
|
|
457
|
+
*/
|
|
458
|
+
declare const RpcTraceContext: Schema.Struct<{
|
|
459
|
+
readonly _tag: Schema.Literal<"effect-cf/RpcTraceContext/v1">;
|
|
460
|
+
readonly traceId: Schema.String;
|
|
461
|
+
readonly spanId: Schema.String;
|
|
462
|
+
readonly sampled: Schema.Boolean;
|
|
463
|
+
}>;
|
|
464
|
+
type RpcTraceContext = typeof RpcTraceContext.Type;
|
|
465
|
+
interface ReceiverOptions {
|
|
466
|
+
/** Stable service name, never an instance id or capability URL. */
|
|
467
|
+
readonly service: string;
|
|
468
|
+
}
|
|
469
|
+
/** Per-invocation metadata passed to Worker and DurableObject RunSymbol overrides. */
|
|
470
|
+
interface RpcInvocationInfo {
|
|
471
|
+
readonly service: string;
|
|
472
|
+
readonly method: string;
|
|
473
|
+
/** Native arguments with valid, opted-in trace metadata removed. Do not log them. */
|
|
474
|
+
readonly args: ReadonlyArray<unknown>;
|
|
475
|
+
/**
|
|
476
|
+
* Set after a definition-backed receiver decodes its arguments, before its
|
|
477
|
+
* handler runs. Absent before decoding and when decoding fails. Do not log it.
|
|
478
|
+
*/
|
|
479
|
+
readonly decodedArgs?: ReadonlyArray<unknown>;
|
|
480
|
+
readonly parent?: RpcTraceContext;
|
|
481
|
+
}
|
|
482
|
+
/**
|
|
483
|
+
* Appends the current live parent only for a receiver that has opted in.
|
|
484
|
+
* Call this inside the CLIENT span, immediately before the native invocation.
|
|
485
|
+
* With no valid propagating parent, the original argument array is returned.
|
|
486
|
+
*/
|
|
487
|
+
declare const withRpcTraceContext: (args: readonly unknown[]) => Effect.Effect<readonly unknown[], never, never>;
|
|
488
|
+
/** Wrap the whole call, including native result resolution and success decoding. */
|
|
489
|
+
declare const withRpcClientSpan: <A, E, R>(effect: Effect.Effect<A, E, R>, binding: string, method: string) => Effect.Effect<A, E, Exclude<R, Tracer.ParentSpan>>;
|
|
490
|
+
/**
|
|
491
|
+
* Optional application instrumentation for the entire receiver effect.
|
|
492
|
+
* Use in a RunSymbol override to include argument decode, handler and encode.
|
|
493
|
+
* Records stable service/method attributes and failure status, not argument or
|
|
494
|
+
* error payloads. The original typed failure still propagates to the caller.
|
|
495
|
+
*/
|
|
496
|
+
declare const withRpcServerSpan: <A, E, R>(effect: Effect.Effect<A, E, R>, invocation: RpcInvocationInfo) => Effect.Effect<A, E, Exclude<R, Tracer.ParentSpan>>;
|
|
518
497
|
//#endregion
|
|
519
498
|
//#region src/internal/RpcInvocation.d.ts
|
|
520
499
|
type AnyArgs = Array<any>;
|
|
@@ -526,28 +505,22 @@ declare namespace ServiceBinding_d_exports {
|
|
|
526
505
|
export { Service, ServiceBindingClient, ServiceBindingDefinition, ServiceBindingEffectClient, ServiceBindingFetchError, ServiceBindingRpcError, ServiceBindingStaticClient, ServiceFetcher, isServiceBindingClient, layer, makeClient, makeDirectMethods };
|
|
527
506
|
}
|
|
528
507
|
declare const TypeId: "effect-cf/ServiceBinding";
|
|
529
|
-
/**
|
|
530
|
-
* Minimum shape for a Cloudflare service binding.
|
|
531
|
-
*/
|
|
532
508
|
interface ServiceFetcher {
|
|
533
509
|
fetch(input: RequestInfo | URL, init?: RequestInit): Promise<Response>;
|
|
534
510
|
}
|
|
535
511
|
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
512
|
type ReservedMethodName$2 = ReservedMethodName$1 | "fetch";
|
|
537
|
-
/**
|
|
538
|
-
* Native Cloudflare service object including optional RPC methods.
|
|
539
|
-
*/
|
|
540
513
|
type ServiceBindingClient<Api extends object> = ServiceFetcher & RpcClient<Provider<Api, ReservedMethodName$2>>;
|
|
541
514
|
type ApiFromDefinition<Definition$12> = Definition$12 extends Definition.Any ? ServerApi$1<Definition$12> : never;
|
|
542
515
|
type ApiOrDefinition<Api extends object, Definition> = [Api] extends [never] ? ApiFromDefinition<Definition> : Api;
|
|
543
516
|
/**
|
|
544
517
|
* Binding metadata used to create an Effect service from a Worker binding.
|
|
545
518
|
*/
|
|
546
|
-
interface ServiceBindingDefinition<Definition$
|
|
547
|
-
/** Binding name as configured in `wrangler.jsonc`. */
|
|
519
|
+
interface ServiceBindingDefinition<Definition$6 extends Definition.Any | undefined = undefined> {
|
|
548
520
|
readonly binding: string;
|
|
549
|
-
|
|
550
|
-
|
|
521
|
+
readonly definition?: Definition$6;
|
|
522
|
+
/** Append live trace context only when the receiver also enables rpcTracing. */
|
|
523
|
+
readonly rpcTracing?: boolean;
|
|
551
524
|
}
|
|
552
525
|
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
526
|
readonly _tag: "ServiceBindingFetchError";
|
|
@@ -579,25 +552,9 @@ type ServiceMethodArgs<Api, Method extends keyof Api> = AsyncMethodArgs<Api, Met
|
|
|
579
552
|
type ServiceMethodSuccess<Api, Method extends keyof Api> = AsyncMethodSuccess<Api, Method>;
|
|
580
553
|
type ServiceMethodCloudflareReturn<Api, Method extends keyof Api> = AsyncMethodCloudflareReturn<Api, Method>;
|
|
581
554
|
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$
|
|
583
|
-
type DirectMethods<R, Definition$
|
|
584
|
-
type ServiceBindingEffectClient<Api extends object, Definition$
|
|
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
|
-
*/
|
|
555
|
+
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>; };
|
|
556
|
+
type DirectMethods<R, Definition$13> = Definition$13 extends Definition.Any ? DefinitionDirectMethods<R, Definition$13> : {};
|
|
557
|
+
type ServiceBindingEffectClient<Api extends object, Definition$7 extends Definition.Any | undefined = undefined> = DirectMethods<never, Definition$7> & {
|
|
601
558
|
readonly fetch: (input: RequestInfo | URL, init?: RequestInit) => Effect.Effect<globalThis.Response, ServiceBindingFetchError>;
|
|
602
559
|
/**
|
|
603
560
|
* Invokes a Worker RPC method and returns Cloudflare's raw RPC result.
|
|
@@ -607,20 +564,6 @@ type ServiceBindingEffectClient<Api extends object, Definition$4 extends Definit
|
|
|
607
564
|
* promise-like value and it does not decode definition-backed success schemas.
|
|
608
565
|
*
|
|
609
566
|
* 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
567
|
*/
|
|
625
568
|
readonly rpc: <Method extends ServiceMethodKey<Api>>(method: Method, ...args: ServiceMethodArgs<Api, Method>) => Effect.Effect<ServiceMethodCloudflareReturn<Api, Method>, ServiceBindingRpcError>;
|
|
626
569
|
/**
|
|
@@ -628,18 +571,6 @@ type ServiceBindingEffectClient<Api extends object, Definition$4 extends Definit
|
|
|
628
571
|
* the success value when the binding was created from a definition.
|
|
629
572
|
*
|
|
630
573
|
* 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
574
|
*/
|
|
644
575
|
readonly call: <Method extends ServiceMethodKey<Api>>(method: Method, ...args: ServiceMethodArgs<Api, Method>) => Effect.Effect<ServiceMethodSuccess<Api, Method>, ServiceBindingRpcError>;
|
|
645
576
|
/**
|
|
@@ -649,24 +580,10 @@ type ServiceBindingEffectClient<Api extends object, Definition$4 extends Definit
|
|
|
649
580
|
*
|
|
650
581
|
* Use this for RPC methods that return Cloudflare RPC resources or other
|
|
651
582
|
* 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
583
|
*/
|
|
667
584
|
readonly scopedCall: <Method extends ServiceMethodKey<Api>>(method: Method, ...args: ServiceMethodArgs<Api, Method>) => Effect.Effect<Awaited<ServiceMethodSuccess<Api, Method>>, unknown, Scope.Scope>;
|
|
668
585
|
};
|
|
669
|
-
type ServiceBindingStaticClient<R, Api extends object, Definition$
|
|
586
|
+
type ServiceBindingStaticClient<R, Api extends object, Definition$8 extends Definition.Any | undefined = undefined> = DirectMethods<R, Definition$8> & {
|
|
670
587
|
readonly fetch: (input: RequestInfo | URL, init?: RequestInit) => Effect.Effect<globalThis.Response, ServiceBindingFetchError, R>;
|
|
671
588
|
readonly rpc: <Method extends ServiceMethodKey<Api>>(method: Method, ...args: ServiceMethodArgs<Api, Method>) => Effect.Effect<ServiceMethodCloudflareReturn<Api, Method>, ServiceBindingRpcError, R>;
|
|
672
589
|
readonly call: <Method extends ServiceMethodKey<Api>>(method: Method, ...args: ServiceMethodArgs<Api, Method>) => Effect.Effect<ServiceMethodSuccess<Api, Method>, ServiceBindingRpcError, R>;
|
|
@@ -674,46 +591,17 @@ type ServiceBindingStaticClient<R, Api extends object, Definition$5 extends Defi
|
|
|
674
591
|
};
|
|
675
592
|
type ServiceBindingValue = Schema.Schema.Type<typeof Schema.Unknown>;
|
|
676
593
|
declare const isServiceBindingClient: <Api extends object>(value: ServiceBindingValue) => value is ServiceBindingClient<Api>;
|
|
677
|
-
declare const makeClient: <Api extends object, const Definition$
|
|
678
|
-
declare const layer: <Self, Api extends object, const Definition$
|
|
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> & {
|
|
594
|
+
declare const makeClient: <Api extends object, const Definition$5 extends Definition.Any | undefined = undefined>(definition: ServiceBindingDefinition<Definition$5>) => ((service: ServiceBindingClient<Api>) => ServiceBindingEffectClient<Api, Definition$5>);
|
|
595
|
+
declare const layer: <Self, Api extends object, const Definition$9 extends Definition.Any | undefined = undefined>(tag: Context.Service<Self, ServiceBindingEffectClient<Api, Definition$9>>, definition: ServiceBindingDefinition<Definition$9>) => import("effect/Layer").Layer<Self, BindingNotFoundError | BindingValidationError, WorkerEnvironment>;
|
|
596
|
+
declare const Service: <Self, Api extends object = never>() => <Id extends string, const Definition$11 extends Definition.Any | undefined = undefined>(id: Id, definition: ServiceBindingDefinition<Definition$11>) => BindingService<Self, Id, ServiceBindingEffectClient<ApiOrDefinition<Api, Definition$11>, Definition$11>> & DirectMethods<Self, Definition$11> & {
|
|
709
597
|
readonly [TypeId]: typeof TypeId;
|
|
710
|
-
readonly definition: ServiceBindingDefinition<Definition$
|
|
598
|
+
readonly definition: ServiceBindingDefinition<Definition$11>;
|
|
711
599
|
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$
|
|
713
|
-
readonly call: <Method extends ServiceMethodKey<ApiOrDefinition<Api, Definition$
|
|
714
|
-
readonly scopedCall: <Method extends ServiceMethodKey<ApiOrDefinition<Api, Definition$
|
|
600
|
+
readonly rpc: <Method extends ServiceMethodKey<ApiOrDefinition<Api, Definition$11>>>(method: Method, ...args: AsyncMethodArgs<ApiOrDefinition<Api, Definition$11>, Method>) => Effect.Effect<Result$1<AsyncMethodSuccess<ApiOrDefinition<Api, Definition$11>, Method>>, ServiceBindingRpcError, Self>;
|
|
601
|
+
readonly call: <Method extends ServiceMethodKey<ApiOrDefinition<Api, Definition$11>>>(method: Method, ...args: AsyncMethodArgs<ApiOrDefinition<Api, Definition$11>, Method>) => Effect.Effect<AsyncMethodSuccess<ApiOrDefinition<Api, Definition$11>, Method>, ServiceBindingRpcError, Self>;
|
|
602
|
+
readonly scopedCall: <Method extends ServiceMethodKey<ApiOrDefinition<Api, Definition$11>>>(method: Method, ...args: AsyncMethodArgs<ApiOrDefinition<Api, Definition$11>, Method>) => Effect.Effect<Awaited<AsyncMethodSuccess<ApiOrDefinition<Api, Definition$11>, Method>>, unknown, Self | Scope.Scope>;
|
|
715
603
|
};
|
|
716
|
-
declare const makeDirectMethods: <R, Api, Definition$
|
|
604
|
+
declare const makeDirectMethods: <R, Api, Definition$10 extends Definition.Any | undefined>(rpcDefinition: Definition$10 | undefined, call: ServiceCall<R, Api>) => DirectMethods<R, Definition$10>;
|
|
717
605
|
declare namespace WorkerDefinition_d_exports {
|
|
718
606
|
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
607
|
}
|
|
@@ -725,7 +613,6 @@ interface Method$1<Args extends ReadonlyArray<ServiceFreeSchema> = ReadonlyArray
|
|
|
725
613
|
declare namespace Method$1 {
|
|
726
614
|
export type Any = Method$1<ReadonlyArray<ServiceFreeSchema>, ServiceFreeSchema>;
|
|
727
615
|
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
616
|
type EncodedArgsFromSchemas<Args extends ReadonlyArray<ServiceFreeSchema>> = { [Index in keyof Args]: Schema.Json; };
|
|
730
617
|
export type Args<Self extends Any> = ArgsFromSchemas<Self["args"]>;
|
|
731
618
|
export type EncodedArgs<Self extends Any> = EncodedArgsFromSchemas<Self["args"]>;
|
|
@@ -770,6 +657,7 @@ type EventLayerOptions<ROut, REvent, EventLayerError> = [REvent] extends [never]
|
|
|
770
657
|
type Options<ROut, Self extends Definition.Any, REvent = never, EventLayerError = never> = BaseOptions<ROut, Self, REvent, EventLayerError> & EventLayerOptions<ROut, REvent, EventLayerError>;
|
|
771
658
|
type LayerOptions = {
|
|
772
659
|
readonly binding: string;
|
|
660
|
+
readonly rpcTracing?: boolean;
|
|
773
661
|
};
|
|
774
662
|
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
663
|
readonly id: Id;
|
|
@@ -806,16 +694,10 @@ declare const implement: <ROut, const Self extends Definition.Any>(_definition:
|
|
|
806
694
|
*/
|
|
807
695
|
type HandlerEffect<ROut, Self extends Definition.Any, Key extends keyof Self["methods"]> = WorkerRpcHandler<ROut, Method$1.Success<Self["methods"][Key]>>;
|
|
808
696
|
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 };
|
|
697
|
+
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
698
|
}
|
|
811
699
|
declare const ExecutionContext_base: Context.ServiceClass<ExecutionContext, "effect-cf/ExecutionContext", globalThis.ExecutionContext<unknown>>;
|
|
812
|
-
/**
|
|
813
|
-
* Access to Cloudflare's native `ExecutionContext`.
|
|
814
|
-
*/
|
|
815
700
|
declare class ExecutionContext extends ExecutionContext_base {}
|
|
816
|
-
/**
|
|
817
|
-
* Options for {@link WorkerContextService.waitUntil}.
|
|
818
|
-
*/
|
|
819
701
|
interface WorkerContextWaitUntilOptions<E, R> {
|
|
820
702
|
/**
|
|
821
703
|
* Failure mode for the background effect: `"observe"` (default) logs or
|
|
@@ -823,53 +705,32 @@ interface WorkerContextWaitUntilOptions<E, R> {
|
|
|
823
705
|
* native `waitUntil` promise.
|
|
824
706
|
*/
|
|
825
707
|
readonly mode?: "observe" | "propagate";
|
|
826
|
-
/** Custom failure handler for the background effect. */
|
|
827
708
|
readonly onFailure?: (cause: Cause.Cause<E>) => Effect.Effect<void, never, R>;
|
|
828
709
|
}
|
|
829
|
-
/**
|
|
830
|
-
* Effect wrapper around `ExecutionContext` background APIs.
|
|
831
|
-
*/
|
|
832
710
|
interface WorkerContextService {
|
|
833
711
|
readonly raw: globalThis.ExecutionContext;
|
|
834
712
|
waitUntil<A, E, R, R2 = never>(effect: Effect.Effect<A, E, R>, options?: WorkerContextWaitUntilOptions<E, R2>): Effect.Effect<void, never, R | R2>;
|
|
835
713
|
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
714
|
readonly passThroughOnException: Effect.Effect<void>;
|
|
837
|
-
/** Abort the current stateless Worker invocation (`ExecutionContext.abort`). */
|
|
838
715
|
abort(reason?: string): Effect.Effect<void>;
|
|
839
716
|
}
|
|
840
717
|
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
718
|
declare class WorkerContext extends WorkerContext_base {}
|
|
854
719
|
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
720
|
declare class NativeRequest extends NativeRequest_base {}
|
|
859
|
-
/**
|
|
860
|
-
* Returns `true` when the request is a websocket upgrade request.
|
|
861
|
-
*/
|
|
862
721
|
declare const isWebSocketUpgrade: (request: Request) => boolean;
|
|
863
722
|
type ReservedMethodName = ReservedMethodName$3 | "fetch" | "connect" | "queue" | "scheduled" | "tail" | "tailStream" | "test" | "trace" | "alarm" | "webSocketMessage" | "webSocketClose" | "webSocketError";
|
|
864
723
|
type WorkerBaseContext<ROut> = ExecutionContext | WorkerContext | WorkerEnvironment | ROut;
|
|
865
724
|
type WorkerFetchContext<ROut> = WorkerBaseContext<ROut> | NativeRequest | HttpServerRequest.HttpServerRequest | Scope.Scope;
|
|
866
725
|
type WorkerRpcContext<ROut> = WorkerBaseContext<ROut> | Scope.Scope;
|
|
726
|
+
/** Override to instrument the whole event, then call super[RunSymbol]. */
|
|
727
|
+
declare const RunSymbol: unique symbol;
|
|
867
728
|
declare const FetchSymbol: unique symbol;
|
|
868
|
-
/**
|
|
869
|
-
|
|
870
|
-
|
|
871
|
-
|
|
872
|
-
|
|
729
|
+
/** Metadata available before an event effect or its event layer starts. */
|
|
730
|
+
interface RunOptions {
|
|
731
|
+
readonly event?: "fetch" | "rpc" | "queue";
|
|
732
|
+
readonly rpc?: RpcInvocationInfo;
|
|
733
|
+
}
|
|
873
734
|
type WorkerFetchSuccess = Response | HttpServerResponse.HttpServerResponse;
|
|
874
735
|
/**
|
|
875
736
|
* Effect type for `fetch` handlers executed by {@link make}.
|
|
@@ -885,9 +746,6 @@ type WorkerRpcHandler<ROut, A = unknown> = Effect.Effect<A, unknown, WorkerRpcCo
|
|
|
885
746
|
type WorkerRpc<ROut> = Record<string, (...args: Array<any>) => WorkerRpcHandler<ROut>>;
|
|
886
747
|
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
748
|
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
749
|
interface WorkerOptions<RRuntime, REvent = never, EventLayerError = never, Rpc extends WorkerRpc<RRuntime | REvent> = Record<never, never>> {
|
|
892
750
|
/**
|
|
893
751
|
* Layer provided around each Cloudflare event handled by this Worker.
|
|
@@ -898,9 +756,7 @@ interface WorkerOptions<RRuntime, REvent = never, EventLayerError = never, Rpc e
|
|
|
898
756
|
* flush capped at two seconds; queue handlers do not flush automatically.
|
|
899
757
|
*/
|
|
900
758
|
readonly eventLayer?: Layer.Layer<REvent, EventLayerError, WorkerBaseContext<RRuntime>>;
|
|
901
|
-
/** Main request handler. */
|
|
902
759
|
readonly fetch?: Effect.Effect<WorkerFetchSuccess, unknown, WorkerFetchContext<RRuntime | REvent>>;
|
|
903
|
-
/** Queue consumer handler invoked per message batch. */
|
|
904
760
|
readonly queue?: QueueHandler<RRuntime | REvent>;
|
|
905
761
|
/**
|
|
906
762
|
* Optional RPC methods exposed as class instance methods.
|
|
@@ -910,6 +766,8 @@ interface WorkerOptions<RRuntime, REvent = never, EventLayerError = never, Rpc e
|
|
|
910
766
|
* flush silently settles within two seconds even if the exporter does not.
|
|
911
767
|
*/
|
|
912
768
|
readonly rpc?: Rpc;
|
|
769
|
+
/** Accept live native trace metadata. The client must also enable rpcTracing. */
|
|
770
|
+
readonly rpcTracing?: ReceiverOptions;
|
|
913
771
|
}
|
|
914
772
|
type WorkerOptionsWithEventLayer<RRuntime, REvent, EventLayerError, Rpc extends WorkerRpc<RRuntime | REvent> = Record<never, never>> = Omit<WorkerOptions<RRuntime, REvent, EventLayerError, Rpc>, "eventLayer"> & {
|
|
915
773
|
readonly eventLayer: Layer.Layer<REvent, EventLayerError, WorkerBaseContext<RRuntime>>;
|
|
@@ -926,6 +784,7 @@ type FetchWorkerOptionsWithEventLayer<RRuntime, REvent, EventLayerError> = Omit<
|
|
|
926
784
|
type WorkerClass<Rpc extends WorkerRpc<ROut>, ROut> = new (ctx: globalThis.ExecutionContext, env: WorkerEnv) => WorkerEntrypoint<WorkerEnv> & {
|
|
927
785
|
fetch(request: Request): Promise<Response>;
|
|
928
786
|
queue(batch: globalThis.MessageBatch): Promise<void>;
|
|
787
|
+
[RunSymbol]<A, E>(effect: Effect.Effect<A, E, WorkerRpcContext<ROut>>, options?: RunOptions): Promise<A>;
|
|
929
788
|
[FetchSymbol](request: Request, requestContext: globalThis.ExecutionContext): Promise<Response>;
|
|
930
789
|
} & WorkerRpcContract<Rpc, ROut>;
|
|
931
790
|
/**
|
|
@@ -935,19 +794,8 @@ interface FetchHandler<Env extends WorkerEnv = WorkerEnv> {
|
|
|
935
794
|
readonly fetch: (request: Request, env: Env, ctx: globalThis.ExecutionContext) => Promise<Response>;
|
|
936
795
|
}
|
|
937
796
|
/**
|
|
938
|
-
*
|
|
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
|
-
* ```
|
|
797
|
+
* The layer is built once per Worker instance and reused for its events.
|
|
798
|
+
* Eviction skips finalizers, so use `eventLayer` for per-event resources.
|
|
951
799
|
*/
|
|
952
800
|
declare function make<ROut, LayerError>(layer: Layer.Layer<ROut, LayerError, ExecutionContext | WorkerContext | WorkerEnvironment>, fetch: WorkerHandler<ROut>): WorkerClass<Record<never, never>, ROut>;
|
|
953
801
|
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>;
|
|
@@ -972,13 +820,9 @@ declare namespace DurableObjectState_d_exports {
|
|
|
972
820
|
* Effect-friendly wrapper around Cloudflare `DurableObjectState`.
|
|
973
821
|
*/
|
|
974
822
|
interface DurableObjectStateService {
|
|
975
|
-
/** Underlying Cloudflare state instance. */
|
|
976
823
|
readonly raw: globalThis.DurableObjectState;
|
|
977
|
-
/** Durable Object id for the current instance. */
|
|
978
824
|
readonly id: globalThis.DurableObjectId;
|
|
979
|
-
/** Wrapped storage API. */
|
|
980
825
|
readonly storage: DurableObjectStorage;
|
|
981
|
-
/** Registers background work with Cloudflare's lifecycle. */
|
|
982
826
|
waitUntil(promise: Promise<unknown>): Effect.Effect<void>;
|
|
983
827
|
/**
|
|
984
828
|
* Runs a background Effect via Cloudflare's `waitUntil` with the caller's
|
|
@@ -1007,37 +851,25 @@ interface DurableObjectStateService {
|
|
|
1007
851
|
* documented timeout (currently 30 seconds).
|
|
1008
852
|
*/
|
|
1009
853
|
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
854
|
acceptWebSocket(ws: DurableWebSocket, tags?: Array<string>): Effect.Effect<void>;
|
|
1012
|
-
/** Lists active sockets, optionally filtered by tag. */
|
|
1013
855
|
getWebSockets(tag?: string): Effect.Effect<Array<DurableWebSocket>>;
|
|
1014
|
-
/** Configures automatic request/response handling for sockets. */
|
|
1015
856
|
setWebSocketAutoResponse(pair?: WebSocketRequestResponsePair): Effect.Effect<void>;
|
|
1016
|
-
/** Gets the configured websocket auto-response pair. */
|
|
1017
857
|
getWebSocketAutoResponse: Effect.Effect<WebSocketRequestResponsePair | null>;
|
|
1018
|
-
/** Timestamp of the last automatic websocket response for a socket. */
|
|
1019
858
|
getWebSocketAutoResponseTimestamp(ws: DurableWebSocket): Effect.Effect<Date | null>;
|
|
1020
|
-
/** Sets the timeout for hibernatable websocket events. */
|
|
1021
859
|
setHibernatableWebSocketEventTimeout(timeoutMs?: number): Effect.Effect<void>;
|
|
1022
|
-
/** Gets the timeout for hibernatable websocket events. */
|
|
1023
860
|
getHibernatableWebSocketEventTimeout: Effect.Effect<number | null>;
|
|
1024
|
-
/** Reads tags attached to a websocket. */
|
|
1025
861
|
getTags(ws: DurableWebSocket): Effect.Effect<Array<string>>;
|
|
1026
862
|
/**
|
|
1027
863
|
* Forcibly resets the Durable Object. Cloudflare logs an uncaught Error using
|
|
1028
864
|
* the optional reason, and the method is not available in `wrangler dev` local
|
|
1029
|
-
* development according to the Durable Object State docs.
|
|
865
|
+
* development according to the Durable Object State docs. Set
|
|
866
|
+
* `retryAlarm: false` to prevent the current alarm invocation from retrying;
|
|
867
|
+
* this option has no effect outside an alarm handler.
|
|
1030
868
|
*/
|
|
1031
|
-
abort(reason?: string): Effect.Effect<void>;
|
|
869
|
+
abort(reason?: string, options?: globalThis.DurableObjectAbortOptions): Effect.Effect<void>;
|
|
1032
870
|
}
|
|
1033
871
|
declare const DurableObjectState_base: Context.ServiceClass<DurableObjectState, "effect-cf/DurableObjectState", DurableObjectStateService>;
|
|
1034
|
-
/**
|
|
1035
|
-
* Context tag for accessing the current Durable Object state service.
|
|
1036
|
-
*/
|
|
1037
872
|
declare class DurableObjectState extends DurableObjectState_base {}
|
|
1038
|
-
/**
|
|
1039
|
-
* Wraps a native Cloudflare `DurableObjectState` as a {@link DurableObjectStateService}.
|
|
1040
|
-
*/
|
|
1041
873
|
declare const fromDurableObjectState: (state: globalThis.DurableObjectState) => DurableObjectStateService;
|
|
1042
874
|
//#endregion
|
|
1043
|
-
export {
|
|
875
|
+
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 };
|