@bytecodealliance/preview2-shim 0.0.19 → 0.0.21

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 (40) hide show
  1. package/LICENSE +220 -0
  2. package/README.md +4 -6
  3. package/lib/browser/cli.js +79 -12
  4. package/lib/browser/filesystem.js +168 -198
  5. package/lib/browser/index.js +1 -5
  6. package/lib/browser/io.js +173 -29
  7. package/lib/common/io.js +6 -4
  8. package/lib/{http → common}/make-request.js +1 -1
  9. package/lib/nodejs/cli.js +5 -4
  10. package/lib/nodejs/filesystem.js +106 -73
  11. package/lib/nodejs/http.js +309 -3
  12. package/lib/nodejs/index.js +0 -5
  13. package/package.json +1 -1
  14. package/types/interfaces/wasi-cli-stderr.d.ts +1 -1
  15. package/types/interfaces/wasi-cli-stdin.d.ts +1 -1
  16. package/types/interfaces/wasi-cli-stdout.d.ts +1 -1
  17. package/types/interfaces/wasi-cli-terminal-stderr.d.ts +1 -1
  18. package/types/interfaces/wasi-cli-terminal-stdin.d.ts +1 -1
  19. package/types/interfaces/wasi-cli-terminal-stdout.d.ts +1 -1
  20. package/types/interfaces/wasi-clocks-monotonic-clock.d.ts +1 -1
  21. package/types/interfaces/wasi-clocks-timezone.d.ts +1 -1
  22. package/types/interfaces/wasi-filesystem-preopens.d.ts +1 -1
  23. package/types/interfaces/wasi-filesystem-types.d.ts +8 -8
  24. package/types/interfaces/wasi-http-incoming-handler.d.ts +19 -0
  25. package/types/interfaces/wasi-http-outgoing-handler.d.ts +23 -0
  26. package/types/interfaces/wasi-http-types.d.ts +371 -0
  27. package/types/interfaces/wasi-io-streams.d.ts +13 -21
  28. package/types/interfaces/wasi-sockets-instance-network.d.ts +1 -1
  29. package/types/interfaces/wasi-sockets-ip-name-lookup.d.ts +5 -5
  30. package/types/interfaces/wasi-sockets-tcp-create-socket.d.ts +4 -4
  31. package/types/interfaces/wasi-sockets-tcp.d.ts +7 -7
  32. package/types/interfaces/wasi-sockets-udp-create-socket.d.ts +4 -4
  33. package/types/interfaces/wasi-sockets-udp.d.ts +5 -5
  34. package/types/wasi-cli-command.d.ts +3 -3
  35. package/types/wasi-http-proxy.d.ts +13 -0
  36. package/lib/browser/poll.js +0 -53
  37. package/lib/http/wasi-http.js +0 -382
  38. package/lib/nodejs/poll.js +0 -9
  39. /package/lib/{http/synckit → synckit}/index.d.ts +0 -0
  40. /package/lib/{http/synckit → synckit}/index.js +0 -0
@@ -0,0 +1,371 @@
1
+ export namespace WasiHttpTypes {
2
+ /**
3
+ * Construct an HTTP Fields.
4
+ *
5
+ * The list represents each key-value pair in the Fields. Keys
6
+ * which have multiple values are represented by multiple entries in this
7
+ * list with the same key.
8
+ *
9
+ * The tuple is a pair of the field key, represented as a string, and
10
+ * Value, represented as a list of bytes. In a valid Fields, all keys
11
+ * and values are valid UTF-8 strings. However, values are not always
12
+ * well-formed, so they are represented as a raw list of bytes.
13
+ */
14
+ export { Fields };
15
+ /**
16
+ * Get all of the values corresponding to a key.
17
+ */
18
+ /**
19
+ * Set all of the values for a key. Clears any existing values for that
20
+ * key, if they have been set.
21
+ */
22
+ /**
23
+ * Delete all values for a key. Does nothing if no values for the key
24
+ * exist.
25
+ */
26
+ /**
27
+ * Append a value for a key. Does not change or delete any existing
28
+ * values for that key.
29
+ */
30
+ /**
31
+ * Retrieve the full set of keys and values in the Fields. Like the
32
+ * constructor, the list represents each key-value pair.
33
+ *
34
+ * The outer list represents each key-value pair in the Fields. Keys
35
+ * which have multiple values are represented by multiple entries in this
36
+ * list with the same key.
37
+ */
38
+ /**
39
+ * Make a deep copy of the Fields. Equivelant in behavior to calling the
40
+ * `fields` constructor on the return value of `entries`
41
+ */
42
+ /**
43
+ * Returns the method of the incoming request.
44
+ */
45
+ export { IncomingRequest };
46
+ /**
47
+ * Returns the path with query parameters from the request, as a string.
48
+ */
49
+ /**
50
+ * Returns the protocol scheme from the request.
51
+ */
52
+ /**
53
+ * Returns the authority from the request, if it was present.
54
+ */
55
+ /**
56
+ * Returns the `headers` from the request.
57
+ *
58
+ * The `headers` returned are a child resource: it must be dropped before
59
+ * the parent `incoming-request` is dropped. Dropping this
60
+ * `incoming-request` before all children are dropped will trap.
61
+ */
62
+ /**
63
+ * Gives the `incoming-body` associated with this request. Will only
64
+ * return success at most once, and subsequent calls will return error.
65
+ */
66
+ /**
67
+ * Construct a new `outgoing-request`.
68
+ */
69
+ export { OutgoingRequest };
70
+ /**
71
+ * Will return the outgoing-body child at most once. If called more than
72
+ * once, subsequent calls will return error.
73
+ */
74
+ /**
75
+ * Set the value of the `response-outparam` to either send a response,
76
+ * or indicate an error.
77
+ *
78
+ * This method consumes the `response-outparam` to ensure that it is
79
+ * called at most once. If it is never called, the implementation
80
+ * will respond with an error.
81
+ */
82
+ export { ResponseOutparam };
83
+ /**
84
+ * Returns the status code from the incoming response.
85
+ */
86
+ export { IncomingResponse };
87
+ /**
88
+ * Returns the headers from the incoming response.
89
+ */
90
+ /**
91
+ * Returns the incoming body. May be called at most once. Returns error
92
+ * if called additional times.
93
+ */
94
+ /**
95
+ * Returns the contents of the body, as a stream of bytes.
96
+ *
97
+ * Returns success on first call: the stream representing the contents
98
+ * can be retrieved at most once. Subsequent calls will return error.
99
+ *
100
+ * The returned `input-stream` resource is a child: it must be dropped
101
+ * before the parent `incoming-body` is dropped, or consumed by
102
+ * `incoming-body.finish`.
103
+ *
104
+ * This invariant ensures that the implementation can determine whether
105
+ * the user is consuming the contents of the body, waiting on the
106
+ * `future-trailers` to be ready, or neither. This allows for network
107
+ * backpressure is to be applied when the user is consuming the body,
108
+ * and for that backpressure to not inhibit delivery of the trailers if
109
+ * the user does not read the entire body.
110
+ */
111
+ export { IncomingBody };
112
+ /**
113
+ * Takes ownership of `incoming-body`, and returns a `future-trailers`.
114
+ * This function will trap if the `input-stream` child is still alive.
115
+ */
116
+ /**
117
+ * Returns a pollable which becomes ready when either the trailers have
118
+ * been received, or an error has occured. When this pollable is ready,
119
+ * the `get` method will return `some`.
120
+ */
121
+ export { FutureTrailers };
122
+ /**
123
+ * Returns the contents of the trailers, or an error which occured,
124
+ * once the future is ready.
125
+ *
126
+ * The outer `option` represents future readiness. Users can wait on this
127
+ * `option` to become `some` using the `subscribe` method.
128
+ *
129
+ * The `result` represents that either the HTTP Request or Response body,
130
+ * as well as any trailers, were received successfully, or that an error
131
+ * occured receiving them.
132
+ */
133
+ /**
134
+ * Construct an `outgoing-response`.
135
+ */
136
+ export { OutgoingResponse };
137
+ /**
138
+ * Returns the resource corresponding to the outgoing Body for this Response.
139
+ *
140
+ * Returns success on the first call: the `outgoing-body` resource for
141
+ * this `outgoing-response` can be retrieved at most once. Sunsequent
142
+ * calls will return error.
143
+ *
144
+ * FIXME: rename this method to `body`.
145
+ */
146
+ /**
147
+ * Returns a stream for writing the body contents.
148
+ *
149
+ * The returned `output-stream` is a child resource: it must be dropped
150
+ * before the parent `outgoing-body` resource is dropped (or finished),
151
+ * otherwise the `outgoing-body` drop or `finish` will trap.
152
+ *
153
+ * Returns success on the first call: the `output-stream` resource for
154
+ * this `outgoing-body` may be retrieved at most once. Subsequent calls
155
+ * will return error.
156
+ */
157
+ export { OutgoingBody };
158
+ /**
159
+ * Finalize an outgoing body, optionally providing trailers. This must be
160
+ * called to signal that the response is complete. If the `outgoing-body`
161
+ * is dropped without calling `outgoing-body.finalize`, the implementation
162
+ * should treat the body as corrupted.
163
+ */
164
+ /**
165
+ * Returns a pollable which becomes ready when either the Response has
166
+ * been received, or an error has occured. When this pollable is ready,
167
+ * the `get` method will return `some`.
168
+ */
169
+ export { FutureIncomingResponse };
170
+ /**
171
+ * Returns the incoming HTTP Response, or an error, once one is ready.
172
+ *
173
+ * The outer `option` represents future readiness. Users can wait on this
174
+ * `option` to become `some` using the `subscribe` method.
175
+ *
176
+ * The outer `result` is used to retrieve the response or error at most
177
+ * once. It will be success on the first call in which the outer option
178
+ * is `some`, and error on subsequent calls.
179
+ *
180
+ * The inner `result` represents that either the incoming HTTP Response
181
+ * status and headers have recieved successfully, or that an error
182
+ * occured. Errors may also occur while consuming the response body,
183
+ * but those will be reported by the `incoming-body` and its
184
+ * `output-stream` child.
185
+ */
186
+ }
187
+ import type { InputStream } from '../interfaces/wasi-io-streams.js';
188
+ export { InputStream };
189
+ import type { OutputStream } from '../interfaces/wasi-io-streams.js';
190
+ export { OutputStream };
191
+ import type { Pollable } from '../interfaces/wasi-io-poll.js';
192
+ export { Pollable };
193
+ /**
194
+ * This type corresponds to HTTP standard Methods.
195
+ */
196
+ export type Method = MethodGet | MethodHead | MethodPost | MethodPut | MethodDelete | MethodConnect | MethodOptions | MethodTrace | MethodPatch | MethodOther;
197
+ export interface MethodGet {
198
+ tag: 'get',
199
+ }
200
+ export interface MethodHead {
201
+ tag: 'head',
202
+ }
203
+ export interface MethodPost {
204
+ tag: 'post',
205
+ }
206
+ export interface MethodPut {
207
+ tag: 'put',
208
+ }
209
+ export interface MethodDelete {
210
+ tag: 'delete',
211
+ }
212
+ export interface MethodConnect {
213
+ tag: 'connect',
214
+ }
215
+ export interface MethodOptions {
216
+ tag: 'options',
217
+ }
218
+ export interface MethodTrace {
219
+ tag: 'trace',
220
+ }
221
+ export interface MethodPatch {
222
+ tag: 'patch',
223
+ }
224
+ export interface MethodOther {
225
+ tag: 'other',
226
+ val: string,
227
+ }
228
+ /**
229
+ * This type corresponds to HTTP standard Related Schemes.
230
+ */
231
+ export type Scheme = SchemeHttp | SchemeHttps | SchemeOther;
232
+ export interface SchemeHttp {
233
+ tag: 'HTTP',
234
+ }
235
+ export interface SchemeHttps {
236
+ tag: 'HTTPS',
237
+ }
238
+ export interface SchemeOther {
239
+ tag: 'other',
240
+ val: string,
241
+ }
242
+ /**
243
+ * TODO: perhaps better align with HTTP semantics?
244
+ * This type enumerates the different kinds of errors that may occur when
245
+ * initially returning a response.
246
+ */
247
+ export type Error = ErrorInvalidUrl | ErrorTimeoutError | ErrorProtocolError | ErrorUnexpectedError;
248
+ export interface ErrorInvalidUrl {
249
+ tag: 'invalid-url',
250
+ val: string,
251
+ }
252
+ export interface ErrorTimeoutError {
253
+ tag: 'timeout-error',
254
+ val: string,
255
+ }
256
+ export interface ErrorProtocolError {
257
+ tag: 'protocol-error',
258
+ val: string,
259
+ }
260
+ export interface ErrorUnexpectedError {
261
+ tag: 'unexpected-error',
262
+ val: string,
263
+ }
264
+ /**
265
+ * Field keys are always strings.
266
+ */
267
+ export type FieldKey = string;
268
+ /**
269
+ * Field values should always be ASCII strings. However, in
270
+ * reality, HTTP implementations often have to interpret malformed values,
271
+ * so they are provided as a list of bytes.
272
+ */
273
+ export type FieldValue = Uint8Array;
274
+ /**
275
+ * Headers is an alias for Fields.
276
+ */
277
+ export type Headers = Fields;
278
+ /**
279
+ * Trailers is an alias for Fields.
280
+ */
281
+ export type Trailers = Fields;
282
+ /**
283
+ * Parameters for making an HTTP Request. Each of these parameters is an
284
+ * optional timeout, with the unit in milliseconds, applicable to the
285
+ * transport layer of the HTTP protocol.
286
+ *
287
+ * These timeouts are separate from any the user may use to bound a
288
+ * blocking call to `wasi:io/poll.poll-list`.
289
+ *
290
+ * FIXME: Make this a resource to allow it to be optionally extended by
291
+ * future evolution of the standard and/or other interfaces at some later
292
+ * date?
293
+ */
294
+ export interface RequestOptions {
295
+ /**
296
+ * The timeout for the initial connect to the HTTP Server.
297
+ */
298
+ connectTimeoutMs?: number,
299
+ /**
300
+ * The timeout for receiving the first byte of the Response body.
301
+ */
302
+ firstByteTimeoutMs?: number,
303
+ /**
304
+ * The timeout for receiving subsequent chunks of bytes in the Response
305
+ * body stream.
306
+ */
307
+ betweenBytesTimeoutMs?: number,
308
+ }
309
+ /**
310
+ * This type corresponds to the HTTP standard Status Code.
311
+ */
312
+ export type StatusCode = number;
313
+
314
+ export class OutgoingRequest {
315
+ constructor(method: Method, pathWithQuery: string | undefined, scheme: Scheme | undefined, authority: string | undefined, headers: Headers)
316
+ write(): OutgoingBody;
317
+ }
318
+
319
+ export class IncomingBody {
320
+ stream(): InputStream;
321
+ static finish(this_: IncomingBody): FutureTrailers;
322
+ }
323
+
324
+ export class ResponseOutparam {
325
+ static set(param: ResponseOutparam, response: Result<OutgoingResponse, Error>): void;
326
+ }
327
+
328
+ export class OutgoingResponse {
329
+ constructor(statusCode: StatusCode, headers: Headers)
330
+ write(): OutgoingBody;
331
+ }
332
+
333
+ export class Fields {
334
+ constructor(entries: [FieldKey, FieldValue][])
335
+ get(name: FieldKey): FieldValue[];
336
+ set(name: FieldKey, value: FieldValue[]): void;
337
+ delete(name: FieldKey): void;
338
+ append(name: FieldKey, value: FieldValue): void;
339
+ entries(): [FieldKey, FieldValue][];
340
+ clone(): Fields;
341
+ }
342
+
343
+ export class FutureTrailers {
344
+ subscribe(): Pollable;
345
+ get(): Result<Trailers, Error> | undefined;
346
+ }
347
+
348
+ export class IncomingResponse {
349
+ status(): StatusCode;
350
+ headers(): Headers;
351
+ consume(): IncomingBody;
352
+ }
353
+
354
+ export class OutgoingBody {
355
+ write(): OutputStream;
356
+ static finish(this_: OutgoingBody, trailers: Trailers | undefined): void;
357
+ }
358
+
359
+ export class IncomingRequest {
360
+ method(): Method;
361
+ pathWithQuery(): string | undefined;
362
+ scheme(): Scheme | undefined;
363
+ authority(): string | undefined;
364
+ headers(): Headers;
365
+ consume(): IncomingBody;
366
+ }
367
+
368
+ export class FutureIncomingResponse {
369
+ subscribe(): Pollable;
370
+ get(): Result<Result<IncomingResponse, Error>, void> | undefined;
371
+ }
@@ -175,34 +175,27 @@ export namespace WasiIoStreams {
175
175
  /**
176
176
  * Read from one stream and write to another.
177
177
  *
178
+ * The behavior of splice is equivelant to:
179
+ * 1. calling `check-write` on the `output-stream`
180
+ * 2. calling `read` on the `input-stream` with the smaller of the
181
+ * `check-write` permitted length and the `len` provided to `splice`
182
+ * 3. calling `write` on the `output-stream` with that read data.
183
+ *
184
+ * Any error reported by the call to `check-write`, `read`, or
185
+ * `write` ends the splice and reports that error.
186
+ *
178
187
  * This function returns the number of bytes transferred; it may be less
179
188
  * than `len`.
180
- *
181
- * Unlike other I/O functions, this function blocks until all the data
182
- * read from the input stream has been written to the output stream.
183
189
  */
184
190
  /**
185
191
  * Read from one stream and write to another, with blocking.
186
192
  *
187
- * This is similar to `splice`, except that it blocks until at least
188
- * one byte can be read.
189
- */
190
- /**
191
- * Forward the entire contents of an input stream to an output stream.
192
- *
193
- * This function repeatedly reads from the input stream and writes
194
- * the data to the output stream, until the end of the input stream
195
- * is reached, or an error is encountered.
196
- *
197
- * Unlike other I/O functions, this function blocks until the end
198
- * of the input stream is seen and all the data has been written to
199
- * the output stream.
200
- *
201
- * This function returns the number of bytes transferred, and the status of
202
- * the output stream.
193
+ * This is similar to `splice`, except that it blocks until the
194
+ * `output-stream` is ready for writing, and the `input-stream`
195
+ * is ready for reading, before performing the `splice`.
203
196
  */
204
197
  }
205
- import type { Pollable } from '../interfaces/wasi-io-poll';
198
+ import type { Pollable } from '../interfaces/wasi-io-poll.js';
206
199
  export { Pollable };
207
200
  /**
208
201
  * An error for input-stream and output-stream operations.
@@ -237,7 +230,6 @@ export namespace WasiIoStreams {
237
230
  blockingWriteZeroesAndFlush(len: bigint): void;
238
231
  splice(src: InputStream, len: bigint): bigint;
239
232
  blockingSplice(src: InputStream, len: bigint): bigint;
240
- forward(src: InputStream): bigint;
241
233
  }
242
234
 
243
235
  export class Error {
@@ -4,5 +4,5 @@ export namespace WasiSocketsInstanceNetwork {
4
4
  */
5
5
  export function instanceNetwork(): Network;
6
6
  }
7
- import type { Network } from '../interfaces/wasi-sockets-network';
7
+ import type { Network } from '../interfaces/wasi-sockets-network.js';
8
8
  export { Network };
@@ -55,15 +55,15 @@ export namespace WasiSocketsIpNameLookup {
55
55
  * It's planned to be removed when `future` is natively supported in Preview3.
56
56
  */
57
57
  }
58
- import type { Pollable } from '../interfaces/wasi-io-poll';
58
+ import type { Pollable } from '../interfaces/wasi-io-poll.js';
59
59
  export { Pollable };
60
- import type { Network } from '../interfaces/wasi-sockets-network';
60
+ import type { Network } from '../interfaces/wasi-sockets-network.js';
61
61
  export { Network };
62
- import type { ErrorCode } from '../interfaces/wasi-sockets-network';
62
+ import type { ErrorCode } from '../interfaces/wasi-sockets-network.js';
63
63
  export { ErrorCode };
64
- import type { IpAddress } from '../interfaces/wasi-sockets-network';
64
+ import type { IpAddress } from '../interfaces/wasi-sockets-network.js';
65
65
  export { IpAddress };
66
- import type { IpAddressFamily } from '../interfaces/wasi-sockets-network';
66
+ import type { IpAddressFamily } from '../interfaces/wasi-sockets-network.js';
67
67
  export { IpAddressFamily };
68
68
 
69
69
  export class ResolveAddressStream {
@@ -22,11 +22,11 @@ export namespace WasiSocketsTcpCreateSocket {
22
22
  */
23
23
  export function createTcpSocket(addressFamily: IpAddressFamily): TcpSocket;
24
24
  }
25
- import type { Network } from '../interfaces/wasi-sockets-network';
25
+ import type { Network } from '../interfaces/wasi-sockets-network.js';
26
26
  export { Network };
27
- import type { ErrorCode } from '../interfaces/wasi-sockets-network';
27
+ import type { ErrorCode } from '../interfaces/wasi-sockets-network.js';
28
28
  export { ErrorCode };
29
- import type { IpAddressFamily } from '../interfaces/wasi-sockets-network';
29
+ import type { IpAddressFamily } from '../interfaces/wasi-sockets-network.js';
30
30
  export { IpAddressFamily };
31
- import type { TcpSocket } from '../interfaces/wasi-sockets-tcp';
31
+ import type { TcpSocket } from '../interfaces/wasi-sockets-tcp.js';
32
32
  export { TcpSocket };
@@ -238,19 +238,19 @@ export namespace WasiSocketsTcp {
238
238
  * - <https://man.freebsd.org/cgi/man.cgi?query=shutdown&sektion=2>
239
239
  */
240
240
  }
241
- import type { InputStream } from '../interfaces/wasi-io-streams';
241
+ import type { InputStream } from '../interfaces/wasi-io-streams.js';
242
242
  export { InputStream };
243
- import type { OutputStream } from '../interfaces/wasi-io-streams';
243
+ import type { OutputStream } from '../interfaces/wasi-io-streams.js';
244
244
  export { OutputStream };
245
- import type { Pollable } from '../interfaces/wasi-io-poll';
245
+ import type { Pollable } from '../interfaces/wasi-io-poll.js';
246
246
  export { Pollable };
247
- import type { Network } from '../interfaces/wasi-sockets-network';
247
+ import type { Network } from '../interfaces/wasi-sockets-network.js';
248
248
  export { Network };
249
- import type { ErrorCode } from '../interfaces/wasi-sockets-network';
249
+ import type { ErrorCode } from '../interfaces/wasi-sockets-network.js';
250
250
  export { ErrorCode };
251
- import type { IpSocketAddress } from '../interfaces/wasi-sockets-network';
251
+ import type { IpSocketAddress } from '../interfaces/wasi-sockets-network.js';
252
252
  export { IpSocketAddress };
253
- import type { IpAddressFamily } from '../interfaces/wasi-sockets-network';
253
+ import type { IpAddressFamily } from '../interfaces/wasi-sockets-network.js';
254
254
  export { IpAddressFamily };
255
255
  /**
256
256
  * # Variants
@@ -22,11 +22,11 @@ export namespace WasiSocketsUdpCreateSocket {
22
22
  */
23
23
  export function createUdpSocket(addressFamily: IpAddressFamily): UdpSocket;
24
24
  }
25
- import type { Network } from '../interfaces/wasi-sockets-network';
25
+ import type { Network } from '../interfaces/wasi-sockets-network.js';
26
26
  export { Network };
27
- import type { ErrorCode } from '../interfaces/wasi-sockets-network';
27
+ import type { ErrorCode } from '../interfaces/wasi-sockets-network.js';
28
28
  export { ErrorCode };
29
- import type { IpAddressFamily } from '../interfaces/wasi-sockets-network';
29
+ import type { IpAddressFamily } from '../interfaces/wasi-sockets-network.js';
30
30
  export { IpAddressFamily };
31
- import type { UdpSocket } from '../interfaces/wasi-sockets-udp';
31
+ import type { UdpSocket } from '../interfaces/wasi-sockets-udp.js';
32
32
  export { UdpSocket };
@@ -184,15 +184,15 @@ export namespace WasiSocketsUdp {
184
184
  * It's planned to be removed when `future` is natively supported in Preview3.
185
185
  */
186
186
  }
187
- import type { Pollable } from '../interfaces/wasi-io-poll';
187
+ import type { Pollable } from '../interfaces/wasi-io-poll.js';
188
188
  export { Pollable };
189
- import type { Network } from '../interfaces/wasi-sockets-network';
189
+ import type { Network } from '../interfaces/wasi-sockets-network.js';
190
190
  export { Network };
191
- import type { ErrorCode } from '../interfaces/wasi-sockets-network';
191
+ import type { ErrorCode } from '../interfaces/wasi-sockets-network.js';
192
192
  export { ErrorCode };
193
- import type { IpSocketAddress } from '../interfaces/wasi-sockets-network';
193
+ import type { IpSocketAddress } from '../interfaces/wasi-sockets-network.js';
194
194
  export { IpSocketAddress };
195
- import type { IpAddressFamily } from '../interfaces/wasi-sockets-network';
195
+ import type { IpAddressFamily } from '../interfaces/wasi-sockets-network.js';
196
196
  export { IpAddressFamily };
197
197
  export interface Datagram {
198
198
  data: Uint8Array,
@@ -15,15 +15,15 @@ import { WasiFilesystemPreopens } from './interfaces/wasi-filesystem-preopens';
15
15
  import { WasiFilesystemTypes } from './interfaces/wasi-filesystem-types';
16
16
  import { WasiIoPoll } from './interfaces/wasi-io-poll';
17
17
  import { WasiIoStreams } from './interfaces/wasi-io-streams';
18
- import { WasiRandomInsecure } from './interfaces/wasi-random-insecure';
19
18
  import { WasiRandomInsecureSeed } from './interfaces/wasi-random-insecure-seed';
19
+ import { WasiRandomInsecure } from './interfaces/wasi-random-insecure';
20
20
  import { WasiRandomRandom } from './interfaces/wasi-random-random';
21
21
  import { WasiSocketsInstanceNetwork } from './interfaces/wasi-sockets-instance-network';
22
22
  import { WasiSocketsIpNameLookup } from './interfaces/wasi-sockets-ip-name-lookup';
23
23
  import { WasiSocketsNetwork } from './interfaces/wasi-sockets-network';
24
- import { WasiSocketsTcp } from './interfaces/wasi-sockets-tcp';
25
24
  import { WasiSocketsTcpCreateSocket } from './interfaces/wasi-sockets-tcp-create-socket';
26
- import { WasiSocketsUdp } from './interfaces/wasi-sockets-udp';
25
+ import { WasiSocketsTcp } from './interfaces/wasi-sockets-tcp';
27
26
  import { WasiSocketsUdpCreateSocket } from './interfaces/wasi-sockets-udp-create-socket';
27
+ import { WasiSocketsUdp } from './interfaces/wasi-sockets-udp';
28
28
  import { WasiCliRun } from './interfaces/wasi-cli-run';
29
29
  export const run: typeof WasiCliRun;
@@ -0,0 +1,13 @@
1
+ import { WasiCliStderr } from './interfaces/wasi-cli-stderr';
2
+ import { WasiCliStdin } from './interfaces/wasi-cli-stdin';
3
+ import { WasiCliStdout } from './interfaces/wasi-cli-stdout';
4
+ import { WasiClocksMonotonicClock } from './interfaces/wasi-clocks-monotonic-clock';
5
+ import { WasiClocksTimezone } from './interfaces/wasi-clocks-timezone';
6
+ import { WasiClocksWallClock } from './interfaces/wasi-clocks-wall-clock';
7
+ import { WasiHttpOutgoingHandler } from './interfaces/wasi-http-outgoing-handler';
8
+ import { WasiHttpTypes } from './interfaces/wasi-http-types';
9
+ import { WasiIoPoll } from './interfaces/wasi-io-poll';
10
+ import { WasiIoStreams } from './interfaces/wasi-io-streams';
11
+ import { WasiRandomRandom } from './interfaces/wasi-random-random';
12
+ import { WasiHttpIncomingHandler } from './interfaces/wasi-http-incoming-handler';
13
+ export const incomingHandler: typeof WasiHttpIncomingHandler;
@@ -1,53 +0,0 @@
1
- let polls = {};
2
- let pollCnt = 1;
3
-
4
- let timer = null, timerInterval = 10, watching = new Set();
5
- function intervalCheck () {
6
- for (const entry of watching) {
7
- if (entry.settled) {
8
- entry.resolvePromise();
9
- entry.promise = entry.resolvePromise = null;
10
- watching.delete(entry);
11
- }
12
- }
13
- if (watching.size === 0) {
14
- clearInterval(timer);
15
- timer = null;
16
- }
17
- }
18
-
19
- export function _createPollable (promise) {
20
- const entry = { settled: false, promise: null, resolvePromise: null };
21
- promise.finally(() => entry.settled = true);
22
- polls[pollCnt] = entry;
23
- return pollCnt++;
24
- }
25
-
26
- export function _pollablePromise (pollable, maxInterval) {
27
- const entry = polls[pollable];
28
- if (entry.settled) return Promise.resolve();
29
- if (!entry.promise)
30
- entry.promise = new Promise(resolve => entry.resolvePromise = resolve);
31
- watching.add(entry);
32
- if (maxInterval) {
33
- if (timerInterval > maxInterval) {
34
- clearInterval(timer);
35
- timer = null;
36
- timerInterval = maxInterval;
37
- }
38
- }
39
- if (!timer)
40
- timer = setInterval(intervalCheck, timerInterval);
41
- return entry.promise;
42
- }
43
-
44
- export const poll = {
45
- dropPollable (pollable) {
46
- const entry = polls[pollable];
47
- watching.delete(entry);
48
- delete polls[pollable];
49
- },
50
- pollOneoff (from) {
51
- return from.map(pollable => polls[pollable].settled);
52
- }
53
- };