@bytecodealliance/preview2-shim 0.0.9 → 0.0.11

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 (47) hide show
  1. package/lib/browser/cli-base.js +6 -15
  2. package/lib/browser/clocks.js +8 -12
  3. package/lib/browser/http.js +3 -9
  4. package/lib/browser/io.js +8 -12
  5. package/lib/browser/logging.js +1 -3
  6. package/lib/browser/poll.js +1 -3
  7. package/lib/browser/random.js +26 -9
  8. package/lib/browser/sockets.js +11 -14
  9. package/lib/nodejs/cli-base.js +6 -15
  10. package/lib/nodejs/clocks.js +3 -9
  11. package/lib/nodejs/filesystem.js +8 -10
  12. package/lib/nodejs/http.js +3 -9
  13. package/lib/nodejs/io.js +33 -28
  14. package/lib/nodejs/logging.js +1 -3
  15. package/lib/nodejs/poll.js +1 -3
  16. package/lib/nodejs/random.js +21 -12
  17. package/lib/nodejs/sockets.js +11 -14
  18. package/package.json +1 -1
  19. package/types/exports/{http-incoming-handler.d.ts → wasi-http-incoming-handler.d.ts} +1 -1
  20. package/types/imports/{cli-base-environment.d.ts → environment.d.ts} +1 -1
  21. package/types/imports/{cli-base-exit.d.ts → exit.d.ts} +1 -1
  22. package/types/imports/{filesystem-filesystem.d.ts → filesystem.d.ts} +1 -1
  23. package/types/imports/{logging-handler.d.ts → handler.d.ts} +1 -1
  24. package/types/imports/{random-insecure-seed.d.ts → insecure-seed.d.ts} +1 -1
  25. package/types/imports/{random-insecure.d.ts → insecure.d.ts} +1 -1
  26. package/types/imports/{sockets-instance-network.d.ts → instance-network.d.ts} +1 -1
  27. package/types/imports/{sockets-ip-name-lookup.d.ts → ip-name-lookup.d.ts} +1 -1
  28. package/types/imports/{clocks-monotonic-clock.d.ts → monotonic-clock.d.ts} +1 -1
  29. package/types/imports/{sockets-network.d.ts → network.d.ts} +1 -1
  30. package/types/imports/{http-outgoing-handler.d.ts → outgoing-handler.d.ts} +1 -1
  31. package/types/imports/{poll-poll.d.ts → poll.d.ts} +1 -1
  32. package/types/imports/{cli-base-preopens.d.ts → preopens.d.ts} +1 -1
  33. package/types/imports/{random-random.d.ts → random.d.ts} +1 -1
  34. package/types/imports/{cli-base-stderr.d.ts → stderr.d.ts} +1 -1
  35. package/types/imports/{cli-base-stdin.d.ts → stdin.d.ts} +1 -1
  36. package/types/imports/{cli-base-stdout.d.ts → stdout.d.ts} +1 -1
  37. package/types/imports/{io-streams.d.ts → streams.d.ts} +1 -1
  38. package/types/imports/{sockets-tcp-create-socket.d.ts → tcp-create-socket.d.ts} +1 -1
  39. package/types/imports/{sockets-tcp.d.ts → tcp.d.ts} +1 -1
  40. package/types/imports/{clocks-timezone.d.ts → timezone.d.ts} +1 -1
  41. package/types/imports/{http-types.d.ts → types.d.ts} +1 -1
  42. package/types/imports/{sockets-udp-create-socket.d.ts → udp-create-socket.d.ts} +1 -1
  43. package/types/imports/{sockets-udp.d.ts → udp.d.ts} +1 -1
  44. package/types/imports/{clocks-wall-clock.d.ts → wall-clock.d.ts} +1 -1
  45. package/types/wasi-command.d.ts +22 -22
  46. package/types/wasi-proxy.d.ts +10 -11
  47. package/types/wasi-reactor.d.ts +23 -23
@@ -3,7 +3,7 @@ export function _setEnv (envObj) {
3
3
  _env = Object.entries(envObj);
4
4
  }
5
5
 
6
- export const cliBaseEnvironment = {
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 cliBaseExit = {
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 cliBasePreopens = {
26
+ export const preopens = {
27
27
  getDirectories () {
28
28
  return [];
29
29
  }
30
30
  }
31
31
 
32
- export const cliBaseStdin = {
32
+ export const stdin = {
33
33
  getStdin () {
34
34
  return 0;
35
35
  }
36
36
  };
37
37
 
38
- export const cliBaseStdout = {
38
+ export const stdout = {
39
39
  getStdout () {
40
40
  return 1;
41
41
  }
42
42
  };
43
43
 
44
- export const cliBaseStderr = {
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
- }
@@ -1,10 +1,11 @@
1
1
  function _hrtimeBigint () {
2
- return BigInt(Math.floor(performance.now() * 1e9));
2
+ // performance.now() is in milliseconds, but we want nanoseconds
3
+ return BigInt(Math.floor(performance.now() * 1e6));
3
4
  }
4
5
 
5
6
  let _hrStart = _hrtimeBigint();
6
7
 
7
- export const clocksMonotonicClock = {
8
+ export const monotonicClock = {
8
9
  resolution() {
9
10
  return 1n;
10
11
  },
@@ -16,7 +17,7 @@ export const clocksMonotonicClock = {
16
17
  }
17
18
  };
18
19
 
19
- export const clocksTimezone = {
20
+ export const timezone = {
20
21
  display (timezone, when) {
21
22
  console.log(`[timezone] DISPLAY ${timezone} ${when}`);
22
23
  },
@@ -31,10 +32,11 @@ export const clocksTimezone = {
31
32
  }
32
33
  };
33
34
 
34
- export const clocksWallClock = {
35
+ export const wallClock = {
35
36
  now() {
36
- const seconds = BigInt(Math.floor(Date.now() / 1e3));
37
- const nanoseconds = (Date.now() % 1e3) * 1e6;
37
+ let now = Date.now(); // in milliseconds
38
+ const seconds = BigInt(Math.floor(now / 1e3));
39
+ const nanoseconds = (now % 1e3) * 1e6;
38
40
  return { seconds, nanoseconds };
39
41
  },
40
42
 
@@ -42,9 +44,3 @@ export const clocksWallClock = {
42
44
  console.log(`[wall-clock] Wall clock resolution`);
43
45
  }
44
46
  };
45
-
46
- export {
47
- clocksMonotonicClock as monotonicClock,
48
- clocksTimezone as timezone,
49
- clocksWallClock as wallClock
50
- }
@@ -34,19 +34,19 @@ export function send(req) {
34
34
  }
35
35
  }
36
36
 
37
- export const httpIncomingHandler = {
37
+ export const incomingHandler = {
38
38
  handle () {
39
39
 
40
40
  }
41
41
  };
42
42
 
43
- export const httpOutgoingHandler = {
43
+ export const outgoingHandler = {
44
44
  handle () {
45
45
 
46
46
  }
47
47
  };
48
48
 
49
- export const httpTypes = {
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 ioStreams = {
1
+ export const streams = {
2
2
  read(s, len) {
3
3
  console.log(`[streams] Read ${s} ${len}`);
4
4
  },
@@ -18,26 +18,24 @@ export const ioStreams = {
18
18
  console.log(`[streams] Drop input stream ${s}`);
19
19
  },
20
20
  write(s, buf) {
21
+ streams.blockingWrite(s, buf);
22
+ },
23
+ blockingWrite(s, buf) {
21
24
  switch (s) {
22
25
  case 0:
23
26
  throw new Error(`TODO: write stdin`);
24
27
  case 1: {
25
- const decoder = new TextDecoder();
26
- console.log(decoder.decode(buf));
27
- return BigInt(buf.byteLength);
28
+ process.stdout.write(buf);
29
+ return [BigInt(buf.byteLength), 'ended'];
28
30
  }
29
31
  case 2: {
30
- const decoder = new TextDecoder();
31
- console.error(decoder.decode(buf));
32
- return BigInt(buf.byteLength);
32
+ process.stderr.write(buf);
33
+ return [BigInt(buf.byteLength), 'ended'];
33
34
  }
34
35
  default:
35
36
  throw new Error(`TODO: write ${s}`);
36
37
  }
37
38
  },
38
- blockingWrite(s, _buf) {
39
- console.log(`[streams] Blocking write ${s}`);
40
- },
41
39
  writeZeroes(s, _len) {
42
40
  console.log(`[streams] Write zeroes ${s}`);
43
41
  },
@@ -60,5 +58,3 @@ export const ioStreams = {
60
58
  console.log(`[streams] Drop output stream ${s}`);
61
59
  }
62
60
  };
63
-
64
- export { ioStreams as streams }
@@ -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 loggingHandler = {
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 }
@@ -1,4 +1,4 @@
1
- export const pollPoll = {
1
+ export const poll = {
2
2
  dropPollable (pollable) {
3
3
  console.log(`[poll] Drop (${pollable})`);
4
4
  },
@@ -7,5 +7,3 @@ export const pollPoll = {
7
7
  return [];
8
8
  }
9
9
  };
10
-
11
- export { pollPoll as poll }
@@ -2,11 +2,28 @@ const MAX_BYTES = 65536;
2
2
 
3
3
  let insecureRandomValue1, insecureRandomValue2;
4
4
 
5
- function getRandomU64 () {
6
- return crypto.getRandomValues(new BigUint64Array(1))[0];
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 randomRandom = {
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: 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 }
@@ -1,10 +1,10 @@
1
- export const socketsInstanceNetwork = {
1
+ export const instanceNetwork = {
2
2
  instanceNetwork () {
3
3
  console.log(`[sockets] instance network`);
4
4
  }
5
5
  };
6
6
 
7
- export const socketsIpNameLookup = {
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 socketsNetwork = {
28
+ export const network = {
29
29
  dropNetwork () {
30
30
 
31
31
  }
32
32
  };
33
33
 
34
- export const socketsTcpCreateSocket = {
34
+ export const tcpCreateSocket = {
35
35
  createTcpSocket () {
36
36
 
37
37
  }
38
38
  };
39
39
 
40
- export const socketsTcp = {
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 socketsUdp = {
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
- socketsInstanceNetwork as instanceNetwork,
198
- socketsIpNameLookup as ipNameLookup,
199
- socketsNetwork as network,
200
- socketsTcpCreateSocket as tcpCreateSocket,
201
- socketsTcp as tcp,
202
- socketsUdp as udp
203
- }
196
+ export const udpCreateSocket = {
197
+ createUdpSocket () {
198
+
199
+ }
200
+ };
@@ -61,48 +61,39 @@ export function _setEnv (envObj) {
61
61
  _env = Object.entries(envObj);
62
62
  }
63
63
 
64
- export const cliBaseEnvironment = {
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 cliBaseExit = {
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 cliBasePreopens = {
77
+ export const preopens = {
78
78
  getDirectories () {
79
79
  return directories;
80
80
  }
81
81
  }
82
82
 
83
- export const cliBaseStdin = {
83
+ export const stdin = {
84
84
  getStdin () {
85
85
  return 0;
86
86
  }
87
87
  };
88
88
 
89
- export const cliBaseStdout = {
89
+ export const stdout = {
90
90
  getStdout () {
91
91
  return 1;
92
92
  }
93
93
  };
94
94
 
95
- export const cliBaseStderr = {
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
- }
@@ -2,7 +2,7 @@ import { hrtime } from "node:process";
2
2
 
3
3
  let _hrStart = hrtime.bigint();
4
4
 
5
- export const clocksMonotonicClock = {
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 clocksTimezone = {
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 clocksWallClock = {
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
- }
@@ -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 { _createFileStream } from './io.js';
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
- return _createFileStream(fd, offset);
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
- _dirStreams.push({ fd, dirs, cursor: 0 });
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 = _dirStreams[stream];
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
- _dirStreams.splice(stream, 1);
309
+ _dropFsStream(stream);
310
310
  }
311
311
  };
312
-
313
- export { filesystem as filesystemFilesystem }
@@ -18,19 +18,19 @@ export function send(req) {
18
18
  throw new UnexpectedError(response);
19
19
  }
20
20
 
21
- export const httpIncomingHandler = {
21
+ export const incomingHandler = {
22
22
  handle () {
23
23
 
24
24
  }
25
25
  };
26
26
 
27
- export const httpOutgoingHandler = {
27
+ export const outgoingHandler = {
28
28
  handle () {
29
29
 
30
30
  }
31
31
  };
32
32
 
33
- export const httpTypes = {
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,45 +46,53 @@ function _convertFsError (e) {
46
46
 
47
47
  export let _streams = {};
48
48
  let streamCnt = 0;
49
- export function _createFileStream(fd, offset) {
50
- // note we only support offset 0
51
- if (Number(offset) === 0)
52
- _streams[streamCnt] = {
53
- type: 'file',
54
- fd: fd
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 const ioStreams = {
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
- switch (s) {
62
- case 0:
63
- return [process.stdin.read(len), true];
64
- default:
65
- throw new Error(`TODO: write ${s}`);
66
- }
74
+ return streams.blockingRead(s, len);
67
75
  },
68
76
  blockingRead(s, len) {
69
77
  len = Number(len);
70
78
  const stream = _streams[s];
71
- if (!stream) throw null;
72
- switch (stream.type) {
79
+ switch (stream?.type) {
73
80
  case 'file': {
74
81
  const buf = Buffer.alloc(Number(len));
75
82
  try {
76
83
  const readBytes = fsReadSync(stream.fd, buf, 0, Number(len));
77
- if (readBytes < Number(len))
78
- return [new Uint8Array(), true];
79
- return [new Uint8Array(buf.buffer, 0, readBytes), false];
84
+ if (readBytes < Number(len)) {
85
+ return [new Uint8Array(buf.buffer, 0, readBytes), 'ended'];
86
+ }
87
+ return [new Uint8Array(buf.buffer, 0, readBytes), 'open'];
80
88
  }
81
89
  catch (e) {
82
90
  _convertFsError(e);
83
91
  }
84
92
  break;
85
93
  }
86
- default: throw null;
87
94
  }
95
+ throw null;
88
96
  },
89
97
  skip(s, _len) {
90
98
  console.log(`[streams] Skip ${s}`);
@@ -97,27 +105,26 @@ export const ioStreams = {
97
105
  },
98
106
  dropInputStream(s) {
99
107
  delete _streams[s];
100
-
101
108
  },
102
109
  write(s, buf) {
110
+ return streams.blockingWrite(s, buf);
111
+ },
112
+ blockingWrite(s, buf) {
103
113
  switch (s) {
104
114
  case 0:
105
115
  throw new Error(`TODO: write stdin`);
106
116
  case 1: {
107
117
  process.stdout.write(buf);
108
- return BigInt(buf.byteLength);
118
+ return [BigInt(buf.byteLength), 'ended'];
109
119
  }
110
120
  case 2: {
111
121
  process.stderr.write(buf);
112
- return BigInt(buf.byteLength);
122
+ return [BigInt(buf.byteLength), 'ended'];
113
123
  }
114
124
  default:
115
125
  throw new Error(`TODO: write ${s}`);
116
126
  }
117
127
  },
118
- blockingWrite(s, _buf) {
119
- console.log(`[streams] Blocking write ${s}`);
120
- },
121
128
  writeZeroes(s, _len) {
122
129
  console.log(`[streams] Write zeroes ${s}`);
123
130
  },
@@ -140,5 +147,3 @@ export const ioStreams = {
140
147
  console.log(`[streams] Drop output stream ${s}`);
141
148
  }
142
149
  };
143
-
144
- export { ioStreams as streams }
@@ -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 loggingHandler = {
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 }
@@ -1,4 +1,4 @@
1
- export const pollPoll = {
1
+ export const poll = {
2
2
  dropPollable (pollable) {
3
3
  console.log(`[poll] Drop (${pollable})`);
4
4
  },
@@ -7,5 +7,3 @@ export const pollPoll = {
7
7
  return [];
8
8
  }
9
9
  };
10
-
11
- export { pollPoll as poll }
@@ -1,23 +1,32 @@
1
1
  import { randomBytes } from "node:crypto";
2
2
 
3
- let insecureRandomValue1, insecureRandomValue2;
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 randomRandom = {
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 }
@@ -1,10 +1,10 @@
1
- export const socketsInstanceNetwork = {
1
+ export const instanceNetwork = {
2
2
  instanceNetwork () {
3
3
  console.log(`[sockets] instance network`);
4
4
  }
5
5
  };
6
6
 
7
- export const socketsIpNameLookup = {
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 socketsNetwork = {
28
+ export const network = {
29
29
  dropNetwork () {
30
30
 
31
31
  }
32
32
  };
33
33
 
34
- export const socketsTcpCreateSocket = {
34
+ export const tcpCreateSocket = {
35
35
  createTcpSocket () {
36
36
 
37
37
  }
38
38
  };
39
39
 
40
- export const socketsTcp = {
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 socketsUdp = {
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
- socketsInstanceNetwork as instanceNetwork,
198
- socketsIpNameLookup as ipNameLookup,
199
- socketsNetwork as network,
200
- socketsTcpCreateSocket as tcpCreateSocket,
201
- socketsTcp as tcp,
202
- socketsUdp as udp
203
- }
196
+ export const udpCreateSocket = {
197
+ createTcpSocket () {
198
+
199
+ }
200
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bytecodealliance/preview2-shim",
3
- "version": "0.0.9",
3
+ "version": "0.0.11",
4
4
  "description": "WASI Preview2 shim for JS environments",
5
5
  "author": "Guy Bedford, Eduardo Rodrigues<16357187+eduardomourar@users.noreply.github.com>",
6
6
  "type": "module",
@@ -1,4 +1,4 @@
1
- export namespace HttpIncomingHandler {
1
+ export namespace ExportsWasiHttpIncomingHandler {
2
2
  export function handle(request: IncomingRequest, responseOut: ResponseOutparam): void;
3
3
  }
4
4
  import type { IncomingRequest } from '../imports/types';
@@ -1,4 +1,4 @@
1
- export namespace CliBaseEnvironment {
1
+ export namespace ImportsEnvironment {
2
2
  /**
3
3
  * Get the POSIX-style environment variables.
4
4
  *
@@ -1,4 +1,4 @@
1
- export namespace CliBaseExit {
1
+ export namespace ImportsExit {
2
2
  /**
3
3
  * Exit the curerent instance and any linked instances.
4
4
  */
@@ -1,4 +1,4 @@
1
- export namespace FilesystemFilesystem {
1
+ export namespace ImportsFilesystem {
2
2
  /**
3
3
  * Return a stream for reading from a file.
4
4
  *
@@ -1,4 +1,4 @@
1
- export namespace LoggingHandler {
1
+ export namespace ImportsHandler {
2
2
  /**
3
3
  * Emit a log message.
4
4
  *
@@ -1,4 +1,4 @@
1
- export namespace RandomInsecureSeed {
1
+ export namespace ImportsInsecureSeed {
2
2
  /**
3
3
  * Return a 128-bit value that may contain a pseudo-random value.
4
4
  *
@@ -1,4 +1,4 @@
1
- export namespace RandomInsecure {
1
+ export namespace ImportsInsecure {
2
2
  /**
3
3
  * Return `len` insecure pseudo-random bytes.
4
4
  *
@@ -1,4 +1,4 @@
1
- export namespace SocketsInstanceNetwork {
1
+ export namespace ImportsInstanceNetwork {
2
2
  /**
3
3
  * Get a handle to the default network.
4
4
  */
@@ -1,4 +1,4 @@
1
- export namespace SocketsIpNameLookup {
1
+ export namespace ImportsIpNameLookup {
2
2
  /**
3
3
  * Resolve an internet host name to a list of IP addresses.
4
4
  *
@@ -1,4 +1,4 @@
1
- export namespace ClocksMonotonicClock {
1
+ export namespace ImportsMonotonicClock {
2
2
  /**
3
3
  * Read the current value of the clock.
4
4
  *
@@ -1,4 +1,4 @@
1
- export namespace SocketsNetwork {
1
+ export namespace ImportsNetwork {
2
2
  /**
3
3
  * Dispose of the specified `network`, after which it may no longer be used.
4
4
  *
@@ -1,4 +1,4 @@
1
- export namespace HttpOutgoingHandler {
1
+ export namespace ImportsOutgoingHandler {
2
2
  export function handle(request: OutgoingRequest, options: RequestOptions | null): FutureIncomingResponse;
3
3
  }
4
4
  import type { OutgoingRequest } from '../imports/types';
@@ -1,4 +1,4 @@
1
- export namespace PollPoll {
1
+ export namespace ImportsPoll {
2
2
  /**
3
3
  * Dispose of the specified `pollable`, after which it may no longer
4
4
  * be used.
@@ -1,4 +1,4 @@
1
- export namespace CliBasePreopens {
1
+ export namespace ImportsPreopens {
2
2
  /**
3
3
  * Return the set of of preopened directories, and their path.
4
4
  */
@@ -1,4 +1,4 @@
1
- export namespace RandomRandom {
1
+ export namespace ImportsRandom {
2
2
  /**
3
3
  * Return `len` cryptographically-secure pseudo-random bytes.
4
4
  *
@@ -1,4 +1,4 @@
1
- export namespace CliBaseStderr {
1
+ export namespace ImportsStderr {
2
2
  export function getStderr(): OutputStream;
3
3
  }
4
4
  import type { OutputStream } from '../imports/streams';
@@ -1,4 +1,4 @@
1
- export namespace CliBaseStdin {
1
+ export namespace ImportsStdin {
2
2
  export function getStdin(): InputStream;
3
3
  }
4
4
  import type { InputStream } from '../imports/streams';
@@ -1,4 +1,4 @@
1
- export namespace CliBaseStdout {
1
+ export namespace ImportsStdout {
2
2
  export function getStdout(): OutputStream;
3
3
  }
4
4
  import type { OutputStream } from '../imports/streams';
@@ -1,4 +1,4 @@
1
- export namespace IoStreams {
1
+ export namespace ImportsStreams {
2
2
  /**
3
3
  * Read bytes from a stream.
4
4
  *
@@ -1,4 +1,4 @@
1
- export namespace SocketsTcpCreateSocket {
1
+ export namespace ImportsTcpCreateSocket {
2
2
  /**
3
3
  * Create a new TCP socket.
4
4
  *
@@ -1,4 +1,4 @@
1
- export namespace SocketsTcp {
1
+ export namespace ImportsTcp {
2
2
  /**
3
3
  * Bind the socket to a specific network on the provided IP address and port.
4
4
  *
@@ -1,4 +1,4 @@
1
- export namespace ClocksTimezone {
1
+ export namespace ImportsTimezone {
2
2
  /**
3
3
  * Return information needed to display the given `datetime`. This includes
4
4
  * the UTC offset, the time zone name, and a flag indicating whether
@@ -1,4 +1,4 @@
1
- export namespace HttpTypes {
1
+ export namespace ImportsTypes {
2
2
  export function dropFields(fields: Fields): void;
3
3
  export function newFields(entries: [string, string][]): Fields;
4
4
  export function fieldsGet(fields: Fields, name: string): string[];
@@ -1,4 +1,4 @@
1
- export namespace SocketsUdpCreateSocket {
1
+ export namespace ImportsUdpCreateSocket {
2
2
  /**
3
3
  * Create a new UDP socket.
4
4
  *
@@ -1,4 +1,4 @@
1
- export namespace SocketsUdp {
1
+ export namespace ImportsUdp {
2
2
  /**
3
3
  * Bind the socket to a specific network on the provided IP address and port.
4
4
  *
@@ -1,4 +1,4 @@
1
- export namespace ClocksWallClock {
1
+ export namespace ImportsWallClock {
2
2
  /**
3
3
  * Read the current value of the clock.
4
4
  *
@@ -1,23 +1,23 @@
1
- import { CliBaseEnvironment as CliBaseEnvironmentImports } from './imports/cli-base-environment';
2
- import { CliBasePreopens as CliBasePreopensImports } from './imports/cli-base-preopens';
3
- import { CliBaseExit as CliBaseExitImports } from './imports/cli-base-exit';
4
- import { CliBaseStdin as CliBaseStdinImports } from './imports/cli-base-stdin';
5
- import { CliBaseStdout as CliBaseStdoutImports } from './imports/cli-base-stdout';
6
- import { CliBaseStderr as CliBaseStderrImports } from './imports/cli-base-stderr';
7
- import { ClocksWallClock as ClocksWallClockImports } from './imports/clocks-wall-clock';
8
- import { ClocksMonotonicClock as ClocksMonotonicClockImports } from './imports/clocks-monotonic-clock';
9
- import { ClocksTimezone as ClocksTimezoneImports } from './imports/clocks-timezone';
10
- import { FilesystemFilesystem as FilesystemFilesystemImports } from './imports/filesystem-filesystem';
11
- import { IoStreams as IoStreamsImports } from './imports/io-streams';
12
- import { PollPoll as PollPollImports } from './imports/poll-poll';
13
- import { RandomRandom as RandomRandomImports } from './imports/random-random';
14
- import { RandomInsecure as RandomInsecureImports } from './imports/random-insecure';
15
- import { RandomInsecureSeed as RandomInsecureSeedImports } from './imports/random-insecure-seed';
16
- import { SocketsNetwork as SocketsNetworkImports } from './imports/sockets-network';
17
- import { SocketsInstanceNetwork as SocketsInstanceNetworkImports } from './imports/sockets-instance-network';
18
- import { SocketsIpNameLookup as SocketsIpNameLookupImports } from './imports/sockets-ip-name-lookup';
19
- import { SocketsTcp as SocketsTcpImports } from './imports/sockets-tcp';
20
- import { SocketsTcpCreateSocket as SocketsTcpCreateSocketImports } from './imports/sockets-tcp-create-socket';
21
- import { SocketsUdp as SocketsUdpImports } from './imports/sockets-udp';
22
- import { SocketsUdpCreateSocket as SocketsUdpCreateSocketImports } from './imports/sockets-udp-create-socket';
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;
@@ -1,11 +1,10 @@
1
- import { HttpTypes as HttpTypesImports } from './imports/http-types';
2
- import { HttpOutgoingHandler as HttpOutgoingHandlerImports } from './imports/http-outgoing-handler';
3
- import { IoStreams as IoStreamsImports } from './imports/io-streams';
4
- import { LoggingHandler as LoggingHandlerImports } from './imports/logging-handler';
5
- import { PollPoll as PollPollImports } from './imports/poll-poll';
6
- import { RandomRandom as RandomRandomImports } from './imports/random-random';
7
- import { RandomInsecure as RandomInsecureImports } from './imports/random-insecure';
8
- import { RandomInsecureSeed as RandomInsecureSeedImports } from './imports/random-insecure-seed';
9
- import { HttpIncomingHandler as HttpIncomingHandlerExports } from './exports/http-incoming-handler';
10
- export const httpIncomingHandler: typeof HttpIncomingHandlerExports;
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;
@@ -1,23 +1,23 @@
1
- import { CliBaseEnvironment as CliBaseEnvironmentImports } from './imports/cli-base-environment';
2
- import { CliBasePreopens as CliBasePreopensImports } from './imports/cli-base-preopens';
3
- import { CliBaseExit as CliBaseExitImports } from './imports/cli-base-exit';
4
- import { CliBaseStdin as CliBaseStdinImports } from './imports/cli-base-stdin';
5
- import { CliBaseStdout as CliBaseStdoutImports } from './imports/cli-base-stdout';
6
- import { CliBaseStderr as CliBaseStderrImports } from './imports/cli-base-stderr';
7
- import { ClocksWallClock as ClocksWallClockImports } from './imports/clocks-wall-clock';
8
- import { ClocksMonotonicClock as ClocksMonotonicClockImports } from './imports/clocks-monotonic-clock';
9
- import { ClocksTimezone as ClocksTimezoneImports } from './imports/clocks-timezone';
10
- import { FilesystemFilesystem as FilesystemFilesystemImports } from './imports/filesystem-filesystem';
11
- import { HttpTypes as HttpTypesImports } from './imports/http-types';
12
- import { HttpOutgoingHandler as HttpOutgoingHandlerImports } from './imports/http-outgoing-handler';
13
- import { IoStreams as IoStreamsImports } from './imports/io-streams';
14
- import { LoggingHandler as LoggingHandlerImports } from './imports/logging-handler';
15
- import { PollPoll as PollPollImports } from './imports/poll-poll';
16
- import { RandomRandom as RandomRandomImports } from './imports/random-random';
17
- import { SocketsNetwork as SocketsNetworkImports } from './imports/sockets-network';
18
- import { SocketsInstanceNetwork as SocketsInstanceNetworkImports } from './imports/sockets-instance-network';
19
- import { SocketsIpNameLookup as SocketsIpNameLookupImports } from './imports/sockets-ip-name-lookup';
20
- import { SocketsTcp as SocketsTcpImports } from './imports/sockets-tcp';
21
- import { SocketsTcpCreateSocket as SocketsTcpCreateSocketImports } from './imports/sockets-tcp-create-socket';
22
- import { SocketsUdp as SocketsUdpImports } from './imports/sockets-udp';
23
- import { SocketsUdpCreateSocket as SocketsUdpCreateSocketImports } from './imports/sockets-udp-create-socket';
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';