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,52 @@
|
|
|
1
|
+
import * as Effect from "effect/Effect";
|
|
2
|
+
import * as Schema from "effect/Schema";
|
|
3
|
+
import * as Tracer from "effect/Tracer";
|
|
4
|
+
declare namespace RpcTracing_d_exports {
|
|
5
|
+
export { ReceiverOptions, RpcInvocationInfo, RpcTraceContext, withRpcClientSpan, withRpcServerSpan, withRpcTraceContext };
|
|
6
|
+
}
|
|
7
|
+
/**
|
|
8
|
+
* Live native RPC metadata. Opted-in receivers reserve a valid trailing value
|
|
9
|
+
* with this tag for transport context; do not use it as a final domain argument.
|
|
10
|
+
* Never store this in durable messages or envelopes.
|
|
11
|
+
*/
|
|
12
|
+
declare const RpcTraceContext: Schema.Struct<{
|
|
13
|
+
readonly _tag: Schema.Literal<"effect-cf/RpcTraceContext/v1">;
|
|
14
|
+
readonly traceId: Schema.String;
|
|
15
|
+
readonly spanId: Schema.String;
|
|
16
|
+
readonly sampled: Schema.Boolean;
|
|
17
|
+
}>;
|
|
18
|
+
type RpcTraceContext = typeof RpcTraceContext.Type;
|
|
19
|
+
interface ReceiverOptions {
|
|
20
|
+
/** Stable service name, never an instance id or capability URL. */
|
|
21
|
+
readonly service: string;
|
|
22
|
+
}
|
|
23
|
+
/** Per-invocation metadata passed to Worker and DurableObject RunSymbol overrides. */
|
|
24
|
+
interface RpcInvocationInfo {
|
|
25
|
+
readonly service: string;
|
|
26
|
+
readonly method: string;
|
|
27
|
+
/** Native arguments with valid, opted-in trace metadata removed. Do not log them. */
|
|
28
|
+
readonly args: ReadonlyArray<unknown>;
|
|
29
|
+
/**
|
|
30
|
+
* Set after a definition-backed receiver decodes its arguments, before its
|
|
31
|
+
* handler runs. Absent before decoding and when decoding fails. Do not log it.
|
|
32
|
+
*/
|
|
33
|
+
readonly decodedArgs?: ReadonlyArray<unknown>;
|
|
34
|
+
readonly parent?: RpcTraceContext;
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Appends the current live parent only for a receiver that has opted in.
|
|
38
|
+
* Call this inside the CLIENT span, immediately before the native invocation.
|
|
39
|
+
* With no valid propagating parent, the original argument array is returned.
|
|
40
|
+
*/
|
|
41
|
+
declare const withRpcTraceContext: (args: readonly unknown[]) => Effect.Effect<readonly unknown[], never, never>;
|
|
42
|
+
/** Wrap the whole call, including native result resolution and success decoding. */
|
|
43
|
+
declare const withRpcClientSpan: <A, E, R>(effect: Effect.Effect<A, E, R>, binding: string, method: string) => Effect.Effect<A, E, Exclude<R, Tracer.ParentSpan>>;
|
|
44
|
+
/**
|
|
45
|
+
* Optional application instrumentation for the entire receiver effect.
|
|
46
|
+
* Use in a RunSymbol override to include argument decode, handler and encode.
|
|
47
|
+
* Records stable service/method attributes and failure status, not argument or
|
|
48
|
+
* error payloads. The original typed failure still propagates to the caller.
|
|
49
|
+
*/
|
|
50
|
+
declare const withRpcServerSpan: <A, E, R>(effect: Effect.Effect<A, E, R>, invocation: RpcInvocationInfo) => Effect.Effect<A, E, Exclude<R, Tracer.ParentSpan>>;
|
|
51
|
+
//#endregion
|
|
52
|
+
export { ReceiverOptions, RpcInvocationInfo, RpcTraceContext, RpcTracing_d_exports, withRpcClientSpan, withRpcServerSpan, withRpcTraceContext };
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import { __exportAll } from "./_virtual/_rolldown/runtime.mjs";
|
|
2
|
+
import * as Context from "effect/Context";
|
|
3
|
+
import * as Effect from "effect/Effect";
|
|
4
|
+
import * as Schema from "effect/Schema";
|
|
5
|
+
import * as Option from "effect/Option";
|
|
6
|
+
import * as Cause from "effect/Cause";
|
|
7
|
+
import * as Exit from "effect/Exit";
|
|
8
|
+
import * as Clock from "effect/Clock";
|
|
9
|
+
import * as Tracer from "effect/Tracer";
|
|
10
|
+
import * as References from "effect/References";
|
|
11
|
+
//#region src/RpcTracing.ts
|
|
12
|
+
var RpcTracing_exports = /* @__PURE__ */ __exportAll({
|
|
13
|
+
RpcTraceContext: () => RpcTraceContext,
|
|
14
|
+
withRpcClientSpan: () => withRpcClientSpan,
|
|
15
|
+
withRpcServerSpan: () => withRpcServerSpan,
|
|
16
|
+
withRpcTraceContext: () => withRpcTraceContext
|
|
17
|
+
});
|
|
18
|
+
/**
|
|
19
|
+
* Live native RPC metadata. Opted-in receivers reserve a valid trailing value
|
|
20
|
+
* with this tag for transport context; do not use it as a final domain argument.
|
|
21
|
+
* Never store this in durable messages or envelopes.
|
|
22
|
+
*/
|
|
23
|
+
const RpcTraceContext = Schema.Struct({
|
|
24
|
+
_tag: Schema.Literal("effect-cf/RpcTraceContext/v1"),
|
|
25
|
+
traceId: Schema.String.check(Schema.isPattern(/^(?!0{32}$)[0-9a-f]{32}$/)),
|
|
26
|
+
spanId: Schema.String.check(Schema.isPattern(/^(?!0{16}$)[0-9a-f]{16}$/)),
|
|
27
|
+
sampled: Schema.Boolean
|
|
28
|
+
});
|
|
29
|
+
const isRpcTraceContext = Schema.is(RpcTraceContext);
|
|
30
|
+
/**
|
|
31
|
+
* Appends the current live parent only for a receiver that has opted in.
|
|
32
|
+
* Call this inside the CLIENT span, immediately before the native invocation.
|
|
33
|
+
* With no valid propagating parent, the original argument array is returned.
|
|
34
|
+
*/
|
|
35
|
+
const withRpcTraceContext = Effect.fnUntraced(function* (args) {
|
|
36
|
+
if (yield* Tracer.DisablePropagation) return args;
|
|
37
|
+
const parent = yield* Effect.serviceOption(Tracer.ParentSpan);
|
|
38
|
+
if (Option.isNone(parent) || Context.get(parent.value.annotations, Tracer.DisablePropagation)) return args;
|
|
39
|
+
const context = {
|
|
40
|
+
_tag: "effect-cf/RpcTraceContext/v1",
|
|
41
|
+
traceId: parent.value.traceId,
|
|
42
|
+
spanId: parent.value.spanId,
|
|
43
|
+
sampled: parent.value.sampled
|
|
44
|
+
};
|
|
45
|
+
return isRpcTraceContext(context) ? [...args, context] : args;
|
|
46
|
+
});
|
|
47
|
+
const attributes = (service, method) => ({
|
|
48
|
+
"sentry.op": "rpc",
|
|
49
|
+
"rpc.system.name": "cloudflare",
|
|
50
|
+
"rpc.method": `${service}/${method}`,
|
|
51
|
+
"server.address": service
|
|
52
|
+
});
|
|
53
|
+
const withRpcSpan = (effect, service, method, options) => Effect.useSpan(`${service}/${method}`, {
|
|
54
|
+
...options,
|
|
55
|
+
attributes: attributes(service, method)
|
|
56
|
+
}, (span) => effect.pipe(Effect.withParentSpan(span), Effect.onExit((exit) => {
|
|
57
|
+
if (Exit.isSuccess(exit) || Cause.hasInterruptsOnly(exit.cause) || span.status._tag === "Ended") return Effect.void;
|
|
58
|
+
return Effect.gen(function* () {
|
|
59
|
+
const endTime = (yield* References.TracerTimingEnabled) ? yield* Clock.currentTimeNanos : 0n;
|
|
60
|
+
span.attribute("error.type", "_OTHER");
|
|
61
|
+
span.end(endTime, Exit.fail("RPC failed"));
|
|
62
|
+
});
|
|
63
|
+
})));
|
|
64
|
+
/** Wrap the whole call, including native result resolution and success decoding. */
|
|
65
|
+
const withRpcClientSpan = (effect, binding, method) => withRpcSpan(effect, binding, method, { kind: "client" });
|
|
66
|
+
/**
|
|
67
|
+
* Optional application instrumentation for the entire receiver effect.
|
|
68
|
+
* Use in a RunSymbol override to include argument decode, handler and encode.
|
|
69
|
+
* Records stable service/method attributes and failure status, not argument or
|
|
70
|
+
* error payloads. The original typed failure still propagates to the caller.
|
|
71
|
+
*/
|
|
72
|
+
const withRpcServerSpan = (effect, invocation) => withRpcSpan(effect, invocation.service, invocation.method, {
|
|
73
|
+
kind: "server",
|
|
74
|
+
parent: invocation.parent === void 0 ? void 0 : Tracer.externalSpan(invocation.parent)
|
|
75
|
+
});
|
|
76
|
+
//#endregion
|
|
77
|
+
export { RpcTraceContext, RpcTracing_exports, withRpcClientSpan, withRpcServerSpan, withRpcTraceContext };
|
package/dist/Sandbox.d.mts
CHANGED
|
@@ -1,6 +1,11 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
1
|
+
import { WorkerEnvironment } from "./Environment.mjs";
|
|
2
|
+
import { BindingNotFoundError, BindingValidationError } from "./Binding.mjs";
|
|
3
|
+
import { ContainerStartOptions, ContainerStopSignal } from "./ContainerNamespace.mjs";
|
|
4
|
+
import * as Context$1 from "effect/Context";
|
|
5
|
+
import * as Effect from "effect/Effect";
|
|
6
|
+
import * as Option from "effect/Option";
|
|
7
|
+
import * as Stream from "effect/Stream";
|
|
8
|
+
import { Layer } from "effect";
|
|
4
9
|
import { BackupOptions, BackupOptions as BackupOptions$1, CheckChangesOptions, CheckChangesOptions as CheckChangesOptions$1, CheckChangesResult, CheckChangesResult as CheckChangesResult$1, CreateTerminalOptions, CreateTerminalOptions as CreateTerminalOptions$1, DirectoryBackup, DirectoryBackup as DirectoryBackup$1, ExecOptions, ExecOptions as ExecOptions$1, FileWatchSSEEvent, FileWatchSSEEvent as FileWatchSSEEvent$1, ISandbox, ISandbox as ISandbox$1, ListFilesOptions, ListFilesOptions as ListFilesOptions$1, MountBucketOptions, MountBucketOptions as MountBucketOptions$1, ProcessExit, ProcessExit as ProcessExit$1, ProcessLogEvent, ProcessLogEvent as ProcessLogEvent$1, ProcessLogsOptions, ProcessLogsOptions as ProcessLogsOptions$1, ProcessOutput, ProcessOutput as ProcessOutput$1, ProcessOutputOptions, ProcessOutputOptions as ProcessOutputOptions$1, ProcessStatus, ProcessStatus as ProcessStatus$1, RestoreBackupResult, RestoreBackupResult as RestoreBackupResult$1, SandboxCommand, SandboxCommand as SandboxCommand$1, SandboxOptions, SandboxOptions as SandboxOptions$1, SandboxProcess, SandboxProcess as SandboxProcess$1, Terminal, Terminal as Terminal$1, TerminalOutputCursor, TerminalOutputCursor as TerminalOutputCursor$1, TerminalOutputEvent, TerminalOutputEvent as TerminalOutputEvent$1, TerminalOutputOptions, TerminalOutputOptions as TerminalOutputOptions$1, TerminalSnapshot, TerminalSnapshot as TerminalSnapshot$1, TunnelInfo, TunnelInfo as TunnelInfo$1, TunnelOptions, TunnelOptions as TunnelOptions$1, WaitForExitOptions, WaitForExitOptions as WaitForExitOptions$1, WaitForLogOptions, WaitForLogOptions as WaitForLogOptions$1, WaitForLogResult, WaitForLogResult as WaitForLogResult$1, WaitForPortOptions, WaitForPortOptions as WaitForPortOptions$1, WatchOptions, WatchOptions as WatchOptions$1 } from "@cloudflare/sandbox";
|
|
5
10
|
//#region src/Sandbox.d.ts
|
|
6
11
|
interface SandboxDefinition {
|
|
@@ -159,7 +164,7 @@ interface SandboxNamespaceClient<Namespace extends SandboxNamespaceResource = Sa
|
|
|
159
164
|
type LayerOptions = {
|
|
160
165
|
readonly binding: string;
|
|
161
166
|
};
|
|
162
|
-
interface TagClass<Self, Id extends string, Namespace extends SandboxNamespaceResource = SandboxNamespaceResource> extends Context.ServiceClass<Self, `effect-cf/Sandbox/${Id}`, SandboxNamespaceClient<Namespace>> {
|
|
167
|
+
interface TagClass<Self, Id extends string, Namespace extends SandboxNamespaceResource = SandboxNamespaceResource> extends Context$1.ServiceClass<Self, `effect-cf/Sandbox/${Id}`, SandboxNamespaceClient<Namespace>> {
|
|
163
168
|
readonly id: Id;
|
|
164
169
|
readonly layer: (options: LayerOptions) => Layer.Layer<Self, BindingNotFoundError | BindingValidationError, WorkerEnvironment>;
|
|
165
170
|
readonly get: (name: string, options?: SandboxOptions$1) => Effect.Effect<SandboxInstanceClient, SandboxOperationError, Self>;
|
|
@@ -168,7 +173,7 @@ interface TagClass<Self, Id extends string, Namespace extends SandboxNamespaceRe
|
|
|
168
173
|
declare const fromSandboxClient: (client: SandboxClientResource, definition: SandboxDefinition, instance: string) => SandboxInstanceClient;
|
|
169
174
|
declare const isSandboxNamespaceResource: <Candidate>(value: Candidate) => value is Candidate & SandboxNamespaceResource;
|
|
170
175
|
declare const makeClient: (definition: SandboxDefinition) => <Namespace extends SandboxNamespaceResource>(namespace: Namespace) => SandboxNamespaceClient<Namespace>;
|
|
171
|
-
declare const layer: <Self, Namespace extends SandboxNamespaceResource>(tag: Context.Service<Self, SandboxNamespaceClient<Namespace>>, definition: SandboxDefinition) => Layer.Layer<Self, BindingNotFoundError | BindingValidationError, WorkerEnvironment>;
|
|
176
|
+
declare const layer: <Self, Namespace extends SandboxNamespaceResource>(tag: Context$1.Service<Self, SandboxNamespaceClient<Namespace>>, definition: SandboxDefinition) => Layer.Layer<Self, BindingNotFoundError | BindingValidationError, WorkerEnvironment>;
|
|
172
177
|
declare const make: <Id extends string>(id: Id) => TagClass<SandboxNamespaceService<Id>, Id, SandboxNamespaceResource>;
|
|
173
178
|
declare const SandboxNamespaceServiceTypeId: unique symbol;
|
|
174
179
|
interface SandboxNamespaceService<Id extends string> {
|
package/dist/Sandbox.mjs
CHANGED
|
@@ -1,6 +1,12 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
1
|
+
import { WorkerEnvironment } from "./Environment.mjs";
|
|
2
|
+
import { layer as layer$1 } from "./Binding.mjs";
|
|
3
|
+
import { causeMessage } from "./internal/ErrorMessage.mjs";
|
|
4
|
+
import * as Context from "effect/Context";
|
|
5
|
+
import * as Data from "effect/Data";
|
|
6
|
+
import * as Effect from "effect/Effect";
|
|
7
|
+
import * as Predicate from "effect/Predicate";
|
|
8
|
+
import * as Option from "effect/Option";
|
|
9
|
+
import * as Stream from "effect/Stream";
|
|
4
10
|
//#region src/Sandbox.ts
|
|
5
11
|
const expectedSandboxNamespace = "Sandbox Durable Object namespace binding with idFromName() and get()";
|
|
6
12
|
var SandboxOperationError = class extends Data.TaggedError("SandboxOperationError") {
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
import { WorkerEnvironment } from "./Environment.mjs";
|
|
2
|
+
import { BindingNotFoundError, BindingService, BindingValidationError } from "./Binding.mjs";
|
|
3
|
+
import { Provider, Result } 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, ServerApi } from "./WorkerDefinition.mjs";
|
|
7
|
+
import * as Effect from "effect/Effect";
|
|
8
|
+
import * as Schema$1 from "effect/Schema";
|
|
9
|
+
import { Context, Scope } from "effect";
|
|
10
|
+
declare namespace ServiceBinding_d_exports {
|
|
11
|
+
export { Service, ServiceBindingClient, ServiceBindingDefinition, ServiceBindingEffectClient, ServiceBindingFetchError, ServiceBindingRpcError, ServiceBindingStaticClient, ServiceFetcher, isServiceBindingClient, layer, makeClient, makeDirectMethods };
|
|
12
|
+
}
|
|
13
|
+
declare const TypeId: "effect-cf/ServiceBinding";
|
|
14
|
+
interface ServiceFetcher {
|
|
15
|
+
fetch(input: RequestInfo | URL, init?: RequestInit): Promise<Response>;
|
|
16
|
+
}
|
|
17
|
+
type RpcClient<Api> = { readonly [Key in keyof Api as Key extends string ? Api[Key] extends ((...args: Array<any>) => any) ? Key : never : never]: Api[Key]; };
|
|
18
|
+
type ReservedMethodName = ReservedMethodName$1 | "fetch";
|
|
19
|
+
type ServiceBindingClient<Api extends object> = ServiceFetcher & RpcClient<Provider<Api, ReservedMethodName>>;
|
|
20
|
+
type ApiFromDefinition<Definition> = Definition extends Definition$1.Any ? ServerApi<Definition> : never;
|
|
21
|
+
type ApiOrDefinition<Api extends object, Definition> = [Api] extends [never] ? ApiFromDefinition<Definition> : Api;
|
|
22
|
+
/**
|
|
23
|
+
* Binding metadata used to create an Effect service from a Worker binding.
|
|
24
|
+
*/
|
|
25
|
+
interface ServiceBindingDefinition<Definition extends Definition$1.Any | undefined = undefined> {
|
|
26
|
+
readonly binding: string;
|
|
27
|
+
readonly definition?: Definition;
|
|
28
|
+
/** Append live trace context only when the receiver also enables rpcTracing. */
|
|
29
|
+
readonly rpcTracing?: boolean;
|
|
30
|
+
}
|
|
31
|
+
declare const ServiceBindingFetchError_base: new <A extends Record<string, any> = {}>(args: import("effect/Types").VoidIfEmpty<{ readonly [P in keyof A as P extends "_tag" ? never : P]: A[P]; }>) => import("effect/Cause").YieldableError & {
|
|
32
|
+
readonly _tag: "ServiceBindingFetchError";
|
|
33
|
+
} & Readonly<A>;
|
|
34
|
+
/**
|
|
35
|
+
* Failure raised when calling `fetch` on a service binding.
|
|
36
|
+
*/
|
|
37
|
+
declare class ServiceBindingFetchError extends ServiceBindingFetchError_base<{
|
|
38
|
+
readonly binding: string;
|
|
39
|
+
readonly cause: unknown;
|
|
40
|
+
}> {
|
|
41
|
+
get message(): string;
|
|
42
|
+
}
|
|
43
|
+
declare const ServiceBindingRpcError_base: new <A extends Record<string, any> = {}>(args: import("effect/Types").VoidIfEmpty<{ readonly [P in keyof A as P extends "_tag" ? never : P]: A[P]; }>) => import("effect/Cause").YieldableError & {
|
|
44
|
+
readonly _tag: "ServiceBindingRpcError";
|
|
45
|
+
} & Readonly<A>;
|
|
46
|
+
/**
|
|
47
|
+
* Failure raised when invoking an RPC method on a service binding.
|
|
48
|
+
*/
|
|
49
|
+
declare class ServiceBindingRpcError extends ServiceBindingRpcError_base<{
|
|
50
|
+
readonly binding: string;
|
|
51
|
+
readonly method: string;
|
|
52
|
+
readonly cause: unknown;
|
|
53
|
+
}> {
|
|
54
|
+
get message(): string;
|
|
55
|
+
}
|
|
56
|
+
type ServiceMethodKey<Api> = AsyncMethodKey<Api>;
|
|
57
|
+
type ServiceMethodArgs<Api, Method extends keyof Api> = AsyncMethodArgs<Api, Method>;
|
|
58
|
+
type ServiceMethodSuccess<Api, Method extends keyof Api> = AsyncMethodSuccess<Api, Method>;
|
|
59
|
+
type ServiceMethodCloudflareReturn<Api, Method extends keyof Api> = AsyncMethodCloudflareReturn<Api, Method>;
|
|
60
|
+
type ServiceCall<R, Api> = <Method extends ServiceMethodKey<Api>>(method: Method, ...args: ServiceMethodArgs<Api, Method>) => Effect.Effect<ServiceMethodSuccess<Api, Method>, ServiceBindingRpcError, R>;
|
|
61
|
+
type DefinitionDirectMethods<R, Definition$2 extends Definition$1.Any> = { readonly [Method in Definition.MethodNames<Definition$2>]: (...args: Method$1.Args<Definition$2["methods"][Method]>) => Effect.Effect<Method$1.Success<Definition$2["methods"][Method]>, ServiceBindingRpcError, R>; };
|
|
62
|
+
type DirectMethods<R, Definition> = Definition extends Definition$1.Any ? DefinitionDirectMethods<R, Definition> : {};
|
|
63
|
+
type ServiceBindingEffectClient<Api extends object, Definition extends Definition$1.Any | undefined = undefined> = DirectMethods<never, Definition> & {
|
|
64
|
+
readonly fetch: (input: RequestInfo | URL, init?: RequestInit) => Effect.Effect<globalThis.Response, ServiceBindingFetchError>;
|
|
65
|
+
/**
|
|
66
|
+
* Invokes a Worker RPC method and returns Cloudflare's raw RPC result.
|
|
67
|
+
*
|
|
68
|
+
* This preserves Cloudflare RPC behavior such as promise-like pipelining and
|
|
69
|
+
* transferable / disposable result objects. It does not resolve the returned
|
|
70
|
+
* promise-like value and it does not decode definition-backed success schemas.
|
|
71
|
+
*
|
|
72
|
+
* Most application code should use {@link call} instead.
|
|
73
|
+
*/
|
|
74
|
+
readonly rpc: <Method extends ServiceMethodKey<Api>>(method: Method, ...args: ServiceMethodArgs<Api, Method>) => Effect.Effect<ServiceMethodCloudflareReturn<Api, Method>, ServiceBindingRpcError>;
|
|
75
|
+
/**
|
|
76
|
+
* Invokes a Worker RPC method, resolves Cloudflare's RPC result, and decodes
|
|
77
|
+
* the success value when the binding was created from a definition.
|
|
78
|
+
*
|
|
79
|
+
* This is the normal choice when application code wants the final typed value.
|
|
80
|
+
*/
|
|
81
|
+
readonly call: <Method extends ServiceMethodKey<Api>>(method: Method, ...args: ServiceMethodArgs<Api, Method>) => Effect.Effect<ServiceMethodSuccess<Api, Method>, ServiceBindingRpcError>;
|
|
82
|
+
/**
|
|
83
|
+
* Invokes a Worker RPC method in the current `Scope`, resolves Cloudflare's RPC
|
|
84
|
+
* result, decodes definition-backed success values, and disposes the resolved
|
|
85
|
+
* result when the scope closes if it implements `Symbol.dispose`.
|
|
86
|
+
*
|
|
87
|
+
* Use this for RPC methods that return Cloudflare RPC resources or other
|
|
88
|
+
* disposable objects whose lifetime should be tied to an Effect scope.
|
|
89
|
+
*/
|
|
90
|
+
readonly scopedCall: <Method extends ServiceMethodKey<Api>>(method: Method, ...args: ServiceMethodArgs<Api, Method>) => Effect.Effect<Awaited<ServiceMethodSuccess<Api, Method>>, ServiceBindingRpcError, Scope.Scope>;
|
|
91
|
+
};
|
|
92
|
+
type ServiceBindingStaticClient<R, Api extends object, Definition extends Definition$1.Any | undefined = undefined> = DirectMethods<R, Definition> & {
|
|
93
|
+
readonly fetch: (input: RequestInfo | URL, init?: RequestInit) => Effect.Effect<globalThis.Response, ServiceBindingFetchError, R>;
|
|
94
|
+
readonly rpc: <Method extends ServiceMethodKey<Api>>(method: Method, ...args: ServiceMethodArgs<Api, Method>) => Effect.Effect<ServiceMethodCloudflareReturn<Api, Method>, ServiceBindingRpcError, R>;
|
|
95
|
+
readonly call: <Method extends ServiceMethodKey<Api>>(method: Method, ...args: ServiceMethodArgs<Api, Method>) => Effect.Effect<ServiceMethodSuccess<Api, Method>, ServiceBindingRpcError, R>;
|
|
96
|
+
readonly scopedCall: <Method extends ServiceMethodKey<Api>>(method: Method, ...args: ServiceMethodArgs<Api, Method>) => Effect.Effect<Awaited<ServiceMethodSuccess<Api, Method>>, ServiceBindingRpcError, Scope.Scope | R>;
|
|
97
|
+
};
|
|
98
|
+
type ServiceBindingValue = Schema$1.Schema.Type<typeof Schema$1.Unknown>;
|
|
99
|
+
declare const isServiceBindingClient: <Api extends object>(value: ServiceBindingValue) => value is ServiceBindingClient<Api>;
|
|
100
|
+
declare const makeClient: <Api extends object, const Definition extends Definition$1.Any | undefined = undefined>(definition: ServiceBindingDefinition<Definition>) => ((service: ServiceBindingClient<Api>) => ServiceBindingEffectClient<Api, Definition>);
|
|
101
|
+
declare const layer: <Self, Api extends object, const Definition extends Definition$1.Any | undefined = undefined>(tag: Context.Service<Self, ServiceBindingEffectClient<Api, Definition>>, definition: ServiceBindingDefinition<Definition>) => import("effect/Layer").Layer<Self, BindingNotFoundError | BindingValidationError, WorkerEnvironment>;
|
|
102
|
+
declare const Service: <Self, Api extends object = never>() => <Id extends string, const Definition extends Definition$1.Any | undefined = undefined>(id: Id, definition: ServiceBindingDefinition<Definition>) => BindingService<Self, Id, ServiceBindingEffectClient<ApiOrDefinition<Api, Definition>, Definition>> & DirectMethods<Self, Definition> & {
|
|
103
|
+
readonly [TypeId]: typeof TypeId;
|
|
104
|
+
readonly definition: ServiceBindingDefinition<Definition>;
|
|
105
|
+
readonly fetch: (input: URL | RequestInfo<unknown, CfProperties<unknown>>, init?: RequestInit<CfProperties<unknown>> | undefined) => Effect.Effect<Response, ServiceBindingFetchError, Self>;
|
|
106
|
+
readonly rpc: <Method extends ServiceMethodKey<ApiOrDefinition<Api, Definition>>>(method: Method, ...args: AsyncMethodArgs<ApiOrDefinition<Api, Definition>, Method>) => Effect.Effect<Result<AsyncMethodSuccess<ApiOrDefinition<Api, Definition>, Method>>, ServiceBindingRpcError, Self>;
|
|
107
|
+
readonly call: <Method extends ServiceMethodKey<ApiOrDefinition<Api, Definition>>>(method: Method, ...args: AsyncMethodArgs<ApiOrDefinition<Api, Definition>, Method>) => Effect.Effect<AsyncMethodSuccess<ApiOrDefinition<Api, Definition>, Method>, ServiceBindingRpcError, Self>;
|
|
108
|
+
readonly scopedCall: <Method extends ServiceMethodKey<ApiOrDefinition<Api, Definition>>>(method: Method, ...args: AsyncMethodArgs<ApiOrDefinition<Api, Definition>, Method>) => Effect.Effect<Awaited<AsyncMethodSuccess<ApiOrDefinition<Api, Definition>, Method>>, ServiceBindingRpcError, Self | Scope.Scope>;
|
|
109
|
+
};
|
|
110
|
+
declare const makeDirectMethods: <R, Api, Definition extends Definition$1.Any | undefined>(rpcDefinition: Definition | undefined, call: ServiceCall<R, Api>) => DirectMethods<R, Definition>;
|
|
111
|
+
//#endregion
|
|
112
|
+
export { Service, ServiceBindingClient, ServiceBindingDefinition, ServiceBindingEffectClient, ServiceBindingFetchError, ServiceBindingRpcError, ServiceBindingStaticClient, ServiceBinding_d_exports, ServiceFetcher, isServiceBindingClient, layer, makeClient, makeDirectMethods };
|
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
import { __exportAll } from "./_virtual/_rolldown/runtime.mjs";
|
|
2
|
+
import { Service as Service$1, 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 Schema from "effect/Schema";
|
|
11
|
+
import * as Predicate from "effect/Predicate";
|
|
12
|
+
import * as Option from "effect/Option";
|
|
13
|
+
//#region src/ServiceBinding.ts
|
|
14
|
+
var ServiceBinding_exports = /* @__PURE__ */ __exportAll({
|
|
15
|
+
Service: () => Service,
|
|
16
|
+
ServiceBindingFetchError: () => ServiceBindingFetchError,
|
|
17
|
+
ServiceBindingRpcError: () => ServiceBindingRpcError,
|
|
18
|
+
isServiceBindingClient: () => isServiceBindingClient,
|
|
19
|
+
layer: () => layer,
|
|
20
|
+
makeClient: () => makeClient,
|
|
21
|
+
makeDirectMethods: () => makeDirectMethods
|
|
22
|
+
});
|
|
23
|
+
const TypeId = "effect-cf/ServiceBinding";
|
|
24
|
+
const expectedServiceBinding = "Worker service binding with fetch()";
|
|
25
|
+
/**
|
|
26
|
+
* Failure raised when calling `fetch` on a service binding.
|
|
27
|
+
*/
|
|
28
|
+
var ServiceBindingFetchError = class extends Data.TaggedError("ServiceBindingFetchError") {
|
|
29
|
+
get message() {
|
|
30
|
+
return `Service binding "${this.binding}" fetch failed: ${causeMessage(this.cause)}`;
|
|
31
|
+
}
|
|
32
|
+
};
|
|
33
|
+
/**
|
|
34
|
+
* Failure raised when invoking an RPC method on a service binding.
|
|
35
|
+
*/
|
|
36
|
+
var ServiceBindingRpcError = class extends Data.TaggedError("ServiceBindingRpcError") {
|
|
37
|
+
get message() {
|
|
38
|
+
return `Service binding "${this.binding}" RPC method "${this.method}" failed: ${causeMessage(this.cause)}`;
|
|
39
|
+
}
|
|
40
|
+
};
|
|
41
|
+
const ServiceBindingSchema = Schema.declare((value) => Predicate.hasProperty(value, "fetch") && Predicate.isFunction(value.fetch));
|
|
42
|
+
const decodeServiceBinding = Schema.decodeUnknownOption(ServiceBindingSchema);
|
|
43
|
+
const isServiceBindingClient = (value) => Option.isSome(decodeServiceBinding(value));
|
|
44
|
+
const makeClient = (definition) => {
|
|
45
|
+
return (service) => {
|
|
46
|
+
const fetch = Effect.fn("ServiceBinding.fetch")(function* (input, init) {
|
|
47
|
+
return yield* Effect.tryPromise({
|
|
48
|
+
try: (signal) => {
|
|
49
|
+
const callerSignal = init?.signal !== void 0 ? init.signal : input instanceof Request ? input.signal : void 0;
|
|
50
|
+
return service.fetch(input, {
|
|
51
|
+
...init,
|
|
52
|
+
signal: callerSignal === null || callerSignal === void 0 ? signal : AbortSignal.any([callerSignal, signal])
|
|
53
|
+
});
|
|
54
|
+
},
|
|
55
|
+
catch: (cause) => new ServiceBindingFetchError({
|
|
56
|
+
binding: definition.binding,
|
|
57
|
+
cause
|
|
58
|
+
})
|
|
59
|
+
});
|
|
60
|
+
});
|
|
61
|
+
const rpc = Effect.fnUntraced(function* (method, ...args) {
|
|
62
|
+
const methodName = String(method);
|
|
63
|
+
const encodedArgs = definition.definition === void 0 ? args : yield* encodeArgs(definition.definition, methodName, args).pipe(Effect.mapError((cause) => new ServiceBindingRpcError({
|
|
64
|
+
binding: definition.binding,
|
|
65
|
+
method: methodName,
|
|
66
|
+
cause
|
|
67
|
+
})));
|
|
68
|
+
const nativeArgs = definition.rpcTracing ? yield* withRpcTraceContext(encodedArgs) : encodedArgs;
|
|
69
|
+
return yield* invokeRpcMethod(service, method, nativeArgs, (cause) => new ServiceBindingRpcError({
|
|
70
|
+
binding: definition.binding,
|
|
71
|
+
method: methodName,
|
|
72
|
+
cause
|
|
73
|
+
}));
|
|
74
|
+
});
|
|
75
|
+
const decodeSuccess$1 = Effect.fnUntraced(function* (methodName, value) {
|
|
76
|
+
if (definition.definition === void 0) return value;
|
|
77
|
+
return yield* decodeSuccess(definition.definition, methodName, value).pipe(Effect.mapError((cause) => new ServiceBindingRpcError({
|
|
78
|
+
binding: definition.binding,
|
|
79
|
+
method: methodName,
|
|
80
|
+
cause
|
|
81
|
+
})));
|
|
82
|
+
});
|
|
83
|
+
const call = Effect.fnUntraced(function* (method, ...args) {
|
|
84
|
+
const methodName = String(method);
|
|
85
|
+
const value = yield* resolve(yield* rpc(method, ...args)).pipe(Effect.mapError((cause) => new ServiceBindingRpcError({
|
|
86
|
+
binding: definition.binding,
|
|
87
|
+
method: methodName,
|
|
88
|
+
cause
|
|
89
|
+
})));
|
|
90
|
+
return yield* decodeSuccess$1(methodName, value);
|
|
91
|
+
}, (effect, ...args) => withRpcClientSpan(effect, definition.binding, String(args[0])));
|
|
92
|
+
const scopedCall = Effect.fnUntraced(function* (method, ...args) {
|
|
93
|
+
const methodName = String(method);
|
|
94
|
+
const result = yield* rpc(method, ...args);
|
|
95
|
+
const value = yield* scoped(result).pipe(Effect.mapError((cause) => new ServiceBindingRpcError({
|
|
96
|
+
binding: definition.binding,
|
|
97
|
+
method: methodName,
|
|
98
|
+
cause
|
|
99
|
+
})));
|
|
100
|
+
return yield* decodeSuccess$1(methodName, value);
|
|
101
|
+
}, (effect, ...args) => withRpcClientSpan(effect, definition.binding, String(args[0])));
|
|
102
|
+
const directMethods = makeDirectMethods(definition.definition, call);
|
|
103
|
+
return Object.assign(directMethods, {
|
|
104
|
+
fetch,
|
|
105
|
+
rpc,
|
|
106
|
+
call,
|
|
107
|
+
scopedCall
|
|
108
|
+
});
|
|
109
|
+
};
|
|
110
|
+
};
|
|
111
|
+
const layer = (tag, definition) => layer$1(tag, definition.binding, (value) => isServiceBindingClient(value), makeClient(definition), { expected: expectedServiceBinding });
|
|
112
|
+
const Service = () => (id, definition) => {
|
|
113
|
+
const tag = Service$1()(id, definition.binding, (value) => isServiceBindingClient(value), makeClient(definition));
|
|
114
|
+
const fetch = Effect.fnUntraced(function* (input, init) {
|
|
115
|
+
return yield* (yield* tag).fetch(input, init);
|
|
116
|
+
});
|
|
117
|
+
const rpc = Effect.fnUntraced(function* (method, ...args) {
|
|
118
|
+
return yield* (yield* tag).rpc(method, ...args);
|
|
119
|
+
});
|
|
120
|
+
const call = Effect.fnUntraced(function* (method, ...args) {
|
|
121
|
+
return yield* (yield* tag).call(method, ...args);
|
|
122
|
+
});
|
|
123
|
+
const scopedCall = Effect.fnUntraced(function* (method, ...args) {
|
|
124
|
+
return yield* (yield* tag).scopedCall(method, ...args);
|
|
125
|
+
});
|
|
126
|
+
const directMethods = makeDirectMethods(definition.definition, call);
|
|
127
|
+
return Object.assign(tag, directMethods, {
|
|
128
|
+
[TypeId]: TypeId,
|
|
129
|
+
definition,
|
|
130
|
+
fetch,
|
|
131
|
+
rpc,
|
|
132
|
+
call,
|
|
133
|
+
scopedCall
|
|
134
|
+
});
|
|
135
|
+
};
|
|
136
|
+
const makeDirectMethods = (rpcDefinition, call) => {
|
|
137
|
+
const methods = {};
|
|
138
|
+
if (rpcDefinition !== void 0) {
|
|
139
|
+
const invoke = call;
|
|
140
|
+
for (const methodName of Object.keys(rpcDefinition.methods)) methods[methodName] = (...args) => invoke(methodName, ...args);
|
|
141
|
+
}
|
|
142
|
+
return methods;
|
|
143
|
+
};
|
|
144
|
+
//#endregion
|
|
145
|
+
export { Service, ServiceBindingFetchError, ServiceBindingRpcError, ServiceBinding_exports, isServiceBindingClient, layer, makeClient, makeDirectMethods };
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import { WorkerEnvironment } from "./Environment.mjs";
|
|
2
|
+
import { BindingNotFoundError, BindingValidationError } from "./Binding.mjs";
|
|
3
|
+
import * as Context$1 from "effect/Context";
|
|
4
|
+
import * as Effect from "effect/Effect";
|
|
5
|
+
import * as Schema$1 from "effect/Schema";
|
|
6
|
+
import { Layer } from "effect";
|
|
7
|
+
declare namespace Vectorize_d_exports {
|
|
8
|
+
export { LayerOptions, Tag, TagClass, VectorizeBinding, VectorizeClient, VectorizeDefinition, VectorizeIndexDetails, VectorizeIndexInfo, VectorizeMatch, VectorizeMatches, VectorizeMutation, VectorizeOperation, VectorizeOperationError, VectorizeQueryOptions, VectorizeService, VectorizeValues, VectorizeVector, VectorizeVectorMetadata, VectorizeVectorMetadataFilter, VectorizeVectorMetadataValue, isVectorizeBinding, layer, make, makeClient };
|
|
9
|
+
}
|
|
10
|
+
type VectorizeOperation = "describe" | "query" | "queryById" | "insert" | "upsert" | "deleteByIds" | "getByIds";
|
|
11
|
+
declare const VectorizeOperationError_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 & {
|
|
12
|
+
readonly _tag: "VectorizeOperationError";
|
|
13
|
+
} & Readonly<A>;
|
|
14
|
+
declare class VectorizeOperationError extends VectorizeOperationError_base<{
|
|
15
|
+
readonly binding: string;
|
|
16
|
+
readonly operation: VectorizeOperation;
|
|
17
|
+
readonly cause: unknown;
|
|
18
|
+
}> {
|
|
19
|
+
get message(): string;
|
|
20
|
+
}
|
|
21
|
+
interface VectorizeDefinition {
|
|
22
|
+
readonly binding: string;
|
|
23
|
+
}
|
|
24
|
+
type VectorizeBinding = CloudflareVectorize | CloudflareVectorizeIndex;
|
|
25
|
+
type VectorizeVector = CloudflareVectorizeVector;
|
|
26
|
+
type VectorizeVectorMetadata = CloudflareVectorizeVectorMetadata;
|
|
27
|
+
type VectorizeVectorMetadataValue = CloudflareVectorizeVectorMetadataValue;
|
|
28
|
+
type VectorizeVectorMetadataFilter = CloudflareVectorizeVectorMetadataFilter;
|
|
29
|
+
type VectorizeQueryOptions = CloudflareVectorizeQueryOptions;
|
|
30
|
+
type VectorizeMatches = CloudflareVectorizeMatches;
|
|
31
|
+
type VectorizeMatch = CloudflareVectorizeMatch;
|
|
32
|
+
type VectorizeIndexInfo = CloudflareVectorizeIndexInfo;
|
|
33
|
+
type VectorizeIndexDetails = CloudflareVectorizeIndexDetails;
|
|
34
|
+
type VectorizeMutation = CloudflareVectorizeAsyncMutation | CloudflareVectorizeVectorMutation;
|
|
35
|
+
type VectorizeValues = Float32Array | Float64Array | ReadonlyArray<number>;
|
|
36
|
+
interface VectorizeClient {
|
|
37
|
+
readonly describe: Effect.Effect<VectorizeIndexInfo | VectorizeIndexDetails, VectorizeOperationError>;
|
|
38
|
+
readonly query: (vector: VectorizeValues, options?: VectorizeQueryOptions) => Effect.Effect<VectorizeMatches, VectorizeOperationError>;
|
|
39
|
+
readonly queryById: (vectorId: string, options?: VectorizeQueryOptions) => Effect.Effect<VectorizeMatches, VectorizeOperationError>;
|
|
40
|
+
readonly insert: (vectors: ReadonlyArray<VectorizeVector>) => Effect.Effect<VectorizeMutation, VectorizeOperationError>;
|
|
41
|
+
readonly upsert: (vectors: ReadonlyArray<VectorizeVector>) => Effect.Effect<VectorizeMutation, VectorizeOperationError>;
|
|
42
|
+
readonly deleteByIds: (ids: ReadonlyArray<string>) => Effect.Effect<VectorizeMutation, VectorizeOperationError>;
|
|
43
|
+
readonly delete: (ids: ReadonlyArray<string>) => Effect.Effect<VectorizeMutation, VectorizeOperationError>;
|
|
44
|
+
readonly getByIds: (ids: ReadonlyArray<string>) => Effect.Effect<ReadonlyArray<VectorizeVector>, VectorizeOperationError>;
|
|
45
|
+
readonly rawUnsafe: Effect.Effect<VectorizeBinding>;
|
|
46
|
+
readonly definition: VectorizeDefinition;
|
|
47
|
+
}
|
|
48
|
+
declare const VectorizeServiceTypeId: unique symbol;
|
|
49
|
+
interface VectorizeService<Id extends string> {
|
|
50
|
+
readonly [VectorizeServiceTypeId]: {
|
|
51
|
+
readonly id: Id;
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
type LayerOptions = {
|
|
55
|
+
readonly binding: string;
|
|
56
|
+
};
|
|
57
|
+
interface TagClass<Self, Id extends string> extends Context$1.ServiceClass<Self, Id, VectorizeClient> {
|
|
58
|
+
readonly id: Id;
|
|
59
|
+
readonly layer: (options: LayerOptions) => Layer.Layer<Self, BindingNotFoundError | BindingValidationError, WorkerEnvironment>;
|
|
60
|
+
}
|
|
61
|
+
type VectorizeBindingValue = Schema$1.Schema.Type<typeof Schema$1.Unknown>;
|
|
62
|
+
declare const isVectorizeBinding: (value: VectorizeBindingValue) => value is VectorizeBinding;
|
|
63
|
+
declare const makeClient: (definition: VectorizeDefinition) => (index: VectorizeBinding) => VectorizeClient;
|
|
64
|
+
declare const layer: <Self>(tag: Context$1.Service<Self, VectorizeClient>, definition: VectorizeDefinition) => Layer.Layer<Self, BindingNotFoundError | BindingValidationError, WorkerEnvironment>;
|
|
65
|
+
declare const make: <Id extends string>(id: Id) => TagClass<VectorizeService<Id>, Id>;
|
|
66
|
+
declare const Tag: <Self>() => <Id extends string>(id: Id) => TagClass<Self, Id>;
|
|
67
|
+
//#endregion
|
|
68
|
+
export { LayerOptions, Tag, TagClass, VectorizeBinding, VectorizeClient, VectorizeDefinition, VectorizeIndexDetails, VectorizeIndexInfo, VectorizeMatch, VectorizeMatches, VectorizeMutation, VectorizeOperation, VectorizeOperationError, VectorizeQueryOptions, VectorizeService, VectorizeValues, VectorizeVector, VectorizeVectorMetadata, VectorizeVectorMetadataFilter, VectorizeVectorMetadataValue, Vectorize_d_exports, isVectorizeBinding, layer, make, makeClient };
|
|
@@ -0,0 +1,76 @@
|
|
|
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 * as Context from "effect/Context";
|
|
5
|
+
import * as Data from "effect/Data";
|
|
6
|
+
import * as Effect from "effect/Effect";
|
|
7
|
+
import * as Schema from "effect/Schema";
|
|
8
|
+
import * as Predicate from "effect/Predicate";
|
|
9
|
+
import * as Option from "effect/Option";
|
|
10
|
+
//#region src/Vectorize.ts
|
|
11
|
+
var Vectorize_exports = /* @__PURE__ */ __exportAll({
|
|
12
|
+
Tag: () => Tag,
|
|
13
|
+
VectorizeOperationError: () => VectorizeOperationError,
|
|
14
|
+
isVectorizeBinding: () => isVectorizeBinding,
|
|
15
|
+
layer: () => layer,
|
|
16
|
+
make: () => make,
|
|
17
|
+
makeClient: () => makeClient
|
|
18
|
+
});
|
|
19
|
+
const expectedVectorizeBinding = "Vectorize index binding with describe(), query(), insert(), upsert(), deleteByIds(), and getByIds()";
|
|
20
|
+
var VectorizeOperationError = class extends Data.TaggedError("VectorizeOperationError") {
|
|
21
|
+
get message() {
|
|
22
|
+
return `Vectorize ${this.operation} failed for binding "${this.binding}": ${causeMessage(this.cause)}`;
|
|
23
|
+
}
|
|
24
|
+
};
|
|
25
|
+
const vectorizeError = (binding, operation, cause) => new VectorizeOperationError({
|
|
26
|
+
binding,
|
|
27
|
+
operation,
|
|
28
|
+
cause
|
|
29
|
+
});
|
|
30
|
+
const tryVectorizePromise = (binding, operation, evaluate) => Effect.tryPromise({
|
|
31
|
+
try: evaluate,
|
|
32
|
+
catch: (cause) => vectorizeError(binding, operation, cause)
|
|
33
|
+
});
|
|
34
|
+
const spanOptions = (binding, operation) => ({ attributes: {
|
|
35
|
+
binding,
|
|
36
|
+
operation
|
|
37
|
+
} });
|
|
38
|
+
const invokeVectorizeMethod = (method, receiver, args) => {
|
|
39
|
+
return Function.prototype.apply.call(method, receiver, args);
|
|
40
|
+
};
|
|
41
|
+
const VectorizeBindingSchema = Schema.declare((value) => Predicate.hasProperty(value, "describe") && Predicate.isFunction(value.describe) && Predicate.hasProperty(value, "query") && Predicate.isFunction(value.query) && Predicate.hasProperty(value, "insert") && Predicate.isFunction(value.insert) && Predicate.hasProperty(value, "upsert") && Predicate.isFunction(value.upsert) && Predicate.hasProperty(value, "deleteByIds") && Predicate.isFunction(value.deleteByIds) && Predicate.hasProperty(value, "getByIds") && Predicate.isFunction(value.getByIds));
|
|
42
|
+
const decodeVectorizeBinding = Schema.decodeUnknownOption(VectorizeBindingSchema);
|
|
43
|
+
const isVectorizeBinding = (value) => Option.isSome(decodeVectorizeBinding(value));
|
|
44
|
+
const makeClient = (definition) => (index) => {
|
|
45
|
+
const runtime = index;
|
|
46
|
+
const deleteByIds = Effect.fn("Vectorize.deleteByIds", spanOptions(definition.binding, "deleteByIds"))((ids) => tryVectorizePromise(definition.binding, "deleteByIds", () => runtime.deleteByIds([...ids])));
|
|
47
|
+
return {
|
|
48
|
+
definition,
|
|
49
|
+
describe: tryVectorizePromise(definition.binding, "describe", () => runtime.describe()).pipe(Effect.withSpan("Vectorize.describe", spanOptions(definition.binding, "describe"))),
|
|
50
|
+
query: Effect.fn("Vectorize.query", spanOptions(definition.binding, "query"))((vector, options) => tryVectorizePromise(definition.binding, "query", () => {
|
|
51
|
+
return runtime.query(vector, options);
|
|
52
|
+
})),
|
|
53
|
+
queryById: Effect.fn("Vectorize.queryById", spanOptions(definition.binding, "queryById"))((vectorId, options) => runtime.queryById !== void 0 ? tryVectorizePromise(definition.binding, "queryById", () => {
|
|
54
|
+
const queryById = runtime.queryById;
|
|
55
|
+
return queryById === void 0 ? Promise.reject(/* @__PURE__ */ new TypeError("Vectorize binding does not expose queryById()")) : invokeVectorizeMethod(queryById, runtime, [vectorId, options]);
|
|
56
|
+
}) : Effect.fail(vectorizeError(definition.binding, "queryById", /* @__PURE__ */ new TypeError("Vectorize binding does not expose queryById()")))),
|
|
57
|
+
insert: Effect.fn("Vectorize.insert", spanOptions(definition.binding, "insert"))((vectors) => tryVectorizePromise(definition.binding, "insert", () => runtime.insert([...vectors]))),
|
|
58
|
+
upsert: Effect.fn("Vectorize.upsert", spanOptions(definition.binding, "upsert"))((vectors) => tryVectorizePromise(definition.binding, "upsert", () => runtime.upsert([...vectors]))),
|
|
59
|
+
deleteByIds,
|
|
60
|
+
delete: deleteByIds,
|
|
61
|
+
getByIds: Effect.fn("Vectorize.getByIds", spanOptions(definition.binding, "getByIds"))((ids) => tryVectorizePromise(definition.binding, "getByIds", () => runtime.getByIds([...ids]))),
|
|
62
|
+
rawUnsafe: Effect.succeed(index)
|
|
63
|
+
};
|
|
64
|
+
};
|
|
65
|
+
const layer = (tag, definition) => layer$1(tag, definition.binding, isVectorizeBinding, makeClient(definition), { expected: expectedVectorizeBinding });
|
|
66
|
+
const make = (id) => Tag()(id);
|
|
67
|
+
const Tag = () => (id) => {
|
|
68
|
+
const tag = Context.Service()(id);
|
|
69
|
+
const makeLayer = (definition) => layer(tag, definition);
|
|
70
|
+
return Object.assign(tag, {
|
|
71
|
+
id,
|
|
72
|
+
layer: makeLayer
|
|
73
|
+
});
|
|
74
|
+
};
|
|
75
|
+
//#endregion
|
|
76
|
+
export { Tag, VectorizeOperationError, Vectorize_exports, isVectorizeBinding, layer, make, makeClient };
|
package/dist/Vitest.d.mts
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import
|
|
1
|
+
import { WorkerEnv, WorkerEnvironment } from "./Environment.mjs";
|
|
2
|
+
import { DurableObjectState, DurableObjectStateService } from "./DurableObjectState.mjs";
|
|
3
|
+
import { WorkflowInstanceStatusName } from "./WorkflowBinding.mjs";
|
|
4
|
+
import * as Effect from "effect/Effect";
|
|
5
|
+
import * as Schema from "effect/Schema";
|
|
6
|
+
import * as Layer from "effect/Layer";
|
|
5
7
|
import { DurableObject } from "cloudflare:workers";
|
|
6
8
|
import { adminSecretsStore as adminSecretsStore$1, getQueueResult, introspectWorkflow as introspectWorkflow$1, introspectWorkflowInstance as introspectWorkflowInstance$1 } from "cloudflare:test";
|
|
7
9
|
//#region src/Vitest.d.ts
|
package/dist/Vitest.mjs
CHANGED
|
@@ -1,7 +1,11 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import
|
|
1
|
+
import { WorkerConfig, WorkerEnvironment } from "./Environment.mjs";
|
|
2
|
+
import { runNativeCallback } from "./internal/NativeCallback.mjs";
|
|
3
|
+
import { DurableObjectState, fromDurableObjectState } from "./DurableObjectState.mjs";
|
|
4
|
+
import * as Effect from "effect/Effect";
|
|
5
|
+
import "effect/Schema";
|
|
6
|
+
import * as Layer from "effect/Layer";
|
|
7
|
+
import * as ConfigProvider from "effect/ConfigProvider";
|
|
8
|
+
import * as Exit from "effect/Exit";
|
|
5
9
|
import { env } from "cloudflare:workers";
|
|
6
10
|
import { abortAllDurableObjects as abortAllDurableObjects$1, adminSecretsStore as adminSecretsStore$1, applyD1Migrations as applyD1Migrations$1, createExecutionContext, createMessageBatch, createPagesEventContext, createScheduledController, evictAllDurableObjects as evictAllDurableObjects$1, evictDurableObject as evictDurableObject$1, getQueueResult, introspectWorkflow as introspectWorkflow$1, introspectWorkflowInstance as introspectWorkflowInstance$1, listDurableObjectIds as listDurableObjectIds$1, reset as reset$1, runDurableObjectAlarm as runDurableObjectAlarm$1, runInDurableObject as runInDurableObject$1, waitOnExecutionContext } from "cloudflare:test";
|
|
7
11
|
//#region src/Vitest.ts
|