@bytecodealliance/preview2-shim 0.16.1 → 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.
@@ -284,6 +284,8 @@ class OutgoingRequest {
284
284
  for (const [key, value] of request.#headers.entries()) {
285
285
  headers.push([key, decoder.decode(value)]);
286
286
  }
287
+ if (!request.#pathWithQuery)
288
+ throw { tag: 'HTTP-request-URI-invalid' };
287
289
  return futureIncomingResponseCreate(
288
290
  request.#method.val || request.#method.tag,
289
291
  scheme,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bytecodealliance/preview2-shim",
3
- "version": "0.16.1",
3
+ "version": "0.16.2",
4
4
  "description": "WASI Preview2 shim for JS environments",
5
5
  "author": "Guy Bedford, Eduardo Rodrigues<16357187+eduardomourar@users.noreply.github.com>",
6
6
  "type": "module",
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 WasiClocksMonotonicClock;
5
- export const monotonicClock: typeof WasiClocksWallClock;
4
+ export const wallClock: typeof WasiClocksWallClock;
5
+ export const monotonicClock: typeof WasiClocksMonotonicClock;
@@ -1,250 +1,5 @@
1
1
  export namespace WasiFilesystemTypes {
2
- /**
3
- * Return a stream for reading from a file, if available.
4
- *
5
- * May fail with an error-code describing why the file cannot be read.
6
- *
7
- * Multiple read, write, and append streams may be active on the same open
8
- * file and they do not interfere with each other.
9
- *
10
- * Note: This allows using `read-stream`, which is similar to `read` in POSIX.
11
- */
12
2
  export { Descriptor };
13
- /**
14
- * Return a stream for writing to a file, if available.
15
- *
16
- * May fail with an error-code describing why the file cannot be written.
17
- *
18
- * Note: This allows using `write-stream`, which is similar to `write` in
19
- * POSIX.
20
- */
21
- /**
22
- * Return a stream for appending to a file, if available.
23
- *
24
- * May fail with an error-code describing why the file cannot be appended.
25
- *
26
- * Note: This allows using `write-stream`, which is similar to `write` with
27
- * `O_APPEND` in in POSIX.
28
- */
29
- /**
30
- * Provide file advisory information on a descriptor.
31
- *
32
- * This is similar to `posix_fadvise` in POSIX.
33
- */
34
- /**
35
- * Synchronize the data of a file to disk.
36
- *
37
- * This function succeeds with no effect if the file descriptor is not
38
- * opened for writing.
39
- *
40
- * Note: This is similar to `fdatasync` in POSIX.
41
- */
42
- /**
43
- * Get flags associated with a descriptor.
44
- *
45
- * Note: This returns similar flags to `fcntl(fd, F_GETFL)` in POSIX.
46
- *
47
- * Note: This returns the value that was the `fs_flags` value returned
48
- * from `fdstat_get` in earlier versions of WASI.
49
- */
50
- /**
51
- * Get the dynamic type of a descriptor.
52
- *
53
- * Note: This returns the same value as the `type` field of the `fd-stat`
54
- * returned by `stat`, `stat-at` and similar.
55
- *
56
- * Note: This returns similar flags to the `st_mode & S_IFMT` value provided
57
- * by `fstat` in POSIX.
58
- *
59
- * Note: This returns the value that was the `fs_filetype` value returned
60
- * from `fdstat_get` in earlier versions of WASI.
61
- */
62
- /**
63
- * Adjust the size of an open file. If this increases the file's size, the
64
- * extra bytes are filled with zeros.
65
- *
66
- * Note: This was called `fd_filestat_set_size` in earlier versions of WASI.
67
- */
68
- /**
69
- * Adjust the timestamps of an open file or directory.
70
- *
71
- * Note: This is similar to `futimens` in POSIX.
72
- *
73
- * Note: This was called `fd_filestat_set_times` in earlier versions of WASI.
74
- */
75
- /**
76
- * Read from a descriptor, without using and updating the descriptor's offset.
77
- *
78
- * This function returns a list of bytes containing the data that was
79
- * read, along with a bool which, when true, indicates that the end of the
80
- * file was reached. The returned list will contain up to `length` bytes; it
81
- * may return fewer than requested, if the end of the file is reached or
82
- * if the I/O operation is interrupted.
83
- *
84
- * In the future, this may change to return a `stream<u8, error-code>`.
85
- *
86
- * Note: This is similar to `pread` in POSIX.
87
- */
88
- /**
89
- * Write to a descriptor, without using and updating the descriptor's offset.
90
- *
91
- * It is valid to write past the end of a file; the file is extended to the
92
- * extent of the write, with bytes between the previous end and the start of
93
- * the write set to zero.
94
- *
95
- * In the future, this may change to take a `stream<u8, error-code>`.
96
- *
97
- * Note: This is similar to `pwrite` in POSIX.
98
- */
99
- /**
100
- * Read directory entries from a directory.
101
- *
102
- * On filesystems where directories contain entries referring to themselves
103
- * and their parents, often named `.` and `..` respectively, these entries
104
- * are omitted.
105
- *
106
- * This always returns a new stream which starts at the beginning of the
107
- * directory. Multiple streams may be active on the same directory, and they
108
- * do not interfere with each other.
109
- */
110
- /**
111
- * Synchronize the data and metadata of a file to disk.
112
- *
113
- * This function succeeds with no effect if the file descriptor is not
114
- * opened for writing.
115
- *
116
- * Note: This is similar to `fsync` in POSIX.
117
- */
118
- /**
119
- * Create a directory.
120
- *
121
- * Note: This is similar to `mkdirat` in POSIX.
122
- */
123
- /**
124
- * Return the attributes of an open file or directory.
125
- *
126
- * Note: This is similar to `fstat` in POSIX, except that it does not return
127
- * device and inode information. For testing whether two descriptors refer to
128
- * the same underlying filesystem object, use `is-same-object`. To obtain
129
- * additional data that can be used do determine whether a file has been
130
- * modified, use `metadata-hash`.
131
- *
132
- * Note: This was called `fd_filestat_get` in earlier versions of WASI.
133
- */
134
- /**
135
- * Return the attributes of a file or directory.
136
- *
137
- * Note: This is similar to `fstatat` in POSIX, except that it does not
138
- * return device and inode information. See the `stat` description for a
139
- * discussion of alternatives.
140
- *
141
- * Note: This was called `path_filestat_get` in earlier versions of WASI.
142
- */
143
- /**
144
- * Adjust the timestamps of a file or directory.
145
- *
146
- * Note: This is similar to `utimensat` in POSIX.
147
- *
148
- * Note: This was called `path_filestat_set_times` in earlier versions of
149
- * WASI.
150
- */
151
- /**
152
- * Create a hard link.
153
- *
154
- * Note: This is similar to `linkat` in POSIX.
155
- */
156
- /**
157
- * Open a file or directory.
158
- *
159
- * The returned descriptor is not guaranteed to be the lowest-numbered
160
- * descriptor not currently open/ it is randomized to prevent applications
161
- * from depending on making assumptions about indexes, since this is
162
- * error-prone in multi-threaded contexts. The returned descriptor is
163
- * guaranteed to be less than 2**31.
164
- *
165
- * If `flags` contains `descriptor-flags::mutate-directory`, and the base
166
- * descriptor doesn't have `descriptor-flags::mutate-directory` set,
167
- * `open-at` fails with `error-code::read-only`.
168
- *
169
- * If `flags` contains `write` or `mutate-directory`, or `open-flags`
170
- * contains `truncate` or `create`, and the base descriptor doesn't have
171
- * `descriptor-flags::mutate-directory` set, `open-at` fails with
172
- * `error-code::read-only`.
173
- *
174
- * Note: This is similar to `openat` in POSIX.
175
- */
176
- /**
177
- * Read the contents of a symbolic link.
178
- *
179
- * If the contents contain an absolute or rooted path in the underlying
180
- * filesystem, this function fails with `error-code::not-permitted`.
181
- *
182
- * Note: This is similar to `readlinkat` in POSIX.
183
- */
184
- /**
185
- * Remove a directory.
186
- *
187
- * Return `error-code::not-empty` if the directory is not empty.
188
- *
189
- * Note: This is similar to `unlinkat(fd, path, AT_REMOVEDIR)` in POSIX.
190
- */
191
- /**
192
- * Rename a filesystem object.
193
- *
194
- * Note: This is similar to `renameat` in POSIX.
195
- */
196
- /**
197
- * Create a symbolic link (also known as a "symlink").
198
- *
199
- * If `old-path` starts with `/`, the function fails with
200
- * `error-code::not-permitted`.
201
- *
202
- * Note: This is similar to `symlinkat` in POSIX.
203
- */
204
- /**
205
- * Unlink a filesystem object that is not a directory.
206
- *
207
- * Return `error-code::is-directory` if the path refers to a directory.
208
- * Note: This is similar to `unlinkat(fd, path, 0)` in POSIX.
209
- */
210
- /**
211
- * Test whether two descriptors refer to the same filesystem object.
212
- *
213
- * In POSIX, this corresponds to testing whether the two descriptors have the
214
- * same device (`st_dev`) and inode (`st_ino` or `d_ino`) numbers.
215
- * wasi-filesystem does not expose device and inode numbers, so this function
216
- * may be used instead.
217
- */
218
- /**
219
- * Return a hash of the metadata associated with a filesystem object referred
220
- * to by a descriptor.
221
- *
222
- * This returns a hash of the last-modification timestamp and file size, and
223
- * may also include the inode number, device number, birth timestamp, and
224
- * other metadata fields that may change when the file is modified or
225
- * replaced. It may also include a secret value chosen by the
226
- * implementation and not otherwise exposed.
227
- *
228
- * Implementations are encourated to provide the following properties:
229
- *
230
- * - If the file is not modified or replaced, the computed hash value should
231
- * usually not change.
232
- * - If the object is modified or replaced, the computed hash value should
233
- * usually change.
234
- * - The inputs to the hash should not be easily computable from the
235
- * computed hash.
236
- *
237
- * However, none of these is required.
238
- */
239
- /**
240
- * Return a hash of the metadata associated with a filesystem object referred
241
- * to by a directory descriptor and a relative path.
242
- *
243
- * This performs the same hash computation as `metadata-hash`.
244
- */
245
- /**
246
- * Read a single directory entry from a `directory-entry-stream`.
247
- */
248
3
  export { DirectoryEntryStream };
249
4
  /**
250
5
  * Attempts to extract a filesystem-related `error-code` from the stream
@@ -639,36 +394,281 @@ export interface MetadataHashValue {
639
394
  upper: bigint,
640
395
  }
641
396
 
642
- export class DirectoryEntryStream {
643
- readDirectoryEntry(): DirectoryEntry | undefined;
644
- }
645
-
646
397
  export class Descriptor {
398
+ /**
399
+ * Return a stream for reading from a file, if available.
400
+ *
401
+ * May fail with an error-code describing why the file cannot be read.
402
+ *
403
+ * Multiple read, write, and append streams may be active on the same open
404
+ * file and they do not interfere with each other.
405
+ *
406
+ * Note: This allows using `read-stream`, which is similar to `read` in POSIX.
407
+ */
647
408
  readViaStream(offset: Filesize): InputStream;
409
+ /**
410
+ * Return a stream for writing to a file, if available.
411
+ *
412
+ * May fail with an error-code describing why the file cannot be written.
413
+ *
414
+ * Note: This allows using `write-stream`, which is similar to `write` in
415
+ * POSIX.
416
+ */
648
417
  writeViaStream(offset: Filesize): OutputStream;
418
+ /**
419
+ * Return a stream for appending to a file, if available.
420
+ *
421
+ * May fail with an error-code describing why the file cannot be appended.
422
+ *
423
+ * Note: This allows using `write-stream`, which is similar to `write` with
424
+ * `O_APPEND` in in POSIX.
425
+ */
649
426
  appendViaStream(): OutputStream;
427
+ /**
428
+ * Provide file advisory information on a descriptor.
429
+ *
430
+ * This is similar to `posix_fadvise` in POSIX.
431
+ */
650
432
  advise(offset: Filesize, length: Filesize, advice: Advice): void;
433
+ /**
434
+ * Synchronize the data of a file to disk.
435
+ *
436
+ * This function succeeds with no effect if the file descriptor is not
437
+ * opened for writing.
438
+ *
439
+ * Note: This is similar to `fdatasync` in POSIX.
440
+ */
651
441
  syncData(): void;
442
+ /**
443
+ * Get flags associated with a descriptor.
444
+ *
445
+ * Note: This returns similar flags to `fcntl(fd, F_GETFL)` in POSIX.
446
+ *
447
+ * Note: This returns the value that was the `fs_flags` value returned
448
+ * from `fdstat_get` in earlier versions of WASI.
449
+ */
652
450
  getFlags(): DescriptorFlags;
451
+ /**
452
+ * Get the dynamic type of a descriptor.
453
+ *
454
+ * Note: This returns the same value as the `type` field of the `fd-stat`
455
+ * returned by `stat`, `stat-at` and similar.
456
+ *
457
+ * Note: This returns similar flags to the `st_mode & S_IFMT` value provided
458
+ * by `fstat` in POSIX.
459
+ *
460
+ * Note: This returns the value that was the `fs_filetype` value returned
461
+ * from `fdstat_get` in earlier versions of WASI.
462
+ */
653
463
  getType(): DescriptorType;
464
+ /**
465
+ * Adjust the size of an open file. If this increases the file's size, the
466
+ * extra bytes are filled with zeros.
467
+ *
468
+ * Note: This was called `fd_filestat_set_size` in earlier versions of WASI.
469
+ */
654
470
  setSize(size: Filesize): void;
471
+ /**
472
+ * Adjust the timestamps of an open file or directory.
473
+ *
474
+ * Note: This is similar to `futimens` in POSIX.
475
+ *
476
+ * Note: This was called `fd_filestat_set_times` in earlier versions of WASI.
477
+ */
655
478
  setTimes(dataAccessTimestamp: NewTimestamp, dataModificationTimestamp: NewTimestamp): void;
479
+ /**
480
+ * Read from a descriptor, without using and updating the descriptor's offset.
481
+ *
482
+ * This function returns a list of bytes containing the data that was
483
+ * read, along with a bool which, when true, indicates that the end of the
484
+ * file was reached. The returned list will contain up to `length` bytes; it
485
+ * may return fewer than requested, if the end of the file is reached or
486
+ * if the I/O operation is interrupted.
487
+ *
488
+ * In the future, this may change to return a `stream<u8, error-code>`.
489
+ *
490
+ * Note: This is similar to `pread` in POSIX.
491
+ */
656
492
  read(length: Filesize, offset: Filesize): [Uint8Array, boolean];
493
+ /**
494
+ * Write to a descriptor, without using and updating the descriptor's offset.
495
+ *
496
+ * It is valid to write past the end of a file; the file is extended to the
497
+ * extent of the write, with bytes between the previous end and the start of
498
+ * the write set to zero.
499
+ *
500
+ * In the future, this may change to take a `stream<u8, error-code>`.
501
+ *
502
+ * Note: This is similar to `pwrite` in POSIX.
503
+ */
657
504
  write(buffer: Uint8Array, offset: Filesize): Filesize;
505
+ /**
506
+ * Read directory entries from a directory.
507
+ *
508
+ * On filesystems where directories contain entries referring to themselves
509
+ * and their parents, often named `.` and `..` respectively, these entries
510
+ * are omitted.
511
+ *
512
+ * This always returns a new stream which starts at the beginning of the
513
+ * directory. Multiple streams may be active on the same directory, and they
514
+ * do not interfere with each other.
515
+ */
658
516
  readDirectory(): DirectoryEntryStream;
517
+ /**
518
+ * Synchronize the data and metadata of a file to disk.
519
+ *
520
+ * This function succeeds with no effect if the file descriptor is not
521
+ * opened for writing.
522
+ *
523
+ * Note: This is similar to `fsync` in POSIX.
524
+ */
659
525
  sync(): void;
526
+ /**
527
+ * Create a directory.
528
+ *
529
+ * Note: This is similar to `mkdirat` in POSIX.
530
+ */
660
531
  createDirectoryAt(path: string): void;
532
+ /**
533
+ * Return the attributes of an open file or directory.
534
+ *
535
+ * Note: This is similar to `fstat` in POSIX, except that it does not return
536
+ * device and inode information. For testing whether two descriptors refer to
537
+ * the same underlying filesystem object, use `is-same-object`. To obtain
538
+ * additional data that can be used do determine whether a file has been
539
+ * modified, use `metadata-hash`.
540
+ *
541
+ * Note: This was called `fd_filestat_get` in earlier versions of WASI.
542
+ */
661
543
  stat(): DescriptorStat;
544
+ /**
545
+ * Return the attributes of a file or directory.
546
+ *
547
+ * Note: This is similar to `fstatat` in POSIX, except that it does not
548
+ * return device and inode information. See the `stat` description for a
549
+ * discussion of alternatives.
550
+ *
551
+ * Note: This was called `path_filestat_get` in earlier versions of WASI.
552
+ */
662
553
  statAt(pathFlags: PathFlags, path: string): DescriptorStat;
554
+ /**
555
+ * Adjust the timestamps of a file or directory.
556
+ *
557
+ * Note: This is similar to `utimensat` in POSIX.
558
+ *
559
+ * Note: This was called `path_filestat_set_times` in earlier versions of
560
+ * WASI.
561
+ */
663
562
  setTimesAt(pathFlags: PathFlags, path: string, dataAccessTimestamp: NewTimestamp, dataModificationTimestamp: NewTimestamp): void;
563
+ /**
564
+ * Create a hard link.
565
+ *
566
+ * Note: This is similar to `linkat` in POSIX.
567
+ */
664
568
  linkAt(oldPathFlags: PathFlags, oldPath: string, newDescriptor: Descriptor, newPath: string): void;
569
+ /**
570
+ * Open a file or directory.
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
+ * If `flags` contains `descriptor-flags::mutate-directory`, and the base
579
+ * descriptor doesn't have `descriptor-flags::mutate-directory` set,
580
+ * `open-at` fails with `error-code::read-only`.
581
+ *
582
+ * If `flags` contains `write` or `mutate-directory`, or `open-flags`
583
+ * contains `truncate` or `create`, and the base descriptor doesn't have
584
+ * `descriptor-flags::mutate-directory` set, `open-at` fails with
585
+ * `error-code::read-only`.
586
+ *
587
+ * Note: This is similar to `openat` in POSIX.
588
+ */
665
589
  openAt(pathFlags: PathFlags, path: string, openFlags: OpenFlags, flags: DescriptorFlags): Descriptor;
590
+ /**
591
+ * Read the contents of a symbolic link.
592
+ *
593
+ * If the contents contain an absolute or rooted path in the underlying
594
+ * filesystem, this function fails with `error-code::not-permitted`.
595
+ *
596
+ * Note: This is similar to `readlinkat` in POSIX.
597
+ */
666
598
  readlinkAt(path: string): string;
599
+ /**
600
+ * Remove a directory.
601
+ *
602
+ * Return `error-code::not-empty` if the directory is not empty.
603
+ *
604
+ * Note: This is similar to `unlinkat(fd, path, AT_REMOVEDIR)` in POSIX.
605
+ */
667
606
  removeDirectoryAt(path: string): void;
607
+ /**
608
+ * Rename a filesystem object.
609
+ *
610
+ * Note: This is similar to `renameat` in POSIX.
611
+ */
668
612
  renameAt(oldPath: string, newDescriptor: Descriptor, newPath: string): void;
613
+ /**
614
+ * Create a symbolic link (also known as a "symlink").
615
+ *
616
+ * If `old-path` starts with `/`, the function fails with
617
+ * `error-code::not-permitted`.
618
+ *
619
+ * Note: This is similar to `symlinkat` in POSIX.
620
+ */
669
621
  symlinkAt(oldPath: string, newPath: string): void;
622
+ /**
623
+ * Unlink a filesystem object that is not a directory.
624
+ *
625
+ * Return `error-code::is-directory` if the path refers to a directory.
626
+ * Note: This is similar to `unlinkat(fd, path, 0)` in POSIX.
627
+ */
670
628
  unlinkFileAt(path: string): void;
629
+ /**
630
+ * Test whether two descriptors refer to the same filesystem object.
631
+ *
632
+ * In POSIX, this corresponds to testing whether the two descriptors have the
633
+ * same device (`st_dev`) and inode (`st_ino` or `d_ino`) numbers.
634
+ * wasi-filesystem does not expose device and inode numbers, so this function
635
+ * may be used instead.
636
+ */
671
637
  isSameObject(other: Descriptor): boolean;
638
+ /**
639
+ * Return a hash of the metadata associated with a filesystem object referred
640
+ * to by a descriptor.
641
+ *
642
+ * This returns a hash of the last-modification timestamp and file size, and
643
+ * may also include the inode number, device number, birth timestamp, and
644
+ * other metadata fields that may change when the file is modified or
645
+ * replaced. It may also include a secret value chosen by the
646
+ * implementation and not otherwise exposed.
647
+ *
648
+ * Implementations are encourated to provide the following properties:
649
+ *
650
+ * - If the file is not modified or replaced, the computed hash value should
651
+ * usually not change.
652
+ * - If the object is modified or replaced, the computed hash value should
653
+ * usually change.
654
+ * - The inputs to the hash should not be easily computable from the
655
+ * computed hash.
656
+ *
657
+ * However, none of these is required.
658
+ */
672
659
  metadataHash(): MetadataHashValue;
660
+ /**
661
+ * Return a hash of the metadata associated with a filesystem object referred
662
+ * to by a directory descriptor and a relative path.
663
+ *
664
+ * This performs the same hash computation as `metadata-hash`.
665
+ */
673
666
  metadataHashAt(pathFlags: PathFlags, path: string): MetadataHashValue;
674
667
  }
668
+
669
+ export class DirectoryEntryStream {
670
+ /**
671
+ * Read a single directory entry from a `directory-entry-stream`.
672
+ */
673
+ readDirectoryEntry(): DirectoryEntry | undefined;
674
+ }