@bytecodealliance/preview2-shim 0.17.1 → 0.17.2

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 (43) hide show
  1. package/lib/io/worker-thread.js +64 -12
  2. package/package.json +1 -1
  3. package/types/cli.d.ts +11 -23
  4. package/types/clocks.d.ts +2 -5
  5. package/types/filesystem.d.ts +2 -5
  6. package/types/http.d.ts +3 -7
  7. package/types/index.d.ts +7 -15
  8. package/types/interfaces/wasi-cli-environment.d.ts +21 -22
  9. package/types/interfaces/wasi-cli-exit.d.ts +5 -6
  10. package/types/interfaces/wasi-cli-run.d.ts +5 -6
  11. package/types/interfaces/wasi-cli-stderr.d.ts +3 -5
  12. package/types/interfaces/wasi-cli-stdin.d.ts +3 -5
  13. package/types/interfaces/wasi-cli-stdout.d.ts +3 -5
  14. package/types/interfaces/wasi-cli-terminal-input.d.ts +5 -3
  15. package/types/interfaces/wasi-cli-terminal-output.d.ts +5 -3
  16. package/types/interfaces/wasi-cli-terminal-stderr.d.ts +7 -9
  17. package/types/interfaces/wasi-cli-terminal-stdin.d.ts +7 -9
  18. package/types/interfaces/wasi-cli-terminal-stdout.d.ts +7 -9
  19. package/types/interfaces/wasi-clocks-monotonic-clock.d.ts +24 -26
  20. package/types/interfaces/wasi-clocks-wall-clock.d.ts +23 -24
  21. package/types/interfaces/wasi-filesystem-preopens.d.ts +6 -8
  22. package/types/interfaces/wasi-filesystem-types.d.ts +34 -33
  23. package/types/interfaces/wasi-http-incoming-handler.d.ts +16 -19
  24. package/types/interfaces/wasi-http-outgoing-handler.d.ts +18 -23
  25. package/types/interfaces/wasi-http-types.d.ts +49 -38
  26. package/types/interfaces/wasi-io-error.d.ts +5 -3
  27. package/types/interfaces/wasi-io-poll.d.ts +27 -25
  28. package/types/interfaces/wasi-io-streams.d.ts +24 -21
  29. package/types/interfaces/wasi-random-insecure-seed.d.ts +21 -22
  30. package/types/interfaces/wasi-random-insecure.d.ts +19 -20
  31. package/types/interfaces/wasi-random-random.d.ts +23 -24
  32. package/types/interfaces/wasi-sockets-instance-network.d.ts +6 -8
  33. package/types/interfaces/wasi-sockets-ip-name-lookup.d.ts +32 -34
  34. package/types/interfaces/wasi-sockets-network.d.ts +5 -3
  35. package/types/interfaces/wasi-sockets-tcp-create-socket.d.ts +28 -33
  36. package/types/interfaces/wasi-sockets-tcp.d.ts +17 -23
  37. package/types/interfaces/wasi-sockets-udp-create-socket.d.ts +28 -33
  38. package/types/interfaces/wasi-sockets-udp.d.ts +20 -17
  39. package/types/io.d.ts +3 -7
  40. package/types/random.d.ts +3 -7
  41. package/types/sockets.d.ts +7 -15
  42. package/types/wasi-cli-command.d.ts +29 -29
  43. package/types/wasi-http-proxy.d.ts +13 -13
@@ -395,7 +395,7 @@ function handle(call, id, payload) {
395
395
  case HTTP_OUTGOING_BODY_DISPOSE:
396
396
  if (debug && !streams.has(id))
397
397
  console.warn(`wasi-io: stream ${id} not found to dispose`);
398
- streams.delete(id);
398
+ streams.delete(id);
399
399
  return;
400
400
  case HTTP_SERVER_START:
401
401
  return startHttpServer(id, payload);
@@ -646,34 +646,86 @@ function handle(call, id, payload) {
646
646
  }
647
647
  stream.pollState.ready = false;
648
648
  return (stream.flushPromise = new Promise((resolve, reject) => {
649
- stream.stream.write(payload, (err) => {
649
+ if (stream.stream === stdout || stream.stream === stderr) {
650
+ // Inside workers, NodeJS actually queues writes destined for
651
+ // stdout/stderr in a port that is only flushed on exit of the worker.
652
+ //
653
+ // In this case, we cannot attempt to wait for the promise.
654
+ //
655
+ // This code may have to be reworked for browsers.
656
+ //
657
+ // see: https://github.com/nodejs/node/blob/v22.12.0/lib/internal/worker/io.js#L288
658
+ // see: https://github.com/nodejs/node/blob/v22.12.0/lib/internal/worker.js#L303
659
+ // see: https://github.com/nodejs/node/blob/v22.12.0/typings/internalBinding/messaging.d.ts#L27
660
+ stream.stream.write(payload);
650
661
  stream.flushPromise = null;
651
662
  pollStateReady(stream.pollState);
652
- if (err) return void reject(streamError(err));
653
663
  resolve(BigInt(payload.byteLength));
654
- });
664
+ } else {
665
+ stream.stream.write(payload, (err) => {
666
+ stream.flushPromise = null;
667
+ pollStateReady(stream.pollState);
668
+ if (err) return void reject(streamError(err));
669
+ resolve(BigInt(payload.byteLength));
670
+ });
671
+ }
655
672
  }));
656
673
  }
657
674
  case OUTPUT_STREAM_FLUSH: {
658
675
  const stream = getStreamOrThrow(id);
659
676
  if (stream.flushPromise) return;
660
677
  stream.pollState.ready = false;
661
- return (stream.flushPromise = new Promise((resolve, reject) => {
662
- stream.stream.write(new Uint8Array([]), (err) => {
678
+ stream.flushPromise = new Promise((resolve, reject) => {
679
+ if (stream.stream === stdout || stream.stream === stderr) {
680
+ // Inside workers, NodeJS actually queues writes destined for
681
+ // stdout/stderr in a port that is only flushed on exit of the worker.
682
+ //
683
+ // In this case, we cannot attempt to wait for the promise.
684
+ //
685
+ // This code may have to be reworked for browsers.
686
+ //
687
+ // see: https://github.com/nodejs/node/blob/v22.12.0/lib/internal/worker/io.js#L288
688
+ // see: https://github.com/nodejs/node/blob/v22.12.0/lib/internal/worker.js#L303
689
+ // see: https://github.com/nodejs/node/blob/v22.12.0/typings/internalBinding/messaging.d.ts#L27
663
690
  stream.flushPromise = null;
664
691
  pollStateReady(stream.pollState);
665
- if (err) return void reject(streamError(err));
666
692
  resolve();
667
- });
668
- }));
693
+ } else {
694
+ // For all other writes, we can perform the actual write and expect the write to complete
695
+ // and trigger the relevant callback
696
+ stream.stream.write(new Uint8Array([]), (err) => {
697
+ stream.flushPromise = null;
698
+ pollStateReady(stream.pollState);
699
+ if (err) return void reject(streamError(err));
700
+ resolve();
701
+ });
702
+ }
703
+ });
704
+ return stream.flushPromise;
669
705
  }
670
706
  case OUTPUT_STREAM_BLOCKING_FLUSH: {
671
707
  const stream = getStreamOrThrow(id);
672
708
  if (stream.flushPromise) return stream.flushPromise;
673
709
  return new Promise((resolve, reject) => {
674
- stream.stream.write(new Uint8Array([]), (err) =>
675
- err ? reject(streamError(err)) : resolve()
676
- );
710
+ if (stream.stream === stdout || stream.stream === stderr) {
711
+ // Inside workers, NodeJS actually queues writes destined for
712
+ // stdout/stderr in a port that is only flushed on exit of the worker.
713
+ //
714
+ // In this case, we cannot attempt to wait for the promise.
715
+ //
716
+ // This code may have to be reworked for browsers.
717
+ //
718
+ // see: https://github.com/nodejs/node/blob/v22.12.0/lib/internal/worker/io.js#L288
719
+ // see: https://github.com/nodejs/node/blob/v22.12.0/lib/internal/worker.js#L303
720
+ // see: https://github.com/nodejs/node/blob/v22.12.0/typings/internalBinding/messaging.d.ts#L27
721
+ resolve();
722
+ } else {
723
+ // For all other writes, we can perform the actual write and expect the write to complete
724
+ // and trigger the relevant callback
725
+ stream.stream.write(new Uint8Array([]), (err) =>
726
+ err ? reject(streamError(err)) : resolve()
727
+ );
728
+ }
677
729
  });
678
730
  }
679
731
  case OUTPUT_STREAM_WRITE_ZEROES:
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bytecodealliance/preview2-shim",
3
- "version": "0.17.1",
3
+ "version": "0.17.2",
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",
package/types/cli.d.ts CHANGED
@@ -1,23 +1,11 @@
1
- import type { WasiCliEnvironment } from './interfaces/wasi-cli-environment.d.ts';
2
- import type { WasiCliExit } from './interfaces/wasi-cli-exit.d.ts';
3
- import type { WasiCliRun } from './interfaces/wasi-cli-run.d.ts';
4
- import type { WasiCliStderr } from './interfaces/wasi-cli-stderr.d.ts';
5
- import type { WasiCliStdin } from './interfaces/wasi-cli-stdin.d.ts';
6
- import type { WasiCliStdout } from './interfaces/wasi-cli-stdout.d.ts';
7
- import type { WasiCliTerminalInput } from './interfaces/wasi-cli-terminal-input.d.ts';
8
- import type { WasiCliTerminalOutput } from './interfaces/wasi-cli-terminal-output.d.ts';
9
- import type { WasiCliTerminalStderr } from './interfaces/wasi-cli-terminal-stderr.d.ts';
10
- import type { WasiCliTerminalStdin } from './interfaces/wasi-cli-terminal-stdin.d.ts';
11
- import type { WasiCliTerminalStdout } from './interfaces/wasi-cli-terminal-stdout.d.ts';
12
-
13
- export const environment: typeof WasiCliEnvironment;
14
- export const exit: typeof WasiCliExit;
15
- export const run: typeof WasiCliRun;
16
- export const stderr: typeof WasiCliStderr;
17
- export const stdin: typeof WasiCliStdin;
18
- export const stdout: typeof WasiCliStdout;
19
- export const terminalInput: typeof WasiCliTerminalInput;
20
- export const terminalOutput: typeof WasiCliTerminalOutput;
21
- export const terminalStderr: typeof WasiCliTerminalStderr;
22
- export const terminalStdin: typeof WasiCliTerminalStdin;
23
- export const terminalStdout: typeof WasiCliTerminalStdout;
1
+ export type * as environment from './interfaces/wasi-cli-environment.d.ts';
2
+ export type * as exit from './interfaces/wasi-cli-exit.d.ts';
3
+ export type * as run from './interfaces/wasi-cli-run.d.ts';
4
+ export type * as stderr from './interfaces/wasi-cli-stderr.d.ts';
5
+ export type * as stdin from './interfaces/wasi-cli-stdin.d.ts';
6
+ export type * as stdout from './interfaces/wasi-cli-stdout.d.ts';
7
+ export type * as terminalInput from './interfaces/wasi-cli-terminal-input.d.ts';
8
+ export type * as terminalOutput from './interfaces/wasi-cli-terminal-output.d.ts';
9
+ export type * as terminalStderr from './interfaces/wasi-cli-terminal-stderr.d.ts';
10
+ export type * as terminalStdin from './interfaces/wasi-cli-terminal-stdin.d.ts';
11
+ export type * as terminalStdout from './interfaces/wasi-cli-terminal-stdout.d.ts';
package/types/clocks.d.ts CHANGED
@@ -1,5 +1,2 @@
1
- import type { WasiClocksMonotonicClock } from './interfaces/wasi-clocks-monotonic-clock.d.ts';
2
- import type { WasiClocksWallClock } from './interfaces/wasi-clocks-wall-clock.d.ts';
3
-
4
- export const wallClock: typeof WasiClocksWallClock;
5
- export const monotonicClock: typeof WasiClocksMonotonicClock;
1
+ export type * as monotonicClock from './interfaces/wasi-clocks-monotonic-clock.d.ts';
2
+ export type * as wallClock from './interfaces/wasi-clocks-wall-clock.d.ts';
@@ -1,5 +1,2 @@
1
- import type { WasiFilesystemPreopens } from './interfaces/wasi-filesystem-preopens.d.ts';
2
- import type { WasiFilesystemTypes } from './interfaces/wasi-filesystem-types.d.ts';
3
-
4
- export const preopens: typeof WasiFilesystemPreopens;
5
- export const types: typeof WasiFilesystemTypes;
1
+ export type * as preopens from './interfaces/wasi-filesystem-preopens.d.ts';
2
+ export type * as types from './interfaces/wasi-filesystem-types.d.ts';
package/types/http.d.ts CHANGED
@@ -1,7 +1,3 @@
1
- import type { WasiHttpIncomingHandler } from './interfaces/wasi-http-incoming-handler.d.ts';
2
- import type { WasiHttpOutgoingHandler } from './interfaces/wasi-http-outgoing-handler.d.ts';
3
- import type { WasiHttpTypes } from './interfaces/wasi-http-types.d.ts';
4
-
5
- export const incomingHandler: typeof WasiHttpIncomingHandler;
6
- export const outgoingHandler: typeof WasiHttpOutgoingHandler;
7
- export const types: typeof WasiHttpTypes;
1
+ export type * as incomingHandler from './interfaces/wasi-http-incoming-handler.d.ts';
2
+ export type * as outgoingHandler from './interfaces/wasi-http-outgoing-handler.d.ts';
3
+ export type * as types from './interfaces/wasi-http-types.d.ts';
package/types/index.d.ts CHANGED
@@ -1,15 +1,7 @@
1
- import type * as WasiCli from "./cli.d.ts";
2
- import type * as WasiClocks from './clocks.d.ts';
3
- import type * as WasiFilesystem from './filesystem.d.ts';
4
- import type * as WasiHttp from "./http.d.ts";
5
- import type * as WasiIo from "./io.d.ts";
6
- import type * as WasiRandom from "./random.d.ts";
7
- import type * as WasiSockets from "./sockets.d.ts";
8
-
9
- export const cli: typeof WasiCli;
10
- export const clocks: typeof WasiClocks;
11
- export const filesystem: typeof WasiFilesystem;
12
- export const http: typeof WasiHttp;
13
- export const io: typeof WasiIo;
14
- export const random: typeof WasiRandom;
15
- export const sockets: typeof WasiSockets;
1
+ export type * as cli from "./cli.d.ts";
2
+ export type * as clocks from './clocks.d.ts';
3
+ export type * as filesystem from './filesystem.d.ts';
4
+ export type * as http from "./http.d.ts";
5
+ export type * as io from "./io.d.ts";
6
+ export type * as random from "./random.d.ts";
7
+ export type * as sockets from "./sockets.d.ts";
@@ -1,22 +1,21 @@
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(): Array<[string, string]>;
13
- /**
14
- * Get the POSIX-style arguments to the program.
15
- */
16
- export function getArguments(): Array<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
- }
1
+ /** @module Interface wasi:cli/environment@0.2.3 **/
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(): Array<[string, string]>;
13
+ /**
14
+ * Get the POSIX-style arguments to the program.
15
+ */
16
+ export function getArguments(): Array<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;
@@ -1,7 +1,6 @@
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
- }
1
+ /** @module Interface wasi:cli/exit@0.2.3 **/
2
+ /**
3
+ * Exit the current instance and any linked instances.
4
+ */
5
+ export function exit(status: Result<void, void>): void;
7
6
  export type Result<T, E> = { tag: 'ok', val: T } | { tag: 'err', val: E };
@@ -1,6 +1,5 @@
1
- export namespace WasiCliRun {
2
- /**
3
- * Run the program.
4
- */
5
- export function run(): void;
6
- }
1
+ /** @module Interface wasi:cli/run@0.2.3 **/
2
+ /**
3
+ * Run the program.
4
+ */
5
+ export function run(): void;
@@ -1,5 +1,3 @@
1
- export namespace WasiCliStderr {
2
- export function getStderr(): OutputStream;
3
- }
4
- import type { OutputStream } from './wasi-io-streams.js';
5
- export { OutputStream };
1
+ /** @module Interface wasi:cli/stderr@0.2.3 **/
2
+ export function getStderr(): OutputStream;
3
+ export type OutputStream = import('./wasi-io-streams.js').OutputStream;
@@ -1,5 +1,3 @@
1
- export namespace WasiCliStdin {
2
- export function getStdin(): InputStream;
3
- }
4
- import type { InputStream } from './wasi-io-streams.js';
5
- export { InputStream };
1
+ /** @module Interface wasi:cli/stdin@0.2.3 **/
2
+ export function getStdin(): InputStream;
3
+ export type InputStream = import('./wasi-io-streams.js').InputStream;
@@ -1,5 +1,3 @@
1
- export namespace WasiCliStdout {
2
- export function getStdout(): OutputStream;
3
- }
4
- import type { OutputStream } from './wasi-io-streams.js';
5
- export { OutputStream };
1
+ /** @module Interface wasi:cli/stdout@0.2.3 **/
2
+ export function getStdout(): OutputStream;
3
+ export type OutputStream = import('./wasi-io-streams.js').OutputStream;
@@ -1,6 +1,8 @@
1
- export namespace WasiCliTerminalInput {
2
- export { TerminalInput };
3
- }
1
+ /** @module Interface wasi:cli/terminal-input@0.2.3 **/
4
2
 
5
3
  export class TerminalInput {
4
+ /**
5
+ * This type does not have a public constructor.
6
+ */
7
+ private constructor();
6
8
  }
@@ -1,6 +1,8 @@
1
- export namespace WasiCliTerminalOutput {
2
- export { TerminalOutput };
3
- }
1
+ /** @module Interface wasi:cli/terminal-output@0.2.3 **/
4
2
 
5
3
  export class TerminalOutput {
4
+ /**
5
+ * This type does not have a public constructor.
6
+ */
7
+ private constructor();
6
8
  }
@@ -1,9 +1,7 @@
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 './wasi-cli-terminal-output.js';
9
- export { TerminalOutput };
1
+ /** @module Interface wasi:cli/terminal-stderr@0.2.3 **/
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
+ export type TerminalOutput = import('./wasi-cli-terminal-output.js').TerminalOutput;
@@ -1,9 +1,7 @@
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 './wasi-cli-terminal-input.js';
9
- export { TerminalInput };
1
+ /** @module Interface wasi:cli/terminal-stdin@0.2.3 **/
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
+ export type TerminalInput = import('./wasi-cli-terminal-input.js').TerminalInput;
@@ -1,9 +1,7 @@
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 './wasi-cli-terminal-output.js';
9
- export { TerminalOutput };
1
+ /** @module Interface wasi:cli/terminal-stdout@0.2.3 **/
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
+ export type TerminalOutput = import('./wasi-cli-terminal-output.js').TerminalOutput;
@@ -1,29 +1,27 @@
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. Returns the duration of time
11
- * corresponding to a clock tick.
12
- */
13
- export function resolution(): Duration;
14
- /**
15
- * Create a `pollable` which will resolve once the specified instant
16
- * has occurred.
17
- */
18
- export function subscribeInstant(when: Instant): Pollable;
19
- /**
20
- * Create a `pollable` that will resolve after the specified duration has
21
- * elapsed from the time this function is invoked.
22
- */
23
- export function subscribeDuration(when: Duration): Pollable;
24
- }
25
- import type { Pollable } from './wasi-io-poll.js';
26
- export { Pollable };
1
+ /** @module Interface wasi:clocks/monotonic-clock@0.2.3 **/
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. Returns the duration of time
11
+ * corresponding to a clock tick.
12
+ */
13
+ export function resolution(): Duration;
14
+ /**
15
+ * Create a `pollable` which will resolve once the specified instant
16
+ * has occurred.
17
+ */
18
+ export function subscribeInstant(when: Instant): Pollable;
19
+ /**
20
+ * Create a `pollable` that will resolve after the specified duration has
21
+ * elapsed from the time this function is invoked.
22
+ */
23
+ export function subscribeDuration(when: Duration): Pollable;
24
+ export type Pollable = import('./wasi-io-poll.js').Pollable;
27
25
  /**
28
26
  * An instant in time, in nanoseconds. An instant is relative to an
29
27
  * unspecified initial value, and can only be compared to instances from
@@ -1,27 +1,26 @@
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
- }
1
+ /** @module Interface wasi:clocks/wall-clock@0.2.3 **/
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;
25
24
  /**
26
25
  * A time and date in seconds plus nanoseconds.
27
26
  */
@@ -1,8 +1,6 @@
1
- export namespace WasiFilesystemPreopens {
2
- /**
3
- * Return the set of preopened directories, and their path.
4
- */
5
- export function getDirectories(): Array<[Descriptor, string]>;
6
- }
7
- import type { Descriptor } from './wasi-filesystem-types.js';
8
- export { Descriptor };
1
+ /** @module Interface wasi:filesystem/preopens@0.2.3 **/
2
+ /**
3
+ * Return the set of preopened directories, and their paths.
4
+ */
5
+ export function getDirectories(): Array<[Descriptor, string]>;
6
+ export type Descriptor = import('./wasi-filesystem-types.js').Descriptor;
@@ -1,28 +1,21 @@
1
- export namespace WasiFilesystemTypes {
2
- export { Descriptor };
3
- export { DirectoryEntryStream };
4
- /**
5
- * Attempts to extract a filesystem-related `error-code` from the stream
6
- * `error` provided.
7
- *
8
- * Stream operations which return `stream-error::last-operation-failed`
9
- * have a payload with more information about the operation that failed.
10
- * This payload can be passed through to this function to see if there's
11
- * filesystem-related information about the error to return.
12
- *
13
- * Note that this function is fallible because not all stream-related
14
- * errors are filesystem-related errors.
15
- */
16
- export function filesystemErrorCode(err: Error): ErrorCode | undefined;
17
- }
18
- import type { InputStream } from './wasi-io-streams.js';
19
- export { InputStream };
20
- import type { OutputStream } from './wasi-io-streams.js';
21
- export { OutputStream };
22
- import type { Error } from './wasi-io-streams.js';
23
- export { Error };
24
- import type { Datetime } from './wasi-clocks-wall-clock.js';
25
- export { Datetime };
1
+ /** @module Interface wasi:filesystem/types@0.2.3 **/
2
+ /**
3
+ * Attempts to extract a filesystem-related `error-code` from the stream
4
+ * `error` provided.
5
+ *
6
+ * Stream operations which return `stream-error::last-operation-failed`
7
+ * have a payload with more information about the operation that failed.
8
+ * This payload can be passed through to this function to see if there's
9
+ * filesystem-related information about the error to return.
10
+ *
11
+ * Note that this function is fallible because not all stream-related
12
+ * errors are filesystem-related errors.
13
+ */
14
+ export function filesystemErrorCode(err: Error): ErrorCode | undefined;
15
+ export type InputStream = import('./wasi-io-streams.js').InputStream;
16
+ export type OutputStream = import('./wasi-io-streams.js').OutputStream;
17
+ export type Error = import('./wasi-io-streams.js').Error;
18
+ export type Datetime = import('./wasi-clocks-wall-clock.js').Datetime;
26
19
  /**
27
20
  * File size or length of a region within a file.
28
21
  */
@@ -395,6 +388,10 @@ export interface MetadataHashValue {
395
388
  }
396
389
 
397
390
  export class Descriptor {
391
+ /**
392
+ * This type does not have a public constructor.
393
+ */
394
+ private constructor();
398
395
  /**
399
396
  * Return a stream for reading from a file, if available.
400
397
  *
@@ -421,7 +418,7 @@ export class Descriptor {
421
418
  * May fail with an error-code describing why the file cannot be appended.
422
419
  *
423
420
  * Note: This allows using `write-stream`, which is similar to `write` with
424
- * `O_APPEND` in in POSIX.
421
+ * `O_APPEND` in POSIX.
425
422
  */
426
423
  appendViaStream(): OutputStream;
427
424
  /**
@@ -639,14 +636,14 @@ export class Descriptor {
639
636
  * replaced. It may also include a secret value chosen by the
640
637
  * implementation and not otherwise exposed.
641
638
  *
642
- * Implementations are encourated to provide the following properties:
639
+ * Implementations are encouraged to provide the following properties:
643
640
  *
644
- * - If the file is not modified or replaced, the computed hash value should
645
- * usually not change.
646
- * - If the object is modified or replaced, the computed hash value should
647
- * usually change.
648
- * - The inputs to the hash should not be easily computable from the
649
- * computed hash.
641
+ * - If the file is not modified or replaced, the computed hash value should
642
+ * usually not change.
643
+ * - If the object is modified or replaced, the computed hash value should
644
+ * usually change.
645
+ * - The inputs to the hash should not be easily computable from the
646
+ * computed hash.
650
647
  *
651
648
  * However, none of these is required.
652
649
  */
@@ -661,6 +658,10 @@ export class Descriptor {
661
658
  }
662
659
 
663
660
  export class DirectoryEntryStream {
661
+ /**
662
+ * This type does not have a public constructor.
663
+ */
664
+ private constructor();
664
665
  /**
665
666
  * Read a single directory entry from a `directory-entry-stream`.
666
667
  */