@bytecodealliance/preview2-shim 0.0.20 → 0.14.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 (43) hide show
  1. package/README.md +4 -14
  2. package/lib/browser/cli.js +77 -12
  3. package/lib/browser/clocks.js +15 -27
  4. package/lib/browser/filesystem.js +147 -205
  5. package/lib/browser/index.js +1 -3
  6. package/lib/{common → browser}/io.js +8 -4
  7. package/lib/common/assert.js +7 -0
  8. package/lib/io/calls.js +64 -0
  9. package/lib/io/worker-http.js +95 -0
  10. package/lib/io/worker-io.js +322 -0
  11. package/lib/io/worker-thread.js +569 -0
  12. package/lib/nodejs/cli.js +45 -58
  13. package/lib/nodejs/clocks.js +13 -27
  14. package/lib/nodejs/filesystem.js +540 -427
  15. package/lib/nodejs/http.js +441 -175
  16. package/lib/nodejs/index.js +4 -1
  17. package/lib/nodejs/io.js +1 -0
  18. package/lib/nodejs/sockets/socket-common.js +116 -0
  19. package/lib/nodejs/sockets/socketopts-bindings.js +94 -0
  20. package/lib/nodejs/sockets/tcp-socket-impl.js +794 -0
  21. package/lib/nodejs/sockets/udp-socket-impl.js +628 -0
  22. package/lib/nodejs/sockets/wasi-sockets.js +320 -0
  23. package/lib/nodejs/sockets.js +11 -200
  24. package/lib/synckit/index.js +4 -2
  25. package/package.json +1 -5
  26. package/types/interfaces/wasi-cli-terminal-input.d.ts +4 -0
  27. package/types/interfaces/wasi-cli-terminal-output.d.ts +4 -0
  28. package/types/interfaces/wasi-clocks-monotonic-clock.d.ts +19 -6
  29. package/types/interfaces/wasi-filesystem-types.d.ts +1 -178
  30. package/types/interfaces/wasi-http-outgoing-handler.d.ts +2 -2
  31. package/types/interfaces/wasi-http-types.d.ts +412 -82
  32. package/types/interfaces/wasi-io-error.d.ts +16 -0
  33. package/types/interfaces/wasi-io-poll.d.ts +19 -8
  34. package/types/interfaces/wasi-io-streams.d.ts +26 -46
  35. package/types/interfaces/wasi-sockets-ip-name-lookup.d.ts +9 -21
  36. package/types/interfaces/wasi-sockets-network.d.ts +4 -0
  37. package/types/interfaces/wasi-sockets-tcp.d.ts +75 -18
  38. package/types/interfaces/wasi-sockets-udp-create-socket.d.ts +1 -1
  39. package/types/interfaces/wasi-sockets-udp.d.ts +282 -193
  40. package/types/wasi-cli-command.d.ts +28 -28
  41. package/types/wasi-http-proxy.d.ts +12 -12
  42. package/lib/common/make-request.js +0 -30
  43. package/types/interfaces/wasi-clocks-timezone.d.ts +0 -56
package/README.md CHANGED
@@ -1,20 +1,10 @@
1
- # WASI Preview2 JavaScript Shim
1
+ # Preview2 Shim
2
2
 
3
- _**Experimental**_ shim modules for the [WASI Preview2](https://github.com/bytecodealliance/preview2-prototyping) component interfaces in JS environments.
3
+ WASI Preview2 implementations for Node.js & browsers.
4
4
 
5
- Currently supports Node.js and browser versions, but alternative implementations for any JS environments can be supported.
5
+ Browser support is considered experimental, and not currently suitable for production applications.
6
6
 
7
- ## Implementation Status
8
-
9
- | Interface | Node.js | Browser |
10
- | --------------- | ----------------------------:|-----------------------------:|
11
- | Clocks | Pending timezone, poll | Pending timezone, poll |
12
- | Filesystem | Basic read support | _N/A_ |
13
- | HTTP | Experimental support | :x: |
14
- | IO | Experimental support | Experimental support |
15
- | Random | :heavy_check_mark: | :heavy_check_mark: |
16
- | Sockets | :x: | _N/A_ |
17
- | CLI | :heavy_check_mark: | :heavy_check_mark: |
7
+ Node.js support is currently being stabilized, which can be tracked in https://github.com/bytecodealliance/jco/milestone/1.
18
8
 
19
9
  # License
20
10
 
@@ -1,4 +1,8 @@
1
1
  import { _setCwd as fsSetCwd } from './filesystem.js';
2
+ import { streams } from './io.js';
3
+ const { InputStream, OutputStream } = streams;
4
+
5
+ const symbolDispose = Symbol.dispose ?? Symbol.for('dispose');
2
6
 
3
7
  let _env = [], _args = [], _cwd = null;
4
8
  export function _setEnv (envObj) {
@@ -38,50 +42,111 @@ export const exit = {
38
42
  }
39
43
  };
40
44
 
45
+ /**
46
+ * @param {import('../common/io.js').InputStreamHandler} handler
47
+ */
48
+ export function _setStdin (handler) {
49
+ stdinStream.handler = handler;
50
+ }
51
+ /**
52
+ * @param {import('../common/io.js').OutputStreamHandler} handler
53
+ */
54
+ export function _setStderr (handler) {
55
+ stderrStream.handler = handler;
56
+ }
57
+ /**
58
+ * @param {import('../common/io.js').OutputStreamHandler} handler
59
+ */
60
+ export function _setStdout (handler) {
61
+ stdoutStream.handler = handler;
62
+ }
63
+
64
+ const stdinStream = new InputStream({
65
+ blockingRead (_len) {
66
+ // TODO
67
+ },
68
+ subscribe () {
69
+ // TODO
70
+ },
71
+ [symbolDispose] () {
72
+ // TODO
73
+ }
74
+ });
75
+ let textDecoder = new TextDecoder();
76
+ const stdoutStream = new OutputStream({
77
+ write (contents) {
78
+ console.log(textDecoder.decode(contents));
79
+ },
80
+ blockingFlush () {
81
+ },
82
+ [symbolDispose] () {
83
+ }
84
+ });
85
+ const stderrStream = new OutputStream({
86
+ write (contents) {
87
+ console.error(textDecoder.decode(contents));
88
+ },
89
+ blockingFlush () {
90
+
91
+ },
92
+ [symbolDispose] () {
93
+
94
+ }
95
+ });
96
+
41
97
  export const stdin = {
98
+ InputStream,
42
99
  getStdin () {
43
- return 0;
100
+ return stdinStream;
44
101
  }
45
102
  };
46
103
 
47
104
  export const stdout = {
105
+ OutputStream,
48
106
  getStdout () {
49
- return 1;
107
+ return stdoutStream;
50
108
  }
51
109
  };
52
110
 
53
111
  export const stderr = {
112
+ OutputStream,
54
113
  getStderr () {
55
- return 2;
114
+ return stderrStream;
56
115
  }
57
116
  };
58
117
 
59
- export const terminalInput = {
60
- dropTerminalInput () {
118
+ class TerminalInput {}
119
+ class TerminalOutput {}
61
120
 
62
- }
121
+ const terminalStdoutInstance = new TerminalOutput();
122
+ const terminalStderrInstance = new TerminalOutput();
123
+ const terminalStdinInstance = new TerminalInput();
124
+
125
+ export const terminalInput = {
126
+ TerminalInput
63
127
  };
64
128
 
65
129
  export const terminalOutput = {
66
- dropTerminalOutput () {
67
-
68
- }
130
+ TerminalOutput
69
131
  };
70
132
 
71
133
  export const terminalStderr = {
134
+ TerminalOutput,
72
135
  getTerminalStderr () {
73
- return 0;
136
+ return terminalStderrInstance;
74
137
  }
75
138
  };
76
139
 
77
140
  export const terminalStdin = {
141
+ TerminalInput,
78
142
  getTerminalStdin () {
79
- return 1;
143
+ return terminalStdinInstance;
80
144
  }
81
145
  };
82
146
 
83
147
  export const terminalStdout = {
148
+ TerminalOutput,
84
149
  getTerminalStdout () {
85
- return 2;
150
+ return terminalStdoutInstance;
86
151
  }
87
152
  };
@@ -1,34 +1,23 @@
1
- function _hrtimeBigint () {
2
- // performance.now() is in milliseconds, but we want nanoseconds
3
- return BigInt(Math.floor(performance.now() * 1e6));
4
- }
5
-
6
- let _hrStart = _hrtimeBigint();
7
-
8
1
  export const monotonicClock = {
9
2
  resolution() {
10
- return 1n;
3
+ // usually we dont get sub-millisecond accuracy in the browser
4
+ // Note: is there a better way to determine this?
5
+ return 1e6;
11
6
  },
12
7
  now () {
13
- return _hrtimeBigint() - _hrStart;
8
+ // performance.now() is in milliseconds, but we want nanoseconds
9
+ return BigInt(Math.floor(performance.now() * 1e6));
14
10
  },
15
- subscribe (_when, _absolute) {
16
- console.log(`[monotonic-clock] Subscribe`);
17
- }
18
- };
19
-
20
- export const timezone = {
21
- display (timezone, when) {
22
- console.log(`[timezone] DISPLAY ${timezone} ${when}`);
11
+ subscribeInstant (instant) {
12
+ instant = BigInt(instant);
13
+ const now = this.now();
14
+ if (instant <= now)
15
+ return this.subscribeDuration(0);
16
+ return this.subscribeDuration(instant - now);
23
17
  },
24
-
25
- utcOffset (timezone, when) {
26
- console.log(`[timezone] UTC OFFSET ${timezone} ${when}`);
27
- return 0;
28
- },
29
-
30
- dropTimezone (timezone) {
31
- console.log(`[timezone] DROP ${timezone}`);
18
+ subscribeDuration (_duration) {
19
+ _duration = BigInt(_duration);
20
+ console.log(`[monotonic-clock] subscribe`);
32
21
  }
33
22
  };
34
23
 
@@ -39,8 +28,7 @@ export const wallClock = {
39
28
  const nanoseconds = (now % 1e3) * 1e6;
40
29
  return { seconds, nanoseconds };
41
30
  },
42
-
43
31
  resolution() {
44
- console.log(`[wall-clock] Wall clock resolution`);
32
+ return { seconds: 0n, nanoseconds: 1e6 };
45
33
  }
46
34
  };
@@ -1,15 +1,7 @@
1
- import { _io } from './io.js';
1
+ import { streams } from './io.js';
2
2
  import { environment } from './cli.js';
3
3
 
4
- const { createStream, getStream, dropStream } = _io;
5
-
6
- let _preopens = [[3, '/']], _rootPreopen = _preopens[0];
7
-
8
- export function _setPreopens (preopens) {
9
- _preopens = preopens;
10
- descriptorCnt = 3 + _preopens.length;
11
- _rootPreopen = _preopens.find(preopen => preopen[1] === '/');
12
- }
4
+ const { InputStream, OutputStream } = streams;
13
5
 
14
6
  let _cwd = null;
15
7
 
@@ -19,11 +11,7 @@ export function _setCwd (cwd) {
19
11
 
20
12
  export function _setFileData (fileData) {
21
13
  _fileData = fileData;
22
- _setPreopens(Object.keys(fileData).map((key) => {
23
- const fd = descriptorCnt++;
24
- descriptorTable[fd] = { entry: fileData[key] };
25
- return [fd, key];
26
- }));
14
+ _rootPreopen[0] = new Descriptor(fileData);
27
15
  const cwd = environment.initialCwd();
28
16
  _setCwd(cwd || '/');
29
17
  }
@@ -32,34 +20,20 @@ export function _getFileData () {
32
20
  return JSON.stringify(_fileData);
33
21
  }
34
22
 
35
- let _fileData = {};
36
-
37
- let descriptorCnt = 4;
38
- const descriptorTable = {
39
- 0: { stream: 0 },
40
- 1: { stream: 1 },
41
- 2: { stream: 2 },
42
- 3: { entry: { dir: {} } },
43
- };
23
+ let _fileData = { dir: {} };
44
24
 
45
25
  const timeZero = {
46
26
  seconds: BigInt(0),
47
27
  nanoseconds: 0
48
28
  };
49
29
 
50
- function getDescriptor (fd) {
51
- const descriptor = descriptorTable[fd];
52
- if (!descriptor) throw 'bad-descriptor';
53
- return descriptor;
54
- }
55
-
56
- function getChildEntry (fd, subpath, openFlags) {
57
- if (subpath === '.' && _rootPreopen && _rootPreopen[0] === fd) {
30
+ function getChildEntry (parentEntry, subpath, openFlags) {
31
+ if (subpath === '.' && _rootPreopen && descriptorGetEntry(_rootPreopen[0]) === parentEntry) {
58
32
  subpath = _cwd;
59
- if (subpath.startsWith('/'))
33
+ if (subpath.startsWith('/') && subpath !== '/')
60
34
  subpath = subpath.slice(1);
61
35
  }
62
- let entry = getDescriptor(fd)?.entry;
36
+ let entry = parentEntry;
63
37
  let segmentIdx;
64
38
  do {
65
39
  if (!entry || !entry.dir) throw 'not-directory';
@@ -76,13 +50,6 @@ function getChildEntry (fd, subpath, openFlags) {
76
50
  return entry;
77
51
  }
78
52
 
79
- function createChildDescriptor (fd, subpath, openFlags) {
80
- const entry = getChildEntry(fd, subpath, openFlags);
81
- const childFd = descriptorCnt++;
82
- descriptorTable[childFd] = { entry };
83
- return childFd;
84
- }
85
-
86
53
  function getSource (fileEntry) {
87
54
  if (typeof fileEntry.source === 'string') {
88
55
  fileEntry.source = new TextEncoder().encode(fileEntry.source);
@@ -90,12 +57,12 @@ function getSource (fileEntry) {
90
57
  return fileEntry.source;
91
58
  }
92
59
 
93
- class DirStream {
60
+ class DirectoryEntryStream {
94
61
  constructor (entries) {
95
62
  this.idx = 0;
96
63
  this.entries = entries;
97
64
  }
98
- next () {
65
+ readDirectoryEntry () {
99
66
  if (this.idx === this.entries.length)
100
67
  return null;
101
68
  const [name, entry] = this.entries[this.idx];
@@ -107,117 +74,116 @@ class DirStream {
107
74
  }
108
75
  }
109
76
 
110
- export const preopens = {
111
- getDirectories () {
112
- return _preopens;
77
+ class Descriptor {
78
+ #stream;
79
+ #entry;
80
+ #mtime = 0;
81
+
82
+ _getEntry (descriptor) {
83
+ return descriptor.#entry;
113
84
  }
114
- }
115
85
 
116
- export const types = {
117
- readViaStream(fd, offset) {
118
- const descriptor = getDescriptor(fd);
119
- const source = getSource(descriptor.entry);
120
- return createStream({
121
- i: Number(offset),
122
- source,
123
- read (len) {
124
- const bytes = this.source.slice(this.i, this.i + Number(len));
125
- this.i += bytes.byteLength;
126
- return [bytes, this.i === this.source.byteLength ? 'ended' : 'open'];
86
+ constructor (entry, isStream) {
87
+ if (isStream)
88
+ this.#stream = entry;
89
+ else
90
+ this.#entry = entry;
91
+ }
92
+
93
+ readViaStream(_offset) {
94
+ const source = getSource(this.#entry);
95
+ let offset = Number(_offset);
96
+ return new InputStream({
97
+ blockingRead (len) {
98
+ if (offset === source.byteLength)
99
+ throw { tag: 'closed' };
100
+ const bytes = source.slice(offset, offset + Number(len));
101
+ offset += bytes.byteLength;
102
+ return bytes;
127
103
  }
128
104
  });
129
- },
105
+ }
130
106
 
131
- writeViaStream(fd, offset) {
132
- const descriptor = getDescriptor(fd);
133
- return createStream({
134
- i: Number(offset),
135
- entry: descriptor.entry,
107
+ writeViaStream(_offset) {
108
+ const entry = this.#entry;
109
+ let offset = Number(_offset);
110
+ return new OutputStream({
136
111
  write (buf) {
137
- const newSource = new Uint8Array(buf.byteLength + this.entry.source.byteLength);
138
- newSource.set(this.entry.source, 0);
139
- newSource.set(buf, this.i);
140
- this.i += buf.byteLength;
141
- this.entry.source = newSource;
112
+ const newSource = new Uint8Array(buf.byteLength + entry.source.byteLength);
113
+ newSource.set(entry.source, 0);
114
+ newSource.set(buf, offset);
115
+ offset += buf.byteLength;
116
+ entry.source = newSource;
142
117
  return buf.byteLength;
143
118
  }
144
119
  });
145
- },
146
-
147
- appendViaStream(fd) {
148
- console.log(`[filesystem] APPEND STREAM ${fd}`);
149
- },
150
-
151
- advise(fd, offset, length, advice) {
152
- console.log(`[filesystem] ADVISE`, fd, offset, length, advice);
153
- },
154
-
155
- syncData(fd) {
156
- console.log(`[filesystem] SYNC DATA ${fd}`);
157
- },
158
-
159
- getFlags(fd) {
160
- console.log(`[filesystem] FLAGS FOR ${fd}`);
161
- },
162
-
163
- getType(fd) {
164
- if (fd < 3) return 'fifo';
165
- const descriptor = getDescriptor(fd);
166
- if (descriptor.stream) return 'fifo';
167
- if (descriptor.entry.dir) return 'directory';
168
- if (descriptor.entry.source) return 'regular-file';
169
- return 'unknown';
170
- },
120
+ }
171
121
 
172
- setFlags(fd, flags) {
173
- console.log(`[filesystem] SET FLAGS ${fd} ${JSON.stringify(flags)}`);
174
- },
122
+ appendViaStream() {
123
+ console.log(`[filesystem] APPEND STREAM`);
124
+ }
175
125
 
176
- setSize(fd, size) {
177
- console.log(`[filesystem] SET SIZE`, fd, size);
178
- },
126
+ advise(descriptor, offset, length, advice) {
127
+ console.log(`[filesystem] ADVISE`, descriptor, offset, length, advice);
128
+ }
179
129
 
180
- setTimes(fd, dataAccessTimestamp, dataModificationTimestamp) {
181
- console.log(`[filesystem] SET TIMES`, fd, dataAccessTimestamp, dataModificationTimestamp);
182
- },
130
+ syncData() {
131
+ console.log(`[filesystem] SYNC DATA`);
132
+ }
133
+
134
+ getFlags() {
135
+ console.log(`[filesystem] FLAGS FOR`);
136
+ }
183
137
 
184
- read(fd, length, offset) {
185
- const descriptor = getDescriptor(fd);
186
- const source = getSource(descriptor.entry);
138
+ getType() {
139
+ if (this.#stream) return 'fifo';
140
+ if (this.#entry.dir) return 'directory';
141
+ if (this.#entry.source) return 'regular-file';
142
+ return 'unknown';
143
+ }
144
+
145
+ setSize(size) {
146
+ console.log(`[filesystem] SET SIZE`, size);
147
+ }
148
+
149
+ setTimes(dataAccessTimestamp, dataModificationTimestamp) {
150
+ console.log(`[filesystem] SET TIMES`, dataAccessTimestamp, dataModificationTimestamp);
151
+ }
152
+
153
+ read(length, offset) {
154
+ const source = getSource(this.#entry);
187
155
  return [source.slice(offset, offset + length), offset + length >= source.byteLength];
188
- },
156
+ }
189
157
 
190
- write(fd, buffer, offset) {
191
- const descriptor = getDescriptor(fd);
158
+ write(buffer, offset) {
192
159
  if (offset !== 0) throw 'invalid-seek';
193
- descriptor.entry.source = buffer;
160
+ this.#entry.source = buffer;
194
161
  return buffer.byteLength;
195
- },
162
+ }
196
163
 
197
- readDirectory(fd) {
198
- const descriptor = getDescriptor(fd);
199
- if (!descriptor?.entry?.dir) throw 'bad-descriptor';
200
- return createStream(new DirStream(Object.entries(descriptor.entry.dir).sort(([a], [b]) => a > b ? 1 : -1)));
201
- },
164
+ readDirectory() {
165
+ if (!this.#entry?.dir)
166
+ throw 'bad-descriptor';
167
+ return new DirectoryEntryStream(Object.entries(this.#entry.dir).sort(([a], [b]) => a > b ? 1 : -1));
168
+ }
202
169
 
203
- sync(fd) {
204
- console.log(`[filesystem] SYNC`, fd);
205
- },
170
+ sync() {
171
+ console.log(`[filesystem] SYNC`);
172
+ }
206
173
 
207
- createDirectoryAt(fd, path) {
208
- const entry = getChildEntry(fd, path, { create: true, directory: true });
174
+ createDirectoryAt(path) {
175
+ const entry = getChildEntry(this.#entry, path, { create: true, directory: true });
209
176
  if (entry.source) throw 'exist';
210
- },
177
+ }
211
178
 
212
- stat(fd) {
213
- const descriptor = getDescriptor(fd);
179
+ stat() {
214
180
  let type = 'unknown', size = BigInt(0);
215
- if (descriptor.entry.source) {
181
+ if (this.#entry.source) {
216
182
  type = 'directory';
217
183
  }
218
- else if (descriptor.entry.dir) {
184
+ else if (this.#entry.dir) {
219
185
  type = 'regular-file';
220
- const source = getSource(descriptor.entry);
186
+ const source = getSource(this.#entry);
221
187
  size = BigInt(source.byteLength);
222
188
  }
223
189
  return {
@@ -228,10 +194,10 @@ export const types = {
228
194
  dataModificationTimestamp: timeZero,
229
195
  statusChangeTimestamp: timeZero,
230
196
  }
231
- },
197
+ }
232
198
 
233
- statAt(fd, pathFlags, path) {
234
- const entry = getChildEntry(fd, path);
199
+ statAt(_pathFlags, path) {
200
+ const entry = getChildEntry(this.#entry, path);
235
201
  let type = 'unknown', size = BigInt(0);
236
202
  if (entry.source) {
237
203
  type = 'regular-file';
@@ -249,95 +215,71 @@ export const types = {
249
215
  dataModificationTimestamp: timeZero,
250
216
  statusChangeTimestamp: timeZero,
251
217
  };
252
- },
253
-
254
- setTimesAt(fd) {
255
- console.log(`[filesystem] SET TIMES AT`, fd);
256
- },
257
-
258
- linkAt(fd) {
259
- console.log(`[filesystem] LINK AT`, fd);
260
- },
261
-
262
- openAt(fd, _pathFlags, path, openFlags, _descriptorFlags, _modes) {
263
- return createChildDescriptor(fd, path, openFlags);
264
- },
265
-
266
- readlinkAt(fd) {
267
- console.log(`[filesystem] READLINK AT`, fd);
268
- },
269
-
270
- removeDirectoryAt(fd) {
271
- console.log(`[filesystem] REMOVE DIR AT`, fd);
272
- },
273
-
274
- renameAt(fd) {
275
- console.log(`[filesystem] RENAME AT`, fd);
276
- },
277
-
278
- symlinkAt(fd) {
279
- console.log(`[filesystem] SYMLINK AT`, fd);
280
- },
281
-
282
- unlinkFileAt(fd) {
283
- console.log(`[filesystem] UNLINK FILE AT`, fd);
284
- },
285
-
286
- changeFilePermissionsAt(fd) {
287
- console.log(`[filesystem] CHANGE FILE PERMISSIONS AT`, fd);
288
- },
218
+ }
289
219
 
290
- changeDirectoryPermissionsAt(fd) {
291
- console.log(`[filesystem] CHANGE DIR PERMISSIONS AT`, fd);
292
- },
220
+ setTimesAt() {
221
+ console.log(`[filesystem] SET TIMES AT`);
222
+ }
293
223
 
294
- lockShared(fd) {
295
- console.log(`[filesystem] LOCK SHARED`, fd);
296
- },
224
+ linkAt() {
225
+ console.log(`[filesystem] LINK AT`);
226
+ }
297
227
 
298
- lockExclusive(fd) {
299
- console.log(`[filesystem] LOCK EXCLUSIVE`, fd);
300
- },
228
+ openAt(_pathFlags, path, openFlags, _descriptorFlags, _modes) {
229
+ const childEntry = getChildEntry(this.#entry, path, openFlags);
230
+ return new Descriptor(childEntry);
231
+ }
301
232
 
302
- tryLockShared(fd) {
303
- console.log(`[filesystem] TRY LOCK SHARED`, fd);
304
- },
233
+ readlinkAt() {
234
+ console.log(`[filesystem] READLINK AT`);
235
+ }
305
236
 
306
- tryLockExclusive(fd) {
307
- console.log(`[filesystem] TRY LOCK EXCLUSIVE`, fd);
308
- },
237
+ removeDirectoryAt() {
238
+ console.log(`[filesystem] REMOVE DIR AT`);
239
+ }
309
240
 
310
- unlock(fd) {
311
- console.log(`[filesystem] UNLOCK`, fd);
312
- },
241
+ renameAt() {
242
+ console.log(`[filesystem] RENAME AT`);
243
+ }
313
244
 
314
- dropDescriptor(fd) {
315
- if (fd < _preopens.length + 3)
316
- return;
317
- delete descriptorTable[fd];
318
- },
245
+ symlinkAt() {
246
+ console.log(`[filesystem] SYMLINK AT`);
247
+ }
319
248
 
320
- readDirectoryEntry(sid) {
321
- return getStream(sid).next();
322
- },
249
+ unlinkFileAt() {
250
+ console.log(`[filesystem] UNLINK FILE AT`);
251
+ }
323
252
 
324
- dropDirectoryEntryStream(sid) {
325
- dropStream(sid);
326
- },
253
+ isSameObject(other) {
254
+ return other === this;
255
+ }
327
256
 
328
- metadataHash(fd) {
329
- const descriptor = getDescriptor(fd);
257
+ metadataHash() {
330
258
  let upper = BigInt(0);
331
- upper += BigInt(descriptor.mtime || 0);
259
+ upper += BigInt(this.#mtime);
332
260
  return { upper, lower: BigInt(0) };
333
- },
261
+ }
334
262
 
335
- metadataHashAt(fd, _pathFlags, _path) {
336
- const descriptor = getDescriptor(fd);
263
+ metadataHashAt(_pathFlags, _path) {
337
264
  let upper = BigInt(0);
338
- upper += BigInt(descriptor.mtime || 0);
265
+ upper += BigInt(this.#mtime);
339
266
  return { upper, lower: BigInt(0) };
340
267
  }
268
+ }
269
+ const descriptorGetEntry = Descriptor.prototype._getEntry;
270
+ delete Descriptor.prototype._getEntry;
271
+
272
+ let _preopens = [[new Descriptor(_fileData), '/']], _rootPreopen = _preopens[0];
273
+
274
+ export const preopens = {
275
+ getDirectories () {
276
+ return _preopens;
277
+ }
278
+ }
279
+
280
+ export const types = {
281
+ Descriptor,
282
+ DirectoryEntryStream
341
283
  };
342
284
 
343
- export { types as filesystemTypes }
285
+ export { types as filesystemTypes }
@@ -1,7 +1,7 @@
1
1
  import * as clocks from "./clocks.js";
2
2
  import * as filesystem from "./filesystem.js";
3
3
  import * as http from "./http.js";
4
- import * as io from "../common/io.js";
4
+ import * as io from "./io.js";
5
5
  import * as random from "./random.js";
6
6
  import * as sockets from "./sockets.js";
7
7
  import * as cli from "./cli.js";
@@ -15,5 +15,3 @@ export {
15
15
  sockets,
16
16
  cli,
17
17
  }
18
-
19
- export { WasiHttp } from "../http/wasi-http.js";