effect-cf 0.29.0 → 0.31.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 +20 -0
- package/README.md +103 -8
- package/dist/{Artifacts-rq3hUKQE.mjs → Artifacts-CSIk1Oml.mjs} +4 -128
- package/dist/Binding-pfilNJmP.mjs +129 -0
- package/dist/ComputerArtifacts.mjs +1 -1
- package/dist/ComputerWorkspace.d.mts +1 -1
- package/dist/ComputerWorkspace.mjs +1 -1
- package/dist/ContainerNamespace-CFjiLw8b.d.mts +155 -0
- package/dist/{DurableObjectState-DnnLoHV-.mjs → DurableObjectState-CxS5Y2hf.mjs} +10 -2
- package/dist/{DurableObjectState-OupNMMUl.d.mts → DurableObjectState-DVIgf0sA.d.mts} +7 -1
- package/dist/Sandbox.d.mts +222 -0
- package/dist/Sandbox.mjs +361 -0
- package/dist/Vitest.d.mts +9 -9
- package/dist/Vitest.mjs +5 -5
- package/dist/{WorkflowBinding-DUZtKCVM.d.mts → WorkflowBinding-C9KRmfDU.d.mts} +6 -3
- package/dist/index.d.mts +62 -199
- package/dist/index.mjs +15 -6
- package/package.json +15 -5
- package/src/DurableObjectStorage.ts +40 -1
- package/src/Images.ts +60 -9
- package/src/Sandbox.ts +1094 -0
- package/src/Vitest.ts +9 -9
- package/src/Worker.ts +2 -0
- package/src/WorkflowBinding.ts +10 -2
- package/src/internal/WorkerContext.ts +1 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { t as __exportAll } from "./rolldown-runtime-D7D4PA-g.mjs";
|
|
2
2
|
import { t as causeMessage } from "./ErrorMessage-BM0K-Nik.mjs";
|
|
3
|
-
import { Cause, Context, Data, Effect, Exit, Option, Predicate, Result, Schema } from "effect";
|
|
3
|
+
import { Cause, Clock, Context, Data, Duration, Effect, Exit, Option, Predicate, Result, Schema } from "effect";
|
|
4
4
|
//#region src/DurableObjectStorage.ts
|
|
5
5
|
var DurableObjectStorage_exports = /* @__PURE__ */ __exportAll({
|
|
6
6
|
StorageOperationError: () => StorageOperationError,
|
|
@@ -24,6 +24,11 @@ const tryStoragePromise = (operation, evaluate) => Effect.tryPromise({
|
|
|
24
24
|
try: evaluate,
|
|
25
25
|
catch: (cause) => storageError(operation, cause)
|
|
26
26
|
});
|
|
27
|
+
const setAlarmAfter = Effect.fn("DurableObjectStorage.setAlarmAfter")(function* (operation, setAlarm, delay, options) {
|
|
28
|
+
const now = yield* Clock.currentTimeMillis;
|
|
29
|
+
const delayMillis = Math.ceil(Duration.toMillis(delay));
|
|
30
|
+
yield* tryStoragePromise(operation, () => setAlarm(now + delayMillis, options));
|
|
31
|
+
});
|
|
27
32
|
const fromSqlCursor = (cursor) => ({
|
|
28
33
|
next: () => tryStorageSync("sql.next", () => cursor.next()),
|
|
29
34
|
toArray: () => tryStorageSync("sql.toArray", () => cursor.toArray()),
|
|
@@ -85,6 +90,7 @@ const fromDurableObjectTransaction = (txn) => ({
|
|
|
85
90
|
rollback: () => tryStorageSync("transaction.rollback", () => txn.rollback()),
|
|
86
91
|
getAlarm: (options) => tryStoragePromise("transaction.getAlarm", () => txn.getAlarm(options)),
|
|
87
92
|
setAlarm: (scheduledTime, options) => tryStoragePromise("transaction.setAlarm", () => txn.setAlarm(scheduledTime, options)),
|
|
93
|
+
setAlarmAfter: (delay, options) => setAlarmAfter("transaction.setAlarm", (scheduledTime, options) => txn.setAlarm(scheduledTime, options), delay, options),
|
|
88
94
|
deleteAlarm: (options) => tryStoragePromise("transaction.deleteAlarm", () => txn.deleteAlarm(options))
|
|
89
95
|
});
|
|
90
96
|
/**
|
|
@@ -97,6 +103,7 @@ const fromDurableObjectStorage = (storage) => ({
|
|
|
97
103
|
deleteAll: (options) => tryStoragePromise("deleteAll", () => storage.deleteAll(options)),
|
|
98
104
|
getAlarm: (options) => tryStoragePromise("getAlarm", () => storage.getAlarm(options)),
|
|
99
105
|
setAlarm: (scheduledTime, options) => tryStoragePromise("setAlarm", () => storage.setAlarm(scheduledTime, options)),
|
|
106
|
+
setAlarmAfter: (delay, options) => setAlarmAfter("setAlarm", (scheduledTime, options) => storage.setAlarm(scheduledTime, options), delay, options),
|
|
100
107
|
deleteAlarm: (options) => tryStoragePromise("deleteAlarm", () => storage.deleteAlarm(options)),
|
|
101
108
|
transactionSync: (closure) => Effect.context().pipe(Effect.flatMap((context) => Effect.suspend(() => {
|
|
102
109
|
let aborted;
|
|
@@ -301,7 +308,8 @@ const fromExecutionContext = (ctx, runPromiseExit = (effect) => Effect.runPromis
|
|
|
301
308
|
raw: ctx,
|
|
302
309
|
waitUntil: (effect, options) => schedule(effect, options, options?.mode ?? "observe"),
|
|
303
310
|
waitUntilPropagating: (effect, options) => schedule(effect, options, "propagate"),
|
|
304
|
-
passThroughOnException: Effect.sync(() => ctx.passThroughOnException())
|
|
311
|
+
passThroughOnException: Effect.sync(() => ctx.passThroughOnException()),
|
|
312
|
+
abort: (reason) => Effect.sync(() => ctx.abort(reason))
|
|
305
313
|
};
|
|
306
314
|
};
|
|
307
315
|
//#endregion
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { c as WorkerEnvironment, n as BindingService, r as BindingValidationError, s as WorkerEnv, t as BindingNotFoundError } from "./Binding-xJJJPmiD.mjs";
|
|
2
|
-
import { Cause, Context, Effect, Layer, Option, Predicate, Schema, Scope } from "effect";
|
|
2
|
+
import { Cause, Context, Duration, Effect, Layer, Option, Predicate, Schema, Scope } from "effect";
|
|
3
3
|
import { HttpServerRequest, HttpServerResponse } from "effect/unstable/http";
|
|
4
4
|
import { RpcStub, RpcTarget, WorkerEntrypoint } from "cloudflare:workers";
|
|
5
5
|
declare namespace DurableObjectStorage_d_exports {
|
|
@@ -84,6 +84,8 @@ interface DurableObjectTransaction {
|
|
|
84
84
|
rollback(): StorageEffect<void>;
|
|
85
85
|
getAlarm(options?: globalThis.DurableObjectGetAlarmOptions): StorageEffect<number | null>;
|
|
86
86
|
setAlarm(scheduledTime: number | Date, options?: globalThis.DurableObjectSetAlarmOptions): StorageEffect<void>;
|
|
87
|
+
/** Schedules the alarm after a delay measured by the Effect clock. */
|
|
88
|
+
setAlarmAfter(delay: Duration.Input, options?: globalThis.DurableObjectSetAlarmOptions): StorageEffect<void>;
|
|
87
89
|
deleteAlarm(options?: globalThis.DurableObjectSetAlarmOptions): StorageEffect<void>;
|
|
88
90
|
}
|
|
89
91
|
/**
|
|
@@ -110,6 +112,8 @@ interface DurableObjectStorage {
|
|
|
110
112
|
deleteAll(options?: globalThis.DurableObjectPutOptions): StorageEffect<void>;
|
|
111
113
|
getAlarm(options?: globalThis.DurableObjectGetAlarmOptions): StorageEffect<number | null>;
|
|
112
114
|
setAlarm(scheduledTime: number | Date, options?: globalThis.DurableObjectSetAlarmOptions): StorageEffect<void>;
|
|
115
|
+
/** Schedules the alarm after a delay measured by the Effect clock. */
|
|
116
|
+
setAlarmAfter(delay: Duration.Input, options?: globalThis.DurableObjectSetAlarmOptions): StorageEffect<void>;
|
|
113
117
|
deleteAlarm(options?: globalThis.DurableObjectSetAlarmOptions): StorageEffect<void>;
|
|
114
118
|
/**
|
|
115
119
|
* SQLite-backed Durable Object storage only.
|
|
@@ -830,6 +834,8 @@ interface WorkerContextService {
|
|
|
830
834
|
waitUntil<A, E, R, R2 = never>(effect: Effect.Effect<A, E, R>, options?: WorkerContextWaitUntilOptions<E, R2>): Effect.Effect<void, never, R | R2>;
|
|
831
835
|
waitUntilPropagating<A, E, R, R2 = never>(effect: Effect.Effect<A, E, R>, options?: Omit<WorkerContextWaitUntilOptions<E, R2>, "mode">): Effect.Effect<void, never, R | R2>;
|
|
832
836
|
readonly passThroughOnException: Effect.Effect<void>;
|
|
837
|
+
/** Abort the current stateless Worker invocation (`ExecutionContext.abort`). */
|
|
838
|
+
abort(reason?: string): Effect.Effect<void>;
|
|
833
839
|
}
|
|
834
840
|
declare const WorkerContext_base: Context.ServiceClass<WorkerContext, "effect-cf/WorkerContext", WorkerContextService>;
|
|
835
841
|
/**
|
|
@@ -0,0 +1,222 @@
|
|
|
1
|
+
import { c as WorkerEnvironment, r as BindingValidationError, t as BindingNotFoundError } from "./Binding-xJJJPmiD.mjs";
|
|
2
|
+
import { n as ContainerStartOptions, r as ContainerStopSignal } from "./ContainerNamespace-CFjiLw8b.mjs";
|
|
3
|
+
import { Context, Effect, Layer, Option, Stream } from "effect";
|
|
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
|
+
//#region src/Sandbox.d.ts
|
|
6
|
+
/** Sandbox namespace binding metadata. */
|
|
7
|
+
interface SandboxDefinition {
|
|
8
|
+
/** Binding name as configured in `wrangler.jsonc`. */
|
|
9
|
+
readonly binding: string;
|
|
10
|
+
}
|
|
11
|
+
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
|
+
readonly _tag: "SandboxOperationError";
|
|
13
|
+
} & Readonly<A>;
|
|
14
|
+
/** Failure raised when invoking a sandbox operation. */
|
|
15
|
+
declare class SandboxOperationError extends SandboxOperationError_base<{
|
|
16
|
+
readonly binding: string;
|
|
17
|
+
readonly instance: string;
|
|
18
|
+
readonly operation: string;
|
|
19
|
+
readonly cause: unknown;
|
|
20
|
+
}> {
|
|
21
|
+
get message(): string;
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Structural Durable Object namespace shape required by `getSandbox()`.
|
|
25
|
+
*
|
|
26
|
+
* This is structural so importing this module does not require
|
|
27
|
+
* `@cloudflare/sandbox` at runtime; the package is loaded lazily when a
|
|
28
|
+
* sandbox instance is first requested.
|
|
29
|
+
*/
|
|
30
|
+
interface SandboxNamespaceResource {
|
|
31
|
+
idFromName(name: string): globalThis.DurableObjectId;
|
|
32
|
+
get(id: globalThis.DurableObjectId, options?: globalThis.DurableObjectNamespaceGetDurableObjectOptions): globalThis.DurableObjectStub;
|
|
33
|
+
}
|
|
34
|
+
/** Result of `writeFile` as reported by the sandbox client. */
|
|
35
|
+
type WriteFileResult = Awaited<ReturnType<ISandbox$1["writeFile"]>>;
|
|
36
|
+
/** Result of `readFile` as reported by the sandbox client. */
|
|
37
|
+
type ReadFileResult = Awaited<ReturnType<ISandbox$1["readFile"]>>;
|
|
38
|
+
/** Result of `mkdir` as reported by the sandbox client. */
|
|
39
|
+
type MkdirResult = Awaited<ReturnType<ISandbox$1["mkdir"]>>;
|
|
40
|
+
/** Result of `deleteFile` as reported by the sandbox client. */
|
|
41
|
+
type DeleteFileResult = Awaited<ReturnType<ISandbox$1["deleteFile"]>>;
|
|
42
|
+
/** Result of `renameFile` as reported by the sandbox client. */
|
|
43
|
+
type RenameFileResult = Awaited<ReturnType<ISandbox$1["renameFile"]>>;
|
|
44
|
+
/** Result of `moveFile` as reported by the sandbox client. */
|
|
45
|
+
type MoveFileResult = Awaited<ReturnType<ISandbox$1["moveFile"]>>;
|
|
46
|
+
/** Result of `listFiles` as reported by the sandbox client. */
|
|
47
|
+
type ListFilesResult = Awaited<ReturnType<ISandbox$1["listFiles"]>>;
|
|
48
|
+
/** Result of `exists` as reported by the sandbox client. */
|
|
49
|
+
type FileExistsResult = Awaited<ReturnType<ISandbox$1["exists"]>>;
|
|
50
|
+
/** Text encodings accepted by `readFile`. */
|
|
51
|
+
type ReadFileEncoding = "utf-8" | "utf8" | "base64";
|
|
52
|
+
/** Options accepted by `exposePort`. */
|
|
53
|
+
interface ExposePortOptions {
|
|
54
|
+
readonly name?: string;
|
|
55
|
+
readonly hostname: string;
|
|
56
|
+
readonly token?: string;
|
|
57
|
+
}
|
|
58
|
+
/** Preview URL information returned by `exposePort`. */
|
|
59
|
+
interface ExposedPort {
|
|
60
|
+
readonly url: string;
|
|
61
|
+
readonly port: number;
|
|
62
|
+
readonly name?: string;
|
|
63
|
+
}
|
|
64
|
+
/** Currently forwardable preview URL returned by `getExposedPorts`. */
|
|
65
|
+
interface ExposedPortStatus {
|
|
66
|
+
readonly url: string;
|
|
67
|
+
readonly port: number;
|
|
68
|
+
readonly status: "active";
|
|
69
|
+
}
|
|
70
|
+
/** Structural tunnel API surface exposed by a sandbox client. */
|
|
71
|
+
interface SandboxTunnelsResource {
|
|
72
|
+
get(port: number, options?: TunnelOptions$1): Promise<TunnelInfo$1>;
|
|
73
|
+
list(): Promise<Array<TunnelInfo$1>>;
|
|
74
|
+
destroy(portOrInfo: number | TunnelInfo$1): Promise<void>;
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* Structural surface of the client returned by `getSandbox()` that this
|
|
78
|
+
* module wraps: the `ISandbox` RPC contract plus the lifecycle, port, and
|
|
79
|
+
* tunnel methods the client proxy forwards to the Sandbox Durable Object.
|
|
80
|
+
*/
|
|
81
|
+
interface SandboxClientResource extends ISandbox$1 {
|
|
82
|
+
start(options?: ContainerStartOptions): Promise<void>;
|
|
83
|
+
stop(signal?: ContainerStopSignal): Promise<void>;
|
|
84
|
+
destroy(): Promise<void>;
|
|
85
|
+
containerFetch(requestOrUrl: Request | string | URL, port?: number): Promise<Response>;
|
|
86
|
+
exposePort(port: number, options: ExposePortOptions): Promise<ExposedPort>;
|
|
87
|
+
unexposePort(port: number): Promise<void>;
|
|
88
|
+
getExposedPorts(hostname: string): Promise<Array<ExposedPortStatus>>;
|
|
89
|
+
isPortExposed(port: number): Promise<boolean>;
|
|
90
|
+
validatePortToken(port: number, token: string): Promise<boolean>;
|
|
91
|
+
readonly tunnels: SandboxTunnelsResource;
|
|
92
|
+
}
|
|
93
|
+
/** Effect-wrapped handle for one process started inside a sandbox. */
|
|
94
|
+
interface SandboxProcessHandle {
|
|
95
|
+
readonly id: string;
|
|
96
|
+
readonly pid: number;
|
|
97
|
+
readonly rawUnsafe: Effect.Effect<SandboxProcess$1>;
|
|
98
|
+
readonly status: Effect.Effect<ProcessStatus$1, SandboxOperationError>;
|
|
99
|
+
readonly exitCode: Effect.Effect<number, SandboxOperationError>;
|
|
100
|
+
readonly logs: (options?: Omit<ProcessLogsOptions$1, "signal">) => Stream.Stream<ProcessLogEvent$1, SandboxOperationError>;
|
|
101
|
+
readonly waitForLog: (pattern: string | RegExp, options?: Omit<WaitForLogOptions$1, "signal">) => Effect.Effect<WaitForLogResult$1, SandboxOperationError>;
|
|
102
|
+
readonly waitForExit: (options?: Omit<WaitForExitOptions$1, "signal">) => Effect.Effect<ProcessExit$1, SandboxOperationError>;
|
|
103
|
+
readonly output: (options?: Omit<ProcessOutputOptions$1, "signal">) => Effect.Effect<ProcessOutput$1<Uint8Array>, SandboxOperationError>;
|
|
104
|
+
readonly outputText: (options?: Omit<ProcessOutputOptions$1, "signal">) => Effect.Effect<ProcessOutput$1<string>, SandboxOperationError>;
|
|
105
|
+
readonly waitForPort: (port: number, options?: Omit<WaitForPortOptions$1, "signal">) => Effect.Effect<void, SandboxOperationError>;
|
|
106
|
+
readonly kill: (signal?: number) => Effect.Effect<void, SandboxOperationError>;
|
|
107
|
+
}
|
|
108
|
+
/** Effect-wrapped handle for one interactive terminal inside a sandbox. */
|
|
109
|
+
interface SandboxTerminalHandle {
|
|
110
|
+
readonly id: string;
|
|
111
|
+
readonly rawUnsafe: Effect.Effect<Terminal$1>;
|
|
112
|
+
readonly snapshot: Effect.Effect<TerminalSnapshot$1, SandboxOperationError>;
|
|
113
|
+
readonly write: (data: Uint8Array) => Effect.Effect<void, SandboxOperationError>;
|
|
114
|
+
readonly resize: (cols: number, rows: number) => Effect.Effect<void, SandboxOperationError>;
|
|
115
|
+
readonly output: (options?: Omit<TerminalOutputOptions$1, "signal">) => Stream.Stream<TerminalOutputEvent$1, SandboxOperationError>;
|
|
116
|
+
readonly waitForExit: (options?: Omit<WaitForExitOptions$1, "signal">) => Effect.Effect<ProcessExit$1, SandboxOperationError>;
|
|
117
|
+
readonly interrupt: Effect.Effect<void, SandboxOperationError>;
|
|
118
|
+
readonly terminate: Effect.Effect<void, SandboxOperationError>;
|
|
119
|
+
readonly connect: (request: Request, options?: {
|
|
120
|
+
readonly cursor?: TerminalOutputCursor$1;
|
|
121
|
+
readonly cols?: number;
|
|
122
|
+
readonly rows?: number;
|
|
123
|
+
}) => Effect.Effect<Response, SandboxOperationError>;
|
|
124
|
+
}
|
|
125
|
+
/** Effect-wrapped tunnel operations for one sandbox instance. */
|
|
126
|
+
interface SandboxTunnelsClient {
|
|
127
|
+
readonly get: (port: number, options?: TunnelOptions$1) => Effect.Effect<TunnelInfo$1, SandboxOperationError>;
|
|
128
|
+
readonly list: Effect.Effect<Array<TunnelInfo$1>, SandboxOperationError>;
|
|
129
|
+
readonly destroy: (portOrInfo: number | TunnelInfo$1) => Effect.Effect<void, SandboxOperationError>;
|
|
130
|
+
}
|
|
131
|
+
/** Effect-wrapped client for one named sandbox instance. */
|
|
132
|
+
interface SandboxInstanceClient {
|
|
133
|
+
readonly rawUnsafe: Effect.Effect<SandboxClientResource>;
|
|
134
|
+
readonly exec: (command: SandboxCommand$1, options?: ExecOptions$1) => Effect.Effect<SandboxProcessHandle, SandboxOperationError>;
|
|
135
|
+
readonly getProcess: (id: string) => Effect.Effect<Option.Option<SandboxProcessHandle>, SandboxOperationError>;
|
|
136
|
+
readonly listProcesses: Effect.Effect<Array<ProcessStatus$1>, SandboxOperationError>;
|
|
137
|
+
readonly writeFile: (path: string, content: string | ReadableStream<Uint8Array>, options?: {
|
|
138
|
+
readonly encoding?: string;
|
|
139
|
+
}) => Effect.Effect<WriteFileResult, SandboxOperationError>;
|
|
140
|
+
readonly readFile: (path: string, options?: {
|
|
141
|
+
readonly encoding?: ReadFileEncoding;
|
|
142
|
+
}) => Effect.Effect<ReadFileResult, SandboxOperationError>;
|
|
143
|
+
readonly readFileStream: (path: string) => Stream.Stream<Uint8Array, SandboxOperationError>;
|
|
144
|
+
readonly mkdir: (path: string, options?: {
|
|
145
|
+
readonly recursive?: boolean;
|
|
146
|
+
}) => Effect.Effect<MkdirResult, SandboxOperationError>;
|
|
147
|
+
readonly deleteFile: (path: string) => Effect.Effect<DeleteFileResult, SandboxOperationError>;
|
|
148
|
+
readonly renameFile: (oldPath: string, newPath: string) => Effect.Effect<RenameFileResult, SandboxOperationError>;
|
|
149
|
+
readonly moveFile: (sourcePath: string, destinationPath: string) => Effect.Effect<MoveFileResult, SandboxOperationError>;
|
|
150
|
+
readonly listFiles: (path: string, options?: ListFilesOptions$1) => Effect.Effect<ListFilesResult, SandboxOperationError>;
|
|
151
|
+
readonly exists: (path: string) => Effect.Effect<FileExistsResult, SandboxOperationError>;
|
|
152
|
+
readonly watch: (path: string, options?: WatchOptions$1) => Stream.Stream<FileWatchSSEEvent$1, SandboxOperationError>;
|
|
153
|
+
readonly checkChanges: (path: string, options?: CheckChangesOptions$1) => Effect.Effect<CheckChangesResult$1, SandboxOperationError>;
|
|
154
|
+
readonly setEnvVars: (envVars: Record<string, string | undefined>) => Effect.Effect<void, SandboxOperationError>;
|
|
155
|
+
readonly exposePort: (port: number, options: ExposePortOptions) => Effect.Effect<ExposedPort, SandboxOperationError>;
|
|
156
|
+
readonly unexposePort: (port: number) => Effect.Effect<void, SandboxOperationError>;
|
|
157
|
+
readonly getExposedPorts: (hostname: string) => Effect.Effect<Array<ExposedPortStatus>, SandboxOperationError>;
|
|
158
|
+
readonly isPortExposed: (port: number) => Effect.Effect<boolean, SandboxOperationError>;
|
|
159
|
+
readonly validatePortToken: (port: number, token: string) => Effect.Effect<boolean, SandboxOperationError>;
|
|
160
|
+
readonly containerFetch: (requestOrUrl: Request | string | URL, port?: number) => Effect.Effect<Response, SandboxOperationError>;
|
|
161
|
+
readonly wsConnect: (request: Request, port: number) => Effect.Effect<Response, SandboxOperationError>;
|
|
162
|
+
readonly mountBucket: (bucket: string, mountPath: string, options: MountBucketOptions$1) => Effect.Effect<void, SandboxOperationError>;
|
|
163
|
+
readonly unmountBucket: (mountPath: string) => Effect.Effect<void, SandboxOperationError>;
|
|
164
|
+
readonly createBackup: (options: BackupOptions$1) => Effect.Effect<DirectoryBackup$1, SandboxOperationError>;
|
|
165
|
+
readonly restoreBackup: (backup: DirectoryBackup$1) => Effect.Effect<RestoreBackupResult$1, SandboxOperationError>;
|
|
166
|
+
readonly createTerminal: (options: CreateTerminalOptions$1) => Effect.Effect<SandboxTerminalHandle, SandboxOperationError>;
|
|
167
|
+
readonly getTerminal: (id: string) => Effect.Effect<Option.Option<SandboxTerminalHandle>, SandboxOperationError>;
|
|
168
|
+
readonly listTerminals: Effect.Effect<Array<SandboxTerminalHandle>, SandboxOperationError>;
|
|
169
|
+
readonly tunnels: SandboxTunnelsClient;
|
|
170
|
+
readonly start: (options?: ContainerStartOptions) => Effect.Effect<void, SandboxOperationError>;
|
|
171
|
+
readonly stop: (signal?: ContainerStopSignal) => Effect.Effect<void, SandboxOperationError>;
|
|
172
|
+
readonly destroy: Effect.Effect<void, SandboxOperationError>;
|
|
173
|
+
}
|
|
174
|
+
/** Effect client for a Sandbox Durable Object namespace binding. */
|
|
175
|
+
interface SandboxNamespaceClient<Namespace extends SandboxNamespaceResource = SandboxNamespaceResource> {
|
|
176
|
+
readonly definition: SandboxDefinition;
|
|
177
|
+
readonly get: (name: string, options?: SandboxOptions$1) => Effect.Effect<SandboxInstanceClient, SandboxOperationError>;
|
|
178
|
+
readonly rawUnsafe: Effect.Effect<Namespace>;
|
|
179
|
+
}
|
|
180
|
+
type LayerOptions = {
|
|
181
|
+
readonly binding: string;
|
|
182
|
+
};
|
|
183
|
+
interface TagClass<Self, Id extends string, Namespace extends SandboxNamespaceResource = SandboxNamespaceResource> extends Context.ServiceClass<Self, `effect-cf/Sandbox/${Id}`, SandboxNamespaceClient<Namespace>> {
|
|
184
|
+
readonly id: Id;
|
|
185
|
+
readonly layer: (options: LayerOptions) => Layer.Layer<Self, BindingNotFoundError | BindingValidationError, WorkerEnvironment>;
|
|
186
|
+
readonly get: (name: string, options?: SandboxOptions$1) => Effect.Effect<SandboxInstanceClient, SandboxOperationError, Self>;
|
|
187
|
+
readonly rawUnsafe: Effect.Effect<Namespace, never, Self>;
|
|
188
|
+
}
|
|
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
|
+
declare const fromSandboxClient: (client: SandboxClientResource, definition: SandboxDefinition, instance: string) => SandboxInstanceClient;
|
|
197
|
+
declare const isSandboxNamespaceResource: <Candidate>(value: Candidate) => value is Candidate & SandboxNamespaceResource;
|
|
198
|
+
declare const makeClient: (definition: SandboxDefinition) => <Namespace extends SandboxNamespaceResource>(namespace: Namespace) => SandboxNamespaceClient<Namespace>;
|
|
199
|
+
declare const layer: <Self, Namespace extends SandboxNamespaceResource>(tag: Context.Service<Self, SandboxNamespaceClient<Namespace>>, definition: SandboxDefinition) => Layer.Layer<Self, BindingNotFoundError | BindingValidationError, WorkerEnvironment>;
|
|
200
|
+
declare const make: <Id extends string>(id: Id) => TagClass<SandboxNamespaceService<Id>, Id, SandboxNamespaceResource>;
|
|
201
|
+
declare const SandboxNamespaceServiceTypeId: unique symbol;
|
|
202
|
+
/** Nominal service marker for Sandbox namespaces created with {@link make}. */
|
|
203
|
+
interface SandboxNamespaceService<Id extends string> {
|
|
204
|
+
readonly [SandboxNamespaceServiceTypeId]: {
|
|
205
|
+
readonly id: Id;
|
|
206
|
+
};
|
|
207
|
+
}
|
|
208
|
+
/** Creates a typed Effect service for a Cloudflare Sandbox namespace. */
|
|
209
|
+
declare const Tag: <Self, Namespace extends SandboxNamespaceResource = SandboxNamespaceResource>() => <Id extends string>(id: Id) => TagClass<Self, Id, Namespace>;
|
|
210
|
+
declare const Sandbox: typeof Tag;
|
|
211
|
+
/**
|
|
212
|
+
* Routes sandbox preview-URL requests (`https://<port>-<sandbox-id>-<token>.<host>`)
|
|
213
|
+
* to the owning sandbox, mirroring `proxyToSandbox` from `@cloudflare/sandbox`.
|
|
214
|
+
*
|
|
215
|
+
* Call this before any other routing in a Worker `fetch` handler; it resolves
|
|
216
|
+
* to `Option.none()` for requests that are not preview-URL traffic.
|
|
217
|
+
*/
|
|
218
|
+
declare const proxyToSandbox: (request: Request<unknown, CfProperties<unknown>>, options?: {
|
|
219
|
+
readonly binding?: string;
|
|
220
|
+
} | undefined) => Effect.Effect<Option.Option<Response>, SandboxOperationError, WorkerEnvironment>;
|
|
221
|
+
//#endregion
|
|
222
|
+
export { type BackupOptions, type CheckChangesOptions, type CheckChangesResult, type CreateTerminalOptions, DeleteFileResult, type DirectoryBackup, type ExecOptions, ExposePortOptions, ExposedPort, ExposedPortStatus, FileExistsResult, type FileWatchSSEEvent, type ISandbox, LayerOptions, type ListFilesOptions, ListFilesResult, MkdirResult, type MountBucketOptions, MoveFileResult, type ProcessExit, type ProcessLogEvent, type ProcessLogsOptions, type ProcessOutput, type ProcessOutputOptions, type ProcessStatus, ReadFileEncoding, ReadFileResult, RenameFileResult, type RestoreBackupResult, Sandbox, SandboxClientResource, type SandboxCommand, SandboxDefinition, SandboxInstanceClient, SandboxNamespaceClient, SandboxNamespaceResource, SandboxNamespaceService, SandboxOperationError, type SandboxOptions, type SandboxProcess, SandboxProcessHandle, SandboxTerminalHandle, SandboxTunnelsClient, SandboxTunnelsResource, Tag, TagClass, type Terminal, type TerminalOutputCursor, type TerminalOutputEvent, type TerminalOutputOptions, type TerminalSnapshot, type TunnelInfo, type TunnelOptions, type WaitForExitOptions, type WaitForLogOptions, type WaitForLogResult, type WaitForPortOptions, type WatchOptions, WriteFileResult, fromSandboxClient, isSandboxNamespaceResource, layer, make, makeClient, proxyToSandbox };
|