@bytecodealliance/preview2-shim 0.0.13 → 0.0.15

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 (44) hide show
  1. package/README.md +2 -2
  2. package/lib/browser/cli.js +21 -6
  3. package/lib/browser/filesystem.js +204 -20
  4. package/lib/browser/http.js +4 -7
  5. package/lib/browser/io.js +89 -19
  6. package/lib/browser/logging.js +2 -2
  7. package/lib/browser/poll.js +48 -4
  8. package/lib/http/error.js +1 -1
  9. package/lib/http/make-request.js +4 -3
  10. package/lib/http/wasi-http.js +88 -53
  11. package/lib/nodejs/cli.js +17 -7
  12. package/lib/nodejs/http.js +4 -7
  13. package/lib/nodejs/io.js +16 -5
  14. package/lib/nodejs/logging.js +2 -2
  15. package/package.json +4 -1
  16. package/types/interfaces/wasi-cli-environment.d.ts +22 -0
  17. package/types/interfaces/wasi-cli-exit.d.ts +7 -0
  18. package/types/interfaces/wasi-cli-run.d.ts +6 -0
  19. package/types/interfaces/wasi-cli-stderr.d.ts +5 -0
  20. package/types/interfaces/wasi-cli-stdin.d.ts +5 -0
  21. package/types/interfaces/wasi-cli-stdout.d.ts +5 -0
  22. package/types/interfaces/wasi-cli-terminal-input.d.ts +13 -0
  23. package/types/interfaces/wasi-cli-terminal-output.d.ts +13 -0
  24. package/types/interfaces/wasi-cli-terminal-stderr.d.ts +9 -0
  25. package/types/interfaces/wasi-cli-terminal-stdin.d.ts +9 -0
  26. package/types/interfaces/wasi-cli-terminal-stdout.d.ts +9 -0
  27. package/types/interfaces/wasi-clocks-monotonic-clock.d.ts +24 -0
  28. package/types/interfaces/wasi-clocks-timezone.d.ts +71 -0
  29. package/types/interfaces/wasi-clocks-wall-clock.d.ts +31 -0
  30. package/types/interfaces/wasi-filesystem-preopens.d.ts +8 -0
  31. package/types/interfaces/wasi-filesystem-types.d.ts +843 -0
  32. package/types/interfaces/wasi-io-streams.d.ts +274 -0
  33. package/types/interfaces/wasi-poll-poll.d.ts +39 -0
  34. package/types/interfaces/wasi-random-insecure-seed.d.ts +22 -0
  35. package/types/interfaces/wasi-random-insecure.d.ts +20 -0
  36. package/types/interfaces/wasi-random-random.d.ts +22 -0
  37. package/types/interfaces/wasi-sockets-instance-network.d.ts +8 -0
  38. package/types/interfaces/wasi-sockets-ip-name-lookup.d.ts +76 -0
  39. package/types/interfaces/wasi-sockets-network.d.ts +180 -0
  40. package/types/interfaces/wasi-sockets-tcp-create-socket.d.ts +33 -0
  41. package/types/interfaces/wasi-sockets-tcp.d.ts +298 -0
  42. package/types/interfaces/wasi-sockets-udp-create-socket.d.ts +33 -0
  43. package/types/interfaces/wasi-sockets-udp.d.ts +228 -0
  44. package/types/wasi-cli-command.d.ts +29 -0
@@ -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/interfaces/wasi-http-types").Fields} Fields
6
+ * @typedef {import("../../types/interfaces/wasi-http-types").FutureIncomingResponse} FutureIncomingResponse
7
+ * @typedef {import("../../types/interfaces/wasi-http-types").Headers} Headers
8
+ * @typedef {import("../../types/interfaces/wasi-http-types").IncomingResponse} IncomingResponse
9
+ * @typedef {import("../../types/interfaces/wasi-http-types").IncomingStream} IncomingStream
10
+ * @typedef {import("../../types/interfaces/wasi-http-types").Method} Method
11
+ * @typedef {import("../../types/interfaces/wasi-http-types").OutgoingRequest} OutgoingRequest
12
+ * @typedef {import("../../types/interfaces/wasi-http-types").RequestOptions} RequestOptions
13
+ * @typedef {import("../../types/interfaces/wasi-http-types").Result} Result
14
+ * @typedef {import("../../types/interfaces/wasi-http-types").Scheme} Scheme
15
+ * @typedef {import("../../types/interfaces/wasi-http-types").StatusCode} StatusCode
16
+ * @typedef {import("../../types/interfaces/wasi-io-streams").StreamStatus} StreamStatus
16
17
  */
17
18
 
18
19
  import * as io from '@bytecodealliance/preview2-shim/io';
@@ -27,7 +28,7 @@ export class WasiHttp {
27
28
  futureIdBase = 1;
28
29
  /** @type {Map<number,ActiveRequest>} */ requests = new Map();
29
30
  /** @type {Map<number,ActiveResponse>} */ responses = new Map();
30
- /** @type {Map<number,Map<string,string[]>>} */ fields = new Map();
31
+ /** @type {Map<number,ActiveFields>} */ fields = new Map();
31
32
  /** @type {Map<number,Uint8Array>} */ streams = new Map();
32
33
  /** @type {Map<number,ActiveFuture>} */ futures = new Map();
33
34
 
@@ -48,12 +49,16 @@ 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) {
57
+ const requestHeaders = this.fields.get(request.headers);
58
+ const decoder = new TextDecoder();
59
+ for (const [key, value] of requestHeaders.fields.entries()) {
60
+ headers[key] = decoder.decode(value);
61
+ }
57
62
  }
58
63
  const body = this.streams.get(request.body);
59
64
 
@@ -66,8 +71,8 @@ export class WasiHttp {
66
71
  });
67
72
 
68
73
  response.status = res.status;
69
- for (const [key, value] of res.headers) {
70
- response.responseHeaders.set(key, [value]);
74
+ if (res.headers && res.headers.length > 0) {
75
+ response.headers = this.newFields(res.headers);
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,47 @@ export class WasiHttp {
121
131
  s.set([]);
122
132
  }
123
133
 
134
+ checkWrite = (stream) => {
135
+ // TODO: implement
136
+ return io.streams.checkWrite(stream);
137
+ }
138
+
124
139
  /**
125
140
  * @param {OutputStream} stream
126
141
  * @param {Uint8Array} buf
127
- * @returns {bigint}
128
142
  */
129
143
  write = (stream, buf) => {
130
144
  if (stream < 3) {
131
- return io.write(stream, buf);
145
+ return io.streams.write(stream, buf);
132
146
  }
133
147
  this.streams.set(stream, buf);
134
- return BigInt(buf.byteLength);
148
+ }
149
+
150
+ blockingWriteAndFlush = (stream, buf) => {
151
+ if (stream < 3) {
152
+ return io.streams.blockingWriteAndFlush(stream, buf);
153
+ }
154
+ // TODO: implement
155
+ }
156
+
157
+ flush = (stream) => {
158
+ return this.blockingFlush(stream);
159
+ }
160
+
161
+ blockingFlush = (stream) => {
162
+ if (stream < 3) {
163
+ return io.streams.blockingFlush(stream);
164
+ }
165
+ // TODO: implement
135
166
  }
136
167
 
137
168
  /**
138
169
  * @param {OutputStream} stream
139
170
  * @returns {Pollable}
140
171
  */
141
- subscribeToOutputStream = (_stream) => {
142
- throw Error("unimplemented: subscribeToOutputStream");
172
+ subscribeToOutputStream = (stream) => {
173
+ // TODO: not implemented yet
174
+ console.log(`[streams] Subscribe to output stream ${stream}`);
143
175
  }
144
176
 
145
177
  /**
@@ -163,21 +195,20 @@ export class WasiHttp {
163
195
  * @returns {Fields}
164
196
  */
165
197
  newFields = (entries) => {
166
- const map = new Map(entries);
167
-
168
198
  const id = this.fieldsIdBase;
169
199
  this.fieldsIdBase += 1;
170
- this.fields.set(id, map);
200
+ this.fields.set(id, new ActiveFields(id, entries));
171
201
 
172
202
  return id;
173
203
  }
174
204
 
175
205
  /**
176
206
  * @param {Fields} fields
177
- * @returns {[string, string][]}
207
+ * @returns {[string, Uint8Array][]}
178
208
  */
179
209
  fieldsEntries = (fields) => {
180
- return this.fields.get(fields) ?? [];
210
+ const activeFields = this.fields.get(fields);
211
+ return activeFields ? Array.from(activeFields.fields) : [];
181
212
  }
182
213
 
183
214
  /**
@@ -189,23 +220,21 @@ export class WasiHttp {
189
220
 
190
221
  /**
191
222
  * @param {Method} method
192
- * @param {string} path
193
- * @param {string} query
223
+ * @param {string | null} pathWithQuery
194
224
  * @param {Scheme | null} scheme
195
- * @param {string} authority
225
+ * @param {string | null} authority
196
226
  * @param {Headers} headers
197
227
  * @returns {number}
198
228
  */
199
- newOutgoingRequest = (method, path, query, scheme, authority, headers) => {
229
+ newOutgoingRequest = (method, pathWithQuery, scheme, authority, headers) => {
200
230
  const id = this.requestIdBase;
201
231
  this.requestIdBase += 1;
202
232
 
203
233
  const req = new ActiveRequest(id);
204
- req.path = path;
205
- req.query = query;
234
+ req.pathWithQuery = pathWithQuery;
206
235
  req.authority = authority;
207
236
  req.method = method;
208
- req.headers = this.fields.get(headers);
237
+ req.headers = headers;
209
238
  req.scheme = scheme;
210
239
  this.requests.set(id, req);
211
240
  return id;
@@ -244,11 +273,7 @@ export class WasiHttp {
244
273
  */
245
274
  incomingResponseHeaders = (response) => {
246
275
  const r = this.responses.get(response);
247
- const id = this.fieldsIdBase;
248
- this.fieldsIdBase += 1;
249
-
250
- this.fields.set(id, r.responseHeaders);
251
- return id;
276
+ return r.headers ?? 0;
252
277
  }
253
278
 
254
279
  /**
@@ -301,10 +326,9 @@ class ActiveRequest {
301
326
  activeRequest = false;
302
327
  /** @type {Method} */ method = { tag: 'get' };
303
328
  /** @type {Scheme | null} */ scheme = { tag: 'HTTP' };
304
- path = "";
305
- query = "";
306
- authority = "";
307
- /** @type {Map<string,string[]>} */ headers = new Map();
329
+ pathWithQuery = null;
330
+ authority = null;
331
+ /** @type {number | null} */ headers = null;
308
332
  body = 3;
309
333
 
310
334
  constructor(id) {
@@ -317,7 +341,7 @@ class ActiveResponse {
317
341
  activeResponse = false;
318
342
  status = 0;
319
343
  body = 3;
320
- /** @type {Map<string,string[]>} */ responseHeaders = new Map();
344
+ /** @type {number | null} */ headers = null;
321
345
 
322
346
  constructor(id) {
323
347
  this.id = id;
@@ -333,3 +357,14 @@ class ActiveFuture {
333
357
  this.responseId = responseId;
334
358
  }
335
359
  }
360
+
361
+ class ActiveFields {
362
+ /** @type {number} */ id;
363
+ /** @type {Map<string, Uint8Array[]>} */ fields;
364
+
365
+ constructor(id, fields) {
366
+ this.id = id;
367
+ const encoder = new TextEncoder();
368
+ this.fields = new Map(fields.map(([k, v]) => [k, encoder.encode(v)]));
369
+ }
370
+ }
package/lib/nodejs/cli.js CHANGED
@@ -1,12 +1,26 @@
1
- let _env;
1
+ let _env, _args = [], _cwd = null;
2
2
  export function _setEnv (envObj) {
3
3
  _env = Object.entries(envObj);
4
4
  }
5
5
 
6
+ export function _setArgs (args) {
7
+ _args = args;
8
+ }
9
+
10
+ export function _setCwd (cwd) {
11
+ _cwd = cwd;
12
+ }
13
+
6
14
  export const environment = {
7
15
  getEnvironment () {
8
16
  if (!_env) _setEnv(process.env);
9
17
  return _env;
18
+ },
19
+ getArguments () {
20
+ return _args;
21
+ },
22
+ initialCwd () {
23
+ return _cwd;
10
24
  }
11
25
  };
12
26
 
@@ -35,15 +49,11 @@ export const stderr = {
35
49
  };
36
50
 
37
51
  export const terminalInput = {
38
- dropTerminalInput () {
39
-
40
- }
52
+ dropTerminalInput () {}
41
53
  };
42
54
 
43
55
  export const terminalOutput = {
44
- dropTerminalOutput () {
45
-
46
- }
56
+ dropTerminalOutput () {}
47
57
  };
48
58
 
49
59
  export const terminalStderr = {
@@ -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) {
package/lib/nodejs/io.js CHANGED
@@ -106,25 +106,36 @@ export const streams = {
106
106
  dropInputStream(s) {
107
107
  delete _streams[s];
108
108
  },
109
- write(s, buf) {
110
- return streams.blockingWrite(s, buf);
109
+ checkWrite(_s) {
110
+ // TODO: implement
111
+ return 1000000n;
111
112
  },
112
- blockingWrite(s, buf) {
113
+ write(s, buf) {
113
114
  switch (s) {
114
115
  case 0:
115
116
  throw new Error(`TODO: write stdin`);
116
117
  case 1: {
117
118
  process.stdout.write(buf);
118
- return [BigInt(buf.byteLength), 'ended'];
119
+ break;
119
120
  }
120
121
  case 2: {
121
122
  process.stderr.write(buf);
122
- return [BigInt(buf.byteLength), 'ended'];
123
+ break;
123
124
  }
124
125
  default:
125
126
  throw new Error(`TODO: write ${s}`);
126
127
  }
127
128
  },
129
+ blockingWriteAndFlush(s, buf) {
130
+ // TODO: implement
131
+ return streams.write(s, buf);
132
+ },
133
+ flush(s) {
134
+ return streams.blockingFlush(s);
135
+ },
136
+ blockingFlush(_s) {
137
+ // TODO: implement
138
+ },
128
139
  writeZeroes(s, _len) {
129
140
  console.log(`[streams] Write zeroes ${s}`);
130
141
  },
@@ -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,8 +1,11 @@
1
1
  {
2
2
  "name": "@bytecodealliance/preview2-shim",
3
- "version": "0.0.13",
3
+ "version": "0.0.15",
4
4
  "description": "WASI Preview2 shim for JS environments",
5
5
  "author": "Guy Bedford, Eduardo Rodrigues<16357187+eduardomourar@users.noreply.github.com>",
6
+ "engines" : {
7
+ "node" : ">=18"
8
+ },
6
9
  "type": "module",
7
10
  "types": "./types/index.d.ts",
8
11
  "exports": {
@@ -0,0 +1,22 @@
1
+ export namespace WasiCliEnvironment {
2
+ /**
3
+ * Get the POSIX-style environment variables.
4
+ *
5
+ * Each environment variable is provided as a pair of string variable names
6
+ * and string value.
7
+ *
8
+ * Morally, these are a value import, but until value imports are available
9
+ * in the component model, this import function should return the same
10
+ * values each time it is called.
11
+ */
12
+ export function getEnvironment(): [string, string][];
13
+ /**
14
+ * Get the POSIX-style arguments to the program.
15
+ */
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 | undefined;
22
+ }
@@ -0,0 +1,7 @@
1
+ export namespace WasiCliExit {
2
+ /**
3
+ * Exit the current instance and any linked instances.
4
+ */
5
+ export function exit(status: Result<void, void>): void;
6
+ }
7
+ export type Result<T, E> = { tag: 'ok', val: T } | { tag: 'err', val: E };
@@ -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 '../interfaces/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 '../interfaces/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 '../interfaces/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 | undefined;
7
+ }
8
+ import type { TerminalOutput } from '../interfaces/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 | undefined;
7
+ }
8
+ import type { TerminalInput } from '../interfaces/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 | undefined;
7
+ }
8
+ import type { TerminalOutput } from '../interfaces/wasi-cli-terminal-output';
9
+ export { TerminalOutput };
@@ -0,0 +1,24 @@
1
+ export namespace WasiClocksMonotonicClock {
2
+ /**
3
+ * Read the current value of the clock.
4
+ *
5
+ * The clock is monotonic, therefore calling this function repeatedly will
6
+ * produce a sequence of non-decreasing values.
7
+ */
8
+ export function now(): Instant;
9
+ /**
10
+ * Query the resolution of the clock.
11
+ */
12
+ export function resolution(): Instant;
13
+ /**
14
+ * Create a `pollable` which will resolve once the specified time has been
15
+ * reached.
16
+ */
17
+ export function subscribe(when: Instant, absolute: boolean): Pollable;
18
+ }
19
+ import type { Pollable } from '../interfaces/wasi-poll-poll';
20
+ export { Pollable };
21
+ /**
22
+ * A timestamp in nanoseconds.
23
+ */
24
+ export type Instant = bigint;
@@ -0,0 +1,71 @@
1
+ export namespace WasiClocksTimezone {
2
+ /**
3
+ * Return information needed to display the given `datetime`. This includes
4
+ * the UTC offset, the time zone name, and a flag indicating whether
5
+ * daylight saving time is active.
6
+ *
7
+ * If the timezone cannot be determined for the given `datetime`, return a
8
+ * `timezone-display` for `UTC` with a `utc-offset` of 0 and no daylight
9
+ * saving time.
10
+ */
11
+ export function display(this_: Timezone, when: Datetime): TimezoneDisplay;
12
+ /**
13
+ * The same as `display`, but only return the UTC offset.
14
+ */
15
+ export function utcOffset(this_: Timezone, when: Datetime): number;
16
+ /**
17
+ * Dispose of the specified input-stream, after which it may no longer
18
+ * be used.
19
+ */
20
+ export function dropTimezone(this_: Timezone): void;
21
+ }
22
+ import type { Datetime } from '../interfaces/wasi-clocks-wall-clock';
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;
34
+ /**
35
+ * Information useful for displaying the timezone of a specific `datetime`.
36
+ *
37
+ * This information may vary within a single `timezone` to reflect daylight
38
+ * saving time adjustments.
39
+ */
40
+ export interface TimezoneDisplay {
41
+ /**
42
+ * The number of seconds difference between UTC time and the local
43
+ * time of the timezone.
44
+ *
45
+ * The returned value will always be less than 86400 which is the
46
+ * number of seconds in a day (24*60*60).
47
+ *
48
+ * In implementations that do not expose an actual time zone, this
49
+ * should return 0.
50
+ */
51
+ utcOffset: number,
52
+ /**
53
+ * The abbreviated name of the timezone to display to a user. The name
54
+ * `UTC` indicates Coordinated Universal Time. Otherwise, this should
55
+ * reference local standards for the name of the time zone.
56
+ *
57
+ * In implementations that do not expose an actual time zone, this
58
+ * should be the string `UTC`.
59
+ *
60
+ * In time zones that do not have an applicable name, a formatted
61
+ * representation of the UTC offset may be returned, such as `-04:00`.
62
+ */
63
+ name: string,
64
+ /**
65
+ * Whether daylight saving time is active.
66
+ *
67
+ * In implementations that do not expose an actual time zone, this
68
+ * should return false.
69
+ */
70
+ inDaylightSavingTime: boolean,
71
+ }
@@ -0,0 +1,31 @@
1
+ export namespace WasiClocksWallClock {
2
+ /**
3
+ * Read the current value of the clock.
4
+ *
5
+ * This clock is not monotonic, therefore calling this function repeatedly
6
+ * will not necessarily produce a sequence of non-decreasing values.
7
+ *
8
+ * The returned timestamps represent the number of seconds since
9
+ * 1970-01-01T00:00:00Z, also known as [POSIX's Seconds Since the Epoch],
10
+ * also known as [Unix Time].
11
+ *
12
+ * The nanoseconds field of the output is always less than 1000000000.
13
+ *
14
+ * [POSIX's Seconds Since the Epoch]: https://pubs.opengroup.org/onlinepubs/9699919799/xrat/V4_xbd_chap04.html#tag_21_04_16
15
+ * [Unix Time]: https://en.wikipedia.org/wiki/Unix_time
16
+ */
17
+ export function now(): Datetime;
18
+ /**
19
+ * Query the resolution of the clock.
20
+ *
21
+ * The nanoseconds field of the output is always less than 1000000000.
22
+ */
23
+ export function resolution(): Datetime;
24
+ }
25
+ /**
26
+ * A time and date in seconds plus nanoseconds.
27
+ */
28
+ export interface Datetime {
29
+ seconds: bigint,
30
+ nanoseconds: number,
31
+ }