@bytecodealliance/preview2-shim 0.0.12 → 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 (91) hide show
  1. package/README.md +2 -2
  2. package/lib/browser/cli.js +87 -0
  3. package/lib/browser/filesystem.js +216 -18
  4. package/lib/browser/http.js +4 -7
  5. package/lib/browser/index.js +2 -2
  6. package/lib/browser/io.js +76 -17
  7. package/lib/browser/logging.js +2 -2
  8. package/lib/browser/poll.js +48 -4
  9. package/lib/http/error.js +1 -1
  10. package/lib/http/make-request.js +3 -2
  11. package/lib/http/wasi-http.js +52 -40
  12. package/lib/nodejs/cli.js +75 -0
  13. package/lib/nodejs/filesystem.js +93 -3
  14. package/lib/nodejs/http.js +4 -7
  15. package/lib/nodejs/index.js +2 -2
  16. package/lib/nodejs/logging.js +2 -2
  17. package/package.json +1 -1
  18. package/types/{imports/environment.d.ts → exports/wasi-cli-environment.d.ts} +6 -1
  19. package/types/{imports/exit.d.ts → exports/wasi-cli-exit.d.ts} +2 -2
  20. package/types/exports/wasi-cli-run.d.ts +6 -0
  21. package/types/exports/wasi-cli-stderr.d.ts +5 -0
  22. package/types/exports/wasi-cli-stdin.d.ts +5 -0
  23. package/types/exports/wasi-cli-stdout.d.ts +5 -0
  24. package/types/exports/wasi-cli-terminal-input.d.ts +13 -0
  25. package/types/exports/wasi-cli-terminal-output.d.ts +13 -0
  26. package/types/exports/wasi-cli-terminal-stderr.d.ts +9 -0
  27. package/types/exports/wasi-cli-terminal-stdin.d.ts +9 -0
  28. package/types/exports/wasi-cli-terminal-stdout.d.ts +9 -0
  29. package/types/{imports/monotonic-clock.d.ts → exports/wasi-clocks-monotonic-clock.d.ts} +2 -2
  30. package/types/{imports/timezone.d.ts → exports/wasi-clocks-timezone.d.ts} +15 -15
  31. package/types/{imports/wall-clock.d.ts → exports/wasi-clocks-wall-clock.d.ts} +1 -1
  32. package/types/exports/wasi-filesystem-preopens.d.ts +8 -0
  33. package/types/{imports/filesystem.d.ts → exports/wasi-filesystem-types.d.ts} +293 -307
  34. package/types/exports/wasi-http-incoming-handler.d.ts +3 -3
  35. package/types/exports/wasi-http-outgoing-handler.d.ts +9 -0
  36. package/types/{imports/types.d.ts → exports/wasi-http-types.d.ts} +40 -41
  37. package/types/exports/wasi-io-streams.d.ts +220 -0
  38. package/types/{imports/poll.d.ts → exports/wasi-poll-poll.d.ts} +6 -8
  39. package/types/{imports/insecure-seed.d.ts → exports/wasi-random-insecure-seed.d.ts} +1 -1
  40. package/types/exports/wasi-random-insecure.d.ts +20 -0
  41. package/types/exports/wasi-random-random.d.ts +22 -0
  42. package/types/{imports/instance-network.d.ts → exports/wasi-sockets-instance-network.d.ts} +2 -2
  43. package/types/{imports/ip-name-lookup.d.ts → exports/wasi-sockets-ip-name-lookup.d.ts} +9 -9
  44. package/types/{imports/network.d.ts → exports/wasi-sockets-network.d.ts} +43 -75
  45. package/types/{imports/tcp-create-socket.d.ts → exports/wasi-sockets-tcp-create-socket.d.ts} +5 -5
  46. package/types/{imports/tcp.d.ts → exports/wasi-sockets-tcp.d.ts} +38 -38
  47. package/types/{imports/udp-create-socket.d.ts → exports/wasi-sockets-udp-create-socket.d.ts} +5 -5
  48. package/types/{imports/udp.d.ts → exports/wasi-sockets-udp.d.ts} +41 -32
  49. package/types/imports/wasi-cli-environment.d.ts +22 -0
  50. package/types/imports/wasi-cli-exit.d.ts +7 -0
  51. package/types/imports/wasi-cli-stderr.d.ts +5 -0
  52. package/types/imports/wasi-cli-stdin.d.ts +5 -0
  53. package/types/imports/wasi-cli-stdout.d.ts +5 -0
  54. package/types/imports/wasi-cli-terminal-input.d.ts +13 -0
  55. package/types/imports/wasi-cli-terminal-output.d.ts +13 -0
  56. package/types/imports/wasi-cli-terminal-stderr.d.ts +9 -0
  57. package/types/imports/wasi-cli-terminal-stdin.d.ts +9 -0
  58. package/types/imports/wasi-cli-terminal-stdout.d.ts +9 -0
  59. package/types/imports/wasi-clocks-monotonic-clock.d.ts +24 -0
  60. package/types/imports/wasi-clocks-timezone.d.ts +71 -0
  61. package/types/imports/wasi-clocks-wall-clock.d.ts +31 -0
  62. package/types/imports/wasi-filesystem-preopens.d.ts +8 -0
  63. package/types/imports/wasi-filesystem-types.d.ts +843 -0
  64. package/types/imports/wasi-http-outgoing-handler.d.ts +9 -0
  65. package/types/imports/wasi-http-types.d.ts +118 -0
  66. package/types/imports/wasi-io-streams.d.ts +220 -0
  67. package/types/imports/wasi-poll-poll.d.ts +39 -0
  68. package/types/imports/wasi-random-insecure-seed.d.ts +22 -0
  69. package/types/imports/{insecure.d.ts → wasi-random-insecure.d.ts} +1 -1
  70. package/types/imports/{random.d.ts → wasi-random-random.d.ts} +1 -1
  71. package/types/imports/wasi-sockets-instance-network.d.ts +8 -0
  72. package/types/imports/wasi-sockets-ip-name-lookup.d.ts +76 -0
  73. package/types/imports/wasi-sockets-network.d.ts +180 -0
  74. package/types/imports/wasi-sockets-tcp-create-socket.d.ts +33 -0
  75. package/types/imports/wasi-sockets-tcp.d.ts +285 -0
  76. package/types/imports/wasi-sockets-udp-create-socket.d.ts +33 -0
  77. package/types/imports/wasi-sockets-udp.d.ts +228 -0
  78. package/types/wasi-cli-command.d.ts +29 -0
  79. package/types/wasi-http-proxy.d.ts +13 -0
  80. package/lib/browser/cli-base.js +0 -48
  81. package/lib/nodejs/cli-base.js +0 -99
  82. package/types/imports/handler.d.ts +0 -40
  83. package/types/imports/outgoing-handler.d.ts +0 -9
  84. package/types/imports/preopens.d.ts +0 -12
  85. package/types/imports/stderr.d.ts +0 -5
  86. package/types/imports/stdin.d.ts +0 -5
  87. package/types/imports/stdout.d.ts +0 -5
  88. package/types/imports/streams.d.ts +0 -180
  89. package/types/wasi-command.d.ts +0 -23
  90. package/types/wasi-proxy.d.ts +0 -10
  91. package/types/wasi-reactor.d.ts +0 -23
@@ -0,0 +1,9 @@
1
+ export namespace WasiHttpOutgoingHandler {
2
+ export function handle(request: OutgoingRequest, options: RequestOptions | null): FutureIncomingResponse;
3
+ }
4
+ import type { OutgoingRequest } from '../imports/wasi-http-types';
5
+ export { OutgoingRequest };
6
+ import type { RequestOptions } from '../imports/wasi-http-types';
7
+ export { RequestOptions };
8
+ import type { FutureIncomingResponse } from '../imports/wasi-http-types';
9
+ export { FutureIncomingResponse };
@@ -0,0 +1,118 @@
1
+ export namespace WasiHttpTypes {
2
+ export function dropFields(fields: Fields): void;
3
+ export function newFields(entries: [string, string][]): Fields;
4
+ export function fieldsGet(fields: Fields, name: string): Uint8Array | ArrayBuffer[];
5
+ export function fieldsSet(fields: Fields, name: string, value: Uint8Array[]): void;
6
+ export function fieldsDelete(fields: Fields, name: string): void;
7
+ export function fieldsAppend(fields: Fields, name: string, value: Uint8Array): void;
8
+ export function fieldsEntries(fields: Fields): [string, Uint8Array | ArrayBuffer][];
9
+ export function fieldsClone(fields: Fields): Fields;
10
+ export function finishIncomingStream(s: IncomingStream): Trailers | null;
11
+ export function finishOutgoingStream(s: OutgoingStream, trailers: Trailers | null): void;
12
+ export function dropIncomingRequest(request: IncomingRequest): void;
13
+ export function dropOutgoingRequest(request: OutgoingRequest): void;
14
+ export function incomingRequestMethod(request: IncomingRequest): Method;
15
+ export function incomingRequestPathWithQuery(request: IncomingRequest): string | null;
16
+ export function incomingRequestScheme(request: IncomingRequest): Scheme | null;
17
+ export function incomingRequestAuthority(request: IncomingRequest): string | null;
18
+ export function incomingRequestHeaders(request: IncomingRequest): Headers;
19
+ export function incomingRequestConsume(request: IncomingRequest): IncomingStream;
20
+ export function newOutgoingRequest(method: Method, pathWithQuery: string | null, scheme: Scheme | null, authority: string | null, headers: Headers): OutgoingRequest;
21
+ export function outgoingRequestWrite(request: OutgoingRequest): OutgoingStream;
22
+ export function dropResponseOutparam(response: ResponseOutparam): void;
23
+ export function setResponseOutparam(param: ResponseOutparam, response: Result<OutgoingResponse, Error>): void;
24
+ export function dropIncomingResponse(response: IncomingResponse): void;
25
+ export function dropOutgoingResponse(response: OutgoingResponse): void;
26
+ export function incomingResponseStatus(response: IncomingResponse): StatusCode;
27
+ export function incomingResponseHeaders(response: IncomingResponse): Headers;
28
+ export function incomingResponseConsume(response: IncomingResponse): IncomingStream;
29
+ export function newOutgoingResponse(statusCode: StatusCode, headers: Headers): OutgoingResponse;
30
+ export function outgoingResponseWrite(response: OutgoingResponse): OutgoingStream;
31
+ export function dropFutureIncomingResponse(f: FutureIncomingResponse): void;
32
+ export function futureIncomingResponseGet(f: FutureIncomingResponse): Result<IncomingResponse, Error> | null;
33
+ export function listenToFutureIncomingResponse(f: FutureIncomingResponse): Pollable;
34
+ }
35
+ import type { InputStream } from '../imports/wasi-io-streams';
36
+ export { InputStream };
37
+ import type { OutputStream } from '../imports/wasi-io-streams';
38
+ export { OutputStream };
39
+ import type { Pollable } from '../imports/wasi-poll-poll';
40
+ export { Pollable };
41
+ export type Method = MethodGet | MethodHead | MethodPost | MethodPut | MethodDelete | MethodConnect | MethodOptions | MethodTrace | MethodPatch | MethodOther;
42
+ export interface MethodGet {
43
+ tag: 'get',
44
+ }
45
+ export interface MethodHead {
46
+ tag: 'head',
47
+ }
48
+ export interface MethodPost {
49
+ tag: 'post',
50
+ }
51
+ export interface MethodPut {
52
+ tag: 'put',
53
+ }
54
+ export interface MethodDelete {
55
+ tag: 'delete',
56
+ }
57
+ export interface MethodConnect {
58
+ tag: 'connect',
59
+ }
60
+ export interface MethodOptions {
61
+ tag: 'options',
62
+ }
63
+ export interface MethodTrace {
64
+ tag: 'trace',
65
+ }
66
+ export interface MethodPatch {
67
+ tag: 'patch',
68
+ }
69
+ export interface MethodOther {
70
+ tag: 'other',
71
+ val: string,
72
+ }
73
+ export type Scheme = SchemeHttp | SchemeHttps | SchemeOther;
74
+ export interface SchemeHttp {
75
+ tag: 'HTTP',
76
+ }
77
+ export interface SchemeHttps {
78
+ tag: 'HTTPS',
79
+ }
80
+ export interface SchemeOther {
81
+ tag: 'other',
82
+ val: string,
83
+ }
84
+ export type Error = ErrorInvalidUrl | ErrorTimeoutError | ErrorProtocolError | ErrorUnexpectedError;
85
+ export interface ErrorInvalidUrl {
86
+ tag: 'invalid-url',
87
+ val: string,
88
+ }
89
+ export interface ErrorTimeoutError {
90
+ tag: 'timeout-error',
91
+ val: string,
92
+ }
93
+ export interface ErrorProtocolError {
94
+ tag: 'protocol-error',
95
+ val: string,
96
+ }
97
+ export interface ErrorUnexpectedError {
98
+ tag: 'unexpected-error',
99
+ val: string,
100
+ }
101
+ export type Fields = number;
102
+ export type Headers = Fields;
103
+ export type Trailers = Fields;
104
+ export type IncomingStream = InputStream;
105
+ export type OutgoingStream = OutputStream;
106
+ export type IncomingRequest = number;
107
+ export type OutgoingRequest = number;
108
+ export interface RequestOptions {
109
+ connectTimeoutMs?: number,
110
+ firstByteTimeoutMs?: number,
111
+ betweenBytesTimeoutMs?: number,
112
+ }
113
+ export type ResponseOutparam = number;
114
+ export type StatusCode = number;
115
+ export type IncomingResponse = number;
116
+ export type OutgoingResponse = number;
117
+ export type FutureIncomingResponse = number;
118
+ export type Result<T, E> = { tag: 'ok', val: T } | { tag: 'err', val: E };
@@ -0,0 +1,220 @@
1
+ export namespace WasiIoStreams {
2
+ /**
3
+ * Perform a non-blocking read from the stream.
4
+ *
5
+ * This function returns a list of bytes containing the data that was
6
+ * read, along with a `stream-status` which, indicates whether further
7
+ * reads are expected to produce data. The returned list will contain up to
8
+ * `len` bytes; it may return fewer than requested, but not more. An
9
+ * empty list and `stream-status:open` indicates no more data is
10
+ * available at this time, and that the pollable given by
11
+ * `subscribe-to-input-stream` will be ready when more data is available.
12
+ *
13
+ * Once a stream has reached the end, subsequent calls to `read` or
14
+ * `skip` will always report `stream-status:ended` rather than producing more
15
+ * data.
16
+ *
17
+ * When the caller gives a `len` of 0, it represents a request to read 0
18
+ * bytes. This read should always succeed and return an empty list and
19
+ * the current `stream-status`.
20
+ *
21
+ * The `len` parameter is a `u64`, which could represent a list of u8 which
22
+ * is not possible to allocate in wasm32, or not desirable to allocate as
23
+ * as a return value by the callee. The callee may return a list of bytes
24
+ * less than `len` in size while more bytes are available for reading.
25
+ */
26
+ export function read(this_: InputStream, len: bigint): [Uint8Array | ArrayBuffer, StreamStatus];
27
+ /**
28
+ * Read bytes from a stream, after blocking until at least one byte can
29
+ * be read. Except for blocking, identical to `read`.
30
+ */
31
+ export function blockingRead(this_: InputStream, len: bigint): [Uint8Array | ArrayBuffer, StreamStatus];
32
+ /**
33
+ * Skip bytes from a stream.
34
+ *
35
+ * This is similar to the `read` function, but avoids copying the
36
+ * bytes into the instance.
37
+ *
38
+ * Once a stream has reached the end, subsequent calls to read or
39
+ * `skip` will always report end-of-stream rather than producing more
40
+ * data.
41
+ *
42
+ * This function returns the number of bytes skipped, along with a
43
+ * `stream-status` indicating whether the end of the stream was
44
+ * reached. The returned value will be at most `len`; it may be less.
45
+ */
46
+ export function skip(this_: InputStream, len: bigint): [bigint, StreamStatus];
47
+ /**
48
+ * Skip bytes from a stream, after blocking until at least one byte
49
+ * can be skipped. Except for blocking behavior, identical to `skip`.
50
+ */
51
+ export function blockingSkip(this_: InputStream, len: bigint): [bigint, StreamStatus];
52
+ /**
53
+ * Create a `pollable` which will resolve once either the specified stream
54
+ * has bytes available to read or the other end of the stream has been
55
+ * closed.
56
+ * The created `pollable` is a child resource of the `input-stream`.
57
+ * Implementations may trap if the `input-stream` is dropped before
58
+ * all derived `pollable`s created with this function are dropped.
59
+ */
60
+ export function subscribeToInputStream(this_: InputStream): Pollable;
61
+ /**
62
+ * Dispose of the specified `input-stream`, after which it may no longer
63
+ * be used.
64
+ * Implementations may trap if this `input-stream` is dropped while child
65
+ * `pollable` resources are still alive.
66
+ * After this `input-stream` is dropped, implementations may report any
67
+ * corresponding `output-stream` has `stream-state.closed`.
68
+ */
69
+ export function dropInputStream(this_: InputStream): void;
70
+ /**
71
+ * Perform a non-blocking write of bytes to a stream.
72
+ *
73
+ * This function returns a `u64` and a `stream-status`. The `u64` indicates
74
+ * the number of bytes from `buf` that were written, which may be less than
75
+ * the length of `buf`. The `stream-status` indicates if further writes to
76
+ * the stream are expected to be read.
77
+ *
78
+ * When the returned `stream-status` is `open`, the `u64` return value may
79
+ * be less than the length of `buf`. This indicates that no more bytes may
80
+ * be written to the stream promptly. In that case the
81
+ * `subscribe-to-output-stream` pollable will indicate when additional bytes
82
+ * may be promptly written.
83
+ *
84
+ * Writing an empty list must return a non-error result with `0` for the
85
+ * `u64` return value, and the current `stream-status`.
86
+ */
87
+ export function write(this_: OutputStream, buf: Uint8Array): [bigint, StreamStatus];
88
+ /**
89
+ * Blocking write of bytes to a stream.
90
+ *
91
+ * This is similar to `write`, except that it blocks until at least one
92
+ * byte can be written.
93
+ */
94
+ export function blockingWrite(this_: OutputStream, buf: Uint8Array): [bigint, StreamStatus];
95
+ /**
96
+ * Write multiple zero-bytes to a stream.
97
+ *
98
+ * This function returns a `u64` indicating the number of zero-bytes
99
+ * that were written; it may be less than `len`. Equivelant to a call to
100
+ * `write` with a list of zeroes of the given length.
101
+ */
102
+ export function writeZeroes(this_: OutputStream, len: bigint): [bigint, StreamStatus];
103
+ /**
104
+ * Write multiple zero bytes to a stream, with blocking.
105
+ *
106
+ * This is similar to `write-zeroes`, except that it blocks until at least
107
+ * one byte can be written. Equivelant to a call to `blocking-write` with
108
+ * a list of zeroes of the given length.
109
+ */
110
+ export function blockingWriteZeroes(this_: OutputStream, len: bigint): [bigint, StreamStatus];
111
+ /**
112
+ * Read from one stream and write to another.
113
+ *
114
+ * This function returns the number of bytes transferred; it may be less
115
+ * than `len`.
116
+ *
117
+ * Unlike other I/O functions, this function blocks until all the data
118
+ * read from the input stream has been written to the output stream.
119
+ */
120
+ export function splice(this_: OutputStream, src: InputStream, len: bigint): [bigint, StreamStatus];
121
+ /**
122
+ * Read from one stream and write to another, with blocking.
123
+ *
124
+ * This is similar to `splice`, except that it blocks until at least
125
+ * one byte can be read.
126
+ */
127
+ export function blockingSplice(this_: OutputStream, src: InputStream, len: bigint): [bigint, StreamStatus];
128
+ /**
129
+ * Forward the entire contents of an input stream to an output stream.
130
+ *
131
+ * This function repeatedly reads from the input stream and writes
132
+ * the data to the output stream, until the end of the input stream
133
+ * is reached, or an error is encountered.
134
+ *
135
+ * Unlike other I/O functions, this function blocks until the end
136
+ * of the input stream is seen and all the data has been written to
137
+ * the output stream.
138
+ *
139
+ * This function returns the number of bytes transferred, and the status of
140
+ * the output stream.
141
+ */
142
+ export function forward(this_: OutputStream, src: InputStream): [bigint, StreamStatus];
143
+ /**
144
+ * Create a `pollable` which will resolve once either the specified stream
145
+ * is ready to accept bytes or the `stream-state` has become closed.
146
+ *
147
+ * Once the stream-state is closed, this pollable is always ready
148
+ * immediately.
149
+ *
150
+ * The created `pollable` is a child resource of the `output-stream`.
151
+ * Implementations may trap if the `output-stream` is dropped before
152
+ * all derived `pollable`s created with this function are dropped.
153
+ */
154
+ export function subscribeToOutputStream(this_: OutputStream): Pollable;
155
+ /**
156
+ * Dispose of the specified `output-stream`, after which it may no longer
157
+ * be used.
158
+ * Implementations may trap if this `output-stream` is dropped while
159
+ * child `pollable` resources are still alive.
160
+ * After this `output-stream` is dropped, implementations may report any
161
+ * corresponding `input-stream` has `stream-state.closed`.
162
+ */
163
+ export function dropOutputStream(this_: OutputStream): void;
164
+ }
165
+ import type { Pollable } from '../imports/wasi-poll-poll';
166
+ export { Pollable };
167
+ /**
168
+ * Streams provide a sequence of data and then end; once they end, they
169
+ * no longer provide any further data.
170
+ *
171
+ * For example, a stream reading from a file ends when the stream reaches
172
+ * the end of the file. For another example, a stream reading from a
173
+ * socket ends when the socket is closed.
174
+ * # Variants
175
+ *
176
+ * ## `"open"`
177
+ *
178
+ * The stream is open and may produce further data.
179
+ * ## `"ended"`
180
+ *
181
+ * When reading, this indicates that the stream will not produce
182
+ * further data.
183
+ * When writing, this indicates that the stream will no longer be read.
184
+ * Further writes are still permitted.
185
+ */
186
+ export type StreamStatus = 'open' | 'ended';
187
+ /**
188
+ * An input bytestream. In the future, this will be replaced by handle
189
+ * types.
190
+ *
191
+ * `input-stream`s are *non-blocking* to the extent practical on underlying
192
+ * platforms. I/O operations always return promptly; if fewer bytes are
193
+ * promptly available than requested, they return the number of bytes promptly
194
+ * available, which could even be zero. To wait for data to be available,
195
+ * use the `subscribe-to-input-stream` function to obtain a `pollable` which
196
+ * can be polled for using `wasi:poll/poll.poll_oneoff`.
197
+ *
198
+ * And at present, it is a `u32` instead of being an actual handle, until
199
+ * the wit-bindgen implementation of handles and resources is ready.
200
+ *
201
+ * This [represents a resource](https://github.com/WebAssembly/WASI/blob/main/docs/WitInWasi.md#Resources).
202
+ */
203
+ export type InputStream = number;
204
+ /**
205
+ * An output bytestream. In the future, this will be replaced by handle
206
+ * types.
207
+ *
208
+ * `output-stream`s are *non-blocking* to the extent practical on
209
+ * underlying platforms. Except where specified otherwise, I/O operations also
210
+ * always return promptly, after the number of bytes that can be written
211
+ * promptly, which could even be zero. To wait for the stream to be ready to
212
+ * accept data, the `subscribe-to-output-stream` function to obtain a
213
+ * `pollable` which can be polled for using `wasi:poll`.
214
+ *
215
+ * And at present, it is a `u32` instead of being an actual handle, until
216
+ * the wit-bindgen implementation of handles and resources is ready.
217
+ *
218
+ * This [represents a resource](https://github.com/WebAssembly/WASI/blob/main/docs/WitInWasi.md#Resources).
219
+ */
220
+ export type OutputStream = number;
@@ -0,0 +1,39 @@
1
+ export namespace WasiPollPoll {
2
+ /**
3
+ * Dispose of the specified `pollable`, after which it may no longer
4
+ * be used.
5
+ */
6
+ export function dropPollable(this_: Pollable): void;
7
+ /**
8
+ * Poll for completion on a set of pollables.
9
+ *
10
+ * The "oneoff" in the name refers to the fact that this function must do a
11
+ * linear scan through the entire list of subscriptions, which may be
12
+ * inefficient if the number is large and the same subscriptions are used
13
+ * many times. In the future, this is expected to be obsoleted by the
14
+ * component model async proposal, which will include a scalable waiting
15
+ * facility.
16
+ *
17
+ * The result list<bool> is the same length as the argument
18
+ * list<pollable>, and indicates the readiness of each corresponding
19
+ * element in that / list, with true indicating ready.
20
+ */
21
+ export function pollOneoff(in_: Uint32Array): boolean[];
22
+ }
23
+ /**
24
+ * A "pollable" handle.
25
+ *
26
+ * This is conceptually represents a `stream<_, _>`, or in other words,
27
+ * a stream that one can wait on, repeatedly, but which does not itself
28
+ * produce any data. It's temporary scaffolding until component-model's
29
+ * async features are ready.
30
+ *
31
+ * And at present, it is a `u32` instead of being an actual handle, until
32
+ * the wit-bindgen implementation of handles and resources is ready.
33
+ *
34
+ * `pollable` lifetimes are not automatically managed. Users must ensure
35
+ * that they do not outlive the resource they reference.
36
+ *
37
+ * This [represents a resource](https://github.com/WebAssembly/WASI/blob/main/docs/WitInWasi.md#Resources).
38
+ */
39
+ export type Pollable = number;
@@ -0,0 +1,22 @@
1
+ export namespace WasiRandomInsecureSeed {
2
+ /**
3
+ * Return a 128-bit value that may contain a pseudo-random value.
4
+ *
5
+ * The returned value is not required to be computed from a CSPRNG, and may
6
+ * even be entirely deterministic. Host implementations are encouraged to
7
+ * provide pseudo-random values to any program exposed to
8
+ * attacker-controlled content, to enable DoS protection built into many
9
+ * languages' hash-map implementations.
10
+ *
11
+ * This function is intended to only be called once, by a source language
12
+ * to initialize Denial Of Service (DoS) protection in its hash-map
13
+ * implementation.
14
+ *
15
+ * # Expected future evolution
16
+ *
17
+ * This will likely be changed to a value import, to prevent it from being
18
+ * called multiple times and potentially used for purposes other than DoS
19
+ * protection.
20
+ */
21
+ export function insecureSeed(): [bigint, bigint];
22
+ }
@@ -1,4 +1,4 @@
1
- export namespace ImportsInsecure {
1
+ export namespace WasiRandomInsecure {
2
2
  /**
3
3
  * Return `len` insecure pseudo-random bytes.
4
4
  *
@@ -1,4 +1,4 @@
1
- export namespace ImportsRandom {
1
+ export namespace WasiRandomRandom {
2
2
  /**
3
3
  * Return `len` cryptographically-secure pseudo-random bytes.
4
4
  *
@@ -0,0 +1,8 @@
1
+ export namespace WasiSocketsInstanceNetwork {
2
+ /**
3
+ * Get a handle to the default network.
4
+ */
5
+ export function instanceNetwork(): Network;
6
+ }
7
+ import type { Network } from '../imports/wasi-sockets-network';
8
+ export { Network };
@@ -0,0 +1,76 @@
1
+ export namespace WasiSocketsIpNameLookup {
2
+ /**
3
+ * Resolve an internet host name to a list of IP addresses.
4
+ *
5
+ * See the wasi-socket proposal README.md for a comparison with getaddrinfo.
6
+ *
7
+ * # Parameters
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.
16
+ *
17
+ * This function never blocks. It either immediately fails or immediately returns successfully with a `resolve-address-stream`
18
+ * that can be used to (asynchronously) fetch the results.
19
+ *
20
+ * At the moment, the stream never completes successfully with 0 items. Ie. the first call
21
+ * to `resolve-next-address` never returns `ok(none)`. This may change in the future.
22
+ *
23
+ * # Typical errors
24
+ * - `invalid-name`: `name` is a syntactically invalid domain name.
25
+ * - `invalid-name`: `name` is an IP address.
26
+ * - `address-family-not-supported`: The specified `address-family` is not supported. (EAI_FAMILY)
27
+ *
28
+ * # References:
29
+ * - <https://pubs.opengroup.org/onlinepubs/9699919799/functions/getaddrinfo.html>
30
+ * - <https://man7.org/linux/man-pages/man3/getaddrinfo.3.html>
31
+ * - <https://learn.microsoft.com/en-us/windows/win32/api/ws2tcpip/nf-ws2tcpip-getaddrinfo>
32
+ * - <https://man.freebsd.org/cgi/man.cgi?query=getaddrinfo&sektion=3>
33
+ */
34
+ export function resolveAddresses(network: Network, name: string, addressFamily: IpAddressFamily | null, includeUnavailable: boolean): ResolveAddressStream;
35
+ /**
36
+ * Returns the next address from the resolver.
37
+ *
38
+ * This function should be called multiple times. On each call, it will
39
+ * return the next address in connection order preference. If all
40
+ * addresses have been exhausted, this function returns `none`.
41
+ * After which, you should release the stream with `drop-resolve-address-stream`.
42
+ *
43
+ * This function never returns IPv4-mapped IPv6 addresses.
44
+ *
45
+ * # Typical errors
46
+ * - `name-unresolvable`: Name does not exist or has no suitable associated IP addresses. (EAI_NONAME, EAI_NODATA, EAI_ADDRFAMILY)
47
+ * - `temporary-resolver-failure`: A temporary failure in name resolution occurred. (EAI_AGAIN)
48
+ * - `permanent-resolver-failure`: A permanent failure in name resolution occurred. (EAI_FAIL)
49
+ * - `would-block`: A result is not available yet. (EWOULDBLOCK, EAGAIN)
50
+ */
51
+ export function resolveNextAddress(this_: ResolveAddressStream): IpAddress | null;
52
+ /**
53
+ * Dispose of the specified `resolve-address-stream`, after which it may no longer be used.
54
+ *
55
+ * Note: this function is scheduled to be removed when Resources are natively supported in Wit.
56
+ */
57
+ export function dropResolveAddressStream(this_: ResolveAddressStream): void;
58
+ /**
59
+ * Create a `pollable` which will resolve once the stream is ready for I/O.
60
+ *
61
+ * Note: this function is here for WASI Preview2 only.
62
+ * It's planned to be removed when `future` is natively supported in Preview3.
63
+ */
64
+ export function subscribe(this_: ResolveAddressStream): Pollable;
65
+ }
66
+ import type { Pollable } from '../imports/wasi-poll-poll';
67
+ export { Pollable };
68
+ import type { Network } from '../imports/wasi-sockets-network';
69
+ export { Network };
70
+ import type { ErrorCode } from '../imports/wasi-sockets-network';
71
+ export { ErrorCode };
72
+ import type { IpAddress } from '../imports/wasi-sockets-network';
73
+ export { IpAddress };
74
+ import type { IpAddressFamily } from '../imports/wasi-sockets-network';
75
+ export { IpAddressFamily };
76
+ export type ResolveAddressStream = number;