effect-cf 0.39.1 → 0.40.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +18 -0
- package/README.md +9 -1
- package/dist/AiGateway.d.mts +86 -0
- package/dist/AiGateway.mjs +178 -0
- package/dist/AnalyticsEngine.d.mts +170 -0
- package/dist/AnalyticsEngine.mjs +275 -0
- package/dist/{Artifacts-B3r3RuTB.d.mts → Artifacts.d.mts} +8 -5
- package/dist/{Artifacts-CBxWGeZB.mjs → Artifacts.mjs} +9 -5
- package/dist/Binding.d.mts +45 -0
- package/dist/{Binding-C82jRhdr.mjs → Binding.mjs} +8 -4
- package/dist/BrowserRendering.d.mts +85 -0
- package/dist/BrowserRendering.mjs +81 -0
- package/dist/Cache.d.mts +40 -0
- package/dist/Cache.mjs +51 -0
- package/dist/CloudflareOtlp.d.mts +95 -0
- package/dist/CloudflareOtlp.mjs +125 -0
- package/dist/CloudflareTracer.d.mts +20 -0
- package/dist/CloudflareTracer.mjs +69 -0
- package/dist/ComputerArtifacts.d.mts +2 -2
- package/dist/ComputerArtifacts.mjs +3 -2
- package/dist/ComputerWorkspace.d.mts +36 -31
- package/dist/ComputerWorkspace.mjs +8 -3
- package/dist/ComputerWorkspaceHost.d.mts +1 -1
- package/dist/ComputerWorkspaceHost.mjs +1 -1
- package/dist/{ContainerNamespace-DbLaeFhN.d.mts → ContainerNamespace.d.mts} +16 -12
- package/dist/ContainerNamespace.mjs +165 -0
- package/dist/D1.d.mts +33 -0
- package/dist/D1.mjs +32 -0
- package/dist/DurableObject.d.mts +103 -0
- package/dist/DurableObject.mjs +77 -0
- package/dist/DurableObjectAlarm.d.mts +187 -0
- package/dist/DurableObjectAlarm.mjs +344 -0
- package/dist/DurableObjectDefinition.d.mts +87 -0
- package/dist/DurableObjectDefinition.mjs +125 -0
- package/dist/DurableObjectNamespace.d.mts +154 -0
- package/dist/DurableObjectNamespace.mjs +144 -0
- package/dist/DurableObjectRpcWebSocket.d.mts +112 -0
- package/dist/DurableObjectRpcWebSocket.mjs +547 -0
- package/dist/DurableObjectSqlite.d.mts +11 -0
- package/dist/DurableObjectSqlite.mjs +16 -0
- package/dist/DurableObjectState.d.mts +65 -0
- package/dist/DurableObjectState.mjs +47 -0
- package/dist/DurableObjectStorage.d.mts +112 -0
- package/dist/{DurableObjectState-DLL0YgBd.mjs → DurableObjectStorage.mjs} +19 -157
- package/dist/DurableObjectWebSocket.d.mts +83 -0
- package/dist/DurableObjectWebSocket.mjs +120 -0
- package/dist/Email.d.mts +106 -0
- package/dist/Email.mjs +247 -0
- package/dist/Environment.d.mts +59 -0
- package/dist/{ErrorMessage-Byx2OgNd.mjs → Environment.mjs} +7 -18
- package/dist/{Hyperdrive-HrwFlZ6x.d.mts → Hyperdrive.d.mts} +8 -5
- package/dist/Hyperdrive.mjs +32 -0
- package/dist/HyperdrivePg.d.mts +4 -3
- package/dist/HyperdrivePg.mjs +3 -1
- package/dist/Images.d.mts +191 -0
- package/dist/Images.mjs +112 -0
- package/dist/Kv.d.mts +84 -0
- package/dist/Kv.mjs +132 -0
- package/dist/Mcp.d.mts +5 -3
- package/dist/Mcp.mjs +13 -4
- package/dist/Queue.d.mts +68 -0
- package/dist/Queue.mjs +54 -0
- package/dist/QueueBinding.d.mts +42 -0
- package/dist/QueueBinding.mjs +69 -0
- package/dist/QueueDefinition.d.mts +48 -0
- package/dist/QueueDefinition.mjs +63 -0
- package/dist/R2.d.mts +89 -0
- package/dist/R2.mjs +117 -0
- package/dist/Rpc.d.mts +29 -0
- package/dist/Rpc.mjs +28 -0
- package/dist/RpcDefinition.d.mts +116 -0
- package/dist/RpcDefinition.mjs +184 -0
- package/dist/RpcTracing.d.mts +52 -0
- package/dist/RpcTracing.mjs +77 -0
- package/dist/Sandbox.d.mts +10 -5
- package/dist/Sandbox.mjs +9 -3
- package/dist/ServiceBinding.d.mts +112 -0
- package/dist/ServiceBinding.mjs +145 -0
- package/dist/Vectorize.d.mts +68 -0
- package/dist/Vectorize.mjs +76 -0
- package/dist/Vitest.d.mts +6 -4
- package/dist/Vitest.mjs +8 -4
- package/dist/WebTransport.d.mts +66 -0
- package/dist/WebTransport.mjs +63 -0
- package/dist/Worker.d.mts +139 -0
- package/dist/Worker.mjs +141 -0
- package/dist/WorkerDefinition.d.mts +100 -0
- package/dist/WorkerDefinition.mjs +103 -0
- package/dist/WorkersAi.d.mts +84 -0
- package/dist/WorkersAi.mjs +84 -0
- package/dist/Workflow.d.mts +91 -0
- package/dist/Workflow.mjs +139 -0
- package/dist/{WorkflowBinding-DtVykUCz.d.mts → WorkflowBinding.d.mts} +14 -10
- package/dist/WorkflowBinding.mjs +100 -0
- package/dist/WorkflowDefinition.d.mts +51 -0
- package/dist/WorkflowDefinition.mjs +69 -0
- package/dist/{rolldown-runtime-D7D4PA-g.mjs → _virtual/_rolldown/runtime.mjs} +1 -1
- package/dist/index.d.mts +40 -1800
- package/dist/index.mjs +40 -3123
- package/dist/{ComputerWorkspaceHostRegistry-CY5Fv4Ng.mjs → internal/ComputerWorkspaceHostRegistry.mjs} +1 -1
- package/dist/internal/Entrypoint.mjs +37 -0
- package/dist/internal/ErrorMessage.mjs +17 -0
- package/dist/internal/NativeCallback.mjs +33 -0
- package/dist/internal/RpcInvocation.d.mts +13 -0
- package/dist/internal/RpcInvocation.mjs +34 -0
- package/dist/internal/Runtime.mjs +31 -0
- package/dist/internal/Telemetry.mjs +20 -0
- package/dist/{WorkerContext-Yobnfw-K.mjs → internal/WorkerContext.mjs} +4 -31
- package/package.json +1 -1
- package/src/AiGateway.ts +5 -1
- package/src/AnalyticsEngine.ts +14 -19
- package/src/Artifacts.ts +6 -1
- package/src/Binding.ts +5 -1
- package/src/BrowserRendering.ts +5 -1
- package/src/Cache.ts +5 -1
- package/src/CloudflareOtlp.ts +12 -10
- package/src/CloudflareTracer.ts +7 -1
- package/src/ComputerArtifacts.ts +2 -1
- package/src/ComputerWorkspace.ts +7 -1
- package/src/ContainerNamespace.ts +6 -1
- package/src/D1.ts +4 -1
- package/src/DurableObject.ts +122 -29
- package/src/DurableObjectAlarm.ts +185 -52
- package/src/DurableObjectDefinition.ts +22 -22
- package/src/DurableObjectNamespace.ts +4 -1
- package/src/DurableObjectRpcWebSocket.ts +7 -1
- package/src/DurableObjectSqlite.ts +2 -1
- package/src/DurableObjectState.ts +4 -1
- package/src/DurableObjectStorage.ts +11 -13
- package/src/DurableObjectWebSocket.ts +5 -1
- package/src/Email.ts +5 -1
- package/src/Environment.ts +6 -1
- package/src/Hyperdrive.ts +4 -1
- package/src/HyperdrivePg.ts +3 -1
- package/src/Images.ts +7 -1
- package/src/Kv.ts +7 -1
- package/src/Mcp.ts +13 -13
- package/src/Queue.ts +3 -1
- package/src/QueueBinding.ts +5 -1
- package/src/QueueDefinition.ts +4 -1
- package/src/R2.ts +7 -1
- package/src/Rpc.ts +4 -1
- package/src/RpcDefinition.ts +4 -1
- package/src/RpcTracing.ts +9 -1
- package/src/Sandbox.ts +7 -1
- package/src/ServiceBinding.ts +6 -1
- package/src/Vectorize.ts +7 -1
- package/src/Vitest.ts +5 -1
- package/src/WebTransport.ts +6 -1
- package/src/Worker.ts +10 -16
- package/src/WorkerDefinition.ts +3 -1
- package/src/WorkersAi.ts +7 -1
- package/src/Workflow.ts +8 -11
- package/src/WorkflowBinding.ts +6 -1
- package/src/WorkflowDefinition.ts +4 -1
- package/src/internal/Entrypoint.ts +3 -1
- package/src/internal/ErrorMessage.ts +1 -1
- package/src/internal/NativeCallback.ts +3 -1
- package/src/internal/RpcInvocation.ts +5 -1
- package/src/internal/Runtime.ts +5 -1
- package/src/internal/Telemetry.ts +4 -3
- package/src/internal/WorkerContext.ts +3 -1
- package/dist/Binding-DKcLrQCM.d.mts +0 -94
- package/dist/DurableObjectState-DJ0K-zyd.d.mts +0 -244
- package/dist/Worker-XsGJsCJX.mjs +0 -885
- package/dist/Worker-gV4mDqIs.d.mts +0 -641
|
@@ -0,0 +1,154 @@
|
|
|
1
|
+
import { WorkerEnvironment } from "./Environment.mjs";
|
|
2
|
+
import { BindingNotFoundError, BindingValidationError } from "./Binding.mjs";
|
|
3
|
+
import { Provider } from "./Rpc.mjs";
|
|
4
|
+
import { Definition, Method as Method$1 } from "./RpcDefinition.mjs";
|
|
5
|
+
import { AsyncMethodArgs, AsyncMethodCloudflareReturn, AsyncMethodKey, AsyncMethodSuccess } from "./internal/RpcInvocation.mjs";
|
|
6
|
+
import { Definition as Definition$1, ReservedMethodName as ReservedMethodName$1 } from "./DurableObjectDefinition.mjs";
|
|
7
|
+
import * as Effect from "effect/Effect";
|
|
8
|
+
import * as Predicate from "effect/Predicate";
|
|
9
|
+
import { Context, Layer, Scope } from "effect";
|
|
10
|
+
declare namespace DurableObjectNamespace_d_exports {
|
|
11
|
+
export { DurableObjectFetchError, DurableObjectNamespaceBindingDefinition, DurableObjectNamespaceClient, DurableObjectNamespaceDefinition, DurableObjectNamespaceEffectClient, DurableObjectNamespaceStaticClient, DurableObjectRpcError, DurableObjectStubClient, isDurableObjectNamespaceClient, layer, makeClient, makeDirectMethods };
|
|
12
|
+
}
|
|
13
|
+
interface DurableObjectFetcher {
|
|
14
|
+
fetch(input: RequestInfo | URL, init?: RequestInit): Promise<Response>;
|
|
15
|
+
}
|
|
16
|
+
type RpcClient<Api> = { readonly [Key in keyof Api as Key extends string ? Api[Key] extends ((...args: Array<any>) => any) ? Key : never : never]: Api[Key]; };
|
|
17
|
+
type ReservedMethodName = ReservedMethodName$1 | "fetch";
|
|
18
|
+
type NamespaceCandidate = Parameters<typeof Predicate.isUnknown>[0];
|
|
19
|
+
/**
|
|
20
|
+
* Cloudflare Durable Object stub, optionally enriched with RPC methods.
|
|
21
|
+
*/
|
|
22
|
+
type DurableObjectStubClient<Api extends object> = DurableObjectFetcher & RpcClient<Provider<Api, ReservedMethodName>> & {
|
|
23
|
+
readonly id: globalThis.DurableObjectId;
|
|
24
|
+
readonly name?: string;
|
|
25
|
+
};
|
|
26
|
+
interface DurableObjectNamespaceClient<Api extends object> {
|
|
27
|
+
newUniqueId(options?: globalThis.DurableObjectNamespaceNewUniqueIdOptions): globalThis.DurableObjectId;
|
|
28
|
+
idFromName(name: string): globalThis.DurableObjectId;
|
|
29
|
+
idFromString(id: string): globalThis.DurableObjectId;
|
|
30
|
+
get(id: globalThis.DurableObjectId, options?: globalThis.DurableObjectNamespaceGetDurableObjectOptions): DurableObjectStubClient<Api>;
|
|
31
|
+
getByName(name: string, options?: globalThis.DurableObjectNamespaceGetDurableObjectOptions): DurableObjectStubClient<Api>;
|
|
32
|
+
jurisdiction(jurisdiction: globalThis.DurableObjectJurisdiction): DurableObjectNamespaceClient<Api>;
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Minimal namespace binding metadata.
|
|
36
|
+
*/
|
|
37
|
+
interface DurableObjectNamespaceDefinition {
|
|
38
|
+
readonly binding: string;
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Namespace binding metadata with optional RPC schema.
|
|
42
|
+
*/
|
|
43
|
+
interface DurableObjectNamespaceBindingDefinition<Definition extends Definition$1.Any | undefined = undefined> {
|
|
44
|
+
readonly binding: string;
|
|
45
|
+
readonly definition?: Definition;
|
|
46
|
+
/** Append live trace context only when the receiver also enables rpcTracing. */
|
|
47
|
+
readonly rpcTracing?: boolean;
|
|
48
|
+
}
|
|
49
|
+
declare const DurableObjectRpcError_base: new <A extends Record<string, any> = {}>(args: import("effect/Types").VoidIfEmpty<{ readonly [P in keyof A as P extends "_tag" ? never : P]: A[P]; }>) => import("effect/Cause").YieldableError & {
|
|
50
|
+
readonly _tag: "DurableObjectRpcError";
|
|
51
|
+
} & Readonly<A>;
|
|
52
|
+
/**
|
|
53
|
+
* Failure raised when invoking an RPC method on a Durable Object stub.
|
|
54
|
+
*/
|
|
55
|
+
declare class DurableObjectRpcError extends DurableObjectRpcError_base<{
|
|
56
|
+
readonly binding: string;
|
|
57
|
+
readonly method: string;
|
|
58
|
+
readonly cause: unknown;
|
|
59
|
+
}> {
|
|
60
|
+
get message(): string;
|
|
61
|
+
}
|
|
62
|
+
declare const DurableObjectFetchError_base: new <A extends Record<string, any> = {}>(args: import("effect/Types").VoidIfEmpty<{ readonly [P in keyof A as P extends "_tag" ? never : P]: A[P]; }>) => import("effect/Cause").YieldableError & {
|
|
63
|
+
readonly _tag: "DurableObjectFetchError";
|
|
64
|
+
} & Readonly<A>;
|
|
65
|
+
/**
|
|
66
|
+
* Failure raised when forwarding a request to a Durable Object stub.
|
|
67
|
+
*/
|
|
68
|
+
declare class DurableObjectFetchError extends DurableObjectFetchError_base<{
|
|
69
|
+
readonly binding: string;
|
|
70
|
+
readonly cause: unknown;
|
|
71
|
+
}> {
|
|
72
|
+
get message(): string;
|
|
73
|
+
}
|
|
74
|
+
type StubMethodKey<Api> = AsyncMethodKey<Api>;
|
|
75
|
+
type StubMethodArgs<Api, Method extends keyof Api> = AsyncMethodArgs<Api, Method>;
|
|
76
|
+
type StubMethodSuccess<Api, Method extends keyof Api> = AsyncMethodSuccess<Api, Method>;
|
|
77
|
+
type StubMethodCloudflareReturn<Api, Method extends keyof Api> = AsyncMethodCloudflareReturn<Api, Method>;
|
|
78
|
+
type StubCall<R, Api extends object> = <Method extends StubMethodKey<Api>>(stub: DurableObjectStubClient<Api>, method: Method, ...args: StubMethodArgs<Api, Method>) => Effect.Effect<StubMethodSuccess<Api, Method>, DurableObjectRpcError, R>;
|
|
79
|
+
type DefinitionNamespaceDirectMethods<R, Api extends object, Definition$3 extends Definition$1.Any> = { readonly [Method in Definition.MethodNames<Definition$3>]: (stub: DurableObjectStubClient<Api>, ...args: Method$1.Args<Definition$3["methods"][Method]>) => Effect.Effect<Method$1.Success<Definition$3["methods"][Method]>, DurableObjectRpcError, R>; };
|
|
80
|
+
type DefinitionDurableObjectDirectClient<R, Definition$2 extends Definition$1.Any> = {
|
|
81
|
+
readonly fetch: (input: RequestInfo | URL, init?: RequestInit) => Effect.Effect<globalThis.Response, DurableObjectFetchError, R>;
|
|
82
|
+
} & { readonly [Method in Definition.MethodNames<Definition$2>]: (...args: Method$1.Args<Definition$2["methods"][Method]>) => Effect.Effect<Method$1.Success<Definition$2["methods"][Method]>, DurableObjectRpcError, R>; };
|
|
83
|
+
type DefinitionNamespaceDirectClientMethods<R, Definition extends Definition$1.Any> = {
|
|
84
|
+
readonly byName: (name: string, options?: globalThis.DurableObjectNamespaceGetDurableObjectOptions) => DefinitionDurableObjectDirectClient<R, Definition>;
|
|
85
|
+
readonly byId: (id: globalThis.DurableObjectId, options?: globalThis.DurableObjectNamespaceGetDurableObjectOptions) => DefinitionDurableObjectDirectClient<R, Definition>;
|
|
86
|
+
};
|
|
87
|
+
type DirectMethods<R, Api extends object, Definition> = Definition extends Definition$1.Any ? DefinitionNamespaceDirectMethods<R, Api, Definition> & DefinitionNamespaceDirectClientMethods<R, Definition> : {};
|
|
88
|
+
type DurableObjectNamespaceEffectClient<Api extends object, Definition extends Definition$1.Any | undefined = undefined> = DirectMethods<never, Api, Definition> & {
|
|
89
|
+
readonly newUniqueId: (options?: globalThis.DurableObjectNamespaceNewUniqueIdOptions) => Effect.Effect<globalThis.DurableObjectId>;
|
|
90
|
+
readonly idFromName: (name: string) => Effect.Effect<globalThis.DurableObjectId>;
|
|
91
|
+
readonly idFromString: (id: string) => Effect.Effect<globalThis.DurableObjectId>;
|
|
92
|
+
readonly get: (id: globalThis.DurableObjectId, options?: globalThis.DurableObjectNamespaceGetDurableObjectOptions) => Effect.Effect<DurableObjectStubClient<Api>>;
|
|
93
|
+
readonly getByName: (name: string, options?: globalThis.DurableObjectNamespaceGetDurableObjectOptions) => Effect.Effect<DurableObjectStubClient<Api>>;
|
|
94
|
+
readonly jurisdiction: (jurisdiction: globalThis.DurableObjectJurisdiction) => Effect.Effect<DurableObjectNamespaceClient<Api>>;
|
|
95
|
+
readonly fetch: (stub: DurableObjectStubClient<Api>, input: RequestInfo | URL, init?: RequestInit) => Effect.Effect<globalThis.Response, DurableObjectFetchError>;
|
|
96
|
+
/**
|
|
97
|
+
* Invokes a Durable Object RPC method and returns Cloudflare's raw RPC result.
|
|
98
|
+
*
|
|
99
|
+
* This preserves Cloudflare RPC behavior such as promise-like pipelining and
|
|
100
|
+
* transferable / disposable result objects. It does not resolve the returned
|
|
101
|
+
* promise-like value and it does not decode definition-backed success schemas.
|
|
102
|
+
*
|
|
103
|
+
* Most application code should use {@link call} instead.
|
|
104
|
+
*/
|
|
105
|
+
readonly rpc: <Method extends StubMethodKey<Api>>(stub: DurableObjectStubClient<Api>, method: Method, ...args: StubMethodArgs<Api, Method>) => Effect.Effect<StubMethodCloudflareReturn<Api, Method>, DurableObjectRpcError>;
|
|
106
|
+
/**
|
|
107
|
+
* Invokes a Durable Object RPC method, resolves Cloudflare's RPC result, and
|
|
108
|
+
* decodes the success value when the namespace was created from a definition.
|
|
109
|
+
*
|
|
110
|
+
* This is the normal choice when application code wants the final typed value.
|
|
111
|
+
*/
|
|
112
|
+
readonly call: <Method extends StubMethodKey<Api>>(stub: DurableObjectStubClient<Api>, method: Method, ...args: StubMethodArgs<Api, Method>) => Effect.Effect<StubMethodSuccess<Api, Method>, DurableObjectRpcError>;
|
|
113
|
+
/**
|
|
114
|
+
* Invokes a Durable Object RPC method in the current `Scope`, resolves
|
|
115
|
+
* Cloudflare's RPC result, decodes definition-backed success values, and
|
|
116
|
+
* disposes the resolved result when the scope closes if it implements
|
|
117
|
+
* `Symbol.dispose`.
|
|
118
|
+
*
|
|
119
|
+
* Use this for RPC methods that return Cloudflare RPC resources or other
|
|
120
|
+
* disposable objects whose lifetime should be tied to an Effect scope.
|
|
121
|
+
*/
|
|
122
|
+
readonly scopedCall: <Method extends StubMethodKey<Api>>(stub: DurableObjectStubClient<Api>, method: Method, ...args: StubMethodArgs<Api, Method>) => Effect.Effect<Awaited<StubMethodSuccess<Api, Method>>, DurableObjectRpcError, Scope.Scope>;
|
|
123
|
+
/**
|
|
124
|
+
* Exposes the underlying native Durable Object namespace binding.
|
|
125
|
+
*
|
|
126
|
+
* Prefer the typed helpers above unless Cloudflare exposes a platform feature
|
|
127
|
+
* that is not wrapped by effect-cf yet.
|
|
128
|
+
*/
|
|
129
|
+
readonly rawUnsafe: Effect.Effect<DurableObjectNamespaceClient<Api>>;
|
|
130
|
+
};
|
|
131
|
+
type DurableObjectNamespaceStaticClient<R, Api extends object, Definition extends Definition$1.Any | undefined = undefined> = DirectMethods<R, Api, Definition> & {
|
|
132
|
+
readonly newUniqueId: (options?: globalThis.DurableObjectNamespaceNewUniqueIdOptions) => Effect.Effect<globalThis.DurableObjectId, never, R>;
|
|
133
|
+
readonly idFromName: (name: string) => Effect.Effect<globalThis.DurableObjectId, never, R>;
|
|
134
|
+
readonly idFromString: (id: string) => Effect.Effect<globalThis.DurableObjectId, never, R>;
|
|
135
|
+
readonly get: (id: globalThis.DurableObjectId, options?: globalThis.DurableObjectNamespaceGetDurableObjectOptions) => Effect.Effect<DurableObjectStubClient<Api>, never, R>;
|
|
136
|
+
readonly getByName: (name: string, options?: globalThis.DurableObjectNamespaceGetDurableObjectOptions) => Effect.Effect<DurableObjectStubClient<Api>, never, R>;
|
|
137
|
+
readonly jurisdiction: (jurisdiction: globalThis.DurableObjectJurisdiction) => Effect.Effect<DurableObjectNamespaceClient<Api>, never, R>;
|
|
138
|
+
readonly fetch: (stub: DurableObjectStubClient<Api>, input: RequestInfo | URL, init?: RequestInit) => Effect.Effect<globalThis.Response, DurableObjectFetchError, R>;
|
|
139
|
+
readonly rpc: <Method extends StubMethodKey<Api>>(stub: DurableObjectStubClient<Api>, method: Method, ...args: StubMethodArgs<Api, Method>) => Effect.Effect<StubMethodCloudflareReturn<Api, Method>, DurableObjectRpcError, R>;
|
|
140
|
+
readonly call: <Method extends StubMethodKey<Api>>(stub: DurableObjectStubClient<Api>, method: Method, ...args: StubMethodArgs<Api, Method>) => Effect.Effect<StubMethodSuccess<Api, Method>, DurableObjectRpcError, R>;
|
|
141
|
+
readonly scopedCall: <Method extends StubMethodKey<Api>>(stub: DurableObjectStubClient<Api>, method: Method, ...args: StubMethodArgs<Api, Method>) => Effect.Effect<Awaited<StubMethodSuccess<Api, Method>>, DurableObjectRpcError, Scope.Scope | R>;
|
|
142
|
+
readonly rawUnsafe: () => Effect.Effect<DurableObjectNamespaceClient<Api>, never, R>;
|
|
143
|
+
};
|
|
144
|
+
declare const isDurableObjectNamespaceClient: <Api extends object>(value: NamespaceCandidate) => value is DurableObjectNamespaceClient<Api>;
|
|
145
|
+
declare const makeClient: <Api extends object, const Definition extends Definition$1.Any | undefined = undefined>(definition: DurableObjectNamespaceBindingDefinition<Definition>) => ((namespace: DurableObjectNamespaceClient<Api>) => DurableObjectNamespaceEffectClient<Api, Definition>);
|
|
146
|
+
declare const layer: <Self, Api extends object, const Definition extends Definition$1.Any | undefined = undefined>(tag: Context.Service<Self, DurableObjectNamespaceEffectClient<Api, Definition>>, definition: DurableObjectNamespaceBindingDefinition<Definition>) => Layer.Layer<Self, BindingNotFoundError | BindingValidationError, WorkerEnvironment>;
|
|
147
|
+
declare const makeDirectMethods: <R, Api extends object, Definition extends Definition$1.Any | undefined>(rpcDefinition: Definition | undefined, helpers: {
|
|
148
|
+
readonly call: StubCall<R, Api>;
|
|
149
|
+
readonly fetch: (stub: DurableObjectStubClient<Api>, input: RequestInfo | URL, init?: RequestInit) => Effect.Effect<globalThis.Response, DurableObjectFetchError, R>;
|
|
150
|
+
readonly get: (id: globalThis.DurableObjectId, options?: globalThis.DurableObjectNamespaceGetDurableObjectOptions) => Effect.Effect<DurableObjectStubClient<Api>, never, R>;
|
|
151
|
+
readonly getByName: (name: string, options?: globalThis.DurableObjectNamespaceGetDurableObjectOptions) => Effect.Effect<DurableObjectStubClient<Api>, never, R>;
|
|
152
|
+
}) => DirectMethods<R, Api, Definition>;
|
|
153
|
+
//#endregion
|
|
154
|
+
export { DurableObjectFetchError, DurableObjectNamespaceBindingDefinition, DurableObjectNamespaceClient, DurableObjectNamespaceDefinition, DurableObjectNamespaceEffectClient, DurableObjectNamespaceStaticClient, DurableObjectNamespace_d_exports, DurableObjectRpcError, DurableObjectStubClient, isDurableObjectNamespaceClient, layer, makeClient, makeDirectMethods };
|
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
import { __exportAll } from "./_virtual/_rolldown/runtime.mjs";
|
|
2
|
+
import { layer as layer$1 } from "./Binding.mjs";
|
|
3
|
+
import { causeMessage } from "./internal/ErrorMessage.mjs";
|
|
4
|
+
import { decodeSuccess, encodeArgs } from "./RpcDefinition.mjs";
|
|
5
|
+
import { withRpcClientSpan, withRpcTraceContext } from "./RpcTracing.mjs";
|
|
6
|
+
import { invokeRpcMethod } from "./internal/RpcInvocation.mjs";
|
|
7
|
+
import { resolve, scoped } from "./Rpc.mjs";
|
|
8
|
+
import * as Data from "effect/Data";
|
|
9
|
+
import * as Effect from "effect/Effect";
|
|
10
|
+
import * as Predicate from "effect/Predicate";
|
|
11
|
+
//#region src/DurableObjectNamespace.ts
|
|
12
|
+
var DurableObjectNamespace_exports = /* @__PURE__ */ __exportAll({
|
|
13
|
+
DurableObjectFetchError: () => DurableObjectFetchError,
|
|
14
|
+
DurableObjectRpcError: () => DurableObjectRpcError,
|
|
15
|
+
isDurableObjectNamespaceClient: () => isDurableObjectNamespaceClient,
|
|
16
|
+
layer: () => layer,
|
|
17
|
+
makeClient: () => makeClient,
|
|
18
|
+
makeDirectMethods: () => makeDirectMethods
|
|
19
|
+
});
|
|
20
|
+
const expectedDurableObjectNamespace = "Durable Object namespace binding with getByName(), get(), idFromName(), idFromString(), newUniqueId(), and jurisdiction()";
|
|
21
|
+
/**
|
|
22
|
+
* Failure raised when invoking an RPC method on a Durable Object stub.
|
|
23
|
+
*/
|
|
24
|
+
var DurableObjectRpcError = class extends Data.TaggedError("DurableObjectRpcError") {
|
|
25
|
+
get message() {
|
|
26
|
+
return `Durable Object RPC method "${this.method}" failed for binding "${this.binding}": ${causeMessage(this.cause)}`;
|
|
27
|
+
}
|
|
28
|
+
};
|
|
29
|
+
/**
|
|
30
|
+
* Failure raised when forwarding a request to a Durable Object stub.
|
|
31
|
+
*/
|
|
32
|
+
var DurableObjectFetchError = class extends Data.TaggedError("DurableObjectFetchError") {
|
|
33
|
+
get message() {
|
|
34
|
+
return `Durable Object fetch failed for binding "${this.binding}": ${causeMessage(this.cause)}`;
|
|
35
|
+
}
|
|
36
|
+
};
|
|
37
|
+
const hasFunction = (value, key) => Predicate.hasProperty(value, key) && Predicate.isFunction(value[key]);
|
|
38
|
+
const isDurableObjectNamespaceClient = (value) => hasFunction(value, "getByName") && hasFunction(value, "get") && hasFunction(value, "idFromName") && hasFunction(value, "idFromString") && hasFunction(value, "newUniqueId") && hasFunction(value, "jurisdiction");
|
|
39
|
+
const makeClient = (definition) => {
|
|
40
|
+
return (namespace) => {
|
|
41
|
+
const newUniqueId = (options) => Effect.sync(() => namespace.newUniqueId(options));
|
|
42
|
+
const idFromName = (name) => Effect.sync(() => namespace.idFromName(name));
|
|
43
|
+
const idFromString = (id) => Effect.sync(() => namespace.idFromString(id));
|
|
44
|
+
const get = (id, options) => Effect.sync(() => namespace.get(id, options));
|
|
45
|
+
const getByName = (name, options) => Effect.sync(() => namespace.getByName(name, options));
|
|
46
|
+
const jurisdiction = (value) => Effect.sync(() => namespace.jurisdiction(value));
|
|
47
|
+
const fetch = (stub, input, init) => Effect.tryPromise({
|
|
48
|
+
try: (signal) => {
|
|
49
|
+
const callerSignal = init?.signal !== void 0 ? init.signal : input instanceof Request ? input.signal : void 0;
|
|
50
|
+
return stub.fetch(input, {
|
|
51
|
+
...init,
|
|
52
|
+
signal: callerSignal === null || callerSignal === void 0 ? signal : AbortSignal.any([callerSignal, signal])
|
|
53
|
+
});
|
|
54
|
+
},
|
|
55
|
+
catch: (cause) => new DurableObjectFetchError({
|
|
56
|
+
binding: definition.binding,
|
|
57
|
+
cause
|
|
58
|
+
})
|
|
59
|
+
});
|
|
60
|
+
const rpc = Effect.fnUntraced(function* (stub, method, ...args) {
|
|
61
|
+
const methodName = String(method);
|
|
62
|
+
const encodedArgs = definition.definition === void 0 ? args : yield* encodeArgs(definition.definition, methodName, args).pipe(Effect.mapError((cause) => new DurableObjectRpcError({
|
|
63
|
+
binding: definition.binding,
|
|
64
|
+
method: methodName,
|
|
65
|
+
cause
|
|
66
|
+
})));
|
|
67
|
+
const nativeArgs = definition.rpcTracing ? yield* withRpcTraceContext(encodedArgs) : encodedArgs;
|
|
68
|
+
return yield* invokeRpcMethod(stub, method, nativeArgs, (cause) => new DurableObjectRpcError({
|
|
69
|
+
binding: definition.binding,
|
|
70
|
+
method: methodName,
|
|
71
|
+
cause
|
|
72
|
+
}));
|
|
73
|
+
});
|
|
74
|
+
const decodeSuccess$1 = Effect.fnUntraced(function* (methodName, value) {
|
|
75
|
+
if (definition.definition === void 0) return value;
|
|
76
|
+
return yield* decodeSuccess(definition.definition, methodName, value).pipe(Effect.mapError((cause) => new DurableObjectRpcError({
|
|
77
|
+
binding: definition.binding,
|
|
78
|
+
method: methodName,
|
|
79
|
+
cause
|
|
80
|
+
})));
|
|
81
|
+
});
|
|
82
|
+
const call = Effect.fnUntraced(function* (stub, method, ...args) {
|
|
83
|
+
const methodName = String(method);
|
|
84
|
+
const value = yield* resolve(yield* rpc(stub, method, ...args)).pipe(Effect.mapError((cause) => new DurableObjectRpcError({
|
|
85
|
+
binding: definition.binding,
|
|
86
|
+
method: methodName,
|
|
87
|
+
cause
|
|
88
|
+
})));
|
|
89
|
+
return yield* decodeSuccess$1(methodName, value);
|
|
90
|
+
}, (effect, ...args) => withRpcClientSpan(effect, definition.binding, String(args[1])));
|
|
91
|
+
const scopedCall = Effect.fnUntraced(function* (stub, method, ...args) {
|
|
92
|
+
const methodName = String(method);
|
|
93
|
+
const result = yield* rpc(stub, method, ...args);
|
|
94
|
+
const value = yield* scoped(result).pipe(Effect.mapError((cause) => new DurableObjectRpcError({
|
|
95
|
+
binding: definition.binding,
|
|
96
|
+
method: methodName,
|
|
97
|
+
cause
|
|
98
|
+
})));
|
|
99
|
+
return yield* decodeSuccess$1(methodName, value);
|
|
100
|
+
}, (effect, ...args) => withRpcClientSpan(effect, definition.binding, String(args[1])));
|
|
101
|
+
const directMethods = makeDirectMethods(definition.definition, {
|
|
102
|
+
call,
|
|
103
|
+
fetch,
|
|
104
|
+
get,
|
|
105
|
+
getByName
|
|
106
|
+
});
|
|
107
|
+
return Object.assign(directMethods, {
|
|
108
|
+
newUniqueId,
|
|
109
|
+
idFromName,
|
|
110
|
+
idFromString,
|
|
111
|
+
get,
|
|
112
|
+
getByName,
|
|
113
|
+
jurisdiction,
|
|
114
|
+
fetch,
|
|
115
|
+
rpc,
|
|
116
|
+
call,
|
|
117
|
+
scopedCall,
|
|
118
|
+
rawUnsafe: Effect.succeed(namespace)
|
|
119
|
+
});
|
|
120
|
+
};
|
|
121
|
+
};
|
|
122
|
+
const layer = (tag, definition) => layer$1(tag, definition.binding, (value) => isDurableObjectNamespaceClient(value), makeClient(definition), { expected: expectedDurableObjectNamespace });
|
|
123
|
+
const makeDirectMethods = (rpcDefinition, helpers) => {
|
|
124
|
+
const methods = {};
|
|
125
|
+
if (rpcDefinition !== void 0) {
|
|
126
|
+
for (const methodName of Object.keys(rpcDefinition.methods)) methods[methodName] = (stub, ...args) => helpers.call(stub, methodName, ...args);
|
|
127
|
+
const makeClient = (getStub) => {
|
|
128
|
+
const client = { fetch: (input, init) => Effect.gen(function* () {
|
|
129
|
+
const stub = yield* getStub();
|
|
130
|
+
return yield* helpers.fetch(stub, input, init);
|
|
131
|
+
}) };
|
|
132
|
+
for (const methodName of Object.keys(rpcDefinition.methods)) client[methodName] = (...args) => Effect.gen(function* () {
|
|
133
|
+
const stub = yield* getStub();
|
|
134
|
+
return yield* helpers.call(stub, methodName, ...args);
|
|
135
|
+
});
|
|
136
|
+
return client;
|
|
137
|
+
};
|
|
138
|
+
methods.byName = (name, options) => makeClient(() => helpers.getByName(name, options));
|
|
139
|
+
methods.byId = (id, options) => makeClient(() => helpers.get(id, options));
|
|
140
|
+
}
|
|
141
|
+
return methods;
|
|
142
|
+
};
|
|
143
|
+
//#endregion
|
|
144
|
+
export { DurableObjectFetchError, DurableObjectNamespace_exports, DurableObjectRpcError, isDurableObjectNamespaceClient, layer, makeClient, makeDirectMethods };
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
import { AcceptUpgradeOptions, AcceptedUpgrade, DurableWebSocket, DurableWebSocketAttachmentError } from "./DurableObjectWebSocket.mjs";
|
|
2
|
+
import { DurableObjectState } from "./DurableObjectState.mjs";
|
|
3
|
+
import * as Context from "effect/Context";
|
|
4
|
+
import * as Effect from "effect/Effect";
|
|
5
|
+
import * as Schema from "effect/Schema";
|
|
6
|
+
import * as Layer from "effect/Layer";
|
|
7
|
+
import * as Option from "effect/Option";
|
|
8
|
+
import * as RpcMessage from "effect/unstable/rpc/RpcMessage";
|
|
9
|
+
import * as RpcSerialization from "effect/unstable/rpc/RpcSerialization";
|
|
10
|
+
import * as RpcServer from "effect/unstable/rpc/RpcServer";
|
|
11
|
+
declare namespace DurableObjectRpcWebSocket_d_exports {
|
|
12
|
+
export { DurableObjectRpcWebSocket, DurableObjectRpcWebSocketService, HeartbeatPolicy, LayerOptions, NativeWebSocketMessage, ResumableStreamDeclaration, RpcWebSocketAttachment, layer, resumableStream };
|
|
13
|
+
}
|
|
14
|
+
/** Heartbeat handling for Effect's application-level RPC Ping messages. */
|
|
15
|
+
type HeartbeatPolicy = "auto-response" | "passthrough";
|
|
16
|
+
type RpcWebSocketAttachment = object;
|
|
17
|
+
/** A resumable RPC stream declaration understood by the websocket transport. */
|
|
18
|
+
interface ResumableStreamDeclaration<ResumeDescriptor = unknown, Checkpoint = unknown> {
|
|
19
|
+
/** Stable declaration identifier. Change it when the persisted representation changes. */
|
|
20
|
+
readonly id: string;
|
|
21
|
+
readonly rpcTag: string;
|
|
22
|
+
/** Validates a resume descriptor restored from a websocket attachment. */
|
|
23
|
+
readonly resumeDescriptorSchema: Schema.Decoder<ResumeDescriptor>;
|
|
24
|
+
/** Validates an acknowledged checkpoint restored from a websocket attachment. */
|
|
25
|
+
readonly checkpointSchema: Schema.Decoder<Checkpoint>;
|
|
26
|
+
/**
|
|
27
|
+
* Extracts compact persisted state from an initial encoded request. Do not
|
|
28
|
+
* recycle a subscription key for an unrelated logical subscription while a
|
|
29
|
+
* delayed checkpoint for the previous subscription can still arrive.
|
|
30
|
+
*/
|
|
31
|
+
readonly identify: (request: RpcMessage.RequestEncoded) => Option.Option<{
|
|
32
|
+
readonly subscriptionKey: string;
|
|
33
|
+
readonly resumeDescriptor: ResumeDescriptor;
|
|
34
|
+
readonly acknowledgedCheckpoint: Checkpoint;
|
|
35
|
+
}>;
|
|
36
|
+
readonly rebuild: (options: {
|
|
37
|
+
readonly subscriptionKey: string;
|
|
38
|
+
readonly resumeDescriptor: ResumeDescriptor;
|
|
39
|
+
readonly acknowledgedCheckpoint: Checkpoint;
|
|
40
|
+
}) => {
|
|
41
|
+
readonly payload: unknown;
|
|
42
|
+
readonly headers?: ReadonlyArray<readonly [string, string]> | undefined;
|
|
43
|
+
readonly traceId?: string | undefined;
|
|
44
|
+
readonly spanId?: string | undefined;
|
|
45
|
+
readonly sampled?: boolean | undefined;
|
|
46
|
+
};
|
|
47
|
+
/** Extracts the durable checkpoint represented by one encoded stream value. */
|
|
48
|
+
readonly checkpointFromValue: (value: RpcMessage.ResponseChunkEncoded["values"][number]) => Option.Option<Checkpoint>;
|
|
49
|
+
/**
|
|
50
|
+
* Produces the checkpoint wire token. A logical event must keep the same
|
|
51
|
+
* token when replayed, and unrelated events must never reuse it during the
|
|
52
|
+
* lifetime of a subscription key.
|
|
53
|
+
*/
|
|
54
|
+
readonly checkpointToken: (checkpoint: Checkpoint) => string;
|
|
55
|
+
}
|
|
56
|
+
type AnyResumableStreamDeclaration = ResumableStreamDeclaration<any, any>;
|
|
57
|
+
/** Declares an explicitly resumable RPC stream. */
|
|
58
|
+
declare const resumableStream: <ResumeDescriptor, Checkpoint>(declaration: ResumableStreamDeclaration<ResumeDescriptor, Checkpoint>) => ResumableStreamDeclaration<ResumeDescriptor, Checkpoint>;
|
|
59
|
+
/**
|
|
60
|
+
* Configuration for {@link layer}.
|
|
61
|
+
*/
|
|
62
|
+
interface LayerOptions {
|
|
63
|
+
readonly tag?: string | undefined;
|
|
64
|
+
readonly attachmentKey?: string | undefined;
|
|
65
|
+
/**
|
|
66
|
+
* Heartbeat behavior. `"auto-response"` (the default) installs Cloudflare's
|
|
67
|
+
* hibernation-safe text Ping/Pong response while an RPC socket exists and no
|
|
68
|
+
* non-resumable RPC operation is active, then removes it while one is pending.
|
|
69
|
+
* `"passthrough"` leaves the Durable Object's existing auto-response
|
|
70
|
+
* configuration unchanged and makes the application responsible for waking a
|
|
71
|
+
* lost pending operation.
|
|
72
|
+
* Cloudflare's pair is global to the Durable Object, so use `"passthrough"`
|
|
73
|
+
* when RPC and unrelated websocket protocols share one object.
|
|
74
|
+
*/
|
|
75
|
+
readonly heartbeat?: HeartbeatPolicy | undefined;
|
|
76
|
+
readonly resumableStreams?: ReadonlyArray<AnyResumableStreamDeclaration> | undefined;
|
|
77
|
+
}
|
|
78
|
+
type NativeWebSocketMessage = string | ArrayBuffer;
|
|
79
|
+
interface DurableObjectRpcWebSocketService {
|
|
80
|
+
/** Accept a server socket that has not already been accepted. */
|
|
81
|
+
readonly accept: (socket: DurableWebSocket, tags?: ReadonlyArray<string>) => Effect.Effect<void>;
|
|
82
|
+
/** Shallow-merges application attachment fields with the adapter's metadata namespace. */
|
|
83
|
+
readonly acceptUpgrade: <Attachment extends RpcWebSocketAttachment = RpcWebSocketAttachment>(options?: AcceptUpgradeOptions<Attachment>) => Effect.Effect<AcceptedUpgrade<Attachment>, DurableWebSocketAttachmentError>;
|
|
84
|
+
readonly message: (socket: DurableWebSocket, message: NativeWebSocketMessage) => Effect.Effect<void>;
|
|
85
|
+
readonly close: (socket: DurableWebSocket) => Effect.Effect<void>;
|
|
86
|
+
readonly error: (socket: DurableWebSocket, cause: unknown) => Effect.Effect<void>;
|
|
87
|
+
/**
|
|
88
|
+
* Persists forward checkpoint progress for a resumable stream. Returns `true`
|
|
89
|
+
* only when the checkpoint advances the current pending chunk batch. A failed
|
|
90
|
+
* websocket attachment write resets the connection and fails with
|
|
91
|
+
* `DurableWebSocketAttachmentError`.
|
|
92
|
+
*/
|
|
93
|
+
readonly checkpoint: <ResumeDescriptor, Checkpoint>(declaration: ResumableStreamDeclaration<ResumeDescriptor, Checkpoint>, options: {
|
|
94
|
+
readonly clientId: number;
|
|
95
|
+
readonly subscriptionKey: string;
|
|
96
|
+
readonly checkpoint: Checkpoint;
|
|
97
|
+
}) => Effect.Effect<boolean, DurableWebSocketAttachmentError>;
|
|
98
|
+
}
|
|
99
|
+
declare const DurableObjectRpcWebSocket_base: Context.ServiceClass<DurableObjectRpcWebSocket, "effect-cf/DurableObjectRpcWebSocket", DurableObjectRpcWebSocketService>;
|
|
100
|
+
declare class DurableObjectRpcWebSocket extends DurableObjectRpcWebSocket_base {}
|
|
101
|
+
/**
|
|
102
|
+
* Builds a hibernation-aware transport that bridges Durable Object websocket
|
|
103
|
+
* events to `RpcServer.Protocol`.
|
|
104
|
+
*
|
|
105
|
+
* The layer restores idle tagged sockets and explicitly declared resumable
|
|
106
|
+
* streams after constructor recreation. A socket that lost any other in-flight
|
|
107
|
+
* request is closed with code 1012, which the stock Effect socket protocol
|
|
108
|
+
* reports as an `RpcClientError` containing `SocketCloseError`.
|
|
109
|
+
*/
|
|
110
|
+
declare const layer: (options?: LayerOptions) => Layer.Layer<RpcServer.Protocol | DurableObjectRpcWebSocket, never, DurableObjectState | RpcSerialization.RpcSerialization>;
|
|
111
|
+
//#endregion
|
|
112
|
+
export { DurableObjectRpcWebSocket, DurableObjectRpcWebSocketService, DurableObjectRpcWebSocket_d_exports, HeartbeatPolicy, LayerOptions, NativeWebSocketMessage, ResumableStreamDeclaration, RpcWebSocketAttachment, layer, resumableStream };
|