@bytecodealliance/preview2-shim 0.0.13 → 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 (76) 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 +76 -17
  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 +3 -2
  10. package/lib/http/wasi-http.js +52 -40
  11. package/lib/nodejs/cli.js +17 -7
  12. package/lib/nodejs/http.js +4 -7
  13. package/lib/nodejs/logging.js +2 -2
  14. package/package.json +1 -1
  15. package/types/exports/wasi-cli-environment.d.ts +22 -0
  16. package/types/exports/wasi-cli-exit.d.ts +7 -0
  17. package/types/exports/wasi-cli-run.d.ts +6 -0
  18. package/types/exports/wasi-cli-stderr.d.ts +5 -0
  19. package/types/exports/wasi-cli-stdin.d.ts +5 -0
  20. package/types/exports/wasi-cli-stdout.d.ts +5 -0
  21. package/types/exports/wasi-cli-terminal-input.d.ts +13 -0
  22. package/types/exports/wasi-cli-terminal-output.d.ts +13 -0
  23. package/types/exports/wasi-cli-terminal-stderr.d.ts +9 -0
  24. package/types/exports/wasi-cli-terminal-stdin.d.ts +9 -0
  25. package/types/exports/wasi-cli-terminal-stdout.d.ts +9 -0
  26. package/types/exports/wasi-clocks-monotonic-clock.d.ts +24 -0
  27. package/types/exports/wasi-clocks-timezone.d.ts +71 -0
  28. package/types/exports/wasi-clocks-wall-clock.d.ts +31 -0
  29. package/types/exports/wasi-filesystem-preopens.d.ts +8 -0
  30. package/types/exports/wasi-filesystem-types.d.ts +843 -0
  31. package/types/exports/wasi-http-incoming-handler.d.ts +7 -0
  32. package/types/exports/wasi-http-outgoing-handler.d.ts +9 -0
  33. package/types/exports/wasi-http-types.d.ts +118 -0
  34. package/types/exports/wasi-io-streams.d.ts +220 -0
  35. package/types/exports/wasi-poll-poll.d.ts +39 -0
  36. package/types/exports/wasi-random-insecure-seed.d.ts +22 -0
  37. package/types/exports/wasi-random-insecure.d.ts +20 -0
  38. package/types/exports/wasi-random-random.d.ts +22 -0
  39. package/types/exports/wasi-sockets-instance-network.d.ts +8 -0
  40. package/types/exports/wasi-sockets-ip-name-lookup.d.ts +76 -0
  41. package/types/exports/wasi-sockets-network.d.ts +180 -0
  42. package/types/exports/wasi-sockets-tcp-create-socket.d.ts +33 -0
  43. package/types/exports/wasi-sockets-tcp.d.ts +285 -0
  44. package/types/exports/wasi-sockets-udp-create-socket.d.ts +33 -0
  45. package/types/exports/wasi-sockets-udp.d.ts +228 -0
  46. package/types/imports/wasi-cli-environment.d.ts +22 -0
  47. package/types/imports/wasi-cli-exit.d.ts +7 -0
  48. package/types/imports/wasi-cli-stderr.d.ts +5 -0
  49. package/types/imports/wasi-cli-stdin.d.ts +5 -0
  50. package/types/imports/wasi-cli-stdout.d.ts +5 -0
  51. package/types/imports/wasi-cli-terminal-input.d.ts +13 -0
  52. package/types/imports/wasi-cli-terminal-output.d.ts +13 -0
  53. package/types/imports/wasi-cli-terminal-stderr.d.ts +9 -0
  54. package/types/imports/wasi-cli-terminal-stdin.d.ts +9 -0
  55. package/types/imports/wasi-cli-terminal-stdout.d.ts +9 -0
  56. package/types/imports/wasi-clocks-monotonic-clock.d.ts +24 -0
  57. package/types/imports/wasi-clocks-timezone.d.ts +71 -0
  58. package/types/imports/wasi-clocks-wall-clock.d.ts +31 -0
  59. package/types/imports/wasi-filesystem-preopens.d.ts +8 -0
  60. package/types/imports/wasi-filesystem-types.d.ts +843 -0
  61. package/types/imports/wasi-http-outgoing-handler.d.ts +9 -0
  62. package/types/imports/wasi-http-types.d.ts +118 -0
  63. package/types/imports/wasi-io-streams.d.ts +220 -0
  64. package/types/imports/wasi-poll-poll.d.ts +39 -0
  65. package/types/imports/wasi-random-insecure-seed.d.ts +22 -0
  66. package/types/imports/wasi-random-insecure.d.ts +20 -0
  67. package/types/imports/wasi-random-random.d.ts +22 -0
  68. package/types/imports/wasi-sockets-instance-network.d.ts +8 -0
  69. package/types/imports/wasi-sockets-ip-name-lookup.d.ts +76 -0
  70. package/types/imports/wasi-sockets-network.d.ts +180 -0
  71. package/types/imports/wasi-sockets-tcp-create-socket.d.ts +33 -0
  72. package/types/imports/wasi-sockets-tcp.d.ts +285 -0
  73. package/types/imports/wasi-sockets-udp-create-socket.d.ts +33 -0
  74. package/types/imports/wasi-sockets-udp.d.ts +228 -0
  75. package/types/wasi-cli-command.d.ts +29 -0
  76. package/types/wasi-http-proxy.d.ts +13 -0
@@ -0,0 +1,228 @@
1
+ export namespace WasiSocketsUdp {
2
+ /**
3
+ * Bind the socket to a specific network on the provided IP address and port.
4
+ *
5
+ * If the IP address is zero (`0.0.0.0` in IPv4, `::` in IPv6), it is left to the implementation to decide which
6
+ * network interface(s) to bind to.
7
+ * If the TCP/UDP port is zero, the socket will be bound to a random free port.
8
+ *
9
+ * When a socket is not explicitly bound, the first invocation to connect will implicitly bind the socket.
10
+ *
11
+ * Unlike in POSIX, this function is async. This enables interactive WASI hosts to inject permission prompts.
12
+ *
13
+ * # Typical `start` errors
14
+ * - `address-family-mismatch`: The `local-address` has the wrong address family. (EINVAL)
15
+ * - `already-bound`: The socket is already bound. (EINVAL)
16
+ * - `concurrency-conflict`: Another `bind` or `connect` operation is already in progress. (EALREADY)
17
+ *
18
+ * # Typical `finish` errors
19
+ * - `ephemeral-ports-exhausted`: No ephemeral ports available. (EADDRINUSE, ENOBUFS on Windows)
20
+ * - `address-in-use`: Address is already in use. (EADDRINUSE)
21
+ * - `address-not-bindable`: `local-address` is not an address that the `network` can bind to. (EADDRNOTAVAIL)
22
+ * - `not-in-progress`: A `bind` operation is not in progress.
23
+ * - `would-block`: Can't finish the operation, it is still in progress. (EWOULDBLOCK, EAGAIN)
24
+ *
25
+ * # References
26
+ * - <https://pubs.opengroup.org/onlinepubs/9699919799/functions/bind.html>
27
+ * - <https://man7.org/linux/man-pages/man2/bind.2.html>
28
+ * - <https://learn.microsoft.com/en-us/windows/win32/api/winsock/nf-winsock-bind>
29
+ * - <https://man.freebsd.org/cgi/man.cgi?query=bind&sektion=2&format=html>
30
+ */
31
+ export function startBind(this_: UdpSocket, network: Network, localAddress: IpSocketAddress): void;
32
+ export function finishBind(this_: UdpSocket): void;
33
+ /**
34
+ * Set the destination address.
35
+ *
36
+ * The local-address is updated based on the best network path to `remote-address`.
37
+ *
38
+ * When a destination address is set:
39
+ * - all receive operations will only return datagrams sent from the provided `remote-address`.
40
+ * - the `send` function can only be used to send to this destination.
41
+ *
42
+ * Note that this function does not generate any network traffic and the peer is not aware of this "connection".
43
+ *
44
+ * Unlike in POSIX, this function is async. This enables interactive WASI hosts to inject permission prompts.
45
+ *
46
+ * # Typical `start` errors
47
+ * - `address-family-mismatch`: The `remote-address` has the wrong address family. (EAFNOSUPPORT)
48
+ * - `invalid-remote-address`: The IP address in `remote-address` is set to INADDR_ANY (`0.0.0.0` / `::`). (EDESTADDRREQ, EADDRNOTAVAIL)
49
+ * - `invalid-remote-address`: The port in `remote-address` is set to 0. (EDESTADDRREQ, EADDRNOTAVAIL)
50
+ * - `already-attached`: The socket is already bound to a different network. The `network` passed to `connect` must be identical to the one passed to `bind`.
51
+ * - `concurrency-conflict`: Another `bind` or `connect` operation is already in progress. (EALREADY)
52
+ *
53
+ * # Typical `finish` errors
54
+ * - `ephemeral-ports-exhausted`: Tried to perform an implicit bind, but there were no ephemeral ports available. (EADDRINUSE, EADDRNOTAVAIL on Linux, EAGAIN on BSD)
55
+ * - `not-in-progress`: A `connect` operation is not in progress.
56
+ * - `would-block`: Can't finish the operation, it is still in progress. (EWOULDBLOCK, EAGAIN)
57
+ *
58
+ * # References
59
+ * - <https://pubs.opengroup.org/onlinepubs/9699919799/functions/connect.html>
60
+ * - <https://man7.org/linux/man-pages/man2/connect.2.html>
61
+ * - <https://learn.microsoft.com/en-us/windows/win32/api/winsock2/nf-winsock2-connect>
62
+ * - <https://man.freebsd.org/cgi/man.cgi?connect>
63
+ */
64
+ export function startConnect(this_: UdpSocket, network: Network, remoteAddress: IpSocketAddress): void;
65
+ export function finishConnect(this_: UdpSocket): void;
66
+ /**
67
+ * Receive messages on the socket.
68
+ *
69
+ * This function attempts to receive up to `max-results` datagrams on the socket without blocking.
70
+ * The returned list may contain fewer elements than requested, but never more.
71
+ * If `max-results` is 0, this function returns successfully with an empty list.
72
+ *
73
+ * # Typical errors
74
+ * - `not-bound`: The socket is not bound to any local address. (EINVAL)
75
+ * - `remote-unreachable`: The remote address is not reachable. (ECONNREFUSED, ECONNRESET, ENETRESET on Windows, EHOSTUNREACH, EHOSTDOWN, ENETUNREACH, ENETDOWN)
76
+ * - `would-block`: There is no pending data available to be read at the moment. (EWOULDBLOCK, EAGAIN)
77
+ *
78
+ * # References
79
+ * - <https://pubs.opengroup.org/onlinepubs/9699919799/functions/recvfrom.html>
80
+ * - <https://pubs.opengroup.org/onlinepubs/9699919799/functions/recvmsg.html>
81
+ * - <https://man7.org/linux/man-pages/man2/recv.2.html>
82
+ * - <https://man7.org/linux/man-pages/man2/recvmmsg.2.html>
83
+ * - <https://learn.microsoft.com/en-us/windows/win32/api/winsock/nf-winsock-recv>
84
+ * - <https://learn.microsoft.com/en-us/windows/win32/api/winsock/nf-winsock-recvfrom>
85
+ * - <https://learn.microsoft.com/en-us/previous-versions/windows/desktop/legacy/ms741687(v=vs.85)>
86
+ * - <https://man.freebsd.org/cgi/man.cgi?query=recv&sektion=2>
87
+ */
88
+ export function receive(this_: UdpSocket, maxResults: bigint): Datagram[];
89
+ /**
90
+ * Send messages on the socket.
91
+ *
92
+ * This function attempts to send all provided `datagrams` on the socket without blocking and
93
+ * returns how many messages were actually sent (or queued for sending).
94
+ *
95
+ * This function semantically behaves the same as iterating the `datagrams` list and sequentially
96
+ * sending each individual datagram until either the end of the list has been reached or the first error occurred.
97
+ * If at least one datagram has been sent successfully, this function never returns an error.
98
+ *
99
+ * If the input list is empty, the function returns `ok(0)`.
100
+ *
101
+ * The remote address option is required. To send a message to the "connected" peer,
102
+ * call `remote-address` to get their address.
103
+ *
104
+ * # Typical errors
105
+ * - `address-family-mismatch`: The `remote-address` has the wrong address family. (EAFNOSUPPORT)
106
+ * - `invalid-remote-address`: The IP address in `remote-address` is set to INADDR_ANY (`0.0.0.0` / `::`). (EDESTADDRREQ, EADDRNOTAVAIL)
107
+ * - `invalid-remote-address`: The port in `remote-address` is set to 0. (EDESTADDRREQ, EADDRNOTAVAIL)
108
+ * - `already-connected`: The socket is in "connected" mode and the `datagram.remote-address` does not match the address passed to `connect`. (EISCONN)
109
+ * - `not-bound`: The socket is not bound to any local address. Unlike POSIX, this function does not perform an implicit bind.
110
+ * - `remote-unreachable`: The remote address is not reachable. (ECONNREFUSED, ECONNRESET, ENETRESET on Windows, EHOSTUNREACH, EHOSTDOWN, ENETUNREACH, ENETDOWN)
111
+ * - `datagram-too-large`: The datagram is too large. (EMSGSIZE)
112
+ * - `would-block`: The send buffer is currently full. (EWOULDBLOCK, EAGAIN)
113
+ *
114
+ * # References
115
+ * - <https://pubs.opengroup.org/onlinepubs/9699919799/functions/sendto.html>
116
+ * - <https://pubs.opengroup.org/onlinepubs/9699919799/functions/sendmsg.html>
117
+ * - <https://man7.org/linux/man-pages/man2/send.2.html>
118
+ * - <https://man7.org/linux/man-pages/man2/sendmmsg.2.html>
119
+ * - <https://learn.microsoft.com/en-us/windows/win32/api/winsock2/nf-winsock2-send>
120
+ * - <https://learn.microsoft.com/en-us/windows/win32/api/winsock2/nf-winsock2-sendto>
121
+ * - <https://learn.microsoft.com/en-us/windows/win32/api/winsock2/nf-winsock2-wsasendmsg>
122
+ * - <https://man.freebsd.org/cgi/man.cgi?query=send&sektion=2>
123
+ */
124
+ export function send(this_: UdpSocket, datagrams: Datagram[]): bigint;
125
+ /**
126
+ * Get the current bound address.
127
+ *
128
+ * # Typical errors
129
+ * - `not-bound`: The socket is not bound to any local address.
130
+ *
131
+ * # References
132
+ * - <https://pubs.opengroup.org/onlinepubs/9699919799/functions/getsockname.html>
133
+ * - <https://man7.org/linux/man-pages/man2/getsockname.2.html>
134
+ * - <https://learn.microsoft.com/en-us/windows/win32/api/winsock/nf-winsock-getsockname>
135
+ * - <https://man.freebsd.org/cgi/man.cgi?getsockname>
136
+ */
137
+ export function localAddress(this_: UdpSocket): IpSocketAddress;
138
+ /**
139
+ * Get the address set with `connect`.
140
+ *
141
+ * # Typical errors
142
+ * - `not-connected`: The socket is not connected to a remote address. (ENOTCONN)
143
+ *
144
+ * # References
145
+ * - <https://pubs.opengroup.org/onlinepubs/9699919799/functions/getpeername.html>
146
+ * - <https://man7.org/linux/man-pages/man2/getpeername.2.html>
147
+ * - <https://learn.microsoft.com/en-us/windows/win32/api/winsock/nf-winsock-getpeername>
148
+ * - <https://man.freebsd.org/cgi/man.cgi?query=getpeername&sektion=2&n=1>
149
+ */
150
+ export function remoteAddress(this_: UdpSocket): IpSocketAddress;
151
+ /**
152
+ * Whether this is a IPv4 or IPv6 socket.
153
+ *
154
+ * Equivalent to the SO_DOMAIN socket option.
155
+ */
156
+ export function addressFamily(this_: UdpSocket): IpAddressFamily;
157
+ /**
158
+ * Whether IPv4 compatibility (dual-stack) mode is disabled or not.
159
+ *
160
+ * Equivalent to the IPV6_V6ONLY socket option.
161
+ *
162
+ * # Typical errors
163
+ * - `ipv6-only-operation`: (get/set) `this` socket is an IPv4 socket.
164
+ * - `already-bound`: (set) The socket is already bound.
165
+ * - `not-supported`: (set) Host does not support dual-stack sockets. (Implementations are not required to.)
166
+ * - `concurrency-conflict`: (set) Another `bind` or `connect` operation is already in progress. (EALREADY)
167
+ */
168
+ export function ipv6Only(this_: UdpSocket): boolean;
169
+ export function setIpv6Only(this_: UdpSocket, value: boolean): void;
170
+ /**
171
+ * Equivalent to the IP_TTL & IPV6_UNICAST_HOPS socket options.
172
+ *
173
+ * # Typical errors
174
+ * - `concurrency-conflict`: (set) Another `bind` or `connect` operation is already in progress. (EALREADY)
175
+ */
176
+ export function unicastHopLimit(this_: UdpSocket): number;
177
+ export function setUnicastHopLimit(this_: UdpSocket, value: number): void;
178
+ /**
179
+ * The kernel buffer space reserved for sends/receives on this socket.
180
+ *
181
+ * Note #1: an implementation may choose to cap or round the buffer size when setting the value.
182
+ * In other words, after setting a value, reading the same setting back may return a different value.
183
+ *
184
+ * Note #2: there is not necessarily a direct relationship between the kernel buffer size and the bytes of
185
+ * actual data to be sent/received by the application, because the kernel might also use the buffer space
186
+ * for internal metadata structures.
187
+ *
188
+ * Equivalent to the SO_RCVBUF and SO_SNDBUF socket options.
189
+ *
190
+ * # Typical errors
191
+ * - `concurrency-conflict`: (set) Another `bind` or `connect` operation is already in progress. (EALREADY)
192
+ */
193
+ export function receiveBufferSize(this_: UdpSocket): bigint;
194
+ export function setReceiveBufferSize(this_: UdpSocket, value: bigint): void;
195
+ export function sendBufferSize(this_: UdpSocket): bigint;
196
+ export function setSendBufferSize(this_: UdpSocket, value: bigint): void;
197
+ /**
198
+ * Create a `pollable` which will resolve once the socket is ready for I/O.
199
+ *
200
+ * Note: this function is here for WASI Preview2 only.
201
+ * It's planned to be removed when `future` is natively supported in Preview3.
202
+ */
203
+ export function subscribe(this_: UdpSocket): Pollable;
204
+ /**
205
+ * Dispose of the specified `udp-socket`, after which it may no longer be used.
206
+ *
207
+ * Note: this function is scheduled to be removed when Resources are natively supported in Wit.
208
+ */
209
+ export function dropUdpSocket(this_: UdpSocket): void;
210
+ }
211
+ import type { Pollable } from '../exports/wasi-poll-poll';
212
+ export { Pollable };
213
+ import type { Network } from '../exports/wasi-sockets-network';
214
+ export { Network };
215
+ import type { ErrorCode } from '../exports/wasi-sockets-network';
216
+ export { ErrorCode };
217
+ import type { IpSocketAddress } from '../exports/wasi-sockets-network';
218
+ export { IpSocketAddress };
219
+ import type { IpAddressFamily } from '../exports/wasi-sockets-network';
220
+ export { IpAddressFamily };
221
+ /**
222
+ * A UDP socket handle.
223
+ */
224
+ export type UdpSocket = number;
225
+ export interface Datagram {
226
+ data: Uint8Array,
227
+ remoteAddress: IpSocketAddress,
228
+ }
@@ -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 | null;
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,5 @@
1
+ export namespace WasiCliStderr {
2
+ export function getStderr(): OutputStream;
3
+ }
4
+ import type { OutputStream } from '../imports/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 '../imports/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 '../imports/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 '../imports/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 '../imports/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 '../imports/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 '../imports/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 '../imports/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
+ }
@@ -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 '../imports/wasi-filesystem-types';
8
+ export { Descriptor };