@bytecodealliance/preview2-shim 0.17.0 → 0.17.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.
- package/lib/browser/cli.js +7 -4
- package/lib/io/worker-socket-tcp.js +2 -2
- package/lib/io/worker-thread.js +3 -2
- package/lib/nodejs/cli.js +3 -0
- package/lib/nodejs/filesystem.js +5 -7
- package/package.json +1 -1
- package/types/interfaces/wasi-filesystem-types.d.ts +0 -6
- package/types/interfaces/wasi-http-types.d.ts +45 -28
- package/types/interfaces/wasi-io-streams.d.ts +3 -0
- package/types/interfaces/wasi-sockets-ip-name-lookup.d.ts +1 -1
- package/types/interfaces/wasi-sockets-tcp.d.ts +1 -1
- package/types/interfaces/wasi-sockets-udp.d.ts +3 -3
package/lib/browser/cli.js
CHANGED
|
@@ -29,16 +29,19 @@ export const environment = {
|
|
|
29
29
|
};
|
|
30
30
|
|
|
31
31
|
class ComponentExit extends Error {
|
|
32
|
-
constructor(
|
|
33
|
-
super(`Component exited ${
|
|
32
|
+
constructor(code) {
|
|
33
|
+
super(`Component exited ${code === 0 ? 'successfully' : 'with error'}`);
|
|
34
34
|
this.exitError = true;
|
|
35
|
-
this.
|
|
35
|
+
this.code = code;
|
|
36
36
|
}
|
|
37
37
|
}
|
|
38
38
|
|
|
39
39
|
export const exit = {
|
|
40
40
|
exit (status) {
|
|
41
|
-
throw new ComponentExit(status.tag === 'err' ?
|
|
41
|
+
throw new ComponentExit(status.tag === 'err' ? 1 : 0);
|
|
42
|
+
},
|
|
43
|
+
exitWithCode (code) {
|
|
44
|
+
throw new ComponentExit(code);
|
|
42
45
|
}
|
|
43
46
|
};
|
|
44
47
|
|
|
@@ -31,7 +31,7 @@ import {
|
|
|
31
31
|
} from "./worker-sockets.js";
|
|
32
32
|
import { Socket, Server } from "node:net";
|
|
33
33
|
|
|
34
|
-
const
|
|
34
|
+
const win = process.platform === 'win32';
|
|
35
35
|
|
|
36
36
|
/**
|
|
37
37
|
* @typedef {import("../../types/interfaces/wasi-sockets-network.js").IpSocketAddress} IpSocketAddress
|
|
@@ -268,7 +268,7 @@ export function socketTcpGetRemoteAddress(id) {
|
|
|
268
268
|
export function socketTcpShutdown(id, _shutdownType) {
|
|
269
269
|
const socket = tcpSockets.get(id);
|
|
270
270
|
if (socket.state !== SOCKET_STATE_CONNECTION) throw "invalid-state";
|
|
271
|
-
if (
|
|
271
|
+
if (win && socket.tcpSocket.destroySoon)
|
|
272
272
|
socket.tcpSocket.destroySoon();
|
|
273
273
|
else
|
|
274
274
|
socket.tcpSocket.destroy();
|
package/lib/io/worker-thread.js
CHANGED
|
@@ -393,8 +393,9 @@ function handle(call, id, payload) {
|
|
|
393
393
|
return;
|
|
394
394
|
}
|
|
395
395
|
case HTTP_OUTGOING_BODY_DISPOSE:
|
|
396
|
-
if (!streams.
|
|
397
|
-
|
|
396
|
+
if (debug && !streams.has(id))
|
|
397
|
+
console.warn(`wasi-io: stream ${id} not found to dispose`);
|
|
398
|
+
streams.delete(id);
|
|
398
399
|
return;
|
|
399
400
|
case HTTP_SERVER_START:
|
|
400
401
|
return startHttpServer(id, payload);
|
package/lib/nodejs/cli.js
CHANGED
package/lib/nodejs/filesystem.js
CHANGED
|
@@ -368,19 +368,16 @@ class Descriptor {
|
|
|
368
368
|
}
|
|
369
369
|
}
|
|
370
370
|
try {
|
|
371
|
-
const fd = openSync(fullPath, fsOpenFlags);
|
|
371
|
+
const fd = openSync(fullPath.endsWith('/') ? fullPath.slice(0, -1) : fullPath, fsOpenFlags);
|
|
372
372
|
const descriptor = descriptorCreate(
|
|
373
373
|
fd,
|
|
374
374
|
descriptorFlags,
|
|
375
375
|
fullPath,
|
|
376
376
|
preopenEntries
|
|
377
377
|
);
|
|
378
|
-
if (fullPath.endsWith(
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
descriptor[symbolDispose]();
|
|
382
|
-
throw "not-directory";
|
|
383
|
-
}
|
|
378
|
+
if (fullPath.endsWith('/') && descriptor.getType() !== 'directory') {
|
|
379
|
+
descriptor[symbolDispose]();
|
|
380
|
+
throw "not-directory";
|
|
384
381
|
}
|
|
385
382
|
return descriptor;
|
|
386
383
|
} catch (e) {
|
|
@@ -671,6 +668,7 @@ function convertFsError(e) {
|
|
|
671
668
|
case "ENOSPC":
|
|
672
669
|
return "insufficient-space";
|
|
673
670
|
case "ENOTDIR":
|
|
671
|
+
case 'ERR_FS_EISDIR':
|
|
674
672
|
return "not-directory";
|
|
675
673
|
case "ENOTEMPTY":
|
|
676
674
|
return "not-empty";
|
package/package.json
CHANGED
|
@@ -569,12 +569,6 @@ export class Descriptor {
|
|
|
569
569
|
/**
|
|
570
570
|
* Open a file or directory.
|
|
571
571
|
*
|
|
572
|
-
* The returned descriptor is not guaranteed to be the lowest-numbered
|
|
573
|
-
* descriptor not currently open/ it is randomized to prevent applications
|
|
574
|
-
* from depending on making assumptions about indexes, since this is
|
|
575
|
-
* error-prone in multi-threaded contexts. The returned descriptor is
|
|
576
|
-
* guaranteed to be less than 2**31.
|
|
577
|
-
*
|
|
578
572
|
* If `flags` contains `descriptor-flags::mutate-directory`, and the base
|
|
579
573
|
* descriptor doesn't have `descriptor-flags::mutate-directory` set,
|
|
580
574
|
* `open-at` fails with `error-code::read-only`.
|
|
@@ -255,7 +255,7 @@ export interface ErrorCodeInternalError {
|
|
|
255
255
|
*/
|
|
256
256
|
export type HeaderError = HeaderErrorInvalidSyntax | HeaderErrorForbidden | HeaderErrorImmutable;
|
|
257
257
|
/**
|
|
258
|
-
* This error indicates that a `field-
|
|
258
|
+
* This error indicates that a `field-name` or `field-value` was
|
|
259
259
|
* syntactically invalid when used with an operation that sets headers in a
|
|
260
260
|
* `fields`.
|
|
261
261
|
*/
|
|
@@ -263,7 +263,7 @@ export interface HeaderErrorInvalidSyntax {
|
|
|
263
263
|
tag: 'invalid-syntax',
|
|
264
264
|
}
|
|
265
265
|
/**
|
|
266
|
-
* This error indicates that a forbidden `field-
|
|
266
|
+
* This error indicates that a forbidden `field-name` was used when trying
|
|
267
267
|
* to set a header in a `fields`.
|
|
268
268
|
*/
|
|
269
269
|
export interface HeaderErrorForbidden {
|
|
@@ -278,8 +278,22 @@ export interface HeaderErrorImmutable {
|
|
|
278
278
|
}
|
|
279
279
|
/**
|
|
280
280
|
* Field keys are always strings.
|
|
281
|
+
*
|
|
282
|
+
* Field keys should always be treated as case insensitive by the `fields`
|
|
283
|
+
* resource for the purposes of equality checking.
|
|
284
|
+
*
|
|
285
|
+
* # Deprecation
|
|
286
|
+
*
|
|
287
|
+
* This type has been deprecated in favor of the `field-name` type.
|
|
281
288
|
*/
|
|
282
289
|
export type FieldKey = string;
|
|
290
|
+
/**
|
|
291
|
+
* Field names are always strings.
|
|
292
|
+
*
|
|
293
|
+
* Field names should always be treated as case insensitive by the `fields`
|
|
294
|
+
* resource for the purposes of equality checking.
|
|
295
|
+
*/
|
|
296
|
+
export type FieldName = FieldKey;
|
|
283
297
|
/**
|
|
284
298
|
* Field values should always be ASCII strings. However, in
|
|
285
299
|
* reality, HTTP implementations often have to interpret malformed values,
|
|
@@ -312,68 +326,71 @@ export class Fields {
|
|
|
312
326
|
*
|
|
313
327
|
* The resulting `fields` is mutable.
|
|
314
328
|
*
|
|
315
|
-
* The list represents each
|
|
329
|
+
* The list represents each name-value pair in the Fields. Names
|
|
316
330
|
* which have multiple values are represented by multiple entries in this
|
|
317
|
-
* list with the same
|
|
331
|
+
* list with the same name.
|
|
318
332
|
*
|
|
319
|
-
* The tuple is a pair of the field
|
|
333
|
+
* The tuple is a pair of the field name, represented as a string, and
|
|
320
334
|
* Value, represented as a list of bytes.
|
|
321
335
|
*
|
|
322
|
-
* An error result will be returned if any `field-
|
|
336
|
+
* An error result will be returned if any `field-name` or `field-value` is
|
|
323
337
|
* syntactically invalid, or if a field is forbidden.
|
|
324
338
|
*/
|
|
325
|
-
static fromList(entries: Array<[
|
|
339
|
+
static fromList(entries: Array<[FieldName, FieldValue]>): Fields;
|
|
326
340
|
/**
|
|
327
|
-
* Get all of the values corresponding to a
|
|
341
|
+
* Get all of the values corresponding to a name. If the name is not present
|
|
328
342
|
* in this `fields` or is syntactically invalid, an empty list is returned.
|
|
329
|
-
* However, if the
|
|
343
|
+
* However, if the name is present but empty, this is represented by a list
|
|
330
344
|
* with one or more empty field-values present.
|
|
331
345
|
*/
|
|
332
|
-
get(name:
|
|
346
|
+
get(name: FieldName): Array<FieldValue>;
|
|
333
347
|
/**
|
|
334
|
-
* Returns `true` when the
|
|
348
|
+
* Returns `true` when the name is present in this `fields`. If the name is
|
|
335
349
|
* syntactically invalid, `false` is returned.
|
|
336
350
|
*/
|
|
337
|
-
has(name:
|
|
351
|
+
has(name: FieldName): boolean;
|
|
338
352
|
/**
|
|
339
|
-
* Set all of the values for a
|
|
340
|
-
*
|
|
353
|
+
* Set all of the values for a name. Clears any existing values for that
|
|
354
|
+
* name, if they have been set.
|
|
341
355
|
*
|
|
342
356
|
* Fails with `header-error.immutable` if the `fields` are immutable.
|
|
343
357
|
*
|
|
344
|
-
* Fails with `header-error.invalid-syntax` if the `field-
|
|
358
|
+
* Fails with `header-error.invalid-syntax` if the `field-name` or any of
|
|
345
359
|
* the `field-value`s are syntactically invalid.
|
|
346
360
|
*/
|
|
347
|
-
set(name:
|
|
361
|
+
set(name: FieldName, value: Array<FieldValue>): void;
|
|
348
362
|
/**
|
|
349
|
-
* Delete all values for a
|
|
363
|
+
* Delete all values for a name. Does nothing if no values for the name
|
|
350
364
|
* exist.
|
|
351
365
|
*
|
|
352
366
|
* Fails with `header-error.immutable` if the `fields` are immutable.
|
|
353
367
|
*
|
|
354
|
-
* Fails with `header-error.invalid-syntax` if the `field-
|
|
368
|
+
* Fails with `header-error.invalid-syntax` if the `field-name` is
|
|
355
369
|
* syntactically invalid.
|
|
356
370
|
*/
|
|
357
|
-
'delete'(name:
|
|
371
|
+
'delete'(name: FieldName): void;
|
|
358
372
|
/**
|
|
359
|
-
* Append a value for a
|
|
360
|
-
* values for that
|
|
373
|
+
* Append a value for a name. Does not change or delete any existing
|
|
374
|
+
* values for that name.
|
|
361
375
|
*
|
|
362
376
|
* Fails with `header-error.immutable` if the `fields` are immutable.
|
|
363
377
|
*
|
|
364
|
-
* Fails with `header-error.invalid-syntax` if the `field-
|
|
378
|
+
* Fails with `header-error.invalid-syntax` if the `field-name` or
|
|
365
379
|
* `field-value` are syntactically invalid.
|
|
366
380
|
*/
|
|
367
|
-
append(name:
|
|
381
|
+
append(name: FieldName, value: FieldValue): void;
|
|
368
382
|
/**
|
|
369
|
-
* Retrieve the full set of
|
|
370
|
-
* constructor, the list represents each
|
|
383
|
+
* Retrieve the full set of names and values in the Fields. Like the
|
|
384
|
+
* constructor, the list represents each name-value pair.
|
|
371
385
|
*
|
|
372
|
-
* The outer list represents each
|
|
386
|
+
* The outer list represents each name-value pair in the Fields. Names
|
|
373
387
|
* which have multiple values are represented by multiple entries in this
|
|
374
|
-
* list with the same
|
|
388
|
+
* list with the same name.
|
|
389
|
+
*
|
|
390
|
+
* The names and values are always returned in the original casing and in
|
|
391
|
+
* the order in which they will be serialized for transport.
|
|
375
392
|
*/
|
|
376
|
-
entries(): Array<[
|
|
393
|
+
entries(): Array<[FieldName, FieldValue]>;
|
|
377
394
|
/**
|
|
378
395
|
* Make a deep copy of the Fields. Equivalent in behavior to calling the
|
|
379
396
|
* `fields` constructor on the return value of `entries`. The resulting
|
|
@@ -14,6 +14,9 @@ export type StreamError = StreamErrorLastOperationFailed | StreamErrorClosed;
|
|
|
14
14
|
* The last operation (a write or flush) failed before completion.
|
|
15
15
|
*
|
|
16
16
|
* More information is available in the `error` payload.
|
|
17
|
+
*
|
|
18
|
+
* After this, the stream will be closed. All future operations return
|
|
19
|
+
* `stream-error::closed`.
|
|
17
20
|
*/
|
|
18
21
|
export interface StreamErrorLastOperationFailed {
|
|
19
22
|
tag: 'last-operation-failed',
|
|
@@ -53,7 +53,7 @@ export class ResolveAddressStream {
|
|
|
53
53
|
/**
|
|
54
54
|
* Create a `pollable` which will resolve once the stream is ready for I/O.
|
|
55
55
|
*
|
|
56
|
-
* Note: this function is here for WASI
|
|
56
|
+
* Note: this function is here for WASI 0.2 only.
|
|
57
57
|
* It's planned to be removed when `future` is natively supported in Preview3.
|
|
58
58
|
*/
|
|
59
59
|
subscribe(): Pollable;
|
|
@@ -332,7 +332,7 @@ export class TcpSocket {
|
|
|
332
332
|
* See <https://github.com/WebAssembly/wasi-sockets/blob/main/TcpSocketOperationalSemantics.md#pollable-readiness>
|
|
333
333
|
* for more information.
|
|
334
334
|
*
|
|
335
|
-
* Note: this function is here for WASI
|
|
335
|
+
* Note: this function is here for WASI 0.2 only.
|
|
336
336
|
* It's planned to be removed when `future` is natively supported in Preview3.
|
|
337
337
|
*/
|
|
338
338
|
subscribe(): Pollable;
|
|
@@ -82,7 +82,7 @@ export class IncomingDatagramStream {
|
|
|
82
82
|
/**
|
|
83
83
|
* Create a `pollable` which will resolve once the stream is ready to receive again.
|
|
84
84
|
*
|
|
85
|
-
* Note: this function is here for WASI
|
|
85
|
+
* Note: this function is here for WASI 0.2 only.
|
|
86
86
|
* It's planned to be removed when `future` is natively supported in Preview3.
|
|
87
87
|
*/
|
|
88
88
|
subscribe(): Pollable;
|
|
@@ -143,7 +143,7 @@ export class OutgoingDatagramStream {
|
|
|
143
143
|
/**
|
|
144
144
|
* Create a `pollable` which will resolve once the stream is ready to send again.
|
|
145
145
|
*
|
|
146
|
-
* Note: this function is here for WASI
|
|
146
|
+
* Note: this function is here for WASI 0.2 only.
|
|
147
147
|
* It's planned to be removed when `future` is natively supported in Preview3.
|
|
148
148
|
*/
|
|
149
149
|
subscribe(): Pollable;
|
|
@@ -290,7 +290,7 @@ export class UdpSocket {
|
|
|
290
290
|
/**
|
|
291
291
|
* Create a `pollable` which will resolve once the socket is ready for I/O.
|
|
292
292
|
*
|
|
293
|
-
* Note: this function is here for WASI
|
|
293
|
+
* Note: this function is here for WASI 0.2 only.
|
|
294
294
|
* It's planned to be removed when `future` is natively supported in Preview3.
|
|
295
295
|
*/
|
|
296
296
|
subscribe(): Pollable;
|