@bytecodealliance/preview2-shim 0.0.12 → 0.0.14

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 (91) hide show
  1. package/README.md +2 -2
  2. package/lib/browser/cli.js +87 -0
  3. package/lib/browser/filesystem.js +216 -18
  4. package/lib/browser/http.js +4 -7
  5. package/lib/browser/index.js +2 -2
  6. package/lib/browser/io.js +76 -17
  7. package/lib/browser/logging.js +2 -2
  8. package/lib/browser/poll.js +48 -4
  9. package/lib/http/error.js +1 -1
  10. package/lib/http/make-request.js +3 -2
  11. package/lib/http/wasi-http.js +52 -40
  12. package/lib/nodejs/cli.js +75 -0
  13. package/lib/nodejs/filesystem.js +93 -3
  14. package/lib/nodejs/http.js +4 -7
  15. package/lib/nodejs/index.js +2 -2
  16. package/lib/nodejs/logging.js +2 -2
  17. package/package.json +1 -1
  18. package/types/{imports/environment.d.ts → exports/wasi-cli-environment.d.ts} +6 -1
  19. package/types/{imports/exit.d.ts → exports/wasi-cli-exit.d.ts} +2 -2
  20. package/types/exports/wasi-cli-run.d.ts +6 -0
  21. package/types/exports/wasi-cli-stderr.d.ts +5 -0
  22. package/types/exports/wasi-cli-stdin.d.ts +5 -0
  23. package/types/exports/wasi-cli-stdout.d.ts +5 -0
  24. package/types/exports/wasi-cli-terminal-input.d.ts +13 -0
  25. package/types/exports/wasi-cli-terminal-output.d.ts +13 -0
  26. package/types/exports/wasi-cli-terminal-stderr.d.ts +9 -0
  27. package/types/exports/wasi-cli-terminal-stdin.d.ts +9 -0
  28. package/types/exports/wasi-cli-terminal-stdout.d.ts +9 -0
  29. package/types/{imports/monotonic-clock.d.ts → exports/wasi-clocks-monotonic-clock.d.ts} +2 -2
  30. package/types/{imports/timezone.d.ts → exports/wasi-clocks-timezone.d.ts} +15 -15
  31. package/types/{imports/wall-clock.d.ts → exports/wasi-clocks-wall-clock.d.ts} +1 -1
  32. package/types/exports/wasi-filesystem-preopens.d.ts +8 -0
  33. package/types/{imports/filesystem.d.ts → exports/wasi-filesystem-types.d.ts} +293 -307
  34. package/types/exports/wasi-http-incoming-handler.d.ts +3 -3
  35. package/types/exports/wasi-http-outgoing-handler.d.ts +9 -0
  36. package/types/{imports/types.d.ts → exports/wasi-http-types.d.ts} +40 -41
  37. package/types/exports/wasi-io-streams.d.ts +220 -0
  38. package/types/{imports/poll.d.ts → exports/wasi-poll-poll.d.ts} +6 -8
  39. package/types/{imports/insecure-seed.d.ts → exports/wasi-random-insecure-seed.d.ts} +1 -1
  40. package/types/exports/wasi-random-insecure.d.ts +20 -0
  41. package/types/exports/wasi-random-random.d.ts +22 -0
  42. package/types/{imports/instance-network.d.ts → exports/wasi-sockets-instance-network.d.ts} +2 -2
  43. package/types/{imports/ip-name-lookup.d.ts → exports/wasi-sockets-ip-name-lookup.d.ts} +9 -9
  44. package/types/{imports/network.d.ts → exports/wasi-sockets-network.d.ts} +43 -75
  45. package/types/{imports/tcp-create-socket.d.ts → exports/wasi-sockets-tcp-create-socket.d.ts} +5 -5
  46. package/types/{imports/tcp.d.ts → exports/wasi-sockets-tcp.d.ts} +38 -38
  47. package/types/{imports/udp-create-socket.d.ts → exports/wasi-sockets-udp-create-socket.d.ts} +5 -5
  48. package/types/{imports/udp.d.ts → exports/wasi-sockets-udp.d.ts} +41 -32
  49. package/types/imports/wasi-cli-environment.d.ts +22 -0
  50. package/types/imports/wasi-cli-exit.d.ts +7 -0
  51. package/types/imports/wasi-cli-stderr.d.ts +5 -0
  52. package/types/imports/wasi-cli-stdin.d.ts +5 -0
  53. package/types/imports/wasi-cli-stdout.d.ts +5 -0
  54. package/types/imports/wasi-cli-terminal-input.d.ts +13 -0
  55. package/types/imports/wasi-cli-terminal-output.d.ts +13 -0
  56. package/types/imports/wasi-cli-terminal-stderr.d.ts +9 -0
  57. package/types/imports/wasi-cli-terminal-stdin.d.ts +9 -0
  58. package/types/imports/wasi-cli-terminal-stdout.d.ts +9 -0
  59. package/types/imports/wasi-clocks-monotonic-clock.d.ts +24 -0
  60. package/types/imports/wasi-clocks-timezone.d.ts +71 -0
  61. package/types/imports/wasi-clocks-wall-clock.d.ts +31 -0
  62. package/types/imports/wasi-filesystem-preopens.d.ts +8 -0
  63. package/types/imports/wasi-filesystem-types.d.ts +843 -0
  64. package/types/imports/wasi-http-outgoing-handler.d.ts +9 -0
  65. package/types/imports/wasi-http-types.d.ts +118 -0
  66. package/types/imports/wasi-io-streams.d.ts +220 -0
  67. package/types/imports/wasi-poll-poll.d.ts +39 -0
  68. package/types/imports/wasi-random-insecure-seed.d.ts +22 -0
  69. package/types/imports/{insecure.d.ts → wasi-random-insecure.d.ts} +1 -1
  70. package/types/imports/{random.d.ts → wasi-random-random.d.ts} +1 -1
  71. package/types/imports/wasi-sockets-instance-network.d.ts +8 -0
  72. package/types/imports/wasi-sockets-ip-name-lookup.d.ts +76 -0
  73. package/types/imports/wasi-sockets-network.d.ts +180 -0
  74. package/types/imports/wasi-sockets-tcp-create-socket.d.ts +33 -0
  75. package/types/imports/wasi-sockets-tcp.d.ts +285 -0
  76. package/types/imports/wasi-sockets-udp-create-socket.d.ts +33 -0
  77. package/types/imports/wasi-sockets-udp.d.ts +228 -0
  78. package/types/wasi-cli-command.d.ts +29 -0
  79. package/types/wasi-http-proxy.d.ts +13 -0
  80. package/lib/browser/cli-base.js +0 -48
  81. package/lib/nodejs/cli-base.js +0 -99
  82. package/types/imports/handler.d.ts +0 -40
  83. package/types/imports/outgoing-handler.d.ts +0 -9
  84. package/types/imports/preopens.d.ts +0 -12
  85. package/types/imports/stderr.d.ts +0 -5
  86. package/types/imports/stdin.d.ts +0 -5
  87. package/types/imports/stdout.d.ts +0 -5
  88. package/types/imports/streams.d.ts +0 -180
  89. package/types/wasi-command.d.ts +0 -23
  90. package/types/wasi-proxy.d.ts +0 -10
  91. package/types/wasi-reactor.d.ts +0 -23
@@ -1,33 +1,39 @@
1
- export namespace ImportsFilesystem {
1
+ export namespace WasiFilesystemTypes {
2
2
  /**
3
- * Return a stream for reading from a file.
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.
4
6
  *
5
7
  * Multiple read, write, and append streams may be active on the same open
6
8
  * file and they do not interfere with each other.
7
9
  *
8
- * Note: This allows using `wasi:io/streams.read`, which is similar to `read` in POSIX.
10
+ * Note: This allows using `read-stream`, which is similar to `read` in POSIX.
9
11
  */
10
- export function readViaStream(this: Descriptor, offset: Filesize): InputStream;
12
+ export function readViaStream(this_: Descriptor, offset: Filesize): InputStream;
11
13
  /**
12
- * Return a stream for writing to a file.
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.
13
17
  *
14
- * Note: This allows using `wasi:io/streams.write`, which is similar to `write` in
18
+ * Note: This allows using `write-stream`, which is similar to `write` in
15
19
  * POSIX.
16
20
  */
17
- export function writeViaStream(this: Descriptor, offset: Filesize): OutputStream;
21
+ export function writeViaStream(this_: Descriptor, offset: Filesize): OutputStream;
18
22
  /**
19
- * Return a stream for appending to a file.
23
+ * Return a stream for appending to a file, if available.
20
24
  *
21
- * Note: This allows using `wasi:io/streams.write`, which is similar to `write` with
25
+ * May fail with an error-code describing why the file cannot be appended.
26
+ *
27
+ * Note: This allows using `write-stream`, which is similar to `write` with
22
28
  * `O_APPEND` in in POSIX.
23
29
  */
24
- export function appendViaStream(this: Descriptor): OutputStream;
30
+ export function appendViaStream(this_: Descriptor): OutputStream;
25
31
  /**
26
32
  * Provide file advisory information on a descriptor.
27
33
  *
28
34
  * This is similar to `posix_fadvise` in POSIX.
29
35
  */
30
- export function advise(this: Descriptor, offset: Filesize, length: Filesize, advice: Advice): void;
36
+ export function advise(this_: Descriptor, offset: Filesize, length: Filesize, advice: Advice): void;
31
37
  /**
32
38
  * Synchronize the data of a file to disk.
33
39
  *
@@ -36,7 +42,7 @@ export namespace ImportsFilesystem {
36
42
  *
37
43
  * Note: This is similar to `fdatasync` in POSIX.
38
44
  */
39
- export function syncData(this: Descriptor): void;
45
+ export function syncData(this_: Descriptor): void;
40
46
  /**
41
47
  * Get flags associated with a descriptor.
42
48
  *
@@ -45,7 +51,7 @@ export namespace ImportsFilesystem {
45
51
  * Note: This returns the value that was the `fs_flags` value returned
46
52
  * from `fdstat_get` in earlier versions of WASI.
47
53
  */
48
- export function getFlags(this: Descriptor): DescriptorFlags;
54
+ export function getFlags(this_: Descriptor): DescriptorFlags;
49
55
  /**
50
56
  * Get the dynamic type of a descriptor.
51
57
  *
@@ -58,14 +64,14 @@ export namespace ImportsFilesystem {
58
64
  * Note: This returns the value that was the `fs_filetype` value returned
59
65
  * from `fdstat_get` in earlier versions of WASI.
60
66
  */
61
- export function getType(this: Descriptor): DescriptorType;
67
+ export function getType(this_: Descriptor): DescriptorType;
62
68
  /**
63
69
  * Adjust the size of an open file. If this increases the file's size, the
64
70
  * extra bytes are filled with zeros.
65
71
  *
66
72
  * Note: This was called `fd_filestat_set_size` in earlier versions of WASI.
67
73
  */
68
- export function setSize(this: Descriptor, size: Filesize): void;
74
+ export function setSize(this_: Descriptor, size: Filesize): void;
69
75
  /**
70
76
  * Adjust the timestamps of an open file or directory.
71
77
  *
@@ -73,7 +79,7 @@ export namespace ImportsFilesystem {
73
79
  *
74
80
  * Note: This was called `fd_filestat_set_times` in earlier versions of WASI.
75
81
  */
76
- export function setTimes(this: Descriptor, dataAccessTimestamp: NewTimestamp, dataModificationTimestamp: NewTimestamp): void;
82
+ export function setTimes(this_: Descriptor, dataAccessTimestamp: NewTimestamp, dataModificationTimestamp: NewTimestamp): void;
77
83
  /**
78
84
  * Read from a descriptor, without using and updating the descriptor's offset.
79
85
  *
@@ -87,7 +93,7 @@ export namespace ImportsFilesystem {
87
93
  *
88
94
  * Note: This is similar to `pread` in POSIX.
89
95
  */
90
- export function read(this: Descriptor, length: Filesize, offset: Filesize): [Uint8Array | ArrayBuffer, boolean];
96
+ export function read(this_: Descriptor, length: Filesize, offset: Filesize): [Uint8Array, boolean];
91
97
  /**
92
98
  * Write to a descriptor, without using and updating the descriptor's offset.
93
99
  *
@@ -99,7 +105,7 @@ export namespace ImportsFilesystem {
99
105
  *
100
106
  * Note: This is similar to `pwrite` in POSIX.
101
107
  */
102
- export function write(this: Descriptor, buffer: Uint8Array, offset: Filesize): Filesize;
108
+ export function write(this_: Descriptor, buffer: Uint8Array | ArrayBuffer, offset: Filesize): Filesize;
103
109
  /**
104
110
  * Read directory entries from a directory.
105
111
  *
@@ -111,7 +117,7 @@ export namespace ImportsFilesystem {
111
117
  * directory. Multiple streams may be active on the same directory, and they
112
118
  * do not interfere with each other.
113
119
  */
114
- export function readDirectory(this: Descriptor): DirectoryEntryStream;
120
+ export function readDirectory(this_: Descriptor): DirectoryEntryStream;
115
121
  /**
116
122
  * Synchronize the data and metadata of a file to disk.
117
123
  *
@@ -120,29 +126,35 @@ export namespace ImportsFilesystem {
120
126
  *
121
127
  * Note: This is similar to `fsync` in POSIX.
122
128
  */
123
- export function sync(this: Descriptor): void;
129
+ export function sync(this_: Descriptor): void;
124
130
  /**
125
131
  * Create a directory.
126
132
  *
127
133
  * Note: This is similar to `mkdirat` in POSIX.
128
134
  */
129
- export function createDirectoryAt(this: Descriptor, path: string): void;
135
+ export function createDirectoryAt(this_: Descriptor, path: string): void;
130
136
  /**
131
137
  * Return the attributes of an open file or directory.
132
138
  *
133
- * Note: This is similar to `fstat` in POSIX.
139
+ * Note: This is similar to `fstat` in POSIX, except that it does not return
140
+ * device and inode information. For testing whether two descriptors refer to
141
+ * the same underlying filesystem object, use `is-same-object`. To obtain
142
+ * additional data that can be used do determine whether a file has been
143
+ * modified, use `metadata-hash`.
134
144
  *
135
145
  * Note: This was called `fd_filestat_get` in earlier versions of WASI.
136
146
  */
137
- export function stat(this: Descriptor): DescriptorStat;
147
+ export function stat(this_: Descriptor): DescriptorStat;
138
148
  /**
139
149
  * Return the attributes of a file or directory.
140
150
  *
141
- * Note: This is similar to `fstatat` in POSIX.
151
+ * Note: This is similar to `fstatat` in POSIX, except that it does not
152
+ * return device and inode information. See the `stat` description for a
153
+ * discussion of alternatives.
142
154
  *
143
155
  * Note: This was called `path_filestat_get` in earlier versions of WASI.
144
156
  */
145
- export function statAt(this: Descriptor, pathFlags: PathFlags, path: string): DescriptorStat;
157
+ export function statAt(this_: Descriptor, pathFlags: PathFlags, path: string): DescriptorStat;
146
158
  /**
147
159
  * Adjust the timestamps of a file or directory.
148
160
  *
@@ -151,13 +163,13 @@ export namespace ImportsFilesystem {
151
163
  * Note: This was called `path_filestat_set_times` in earlier versions of
152
164
  * WASI.
153
165
  */
154
- export function setTimesAt(this: Descriptor, pathFlags: PathFlags, path: string, dataAccessTimestamp: NewTimestamp, dataModificationTimestamp: NewTimestamp): void;
166
+ export function setTimesAt(this_: Descriptor, pathFlags: PathFlags, path: string, dataAccessTimestamp: NewTimestamp, dataModificationTimestamp: NewTimestamp): void;
155
167
  /**
156
168
  * Create a hard link.
157
169
  *
158
170
  * Note: This is similar to `linkat` in POSIX.
159
171
  */
160
- export function linkAt(this: Descriptor, oldPathFlags: PathFlags, oldPath: string, newDescriptor: Descriptor, newPath: string): void;
172
+ export function linkAt(this_: Descriptor, oldPathFlags: PathFlags, oldPath: string, newDescriptor: Descriptor, newPath: string): void;
161
173
  /**
162
174
  * Open a file or directory.
163
175
  *
@@ -178,7 +190,7 @@ export namespace ImportsFilesystem {
178
190
  *
179
191
  * Note: This is similar to `openat` in POSIX.
180
192
  */
181
- export function openAt(this: Descriptor, pathFlags: PathFlags, path: string, openFlags: OpenFlags, flags: DescriptorFlags, modes: Modes): Descriptor;
193
+ export function openAt(this_: Descriptor, pathFlags: PathFlags, path: string, openFlags: OpenFlags, flags: DescriptorFlags, modes: Modes): Descriptor;
182
194
  /**
183
195
  * Read the contents of a symbolic link.
184
196
  *
@@ -187,7 +199,7 @@ export namespace ImportsFilesystem {
187
199
  *
188
200
  * Note: This is similar to `readlinkat` in POSIX.
189
201
  */
190
- export function readlinkAt(this: Descriptor, path: string): string;
202
+ export function readlinkAt(this_: Descriptor, path: string): string;
191
203
  /**
192
204
  * Remove a directory.
193
205
  *
@@ -195,13 +207,13 @@ export namespace ImportsFilesystem {
195
207
  *
196
208
  * Note: This is similar to `unlinkat(fd, path, AT_REMOVEDIR)` in POSIX.
197
209
  */
198
- export function removeDirectoryAt(this: Descriptor, path: string): void;
210
+ export function removeDirectoryAt(this_: Descriptor, path: string): void;
199
211
  /**
200
212
  * Rename a filesystem object.
201
213
  *
202
214
  * Note: This is similar to `renameat` in POSIX.
203
215
  */
204
- export function renameAt(this: Descriptor, oldPath: string, newDescriptor: Descriptor, newPath: string): void;
216
+ export function renameAt(this_: Descriptor, oldPath: string, newDescriptor: Descriptor, newPath: string): void;
205
217
  /**
206
218
  * Create a symbolic link (also known as a "symlink").
207
219
  *
@@ -210,7 +222,7 @@ export namespace ImportsFilesystem {
210
222
  *
211
223
  * Note: This is similar to `symlinkat` in POSIX.
212
224
  */
213
- export function symlinkAt(this: Descriptor, oldPath: string, newPath: string): void;
225
+ export function symlinkAt(this_: Descriptor, oldPath: string, newPath: string): void;
214
226
  /**
215
227
  * Check accessibility of a filesystem path.
216
228
  *
@@ -223,14 +235,14 @@ export namespace ImportsFilesystem {
223
235
  *
224
236
  * Note: This is similar to `faccessat` with the `AT_EACCESS` flag in POSIX.
225
237
  */
226
- export function accessAt(this: Descriptor, pathFlags: PathFlags, path: string, type: AccessType): void;
238
+ export function accessAt(this_: Descriptor, pathFlags: PathFlags, path: string, type: AccessType): void;
227
239
  /**
228
240
  * Unlink a filesystem object that is not a directory.
229
241
  *
230
242
  * Return `error-code::is-directory` if the path refers to a directory.
231
243
  * Note: This is similar to `unlinkat(fd, path, 0)` in POSIX.
232
244
  */
233
- export function unlinkFileAt(this: Descriptor, path: string): void;
245
+ export function unlinkFileAt(this_: Descriptor, path: string): void;
234
246
  /**
235
247
  * Change the permissions of a filesystem object that is not a directory.
236
248
  *
@@ -239,7 +251,7 @@ export namespace ImportsFilesystem {
239
251
  *
240
252
  * Note: This is similar to `fchmodat` in POSIX.
241
253
  */
242
- export function changeFilePermissionsAt(this: Descriptor, pathFlags: PathFlags, path: string, modes: Modes): void;
254
+ export function changeFilePermissionsAt(this_: Descriptor, pathFlags: PathFlags, path: string, modes: Modes): void;
243
255
  /**
244
256
  * Change the permissions of a directory.
245
257
  *
@@ -252,7 +264,7 @@ export namespace ImportsFilesystem {
252
264
  *
253
265
  * Note: This is similar to `fchmodat` in POSIX.
254
266
  */
255
- export function changeDirectoryPermissionsAt(this: Descriptor, pathFlags: PathFlags, path: string, modes: Modes): void;
267
+ export function changeDirectoryPermissionsAt(this_: Descriptor, pathFlags: PathFlags, path: string, modes: Modes): void;
256
268
  /**
257
269
  * Request a shared advisory lock for an open file.
258
270
  *
@@ -275,7 +287,7 @@ export namespace ImportsFilesystem {
275
287
  *
276
288
  * Note: This is similar to `flock(fd, LOCK_SH)` in Unix.
277
289
  */
278
- export function lockShared(this: Descriptor): void;
290
+ export function lockShared(this_: Descriptor): void;
279
291
  /**
280
292
  * Request an exclusive advisory lock for an open file.
281
293
  *
@@ -300,7 +312,7 @@ export namespace ImportsFilesystem {
300
312
  *
301
313
  * Note: This is similar to `flock(fd, LOCK_EX)` in Unix.
302
314
  */
303
- export function lockExclusive(this: Descriptor): void;
315
+ export function lockExclusive(this_: Descriptor): void;
304
316
  /**
305
317
  * Request a shared advisory lock for an open file.
306
318
  *
@@ -324,7 +336,7 @@ export namespace ImportsFilesystem {
324
336
  *
325
337
  * Note: This is similar to `flock(fd, LOCK_SH | LOCK_NB)` in Unix.
326
338
  */
327
- export function tryLockShared(this: Descriptor): void;
339
+ export function tryLockShared(this_: Descriptor): void;
328
340
  /**
329
341
  * Request an exclusive advisory lock for an open file.
330
342
  *
@@ -350,34 +362,165 @@ export namespace ImportsFilesystem {
350
362
  *
351
363
  * Note: This is similar to `flock(fd, LOCK_EX | LOCK_NB)` in Unix.
352
364
  */
353
- export function tryLockExclusive(this: Descriptor): void;
365
+ export function tryLockExclusive(this_: Descriptor): void;
354
366
  /**
355
367
  * Release a shared or exclusive lock on an open file.
356
368
  *
357
369
  * Note: This is similar to `flock(fd, LOCK_UN)` in Unix.
358
370
  */
359
- export function unlock(this: Descriptor): void;
371
+ export function unlock(this_: Descriptor): void;
360
372
  /**
361
373
  * Dispose of the specified `descriptor`, after which it may no longer
362
374
  * be used.
363
375
  */
364
- export function dropDescriptor(this: Descriptor): void;
376
+ export function dropDescriptor(this_: Descriptor): void;
365
377
  /**
366
378
  * Read a single directory entry from a `directory-entry-stream`.
367
379
  */
368
- export function readDirectoryEntry(this: DirectoryEntryStream): DirectoryEntry | null;
380
+ export function readDirectoryEntry(this_: DirectoryEntryStream): DirectoryEntry | null;
369
381
  /**
370
382
  * Dispose of the specified `directory-entry-stream`, after which it may no longer
371
383
  * be used.
372
384
  */
373
- export function dropDirectoryEntryStream(this: DirectoryEntryStream): void;
385
+ export function dropDirectoryEntryStream(this_: DirectoryEntryStream): void;
386
+ /**
387
+ * Test whether two descriptors refer to the same filesystem object.
388
+ *
389
+ * In POSIX, this corresponds to testing whether the two descriptors have the
390
+ * same device (`st_dev`) and inode (`st_ino` or `d_ino`) numbers.
391
+ * wasi-filesystem does not expose device and inode numbers, so this function
392
+ * may be used instead.
393
+ */
394
+ export function isSameObject(this_: Descriptor, other: Descriptor): boolean;
395
+ /**
396
+ * Return a hash of the metadata associated with a filesystem object referred
397
+ * to by a descriptor.
398
+ *
399
+ * This returns a hash of the last-modification timestamp and file size, and
400
+ * may also include the inode number, device number, birth timestamp, and
401
+ * other metadata fields that may change when the file is modified or
402
+ * replaced. It may also include a secret value chosen by the
403
+ * implementation and not otherwise exposed.
404
+ *
405
+ * Implementations are encourated to provide the following properties:
406
+ *
407
+ * - If the file is not modified or replaced, the computed hash value should
408
+ * usually not change.
409
+ * - If the object is modified or replaced, the computed hash value should
410
+ * usually change.
411
+ * - The inputs to the hash should not be easily computable from the
412
+ * computed hash.
413
+ *
414
+ * However, none of these is required.
415
+ */
416
+ export function metadataHash(this_: Descriptor): MetadataHashValue;
417
+ /**
418
+ * Return a hash of the metadata associated with a filesystem object referred
419
+ * to by a directory descriptor and a relative path.
420
+ *
421
+ * This performs the same hash computation as `metadata-hash`.
422
+ */
423
+ export function metadataHashAt(this_: Descriptor, pathFlags: PathFlags, path: string): MetadataHashValue;
374
424
  }
375
- import type { InputStream } from '../imports/streams';
425
+ import type { InputStream } from '../exports/wasi-io-streams';
376
426
  export { InputStream };
377
- import type { OutputStream } from '../imports/streams';
427
+ import type { OutputStream } from '../exports/wasi-io-streams';
378
428
  export { OutputStream };
379
- import type { Datetime } from '../imports/wall-clock';
429
+ import type { Datetime } from '../exports/wasi-clocks-wall-clock';
380
430
  export { Datetime };
431
+ /**
432
+ * File size or length of a region within a file.
433
+ */
434
+ export type Filesize = bigint;
435
+ /**
436
+ * The type of a filesystem object referenced by a descriptor.
437
+ *
438
+ * Note: This was called `filetype` in earlier versions of WASI.
439
+ * # Variants
440
+ *
441
+ * ## `"unknown"`
442
+ *
443
+ * The type of the descriptor or file is unknown or is different from
444
+ * any of the other types specified.
445
+ * ## `"block-device"`
446
+ *
447
+ * The descriptor refers to a block device inode.
448
+ * ## `"character-device"`
449
+ *
450
+ * The descriptor refers to a character device inode.
451
+ * ## `"directory"`
452
+ *
453
+ * The descriptor refers to a directory inode.
454
+ * ## `"fifo"`
455
+ *
456
+ * The descriptor refers to a named pipe.
457
+ * ## `"symbolic-link"`
458
+ *
459
+ * The file refers to a symbolic link inode.
460
+ * ## `"regular-file"`
461
+ *
462
+ * The descriptor refers to a regular file inode.
463
+ * ## `"socket"`
464
+ *
465
+ * The descriptor refers to a socket.
466
+ */
467
+ export type DescriptorType = 'unknown' | 'block-device' | 'character-device' | 'directory' | 'fifo' | 'symbolic-link' | 'regular-file' | 'socket';
468
+ /**
469
+ * Descriptor flags.
470
+ *
471
+ * Note: This was called `fdflags` in earlier versions of WASI.
472
+ */
473
+ export interface DescriptorFlags {
474
+ /**
475
+ * Read mode: Data can be read.
476
+ */
477
+ read?: boolean,
478
+ /**
479
+ * Write mode: Data can be written to.
480
+ */
481
+ write?: boolean,
482
+ /**
483
+ * Request that writes be performed according to synchronized I/O file
484
+ * integrity completion. The data stored in the file and the file's
485
+ * metadata are synchronized. This is similar to `O_SYNC` in POSIX.
486
+ *
487
+ * The precise semantics of this operation have not yet been defined for
488
+ * WASI. At this time, it should be interpreted as a request, and not a
489
+ * requirement.
490
+ */
491
+ fileIntegritySync?: boolean,
492
+ /**
493
+ * Request that writes be performed according to synchronized I/O data
494
+ * integrity completion. Only the data stored in the file is
495
+ * synchronized. This is similar to `O_DSYNC` in POSIX.
496
+ *
497
+ * The precise semantics of this operation have not yet been defined for
498
+ * WASI. At this time, it should be interpreted as a request, and not a
499
+ * requirement.
500
+ */
501
+ dataIntegritySync?: boolean,
502
+ /**
503
+ * Requests that reads be performed at the same level of integrety
504
+ * requested for writes. This is similar to `O_RSYNC` in POSIX.
505
+ *
506
+ * The precise semantics of this operation have not yet been defined for
507
+ * WASI. At this time, it should be interpreted as a request, and not a
508
+ * requirement.
509
+ */
510
+ requestedWriteSync?: boolean,
511
+ /**
512
+ * Mutating directories mode: Directory contents may be mutated.
513
+ *
514
+ * When this flag is unset on a descriptor, operations using the
515
+ * descriptor which would create, rename, delete, modify the data or
516
+ * metadata of filesystem objects, or obtain another handle which
517
+ * would permit any of those, shall fail with `error-code::read-only` if
518
+ * they would otherwise succeed.
519
+ *
520
+ * This may only be set on directories.
521
+ */
522
+ mutateDirectory?: boolean,
523
+ }
381
524
  /**
382
525
  * Flags determining the method of how paths are resolved.
383
526
  */
@@ -430,408 +573,240 @@ export interface Modes {
430
573
  */
431
574
  executable?: boolean,
432
575
  }
576
+ /**
577
+ * Access type used by `access-at`.
578
+ */
579
+ export type AccessType = AccessTypeAccess | AccessTypeExists;
580
+ /**
581
+ * Test for readability, writeability, or executability.
582
+ */
583
+ export interface AccessTypeAccess {
584
+ tag: 'access',
585
+ val: Modes,
586
+ }
587
+ /**
588
+ * Test whether the path exists.
589
+ */
590
+ export interface AccessTypeExists {
591
+ tag: 'exists',
592
+ }
433
593
  /**
434
594
  * Number of hard links to an inode.
435
595
  */
436
596
  export type LinkCount = bigint;
437
597
  /**
438
- * Filesystem object serial number that is unique within its file system.
598
+ * File attributes.
599
+ *
600
+ * Note: This was called `filestat` in earlier versions of WASI.
601
+ */
602
+ export interface DescriptorStat {
603
+ /**
604
+ * File type.
605
+ */
606
+ type: DescriptorType,
607
+ /**
608
+ * Number of hard links to the file.
609
+ */
610
+ linkCount: LinkCount,
611
+ /**
612
+ * For regular files, the file size in bytes. For symbolic links, the
613
+ * length in bytes of the pathname contained in the symbolic link.
614
+ */
615
+ size: Filesize,
616
+ /**
617
+ * Last data access timestamp.
618
+ */
619
+ dataAccessTimestamp: Datetime,
620
+ /**
621
+ * Last data modification timestamp.
622
+ */
623
+ dataModificationTimestamp: Datetime,
624
+ /**
625
+ * Last file status change timestamp.
626
+ */
627
+ statusChangeTimestamp: Datetime,
628
+ }
629
+ /**
630
+ * When setting a timestamp, this gives the value to set it to.
439
631
  */
440
- export type Inode = bigint;
632
+ export type NewTimestamp = NewTimestampNoChange | NewTimestampNow | NewTimestampTimestamp;
441
633
  /**
442
- * File size or length of a region within a file.
634
+ * Leave the timestamp set to its previous value.
443
635
  */
444
- export type Filesize = bigint;
636
+ export interface NewTimestampNoChange {
637
+ tag: 'no-change',
638
+ }
639
+ /**
640
+ * Set the timestamp to the current time of the system clock associated
641
+ * with the filesystem.
642
+ */
643
+ export interface NewTimestampNow {
644
+ tag: 'now',
645
+ }
646
+ /**
647
+ * Set the timestamp to the given value.
648
+ */
649
+ export interface NewTimestampTimestamp {
650
+ tag: 'timestamp',
651
+ val: Datetime,
652
+ }
653
+ /**
654
+ * A directory entry.
655
+ */
656
+ export interface DirectoryEntry {
657
+ /**
658
+ * The type of the file referred to by this directory entry.
659
+ */
660
+ type: DescriptorType,
661
+ /**
662
+ * The name of the object.
663
+ */
664
+ name: string,
665
+ }
445
666
  /**
446
667
  * Error codes returned by functions, similar to `errno` in POSIX.
447
668
  * Not all of these error codes are returned by the functions provided by this
448
669
  * API; some are used in higher-level library layers, and others are provided
449
670
  * merely for alignment with POSIX.
450
- *
451
671
  * # Variants
452
672
  *
453
673
  * ## `"access"`
454
674
  *
455
675
  * Permission denied, similar to `EACCES` in POSIX.
456
- *
457
676
  * ## `"would-block"`
458
677
  *
459
678
  * Resource unavailable, or operation would block, similar to `EAGAIN` and `EWOULDBLOCK` in POSIX.
460
- *
461
679
  * ## `"already"`
462
680
  *
463
681
  * Connection already in progress, similar to `EALREADY` in POSIX.
464
- *
465
682
  * ## `"bad-descriptor"`
466
683
  *
467
684
  * Bad descriptor, similar to `EBADF` in POSIX.
468
- *
469
685
  * ## `"busy"`
470
686
  *
471
687
  * Device or resource busy, similar to `EBUSY` in POSIX.
472
- *
473
688
  * ## `"deadlock"`
474
689
  *
475
690
  * Resource deadlock would occur, similar to `EDEADLK` in POSIX.
476
- *
477
691
  * ## `"quota"`
478
692
  *
479
693
  * Storage quota exceeded, similar to `EDQUOT` in POSIX.
480
- *
481
694
  * ## `"exist"`
482
695
  *
483
696
  * File exists, similar to `EEXIST` in POSIX.
484
- *
485
697
  * ## `"file-too-large"`
486
698
  *
487
699
  * File too large, similar to `EFBIG` in POSIX.
488
- *
489
700
  * ## `"illegal-byte-sequence"`
490
701
  *
491
702
  * Illegal byte sequence, similar to `EILSEQ` in POSIX.
492
- *
493
703
  * ## `"in-progress"`
494
704
  *
495
705
  * Operation in progress, similar to `EINPROGRESS` in POSIX.
496
- *
497
706
  * ## `"interrupted"`
498
707
  *
499
708
  * Interrupted function, similar to `EINTR` in POSIX.
500
- *
501
709
  * ## `"invalid"`
502
710
  *
503
711
  * Invalid argument, similar to `EINVAL` in POSIX.
504
- *
505
712
  * ## `"io"`
506
713
  *
507
714
  * I/O error, similar to `EIO` in POSIX.
508
- *
509
715
  * ## `"is-directory"`
510
716
  *
511
717
  * Is a directory, similar to `EISDIR` in POSIX.
512
- *
513
718
  * ## `"loop"`
514
719
  *
515
720
  * Too many levels of symbolic links, similar to `ELOOP` in POSIX.
516
- *
517
721
  * ## `"too-many-links"`
518
722
  *
519
723
  * Too many links, similar to `EMLINK` in POSIX.
520
- *
521
724
  * ## `"message-size"`
522
725
  *
523
726
  * Message too large, similar to `EMSGSIZE` in POSIX.
524
- *
525
727
  * ## `"name-too-long"`
526
728
  *
527
729
  * Filename too long, similar to `ENAMETOOLONG` in POSIX.
528
- *
529
730
  * ## `"no-device"`
530
731
  *
531
732
  * No such device, similar to `ENODEV` in POSIX.
532
- *
533
733
  * ## `"no-entry"`
534
734
  *
535
735
  * No such file or directory, similar to `ENOENT` in POSIX.
536
- *
537
736
  * ## `"no-lock"`
538
737
  *
539
738
  * No locks available, similar to `ENOLCK` in POSIX.
540
- *
541
739
  * ## `"insufficient-memory"`
542
740
  *
543
741
  * Not enough space, similar to `ENOMEM` in POSIX.
544
- *
545
742
  * ## `"insufficient-space"`
546
743
  *
547
744
  * No space left on device, similar to `ENOSPC` in POSIX.
548
- *
549
745
  * ## `"not-directory"`
550
746
  *
551
747
  * Not a directory or a symbolic link to a directory, similar to `ENOTDIR` in POSIX.
552
- *
553
748
  * ## `"not-empty"`
554
749
  *
555
750
  * Directory not empty, similar to `ENOTEMPTY` in POSIX.
556
- *
557
751
  * ## `"not-recoverable"`
558
752
  *
559
753
  * State not recoverable, similar to `ENOTRECOVERABLE` in POSIX.
560
- *
561
754
  * ## `"unsupported"`
562
755
  *
563
756
  * Not supported, similar to `ENOTSUP` and `ENOSYS` in POSIX.
564
- *
565
757
  * ## `"no-tty"`
566
758
  *
567
759
  * Inappropriate I/O control operation, similar to `ENOTTY` in POSIX.
568
- *
569
760
  * ## `"no-such-device"`
570
761
  *
571
762
  * No such device or address, similar to `ENXIO` in POSIX.
572
- *
573
763
  * ## `"overflow"`
574
764
  *
575
765
  * Value too large to be stored in data type, similar to `EOVERFLOW` in POSIX.
576
- *
577
766
  * ## `"not-permitted"`
578
767
  *
579
768
  * Operation not permitted, similar to `EPERM` in POSIX.
580
- *
581
769
  * ## `"pipe"`
582
770
  *
583
771
  * Broken pipe, similar to `EPIPE` in POSIX.
584
- *
585
772
  * ## `"read-only"`
586
773
  *
587
774
  * Read-only file system, similar to `EROFS` in POSIX.
588
- *
589
775
  * ## `"invalid-seek"`
590
776
  *
591
777
  * Invalid seek, similar to `ESPIPE` in POSIX.
592
- *
593
778
  * ## `"text-file-busy"`
594
779
  *
595
780
  * Text file busy, similar to `ETXTBSY` in POSIX.
596
- *
597
781
  * ## `"cross-device"`
598
782
  *
599
783
  * Cross-device link, similar to `EXDEV` in POSIX.
600
784
  */
601
785
  export type ErrorCode = 'access' | 'would-block' | 'already' | 'bad-descriptor' | 'busy' | 'deadlock' | 'quota' | 'exist' | 'file-too-large' | 'illegal-byte-sequence' | 'in-progress' | 'interrupted' | 'invalid' | 'io' | 'is-directory' | 'loop' | 'too-many-links' | 'message-size' | 'name-too-long' | 'no-device' | 'no-entry' | 'no-lock' | 'insufficient-memory' | 'insufficient-space' | 'not-directory' | 'not-empty' | 'not-recoverable' | 'unsupported' | 'no-tty' | 'no-such-device' | 'overflow' | 'not-permitted' | 'pipe' | 'read-only' | 'invalid-seek' | 'text-file-busy' | 'cross-device';
602
- /**
603
- * A stream of directory entries.
604
- *
605
- * This [represents a stream of `dir-entry`](https://github.com/WebAssembly/WASI/blob/main/docs/WitInWasi.md#Streams).
606
- */
607
- export type DirectoryEntryStream = number;
608
- /**
609
- * Identifier for a device containing a file system. Can be used in
610
- * combination with `inode` to uniquely identify a file or directory in
611
- * the filesystem.
612
- */
613
- export type Device = bigint;
614
- /**
615
- * The type of a filesystem object referenced by a descriptor.
616
- *
617
- * Note: This was called `filetype` in earlier versions of WASI.
618
- *
619
- * # Variants
620
- *
621
- * ## `"unknown"`
622
- *
623
- * The type of the descriptor or file is unknown or is different from
624
- * any of the other types specified.
625
- *
626
- * ## `"block-device"`
627
- *
628
- * The descriptor refers to a block device inode.
629
- *
630
- * ## `"character-device"`
631
- *
632
- * The descriptor refers to a character device inode.
633
- *
634
- * ## `"directory"`
635
- *
636
- * The descriptor refers to a directory inode.
637
- *
638
- * ## `"fifo"`
639
- *
640
- * The descriptor refers to a named pipe.
641
- *
642
- * ## `"symbolic-link"`
643
- *
644
- * The file refers to a symbolic link inode.
645
- *
646
- * ## `"regular-file"`
647
- *
648
- * The descriptor refers to a regular file inode.
649
- *
650
- * ## `"socket"`
651
- *
652
- * The descriptor refers to a socket.
653
- */
654
- export type DescriptorType = 'unknown' | 'block-device' | 'character-device' | 'directory' | 'fifo' | 'symbolic-link' | 'regular-file' | 'socket';
655
- /**
656
- * A directory entry.
657
- */
658
- export interface DirectoryEntry {
659
- /**
660
- * The serial number of the object referred to by this directory entry.
661
- * May be none if the inode value is not known.
662
- *
663
- * When this is none, libc implementations might do an extra `stat-at`
664
- * call to retrieve the inode number to fill their `d_ino` fields, so
665
- * implementations which can set this to a non-none value should do so.
666
- */
667
- inode?: Inode,
668
- /**
669
- * The type of the file referred to by this directory entry.
670
- */
671
- type: DescriptorType,
672
- /**
673
- * The name of the object.
674
- */
675
- name: string,
676
- }
677
- /**
678
- * Descriptor flags.
679
- *
680
- * Note: This was called `fdflags` in earlier versions of WASI.
681
- */
682
- export interface DescriptorFlags {
683
- /**
684
- * Read mode: Data can be read.
685
- */
686
- read?: boolean,
687
- /**
688
- * Write mode: Data can be written to.
689
- */
690
- write?: boolean,
691
- /**
692
- * Request that writes be performed according to synchronized I/O file
693
- * integrity completion. The data stored in the file and the file's
694
- * metadata are synchronized. This is similar to `O_SYNC` in POSIX.
695
- *
696
- * The precise semantics of this operation have not yet been defined for
697
- * WASI. At this time, it should be interpreted as a request, and not a
698
- * requirement.
699
- */
700
- fileIntegritySync?: boolean,
701
- /**
702
- * Request that writes be performed according to synchronized I/O data
703
- * integrity completion. Only the data stored in the file is
704
- * synchronized. This is similar to `O_DSYNC` in POSIX.
705
- *
706
- * The precise semantics of this operation have not yet been defined for
707
- * WASI. At this time, it should be interpreted as a request, and not a
708
- * requirement.
709
- */
710
- dataIntegritySync?: boolean,
711
- /**
712
- * Requests that reads be performed at the same level of integrety
713
- * requested for writes. This is similar to `O_RSYNC` in POSIX.
714
- *
715
- * The precise semantics of this operation have not yet been defined for
716
- * WASI. At this time, it should be interpreted as a request, and not a
717
- * requirement.
718
- */
719
- requestedWriteSync?: boolean,
720
- /**
721
- * Mutating directories mode: Directory contents may be mutated.
722
- *
723
- * When this flag is unset on a descriptor, operations using the
724
- * descriptor which would create, rename, delete, modify the data or
725
- * metadata of filesystem objects, or obtain another handle which
726
- * would permit any of those, shall fail with `error-code::read-only` if
727
- * they would otherwise succeed.
728
- *
729
- * This may only be set on directories.
730
- */
731
- mutateDirectory?: boolean,
732
- }
733
- /**
734
- * A descriptor is a reference to a filesystem object, which may be a file,
735
- * directory, named pipe, special file, or other object on which filesystem
736
- * calls may be made.
737
- *
738
- * This [represents a resource](https://github.com/WebAssembly/WASI/blob/main/docs/WitInWasi.md#Resources).
739
- */
740
- export type Descriptor = number;
741
- /**
742
- * When setting a timestamp, this gives the value to set it to.
743
- */
744
- export type NewTimestamp = NewTimestampNoChange | NewTimestampNow | NewTimestampTimestamp;
745
- /**
746
- * Leave the timestamp set to its previous value.
747
- */
748
- export interface NewTimestampNoChange {
749
- tag: 'no-change',
750
- }
751
- /**
752
- * Set the timestamp to the current time of the system clock associated
753
- * with the filesystem.
754
- */
755
- export interface NewTimestampNow {
756
- tag: 'now',
757
- }
758
- /**
759
- * Set the timestamp to the given value.
760
- */
761
- export interface NewTimestampTimestamp {
762
- tag: 'timestamp',
763
- val: Datetime,
764
- }
765
- /**
766
- * File attributes.
767
- *
768
- * Note: This was called `filestat` in earlier versions of WASI.
769
- */
770
- export interface DescriptorStat {
771
- /**
772
- * Device ID of device containing the file.
773
- */
774
- device: Device,
775
- /**
776
- * File serial number.
777
- */
778
- inode: Inode,
779
- /**
780
- * File type.
781
- */
782
- type: DescriptorType,
783
- /**
784
- * Number of hard links to the file.
785
- */
786
- linkCount: LinkCount,
787
- /**
788
- * For regular files, the file size in bytes. For symbolic links, the
789
- * length in bytes of the pathname contained in the symbolic link.
790
- */
791
- size: Filesize,
792
- /**
793
- * Last data access timestamp.
794
- */
795
- dataAccessTimestamp: Datetime,
796
- /**
797
- * Last data modification timestamp.
798
- */
799
- dataModificationTimestamp: Datetime,
800
- /**
801
- * Last file status change timestamp.
802
- */
803
- statusChangeTimestamp: Datetime,
804
- }
805
786
  /**
806
787
  * File or memory access pattern advisory information.
807
- *
808
788
  * # Variants
809
789
  *
810
790
  * ## `"normal"`
811
791
  *
812
792
  * The application has no advice to give on its behavior with respect
813
793
  * to the specified data.
814
- *
815
794
  * ## `"sequential"`
816
795
  *
817
796
  * The application expects to access the specified data sequentially
818
797
  * from lower offsets to higher offsets.
819
- *
820
798
  * ## `"random"`
821
799
  *
822
800
  * The application expects to access the specified data in a random
823
801
  * order.
824
- *
825
802
  * ## `"will-need"`
826
803
  *
827
804
  * The application expects to access the specified data in the near
828
805
  * future.
829
- *
830
806
  * ## `"dont-need"`
831
807
  *
832
808
  * The application expects that it will not access the specified data
833
809
  * in the near future.
834
- *
835
810
  * ## `"no-reuse"`
836
811
  *
837
812
  * The application expects to access the specified data once and then
@@ -839,19 +814,30 @@ export interface DescriptorStat {
839
814
  */
840
815
  export type Advice = 'normal' | 'sequential' | 'random' | 'will-need' | 'dont-need' | 'no-reuse';
841
816
  /**
842
- * Access type used by `access-at`.
817
+ * A descriptor is a reference to a filesystem object, which may be a file,
818
+ * directory, named pipe, special file, or other object on which filesystem
819
+ * calls may be made.
820
+ *
821
+ * This [represents a resource](https://github.com/WebAssembly/WASI/blob/main/docs/WitInWasi.md#Resources).
843
822
  */
844
- export type AccessType = AccessTypeAccess | AccessTypeExists;
823
+ export type Descriptor = number;
845
824
  /**
846
- * Test for readability, writeability, or executability.
825
+ * A 128-bit hash value, split into parts because wasm doesn't have a
826
+ * 128-bit integer type.
847
827
  */
848
- export interface AccessTypeAccess {
849
- tag: 'access',
850
- val: Modes,
828
+ export interface MetadataHashValue {
829
+ /**
830
+ * 64 bits of a 128-bit hash value.
831
+ */
832
+ lower: bigint,
833
+ /**
834
+ * Another 64 bits of a 128-bit hash value.
835
+ */
836
+ upper: bigint,
851
837
  }
852
838
  /**
853
- * Test whether the path exists.
839
+ * A stream of directory entries.
840
+ *
841
+ * This [represents a stream of `dir-entry`](https://github.com/WebAssembly/WASI/blob/main/docs/WitInWasi.md#Streams).
854
842
  */
855
- export interface AccessTypeExists {
856
- tag: 'exists',
857
- }
843
+ export type DirectoryEntryStream = number;