@bytecodealliance/preview2-shim 0.0.9 → 0.0.10
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/lib/browser/cli-base.js +6 -15
- package/lib/browser/clocks.js +3 -9
- package/lib/browser/http.js +3 -9
- package/lib/browser/io.js +1 -3
- package/lib/browser/logging.js +1 -3
- package/lib/browser/poll.js +1 -3
- package/lib/browser/random.js +26 -9
- package/lib/browser/sockets.js +11 -14
- package/lib/nodejs/cli-base.js +6 -15
- package/lib/nodejs/clocks.js +3 -9
- package/lib/nodejs/filesystem.js +8 -10
- package/lib/nodejs/http.js +3 -9
- package/lib/nodejs/io.js +21 -11
- package/lib/nodejs/logging.js +1 -3
- package/lib/nodejs/poll.js +1 -3
- package/lib/nodejs/random.js +21 -12
- package/lib/nodejs/sockets.js +11 -14
- package/package.json +1 -1
- package/types/exports/{http-incoming-handler.d.ts → wasi-http-incoming-handler.d.ts} +1 -1
- package/types/imports/{cli-base-environment.d.ts → environment.d.ts} +1 -1
- package/types/imports/{cli-base-exit.d.ts → exit.d.ts} +1 -1
- package/types/imports/{filesystem-filesystem.d.ts → filesystem.d.ts} +1 -1
- package/types/imports/{logging-handler.d.ts → handler.d.ts} +1 -1
- package/types/imports/{random-insecure-seed.d.ts → insecure-seed.d.ts} +1 -1
- package/types/imports/{random-insecure.d.ts → insecure.d.ts} +1 -1
- package/types/imports/{sockets-instance-network.d.ts → instance-network.d.ts} +1 -1
- package/types/imports/{sockets-ip-name-lookup.d.ts → ip-name-lookup.d.ts} +1 -1
- package/types/imports/{clocks-monotonic-clock.d.ts → monotonic-clock.d.ts} +1 -1
- package/types/imports/{sockets-network.d.ts → network.d.ts} +1 -1
- package/types/imports/{http-outgoing-handler.d.ts → outgoing-handler.d.ts} +1 -1
- package/types/imports/{poll-poll.d.ts → poll.d.ts} +1 -1
- package/types/imports/{cli-base-preopens.d.ts → preopens.d.ts} +1 -1
- package/types/imports/{random-random.d.ts → random.d.ts} +1 -1
- package/types/imports/{cli-base-stderr.d.ts → stderr.d.ts} +1 -1
- package/types/imports/{cli-base-stdin.d.ts → stdin.d.ts} +1 -1
- package/types/imports/{cli-base-stdout.d.ts → stdout.d.ts} +1 -1
- package/types/imports/{io-streams.d.ts → streams.d.ts} +1 -1
- package/types/imports/{sockets-tcp-create-socket.d.ts → tcp-create-socket.d.ts} +1 -1
- package/types/imports/{sockets-tcp.d.ts → tcp.d.ts} +1 -1
- package/types/imports/{clocks-timezone.d.ts → timezone.d.ts} +1 -1
- package/types/imports/{http-types.d.ts → types.d.ts} +1 -1
- package/types/imports/{sockets-udp-create-socket.d.ts → udp-create-socket.d.ts} +1 -1
- package/types/imports/{sockets-udp.d.ts → udp.d.ts} +1 -1
- package/types/imports/{clocks-wall-clock.d.ts → wall-clock.d.ts} +1 -1
- package/types/wasi-command.d.ts +22 -22
- package/types/wasi-proxy.d.ts +10 -11
- package/types/wasi-reactor.d.ts +23 -23
package/lib/browser/cli-base.js
CHANGED
|
@@ -3,7 +3,7 @@ export function _setEnv (envObj) {
|
|
|
3
3
|
_env = Object.entries(envObj);
|
|
4
4
|
}
|
|
5
5
|
|
|
6
|
-
export const
|
|
6
|
+
export const environment = {
|
|
7
7
|
getEnvironment () {
|
|
8
8
|
if (!_env) _env = [];
|
|
9
9
|
return _env;
|
|
@@ -17,41 +17,32 @@ class ComponentExit extends Error {
|
|
|
17
17
|
}
|
|
18
18
|
}
|
|
19
19
|
|
|
20
|
-
export const
|
|
20
|
+
export const exit = {
|
|
21
21
|
exit (status) {
|
|
22
22
|
throw new ComponentExit(status.tag === 'err' ? 1 : 0);
|
|
23
23
|
}
|
|
24
24
|
};
|
|
25
25
|
|
|
26
|
-
export const
|
|
26
|
+
export const preopens = {
|
|
27
27
|
getDirectories () {
|
|
28
28
|
return [];
|
|
29
29
|
}
|
|
30
30
|
}
|
|
31
31
|
|
|
32
|
-
export const
|
|
32
|
+
export const stdin = {
|
|
33
33
|
getStdin () {
|
|
34
34
|
return 0;
|
|
35
35
|
}
|
|
36
36
|
};
|
|
37
37
|
|
|
38
|
-
export const
|
|
38
|
+
export const stdout = {
|
|
39
39
|
getStdout () {
|
|
40
40
|
return 1;
|
|
41
41
|
}
|
|
42
42
|
};
|
|
43
43
|
|
|
44
|
-
export const
|
|
44
|
+
export const stderr = {
|
|
45
45
|
getStderr () {
|
|
46
46
|
return 2;
|
|
47
47
|
}
|
|
48
48
|
};
|
|
49
|
-
|
|
50
|
-
export {
|
|
51
|
-
cliBaseEnvironment as environment,
|
|
52
|
-
cliBaseExit as exit,
|
|
53
|
-
cliBasePreopens as preopens,
|
|
54
|
-
cliBaseStdin as stdin,
|
|
55
|
-
cliBaseStdout as stdout,
|
|
56
|
-
cliBaseStderr as stderr
|
|
57
|
-
}
|
package/lib/browser/clocks.js
CHANGED
|
@@ -4,7 +4,7 @@ function _hrtimeBigint () {
|
|
|
4
4
|
|
|
5
5
|
let _hrStart = _hrtimeBigint();
|
|
6
6
|
|
|
7
|
-
export const
|
|
7
|
+
export const monotonicClock = {
|
|
8
8
|
resolution() {
|
|
9
9
|
return 1n;
|
|
10
10
|
},
|
|
@@ -16,7 +16,7 @@ export const clocksMonotonicClock = {
|
|
|
16
16
|
}
|
|
17
17
|
};
|
|
18
18
|
|
|
19
|
-
export const
|
|
19
|
+
export const timezone = {
|
|
20
20
|
display (timezone, when) {
|
|
21
21
|
console.log(`[timezone] DISPLAY ${timezone} ${when}`);
|
|
22
22
|
},
|
|
@@ -31,7 +31,7 @@ export const clocksTimezone = {
|
|
|
31
31
|
}
|
|
32
32
|
};
|
|
33
33
|
|
|
34
|
-
export const
|
|
34
|
+
export const wallClock = {
|
|
35
35
|
now() {
|
|
36
36
|
const seconds = BigInt(Math.floor(Date.now() / 1e3));
|
|
37
37
|
const nanoseconds = (Date.now() % 1e3) * 1e6;
|
|
@@ -42,9 +42,3 @@ export const clocksWallClock = {
|
|
|
42
42
|
console.log(`[wall-clock] Wall clock resolution`);
|
|
43
43
|
}
|
|
44
44
|
};
|
|
45
|
-
|
|
46
|
-
export {
|
|
47
|
-
clocksMonotonicClock as monotonicClock,
|
|
48
|
-
clocksTimezone as timezone,
|
|
49
|
-
clocksWallClock as wallClock
|
|
50
|
-
}
|
package/lib/browser/http.js
CHANGED
|
@@ -34,19 +34,19 @@ export function send(req) {
|
|
|
34
34
|
}
|
|
35
35
|
}
|
|
36
36
|
|
|
37
|
-
export const
|
|
37
|
+
export const incomingHandler = {
|
|
38
38
|
handle () {
|
|
39
39
|
|
|
40
40
|
}
|
|
41
41
|
};
|
|
42
42
|
|
|
43
|
-
export const
|
|
43
|
+
export const outgoingHandler = {
|
|
44
44
|
handle () {
|
|
45
45
|
|
|
46
46
|
}
|
|
47
47
|
};
|
|
48
48
|
|
|
49
|
-
export const
|
|
49
|
+
export const types = {
|
|
50
50
|
dropFields(_fields) {
|
|
51
51
|
console.log("[types] Drop fields");
|
|
52
52
|
},
|
|
@@ -147,9 +147,3 @@ export const httpTypes = {
|
|
|
147
147
|
console.log("[types] Listen to future incoming response");
|
|
148
148
|
}
|
|
149
149
|
};
|
|
150
|
-
|
|
151
|
-
export {
|
|
152
|
-
httpIncomingHandler as incomingHandler,
|
|
153
|
-
httpOutgoingHandler as outgoingHandler,
|
|
154
|
-
httpTypes as types
|
|
155
|
-
}
|
package/lib/browser/io.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export const
|
|
1
|
+
export const streams = {
|
|
2
2
|
read(s, len) {
|
|
3
3
|
console.log(`[streams] Read ${s} ${len}`);
|
|
4
4
|
},
|
|
@@ -60,5 +60,3 @@ export const ioStreams = {
|
|
|
60
60
|
console.log(`[streams] Drop output stream ${s}`);
|
|
61
61
|
}
|
|
62
62
|
};
|
|
63
|
-
|
|
64
|
-
export { ioStreams as streams }
|
package/lib/browser/logging.js
CHANGED
|
@@ -2,7 +2,7 @@ const levels = ["trace", "debug", "info", "warn", "error"];
|
|
|
2
2
|
|
|
3
3
|
let logLevel = levels.indexOf("warn");
|
|
4
4
|
|
|
5
|
-
export const
|
|
5
|
+
export const handler = {
|
|
6
6
|
log(level, context, msg) {
|
|
7
7
|
if (logLevel > levels.indexOf(level)) return;
|
|
8
8
|
console[level](`(${context}) ${msg}\n`);
|
|
@@ -12,5 +12,3 @@ export const loggingHandler = {
|
|
|
12
12
|
export function setLevel(level) {
|
|
13
13
|
logLevel = levels.indexOf(level);
|
|
14
14
|
}
|
|
15
|
-
|
|
16
|
-
export { loggingHandler as handler }
|
package/lib/browser/poll.js
CHANGED
package/lib/browser/random.js
CHANGED
|
@@ -2,11 +2,28 @@ const MAX_BYTES = 65536;
|
|
|
2
2
|
|
|
3
3
|
let insecureRandomValue1, insecureRandomValue2;
|
|
4
4
|
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
5
|
+
export const insecure = {
|
|
6
|
+
getInsecureRandomBytes (len) {
|
|
7
|
+
return random.getRandomBytes(len);
|
|
8
|
+
},
|
|
9
|
+
getInsecureRandomU64 () {
|
|
10
|
+
return random.getRandomU64();
|
|
11
|
+
}
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
let insecureSeedValue1, insecureSeedValue2;
|
|
15
|
+
|
|
16
|
+
export const insecureSeed = {
|
|
17
|
+
insecureSeed () {
|
|
18
|
+
if (insecureSeedValue1 === undefined) {
|
|
19
|
+
insecureSeedValue1 = random.getRandomU64();
|
|
20
|
+
insecureSeedValue2 = random.getRandomU64();
|
|
21
|
+
}
|
|
22
|
+
return [insecureSeedValue1, insecureSeedValue2];
|
|
23
|
+
}
|
|
24
|
+
};
|
|
8
25
|
|
|
9
|
-
export const
|
|
26
|
+
export const random = {
|
|
10
27
|
getRandomBytes(len) {
|
|
11
28
|
const bytes = new Uint8Array(Number(len));
|
|
12
29
|
|
|
@@ -25,15 +42,15 @@ export const randomRandom = {
|
|
|
25
42
|
return bytes;
|
|
26
43
|
},
|
|
27
44
|
|
|
28
|
-
getRandomU64
|
|
45
|
+
getRandomU64 () {
|
|
46
|
+
return crypto.getRandomValues(new BigUint64Array(1))[0];
|
|
47
|
+
},
|
|
29
48
|
|
|
30
49
|
insecureRandom () {
|
|
31
50
|
if (insecureRandomValue1 === undefined) {
|
|
32
|
-
insecureRandomValue1 = getRandomU64();
|
|
33
|
-
insecureRandomValue2 = getRandomU64();
|
|
51
|
+
insecureRandomValue1 = random.getRandomU64();
|
|
52
|
+
insecureRandomValue2 = random.getRandomU64();
|
|
34
53
|
}
|
|
35
54
|
return [insecureRandomValue1, insecureRandomValue2];
|
|
36
55
|
}
|
|
37
56
|
};
|
|
38
|
-
|
|
39
|
-
export { randomRandom as random }
|
package/lib/browser/sockets.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
export const
|
|
1
|
+
export const instanceNetwork = {
|
|
2
2
|
instanceNetwork () {
|
|
3
3
|
console.log(`[sockets] instance network`);
|
|
4
4
|
}
|
|
5
5
|
};
|
|
6
6
|
|
|
7
|
-
export const
|
|
7
|
+
export const ipNameLookup = {
|
|
8
8
|
dropResolveAddressStream () {
|
|
9
9
|
|
|
10
10
|
},
|
|
@@ -25,19 +25,19 @@ export const socketsIpNameLookup = {
|
|
|
25
25
|
},
|
|
26
26
|
};
|
|
27
27
|
|
|
28
|
-
export const
|
|
28
|
+
export const network = {
|
|
29
29
|
dropNetwork () {
|
|
30
30
|
|
|
31
31
|
}
|
|
32
32
|
};
|
|
33
33
|
|
|
34
|
-
export const
|
|
34
|
+
export const tcpCreateSocket = {
|
|
35
35
|
createTcpSocket () {
|
|
36
36
|
|
|
37
37
|
}
|
|
38
38
|
};
|
|
39
39
|
|
|
40
|
-
export const
|
|
40
|
+
export const tcp = {
|
|
41
41
|
subscribe () {
|
|
42
42
|
|
|
43
43
|
},
|
|
@@ -115,7 +115,7 @@ export const socketsTcp = {
|
|
|
115
115
|
}
|
|
116
116
|
};
|
|
117
117
|
|
|
118
|
-
export const
|
|
118
|
+
export const udp = {
|
|
119
119
|
subscribe () {
|
|
120
120
|
|
|
121
121
|
},
|
|
@@ -193,11 +193,8 @@ export const socketsUdp = {
|
|
|
193
193
|
}
|
|
194
194
|
};
|
|
195
195
|
|
|
196
|
-
export {
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
socketsTcp as tcp,
|
|
202
|
-
socketsUdp as udp
|
|
203
|
-
}
|
|
196
|
+
export const udpCreateSocket = {
|
|
197
|
+
createUdpSocket () {
|
|
198
|
+
|
|
199
|
+
}
|
|
200
|
+
};
|
package/lib/nodejs/cli-base.js
CHANGED
|
@@ -61,48 +61,39 @@ export function _setEnv (envObj) {
|
|
|
61
61
|
_env = Object.entries(envObj);
|
|
62
62
|
}
|
|
63
63
|
|
|
64
|
-
export const
|
|
64
|
+
export const environment = {
|
|
65
65
|
getEnvironment () {
|
|
66
66
|
if (!_env) _setEnv(process.env);
|
|
67
67
|
return _env;
|
|
68
68
|
}
|
|
69
69
|
};
|
|
70
70
|
|
|
71
|
-
export const
|
|
71
|
+
export const exit = {
|
|
72
72
|
exit (status) {
|
|
73
73
|
process.exit(status.tag === 'err' ? 1 : 0);
|
|
74
74
|
}
|
|
75
75
|
};
|
|
76
76
|
|
|
77
|
-
export const
|
|
77
|
+
export const preopens = {
|
|
78
78
|
getDirectories () {
|
|
79
79
|
return directories;
|
|
80
80
|
}
|
|
81
81
|
}
|
|
82
82
|
|
|
83
|
-
export const
|
|
83
|
+
export const stdin = {
|
|
84
84
|
getStdin () {
|
|
85
85
|
return 0;
|
|
86
86
|
}
|
|
87
87
|
};
|
|
88
88
|
|
|
89
|
-
export const
|
|
89
|
+
export const stdout = {
|
|
90
90
|
getStdout () {
|
|
91
91
|
return 1;
|
|
92
92
|
}
|
|
93
93
|
};
|
|
94
94
|
|
|
95
|
-
export const
|
|
95
|
+
export const stderr = {
|
|
96
96
|
getStderr () {
|
|
97
97
|
return 2;
|
|
98
98
|
}
|
|
99
99
|
};
|
|
100
|
-
|
|
101
|
-
export {
|
|
102
|
-
cliBaseEnvironment as environment,
|
|
103
|
-
cliBaseExit as exit,
|
|
104
|
-
cliBasePreopens as preopens,
|
|
105
|
-
cliBaseStdin as stdin,
|
|
106
|
-
cliBaseStdout as stdout,
|
|
107
|
-
cliBaseStderr as stderr
|
|
108
|
-
}
|
package/lib/nodejs/clocks.js
CHANGED
|
@@ -2,7 +2,7 @@ import { hrtime } from "node:process";
|
|
|
2
2
|
|
|
3
3
|
let _hrStart = hrtime.bigint();
|
|
4
4
|
|
|
5
|
-
export const
|
|
5
|
+
export const monotonicClock = {
|
|
6
6
|
resolution () {
|
|
7
7
|
return 1n;
|
|
8
8
|
},
|
|
@@ -16,7 +16,7 @@ export const clocksMonotonicClock = {
|
|
|
16
16
|
}
|
|
17
17
|
};
|
|
18
18
|
|
|
19
|
-
export const
|
|
19
|
+
export const timezone = {
|
|
20
20
|
display (timezone, when) {
|
|
21
21
|
console.log(`[timezone] DISPLAY ${timezone} ${when}`);
|
|
22
22
|
},
|
|
@@ -31,7 +31,7 @@ export const clocksTimezone = {
|
|
|
31
31
|
}
|
|
32
32
|
};
|
|
33
33
|
|
|
34
|
-
export const
|
|
34
|
+
export const wallClock = {
|
|
35
35
|
now() {
|
|
36
36
|
const seconds = BigInt(Math.floor(Date.now() / 1e3));
|
|
37
37
|
const nanoseconds = (Date.now() % 1e3) * 1e6;
|
|
@@ -42,9 +42,3 @@ export const clocksWallClock = {
|
|
|
42
42
|
console.log(`[wall-clock] Wall clock resolution`);
|
|
43
43
|
}
|
|
44
44
|
};
|
|
45
|
-
|
|
46
|
-
export {
|
|
47
|
-
clocksMonotonicClock as monotonicClock,
|
|
48
|
-
clocksTimezone as timezone,
|
|
49
|
-
clocksWallClock as wallClock
|
|
50
|
-
}
|
package/lib/nodejs/filesystem.js
CHANGED
|
@@ -1,8 +1,6 @@
|
|
|
1
1
|
import { openSync, constants, statSync, lstatSync, fstatSync, closeSync, readdirSync } from 'node:fs';
|
|
2
2
|
import { _descriptors, _addOpenedDescriptor, _removeOpenedDescriptor, _getDescriptorType, _setSubdescriptorType, _setDescriptorType, _getFullPath } from './cli-base.js';
|
|
3
|
-
import {
|
|
4
|
-
|
|
5
|
-
let _dirStreams = [];
|
|
3
|
+
import { _createFsStream, _dropFsStream, _getFsStreamContext } from './io.js';
|
|
6
4
|
|
|
7
5
|
const nsMagnitude = 1_000_000_000_000n;
|
|
8
6
|
function nsToDateTime (ns) {
|
|
@@ -75,7 +73,10 @@ function _lookupType (obj) {
|
|
|
75
73
|
|
|
76
74
|
export const filesystem = {
|
|
77
75
|
readViaStream(fd, offset) {
|
|
78
|
-
|
|
76
|
+
if (Number(offset) !== 0)
|
|
77
|
+
throw new Error('Read streams with non-zero offset not currently supported');
|
|
78
|
+
const stream = _createFsStream(fd, 'file', { offset: 0 });
|
|
79
|
+
return stream;
|
|
79
80
|
},
|
|
80
81
|
|
|
81
82
|
writeViaStream(fd, offset) {
|
|
@@ -136,8 +137,7 @@ export const filesystem = {
|
|
|
136
137
|
catch (e) {
|
|
137
138
|
_convertFsError(e);
|
|
138
139
|
}
|
|
139
|
-
|
|
140
|
-
return _dirStreams.length - 1;
|
|
140
|
+
return _createFsStream(fd, 'dir', { dirs, cursor: 0, fd });
|
|
141
141
|
},
|
|
142
142
|
|
|
143
143
|
sync(fd) {
|
|
@@ -296,7 +296,7 @@ export const filesystem = {
|
|
|
296
296
|
},
|
|
297
297
|
|
|
298
298
|
readDirectoryEntry(stream) {
|
|
299
|
-
const streamValue =
|
|
299
|
+
const streamValue = _getFsStreamContext(stream, 'dir');
|
|
300
300
|
if (streamValue.cursor === streamValue.dirs.length)
|
|
301
301
|
return null;
|
|
302
302
|
const dir = streamValue.dirs[streamValue.cursor++];
|
|
@@ -306,8 +306,6 @@ export const filesystem = {
|
|
|
306
306
|
},
|
|
307
307
|
|
|
308
308
|
dropDirectoryEntryStream(stream) {
|
|
309
|
-
|
|
309
|
+
_dropFsStream(stream);
|
|
310
310
|
}
|
|
311
311
|
};
|
|
312
|
-
|
|
313
|
-
export { filesystem as filesystemFilesystem }
|
package/lib/nodejs/http.js
CHANGED
|
@@ -18,19 +18,19 @@ export function send(req) {
|
|
|
18
18
|
throw new UnexpectedError(response);
|
|
19
19
|
}
|
|
20
20
|
|
|
21
|
-
export const
|
|
21
|
+
export const incomingHandler = {
|
|
22
22
|
handle () {
|
|
23
23
|
|
|
24
24
|
}
|
|
25
25
|
};
|
|
26
26
|
|
|
27
|
-
export const
|
|
27
|
+
export const outgoingHandler = {
|
|
28
28
|
handle () {
|
|
29
29
|
|
|
30
30
|
}
|
|
31
31
|
};
|
|
32
32
|
|
|
33
|
-
export const
|
|
33
|
+
export const types = {
|
|
34
34
|
dropFields(_fields) {
|
|
35
35
|
console.log("[types] Drop fields");
|
|
36
36
|
},
|
|
@@ -131,9 +131,3 @@ export const httpTypes = {
|
|
|
131
131
|
console.log("[types] Listen to future incoming response");
|
|
132
132
|
}
|
|
133
133
|
};
|
|
134
|
-
|
|
135
|
-
export {
|
|
136
|
-
httpIncomingHandler as incomingHandler,
|
|
137
|
-
httpOutgoingHandler as outgoingHandler,
|
|
138
|
-
httpTypes as types
|
|
139
|
-
}
|
package/lib/nodejs/io.js
CHANGED
|
@@ -46,17 +46,30 @@ function _convertFsError (e) {
|
|
|
46
46
|
|
|
47
47
|
export let _streams = {};
|
|
48
48
|
let streamCnt = 0;
|
|
49
|
-
export function
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
};
|
|
49
|
+
export function _createFsStream(fd, type, context) {
|
|
50
|
+
_streams[streamCnt] = {
|
|
51
|
+
type,
|
|
52
|
+
fd,
|
|
53
|
+
context
|
|
54
|
+
};
|
|
56
55
|
return streamCnt++;
|
|
57
56
|
}
|
|
58
57
|
|
|
59
|
-
export
|
|
58
|
+
export function _getFsStreamContext(stream, type) {
|
|
59
|
+
const entry = _streams[stream];
|
|
60
|
+
if (!entry)
|
|
61
|
+
throw new Error(`No '${type}' stream found at stream ${stream}`);
|
|
62
|
+
if (entry.type !== type)
|
|
63
|
+
throw new Error(`Unexpected '${entry.type}' stream found at stream ${stream}, expected '${type}'`);
|
|
64
|
+
return entry.context;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
export function _dropFsStream(stream) {
|
|
68
|
+
// TODO: recycling?
|
|
69
|
+
delete _streams[stream];
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
export const streams = {
|
|
60
73
|
read(s, len) {
|
|
61
74
|
switch (s) {
|
|
62
75
|
case 0:
|
|
@@ -97,7 +110,6 @@ export const ioStreams = {
|
|
|
97
110
|
},
|
|
98
111
|
dropInputStream(s) {
|
|
99
112
|
delete _streams[s];
|
|
100
|
-
|
|
101
113
|
},
|
|
102
114
|
write(s, buf) {
|
|
103
115
|
switch (s) {
|
|
@@ -140,5 +152,3 @@ export const ioStreams = {
|
|
|
140
152
|
console.log(`[streams] Drop output stream ${s}`);
|
|
141
153
|
}
|
|
142
154
|
};
|
|
143
|
-
|
|
144
|
-
export { ioStreams as streams }
|
package/lib/nodejs/logging.js
CHANGED
|
@@ -2,7 +2,7 @@ const levels = ["trace", "debug", "info", "warn", "error"];
|
|
|
2
2
|
|
|
3
3
|
let logLevel = levels.indexOf("warn");
|
|
4
4
|
|
|
5
|
-
export const
|
|
5
|
+
export const handler = {
|
|
6
6
|
log(level, context, msg) {
|
|
7
7
|
if (logLevel > levels.indexOf(level)) return;
|
|
8
8
|
process.stdout.write(`${level}: (${context}) ${msg}\n`);
|
|
@@ -12,5 +12,3 @@ export const loggingHandler = {
|
|
|
12
12
|
export function setLevel(level) {
|
|
13
13
|
logLevel = levels.indexOf(level);
|
|
14
14
|
}
|
|
15
|
-
|
|
16
|
-
export { loggingHandler as handler }
|
package/lib/nodejs/poll.js
CHANGED
package/lib/nodejs/random.js
CHANGED
|
@@ -1,23 +1,32 @@
|
|
|
1
1
|
import { randomBytes } from "node:crypto";
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
export const insecure = {
|
|
4
|
+
getInsecureRandomBytes (len) {
|
|
5
|
+
return randomBytes(Number(len));
|
|
6
|
+
},
|
|
7
|
+
getInsecureRandomU64 () {
|
|
8
|
+
return new BigUint64Array(randomBytes(8).buffer)[0];
|
|
9
|
+
}
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
let insecureSeedValue1, insecureSeedValue2;
|
|
13
|
+
|
|
14
|
+
export const insecureSeed = {
|
|
15
|
+
insecureSeed () {
|
|
16
|
+
if (insecureSeedValue1 === undefined) {
|
|
17
|
+
insecureSeedValue1 = random.getRandomU64();
|
|
18
|
+
insecureSeedValue2 = random.getRandomU64();
|
|
19
|
+
}
|
|
20
|
+
return [insecureSeedValue1, insecureSeedValue2];
|
|
21
|
+
}
|
|
22
|
+
};
|
|
4
23
|
|
|
5
|
-
export const
|
|
24
|
+
export const random = {
|
|
6
25
|
getRandomBytes(len) {
|
|
7
26
|
return randomBytes(Number(len));
|
|
8
27
|
},
|
|
9
28
|
|
|
10
29
|
getRandomU64 () {
|
|
11
30
|
return new BigUint64Array(randomBytes(8).buffer)[0];
|
|
12
|
-
},
|
|
13
|
-
|
|
14
|
-
insecureRandom () {
|
|
15
|
-
if (insecureRandomValue1 === undefined) {
|
|
16
|
-
insecureRandomValue1 = randomRandom.getRandomU64();
|
|
17
|
-
insecureRandomValue2 = randomRandom.getRandomU64();
|
|
18
|
-
}
|
|
19
|
-
return [insecureRandomValue1, insecureRandomValue2];
|
|
20
31
|
}
|
|
21
32
|
};
|
|
22
|
-
|
|
23
|
-
export { randomRandom as random }
|
package/lib/nodejs/sockets.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
export const
|
|
1
|
+
export const instanceNetwork = {
|
|
2
2
|
instanceNetwork () {
|
|
3
3
|
console.log(`[sockets] instance network`);
|
|
4
4
|
}
|
|
5
5
|
};
|
|
6
6
|
|
|
7
|
-
export const
|
|
7
|
+
export const ipNameLookup = {
|
|
8
8
|
dropResolveAddressStream () {
|
|
9
9
|
|
|
10
10
|
},
|
|
@@ -25,19 +25,19 @@ export const socketsIpNameLookup = {
|
|
|
25
25
|
},
|
|
26
26
|
};
|
|
27
27
|
|
|
28
|
-
export const
|
|
28
|
+
export const network = {
|
|
29
29
|
dropNetwork () {
|
|
30
30
|
|
|
31
31
|
}
|
|
32
32
|
};
|
|
33
33
|
|
|
34
|
-
export const
|
|
34
|
+
export const tcpCreateSocket = {
|
|
35
35
|
createTcpSocket () {
|
|
36
36
|
|
|
37
37
|
}
|
|
38
38
|
};
|
|
39
39
|
|
|
40
|
-
export const
|
|
40
|
+
export const tcp = {
|
|
41
41
|
subscribe () {
|
|
42
42
|
|
|
43
43
|
},
|
|
@@ -115,7 +115,7 @@ export const socketsTcp = {
|
|
|
115
115
|
}
|
|
116
116
|
};
|
|
117
117
|
|
|
118
|
-
export const
|
|
118
|
+
export const udp = {
|
|
119
119
|
subscribe () {
|
|
120
120
|
|
|
121
121
|
},
|
|
@@ -193,11 +193,8 @@ export const socketsUdp = {
|
|
|
193
193
|
}
|
|
194
194
|
};
|
|
195
195
|
|
|
196
|
-
export {
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
socketsTcp as tcp,
|
|
202
|
-
socketsUdp as udp
|
|
203
|
-
}
|
|
196
|
+
export const udpCreateSocket = {
|
|
197
|
+
createTcpSocket () {
|
|
198
|
+
|
|
199
|
+
}
|
|
200
|
+
};
|
package/package.json
CHANGED
package/types/wasi-command.d.ts
CHANGED
|
@@ -1,23 +1,23 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
9
|
-
import {
|
|
10
|
-
import {
|
|
11
|
-
import {
|
|
12
|
-
import {
|
|
13
|
-
import {
|
|
14
|
-
import {
|
|
15
|
-
import {
|
|
16
|
-
import {
|
|
17
|
-
import {
|
|
18
|
-
import {
|
|
19
|
-
import {
|
|
20
|
-
import {
|
|
21
|
-
import {
|
|
22
|
-
import {
|
|
1
|
+
import { ImportsEnvironment } from './imports/environment';
|
|
2
|
+
import { ImportsExit } from './imports/exit';
|
|
3
|
+
import { ImportsPreopens } from './imports/preopens';
|
|
4
|
+
import { ImportsStderr } from './imports/stderr';
|
|
5
|
+
import { ImportsStdin } from './imports/stdin';
|
|
6
|
+
import { ImportsStdout } from './imports/stdout';
|
|
7
|
+
import { ImportsMonotonicClock } from './imports/monotonic-clock';
|
|
8
|
+
import { ImportsTimezone } from './imports/timezone';
|
|
9
|
+
import { ImportsWallClock } from './imports/wall-clock';
|
|
10
|
+
import { ImportsFilesystem } from './imports/filesystem';
|
|
11
|
+
import { ImportsStreams } from './imports/streams';
|
|
12
|
+
import { ImportsPoll } from './imports/poll';
|
|
13
|
+
import { ImportsInsecure } from './imports/insecure';
|
|
14
|
+
import { ImportsInsecureSeed } from './imports/insecure-seed';
|
|
15
|
+
import { ImportsRandom } from './imports/random';
|
|
16
|
+
import { ImportsInstanceNetwork } from './imports/instance-network';
|
|
17
|
+
import { ImportsIpNameLookup } from './imports/ip-name-lookup';
|
|
18
|
+
import { ImportsNetwork } from './imports/network';
|
|
19
|
+
import { ImportsTcp } from './imports/tcp';
|
|
20
|
+
import { ImportsTcpCreateSocket } from './imports/tcp-create-socket';
|
|
21
|
+
import { ImportsUdp } from './imports/udp';
|
|
22
|
+
import { ImportsUdpCreateSocket } from './imports/udp-create-socket';
|
|
23
23
|
export function run(): void;
|
package/types/wasi-proxy.d.ts
CHANGED
|
@@ -1,11 +1,10 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
9
|
-
import {
|
|
10
|
-
export const
|
|
11
|
-
export const incomingHandler: typeof HttpIncomingHandlerExports;
|
|
1
|
+
import { ImportsOutgoingHandler } from './imports/outgoing-handler';
|
|
2
|
+
import { ImportsTypes } from './imports/types';
|
|
3
|
+
import { ImportsStreams } from './imports/streams';
|
|
4
|
+
import { ImportsHandler } from './imports/handler';
|
|
5
|
+
import { ImportsPoll } from './imports/poll';
|
|
6
|
+
import { ImportsInsecure } from './imports/insecure';
|
|
7
|
+
import { ImportsInsecureSeed } from './imports/insecure-seed';
|
|
8
|
+
import { ImportsRandom } from './imports/random';
|
|
9
|
+
import { ExportsWasiHttpIncomingHandler } from './exports/wasi-http-incoming-handler';
|
|
10
|
+
export const incomingHandler: typeof ExportsWasiHttpIncomingHandler;
|
package/types/wasi-reactor.d.ts
CHANGED
|
@@ -1,23 +1,23 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
9
|
-
import {
|
|
10
|
-
import {
|
|
11
|
-
import {
|
|
12
|
-
import {
|
|
13
|
-
import {
|
|
14
|
-
import {
|
|
15
|
-
import {
|
|
16
|
-
import {
|
|
17
|
-
import {
|
|
18
|
-
import {
|
|
19
|
-
import {
|
|
20
|
-
import {
|
|
21
|
-
import {
|
|
22
|
-
import {
|
|
23
|
-
import {
|
|
1
|
+
import { ImportsEnvironment } from './imports/environment';
|
|
2
|
+
import { ImportsExit } from './imports/exit';
|
|
3
|
+
import { ImportsPreopens } from './imports/preopens';
|
|
4
|
+
import { ImportsStderr } from './imports/stderr';
|
|
5
|
+
import { ImportsStdin } from './imports/stdin';
|
|
6
|
+
import { ImportsStdout } from './imports/stdout';
|
|
7
|
+
import { ImportsMonotonicClock } from './imports/monotonic-clock';
|
|
8
|
+
import { ImportsTimezone } from './imports/timezone';
|
|
9
|
+
import { ImportsWallClock } from './imports/wall-clock';
|
|
10
|
+
import { ImportsFilesystem } from './imports/filesystem';
|
|
11
|
+
import { ImportsOutgoingHandler } from './imports/outgoing-handler';
|
|
12
|
+
import { ImportsTypes } from './imports/types';
|
|
13
|
+
import { ImportsStreams } from './imports/streams';
|
|
14
|
+
import { ImportsHandler } from './imports/handler';
|
|
15
|
+
import { ImportsPoll } from './imports/poll';
|
|
16
|
+
import { ImportsRandom } from './imports/random';
|
|
17
|
+
import { ImportsInstanceNetwork } from './imports/instance-network';
|
|
18
|
+
import { ImportsIpNameLookup } from './imports/ip-name-lookup';
|
|
19
|
+
import { ImportsNetwork } from './imports/network';
|
|
20
|
+
import { ImportsTcp } from './imports/tcp';
|
|
21
|
+
import { ImportsTcpCreateSocket } from './imports/tcp-create-socket';
|
|
22
|
+
import { ImportsUdp } from './imports/udp';
|
|
23
|
+
import { ImportsUdpCreateSocket } from './imports/udp-create-socket';
|