effect-cf 0.11.0 → 0.13.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +14 -0
- package/dist/index.d.mts +1082 -872
- package/dist/index.mjs +770 -494
- package/package.json +2 -1
- package/src/CloudflareOtlp.ts +516 -0
- package/src/DurableObject.ts +62 -21
- package/src/DurableObjectDefinition.ts +19 -9
- package/src/Worker.ts +88 -29
- package/src/WorkerDefinition.ts +16 -8
- package/src/index.ts +1 -0
package/dist/index.d.mts
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import { a as BindingService, c as WorkerConfig, i as BindingNotFoundError, l as WorkerEnv, o as BindingValidationError, s as Binding_d_exports, t as Hyperdrive_d_exports, u as WorkerEnvironment } from "./Hyperdrive-L6ldMlRF.mjs";
|
|
2
|
-
import { Cause, Context, Data, DateTime, Duration, Effect, Layer, Option, Schema, Scope } from "effect";
|
|
2
|
+
import { Cause, Config, Context, Data, DateTime, Duration, Effect, Layer, Option, Schema, Scope } from "effect";
|
|
3
|
+
import { HttpServerRequest, HttpServerResponse } from "effect/unstable/http";
|
|
4
|
+
import { OtlpMetrics } from "effect/unstable/observability";
|
|
3
5
|
import { D1Client } from "@effect/sql-d1";
|
|
4
6
|
import { DurableObject, RpcStub, RpcTarget, WorkerEntrypoint, WorkflowEntrypoint, WorkflowEvent, WorkflowSleepDuration, WorkflowStep, WorkflowStepConfig, WorkflowStepContext, WorkflowStepEvent, WorkflowTimeoutDuration } from "cloudflare:workers";
|
|
5
|
-
import { HttpServerRequest, HttpServerResponse } from "effect/unstable/http";
|
|
6
7
|
import * as RpcSerialization from "effect/unstable/rpc/RpcSerialization";
|
|
7
8
|
import * as RpcServer from "effect/unstable/rpc/RpcServer";
|
|
8
9
|
import { SqliteClient } from "@effect/sql-sqlite-do";
|
|
@@ -11,981 +12,1182 @@ import * as _$effect_Types0 from "effect/Types";
|
|
|
11
12
|
import * as _$effect_Cause0 from "effect/Cause";
|
|
12
13
|
import * as _$effect_Layer0 from "effect/Layer";
|
|
13
14
|
import * as _$effect_Scope0 from "effect/Scope";
|
|
15
|
+
import * as Duration$1 from "effect/Duration";
|
|
16
|
+
import * as Tracer from "effect/Tracer";
|
|
14
17
|
import * as _$effect_Config0 from "effect/Config";
|
|
15
18
|
|
|
16
|
-
//#region src/
|
|
17
|
-
declare namespace
|
|
18
|
-
export {
|
|
19
|
+
//#region src/DurableObjectStorage.d.ts
|
|
20
|
+
declare namespace DurableObjectStorage_d_exports {
|
|
21
|
+
export { DurableObjectStorage, DurableObjectTransaction, SchemaBackedSyncKvStorage, SqlCursor, SqlStorage, SqlStorageValue, StorageOperationError, SyncKvDefinition, SyncKvStorage, fromDurableObjectStorage };
|
|
19
22
|
}
|
|
20
|
-
/**
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
readonly
|
|
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";
|
|
27
|
+
} & Readonly<A>;
|
|
28
|
+
/** Error type used when a storage operation throws or rejects. */
|
|
29
|
+
declare class StorageOperationError extends StorageOperationError_base<{
|
|
30
|
+
readonly operation: string;
|
|
31
|
+
readonly cause: unknown;
|
|
32
|
+
}> {}
|
|
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>;
|
|
24
51
|
}
|
|
25
|
-
/**
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
};
|
|
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;
|
|
33
59
|
}
|
|
34
60
|
/**
|
|
35
|
-
*
|
|
61
|
+
* Schema pair used by `SyncKvStorage.schema(...)`.
|
|
36
62
|
*/
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
};
|
|
63
|
+
interface SyncKvDefinition<Key, Value, EncodedValue> {
|
|
64
|
+
readonly key: Schema.Codec<Key, string>;
|
|
65
|
+
readonly value: Schema.Codec<Value, EncodedValue>;
|
|
66
|
+
}
|
|
42
67
|
/**
|
|
43
|
-
*
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
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.
|
|
47
104
|
*
|
|
48
105
|
* @example
|
|
49
106
|
* ```ts
|
|
50
|
-
*
|
|
51
|
-
*
|
|
52
|
-
*
|
|
53
|
-
*
|
|
54
|
-
*
|
|
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
|
+
* });
|
|
55
113
|
* ```
|
|
56
114
|
*/
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
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;
|
|
64
147
|
}
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
[key: string | number]: unknown;
|
|
72
|
-
} ? { [Key in keyof T]: Stubify<T[Key]> } : T;
|
|
73
|
-
type MaybeProvider<T> = T extends object ? Provider<T> : unknown;
|
|
74
|
-
type MaybeDisposable<T> = T extends object ? Disposable : unknown;
|
|
75
|
-
type Result<T> = T extends Stubable ? Promise<Stub<T>> & Provider<T> : T extends Serializable<T> ? Promise<Stubify<T> & MaybeDisposable<T>> & MaybeProvider<T> : never;
|
|
76
|
-
type MethodKey<Api> = { [Key in keyof Api]-?: Key extends string ? Api[Key] extends ((...args: Array<any>) => unknown) ? Key : never : never }[keyof Api];
|
|
77
|
-
type MethodArgs<Api, Method extends keyof Api> = Api[Method] extends ((...args: infer Args) => unknown) ? Args : never;
|
|
78
|
-
type MethodReturn<Api, Method extends keyof Api> = Api[Method] extends ((...args: Array<any>) => infer Return) ? Return : never;
|
|
79
|
-
type DisposableValue = {
|
|
80
|
-
[Symbol.dispose](): void;
|
|
81
|
-
};
|
|
82
|
-
declare const isDisposable: (value: unknown) => value is DisposableValue;
|
|
83
|
-
declare const dispose: (value: unknown) => Effect.Effect<void>;
|
|
84
|
-
declare const resolve: <A>(value: A) => Effect.Effect<Awaited<A>, unknown>;
|
|
85
|
-
declare const scoped: <A>(value: A) => Effect.Effect<Awaited<A>, unknown, Scope.Scope>;
|
|
86
|
-
declare namespace RpcDefinition_d_exports {
|
|
87
|
-
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 };
|
|
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 };
|
|
88
154
|
}
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
} &
|
|
92
|
-
|
|
93
|
-
readonly definition: string;
|
|
94
|
-
readonly method: string;
|
|
95
|
-
}> {}
|
|
96
|
-
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 & {
|
|
97
|
-
readonly _tag: "RpcArgumentCountError";
|
|
98
|
-
} & Readonly<A>;
|
|
99
|
-
declare class RpcArgumentCountError extends RpcArgumentCountError_base<{
|
|
100
|
-
readonly definition: string;
|
|
101
|
-
readonly method: string;
|
|
102
|
-
readonly expected: number;
|
|
103
|
-
readonly actual: number;
|
|
104
|
-
}> {}
|
|
105
|
-
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 & {
|
|
106
|
-
readonly _tag: "RpcArgumentDecodeError";
|
|
107
|
-
} & Readonly<A>;
|
|
108
|
-
declare class RpcArgumentDecodeError extends RpcArgumentDecodeError_base<{
|
|
109
|
-
readonly definition: string;
|
|
110
|
-
readonly method: string;
|
|
111
|
-
readonly index: number;
|
|
112
|
-
readonly cause: unknown;
|
|
113
|
-
}> {}
|
|
114
|
-
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 & {
|
|
115
|
-
readonly _tag: "RpcArgumentEncodeError";
|
|
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";
|
|
116
159
|
} & Readonly<A>;
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
readonly method: string;
|
|
120
|
-
readonly index: number;
|
|
160
|
+
/** Error raised when sending on a Durable Object websocket fails. */
|
|
161
|
+
declare class DurableWebSocketSendError extends DurableWebSocketSendError_base<{
|
|
121
162
|
readonly cause: unknown;
|
|
122
163
|
}> {}
|
|
123
|
-
declare const
|
|
124
|
-
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";
|
|
125
166
|
} & Readonly<A>;
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
readonly method: string;
|
|
167
|
+
/** Error raised when closing a Durable Object websocket fails. */
|
|
168
|
+
declare class DurableWebSocketCloseError extends DurableWebSocketCloseError_base<{
|
|
129
169
|
readonly cause: unknown;
|
|
130
170
|
}> {}
|
|
131
|
-
declare const
|
|
132
|
-
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";
|
|
133
173
|
} & Readonly<A>;
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
readonly
|
|
174
|
+
/** Error raised when serializing or deserializing a websocket attachment fails. */
|
|
175
|
+
declare class DurableWebSocketAttachmentError extends DurableWebSocketAttachmentError_base<{
|
|
176
|
+
readonly operation: "serialize" | "deserialize";
|
|
137
177
|
readonly cause: unknown;
|
|
138
178
|
}> {}
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
export type EncodedArgs<Self extends Any> = EncodedArgsFromSchemas<Self["args"]>;
|
|
152
|
-
export type Success<Self extends Any> = Schema.Schema.Type<Self["success"]>;
|
|
153
|
-
export type EncodedSuccess<Self extends Any> = Schema.Codec.Encoded<Self["success"]>;
|
|
154
|
-
export {};
|
|
155
|
-
}
|
|
156
|
-
type Methods$4 = Record<string, Method$5.Any>;
|
|
157
|
-
type NoReservedMethods$4<MethodsShape extends Methods$4, Reserved extends string = ReservedMethodName$6> = Extract<keyof MethodsShape, Reserved> extends never ? MethodsShape : never;
|
|
158
|
-
interface Definition$9<Id extends string = string, MethodsShape extends Methods$4 = Methods$4> {
|
|
159
|
-
readonly id: Id;
|
|
160
|
-
readonly methods: MethodsShape;
|
|
161
|
-
}
|
|
162
|
-
declare namespace Definition$9 {
|
|
163
|
-
type Any = Definition$9<string, Methods$4>;
|
|
164
|
-
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]>> };
|
|
165
|
-
type Api<Self extends Any, Reserved extends string = never> = Provider<ServerApi<Self>, Reserved>;
|
|
166
|
-
type MethodNames<Self extends Any> = Extract<keyof Self["methods"], string>;
|
|
167
|
-
}
|
|
168
|
-
declare class ReservedMethodNameError extends Error {
|
|
169
|
-
readonly method: string;
|
|
170
|
-
readonly target: string;
|
|
171
|
-
constructor(target: string, method: string);
|
|
172
|
-
}
|
|
173
|
-
declare const assertNoReservedMethods: (target: string, methods: Record<string, unknown>, reserved: ReadonlySet<string>) => void;
|
|
174
|
-
declare function method$4<Success extends ServiceFreeSchema$4>(definition: {
|
|
175
|
-
readonly success: Success;
|
|
176
|
-
}): Method$5<readonly [], Success>;
|
|
177
|
-
declare function method$4<const Args extends ReadonlyArray<ServiceFreeSchema$4>, Success extends ServiceFreeSchema$4>(definition: {
|
|
178
|
-
readonly args: Args;
|
|
179
|
-
readonly success: Success;
|
|
180
|
-
}): Method$5<Args, Success>;
|
|
181
|
-
declare const assertNoReservedMethodNames: (definition: Definition$9.Any) => Effect.Effect<void, RpcReservedMethodNameError>;
|
|
182
|
-
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>;
|
|
183
|
-
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>;
|
|
184
|
-
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>;
|
|
185
|
-
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>;
|
|
186
|
-
declare const make$9: <Id extends string, const MethodsShape extends Methods$4>(id: Id, methods: MethodsShape) => Definition$9<Id, MethodsShape>;
|
|
187
|
-
declare namespace QueueBinding_d_exports {
|
|
188
|
-
export { MessageSendRequest, QueueBindingClient, QueueBindingDefinition, QueueMetrics, QueueOperationError, QueueProducer, QueueSendBatchOptions, QueueSendBatchResponse, QueueSendOptions, QueueSendResponse, isQueue, layer$8 as layer, makeClient$6 as makeClient };
|
|
189
|
-
}
|
|
190
|
-
type QueueSendOptions = globalThis.QueueSendOptions;
|
|
191
|
-
type QueueSendResponse = globalThis.QueueSendResponse;
|
|
192
|
-
type QueueSendBatchOptions = globalThis.QueueSendBatchOptions;
|
|
193
|
-
type QueueSendBatchResponse = globalThis.QueueSendBatchResponse;
|
|
194
|
-
type QueueMetrics = globalThis.QueueMetrics;
|
|
195
|
-
type MessageSendRequest<Body> = globalThis.MessageSendRequest<Body>;
|
|
196
|
-
type QueueProducer<Body> = Pick<globalThis.Queue<Body>, "send"> & Partial<Pick<globalThis.Queue<Body>, "sendBatch" | "metrics">>;
|
|
197
|
-
interface QueueBindingDefinition<Message extends ServiceFreeSchema$4> {
|
|
198
|
-
/** Binding name as configured in `wrangler.jsonc`. */
|
|
199
|
-
readonly binding: string;
|
|
200
|
-
/** Codec used to encode messages before sending them to Cloudflare Queues. */
|
|
201
|
-
readonly message: Message;
|
|
202
|
-
}
|
|
203
|
-
interface QueueBindingClient<Message extends ServiceFreeSchema$4> {
|
|
204
|
-
readonly send: (message: Schema.Schema.Type<Message>, options?: QueueSendOptions) => Effect.Effect<void, QueueOperationError | Schema.SchemaError>;
|
|
205
|
-
readonly sendBatch: (messages: Iterable<MessageSendRequest<Schema.Schema.Type<Message>>>, options?: QueueSendBatchOptions) => Effect.Effect<void, QueueOperationError | Schema.SchemaError>;
|
|
206
|
-
readonly metrics: () => Effect.Effect<QueueMetrics, QueueOperationError>;
|
|
207
|
-
readonly unsafeRaw: Effect.Effect<globalThis.Queue<Schema.Codec.Encoded<Message>>>;
|
|
208
|
-
}
|
|
209
|
-
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 & {
|
|
210
|
-
readonly _tag: "QueueOperationError";
|
|
211
|
-
} & Readonly<A>;
|
|
212
|
-
declare class QueueOperationError extends QueueOperationError_base<{
|
|
213
|
-
readonly binding: string;
|
|
214
|
-
readonly operation: string;
|
|
215
|
-
readonly cause: unknown;
|
|
216
|
-
readonly message: string;
|
|
217
|
-
}> {}
|
|
218
|
-
declare const isQueue: <Body>(value: unknown) => value is QueueProducer<Body>;
|
|
219
|
-
declare const makeClient$6: <Message extends ServiceFreeSchema$4>(definition: QueueBindingDefinition<Message>) => ((queue: QueueProducer<Schema.Codec.Encoded<Message>>) => QueueBindingClient<Message>);
|
|
220
|
-
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>;
|
|
221
|
-
declare namespace QueueDefinition_d_exports {
|
|
222
|
-
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 };
|
|
223
|
-
}
|
|
224
|
-
interface Definition$8<Id extends string = string, Message extends ServiceFreeSchema$4 = ServiceFreeSchema$4> {
|
|
225
|
-
readonly id: Id;
|
|
226
|
-
readonly message: Message;
|
|
227
|
-
}
|
|
228
|
-
declare namespace Definition$8 {
|
|
229
|
-
type Any = Definition$8<string, ServiceFreeSchema$4>;
|
|
230
|
-
}
|
|
231
|
-
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>;
|
|
232
|
-
interface Options$7<ROut, Self extends Definition$8.Any> extends Omit<WorkerOptions<ROut, Record<never, never>>, "queue" | "rpc"> {
|
|
233
|
-
readonly queue: Handler$3<ROut, Self>;
|
|
234
|
-
readonly rpc?: never;
|
|
235
|
-
}
|
|
236
|
-
type LayerOptions$11 = {
|
|
237
|
-
readonly binding: string;
|
|
238
|
-
};
|
|
239
|
-
interface TagClass$10<Self, Id extends string, Message extends ServiceFreeSchema$4> extends Context.ServiceClass<Self, Id, QueueBindingClient<Message>> {
|
|
240
|
-
readonly id: Id;
|
|
241
|
-
readonly message: Message;
|
|
242
|
-
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>;
|
|
243
|
-
readonly layer: (options: LayerOptions$11) => Layer.Layer<Self, BindingNotFoundError | BindingValidationError, WorkerEnvironment>;
|
|
244
|
-
readonly send: (message: Schema.Schema.Type<Message>, options?: QueueSendOptions) => Effect.Effect<void, QueueOperationError | Schema.SchemaError, Self>;
|
|
245
|
-
readonly sendBatch: (messages: Iterable<MessageSendRequest<Schema.Schema.Type<Message>>>, options?: QueueSendBatchOptions) => Effect.Effect<void, QueueOperationError | Schema.SchemaError, Self>;
|
|
246
|
-
readonly metrics: () => Effect.Effect<QueueMetrics, QueueOperationError, Self>;
|
|
247
|
-
readonly unsafeRaw: () => Effect.Effect<globalThis.Queue<Schema.Codec.Encoded<Message>>, never, Self>;
|
|
248
|
-
}
|
|
249
|
-
declare const make$8: <Id extends string, Message extends ServiceFreeSchema$4>(id: Id, definition: {
|
|
250
|
-
readonly message: Message;
|
|
251
|
-
}) => TagClass$10<Definition$8<Id, Message>, Id, Message>;
|
|
252
|
-
declare const Tag$11: <Self>() => <Id extends string, Message extends ServiceFreeSchema$4>(id: Id, definition: {
|
|
253
|
-
readonly message: Message;
|
|
254
|
-
}) => TagClass$10<Self, Id, Message>;
|
|
255
|
-
declare const Queue$1: <Self>() => <Id extends string, Message extends ServiceFreeSchema$4>(id: Id, definition: {
|
|
256
|
-
readonly message: Message;
|
|
257
|
-
}) => TagClass$10<Self, Id, Message>;
|
|
258
|
-
declare const implement$7: <ROut, const Self extends Definition$8.Any>(_definition: Self, handler: Handler$3<ROut, Self>) => Handler$3<ROut, Self>;
|
|
259
|
-
declare namespace Queue_d_exports {
|
|
260
|
-
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 };
|
|
261
|
-
}
|
|
262
|
-
interface QueueMessage<Body> {
|
|
263
|
-
readonly raw: globalThis.Message<unknown>;
|
|
264
|
-
readonly id: string;
|
|
265
|
-
readonly timestamp: Date;
|
|
266
|
-
readonly body: Body;
|
|
267
|
-
readonly attempts: number;
|
|
268
|
-
readonly ack: Effect.Effect<void>;
|
|
269
|
-
readonly retry: (options?: globalThis.QueueRetryOptions) => Effect.Effect<void>;
|
|
270
|
-
}
|
|
271
|
-
interface QueueBatch<Body> {
|
|
272
|
-
readonly raw: globalThis.MessageBatch<unknown>;
|
|
273
|
-
readonly messages: ReadonlyArray<QueueMessage<Body>>;
|
|
274
|
-
readonly queue: string;
|
|
275
|
-
readonly metadata: globalThis.MessageBatchMetadata;
|
|
276
|
-
readonly ackAll: Effect.Effect<void>;
|
|
277
|
-
readonly retryAll: (options?: globalThis.QueueRetryOptions) => Effect.Effect<void>;
|
|
278
|
-
}
|
|
279
|
-
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 & {
|
|
280
|
-
readonly _tag: "QueueMessageDecodeError";
|
|
281
|
-
} & Readonly<A>;
|
|
282
|
-
declare class QueueMessageDecodeError extends QueueMessageDecodeError_base<{
|
|
283
|
-
readonly queue: string;
|
|
284
|
-
readonly messageId: string;
|
|
285
|
-
readonly index: number;
|
|
286
|
-
readonly cause: unknown;
|
|
287
|
-
}> {}
|
|
288
|
-
type RuntimeContext$2<ROut> = ExecutionContext | WorkerContext | WorkerEnvironment | ROut;
|
|
289
|
-
type QueueHandlerContext<ROut> = RuntimeContext$2<ROut> | Scope.Scope;
|
|
290
|
-
type QueueHandler<ROut, Body = unknown> = (batch: QueueBatch<Body>) => Effect.Effect<void, unknown, QueueHandlerContext<ROut>>;
|
|
291
|
-
interface QueueOptions<ROut, Body = unknown> {
|
|
292
|
-
readonly queue: QueueHandler<ROut, Body>;
|
|
293
|
-
}
|
|
294
|
-
declare const fromMessage: <Body>(message: globalThis.Message<unknown>, body: Body) => {
|
|
295
|
-
raw: Message<unknown>;
|
|
296
|
-
id: string;
|
|
297
|
-
timestamp: Date;
|
|
298
|
-
body: Body;
|
|
299
|
-
attempts: number;
|
|
300
|
-
ack: Effect.Effect<void, never, never>;
|
|
301
|
-
retry: (options?: globalThis.QueueRetryOptions) => Effect.Effect<void, never, never>;
|
|
302
|
-
};
|
|
303
|
-
declare const fromMessageBatch: <Body>(batch: globalThis.MessageBatch<unknown>, messages: ReadonlyArray<QueueMessage<Body>>) => QueueBatch<Body>;
|
|
304
|
-
declare const decodeBatch: <Body>(batch: globalThis.MessageBatch<unknown>, decodeBody: (body: unknown) => Effect.Effect<Body, unknown>) => Effect.Effect<QueueBatch<Body>, QueueMessageDecodeError>;
|
|
305
|
-
type Definition$7<Id extends string = string, Message extends Definition$8.Any["message"] = Definition$8.Any["message"]> = Definition$8<Id, Message>;
|
|
306
|
-
declare namespace Definition$7 {
|
|
307
|
-
type Any = Definition$8.Any;
|
|
308
|
-
}
|
|
309
|
-
type LayerOptions$10 = LayerOptions$11;
|
|
310
|
-
type TagClass$9<Self, Id extends string, Message extends Definition$8.Any["message"]> = TagClass$10<Self, Id, Message>;
|
|
311
|
-
declare const Tag$10: <Self>() => <Id extends string, Message extends Definition$8.Any["message"]>(id: Id, definition: {
|
|
312
|
-
readonly message: Message;
|
|
313
|
-
}) => TagClass$9<Self, Id, Message>;
|
|
314
|
-
declare const implement$6: <ROut, const Self extends Definition$8.Any>(_definition: Self, handler: Handler$3<ROut, Self>) => Handler$3<ROut, Self>;
|
|
315
|
-
type Handler$2<ROut, Self extends Definition$8.Any> = Handler$3<ROut, Self>;
|
|
316
|
-
type Options$6<ROut, Self extends Definition$8.Any> = Options$7<ROut, Self>;
|
|
317
|
-
declare namespace WorkerDefinition_d_exports {
|
|
318
|
-
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 };
|
|
319
|
-
}
|
|
320
|
-
type ServiceFreeSchema$3 = Schema.Codec<any, any, never, never>;
|
|
321
|
-
interface Method$4<Args extends ReadonlyArray<ServiceFreeSchema$3> = ReadonlyArray<ServiceFreeSchema$3>, Success extends ServiceFreeSchema$3 = ServiceFreeSchema$3> {
|
|
322
|
-
readonly args: Args;
|
|
323
|
-
readonly success: Success;
|
|
324
|
-
}
|
|
325
|
-
declare namespace Method$4 {
|
|
326
|
-
export type Any = Method$4<ReadonlyArray<ServiceFreeSchema$3>, ServiceFreeSchema$3>;
|
|
327
|
-
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]>>;
|
|
328
|
-
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]>>;
|
|
329
|
-
export type Args<Self extends Any> = ArgsFromSchemas<Self["args"]>;
|
|
330
|
-
export type EncodedArgs<Self extends Any> = EncodedArgsFromSchemas<Self["args"]>;
|
|
331
|
-
export type Success<Self extends Any> = Schema.Schema.Type<Self["success"]>;
|
|
332
|
-
export type EncodedSuccess<Self extends Any> = Schema.Codec.Encoded<Self["success"]>;
|
|
333
|
-
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>;
|
|
334
191
|
}
|
|
335
|
-
|
|
192
|
+
/** Wraps a native Cloudflare websocket in the Effect-native Durable Object API. */
|
|
193
|
+
declare const fromWebSocket: <Attachment = unknown>(raw: WebSocket) => DurableWebSocket<Attachment>;
|
|
336
194
|
/**
|
|
337
|
-
*
|
|
338
|
-
*
|
|
339
|
-
* Create with {@link make} and reuse to type both worker implementations and
|
|
340
|
-
* service bindings in other workers.
|
|
195
|
+
* Options for accepting an incoming websocket request in a Durable Object.
|
|
341
196
|
*/
|
|
342
|
-
interface
|
|
343
|
-
|
|
344
|
-
readonly
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
type Any = Definition$6<string, Methods$3>;
|
|
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;
|
|
348
202
|
}
|
|
349
|
-
type ReservedMethodName$5 = ReservedMethodName$3;
|
|
350
|
-
type NoReservedMethods$3<MethodsShape extends Methods$3> = Extract<keyof MethodsShape, ReservedMethodName$5> extends never ? MethodsShape : never;
|
|
351
|
-
/**
|
|
352
|
-
* Promise-based client API derived from a {@link Definition}.
|
|
353
|
-
*/
|
|
354
|
-
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]>> };
|
|
355
|
-
type Api$3<Self extends Definition$6.Any> = Provider<ServerApi$4<Self>, ReservedMethodName$5>;
|
|
356
|
-
/**
|
|
357
|
-
* Effect handlers for each RPC method in a worker definition.
|
|
358
|
-
*/
|
|
359
|
-
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]>> };
|
|
360
203
|
/**
|
|
361
|
-
*
|
|
204
|
+
* Result of a websocket upgrade accepted by {@link acceptUpgrade}.
|
|
362
205
|
*/
|
|
363
|
-
interface
|
|
364
|
-
readonly
|
|
206
|
+
interface AcceptedUpgrade<Attachment = unknown> {
|
|
207
|
+
readonly client: WebSocket;
|
|
208
|
+
readonly server: DurableWebSocket<Attachment>;
|
|
209
|
+
readonly response: Response;
|
|
365
210
|
}
|
|
366
|
-
type LayerOptions$9 = {
|
|
367
|
-
readonly binding: string;
|
|
368
|
-
};
|
|
369
|
-
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>> & {
|
|
370
|
-
readonly id: Id;
|
|
371
|
-
readonly methods: MethodsShape;
|
|
372
|
-
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>;
|
|
373
|
-
readonly layer: (options: LayerOptions$9) => Layer.Layer<Self, BindingNotFoundError | BindingValidationError, WorkerEnvironment>;
|
|
374
|
-
};
|
|
375
|
-
/**
|
|
376
|
-
* Defines a single RPC method schema in a worker definition.
|
|
377
|
-
*/
|
|
378
|
-
declare const method$3: {
|
|
379
|
-
<Success extends ServiceFreeSchema$3>(definition: {
|
|
380
|
-
readonly success: Success;
|
|
381
|
-
}): Method$4<readonly [], Success>;
|
|
382
|
-
<const Args extends readonly ServiceFreeSchema$3[], Success extends ServiceFreeSchema$3>(definition: {
|
|
383
|
-
readonly args: Args;
|
|
384
|
-
readonly success: Success;
|
|
385
|
-
}): Method$4<Args, Success>;
|
|
386
|
-
};
|
|
387
|
-
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>;
|
|
388
|
-
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>;
|
|
389
|
-
declare const Worker: <Self>() => <Id extends string, const MethodsShape extends Methods$3>(id: Id, methods: MethodsShape & NoReservedMethods$3<MethodsShape>) => TagClass$8<Self, Id, MethodsShape>;
|
|
390
|
-
/**
|
|
391
|
-
* Helper for implementing handlers with the exact method shape of a definition.
|
|
392
|
-
*/
|
|
393
|
-
declare const implement$5: <ROut, const Self extends Definition$6.Any>(_definition: Self, handlers: Handlers$3<ROut, Self>) => Handlers$3<ROut, Self>;
|
|
394
211
|
/**
|
|
395
|
-
*
|
|
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
|
+
* ```
|
|
396
222
|
*/
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
type AsyncMethodCloudflareReturn<Api, Method extends keyof Api> = Result<AsyncMethodSuccess<Api, Method>>;
|
|
405
|
-
declare namespace ServiceBinding_d_exports {
|
|
406
|
-
export { Service, ServiceBindingClient, ServiceBindingDefinition, ServiceBindingEffectClient, ServiceBindingFetchError, ServiceBindingRpcError, ServiceBindingStaticClient, ServiceFetcher, isServiceBindingClient, layer$7 as layer, makeClient$5 as makeClient, makeDirectMethods$1 as makeDirectMethods };
|
|
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;
|
|
407
230
|
}
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
*/
|
|
412
|
-
interface ServiceFetcher {
|
|
413
|
-
fetch(input: RequestInfo | URL, init?: RequestInit): Promise<Response>;
|
|
231
|
+
interface RehydratedDurableWebSocket<Attachment> {
|
|
232
|
+
readonly socket: DurableWebSocket<Attachment>;
|
|
233
|
+
readonly attachment: Attachment;
|
|
414
234
|
}
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
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>;
|
|
240
|
+
}
|
|
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>;
|
|
247
|
+
}
|
|
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;
|
|
253
|
+
};
|
|
254
|
+
declare namespace DurableObjectState_d_exports {
|
|
255
|
+
export { DurableObjectState, DurableObjectStateService, fromDurableObjectState };
|
|
431
256
|
}
|
|
432
|
-
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 & {
|
|
433
|
-
readonly _tag: "ServiceBindingFetchError";
|
|
434
|
-
} & Readonly<A>;
|
|
435
|
-
/**
|
|
436
|
-
* Failure raised when calling `fetch` on a service binding.
|
|
437
|
-
*/
|
|
438
|
-
declare class ServiceBindingFetchError extends ServiceBindingFetchError_base<{
|
|
439
|
-
readonly binding: string;
|
|
440
|
-
readonly cause: unknown;
|
|
441
|
-
}> {}
|
|
442
|
-
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 & {
|
|
443
|
-
readonly _tag: "ServiceBindingRpcError";
|
|
444
|
-
} & Readonly<A>;
|
|
445
257
|
/**
|
|
446
|
-
*
|
|
258
|
+
* Effect-friendly wrapper around Cloudflare `DurableObjectState`.
|
|
447
259
|
*/
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
readonly
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
type ServiceCall<R, Api> = <Method extends ServiceMethodKey<Api>>(method: Method, ...args: ServiceMethodArgs<Api, Method>) => Effect.Effect<ServiceMethodSuccess<Api, Method>, ServiceBindingRpcError, R>;
|
|
458
|
-
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> };
|
|
459
|
-
type DirectMethods$1<R, Definition> = Definition extends Definition$6.Any ? DefinitionDirectMethods<R, Definition> : {};
|
|
460
|
-
type ServiceBindingEffectClient<Api extends object, Definition extends Definition$6.Any | undefined = undefined> = DirectMethods$1<never, Definition> & {
|
|
461
|
-
/**
|
|
462
|
-
* Forwards an HTTP request to the bound Worker service.
|
|
463
|
-
*
|
|
464
|
-
* Use this when the service binding is acting as an HTTP origin rather than a
|
|
465
|
-
* Cloudflare RPC target.
|
|
466
|
-
*
|
|
467
|
-
* @example
|
|
468
|
-
* ```ts
|
|
469
|
-
* import { Effect } from "effect";
|
|
470
|
-
*
|
|
471
|
-
* const program = Effect.gen(function* () {
|
|
472
|
-
* const api = yield* ApiWorker;
|
|
473
|
-
* return yield* api.fetch(new Request("https://internal.example/users"));
|
|
474
|
-
* });
|
|
475
|
-
* ```
|
|
476
|
-
*/
|
|
477
|
-
readonly fetch: (input: RequestInfo | URL, init?: RequestInit) => Effect.Effect<globalThis.Response, ServiceBindingFetchError>;
|
|
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>;
|
|
478
269
|
/**
|
|
479
|
-
*
|
|
480
|
-
*
|
|
481
|
-
* This preserves Cloudflare RPC behavior such as promise-like pipelining and
|
|
482
|
-
* transferable / disposable result objects. It does not resolve the returned
|
|
483
|
-
* promise-like value and it does not decode definition-backed success schemas.
|
|
484
|
-
*
|
|
485
|
-
* Most application code should use {@link call} instead.
|
|
486
|
-
*
|
|
487
|
-
* @example
|
|
488
|
-
* ```ts
|
|
489
|
-
* import { Effect } from "effect";
|
|
490
|
-
*
|
|
491
|
-
* const program = Effect.gen(function* () {
|
|
492
|
-
* const counter = yield* CounterService;
|
|
493
|
-
*
|
|
494
|
-
* const result = yield* counter.rpc("increment", 41);
|
|
495
|
-
* const value = yield* Effect.promise(() => result);
|
|
270
|
+
* Runs an Effect inside Cloudflare's `blockConcurrencyWhile` gate.
|
|
496
271
|
*
|
|
497
|
-
*
|
|
498
|
-
*
|
|
499
|
-
*
|
|
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.
|
|
500
278
|
*/
|
|
501
|
-
|
|
279
|
+
blockConcurrencyWhile<A, E, R>(effect: Effect.Effect<A, E, R>): Effect.Effect<A, E, R>;
|
|
502
280
|
/**
|
|
503
|
-
*
|
|
504
|
-
*
|
|
505
|
-
*
|
|
506
|
-
* This is the normal choice when application code wants the final typed value.
|
|
507
|
-
*
|
|
508
|
-
* @example
|
|
509
|
-
* ```ts
|
|
510
|
-
* import { Effect } from "effect";
|
|
511
|
-
*
|
|
512
|
-
* const program = Effect.gen(function* () {
|
|
513
|
-
* const counter = yield* CounterService;
|
|
514
|
-
* const value = yield* counter.call("increment", 41);
|
|
281
|
+
* Runs an Effect inside Cloudflare's `blockConcurrencyWhile` gate and lets
|
|
282
|
+
* Effect failures reject the callback.
|
|
515
283
|
*
|
|
516
|
-
*
|
|
517
|
-
*
|
|
518
|
-
*
|
|
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).
|
|
519
287
|
*/
|
|
520
|
-
|
|
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>>;
|
|
521
305
|
/**
|
|
522
|
-
*
|
|
523
|
-
*
|
|
524
|
-
*
|
|
525
|
-
*
|
|
526
|
-
* Use this for RPC methods that return Cloudflare RPC resources or other
|
|
527
|
-
* disposable objects whose lifetime should be tied to an Effect scope.
|
|
528
|
-
*
|
|
529
|
-
* @example
|
|
530
|
-
* ```ts
|
|
531
|
-
* import { Effect } from "effect";
|
|
532
|
-
*
|
|
533
|
-
* const program = Effect.scoped(
|
|
534
|
-
* Effect.gen(function* () {
|
|
535
|
-
* const files = yield* FileService;
|
|
536
|
-
* const handle = yield* files.scopedCall("open", "report.csv");
|
|
537
|
-
*
|
|
538
|
-
* return yield* handle.read();
|
|
539
|
-
* }),
|
|
540
|
-
* );
|
|
541
|
-
* ```
|
|
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.
|
|
542
309
|
*/
|
|
543
|
-
|
|
544
|
-
}
|
|
545
|
-
|
|
546
|
-
readonly fetch: (input: RequestInfo | URL, init?: RequestInit) => Effect.Effect<globalThis.Response, ServiceBindingFetchError, R>;
|
|
547
|
-
readonly rpc: <Method extends ServiceMethodKey<Api>>(method: Method, ...args: ServiceMethodArgs<Api, Method>) => Effect.Effect<ServiceMethodCloudflareReturn<Api, Method>, ServiceBindingRpcError, R>;
|
|
548
|
-
readonly call: <Method extends ServiceMethodKey<Api>>(method: Method, ...args: ServiceMethodArgs<Api, Method>) => Effect.Effect<ServiceMethodSuccess<Api, Method>, ServiceBindingRpcError, R>;
|
|
549
|
-
readonly scopedCall: <Method extends ServiceMethodKey<Api>>(method: Method, ...args: ServiceMethodArgs<Api, Method>) => Effect.Effect<Awaited<ServiceMethodSuccess<Api, Method>>, unknown, Scope.Scope | R>;
|
|
550
|
-
};
|
|
551
|
-
declare const isServiceBindingClient: <Api extends object>(value: unknown) => value is ServiceBindingClient<Api>;
|
|
552
|
-
declare const makeClient$5: <Api extends object, const Definition extends Definition$6.Any | undefined = undefined>(definition: ServiceBindingDefinition<Definition>) => ((service: ServiceBindingClient<Api>) => ServiceBindingEffectClient<Api, Definition>);
|
|
553
|
-
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>;
|
|
310
|
+
abort(reason?: string): Effect.Effect<void>;
|
|
311
|
+
}
|
|
312
|
+
declare const DurableObjectState_base: Context.ServiceClass<DurableObjectState, "effect-cf/DurableObjectState", DurableObjectStateService>;
|
|
554
313
|
/**
|
|
555
|
-
*
|
|
314
|
+
* Context tag for accessing the current Durable Object state service.
|
|
315
|
+
*/
|
|
316
|
+
declare class DurableObjectState extends DurableObjectState_base {}
|
|
317
|
+
/**
|
|
318
|
+
* Wraps a native Cloudflare `DurableObjectState` as a {@link DurableObjectStateService}.
|
|
319
|
+
*/
|
|
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
|
+
}
|
|
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";
|
|
328
|
+
/**
|
|
329
|
+
* Resolved OpenTelemetry settings used by the Cloudflare OTLP layers.
|
|
556
330
|
*
|
|
557
|
-
*
|
|
558
|
-
*
|
|
559
|
-
*
|
|
560
|
-
*
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
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
|
+
*/
|
|
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
|
+
}
|
|
360
|
+
/**
|
|
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.
|
|
384
|
+
*/
|
|
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>;
|
|
401
|
+
/**
|
|
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}.
|
|
564
408
|
*
|
|
565
409
|
* @example
|
|
566
410
|
* ```ts
|
|
567
|
-
* const
|
|
568
|
-
*
|
|
569
|
-
*
|
|
570
|
-
*
|
|
411
|
+
* const CustomOtlpSettings = Layer.effect(
|
|
412
|
+
* CloudflareOtlp.CloudflareOtlpSettings,
|
|
413
|
+
* Config.all({
|
|
414
|
+
* ...CloudflareOtlp.settingsConfig,
|
|
415
|
+
* endpoint: Config.string("MY_OTLP_ENDPOINT").pipe(Config.option),
|
|
571
416
|
* }),
|
|
572
|
-
*
|
|
417
|
+
* ).pipe(Layer.provide(WorkerConfig.layer));
|
|
418
|
+
* ```
|
|
419
|
+
*/
|
|
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;
|
|
470
|
+
}
|
|
471
|
+
/**
|
|
472
|
+
* Layer that reads standard OpenTelemetry settings from the current Cloudflare
|
|
473
|
+
* `env` object.
|
|
573
474
|
*
|
|
574
|
-
*
|
|
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.
|
|
478
|
+
*/
|
|
479
|
+
declare const settingsLayer: Layer.Layer<CloudflareOtlpSettings, Config.ConfigError, WorkerEnvironment>;
|
|
480
|
+
/**
|
|
481
|
+
* Base OTLP telemetry layer for Cloudflare-compatible runtimes.
|
|
575
482
|
*
|
|
576
|
-
*
|
|
577
|
-
*
|
|
578
|
-
*
|
|
579
|
-
*
|
|
580
|
-
*
|
|
581
|
-
*
|
|
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.
|
|
582
491
|
*/
|
|
583
|
-
declare const
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
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>;
|
|
504
|
+
/**
|
|
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.
|
|
510
|
+
*/
|
|
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 };
|
|
594
514
|
}
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
readonly
|
|
599
|
-
readonly onFailure?: (cause: Cause.Cause<E>) => Effect.Effect<void, never, R>;
|
|
515
|
+
/** Typed D1 binding definition. */
|
|
516
|
+
interface D1Definition {
|
|
517
|
+
/** Binding name as configured in `wrangler.jsonc`. */
|
|
518
|
+
readonly binding: string;
|
|
600
519
|
}
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
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
|
+
};
|
|
606
528
|
}
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
declare
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
529
|
+
/**
|
|
530
|
+
* Creates a typed D1 service tag plus Effect helpers.
|
|
531
|
+
*/
|
|
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>;
|
|
536
|
+
};
|
|
537
|
+
/**
|
|
538
|
+
* Builds a D1 service around a Cloudflare D1 database binding.
|
|
539
|
+
*
|
|
540
|
+
* The returned service exposes the raw `D1Database` binding and `sqlLayer(...)`
|
|
541
|
+
* for providing `effect/unstable/sql` via `@effect/sql-d1`.
|
|
542
|
+
*
|
|
543
|
+
* @example
|
|
544
|
+
* ```ts
|
|
545
|
+
* class TodoDatabase extends D1.Service<TodoDatabase>()("TodoDatabase", {
|
|
546
|
+
* binding: "TODO_DB",
|
|
547
|
+
* }) {}
|
|
548
|
+
*
|
|
549
|
+
* const SqlLive = TodoDatabase.sqlLayer();
|
|
550
|
+
* ```
|
|
551
|
+
*/
|
|
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>>;
|
|
556
|
+
};
|
|
557
|
+
declare namespace Rpc_d_exports {
|
|
558
|
+
export { DisposableValue, MethodArgs, MethodKey, MethodReturn, Provider, Result, RpcStub, RpcTarget, Serializable, Stub, Stubable, Stubify, dispose, isDisposable, resolve, scoped };
|
|
626
559
|
}
|
|
627
|
-
type
|
|
628
|
-
|
|
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;
|
|
629
576
|
};
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
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 };
|
|
636
583
|
}
|
|
637
|
-
declare const
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
declare
|
|
641
|
-
|
|
642
|
-
|
|
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> {
|
|
643
638
|
readonly args: Args;
|
|
644
639
|
readonly success: Success;
|
|
645
640
|
}
|
|
646
|
-
declare namespace Method$
|
|
647
|
-
export type Any = Method$
|
|
648
|
-
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]>>;
|
|
649
645
|
export type Args<Self extends Any> = ArgsFromSchemas<Self["args"]>;
|
|
646
|
+
export type EncodedArgs<Self extends Any> = EncodedArgsFromSchemas<Self["args"]>;
|
|
650
647
|
export type Success<Self extends Any> = Schema.Schema.Type<Self["success"]>;
|
|
648
|
+
export type EncodedSuccess<Self extends Any> = Schema.Codec.Encoded<Self["success"]>;
|
|
651
649
|
export {};
|
|
652
650
|
}
|
|
653
|
-
type Methods$
|
|
654
|
-
type NoReservedMethods$
|
|
655
|
-
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> {
|
|
656
654
|
readonly id: Id;
|
|
657
655
|
readonly methods: MethodsShape;
|
|
658
656
|
}
|
|
659
|
-
declare namespace Definition$
|
|
660
|
-
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>;
|
|
661
662
|
}
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
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);
|
|
667
667
|
}
|
|
668
|
-
|
|
669
|
-
|
|
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> {
|
|
670
720
|
readonly id: Id;
|
|
671
|
-
readonly
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
readonly success: Success;
|
|
684
|
-
}): 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;
|
|
685
733
|
};
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
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>;
|
|
690
743
|
}
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
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";
|
|
695
776
|
} & Readonly<A>;
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
readonly
|
|
777
|
+
declare class QueueMessageDecodeError extends QueueMessageDecodeError_base<{
|
|
778
|
+
readonly queue: string;
|
|
779
|
+
readonly messageId: string;
|
|
780
|
+
readonly index: number;
|
|
699
781
|
readonly cause: unknown;
|
|
700
782
|
}> {}
|
|
701
|
-
type
|
|
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 {};
|
|
829
|
+
}
|
|
830
|
+
type Methods$3 = Record<string, Method$4.Any>;
|
|
702
831
|
/**
|
|
703
|
-
*
|
|
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.
|
|
704
836
|
*/
|
|
705
|
-
interface
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
value?: never;
|
|
712
|
-
}>;
|
|
713
|
-
toArray(): StorageEffect<Array<T>>;
|
|
714
|
-
one(): StorageEffect<T>;
|
|
715
|
-
raw<U extends Array<SqlStorageValue>>(): StorageEffect<IterableIterator<U>>;
|
|
716
|
-
readonly columnNames: Array<string>;
|
|
717
|
-
readonly rowsRead: StorageEffect<number>;
|
|
718
|
-
readonly rowsWritten: StorageEffect<number>;
|
|
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>;
|
|
719
843
|
}
|
|
844
|
+
type ReservedMethodName$5 = ReservedMethodName$3;
|
|
845
|
+
type NoReservedMethods$3<MethodsShape extends Methods$3> = Extract<keyof MethodsShape, ReservedMethodName$5> extends never ? MethodsShape : never;
|
|
720
846
|
/**
|
|
721
|
-
*
|
|
847
|
+
* Promise-based client API derived from a {@link Definition}.
|
|
848
|
+
*/
|
|
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>;
|
|
851
|
+
/**
|
|
852
|
+
* Effect handlers for each RPC method in a worker definition.
|
|
853
|
+
*/
|
|
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]>> };
|
|
855
|
+
/**
|
|
856
|
+
* Worker constructor options for a specific RPC definition.
|
|
722
857
|
*/
|
|
723
|
-
interface
|
|
724
|
-
|
|
725
|
-
exec<T extends Record<string, SqlStorageValue>>(query: string, ...bindings: Array<SqlStorageValue>): StorageEffect<SqlCursor<T>>;
|
|
726
|
-
readonly databaseSize: number;
|
|
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>;
|
|
727
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
|
+
};
|
|
728
870
|
/**
|
|
729
|
-
*
|
|
871
|
+
* Defines a single RPC method schema in a worker definition.
|
|
730
872
|
*/
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
}
|
|
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>;
|
|
735
885
|
/**
|
|
736
|
-
*
|
|
886
|
+
* Helper for implementing handlers with the exact method shape of a definition.
|
|
737
887
|
*/
|
|
738
|
-
|
|
739
|
-
get(key: Key): Effect.Effect<Option.Option<Value>, unknown>;
|
|
740
|
-
put(key: Key, value: Value): Effect.Effect<void, unknown>;
|
|
741
|
-
delete(key: Key): Effect.Effect<boolean, unknown>;
|
|
742
|
-
list(options?: globalThis.SyncKvListOptions): Effect.Effect<Array<[Key, Value]>, unknown>;
|
|
743
|
-
}
|
|
888
|
+
declare const implement$5: <ROut, const Self extends Definition$6.Any>(_definition: Self, handlers: Handlers$3<ROut, Self>) => Handlers$3<ROut, Self>;
|
|
744
889
|
/**
|
|
745
|
-
*
|
|
890
|
+
* Convenience alias for a single worker RPC handler Effect.
|
|
746
891
|
*/
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
|
|
751
|
-
|
|
752
|
-
|
|
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 };
|
|
753
902
|
}
|
|
903
|
+
declare const TypeId$1: "effect-cf/ServiceBinding";
|
|
754
904
|
/**
|
|
755
|
-
*
|
|
905
|
+
* Minimum shape for a Cloudflare service binding.
|
|
756
906
|
*/
|
|
757
|
-
interface
|
|
758
|
-
|
|
759
|
-
get<T = unknown>(keys: Array<string>, options?: globalThis.DurableObjectGetOptions): StorageEffect<Map<string, T>>;
|
|
760
|
-
list<T = unknown>(options?: globalThis.DurableObjectListOptions): StorageEffect<Map<string, T>>;
|
|
761
|
-
put<T>(key: string, value: T, options?: globalThis.DurableObjectPutOptions): StorageEffect<void>;
|
|
762
|
-
put<T>(entries: Record<string, T>, options?: globalThis.DurableObjectPutOptions): StorageEffect<void>;
|
|
763
|
-
delete(key: string, options?: globalThis.DurableObjectPutOptions): StorageEffect<boolean>;
|
|
764
|
-
delete(keys: Array<string>, options?: globalThis.DurableObjectPutOptions): StorageEffect<number>;
|
|
765
|
-
rollback(): StorageEffect<void>;
|
|
766
|
-
getAlarm(options?: globalThis.DurableObjectGetAlarmOptions): StorageEffect<number | null>;
|
|
767
|
-
setAlarm(scheduledTime: number | Date, options?: globalThis.DurableObjectSetAlarmOptions): StorageEffect<void>;
|
|
768
|
-
deleteAlarm(options?: globalThis.DurableObjectSetAlarmOptions): StorageEffect<void>;
|
|
907
|
+
interface ServiceFetcher {
|
|
908
|
+
fetch(input: RequestInfo | URL, init?: RequestInit): Promise<Response>;
|
|
769
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";
|
|
770
912
|
/**
|
|
771
|
-
*
|
|
772
|
-
*
|
|
773
|
-
* @example
|
|
774
|
-
* ```ts
|
|
775
|
-
* const program = Effect.gen(function* () {
|
|
776
|
-
* const state = yield* DurableObjectState;
|
|
777
|
-
* yield* state.storage.put("counter", 1);
|
|
778
|
-
* const value = yield* state.storage.get<number>("counter");
|
|
779
|
-
* return value;
|
|
780
|
-
* });
|
|
781
|
-
* ```
|
|
913
|
+
* Native Cloudflare service object including optional RPC methods.
|
|
782
914
|
*/
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
|
|
786
|
-
delete(key: string, options?: globalThis.DurableObjectPutOptions): StorageEffect<boolean>;
|
|
787
|
-
/**
|
|
788
|
-
* Deletes all stored data. On compatibility dates before 2026-02-24, Cloudflare
|
|
789
|
-
* documents that active alarms must be deleted separately with `deleteAlarm()`.
|
|
790
|
-
*/
|
|
791
|
-
deleteAll(options?: globalThis.DurableObjectPutOptions): StorageEffect<void>;
|
|
792
|
-
getAlarm(options?: globalThis.DurableObjectGetAlarmOptions): StorageEffect<number | null>;
|
|
793
|
-
setAlarm(scheduledTime: number | Date, options?: globalThis.DurableObjectSetAlarmOptions): StorageEffect<void>;
|
|
794
|
-
deleteAlarm(options?: globalThis.DurableObjectSetAlarmOptions): StorageEffect<void>;
|
|
795
|
-
/**
|
|
796
|
-
* SQLite-backed Durable Object storage only.
|
|
797
|
-
*
|
|
798
|
-
* The callback Effect must complete synchronously. If it requires asynchronous
|
|
799
|
-
* work, use `transaction` instead so Cloudflare can run the async transaction
|
|
800
|
-
* callback under the platform's transaction contract.
|
|
801
|
-
*/
|
|
802
|
-
transactionSync<A, E, R>(closure: () => Effect.Effect<A, E, R>): Effect.Effect<A, E | StorageOperationError, R>;
|
|
803
|
-
/**
|
|
804
|
-
* Runs an async transaction and exposes a typed transaction wrapper.
|
|
805
|
-
*/
|
|
806
|
-
transaction<A, E, R>(closure: (txn: DurableObjectTransaction) => Effect.Effect<A, E, R>): Effect.Effect<A, E | StorageOperationError, R>;
|
|
807
|
-
/** Flushes pending writes to disk. */
|
|
808
|
-
sync(): StorageEffect<void>;
|
|
809
|
-
/** SQLite-backed Durable Object storage point-in-time recovery API only. */
|
|
810
|
-
getCurrentBookmark(): StorageEffect<string>;
|
|
811
|
-
/** SQLite-backed Durable Object storage point-in-time recovery API only. */
|
|
812
|
-
onNextSessionRestoreBookmark(bookmark: string): StorageEffect<string>;
|
|
813
|
-
readonly sql: SqlStorage;
|
|
814
|
-
readonly kv: SyncKvStorage;
|
|
815
|
-
}
|
|
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;
|
|
816
918
|
/**
|
|
817
|
-
*
|
|
919
|
+
* Binding metadata used to create an Effect service from a Worker binding.
|
|
818
920
|
*/
|
|
819
|
-
|
|
820
|
-
|
|
821
|
-
|
|
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;
|
|
822
926
|
}
|
|
823
|
-
|
|
824
|
-
|
|
825
|
-
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 & {
|
|
826
|
-
readonly _tag: "DurableWebSocketSendError";
|
|
827
|
-
} & Readonly<A>;
|
|
828
|
-
/** Error raised when sending on a Durable Object websocket fails. */
|
|
829
|
-
declare class DurableWebSocketSendError extends DurableWebSocketSendError_base<{
|
|
830
|
-
readonly cause: unknown;
|
|
831
|
-
}> {}
|
|
832
|
-
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 & {
|
|
833
|
-
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";
|
|
834
929
|
} & Readonly<A>;
|
|
835
|
-
/**
|
|
836
|
-
|
|
930
|
+
/**
|
|
931
|
+
* Failure raised when calling `fetch` on a service binding.
|
|
932
|
+
*/
|
|
933
|
+
declare class ServiceBindingFetchError extends ServiceBindingFetchError_base<{
|
|
934
|
+
readonly binding: string;
|
|
837
935
|
readonly cause: unknown;
|
|
838
936
|
}> {}
|
|
839
|
-
declare const
|
|
840
|
-
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";
|
|
841
939
|
} & Readonly<A>;
|
|
842
|
-
/** Error raised when serializing or deserializing a websocket attachment fails. */
|
|
843
|
-
declare class DurableWebSocketAttachmentError extends DurableWebSocketAttachmentError_base<{
|
|
844
|
-
readonly operation: "serialize" | "deserialize";
|
|
845
|
-
readonly cause: unknown;
|
|
846
|
-
}> {}
|
|
847
|
-
/** Effect-native wrapper around a hibernatable Durable Object websocket. */
|
|
848
|
-
interface DurableWebSocket<Attachment = unknown> {
|
|
849
|
-
/** Underlying Cloudflare websocket. */
|
|
850
|
-
readonly raw: WebSocket;
|
|
851
|
-
/** Sends a message through the socket. */
|
|
852
|
-
send(data: DurableWebSocketSendData): Effect.Effect<void, DurableWebSocketSendError>;
|
|
853
|
-
/** Closes the socket. */
|
|
854
|
-
close(code?: number, reason?: string): Effect.Effect<void, DurableWebSocketCloseError>;
|
|
855
|
-
/** Serializes hibernation attachment metadata onto the socket. */
|
|
856
|
-
serializeAttachment<A = Attachment>(value: A): Effect.Effect<void, DurableWebSocketAttachmentError>;
|
|
857
|
-
/** Deserializes hibernation attachment metadata from the socket. */
|
|
858
|
-
readonly deserializeAttachment: Effect.Effect<unknown, DurableWebSocketAttachmentError>;
|
|
859
|
-
}
|
|
860
|
-
/** Wraps a native Cloudflare websocket in the Effect-native Durable Object API. */
|
|
861
|
-
declare const fromWebSocket: <Attachment = unknown>(raw: WebSocket) => DurableWebSocket<Attachment>;
|
|
862
|
-
/**
|
|
863
|
-
* Options for accepting an incoming websocket request in a Durable Object.
|
|
864
|
-
*/
|
|
865
|
-
interface AcceptUpgradeOptions<Attachment = unknown> {
|
|
866
|
-
/** Optional websocket tags for Durable Object hibernation filtering. */
|
|
867
|
-
readonly tags?: ReadonlyArray<string> | undefined;
|
|
868
|
-
/** Optional attachment serialized onto the server socket. */
|
|
869
|
-
readonly attachment?: Attachment | undefined;
|
|
870
|
-
}
|
|
871
940
|
/**
|
|
872
|
-
*
|
|
941
|
+
* Failure raised when invoking an RPC method on a service binding.
|
|
873
942
|
*/
|
|
874
|
-
|
|
875
|
-
readonly
|
|
876
|
-
readonly
|
|
877
|
-
readonly
|
|
878
|
-
}
|
|
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>;
|
|
879
1049
|
/**
|
|
880
|
-
*
|
|
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
|
|
881
1059
|
*
|
|
882
1060
|
* @example
|
|
883
1061
|
* ```ts
|
|
884
|
-
* const
|
|
885
|
-
*
|
|
1062
|
+
* const Counter = WorkerDefinition.make("Counter", {
|
|
1063
|
+
* increment: WorkerDefinition.method({
|
|
1064
|
+
* args: [Schema.Number],
|
|
1065
|
+
* success: Schema.Number,
|
|
1066
|
+
* }),
|
|
886
1067
|
* });
|
|
887
1068
|
*
|
|
888
|
-
*
|
|
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
|
+
* });
|
|
889
1076
|
* ```
|
|
890
1077
|
*/
|
|
891
|
-
declare const
|
|
892
|
-
|
|
893
|
-
|
|
894
|
-
|
|
895
|
-
readonly
|
|
896
|
-
|
|
897
|
-
readonly
|
|
898
|
-
}
|
|
899
|
-
|
|
900
|
-
|
|
901
|
-
|
|
902
|
-
}
|
|
903
|
-
interface DurableWebSocketAttachment<Attachment, Encoded> {
|
|
904
|
-
serialize(socket: DurableWebSocket<unknown>, value: Attachment): Effect.Effect<void, DurableWebSocketAttachmentError>;
|
|
905
|
-
deserialize(socket: DurableWebSocket<unknown>): Effect.Effect<Option.Option<Attachment>, DurableWebSocketAttachmentError>;
|
|
906
|
-
rehydrate(options?: AttachmentRehydrateOptions): Effect.Effect<Array<RehydratedDurableWebSocket<Attachment>>, DurableWebSocketAttachmentError, DurableObjectState>;
|
|
907
|
-
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 };
|
|
908
1089
|
}
|
|
909
|
-
|
|
910
|
-
declare
|
|
911
|
-
interface
|
|
912
|
-
readonly
|
|
913
|
-
readonly
|
|
914
|
-
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>;
|
|
915
1095
|
}
|
|
916
|
-
|
|
917
|
-
|
|
918
|
-
|
|
919
|
-
|
|
920
|
-
|
|
921
|
-
};
|
|
922
|
-
declare namespace DurableObjectState_d_exports {
|
|
923
|
-
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>;
|
|
924
1101
|
}
|
|
925
|
-
|
|
926
|
-
|
|
927
|
-
|
|
928
|
-
|
|
929
|
-
|
|
930
|
-
|
|
931
|
-
|
|
932
|
-
|
|
933
|
-
|
|
934
|
-
|
|
935
|
-
|
|
936
|
-
|
|
937
|
-
|
|
938
|
-
|
|
939
|
-
|
|
940
|
-
|
|
941
|
-
* callback exceeds the platform timeout (currently documented as 30 seconds).
|
|
942
|
-
* This safe default resolves the callback with the Effect `Exit` for typed
|
|
943
|
-
* Effect failures and resumes that `Exit` afterward, so typed failures remain
|
|
944
|
-
* ordinary Effect failures instead of resetting the Durable Object. Defects
|
|
945
|
-
* and interruptions still reject the callback.
|
|
946
|
-
*/
|
|
947
|
-
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>> {
|
|
948
1118
|
/**
|
|
949
|
-
*
|
|
950
|
-
* Effect failures reject the callback.
|
|
1119
|
+
* Layer provided around each Cloudflare event handled by this Worker.
|
|
951
1120
|
*
|
|
952
|
-
*
|
|
953
|
-
*
|
|
954
|
-
*
|
|
955
|
-
*/
|
|
956
|
-
blockConcurrencyWhileOrReset<A, E, R>(effect: Effect.Effect<A, E, R>): Effect.Effect<A, E, R>;
|
|
957
|
-
/** Accepts a websocket connection for hibernation-capable Durable Objects. */
|
|
958
|
-
acceptWebSocket(ws: DurableWebSocket, tags?: Array<string>): Effect.Effect<void>;
|
|
959
|
-
/** Lists active sockets, optionally filtered by tag. */
|
|
960
|
-
getWebSockets(tag?: string): Effect.Effect<Array<DurableWebSocket>>;
|
|
961
|
-
/** Configures automatic request/response handling for sockets. */
|
|
962
|
-
setWebSocketAutoResponse(pair?: WebSocketRequestResponsePair): Effect.Effect<void>;
|
|
963
|
-
/** Gets the configured websocket auto-response pair. */
|
|
964
|
-
getWebSocketAutoResponse: Effect.Effect<WebSocketRequestResponsePair | null>;
|
|
965
|
-
/** Timestamp of the last automatic websocket response for a socket. */
|
|
966
|
-
getWebSocketAutoResponseTimestamp(ws: DurableWebSocket): Effect.Effect<Date | null>;
|
|
967
|
-
/** Sets the timeout for hibernatable websocket events. */
|
|
968
|
-
setHibernatableWebSocketEventTimeout(timeoutMs?: number): Effect.Effect<void>;
|
|
969
|
-
/** Gets the timeout for hibernatable websocket events. */
|
|
970
|
-
getHibernatableWebSocketEventTimeout: Effect.Effect<number | null>;
|
|
971
|
-
/** Reads tags attached to a websocket. */
|
|
972
|
-
getTags(ws: DurableWebSocket): Effect.Effect<Array<string>>;
|
|
973
|
-
/**
|
|
974
|
-
* Forcibly resets the Durable Object. Cloudflare logs an uncaught Error using
|
|
975
|
-
* the optional reason, and the method is not available in `wrangler dev` local
|
|
976
|
-
* 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.
|
|
977
1124
|
*/
|
|
978
|
-
|
|
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;
|
|
979
1129
|
}
|
|
980
|
-
|
|
981
|
-
|
|
982
|
-
|
|
983
|
-
|
|
984
|
-
|
|
985
|
-
|
|
986
|
-
|
|
987
|
-
|
|
988
|
-
|
|
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]>>;
|
|
989
1191
|
declare namespace DurableObjectNamespace_d_exports {
|
|
990
1192
|
export { DurableObjectFetchError, DurableObjectNamespaceBindingDefinition, DurableObjectNamespaceClient, DurableObjectNamespaceDefinition, DurableObjectNamespaceEffectClient, DurableObjectNamespaceStaticClient, DurableObjectRpcError, DurableObjectStubClient, isDurableObjectNamespaceClient, layer$6 as layer, makeClient$4 as makeClient, makeDirectMethods };
|
|
991
1193
|
}
|
|
@@ -1236,8 +1438,8 @@ type Handlers$1<ROut, Self extends Definition$4.Any> = { readonly [Key in keyof
|
|
|
1236
1438
|
/**
|
|
1237
1439
|
* Durable Object constructor options for a specific RPC definition.
|
|
1238
1440
|
*/
|
|
1239
|
-
interface Options$3<ROut, Self extends Definition$4.Any> extends Omit<DurableObjectOptions<ROut, Handlers$1<ROut, Self>>, "rpc"> {
|
|
1240
|
-
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>;
|
|
1241
1443
|
}
|
|
1242
1444
|
type LayerOptions$7 = {
|
|
1243
1445
|
readonly binding: string;
|
|
@@ -1245,7 +1447,7 @@ type LayerOptions$7 = {
|
|
|
1245
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>> & {
|
|
1246
1448
|
readonly id: Id;
|
|
1247
1449
|
readonly methods: MethodsShape;
|
|
1248
|
-
readonly make: <ROut, LayerError>(layer: Layer.Layer<ROut, LayerError, DurableObjectState | WorkerEnvironment>, options: Options$3<ROut, Definition$4<Id, MethodsShape
|
|
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>;
|
|
1249
1451
|
readonly layer: (options: LayerOptions$7) => Layer.Layer<Self, BindingNotFoundError | BindingValidationError, WorkerEnvironment>;
|
|
1250
1452
|
};
|
|
1251
1453
|
/**
|
|
@@ -1290,7 +1492,15 @@ type RpcHandlers<ROut, Api> = { readonly [Key in keyof Api as Key extends keyof
|
|
|
1290
1492
|
/**
|
|
1291
1493
|
* Options for creating a Durable Object class backed by Effect handlers.
|
|
1292
1494
|
*/
|
|
1293
|
-
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>;
|
|
1294
1504
|
/**
|
|
1295
1505
|
* Effect run when Cloudflare loads this Durable Object instance into memory.
|
|
1296
1506
|
*
|
|
@@ -1299,11 +1509,11 @@ interface DurableObjectOptions<ROut, Rpc extends DurableObjectRpc<ROut>> {
|
|
|
1299
1509
|
* the same Durable Object id again after eviction or restart; use Durable
|
|
1300
1510
|
* Object storage if work must happen only once per id.
|
|
1301
1511
|
*/
|
|
1302
|
-
readonly initialize?: Effect.Effect<void, unknown, HandlerContext<
|
|
1512
|
+
readonly initialize?: Effect.Effect<void, unknown, HandlerContext<RRuntime>>;
|
|
1303
1513
|
/** Optional RPC methods exposed as Durable Object instance methods. */
|
|
1304
1514
|
readonly rpc?: Rpc;
|
|
1305
1515
|
/** Optional fetch handler for HTTP/WebSocket requests. */
|
|
1306
|
-
readonly fetch?: Effect.Effect<Response, unknown, FetchContext<
|
|
1516
|
+
readonly fetch?: Effect.Effect<Response, unknown, FetchContext<RRuntime | REvent>>;
|
|
1307
1517
|
/**
|
|
1308
1518
|
* Optional logical alarm processing effect.
|
|
1309
1519
|
*
|
|
@@ -1311,11 +1521,11 @@ interface DurableObjectOptions<ROut, Rpc extends DurableObjectRpc<ROut>> {
|
|
|
1311
1521
|
* `DurableObjectAlarm.processDue(...)` so the reusable scheduler stays inside
|
|
1312
1522
|
* the Durable Object's single managed runtime boundary.
|
|
1313
1523
|
*/
|
|
1314
|
-
readonly alarms?: Effect.Effect<unknown, unknown, HandlerContext<
|
|
1315
|
-
readonly alarm?: (alarmInfo?: globalThis.AlarmInvocationInfo) => Effect.Effect<void, unknown, HandlerContext<
|
|
1316
|
-
readonly webSocketMessage?: (socket: DurableWebSocket, message: string | ArrayBuffer) => Effect.Effect<void, unknown, HandlerContext<
|
|
1317
|
-
readonly webSocketClose?: (socket: DurableWebSocket, code: number, reason: string, wasClean: boolean) => Effect.Effect<void, unknown, HandlerContext<
|
|
1318
|
-
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>>;
|
|
1319
1529
|
}
|
|
1320
1530
|
/**
|
|
1321
1531
|
* Cloudflare `DurableObject` constructor produced by {@link make}.
|
|
@@ -1324,7 +1534,7 @@ type DurableObjectClass<Rpc extends DurableObjectRpc<ROut>, ROut> = new (state:
|
|
|
1324
1534
|
/**
|
|
1325
1535
|
* Creates a Durable Object class backed by a single managed Effect runtime.
|
|
1326
1536
|
*/
|
|
1327
|
-
declare const make$4: <ROut, LayerError, const Rpc extends DurableObjectRpc<ROut> = Record<never, never>>(layer: Layer.Layer<ROut, LayerError, DurableObjectState | WorkerEnvironment>, options?: DurableObjectOptions<ROut, Rpc>) => DurableObjectClass<Rpc, ROut>;
|
|
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>;
|
|
1328
1538
|
type ServiceFreeSchema = Schema.Codec<any, any, never, never>;
|
|
1329
1539
|
interface Method$1<Args extends ReadonlyArray<ServiceFreeSchema> = ReadonlyArray<ServiceFreeSchema>, Success extends ServiceFreeSchema = ServiceFreeSchema> {
|
|
1330
1540
|
readonly args: Args;
|
|
@@ -1351,13 +1561,13 @@ type LayerOptions$6 = LayerOptions$7;
|
|
|
1351
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]>> };
|
|
1352
1562
|
type Api<Self extends Definition$3.Any> = Provider<ServerApi$1<Self>, ReservedMethodName>;
|
|
1353
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]>> };
|
|
1354
|
-
interface Options$2<ROut, Self extends Definition$3.Any> extends Omit<DurableObjectOptions<ROut, Handlers<ROut, Self>>, "rpc"> {
|
|
1355
|
-
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>;
|
|
1356
1566
|
}
|
|
1357
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>> & {
|
|
1358
1568
|
readonly id: Id;
|
|
1359
1569
|
readonly methods: MethodsShape;
|
|
1360
|
-
readonly make: <ROut, LayerError>(layer: Layer.Layer<ROut, LayerError, DurableObjectState | WorkerEnvironment>, options: Options$2<ROut, Definition$3<Id, MethodsShape
|
|
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>;
|
|
1361
1571
|
readonly layer: (options: LayerOptions$6) => Layer.Layer<Self, BindingNotFoundError | BindingValidationError, WorkerEnvironment>;
|
|
1362
1572
|
};
|
|
1363
1573
|
type TagFactory = <Self>() => <Id extends string, const MethodsShape extends Methods>(id: Id, methods: MethodsShape & NoReservedMethods<MethodsShape>) => TagClass$5<Self, Id, MethodsShape>;
|
|
@@ -2188,4 +2398,4 @@ declare const implement: <ROut, const Self extends Definition$1.Any>(_definition
|
|
|
2188
2398
|
type Handler<ROut, Self extends Definition$1.Any> = Handler$1<ROut, Self>;
|
|
2189
2399
|
type Options<ROut, Self extends Definition$1.Any> = Options$1<ROut, Self>;
|
|
2190
2400
|
//#endregion
|
|
2191
|
-
export { Binding_d_exports as Binding, D1_d_exports as D1, DurableObject_d_exports as DurableObject, DurableObjectAlarm_d_exports as DurableObjectAlarm, DurableObjectDefinition_d_exports as DurableObjectDefinition, DurableObjectNamespace_d_exports as DurableObjectNamespace, DurableObjectRpcWebSocket_d_exports as DurableObjectRpcWebSocket, DurableObjectSqlite_d_exports as DurableObjectSqlite, DurableObjectState_d_exports as DurableObjectState, DurableObjectStorage_d_exports as DurableObjectStorage, DurableObjectWebSocket_d_exports as DurableObjectWebSocket, Hyperdrive_d_exports as Hyperdrive, Images_d_exports as Images, Kv_d_exports as Kv, Queue_d_exports as Queue, QueueBinding_d_exports as QueueBinding, QueueDefinition_d_exports as QueueDefinition, R2_d_exports as R2, Rpc_d_exports as Rpc, RpcDefinition_d_exports as RpcDefinition, ServiceBinding_d_exports as ServiceBinding, Worker_d_exports as Worker, WorkerConfig, WorkerDefinition_d_exports as WorkerDefinition, type WorkerEnv, WorkerEnvironment, Workflow_d_exports as Workflow, WorkflowBinding_d_exports as WorkflowBinding, WorkflowDefinition_d_exports as WorkflowDefinition };
|
|
2401
|
+
export { Binding_d_exports as Binding, CloudflareOtlp_d_exports as CloudflareOtlp, D1_d_exports as D1, DurableObject_d_exports as DurableObject, DurableObjectAlarm_d_exports as DurableObjectAlarm, DurableObjectDefinition_d_exports as DurableObjectDefinition, DurableObjectNamespace_d_exports as DurableObjectNamespace, DurableObjectRpcWebSocket_d_exports as DurableObjectRpcWebSocket, DurableObjectSqlite_d_exports as DurableObjectSqlite, DurableObjectState_d_exports as DurableObjectState, DurableObjectStorage_d_exports as DurableObjectStorage, DurableObjectWebSocket_d_exports as DurableObjectWebSocket, Hyperdrive_d_exports as Hyperdrive, Images_d_exports as Images, Kv_d_exports as Kv, Queue_d_exports as Queue, QueueBinding_d_exports as QueueBinding, QueueDefinition_d_exports as QueueDefinition, R2_d_exports as R2, Rpc_d_exports as Rpc, RpcDefinition_d_exports as RpcDefinition, ServiceBinding_d_exports as ServiceBinding, Worker_d_exports as Worker, WorkerConfig, WorkerDefinition_d_exports as WorkerDefinition, type WorkerEnv, WorkerEnvironment, Workflow_d_exports as Workflow, WorkflowBinding_d_exports as WorkflowBinding, WorkflowDefinition_d_exports as WorkflowDefinition };
|