nuxt-ai-ready 2.5.2 → 3.0.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.
- package/README.md +13 -12
- package/dist/chunks/agent-skills.mjs +35 -12
- package/dist/chunks/prerender.mjs +35 -24
- package/dist/cli.mjs +5 -2
- package/dist/module.d.mts +4 -0
- package/dist/module.json +2 -2
- package/dist/module.mjs +8 -4
- package/dist/runtime/app/index.d.ts +3 -0
- package/dist/runtime/app/index.js +2 -0
- package/dist/runtime/cache-control.d.ts +2 -0
- package/dist/runtime/cache-control.js +11 -0
- package/dist/runtime/llms-txt-utils.js +1 -1
- package/dist/runtime/server/db/context.d.ts +13 -0
- package/dist/runtime/server/db/drizzle/client.d.ts +6 -7
- package/dist/runtime/server/db/drizzle/client.js +13 -2
- package/dist/runtime/server/db/drizzle/providers/bun.d.ts +2 -2
- package/dist/runtime/server/db/drizzle/providers/bun.js +2 -2
- package/dist/runtime/server/db/drizzle/providers/d1.d.ts +2 -2
- package/dist/runtime/server/db/drizzle/providers/d1.js +3 -2
- package/dist/runtime/server/db/drizzle/providers/libsql.d.ts +2 -2
- package/dist/runtime/server/db/drizzle/providers/libsql.js +2 -2
- package/dist/runtime/server/db/drizzle/providers/neon.d.ts +2 -2
- package/dist/runtime/server/db/drizzle/providers/neon.js +2 -2
- package/dist/runtime/server/db/drizzle/providers/node-sqlite.d.ts +2 -2
- package/dist/runtime/server/db/drizzle/providers/node-sqlite.js +2 -2
- package/dist/runtime/server/db/drizzle/providers/postgres.d.ts +2 -2
- package/dist/runtime/server/db/drizzle/providers/postgres.js +2 -2
- package/dist/runtime/server/db/drizzle/queries.d.ts +27 -27
- package/dist/runtime/server/db/drizzle/queries.js +6 -5
- package/dist/runtime/server/db/drizzle/raw.d.ts +2 -6
- package/dist/runtime/server/db/index.d.ts +1 -1
- package/dist/runtime/server/db/index.js +1 -1
- package/dist/runtime/server/db/queries.d.ts +36 -36
- package/dist/runtime/server/db/queries.js +8 -9
- package/dist/runtime/server/db/seed.d.ts +2 -2
- package/dist/runtime/server/db/seed.js +4 -3
- package/dist/runtime/server/db/shared.d.ts +8 -0
- package/dist/runtime/server/db/shared.js +8 -2
- package/dist/runtime/server/index.d.ts +2 -0
- package/dist/runtime/server/index.js +17 -0
- package/dist/runtime/server/mcp/tools/get-page-markdown.js +1 -1
- package/dist/runtime/server/mcp/tools/list-pages.js +1 -1
- package/dist/runtime/server/mcp/tools/search-pages.js +1 -1
- package/dist/runtime/server/middleware/markdown.js +3 -3
- package/dist/runtime/server/middleware/markdown.prerender.js +1 -1
- package/dist/runtime/server/plugins/db-lifecycle-nitro3.d.ts +2 -0
- package/dist/runtime/server/plugins/db-lifecycle-nitro3.js +16 -0
- package/dist/runtime/server/plugins/html-capture.prerender.js +6 -4
- package/dist/runtime/server/plugins/link-header-nitro3.d.ts +2 -0
- package/dist/runtime/server/plugins/link-header-nitro3.js +20 -0
- package/dist/runtime/server/plugins/link-header.d.ts +6 -0
- package/dist/runtime/server/plugins/link-header.js +7 -11
- package/dist/runtime/server/plugins/markdown-negotiation.js +8 -1
- package/dist/runtime/server/plugins/sitemap-seeder.js +3 -3
- package/dist/runtime/server/routes/agent-skills-artifact.d.ts +1 -1
- package/dist/runtime/server/routes/agent-skills-artifact.js +10 -10
- package/dist/runtime/server/routes/agent-skills-index.d.ts +1 -1
- package/dist/runtime/server/routes/agent-skills-index.js +7 -6
- package/dist/runtime/server/routes/ai-catalog.d.ts +2 -1
- package/dist/runtime/server/routes/ai-catalog.js +7 -8
- package/dist/runtime/server/routes/api-catalog.d.ts +3 -1
- package/dist/runtime/server/routes/api-catalog.js +12 -12
- package/dist/runtime/server/routes/llms-full.txt.get.js +1 -1
- package/dist/runtime/server/routes/mcp-server-card.d.ts +1 -1
- package/dist/runtime/server/routes/mcp-server-card.js +7 -8
- package/dist/runtime/server/utils/checkStale.d.ts +2 -2
- package/dist/runtime/server/utils/cloudflare-prerendered.d.ts +3 -0
- package/dist/runtime/server/utils/cloudflare-prerendered.js +23 -0
- package/dist/runtime/server/utils/cloudflare.d.ts +5 -5
- package/dist/runtime/server/utils/cloudflare.js +31 -7
- package/dist/runtime/server/utils/content-negotiation.d.ts +5 -3
- package/dist/runtime/server/utils/content-negotiation.js +8 -7
- package/dist/runtime/server/utils/context.d.ts +3 -3
- package/dist/runtime/server/utils/context.js +1 -1
- package/dist/runtime/server/utils/discovery-response.d.ts +2 -0
- package/dist/runtime/server/utils/link-header.d.ts +5 -3
- package/dist/runtime/server/utils/link-header.js +26 -2
- package/dist/runtime/server/utils/markdown-request.d.ts +4 -3
- package/dist/runtime/server/utils/markdown-request.js +15 -13
- package/dist/runtime/server/utils/negotiation-decision.d.ts +4 -0
- package/dist/runtime/server/utils/negotiation-decision.js +6 -5
- package/dist/runtime/server/utils/negotiation-response.d.ts +1 -1
- package/dist/runtime/server/utils/negotiation-response.js +63 -23
- package/dist/runtime/server/utils/prerender-html.d.ts +2 -1
- package/dist/runtime/server/utils/prerender-html.js +3 -1
- package/dist/runtime/types.d.ts +15 -7
- package/dist/shared/nuxt-ai-ready.B3hAuOLQ.mjs +29 -0
- package/dist/shared/{nuxt-ai-ready.CLSWou20.mjs → nuxt-ai-ready.C34F0LJo.mjs} +560 -219
- package/package.json +85 -20
- package/skills/nuxt-ai-ready/SKILL.md +26 -12
- package/skills/nuxt-ai-ready/references/runtime-indexing.md +7 -6
- package/dist/runtime/server/db/drizzle/providers/sqlite.d.ts +0 -8
- package/dist/runtime/server/db/drizzle/providers/sqlite.js +0 -15
- package/node_modules/@mdream/js/LICENSE.md +0 -9
- package/node_modules/@mdream/js/README.md +0 -792
- package/node_modules/@mdream/js/bin/mdream.mjs +0 -2
- package/node_modules/@mdream/js/dist/_chunks/const.mjs +0 -134
- package/node_modules/@mdream/js/dist/_chunks/index.d.mts +0 -9
- package/node_modules/@mdream/js/dist/_chunks/markdown-processor.mjs +0 -1968
- package/node_modules/@mdream/js/dist/_chunks/minimal.d.mts +0 -6
- package/node_modules/@mdream/js/dist/_chunks/parse.mjs +0 -2756
- package/node_modules/@mdream/js/dist/_chunks/plugins.mjs +0 -725
- package/node_modules/@mdream/js/dist/_chunks/resolve-plugins.mjs +0 -44
- package/node_modules/@mdream/js/dist/_chunks/stream.mjs +0 -37
- package/node_modules/@mdream/js/dist/_chunks/types.d.mts +0 -473
- package/node_modules/@mdream/js/dist/cli.d.mts +0 -1
- package/node_modules/@mdream/js/dist/cli.mjs +0 -32
- package/node_modules/@mdream/js/dist/core.d.mts +0 -15
- package/node_modules/@mdream/js/dist/core.mjs +0 -28
- package/node_modules/@mdream/js/dist/index.d.mts +0 -4
- package/node_modules/@mdream/js/dist/index.mjs +0 -58
- package/node_modules/@mdream/js/dist/llms-txt.d.mts +0 -86
- package/node_modules/@mdream/js/dist/llms-txt.mjs +0 -308
- package/node_modules/@mdream/js/dist/negotiate.d.mts +0 -35
- package/node_modules/@mdream/js/dist/negotiate.mjs +0 -121
- package/node_modules/@mdream/js/dist/parse.d.mts +0 -90
- package/node_modules/@mdream/js/dist/parse.mjs +0 -2
- package/node_modules/@mdream/js/dist/plugins.d.mts +0 -85
- package/node_modules/@mdream/js/dist/plugins.mjs +0 -2
- package/node_modules/@mdream/js/dist/preset/minimal.d.mts +0 -2
- package/node_modules/@mdream/js/dist/preset/minimal.mjs +0 -33
- package/node_modules/@mdream/js/dist/splitter.d.mts +0 -18
- package/node_modules/@mdream/js/dist/splitter.mjs +0 -194
- package/node_modules/@mdream/js/package.json +0 -103
- package/node_modules/cac/LICENSE +0 -21
- package/node_modules/cac/README.md +0 -492
- package/node_modules/cac/dist/index.d.ts +0 -196
- package/node_modules/cac/dist/index.js +0 -638
- package/node_modules/cac/package.json +0 -72
- package/node_modules/mdream/LICENSE.md +0 -9
- package/node_modules/mdream/README.md +0 -1091
- package/node_modules/mdream/bin/mdream.mjs +0 -46
- package/node_modules/mdream/dist/browser.d.mts +0 -105
- package/node_modules/mdream/dist/browser.mjs +0 -262
- package/node_modules/mdream/dist/edge.d.mts +0 -100
- package/node_modules/mdream/dist/edge.mjs +0 -250
- package/node_modules/mdream/dist/iife.js +0 -605
- package/node_modules/mdream/dist/index.d.mts +0 -89
- package/node_modules/mdream/dist/index.mjs +0 -184
- package/node_modules/mdream/dist/wasm.d.mts +0 -100
- package/node_modules/mdream/dist/wasm.mjs +0 -140
- package/node_modules/mdream/dist/worker.d.mts +0 -101
- package/node_modules/mdream/dist/worker.mjs +0 -217
- package/node_modules/mdream/napi/index.d.mts +0 -127
- package/node_modules/mdream/napi/index.d.ts +0 -127
- package/node_modules/mdream/napi/index.mjs +0 -725
- 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 +0 -2144
- 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 +0 -21
- package/node_modules/mdream/node_modules/@emnapi/core/README.md +0 -1
- package/node_modules/mdream/node_modules/@emnapi/core/dist/emnapi-core.d.ts +0 -392
- package/node_modules/mdream/node_modules/@emnapi/core/dist/emnapi-core.full.d.ts +0 -392
- package/node_modules/mdream/node_modules/@emnapi/core/dist/emnapi-core.full.js +0 -8351
- package/node_modules/mdream/node_modules/@emnapi/core/dist/emnapi-core.js +0 -7268
- package/node_modules/mdream/node_modules/@emnapi/core/dist/plugins/async-work.d.ts +0 -5
- package/node_modules/mdream/node_modules/@emnapi/core/dist/plugins/async-work.js +0 -843
- package/node_modules/mdream/node_modules/@emnapi/core/dist/plugins/index.d.ts +0 -4
- package/node_modules/mdream/node_modules/@emnapi/core/dist/plugins/index.js +0 -3
- package/node_modules/mdream/node_modules/@emnapi/core/dist/plugins/threadsafe-function.d.ts +0 -5
- package/node_modules/mdream/node_modules/@emnapi/core/dist/plugins/threadsafe-function.js +0 -1010
- package/node_modules/mdream/node_modules/@emnapi/core/dist/plugins/v8.d.ts +0 -5
- package/node_modules/mdream/node_modules/@emnapi/core/dist/plugins/v8.js +0 -1446
- package/node_modules/mdream/node_modules/@emnapi/core/package.json +0 -39
- package/node_modules/mdream/node_modules/@emnapi/core/rollup.config.js +0 -60
- package/node_modules/mdream/node_modules/@emnapi/runtime/LICENSE +0 -21
- package/node_modules/mdream/node_modules/@emnapi/runtime/README.md +0 -1
- package/node_modules/mdream/node_modules/@emnapi/runtime/dist/emnapi.d.ts +0 -833
- package/node_modules/mdream/node_modules/@emnapi/runtime/dist/emnapi.js +0 -2306
- package/node_modules/mdream/node_modules/@emnapi/runtime/dist/emnapi.js.map +0 -1
- package/node_modules/mdream/node_modules/@emnapi/runtime/index.cjs +0 -63
- package/node_modules/mdream/node_modules/@emnapi/runtime/package.json +0 -39
- package/node_modules/mdream/node_modules/@emnapi/runtime/rollup.config.js +0 -25
- package/node_modules/mdream/node_modules/@emnapi/wasi-threads/LICENSE +0 -21
- package/node_modules/mdream/node_modules/@emnapi/wasi-threads/README.md +0 -203
- package/node_modules/mdream/node_modules/@emnapi/wasi-threads/dist/wasi-threads.d.ts +0 -236
- package/node_modules/mdream/node_modules/@emnapi/wasi-threads/dist/wasi-threads.js +0 -1086
- package/node_modules/mdream/node_modules/@emnapi/wasi-threads/package.json +0 -35
- package/node_modules/mdream/node_modules/@emnapi/wasi-threads/rollup.config.js +0 -6
- package/node_modules/mdream/node_modules/@napi-rs/wasm-runtime/dist/emnapi-plugins.cjs +0 -1472
- package/node_modules/mdream/node_modules/@napi-rs/wasm-runtime/dist/emnapi-plugins.js +0 -1470
- package/node_modules/mdream/node_modules/@napi-rs/wasm-runtime/dist/fs-proxy.cjs +0 -237
- package/node_modules/mdream/node_modules/@napi-rs/wasm-runtime/dist/fs.js +0 -18260
- package/node_modules/mdream/node_modules/@napi-rs/wasm-runtime/fs-proxy.js +0 -317
- package/node_modules/mdream/node_modules/@napi-rs/wasm-runtime/package.json +0 -67
- package/node_modules/mdream/node_modules/@napi-rs/wasm-runtime/runtime.cjs +0 -39
- package/node_modules/mdream/node_modules/@napi-rs/wasm-runtime/runtime.js +0 -36
- package/node_modules/mdream/node_modules/@tybys/wasm-util/LICENSE +0 -21
- package/node_modules/mdream/node_modules/@tybys/wasm-util/README.md +0 -193
- package/node_modules/mdream/node_modules/@tybys/wasm-util/dist/tsdoc-metadata.json +0 -11
- package/node_modules/mdream/node_modules/@tybys/wasm-util/dist/wasm-util.d.ts +0 -423
- package/node_modules/mdream/node_modules/@tybys/wasm-util/dist/wasm-util.esm-bundler.js +0 -2932
- package/node_modules/mdream/node_modules/@tybys/wasm-util/dist/wasm-util.esm.js +0 -2932
- package/node_modules/mdream/node_modules/@tybys/wasm-util/dist/wasm-util.esm.min.js +0 -1
- package/node_modules/mdream/node_modules/@tybys/wasm-util/dist/wasm-util.js +0 -2954
- package/node_modules/mdream/node_modules/@tybys/wasm-util/dist/wasm-util.min.js +0 -1
- package/node_modules/mdream/node_modules/@tybys/wasm-util/lib/cjs/asyncify.js +0 -158
- package/node_modules/mdream/node_modules/@tybys/wasm-util/lib/cjs/index.js +0 -13
- package/node_modules/mdream/node_modules/@tybys/wasm-util/lib/cjs/jspi.js +0 -46
- package/node_modules/mdream/node_modules/@tybys/wasm-util/lib/cjs/load.js +0 -97
- package/node_modules/mdream/node_modules/@tybys/wasm-util/lib/cjs/memory.js +0 -35
- package/node_modules/mdream/node_modules/@tybys/wasm-util/lib/cjs/wasi/error.js +0 -103
- package/node_modules/mdream/node_modules/@tybys/wasm-util/lib/cjs/wasi/fd.js +0 -268
- package/node_modules/mdream/node_modules/@tybys/wasm-util/lib/cjs/wasi/fs.js +0 -3
- package/node_modules/mdream/node_modules/@tybys/wasm-util/lib/cjs/wasi/index.js +0 -192
- package/node_modules/mdream/node_modules/@tybys/wasm-util/lib/cjs/wasi/path.js +0 -316
- package/node_modules/mdream/node_modules/@tybys/wasm-util/lib/cjs/wasi/preview1.js +0 -1599
- package/node_modules/mdream/node_modules/@tybys/wasm-util/lib/cjs/wasi/rights.js +0 -141
- package/node_modules/mdream/node_modules/@tybys/wasm-util/lib/cjs/wasi/types.js +0 -220
- package/node_modules/mdream/node_modules/@tybys/wasm-util/lib/cjs/wasi/util.js +0 -128
- package/node_modules/mdream/node_modules/@tybys/wasm-util/lib/cjs/webassembly.js +0 -13
- package/node_modules/mdream/node_modules/@tybys/wasm-util/lib/mjs/asyncify.mjs +0 -153
- package/node_modules/mdream/node_modules/@tybys/wasm-util/lib/mjs/index.mjs +0 -9
- package/node_modules/mdream/node_modules/@tybys/wasm-util/lib/mjs/jspi.mjs +0 -39
- package/node_modules/mdream/node_modules/@tybys/wasm-util/lib/mjs/load.mjs +0 -89
- package/node_modules/mdream/node_modules/@tybys/wasm-util/lib/mjs/memory.mjs +0 -28
- package/node_modules/mdream/node_modules/@tybys/wasm-util/lib/mjs/wasi/error.mjs +0 -97
- package/node_modules/mdream/node_modules/@tybys/wasm-util/lib/mjs/wasi/fd.mjs +0 -256
- package/node_modules/mdream/node_modules/@tybys/wasm-util/lib/mjs/wasi/fs.mjs +0 -1
- package/node_modules/mdream/node_modules/@tybys/wasm-util/lib/mjs/wasi/index.mjs +0 -186
- package/node_modules/mdream/node_modules/@tybys/wasm-util/lib/mjs/wasi/path.mjs +0 -310
- package/node_modules/mdream/node_modules/@tybys/wasm-util/lib/mjs/wasi/preview1.mjs +0 -1593
- package/node_modules/mdream/node_modules/@tybys/wasm-util/lib/mjs/wasi/rights.mjs +0 -135
- package/node_modules/mdream/node_modules/@tybys/wasm-util/lib/mjs/wasi/types.mjs +0 -216
- package/node_modules/mdream/node_modules/@tybys/wasm-util/lib/mjs/wasi/util.mjs +0 -113
- package/node_modules/mdream/node_modules/@tybys/wasm-util/lib/mjs/webassembly.mjs +0 -9
- package/node_modules/mdream/node_modules/@tybys/wasm-util/package.json +0 -58
- package/node_modules/mdream/node_modules/tslib/CopyrightNotice.txt +0 -15
- package/node_modules/mdream/node_modules/tslib/LICENSE.txt +0 -12
- package/node_modules/mdream/node_modules/tslib/README.md +0 -164
- package/node_modules/mdream/node_modules/tslib/SECURITY.md +0 -41
- package/node_modules/mdream/node_modules/tslib/modules/index.d.ts +0 -38
- package/node_modules/mdream/node_modules/tslib/modules/index.js +0 -70
- package/node_modules/mdream/node_modules/tslib/modules/package.json +0 -3
- package/node_modules/mdream/node_modules/tslib/package.json +0 -47
- package/node_modules/mdream/node_modules/tslib/tslib.d.ts +0 -460
- package/node_modules/mdream/node_modules/tslib/tslib.es6.html +0 -1
- package/node_modules/mdream/node_modules/tslib/tslib.es6.js +0 -402
- package/node_modules/mdream/node_modules/tslib/tslib.es6.mjs +0 -401
- package/node_modules/mdream/node_modules/tslib/tslib.html +0 -1
- package/node_modules/mdream/node_modules/tslib/tslib.js +0 -484
- package/node_modules/mdream/package.json +0 -110
- package/node_modules/mdream/skills/mdream/SKILL.md +0 -124
- package/node_modules/mdream/skills/mdream/references/runtimes.md +0 -49
- package/node_modules/mdream/wasm/mdream_edge.d.ts +0 -90
- package/node_modules/mdream/wasm/mdream_edge.js +0 -517
- package/node_modules/mdream/wasm/mdream_edge_bg.wasm +0 -0
- package/node_modules/mdream/wasm/mdream_edge_bg.wasm.d.ts +0 -20
- package/node_modules/mdream/wasm/package.json +0 -17
- package/node_modules/mdream/wasm-bundler/mdream_edge.d.ts +0 -45
- package/node_modules/mdream/wasm-bundler/mdream_edge.js +0 -13
- package/node_modules/mdream/wasm-bundler/mdream_edge_bg.js +0 -413
- package/node_modules/mdream/wasm-bundler/mdream_edge_bg.wasm +0 -0
- package/node_modules/mdream/wasm-bundler/mdream_edge_bg.wasm.d.ts +0 -20
- package/node_modules/mdream/wasm-bundler/package.json +0 -19
- package/node_modules/pathe/LICENSE +0 -70
- package/node_modules/pathe/README.md +0 -73
- package/node_modules/pathe/dist/index.cjs +0 -39
- package/node_modules/pathe/dist/index.d.cts +0 -47
- package/node_modules/pathe/dist/index.d.mts +0 -47
- package/node_modules/pathe/dist/index.d.ts +0 -47
- package/node_modules/pathe/dist/index.mjs +0 -19
- package/node_modules/pathe/dist/shared/pathe.BSlhyZSM.cjs +0 -266
- package/node_modules/pathe/dist/shared/pathe.M-eThtNZ.mjs +0 -249
- package/node_modules/pathe/dist/utils.cjs +0 -82
- package/node_modules/pathe/dist/utils.d.cts +0 -32
- package/node_modules/pathe/dist/utils.d.mts +0 -32
- package/node_modules/pathe/dist/utils.d.ts +0 -32
- package/node_modules/pathe/dist/utils.mjs +0 -77
- package/node_modules/pathe/package.json +0 -61
- package/node_modules/pathe/utils.d.ts +0 -1
|
@@ -1,237 +0,0 @@
|
|
|
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;
|