effect-cf 0.12.0 → 0.13.1
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 +15 -0
- package/dist/index.d.mts +1085 -1085
- package/dist/index.mjs +1489 -1519
- package/package.json +1 -1
- package/src/CloudflareOtlp.ts +0 -112
- package/src/DurableObject.ts +64 -21
- package/src/DurableObjectDefinition.ts +19 -9
- package/src/Worker.ts +90 -29
- package/src/WorkerDefinition.ts +16 -8
- package/src/internal/Clock.ts +28 -0
package/dist/index.d.mts
CHANGED
|
@@ -2,8 +2,8 @@ import { a as BindingService, c as WorkerConfig, i as BindingNotFoundError, l as
|
|
|
2
2
|
import { Cause, Config, Context, Data, DateTime, Duration, Effect, Layer, Option, Schema, Scope } from "effect";
|
|
3
3
|
import { HttpServerRequest, HttpServerResponse } from "effect/unstable/http";
|
|
4
4
|
import { OtlpMetrics } from "effect/unstable/observability";
|
|
5
|
-
import { DurableObject, RpcStub, RpcTarget, WorkerEntrypoint, WorkflowEntrypoint, WorkflowEvent, WorkflowSleepDuration, WorkflowStep, WorkflowStepConfig, WorkflowStepContext, WorkflowStepEvent, WorkflowTimeoutDuration } from "cloudflare:workers";
|
|
6
5
|
import { D1Client } from "@effect/sql-d1";
|
|
6
|
+
import { DurableObject, RpcStub, RpcTarget, WorkerEntrypoint, WorkflowEntrypoint, WorkflowEvent, WorkflowSleepDuration, WorkflowStep, WorkflowStepConfig, WorkflowStepContext, WorkflowStepEvent, WorkflowTimeoutDuration } from "cloudflare:workers";
|
|
7
7
|
import * as RpcSerialization from "effect/unstable/rpc/RpcSerialization";
|
|
8
8
|
import * as RpcServer from "effect/unstable/rpc/RpcServer";
|
|
9
9
|
import { SqliteClient } from "@effect/sql-sqlite-do";
|
|
@@ -16,936 +16,1180 @@ import * as Duration$1 from "effect/Duration";
|
|
|
16
16
|
import * as Tracer from "effect/Tracer";
|
|
17
17
|
import * as _$effect_Config0 from "effect/Config";
|
|
18
18
|
|
|
19
|
-
//#region src/
|
|
20
|
-
declare namespace
|
|
21
|
-
export {
|
|
22
|
-
}
|
|
23
|
-
type Stubable = Rpc.Stubable;
|
|
24
|
-
type Stub<T extends Stubable> = Rpc.Stub<T>;
|
|
25
|
-
type Provider<T extends object, Reserved extends string = never> = Rpc.Provider<T, Reserved>;
|
|
26
|
-
type BaseType = void | undefined | null | boolean | number | bigint | string | TypedArray | ArrayBuffer | DataView | Date | Error | RegExp | ReadableStream<Uint8Array> | WritableStream<Uint8Array> | Request | Response | Headers;
|
|
27
|
-
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;
|
|
28
|
-
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 {
|
|
29
|
-
[key: string | number]: unknown;
|
|
30
|
-
} ? { [Key in keyof T]: Stubify<T[Key]> } : T;
|
|
31
|
-
type MaybeProvider<T> = T extends object ? Provider<T> : unknown;
|
|
32
|
-
type MaybeDisposable<T> = T extends object ? Disposable : unknown;
|
|
33
|
-
type Result<T> = T extends Stubable ? Promise<Stub<T>> & Provider<T> : T extends Serializable<T> ? Promise<Stubify<T> & MaybeDisposable<T>> & MaybeProvider<T> : never;
|
|
34
|
-
type MethodKey<Api> = { [Key in keyof Api]-?: Key extends string ? Api[Key] extends ((...args: Array<any>) => unknown) ? Key : never : never }[keyof Api];
|
|
35
|
-
type MethodArgs<Api, Method extends keyof Api> = Api[Method] extends ((...args: infer Args) => unknown) ? Args : never;
|
|
36
|
-
type MethodReturn<Api, Method extends keyof Api> = Api[Method] extends ((...args: Array<any>) => infer Return) ? Return : never;
|
|
37
|
-
type DisposableValue = {
|
|
38
|
-
[Symbol.dispose](): void;
|
|
39
|
-
};
|
|
40
|
-
declare const isDisposable: (value: unknown) => value is DisposableValue;
|
|
41
|
-
declare const dispose: (value: unknown) => Effect.Effect<void>;
|
|
42
|
-
declare const resolve: <A>(value: A) => Effect.Effect<Awaited<A>, unknown>;
|
|
43
|
-
declare const scoped: <A>(value: A) => Effect.Effect<Awaited<A>, unknown, Scope.Scope>;
|
|
44
|
-
declare namespace RpcDefinition_d_exports {
|
|
45
|
-
export { Definition$9 as Definition, Method$5 as Method, Methods$4 as Methods, NoReservedMethods$4 as NoReservedMethods, ReservedMethodName$6 as ReservedMethodName, ReservedMethodNameError, RpcArgumentCountError, RpcArgumentDecodeError, RpcArgumentEncodeError, RpcReservedMethodNameError, RpcSuccessDecodeError, RpcSuccessEncodeError, ServiceFreeSchema$4 as ServiceFreeSchema, assertNoReservedMethodNames, assertNoReservedMethods, decodeArgs, decodeSuccess, encodeArgs, encodeSuccess, make$10 as make, method$4 as method, reservedMethodNames };
|
|
19
|
+
//#region src/DurableObjectStorage.d.ts
|
|
20
|
+
declare namespace DurableObjectStorage_d_exports {
|
|
21
|
+
export { DurableObjectStorage, DurableObjectTransaction, SchemaBackedSyncKvStorage, SqlCursor, SqlStorage, SqlStorageValue, StorageOperationError, SyncKvDefinition, SyncKvStorage, fromDurableObjectStorage };
|
|
46
22
|
}
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
} &
|
|
50
|
-
|
|
51
|
-
readonly definition: string;
|
|
52
|
-
readonly method: string;
|
|
53
|
-
}> {}
|
|
54
|
-
declare const RpcArgumentCountError_base: new <A extends Record<string, any> = {}>(args: _$effect_Types0.VoidIfEmpty<{ readonly [P in keyof A as P extends "_tag" ? never : P]: A[P] }>) => _$effect_Cause0.YieldableError & {
|
|
55
|
-
readonly _tag: "RpcArgumentCountError";
|
|
56
|
-
} & Readonly<A>;
|
|
57
|
-
declare class RpcArgumentCountError extends RpcArgumentCountError_base<{
|
|
58
|
-
readonly definition: string;
|
|
59
|
-
readonly method: string;
|
|
60
|
-
readonly expected: number;
|
|
61
|
-
readonly actual: number;
|
|
62
|
-
}> {}
|
|
63
|
-
declare const RpcArgumentDecodeError_base: new <A extends Record<string, any> = {}>(args: _$effect_Types0.VoidIfEmpty<{ readonly [P in keyof A as P extends "_tag" ? never : P]: A[P] }>) => _$effect_Cause0.YieldableError & {
|
|
64
|
-
readonly _tag: "RpcArgumentDecodeError";
|
|
23
|
+
/** Supported primitive value types for Durable Object SQL APIs. */
|
|
24
|
+
type SqlStorageValue = globalThis.SqlStorageValue;
|
|
25
|
+
declare const StorageOperationError_base: new <A extends Record<string, any> = {}>(args: _$effect_Types0.VoidIfEmpty<{ readonly [P in keyof A as P extends "_tag" ? never : P]: A[P] }>) => _$effect_Cause0.YieldableError & {
|
|
26
|
+
readonly _tag: "StorageOperationError";
|
|
65
27
|
} & Readonly<A>;
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
readonly
|
|
69
|
-
readonly index: number;
|
|
28
|
+
/** Error type used when a storage operation throws or rejects. */
|
|
29
|
+
declare class StorageOperationError extends StorageOperationError_base<{
|
|
30
|
+
readonly operation: string;
|
|
70
31
|
readonly cause: unknown;
|
|
71
32
|
}> {}
|
|
72
|
-
|
|
73
|
-
|
|
33
|
+
type StorageEffect<A> = Effect.Effect<A, StorageOperationError>;
|
|
34
|
+
/**
|
|
35
|
+
* Effect wrapper for Cloudflare SQL cursor operations.
|
|
36
|
+
*/
|
|
37
|
+
interface SqlCursor<T extends Record<string, SqlStorageValue>> {
|
|
38
|
+
next(): StorageEffect<{
|
|
39
|
+
done?: false;
|
|
40
|
+
value: T;
|
|
41
|
+
} | {
|
|
42
|
+
done: true;
|
|
43
|
+
value?: never;
|
|
44
|
+
}>;
|
|
45
|
+
toArray(): StorageEffect<Array<T>>;
|
|
46
|
+
one(): StorageEffect<T>;
|
|
47
|
+
raw<U extends Array<SqlStorageValue>>(): StorageEffect<IterableIterator<U>>;
|
|
48
|
+
readonly columnNames: Array<string>;
|
|
49
|
+
readonly rowsRead: StorageEffect<number>;
|
|
50
|
+
readonly rowsWritten: StorageEffect<number>;
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Effect wrapper for Durable Object SQLite APIs.
|
|
54
|
+
*/
|
|
55
|
+
interface SqlStorage {
|
|
56
|
+
/** Executes a SQL statement and returns a typed cursor. */
|
|
57
|
+
exec<T extends Record<string, SqlStorageValue>>(query: string, ...bindings: Array<SqlStorageValue>): StorageEffect<SqlCursor<T>>;
|
|
58
|
+
readonly databaseSize: number;
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* Schema pair used by `SyncKvStorage.schema(...)`.
|
|
62
|
+
*/
|
|
63
|
+
interface SyncKvDefinition<Key, Value, EncodedValue> {
|
|
64
|
+
readonly key: Schema.Codec<Key, string>;
|
|
65
|
+
readonly value: Schema.Codec<Value, EncodedValue>;
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* Sync KV wrapper that transparently encodes keys/values through Effect Schema.
|
|
69
|
+
*/
|
|
70
|
+
interface SchemaBackedSyncKvStorage<Key, Value> {
|
|
71
|
+
get(key: Key): Effect.Effect<Option.Option<Value>, unknown>;
|
|
72
|
+
put(key: Key, value: Value): Effect.Effect<void, unknown>;
|
|
73
|
+
delete(key: Key): Effect.Effect<boolean, unknown>;
|
|
74
|
+
list(options?: globalThis.SyncKvListOptions): Effect.Effect<Array<[Key, Value]>, unknown>;
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* Effect wrapper for synchronous KV attached to Durable Object SQLite storage.
|
|
78
|
+
*/
|
|
79
|
+
interface SyncKvStorage {
|
|
80
|
+
get<T = unknown>(key: string): StorageEffect<T | undefined>;
|
|
81
|
+
put<T>(key: string, value: T): StorageEffect<void>;
|
|
82
|
+
delete(key: string): StorageEffect<boolean>;
|
|
83
|
+
list<T = unknown>(options?: globalThis.SyncKvListOptions): StorageEffect<Array<[string, T]>>;
|
|
84
|
+
schema<Key, Value, EncodedValue>(definition: SyncKvDefinition<Key, Value, EncodedValue>): SchemaBackedSyncKvStorage<Key, Value>;
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* Effect wrapper around Cloudflare transaction callbacks.
|
|
88
|
+
*/
|
|
89
|
+
interface DurableObjectTransaction {
|
|
90
|
+
get<T = unknown>(key: string, options?: globalThis.DurableObjectGetOptions): StorageEffect<T | undefined>;
|
|
91
|
+
get<T = unknown>(keys: Array<string>, options?: globalThis.DurableObjectGetOptions): StorageEffect<Map<string, T>>;
|
|
92
|
+
list<T = unknown>(options?: globalThis.DurableObjectListOptions): StorageEffect<Map<string, T>>;
|
|
93
|
+
put<T>(key: string, value: T, options?: globalThis.DurableObjectPutOptions): StorageEffect<void>;
|
|
94
|
+
put<T>(entries: Record<string, T>, options?: globalThis.DurableObjectPutOptions): StorageEffect<void>;
|
|
95
|
+
delete(key: string, options?: globalThis.DurableObjectPutOptions): StorageEffect<boolean>;
|
|
96
|
+
delete(keys: Array<string>, options?: globalThis.DurableObjectPutOptions): StorageEffect<number>;
|
|
97
|
+
rollback(): StorageEffect<void>;
|
|
98
|
+
getAlarm(options?: globalThis.DurableObjectGetAlarmOptions): StorageEffect<number | null>;
|
|
99
|
+
setAlarm(scheduledTime: number | Date, options?: globalThis.DurableObjectSetAlarmOptions): StorageEffect<void>;
|
|
100
|
+
deleteAlarm(options?: globalThis.DurableObjectSetAlarmOptions): StorageEffect<void>;
|
|
101
|
+
}
|
|
102
|
+
/**
|
|
103
|
+
* Effect wrapper around Cloudflare Durable Object storage.
|
|
104
|
+
*
|
|
105
|
+
* @example
|
|
106
|
+
* ```ts
|
|
107
|
+
* const program = Effect.gen(function* () {
|
|
108
|
+
* const state = yield* DurableObjectState;
|
|
109
|
+
* yield* state.storage.put("counter", 1);
|
|
110
|
+
* const value = yield* state.storage.get<number>("counter");
|
|
111
|
+
* return value;
|
|
112
|
+
* });
|
|
113
|
+
* ```
|
|
114
|
+
*/
|
|
115
|
+
interface DurableObjectStorage {
|
|
116
|
+
get<T = unknown>(key: string, options?: globalThis.DurableObjectGetOptions): StorageEffect<T | undefined>;
|
|
117
|
+
put<T>(key: string, value: T, options?: globalThis.DurableObjectPutOptions): StorageEffect<void>;
|
|
118
|
+
delete(key: string, options?: globalThis.DurableObjectPutOptions): StorageEffect<boolean>;
|
|
119
|
+
/**
|
|
120
|
+
* Deletes all stored data. On compatibility dates before 2026-02-24, Cloudflare
|
|
121
|
+
* documents that active alarms must be deleted separately with `deleteAlarm()`.
|
|
122
|
+
*/
|
|
123
|
+
deleteAll(options?: globalThis.DurableObjectPutOptions): StorageEffect<void>;
|
|
124
|
+
getAlarm(options?: globalThis.DurableObjectGetAlarmOptions): StorageEffect<number | null>;
|
|
125
|
+
setAlarm(scheduledTime: number | Date, options?: globalThis.DurableObjectSetAlarmOptions): StorageEffect<void>;
|
|
126
|
+
deleteAlarm(options?: globalThis.DurableObjectSetAlarmOptions): StorageEffect<void>;
|
|
127
|
+
/**
|
|
128
|
+
* SQLite-backed Durable Object storage only.
|
|
129
|
+
*
|
|
130
|
+
* The callback Effect must complete synchronously. If it requires asynchronous
|
|
131
|
+
* work, use `transaction` instead so Cloudflare can run the async transaction
|
|
132
|
+
* callback under the platform's transaction contract.
|
|
133
|
+
*/
|
|
134
|
+
transactionSync<A, E, R>(closure: () => Effect.Effect<A, E, R>): Effect.Effect<A, E | StorageOperationError, R>;
|
|
135
|
+
/**
|
|
136
|
+
* Runs an async transaction and exposes a typed transaction wrapper.
|
|
137
|
+
*/
|
|
138
|
+
transaction<A, E, R>(closure: (txn: DurableObjectTransaction) => Effect.Effect<A, E, R>): Effect.Effect<A, E | StorageOperationError, R>;
|
|
139
|
+
/** Flushes pending writes to disk. */
|
|
140
|
+
sync(): StorageEffect<void>;
|
|
141
|
+
/** SQLite-backed Durable Object storage point-in-time recovery API only. */
|
|
142
|
+
getCurrentBookmark(): StorageEffect<string>;
|
|
143
|
+
/** SQLite-backed Durable Object storage point-in-time recovery API only. */
|
|
144
|
+
onNextSessionRestoreBookmark(bookmark: string): StorageEffect<string>;
|
|
145
|
+
readonly sql: SqlStorage;
|
|
146
|
+
readonly kv: SyncKvStorage;
|
|
147
|
+
}
|
|
148
|
+
/**
|
|
149
|
+
* Wraps native Cloudflare storage APIs as Effect-returning helpers.
|
|
150
|
+
*/
|
|
151
|
+
declare const fromDurableObjectStorage: (storage: globalThis.DurableObjectStorage) => DurableObjectStorage;
|
|
152
|
+
declare namespace DurableObjectWebSocket_d_exports {
|
|
153
|
+
export { AcceptUpgradeOptions, AcceptedUpgrade, AttachmentInvalidPolicy, AttachmentRehydrateOptions, DurableWebSocket, DurableWebSocketAttachment, DurableWebSocketAttachmentError, DurableWebSocketCloseError, DurableWebSocketHandlers, DurableWebSocketSendData, DurableWebSocketSendError, RehydratedDurableWebSocket, acceptUpgrade, attachment, fromWebSocket, handlers };
|
|
154
|
+
}
|
|
155
|
+
/** Data supported by Cloudflare websocket `send`. */
|
|
156
|
+
type DurableWebSocketSendData = string | ArrayBuffer | ArrayBufferView;
|
|
157
|
+
declare const DurableWebSocketSendError_base: new <A extends Record<string, any> = {}>(args: _$effect_Types0.VoidIfEmpty<{ readonly [P in keyof A as P extends "_tag" ? never : P]: A[P] }>) => _$effect_Cause0.YieldableError & {
|
|
158
|
+
readonly _tag: "DurableWebSocketSendError";
|
|
74
159
|
} & Readonly<A>;
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
readonly method: string;
|
|
78
|
-
readonly index: number;
|
|
160
|
+
/** Error raised when sending on a Durable Object websocket fails. */
|
|
161
|
+
declare class DurableWebSocketSendError extends DurableWebSocketSendError_base<{
|
|
79
162
|
readonly cause: unknown;
|
|
80
163
|
}> {}
|
|
81
|
-
declare const
|
|
82
|
-
readonly _tag: "
|
|
164
|
+
declare const DurableWebSocketCloseError_base: new <A extends Record<string, any> = {}>(args: _$effect_Types0.VoidIfEmpty<{ readonly [P in keyof A as P extends "_tag" ? never : P]: A[P] }>) => _$effect_Cause0.YieldableError & {
|
|
165
|
+
readonly _tag: "DurableWebSocketCloseError";
|
|
83
166
|
} & Readonly<A>;
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
readonly method: string;
|
|
167
|
+
/** Error raised when closing a Durable Object websocket fails. */
|
|
168
|
+
declare class DurableWebSocketCloseError extends DurableWebSocketCloseError_base<{
|
|
87
169
|
readonly cause: unknown;
|
|
88
170
|
}> {}
|
|
89
|
-
declare const
|
|
90
|
-
readonly _tag: "
|
|
171
|
+
declare const DurableWebSocketAttachmentError_base: new <A extends Record<string, any> = {}>(args: _$effect_Types0.VoidIfEmpty<{ readonly [P in keyof A as P extends "_tag" ? never : P]: A[P] }>) => _$effect_Cause0.YieldableError & {
|
|
172
|
+
readonly _tag: "DurableWebSocketAttachmentError";
|
|
91
173
|
} & Readonly<A>;
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
readonly
|
|
174
|
+
/** Error raised when serializing or deserializing a websocket attachment fails. */
|
|
175
|
+
declare class DurableWebSocketAttachmentError extends DurableWebSocketAttachmentError_base<{
|
|
176
|
+
readonly operation: "serialize" | "deserialize";
|
|
95
177
|
readonly cause: unknown;
|
|
96
178
|
}> {}
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
export type EncodedArgs<Self extends Any> = EncodedArgsFromSchemas<Self["args"]>;
|
|
110
|
-
export type Success<Self extends Any> = Schema.Schema.Type<Self["success"]>;
|
|
111
|
-
export type EncodedSuccess<Self extends Any> = Schema.Codec.Encoded<Self["success"]>;
|
|
112
|
-
export {};
|
|
179
|
+
/** Effect-native wrapper around a hibernatable Durable Object websocket. */
|
|
180
|
+
interface DurableWebSocket<Attachment = unknown> {
|
|
181
|
+
/** Underlying Cloudflare websocket. */
|
|
182
|
+
readonly raw: WebSocket;
|
|
183
|
+
/** Sends a message through the socket. */
|
|
184
|
+
send(data: DurableWebSocketSendData): Effect.Effect<void, DurableWebSocketSendError>;
|
|
185
|
+
/** Closes the socket. */
|
|
186
|
+
close(code?: number, reason?: string): Effect.Effect<void, DurableWebSocketCloseError>;
|
|
187
|
+
/** Serializes hibernation attachment metadata onto the socket. */
|
|
188
|
+
serializeAttachment<A = Attachment>(value: A): Effect.Effect<void, DurableWebSocketAttachmentError>;
|
|
189
|
+
/** Deserializes hibernation attachment metadata from the socket. */
|
|
190
|
+
readonly deserializeAttachment: Effect.Effect<unknown, DurableWebSocketAttachmentError>;
|
|
113
191
|
}
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
192
|
+
/** Wraps a native Cloudflare websocket in the Effect-native Durable Object API. */
|
|
193
|
+
declare const fromWebSocket: <Attachment = unknown>(raw: WebSocket) => DurableWebSocket<Attachment>;
|
|
194
|
+
/**
|
|
195
|
+
* Options for accepting an incoming websocket request in a Durable Object.
|
|
196
|
+
*/
|
|
197
|
+
interface AcceptUpgradeOptions<Attachment = unknown> {
|
|
198
|
+
/** Optional websocket tags for Durable Object hibernation filtering. */
|
|
199
|
+
readonly tags?: ReadonlyArray<string> | undefined;
|
|
200
|
+
/** Optional attachment serialized onto the server socket. */
|
|
201
|
+
readonly attachment?: Attachment | undefined;
|
|
119
202
|
}
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
readonly method: string;
|
|
128
|
-
readonly target: string;
|
|
129
|
-
constructor(target: string, method: string);
|
|
130
|
-
}
|
|
131
|
-
declare const assertNoReservedMethods: (target: string, methods: Record<string, unknown>, reserved: ReadonlySet<string>) => void;
|
|
132
|
-
declare function method$4<Success extends ServiceFreeSchema$4>(definition: {
|
|
133
|
-
readonly success: Success;
|
|
134
|
-
}): Method$5<readonly [], Success>;
|
|
135
|
-
declare function method$4<const Args extends ReadonlyArray<ServiceFreeSchema$4>, Success extends ServiceFreeSchema$4>(definition: {
|
|
136
|
-
readonly args: Args;
|
|
137
|
-
readonly success: Success;
|
|
138
|
-
}): Method$5<Args, Success>;
|
|
139
|
-
declare const assertNoReservedMethodNames: (definition: Definition$9.Any) => Effect.Effect<void, RpcReservedMethodNameError>;
|
|
140
|
-
declare const decodeArgs: <const Self extends Definition$9.Any, MethodName extends Definition$9.MethodNames<Self>>(definition: Self, methodName: MethodName, args: ReadonlyArray<unknown>) => Effect.Effect<Method$5.Args<Self["methods"][MethodName]>, RpcArgumentCountError | RpcArgumentDecodeError>;
|
|
141
|
-
declare const encodeArgs: <const Self extends Definition$9.Any, MethodName extends Definition$9.MethodNames<Self>>(definition: Self, methodName: MethodName, args: Method$5.Args<Self["methods"][MethodName]>) => Effect.Effect<Method$5.EncodedArgs<Self["methods"][MethodName]>, RpcArgumentCountError | RpcArgumentEncodeError>;
|
|
142
|
-
declare const encodeSuccess: <const Self extends Definition$9.Any, MethodName extends Definition$9.MethodNames<Self>>(definition: Self, methodName: MethodName, value: Method$5.Success<Self["methods"][MethodName]>) => Effect.Effect<Method$5.EncodedSuccess<Self["methods"][MethodName]>, RpcSuccessEncodeError>;
|
|
143
|
-
declare const decodeSuccess: <const Self extends Definition$9.Any, MethodName extends Definition$9.MethodNames<Self>>(definition: Self, methodName: MethodName, value: unknown) => Effect.Effect<Method$5.Success<Self["methods"][MethodName]>, RpcSuccessDecodeError>;
|
|
144
|
-
declare const make$10: <Id extends string, const MethodsShape extends Methods$4>(id: Id, methods: MethodsShape) => Definition$9<Id, MethodsShape>;
|
|
145
|
-
declare namespace QueueBinding_d_exports {
|
|
146
|
-
export { MessageSendRequest, QueueBindingClient, QueueBindingDefinition, QueueMetrics, QueueOperationError, QueueProducer, QueueSendBatchOptions, QueueSendBatchResponse, QueueSendOptions, QueueSendResponse, isQueue, layer$9 as layer, makeClient$6 as makeClient };
|
|
147
|
-
}
|
|
148
|
-
type QueueSendOptions = globalThis.QueueSendOptions;
|
|
149
|
-
type QueueSendResponse = globalThis.QueueSendResponse;
|
|
150
|
-
type QueueSendBatchOptions = globalThis.QueueSendBatchOptions;
|
|
151
|
-
type QueueSendBatchResponse = globalThis.QueueSendBatchResponse;
|
|
152
|
-
type QueueMetrics = globalThis.QueueMetrics;
|
|
153
|
-
type MessageSendRequest<Body> = globalThis.MessageSendRequest<Body>;
|
|
154
|
-
type QueueProducer<Body> = Pick<globalThis.Queue<Body>, "send"> & Partial<Pick<globalThis.Queue<Body>, "sendBatch" | "metrics">>;
|
|
155
|
-
interface QueueBindingDefinition<Message extends ServiceFreeSchema$4> {
|
|
156
|
-
/** Binding name as configured in `wrangler.jsonc`. */
|
|
157
|
-
readonly binding: string;
|
|
158
|
-
/** Codec used to encode messages before sending them to Cloudflare Queues. */
|
|
159
|
-
readonly message: Message;
|
|
160
|
-
}
|
|
161
|
-
interface QueueBindingClient<Message extends ServiceFreeSchema$4> {
|
|
162
|
-
readonly send: (message: Schema.Schema.Type<Message>, options?: QueueSendOptions) => Effect.Effect<void, QueueOperationError | Schema.SchemaError>;
|
|
163
|
-
readonly sendBatch: (messages: Iterable<MessageSendRequest<Schema.Schema.Type<Message>>>, options?: QueueSendBatchOptions) => Effect.Effect<void, QueueOperationError | Schema.SchemaError>;
|
|
164
|
-
readonly metrics: () => Effect.Effect<QueueMetrics, QueueOperationError>;
|
|
165
|
-
readonly unsafeRaw: Effect.Effect<globalThis.Queue<Schema.Codec.Encoded<Message>>>;
|
|
166
|
-
}
|
|
167
|
-
declare const QueueOperationError_base: new <A extends Record<string, any> = {}>(args: _$effect_Types0.VoidIfEmpty<{ readonly [P in keyof A as P extends "_tag" ? never : P]: A[P] }>) => _$effect_Cause0.YieldableError & {
|
|
168
|
-
readonly _tag: "QueueOperationError";
|
|
169
|
-
} & Readonly<A>;
|
|
170
|
-
declare class QueueOperationError extends QueueOperationError_base<{
|
|
171
|
-
readonly binding: string;
|
|
172
|
-
readonly operation: string;
|
|
173
|
-
readonly cause: unknown;
|
|
174
|
-
readonly message: string;
|
|
175
|
-
}> {}
|
|
176
|
-
declare const isQueue: <Body>(value: unknown) => value is QueueProducer<Body>;
|
|
177
|
-
declare const makeClient$6: <Message extends ServiceFreeSchema$4>(definition: QueueBindingDefinition<Message>) => ((queue: QueueProducer<Schema.Codec.Encoded<Message>>) => QueueBindingClient<Message>);
|
|
178
|
-
declare const layer$9: <Self, Message extends ServiceFreeSchema$4>(tag: Context.Service<Self, QueueBindingClient<Message>>, definition: QueueBindingDefinition<Message>) => _$effect_Layer0.Layer<Self, BindingNotFoundError | BindingValidationError, WorkerEnvironment>;
|
|
179
|
-
declare namespace QueueDefinition_d_exports {
|
|
180
|
-
export { Definition$8 as Definition, Handler$3 as Handler, LayerOptions$12 as LayerOptions, Options$7 as Options, Queue$1 as Queue, Tag$11 as Tag, TagClass$10 as TagClass, implement$7 as implement, make$9 as make };
|
|
181
|
-
}
|
|
182
|
-
interface Definition$8<Id extends string = string, Message extends ServiceFreeSchema$4 = ServiceFreeSchema$4> {
|
|
183
|
-
readonly id: Id;
|
|
184
|
-
readonly message: Message;
|
|
185
|
-
}
|
|
186
|
-
declare namespace Definition$8 {
|
|
187
|
-
type Any = Definition$8<string, ServiceFreeSchema$4>;
|
|
188
|
-
}
|
|
189
|
-
type Handler$3<ROut, Self extends Definition$8.Any> = (batch: QueueBatch<Schema.Schema.Type<Self["message"]>>) => Effect.Effect<void, unknown, ExecutionContext | WorkerContext | WorkerEnvironment | Scope.Scope | ROut>;
|
|
190
|
-
interface Options$7<ROut, Self extends Definition$8.Any> extends Omit<WorkerOptions<ROut, Record<never, never>>, "queue" | "rpc"> {
|
|
191
|
-
readonly queue: Handler$3<ROut, Self>;
|
|
192
|
-
readonly rpc?: never;
|
|
193
|
-
}
|
|
194
|
-
type LayerOptions$12 = {
|
|
195
|
-
readonly binding: string;
|
|
196
|
-
};
|
|
197
|
-
interface TagClass$10<Self, Id extends string, Message extends ServiceFreeSchema$4> extends Context.ServiceClass<Self, Id, QueueBindingClient<Message>> {
|
|
198
|
-
readonly id: Id;
|
|
199
|
-
readonly message: Message;
|
|
200
|
-
readonly make: <ROut, LayerError>(layer: Layer.Layer<ROut, LayerError, ExecutionContext | WorkerContext | WorkerEnvironment>, options: Options$7<ROut, Definition$8<Id, Message>>) => WorkerClass<Record<never, never>, ROut>;
|
|
201
|
-
readonly layer: (options: LayerOptions$12) => Layer.Layer<Self, BindingNotFoundError | BindingValidationError, WorkerEnvironment>;
|
|
202
|
-
readonly send: (message: Schema.Schema.Type<Message>, options?: QueueSendOptions) => Effect.Effect<void, QueueOperationError | Schema.SchemaError, Self>;
|
|
203
|
-
readonly sendBatch: (messages: Iterable<MessageSendRequest<Schema.Schema.Type<Message>>>, options?: QueueSendBatchOptions) => Effect.Effect<void, QueueOperationError | Schema.SchemaError, Self>;
|
|
204
|
-
readonly metrics: () => Effect.Effect<QueueMetrics, QueueOperationError, Self>;
|
|
205
|
-
readonly unsafeRaw: () => Effect.Effect<globalThis.Queue<Schema.Codec.Encoded<Message>>, never, Self>;
|
|
203
|
+
/**
|
|
204
|
+
* Result of a websocket upgrade accepted by {@link acceptUpgrade}.
|
|
205
|
+
*/
|
|
206
|
+
interface AcceptedUpgrade<Attachment = unknown> {
|
|
207
|
+
readonly client: WebSocket;
|
|
208
|
+
readonly server: DurableWebSocket<Attachment>;
|
|
209
|
+
readonly response: Response;
|
|
206
210
|
}
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
211
|
+
/**
|
|
212
|
+
* Accepts a websocket upgrade and registers the server socket on `DurableObjectState`.
|
|
213
|
+
*
|
|
214
|
+
* @example
|
|
215
|
+
* ```ts
|
|
216
|
+
* const response = yield* DurableObjectWebSocket.acceptUpgrade({
|
|
217
|
+
* tags: ["room:general"],
|
|
218
|
+
* });
|
|
219
|
+
*
|
|
220
|
+
* return response.response;
|
|
221
|
+
* ```
|
|
222
|
+
*/
|
|
223
|
+
declare const acceptUpgrade: <Attachment = unknown>(options?: AcceptUpgradeOptions<Attachment>) => Effect.Effect<AcceptedUpgrade<Attachment>, never, DurableObjectState>;
|
|
224
|
+
type AttachmentInvalidPolicy = "ignore" | "ignore-and-close" | "fail";
|
|
225
|
+
interface AttachmentRehydrateOptions {
|
|
226
|
+
/** Optional Durable Object websocket tag filter. */
|
|
227
|
+
readonly tag?: string | undefined;
|
|
228
|
+
/** Invalid attachment behavior. Defaults to skipping invalid sockets. */
|
|
229
|
+
readonly onInvalid?: AttachmentInvalidPolicy | undefined;
|
|
219
230
|
}
|
|
220
|
-
interface
|
|
221
|
-
readonly
|
|
222
|
-
readonly
|
|
223
|
-
readonly timestamp: Date;
|
|
224
|
-
readonly body: Body;
|
|
225
|
-
readonly attempts: number;
|
|
226
|
-
readonly ack: Effect.Effect<void>;
|
|
227
|
-
readonly retry: (options?: globalThis.QueueRetryOptions) => Effect.Effect<void>;
|
|
231
|
+
interface RehydratedDurableWebSocket<Attachment> {
|
|
232
|
+
readonly socket: DurableWebSocket<Attachment>;
|
|
233
|
+
readonly attachment: Attachment;
|
|
228
234
|
}
|
|
229
|
-
interface
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
readonly
|
|
234
|
-
readonly ackAll: Effect.Effect<void>;
|
|
235
|
-
readonly retryAll: (options?: globalThis.QueueRetryOptions) => Effect.Effect<void>;
|
|
235
|
+
interface DurableWebSocketAttachment<Attachment, Encoded> {
|
|
236
|
+
serialize(socket: DurableWebSocket<unknown>, value: Attachment): Effect.Effect<void, DurableWebSocketAttachmentError>;
|
|
237
|
+
deserialize(socket: DurableWebSocket<unknown>): Effect.Effect<Option.Option<Attachment>, DurableWebSocketAttachmentError>;
|
|
238
|
+
rehydrate(options?: AttachmentRehydrateOptions): Effect.Effect<Array<RehydratedDurableWebSocket<Attachment>>, DurableWebSocketAttachmentError, DurableObjectState>;
|
|
239
|
+
readonly schema: Schema.Codec<Attachment, Encoded, never, never>;
|
|
236
240
|
}
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
readonly
|
|
242
|
-
readonly
|
|
243
|
-
readonly index: number;
|
|
244
|
-
readonly cause: unknown;
|
|
245
|
-
}> {}
|
|
246
|
-
type RuntimeContext$2<ROut> = ExecutionContext | WorkerContext | WorkerEnvironment | ROut;
|
|
247
|
-
type QueueHandlerContext<ROut> = RuntimeContext$2<ROut> | Scope.Scope;
|
|
248
|
-
type QueueHandler<ROut, Body = unknown> = (batch: QueueBatch<Body>) => Effect.Effect<void, unknown, QueueHandlerContext<ROut>>;
|
|
249
|
-
interface QueueOptions<ROut, Body = unknown> {
|
|
250
|
-
readonly queue: QueueHandler<ROut, Body>;
|
|
241
|
+
/** Creates typed attachment helpers for accepted and rehydrated sockets. */
|
|
242
|
+
declare const attachment: <const AttachmentSchema extends Schema.Codec<any, any, never, never>>(schema: AttachmentSchema) => DurableWebSocketAttachment<Schema.Schema.Type<AttachmentSchema>, Schema.Codec.Encoded<AttachmentSchema>>;
|
|
243
|
+
interface DurableWebSocketHandlers<R = never, E = unknown> {
|
|
244
|
+
readonly message?: (socket: DurableWebSocket, message: string | ArrayBuffer) => Effect.Effect<void, E, R>;
|
|
245
|
+
readonly close?: (socket: DurableWebSocket, code: number, reason: string, wasClean: boolean) => Effect.Effect<void, E, R>;
|
|
246
|
+
readonly error?: (socket: DurableWebSocket, error: unknown) => Effect.Effect<void, E, R>;
|
|
251
247
|
}
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
attempts: number;
|
|
258
|
-
ack: Effect.Effect<void, never, never>;
|
|
259
|
-
retry: (options?: globalThis.QueueRetryOptions) => Effect.Effect<void, never, never>;
|
|
248
|
+
/** Maps compact websocket lifecycle handler names to `DurableObject.make` options. */
|
|
249
|
+
declare const handlers: <R = never, E = unknown>(options: DurableWebSocketHandlers<R, E>) => {
|
|
250
|
+
webSocketMessage: ((socket: DurableWebSocket, message: string | ArrayBuffer) => Effect.Effect<void, E, R>) | undefined;
|
|
251
|
+
webSocketClose: ((socket: DurableWebSocket, code: number, reason: string, wasClean: boolean) => Effect.Effect<void, E, R>) | undefined;
|
|
252
|
+
webSocketError: ((socket: DurableWebSocket, error: unknown) => Effect.Effect<void, E, R>) | undefined;
|
|
260
253
|
};
|
|
261
|
-
declare
|
|
262
|
-
|
|
263
|
-
type Definition$7<Id extends string = string, Message extends Definition$8.Any["message"] = Definition$8.Any["message"]> = Definition$8<Id, Message>;
|
|
264
|
-
declare namespace Definition$7 {
|
|
265
|
-
type Any = Definition$8.Any;
|
|
266
|
-
}
|
|
267
|
-
type LayerOptions$11 = LayerOptions$12;
|
|
268
|
-
type TagClass$9<Self, Id extends string, Message extends Definition$8.Any["message"]> = TagClass$10<Self, Id, Message>;
|
|
269
|
-
declare const Tag$10: <Self>() => <Id extends string, Message extends Definition$8.Any["message"]>(id: Id, definition: {
|
|
270
|
-
readonly message: Message;
|
|
271
|
-
}) => TagClass$9<Self, Id, Message>;
|
|
272
|
-
declare const implement$6: <ROut, const Self extends Definition$8.Any>(_definition: Self, handler: Handler$3<ROut, Self>) => Handler$3<ROut, Self>;
|
|
273
|
-
type Handler$2<ROut, Self extends Definition$8.Any> = Handler$3<ROut, Self>;
|
|
274
|
-
type Options$6<ROut, Self extends Definition$8.Any> = Options$7<ROut, Self>;
|
|
275
|
-
declare namespace WorkerDefinition_d_exports {
|
|
276
|
-
export { Api$3 as Api, Definition$6 as Definition, HandlerEffect$3 as HandlerEffect, Handlers$3 as Handlers, LayerOptions$10 as LayerOptions, Method$4 as Method, Methods$3 as Methods, NoReservedMethods$3 as NoReservedMethods, Options$5 as Options, ReservedMethodName$5 as ReservedMethodName, ServerApi$4 as ServerApi, ServiceFreeSchema$3 as ServiceFreeSchema, Tag$9 as Tag, TagClass$8 as TagClass, Worker, implement$5 as implement, make$8 as make, method$3 as method };
|
|
277
|
-
}
|
|
278
|
-
type ServiceFreeSchema$3 = Schema.Codec<any, any, never, never>;
|
|
279
|
-
interface Method$4<Args extends ReadonlyArray<ServiceFreeSchema$3> = ReadonlyArray<ServiceFreeSchema$3>, Success extends ServiceFreeSchema$3 = ServiceFreeSchema$3> {
|
|
280
|
-
readonly args: Args;
|
|
281
|
-
readonly success: Success;
|
|
282
|
-
}
|
|
283
|
-
declare namespace Method$4 {
|
|
284
|
-
export type Any = Method$4<ReadonlyArray<ServiceFreeSchema$3>, ServiceFreeSchema$3>;
|
|
285
|
-
type ArgsFromSchemas<Args extends ReadonlyArray<ServiceFreeSchema$3>> = Args extends readonly [] ? [] : Args extends readonly [infer Head extends ServiceFreeSchema$3, ...infer Tail extends ReadonlyArray<ServiceFreeSchema$3>] ? [Schema.Schema.Type<Head>, ...ArgsFromSchemas<Tail>] : Array<Schema.Schema.Type<Args[number]>>;
|
|
286
|
-
type EncodedArgsFromSchemas<Args extends ReadonlyArray<ServiceFreeSchema$3>> = Args extends readonly [] ? [] : Args extends readonly [infer Head extends ServiceFreeSchema$3, ...infer Tail extends ReadonlyArray<ServiceFreeSchema$3>] ? [Schema.Codec.Encoded<Head>, ...EncodedArgsFromSchemas<Tail>] : Array<Schema.Codec.Encoded<Args[number]>>;
|
|
287
|
-
export type Args<Self extends Any> = ArgsFromSchemas<Self["args"]>;
|
|
288
|
-
export type EncodedArgs<Self extends Any> = EncodedArgsFromSchemas<Self["args"]>;
|
|
289
|
-
export type Success<Self extends Any> = Schema.Schema.Type<Self["success"]>;
|
|
290
|
-
export type EncodedSuccess<Self extends Any> = Schema.Codec.Encoded<Self["success"]>;
|
|
291
|
-
export {};
|
|
254
|
+
declare namespace DurableObjectState_d_exports {
|
|
255
|
+
export { DurableObjectState, DurableObjectStateService, fromDurableObjectState };
|
|
292
256
|
}
|
|
293
|
-
type Methods$3 = Record<string, Method$4.Any>;
|
|
294
257
|
/**
|
|
295
|
-
*
|
|
296
|
-
*
|
|
297
|
-
* Create with {@link make} and reuse to type both worker implementations and
|
|
298
|
-
* service bindings in other workers.
|
|
258
|
+
* Effect-friendly wrapper around Cloudflare `DurableObjectState`.
|
|
299
259
|
*/
|
|
300
|
-
interface
|
|
301
|
-
|
|
302
|
-
readonly
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
260
|
+
interface DurableObjectStateService {
|
|
261
|
+
/** Underlying Cloudflare state instance. */
|
|
262
|
+
readonly raw: globalThis.DurableObjectState;
|
|
263
|
+
/** Durable Object id for the current instance. */
|
|
264
|
+
readonly id: globalThis.DurableObjectId;
|
|
265
|
+
/** Wrapped storage API. */
|
|
266
|
+
readonly storage: DurableObjectStorage;
|
|
267
|
+
/** Registers background work with Cloudflare's lifecycle. */
|
|
268
|
+
waitUntil(promise: Promise<unknown>): Effect.Effect<void>;
|
|
269
|
+
/**
|
|
270
|
+
* Runs an Effect inside Cloudflare's `blockConcurrencyWhile` gate.
|
|
271
|
+
*
|
|
272
|
+
* Cloudflare resets a Durable Object if the callback throws/rejects, or if the
|
|
273
|
+
* callback exceeds the platform timeout (currently documented as 30 seconds).
|
|
274
|
+
* This safe default resolves the callback with the Effect `Exit` for typed
|
|
275
|
+
* Effect failures and resumes that `Exit` afterward, so typed failures remain
|
|
276
|
+
* ordinary Effect failures instead of resetting the Durable Object. Defects
|
|
277
|
+
* and interruptions still reject the callback.
|
|
278
|
+
*/
|
|
279
|
+
blockConcurrencyWhile<A, E, R>(effect: Effect.Effect<A, E, R>): Effect.Effect<A, E, R>;
|
|
280
|
+
/**
|
|
281
|
+
* Runs an Effect inside Cloudflare's `blockConcurrencyWhile` gate and lets
|
|
282
|
+
* Effect failures reject the callback.
|
|
283
|
+
*
|
|
284
|
+
* Use this only when Cloudflare's reset-on-throw behavior is intentional. The
|
|
285
|
+
* platform also resets the Durable Object if the callback exceeds the
|
|
286
|
+
* documented timeout (currently 30 seconds).
|
|
287
|
+
*/
|
|
288
|
+
blockConcurrencyWhileOrReset<A, E, R>(effect: Effect.Effect<A, E, R>): Effect.Effect<A, E, R>;
|
|
289
|
+
/** Accepts a websocket connection for hibernation-capable Durable Objects. */
|
|
290
|
+
acceptWebSocket(ws: DurableWebSocket, tags?: Array<string>): Effect.Effect<void>;
|
|
291
|
+
/** Lists active sockets, optionally filtered by tag. */
|
|
292
|
+
getWebSockets(tag?: string): Effect.Effect<Array<DurableWebSocket>>;
|
|
293
|
+
/** Configures automatic request/response handling for sockets. */
|
|
294
|
+
setWebSocketAutoResponse(pair?: WebSocketRequestResponsePair): Effect.Effect<void>;
|
|
295
|
+
/** Gets the configured websocket auto-response pair. */
|
|
296
|
+
getWebSocketAutoResponse: Effect.Effect<WebSocketRequestResponsePair | null>;
|
|
297
|
+
/** Timestamp of the last automatic websocket response for a socket. */
|
|
298
|
+
getWebSocketAutoResponseTimestamp(ws: DurableWebSocket): Effect.Effect<Date | null>;
|
|
299
|
+
/** Sets the timeout for hibernatable websocket events. */
|
|
300
|
+
setHibernatableWebSocketEventTimeout(timeoutMs?: number): Effect.Effect<void>;
|
|
301
|
+
/** Gets the timeout for hibernatable websocket events. */
|
|
302
|
+
getHibernatableWebSocketEventTimeout: Effect.Effect<number | null>;
|
|
303
|
+
/** Reads tags attached to a websocket. */
|
|
304
|
+
getTags(ws: DurableWebSocket): Effect.Effect<Array<string>>;
|
|
305
|
+
/**
|
|
306
|
+
* Forcibly resets the Durable Object. Cloudflare logs an uncaught Error using
|
|
307
|
+
* the optional reason, and the method is not available in `wrangler dev` local
|
|
308
|
+
* development according to the Durable Object State docs.
|
|
309
|
+
*/
|
|
310
|
+
abort(reason?: string): Effect.Effect<void>;
|
|
306
311
|
}
|
|
307
|
-
|
|
308
|
-
type NoReservedMethods$3<MethodsShape extends Methods$3> = Extract<keyof MethodsShape, ReservedMethodName$5> extends never ? MethodsShape : never;
|
|
309
|
-
/**
|
|
310
|
-
* Promise-based client API derived from a {@link Definition}.
|
|
311
|
-
*/
|
|
312
|
-
type ServerApi$4<Self extends Definition$6.Any> = { readonly [Key in keyof Self["methods"]]: (...args: Method$4.Args<Self["methods"][Key]>) => Promise<Method$4.Success<Self["methods"][Key]>> };
|
|
313
|
-
type Api$3<Self extends Definition$6.Any> = Provider<ServerApi$4<Self>, ReservedMethodName$5>;
|
|
312
|
+
declare const DurableObjectState_base: Context.ServiceClass<DurableObjectState, "effect-cf/DurableObjectState", DurableObjectStateService>;
|
|
314
313
|
/**
|
|
315
|
-
*
|
|
314
|
+
* Context tag for accessing the current Durable Object state service.
|
|
316
315
|
*/
|
|
317
|
-
|
|
316
|
+
declare class DurableObjectState extends DurableObjectState_base {}
|
|
318
317
|
/**
|
|
319
|
-
*
|
|
318
|
+
* Wraps a native Cloudflare `DurableObjectState` as a {@link DurableObjectStateService}.
|
|
320
319
|
*/
|
|
321
|
-
|
|
322
|
-
|
|
320
|
+
declare const fromDurableObjectState: (state: globalThis.DurableObjectState) => DurableObjectStateService;
|
|
321
|
+
declare namespace CloudflareOtlp_d_exports {
|
|
322
|
+
export { CloudflareOtlpSettings, DurableObjectResourceOptions, LayerOptions$12 as LayerOptions, ResourceOptions, Serialization, Settings, Signal, WorkerResourceOptions, durableObjectLayer, layer$9 as layer, layerJson, layerProtobuf, settingsConfig, settingsLayer, workerLayer };
|
|
323
323
|
}
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
type
|
|
328
|
-
readonly id: Id;
|
|
329
|
-
readonly methods: MethodsShape;
|
|
330
|
-
readonly make: <ROut, LayerError>(layer: Layer.Layer<ROut, LayerError, ExecutionContext | WorkerContext | WorkerEnvironment>, options: Options$5<ROut, Definition$6<Id, MethodsShape>>) => WorkerClass<Handlers$3<ROut, Definition$6<Id, MethodsShape>>, ROut>;
|
|
331
|
-
readonly layer: (options: LayerOptions$10) => Layer.Layer<Self, BindingNotFoundError | BindingValidationError, WorkerEnvironment>;
|
|
332
|
-
};
|
|
324
|
+
/** Telemetry signal groups supported by the Cloudflare OTLP layers. */
|
|
325
|
+
type Signal = "logs" | "traces" | "metrics";
|
|
326
|
+
/** OTLP payload serialization used by the Effect OTLP exporters. */
|
|
327
|
+
type Serialization = "json" | "protobuf";
|
|
333
328
|
/**
|
|
334
|
-
*
|
|
329
|
+
* Resolved OpenTelemetry settings used by the Cloudflare OTLP layers.
|
|
330
|
+
*
|
|
331
|
+
* The default {@link settingsLayer} reads the standard OpenTelemetry
|
|
332
|
+
* environment variable names from `WorkerEnvironment`. Applications that use
|
|
333
|
+
* different binding names can provide {@link CloudflareOtlpSettings} directly
|
|
334
|
+
* with a custom layer.
|
|
335
335
|
*/
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
336
|
+
interface Settings {
|
|
337
|
+
/** Generic OTLP base endpoint, read from `OTEL_EXPORTER_OTLP_ENDPOINT`. */
|
|
338
|
+
readonly endpoint: Option.Option<string>;
|
|
339
|
+
/** Logs-specific OTLP endpoint, read from `OTEL_EXPORTER_OTLP_LOGS_ENDPOINT`. */
|
|
340
|
+
readonly logsEndpoint: Option.Option<string>;
|
|
341
|
+
/** Traces-specific OTLP endpoint, read from `OTEL_EXPORTER_OTLP_TRACES_ENDPOINT`. */
|
|
342
|
+
readonly tracesEndpoint: Option.Option<string>;
|
|
343
|
+
/** Metrics-specific OTLP endpoint, read from `OTEL_EXPORTER_OTLP_METRICS_ENDPOINT`. */
|
|
344
|
+
readonly metricsEndpoint: Option.Option<string>;
|
|
345
|
+
/** Comma-separated OTLP headers, read from `OTEL_EXPORTER_OTLP_HEADERS`. */
|
|
346
|
+
readonly headers: Option.Option<string>;
|
|
347
|
+
/** Logs-specific OTLP headers, read from `OTEL_EXPORTER_OTLP_LOGS_HEADERS`. */
|
|
348
|
+
readonly logsHeaders: Option.Option<string>;
|
|
349
|
+
/** Traces-specific OTLP headers, read from `OTEL_EXPORTER_OTLP_TRACES_HEADERS`. */
|
|
350
|
+
readonly tracesHeaders: Option.Option<string>;
|
|
351
|
+
/** Metrics-specific OTLP headers, read from `OTEL_EXPORTER_OTLP_METRICS_HEADERS`. */
|
|
352
|
+
readonly metricsHeaders: Option.Option<string>;
|
|
353
|
+
/** Service name, read from `OTEL_SERVICE_NAME`. */
|
|
354
|
+
readonly serviceName: Option.Option<string>;
|
|
355
|
+
/** Service version, read from the effect-cf convenience alias `OTEL_SERVICE_VERSION`. */
|
|
356
|
+
readonly serviceVersion: Option.Option<string>;
|
|
357
|
+
/** Resource attributes, read from `OTEL_RESOURCE_ATTRIBUTES`. */
|
|
358
|
+
readonly resourceAttributes: Option.Option<Record<string, string>>;
|
|
359
|
+
}
|
|
348
360
|
/**
|
|
349
|
-
*
|
|
361
|
+
* Supported OpenTelemetry environment configuration for Cloudflare OTLP export.
|
|
362
|
+
*
|
|
363
|
+
* This config intentionally uses the conventional `OTEL_*` variable names so
|
|
364
|
+
* deployments can share the same settings used by other OpenTelemetry SDKs.
|
|
365
|
+
* It covers the OTLP HTTP settings supported by the Effect OTLP layers:
|
|
366
|
+
*
|
|
367
|
+
* - `OTEL_EXPORTER_OTLP_ENDPOINT`
|
|
368
|
+
* - `OTEL_EXPORTER_OTLP_LOGS_ENDPOINT`
|
|
369
|
+
* - `OTEL_EXPORTER_OTLP_TRACES_ENDPOINT`
|
|
370
|
+
* - `OTEL_EXPORTER_OTLP_METRICS_ENDPOINT`
|
|
371
|
+
* - `OTEL_EXPORTER_OTLP_HEADERS`
|
|
372
|
+
* - `OTEL_EXPORTER_OTLP_LOGS_HEADERS`
|
|
373
|
+
* - `OTEL_EXPORTER_OTLP_TRACES_HEADERS`
|
|
374
|
+
* - `OTEL_EXPORTER_OTLP_METRICS_HEADERS`
|
|
375
|
+
* - `OTEL_SERVICE_NAME`
|
|
376
|
+
* - `OTEL_RESOURCE_ATTRIBUTES`
|
|
377
|
+
*
|
|
378
|
+
* `OTEL_SERVICE_VERSION` is also accepted as an effect-cf convenience alias.
|
|
379
|
+
* The standard OpenTelemetry way to configure service version is
|
|
380
|
+
* `OTEL_RESOURCE_ATTRIBUTES=service.version=...`.
|
|
381
|
+
*
|
|
382
|
+
* Consumers with non-standard binding names should map those names into
|
|
383
|
+
* {@link CloudflareOtlpSettings} rather than changing this config globally.
|
|
350
384
|
*/
|
|
351
|
-
declare const
|
|
385
|
+
declare const settingsConfig: Config.Config<{
|
|
386
|
+
endpoint: Option.Option<string>;
|
|
387
|
+
logsEndpoint: Option.Option<string>;
|
|
388
|
+
tracesEndpoint: Option.Option<string>;
|
|
389
|
+
metricsEndpoint: Option.Option<string>;
|
|
390
|
+
headers: Option.Option<string>;
|
|
391
|
+
logsHeaders: Option.Option<string>;
|
|
392
|
+
tracesHeaders: Option.Option<string>;
|
|
393
|
+
metricsHeaders: Option.Option<string>;
|
|
394
|
+
serviceName: Option.Option<string>;
|
|
395
|
+
serviceVersion: Option.Option<string>;
|
|
396
|
+
resourceAttributes: Option.Option<{
|
|
397
|
+
readonly [x: string]: string;
|
|
398
|
+
}>;
|
|
399
|
+
}>;
|
|
400
|
+
declare const CloudflareOtlpSettings_base: Context.ServiceClass<CloudflareOtlpSettings, "effect-cf/CloudflareOtlpSettings", Settings>;
|
|
352
401
|
/**
|
|
353
|
-
*
|
|
402
|
+
* Service carrying already-resolved Cloudflare OTLP settings.
|
|
403
|
+
*
|
|
404
|
+
* Provide this service directly when an application needs to map custom
|
|
405
|
+
* Cloudflare binding names, compute settings dynamically, or override settings
|
|
406
|
+
* in tests. When this service is present, the OTLP layers use it instead of
|
|
407
|
+
* reading {@link settingsConfig}.
|
|
408
|
+
*
|
|
409
|
+
* @example
|
|
410
|
+
* ```ts
|
|
411
|
+
* const CustomOtlpSettings = Layer.effect(
|
|
412
|
+
* CloudflareOtlp.CloudflareOtlpSettings,
|
|
413
|
+
* Config.all({
|
|
414
|
+
* ...CloudflareOtlp.settingsConfig,
|
|
415
|
+
* endpoint: Config.string("MY_OTLP_ENDPOINT").pipe(Config.option),
|
|
416
|
+
* }),
|
|
417
|
+
* ).pipe(Layer.provide(WorkerConfig.layer));
|
|
418
|
+
* ```
|
|
354
419
|
*/
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
420
|
+
declare class CloudflareOtlpSettings extends CloudflareOtlpSettings_base {}
|
|
421
|
+
/** Resource metadata shared by Worker and Durable Object OTLP layers. */
|
|
422
|
+
interface ResourceOptions {
|
|
423
|
+
/** Explicit service name. Overrides `OTEL_SERVICE_NAME` when provided. */
|
|
424
|
+
readonly serviceName?: string;
|
|
425
|
+
/** Explicit service version. Overrides `OTEL_SERVICE_VERSION` when provided. */
|
|
426
|
+
readonly serviceVersion?: string;
|
|
427
|
+
/** Additional resource attributes attached to all exported telemetry. */
|
|
428
|
+
readonly attributes?: Record<string, unknown>;
|
|
429
|
+
}
|
|
430
|
+
/** Resource metadata specific to Cloudflare Workers. */
|
|
431
|
+
interface WorkerResourceOptions extends ResourceOptions {
|
|
432
|
+
/** Cloudflare Worker name to attach as `cloudflare.worker.name`. */
|
|
433
|
+
readonly workerName?: string;
|
|
434
|
+
}
|
|
435
|
+
/** Resource metadata specific to Cloudflare Durable Objects. */
|
|
436
|
+
interface DurableObjectResourceOptions extends ResourceOptions {
|
|
437
|
+
/** Durable Object class name to attach as `cloudflare.durable_object.class`. */
|
|
438
|
+
readonly className?: string;
|
|
439
|
+
/**
|
|
440
|
+
* Include the Durable Object id as `cloudflare.durable_object.id`.
|
|
441
|
+
*
|
|
442
|
+
* This is disabled by default because object ids can be high-cardinality.
|
|
443
|
+
*/
|
|
444
|
+
readonly includeObjectId?: boolean;
|
|
445
|
+
}
|
|
446
|
+
/** Options shared by all Cloudflare OTLP telemetry layers. */
|
|
447
|
+
interface LayerOptions$12 extends ResourceOptions {
|
|
448
|
+
/** Telemetry signals to export. Defaults to logs, traces, and metrics. */
|
|
449
|
+
readonly signals?: ReadonlyArray<Signal>;
|
|
450
|
+
/** OTLP payload serialization. Defaults to protobuf. */
|
|
451
|
+
readonly serialization?: Serialization;
|
|
452
|
+
/** Maximum batch size for log and trace exporters. */
|
|
453
|
+
readonly maxBatchSize?: number;
|
|
454
|
+
/** Maximum time to wait for exporter shutdown/flush when a scope closes. */
|
|
455
|
+
readonly shutdownTimeout?: Duration$1.Input;
|
|
456
|
+
/** Export interval for the logs exporter. */
|
|
457
|
+
readonly loggerExportInterval?: Duration$1.Input;
|
|
458
|
+
/** Exclude log records emitted for spans when exporting logs. */
|
|
459
|
+
readonly loggerExcludeLogSpans?: boolean;
|
|
460
|
+
/** Merge the OTLP logger with existing loggers instead of replacing them. */
|
|
461
|
+
readonly loggerMergeWithExisting?: boolean;
|
|
462
|
+
/** Export interval for the traces exporter. */
|
|
463
|
+
readonly tracerExportInterval?: Duration$1.Input;
|
|
464
|
+
/** Custom trace context lookup used by the Effect OTLP tracer. */
|
|
465
|
+
readonly tracerContext?: <X>(primitive: Tracer.EffectPrimitive<X>, span: Tracer.AnySpan) => X;
|
|
466
|
+
/** Export interval for the metrics exporter. */
|
|
467
|
+
readonly metricsExportInterval?: Duration$1.Input;
|
|
468
|
+
/** Aggregation temporality for exported metrics. */
|
|
469
|
+
readonly metricsTemporality?: OtlpMetrics.AggregationTemporality;
|
|
365
470
|
}
|
|
366
|
-
declare const TypeId$1: "effect-cf/ServiceBinding";
|
|
367
471
|
/**
|
|
368
|
-
*
|
|
472
|
+
* Layer that reads standard OpenTelemetry settings from the current Cloudflare
|
|
473
|
+
* `env` object.
|
|
474
|
+
*
|
|
475
|
+
* The layer depends on {@link WorkerEnvironment} and installs a
|
|
476
|
+
* Cloudflare-backed Effect `ConfigProvider`, so `settingsConfig` reads from
|
|
477
|
+
* Worker vars/secrets instead of Node process environment variables.
|
|
369
478
|
*/
|
|
370
|
-
|
|
371
|
-
fetch(input: RequestInfo | URL, init?: RequestInit): Promise<Response>;
|
|
372
|
-
}
|
|
373
|
-
type RpcClient$1<Api> = { readonly [Key in keyof Api as Key extends string ? Api[Key] extends ((...args: Array<any>) => unknown) ? Key : never : never]: Api[Key] };
|
|
374
|
-
type ReservedMethodName$4 = ReservedMethodName$5 | "fetch";
|
|
479
|
+
declare const settingsLayer: Layer.Layer<CloudflareOtlpSettings, Config.ConfigError, WorkerEnvironment>;
|
|
375
480
|
/**
|
|
376
|
-
*
|
|
481
|
+
* Base OTLP telemetry layer for Cloudflare-compatible runtimes.
|
|
482
|
+
*
|
|
483
|
+
* The layer reads {@link CloudflareOtlpSettings} when provided. Otherwise it
|
|
484
|
+
* reads standard OpenTelemetry config from `WorkerEnvironment` when available,
|
|
485
|
+
* then falls back to the ambient Effect `ConfigProvider`.
|
|
486
|
+
*
|
|
487
|
+
* When only `OTEL_EXPORTER_OTLP_ENDPOINT` is configured, per-signal paths are
|
|
488
|
+
* derived by appending `/v1/logs`, `/v1/traces`, and `/v1/metrics`. Signal
|
|
489
|
+
* specific endpoints are used as-is, matching the OpenTelemetry OTLP exporter
|
|
490
|
+
* convention.
|
|
377
491
|
*/
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
492
|
+
declare const layer$9: (options?: LayerOptions$12) => Layer.Layer<never, never, never>;
|
|
493
|
+
/** Base OTLP telemetry layer forced to JSON serialization. */
|
|
494
|
+
declare const layerJson: (options?: Omit<LayerOptions$12, "serialization">) => Layer.Layer<never, never, never>;
|
|
495
|
+
/** Base OTLP telemetry layer forced to protobuf serialization. */
|
|
496
|
+
declare const layerProtobuf: (options?: Omit<LayerOptions$12, "serialization">) => Layer.Layer<never, never, never>;
|
|
497
|
+
/**
|
|
498
|
+
* OTLP layer with Cloudflare Worker resource attributes.
|
|
499
|
+
*
|
|
500
|
+
* Provide this layer at runtime scope for long-lived metrics aggregation, or at
|
|
501
|
+
* handler scope when traces/logs should flush as the Cloudflare event finishes.
|
|
502
|
+
*/
|
|
503
|
+
declare const workerLayer: (options?: LayerOptions$12 & WorkerResourceOptions) => Layer.Layer<never, never, never>;
|
|
381
504
|
/**
|
|
382
|
-
*
|
|
505
|
+
* OTLP layer with Cloudflare Durable Object resource attributes.
|
|
506
|
+
*
|
|
507
|
+
* The layer reads {@link DurableObjectState} so it can optionally include the
|
|
508
|
+
* Durable Object id. Prefer leaving `includeObjectId` disabled unless the
|
|
509
|
+
* backend can tolerate high-cardinality resource attributes.
|
|
383
510
|
*/
|
|
384
|
-
|
|
511
|
+
declare const durableObjectLayer: (options?: LayerOptions$12 & DurableObjectResourceOptions) => Layer.Layer<never, never, DurableObjectState>;
|
|
512
|
+
declare namespace D1_d_exports {
|
|
513
|
+
export { D1Definition, D1Service, D1SqlLayerOptions, Service$1 as Service, make$10 as make };
|
|
514
|
+
}
|
|
515
|
+
/** Typed D1 binding definition. */
|
|
516
|
+
interface D1Definition {
|
|
385
517
|
/** Binding name as configured in `wrangler.jsonc`. */
|
|
386
518
|
readonly binding: string;
|
|
387
|
-
/** Optional RPC schema used for argument/result encoding. */
|
|
388
|
-
readonly definition?: Definition;
|
|
389
519
|
}
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
/**
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
}> {}
|
|
400
|
-
declare const ServiceBindingRpcError_base: new <A extends Record<string, any> = {}>(args: _$effect_Types0.VoidIfEmpty<{ readonly [P in keyof A as P extends "_tag" ? never : P]: A[P] }>) => _$effect_Cause0.YieldableError & {
|
|
401
|
-
readonly _tag: "ServiceBindingRpcError";
|
|
402
|
-
} & Readonly<A>;
|
|
520
|
+
/** Options forwarded to `@effect/sql-d1` when building a SQL client layer. */
|
|
521
|
+
type D1SqlLayerOptions = Omit<D1Client.D1ClientConfig, "db">;
|
|
522
|
+
declare const D1ServiceTypeId: unique symbol;
|
|
523
|
+
/** Nominal service marker for D1 services created with {@link make}. */
|
|
524
|
+
interface D1Service<Id extends string> {
|
|
525
|
+
readonly [D1ServiceTypeId]: {
|
|
526
|
+
readonly id: Id;
|
|
527
|
+
};
|
|
528
|
+
}
|
|
403
529
|
/**
|
|
404
|
-
*
|
|
530
|
+
* Creates a typed D1 service tag plus Effect helpers.
|
|
405
531
|
*/
|
|
406
|
-
declare
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
}> {}
|
|
411
|
-
type ServiceMethodKey<Api> = AsyncMethodKey<Api>;
|
|
412
|
-
type ServiceMethodArgs<Api, Method extends keyof Api> = AsyncMethodArgs<Api, Method>;
|
|
413
|
-
type ServiceMethodSuccess<Api, Method extends keyof Api> = AsyncMethodSuccess<Api, Method>;
|
|
414
|
-
type ServiceMethodCloudflareReturn<Api, Method extends keyof Api> = AsyncMethodCloudflareReturn<Api, Method>;
|
|
415
|
-
type ServiceCall<R, Api> = <Method extends ServiceMethodKey<Api>>(method: Method, ...args: ServiceMethodArgs<Api, Method>) => Effect.Effect<ServiceMethodSuccess<Api, Method>, ServiceBindingRpcError, R>;
|
|
416
|
-
type DefinitionDirectMethods<R, Definition extends Definition$6.Any> = { readonly [Method in Definition$9.MethodNames<Definition>]: (...args: Method$5.Args<Definition["methods"][Method]>) => Effect.Effect<Method$5.Success<Definition["methods"][Method]>, ServiceBindingRpcError, R> };
|
|
417
|
-
type DirectMethods$1<R, Definition> = Definition extends Definition$6.Any ? DefinitionDirectMethods<R, Definition> : {};
|
|
418
|
-
type ServiceBindingEffectClient<Api extends object, Definition extends Definition$6.Any | undefined = undefined> = DirectMethods$1<never, Definition> & {
|
|
419
|
-
/**
|
|
420
|
-
* Forwards an HTTP request to the bound Worker service.
|
|
421
|
-
*
|
|
422
|
-
* Use this when the service binding is acting as an HTTP origin rather than a
|
|
423
|
-
* Cloudflare RPC target.
|
|
424
|
-
*
|
|
425
|
-
* @example
|
|
426
|
-
* ```ts
|
|
427
|
-
* import { Effect } from "effect";
|
|
428
|
-
*
|
|
429
|
-
* const program = Effect.gen(function* () {
|
|
430
|
-
* const api = yield* ApiWorker;
|
|
431
|
-
* return yield* api.fetch(new Request("https://internal.example/users"));
|
|
432
|
-
* });
|
|
433
|
-
* ```
|
|
434
|
-
*/
|
|
435
|
-
readonly fetch: (input: RequestInfo | URL, init?: RequestInit) => Effect.Effect<globalThis.Response, ServiceBindingFetchError>;
|
|
436
|
-
/**
|
|
437
|
-
* Invokes a Worker RPC method and returns Cloudflare's raw RPC result.
|
|
438
|
-
*
|
|
439
|
-
* This preserves Cloudflare RPC behavior such as promise-like pipelining and
|
|
440
|
-
* transferable / disposable result objects. It does not resolve the returned
|
|
441
|
-
* promise-like value and it does not decode definition-backed success schemas.
|
|
442
|
-
*
|
|
443
|
-
* Most application code should use {@link call} instead.
|
|
444
|
-
*
|
|
445
|
-
* @example
|
|
446
|
-
* ```ts
|
|
447
|
-
* import { Effect } from "effect";
|
|
448
|
-
*
|
|
449
|
-
* const program = Effect.gen(function* () {
|
|
450
|
-
* const counter = yield* CounterService;
|
|
451
|
-
*
|
|
452
|
-
* const result = yield* counter.rpc("increment", 41);
|
|
453
|
-
* const value = yield* Effect.promise(() => result);
|
|
454
|
-
*
|
|
455
|
-
* return value;
|
|
456
|
-
* });
|
|
457
|
-
* ```
|
|
458
|
-
*/
|
|
459
|
-
readonly rpc: <Method extends ServiceMethodKey<Api>>(method: Method, ...args: ServiceMethodArgs<Api, Method>) => Effect.Effect<ServiceMethodCloudflareReturn<Api, Method>, ServiceBindingRpcError>;
|
|
460
|
-
/**
|
|
461
|
-
* Invokes a Worker RPC method, resolves Cloudflare's RPC result, and decodes
|
|
462
|
-
* the success value when the binding was created from a definition.
|
|
463
|
-
*
|
|
464
|
-
* This is the normal choice when application code wants the final typed value.
|
|
465
|
-
*
|
|
466
|
-
* @example
|
|
467
|
-
* ```ts
|
|
468
|
-
* import { Effect } from "effect";
|
|
469
|
-
*
|
|
470
|
-
* const program = Effect.gen(function* () {
|
|
471
|
-
* const counter = yield* CounterService;
|
|
472
|
-
* const value = yield* counter.call("increment", 41);
|
|
473
|
-
*
|
|
474
|
-
* return value;
|
|
475
|
-
* });
|
|
476
|
-
* ```
|
|
477
|
-
*/
|
|
478
|
-
readonly call: <Method extends ServiceMethodKey<Api>>(method: Method, ...args: ServiceMethodArgs<Api, Method>) => Effect.Effect<ServiceMethodSuccess<Api, Method>, ServiceBindingRpcError>;
|
|
479
|
-
/**
|
|
480
|
-
* Invokes a Worker RPC method in the current `Scope`, resolves Cloudflare's RPC
|
|
481
|
-
* result, decodes definition-backed success values, and disposes the resolved
|
|
482
|
-
* result when the scope closes if it implements `Symbol.dispose`.
|
|
483
|
-
*
|
|
484
|
-
* Use this for RPC methods that return Cloudflare RPC resources or other
|
|
485
|
-
* disposable objects whose lifetime should be tied to an Effect scope.
|
|
486
|
-
*
|
|
487
|
-
* @example
|
|
488
|
-
* ```ts
|
|
489
|
-
* import { Effect } from "effect";
|
|
490
|
-
*
|
|
491
|
-
* const program = Effect.scoped(
|
|
492
|
-
* Effect.gen(function* () {
|
|
493
|
-
* const files = yield* FileService;
|
|
494
|
-
* const handle = yield* files.scopedCall("open", "report.csv");
|
|
495
|
-
*
|
|
496
|
-
* return yield* handle.read();
|
|
497
|
-
* }),
|
|
498
|
-
* );
|
|
499
|
-
* ```
|
|
500
|
-
*/
|
|
501
|
-
readonly scopedCall: <Method extends ServiceMethodKey<Api>>(method: Method, ...args: ServiceMethodArgs<Api, Method>) => Effect.Effect<Awaited<ServiceMethodSuccess<Api, Method>>, unknown, Scope.Scope>;
|
|
502
|
-
};
|
|
503
|
-
type ServiceBindingStaticClient<R, Api extends object, Definition extends Definition$6.Any | undefined = undefined> = DirectMethods$1<R, Definition> & {
|
|
504
|
-
readonly fetch: (input: RequestInfo | URL, init?: RequestInit) => Effect.Effect<globalThis.Response, ServiceBindingFetchError, R>;
|
|
505
|
-
readonly rpc: <Method extends ServiceMethodKey<Api>>(method: Method, ...args: ServiceMethodArgs<Api, Method>) => Effect.Effect<ServiceMethodCloudflareReturn<Api, Method>, ServiceBindingRpcError, R>;
|
|
506
|
-
readonly call: <Method extends ServiceMethodKey<Api>>(method: Method, ...args: ServiceMethodArgs<Api, Method>) => Effect.Effect<ServiceMethodSuccess<Api, Method>, ServiceBindingRpcError, R>;
|
|
507
|
-
readonly scopedCall: <Method extends ServiceMethodKey<Api>>(method: Method, ...args: ServiceMethodArgs<Api, Method>) => Effect.Effect<Awaited<ServiceMethodSuccess<Api, Method>>, unknown, Scope.Scope | R>;
|
|
532
|
+
declare const make$10: <Id extends string>(id: Id, definition: D1Definition) => BindingService<D1Service<Id>, Id, D1Database> & {
|
|
533
|
+
"effect-cf/D1": "effect-cf/D1";
|
|
534
|
+
definition: D1Definition;
|
|
535
|
+
sqlLayer: (options?: D1SqlLayerOptions) => Layer.Layer<D1Client.D1Client | _$effect_unstable_sql_SqlClient0.SqlClient, BindingNotFoundError | BindingValidationError | _$effect_Config0.ConfigError, WorkerEnvironment>;
|
|
508
536
|
};
|
|
509
|
-
declare const isServiceBindingClient: <Api extends object>(value: unknown) => value is ServiceBindingClient<Api>;
|
|
510
|
-
declare const makeClient$5: <Api extends object, const Definition extends Definition$6.Any | undefined = undefined>(definition: ServiceBindingDefinition<Definition>) => ((service: ServiceBindingClient<Api>) => ServiceBindingEffectClient<Api, Definition>);
|
|
511
|
-
declare const layer$8: <Self, Api extends object, const Definition extends Definition$6.Any | undefined = undefined>(tag: Context.Service<Self, ServiceBindingEffectClient<Api, Definition>>, definition: ServiceBindingDefinition<Definition>) => _$effect_Layer0.Layer<Self, BindingNotFoundError | BindingValidationError, WorkerEnvironment>;
|
|
512
537
|
/**
|
|
513
|
-
*
|
|
538
|
+
* Builds a D1 service around a Cloudflare D1 database binding.
|
|
514
539
|
*
|
|
515
|
-
*
|
|
516
|
-
*
|
|
517
|
-
* - `fetch(...)` for raw HTTP forwarding
|
|
518
|
-
* - `rpc(...)` for raw Cloudflare RPC results
|
|
519
|
-
* - `call(...)` for resolved and decoded RPC results
|
|
520
|
-
* - `scopedCall(...)` for scoped and decoded disposable RPC results
|
|
521
|
-
* - direct RPC methods when `definition` is provided
|
|
540
|
+
* The returned service exposes the raw `D1Database` binding and `sqlLayer(...)`
|
|
541
|
+
* for providing `effect/unstable/sql` via `@effect/sql-d1`.
|
|
522
542
|
*
|
|
523
543
|
* @example
|
|
524
544
|
* ```ts
|
|
525
|
-
*
|
|
526
|
-
*
|
|
527
|
-
*
|
|
528
|
-
* success: Schema.Number,
|
|
529
|
-
* }),
|
|
530
|
-
* });
|
|
531
|
-
*
|
|
532
|
-
* const CounterLive = Counter.layer({ binding: "COUNTER" });
|
|
545
|
+
* class TodoDatabase extends D1.Service<TodoDatabase>()("TodoDatabase", {
|
|
546
|
+
* binding: "TODO_DB",
|
|
547
|
+
* }) {}
|
|
533
548
|
*
|
|
534
|
-
* const
|
|
535
|
-
* const counter = yield* Counter;
|
|
536
|
-
* const next = yield* counter.increment(1);
|
|
537
|
-
* return next;
|
|
538
|
-
* });
|
|
549
|
+
* const SqlLive = TodoDatabase.sqlLayer();
|
|
539
550
|
* ```
|
|
540
551
|
*/
|
|
541
|
-
declare const Service$1: <Self
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
readonly rpc: <Method extends ServiceMethodKey<ApiOrDefinition<Api, Definition>>>(method: Method, ...args: ServiceMethodArgs<ApiOrDefinition<Api, Definition>, Method>) => Effect.Effect<Result<AsyncMethodSuccess<ApiOrDefinition<Api, Definition>, Method>>, ServiceBindingRpcError, Self>;
|
|
546
|
-
readonly call: <Method extends ServiceMethodKey<ApiOrDefinition<Api, Definition>>>(method: Method, ...args: ServiceMethodArgs<ApiOrDefinition<Api, Definition>, Method>) => Effect.Effect<AsyncMethodSuccess<ApiOrDefinition<Api, Definition>, Method>, ServiceBindingRpcError, Self>;
|
|
547
|
-
readonly scopedCall: <Method extends ServiceMethodKey<ApiOrDefinition<Api, Definition>>>(method: Method, ...args: ServiceMethodArgs<ApiOrDefinition<Api, Definition>, Method>) => Effect.Effect<Awaited<AsyncMethodSuccess<ApiOrDefinition<Api, Definition>, Method>>, unknown, Self | Scope.Scope>;
|
|
552
|
+
declare const Service$1: <Self>() => <Id extends string>(id: Id, definition: D1Definition) => BindingService<Self, Id, D1Database> & {
|
|
553
|
+
"effect-cf/D1": "effect-cf/D1";
|
|
554
|
+
definition: D1Definition;
|
|
555
|
+
sqlLayer: (options?: D1SqlLayerOptions) => Layer.Layer<D1Client.D1Client | _$effect_unstable_sql_SqlClient0.SqlClient, BindingNotFoundError | BindingValidationError | _$effect_Config0.ConfigError, WorkerEnvironment | Exclude<Exclude<Self, _$effect_Scope0.Scope>, Self>>;
|
|
548
556
|
};
|
|
549
|
-
declare
|
|
550
|
-
|
|
551
|
-
export { Api$2 as Api, Definition$5 as Definition, ExecutionContext, FetchHandler, FetchWorkerOptions, HandlerEffect$2 as HandlerEffect, Handlers$2 as Handlers, LayerOptions$9 as LayerOptions, Method$3 as Method, Methods$2 as Methods, NativeRequest, NoReservedMethods$2 as NoReservedMethods, Options$4 as Options, ReservedMethodName$3 as ReservedMethodName, RpcHandlers$1 as RpcHandlers, ServerApi$3 as ServerApi, ServiceFreeSchema$2 as ServiceFreeSchema, Tag$8 as Tag, TagClass$7 as TagClass, TagFactory$1 as TagFactory, WorkerClass, WorkerContext, WorkerContextService, WorkerContextWaitUntilOptions, WorkerFetchSuccess, WorkerHandler, WorkerOptions, WorkerRpc, WorkerRpcHandler, WorkerRpcShape, implement$4 as implement, isWebSocketUpgrade, make$7 as make, makeFetchHandler, method$2 as method, renderHttpResponse };
|
|
552
|
-
}
|
|
553
|
-
declare const ExecutionContext_base: Context.ServiceClass<ExecutionContext, "effect-cf/ExecutionContext", globalThis.ExecutionContext<unknown>>;
|
|
554
|
-
declare class ExecutionContext extends ExecutionContext_base {}
|
|
555
|
-
interface WorkerContextWaitUntilOptions<E, R> {
|
|
556
|
-
readonly mode?: "observe" | "propagate";
|
|
557
|
-
readonly onFailure?: (cause: Cause.Cause<E>) => Effect.Effect<void, never, R>;
|
|
558
|
-
}
|
|
559
|
-
interface WorkerContextService {
|
|
560
|
-
readonly raw: globalThis.ExecutionContext;
|
|
561
|
-
waitUntil<A, E, R, R2 = never>(effect: Effect.Effect<A, E, R>, options?: WorkerContextWaitUntilOptions<E, R2>): Effect.Effect<void, never, R | R2>;
|
|
562
|
-
waitUntilPropagating<A, E, R, R2 = never>(effect: Effect.Effect<A, E, R>, options?: Omit<WorkerContextWaitUntilOptions<E, R2>, "mode">): Effect.Effect<void, never, R | R2>;
|
|
563
|
-
readonly passThroughOnException: Effect.Effect<void>;
|
|
564
|
-
}
|
|
565
|
-
declare const WorkerContext_base: Context.ServiceClass<WorkerContext, "effect-cf/WorkerContext", WorkerContextService>;
|
|
566
|
-
declare class WorkerContext extends WorkerContext_base {}
|
|
567
|
-
declare const NativeRequest_base: Context.ServiceClass<NativeRequest, "effect-cf/NativeRequest", Request<unknown, CfProperties<unknown>>>;
|
|
568
|
-
declare class NativeRequest extends NativeRequest_base {}
|
|
569
|
-
declare const isWebSocketUpgrade: (request: Request) => boolean;
|
|
570
|
-
type ReservedMethodName$3 = ReservedMethodName$6 | "fetch" | "connect" | "queue" | "scheduled" | "tail" | "tailStream" | "test" | "trace" | "alarm" | "webSocketMessage" | "webSocketClose" | "webSocketError";
|
|
571
|
-
type WorkerBaseContext<ROut> = ExecutionContext | WorkerContext | WorkerEnvironment | ROut;
|
|
572
|
-
type WorkerFetchContext<ROut> = WorkerBaseContext<ROut> | NativeRequest | HttpServerRequest.HttpServerRequest | Scope.Scope;
|
|
573
|
-
type WorkerRpcContext<ROut> = WorkerBaseContext<ROut> | Scope.Scope;
|
|
574
|
-
type WorkerFetchSuccess = Response | HttpServerResponse.HttpServerResponse;
|
|
575
|
-
type WorkerHandler<ROut, A = WorkerFetchSuccess> = Effect.Effect<A, unknown, WorkerFetchContext<ROut>>;
|
|
576
|
-
type WorkerRpcHandler<ROut, A = unknown> = Effect.Effect<A, unknown, WorkerRpcContext<ROut>>;
|
|
577
|
-
type WorkerRpc<ROut> = Record<string, (...args: Array<any>) => WorkerRpcHandler<ROut>>;
|
|
578
|
-
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 };
|
|
579
|
-
type RpcHandlers$1<ROut, Api> = { readonly [Key in keyof Api as Key extends keyof WorkerEntrypoint ? never : Key extends string ? Key extends ReservedMethodName$3 ? 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 };
|
|
580
|
-
interface WorkerOptions<ROut, Rpc extends WorkerRpc<ROut>> {
|
|
581
|
-
readonly fetch?: Effect.Effect<WorkerFetchSuccess, unknown, WorkerFetchContext<ROut>>;
|
|
582
|
-
readonly queue?: QueueHandler<ROut>;
|
|
583
|
-
readonly rpc?: Rpc;
|
|
557
|
+
declare namespace Rpc_d_exports {
|
|
558
|
+
export { DisposableValue, MethodArgs, MethodKey, MethodReturn, Provider, Result, RpcStub, RpcTarget, Serializable, Stub, Stubable, Stubify, dispose, isDisposable, resolve, scoped };
|
|
584
559
|
}
|
|
585
|
-
type
|
|
586
|
-
|
|
560
|
+
type Stubable = Rpc.Stubable;
|
|
561
|
+
type Stub<T extends Stubable> = Rpc.Stub<T>;
|
|
562
|
+
type Provider<T extends object, Reserved extends string = never> = Rpc.Provider<T, Reserved>;
|
|
563
|
+
type BaseType = void | undefined | null | boolean | number | bigint | string | TypedArray | ArrayBuffer | DataView | Date | Error | RegExp | ReadableStream<Uint8Array> | WritableStream<Uint8Array> | Request | Response | Headers;
|
|
564
|
+
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;
|
|
565
|
+
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 {
|
|
566
|
+
[key: string | number]: unknown;
|
|
567
|
+
} ? { [Key in keyof T]: Stubify<T[Key]> } : T;
|
|
568
|
+
type MaybeProvider<T> = T extends object ? Provider<T> : unknown;
|
|
569
|
+
type MaybeDisposable<T> = T extends object ? Disposable : unknown;
|
|
570
|
+
type Result<T> = T extends Stubable ? Promise<Stub<T>> & Provider<T> : T extends Serializable<T> ? Promise<Stubify<T> & MaybeDisposable<T>> & MaybeProvider<T> : never;
|
|
571
|
+
type MethodKey<Api> = { [Key in keyof Api]-?: Key extends string ? Api[Key] extends ((...args: Array<any>) => unknown) ? Key : never : never }[keyof Api];
|
|
572
|
+
type MethodArgs<Api, Method extends keyof Api> = Api[Method] extends ((...args: infer Args) => unknown) ? Args : never;
|
|
573
|
+
type MethodReturn<Api, Method extends keyof Api> = Api[Method] extends ((...args: Array<any>) => infer Return) ? Return : never;
|
|
574
|
+
type DisposableValue = {
|
|
575
|
+
[Symbol.dispose](): void;
|
|
587
576
|
};
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
577
|
+
declare const isDisposable: (value: unknown) => value is DisposableValue;
|
|
578
|
+
declare const dispose: (value: unknown) => Effect.Effect<void>;
|
|
579
|
+
declare const resolve: <A>(value: A) => Effect.Effect<Awaited<A>, unknown>;
|
|
580
|
+
declare const scoped: <A>(value: A) => Effect.Effect<Awaited<A>, unknown, Scope.Scope>;
|
|
581
|
+
declare namespace RpcDefinition_d_exports {
|
|
582
|
+
export { Definition$9 as Definition, Method$5 as Method, Methods$4 as Methods, NoReservedMethods$4 as NoReservedMethods, ReservedMethodName$6 as ReservedMethodName, ReservedMethodNameError, RpcArgumentCountError, RpcArgumentDecodeError, RpcArgumentEncodeError, RpcReservedMethodNameError, RpcSuccessDecodeError, RpcSuccessEncodeError, ServiceFreeSchema$4 as ServiceFreeSchema, assertNoReservedMethodNames, assertNoReservedMethods, decodeArgs, decodeSuccess, encodeArgs, encodeSuccess, make$9 as make, method$4 as method, reservedMethodNames };
|
|
594
583
|
}
|
|
595
|
-
declare const
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
declare
|
|
599
|
-
|
|
600
|
-
|
|
584
|
+
declare const RpcReservedMethodNameError_base: new <A extends Record<string, any> = {}>(args: _$effect_Types0.VoidIfEmpty<{ readonly [P in keyof A as P extends "_tag" ? never : P]: A[P] }>) => _$effect_Cause0.YieldableError & {
|
|
585
|
+
readonly _tag: "RpcReservedMethodNameError";
|
|
586
|
+
} & Readonly<A>;
|
|
587
|
+
declare class RpcReservedMethodNameError extends RpcReservedMethodNameError_base<{
|
|
588
|
+
readonly definition: string;
|
|
589
|
+
readonly method: string;
|
|
590
|
+
}> {}
|
|
591
|
+
declare const RpcArgumentCountError_base: new <A extends Record<string, any> = {}>(args: _$effect_Types0.VoidIfEmpty<{ readonly [P in keyof A as P extends "_tag" ? never : P]: A[P] }>) => _$effect_Cause0.YieldableError & {
|
|
592
|
+
readonly _tag: "RpcArgumentCountError";
|
|
593
|
+
} & Readonly<A>;
|
|
594
|
+
declare class RpcArgumentCountError extends RpcArgumentCountError_base<{
|
|
595
|
+
readonly definition: string;
|
|
596
|
+
readonly method: string;
|
|
597
|
+
readonly expected: number;
|
|
598
|
+
readonly actual: number;
|
|
599
|
+
}> {}
|
|
600
|
+
declare const RpcArgumentDecodeError_base: new <A extends Record<string, any> = {}>(args: _$effect_Types0.VoidIfEmpty<{ readonly [P in keyof A as P extends "_tag" ? never : P]: A[P] }>) => _$effect_Cause0.YieldableError & {
|
|
601
|
+
readonly _tag: "RpcArgumentDecodeError";
|
|
602
|
+
} & Readonly<A>;
|
|
603
|
+
declare class RpcArgumentDecodeError extends RpcArgumentDecodeError_base<{
|
|
604
|
+
readonly definition: string;
|
|
605
|
+
readonly method: string;
|
|
606
|
+
readonly index: number;
|
|
607
|
+
readonly cause: unknown;
|
|
608
|
+
}> {}
|
|
609
|
+
declare const RpcArgumentEncodeError_base: new <A extends Record<string, any> = {}>(args: _$effect_Types0.VoidIfEmpty<{ readonly [P in keyof A as P extends "_tag" ? never : P]: A[P] }>) => _$effect_Cause0.YieldableError & {
|
|
610
|
+
readonly _tag: "RpcArgumentEncodeError";
|
|
611
|
+
} & Readonly<A>;
|
|
612
|
+
declare class RpcArgumentEncodeError extends RpcArgumentEncodeError_base<{
|
|
613
|
+
readonly definition: string;
|
|
614
|
+
readonly method: string;
|
|
615
|
+
readonly index: number;
|
|
616
|
+
readonly cause: unknown;
|
|
617
|
+
}> {}
|
|
618
|
+
declare const RpcSuccessDecodeError_base: new <A extends Record<string, any> = {}>(args: _$effect_Types0.VoidIfEmpty<{ readonly [P in keyof A as P extends "_tag" ? never : P]: A[P] }>) => _$effect_Cause0.YieldableError & {
|
|
619
|
+
readonly _tag: "RpcSuccessDecodeError";
|
|
620
|
+
} & Readonly<A>;
|
|
621
|
+
declare class RpcSuccessDecodeError extends RpcSuccessDecodeError_base<{
|
|
622
|
+
readonly definition: string;
|
|
623
|
+
readonly method: string;
|
|
624
|
+
readonly cause: unknown;
|
|
625
|
+
}> {}
|
|
626
|
+
declare const RpcSuccessEncodeError_base: new <A extends Record<string, any> = {}>(args: _$effect_Types0.VoidIfEmpty<{ readonly [P in keyof A as P extends "_tag" ? never : P]: A[P] }>) => _$effect_Cause0.YieldableError & {
|
|
627
|
+
readonly _tag: "RpcSuccessEncodeError";
|
|
628
|
+
} & Readonly<A>;
|
|
629
|
+
declare class RpcSuccessEncodeError extends RpcSuccessEncodeError_base<{
|
|
630
|
+
readonly definition: string;
|
|
631
|
+
readonly method: string;
|
|
632
|
+
readonly cause: unknown;
|
|
633
|
+
}> {}
|
|
634
|
+
declare const reservedMethodNames: Set<string>;
|
|
635
|
+
type ReservedMethodName$6 = "constructor" | "fetch" | "connect" | "alarm" | "webSocketMessage" | "webSocketClose" | "webSocketError" | "then" | "dup" | "dispose" | "serialize" | "deserialize";
|
|
636
|
+
type ServiceFreeSchema$4 = Schema.Codec<any, any, never, never>;
|
|
637
|
+
interface Method$5<Args extends ReadonlyArray<ServiceFreeSchema$4> = ReadonlyArray<ServiceFreeSchema$4>, Success extends ServiceFreeSchema$4 = ServiceFreeSchema$4> {
|
|
601
638
|
readonly args: Args;
|
|
602
639
|
readonly success: Success;
|
|
603
640
|
}
|
|
604
|
-
declare namespace Method$
|
|
605
|
-
export type Any = Method$
|
|
606
|
-
type ArgsFromSchemas<Args extends ReadonlyArray<ServiceFreeSchema$
|
|
641
|
+
declare namespace Method$5 {
|
|
642
|
+
export type Any = Method$5<ReadonlyArray<ServiceFreeSchema$4>, ServiceFreeSchema$4>;
|
|
643
|
+
type ArgsFromSchemas<Args extends ReadonlyArray<ServiceFreeSchema$4>> = Args extends readonly [] ? [] : Args extends readonly [infer Head extends ServiceFreeSchema$4, ...infer Tail extends ReadonlyArray<ServiceFreeSchema$4>] ? [Schema.Schema.Type<Head>, ...ArgsFromSchemas<Tail>] : Array<Schema.Schema.Type<Args[number]>>;
|
|
644
|
+
type EncodedArgsFromSchemas<Args extends ReadonlyArray<ServiceFreeSchema$4>> = Args extends readonly [] ? [] : Args extends readonly [infer Head extends ServiceFreeSchema$4, ...infer Tail extends ReadonlyArray<ServiceFreeSchema$4>] ? [Schema.Codec.Encoded<Head>, ...EncodedArgsFromSchemas<Tail>] : Array<Schema.Codec.Encoded<Args[number]>>;
|
|
607
645
|
export type Args<Self extends Any> = ArgsFromSchemas<Self["args"]>;
|
|
646
|
+
export type EncodedArgs<Self extends Any> = EncodedArgsFromSchemas<Self["args"]>;
|
|
608
647
|
export type Success<Self extends Any> = Schema.Schema.Type<Self["success"]>;
|
|
648
|
+
export type EncodedSuccess<Self extends Any> = Schema.Codec.Encoded<Self["success"]>;
|
|
609
649
|
export {};
|
|
610
650
|
}
|
|
611
|
-
type Methods$
|
|
612
|
-
type NoReservedMethods$
|
|
613
|
-
interface Definition$
|
|
651
|
+
type Methods$4 = Record<string, Method$5.Any>;
|
|
652
|
+
type NoReservedMethods$4<MethodsShape extends Methods$4, Reserved extends string = ReservedMethodName$6> = Extract<keyof MethodsShape, Reserved> extends never ? MethodsShape : never;
|
|
653
|
+
interface Definition$9<Id extends string = string, MethodsShape extends Methods$4 = Methods$4> {
|
|
614
654
|
readonly id: Id;
|
|
615
655
|
readonly methods: MethodsShape;
|
|
616
656
|
}
|
|
617
|
-
declare namespace Definition$
|
|
618
|
-
type Any = Definition$
|
|
657
|
+
declare namespace Definition$9 {
|
|
658
|
+
type Any = Definition$9<string, Methods$4>;
|
|
659
|
+
type ServerApi<Self extends Any> = { readonly [Key in keyof Self["methods"]]: (...args: Method$5.Args<Self["methods"][Key]>) => Promise<Method$5.Success<Self["methods"][Key]>> };
|
|
660
|
+
type Api<Self extends Any, Reserved extends string = never> = Provider<ServerApi<Self>, Reserved>;
|
|
661
|
+
type MethodNames<Self extends Any> = Extract<keyof Self["methods"], string>;
|
|
619
662
|
}
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
readonly rpc: Handlers$2<ROut, Self>;
|
|
663
|
+
declare class ReservedMethodNameError extends Error {
|
|
664
|
+
readonly method: string;
|
|
665
|
+
readonly target: string;
|
|
666
|
+
constructor(target: string, method: string);
|
|
625
667
|
}
|
|
626
|
-
|
|
627
|
-
|
|
668
|
+
declare const assertNoReservedMethods: (target: string, methods: Record<string, unknown>, reserved: ReadonlySet<string>) => void;
|
|
669
|
+
declare function method$4<Success extends ServiceFreeSchema$4>(definition: {
|
|
670
|
+
readonly success: Success;
|
|
671
|
+
}): Method$5<readonly [], Success>;
|
|
672
|
+
declare function method$4<const Args extends ReadonlyArray<ServiceFreeSchema$4>, Success extends ServiceFreeSchema$4>(definition: {
|
|
673
|
+
readonly args: Args;
|
|
674
|
+
readonly success: Success;
|
|
675
|
+
}): Method$5<Args, Success>;
|
|
676
|
+
declare const assertNoReservedMethodNames: (definition: Definition$9.Any) => Effect.Effect<void, RpcReservedMethodNameError>;
|
|
677
|
+
declare const decodeArgs: <const Self extends Definition$9.Any, MethodName extends Definition$9.MethodNames<Self>>(definition: Self, methodName: MethodName, args: ReadonlyArray<unknown>) => Effect.Effect<Method$5.Args<Self["methods"][MethodName]>, RpcArgumentCountError | RpcArgumentDecodeError>;
|
|
678
|
+
declare const encodeArgs: <const Self extends Definition$9.Any, MethodName extends Definition$9.MethodNames<Self>>(definition: Self, methodName: MethodName, args: Method$5.Args<Self["methods"][MethodName]>) => Effect.Effect<Method$5.EncodedArgs<Self["methods"][MethodName]>, RpcArgumentCountError | RpcArgumentEncodeError>;
|
|
679
|
+
declare const encodeSuccess: <const Self extends Definition$9.Any, MethodName extends Definition$9.MethodNames<Self>>(definition: Self, methodName: MethodName, value: Method$5.Success<Self["methods"][MethodName]>) => Effect.Effect<Method$5.EncodedSuccess<Self["methods"][MethodName]>, RpcSuccessEncodeError>;
|
|
680
|
+
declare const decodeSuccess: <const Self extends Definition$9.Any, MethodName extends Definition$9.MethodNames<Self>>(definition: Self, methodName: MethodName, value: unknown) => Effect.Effect<Method$5.Success<Self["methods"][MethodName]>, RpcSuccessDecodeError>;
|
|
681
|
+
declare const make$9: <Id extends string, const MethodsShape extends Methods$4>(id: Id, methods: MethodsShape) => Definition$9<Id, MethodsShape>;
|
|
682
|
+
declare namespace QueueBinding_d_exports {
|
|
683
|
+
export { MessageSendRequest, QueueBindingClient, QueueBindingDefinition, QueueMetrics, QueueOperationError, QueueProducer, QueueSendBatchOptions, QueueSendBatchResponse, QueueSendOptions, QueueSendResponse, isQueue, layer$8 as layer, makeClient$6 as makeClient };
|
|
684
|
+
}
|
|
685
|
+
type QueueSendOptions = globalThis.QueueSendOptions;
|
|
686
|
+
type QueueSendResponse = globalThis.QueueSendResponse;
|
|
687
|
+
type QueueSendBatchOptions = globalThis.QueueSendBatchOptions;
|
|
688
|
+
type QueueSendBatchResponse = globalThis.QueueSendBatchResponse;
|
|
689
|
+
type QueueMetrics = globalThis.QueueMetrics;
|
|
690
|
+
type MessageSendRequest<Body> = globalThis.MessageSendRequest<Body>;
|
|
691
|
+
type QueueProducer<Body> = Pick<globalThis.Queue<Body>, "send"> & Partial<Pick<globalThis.Queue<Body>, "sendBatch" | "metrics">>;
|
|
692
|
+
interface QueueBindingDefinition<Message extends ServiceFreeSchema$4> {
|
|
693
|
+
/** Binding name as configured in `wrangler.jsonc`. */
|
|
694
|
+
readonly binding: string;
|
|
695
|
+
/** Codec used to encode messages before sending them to Cloudflare Queues. */
|
|
696
|
+
readonly message: Message;
|
|
697
|
+
}
|
|
698
|
+
interface QueueBindingClient<Message extends ServiceFreeSchema$4> {
|
|
699
|
+
readonly send: (message: Schema.Schema.Type<Message>, options?: QueueSendOptions) => Effect.Effect<void, QueueOperationError | Schema.SchemaError>;
|
|
700
|
+
readonly sendBatch: (messages: Iterable<MessageSendRequest<Schema.Schema.Type<Message>>>, options?: QueueSendBatchOptions) => Effect.Effect<void, QueueOperationError | Schema.SchemaError>;
|
|
701
|
+
readonly metrics: () => Effect.Effect<QueueMetrics, QueueOperationError>;
|
|
702
|
+
readonly unsafeRaw: Effect.Effect<globalThis.Queue<Schema.Codec.Encoded<Message>>>;
|
|
703
|
+
}
|
|
704
|
+
declare const QueueOperationError_base: new <A extends Record<string, any> = {}>(args: _$effect_Types0.VoidIfEmpty<{ readonly [P in keyof A as P extends "_tag" ? never : P]: A[P] }>) => _$effect_Cause0.YieldableError & {
|
|
705
|
+
readonly _tag: "QueueOperationError";
|
|
706
|
+
} & Readonly<A>;
|
|
707
|
+
declare class QueueOperationError extends QueueOperationError_base<{
|
|
708
|
+
readonly binding: string;
|
|
709
|
+
readonly operation: string;
|
|
710
|
+
readonly cause: unknown;
|
|
711
|
+
readonly message: string;
|
|
712
|
+
}> {}
|
|
713
|
+
declare const isQueue: <Body>(value: unknown) => value is QueueProducer<Body>;
|
|
714
|
+
declare const makeClient$6: <Message extends ServiceFreeSchema$4>(definition: QueueBindingDefinition<Message>) => ((queue: QueueProducer<Schema.Codec.Encoded<Message>>) => QueueBindingClient<Message>);
|
|
715
|
+
declare const layer$8: <Self, Message extends ServiceFreeSchema$4>(tag: Context.Service<Self, QueueBindingClient<Message>>, definition: QueueBindingDefinition<Message>) => _$effect_Layer0.Layer<Self, BindingNotFoundError | BindingValidationError, WorkerEnvironment>;
|
|
716
|
+
declare namespace QueueDefinition_d_exports {
|
|
717
|
+
export { Definition$8 as Definition, Handler$3 as Handler, LayerOptions$11 as LayerOptions, Options$7 as Options, Queue$1 as Queue, Tag$11 as Tag, TagClass$10 as TagClass, implement$7 as implement, make$8 as make };
|
|
718
|
+
}
|
|
719
|
+
interface Definition$8<Id extends string = string, Message extends ServiceFreeSchema$4 = ServiceFreeSchema$4> {
|
|
628
720
|
readonly id: Id;
|
|
629
|
-
readonly
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
readonly success: Success;
|
|
642
|
-
}): Method$3<Args, Success>;
|
|
721
|
+
readonly message: Message;
|
|
722
|
+
}
|
|
723
|
+
declare namespace Definition$8 {
|
|
724
|
+
type Any = Definition$8<string, ServiceFreeSchema$4>;
|
|
725
|
+
}
|
|
726
|
+
type Handler$3<ROut, Self extends Definition$8.Any> = (batch: QueueBatch<Schema.Schema.Type<Self["message"]>>) => Effect.Effect<void, unknown, ExecutionContext | WorkerContext | WorkerEnvironment | Scope.Scope | ROut>;
|
|
727
|
+
interface Options$7<ROut, Self extends Definition$8.Any> extends Omit<WorkerOptions<ROut, Record<never, never>>, "queue" | "rpc"> {
|
|
728
|
+
readonly queue: Handler$3<ROut, Self>;
|
|
729
|
+
readonly rpc?: never;
|
|
730
|
+
}
|
|
731
|
+
type LayerOptions$11 = {
|
|
732
|
+
readonly binding: string;
|
|
643
733
|
};
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
734
|
+
interface TagClass$10<Self, Id extends string, Message extends ServiceFreeSchema$4> extends Context.ServiceClass<Self, Id, QueueBindingClient<Message>> {
|
|
735
|
+
readonly id: Id;
|
|
736
|
+
readonly message: Message;
|
|
737
|
+
readonly make: <ROut, LayerError>(layer: Layer.Layer<ROut, LayerError, ExecutionContext | WorkerContext | WorkerEnvironment>, options: Options$7<ROut, Definition$8<Id, Message>>) => WorkerClass<Record<never, never>, ROut>;
|
|
738
|
+
readonly layer: (options: LayerOptions$11) => Layer.Layer<Self, BindingNotFoundError | BindingValidationError, WorkerEnvironment>;
|
|
739
|
+
readonly send: (message: Schema.Schema.Type<Message>, options?: QueueSendOptions) => Effect.Effect<void, QueueOperationError | Schema.SchemaError, Self>;
|
|
740
|
+
readonly sendBatch: (messages: Iterable<MessageSendRequest<Schema.Schema.Type<Message>>>, options?: QueueSendBatchOptions) => Effect.Effect<void, QueueOperationError | Schema.SchemaError, Self>;
|
|
741
|
+
readonly metrics: () => Effect.Effect<QueueMetrics, QueueOperationError, Self>;
|
|
742
|
+
readonly unsafeRaw: () => Effect.Effect<globalThis.Queue<Schema.Codec.Encoded<Message>>, never, Self>;
|
|
648
743
|
}
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
744
|
+
declare const make$8: <Id extends string, Message extends ServiceFreeSchema$4>(id: Id, definition: {
|
|
745
|
+
readonly message: Message;
|
|
746
|
+
}) => TagClass$10<Definition$8<Id, Message>, Id, Message>;
|
|
747
|
+
declare const Tag$11: <Self>() => <Id extends string, Message extends ServiceFreeSchema$4>(id: Id, definition: {
|
|
748
|
+
readonly message: Message;
|
|
749
|
+
}) => TagClass$10<Self, Id, Message>;
|
|
750
|
+
declare const Queue$1: <Self>() => <Id extends string, Message extends ServiceFreeSchema$4>(id: Id, definition: {
|
|
751
|
+
readonly message: Message;
|
|
752
|
+
}) => TagClass$10<Self, Id, Message>;
|
|
753
|
+
declare const implement$7: <ROut, const Self extends Definition$8.Any>(_definition: Self, handler: Handler$3<ROut, Self>) => Handler$3<ROut, Self>;
|
|
754
|
+
declare namespace Queue_d_exports {
|
|
755
|
+
export { Definition$7 as Definition, Handler$2 as Handler, LayerOptions$10 as LayerOptions, Options$6 as Options, QueueBatch, QueueHandler, QueueMessage, QueueMessageDecodeError, QueueOptions, Tag$10 as Tag, TagClass$9 as TagClass, decodeBatch, fromMessage, fromMessageBatch, implement$6 as implement };
|
|
756
|
+
}
|
|
757
|
+
interface QueueMessage<Body> {
|
|
758
|
+
readonly raw: globalThis.Message<unknown>;
|
|
759
|
+
readonly id: string;
|
|
760
|
+
readonly timestamp: Date;
|
|
761
|
+
readonly body: Body;
|
|
762
|
+
readonly attempts: number;
|
|
763
|
+
readonly ack: Effect.Effect<void>;
|
|
764
|
+
readonly retry: (options?: globalThis.QueueRetryOptions) => Effect.Effect<void>;
|
|
765
|
+
}
|
|
766
|
+
interface QueueBatch<Body> {
|
|
767
|
+
readonly raw: globalThis.MessageBatch<unknown>;
|
|
768
|
+
readonly messages: ReadonlyArray<QueueMessage<Body>>;
|
|
769
|
+
readonly queue: string;
|
|
770
|
+
readonly metadata: globalThis.MessageBatchMetadata;
|
|
771
|
+
readonly ackAll: Effect.Effect<void>;
|
|
772
|
+
readonly retryAll: (options?: globalThis.QueueRetryOptions) => Effect.Effect<void>;
|
|
773
|
+
}
|
|
774
|
+
declare const QueueMessageDecodeError_base: new <A extends Record<string, any> = {}>(args: _$effect_Types0.VoidIfEmpty<{ readonly [P in keyof A as P extends "_tag" ? never : P]: A[P] }>) => _$effect_Cause0.YieldableError & {
|
|
775
|
+
readonly _tag: "QueueMessageDecodeError";
|
|
653
776
|
} & Readonly<A>;
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
readonly
|
|
777
|
+
declare class QueueMessageDecodeError extends QueueMessageDecodeError_base<{
|
|
778
|
+
readonly queue: string;
|
|
779
|
+
readonly messageId: string;
|
|
780
|
+
readonly index: number;
|
|
657
781
|
readonly cause: unknown;
|
|
658
782
|
}> {}
|
|
659
|
-
type
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
783
|
+
type RuntimeContext$2<ROut> = ExecutionContext | WorkerContext | WorkerEnvironment | ROut;
|
|
784
|
+
type QueueHandlerContext<ROut> = RuntimeContext$2<ROut> | Scope.Scope;
|
|
785
|
+
type QueueHandler<ROut, Body = unknown> = (batch: QueueBatch<Body>) => Effect.Effect<void, unknown, QueueHandlerContext<ROut>>;
|
|
786
|
+
interface QueueOptions<ROut, Body = unknown> {
|
|
787
|
+
readonly queue: QueueHandler<ROut, Body>;
|
|
788
|
+
}
|
|
789
|
+
declare const fromMessage: <Body>(message: globalThis.Message<unknown>, body: Body) => {
|
|
790
|
+
raw: Message<unknown>;
|
|
791
|
+
id: string;
|
|
792
|
+
timestamp: Date;
|
|
793
|
+
body: Body;
|
|
794
|
+
attempts: number;
|
|
795
|
+
ack: Effect.Effect<void, never, never>;
|
|
796
|
+
retry: (options?: globalThis.QueueRetryOptions) => Effect.Effect<void, never, never>;
|
|
797
|
+
};
|
|
798
|
+
declare const fromMessageBatch: <Body>(batch: globalThis.MessageBatch<unknown>, messages: ReadonlyArray<QueueMessage<Body>>) => QueueBatch<Body>;
|
|
799
|
+
declare const decodeBatch: <Body>(batch: globalThis.MessageBatch<unknown>, decodeBody: (body: unknown) => Effect.Effect<Body, unknown>) => Effect.Effect<QueueBatch<Body>, QueueMessageDecodeError>;
|
|
800
|
+
type Definition$7<Id extends string = string, Message extends Definition$8.Any["message"] = Definition$8.Any["message"]> = Definition$8<Id, Message>;
|
|
801
|
+
declare namespace Definition$7 {
|
|
802
|
+
type Any = Definition$8.Any;
|
|
803
|
+
}
|
|
804
|
+
type LayerOptions$10 = LayerOptions$11;
|
|
805
|
+
type TagClass$9<Self, Id extends string, Message extends Definition$8.Any["message"]> = TagClass$10<Self, Id, Message>;
|
|
806
|
+
declare const Tag$10: <Self>() => <Id extends string, Message extends Definition$8.Any["message"]>(id: Id, definition: {
|
|
807
|
+
readonly message: Message;
|
|
808
|
+
}) => TagClass$9<Self, Id, Message>;
|
|
809
|
+
declare const implement$6: <ROut, const Self extends Definition$8.Any>(_definition: Self, handler: Handler$3<ROut, Self>) => Handler$3<ROut, Self>;
|
|
810
|
+
type Handler$2<ROut, Self extends Definition$8.Any> = Handler$3<ROut, Self>;
|
|
811
|
+
type Options$6<ROut, Self extends Definition$8.Any> = Options$7<ROut, Self>;
|
|
812
|
+
declare namespace WorkerDefinition_d_exports {
|
|
813
|
+
export { Api$3 as Api, Definition$6 as Definition, HandlerEffect$3 as HandlerEffect, Handlers$3 as Handlers, LayerOptions$9 as LayerOptions, Method$4 as Method, Methods$3 as Methods, NoReservedMethods$3 as NoReservedMethods, Options$5 as Options, ReservedMethodName$5 as ReservedMethodName, ServerApi$4 as ServerApi, ServiceFreeSchema$3 as ServiceFreeSchema, Tag$9 as Tag, TagClass$8 as TagClass, Worker, implement$5 as implement, make$7 as make, method$3 as method };
|
|
814
|
+
}
|
|
815
|
+
type ServiceFreeSchema$3 = Schema.Codec<any, any, never, never>;
|
|
816
|
+
interface Method$4<Args extends ReadonlyArray<ServiceFreeSchema$3> = ReadonlyArray<ServiceFreeSchema$3>, Success extends ServiceFreeSchema$3 = ServiceFreeSchema$3> {
|
|
817
|
+
readonly args: Args;
|
|
818
|
+
readonly success: Success;
|
|
819
|
+
}
|
|
820
|
+
declare namespace Method$4 {
|
|
821
|
+
export type Any = Method$4<ReadonlyArray<ServiceFreeSchema$3>, ServiceFreeSchema$3>;
|
|
822
|
+
type ArgsFromSchemas<Args extends ReadonlyArray<ServiceFreeSchema$3>> = Args extends readonly [] ? [] : Args extends readonly [infer Head extends ServiceFreeSchema$3, ...infer Tail extends ReadonlyArray<ServiceFreeSchema$3>] ? [Schema.Schema.Type<Head>, ...ArgsFromSchemas<Tail>] : Array<Schema.Schema.Type<Args[number]>>;
|
|
823
|
+
type EncodedArgsFromSchemas<Args extends ReadonlyArray<ServiceFreeSchema$3>> = Args extends readonly [] ? [] : Args extends readonly [infer Head extends ServiceFreeSchema$3, ...infer Tail extends ReadonlyArray<ServiceFreeSchema$3>] ? [Schema.Codec.Encoded<Head>, ...EncodedArgsFromSchemas<Tail>] : Array<Schema.Codec.Encoded<Args[number]>>;
|
|
824
|
+
export type Args<Self extends Any> = ArgsFromSchemas<Self["args"]>;
|
|
825
|
+
export type EncodedArgs<Self extends Any> = EncodedArgsFromSchemas<Self["args"]>;
|
|
826
|
+
export type Success<Self extends Any> = Schema.Schema.Type<Self["success"]>;
|
|
827
|
+
export type EncodedSuccess<Self extends Any> = Schema.Codec.Encoded<Self["success"]>;
|
|
828
|
+
export {};
|
|
677
829
|
}
|
|
830
|
+
type Methods$3 = Record<string, Method$4.Any>;
|
|
678
831
|
/**
|
|
679
|
-
*
|
|
832
|
+
* RPC contract for a Worker service.
|
|
833
|
+
*
|
|
834
|
+
* Create with {@link make} and reuse to type both worker implementations and
|
|
835
|
+
* service bindings in other workers.
|
|
680
836
|
*/
|
|
681
|
-
interface
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
837
|
+
interface Definition$6<Id extends string = string, MethodsShape extends Methods$3 = Methods$3> {
|
|
838
|
+
readonly id: Id;
|
|
839
|
+
readonly methods: MethodsShape;
|
|
840
|
+
}
|
|
841
|
+
declare namespace Definition$6 {
|
|
842
|
+
type Any = Definition$6<string, Methods$3>;
|
|
685
843
|
}
|
|
844
|
+
type ReservedMethodName$5 = ReservedMethodName$3;
|
|
845
|
+
type NoReservedMethods$3<MethodsShape extends Methods$3> = Extract<keyof MethodsShape, ReservedMethodName$5> extends never ? MethodsShape : never;
|
|
686
846
|
/**
|
|
687
|
-
*
|
|
847
|
+
* Promise-based client API derived from a {@link Definition}.
|
|
688
848
|
*/
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
readonly value: Schema.Codec<Value, EncodedValue>;
|
|
692
|
-
}
|
|
849
|
+
type ServerApi$4<Self extends Definition$6.Any> = { readonly [Key in keyof Self["methods"]]: (...args: Method$4.Args<Self["methods"][Key]>) => Promise<Method$4.Success<Self["methods"][Key]>> };
|
|
850
|
+
type Api$3<Self extends Definition$6.Any> = Provider<ServerApi$4<Self>, ReservedMethodName$5>;
|
|
693
851
|
/**
|
|
694
|
-
*
|
|
852
|
+
* Effect handlers for each RPC method in a worker definition.
|
|
695
853
|
*/
|
|
696
|
-
|
|
697
|
-
get(key: Key): Effect.Effect<Option.Option<Value>, unknown>;
|
|
698
|
-
put(key: Key, value: Value): Effect.Effect<void, unknown>;
|
|
699
|
-
delete(key: Key): Effect.Effect<boolean, unknown>;
|
|
700
|
-
list(options?: globalThis.SyncKvListOptions): Effect.Effect<Array<[Key, Value]>, unknown>;
|
|
701
|
-
}
|
|
854
|
+
type Handlers$3<ROut, Self extends Definition$6.Any> = { readonly [Key in keyof Self["methods"]]: (...args: Method$4.Args<Self["methods"][Key]>) => WorkerRpcHandler<ROut, Method$4.Success<Self["methods"][Key]>> };
|
|
702
855
|
/**
|
|
703
|
-
*
|
|
856
|
+
* Worker constructor options for a specific RPC definition.
|
|
704
857
|
*/
|
|
705
|
-
interface
|
|
706
|
-
|
|
707
|
-
put<T>(key: string, value: T): StorageEffect<void>;
|
|
708
|
-
delete(key: string): StorageEffect<boolean>;
|
|
709
|
-
list<T = unknown>(options?: globalThis.SyncKvListOptions): StorageEffect<Array<[string, T]>>;
|
|
710
|
-
schema<Key, Value, EncodedValue>(definition: SyncKvDefinition<Key, Value, EncodedValue>): SchemaBackedSyncKvStorage<Key, Value>;
|
|
858
|
+
interface Options$5<ROut, Self extends Definition$6.Any, REvent = never, EventLayerError = never> extends Omit<WorkerOptions<ROut, REvent, EventLayerError, Handlers$3<ROut | REvent, Self>>, "rpc"> {
|
|
859
|
+
readonly rpc: Handlers$3<ROut | REvent, Self>;
|
|
711
860
|
}
|
|
861
|
+
type LayerOptions$9 = {
|
|
862
|
+
readonly binding: string;
|
|
863
|
+
};
|
|
864
|
+
type TagClass$8<Self, Id extends string, MethodsShape extends Methods$3> = Context.ServiceClass<Self, Id, ServiceBindingEffectClient<Api$3<Definition$6<Id, MethodsShape>>, Definition$6<Id, MethodsShape>>> & ServiceBindingStaticClient<Self, Api$3<Definition$6<Id, MethodsShape>>, Definition$6<Id, MethodsShape>> & {
|
|
865
|
+
readonly id: Id;
|
|
866
|
+
readonly methods: MethodsShape;
|
|
867
|
+
readonly make: <ROut, LayerError, REvent = never, EventLayerError = never>(layer: Layer.Layer<ROut, LayerError, ExecutionContext | WorkerContext | WorkerEnvironment>, options: Options$5<ROut, Definition$6<Id, MethodsShape>, REvent, EventLayerError>) => WorkerClass<Handlers$3<ROut | REvent, Definition$6<Id, MethodsShape>>, ROut | REvent>;
|
|
868
|
+
readonly layer: (options: LayerOptions$9) => Layer.Layer<Self, BindingNotFoundError | BindingValidationError, WorkerEnvironment>;
|
|
869
|
+
};
|
|
712
870
|
/**
|
|
713
|
-
*
|
|
871
|
+
* Defines a single RPC method schema in a worker definition.
|
|
714
872
|
*/
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
|
|
873
|
+
declare const method$3: {
|
|
874
|
+
<Success extends ServiceFreeSchema$3>(definition: {
|
|
875
|
+
readonly success: Success;
|
|
876
|
+
}): Method$4<readonly [], Success>;
|
|
877
|
+
<const Args extends readonly ServiceFreeSchema$3[], Success extends ServiceFreeSchema$3>(definition: {
|
|
878
|
+
readonly args: Args;
|
|
879
|
+
readonly success: Success;
|
|
880
|
+
}): Method$4<Args, Success>;
|
|
881
|
+
};
|
|
882
|
+
declare const make$7: <Id extends string, const MethodsShape extends Methods$3>(id: Id, methods: MethodsShape & NoReservedMethods$3<MethodsShape>) => TagClass$8<Definition$6<Id, MethodsShape>, Id, MethodsShape>;
|
|
883
|
+
declare const Tag$9: <Self>() => <Id extends string, const MethodsShape extends Methods$3>(id: Id, methods: MethodsShape & NoReservedMethods$3<MethodsShape>) => TagClass$8<Self, Id, MethodsShape>;
|
|
884
|
+
declare const Worker: <Self>() => <Id extends string, const MethodsShape extends Methods$3>(id: Id, methods: MethodsShape & NoReservedMethods$3<MethodsShape>) => TagClass$8<Self, Id, MethodsShape>;
|
|
885
|
+
/**
|
|
886
|
+
* Helper for implementing handlers with the exact method shape of a definition.
|
|
887
|
+
*/
|
|
888
|
+
declare const implement$5: <ROut, const Self extends Definition$6.Any>(_definition: Self, handlers: Handlers$3<ROut, Self>) => Handlers$3<ROut, Self>;
|
|
889
|
+
/**
|
|
890
|
+
* Convenience alias for a single worker RPC handler Effect.
|
|
891
|
+
*/
|
|
892
|
+
type HandlerEffect$3<ROut, Self extends Definition$6.Any, Key extends keyof Self["methods"]> = WorkerRpcHandler<ROut, Method$4.Success<Self["methods"][Key]>>;
|
|
893
|
+
//#endregion
|
|
894
|
+
//#region src/internal/RpcInvocation.d.ts
|
|
895
|
+
type AnyArgs = Array<any>;
|
|
896
|
+
type AsyncMethodKey<Api> = { [Key in keyof Api]-?: Key extends string ? Api[Key] extends ((...args: AnyArgs) => Promise<unknown>) ? Key : never : never }[keyof Api];
|
|
897
|
+
type AsyncMethodArgs<Api, Method extends keyof Api> = Api[Method] extends ((...args: infer Args) => Promise<unknown>) ? Args : never;
|
|
898
|
+
type AsyncMethodSuccess<Api, Method extends keyof Api> = Api[Method] extends ((...args: AnyArgs) => Promise<infer A>) ? A : never;
|
|
899
|
+
type AsyncMethodCloudflareReturn<Api, Method extends keyof Api> = Result<AsyncMethodSuccess<Api, Method>>;
|
|
900
|
+
declare namespace ServiceBinding_d_exports {
|
|
901
|
+
export { Service, ServiceBindingClient, ServiceBindingDefinition, ServiceBindingEffectClient, ServiceBindingFetchError, ServiceBindingRpcError, ServiceBindingStaticClient, ServiceFetcher, isServiceBindingClient, layer$7 as layer, makeClient$5 as makeClient, makeDirectMethods$1 as makeDirectMethods };
|
|
727
902
|
}
|
|
903
|
+
declare const TypeId$1: "effect-cf/ServiceBinding";
|
|
728
904
|
/**
|
|
729
|
-
*
|
|
730
|
-
*
|
|
731
|
-
* @example
|
|
732
|
-
* ```ts
|
|
733
|
-
* const program = Effect.gen(function* () {
|
|
734
|
-
* const state = yield* DurableObjectState;
|
|
735
|
-
* yield* state.storage.put("counter", 1);
|
|
736
|
-
* const value = yield* state.storage.get<number>("counter");
|
|
737
|
-
* return value;
|
|
738
|
-
* });
|
|
739
|
-
* ```
|
|
905
|
+
* Minimum shape for a Cloudflare service binding.
|
|
740
906
|
*/
|
|
741
|
-
interface
|
|
742
|
-
|
|
743
|
-
put<T>(key: string, value: T, options?: globalThis.DurableObjectPutOptions): StorageEffect<void>;
|
|
744
|
-
delete(key: string, options?: globalThis.DurableObjectPutOptions): StorageEffect<boolean>;
|
|
745
|
-
/**
|
|
746
|
-
* Deletes all stored data. On compatibility dates before 2026-02-24, Cloudflare
|
|
747
|
-
* documents that active alarms must be deleted separately with `deleteAlarm()`.
|
|
748
|
-
*/
|
|
749
|
-
deleteAll(options?: globalThis.DurableObjectPutOptions): StorageEffect<void>;
|
|
750
|
-
getAlarm(options?: globalThis.DurableObjectGetAlarmOptions): StorageEffect<number | null>;
|
|
751
|
-
setAlarm(scheduledTime: number | Date, options?: globalThis.DurableObjectSetAlarmOptions): StorageEffect<void>;
|
|
752
|
-
deleteAlarm(options?: globalThis.DurableObjectSetAlarmOptions): StorageEffect<void>;
|
|
753
|
-
/**
|
|
754
|
-
* SQLite-backed Durable Object storage only.
|
|
755
|
-
*
|
|
756
|
-
* The callback Effect must complete synchronously. If it requires asynchronous
|
|
757
|
-
* work, use `transaction` instead so Cloudflare can run the async transaction
|
|
758
|
-
* callback under the platform's transaction contract.
|
|
759
|
-
*/
|
|
760
|
-
transactionSync<A, E, R>(closure: () => Effect.Effect<A, E, R>): Effect.Effect<A, E | StorageOperationError, R>;
|
|
761
|
-
/**
|
|
762
|
-
* Runs an async transaction and exposes a typed transaction wrapper.
|
|
763
|
-
*/
|
|
764
|
-
transaction<A, E, R>(closure: (txn: DurableObjectTransaction) => Effect.Effect<A, E, R>): Effect.Effect<A, E | StorageOperationError, R>;
|
|
765
|
-
/** Flushes pending writes to disk. */
|
|
766
|
-
sync(): StorageEffect<void>;
|
|
767
|
-
/** SQLite-backed Durable Object storage point-in-time recovery API only. */
|
|
768
|
-
getCurrentBookmark(): StorageEffect<string>;
|
|
769
|
-
/** SQLite-backed Durable Object storage point-in-time recovery API only. */
|
|
770
|
-
onNextSessionRestoreBookmark(bookmark: string): StorageEffect<string>;
|
|
771
|
-
readonly sql: SqlStorage;
|
|
772
|
-
readonly kv: SyncKvStorage;
|
|
907
|
+
interface ServiceFetcher {
|
|
908
|
+
fetch(input: RequestInfo | URL, init?: RequestInit): Promise<Response>;
|
|
773
909
|
}
|
|
910
|
+
type RpcClient$1<Api> = { readonly [Key in keyof Api as Key extends string ? Api[Key] extends ((...args: Array<any>) => unknown) ? Key : never : never]: Api[Key] };
|
|
911
|
+
type ReservedMethodName$4 = ReservedMethodName$5 | "fetch";
|
|
774
912
|
/**
|
|
775
|
-
*
|
|
913
|
+
* Native Cloudflare service object including optional RPC methods.
|
|
776
914
|
*/
|
|
777
|
-
|
|
778
|
-
|
|
779
|
-
|
|
915
|
+
type ServiceBindingClient<Api extends object> = ServiceFetcher & RpcClient$1<Provider<Api, ReservedMethodName$4>>;
|
|
916
|
+
type ApiFromDefinition<Definition> = Definition extends Definition$6.Any ? ServerApi$4<Definition> : never;
|
|
917
|
+
type ApiOrDefinition<Api extends object, Definition> = [Api] extends [never] ? ApiFromDefinition<Definition> : Api;
|
|
918
|
+
/**
|
|
919
|
+
* Binding metadata used to create an Effect service from a Worker binding.
|
|
920
|
+
*/
|
|
921
|
+
interface ServiceBindingDefinition<Definition extends Definition$6.Any | undefined = undefined> {
|
|
922
|
+
/** Binding name as configured in `wrangler.jsonc`. */
|
|
923
|
+
readonly binding: string;
|
|
924
|
+
/** Optional RPC schema used for argument/result encoding. */
|
|
925
|
+
readonly definition?: Definition;
|
|
780
926
|
}
|
|
781
|
-
|
|
782
|
-
|
|
783
|
-
declare const DurableWebSocketSendError_base: new <A extends Record<string, any> = {}>(args: _$effect_Types0.VoidIfEmpty<{ readonly [P in keyof A as P extends "_tag" ? never : P]: A[P] }>) => _$effect_Cause0.YieldableError & {
|
|
784
|
-
readonly _tag: "DurableWebSocketSendError";
|
|
785
|
-
} & Readonly<A>;
|
|
786
|
-
/** Error raised when sending on a Durable Object websocket fails. */
|
|
787
|
-
declare class DurableWebSocketSendError extends DurableWebSocketSendError_base<{
|
|
788
|
-
readonly cause: unknown;
|
|
789
|
-
}> {}
|
|
790
|
-
declare const DurableWebSocketCloseError_base: new <A extends Record<string, any> = {}>(args: _$effect_Types0.VoidIfEmpty<{ readonly [P in keyof A as P extends "_tag" ? never : P]: A[P] }>) => _$effect_Cause0.YieldableError & {
|
|
791
|
-
readonly _tag: "DurableWebSocketCloseError";
|
|
927
|
+
declare const ServiceBindingFetchError_base: new <A extends Record<string, any> = {}>(args: _$effect_Types0.VoidIfEmpty<{ readonly [P in keyof A as P extends "_tag" ? never : P]: A[P] }>) => _$effect_Cause0.YieldableError & {
|
|
928
|
+
readonly _tag: "ServiceBindingFetchError";
|
|
792
929
|
} & Readonly<A>;
|
|
793
|
-
/**
|
|
794
|
-
|
|
930
|
+
/**
|
|
931
|
+
* Failure raised when calling `fetch` on a service binding.
|
|
932
|
+
*/
|
|
933
|
+
declare class ServiceBindingFetchError extends ServiceBindingFetchError_base<{
|
|
934
|
+
readonly binding: string;
|
|
795
935
|
readonly cause: unknown;
|
|
796
936
|
}> {}
|
|
797
|
-
declare const
|
|
798
|
-
readonly _tag: "
|
|
937
|
+
declare const ServiceBindingRpcError_base: new <A extends Record<string, any> = {}>(args: _$effect_Types0.VoidIfEmpty<{ readonly [P in keyof A as P extends "_tag" ? never : P]: A[P] }>) => _$effect_Cause0.YieldableError & {
|
|
938
|
+
readonly _tag: "ServiceBindingRpcError";
|
|
799
939
|
} & Readonly<A>;
|
|
800
|
-
/** Error raised when serializing or deserializing a websocket attachment fails. */
|
|
801
|
-
declare class DurableWebSocketAttachmentError extends DurableWebSocketAttachmentError_base<{
|
|
802
|
-
readonly operation: "serialize" | "deserialize";
|
|
803
|
-
readonly cause: unknown;
|
|
804
|
-
}> {}
|
|
805
|
-
/** Effect-native wrapper around a hibernatable Durable Object websocket. */
|
|
806
|
-
interface DurableWebSocket<Attachment = unknown> {
|
|
807
|
-
/** Underlying Cloudflare websocket. */
|
|
808
|
-
readonly raw: WebSocket;
|
|
809
|
-
/** Sends a message through the socket. */
|
|
810
|
-
send(data: DurableWebSocketSendData): Effect.Effect<void, DurableWebSocketSendError>;
|
|
811
|
-
/** Closes the socket. */
|
|
812
|
-
close(code?: number, reason?: string): Effect.Effect<void, DurableWebSocketCloseError>;
|
|
813
|
-
/** Serializes hibernation attachment metadata onto the socket. */
|
|
814
|
-
serializeAttachment<A = Attachment>(value: A): Effect.Effect<void, DurableWebSocketAttachmentError>;
|
|
815
|
-
/** Deserializes hibernation attachment metadata from the socket. */
|
|
816
|
-
readonly deserializeAttachment: Effect.Effect<unknown, DurableWebSocketAttachmentError>;
|
|
817
|
-
}
|
|
818
|
-
/** Wraps a native Cloudflare websocket in the Effect-native Durable Object API. */
|
|
819
|
-
declare const fromWebSocket: <Attachment = unknown>(raw: WebSocket) => DurableWebSocket<Attachment>;
|
|
820
|
-
/**
|
|
821
|
-
* Options for accepting an incoming websocket request in a Durable Object.
|
|
822
|
-
*/
|
|
823
|
-
interface AcceptUpgradeOptions<Attachment = unknown> {
|
|
824
|
-
/** Optional websocket tags for Durable Object hibernation filtering. */
|
|
825
|
-
readonly tags?: ReadonlyArray<string> | undefined;
|
|
826
|
-
/** Optional attachment serialized onto the server socket. */
|
|
827
|
-
readonly attachment?: Attachment | undefined;
|
|
828
|
-
}
|
|
829
940
|
/**
|
|
830
|
-
*
|
|
941
|
+
* Failure raised when invoking an RPC method on a service binding.
|
|
831
942
|
*/
|
|
832
|
-
|
|
833
|
-
readonly
|
|
834
|
-
readonly
|
|
835
|
-
readonly
|
|
836
|
-
}
|
|
943
|
+
declare class ServiceBindingRpcError extends ServiceBindingRpcError_base<{
|
|
944
|
+
readonly binding: string;
|
|
945
|
+
readonly method: string;
|
|
946
|
+
readonly cause: unknown;
|
|
947
|
+
}> {}
|
|
948
|
+
type ServiceMethodKey<Api> = AsyncMethodKey<Api>;
|
|
949
|
+
type ServiceMethodArgs<Api, Method extends keyof Api> = AsyncMethodArgs<Api, Method>;
|
|
950
|
+
type ServiceMethodSuccess<Api, Method extends keyof Api> = AsyncMethodSuccess<Api, Method>;
|
|
951
|
+
type ServiceMethodCloudflareReturn<Api, Method extends keyof Api> = AsyncMethodCloudflareReturn<Api, Method>;
|
|
952
|
+
type ServiceCall<R, Api> = <Method extends ServiceMethodKey<Api>>(method: Method, ...args: ServiceMethodArgs<Api, Method>) => Effect.Effect<ServiceMethodSuccess<Api, Method>, ServiceBindingRpcError, R>;
|
|
953
|
+
type DefinitionDirectMethods<R, Definition extends Definition$6.Any> = { readonly [Method in Definition$9.MethodNames<Definition>]: (...args: Method$5.Args<Definition["methods"][Method]>) => Effect.Effect<Method$5.Success<Definition["methods"][Method]>, ServiceBindingRpcError, R> };
|
|
954
|
+
type DirectMethods$1<R, Definition> = Definition extends Definition$6.Any ? DefinitionDirectMethods<R, Definition> : {};
|
|
955
|
+
type ServiceBindingEffectClient<Api extends object, Definition extends Definition$6.Any | undefined = undefined> = DirectMethods$1<never, Definition> & {
|
|
956
|
+
/**
|
|
957
|
+
* Forwards an HTTP request to the bound Worker service.
|
|
958
|
+
*
|
|
959
|
+
* Use this when the service binding is acting as an HTTP origin rather than a
|
|
960
|
+
* Cloudflare RPC target.
|
|
961
|
+
*
|
|
962
|
+
* @example
|
|
963
|
+
* ```ts
|
|
964
|
+
* import { Effect } from "effect";
|
|
965
|
+
*
|
|
966
|
+
* const program = Effect.gen(function* () {
|
|
967
|
+
* const api = yield* ApiWorker;
|
|
968
|
+
* return yield* api.fetch(new Request("https://internal.example/users"));
|
|
969
|
+
* });
|
|
970
|
+
* ```
|
|
971
|
+
*/
|
|
972
|
+
readonly fetch: (input: RequestInfo | URL, init?: RequestInit) => Effect.Effect<globalThis.Response, ServiceBindingFetchError>;
|
|
973
|
+
/**
|
|
974
|
+
* Invokes a Worker RPC method and returns Cloudflare's raw RPC result.
|
|
975
|
+
*
|
|
976
|
+
* This preserves Cloudflare RPC behavior such as promise-like pipelining and
|
|
977
|
+
* transferable / disposable result objects. It does not resolve the returned
|
|
978
|
+
* promise-like value and it does not decode definition-backed success schemas.
|
|
979
|
+
*
|
|
980
|
+
* Most application code should use {@link call} instead.
|
|
981
|
+
*
|
|
982
|
+
* @example
|
|
983
|
+
* ```ts
|
|
984
|
+
* import { Effect } from "effect";
|
|
985
|
+
*
|
|
986
|
+
* const program = Effect.gen(function* () {
|
|
987
|
+
* const counter = yield* CounterService;
|
|
988
|
+
*
|
|
989
|
+
* const result = yield* counter.rpc("increment", 41);
|
|
990
|
+
* const value = yield* Effect.promise(() => result);
|
|
991
|
+
*
|
|
992
|
+
* return value;
|
|
993
|
+
* });
|
|
994
|
+
* ```
|
|
995
|
+
*/
|
|
996
|
+
readonly rpc: <Method extends ServiceMethodKey<Api>>(method: Method, ...args: ServiceMethodArgs<Api, Method>) => Effect.Effect<ServiceMethodCloudflareReturn<Api, Method>, ServiceBindingRpcError>;
|
|
997
|
+
/**
|
|
998
|
+
* Invokes a Worker RPC method, resolves Cloudflare's RPC result, and decodes
|
|
999
|
+
* the success value when the binding was created from a definition.
|
|
1000
|
+
*
|
|
1001
|
+
* This is the normal choice when application code wants the final typed value.
|
|
1002
|
+
*
|
|
1003
|
+
* @example
|
|
1004
|
+
* ```ts
|
|
1005
|
+
* import { Effect } from "effect";
|
|
1006
|
+
*
|
|
1007
|
+
* const program = Effect.gen(function* () {
|
|
1008
|
+
* const counter = yield* CounterService;
|
|
1009
|
+
* const value = yield* counter.call("increment", 41);
|
|
1010
|
+
*
|
|
1011
|
+
* return value;
|
|
1012
|
+
* });
|
|
1013
|
+
* ```
|
|
1014
|
+
*/
|
|
1015
|
+
readonly call: <Method extends ServiceMethodKey<Api>>(method: Method, ...args: ServiceMethodArgs<Api, Method>) => Effect.Effect<ServiceMethodSuccess<Api, Method>, ServiceBindingRpcError>;
|
|
1016
|
+
/**
|
|
1017
|
+
* Invokes a Worker RPC method in the current `Scope`, resolves Cloudflare's RPC
|
|
1018
|
+
* result, decodes definition-backed success values, and disposes the resolved
|
|
1019
|
+
* result when the scope closes if it implements `Symbol.dispose`.
|
|
1020
|
+
*
|
|
1021
|
+
* Use this for RPC methods that return Cloudflare RPC resources or other
|
|
1022
|
+
* disposable objects whose lifetime should be tied to an Effect scope.
|
|
1023
|
+
*
|
|
1024
|
+
* @example
|
|
1025
|
+
* ```ts
|
|
1026
|
+
* import { Effect } from "effect";
|
|
1027
|
+
*
|
|
1028
|
+
* const program = Effect.scoped(
|
|
1029
|
+
* Effect.gen(function* () {
|
|
1030
|
+
* const files = yield* FileService;
|
|
1031
|
+
* const handle = yield* files.scopedCall("open", "report.csv");
|
|
1032
|
+
*
|
|
1033
|
+
* return yield* handle.read();
|
|
1034
|
+
* }),
|
|
1035
|
+
* );
|
|
1036
|
+
* ```
|
|
1037
|
+
*/
|
|
1038
|
+
readonly scopedCall: <Method extends ServiceMethodKey<Api>>(method: Method, ...args: ServiceMethodArgs<Api, Method>) => Effect.Effect<Awaited<ServiceMethodSuccess<Api, Method>>, unknown, Scope.Scope>;
|
|
1039
|
+
};
|
|
1040
|
+
type ServiceBindingStaticClient<R, Api extends object, Definition extends Definition$6.Any | undefined = undefined> = DirectMethods$1<R, Definition> & {
|
|
1041
|
+
readonly fetch: (input: RequestInfo | URL, init?: RequestInit) => Effect.Effect<globalThis.Response, ServiceBindingFetchError, R>;
|
|
1042
|
+
readonly rpc: <Method extends ServiceMethodKey<Api>>(method: Method, ...args: ServiceMethodArgs<Api, Method>) => Effect.Effect<ServiceMethodCloudflareReturn<Api, Method>, ServiceBindingRpcError, R>;
|
|
1043
|
+
readonly call: <Method extends ServiceMethodKey<Api>>(method: Method, ...args: ServiceMethodArgs<Api, Method>) => Effect.Effect<ServiceMethodSuccess<Api, Method>, ServiceBindingRpcError, R>;
|
|
1044
|
+
readonly scopedCall: <Method extends ServiceMethodKey<Api>>(method: Method, ...args: ServiceMethodArgs<Api, Method>) => Effect.Effect<Awaited<ServiceMethodSuccess<Api, Method>>, unknown, Scope.Scope | R>;
|
|
1045
|
+
};
|
|
1046
|
+
declare const isServiceBindingClient: <Api extends object>(value: unknown) => value is ServiceBindingClient<Api>;
|
|
1047
|
+
declare const makeClient$5: <Api extends object, const Definition extends Definition$6.Any | undefined = undefined>(definition: ServiceBindingDefinition<Definition>) => ((service: ServiceBindingClient<Api>) => ServiceBindingEffectClient<Api, Definition>);
|
|
1048
|
+
declare const layer$7: <Self, Api extends object, const Definition extends Definition$6.Any | undefined = undefined>(tag: Context.Service<Self, ServiceBindingEffectClient<Api, Definition>>, definition: ServiceBindingDefinition<Definition>) => _$effect_Layer0.Layer<Self, BindingNotFoundError | BindingValidationError, WorkerEnvironment>;
|
|
837
1049
|
/**
|
|
838
|
-
*
|
|
1050
|
+
* Creates a typed Effect service for a Worker service binding.
|
|
1051
|
+
*
|
|
1052
|
+
* Returned value includes:
|
|
1053
|
+
* - a Context tag for dependency injection
|
|
1054
|
+
* - `fetch(...)` for raw HTTP forwarding
|
|
1055
|
+
* - `rpc(...)` for raw Cloudflare RPC results
|
|
1056
|
+
* - `call(...)` for resolved and decoded RPC results
|
|
1057
|
+
* - `scopedCall(...)` for scoped and decoded disposable RPC results
|
|
1058
|
+
* - direct RPC methods when `definition` is provided
|
|
839
1059
|
*
|
|
840
1060
|
* @example
|
|
841
1061
|
* ```ts
|
|
842
|
-
* const
|
|
843
|
-
*
|
|
1062
|
+
* const Counter = WorkerDefinition.make("Counter", {
|
|
1063
|
+
* increment: WorkerDefinition.method({
|
|
1064
|
+
* args: [Schema.Number],
|
|
1065
|
+
* success: Schema.Number,
|
|
1066
|
+
* }),
|
|
844
1067
|
* });
|
|
845
1068
|
*
|
|
846
|
-
*
|
|
1069
|
+
* const CounterLive = Counter.layer({ binding: "COUNTER" });
|
|
1070
|
+
*
|
|
1071
|
+
* const program = Effect.gen(function* () {
|
|
1072
|
+
* const counter = yield* Counter;
|
|
1073
|
+
* const next = yield* counter.increment(1);
|
|
1074
|
+
* return next;
|
|
1075
|
+
* });
|
|
847
1076
|
* ```
|
|
848
1077
|
*/
|
|
849
|
-
declare const
|
|
850
|
-
|
|
851
|
-
|
|
852
|
-
|
|
853
|
-
readonly
|
|
854
|
-
|
|
855
|
-
readonly
|
|
856
|
-
}
|
|
857
|
-
|
|
858
|
-
|
|
859
|
-
|
|
860
|
-
}
|
|
861
|
-
interface DurableWebSocketAttachment<Attachment, Encoded> {
|
|
862
|
-
serialize(socket: DurableWebSocket<unknown>, value: Attachment): Effect.Effect<void, DurableWebSocketAttachmentError>;
|
|
863
|
-
deserialize(socket: DurableWebSocket<unknown>): Effect.Effect<Option.Option<Attachment>, DurableWebSocketAttachmentError>;
|
|
864
|
-
rehydrate(options?: AttachmentRehydrateOptions): Effect.Effect<Array<RehydratedDurableWebSocket<Attachment>>, DurableWebSocketAttachmentError, DurableObjectState>;
|
|
865
|
-
readonly schema: Schema.Codec<Attachment, Encoded, never, never>;
|
|
1078
|
+
declare const Service: <Self, Api extends object = never>() => <Id extends string, const Definition extends Definition$6.Any | undefined = undefined>(id: Id, definition: ServiceBindingDefinition<Definition>) => BindingService<Self, Id, ServiceBindingEffectClient<ApiOrDefinition<Api, Definition>, Definition>> & DirectMethods$1<Self, Definition> & {
|
|
1079
|
+
readonly [TypeId$1]: typeof TypeId$1;
|
|
1080
|
+
readonly definition: ServiceBindingDefinition<Definition>;
|
|
1081
|
+
readonly fetch: (input: RequestInfo | URL, init?: RequestInit) => Effect.Effect<Response, ServiceBindingFetchError, Self>;
|
|
1082
|
+
readonly rpc: <Method extends ServiceMethodKey<ApiOrDefinition<Api, Definition>>>(method: Method, ...args: ServiceMethodArgs<ApiOrDefinition<Api, Definition>, Method>) => Effect.Effect<Result<AsyncMethodSuccess<ApiOrDefinition<Api, Definition>, Method>>, ServiceBindingRpcError, Self>;
|
|
1083
|
+
readonly call: <Method extends ServiceMethodKey<ApiOrDefinition<Api, Definition>>>(method: Method, ...args: ServiceMethodArgs<ApiOrDefinition<Api, Definition>, Method>) => Effect.Effect<AsyncMethodSuccess<ApiOrDefinition<Api, Definition>, Method>, ServiceBindingRpcError, Self>;
|
|
1084
|
+
readonly scopedCall: <Method extends ServiceMethodKey<ApiOrDefinition<Api, Definition>>>(method: Method, ...args: ServiceMethodArgs<ApiOrDefinition<Api, Definition>, Method>) => Effect.Effect<Awaited<AsyncMethodSuccess<ApiOrDefinition<Api, Definition>, Method>>, unknown, Self | Scope.Scope>;
|
|
1085
|
+
};
|
|
1086
|
+
declare const makeDirectMethods$1: <R, Api, Definition extends Definition$6.Any | undefined>(rpcDefinition: Definition | undefined, call: ServiceCall<R, Api>) => DirectMethods$1<R, Definition>;
|
|
1087
|
+
declare namespace Worker_d_exports {
|
|
1088
|
+
export { Api$2 as Api, Definition$5 as Definition, ExecutionContext, FetchHandler, FetchWorkerOptions, HandlerEffect$2 as HandlerEffect, Handlers$2 as Handlers, LayerOptions$8 as LayerOptions, Method$3 as Method, Methods$2 as Methods, NativeRequest, NoReservedMethods$2 as NoReservedMethods, Options$4 as Options, ReservedMethodName$3 as ReservedMethodName, RpcHandlers$1 as RpcHandlers, ServerApi$3 as ServerApi, ServiceFreeSchema$2 as ServiceFreeSchema, Tag$8 as Tag, TagClass$7 as TagClass, TagFactory$1 as TagFactory, WorkerClass, WorkerContext, WorkerContextService, WorkerContextWaitUntilOptions, WorkerFetchSuccess, WorkerHandler, WorkerOptions, WorkerRpc, WorkerRpcHandler, WorkerRpcShape, implement$4 as implement, isWebSocketUpgrade, make$6 as make, makeFetchHandler, method$2 as method, renderHttpResponse };
|
|
866
1089
|
}
|
|
867
|
-
|
|
868
|
-
declare
|
|
869
|
-
interface
|
|
870
|
-
readonly
|
|
871
|
-
readonly
|
|
872
|
-
readonly error?: (socket: DurableWebSocket, error: unknown) => Effect.Effect<void, E, R>;
|
|
1090
|
+
declare const ExecutionContext_base: Context.ServiceClass<ExecutionContext, "effect-cf/ExecutionContext", globalThis.ExecutionContext<unknown>>;
|
|
1091
|
+
declare class ExecutionContext extends ExecutionContext_base {}
|
|
1092
|
+
interface WorkerContextWaitUntilOptions<E, R> {
|
|
1093
|
+
readonly mode?: "observe" | "propagate";
|
|
1094
|
+
readonly onFailure?: (cause: Cause.Cause<E>) => Effect.Effect<void, never, R>;
|
|
873
1095
|
}
|
|
874
|
-
|
|
875
|
-
|
|
876
|
-
|
|
877
|
-
|
|
878
|
-
|
|
879
|
-
};
|
|
880
|
-
declare namespace DurableObjectState_d_exports {
|
|
881
|
-
export { DurableObjectState, DurableObjectStateService, fromDurableObjectState };
|
|
1096
|
+
interface WorkerContextService {
|
|
1097
|
+
readonly raw: globalThis.ExecutionContext;
|
|
1098
|
+
waitUntil<A, E, R, R2 = never>(effect: Effect.Effect<A, E, R>, options?: WorkerContextWaitUntilOptions<E, R2>): Effect.Effect<void, never, R | R2>;
|
|
1099
|
+
waitUntilPropagating<A, E, R, R2 = never>(effect: Effect.Effect<A, E, R>, options?: Omit<WorkerContextWaitUntilOptions<E, R2>, "mode">): Effect.Effect<void, never, R | R2>;
|
|
1100
|
+
readonly passThroughOnException: Effect.Effect<void>;
|
|
882
1101
|
}
|
|
883
|
-
|
|
884
|
-
|
|
885
|
-
|
|
886
|
-
|
|
887
|
-
|
|
888
|
-
|
|
889
|
-
|
|
890
|
-
|
|
891
|
-
|
|
892
|
-
|
|
893
|
-
|
|
894
|
-
|
|
895
|
-
|
|
896
|
-
|
|
897
|
-
|
|
898
|
-
|
|
899
|
-
* callback exceeds the platform timeout (currently documented as 30 seconds).
|
|
900
|
-
* This safe default resolves the callback with the Effect `Exit` for typed
|
|
901
|
-
* Effect failures and resumes that `Exit` afterward, so typed failures remain
|
|
902
|
-
* ordinary Effect failures instead of resetting the Durable Object. Defects
|
|
903
|
-
* and interruptions still reject the callback.
|
|
904
|
-
*/
|
|
905
|
-
blockConcurrencyWhile<A, E, R>(effect: Effect.Effect<A, E, R>): Effect.Effect<A, E, R>;
|
|
1102
|
+
declare const WorkerContext_base: Context.ServiceClass<WorkerContext, "effect-cf/WorkerContext", WorkerContextService>;
|
|
1103
|
+
declare class WorkerContext extends WorkerContext_base {}
|
|
1104
|
+
declare const NativeRequest_base: Context.ServiceClass<NativeRequest, "effect-cf/NativeRequest", Request<unknown, CfProperties<unknown>>>;
|
|
1105
|
+
declare class NativeRequest extends NativeRequest_base {}
|
|
1106
|
+
declare const isWebSocketUpgrade: (request: Request) => boolean;
|
|
1107
|
+
type ReservedMethodName$3 = ReservedMethodName$6 | "fetch" | "connect" | "queue" | "scheduled" | "tail" | "tailStream" | "test" | "trace" | "alarm" | "webSocketMessage" | "webSocketClose" | "webSocketError";
|
|
1108
|
+
type WorkerBaseContext<ROut> = ExecutionContext | WorkerContext | WorkerEnvironment | ROut;
|
|
1109
|
+
type WorkerFetchContext<ROut> = WorkerBaseContext<ROut> | NativeRequest | HttpServerRequest.HttpServerRequest | Scope.Scope;
|
|
1110
|
+
type WorkerRpcContext<ROut> = WorkerBaseContext<ROut> | Scope.Scope;
|
|
1111
|
+
type WorkerFetchSuccess = Response | HttpServerResponse.HttpServerResponse;
|
|
1112
|
+
type WorkerHandler<ROut, A = WorkerFetchSuccess> = Effect.Effect<A, unknown, WorkerFetchContext<ROut>>;
|
|
1113
|
+
type WorkerRpcHandler<ROut, A = unknown> = Effect.Effect<A, unknown, WorkerRpcContext<ROut>>;
|
|
1114
|
+
type WorkerRpc<ROut> = Record<string, (...args: Array<any>) => WorkerRpcHandler<ROut>>;
|
|
1115
|
+
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 };
|
|
1116
|
+
type RpcHandlers$1<ROut, Api> = { readonly [Key in keyof Api as Key extends keyof WorkerEntrypoint ? never : Key extends string ? Key extends ReservedMethodName$3 ? 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 };
|
|
1117
|
+
interface WorkerOptions<RRuntime, REvent = never, EventLayerError = never, Rpc extends WorkerRpc<RRuntime | REvent> = Record<never, never>> {
|
|
906
1118
|
/**
|
|
907
|
-
*
|
|
908
|
-
* Effect failures reject the callback.
|
|
1119
|
+
* Layer provided around each Cloudflare event handled by this Worker.
|
|
909
1120
|
*
|
|
910
|
-
*
|
|
911
|
-
*
|
|
912
|
-
*
|
|
913
|
-
*/
|
|
914
|
-
blockConcurrencyWhileOrReset<A, E, R>(effect: Effect.Effect<A, E, R>): Effect.Effect<A, E, R>;
|
|
915
|
-
/** Accepts a websocket connection for hibernation-capable Durable Objects. */
|
|
916
|
-
acceptWebSocket(ws: DurableWebSocket, tags?: Array<string>): Effect.Effect<void>;
|
|
917
|
-
/** Lists active sockets, optionally filtered by tag. */
|
|
918
|
-
getWebSockets(tag?: string): Effect.Effect<Array<DurableWebSocket>>;
|
|
919
|
-
/** Configures automatic request/response handling for sockets. */
|
|
920
|
-
setWebSocketAutoResponse(pair?: WebSocketRequestResponsePair): Effect.Effect<void>;
|
|
921
|
-
/** Gets the configured websocket auto-response pair. */
|
|
922
|
-
getWebSocketAutoResponse: Effect.Effect<WebSocketRequestResponsePair | null>;
|
|
923
|
-
/** Timestamp of the last automatic websocket response for a socket. */
|
|
924
|
-
getWebSocketAutoResponseTimestamp(ws: DurableWebSocket): Effect.Effect<Date | null>;
|
|
925
|
-
/** Sets the timeout for hibernatable websocket events. */
|
|
926
|
-
setHibernatableWebSocketEventTimeout(timeoutMs?: number): Effect.Effect<void>;
|
|
927
|
-
/** Gets the timeout for hibernatable websocket events. */
|
|
928
|
-
getHibernatableWebSocketEventTimeout: Effect.Effect<number | null>;
|
|
929
|
-
/** Reads tags attached to a websocket. */
|
|
930
|
-
getTags(ws: DurableWebSocket): Effect.Effect<Array<string>>;
|
|
931
|
-
/**
|
|
932
|
-
* Forcibly resets the Durable Object. Cloudflare logs an uncaught Error using
|
|
933
|
-
* the optional reason, and the method is not available in `wrangler dev` local
|
|
934
|
-
* development according to the Durable Object State docs.
|
|
1121
|
+
* The layer is built inside the event's Effect scope and finalized when the
|
|
1122
|
+
* event effect completes. Use this for event-scoped resources such as OTLP
|
|
1123
|
+
* trace/log exporters that should flush at event completion.
|
|
935
1124
|
*/
|
|
936
|
-
|
|
1125
|
+
readonly eventLayer?: Layer.Layer<REvent, EventLayerError, WorkerBaseContext<RRuntime>>;
|
|
1126
|
+
readonly fetch?: Effect.Effect<WorkerFetchSuccess, unknown, WorkerFetchContext<RRuntime | REvent>>;
|
|
1127
|
+
readonly queue?: QueueHandler<RRuntime | REvent>;
|
|
1128
|
+
readonly rpc?: Rpc;
|
|
937
1129
|
}
|
|
938
|
-
|
|
939
|
-
|
|
940
|
-
|
|
941
|
-
|
|
942
|
-
|
|
943
|
-
|
|
944
|
-
|
|
945
|
-
|
|
946
|
-
|
|
1130
|
+
type FetchWorkerOptions<RRuntime, REvent = never, EventLayerError = never> = Omit<WorkerOptions<RRuntime, REvent, EventLayerError, Record<never, never>>, "rpc"> & {
|
|
1131
|
+
readonly rpc?: never;
|
|
1132
|
+
};
|
|
1133
|
+
type WorkerClass<Rpc extends WorkerRpc<ROut>, ROut> = new (ctx: globalThis.ExecutionContext, env: WorkerEnv) => WorkerEntrypoint<WorkerEnv> & {
|
|
1134
|
+
fetch(request: Request): Promise<Response>;
|
|
1135
|
+
queue(batch: globalThis.MessageBatch): Promise<void>;
|
|
1136
|
+
} & WorkerRpcShape<Rpc, ROut>;
|
|
1137
|
+
interface FetchHandler<Env extends WorkerEnv = WorkerEnv> {
|
|
1138
|
+
readonly fetch: (request: Request, env: Env, ctx: globalThis.ExecutionContext) => Promise<Response>;
|
|
1139
|
+
}
|
|
1140
|
+
declare const renderHttpResponse: <A extends HttpServerResponse.HttpServerResponse, E, R>(effect: Effect.Effect<A, E, R>) => Effect.Effect<Response, E, R>;
|
|
1141
|
+
declare function make$6<ROut, LayerError>(layer: Layer.Layer<ROut, LayerError, ExecutionContext | WorkerContext | WorkerEnvironment>, fetch: WorkerHandler<ROut>): WorkerClass<Record<never, never>, ROut>;
|
|
1142
|
+
declare function make$6<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>;
|
|
1143
|
+
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>;
|
|
1144
|
+
type ServiceFreeSchema$2 = Schema.Codec<any, any, never, never>;
|
|
1145
|
+
interface Method$3<Args extends ReadonlyArray<ServiceFreeSchema$2> = ReadonlyArray<ServiceFreeSchema$2>, Success extends ServiceFreeSchema$2 = ServiceFreeSchema$2> {
|
|
1146
|
+
readonly args: Args;
|
|
1147
|
+
readonly success: Success;
|
|
1148
|
+
}
|
|
1149
|
+
declare namespace Method$3 {
|
|
1150
|
+
export type Any = Method$3<ReadonlyArray<ServiceFreeSchema$2>, ServiceFreeSchema$2>;
|
|
1151
|
+
type ArgsFromSchemas<Args extends ReadonlyArray<ServiceFreeSchema$2>> = Args extends readonly [] ? [] : Args extends readonly [infer Head extends ServiceFreeSchema$2, ...infer Tail extends ReadonlyArray<ServiceFreeSchema$2>] ? [Schema.Schema.Type<Head>, ...ArgsFromSchemas<Tail>] : Array<Schema.Schema.Type<Args[number]>>;
|
|
1152
|
+
export type Args<Self extends Any> = ArgsFromSchemas<Self["args"]>;
|
|
1153
|
+
export type Success<Self extends Any> = Schema.Schema.Type<Self["success"]>;
|
|
1154
|
+
export {};
|
|
1155
|
+
}
|
|
1156
|
+
type Methods$2 = Record<string, Method$3.Any>;
|
|
1157
|
+
type NoReservedMethods$2<MethodsShape extends Methods$2> = Extract<keyof MethodsShape, ReservedMethodName$3> extends never ? MethodsShape : never;
|
|
1158
|
+
interface Definition$5<Id extends string = string, MethodsShape extends Methods$2 = Methods$2> {
|
|
1159
|
+
readonly id: Id;
|
|
1160
|
+
readonly methods: MethodsShape;
|
|
1161
|
+
}
|
|
1162
|
+
declare namespace Definition$5 {
|
|
1163
|
+
type Any = Definition$5<string, Methods$2>;
|
|
1164
|
+
}
|
|
1165
|
+
type ServerApi$3<Self extends Definition$5.Any> = { readonly [Key in keyof Self["methods"]]: (...args: Method$3.Args<Self["methods"][Key]>) => Promise<Method$3.Success<Self["methods"][Key]>> };
|
|
1166
|
+
type Api$2<Self extends Definition$5.Any> = Provider<ServerApi$3<Self>, ReservedMethodName$3>;
|
|
1167
|
+
type Handlers$2<ROut, Self extends Definition$5.Any> = { readonly [Key in keyof Self["methods"]]: (...args: Method$3.Args<Self["methods"][Key]>) => WorkerRpcHandler<ROut, Method$3.Success<Self["methods"][Key]>> };
|
|
1168
|
+
interface Options$4<ROut, Self extends Definition$5.Any, REvent = never, EventLayerError = never> extends Omit<WorkerOptions<ROut, REvent, EventLayerError, Handlers$2<ROut | REvent, Self>>, "rpc"> {
|
|
1169
|
+
readonly rpc: Handlers$2<ROut | REvent, Self>;
|
|
1170
|
+
}
|
|
1171
|
+
type LayerOptions$8 = LayerOptions$9;
|
|
1172
|
+
type TagClass$7<Self, Id extends string, MethodsShape extends Methods$2> = Context.ServiceClass<Self, Id, ServiceBindingEffectClient<Api$2<Definition$5<Id, MethodsShape>>, Definition$5<Id, MethodsShape>>> & ServiceBindingStaticClient<Self, Api$2<Definition$5<Id, MethodsShape>>, Definition$5<Id, MethodsShape>> & {
|
|
1173
|
+
readonly id: Id;
|
|
1174
|
+
readonly methods: MethodsShape;
|
|
1175
|
+
readonly make: <ROut, LayerError, REvent = never, EventLayerError = never>(layer: Layer.Layer<ROut, LayerError, ExecutionContext | WorkerContext | WorkerEnvironment>, options: Options$4<ROut, Definition$5<Id, MethodsShape>, REvent, EventLayerError>) => WorkerClass<Handlers$2<ROut | REvent, Definition$5<Id, MethodsShape>>, ROut | REvent>;
|
|
1176
|
+
readonly layer: (options: LayerOptions$8) => Layer.Layer<Self, BindingNotFoundError | BindingValidationError, WorkerEnvironment>;
|
|
1177
|
+
};
|
|
1178
|
+
type TagFactory$1 = <Self>() => <Id extends string, const MethodsShape extends Methods$2>(id: Id, methods: MethodsShape & NoReservedMethods$2<MethodsShape>) => TagClass$7<Self, Id, MethodsShape>;
|
|
1179
|
+
declare const Tag$8: TagFactory$1;
|
|
1180
|
+
declare const method$2: {
|
|
1181
|
+
<Success extends ServiceFreeSchema$2>(definition: {
|
|
1182
|
+
readonly success: Success;
|
|
1183
|
+
}): Method$3<readonly [], Success>;
|
|
1184
|
+
<const Args extends readonly ServiceFreeSchema$2[], Success extends ServiceFreeSchema$2>(definition: {
|
|
1185
|
+
readonly args: Args;
|
|
1186
|
+
readonly success: Success;
|
|
1187
|
+
}): Method$3<Args, Success>;
|
|
1188
|
+
};
|
|
1189
|
+
declare const implement$4: <ROut, const Self extends Definition$5.Any>(_definition: Self, handlers: Handlers$2<ROut, Self>) => Handlers$2<ROut, Self>;
|
|
1190
|
+
type HandlerEffect$2<ROut, Self extends Definition$5.Any, Key extends keyof Self["methods"]> = WorkerRpcHandler<ROut, Method$3.Success<Self["methods"][Key]>>;
|
|
947
1191
|
declare namespace DurableObjectNamespace_d_exports {
|
|
948
|
-
export { DurableObjectFetchError, DurableObjectNamespaceBindingDefinition, DurableObjectNamespaceClient, DurableObjectNamespaceDefinition, DurableObjectNamespaceEffectClient, DurableObjectNamespaceStaticClient, DurableObjectRpcError, DurableObjectStubClient, isDurableObjectNamespaceClient, layer$
|
|
1192
|
+
export { DurableObjectFetchError, DurableObjectNamespaceBindingDefinition, DurableObjectNamespaceClient, DurableObjectNamespaceDefinition, DurableObjectNamespaceEffectClient, DurableObjectNamespaceStaticClient, DurableObjectRpcError, DurableObjectStubClient, isDurableObjectNamespaceClient, layer$6 as layer, makeClient$4 as makeClient, makeDirectMethods };
|
|
949
1193
|
}
|
|
950
1194
|
interface DurableObjectFetcher {
|
|
951
1195
|
fetch(input: RequestInfo | URL, init?: RequestInit): Promise<Response>;
|
|
@@ -1144,7 +1388,7 @@ type DurableObjectNamespaceStaticClient<R, Api extends object, Definition extend
|
|
|
1144
1388
|
};
|
|
1145
1389
|
declare const isDurableObjectNamespaceClient: <Api extends object>(value: unknown) => value is DurableObjectNamespaceClient<Api>;
|
|
1146
1390
|
declare const makeClient$4: <Api extends object, const Definition extends Definition$4.Any | undefined = undefined>(definition: DurableObjectNamespaceBindingDefinition<Definition>) => ((namespace: DurableObjectNamespaceClient<Api>) => DurableObjectNamespaceEffectClient<Api, Definition>);
|
|
1147
|
-
declare const layer$
|
|
1391
|
+
declare const layer$6: <Self, Api extends object, const Definition extends Definition$4.Any | undefined = undefined>(tag: Context.Service<Self, DurableObjectNamespaceEffectClient<Api, Definition>>, definition: DurableObjectNamespaceBindingDefinition<Definition>) => _$effect_Layer0.Layer<Self, BindingNotFoundError | BindingValidationError, WorkerEnvironment>;
|
|
1148
1392
|
declare const makeDirectMethods: <R, Api extends object, Definition extends Definition$4.Any | undefined>(rpcDefinition: Definition | undefined, helpers: {
|
|
1149
1393
|
readonly call: StubCall<R, Api>;
|
|
1150
1394
|
readonly fetch: (stub: DurableObjectStubClient<Api>, input: RequestInfo | URL, init?: RequestInit) => Effect.Effect<globalThis.Response, DurableObjectFetchError, R>;
|
|
@@ -1152,7 +1396,7 @@ declare const makeDirectMethods: <R, Api extends object, Definition extends Defi
|
|
|
1152
1396
|
readonly getByName: (name: string, options?: globalThis.DurableObjectNamespaceGetDurableObjectOptions) => Effect.Effect<DurableObjectStubClient<Api>, never, R>;
|
|
1153
1397
|
}) => DirectMethods<R, Api, Definition>;
|
|
1154
1398
|
declare namespace DurableObjectDefinition_d_exports {
|
|
1155
|
-
export { Api$1 as Api, Definition$4 as Definition, DurableObject$1 as DurableObject, HandlerEffect$1 as HandlerEffect, Handlers$1 as Handlers, LayerOptions$
|
|
1399
|
+
export { Api$1 as Api, Definition$4 as Definition, DurableObject$1 as DurableObject, HandlerEffect$1 as HandlerEffect, Handlers$1 as Handlers, LayerOptions$7 as LayerOptions, Method$2 as Method, Methods$1 as Methods, NoReservedMethods$1 as NoReservedMethods, Options$3 as Options, ReservedMethodName$1 as ReservedMethodName, ServerApi$2 as ServerApi, ServiceFreeSchema$1 as ServiceFreeSchema, Tag$7 as Tag, TagClass$6 as TagClass, implement$3 as implement, make$5 as make, method$1 as method };
|
|
1156
1400
|
}
|
|
1157
1401
|
type ServiceFreeSchema$1 = Schema.Codec<any, any, never, never>;
|
|
1158
1402
|
interface Method$2<Args extends ReadonlyArray<ServiceFreeSchema$1> = ReadonlyArray<ServiceFreeSchema$1>, Success extends ServiceFreeSchema$1 = ServiceFreeSchema$1> {
|
|
@@ -1194,17 +1438,17 @@ type Handlers$1<ROut, Self extends Definition$4.Any> = { readonly [Key in keyof
|
|
|
1194
1438
|
/**
|
|
1195
1439
|
* Durable Object constructor options for a specific RPC definition.
|
|
1196
1440
|
*/
|
|
1197
|
-
interface Options$3<ROut, Self extends Definition$4.Any> extends Omit<DurableObjectOptions<ROut, Handlers$1<ROut, Self>>, "rpc"> {
|
|
1198
|
-
readonly rpc: Handlers$1<ROut, Self>;
|
|
1441
|
+
interface Options$3<ROut, Self extends Definition$4.Any, REvent = never, EventLayerError = never> extends Omit<DurableObjectOptions<ROut, REvent, EventLayerError, Handlers$1<ROut | REvent, Self>>, "rpc"> {
|
|
1442
|
+
readonly rpc: Handlers$1<ROut | REvent, Self>;
|
|
1199
1443
|
}
|
|
1200
|
-
type LayerOptions$
|
|
1444
|
+
type LayerOptions$7 = {
|
|
1201
1445
|
readonly binding: string;
|
|
1202
1446
|
};
|
|
1203
1447
|
type TagClass$6<Self, Id extends string, MethodsShape extends Methods$1> = Context.ServiceClass<Self, Id, DurableObjectNamespaceEffectClient<Api$1<Definition$4<Id, MethodsShape>>, Definition$4<Id, MethodsShape>>> & DurableObjectNamespaceStaticClient<Self, Api$1<Definition$4<Id, MethodsShape>>, Definition$4<Id, MethodsShape>> & {
|
|
1204
1448
|
readonly id: Id;
|
|
1205
1449
|
readonly methods: MethodsShape;
|
|
1206
|
-
readonly make: <ROut, LayerError>(layer: Layer.Layer<ROut, LayerError, DurableObjectState | WorkerEnvironment>, options: Options$3<ROut, Definition$4<Id, MethodsShape
|
|
1207
|
-
readonly layer: (options: LayerOptions$
|
|
1450
|
+
readonly make: <ROut, LayerError, REvent = never, EventLayerError = never>(layer: Layer.Layer<ROut, LayerError, DurableObjectState | WorkerEnvironment>, options: Options$3<ROut, Definition$4<Id, MethodsShape>, REvent, EventLayerError>) => DurableObjectClass<Handlers$1<ROut | REvent, Definition$4<Id, MethodsShape>>, ROut | REvent>;
|
|
1451
|
+
readonly layer: (options: LayerOptions$7) => Layer.Layer<Self, BindingNotFoundError | BindingValidationError, WorkerEnvironment>;
|
|
1208
1452
|
};
|
|
1209
1453
|
/**
|
|
1210
1454
|
* Defines a single RPC method schema in a Durable Object definition.
|
|
@@ -1218,7 +1462,7 @@ declare const method$1: {
|
|
|
1218
1462
|
readonly success: Success;
|
|
1219
1463
|
}): Method$2<Args, Success>;
|
|
1220
1464
|
};
|
|
1221
|
-
declare const make$
|
|
1465
|
+
declare const make$5: <Id extends string, const MethodsShape extends Methods$1>(id: Id, methods: MethodsShape & NoReservedMethods$1<MethodsShape>) => TagClass$6<Definition$4<Id, MethodsShape>, Id, MethodsShape>;
|
|
1222
1466
|
declare const Tag$7: <Self>() => <Id extends string, const MethodsShape extends Methods$1>(id: Id, methods: MethodsShape & NoReservedMethods$1<MethodsShape>) => TagClass$6<Self, Id, MethodsShape>;
|
|
1223
1467
|
declare const DurableObject$1: <Self>() => <Id extends string, const MethodsShape extends Methods$1>(id: Id, methods: MethodsShape & NoReservedMethods$1<MethodsShape>) => TagClass$6<Self, Id, MethodsShape>;
|
|
1224
1468
|
/**
|
|
@@ -1230,7 +1474,7 @@ declare const implement$3: <ROut, const Self extends Definition$4.Any>(_definiti
|
|
|
1230
1474
|
*/
|
|
1231
1475
|
type HandlerEffect$1<ROut, Self extends Definition$4.Any, Key extends keyof Self["methods"]> = DurableObjectHandler<ROut, Method$2.Success<Self["methods"][Key]>>;
|
|
1232
1476
|
declare namespace DurableObject_d_exports {
|
|
1233
|
-
export { Api, Definition$3 as Definition, DurableObjectClass, DurableObjectHandler, DurableObjectOptions, DurableObjectRpc, DurableObjectRpcShape, HandlerEffect, Handlers, LayerOptions$
|
|
1477
|
+
export { Api, Definition$3 as Definition, DurableObjectClass, DurableObjectHandler, DurableObjectOptions, DurableObjectRpc, DurableObjectRpcShape, HandlerEffect, Handlers, LayerOptions$6 as LayerOptions, Method$1 as Method, Methods, NoReservedMethods, Options$2 as Options, ReservedMethodName, RpcHandlers, ServerApi$1 as ServerApi, ServiceFreeSchema, Tag$6 as Tag, TagClass$5 as TagClass, TagFactory, implement$2 as implement, make$4 as make, method };
|
|
1234
1478
|
}
|
|
1235
1479
|
type RuntimeContext$1<ROut> = DurableObjectState | WorkerEnvironment | ROut;
|
|
1236
1480
|
type HandlerContext<ROut> = RuntimeContext$1<ROut> | Scope.Scope;
|
|
@@ -1248,7 +1492,15 @@ type RpcHandlers<ROut, Api> = { readonly [Key in keyof Api as Key extends keyof
|
|
|
1248
1492
|
/**
|
|
1249
1493
|
* Options for creating a Durable Object class backed by Effect handlers.
|
|
1250
1494
|
*/
|
|
1251
|
-
interface DurableObjectOptions<
|
|
1495
|
+
interface DurableObjectOptions<RRuntime, REvent = never, EventLayerError = never, Rpc extends DurableObjectRpc<RRuntime | REvent> = Record<never, never>> {
|
|
1496
|
+
/**
|
|
1497
|
+
* Layer provided around each Cloudflare event handled by this Durable Object.
|
|
1498
|
+
*
|
|
1499
|
+
* The layer is built inside the event's Effect scope and finalized when the
|
|
1500
|
+
* event effect completes. It is not applied to `initialize`, which is an
|
|
1501
|
+
* instance-load lifecycle hook rather than a platform event.
|
|
1502
|
+
*/
|
|
1503
|
+
readonly eventLayer?: Layer.Layer<REvent, EventLayerError, DurableObjectState | WorkerEnvironment | RRuntime>;
|
|
1252
1504
|
/**
|
|
1253
1505
|
* Effect run when Cloudflare loads this Durable Object instance into memory.
|
|
1254
1506
|
*
|
|
@@ -1257,11 +1509,11 @@ interface DurableObjectOptions<ROut, Rpc extends DurableObjectRpc<ROut>> {
|
|
|
1257
1509
|
* the same Durable Object id again after eviction or restart; use Durable
|
|
1258
1510
|
* Object storage if work must happen only once per id.
|
|
1259
1511
|
*/
|
|
1260
|
-
readonly initialize?: Effect.Effect<void, unknown, HandlerContext<
|
|
1512
|
+
readonly initialize?: Effect.Effect<void, unknown, HandlerContext<RRuntime>>;
|
|
1261
1513
|
/** Optional RPC methods exposed as Durable Object instance methods. */
|
|
1262
1514
|
readonly rpc?: Rpc;
|
|
1263
1515
|
/** Optional fetch handler for HTTP/WebSocket requests. */
|
|
1264
|
-
readonly fetch?: Effect.Effect<Response, unknown, FetchContext<
|
|
1516
|
+
readonly fetch?: Effect.Effect<Response, unknown, FetchContext<RRuntime | REvent>>;
|
|
1265
1517
|
/**
|
|
1266
1518
|
* Optional logical alarm processing effect.
|
|
1267
1519
|
*
|
|
@@ -1269,11 +1521,11 @@ interface DurableObjectOptions<ROut, Rpc extends DurableObjectRpc<ROut>> {
|
|
|
1269
1521
|
* `DurableObjectAlarm.processDue(...)` so the reusable scheduler stays inside
|
|
1270
1522
|
* the Durable Object's single managed runtime boundary.
|
|
1271
1523
|
*/
|
|
1272
|
-
readonly alarms?: Effect.Effect<unknown, unknown, HandlerContext<
|
|
1273
|
-
readonly alarm?: (alarmInfo?: globalThis.AlarmInvocationInfo) => Effect.Effect<void, unknown, HandlerContext<
|
|
1274
|
-
readonly webSocketMessage?: (socket: DurableWebSocket, message: string | ArrayBuffer) => Effect.Effect<void, unknown, HandlerContext<
|
|
1275
|
-
readonly webSocketClose?: (socket: DurableWebSocket, code: number, reason: string, wasClean: boolean) => Effect.Effect<void, unknown, HandlerContext<
|
|
1276
|
-
readonly webSocketError?: (socket: DurableWebSocket, error: unknown) => Effect.Effect<void, unknown, HandlerContext<
|
|
1524
|
+
readonly alarms?: Effect.Effect<unknown, unknown, HandlerContext<RRuntime | REvent>>;
|
|
1525
|
+
readonly alarm?: (alarmInfo?: globalThis.AlarmInvocationInfo) => Effect.Effect<void, unknown, HandlerContext<RRuntime | REvent>>;
|
|
1526
|
+
readonly webSocketMessage?: (socket: DurableWebSocket, message: string | ArrayBuffer) => Effect.Effect<void, unknown, HandlerContext<RRuntime | REvent>>;
|
|
1527
|
+
readonly webSocketClose?: (socket: DurableWebSocket, code: number, reason: string, wasClean: boolean) => Effect.Effect<void, unknown, HandlerContext<RRuntime | REvent>>;
|
|
1528
|
+
readonly webSocketError?: (socket: DurableWebSocket, error: unknown) => Effect.Effect<void, unknown, HandlerContext<RRuntime | REvent>>;
|
|
1277
1529
|
}
|
|
1278
1530
|
/**
|
|
1279
1531
|
* Cloudflare `DurableObject` constructor produced by {@link make}.
|
|
@@ -1282,7 +1534,7 @@ type DurableObjectClass<Rpc extends DurableObjectRpc<ROut>, ROut> = new (state:
|
|
|
1282
1534
|
/**
|
|
1283
1535
|
* Creates a Durable Object class backed by a single managed Effect runtime.
|
|
1284
1536
|
*/
|
|
1285
|
-
declare const make$
|
|
1537
|
+
declare const make$4: <ROut, LayerError, REvent = never, EventLayerError = never, const Rpc extends DurableObjectRpc<ROut | REvent> = Record<never, never>>(layer: Layer.Layer<ROut, LayerError, DurableObjectState | WorkerEnvironment>, options?: DurableObjectOptions<ROut, REvent, EventLayerError, Rpc>) => DurableObjectClass<Rpc, ROut | REvent>;
|
|
1286
1538
|
type ServiceFreeSchema = Schema.Codec<any, any, never, never>;
|
|
1287
1539
|
interface Method$1<Args extends ReadonlyArray<ServiceFreeSchema> = ReadonlyArray<ServiceFreeSchema>, Success extends ServiceFreeSchema = ServiceFreeSchema> {
|
|
1288
1540
|
readonly args: Args;
|
|
@@ -1305,18 +1557,18 @@ interface Definition$3<Id extends string = string, MethodsShape extends Methods
|
|
|
1305
1557
|
declare namespace Definition$3 {
|
|
1306
1558
|
type Any = Definition$3<string, Methods>;
|
|
1307
1559
|
}
|
|
1308
|
-
type LayerOptions$
|
|
1560
|
+
type LayerOptions$6 = LayerOptions$7;
|
|
1309
1561
|
type ServerApi$1<Self extends Definition$3.Any> = { readonly [Key in keyof Self["methods"]]: (...args: Method$1.Args<Self["methods"][Key]>) => Promise<Method$1.Success<Self["methods"][Key]>> };
|
|
1310
1562
|
type Api<Self extends Definition$3.Any> = Provider<ServerApi$1<Self>, ReservedMethodName>;
|
|
1311
1563
|
type Handlers<ROut, Self extends Definition$3.Any> = { readonly [Key in keyof Self["methods"]]: (...args: Method$1.Args<Self["methods"][Key]>) => DurableObjectHandler<ROut, Method$1.Success<Self["methods"][Key]>> };
|
|
1312
|
-
interface Options$2<ROut, Self extends Definition$3.Any> extends Omit<DurableObjectOptions<ROut, Handlers<ROut, Self>>, "rpc"> {
|
|
1313
|
-
readonly rpc: Handlers<ROut, Self>;
|
|
1564
|
+
interface Options$2<ROut, Self extends Definition$3.Any, REvent = never, EventLayerError = never> extends Omit<DurableObjectOptions<ROut, REvent, EventLayerError, Handlers<ROut | REvent, Self>>, "rpc"> {
|
|
1565
|
+
readonly rpc: Handlers<ROut | REvent, Self>;
|
|
1314
1566
|
}
|
|
1315
1567
|
type TagClass$5<Self, Id extends string, MethodsShape extends Methods> = Context.ServiceClass<Self, Id, DurableObjectNamespaceEffectClient<Api<Definition$3<Id, MethodsShape>>, Definition$3<Id, MethodsShape>>> & DurableObjectNamespaceStaticClient<Self, Api<Definition$3<Id, MethodsShape>>, Definition$3<Id, MethodsShape>> & {
|
|
1316
1568
|
readonly id: Id;
|
|
1317
1569
|
readonly methods: MethodsShape;
|
|
1318
|
-
readonly make: <ROut, LayerError>(layer: Layer.Layer<ROut, LayerError, DurableObjectState | WorkerEnvironment>, options: Options$2<ROut, Definition$3<Id, MethodsShape
|
|
1319
|
-
readonly layer: (options: LayerOptions$
|
|
1570
|
+
readonly make: <ROut, LayerError, REvent = never, EventLayerError = never>(layer: Layer.Layer<ROut, LayerError, DurableObjectState | WorkerEnvironment>, options: Options$2<ROut, Definition$3<Id, MethodsShape>, REvent, EventLayerError>) => DurableObjectClass<Handlers<ROut | REvent, Definition$3<Id, MethodsShape>>, ROut | REvent>;
|
|
1571
|
+
readonly layer: (options: LayerOptions$6) => Layer.Layer<Self, BindingNotFoundError | BindingValidationError, WorkerEnvironment>;
|
|
1320
1572
|
};
|
|
1321
1573
|
type TagFactory = <Self>() => <Id extends string, const MethodsShape extends Methods>(id: Id, methods: MethodsShape & NoReservedMethods<MethodsShape>) => TagClass$5<Self, Id, MethodsShape>;
|
|
1322
1574
|
declare const Tag$6: TagFactory;
|
|
@@ -1331,258 +1583,6 @@ declare const method: {
|
|
|
1331
1583
|
};
|
|
1332
1584
|
declare const implement$2: <ROut, const Self extends Definition$3.Any>(_definition: Self, handlers: Handlers<ROut, Self>) => Handlers<ROut, Self>;
|
|
1333
1585
|
type HandlerEffect<ROut, Self extends Definition$3.Any, Key extends keyof Self["methods"]> = DurableObjectHandler<ROut, Method$1.Success<Self["methods"][Key]>>;
|
|
1334
|
-
declare namespace CloudflareOtlp_d_exports {
|
|
1335
|
-
export { CloudflareOtlpSettings, DurableObjectResourceOptions, LayerOptions$6 as LayerOptions, ResourceOptions, Serialization, Settings, Signal, WorkerResourceOptions, durableObjectLayer, instrumentDurableObjectOptions, instrumentWorkerOptions, layer$6 as layer, layerJson, layerProtobuf, settingsConfig, settingsLayer, workerLayer };
|
|
1336
|
-
}
|
|
1337
|
-
/** Telemetry signal groups supported by the Cloudflare OTLP layers. */
|
|
1338
|
-
type Signal = "logs" | "traces" | "metrics";
|
|
1339
|
-
/** OTLP payload serialization used by the Effect OTLP exporters. */
|
|
1340
|
-
type Serialization = "json" | "protobuf";
|
|
1341
|
-
/**
|
|
1342
|
-
* Resolved OpenTelemetry settings used by the Cloudflare OTLP layers.
|
|
1343
|
-
*
|
|
1344
|
-
* The default {@link settingsLayer} reads the standard OpenTelemetry
|
|
1345
|
-
* environment variable names from `WorkerEnvironment`. Applications that use
|
|
1346
|
-
* different binding names can provide {@link CloudflareOtlpSettings} directly
|
|
1347
|
-
* with a custom layer.
|
|
1348
|
-
*/
|
|
1349
|
-
interface Settings {
|
|
1350
|
-
/** Generic OTLP base endpoint, read from `OTEL_EXPORTER_OTLP_ENDPOINT`. */
|
|
1351
|
-
readonly endpoint: Option.Option<string>;
|
|
1352
|
-
/** Logs-specific OTLP endpoint, read from `OTEL_EXPORTER_OTLP_LOGS_ENDPOINT`. */
|
|
1353
|
-
readonly logsEndpoint: Option.Option<string>;
|
|
1354
|
-
/** Traces-specific OTLP endpoint, read from `OTEL_EXPORTER_OTLP_TRACES_ENDPOINT`. */
|
|
1355
|
-
readonly tracesEndpoint: Option.Option<string>;
|
|
1356
|
-
/** Metrics-specific OTLP endpoint, read from `OTEL_EXPORTER_OTLP_METRICS_ENDPOINT`. */
|
|
1357
|
-
readonly metricsEndpoint: Option.Option<string>;
|
|
1358
|
-
/** Comma-separated OTLP headers, read from `OTEL_EXPORTER_OTLP_HEADERS`. */
|
|
1359
|
-
readonly headers: Option.Option<string>;
|
|
1360
|
-
/** Logs-specific OTLP headers, read from `OTEL_EXPORTER_OTLP_LOGS_HEADERS`. */
|
|
1361
|
-
readonly logsHeaders: Option.Option<string>;
|
|
1362
|
-
/** Traces-specific OTLP headers, read from `OTEL_EXPORTER_OTLP_TRACES_HEADERS`. */
|
|
1363
|
-
readonly tracesHeaders: Option.Option<string>;
|
|
1364
|
-
/** Metrics-specific OTLP headers, read from `OTEL_EXPORTER_OTLP_METRICS_HEADERS`. */
|
|
1365
|
-
readonly metricsHeaders: Option.Option<string>;
|
|
1366
|
-
/** Service name, read from `OTEL_SERVICE_NAME`. */
|
|
1367
|
-
readonly serviceName: Option.Option<string>;
|
|
1368
|
-
/** Service version, read from the effect-cf convenience alias `OTEL_SERVICE_VERSION`. */
|
|
1369
|
-
readonly serviceVersion: Option.Option<string>;
|
|
1370
|
-
/** Resource attributes, read from `OTEL_RESOURCE_ATTRIBUTES`. */
|
|
1371
|
-
readonly resourceAttributes: Option.Option<Record<string, string>>;
|
|
1372
|
-
}
|
|
1373
|
-
/**
|
|
1374
|
-
* Supported OpenTelemetry environment configuration for Cloudflare OTLP export.
|
|
1375
|
-
*
|
|
1376
|
-
* This config intentionally uses the conventional `OTEL_*` variable names so
|
|
1377
|
-
* deployments can share the same settings used by other OpenTelemetry SDKs.
|
|
1378
|
-
* It covers the OTLP HTTP settings supported by the Effect OTLP layers:
|
|
1379
|
-
*
|
|
1380
|
-
* - `OTEL_EXPORTER_OTLP_ENDPOINT`
|
|
1381
|
-
* - `OTEL_EXPORTER_OTLP_LOGS_ENDPOINT`
|
|
1382
|
-
* - `OTEL_EXPORTER_OTLP_TRACES_ENDPOINT`
|
|
1383
|
-
* - `OTEL_EXPORTER_OTLP_METRICS_ENDPOINT`
|
|
1384
|
-
* - `OTEL_EXPORTER_OTLP_HEADERS`
|
|
1385
|
-
* - `OTEL_EXPORTER_OTLP_LOGS_HEADERS`
|
|
1386
|
-
* - `OTEL_EXPORTER_OTLP_TRACES_HEADERS`
|
|
1387
|
-
* - `OTEL_EXPORTER_OTLP_METRICS_HEADERS`
|
|
1388
|
-
* - `OTEL_SERVICE_NAME`
|
|
1389
|
-
* - `OTEL_RESOURCE_ATTRIBUTES`
|
|
1390
|
-
*
|
|
1391
|
-
* `OTEL_SERVICE_VERSION` is also accepted as an effect-cf convenience alias.
|
|
1392
|
-
* The standard OpenTelemetry way to configure service version is
|
|
1393
|
-
* `OTEL_RESOURCE_ATTRIBUTES=service.version=...`.
|
|
1394
|
-
*
|
|
1395
|
-
* Consumers with non-standard binding names should map those names into
|
|
1396
|
-
* {@link CloudflareOtlpSettings} rather than changing this config globally.
|
|
1397
|
-
*/
|
|
1398
|
-
declare const settingsConfig: Config.Config<{
|
|
1399
|
-
endpoint: Option.Option<string>;
|
|
1400
|
-
logsEndpoint: Option.Option<string>;
|
|
1401
|
-
tracesEndpoint: Option.Option<string>;
|
|
1402
|
-
metricsEndpoint: Option.Option<string>;
|
|
1403
|
-
headers: Option.Option<string>;
|
|
1404
|
-
logsHeaders: Option.Option<string>;
|
|
1405
|
-
tracesHeaders: Option.Option<string>;
|
|
1406
|
-
metricsHeaders: Option.Option<string>;
|
|
1407
|
-
serviceName: Option.Option<string>;
|
|
1408
|
-
serviceVersion: Option.Option<string>;
|
|
1409
|
-
resourceAttributes: Option.Option<{
|
|
1410
|
-
readonly [x: string]: string;
|
|
1411
|
-
}>;
|
|
1412
|
-
}>;
|
|
1413
|
-
declare const CloudflareOtlpSettings_base: Context.ServiceClass<CloudflareOtlpSettings, "effect-cf/CloudflareOtlpSettings", Settings>;
|
|
1414
|
-
/**
|
|
1415
|
-
* Service carrying already-resolved Cloudflare OTLP settings.
|
|
1416
|
-
*
|
|
1417
|
-
* Provide this service directly when an application needs to map custom
|
|
1418
|
-
* Cloudflare binding names, compute settings dynamically, or override settings
|
|
1419
|
-
* in tests. When this service is present, the OTLP layers use it instead of
|
|
1420
|
-
* reading {@link settingsConfig}.
|
|
1421
|
-
*
|
|
1422
|
-
* @example
|
|
1423
|
-
* ```ts
|
|
1424
|
-
* const CustomOtlpSettings = Layer.effect(
|
|
1425
|
-
* CloudflareOtlp.CloudflareOtlpSettings,
|
|
1426
|
-
* Config.all({
|
|
1427
|
-
* ...CloudflareOtlp.settingsConfig,
|
|
1428
|
-
* endpoint: Config.string("MY_OTLP_ENDPOINT").pipe(Config.option),
|
|
1429
|
-
* }),
|
|
1430
|
-
* ).pipe(Layer.provide(WorkerConfig.layer));
|
|
1431
|
-
* ```
|
|
1432
|
-
*/
|
|
1433
|
-
declare class CloudflareOtlpSettings extends CloudflareOtlpSettings_base {}
|
|
1434
|
-
/** Resource metadata shared by Worker and Durable Object OTLP layers. */
|
|
1435
|
-
interface ResourceOptions {
|
|
1436
|
-
/** Explicit service name. Overrides `OTEL_SERVICE_NAME` when provided. */
|
|
1437
|
-
readonly serviceName?: string;
|
|
1438
|
-
/** Explicit service version. Overrides `OTEL_SERVICE_VERSION` when provided. */
|
|
1439
|
-
readonly serviceVersion?: string;
|
|
1440
|
-
/** Additional resource attributes attached to all exported telemetry. */
|
|
1441
|
-
readonly attributes?: Record<string, unknown>;
|
|
1442
|
-
}
|
|
1443
|
-
/** Resource metadata specific to Cloudflare Workers. */
|
|
1444
|
-
interface WorkerResourceOptions extends ResourceOptions {
|
|
1445
|
-
/** Cloudflare Worker name to attach as `cloudflare.worker.name`. */
|
|
1446
|
-
readonly workerName?: string;
|
|
1447
|
-
}
|
|
1448
|
-
/** Resource metadata specific to Cloudflare Durable Objects. */
|
|
1449
|
-
interface DurableObjectResourceOptions extends ResourceOptions {
|
|
1450
|
-
/** Durable Object class name to attach as `cloudflare.durable_object.class`. */
|
|
1451
|
-
readonly className?: string;
|
|
1452
|
-
/**
|
|
1453
|
-
* Include the Durable Object id as `cloudflare.durable_object.id`.
|
|
1454
|
-
*
|
|
1455
|
-
* This is disabled by default because object ids can be high-cardinality.
|
|
1456
|
-
*/
|
|
1457
|
-
readonly includeObjectId?: boolean;
|
|
1458
|
-
}
|
|
1459
|
-
/** Options shared by all Cloudflare OTLP telemetry layers. */
|
|
1460
|
-
interface LayerOptions$6 extends ResourceOptions {
|
|
1461
|
-
/** Telemetry signals to export. Defaults to logs, traces, and metrics. */
|
|
1462
|
-
readonly signals?: ReadonlyArray<Signal>;
|
|
1463
|
-
/** OTLP payload serialization. Defaults to protobuf. */
|
|
1464
|
-
readonly serialization?: Serialization;
|
|
1465
|
-
/** Maximum batch size for log and trace exporters. */
|
|
1466
|
-
readonly maxBatchSize?: number;
|
|
1467
|
-
/** Maximum time to wait for exporter shutdown/flush when a scope closes. */
|
|
1468
|
-
readonly shutdownTimeout?: Duration$1.Input;
|
|
1469
|
-
/** Export interval for the logs exporter. */
|
|
1470
|
-
readonly loggerExportInterval?: Duration$1.Input;
|
|
1471
|
-
/** Exclude log records emitted for spans when exporting logs. */
|
|
1472
|
-
readonly loggerExcludeLogSpans?: boolean;
|
|
1473
|
-
/** Merge the OTLP logger with existing loggers instead of replacing them. */
|
|
1474
|
-
readonly loggerMergeWithExisting?: boolean;
|
|
1475
|
-
/** Export interval for the traces exporter. */
|
|
1476
|
-
readonly tracerExportInterval?: Duration$1.Input;
|
|
1477
|
-
/** Custom trace context lookup used by the Effect OTLP tracer. */
|
|
1478
|
-
readonly tracerContext?: <X>(primitive: Tracer.EffectPrimitive<X>, span: Tracer.AnySpan) => X;
|
|
1479
|
-
/** Export interval for the metrics exporter. */
|
|
1480
|
-
readonly metricsExportInterval?: Duration$1.Input;
|
|
1481
|
-
/** Aggregation temporality for exported metrics. */
|
|
1482
|
-
readonly metricsTemporality?: OtlpMetrics.AggregationTemporality;
|
|
1483
|
-
}
|
|
1484
|
-
/**
|
|
1485
|
-
* Layer that reads standard OpenTelemetry settings from the current Cloudflare
|
|
1486
|
-
* `env` object.
|
|
1487
|
-
*
|
|
1488
|
-
* The layer depends on {@link WorkerEnvironment} and installs a
|
|
1489
|
-
* Cloudflare-backed Effect `ConfigProvider`, so `settingsConfig` reads from
|
|
1490
|
-
* Worker vars/secrets instead of Node process environment variables.
|
|
1491
|
-
*/
|
|
1492
|
-
declare const settingsLayer: Layer.Layer<CloudflareOtlpSettings, Config.ConfigError, WorkerEnvironment>;
|
|
1493
|
-
/**
|
|
1494
|
-
* Base OTLP telemetry layer for Cloudflare-compatible runtimes.
|
|
1495
|
-
*
|
|
1496
|
-
* The layer reads {@link CloudflareOtlpSettings} when provided. Otherwise it
|
|
1497
|
-
* reads standard OpenTelemetry config from `WorkerEnvironment` when available,
|
|
1498
|
-
* then falls back to the ambient Effect `ConfigProvider`.
|
|
1499
|
-
*
|
|
1500
|
-
* When only `OTEL_EXPORTER_OTLP_ENDPOINT` is configured, per-signal paths are
|
|
1501
|
-
* derived by appending `/v1/logs`, `/v1/traces`, and `/v1/metrics`. Signal
|
|
1502
|
-
* specific endpoints are used as-is, matching the OpenTelemetry OTLP exporter
|
|
1503
|
-
* convention.
|
|
1504
|
-
*/
|
|
1505
|
-
declare const layer$6: (options?: LayerOptions$6) => Layer.Layer<never, never, never>;
|
|
1506
|
-
/** Base OTLP telemetry layer forced to JSON serialization. */
|
|
1507
|
-
declare const layerJson: (options?: Omit<LayerOptions$6, "serialization">) => Layer.Layer<never, never, never>;
|
|
1508
|
-
/** Base OTLP telemetry layer forced to protobuf serialization. */
|
|
1509
|
-
declare const layerProtobuf: (options?: Omit<LayerOptions$6, "serialization">) => Layer.Layer<never, never, never>;
|
|
1510
|
-
/**
|
|
1511
|
-
* OTLP layer with Cloudflare Worker resource attributes.
|
|
1512
|
-
*
|
|
1513
|
-
* Provide this layer at runtime scope for long-lived metrics aggregation, or at
|
|
1514
|
-
* handler scope when traces/logs should flush as the Cloudflare event finishes.
|
|
1515
|
-
*/
|
|
1516
|
-
declare const workerLayer: (options?: LayerOptions$6 & WorkerResourceOptions) => Layer.Layer<never, never, never>;
|
|
1517
|
-
/**
|
|
1518
|
-
* OTLP layer with Cloudflare Durable Object resource attributes.
|
|
1519
|
-
*
|
|
1520
|
-
* The layer reads {@link DurableObjectState} so it can optionally include the
|
|
1521
|
-
* Durable Object id. Prefer leaving `includeObjectId` disabled unless the
|
|
1522
|
-
* backend can tolerate high-cardinality resource attributes.
|
|
1523
|
-
*/
|
|
1524
|
-
declare const durableObjectLayer: (options?: LayerOptions$6 & DurableObjectResourceOptions) => Layer.Layer<never, never, DurableObjectState>;
|
|
1525
|
-
/**
|
|
1526
|
-
* Instrument Worker lifecycle handlers with event-scoped OTLP telemetry.
|
|
1527
|
-
*
|
|
1528
|
-
* Each defined handler is provided with {@link workerLayer}. Because Worker
|
|
1529
|
-
* handlers run inside `Effect.scoped`, the exporter scope closes and flushes at
|
|
1530
|
-
* the end of each Cloudflare event.
|
|
1531
|
-
*/
|
|
1532
|
-
declare const instrumentWorkerOptions: (options?: LayerOptions$6 & WorkerResourceOptions) => <ROut, Rpc extends WorkerRpc<ROut>>(handlers: WorkerOptions<ROut, Rpc>) => WorkerOptions<ROut | WorkerEnvironment | CloudflareOtlpSettings, Rpc>;
|
|
1533
|
-
/**
|
|
1534
|
-
* Instrument Durable Object lifecycle handlers with event-scoped OTLP telemetry.
|
|
1535
|
-
*
|
|
1536
|
-
* Each defined handler is provided with {@link durableObjectLayer}. Because
|
|
1537
|
-
* Durable Object handlers run inside `Effect.scoped`, the exporter scope closes
|
|
1538
|
-
* and flushes at the end of each Cloudflare event.
|
|
1539
|
-
*/
|
|
1540
|
-
declare const instrumentDurableObjectOptions: (options?: LayerOptions$6 & DurableObjectResourceOptions) => <ROut, Rpc extends DurableObjectRpc<ROut>>(handlers: DurableObjectOptions<ROut, Rpc>) => DurableObjectOptions<ROut | WorkerEnvironment | DurableObjectState | CloudflareOtlpSettings, Rpc>;
|
|
1541
|
-
declare namespace D1_d_exports {
|
|
1542
|
-
export { D1Definition, D1Service, D1SqlLayerOptions, Service, make$4 as make };
|
|
1543
|
-
}
|
|
1544
|
-
/** Typed D1 binding definition. */
|
|
1545
|
-
interface D1Definition {
|
|
1546
|
-
/** Binding name as configured in `wrangler.jsonc`. */
|
|
1547
|
-
readonly binding: string;
|
|
1548
|
-
}
|
|
1549
|
-
/** Options forwarded to `@effect/sql-d1` when building a SQL client layer. */
|
|
1550
|
-
type D1SqlLayerOptions = Omit<D1Client.D1ClientConfig, "db">;
|
|
1551
|
-
declare const D1ServiceTypeId: unique symbol;
|
|
1552
|
-
/** Nominal service marker for D1 services created with {@link make}. */
|
|
1553
|
-
interface D1Service<Id extends string> {
|
|
1554
|
-
readonly [D1ServiceTypeId]: {
|
|
1555
|
-
readonly id: Id;
|
|
1556
|
-
};
|
|
1557
|
-
}
|
|
1558
|
-
/**
|
|
1559
|
-
* Creates a typed D1 service tag plus Effect helpers.
|
|
1560
|
-
*/
|
|
1561
|
-
declare const make$4: <Id extends string>(id: Id, definition: D1Definition) => BindingService<D1Service<Id>, Id, D1Database> & {
|
|
1562
|
-
"effect-cf/D1": "effect-cf/D1";
|
|
1563
|
-
definition: D1Definition;
|
|
1564
|
-
sqlLayer: (options?: D1SqlLayerOptions) => Layer.Layer<D1Client.D1Client | _$effect_unstable_sql_SqlClient0.SqlClient, BindingNotFoundError | BindingValidationError | _$effect_Config0.ConfigError, WorkerEnvironment>;
|
|
1565
|
-
};
|
|
1566
|
-
/**
|
|
1567
|
-
* Builds a D1 service around a Cloudflare D1 database binding.
|
|
1568
|
-
*
|
|
1569
|
-
* The returned service exposes the raw `D1Database` binding and `sqlLayer(...)`
|
|
1570
|
-
* for providing `effect/unstable/sql` via `@effect/sql-d1`.
|
|
1571
|
-
*
|
|
1572
|
-
* @example
|
|
1573
|
-
* ```ts
|
|
1574
|
-
* class TodoDatabase extends D1.Service<TodoDatabase>()("TodoDatabase", {
|
|
1575
|
-
* binding: "TODO_DB",
|
|
1576
|
-
* }) {}
|
|
1577
|
-
*
|
|
1578
|
-
* const SqlLive = TodoDatabase.sqlLayer();
|
|
1579
|
-
* ```
|
|
1580
|
-
*/
|
|
1581
|
-
declare const Service: <Self>() => <Id extends string>(id: Id, definition: D1Definition) => BindingService<Self, Id, D1Database> & {
|
|
1582
|
-
"effect-cf/D1": "effect-cf/D1";
|
|
1583
|
-
definition: D1Definition;
|
|
1584
|
-
sqlLayer: (options?: D1SqlLayerOptions) => Layer.Layer<D1Client.D1Client | _$effect_unstable_sql_SqlClient0.SqlClient, BindingNotFoundError | BindingValidationError | _$effect_Config0.ConfigError, WorkerEnvironment | Exclude<Exclude<Self, _$effect_Scope0.Scope>, Self>>;
|
|
1585
|
-
};
|
|
1586
1586
|
declare namespace DurableObjectAlarm_d_exports {
|
|
1587
1587
|
export { AlarmDefinitionConfig, AlarmDefinitionEntry, AlarmDefinitionPayload, AlarmDefinitions, AlarmFailurePolicy, AlarmPayload, AlarmPayloadSchema, AlarmRef, AlarmRetryPolicy, AlarmScheduler, DefinedAlarmEvent, DefinedAlarmHandlers, DurableObjectAlarm, DurableObjectAlarmError, DurableObjectAlarmEvent, InvalidAlarmPayloadError, InvalidAlarmRefError, InvalidProcessDueAlarmsOptionsError, InvalidRepeatEveryError, ProcessDueAlarmsFailure, ProcessDueAlarmsFailureAction, ProcessDueAlarmsHandler, ProcessDueAlarmsMode, ProcessDueAlarmsOptions, ProcessDueAlarmsResult, ScheduleAlarmInput, StoredAlarmDecodeError, define, process, processDue };
|
|
1588
1588
|
}
|