@eryx-org/eryx 0.0.0 → 0.15.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +281 -4
- package/eryx-sandbox.conditional-host-import-0.wasm +0 -0
- package/eryx-sandbox.conditional-host-import-1.wasm +0 -0
- package/eryx-sandbox.conditional-suspending-1-i32-to-i32.wasm +0 -0
- package/eryx-sandbox.core.wasm +0 -0
- package/eryx-sandbox.core10.wasm +0 -0
- package/eryx-sandbox.core11.wasm +0 -0
- package/eryx-sandbox.core12.wasm +0 -0
- package/eryx-sandbox.core13.wasm +0 -0
- package/eryx-sandbox.core2.wasm +0 -0
- package/eryx-sandbox.core3.wasm +0 -0
- package/eryx-sandbox.core4.wasm +0 -0
- package/eryx-sandbox.core5.wasm +0 -0
- package/eryx-sandbox.core6.wasm +0 -0
- package/eryx-sandbox.core7.wasm +0 -0
- package/eryx-sandbox.core8.wasm +0 -0
- package/eryx-sandbox.core9.wasm +0 -0
- package/eryx-sandbox.d.ts +185 -0
- package/eryx-sandbox.js +55329 -0
- package/index.d.ts +331 -0
- package/index.js +698 -0
- package/instance.js +174 -0
- package/interfaces/eryx-net-tcp.d.ts +39 -0
- package/interfaces/eryx-net-tls.d.ts +33 -0
- package/interfaces/wasi-cli-environment.d.ts +3 -0
- package/interfaces/wasi-cli-exit.d.ts +3 -0
- package/interfaces/wasi-cli-stderr.d.ts +3 -0
- package/interfaces/wasi-cli-stdin.d.ts +3 -0
- package/interfaces/wasi-cli-stdout.d.ts +3 -0
- package/interfaces/wasi-cli-terminal-input.d.ts +8 -0
- package/interfaces/wasi-cli-terminal-output.d.ts +8 -0
- package/interfaces/wasi-cli-terminal-stderr.d.ts +3 -0
- package/interfaces/wasi-cli-terminal-stdin.d.ts +3 -0
- package/interfaces/wasi-cli-terminal-stdout.d.ts +3 -0
- package/interfaces/wasi-clocks-monotonic-clock.d.ts +8 -0
- package/interfaces/wasi-clocks-wall-clock.d.ts +7 -0
- package/interfaces/wasi-filesystem-preopens.d.ts +3 -0
- package/interfaces/wasi-filesystem-types.d.ts +288 -0
- package/interfaces/wasi-io-error.d.ts +8 -0
- package/interfaces/wasi-io-poll.d.ts +10 -0
- package/interfaces/wasi-io-streams.d.ts +51 -0
- package/interfaces/wasi-random-random.d.ts +2 -0
- package/interfaces/wasi-sockets-instance-network.d.ts +3 -0
- package/interfaces/wasi-sockets-ip-name-lookup.d.ts +21 -0
- package/interfaces/wasi-sockets-network.d.ts +92 -0
- package/interfaces/wasi-sockets-tcp-create-socket.d.ts +8 -0
- package/interfaces/wasi-sockets-tcp.d.ts +127 -0
- package/interfaces/wasi-sockets-udp-create-socket.d.ts +8 -0
- package/interfaces/wasi-sockets-udp.d.ts +93 -0
- package/package.json +69 -3
- package/python-stdlib.tar.gz +0 -0
- package/shims/callbacks.d.ts +45 -0
- package/shims/callbacks.js +469 -0
- package/shims/ip.js +46 -0
- package/shims/net-fetch.js +264 -0
- package/shims/net-node.js +236 -0
- package/shims/net.d.ts +84 -0
- package/shims/net.js +260 -0
- package/shims/preview2-node.js +35 -0
- package/shims/raw-json.js +111 -0
- package/shims/sockets.js +53 -0
- package/stdlib-loader.js +174 -0
- package/worker.js +100 -0
package/instance.js
ADDED
|
@@ -0,0 +1,174 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Building one sandbox instance: the shared stdlib template, compiled core
|
|
3
|
+
* modules and WASI imports, and per-instance filesystem and callback wiring.
|
|
4
|
+
* Used by index.js in-thread and by worker.js inside a Worker.
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
// The jco-generated component, transpiled with `--instantiation async` so each
|
|
8
|
+
// Sandbox gets its own instance and imports.
|
|
9
|
+
import { instantiate } from "./eryx-sandbox.js";
|
|
10
|
+
|
|
11
|
+
import {
|
|
12
|
+
environment,
|
|
13
|
+
exit,
|
|
14
|
+
stderr,
|
|
15
|
+
stdin,
|
|
16
|
+
stdout,
|
|
17
|
+
terminalInput,
|
|
18
|
+
terminalOutput,
|
|
19
|
+
terminalStderr,
|
|
20
|
+
terminalStdin,
|
|
21
|
+
terminalStdout,
|
|
22
|
+
} from "#preview2/cli";
|
|
23
|
+
import { monotonicClock, wallClock } from "#preview2/clocks";
|
|
24
|
+
import { createFilesystem, InMemoryFilesystemAdapter } from "#preview2/filesystem";
|
|
25
|
+
import { error, poll, streams } from "#preview2/io";
|
|
26
|
+
import { random } from "#preview2/random";
|
|
27
|
+
import * as sockets from "./shims/sockets.js";
|
|
28
|
+
|
|
29
|
+
// Import stdlib loader
|
|
30
|
+
import { loadStdlib } from "./stdlib-loader.js";
|
|
31
|
+
|
|
32
|
+
// Load the Python stdlib once; every Sandbox gets its own copy-on-access view of it.
|
|
33
|
+
const stdlibTree = await loadStdlib();
|
|
34
|
+
|
|
35
|
+
// The stdlib tar extracts to python-stdlib/*, but the WASM expects
|
|
36
|
+
// files at the root of the preopen (mounted as /python-stdlib).
|
|
37
|
+
const stdlibDir = stdlibTree.dir?.["python-stdlib"] || stdlibTree;
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* The template file tree each new Sandbox copies: the stdlib and an empty
|
|
41
|
+
* site-packages directory. Files added here are visible to sandboxes created
|
|
42
|
+
* afterwards; use a Sandbox's own `_fileTree` to change one that exists.
|
|
43
|
+
*/
|
|
44
|
+
export const _fileTree = {
|
|
45
|
+
dir: { "python-stdlib": stdlibDir, "site-packages": { dir: {} } },
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* Copy a file tree for one instance. Directories are copied up front; a file's
|
|
50
|
+
* bytes are copied the first time the instance touches them, so writes (which
|
|
51
|
+
* the in-memory filesystem makes in place) never reach the template or another
|
|
52
|
+
* instance, and untouched stdlib files cost nothing.
|
|
53
|
+
* @param {Object} node
|
|
54
|
+
* @returns {Object}
|
|
55
|
+
*/
|
|
56
|
+
export function forkTree(node) {
|
|
57
|
+
if (node.dir) {
|
|
58
|
+
const dir = {};
|
|
59
|
+
for (const [name, child] of Object.entries(node.dir)) dir[name] = forkTree(child);
|
|
60
|
+
return { ...node, dir };
|
|
61
|
+
}
|
|
62
|
+
if (!("source" in node)) return { ...node };
|
|
63
|
+
const shared = node.source;
|
|
64
|
+
let own;
|
|
65
|
+
return {
|
|
66
|
+
get source() {
|
|
67
|
+
// Not `slice()`: on a Node Buffer that returns a view, not a copy.
|
|
68
|
+
return (own ??= typeof shared === "string" ? shared : new Uint8Array(shared));
|
|
69
|
+
},
|
|
70
|
+
set source(value) {
|
|
71
|
+
own = value;
|
|
72
|
+
},
|
|
73
|
+
};
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
export const isNode =
|
|
77
|
+
typeof globalThis.process !== "undefined" &&
|
|
78
|
+
typeof globalThis.process.versions?.node !== "undefined";
|
|
79
|
+
|
|
80
|
+
/** Compiled core modules, shared by every instance. */
|
|
81
|
+
const _coreModules = new Map();
|
|
82
|
+
|
|
83
|
+
/**
|
|
84
|
+
* Compile (once) a core wasm module of the component.
|
|
85
|
+
* @param {string} name
|
|
86
|
+
* @returns {Promise<WebAssembly.Module>}
|
|
87
|
+
*/
|
|
88
|
+
export function getCoreModule(name) {
|
|
89
|
+
if (!_coreModules.has(name)) {
|
|
90
|
+
const url = new URL(`./${name}`, import.meta.url);
|
|
91
|
+
_coreModules.set(
|
|
92
|
+
name,
|
|
93
|
+
isNode
|
|
94
|
+
? import(/* webpackIgnore: true */ "node:fs/promises").then(async (fs) =>
|
|
95
|
+
WebAssembly.compile(await fs.readFile(url)),
|
|
96
|
+
)
|
|
97
|
+
: WebAssembly.compileStreaming(fetch(url)),
|
|
98
|
+
);
|
|
99
|
+
}
|
|
100
|
+
return _coreModules.get(name);
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
const _sockets = {
|
|
104
|
+
"wasi:sockets/instance-network": sockets.instanceNetwork,
|
|
105
|
+
"wasi:sockets/ip-name-lookup": sockets.ipNameLookup,
|
|
106
|
+
"wasi:sockets/network": sockets.network,
|
|
107
|
+
"wasi:sockets/tcp": sockets.tcp,
|
|
108
|
+
"wasi:sockets/tcp-create-socket": sockets.tcpCreateSocket,
|
|
109
|
+
"wasi:sockets/udp": sockets.udp,
|
|
110
|
+
"wasi:sockets/udp-create-socket": sockets.udpCreateSocket,
|
|
111
|
+
};
|
|
112
|
+
|
|
113
|
+
/**
|
|
114
|
+
* Instantiate the component with its own filesystem and callback imports, then
|
|
115
|
+
* finish the pre-initialized interpreter's setup.
|
|
116
|
+
* @param {Object} fileTree - The instance's own file tree
|
|
117
|
+
* @param {ReturnType<typeof import("./shims/callbacks.js").createCallbackHost>["imports"]} cb - Callback imports
|
|
118
|
+
* @param {{tcp: Object, tls: Object}} net - The instance's eryx:net imports
|
|
119
|
+
* @param {(name: string) => WebAssembly.Module | Promise<WebAssembly.Module>} [getModule] -
|
|
120
|
+
* Core-module source, when not this thread's cache
|
|
121
|
+
*/
|
|
122
|
+
export async function instantiateSandbox(fileTree, cb, net, getModule = getCoreModule) {
|
|
123
|
+
const fs = createFilesystem({
|
|
124
|
+
adapter: new InMemoryFilesystemAdapter(),
|
|
125
|
+
preopens: { "/": fileTree },
|
|
126
|
+
});
|
|
127
|
+
const instance = await instantiate(getModule, {
|
|
128
|
+
invoke: { default: cb.invoke },
|
|
129
|
+
sleep: { default: cb.sleep },
|
|
130
|
+
"list-callbacks": { default: cb.listCallbacks },
|
|
131
|
+
"get-execution-options": { default: cb.getExecutionOptions },
|
|
132
|
+
"report-trace": { default: cb.reportTrace },
|
|
133
|
+
"report-output": { default: cb.reportOutput },
|
|
134
|
+
"eryx:net/tcp": net.tcp,
|
|
135
|
+
"eryx:net/tls": net.tls,
|
|
136
|
+
"wasi:cli/environment": environment,
|
|
137
|
+
"wasi:cli/exit": exit,
|
|
138
|
+
"wasi:cli/stderr": stderr,
|
|
139
|
+
"wasi:cli/stdin": stdin,
|
|
140
|
+
"wasi:cli/stdout": stdout,
|
|
141
|
+
"wasi:cli/terminal-input": terminalInput,
|
|
142
|
+
"wasi:cli/terminal-output": terminalOutput,
|
|
143
|
+
"wasi:cli/terminal-stderr": terminalStderr,
|
|
144
|
+
"wasi:cli/terminal-stdin": terminalStdin,
|
|
145
|
+
"wasi:cli/terminal-stdout": terminalStdout,
|
|
146
|
+
"wasi:clocks/monotonic-clock": monotonicClock,
|
|
147
|
+
"wasi:clocks/wall-clock": wallClock,
|
|
148
|
+
"wasi:filesystem/preopens": fs.preopens,
|
|
149
|
+
"wasi:filesystem/types": fs.types,
|
|
150
|
+
"wasi:io/error": error,
|
|
151
|
+
"wasi:io/poll": poll,
|
|
152
|
+
"wasi:io/streams": streams,
|
|
153
|
+
"wasi:random/random": random,
|
|
154
|
+
..._sockets,
|
|
155
|
+
});
|
|
156
|
+
// The pre-initialized WASM has Python's core state baked in, but
|
|
157
|
+
// finalizePreinit() must still be called to finish setup.
|
|
158
|
+
instance.finalizePreinit();
|
|
159
|
+
return instance;
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
|
|
163
|
+
/** Turn a thrown value into something structured clone keeps intact. */
|
|
164
|
+
export function encodeError(e) {
|
|
165
|
+
return e instanceof Error ? { error: { name: e.name, message: e.message } } : { thrown: e };
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
/** Rebuild a value thrown on the other side of the channel. */
|
|
169
|
+
export function decodeError(reply) {
|
|
170
|
+
if (!reply.error) return reply.thrown;
|
|
171
|
+
const error = new Error(reply.error.message);
|
|
172
|
+
error.name = reply.error.name;
|
|
173
|
+
return error;
|
|
174
|
+
}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
/** @module Interface eryx:net/tcp@0.1.0 **/
|
|
2
|
+
/**
|
|
3
|
+
* @throws {TcpError} To return the error of the result, throw it, or an `Error` that has it as its `payload`.
|
|
4
|
+
*/
|
|
5
|
+
export function connect(host: string, port: number, timeoutMs: number): TcpHandle;
|
|
6
|
+
/**
|
|
7
|
+
* @throws {TcpError} To return the error of the result, throw it, or an `Error` that has it as its `payload`.
|
|
8
|
+
*/
|
|
9
|
+
export function read(handle: TcpHandle, len: number, timeoutMs: number): Uint8Array;
|
|
10
|
+
/**
|
|
11
|
+
* @throws {TcpError} To return the error of the result, throw it, or an `Error` that has it as its `payload`.
|
|
12
|
+
*/
|
|
13
|
+
export function write(handle: TcpHandle, timeoutMs: number, data: Uint8Array): number;
|
|
14
|
+
export function close(handle: TcpHandle): void;
|
|
15
|
+
export type TcpHandle = number;
|
|
16
|
+
export type TcpError = TcpErrorConnectionRefused | TcpErrorConnectionReset | TcpErrorTimedOut | TcpErrorHostNotFound | TcpErrorIoError | TcpErrorNotPermitted | TcpErrorInvalidHandle;
|
|
17
|
+
export interface TcpErrorConnectionRefused {
|
|
18
|
+
tag: 'connection-refused',
|
|
19
|
+
}
|
|
20
|
+
export interface TcpErrorConnectionReset {
|
|
21
|
+
tag: 'connection-reset',
|
|
22
|
+
}
|
|
23
|
+
export interface TcpErrorTimedOut {
|
|
24
|
+
tag: 'timed-out',
|
|
25
|
+
}
|
|
26
|
+
export interface TcpErrorHostNotFound {
|
|
27
|
+
tag: 'host-not-found',
|
|
28
|
+
}
|
|
29
|
+
export interface TcpErrorIoError {
|
|
30
|
+
tag: 'io-error',
|
|
31
|
+
val: string,
|
|
32
|
+
}
|
|
33
|
+
export interface TcpErrorNotPermitted {
|
|
34
|
+
tag: 'not-permitted',
|
|
35
|
+
val: string,
|
|
36
|
+
}
|
|
37
|
+
export interface TcpErrorInvalidHandle {
|
|
38
|
+
tag: 'invalid-handle',
|
|
39
|
+
}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/** @module Interface eryx:net/tls@0.1.0 **/
|
|
2
|
+
/**
|
|
3
|
+
* @throws {TlsError} To return the error of the result, throw it, or an `Error` that has it as its `payload`.
|
|
4
|
+
*/
|
|
5
|
+
export function upgrade(tcp: TcpHandle, hostname: string, timeoutMs: number): TlsHandle;
|
|
6
|
+
/**
|
|
7
|
+
* @throws {TlsError} To return the error of the result, throw it, or an `Error` that has it as its `payload`.
|
|
8
|
+
*/
|
|
9
|
+
export function read(handle: TlsHandle, len: number, timeoutMs: number): Uint8Array;
|
|
10
|
+
/**
|
|
11
|
+
* @throws {TlsError} To return the error of the result, throw it, or an `Error` that has it as its `payload`.
|
|
12
|
+
*/
|
|
13
|
+
export function write(handle: TlsHandle, timeoutMs: number, data: Uint8Array): number;
|
|
14
|
+
export function close(handle: TlsHandle): void;
|
|
15
|
+
export type TcpHandle = import('./eryx-net-tcp.js').TcpHandle;
|
|
16
|
+
export type TlsHandle = number;
|
|
17
|
+
export type TcpError = import('./eryx-net-tcp.js').TcpError;
|
|
18
|
+
export type TlsError = TlsErrorTcp | TlsErrorHandshakeFailed | TlsErrorCertificateError | TlsErrorInvalidHandle;
|
|
19
|
+
export interface TlsErrorTcp {
|
|
20
|
+
tag: 'tcp',
|
|
21
|
+
val: TcpError,
|
|
22
|
+
}
|
|
23
|
+
export interface TlsErrorHandshakeFailed {
|
|
24
|
+
tag: 'handshake-failed',
|
|
25
|
+
val: string,
|
|
26
|
+
}
|
|
27
|
+
export interface TlsErrorCertificateError {
|
|
28
|
+
tag: 'certificate-error',
|
|
29
|
+
val: string,
|
|
30
|
+
}
|
|
31
|
+
export interface TlsErrorInvalidHandle {
|
|
32
|
+
tag: 'invalid-handle',
|
|
33
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/** @module Interface wasi:clocks/monotonic-clock@0.2.0 **/
|
|
2
|
+
export function now(): Instant;
|
|
3
|
+
export function resolution(): Duration;
|
|
4
|
+
export function subscribeInstant(when: Instant): Pollable;
|
|
5
|
+
export function subscribeDuration(when: Duration): Pollable;
|
|
6
|
+
export type Duration = bigint;
|
|
7
|
+
export type Instant = bigint;
|
|
8
|
+
export type Pollable = import('./wasi-io-poll.js').Pollable;
|
|
@@ -0,0 +1,288 @@
|
|
|
1
|
+
/** @module Interface wasi:filesystem/types@0.2.0 **/
|
|
2
|
+
export function filesystemErrorCode(err: Error): ErrorCode | undefined;
|
|
3
|
+
export type Filesize = bigint;
|
|
4
|
+
/**
|
|
5
|
+
* # Variants
|
|
6
|
+
*
|
|
7
|
+
* ## `"normal"`
|
|
8
|
+
*
|
|
9
|
+
* ## `"sequential"`
|
|
10
|
+
*
|
|
11
|
+
* ## `"random"`
|
|
12
|
+
*
|
|
13
|
+
* ## `"will-need"`
|
|
14
|
+
*
|
|
15
|
+
* ## `"dont-need"`
|
|
16
|
+
*
|
|
17
|
+
* ## `"no-reuse"`
|
|
18
|
+
*/
|
|
19
|
+
export type Advice = "normal" | "sequential" | "random" | "will-need" | "dont-need" | "no-reuse";
|
|
20
|
+
/**
|
|
21
|
+
* # Variants
|
|
22
|
+
*
|
|
23
|
+
* ## `"access"`
|
|
24
|
+
*
|
|
25
|
+
* ## `"would-block"`
|
|
26
|
+
*
|
|
27
|
+
* ## `"already"`
|
|
28
|
+
*
|
|
29
|
+
* ## `"bad-descriptor"`
|
|
30
|
+
*
|
|
31
|
+
* ## `"busy"`
|
|
32
|
+
*
|
|
33
|
+
* ## `"deadlock"`
|
|
34
|
+
*
|
|
35
|
+
* ## `"quota"`
|
|
36
|
+
*
|
|
37
|
+
* ## `"exist"`
|
|
38
|
+
*
|
|
39
|
+
* ## `"file-too-large"`
|
|
40
|
+
*
|
|
41
|
+
* ## `"illegal-byte-sequence"`
|
|
42
|
+
*
|
|
43
|
+
* ## `"in-progress"`
|
|
44
|
+
*
|
|
45
|
+
* ## `"interrupted"`
|
|
46
|
+
*
|
|
47
|
+
* ## `"invalid"`
|
|
48
|
+
*
|
|
49
|
+
* ## `"io"`
|
|
50
|
+
*
|
|
51
|
+
* ## `"is-directory"`
|
|
52
|
+
*
|
|
53
|
+
* ## `"loop"`
|
|
54
|
+
*
|
|
55
|
+
* ## `"too-many-links"`
|
|
56
|
+
*
|
|
57
|
+
* ## `"message-size"`
|
|
58
|
+
*
|
|
59
|
+
* ## `"name-too-long"`
|
|
60
|
+
*
|
|
61
|
+
* ## `"no-device"`
|
|
62
|
+
*
|
|
63
|
+
* ## `"no-entry"`
|
|
64
|
+
*
|
|
65
|
+
* ## `"no-lock"`
|
|
66
|
+
*
|
|
67
|
+
* ## `"insufficient-memory"`
|
|
68
|
+
*
|
|
69
|
+
* ## `"insufficient-space"`
|
|
70
|
+
*
|
|
71
|
+
* ## `"not-directory"`
|
|
72
|
+
*
|
|
73
|
+
* ## `"not-empty"`
|
|
74
|
+
*
|
|
75
|
+
* ## `"not-recoverable"`
|
|
76
|
+
*
|
|
77
|
+
* ## `"unsupported"`
|
|
78
|
+
*
|
|
79
|
+
* ## `"no-tty"`
|
|
80
|
+
*
|
|
81
|
+
* ## `"no-such-device"`
|
|
82
|
+
*
|
|
83
|
+
* ## `"overflow"`
|
|
84
|
+
*
|
|
85
|
+
* ## `"not-permitted"`
|
|
86
|
+
*
|
|
87
|
+
* ## `"pipe"`
|
|
88
|
+
*
|
|
89
|
+
* ## `"read-only"`
|
|
90
|
+
*
|
|
91
|
+
* ## `"invalid-seek"`
|
|
92
|
+
*
|
|
93
|
+
* ## `"text-file-busy"`
|
|
94
|
+
*
|
|
95
|
+
* ## `"cross-device"`
|
|
96
|
+
*/
|
|
97
|
+
export type ErrorCode = "access" | "would-block" | "already" | "bad-descriptor" | "busy" | "deadlock" | "quota" | "exist" | "file-too-large" | "illegal-byte-sequence" | "in-progress" | "interrupted" | "invalid" | "io" | "is-directory" | "loop" | "too-many-links" | "message-size" | "name-too-long" | "no-device" | "no-entry" | "no-lock" | "insufficient-memory" | "insufficient-space" | "not-directory" | "not-empty" | "not-recoverable" | "unsupported" | "no-tty" | "no-such-device" | "overflow" | "not-permitted" | "pipe" | "read-only" | "invalid-seek" | "text-file-busy" | "cross-device";
|
|
98
|
+
/**
|
|
99
|
+
* # Variants
|
|
100
|
+
*
|
|
101
|
+
* ## `"unknown"`
|
|
102
|
+
*
|
|
103
|
+
* ## `"block-device"`
|
|
104
|
+
*
|
|
105
|
+
* ## `"character-device"`
|
|
106
|
+
*
|
|
107
|
+
* ## `"directory"`
|
|
108
|
+
*
|
|
109
|
+
* ## `"fifo"`
|
|
110
|
+
*
|
|
111
|
+
* ## `"symbolic-link"`
|
|
112
|
+
*
|
|
113
|
+
* ## `"regular-file"`
|
|
114
|
+
*
|
|
115
|
+
* ## `"socket"`
|
|
116
|
+
*/
|
|
117
|
+
export type DescriptorType = "unknown" | "block-device" | "character-device" | "directory" | "fifo" | "symbolic-link" | "regular-file" | "socket";
|
|
118
|
+
export type Error = import('./wasi-io-streams.js').Error;
|
|
119
|
+
export type InputStream = import('./wasi-io-streams.js').InputStream;
|
|
120
|
+
export type OutputStream = import('./wasi-io-streams.js').OutputStream;
|
|
121
|
+
export interface DescriptorFlags {
|
|
122
|
+
read?: boolean,
|
|
123
|
+
write?: boolean,
|
|
124
|
+
fileIntegritySync?: boolean,
|
|
125
|
+
dataIntegritySync?: boolean,
|
|
126
|
+
requestedWriteSync?: boolean,
|
|
127
|
+
mutateDirectory?: boolean,
|
|
128
|
+
}
|
|
129
|
+
export type Datetime = import('./wasi-clocks-wall-clock.js').Datetime;
|
|
130
|
+
export type NewTimestamp = NewTimestampNoChange | NewTimestampNow | NewTimestampTimestamp;
|
|
131
|
+
export interface NewTimestampNoChange {
|
|
132
|
+
tag: 'no-change',
|
|
133
|
+
}
|
|
134
|
+
export interface NewTimestampNow {
|
|
135
|
+
tag: 'now',
|
|
136
|
+
}
|
|
137
|
+
export interface NewTimestampTimestamp {
|
|
138
|
+
tag: 'timestamp',
|
|
139
|
+
val: Datetime,
|
|
140
|
+
}
|
|
141
|
+
export type LinkCount = bigint;
|
|
142
|
+
export interface DescriptorStat {
|
|
143
|
+
type: DescriptorType,
|
|
144
|
+
linkCount: LinkCount,
|
|
145
|
+
size: Filesize,
|
|
146
|
+
dataAccessTimestamp?: Datetime,
|
|
147
|
+
dataModificationTimestamp?: Datetime,
|
|
148
|
+
statusChangeTimestamp?: Datetime,
|
|
149
|
+
}
|
|
150
|
+
export interface PathFlags {
|
|
151
|
+
symlinkFollow?: boolean,
|
|
152
|
+
}
|
|
153
|
+
export interface OpenFlags {
|
|
154
|
+
create?: boolean,
|
|
155
|
+
directory?: boolean,
|
|
156
|
+
exclusive?: boolean,
|
|
157
|
+
truncate?: boolean,
|
|
158
|
+
}
|
|
159
|
+
export interface MetadataHashValue {
|
|
160
|
+
lower: bigint,
|
|
161
|
+
upper: bigint,
|
|
162
|
+
}
|
|
163
|
+
export interface DirectoryEntry {
|
|
164
|
+
type: DescriptorType,
|
|
165
|
+
name: string,
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
export class Descriptor {
|
|
169
|
+
/**
|
|
170
|
+
* This type does not have a public constructor.
|
|
171
|
+
*/
|
|
172
|
+
private constructor();
|
|
173
|
+
/**
|
|
174
|
+
* @throws {ErrorCode} To return the error of the result, throw it, or an `Error` that has it as its `payload`.
|
|
175
|
+
*/
|
|
176
|
+
readViaStream(offset: Filesize): InputStream;
|
|
177
|
+
/**
|
|
178
|
+
* @throws {ErrorCode} To return the error of the result, throw it, or an `Error` that has it as its `payload`.
|
|
179
|
+
*/
|
|
180
|
+
writeViaStream(offset: Filesize): OutputStream;
|
|
181
|
+
/**
|
|
182
|
+
* @throws {ErrorCode} To return the error of the result, throw it, or an `Error` that has it as its `payload`.
|
|
183
|
+
*/
|
|
184
|
+
appendViaStream(): OutputStream;
|
|
185
|
+
/**
|
|
186
|
+
* @throws {ErrorCode} To return the error of the result, throw it, or an `Error` that has it as its `payload`.
|
|
187
|
+
*/
|
|
188
|
+
advise(offset: Filesize, length: Filesize, advice: Advice): void;
|
|
189
|
+
/**
|
|
190
|
+
* @throws {ErrorCode} To return the error of the result, throw it, or an `Error` that has it as its `payload`.
|
|
191
|
+
*/
|
|
192
|
+
syncData(): void;
|
|
193
|
+
/**
|
|
194
|
+
* @throws {ErrorCode} To return the error of the result, throw it, or an `Error` that has it as its `payload`.
|
|
195
|
+
*/
|
|
196
|
+
getFlags(): DescriptorFlags;
|
|
197
|
+
/**
|
|
198
|
+
* @throws {ErrorCode} To return the error of the result, throw it, or an `Error` that has it as its `payload`.
|
|
199
|
+
*/
|
|
200
|
+
getType(): DescriptorType;
|
|
201
|
+
/**
|
|
202
|
+
* @throws {ErrorCode} To return the error of the result, throw it, or an `Error` that has it as its `payload`.
|
|
203
|
+
*/
|
|
204
|
+
setSize(size: Filesize): void;
|
|
205
|
+
/**
|
|
206
|
+
* @throws {ErrorCode} To return the error of the result, throw it, or an `Error` that has it as its `payload`.
|
|
207
|
+
*/
|
|
208
|
+
setTimes(dataAccessTimestamp: NewTimestamp, dataModificationTimestamp: NewTimestamp): void;
|
|
209
|
+
/**
|
|
210
|
+
* @throws {ErrorCode} To return the error of the result, throw it, or an `Error` that has it as its `payload`.
|
|
211
|
+
*/
|
|
212
|
+
read(length: Filesize, offset: Filesize): [Uint8Array, boolean];
|
|
213
|
+
/**
|
|
214
|
+
* @throws {ErrorCode} To return the error of the result, throw it, or an `Error` that has it as its `payload`.
|
|
215
|
+
*/
|
|
216
|
+
write(buffer: Uint8Array, offset: Filesize): Filesize;
|
|
217
|
+
/**
|
|
218
|
+
* @throws {ErrorCode} To return the error of the result, throw it, or an `Error` that has it as its `payload`.
|
|
219
|
+
*/
|
|
220
|
+
readDirectory(): DirectoryEntryStream;
|
|
221
|
+
/**
|
|
222
|
+
* @throws {ErrorCode} To return the error of the result, throw it, or an `Error` that has it as its `payload`.
|
|
223
|
+
*/
|
|
224
|
+
sync(): void;
|
|
225
|
+
/**
|
|
226
|
+
* @throws {ErrorCode} To return the error of the result, throw it, or an `Error` that has it as its `payload`.
|
|
227
|
+
*/
|
|
228
|
+
createDirectoryAt(path: string): void;
|
|
229
|
+
/**
|
|
230
|
+
* @throws {ErrorCode} To return the error of the result, throw it, or an `Error` that has it as its `payload`.
|
|
231
|
+
*/
|
|
232
|
+
stat(): DescriptorStat;
|
|
233
|
+
/**
|
|
234
|
+
* @throws {ErrorCode} To return the error of the result, throw it, or an `Error` that has it as its `payload`.
|
|
235
|
+
*/
|
|
236
|
+
statAt(pathFlags: PathFlags, path: string): DescriptorStat;
|
|
237
|
+
/**
|
|
238
|
+
* @throws {ErrorCode} To return the error of the result, throw it, or an `Error` that has it as its `payload`.
|
|
239
|
+
*/
|
|
240
|
+
setTimesAt(pathFlags: PathFlags, path: string, dataAccessTimestamp: NewTimestamp, dataModificationTimestamp: NewTimestamp): void;
|
|
241
|
+
/**
|
|
242
|
+
* @throws {ErrorCode} To return the error of the result, throw it, or an `Error` that has it as its `payload`.
|
|
243
|
+
*/
|
|
244
|
+
linkAt(oldPathFlags: PathFlags, oldPath: string, newDescriptor: Descriptor, newPath: string): void;
|
|
245
|
+
/**
|
|
246
|
+
* @throws {ErrorCode} To return the error of the result, throw it, or an `Error` that has it as its `payload`.
|
|
247
|
+
*/
|
|
248
|
+
openAt(pathFlags: PathFlags, path: string, openFlags: OpenFlags, flags: DescriptorFlags): Descriptor;
|
|
249
|
+
/**
|
|
250
|
+
* @throws {ErrorCode} To return the error of the result, throw it, or an `Error` that has it as its `payload`.
|
|
251
|
+
*/
|
|
252
|
+
readlinkAt(path: string): string;
|
|
253
|
+
/**
|
|
254
|
+
* @throws {ErrorCode} To return the error of the result, throw it, or an `Error` that has it as its `payload`.
|
|
255
|
+
*/
|
|
256
|
+
removeDirectoryAt(path: string): void;
|
|
257
|
+
/**
|
|
258
|
+
* @throws {ErrorCode} To return the error of the result, throw it, or an `Error` that has it as its `payload`.
|
|
259
|
+
*/
|
|
260
|
+
renameAt(oldPath: string, newDescriptor: Descriptor, newPath: string): void;
|
|
261
|
+
/**
|
|
262
|
+
* @throws {ErrorCode} To return the error of the result, throw it, or an `Error` that has it as its `payload`.
|
|
263
|
+
*/
|
|
264
|
+
symlinkAt(oldPath: string, newPath: string): void;
|
|
265
|
+
/**
|
|
266
|
+
* @throws {ErrorCode} To return the error of the result, throw it, or an `Error` that has it as its `payload`.
|
|
267
|
+
*/
|
|
268
|
+
unlinkFileAt(path: string): void;
|
|
269
|
+
/**
|
|
270
|
+
* @throws {ErrorCode} To return the error of the result, throw it, or an `Error` that has it as its `payload`.
|
|
271
|
+
*/
|
|
272
|
+
metadataHash(): MetadataHashValue;
|
|
273
|
+
/**
|
|
274
|
+
* @throws {ErrorCode} To return the error of the result, throw it, or an `Error` that has it as its `payload`.
|
|
275
|
+
*/
|
|
276
|
+
metadataHashAt(pathFlags: PathFlags, path: string): MetadataHashValue;
|
|
277
|
+
}
|
|
278
|
+
|
|
279
|
+
export class DirectoryEntryStream {
|
|
280
|
+
/**
|
|
281
|
+
* This type does not have a public constructor.
|
|
282
|
+
*/
|
|
283
|
+
private constructor();
|
|
284
|
+
/**
|
|
285
|
+
* @throws {ErrorCode} To return the error of the result, throw it, or an `Error` that has it as its `payload`.
|
|
286
|
+
*/
|
|
287
|
+
readDirectoryEntry(): DirectoryEntry | undefined;
|
|
288
|
+
}
|