@bytecodealliance/preview2-shim 0.0.8 → 0.0.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (102) hide show
  1. package/README.md +1 -0
  2. package/lib/browser/cli-base.js +57 -0
  3. package/lib/browser/clocks.js +50 -0
  4. package/lib/browser/filesystem.js +134 -141
  5. package/lib/browser/http.js +120 -0
  6. package/lib/browser/index.js +15 -37
  7. package/lib/browser/io.js +62 -20
  8. package/lib/browser/logging.js +16 -0
  9. package/lib/browser/poll.js +10 -6
  10. package/lib/browser/random.js +32 -25
  11. package/lib/browser/sockets.js +203 -0
  12. package/lib/nodejs/{preopens.js → cli-base.js} +47 -8
  13. package/lib/nodejs/clocks.js +50 -0
  14. package/lib/nodejs/filesystem.js +239 -234
  15. package/lib/nodejs/http.js +120 -0
  16. package/lib/nodejs/index.js +15 -37
  17. package/lib/nodejs/io.js +138 -19
  18. package/lib/nodejs/logging.js +16 -0
  19. package/lib/nodejs/poll.js +10 -6
  20. package/lib/nodejs/random.js +18 -13
  21. package/lib/nodejs/sockets.js +203 -0
  22. package/package.json +1 -1
  23. package/types/exports/{HTTP.d.ts → http-incoming-handler.d.ts} +1 -1
  24. package/types/imports/cli-base-environment.d.ts +17 -0
  25. package/types/imports/{exit.d.ts → cli-base-exit.d.ts} +4 -1
  26. package/types/imports/{preopens.d.ts → cli-base-preopens.d.ts} +6 -9
  27. package/types/imports/cli-base-stderr.d.ts +5 -0
  28. package/types/imports/cli-base-stdin.d.ts +5 -0
  29. package/types/imports/cli-base-stdout.d.ts +5 -0
  30. package/types/imports/clocks-monotonic-clock.d.ts +24 -0
  31. package/types/imports/clocks-timezone.d.ts +71 -0
  32. package/types/imports/clocks-wall-clock.d.ts +31 -0
  33. package/types/imports/filesystem-filesystem.d.ts +857 -0
  34. package/types/imports/{default-outgoing-HTTP.d.ts → http-outgoing-handler.d.ts} +1 -1
  35. package/types/imports/{types.d.ts → http-types.d.ts} +28 -28
  36. package/types/imports/io-streams.d.ts +180 -0
  37. package/types/imports/logging-handler.d.ts +40 -0
  38. package/types/imports/poll-poll.d.ts +41 -0
  39. package/types/imports/random-insecure-seed.d.ts +22 -0
  40. package/types/imports/random-insecure.d.ts +20 -0
  41. package/types/imports/random-random.d.ts +22 -0
  42. package/types/imports/{instance-network.d.ts → sockets-instance-network.d.ts} +4 -1
  43. package/types/imports/sockets-ip-name-lookup.d.ts +76 -0
  44. package/types/imports/sockets-network.d.ts +212 -0
  45. package/types/imports/sockets-tcp-create-socket.d.ts +33 -0
  46. package/types/imports/sockets-tcp.d.ts +285 -0
  47. package/types/imports/sockets-udp-create-socket.d.ts +33 -0
  48. package/types/imports/sockets-udp.d.ts +219 -0
  49. package/types/wasi-command.d.ts +23 -0
  50. package/types/wasi-proxy.d.ts +11 -44
  51. package/types/wasi-reactor.d.ts +23 -70
  52. package/lib/browser/console.js +0 -12
  53. package/lib/browser/default-outgoing-HTTP.js +0 -3
  54. package/lib/browser/environment.js +0 -17
  55. package/lib/browser/exit.js +0 -21
  56. package/lib/browser/instance-network.js +0 -3
  57. package/lib/browser/ip-name-lookup.js +0 -23
  58. package/lib/browser/monotonic-clock.js +0 -14
  59. package/lib/browser/network.js +0 -3
  60. package/lib/browser/preopens.js +0 -11
  61. package/lib/browser/stderr.js +0 -4
  62. package/lib/browser/streams.js +0 -60
  63. package/lib/browser/tcp-create-socket.js +0 -3
  64. package/lib/browser/tcp.js +0 -75
  65. package/lib/browser/timezone.js +0 -12
  66. package/lib/browser/types.js +0 -99
  67. package/lib/browser/udp-create-socket.js +0 -3
  68. package/lib/browser/udp.js +0 -75
  69. package/lib/browser/wall-clock.js +0 -9
  70. package/lib/nodejs/console.js +0 -12
  71. package/lib/nodejs/default-outgoing-HTTP.js +0 -3
  72. package/lib/nodejs/environment.js +0 -19
  73. package/lib/nodejs/exit.js +0 -3
  74. package/lib/nodejs/instance-network.js +0 -3
  75. package/lib/nodejs/ip-name-lookup.js +0 -23
  76. package/lib/nodejs/monotonic-clock.js +0 -14
  77. package/lib/nodejs/network.js +0 -3
  78. package/lib/nodejs/stderr.js +0 -4
  79. package/lib/nodejs/streams.js +0 -97
  80. package/lib/nodejs/tcp-create-socket.js +0 -3
  81. package/lib/nodejs/tcp.js +0 -75
  82. package/lib/nodejs/timezone.js +0 -12
  83. package/lib/nodejs/types.js +0 -99
  84. package/lib/nodejs/udp-create-socket.js +0 -3
  85. package/lib/nodejs/udp.js +0 -75
  86. package/lib/nodejs/wall-clock.js +0 -9
  87. package/types/imports/console.d.ts +0 -17
  88. package/types/imports/environment.d.ts +0 -4
  89. package/types/imports/filesystem.d.ts +0 -210
  90. package/types/imports/ip-name-lookup.d.ts +0 -19
  91. package/types/imports/monotonic-clock.d.ts +0 -8
  92. package/types/imports/network.d.ts +0 -50
  93. package/types/imports/poll.d.ts +0 -5
  94. package/types/imports/random.d.ts +0 -5
  95. package/types/imports/streams.d.ts +0 -23
  96. package/types/imports/tcp-create-socket.d.ts +0 -9
  97. package/types/imports/tcp.d.ts +0 -52
  98. package/types/imports/timezone.d.ts +0 -13
  99. package/types/imports/udp-create-socket.d.ts +0 -9
  100. package/types/imports/udp.d.ts +0 -36
  101. package/types/imports/wall-clock.d.ts +0 -8
  102. package/types/index.d.ts +0 -8
package/lib/nodejs/io.js CHANGED
@@ -1,25 +1,144 @@
1
- export function read(s, len) {
2
- switch (s) {
3
- case 0:
4
- return [process.stdin.read(len), true];
5
- default:
6
- throw new Error(`TODO: write ${s}`);
1
+ import { readSync as fsReadSync } from 'node:fs';
2
+
3
+ function _convertFsError (e) {
4
+ switch (e.code) {
5
+ case 'EACCES': throw 'access';
6
+ case 'EAGAIN':
7
+ case 'EWOULDBLOCK': throw 'would-block';
8
+ case 'EALREADY': throw 'already';
9
+ case 'EBADF': throw 'bad-descriptor';
10
+ case 'EBUSY': throw 'busy';
11
+ case 'EDEADLK': throw 'deadlock';
12
+ case 'EDQUOT': throw 'quota';
13
+ case 'EEXIST': throw 'exist';
14
+ case 'EFBIG': throw 'file-too-large';
15
+ case 'EILSEQ': throw 'illegal-byte-sequence';
16
+ case 'EINPROGRESS': throw 'in-progress';
17
+ case 'EINTR': throw 'interrupted';
18
+ case 'EINVAL': throw 'invalid';
19
+ case 'EIO': throw 'io';
20
+ case 'EISDIR': throw 'is-directory';
21
+ case 'ELOOP': throw 'loop';
22
+ case 'EMLINK': throw 'too-many-links';
23
+ case 'EMSGSIZE': throw 'message-size';
24
+ case 'ENAMETOOLONG': throw 'name-too-long'
25
+ case 'ENODEV': throw 'no-device';
26
+ case 'ENOENT': throw 'no-entry';
27
+ case 'ENOLCK': throw 'no-lock';
28
+ case 'ENOMEM': throw 'insufficient-memory';
29
+ case 'ENOSPC': throw 'insufficient-space';
30
+ case 'ENOTDIR': throw 'not-directory';
31
+ case 'ENOTEMPTY': throw 'not-empty';
32
+ case 'ENOTRECOVERABLE': throw 'not-recoverable';
33
+ case 'ENOTSUP': throw 'unsupported';
34
+ case 'ENOTTY': throw 'no-tty';
35
+ case 'ENXIO': throw 'no-such-device';
36
+ case 'EOVERFLOW': throw 'overflow';
37
+ case 'EPERM': throw 'not-permitted';
38
+ case 'EPIPE': throw 'pipe';
39
+ case 'EROFS': throw 'read-only';
40
+ case 'ESPIPE': throw 'invalid-seek';
41
+ case 'ETXTBSY': throw 'text-file-busy';
42
+ case 'EXDEV': throw 'cross-device';
43
+ default: throw e;
7
44
  }
8
45
  }
9
46
 
10
- export function write(s, buf) {
11
- switch (s) {
12
- case 0:
13
- throw new Error(`TODO: write stdin`);
14
- case 1: {
15
- process.stdout.write(buf);
16
- return BigInt(buf.byteLength);
47
+ export let _streams = {};
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
+ };
56
+ return streamCnt++;
57
+ }
58
+
59
+ export const ioStreams = {
60
+ 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}`);
17
66
  }
18
- case 2: {
19
- process.stderr.write(buf);
20
- return BigInt(buf.byteLength);
67
+ },
68
+ blockingRead(s, len) {
69
+ len = Number(len);
70
+ const stream = _streams[s];
71
+ if (!stream) throw null;
72
+ switch (stream.type) {
73
+ case 'file': {
74
+ const buf = Buffer.alloc(Number(len));
75
+ try {
76
+ 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];
80
+ }
81
+ catch (e) {
82
+ _convertFsError(e);
83
+ }
84
+ break;
85
+ }
86
+ default: throw null;
21
87
  }
22
- default:
23
- throw new Error(`TODO: write ${s}`);
88
+ },
89
+ skip(s, _len) {
90
+ console.log(`[streams] Skip ${s}`);
91
+ },
92
+ blockingSkip(s, _len) {
93
+ console.log(`[streams] Blocking skip ${s}`);
94
+ },
95
+ subscribeToInputStream(s) {
96
+ console.log(`[streams] Subscribe to input stream ${s}`);
97
+ },
98
+ dropInputStream(s) {
99
+ delete _streams[s];
100
+
101
+ },
102
+ write(s, buf) {
103
+ switch (s) {
104
+ case 0:
105
+ throw new Error(`TODO: write stdin`);
106
+ case 1: {
107
+ process.stdout.write(buf);
108
+ return BigInt(buf.byteLength);
109
+ }
110
+ case 2: {
111
+ process.stderr.write(buf);
112
+ return BigInt(buf.byteLength);
113
+ }
114
+ default:
115
+ throw new Error(`TODO: write ${s}`);
116
+ }
117
+ },
118
+ blockingWrite(s, _buf) {
119
+ console.log(`[streams] Blocking write ${s}`);
120
+ },
121
+ writeZeroes(s, _len) {
122
+ console.log(`[streams] Write zeroes ${s}`);
123
+ },
124
+ blockingWriteZeroes(s, _len) {
125
+ console.log(`[streams] Blocking write zeroes ${s}`);
126
+ },
127
+ splice(s, _src, _len) {
128
+ console.log(`[streams] Splice ${s}`);
129
+ },
130
+ blockingSplice(s, _src, _len) {
131
+ console.log(`[streams] Blocking splice ${s}`);
132
+ },
133
+ forward(s, _src) {
134
+ console.log(`[streams] Forward ${s}`);
135
+ },
136
+ subscribeToOutputStream(s) {
137
+ console.log(`[streams] Subscribe to output stream ${s}`);
138
+ },
139
+ dropOutputStream(s) {
140
+ console.log(`[streams] Drop output stream ${s}`);
24
141
  }
25
- }
142
+ };
143
+
144
+ export { ioStreams as streams }
@@ -0,0 +1,16 @@
1
+ const levels = ["trace", "debug", "info", "warn", "error"];
2
+
3
+ let logLevel = levels.indexOf("warn");
4
+
5
+ export const loggingHandler = {
6
+ log(level, context, msg) {
7
+ if (logLevel > levels.indexOf(level)) return;
8
+ process.stdout.write(`${level}: (${context}) ${msg}\n`);
9
+ }
10
+ };
11
+
12
+ export function setLevel(level) {
13
+ logLevel = levels.indexOf(level);
14
+ }
15
+
16
+ export { loggingHandler as handler }
@@ -1,7 +1,11 @@
1
- export function dropPollable(p) {
2
- console.log(`[poll] Drop pollable ${p}`);
3
- }
1
+ export const pollPoll = {
2
+ dropPollable (pollable) {
3
+ console.log(`[poll] Drop (${pollable})`);
4
+ },
5
+ pollOneoff (input) {
6
+ console.log(`[poll] Oneoff (${input})`);
7
+ return [];
8
+ }
9
+ };
4
10
 
5
- export function pollOneoff(f) {
6
- console.log(`[poll] Poll oneoff ${f}`);
7
- }
11
+ export { pollPoll as poll }
@@ -1,18 +1,23 @@
1
1
  import { randomBytes } from "node:crypto";
2
2
 
3
- export function getRandomBytes(len) {
4
- return randomBytes(Number(len));
5
- }
3
+ let insecureRandomValue1, insecureRandomValue2;
6
4
 
7
- export function getRandomU64 () {
8
- return new BigUint64Array(randomBytes(8).buffer)[0];
9
- }
5
+ export const randomRandom = {
6
+ getRandomBytes(len) {
7
+ return randomBytes(Number(len));
8
+ },
10
9
 
11
- let insecureRandomValue1, insecureRandomValue2;
12
- export function insecureRandom () {
13
- if (insecureRandomValue1 === undefined) {
14
- insecureRandomValue1 = getRandomU64();
15
- insecureRandomValue2 = getRandomU64();
10
+ getRandomU64 () {
11
+ 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];
16
20
  }
17
- return [insecureRandomValue1, insecureRandomValue2];
18
- }
21
+ };
22
+
23
+ export { randomRandom as random }
@@ -0,0 +1,203 @@
1
+ export const socketsInstanceNetwork = {
2
+ instanceNetwork () {
3
+ console.log(`[sockets] instance network`);
4
+ }
5
+ };
6
+
7
+ export const socketsIpNameLookup = {
8
+ dropResolveAddressStream () {
9
+
10
+ },
11
+ subscribe () {
12
+
13
+ },
14
+ resolveAddresses () {
15
+
16
+ },
17
+ resolveNextAddress () {
18
+
19
+ },
20
+ nonBlocking () {
21
+
22
+ },
23
+ setNonBlocking () {
24
+
25
+ },
26
+ };
27
+
28
+ export const socketsNetwork = {
29
+ dropNetwork () {
30
+
31
+ }
32
+ };
33
+
34
+ export const socketsTcpCreateSocket = {
35
+ createTcpSocket () {
36
+
37
+ }
38
+ };
39
+
40
+ export const socketsTcp = {
41
+ subscribe () {
42
+
43
+ },
44
+ dropTcpSocket() {
45
+
46
+ },
47
+ bind() {
48
+
49
+ },
50
+ connect() {
51
+
52
+ },
53
+ listen() {
54
+
55
+ },
56
+ accept() {
57
+
58
+ },
59
+ localAddress() {
60
+
61
+ },
62
+ remoteAddress() {
63
+
64
+ },
65
+ addressFamily() {
66
+
67
+ },
68
+ ipv6Only() {
69
+
70
+ },
71
+ setIpv6Only() {
72
+
73
+ },
74
+ setListenBacklogSize() {
75
+
76
+ },
77
+ keepAlive() {
78
+
79
+ },
80
+ setKeepAlive() {
81
+
82
+ },
83
+ noDelay() {
84
+
85
+ },
86
+ setNoDelay() {
87
+
88
+ },
89
+ unicastHopLimit() {
90
+
91
+ },
92
+ setUnicastHopLimit() {
93
+
94
+ },
95
+ receiveBufferSize() {
96
+
97
+ },
98
+ setReceiveBufferSize() {
99
+
100
+ },
101
+ sendBufferSize() {
102
+
103
+ },
104
+ setSendBufferSize() {
105
+
106
+ },
107
+ nonBlocking() {
108
+
109
+ },
110
+ setNonBlocking() {
111
+
112
+ },
113
+ shutdown() {
114
+
115
+ }
116
+ };
117
+
118
+ export const socketsUdp = {
119
+ subscribe () {
120
+
121
+ },
122
+
123
+ dropUdpSocket () {
124
+
125
+ },
126
+
127
+ bind () {
128
+
129
+ },
130
+
131
+ connect () {
132
+
133
+ },
134
+
135
+ receive () {
136
+
137
+ },
138
+
139
+ send () {
140
+
141
+ },
142
+
143
+ localAddress () {
144
+
145
+ },
146
+
147
+ remoteAddress () {
148
+
149
+ },
150
+
151
+ addressFamily () {
152
+
153
+ },
154
+
155
+ ipv6Only () {
156
+
157
+ },
158
+
159
+ setIpv6Only () {
160
+
161
+ },
162
+
163
+ unicastHopLimit () {
164
+
165
+ },
166
+
167
+ setUnicastHopLimit () {
168
+
169
+ },
170
+
171
+ receiveBufferSize () {
172
+
173
+ },
174
+
175
+ setReceiveBufferSize () {
176
+
177
+ },
178
+
179
+ sendBufferSize () {
180
+
181
+ },
182
+
183
+ setSendBufferSize () {
184
+
185
+ },
186
+
187
+ nonBlocking () {
188
+
189
+ },
190
+
191
+ setNonBlocking () {
192
+
193
+ }
194
+ };
195
+
196
+ export {
197
+ socketsInstanceNetwork as instanceNetwork,
198
+ socketsIpNameLookup as ipNameLookup,
199
+ socketsNetwork as network,
200
+ socketsTcpCreateSocket as tcpCreateSocket,
201
+ socketsTcp as tcp,
202
+ socketsUdp as udp
203
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bytecodealliance/preview2-shim",
3
- "version": "0.0.8",
3
+ "version": "0.0.9",
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 Http {
1
+ export namespace HttpIncomingHandler {
2
2
  export function handle(request: IncomingRequest, responseOut: ResponseOutparam): void;
3
3
  }
4
4
  import type { IncomingRequest } from '../imports/types';
@@ -0,0 +1,17 @@
1
+ export namespace CliBaseEnvironment {
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
+ }
@@ -1,4 +1,7 @@
1
- export namespace Exit {
1
+ export namespace CliBaseExit {
2
+ /**
3
+ * Exit the curerent instance and any linked instances.
4
+ */
2
5
  export function exit(status: Result<void, void>): void;
3
6
  }
4
7
  export type Result<T, E> = { tag: 'ok', val: T } | { tag: 'err', val: E };
@@ -1,15 +1,12 @@
1
- export namespace Preopens {
2
- export function getStdio(): StdioPreopens;
1
+ export namespace CliBasePreopens {
2
+ /**
3
+ * Return the set of of preopened directories, and their path.
4
+ */
3
5
  export function getDirectories(): [Descriptor, string][];
4
6
  }
7
+ import type { Descriptor } from '../imports/filesystem';
8
+ export { Descriptor };
5
9
  import type { InputStream } from '../imports/streams';
6
10
  export { InputStream };
7
11
  import type { OutputStream } from '../imports/streams';
8
12
  export { OutputStream };
9
- export interface StdioPreopens {
10
- stdin: InputStream,
11
- stdout: OutputStream,
12
- stderr: OutputStream,
13
- }
14
- import type { Descriptor } from '../imports/filesystem';
15
- export { Descriptor };
@@ -0,0 +1,5 @@
1
+ export namespace CliBaseStderr {
2
+ export function getStderr(): OutputStream;
3
+ }
4
+ import type { OutputStream } from '../imports/streams';
5
+ export { OutputStream };
@@ -0,0 +1,5 @@
1
+ export namespace CliBaseStdin {
2
+ export function getStdin(): InputStream;
3
+ }
4
+ import type { InputStream } from '../imports/streams';
5
+ export { InputStream };
@@ -0,0 +1,5 @@
1
+ export namespace CliBaseStdout {
2
+ export function getStdout(): OutputStream;
3
+ }
4
+ import type { OutputStream } from '../imports/streams';
5
+ export { OutputStream };
@@ -0,0 +1,24 @@
1
+ export namespace ClocksMonotonicClock {
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 '../imports/poll';
20
+ export { Pollable };
21
+ /**
22
+ * A timestamp in nanoseconds.
23
+ */
24
+ export type Instant = bigint;
@@ -0,0 +1,71 @@
1
+ export namespace ClocksTimezone {
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 '../imports/wall-clock';
23
+ export { Datetime };
24
+ /**
25
+ * Information useful for displaying the timezone of a specific `datetime`.
26
+ *
27
+ * This information may vary within a single `timezone` to reflect daylight
28
+ * saving time adjustments.
29
+ */
30
+ export interface TimezoneDisplay {
31
+ /**
32
+ * The number of seconds difference between UTC time and the local
33
+ * time of the timezone.
34
+ *
35
+ * The returned value will always be less than 86400 which is the
36
+ * number of seconds in a day (24*60*60).
37
+ *
38
+ * In implementations that do not expose an actual time zone, this
39
+ * should return 0.
40
+ */
41
+ utcOffset: number,
42
+ /**
43
+ * The abbreviated name of the timezone to display to a user. The name
44
+ * `UTC` indicates Coordinated Universal Time. Otherwise, this should
45
+ * reference local standards for the name of the time zone.
46
+ *
47
+ * In implementations that do not expose an actual time zone, this
48
+ * should be the string `UTC`.
49
+ *
50
+ * In time zones that do not have an applicable name, a formatted
51
+ * representation of the UTC offset may be returned, such as `-04:00`.
52
+ */
53
+ name: string,
54
+ /**
55
+ * Whether daylight saving time is active.
56
+ *
57
+ * In implementations that do not expose an actual time zone, this
58
+ * should return false.
59
+ */
60
+ inDaylightSavingTime: boolean,
61
+ }
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;
@@ -0,0 +1,31 @@
1
+ export namespace ClocksWallClock {
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
+ }