effect-cf 0.23.1 → 0.24.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 +8 -0
- package/README.md +151 -0
- package/dist/{Hyperdrive-COyg7R26.d.mts → Binding-Bq_FPzlt.d.mts} +4 -36
- package/dist/DurableObjectState-8sgBJB0s.mjs +384 -0
- package/dist/Hyperdrive-pEMnh3W6.d.mts +36 -0
- package/dist/HyperdrivePg.d.mts +2 -1
- package/dist/Vitest.d.mts +192 -0
- package/dist/Vitest.mjs +184 -0
- package/dist/WorkflowBinding-BECGNTzu.d.mts +1081 -0
- package/dist/index.d.mts +80 -1153
- package/dist/index.mjs +2 -382
- package/package.json +10 -1
- package/src/Vitest.ts +500 -0
|
@@ -0,0 +1,1081 @@
|
|
|
1
|
+
import { c as WorkerEnvironment, n as BindingService, r as BindingValidationError, s as WorkerEnv, t as BindingNotFoundError } from "./Binding-Bq_FPzlt.mjs";
|
|
2
|
+
import { Cause, Context, Effect, Layer, Option, Schema, Scope } from "effect";
|
|
3
|
+
import { HttpServerRequest, HttpServerResponse } from "effect/unstable/http";
|
|
4
|
+
import { RpcStub, RpcTarget, WorkerEntrypoint } from "cloudflare:workers";
|
|
5
|
+
declare namespace DurableObjectStorage_d_exports {
|
|
6
|
+
export { DurableObjectStorage, DurableObjectTransaction, SchemaBackedSyncKvStorage, SqlCursor, SqlStorage, SqlStorageValue, StorageOperationError, SyncKvDefinition, SyncKvStorage, fromDurableObjectStorage };
|
|
7
|
+
}
|
|
8
|
+
/** Supported primitive value types for Durable Object SQL APIs. */
|
|
9
|
+
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 & {
|
|
11
|
+
readonly _tag: "StorageOperationError";
|
|
12
|
+
} & Readonly<A>;
|
|
13
|
+
/** Error type used when a storage operation throws or rejects. */
|
|
14
|
+
declare class StorageOperationError extends StorageOperationError_base<{
|
|
15
|
+
readonly operation: string;
|
|
16
|
+
readonly cause: unknown;
|
|
17
|
+
}> {
|
|
18
|
+
get message(): string;
|
|
19
|
+
}
|
|
20
|
+
type StorageEffect<A> = Effect.Effect<A, StorageOperationError>;
|
|
21
|
+
/**
|
|
22
|
+
* Effect wrapper for Cloudflare SQL cursor operations.
|
|
23
|
+
*/
|
|
24
|
+
interface SqlCursor<T extends Record<string, SqlStorageValue>> {
|
|
25
|
+
next(): StorageEffect<{
|
|
26
|
+
done?: false;
|
|
27
|
+
value: T;
|
|
28
|
+
} | {
|
|
29
|
+
done: true;
|
|
30
|
+
value?: never;
|
|
31
|
+
}>;
|
|
32
|
+
toArray(): StorageEffect<Array<T>>;
|
|
33
|
+
one(): StorageEffect<T>;
|
|
34
|
+
raw<U extends Array<SqlStorageValue>>(): StorageEffect<IterableIterator<U>>;
|
|
35
|
+
readonly columnNames: Array<string>;
|
|
36
|
+
readonly rowsRead: StorageEffect<number>;
|
|
37
|
+
readonly rowsWritten: StorageEffect<number>;
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Effect wrapper for Durable Object SQLite APIs.
|
|
41
|
+
*/
|
|
42
|
+
interface SqlStorage {
|
|
43
|
+
/** Executes a SQL statement and returns a typed cursor. */
|
|
44
|
+
exec<T extends Record<string, SqlStorageValue>>(query: string, ...bindings: Array<SqlStorageValue>): StorageEffect<SqlCursor<T>>;
|
|
45
|
+
readonly databaseSize: number;
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Schema pair used by `SyncKvStorage.schema(...)`.
|
|
49
|
+
*/
|
|
50
|
+
interface SyncKvDefinition<Key, Value, EncodedValue> {
|
|
51
|
+
readonly key: Schema.Codec<Key, string>;
|
|
52
|
+
readonly value: Schema.Codec<Value, EncodedValue>;
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* Sync KV wrapper that transparently encodes keys/values through Effect Schema.
|
|
56
|
+
*/
|
|
57
|
+
interface SchemaBackedSyncKvStorage<Key, Value> {
|
|
58
|
+
get(key: Key): Effect.Effect<Option.Option<Value>, unknown>;
|
|
59
|
+
put(key: Key, value: Value): Effect.Effect<void, unknown>;
|
|
60
|
+
delete(key: Key): Effect.Effect<boolean, unknown>;
|
|
61
|
+
list(options?: globalThis.SyncKvListOptions): Effect.Effect<Array<[Key, Value]>, unknown>;
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* Effect wrapper for synchronous KV attached to Durable Object SQLite storage.
|
|
65
|
+
*/
|
|
66
|
+
interface SyncKvStorage {
|
|
67
|
+
get<T = unknown>(key: string): StorageEffect<T | undefined>;
|
|
68
|
+
put<T>(key: string, value: T): StorageEffect<void>;
|
|
69
|
+
delete(key: string): StorageEffect<boolean>;
|
|
70
|
+
list<T = unknown>(options?: globalThis.SyncKvListOptions): StorageEffect<Array<[string, T]>>;
|
|
71
|
+
schema<Key, Value, EncodedValue>(definition: SyncKvDefinition<Key, Value, EncodedValue>): SchemaBackedSyncKvStorage<Key, Value>;
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* Effect wrapper around Cloudflare transaction callbacks.
|
|
75
|
+
*/
|
|
76
|
+
interface DurableObjectTransaction {
|
|
77
|
+
get<T = unknown>(key: string, options?: globalThis.DurableObjectGetOptions): StorageEffect<T | undefined>;
|
|
78
|
+
get<T = unknown>(keys: Array<string>, options?: globalThis.DurableObjectGetOptions): StorageEffect<Map<string, T>>;
|
|
79
|
+
list<T = unknown>(options?: globalThis.DurableObjectListOptions): StorageEffect<Map<string, T>>;
|
|
80
|
+
put<T>(key: string, value: T, options?: globalThis.DurableObjectPutOptions): StorageEffect<void>;
|
|
81
|
+
put<T>(entries: Record<string, T>, options?: globalThis.DurableObjectPutOptions): StorageEffect<void>;
|
|
82
|
+
delete(key: string, options?: globalThis.DurableObjectPutOptions): StorageEffect<boolean>;
|
|
83
|
+
delete(keys: Array<string>, options?: globalThis.DurableObjectPutOptions): StorageEffect<number>;
|
|
84
|
+
rollback(): StorageEffect<void>;
|
|
85
|
+
getAlarm(options?: globalThis.DurableObjectGetAlarmOptions): StorageEffect<number | null>;
|
|
86
|
+
setAlarm(scheduledTime: number | Date, options?: globalThis.DurableObjectSetAlarmOptions): StorageEffect<void>;
|
|
87
|
+
deleteAlarm(options?: globalThis.DurableObjectSetAlarmOptions): StorageEffect<void>;
|
|
88
|
+
}
|
|
89
|
+
/**
|
|
90
|
+
* Effect wrapper around Cloudflare Durable Object storage.
|
|
91
|
+
*
|
|
92
|
+
* @example
|
|
93
|
+
* ```ts
|
|
94
|
+
* const program = Effect.gen(function* () {
|
|
95
|
+
* const state = yield* DurableObjectState;
|
|
96
|
+
* yield* state.storage.put("counter", 1);
|
|
97
|
+
* const value = yield* state.storage.get<number>("counter");
|
|
98
|
+
* return value;
|
|
99
|
+
* });
|
|
100
|
+
* ```
|
|
101
|
+
*/
|
|
102
|
+
interface DurableObjectStorage {
|
|
103
|
+
get<T = unknown>(key: string, options?: globalThis.DurableObjectGetOptions): StorageEffect<T | undefined>;
|
|
104
|
+
put<T>(key: string, value: T, options?: globalThis.DurableObjectPutOptions): StorageEffect<void>;
|
|
105
|
+
delete(key: string, options?: globalThis.DurableObjectPutOptions): StorageEffect<boolean>;
|
|
106
|
+
/**
|
|
107
|
+
* Deletes all stored data. On compatibility dates before 2026-02-24, Cloudflare
|
|
108
|
+
* documents that active alarms must be deleted separately with `deleteAlarm()`.
|
|
109
|
+
*/
|
|
110
|
+
deleteAll(options?: globalThis.DurableObjectPutOptions): StorageEffect<void>;
|
|
111
|
+
getAlarm(options?: globalThis.DurableObjectGetAlarmOptions): StorageEffect<number | null>;
|
|
112
|
+
setAlarm(scheduledTime: number | Date, options?: globalThis.DurableObjectSetAlarmOptions): StorageEffect<void>;
|
|
113
|
+
deleteAlarm(options?: globalThis.DurableObjectSetAlarmOptions): StorageEffect<void>;
|
|
114
|
+
/**
|
|
115
|
+
* SQLite-backed Durable Object storage only.
|
|
116
|
+
*
|
|
117
|
+
* The callback Effect must complete synchronously. If it requires asynchronous
|
|
118
|
+
* work, use `transaction` instead so Cloudflare can run the async transaction
|
|
119
|
+
* callback under the platform's transaction contract.
|
|
120
|
+
*/
|
|
121
|
+
transactionSync<A, E, R>(closure: () => Effect.Effect<A, E, R>): Effect.Effect<A, E | StorageOperationError, R>;
|
|
122
|
+
/**
|
|
123
|
+
* Runs an async transaction and exposes a typed transaction wrapper.
|
|
124
|
+
*/
|
|
125
|
+
transaction<A, E, R>(closure: (txn: DurableObjectTransaction) => Effect.Effect<A, E, R>): Effect.Effect<A, E | StorageOperationError, R>;
|
|
126
|
+
/** Flushes pending writes to disk. */
|
|
127
|
+
sync(): StorageEffect<void>;
|
|
128
|
+
/** SQLite-backed Durable Object storage point-in-time recovery API only. */
|
|
129
|
+
getCurrentBookmark(): StorageEffect<string>;
|
|
130
|
+
/** SQLite-backed Durable Object storage point-in-time recovery API only. */
|
|
131
|
+
onNextSessionRestoreBookmark(bookmark: string): StorageEffect<string>;
|
|
132
|
+
readonly sql: SqlStorage;
|
|
133
|
+
readonly kv: SyncKvStorage;
|
|
134
|
+
}
|
|
135
|
+
/**
|
|
136
|
+
* Wraps native Cloudflare storage APIs as Effect-returning helpers.
|
|
137
|
+
*/
|
|
138
|
+
declare const fromDurableObjectStorage: (storage: globalThis.DurableObjectStorage) => DurableObjectStorage;
|
|
139
|
+
declare namespace DurableObjectWebSocket_d_exports {
|
|
140
|
+
export { AcceptUpgradeOptions, AcceptedUpgrade, AttachmentInvalidPolicy, AttachmentRehydrateOptions, DurableWebSocket, DurableWebSocketAttachment, DurableWebSocketAttachmentError, DurableWebSocketCloseError, DurableWebSocketHandlers, DurableWebSocketSendData, DurableWebSocketSendError, RehydratedDurableWebSocket, acceptUpgrade, attachment, fromWebSocket, handlers };
|
|
141
|
+
}
|
|
142
|
+
/** Data supported by Cloudflare websocket `send`. */
|
|
143
|
+
type DurableWebSocketSendData = string | ArrayBuffer | ArrayBufferView;
|
|
144
|
+
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 & {
|
|
145
|
+
readonly _tag: "DurableWebSocketSendError";
|
|
146
|
+
} & Readonly<A>;
|
|
147
|
+
/** Error raised when sending on a Durable Object websocket fails. */
|
|
148
|
+
declare class DurableWebSocketSendError extends DurableWebSocketSendError_base<{
|
|
149
|
+
readonly cause: unknown;
|
|
150
|
+
}> {
|
|
151
|
+
get message(): string;
|
|
152
|
+
}
|
|
153
|
+
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 & {
|
|
154
|
+
readonly _tag: "DurableWebSocketCloseError";
|
|
155
|
+
} & Readonly<A>;
|
|
156
|
+
/** Error raised when closing a Durable Object websocket fails. */
|
|
157
|
+
declare class DurableWebSocketCloseError extends DurableWebSocketCloseError_base<{
|
|
158
|
+
readonly cause: unknown;
|
|
159
|
+
}> {
|
|
160
|
+
get message(): string;
|
|
161
|
+
}
|
|
162
|
+
declare const DurableWebSocketAttachmentError_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 & {
|
|
163
|
+
readonly _tag: "DurableWebSocketAttachmentError";
|
|
164
|
+
} & Readonly<A>;
|
|
165
|
+
/** Error raised when serializing or deserializing a websocket attachment fails. */
|
|
166
|
+
declare class DurableWebSocketAttachmentError extends DurableWebSocketAttachmentError_base<{
|
|
167
|
+
readonly operation: "serialize" | "deserialize";
|
|
168
|
+
readonly cause: unknown;
|
|
169
|
+
}> {
|
|
170
|
+
get message(): string;
|
|
171
|
+
}
|
|
172
|
+
/** Effect-native wrapper around a hibernatable Durable Object websocket. */
|
|
173
|
+
interface DurableWebSocket<Attachment = unknown> {
|
|
174
|
+
/** Underlying Cloudflare websocket. */
|
|
175
|
+
readonly raw: WebSocket;
|
|
176
|
+
/** Sends a message through the socket. */
|
|
177
|
+
send(data: DurableWebSocketSendData): Effect.Effect<void, DurableWebSocketSendError>;
|
|
178
|
+
/** Closes the socket. */
|
|
179
|
+
close(code?: number, reason?: string): Effect.Effect<void, DurableWebSocketCloseError>;
|
|
180
|
+
/** Serializes hibernation attachment metadata onto the socket. */
|
|
181
|
+
serializeAttachment<A = Attachment>(value: A): Effect.Effect<void, DurableWebSocketAttachmentError>;
|
|
182
|
+
/** Deserializes hibernation attachment metadata from the socket. */
|
|
183
|
+
readonly deserializeAttachment: Effect.Effect<unknown, DurableWebSocketAttachmentError>;
|
|
184
|
+
}
|
|
185
|
+
/** Wraps a native Cloudflare websocket in the Effect-native Durable Object API. */
|
|
186
|
+
declare const fromWebSocket: <Attachment = unknown>(raw: WebSocket) => DurableWebSocket<Attachment>;
|
|
187
|
+
/**
|
|
188
|
+
* Options for accepting an incoming websocket request in a Durable Object.
|
|
189
|
+
*/
|
|
190
|
+
interface AcceptUpgradeOptions<Attachment = unknown> {
|
|
191
|
+
/** Optional websocket tags for Durable Object hibernation filtering. */
|
|
192
|
+
readonly tags?: ReadonlyArray<string> | undefined;
|
|
193
|
+
/** Optional attachment serialized onto the server socket. */
|
|
194
|
+
readonly attachment?: Attachment | undefined;
|
|
195
|
+
}
|
|
196
|
+
/**
|
|
197
|
+
* Result of a websocket upgrade accepted by {@link acceptUpgrade}.
|
|
198
|
+
*/
|
|
199
|
+
interface AcceptedUpgrade<Attachment = unknown> {
|
|
200
|
+
readonly client: WebSocket;
|
|
201
|
+
readonly server: DurableWebSocket<Attachment>;
|
|
202
|
+
readonly response: Response;
|
|
203
|
+
}
|
|
204
|
+
/**
|
|
205
|
+
* Accepts a websocket upgrade and registers the server socket on `DurableObjectState`.
|
|
206
|
+
*
|
|
207
|
+
* @example
|
|
208
|
+
* ```ts
|
|
209
|
+
* const response = yield* DurableObjectWebSocket.acceptUpgrade({
|
|
210
|
+
* tags: ["room:general"],
|
|
211
|
+
* });
|
|
212
|
+
*
|
|
213
|
+
* return response.response;
|
|
214
|
+
* ```
|
|
215
|
+
*/
|
|
216
|
+
declare const acceptUpgrade: <Attachment = unknown>(options?: AcceptUpgradeOptions<Attachment> | undefined) => Effect.Effect<AcceptedUpgrade<Attachment>, DurableWebSocketAttachmentError, DurableObjectState>;
|
|
217
|
+
type AttachmentInvalidPolicy = "ignore" | "ignore-and-close" | "fail";
|
|
218
|
+
interface AttachmentRehydrateOptions {
|
|
219
|
+
/** Optional Durable Object websocket tag filter. */
|
|
220
|
+
readonly tag?: string | undefined;
|
|
221
|
+
/** Invalid attachment behavior. Defaults to skipping invalid sockets. */
|
|
222
|
+
readonly onInvalid?: AttachmentInvalidPolicy | undefined;
|
|
223
|
+
}
|
|
224
|
+
interface RehydratedDurableWebSocket<Attachment> {
|
|
225
|
+
readonly socket: DurableWebSocket<Attachment>;
|
|
226
|
+
readonly attachment: Attachment;
|
|
227
|
+
}
|
|
228
|
+
interface DurableWebSocketAttachment<Attachment, Encoded> {
|
|
229
|
+
serialize(socket: DurableWebSocket<unknown>, value: Attachment): Effect.Effect<void, DurableWebSocketAttachmentError>;
|
|
230
|
+
deserialize(socket: DurableWebSocket<unknown>): Effect.Effect<Option.Option<Attachment>, DurableWebSocketAttachmentError>;
|
|
231
|
+
rehydrate(options?: AttachmentRehydrateOptions): Effect.Effect<Array<RehydratedDurableWebSocket<Attachment>>, DurableWebSocketAttachmentError, DurableObjectState>;
|
|
232
|
+
readonly schema: Schema.Codec<Attachment, Encoded, never, never>;
|
|
233
|
+
}
|
|
234
|
+
/** Creates typed attachment helpers for accepted and rehydrated sockets. */
|
|
235
|
+
declare const attachment: <const AttachmentSchema extends Schema.Codec<any, any, never, never>>(schema: AttachmentSchema) => DurableWebSocketAttachment<Schema.Schema.Type<AttachmentSchema>, Schema.Codec.Encoded<AttachmentSchema>>;
|
|
236
|
+
interface DurableWebSocketHandlers<R = never, E = unknown> {
|
|
237
|
+
readonly message?: (socket: DurableWebSocket, message: string | ArrayBuffer) => Effect.Effect<void, E, R>;
|
|
238
|
+
readonly close?: (socket: DurableWebSocket, code: number, reason: string, wasClean: boolean) => Effect.Effect<void, E, R>;
|
|
239
|
+
readonly error?: (socket: DurableWebSocket, error: unknown) => Effect.Effect<void, E, R>;
|
|
240
|
+
}
|
|
241
|
+
/** Maps compact websocket lifecycle handler names to `DurableObject.make` options. */
|
|
242
|
+
declare const handlers: <R = never, E = unknown>(options: DurableWebSocketHandlers<R, E>) => {
|
|
243
|
+
webSocketMessage: ((socket: DurableWebSocket, message: string | ArrayBuffer) => Effect.Effect<void, E, R>) | undefined;
|
|
244
|
+
webSocketClose: ((socket: DurableWebSocket, code: number, reason: string, wasClean: boolean) => Effect.Effect<void, E, R>) | undefined;
|
|
245
|
+
webSocketError: ((socket: DurableWebSocket, error: unknown) => Effect.Effect<void, E, R>) | undefined;
|
|
246
|
+
};
|
|
247
|
+
declare namespace Rpc_d_exports {
|
|
248
|
+
export { DisposableValue, MethodArgs, MethodKey, MethodReturn, Provider, Result$1 as Result, RpcStub, RpcTarget, Serializable, Stub, Stubable, Stubify, dispose, isDisposable, resolve, scoped };
|
|
249
|
+
}
|
|
250
|
+
type Stubable = Rpc.Stubable;
|
|
251
|
+
type Stub<T extends Stubable> = Rpc.Stub<T>;
|
|
252
|
+
type Provider<T extends object, Reserved extends string = never> = Rpc.Provider<T, Reserved>;
|
|
253
|
+
type BaseType = void | undefined | null | boolean | number | bigint | string | TypedArray | ArrayBuffer | DataView | Date | Error | RegExp | ReadableStream<Uint8Array> | WritableStream<Uint8Array> | Request | Response | Headers;
|
|
254
|
+
type Serializable<T> = BaseType | Map<T extends Map<infer Key, unknown> ? Serializable<Key> : never, T extends Map<unknown, infer Value> ? Serializable<Value> : never> | Set<T extends Set<infer Value> ? Serializable<Value> : never> | ReadonlyArray<T extends ReadonlyArray<infer Value> ? Serializable<Value> : never> | { [Key in keyof T]: Key extends number | string ? Serializable<T[Key]> : never; } | Stub<Stubable> | Stubable;
|
|
255
|
+
type Stubify<T> = T extends Stubable ? Stub<T> : T extends Map<infer Key, infer Value> ? Map<Stubify<Key>, Stubify<Value>> : T extends Set<infer Value> ? Set<Stubify<Value>> : T extends Array<infer Value> ? Array<Stubify<Value>> : T extends ReadonlyArray<infer Value> ? ReadonlyArray<Stubify<Value>> : T extends BaseType ? T : T extends {
|
|
256
|
+
[key: string | number]: unknown;
|
|
257
|
+
} ? { [Key in keyof T]: Stubify<T[Key]>; } : T;
|
|
258
|
+
type MaybeProvider<T> = T extends object ? Provider<T> : unknown;
|
|
259
|
+
type MaybeDisposable<T> = T extends object ? Disposable : unknown;
|
|
260
|
+
type Result$1<T> = T extends Stubable ? Promise<Stub<T>> & Provider<T> : T extends Serializable<T> ? Promise<Stubify<T> & MaybeDisposable<T>> & MaybeProvider<T> : never;
|
|
261
|
+
type MethodKey<Api> = { [Key in keyof Api]-?: Key extends string ? Api[Key] extends ((...args: Array<any>) => unknown) ? Key : never : never; }[keyof Api];
|
|
262
|
+
type MethodArgs<Api, Method extends keyof Api> = Api[Method] extends ((...args: infer Args) => unknown) ? Args : never;
|
|
263
|
+
type MethodReturn<Api, Method extends keyof Api> = Api[Method] extends ((...args: Array<any>) => infer Return) ? Return : never;
|
|
264
|
+
type DisposableValue = {
|
|
265
|
+
[Symbol.dispose](): void;
|
|
266
|
+
};
|
|
267
|
+
declare const isDisposable: (value: unknown) => value is DisposableValue;
|
|
268
|
+
declare const dispose: (value: unknown) => Effect.Effect<void>;
|
|
269
|
+
declare const resolve: <A>(value: A) => Effect.Effect<Awaited<A>, unknown>;
|
|
270
|
+
declare const scoped: <A>(value: A) => Effect.Effect<Awaited<A>, unknown, Scope.Scope>;
|
|
271
|
+
declare namespace RpcDefinition_d_exports {
|
|
272
|
+
export { Definition$3 as Definition, Method$2 as Method, Methods$1 as Methods, NoReservedMethods$1 as NoReservedMethods, ReservedMethodName$3 as ReservedMethodName, RpcArgumentCountError, RpcArgumentDecodeError, RpcArgumentEncodeError, RpcReservedMethodNameError, RpcSuccessDecodeError, RpcSuccessEncodeError, ServiceFreeSchema$1 as ServiceFreeSchema, WireError, assertNoReservedMethods, decodeArgs, decodeSuccess, decodeWireError, encodeArgs, encodeSuccess, encodeWireError, isWireError, make$3 as make, method$1 as method, reservedMethodNames };
|
|
273
|
+
}
|
|
274
|
+
declare const RpcReservedMethodNameError_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 & {
|
|
275
|
+
readonly _tag: "RpcReservedMethodNameError";
|
|
276
|
+
} & Readonly<A>;
|
|
277
|
+
declare class RpcReservedMethodNameError extends RpcReservedMethodNameError_base<{
|
|
278
|
+
readonly definition: string;
|
|
279
|
+
readonly method: string;
|
|
280
|
+
}> {
|
|
281
|
+
get message(): string;
|
|
282
|
+
}
|
|
283
|
+
declare const RpcArgumentCountError_base: Schema.Class<RpcArgumentCountError, Schema.TaggedStruct<"RpcArgumentCountError", {
|
|
284
|
+
readonly definition: Schema.String;
|
|
285
|
+
readonly method: Schema.String;
|
|
286
|
+
readonly expected: Schema.Number;
|
|
287
|
+
readonly actual: Schema.Number;
|
|
288
|
+
}>, import("effect/Cause").YieldableError>;
|
|
289
|
+
declare class RpcArgumentCountError extends RpcArgumentCountError_base {
|
|
290
|
+
get message(): string;
|
|
291
|
+
}
|
|
292
|
+
declare const RpcArgumentDecodeError_base: Schema.Class<RpcArgumentDecodeError, Schema.TaggedStruct<"RpcArgumentDecodeError", {
|
|
293
|
+
readonly definition: Schema.String;
|
|
294
|
+
readonly method: Schema.String;
|
|
295
|
+
readonly cause: Schema.Defect;
|
|
296
|
+
}>, import("effect/Cause").YieldableError>;
|
|
297
|
+
declare class RpcArgumentDecodeError extends RpcArgumentDecodeError_base {
|
|
298
|
+
get message(): string;
|
|
299
|
+
}
|
|
300
|
+
declare const RpcArgumentEncodeError_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 & {
|
|
301
|
+
readonly _tag: "RpcArgumentEncodeError";
|
|
302
|
+
} & Readonly<A>;
|
|
303
|
+
declare class RpcArgumentEncodeError extends RpcArgumentEncodeError_base<{
|
|
304
|
+
readonly definition: string;
|
|
305
|
+
readonly method: string;
|
|
306
|
+
readonly cause: unknown;
|
|
307
|
+
}> {
|
|
308
|
+
get message(): string;
|
|
309
|
+
}
|
|
310
|
+
declare const RpcSuccessDecodeError_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 & {
|
|
311
|
+
readonly _tag: "RpcSuccessDecodeError";
|
|
312
|
+
} & Readonly<A>;
|
|
313
|
+
declare class RpcSuccessDecodeError extends RpcSuccessDecodeError_base<{
|
|
314
|
+
readonly definition: string;
|
|
315
|
+
readonly method: string;
|
|
316
|
+
readonly cause: unknown;
|
|
317
|
+
}> {
|
|
318
|
+
get message(): string;
|
|
319
|
+
}
|
|
320
|
+
declare const RpcSuccessEncodeError_base: Schema.Class<RpcSuccessEncodeError, Schema.TaggedStruct<"RpcSuccessEncodeError", {
|
|
321
|
+
readonly definition: Schema.String;
|
|
322
|
+
readonly method: Schema.String;
|
|
323
|
+
readonly cause: Schema.Defect;
|
|
324
|
+
}>, import("effect/Cause").YieldableError>;
|
|
325
|
+
declare class RpcSuccessEncodeError extends RpcSuccessEncodeError_base {
|
|
326
|
+
get message(): string;
|
|
327
|
+
}
|
|
328
|
+
/** Errors raised server-side that must survive the Cloudflare RPC wire. */
|
|
329
|
+
type WireError = RpcArgumentCountError | RpcArgumentDecodeError | RpcSuccessEncodeError;
|
|
330
|
+
declare const isWireError: (error: unknown) => error is WireError;
|
|
331
|
+
/**
|
|
332
|
+
* Encodes package RPC errors into a plain `Error` envelope so their tags
|
|
333
|
+
* survive Cloudflare RPC serialization, which drops custom error properties.
|
|
334
|
+
*/
|
|
335
|
+
declare const encodeWireError: (error: unknown) => unknown;
|
|
336
|
+
/** Restores package RPC errors from the {@link encodeWireError} envelope. */
|
|
337
|
+
declare const decodeWireError: (cause: unknown) => unknown;
|
|
338
|
+
declare const reservedMethodNames: Set<string>;
|
|
339
|
+
type ReservedMethodName$3 = "constructor" | "fetch" | "connect" | "alarm" | "webSocketMessage" | "webSocketClose" | "webSocketError" | "then" | "dup" | "dispose" | "serialize" | "deserialize";
|
|
340
|
+
type ServiceFreeSchema$1 = Schema.Codec<any, any, never, never>;
|
|
341
|
+
interface Method$2<Args extends ReadonlyArray<ServiceFreeSchema$1> = ReadonlyArray<ServiceFreeSchema$1>, Success extends ServiceFreeSchema$1 = ServiceFreeSchema$1> {
|
|
342
|
+
readonly args: Args;
|
|
343
|
+
readonly success: Success;
|
|
344
|
+
}
|
|
345
|
+
declare namespace Method$2 {
|
|
346
|
+
export type Any = Method$2<ReadonlyArray<ServiceFreeSchema$1>, ServiceFreeSchema$1>;
|
|
347
|
+
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]>>;
|
|
348
|
+
/** Method schemas cross the wire through their canonical JSON codec. */
|
|
349
|
+
type EncodedArgsFromSchemas<Args extends ReadonlyArray<ServiceFreeSchema$1>> = { [Index in keyof Args]: Schema.Json; };
|
|
350
|
+
export type Args<Self extends Any> = ArgsFromSchemas<Self["args"]>;
|
|
351
|
+
export type EncodedArgs<Self extends Any> = EncodedArgsFromSchemas<Self["args"]>;
|
|
352
|
+
export type Success<Self extends Any> = Schema.Schema.Type<Self["success"]>;
|
|
353
|
+
export type EncodedSuccess<Self extends Any> = Schema.Json;
|
|
354
|
+
export {};
|
|
355
|
+
}
|
|
356
|
+
type Methods$1 = Record<string, Method$2.Any>;
|
|
357
|
+
type NoReservedMethods$1<MethodsShape extends Methods$1, Reserved extends string = ReservedMethodName$3> = Extract<keyof MethodsShape, Reserved> extends never ? MethodsShape : never;
|
|
358
|
+
interface Definition$3<Id extends string = string, MethodsShape extends Methods$1 = Methods$1> {
|
|
359
|
+
readonly id: Id;
|
|
360
|
+
readonly methods: MethodsShape;
|
|
361
|
+
}
|
|
362
|
+
declare namespace Definition$3 {
|
|
363
|
+
type Any = Definition$3<string, Methods$1>;
|
|
364
|
+
type ServerApi<Self extends Any> = { readonly [Key in keyof Self["methods"]]: (...args: Method$2.Args<Self["methods"][Key]>) => Promise<Method$2.Success<Self["methods"][Key]>>; };
|
|
365
|
+
type Api<Self extends Any, Reserved extends string = never> = Provider<ServerApi<Self>, Reserved>;
|
|
366
|
+
type MethodNames<Self extends Any> = Extract<keyof Self["methods"], string>;
|
|
367
|
+
}
|
|
368
|
+
declare const assertNoReservedMethods: (target: string, methods: Record<string, unknown>, reserved: ReadonlySet<string>) => void;
|
|
369
|
+
declare function method$1<Success extends ServiceFreeSchema$1>(definition: {
|
|
370
|
+
readonly success: Success;
|
|
371
|
+
}): Method$2<readonly [], Success>;
|
|
372
|
+
declare function method$1<const Args extends ReadonlyArray<ServiceFreeSchema$1>, Success extends ServiceFreeSchema$1>(definition: {
|
|
373
|
+
readonly args: Args;
|
|
374
|
+
readonly success: Success;
|
|
375
|
+
}): Method$2<Args, Success>;
|
|
376
|
+
declare const decodeArgs: <const Self extends Definition$3.Any, MethodName extends Definition$3.MethodNames<Self>>(definition: Self, methodName: MethodName, args: readonly unknown[]) => Effect.Effect<Self["methods"][MethodName]["args"] extends (infer T) ? T extends Self["methods"][MethodName]["args"] ? T extends readonly [] ? [] : T extends readonly [infer Head extends ServiceFreeSchema$1, ...infer Tail extends readonly ServiceFreeSchema$1[]] ? [Schema.Schema.Type<Head>, ...Tail extends readonly [] ? [] : Tail extends readonly [infer Head extends ServiceFreeSchema$1, ...infer Tail extends readonly ServiceFreeSchema$1[]] ? [Schema.Schema.Type<Head>, ...Tail extends readonly [] ? [] : Tail extends readonly [infer Head extends ServiceFreeSchema$1, ...infer Tail extends readonly ServiceFreeSchema$1[]] ? [Schema.Schema.Type<Head>, ...Tail extends readonly [] ? [] : Tail extends readonly [infer Head extends ServiceFreeSchema$1, ...infer Tail extends readonly ServiceFreeSchema$1[]] ? [Schema.Schema.Type<Head>, ...Tail extends readonly [] ? [] : Tail extends readonly [infer Head extends ServiceFreeSchema$1, ...infer Tail extends readonly ServiceFreeSchema$1[]] ? [Schema.Schema.Type<Head>, ...Tail extends readonly [] ? [] : Tail extends readonly [infer Head extends ServiceFreeSchema$1, ...infer Tail extends readonly ServiceFreeSchema$1[]] ? [Schema.Schema.Type<Head>, ...Tail extends readonly [] ? [] : Tail extends readonly [infer Head extends ServiceFreeSchema$1, ...infer Tail extends readonly ServiceFreeSchema$1[]] ? [Schema.Schema.Type<Head>, ...Tail extends readonly [] ? [] : Tail extends readonly [infer Head extends ServiceFreeSchema$1, ...infer Tail extends readonly ServiceFreeSchema$1[]] ? [Schema.Schema.Type<Head>, ...Tail extends readonly [] ? [] : Tail extends readonly [infer Head extends ServiceFreeSchema$1, ...infer Tail extends readonly ServiceFreeSchema$1[]] ? [Schema.Schema.Type<Head>, ...Tail extends readonly [] ? [] : Tail extends readonly [infer Head extends ServiceFreeSchema$1, ...infer Tail extends readonly ServiceFreeSchema$1[]] ? [Schema.Schema.Type<Head>, ...Tail extends readonly [] ? [] : Tail extends readonly [infer Head extends ServiceFreeSchema$1, ...infer Tail extends readonly ServiceFreeSchema$1[]] ? [Schema.Schema.Type<Head>, ... /*elided*/ any] : Schema.Schema.Type<Tail[number]>[]] : Schema.Schema.Type<Tail[number]>[]] : Schema.Schema.Type<Tail[number]>[]] : Schema.Schema.Type<Tail[number]>[]] : Schema.Schema.Type<Tail[number]>[]] : Schema.Schema.Type<Tail[number]>[]] : Schema.Schema.Type<Tail[number]>[]] : Schema.Schema.Type<Tail[number]>[]] : Schema.Schema.Type<Tail[number]>[]] : Schema.Schema.Type<Tail[number]>[]] : Schema.Schema.Type<T[number]>[] : never : never, RpcArgumentCountError | RpcArgumentDecodeError, never>;
|
|
377
|
+
declare const encodeArgs: <const Self extends Definition$3.Any, MethodName extends Definition$3.MethodNames<Self>>(definition: Self, methodName: MethodName, args: Self["methods"][MethodName]["args"] extends (infer T) ? T extends Self["methods"][MethodName]["args"] ? T extends readonly [] ? [] : T extends readonly [infer Head extends ServiceFreeSchema$1, ...infer Tail extends readonly ServiceFreeSchema$1[]] ? [Schema.Schema.Type<Head>, ...Tail extends readonly [] ? [] : Tail extends readonly [infer Head extends ServiceFreeSchema$1, ...infer Tail extends readonly ServiceFreeSchema$1[]] ? [Schema.Schema.Type<Head>, ...Tail extends readonly [] ? [] : Tail extends readonly [infer Head extends ServiceFreeSchema$1, ...infer Tail extends readonly ServiceFreeSchema$1[]] ? [Schema.Schema.Type<Head>, ...Tail extends readonly [] ? [] : Tail extends readonly [infer Head extends ServiceFreeSchema$1, ...infer Tail extends readonly ServiceFreeSchema$1[]] ? [Schema.Schema.Type<Head>, ...Tail extends readonly [] ? [] : Tail extends readonly [infer Head extends ServiceFreeSchema$1, ...infer Tail extends readonly ServiceFreeSchema$1[]] ? [Schema.Schema.Type<Head>, ...Tail extends readonly [] ? [] : Tail extends readonly [infer Head extends ServiceFreeSchema$1, ...infer Tail extends readonly ServiceFreeSchema$1[]] ? [Schema.Schema.Type<Head>, ...Tail extends readonly [] ? [] : Tail extends readonly [infer Head extends ServiceFreeSchema$1, ...infer Tail extends readonly ServiceFreeSchema$1[]] ? [Schema.Schema.Type<Head>, ...Tail extends readonly [] ? [] : Tail extends readonly [infer Head extends ServiceFreeSchema$1, ...infer Tail extends readonly ServiceFreeSchema$1[]] ? [Schema.Schema.Type<Head>, ...Tail extends readonly [] ? [] : Tail extends readonly [infer Head extends ServiceFreeSchema$1, ...infer Tail extends readonly ServiceFreeSchema$1[]] ? [Schema.Schema.Type<Head>, ...Tail extends readonly [] ? [] : Tail extends readonly [infer Head extends ServiceFreeSchema$1, ...infer Tail extends readonly ServiceFreeSchema$1[]] ? [Schema.Schema.Type<Head>, ...Tail extends readonly [] ? [] : Tail extends readonly [infer Head extends ServiceFreeSchema$1, ...infer Tail extends readonly ServiceFreeSchema$1[]] ? [Schema.Schema.Type<Head>, ... /*elided*/ any] : Schema.Schema.Type<Tail[number]>[]] : Schema.Schema.Type<Tail[number]>[]] : Schema.Schema.Type<Tail[number]>[]] : Schema.Schema.Type<Tail[number]>[]] : Schema.Schema.Type<Tail[number]>[]] : Schema.Schema.Type<Tail[number]>[]] : Schema.Schema.Type<Tail[number]>[]] : Schema.Schema.Type<Tail[number]>[]] : Schema.Schema.Type<Tail[number]>[]] : Schema.Schema.Type<Tail[number]>[]] : Schema.Schema.Type<T[number]>[] : never : never) => Effect.Effect<Self["methods"][MethodName]["args"] extends (infer T_1 extends readonly ServiceFreeSchema$1[]) ? { [Index in keyof T_1]: Schema.Json; } : never, RpcArgumentCountError | RpcArgumentEncodeError, never>;
|
|
378
|
+
declare const encodeSuccess: <const Self extends Definition$3.Any, MethodName extends Definition$3.MethodNames<Self>>(definition: Self, methodName: MethodName, value: Method$2.Success<Self["methods"][MethodName]>) => Effect.Effect<Method$2.EncodedSuccess<Self["methods"][MethodName]>, RpcSuccessEncodeError>;
|
|
379
|
+
declare const decodeSuccess: <const Self extends Definition$3.Any, MethodName extends Definition$3.MethodNames<Self>>(definition: Self, methodName: MethodName, value: unknown) => Effect.Effect<Method$2.Success<Self["methods"][MethodName]>, RpcSuccessDecodeError>;
|
|
380
|
+
declare const make$3: <Id extends string, const MethodsShape extends Methods$1>(id: Id, methods: MethodsShape) => Definition$3<Id, MethodsShape>;
|
|
381
|
+
declare namespace QueueBinding_d_exports {
|
|
382
|
+
export { MessageSendRequest, QueueBindingClient, QueueBindingDefinition, QueueMetrics, QueueOperationError, QueueProducer, QueueSendBatchOptions, QueueSendBatchResponse, QueueSendOptions, QueueSendResponse, isQueue, layer$2 as layer, makeClient$2 as makeClient };
|
|
383
|
+
}
|
|
384
|
+
type QueueSendOptions = CloudflareQueueSendOptions;
|
|
385
|
+
type QueueSendResponse = CloudflareQueueSendResponse;
|
|
386
|
+
type QueueSendBatchOptions = CloudflareQueueSendBatchOptions;
|
|
387
|
+
type QueueSendBatchResponse = CloudflareQueueSendBatchResponse;
|
|
388
|
+
type QueueMetrics = CloudflareQueueMetrics;
|
|
389
|
+
type MessageSendRequest<Body> = CloudflareMessageSendRequest<Body>;
|
|
390
|
+
type QueueProducer<Body> = Pick<CloudflareQueue<Body>, "send"> & Partial<Pick<CloudflareQueue<Body>, "sendBatch" | "metrics">>;
|
|
391
|
+
interface QueueBindingDefinition<Message extends ServiceFreeSchema$1> {
|
|
392
|
+
/** Binding name as configured in `wrangler.jsonc`. */
|
|
393
|
+
readonly binding: string;
|
|
394
|
+
/** Codec used to encode messages before sending them to Cloudflare Queues. */
|
|
395
|
+
readonly message: Message;
|
|
396
|
+
}
|
|
397
|
+
interface QueueBindingClient<Message extends ServiceFreeSchema$1> {
|
|
398
|
+
readonly send: (message: Schema.Schema.Type<Message>, options?: QueueSendOptions) => Effect.Effect<void, QueueOperationError | Schema.SchemaError>;
|
|
399
|
+
readonly sendBatch: (messages: Iterable<MessageSendRequest<Schema.Schema.Type<Message>>>, options?: QueueSendBatchOptions) => Effect.Effect<void, QueueOperationError | Schema.SchemaError>;
|
|
400
|
+
readonly metrics: () => Effect.Effect<QueueMetrics, QueueOperationError>;
|
|
401
|
+
readonly rawUnsafe: Effect.Effect<CloudflareQueue<Schema.Codec.Encoded<Message>>>;
|
|
402
|
+
}
|
|
403
|
+
declare const QueueOperationError_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 & {
|
|
404
|
+
readonly _tag: "QueueOperationError";
|
|
405
|
+
} & Readonly<A>;
|
|
406
|
+
declare class QueueOperationError extends QueueOperationError_base<{
|
|
407
|
+
readonly binding: string;
|
|
408
|
+
readonly operation: string;
|
|
409
|
+
readonly cause: unknown;
|
|
410
|
+
readonly message: string;
|
|
411
|
+
}> {}
|
|
412
|
+
declare const isQueue: <Body>(value: unknown) => value is QueueProducer<Body>;
|
|
413
|
+
declare const makeClient$2: <Message extends ServiceFreeSchema$1>(definition: QueueBindingDefinition<Message>) => ((queue: QueueProducer<Schema.Codec.Encoded<Message>>) => QueueBindingClient<Message>);
|
|
414
|
+
declare const layer$2: <Self, Message extends ServiceFreeSchema$1>(tag: Context.Service<Self, QueueBindingClient<Message>>, definition: QueueBindingDefinition<Message>) => import("effect/Layer").Layer<Self, BindingNotFoundError | BindingValidationError, WorkerEnvironment>;
|
|
415
|
+
declare namespace QueueDefinition_d_exports {
|
|
416
|
+
export { Definition$2 as Definition, Handler$1 as Handler, LayerOptions$2 as LayerOptions, Options$2 as Options, Queue$1 as Queue, Tag$2 as Tag, TagClass$2 as TagClass, implement$2 as implement, make$2 as make };
|
|
417
|
+
}
|
|
418
|
+
interface Definition$2<Id extends string = string, Message extends ServiceFreeSchema$1 = ServiceFreeSchema$1> {
|
|
419
|
+
readonly id: Id;
|
|
420
|
+
readonly message: Message;
|
|
421
|
+
}
|
|
422
|
+
declare namespace Definition$2 {
|
|
423
|
+
type Any = Definition$2<string, ServiceFreeSchema$1>;
|
|
424
|
+
}
|
|
425
|
+
type Handler$1<ROut, Self extends Definition$2.Any> = (batch: QueueBatch<Schema.Schema.Type<Self["message"]>>) => Effect.Effect<void, unknown, ExecutionContext | WorkerContext | WorkerEnvironment | Scope.Scope | ROut>;
|
|
426
|
+
interface Options$2<ROut, Self extends Definition$2.Any> extends Omit<WorkerOptions<ROut, Record<never, never>>, "queue" | "rpc"> {
|
|
427
|
+
readonly queue: Handler$1<ROut, Self>;
|
|
428
|
+
readonly rpc?: never;
|
|
429
|
+
}
|
|
430
|
+
type LayerOptions$2 = {
|
|
431
|
+
readonly binding: string;
|
|
432
|
+
};
|
|
433
|
+
interface TagClass$2<Self, Id extends string, Message extends ServiceFreeSchema$1> extends Context.ServiceClass<Self, `effect-cf/Queue/${Id}`, QueueBindingClient<Message>> {
|
|
434
|
+
readonly id: Id;
|
|
435
|
+
readonly message: Message;
|
|
436
|
+
readonly make: <ROut, LayerError>(layer: Layer.Layer<ROut, LayerError, ExecutionContext | WorkerContext | WorkerEnvironment>, options: Options$2<ROut, Definition$2<Id, Message>>) => WorkerClass<Record<never, never>, ROut>;
|
|
437
|
+
readonly layer: (options: LayerOptions$2) => Layer.Layer<Self, BindingNotFoundError | BindingValidationError, WorkerEnvironment>;
|
|
438
|
+
readonly send: (message: Schema.Schema.Type<Message>, options?: QueueSendOptions) => Effect.Effect<void, QueueOperationError | Schema.SchemaError, Self>;
|
|
439
|
+
readonly sendBatch: (messages: Iterable<MessageSendRequest<Schema.Schema.Type<Message>>>, options?: QueueSendBatchOptions) => Effect.Effect<void, QueueOperationError | Schema.SchemaError, Self>;
|
|
440
|
+
readonly metrics: () => Effect.Effect<QueueMetrics, QueueOperationError, Self>;
|
|
441
|
+
readonly rawUnsafe: Effect.Effect<globalThis.Queue<Schema.Codec.Encoded<Message>>, never, Self>;
|
|
442
|
+
}
|
|
443
|
+
declare const make$2: <Id extends string, Message extends ServiceFreeSchema$1>(id: Id, definition: {
|
|
444
|
+
readonly message: Message;
|
|
445
|
+
}) => TagClass$2<Definition$2<Id, Message>, Id, Message>;
|
|
446
|
+
declare const Tag$2: <Self>() => <Id extends string, Message extends ServiceFreeSchema$1>(id: Id, definition: {
|
|
447
|
+
readonly message: Message;
|
|
448
|
+
}) => TagClass$2<Self, Id, Message>;
|
|
449
|
+
declare const Queue$1: typeof Tag$2;
|
|
450
|
+
declare const implement$2: <ROut, const Self extends Definition$2.Any>(_definition: Self, handler: Handler$1<ROut, Self>) => Handler$1<ROut, Self>;
|
|
451
|
+
declare namespace Queue_d_exports {
|
|
452
|
+
export { Definition$1 as Definition, Handler, LayerOptions$1 as LayerOptions, Options$1 as Options, QueueBatch, QueueHandler, QueueMessage, QueueMessageDecodeError, QueueOptions, Tag$1 as Tag, TagClass$1 as TagClass, decodeBatch, fromMessage, fromMessageBatch, implement$1 as implement };
|
|
453
|
+
}
|
|
454
|
+
interface QueueMessage<Body> {
|
|
455
|
+
readonly raw: globalThis.Message<unknown>;
|
|
456
|
+
readonly id: string;
|
|
457
|
+
readonly timestamp: Date;
|
|
458
|
+
readonly body: Body;
|
|
459
|
+
readonly attempts: number;
|
|
460
|
+
readonly ack: Effect.Effect<void>;
|
|
461
|
+
readonly retry: (options?: globalThis.QueueRetryOptions) => Effect.Effect<void>;
|
|
462
|
+
}
|
|
463
|
+
interface QueueBatch<Body> {
|
|
464
|
+
readonly raw: globalThis.MessageBatch<unknown>;
|
|
465
|
+
readonly messages: ReadonlyArray<QueueMessage<Body>>;
|
|
466
|
+
readonly queue: string;
|
|
467
|
+
readonly metadata: globalThis.MessageBatchMetadata;
|
|
468
|
+
readonly ackAll: Effect.Effect<void>;
|
|
469
|
+
readonly retryAll: (options?: globalThis.QueueRetryOptions) => Effect.Effect<void>;
|
|
470
|
+
}
|
|
471
|
+
declare const QueueMessageDecodeError_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 & {
|
|
472
|
+
readonly _tag: "QueueMessageDecodeError";
|
|
473
|
+
} & Readonly<A>;
|
|
474
|
+
declare class QueueMessageDecodeError extends QueueMessageDecodeError_base<{
|
|
475
|
+
readonly queue: string;
|
|
476
|
+
readonly messageId: string;
|
|
477
|
+
readonly index: number;
|
|
478
|
+
readonly cause: unknown;
|
|
479
|
+
}> {
|
|
480
|
+
get message(): string;
|
|
481
|
+
}
|
|
482
|
+
type RuntimeContext<ROut> = ExecutionContext | WorkerContext | WorkerEnvironment | ROut;
|
|
483
|
+
type QueueHandlerContext<ROut> = RuntimeContext<ROut> | Scope.Scope;
|
|
484
|
+
type QueueHandler<ROut, Body = unknown> = (batch: QueueBatch<Body>) => Effect.Effect<void, unknown, QueueHandlerContext<ROut>>;
|
|
485
|
+
interface QueueOptions<ROut, Body = unknown> {
|
|
486
|
+
readonly queue: QueueHandler<ROut, Body>;
|
|
487
|
+
}
|
|
488
|
+
declare const fromMessage: <Body>(message: globalThis.Message<unknown>, body: Body) => {
|
|
489
|
+
raw: Message<unknown>;
|
|
490
|
+
id: string;
|
|
491
|
+
timestamp: Date;
|
|
492
|
+
body: Body;
|
|
493
|
+
attempts: number;
|
|
494
|
+
ack: Effect.Effect<void, never, never>;
|
|
495
|
+
retry: (options?: globalThis.QueueRetryOptions) => Effect.Effect<void, never, never>;
|
|
496
|
+
};
|
|
497
|
+
declare const fromMessageBatch: <Body>(batch: globalThis.MessageBatch<unknown>, messages: ReadonlyArray<QueueMessage<Body>>) => QueueBatch<Body>;
|
|
498
|
+
declare const decodeBatch: <Body>(batch: globalThis.MessageBatch<unknown>, decodeBody: (body: unknown) => Effect.Effect<Body, unknown>) => Effect.Effect<QueueBatch<Body>, QueueMessageDecodeError>;
|
|
499
|
+
type Definition$1<Id extends string = string, Message extends Definition$2.Any["message"] = Definition$2.Any["message"]> = Definition$2<Id, Message>;
|
|
500
|
+
declare namespace Definition$1 {
|
|
501
|
+
type Any = Definition$2.Any;
|
|
502
|
+
}
|
|
503
|
+
type LayerOptions$1 = LayerOptions$2;
|
|
504
|
+
type TagClass$1<Self, Id extends string, Message extends Definition$2.Any["message"]> = TagClass$2<Self, Id, Message>;
|
|
505
|
+
declare const Tag$1: <Self>() => <Id extends string, Message extends Definition$2.Any["message"]>(id: Id, definition: {
|
|
506
|
+
readonly message: Message;
|
|
507
|
+
}) => TagClass$1<Self, Id, Message>;
|
|
508
|
+
declare const implement$1: typeof implement$2;
|
|
509
|
+
type Handler<ROut, Self extends Definition$2.Any> = Handler$1<ROut, Self>;
|
|
510
|
+
type Options$1<ROut, Self extends Definition$2.Any> = Options$2<ROut, Self>;
|
|
511
|
+
//#endregion
|
|
512
|
+
//#region src/internal/RpcInvocation.d.ts
|
|
513
|
+
type AnyArgs = Array<any>;
|
|
514
|
+
type AsyncMethodKey<Api> = { [Key in keyof Api]-?: Key extends string ? Api[Key] extends ((...args: AnyArgs) => Promise<unknown>) ? Key : never : never; }[keyof Api];
|
|
515
|
+
type AsyncMethodArgs<Api, Method extends keyof Api> = Api[Method] extends ((...args: infer Args) => Promise<unknown>) ? Args : never;
|
|
516
|
+
type AsyncMethodSuccess<Api, Method extends keyof Api> = Api[Method] extends ((...args: AnyArgs) => Promise<infer A>) ? A : never;
|
|
517
|
+
type AsyncMethodCloudflareReturn<Api, Method extends keyof Api> = Result$1<AsyncMethodSuccess<Api, Method>>;
|
|
518
|
+
declare namespace ServiceBinding_d_exports {
|
|
519
|
+
export { Service, ServiceBindingClient, ServiceBindingDefinition, ServiceBindingEffectClient, ServiceBindingFetchError, ServiceBindingRpcError, ServiceBindingStaticClient, ServiceFetcher, isServiceBindingClient, layer$1 as layer, makeClient$1 as makeClient, makeDirectMethods };
|
|
520
|
+
}
|
|
521
|
+
declare const TypeId: "effect-cf/ServiceBinding";
|
|
522
|
+
/**
|
|
523
|
+
* Minimum shape for a Cloudflare service binding.
|
|
524
|
+
*/
|
|
525
|
+
interface ServiceFetcher {
|
|
526
|
+
fetch(input: RequestInfo | URL, init?: RequestInit): Promise<Response>;
|
|
527
|
+
}
|
|
528
|
+
type RpcClient<Api> = { readonly [Key in keyof Api as Key extends string ? Api[Key] extends ((...args: Array<any>) => unknown) ? Key : never : never]: Api[Key]; };
|
|
529
|
+
type ReservedMethodName$2 = ReservedMethodName$1 | "fetch";
|
|
530
|
+
/**
|
|
531
|
+
* Native Cloudflare service object including optional RPC methods.
|
|
532
|
+
*/
|
|
533
|
+
type ServiceBindingClient<Api extends object> = ServiceFetcher & RpcClient<Provider<Api, ReservedMethodName$2>>;
|
|
534
|
+
type ApiFromDefinition<Definition$4> = Definition$4 extends Definition.Any ? ServerApi$1<Definition$4> : never;
|
|
535
|
+
type ApiOrDefinition<Api extends object, Definition> = [Api] extends [never] ? ApiFromDefinition<Definition> : Api;
|
|
536
|
+
/**
|
|
537
|
+
* Binding metadata used to create an Effect service from a Worker binding.
|
|
538
|
+
*/
|
|
539
|
+
interface ServiceBindingDefinition<Definition$9 extends Definition.Any | undefined = undefined> {
|
|
540
|
+
/** Binding name as configured in `wrangler.jsonc`. */
|
|
541
|
+
readonly binding: string;
|
|
542
|
+
/** Optional RPC schema used for argument/result encoding. */
|
|
543
|
+
readonly definition?: Definition$9;
|
|
544
|
+
}
|
|
545
|
+
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 & {
|
|
546
|
+
readonly _tag: "ServiceBindingFetchError";
|
|
547
|
+
} & Readonly<A>;
|
|
548
|
+
/**
|
|
549
|
+
* Failure raised when calling `fetch` on a service binding.
|
|
550
|
+
*/
|
|
551
|
+
declare class ServiceBindingFetchError extends ServiceBindingFetchError_base<{
|
|
552
|
+
readonly binding: string;
|
|
553
|
+
readonly cause: unknown;
|
|
554
|
+
}> {
|
|
555
|
+
get message(): string;
|
|
556
|
+
}
|
|
557
|
+
declare const ServiceBindingRpcError_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 & {
|
|
558
|
+
readonly _tag: "ServiceBindingRpcError";
|
|
559
|
+
} & Readonly<A>;
|
|
560
|
+
/**
|
|
561
|
+
* Failure raised when invoking an RPC method on a service binding.
|
|
562
|
+
*/
|
|
563
|
+
declare class ServiceBindingRpcError extends ServiceBindingRpcError_base<{
|
|
564
|
+
readonly binding: string;
|
|
565
|
+
readonly method: string;
|
|
566
|
+
readonly cause: unknown;
|
|
567
|
+
}> {
|
|
568
|
+
get message(): string;
|
|
569
|
+
}
|
|
570
|
+
type ServiceMethodKey<Api> = AsyncMethodKey<Api>;
|
|
571
|
+
type ServiceMethodArgs<Api, Method extends keyof Api> = AsyncMethodArgs<Api, Method>;
|
|
572
|
+
type ServiceMethodSuccess<Api, Method extends keyof Api> = AsyncMethodSuccess<Api, Method>;
|
|
573
|
+
type ServiceMethodCloudflareReturn<Api, Method extends keyof Api> = AsyncMethodCloudflareReturn<Api, Method>;
|
|
574
|
+
type ServiceCall<R, Api> = <Method extends ServiceMethodKey<Api>>(method: Method, ...args: ServiceMethodArgs<Api, Method>) => Effect.Effect<ServiceMethodSuccess<Api, Method>, ServiceBindingRpcError, R>;
|
|
575
|
+
type DefinitionDirectMethods<R, Definition$13 extends Definition.Any> = { readonly [Method in Definition$3.MethodNames<Definition$13>]: (...args: Method$2.Args<Definition$13["methods"][Method]>) => Effect.Effect<Method$2.Success<Definition$13["methods"][Method]>, ServiceBindingRpcError, R>; };
|
|
576
|
+
type DirectMethods<R, Definition$10> = Definition$10 extends Definition.Any ? DefinitionDirectMethods<R, Definition$10> : {};
|
|
577
|
+
type ServiceBindingEffectClient<Api extends object, Definition$6 extends Definition.Any | undefined = undefined> = DirectMethods<never, Definition$6> & {
|
|
578
|
+
/**
|
|
579
|
+
* Forwards an HTTP request to the bound Worker service.
|
|
580
|
+
*
|
|
581
|
+
* Use this when the service binding is acting as an HTTP origin rather than a
|
|
582
|
+
* Cloudflare RPC target.
|
|
583
|
+
*
|
|
584
|
+
* @example
|
|
585
|
+
* ```ts
|
|
586
|
+
* import { Effect } from "effect";
|
|
587
|
+
*
|
|
588
|
+
* const program = Effect.gen(function* () {
|
|
589
|
+
* const api = yield* ApiWorker;
|
|
590
|
+
* return yield* api.fetch(new Request("https://internal.example/users"));
|
|
591
|
+
* });
|
|
592
|
+
* ```
|
|
593
|
+
*/
|
|
594
|
+
readonly fetch: (input: RequestInfo | URL, init?: RequestInit) => Effect.Effect<globalThis.Response, ServiceBindingFetchError>;
|
|
595
|
+
/**
|
|
596
|
+
* Invokes a Worker RPC method and returns Cloudflare's raw RPC result.
|
|
597
|
+
*
|
|
598
|
+
* This preserves Cloudflare RPC behavior such as promise-like pipelining and
|
|
599
|
+
* transferable / disposable result objects. It does not resolve the returned
|
|
600
|
+
* promise-like value and it does not decode definition-backed success schemas.
|
|
601
|
+
*
|
|
602
|
+
* Most application code should use {@link call} instead.
|
|
603
|
+
*
|
|
604
|
+
* @example
|
|
605
|
+
* ```ts
|
|
606
|
+
* import { Effect } from "effect";
|
|
607
|
+
*
|
|
608
|
+
* const program = Effect.gen(function* () {
|
|
609
|
+
* const counter = yield* CounterService;
|
|
610
|
+
*
|
|
611
|
+
* const result = yield* counter.rpc("increment", 41);
|
|
612
|
+
* const value = yield* Effect.promise(() => result);
|
|
613
|
+
*
|
|
614
|
+
* return value;
|
|
615
|
+
* });
|
|
616
|
+
* ```
|
|
617
|
+
*/
|
|
618
|
+
readonly rpc: <Method extends ServiceMethodKey<Api>>(method: Method, ...args: ServiceMethodArgs<Api, Method>) => Effect.Effect<ServiceMethodCloudflareReturn<Api, Method>, ServiceBindingRpcError>;
|
|
619
|
+
/**
|
|
620
|
+
* Invokes a Worker RPC method, resolves Cloudflare's RPC result, and decodes
|
|
621
|
+
* the success value when the binding was created from a definition.
|
|
622
|
+
*
|
|
623
|
+
* This is the normal choice when application code wants the final typed value.
|
|
624
|
+
*
|
|
625
|
+
* @example
|
|
626
|
+
* ```ts
|
|
627
|
+
* import { Effect } from "effect";
|
|
628
|
+
*
|
|
629
|
+
* const program = Effect.gen(function* () {
|
|
630
|
+
* const counter = yield* CounterService;
|
|
631
|
+
* const value = yield* counter.call("increment", 41);
|
|
632
|
+
*
|
|
633
|
+
* return value;
|
|
634
|
+
* });
|
|
635
|
+
* ```
|
|
636
|
+
*/
|
|
637
|
+
readonly call: <Method extends ServiceMethodKey<Api>>(method: Method, ...args: ServiceMethodArgs<Api, Method>) => Effect.Effect<ServiceMethodSuccess<Api, Method>, ServiceBindingRpcError>;
|
|
638
|
+
/**
|
|
639
|
+
* Invokes a Worker RPC method in the current `Scope`, resolves Cloudflare's RPC
|
|
640
|
+
* result, decodes definition-backed success values, and disposes the resolved
|
|
641
|
+
* result when the scope closes if it implements `Symbol.dispose`.
|
|
642
|
+
*
|
|
643
|
+
* Use this for RPC methods that return Cloudflare RPC resources or other
|
|
644
|
+
* disposable objects whose lifetime should be tied to an Effect scope.
|
|
645
|
+
*
|
|
646
|
+
* @example
|
|
647
|
+
* ```ts
|
|
648
|
+
* import { Effect } from "effect";
|
|
649
|
+
*
|
|
650
|
+
* const program = Effect.scoped(
|
|
651
|
+
* Effect.gen(function* () {
|
|
652
|
+
* const files = yield* FileService;
|
|
653
|
+
* const handle = yield* files.scopedCall("open", "report.csv");
|
|
654
|
+
*
|
|
655
|
+
* return yield* handle.read();
|
|
656
|
+
* }),
|
|
657
|
+
* );
|
|
658
|
+
* ```
|
|
659
|
+
*/
|
|
660
|
+
readonly scopedCall: <Method extends ServiceMethodKey<Api>>(method: Method, ...args: ServiceMethodArgs<Api, Method>) => Effect.Effect<Awaited<ServiceMethodSuccess<Api, Method>>, unknown, Scope.Scope>;
|
|
661
|
+
};
|
|
662
|
+
type ServiceBindingStaticClient<R, Api extends object, Definition$7 extends Definition.Any | undefined = undefined> = DirectMethods<R, Definition$7> & {
|
|
663
|
+
readonly fetch: (input: RequestInfo | URL, init?: RequestInit) => Effect.Effect<globalThis.Response, ServiceBindingFetchError, R>;
|
|
664
|
+
readonly rpc: <Method extends ServiceMethodKey<Api>>(method: Method, ...args: ServiceMethodArgs<Api, Method>) => Effect.Effect<ServiceMethodCloudflareReturn<Api, Method>, ServiceBindingRpcError, R>;
|
|
665
|
+
readonly call: <Method extends ServiceMethodKey<Api>>(method: Method, ...args: ServiceMethodArgs<Api, Method>) => Effect.Effect<ServiceMethodSuccess<Api, Method>, ServiceBindingRpcError, R>;
|
|
666
|
+
readonly scopedCall: <Method extends ServiceMethodKey<Api>>(method: Method, ...args: ServiceMethodArgs<Api, Method>) => Effect.Effect<Awaited<ServiceMethodSuccess<Api, Method>>, unknown, Scope.Scope | R>;
|
|
667
|
+
};
|
|
668
|
+
declare const isServiceBindingClient: <Api extends object>(value: unknown) => value is ServiceBindingClient<Api>;
|
|
669
|
+
declare const makeClient$1: <Api extends object, const Definition$8 extends Definition.Any | undefined = undefined>(definition: ServiceBindingDefinition<Definition$8>) => ((service: ServiceBindingClient<Api>) => ServiceBindingEffectClient<Api, Definition$8>);
|
|
670
|
+
declare const layer$1: <Self, Api extends object, const Definition$12 extends Definition.Any | undefined = undefined>(tag: Context.Service<Self, ServiceBindingEffectClient<Api, Definition$12>>, definition: ServiceBindingDefinition<Definition$12>) => import("effect/Layer").Layer<Self, BindingNotFoundError | BindingValidationError, WorkerEnvironment>;
|
|
671
|
+
/**
|
|
672
|
+
* Creates a typed Effect service for a Worker service binding.
|
|
673
|
+
*
|
|
674
|
+
* Returned value includes:
|
|
675
|
+
* - a Context tag for dependency injection
|
|
676
|
+
* - `fetch(...)` for raw HTTP forwarding
|
|
677
|
+
* - `rpc(...)` for raw Cloudflare RPC results
|
|
678
|
+
* - `call(...)` for resolved and decoded RPC results
|
|
679
|
+
* - `scopedCall(...)` for scoped and decoded disposable RPC results
|
|
680
|
+
* - direct RPC methods when `definition` is provided
|
|
681
|
+
*
|
|
682
|
+
* @example
|
|
683
|
+
* ```ts
|
|
684
|
+
* const Counter = WorkerDefinition.make("Counter", {
|
|
685
|
+
* increment: WorkerDefinition.method({
|
|
686
|
+
* args: [Schema.Number],
|
|
687
|
+
* success: Schema.Number,
|
|
688
|
+
* }),
|
|
689
|
+
* });
|
|
690
|
+
*
|
|
691
|
+
* const CounterLive = Counter.layer({ binding: "COUNTER" });
|
|
692
|
+
*
|
|
693
|
+
* const program = Effect.gen(function* () {
|
|
694
|
+
* const counter = yield* Counter;
|
|
695
|
+
* const next = yield* counter.increment(1);
|
|
696
|
+
* return next;
|
|
697
|
+
* });
|
|
698
|
+
* ```
|
|
699
|
+
*/
|
|
700
|
+
declare const Service: <Self, Api extends object = never>() => <Id extends string, const Definition$5 extends Definition.Any | undefined = undefined>(id: Id, definition: ServiceBindingDefinition<Definition$5>) => BindingService<Self, Id, ServiceBindingEffectClient<ApiOrDefinition<Api, Definition$5>, Definition$5>> & DirectMethods<Self, Definition$5> & {
|
|
701
|
+
readonly [TypeId]: typeof TypeId;
|
|
702
|
+
readonly definition: ServiceBindingDefinition<Definition$5>;
|
|
703
|
+
readonly fetch: (input: URL | RequestInfo<unknown, CfProperties<unknown>>, init?: RequestInit<CfProperties<unknown>> | undefined) => Effect.Effect<Response, ServiceBindingFetchError, Self>;
|
|
704
|
+
readonly rpc: <Method extends ServiceMethodKey<ApiOrDefinition<Api, Definition$5>>>(method: Method, ...args: AsyncMethodArgs<ApiOrDefinition<Api, Definition$5>, Method>) => Effect.Effect<Result$1<AsyncMethodSuccess<ApiOrDefinition<Api, Definition$5>, Method>>, ServiceBindingRpcError, Self>;
|
|
705
|
+
readonly call: <Method extends ServiceMethodKey<ApiOrDefinition<Api, Definition$5>>>(method: Method, ...args: AsyncMethodArgs<ApiOrDefinition<Api, Definition$5>, Method>) => Effect.Effect<AsyncMethodSuccess<ApiOrDefinition<Api, Definition$5>, Method>, ServiceBindingRpcError, Self>;
|
|
706
|
+
readonly scopedCall: <Method extends ServiceMethodKey<ApiOrDefinition<Api, Definition$5>>>(method: Method, ...args: AsyncMethodArgs<ApiOrDefinition<Api, Definition$5>, Method>) => Effect.Effect<Awaited<AsyncMethodSuccess<ApiOrDefinition<Api, Definition$5>, Method>>, unknown, Self | Scope.Scope>;
|
|
707
|
+
};
|
|
708
|
+
declare const makeDirectMethods: <R, Api, Definition$11 extends Definition.Any | undefined>(rpcDefinition: Definition$11 | undefined, call: ServiceCall<R, Api>) => DirectMethods<R, Definition$11>;
|
|
709
|
+
declare namespace WorkerDefinition_d_exports {
|
|
710
|
+
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 };
|
|
711
|
+
}
|
|
712
|
+
type ServiceFreeSchema = Schema.Codec<any, any, never, never>;
|
|
713
|
+
interface Method$1<Args extends ReadonlyArray<ServiceFreeSchema> = ReadonlyArray<ServiceFreeSchema>, Success extends ServiceFreeSchema = ServiceFreeSchema> {
|
|
714
|
+
readonly args: Args;
|
|
715
|
+
readonly success: Success;
|
|
716
|
+
}
|
|
717
|
+
declare namespace Method$1 {
|
|
718
|
+
export type Any = Method$1<ReadonlyArray<ServiceFreeSchema>, ServiceFreeSchema>;
|
|
719
|
+
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]>>;
|
|
720
|
+
/** Method schemas cross the wire through their canonical JSON codec. */
|
|
721
|
+
type EncodedArgsFromSchemas<Args extends ReadonlyArray<ServiceFreeSchema>> = { [Index in keyof Args]: Schema.Json; };
|
|
722
|
+
export type Args<Self extends Any> = ArgsFromSchemas<Self["args"]>;
|
|
723
|
+
export type EncodedArgs<Self extends Any> = EncodedArgsFromSchemas<Self["args"]>;
|
|
724
|
+
export type Success<Self extends Any> = Schema.Schema.Type<Self["success"]>;
|
|
725
|
+
export type EncodedSuccess<Self extends Any> = Schema.Json;
|
|
726
|
+
export {};
|
|
727
|
+
}
|
|
728
|
+
type Methods = Record<string, Method$1.Any>;
|
|
729
|
+
/**
|
|
730
|
+
* RPC contract for a Worker service.
|
|
731
|
+
*
|
|
732
|
+
* Create with {@link make} and reuse to type both worker implementations and
|
|
733
|
+
* service bindings in other workers.
|
|
734
|
+
*/
|
|
735
|
+
interface Definition<Id extends string = string, MethodsShape extends Methods = Methods> {
|
|
736
|
+
readonly id: Id;
|
|
737
|
+
readonly methods: MethodsShape;
|
|
738
|
+
}
|
|
739
|
+
declare namespace Definition {
|
|
740
|
+
type Any = Definition<string, Methods>;
|
|
741
|
+
}
|
|
742
|
+
type ReservedMethodName$1 = ReservedMethodName;
|
|
743
|
+
type NoReservedMethods<MethodsShape extends Methods> = Extract<keyof MethodsShape, ReservedMethodName$1> extends never ? MethodsShape : never;
|
|
744
|
+
/**
|
|
745
|
+
* Promise-based client API derived from a {@link Definition}.
|
|
746
|
+
*/
|
|
747
|
+
type ServerApi$1<Self extends Definition.Any> = { readonly [Key in keyof Self["methods"]]: (...args: Method$1.Args<Self["methods"][Key]>) => Promise<Method$1.Success<Self["methods"][Key]>>; };
|
|
748
|
+
type Api<Self extends Definition.Any> = Provider<ServerApi$1<Self>, ReservedMethodName$1>;
|
|
749
|
+
/**
|
|
750
|
+
* Effect handlers for each RPC method in a worker definition.
|
|
751
|
+
*/
|
|
752
|
+
type Handlers<ROut, Self extends Definition.Any> = { readonly [Key in keyof Self["methods"]]: (...args: Method$1.Args<Self["methods"][Key]>) => WorkerRpcHandler<ROut, Method$1.Success<Self["methods"][Key]>>; };
|
|
753
|
+
/**
|
|
754
|
+
* Worker constructor options for a specific RPC definition.
|
|
755
|
+
*/
|
|
756
|
+
interface Options<ROut, Self extends Definition.Any, REvent = never, EventLayerError = never> extends Omit<WorkerOptions<ROut, REvent, EventLayerError, Handlers<ROut | REvent, Self>>, "rpc"> {
|
|
757
|
+
readonly rpc: Handlers<ROut | REvent, Self>;
|
|
758
|
+
}
|
|
759
|
+
type LayerOptions = {
|
|
760
|
+
readonly binding: string;
|
|
761
|
+
};
|
|
762
|
+
type TagClass<Self, Id extends string, MethodsShape extends Methods> = Context.ServiceClass<Self, Id, ServiceBindingEffectClient<Api<Definition<Id, MethodsShape>>, Definition<Id, MethodsShape>>> & ServiceBindingStaticClient<Self, Api<Definition<Id, MethodsShape>>, Definition<Id, MethodsShape>> & {
|
|
763
|
+
readonly id: Id;
|
|
764
|
+
readonly methods: MethodsShape;
|
|
765
|
+
readonly make: <ROut, LayerError, REvent = never, EventLayerError = never>(layer: Layer.Layer<ROut, LayerError, ExecutionContext | WorkerContext | WorkerEnvironment>, options: Options<ROut, Definition<Id, MethodsShape>, REvent, EventLayerError>) => WorkerClass<Handlers<ROut | REvent, Definition<Id, MethodsShape>>, ROut | REvent>;
|
|
766
|
+
readonly layer: (options: LayerOptions) => Layer.Layer<Self, BindingNotFoundError | BindingValidationError, WorkerEnvironment>;
|
|
767
|
+
};
|
|
768
|
+
/**
|
|
769
|
+
* Defines a single RPC method schema in a worker definition.
|
|
770
|
+
*/
|
|
771
|
+
declare const method: {
|
|
772
|
+
<Success extends ServiceFreeSchema>(definition: {
|
|
773
|
+
readonly success: Success;
|
|
774
|
+
}): Method$1<readonly [], Success>;
|
|
775
|
+
<const Args extends ReadonlyArray<ServiceFreeSchema>, Success extends ServiceFreeSchema>(definition: {
|
|
776
|
+
readonly args: Args;
|
|
777
|
+
readonly success: Success;
|
|
778
|
+
}): Method$1<Args, Success>;
|
|
779
|
+
};
|
|
780
|
+
declare const make$1: <Id extends string, const MethodsShape extends Methods>(id: Id, methods: MethodsShape & NoReservedMethods<MethodsShape>) => TagClass<Definition<Id, MethodsShape>, Id, MethodsShape>;
|
|
781
|
+
declare const Tag: <Self>() => <Id extends string, const MethodsShape extends Methods>(id: Id, methods: MethodsShape & NoReservedMethods<MethodsShape>) => TagClass<Self, Id, MethodsShape>;
|
|
782
|
+
declare const Worker: typeof Tag;
|
|
783
|
+
/**
|
|
784
|
+
* Helper for implementing handlers with the exact method shape of a definition.
|
|
785
|
+
*/
|
|
786
|
+
declare const implement: <ROut, const Self extends Definition.Any>(_definition: Self, handlers: Handlers<ROut, Self>) => Handlers<ROut, Self>;
|
|
787
|
+
/**
|
|
788
|
+
* Convenience alias for a single worker RPC handler Effect.
|
|
789
|
+
*/
|
|
790
|
+
type HandlerEffect<ROut, Self extends Definition.Any, Key extends keyof Self["methods"]> = WorkerRpcHandler<ROut, Method$1.Success<Self["methods"][Key]>>;
|
|
791
|
+
declare namespace Worker_d_exports {
|
|
792
|
+
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, WorkerRpcHandler, WorkerRpcShape, implement, isWebSocketUpgrade, make, makeFetchHandler, method };
|
|
793
|
+
}
|
|
794
|
+
declare const ExecutionContext_base: Context.ServiceClass<ExecutionContext, "effect-cf/ExecutionContext", globalThis.ExecutionContext<unknown>>;
|
|
795
|
+
/**
|
|
796
|
+
* Access to Cloudflare's native `ExecutionContext`.
|
|
797
|
+
*/
|
|
798
|
+
declare class ExecutionContext extends ExecutionContext_base {}
|
|
799
|
+
/**
|
|
800
|
+
* Options for {@link WorkerContextService.waitUntil}.
|
|
801
|
+
*/
|
|
802
|
+
interface WorkerContextWaitUntilOptions<E, R> {
|
|
803
|
+
/**
|
|
804
|
+
* Failure mode for the background effect: `"observe"` (default) logs or
|
|
805
|
+
* routes the failure to `onFailure`, while `"propagate"` also rejects the
|
|
806
|
+
* native `waitUntil` promise.
|
|
807
|
+
*/
|
|
808
|
+
readonly mode?: "observe" | "propagate";
|
|
809
|
+
/** Custom failure handler for the background effect. */
|
|
810
|
+
readonly onFailure?: (cause: Cause.Cause<E>) => Effect.Effect<void, never, R>;
|
|
811
|
+
}
|
|
812
|
+
/**
|
|
813
|
+
* Effect wrapper around `ExecutionContext` background APIs.
|
|
814
|
+
*/
|
|
815
|
+
interface WorkerContextService {
|
|
816
|
+
readonly raw: globalThis.ExecutionContext;
|
|
817
|
+
waitUntil<A, E, R, R2 = never>(effect: Effect.Effect<A, E, R>, options?: WorkerContextWaitUntilOptions<E, R2>): Effect.Effect<void, never, R | R2>;
|
|
818
|
+
waitUntilPropagating<A, E, R, R2 = never>(effect: Effect.Effect<A, E, R>, options?: Omit<WorkerContextWaitUntilOptions<E, R2>, "mode">): Effect.Effect<void, never, R | R2>;
|
|
819
|
+
readonly passThroughOnException: Effect.Effect<void>;
|
|
820
|
+
}
|
|
821
|
+
declare const WorkerContext_base: Context.ServiceClass<WorkerContext, "effect-cf/WorkerContext", WorkerContextService>;
|
|
822
|
+
/**
|
|
823
|
+
* Service used inside handlers to schedule background work via `waitUntil`.
|
|
824
|
+
*
|
|
825
|
+
* @example
|
|
826
|
+
* ```ts
|
|
827
|
+
* const handler = Effect.gen(function* () {
|
|
828
|
+
* const ctx = yield* Worker.WorkerContext;
|
|
829
|
+
* yield* ctx.waitUntil(Effect.log("flush analytics"));
|
|
830
|
+
* return new Response("ok");
|
|
831
|
+
* });
|
|
832
|
+
* ```
|
|
833
|
+
*/
|
|
834
|
+
declare class WorkerContext extends WorkerContext_base {}
|
|
835
|
+
declare const NativeRequest_base: Context.ServiceClass<NativeRequest, "effect-cf/NativeRequest", Request<unknown, CfProperties<unknown>>>;
|
|
836
|
+
/**
|
|
837
|
+
* Access to the incoming `Request` currently handled by a worker or Durable Object fetch.
|
|
838
|
+
*/
|
|
839
|
+
declare class NativeRequest extends NativeRequest_base {}
|
|
840
|
+
/**
|
|
841
|
+
* Returns `true` when the request is a websocket upgrade request.
|
|
842
|
+
*/
|
|
843
|
+
declare const isWebSocketUpgrade: (request: Request) => boolean;
|
|
844
|
+
type ReservedMethodName = ReservedMethodName$3 | "fetch" | "connect" | "queue" | "scheduled" | "tail" | "tailStream" | "test" | "trace" | "alarm" | "webSocketMessage" | "webSocketClose" | "webSocketError";
|
|
845
|
+
type WorkerBaseContext<ROut> = ExecutionContext | WorkerContext | WorkerEnvironment | ROut;
|
|
846
|
+
type WorkerFetchContext<ROut> = WorkerBaseContext<ROut> | NativeRequest | HttpServerRequest.HttpServerRequest | Scope.Scope;
|
|
847
|
+
type WorkerRpcContext<ROut> = WorkerBaseContext<ROut> | Scope.Scope;
|
|
848
|
+
/**
|
|
849
|
+
* Successful result of a worker fetch handler: either a native `Response`
|
|
850
|
+
* (returned to Cloudflare untouched) or an Effect `HttpServerResponse`
|
|
851
|
+
* (rendered through the Effect HTTP pipeline).
|
|
852
|
+
*/
|
|
853
|
+
type WorkerFetchSuccess = Response | HttpServerResponse.HttpServerResponse;
|
|
854
|
+
/**
|
|
855
|
+
* Effect type for `fetch` handlers executed by {@link make}.
|
|
856
|
+
*/
|
|
857
|
+
type WorkerHandler<ROut, A = WorkerFetchSuccess> = Effect.Effect<A, unknown, WorkerFetchContext<ROut>>;
|
|
858
|
+
/**
|
|
859
|
+
* Effect type for worker RPC handlers.
|
|
860
|
+
*/
|
|
861
|
+
type WorkerRpcHandler<ROut, A = unknown> = Effect.Effect<A, unknown, WorkerRpcContext<ROut>>;
|
|
862
|
+
/**
|
|
863
|
+
* Shape of worker RPC handlers passed to {@link make}.
|
|
864
|
+
*/
|
|
865
|
+
type WorkerRpc<ROut> = Record<string, (...args: Array<any>) => WorkerRpcHandler<ROut>>;
|
|
866
|
+
type WorkerRpcShape<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; };
|
|
867
|
+
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<unknown>) ? Key : never : never]: Api[Key] extends ((...args: infer Args) => Promise<infer A>) ? (...args: Args) => WorkerRpcHandler<ROut, A> : never; };
|
|
868
|
+
/**
|
|
869
|
+
* Options for creating a worker class with Effect handlers.
|
|
870
|
+
*/
|
|
871
|
+
interface WorkerOptions<RRuntime, REvent = never, EventLayerError = never, Rpc extends WorkerRpc<RRuntime | REvent> = Record<never, never>> {
|
|
872
|
+
/**
|
|
873
|
+
* Layer provided around each Cloudflare event handled by this Worker.
|
|
874
|
+
*
|
|
875
|
+
* The layer is built inside the event's Effect scope and finalized when the
|
|
876
|
+
* event effect completes. Use this for event-scoped resources such as OTLP
|
|
877
|
+
* trace/log exporters that should flush at event completion.
|
|
878
|
+
*/
|
|
879
|
+
readonly eventLayer?: Layer.Layer<REvent, EventLayerError, WorkerBaseContext<RRuntime>>;
|
|
880
|
+
/** Main request handler. */
|
|
881
|
+
readonly fetch?: Effect.Effect<WorkerFetchSuccess, unknown, WorkerFetchContext<RRuntime | REvent>>;
|
|
882
|
+
/** Queue consumer handler invoked per message batch. */
|
|
883
|
+
readonly queue?: QueueHandler<RRuntime | REvent>;
|
|
884
|
+
/** Optional RPC methods exposed as class instance methods. */
|
|
885
|
+
readonly rpc?: Rpc;
|
|
886
|
+
}
|
|
887
|
+
type FetchWorkerOptions<RRuntime, REvent = never, EventLayerError = never> = Omit<WorkerOptions<RRuntime, REvent, EventLayerError, Record<never, never>>, "rpc"> & {
|
|
888
|
+
readonly rpc?: never;
|
|
889
|
+
};
|
|
890
|
+
/**
|
|
891
|
+
* Cloudflare `WorkerEntrypoint` constructor produced by {@link make}.
|
|
892
|
+
*/
|
|
893
|
+
type WorkerClass<Rpc extends WorkerRpc<ROut>, ROut> = new (ctx: globalThis.ExecutionContext, env: WorkerEnv) => WorkerEntrypoint<WorkerEnv> & {
|
|
894
|
+
fetch(request: Request): Promise<Response>;
|
|
895
|
+
queue(batch: globalThis.MessageBatch): Promise<void>;
|
|
896
|
+
} & WorkerRpcShape<Rpc, ROut>;
|
|
897
|
+
/**
|
|
898
|
+
* `ExportedHandler`-compatible fetch object produced by {@link makeFetchHandler}.
|
|
899
|
+
*/
|
|
900
|
+
interface FetchHandler<Env extends WorkerEnv = WorkerEnv> {
|
|
901
|
+
readonly fetch: (request: Request, env: Env, ctx: globalThis.ExecutionContext) => Promise<Response>;
|
|
902
|
+
}
|
|
903
|
+
/**
|
|
904
|
+
* Creates a Cloudflare worker class backed by a single managed Effect runtime.
|
|
905
|
+
*
|
|
906
|
+
* The runtime layer is built when Cloudflare constructs the class and reused
|
|
907
|
+
* for every event the instance handles. Layer finalizers do not run when the
|
|
908
|
+
* isolate is evicted; Cloudflare provides no shutdown hook. Use `eventLayer`
|
|
909
|
+
* for resources that must be finalized per event.
|
|
910
|
+
*
|
|
911
|
+
* @example
|
|
912
|
+
* ```ts
|
|
913
|
+
* export default Worker.make(Layer.empty, {
|
|
914
|
+
* fetch: Effect.succeed(new Response("ok")),
|
|
915
|
+
* });
|
|
916
|
+
* ```
|
|
917
|
+
*/
|
|
918
|
+
declare function make<ROut, LayerError>(layer: Layer.Layer<ROut, LayerError, ExecutionContext | WorkerContext | WorkerEnvironment>, fetch: WorkerHandler<ROut>): WorkerClass<Record<never, never>, ROut>;
|
|
919
|
+
declare function make<ROut, LayerError, REvent = never, EventLayerError = never, const Rpc extends WorkerRpc<ROut | REvent> = Record<never, never>>(layer: Layer.Layer<ROut, LayerError, ExecutionContext | WorkerContext | WorkerEnvironment>, options: WorkerOptions<ROut, REvent, EventLayerError, Rpc>): WorkerClass<Rpc, ROut | REvent>;
|
|
920
|
+
/**
|
|
921
|
+
* Creates an `ExportedHandler`-compatible `{ fetch }` object backed by
|
|
922
|
+
* {@link make}.
|
|
923
|
+
*
|
|
924
|
+
* The Effect runtime is cached per `env` identity, so the user layer builds
|
|
925
|
+
* once per isolate instead of once per request. `ExecutionContext`-backed
|
|
926
|
+
* services (`Worker.ExecutionContext`, `Worker.WorkerContext`) are still
|
|
927
|
+
* provided fresh for every request. Layer finalizers do not run when the
|
|
928
|
+
* isolate is evicted; Cloudflare provides no shutdown hook. Use `eventLayer`
|
|
929
|
+
* for resources that must be finalized per event.
|
|
930
|
+
*/
|
|
931
|
+
declare const makeFetchHandler: <ROut, LayerError, REvent = never, EventLayerError = never, Env extends WorkerEnv = WorkerEnv>(layer: Layer.Layer<ROut, LayerError, ExecutionContext | WorkerContext | WorkerEnvironment>, options: FetchWorkerOptions<ROut, REvent, EventLayerError>) => FetchHandler<Env>;
|
|
932
|
+
declare namespace DurableObjectState_d_exports {
|
|
933
|
+
export { DurableObjectState, DurableObjectStateService, fromDurableObjectState };
|
|
934
|
+
}
|
|
935
|
+
/**
|
|
936
|
+
* Effect-friendly wrapper around Cloudflare `DurableObjectState`.
|
|
937
|
+
*/
|
|
938
|
+
interface DurableObjectStateService {
|
|
939
|
+
/** Underlying Cloudflare state instance. */
|
|
940
|
+
readonly raw: globalThis.DurableObjectState;
|
|
941
|
+
/** Durable Object id for the current instance. */
|
|
942
|
+
readonly id: globalThis.DurableObjectId;
|
|
943
|
+
/** Wrapped storage API. */
|
|
944
|
+
readonly storage: DurableObjectStorage;
|
|
945
|
+
/** Registers background work with Cloudflare's lifecycle. */
|
|
946
|
+
waitUntil(promise: Promise<unknown>): Effect.Effect<void>;
|
|
947
|
+
/**
|
|
948
|
+
* Runs a background Effect via Cloudflare's `waitUntil` with the caller's
|
|
949
|
+
* Effect context, mirroring `WorkerContext.waitUntil` failure modes:
|
|
950
|
+
* `"observe"` (default) logs or routes failures to `onFailure`, while
|
|
951
|
+
* `"propagate"` also rejects the native `waitUntil` promise.
|
|
952
|
+
*/
|
|
953
|
+
waitUntil<A, E, R, R2 = never>(effect: Effect.Effect<A, E, R>, options?: WorkerContextWaitUntilOptions<E, R2>): Effect.Effect<void, never, R | R2>;
|
|
954
|
+
/**
|
|
955
|
+
* Runs an Effect inside Cloudflare's `blockConcurrencyWhile` gate.
|
|
956
|
+
*
|
|
957
|
+
* Cloudflare resets a Durable Object if the callback throws/rejects, or if the
|
|
958
|
+
* callback exceeds the platform timeout (currently documented as 30 seconds).
|
|
959
|
+
* This safe default resolves the callback with the Effect `Exit` for typed
|
|
960
|
+
* Effect failures and resumes that `Exit` afterward, so typed failures remain
|
|
961
|
+
* ordinary Effect failures instead of resetting the Durable Object. Defects
|
|
962
|
+
* and interruptions still reject the callback.
|
|
963
|
+
*/
|
|
964
|
+
blockConcurrencyWhile<A, E, R>(effect: Effect.Effect<A, E, R>): Effect.Effect<A, E, R>;
|
|
965
|
+
/**
|
|
966
|
+
* Runs an Effect inside Cloudflare's `blockConcurrencyWhile` gate and lets
|
|
967
|
+
* Effect failures reject the callback.
|
|
968
|
+
*
|
|
969
|
+
* Use this only when Cloudflare's reset-on-throw behavior is intentional. The
|
|
970
|
+
* platform also resets the Durable Object if the callback exceeds the
|
|
971
|
+
* documented timeout (currently 30 seconds).
|
|
972
|
+
*/
|
|
973
|
+
blockConcurrencyWhileOrReset<A, E, R>(effect: Effect.Effect<A, E, R>): Effect.Effect<A, E, R>;
|
|
974
|
+
/** Accepts a websocket connection for hibernation-capable Durable Objects. */
|
|
975
|
+
acceptWebSocket(ws: DurableWebSocket, tags?: Array<string>): Effect.Effect<void>;
|
|
976
|
+
/** Lists active sockets, optionally filtered by tag. */
|
|
977
|
+
getWebSockets(tag?: string): Effect.Effect<Array<DurableWebSocket>>;
|
|
978
|
+
/** Configures automatic request/response handling for sockets. */
|
|
979
|
+
setWebSocketAutoResponse(pair?: WebSocketRequestResponsePair): Effect.Effect<void>;
|
|
980
|
+
/** Gets the configured websocket auto-response pair. */
|
|
981
|
+
getWebSocketAutoResponse: Effect.Effect<WebSocketRequestResponsePair | null>;
|
|
982
|
+
/** Timestamp of the last automatic websocket response for a socket. */
|
|
983
|
+
getWebSocketAutoResponseTimestamp(ws: DurableWebSocket): Effect.Effect<Date | null>;
|
|
984
|
+
/** Sets the timeout for hibernatable websocket events. */
|
|
985
|
+
setHibernatableWebSocketEventTimeout(timeoutMs?: number): Effect.Effect<void>;
|
|
986
|
+
/** Gets the timeout for hibernatable websocket events. */
|
|
987
|
+
getHibernatableWebSocketEventTimeout: Effect.Effect<number | null>;
|
|
988
|
+
/** Reads tags attached to a websocket. */
|
|
989
|
+
getTags(ws: DurableWebSocket): Effect.Effect<Array<string>>;
|
|
990
|
+
/**
|
|
991
|
+
* Forcibly resets the Durable Object. Cloudflare logs an uncaught Error using
|
|
992
|
+
* the optional reason, and the method is not available in `wrangler dev` local
|
|
993
|
+
* development according to the Durable Object State docs.
|
|
994
|
+
*/
|
|
995
|
+
abort(reason?: string): Effect.Effect<void>;
|
|
996
|
+
}
|
|
997
|
+
declare const DurableObjectState_base: Context.ServiceClass<DurableObjectState, "effect-cf/DurableObjectState", DurableObjectStateService>;
|
|
998
|
+
/**
|
|
999
|
+
* Context tag for accessing the current Durable Object state service.
|
|
1000
|
+
*/
|
|
1001
|
+
declare class DurableObjectState extends DurableObjectState_base {}
|
|
1002
|
+
/**
|
|
1003
|
+
* Wraps a native Cloudflare `DurableObjectState` as a {@link DurableObjectStateService}.
|
|
1004
|
+
*/
|
|
1005
|
+
declare const fromDurableObjectState: (state: globalThis.DurableObjectState) => DurableObjectStateService;
|
|
1006
|
+
declare namespace WorkflowBinding_d_exports {
|
|
1007
|
+
export { WorkflowBindingClient, WorkflowBindingDefinition, WorkflowInstance, WorkflowInstanceCreateBatchOptions, WorkflowInstanceCreateOptions, WorkflowInstanceEvent, WorkflowInstanceRestartOptions, WorkflowInstanceStatus, WorkflowInstanceStatusName, WorkflowOperationError, WorkflowResultDecodeError, isWorkflow, layer, makeClient };
|
|
1008
|
+
}
|
|
1009
|
+
type WorkflowInstanceCreateOptions<Payload> = Omit<CloudflareWorkflowInstanceCreateOptions<Payload>, "params">;
|
|
1010
|
+
type WorkflowInstanceCreateBatchOptions<Payload, EncodedPayload = unknown> = ReadonlyArray<{
|
|
1011
|
+
readonly payload: Payload;
|
|
1012
|
+
} & WorkflowInstanceCreateOptions<EncodedPayload>>;
|
|
1013
|
+
interface WorkflowInstanceRestartOptions {
|
|
1014
|
+
readonly from?: {
|
|
1015
|
+
readonly name?: string;
|
|
1016
|
+
readonly count?: number;
|
|
1017
|
+
readonly type?: string;
|
|
1018
|
+
};
|
|
1019
|
+
}
|
|
1020
|
+
type WorkflowInstanceStatusName = CloudflareInstanceStatus["status"];
|
|
1021
|
+
interface WorkflowInstanceStatus<Result> {
|
|
1022
|
+
readonly status: WorkflowInstanceStatusName;
|
|
1023
|
+
readonly output: Option.Option<Result>;
|
|
1024
|
+
readonly error: Option.Option<{
|
|
1025
|
+
readonly name: string;
|
|
1026
|
+
readonly message: string;
|
|
1027
|
+
}>;
|
|
1028
|
+
}
|
|
1029
|
+
interface WorkflowInstance<Result> {
|
|
1030
|
+
readonly raw: CloudflareWorkflowInstance;
|
|
1031
|
+
readonly id: string;
|
|
1032
|
+
readonly pause: Effect.Effect<void, WorkflowOperationError>;
|
|
1033
|
+
readonly resume: Effect.Effect<void, WorkflowOperationError>;
|
|
1034
|
+
readonly terminate: Effect.Effect<void, WorkflowOperationError>;
|
|
1035
|
+
readonly restart: (options?: WorkflowInstanceRestartOptions) => Effect.Effect<void, WorkflowOperationError>;
|
|
1036
|
+
readonly status: Effect.Effect<WorkflowInstanceStatus<Result>, WorkflowOperationError | WorkflowResultDecodeError>;
|
|
1037
|
+
readonly sendEvent: (event: WorkflowInstanceEvent) => Effect.Effect<void, WorkflowOperationError>;
|
|
1038
|
+
}
|
|
1039
|
+
interface WorkflowInstanceEvent {
|
|
1040
|
+
readonly type: string;
|
|
1041
|
+
readonly payload: unknown;
|
|
1042
|
+
}
|
|
1043
|
+
interface WorkflowBindingDefinition<Payload extends ServiceFreeSchema$1, Result extends ServiceFreeSchema$1> {
|
|
1044
|
+
/** Binding name as configured in `wrangler.jsonc`. */
|
|
1045
|
+
readonly binding: string;
|
|
1046
|
+
/** Codec used to encode payloads passed to `Workflow.create`. */
|
|
1047
|
+
readonly payload: Payload;
|
|
1048
|
+
/** Codec used to decode completed workflow status output. */
|
|
1049
|
+
readonly result: Result;
|
|
1050
|
+
}
|
|
1051
|
+
interface WorkflowBindingClient<Payload extends ServiceFreeSchema$1, Result extends ServiceFreeSchema$1> {
|
|
1052
|
+
readonly create: (payload: Schema.Schema.Type<Payload>, options?: WorkflowInstanceCreateOptions<Schema.Codec.Encoded<Payload>>) => Effect.Effect<WorkflowInstance<Schema.Schema.Type<Result>>, WorkflowOperationError | Schema.SchemaError>;
|
|
1053
|
+
readonly createBatch: (batch: WorkflowInstanceCreateBatchOptions<Schema.Schema.Type<Payload>, Schema.Codec.Encoded<Payload>>) => Effect.Effect<ReadonlyArray<WorkflowInstance<Schema.Schema.Type<Result>>>, WorkflowOperationError | Schema.SchemaError>;
|
|
1054
|
+
readonly get: (instanceId: string) => Effect.Effect<WorkflowInstance<Schema.Schema.Type<Result>>, WorkflowOperationError>;
|
|
1055
|
+
readonly rawUnsafe: Effect.Effect<CloudflareWorkflow<Schema.Codec.Encoded<Payload>>>;
|
|
1056
|
+
}
|
|
1057
|
+
declare const WorkflowOperationError_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 & {
|
|
1058
|
+
readonly _tag: "WorkflowOperationError";
|
|
1059
|
+
} & Readonly<A>;
|
|
1060
|
+
declare class WorkflowOperationError extends WorkflowOperationError_base<{
|
|
1061
|
+
readonly binding: string;
|
|
1062
|
+
readonly operation: string;
|
|
1063
|
+
readonly cause: unknown;
|
|
1064
|
+
}> {
|
|
1065
|
+
get message(): string;
|
|
1066
|
+
}
|
|
1067
|
+
declare const WorkflowResultDecodeError_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 & {
|
|
1068
|
+
readonly _tag: "WorkflowResultDecodeError";
|
|
1069
|
+
} & Readonly<A>;
|
|
1070
|
+
declare class WorkflowResultDecodeError extends WorkflowResultDecodeError_base<{
|
|
1071
|
+
readonly binding: string;
|
|
1072
|
+
readonly instanceId: string;
|
|
1073
|
+
readonly cause: unknown;
|
|
1074
|
+
}> {
|
|
1075
|
+
get message(): string;
|
|
1076
|
+
}
|
|
1077
|
+
declare const isWorkflow: <Payload>(value: unknown) => value is CloudflareWorkflow<Payload>;
|
|
1078
|
+
declare const makeClient: <Payload extends ServiceFreeSchema$1, Result extends ServiceFreeSchema$1>(definition: WorkflowBindingDefinition<Payload, Result>) => ((workflow: CloudflareWorkflow<Schema.Codec.Encoded<Payload>>) => WorkflowBindingClient<Payload, Result>);
|
|
1079
|
+
declare const layer: <Self, Payload extends ServiceFreeSchema$1, Result extends ServiceFreeSchema$1>(tag: Context.Service<Self, WorkflowBindingClient<Payload, Result>>, definition: WorkflowBindingDefinition<Payload, Result>) => import("effect/Layer").Layer<Self, BindingNotFoundError | BindingValidationError, WorkerEnvironment>;
|
|
1080
|
+
//#endregion
|
|
1081
|
+
export { Rpc_d_exports as A, QueueBinding_d_exports as C, RpcDefinition_d_exports as D, ReservedMethodName$3 as E, DurableWebSocket as M, DurableObjectStorage_d_exports as N, ServiceFreeSchema$1 as O, StorageOperationError as P, QueueDefinition_d_exports as S, Method$2 as T, AsyncMethodArgs as _, WorkflowInstanceCreateOptions as a, AsyncMethodSuccess as b, DurableObjectState as c, ExecutionContext as d, NativeRequest as f, ServiceBinding_d_exports as g, WorkerDefinition_d_exports as h, WorkflowInstanceCreateBatchOptions as i, DurableObjectWebSocket_d_exports as j, Provider as k, DurableObjectStateService as l, Worker_d_exports as m, WorkflowBinding_d_exports as n, WorkflowInstanceStatusName as o, WorkerContext as p, WorkflowInstance as r, WorkflowOperationError as s, WorkflowBindingClient as t, DurableObjectState_d_exports as u, AsyncMethodCloudflareReturn as v, Definition$3 as w, Queue_d_exports as x, AsyncMethodKey as y };
|