@bytecodealliance/preview2-shim 0.0.8 → 0.0.9
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/README.md +1 -0
- package/lib/browser/cli-base.js +57 -0
- package/lib/browser/clocks.js +50 -0
- package/lib/browser/filesystem.js +134 -141
- package/lib/browser/http.js +120 -0
- package/lib/browser/index.js +15 -37
- package/lib/browser/io.js +62 -20
- package/lib/browser/logging.js +16 -0
- package/lib/browser/poll.js +10 -6
- package/lib/browser/random.js +32 -25
- package/lib/browser/sockets.js +203 -0
- package/lib/nodejs/{preopens.js → cli-base.js} +47 -8
- package/lib/nodejs/clocks.js +50 -0
- package/lib/nodejs/filesystem.js +239 -234
- package/lib/nodejs/http.js +120 -0
- package/lib/nodejs/index.js +15 -37
- package/lib/nodejs/io.js +138 -19
- package/lib/nodejs/logging.js +16 -0
- package/lib/nodejs/poll.js +10 -6
- package/lib/nodejs/random.js +18 -13
- package/lib/nodejs/sockets.js +203 -0
- package/package.json +1 -1
- package/types/exports/{HTTP.d.ts → http-incoming-handler.d.ts} +1 -1
- package/types/imports/cli-base-environment.d.ts +17 -0
- package/types/imports/{exit.d.ts → cli-base-exit.d.ts} +4 -1
- package/types/imports/{preopens.d.ts → cli-base-preopens.d.ts} +6 -9
- package/types/imports/cli-base-stderr.d.ts +5 -0
- package/types/imports/cli-base-stdin.d.ts +5 -0
- package/types/imports/cli-base-stdout.d.ts +5 -0
- package/types/imports/clocks-monotonic-clock.d.ts +24 -0
- package/types/imports/clocks-timezone.d.ts +71 -0
- package/types/imports/clocks-wall-clock.d.ts +31 -0
- package/types/imports/filesystem-filesystem.d.ts +857 -0
- package/types/imports/{default-outgoing-HTTP.d.ts → http-outgoing-handler.d.ts} +1 -1
- package/types/imports/{types.d.ts → http-types.d.ts} +28 -28
- package/types/imports/io-streams.d.ts +180 -0
- package/types/imports/logging-handler.d.ts +40 -0
- package/types/imports/poll-poll.d.ts +41 -0
- package/types/imports/random-insecure-seed.d.ts +22 -0
- package/types/imports/random-insecure.d.ts +20 -0
- package/types/imports/random-random.d.ts +22 -0
- package/types/imports/{instance-network.d.ts → sockets-instance-network.d.ts} +4 -1
- package/types/imports/sockets-ip-name-lookup.d.ts +76 -0
- package/types/imports/sockets-network.d.ts +212 -0
- package/types/imports/sockets-tcp-create-socket.d.ts +33 -0
- package/types/imports/sockets-tcp.d.ts +285 -0
- package/types/imports/sockets-udp-create-socket.d.ts +33 -0
- package/types/imports/sockets-udp.d.ts +219 -0
- package/types/wasi-command.d.ts +23 -0
- package/types/wasi-proxy.d.ts +11 -44
- package/types/wasi-reactor.d.ts +23 -70
- package/lib/browser/console.js +0 -12
- package/lib/browser/default-outgoing-HTTP.js +0 -3
- package/lib/browser/environment.js +0 -17
- package/lib/browser/exit.js +0 -21
- package/lib/browser/instance-network.js +0 -3
- package/lib/browser/ip-name-lookup.js +0 -23
- package/lib/browser/monotonic-clock.js +0 -14
- package/lib/browser/network.js +0 -3
- package/lib/browser/preopens.js +0 -11
- package/lib/browser/stderr.js +0 -4
- package/lib/browser/streams.js +0 -60
- package/lib/browser/tcp-create-socket.js +0 -3
- package/lib/browser/tcp.js +0 -75
- package/lib/browser/timezone.js +0 -12
- package/lib/browser/types.js +0 -99
- package/lib/browser/udp-create-socket.js +0 -3
- package/lib/browser/udp.js +0 -75
- package/lib/browser/wall-clock.js +0 -9
- package/lib/nodejs/console.js +0 -12
- package/lib/nodejs/default-outgoing-HTTP.js +0 -3
- package/lib/nodejs/environment.js +0 -19
- package/lib/nodejs/exit.js +0 -3
- package/lib/nodejs/instance-network.js +0 -3
- package/lib/nodejs/ip-name-lookup.js +0 -23
- package/lib/nodejs/monotonic-clock.js +0 -14
- package/lib/nodejs/network.js +0 -3
- package/lib/nodejs/stderr.js +0 -4
- package/lib/nodejs/streams.js +0 -97
- package/lib/nodejs/tcp-create-socket.js +0 -3
- package/lib/nodejs/tcp.js +0 -75
- package/lib/nodejs/timezone.js +0 -12
- package/lib/nodejs/types.js +0 -99
- package/lib/nodejs/udp-create-socket.js +0 -3
- package/lib/nodejs/udp.js +0 -75
- package/lib/nodejs/wall-clock.js +0 -9
- package/types/imports/console.d.ts +0 -17
- package/types/imports/environment.d.ts +0 -4
- package/types/imports/filesystem.d.ts +0 -210
- package/types/imports/ip-name-lookup.d.ts +0 -19
- package/types/imports/monotonic-clock.d.ts +0 -8
- package/types/imports/network.d.ts +0 -50
- package/types/imports/poll.d.ts +0 -5
- package/types/imports/random.d.ts +0 -5
- package/types/imports/streams.d.ts +0 -23
- package/types/imports/tcp-create-socket.d.ts +0 -9
- package/types/imports/tcp.d.ts +0 -52
- package/types/imports/timezone.d.ts +0 -13
- package/types/imports/udp-create-socket.d.ts +0 -9
- package/types/imports/udp.d.ts +0 -36
- package/types/imports/wall-clock.d.ts +0 -8
- package/types/index.d.ts +0 -8
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export namespace
|
|
1
|
+
export namespace HttpTypes {
|
|
2
2
|
export function dropFields(fields: Fields): void;
|
|
3
3
|
export function newFields(entries: [string, string][]): Fields;
|
|
4
4
|
export function fieldsGet(fields: Fields, name: string): string[];
|
|
@@ -33,15 +33,32 @@ export namespace Types {
|
|
|
33
33
|
export function futureIncomingResponseGet(f: FutureIncomingResponse): Result<IncomingResponse, Error> | null;
|
|
34
34
|
export function listenToFutureIncomingResponse(f: FutureIncomingResponse): Pollable;
|
|
35
35
|
}
|
|
36
|
-
export type Fields = number;
|
|
37
36
|
import type { InputStream } from '../imports/streams';
|
|
38
37
|
export { InputStream };
|
|
39
|
-
export type IncomingStream = InputStream;
|
|
40
|
-
export type Trailers = Fields;
|
|
41
38
|
import type { OutputStream } from '../imports/streams';
|
|
42
39
|
export { OutputStream };
|
|
40
|
+
import type { Pollable } from '../imports/poll';
|
|
41
|
+
export { Pollable };
|
|
42
|
+
export type StatusCode = number;
|
|
43
|
+
export type Scheme = SchemeHttp | SchemeHttps | SchemeOther;
|
|
44
|
+
export interface SchemeHttp {
|
|
45
|
+
tag: 'HTTP',
|
|
46
|
+
}
|
|
47
|
+
export interface SchemeHttps {
|
|
48
|
+
tag: 'HTTPS',
|
|
49
|
+
}
|
|
50
|
+
export interface SchemeOther {
|
|
51
|
+
tag: 'other',
|
|
52
|
+
val: string,
|
|
53
|
+
}
|
|
54
|
+
export type ResponseOutparam = number;
|
|
55
|
+
export interface RequestOptions {
|
|
56
|
+
connectTimeoutMs?: number,
|
|
57
|
+
firstByteTimeoutMs?: number,
|
|
58
|
+
betweenBytesTimeoutMs?: number,
|
|
59
|
+
}
|
|
43
60
|
export type OutgoingStream = OutputStream;
|
|
44
|
-
export type
|
|
61
|
+
export type OutgoingResponse = number;
|
|
45
62
|
export type OutgoingRequest = number;
|
|
46
63
|
export type Method = MethodGet | MethodHead | MethodPost | MethodPut | MethodDelete | MethodConnect | MethodOptions | MethodTrace | MethodPatch | MethodOther;
|
|
47
64
|
export interface MethodGet {
|
|
@@ -75,20 +92,13 @@ export interface MethodOther {
|
|
|
75
92
|
tag: 'other',
|
|
76
93
|
val: string,
|
|
77
94
|
}
|
|
78
|
-
export type
|
|
79
|
-
export
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
export
|
|
83
|
-
|
|
84
|
-
}
|
|
85
|
-
export interface SchemeOther {
|
|
86
|
-
tag: 'other',
|
|
87
|
-
val: string,
|
|
88
|
-
}
|
|
95
|
+
export type IncomingStream = InputStream;
|
|
96
|
+
export type IncomingResponse = number;
|
|
97
|
+
export type IncomingRequest = number;
|
|
98
|
+
export type FutureIncomingResponse = number;
|
|
99
|
+
export type Fields = number;
|
|
100
|
+
export type Trailers = Fields;
|
|
89
101
|
export type Headers = Fields;
|
|
90
|
-
export type ResponseOutparam = number;
|
|
91
|
-
export type OutgoingResponse = number;
|
|
92
102
|
export type Error = ErrorInvalidUrl | ErrorTimeoutError | ErrorProtocolError | ErrorUnexpectedError;
|
|
93
103
|
export interface ErrorInvalidUrl {
|
|
94
104
|
tag: 'invalid-url',
|
|
@@ -106,14 +116,4 @@ export interface ErrorUnexpectedError {
|
|
|
106
116
|
tag: 'unexpected-error',
|
|
107
117
|
val: string,
|
|
108
118
|
}
|
|
109
|
-
export type IncomingResponse = number;
|
|
110
|
-
export type StatusCode = number;
|
|
111
|
-
export type FutureIncomingResponse = number;
|
|
112
|
-
import type { Pollable } from '../imports/poll';
|
|
113
|
-
export { Pollable };
|
|
114
|
-
export interface RequestOptions {
|
|
115
|
-
connectTimeoutMs?: number,
|
|
116
|
-
firstByteTimeoutMs?: number,
|
|
117
|
-
betweenBytesTimeoutMs?: number,
|
|
118
|
-
}
|
|
119
119
|
export type Result<T, E> = { tag: 'ok', val: T } | { tag: 'err', val: E };
|
|
@@ -0,0 +1,180 @@
|
|
|
1
|
+
export namespace IoStreams {
|
|
2
|
+
/**
|
|
3
|
+
* Read bytes from a stream.
|
|
4
|
+
*
|
|
5
|
+
* This function returns a list of bytes containing the data that was
|
|
6
|
+
* read, along with a bool which, when true, indicates that the end of the
|
|
7
|
+
* stream was reached. The returned list will contain up to `len` bytes; it
|
|
8
|
+
* may return fewer than requested, but not more.
|
|
9
|
+
*
|
|
10
|
+
* Once a stream has reached the end, subsequent calls to read or
|
|
11
|
+
* `skip` will always report end-of-stream rather than producing more
|
|
12
|
+
* data.
|
|
13
|
+
*
|
|
14
|
+
* If `len` is 0, it represents a request to read 0 bytes, which should
|
|
15
|
+
* always succeed, assuming the stream hasn't reached its end yet, and
|
|
16
|
+
* return an empty list.
|
|
17
|
+
*
|
|
18
|
+
* The len here is a `u64`, but some callees may not be able to allocate
|
|
19
|
+
* a buffer as large as that would imply.
|
|
20
|
+
* FIXME: describe what happens if allocation fails.
|
|
21
|
+
*/
|
|
22
|
+
export function read(this: InputStream, len: bigint): [Uint8Array | ArrayBuffer, boolean];
|
|
23
|
+
/**
|
|
24
|
+
* Read bytes from a stream, with blocking.
|
|
25
|
+
*
|
|
26
|
+
* This is similar to `read`, except that it blocks until at least one
|
|
27
|
+
* byte can be read.
|
|
28
|
+
*/
|
|
29
|
+
export function blockingRead(this: InputStream, len: bigint): [Uint8Array | ArrayBuffer, boolean];
|
|
30
|
+
/**
|
|
31
|
+
* Skip bytes from a stream.
|
|
32
|
+
*
|
|
33
|
+
* This is similar to the `read` function, but avoids copying the
|
|
34
|
+
* bytes into the instance.
|
|
35
|
+
*
|
|
36
|
+
* Once a stream has reached the end, subsequent calls to read or
|
|
37
|
+
* `skip` will always report end-of-stream rather than producing more
|
|
38
|
+
* data.
|
|
39
|
+
*
|
|
40
|
+
* This function returns the number of bytes skipped, along with a bool
|
|
41
|
+
* indicating whether the end of the stream was reached. The returned
|
|
42
|
+
* value will be at most `len`; it may be less.
|
|
43
|
+
*/
|
|
44
|
+
export function skip(this: InputStream, len: bigint): [bigint, boolean];
|
|
45
|
+
/**
|
|
46
|
+
* Skip bytes from a stream, with blocking.
|
|
47
|
+
*
|
|
48
|
+
* This is similar to `skip`, except that it blocks until at least one
|
|
49
|
+
* byte can be consumed.
|
|
50
|
+
*/
|
|
51
|
+
export function blockingSkip(this: InputStream, len: bigint): [bigint, boolean];
|
|
52
|
+
/**
|
|
53
|
+
* Create a `pollable` which will resolve once either the specified stream
|
|
54
|
+
* has bytes available to read or the other end of the stream has been
|
|
55
|
+
* closed.
|
|
56
|
+
*/
|
|
57
|
+
export function subscribeToInputStream(this: InputStream): Pollable;
|
|
58
|
+
/**
|
|
59
|
+
* Dispose of the specified `input-stream`, after which it may no longer
|
|
60
|
+
* be used.
|
|
61
|
+
*/
|
|
62
|
+
export function dropInputStream(this: InputStream): void;
|
|
63
|
+
/**
|
|
64
|
+
* Write bytes to a stream.
|
|
65
|
+
*
|
|
66
|
+
* This function returns a `u64` indicating the number of bytes from
|
|
67
|
+
* `buf` that were written; it may be less than the full list.
|
|
68
|
+
*/
|
|
69
|
+
export function write(this: OutputStream, buf: Uint8Array): bigint;
|
|
70
|
+
/**
|
|
71
|
+
* Write bytes to a stream, with blocking.
|
|
72
|
+
*
|
|
73
|
+
* This is similar to `write`, except that it blocks until at least one
|
|
74
|
+
* byte can be written.
|
|
75
|
+
*/
|
|
76
|
+
export function blockingWrite(this: OutputStream, buf: Uint8Array): bigint;
|
|
77
|
+
/**
|
|
78
|
+
* Write multiple zero bytes to a stream.
|
|
79
|
+
*
|
|
80
|
+
* This function returns a `u64` indicating the number of zero bytes
|
|
81
|
+
* that were written; it may be less than `len`.
|
|
82
|
+
*/
|
|
83
|
+
export function writeZeroes(this: OutputStream, len: bigint): bigint;
|
|
84
|
+
/**
|
|
85
|
+
* Write multiple zero bytes to a stream, with blocking.
|
|
86
|
+
*
|
|
87
|
+
* This is similar to `write-zeroes`, except that it blocks until at least
|
|
88
|
+
* one byte can be written.
|
|
89
|
+
*/
|
|
90
|
+
export function blockingWriteZeroes(this: OutputStream, len: bigint): bigint;
|
|
91
|
+
/**
|
|
92
|
+
* Read from one stream and write to another.
|
|
93
|
+
*
|
|
94
|
+
* This function returns the number of bytes transferred; it may be less
|
|
95
|
+
* than `len`.
|
|
96
|
+
*
|
|
97
|
+
* Unlike other I/O functions, this function blocks until all the data
|
|
98
|
+
* read from the input stream has been written to the output stream.
|
|
99
|
+
*/
|
|
100
|
+
export function splice(this: OutputStream, src: InputStream, len: bigint): [bigint, boolean];
|
|
101
|
+
/**
|
|
102
|
+
* Read from one stream and write to another, with blocking.
|
|
103
|
+
*
|
|
104
|
+
* This is similar to `splice`, except that it blocks until at least
|
|
105
|
+
* one byte can be read.
|
|
106
|
+
*/
|
|
107
|
+
export function blockingSplice(this: OutputStream, src: InputStream, len: bigint): [bigint, boolean];
|
|
108
|
+
/**
|
|
109
|
+
* Forward the entire contents of an input stream to an output stream.
|
|
110
|
+
*
|
|
111
|
+
* This function repeatedly reads from the input stream and writes
|
|
112
|
+
* the data to the output stream, until the end of the input stream
|
|
113
|
+
* is reached, or an error is encountered.
|
|
114
|
+
*
|
|
115
|
+
* Unlike other I/O functions, this function blocks until the end
|
|
116
|
+
* of the input stream is seen and all the data has been written to
|
|
117
|
+
* the output stream.
|
|
118
|
+
*
|
|
119
|
+
* This function returns the number of bytes transferred.
|
|
120
|
+
*/
|
|
121
|
+
export function forward(this: OutputStream, src: InputStream): bigint;
|
|
122
|
+
/**
|
|
123
|
+
* Create a `pollable` which will resolve once either the specified stream
|
|
124
|
+
* is ready to accept bytes or the other end of the stream has been closed.
|
|
125
|
+
*/
|
|
126
|
+
export function subscribeToOutputStream(this: OutputStream): Pollable;
|
|
127
|
+
/**
|
|
128
|
+
* Dispose of the specified `output-stream`, after which it may no longer
|
|
129
|
+
* be used.
|
|
130
|
+
*/
|
|
131
|
+
export function dropOutputStream(this: OutputStream): void;
|
|
132
|
+
}
|
|
133
|
+
import type { Pollable } from '../imports/poll';
|
|
134
|
+
export { Pollable };
|
|
135
|
+
/**
|
|
136
|
+
* An error type returned from a stream operation. Currently this
|
|
137
|
+
* doesn't provide any additional information.
|
|
138
|
+
*/
|
|
139
|
+
export interface StreamError {
|
|
140
|
+
}
|
|
141
|
+
/**
|
|
142
|
+
* An output bytestream. In the future, this will be replaced by handle
|
|
143
|
+
* types.
|
|
144
|
+
*
|
|
145
|
+
* This conceptually represents a `stream<u8, _>`. It's temporary
|
|
146
|
+
* scaffolding until component-model's async features are ready.
|
|
147
|
+
*
|
|
148
|
+
* `output-stream`s are *non-blocking* to the extent practical on
|
|
149
|
+
* underlying platforms. Except where specified otherwise, I/O operations also
|
|
150
|
+
* always return promptly, after the number of bytes that can be written
|
|
151
|
+
* promptly, which could even be zero. To wait for the stream to be ready to
|
|
152
|
+
* accept data, the `subscribe-to-output-stream` function to obtain a
|
|
153
|
+
* `pollable` which can be polled for using `wasi_poll`.
|
|
154
|
+
*
|
|
155
|
+
* And at present, it is a `u32` instead of being an actual handle, until
|
|
156
|
+
* the wit-bindgen implementation of handles and resources is ready.
|
|
157
|
+
*
|
|
158
|
+
* This [represents a resource](https://github.com/WebAssembly/WASI/blob/main/docs/WitInWasi.md#Resources).
|
|
159
|
+
*/
|
|
160
|
+
export type OutputStream = number;
|
|
161
|
+
/**
|
|
162
|
+
* An input bytestream. In the future, this will be replaced by handle
|
|
163
|
+
* types.
|
|
164
|
+
*
|
|
165
|
+
* This conceptually represents a `stream<u8, _>`. It's temporary
|
|
166
|
+
* scaffolding until component-model's async features are ready.
|
|
167
|
+
*
|
|
168
|
+
* `input-stream`s are *non-blocking* to the extent practical on underlying
|
|
169
|
+
* platforms. I/O operations always return promptly; if fewer bytes are
|
|
170
|
+
* promptly available than requested, they return the number of bytes promptly
|
|
171
|
+
* available, which could even be zero. To wait for data to be available,
|
|
172
|
+
* use the `subscribe-to-input-stream` function to obtain a `pollable` which
|
|
173
|
+
* can be polled for using `wasi_poll`.
|
|
174
|
+
*
|
|
175
|
+
* And at present, it is a `u32` instead of being an actual handle, until
|
|
176
|
+
* the wit-bindgen implementation of handles and resources is ready.
|
|
177
|
+
*
|
|
178
|
+
* This [represents a resource](https://github.com/WebAssembly/WASI/blob/main/docs/WitInWasi.md#Resources).
|
|
179
|
+
*/
|
|
180
|
+
export type InputStream = number;
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
export namespace LoggingHandler {
|
|
2
|
+
/**
|
|
3
|
+
* Emit a log message.
|
|
4
|
+
*
|
|
5
|
+
* A log message has a `level` describing what kind of message is being
|
|
6
|
+
* sent, a context, which is an uninterpreted string meant to help
|
|
7
|
+
* consumers group similar messages, and a string containing the message
|
|
8
|
+
* text.
|
|
9
|
+
*/
|
|
10
|
+
export function log(level: Level, context: string, message: string): void;
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* A log level, describing a kind of message.
|
|
14
|
+
*
|
|
15
|
+
* # Variants
|
|
16
|
+
*
|
|
17
|
+
* ## `"trace"`
|
|
18
|
+
*
|
|
19
|
+
* Describes messages about the values of variables and the flow of
|
|
20
|
+
* control within a program.
|
|
21
|
+
*
|
|
22
|
+
* ## `"debug"`
|
|
23
|
+
*
|
|
24
|
+
* Describes messages likely to be of interest to someone debugging a
|
|
25
|
+
* program.
|
|
26
|
+
*
|
|
27
|
+
* ## `"info"`
|
|
28
|
+
*
|
|
29
|
+
* Describes messages likely to be of interest to someone monitoring a
|
|
30
|
+
* program.
|
|
31
|
+
*
|
|
32
|
+
* ## `"warn"`
|
|
33
|
+
*
|
|
34
|
+
* Describes messages indicating hazardous situations.
|
|
35
|
+
*
|
|
36
|
+
* ## `"error"`
|
|
37
|
+
*
|
|
38
|
+
* Describes messages indicating serious errors.
|
|
39
|
+
*/
|
|
40
|
+
export type Level = 'trace' | 'debug' | 'info' | 'warn' | 'error';
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
export namespace PollPoll {
|
|
2
|
+
/**
|
|
3
|
+
* Dispose of the specified `pollable`, after which it may no longer
|
|
4
|
+
* be used.
|
|
5
|
+
*/
|
|
6
|
+
export function dropPollable(this: Pollable): void;
|
|
7
|
+
/**
|
|
8
|
+
* Poll for completion on a set of pollables.
|
|
9
|
+
*
|
|
10
|
+
* The "oneoff" in the name refers to the fact that this function must do a
|
|
11
|
+
* linear scan through the entire list of subscriptions, which may be
|
|
12
|
+
* inefficient if the number is large and the same subscriptions are used
|
|
13
|
+
* many times. In the future, this is expected to be obsoleted by the
|
|
14
|
+
* component model async proposal, which will include a scalable waiting
|
|
15
|
+
* facility.
|
|
16
|
+
*
|
|
17
|
+
* Note that the return type would ideally be `list<bool>`, but that would
|
|
18
|
+
* be more difficult to polyfill given the current state of `wit-bindgen`.
|
|
19
|
+
* See <https://github.com/bytecodealliance/preview2-prototyping/pull/11#issuecomment-1329873061>
|
|
20
|
+
* for details. For now, we use zero to mean "not ready" and non-zero to
|
|
21
|
+
* mean "ready".
|
|
22
|
+
*/
|
|
23
|
+
export function pollOneoff(in: Uint32Array): Uint8Array | ArrayBuffer;
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* A "pollable" handle.
|
|
27
|
+
*
|
|
28
|
+
* This is conceptually represents a `stream<_, _>`, or in other words,
|
|
29
|
+
* a stream that one can wait on, repeatedly, but which does not itself
|
|
30
|
+
* produce any data. It's temporary scaffolding until component-model's
|
|
31
|
+
* async features are ready.
|
|
32
|
+
*
|
|
33
|
+
* And at present, it is a `u32` instead of being an actual handle, until
|
|
34
|
+
* the wit-bindgen implementation of handles and resources is ready.
|
|
35
|
+
*
|
|
36
|
+
* `pollable` lifetimes are not automatically managed. Users must ensure
|
|
37
|
+
* that they do not outlive the resource they reference.
|
|
38
|
+
*
|
|
39
|
+
* This [represents a resource](https://github.com/WebAssembly/WASI/blob/main/docs/WitInWasi.md#Resources).
|
|
40
|
+
*/
|
|
41
|
+
export type Pollable = number;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
export namespace RandomInsecureSeed {
|
|
2
|
+
/**
|
|
3
|
+
* Return a 128-bit value that may contain a pseudo-random value.
|
|
4
|
+
*
|
|
5
|
+
* The returned value is not required to be computed from a CSPRNG, and may
|
|
6
|
+
* even be entirely deterministic. Host implementations are encouraged to
|
|
7
|
+
* provide pseudo-random values to any program exposed to
|
|
8
|
+
* attacker-controlled content, to enable DoS protection built into many
|
|
9
|
+
* languages' hash-map implementations.
|
|
10
|
+
*
|
|
11
|
+
* This function is intended to only be called once, by a source language
|
|
12
|
+
* to initialize Denial Of Service (DoS) protection in its hash-map
|
|
13
|
+
* implementation.
|
|
14
|
+
*
|
|
15
|
+
* # Expected future evolution
|
|
16
|
+
*
|
|
17
|
+
* This will likely be changed to a value import, to prevent it from being
|
|
18
|
+
* called multiple times and potentially used for purposes other than DoS
|
|
19
|
+
* protection.
|
|
20
|
+
*/
|
|
21
|
+
export function insecureSeed(): [bigint, bigint];
|
|
22
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
export namespace RandomInsecure {
|
|
2
|
+
/**
|
|
3
|
+
* Return `len` insecure pseudo-random bytes.
|
|
4
|
+
*
|
|
5
|
+
* This function is not cryptographically secure. Do not use it for
|
|
6
|
+
* anything related to security.
|
|
7
|
+
*
|
|
8
|
+
* There are no requirements on the values of the returned bytes, however
|
|
9
|
+
* implementations are encouraged to return evenly distributed values with
|
|
10
|
+
* a long period.
|
|
11
|
+
*/
|
|
12
|
+
export function getInsecureRandomBytes(len: bigint): Uint8Array | ArrayBuffer;
|
|
13
|
+
/**
|
|
14
|
+
* Return an insecure pseudo-random `u64` value.
|
|
15
|
+
*
|
|
16
|
+
* This function returns the same type of pseudo-random data as
|
|
17
|
+
* `get-insecure-random-bytes`, represented as a `u64`.
|
|
18
|
+
*/
|
|
19
|
+
export function getInsecureRandomU64(): bigint;
|
|
20
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
export namespace RandomRandom {
|
|
2
|
+
/**
|
|
3
|
+
* Return `len` cryptographically-secure pseudo-random bytes.
|
|
4
|
+
*
|
|
5
|
+
* This function must produce data from an adequately seeded
|
|
6
|
+
* cryptographically-secure pseudo-random number generator (CSPRNG), so it
|
|
7
|
+
* must not block, from the perspective of the calling program, and the
|
|
8
|
+
* returned data is always unpredictable.
|
|
9
|
+
*
|
|
10
|
+
* This function must always return fresh pseudo-random data. Deterministic
|
|
11
|
+
* environments must omit this function, rather than implementing it with
|
|
12
|
+
* deterministic data.
|
|
13
|
+
*/
|
|
14
|
+
export function getRandomBytes(len: bigint): Uint8Array | ArrayBuffer;
|
|
15
|
+
/**
|
|
16
|
+
* Return a cryptographically-secure pseudo-random `u64` value.
|
|
17
|
+
*
|
|
18
|
+
* This function returns the same type of pseudo-random data as
|
|
19
|
+
* `get-random-bytes`, represented as a `u64`.
|
|
20
|
+
*/
|
|
21
|
+
export function getRandomU64(): bigint;
|
|
22
|
+
}
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
export namespace SocketsIpNameLookup {
|
|
2
|
+
/**
|
|
3
|
+
* Resolve an internet host name to a list of IP addresses.
|
|
4
|
+
*
|
|
5
|
+
* See the wasi-socket proposal README.md for a comparison with getaddrinfo.
|
|
6
|
+
*
|
|
7
|
+
* # Parameters
|
|
8
|
+
* - `name`: The name to look up. IP addresses are not allowed. Unicode domain names are automatically converted
|
|
9
|
+
* to ASCII using IDNA encoding.
|
|
10
|
+
* - `address-family`: If provided, limit the results to addresses of this specific address family.
|
|
11
|
+
* - `include-unavailable`: When set to true, this function will also return addresses of which the runtime
|
|
12
|
+
* thinks (or knows) can't be connected to at the moment. For example, this will return IPv6 addresses on
|
|
13
|
+
* systems without an active IPv6 interface. Notes:
|
|
14
|
+
* - Even when no public IPv6 interfaces are present or active, names like "localhost" can still resolve to an IPv6 address.
|
|
15
|
+
* - Whatever is "available" or "unavailable" is volatile and can change everytime a network cable is unplugged.
|
|
16
|
+
*
|
|
17
|
+
* This function never blocks. It either immediately fails or immediately returns successfully with a `resolve-address-stream`
|
|
18
|
+
* that can be used to (asynchronously) fetch the results.
|
|
19
|
+
*
|
|
20
|
+
* At the moment, the stream never completes successfully with 0 items. Ie. the first call
|
|
21
|
+
* to `resolve-next-address` never returns `ok(none)`. This may change in the future.
|
|
22
|
+
*
|
|
23
|
+
* # Typical errors
|
|
24
|
+
* - `invalid-name`: `name` is a syntactically invalid domain name.
|
|
25
|
+
* - `invalid-name`: `name` is an IP address.
|
|
26
|
+
* - `address-family-not-supported`: The specified `address-family` is not supported. (EAI_FAMILY)
|
|
27
|
+
*
|
|
28
|
+
* # References:
|
|
29
|
+
* - <https://pubs.opengroup.org/onlinepubs/9699919799/functions/getaddrinfo.html>
|
|
30
|
+
* - <https://man7.org/linux/man-pages/man3/getaddrinfo.3.html>
|
|
31
|
+
* - <https://learn.microsoft.com/en-us/windows/win32/api/ws2tcpip/nf-ws2tcpip-getaddrinfo>
|
|
32
|
+
* - <https://man.freebsd.org/cgi/man.cgi?query=getaddrinfo&sektion=3>
|
|
33
|
+
*/
|
|
34
|
+
export function resolveAddresses(network: Network, name: string, addressFamily: IpAddressFamily | null, includeUnavailable: boolean): ResolveAddressStream;
|
|
35
|
+
/**
|
|
36
|
+
* Returns the next address from the resolver.
|
|
37
|
+
*
|
|
38
|
+
* This function should be called multiple times. On each call, it will
|
|
39
|
+
* return the next address in connection order preference. If all
|
|
40
|
+
* addresses have been exhausted, this function returns `none`.
|
|
41
|
+
* After which, you should release the stream with `drop-resolve-address-stream`.
|
|
42
|
+
*
|
|
43
|
+
* This function never returns IPv4-mapped IPv6 addresses.
|
|
44
|
+
*
|
|
45
|
+
* # Typical errors
|
|
46
|
+
* - `name-unresolvable`: Name does not exist or has no suitable associated IP addresses. (EAI_NONAME, EAI_NODATA, EAI_ADDRFAMILY)
|
|
47
|
+
* - `temporary-resolver-failure`: A temporary failure in name resolution occurred. (EAI_AGAIN)
|
|
48
|
+
* - `permanent-resolver-failure`: A permanent failure in name resolution occurred. (EAI_FAIL)
|
|
49
|
+
* - `would-block`: A result is not available yet. (EWOULDBLOCK, EAGAIN)
|
|
50
|
+
*/
|
|
51
|
+
export function resolveNextAddress(this: ResolveAddressStream): IpAddress | null;
|
|
52
|
+
/**
|
|
53
|
+
* Dispose of the specified `resolve-address-stream`, after which it may no longer be used.
|
|
54
|
+
*
|
|
55
|
+
* Note: this function is scheduled to be removed when Resources are natively supported in Wit.
|
|
56
|
+
*/
|
|
57
|
+
export function dropResolveAddressStream(this: ResolveAddressStream): void;
|
|
58
|
+
/**
|
|
59
|
+
* Create a `pollable` which will resolve once the stream is ready for I/O.
|
|
60
|
+
*
|
|
61
|
+
* Note: this function is here for WASI Preview2 only.
|
|
62
|
+
* It's planned to be removed when `future` is natively supported in Preview3.
|
|
63
|
+
*/
|
|
64
|
+
export function subscribe(this: ResolveAddressStream): Pollable;
|
|
65
|
+
}
|
|
66
|
+
import type { Pollable } from '../imports/poll';
|
|
67
|
+
export { Pollable };
|
|
68
|
+
import type { Network } from '../imports/network';
|
|
69
|
+
export { Network };
|
|
70
|
+
import type { ErrorCode } from '../imports/network';
|
|
71
|
+
export { ErrorCode };
|
|
72
|
+
import type { IpAddress } from '../imports/network';
|
|
73
|
+
export { IpAddress };
|
|
74
|
+
import type { IpAddressFamily } from '../imports/network';
|
|
75
|
+
export { IpAddressFamily };
|
|
76
|
+
export type ResolveAddressStream = number;
|