@bytecodealliance/preview2-shim 0.0.17 → 0.0.19

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,13 +1,2 @@
1
1
  export namespace WasiCliTerminalOutput {
2
- /**
3
- * Dispose of the specified terminal-output, after which it may no longer
4
- * be used.
5
- */
6
- export function dropTerminalOutput(this_: TerminalOutput): void;
7
2
  }
8
- /**
9
- * The output side of a terminal.
10
- *
11
- * This [represents a resource](https://github.com/WebAssembly/WASI/blob/main/docs/WitInWasi.md#Resources).
12
- */
13
- export type TerminalOutput = number;
@@ -16,7 +16,7 @@ export namespace WasiClocksMonotonicClock {
16
16
  */
17
17
  export function subscribe(when: Instant, absolute: boolean): Pollable;
18
18
  }
19
- import type { Pollable } from '../interfaces/wasi-poll-poll';
19
+ import type { Pollable } from '../interfaces/wasi-io-poll';
20
20
  export { Pollable };
21
21
  /**
22
22
  * A timestamp in nanoseconds.
@@ -8,29 +8,14 @@ export namespace WasiClocksTimezone {
8
8
  * `timezone-display` for `UTC` with a `utc-offset` of 0 and no daylight
9
9
  * saving time.
10
10
  */
11
- export function display(this_: Timezone, when: Datetime): TimezoneDisplay;
11
+ export function display(when: Datetime): TimezoneDisplay;
12
12
  /**
13
13
  * The same as `display`, but only return the UTC offset.
14
14
  */
15
- export function utcOffset(this_: Timezone, when: Datetime): number;
16
- /**
17
- * Dispose of the specified input-stream, after which it may no longer
18
- * be used.
19
- */
20
- export function dropTimezone(this_: Timezone): void;
15
+ export function utcOffset(when: Datetime): number;
21
16
  }
22
17
  import type { Datetime } from '../interfaces/wasi-clocks-wall-clock';
23
18
  export { Datetime };
24
- /**
25
- * A timezone.
26
- *
27
- * In timezones that recognize daylight saving time, also known as daylight
28
- * time and summer time, the information returned from the functions varies
29
- * over time to reflect these adjustments.
30
- *
31
- * This [represents a resource](https://github.com/WebAssembly/WASI/blob/main/docs/WitInWasi.md#Resources).
32
- */
33
- export type Timezone = number;
34
19
  /**
35
20
  * Information useful for displaying the timezone of a specific `datetime`.
36
21
  *
@@ -9,7 +9,7 @@ export namespace WasiFilesystemTypes {
9
9
  *
10
10
  * Note: This allows using `read-stream`, which is similar to `read` in POSIX.
11
11
  */
12
- export function readViaStream(this_: Descriptor, offset: Filesize): InputStream;
12
+ export { Descriptor };
13
13
  /**
14
14
  * Return a stream for writing to a file, if available.
15
15
  *
@@ -18,7 +18,6 @@ export namespace WasiFilesystemTypes {
18
18
  * Note: This allows using `write-stream`, which is similar to `write` in
19
19
  * POSIX.
20
20
  */
21
- export function writeViaStream(this_: Descriptor, offset: Filesize): OutputStream;
22
21
  /**
23
22
  * Return a stream for appending to a file, if available.
24
23
  *
@@ -27,13 +26,11 @@ export namespace WasiFilesystemTypes {
27
26
  * Note: This allows using `write-stream`, which is similar to `write` with
28
27
  * `O_APPEND` in in POSIX.
29
28
  */
30
- export function appendViaStream(this_: Descriptor): OutputStream;
31
29
  /**
32
30
  * Provide file advisory information on a descriptor.
33
31
  *
34
32
  * This is similar to `posix_fadvise` in POSIX.
35
33
  */
36
- export function advise(this_: Descriptor, offset: Filesize, length: Filesize, advice: Advice): void;
37
34
  /**
38
35
  * Synchronize the data of a file to disk.
39
36
  *
@@ -42,7 +39,6 @@ export namespace WasiFilesystemTypes {
42
39
  *
43
40
  * Note: This is similar to `fdatasync` in POSIX.
44
41
  */
45
- export function syncData(this_: Descriptor): void;
46
42
  /**
47
43
  * Get flags associated with a descriptor.
48
44
  *
@@ -51,7 +47,6 @@ export namespace WasiFilesystemTypes {
51
47
  * Note: This returns the value that was the `fs_flags` value returned
52
48
  * from `fdstat_get` in earlier versions of WASI.
53
49
  */
54
- export function getFlags(this_: Descriptor): DescriptorFlags;
55
50
  /**
56
51
  * Get the dynamic type of a descriptor.
57
52
  *
@@ -64,14 +59,12 @@ export namespace WasiFilesystemTypes {
64
59
  * Note: This returns the value that was the `fs_filetype` value returned
65
60
  * from `fdstat_get` in earlier versions of WASI.
66
61
  */
67
- export function getType(this_: Descriptor): DescriptorType;
68
62
  /**
69
63
  * Adjust the size of an open file. If this increases the file's size, the
70
64
  * extra bytes are filled with zeros.
71
65
  *
72
66
  * Note: This was called `fd_filestat_set_size` in earlier versions of WASI.
73
67
  */
74
- export function setSize(this_: Descriptor, size: Filesize): void;
75
68
  /**
76
69
  * Adjust the timestamps of an open file or directory.
77
70
  *
@@ -79,7 +72,6 @@ export namespace WasiFilesystemTypes {
79
72
  *
80
73
  * Note: This was called `fd_filestat_set_times` in earlier versions of WASI.
81
74
  */
82
- export function setTimes(this_: Descriptor, dataAccessTimestamp: NewTimestamp, dataModificationTimestamp: NewTimestamp): void;
83
75
  /**
84
76
  * Read from a descriptor, without using and updating the descriptor's offset.
85
77
  *
@@ -93,7 +85,6 @@ export namespace WasiFilesystemTypes {
93
85
  *
94
86
  * Note: This is similar to `pread` in POSIX.
95
87
  */
96
- export function read(this_: Descriptor, length: Filesize, offset: Filesize): [Uint8Array, boolean];
97
88
  /**
98
89
  * Write to a descriptor, without using and updating the descriptor's offset.
99
90
  *
@@ -105,7 +96,6 @@ export namespace WasiFilesystemTypes {
105
96
  *
106
97
  * Note: This is similar to `pwrite` in POSIX.
107
98
  */
108
- export function write(this_: Descriptor, buffer: Uint8Array, offset: Filesize): Filesize;
109
99
  /**
110
100
  * Read directory entries from a directory.
111
101
  *
@@ -117,7 +107,6 @@ export namespace WasiFilesystemTypes {
117
107
  * directory. Multiple streams may be active on the same directory, and they
118
108
  * do not interfere with each other.
119
109
  */
120
- export function readDirectory(this_: Descriptor): DirectoryEntryStream;
121
110
  /**
122
111
  * Synchronize the data and metadata of a file to disk.
123
112
  *
@@ -126,13 +115,11 @@ export namespace WasiFilesystemTypes {
126
115
  *
127
116
  * Note: This is similar to `fsync` in POSIX.
128
117
  */
129
- export function sync(this_: Descriptor): void;
130
118
  /**
131
119
  * Create a directory.
132
120
  *
133
121
  * Note: This is similar to `mkdirat` in POSIX.
134
122
  */
135
- export function createDirectoryAt(this_: Descriptor, path: string): void;
136
123
  /**
137
124
  * Return the attributes of an open file or directory.
138
125
  *
@@ -144,7 +131,6 @@ export namespace WasiFilesystemTypes {
144
131
  *
145
132
  * Note: This was called `fd_filestat_get` in earlier versions of WASI.
146
133
  */
147
- export function stat(this_: Descriptor): DescriptorStat;
148
134
  /**
149
135
  * Return the attributes of a file or directory.
150
136
  *
@@ -154,7 +140,6 @@ export namespace WasiFilesystemTypes {
154
140
  *
155
141
  * Note: This was called `path_filestat_get` in earlier versions of WASI.
156
142
  */
157
- export function statAt(this_: Descriptor, pathFlags: PathFlags, path: string): DescriptorStat;
158
143
  /**
159
144
  * Adjust the timestamps of a file or directory.
160
145
  *
@@ -163,13 +148,11 @@ export namespace WasiFilesystemTypes {
163
148
  * Note: This was called `path_filestat_set_times` in earlier versions of
164
149
  * WASI.
165
150
  */
166
- export function setTimesAt(this_: Descriptor, pathFlags: PathFlags, path: string, dataAccessTimestamp: NewTimestamp, dataModificationTimestamp: NewTimestamp): void;
167
151
  /**
168
152
  * Create a hard link.
169
153
  *
170
154
  * Note: This is similar to `linkat` in POSIX.
171
155
  */
172
- export function linkAt(this_: Descriptor, oldPathFlags: PathFlags, oldPath: string, newDescriptor: Descriptor, newPath: string): void;
173
156
  /**
174
157
  * Open a file or directory.
175
158
  *
@@ -190,7 +173,6 @@ export namespace WasiFilesystemTypes {
190
173
  *
191
174
  * Note: This is similar to `openat` in POSIX.
192
175
  */
193
- export function openAt(this_: Descriptor, pathFlags: PathFlags, path: string, openFlags: OpenFlags, flags: DescriptorFlags, modes: Modes): Descriptor;
194
176
  /**
195
177
  * Read the contents of a symbolic link.
196
178
  *
@@ -199,7 +181,6 @@ export namespace WasiFilesystemTypes {
199
181
  *
200
182
  * Note: This is similar to `readlinkat` in POSIX.
201
183
  */
202
- export function readlinkAt(this_: Descriptor, path: string): string;
203
184
  /**
204
185
  * Remove a directory.
205
186
  *
@@ -207,13 +188,11 @@ export namespace WasiFilesystemTypes {
207
188
  *
208
189
  * Note: This is similar to `unlinkat(fd, path, AT_REMOVEDIR)` in POSIX.
209
190
  */
210
- export function removeDirectoryAt(this_: Descriptor, path: string): void;
211
191
  /**
212
192
  * Rename a filesystem object.
213
193
  *
214
194
  * Note: This is similar to `renameat` in POSIX.
215
195
  */
216
- export function renameAt(this_: Descriptor, oldPath: string, newDescriptor: Descriptor, newPath: string): void;
217
196
  /**
218
197
  * Create a symbolic link (also known as a "symlink").
219
198
  *
@@ -222,7 +201,6 @@ export namespace WasiFilesystemTypes {
222
201
  *
223
202
  * Note: This is similar to `symlinkat` in POSIX.
224
203
  */
225
- export function symlinkAt(this_: Descriptor, oldPath: string, newPath: string): void;
226
204
  /**
227
205
  * Check accessibility of a filesystem path.
228
206
  *
@@ -235,14 +213,12 @@ export namespace WasiFilesystemTypes {
235
213
  *
236
214
  * Note: This is similar to `faccessat` with the `AT_EACCESS` flag in POSIX.
237
215
  */
238
- export function accessAt(this_: Descriptor, pathFlags: PathFlags, path: string, type: AccessType): void;
239
216
  /**
240
217
  * Unlink a filesystem object that is not a directory.
241
218
  *
242
219
  * Return `error-code::is-directory` if the path refers to a directory.
243
220
  * Note: This is similar to `unlinkat(fd, path, 0)` in POSIX.
244
221
  */
245
- export function unlinkFileAt(this_: Descriptor, path: string): void;
246
222
  /**
247
223
  * Change the permissions of a filesystem object that is not a directory.
248
224
  *
@@ -251,7 +227,6 @@ export namespace WasiFilesystemTypes {
251
227
  *
252
228
  * Note: This is similar to `fchmodat` in POSIX.
253
229
  */
254
- export function changeFilePermissionsAt(this_: Descriptor, pathFlags: PathFlags, path: string, modes: Modes): void;
255
230
  /**
256
231
  * Change the permissions of a directory.
257
232
  *
@@ -264,7 +239,6 @@ export namespace WasiFilesystemTypes {
264
239
  *
265
240
  * Note: This is similar to `fchmodat` in POSIX.
266
241
  */
267
- export function changeDirectoryPermissionsAt(this_: Descriptor, pathFlags: PathFlags, path: string, modes: Modes): void;
268
242
  /**
269
243
  * Request a shared advisory lock for an open file.
270
244
  *
@@ -287,7 +261,6 @@ export namespace WasiFilesystemTypes {
287
261
  *
288
262
  * Note: This is similar to `flock(fd, LOCK_SH)` in Unix.
289
263
  */
290
- export function lockShared(this_: Descriptor): void;
291
264
  /**
292
265
  * Request an exclusive advisory lock for an open file.
293
266
  *
@@ -312,7 +285,6 @@ export namespace WasiFilesystemTypes {
312
285
  *
313
286
  * Note: This is similar to `flock(fd, LOCK_EX)` in Unix.
314
287
  */
315
- export function lockExclusive(this_: Descriptor): void;
316
288
  /**
317
289
  * Request a shared advisory lock for an open file.
318
290
  *
@@ -336,7 +308,6 @@ export namespace WasiFilesystemTypes {
336
308
  *
337
309
  * Note: This is similar to `flock(fd, LOCK_SH | LOCK_NB)` in Unix.
338
310
  */
339
- export function tryLockShared(this_: Descriptor): void;
340
311
  /**
341
312
  * Request an exclusive advisory lock for an open file.
342
313
  *
@@ -362,27 +333,11 @@ export namespace WasiFilesystemTypes {
362
333
  *
363
334
  * Note: This is similar to `flock(fd, LOCK_EX | LOCK_NB)` in Unix.
364
335
  */
365
- export function tryLockExclusive(this_: Descriptor): void;
366
336
  /**
367
337
  * Release a shared or exclusive lock on an open file.
368
338
  *
369
339
  * Note: This is similar to `flock(fd, LOCK_UN)` in Unix.
370
340
  */
371
- export function unlock(this_: Descriptor): void;
372
- /**
373
- * Dispose of the specified `descriptor`, after which it may no longer
374
- * be used.
375
- */
376
- export function dropDescriptor(this_: Descriptor): void;
377
- /**
378
- * Read a single directory entry from a `directory-entry-stream`.
379
- */
380
- export function readDirectoryEntry(this_: DirectoryEntryStream): DirectoryEntry | undefined;
381
- /**
382
- * Dispose of the specified `directory-entry-stream`, after which it may no longer
383
- * be used.
384
- */
385
- export function dropDirectoryEntryStream(this_: DirectoryEntryStream): void;
386
341
  /**
387
342
  * Test whether two descriptors refer to the same filesystem object.
388
343
  *
@@ -391,7 +346,6 @@ export namespace WasiFilesystemTypes {
391
346
  * wasi-filesystem does not expose device and inode numbers, so this function
392
347
  * may be used instead.
393
348
  */
394
- export function isSameObject(this_: Descriptor, other: Descriptor): boolean;
395
349
  /**
396
350
  * Return a hash of the metadata associated with a filesystem object referred
397
351
  * to by a descriptor.
@@ -413,19 +367,36 @@ export namespace WasiFilesystemTypes {
413
367
  *
414
368
  * However, none of these is required.
415
369
  */
416
- export function metadataHash(this_: Descriptor): MetadataHashValue;
417
370
  /**
418
371
  * Return a hash of the metadata associated with a filesystem object referred
419
372
  * to by a directory descriptor and a relative path.
420
373
  *
421
374
  * This performs the same hash computation as `metadata-hash`.
422
375
  */
423
- export function metadataHashAt(this_: Descriptor, pathFlags: PathFlags, path: string): MetadataHashValue;
376
+ /**
377
+ * Read a single directory entry from a `directory-entry-stream`.
378
+ */
379
+ export { DirectoryEntryStream };
380
+ /**
381
+ * Attempts to extract a filesystem-related `error-code` from the stream
382
+ * `error` provided.
383
+ *
384
+ * Stream operations which return `stream-error::last-operation-failed`
385
+ * have a payload with more information about the operation that failed.
386
+ * This payload can be passed through to this function to see if there's
387
+ * filesystem-related information about the error to return.
388
+ *
389
+ * Note that this function is fallible because not all stream-related
390
+ * errors are filesystem-related errors.
391
+ */
392
+ export function filesystemErrorCode(err: Error): ErrorCode | undefined;
424
393
  }
425
394
  import type { InputStream } from '../interfaces/wasi-io-streams';
426
395
  export { InputStream };
427
396
  import type { OutputStream } from '../interfaces/wasi-io-streams';
428
397
  export { OutputStream };
398
+ import type { Error } from '../interfaces/wasi-io-streams';
399
+ export { Error };
429
400
  import type { Datetime } from '../interfaces/wasi-clocks-wall-clock';
430
401
  export { Datetime };
431
402
  /**
@@ -615,16 +586,25 @@ export interface DescriptorStat {
615
586
  size: Filesize,
616
587
  /**
617
588
  * Last data access timestamp.
589
+ *
590
+ * If the `option` is none, the platform doesn't maintain an access
591
+ * timestamp for this file.
618
592
  */
619
- dataAccessTimestamp: Datetime,
593
+ dataAccessTimestamp?: Datetime,
620
594
  /**
621
595
  * Last data modification timestamp.
596
+ *
597
+ * If the `option` is none, the platform doesn't maintain a
598
+ * modification timestamp for this file.
622
599
  */
623
- dataModificationTimestamp: Datetime,
600
+ dataModificationTimestamp?: Datetime,
624
601
  /**
625
- * Last file status change timestamp.
602
+ * Last file status-change timestamp.
603
+ *
604
+ * If the `option` is none, the platform doesn't maintain a
605
+ * status-change timestamp for this file.
626
606
  */
627
- statusChangeTimestamp: Datetime,
607
+ statusChangeTimestamp?: Datetime,
628
608
  }
629
609
  /**
630
610
  * When setting a timestamp, this gives the value to set it to.
@@ -813,14 +793,6 @@ export type ErrorCode = 'access' | 'would-block' | 'already' | 'bad-descriptor'
813
793
  * not reuse it thereafter.
814
794
  */
815
795
  export type Advice = 'normal' | 'sequential' | 'random' | 'will-need' | 'dont-need' | 'no-reuse';
816
- /**
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).
822
- */
823
- export type Descriptor = number;
824
796
  /**
825
797
  * A 128-bit hash value, split into parts because wasm doesn't have a
826
798
  * 128-bit integer type.
@@ -835,9 +807,45 @@ export interface MetadataHashValue {
835
807
  */
836
808
  upper: bigint,
837
809
  }
838
- /**
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).
842
- */
843
- export type DirectoryEntryStream = number;
810
+
811
+ export class DirectoryEntryStream {
812
+ readDirectoryEntry(): DirectoryEntry | undefined;
813
+ }
814
+
815
+ export class Descriptor {
816
+ readViaStream(offset: Filesize): InputStream;
817
+ writeViaStream(offset: Filesize): OutputStream;
818
+ appendViaStream(): OutputStream;
819
+ advise(offset: Filesize, length: Filesize, advice: Advice): void;
820
+ syncData(): void;
821
+ getFlags(): DescriptorFlags;
822
+ getType(): DescriptorType;
823
+ setSize(size: Filesize): void;
824
+ setTimes(dataAccessTimestamp: NewTimestamp, dataModificationTimestamp: NewTimestamp): void;
825
+ read(length: Filesize, offset: Filesize): [Uint8Array, boolean];
826
+ write(buffer: Uint8Array, offset: Filesize): Filesize;
827
+ readDirectory(): DirectoryEntryStream;
828
+ sync(): void;
829
+ createDirectoryAt(path: string): void;
830
+ stat(): DescriptorStat;
831
+ statAt(pathFlags: PathFlags, path: string): DescriptorStat;
832
+ setTimesAt(pathFlags: PathFlags, path: string, dataAccessTimestamp: NewTimestamp, dataModificationTimestamp: NewTimestamp): void;
833
+ linkAt(oldPathFlags: PathFlags, oldPath: string, newDescriptor: Descriptor, newPath: string): void;
834
+ openAt(pathFlags: PathFlags, path: string, openFlags: OpenFlags, flags: DescriptorFlags, modes: Modes): Descriptor;
835
+ readlinkAt(path: string): string;
836
+ removeDirectoryAt(path: string): void;
837
+ renameAt(oldPath: string, newDescriptor: Descriptor, newPath: string): void;
838
+ symlinkAt(oldPath: string, newPath: string): void;
839
+ accessAt(pathFlags: PathFlags, path: string, type: AccessType): void;
840
+ unlinkFileAt(path: string): void;
841
+ changeFilePermissionsAt(pathFlags: PathFlags, path: string, modes: Modes): void;
842
+ changeDirectoryPermissionsAt(pathFlags: PathFlags, path: string, modes: Modes): void;
843
+ lockShared(): void;
844
+ lockExclusive(): void;
845
+ tryLockShared(): void;
846
+ tryLockExclusive(): void;
847
+ unlock(): void;
848
+ isSameObject(other: Descriptor): boolean;
849
+ metadataHash(): MetadataHashValue;
850
+ metadataHashAt(pathFlags: PathFlags, path: string): MetadataHashValue;
851
+ }
@@ -0,0 +1,30 @@
1
+ export namespace WasiIoPoll {
2
+ /**
3
+ * Poll for completion on a set of pollables.
4
+ *
5
+ * This function takes a list of pollables, which identify I/O sources of
6
+ * interest, and waits until one or more of the events is ready for I/O.
7
+ *
8
+ * The result `list<u32>` contains one or more indices of handles in the
9
+ * argument list that is ready for I/O.
10
+ *
11
+ * If the list contains more elements than can be indexed with a `u32`
12
+ * value, this function traps.
13
+ *
14
+ * A timeout can be implemented by adding a pollable from the
15
+ * wasi-clocks API to the list.
16
+ *
17
+ * This function does not return a `result`; polling in itself does not
18
+ * do any I/O so it doesn't fail. If any of the I/O sources identified by
19
+ * the pollables has an error, it is indicated by marking the source as
20
+ * being reaedy for I/O.
21
+ */
22
+ export function pollList(in_: Pollable[]): Uint32Array;
23
+ /**
24
+ * Poll for completion on a single pollable.
25
+ *
26
+ * This function is similar to `poll-list`, but operates on only a single
27
+ * pollable. When it returns, the handle is ready for I/O.
28
+ */
29
+ export function pollOne(in_: Pollable): void;
30
+ }