@bytecodealliance/preview2-shim 0.0.2 → 0.0.4

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 (60) hide show
  1. package/lib/browser/default-outgoing-HTTP.js +3 -0
  2. package/lib/browser/environment.js +3 -0
  3. package/lib/browser/filesystem.js +4 -0
  4. package/lib/browser/http.js +6 -4
  5. package/lib/browser/index.js +25 -11
  6. package/lib/browser/poll.js +4 -0
  7. package/lib/browser/streams.js +45 -0
  8. package/lib/browser/types.js +99 -0
  9. package/lib/http/error.js +1 -1
  10. package/lib/http/make-request.js +2 -2
  11. package/lib/http/synckit/index.d.ts +71 -0
  12. package/lib/http/synckit/index.js +141 -0
  13. package/lib/nodejs/default-outgoing-HTTP.js +3 -0
  14. package/lib/nodejs/environment.js +7 -0
  15. package/lib/nodejs/filesystem.js +9 -3
  16. package/lib/nodejs/http.js +4 -4
  17. package/lib/nodejs/index.js +25 -11
  18. package/lib/nodejs/monotonic-clock.js +4 -0
  19. package/lib/nodejs/poll.js +4 -0
  20. package/lib/nodejs/streams.js +45 -0
  21. package/lib/nodejs/types.js +99 -0
  22. package/lib/nodejs/wall-clock.js +4 -0
  23. package/package.json +18 -3
  24. package/types/exports/HTTP.d.ts +7 -0
  25. package/types/imports/console.d.ts +17 -0
  26. package/types/imports/default-outgoing-HTTP.d.ts +9 -0
  27. package/types/imports/environment-preopens.d.ts +5 -0
  28. package/types/imports/environment.d.ts +3 -0
  29. package/types/imports/exit.d.ts +4 -0
  30. package/types/imports/filesystem.d.ts +212 -0
  31. package/types/imports/instance-monotonic-clock.d.ts +5 -0
  32. package/types/imports/instance-network.d.ts +5 -0
  33. package/types/imports/instance-wall-clock.d.ts +5 -0
  34. package/types/imports/ip-name-lookup.d.ts +19 -0
  35. package/types/imports/monotonic-clock.d.ts +10 -0
  36. package/types/imports/network.d.ts +50 -0
  37. package/types/imports/poll.d.ts +5 -0
  38. package/types/imports/random.d.ts +5 -0
  39. package/types/{wasi-stderr.d.ts → imports/stderr.d.ts} +1 -1
  40. package/types/imports/streams.d.ts +23 -0
  41. package/types/imports/tcp-create-socket.d.ts +9 -0
  42. package/types/imports/tcp.d.ts +52 -0
  43. package/types/imports/timezone.d.ts +13 -0
  44. package/types/imports/types.d.ts +119 -0
  45. package/types/imports/udp-create-socket.d.ts +9 -0
  46. package/types/imports/udp.d.ts +36 -0
  47. package/types/imports/wall-clock.d.ts +10 -0
  48. package/types/index.d.ts +8 -9
  49. package/types/wasi-proxy.d.ts +44 -0
  50. package/types/wasi-reactor.d.ts +70 -0
  51. package/types/wasi-clocks.d.ts +0 -11
  52. package/types/wasi-default-clocks.d.ts +0 -6
  53. package/types/wasi-exit.d.ts +0 -3
  54. package/types/wasi-filesystem.d.ts +0 -150
  55. package/types/wasi-http.d.ts +0 -55
  56. package/types/wasi-io.d.ts +0 -10
  57. package/types/wasi-poll.d.ts +0 -4
  58. package/types/wasi-random.d.ts +0 -3
  59. /package/lib/browser/{logging.js → console.js} +0 -0
  60. /package/lib/nodejs/{logging.js → console.js} +0 -0
@@ -0,0 +1,3 @@
1
+ export function handle(_request, _options) {
2
+ console.log("[default-outgoing-HTTP] Handle");
3
+ }
@@ -0,0 +1,3 @@
1
+ export function getEnvironment () {
2
+ return [];
3
+ }
@@ -45,3 +45,7 @@ export function todoType(fd) {
45
45
  export function dropDirEntryStream(s) {
46
46
  console.log(`[filesystem] CLOSE DIR ENTRY STREAM: ${s}`);
47
47
  }
48
+
49
+ export function getPreopens () {
50
+ console.log(`[filesystem] GET PREOPENS`);
51
+ }
@@ -1,7 +1,7 @@
1
1
  import { UnexpectedError } from "../http/error.js";
2
2
 
3
3
  /**
4
- * @param {import("../types/wasi-http").Request} req
4
+ * @param {import("../types/imports/types").Request} req
5
5
  * @returns {string}
6
6
  */
7
7
  export function send(req) {
@@ -9,18 +9,20 @@ export function send(req) {
9
9
  try {
10
10
  const xhr = new XMLHttpRequest();
11
11
  xhr.open(req.method.toString(), req.uri, false);
12
- xhr.responseType = "arraybuffer";
13
12
  for (let [name, value] of req.headers) {
14
- xhr.setRequestHeader(name, value);
13
+ if (name !== "user-agent") {
14
+ xhr.setRequestHeader(name, value);
15
+ }
15
16
  }
16
17
  xhr.send(req.body.length > 0 ? req.body : null);
18
+ const body = xhr.response ? new TextEncoder().encode(xhr.response) : undefined;
17
19
  return {
18
20
  status: xhr.status,
19
21
  headers: xhr
20
22
  .getAllResponseHeaders()
21
23
  .trim()
22
24
  .split(/[\r\n]+/),
23
- body: xhr.response.byteLength > 0 ? xhr.response : undefined,
25
+ body,
24
26
  };
25
27
  } catch (err) {
26
28
  throw new UnexpectedError(err.message);
@@ -1,21 +1,35 @@
1
- import * as clocks from "./clocks.js";
2
1
  import * as defaultClocks from "./default-clocks.js";
2
+ import * as defaultOutgoingHttp from "./default-outgoing-HTTP.js";
3
+ import * as environment from "./environment.js";
3
4
  import * as exit from "./exit.js";
4
5
  import * as filesystem from "./filesystem.js";
6
+ import * as http from "./http.js";
5
7
  import * as io from "./io.js";
6
- import * as logging from "./logging.js";
8
+ import * as logging from "./console.js";
9
+ import * as monotonicClock from "./monotonic-clock.js";
7
10
  import * as poll from "./poll.js";
8
11
  import * as random from "./random.js";
9
12
  import * as stderr from "./stderr.js";
13
+ import * as streams from "./streams.js";
14
+ import * as types from "./types.js";
15
+ import * as wallClock from "./wall-clock.js";
10
16
 
11
17
  export const importObject = {
12
- "wasi-clocks": clocks,
13
- "wasi-default-clocks": defaultClocks,
14
- "wasi-exit": exit,
15
- "wasi-filesystem": filesystem,
16
- "wasi-io": io,
17
- "wasi-logging": logging,
18
- "wasi-poll": poll,
19
- "wasi-random": random,
20
- "wasi-stderr": stderr,
18
+ "default-clocks": defaultClocks,
19
+ "default-outgoing-HTTP": defaultOutgoingHttp,
20
+ "environment": environment,
21
+ "exit": exit,
22
+ "filesystem": filesystem,
23
+ "http": http,
24
+ "io": io,
25
+ "logging": logging,
26
+ "monotonic-clock": monotonicClock,
27
+ "poll": poll,
28
+ "random": random,
29
+ "stderr": stderr,
30
+ "streams": streams,
31
+ "types": types,
32
+ "wall-clock": wallClock,
21
33
  };
34
+
35
+ export default importObject;
@@ -1,3 +1,7 @@
1
+ export function dropPollable(p) {
2
+ console.log(`[poll] Drop pollable ${p}`);
3
+ }
4
+
1
5
  export function pollOneoff(f) {
2
6
  console.log(`[poll] Poll oneoff ${f}`);
3
7
  }
@@ -0,0 +1,45 @@
1
+ export function read(s, _len) {
2
+ console.log(`[streams] Read ${s}`);
3
+ }
4
+ export function blockingRead(s, _len) {
5
+ console.log(`[streams] Blocking read ${s}`);
6
+ }
7
+ export function skip(s, _len) {
8
+ console.log(`[streams] Skip ${s}`);
9
+ }
10
+ export function blockingSkip(s, _len) {
11
+ console.log(`[streams] Blocking skip ${s}`);
12
+ }
13
+ export function subscribeToInputStream(s) {
14
+ console.log(`[streams] Subscribe to input stream ${s}`);
15
+ }
16
+ export function dropInputStream(s) {
17
+ console.log(`[streams] Drop input stream ${s}`);
18
+ }
19
+ export function write(s, _buf) {
20
+ console.log(`[streams] Write ${s}`);
21
+ }
22
+ export function blockingWrite(s, _buf) {
23
+ console.log(`[streams] Blocking write ${s}`);
24
+ }
25
+ export function writeZeroes(s, _len) {
26
+ console.log(`[streams] Write zeroes ${s}`);
27
+ }
28
+ export function blockingWriteZeroes(s, _len) {
29
+ console.log(`[streams] Blocking write zeroes ${s}`);
30
+ }
31
+ export function splice(s, _src, _len) {
32
+ console.log(`[streams] Splice ${s}`);
33
+ }
34
+ export function blockingSplice(s, _src, _len) {
35
+ console.log(`[streams] Blocking splice ${s}`);
36
+ }
37
+ export function forward(s, _src) {
38
+ console.log(`[streams] Forward ${s}`);
39
+ }
40
+ export function subscribeToOutputStream(s) {
41
+ console.log(`[streams] Subscribe to output stream ${s}`);
42
+ }
43
+ export function dropOutputStream(s) {
44
+ console.log(`[streams] Drop output stream ${s}`);
45
+ }
@@ -0,0 +1,99 @@
1
+ export function dropFields(_fields) {
2
+ console.log("[types] Drop fields");
3
+ }
4
+ export function newFields(_entries) {
5
+ console.log("[types] New fields");
6
+ }
7
+ export function fieldsGet(_fields, _name) {
8
+ console.log("[types] Fields get");
9
+ }
10
+ export function fieldsSet(_fields, _name, _value) {
11
+ console.log("[types] Fields set");
12
+ }
13
+ export function fieldsDelete(_fields, _name) {
14
+ console.log("[types] Fields delete");
15
+ }
16
+ export function fieldsAppend(_fields, _name, _value) {
17
+ console.log("[types] Fields append");
18
+ }
19
+ export function fieldsEntries(_fields) {
20
+ console.log("[types] Fields entries");
21
+ }
22
+ export function fieldsClone(_fields) {
23
+ console.log("[types] Fields clone");
24
+ }
25
+ export function finishIncomingStream(s) {
26
+ console.log(`[types] Finish incoming stream ${s}`);
27
+ }
28
+ export function finishOutgoingStream(s, _trailers) {
29
+ console.log(`[types] Finish outgoing stream ${s}`);
30
+ }
31
+ export function dropIncomingRequest(_req) {
32
+ console.log("[types] Drop incoming request");
33
+ }
34
+ export function dropOutgoingRequest(_req) {
35
+ console.log("[types] Drop outgoing request");
36
+ }
37
+ export function incomingRequestMethod(_req) {
38
+ console.log("[types] Incoming request method");
39
+ }
40
+ export function incomingRequestPath(_req) {
41
+ console.log("[types] Incoming request path");
42
+ }
43
+ export function incomingRequestQuery(_req) {
44
+ console.log("[types] Incoming request query");
45
+ }
46
+ export function incomingRequestScheme(_req) {
47
+ console.log("[types] Incoming request scheme");
48
+ }
49
+ export function incomingRequestAuthority(_req) {
50
+ console.log("[types] Incoming request authority");
51
+ }
52
+ export function incomingRequestHeaders(_req) {
53
+ console.log("[types] Incoming request headers");
54
+ }
55
+ export function incomingRequestConsume(_req) {
56
+ console.log("[types] Incoming request consume");
57
+ }
58
+ export function newOutgoingRequest(_method, _path, _query, _scheme, _authority, _headers) {
59
+ console.log("[types] New outgoing request");
60
+ }
61
+ export function outgoingRequestWrite(_req) {
62
+ console.log("[types] Outgoing request write");
63
+ }
64
+ export function dropResponseOutparam(_res) {
65
+ console.log("[types] Drop response outparam");
66
+ }
67
+ export function setResponseOutparam(_res) {
68
+ console.log("[types] Drop fields");
69
+ }
70
+ export function dropIncomingResponse(_res) {
71
+ console.log("[types] Drop incoming response");
72
+ }
73
+ export function dropOutgoingResponse(_res) {
74
+ console.log("[types] Drop outgoing response");
75
+ }
76
+ export function incomingResponseStatus(_res) {
77
+ console.log("[types] Incoming response status");
78
+ }
79
+ export function incomingResponseHeaders(_res) {
80
+ console.log("[types] Incoming response headers");
81
+ }
82
+ export function incomingResponseConsume(_res) {
83
+ console.log("[types] Incoming response consume");
84
+ }
85
+ export function newOutgoingResponse(_statusCode, _headers) {
86
+ console.log("[types] New outgoing response");
87
+ }
88
+ export function outgoingResponseWrite(_res) {
89
+ console.log("[types] Outgoing response write");
90
+ }
91
+ export function dropFutureIncomingResponse(_f) {
92
+ console.log("[types] Drop future incoming response");
93
+ }
94
+ export function futureIncomingResponseGet(_f) {
95
+ console.log("[types] Future incoming response get");
96
+ }
97
+ export function listenToFutureIncomingResponse(_f) {
98
+ console.log("[types] Listen to future incoming response");
99
+ }
package/lib/http/error.js CHANGED
@@ -1,5 +1,5 @@
1
1
  export class UnexpectedError extends Error {
2
- /** @type { import("../types/wasi-http").HttpErrorUnexpectedError } */
2
+ /** @type { import("../types/http").HttpErrorUnexpectedError } */
3
3
  payload;
4
4
  constructor(message = "unexpected-error") {
5
5
  super(message);
@@ -1,7 +1,7 @@
1
- import { runAsWorker } from "synckit";
1
+ import { runAsWorker } from "./synckit/index.js";
2
2
 
3
3
  /**
4
- * @param {import("../types/wasi-http").Request} req
4
+ * @param {import("../types/imports/types").Request} req
5
5
  * @returns {Promise<string>}
6
6
  */
7
7
  async function makeRequest(req) {
@@ -0,0 +1,71 @@
1
+ /*
2
+ MIT License
3
+
4
+ Copyright (c) 2021 UnTS
5
+
6
+ Permission is hereby granted, free of charge, to any person obtaining a copy
7
+ of this software and associated documentation files (the "Software"), to deal
8
+ in the Software without restriction, including without limitation the rights
9
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10
+ copies of the Software, and to permit persons to whom the Software is
11
+ furnished to do so, subject to the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be included in all
14
+ copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22
+ SOFTWARE.
23
+ */
24
+
25
+ /// <reference types="node" />
26
+ import { MessagePort } from "node:worker_threads";
27
+ export type AnyFn<R = any, T extends any[] = any[]> = (...args: T) => R;
28
+ export type AnyPromise<T = any> = Promise<T>;
29
+ export type AnyAsyncFn<T = any> = AnyFn<Promise<T>>;
30
+ export type Syncify<T extends AnyAsyncFn> = T extends (
31
+ ...args: infer Args
32
+ ) => Promise<infer R>
33
+ ? (...args: Args) => R
34
+ : never;
35
+ export type PromiseType<T extends AnyPromise> = T extends Promise<infer R>
36
+ ? R
37
+ : never;
38
+ export interface MainToWorkerMessage<T extends unknown[]> {
39
+ sharedBuffer: SharedArrayBuffer;
40
+ id: number;
41
+ args: T;
42
+ }
43
+ export interface WorkerData {
44
+ workerPort: MessagePort;
45
+ }
46
+ export interface DataMessage<T> {
47
+ result?: T;
48
+ error?: unknown;
49
+ properties?: unknown;
50
+ }
51
+ export interface WorkerToMainMessage<T = unknown> extends DataMessage<T> {
52
+ id: number;
53
+ }
54
+ export interface SyncifyOptions {
55
+ bufferSize?: number;
56
+ timeout?: number;
57
+ execArgv?: string[];
58
+ }
59
+ export declare function createSyncFn<T extends AnyAsyncFn>(
60
+ workerPath: string,
61
+ bufferSize?: number,
62
+ timeout?: number
63
+ ): Syncify<T>;
64
+ export declare function createSyncFn<T extends AnyAsyncFn>(
65
+ workerPath: string,
66
+ options?: SyncifyOptions
67
+ ): Syncify<T>;
68
+ export declare function runAsWorker<
69
+ R = unknown,
70
+ T extends AnyAsyncFn<R> = AnyAsyncFn<R>
71
+ >(fn: T): void;
@@ -0,0 +1,141 @@
1
+ // Based on: https://github.com/un-ts/synckit
2
+ /*
3
+ MIT License
4
+
5
+ Copyright (c) 2021 UnTS
6
+
7
+ Permission is hereby granted, free of charge, to any person obtaining a copy
8
+ of this software and associated documentation files (the "Software"), to deal
9
+ in the Software without restriction, including without limitation the rights
10
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11
+ copies of the Software, and to permit persons to whom the Software is
12
+ furnished to do so, subject to the following conditions:
13
+
14
+ The above copyright notice and this permission notice shall be included in all
15
+ copies or substantial portions of the Software.
16
+
17
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23
+ SOFTWARE.
24
+ */
25
+
26
+ import path from "node:path";
27
+ import {
28
+ MessageChannel,
29
+ Worker,
30
+ receiveMessageOnPort,
31
+ workerData,
32
+ parentPort,
33
+ } from "node:worker_threads";
34
+
35
+ const DEFAULT_WORKER_BUFFER_SIZE = 1024;
36
+ const syncFnCache = new Map();
37
+
38
+ function extractProperties(object) {
39
+ if (object && typeof object === "object") {
40
+ const properties = {};
41
+ for (const key in object) {
42
+ properties[key] = object[key];
43
+ }
44
+ return properties;
45
+ }
46
+ }
47
+
48
+ export function createSyncFn(workerPath, bufferSizeOrOptions, timeout) {
49
+ if (!path.isAbsolute(workerPath)) {
50
+ throw new Error("`workerPath` must be absolute");
51
+ }
52
+ const cachedSyncFn = syncFnCache.get(workerPath);
53
+ if (cachedSyncFn) {
54
+ return cachedSyncFn;
55
+ }
56
+ const syncFn = startWorkerThread(
57
+ workerPath,
58
+ typeof bufferSizeOrOptions === "number"
59
+ ? { bufferSize: bufferSizeOrOptions, timeout }
60
+ : bufferSizeOrOptions
61
+ );
62
+ syncFnCache.set(workerPath, syncFn);
63
+ return syncFn;
64
+ }
65
+
66
+ function startWorkerThread(
67
+ workerPath,
68
+ {
69
+ bufferSize = DEFAULT_WORKER_BUFFER_SIZE,
70
+ timeout = undefined,
71
+ execArgv = [],
72
+ } = {}
73
+ ) {
74
+ const { port1: mainPort, port2: workerPort } = new MessageChannel();
75
+ const worker = new Worker(workerPath, {
76
+ workerData: { workerPort },
77
+ transferList: [workerPort],
78
+ execArgv: execArgv,
79
+ });
80
+ let nextID = 0;
81
+ const syncFn = (...args) => {
82
+ const id = nextID++;
83
+ const sharedBuffer = new SharedArrayBuffer(bufferSize);
84
+ const sharedBufferView = new Int32Array(sharedBuffer);
85
+ const msg = { sharedBuffer, id, args };
86
+ worker.postMessage(msg);
87
+ const status = Atomics.wait(sharedBufferView, 0, 0, timeout);
88
+ if (!["ok", "not-equal"].includes(status)) {
89
+ throw new Error("Internal error: Atomics.wait() failed: " + status);
90
+ }
91
+ const {
92
+ id: id2,
93
+ result,
94
+ error,
95
+ properties,
96
+ } = receiveMessageOnPort(mainPort).message;
97
+ if (id !== id2) {
98
+ throw new Error(`Internal error: Expected id ${id} but got id ${id2}`);
99
+ }
100
+ if (error) {
101
+ throw Object.assign(error, properties);
102
+ }
103
+ return result;
104
+ };
105
+ worker.unref();
106
+ return syncFn;
107
+ }
108
+
109
+ export function runAsWorker(fn) {
110
+ if (!workerData) {
111
+ return;
112
+ }
113
+ const { workerPort } = workerData;
114
+ try {
115
+ parentPort.on("message", ({ sharedBuffer, id, args }) => {
116
+ (async () => {
117
+ const sharedBufferView = new Int32Array(sharedBuffer);
118
+ let msg;
119
+ try {
120
+ msg = { id, result: await fn(...args) };
121
+ } catch (error) {
122
+ msg = { id, error, properties: extractProperties(error) };
123
+ }
124
+ workerPort.postMessage(msg);
125
+ Atomics.add(sharedBufferView, 0, 1);
126
+ Atomics.notify(sharedBufferView, 0);
127
+ })();
128
+ });
129
+ } catch (error) {
130
+ parentPort.on("message", ({ sharedBuffer, id }) => {
131
+ const sharedBufferView = new Int32Array(sharedBuffer);
132
+ workerPort.postMessage({
133
+ id,
134
+ error,
135
+ properties: extractProperties(error),
136
+ });
137
+ Atomics.add(sharedBufferView, 0, 1);
138
+ Atomics.notify(sharedBufferView, 0);
139
+ });
140
+ }
141
+ }
@@ -0,0 +1,3 @@
1
+ export function handle(_request, _options) {
2
+ console.log("[default-outgoing-HTTP] Handle");
3
+ }
@@ -0,0 +1,7 @@
1
+ export function getEnvironment () {
2
+ return [];
3
+ }
4
+
5
+ export function preopens () {
6
+ return [];
7
+ }
@@ -9,7 +9,7 @@
9
9
  // ctim: Timestamp,
10
10
  // }
11
11
 
12
- export function flags(fd) {
12
+ export function getFlags(fd) {
13
13
  console.log(`[filesystem] FLAGS FOR ${fd}`);
14
14
  }
15
15
 
@@ -49,10 +49,16 @@ export function stat(fd) {
49
49
  console.log(`[filesystem] STAT: ${fd}`);
50
50
  }
51
51
 
52
- export function todoType(fd) {
52
+ export function getType(fd) {
53
53
  console.log(`[filesystem] TODO TYPE: ${fd}`);
54
54
  }
55
55
 
56
- export function dropDirEntryStream(s) {
56
+ export function dropDirectoryEntryStream(s) {
57
57
  console.log(`[filesystem] CLOSE DIR ENTRY STREAM ${s}`);
58
58
  }
59
+
60
+ // backwards compat
61
+ export function getPreopens() {
62
+ return [];
63
+ }
64
+ export { getFlags as flags, getType as todoType, dropDirectoryEntryStream as dropDirEntryStream }
@@ -1,12 +1,12 @@
1
- import { createSyncFn } from "synckit";
2
- import path from "node:path";
3
1
  import { fileURLToPath } from "node:url";
4
2
  import { UnexpectedError } from "../http/error.js";
3
+ import { createSyncFn } from "../http/synckit/index.js";
4
+
5
+ const workerPath = fileURLToPath(new URL('../http/make-request.js', import.meta.url));
5
6
 
6
7
  export function send(req) {
7
8
  console.log(`[http] Send (nodejs) ${req.uri}`);
8
- const dirname = path.dirname(fileURLToPath(import.meta.url));
9
- const syncFn = createSyncFn(path.resolve(dirname, "../http/make-request.js"));
9
+ const syncFn = createSyncFn(workerPath);
10
10
  let rawResponse = syncFn(req);
11
11
  let response = JSON.parse(rawResponse);
12
12
  if (response.status) {
@@ -1,21 +1,35 @@
1
- import * as clocks from "./clocks.js";
1
+ import * as console from "./console.js";
2
2
  import * as defaultClocks from "./default-clocks.js";
3
+ import * as defaultOutgoingHttp from "./default-outgoing-HTTP.js";
4
+ import * as environment from "./environment.js";
3
5
  import * as exit from "./exit.js";
4
6
  import * as filesystem from "./filesystem.js";
7
+ import * as http from "./http.js";
5
8
  import * as io from "./io.js";
6
- import * as logging from "./logging.js";
9
+ import * as monotonicClock from "./monotonic-clock.js";
7
10
  import * as poll from "./poll.js";
8
11
  import * as random from "./random.js";
9
12
  import * as stderr from "./stderr.js";
13
+ import * as streams from "./streams.js";
14
+ import * as types from "./types.js";
15
+ import * as wallClock from "./wall-clock.js";
10
16
 
11
17
  export const importObject = {
12
- "wasi-clocks": clocks,
13
- "wasi-default-clocks": defaultClocks,
14
- "wasi-exit": exit,
15
- "wasi-filesystem": filesystem,
16
- "wasi-io": io,
17
- "wasi-logging": logging,
18
- "wasi-poll": poll,
19
- "wasi-random": random,
20
- "wasi-stderr": stderr,
18
+ "console": console,
19
+ "default-clocks": defaultClocks,
20
+ "default-outgoing-HTTP": defaultOutgoingHttp,
21
+ "environment": environment,
22
+ "exit": exit,
23
+ "filesystem": filesystem,
24
+ "http": http,
25
+ "io": io,
26
+ "monotonic-clock": monotonicClock,
27
+ "poll": poll,
28
+ "random": random,
29
+ "stderr": stderr,
30
+ "streams": streams,
31
+ "types": types,
32
+ "wall-clock": wallClock,
21
33
  };
34
+
35
+ export default importObject;
@@ -12,3 +12,7 @@ export function now(clock) {
12
12
  }
13
13
  console.log("[clocks] UNKNOWN CLOCK");
14
14
  }
15
+
16
+ export function instanceMonotonicClock () {
17
+ return 0;
18
+ }
@@ -1,3 +1,7 @@
1
+ export function dropPollable(p) {
2
+ console.log(`[poll] Drop pollable ${p}`);
3
+ }
4
+
1
5
  export function pollOneoff(f) {
2
6
  console.log(`[poll] Poll oneoff ${f}`);
3
7
  }
@@ -0,0 +1,45 @@
1
+ export function read(s, _len) {
2
+ console.log(`[streams] Read ${s}`);
3
+ }
4
+ export function blockingRead(s, _len) {
5
+ console.log(`[streams] Blocking read ${s}`);
6
+ }
7
+ export function skip(s, _len) {
8
+ console.log(`[streams] Skip ${s}`);
9
+ }
10
+ export function blockingSkip(s, _len) {
11
+ console.log(`[streams] Blocking skip ${s}`);
12
+ }
13
+ export function subscribeToInputStream(s) {
14
+ console.log(`[streams] Subscribe to input stream ${s}`);
15
+ }
16
+ export function dropInputStream(s) {
17
+ console.log(`[streams] Drop input stream ${s}`);
18
+ }
19
+ export function write(s, _buf) {
20
+ console.log(`[streams] Write ${s}`);
21
+ }
22
+ export function blockingWrite(s, _buf) {
23
+ console.log(`[streams] Blocking write ${s}`);
24
+ }
25
+ export function writeZeroes(s, _len) {
26
+ console.log(`[streams] Write zeroes ${s}`);
27
+ }
28
+ export function blockingWriteZeroes(s, _len) {
29
+ console.log(`[streams] Blocking write zeroes ${s}`);
30
+ }
31
+ export function splice(s, _src, _len) {
32
+ console.log(`[streams] Splice ${s}`);
33
+ }
34
+ export function blockingSplice(s, _src, _len) {
35
+ console.log(`[streams] Blocking splice ${s}`);
36
+ }
37
+ export function forward(s, _src) {
38
+ console.log(`[streams] Forward ${s}`);
39
+ }
40
+ export function subscribeToOutputStream(s) {
41
+ console.log(`[streams] Subscribe to output stream ${s}`);
42
+ }
43
+ export function dropOutputStream(s) {
44
+ console.log(`[streams] Drop output stream ${s}`);
45
+ }