nuxt-ai-ready 2.5.0 → 2.5.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.
- package/dist/chunks/agent-skills.mjs +1 -1
- package/dist/chunks/prerender.mjs +1 -1
- package/dist/cli.mjs +2 -0
- package/dist/module.json +1 -1
- package/dist/module.mjs +1 -1
- package/dist/runtime/server/db/drizzle/queries.js +0 -1
- package/dist/runtime/server/db/queries.d.ts +2 -0
- package/dist/runtime/server/db/queries.js +11 -5
- package/dist/runtime/server/db/seed.d.ts +2 -2
- package/dist/runtime/server/routes/__ai-ready/reindex.post.js +2 -0
- package/dist/runtime/server/utils/batchIndex.js +4 -2
- package/dist/runtime/server/utils/checkStale.d.ts +1 -1
- package/dist/runtime/server/utils/checkStale.js +1 -1
- package/dist/runtime/server/utils/indexPage.d.ts +8 -1
- package/dist/runtime/server/utils/indexPage.js +13 -5
- package/dist/shared/{nuxt-ai-ready.DsokNmXc.mjs → nuxt-ai-ready.CLSWou20.mjs} +2 -0
- package/node_modules/@mdream/js/LICENSE.md +9 -0
- package/node_modules/@mdream/js/README.md +792 -0
- package/node_modules/@mdream/js/bin/mdream.mjs +2 -0
- package/node_modules/@mdream/js/dist/_chunks/const.mjs +134 -0
- package/node_modules/@mdream/js/dist/_chunks/index.d.mts +9 -0
- package/node_modules/@mdream/js/dist/_chunks/markdown-processor.mjs +1968 -0
- package/node_modules/@mdream/js/dist/_chunks/minimal.d.mts +6 -0
- package/node_modules/@mdream/js/dist/_chunks/parse.mjs +2756 -0
- package/node_modules/@mdream/js/dist/_chunks/plugins.mjs +725 -0
- package/node_modules/@mdream/js/dist/_chunks/resolve-plugins.mjs +44 -0
- package/node_modules/@mdream/js/dist/_chunks/stream.mjs +37 -0
- package/node_modules/@mdream/js/dist/_chunks/types.d.mts +473 -0
- package/node_modules/@mdream/js/dist/cli.d.mts +1 -0
- package/node_modules/@mdream/js/dist/cli.mjs +32 -0
- package/node_modules/@mdream/js/dist/core.d.mts +15 -0
- package/node_modules/@mdream/js/dist/core.mjs +28 -0
- package/node_modules/@mdream/js/dist/index.d.mts +4 -0
- package/node_modules/@mdream/js/dist/index.mjs +58 -0
- package/node_modules/@mdream/js/dist/llms-txt.d.mts +86 -0
- package/node_modules/@mdream/js/dist/llms-txt.mjs +308 -0
- package/node_modules/@mdream/js/dist/negotiate.d.mts +35 -0
- package/node_modules/@mdream/js/dist/negotiate.mjs +121 -0
- package/node_modules/@mdream/js/dist/parse.d.mts +90 -0
- package/node_modules/@mdream/js/dist/parse.mjs +2 -0
- package/node_modules/@mdream/js/dist/plugins.d.mts +85 -0
- package/node_modules/@mdream/js/dist/plugins.mjs +2 -0
- package/node_modules/@mdream/js/dist/preset/minimal.d.mts +2 -0
- package/node_modules/@mdream/js/dist/preset/minimal.mjs +33 -0
- package/node_modules/@mdream/js/dist/splitter.d.mts +18 -0
- package/node_modules/@mdream/js/dist/splitter.mjs +194 -0
- package/node_modules/@mdream/js/package.json +103 -0
- package/node_modules/cac/LICENSE +21 -0
- package/node_modules/cac/README.md +492 -0
- package/node_modules/cac/dist/index.d.ts +196 -0
- package/node_modules/cac/dist/index.js +638 -0
- package/node_modules/cac/package.json +72 -0
- package/node_modules/mdream/LICENSE.md +9 -0
- package/node_modules/mdream/README.md +1091 -0
- package/node_modules/mdream/bin/mdream.mjs +46 -0
- package/node_modules/mdream/dist/browser.d.mts +105 -0
- package/node_modules/mdream/dist/browser.mjs +262 -0
- package/node_modules/mdream/dist/edge.d.mts +100 -0
- package/node_modules/mdream/dist/edge.mjs +250 -0
- package/node_modules/mdream/dist/iife.js +605 -0
- package/node_modules/mdream/dist/index.d.mts +89 -0
- package/node_modules/mdream/dist/index.mjs +184 -0
- package/node_modules/mdream/dist/wasm.d.mts +100 -0
- package/node_modules/mdream/dist/wasm.mjs +140 -0
- package/node_modules/mdream/dist/worker.d.mts +101 -0
- package/node_modules/mdream/dist/worker.mjs +217 -0
- package/node_modules/mdream/napi/index.d.mts +127 -0
- package/node_modules/mdream/napi/index.d.ts +127 -0
- package/node_modules/mdream/napi/index.mjs +725 -0
- package/node_modules/mdream/napi/rust.android-arm-eabi.node +0 -0
- package/node_modules/mdream/napi/rust.android-arm64.node +0 -0
- package/node_modules/mdream/napi/rust.darwin-arm64.node +0 -0
- package/node_modules/mdream/napi/rust.darwin-x64.node +0 -0
- package/node_modules/mdream/napi/rust.freebsd-x64.node +0 -0
- package/node_modules/mdream/napi/rust.linux-arm-gnueabihf.node +0 -0
- package/node_modules/mdream/napi/rust.linux-arm64-gnu.node +0 -0
- package/node_modules/mdream/napi/rust.linux-arm64-musl.node +0 -0
- package/node_modules/mdream/napi/rust.linux-x64-gnu.node +0 -0
- package/node_modules/mdream/napi/rust.linux-x64-musl.node +0 -0
- package/node_modules/mdream/napi/rust.wasi.cjs +2144 -0
- package/node_modules/mdream/napi/rust.wasm32-wasi.wasm +0 -0
- package/node_modules/mdream/napi/rust.win32-arm64-msvc.node +0 -0
- package/node_modules/mdream/napi/rust.win32-x64-msvc.node +0 -0
- package/node_modules/mdream/node_modules/@emnapi/core/LICENSE +21 -0
- package/node_modules/mdream/node_modules/@emnapi/core/README.md +1 -0
- package/node_modules/mdream/node_modules/@emnapi/core/dist/emnapi-core.d.ts +392 -0
- package/node_modules/mdream/node_modules/@emnapi/core/dist/emnapi-core.full.d.ts +392 -0
- package/node_modules/mdream/node_modules/@emnapi/core/dist/emnapi-core.full.js +8351 -0
- package/node_modules/mdream/node_modules/@emnapi/core/dist/emnapi-core.js +7268 -0
- package/node_modules/mdream/node_modules/@emnapi/core/dist/plugins/async-work.d.ts +5 -0
- package/node_modules/mdream/node_modules/@emnapi/core/dist/plugins/async-work.js +843 -0
- package/node_modules/mdream/node_modules/@emnapi/core/dist/plugins/index.d.ts +4 -0
- package/node_modules/mdream/node_modules/@emnapi/core/dist/plugins/index.js +3 -0
- package/node_modules/mdream/node_modules/@emnapi/core/dist/plugins/threadsafe-function.d.ts +5 -0
- package/node_modules/mdream/node_modules/@emnapi/core/dist/plugins/threadsafe-function.js +1010 -0
- package/node_modules/mdream/node_modules/@emnapi/core/dist/plugins/v8.d.ts +5 -0
- package/node_modules/mdream/node_modules/@emnapi/core/dist/plugins/v8.js +1446 -0
- package/node_modules/mdream/node_modules/@emnapi/core/package.json +39 -0
- package/node_modules/mdream/node_modules/@emnapi/core/rollup.config.js +60 -0
- package/node_modules/mdream/node_modules/@emnapi/runtime/LICENSE +21 -0
- package/node_modules/mdream/node_modules/@emnapi/runtime/README.md +1 -0
- package/node_modules/mdream/node_modules/@emnapi/runtime/dist/emnapi.d.ts +833 -0
- package/node_modules/mdream/node_modules/@emnapi/runtime/dist/emnapi.js +2306 -0
- package/node_modules/mdream/node_modules/@emnapi/runtime/dist/emnapi.js.map +1 -0
- package/node_modules/mdream/node_modules/@emnapi/runtime/index.cjs +63 -0
- package/node_modules/mdream/node_modules/@emnapi/runtime/package.json +39 -0
- package/node_modules/mdream/node_modules/@emnapi/runtime/rollup.config.js +25 -0
- package/node_modules/mdream/node_modules/@emnapi/wasi-threads/LICENSE +21 -0
- package/node_modules/mdream/node_modules/@emnapi/wasi-threads/README.md +203 -0
- package/node_modules/mdream/node_modules/@emnapi/wasi-threads/dist/wasi-threads.d.ts +236 -0
- package/node_modules/mdream/node_modules/@emnapi/wasi-threads/dist/wasi-threads.js +1086 -0
- package/node_modules/mdream/node_modules/@emnapi/wasi-threads/package.json +35 -0
- package/node_modules/mdream/node_modules/@emnapi/wasi-threads/rollup.config.js +6 -0
- package/node_modules/mdream/node_modules/@napi-rs/wasm-runtime/dist/emnapi-plugins.cjs +1472 -0
- package/node_modules/mdream/node_modules/@napi-rs/wasm-runtime/dist/emnapi-plugins.js +1470 -0
- package/node_modules/mdream/node_modules/@napi-rs/wasm-runtime/dist/fs-proxy.cjs +237 -0
- package/node_modules/mdream/node_modules/@napi-rs/wasm-runtime/dist/fs.js +18260 -0
- package/node_modules/mdream/node_modules/@napi-rs/wasm-runtime/fs-proxy.js +317 -0
- package/node_modules/mdream/node_modules/@napi-rs/wasm-runtime/package.json +67 -0
- package/node_modules/mdream/node_modules/@napi-rs/wasm-runtime/runtime.cjs +39 -0
- package/node_modules/mdream/node_modules/@napi-rs/wasm-runtime/runtime.js +36 -0
- package/node_modules/mdream/node_modules/@tybys/wasm-util/LICENSE +21 -0
- package/node_modules/mdream/node_modules/@tybys/wasm-util/README.md +193 -0
- package/node_modules/mdream/node_modules/@tybys/wasm-util/dist/tsdoc-metadata.json +11 -0
- package/node_modules/mdream/node_modules/@tybys/wasm-util/dist/wasm-util.d.ts +423 -0
- package/node_modules/mdream/node_modules/@tybys/wasm-util/dist/wasm-util.esm-bundler.js +2932 -0
- package/node_modules/mdream/node_modules/@tybys/wasm-util/dist/wasm-util.esm.js +2932 -0
- package/node_modules/mdream/node_modules/@tybys/wasm-util/dist/wasm-util.esm.min.js +1 -0
- package/node_modules/mdream/node_modules/@tybys/wasm-util/dist/wasm-util.js +2954 -0
- package/node_modules/mdream/node_modules/@tybys/wasm-util/dist/wasm-util.min.js +1 -0
- package/node_modules/mdream/node_modules/@tybys/wasm-util/lib/cjs/asyncify.js +158 -0
- package/node_modules/mdream/node_modules/@tybys/wasm-util/lib/cjs/index.js +13 -0
- package/node_modules/mdream/node_modules/@tybys/wasm-util/lib/cjs/jspi.js +46 -0
- package/node_modules/mdream/node_modules/@tybys/wasm-util/lib/cjs/load.js +97 -0
- package/node_modules/mdream/node_modules/@tybys/wasm-util/lib/cjs/memory.js +35 -0
- package/node_modules/mdream/node_modules/@tybys/wasm-util/lib/cjs/wasi/error.js +103 -0
- package/node_modules/mdream/node_modules/@tybys/wasm-util/lib/cjs/wasi/fd.js +268 -0
- package/node_modules/mdream/node_modules/@tybys/wasm-util/lib/cjs/wasi/fs.js +3 -0
- package/node_modules/mdream/node_modules/@tybys/wasm-util/lib/cjs/wasi/index.js +192 -0
- package/node_modules/mdream/node_modules/@tybys/wasm-util/lib/cjs/wasi/path.js +316 -0
- package/node_modules/mdream/node_modules/@tybys/wasm-util/lib/cjs/wasi/preview1.js +1599 -0
- package/node_modules/mdream/node_modules/@tybys/wasm-util/lib/cjs/wasi/rights.js +141 -0
- package/node_modules/mdream/node_modules/@tybys/wasm-util/lib/cjs/wasi/types.js +220 -0
- package/node_modules/mdream/node_modules/@tybys/wasm-util/lib/cjs/wasi/util.js +128 -0
- package/node_modules/mdream/node_modules/@tybys/wasm-util/lib/cjs/webassembly.js +13 -0
- package/node_modules/mdream/node_modules/@tybys/wasm-util/lib/mjs/asyncify.mjs +153 -0
- package/node_modules/mdream/node_modules/@tybys/wasm-util/lib/mjs/index.mjs +9 -0
- package/node_modules/mdream/node_modules/@tybys/wasm-util/lib/mjs/jspi.mjs +39 -0
- package/node_modules/mdream/node_modules/@tybys/wasm-util/lib/mjs/load.mjs +89 -0
- package/node_modules/mdream/node_modules/@tybys/wasm-util/lib/mjs/memory.mjs +28 -0
- package/node_modules/mdream/node_modules/@tybys/wasm-util/lib/mjs/wasi/error.mjs +97 -0
- package/node_modules/mdream/node_modules/@tybys/wasm-util/lib/mjs/wasi/fd.mjs +256 -0
- package/node_modules/mdream/node_modules/@tybys/wasm-util/lib/mjs/wasi/fs.mjs +1 -0
- package/node_modules/mdream/node_modules/@tybys/wasm-util/lib/mjs/wasi/index.mjs +186 -0
- package/node_modules/mdream/node_modules/@tybys/wasm-util/lib/mjs/wasi/path.mjs +310 -0
- package/node_modules/mdream/node_modules/@tybys/wasm-util/lib/mjs/wasi/preview1.mjs +1593 -0
- package/node_modules/mdream/node_modules/@tybys/wasm-util/lib/mjs/wasi/rights.mjs +135 -0
- package/node_modules/mdream/node_modules/@tybys/wasm-util/lib/mjs/wasi/types.mjs +216 -0
- package/node_modules/mdream/node_modules/@tybys/wasm-util/lib/mjs/wasi/util.mjs +113 -0
- package/node_modules/mdream/node_modules/@tybys/wasm-util/lib/mjs/webassembly.mjs +9 -0
- package/node_modules/mdream/node_modules/@tybys/wasm-util/package.json +58 -0
- package/node_modules/mdream/node_modules/tslib/CopyrightNotice.txt +15 -0
- package/node_modules/mdream/node_modules/tslib/LICENSE.txt +12 -0
- package/node_modules/mdream/node_modules/tslib/README.md +164 -0
- package/node_modules/mdream/node_modules/tslib/SECURITY.md +41 -0
- package/node_modules/mdream/node_modules/tslib/modules/index.d.ts +38 -0
- package/node_modules/mdream/node_modules/tslib/modules/index.js +70 -0
- package/node_modules/mdream/node_modules/tslib/modules/package.json +3 -0
- package/node_modules/mdream/node_modules/tslib/package.json +47 -0
- package/node_modules/mdream/node_modules/tslib/tslib.d.ts +460 -0
- package/node_modules/mdream/node_modules/tslib/tslib.es6.html +1 -0
- package/node_modules/mdream/node_modules/tslib/tslib.es6.js +402 -0
- package/node_modules/mdream/node_modules/tslib/tslib.es6.mjs +401 -0
- package/node_modules/mdream/node_modules/tslib/tslib.html +1 -0
- package/node_modules/mdream/node_modules/tslib/tslib.js +484 -0
- package/node_modules/mdream/package.json +110 -0
- package/node_modules/mdream/skills/mdream/SKILL.md +124 -0
- package/node_modules/mdream/skills/mdream/references/runtimes.md +49 -0
- package/node_modules/mdream/wasm/mdream_edge.d.ts +90 -0
- package/node_modules/mdream/wasm/mdream_edge.js +517 -0
- package/node_modules/mdream/wasm/mdream_edge_bg.wasm +0 -0
- package/node_modules/mdream/wasm/mdream_edge_bg.wasm.d.ts +20 -0
- package/node_modules/mdream/wasm/package.json +17 -0
- package/node_modules/mdream/wasm-bundler/mdream_edge.d.ts +45 -0
- package/node_modules/mdream/wasm-bundler/mdream_edge.js +13 -0
- package/node_modules/mdream/wasm-bundler/mdream_edge_bg.js +413 -0
- package/node_modules/mdream/wasm-bundler/mdream_edge_bg.wasm +0 -0
- package/node_modules/mdream/wasm-bundler/mdream_edge_bg.wasm.d.ts +20 -0
- package/node_modules/mdream/wasm-bundler/package.json +19 -0
- package/node_modules/pathe/LICENSE +70 -0
- package/node_modules/pathe/README.md +73 -0
- package/node_modules/pathe/dist/index.cjs +39 -0
- package/node_modules/pathe/dist/index.d.cts +47 -0
- package/node_modules/pathe/dist/index.d.mts +47 -0
- package/node_modules/pathe/dist/index.d.ts +47 -0
- package/node_modules/pathe/dist/index.mjs +19 -0
- package/node_modules/pathe/dist/shared/pathe.BSlhyZSM.cjs +266 -0
- package/node_modules/pathe/dist/shared/pathe.M-eThtNZ.mjs +249 -0
- package/node_modules/pathe/dist/utils.cjs +82 -0
- package/node_modules/pathe/dist/utils.d.cts +32 -0
- package/node_modules/pathe/dist/utils.d.mts +32 -0
- package/node_modules/pathe/dist/utils.d.ts +32 -0
- package/node_modules/pathe/dist/utils.mjs +77 -0
- package/node_modules/pathe/package.json +61 -0
- package/node_modules/pathe/utils.d.ts +1 -0
- package/package.json +8 -64
|
@@ -0,0 +1,237 @@
|
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
+
//#region fs-proxy.js
|
|
3
|
+
/**
|
|
4
|
+
* @param {unknown} value
|
|
5
|
+
*/
|
|
6
|
+
const getType = (value) => {
|
|
7
|
+
if (value === void 0) return 0;
|
|
8
|
+
if (value === null) return 1;
|
|
9
|
+
if (isBuffer(value)) return 10;
|
|
10
|
+
const t = typeof value;
|
|
11
|
+
if (t === "boolean") return 2;
|
|
12
|
+
if (t === "number") return 3;
|
|
13
|
+
if (t === "string") return 4;
|
|
14
|
+
if (t === "object") return 6;
|
|
15
|
+
if (t === "bigint") return 9;
|
|
16
|
+
return -1;
|
|
17
|
+
};
|
|
18
|
+
/**
|
|
19
|
+
* @param {unknown} value
|
|
20
|
+
* @returns {value is Uint8Array}
|
|
21
|
+
*/
|
|
22
|
+
const isBuffer = (value) => {
|
|
23
|
+
const BufferCtor = globalThis.Buffer;
|
|
24
|
+
if (typeof BufferCtor?.isBuffer === "function") return BufferCtor.isBuffer(value);
|
|
25
|
+
return value instanceof Uint8Array && value.constructor?.name === "Buffer";
|
|
26
|
+
};
|
|
27
|
+
const RESPONSE_HEADER_SIZE = 16;
|
|
28
|
+
const RESPONSE_PAYLOAD_SIZE = 10240;
|
|
29
|
+
const RESPONSE_BUFFER_SIZE = 10256;
|
|
30
|
+
/**
|
|
31
|
+
* @param {Int32Array} sab
|
|
32
|
+
* @param {Uint8Array} payload
|
|
33
|
+
*/
|
|
34
|
+
const writeResponsePayload = (sab, payload) => {
|
|
35
|
+
if (payload.length > RESPONSE_PAYLOAD_SIZE) throw new RangeError("payload overflow");
|
|
36
|
+
new Uint8Array(sab.buffer).set(payload, RESPONSE_HEADER_SIZE);
|
|
37
|
+
};
|
|
38
|
+
/**
|
|
39
|
+
* @param {import('memfs').IFs} memfs
|
|
40
|
+
* @param {any} value
|
|
41
|
+
* @param {ReturnType<typeof getType>} type
|
|
42
|
+
* @returns {Uint8Array}
|
|
43
|
+
*/
|
|
44
|
+
const encodeValue = (memfs, value, type) => {
|
|
45
|
+
switch (type) {
|
|
46
|
+
case 0:
|
|
47
|
+
case 1: return /* @__PURE__ */ new Uint8Array(0);
|
|
48
|
+
case 2: {
|
|
49
|
+
const view = /* @__PURE__ */ new Int32Array(1);
|
|
50
|
+
view[0] = value ? 1 : 0;
|
|
51
|
+
return new Uint8Array(view.buffer);
|
|
52
|
+
}
|
|
53
|
+
case 3: {
|
|
54
|
+
const view = /* @__PURE__ */ new Float64Array(1);
|
|
55
|
+
view[0] = value;
|
|
56
|
+
return new Uint8Array(view.buffer);
|
|
57
|
+
}
|
|
58
|
+
case 4: return new TextEncoder().encode(value);
|
|
59
|
+
case 10: return new Uint8Array(value);
|
|
60
|
+
case 6: {
|
|
61
|
+
function storeConstructor(obj, memfs, processed = /* @__PURE__ */ new WeakSet()) {
|
|
62
|
+
if (!obj || typeof obj !== "object") return;
|
|
63
|
+
if (processed.has(obj)) return;
|
|
64
|
+
processed.add(obj);
|
|
65
|
+
const [entry] = Object.entries(memfs).filter(([_key, v]) => v === obj.constructor)[0] ?? [];
|
|
66
|
+
if (entry) Object.defineProperty(obj, "__constructor__", {
|
|
67
|
+
configurable: true,
|
|
68
|
+
writable: true,
|
|
69
|
+
enumerable: true,
|
|
70
|
+
value: entry
|
|
71
|
+
});
|
|
72
|
+
for (const value of Object.values(obj)) storeConstructor(value, memfs, processed);
|
|
73
|
+
}
|
|
74
|
+
storeConstructor(value, memfs);
|
|
75
|
+
const json = JSON.stringify(value, (_, value) => {
|
|
76
|
+
if (typeof value === "bigint") return `BigInt(${String(value)})`;
|
|
77
|
+
if (value instanceof Error) return {
|
|
78
|
+
...value,
|
|
79
|
+
message: value.message,
|
|
80
|
+
stack: value.stack,
|
|
81
|
+
__error__: value.constructor.name
|
|
82
|
+
};
|
|
83
|
+
return value;
|
|
84
|
+
});
|
|
85
|
+
return new TextEncoder().encode(json);
|
|
86
|
+
}
|
|
87
|
+
case 9: return new TextEncoder().encode(String(value));
|
|
88
|
+
default: throw new Error("unsupported data");
|
|
89
|
+
}
|
|
90
|
+
};
|
|
91
|
+
/**
|
|
92
|
+
* @param {typeof import('memfs')} memfs
|
|
93
|
+
* @param {Uint8Array} payload
|
|
94
|
+
* @param {number} type
|
|
95
|
+
* @returns {any}
|
|
96
|
+
*/
|
|
97
|
+
const decodeValue = (memfs, payload, type) => {
|
|
98
|
+
if (type === 0) return void 0;
|
|
99
|
+
if (type === 1) return null;
|
|
100
|
+
if (type === 2) return Boolean(new Int32Array(payload.buffer, payload.byteOffset, 1)[0]);
|
|
101
|
+
if (type === 3) return new Float64Array(payload.buffer, payload.byteOffset, 1)[0];
|
|
102
|
+
if (type === 4) return new TextDecoder().decode(payload.slice());
|
|
103
|
+
if (type === 10) {
|
|
104
|
+
const BufferCtor = globalThis.Buffer;
|
|
105
|
+
if (typeof BufferCtor?.from === "function") return BufferCtor.from(payload);
|
|
106
|
+
return payload.slice();
|
|
107
|
+
}
|
|
108
|
+
if (type === 6) {
|
|
109
|
+
const obj = JSON.parse(new TextDecoder().decode(payload.slice()), (_key, value) => {
|
|
110
|
+
if (typeof value === "string") {
|
|
111
|
+
const matched = value.match(/^BigInt\((-?\d+)\)$/);
|
|
112
|
+
if (matched && matched[1]) return BigInt(matched[1]);
|
|
113
|
+
}
|
|
114
|
+
return value;
|
|
115
|
+
});
|
|
116
|
+
function loadConstructor(obj, memfs, processed = /* @__PURE__ */ new WeakSet()) {
|
|
117
|
+
if (!obj || typeof obj !== "object") return;
|
|
118
|
+
if (processed.has(obj)) return;
|
|
119
|
+
processed.add(obj);
|
|
120
|
+
if (obj.__constructor__) {
|
|
121
|
+
const ctor = obj.__constructor__;
|
|
122
|
+
delete obj.__constructor__;
|
|
123
|
+
Object.setPrototypeOf(obj, memfs[ctor].prototype);
|
|
124
|
+
}
|
|
125
|
+
for (const value of Object.values(obj)) loadConstructor(value, memfs, processed);
|
|
126
|
+
}
|
|
127
|
+
loadConstructor(obj, memfs);
|
|
128
|
+
if (obj.__error__) {
|
|
129
|
+
const name = obj.__error__;
|
|
130
|
+
const ErrorConstructor = globalThis[name] || Error;
|
|
131
|
+
delete obj.__error__;
|
|
132
|
+
const err = new ErrorConstructor(obj.message);
|
|
133
|
+
Object.defineProperty(err, "stack", {
|
|
134
|
+
configurable: true,
|
|
135
|
+
enumerable: false,
|
|
136
|
+
writable: true,
|
|
137
|
+
value: err.stack
|
|
138
|
+
});
|
|
139
|
+
Object.defineProperty(err, Symbol.toStringTag, {
|
|
140
|
+
configurable: true,
|
|
141
|
+
enumerable: false,
|
|
142
|
+
writable: true,
|
|
143
|
+
value: name
|
|
144
|
+
});
|
|
145
|
+
for (const [k, v] of Object.entries(obj)) {
|
|
146
|
+
if (k === "message" || k === "stack") continue;
|
|
147
|
+
err[k] = v;
|
|
148
|
+
}
|
|
149
|
+
return err;
|
|
150
|
+
}
|
|
151
|
+
return obj;
|
|
152
|
+
}
|
|
153
|
+
if (type === 9) return BigInt(new TextDecoder().decode(payload.slice()));
|
|
154
|
+
throw new Error("unsupported data");
|
|
155
|
+
};
|
|
156
|
+
/**
|
|
157
|
+
* @param {import('memfs').IFs} fs
|
|
158
|
+
* @returns {(e: { data: { __fs__: { sab: Int32Array, type: keyof import('memfs').IFs, payload: any[] } } }) => void}
|
|
159
|
+
*/
|
|
160
|
+
const createOnMessage = (fs) => function onMessage(e) {
|
|
161
|
+
if (e.data.__fs__) {
|
|
162
|
+
/**
|
|
163
|
+
* 0..4 status(int32_t): 21(waiting) 0(success) 1(error)
|
|
164
|
+
* 5..8 type(napi_valuetype): 0(undefined) 1(null) 2(boolean) 3(number) 4(string) 6(jsonstring) 9(bigint) 10(buffer) -1(unsupported)
|
|
165
|
+
* 9..16 payload_size(uint32_t) <= 10240
|
|
166
|
+
* 16..16 + payload_size payload_content
|
|
167
|
+
*/
|
|
168
|
+
const { sab, type, payload } = e.data.__fs__;
|
|
169
|
+
const fn = fs[type];
|
|
170
|
+
try {
|
|
171
|
+
const ret = fn.apply(fs, payload);
|
|
172
|
+
const t = getType(ret);
|
|
173
|
+
Atomics.store(sab, 1, t);
|
|
174
|
+
const v = encodeValue(fs, ret, t);
|
|
175
|
+
Atomics.store(sab, 2, v.length);
|
|
176
|
+
writeResponsePayload(sab, v);
|
|
177
|
+
Atomics.store(sab, 0, 0);
|
|
178
|
+
} catch (err) {
|
|
179
|
+
let t = getType(err);
|
|
180
|
+
let v;
|
|
181
|
+
try {
|
|
182
|
+
if (t === -1) throw new Error("unsupported data");
|
|
183
|
+
v = encodeValue(fs, err, t);
|
|
184
|
+
} catch {
|
|
185
|
+
const fallback = (() => {
|
|
186
|
+
try {
|
|
187
|
+
return String(err);
|
|
188
|
+
} catch {
|
|
189
|
+
return "Unserializable thrown value";
|
|
190
|
+
}
|
|
191
|
+
})();
|
|
192
|
+
t = getType(fallback);
|
|
193
|
+
v = encodeValue(fs, fallback, t);
|
|
194
|
+
}
|
|
195
|
+
if (v.length > RESPONSE_PAYLOAD_SIZE) {
|
|
196
|
+
const overflowErr = /* @__PURE__ */ new RangeError("payload overflow");
|
|
197
|
+
t = getType(overflowErr);
|
|
198
|
+
v = encodeValue(fs, overflowErr, t);
|
|
199
|
+
}
|
|
200
|
+
Atomics.store(sab, 1, t);
|
|
201
|
+
Atomics.store(sab, 2, v.length);
|
|
202
|
+
writeResponsePayload(sab, v);
|
|
203
|
+
Atomics.store(sab, 0, 1);
|
|
204
|
+
} finally {
|
|
205
|
+
Atomics.notify(sab, 0);
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
};
|
|
209
|
+
/**
|
|
210
|
+
* @param {typeof import('memfs')} memfs
|
|
211
|
+
*/
|
|
212
|
+
const createFsProxy = (memfs) => new Proxy({}, { get(_target, p, _receiver) {
|
|
213
|
+
/**
|
|
214
|
+
* @param {any[]} args
|
|
215
|
+
*/
|
|
216
|
+
return function(...args) {
|
|
217
|
+
const sab = new SharedArrayBuffer(RESPONSE_BUFFER_SIZE);
|
|
218
|
+
const i32arr = new Int32Array(sab);
|
|
219
|
+
Atomics.store(i32arr, 0, 21);
|
|
220
|
+
postMessage({ __fs__: {
|
|
221
|
+
sab: i32arr,
|
|
222
|
+
type: p,
|
|
223
|
+
payload: args
|
|
224
|
+
} });
|
|
225
|
+
Atomics.wait(i32arr, 0, 21);
|
|
226
|
+
const status = Atomics.load(i32arr, 0);
|
|
227
|
+
const type = Atomics.load(i32arr, 1);
|
|
228
|
+
const size = Atomics.load(i32arr, 2);
|
|
229
|
+
const content = new Uint8Array(sab, RESPONSE_HEADER_SIZE, size);
|
|
230
|
+
const value = decodeValue(memfs, content, type);
|
|
231
|
+
if (status === 1) throw value;
|
|
232
|
+
return value;
|
|
233
|
+
};
|
|
234
|
+
} });
|
|
235
|
+
//#endregion
|
|
236
|
+
exports.createFsProxy = createFsProxy;
|
|
237
|
+
exports.createOnMessage = createOnMessage;
|