@bytecodealliance/preview3-shim 0.1.0-rc.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +220 -0
- package/README.md +14 -0
- package/lib/nodejs/cli.js +127 -0
- package/lib/nodejs/clocks.js +100 -0
- package/lib/nodejs/filesystem/descriptor.js +997 -0
- package/lib/nodejs/filesystem/error.js +92 -0
- package/lib/nodejs/filesystem/utils.js +19 -0
- package/lib/nodejs/filesystem.js +2 -0
- package/lib/nodejs/finalization.js +33 -0
- package/lib/nodejs/future.js +187 -0
- package/lib/nodejs/http/client.js +146 -0
- package/lib/nodejs/http/error.js +71 -0
- package/lib/nodejs/http/fields.js +359 -0
- package/lib/nodejs/http/request.js +589 -0
- package/lib/nodejs/http/response.js +212 -0
- package/lib/nodejs/http/server.js +157 -0
- package/lib/nodejs/http.js +34 -0
- package/lib/nodejs/index.js +8 -0
- package/lib/nodejs/random.js +14 -0
- package/lib/nodejs/sockets/address.js +146 -0
- package/lib/nodejs/sockets/error.js +123 -0
- package/lib/nodejs/sockets/ip-name-lookup.js +93 -0
- package/lib/nodejs/sockets/tcp.js +776 -0
- package/lib/nodejs/sockets/udp.js +516 -0
- package/lib/nodejs/sockets.js +14 -0
- package/lib/nodejs/stream.js +423 -0
- package/lib/nodejs/workers/cli-worker.js +49 -0
- package/lib/nodejs/workers/filesystem-worker.js +119 -0
- package/lib/nodejs/workers/http-worker.js +387 -0
- package/lib/nodejs/workers/resource-worker.js +151 -0
- package/lib/nodejs/workers/tcp-worker.js +283 -0
- package/lib/nodejs/workers/udp-worker.js +194 -0
- package/package.json +57 -0
- package/types/cli.d.ts +12 -0
- package/types/clocks.d.ts +2 -0
- package/types/filesystem.d.ts +2 -0
- package/types/http.d.ts +4 -0
- package/types/index.d.ts +6 -0
- package/types/interfaces/wasi-cli-environment.d.ts +21 -0
- package/types/interfaces/wasi-cli-exit.d.ts +6 -0
- package/types/interfaces/wasi-cli-run.d.ts +5 -0
- package/types/interfaces/wasi-cli-stderr.d.ts +14 -0
- package/types/interfaces/wasi-cli-stdin.d.ts +19 -0
- package/types/interfaces/wasi-cli-stdout.d.ts +14 -0
- package/types/interfaces/wasi-cli-terminal-input.d.ts +8 -0
- package/types/interfaces/wasi-cli-terminal-output.d.ts +8 -0
- package/types/interfaces/wasi-cli-terminal-stderr.d.ts +7 -0
- package/types/interfaces/wasi-cli-terminal-stdin.d.ts +7 -0
- package/types/interfaces/wasi-cli-terminal-stdout.d.ts +7 -0
- package/types/interfaces/wasi-cli-types.d.ts +15 -0
- package/types/interfaces/wasi-clocks-monotonic-clock.d.ts +33 -0
- package/types/interfaces/wasi-clocks-system-clock.d.ts +38 -0
- package/types/interfaces/wasi-clocks-types.d.ts +5 -0
- package/types/interfaces/wasi-filesystem-preopens.d.ts +6 -0
- package/types/interfaces/wasi-filesystem-types.d.ts +780 -0
- package/types/interfaces/wasi-http-client.d.ts +9 -0
- package/types/interfaces/wasi-http-handler.d.ts +9 -0
- package/types/interfaces/wasi-http-types.d.ts +619 -0
- package/types/interfaces/wasi-random-insecure-seed.d.ts +21 -0
- package/types/interfaces/wasi-random-insecure.d.ts +26 -0
- package/types/interfaces/wasi-random-random.d.ts +31 -0
- package/types/interfaces/wasi-sockets-ip-name-lookup.d.ts +77 -0
- package/types/interfaces/wasi-sockets-types.d.ts +830 -0
- package/types/random.d.ts +3 -0
- package/types/sockets.d.ts +2 -0
- package/types/wasi-cli-command.d.ts +23 -0
- package/types/wasi-http-service.d.ts +14 -0
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/** @module Interface wasi:http/client@0.3.0-rc-2026-03-15 **/
|
|
2
|
+
/**
|
|
3
|
+
* This function may be used to either send an outgoing request over the
|
|
4
|
+
* network or to forward it to another component.
|
|
5
|
+
*/
|
|
6
|
+
export function send(request: Request): Promise<Response>;
|
|
7
|
+
export type Request = import('./wasi-http-types.js').Request;
|
|
8
|
+
export type Response = import('./wasi-http-types.js').Response;
|
|
9
|
+
export type ErrorCode = import('./wasi-http-types.js').ErrorCode;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/** @module Interface wasi:http/handler@0.3.0-rc-2026-03-15 **/
|
|
2
|
+
/**
|
|
3
|
+
* This function may be called with either an incoming request read from the
|
|
4
|
+
* network or a request synthesized or forwarded by another component.
|
|
5
|
+
*/
|
|
6
|
+
export function handle(request: Request): Promise<Response>;
|
|
7
|
+
export type Request = import('./wasi-http-types.js').Request;
|
|
8
|
+
export type Response = import('./wasi-http-types.js').Response;
|
|
9
|
+
export type ErrorCode = import('./wasi-http-types.js').ErrorCode;
|
|
@@ -0,0 +1,619 @@
|
|
|
1
|
+
/** @module Interface wasi:http/types@0.3.0-rc-2026-03-15 **/
|
|
2
|
+
export type Duration = import('./wasi-clocks-types.js').Duration;
|
|
3
|
+
/**
|
|
4
|
+
* This type corresponds to HTTP standard Methods.
|
|
5
|
+
*/
|
|
6
|
+
export type Method = MethodGet | MethodHead | MethodPost | MethodPut | MethodDelete | MethodConnect | MethodOptions | MethodTrace | MethodPatch | MethodOther;
|
|
7
|
+
export interface MethodGet {
|
|
8
|
+
tag: 'get',
|
|
9
|
+
}
|
|
10
|
+
export interface MethodHead {
|
|
11
|
+
tag: 'head',
|
|
12
|
+
}
|
|
13
|
+
export interface MethodPost {
|
|
14
|
+
tag: 'post',
|
|
15
|
+
}
|
|
16
|
+
export interface MethodPut {
|
|
17
|
+
tag: 'put',
|
|
18
|
+
}
|
|
19
|
+
export interface MethodDelete {
|
|
20
|
+
tag: 'delete',
|
|
21
|
+
}
|
|
22
|
+
export interface MethodConnect {
|
|
23
|
+
tag: 'connect',
|
|
24
|
+
}
|
|
25
|
+
export interface MethodOptions {
|
|
26
|
+
tag: 'options',
|
|
27
|
+
}
|
|
28
|
+
export interface MethodTrace {
|
|
29
|
+
tag: 'trace',
|
|
30
|
+
}
|
|
31
|
+
export interface MethodPatch {
|
|
32
|
+
tag: 'patch',
|
|
33
|
+
}
|
|
34
|
+
export interface MethodOther {
|
|
35
|
+
tag: 'other',
|
|
36
|
+
val: string,
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* This type corresponds to HTTP standard Related Schemes.
|
|
40
|
+
*/
|
|
41
|
+
export type Scheme = SchemeHttp | SchemeHttps | SchemeOther;
|
|
42
|
+
export interface SchemeHttp {
|
|
43
|
+
tag: 'HTTP',
|
|
44
|
+
}
|
|
45
|
+
export interface SchemeHttps {
|
|
46
|
+
tag: 'HTTPS',
|
|
47
|
+
}
|
|
48
|
+
export interface SchemeOther {
|
|
49
|
+
tag: 'other',
|
|
50
|
+
val: string,
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Defines the case payload type for `DNS-error` above:
|
|
54
|
+
*/
|
|
55
|
+
export interface DnsErrorPayload {
|
|
56
|
+
rcode?: string,
|
|
57
|
+
infoCode?: number,
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* Defines the case payload type for `TLS-alert-received` above:
|
|
61
|
+
*/
|
|
62
|
+
export interface TlsAlertReceivedPayload {
|
|
63
|
+
alertId?: number,
|
|
64
|
+
alertMessage?: string,
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* Defines the case payload type for `HTTP-response-{header,trailer}-size` above:
|
|
68
|
+
*/
|
|
69
|
+
export interface FieldSizePayload {
|
|
70
|
+
fieldName?: string,
|
|
71
|
+
fieldSize?: number,
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* These cases are inspired by the IANA HTTP Proxy Error Types:
|
|
75
|
+
* <https://www.iana.org/assignments/http-proxy-status/http-proxy-status.xhtml#table-http-proxy-error-types>
|
|
76
|
+
*/
|
|
77
|
+
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;
|
|
78
|
+
export interface ErrorCodeDnsTimeout {
|
|
79
|
+
tag: 'DNS-timeout',
|
|
80
|
+
}
|
|
81
|
+
export interface ErrorCodeDnsError {
|
|
82
|
+
tag: 'DNS-error',
|
|
83
|
+
val: DnsErrorPayload,
|
|
84
|
+
}
|
|
85
|
+
export interface ErrorCodeDestinationNotFound {
|
|
86
|
+
tag: 'destination-not-found',
|
|
87
|
+
}
|
|
88
|
+
export interface ErrorCodeDestinationUnavailable {
|
|
89
|
+
tag: 'destination-unavailable',
|
|
90
|
+
}
|
|
91
|
+
export interface ErrorCodeDestinationIpProhibited {
|
|
92
|
+
tag: 'destination-IP-prohibited',
|
|
93
|
+
}
|
|
94
|
+
export interface ErrorCodeDestinationIpUnroutable {
|
|
95
|
+
tag: 'destination-IP-unroutable',
|
|
96
|
+
}
|
|
97
|
+
export interface ErrorCodeConnectionRefused {
|
|
98
|
+
tag: 'connection-refused',
|
|
99
|
+
}
|
|
100
|
+
export interface ErrorCodeConnectionTerminated {
|
|
101
|
+
tag: 'connection-terminated',
|
|
102
|
+
}
|
|
103
|
+
export interface ErrorCodeConnectionTimeout {
|
|
104
|
+
tag: 'connection-timeout',
|
|
105
|
+
}
|
|
106
|
+
export interface ErrorCodeConnectionReadTimeout {
|
|
107
|
+
tag: 'connection-read-timeout',
|
|
108
|
+
}
|
|
109
|
+
export interface ErrorCodeConnectionWriteTimeout {
|
|
110
|
+
tag: 'connection-write-timeout',
|
|
111
|
+
}
|
|
112
|
+
export interface ErrorCodeConnectionLimitReached {
|
|
113
|
+
tag: 'connection-limit-reached',
|
|
114
|
+
}
|
|
115
|
+
export interface ErrorCodeTlsProtocolError {
|
|
116
|
+
tag: 'TLS-protocol-error',
|
|
117
|
+
}
|
|
118
|
+
export interface ErrorCodeTlsCertificateError {
|
|
119
|
+
tag: 'TLS-certificate-error',
|
|
120
|
+
}
|
|
121
|
+
export interface ErrorCodeTlsAlertReceived {
|
|
122
|
+
tag: 'TLS-alert-received',
|
|
123
|
+
val: TlsAlertReceivedPayload,
|
|
124
|
+
}
|
|
125
|
+
export interface ErrorCodeHttpRequestDenied {
|
|
126
|
+
tag: 'HTTP-request-denied',
|
|
127
|
+
}
|
|
128
|
+
export interface ErrorCodeHttpRequestLengthRequired {
|
|
129
|
+
tag: 'HTTP-request-length-required',
|
|
130
|
+
}
|
|
131
|
+
export interface ErrorCodeHttpRequestBodySize {
|
|
132
|
+
tag: 'HTTP-request-body-size',
|
|
133
|
+
val: bigint | undefined,
|
|
134
|
+
}
|
|
135
|
+
export interface ErrorCodeHttpRequestMethodInvalid {
|
|
136
|
+
tag: 'HTTP-request-method-invalid',
|
|
137
|
+
}
|
|
138
|
+
export interface ErrorCodeHttpRequestUriInvalid {
|
|
139
|
+
tag: 'HTTP-request-URI-invalid',
|
|
140
|
+
}
|
|
141
|
+
export interface ErrorCodeHttpRequestUriTooLong {
|
|
142
|
+
tag: 'HTTP-request-URI-too-long',
|
|
143
|
+
}
|
|
144
|
+
export interface ErrorCodeHttpRequestHeaderSectionSize {
|
|
145
|
+
tag: 'HTTP-request-header-section-size',
|
|
146
|
+
val: number | undefined,
|
|
147
|
+
}
|
|
148
|
+
export interface ErrorCodeHttpRequestHeaderSize {
|
|
149
|
+
tag: 'HTTP-request-header-size',
|
|
150
|
+
val: FieldSizePayload | undefined,
|
|
151
|
+
}
|
|
152
|
+
export interface ErrorCodeHttpRequestTrailerSectionSize {
|
|
153
|
+
tag: 'HTTP-request-trailer-section-size',
|
|
154
|
+
val: number | undefined,
|
|
155
|
+
}
|
|
156
|
+
export interface ErrorCodeHttpRequestTrailerSize {
|
|
157
|
+
tag: 'HTTP-request-trailer-size',
|
|
158
|
+
val: FieldSizePayload,
|
|
159
|
+
}
|
|
160
|
+
export interface ErrorCodeHttpResponseIncomplete {
|
|
161
|
+
tag: 'HTTP-response-incomplete',
|
|
162
|
+
}
|
|
163
|
+
export interface ErrorCodeHttpResponseHeaderSectionSize {
|
|
164
|
+
tag: 'HTTP-response-header-section-size',
|
|
165
|
+
val: number | undefined,
|
|
166
|
+
}
|
|
167
|
+
export interface ErrorCodeHttpResponseHeaderSize {
|
|
168
|
+
tag: 'HTTP-response-header-size',
|
|
169
|
+
val: FieldSizePayload,
|
|
170
|
+
}
|
|
171
|
+
export interface ErrorCodeHttpResponseBodySize {
|
|
172
|
+
tag: 'HTTP-response-body-size',
|
|
173
|
+
val: bigint | undefined,
|
|
174
|
+
}
|
|
175
|
+
export interface ErrorCodeHttpResponseTrailerSectionSize {
|
|
176
|
+
tag: 'HTTP-response-trailer-section-size',
|
|
177
|
+
val: number | undefined,
|
|
178
|
+
}
|
|
179
|
+
export interface ErrorCodeHttpResponseTrailerSize {
|
|
180
|
+
tag: 'HTTP-response-trailer-size',
|
|
181
|
+
val: FieldSizePayload,
|
|
182
|
+
}
|
|
183
|
+
export interface ErrorCodeHttpResponseTransferCoding {
|
|
184
|
+
tag: 'HTTP-response-transfer-coding',
|
|
185
|
+
val: string | undefined,
|
|
186
|
+
}
|
|
187
|
+
export interface ErrorCodeHttpResponseContentCoding {
|
|
188
|
+
tag: 'HTTP-response-content-coding',
|
|
189
|
+
val: string | undefined,
|
|
190
|
+
}
|
|
191
|
+
export interface ErrorCodeHttpResponseTimeout {
|
|
192
|
+
tag: 'HTTP-response-timeout',
|
|
193
|
+
}
|
|
194
|
+
export interface ErrorCodeHttpUpgradeFailed {
|
|
195
|
+
tag: 'HTTP-upgrade-failed',
|
|
196
|
+
}
|
|
197
|
+
export interface ErrorCodeHttpProtocolError {
|
|
198
|
+
tag: 'HTTP-protocol-error',
|
|
199
|
+
}
|
|
200
|
+
export interface ErrorCodeLoopDetected {
|
|
201
|
+
tag: 'loop-detected',
|
|
202
|
+
}
|
|
203
|
+
export interface ErrorCodeConfigurationError {
|
|
204
|
+
tag: 'configuration-error',
|
|
205
|
+
}
|
|
206
|
+
/**
|
|
207
|
+
* This is a catch-all error for anything that doesn't fit cleanly into a
|
|
208
|
+
* more specific case. It also includes an optional string for an
|
|
209
|
+
* unstructured description of the error. Users should not depend on the
|
|
210
|
+
* string for diagnosing errors, as it's not required to be consistent
|
|
211
|
+
* between implementations.
|
|
212
|
+
*/
|
|
213
|
+
export interface ErrorCodeInternalError {
|
|
214
|
+
tag: 'internal-error',
|
|
215
|
+
val: string | undefined,
|
|
216
|
+
}
|
|
217
|
+
/**
|
|
218
|
+
* This type enumerates the different kinds of errors that may occur when
|
|
219
|
+
* setting or appending to a `fields` resource.
|
|
220
|
+
*/
|
|
221
|
+
export type HeaderError = HeaderErrorInvalidSyntax | HeaderErrorForbidden | HeaderErrorImmutable | HeaderErrorSizeExceeded | HeaderErrorOther;
|
|
222
|
+
/**
|
|
223
|
+
* This error indicates that a `field-name` or `field-value` was
|
|
224
|
+
* syntactically invalid when used with an operation that sets headers in a
|
|
225
|
+
* `fields`.
|
|
226
|
+
*/
|
|
227
|
+
export interface HeaderErrorInvalidSyntax {
|
|
228
|
+
tag: 'invalid-syntax',
|
|
229
|
+
}
|
|
230
|
+
/**
|
|
231
|
+
* This error indicates that a forbidden `field-name` was used when trying
|
|
232
|
+
* to set a header in a `fields`.
|
|
233
|
+
*/
|
|
234
|
+
export interface HeaderErrorForbidden {
|
|
235
|
+
tag: 'forbidden',
|
|
236
|
+
}
|
|
237
|
+
/**
|
|
238
|
+
* This error indicates that the operation on the `fields` was not
|
|
239
|
+
* permitted because the fields are immutable.
|
|
240
|
+
*/
|
|
241
|
+
export interface HeaderErrorImmutable {
|
|
242
|
+
tag: 'immutable',
|
|
243
|
+
}
|
|
244
|
+
/**
|
|
245
|
+
* This error indicates that the operation would exceed an
|
|
246
|
+
* implementation-defined limit on field sizes. This may apply to
|
|
247
|
+
* an individual `field-value`, a single `field-name` plus all its
|
|
248
|
+
* values, or the total aggregate size of all fields.
|
|
249
|
+
*/
|
|
250
|
+
export interface HeaderErrorSizeExceeded {
|
|
251
|
+
tag: 'size-exceeded',
|
|
252
|
+
}
|
|
253
|
+
/**
|
|
254
|
+
* This is a catch-all error for anything that doesn't fit cleanly into a
|
|
255
|
+
* more specific case. Implementations can use this to extend the error
|
|
256
|
+
* type without breaking existing code. It also includes an optional
|
|
257
|
+
* string for an unstructured description of the error. Users should not
|
|
258
|
+
* depend on the string for diagnosing errors, as it's not required to be
|
|
259
|
+
* consistent between implementations.
|
|
260
|
+
*/
|
|
261
|
+
export interface HeaderErrorOther {
|
|
262
|
+
tag: 'other',
|
|
263
|
+
val: string | undefined,
|
|
264
|
+
}
|
|
265
|
+
/**
|
|
266
|
+
* This type enumerates the different kinds of errors that may occur when
|
|
267
|
+
* setting fields of a `request-options` resource.
|
|
268
|
+
*/
|
|
269
|
+
export type RequestOptionsError = RequestOptionsErrorNotSupported | RequestOptionsErrorImmutable | RequestOptionsErrorOther;
|
|
270
|
+
/**
|
|
271
|
+
* Indicates the specified field is not supported by this implementation.
|
|
272
|
+
*/
|
|
273
|
+
export interface RequestOptionsErrorNotSupported {
|
|
274
|
+
tag: 'not-supported',
|
|
275
|
+
}
|
|
276
|
+
/**
|
|
277
|
+
* Indicates that the operation on the `request-options` was not permitted
|
|
278
|
+
* because it is immutable.
|
|
279
|
+
*/
|
|
280
|
+
export interface RequestOptionsErrorImmutable {
|
|
281
|
+
tag: 'immutable',
|
|
282
|
+
}
|
|
283
|
+
/**
|
|
284
|
+
* This is a catch-all error for anything that doesn't fit cleanly into a
|
|
285
|
+
* more specific case. Implementations can use this to extend the error
|
|
286
|
+
* type without breaking existing code. It also includes an optional
|
|
287
|
+
* string for an unstructured description of the error. Users should not
|
|
288
|
+
* depend on the string for diagnosing errors, as it's not required to be
|
|
289
|
+
* consistent between implementations.
|
|
290
|
+
*/
|
|
291
|
+
export interface RequestOptionsErrorOther {
|
|
292
|
+
tag: 'other',
|
|
293
|
+
val: string | undefined,
|
|
294
|
+
}
|
|
295
|
+
/**
|
|
296
|
+
* Field names are always strings.
|
|
297
|
+
*
|
|
298
|
+
* Field names should always be treated as case insensitive by the `fields`
|
|
299
|
+
* resource for the purposes of equality checking.
|
|
300
|
+
*/
|
|
301
|
+
export type FieldName = string;
|
|
302
|
+
/**
|
|
303
|
+
* Field values should always be ASCII strings. However, in
|
|
304
|
+
* reality, HTTP implementations often have to interpret malformed values,
|
|
305
|
+
* so they are provided as a list of bytes.
|
|
306
|
+
*/
|
|
307
|
+
export type FieldValue = Uint8Array;
|
|
308
|
+
/**
|
|
309
|
+
* Headers is an alias for Fields.
|
|
310
|
+
*/
|
|
311
|
+
export type Headers = Fields;
|
|
312
|
+
/**
|
|
313
|
+
* Trailers is an alias for Fields.
|
|
314
|
+
*/
|
|
315
|
+
export type Trailers = Fields;
|
|
316
|
+
/**
|
|
317
|
+
* This type corresponds to the HTTP standard Status Code.
|
|
318
|
+
*/
|
|
319
|
+
export type StatusCode = number;
|
|
320
|
+
export type Result<T, E> = { tag: 'ok', val: T } | { tag: 'err', val: E };
|
|
321
|
+
|
|
322
|
+
export class Fields {
|
|
323
|
+
/**
|
|
324
|
+
* Construct an empty HTTP Fields.
|
|
325
|
+
*
|
|
326
|
+
* The resulting `fields` is mutable.
|
|
327
|
+
*/
|
|
328
|
+
constructor()
|
|
329
|
+
/**
|
|
330
|
+
* Construct an HTTP Fields.
|
|
331
|
+
*
|
|
332
|
+
* The resulting `fields` is mutable.
|
|
333
|
+
*
|
|
334
|
+
* The list represents each name-value pair in the Fields. Names
|
|
335
|
+
* which have multiple values are represented by multiple entries in this
|
|
336
|
+
* list with the same name.
|
|
337
|
+
*
|
|
338
|
+
* The tuple is a pair of the field name, represented as a string, and
|
|
339
|
+
* Value, represented as a list of bytes. In a valid Fields, all names
|
|
340
|
+
* and values are valid UTF-8 strings. However, values are not always
|
|
341
|
+
* well-formed, so they are represented as a raw list of bytes.
|
|
342
|
+
*
|
|
343
|
+
* An error result will be returned if any header or value was
|
|
344
|
+
* syntactically invalid, if a header was forbidden, or if the
|
|
345
|
+
* entries would exceed an implementation size limit.
|
|
346
|
+
*/
|
|
347
|
+
static fromList(entries: Array<[FieldName, FieldValue]>): Fields;
|
|
348
|
+
/**
|
|
349
|
+
* Get all of the values corresponding to a name. If the name is not present
|
|
350
|
+
* in this `fields`, an empty list is returned. However, if the name is
|
|
351
|
+
* present but empty, this is represented by a list with one or more
|
|
352
|
+
* empty field-values present.
|
|
353
|
+
*/
|
|
354
|
+
get(name: FieldName): Array<FieldValue>;
|
|
355
|
+
/**
|
|
356
|
+
* Returns `true` when the name is present in this `fields`. If the name is
|
|
357
|
+
* syntactically invalid, `false` is returned.
|
|
358
|
+
*/
|
|
359
|
+
has(name: FieldName): boolean;
|
|
360
|
+
/**
|
|
361
|
+
* Set all of the values for a name. Clears any existing values for that
|
|
362
|
+
* name, if they have been set.
|
|
363
|
+
*
|
|
364
|
+
* Fails with `header-error.immutable` if the `fields` are immutable.
|
|
365
|
+
*
|
|
366
|
+
* Fails with `header-error.size-exceeded` if the name or values would
|
|
367
|
+
* exceed an implementation-defined size limit.
|
|
368
|
+
*/
|
|
369
|
+
set(name: FieldName, value: Array<FieldValue>): void;
|
|
370
|
+
/**
|
|
371
|
+
* Delete all values for a name. Does nothing if no values for the name
|
|
372
|
+
* exist.
|
|
373
|
+
*
|
|
374
|
+
* Fails with `header-error.immutable` if the `fields` are immutable.
|
|
375
|
+
*/
|
|
376
|
+
'delete'(name: FieldName): void;
|
|
377
|
+
/**
|
|
378
|
+
* Delete all values for a name. Does nothing if no values for the name
|
|
379
|
+
* exist.
|
|
380
|
+
*
|
|
381
|
+
* Returns all values previously corresponding to the name, if any.
|
|
382
|
+
*
|
|
383
|
+
* Fails with `header-error.immutable` if the `fields` are immutable.
|
|
384
|
+
*/
|
|
385
|
+
getAndDelete(name: FieldName): Array<FieldValue>;
|
|
386
|
+
/**
|
|
387
|
+
* Append a value for a name. Does not change or delete any existing
|
|
388
|
+
* values for that name.
|
|
389
|
+
*
|
|
390
|
+
* Fails with `header-error.immutable` if the `fields` are immutable.
|
|
391
|
+
*
|
|
392
|
+
* Fails with `header-error.size-exceeded` if the value would exceed
|
|
393
|
+
* an implementation-defined size limit.
|
|
394
|
+
*/
|
|
395
|
+
append(name: FieldName, value: FieldValue): void;
|
|
396
|
+
/**
|
|
397
|
+
* Retrieve the full set of names and values in the Fields. Like the
|
|
398
|
+
* constructor, the list represents each name-value pair.
|
|
399
|
+
*
|
|
400
|
+
* The outer list represents each name-value pair in the Fields. Names
|
|
401
|
+
* which have multiple values are represented by multiple entries in this
|
|
402
|
+
* list with the same name.
|
|
403
|
+
*
|
|
404
|
+
* The names and values are always returned in the original casing and in
|
|
405
|
+
* the order in which they will be serialized for transport.
|
|
406
|
+
*/
|
|
407
|
+
copyAll(): Array<[FieldName, FieldValue]>;
|
|
408
|
+
/**
|
|
409
|
+
* Make a deep copy of the Fields. Equivalent in behavior to calling the
|
|
410
|
+
* `fields` constructor on the return value of `copy-all`. The resulting
|
|
411
|
+
* `fields` is mutable.
|
|
412
|
+
*/
|
|
413
|
+
clone(): Fields;
|
|
414
|
+
}
|
|
415
|
+
|
|
416
|
+
export class Request {
|
|
417
|
+
/**
|
|
418
|
+
* This type does not have a public constructor.
|
|
419
|
+
*/
|
|
420
|
+
private constructor();
|
|
421
|
+
/**
|
|
422
|
+
* Construct a new `request` with a default `method` of `GET`, and
|
|
423
|
+
* `none` values for `path-with-query`, `scheme`, and `authority`.
|
|
424
|
+
*
|
|
425
|
+
* `headers` is the HTTP Headers for the Request.
|
|
426
|
+
*
|
|
427
|
+
* `contents` is the optional body content stream with `none`
|
|
428
|
+
* representing a zero-length content stream.
|
|
429
|
+
* Once it is closed, `trailers` future must resolve to a result.
|
|
430
|
+
* If `trailers` resolves to an error, underlying connection
|
|
431
|
+
* will be closed immediately.
|
|
432
|
+
*
|
|
433
|
+
* `options` is optional `request-options` resource to be used
|
|
434
|
+
* if the request is sent over a network connection.
|
|
435
|
+
*
|
|
436
|
+
* It is possible to construct, or manipulate with the accessor functions
|
|
437
|
+
* below, a `request` with an invalid combination of `scheme`
|
|
438
|
+
* and `authority`, or `headers` which are not permitted to be sent.
|
|
439
|
+
* It is the obligation of the `handler.handle` implementation
|
|
440
|
+
* to reject invalid constructions of `request`.
|
|
441
|
+
*
|
|
442
|
+
* The returned future resolves to result of transmission of this request.
|
|
443
|
+
*/
|
|
444
|
+
static 'new'(headers: Headers, contents: ReadableStream<number> | undefined, trailers: Promise<Result<Trailers | undefined, ErrorCode>>, options: RequestOptions | undefined): [Request, Promise<Result<void, ErrorCode>>];
|
|
445
|
+
/**
|
|
446
|
+
* Get the Method for the Request.
|
|
447
|
+
*/
|
|
448
|
+
getMethod(): Method;
|
|
449
|
+
/**
|
|
450
|
+
* Set the Method for the Request. Fails if the string present in a
|
|
451
|
+
* `method.other` argument is not a syntactically valid method.
|
|
452
|
+
*/
|
|
453
|
+
setMethod(method: Method): void;
|
|
454
|
+
/**
|
|
455
|
+
* Get the combination of the HTTP Path and Query for the Request. When
|
|
456
|
+
* `none`, this represents an empty Path and empty Query.
|
|
457
|
+
*/
|
|
458
|
+
getPathWithQuery(): string | undefined;
|
|
459
|
+
/**
|
|
460
|
+
* Set the combination of the HTTP Path and Query for the Request. When
|
|
461
|
+
* `none`, this represents an empty Path and empty Query. Fails is the
|
|
462
|
+
* string given is not a syntactically valid path and query uri component.
|
|
463
|
+
*/
|
|
464
|
+
setPathWithQuery(pathWithQuery: string | undefined): void;
|
|
465
|
+
/**
|
|
466
|
+
* Get the HTTP Related Scheme for the Request. When `none`, the
|
|
467
|
+
* implementation may choose an appropriate default scheme.
|
|
468
|
+
*/
|
|
469
|
+
getScheme(): Scheme | undefined;
|
|
470
|
+
/**
|
|
471
|
+
* Set the HTTP Related Scheme for the Request. When `none`, the
|
|
472
|
+
* implementation may choose an appropriate default scheme. Fails if the
|
|
473
|
+
* string given is not a syntactically valid uri scheme.
|
|
474
|
+
*/
|
|
475
|
+
setScheme(scheme: Scheme | undefined): void;
|
|
476
|
+
/**
|
|
477
|
+
* Get the authority of the Request's target URI. A value of `none` may be used
|
|
478
|
+
* with Related Schemes which do not require an authority. The HTTP and
|
|
479
|
+
* HTTPS schemes always require an authority.
|
|
480
|
+
*/
|
|
481
|
+
getAuthority(): string | undefined;
|
|
482
|
+
/**
|
|
483
|
+
* Set the authority of the Request's target URI. A value of `none` may be used
|
|
484
|
+
* with Related Schemes which do not require an authority. The HTTP and
|
|
485
|
+
* HTTPS schemes always require an authority. Fails if the string given is
|
|
486
|
+
* not a syntactically valid URI authority.
|
|
487
|
+
*/
|
|
488
|
+
setAuthority(authority: string | undefined): void;
|
|
489
|
+
/**
|
|
490
|
+
* Get the `request-options` to be associated with this request
|
|
491
|
+
*
|
|
492
|
+
* The returned `request-options` resource is immutable: `set-*` operations
|
|
493
|
+
* will fail if invoked.
|
|
494
|
+
*
|
|
495
|
+
* This `request-options` resource is a child: it must be dropped before
|
|
496
|
+
* the parent `request` is dropped, or its ownership is transferred to
|
|
497
|
+
* another component by e.g. `handler.handle`.
|
|
498
|
+
*/
|
|
499
|
+
getOptions(): RequestOptions | undefined;
|
|
500
|
+
/**
|
|
501
|
+
* Get the headers associated with the Request.
|
|
502
|
+
*
|
|
503
|
+
* The returned `headers` resource is immutable: `set`, `append`, and
|
|
504
|
+
* `delete` operations will fail with `header-error.immutable`.
|
|
505
|
+
*/
|
|
506
|
+
getHeaders(): Headers;
|
|
507
|
+
/**
|
|
508
|
+
* Get body of the Request.
|
|
509
|
+
*
|
|
510
|
+
* Stream returned by this method represents the contents of the body.
|
|
511
|
+
* Once the stream is reported as closed, callers should await the returned
|
|
512
|
+
* future to determine whether the body was received successfully.
|
|
513
|
+
* The future will only resolve after the stream is reported as closed.
|
|
514
|
+
*
|
|
515
|
+
* This function takes a `res` future as a parameter, which can be used to
|
|
516
|
+
* communicate an error in handling of the request.
|
|
517
|
+
*
|
|
518
|
+
* Note that function will move the `request`, but references to headers or
|
|
519
|
+
* request options acquired from it previously will remain valid.
|
|
520
|
+
*/
|
|
521
|
+
static consumeBody(this_: Request, res: Promise<Result<void, ErrorCode>>): [ReadableStream<number>, Promise<Result<Trailers | undefined, ErrorCode>>];
|
|
522
|
+
}
|
|
523
|
+
|
|
524
|
+
export class RequestOptions {
|
|
525
|
+
/**
|
|
526
|
+
* Construct a default `request-options` value.
|
|
527
|
+
*/
|
|
528
|
+
constructor()
|
|
529
|
+
/**
|
|
530
|
+
* The timeout for the initial connect to the HTTP Server.
|
|
531
|
+
*/
|
|
532
|
+
getConnectTimeout(): Duration | undefined;
|
|
533
|
+
/**
|
|
534
|
+
* Set the timeout for the initial connect to the HTTP Server. An error
|
|
535
|
+
* return value indicates that this timeout is not supported or that this
|
|
536
|
+
* handle is immutable.
|
|
537
|
+
*/
|
|
538
|
+
setConnectTimeout(duration: Duration | undefined): void;
|
|
539
|
+
/**
|
|
540
|
+
* The timeout for receiving the first byte of the Response body.
|
|
541
|
+
*/
|
|
542
|
+
getFirstByteTimeout(): Duration | undefined;
|
|
543
|
+
/**
|
|
544
|
+
* Set the timeout for receiving the first byte of the Response body. An
|
|
545
|
+
* error return value indicates that this timeout is not supported or that
|
|
546
|
+
* this handle is immutable.
|
|
547
|
+
*/
|
|
548
|
+
setFirstByteTimeout(duration: Duration | undefined): void;
|
|
549
|
+
/**
|
|
550
|
+
* The timeout for receiving subsequent chunks of bytes in the Response
|
|
551
|
+
* body stream.
|
|
552
|
+
*/
|
|
553
|
+
getBetweenBytesTimeout(): Duration | undefined;
|
|
554
|
+
/**
|
|
555
|
+
* Set the timeout for receiving subsequent chunks of bytes in the Response
|
|
556
|
+
* body stream. An error return value indicates that this timeout is not
|
|
557
|
+
* supported or that this handle is immutable.
|
|
558
|
+
*/
|
|
559
|
+
setBetweenBytesTimeout(duration: Duration | undefined): void;
|
|
560
|
+
/**
|
|
561
|
+
* Make a deep copy of the `request-options`.
|
|
562
|
+
* The resulting `request-options` is mutable.
|
|
563
|
+
*/
|
|
564
|
+
clone(): RequestOptions;
|
|
565
|
+
}
|
|
566
|
+
|
|
567
|
+
export class Response {
|
|
568
|
+
/**
|
|
569
|
+
* This type does not have a public constructor.
|
|
570
|
+
*/
|
|
571
|
+
private constructor();
|
|
572
|
+
/**
|
|
573
|
+
* Construct a new `response`, with a default `status-code` of `200`.
|
|
574
|
+
* If a different `status-code` is needed, it must be set via the
|
|
575
|
+
* `set-status-code` method.
|
|
576
|
+
*
|
|
577
|
+
* `headers` is the HTTP Headers for the Response.
|
|
578
|
+
*
|
|
579
|
+
* `contents` is the optional body content stream with `none`
|
|
580
|
+
* representing a zero-length content stream.
|
|
581
|
+
* Once it is closed, `trailers` future must resolve to a result.
|
|
582
|
+
* If `trailers` resolves to an error, underlying connection
|
|
583
|
+
* will be closed immediately.
|
|
584
|
+
*
|
|
585
|
+
* The returned future resolves to result of transmission of this response.
|
|
586
|
+
*/
|
|
587
|
+
static 'new'(headers: Headers, contents: ReadableStream<number> | undefined, trailers: Promise<Result<Trailers | undefined, ErrorCode>>): [Response, Promise<Result<void, ErrorCode>>];
|
|
588
|
+
/**
|
|
589
|
+
* Get the HTTP Status Code for the Response.
|
|
590
|
+
*/
|
|
591
|
+
getStatusCode(): StatusCode;
|
|
592
|
+
/**
|
|
593
|
+
* Set the HTTP Status Code for the Response. Fails if the status-code
|
|
594
|
+
* given is not a valid http status code.
|
|
595
|
+
*/
|
|
596
|
+
setStatusCode(statusCode: StatusCode): void;
|
|
597
|
+
/**
|
|
598
|
+
* Get the headers associated with the Response.
|
|
599
|
+
*
|
|
600
|
+
* The returned `headers` resource is immutable: `set`, `append`, and
|
|
601
|
+
* `delete` operations will fail with `header-error.immutable`.
|
|
602
|
+
*/
|
|
603
|
+
getHeaders(): Headers;
|
|
604
|
+
/**
|
|
605
|
+
* Get body of the Response.
|
|
606
|
+
*
|
|
607
|
+
* Stream returned by this method represents the contents of the body.
|
|
608
|
+
* Once the stream is reported as closed, callers should await the returned
|
|
609
|
+
* future to determine whether the body was received successfully.
|
|
610
|
+
* The future will only resolve after the stream is reported as closed.
|
|
611
|
+
*
|
|
612
|
+
* This function takes a `res` future as a parameter, which can be used to
|
|
613
|
+
* communicate an error in handling of the response.
|
|
614
|
+
*
|
|
615
|
+
* Note that function will move the `response`, but references to headers
|
|
616
|
+
* acquired from it previously will remain valid.
|
|
617
|
+
*/
|
|
618
|
+
static consumeBody(this_: Response, res: Promise<Result<void, ErrorCode>>): [ReadableStream<number>, Promise<Result<Trailers | undefined, ErrorCode>>];
|
|
619
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/** @module Interface wasi:random/insecure-seed@0.3.0-rc-2026-03-15 **/
|
|
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 getInsecureSeed(): [bigint, bigint];
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/** @module Interface wasi:random/insecure@0.3.0-rc-2026-03-15 **/
|
|
2
|
+
/**
|
|
3
|
+
* Return up to `max-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
|
+
* Implementations MAY return fewer bytes than requested (a short read).
|
|
13
|
+
* Callers that require exactly `max-len` bytes MUST call this function in
|
|
14
|
+
* a loop until the desired number of bytes has been accumulated.
|
|
15
|
+
* Implementations MUST return at least 1 byte when `max-len` is greater
|
|
16
|
+
* than zero. When `max-len` is zero, implementations MUST return an empty
|
|
17
|
+
* list without trapping.
|
|
18
|
+
*/
|
|
19
|
+
export function getInsecureRandomBytes(maxLen: bigint): Uint8Array;
|
|
20
|
+
/**
|
|
21
|
+
* Return an insecure pseudo-random `u64` value.
|
|
22
|
+
*
|
|
23
|
+
* This function returns the same type of pseudo-random data as
|
|
24
|
+
* `get-insecure-random-bytes`, represented as a `u64`.
|
|
25
|
+
*/
|
|
26
|
+
export function getInsecureRandomU64(): bigint;
|