@bytecodealliance/preview2-shim 0.16.0 → 0.16.2
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/lib/io/worker-http.js +12 -9
- package/lib/nodejs/clocks.js +2 -2
- package/lib/nodejs/http.js +11 -19
- package/lib/nodejs/random.js +1 -1
- package/package.json +1 -1
- package/types/clocks.d.ts +2 -2
- package/types/interfaces/wasi-cli-stderr.d.ts +1 -1
- package/types/interfaces/wasi-cli-stdin.d.ts +1 -1
- package/types/interfaces/wasi-cli-stdout.d.ts +1 -1
- package/types/interfaces/wasi-cli-terminal-stderr.d.ts +1 -1
- package/types/interfaces/wasi-cli-terminal-stdin.d.ts +1 -1
- package/types/interfaces/wasi-cli-terminal-stdout.d.ts +1 -1
- package/types/interfaces/wasi-clocks-monotonic-clock.d.ts +1 -1
- package/types/interfaces/wasi-filesystem-preopens.d.ts +1 -1
- package/types/interfaces/wasi-filesystem-types.d.ts +249 -249
- package/types/interfaces/wasi-http-incoming-handler.d.ts +2 -2
- package/types/interfaces/wasi-http-outgoing-handler.d.ts +4 -4
- package/types/interfaces/wasi-http-types.d.ts +359 -359
- package/types/interfaces/wasi-io-error.d.ts +9 -9
- package/types/interfaces/wasi-io-poll.d.ts +12 -12
- package/types/interfaces/wasi-io-streams.d.ts +218 -218
- package/types/interfaces/wasi-sockets-instance-network.d.ts +1 -1
- package/types/interfaces/wasi-sockets-ip-name-lookup.d.ts +25 -25
- package/types/interfaces/wasi-sockets-tcp-create-socket.d.ts +4 -4
- package/types/interfaces/wasi-sockets-tcp.d.ts +309 -309
- package/types/interfaces/wasi-sockets-udp-create-socket.d.ts +4 -4
- package/types/interfaces/wasi-sockets-udp.d.ts +276 -276
package/lib/io/worker-http.js
CHANGED
|
@@ -1,7 +1,4 @@
|
|
|
1
|
-
import {
|
|
2
|
-
createReadableStream,
|
|
3
|
-
getStreamOrThrow,
|
|
4
|
-
} from "./worker-thread.js";
|
|
1
|
+
import { createReadableStream, getStreamOrThrow } from "./worker-thread.js";
|
|
5
2
|
import {
|
|
6
3
|
createServer,
|
|
7
4
|
request as httpRequest,
|
|
@@ -117,7 +114,7 @@ export async function createHttpRequest(
|
|
|
117
114
|
host: authority.split(":")[0],
|
|
118
115
|
port: authority.split(":")[1],
|
|
119
116
|
path: pathWithQuery,
|
|
120
|
-
timeout: connectTimeout && Number(connectTimeout),
|
|
117
|
+
timeout: connectTimeout && Number(connectTimeout / 1_000_000n),
|
|
121
118
|
});
|
|
122
119
|
break;
|
|
123
120
|
case "https:":
|
|
@@ -127,7 +124,7 @@ export async function createHttpRequest(
|
|
|
127
124
|
host: authority.split(":")[0],
|
|
128
125
|
port: authority.split(":")[1],
|
|
129
126
|
path: pathWithQuery,
|
|
130
|
-
timeout: connectTimeout && Number(connectTimeout),
|
|
127
|
+
timeout: connectTimeout && Number(connectTimeout / 1_000_000n),
|
|
131
128
|
});
|
|
132
129
|
break;
|
|
133
130
|
default:
|
|
@@ -143,20 +140,26 @@ export async function createHttpRequest(
|
|
|
143
140
|
req.end();
|
|
144
141
|
}
|
|
145
142
|
const res = await new Promise((resolve, reject) => {
|
|
143
|
+
req.once('timeout', () => {
|
|
144
|
+
reject({
|
|
145
|
+
tag: "connection-timeout"
|
|
146
|
+
});
|
|
147
|
+
req.destroy();
|
|
148
|
+
});
|
|
146
149
|
req.once("response", resolve);
|
|
147
150
|
req.once("close", () => reject);
|
|
148
151
|
req.once("error", reject);
|
|
149
152
|
});
|
|
150
|
-
if (firstByteTimeout) res.setTimeout(Number(firstByteTimeout));
|
|
153
|
+
if (firstByteTimeout) res.setTimeout(Number(firstByteTimeout / 1_000_000n));
|
|
151
154
|
if (betweenBytesTimeout)
|
|
152
155
|
res.once("readable", () => {
|
|
153
|
-
res.setTimeout(Number(betweenBytesTimeout));
|
|
156
|
+
res.setTimeout(Number(betweenBytesTimeout / 1_000_000n));
|
|
154
157
|
});
|
|
155
158
|
const bodyStreamId = createReadableStream(res);
|
|
156
159
|
return {
|
|
157
160
|
status: res.statusCode,
|
|
158
161
|
headers: Array.from(Object.entries(res.headers)),
|
|
159
|
-
bodyStreamId
|
|
162
|
+
bodyStreamId,
|
|
160
163
|
};
|
|
161
164
|
} catch (e) {
|
|
162
165
|
if (e?.tag) throw e;
|
package/lib/nodejs/clocks.js
CHANGED
|
@@ -38,7 +38,7 @@ export const wallClock = {
|
|
|
38
38
|
|
|
39
39
|
monotonicClock.resolution[symbolCabiLower] = () => resolution;
|
|
40
40
|
monotonicClock.now[symbolCabiLower] = () => hrtime.bigint;
|
|
41
|
-
wallClock.resolution[symbolCabiLower] = (memory) => {
|
|
41
|
+
wallClock.resolution[symbolCabiLower] = ({ memory }) => {
|
|
42
42
|
let buf32 = new Int32Array(memory.buffer);
|
|
43
43
|
return function now(retptr) {
|
|
44
44
|
if (memory.buffer !== buf32.buffer) buf32 = new Int32Array(memory.buffer);
|
|
@@ -49,7 +49,7 @@ wallClock.resolution[symbolCabiLower] = (memory) => {
|
|
|
49
49
|
};
|
|
50
50
|
};
|
|
51
51
|
|
|
52
|
-
wallClock.now[symbolCabiLower] = (memory) => {
|
|
52
|
+
wallClock.now[symbolCabiLower] = ({ memory }) => {
|
|
53
53
|
let buf32 = new Int32Array(memory.buffer);
|
|
54
54
|
let buf64 = new BigInt64Array(memory.buffer);
|
|
55
55
|
return function now(retptr) {
|
package/lib/nodejs/http.js
CHANGED
|
@@ -175,37 +175,27 @@ class ResponseOutparam {
|
|
|
175
175
|
const responseOutparamCreate = ResponseOutparam._create;
|
|
176
176
|
delete ResponseOutparam._create;
|
|
177
177
|
|
|
178
|
+
const defaultHttpTimeout = 600_000_000_000n;
|
|
179
|
+
|
|
178
180
|
class RequestOptions {
|
|
179
|
-
#connectTimeout;
|
|
180
|
-
#firstByteTimeout;
|
|
181
|
-
#betweenBytesTimeout;
|
|
182
|
-
//The WASI Duration is nanoseconds, js timers are set with Ms.
|
|
183
|
-
//We store the data as nanos, but provide TimeoutMs methods for
|
|
184
|
-
//convenience in setting timers elsewhere
|
|
181
|
+
#connectTimeout = defaultHttpTimeout;
|
|
182
|
+
#firstByteTimeout = defaultHttpTimeout;
|
|
183
|
+
#betweenBytesTimeout = defaultHttpTimeout;
|
|
185
184
|
connectTimeout() {
|
|
186
185
|
return this.#connectTimeout;
|
|
187
186
|
}
|
|
188
|
-
connectTimeoutMs() {
|
|
189
|
-
return this.#connectTimeout / 1_000_000;
|
|
190
|
-
}
|
|
191
187
|
setConnectTimeout(duration) {
|
|
192
188
|
this.#connectTimeout = duration;
|
|
193
189
|
}
|
|
194
190
|
firstByteTimeout() {
|
|
195
191
|
return this.#firstByteTimeout;
|
|
196
192
|
}
|
|
197
|
-
firstByteTimeoutMs() {
|
|
198
|
-
return this.#firstByteTimeout / 1_000_000;
|
|
199
|
-
}
|
|
200
193
|
setFirstByteTimeout(duration) {
|
|
201
194
|
this.#firstByteTimeout = duration;
|
|
202
195
|
}
|
|
203
196
|
betweenBytesTimeout() {
|
|
204
197
|
return this.#betweenBytesTimeout;
|
|
205
198
|
}
|
|
206
|
-
betweenBytesTimeoutMs() {
|
|
207
|
-
return this.#betweenBytesTimeout / 1_000_000;
|
|
208
|
-
}
|
|
209
199
|
setBetweenBytesTimeout(duration) {
|
|
210
200
|
this.#betweenBytesTimeout = duration;
|
|
211
201
|
}
|
|
@@ -284,9 +274,9 @@ class OutgoingRequest {
|
|
|
284
274
|
}
|
|
285
275
|
[symbolDispose]() {}
|
|
286
276
|
static _handle(request, options) {
|
|
287
|
-
const connectTimeout = options?.
|
|
288
|
-
const betweenBytesTimeout = options?.
|
|
289
|
-
const firstByteTimeout = options?.
|
|
277
|
+
const connectTimeout = options?.connectTimeout();
|
|
278
|
+
const betweenBytesTimeout = options?.betweenBytesTimeout();
|
|
279
|
+
const firstByteTimeout = options?.firstByteTimeout();
|
|
290
280
|
const scheme = schemeString(request.#scheme);
|
|
291
281
|
// note: host header is automatically added by Node.js
|
|
292
282
|
const headers = [];
|
|
@@ -294,6 +284,8 @@ class OutgoingRequest {
|
|
|
294
284
|
for (const [key, value] of request.#headers.entries()) {
|
|
295
285
|
headers.push([key, decoder.decode(value)]);
|
|
296
286
|
}
|
|
287
|
+
if (!request.#pathWithQuery)
|
|
288
|
+
throw { tag: 'HTTP-request-URI-invalid' };
|
|
297
289
|
return futureIncomingResponseCreate(
|
|
298
290
|
request.#method.val || request.#method.tag,
|
|
299
291
|
scheme,
|
|
@@ -303,7 +295,7 @@ class OutgoingRequest {
|
|
|
303
295
|
outgoingBodyOutputStreamId(request.#body),
|
|
304
296
|
connectTimeout,
|
|
305
297
|
betweenBytesTimeout,
|
|
306
|
-
firstByteTimeout
|
|
298
|
+
firstByteTimeout,
|
|
307
299
|
);
|
|
308
300
|
}
|
|
309
301
|
}
|
package/lib/nodejs/random.js
CHANGED
|
@@ -31,7 +31,7 @@ function getRandomBytes(len) {
|
|
|
31
31
|
return randomBytes(Number(len));
|
|
32
32
|
}
|
|
33
33
|
|
|
34
|
-
|
|
34
|
+
getRandomBytes[Symbol.for("cabiLower")] = ({ memory, realloc }) => {
|
|
35
35
|
let buf32 = new Uint32Array(memory.buffer);
|
|
36
36
|
return function randomBytes(len, retptr) {
|
|
37
37
|
len = Number(len);
|
package/package.json
CHANGED
package/types/clocks.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { WasiClocksMonotonicClock } from './interfaces/wasi-clocks-monotonic-clock.d.ts';
|
|
2
2
|
import type { WasiClocksWallClock } from './interfaces/wasi-clocks-wall-clock.d.ts';
|
|
3
3
|
|
|
4
|
-
export const wallClock: typeof
|
|
5
|
-
export const monotonicClock: typeof
|
|
4
|
+
export const wallClock: typeof WasiClocksWallClock;
|
|
5
|
+
export const monotonicClock: typeof WasiClocksMonotonicClock;
|
|
@@ -5,5 +5,5 @@ export namespace WasiCliTerminalStderr {
|
|
|
5
5
|
*/
|
|
6
6
|
export function getTerminalStderr(): TerminalOutput | undefined;
|
|
7
7
|
}
|
|
8
|
-
import type { TerminalOutput } from '
|
|
8
|
+
import type { TerminalOutput } from './wasi-cli-terminal-output.js';
|
|
9
9
|
export { TerminalOutput };
|
|
@@ -5,5 +5,5 @@ export namespace WasiCliTerminalStdin {
|
|
|
5
5
|
*/
|
|
6
6
|
export function getTerminalStdin(): TerminalInput | undefined;
|
|
7
7
|
}
|
|
8
|
-
import type { TerminalInput } from '
|
|
8
|
+
import type { TerminalInput } from './wasi-cli-terminal-input.js';
|
|
9
9
|
export { TerminalInput };
|
|
@@ -5,5 +5,5 @@ export namespace WasiCliTerminalStdout {
|
|
|
5
5
|
*/
|
|
6
6
|
export function getTerminalStdout(): TerminalOutput | undefined;
|
|
7
7
|
}
|
|
8
|
-
import type { TerminalOutput } from '
|
|
8
|
+
import type { TerminalOutput } from './wasi-cli-terminal-output.js';
|
|
9
9
|
export { TerminalOutput };
|
|
@@ -23,7 +23,7 @@ export namespace WasiClocksMonotonicClock {
|
|
|
23
23
|
*/
|
|
24
24
|
export function subscribeDuration(when: Duration): Pollable;
|
|
25
25
|
}
|
|
26
|
-
import type { Pollable } from '
|
|
26
|
+
import type { Pollable } from './wasi-io-poll.js';
|
|
27
27
|
export { Pollable };
|
|
28
28
|
/**
|
|
29
29
|
* An instant in time, in nanoseconds. An instant is relative to an
|
|
@@ -4,5 +4,5 @@ export namespace WasiFilesystemPreopens {
|
|
|
4
4
|
*/
|
|
5
5
|
export function getDirectories(): [Descriptor, string][];
|
|
6
6
|
}
|
|
7
|
-
import type { Descriptor } from '
|
|
7
|
+
import type { Descriptor } from './wasi-filesystem-types.js';
|
|
8
8
|
export { Descriptor };
|