@cloudflare/sandbox 0.13.0-next.776.1 → 1.0.0-rc.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/README.md +62 -219
- package/dist/index.d.mts +548 -0
- package/dist/index.mjs +2452 -0
- package/package.json +17 -118
- package/Dockerfile +0 -368
- package/dist/bridge/index.d.ts +0 -181
- package/dist/bridge/index.d.ts.map +0 -1
- package/dist/bridge/index.js +0 -3053
- package/dist/bridge/index.js.map +0 -1
- package/dist/contexts-1EsLHByO.d.ts +0 -463
- package/dist/contexts-1EsLHByO.d.ts.map +0 -1
- package/dist/dist-Duor5GbS.js +0 -752
- package/dist/dist-Duor5GbS.js.map +0 -1
- package/dist/errors/index.d.ts +0 -4
- package/dist/errors/index.js +0 -4
- package/dist/errors-CXR0xBpw.js +0 -285
- package/dist/errors-CXR0xBpw.js.map +0 -1
- package/dist/errors-QYlSkVGz.js +0 -893
- package/dist/errors-QYlSkVGz.js.map +0 -1
- package/dist/extensions/index.d.ts +0 -4
- package/dist/extensions/index.js +0 -6
- package/dist/extensions-CFB2xHqY.js +0 -1023
- package/dist/extensions-CFB2xHqY.js.map +0 -1
- package/dist/filesystem-BWAZCZER.d.ts +0 -732
- package/dist/filesystem-BWAZCZER.d.ts.map +0 -1
- package/dist/git/index.d.ts +0 -63
- package/dist/git/index.d.ts.map +0 -1
- package/dist/git/index.js +0 -338
- package/dist/git/index.js.map +0 -1
- package/dist/index-Bs4bqXDR.d.ts +0 -438
- package/dist/index-Bs4bqXDR.d.ts.map +0 -1
- package/dist/index-HNYBk-az.d.ts +0 -444
- package/dist/index-HNYBk-az.d.ts.map +0 -1
- package/dist/index.d.ts +0 -576
- package/dist/index.d.ts.map +0 -1
- package/dist/index.js +0 -33
- package/dist/index.js.map +0 -1
- package/dist/interpreter/index.d.ts +0 -311
- package/dist/interpreter/index.d.ts.map +0 -1
- package/dist/interpreter/index.js +0 -292
- package/dist/interpreter/index.js.map +0 -1
- package/dist/openai/index.d.ts +0 -68
- package/dist/openai/index.d.ts.map +0 -1
- package/dist/openai/index.js +0 -367
- package/dist/openai/index.js.map +0 -1
- package/dist/opencode/index.d.ts +0 -182
- package/dist/opencode/index.d.ts.map +0 -1
- package/dist/opencode/index.js +0 -454
- package/dist/opencode/index.js.map +0 -1
- package/dist/process-types-GStiZ8f8.d.ts +0 -73
- package/dist/process-types-GStiZ8f8.d.ts.map +0 -1
- package/dist/sandbox-BbAabq93.d.ts +0 -42
- package/dist/sandbox-BbAabq93.d.ts.map +0 -1
- package/dist/sandbox-cmlgGVYX.js +0 -10056
- package/dist/sandbox-cmlgGVYX.js.map +0 -1
- package/dist/sidecar/index.d.ts +0 -77
- package/dist/sidecar/index.d.ts.map +0 -1
- package/dist/sidecar/index.js +0 -201
- package/dist/sidecar/index.js.map +0 -1
- package/dist/xterm/index.d.ts +0 -93
- package/dist/xterm/index.d.ts.map +0 -1
- package/dist/xterm/index.js +0 -220
- package/dist/xterm/index.js.map +0 -1
package/dist/index.d.mts
ADDED
|
@@ -0,0 +1,548 @@
|
|
|
1
|
+
import { WorkerEntrypoint } from "cloudflare:workers";
|
|
2
|
+
import "zod/mini";
|
|
3
|
+
//#region src/directory-backups/contracts.d.ts
|
|
4
|
+
/** The only archive format this version writes and reads. */
|
|
5
|
+
declare const DIRECTORY_BACKUP_FORMAT = "tar+zstd/1";
|
|
6
|
+
/**
|
|
7
|
+
* A saved directory. A plain, serializable object: store it wherever the application keeps
|
|
8
|
+
* state. It only works with the same R2 binding and key prefix that created it.
|
|
9
|
+
*/
|
|
10
|
+
interface DirectoryBackup {
|
|
11
|
+
/** UUID. The object key is `<prefix><id>.tar.zst`. */
|
|
12
|
+
readonly id: string;
|
|
13
|
+
/** The directory the backup came from, and the default restore target. */
|
|
14
|
+
readonly dir: string;
|
|
15
|
+
/** Stored bytes, as R2 reported when the upload completed. */
|
|
16
|
+
readonly size: number;
|
|
17
|
+
readonly name?: string;
|
|
18
|
+
/** SHA-256 of the stored object, checked on every restore. */
|
|
19
|
+
readonly sha256: string;
|
|
20
|
+
readonly format: typeof DIRECTORY_BACKUP_FORMAT;
|
|
21
|
+
}
|
|
22
|
+
/** Where backups are stored. */
|
|
23
|
+
interface DirectoryBackupStorage {
|
|
24
|
+
/** Name of an R2 bucket binding in the Worker's `env`. The gateway reads it there. */
|
|
25
|
+
readonly binding: string;
|
|
26
|
+
/** Optional key prefix. A non-empty prefix ends in `/`. */
|
|
27
|
+
readonly prefix?: string;
|
|
28
|
+
}
|
|
29
|
+
interface DirectoryBackupOptions {
|
|
30
|
+
/** Absolute path of the directory to back up. Pause writers in it first. */
|
|
31
|
+
dir: string;
|
|
32
|
+
/** A label stored in the record and in the object's custom metadata. */
|
|
33
|
+
name?: string;
|
|
34
|
+
/** gitignore-syntax patterns, relative to `dir`. */
|
|
35
|
+
exclude?: readonly string[];
|
|
36
|
+
/** Also apply `.gitignore` files inside `dir` and `.git/info/exclude`. No `git` binary is needed. */
|
|
37
|
+
gitignore?: boolean;
|
|
38
|
+
/** Cancels the operation without imposing a timeout. */
|
|
39
|
+
signal?: AbortSignal;
|
|
40
|
+
}
|
|
41
|
+
interface DirectoryRestoreOptions {
|
|
42
|
+
/** Absolute path to restore into instead of the record's `dir`. */
|
|
43
|
+
dir?: string;
|
|
44
|
+
/** Cancels the operation without imposing a timeout. */
|
|
45
|
+
signal?: AbortSignal;
|
|
46
|
+
}
|
|
47
|
+
interface DirectoryBackupDeleteOptions {
|
|
48
|
+
signal?: AbortSignal;
|
|
49
|
+
}
|
|
50
|
+
interface DirectoryBackupPart {
|
|
51
|
+
readonly partNumber: number;
|
|
52
|
+
readonly etag: string;
|
|
53
|
+
}
|
|
54
|
+
/** Props for the Durable Object's control calls. The container never receives these. */
|
|
55
|
+
interface ControlGatewayProps {
|
|
56
|
+
readonly protocolVersion: 1;
|
|
57
|
+
readonly mode: "control";
|
|
58
|
+
readonly binding: string;
|
|
59
|
+
readonly key: string;
|
|
60
|
+
}
|
|
61
|
+
/** The one grant the container holds while its operation runs: write parts of one upload. */
|
|
62
|
+
interface WriteGatewayProps {
|
|
63
|
+
readonly protocolVersion: 1;
|
|
64
|
+
readonly mode: "write";
|
|
65
|
+
readonly binding: string;
|
|
66
|
+
readonly key: string;
|
|
67
|
+
readonly uploadId: string;
|
|
68
|
+
}
|
|
69
|
+
/** The one grant the container holds while its operation runs: read ranges of one object. */
|
|
70
|
+
interface ReadGatewayProps {
|
|
71
|
+
readonly protocolVersion: 1;
|
|
72
|
+
readonly mode: "read";
|
|
73
|
+
readonly binding: string;
|
|
74
|
+
readonly key: string;
|
|
75
|
+
}
|
|
76
|
+
/** Props that deny every container request once an operation ends. */
|
|
77
|
+
interface DenyGatewayProps {
|
|
78
|
+
readonly protocolVersion: 1;
|
|
79
|
+
readonly mode: "deny";
|
|
80
|
+
}
|
|
81
|
+
type DirectoryBackupGatewayProps = ControlGatewayProps | WriteGatewayProps | ReadGatewayProps | DenyGatewayProps;
|
|
82
|
+
/** The control methods `DirectoryBackupGateway` exposes to the Durable Object over RPC. */
|
|
83
|
+
interface DirectoryBackupGatewayControl {
|
|
84
|
+
createUpload(name?: string): Promise<string>;
|
|
85
|
+
completeUpload(uploadId: string, parts: readonly DirectoryBackupPart[]): Promise<number>;
|
|
86
|
+
abortUpload(uploadId: string): Promise<void>;
|
|
87
|
+
deleteObject(): Promise<void>;
|
|
88
|
+
}
|
|
89
|
+
/** The application's `ctx.exports.DirectoryBackupGateway`. */
|
|
90
|
+
interface DirectoryBackupGatewayBinding {
|
|
91
|
+
(options: {
|
|
92
|
+
readonly props: DirectoryBackupGatewayProps;
|
|
93
|
+
}): Fetcher & DirectoryBackupGatewayControl;
|
|
94
|
+
}
|
|
95
|
+
//#endregion
|
|
96
|
+
//#region src/directory-backups/directory-backup-gateway.d.ts
|
|
97
|
+
/**
|
|
98
|
+
* Moves directory backups between a container and an R2 bucket binding. Export it from the
|
|
99
|
+
* Worker and pass `ctx.exports.DirectoryBackupGateway` to `DirectoryBackups`.
|
|
100
|
+
*
|
|
101
|
+
* The container reaches `fetch()` through the outbound intercept and can only use the grant
|
|
102
|
+
* its current operation holds. The other methods are for the Durable Object alone.
|
|
103
|
+
*/
|
|
104
|
+
declare class DirectoryBackupGateway extends WorkerEntrypoint<object, DirectoryBackupGatewayProps> {
|
|
105
|
+
#private;
|
|
106
|
+
fetch(request: Request): Promise<Response>;
|
|
107
|
+
createUpload(name?: string): Promise<string>;
|
|
108
|
+
completeUpload(uploadId: string, parts: readonly DirectoryBackupPart[]): Promise<number>;
|
|
109
|
+
abortUpload(uploadId: string): Promise<void>;
|
|
110
|
+
deleteObject(): Promise<void>;
|
|
111
|
+
}
|
|
112
|
+
//#endregion
|
|
113
|
+
//#region src/directory-backups/directory-backups.d.ts
|
|
114
|
+
type DirectoryBackupContainer = Pick<Container, "exec" | "interceptOutboundHttp">;
|
|
115
|
+
/**
|
|
116
|
+
* Saves one directory from the running Container to an R2 bucket, and restores it as
|
|
117
|
+
* ordinary files into a Container, which may run a different image.
|
|
118
|
+
*
|
|
119
|
+
* One backup or restore runs at a time per Container; others wait their turn, so
|
|
120
|
+
* `Promise.all()` over several directories works. Start the Container first: this class never
|
|
121
|
+
* starts, retries, or times out anything. The application stores the returned records and
|
|
122
|
+
* decides when to delete them.
|
|
123
|
+
*/
|
|
124
|
+
declare class DirectoryBackups {
|
|
125
|
+
#private;
|
|
126
|
+
constructor(container: DirectoryBackupContainer, gateway: DirectoryBackupGatewayBinding, storage: DirectoryBackupStorage);
|
|
127
|
+
/**
|
|
128
|
+
* Backs up `dir` and returns its record. Pause writers in `dir` first: files that change
|
|
129
|
+
* while it's read are captured as they are at that moment.
|
|
130
|
+
*
|
|
131
|
+
* @throws {SandboxFileError} `dir` is missing or not a directory, a file can't be read, or an
|
|
132
|
+
* exclude pattern is invalid (`EINVAL`).
|
|
133
|
+
* @throws {SandboxBackupError} `BACKUP_TRANSFER` when a part upload fails, or
|
|
134
|
+
* `BACKUP_INTEGRITY` when R2 stored a different size than was uploaded.
|
|
135
|
+
*/
|
|
136
|
+
backup(options: DirectoryBackupOptions): Promise<DirectoryBackup>;
|
|
137
|
+
/**
|
|
138
|
+
* Replaces `options.dir`, or the record's `dir`, with the backup's contents. The directory is
|
|
139
|
+
* extracted beside the target and swapped in only after the download is verified, so a failed
|
|
140
|
+
* or aborted restore leaves the target as it was. The target's parent must exist; the target
|
|
141
|
+
* need not.
|
|
142
|
+
*
|
|
143
|
+
* @throws {SandboxFileError} The target's parent is missing (`ENOENT`), the target isn't a
|
|
144
|
+
* directory (`ENOTDIR`) or is a mount point (`EBUSY`), the swap fails (for example `EXDEV`),
|
|
145
|
+
* or the disk fills (`ENOSPC`).
|
|
146
|
+
* @throws {SandboxBackupError} `BACKUP_NOT_FOUND`, `BACKUP_INTEGRITY`, or `BACKUP_TRANSFER`.
|
|
147
|
+
*/
|
|
148
|
+
restore(backup: DirectoryBackup, options?: DirectoryRestoreOptions): Promise<void>;
|
|
149
|
+
/**
|
|
150
|
+
* Deletes the backup's object. Needs no running Container. Deleting an object that is already
|
|
151
|
+
* gone succeeds. A restore reading it at the same time fails, and nothing is swapped.
|
|
152
|
+
*/
|
|
153
|
+
delete(backup: DirectoryBackup, options?: DirectoryBackupDeleteOptions): Promise<void>;
|
|
154
|
+
}
|
|
155
|
+
//#endregion
|
|
156
|
+
//#region src/files/content.d.ts
|
|
157
|
+
type FileContent = string | ArrayBuffer | ArrayBufferView | Blob | ReadableStream<Uint8Array>;
|
|
158
|
+
//#endregion
|
|
159
|
+
//#region src/files/file-type.d.ts
|
|
160
|
+
type SandboxFileType = "file" | "directory" | "symlink" | "blockDevice" | "characterDevice" | "fifo" | "socket";
|
|
161
|
+
//#endregion
|
|
162
|
+
//#region src/files/read-directory.d.ts
|
|
163
|
+
interface SandboxDirectoryEntry {
|
|
164
|
+
name: string;
|
|
165
|
+
type: SandboxFileType;
|
|
166
|
+
}
|
|
167
|
+
//#endregion
|
|
168
|
+
//#region src/files/stat-file.d.ts
|
|
169
|
+
interface SandboxFileStat {
|
|
170
|
+
type: SandboxFileType;
|
|
171
|
+
size: bigint;
|
|
172
|
+
mode: number;
|
|
173
|
+
uid: number;
|
|
174
|
+
gid: number;
|
|
175
|
+
accessedAt: Date;
|
|
176
|
+
modifiedAt: Date;
|
|
177
|
+
changedAt: Date;
|
|
178
|
+
}
|
|
179
|
+
//#endregion
|
|
180
|
+
//#region src/files/files.d.ts
|
|
181
|
+
interface FileOperationOptions {
|
|
182
|
+
/** Absolute directory that a relative path is joined onto. An absolute path ignores it. */
|
|
183
|
+
cwd?: string;
|
|
184
|
+
/** Numeric user and group IDs that open the file, as `uid:gid`. */
|
|
185
|
+
user?: string;
|
|
186
|
+
/** Cancels the native container process without imposing a timeout. */
|
|
187
|
+
signal?: AbortSignal;
|
|
188
|
+
}
|
|
189
|
+
type RemoveOptions = FileOperationOptions & {
|
|
190
|
+
/** Permits removing a directory tree without following symlinks. */
|
|
191
|
+
recursive?: boolean;
|
|
192
|
+
/** Ignores a missing target. */
|
|
193
|
+
force?: boolean;
|
|
194
|
+
};
|
|
195
|
+
type MkdirOptions = FileOperationOptions & {
|
|
196
|
+
/** Creates missing parent directories and accepts an existing target directory. */
|
|
197
|
+
recursive?: boolean;
|
|
198
|
+
};
|
|
199
|
+
/**
|
|
200
|
+
* Structured file operations for a sandbox workspace.
|
|
201
|
+
*
|
|
202
|
+
* Operations run against the current native container execution. Its image must provide the matching shim at
|
|
203
|
+
* `/usr/local/bin/sandbox-shim`.
|
|
204
|
+
*/
|
|
205
|
+
declare class Files {
|
|
206
|
+
#private;
|
|
207
|
+
constructor(container: Pick<Container, "exec">);
|
|
208
|
+
/**
|
|
209
|
+
* Streams bytes from a path in the running container using native Linux file semantics.
|
|
210
|
+
*
|
|
211
|
+
* Native container, transport, and abort failures propagate unchanged.
|
|
212
|
+
*
|
|
213
|
+
* @param path - Absolute path, or a relative path when `options.cwd` is provided.
|
|
214
|
+
* @param options - Native execution options relevant to opening the file.
|
|
215
|
+
* @returns A binary response whose body applies backpressure to the container process. A
|
|
216
|
+
* file-streaming or native transport failure can surface while the body is consumed.
|
|
217
|
+
* @throws {TypeError} The path is empty, contains NUL, or is relative without `cwd`, or an
|
|
218
|
+
* option is unknown or invalid.
|
|
219
|
+
* @throws {SandboxFileError} The container reports a filesystem failure before returning the
|
|
220
|
+
* response. A late file-streaming failure errors the response body with the same error type.
|
|
221
|
+
* @throws {SandboxProtocolError} The package and `sandbox-shim` cannot complete their protocol.
|
|
222
|
+
*/
|
|
223
|
+
readFile(path: string, options?: FileOperationOptions): Promise<Response>;
|
|
224
|
+
/**
|
|
225
|
+
* Creates or truncates a file and streams content into it using native Linux semantics.
|
|
226
|
+
*
|
|
227
|
+
* The destination is opened before a caller-provided stream is consumed. Failures after that
|
|
228
|
+
* point can leave a created, truncated, or partially written file. Native container, transport,
|
|
229
|
+
* source-stream, and abort failures propagate unchanged.
|
|
230
|
+
*
|
|
231
|
+
* @throws {TypeError} The path is empty, contains NUL, or is relative without an absolute `cwd`,
|
|
232
|
+
* or an option is unknown or invalid.
|
|
233
|
+
* @throws {SandboxFileError} The container reports a filesystem failure.
|
|
234
|
+
* @throws {SandboxProtocolError} The package and `sandbox-shim` cannot complete their protocol.
|
|
235
|
+
*/
|
|
236
|
+
writeFile(path: string, content: FileContent, options?: FileOperationOptions): Promise<void>;
|
|
237
|
+
/**
|
|
238
|
+
* Returns metadata for a path using native Linux filesystem semantics.
|
|
239
|
+
*
|
|
240
|
+
* Native container, transport, and abort failures propagate unchanged.
|
|
241
|
+
*
|
|
242
|
+
* @throws {TypeError} The path is empty, contains NUL, or is relative without an absolute `cwd`,
|
|
243
|
+
* or an option is unknown or invalid.
|
|
244
|
+
* @throws {SandboxFileError} The container reports a filesystem failure.
|
|
245
|
+
* @throws {SandboxProtocolError} The package and `sandbox-shim` cannot complete their protocol.
|
|
246
|
+
*/
|
|
247
|
+
stat(path: string, options?: FileOperationOptions): Promise<SandboxFileStat>;
|
|
248
|
+
/**
|
|
249
|
+
* Returns metadata for a path without following its final symlink.
|
|
250
|
+
*
|
|
251
|
+
* Native container, transport, and abort failures propagate unchanged.
|
|
252
|
+
*
|
|
253
|
+
* @throws {TypeError} The path is empty, contains NUL, or is relative without an absolute `cwd`,
|
|
254
|
+
* or an option is unknown or invalid.
|
|
255
|
+
* @throws {SandboxFileError} The container reports a filesystem failure.
|
|
256
|
+
* @throws {SandboxProtocolError} The package and `sandbox-shim` cannot complete their protocol.
|
|
257
|
+
*/
|
|
258
|
+
lstat(path: string, options?: FileOperationOptions): Promise<SandboxFileStat>;
|
|
259
|
+
/**
|
|
260
|
+
* Returns the immediate entries from a directory in native enumeration order.
|
|
261
|
+
*
|
|
262
|
+
* The directory path may resolve through a symlink, but entry types describe the entries
|
|
263
|
+
* themselves and do not follow symlinks. The operation does not recurse or retrieve metadata
|
|
264
|
+
* for each child.
|
|
265
|
+
* Native container, transport, and abort failures propagate unchanged.
|
|
266
|
+
*
|
|
267
|
+
* @throws {TypeError} The path is empty, contains NUL, or is relative without an absolute `cwd`,
|
|
268
|
+
* or an option is unknown or invalid.
|
|
269
|
+
* @throws {SandboxFileError} The container reports a filesystem failure.
|
|
270
|
+
* @throws {SandboxProtocolError} The package and `sandbox-shim` cannot complete their protocol.
|
|
271
|
+
*/
|
|
272
|
+
readDirectory(path: string, options?: FileOperationOptions): Promise<SandboxDirectoryEntry[]>;
|
|
273
|
+
/**
|
|
274
|
+
* Creates a directory using native Linux filesystem semantics.
|
|
275
|
+
*
|
|
276
|
+
* By default only the final directory is created. With `recursive`, missing parents are
|
|
277
|
+
* created and an existing target directory is accepted. Partial parent creation can remain
|
|
278
|
+
* after failure or cancellation.
|
|
279
|
+
* Native container, transport, and abort failures propagate unchanged.
|
|
280
|
+
*
|
|
281
|
+
* @throws {TypeError} The path is empty, contains NUL, or is relative without an absolute `cwd`,
|
|
282
|
+
* or an option is unknown or invalid.
|
|
283
|
+
* @throws {SandboxFileError} The container reports a filesystem failure.
|
|
284
|
+
* @throws {SandboxProtocolError} The package and `sandbox-shim` cannot complete their protocol.
|
|
285
|
+
*/
|
|
286
|
+
mkdir(path: string, options?: MkdirOptions): Promise<void>;
|
|
287
|
+
/**
|
|
288
|
+
* Renames a file, directory, or symlink using native Linux filesystem semantics.
|
|
289
|
+
*
|
|
290
|
+
* Existing destinations are replaced when Linux permits it. Cross-filesystem renames fail
|
|
291
|
+
* with `EXDEV`; no copy-and-remove fallback is attempted.
|
|
292
|
+
* Native container, transport, and abort failures propagate unchanged.
|
|
293
|
+
*
|
|
294
|
+
* @throws {TypeError} A path is empty, contains NUL, or is relative without an absolute `cwd`,
|
|
295
|
+
* or an option is unknown or invalid.
|
|
296
|
+
* @throws {SandboxFileError} The container reports a filesystem failure.
|
|
297
|
+
* @throws {SandboxProtocolError} The package and `sandbox-shim` cannot complete their protocol.
|
|
298
|
+
*/
|
|
299
|
+
rename(source: string, destination: string, options?: FileOperationOptions): Promise<void>;
|
|
300
|
+
/**
|
|
301
|
+
* Removes a file or symlink using native Linux filesystem semantics.
|
|
302
|
+
*
|
|
303
|
+
* Directories are rejected unless `recursive` is set. Recursive removal does not follow
|
|
304
|
+
* symlinks and can leave partial effects after failure or cancellation. `force` ignores only
|
|
305
|
+
* a missing target. Native container, transport, and abort failures propagate unchanged.
|
|
306
|
+
*
|
|
307
|
+
* @throws {TypeError} The path is empty, contains NUL, or is relative without an absolute `cwd`,
|
|
308
|
+
* or an option is unknown or invalid.
|
|
309
|
+
* @throws {SandboxFileError} The container reports a filesystem failure.
|
|
310
|
+
* @throws {SandboxProtocolError} The package and `sandbox-shim` cannot complete their protocol.
|
|
311
|
+
*/
|
|
312
|
+
remove(path: string, options?: RemoveOptions): Promise<void>;
|
|
313
|
+
}
|
|
314
|
+
//#endregion
|
|
315
|
+
//#region src/s3-mounts/contracts.d.ts
|
|
316
|
+
type S3MountAccess = "read-only" | "read-write";
|
|
317
|
+
type S3MountCredentials = {
|
|
318
|
+
readonly type: "static";
|
|
319
|
+
readonly accessKeyId: string;
|
|
320
|
+
readonly secretAccessKey: string;
|
|
321
|
+
readonly sessionToken?: string;
|
|
322
|
+
} | {
|
|
323
|
+
readonly type: "provider";
|
|
324
|
+
readonly fetcher: Pick<Fetcher, "fetch">;
|
|
325
|
+
};
|
|
326
|
+
type S3MountSource = {
|
|
327
|
+
readonly type: "s3";
|
|
328
|
+
readonly endpoint: string;
|
|
329
|
+
readonly region: string;
|
|
330
|
+
readonly bucket: string;
|
|
331
|
+
readonly credentials: S3MountCredentials;
|
|
332
|
+
};
|
|
333
|
+
type S3fsOptionValue = string | number | boolean;
|
|
334
|
+
interface S3MountRequest {
|
|
335
|
+
readonly mountPath: string;
|
|
336
|
+
readonly source: S3MountSource;
|
|
337
|
+
/** Optional object-key prefix. A non-empty value ends in `/`. */
|
|
338
|
+
readonly keyPrefix?: string;
|
|
339
|
+
readonly access: S3MountAccess;
|
|
340
|
+
readonly s3fsOptions?: Readonly<Record<string, S3fsOptionValue>>;
|
|
341
|
+
}
|
|
342
|
+
interface S3MountOperationOptions {
|
|
343
|
+
readonly signal?: AbortSignal;
|
|
344
|
+
}
|
|
345
|
+
interface S3MountObservedConfiguration {
|
|
346
|
+
readonly source: {
|
|
347
|
+
readonly type: "s3";
|
|
348
|
+
readonly endpoint: string;
|
|
349
|
+
readonly region: string;
|
|
350
|
+
readonly bucket: string;
|
|
351
|
+
};
|
|
352
|
+
/** Omitted for the bucket root; otherwise canonical and slash-terminated. */
|
|
353
|
+
readonly keyPrefix?: string;
|
|
354
|
+
readonly access: S3MountAccess;
|
|
355
|
+
readonly s3fsOptions: readonly {
|
|
356
|
+
readonly name: string;
|
|
357
|
+
readonly value?: string;
|
|
358
|
+
}[];
|
|
359
|
+
}
|
|
360
|
+
type S3MountFuseInspection = {
|
|
361
|
+
readonly status: "connected";
|
|
362
|
+
} | {
|
|
363
|
+
readonly status: "disconnected";
|
|
364
|
+
} | {
|
|
365
|
+
readonly status: "indeterminate";
|
|
366
|
+
readonly detail: string;
|
|
367
|
+
};
|
|
368
|
+
type S3MountGatewayInspection = {
|
|
369
|
+
readonly status: "unreachable";
|
|
370
|
+
readonly detail: string;
|
|
371
|
+
} | {
|
|
372
|
+
readonly status: "error";
|
|
373
|
+
readonly reason: "credential-provider" | "protocol" | "internal";
|
|
374
|
+
readonly detail: string;
|
|
375
|
+
} | {
|
|
376
|
+
readonly status: "reachable";
|
|
377
|
+
readonly upstream: {
|
|
378
|
+
readonly status: "usable";
|
|
379
|
+
} | {
|
|
380
|
+
readonly status: "unavailable";
|
|
381
|
+
readonly detail: string;
|
|
382
|
+
} | {
|
|
383
|
+
readonly status: "rejected";
|
|
384
|
+
readonly reason: "credentials" | "access" | "not-found" | "other";
|
|
385
|
+
readonly detail: string;
|
|
386
|
+
};
|
|
387
|
+
};
|
|
388
|
+
type S3MountInspection = {
|
|
389
|
+
readonly mountPath: string;
|
|
390
|
+
readonly attachment: {
|
|
391
|
+
readonly status: "absent";
|
|
392
|
+
};
|
|
393
|
+
} | {
|
|
394
|
+
readonly mountPath: string;
|
|
395
|
+
readonly attachment: {
|
|
396
|
+
readonly status: "unmanaged";
|
|
397
|
+
readonly filesystemType: string;
|
|
398
|
+
};
|
|
399
|
+
} | {
|
|
400
|
+
readonly mountPath: string;
|
|
401
|
+
readonly attachment: {
|
|
402
|
+
readonly status: "incompatible";
|
|
403
|
+
};
|
|
404
|
+
} | {
|
|
405
|
+
readonly mountPath: string;
|
|
406
|
+
readonly attachment: {
|
|
407
|
+
readonly status: "stale";
|
|
408
|
+
readonly configuration: S3MountObservedConfiguration;
|
|
409
|
+
};
|
|
410
|
+
readonly gateway: S3MountGatewayInspection;
|
|
411
|
+
} | {
|
|
412
|
+
readonly mountPath: string;
|
|
413
|
+
readonly attachment: {
|
|
414
|
+
readonly status: "managed";
|
|
415
|
+
readonly configuration: S3MountObservedConfiguration;
|
|
416
|
+
};
|
|
417
|
+
readonly fuse: S3MountFuseInspection;
|
|
418
|
+
readonly gateway: S3MountGatewayInspection;
|
|
419
|
+
};
|
|
420
|
+
/** Props passed only to an active route-scoped `S3Gateway` service instance. */
|
|
421
|
+
interface ActiveS3GatewayProps {
|
|
422
|
+
readonly protocolVersion: 1;
|
|
423
|
+
readonly mode: "active";
|
|
424
|
+
readonly routeId: string;
|
|
425
|
+
readonly source: S3MountSource;
|
|
426
|
+
readonly keyPrefix?: string;
|
|
427
|
+
readonly access: S3MountAccess;
|
|
428
|
+
}
|
|
429
|
+
/** Props that deny requests after the matching mount is removed. */
|
|
430
|
+
interface DenyS3GatewayProps {
|
|
431
|
+
readonly protocolVersion: 1;
|
|
432
|
+
readonly mode: "deny";
|
|
433
|
+
readonly routeId: string;
|
|
434
|
+
}
|
|
435
|
+
type S3GatewayProps = ActiveS3GatewayProps | DenyS3GatewayProps;
|
|
436
|
+
interface S3GatewayBinding {
|
|
437
|
+
(options: {
|
|
438
|
+
readonly props: S3GatewayProps;
|
|
439
|
+
}): Fetcher;
|
|
440
|
+
}
|
|
441
|
+
//#endregion
|
|
442
|
+
//#region src/s3-mounts/s3-gateway.d.ts
|
|
443
|
+
declare class S3Gateway extends WorkerEntrypoint<object, S3GatewayProps> {
|
|
444
|
+
fetch(request: Request): Promise<Response>;
|
|
445
|
+
}
|
|
446
|
+
//#endregion
|
|
447
|
+
//#region src/s3-mounts/s3-mounts.d.ts
|
|
448
|
+
type S3MountContainer = Pick<Container, "exec" | "interceptOutboundHttp">;
|
|
449
|
+
/**
|
|
450
|
+
* Attaches an S3-compatible bucket or prefix to a running Container.
|
|
451
|
+
*
|
|
452
|
+
* Use this for a few long-lived mounts in one job or session. Calling `mount()`
|
|
453
|
+
* again with the same settings reuses the existing mount. `unmount()` stops
|
|
454
|
+
* access and unmounts the path. It does not fully clean up the Container's
|
|
455
|
+
* intercept. For a new job or tenant, use a new sandbox name.
|
|
456
|
+
*
|
|
457
|
+
* Start the Container before calling `mount()`. This class never starts,
|
|
458
|
+
* monitors, or replaces it. The mounted path is not a POSIX filesystem. Do not
|
|
459
|
+
* use it for locking or atomic rename.
|
|
460
|
+
*/
|
|
461
|
+
declare class S3Mounts {
|
|
462
|
+
#private;
|
|
463
|
+
constructor(container: S3MountContainer, gateway: S3GatewayBinding);
|
|
464
|
+
/**
|
|
465
|
+
* Creates the mount, reuses a matching mount, or repairs leftover state.
|
|
466
|
+
*
|
|
467
|
+
* Reuse does not consume another Container intercept. Use `inspect()` to read
|
|
468
|
+
* current state without changing it.
|
|
469
|
+
*/
|
|
470
|
+
mount(request: S3MountRequest, options?: S3MountOperationOptions): Promise<void>;
|
|
471
|
+
/**
|
|
472
|
+
* Reports the current path without changing it.
|
|
473
|
+
*
|
|
474
|
+
* Waits for an in-flight `mount()` or `unmount()` on the same path first.
|
|
475
|
+
* Gateway evidence can be newer than the guest snapshot. Pass `signal` when
|
|
476
|
+
* the application needs a deadline.
|
|
477
|
+
*/
|
|
478
|
+
inspect(mountPath: string, options?: S3MountOperationOptions): Promise<S3MountInspection>;
|
|
479
|
+
/**
|
|
480
|
+
* Stops new access, then unmounts the path.
|
|
481
|
+
*
|
|
482
|
+
* This does not remove the Container intercept. If denying access fails, the
|
|
483
|
+
* filesystem stays mounted. If the filesystem is busy, access stays denied
|
|
484
|
+
* and you can retry. This never force-unmounts.
|
|
485
|
+
*/
|
|
486
|
+
unmount(mountPath: string, options?: S3MountOperationOptions): Promise<void>;
|
|
487
|
+
}
|
|
488
|
+
//#endregion
|
|
489
|
+
//#region src/shared/errors.d.ts
|
|
490
|
+
/** Symbolic Linux errno, or `UNKNOWN` when the runtime does not name it. */
|
|
491
|
+
type SandboxFileErrorCode = `E${string}` | "UNKNOWN";
|
|
492
|
+
declare const FILE_OPERATIONS: readonly ["readFile", "writeFile", "stat", "lstat", "readDirectory", "mkdir", "rename", "remove", "backup", "restore"];
|
|
493
|
+
/** Filesystem operation that failed. */
|
|
494
|
+
type SandboxFileOperation = (typeof FILE_OPERATIONS)[number];
|
|
495
|
+
/** A native Linux filesystem failure reported by the sandbox container. */
|
|
496
|
+
interface SandboxFileError extends Error {
|
|
497
|
+
readonly name: "SandboxFileError";
|
|
498
|
+
readonly code: SandboxFileErrorCode;
|
|
499
|
+
readonly operation: SandboxFileOperation;
|
|
500
|
+
readonly path: string;
|
|
501
|
+
readonly destination?: string;
|
|
502
|
+
readonly detail: string;
|
|
503
|
+
}
|
|
504
|
+
declare const SandboxFileError: {
|
|
505
|
+
/** Recognizes local and JSRPC-crossed SandboxFileError values. */
|
|
506
|
+
is(cause: unknown): cause is SandboxFileError;
|
|
507
|
+
};
|
|
508
|
+
/** An incompatible or malformed exchange with `sandbox-shim`. */
|
|
509
|
+
interface SandboxProtocolError extends Error {
|
|
510
|
+
readonly name: "SandboxProtocolError";
|
|
511
|
+
readonly code: "SANDBOX_PROTOCOL_ERROR";
|
|
512
|
+
readonly detail: string;
|
|
513
|
+
}
|
|
514
|
+
declare const SandboxProtocolError: {
|
|
515
|
+
/** Recognizes local and JSRPC-crossed SandboxProtocolError values. */
|
|
516
|
+
is(cause: unknown): cause is SandboxProtocolError;
|
|
517
|
+
};
|
|
518
|
+
type SandboxS3MountErrorCode = "S3_MOUNT_CONFLICT" | "S3_MOUNT_BUSY" | "S3_MOUNT_FAILED" | "S3_MOUNT_INCOMPATIBLE";
|
|
519
|
+
type S3MountOperation = "mount" | "inspect" | "unmount";
|
|
520
|
+
/** A classifiable failure while reconciling an S3-compatible filesystem mount. */
|
|
521
|
+
interface SandboxS3MountError extends Error {
|
|
522
|
+
readonly name: "SandboxS3MountError";
|
|
523
|
+
readonly code: SandboxS3MountErrorCode;
|
|
524
|
+
readonly operation: S3MountOperation;
|
|
525
|
+
readonly path: string;
|
|
526
|
+
readonly detail: string;
|
|
527
|
+
}
|
|
528
|
+
declare const SandboxS3MountError: {
|
|
529
|
+
/** Recognizes local and JSRPC-crossed SandboxS3MountError values. */
|
|
530
|
+
is(cause: unknown): cause is SandboxS3MountError;
|
|
531
|
+
};
|
|
532
|
+
type SandboxBackupErrorCode = "BACKUP_NOT_FOUND" | "BACKUP_INTEGRITY" | "BACKUP_TRANSFER";
|
|
533
|
+
type DirectoryBackupOperation = "backup" | "restore" | "delete";
|
|
534
|
+
/** A failure specific to a directory backup: a missing, altered, or unreachable object. */
|
|
535
|
+
interface SandboxBackupError extends Error {
|
|
536
|
+
readonly name: "SandboxBackupError";
|
|
537
|
+
readonly code: SandboxBackupErrorCode;
|
|
538
|
+
readonly operation: DirectoryBackupOperation;
|
|
539
|
+
/** The directory being backed up or restored, or the record's directory for `delete`. */
|
|
540
|
+
readonly path: string;
|
|
541
|
+
readonly detail: string;
|
|
542
|
+
}
|
|
543
|
+
declare const SandboxBackupError: {
|
|
544
|
+
/** Recognizes local and JSRPC-crossed SandboxBackupError values. */
|
|
545
|
+
is(cause: unknown): cause is SandboxBackupError;
|
|
546
|
+
};
|
|
547
|
+
//#endregion
|
|
548
|
+
export { type DirectoryBackup, type DirectoryBackupDeleteOptions, DirectoryBackupGateway, type DirectoryBackupGatewayBinding, type DirectoryBackupOperation, type DirectoryBackupOptions, type DirectoryBackupStorage, DirectoryBackups, type DirectoryRestoreOptions, type FileContent, type FileOperationOptions, Files, type MkdirOptions, type RemoveOptions, S3Gateway, type S3GatewayBinding, type S3MountInspection, type S3MountOperation, type S3MountOperationOptions, type S3MountRequest, S3Mounts, SandboxBackupError, type SandboxBackupErrorCode, type SandboxDirectoryEntry, SandboxFileError, type SandboxFileStat, type SandboxFileType, SandboxProtocolError, SandboxS3MountError, type SandboxS3MountErrorCode };
|