@bytecodealliance/preview2-shim 0.0.21 → 0.14.1
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.
- package/README.md +4 -14
- package/lib/browser/cli.js +2 -4
- package/lib/browser/clocks.js +15 -27
- package/lib/browser/filesystem.js +2 -30
- package/lib/browser/http.js +1 -3
- package/lib/browser/io.js +4 -2
- package/lib/common/assert.js +7 -0
- package/lib/io/calls.js +64 -0
- package/lib/io/worker-http.js +95 -0
- package/lib/io/worker-io.js +322 -0
- package/lib/io/worker-thread.js +569 -0
- package/lib/nodejs/cli.js +45 -59
- package/lib/nodejs/clocks.js +13 -27
- package/lib/nodejs/filesystem.js +539 -459
- package/lib/nodejs/http.js +440 -173
- package/lib/nodejs/index.js +4 -1
- package/lib/nodejs/io.js +1 -0
- package/lib/nodejs/sockets/socket-common.js +116 -0
- package/lib/nodejs/sockets/socketopts-bindings.js +94 -0
- package/lib/nodejs/sockets/tcp-socket-impl.js +794 -0
- package/lib/nodejs/sockets/udp-socket-impl.js +628 -0
- package/lib/nodejs/sockets/wasi-sockets.js +320 -0
- package/lib/nodejs/sockets.js +11 -200
- package/lib/synckit/index.js +4 -2
- package/package.json +1 -5
- package/types/interfaces/wasi-cli-terminal-input.d.ts +4 -0
- package/types/interfaces/wasi-cli-terminal-output.d.ts +4 -0
- package/types/interfaces/wasi-clocks-monotonic-clock.d.ts +19 -6
- package/types/interfaces/wasi-filesystem-types.d.ts +1 -178
- package/types/interfaces/wasi-http-outgoing-handler.d.ts +2 -2
- package/types/interfaces/wasi-http-types.d.ts +412 -82
- package/types/interfaces/wasi-io-error.d.ts +16 -0
- package/types/interfaces/wasi-io-poll.d.ts +19 -8
- package/types/interfaces/wasi-io-streams.d.ts +26 -46
- package/types/interfaces/wasi-sockets-ip-name-lookup.d.ts +9 -21
- package/types/interfaces/wasi-sockets-network.d.ts +4 -0
- package/types/interfaces/wasi-sockets-tcp.d.ts +75 -18
- package/types/interfaces/wasi-sockets-udp-create-socket.d.ts +1 -1
- package/types/interfaces/wasi-sockets-udp.d.ts +282 -193
- package/types/wasi-cli-command.d.ts +28 -28
- package/types/wasi-http-proxy.d.ts +12 -12
- package/lib/common/io.js +0 -183
- package/lib/common/make-request.js +0 -30
- package/types/interfaces/wasi-clocks-timezone.d.ts +0 -56
|
@@ -1,31 +1,21 @@
|
|
|
1
1
|
export namespace WasiIoStreams {
|
|
2
|
-
/**
|
|
3
|
-
* Returns a string that's suitable to assist humans in debugging this
|
|
4
|
-
* error.
|
|
5
|
-
*
|
|
6
|
-
* The returned string will change across platforms and hosts which
|
|
7
|
-
* means that parsing it, for example, would be a
|
|
8
|
-
* platform-compatibility hazard.
|
|
9
|
-
*/
|
|
10
|
-
export { Error };
|
|
11
2
|
/**
|
|
12
3
|
* Perform a non-blocking read from the stream.
|
|
13
4
|
*
|
|
14
|
-
* This function returns a list of bytes containing the data
|
|
15
|
-
*
|
|
16
|
-
*
|
|
17
|
-
*
|
|
18
|
-
*
|
|
19
|
-
* available
|
|
20
|
-
* will be ready when more data is available.
|
|
5
|
+
* This function returns a list of bytes containing the read data,
|
|
6
|
+
* when successful. The returned list will contain up to `len` bytes;
|
|
7
|
+
* it may return fewer than requested, but not more. The list is
|
|
8
|
+
* empty when no bytes are available for reading at this time. The
|
|
9
|
+
* pollable given by `subscribe` will be ready when more bytes are
|
|
10
|
+
* available.
|
|
21
11
|
*
|
|
22
|
-
*
|
|
23
|
-
*
|
|
24
|
-
*
|
|
12
|
+
* This function fails with a `stream-error` when the operation
|
|
13
|
+
* encounters an error, giving `last-operation-failed`, or when the
|
|
14
|
+
* stream is closed, giving `closed`.
|
|
25
15
|
*
|
|
26
|
-
* When the caller gives a `len` of 0, it represents a request to
|
|
27
|
-
* bytes.
|
|
28
|
-
*
|
|
16
|
+
* When the caller gives a `len` of 0, it represents a request to
|
|
17
|
+
* read 0 bytes. If the stream is still open, this call should
|
|
18
|
+
* succeed and return an empty list, or otherwise fail with `closed`.
|
|
29
19
|
*
|
|
30
20
|
* The `len` parameter is a `u64`, which could represent a list of u8 which
|
|
31
21
|
* is not possible to allocate in wasm32, or not desirable to allocate as
|
|
@@ -35,21 +25,13 @@ export namespace WasiIoStreams {
|
|
|
35
25
|
export { InputStream };
|
|
36
26
|
/**
|
|
37
27
|
* Read bytes from a stream, after blocking until at least one byte can
|
|
38
|
-
* be read. Except for blocking, identical to `read`.
|
|
28
|
+
* be read. Except for blocking, behavior is identical to `read`.
|
|
39
29
|
*/
|
|
40
30
|
/**
|
|
41
|
-
* Skip bytes from a stream.
|
|
42
|
-
*
|
|
43
|
-
* This is similar to the `read` function, but avoids copying the
|
|
44
|
-
* bytes into the instance.
|
|
45
|
-
*
|
|
46
|
-
* Once a stream has reached the end, subsequent calls to read or
|
|
47
|
-
* `skip` will always report end-of-stream rather than producing more
|
|
48
|
-
* data.
|
|
31
|
+
* Skip bytes from a stream. Returns number of bytes skipped.
|
|
49
32
|
*
|
|
50
|
-
*
|
|
51
|
-
*
|
|
52
|
-
* reached. The returned value will be at most `len`; it may be less.
|
|
33
|
+
* Behaves identical to `read`, except instead of returning a list
|
|
34
|
+
* of bytes, returns the number of bytes consumed from the stream.
|
|
53
35
|
*/
|
|
54
36
|
/**
|
|
55
37
|
* Skip bytes from a stream, after blocking until at least one byte
|
|
@@ -195,6 +177,8 @@ export namespace WasiIoStreams {
|
|
|
195
177
|
* is ready for reading, before performing the `splice`.
|
|
196
178
|
*/
|
|
197
179
|
}
|
|
180
|
+
import type { Error } from '../interfaces/wasi-io-error.js';
|
|
181
|
+
export { Error };
|
|
198
182
|
import type { Pollable } from '../interfaces/wasi-io-poll.js';
|
|
199
183
|
export { Pollable };
|
|
200
184
|
/**
|
|
@@ -219,6 +203,14 @@ export namespace WasiIoStreams {
|
|
|
219
203
|
tag: 'closed',
|
|
220
204
|
}
|
|
221
205
|
|
|
206
|
+
export class InputStream {
|
|
207
|
+
read(len: bigint): Uint8Array;
|
|
208
|
+
blockingRead(len: bigint): Uint8Array;
|
|
209
|
+
skip(len: bigint): bigint;
|
|
210
|
+
blockingSkip(len: bigint): bigint;
|
|
211
|
+
subscribe(): Pollable;
|
|
212
|
+
}
|
|
213
|
+
|
|
222
214
|
export class OutputStream {
|
|
223
215
|
checkWrite(): bigint;
|
|
224
216
|
write(contents: Uint8Array): void;
|
|
@@ -231,16 +223,4 @@ export namespace WasiIoStreams {
|
|
|
231
223
|
splice(src: InputStream, len: bigint): bigint;
|
|
232
224
|
blockingSplice(src: InputStream, len: bigint): bigint;
|
|
233
225
|
}
|
|
234
|
-
|
|
235
|
-
export class Error {
|
|
236
|
-
toDebugString(): string;
|
|
237
|
-
}
|
|
238
|
-
|
|
239
|
-
export class InputStream {
|
|
240
|
-
read(len: bigint): Uint8Array;
|
|
241
|
-
blockingRead(len: bigint): Uint8Array;
|
|
242
|
-
skip(len: bigint): bigint;
|
|
243
|
-
blockingSkip(len: bigint): bigint;
|
|
244
|
-
subscribe(): Pollable;
|
|
245
|
-
}
|
|
246
226
|
|
|
@@ -2,28 +2,18 @@ export namespace WasiSocketsIpNameLookup {
|
|
|
2
2
|
/**
|
|
3
3
|
* Resolve an internet host name to a list of IP addresses.
|
|
4
4
|
*
|
|
5
|
-
*
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
-
* - `name`: The name to look up. IP addresses are not allowed. Unicode domain names are automatically converted
|
|
9
|
-
* to ASCII using IDNA encoding.
|
|
10
|
-
* - `address-family`: If provided, limit the results to addresses of this specific address family.
|
|
11
|
-
* - `include-unavailable`: When set to true, this function will also return addresses of which the runtime
|
|
12
|
-
* thinks (or knows) can't be connected to at the moment. For example, this will return IPv6 addresses on
|
|
13
|
-
* systems without an active IPv6 interface. Notes:
|
|
14
|
-
* - Even when no public IPv6 interfaces are present or active, names like "localhost" can still resolve to an IPv6 address.
|
|
15
|
-
* - Whatever is "available" or "unavailable" is volatile and can change everytime a network cable is unplugged.
|
|
5
|
+
* Unicode domain names are automatically converted to ASCII using IDNA encoding.
|
|
6
|
+
* If the input is an IP address string, the address is parsed and returned
|
|
7
|
+
* as-is without making any external requests.
|
|
16
8
|
*
|
|
17
|
-
*
|
|
18
|
-
* that can be used to (asynchronously) fetch the results.
|
|
9
|
+
* See the wasi-socket proposal README.md for a comparison with getaddrinfo.
|
|
19
10
|
*
|
|
20
|
-
*
|
|
21
|
-
*
|
|
11
|
+
* This function never blocks. It either immediately fails or immediately
|
|
12
|
+
* returns successfully with a `resolve-address-stream` that can be used
|
|
13
|
+
* to (asynchronously) fetch the results.
|
|
22
14
|
*
|
|
23
15
|
* # Typical errors
|
|
24
|
-
* - `invalid-argument`:
|
|
25
|
-
* - `invalid-argument`: `name` is an IP address.
|
|
26
|
-
* - `not-supported`: The specified `address-family` is not supported. (EAI_FAMILY)
|
|
16
|
+
* - `invalid-argument`: `name` is a syntactically invalid domain name or IP address.
|
|
27
17
|
*
|
|
28
18
|
* # References:
|
|
29
19
|
* - <https://pubs.opengroup.org/onlinepubs/9699919799/functions/getaddrinfo.html>
|
|
@@ -31,7 +21,7 @@ export namespace WasiSocketsIpNameLookup {
|
|
|
31
21
|
* - <https://learn.microsoft.com/en-us/windows/win32/api/ws2tcpip/nf-ws2tcpip-getaddrinfo>
|
|
32
22
|
* - <https://man.freebsd.org/cgi/man.cgi?query=getaddrinfo&sektion=3>
|
|
33
23
|
*/
|
|
34
|
-
export function resolveAddresses(network: Network, name: string
|
|
24
|
+
export function resolveAddresses(network: Network, name: string): ResolveAddressStream;
|
|
35
25
|
/**
|
|
36
26
|
* Returns the next address from the resolver.
|
|
37
27
|
*
|
|
@@ -63,8 +53,6 @@ import type { ErrorCode } from '../interfaces/wasi-sockets-network.js';
|
|
|
63
53
|
export { ErrorCode };
|
|
64
54
|
import type { IpAddress } from '../interfaces/wasi-sockets-network.js';
|
|
65
55
|
export { IpAddress };
|
|
66
|
-
import type { IpAddressFamily } from '../interfaces/wasi-sockets-network.js';
|
|
67
|
-
export { IpAddressFamily };
|
|
68
56
|
|
|
69
57
|
export class ResolveAddressStream {
|
|
70
58
|
resolveNextAddress(): IpAddress | undefined;
|
|
@@ -63,7 +63,7 @@ export namespace WasiSocketsTcp {
|
|
|
63
63
|
* - `connection-refused`: The connection was forcefully rejected. (ECONNREFUSED)
|
|
64
64
|
* - `connection-reset`: The connection was reset. (ECONNRESET)
|
|
65
65
|
* - `connection-aborted`: The connection was aborted. (ECONNABORTED)
|
|
66
|
-
* - `remote-unreachable`: The remote address is not reachable. (EHOSTUNREACH, EHOSTDOWN, ENETUNREACH, ENETDOWN)
|
|
66
|
+
* - `remote-unreachable`: The remote address is not reachable. (EHOSTUNREACH, EHOSTDOWN, ENETUNREACH, ENETDOWN, ENONET)
|
|
67
67
|
* - `address-in-use`: Tried to perform an implicit bind, but there were no ephemeral ports available. (EADDRINUSE, EADDRNOTAVAIL on Linux, EAGAIN on BSD)
|
|
68
68
|
* - `not-in-progress`: A `connect` operation is not in progress.
|
|
69
69
|
* - `would-block`: Can't finish the operation, it is still in progress. (EWOULDBLOCK, EAGAIN)
|
|
@@ -105,9 +105,11 @@ export namespace WasiSocketsTcp {
|
|
|
105
105
|
* The returned socket is bound and in the Connection state. The following properties are inherited from the listener socket:
|
|
106
106
|
* - `address-family`
|
|
107
107
|
* - `ipv6-only`
|
|
108
|
-
* - `keep-alive`
|
|
109
|
-
* - `
|
|
110
|
-
* - `
|
|
108
|
+
* - `keep-alive-enabled`
|
|
109
|
+
* - `keep-alive-idle-time`
|
|
110
|
+
* - `keep-alive-interval`
|
|
111
|
+
* - `keep-alive-count`
|
|
112
|
+
* - `hop-limit`
|
|
111
113
|
* - `receive-buffer-size`
|
|
112
114
|
* - `send-buffer-size`
|
|
113
115
|
*
|
|
@@ -156,6 +158,11 @@ export namespace WasiSocketsTcp {
|
|
|
156
158
|
* - <https://learn.microsoft.com/en-us/windows/win32/api/winsock/nf-winsock-getpeername>
|
|
157
159
|
* - <https://man.freebsd.org/cgi/man.cgi?query=getpeername&sektion=2&n=1>
|
|
158
160
|
*/
|
|
161
|
+
/**
|
|
162
|
+
* Whether the socket is listening for new connections.
|
|
163
|
+
*
|
|
164
|
+
* Equivalent to the SO_ACCEPTCONN socket option.
|
|
165
|
+
*/
|
|
159
166
|
/**
|
|
160
167
|
* Whether this is a IPv4 or IPv6 socket.
|
|
161
168
|
*
|
|
@@ -174,21 +181,66 @@ export namespace WasiSocketsTcp {
|
|
|
174
181
|
/**
|
|
175
182
|
* Hints the desired listen queue size. Implementations are free to ignore this.
|
|
176
183
|
*
|
|
184
|
+
* If the provided value is 0, an `invalid-argument` error is returned.
|
|
185
|
+
* Any other value will never cause an error, but it might be silently clamped and/or rounded.
|
|
186
|
+
*
|
|
177
187
|
* # Typical errors
|
|
178
188
|
* - `not-supported`: (set) The platform does not support changing the backlog size after the initial listen.
|
|
189
|
+
* - `invalid-argument`: (set) The provided value was 0.
|
|
179
190
|
* - `invalid-state`: (set) The socket is already in the Connection state.
|
|
180
191
|
*/
|
|
181
192
|
/**
|
|
193
|
+
* Enables or disables keepalive.
|
|
194
|
+
*
|
|
195
|
+
* The keepalive behavior can be adjusted using:
|
|
196
|
+
* - `keep-alive-idle-time`
|
|
197
|
+
* - `keep-alive-interval`
|
|
198
|
+
* - `keep-alive-count`
|
|
199
|
+
* These properties can be configured while `keep-alive-enabled` is false, but only come into effect when `keep-alive-enabled` is true.
|
|
200
|
+
*
|
|
182
201
|
* Equivalent to the SO_KEEPALIVE socket option.
|
|
183
202
|
*/
|
|
184
203
|
/**
|
|
185
|
-
*
|
|
204
|
+
* Amount of time the connection has to be idle before TCP starts sending keepalive packets.
|
|
186
205
|
*
|
|
187
|
-
*
|
|
206
|
+
* If the provided value is 0, an `invalid-argument` error is returned.
|
|
207
|
+
* Any other value will never cause an error, but it might be silently clamped and/or rounded.
|
|
208
|
+
* I.e. after setting a value, reading the same setting back may return a different value.
|
|
209
|
+
*
|
|
210
|
+
* Equivalent to the TCP_KEEPIDLE socket option. (TCP_KEEPALIVE on MacOS)
|
|
211
|
+
*
|
|
212
|
+
* # Typical errors
|
|
213
|
+
* - `invalid-argument`: (set) The provided value was 0.
|
|
214
|
+
*/
|
|
215
|
+
/**
|
|
216
|
+
* The time between keepalive packets.
|
|
217
|
+
*
|
|
218
|
+
* If the provided value is 0, an `invalid-argument` error is returned.
|
|
219
|
+
* Any other value will never cause an error, but it might be silently clamped and/or rounded.
|
|
220
|
+
* I.e. after setting a value, reading the same setting back may return a different value.
|
|
221
|
+
*
|
|
222
|
+
* Equivalent to the TCP_KEEPINTVL socket option.
|
|
223
|
+
*
|
|
224
|
+
* # Typical errors
|
|
225
|
+
* - `invalid-argument`: (set) The provided value was 0.
|
|
226
|
+
*/
|
|
227
|
+
/**
|
|
228
|
+
* The maximum amount of keepalive packets TCP should send before aborting the connection.
|
|
229
|
+
*
|
|
230
|
+
* If the provided value is 0, an `invalid-argument` error is returned.
|
|
231
|
+
* Any other value will never cause an error, but it might be silently clamped and/or rounded.
|
|
232
|
+
* I.e. after setting a value, reading the same setting back may return a different value.
|
|
233
|
+
*
|
|
234
|
+
* Equivalent to the TCP_KEEPCNT socket option.
|
|
235
|
+
*
|
|
236
|
+
* # Typical errors
|
|
237
|
+
* - `invalid-argument`: (set) The provided value was 0.
|
|
188
238
|
*/
|
|
189
239
|
/**
|
|
190
240
|
* Equivalent to the IP_TTL & IPV6_UNICAST_HOPS socket options.
|
|
191
241
|
*
|
|
242
|
+
* If the provided value is 0, an `invalid-argument` error is returned.
|
|
243
|
+
*
|
|
192
244
|
* # Typical errors
|
|
193
245
|
* - `invalid-argument`: (set) The TTL value must be 1 or higher.
|
|
194
246
|
* - `invalid-state`: (set) The socket is already in the Connection state.
|
|
@@ -197,16 +249,14 @@ export namespace WasiSocketsTcp {
|
|
|
197
249
|
/**
|
|
198
250
|
* The kernel buffer space reserved for sends/receives on this socket.
|
|
199
251
|
*
|
|
200
|
-
*
|
|
201
|
-
*
|
|
202
|
-
*
|
|
203
|
-
* Note #2: there is not necessarily a direct relationship between the kernel buffer size and the bytes of
|
|
204
|
-
* actual data to be sent/received by the application, because the kernel might also use the buffer space
|
|
205
|
-
* for internal metadata structures.
|
|
252
|
+
* If the provided value is 0, an `invalid-argument` error is returned.
|
|
253
|
+
* Any other value will never cause an error, but it might be silently clamped and/or rounded.
|
|
254
|
+
* I.e. after setting a value, reading the same setting back may return a different value.
|
|
206
255
|
*
|
|
207
256
|
* Equivalent to the SO_RCVBUF and SO_SNDBUF socket options.
|
|
208
257
|
*
|
|
209
258
|
* # Typical errors
|
|
259
|
+
* - `invalid-argument`: (set) The provided value was 0.
|
|
210
260
|
* - `invalid-state`: (set) The socket is already in the Connection state.
|
|
211
261
|
* - `invalid-state`: (set) The socket is already in the Listener state.
|
|
212
262
|
*/
|
|
@@ -244,6 +294,8 @@ import type { OutputStream } from '../interfaces/wasi-io-streams.js';
|
|
|
244
294
|
export { OutputStream };
|
|
245
295
|
import type { Pollable } from '../interfaces/wasi-io-poll.js';
|
|
246
296
|
export { Pollable };
|
|
297
|
+
import type { Duration } from '../interfaces/wasi-clocks-monotonic-clock.js';
|
|
298
|
+
export { Duration };
|
|
247
299
|
import type { Network } from '../interfaces/wasi-sockets-network.js';
|
|
248
300
|
export { Network };
|
|
249
301
|
import type { ErrorCode } from '../interfaces/wasi-sockets-network.js';
|
|
@@ -277,16 +329,21 @@ export class TcpSocket {
|
|
|
277
329
|
accept(): [TcpSocket, InputStream, OutputStream];
|
|
278
330
|
localAddress(): IpSocketAddress;
|
|
279
331
|
remoteAddress(): IpSocketAddress;
|
|
332
|
+
isListening(): boolean;
|
|
280
333
|
addressFamily(): IpAddressFamily;
|
|
281
334
|
ipv6Only(): boolean;
|
|
282
335
|
setIpv6Only(value: boolean): void;
|
|
283
336
|
setListenBacklogSize(value: bigint): void;
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
337
|
+
keepAliveEnabled(): boolean;
|
|
338
|
+
setKeepAliveEnabled(value: boolean): void;
|
|
339
|
+
keepAliveIdleTime(): Duration;
|
|
340
|
+
setKeepAliveIdleTime(value: Duration): void;
|
|
341
|
+
keepAliveInterval(): Duration;
|
|
342
|
+
setKeepAliveInterval(value: Duration): void;
|
|
343
|
+
keepAliveCount(): number;
|
|
344
|
+
setKeepAliveCount(value: number): void;
|
|
345
|
+
hopLimit(): number;
|
|
346
|
+
setHopLimit(value: number): void;
|
|
290
347
|
receiveBufferSize(): bigint;
|
|
291
348
|
setReceiveBufferSize(value: bigint): void;
|
|
292
349
|
sendBufferSize(): bigint;
|
|
@@ -5,7 +5,7 @@ export namespace WasiSocketsUdpCreateSocket {
|
|
|
5
5
|
* Similar to `socket(AF_INET or AF_INET6, SOCK_DGRAM, IPPROTO_UDP)` in POSIX.
|
|
6
6
|
*
|
|
7
7
|
* This function does not require a network capability handle. This is considered to be safe because
|
|
8
|
-
* at time of creation, the socket is not bound to any `network` yet. Up to the moment `bind
|
|
8
|
+
* at time of creation, the socket is not bound to any `network` yet. Up to the moment `bind` is called,
|
|
9
9
|
* the socket is effectively an in-memory configuration object, unable to communicate with the outside world.
|
|
10
10
|
*
|
|
11
11
|
* All sockets are non-blocking. Use the wasi-poll interface to block on asynchronous operations.
|