@eryx-org/eryx 0.0.0 → 0.15.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.
Files changed (63) hide show
  1. package/README.md +281 -4
  2. package/eryx-sandbox.conditional-host-import-0.wasm +0 -0
  3. package/eryx-sandbox.conditional-host-import-1.wasm +0 -0
  4. package/eryx-sandbox.conditional-suspending-1-i32-to-i32.wasm +0 -0
  5. package/eryx-sandbox.core.wasm +0 -0
  6. package/eryx-sandbox.core10.wasm +0 -0
  7. package/eryx-sandbox.core11.wasm +0 -0
  8. package/eryx-sandbox.core12.wasm +0 -0
  9. package/eryx-sandbox.core13.wasm +0 -0
  10. package/eryx-sandbox.core2.wasm +0 -0
  11. package/eryx-sandbox.core3.wasm +0 -0
  12. package/eryx-sandbox.core4.wasm +0 -0
  13. package/eryx-sandbox.core5.wasm +0 -0
  14. package/eryx-sandbox.core6.wasm +0 -0
  15. package/eryx-sandbox.core7.wasm +0 -0
  16. package/eryx-sandbox.core8.wasm +0 -0
  17. package/eryx-sandbox.core9.wasm +0 -0
  18. package/eryx-sandbox.d.ts +163 -0
  19. package/eryx-sandbox.js +43541 -0
  20. package/index.d.ts +331 -0
  21. package/index.js +698 -0
  22. package/instance.js +174 -0
  23. package/interfaces/eryx-net-tcp.d.ts +30 -0
  24. package/interfaces/eryx-net-tls.d.ts +24 -0
  25. package/interfaces/wasi-cli-environment.d.ts +3 -0
  26. package/interfaces/wasi-cli-exit.d.ts +3 -0
  27. package/interfaces/wasi-cli-stderr.d.ts +3 -0
  28. package/interfaces/wasi-cli-stdin.d.ts +3 -0
  29. package/interfaces/wasi-cli-stdout.d.ts +3 -0
  30. package/interfaces/wasi-cli-terminal-input.d.ts +8 -0
  31. package/interfaces/wasi-cli-terminal-output.d.ts +8 -0
  32. package/interfaces/wasi-cli-terminal-stderr.d.ts +3 -0
  33. package/interfaces/wasi-cli-terminal-stdin.d.ts +3 -0
  34. package/interfaces/wasi-cli-terminal-stdout.d.ts +3 -0
  35. package/interfaces/wasi-clocks-monotonic-clock.d.ts +8 -0
  36. package/interfaces/wasi-clocks-wall-clock.d.ts +7 -0
  37. package/interfaces/wasi-filesystem-preopens.d.ts +3 -0
  38. package/interfaces/wasi-filesystem-types.d.ts +207 -0
  39. package/interfaces/wasi-io-error.d.ts +8 -0
  40. package/interfaces/wasi-io-poll.d.ts +10 -0
  41. package/interfaces/wasi-io-streams.d.ts +33 -0
  42. package/interfaces/wasi-random-random.d.ts +2 -0
  43. package/interfaces/wasi-sockets-instance-network.d.ts +3 -0
  44. package/interfaces/wasi-sockets-ip-name-lookup.d.ts +15 -0
  45. package/interfaces/wasi-sockets-network.d.ts +92 -0
  46. package/interfaces/wasi-sockets-tcp-create-socket.d.ts +5 -0
  47. package/interfaces/wasi-sockets-tcp.d.ts +52 -0
  48. package/interfaces/wasi-sockets-udp-create-socket.d.ts +5 -0
  49. package/interfaces/wasi-sockets-udp.d.ts +51 -0
  50. package/package.json +69 -3
  51. package/python-stdlib.tar.gz +0 -0
  52. package/shims/callbacks.d.ts +45 -0
  53. package/shims/callbacks.js +469 -0
  54. package/shims/ip.js +46 -0
  55. package/shims/net-fetch.js +264 -0
  56. package/shims/net-node.js +236 -0
  57. package/shims/net.d.ts +84 -0
  58. package/shims/net.js +255 -0
  59. package/shims/preview2-node.js +35 -0
  60. package/shims/raw-json.js +111 -0
  61. package/shims/sockets.js +53 -0
  62. package/stdlib-loader.js +174 -0
  63. 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,30 @@
1
+ /** @module Interface eryx:net/tcp@0.1.0 **/
2
+ export function connect(host: string, port: number, timeoutMs: number): TcpHandle;
3
+ export function read(handle: TcpHandle, len: number, timeoutMs: number): Uint8Array;
4
+ export function write(handle: TcpHandle, timeoutMs: number, data: Uint8Array): number;
5
+ export function close(handle: TcpHandle): void;
6
+ export type TcpHandle = number;
7
+ export type TcpError = TcpErrorConnectionRefused | TcpErrorConnectionReset | TcpErrorTimedOut | TcpErrorHostNotFound | TcpErrorIoError | TcpErrorNotPermitted | TcpErrorInvalidHandle;
8
+ export interface TcpErrorConnectionRefused {
9
+ tag: 'connection-refused',
10
+ }
11
+ export interface TcpErrorConnectionReset {
12
+ tag: 'connection-reset',
13
+ }
14
+ export interface TcpErrorTimedOut {
15
+ tag: 'timed-out',
16
+ }
17
+ export interface TcpErrorHostNotFound {
18
+ tag: 'host-not-found',
19
+ }
20
+ export interface TcpErrorIoError {
21
+ tag: 'io-error',
22
+ val: string,
23
+ }
24
+ export interface TcpErrorNotPermitted {
25
+ tag: 'not-permitted',
26
+ val: string,
27
+ }
28
+ export interface TcpErrorInvalidHandle {
29
+ tag: 'invalid-handle',
30
+ }
@@ -0,0 +1,24 @@
1
+ /** @module Interface eryx:net/tls@0.1.0 **/
2
+ export function upgrade(tcp: TcpHandle, hostname: string, timeoutMs: number): TlsHandle;
3
+ export function read(handle: TlsHandle, len: number, timeoutMs: number): Uint8Array;
4
+ export function write(handle: TlsHandle, timeoutMs: number, data: Uint8Array): number;
5
+ export function close(handle: TlsHandle): void;
6
+ export type TcpHandle = import('./eryx-net-tcp.js').TcpHandle;
7
+ export type TlsHandle = number;
8
+ export type TcpError = import('./eryx-net-tcp.js').TcpError;
9
+ export type TlsError = TlsErrorTcp | TlsErrorHandshakeFailed | TlsErrorCertificateError | TlsErrorInvalidHandle;
10
+ export interface TlsErrorTcp {
11
+ tag: 'tcp',
12
+ val: TcpError,
13
+ }
14
+ export interface TlsErrorHandshakeFailed {
15
+ tag: 'handshake-failed',
16
+ val: string,
17
+ }
18
+ export interface TlsErrorCertificateError {
19
+ tag: 'certificate-error',
20
+ val: string,
21
+ }
22
+ export interface TlsErrorInvalidHandle {
23
+ tag: 'invalid-handle',
24
+ }
@@ -0,0 +1,3 @@
1
+ /** @module Interface wasi:cli/environment@0.2.0 **/
2
+ export function getEnvironment(): Array<[string, string]>;
3
+ export function getArguments(): Array<string>;
@@ -0,0 +1,3 @@
1
+ /** @module Interface wasi:cli/exit@0.2.0 **/
2
+ export function exit(status: Result<void, void>): void;
3
+ export type Result<T, E> = { tag: 'ok', val: T } | { tag: 'err', val: E };
@@ -0,0 +1,3 @@
1
+ /** @module Interface wasi:cli/stderr@0.2.0 **/
2
+ export function getStderr(): OutputStream;
3
+ export type OutputStream = import('./wasi-io-streams.js').OutputStream;
@@ -0,0 +1,3 @@
1
+ /** @module Interface wasi:cli/stdin@0.2.0 **/
2
+ export function getStdin(): InputStream;
3
+ export type InputStream = import('./wasi-io-streams.js').InputStream;
@@ -0,0 +1,3 @@
1
+ /** @module Interface wasi:cli/stdout@0.2.0 **/
2
+ export function getStdout(): OutputStream;
3
+ export type OutputStream = import('./wasi-io-streams.js').OutputStream;
@@ -0,0 +1,8 @@
1
+ /** @module Interface wasi:cli/terminal-input@0.2.0 **/
2
+
3
+ export class TerminalInput {
4
+ /**
5
+ * This type does not have a public constructor.
6
+ */
7
+ private constructor();
8
+ }
@@ -0,0 +1,8 @@
1
+ /** @module Interface wasi:cli/terminal-output@0.2.0 **/
2
+
3
+ export class TerminalOutput {
4
+ /**
5
+ * This type does not have a public constructor.
6
+ */
7
+ private constructor();
8
+ }
@@ -0,0 +1,3 @@
1
+ /** @module Interface wasi:cli/terminal-stderr@0.2.0 **/
2
+ export function getTerminalStderr(): TerminalOutput | undefined;
3
+ export type TerminalOutput = import('./wasi-cli-terminal-output.js').TerminalOutput;
@@ -0,0 +1,3 @@
1
+ /** @module Interface wasi:cli/terminal-stdin@0.2.0 **/
2
+ export function getTerminalStdin(): TerminalInput | undefined;
3
+ export type TerminalInput = import('./wasi-cli-terminal-input.js').TerminalInput;
@@ -0,0 +1,3 @@
1
+ /** @module Interface wasi:cli/terminal-stdout@0.2.0 **/
2
+ export function getTerminalStdout(): TerminalOutput | undefined;
3
+ export type TerminalOutput = import('./wasi-cli-terminal-output.js').TerminalOutput;
@@ -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,7 @@
1
+ /** @module Interface wasi:clocks/wall-clock@0.2.0 **/
2
+ export function now(): Datetime;
3
+ export function resolution(): Datetime;
4
+ export interface Datetime {
5
+ seconds: bigint,
6
+ nanoseconds: number,
7
+ }
@@ -0,0 +1,3 @@
1
+ /** @module Interface wasi:filesystem/preopens@0.2.0 **/
2
+ export function getDirectories(): Array<[Descriptor, string]>;
3
+ export type Descriptor = import('./wasi-filesystem-types.js').Descriptor;
@@ -0,0 +1,207 @@
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
+ readViaStream(offset: Filesize): InputStream;
174
+ writeViaStream(offset: Filesize): OutputStream;
175
+ appendViaStream(): OutputStream;
176
+ advise(offset: Filesize, length: Filesize, advice: Advice): void;
177
+ syncData(): void;
178
+ getFlags(): DescriptorFlags;
179
+ getType(): DescriptorType;
180
+ setSize(size: Filesize): void;
181
+ setTimes(dataAccessTimestamp: NewTimestamp, dataModificationTimestamp: NewTimestamp): void;
182
+ read(length: Filesize, offset: Filesize): [Uint8Array, boolean];
183
+ write(buffer: Uint8Array, offset: Filesize): Filesize;
184
+ readDirectory(): DirectoryEntryStream;
185
+ sync(): void;
186
+ createDirectoryAt(path: string): void;
187
+ stat(): DescriptorStat;
188
+ statAt(pathFlags: PathFlags, path: string): DescriptorStat;
189
+ setTimesAt(pathFlags: PathFlags, path: string, dataAccessTimestamp: NewTimestamp, dataModificationTimestamp: NewTimestamp): void;
190
+ linkAt(oldPathFlags: PathFlags, oldPath: string, newDescriptor: Descriptor, newPath: string): void;
191
+ openAt(pathFlags: PathFlags, path: string, openFlags: OpenFlags, flags: DescriptorFlags): Descriptor;
192
+ readlinkAt(path: string): string;
193
+ removeDirectoryAt(path: string): void;
194
+ renameAt(oldPath: string, newDescriptor: Descriptor, newPath: string): void;
195
+ symlinkAt(oldPath: string, newPath: string): void;
196
+ unlinkFileAt(path: string): void;
197
+ metadataHash(): MetadataHashValue;
198
+ metadataHashAt(pathFlags: PathFlags, path: string): MetadataHashValue;
199
+ }
200
+
201
+ export class DirectoryEntryStream {
202
+ /**
203
+ * This type does not have a public constructor.
204
+ */
205
+ private constructor();
206
+ readDirectoryEntry(): DirectoryEntry | undefined;
207
+ }
@@ -0,0 +1,8 @@
1
+ /** @module Interface wasi:io/error@0.2.0 **/
2
+
3
+ export class Error {
4
+ /**
5
+ * This type does not have a public constructor.
6
+ */
7
+ private constructor();
8
+ }
@@ -0,0 +1,10 @@
1
+ /** @module Interface wasi:io/poll@0.2.0 **/
2
+ export function poll(in_: Array<Pollable>): Uint32Array;
3
+
4
+ export class Pollable {
5
+ /**
6
+ * This type does not have a public constructor.
7
+ */
8
+ private constructor();
9
+ block(): void;
10
+ }
@@ -0,0 +1,33 @@
1
+ /** @module Interface wasi:io/streams@0.2.0 **/
2
+ export type Error = import('./wasi-io-error.js').Error;
3
+ export type Pollable = import('./wasi-io-poll.js').Pollable;
4
+ export type StreamError = StreamErrorLastOperationFailed | StreamErrorClosed;
5
+ export interface StreamErrorLastOperationFailed {
6
+ tag: 'last-operation-failed',
7
+ val: Error,
8
+ }
9
+ export interface StreamErrorClosed {
10
+ tag: 'closed',
11
+ }
12
+
13
+ export class InputStream {
14
+ /**
15
+ * This type does not have a public constructor.
16
+ */
17
+ private constructor();
18
+ read(len: bigint): Uint8Array;
19
+ blockingRead(len: bigint): Uint8Array;
20
+ subscribe(): Pollable;
21
+ }
22
+
23
+ export class OutputStream {
24
+ /**
25
+ * This type does not have a public constructor.
26
+ */
27
+ private constructor();
28
+ checkWrite(): bigint;
29
+ write(contents: Uint8Array): void;
30
+ blockingWriteAndFlush(contents: Uint8Array): void;
31
+ blockingFlush(): void;
32
+ subscribe(): Pollable;
33
+ }
@@ -0,0 +1,2 @@
1
+ /** @module Interface wasi:random/random@0.2.0 **/
2
+ export function getRandomBytes(len: bigint): Uint8Array;
@@ -0,0 +1,3 @@
1
+ /** @module Interface wasi:sockets/instance-network@0.2.0 **/
2
+ export function instanceNetwork(): Network;
3
+ export type Network = import('./wasi-sockets-network.js').Network;
@@ -0,0 +1,15 @@
1
+ /** @module Interface wasi:sockets/ip-name-lookup@0.2.0 **/
2
+ export function resolveAddresses(network: Network, name: string): ResolveAddressStream;
3
+ export type IpAddress = import('./wasi-sockets-network.js').IpAddress;
4
+ export type ErrorCode = import('./wasi-sockets-network.js').ErrorCode;
5
+ export type Pollable = import('./wasi-io-poll.js').Pollable;
6
+ export type Network = import('./wasi-sockets-network.js').Network;
7
+
8
+ export class ResolveAddressStream {
9
+ /**
10
+ * This type does not have a public constructor.
11
+ */
12
+ private constructor();
13
+ resolveNextAddress(): IpAddress | undefined;
14
+ subscribe(): Pollable;
15
+ }