@bytecodealliance/preview2-shim 0.0.21 → 0.14.1
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.
- package/README.md +4 -14
- package/lib/browser/cli.js +2 -4
- package/lib/browser/clocks.js +15 -27
- package/lib/browser/filesystem.js +2 -30
- package/lib/browser/http.js +1 -3
- package/lib/browser/io.js +4 -2
- package/lib/common/assert.js +7 -0
- package/lib/io/calls.js +64 -0
- package/lib/io/worker-http.js +95 -0
- package/lib/io/worker-io.js +322 -0
- package/lib/io/worker-thread.js +569 -0
- package/lib/nodejs/cli.js +45 -59
- package/lib/nodejs/clocks.js +13 -27
- package/lib/nodejs/filesystem.js +539 -459
- package/lib/nodejs/http.js +440 -173
- package/lib/nodejs/index.js +4 -1
- package/lib/nodejs/io.js +1 -0
- package/lib/nodejs/sockets/socket-common.js +116 -0
- package/lib/nodejs/sockets/socketopts-bindings.js +94 -0
- package/lib/nodejs/sockets/tcp-socket-impl.js +794 -0
- package/lib/nodejs/sockets/udp-socket-impl.js +628 -0
- package/lib/nodejs/sockets/wasi-sockets.js +320 -0
- package/lib/nodejs/sockets.js +11 -200
- package/lib/synckit/index.js +4 -2
- package/package.json +1 -5
- package/types/interfaces/wasi-cli-terminal-input.d.ts +4 -0
- package/types/interfaces/wasi-cli-terminal-output.d.ts +4 -0
- package/types/interfaces/wasi-clocks-monotonic-clock.d.ts +19 -6
- package/types/interfaces/wasi-filesystem-types.d.ts +1 -178
- package/types/interfaces/wasi-http-outgoing-handler.d.ts +2 -2
- package/types/interfaces/wasi-http-types.d.ts +412 -82
- package/types/interfaces/wasi-io-error.d.ts +16 -0
- package/types/interfaces/wasi-io-poll.d.ts +19 -8
- package/types/interfaces/wasi-io-streams.d.ts +26 -46
- package/types/interfaces/wasi-sockets-ip-name-lookup.d.ts +9 -21
- package/types/interfaces/wasi-sockets-network.d.ts +4 -0
- package/types/interfaces/wasi-sockets-tcp.d.ts +75 -18
- package/types/interfaces/wasi-sockets-udp-create-socket.d.ts +1 -1
- package/types/interfaces/wasi-sockets-udp.d.ts +282 -193
- package/types/wasi-cli-command.d.ts +28 -28
- package/types/wasi-http-proxy.d.ts +12 -12
- package/lib/common/io.js +0 -183
- package/lib/common/make-request.js +0 -30
- package/types/interfaces/wasi-clocks-timezone.d.ts +0 -56
package/lib/common/io.js
DELETED
|
@@ -1,183 +0,0 @@
|
|
|
1
|
-
let id = 0;
|
|
2
|
-
|
|
3
|
-
const symbolDispose = Symbol.dispose || Symbol.for('dispose');
|
|
4
|
-
|
|
5
|
-
class Error {
|
|
6
|
-
constructor (msg) {
|
|
7
|
-
this.msg = msg;
|
|
8
|
-
}
|
|
9
|
-
toDebugString () {
|
|
10
|
-
return this.msg;
|
|
11
|
-
}
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
/**
|
|
15
|
-
* @typedef {{
|
|
16
|
-
* read?: (len: BigInt) => Uint8Array,
|
|
17
|
-
* blockingRead: (len: BigInt) => Uint8Array,
|
|
18
|
-
* skip?: (len: BigInt) => BigInt,
|
|
19
|
-
* blockingSkip?: (len: BigInt) => BigInt,
|
|
20
|
-
* subscribe: () => void,
|
|
21
|
-
* drop?: () => void,
|
|
22
|
-
* }} InputStreamHandler
|
|
23
|
-
*
|
|
24
|
-
* @typedef {{
|
|
25
|
-
* checkWrite?: () -> BigInt,
|
|
26
|
-
* write: (buf: Uint8Array) => BigInt,
|
|
27
|
-
* blockingWriteAndFlush?: (buf: Uint8Array) => void,
|
|
28
|
-
* flush?: () => void,
|
|
29
|
-
* blockingFlush: () => void,
|
|
30
|
-
* writeZeroes?: (len: BigInt) => void,
|
|
31
|
-
* blockingWriteZeroes?: (len: BigInt) => void,
|
|
32
|
-
* blockingWriteZeroesAndFlush?: (len: BigInt) => void,
|
|
33
|
-
* splice?: (src: InputStream, len: BigInt) => BigInt,
|
|
34
|
-
* blockingSplice?: (src: InputStream, len: BigInt) => BigInt,
|
|
35
|
-
* forward?: (src: InputStream) => void,
|
|
36
|
-
* subscribe?: () => void,
|
|
37
|
-
* drop?: () => void,
|
|
38
|
-
* }} OutputStreamHandler
|
|
39
|
-
*
|
|
40
|
-
**/
|
|
41
|
-
|
|
42
|
-
class InputStream {
|
|
43
|
-
/**
|
|
44
|
-
* @param {InputStreamHandler} handler
|
|
45
|
-
*/
|
|
46
|
-
constructor (handler) {
|
|
47
|
-
if (!handler)
|
|
48
|
-
console.trace('no handler');
|
|
49
|
-
this.id = ++id;
|
|
50
|
-
this.handler = handler;
|
|
51
|
-
}
|
|
52
|
-
read(len) {
|
|
53
|
-
if (this.handler.read)
|
|
54
|
-
return this.handler.read(len);
|
|
55
|
-
return this.handler.blockingRead.call(this, len);
|
|
56
|
-
}
|
|
57
|
-
blockingRead(len) {
|
|
58
|
-
return this.handler.blockingRead.call(this, len);
|
|
59
|
-
}
|
|
60
|
-
skip(len) {
|
|
61
|
-
if (this.handler.skip)
|
|
62
|
-
return this.handler.skip.call(this, len);
|
|
63
|
-
if (this.handler.read) {
|
|
64
|
-
const bytes = this.handler.read.call(this, len);
|
|
65
|
-
return BigInt(bytes.byteLength);
|
|
66
|
-
}
|
|
67
|
-
return this.blockingSkip.call(this, len);
|
|
68
|
-
}
|
|
69
|
-
blockingSkip(len) {
|
|
70
|
-
if (this.handler.blockingSkip)
|
|
71
|
-
return this.handler.blockingSkip.call(this, len);
|
|
72
|
-
const bytes = this.handler.blockingRead.call(this, len);
|
|
73
|
-
return BigInt(bytes.byteLength);
|
|
74
|
-
}
|
|
75
|
-
subscribe() {
|
|
76
|
-
console.log(`[streams] Subscribe to input stream ${this.id}`);
|
|
77
|
-
}
|
|
78
|
-
[symbolDispose] () {
|
|
79
|
-
if (this.handler.drop)
|
|
80
|
-
this.handler.drop.call(this);
|
|
81
|
-
}
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
class OutputStream {
|
|
85
|
-
/**
|
|
86
|
-
* @param {OutputStreamHandler} handler
|
|
87
|
-
*/
|
|
88
|
-
constructor (handler) {
|
|
89
|
-
if (!handler)
|
|
90
|
-
console.trace('no handler');
|
|
91
|
-
this.id = ++id;
|
|
92
|
-
this.open = true;
|
|
93
|
-
this.handler = handler;
|
|
94
|
-
}
|
|
95
|
-
checkWrite(len) {
|
|
96
|
-
if (!this.open)
|
|
97
|
-
return 0n;
|
|
98
|
-
if (this.handler.checkWrite)
|
|
99
|
-
return this.handler.checkWrite.call(this, len);
|
|
100
|
-
return 1_000_000n;
|
|
101
|
-
}
|
|
102
|
-
write(buf) {
|
|
103
|
-
this.handler.write.call(this, buf);
|
|
104
|
-
}
|
|
105
|
-
blockingWriteAndFlush(buf) {
|
|
106
|
-
/// Perform a write of up to 4096 bytes, and then flush the stream. Block
|
|
107
|
-
/// until all of these operations are complete, or an error occurs.
|
|
108
|
-
///
|
|
109
|
-
/// This is a convenience wrapper around the use of `check-write`,
|
|
110
|
-
/// `subscribe`, `write`, and `flush`, and is implemented with the
|
|
111
|
-
/// following pseudo-code:
|
|
112
|
-
///
|
|
113
|
-
/// ```text
|
|
114
|
-
/// let pollable = this.subscribe();
|
|
115
|
-
/// while !contents.is_empty() {
|
|
116
|
-
/// // Wait for the stream to become writable
|
|
117
|
-
/// poll-one(pollable);
|
|
118
|
-
/// let Ok(n) = this.check-write(); // eliding error handling
|
|
119
|
-
/// let len = min(n, contents.len());
|
|
120
|
-
/// let (chunk, rest) = contents.split_at(len);
|
|
121
|
-
/// this.write(chunk ); // eliding error handling
|
|
122
|
-
/// contents = rest;
|
|
123
|
-
/// }
|
|
124
|
-
/// this.flush();
|
|
125
|
-
/// // Wait for completion of `flush`
|
|
126
|
-
/// poll-one(pollable);
|
|
127
|
-
/// // Check for any errors that arose during `flush`
|
|
128
|
-
/// let _ = this.check-write(); // eliding error handling
|
|
129
|
-
/// ```
|
|
130
|
-
this.handler.write.call(this, buf);
|
|
131
|
-
}
|
|
132
|
-
flush() {
|
|
133
|
-
if (this.handler.flush)
|
|
134
|
-
this.handler.flush.call(this);
|
|
135
|
-
}
|
|
136
|
-
blockingFlush() {
|
|
137
|
-
this.open = true;
|
|
138
|
-
}
|
|
139
|
-
writeZeroes(len) {
|
|
140
|
-
this.write.call(this, new Uint8Array(Number(len)));
|
|
141
|
-
}
|
|
142
|
-
blockingWriteZeroes(len) {
|
|
143
|
-
this.blockingWrite.call(this, new Uint8Array(Number(len)));
|
|
144
|
-
}
|
|
145
|
-
blockingWriteZeroesAndFlush(len) {
|
|
146
|
-
this.blockingWriteAndFlush.call(this, new Uint8Array(Number(len)));
|
|
147
|
-
}
|
|
148
|
-
splice(src, len) {
|
|
149
|
-
const spliceLen = Math.min(len, this.checkWrite.call(this));
|
|
150
|
-
const bytes = src.read(spliceLen);
|
|
151
|
-
this.write.call(this, bytes);
|
|
152
|
-
return bytes.byteLength;
|
|
153
|
-
}
|
|
154
|
-
blockingSplice(_src, _len) {
|
|
155
|
-
console.log(`[streams] Blocking splice ${this.id}`);
|
|
156
|
-
}
|
|
157
|
-
forward(_src) {
|
|
158
|
-
console.log(`[streams] Forward ${this.id}`);
|
|
159
|
-
}
|
|
160
|
-
subscribe() {
|
|
161
|
-
console.log(`[streams] Subscribe to output stream ${this.id}`);
|
|
162
|
-
}
|
|
163
|
-
[symbolDispose]() {
|
|
164
|
-
}
|
|
165
|
-
}
|
|
166
|
-
|
|
167
|
-
export const streams = { Error, InputStream, OutputStream };
|
|
168
|
-
|
|
169
|
-
class Pollable {}
|
|
170
|
-
|
|
171
|
-
function pollList (_list) {
|
|
172
|
-
// TODO
|
|
173
|
-
}
|
|
174
|
-
|
|
175
|
-
function pollOne (_poll) {
|
|
176
|
-
// TODO
|
|
177
|
-
}
|
|
178
|
-
|
|
179
|
-
export const poll = {
|
|
180
|
-
Pollable,
|
|
181
|
-
pollList,
|
|
182
|
-
pollOne
|
|
183
|
-
};
|
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
import { runAsWorker } from "../synckit/index.js";
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* @param {import("../../types/interfaces/wasi-http-types").Request} req
|
|
5
|
-
* @returns {Promise<string>}
|
|
6
|
-
*/
|
|
7
|
-
async function makeRequest(req) {
|
|
8
|
-
try {
|
|
9
|
-
let headers = new Headers(req.headers);
|
|
10
|
-
const resp = await fetch(req.uri, {
|
|
11
|
-
method: req.method.toString(),
|
|
12
|
-
headers,
|
|
13
|
-
body: req.body && req.body.length > 0 ? req.body : undefined,
|
|
14
|
-
redirect: "manual",
|
|
15
|
-
});
|
|
16
|
-
let arrayBuffer = await resp.arrayBuffer();
|
|
17
|
-
return JSON.stringify({
|
|
18
|
-
status: resp.status,
|
|
19
|
-
headers: Array.from(resp.headers),
|
|
20
|
-
body:
|
|
21
|
-
arrayBuffer.byteLength > 0
|
|
22
|
-
? Buffer.from(arrayBuffer).toString("base64")
|
|
23
|
-
: undefined,
|
|
24
|
-
});
|
|
25
|
-
} catch (err) {
|
|
26
|
-
return JSON.stringify({ message: err.toString() });
|
|
27
|
-
}
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
runAsWorker(makeRequest);
|
|
@@ -1,56 +0,0 @@
|
|
|
1
|
-
export namespace WasiClocksTimezone {
|
|
2
|
-
/**
|
|
3
|
-
* Return information needed to display the given `datetime`. This includes
|
|
4
|
-
* the UTC offset, the time zone name, and a flag indicating whether
|
|
5
|
-
* daylight saving time is active.
|
|
6
|
-
*
|
|
7
|
-
* If the timezone cannot be determined for the given `datetime`, return a
|
|
8
|
-
* `timezone-display` for `UTC` with a `utc-offset` of 0 and no daylight
|
|
9
|
-
* saving time.
|
|
10
|
-
*/
|
|
11
|
-
export function display(when: Datetime): TimezoneDisplay;
|
|
12
|
-
/**
|
|
13
|
-
* The same as `display`, but only return the UTC offset.
|
|
14
|
-
*/
|
|
15
|
-
export function utcOffset(when: Datetime): number;
|
|
16
|
-
}
|
|
17
|
-
import type { Datetime } from '../interfaces/wasi-clocks-wall-clock.js';
|
|
18
|
-
export { Datetime };
|
|
19
|
-
/**
|
|
20
|
-
* Information useful for displaying the timezone of a specific `datetime`.
|
|
21
|
-
*
|
|
22
|
-
* This information may vary within a single `timezone` to reflect daylight
|
|
23
|
-
* saving time adjustments.
|
|
24
|
-
*/
|
|
25
|
-
export interface TimezoneDisplay {
|
|
26
|
-
/**
|
|
27
|
-
* The number of seconds difference between UTC time and the local
|
|
28
|
-
* time of the timezone.
|
|
29
|
-
*
|
|
30
|
-
* The returned value will always be less than 86400 which is the
|
|
31
|
-
* number of seconds in a day (24*60*60).
|
|
32
|
-
*
|
|
33
|
-
* In implementations that do not expose an actual time zone, this
|
|
34
|
-
* should return 0.
|
|
35
|
-
*/
|
|
36
|
-
utcOffset: number,
|
|
37
|
-
/**
|
|
38
|
-
* The abbreviated name of the timezone to display to a user. The name
|
|
39
|
-
* `UTC` indicates Coordinated Universal Time. Otherwise, this should
|
|
40
|
-
* reference local standards for the name of the time zone.
|
|
41
|
-
*
|
|
42
|
-
* In implementations that do not expose an actual time zone, this
|
|
43
|
-
* should be the string `UTC`.
|
|
44
|
-
*
|
|
45
|
-
* In time zones that do not have an applicable name, a formatted
|
|
46
|
-
* representation of the UTC offset may be returned, such as `-04:00`.
|
|
47
|
-
*/
|
|
48
|
-
name: string,
|
|
49
|
-
/**
|
|
50
|
-
* Whether daylight saving time is active.
|
|
51
|
-
*
|
|
52
|
-
* In implementations that do not expose an actual time zone, this
|
|
53
|
-
* should return false.
|
|
54
|
-
*/
|
|
55
|
-
inDaylightSavingTime: boolean,
|
|
56
|
-
}
|