@bytecodealliance/preview2-shim 0.0.12 → 0.0.14

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 (91) hide show
  1. package/README.md +2 -2
  2. package/lib/browser/cli.js +87 -0
  3. package/lib/browser/filesystem.js +216 -18
  4. package/lib/browser/http.js +4 -7
  5. package/lib/browser/index.js +2 -2
  6. package/lib/browser/io.js +76 -17
  7. package/lib/browser/logging.js +2 -2
  8. package/lib/browser/poll.js +48 -4
  9. package/lib/http/error.js +1 -1
  10. package/lib/http/make-request.js +3 -2
  11. package/lib/http/wasi-http.js +52 -40
  12. package/lib/nodejs/cli.js +75 -0
  13. package/lib/nodejs/filesystem.js +93 -3
  14. package/lib/nodejs/http.js +4 -7
  15. package/lib/nodejs/index.js +2 -2
  16. package/lib/nodejs/logging.js +2 -2
  17. package/package.json +1 -1
  18. package/types/{imports/environment.d.ts → exports/wasi-cli-environment.d.ts} +6 -1
  19. package/types/{imports/exit.d.ts → exports/wasi-cli-exit.d.ts} +2 -2
  20. package/types/exports/wasi-cli-run.d.ts +6 -0
  21. package/types/exports/wasi-cli-stderr.d.ts +5 -0
  22. package/types/exports/wasi-cli-stdin.d.ts +5 -0
  23. package/types/exports/wasi-cli-stdout.d.ts +5 -0
  24. package/types/exports/wasi-cli-terminal-input.d.ts +13 -0
  25. package/types/exports/wasi-cli-terminal-output.d.ts +13 -0
  26. package/types/exports/wasi-cli-terminal-stderr.d.ts +9 -0
  27. package/types/exports/wasi-cli-terminal-stdin.d.ts +9 -0
  28. package/types/exports/wasi-cli-terminal-stdout.d.ts +9 -0
  29. package/types/{imports/monotonic-clock.d.ts → exports/wasi-clocks-monotonic-clock.d.ts} +2 -2
  30. package/types/{imports/timezone.d.ts → exports/wasi-clocks-timezone.d.ts} +15 -15
  31. package/types/{imports/wall-clock.d.ts → exports/wasi-clocks-wall-clock.d.ts} +1 -1
  32. package/types/exports/wasi-filesystem-preopens.d.ts +8 -0
  33. package/types/{imports/filesystem.d.ts → exports/wasi-filesystem-types.d.ts} +293 -307
  34. package/types/exports/wasi-http-incoming-handler.d.ts +3 -3
  35. package/types/exports/wasi-http-outgoing-handler.d.ts +9 -0
  36. package/types/{imports/types.d.ts → exports/wasi-http-types.d.ts} +40 -41
  37. package/types/exports/wasi-io-streams.d.ts +220 -0
  38. package/types/{imports/poll.d.ts → exports/wasi-poll-poll.d.ts} +6 -8
  39. package/types/{imports/insecure-seed.d.ts → exports/wasi-random-insecure-seed.d.ts} +1 -1
  40. package/types/exports/wasi-random-insecure.d.ts +20 -0
  41. package/types/exports/wasi-random-random.d.ts +22 -0
  42. package/types/{imports/instance-network.d.ts → exports/wasi-sockets-instance-network.d.ts} +2 -2
  43. package/types/{imports/ip-name-lookup.d.ts → exports/wasi-sockets-ip-name-lookup.d.ts} +9 -9
  44. package/types/{imports/network.d.ts → exports/wasi-sockets-network.d.ts} +43 -75
  45. package/types/{imports/tcp-create-socket.d.ts → exports/wasi-sockets-tcp-create-socket.d.ts} +5 -5
  46. package/types/{imports/tcp.d.ts → exports/wasi-sockets-tcp.d.ts} +38 -38
  47. package/types/{imports/udp-create-socket.d.ts → exports/wasi-sockets-udp-create-socket.d.ts} +5 -5
  48. package/types/{imports/udp.d.ts → exports/wasi-sockets-udp.d.ts} +41 -32
  49. package/types/imports/wasi-cli-environment.d.ts +22 -0
  50. package/types/imports/wasi-cli-exit.d.ts +7 -0
  51. package/types/imports/wasi-cli-stderr.d.ts +5 -0
  52. package/types/imports/wasi-cli-stdin.d.ts +5 -0
  53. package/types/imports/wasi-cli-stdout.d.ts +5 -0
  54. package/types/imports/wasi-cli-terminal-input.d.ts +13 -0
  55. package/types/imports/wasi-cli-terminal-output.d.ts +13 -0
  56. package/types/imports/wasi-cli-terminal-stderr.d.ts +9 -0
  57. package/types/imports/wasi-cli-terminal-stdin.d.ts +9 -0
  58. package/types/imports/wasi-cli-terminal-stdout.d.ts +9 -0
  59. package/types/imports/wasi-clocks-monotonic-clock.d.ts +24 -0
  60. package/types/imports/wasi-clocks-timezone.d.ts +71 -0
  61. package/types/imports/wasi-clocks-wall-clock.d.ts +31 -0
  62. package/types/imports/wasi-filesystem-preopens.d.ts +8 -0
  63. package/types/imports/wasi-filesystem-types.d.ts +843 -0
  64. package/types/imports/wasi-http-outgoing-handler.d.ts +9 -0
  65. package/types/imports/wasi-http-types.d.ts +118 -0
  66. package/types/imports/wasi-io-streams.d.ts +220 -0
  67. package/types/imports/wasi-poll-poll.d.ts +39 -0
  68. package/types/imports/wasi-random-insecure-seed.d.ts +22 -0
  69. package/types/imports/{insecure.d.ts → wasi-random-insecure.d.ts} +1 -1
  70. package/types/imports/{random.d.ts → wasi-random-random.d.ts} +1 -1
  71. package/types/imports/wasi-sockets-instance-network.d.ts +8 -0
  72. package/types/imports/wasi-sockets-ip-name-lookup.d.ts +76 -0
  73. package/types/imports/wasi-sockets-network.d.ts +180 -0
  74. package/types/imports/wasi-sockets-tcp-create-socket.d.ts +33 -0
  75. package/types/imports/wasi-sockets-tcp.d.ts +285 -0
  76. package/types/imports/wasi-sockets-udp-create-socket.d.ts +33 -0
  77. package/types/imports/wasi-sockets-udp.d.ts +228 -0
  78. package/types/wasi-cli-command.d.ts +29 -0
  79. package/types/wasi-http-proxy.d.ts +13 -0
  80. package/lib/browser/cli-base.js +0 -48
  81. package/lib/nodejs/cli-base.js +0 -99
  82. package/types/imports/handler.d.ts +0 -40
  83. package/types/imports/outgoing-handler.d.ts +0 -9
  84. package/types/imports/preopens.d.ts +0 -12
  85. package/types/imports/stderr.d.ts +0 -5
  86. package/types/imports/stdin.d.ts +0 -5
  87. package/types/imports/stdout.d.ts +0 -5
  88. package/types/imports/streams.d.ts +0 -180
  89. package/types/wasi-command.d.ts +0 -23
  90. package/types/wasi-proxy.d.ts +0 -10
  91. package/types/wasi-reactor.d.ts +0 -23
@@ -1,18 +1,19 @@
1
1
  // Based on:
2
- // https://github.com/bytecodealliance/wasmtime/blob/76eb40e0756d90cc9c16b26a8d8b1e0ebf75f44d/crates/wasi-http/src/http_impl.rs
2
+ // https://github.com/bytecodealliance/wasmtime/blob/8efcb9851602287fd07a1a1e91501f51f2653d7e/crates/wasi-http/
3
3
 
4
4
  /**
5
- * @typedef {import("../../types/imports/types").Fields} Fields
6
- * @typedef {import("../../types/imports/types").FutureIncomingResponse} FutureIncomingResponse
7
- * @typedef {import("../../types/imports/types").Headers} Headers
8
- * @typedef {import("../../types/imports/types").IncomingResponse} IncomingResponse
9
- * @typedef {import("../../types/imports/types").IncomingStream} IncomingStream
10
- * @typedef {import("../../types/imports/types").Method} Method
11
- * @typedef {import("../../types/imports/types").OutgoingRequest} OutgoingRequest
12
- * @typedef {import("../../types/imports/types").RequestOptions} RequestOptions
13
- * @typedef {import("../../types/imports/types").Result} Result
14
- * @typedef {import("../../types/imports/types").Scheme} Scheme
15
- * @typedef {import("../../types/imports/types").StatusCode} StatusCode
5
+ * @typedef {import("../../types/imports/wasi-http-types").Fields} Fields
6
+ * @typedef {import("../../types/imports/wasi-http-types").FutureIncomingResponse} FutureIncomingResponse
7
+ * @typedef {import("../../types/imports/wasi-http-types").Headers} Headers
8
+ * @typedef {import("../../types/imports/wasi-http-types").IncomingResponse} IncomingResponse
9
+ * @typedef {import("../../types/imports/wasi-http-types").IncomingStream} IncomingStream
10
+ * @typedef {import("../../types/imports/wasi-http-types").Method} Method
11
+ * @typedef {import("../../types/imports/wasi-http-types").OutgoingRequest} OutgoingRequest
12
+ * @typedef {import("../../types/imports/wasi-http-types").RequestOptions} RequestOptions
13
+ * @typedef {import("../../types/imports/wasi-http-types").Result} Result
14
+ * @typedef {import("../../types/imports/wasi-http-types").Scheme} Scheme
15
+ * @typedef {import("../../types/imports/wasi-http-types").StatusCode} StatusCode
16
+ * @typedef {import("../../types/imports/wasi-io-streams").StreamStatus} StreamStatus
16
17
  */
17
18
 
18
19
  import * as io from '@bytecodealliance/preview2-shim/io';
@@ -48,12 +49,14 @@ export class WasiHttp {
48
49
 
49
50
  const scheme = request.scheme.tag === "HTTP" ? "http://" : "https://";
50
51
 
51
- const url = scheme + request.authority + request.path + request.query;
52
+ const url = scheme + request.authority + request.pathWithQuery;
52
53
  const headers = {
53
54
  "host": request.authority,
54
55
  };
55
- for (const [key, value] of request.headers.entries()) {
56
- headers[key] = Array.isArray(value) ? value.join(",") : value;
56
+ if (request.headers && request.headers.size > 0) {
57
+ for (const [key, value] of request.headers.entries()) {
58
+ headers[key] = Array.isArray(value) ? value.join(",") : value;
59
+ }
57
60
  }
58
61
  const body = this.streams.get(request.body);
59
62
 
@@ -66,8 +69,10 @@ export class WasiHttp {
66
69
  });
67
70
 
68
71
  response.status = res.status;
69
- for (const [key, value] of res.headers) {
70
- response.responseHeaders.set(key, [value]);
72
+ if (res.headers && res.headers.size > 0) {
73
+ for (const [key, value] of res.headers) {
74
+ response.responseHeaders.set(key, [value]);
75
+ }
71
76
  }
72
77
  const buf = res.body;
73
78
  response.body = this.streamIdBase;
@@ -82,25 +87,29 @@ export class WasiHttp {
82
87
  return futureId;
83
88
  }
84
89
 
90
+ read = (stream, len) => {
91
+ return this.blockingRead(stream, len);
92
+ }
93
+
85
94
  /**
86
95
  * @param {InputStream} stream
87
96
  * @param {bigint} len
88
- * @returns {[Uint8Array | ArrayBuffer, boolean]}
97
+ * @returns {[Uint8Array | ArrayBuffer, StreamStatus]}
89
98
  */
90
- read = (stream, len) => {
99
+ blockingRead = (stream, len) => {
91
100
  if (stream < 3) {
92
- return io.read(stream);
101
+ return io.streams.blockingRead(stream);
93
102
  }
94
103
  const s = this.streams.get(stream);
95
104
  if (!s) throw Error(`stream not found: ${stream}`);
96
105
  const position = Number(len);
97
106
  if (position === 0) {
98
- return [new Uint8Array(), s.byteLength > 0];
107
+ return [new Uint8Array(), s.byteLength > 0 ? 'open' : 'ended'];
99
108
  } else if (s.byteLength > position) {
100
109
  this.streams.set(stream, s.slice(position, s.byteLength));
101
- return [s.slice(0, position), false];
110
+ return [s.slice(0, position), 'open'];
102
111
  } else {
103
- return [s.slice(0, position), true];
112
+ return [s.slice(0, position), 'ended'];
104
113
  }
105
114
  }
106
115
 
@@ -108,8 +117,9 @@ export class WasiHttp {
108
117
  * @param {InputStream} stream
109
118
  * @returns {Pollable}
110
119
  */
111
- subscribeToInputStream = (_stream) => {
112
- throw Error("unimplemented: subscribeToInputStream");
120
+ subscribeToInputStream = (stream) => {
121
+ // TODO: not implemented yet
122
+ console.log(`[streams] Subscribe to input stream ${stream}`);
113
123
  }
114
124
 
115
125
  /**
@@ -121,25 +131,30 @@ export class WasiHttp {
121
131
  s.set([]);
122
132
  }
123
133
 
134
+ write = (stream, buf) => {
135
+ return this.blockingWrite(stream, buf);
136
+ }
137
+
124
138
  /**
125
139
  * @param {OutputStream} stream
126
140
  * @param {Uint8Array} buf
127
- * @returns {bigint}
141
+ * @returns {[bigint, StreamStatus]}
128
142
  */
129
- write = (stream, buf) => {
143
+ blockingWrite = (stream, buf) => {
130
144
  if (stream < 3) {
131
- return io.write(stream, buf);
145
+ return io.streams.blockingWrite(stream, buf);
132
146
  }
133
147
  this.streams.set(stream, buf);
134
- return BigInt(buf.byteLength);
148
+ return [BigInt(buf.byteLength), 'ended'];
135
149
  }
136
150
 
137
151
  /**
138
152
  * @param {OutputStream} stream
139
153
  * @returns {Pollable}
140
154
  */
141
- subscribeToOutputStream = (_stream) => {
142
- throw Error("unimplemented: subscribeToOutputStream");
155
+ subscribeToOutputStream = (stream) => {
156
+ // TODO: not implemented yet
157
+ console.log(`[streams] Subscribe to output stream ${stream}`);
143
158
  }
144
159
 
145
160
  /**
@@ -189,20 +204,18 @@ export class WasiHttp {
189
204
 
190
205
  /**
191
206
  * @param {Method} method
192
- * @param {string} path
193
- * @param {string} query
207
+ * @param {string | null} pathWithQuery
194
208
  * @param {Scheme | null} scheme
195
- * @param {string} authority
209
+ * @param {string | null} authority
196
210
  * @param {Headers} headers
197
211
  * @returns {number}
198
212
  */
199
- newOutgoingRequest = (method, path, query, scheme, authority, headers) => {
213
+ newOutgoingRequest = (method, pathWithQuery, scheme, authority, headers) => {
200
214
  const id = this.requestIdBase;
201
215
  this.requestIdBase += 1;
202
216
 
203
217
  const req = new ActiveRequest(id);
204
- req.path = path;
205
- req.query = query;
218
+ req.pathWithQuery = pathWithQuery;
206
219
  req.authority = authority;
207
220
  req.method = method;
208
221
  req.headers = this.fields.get(headers);
@@ -301,9 +314,8 @@ class ActiveRequest {
301
314
  activeRequest = false;
302
315
  /** @type {Method} */ method = { tag: 'get' };
303
316
  /** @type {Scheme | null} */ scheme = { tag: 'HTTP' };
304
- path = "";
305
- query = "";
306
- authority = "";
317
+ pathWithQuery = null;
318
+ authority = null;
307
319
  /** @type {Map<string,string[]>} */ headers = new Map();
308
320
  body = 3;
309
321
 
@@ -0,0 +1,75 @@
1
+ let _env, _args = [], _cwd = null;
2
+ export function _setEnv (envObj) {
3
+ _env = Object.entries(envObj);
4
+ }
5
+
6
+ export function _setArgs (args) {
7
+ _args = args;
8
+ }
9
+
10
+ export function _setCwd (cwd) {
11
+ _cwd = cwd;
12
+ }
13
+
14
+ export const environment = {
15
+ getEnvironment () {
16
+ if (!_env) _setEnv(process.env);
17
+ return _env;
18
+ },
19
+ getArguments () {
20
+ return _args;
21
+ },
22
+ initialCwd () {
23
+ return _cwd;
24
+ }
25
+ };
26
+
27
+ export const exit = {
28
+ exit (status) {
29
+ process.exit(status.tag === 'err' ? 1 : 0);
30
+ }
31
+ };
32
+
33
+ export const stdin = {
34
+ getStdin () {
35
+ return 0;
36
+ }
37
+ };
38
+
39
+ export const stdout = {
40
+ getStdout () {
41
+ return 1;
42
+ }
43
+ };
44
+
45
+ export const stderr = {
46
+ getStderr () {
47
+ return 2;
48
+ }
49
+ };
50
+
51
+ export const terminalInput = {
52
+ dropTerminalInput () {}
53
+ };
54
+
55
+ export const terminalOutput = {
56
+ dropTerminalOutput () {}
57
+ };
58
+
59
+ export const terminalStderr = {
60
+ getTerminalStderr () {
61
+ return 0;
62
+ }
63
+ };
64
+
65
+ export const terminalStdin = {
66
+ getTerminalStdin () {
67
+ return 1;
68
+ }
69
+ };
70
+
71
+ export const terminalStdout = {
72
+ getTerminalStdout () {
73
+ return 2;
74
+ }
75
+ };
@@ -1,7 +1,70 @@
1
1
  import { openSync, constants, statSync, lstatSync, fstatSync, closeSync, readdirSync } from 'node:fs';
2
- import { _descriptors, _addOpenedDescriptor, _removeOpenedDescriptor, _getDescriptorType, _setSubdescriptorType, _setDescriptorType, _getFullPath } from './cli-base.js';
3
2
  import { _createFsStream, _dropFsStream, _getFsStreamContext } from './io.js';
4
3
 
4
+ // default is full permissions
5
+ let preopenCnt = 4;
6
+ export let _descriptors = {
7
+ 3: { type: 'directory', path: '/', parent: null, subpathTypes: {} }
8
+ };
9
+ let directories = [[3, '/']];
10
+
11
+ export function _setPreopens (preopens) {
12
+ _descriptors = {};
13
+ directories = [,,];
14
+ for (const [virtualPath, path] of Object.entries(preopens)) {
15
+ _descriptors[preopenCnt] = { type: 'directory', path, parent: null, subpathTypes: {} };
16
+ directories.push([preopenCnt++, virtualPath]);
17
+ }
18
+ }
19
+
20
+ export function _getFullPath (fd) {
21
+ let path = '';
22
+ while (fd) {
23
+ path = _descriptors[fd].path + path;
24
+ fd = _descriptors[fd].parent;
25
+ }
26
+ return path;
27
+ }
28
+
29
+ export function _getDescriptorType (fd) {
30
+ return _descriptors[fd].type;
31
+ }
32
+
33
+ export function _setDescriptorType (fd, type) {
34
+ _descriptors[fd].type = type;
35
+ }
36
+
37
+ export function _setSubdescriptorType (fd, path, type) {
38
+ while (_descriptors[fd].parent) {
39
+ path = _descriptors[fd].path + path;
40
+ fd = _descriptors[fd].parent;
41
+ }
42
+ _descriptors[fd].subpathTypes[path] = type;
43
+ }
44
+
45
+ export function _addOpenedDescriptor (fd, path, parentFd) {
46
+ if (fd < preopenCnt || _descriptors[fd])
47
+ throw 'bad-descriptor';
48
+ let type = null;
49
+ for (const [_path, _type] of Object.entries(_descriptors[parentFd].subpathTypes)) {
50
+ if (_path === path)
51
+ type = _type;
52
+ }
53
+ _descriptors[fd] = { path, type, parent: parentFd, subpathTypes: {} };
54
+ }
55
+
56
+ export function _removeOpenedDescriptor (fd) {
57
+ if (fd < preopenCnt)
58
+ throw 'eperm';
59
+ delete _descriptors[fd];
60
+ }
61
+
62
+ export const preopens = {
63
+ getDirectories () {
64
+ return directories;
65
+ }
66
+ }
67
+
5
68
  const nsMagnitude = 1_000_000_000_000n;
6
69
  function nsToDateTime (ns) {
7
70
  const seconds = ns / nsMagnitude;
@@ -71,7 +134,7 @@ function _lookupType (obj) {
71
134
  return 'unknown';
72
135
  }
73
136
 
74
- export const filesystem = {
137
+ export const types = {
75
138
  readViaStream(fd, offset) {
76
139
  if (Number(offset) !== 0)
77
140
  throw new Error('Read streams with non-zero offset not currently supported');
@@ -102,7 +165,7 @@ export const filesystem = {
102
165
  getType(fd) {
103
166
  let type = _getDescriptorType(fd);
104
167
  if (type === null) {
105
- filesystem.stat(fd);
168
+ types.stat(fd);
106
169
  type = _getDescriptorType(fd);
107
170
  }
108
171
  return type;
@@ -307,5 +370,32 @@ export const filesystem = {
307
370
 
308
371
  dropDirectoryEntryStream(stream) {
309
372
  _dropFsStream(stream);
373
+ },
374
+
375
+ metadataHash(fd) {
376
+ let stats;
377
+ try {
378
+ stats = fstatSync(fd, { bigint: true });
379
+ }
380
+ catch (e) {
381
+ _convertFsError(e);
382
+ }
383
+ const type = _lookupType(stats);
384
+ _setDescriptorType(fd, type);
385
+ return { upper: BigInt(stats.size), lower: stats.mtimeNs };
386
+ },
387
+
388
+ metadataHashAt(fd, { symlinkFollow }, path) {
389
+ const fullPath = _descriptors[fd].path + path;
390
+ let stats;
391
+ try {
392
+ stats = (symlinkFollow ? statSync : lstatSync)(fullPath, { bigint: true });
393
+ }
394
+ catch (e) {
395
+ _convertFsError(e);
396
+ }
397
+ const type = _lookupType(stats);
398
+ _setSubdescriptorType(fd, path, type);
399
+ return { upper: BigInt(stats.size), lower: stats.mtimeNs };
310
400
  }
311
401
  };
@@ -15,7 +15,7 @@ export function send(req) {
15
15
  body: response.body ? Buffer.from(response.body, "base64") : undefined,
16
16
  };
17
17
  }
18
- throw new UnexpectedError(response);
18
+ throw new UnexpectedError(response.message);
19
19
  }
20
20
 
21
21
  export const incomingHandler = {
@@ -70,11 +70,8 @@ export const types = {
70
70
  incomingRequestMethod(_req) {
71
71
  console.log("[types] Incoming request method");
72
72
  },
73
- incomingRequestPath(_req) {
74
- console.log("[types] Incoming request path");
75
- },
76
- incomingRequestQuery(_req) {
77
- console.log("[types] Incoming request query");
73
+ incomingRequestPathWithQuery(_req) {
74
+ console.log("[types] Incoming request path with query");
78
75
  },
79
76
  incomingRequestScheme(_req) {
80
77
  console.log("[types] Incoming request scheme");
@@ -88,7 +85,7 @@ export const types = {
88
85
  incomingRequestConsume(_req) {
89
86
  console.log("[types] Incoming request consume");
90
87
  },
91
- newOutgoingRequest(_method, _path, _query, _scheme, _authority, _headers) {
88
+ newOutgoingRequest(_method, _pathWithQuery, _scheme, _authority, _headers) {
92
89
  console.log("[types] New outgoing request");
93
90
  },
94
91
  outgoingRequestWrite(_req) {
@@ -6,7 +6,7 @@ import * as logging from "./logging.js";
6
6
  import * as poll from "./poll.js";
7
7
  import * as random from "./random.js";
8
8
  import * as sockets from "./sockets.js";
9
- import * as cliBase from "./cli-base.js";
9
+ import * as cli from "./cli.js";
10
10
 
11
11
  export const importObject = {
12
12
  clocks,
@@ -17,7 +17,7 @@ export const importObject = {
17
17
  poll,
18
18
  random,
19
19
  sockets,
20
- cliBase,
20
+ cli,
21
21
  };
22
22
 
23
23
  export { WasiHttp } from "../http/wasi-http.js";
@@ -1,8 +1,8 @@
1
- const levels = ["trace", "debug", "info", "warn", "error"];
1
+ const levels = ["trace", "debug", "info", "warn", "error", "critical"];
2
2
 
3
3
  let logLevel = levels.indexOf("warn");
4
4
 
5
- export const handler = {
5
+ export const logging = {
6
6
  log(level, context, msg) {
7
7
  if (logLevel > levels.indexOf(level)) return;
8
8
  process.stdout.write(`${level}: (${context}) ${msg}\n`);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bytecodealliance/preview2-shim",
3
- "version": "0.0.12",
3
+ "version": "0.0.14",
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 ImportsEnvironment {
1
+ export namespace WasiCliEnvironment {
2
2
  /**
3
3
  * Get the POSIX-style environment variables.
4
4
  *
@@ -14,4 +14,9 @@ export namespace ImportsEnvironment {
14
14
  * Get the POSIX-style arguments to the program.
15
15
  */
16
16
  export function getArguments(): string[];
17
+ /**
18
+ * Return a path that programs should use as their initial current working
19
+ * directory, interpreting `.` as shorthand for this.
20
+ */
21
+ export function initialCwd(): string | null;
17
22
  }
@@ -1,6 +1,6 @@
1
- export namespace ImportsExit {
1
+ export namespace WasiCliExit {
2
2
  /**
3
- * Exit the curerent instance and any linked instances.
3
+ * Exit the current instance and any linked instances.
4
4
  */
5
5
  export function exit(status: Result<void, void>): void;
6
6
  }
@@ -0,0 +1,6 @@
1
+ export namespace WasiCliRun {
2
+ /**
3
+ * Run the program.
4
+ */
5
+ export function run(): void;
6
+ }
@@ -0,0 +1,5 @@
1
+ export namespace WasiCliStderr {
2
+ export function getStderr(): OutputStream;
3
+ }
4
+ import type { OutputStream } from '../exports/wasi-io-streams';
5
+ export { OutputStream };
@@ -0,0 +1,5 @@
1
+ export namespace WasiCliStdin {
2
+ export function getStdin(): InputStream;
3
+ }
4
+ import type { InputStream } from '../exports/wasi-io-streams';
5
+ export { InputStream };
@@ -0,0 +1,5 @@
1
+ export namespace WasiCliStdout {
2
+ export function getStdout(): OutputStream;
3
+ }
4
+ import type { OutputStream } from '../exports/wasi-io-streams';
5
+ export { OutputStream };
@@ -0,0 +1,13 @@
1
+ export namespace WasiCliTerminalInput {
2
+ /**
3
+ * Dispose of the specified terminal-input after which it may no longer
4
+ * be used.
5
+ */
6
+ export function dropTerminalInput(this_: TerminalInput): void;
7
+ }
8
+ /**
9
+ * The input side of a terminal.
10
+ *
11
+ * This [represents a resource](https://github.com/WebAssembly/WASI/blob/main/docs/WitInWasi.md#Resources).
12
+ */
13
+ export type TerminalInput = number;
@@ -0,0 +1,13 @@
1
+ export namespace WasiCliTerminalOutput {
2
+ /**
3
+ * Dispose of the specified terminal-output, after which it may no longer
4
+ * be used.
5
+ */
6
+ export function dropTerminalOutput(this_: TerminalOutput): void;
7
+ }
8
+ /**
9
+ * The output side of a terminal.
10
+ *
11
+ * This [represents a resource](https://github.com/WebAssembly/WASI/blob/main/docs/WitInWasi.md#Resources).
12
+ */
13
+ export type TerminalOutput = number;
@@ -0,0 +1,9 @@
1
+ export namespace WasiCliTerminalStderr {
2
+ /**
3
+ * If stderr is connected to a terminal, return a `terminal-output` handle
4
+ * allowing further interaction with it.
5
+ */
6
+ export function getTerminalStderr(): TerminalOutput | null;
7
+ }
8
+ import type { TerminalOutput } from '../exports/wasi-cli-terminal-output';
9
+ export { TerminalOutput };
@@ -0,0 +1,9 @@
1
+ export namespace WasiCliTerminalStdin {
2
+ /**
3
+ * If stdin is connected to a terminal, return a `terminal-input` handle
4
+ * allowing further interaction with it.
5
+ */
6
+ export function getTerminalStdin(): TerminalInput | null;
7
+ }
8
+ import type { TerminalInput } from '../exports/wasi-cli-terminal-input';
9
+ export { TerminalInput };
@@ -0,0 +1,9 @@
1
+ export namespace WasiCliTerminalStdout {
2
+ /**
3
+ * If stdout is connected to a terminal, return a `terminal-output` handle
4
+ * allowing further interaction with it.
5
+ */
6
+ export function getTerminalStdout(): TerminalOutput | null;
7
+ }
8
+ import type { TerminalOutput } from '../exports/wasi-cli-terminal-output';
9
+ export { TerminalOutput };
@@ -1,4 +1,4 @@
1
- export namespace ImportsMonotonicClock {
1
+ export namespace WasiClocksMonotonicClock {
2
2
  /**
3
3
  * Read the current value of the clock.
4
4
  *
@@ -16,7 +16,7 @@ export namespace ImportsMonotonicClock {
16
16
  */
17
17
  export function subscribe(when: Instant, absolute: boolean): Pollable;
18
18
  }
19
- import type { Pollable } from '../imports/poll';
19
+ import type { Pollable } from '../exports/wasi-poll-poll';
20
20
  export { Pollable };
21
21
  /**
22
22
  * A timestamp in nanoseconds.
@@ -1,4 +1,4 @@
1
- export namespace ImportsTimezone {
1
+ export namespace WasiClocksTimezone {
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
@@ -8,19 +8,29 @@ export namespace ImportsTimezone {
8
8
  * `timezone-display` for `UTC` with a `utc-offset` of 0 and no daylight
9
9
  * saving time.
10
10
  */
11
- export function display(this: Timezone, when: Datetime): TimezoneDisplay;
11
+ export function display(this_: Timezone, when: Datetime): TimezoneDisplay;
12
12
  /**
13
13
  * The same as `display`, but only return the UTC offset.
14
14
  */
15
- export function utcOffset(this: Timezone, when: Datetime): number;
15
+ export function utcOffset(this_: Timezone, when: Datetime): number;
16
16
  /**
17
17
  * Dispose of the specified input-stream, after which it may no longer
18
18
  * be used.
19
19
  */
20
- export function dropTimezone(this: Timezone): void;
20
+ export function dropTimezone(this_: Timezone): void;
21
21
  }
22
- import type { Datetime } from '../imports/wall-clock';
22
+ import type { Datetime } from '../exports/wasi-clocks-wall-clock';
23
23
  export { Datetime };
24
+ /**
25
+ * A timezone.
26
+ *
27
+ * In timezones that recognize daylight saving time, also known as daylight
28
+ * time and summer time, the information returned from the functions varies
29
+ * over time to reflect these adjustments.
30
+ *
31
+ * This [represents a resource](https://github.com/WebAssembly/WASI/blob/main/docs/WitInWasi.md#Resources).
32
+ */
33
+ export type Timezone = number;
24
34
  /**
25
35
  * Information useful for displaying the timezone of a specific `datetime`.
26
36
  *
@@ -59,13 +69,3 @@ export interface TimezoneDisplay {
59
69
  */
60
70
  inDaylightSavingTime: boolean,
61
71
  }
62
- /**
63
- * A timezone.
64
- *
65
- * In timezones that recognize daylight saving time, also known as daylight
66
- * time and summer time, the information returned from the functions varies
67
- * over time to reflect these adjustments.
68
- *
69
- * This [represents a resource](https://github.com/WebAssembly/WASI/blob/main/docs/WitInWasi.md#Resources).
70
- */
71
- export type Timezone = number;
@@ -1,4 +1,4 @@
1
- export namespace ImportsWallClock {
1
+ export namespace WasiClocksWallClock {
2
2
  /**
3
3
  * Read the current value of the clock.
4
4
  *
@@ -0,0 +1,8 @@
1
+ export namespace WasiFilesystemPreopens {
2
+ /**
3
+ * Return the set of preopened directories, and their path.
4
+ */
5
+ export function getDirectories(): [Descriptor, string][];
6
+ }
7
+ import type { Descriptor } from '../exports/wasi-filesystem-types';
8
+ export { Descriptor };