@bytecodealliance/preview3-shim 0.1.0-rc.0

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.
Files changed (67) hide show
  1. package/LICENSE +220 -0
  2. package/README.md +14 -0
  3. package/lib/nodejs/cli.js +127 -0
  4. package/lib/nodejs/clocks.js +100 -0
  5. package/lib/nodejs/filesystem/descriptor.js +997 -0
  6. package/lib/nodejs/filesystem/error.js +92 -0
  7. package/lib/nodejs/filesystem/utils.js +19 -0
  8. package/lib/nodejs/filesystem.js +2 -0
  9. package/lib/nodejs/finalization.js +33 -0
  10. package/lib/nodejs/future.js +187 -0
  11. package/lib/nodejs/http/client.js +146 -0
  12. package/lib/nodejs/http/error.js +71 -0
  13. package/lib/nodejs/http/fields.js +359 -0
  14. package/lib/nodejs/http/request.js +589 -0
  15. package/lib/nodejs/http/response.js +212 -0
  16. package/lib/nodejs/http/server.js +157 -0
  17. package/lib/nodejs/http.js +34 -0
  18. package/lib/nodejs/index.js +8 -0
  19. package/lib/nodejs/random.js +14 -0
  20. package/lib/nodejs/sockets/address.js +146 -0
  21. package/lib/nodejs/sockets/error.js +123 -0
  22. package/lib/nodejs/sockets/ip-name-lookup.js +93 -0
  23. package/lib/nodejs/sockets/tcp.js +776 -0
  24. package/lib/nodejs/sockets/udp.js +516 -0
  25. package/lib/nodejs/sockets.js +14 -0
  26. package/lib/nodejs/stream.js +423 -0
  27. package/lib/nodejs/workers/cli-worker.js +49 -0
  28. package/lib/nodejs/workers/filesystem-worker.js +119 -0
  29. package/lib/nodejs/workers/http-worker.js +387 -0
  30. package/lib/nodejs/workers/resource-worker.js +151 -0
  31. package/lib/nodejs/workers/tcp-worker.js +283 -0
  32. package/lib/nodejs/workers/udp-worker.js +194 -0
  33. package/package.json +57 -0
  34. package/types/cli.d.ts +12 -0
  35. package/types/clocks.d.ts +2 -0
  36. package/types/filesystem.d.ts +2 -0
  37. package/types/http.d.ts +4 -0
  38. package/types/index.d.ts +6 -0
  39. package/types/interfaces/wasi-cli-environment.d.ts +21 -0
  40. package/types/interfaces/wasi-cli-exit.d.ts +6 -0
  41. package/types/interfaces/wasi-cli-run.d.ts +5 -0
  42. package/types/interfaces/wasi-cli-stderr.d.ts +14 -0
  43. package/types/interfaces/wasi-cli-stdin.d.ts +19 -0
  44. package/types/interfaces/wasi-cli-stdout.d.ts +14 -0
  45. package/types/interfaces/wasi-cli-terminal-input.d.ts +8 -0
  46. package/types/interfaces/wasi-cli-terminal-output.d.ts +8 -0
  47. package/types/interfaces/wasi-cli-terminal-stderr.d.ts +7 -0
  48. package/types/interfaces/wasi-cli-terminal-stdin.d.ts +7 -0
  49. package/types/interfaces/wasi-cli-terminal-stdout.d.ts +7 -0
  50. package/types/interfaces/wasi-cli-types.d.ts +15 -0
  51. package/types/interfaces/wasi-clocks-monotonic-clock.d.ts +33 -0
  52. package/types/interfaces/wasi-clocks-system-clock.d.ts +38 -0
  53. package/types/interfaces/wasi-clocks-types.d.ts +5 -0
  54. package/types/interfaces/wasi-filesystem-preopens.d.ts +6 -0
  55. package/types/interfaces/wasi-filesystem-types.d.ts +780 -0
  56. package/types/interfaces/wasi-http-client.d.ts +9 -0
  57. package/types/interfaces/wasi-http-handler.d.ts +9 -0
  58. package/types/interfaces/wasi-http-types.d.ts +619 -0
  59. package/types/interfaces/wasi-random-insecure-seed.d.ts +21 -0
  60. package/types/interfaces/wasi-random-insecure.d.ts +26 -0
  61. package/types/interfaces/wasi-random-random.d.ts +31 -0
  62. package/types/interfaces/wasi-sockets-ip-name-lookup.d.ts +77 -0
  63. package/types/interfaces/wasi-sockets-types.d.ts +830 -0
  64. package/types/random.d.ts +3 -0
  65. package/types/sockets.d.ts +2 -0
  66. package/types/wasi-cli-command.d.ts +23 -0
  67. package/types/wasi-http-service.d.ts +14 -0
@@ -0,0 +1,780 @@
1
+ /** @module Interface wasi:filesystem/types@0.3.0-rc-2026-03-15 **/
2
+ export type Instant = import('./wasi-clocks-system-clock.js').Instant;
3
+ /**
4
+ * File size or length of a region within a file.
5
+ */
6
+ export type Filesize = bigint;
7
+ /**
8
+ * The type of a filesystem object referenced by a descriptor.
9
+ *
10
+ * Note: This was called `filetype` in earlier versions of WASI.
11
+ */
12
+ export type DescriptorType = DescriptorTypeBlockDevice | DescriptorTypeCharacterDevice | DescriptorTypeDirectory | DescriptorTypeFifo | DescriptorTypeSymbolicLink | DescriptorTypeRegularFile | DescriptorTypeSocket | DescriptorTypeOther;
13
+ /**
14
+ * The descriptor refers to a block device inode.
15
+ */
16
+ export interface DescriptorTypeBlockDevice {
17
+ tag: 'block-device',
18
+ }
19
+ /**
20
+ * The descriptor refers to a character device inode.
21
+ */
22
+ export interface DescriptorTypeCharacterDevice {
23
+ tag: 'character-device',
24
+ }
25
+ /**
26
+ * The descriptor refers to a directory inode.
27
+ */
28
+ export interface DescriptorTypeDirectory {
29
+ tag: 'directory',
30
+ }
31
+ /**
32
+ * The descriptor refers to a named pipe.
33
+ */
34
+ export interface DescriptorTypeFifo {
35
+ tag: 'fifo',
36
+ }
37
+ /**
38
+ * The file refers to a symbolic link inode.
39
+ */
40
+ export interface DescriptorTypeSymbolicLink {
41
+ tag: 'symbolic-link',
42
+ }
43
+ /**
44
+ * The descriptor refers to a regular file inode.
45
+ */
46
+ export interface DescriptorTypeRegularFile {
47
+ tag: 'regular-file',
48
+ }
49
+ /**
50
+ * The descriptor refers to a socket.
51
+ */
52
+ export interface DescriptorTypeSocket {
53
+ tag: 'socket',
54
+ }
55
+ /**
56
+ * The type of the descriptor or file is different from any of the
57
+ * other types specified.
58
+ */
59
+ export interface DescriptorTypeOther {
60
+ tag: 'other',
61
+ val: string | undefined,
62
+ }
63
+ /**
64
+ * Descriptor flags.
65
+ *
66
+ * Note: This was called `fdflags` in earlier versions of WASI.
67
+ */
68
+ export interface DescriptorFlags {
69
+ /**
70
+ * Read mode: Data can be read.
71
+ */
72
+ read?: boolean,
73
+ /**
74
+ * Write mode: Data can be written to.
75
+ */
76
+ write?: boolean,
77
+ /**
78
+ * Request that writes be performed according to synchronized I/O file
79
+ * integrity completion. The data stored in the file and the file's
80
+ * metadata are synchronized. This is similar to `O_SYNC` in POSIX.
81
+ *
82
+ * The precise semantics of this operation have not yet been defined for
83
+ * WASI. At this time, it should be interpreted as a request, and not a
84
+ * requirement.
85
+ */
86
+ fileIntegritySync?: boolean,
87
+ /**
88
+ * Request that writes be performed according to synchronized I/O data
89
+ * integrity completion. Only the data stored in the file is
90
+ * synchronized. This is similar to `O_DSYNC` in POSIX.
91
+ *
92
+ * The precise semantics of this operation have not yet been defined for
93
+ * WASI. At this time, it should be interpreted as a request, and not a
94
+ * requirement.
95
+ */
96
+ dataIntegritySync?: boolean,
97
+ /**
98
+ * Requests that reads be performed at the same level of integrity
99
+ * requested for writes. This is similar to `O_RSYNC` in POSIX.
100
+ *
101
+ * The precise semantics of this operation have not yet been defined for
102
+ * WASI. At this time, it should be interpreted as a request, and not a
103
+ * requirement.
104
+ */
105
+ requestedWriteSync?: boolean,
106
+ /**
107
+ * Mutating directories mode: Directory contents may be mutated.
108
+ *
109
+ * When this flag is unset on a descriptor, operations using the
110
+ * descriptor which would create, rename, delete, modify the data or
111
+ * metadata of filesystem objects, or obtain another handle which
112
+ * would permit any of those, shall fail with `error-code::read-only` if
113
+ * they would otherwise succeed.
114
+ *
115
+ * This may only be set on directories.
116
+ */
117
+ mutateDirectory?: boolean,
118
+ }
119
+ /**
120
+ * Flags determining the method of how paths are resolved.
121
+ */
122
+ export interface PathFlags {
123
+ /**
124
+ * As long as the resolved path corresponds to a symbolic link, it is
125
+ * expanded.
126
+ */
127
+ symlinkFollow?: boolean,
128
+ }
129
+ /**
130
+ * Open flags used by `open-at`.
131
+ */
132
+ export interface OpenFlags {
133
+ /**
134
+ * Create file if it does not exist, similar to `O_CREAT` in POSIX.
135
+ */
136
+ create?: boolean,
137
+ /**
138
+ * Fail if not a directory, similar to `O_DIRECTORY` in POSIX.
139
+ */
140
+ directory?: boolean,
141
+ /**
142
+ * Fail if file already exists, similar to `O_EXCL` in POSIX.
143
+ */
144
+ exclusive?: boolean,
145
+ /**
146
+ * Truncate file to size 0, similar to `O_TRUNC` in POSIX.
147
+ */
148
+ truncate?: boolean,
149
+ }
150
+ /**
151
+ * Number of hard links to an inode.
152
+ */
153
+ export type LinkCount = bigint;
154
+ /**
155
+ * File attributes.
156
+ *
157
+ * Note: This was called `filestat` in earlier versions of WASI.
158
+ */
159
+ export interface DescriptorStat {
160
+ /**
161
+ * File type.
162
+ */
163
+ type: DescriptorType,
164
+ /**
165
+ * Number of hard links to the file.
166
+ */
167
+ linkCount: LinkCount,
168
+ /**
169
+ * For regular files, the file size in bytes. For symbolic links, the
170
+ * length in bytes of the pathname contained in the symbolic link.
171
+ */
172
+ size: Filesize,
173
+ /**
174
+ * Last data access timestamp.
175
+ *
176
+ * If the `option` is none, the platform doesn't maintain an access
177
+ * timestamp for this file.
178
+ */
179
+ dataAccessTimestamp?: Instant,
180
+ /**
181
+ * Last data modification timestamp.
182
+ *
183
+ * If the `option` is none, the platform doesn't maintain a
184
+ * modification timestamp for this file.
185
+ */
186
+ dataModificationTimestamp?: Instant,
187
+ /**
188
+ * Last file status-change timestamp.
189
+ *
190
+ * If the `option` is none, the platform doesn't maintain a
191
+ * status-change timestamp for this file.
192
+ */
193
+ statusChangeTimestamp?: Instant,
194
+ }
195
+ /**
196
+ * When setting a timestamp, this gives the value to set it to.
197
+ */
198
+ export type NewTimestamp = NewTimestampNoChange | NewTimestampNow | NewTimestampTimestamp;
199
+ /**
200
+ * Leave the timestamp set to its previous value.
201
+ */
202
+ export interface NewTimestampNoChange {
203
+ tag: 'no-change',
204
+ }
205
+ /**
206
+ * Set the timestamp to the current time of the system clock associated
207
+ * with the filesystem.
208
+ */
209
+ export interface NewTimestampNow {
210
+ tag: 'now',
211
+ }
212
+ /**
213
+ * Set the timestamp to the given value.
214
+ */
215
+ export interface NewTimestampTimestamp {
216
+ tag: 'timestamp',
217
+ val: Instant,
218
+ }
219
+ /**
220
+ * A directory entry.
221
+ */
222
+ export interface DirectoryEntry {
223
+ /**
224
+ * The type of the file referred to by this directory entry.
225
+ */
226
+ type: DescriptorType,
227
+ /**
228
+ * The name of the object.
229
+ */
230
+ name: string,
231
+ }
232
+ /**
233
+ * Error codes returned by functions, similar to `errno` in POSIX.
234
+ * Not all of these error codes are returned by the functions provided by this
235
+ * API; some are used in higher-level library layers, and others are provided
236
+ * merely for alignment with POSIX.
237
+ */
238
+ export type ErrorCode = ErrorCodeAccess | ErrorCodeAlready | ErrorCodeBadDescriptor | ErrorCodeBusy | ErrorCodeDeadlock | ErrorCodeQuota | ErrorCodeExist | ErrorCodeFileTooLarge | ErrorCodeIllegalByteSequence | ErrorCodeInProgress | ErrorCodeInterrupted | ErrorCodeInvalid | ErrorCodeIo | ErrorCodeIsDirectory | ErrorCodeLoop | ErrorCodeTooManyLinks | ErrorCodeMessageSize | ErrorCodeNameTooLong | ErrorCodeNoDevice | ErrorCodeNoEntry | ErrorCodeNoLock | ErrorCodeInsufficientMemory | ErrorCodeInsufficientSpace | ErrorCodeNotDirectory | ErrorCodeNotEmpty | ErrorCodeNotRecoverable | ErrorCodeUnsupported | ErrorCodeNoTty | ErrorCodeNoSuchDevice | ErrorCodeOverflow | ErrorCodeNotPermitted | ErrorCodePipe | ErrorCodeReadOnly | ErrorCodeInvalidSeek | ErrorCodeTextFileBusy | ErrorCodeCrossDevice | ErrorCodeOther;
239
+ /**
240
+ * Permission denied, similar to `EACCES` in POSIX.
241
+ */
242
+ export interface ErrorCodeAccess {
243
+ tag: 'access',
244
+ }
245
+ /**
246
+ * Connection already in progress, similar to `EALREADY` in POSIX.
247
+ */
248
+ export interface ErrorCodeAlready {
249
+ tag: 'already',
250
+ }
251
+ /**
252
+ * Bad descriptor, similar to `EBADF` in POSIX.
253
+ */
254
+ export interface ErrorCodeBadDescriptor {
255
+ tag: 'bad-descriptor',
256
+ }
257
+ /**
258
+ * Device or resource busy, similar to `EBUSY` in POSIX.
259
+ */
260
+ export interface ErrorCodeBusy {
261
+ tag: 'busy',
262
+ }
263
+ /**
264
+ * Resource deadlock would occur, similar to `EDEADLK` in POSIX.
265
+ */
266
+ export interface ErrorCodeDeadlock {
267
+ tag: 'deadlock',
268
+ }
269
+ /**
270
+ * Storage quota exceeded, similar to `EDQUOT` in POSIX.
271
+ */
272
+ export interface ErrorCodeQuota {
273
+ tag: 'quota',
274
+ }
275
+ /**
276
+ * File exists, similar to `EEXIST` in POSIX.
277
+ */
278
+ export interface ErrorCodeExist {
279
+ tag: 'exist',
280
+ }
281
+ /**
282
+ * File too large, similar to `EFBIG` in POSIX.
283
+ */
284
+ export interface ErrorCodeFileTooLarge {
285
+ tag: 'file-too-large',
286
+ }
287
+ /**
288
+ * Illegal byte sequence, similar to `EILSEQ` in POSIX.
289
+ */
290
+ export interface ErrorCodeIllegalByteSequence {
291
+ tag: 'illegal-byte-sequence',
292
+ }
293
+ /**
294
+ * Operation in progress, similar to `EINPROGRESS` in POSIX.
295
+ */
296
+ export interface ErrorCodeInProgress {
297
+ tag: 'in-progress',
298
+ }
299
+ /**
300
+ * Interrupted function, similar to `EINTR` in POSIX.
301
+ */
302
+ export interface ErrorCodeInterrupted {
303
+ tag: 'interrupted',
304
+ }
305
+ /**
306
+ * Invalid argument, similar to `EINVAL` in POSIX.
307
+ */
308
+ export interface ErrorCodeInvalid {
309
+ tag: 'invalid',
310
+ }
311
+ /**
312
+ * I/O error, similar to `EIO` in POSIX.
313
+ */
314
+ export interface ErrorCodeIo {
315
+ tag: 'io',
316
+ }
317
+ /**
318
+ * Is a directory, similar to `EISDIR` in POSIX.
319
+ */
320
+ export interface ErrorCodeIsDirectory {
321
+ tag: 'is-directory',
322
+ }
323
+ /**
324
+ * Too many levels of symbolic links, similar to `ELOOP` in POSIX.
325
+ */
326
+ export interface ErrorCodeLoop {
327
+ tag: 'loop',
328
+ }
329
+ /**
330
+ * Too many links, similar to `EMLINK` in POSIX.
331
+ */
332
+ export interface ErrorCodeTooManyLinks {
333
+ tag: 'too-many-links',
334
+ }
335
+ /**
336
+ * Message too large, similar to `EMSGSIZE` in POSIX.
337
+ */
338
+ export interface ErrorCodeMessageSize {
339
+ tag: 'message-size',
340
+ }
341
+ /**
342
+ * Filename too long, similar to `ENAMETOOLONG` in POSIX.
343
+ */
344
+ export interface ErrorCodeNameTooLong {
345
+ tag: 'name-too-long',
346
+ }
347
+ /**
348
+ * No such device, similar to `ENODEV` in POSIX.
349
+ */
350
+ export interface ErrorCodeNoDevice {
351
+ tag: 'no-device',
352
+ }
353
+ /**
354
+ * No such file or directory, similar to `ENOENT` in POSIX.
355
+ */
356
+ export interface ErrorCodeNoEntry {
357
+ tag: 'no-entry',
358
+ }
359
+ /**
360
+ * No locks available, similar to `ENOLCK` in POSIX.
361
+ */
362
+ export interface ErrorCodeNoLock {
363
+ tag: 'no-lock',
364
+ }
365
+ /**
366
+ * Not enough space, similar to `ENOMEM` in POSIX.
367
+ */
368
+ export interface ErrorCodeInsufficientMemory {
369
+ tag: 'insufficient-memory',
370
+ }
371
+ /**
372
+ * No space left on device, similar to `ENOSPC` in POSIX.
373
+ */
374
+ export interface ErrorCodeInsufficientSpace {
375
+ tag: 'insufficient-space',
376
+ }
377
+ /**
378
+ * Not a directory or a symbolic link to a directory, similar to `ENOTDIR` in POSIX.
379
+ */
380
+ export interface ErrorCodeNotDirectory {
381
+ tag: 'not-directory',
382
+ }
383
+ /**
384
+ * Directory not empty, similar to `ENOTEMPTY` in POSIX.
385
+ */
386
+ export interface ErrorCodeNotEmpty {
387
+ tag: 'not-empty',
388
+ }
389
+ /**
390
+ * State not recoverable, similar to `ENOTRECOVERABLE` in POSIX.
391
+ */
392
+ export interface ErrorCodeNotRecoverable {
393
+ tag: 'not-recoverable',
394
+ }
395
+ /**
396
+ * Not supported, similar to `ENOTSUP` and `ENOSYS` in POSIX.
397
+ */
398
+ export interface ErrorCodeUnsupported {
399
+ tag: 'unsupported',
400
+ }
401
+ /**
402
+ * Inappropriate I/O control operation, similar to `ENOTTY` in POSIX.
403
+ */
404
+ export interface ErrorCodeNoTty {
405
+ tag: 'no-tty',
406
+ }
407
+ /**
408
+ * No such device or address, similar to `ENXIO` in POSIX.
409
+ */
410
+ export interface ErrorCodeNoSuchDevice {
411
+ tag: 'no-such-device',
412
+ }
413
+ /**
414
+ * Value too large to be stored in data type, similar to `EOVERFLOW` in POSIX.
415
+ */
416
+ export interface ErrorCodeOverflow {
417
+ tag: 'overflow',
418
+ }
419
+ /**
420
+ * Operation not permitted, similar to `EPERM` in POSIX.
421
+ */
422
+ export interface ErrorCodeNotPermitted {
423
+ tag: 'not-permitted',
424
+ }
425
+ /**
426
+ * Broken pipe, similar to `EPIPE` in POSIX.
427
+ */
428
+ export interface ErrorCodePipe {
429
+ tag: 'pipe',
430
+ }
431
+ /**
432
+ * Read-only file system, similar to `EROFS` in POSIX.
433
+ */
434
+ export interface ErrorCodeReadOnly {
435
+ tag: 'read-only',
436
+ }
437
+ /**
438
+ * Invalid seek, similar to `ESPIPE` in POSIX.
439
+ */
440
+ export interface ErrorCodeInvalidSeek {
441
+ tag: 'invalid-seek',
442
+ }
443
+ /**
444
+ * Text file busy, similar to `ETXTBSY` in POSIX.
445
+ */
446
+ export interface ErrorCodeTextFileBusy {
447
+ tag: 'text-file-busy',
448
+ }
449
+ /**
450
+ * Cross-device link, similar to `EXDEV` in POSIX.
451
+ */
452
+ export interface ErrorCodeCrossDevice {
453
+ tag: 'cross-device',
454
+ }
455
+ /**
456
+ * A catch-all for errors not captured by the existing variants.
457
+ * Implementations can use this to extend the error type without
458
+ * breaking existing code.
459
+ */
460
+ export interface ErrorCodeOther {
461
+ tag: 'other',
462
+ val: string | undefined,
463
+ }
464
+ /**
465
+ * File or memory access pattern advisory information.
466
+ * # Variants
467
+ *
468
+ * ## `"normal"`
469
+ *
470
+ * The application has no advice to give on its behavior with respect
471
+ * to the specified data.
472
+ * ## `"sequential"`
473
+ *
474
+ * The application expects to access the specified data sequentially
475
+ * from lower offsets to higher offsets.
476
+ * ## `"random"`
477
+ *
478
+ * The application expects to access the specified data in a random
479
+ * order.
480
+ * ## `"will-need"`
481
+ *
482
+ * The application expects to access the specified data in the near
483
+ * future.
484
+ * ## `"dont-need"`
485
+ *
486
+ * The application expects that it will not access the specified data
487
+ * in the near future.
488
+ * ## `"no-reuse"`
489
+ *
490
+ * The application expects to access the specified data once and then
491
+ * not reuse it thereafter.
492
+ */
493
+ export type Advice = 'normal' | 'sequential' | 'random' | 'will-need' | 'dont-need' | 'no-reuse';
494
+ /**
495
+ * A 128-bit hash value, split into parts because wasm doesn't have a
496
+ * 128-bit integer type.
497
+ */
498
+ export interface MetadataHashValue {
499
+ /**
500
+ * 64 bits of a 128-bit hash value.
501
+ */
502
+ lower: bigint,
503
+ /**
504
+ * Another 64 bits of a 128-bit hash value.
505
+ */
506
+ upper: bigint,
507
+ }
508
+ export type Result<T, E> = { tag: 'ok', val: T } | { tag: 'err', val: E };
509
+
510
+ export class Descriptor {
511
+ /**
512
+ * This type does not have a public constructor.
513
+ */
514
+ private constructor();
515
+ /**
516
+ * Return a stream for reading from a file.
517
+ *
518
+ * Multiple read, write, and append streams may be active on the same open
519
+ * file and they do not interfere with each other.
520
+ *
521
+ * This function returns a `stream` which provides the data received from the
522
+ * file, and a `future` providing additional error information in case an
523
+ * error is encountered.
524
+ *
525
+ * If no error is encountered, `stream.read` on the `stream` will return
526
+ * `read-status::closed` with no `error-context` and the future resolves to
527
+ * the value `ok`. If an error is encountered, `stream.read` on the
528
+ * `stream` returns `read-status::closed` with an `error-context` and the future
529
+ * resolves to `err` with an `error-code`.
530
+ *
531
+ * Note: This is similar to `pread` in POSIX.
532
+ */
533
+ readViaStream(offset: Filesize): [ReadableStream<number>, Promise<Result<void, ErrorCode>>];
534
+ /**
535
+ * Return a stream for writing to a file, if available.
536
+ *
537
+ * May fail with an error-code describing why the file cannot be written.
538
+ *
539
+ * It is valid to write past the end of a file; the file is extended to the
540
+ * extent of the write, with bytes between the previous end and the start of
541
+ * the write set to zero.
542
+ *
543
+ * This function returns once either full contents of the stream are
544
+ * written or an error is encountered.
545
+ *
546
+ * Note: This is similar to `pwrite` in POSIX.
547
+ */
548
+ writeViaStream(data: ReadableStream<number>, offset: Filesize): Promise<Result<void, ErrorCode>>;
549
+ /**
550
+ * Return a stream for appending to a file, if available.
551
+ *
552
+ * May fail with an error-code describing why the file cannot be appended.
553
+ *
554
+ * This function returns once either full contents of the stream are
555
+ * written or an error is encountered.
556
+ *
557
+ * Note: This is similar to `write` with `O_APPEND` in POSIX.
558
+ */
559
+ appendViaStream(data: ReadableStream<number>): Promise<Result<void, ErrorCode>>;
560
+ /**
561
+ * Provide file advisory information on a descriptor.
562
+ *
563
+ * This is similar to `posix_fadvise` in POSIX.
564
+ */
565
+ advise(offset: Filesize, length: Filesize, advice: Advice): Promise<void>;
566
+ /**
567
+ * Synchronize the data of a file to disk.
568
+ *
569
+ * This function succeeds with no effect if the file descriptor is not
570
+ * opened for writing.
571
+ *
572
+ * Note: This is similar to `fdatasync` in POSIX.
573
+ */
574
+ syncData(): Promise<void>;
575
+ /**
576
+ * Get flags associated with a descriptor.
577
+ *
578
+ * Note: This returns similar flags to `fcntl(fd, F_GETFL)` in POSIX.
579
+ *
580
+ * Note: This returns the value that was the `fs_flags` value returned
581
+ * from `fdstat_get` in earlier versions of WASI.
582
+ */
583
+ getFlags(): Promise<DescriptorFlags>;
584
+ /**
585
+ * Get the dynamic type of a descriptor.
586
+ *
587
+ * Note: This returns the same value as the `type` field of the `fd-stat`
588
+ * returned by `stat`, `stat-at` and similar.
589
+ *
590
+ * Note: This returns similar flags to the `st_mode & S_IFMT` value provided
591
+ * by `fstat` in POSIX.
592
+ *
593
+ * Note: This returns the value that was the `fs_filetype` value returned
594
+ * from `fdstat_get` in earlier versions of WASI.
595
+ */
596
+ getType(): Promise<DescriptorType>;
597
+ /**
598
+ * Adjust the size of an open file. If this increases the file's size, the
599
+ * extra bytes are filled with zeros.
600
+ *
601
+ * Note: This was called `fd_filestat_set_size` in earlier versions of WASI.
602
+ */
603
+ setSize(size: Filesize): Promise<void>;
604
+ /**
605
+ * Adjust the timestamps of an open file or directory.
606
+ *
607
+ * Note: This is similar to `futimens` in POSIX.
608
+ *
609
+ * Note: This was called `fd_filestat_set_times` in earlier versions of WASI.
610
+ */
611
+ setTimes(dataAccessTimestamp: NewTimestamp, dataModificationTimestamp: NewTimestamp): Promise<void>;
612
+ /**
613
+ * Read directory entries from a directory.
614
+ *
615
+ * On filesystems where directories contain entries referring to themselves
616
+ * and their parents, often named `.` and `..` respectively, these entries
617
+ * are omitted.
618
+ *
619
+ * This always returns a new stream which starts at the beginning of the
620
+ * directory. Multiple streams may be active on the same directory, and they
621
+ * do not interfere with each other.
622
+ *
623
+ * This function returns a future, which will resolve to an error code if
624
+ * reading full contents of the directory fails.
625
+ */
626
+ readDirectory(): [ReadableStream<DirectoryEntry>, Promise<Result<void, ErrorCode>>];
627
+ /**
628
+ * Synchronize the data and metadata of a file to disk.
629
+ *
630
+ * This function succeeds with no effect if the file descriptor is not
631
+ * opened for writing.
632
+ *
633
+ * Note: This is similar to `fsync` in POSIX.
634
+ */
635
+ sync(): Promise<void>;
636
+ /**
637
+ * Create a directory.
638
+ *
639
+ * Note: This is similar to `mkdirat` in POSIX.
640
+ */
641
+ createDirectoryAt(path: string): Promise<void>;
642
+ /**
643
+ * Return the attributes of an open file or directory.
644
+ *
645
+ * Note: This is similar to `fstat` in POSIX, except that it does not return
646
+ * device and inode information. For testing whether two descriptors refer to
647
+ * the same underlying filesystem object, use `is-same-object`. To obtain
648
+ * additional data that can be used do determine whether a file has been
649
+ * modified, use `metadata-hash`.
650
+ *
651
+ * Note: This was called `fd_filestat_get` in earlier versions of WASI.
652
+ */
653
+ stat(): Promise<DescriptorStat>;
654
+ /**
655
+ * Return the attributes of a file or directory.
656
+ *
657
+ * Note: This is similar to `fstatat` in POSIX, except that it does not
658
+ * return device and inode information. See the `stat` description for a
659
+ * discussion of alternatives.
660
+ *
661
+ * Note: This was called `path_filestat_get` in earlier versions of WASI.
662
+ */
663
+ statAt(pathFlags: PathFlags, path: string): Promise<DescriptorStat>;
664
+ /**
665
+ * Adjust the timestamps of a file or directory.
666
+ *
667
+ * Note: This is similar to `utimensat` in POSIX.
668
+ *
669
+ * Note: This was called `path_filestat_set_times` in earlier versions of
670
+ * WASI.
671
+ */
672
+ setTimesAt(pathFlags: PathFlags, path: string, dataAccessTimestamp: NewTimestamp, dataModificationTimestamp: NewTimestamp): Promise<void>;
673
+ /**
674
+ * Create a hard link.
675
+ *
676
+ * Fails with `error-code::no-entry` if the old path does not exist,
677
+ * with `error-code::exist` if the new path already exists, and
678
+ * `error-code::not-permitted` if the old path is not a file.
679
+ *
680
+ * Note: This is similar to `linkat` in POSIX.
681
+ */
682
+ linkAt(oldPathFlags: PathFlags, oldPath: string, newDescriptor: Descriptor, newPath: string): Promise<void>;
683
+ /**
684
+ * Open a file or directory.
685
+ *
686
+ * If `flags` contains `descriptor-flags::mutate-directory`, and the base
687
+ * descriptor doesn't have `descriptor-flags::mutate-directory` set,
688
+ * `open-at` fails with `error-code::read-only`.
689
+ *
690
+ * If `flags` contains `write` or `mutate-directory`, or `open-flags`
691
+ * contains `truncate` or `create`, and the base descriptor doesn't have
692
+ * `descriptor-flags::mutate-directory` set, `open-at` fails with
693
+ * `error-code::read-only`.
694
+ *
695
+ * Note: This is similar to `openat` in POSIX.
696
+ */
697
+ openAt(pathFlags: PathFlags, path: string, openFlags: OpenFlags, flags: DescriptorFlags): Promise<Descriptor>;
698
+ /**
699
+ * Read the contents of a symbolic link.
700
+ *
701
+ * If the contents contain an absolute or rooted path in the underlying
702
+ * filesystem, this function fails with `error-code::not-permitted`.
703
+ *
704
+ * Note: This is similar to `readlinkat` in POSIX.
705
+ */
706
+ readlinkAt(path: string): Promise<string>;
707
+ /**
708
+ * Remove a directory.
709
+ *
710
+ * Return `error-code::not-empty` if the directory is not empty.
711
+ *
712
+ * Note: This is similar to `unlinkat(fd, path, AT_REMOVEDIR)` in POSIX.
713
+ */
714
+ removeDirectoryAt(path: string): Promise<void>;
715
+ /**
716
+ * Rename a filesystem object.
717
+ *
718
+ * Note: This is similar to `renameat` in POSIX.
719
+ */
720
+ renameAt(oldPath: string, newDescriptor: Descriptor, newPath: string): Promise<void>;
721
+ /**
722
+ * Create a symbolic link (also known as a "symlink").
723
+ *
724
+ * If `old-path` starts with `/`, the function fails with
725
+ * `error-code::not-permitted`.
726
+ *
727
+ * Note: This is similar to `symlinkat` in POSIX.
728
+ */
729
+ symlinkAt(oldPath: string, newPath: string): Promise<void>;
730
+ /**
731
+ * Unlink a filesystem object that is not a directory.
732
+ *
733
+ * This is similar to `unlinkat(fd, path, 0)` in POSIX.
734
+ *
735
+ * Error returns are as specified by POSIX.
736
+ *
737
+ * If the filesystem object is a directory, `error-code::access` or
738
+ * `error-code::is-directory` may be returned instead of the
739
+ * POSIX-specified `error-code::not-permitted`.
740
+ */
741
+ unlinkFileAt(path: string): Promise<void>;
742
+ /**
743
+ * Test whether two descriptors refer to the same filesystem object.
744
+ *
745
+ * In POSIX, this corresponds to testing whether the two descriptors have the
746
+ * same device (`st_dev`) and inode (`st_ino` or `d_ino`) numbers.
747
+ * wasi-filesystem does not expose device and inode numbers, so this function
748
+ * may be used instead.
749
+ */
750
+ isSameObject(other: Descriptor): Promise<boolean>;
751
+ /**
752
+ * Return a hash of the metadata associated with a filesystem object referred
753
+ * to by a descriptor.
754
+ *
755
+ * This returns a hash of the last-modification timestamp and file size, and
756
+ * may also include the inode number, device number, birth timestamp, and
757
+ * other metadata fields that may change when the file is modified or
758
+ * replaced. It may also include a secret value chosen by the
759
+ * implementation and not otherwise exposed.
760
+ *
761
+ * Implementations are encouraged to provide the following properties:
762
+ *
763
+ * - If the file is not modified or replaced, the computed hash value should
764
+ * usually not change.
765
+ * - If the object is modified or replaced, the computed hash value should
766
+ * usually change.
767
+ * - The inputs to the hash should not be easily computable from the
768
+ * computed hash.
769
+ *
770
+ * However, none of these is required.
771
+ */
772
+ metadataHash(): Promise<MetadataHashValue>;
773
+ /**
774
+ * Return a hash of the metadata associated with a filesystem object referred
775
+ * to by a directory descriptor and a relative path.
776
+ *
777
+ * This performs the same hash computation as `metadata-hash`.
778
+ */
779
+ metadataHashAt(pathFlags: PathFlags, path: string): Promise<MetadataHashValue>;
780
+ }