@bytecodealliance/preview2-shim 0.0.7 → 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.
- package/README.md +4 -3
- package/lib/browser/cli-base.js +57 -0
- package/lib/browser/clocks.js +50 -0
- package/lib/browser/filesystem.js +134 -141
- package/lib/browser/http.js +120 -0
- package/lib/browser/index.js +14 -20
- package/lib/browser/io.js +62 -20
- package/lib/browser/logging.js +8 -4
- package/lib/browser/poll.js +10 -6
- package/lib/browser/random.js +32 -25
- package/lib/browser/sockets.js +203 -0
- package/lib/nodejs/cli-base.js +108 -0
- package/lib/nodejs/clocks.js +50 -0
- package/lib/nodejs/filesystem.js +313 -150
- package/lib/nodejs/http.js +120 -0
- package/lib/nodejs/index.js +14 -20
- package/lib/nodejs/io.js +138 -19
- package/lib/nodejs/logging.js +8 -4
- package/lib/nodejs/poll.js +10 -6
- package/lib/nodejs/random.js +18 -13
- package/lib/nodejs/sockets.js +203 -0
- package/package.json +1 -1
- package/types/exports/{HTTP.d.ts → http-incoming-handler.d.ts} +1 -1
- package/types/imports/cli-base-environment.d.ts +17 -0
- package/types/imports/{exit.d.ts → cli-base-exit.d.ts} +4 -1
- package/types/imports/{preopens.d.ts → cli-base-preopens.d.ts} +6 -9
- package/types/imports/cli-base-stderr.d.ts +5 -0
- package/types/imports/cli-base-stdin.d.ts +5 -0
- package/types/imports/cli-base-stdout.d.ts +5 -0
- package/types/imports/clocks-monotonic-clock.d.ts +24 -0
- package/types/imports/clocks-timezone.d.ts +71 -0
- package/types/imports/clocks-wall-clock.d.ts +31 -0
- package/types/imports/filesystem-filesystem.d.ts +857 -0
- package/types/imports/{default-outgoing-HTTP.d.ts → http-outgoing-handler.d.ts} +1 -1
- package/types/imports/{types.d.ts → http-types.d.ts} +28 -28
- package/types/imports/io-streams.d.ts +180 -0
- package/types/imports/logging-handler.d.ts +40 -0
- package/types/imports/poll-poll.d.ts +41 -0
- package/types/imports/random-insecure-seed.d.ts +22 -0
- package/types/imports/random-insecure.d.ts +20 -0
- package/types/imports/random-random.d.ts +22 -0
- package/types/imports/{instance-network.d.ts → sockets-instance-network.d.ts} +4 -1
- package/types/imports/sockets-ip-name-lookup.d.ts +76 -0
- package/types/imports/sockets-network.d.ts +212 -0
- package/types/imports/sockets-tcp-create-socket.d.ts +33 -0
- package/types/imports/sockets-tcp.d.ts +285 -0
- package/types/imports/sockets-udp-create-socket.d.ts +33 -0
- package/types/imports/sockets-udp.d.ts +219 -0
- package/types/wasi-command.d.ts +23 -0
- package/types/wasi-proxy.d.ts +11 -44
- package/types/wasi-reactor.d.ts +23 -70
- package/lib/browser/default-outgoing-HTTP.js +0 -3
- package/lib/browser/environment.js +0 -3
- package/lib/browser/exit.js +0 -21
- package/lib/browser/monotonic-clock.js +0 -35
- package/lib/browser/preopens.js +0 -11
- package/lib/browser/stderr.js +0 -4
- package/lib/browser/streams.js +0 -60
- package/lib/browser/timezone.js +0 -12
- package/lib/browser/types.js +0 -99
- package/lib/browser/wall-clock.js +0 -12
- package/lib/nodejs/default-outgoing-HTTP.js +0 -3
- package/lib/nodejs/environment.js +0 -7
- package/lib/nodejs/exit.js +0 -4
- package/lib/nodejs/monotonic-clock.js +0 -14
- package/lib/nodejs/preopens.js +0 -11
- package/lib/nodejs/stderr.js +0 -4
- package/lib/nodejs/streams.js +0 -63
- package/lib/nodejs/timezone.js +0 -12
- package/lib/nodejs/types.js +0 -99
- package/lib/nodejs/wall-clock.js +0 -12
- package/types/imports/console.d.ts +0 -17
- package/types/imports/environment.d.ts +0 -4
- package/types/imports/filesystem.d.ts +0 -212
- package/types/imports/ip-name-lookup.d.ts +0 -19
- package/types/imports/monotonic-clock.d.ts +0 -8
- package/types/imports/network.d.ts +0 -50
- package/types/imports/poll.d.ts +0 -5
- package/types/imports/random.d.ts +0 -5
- package/types/imports/streams.d.ts +0 -23
- package/types/imports/tcp-create-socket.d.ts +0 -9
- package/types/imports/tcp.d.ts +0 -52
- package/types/imports/timezone.d.ts +0 -13
- package/types/imports/udp-create-socket.d.ts +0 -9
- package/types/imports/udp.d.ts +0 -36
- package/types/imports/wall-clock.d.ts +0 -8
- package/types/index.d.ts +0 -8
|
@@ -0,0 +1,219 @@
|
|
|
1
|
+
export namespace SocketsUdp {
|
|
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
|
+
*/
|
|
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
|
+
*/
|
|
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
|
+
*/
|
|
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
|
+
*/
|
|
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
|
+
*/
|
|
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
|
+
*/
|
|
157
|
+
export function ipv6Only(this: UdpSocket): boolean;
|
|
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
|
+
*/
|
|
165
|
+
export function unicastHopLimit(this: UdpSocket): number;
|
|
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
|
+
*/
|
|
184
|
+
export function receiveBufferSize(this: UdpSocket): bigint;
|
|
185
|
+
export function setReceiveBufferSize(this: UdpSocket, value: bigint): void;
|
|
186
|
+
export function sendBufferSize(this: UdpSocket): bigint;
|
|
187
|
+
export function setSendBufferSize(this: UdpSocket, value: bigint): void;
|
|
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
|
+
*/
|
|
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
|
+
*/
|
|
200
|
+
export function dropUdpSocket(this: UdpSocket): void;
|
|
201
|
+
}
|
|
202
|
+
import type { Pollable } from '../imports/poll';
|
|
203
|
+
export { Pollable };
|
|
204
|
+
import type { Network } from '../imports/network';
|
|
205
|
+
export { Network };
|
|
206
|
+
import type { ErrorCode } from '../imports/network';
|
|
207
|
+
export { ErrorCode };
|
|
208
|
+
import type { IpSocketAddress } from '../imports/network';
|
|
209
|
+
export { IpSocketAddress };
|
|
210
|
+
import type { IpAddressFamily } from '../imports/network';
|
|
211
|
+
export { IpAddressFamily };
|
|
212
|
+
/**
|
|
213
|
+
* A UDP socket handle.
|
|
214
|
+
*/
|
|
215
|
+
export type UdpSocket = number;
|
|
216
|
+
export interface Datagram {
|
|
217
|
+
data: Uint8Array,
|
|
218
|
+
remoteAddress: IpSocketAddress,
|
|
219
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { CliBaseEnvironment as CliBaseEnvironmentImports } from './imports/cli-base-environment';
|
|
2
|
+
import { CliBasePreopens as CliBasePreopensImports } from './imports/cli-base-preopens';
|
|
3
|
+
import { CliBaseExit as CliBaseExitImports } from './imports/cli-base-exit';
|
|
4
|
+
import { CliBaseStdin as CliBaseStdinImports } from './imports/cli-base-stdin';
|
|
5
|
+
import { CliBaseStdout as CliBaseStdoutImports } from './imports/cli-base-stdout';
|
|
6
|
+
import { CliBaseStderr as CliBaseStderrImports } from './imports/cli-base-stderr';
|
|
7
|
+
import { ClocksWallClock as ClocksWallClockImports } from './imports/clocks-wall-clock';
|
|
8
|
+
import { ClocksMonotonicClock as ClocksMonotonicClockImports } from './imports/clocks-monotonic-clock';
|
|
9
|
+
import { ClocksTimezone as ClocksTimezoneImports } from './imports/clocks-timezone';
|
|
10
|
+
import { FilesystemFilesystem as FilesystemFilesystemImports } from './imports/filesystem-filesystem';
|
|
11
|
+
import { IoStreams as IoStreamsImports } from './imports/io-streams';
|
|
12
|
+
import { PollPoll as PollPollImports } from './imports/poll-poll';
|
|
13
|
+
import { RandomRandom as RandomRandomImports } from './imports/random-random';
|
|
14
|
+
import { RandomInsecure as RandomInsecureImports } from './imports/random-insecure';
|
|
15
|
+
import { RandomInsecureSeed as RandomInsecureSeedImports } from './imports/random-insecure-seed';
|
|
16
|
+
import { SocketsNetwork as SocketsNetworkImports } from './imports/sockets-network';
|
|
17
|
+
import { SocketsInstanceNetwork as SocketsInstanceNetworkImports } from './imports/sockets-instance-network';
|
|
18
|
+
import { SocketsIpNameLookup as SocketsIpNameLookupImports } from './imports/sockets-ip-name-lookup';
|
|
19
|
+
import { SocketsTcp as SocketsTcpImports } from './imports/sockets-tcp';
|
|
20
|
+
import { SocketsTcpCreateSocket as SocketsTcpCreateSocketImports } from './imports/sockets-tcp-create-socket';
|
|
21
|
+
import { SocketsUdp as SocketsUdpImports } from './imports/sockets-udp';
|
|
22
|
+
import { SocketsUdpCreateSocket as SocketsUdpCreateSocketImports } from './imports/sockets-udp-create-socket';
|
|
23
|
+
export function run(): void;
|
package/types/wasi-proxy.d.ts
CHANGED
|
@@ -1,44 +1,11 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
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 { HttpTypes as HttpTypesImports } from './imports/http-types';
|
|
2
|
+
import { HttpOutgoingHandler as HttpOutgoingHandlerImports } from './imports/http-outgoing-handler';
|
|
3
|
+
import { IoStreams as IoStreamsImports } from './imports/io-streams';
|
|
4
|
+
import { LoggingHandler as LoggingHandlerImports } from './imports/logging-handler';
|
|
5
|
+
import { PollPoll as PollPollImports } from './imports/poll-poll';
|
|
6
|
+
import { RandomRandom as RandomRandomImports } from './imports/random-random';
|
|
7
|
+
import { RandomInsecure as RandomInsecureImports } from './imports/random-insecure';
|
|
8
|
+
import { RandomInsecureSeed as RandomInsecureSeedImports } from './imports/random-insecure-seed';
|
|
9
|
+
import { HttpIncomingHandler as HttpIncomingHandlerExports } from './exports/http-incoming-handler';
|
|
10
|
+
export const httpIncomingHandler: typeof HttpIncomingHandlerExports;
|
|
11
|
+
export const incomingHandler: typeof HttpIncomingHandlerExports;
|
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 { CliBaseEnvironment as CliBaseEnvironmentImports } from './imports/cli-base-environment';
|
|
2
|
+
import { CliBasePreopens as CliBasePreopensImports } from './imports/cli-base-preopens';
|
|
3
|
+
import { CliBaseExit as CliBaseExitImports } from './imports/cli-base-exit';
|
|
4
|
+
import { CliBaseStdin as CliBaseStdinImports } from './imports/cli-base-stdin';
|
|
5
|
+
import { CliBaseStdout as CliBaseStdoutImports } from './imports/cli-base-stdout';
|
|
6
|
+
import { CliBaseStderr as CliBaseStderrImports } from './imports/cli-base-stderr';
|
|
7
|
+
import { ClocksWallClock as ClocksWallClockImports } from './imports/clocks-wall-clock';
|
|
8
|
+
import { ClocksMonotonicClock as ClocksMonotonicClockImports } from './imports/clocks-monotonic-clock';
|
|
9
|
+
import { ClocksTimezone as ClocksTimezoneImports } from './imports/clocks-timezone';
|
|
10
|
+
import { FilesystemFilesystem as FilesystemFilesystemImports } from './imports/filesystem-filesystem';
|
|
11
|
+
import { HttpTypes as HttpTypesImports } from './imports/http-types';
|
|
12
|
+
import { HttpOutgoingHandler as HttpOutgoingHandlerImports } from './imports/http-outgoing-handler';
|
|
13
|
+
import { IoStreams as IoStreamsImports } from './imports/io-streams';
|
|
14
|
+
import { LoggingHandler as LoggingHandlerImports } from './imports/logging-handler';
|
|
15
|
+
import { PollPoll as PollPollImports } from './imports/poll-poll';
|
|
16
|
+
import { RandomRandom as RandomRandomImports } from './imports/random-random';
|
|
17
|
+
import { SocketsNetwork as SocketsNetworkImports } from './imports/sockets-network';
|
|
18
|
+
import { SocketsInstanceNetwork as SocketsInstanceNetworkImports } from './imports/sockets-instance-network';
|
|
19
|
+
import { SocketsIpNameLookup as SocketsIpNameLookupImports } from './imports/sockets-ip-name-lookup';
|
|
20
|
+
import { SocketsTcp as SocketsTcpImports } from './imports/sockets-tcp';
|
|
21
|
+
import { SocketsTcpCreateSocket as SocketsTcpCreateSocketImports } from './imports/sockets-tcp-create-socket';
|
|
22
|
+
import { SocketsUdp as SocketsUdpImports } from './imports/sockets-udp';
|
|
23
|
+
import { SocketsUdpCreateSocket as SocketsUdpCreateSocketImports } from './imports/sockets-udp-create-socket';
|
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,35 +0,0 @@
|
|
|
1
|
-
|
|
2
|
-
export function resolution(clock) {
|
|
3
|
-
console.log(`[monotonic-clock] Monotonic clock resolution ${clock}`);
|
|
4
|
-
}
|
|
5
|
-
|
|
6
|
-
let hrStart = hrtimeBigint();
|
|
7
|
-
|
|
8
|
-
export function now(clock) {
|
|
9
|
-
if (clock === 0) {
|
|
10
|
-
return hrtimeBigint() - hrStart;
|
|
11
|
-
}
|
|
12
|
-
console.log(`[monotonic clock] Unknown clock ${clock}`);
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
function hrtime(previousTimestamp) {
|
|
16
|
-
const baseNow = Math.floor((Date.now() - performance.now()) * 1e-3);
|
|
17
|
-
const clocktime = performance.now() * 1e-3;
|
|
18
|
-
let seconds = Math.floor(clocktime) + baseNow;
|
|
19
|
-
let nanoseconds = Math.floor((clocktime % 1) * 1e9);
|
|
20
|
-
|
|
21
|
-
if (previousTimestamp) {
|
|
22
|
-
seconds = seconds - previousTimestamp[0];
|
|
23
|
-
nanoseconds = nanoseconds - previousTimestamp[1];
|
|
24
|
-
if (nanoseconds < 0) {
|
|
25
|
-
seconds--;
|
|
26
|
-
nanoseconds += 1e9;
|
|
27
|
-
}
|
|
28
|
-
}
|
|
29
|
-
return [seconds, nanoseconds];
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
function hrtimeBigint(time) {
|
|
33
|
-
const diff = hrtime(time);
|
|
34
|
-
return BigInt(diff[0] * 1e9 + diff[1]);
|
|
35
|
-
}
|
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
|
-
}
|
package/lib/browser/timezone.js
DELETED
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
export function display (timezone, when) {
|
|
2
|
-
console.log(`[timezone] DISPLAY ${timezone} ${when}`);
|
|
3
|
-
}
|
|
4
|
-
|
|
5
|
-
export function utcOffset (timezone, when) {
|
|
6
|
-
console.log(`[timezone] UTC OFFSET ${timezone} ${when}`);
|
|
7
|
-
return 0;
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
export function dropTimezone (timezone) {
|
|
11
|
-
console.log(`[timezone] DROP ${timezone}`);
|
|
12
|
-
}
|
package/lib/browser/types.js
DELETED
|
@@ -1,99 +0,0 @@
|
|
|
1
|
-
export function dropFields(_fields) {
|
|
2
|
-
console.log("[types] Drop fields");
|
|
3
|
-
}
|
|
4
|
-
export function newFields(_entries) {
|
|
5
|
-
console.log("[types] New fields");
|
|
6
|
-
}
|
|
7
|
-
export function fieldsGet(_fields, _name) {
|
|
8
|
-
console.log("[types] Fields get");
|
|
9
|
-
}
|
|
10
|
-
export function fieldsSet(_fields, _name, _value) {
|
|
11
|
-
console.log("[types] Fields set");
|
|
12
|
-
}
|
|
13
|
-
export function fieldsDelete(_fields, _name) {
|
|
14
|
-
console.log("[types] Fields delete");
|
|
15
|
-
}
|
|
16
|
-
export function fieldsAppend(_fields, _name, _value) {
|
|
17
|
-
console.log("[types] Fields append");
|
|
18
|
-
}
|
|
19
|
-
export function fieldsEntries(_fields) {
|
|
20
|
-
console.log("[types] Fields entries");
|
|
21
|
-
}
|
|
22
|
-
export function fieldsClone(_fields) {
|
|
23
|
-
console.log("[types] Fields clone");
|
|
24
|
-
}
|
|
25
|
-
export function finishIncomingStream(s) {
|
|
26
|
-
console.log(`[types] Finish incoming stream ${s}`);
|
|
27
|
-
}
|
|
28
|
-
export function finishOutgoingStream(s, _trailers) {
|
|
29
|
-
console.log(`[types] Finish outgoing stream ${s}`);
|
|
30
|
-
}
|
|
31
|
-
export function dropIncomingRequest(_req) {
|
|
32
|
-
console.log("[types] Drop incoming request");
|
|
33
|
-
}
|
|
34
|
-
export function dropOutgoingRequest(_req) {
|
|
35
|
-
console.log("[types] Drop outgoing request");
|
|
36
|
-
}
|
|
37
|
-
export function incomingRequestMethod(_req) {
|
|
38
|
-
console.log("[types] Incoming request method");
|
|
39
|
-
}
|
|
40
|
-
export function incomingRequestPath(_req) {
|
|
41
|
-
console.log("[types] Incoming request path");
|
|
42
|
-
}
|
|
43
|
-
export function incomingRequestQuery(_req) {
|
|
44
|
-
console.log("[types] Incoming request query");
|
|
45
|
-
}
|
|
46
|
-
export function incomingRequestScheme(_req) {
|
|
47
|
-
console.log("[types] Incoming request scheme");
|
|
48
|
-
}
|
|
49
|
-
export function incomingRequestAuthority(_req) {
|
|
50
|
-
console.log("[types] Incoming request authority");
|
|
51
|
-
}
|
|
52
|
-
export function incomingRequestHeaders(_req) {
|
|
53
|
-
console.log("[types] Incoming request headers");
|
|
54
|
-
}
|
|
55
|
-
export function incomingRequestConsume(_req) {
|
|
56
|
-
console.log("[types] Incoming request consume");
|
|
57
|
-
}
|
|
58
|
-
export function newOutgoingRequest(_method, _path, _query, _scheme, _authority, _headers) {
|
|
59
|
-
console.log("[types] New outgoing request");
|
|
60
|
-
}
|
|
61
|
-
export function outgoingRequestWrite(_req) {
|
|
62
|
-
console.log("[types] Outgoing request write");
|
|
63
|
-
}
|
|
64
|
-
export function dropResponseOutparam(_res) {
|
|
65
|
-
console.log("[types] Drop response outparam");
|
|
66
|
-
}
|
|
67
|
-
export function setResponseOutparam(_res) {
|
|
68
|
-
console.log("[types] Drop fields");
|
|
69
|
-
}
|
|
70
|
-
export function dropIncomingResponse(_res) {
|
|
71
|
-
console.log("[types] Drop incoming response");
|
|
72
|
-
}
|
|
73
|
-
export function dropOutgoingResponse(_res) {
|
|
74
|
-
console.log("[types] Drop outgoing response");
|
|
75
|
-
}
|
|
76
|
-
export function incomingResponseStatus(_res) {
|
|
77
|
-
console.log("[types] Incoming response status");
|
|
78
|
-
}
|
|
79
|
-
export function incomingResponseHeaders(_res) {
|
|
80
|
-
console.log("[types] Incoming response headers");
|
|
81
|
-
}
|
|
82
|
-
export function incomingResponseConsume(_res) {
|
|
83
|
-
console.log("[types] Incoming response consume");
|
|
84
|
-
}
|
|
85
|
-
export function newOutgoingResponse(_statusCode, _headers) {
|
|
86
|
-
console.log("[types] New outgoing response");
|
|
87
|
-
}
|
|
88
|
-
export function outgoingResponseWrite(_res) {
|
|
89
|
-
console.log("[types] Outgoing response write");
|
|
90
|
-
}
|
|
91
|
-
export function dropFutureIncomingResponse(_f) {
|
|
92
|
-
console.log("[types] Drop future incoming response");
|
|
93
|
-
}
|
|
94
|
-
export function futureIncomingResponseGet(_f) {
|
|
95
|
-
console.log("[types] Future incoming response get");
|
|
96
|
-
}
|
|
97
|
-
export function listenToFutureIncomingResponse(_f) {
|
|
98
|
-
console.log("[types] Listen to future incoming response");
|
|
99
|
-
}
|