@bytecodealliance/preview3-shim 0.1.2 → 0.2.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 (112) hide show
  1. package/dist/nodejs/cli.d.ts +51 -0
  2. package/dist/nodejs/cli.js +106 -0
  3. package/dist/nodejs/clocks.d.ts +55 -0
  4. package/dist/nodejs/clocks.js +83 -0
  5. package/dist/nodejs/filesystem/descriptor.d.ts +443 -0
  6. package/dist/nodejs/filesystem/descriptor.js +1010 -0
  7. package/dist/nodejs/filesystem/error.d.ts +61 -0
  8. package/dist/nodejs/filesystem/error.js +86 -0
  9. package/dist/nodejs/filesystem/utils.d.ts +8 -0
  10. package/dist/nodejs/filesystem/utils.js +25 -0
  11. package/dist/nodejs/filesystem.js +2 -0
  12. package/dist/nodejs/finalization.d.ts +2 -0
  13. package/{lib → dist}/nodejs/finalization.js +15 -21
  14. package/dist/nodejs/future.d.ts +98 -0
  15. package/dist/nodejs/future.js +176 -0
  16. package/dist/nodejs/http/client.d.ts +22 -0
  17. package/dist/nodejs/http/client.js +138 -0
  18. package/dist/nodejs/http/error.d.ts +18 -0
  19. package/dist/nodejs/http/error.js +62 -0
  20. package/dist/nodejs/http/fields.d.ts +144 -0
  21. package/dist/nodejs/http/fields.js +327 -0
  22. package/dist/nodejs/http/request.d.ts +256 -0
  23. package/dist/nodejs/http/request.js +606 -0
  24. package/dist/nodejs/http/response.d.ts +82 -0
  25. package/dist/nodejs/http/response.js +202 -0
  26. package/dist/nodejs/http/server.d.ts +13 -0
  27. package/dist/nodejs/http/server.js +127 -0
  28. package/dist/nodejs/http.d.ts +19 -0
  29. package/{lib → dist}/nodejs/http.js +13 -18
  30. package/dist/nodejs/index.js +8 -0
  31. package/dist/nodejs/random.d.ts +5 -0
  32. package/{lib → dist}/nodejs/random.js +2 -8
  33. package/dist/nodejs/sockets/address.d.ts +78 -0
  34. package/dist/nodejs/sockets/address.js +120 -0
  35. package/dist/nodejs/sockets/error.d.ts +83 -0
  36. package/dist/nodejs/sockets/error.js +120 -0
  37. package/dist/nodejs/sockets/ip-name-lookup.d.ts +18 -0
  38. package/dist/nodejs/sockets/ip-name-lookup.js +84 -0
  39. package/dist/nodejs/sockets/tcp.d.ts +333 -0
  40. package/dist/nodejs/sockets/tcp.js +723 -0
  41. package/dist/nodejs/sockets/udp.d.ts +224 -0
  42. package/dist/nodejs/sockets/udp.js +475 -0
  43. package/dist/nodejs/sockets.d.ts +11 -0
  44. package/{lib → dist}/nodejs/sockets.js +2 -5
  45. package/dist/nodejs/stream.d.ts +161 -0
  46. package/dist/nodejs/stream.js +388 -0
  47. package/dist/nodejs/workers/cli-worker.d.ts +1 -0
  48. package/dist/nodejs/workers/cli-worker.js +41 -0
  49. package/dist/nodejs/workers/filesystem-worker.d.ts +1 -0
  50. package/dist/nodejs/workers/filesystem-worker.js +102 -0
  51. package/dist/nodejs/workers/http-worker.d.ts +1 -0
  52. package/dist/nodejs/workers/http-worker.js +355 -0
  53. package/dist/nodejs/workers/resource-worker.d.ts +13 -0
  54. package/dist/nodejs/workers/resource-worker.js +152 -0
  55. package/dist/nodejs/workers/tcp-worker.d.ts +2 -0
  56. package/dist/nodejs/workers/tcp-worker.js +318 -0
  57. package/dist/nodejs/workers/udp-worker.d.ts +1 -0
  58. package/dist/nodejs/workers/udp-worker.js +156 -0
  59. package/package.json +20 -12
  60. package/types/interfaces/wasi-cli-environment.d.ts +3 -3
  61. package/types/interfaces/wasi-cli-exit.d.ts +12 -1
  62. package/types/interfaces/wasi-cli-run.d.ts +1 -1
  63. package/types/interfaces/wasi-cli-stderr.d.ts +3 -3
  64. package/types/interfaces/wasi-cli-stdin.d.ts +5 -5
  65. package/types/interfaces/wasi-cli-stdout.d.ts +3 -3
  66. package/types/interfaces/wasi-cli-terminal-input.d.ts +1 -1
  67. package/types/interfaces/wasi-cli-terminal-output.d.ts +1 -1
  68. package/types/interfaces/wasi-cli-terminal-stderr.d.ts +1 -1
  69. package/types/interfaces/wasi-cli-terminal-stdin.d.ts +1 -1
  70. package/types/interfaces/wasi-cli-terminal-stdout.d.ts +1 -1
  71. package/types/interfaces/wasi-cli-types.d.ts +5 -5
  72. package/types/interfaces/wasi-clocks-monotonic-clock.d.ts +3 -3
  73. package/types/interfaces/wasi-clocks-system-clock.d.ts +6 -6
  74. package/types/interfaces/wasi-clocks-types.d.ts +1 -1
  75. package/types/interfaces/wasi-filesystem-preopens.d.ts +1 -1
  76. package/types/interfaces/wasi-filesystem-types.d.ts +74 -74
  77. package/types/interfaces/wasi-http-client.d.ts +1 -1
  78. package/types/interfaces/wasi-http-handler.d.ts +1 -1
  79. package/types/interfaces/wasi-http-types.d.ts +34 -34
  80. package/types/interfaces/wasi-random-insecure-seed.d.ts +5 -5
  81. package/types/interfaces/wasi-random-insecure.d.ts +5 -5
  82. package/types/interfaces/wasi-random-random.d.ts +5 -5
  83. package/types/interfaces/wasi-sockets-ip-name-lookup.d.ts +11 -11
  84. package/types/interfaces/wasi-sockets-types.d.ts +121 -121
  85. package/types/wasi-cli-command.d.ts +23 -23
  86. package/types/wasi-http-service.d.ts +14 -14
  87. package/lib/nodejs/cli.js +0 -127
  88. package/lib/nodejs/clocks.js +0 -98
  89. package/lib/nodejs/filesystem/descriptor.js +0 -1093
  90. package/lib/nodejs/filesystem/error.js +0 -92
  91. package/lib/nodejs/filesystem/utils.js +0 -19
  92. package/lib/nodejs/future.js +0 -190
  93. package/lib/nodejs/http/client.js +0 -161
  94. package/lib/nodejs/http/error.js +0 -71
  95. package/lib/nodejs/http/fields.js +0 -373
  96. package/lib/nodejs/http/request.js +0 -691
  97. package/lib/nodejs/http/response.js +0 -227
  98. package/lib/nodejs/http/server.js +0 -157
  99. package/lib/nodejs/sockets/address.js +0 -146
  100. package/lib/nodejs/sockets/error.js +0 -123
  101. package/lib/nodejs/sockets/ip-name-lookup.js +0 -93
  102. package/lib/nodejs/sockets/tcp.js +0 -801
  103. package/lib/nodejs/sockets/udp.js +0 -516
  104. package/lib/nodejs/stream.js +0 -437
  105. package/lib/nodejs/workers/cli-worker.js +0 -49
  106. package/lib/nodejs/workers/filesystem-worker.js +0 -119
  107. package/lib/nodejs/workers/http-worker.js +0 -417
  108. package/lib/nodejs/workers/resource-worker.js +0 -195
  109. package/lib/nodejs/workers/tcp-worker.js +0 -370
  110. package/lib/nodejs/workers/udp-worker.js +0 -194
  111. /package/{lib/nodejs/filesystem.js → dist/nodejs/filesystem.d.ts} +0 -0
  112. /package/{lib/nodejs/index.js → dist/nodejs/index.d.ts} +0 -0
@@ -0,0 +1,443 @@
1
+ import { StreamReader } from "../stream.js";
2
+ import { FutureReader } from "../future.js";
3
+ declare const symbolDispose: symbol;
4
+ declare class Descriptor {
5
+ #private;
6
+ [symbolDispose]: () => void;
7
+ static _create(handle: any, mode: any, fullPath: any, isDirectory?: boolean): Descriptor;
8
+ static _createPreopen(hostPreopen: any): Descriptor;
9
+ /**
10
+ * Return a stream for reading from a file.
11
+ * WIT:
12
+ * ```
13
+ * read-via-stream: func(offset: filesize) -> tuple<stream<u8>, future<result<_, error-code>>>
14
+ * ```
15
+ *
16
+ * @param {bigint} offset The offset within the file.
17
+ * @returns {{stream: StreamReader, future: FutureReader}}
18
+ * A tuple: a readable byte stream and a future that resolves to an error code.
19
+ * @throws {FSError} `payload.tag` contains mapped WASI error code.
20
+ */
21
+ readViaStream(offset: any): (StreamReader | FutureReader)[];
22
+ /**
23
+ * Write to a file via a byte stream.
24
+ * WIT:
25
+ * ```
26
+ * write-via-stream: async func(data: stream<u8>, offset: filesize) -> result<_, error-code>
27
+ * ```
28
+ *
29
+ * @async
30
+ * @param {object} data A readable byte stream.
31
+ * @param {bigint} offset The offset within the file.
32
+ * @returns {Promise<void>}
33
+ * @throws {FSError} `payload.tag` contains mapped WASI error code.
34
+ */
35
+ writeViaStream(data: any, offset: any): Promise<void>;
36
+ /**
37
+ * Append to a file via a byte stream.
38
+ * WIT:
39
+ * ```
40
+ * append-via-stream: async func(data: stream<u8>) -> result<_, error-code>
41
+ * ```
42
+ *
43
+ * @async
44
+ * @param {object} data A readable byte stream.
45
+ * @returns {Promise<void>}
46
+ * @throws {FSError} `payload.tag` contains mapped WASI error code.
47
+ */
48
+ appendViaStream(data: any): Promise<void>;
49
+ /**
50
+ * Advisory on file access patterns.
51
+ * WIT:
52
+ * ```
53
+ * advise: async func(offset: filesize, length: filesize, advice: advice) -> result<_, error-code>
54
+ * ```
55
+ *
56
+ * @async
57
+ * @param {bigint} offset Start of the region.
58
+ * @param {bigint} length Length of the region.
59
+ * @param {string} advice One of the Wasi `advice` values.
60
+ * @returns {Promise<void>}
61
+ * @throws {FSError} `payload.tag` contains mapped WASI error code.
62
+ */
63
+ advise(_offset: any, _length: any, _advice: any): Promise<void>;
64
+ /**
65
+ * Synchronize file data to disk.
66
+ * WIT:
67
+ * ```
68
+ * sync-data: async func() -> result<_, error-code>
69
+ * ```
70
+ *
71
+ * @async
72
+ * @returns {Promise<void>}
73
+ * @throws {FSError} `payload.tag` contains mapped WASI error code.
74
+ */
75
+ syncData(): Promise<void>;
76
+ /**
77
+ * Get flags associated with a descriptor.
78
+ * WIT:
79
+ * ```
80
+ * get-flags: async func() -> result<descriptor-flags, error-code>
81
+ * ```
82
+ *
83
+ * @async
84
+ * @returns {Promise<object>} The descriptor flags object.
85
+ * @throws {FSError} `payload.tag` contains mapped WASI error code.
86
+ */
87
+ getFlags(): Promise<any>;
88
+ /**
89
+ * Get the dynamic type of a descriptor.
90
+ * WIT:
91
+ * ```
92
+ * get-type: async func() -> result<descriptor-type, error-code>
93
+ * ```
94
+ *
95
+ * @async
96
+ * @returns {Promise<string>} The descriptor type.
97
+ * @throws {FSError} `payload.tag` contains mapped WASI error code.
98
+ */
99
+ getType(): Promise<{
100
+ tag: string;
101
+ val?: undefined;
102
+ } | {
103
+ tag: string;
104
+ val: any;
105
+ }>;
106
+ /**
107
+ * Adjust the size of an open file.
108
+ * WIT:
109
+ * ```
110
+ * set-size: async func(size: filesize) -> result<_, error-code>
111
+ * ```
112
+ *
113
+ * @async
114
+ * @param {bigint} size The new size.
115
+ * @returns {Promise<void>}
116
+ * @throws {FSError} `payload.tag` contains mapped WASI error code.
117
+ */
118
+ setSize(size: any): Promise<void>;
119
+ /**
120
+ * Adjust the timestamps of an open file or directory.
121
+ * WIT:
122
+ * ```
123
+ * set-times: async func(data-access-timestamp: new-timestamp, data-modification-timestamp: new-timestamp) -> result<_, error-code>
124
+ * ```
125
+ *
126
+ * @async
127
+ * @param {object} atimeDesc new-timestamp descriptor
128
+ * @param {object} mtimeDesc new-timestamp descriptor
129
+ * @returns {Promise<void>}
130
+ * @throws {FSError} `payload.tag` contains mapped WASI error code.
131
+ */
132
+ setTimes(atimeDesc: any, mtimeDesc: any): Promise<void>;
133
+ /**
134
+ * Read directory entries via a stream.
135
+ * WIT:
136
+ * ```
137
+ * read-directory: async func() -> tuple<stream<directory-entry>, future<result<_, error-code>>>
138
+ * ```
139
+ *
140
+ * @async
141
+ * @returns {{stream: StreamReader, future: FutureReader}}
142
+ * @throws {FSError} `payload.tag` contains mapped WASI error code.
143
+ */
144
+ readDirectory(): (StreamReader | FutureReader)[];
145
+ /**
146
+ * Synchronize data & metadata to disk.
147
+ * WIT:
148
+ * ```
149
+ * sync: async func() -> result<_, error-code>
150
+ * ```
151
+ *
152
+ * @async
153
+ * @returns {Promise<void>}
154
+ * @throws {FSError} `payload.tag` contains mapped WASI error code.
155
+ */
156
+ sync(): Promise<void>;
157
+ /**
158
+ * Create a directory.
159
+ * WIT:
160
+ * ```
161
+ * create-directory-at: async func(path: string) -> result<_, error-code>
162
+ * ```
163
+ *
164
+ * @async
165
+ * @param {string} path Relative path.
166
+ * @returns {Promise<void>}
167
+ * @throws {FSError} `payload.tag` contains mapped WASI error code.
168
+ */
169
+ createDirectoryAt(path: any): Promise<void>;
170
+ /**
171
+ * Return attributes of an open file or directory.
172
+ * WIT:
173
+ * ```
174
+ * stat: async func() -> result<descriptor-stat, error-code>
175
+ * ```
176
+ *
177
+ * @async
178
+ * @returns {Promise<object>} File statistics.
179
+ * @throws {FSError} `payload.tag` contains mapped WASI error code.
180
+ */
181
+ stat(): Promise<{
182
+ type: {
183
+ tag: string;
184
+ val?: undefined;
185
+ } | {
186
+ tag: string;
187
+ val: any;
188
+ };
189
+ linkCount: any;
190
+ size: any;
191
+ dataAccessTimestamp: {
192
+ seconds: bigint;
193
+ nanoseconds: number;
194
+ };
195
+ dataModificationTimestamp: {
196
+ seconds: bigint;
197
+ nanoseconds: number;
198
+ };
199
+ statusChangeTimestamp: {
200
+ seconds: bigint;
201
+ nanoseconds: number;
202
+ };
203
+ }>;
204
+ /**
205
+ * Adjust timestamps on a file or symlink.
206
+ * WIT:
207
+ * ```
208
+ * set-times-at: async func(
209
+ * path-flags: path-flags,
210
+ * path: string,
211
+ * data-access-timestamp: new-timestamp,
212
+ * data-modification-timestamp: new-timestamp
213
+ * ) -> result<_, error-code>
214
+ * ```
215
+ *
216
+ * @async
217
+ * @param {object} flags Path flags.
218
+ * @param {string} path Relative path.
219
+ * @param {object} atimeDesc New access timestamp.
220
+ * @param {object} mtimeDesc New modification timestamp.
221
+ * @returns {Promise<void>}
222
+ * @throws {FSError} `payload.tag` contains mapped WASI error code.
223
+ */
224
+ statAt(flags: any, path: any): Promise<{
225
+ type: {
226
+ tag: string;
227
+ val?: undefined;
228
+ } | {
229
+ tag: string;
230
+ val: any;
231
+ };
232
+ linkCount: bigint;
233
+ size: bigint;
234
+ dataAccessTimestamp: {
235
+ seconds: bigint;
236
+ nanoseconds: number;
237
+ };
238
+ dataModificationTimestamp: {
239
+ seconds: bigint;
240
+ nanoseconds: number;
241
+ };
242
+ statusChangeTimestamp: {
243
+ seconds: bigint;
244
+ nanoseconds: number;
245
+ };
246
+ }>;
247
+ /**
248
+ * Adjust timestamps on a file or symlink.
249
+ * WIT:
250
+ * ```
251
+ * set-times-at: async func(
252
+ * path-flags: path-flags,
253
+ * path: string,
254
+ * data-access-timestamp: new-timestamp,
255
+ * data-modification-timestamp: new-timestamp
256
+ * ) -> result<_, error-code>
257
+ * ```
258
+ *
259
+ * @async
260
+ * @param {object} flags Path flags.
261
+ * @param {string} path Relative path.
262
+ * @param {object} atimeDesc New access timestamp.
263
+ * @param {object} mtimeDesc New modification timestamp.
264
+ * @returns {Promise<void>}
265
+ * @throws {FSError} `payload.tag` contains mapped WASI error code.
266
+ */
267
+ setTimesAt(flags: any, path: any, atimeDesc: any, mtimeDesc: any): Promise<void>;
268
+ /**
269
+ * Create a hard link.
270
+ * WIT:
271
+ * ```
272
+ * link-at: async func(
273
+ * old-path-flags: path-flags,
274
+ * old-path: string,
275
+ * new-descriptor: borrow<descriptor>,
276
+ * new-path: string
277
+ * ) -> result<_, error-code>
278
+ * ```
279
+ *
280
+ * @async
281
+ * @param {object} oldFlags Old path flags.
282
+ * @param {string} oldPath Source path.
283
+ * @param {Descriptor} newDesc Target descriptor.
284
+ * @param {string} newPath Destination path.
285
+ * @returns {Promise<void>}
286
+ * @throws {FSError} `payload.tag` contains mapped WASI error code.
287
+ */
288
+ linkAt(oldFlags: any, oldPath: any, newDesc: any, newPath: any): Promise<void>;
289
+ /**
290
+ * Open a file or directory.
291
+ * WIT:
292
+ * ```
293
+ * open-at: async func(
294
+ * path-flags: path-flags,
295
+ * path: string,
296
+ * open-flags: open-flags,
297
+ * %flags: descriptor-flags
298
+ * ) -> result<descriptor, error-code>
299
+ * ```
300
+ *
301
+ * @async
302
+ * @param {object} pf - path flags
303
+ * @param {string} path - relative path
304
+ * @param {object} of - open flags
305
+ * @param {object} df - descriptor flags
306
+ * @returns {Promise<Descriptor>}
307
+ * @throws {FSError} `payload.tag` contains mapped WASI error code.
308
+ */
309
+ openAt(pf: any, path: any, of: any, df: any): Promise<Descriptor>;
310
+ /**
311
+ * Read the contents of a symbolic link.
312
+ * WIT:
313
+ * ```
314
+ * readlink-at: async func(path: string) -> result<string, error-code>
315
+ * ```
316
+ *
317
+ * @async
318
+ * @param {string} path Relative path.
319
+ * @returns {Promise<string>}
320
+ * @throws {FSError} `payload.tag` contains mapped WASI error code.
321
+ */
322
+ readlinkAt(path: any): Promise<string>;
323
+ /**
324
+ * Remove a directory.
325
+ * WIT:
326
+ * ```
327
+ * remove-directory-at: async func(path: string) -> result<_, error-code>
328
+ * ```
329
+ *
330
+ * @async
331
+ * @param {string} path Relative path.
332
+ * @returns {Promise<void>}
333
+ * @throws {FSError} `payload.tag` contains mapped WASI error code.
334
+ */
335
+ removeDirectoryAt(path: any): Promise<void>;
336
+ /**
337
+ * Rename a filesystem object.
338
+ * WIT:
339
+ * ```
340
+ * rename-at: async func(old-path: string, new-descriptor: borrow<descriptor>, new-path: string) -> result<_, error-code>
341
+ * ```
342
+ *
343
+ * @async
344
+ * @param {string} oldPath Source path.
345
+ * @param {Descriptor} newDesc Target descriptor.
346
+ * @param {string} newPath Destination path.
347
+ * @returns {Promise<void>}
348
+ * @throws {FSError} `payload.tag` contains mapped WASI error code.
349
+ */
350
+ renameAt(oldPath: any, newDesc: any, newPath: any): Promise<void>;
351
+ /**
352
+ * Create a symbolic link.
353
+ * WIT:
354
+ * ```
355
+ * symlink-at: async func(old-path: string, new-path: string) -> result<_, error-code>
356
+ * ```
357
+ *
358
+ * @async
359
+ * @param {string} target Link target.
360
+ * @param {string} path Destination path.
361
+ * @returns {Promise<void>}
362
+ * @throws {FSError} `payload.tag` contains mapped WASI error code.
363
+ */
364
+ symlinkAt(target: any, path: any): Promise<void>;
365
+ /**
366
+ * Unlink a filesystem object that is not a directory.
367
+ * WIT:
368
+ * ```
369
+ * unlink-file-at: async func(path: string) -> result<_, error-code>
370
+ * ```
371
+ *
372
+ * @async
373
+ * @param {string} path Relative path.
374
+ * @returns {Promise<void>}
375
+ * @throws {FSError} `payload.tag` contains mapped WASI error code.
376
+ */
377
+ unlinkFileAt(path: any): Promise<void>;
378
+ /**
379
+ * Test whether two descriptors refer to the same object.
380
+ * WIT:
381
+ * ```
382
+ * is-same-object: async func(other: borrow<descriptor>) -> bool
383
+ * ```
384
+ *
385
+ * @async
386
+ * @param {Descriptor} other Another descriptor.
387
+ * @returns {Promise<boolean>}
388
+ */
389
+ isSameObject(other: any): Promise<boolean>;
390
+ /**
391
+ * Return a hash of the metadata associated with this descriptor.
392
+ * WIT:
393
+ * ```
394
+ * metadata-hash: async func() -> result<metadata-hash-value, error-code>
395
+ * ```
396
+ *
397
+ * @async
398
+ * @returns {Promise<{upper: bigint, lower: bigint}>}
399
+ * @throws {FSError} `payload.tag` contains mapped WASI error code.
400
+ */
401
+ metadataHash(): Promise<{
402
+ upper: any;
403
+ lower: any;
404
+ }>;
405
+ /**
406
+ * Return a hash of the metadata via path.
407
+ * WIT:
408
+ * ```
409
+ * metadata-hash-at: async func(path-flags: path-flags, path: string) -> result<metadata-hash-value, error-code>
410
+ * ```
411
+ *
412
+ * @async
413
+ * @param {object} flags Path flags.
414
+ * @param {string} path Relative path.
415
+ * @returns {Promise<{upper: bigint, lower: bigint}>}
416
+ * @throws {FSError} `payload.tag` contains mapped WASI error code.
417
+ */
418
+ metadataHashAt(flags: any, path: any): Promise<{
419
+ upper: bigint;
420
+ lower: bigint;
421
+ }>;
422
+ }
423
+ export declare const preopens: {
424
+ Descriptor: typeof Descriptor;
425
+ getDirectories: () => any[];
426
+ };
427
+ export declare const types: {
428
+ Descriptor: typeof Descriptor;
429
+ };
430
+ /**
431
+ * Set the preopen table.
432
+ *
433
+ * @param {Record<string, string>} entries
434
+ */
435
+ export declare function _setPreopens(entries: any): void;
436
+ /**
437
+ * Add a new preopen mapping.
438
+ *
439
+ * @param {string} virtualPath
440
+ * @param {string} hostPreopen
441
+ */
442
+ export declare function _addPreopen(virtualPath: any, hostPreopen: any): void;
443
+ export {};