@bytecodealliance/preview2-shim 0.17.5 → 0.17.6

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.
@@ -1,4 +1,3 @@
1
- // eslint-disable-next-line no-unused-vars
2
1
  let _cwd = '/';
3
2
 
4
3
  export function _setCwd(cwd) {
@@ -325,6 +325,103 @@ export const preopens = {
325
325
  export const types = {
326
326
  Descriptor,
327
327
  DirectoryEntryStream,
328
+ filesystemErrorCode(err) {
329
+ return convertFsError(err.payload);
330
+ },
328
331
  };
329
332
 
333
+ function convertFsError(e) {
334
+ switch (e.code) {
335
+ case 'EACCES':
336
+ return 'access';
337
+ case 'EAGAIN':
338
+ case 'EWOULDBLOCK':
339
+ return 'would-block';
340
+ case 'EALREADY':
341
+ return 'already';
342
+ case 'EBADF':
343
+ return 'bad-descriptor';
344
+ case 'EBUSY':
345
+ return 'busy';
346
+ case 'EDEADLK':
347
+ return 'deadlock';
348
+ case 'EDQUOT':
349
+ return 'quota';
350
+ case 'EEXIST':
351
+ return 'exist';
352
+ case 'EFBIG':
353
+ return 'file-too-large';
354
+ case 'EILSEQ':
355
+ return 'illegal-byte-sequence';
356
+ case 'EINPROGRESS':
357
+ return 'in-progress';
358
+ case 'EINTR':
359
+ return 'interrupted';
360
+ case 'EINVAL':
361
+ return 'invalid';
362
+ case 'EIO':
363
+ return 'io';
364
+ case 'EISDIR':
365
+ return 'is-directory';
366
+ case 'ELOOP':
367
+ return 'loop';
368
+ case 'EMLINK':
369
+ return 'too-many-links';
370
+ case 'EMSGSIZE':
371
+ return 'message-size';
372
+ case 'ENAMETOOLONG':
373
+ return 'name-too-long';
374
+ case 'ENODEV':
375
+ return 'no-device';
376
+ case 'ENOENT':
377
+ return 'no-entry';
378
+ case 'ENOLCK':
379
+ return 'no-lock';
380
+ case 'ENOMEM':
381
+ return 'insufficient-memory';
382
+ case 'ENOSPC':
383
+ return 'insufficient-space';
384
+ case 'ENOTDIR':
385
+ case 'ERR_FS_EISDIR':
386
+ return 'not-directory';
387
+ case 'ENOTEMPTY':
388
+ return 'not-empty';
389
+ case 'ENOTRECOVERABLE':
390
+ return 'not-recoverable';
391
+ case 'ENOTSUP':
392
+ return 'unsupported';
393
+ case 'ENOTTY':
394
+ return 'no-tty';
395
+ // windows gives this error for badly structured `//` reads
396
+ // this seems like a slightly better error than unknown given
397
+ // that it's a common footgun
398
+ case -4094:
399
+ case 'ENXIO':
400
+ return 'no-such-device';
401
+ case 'EOVERFLOW':
402
+ return 'overflow';
403
+ case 'EPERM':
404
+ return 'not-permitted';
405
+ case 'EPIPE':
406
+ return 'pipe';
407
+ case 'EROFS':
408
+ return 'read-only';
409
+ case 'ESPIPE':
410
+ return 'invalid-seek';
411
+ case 'ETXTBSY':
412
+ return 'text-file-busy';
413
+ case 'EXDEV':
414
+ return 'cross-device';
415
+ case 'UNKNOWN':
416
+ switch (e.errno) {
417
+ case -4094:
418
+ return 'no-such-device';
419
+ default:
420
+ throw e;
421
+ }
422
+ default:
423
+ throw e;
424
+ }
425
+ }
426
+
330
427
  export { types as filesystemTypes };
@@ -142,4 +142,14 @@ export const types = {
142
142
  listenToFutureIncomingResponse(_f) {
143
143
  console.log('[types] Listen to future incoming response');
144
144
  },
145
+ Fields: class Fields {},
146
+ FutureIncomingResponse: new class FutureIncomingResponse {},
147
+ IncomingBody: new class IncomingBody {},
148
+ IncomingRequest: new class IncomingRequest {},
149
+ IncomingResponse: new class IncomingResponse {},
150
+ OutgoingBody: new class OutgoingBody {},
151
+ OutgoingRequest: new class OutgoingRequest {},
152
+ OutgoingResponse: new class OutgoingResponse {},
153
+ RequestOptions: new class RequestOptions {},
154
+ ResponseOutparam: new class ResponseOutparam {},
145
155
  };
package/lib/browser/io.js CHANGED
@@ -17,7 +17,7 @@ const IoError = class Error {
17
17
  * blockingRead: (len: BigInt) => Uint8Array,
18
18
  * skip?: (len: BigInt) => BigInt,
19
19
  * blockingSkip?: (len: BigInt) => BigInt,
20
- * subscribe: () => void,
20
+ * subscribe: () => Pollable,
21
21
  * drop?: () => void,
22
22
  * }} InputStreamHandler
23
23
  *
@@ -33,7 +33,7 @@ const IoError = class Error {
33
33
  * splice?: (src: InputStream, len: BigInt) => BigInt,
34
34
  * blockingSplice?: (src: InputStream, len: BigInt) => BigInt,
35
35
  * forward?: (src: InputStream) => void,
36
- * subscribe?: () => void,
36
+ * subscribe?: () => Pollable,
37
37
  * drop?: () => void,
38
38
  * }} OutputStreamHandler
39
39
  *
@@ -78,6 +78,7 @@ class InputStream {
78
78
  }
79
79
  subscribe() {
80
80
  console.log(`[streams] Subscribe to input stream ${this.id}`);
81
+ return new Pollable();
81
82
  }
82
83
  [symbolDispose]() {
83
84
  if (this.handler.drop) {
@@ -168,6 +169,7 @@ class OutputStream {
168
169
  }
169
170
  subscribe() {
170
171
  console.log(`[streams] Subscribe to output stream ${this.id}`);
172
+ return new Pollable();
171
173
  }
172
174
  [symbolDispose]() {}
173
175
  }
@@ -190,4 +192,5 @@ export const poll = {
190
192
  Pollable,
191
193
  pollList,
192
194
  pollOne,
195
+ poll: pollOne,
193
196
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bytecodealliance/preview2-shim",
3
- "version": "0.17.5",
3
+ "version": "0.17.6",
4
4
  "description": "WASI Preview2 shim for JS environments",
5
5
  "author": "Guy Bedford, Eduardo Rodrigues<16357187+eduardomourar@users.noreply.github.com>",
6
6
  "contributors": [