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.
Files changed (166) hide show
  1. package/CHANGELOG.md +18 -0
  2. package/README.md +9 -1
  3. package/dist/AiGateway.d.mts +86 -0
  4. package/dist/AiGateway.mjs +178 -0
  5. package/dist/AnalyticsEngine.d.mts +170 -0
  6. package/dist/AnalyticsEngine.mjs +275 -0
  7. package/dist/{Artifacts-B3r3RuTB.d.mts → Artifacts.d.mts} +8 -5
  8. package/dist/{Artifacts-CBxWGeZB.mjs → Artifacts.mjs} +9 -5
  9. package/dist/Binding.d.mts +45 -0
  10. package/dist/{Binding-C82jRhdr.mjs → Binding.mjs} +8 -4
  11. package/dist/BrowserRendering.d.mts +85 -0
  12. package/dist/BrowserRendering.mjs +81 -0
  13. package/dist/Cache.d.mts +40 -0
  14. package/dist/Cache.mjs +51 -0
  15. package/dist/CloudflareOtlp.d.mts +95 -0
  16. package/dist/CloudflareOtlp.mjs +125 -0
  17. package/dist/CloudflareTracer.d.mts +20 -0
  18. package/dist/CloudflareTracer.mjs +69 -0
  19. package/dist/ComputerArtifacts.d.mts +2 -2
  20. package/dist/ComputerArtifacts.mjs +3 -2
  21. package/dist/ComputerWorkspace.d.mts +36 -31
  22. package/dist/ComputerWorkspace.mjs +8 -3
  23. package/dist/ComputerWorkspaceHost.d.mts +1 -1
  24. package/dist/ComputerWorkspaceHost.mjs +1 -1
  25. package/dist/{ContainerNamespace-DbLaeFhN.d.mts → ContainerNamespace.d.mts} +16 -12
  26. package/dist/ContainerNamespace.mjs +165 -0
  27. package/dist/D1.d.mts +33 -0
  28. package/dist/D1.mjs +32 -0
  29. package/dist/DurableObject.d.mts +103 -0
  30. package/dist/DurableObject.mjs +77 -0
  31. package/dist/DurableObjectAlarm.d.mts +187 -0
  32. package/dist/DurableObjectAlarm.mjs +344 -0
  33. package/dist/DurableObjectDefinition.d.mts +87 -0
  34. package/dist/DurableObjectDefinition.mjs +125 -0
  35. package/dist/DurableObjectNamespace.d.mts +154 -0
  36. package/dist/DurableObjectNamespace.mjs +144 -0
  37. package/dist/DurableObjectRpcWebSocket.d.mts +112 -0
  38. package/dist/DurableObjectRpcWebSocket.mjs +547 -0
  39. package/dist/DurableObjectSqlite.d.mts +11 -0
  40. package/dist/DurableObjectSqlite.mjs +16 -0
  41. package/dist/DurableObjectState.d.mts +65 -0
  42. package/dist/DurableObjectState.mjs +47 -0
  43. package/dist/DurableObjectStorage.d.mts +112 -0
  44. package/dist/{DurableObjectState-DLL0YgBd.mjs → DurableObjectStorage.mjs} +19 -157
  45. package/dist/DurableObjectWebSocket.d.mts +83 -0
  46. package/dist/DurableObjectWebSocket.mjs +120 -0
  47. package/dist/Email.d.mts +106 -0
  48. package/dist/Email.mjs +247 -0
  49. package/dist/Environment.d.mts +59 -0
  50. package/dist/{ErrorMessage-Byx2OgNd.mjs → Environment.mjs} +7 -18
  51. package/dist/{Hyperdrive-HrwFlZ6x.d.mts → Hyperdrive.d.mts} +8 -5
  52. package/dist/Hyperdrive.mjs +32 -0
  53. package/dist/HyperdrivePg.d.mts +4 -3
  54. package/dist/HyperdrivePg.mjs +3 -1
  55. package/dist/Images.d.mts +191 -0
  56. package/dist/Images.mjs +112 -0
  57. package/dist/Kv.d.mts +84 -0
  58. package/dist/Kv.mjs +132 -0
  59. package/dist/Mcp.d.mts +5 -3
  60. package/dist/Mcp.mjs +13 -4
  61. package/dist/Queue.d.mts +68 -0
  62. package/dist/Queue.mjs +54 -0
  63. package/dist/QueueBinding.d.mts +42 -0
  64. package/dist/QueueBinding.mjs +69 -0
  65. package/dist/QueueDefinition.d.mts +48 -0
  66. package/dist/QueueDefinition.mjs +63 -0
  67. package/dist/R2.d.mts +89 -0
  68. package/dist/R2.mjs +117 -0
  69. package/dist/Rpc.d.mts +29 -0
  70. package/dist/Rpc.mjs +28 -0
  71. package/dist/RpcDefinition.d.mts +116 -0
  72. package/dist/RpcDefinition.mjs +184 -0
  73. package/dist/RpcTracing.d.mts +52 -0
  74. package/dist/RpcTracing.mjs +77 -0
  75. package/dist/Sandbox.d.mts +10 -5
  76. package/dist/Sandbox.mjs +9 -3
  77. package/dist/ServiceBinding.d.mts +112 -0
  78. package/dist/ServiceBinding.mjs +145 -0
  79. package/dist/Vectorize.d.mts +68 -0
  80. package/dist/Vectorize.mjs +76 -0
  81. package/dist/Vitest.d.mts +6 -4
  82. package/dist/Vitest.mjs +8 -4
  83. package/dist/WebTransport.d.mts +66 -0
  84. package/dist/WebTransport.mjs +63 -0
  85. package/dist/Worker.d.mts +139 -0
  86. package/dist/Worker.mjs +141 -0
  87. package/dist/WorkerDefinition.d.mts +100 -0
  88. package/dist/WorkerDefinition.mjs +103 -0
  89. package/dist/WorkersAi.d.mts +84 -0
  90. package/dist/WorkersAi.mjs +84 -0
  91. package/dist/Workflow.d.mts +91 -0
  92. package/dist/Workflow.mjs +139 -0
  93. package/dist/{WorkflowBinding-DtVykUCz.d.mts → WorkflowBinding.d.mts} +14 -10
  94. package/dist/WorkflowBinding.mjs +100 -0
  95. package/dist/WorkflowDefinition.d.mts +51 -0
  96. package/dist/WorkflowDefinition.mjs +69 -0
  97. package/dist/{rolldown-runtime-D7D4PA-g.mjs → _virtual/_rolldown/runtime.mjs} +1 -1
  98. package/dist/index.d.mts +40 -1800
  99. package/dist/index.mjs +40 -3123
  100. package/dist/{ComputerWorkspaceHostRegistry-CY5Fv4Ng.mjs → internal/ComputerWorkspaceHostRegistry.mjs} +1 -1
  101. package/dist/internal/Entrypoint.mjs +37 -0
  102. package/dist/internal/ErrorMessage.mjs +17 -0
  103. package/dist/internal/NativeCallback.mjs +33 -0
  104. package/dist/internal/RpcInvocation.d.mts +13 -0
  105. package/dist/internal/RpcInvocation.mjs +34 -0
  106. package/dist/internal/Runtime.mjs +31 -0
  107. package/dist/internal/Telemetry.mjs +20 -0
  108. package/dist/{WorkerContext-Yobnfw-K.mjs → internal/WorkerContext.mjs} +4 -31
  109. package/package.json +1 -1
  110. package/src/AiGateway.ts +5 -1
  111. package/src/AnalyticsEngine.ts +14 -19
  112. package/src/Artifacts.ts +6 -1
  113. package/src/Binding.ts +5 -1
  114. package/src/BrowserRendering.ts +5 -1
  115. package/src/Cache.ts +5 -1
  116. package/src/CloudflareOtlp.ts +12 -10
  117. package/src/CloudflareTracer.ts +7 -1
  118. package/src/ComputerArtifacts.ts +2 -1
  119. package/src/ComputerWorkspace.ts +7 -1
  120. package/src/ContainerNamespace.ts +6 -1
  121. package/src/D1.ts +4 -1
  122. package/src/DurableObject.ts +122 -29
  123. package/src/DurableObjectAlarm.ts +185 -52
  124. package/src/DurableObjectDefinition.ts +22 -22
  125. package/src/DurableObjectNamespace.ts +4 -1
  126. package/src/DurableObjectRpcWebSocket.ts +7 -1
  127. package/src/DurableObjectSqlite.ts +2 -1
  128. package/src/DurableObjectState.ts +4 -1
  129. package/src/DurableObjectStorage.ts +11 -13
  130. package/src/DurableObjectWebSocket.ts +5 -1
  131. package/src/Email.ts +5 -1
  132. package/src/Environment.ts +6 -1
  133. package/src/Hyperdrive.ts +4 -1
  134. package/src/HyperdrivePg.ts +3 -1
  135. package/src/Images.ts +7 -1
  136. package/src/Kv.ts +7 -1
  137. package/src/Mcp.ts +13 -13
  138. package/src/Queue.ts +3 -1
  139. package/src/QueueBinding.ts +5 -1
  140. package/src/QueueDefinition.ts +4 -1
  141. package/src/R2.ts +7 -1
  142. package/src/Rpc.ts +4 -1
  143. package/src/RpcDefinition.ts +4 -1
  144. package/src/RpcTracing.ts +9 -1
  145. package/src/Sandbox.ts +7 -1
  146. package/src/ServiceBinding.ts +6 -1
  147. package/src/Vectorize.ts +7 -1
  148. package/src/Vitest.ts +5 -1
  149. package/src/WebTransport.ts +6 -1
  150. package/src/Worker.ts +10 -16
  151. package/src/WorkerDefinition.ts +3 -1
  152. package/src/WorkersAi.ts +7 -1
  153. package/src/Workflow.ts +8 -11
  154. package/src/WorkflowBinding.ts +6 -1
  155. package/src/WorkflowDefinition.ts +4 -1
  156. package/src/internal/Entrypoint.ts +3 -1
  157. package/src/internal/ErrorMessage.ts +1 -1
  158. package/src/internal/NativeCallback.ts +3 -1
  159. package/src/internal/RpcInvocation.ts +5 -1
  160. package/src/internal/Runtime.ts +5 -1
  161. package/src/internal/Telemetry.ts +4 -3
  162. package/src/internal/WorkerContext.ts +3 -1
  163. package/dist/Binding-DKcLrQCM.d.mts +0 -94
  164. package/dist/DurableObjectState-DJ0K-zyd.d.mts +0 -244
  165. package/dist/Worker-XsGJsCJX.mjs +0 -885
  166. 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 };