@bytecodealliance/preview2-shim 0.0.21 → 0.14.1

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 (44) hide show
  1. package/README.md +4 -14
  2. package/lib/browser/cli.js +2 -4
  3. package/lib/browser/clocks.js +15 -27
  4. package/lib/browser/filesystem.js +2 -30
  5. package/lib/browser/http.js +1 -3
  6. package/lib/browser/io.js +4 -2
  7. package/lib/common/assert.js +7 -0
  8. package/lib/io/calls.js +64 -0
  9. package/lib/io/worker-http.js +95 -0
  10. package/lib/io/worker-io.js +322 -0
  11. package/lib/io/worker-thread.js +569 -0
  12. package/lib/nodejs/cli.js +45 -59
  13. package/lib/nodejs/clocks.js +13 -27
  14. package/lib/nodejs/filesystem.js +539 -459
  15. package/lib/nodejs/http.js +440 -173
  16. package/lib/nodejs/index.js +4 -1
  17. package/lib/nodejs/io.js +1 -0
  18. package/lib/nodejs/sockets/socket-common.js +116 -0
  19. package/lib/nodejs/sockets/socketopts-bindings.js +94 -0
  20. package/lib/nodejs/sockets/tcp-socket-impl.js +794 -0
  21. package/lib/nodejs/sockets/udp-socket-impl.js +628 -0
  22. package/lib/nodejs/sockets/wasi-sockets.js +320 -0
  23. package/lib/nodejs/sockets.js +11 -200
  24. package/lib/synckit/index.js +4 -2
  25. package/package.json +1 -5
  26. package/types/interfaces/wasi-cli-terminal-input.d.ts +4 -0
  27. package/types/interfaces/wasi-cli-terminal-output.d.ts +4 -0
  28. package/types/interfaces/wasi-clocks-monotonic-clock.d.ts +19 -6
  29. package/types/interfaces/wasi-filesystem-types.d.ts +1 -178
  30. package/types/interfaces/wasi-http-outgoing-handler.d.ts +2 -2
  31. package/types/interfaces/wasi-http-types.d.ts +412 -82
  32. package/types/interfaces/wasi-io-error.d.ts +16 -0
  33. package/types/interfaces/wasi-io-poll.d.ts +19 -8
  34. package/types/interfaces/wasi-io-streams.d.ts +26 -46
  35. package/types/interfaces/wasi-sockets-ip-name-lookup.d.ts +9 -21
  36. package/types/interfaces/wasi-sockets-network.d.ts +4 -0
  37. package/types/interfaces/wasi-sockets-tcp.d.ts +75 -18
  38. package/types/interfaces/wasi-sockets-udp-create-socket.d.ts +1 -1
  39. package/types/interfaces/wasi-sockets-udp.d.ts +282 -193
  40. package/types/wasi-cli-command.d.ts +28 -28
  41. package/types/wasi-http-proxy.d.ts +12 -12
  42. package/lib/common/io.js +0 -183
  43. package/lib/common/make-request.js +0 -30
  44. package/types/interfaces/wasi-clocks-timezone.d.ts +0 -56
@@ -1,7 +1,29 @@
1
1
  export namespace WasiHttpTypes {
2
+ /**
3
+ * Attempts to extract a http-related `error` from the wasi:io `error`
4
+ * provided.
5
+ *
6
+ * Stream operations which return
7
+ * `wasi:io/stream/stream-error::last-operation-failed` have a payload of
8
+ * type `wasi:io/error/error` with more information about the operation
9
+ * that failed. This payload can be passed through to this function to see
10
+ * if there's http-related information about the error to return.
11
+ *
12
+ * Note that this function is fallible because not all io-errors are
13
+ * http-related errors.
14
+ */
15
+ export function httpErrorCode(err: IoError): ErrorCode | undefined;
16
+ /**
17
+ * Construct an empty HTTP Fields.
18
+ *
19
+ * The resulting `fields` is mutable.
20
+ */
21
+ export { Fields };
2
22
  /**
3
23
  * Construct an HTTP Fields.
4
24
  *
25
+ * The resulting `fields` is mutable.
26
+ *
5
27
  * The list represents each key-value pair in the Fields. Keys
6
28
  * which have multiple values are represented by multiple entries in this
7
29
  * list with the same key.
@@ -10,22 +32,30 @@ export namespace WasiHttpTypes {
10
32
  * Value, represented as a list of bytes. In a valid Fields, all keys
11
33
  * and values are valid UTF-8 strings. However, values are not always
12
34
  * well-formed, so they are represented as a raw list of bytes.
35
+ *
36
+ * An error result will be returned if any header or value was
37
+ * syntactically invalid, or if a header was forbidden.
13
38
  */
14
- export { Fields };
15
39
  /**
16
40
  * Get all of the values corresponding to a key.
17
41
  */
18
42
  /**
19
43
  * Set all of the values for a key. Clears any existing values for that
20
44
  * key, if they have been set.
45
+ *
46
+ * Fails with `header-error.immutable` if the `fields` are immutable.
21
47
  */
22
48
  /**
23
49
  * Delete all values for a key. Does nothing if no values for the key
24
50
  * exist.
51
+ *
52
+ * Fails with `header-error.immutable` if the `fields` are immutable.
25
53
  */
26
54
  /**
27
55
  * Append a value for a key. Does not change or delete any existing
28
56
  * values for that key.
57
+ *
58
+ * Fails with `header-error.immutable` if the `fields` are immutable.
29
59
  */
30
60
  /**
31
61
  * Retrieve the full set of keys and values in the Fields. Like the
@@ -37,7 +67,8 @@ export namespace WasiHttpTypes {
37
67
  */
38
68
  /**
39
69
  * Make a deep copy of the Fields. Equivelant in behavior to calling the
40
- * `fields` constructor on the return value of `entries`
70
+ * `fields` constructor on the return value of `entries`. The resulting
71
+ * `fields` is mutable.
41
72
  */
42
73
  /**
43
74
  * Returns the method of the incoming request.
@@ -53,7 +84,10 @@ export namespace WasiHttpTypes {
53
84
  * Returns the authority from the request, if it was present.
54
85
  */
55
86
  /**
56
- * Returns the `headers` from the request.
87
+ * Get the `headers` associated with the request.
88
+ *
89
+ * The returned `headers` resource is immutable: `set`, `append`, and
90
+ * `delete` operations will fail with `header-error.immutable`.
57
91
  *
58
92
  * The `headers` returned are a child resource: it must be dropped before
59
93
  * the parent `incoming-request` is dropped. Dropping this
@@ -64,12 +98,98 @@ export namespace WasiHttpTypes {
64
98
  * return success at most once, and subsequent calls will return error.
65
99
  */
66
100
  /**
67
- * Construct a new `outgoing-request`.
101
+ * Construct a new `outgoing-request` with a default `method` of `GET`, and
102
+ * `none` values for `path-with-query`, `scheme`, and `authority`.
103
+ *
104
+ * * `headers` is the HTTP Headers for the Request.
105
+ *
106
+ * It is possible to construct, or manipulate with the accessor functions
107
+ * below, an `outgoing-request` with an invalid combination of `scheme`
108
+ * and `authority`, or `headers` which are not permitted to be sent.
109
+ * It is the obligation of the `outgoing-handler.handle` implementation
110
+ * to reject invalid constructions of `outgoing-request`.
68
111
  */
69
112
  export { OutgoingRequest };
70
113
  /**
71
- * Will return the outgoing-body child at most once. If called more than
72
- * once, subsequent calls will return error.
114
+ * Returns the resource corresponding to the outgoing Body for this
115
+ * Request.
116
+ *
117
+ * Returns success on the first call: the `outgoing-body` resource for
118
+ * this `outgoing-request` can be retrieved at most once. Subsequent
119
+ * calls will return error.
120
+ */
121
+ /**
122
+ * Get the Method for the Request.
123
+ */
124
+ /**
125
+ * Set the Method for the Request. Fails if the string present in a
126
+ * `method.other` argument is not a syntactically valid method.
127
+ */
128
+ /**
129
+ * Get the combination of the HTTP Path and Query for the Request.
130
+ * When `none`, this represents an empty Path and empty Query.
131
+ */
132
+ /**
133
+ * Set the combination of the HTTP Path and Query for the Request.
134
+ * When `none`, this represents an empty Path and empty Query. Fails is the
135
+ * string given is not a syntactically valid path and query uri component.
136
+ */
137
+ /**
138
+ * Get the HTTP Related Scheme for the Request. When `none`, the
139
+ * implementation may choose an appropriate default scheme.
140
+ */
141
+ /**
142
+ * Set the HTTP Related Scheme for the Request. When `none`, the
143
+ * implementation may choose an appropriate default scheme. Fails if the
144
+ * string given is not a syntactically valid uri scheme.
145
+ */
146
+ /**
147
+ * Get the HTTP Authority for the Request. A value of `none` may be used
148
+ * with Related Schemes which do not require an Authority. The HTTP and
149
+ * HTTPS schemes always require an authority.
150
+ */
151
+ /**
152
+ * Set the HTTP Authority for the Request. A value of `none` may be used
153
+ * with Related Schemes which do not require an Authority. The HTTP and
154
+ * HTTPS schemes always require an authority. Fails if the string given is
155
+ * not a syntactically valid uri authority.
156
+ */
157
+ /**
158
+ * Get the headers associated with the Request.
159
+ *
160
+ * The returned `headers` resource is immutable: `set`, `append`, and
161
+ * `delete` operations will fail with `header-error.immutable`.
162
+ *
163
+ * This headers resource is a child: it must be dropped before the parent
164
+ * `outgoing-request` is dropped, or its ownership is transfered to
165
+ * another component by e.g. `outgoing-handler.handle`.
166
+ */
167
+ /**
168
+ * Construct a default `request-options` value.
169
+ */
170
+ export { RequestOptions };
171
+ /**
172
+ * The timeout for the initial connect to the HTTP Server.
173
+ */
174
+ /**
175
+ * Set the timeout for the initial connect to the HTTP Server. An error
176
+ * return value indicates that this timeout is not supported.
177
+ */
178
+ /**
179
+ * The timeout for receiving the first byte of the Response body.
180
+ */
181
+ /**
182
+ * Set the timeout for receiving the first byte of the Response body. An
183
+ * error return value indicates that this timeout is not supported.
184
+ */
185
+ /**
186
+ * The timeout for receiving subsequent chunks of bytes in the Response
187
+ * body stream.
188
+ */
189
+ /**
190
+ * Set the timeout for receiving subsequent chunks of bytes in the Response
191
+ * body stream. An error return value indicates that this timeout is not
192
+ * supported.
73
193
  */
74
194
  /**
75
195
  * Set the value of the `response-outparam` to either send a response,
@@ -78,6 +198,9 @@ export namespace WasiHttpTypes {
78
198
  * This method consumes the `response-outparam` to ensure that it is
79
199
  * called at most once. If it is never called, the implementation
80
200
  * will respond with an error.
201
+ *
202
+ * The user may provide an `error` to `response` to allow the
203
+ * implementation determine how to respond with an HTTP error response.
81
204
  */
82
205
  export { ResponseOutparam };
83
206
  /**
@@ -86,6 +209,12 @@ export namespace WasiHttpTypes {
86
209
  export { IncomingResponse };
87
210
  /**
88
211
  * Returns the headers from the incoming response.
212
+ *
213
+ * The returned `headers` resource is immutable: `set`, `append`, and
214
+ * `delete` operations will fail with `header-error.immutable`.
215
+ *
216
+ * This headers resource is a child: it must be dropped before the parent
217
+ * `incoming-response` is dropped.
89
218
  */
90
219
  /**
91
220
  * Returns the incoming body. May be called at most once. Returns error
@@ -128,20 +257,45 @@ export namespace WasiHttpTypes {
128
257
  *
129
258
  * The `result` represents that either the HTTP Request or Response body,
130
259
  * as well as any trailers, were received successfully, or that an error
131
- * occured receiving them.
260
+ * occured receiving them. The optional `trailers` indicates whether or not
261
+ * trailers were present in the body.
262
+ *
263
+ * When some `trailers` are returned by this method, the `trailers`
264
+ * resource is immutable, and a child. Use of the `set`, `append`, or
265
+ * `delete` methods will return an error, and the resource must be
266
+ * dropped before the parent `future-trailers` is dropped.
132
267
  */
133
268
  /**
134
- * Construct an `outgoing-response`.
269
+ * Construct an `outgoing-response`, with a default `status-code` of `200`.
270
+ * If a different `status-code` is needed, it must be set via the
271
+ * `set-status-code` method.
272
+ *
273
+ * * `headers` is the HTTP Headers for the Response.
135
274
  */
136
275
  export { OutgoingResponse };
276
+ /**
277
+ * Get the HTTP Status Code for the Response.
278
+ */
279
+ /**
280
+ * Set the HTTP Status Code for the Response. Fails if the status-code
281
+ * given is not a valid http status code.
282
+ */
283
+ /**
284
+ * Get the headers associated with the Request.
285
+ *
286
+ * The returned `headers` resource is immutable: `set`, `append`, and
287
+ * `delete` operations will fail with `header-error.immutable`.
288
+ *
289
+ * This headers resource is a child: it must be dropped before the parent
290
+ * `outgoing-request` is dropped, or its ownership is transfered to
291
+ * another component by e.g. `outgoing-handler.handle`.
292
+ */
137
293
  /**
138
294
  * Returns the resource corresponding to the outgoing Body for this Response.
139
295
  *
140
296
  * Returns success on the first call: the `outgoing-body` resource for
141
- * this `outgoing-response` can be retrieved at most once. Sunsequent
297
+ * this `outgoing-response` can be retrieved at most once. Subsequent
142
298
  * calls will return error.
143
- *
144
- * FIXME: rename this method to `body`.
145
299
  */
146
300
  /**
147
301
  * Returns a stream for writing the body contents.
@@ -160,6 +314,11 @@ export namespace WasiHttpTypes {
160
314
  * called to signal that the response is complete. If the `outgoing-body`
161
315
  * is dropped without calling `outgoing-body.finalize`, the implementation
162
316
  * should treat the body as corrupted.
317
+ *
318
+ * Fails if the body's `outgoing-request` or `outgoing-response` was
319
+ * constructed with a Content-Length header, and the contents written
320
+ * to the body (via `write`) does not match the value given in the
321
+ * Content-Length.
163
322
  */
164
323
  /**
165
324
  * Returns a pollable which becomes ready when either the Response has
@@ -184,10 +343,14 @@ export namespace WasiHttpTypes {
184
343
  * `output-stream` child.
185
344
  */
186
345
  }
346
+ import type { Duration } from '../interfaces/wasi-clocks-monotonic-clock.js';
347
+ export { Duration };
187
348
  import type { InputStream } from '../interfaces/wasi-io-streams.js';
188
349
  export { InputStream };
189
350
  import type { OutputStream } from '../interfaces/wasi-io-streams.js';
190
351
  export { OutputStream };
352
+ import type { IoError } from '../interfaces/wasi-io-error.js';
353
+ export { IoError };
191
354
  import type { Pollable } from '../interfaces/wasi-io-poll.js';
192
355
  export { Pollable };
193
356
  /**
@@ -240,26 +403,196 @@ export interface SchemeOther {
240
403
  val: string,
241
404
  }
242
405
  /**
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.
406
+ * Defines the case payload type for `DNS-error` above:
246
407
  */
247
- export type Error = ErrorInvalidUrl | ErrorTimeoutError | ErrorProtocolError | ErrorUnexpectedError;
248
- export interface ErrorInvalidUrl {
249
- tag: 'invalid-url',
250
- val: string,
408
+ export interface DnsErrorPayload {
409
+ rcode?: string,
410
+ infoCode?: number,
251
411
  }
252
- export interface ErrorTimeoutError {
253
- tag: 'timeout-error',
254
- val: string,
412
+ /**
413
+ * Defines the case payload type for `TLS-alert-received` above:
414
+ */
415
+ export interface TlsAlertReceivedPayload {
416
+ alertId?: number,
417
+ alertMessage?: string,
255
418
  }
256
- export interface ErrorProtocolError {
257
- tag: 'protocol-error',
258
- val: string,
419
+ /**
420
+ * Defines the case payload type for `HTTP-response-{header,trailer}-size` above:
421
+ */
422
+ export interface FieldSizePayload {
423
+ fieldName?: string,
424
+ fieldSize?: number,
259
425
  }
260
- export interface ErrorUnexpectedError {
261
- tag: 'unexpected-error',
262
- val: string,
426
+ /**
427
+ * These cases are inspired by the IANA HTTP Proxy Error Types:
428
+ * https://www.iana.org/assignments/http-proxy-status/http-proxy-status.xhtml#table-http-proxy-error-types
429
+ */
430
+ export type ErrorCode = ErrorCodeDnsTimeout | ErrorCodeDnsError | ErrorCodeDestinationNotFound | ErrorCodeDestinationUnavailable | ErrorCodeDestinationIpProhibited | ErrorCodeDestinationIpUnroutable | ErrorCodeConnectionRefused | ErrorCodeConnectionTerminated | ErrorCodeConnectionTimeout | ErrorCodeConnectionReadTimeout | ErrorCodeConnectionWriteTimeout | ErrorCodeConnectionLimitReached | ErrorCodeTlsProtocolError | ErrorCodeTlsCertificateError | ErrorCodeTlsAlertReceived | ErrorCodeHttpRequestDenied | ErrorCodeHttpRequestLengthRequired | ErrorCodeHttpRequestBodySize | ErrorCodeHttpRequestMethodInvalid | ErrorCodeHttpRequestUriInvalid | ErrorCodeHttpRequestUriTooLong | ErrorCodeHttpRequestHeaderSectionSize | ErrorCodeHttpRequestHeaderSize | ErrorCodeHttpRequestTrailerSectionSize | ErrorCodeHttpRequestTrailerSize | ErrorCodeHttpResponseIncomplete | ErrorCodeHttpResponseHeaderSectionSize | ErrorCodeHttpResponseHeaderSize | ErrorCodeHttpResponseBodySize | ErrorCodeHttpResponseTrailerSectionSize | ErrorCodeHttpResponseTrailerSize | ErrorCodeHttpResponseTransferCoding | ErrorCodeHttpResponseContentCoding | ErrorCodeHttpResponseTimeout | ErrorCodeHttpUpgradeFailed | ErrorCodeHttpProtocolError | ErrorCodeLoopDetected | ErrorCodeConfigurationError | ErrorCodeInternalError;
431
+ export interface ErrorCodeDnsTimeout {
432
+ tag: 'DNS-timeout',
433
+ }
434
+ export interface ErrorCodeDnsError {
435
+ tag: 'DNS-error',
436
+ val: DnsErrorPayload,
437
+ }
438
+ export interface ErrorCodeDestinationNotFound {
439
+ tag: 'destination-not-found',
440
+ }
441
+ export interface ErrorCodeDestinationUnavailable {
442
+ tag: 'destination-unavailable',
443
+ }
444
+ export interface ErrorCodeDestinationIpProhibited {
445
+ tag: 'destination-IP-prohibited',
446
+ }
447
+ export interface ErrorCodeDestinationIpUnroutable {
448
+ tag: 'destination-IP-unroutable',
449
+ }
450
+ export interface ErrorCodeConnectionRefused {
451
+ tag: 'connection-refused',
452
+ }
453
+ export interface ErrorCodeConnectionTerminated {
454
+ tag: 'connection-terminated',
455
+ }
456
+ export interface ErrorCodeConnectionTimeout {
457
+ tag: 'connection-timeout',
458
+ }
459
+ export interface ErrorCodeConnectionReadTimeout {
460
+ tag: 'connection-read-timeout',
461
+ }
462
+ export interface ErrorCodeConnectionWriteTimeout {
463
+ tag: 'connection-write-timeout',
464
+ }
465
+ export interface ErrorCodeConnectionLimitReached {
466
+ tag: 'connection-limit-reached',
467
+ }
468
+ export interface ErrorCodeTlsProtocolError {
469
+ tag: 'TLS-protocol-error',
470
+ }
471
+ export interface ErrorCodeTlsCertificateError {
472
+ tag: 'TLS-certificate-error',
473
+ }
474
+ export interface ErrorCodeTlsAlertReceived {
475
+ tag: 'TLS-alert-received',
476
+ val: TlsAlertReceivedPayload,
477
+ }
478
+ export interface ErrorCodeHttpRequestDenied {
479
+ tag: 'HTTP-request-denied',
480
+ }
481
+ export interface ErrorCodeHttpRequestLengthRequired {
482
+ tag: 'HTTP-request-length-required',
483
+ }
484
+ export interface ErrorCodeHttpRequestBodySize {
485
+ tag: 'HTTP-request-body-size',
486
+ val: bigint | undefined,
487
+ }
488
+ export interface ErrorCodeHttpRequestMethodInvalid {
489
+ tag: 'HTTP-request-method-invalid',
490
+ }
491
+ export interface ErrorCodeHttpRequestUriInvalid {
492
+ tag: 'HTTP-request-URI-invalid',
493
+ }
494
+ export interface ErrorCodeHttpRequestUriTooLong {
495
+ tag: 'HTTP-request-URI-too-long',
496
+ }
497
+ export interface ErrorCodeHttpRequestHeaderSectionSize {
498
+ tag: 'HTTP-request-header-section-size',
499
+ val: number | undefined,
500
+ }
501
+ export interface ErrorCodeHttpRequestHeaderSize {
502
+ tag: 'HTTP-request-header-size',
503
+ val: FieldSizePayload | undefined,
504
+ }
505
+ export interface ErrorCodeHttpRequestTrailerSectionSize {
506
+ tag: 'HTTP-request-trailer-section-size',
507
+ val: number | undefined,
508
+ }
509
+ export interface ErrorCodeHttpRequestTrailerSize {
510
+ tag: 'HTTP-request-trailer-size',
511
+ val: FieldSizePayload,
512
+ }
513
+ export interface ErrorCodeHttpResponseIncomplete {
514
+ tag: 'HTTP-response-incomplete',
515
+ }
516
+ export interface ErrorCodeHttpResponseHeaderSectionSize {
517
+ tag: 'HTTP-response-header-section-size',
518
+ val: number | undefined,
519
+ }
520
+ export interface ErrorCodeHttpResponseHeaderSize {
521
+ tag: 'HTTP-response-header-size',
522
+ val: FieldSizePayload,
523
+ }
524
+ export interface ErrorCodeHttpResponseBodySize {
525
+ tag: 'HTTP-response-body-size',
526
+ val: bigint | undefined,
527
+ }
528
+ export interface ErrorCodeHttpResponseTrailerSectionSize {
529
+ tag: 'HTTP-response-trailer-section-size',
530
+ val: number | undefined,
531
+ }
532
+ export interface ErrorCodeHttpResponseTrailerSize {
533
+ tag: 'HTTP-response-trailer-size',
534
+ val: FieldSizePayload,
535
+ }
536
+ export interface ErrorCodeHttpResponseTransferCoding {
537
+ tag: 'HTTP-response-transfer-coding',
538
+ val: string | undefined,
539
+ }
540
+ export interface ErrorCodeHttpResponseContentCoding {
541
+ tag: 'HTTP-response-content-coding',
542
+ val: string | undefined,
543
+ }
544
+ export interface ErrorCodeHttpResponseTimeout {
545
+ tag: 'HTTP-response-timeout',
546
+ }
547
+ export interface ErrorCodeHttpUpgradeFailed {
548
+ tag: 'HTTP-upgrade-failed',
549
+ }
550
+ export interface ErrorCodeHttpProtocolError {
551
+ tag: 'HTTP-protocol-error',
552
+ }
553
+ export interface ErrorCodeLoopDetected {
554
+ tag: 'loop-detected',
555
+ }
556
+ export interface ErrorCodeConfigurationError {
557
+ tag: 'configuration-error',
558
+ }
559
+ /**
560
+ * This is a catch-all error for anything that doesn't fit cleanly into a
561
+ * more specific case. It also includes an optional string for an
562
+ * unstructured description of the error. Users should not depend on the
563
+ * string for diagnosing errors, as it's not required to be consistent
564
+ * between implementations.
565
+ */
566
+ export interface ErrorCodeInternalError {
567
+ tag: 'internal-error',
568
+ val: string | undefined,
569
+ }
570
+ /**
571
+ * This type enumerates the different kinds of errors that may occur when
572
+ * setting or appending to a `fields` resource.
573
+ */
574
+ export type HeaderError = HeaderErrorInvalidSyntax | HeaderErrorForbidden | HeaderErrorImmutable;
575
+ /**
576
+ * This error indicates that a `field-key` or `field-value` was
577
+ * syntactically invalid when used with an operation that sets headers in a
578
+ * `fields`.
579
+ */
580
+ export interface HeaderErrorInvalidSyntax {
581
+ tag: 'invalid-syntax',
582
+ }
583
+ /**
584
+ * This error indicates that a forbidden `field-key` was used when trying
585
+ * to set a header in a `fields`.
586
+ */
587
+ export interface HeaderErrorForbidden {
588
+ tag: 'forbidden',
589
+ }
590
+ /**
591
+ * This error indicates that the operation on the `fields` was not
592
+ * permitted because the fields are immutable.
593
+ */
594
+ export interface HeaderErrorImmutable {
595
+ tag: 'immutable',
263
596
  }
264
597
  /**
265
598
  * Field keys are always strings.
@@ -279,59 +612,20 @@ export type Headers = Fields;
279
612
  * Trailers is an alias for Fields.
280
613
  */
281
614
  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
615
  /**
310
616
  * This type corresponds to the HTTP standard Status Code.
311
617
  */
312
618
  export type StatusCode = number;
619
+ export type Result<T, E> = { tag: 'ok', val: T } | { tag: 'err', val: E };
313
620
 
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;
621
+ export class FutureIncomingResponse {
622
+ subscribe(): Pollable;
623
+ get(): Result<Result<IncomingResponse, ErrorCode>, void> | undefined;
331
624
  }
332
625
 
333
626
  export class Fields {
334
- constructor(entries: [FieldKey, FieldValue][])
627
+ constructor()
628
+ static fromList(entries: [FieldKey, FieldValue][]): Fields;
335
629
  get(name: FieldKey): FieldValue[];
336
630
  set(name: FieldKey, value: FieldValue[]): void;
337
631
  delete(name: FieldKey): void;
@@ -342,18 +636,40 @@ export class Fields {
342
636
 
343
637
  export class FutureTrailers {
344
638
  subscribe(): Pollable;
345
- get(): Result<Trailers, Error> | undefined;
639
+ get(): Result<Trailers | undefined, ErrorCode> | undefined;
346
640
  }
347
641
 
348
- export class IncomingResponse {
349
- status(): StatusCode;
642
+ export class OutgoingRequest {
643
+ constructor(headers: Headers)
644
+ body(): OutgoingBody;
645
+ method(): Method;
646
+ setMethod(method: Method): void;
647
+ pathWithQuery(): string | undefined;
648
+ setPathWithQuery(pathWithQuery: string | undefined): void;
649
+ scheme(): Scheme | undefined;
650
+ setScheme(scheme: Scheme | undefined): void;
651
+ authority(): string | undefined;
652
+ setAuthority(authority: string | undefined): void;
350
653
  headers(): Headers;
351
- consume(): IncomingBody;
352
654
  }
353
655
 
354
- export class OutgoingBody {
355
- write(): OutputStream;
356
- static finish(this_: OutgoingBody, trailers: Trailers | undefined): void;
656
+ export class RequestOptions {
657
+ constructor()
658
+ connectTimeoutMs(): Duration | undefined;
659
+ setConnectTimeoutMs(ms: Duration | undefined): void;
660
+ firstByteTimeoutMs(): Duration | undefined;
661
+ setFirstByteTimeoutMs(ms: Duration | undefined): void;
662
+ betweenBytesTimeoutMs(): Duration | undefined;
663
+ setBetweenBytesTimeoutMs(ms: Duration | undefined): void;
664
+ }
665
+
666
+ export class IncomingBody {
667
+ stream(): InputStream;
668
+ static finish(this_: IncomingBody): FutureTrailers;
669
+ }
670
+
671
+ export class ResponseOutparam {
672
+ static set(param: ResponseOutparam, response: Result<OutgoingResponse, ErrorCode>): void;
357
673
  }
358
674
 
359
675
  export class IncomingRequest {
@@ -365,7 +681,21 @@ export class IncomingRequest {
365
681
  consume(): IncomingBody;
366
682
  }
367
683
 
368
- export class FutureIncomingResponse {
369
- subscribe(): Pollable;
370
- get(): Result<Result<IncomingResponse, Error>, void> | undefined;
684
+ export class OutgoingResponse {
685
+ constructor(headers: Headers)
686
+ statusCode(): StatusCode;
687
+ setStatusCode(statusCode: StatusCode): void;
688
+ headers(): Headers;
689
+ body(): OutgoingBody;
690
+ }
691
+
692
+ export class IncomingResponse {
693
+ status(): StatusCode;
694
+ headers(): Headers;
695
+ consume(): IncomingBody;
696
+ }
697
+
698
+ export class OutgoingBody {
699
+ write(): OutputStream;
700
+ static finish(this_: OutgoingBody, trailers: Trailers | undefined): void;
371
701
  }
@@ -0,0 +1,16 @@
1
+ export namespace WasiIoError {
2
+ /**
3
+ * Returns a string that is suitable to assist humans in debugging
4
+ * this error.
5
+ *
6
+ * WARNING: The returned string should not be consumed mechanically!
7
+ * It may change across platforms, hosts, or other implementation
8
+ * details. Parsing this string is a major platform-compatibility
9
+ * hazard.
10
+ */
11
+ export { Error };
12
+ }
13
+
14
+ export class Error {
15
+ toDebugString(): string;
16
+ }
@@ -1,4 +1,17 @@
1
1
  export namespace WasiIoPoll {
2
+ /**
3
+ * Return the readiness of a pollable. This function never blocks.
4
+ *
5
+ * Returns `true` when the pollable is ready, and `false` otherwise.
6
+ */
7
+ export { Pollable };
8
+ /**
9
+ * `block` returns immediately if the pollable is ready, and otherwise
10
+ * blocks until ready.
11
+ *
12
+ * This function is equivalent to calling `poll.poll` on a list
13
+ * containing only this pollable.
14
+ */
2
15
  /**
3
16
  * Poll for completion on a set of pollables.
4
17
  *
@@ -19,12 +32,10 @@ export namespace WasiIoPoll {
19
32
  * the pollables has an error, it is indicated by marking the source as
20
33
  * being reaedy for I/O.
21
34
  */
22
- export function pollList(in_: Pollable[]): Uint32Array;
23
- /**
24
- * Poll for completion on a single pollable.
25
- *
26
- * This function is similar to `poll-list`, but operates on only a single
27
- * pollable. When it returns, the handle is ready for I/O.
28
- */
29
- export function pollOne(in_: Pollable): void;
35
+ export function poll(in_: Pollable[]): Uint32Array;
36
+ }
37
+
38
+ export class Pollable {
39
+ ready(): boolean;
40
+ block(): void;
30
41
  }