@bytecodealliance/preview2-shim 0.18.1 → 0.19.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/dist/browser/cli.d.ts +16 -0
- package/dist/browser/cli.js +109 -0
- package/dist/browser/clocks.d.ts +3 -0
- package/dist/browser/clocks.js +36 -0
- package/dist/browser/config.d.ts +2 -0
- package/{lib → dist}/browser/config.js +2 -4
- package/dist/browser/environment.d.ts +5 -0
- package/dist/browser/environment.js +24 -0
- package/dist/browser/filesystem.d.ts +132 -0
- package/dist/browser/filesystem.js +464 -0
- package/dist/browser/http.d.ts +4 -0
- package/dist/browser/http.js +643 -0
- package/dist/browser/index.d.ts +7 -0
- package/dist/browser/index.js +7 -0
- package/dist/browser/io.d.ts +58 -0
- package/dist/browser/io.js +205 -0
- package/dist/browser/random.d.ts +4 -0
- package/dist/browser/random.js +49 -0
- package/dist/browser/sockets.d.ts +8 -0
- package/dist/browser/sockets.js +66 -0
- package/dist/common/instantiation.d.ts +97 -0
- package/dist/common/instantiation.js +227 -0
- package/dist/io/calls.d.ts +91 -0
- package/{lib → dist}/io/calls.js +4 -19
- package/dist/io/worker-http.d.ts +17 -0
- package/dist/io/worker-http.js +192 -0
- package/dist/io/worker-io.d.ts +84 -0
- package/dist/io/worker-io.js +375 -0
- package/dist/io/worker-socket-tcp.d.ts +34 -0
- package/dist/io/worker-socket-tcp.js +251 -0
- package/dist/io/worker-socket-udp.d.ts +54 -0
- package/dist/io/worker-socket-udp.js +492 -0
- package/dist/io/worker-sockets.d.ts +32 -0
- package/dist/io/worker-sockets.js +265 -0
- package/dist/io/worker-thread.d.ts +73 -0
- package/dist/io/worker-thread.js +791 -0
- package/dist/nodejs/cli.d.ts +30 -0
- package/dist/nodejs/cli.js +86 -0
- package/dist/nodejs/clocks.d.ts +3 -0
- package/dist/nodejs/clocks.js +61 -0
- package/dist/nodejs/filesystem.d.ts +113 -0
- package/dist/nodejs/filesystem.js +758 -0
- package/dist/nodejs/http.d.ts +82 -0
- package/dist/nodejs/http.js +674 -0
- package/dist/nodejs/index.d.ts +7 -0
- package/dist/nodejs/index.js +7 -0
- package/dist/nodejs/io.d.ts +1 -0
- package/dist/nodejs/io.js +1 -0
- package/dist/nodejs/random.d.ts +4 -0
- package/dist/nodejs/random.js +42 -0
- package/dist/nodejs/sockets.d.ts +21 -0
- package/dist/nodejs/sockets.js +482 -0
- package/dist/synckit/index.d.ts +2 -0
- package/dist/synckit/index.js +117 -0
- package/package.json +26 -13
- package/types/instantiation.d.ts +7 -7
- package/lib/browser/cli.js +0 -135
- package/lib/browser/clocks.js +0 -39
- package/lib/browser/environment.js +0 -29
- package/lib/browser/filesystem.js +0 -503
- package/lib/browser/http.js +0 -707
- package/lib/browser/index.js +0 -9
- package/lib/browser/io.js +0 -262
- package/lib/browser/random.js +0 -56
- package/lib/browser/sockets.js +0 -88
- package/lib/common/instantiation.js +0 -253
- package/lib/io/worker-http.js +0 -206
- package/lib/io/worker-io.js +0 -468
- package/lib/io/worker-socket-tcp.js +0 -331
- package/lib/io/worker-socket-udp.js +0 -587
- package/lib/io/worker-sockets.js +0 -364
- package/lib/io/worker-thread.js +0 -1051
- package/lib/nodejs/cli.js +0 -109
- package/lib/nodejs/clocks.js +0 -67
- package/lib/nodejs/filesystem.js +0 -829
- package/lib/nodejs/http.js +0 -764
- package/lib/nodejs/index.js +0 -9
- package/lib/nodejs/io.js +0 -1
- package/lib/nodejs/random.js +0 -49
- package/lib/nodejs/sockets.js +0 -565
- package/lib/synckit/index.js +0 -127
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import type { exit as ExitNamespace, stderr as StderrNamespace, stdin as StdinNamespace, stdout as StdoutNamespace, terminalInput as TerminalInputNamespace, terminalOutput as TerminalOutputNamespace, terminalStderr as TerminalStderrNamespace, terminalStdin as TerminalStdinNamespace, terminalStdout as TerminalStdoutNamespace } from "../../types/cli.js";
|
|
2
|
+
export declare const _appendEnv: (env: Record<string, string>) => void;
|
|
3
|
+
export declare const _setEnv: (env: Record<string, string>) => undefined;
|
|
4
|
+
export declare const _setArgs: (args: string[]) => undefined;
|
|
5
|
+
export declare const _setCwd: (cwd: string) => undefined;
|
|
6
|
+
export declare const _setStdin: (stdin: any) => undefined;
|
|
7
|
+
export declare const _setStdout: (stdout: any) => undefined;
|
|
8
|
+
export declare const _setStderr: (stderr: any) => undefined;
|
|
9
|
+
export declare const _setTerminalStdin: (terminalStdin: TerminalInput) => undefined;
|
|
10
|
+
export declare const _setTerminalStdout: (terminalStdout: TerminalOutput) => undefined;
|
|
11
|
+
export declare const _setTerminalStderr: (terminalStderr: TerminalOutput) => undefined;
|
|
12
|
+
export declare const environment: {
|
|
13
|
+
getEnvironment(): [string, string | undefined][];
|
|
14
|
+
getArguments(): string[];
|
|
15
|
+
initialCwd(): string;
|
|
16
|
+
};
|
|
17
|
+
export declare const exit: typeof ExitNamespace;
|
|
18
|
+
export declare const stdin: typeof StdinNamespace;
|
|
19
|
+
export declare const stdout: typeof StdoutNamespace;
|
|
20
|
+
export declare const stderr: typeof StderrNamespace;
|
|
21
|
+
declare class TerminalInput {
|
|
22
|
+
}
|
|
23
|
+
declare class TerminalOutput {
|
|
24
|
+
}
|
|
25
|
+
export declare const terminalInput: typeof TerminalInputNamespace;
|
|
26
|
+
export declare const terminalOutput: typeof TerminalOutputNamespace;
|
|
27
|
+
export declare const terminalStdin: typeof TerminalStdinNamespace;
|
|
28
|
+
export declare const terminalStdout: typeof TerminalStdoutNamespace;
|
|
29
|
+
export declare const terminalStderr: typeof TerminalStderrNamespace;
|
|
30
|
+
export {};
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
import process, { argv, env, cwd } from "node:process";
|
|
2
|
+
import { ioCall, inputStreamCreate, outputStreamCreate } from "../io/worker-io.js";
|
|
3
|
+
import { INPUT_STREAM_CREATE, STDERR, STDIN, STDOUT } from "../io/calls.js";
|
|
4
|
+
export const _appendEnv = (env) => {
|
|
5
|
+
void (_env = [..._env.filter(([curKey]) => !(curKey in env)), ...Object.entries(env)]);
|
|
6
|
+
};
|
|
7
|
+
export const _setEnv = (env) => void (_env = Object.entries(env));
|
|
8
|
+
export const _setArgs = (args) => void (_args = args);
|
|
9
|
+
export const _setCwd = (cwd) => void (_cwd = cwd);
|
|
10
|
+
export const _setStdin = (stdin) => void (stdinStream = stdin);
|
|
11
|
+
export const _setStdout = (stdout) => void (stdoutStream = stdout);
|
|
12
|
+
export const _setStderr = (stderr) => void (stderrStream = stderr);
|
|
13
|
+
export const _setTerminalStdin = (terminalStdin) => void (terminalStdinInstance = terminalStdin);
|
|
14
|
+
export const _setTerminalStdout = (terminalStdout) => void (terminalStdoutInstance = terminalStdout);
|
|
15
|
+
export const _setTerminalStderr = (terminalStderr) => void (terminalStderrInstance = terminalStderr);
|
|
16
|
+
let _env = Object.entries(env), _args = argv.slice(1), _cwd = cwd();
|
|
17
|
+
export const environment = {
|
|
18
|
+
getEnvironment() {
|
|
19
|
+
return _env;
|
|
20
|
+
},
|
|
21
|
+
getArguments() {
|
|
22
|
+
return _args;
|
|
23
|
+
},
|
|
24
|
+
initialCwd() {
|
|
25
|
+
return _cwd;
|
|
26
|
+
},
|
|
27
|
+
};
|
|
28
|
+
export const exit = {
|
|
29
|
+
exit(status) {
|
|
30
|
+
process.exit(status.tag === "err" ? 1 : 0);
|
|
31
|
+
},
|
|
32
|
+
// @ts-expect-error - Available only wasi-cli v0.2.12
|
|
33
|
+
exitWithCode(code) {
|
|
34
|
+
process.exit(code);
|
|
35
|
+
},
|
|
36
|
+
};
|
|
37
|
+
// Stdin is created as a FILE descriptor
|
|
38
|
+
let stdinStream;
|
|
39
|
+
let stdoutStream = outputStreamCreate(STDOUT, 1);
|
|
40
|
+
let stderrStream = outputStreamCreate(STDERR, 2);
|
|
41
|
+
export const stdin = {
|
|
42
|
+
getStdin() {
|
|
43
|
+
if (!stdinStream) {
|
|
44
|
+
stdinStream = inputStreamCreate(STDIN, ioCall(INPUT_STREAM_CREATE | STDIN, null, null));
|
|
45
|
+
}
|
|
46
|
+
return stdinStream;
|
|
47
|
+
},
|
|
48
|
+
};
|
|
49
|
+
export const stdout = {
|
|
50
|
+
getStdout() {
|
|
51
|
+
return stdoutStream;
|
|
52
|
+
},
|
|
53
|
+
};
|
|
54
|
+
export const stderr = {
|
|
55
|
+
getStderr() {
|
|
56
|
+
return stderrStream;
|
|
57
|
+
},
|
|
58
|
+
};
|
|
59
|
+
class TerminalInput {
|
|
60
|
+
}
|
|
61
|
+
class TerminalOutput {
|
|
62
|
+
}
|
|
63
|
+
let terminalStdoutInstance = new TerminalOutput();
|
|
64
|
+
let terminalStderrInstance = new TerminalOutput();
|
|
65
|
+
let terminalStdinInstance = new TerminalInput();
|
|
66
|
+
export const terminalInput = {
|
|
67
|
+
TerminalInput,
|
|
68
|
+
};
|
|
69
|
+
export const terminalOutput = {
|
|
70
|
+
TerminalOutput,
|
|
71
|
+
};
|
|
72
|
+
export const terminalStdin = {
|
|
73
|
+
getTerminalStdin() {
|
|
74
|
+
return terminalStdinInstance;
|
|
75
|
+
},
|
|
76
|
+
};
|
|
77
|
+
export const terminalStdout = {
|
|
78
|
+
getTerminalStdout() {
|
|
79
|
+
return terminalStdoutInstance;
|
|
80
|
+
},
|
|
81
|
+
};
|
|
82
|
+
export const terminalStderr = {
|
|
83
|
+
getTerminalStderr() {
|
|
84
|
+
return terminalStderrInstance;
|
|
85
|
+
},
|
|
86
|
+
};
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import { createPoll } from "../io/worker-io.js";
|
|
2
|
+
import { CLOCKS_INSTANT_SUBSCRIBE, CLOCKS_DURATION_SUBSCRIBE } from "../io/calls.js";
|
|
3
|
+
import { hrtime } from "node:process";
|
|
4
|
+
const symbolCabiLower = Symbol.for("cabiLower");
|
|
5
|
+
function resolution() {
|
|
6
|
+
return 1n;
|
|
7
|
+
}
|
|
8
|
+
export const monotonicClock = {
|
|
9
|
+
resolution,
|
|
10
|
+
now() {
|
|
11
|
+
return hrtime.bigint();
|
|
12
|
+
},
|
|
13
|
+
subscribeInstant(instant) {
|
|
14
|
+
return createPoll(CLOCKS_INSTANT_SUBSCRIBE, null, instant);
|
|
15
|
+
},
|
|
16
|
+
subscribeDuration(duration) {
|
|
17
|
+
duration = BigInt(duration);
|
|
18
|
+
return createPoll(CLOCKS_DURATION_SUBSCRIBE, null, duration);
|
|
19
|
+
},
|
|
20
|
+
};
|
|
21
|
+
export const wallClock = {
|
|
22
|
+
resolution() {
|
|
23
|
+
return { seconds: 0n, nanoseconds: 1e6 };
|
|
24
|
+
},
|
|
25
|
+
now() {
|
|
26
|
+
const seconds = BigInt(Math.floor(Date.now() / 1e3));
|
|
27
|
+
const nanoseconds = (Date.now() % 1e3) * 1e6;
|
|
28
|
+
return { seconds, nanoseconds };
|
|
29
|
+
},
|
|
30
|
+
};
|
|
31
|
+
monotonicClock.resolution[symbolCabiLower] = () => resolution;
|
|
32
|
+
monotonicClock.now[symbolCabiLower] = () => hrtime.bigint;
|
|
33
|
+
wallClock.resolution[symbolCabiLower] = ({ memory }) => {
|
|
34
|
+
let buf32 = new Int32Array(memory.buffer);
|
|
35
|
+
return function now(retptr) {
|
|
36
|
+
if (memory.buffer !== buf32.buffer) {
|
|
37
|
+
buf32 = new Int32Array(memory.buffer);
|
|
38
|
+
}
|
|
39
|
+
if (retptr % 4) {
|
|
40
|
+
throw new Error("wasi-io trap: retptr not aligned");
|
|
41
|
+
}
|
|
42
|
+
buf32[(retptr >> 2) + 0] = 0;
|
|
43
|
+
buf32[(retptr >> 2) + 4] = 0;
|
|
44
|
+
buf32[(retptr >> 2) + 8] = 1_000_000;
|
|
45
|
+
};
|
|
46
|
+
};
|
|
47
|
+
wallClock.now[symbolCabiLower] = ({ memory }) => {
|
|
48
|
+
let buf32 = new Int32Array(memory.buffer);
|
|
49
|
+
let buf64 = new BigInt64Array(memory.buffer);
|
|
50
|
+
return function now(retptr) {
|
|
51
|
+
if (memory.buffer !== buf32.buffer) {
|
|
52
|
+
buf32 = new Int32Array(memory.buffer);
|
|
53
|
+
buf64 = new BigInt64Array(memory.buffer);
|
|
54
|
+
}
|
|
55
|
+
if (retptr % 4) {
|
|
56
|
+
throw new Error("wasi-io trap: retptr not aligned");
|
|
57
|
+
}
|
|
58
|
+
buf64[(retptr >> 2) + 0] = BigInt(Math.floor(Date.now() / 1e3));
|
|
59
|
+
buf32[(retptr >> 2) + 8] = (Date.now() % 1e3) * 1e6;
|
|
60
|
+
};
|
|
61
|
+
};
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
import { types as TypesNamespace, preopens as PreopensNamespace } from "../../types/filesystem.js";
|
|
2
|
+
import type { Descriptor as IDescriptor, DirectoryEntryStream as IDirectoryEntryStream } from "../../types/interfaces/wasi-filesystem-types.js";
|
|
3
|
+
declare const symbolDispose: symbol;
|
|
4
|
+
/**
|
|
5
|
+
* @implements {DescriptorProps}
|
|
6
|
+
*/
|
|
7
|
+
declare class Descriptor implements IDescriptor {
|
|
8
|
+
#private;
|
|
9
|
+
[symbolDispose]: () => void;
|
|
10
|
+
private _id;
|
|
11
|
+
static _createPreopen(hostPreopen: any): Descriptor;
|
|
12
|
+
static _create(fd: any, mode: any, fullPath: any): Descriptor;
|
|
13
|
+
readViaStream(offset: any): any;
|
|
14
|
+
writeViaStream(offset: any): any;
|
|
15
|
+
appendViaStream(): any;
|
|
16
|
+
advise(_offset: any, _length: any, _advice: any): void;
|
|
17
|
+
syncData(): void;
|
|
18
|
+
getFlags(): any;
|
|
19
|
+
getType(): TypesNamespace.DescriptorType;
|
|
20
|
+
setSize(size: any): void;
|
|
21
|
+
setTimes(dataAccessTimestamp: any, dataModificationTimestamp: any): void;
|
|
22
|
+
read(length: any, offset: any): [Uint8Array, boolean];
|
|
23
|
+
write(buffer: any, offset: any): bigint;
|
|
24
|
+
readDirectory(): IDirectoryEntryStream;
|
|
25
|
+
sync(): void;
|
|
26
|
+
createDirectoryAt(path: any): void;
|
|
27
|
+
stat(): {
|
|
28
|
+
type: TypesNamespace.DescriptorType;
|
|
29
|
+
linkCount: any;
|
|
30
|
+
size: any;
|
|
31
|
+
dataAccessTimestamp: {
|
|
32
|
+
seconds: bigint;
|
|
33
|
+
nanoseconds: number;
|
|
34
|
+
};
|
|
35
|
+
dataModificationTimestamp: {
|
|
36
|
+
seconds: bigint;
|
|
37
|
+
nanoseconds: number;
|
|
38
|
+
};
|
|
39
|
+
statusChangeTimestamp: {
|
|
40
|
+
seconds: bigint;
|
|
41
|
+
nanoseconds: number;
|
|
42
|
+
};
|
|
43
|
+
};
|
|
44
|
+
statAt(pathFlags: any, path: any): {
|
|
45
|
+
type: TypesNamespace.DescriptorType;
|
|
46
|
+
linkCount: any;
|
|
47
|
+
size: any;
|
|
48
|
+
dataAccessTimestamp: {
|
|
49
|
+
seconds: bigint;
|
|
50
|
+
nanoseconds: number;
|
|
51
|
+
};
|
|
52
|
+
dataModificationTimestamp: {
|
|
53
|
+
seconds: bigint;
|
|
54
|
+
nanoseconds: number;
|
|
55
|
+
};
|
|
56
|
+
statusChangeTimestamp: {
|
|
57
|
+
seconds: bigint;
|
|
58
|
+
nanoseconds: number;
|
|
59
|
+
};
|
|
60
|
+
};
|
|
61
|
+
setTimesAt(pathFlags: any, path: any, dataAccessTimestamp: any, dataModificationTimestamp: any): void;
|
|
62
|
+
linkAt(oldPathFlags: any, oldPath: any, newDescriptor: any, newPath: any): void;
|
|
63
|
+
openAt(pathFlags: any, path: any, openFlags: any, descriptorFlags: any): Descriptor;
|
|
64
|
+
readlinkAt(path: any): string;
|
|
65
|
+
removeDirectoryAt(path: any): void;
|
|
66
|
+
renameAt(oldPath: any, newDescriptor: any, newPath: any): void;
|
|
67
|
+
symlinkAt(target: any, path: any): void;
|
|
68
|
+
unlinkFileAt(path: any): void;
|
|
69
|
+
isSameObject(other: any): boolean;
|
|
70
|
+
metadataHash(): {
|
|
71
|
+
upper: bigint;
|
|
72
|
+
lower: bigint;
|
|
73
|
+
};
|
|
74
|
+
metadataHashAt(pathFlags: any, path: any): {
|
|
75
|
+
upper: bigint;
|
|
76
|
+
lower: bigint;
|
|
77
|
+
};
|
|
78
|
+
}
|
|
79
|
+
export declare const preopens: typeof PreopensNamespace;
|
|
80
|
+
export declare const types: typeof TypesNamespace;
|
|
81
|
+
/**
|
|
82
|
+
* Replace all preopens with the given set.
|
|
83
|
+
* @param {Record<string, string>} preopens - Map of virtual paths to host paths
|
|
84
|
+
*/
|
|
85
|
+
export declare function _setPreopens(preopens: any): void;
|
|
86
|
+
/**
|
|
87
|
+
* Add a single preopen mapping.
|
|
88
|
+
* @param {string} virtualPath - The virtual path visible to the guest
|
|
89
|
+
* @param {string} hostPreopen - The host filesystem path
|
|
90
|
+
*/
|
|
91
|
+
export declare function _addPreopen(virtualPath: any, hostPreopen: any): void;
|
|
92
|
+
/**
|
|
93
|
+
* Clear all preopens, giving the guest no filesystem access.
|
|
94
|
+
* Call this immediately after import to disable default full filesystem access.
|
|
95
|
+
*
|
|
96
|
+
* @example
|
|
97
|
+
* import { _clearPreopens } from '@bytecodealliance/preview2-shim/filesystem';
|
|
98
|
+
* _clearPreopens(); // Now guest has no filesystem access by default
|
|
99
|
+
*/
|
|
100
|
+
export declare function _clearPreopens(): void;
|
|
101
|
+
/**
|
|
102
|
+
* Get current preopens configuration.
|
|
103
|
+
* @returns {Array<[Descriptor, string]>} Array of [descriptor, virtualPath] pairs
|
|
104
|
+
*/
|
|
105
|
+
export declare function _getPreopens(): [Descriptor, string][];
|
|
106
|
+
/**
|
|
107
|
+
* Create a preopen descriptor for a host path.
|
|
108
|
+
* This is used internally to create isolated preopen instances.
|
|
109
|
+
* @param hostPreopen - The host filesystem path
|
|
110
|
+
* @returns A preopen descriptor
|
|
111
|
+
*/
|
|
112
|
+
export declare function _createPreopenDescriptor(hostPreopen: string): Descriptor;
|
|
113
|
+
export {};
|