@bytecodealliance/preview2-shim 0.0.8 → 0.0.9
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 +1 -0
- package/lib/browser/cli-base.js +57 -0
- package/lib/browser/clocks.js +50 -0
- package/lib/browser/filesystem.js +134 -141
- package/lib/browser/http.js +120 -0
- package/lib/browser/index.js +15 -37
- package/lib/browser/io.js +62 -20
- package/lib/browser/logging.js +16 -0
- package/lib/browser/poll.js +10 -6
- package/lib/browser/random.js +32 -25
- package/lib/browser/sockets.js +203 -0
- package/lib/nodejs/{preopens.js → cli-base.js} +47 -8
- package/lib/nodejs/clocks.js +50 -0
- package/lib/nodejs/filesystem.js +239 -234
- package/lib/nodejs/http.js +120 -0
- package/lib/nodejs/index.js +15 -37
- package/lib/nodejs/io.js +138 -19
- package/lib/nodejs/logging.js +16 -0
- package/lib/nodejs/poll.js +10 -6
- package/lib/nodejs/random.js +18 -13
- package/lib/nodejs/sockets.js +203 -0
- package/package.json +1 -1
- package/types/exports/{HTTP.d.ts → http-incoming-handler.d.ts} +1 -1
- package/types/imports/cli-base-environment.d.ts +17 -0
- package/types/imports/{exit.d.ts → cli-base-exit.d.ts} +4 -1
- package/types/imports/{preopens.d.ts → cli-base-preopens.d.ts} +6 -9
- package/types/imports/cli-base-stderr.d.ts +5 -0
- package/types/imports/cli-base-stdin.d.ts +5 -0
- package/types/imports/cli-base-stdout.d.ts +5 -0
- package/types/imports/clocks-monotonic-clock.d.ts +24 -0
- package/types/imports/clocks-timezone.d.ts +71 -0
- package/types/imports/clocks-wall-clock.d.ts +31 -0
- package/types/imports/filesystem-filesystem.d.ts +857 -0
- package/types/imports/{default-outgoing-HTTP.d.ts → http-outgoing-handler.d.ts} +1 -1
- package/types/imports/{types.d.ts → http-types.d.ts} +28 -28
- package/types/imports/io-streams.d.ts +180 -0
- package/types/imports/logging-handler.d.ts +40 -0
- package/types/imports/poll-poll.d.ts +41 -0
- package/types/imports/random-insecure-seed.d.ts +22 -0
- package/types/imports/random-insecure.d.ts +20 -0
- package/types/imports/random-random.d.ts +22 -0
- package/types/imports/{instance-network.d.ts → sockets-instance-network.d.ts} +4 -1
- package/types/imports/sockets-ip-name-lookup.d.ts +76 -0
- package/types/imports/sockets-network.d.ts +212 -0
- package/types/imports/sockets-tcp-create-socket.d.ts +33 -0
- package/types/imports/sockets-tcp.d.ts +285 -0
- package/types/imports/sockets-udp-create-socket.d.ts +33 -0
- package/types/imports/sockets-udp.d.ts +219 -0
- package/types/wasi-command.d.ts +23 -0
- package/types/wasi-proxy.d.ts +11 -44
- package/types/wasi-reactor.d.ts +23 -70
- package/lib/browser/console.js +0 -12
- package/lib/browser/default-outgoing-HTTP.js +0 -3
- package/lib/browser/environment.js +0 -17
- package/lib/browser/exit.js +0 -21
- package/lib/browser/instance-network.js +0 -3
- package/lib/browser/ip-name-lookup.js +0 -23
- package/lib/browser/monotonic-clock.js +0 -14
- package/lib/browser/network.js +0 -3
- package/lib/browser/preopens.js +0 -11
- package/lib/browser/stderr.js +0 -4
- package/lib/browser/streams.js +0 -60
- package/lib/browser/tcp-create-socket.js +0 -3
- package/lib/browser/tcp.js +0 -75
- package/lib/browser/timezone.js +0 -12
- package/lib/browser/types.js +0 -99
- package/lib/browser/udp-create-socket.js +0 -3
- package/lib/browser/udp.js +0 -75
- package/lib/browser/wall-clock.js +0 -9
- package/lib/nodejs/console.js +0 -12
- package/lib/nodejs/default-outgoing-HTTP.js +0 -3
- package/lib/nodejs/environment.js +0 -19
- package/lib/nodejs/exit.js +0 -3
- package/lib/nodejs/instance-network.js +0 -3
- package/lib/nodejs/ip-name-lookup.js +0 -23
- package/lib/nodejs/monotonic-clock.js +0 -14
- package/lib/nodejs/network.js +0 -3
- package/lib/nodejs/stderr.js +0 -4
- package/lib/nodejs/streams.js +0 -97
- package/lib/nodejs/tcp-create-socket.js +0 -3
- package/lib/nodejs/tcp.js +0 -75
- package/lib/nodejs/timezone.js +0 -12
- package/lib/nodejs/types.js +0 -99
- package/lib/nodejs/udp-create-socket.js +0 -3
- package/lib/nodejs/udp.js +0 -75
- package/lib/nodejs/wall-clock.js +0 -9
- package/types/imports/console.d.ts +0 -17
- package/types/imports/environment.d.ts +0 -4
- package/types/imports/filesystem.d.ts +0 -210
- package/types/imports/ip-name-lookup.d.ts +0 -19
- package/types/imports/monotonic-clock.d.ts +0 -8
- package/types/imports/network.d.ts +0 -50
- package/types/imports/poll.d.ts +0 -5
- package/types/imports/random.d.ts +0 -5
- package/types/imports/streams.d.ts +0 -23
- package/types/imports/tcp-create-socket.d.ts +0 -9
- package/types/imports/tcp.d.ts +0 -52
- package/types/imports/timezone.d.ts +0 -13
- package/types/imports/udp-create-socket.d.ts +0 -9
- package/types/imports/udp.d.ts +0 -36
- package/types/imports/wall-clock.d.ts +0 -8
- package/types/index.d.ts +0 -8
package/lib/browser/poll.js
CHANGED
|
@@ -1,7 +1,11 @@
|
|
|
1
|
-
export
|
|
2
|
-
|
|
3
|
-
}
|
|
1
|
+
export const pollPoll = {
|
|
2
|
+
dropPollable (pollable) {
|
|
3
|
+
console.log(`[poll] Drop (${pollable})`);
|
|
4
|
+
},
|
|
5
|
+
pollOneoff (input) {
|
|
6
|
+
console.log(`[poll] Oneoff (${input})`);
|
|
7
|
+
return [];
|
|
8
|
+
}
|
|
9
|
+
};
|
|
4
10
|
|
|
5
|
-
export
|
|
6
|
-
console.log(`[poll] Poll oneoff ${f}`);
|
|
7
|
-
}
|
|
11
|
+
export { pollPoll as poll }
|
package/lib/browser/random.js
CHANGED
|
@@ -1,32 +1,39 @@
|
|
|
1
1
|
const MAX_BYTES = 65536;
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
const bytes = new Uint8Array(Number(len));
|
|
5
|
-
|
|
6
|
-
if (len > MAX_BYTES) {
|
|
7
|
-
// this is the max bytes crypto.getRandomValues
|
|
8
|
-
// can do at once see https://developer.mozilla.org/en-US/docs/Web/API/window.crypto.getRandomValues
|
|
9
|
-
for (var generated = 0; generated < len; generated += MAX_BYTES) {
|
|
10
|
-
// buffer.slice automatically checks if the end is past the end of
|
|
11
|
-
// the buffer so we don't have to here
|
|
12
|
-
crypto.getRandomValues(bytes.slice(generated, generated + MAX_BYTES));
|
|
13
|
-
}
|
|
14
|
-
} else {
|
|
15
|
-
crypto.getRandomValues(bytes);
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
return bytes;
|
|
19
|
-
}
|
|
3
|
+
let insecureRandomValue1, insecureRandomValue2;
|
|
20
4
|
|
|
21
|
-
|
|
5
|
+
function getRandomU64 () {
|
|
22
6
|
return crypto.getRandomValues(new BigUint64Array(1))[0];
|
|
23
7
|
}
|
|
24
8
|
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
9
|
+
export const randomRandom = {
|
|
10
|
+
getRandomBytes(len) {
|
|
11
|
+
const bytes = new Uint8Array(Number(len));
|
|
12
|
+
|
|
13
|
+
if (len > MAX_BYTES) {
|
|
14
|
+
// this is the max bytes crypto.getRandomValues
|
|
15
|
+
// can do at once see https://developer.mozilla.org/en-US/docs/Web/API/window.crypto.getRandomValues
|
|
16
|
+
for (var generated = 0; generated < len; generated += MAX_BYTES) {
|
|
17
|
+
// buffer.slice automatically checks if the end is past the end of
|
|
18
|
+
// the buffer so we don't have to here
|
|
19
|
+
crypto.getRandomValues(bytes.slice(generated, generated + MAX_BYTES));
|
|
20
|
+
}
|
|
21
|
+
} else {
|
|
22
|
+
crypto.getRandomValues(bytes);
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
return bytes;
|
|
26
|
+
},
|
|
27
|
+
|
|
28
|
+
getRandomU64: getRandomU64,
|
|
29
|
+
|
|
30
|
+
insecureRandom () {
|
|
31
|
+
if (insecureRandomValue1 === undefined) {
|
|
32
|
+
insecureRandomValue1 = getRandomU64();
|
|
33
|
+
insecureRandomValue2 = getRandomU64();
|
|
34
|
+
}
|
|
35
|
+
return [insecureRandomValue1, insecureRandomValue2];
|
|
30
36
|
}
|
|
31
|
-
|
|
32
|
-
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
export { randomRandom as random }
|
|
@@ -0,0 +1,203 @@
|
|
|
1
|
+
export const socketsInstanceNetwork = {
|
|
2
|
+
instanceNetwork () {
|
|
3
|
+
console.log(`[sockets] instance network`);
|
|
4
|
+
}
|
|
5
|
+
};
|
|
6
|
+
|
|
7
|
+
export const socketsIpNameLookup = {
|
|
8
|
+
dropResolveAddressStream () {
|
|
9
|
+
|
|
10
|
+
},
|
|
11
|
+
subscribe () {
|
|
12
|
+
|
|
13
|
+
},
|
|
14
|
+
resolveAddresses () {
|
|
15
|
+
|
|
16
|
+
},
|
|
17
|
+
resolveNextAddress () {
|
|
18
|
+
|
|
19
|
+
},
|
|
20
|
+
nonBlocking () {
|
|
21
|
+
|
|
22
|
+
},
|
|
23
|
+
setNonBlocking () {
|
|
24
|
+
|
|
25
|
+
},
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
export const socketsNetwork = {
|
|
29
|
+
dropNetwork () {
|
|
30
|
+
|
|
31
|
+
}
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
export const socketsTcpCreateSocket = {
|
|
35
|
+
createTcpSocket () {
|
|
36
|
+
|
|
37
|
+
}
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
export const socketsTcp = {
|
|
41
|
+
subscribe () {
|
|
42
|
+
|
|
43
|
+
},
|
|
44
|
+
dropTcpSocket() {
|
|
45
|
+
|
|
46
|
+
},
|
|
47
|
+
bind() {
|
|
48
|
+
|
|
49
|
+
},
|
|
50
|
+
connect() {
|
|
51
|
+
|
|
52
|
+
},
|
|
53
|
+
listen() {
|
|
54
|
+
|
|
55
|
+
},
|
|
56
|
+
accept() {
|
|
57
|
+
|
|
58
|
+
},
|
|
59
|
+
localAddress() {
|
|
60
|
+
|
|
61
|
+
},
|
|
62
|
+
remoteAddress() {
|
|
63
|
+
|
|
64
|
+
},
|
|
65
|
+
addressFamily() {
|
|
66
|
+
|
|
67
|
+
},
|
|
68
|
+
ipv6Only() {
|
|
69
|
+
|
|
70
|
+
},
|
|
71
|
+
setIpv6Only() {
|
|
72
|
+
|
|
73
|
+
},
|
|
74
|
+
setListenBacklogSize() {
|
|
75
|
+
|
|
76
|
+
},
|
|
77
|
+
keepAlive() {
|
|
78
|
+
|
|
79
|
+
},
|
|
80
|
+
setKeepAlive() {
|
|
81
|
+
|
|
82
|
+
},
|
|
83
|
+
noDelay() {
|
|
84
|
+
|
|
85
|
+
},
|
|
86
|
+
setNoDelay() {
|
|
87
|
+
|
|
88
|
+
},
|
|
89
|
+
unicastHopLimit() {
|
|
90
|
+
|
|
91
|
+
},
|
|
92
|
+
setUnicastHopLimit() {
|
|
93
|
+
|
|
94
|
+
},
|
|
95
|
+
receiveBufferSize() {
|
|
96
|
+
|
|
97
|
+
},
|
|
98
|
+
setReceiveBufferSize() {
|
|
99
|
+
|
|
100
|
+
},
|
|
101
|
+
sendBufferSize() {
|
|
102
|
+
|
|
103
|
+
},
|
|
104
|
+
setSendBufferSize() {
|
|
105
|
+
|
|
106
|
+
},
|
|
107
|
+
nonBlocking() {
|
|
108
|
+
|
|
109
|
+
},
|
|
110
|
+
setNonBlocking() {
|
|
111
|
+
|
|
112
|
+
},
|
|
113
|
+
shutdown() {
|
|
114
|
+
|
|
115
|
+
}
|
|
116
|
+
};
|
|
117
|
+
|
|
118
|
+
export const socketsUdp = {
|
|
119
|
+
subscribe () {
|
|
120
|
+
|
|
121
|
+
},
|
|
122
|
+
|
|
123
|
+
dropUdpSocket () {
|
|
124
|
+
|
|
125
|
+
},
|
|
126
|
+
|
|
127
|
+
bind () {
|
|
128
|
+
|
|
129
|
+
},
|
|
130
|
+
|
|
131
|
+
connect () {
|
|
132
|
+
|
|
133
|
+
},
|
|
134
|
+
|
|
135
|
+
receive () {
|
|
136
|
+
|
|
137
|
+
},
|
|
138
|
+
|
|
139
|
+
send () {
|
|
140
|
+
|
|
141
|
+
},
|
|
142
|
+
|
|
143
|
+
localAddress () {
|
|
144
|
+
|
|
145
|
+
},
|
|
146
|
+
|
|
147
|
+
remoteAddress () {
|
|
148
|
+
|
|
149
|
+
},
|
|
150
|
+
|
|
151
|
+
addressFamily () {
|
|
152
|
+
|
|
153
|
+
},
|
|
154
|
+
|
|
155
|
+
ipv6Only () {
|
|
156
|
+
|
|
157
|
+
},
|
|
158
|
+
|
|
159
|
+
setIpv6Only () {
|
|
160
|
+
|
|
161
|
+
},
|
|
162
|
+
|
|
163
|
+
unicastHopLimit () {
|
|
164
|
+
|
|
165
|
+
},
|
|
166
|
+
|
|
167
|
+
setUnicastHopLimit () {
|
|
168
|
+
|
|
169
|
+
},
|
|
170
|
+
|
|
171
|
+
receiveBufferSize () {
|
|
172
|
+
|
|
173
|
+
},
|
|
174
|
+
|
|
175
|
+
setReceiveBufferSize () {
|
|
176
|
+
|
|
177
|
+
},
|
|
178
|
+
|
|
179
|
+
sendBufferSize () {
|
|
180
|
+
|
|
181
|
+
},
|
|
182
|
+
|
|
183
|
+
setSendBufferSize () {
|
|
184
|
+
|
|
185
|
+
},
|
|
186
|
+
|
|
187
|
+
nonBlocking () {
|
|
188
|
+
|
|
189
|
+
},
|
|
190
|
+
|
|
191
|
+
setNonBlocking () {
|
|
192
|
+
|
|
193
|
+
}
|
|
194
|
+
};
|
|
195
|
+
|
|
196
|
+
export {
|
|
197
|
+
socketsInstanceNetwork as instanceNetwork,
|
|
198
|
+
socketsIpNameLookup as ipNameLookup,
|
|
199
|
+
socketsNetwork as network,
|
|
200
|
+
socketsTcpCreateSocket as tcpCreateSocket,
|
|
201
|
+
socketsTcp as tcp,
|
|
202
|
+
socketsUdp as udp
|
|
203
|
+
}
|
|
@@ -56,14 +56,53 @@ export function _setPreopens (preopens) {
|
|
|
56
56
|
}
|
|
57
57
|
}
|
|
58
58
|
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
stdout: 1,
|
|
63
|
-
stderr: 2,
|
|
64
|
-
};
|
|
59
|
+
let _env;
|
|
60
|
+
export function _setEnv (envObj) {
|
|
61
|
+
_env = Object.entries(envObj);
|
|
65
62
|
}
|
|
66
63
|
|
|
67
|
-
export
|
|
68
|
-
|
|
64
|
+
export const cliBaseEnvironment = {
|
|
65
|
+
getEnvironment () {
|
|
66
|
+
if (!_env) _setEnv(process.env);
|
|
67
|
+
return _env;
|
|
68
|
+
}
|
|
69
|
+
};
|
|
70
|
+
|
|
71
|
+
export const cliBaseExit = {
|
|
72
|
+
exit (status) {
|
|
73
|
+
process.exit(status.tag === 'err' ? 1 : 0);
|
|
74
|
+
}
|
|
75
|
+
};
|
|
76
|
+
|
|
77
|
+
export const cliBasePreopens = {
|
|
78
|
+
getDirectories () {
|
|
79
|
+
return directories;
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
export const cliBaseStdin = {
|
|
84
|
+
getStdin () {
|
|
85
|
+
return 0;
|
|
86
|
+
}
|
|
87
|
+
};
|
|
88
|
+
|
|
89
|
+
export const cliBaseStdout = {
|
|
90
|
+
getStdout () {
|
|
91
|
+
return 1;
|
|
92
|
+
}
|
|
93
|
+
};
|
|
94
|
+
|
|
95
|
+
export const cliBaseStderr = {
|
|
96
|
+
getStderr () {
|
|
97
|
+
return 2;
|
|
98
|
+
}
|
|
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
|
|
69
108
|
}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { hrtime } from "node:process";
|
|
2
|
+
|
|
3
|
+
let _hrStart = hrtime.bigint();
|
|
4
|
+
|
|
5
|
+
export const clocksMonotonicClock = {
|
|
6
|
+
resolution () {
|
|
7
|
+
return 1n;
|
|
8
|
+
},
|
|
9
|
+
|
|
10
|
+
now () {
|
|
11
|
+
return hrtime.bigint() - _hrStart;
|
|
12
|
+
},
|
|
13
|
+
|
|
14
|
+
subscribe (_when, _absolute) {
|
|
15
|
+
console.log(`[monotonic-clock] Subscribe`);
|
|
16
|
+
}
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
export const clocksTimezone = {
|
|
20
|
+
display (timezone, when) {
|
|
21
|
+
console.log(`[timezone] DISPLAY ${timezone} ${when}`);
|
|
22
|
+
},
|
|
23
|
+
|
|
24
|
+
utcOffset (timezone, when) {
|
|
25
|
+
console.log(`[timezone] UTC OFFSET ${timezone} ${when}`);
|
|
26
|
+
return 0;
|
|
27
|
+
},
|
|
28
|
+
|
|
29
|
+
dropTimezone (timezone) {
|
|
30
|
+
console.log(`[timezone] DROP ${timezone}`);
|
|
31
|
+
}
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
export const clocksWallClock = {
|
|
35
|
+
now() {
|
|
36
|
+
const seconds = BigInt(Math.floor(Date.now() / 1e3));
|
|
37
|
+
const nanoseconds = (Date.now() % 1e3) * 1e6;
|
|
38
|
+
return { seconds, nanoseconds };
|
|
39
|
+
},
|
|
40
|
+
|
|
41
|
+
resolution() {
|
|
42
|
+
console.log(`[wall-clock] Wall clock resolution`);
|
|
43
|
+
}
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
export {
|
|
47
|
+
clocksMonotonicClock as monotonicClock,
|
|
48
|
+
clocksTimezone as timezone,
|
|
49
|
+
clocksWallClock as wallClock
|
|
50
|
+
}
|