@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
@@ -1,7 +1,7 @@
1
- export namespace ExportsWasiHttpIncomingHandler {
1
+ export namespace WasiHttpIncomingHandler {
2
2
  export function handle(request: IncomingRequest, responseOut: ResponseOutparam): void;
3
3
  }
4
- import type { IncomingRequest } from '../imports/types';
4
+ import type { IncomingRequest } from '../exports/wasi-http-types';
5
5
  export { IncomingRequest };
6
- import type { ResponseOutparam } from '../imports/types';
6
+ import type { ResponseOutparam } from '../exports/wasi-http-types';
7
7
  export { ResponseOutparam };
@@ -0,0 +1,9 @@
1
+ export namespace WasiHttpOutgoingHandler {
2
+ export function handle(request: OutgoingRequest, options: RequestOptions | null): FutureIncomingResponse;
3
+ }
4
+ import type { OutgoingRequest } from '../exports/wasi-http-types';
5
+ export { OutgoingRequest };
6
+ import type { RequestOptions } from '../exports/wasi-http-types';
7
+ export { RequestOptions };
8
+ import type { FutureIncomingResponse } from '../exports/wasi-http-types';
9
+ export { FutureIncomingResponse };
@@ -1,27 +1,26 @@
1
- export namespace ImportsTypes {
1
+ export namespace WasiHttpTypes {
2
2
  export function dropFields(fields: Fields): void;
3
3
  export function newFields(entries: [string, string][]): Fields;
4
- export function fieldsGet(fields: Fields, name: string): string[];
5
- export function fieldsSet(fields: Fields, name: string, value: string[]): void;
4
+ export function fieldsGet(fields: Fields, name: string): Uint8Array[];
5
+ export function fieldsSet(fields: Fields, name: string, value: Uint8Array | ArrayBuffer[]): void;
6
6
  export function fieldsDelete(fields: Fields, name: string): void;
7
- export function fieldsAppend(fields: Fields, name: string, value: string): void;
8
- export function fieldsEntries(fields: Fields): [string, string][];
7
+ export function fieldsAppend(fields: Fields, name: string, value: Uint8Array | ArrayBuffer): void;
8
+ export function fieldsEntries(fields: Fields): [string, Uint8Array][];
9
9
  export function fieldsClone(fields: Fields): Fields;
10
10
  export function finishIncomingStream(s: IncomingStream): Trailers | null;
11
11
  export function finishOutgoingStream(s: OutgoingStream, trailers: Trailers | null): void;
12
12
  export function dropIncomingRequest(request: IncomingRequest): void;
13
13
  export function dropOutgoingRequest(request: OutgoingRequest): void;
14
14
  export function incomingRequestMethod(request: IncomingRequest): Method;
15
- export function incomingRequestPath(request: IncomingRequest): string;
16
- export function incomingRequestQuery(request: IncomingRequest): string;
15
+ export function incomingRequestPathWithQuery(request: IncomingRequest): string | null;
17
16
  export function incomingRequestScheme(request: IncomingRequest): Scheme | null;
18
- export function incomingRequestAuthority(request: IncomingRequest): string;
17
+ export function incomingRequestAuthority(request: IncomingRequest): string | null;
19
18
  export function incomingRequestHeaders(request: IncomingRequest): Headers;
20
19
  export function incomingRequestConsume(request: IncomingRequest): IncomingStream;
21
- export function newOutgoingRequest(method: Method, path: string, query: string, scheme: Scheme | null, authority: string, headers: Headers): OutgoingRequest;
20
+ export function newOutgoingRequest(method: Method, pathWithQuery: string | null, scheme: Scheme | null, authority: string | null, headers: Headers): OutgoingRequest;
22
21
  export function outgoingRequestWrite(request: OutgoingRequest): OutgoingStream;
23
22
  export function dropResponseOutparam(response: ResponseOutparam): void;
24
- export function setResponseOutparam(response: Result<OutgoingResponse, Error>): void;
23
+ export function setResponseOutparam(param: ResponseOutparam, response: Result<OutgoingResponse, Error>): void;
25
24
  export function dropIncomingResponse(response: IncomingResponse): void;
26
25
  export function dropOutgoingResponse(response: OutgoingResponse): void;
27
26
  export function incomingResponseStatus(response: IncomingResponse): StatusCode;
@@ -33,33 +32,12 @@ export namespace ImportsTypes {
33
32
  export function futureIncomingResponseGet(f: FutureIncomingResponse): Result<IncomingResponse, Error> | null;
34
33
  export function listenToFutureIncomingResponse(f: FutureIncomingResponse): Pollable;
35
34
  }
36
- import type { InputStream } from '../imports/streams';
35
+ import type { InputStream } from '../exports/wasi-io-streams';
37
36
  export { InputStream };
38
- import type { OutputStream } from '../imports/streams';
37
+ import type { OutputStream } from '../exports/wasi-io-streams';
39
38
  export { OutputStream };
40
- import type { Pollable } from '../imports/poll';
39
+ import type { Pollable } from '../exports/wasi-poll-poll';
41
40
  export { Pollable };
42
- export type StatusCode = number;
43
- export type Scheme = SchemeHttp | SchemeHttps | SchemeOther;
44
- export interface SchemeHttp {
45
- tag: 'HTTP',
46
- }
47
- export interface SchemeHttps {
48
- tag: 'HTTPS',
49
- }
50
- export interface SchemeOther {
51
- tag: 'other',
52
- val: string,
53
- }
54
- export type ResponseOutparam = number;
55
- export interface RequestOptions {
56
- connectTimeoutMs?: number,
57
- firstByteTimeoutMs?: number,
58
- betweenBytesTimeoutMs?: number,
59
- }
60
- export type OutgoingStream = OutputStream;
61
- export type OutgoingResponse = number;
62
- export type OutgoingRequest = number;
63
41
  export type Method = MethodGet | MethodHead | MethodPost | MethodPut | MethodDelete | MethodConnect | MethodOptions | MethodTrace | MethodPatch | MethodOther;
64
42
  export interface MethodGet {
65
43
  tag: 'get',
@@ -92,13 +70,17 @@ export interface MethodOther {
92
70
  tag: 'other',
93
71
  val: string,
94
72
  }
95
- export type IncomingStream = InputStream;
96
- export type IncomingResponse = number;
97
- export type IncomingRequest = number;
98
- export type FutureIncomingResponse = number;
99
- export type Fields = number;
100
- export type Trailers = Fields;
101
- export type Headers = Fields;
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
+ }
102
84
  export type Error = ErrorInvalidUrl | ErrorTimeoutError | ErrorProtocolError | ErrorUnexpectedError;
103
85
  export interface ErrorInvalidUrl {
104
86
  tag: 'invalid-url',
@@ -116,4 +98,21 @@ export interface ErrorUnexpectedError {
116
98
  tag: 'unexpected-error',
117
99
  val: string,
118
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;
119
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, 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, 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 | ArrayBuffer): [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 | ArrayBuffer): [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 '../exports/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;
@@ -1,9 +1,9 @@
1
- export namespace ImportsPoll {
1
+ export namespace WasiPollPoll {
2
2
  /**
3
3
  * Dispose of the specified `pollable`, after which it may no longer
4
4
  * be used.
5
5
  */
6
- export function dropPollable(this: Pollable): void;
6
+ export function dropPollable(this_: Pollable): void;
7
7
  /**
8
8
  * Poll for completion on a set of pollables.
9
9
  *
@@ -14,13 +14,11 @@ export namespace ImportsPoll {
14
14
  * component model async proposal, which will include a scalable waiting
15
15
  * facility.
16
16
  *
17
- * Note that the return type would ideally be `list<bool>`, but that would
18
- * be more difficult to polyfill given the current state of `wit-bindgen`.
19
- * See <https://github.com/bytecodealliance/preview2-prototyping/pull/11#issuecomment-1329873061>
20
- * for details. For now, we use zero to mean "not ready" and non-zero to
21
- * mean "ready".
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.
22
20
  */
23
- export function pollOneoff(in: Uint32Array): Uint8Array | ArrayBuffer;
21
+ export function pollOneoff(in_: Uint32Array): boolean[];
24
22
  }
25
23
  /**
26
24
  * A "pollable" handle.
@@ -1,4 +1,4 @@
1
- export namespace ImportsInsecureSeed {
1
+ export namespace WasiRandomInsecureSeed {
2
2
  /**
3
3
  * Return a 128-bit value that may contain a pseudo-random value.
4
4
  *
@@ -0,0 +1,20 @@
1
+ export namespace WasiRandomInsecure {
2
+ /**
3
+ * Return `len` insecure pseudo-random bytes.
4
+ *
5
+ * This function is not cryptographically secure. Do not use it for
6
+ * anything related to security.
7
+ *
8
+ * There are no requirements on the values of the returned bytes, however
9
+ * implementations are encouraged to return evenly distributed values with
10
+ * a long period.
11
+ */
12
+ export function getInsecureRandomBytes(len: bigint): Uint8Array;
13
+ /**
14
+ * Return an insecure pseudo-random `u64` value.
15
+ *
16
+ * This function returns the same type of pseudo-random data as
17
+ * `get-insecure-random-bytes`, represented as a `u64`.
18
+ */
19
+ export function getInsecureRandomU64(): bigint;
20
+ }
@@ -0,0 +1,22 @@
1
+ export namespace WasiRandomRandom {
2
+ /**
3
+ * Return `len` cryptographically-secure pseudo-random bytes.
4
+ *
5
+ * This function must produce data from an adequately seeded
6
+ * cryptographically-secure pseudo-random number generator (CSPRNG), so it
7
+ * must not block, from the perspective of the calling program, and the
8
+ * returned data is always unpredictable.
9
+ *
10
+ * This function must always return fresh pseudo-random data. Deterministic
11
+ * environments must omit this function, rather than implementing it with
12
+ * deterministic data.
13
+ */
14
+ export function getRandomBytes(len: bigint): Uint8Array;
15
+ /**
16
+ * Return a cryptographically-secure pseudo-random `u64` value.
17
+ *
18
+ * This function returns the same type of pseudo-random data as
19
+ * `get-random-bytes`, represented as a `u64`.
20
+ */
21
+ export function getRandomU64(): bigint;
22
+ }
@@ -1,8 +1,8 @@
1
- export namespace ImportsInstanceNetwork {
1
+ export namespace WasiSocketsInstanceNetwork {
2
2
  /**
3
3
  * Get a handle to the default network.
4
4
  */
5
5
  export function instanceNetwork(): Network;
6
6
  }
7
- import type { Network } from '../imports/network';
7
+ import type { Network } from '../exports/wasi-sockets-network';
8
8
  export { Network };
@@ -1,4 +1,4 @@
1
- export namespace ImportsIpNameLookup {
1
+ export namespace WasiSocketsIpNameLookup {
2
2
  /**
3
3
  * Resolve an internet host name to a list of IP addresses.
4
4
  *
@@ -48,29 +48,29 @@ export namespace ImportsIpNameLookup {
48
48
  * - `permanent-resolver-failure`: A permanent failure in name resolution occurred. (EAI_FAIL)
49
49
  * - `would-block`: A result is not available yet. (EWOULDBLOCK, EAGAIN)
50
50
  */
51
- export function resolveNextAddress(this: ResolveAddressStream): IpAddress | null;
51
+ export function resolveNextAddress(this_: ResolveAddressStream): IpAddress | null;
52
52
  /**
53
53
  * Dispose of the specified `resolve-address-stream`, after which it may no longer be used.
54
54
  *
55
55
  * Note: this function is scheduled to be removed when Resources are natively supported in Wit.
56
56
  */
57
- export function dropResolveAddressStream(this: ResolveAddressStream): void;
57
+ export function dropResolveAddressStream(this_: ResolveAddressStream): void;
58
58
  /**
59
59
  * Create a `pollable` which will resolve once the stream is ready for I/O.
60
60
  *
61
61
  * Note: this function is here for WASI Preview2 only.
62
62
  * It's planned to be removed when `future` is natively supported in Preview3.
63
63
  */
64
- export function subscribe(this: ResolveAddressStream): Pollable;
64
+ export function subscribe(this_: ResolveAddressStream): Pollable;
65
65
  }
66
- import type { Pollable } from '../imports/poll';
66
+ import type { Pollable } from '../exports/wasi-poll-poll';
67
67
  export { Pollable };
68
- import type { Network } from '../imports/network';
68
+ import type { Network } from '../exports/wasi-sockets-network';
69
69
  export { Network };
70
- import type { ErrorCode } from '../imports/network';
70
+ import type { ErrorCode } from '../exports/wasi-sockets-network';
71
71
  export { ErrorCode };
72
- import type { IpAddress } from '../imports/network';
72
+ import type { IpAddress } from '../exports/wasi-sockets-network';
73
73
  export { IpAddress };
74
- import type { IpAddressFamily } from '../imports/network';
74
+ import type { IpAddressFamily } from '../exports/wasi-sockets-network';
75
75
  export { IpAddressFamily };
76
76
  export type ResolveAddressStream = number;