@bytecodealliance/preview2-shim 0.0.5 → 0.0.7
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 +10 -20
- package/lib/browser/filesystem.js +121 -22
- package/lib/browser/index.js +2 -14
- package/lib/browser/monotonic-clock.js +2 -2
- package/lib/browser/random.js +13 -0
- package/lib/browser/stderr.js +1 -0
- package/lib/browser/timezone.js +12 -0
- package/lib/browser/wall-clock.js +2 -2
- package/lib/http/wasi-http.js +80 -12
- package/lib/nodejs/filesystem.js +109 -23
- package/lib/nodejs/index.js +2 -14
- package/lib/nodejs/monotonic-clock.js +6 -10
- package/lib/nodejs/random.js +13 -0
- package/lib/nodejs/stderr.js +1 -0
- package/lib/nodejs/timezone.js +12 -0
- package/lib/nodejs/wall-clock.js +2 -6
- package/package.json +1 -1
- package/types/imports/environment.d.ts +1 -0
- package/types/imports/monotonic-clock.d.ts +3 -5
- package/types/imports/wall-clock.d.ts +2 -4
- package/types/wasi-reactor.d.ts +6 -8
- package/lib/browser/environment-preopens.js +0 -3
- package/lib/browser/instance-monotonic-clock.js +0 -3
- package/lib/browser/instance-wall-clock.js +0 -3
- package/lib/nodejs/environment-preopens.js +0 -3
- package/lib/nodejs/instance-monotonic-clock.js +0 -3
- package/lib/nodejs/instance-wall-clock.js +0 -3
- package/types/imports/environment-preopens.d.ts +0 -5
- package/types/imports/instance-monotonic-clock.d.ts +0 -5
- package/types/imports/instance-wall-clock.d.ts +0 -5
- package/types/imports/stderr.d.ts +0 -3
- /package/lib/browser/{console.js → logging.js} +0 -0
- /package/lib/nodejs/{console.js → logging.js} +0 -0
package/README.md
CHANGED
|
@@ -6,26 +6,16 @@ Currently supports Node.js and browser versions, but alternative implementations
|
|
|
6
6
|
|
|
7
7
|
## Implementation Status
|
|
8
8
|
|
|
9
|
-
| Interface | Node.js
|
|
10
|
-
| --------------- |
|
|
11
|
-
|
|
|
12
|
-
|
|
|
13
|
-
|
|
|
14
|
-
|
|
|
15
|
-
|
|
|
16
|
-
|
|
|
17
|
-
|
|
|
18
|
-
|
|
|
19
|
-
| IP | :x: | :x: |
|
|
20
|
-
| Logging | :heavy_check_mark: | :heavy_check_mark: |
|
|
21
|
-
| Monotonic Clock | Missing `resolution` | Missing `resolution` |
|
|
22
|
-
| Net | :x: | :x: |
|
|
23
|
-
| Poll | :x: | :x: |
|
|
24
|
-
| Random | :heavy_check_mark: | :heavy_check_mark: |
|
|
25
|
-
| Stderr | :heavy_check_mark: | :heavy_check_mark: |
|
|
26
|
-
| TCP | :x: | :x: |
|
|
27
|
-
| Timezone | :x: | :x: |
|
|
28
|
-
| Wall Clock | Missing `resolution` | Missing `resolution` |
|
|
9
|
+
| Interface | Node.js | Browser |
|
|
10
|
+
| --------------- | ----------------------------:|-----------------------------:|
|
|
11
|
+
| Clocks | Pending timezone, resolution | Pending timezone, resolution |
|
|
12
|
+
| Filesystem | :x: | :x: |
|
|
13
|
+
| HTTP | :x: | :x: |
|
|
14
|
+
| IO | :x: | :x: |
|
|
15
|
+
| Logging | :heavy_check_mark: | :heavy_check_mark: |
|
|
16
|
+
| Poll | :x: | :x: |
|
|
17
|
+
| Random | :heavy_check_mark: | :heavy_check_mark: |
|
|
18
|
+
| Sockets | :x: | :x: |
|
|
29
19
|
|
|
30
20
|
# License
|
|
31
21
|
|
|
@@ -1,51 +1,150 @@
|
|
|
1
|
-
export
|
|
1
|
+
// export interface DescriptorStat {
|
|
2
|
+
// dev: Device,
|
|
3
|
+
// ino: Inode,
|
|
4
|
+
// type: DescriptorType,
|
|
5
|
+
// nlink: Linkcount,
|
|
6
|
+
// size: Filesize,
|
|
7
|
+
// atim: Timestamp,
|
|
8
|
+
// mtim: Timestamp,
|
|
9
|
+
// ctim: Timestamp,
|
|
10
|
+
// }
|
|
11
|
+
|
|
12
|
+
export function readViaStream(fd, offset) {
|
|
13
|
+
console.log(`[filesystem] READ STREAM ${fd} ${offset}`);
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export function writeViaStream(fd, offset) {
|
|
17
|
+
console.log(`[filesystem] WRITE STREAM ${fd} ${offset}`);
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export function appendViaStream(fd) {
|
|
21
|
+
console.log(`[filesystem] APPEND STREAM ${fd}`);
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export function advise(fd, offset, length, advice) {
|
|
25
|
+
console.log(`[filesystem] ADVISE`, fd, offset, length, advice);
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export function syncData(fd) {
|
|
29
|
+
console.log(`[filesystem] SYNC DATA ${fd}`);
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export function getFlags(fd) {
|
|
2
33
|
console.log(`[filesystem] FLAGS FOR ${fd}`);
|
|
3
34
|
}
|
|
4
35
|
|
|
36
|
+
export function getType(fd) {
|
|
37
|
+
console.log(`[filesystem] GET TYPE ${fd}`);
|
|
38
|
+
}
|
|
39
|
+
|
|
5
40
|
export function setFlags(fd, flags) {
|
|
6
41
|
console.log(`[filesystem] SET FLAGS ${fd} ${JSON.stringify(flags)}`);
|
|
7
42
|
}
|
|
8
43
|
|
|
9
|
-
export function
|
|
10
|
-
console.log(`[filesystem]
|
|
44
|
+
export function setSize(fd, size) {
|
|
45
|
+
console.log(`[filesystem] SET SIZE`, fd, size);
|
|
11
46
|
}
|
|
12
47
|
|
|
13
|
-
export function
|
|
14
|
-
console.log(`[filesystem]
|
|
48
|
+
export function setTimes(fd, dataAccessTimestamp, dataModificationTimestamp) {
|
|
49
|
+
console.log(`[filesystem] SET TIMES`, fd, dataAccessTimestamp, dataModificationTimestamp);
|
|
15
50
|
}
|
|
16
51
|
|
|
17
|
-
export function
|
|
18
|
-
console.log(`[filesystem]
|
|
52
|
+
export function read(fd, length, offset) {
|
|
53
|
+
console.log(`[filesystem] READ`, fd, length, offset);
|
|
19
54
|
}
|
|
20
55
|
|
|
21
|
-
export function
|
|
22
|
-
console.log(`[filesystem] WRITE
|
|
56
|
+
export function write(fd, buffer, offset) {
|
|
57
|
+
console.log(`[filesystem] WRITE`, fd, buffer, offset);
|
|
23
58
|
}
|
|
24
59
|
|
|
25
|
-
export function
|
|
26
|
-
console.log(`[filesystem]
|
|
60
|
+
export function readDirectory(fd) {
|
|
61
|
+
console.log(`[filesystem] READ DIR`, fd);
|
|
27
62
|
}
|
|
28
63
|
|
|
29
|
-
export function
|
|
30
|
-
console.log(`[filesystem]
|
|
64
|
+
export function sync(fd) {
|
|
65
|
+
console.log(`[filesystem] SYNC`, fd);
|
|
31
66
|
}
|
|
32
67
|
|
|
33
|
-
export function
|
|
34
|
-
console.log(`[filesystem]
|
|
68
|
+
export function createDirectoryAt(fd, path) {
|
|
69
|
+
console.log(`[filesystem] CREATE DIRECTORY`, fd, path);
|
|
35
70
|
}
|
|
36
71
|
|
|
37
72
|
export function stat(fd) {
|
|
38
|
-
console.log(`[filesystem] STAT
|
|
73
|
+
console.log(`[filesystem] STAT`, fd);
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
export function statAt(fd, pathFlags, path) {
|
|
77
|
+
console.log(`[filesystem] STAT`, fd, pathFlags, path);
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
export function setTimesAt(fd) {
|
|
81
|
+
console.log(`[filesystem] SET TIMES AT`, fd);
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
export function linkAt(fd) {
|
|
85
|
+
console.log(`[filesystem] LINK AT`, fd);
|
|
39
86
|
}
|
|
40
87
|
|
|
41
|
-
export function
|
|
42
|
-
console.log(`[filesystem]
|
|
88
|
+
export function openAt(fd) {
|
|
89
|
+
console.log(`[filesystem] OPEN AT`, fd);
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
export function readlinkAt(fd) {
|
|
93
|
+
console.log(`[filesystem] READLINK AT`, fd);
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
export function removeDirectoryAt(fd) {
|
|
97
|
+
console.log(`[filesystem] REMOVE DIR AT`, fd);
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
export function renameAt(fd) {
|
|
101
|
+
console.log(`[filesystem] RENAME AT`, fd);
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
export function symlinkAt(fd) {
|
|
105
|
+
console.log(`[filesystem] SYMLINK AT`, fd);
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
export function unlinkFileAt(fd) {
|
|
109
|
+
console.log(`[filesystem] UNLINK FILE AT`, fd);
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
export function changeFilePermissionsAt(fd) {
|
|
113
|
+
console.log(`[filesystem] CHANGE FILE PERMISSIONS AT`, fd);
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
export function changeDirectoryPermissionsAt(fd) {
|
|
117
|
+
console.log(`[filesystem] CHANGE DIR PERMISSIONS AT`, fd);
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
export function lockShared(fd) {
|
|
121
|
+
console.log(`[filesystem] LOCK SHARED`, fd);
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
export function lockExclusive(fd) {
|
|
125
|
+
console.log(`[filesystem] LOCK EXCLUSIVE`, fd);
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
export function tryLockShared(fd) {
|
|
129
|
+
console.log(`[filesystem] TRY LOCK SHARED`, fd);
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
export function tryLockExclusive(fd) {
|
|
133
|
+
console.log(`[filesystem] TRY LOCK EXCLUSIVE`, fd);
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
export function unlock(fd) {
|
|
137
|
+
console.log(`[filesystem] UNLOCK`, fd);
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
export function dropDescriptor(fd) {
|
|
141
|
+
console.log(`[filesystem] DROP DESCRIPTOR`, fd);
|
|
43
142
|
}
|
|
44
143
|
|
|
45
|
-
export function
|
|
46
|
-
console.log(`[filesystem]
|
|
144
|
+
export function readDirectoryEntry(stream) {
|
|
145
|
+
console.log(`[filesystem] READ DIRECTRY ENTRY`, stream);
|
|
47
146
|
}
|
|
48
147
|
|
|
49
|
-
export function
|
|
50
|
-
console.log(`[filesystem]
|
|
148
|
+
export function dropDirectoryEntryStream(stream) {
|
|
149
|
+
console.log(`[filesystem] DROP DIRECTORY ENTRY`, stream);
|
|
51
150
|
}
|
package/lib/browser/index.js
CHANGED
|
@@ -1,40 +1,28 @@
|
|
|
1
|
-
import * as
|
|
1
|
+
import * as logging from "./logging.js";
|
|
2
2
|
import * as defaultOutgoingHttp from "./default-outgoing-HTTP.js";
|
|
3
3
|
import * as environment from "./environment.js";
|
|
4
|
-
import * as environmentPreopens from "./environment-preopens.js";
|
|
5
4
|
import * as exit from "./exit.js";
|
|
6
5
|
import * as filesystem from "./filesystem.js";
|
|
7
6
|
import * as http from "./http.js";
|
|
8
|
-
import * as instanceMonotonicClock from "./instance-monotonic-clock.js";
|
|
9
|
-
import * as instanceWallClock from "./instance-wall-clock.js";
|
|
10
|
-
import * as io from "./io.js";
|
|
11
7
|
import * as monotonicClock from "./monotonic-clock.js";
|
|
12
8
|
import * as poll from "./poll.js";
|
|
13
9
|
import * as preopens from "./preopens.js";
|
|
14
10
|
import * as random from "./random.js";
|
|
15
|
-
import * as stderr from "./stderr.js";
|
|
16
11
|
import * as streams from "./streams.js";
|
|
17
|
-
import * as types from "./types.js";
|
|
18
12
|
import * as wallClock from "./wall-clock.js";
|
|
19
13
|
|
|
20
14
|
export const importObject = {
|
|
21
|
-
"console": console,
|
|
22
15
|
"default-outgoing-HTTP": defaultOutgoingHttp,
|
|
23
16
|
"environment": environment,
|
|
24
|
-
"environment-preopens": environmentPreopens,
|
|
25
17
|
"exit": exit,
|
|
26
18
|
"filesystem": filesystem,
|
|
27
19
|
"http": http,
|
|
28
|
-
"
|
|
29
|
-
"instance-wall-clock": instanceWallClock,
|
|
30
|
-
"io": io,
|
|
20
|
+
"logging": logging,
|
|
31
21
|
"monotonic-clock": monotonicClock,
|
|
32
22
|
"poll": poll,
|
|
33
23
|
"preopens": preopens,
|
|
34
24
|
"random": random,
|
|
35
|
-
"stderr": stderr,
|
|
36
25
|
"streams": streams,
|
|
37
|
-
"types": types,
|
|
38
26
|
"wall-clock": wallClock,
|
|
39
27
|
};
|
|
40
28
|
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
|
|
2
2
|
export function resolution(clock) {
|
|
3
|
-
console.log(`[
|
|
3
|
+
console.log(`[monotonic-clock] Monotonic clock resolution ${clock}`);
|
|
4
4
|
}
|
|
5
5
|
|
|
6
6
|
let hrStart = hrtimeBigint();
|
|
@@ -9,7 +9,7 @@ export function now(clock) {
|
|
|
9
9
|
if (clock === 0) {
|
|
10
10
|
return hrtimeBigint() - hrStart;
|
|
11
11
|
}
|
|
12
|
-
console.log(
|
|
12
|
+
console.log(`[monotonic clock] Unknown clock ${clock}`);
|
|
13
13
|
}
|
|
14
14
|
|
|
15
15
|
function hrtime(previousTimestamp) {
|
package/lib/browser/random.js
CHANGED
|
@@ -17,3 +17,16 @@ export function getRandomBytes(len) {
|
|
|
17
17
|
|
|
18
18
|
return bytes;
|
|
19
19
|
}
|
|
20
|
+
|
|
21
|
+
export function getRandomU64 () {
|
|
22
|
+
return crypto.getRandomValues(new BigUint64Array(1))[0];
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
let insecureRandomValue1, insecureRandomValue2;
|
|
26
|
+
export function insecureRandom () {
|
|
27
|
+
if (insecureRandomValue1 === undefined) {
|
|
28
|
+
insecureRandomValue1 = getRandomU64();
|
|
29
|
+
insecureRandomValue2 = getRandomU64();
|
|
30
|
+
}
|
|
31
|
+
return [insecureRandomValue1, insecureRandomValue2];
|
|
32
|
+
}
|
package/lib/browser/stderr.js
CHANGED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export function display (timezone, when) {
|
|
2
|
+
console.log(`[timezone] DISPLAY ${timezone} ${when}`);
|
|
3
|
+
}
|
|
4
|
+
|
|
5
|
+
export function utcOffset (timezone, when) {
|
|
6
|
+
console.log(`[timezone] UTC OFFSET ${timezone} ${when}`);
|
|
7
|
+
return 0;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export function dropTimezone (timezone) {
|
|
11
|
+
console.log(`[timezone] DROP ${timezone}`);
|
|
12
|
+
}
|
|
@@ -4,9 +4,9 @@ export function now(clock) {
|
|
|
4
4
|
const nanoseconds = (Date.now() % 1000) * 1000 * 1000;
|
|
5
5
|
return { seconds, nanoseconds };
|
|
6
6
|
}
|
|
7
|
-
console.log(
|
|
7
|
+
console.log(`[wall-clock] Unknown clock ${clock}`);
|
|
8
8
|
}
|
|
9
9
|
|
|
10
10
|
export function resolution(clock) {
|
|
11
|
-
console.log(`[
|
|
11
|
+
console.log(`[wall-clock] Wall clock resolution ${clock}`);
|
|
12
12
|
}
|
package/lib/http/wasi-http.js
CHANGED
|
@@ -10,22 +10,26 @@
|
|
|
10
10
|
* @typedef {import("../../types/imports/types").Method} Method
|
|
11
11
|
* @typedef {import("../../types/imports/types").OutgoingRequest} OutgoingRequest
|
|
12
12
|
* @typedef {import("../../types/imports/types").RequestOptions} RequestOptions
|
|
13
|
+
* @typedef {import("../../types/imports/types").Result} Result
|
|
13
14
|
* @typedef {import("../../types/imports/types").Scheme} Scheme
|
|
14
15
|
* @typedef {import("../../types/imports/types").StatusCode} StatusCode
|
|
15
|
-
|
|
16
|
+
*/
|
|
16
17
|
|
|
17
18
|
import * as io from '@bytecodealliance/preview2-shim/io';
|
|
18
19
|
import * as http from '@bytecodealliance/preview2-shim/http';
|
|
20
|
+
import { UnexpectedError } from './error.js';
|
|
19
21
|
|
|
20
22
|
export class WasiHttp {
|
|
21
23
|
requestIdBase = 1;
|
|
22
24
|
responseIdBase = 1;
|
|
23
25
|
fieldsIdBase = 1;
|
|
24
|
-
|
|
26
|
+
streamIdBase = 3;
|
|
27
|
+
futureIdBase = 1;
|
|
25
28
|
/** @type {Map<number,ActiveRequest>} */ requests = new Map();
|
|
26
29
|
/** @type {Map<number,ActiveResponse>} */ responses = new Map();
|
|
27
30
|
/** @type {Map<number,Map<string,string[]>>} */ fields = new Map();
|
|
28
31
|
/** @type {Map<number,Uint8Array>} */ streams = new Map();
|
|
32
|
+
/** @type {Map<number,ActiveFuture>} */ futures = new Map();
|
|
29
33
|
|
|
30
34
|
constructor() {}
|
|
31
35
|
|
|
@@ -34,11 +38,7 @@ export class WasiHttp {
|
|
|
34
38
|
* @param {RequestOptions | null} options
|
|
35
39
|
* @returns {FutureIncomingResponse}
|
|
36
40
|
*/
|
|
37
|
-
handle = (requestId, {
|
|
38
|
-
connectTimeoutMs: _connectTimeoutMs = 600_000,
|
|
39
|
-
firstByteTimeoutMs: _firstByteTimeoutMs = 600_000,
|
|
40
|
-
betweenBytesTimeoutMs: _betweenBytesTimeoutMs = 600_000
|
|
41
|
-
} = {}) => {
|
|
41
|
+
handle = (requestId, _options) => {
|
|
42
42
|
const request = this.requests.get(requestId);
|
|
43
43
|
if (!request) throw Error("not found!");
|
|
44
44
|
|
|
@@ -70,11 +70,16 @@ export class WasiHttp {
|
|
|
70
70
|
response.responseHeaders.set(key, [value]);
|
|
71
71
|
}
|
|
72
72
|
const buf = res.body;
|
|
73
|
-
response.body = this.
|
|
74
|
-
this.
|
|
73
|
+
response.body = this.streamIdBase;
|
|
74
|
+
this.streamIdBase += 1;
|
|
75
75
|
this.streams.set(response.body, buf);
|
|
76
76
|
this.responses.set(responseId, response);
|
|
77
|
-
|
|
77
|
+
|
|
78
|
+
const futureId = this.futureIdBase;
|
|
79
|
+
this.futureIdBase += 1;
|
|
80
|
+
const future = new ActiveFuture(futureId, responseId);
|
|
81
|
+
this.futures.set(futureId, future);
|
|
82
|
+
return futureId;
|
|
78
83
|
}
|
|
79
84
|
|
|
80
85
|
/**
|
|
@@ -146,6 +151,13 @@ export class WasiHttp {
|
|
|
146
151
|
s.set([]);
|
|
147
152
|
}
|
|
148
153
|
|
|
154
|
+
/**
|
|
155
|
+
* @param {Fields} fields
|
|
156
|
+
*/
|
|
157
|
+
dropFields = (fields) => {
|
|
158
|
+
this.fields.delete(fields);
|
|
159
|
+
}
|
|
160
|
+
|
|
149
161
|
/**
|
|
150
162
|
* @param {[string, string][]} entries
|
|
151
163
|
* @returns {Fields}
|
|
@@ -154,7 +166,7 @@ export class WasiHttp {
|
|
|
154
166
|
const map = new Map(entries);
|
|
155
167
|
|
|
156
168
|
const id = this.fieldsIdBase;
|
|
157
|
-
this.fieldsIdBase
|
|
169
|
+
this.fieldsIdBase += 1;
|
|
158
170
|
this.fields.set(id, map);
|
|
159
171
|
|
|
160
172
|
return id;
|
|
@@ -198,6 +210,17 @@ export class WasiHttp {
|
|
|
198
210
|
this.requests.set(id, req);
|
|
199
211
|
return id;
|
|
200
212
|
}
|
|
213
|
+
|
|
214
|
+
/**
|
|
215
|
+
* @param {OutgoingRequest} request
|
|
216
|
+
* @returns {OutgoingStream}
|
|
217
|
+
*/
|
|
218
|
+
outgoingRequestWrite = (request) => {
|
|
219
|
+
const req = this.requests.get(request);
|
|
220
|
+
req.body = this.streamIdBase;
|
|
221
|
+
this.streamIdBase += 1;
|
|
222
|
+
return req.body;
|
|
223
|
+
}
|
|
201
224
|
|
|
202
225
|
/**
|
|
203
226
|
* @param {IncomingResponse} response
|
|
@@ -222,7 +245,7 @@ export class WasiHttp {
|
|
|
222
245
|
incomingResponseHeaders = (response) => {
|
|
223
246
|
const r = this.responses.get(response);
|
|
224
247
|
const id = this.fieldsIdBase;
|
|
225
|
-
this.fieldsIdBase
|
|
248
|
+
this.fieldsIdBase += 1;
|
|
226
249
|
|
|
227
250
|
this.fields.set(id, r.responseHeaders);
|
|
228
251
|
return id;
|
|
@@ -236,6 +259,41 @@ export class WasiHttp {
|
|
|
236
259
|
const r = this.responses.get(response);
|
|
237
260
|
return r.body;
|
|
238
261
|
}
|
|
262
|
+
|
|
263
|
+
/**
|
|
264
|
+
* @param {FutureIncomingResponse} future
|
|
265
|
+
*/
|
|
266
|
+
dropFutureIncomingResponse = (future) => {
|
|
267
|
+
return this.futures.delete(future);
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
/**
|
|
271
|
+
* @param {FutureIncomingResponse} future
|
|
272
|
+
* @returns {Result<IncomingResponse, Error> | null}
|
|
273
|
+
*/
|
|
274
|
+
futureIncomingResponseGet = (future) => {
|
|
275
|
+
const f = this.futures.get(future);
|
|
276
|
+
if (!f) {
|
|
277
|
+
return {
|
|
278
|
+
tag: "err",
|
|
279
|
+
val: UnexpectedError(`no such future ${f}`),
|
|
280
|
+
};
|
|
281
|
+
}
|
|
282
|
+
// For now this will assume the future will return
|
|
283
|
+
// the response immediately
|
|
284
|
+
const response = f.responseId;
|
|
285
|
+
const r = this.responses.get(response);
|
|
286
|
+
if (!r) {
|
|
287
|
+
return {
|
|
288
|
+
tag: "err",
|
|
289
|
+
val: UnexpectedError(`no such response ${response}`),
|
|
290
|
+
};
|
|
291
|
+
}
|
|
292
|
+
return {
|
|
293
|
+
tag: "ok",
|
|
294
|
+
val: response,
|
|
295
|
+
};
|
|
296
|
+
}
|
|
239
297
|
}
|
|
240
298
|
|
|
241
299
|
class ActiveRequest {
|
|
@@ -265,3 +323,13 @@ class ActiveResponse {
|
|
|
265
323
|
this.id = id;
|
|
266
324
|
}
|
|
267
325
|
}
|
|
326
|
+
|
|
327
|
+
class ActiveFuture {
|
|
328
|
+
/** @type {number} */ id;
|
|
329
|
+
/** @type {number} */ responseId;
|
|
330
|
+
|
|
331
|
+
constructor(id, responseId) {
|
|
332
|
+
this.id = id;
|
|
333
|
+
this.responseId = responseId;
|
|
334
|
+
}
|
|
335
|
+
}
|
package/lib/nodejs/filesystem.js
CHANGED
|
@@ -9,56 +9,142 @@
|
|
|
9
9
|
// ctim: Timestamp,
|
|
10
10
|
// }
|
|
11
11
|
|
|
12
|
+
export function readViaStream(fd, offset) {
|
|
13
|
+
console.log(`[filesystem] READ STREAM ${fd} ${offset}`);
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export function writeViaStream(fd, offset) {
|
|
17
|
+
console.log(`[filesystem] WRITE STREAM ${fd} ${offset}`);
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export function appendViaStream(fd) {
|
|
21
|
+
console.log(`[filesystem] APPEND STREAM ${fd}`);
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export function advise(fd, offset, length, advice) {
|
|
25
|
+
console.log(`[filesystem] ADVISE`, fd, offset, length, advice);
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export function syncData(fd) {
|
|
29
|
+
console.log(`[filesystem] SYNC DATA ${fd}`);
|
|
30
|
+
}
|
|
31
|
+
|
|
12
32
|
export function getFlags(fd) {
|
|
13
33
|
console.log(`[filesystem] FLAGS FOR ${fd}`);
|
|
14
34
|
}
|
|
15
35
|
|
|
36
|
+
export function getType(fd) {
|
|
37
|
+
console.log(`[filesystem] GET TYPE ${fd}`);
|
|
38
|
+
}
|
|
39
|
+
|
|
16
40
|
export function setFlags(fd, flags) {
|
|
17
41
|
console.log(`[filesystem] SET FLAGS ${fd} ${JSON.stringify(flags)}`);
|
|
18
42
|
}
|
|
19
43
|
|
|
20
|
-
export function
|
|
21
|
-
console.log(`[filesystem]
|
|
44
|
+
export function setSize(fd, size) {
|
|
45
|
+
console.log(`[filesystem] SET SIZE`, fd, size);
|
|
22
46
|
}
|
|
23
47
|
|
|
24
|
-
export function
|
|
25
|
-
console.log(`[filesystem]
|
|
48
|
+
export function setTimes(fd, dataAccessTimestamp, dataModificationTimestamp) {
|
|
49
|
+
console.log(`[filesystem] SET TIMES`, fd, dataAccessTimestamp, dataModificationTimestamp);
|
|
26
50
|
}
|
|
27
51
|
|
|
28
|
-
export function
|
|
29
|
-
console.log(`[filesystem]
|
|
52
|
+
export function read(fd, length, offset) {
|
|
53
|
+
console.log(`[filesystem] READ`, fd, length, offset);
|
|
30
54
|
}
|
|
31
55
|
|
|
32
|
-
export function
|
|
33
|
-
console.log(`[filesystem] WRITE
|
|
56
|
+
export function write(fd, buffer, offset) {
|
|
57
|
+
console.log(`[filesystem] WRITE`, fd, buffer, offset);
|
|
34
58
|
}
|
|
35
59
|
|
|
36
|
-
export function
|
|
37
|
-
console.log(`[filesystem]
|
|
60
|
+
export function readDirectory(fd) {
|
|
61
|
+
console.log(`[filesystem] READ DIR`, fd);
|
|
38
62
|
}
|
|
39
63
|
|
|
40
|
-
export function
|
|
41
|
-
console.log(`[filesystem]
|
|
64
|
+
export function sync(fd) {
|
|
65
|
+
console.log(`[filesystem] SYNC`, fd);
|
|
42
66
|
}
|
|
43
67
|
|
|
44
|
-
export function
|
|
45
|
-
console.log(`[filesystem]
|
|
68
|
+
export function createDirectoryAt(fd, path) {
|
|
69
|
+
console.log(`[filesystem] CREATE DIRECTORY`, fd, path);
|
|
46
70
|
}
|
|
47
71
|
|
|
48
72
|
export function stat(fd) {
|
|
49
|
-
console.log(`[filesystem] STAT
|
|
73
|
+
console.log(`[filesystem] STAT`, fd);
|
|
50
74
|
}
|
|
51
75
|
|
|
52
|
-
export function
|
|
53
|
-
console.log(`[filesystem]
|
|
76
|
+
export function statAt(fd, pathFlags, path) {
|
|
77
|
+
console.log(`[filesystem] STAT`, fd, pathFlags, path);
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
export function setTimesAt(fd) {
|
|
81
|
+
console.log(`[filesystem] SET TIMES AT`, fd);
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
export function linkAt(fd) {
|
|
85
|
+
console.log(`[filesystem] LINK AT`, fd);
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
export function openAt(fd) {
|
|
89
|
+
console.log(`[filesystem] OPEN AT`, fd);
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
export function readlinkAt(fd) {
|
|
93
|
+
console.log(`[filesystem] READLINK AT`, fd);
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
export function removeDirectoryAt(fd) {
|
|
97
|
+
console.log(`[filesystem] REMOVE DIR AT`, fd);
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
export function renameAt(fd) {
|
|
101
|
+
console.log(`[filesystem] RENAME AT`, fd);
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
export function symlinkAt(fd) {
|
|
105
|
+
console.log(`[filesystem] SYMLINK AT`, fd);
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
export function unlinkFileAt(fd) {
|
|
109
|
+
console.log(`[filesystem] UNLINK FILE AT`, fd);
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
export function changeFilePermissionsAt(fd) {
|
|
113
|
+
console.log(`[filesystem] CHANGE FILE PERMISSIONS AT`, fd);
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
export function changeDirectoryPermissionsAt(fd) {
|
|
117
|
+
console.log(`[filesystem] CHANGE DIR PERMISSIONS AT`, fd);
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
export function lockShared(fd) {
|
|
121
|
+
console.log(`[filesystem] LOCK SHARED`, fd);
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
export function lockExclusive(fd) {
|
|
125
|
+
console.log(`[filesystem] LOCK EXCLUSIVE`, fd);
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
export function tryLockShared(fd) {
|
|
129
|
+
console.log(`[filesystem] TRY LOCK SHARED`, fd);
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
export function tryLockExclusive(fd) {
|
|
133
|
+
console.log(`[filesystem] TRY LOCK EXCLUSIVE`, fd);
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
export function unlock(fd) {
|
|
137
|
+
console.log(`[filesystem] UNLOCK`, fd);
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
export function dropDescriptor(fd) {
|
|
141
|
+
console.log(`[filesystem] DROP DESCRIPTOR`, fd);
|
|
54
142
|
}
|
|
55
143
|
|
|
56
|
-
export function
|
|
57
|
-
console.log(`[filesystem]
|
|
144
|
+
export function readDirectoryEntry(stream) {
|
|
145
|
+
console.log(`[filesystem] READ DIRECTRY ENTRY`, stream);
|
|
58
146
|
}
|
|
59
147
|
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
return [];
|
|
148
|
+
export function dropDirectoryEntryStream(stream) {
|
|
149
|
+
console.log(`[filesystem] DROP DIRECTORY ENTRY`, stream);
|
|
63
150
|
}
|
|
64
|
-
export { getFlags as flags, getType as todoType, dropDirectoryEntryStream as dropDirEntryStream }
|
package/lib/nodejs/index.js
CHANGED
|
@@ -1,40 +1,28 @@
|
|
|
1
|
-
import * as
|
|
1
|
+
import * as logging from "./logging.js";
|
|
2
2
|
import * as defaultOutgoingHttp from "./default-outgoing-HTTP.js";
|
|
3
3
|
import * as environment from "./environment.js";
|
|
4
|
-
import * as environmentPreopens from "./environment-preopens.js";
|
|
5
4
|
import * as exit from "./exit.js";
|
|
6
5
|
import * as filesystem from "./filesystem.js";
|
|
7
6
|
import * as http from "./http.js";
|
|
8
|
-
import * as instanceMonotonicClock from "./instance-monotonic-clock.js";
|
|
9
|
-
import * as instanceWallClock from "./instance-wall-clock.js";
|
|
10
|
-
import * as io from "./io.js";
|
|
11
7
|
import * as monotonicClock from "./monotonic-clock.js";
|
|
12
8
|
import * as poll from "./poll.js";
|
|
13
9
|
import * as preopens from "./preopens.js";
|
|
14
10
|
import * as random from "./random.js";
|
|
15
|
-
import * as stderr from "./stderr.js";
|
|
16
11
|
import * as streams from "./streams.js";
|
|
17
|
-
import * as types from "./types.js";
|
|
18
12
|
import * as wallClock from "./wall-clock.js";
|
|
19
13
|
|
|
20
14
|
export const importObject = {
|
|
21
|
-
"console": console,
|
|
22
15
|
"default-outgoing-HTTP": defaultOutgoingHttp,
|
|
23
16
|
"environment": environment,
|
|
24
|
-
"environment-preopens": environmentPreopens,
|
|
25
17
|
"exit": exit,
|
|
26
18
|
"filesystem": filesystem,
|
|
27
19
|
"http": http,
|
|
28
|
-
"
|
|
29
|
-
"instance-wall-clock": instanceWallClock,
|
|
30
|
-
"io": io,
|
|
20
|
+
"logging": logging,
|
|
31
21
|
"monotonic-clock": monotonicClock,
|
|
32
22
|
"poll": poll,
|
|
33
23
|
"preopens": preopens,
|
|
34
24
|
"random": random,
|
|
35
|
-
"stderr": stderr,
|
|
36
25
|
"streams": streams,
|
|
37
|
-
"types": types,
|
|
38
26
|
"wall-clock": wallClock,
|
|
39
27
|
};
|
|
40
28
|
|
|
@@ -1,18 +1,14 @@
|
|
|
1
1
|
import { hrtime } from "node:process";
|
|
2
2
|
|
|
3
|
-
export function resolution(
|
|
4
|
-
console.log(`[
|
|
3
|
+
export function resolution() {
|
|
4
|
+
console.log(`[monotonic-clock] Monotonic clock resolution`);
|
|
5
5
|
}
|
|
6
6
|
|
|
7
7
|
let hrStart = hrtime.bigint();
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
if (clock === 0) {
|
|
11
|
-
return hrtime.bigint() - hrStart;
|
|
12
|
-
}
|
|
13
|
-
console.log("[clocks] UNKNOWN CLOCK");
|
|
8
|
+
export function now() {
|
|
9
|
+
return hrtime.bigint() - hrStart;
|
|
14
10
|
}
|
|
15
11
|
|
|
16
|
-
export function
|
|
17
|
-
|
|
12
|
+
export function subscribe (_when, _absolute) {
|
|
13
|
+
console.log(`[monotonic-clock] Subscribe`);
|
|
18
14
|
}
|
package/lib/nodejs/random.js
CHANGED
|
@@ -3,3 +3,16 @@ import { randomBytes } from "node:crypto";
|
|
|
3
3
|
export function getRandomBytes(len) {
|
|
4
4
|
return randomBytes(Number(len));
|
|
5
5
|
}
|
|
6
|
+
|
|
7
|
+
export function getRandomU64 () {
|
|
8
|
+
return new BigUint64Array(randomBytes(8).buffer)[0];
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
let insecureRandomValue1, insecureRandomValue2;
|
|
12
|
+
export function insecureRandom () {
|
|
13
|
+
if (insecureRandomValue1 === undefined) {
|
|
14
|
+
insecureRandomValue1 = getRandomU64();
|
|
15
|
+
insecureRandomValue2 = getRandomU64();
|
|
16
|
+
}
|
|
17
|
+
return [insecureRandomValue1, insecureRandomValue2];
|
|
18
|
+
}
|
package/lib/nodejs/stderr.js
CHANGED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export function display (timezone, when) {
|
|
2
|
+
console.log(`[timezone] DISPLAY ${timezone} ${when}`);
|
|
3
|
+
}
|
|
4
|
+
|
|
5
|
+
export function utcOffset (timezone, when) {
|
|
6
|
+
console.log(`[timezone] UTC OFFSET ${timezone} ${when}`);
|
|
7
|
+
return 0;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export function dropTimezone (timezone) {
|
|
11
|
+
console.log(`[timezone] DROP ${timezone}`);
|
|
12
|
+
}
|
package/lib/nodejs/wall-clock.js
CHANGED
|
@@ -4,13 +4,9 @@ export function now(clock) {
|
|
|
4
4
|
const nanoseconds = (Date.now() % 1000) * 1000 * 1000;
|
|
5
5
|
return { seconds, nanoseconds };
|
|
6
6
|
}
|
|
7
|
-
console.log(
|
|
7
|
+
console.log(`[wall-clock] now() UNKNOWN CLOCK ${clock}`);
|
|
8
8
|
}
|
|
9
9
|
|
|
10
10
|
export function resolution(clock) {
|
|
11
|
-
console.log(`[
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
export function instanceWallClock () {
|
|
15
|
-
return 1;
|
|
11
|
+
console.log(`[wall-clock] Wall clock resolution ${clock}`);
|
|
16
12
|
}
|
package/package.json
CHANGED
|
@@ -1,10 +1,8 @@
|
|
|
1
1
|
export namespace MonotonicClock {
|
|
2
|
-
export function now(
|
|
3
|
-
export function resolution(
|
|
4
|
-
export function subscribe(
|
|
5
|
-
export function dropMonotonicClock(this: MonotonicClock): void;
|
|
2
|
+
export function now(): Instant;
|
|
3
|
+
export function resolution(): Instant;
|
|
4
|
+
export function subscribe(when: Instant, absolute: boolean): Pollable;
|
|
6
5
|
}
|
|
7
|
-
export type MonotonicClock = number;
|
|
8
6
|
export type Instant = bigint;
|
|
9
7
|
import type { Pollable } from '../imports/poll';
|
|
10
8
|
export { Pollable };
|
|
@@ -1,9 +1,7 @@
|
|
|
1
1
|
export namespace WallClock {
|
|
2
|
-
export function now(
|
|
3
|
-
export function resolution(
|
|
4
|
-
export function dropWallClock(this: WallClock): void;
|
|
2
|
+
export function now(): Datetime;
|
|
3
|
+
export function resolution(): Datetime;
|
|
5
4
|
}
|
|
6
|
-
export type WallClock = number;
|
|
7
5
|
export interface Datetime {
|
|
8
6
|
seconds: bigint,
|
|
9
7
|
nanoseconds: number,
|
package/types/wasi-reactor.d.ts
CHANGED
|
@@ -1,8 +1,6 @@
|
|
|
1
1
|
import { WallClock as WallClockImports } from './imports/wall-clock';
|
|
2
2
|
import { Poll as PollImports } from './imports/poll';
|
|
3
3
|
import { MonotonicClock as MonotonicClockImports } from './imports/monotonic-clock';
|
|
4
|
-
import { InstanceWallClock as InstanceWallClockImports } from './imports/instance-wall-clock';
|
|
5
|
-
import { InstanceMonotonicClock as InstanceMonotonicClockImports } from './imports/instance-monotonic-clock';
|
|
6
4
|
import { Timezone as TimezoneImports } from './imports/timezone';
|
|
7
5
|
import { Streams as StreamsImports } from './imports/streams';
|
|
8
6
|
import { Filesystem as FilesystemImports } from './imports/filesystem';
|
|
@@ -14,17 +12,16 @@ import { TcpCreateSocket as TcpCreateSocketImports } from './imports/tcp-create-
|
|
|
14
12
|
import { Udp as UdpImports } from './imports/udp';
|
|
15
13
|
import { UdpCreateSocket as UdpCreateSocketImports } from './imports/udp-create-socket';
|
|
16
14
|
import { Random as RandomImports } from './imports/random';
|
|
15
|
+
import { Console as ConsoleImports } from './imports/console';
|
|
16
|
+
import { Types as TypesImports } from './imports/types';
|
|
17
|
+
import { DefaultOutgoingHttp as DefaultOutgoingHttpImports } from './imports/default-outgoing-HTTP';
|
|
17
18
|
import { Environment as EnvironmentImports } from './imports/environment';
|
|
18
|
-
import { EnvironmentPreopens as EnvironmentPreopensImports } from './imports/environment-preopens';
|
|
19
19
|
import { Preopens as PreopensImports } from './imports/preopens';
|
|
20
20
|
import { Exit as ExitImports } from './imports/exit';
|
|
21
|
-
import { Stderr as StderrImports } from './imports/stderr';
|
|
22
21
|
export interface ImportObject {
|
|
23
22
|
'wall-clock': typeof WallClockImports,
|
|
24
23
|
'poll': typeof PollImports,
|
|
25
24
|
'monotonic-clock': typeof MonotonicClockImports,
|
|
26
|
-
'instance-wall-clock': typeof InstanceWallClockImports,
|
|
27
|
-
'instance-monotonic-clock': typeof InstanceMonotonicClockImports,
|
|
28
25
|
'timezone': typeof TimezoneImports,
|
|
29
26
|
'streams': typeof StreamsImports,
|
|
30
27
|
'filesystem': typeof FilesystemImports,
|
|
@@ -36,11 +33,12 @@ export interface ImportObject {
|
|
|
36
33
|
'udp': typeof UdpImports,
|
|
37
34
|
'udp-create-socket': typeof UdpCreateSocketImports,
|
|
38
35
|
'random': typeof RandomImports,
|
|
36
|
+
'console': typeof ConsoleImports,
|
|
37
|
+
'types': typeof TypesImports,
|
|
38
|
+
'default-outgoing-HTTP': typeof DefaultOutgoingHttpImports,
|
|
39
39
|
'environment': typeof EnvironmentImports,
|
|
40
|
-
'environment-preopens': typeof EnvironmentPreopensImports,
|
|
41
40
|
'preopens': typeof PreopensImports,
|
|
42
41
|
'exit': typeof ExitImports,
|
|
43
|
-
'stderr': typeof StderrImports,
|
|
44
42
|
}
|
|
45
43
|
export interface WasiReactor {
|
|
46
44
|
}
|
|
File without changes
|
|
File without changes
|