effect-cf 0.33.0 → 0.35.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +22 -0
- package/README.md +31 -1079
- package/dist/{Artifacts-DnHQA-Ax.d.mts → Artifacts-B3r3RuTB.d.mts} +1 -48
- package/dist/{Artifacts-CSIk1Oml.mjs → Artifacts-CBxWGeZB.mjs} +2 -7
- package/dist/{Binding-pfilNJmP.mjs → Binding-C82jRhdr.mjs} +1 -2
- package/dist/{Binding-xJJJPmiD.d.mts → Binding-DKcLrQCM.d.mts} +0 -45
- package/dist/ComputerArtifacts.d.mts +1 -3
- package/dist/ComputerArtifacts.mjs +1 -2
- package/dist/ComputerWorkspace.d.mts +11 -12
- package/dist/ComputerWorkspace.mjs +31 -10
- package/dist/ComputerWorkspaceHost.d.mts +1 -9
- package/dist/{ContainerNamespace-CFjiLw8b.d.mts → ContainerNamespace-DbLaeFhN.d.mts} +1 -14
- package/dist/{DurableObjectState-CVLLse69.mjs → DurableObjectState-DcqElJ4e.mjs} +82 -89
- package/dist/{DurableObjectState-BpRjz6-q.d.mts → DurableObjectState-DpYdNZgT.d.mts} +102 -266
- package/dist/{ErrorMessage-BM0K-Nik.mjs → ErrorMessage-Byx2OgNd.mjs} +0 -1
- package/dist/{Hyperdrive-z-9fFz15.d.mts → Hyperdrive-HrwFlZ6x.d.mts} +1 -4
- package/dist/HyperdrivePg.d.mts +2 -11
- package/dist/HyperdrivePg.mjs +0 -8
- package/dist/Sandbox.d.mts +2 -32
- package/dist/Sandbox.mjs +2 -11
- package/dist/Vitest.d.mts +3 -31
- package/dist/Vitest.mjs +8 -26
- package/dist/{WorkflowBinding-lBR4_-op.d.mts → WorkflowBinding-Cn3AuUyP.d.mts} +2 -5
- package/dist/index.d.mts +42 -480
- package/dist/index.mjs +267 -380
- package/package.json +1 -1
- package/src/AiGateway.ts +0 -6
- package/src/AnalyticsEngine.ts +8 -10
- package/src/Artifacts.ts +0 -47
- package/src/Binding.ts +0 -8
- package/src/BrowserRendering.ts +0 -4
- package/src/Cache.ts +0 -19
- package/src/CloudflareOtlp.ts +6 -39
- package/src/ComputerArtifacts.ts +0 -2
- package/src/ComputerWorkspace.ts +53 -35
- package/src/ComputerWorkspaceHost.ts +0 -8
- package/src/ContainerNamespace.ts +0 -13
- package/src/D1.ts +0 -22
- package/src/DurableObject.ts +51 -32
- package/src/DurableObjectAlarm.ts +6 -210
- package/src/DurableObjectDefinition.ts +8 -20
- package/src/DurableObjectNamespace.ts +88 -115
- package/src/DurableObjectRpcWebSocket.ts +5 -46
- package/src/DurableObjectSqlite.ts +0 -12
- package/src/DurableObjectState.ts +18 -38
- package/src/DurableObjectStorage.ts +55 -70
- package/src/DurableObjectWebSocket.ts +23 -72
- package/src/Email.ts +0 -12
- package/src/Environment.ts +0 -37
- package/src/Hyperdrive.ts +0 -3
- package/src/HyperdrivePg.ts +0 -9
- package/src/Images.ts +0 -5
- package/src/Kv.ts +0 -15
- package/src/QueueBinding.ts +0 -2
- package/src/R2.ts +0 -5
- package/src/RpcDefinition.ts +5 -17
- package/src/RpcTracing.ts +133 -0
- package/src/Sandbox.ts +0 -30
- package/src/ServiceBinding.ts +83 -128
- package/src/Vectorize.ts +0 -5
- package/src/Vitest.ts +18 -43
- package/src/WebTransport.ts +0 -15
- package/src/Worker.ts +140 -108
- package/src/WorkerDefinition.ts +5 -14
- package/src/WorkersAi.ts +21 -18
- package/src/Workflow.ts +45 -54
- package/src/WorkflowBinding.ts +0 -3
- package/src/index.ts +1 -0
- package/src/internal/Entrypoint.ts +23 -4
- package/src/internal/ErrorMessage.ts +0 -1
- package/src/internal/NativeCallback.ts +55 -0
- package/src/internal/RpcInvocation.ts +18 -1
- package/src/internal/Runtime.ts +12 -7
- package/src/internal/WorkerContext.ts +5 -14
|
@@ -40,7 +40,6 @@ const causeMessage = (cause) => {
|
|
|
40
40
|
return "unknown cause";
|
|
41
41
|
}
|
|
42
42
|
};
|
|
43
|
-
/** Renders a violation list as a single `path: message; ...` line. */
|
|
44
43
|
const violationsMessage = (violations) => violations.map((violation) => `${violation.path}: ${violation.message}`).join("; ");
|
|
45
44
|
//#endregion
|
|
46
45
|
export { WorkerEnvironment as a, WorkerConfig as i, violationsMessage as n, Environment_exports as r, causeMessage as t };
|
|
@@ -1,11 +1,9 @@
|
|
|
1
|
-
import { c as WorkerEnvironment, r as BindingValidationError, t as BindingNotFoundError } from "./Binding-
|
|
1
|
+
import { c as WorkerEnvironment, r as BindingValidationError, t as BindingNotFoundError } from "./Binding-DKcLrQCM.mjs";
|
|
2
2
|
import { Context, Effect, Layer } from "effect";
|
|
3
3
|
declare namespace Hyperdrive_d_exports {
|
|
4
4
|
export { HyperdriveClient, HyperdriveDefinition, HyperdriveService, LayerOptions, Tag, TagClass, isHyperdrive, layer, make, makeClient };
|
|
5
5
|
}
|
|
6
|
-
/** Typed Hyperdrive binding definition. */
|
|
7
6
|
interface HyperdriveDefinition {
|
|
8
|
-
/** Binding name as configured in `wrangler.jsonc`. */
|
|
9
7
|
readonly binding: string;
|
|
10
8
|
}
|
|
11
9
|
interface HyperdriveClient {
|
|
@@ -14,7 +12,6 @@ interface HyperdriveClient {
|
|
|
14
12
|
readonly definition: HyperdriveDefinition;
|
|
15
13
|
}
|
|
16
14
|
declare const HyperdriveServiceTypeId: unique symbol;
|
|
17
|
-
/** Nominal service marker for Hyperdrive services created with {@link make}. */
|
|
18
15
|
interface HyperdriveService<Id extends string> {
|
|
19
16
|
readonly [HyperdriveServiceTypeId]: {
|
|
20
17
|
readonly id: Id;
|
package/dist/HyperdrivePg.d.mts
CHANGED
|
@@ -1,19 +1,10 @@
|
|
|
1
|
-
import { c as WorkerEnvironment, r as BindingValidationError, t as BindingNotFoundError } from "./Binding-
|
|
2
|
-
import { n as LayerOptions, r as TagClass } from "./Hyperdrive-
|
|
1
|
+
import { c as WorkerEnvironment, r as BindingValidationError, t as BindingNotFoundError } from "./Binding-DKcLrQCM.mjs";
|
|
2
|
+
import { n as LayerOptions, r as TagClass } from "./Hyperdrive-HrwFlZ6x.mjs";
|
|
3
3
|
import { Layer } from "effect";
|
|
4
4
|
import { PgClient } from "@effect/sql-pg";
|
|
5
5
|
import { SqlClient, SqlError } from "effect/unstable/sql";
|
|
6
6
|
//#region src/HyperdrivePg.d.ts
|
|
7
|
-
/** Hyperdrive owns database pooling, so app-side pool and connection options are not exposed. */
|
|
8
7
|
type PgLayerOptions = Omit<Parameters<typeof PgClient.makeClient>[0], "url" | "host" | "port" | "path" | "ssl" | "database" | "username" | "password" | "stream">;
|
|
9
|
-
/**
|
|
10
|
-
* Provides `PgClient` and `SqlClient` backed by a Hyperdrive binding.
|
|
11
|
-
*
|
|
12
|
-
* Note: since Effect `4.0.0-beta.99`, `PgClient.makeClient` connects eagerly,
|
|
13
|
-
* so the TCP connection to Hyperdrive is opened when this layer is built.
|
|
14
|
-
* In per-request Workers runtimes, build the layer within the request
|
|
15
|
-
* lifecycle rather than sharing it across requests.
|
|
16
|
-
*/
|
|
17
8
|
declare const layer: <Self, Id extends string>(tag: TagClass<Self, Id>, binding: LayerOptions, options?: PgLayerOptions) => Layer.Layer<PgClient.PgClient | SqlClient.SqlClient, BindingNotFoundError | BindingValidationError | SqlError.SqlError, WorkerEnvironment>;
|
|
18
9
|
//#endregion
|
|
19
10
|
export { PgLayerOptions, layer };
|
package/dist/HyperdrivePg.mjs
CHANGED
|
@@ -1,14 +1,6 @@
|
|
|
1
1
|
import { Effect, Layer, Redacted } from "effect";
|
|
2
2
|
import { PgClient } from "@effect/sql-pg";
|
|
3
3
|
//#region src/HyperdrivePg.ts
|
|
4
|
-
/**
|
|
5
|
-
* Provides `PgClient` and `SqlClient` backed by a Hyperdrive binding.
|
|
6
|
-
*
|
|
7
|
-
* Note: since Effect `4.0.0-beta.99`, `PgClient.makeClient` connects eagerly,
|
|
8
|
-
* so the TCP connection to Hyperdrive is opened when this layer is built.
|
|
9
|
-
* In per-request Workers runtimes, build the layer within the request
|
|
10
|
-
* lifecycle rather than sharing it across requests.
|
|
11
|
-
*/
|
|
12
4
|
const layer = (tag, binding, options) => PgClient.layerFrom(Effect.flatMap(tag, (hyperdrive) => PgClient.makeClient({
|
|
13
5
|
...options,
|
|
14
6
|
url: Redacted.make(hyperdrive.connectionString)
|
package/dist/Sandbox.d.mts
CHANGED
|
@@ -1,17 +1,14 @@
|
|
|
1
|
-
import { c as WorkerEnvironment, r as BindingValidationError, t as BindingNotFoundError } from "./Binding-
|
|
2
|
-
import { n as ContainerStartOptions, r as ContainerStopSignal } from "./ContainerNamespace-
|
|
1
|
+
import { c as WorkerEnvironment, r as BindingValidationError, t as BindingNotFoundError } from "./Binding-DKcLrQCM.mjs";
|
|
2
|
+
import { n as ContainerStartOptions, r as ContainerStopSignal } from "./ContainerNamespace-DbLaeFhN.mjs";
|
|
3
3
|
import { Context, Effect, Layer, Option, Stream } from "effect";
|
|
4
4
|
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
5
|
//#region src/Sandbox.d.ts
|
|
6
|
-
/** Sandbox namespace binding metadata. */
|
|
7
6
|
interface SandboxDefinition {
|
|
8
|
-
/** Binding name as configured in `wrangler.jsonc`. */
|
|
9
7
|
readonly binding: string;
|
|
10
8
|
}
|
|
11
9
|
declare const SandboxOperationError_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
10
|
readonly _tag: "SandboxOperationError";
|
|
13
11
|
} & Readonly<A>;
|
|
14
|
-
/** Failure raised when invoking a sandbox operation. */
|
|
15
12
|
declare class SandboxOperationError extends SandboxOperationError_base<{
|
|
16
13
|
readonly binding: string;
|
|
17
14
|
readonly instance: string;
|
|
@@ -31,43 +28,30 @@ interface SandboxNamespaceResource {
|
|
|
31
28
|
idFromName(name: string): globalThis.DurableObjectId;
|
|
32
29
|
get(id: globalThis.DurableObjectId, options?: globalThis.DurableObjectNamespaceGetDurableObjectOptions): globalThis.DurableObjectStub;
|
|
33
30
|
}
|
|
34
|
-
/** Result of `writeFile` as reported by the sandbox client. */
|
|
35
31
|
type WriteFileResult = Awaited<ReturnType<ISandbox$1["writeFile"]>>;
|
|
36
|
-
/** Result of `readFile` as reported by the sandbox client. */
|
|
37
32
|
type ReadFileResult = Awaited<ReturnType<ISandbox$1["readFile"]>>;
|
|
38
|
-
/** Result of `mkdir` as reported by the sandbox client. */
|
|
39
33
|
type MkdirResult = Awaited<ReturnType<ISandbox$1["mkdir"]>>;
|
|
40
|
-
/** Result of `deleteFile` as reported by the sandbox client. */
|
|
41
34
|
type DeleteFileResult = Awaited<ReturnType<ISandbox$1["deleteFile"]>>;
|
|
42
|
-
/** Result of `renameFile` as reported by the sandbox client. */
|
|
43
35
|
type RenameFileResult = Awaited<ReturnType<ISandbox$1["renameFile"]>>;
|
|
44
|
-
/** Result of `moveFile` as reported by the sandbox client. */
|
|
45
36
|
type MoveFileResult = Awaited<ReturnType<ISandbox$1["moveFile"]>>;
|
|
46
|
-
/** Result of `listFiles` as reported by the sandbox client. */
|
|
47
37
|
type ListFilesResult = Awaited<ReturnType<ISandbox$1["listFiles"]>>;
|
|
48
|
-
/** Result of `exists` as reported by the sandbox client. */
|
|
49
38
|
type FileExistsResult = Awaited<ReturnType<ISandbox$1["exists"]>>;
|
|
50
|
-
/** Text encodings accepted by `readFile`. */
|
|
51
39
|
type ReadFileEncoding = "utf-8" | "utf8" | "base64";
|
|
52
|
-
/** Options accepted by `exposePort`. */
|
|
53
40
|
interface ExposePortOptions {
|
|
54
41
|
readonly name?: string;
|
|
55
42
|
readonly hostname: string;
|
|
56
43
|
readonly token?: string;
|
|
57
44
|
}
|
|
58
|
-
/** Preview URL information returned by `exposePort`. */
|
|
59
45
|
interface ExposedPort {
|
|
60
46
|
readonly url: string;
|
|
61
47
|
readonly port: number;
|
|
62
48
|
readonly name?: string;
|
|
63
49
|
}
|
|
64
|
-
/** Currently forwardable preview URL returned by `getExposedPorts`. */
|
|
65
50
|
interface ExposedPortStatus {
|
|
66
51
|
readonly url: string;
|
|
67
52
|
readonly port: number;
|
|
68
53
|
readonly status: "active";
|
|
69
54
|
}
|
|
70
|
-
/** Structural tunnel API surface exposed by a sandbox client. */
|
|
71
55
|
interface SandboxTunnelsResource {
|
|
72
56
|
get(port: number, options?: TunnelOptions$1): Promise<TunnelInfo$1>;
|
|
73
57
|
list(): Promise<Array<TunnelInfo$1>>;
|
|
@@ -90,7 +74,6 @@ interface SandboxClientResource extends ISandbox$1 {
|
|
|
90
74
|
validatePortToken(port: number, token: string): Promise<boolean>;
|
|
91
75
|
readonly tunnels: SandboxTunnelsResource;
|
|
92
76
|
}
|
|
93
|
-
/** Effect-wrapped handle for one process started inside a sandbox. */
|
|
94
77
|
interface SandboxProcessHandle {
|
|
95
78
|
readonly id: string;
|
|
96
79
|
readonly pid: number;
|
|
@@ -105,7 +88,6 @@ interface SandboxProcessHandle {
|
|
|
105
88
|
readonly waitForPort: (port: number, options?: Omit<WaitForPortOptions$1, "signal">) => Effect.Effect<void, SandboxOperationError>;
|
|
106
89
|
readonly kill: (signal?: number) => Effect.Effect<void, SandboxOperationError>;
|
|
107
90
|
}
|
|
108
|
-
/** Effect-wrapped handle for one interactive terminal inside a sandbox. */
|
|
109
91
|
interface SandboxTerminalHandle {
|
|
110
92
|
readonly id: string;
|
|
111
93
|
readonly rawUnsafe: Effect.Effect<Terminal$1>;
|
|
@@ -122,13 +104,11 @@ interface SandboxTerminalHandle {
|
|
|
122
104
|
readonly rows?: number;
|
|
123
105
|
}) => Effect.Effect<Response, SandboxOperationError>;
|
|
124
106
|
}
|
|
125
|
-
/** Effect-wrapped tunnel operations for one sandbox instance. */
|
|
126
107
|
interface SandboxTunnelsClient {
|
|
127
108
|
readonly get: (port: number, options?: TunnelOptions$1) => Effect.Effect<TunnelInfo$1, SandboxOperationError>;
|
|
128
109
|
readonly list: Effect.Effect<Array<TunnelInfo$1>, SandboxOperationError>;
|
|
129
110
|
readonly destroy: (portOrInfo: number | TunnelInfo$1) => Effect.Effect<void, SandboxOperationError>;
|
|
130
111
|
}
|
|
131
|
-
/** Effect-wrapped client for one named sandbox instance. */
|
|
132
112
|
interface SandboxInstanceClient {
|
|
133
113
|
readonly rawUnsafe: Effect.Effect<SandboxClientResource>;
|
|
134
114
|
readonly exec: (command: SandboxCommand$1, options?: ExecOptions$1) => Effect.Effect<SandboxProcessHandle, SandboxOperationError>;
|
|
@@ -171,7 +151,6 @@ interface SandboxInstanceClient {
|
|
|
171
151
|
readonly stop: (signal?: ContainerStopSignal) => Effect.Effect<void, SandboxOperationError>;
|
|
172
152
|
readonly destroy: Effect.Effect<void, SandboxOperationError>;
|
|
173
153
|
}
|
|
174
|
-
/** Effect client for a Sandbox Durable Object namespace binding. */
|
|
175
154
|
interface SandboxNamespaceClient<Namespace extends SandboxNamespaceResource = SandboxNamespaceResource> {
|
|
176
155
|
readonly definition: SandboxDefinition;
|
|
177
156
|
readonly get: (name: string, options?: SandboxOptions$1) => Effect.Effect<SandboxInstanceClient, SandboxOperationError>;
|
|
@@ -186,26 +165,17 @@ interface TagClass<Self, Id extends string, Namespace extends SandboxNamespaceRe
|
|
|
186
165
|
readonly get: (name: string, options?: SandboxOptions$1) => Effect.Effect<SandboxInstanceClient, SandboxOperationError, Self>;
|
|
187
166
|
readonly rawUnsafe: Effect.Effect<Namespace, never, Self>;
|
|
188
167
|
}
|
|
189
|
-
/**
|
|
190
|
-
* Wraps an already-created sandbox client (the value returned by
|
|
191
|
-
* `getSandbox()` from `@cloudflare/sandbox`) into an Effect client.
|
|
192
|
-
*
|
|
193
|
-
* Prefer {@link Tag}/{@link make} with a layer for application code; this
|
|
194
|
-
* entry point exists for advanced composition and testing.
|
|
195
|
-
*/
|
|
196
168
|
declare const fromSandboxClient: (client: SandboxClientResource, definition: SandboxDefinition, instance: string) => SandboxInstanceClient;
|
|
197
169
|
declare const isSandboxNamespaceResource: <Candidate>(value: Candidate) => value is Candidate & SandboxNamespaceResource;
|
|
198
170
|
declare const makeClient: (definition: SandboxDefinition) => <Namespace extends SandboxNamespaceResource>(namespace: Namespace) => SandboxNamespaceClient<Namespace>;
|
|
199
171
|
declare const layer: <Self, Namespace extends SandboxNamespaceResource>(tag: Context.Service<Self, SandboxNamespaceClient<Namespace>>, definition: SandboxDefinition) => Layer.Layer<Self, BindingNotFoundError | BindingValidationError, WorkerEnvironment>;
|
|
200
172
|
declare const make: <Id extends string>(id: Id) => TagClass<SandboxNamespaceService<Id>, Id, SandboxNamespaceResource>;
|
|
201
173
|
declare const SandboxNamespaceServiceTypeId: unique symbol;
|
|
202
|
-
/** Nominal service marker for Sandbox namespaces created with {@link make}. */
|
|
203
174
|
interface SandboxNamespaceService<Id extends string> {
|
|
204
175
|
readonly [SandboxNamespaceServiceTypeId]: {
|
|
205
176
|
readonly id: Id;
|
|
206
177
|
};
|
|
207
178
|
}
|
|
208
|
-
/** Creates a typed Effect service for a Cloudflare Sandbox namespace. */
|
|
209
179
|
declare const Tag: <Self, Namespace extends SandboxNamespaceResource = SandboxNamespaceResource>() => <Id extends string>(id: Id) => TagClass<Self, Id, Namespace>;
|
|
210
180
|
declare const Sandbox: typeof Tag;
|
|
211
181
|
/**
|
package/dist/Sandbox.mjs
CHANGED
|
@@ -1,9 +1,8 @@
|
|
|
1
|
-
import { a as WorkerEnvironment, t as causeMessage } from "./ErrorMessage-
|
|
2
|
-
import { r as layer$1 } from "./Binding-
|
|
1
|
+
import { a as WorkerEnvironment, t as causeMessage } from "./ErrorMessage-Byx2OgNd.mjs";
|
|
2
|
+
import { r as layer$1 } from "./Binding-C82jRhdr.mjs";
|
|
3
3
|
import { Context, Data, Effect, Option, Predicate, Stream } from "effect";
|
|
4
4
|
//#region src/Sandbox.ts
|
|
5
5
|
const expectedSandboxNamespace = "Sandbox Durable Object namespace binding with idFromName() and get()";
|
|
6
|
-
/** Failure raised when invoking a sandbox operation. */
|
|
7
6
|
var SandboxOperationError = class extends Data.TaggedError("SandboxOperationError") {
|
|
8
7
|
get message() {
|
|
9
8
|
return `Sandbox ${this.operation} failed for binding "${this.binding}" instance "${this.instance}": ${causeMessage(this.cause)}`;
|
|
@@ -135,13 +134,6 @@ const makeTerminalHandle = (definition, instance, terminal) => {
|
|
|
135
134
|
})
|
|
136
135
|
};
|
|
137
136
|
};
|
|
138
|
-
/**
|
|
139
|
-
* Wraps an already-created sandbox client (the value returned by
|
|
140
|
-
* `getSandbox()` from `@cloudflare/sandbox`) into an Effect client.
|
|
141
|
-
*
|
|
142
|
-
* Prefer {@link Tag}/{@link make} with a layer for application code; this
|
|
143
|
-
* entry point exists for advanced composition and testing.
|
|
144
|
-
*/
|
|
145
137
|
const fromSandboxClient = (client, definition, instance) => {
|
|
146
138
|
const spanOptions = (operation) => ({ attributes: {
|
|
147
139
|
binding: definition.binding,
|
|
@@ -325,7 +317,6 @@ const makeClient = (definition) => (namespace) => {
|
|
|
325
317
|
};
|
|
326
318
|
const layer = (tag, definition) => layer$1(tag, definition.binding, (value) => isSandboxNamespaceResource(value), makeClient(definition), { expected: expectedSandboxNamespace });
|
|
327
319
|
const make = (id) => Tag()(id);
|
|
328
|
-
/** Creates a typed Effect service for a Cloudflare Sandbox namespace. */
|
|
329
320
|
const Tag = () => (id) => {
|
|
330
321
|
const tag = Context.Service()(`effect-cf/Sandbox/${id}`);
|
|
331
322
|
const makeLayer = (definition) => layer(tag, definition);
|
package/dist/Vitest.d.mts
CHANGED
|
@@ -1,23 +1,14 @@
|
|
|
1
|
-
import { c as WorkerEnvironment, s as WorkerEnv } from "./Binding-
|
|
2
|
-
import { n as DurableObjectStateService, t as DurableObjectState } from "./DurableObjectState-
|
|
3
|
-
import { o as WorkflowInstanceStatusName } from "./WorkflowBinding-
|
|
1
|
+
import { c as WorkerEnvironment, s as WorkerEnv } from "./Binding-DKcLrQCM.mjs";
|
|
2
|
+
import { n as DurableObjectStateService, t as DurableObjectState } from "./DurableObjectState-DpYdNZgT.mjs";
|
|
3
|
+
import { o as WorkflowInstanceStatusName } from "./WorkflowBinding-Cn3AuUyP.mjs";
|
|
4
4
|
import { Effect, Layer, Schema } from "effect";
|
|
5
5
|
import { DurableObject } from "cloudflare:workers";
|
|
6
6
|
import { adminSecretsStore as adminSecretsStore$1, getQueueResult, introspectWorkflow as introspectWorkflow$1, introspectWorkflowInstance as introspectWorkflowInstance$1 } from "cloudflare:test";
|
|
7
7
|
//#region src/Vitest.d.ts
|
|
8
|
-
/**
|
|
9
|
-
* Provides the Workers test environment as both {@link WorkerEnvironment} and
|
|
10
|
-
* the active Effect `ConfigProvider`.
|
|
11
|
-
*/
|
|
12
8
|
declare const layer: Layer.Layer<WorkerEnvironment>;
|
|
13
|
-
/** Constructor shape shared by Effect-backed Worker entrypoints. */
|
|
14
9
|
interface WorkerConstructor<Instance> {
|
|
15
10
|
new (context: globalThis.ExecutionContext, env: WorkerEnv): Instance;
|
|
16
11
|
}
|
|
17
|
-
/**
|
|
18
|
-
* Creates an `ExecutionContext` and drains all `waitUntil` work before the
|
|
19
|
-
* returned effect completes, including when `use` fails or is interrupted.
|
|
20
|
-
*/
|
|
21
12
|
declare const withExecutionContext: <A, E, R>(use: (context: globalThis.ExecutionContext) => Effect.Effect<A, E, R>) => Effect.Effect<A, E, R>;
|
|
22
13
|
interface FetchWorker {
|
|
23
14
|
fetch(request: Request): Promise<Response>;
|
|
@@ -27,9 +18,7 @@ interface FetchWorker {
|
|
|
27
18
|
* work before returning the response.
|
|
28
19
|
*/
|
|
29
20
|
declare const fetch: <Instance extends FetchWorker>(Worker: WorkerConstructor<Instance>, request: Request<unknown, CfProperties<unknown>>, workerEnv?: Cloudflare.Env | undefined) => Effect.Effect<Response, never, never>;
|
|
30
|
-
/** Modules-format scheduled handler accepted by {@link scheduled}. */
|
|
31
21
|
type ScheduledHandler = NonNullable<globalThis.ExportedHandler<WorkerEnv>["scheduled"]>;
|
|
32
|
-
/** Options used to construct a scheduled event controller. */
|
|
33
22
|
interface ScheduledOptions {
|
|
34
23
|
readonly scheduledTime?: number | Date;
|
|
35
24
|
readonly cron?: string;
|
|
@@ -54,7 +43,6 @@ type PagesEventContextInitData<Context> = Context extends globalThis.EventContex
|
|
|
54
43
|
} : {
|
|
55
44
|
readonly data: Data;
|
|
56
45
|
} : never;
|
|
57
|
-
/** Initialization accepted by the Workers Vitest plugin for a Pages Function. */
|
|
58
46
|
type PagesEventContextInit<Function extends AnyPagesFunction> = PagesEventContextInitBase & PagesEventContextInitParams<Parameters<Function>[0]> & PagesEventContextInitData<Parameters<Function>[0]>;
|
|
59
47
|
/**
|
|
60
48
|
* Invokes a Pages Function with a typed event context and drains its
|
|
@@ -64,7 +52,6 @@ declare const pages: <Function extends AnyPagesFunction>(handler: Function, init
|
|
|
64
52
|
interface QueueWorker {
|
|
65
53
|
queue(batch: globalThis.MessageBatch): Promise<void>;
|
|
66
54
|
}
|
|
67
|
-
/** Input message accepted by the Workers Vitest plugin's `createMessageBatch` helper. */
|
|
68
55
|
type QueueMessage<Body> = {
|
|
69
56
|
readonly id: string;
|
|
70
57
|
readonly timestamp: Date;
|
|
@@ -76,7 +63,6 @@ type QueueMessage<Body> = {
|
|
|
76
63
|
});
|
|
77
64
|
/** Acknowledgement and retry result returned by the Workers Vitest plugin. */
|
|
78
65
|
type QueueResult = Awaited<ReturnType<typeof getQueueResult>>;
|
|
79
|
-
/** Result of invoking a queue consumer through {@link queue}. */
|
|
80
66
|
interface QueueRunResult<Body> {
|
|
81
67
|
readonly batch: globalThis.MessageBatch<Body>;
|
|
82
68
|
readonly result: QueueResult;
|
|
@@ -94,28 +80,19 @@ declare const queue: <Body, Instance extends QueueWorker>(Worker: WorkerConstruc
|
|
|
94
80
|
* passed to `use` for direct access.
|
|
95
81
|
*/
|
|
96
82
|
declare const runInDurableObject: <Object extends DurableObject, A, E, R>(stub: DurableObjectStub<Object>, use: (instance: Object, state: DurableObjectStateService) => Effect.Effect<A, E, R>) => Effect.Effect<A, E, Exclude<R, DurableObjectState>>;
|
|
97
|
-
/** Immediately runs and removes a scheduled Durable Object alarm. */
|
|
98
83
|
declare const runDurableObjectAlarm: (stub: DurableObjectStub<DurableObject<Cloudflare.Env, {}>>) => Effect.Effect<boolean, never, never>;
|
|
99
|
-
/** Options controlling how Durable Object eviction handles WebSockets. */
|
|
100
84
|
interface DurableObjectEvictionOptions {
|
|
101
85
|
readonly webSockets?: "close" | "hibernate";
|
|
102
86
|
}
|
|
103
|
-
/** Gracefully evicts one running Durable Object while preserving durable storage. */
|
|
104
87
|
declare const evictDurableObject: (stub: DurableObjectStub<DurableObject<Cloudflare.Env, {}>>, options?: DurableObjectEvictionOptions | undefined) => Effect.Effect<void, never, never>;
|
|
105
|
-
/** Lists all IDs created in a Durable Object namespace. */
|
|
106
88
|
declare const listDurableObjectIds: <Object extends DurableObject | undefined>(namespace: DurableObjectNamespace<Object>) => Effect.Effect<DurableObjectId[], never, never>;
|
|
107
|
-
/** Deletes data from all bindings attached to the current test Worker. */
|
|
108
89
|
declare const reset: () => Effect.Effect<void, never, never>;
|
|
109
|
-
/** Aborts all Durable Object instances without deleting their persisted data. */
|
|
110
90
|
declare const abortAllDurableObjects: () => Effect.Effect<void, never, never>;
|
|
111
|
-
/** Gracefully evicts all running Durable Objects while preserving durable storage. */
|
|
112
91
|
declare const evictAllDurableObjects: (options?: DurableObjectEvictionOptions | undefined) => Effect.Effect<void, never, never>;
|
|
113
|
-
/** A D1 migration accepted by the Workers Vitest plugin. */
|
|
114
92
|
interface D1Migration {
|
|
115
93
|
readonly name: string;
|
|
116
94
|
readonly queries: ReadonlyArray<string>;
|
|
117
95
|
}
|
|
118
|
-
/** Applies all D1 migrations that have not already been recorded. */
|
|
119
96
|
declare const applyD1Migrations: (database: D1Database, migrations: readonly D1Migration[], migrationsTableName?: string | undefined) => Effect.Effect<void, never, never>;
|
|
120
97
|
type NativeSecretsStoreAdmin = ReturnType<typeof adminSecretsStore$1>;
|
|
121
98
|
/** Secret metadata returned by {@link SecretsStoreAdmin.list}. */
|
|
@@ -141,17 +118,14 @@ declare const adminSecretsStore: (binding: {
|
|
|
141
118
|
}) => Effect.Effect<SecretsStoreAdmin, never, never>;
|
|
142
119
|
type NativeWorkflowIntrospector = Awaited<ReturnType<typeof introspectWorkflow$1>>;
|
|
143
120
|
type NativeWorkflowInstanceIntrospector = Awaited<ReturnType<typeof introspectWorkflowInstance$1>>;
|
|
144
|
-
/** Identifies one occurrence of a Workflow step or sleep. */
|
|
145
121
|
interface WorkflowStepTarget {
|
|
146
122
|
readonly name: string;
|
|
147
123
|
readonly index?: number;
|
|
148
124
|
}
|
|
149
|
-
/** Event delivered to a mocked Workflow `waitForEvent` operation. */
|
|
150
125
|
interface WorkflowMockEvent {
|
|
151
126
|
readonly type: string;
|
|
152
127
|
readonly payload: unknown;
|
|
153
128
|
}
|
|
154
|
-
/** Effect-native Workflow behavior modifier. */
|
|
155
129
|
interface WorkflowInstanceModifier {
|
|
156
130
|
readonly disableSleeps: (steps?: ReadonlyArray<WorkflowStepTarget>) => Effect.Effect<void>;
|
|
157
131
|
readonly disableRetryDelays: (steps?: ReadonlyArray<WorkflowStepTarget>) => Effect.Effect<void>;
|
|
@@ -162,7 +136,6 @@ interface WorkflowInstanceModifier {
|
|
|
162
136
|
readonly forceEventTimeout: (step: WorkflowStepTarget) => Effect.Effect<void>;
|
|
163
137
|
}
|
|
164
138
|
type WorkflowMockResult = Schema.Schema.Type<typeof Schema.Unknown>;
|
|
165
|
-
/** Effect-native introspector for one Workflow instance. */
|
|
166
139
|
interface WorkflowInstanceIntrospector {
|
|
167
140
|
readonly raw: NativeWorkflowInstanceIntrospector;
|
|
168
141
|
readonly modify: <A, E, R>(use: (modifier: WorkflowInstanceModifier) => Effect.Effect<A, E, R>) => Effect.Effect<A, E, R>;
|
|
@@ -174,7 +147,6 @@ interface WorkflowInstanceIntrospector {
|
|
|
174
147
|
readonly message: string;
|
|
175
148
|
}>;
|
|
176
149
|
}
|
|
177
|
-
/** Effect-native introspector for subsequently created Workflow instances. */
|
|
178
150
|
interface WorkflowIntrospector {
|
|
179
151
|
readonly raw: NativeWorkflowIntrospector;
|
|
180
152
|
readonly modifyAll: <A, E, R>(use: (modifier: WorkflowInstanceModifier) => Effect.Effect<A, E, R>) => Effect.Effect<A, E, R>;
|
package/dist/Vitest.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { a as WorkerEnvironment, i as WorkerConfig } from "./ErrorMessage-
|
|
2
|
-
import { r as fromDurableObjectState, t as DurableObjectState } from "./DurableObjectState-
|
|
1
|
+
import { a as WorkerEnvironment, i as WorkerConfig } from "./ErrorMessage-Byx2OgNd.mjs";
|
|
2
|
+
import { l as runNativeCallback, r as fromDurableObjectState, t as DurableObjectState } from "./DurableObjectState-DcqElJ4e.mjs";
|
|
3
3
|
import { ConfigProvider, Effect, Exit, Layer } from "effect";
|
|
4
4
|
import { env } from "cloudflare:workers";
|
|
5
5
|
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";
|
|
@@ -11,15 +11,7 @@ import { abortAllDurableObjects as abortAllDurableObjects$1, adminSecretsStore a
|
|
|
11
11
|
* run inside the Workers test runtime, where `cloudflare:test` is available.
|
|
12
12
|
*/
|
|
13
13
|
const currentEnv = env;
|
|
14
|
-
/**
|
|
15
|
-
* Provides the Workers test environment as both {@link WorkerEnvironment} and
|
|
16
|
-
* the active Effect `ConfigProvider`.
|
|
17
|
-
*/
|
|
18
14
|
const layer = Layer.mergeAll(Layer.succeed(WorkerEnvironment, currentEnv), ConfigProvider.layer(WorkerConfig.providerFromEnv(currentEnv)));
|
|
19
|
-
/**
|
|
20
|
-
* Creates an `ExecutionContext` and drains all `waitUntil` work before the
|
|
21
|
-
* returned effect completes, including when `use` fails or is interrupted.
|
|
22
|
-
*/
|
|
23
15
|
const withExecutionContext = Effect.fn("effect-cf/vitest/withExecutionContext")(function* (use) {
|
|
24
16
|
return yield* Effect.acquireUseRelease(Effect.sync(createExecutionContext), use, (context) => Effect.promise(() => waitOnExecutionContext(context)));
|
|
25
17
|
});
|
|
@@ -71,38 +63,29 @@ const queue = Effect.fn("effect-cf/vitest/queue")(function* (Worker, queueName,
|
|
|
71
63
|
* passed to `use` for direct access.
|
|
72
64
|
*/
|
|
73
65
|
const runInDurableObject = Effect.fn("effect-cf/vitest/runInDurableObject")(function* (stub, use) {
|
|
74
|
-
|
|
75
|
-
return yield* yield* Effect.promise(() => runInDurableObject$1(stub, (instance, nativeState) => {
|
|
66
|
+
return yield* yield* runNativeCallback((run) => runInDurableObject$1(stub, (instance, nativeState) => {
|
|
76
67
|
const state = fromDurableObjectState(nativeState);
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
}));
|
|
68
|
+
return run(Effect.provideService(Effect.suspend(() => use(instance, state)), DurableObjectState, state));
|
|
69
|
+
})).pipe(Effect.orDie);
|
|
80
70
|
});
|
|
81
|
-
/** Immediately runs and removes a scheduled Durable Object alarm. */
|
|
82
71
|
const runDurableObjectAlarm = Effect.fn("effect-cf/vitest/runDurableObjectAlarm")(function* (stub) {
|
|
83
72
|
return yield* Effect.promise(() => runDurableObjectAlarm$1(stub));
|
|
84
73
|
});
|
|
85
|
-
/** Gracefully evicts one running Durable Object while preserving durable storage. */
|
|
86
74
|
const evictDurableObject = Effect.fn("effect-cf/vitest/evictDurableObject")(function* (stub, options) {
|
|
87
75
|
yield* Effect.promise(() => evictDurableObject$1(stub, options));
|
|
88
76
|
});
|
|
89
|
-
/** Lists all IDs created in a Durable Object namespace. */
|
|
90
77
|
const listDurableObjectIds = Effect.fn("effect-cf/vitest/listDurableObjectIds")(function* (namespace) {
|
|
91
78
|
return yield* Effect.promise(() => listDurableObjectIds$1(namespace));
|
|
92
79
|
});
|
|
93
|
-
/** Deletes data from all bindings attached to the current test Worker. */
|
|
94
80
|
const reset = Effect.fn("effect-cf/vitest/reset")(function* () {
|
|
95
81
|
yield* Effect.promise(reset$1);
|
|
96
82
|
});
|
|
97
|
-
/** Aborts all Durable Object instances without deleting their persisted data. */
|
|
98
83
|
const abortAllDurableObjects = Effect.fn("effect-cf/vitest/abortAllDurableObjects")(function* () {
|
|
99
84
|
yield* Effect.promise(abortAllDurableObjects$1);
|
|
100
85
|
});
|
|
101
|
-
/** Gracefully evicts all running Durable Objects while preserving durable storage. */
|
|
102
86
|
const evictAllDurableObjects = Effect.fn("effect-cf/vitest/evictAllDurableObjects")(function* (options) {
|
|
103
87
|
yield* Effect.promise(() => evictAllDurableObjects$1(options));
|
|
104
88
|
});
|
|
105
|
-
/** Applies all D1 migrations that have not already been recorded. */
|
|
106
89
|
const applyD1Migrations = Effect.fn("effect-cf/vitest/applyD1Migrations")(function* (database, migrations, migrationsTableName) {
|
|
107
90
|
yield* Effect.promise(() => applyD1Migrations$1(database, migrations.map(({ name, queries }) => ({
|
|
108
91
|
name,
|
|
@@ -134,12 +117,11 @@ const wrapWorkflowModifier = (modifier) => ({
|
|
|
134
117
|
forceEventTimeout: (step) => Effect.promise(() => modifier.forceEventTimeout(step))
|
|
135
118
|
});
|
|
136
119
|
const runWorkflowModifier = Effect.fnUntraced(function* (register, use) {
|
|
137
|
-
|
|
138
|
-
return yield* yield* Effect.promise(async () => {
|
|
120
|
+
return yield* yield* runNativeCallback(async (run) => {
|
|
139
121
|
let callbackExit;
|
|
140
122
|
try {
|
|
141
123
|
await register(async (modifier) => {
|
|
142
|
-
callbackExit = await Effect.
|
|
124
|
+
callbackExit = await run(Effect.suspend(() => use(wrapWorkflowModifier(modifier))));
|
|
143
125
|
if (Exit.isFailure(callbackExit)) throw callbackExit;
|
|
144
126
|
});
|
|
145
127
|
} catch (cause) {
|
|
@@ -148,7 +130,7 @@ const runWorkflowModifier = Effect.fnUntraced(function* (register, use) {
|
|
|
148
130
|
}
|
|
149
131
|
if (callbackExit === void 0) throw new Error("The Workers Vitest plugin did not invoke the Workflow modifier callback");
|
|
150
132
|
return callbackExit;
|
|
151
|
-
});
|
|
133
|
+
}).pipe(Effect.orDie);
|
|
152
134
|
});
|
|
153
135
|
const wrapWorkflowInstanceIntrospector = (introspector) => ({
|
|
154
136
|
raw: introspector,
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { c as WorkerEnvironment, r as BindingValidationError, t as BindingNotFoundError } from "./Binding-
|
|
2
|
-
import {
|
|
1
|
+
import { c as WorkerEnvironment, r as BindingValidationError, t as BindingNotFoundError } from "./Binding-DKcLrQCM.mjs";
|
|
2
|
+
import { w as ServiceFreeSchema } from "./DurableObjectState-DpYdNZgT.mjs";
|
|
3
3
|
import { Context, Effect, Option, Schema } from "effect";
|
|
4
4
|
declare namespace WorkflowBinding_d_exports {
|
|
5
5
|
export { WorkflowBindingClient, WorkflowBindingDefinition, WorkflowInstance, WorkflowInstanceCreateBatchOptions, WorkflowInstanceCreateOptions, WorkflowInstanceEvent, WorkflowInstanceLocationHint, WorkflowInstanceRestartOptions, WorkflowInstanceStatus, WorkflowInstanceStatusName, WorkflowInstanceTerminateOptions, WorkflowOperationError, WorkflowResultDecodeError, isWorkflow, layer, makeClient };
|
|
@@ -36,11 +36,8 @@ interface WorkflowInstanceEvent {
|
|
|
36
36
|
readonly payload: unknown;
|
|
37
37
|
}
|
|
38
38
|
interface WorkflowBindingDefinition<Payload extends ServiceFreeSchema, Result extends ServiceFreeSchema> {
|
|
39
|
-
/** Binding name as configured in `wrangler.jsonc`. */
|
|
40
39
|
readonly binding: string;
|
|
41
|
-
/** Codec used to encode payloads passed to `Workflow.create`. */
|
|
42
40
|
readonly payload: Payload;
|
|
43
|
-
/** Codec used to decode completed workflow status output. */
|
|
44
41
|
readonly result: Result;
|
|
45
42
|
}
|
|
46
43
|
interface WorkflowBindingClient<Payload extends ServiceFreeSchema, Result extends ServiceFreeSchema> {
|