@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,180 +0,0 @@
1
- export namespace ImportsStreams {
2
- /**
3
- * Read bytes from a stream.
4
- *
5
- * This function returns a list of bytes containing the data that was
6
- * read, along with a bool which, when true, indicates that the end of the
7
- * stream was reached. The returned list will contain up to `len` bytes; it
8
- * may return fewer than requested, but not more.
9
- *
10
- * Once a stream has reached the end, subsequent calls to read or
11
- * `skip` will always report end-of-stream rather than producing more
12
- * data.
13
- *
14
- * If `len` is 0, it represents a request to read 0 bytes, which should
15
- * always succeed, assuming the stream hasn't reached its end yet, and
16
- * return an empty list.
17
- *
18
- * The len here is a `u64`, but some callees may not be able to allocate
19
- * a buffer as large as that would imply.
20
- * FIXME: describe what happens if allocation fails.
21
- */
22
- export function read(this: InputStream, len: bigint): [Uint8Array | ArrayBuffer, boolean];
23
- /**
24
- * Read bytes from a stream, with blocking.
25
- *
26
- * This is similar to `read`, except that it blocks until at least one
27
- * byte can be read.
28
- */
29
- export function blockingRead(this: InputStream, len: bigint): [Uint8Array | ArrayBuffer, boolean];
30
- /**
31
- * Skip bytes from a stream.
32
- *
33
- * This is similar to the `read` function, but avoids copying the
34
- * bytes into the instance.
35
- *
36
- * Once a stream has reached the end, subsequent calls to read or
37
- * `skip` will always report end-of-stream rather than producing more
38
- * data.
39
- *
40
- * This function returns the number of bytes skipped, along with a bool
41
- * indicating whether the end of the stream was reached. The returned
42
- * value will be at most `len`; it may be less.
43
- */
44
- export function skip(this: InputStream, len: bigint): [bigint, boolean];
45
- /**
46
- * Skip bytes from a stream, with blocking.
47
- *
48
- * This is similar to `skip`, except that it blocks until at least one
49
- * byte can be consumed.
50
- */
51
- export function blockingSkip(this: InputStream, len: bigint): [bigint, boolean];
52
- /**
53
- * Create a `pollable` which will resolve once either the specified stream
54
- * has bytes available to read or the other end of the stream has been
55
- * closed.
56
- */
57
- export function subscribeToInputStream(this: InputStream): Pollable;
58
- /**
59
- * Dispose of the specified `input-stream`, after which it may no longer
60
- * be used.
61
- */
62
- export function dropInputStream(this: InputStream): void;
63
- /**
64
- * Write bytes to a stream.
65
- *
66
- * This function returns a `u64` indicating the number of bytes from
67
- * `buf` that were written; it may be less than the full list.
68
- */
69
- export function write(this: OutputStream, buf: Uint8Array): bigint;
70
- /**
71
- * Write bytes to a stream, with blocking.
72
- *
73
- * This is similar to `write`, except that it blocks until at least one
74
- * byte can be written.
75
- */
76
- export function blockingWrite(this: OutputStream, buf: Uint8Array): bigint;
77
- /**
78
- * Write multiple zero bytes to a stream.
79
- *
80
- * This function returns a `u64` indicating the number of zero bytes
81
- * that were written; it may be less than `len`.
82
- */
83
- export function writeZeroes(this: OutputStream, len: bigint): bigint;
84
- /**
85
- * Write multiple zero bytes to a stream, with blocking.
86
- *
87
- * This is similar to `write-zeroes`, except that it blocks until at least
88
- * one byte can be written.
89
- */
90
- export function blockingWriteZeroes(this: OutputStream, len: bigint): bigint;
91
- /**
92
- * Read from one stream and write to another.
93
- *
94
- * This function returns the number of bytes transferred; it may be less
95
- * than `len`.
96
- *
97
- * Unlike other I/O functions, this function blocks until all the data
98
- * read from the input stream has been written to the output stream.
99
- */
100
- export function splice(this: OutputStream, src: InputStream, len: bigint): [bigint, boolean];
101
- /**
102
- * Read from one stream and write to another, with blocking.
103
- *
104
- * This is similar to `splice`, except that it blocks until at least
105
- * one byte can be read.
106
- */
107
- export function blockingSplice(this: OutputStream, src: InputStream, len: bigint): [bigint, boolean];
108
- /**
109
- * Forward the entire contents of an input stream to an output stream.
110
- *
111
- * This function repeatedly reads from the input stream and writes
112
- * the data to the output stream, until the end of the input stream
113
- * is reached, or an error is encountered.
114
- *
115
- * Unlike other I/O functions, this function blocks until the end
116
- * of the input stream is seen and all the data has been written to
117
- * the output stream.
118
- *
119
- * This function returns the number of bytes transferred.
120
- */
121
- export function forward(this: OutputStream, src: InputStream): bigint;
122
- /**
123
- * Create a `pollable` which will resolve once either the specified stream
124
- * is ready to accept bytes or the other end of the stream has been closed.
125
- */
126
- export function subscribeToOutputStream(this: OutputStream): Pollable;
127
- /**
128
- * Dispose of the specified `output-stream`, after which it may no longer
129
- * be used.
130
- */
131
- export function dropOutputStream(this: OutputStream): void;
132
- }
133
- import type { Pollable } from '../imports/poll';
134
- export { Pollable };
135
- /**
136
- * An error type returned from a stream operation. Currently this
137
- * doesn't provide any additional information.
138
- */
139
- export interface StreamError {
140
- }
141
- /**
142
- * An output bytestream. In the future, this will be replaced by handle
143
- * types.
144
- *
145
- * This conceptually represents a `stream<u8, _>`. It's temporary
146
- * scaffolding until component-model's async features are ready.
147
- *
148
- * `output-stream`s are *non-blocking* to the extent practical on
149
- * underlying platforms. Except where specified otherwise, I/O operations also
150
- * always return promptly, after the number of bytes that can be written
151
- * promptly, which could even be zero. To wait for the stream to be ready to
152
- * accept data, the `subscribe-to-output-stream` function to obtain a
153
- * `pollable` which can be polled for using `wasi_poll`.
154
- *
155
- * And at present, it is a `u32` instead of being an actual handle, until
156
- * the wit-bindgen implementation of handles and resources is ready.
157
- *
158
- * This [represents a resource](https://github.com/WebAssembly/WASI/blob/main/docs/WitInWasi.md#Resources).
159
- */
160
- export type OutputStream = number;
161
- /**
162
- * An input bytestream. In the future, this will be replaced by handle
163
- * types.
164
- *
165
- * This conceptually represents a `stream<u8, _>`. It's temporary
166
- * scaffolding until component-model's async features are ready.
167
- *
168
- * `input-stream`s are *non-blocking* to the extent practical on underlying
169
- * platforms. I/O operations always return promptly; if fewer bytes are
170
- * promptly available than requested, they return the number of bytes promptly
171
- * available, which could even be zero. To wait for data to be available,
172
- * use the `subscribe-to-input-stream` function to obtain a `pollable` which
173
- * can be polled for using `wasi_poll`.
174
- *
175
- * And at present, it is a `u32` instead of being an actual handle, until
176
- * the wit-bindgen implementation of handles and resources is ready.
177
- *
178
- * This [represents a resource](https://github.com/WebAssembly/WASI/blob/main/docs/WitInWasi.md#Resources).
179
- */
180
- export type InputStream = number;
@@ -1,23 +0,0 @@
1
- import { ImportsEnvironment } from './imports/environment';
2
- import { ImportsExit } from './imports/exit';
3
- import { ImportsPreopens } from './imports/preopens';
4
- import { ImportsStderr } from './imports/stderr';
5
- import { ImportsStdin } from './imports/stdin';
6
- import { ImportsStdout } from './imports/stdout';
7
- import { ImportsMonotonicClock } from './imports/monotonic-clock';
8
- import { ImportsTimezone } from './imports/timezone';
9
- import { ImportsWallClock } from './imports/wall-clock';
10
- import { ImportsFilesystem } from './imports/filesystem';
11
- import { ImportsStreams } from './imports/streams';
12
- import { ImportsPoll } from './imports/poll';
13
- import { ImportsInsecure } from './imports/insecure';
14
- import { ImportsInsecureSeed } from './imports/insecure-seed';
15
- import { ImportsRandom } from './imports/random';
16
- import { ImportsInstanceNetwork } from './imports/instance-network';
17
- import { ImportsIpNameLookup } from './imports/ip-name-lookup';
18
- import { ImportsNetwork } from './imports/network';
19
- import { ImportsTcp } from './imports/tcp';
20
- import { ImportsTcpCreateSocket } from './imports/tcp-create-socket';
21
- import { ImportsUdp } from './imports/udp';
22
- import { ImportsUdpCreateSocket } from './imports/udp-create-socket';
23
- export function run(): void;
@@ -1,10 +0,0 @@
1
- import { ImportsOutgoingHandler } from './imports/outgoing-handler';
2
- import { ImportsTypes } from './imports/types';
3
- import { ImportsStreams } from './imports/streams';
4
- import { ImportsHandler } from './imports/handler';
5
- import { ImportsPoll } from './imports/poll';
6
- import { ImportsInsecure } from './imports/insecure';
7
- import { ImportsInsecureSeed } from './imports/insecure-seed';
8
- import { ImportsRandom } from './imports/random';
9
- import { ExportsWasiHttpIncomingHandler } from './exports/wasi-http-incoming-handler';
10
- export const incomingHandler: typeof ExportsWasiHttpIncomingHandler;
@@ -1,23 +0,0 @@
1
- import { ImportsEnvironment } from './imports/environment';
2
- import { ImportsExit } from './imports/exit';
3
- import { ImportsPreopens } from './imports/preopens';
4
- import { ImportsStderr } from './imports/stderr';
5
- import { ImportsStdin } from './imports/stdin';
6
- import { ImportsStdout } from './imports/stdout';
7
- import { ImportsMonotonicClock } from './imports/monotonic-clock';
8
- import { ImportsTimezone } from './imports/timezone';
9
- import { ImportsWallClock } from './imports/wall-clock';
10
- import { ImportsFilesystem } from './imports/filesystem';
11
- import { ImportsOutgoingHandler } from './imports/outgoing-handler';
12
- import { ImportsTypes } from './imports/types';
13
- import { ImportsStreams } from './imports/streams';
14
- import { ImportsHandler } from './imports/handler';
15
- import { ImportsPoll } from './imports/poll';
16
- import { ImportsRandom } from './imports/random';
17
- import { ImportsInstanceNetwork } from './imports/instance-network';
18
- import { ImportsIpNameLookup } from './imports/ip-name-lookup';
19
- import { ImportsNetwork } from './imports/network';
20
- import { ImportsTcp } from './imports/tcp';
21
- import { ImportsTcpCreateSocket } from './imports/tcp-create-socket';
22
- import { ImportsUdp } from './imports/udp';
23
- import { ImportsUdpCreateSocket } from './imports/udp-create-socket';