@cosmonic-labs/openapi2mcp 0.10.1 → 0.10.2

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 (75) hide show
  1. package/dist/openapi2mcp.core.wasm +0 -0
  2. package/node_modules/@bytecodealliance/preview2-shim/LICENSE +220 -0
  3. package/node_modules/@bytecodealliance/preview2-shim/README.md +113 -0
  4. package/node_modules/@bytecodealliance/preview2-shim/lib/browser/cli.js +135 -0
  5. package/node_modules/@bytecodealliance/preview2-shim/lib/browser/clocks.js +39 -0
  6. package/node_modules/@bytecodealliance/preview2-shim/lib/browser/config.js +9 -0
  7. package/node_modules/@bytecodealliance/preview2-shim/lib/browser/environment.js +29 -0
  8. package/node_modules/@bytecodealliance/preview2-shim/lib/browser/filesystem.js +485 -0
  9. package/node_modules/@bytecodealliance/preview2-shim/lib/browser/http.js +707 -0
  10. package/node_modules/@bytecodealliance/preview2-shim/lib/browser/index.js +9 -0
  11. package/node_modules/@bytecodealliance/preview2-shim/lib/browser/io.js +262 -0
  12. package/node_modules/@bytecodealliance/preview2-shim/lib/browser/random.js +56 -0
  13. package/node_modules/@bytecodealliance/preview2-shim/lib/browser/sockets.js +88 -0
  14. package/node_modules/@bytecodealliance/preview2-shim/lib/common/instantiation.js +253 -0
  15. package/node_modules/@bytecodealliance/preview2-shim/lib/io/calls.js +128 -0
  16. package/node_modules/@bytecodealliance/preview2-shim/lib/io/worker-http.js +206 -0
  17. package/node_modules/@bytecodealliance/preview2-shim/lib/io/worker-io.js +468 -0
  18. package/node_modules/@bytecodealliance/preview2-shim/lib/io/worker-socket-tcp.js +331 -0
  19. package/node_modules/@bytecodealliance/preview2-shim/lib/io/worker-socket-udp.js +587 -0
  20. package/node_modules/@bytecodealliance/preview2-shim/lib/io/worker-sockets.js +364 -0
  21. package/node_modules/@bytecodealliance/preview2-shim/lib/io/worker-thread.js +1051 -0
  22. package/node_modules/@bytecodealliance/preview2-shim/lib/nodejs/cli.js +109 -0
  23. package/node_modules/@bytecodealliance/preview2-shim/lib/nodejs/clocks.js +67 -0
  24. package/node_modules/@bytecodealliance/preview2-shim/lib/nodejs/filesystem.js +829 -0
  25. package/node_modules/@bytecodealliance/preview2-shim/lib/nodejs/http.js +764 -0
  26. package/node_modules/@bytecodealliance/preview2-shim/lib/nodejs/index.js +9 -0
  27. package/node_modules/@bytecodealliance/preview2-shim/lib/nodejs/io.js +1 -0
  28. package/node_modules/@bytecodealliance/preview2-shim/lib/nodejs/random.js +49 -0
  29. package/node_modules/@bytecodealliance/preview2-shim/lib/nodejs/sockets.js +565 -0
  30. package/node_modules/@bytecodealliance/preview2-shim/lib/synckit/index.js +127 -0
  31. package/node_modules/@bytecodealliance/preview2-shim/package.json +65 -0
  32. package/node_modules/@bytecodealliance/preview2-shim/types/cli.d.ts +11 -0
  33. package/node_modules/@bytecodealliance/preview2-shim/types/clocks.d.ts +2 -0
  34. package/node_modules/@bytecodealliance/preview2-shim/types/filesystem.d.ts +29 -0
  35. package/node_modules/@bytecodealliance/preview2-shim/types/http.d.ts +3 -0
  36. package/node_modules/@bytecodealliance/preview2-shim/types/index.d.ts +6 -0
  37. package/node_modules/@bytecodealliance/preview2-shim/types/instantiation.d.ts +199 -0
  38. package/node_modules/@bytecodealliance/preview2-shim/types/interfaces/wasi-cli-environment.d.ts +21 -0
  39. package/node_modules/@bytecodealliance/preview2-shim/types/interfaces/wasi-cli-exit.d.ts +6 -0
  40. package/node_modules/@bytecodealliance/preview2-shim/types/interfaces/wasi-cli-run.d.ts +5 -0
  41. package/node_modules/@bytecodealliance/preview2-shim/types/interfaces/wasi-cli-stderr.d.ts +3 -0
  42. package/node_modules/@bytecodealliance/preview2-shim/types/interfaces/wasi-cli-stdin.d.ts +3 -0
  43. package/node_modules/@bytecodealliance/preview2-shim/types/interfaces/wasi-cli-stdout.d.ts +3 -0
  44. package/node_modules/@bytecodealliance/preview2-shim/types/interfaces/wasi-cli-terminal-input.d.ts +8 -0
  45. package/node_modules/@bytecodealliance/preview2-shim/types/interfaces/wasi-cli-terminal-output.d.ts +8 -0
  46. package/node_modules/@bytecodealliance/preview2-shim/types/interfaces/wasi-cli-terminal-stderr.d.ts +7 -0
  47. package/node_modules/@bytecodealliance/preview2-shim/types/interfaces/wasi-cli-terminal-stdin.d.ts +7 -0
  48. package/node_modules/@bytecodealliance/preview2-shim/types/interfaces/wasi-cli-terminal-stdout.d.ts +7 -0
  49. package/node_modules/@bytecodealliance/preview2-shim/types/interfaces/wasi-clocks-monotonic-clock.d.ts +34 -0
  50. package/node_modules/@bytecodealliance/preview2-shim/types/interfaces/wasi-clocks-wall-clock.d.ts +30 -0
  51. package/node_modules/@bytecodealliance/preview2-shim/types/interfaces/wasi-filesystem-preopens.d.ts +6 -0
  52. package/node_modules/@bytecodealliance/preview2-shim/types/interfaces/wasi-filesystem-types.d.ts +669 -0
  53. package/node_modules/@bytecodealliance/preview2-shim/types/interfaces/wasi-http-incoming-handler.d.ts +16 -0
  54. package/node_modules/@bytecodealliance/preview2-shim/types/interfaces/wasi-http-outgoing-handler.d.ts +18 -0
  55. package/node_modules/@bytecodealliance/preview2-shim/types/interfaces/wasi-http-types.d.ts +748 -0
  56. package/node_modules/@bytecodealliance/preview2-shim/types/interfaces/wasi-io-error.d.ts +18 -0
  57. package/node_modules/@bytecodealliance/preview2-shim/types/interfaces/wasi-io-poll.d.ts +44 -0
  58. package/node_modules/@bytecodealliance/preview2-shim/types/interfaces/wasi-io-streams.d.ts +243 -0
  59. package/node_modules/@bytecodealliance/preview2-shim/types/interfaces/wasi-random-insecure-seed.d.ts +21 -0
  60. package/node_modules/@bytecodealliance/preview2-shim/types/interfaces/wasi-random-insecure.d.ts +19 -0
  61. package/node_modules/@bytecodealliance/preview2-shim/types/interfaces/wasi-random-random.d.ts +23 -0
  62. package/node_modules/@bytecodealliance/preview2-shim/types/interfaces/wasi-sockets-instance-network.d.ts +6 -0
  63. package/node_modules/@bytecodealliance/preview2-shim/types/interfaces/wasi-sockets-ip-name-lookup.d.ts +58 -0
  64. package/node_modules/@bytecodealliance/preview2-shim/types/interfaces/wasi-sockets-network.d.ts +164 -0
  65. package/node_modules/@bytecodealliance/preview2-shim/types/interfaces/wasi-sockets-tcp-create-socket.d.ts +28 -0
  66. package/node_modules/@bytecodealliance/preview2-shim/types/interfaces/wasi-sockets-tcp.d.ts +359 -0
  67. package/node_modules/@bytecodealliance/preview2-shim/types/interfaces/wasi-sockets-udp-create-socket.d.ts +28 -0
  68. package/node_modules/@bytecodealliance/preview2-shim/types/interfaces/wasi-sockets-udp.d.ts +301 -0
  69. package/node_modules/@bytecodealliance/preview2-shim/types/io.d.ts +3 -0
  70. package/node_modules/@bytecodealliance/preview2-shim/types/random.d.ts +3 -0
  71. package/node_modules/@bytecodealliance/preview2-shim/types/sockets.d.ts +7 -0
  72. package/node_modules/@bytecodealliance/preview2-shim/types/wasi-cli-command.d.ts +29 -0
  73. package/node_modules/@bytecodealliance/preview2-shim/types/wasi-http-proxy.d.ts +13 -0
  74. package/package.json +9 -6
  75. package/patches/@bytecodealliance+preview2-shim+0.18.0.patch +13 -0
@@ -0,0 +1,127 @@
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
+
37
+ function extractProperties(object) {
38
+ if (object && typeof object === "object") {
39
+ const properties = {};
40
+ for (const key in object) {
41
+ properties[key] = object[key];
42
+ }
43
+ return properties;
44
+ }
45
+ }
46
+
47
+ const CALL_TIMEOUT = undefined;
48
+
49
+ export function createSyncFn(workerPath, debug, callbackHandler) {
50
+ if (!path.isAbsolute(workerPath)) {
51
+ throw new Error("`workerPath` must be absolute");
52
+ }
53
+ const { port1: mainPort, port2: workerPort } = new MessageChannel();
54
+ const worker = new Worker(workerPath, {
55
+ workerData: { workerPort, debug },
56
+ transferList: [workerPort],
57
+ execArgv: [],
58
+ });
59
+ worker.on("message", ({ type, id, payload }) => {
60
+ if (!type) {
61
+ throw new Error("Internal error: Expected a type of a worker callback");
62
+ }
63
+ callbackHandler(type, id, payload);
64
+ });
65
+ let nextID = 0;
66
+ const syncFn = (...args) => {
67
+ const cid = nextID++;
68
+ const sharedBuffer = new SharedArrayBuffer(DEFAULT_WORKER_BUFFER_SIZE);
69
+ const sharedBufferView = new Int32Array(sharedBuffer);
70
+ const msg = { sharedBuffer, cid, args };
71
+ worker.postMessage(msg);
72
+ const status = Atomics.wait(sharedBufferView, 0, 0, CALL_TIMEOUT);
73
+ if (!["ok", "not-equal"].includes(status)) {
74
+ throw new Error("Internal error: Atomics.wait() failed: " + status);
75
+ }
76
+ const { cid: cid2, result, error, properties } = receiveMessageOnPort(mainPort).message;
77
+ if (cid !== cid2) {
78
+ throw new Error(`Internal error: Expected id ${cid} but got id ${cid2}`);
79
+ }
80
+ if (error) {
81
+ if (error instanceof Error) {
82
+ throw Object.assign(error, properties);
83
+ }
84
+ throw error;
85
+ }
86
+ return result;
87
+ };
88
+ if (worker.unref) {
89
+ worker.unref();
90
+ }
91
+ return syncFn;
92
+ }
93
+
94
+ export function runAsWorker(fn) {
95
+ if (!workerData) {
96
+ return;
97
+ }
98
+ const { workerPort, debug } = workerData;
99
+ try {
100
+ parentPort.on("message", ({ sharedBuffer, cid, args }) => {
101
+ (async () => {
102
+ const sharedBufferView = new Int32Array(sharedBuffer);
103
+ let msg;
104
+ try {
105
+ msg = { cid, result: await fn(...args) };
106
+ } catch (error) {
107
+ msg = { cid, error, properties: extractProperties(error) };
108
+ }
109
+ workerPort.postMessage(msg);
110
+ Atomics.add(sharedBufferView, 0, 1);
111
+ Atomics.notify(sharedBufferView, 0);
112
+ })();
113
+ });
114
+ } catch (error) {
115
+ parentPort.on("message", ({ sharedBuffer, cid }) => {
116
+ const sharedBufferView = new Int32Array(sharedBuffer);
117
+ workerPort.postMessage({
118
+ cid,
119
+ error,
120
+ properties: extractProperties(error),
121
+ });
122
+ Atomics.add(sharedBufferView, 0, 1);
123
+ Atomics.notify(sharedBufferView, 0);
124
+ });
125
+ }
126
+ return debug;
127
+ }
@@ -0,0 +1,65 @@
1
+ {
2
+ "name": "@bytecodealliance/preview2-shim",
3
+ "version": "0.18.0",
4
+ "description": "WASI Preview2 shim for JS environments",
5
+ "homepage": "https://github.com/bytecodealliance/jco#readme",
6
+ "bugs": {
7
+ "url": "https://github.com/bytecodealliance/jco/issues"
8
+ },
9
+ "license": "(Apache-2.0 WITH LLVM-exception)",
10
+ "author": "Guy Bedford, Eduardo Rodrigues<16357187+eduardomourar@users.noreply.github.com>",
11
+ "contributors": [
12
+ {
13
+ "name": "Guy Bedford"
14
+ },
15
+ {
16
+ "name": "Eduardo Rodrigues",
17
+ "email": "16357187+eduardomourar@users.noreply.github.com"
18
+ },
19
+ {
20
+ "name": "Victor Adossi",
21
+ "email": "vadossi@cosmonic.com"
22
+ }
23
+ ],
24
+ "repository": {
25
+ "type": "git",
26
+ "url": "git+https://github.com/bytecodealliance/jco.git"
27
+ },
28
+ "files": [
29
+ "types",
30
+ "lib"
31
+ ],
32
+ "type": "module",
33
+ "types": "./types/index.d.ts",
34
+ "exports": {
35
+ ".": {
36
+ "types": "./types/index.d.ts",
37
+ "node": "./lib/nodejs/index.js",
38
+ "default": "./lib/browser/index.js"
39
+ },
40
+ "./*": {
41
+ "types": "./types/*.d.ts",
42
+ "node": "./lib/nodejs/*.js",
43
+ "default": "./lib/browser/*.js"
44
+ },
45
+ "./instantiation": {
46
+ "types": "./types/instantiation.d.ts",
47
+ "node": "./lib/common/instantiation.js",
48
+ "default": "./lib/common/instantiation.js"
49
+ }
50
+ },
51
+ "devDependencies": {
52
+ "@bytecodealliance/componentize-js": "0.21.0",
53
+ "@bytecodealliance/jco": "1.15.2",
54
+ "mime": "^4.0.7",
55
+ "puppeteer": "^24.43.1"
56
+ },
57
+ "scripts": {
58
+ "types:check": "tsc --noEmit",
59
+ "fmt": "oxfmt",
60
+ "fmt:check": "oxfmt --check",
61
+ "lint": "oxlint",
62
+ "lint:fix": "oxlint --fix",
63
+ "test": "vitest run -c test/vitest.ts"
64
+ }
65
+ }
@@ -0,0 +1,11 @@
1
+ export type * as environment from './interfaces/wasi-cli-environment.d.ts';
2
+ export type * as exit from './interfaces/wasi-cli-exit.d.ts';
3
+ export type * as run from './interfaces/wasi-cli-run.d.ts';
4
+ export type * as stderr from './interfaces/wasi-cli-stderr.d.ts';
5
+ export type * as stdin from './interfaces/wasi-cli-stdin.d.ts';
6
+ export type * as stdout from './interfaces/wasi-cli-stdout.d.ts';
7
+ export type * as terminalInput from './interfaces/wasi-cli-terminal-input.d.ts';
8
+ export type * as terminalOutput from './interfaces/wasi-cli-terminal-output.d.ts';
9
+ export type * as terminalStderr from './interfaces/wasi-cli-terminal-stderr.d.ts';
10
+ export type * as terminalStdin from './interfaces/wasi-cli-terminal-stdin.d.ts';
11
+ export type * as terminalStdout from './interfaces/wasi-cli-terminal-stdout.d.ts';
@@ -0,0 +1,2 @@
1
+ export type * as monotonicClock from './interfaces/wasi-clocks-monotonic-clock.d.ts';
2
+ export type * as wallClock from './interfaces/wasi-clocks-wall-clock.d.ts';
@@ -0,0 +1,29 @@
1
+ export type * as preopens from './interfaces/wasi-filesystem-preopens.d.ts';
2
+ export type * as types from './interfaces/wasi-filesystem-types.d.ts';
3
+
4
+ import type { Descriptor } from './interfaces/wasi-filesystem-types.d.ts';
5
+
6
+ /**
7
+ * Replace all preopens with the given set.
8
+ * @param preopens - Map of virtual paths to host paths
9
+ */
10
+ export function _setPreopens(preopens: Record<string, string>): void;
11
+
12
+ /**
13
+ * Add a single preopen mapping.
14
+ * @param virtualPath - The virtual path visible to the guest
15
+ * @param hostPreopen - The host filesystem path
16
+ */
17
+ export function _addPreopen(virtualPath: string, hostPreopen: string): void;
18
+
19
+ /**
20
+ * Clear all preopens, giving the guest no filesystem access.
21
+ * Call this immediately after import to disable default full filesystem access.
22
+ */
23
+ export function _clearPreopens(): void;
24
+
25
+ /**
26
+ * Get current preopens configuration.
27
+ * @returns Array of [descriptor, virtualPath] pairs
28
+ */
29
+ export function _getPreopens(): Array<[Descriptor, string]>;
@@ -0,0 +1,3 @@
1
+ export type * as incomingHandler from './interfaces/wasi-http-incoming-handler.d.ts';
2
+ export type * as outgoingHandler from './interfaces/wasi-http-outgoing-handler.d.ts';
3
+ export type * as types from './interfaces/wasi-http-types.d.ts';
@@ -0,0 +1,6 @@
1
+ export type * as cli from "./cli.d.ts";
2
+ export type * as clocks from './clocks.d.ts';
3
+ export type * as filesystem from './filesystem.d.ts';
4
+ export type * as http from "./http.d.ts";
5
+ export type * as random from "./random.d.ts";
6
+ export type * as sockets from "./sockets.d.ts";
@@ -0,0 +1,199 @@
1
+ /**
2
+ * Type alias that represents the kind of imports that the average
3
+ * transpiled Jco component will require.
4
+ *
5
+ * For example, `wasi:http/types` and `wasi:http/outgoing-handler` are present due to
6
+ * the ability for a component to call `fetch()` at any point in time.
7
+ *
8
+ * While the feature can be disabled when building with `jco componentize` or `componentize-js`,
9
+ * by default it is enabled, and as such included here (practically, the implementations can be no-ops).
10
+ */
11
+ type _WASIImportObject = {
12
+ 'wasi:cli/environment': typeof import('./interfaces/wasi-cli-environment.d.ts');
13
+ 'wasi:cli/exit': typeof import('./interfaces/wasi-cli-exit.d.ts');
14
+ 'wasi:cli/stderr': typeof import('./interfaces/wasi-cli-stderr.d.ts');
15
+ 'wasi:cli/stdin': typeof import('./interfaces/wasi-cli-stdin.d.ts');
16
+ 'wasi:cli/stdout': typeof import('./interfaces/wasi-cli-stdout.d.ts');
17
+ 'wasi:cli/terminal-input': typeof import('./interfaces/wasi-cli-terminal-input.d.ts');
18
+ 'wasi:cli/terminal-output': typeof import('./interfaces/wasi-cli-terminal-output.d.ts');
19
+ 'wasi:cli/terminal-stderr': typeof import('./interfaces/wasi-cli-terminal-stderr.d.ts');
20
+ 'wasi:cli/terminal-stdin': typeof import('./interfaces/wasi-cli-terminal-stdin.d.ts');
21
+ 'wasi:cli/terminal-stdout': typeof import('./interfaces/wasi-cli-terminal-stdout.d.ts');
22
+
23
+ 'wasi:sockets/instance-network': typeof import('./interfaces/wasi-sockets-instance-network.d.ts');
24
+ 'wasi:sockets/ip-name-lookup': typeof import('./interfaces/wasi-sockets-ip-name-lookup.d.ts');
25
+ 'wasi:sockets/network': typeof import('./interfaces/wasi-sockets-network.d.ts');
26
+ 'wasi:sockets/tcp': typeof import('./interfaces/wasi-sockets-tcp.d.ts');
27
+ 'wasi:sockets/tcp-create-socket': typeof import('./interfaces/wasi-sockets-tcp-create-socket.d.ts');
28
+ 'wasi:sockets/udp': typeof import('./interfaces/wasi-sockets-udp.d.ts');
29
+ 'wasi:sockets/udp-create-socket': typeof import('./interfaces/wasi-sockets-udp-create-socket.d.ts');
30
+
31
+ 'wasi:filesystem/preopens': typeof import('./interfaces/wasi-filesystem-preopens.d.ts');
32
+ 'wasi:filesystem/types': typeof import('./interfaces/wasi-filesystem-types.d.ts');
33
+
34
+ 'wasi:io/error': typeof import('./interfaces/wasi-io-error.d.ts');
35
+ 'wasi:io/poll': typeof import('./interfaces/wasi-io-poll.d.ts');
36
+ 'wasi:io/streams': typeof import('./interfaces/wasi-io-streams.d.ts');
37
+
38
+ 'wasi:random/random': typeof import('./interfaces/wasi-random-random.d.ts');
39
+ 'wasi:random/insecure': typeof import('./interfaces/wasi-random-insecure.d.ts');
40
+ 'wasi:random/insecure-seed': typeof import('./interfaces/wasi-random-insecure-seed.d.ts');
41
+
42
+ 'wasi:clocks/monotonic-clock': typeof import('./interfaces/wasi-clocks-monotonic-clock.d.ts');
43
+ 'wasi:clocks/wall-clock': typeof import('./interfaces/wasi-clocks-wall-clock.d.ts');
44
+
45
+ 'wasi:http/types': typeof import('./interfaces/wasi-http-types.d.ts');
46
+ 'wasi:http/outgoing-handler': typeof import('./interfaces/wasi-http-outgoing-handler.d.ts');
47
+ };
48
+
49
+ type WASIImportObject = VersionedWASIImportObject<''>;
50
+
51
+ type VersionedWASIImportObject<V extends string> = {
52
+ [K in keyof _WASIImportObject as AppendVersion<K, V>]: _WASIImportObject[K];
53
+ };
54
+
55
+ /** Used to append versions to generated WASI import objects */
56
+ type AppendVersion<
57
+ Key extends string | number | symbol,
58
+ Version extends string,
59
+ > = Version extends `${infer V}`
60
+ ? Key extends `${infer K}`
61
+ ? Key extends ''
62
+ ? `${K}`
63
+ : `${K}@${V}`
64
+ : never
65
+ : never;
66
+
67
+ /**
68
+ * Sandbox configuration options for WASIShim
69
+ */
70
+ interface SandboxConfig {
71
+ /** Filesystem preopens mapping (virtual path -> host path) */
72
+ preopens?: Record<string, string>;
73
+ /** Environment variables visible to the guest */
74
+ env?: Record<string, string>;
75
+ /** Command-line arguments */
76
+ args?: string[];
77
+ /** Whether to enable network access (sockets, HTTP). Default: true */
78
+ enableNetwork?: boolean;
79
+ }
80
+
81
+ /**
82
+ * Configuration options for WASIShim
83
+ */
84
+ interface WASIShimConfig {
85
+ /** Custom CLI shim */
86
+ cli?: object;
87
+ /** Custom filesystem shim */
88
+ filesystem?: object;
89
+ /** Custom I/O shim */
90
+ io?: object;
91
+ /** Custom random shim */
92
+ random?: object;
93
+ /** Custom clocks shim */
94
+ clocks?: object;
95
+ /** Custom sockets shim */
96
+ sockets?: object;
97
+ /** Custom HTTP shim */
98
+ http?: object;
99
+ /** Sandbox configuration for restricting guest capabilities */
100
+ sandbox?: SandboxConfig;
101
+ }
102
+
103
+ /**
104
+ * (EXPERIMENTAL) A class that holds WASI shims and can be used to configure
105
+ * an instantiation of a WebAssembly component transpiled with jco
106
+ * (i.e. via `jco transpile`).
107
+ *
108
+ * Normally, transpiled components contain mapping for WASI interfaces
109
+ * and/or imports that import the relevant packages (ex. `@bytecodealliance/preview2-shim/clocks`)
110
+ * from the right sources.
111
+ *
112
+ * This function makes use of the `WASIShim` object to provide an object that can be easily
113
+ * fed to the `instantiate` function produced by a transpiled component:
114
+ *
115
+ * ```js
116
+ * import { WASIShim } from "@bytecodealliance/preview2-shim/instantiation"
117
+ * // ...
118
+ * import { instantiate } from "path/to/transpiled/component.js"
119
+ * // ...
120
+ * const component = await instantiate(null, new WASIShim().getImportObject())
121
+ * ```
122
+ *
123
+ * You can also replace imports that you'd like to override with custom implementations,
124
+ * by using the `WASIShim` object directly:
125
+ *
126
+ * ```js
127
+ * import { random } from "@bytecodealliance/preview2-shim"
128
+ * import { WASIShim } from "@bytecodealliance/preview2-shim/instantiation"
129
+ * // ...
130
+ * import { instantiate } from "path/to/transpiled/component.js"
131
+ * // ...
132
+ * const customWASIShim = new WASIShim({
133
+ * random: {
134
+ * // For these two interfaces we re-use the default provided shim
135
+ * random: random.random,
136
+ * insecure-seed: random.insecureSeed,
137
+ * // For insecure, we can supply our own custom implementation
138
+ * insecure: {
139
+ * ...
140
+ * }
141
+ * }
142
+ * });
143
+ *
144
+ * const component = await instantiate(null, customWASIShim.getImportObject())
145
+ * ```
146
+ *
147
+ * For sandboxing, you can configure preopens, environment variables, and other
148
+ * capabilities via the `sandbox` option:
149
+ *
150
+ * ```js
151
+ * import { WASIShim } from "@bytecodealliance/preview2-shim/instantiation"
152
+ *
153
+ * // Fully sandboxed - no filesystem, network, or env access
154
+ * const sandboxedShim = new WASIShim({
155
+ * sandbox: {
156
+ * preopens: {}, // No filesystem access
157
+ * env: {}, // No environment variables
158
+ * args: ['program'], // Custom arguments
159
+ * enableNetwork: false, // Disable network
160
+ * }
161
+ * });
162
+ *
163
+ * // Limited filesystem access
164
+ * const limitedShim = new WASIShim({
165
+ * sandbox: {
166
+ * preopens: {
167
+ * '/data': '/tmp/guest-data', // Guest sees /data, maps to /tmp/guest-data
168
+ * '/config': '/etc/app' // Guest sees /config, maps to /etc/app
169
+ * }
170
+ * }
171
+ * });
172
+ * ```
173
+ *
174
+ * Note that this object is similar but not identical to the Node `WASI` object --
175
+ * it is solely concerned with shimming of preview2 when dealing with a WebAssembly
176
+ * component transpiled by Jco. While this object *does* work with Node (and the browser)
177
+ * semantics are not the same as Node's `WASI` object.
178
+ *
179
+ * @class WASIShim
180
+ */
181
+ export class WASIShim {
182
+ constructor(config?: WASIShimConfig);
183
+
184
+ /**
185
+ * Generate an import object for the shim that can be used with
186
+ * functions like `instantiate` that are exposed from a transpiled
187
+ * WebAssembly component.
188
+ *
189
+ * @param {options} [opt]
190
+ * @returns {object}
191
+ */
192
+ getImportObject<V extends string = ''>(
193
+ opts?: GetImportObjectArgs
194
+ ): VersionedWASIImportObject<V>;
195
+ }
196
+
197
+ interface GetImportObjectArgs {
198
+ asVersion?: string;
199
+ }
@@ -0,0 +1,21 @@
1
+ /** @module Interface wasi:cli/environment@0.2.3 **/
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(): Array<[string, string]>;
13
+ /**
14
+ * Get the POSIX-style arguments to the program.
15
+ */
16
+ export function getArguments(): Array<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 | undefined;
@@ -0,0 +1,6 @@
1
+ /** @module Interface wasi:cli/exit@0.2.3 **/
2
+ /**
3
+ * Exit the current instance and any linked instances.
4
+ */
5
+ export function exit(status: Result<void, void>): void;
6
+ export type Result<T, E> = { tag: 'ok', val: T } | { tag: 'err', val: E };
@@ -0,0 +1,5 @@
1
+ /** @module Interface wasi:cli/run@0.2.3 **/
2
+ /**
3
+ * Run the program.
4
+ */
5
+ export function run(): void;
@@ -0,0 +1,3 @@
1
+ /** @module Interface wasi:cli/stderr@0.2.3 **/
2
+ export function getStderr(): OutputStream;
3
+ export type OutputStream = import('./wasi-io-streams.js').OutputStream;
@@ -0,0 +1,3 @@
1
+ /** @module Interface wasi:cli/stdin@0.2.3 **/
2
+ export function getStdin(): InputStream;
3
+ export type InputStream = import('./wasi-io-streams.js').InputStream;
@@ -0,0 +1,3 @@
1
+ /** @module Interface wasi:cli/stdout@0.2.3 **/
2
+ export function getStdout(): OutputStream;
3
+ export type OutputStream = import('./wasi-io-streams.js').OutputStream;
@@ -0,0 +1,8 @@
1
+ /** @module Interface wasi:cli/terminal-input@0.2.3 **/
2
+
3
+ export class TerminalInput {
4
+ /**
5
+ * This type does not have a public constructor.
6
+ */
7
+ private constructor();
8
+ }
@@ -0,0 +1,8 @@
1
+ /** @module Interface wasi:cli/terminal-output@0.2.3 **/
2
+
3
+ export class TerminalOutput {
4
+ /**
5
+ * This type does not have a public constructor.
6
+ */
7
+ private constructor();
8
+ }
@@ -0,0 +1,7 @@
1
+ /** @module Interface wasi:cli/terminal-stderr@0.2.3 **/
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 | undefined;
7
+ export type TerminalOutput = import('./wasi-cli-terminal-output.js').TerminalOutput;
@@ -0,0 +1,7 @@
1
+ /** @module Interface wasi:cli/terminal-stdin@0.2.3 **/
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 | undefined;
7
+ export type TerminalInput = import('./wasi-cli-terminal-input.js').TerminalInput;
@@ -0,0 +1,7 @@
1
+ /** @module Interface wasi:cli/terminal-stdout@0.2.3 **/
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 | undefined;
7
+ export type TerminalOutput = import('./wasi-cli-terminal-output.js').TerminalOutput;
@@ -0,0 +1,34 @@
1
+ /** @module Interface wasi:clocks/monotonic-clock@0.2.3 **/
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. Returns the duration of time
11
+ * corresponding to a clock tick.
12
+ */
13
+ export function resolution(): Duration;
14
+ /**
15
+ * Create a `pollable` which will resolve once the specified instant
16
+ * has occurred.
17
+ */
18
+ export function subscribeInstant(when: Instant): Pollable;
19
+ /**
20
+ * Create a `pollable` that will resolve after the specified duration has
21
+ * elapsed from the time this function is invoked.
22
+ */
23
+ export function subscribeDuration(when: Duration): Pollable;
24
+ export type Pollable = import('./wasi-io-poll.js').Pollable;
25
+ /**
26
+ * An instant in time, in nanoseconds. An instant is relative to an
27
+ * unspecified initial value, and can only be compared to instances from
28
+ * the same monotonic-clock.
29
+ */
30
+ export type Instant = bigint;
31
+ /**
32
+ * A duration of time, in nanoseconds.
33
+ */
34
+ export type Duration = bigint;
@@ -0,0 +1,30 @@
1
+ /** @module Interface wasi:clocks/wall-clock@0.2.3 **/
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
+ * A time and date in seconds plus nanoseconds.
26
+ */
27
+ export interface Datetime {
28
+ seconds: bigint,
29
+ nanoseconds: number,
30
+ }
@@ -0,0 +1,6 @@
1
+ /** @module Interface wasi:filesystem/preopens@0.2.3 **/
2
+ /**
3
+ * Return the set of preopened directories, and their paths.
4
+ */
5
+ export function getDirectories(): Array<[Descriptor, string]>;
6
+ export type Descriptor = import('./wasi-filesystem-types.js').Descriptor;