@bytecodealliance/preview2-shim 0.0.13 → 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.
- package/README.md +2 -2
- package/lib/browser/cli.js +21 -6
- package/lib/browser/filesystem.js +204 -20
- package/lib/browser/http.js +4 -7
- package/lib/browser/io.js +76 -17
- package/lib/browser/logging.js +2 -2
- package/lib/browser/poll.js +48 -4
- package/lib/http/error.js +1 -1
- package/lib/http/make-request.js +3 -2
- package/lib/http/wasi-http.js +52 -40
- package/lib/nodejs/cli.js +17 -7
- package/lib/nodejs/http.js +4 -7
- package/lib/nodejs/logging.js +2 -2
- package/package.json +1 -1
- package/types/exports/wasi-cli-environment.d.ts +22 -0
- package/types/exports/wasi-cli-exit.d.ts +7 -0
- package/types/exports/wasi-cli-run.d.ts +6 -0
- package/types/exports/wasi-cli-stderr.d.ts +5 -0
- package/types/exports/wasi-cli-stdin.d.ts +5 -0
- package/types/exports/wasi-cli-stdout.d.ts +5 -0
- package/types/exports/wasi-cli-terminal-input.d.ts +13 -0
- package/types/exports/wasi-cli-terminal-output.d.ts +13 -0
- package/types/exports/wasi-cli-terminal-stderr.d.ts +9 -0
- package/types/exports/wasi-cli-terminal-stdin.d.ts +9 -0
- package/types/exports/wasi-cli-terminal-stdout.d.ts +9 -0
- package/types/exports/wasi-clocks-monotonic-clock.d.ts +24 -0
- package/types/exports/wasi-clocks-timezone.d.ts +71 -0
- package/types/exports/wasi-clocks-wall-clock.d.ts +31 -0
- package/types/exports/wasi-filesystem-preopens.d.ts +8 -0
- package/types/exports/wasi-filesystem-types.d.ts +843 -0
- package/types/exports/wasi-http-incoming-handler.d.ts +7 -0
- package/types/exports/wasi-http-outgoing-handler.d.ts +9 -0
- package/types/exports/wasi-http-types.d.ts +118 -0
- package/types/exports/wasi-io-streams.d.ts +220 -0
- package/types/exports/wasi-poll-poll.d.ts +39 -0
- package/types/exports/wasi-random-insecure-seed.d.ts +22 -0
- package/types/exports/wasi-random-insecure.d.ts +20 -0
- package/types/exports/wasi-random-random.d.ts +22 -0
- package/types/exports/wasi-sockets-instance-network.d.ts +8 -0
- package/types/exports/wasi-sockets-ip-name-lookup.d.ts +76 -0
- package/types/exports/wasi-sockets-network.d.ts +180 -0
- package/types/exports/wasi-sockets-tcp-create-socket.d.ts +33 -0
- package/types/exports/wasi-sockets-tcp.d.ts +285 -0
- package/types/exports/wasi-sockets-udp-create-socket.d.ts +33 -0
- package/types/exports/wasi-sockets-udp.d.ts +228 -0
- package/types/imports/wasi-cli-environment.d.ts +22 -0
- package/types/imports/wasi-cli-exit.d.ts +7 -0
- package/types/imports/wasi-cli-stderr.d.ts +5 -0
- package/types/imports/wasi-cli-stdin.d.ts +5 -0
- package/types/imports/wasi-cli-stdout.d.ts +5 -0
- package/types/imports/wasi-cli-terminal-input.d.ts +13 -0
- package/types/imports/wasi-cli-terminal-output.d.ts +13 -0
- package/types/imports/wasi-cli-terminal-stderr.d.ts +9 -0
- package/types/imports/wasi-cli-terminal-stdin.d.ts +9 -0
- package/types/imports/wasi-cli-terminal-stdout.d.ts +9 -0
- package/types/imports/wasi-clocks-monotonic-clock.d.ts +24 -0
- package/types/imports/wasi-clocks-timezone.d.ts +71 -0
- package/types/imports/wasi-clocks-wall-clock.d.ts +31 -0
- package/types/imports/wasi-filesystem-preopens.d.ts +8 -0
- package/types/imports/wasi-filesystem-types.d.ts +843 -0
- package/types/imports/wasi-http-outgoing-handler.d.ts +9 -0
- package/types/imports/wasi-http-types.d.ts +118 -0
- package/types/imports/wasi-io-streams.d.ts +220 -0
- package/types/imports/wasi-poll-poll.d.ts +39 -0
- package/types/imports/wasi-random-insecure-seed.d.ts +22 -0
- package/types/imports/wasi-random-insecure.d.ts +20 -0
- package/types/imports/wasi-random-random.d.ts +22 -0
- package/types/imports/wasi-sockets-instance-network.d.ts +8 -0
- package/types/imports/wasi-sockets-ip-name-lookup.d.ts +76 -0
- package/types/imports/wasi-sockets-network.d.ts +180 -0
- package/types/imports/wasi-sockets-tcp-create-socket.d.ts +33 -0
- package/types/imports/wasi-sockets-tcp.d.ts +285 -0
- package/types/imports/wasi-sockets-udp-create-socket.d.ts +33 -0
- package/types/imports/wasi-sockets-udp.d.ts +228 -0
- package/types/wasi-cli-command.d.ts +29 -0
- package/types/wasi-http-proxy.d.ts +13 -0
package/lib/http/wasi-http.js
CHANGED
|
@@ -1,18 +1,19 @@
|
|
|
1
1
|
// Based on:
|
|
2
|
-
// https://github.com/bytecodealliance/wasmtime/blob/
|
|
2
|
+
// https://github.com/bytecodealliance/wasmtime/blob/8efcb9851602287fd07a1a1e91501f51f2653d7e/crates/wasi-http/
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
|
-
* @typedef {import("../../types/imports/types").Fields} Fields
|
|
6
|
-
* @typedef {import("../../types/imports/types").FutureIncomingResponse} FutureIncomingResponse
|
|
7
|
-
* @typedef {import("../../types/imports/types").Headers} Headers
|
|
8
|
-
* @typedef {import("../../types/imports/types").IncomingResponse} IncomingResponse
|
|
9
|
-
* @typedef {import("../../types/imports/types").IncomingStream} IncomingStream
|
|
10
|
-
* @typedef {import("../../types/imports/types").Method} Method
|
|
11
|
-
* @typedef {import("../../types/imports/types").OutgoingRequest} OutgoingRequest
|
|
12
|
-
* @typedef {import("../../types/imports/types").RequestOptions} RequestOptions
|
|
13
|
-
* @typedef {import("../../types/imports/types").Result} Result
|
|
14
|
-
* @typedef {import("../../types/imports/types").Scheme} Scheme
|
|
15
|
-
* @typedef {import("../../types/imports/types").StatusCode} StatusCode
|
|
5
|
+
* @typedef {import("../../types/imports/wasi-http-types").Fields} Fields
|
|
6
|
+
* @typedef {import("../../types/imports/wasi-http-types").FutureIncomingResponse} FutureIncomingResponse
|
|
7
|
+
* @typedef {import("../../types/imports/wasi-http-types").Headers} Headers
|
|
8
|
+
* @typedef {import("../../types/imports/wasi-http-types").IncomingResponse} IncomingResponse
|
|
9
|
+
* @typedef {import("../../types/imports/wasi-http-types").IncomingStream} IncomingStream
|
|
10
|
+
* @typedef {import("../../types/imports/wasi-http-types").Method} Method
|
|
11
|
+
* @typedef {import("../../types/imports/wasi-http-types").OutgoingRequest} OutgoingRequest
|
|
12
|
+
* @typedef {import("../../types/imports/wasi-http-types").RequestOptions} RequestOptions
|
|
13
|
+
* @typedef {import("../../types/imports/wasi-http-types").Result} Result
|
|
14
|
+
* @typedef {import("../../types/imports/wasi-http-types").Scheme} Scheme
|
|
15
|
+
* @typedef {import("../../types/imports/wasi-http-types").StatusCode} StatusCode
|
|
16
|
+
* @typedef {import("../../types/imports/wasi-io-streams").StreamStatus} StreamStatus
|
|
16
17
|
*/
|
|
17
18
|
|
|
18
19
|
import * as io from '@bytecodealliance/preview2-shim/io';
|
|
@@ -48,12 +49,14 @@ export class WasiHttp {
|
|
|
48
49
|
|
|
49
50
|
const scheme = request.scheme.tag === "HTTP" ? "http://" : "https://";
|
|
50
51
|
|
|
51
|
-
const url = scheme + request.authority + request.
|
|
52
|
+
const url = scheme + request.authority + request.pathWithQuery;
|
|
52
53
|
const headers = {
|
|
53
54
|
"host": request.authority,
|
|
54
55
|
};
|
|
55
|
-
|
|
56
|
-
|
|
56
|
+
if (request.headers && request.headers.size > 0) {
|
|
57
|
+
for (const [key, value] of request.headers.entries()) {
|
|
58
|
+
headers[key] = Array.isArray(value) ? value.join(",") : value;
|
|
59
|
+
}
|
|
57
60
|
}
|
|
58
61
|
const body = this.streams.get(request.body);
|
|
59
62
|
|
|
@@ -66,8 +69,10 @@ export class WasiHttp {
|
|
|
66
69
|
});
|
|
67
70
|
|
|
68
71
|
response.status = res.status;
|
|
69
|
-
|
|
70
|
-
|
|
72
|
+
if (res.headers && res.headers.size > 0) {
|
|
73
|
+
for (const [key, value] of res.headers) {
|
|
74
|
+
response.responseHeaders.set(key, [value]);
|
|
75
|
+
}
|
|
71
76
|
}
|
|
72
77
|
const buf = res.body;
|
|
73
78
|
response.body = this.streamIdBase;
|
|
@@ -82,25 +87,29 @@ export class WasiHttp {
|
|
|
82
87
|
return futureId;
|
|
83
88
|
}
|
|
84
89
|
|
|
90
|
+
read = (stream, len) => {
|
|
91
|
+
return this.blockingRead(stream, len);
|
|
92
|
+
}
|
|
93
|
+
|
|
85
94
|
/**
|
|
86
95
|
* @param {InputStream} stream
|
|
87
96
|
* @param {bigint} len
|
|
88
|
-
* @returns {[Uint8Array | ArrayBuffer,
|
|
97
|
+
* @returns {[Uint8Array | ArrayBuffer, StreamStatus]}
|
|
89
98
|
*/
|
|
90
|
-
|
|
99
|
+
blockingRead = (stream, len) => {
|
|
91
100
|
if (stream < 3) {
|
|
92
|
-
return io.
|
|
101
|
+
return io.streams.blockingRead(stream);
|
|
93
102
|
}
|
|
94
103
|
const s = this.streams.get(stream);
|
|
95
104
|
if (!s) throw Error(`stream not found: ${stream}`);
|
|
96
105
|
const position = Number(len);
|
|
97
106
|
if (position === 0) {
|
|
98
|
-
return [new Uint8Array(), s.byteLength > 0];
|
|
107
|
+
return [new Uint8Array(), s.byteLength > 0 ? 'open' : 'ended'];
|
|
99
108
|
} else if (s.byteLength > position) {
|
|
100
109
|
this.streams.set(stream, s.slice(position, s.byteLength));
|
|
101
|
-
return [s.slice(0, position),
|
|
110
|
+
return [s.slice(0, position), 'open'];
|
|
102
111
|
} else {
|
|
103
|
-
return [s.slice(0, position),
|
|
112
|
+
return [s.slice(0, position), 'ended'];
|
|
104
113
|
}
|
|
105
114
|
}
|
|
106
115
|
|
|
@@ -108,8 +117,9 @@ export class WasiHttp {
|
|
|
108
117
|
* @param {InputStream} stream
|
|
109
118
|
* @returns {Pollable}
|
|
110
119
|
*/
|
|
111
|
-
subscribeToInputStream = (
|
|
112
|
-
|
|
120
|
+
subscribeToInputStream = (stream) => {
|
|
121
|
+
// TODO: not implemented yet
|
|
122
|
+
console.log(`[streams] Subscribe to input stream ${stream}`);
|
|
113
123
|
}
|
|
114
124
|
|
|
115
125
|
/**
|
|
@@ -121,25 +131,30 @@ export class WasiHttp {
|
|
|
121
131
|
s.set([]);
|
|
122
132
|
}
|
|
123
133
|
|
|
134
|
+
write = (stream, buf) => {
|
|
135
|
+
return this.blockingWrite(stream, buf);
|
|
136
|
+
}
|
|
137
|
+
|
|
124
138
|
/**
|
|
125
139
|
* @param {OutputStream} stream
|
|
126
140
|
* @param {Uint8Array} buf
|
|
127
|
-
* @returns {bigint}
|
|
141
|
+
* @returns {[bigint, StreamStatus]}
|
|
128
142
|
*/
|
|
129
|
-
|
|
143
|
+
blockingWrite = (stream, buf) => {
|
|
130
144
|
if (stream < 3) {
|
|
131
|
-
return io.
|
|
145
|
+
return io.streams.blockingWrite(stream, buf);
|
|
132
146
|
}
|
|
133
147
|
this.streams.set(stream, buf);
|
|
134
|
-
return BigInt(buf.byteLength);
|
|
148
|
+
return [BigInt(buf.byteLength), 'ended'];
|
|
135
149
|
}
|
|
136
150
|
|
|
137
151
|
/**
|
|
138
152
|
* @param {OutputStream} stream
|
|
139
153
|
* @returns {Pollable}
|
|
140
154
|
*/
|
|
141
|
-
subscribeToOutputStream = (
|
|
142
|
-
|
|
155
|
+
subscribeToOutputStream = (stream) => {
|
|
156
|
+
// TODO: not implemented yet
|
|
157
|
+
console.log(`[streams] Subscribe to output stream ${stream}`);
|
|
143
158
|
}
|
|
144
159
|
|
|
145
160
|
/**
|
|
@@ -189,20 +204,18 @@ export class WasiHttp {
|
|
|
189
204
|
|
|
190
205
|
/**
|
|
191
206
|
* @param {Method} method
|
|
192
|
-
* @param {string}
|
|
193
|
-
* @param {string} query
|
|
207
|
+
* @param {string | null} pathWithQuery
|
|
194
208
|
* @param {Scheme | null} scheme
|
|
195
|
-
* @param {string} authority
|
|
209
|
+
* @param {string | null} authority
|
|
196
210
|
* @param {Headers} headers
|
|
197
211
|
* @returns {number}
|
|
198
212
|
*/
|
|
199
|
-
newOutgoingRequest = (method,
|
|
213
|
+
newOutgoingRequest = (method, pathWithQuery, scheme, authority, headers) => {
|
|
200
214
|
const id = this.requestIdBase;
|
|
201
215
|
this.requestIdBase += 1;
|
|
202
216
|
|
|
203
217
|
const req = new ActiveRequest(id);
|
|
204
|
-
req.
|
|
205
|
-
req.query = query;
|
|
218
|
+
req.pathWithQuery = pathWithQuery;
|
|
206
219
|
req.authority = authority;
|
|
207
220
|
req.method = method;
|
|
208
221
|
req.headers = this.fields.get(headers);
|
|
@@ -301,9 +314,8 @@ class ActiveRequest {
|
|
|
301
314
|
activeRequest = false;
|
|
302
315
|
/** @type {Method} */ method = { tag: 'get' };
|
|
303
316
|
/** @type {Scheme | null} */ scheme = { tag: 'HTTP' };
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
authority = "";
|
|
317
|
+
pathWithQuery = null;
|
|
318
|
+
authority = null;
|
|
307
319
|
/** @type {Map<string,string[]>} */ headers = new Map();
|
|
308
320
|
body = 3;
|
|
309
321
|
|
package/lib/nodejs/cli.js
CHANGED
|
@@ -1,12 +1,26 @@
|
|
|
1
|
-
let _env;
|
|
1
|
+
let _env, _args = [], _cwd = null;
|
|
2
2
|
export function _setEnv (envObj) {
|
|
3
3
|
_env = Object.entries(envObj);
|
|
4
4
|
}
|
|
5
5
|
|
|
6
|
+
export function _setArgs (args) {
|
|
7
|
+
_args = args;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export function _setCwd (cwd) {
|
|
11
|
+
_cwd = cwd;
|
|
12
|
+
}
|
|
13
|
+
|
|
6
14
|
export const environment = {
|
|
7
15
|
getEnvironment () {
|
|
8
16
|
if (!_env) _setEnv(process.env);
|
|
9
17
|
return _env;
|
|
18
|
+
},
|
|
19
|
+
getArguments () {
|
|
20
|
+
return _args;
|
|
21
|
+
},
|
|
22
|
+
initialCwd () {
|
|
23
|
+
return _cwd;
|
|
10
24
|
}
|
|
11
25
|
};
|
|
12
26
|
|
|
@@ -35,15 +49,11 @@ export const stderr = {
|
|
|
35
49
|
};
|
|
36
50
|
|
|
37
51
|
export const terminalInput = {
|
|
38
|
-
dropTerminalInput () {
|
|
39
|
-
|
|
40
|
-
}
|
|
52
|
+
dropTerminalInput () {}
|
|
41
53
|
};
|
|
42
54
|
|
|
43
55
|
export const terminalOutput = {
|
|
44
|
-
dropTerminalOutput () {
|
|
45
|
-
|
|
46
|
-
}
|
|
56
|
+
dropTerminalOutput () {}
|
|
47
57
|
};
|
|
48
58
|
|
|
49
59
|
export const terminalStderr = {
|
package/lib/nodejs/http.js
CHANGED
|
@@ -15,7 +15,7 @@ export function send(req) {
|
|
|
15
15
|
body: response.body ? Buffer.from(response.body, "base64") : undefined,
|
|
16
16
|
};
|
|
17
17
|
}
|
|
18
|
-
throw new UnexpectedError(response);
|
|
18
|
+
throw new UnexpectedError(response.message);
|
|
19
19
|
}
|
|
20
20
|
|
|
21
21
|
export const incomingHandler = {
|
|
@@ -70,11 +70,8 @@ export const types = {
|
|
|
70
70
|
incomingRequestMethod(_req) {
|
|
71
71
|
console.log("[types] Incoming request method");
|
|
72
72
|
},
|
|
73
|
-
|
|
74
|
-
console.log("[types] Incoming request path");
|
|
75
|
-
},
|
|
76
|
-
incomingRequestQuery(_req) {
|
|
77
|
-
console.log("[types] Incoming request query");
|
|
73
|
+
incomingRequestPathWithQuery(_req) {
|
|
74
|
+
console.log("[types] Incoming request path with query");
|
|
78
75
|
},
|
|
79
76
|
incomingRequestScheme(_req) {
|
|
80
77
|
console.log("[types] Incoming request scheme");
|
|
@@ -88,7 +85,7 @@ export const types = {
|
|
|
88
85
|
incomingRequestConsume(_req) {
|
|
89
86
|
console.log("[types] Incoming request consume");
|
|
90
87
|
},
|
|
91
|
-
newOutgoingRequest(_method,
|
|
88
|
+
newOutgoingRequest(_method, _pathWithQuery, _scheme, _authority, _headers) {
|
|
92
89
|
console.log("[types] New outgoing request");
|
|
93
90
|
},
|
|
94
91
|
outgoingRequestWrite(_req) {
|
package/lib/nodejs/logging.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
const levels = ["trace", "debug", "info", "warn", "error"];
|
|
1
|
+
const levels = ["trace", "debug", "info", "warn", "error", "critical"];
|
|
2
2
|
|
|
3
3
|
let logLevel = levels.indexOf("warn");
|
|
4
4
|
|
|
5
|
-
export const
|
|
5
|
+
export const logging = {
|
|
6
6
|
log(level, context, msg) {
|
|
7
7
|
if (logLevel > levels.indexOf(level)) return;
|
|
8
8
|
process.stdout.write(`${level}: (${context}) ${msg}\n`);
|
package/package.json
CHANGED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
export namespace WasiCliEnvironment {
|
|
2
|
+
/**
|
|
3
|
+
* Get the POSIX-style environment variables.
|
|
4
|
+
*
|
|
5
|
+
* Each environment variable is provided as a pair of string variable names
|
|
6
|
+
* and string value.
|
|
7
|
+
*
|
|
8
|
+
* Morally, these are a value import, but until value imports are available
|
|
9
|
+
* in the component model, this import function should return the same
|
|
10
|
+
* values each time it is called.
|
|
11
|
+
*/
|
|
12
|
+
export function getEnvironment(): [string, string][];
|
|
13
|
+
/**
|
|
14
|
+
* Get the POSIX-style arguments to the program.
|
|
15
|
+
*/
|
|
16
|
+
export function getArguments(): string[];
|
|
17
|
+
/**
|
|
18
|
+
* Return a path that programs should use as their initial current working
|
|
19
|
+
* directory, interpreting `.` as shorthand for this.
|
|
20
|
+
*/
|
|
21
|
+
export function initialCwd(): string | null;
|
|
22
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export namespace WasiCliTerminalInput {
|
|
2
|
+
/**
|
|
3
|
+
* Dispose of the specified terminal-input after which it may no longer
|
|
4
|
+
* be used.
|
|
5
|
+
*/
|
|
6
|
+
export function dropTerminalInput(this_: TerminalInput): void;
|
|
7
|
+
}
|
|
8
|
+
/**
|
|
9
|
+
* The input 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 TerminalInput = number;
|
|
@@ -0,0 +1,13 @@
|
|
|
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
|
+
}
|
|
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;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export namespace WasiCliTerminalStderr {
|
|
2
|
+
/**
|
|
3
|
+
* If stderr is connected to a terminal, return a `terminal-output` handle
|
|
4
|
+
* allowing further interaction with it.
|
|
5
|
+
*/
|
|
6
|
+
export function getTerminalStderr(): TerminalOutput | null;
|
|
7
|
+
}
|
|
8
|
+
import type { TerminalOutput } from '../exports/wasi-cli-terminal-output';
|
|
9
|
+
export { TerminalOutput };
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export namespace WasiCliTerminalStdin {
|
|
2
|
+
/**
|
|
3
|
+
* If stdin is connected to a terminal, return a `terminal-input` handle
|
|
4
|
+
* allowing further interaction with it.
|
|
5
|
+
*/
|
|
6
|
+
export function getTerminalStdin(): TerminalInput | null;
|
|
7
|
+
}
|
|
8
|
+
import type { TerminalInput } from '../exports/wasi-cli-terminal-input';
|
|
9
|
+
export { TerminalInput };
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export namespace WasiCliTerminalStdout {
|
|
2
|
+
/**
|
|
3
|
+
* If stdout is connected to a terminal, return a `terminal-output` handle
|
|
4
|
+
* allowing further interaction with it.
|
|
5
|
+
*/
|
|
6
|
+
export function getTerminalStdout(): TerminalOutput | null;
|
|
7
|
+
}
|
|
8
|
+
import type { TerminalOutput } from '../exports/wasi-cli-terminal-output';
|
|
9
|
+
export { TerminalOutput };
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
export namespace WasiClocksMonotonicClock {
|
|
2
|
+
/**
|
|
3
|
+
* Read the current value of the clock.
|
|
4
|
+
*
|
|
5
|
+
* The clock is monotonic, therefore calling this function repeatedly will
|
|
6
|
+
* produce a sequence of non-decreasing values.
|
|
7
|
+
*/
|
|
8
|
+
export function now(): Instant;
|
|
9
|
+
/**
|
|
10
|
+
* Query the resolution of the clock.
|
|
11
|
+
*/
|
|
12
|
+
export function resolution(): Instant;
|
|
13
|
+
/**
|
|
14
|
+
* Create a `pollable` which will resolve once the specified time has been
|
|
15
|
+
* reached.
|
|
16
|
+
*/
|
|
17
|
+
export function subscribe(when: Instant, absolute: boolean): Pollable;
|
|
18
|
+
}
|
|
19
|
+
import type { Pollable } from '../exports/wasi-poll-poll';
|
|
20
|
+
export { Pollable };
|
|
21
|
+
/**
|
|
22
|
+
* A timestamp in nanoseconds.
|
|
23
|
+
*/
|
|
24
|
+
export type Instant = bigint;
|
|
@@ -0,0 +1,71 @@
|
|
|
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(this_: Timezone, when: Datetime): TimezoneDisplay;
|
|
12
|
+
/**
|
|
13
|
+
* The same as `display`, but only return the UTC offset.
|
|
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;
|
|
21
|
+
}
|
|
22
|
+
import type { Datetime } from '../exports/wasi-clocks-wall-clock';
|
|
23
|
+
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
|
+
/**
|
|
35
|
+
* Information useful for displaying the timezone of a specific `datetime`.
|
|
36
|
+
*
|
|
37
|
+
* This information may vary within a single `timezone` to reflect daylight
|
|
38
|
+
* saving time adjustments.
|
|
39
|
+
*/
|
|
40
|
+
export interface TimezoneDisplay {
|
|
41
|
+
/**
|
|
42
|
+
* The number of seconds difference between UTC time and the local
|
|
43
|
+
* time of the timezone.
|
|
44
|
+
*
|
|
45
|
+
* The returned value will always be less than 86400 which is the
|
|
46
|
+
* number of seconds in a day (24*60*60).
|
|
47
|
+
*
|
|
48
|
+
* In implementations that do not expose an actual time zone, this
|
|
49
|
+
* should return 0.
|
|
50
|
+
*/
|
|
51
|
+
utcOffset: number,
|
|
52
|
+
/**
|
|
53
|
+
* The abbreviated name of the timezone to display to a user. The name
|
|
54
|
+
* `UTC` indicates Coordinated Universal Time. Otherwise, this should
|
|
55
|
+
* reference local standards for the name of the time zone.
|
|
56
|
+
*
|
|
57
|
+
* In implementations that do not expose an actual time zone, this
|
|
58
|
+
* should be the string `UTC`.
|
|
59
|
+
*
|
|
60
|
+
* In time zones that do not have an applicable name, a formatted
|
|
61
|
+
* representation of the UTC offset may be returned, such as `-04:00`.
|
|
62
|
+
*/
|
|
63
|
+
name: string,
|
|
64
|
+
/**
|
|
65
|
+
* Whether daylight saving time is active.
|
|
66
|
+
*
|
|
67
|
+
* In implementations that do not expose an actual time zone, this
|
|
68
|
+
* should return false.
|
|
69
|
+
*/
|
|
70
|
+
inDaylightSavingTime: boolean,
|
|
71
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
export namespace WasiClocksWallClock {
|
|
2
|
+
/**
|
|
3
|
+
* Read the current value of the clock.
|
|
4
|
+
*
|
|
5
|
+
* This clock is not monotonic, therefore calling this function repeatedly
|
|
6
|
+
* will not necessarily produce a sequence of non-decreasing values.
|
|
7
|
+
*
|
|
8
|
+
* The returned timestamps represent the number of seconds since
|
|
9
|
+
* 1970-01-01T00:00:00Z, also known as [POSIX's Seconds Since the Epoch],
|
|
10
|
+
* also known as [Unix Time].
|
|
11
|
+
*
|
|
12
|
+
* The nanoseconds field of the output is always less than 1000000000.
|
|
13
|
+
*
|
|
14
|
+
* [POSIX's Seconds Since the Epoch]: https://pubs.opengroup.org/onlinepubs/9699919799/xrat/V4_xbd_chap04.html#tag_21_04_16
|
|
15
|
+
* [Unix Time]: https://en.wikipedia.org/wiki/Unix_time
|
|
16
|
+
*/
|
|
17
|
+
export function now(): Datetime;
|
|
18
|
+
/**
|
|
19
|
+
* Query the resolution of the clock.
|
|
20
|
+
*
|
|
21
|
+
* The nanoseconds field of the output is always less than 1000000000.
|
|
22
|
+
*/
|
|
23
|
+
export function resolution(): Datetime;
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* A time and date in seconds plus nanoseconds.
|
|
27
|
+
*/
|
|
28
|
+
export interface Datetime {
|
|
29
|
+
seconds: bigint,
|
|
30
|
+
nanoseconds: number,
|
|
31
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export namespace WasiFilesystemPreopens {
|
|
2
|
+
/**
|
|
3
|
+
* Return the set of preopened directories, and their path.
|
|
4
|
+
*/
|
|
5
|
+
export function getDirectories(): [Descriptor, string][];
|
|
6
|
+
}
|
|
7
|
+
import type { Descriptor } from '../exports/wasi-filesystem-types';
|
|
8
|
+
export { Descriptor };
|