@bytecodealliance/preview2-shim 0.0.8 → 0.0.10
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 +1 -0
- package/lib/browser/cli-base.js +48 -0
- package/lib/browser/clocks.js +44 -0
- package/lib/browser/filesystem.js +134 -141
- package/lib/browser/http.js +114 -0
- package/lib/browser/index.js +15 -37
- package/lib/browser/io.js +60 -20
- package/lib/browser/{console.js → logging.js} +7 -5
- package/lib/browser/poll.js +9 -7
- package/lib/browser/random.js +48 -24
- package/lib/browser/sockets.js +200 -0
- package/lib/nodejs/{preopens.js → cli-base.js} +38 -8
- package/lib/nodejs/clocks.js +44 -0
- package/lib/nodejs/filesystem.js +240 -237
- package/lib/nodejs/http.js +114 -0
- package/lib/nodejs/index.js +15 -37
- package/lib/nodejs/io.js +148 -19
- package/lib/nodejs/{console.js → logging.js} +7 -5
- package/lib/nodejs/poll.js +9 -7
- package/lib/nodejs/random.js +27 -13
- package/lib/nodejs/sockets.js +200 -0
- package/package.json +1 -1
- package/types/exports/{HTTP.d.ts → wasi-http-incoming-handler.d.ts} +1 -1
- package/types/imports/environment.d.ts +14 -1
- package/types/imports/exit.d.ts +4 -1
- package/types/imports/filesystem.d.ts +695 -48
- package/types/imports/handler.d.ts +40 -0
- package/types/imports/insecure-seed.d.ts +22 -0
- package/types/imports/insecure.d.ts +20 -0
- package/types/imports/instance-network.d.ts +4 -1
- package/types/imports/ip-name-lookup.d.ts +66 -9
- package/types/imports/monotonic-clock.d.ts +18 -2
- package/types/imports/network.d.ts +171 -9
- package/types/imports/{default-outgoing-HTTP.d.ts → outgoing-handler.d.ts} +1 -1
- package/types/imports/poll.d.ts +38 -2
- package/types/imports/preopens.d.ts +6 -9
- package/types/imports/random.d.ts +19 -2
- package/types/imports/stderr.d.ts +5 -0
- package/types/imports/stdin.d.ts +5 -0
- package/types/imports/stdout.d.ts +5 -0
- package/types/imports/streams.d.ts +161 -4
- package/types/imports/tcp-create-socket.d.ts +27 -3
- package/types/imports/tcp.d.ts +248 -15
- package/types/imports/timezone.d.ts +60 -2
- package/types/imports/types.d.ts +28 -28
- package/types/imports/udp-create-socket.d.ts +27 -3
- package/types/imports/udp.d.ts +195 -12
- package/types/imports/wall-clock.d.ts +24 -1
- package/types/wasi-command.d.ts +23 -0
- package/types/wasi-proxy.d.ts +10 -44
- package/types/wasi-reactor.d.ts +23 -70
- package/lib/browser/default-outgoing-HTTP.js +0 -3
- package/lib/browser/environment.js +0 -17
- package/lib/browser/exit.js +0 -21
- package/lib/browser/instance-network.js +0 -3
- package/lib/browser/ip-name-lookup.js +0 -23
- package/lib/browser/monotonic-clock.js +0 -14
- package/lib/browser/network.js +0 -3
- package/lib/browser/preopens.js +0 -11
- package/lib/browser/stderr.js +0 -4
- package/lib/browser/streams.js +0 -60
- package/lib/browser/tcp-create-socket.js +0 -3
- package/lib/browser/tcp.js +0 -75
- package/lib/browser/timezone.js +0 -12
- package/lib/browser/types.js +0 -99
- package/lib/browser/udp-create-socket.js +0 -3
- package/lib/browser/udp.js +0 -75
- package/lib/browser/wall-clock.js +0 -9
- package/lib/nodejs/default-outgoing-HTTP.js +0 -3
- package/lib/nodejs/environment.js +0 -19
- package/lib/nodejs/exit.js +0 -3
- package/lib/nodejs/instance-network.js +0 -3
- package/lib/nodejs/ip-name-lookup.js +0 -23
- package/lib/nodejs/monotonic-clock.js +0 -14
- package/lib/nodejs/network.js +0 -3
- package/lib/nodejs/stderr.js +0 -4
- package/lib/nodejs/streams.js +0 -97
- package/lib/nodejs/tcp-create-socket.js +0 -3
- package/lib/nodejs/tcp.js +0 -75
- package/lib/nodejs/timezone.js +0 -12
- package/lib/nodejs/types.js +0 -99
- package/lib/nodejs/udp-create-socket.js +0 -3
- package/lib/nodejs/udp.js +0 -75
- package/lib/nodejs/wall-clock.js +0 -9
- package/types/imports/console.d.ts +0 -17
- package/types/index.d.ts +0 -8
|
@@ -1,9 +1,33 @@
|
|
|
1
|
-
export namespace
|
|
1
|
+
export namespace ImportsUdpCreateSocket {
|
|
2
|
+
/**
|
|
3
|
+
* Create a new UDP socket.
|
|
4
|
+
*
|
|
5
|
+
* Similar to `socket(AF_INET or AF_INET6, SOCK_DGRAM, IPPROTO_UDP)` in POSIX.
|
|
6
|
+
*
|
|
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`/`connect` is called,
|
|
9
|
+
* the socket is effectively an in-memory configuration object, unable to communicate with the outside world.
|
|
10
|
+
*
|
|
11
|
+
* All sockets are non-blocking. Use the wasi-poll interface to block on asynchronous operations.
|
|
12
|
+
*
|
|
13
|
+
* # Typical errors
|
|
14
|
+
* - `not-supported`: The host does not support UDP sockets. (EOPNOTSUPP)
|
|
15
|
+
* - `address-family-not-supported`: The specified `address-family` is not supported. (EAFNOSUPPORT)
|
|
16
|
+
* - `new-socket-limit`: The new socket resource could not be created because of a system limit. (EMFILE, ENFILE)
|
|
17
|
+
*
|
|
18
|
+
* # References:
|
|
19
|
+
* - <https://pubs.opengroup.org/onlinepubs/9699919799/functions/socket.html>
|
|
20
|
+
* - <https://man7.org/linux/man-pages/man2/socket.2.html>
|
|
21
|
+
* - <https://learn.microsoft.com/en-us/windows/win32/api/winsock2/nf-winsock2-wsasocketw>
|
|
22
|
+
* - <https://man.freebsd.org/cgi/man.cgi?query=socket&sektion=2>
|
|
23
|
+
*/
|
|
2
24
|
export function createUdpSocket(addressFamily: IpAddressFamily): UdpSocket;
|
|
3
25
|
}
|
|
26
|
+
import type { Network } from '../imports/network';
|
|
27
|
+
export { Network };
|
|
28
|
+
import type { ErrorCode } from '../imports/network';
|
|
29
|
+
export { ErrorCode };
|
|
4
30
|
import type { IpAddressFamily } from '../imports/network';
|
|
5
31
|
export { IpAddressFamily };
|
|
6
32
|
import type { UdpSocket } from '../imports/udp';
|
|
7
33
|
export { UdpSocket };
|
|
8
|
-
import type { Error } from '../imports/network';
|
|
9
|
-
export { Error };
|
package/types/imports/udp.d.ts
CHANGED
|
@@ -1,36 +1,219 @@
|
|
|
1
|
-
export namespace
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
export namespace ImportsUdp {
|
|
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 a message.
|
|
68
|
+
*
|
|
69
|
+
* Returns:
|
|
70
|
+
* - The sender address of the datagram
|
|
71
|
+
* - The number of bytes read.
|
|
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://learn.microsoft.com/en-us/windows/win32/api/winsock/nf-winsock-recv>
|
|
83
|
+
* - <https://learn.microsoft.com/en-us/windows/win32/api/winsock/nf-winsock-recvfrom>
|
|
84
|
+
* - <https://learn.microsoft.com/en-us/previous-versions/windows/desktop/legacy/ms741687(v=vs.85)>
|
|
85
|
+
* - <https://man.freebsd.org/cgi/man.cgi?query=recv&sektion=2>
|
|
86
|
+
*/
|
|
4
87
|
export function receive(this: UdpSocket): Datagram;
|
|
88
|
+
/**
|
|
89
|
+
* Send a message to a specific destination address.
|
|
90
|
+
*
|
|
91
|
+
* The remote address option is required. To send a message to the "connected" peer,
|
|
92
|
+
* call `remote-address` to get their address.
|
|
93
|
+
*
|
|
94
|
+
* # Typical errors
|
|
95
|
+
* - `address-family-mismatch`: The `remote-address` has the wrong address family. (EAFNOSUPPORT)
|
|
96
|
+
* - `invalid-remote-address`: The IP address in `remote-address` is set to INADDR_ANY (`0.0.0.0` / `::`). (EDESTADDRREQ, EADDRNOTAVAIL)
|
|
97
|
+
* - `invalid-remote-address`: The port in `remote-address` is set to 0. (EDESTADDRREQ, EADDRNOTAVAIL)
|
|
98
|
+
* - `already-connected`: The socket is in "connected" mode and the `datagram.remote-address` does not match the address passed to `connect`. (EISCONN)
|
|
99
|
+
* - `not-bound`: The socket is not bound to any local address. Unlike POSIX, this function does not perform an implicit bind.
|
|
100
|
+
* - `remote-unreachable`: The remote address is not reachable. (ECONNREFUSED, ECONNRESET, ENETRESET on Windows, EHOSTUNREACH, EHOSTDOWN, ENETUNREACH, ENETDOWN)
|
|
101
|
+
* - `datagram-too-large`: The datagram is too large. (EMSGSIZE)
|
|
102
|
+
* - `would-block`: The send buffer is currently full. (EWOULDBLOCK, EAGAIN)
|
|
103
|
+
*
|
|
104
|
+
* # References
|
|
105
|
+
* - <https://pubs.opengroup.org/onlinepubs/9699919799/functions/sendto.html>
|
|
106
|
+
* - <https://pubs.opengroup.org/onlinepubs/9699919799/functions/sendmsg.html>
|
|
107
|
+
* - <https://man7.org/linux/man-pages/man2/send.2.html>
|
|
108
|
+
* - <https://learn.microsoft.com/en-us/windows/win32/api/winsock2/nf-winsock2-send>
|
|
109
|
+
* - <https://learn.microsoft.com/en-us/windows/win32/api/winsock2/nf-winsock2-sendto>
|
|
110
|
+
* - <https://learn.microsoft.com/en-us/windows/win32/api/winsock2/nf-winsock2-wsasendmsg>
|
|
111
|
+
* - <https://man.freebsd.org/cgi/man.cgi?query=send&sektion=2>
|
|
112
|
+
*/
|
|
5
113
|
export function send(this: UdpSocket, datagram: Datagram): void;
|
|
114
|
+
/**
|
|
115
|
+
* Get the current bound address.
|
|
116
|
+
*
|
|
117
|
+
* # Typical errors
|
|
118
|
+
* - `not-bound`: The socket is not bound to any local address.
|
|
119
|
+
*
|
|
120
|
+
* # References
|
|
121
|
+
* - <https://pubs.opengroup.org/onlinepubs/9699919799/functions/getsockname.html>
|
|
122
|
+
* - <https://man7.org/linux/man-pages/man2/getsockname.2.html>
|
|
123
|
+
* - <https://learn.microsoft.com/en-us/windows/win32/api/winsock/nf-winsock-getsockname>
|
|
124
|
+
* - <https://man.freebsd.org/cgi/man.cgi?getsockname>
|
|
125
|
+
*/
|
|
6
126
|
export function localAddress(this: UdpSocket): IpSocketAddress;
|
|
127
|
+
/**
|
|
128
|
+
* Get the address set with `connect`.
|
|
129
|
+
*
|
|
130
|
+
* # Typical errors
|
|
131
|
+
* - `not-connected`: The socket is not connected to a remote address. (ENOTCONN)
|
|
132
|
+
*
|
|
133
|
+
* # References
|
|
134
|
+
* - <https://pubs.opengroup.org/onlinepubs/9699919799/functions/getpeername.html>
|
|
135
|
+
* - <https://man7.org/linux/man-pages/man2/getpeername.2.html>
|
|
136
|
+
* - <https://learn.microsoft.com/en-us/windows/win32/api/winsock/nf-winsock-getpeername>
|
|
137
|
+
* - <https://man.freebsd.org/cgi/man.cgi?query=getpeername&sektion=2&n=1>
|
|
138
|
+
*/
|
|
7
139
|
export function remoteAddress(this: UdpSocket): IpSocketAddress;
|
|
140
|
+
/**
|
|
141
|
+
* Whether this is a IPv4 or IPv6 socket.
|
|
142
|
+
*
|
|
143
|
+
* Equivalent to the SO_DOMAIN socket option.
|
|
144
|
+
*/
|
|
8
145
|
export function addressFamily(this: UdpSocket): IpAddressFamily;
|
|
146
|
+
/**
|
|
147
|
+
* Whether IPv4 compatibility (dual-stack) mode is disabled or not.
|
|
148
|
+
*
|
|
149
|
+
* Equivalent to the IPV6_V6ONLY socket option.
|
|
150
|
+
*
|
|
151
|
+
* # Typical errors
|
|
152
|
+
* - `ipv6-only-operation`: (get/set) `this` socket is an IPv4 socket.
|
|
153
|
+
* - `already-bound`: (set) The socket is already bound.
|
|
154
|
+
* - `not-supported`: (set) Host does not support dual-stack sockets. (Implementations are not required to.)
|
|
155
|
+
* - `concurrency-conflict`: (set) Another `bind` or `connect` operation is already in progress. (EALREADY)
|
|
156
|
+
*/
|
|
9
157
|
export function ipv6Only(this: UdpSocket): boolean;
|
|
10
158
|
export function setIpv6Only(this: UdpSocket, value: boolean): void;
|
|
159
|
+
/**
|
|
160
|
+
* Equivalent to the IP_TTL & IPV6_UNICAST_HOPS socket options.
|
|
161
|
+
*
|
|
162
|
+
* # Typical errors
|
|
163
|
+
* - `concurrency-conflict`: (set) Another `bind` or `connect` operation is already in progress. (EALREADY)
|
|
164
|
+
*/
|
|
11
165
|
export function unicastHopLimit(this: UdpSocket): number;
|
|
12
166
|
export function setUnicastHopLimit(this: UdpSocket, value: number): void;
|
|
167
|
+
/**
|
|
168
|
+
* The kernel buffer space reserved for sends/receives on this socket.
|
|
169
|
+
*
|
|
170
|
+
* Note #1: an implementation may choose to cap or round the buffer size when setting the value.
|
|
171
|
+
* In other words, after setting a value, reading the same setting back may return a different value.
|
|
172
|
+
*
|
|
173
|
+
* Note #2: there is not necessarily a direct relationship between the kernel buffer size and the bytes of
|
|
174
|
+
* actual data to be sent/received by the application, because the kernel might also use the buffer space
|
|
175
|
+
* for internal metadata structures.
|
|
176
|
+
*
|
|
177
|
+
* Fails when this socket is in the Listening state.
|
|
178
|
+
*
|
|
179
|
+
* Equivalent to the SO_RCVBUF and SO_SNDBUF socket options.
|
|
180
|
+
*
|
|
181
|
+
* # Typical errors
|
|
182
|
+
* - `concurrency-conflict`: (set) Another `bind` or `connect` operation is already in progress. (EALREADY)
|
|
183
|
+
*/
|
|
13
184
|
export function receiveBufferSize(this: UdpSocket): bigint;
|
|
14
185
|
export function setReceiveBufferSize(this: UdpSocket, value: bigint): void;
|
|
15
186
|
export function sendBufferSize(this: UdpSocket): bigint;
|
|
16
187
|
export function setSendBufferSize(this: UdpSocket, value: bigint): void;
|
|
17
|
-
|
|
18
|
-
|
|
188
|
+
/**
|
|
189
|
+
* Create a `pollable` which will resolve once the socket is ready for I/O.
|
|
190
|
+
*
|
|
191
|
+
* Note: this function is here for WASI Preview2 only.
|
|
192
|
+
* It's planned to be removed when `future` is natively supported in Preview3.
|
|
193
|
+
*/
|
|
19
194
|
export function subscribe(this: UdpSocket): Pollable;
|
|
195
|
+
/**
|
|
196
|
+
* Dispose of the specified `udp-socket`, after which it may no longer be used.
|
|
197
|
+
*
|
|
198
|
+
* Note: this function is scheduled to be removed when Resources are natively supported in Wit.
|
|
199
|
+
*/
|
|
20
200
|
export function dropUdpSocket(this: UdpSocket): void;
|
|
21
201
|
}
|
|
22
|
-
|
|
202
|
+
import type { Pollable } from '../imports/poll';
|
|
203
|
+
export { Pollable };
|
|
23
204
|
import type { Network } from '../imports/network';
|
|
24
205
|
export { Network };
|
|
206
|
+
import type { ErrorCode } from '../imports/network';
|
|
207
|
+
export { ErrorCode };
|
|
25
208
|
import type { IpSocketAddress } from '../imports/network';
|
|
26
209
|
export { IpSocketAddress };
|
|
27
|
-
import type {
|
|
28
|
-
export {
|
|
210
|
+
import type { IpAddressFamily } from '../imports/network';
|
|
211
|
+
export { IpAddressFamily };
|
|
212
|
+
/**
|
|
213
|
+
* A UDP socket handle.
|
|
214
|
+
*/
|
|
215
|
+
export type UdpSocket = number;
|
|
29
216
|
export interface Datagram {
|
|
30
217
|
data: Uint8Array,
|
|
31
218
|
remoteAddress: IpSocketAddress,
|
|
32
219
|
}
|
|
33
|
-
import type { IpAddressFamily } from '../imports/network';
|
|
34
|
-
export { IpAddressFamily };
|
|
35
|
-
import type { Pollable } from '../imports/poll';
|
|
36
|
-
export { Pollable };
|
|
@@ -1,7 +1,30 @@
|
|
|
1
|
-
export namespace
|
|
1
|
+
export namespace ImportsWallClock {
|
|
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
|
+
*/
|
|
2
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
|
+
*/
|
|
3
23
|
export function resolution(): Datetime;
|
|
4
24
|
}
|
|
25
|
+
/**
|
|
26
|
+
* A time and date in seconds plus nanoseconds.
|
|
27
|
+
*/
|
|
5
28
|
export interface Datetime {
|
|
6
29
|
seconds: bigint,
|
|
7
30
|
nanoseconds: number,
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { ImportsEnvironment } from './imports/environment';
|
|
2
|
+
import { ImportsExit } from './imports/exit';
|
|
3
|
+
import { ImportsPreopens } from './imports/preopens';
|
|
4
|
+
import { ImportsStderr } from './imports/stderr';
|
|
5
|
+
import { ImportsStdin } from './imports/stdin';
|
|
6
|
+
import { ImportsStdout } from './imports/stdout';
|
|
7
|
+
import { ImportsMonotonicClock } from './imports/monotonic-clock';
|
|
8
|
+
import { ImportsTimezone } from './imports/timezone';
|
|
9
|
+
import { ImportsWallClock } from './imports/wall-clock';
|
|
10
|
+
import { ImportsFilesystem } from './imports/filesystem';
|
|
11
|
+
import { ImportsStreams } from './imports/streams';
|
|
12
|
+
import { ImportsPoll } from './imports/poll';
|
|
13
|
+
import { ImportsInsecure } from './imports/insecure';
|
|
14
|
+
import { ImportsInsecureSeed } from './imports/insecure-seed';
|
|
15
|
+
import { ImportsRandom } from './imports/random';
|
|
16
|
+
import { ImportsInstanceNetwork } from './imports/instance-network';
|
|
17
|
+
import { ImportsIpNameLookup } from './imports/ip-name-lookup';
|
|
18
|
+
import { ImportsNetwork } from './imports/network';
|
|
19
|
+
import { ImportsTcp } from './imports/tcp';
|
|
20
|
+
import { ImportsTcpCreateSocket } from './imports/tcp-create-socket';
|
|
21
|
+
import { ImportsUdp } from './imports/udp';
|
|
22
|
+
import { ImportsUdpCreateSocket } from './imports/udp-create-socket';
|
|
23
|
+
export function run(): void;
|
package/types/wasi-proxy.d.ts
CHANGED
|
@@ -1,44 +1,10 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
'poll': typeof PollImports,
|
|
12
|
-
'streams': typeof StreamsImports,
|
|
13
|
-
'types': typeof TypesImports,
|
|
14
|
-
'default-outgoing-HTTP': typeof DefaultOutgoingHttpImports,
|
|
15
|
-
}
|
|
16
|
-
export interface WasiProxy {
|
|
17
|
-
'HTTP': typeof HttpExports,
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
/**
|
|
21
|
-
* Instantiates this component with the provided imports and
|
|
22
|
-
* returns a map of all the exports of the component.
|
|
23
|
-
*
|
|
24
|
-
* This function is intended to be similar to the
|
|
25
|
-
* `WebAssembly.instantiate` function. The second `imports`
|
|
26
|
-
* argument is the "import object" for wasm, except here it
|
|
27
|
-
* uses component-model-layer types instead of core wasm
|
|
28
|
-
* integers/numbers/etc.
|
|
29
|
-
*
|
|
30
|
-
* The first argument to this function, `compileCore`, is
|
|
31
|
-
* used to compile core wasm modules within the component.
|
|
32
|
-
* Components are composed of core wasm modules and this callback
|
|
33
|
-
* will be invoked per core wasm module. The caller of this
|
|
34
|
-
* function is responsible for reading the core wasm module
|
|
35
|
-
* identified by `path` and returning its compiled
|
|
36
|
-
* WebAssembly.Module object. This would use `compileStreaming`
|
|
37
|
-
* on the web, for example.
|
|
38
|
-
*/
|
|
39
|
-
export function instantiate(
|
|
40
|
-
compileCore: (path: string, imports: Record<string, any>) => Promise<WebAssembly.Module>,
|
|
41
|
-
imports: ImportObject,
|
|
42
|
-
instantiateCore?: (module: WebAssembly.Module, imports: Record<string, any>) => Promise<WebAssembly.Instance>
|
|
43
|
-
): Promise<WasiProxy>;
|
|
44
|
-
|
|
1
|
+
import { ImportsOutgoingHandler } from './imports/outgoing-handler';
|
|
2
|
+
import { ImportsTypes } from './imports/types';
|
|
3
|
+
import { ImportsStreams } from './imports/streams';
|
|
4
|
+
import { ImportsHandler } from './imports/handler';
|
|
5
|
+
import { ImportsPoll } from './imports/poll';
|
|
6
|
+
import { ImportsInsecure } from './imports/insecure';
|
|
7
|
+
import { ImportsInsecureSeed } from './imports/insecure-seed';
|
|
8
|
+
import { ImportsRandom } from './imports/random';
|
|
9
|
+
import { ExportsWasiHttpIncomingHandler } from './exports/wasi-http-incoming-handler';
|
|
10
|
+
export const incomingHandler: typeof ExportsWasiHttpIncomingHandler;
|
package/types/wasi-reactor.d.ts
CHANGED
|
@@ -1,70 +1,23 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
9
|
-
import {
|
|
10
|
-
import {
|
|
11
|
-
import {
|
|
12
|
-
import {
|
|
13
|
-
import {
|
|
14
|
-
import {
|
|
15
|
-
import {
|
|
16
|
-
import {
|
|
17
|
-
import {
|
|
18
|
-
import {
|
|
19
|
-
import {
|
|
20
|
-
import {
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
'monotonic-clock': typeof MonotonicClockImports,
|
|
25
|
-
'timezone': typeof TimezoneImports,
|
|
26
|
-
'streams': typeof StreamsImports,
|
|
27
|
-
'filesystem': typeof FilesystemImports,
|
|
28
|
-
'network': typeof NetworkImports,
|
|
29
|
-
'instance-network': typeof InstanceNetworkImports,
|
|
30
|
-
'ip-name-lookup': typeof IpNameLookupImports,
|
|
31
|
-
'tcp': typeof TcpImports,
|
|
32
|
-
'tcp-create-socket': typeof TcpCreateSocketImports,
|
|
33
|
-
'udp': typeof UdpImports,
|
|
34
|
-
'udp-create-socket': typeof UdpCreateSocketImports,
|
|
35
|
-
'random': typeof RandomImports,
|
|
36
|
-
'console': typeof ConsoleImports,
|
|
37
|
-
'types': typeof TypesImports,
|
|
38
|
-
'default-outgoing-HTTP': typeof DefaultOutgoingHttpImports,
|
|
39
|
-
'environment': typeof EnvironmentImports,
|
|
40
|
-
'preopens': typeof PreopensImports,
|
|
41
|
-
'exit': typeof ExitImports,
|
|
42
|
-
}
|
|
43
|
-
export interface WasiReactor {
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
/**
|
|
47
|
-
* Instantiates this component with the provided imports and
|
|
48
|
-
* returns a map of all the exports of the component.
|
|
49
|
-
*
|
|
50
|
-
* This function is intended to be similar to the
|
|
51
|
-
* `WebAssembly.instantiate` function. The second `imports`
|
|
52
|
-
* argument is the "import object" for wasm, except here it
|
|
53
|
-
* uses component-model-layer types instead of core wasm
|
|
54
|
-
* integers/numbers/etc.
|
|
55
|
-
*
|
|
56
|
-
* The first argument to this function, `compileCore`, is
|
|
57
|
-
* used to compile core wasm modules within the component.
|
|
58
|
-
* Components are composed of core wasm modules and this callback
|
|
59
|
-
* will be invoked per core wasm module. The caller of this
|
|
60
|
-
* function is responsible for reading the core wasm module
|
|
61
|
-
* identified by `path` and returning its compiled
|
|
62
|
-
* WebAssembly.Module object. This would use `compileStreaming`
|
|
63
|
-
* on the web, for example.
|
|
64
|
-
*/
|
|
65
|
-
export function instantiate(
|
|
66
|
-
compileCore: (path: string, imports: Record<string, any>) => Promise<WebAssembly.Module>,
|
|
67
|
-
imports: ImportObject,
|
|
68
|
-
instantiateCore?: (module: WebAssembly.Module, imports: Record<string, any>) => Promise<WebAssembly.Instance>
|
|
69
|
-
): Promise<WasiReactor>;
|
|
70
|
-
|
|
1
|
+
import { ImportsEnvironment } from './imports/environment';
|
|
2
|
+
import { ImportsExit } from './imports/exit';
|
|
3
|
+
import { ImportsPreopens } from './imports/preopens';
|
|
4
|
+
import { ImportsStderr } from './imports/stderr';
|
|
5
|
+
import { ImportsStdin } from './imports/stdin';
|
|
6
|
+
import { ImportsStdout } from './imports/stdout';
|
|
7
|
+
import { ImportsMonotonicClock } from './imports/monotonic-clock';
|
|
8
|
+
import { ImportsTimezone } from './imports/timezone';
|
|
9
|
+
import { ImportsWallClock } from './imports/wall-clock';
|
|
10
|
+
import { ImportsFilesystem } from './imports/filesystem';
|
|
11
|
+
import { ImportsOutgoingHandler } from './imports/outgoing-handler';
|
|
12
|
+
import { ImportsTypes } from './imports/types';
|
|
13
|
+
import { ImportsStreams } from './imports/streams';
|
|
14
|
+
import { ImportsHandler } from './imports/handler';
|
|
15
|
+
import { ImportsPoll } from './imports/poll';
|
|
16
|
+
import { ImportsRandom } from './imports/random';
|
|
17
|
+
import { ImportsInstanceNetwork } from './imports/instance-network';
|
|
18
|
+
import { ImportsIpNameLookup } from './imports/ip-name-lookup';
|
|
19
|
+
import { ImportsNetwork } from './imports/network';
|
|
20
|
+
import { ImportsTcp } from './imports/tcp';
|
|
21
|
+
import { ImportsTcpCreateSocket } from './imports/tcp-create-socket';
|
|
22
|
+
import { ImportsUdp } from './imports/udp';
|
|
23
|
+
import { ImportsUdpCreateSocket } from './imports/udp-create-socket';
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
let _env;
|
|
2
|
-
export function _setEnv (envObj) {
|
|
3
|
-
_env = Object.entries(envObj);
|
|
4
|
-
}
|
|
5
|
-
|
|
6
|
-
export function getEnvironment () {
|
|
7
|
-
if (!_env) _env = [];
|
|
8
|
-
return _env;
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
export function preopens () {
|
|
12
|
-
return [];
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
export function getArguments () {
|
|
16
|
-
return [];
|
|
17
|
-
}
|
package/lib/browser/exit.js
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
class FailureExit extends Error {
|
|
2
|
-
code = 1;
|
|
3
|
-
constructor() {
|
|
4
|
-
super("failure-exit");
|
|
5
|
-
}
|
|
6
|
-
}
|
|
7
|
-
|
|
8
|
-
class SuccessfulExit extends Error {
|
|
9
|
-
code = 0;
|
|
10
|
-
constructor() {
|
|
11
|
-
super("successful-exit");
|
|
12
|
-
}
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
export function exit(status) {
|
|
16
|
-
console.log(`[exit] Exit: ${JSON.stringify(status)}`);
|
|
17
|
-
if (status.tag === "err") {
|
|
18
|
-
throw new FailureExit();
|
|
19
|
-
}
|
|
20
|
-
throw new SuccessfulExit();
|
|
21
|
-
}
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
export function dropResolveAddressStream () {
|
|
2
|
-
|
|
3
|
-
}
|
|
4
|
-
|
|
5
|
-
export function subscribe () {
|
|
6
|
-
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
export function resolveAddresses () {
|
|
10
|
-
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
export function resolveNextAddress () {
|
|
14
|
-
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
export function nonBlocking () {
|
|
18
|
-
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
export function setNonBlocking () {
|
|
22
|
-
|
|
23
|
-
}
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
|
|
2
|
-
export function resolution(clock) {
|
|
3
|
-
console.log(`[monotonic-clock] Monotonic clock resolution ${clock}`);
|
|
4
|
-
}
|
|
5
|
-
|
|
6
|
-
function _hrtimeBigint () {
|
|
7
|
-
return BigInt(Math.floor(performance.now() * 1e9));
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
let _hrStart = _hrtimeBigint();
|
|
11
|
-
|
|
12
|
-
export function now () {
|
|
13
|
-
return _hrtimeBigint() - _hrStart;
|
|
14
|
-
}
|
package/lib/browser/network.js
DELETED
package/lib/browser/preopens.js
DELETED
package/lib/browser/stderr.js
DELETED
package/lib/browser/streams.js
DELETED
|
@@ -1,60 +0,0 @@
|
|
|
1
|
-
export function read(s, _len) {
|
|
2
|
-
console.log(`[streams] Read ${s}`);
|
|
3
|
-
}
|
|
4
|
-
export function blockingRead(s, _len) {
|
|
5
|
-
console.log(`[streams] Blocking read ${s}`);
|
|
6
|
-
}
|
|
7
|
-
export function skip(s, _len) {
|
|
8
|
-
console.log(`[streams] Skip ${s}`);
|
|
9
|
-
}
|
|
10
|
-
export function blockingSkip(s, _len) {
|
|
11
|
-
console.log(`[streams] Blocking skip ${s}`);
|
|
12
|
-
}
|
|
13
|
-
export function subscribeToInputStream(s) {
|
|
14
|
-
console.log(`[streams] Subscribe to input stream ${s}`);
|
|
15
|
-
}
|
|
16
|
-
export function dropInputStream(s) {
|
|
17
|
-
console.log(`[streams] Drop input stream ${s}`);
|
|
18
|
-
}
|
|
19
|
-
export function write(s, buf) {
|
|
20
|
-
switch (s) {
|
|
21
|
-
case 0:
|
|
22
|
-
throw new Error(`TODO: write stdin`);
|
|
23
|
-
case 1: {
|
|
24
|
-
const decoder = new TextDecoder();
|
|
25
|
-
console.log(decoder.decode(buf));
|
|
26
|
-
return BigInt(buf.byteLength);
|
|
27
|
-
}
|
|
28
|
-
case 2: {
|
|
29
|
-
const decoder = new TextDecoder();
|
|
30
|
-
console.error(decoder.decode(buf));
|
|
31
|
-
return BigInt(buf.byteLength);
|
|
32
|
-
}
|
|
33
|
-
default:
|
|
34
|
-
throw new Error(`TODO: write ${s}`);
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
export function blockingWrite(s, _buf) {
|
|
38
|
-
console.log(`[streams] Blocking write ${s}`);
|
|
39
|
-
}
|
|
40
|
-
export function writeZeroes(s, _len) {
|
|
41
|
-
console.log(`[streams] Write zeroes ${s}`);
|
|
42
|
-
}
|
|
43
|
-
export function blockingWriteZeroes(s, _len) {
|
|
44
|
-
console.log(`[streams] Blocking write zeroes ${s}`);
|
|
45
|
-
}
|
|
46
|
-
export function splice(s, _src, _len) {
|
|
47
|
-
console.log(`[streams] Splice ${s}`);
|
|
48
|
-
}
|
|
49
|
-
export function blockingSplice(s, _src, _len) {
|
|
50
|
-
console.log(`[streams] Blocking splice ${s}`);
|
|
51
|
-
}
|
|
52
|
-
export function forward(s, _src) {
|
|
53
|
-
console.log(`[streams] Forward ${s}`);
|
|
54
|
-
}
|
|
55
|
-
export function subscribeToOutputStream(s) {
|
|
56
|
-
console.log(`[streams] Subscribe to output stream ${s}`);
|
|
57
|
-
}
|
|
58
|
-
export function dropOutputStream(s) {
|
|
59
|
-
console.log(`[streams] Drop output stream ${s}`);
|
|
60
|
-
}
|