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,268 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.AsyncTable = exports.SyncTable = exports.FileDescriptorTable = exports.toFileStat = exports.toFileType = exports.StandardOutput = exports.FileDescriptor = exports.concatBuffer = void 0;
|
|
4
|
+
const types_1 = require("./types");
|
|
5
|
+
const rights_1 = require("./rights");
|
|
6
|
+
const error_1 = require("./error");
|
|
7
|
+
function concatBuffer(buffers, size) {
|
|
8
|
+
let total = 0;
|
|
9
|
+
if (typeof size === 'number' && size >= 0) {
|
|
10
|
+
total = size;
|
|
11
|
+
}
|
|
12
|
+
else {
|
|
13
|
+
for (let i = 0; i < buffers.length; i++) {
|
|
14
|
+
const buffer = buffers[i];
|
|
15
|
+
total += buffer.length;
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
let pos = 0;
|
|
19
|
+
const ret = new Uint8Array(total);
|
|
20
|
+
for (let i = 0; i < buffers.length; i++) {
|
|
21
|
+
const buffer = buffers[i];
|
|
22
|
+
ret.set(buffer, pos);
|
|
23
|
+
pos += buffer.length;
|
|
24
|
+
}
|
|
25
|
+
return ret;
|
|
26
|
+
}
|
|
27
|
+
exports.concatBuffer = concatBuffer;
|
|
28
|
+
class FileDescriptor {
|
|
29
|
+
constructor(id, fd, path, realPath, type, rightsBase, rightsInheriting, preopen) {
|
|
30
|
+
this.id = id;
|
|
31
|
+
this.fd = fd;
|
|
32
|
+
this.path = path;
|
|
33
|
+
this.realPath = realPath;
|
|
34
|
+
this.type = type;
|
|
35
|
+
this.rightsBase = rightsBase;
|
|
36
|
+
this.rightsInheriting = rightsInheriting;
|
|
37
|
+
this.preopen = preopen;
|
|
38
|
+
this.pos = BigInt(0);
|
|
39
|
+
this.size = BigInt(0);
|
|
40
|
+
}
|
|
41
|
+
seek(offset, whence) {
|
|
42
|
+
if (whence === types_1.WasiWhence.SET) {
|
|
43
|
+
this.pos = BigInt(offset);
|
|
44
|
+
}
|
|
45
|
+
else if (whence === types_1.WasiWhence.CUR) {
|
|
46
|
+
this.pos += BigInt(offset);
|
|
47
|
+
}
|
|
48
|
+
else if (whence === types_1.WasiWhence.END) {
|
|
49
|
+
this.pos = BigInt(this.size) - BigInt(offset);
|
|
50
|
+
}
|
|
51
|
+
else {
|
|
52
|
+
throw new error_1.WasiError('Unknown whence', types_1.WasiErrno.EIO);
|
|
53
|
+
}
|
|
54
|
+
return this.pos;
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
exports.FileDescriptor = FileDescriptor;
|
|
58
|
+
class StandardOutput extends FileDescriptor {
|
|
59
|
+
constructor(log, id, fd, path, realPath, type, rightsBase, rightsInheriting, preopen) {
|
|
60
|
+
super(id, fd, path, realPath, type, rightsBase, rightsInheriting, preopen);
|
|
61
|
+
this._log = log;
|
|
62
|
+
this._buf = null;
|
|
63
|
+
}
|
|
64
|
+
write(buffer) {
|
|
65
|
+
const originalBuffer = buffer;
|
|
66
|
+
if (this._buf) {
|
|
67
|
+
buffer = concatBuffer([this._buf, buffer]);
|
|
68
|
+
this._buf = null;
|
|
69
|
+
}
|
|
70
|
+
if (buffer.indexOf(10) === -1) {
|
|
71
|
+
this._buf = buffer;
|
|
72
|
+
return originalBuffer.byteLength;
|
|
73
|
+
}
|
|
74
|
+
let written = 0;
|
|
75
|
+
let lastBegin = 0;
|
|
76
|
+
let index;
|
|
77
|
+
while ((index = buffer.indexOf(10, written)) !== -1) {
|
|
78
|
+
const str = new TextDecoder().decode(buffer.subarray(lastBegin, index));
|
|
79
|
+
this._log(str);
|
|
80
|
+
written += index - lastBegin + 1;
|
|
81
|
+
lastBegin = index + 1;
|
|
82
|
+
}
|
|
83
|
+
if (written < buffer.length) {
|
|
84
|
+
this._buf = buffer.slice(written);
|
|
85
|
+
}
|
|
86
|
+
return originalBuffer.byteLength;
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
exports.StandardOutput = StandardOutput;
|
|
90
|
+
function toFileType(stat) {
|
|
91
|
+
if (stat.isBlockDevice())
|
|
92
|
+
return types_1.WasiFileType.BLOCK_DEVICE;
|
|
93
|
+
if (stat.isCharacterDevice())
|
|
94
|
+
return types_1.WasiFileType.CHARACTER_DEVICE;
|
|
95
|
+
if (stat.isDirectory())
|
|
96
|
+
return types_1.WasiFileType.DIRECTORY;
|
|
97
|
+
if (stat.isSocket())
|
|
98
|
+
return types_1.WasiFileType.SOCKET_STREAM;
|
|
99
|
+
if (stat.isFile())
|
|
100
|
+
return types_1.WasiFileType.REGULAR_FILE;
|
|
101
|
+
if (stat.isSymbolicLink())
|
|
102
|
+
return types_1.WasiFileType.SYMBOLIC_LINK;
|
|
103
|
+
return types_1.WasiFileType.UNKNOWN;
|
|
104
|
+
}
|
|
105
|
+
exports.toFileType = toFileType;
|
|
106
|
+
function toFileStat(view, buf, stat) {
|
|
107
|
+
view.setBigUint64(buf, stat.dev, true);
|
|
108
|
+
view.setBigUint64(buf + 8, stat.ino, true);
|
|
109
|
+
view.setBigUint64(buf + 16, BigInt(toFileType(stat)), true);
|
|
110
|
+
view.setBigUint64(buf + 24, stat.nlink, true);
|
|
111
|
+
view.setBigUint64(buf + 32, stat.size, true);
|
|
112
|
+
view.setBigUint64(buf + 40, stat.atimeMs * BigInt(1000000), true);
|
|
113
|
+
view.setBigUint64(buf + 48, stat.mtimeMs * BigInt(1000000), true);
|
|
114
|
+
view.setBigUint64(buf + 56, stat.ctimeMs * BigInt(1000000), true);
|
|
115
|
+
}
|
|
116
|
+
exports.toFileStat = toFileStat;
|
|
117
|
+
class FileDescriptorTable {
|
|
118
|
+
constructor(options) {
|
|
119
|
+
this.used = 0;
|
|
120
|
+
this.size = options.size;
|
|
121
|
+
this.fds = Array(options.size);
|
|
122
|
+
this.stdio = [options.in, options.out, options.err];
|
|
123
|
+
this.print = options.print;
|
|
124
|
+
this.printErr = options.printErr;
|
|
125
|
+
this.insertStdio(options.in, 0, '<stdin>');
|
|
126
|
+
this.insertStdio(options.out, 1, '<stdout>');
|
|
127
|
+
this.insertStdio(options.err, 2, '<stderr>');
|
|
128
|
+
}
|
|
129
|
+
insertStdio(fd, expected, name) {
|
|
130
|
+
const type = types_1.WasiFileType.CHARACTER_DEVICE;
|
|
131
|
+
const { base, inheriting } = (0, rights_1.getRights)(this.stdio, fd, types_1.FileControlFlag.O_RDWR, type);
|
|
132
|
+
const wrap = this.insert(fd, name, name, type, base, inheriting, 0);
|
|
133
|
+
if (wrap.id !== expected) {
|
|
134
|
+
throw new error_1.WasiError(`id: ${wrap.id} !== expected: ${expected}`, types_1.WasiErrno.EBADF);
|
|
135
|
+
}
|
|
136
|
+
return wrap;
|
|
137
|
+
}
|
|
138
|
+
insert(fd, mappedPath, realPath, type, rightsBase, rightsInheriting, preopen) {
|
|
139
|
+
var _a, _b;
|
|
140
|
+
let index = -1;
|
|
141
|
+
if (this.used >= this.size) {
|
|
142
|
+
const newSize = this.size * 2;
|
|
143
|
+
this.fds.length = newSize;
|
|
144
|
+
index = this.size;
|
|
145
|
+
this.size = newSize;
|
|
146
|
+
}
|
|
147
|
+
else {
|
|
148
|
+
for (let i = 0; i < this.size; ++i) {
|
|
149
|
+
if (this.fds[i] == null) {
|
|
150
|
+
index = i;
|
|
151
|
+
break;
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
let entry;
|
|
156
|
+
if (mappedPath === '<stdout>') {
|
|
157
|
+
entry = new StandardOutput((_a = this.print) !== null && _a !== void 0 ? _a : console.log, index, fd, mappedPath, realPath, type, rightsBase, rightsInheriting, preopen);
|
|
158
|
+
}
|
|
159
|
+
else if (mappedPath === '<stderr>') {
|
|
160
|
+
entry = new StandardOutput((_b = this.printErr) !== null && _b !== void 0 ? _b : console.error, index, fd, mappedPath, realPath, type, rightsBase, rightsInheriting, preopen);
|
|
161
|
+
}
|
|
162
|
+
else {
|
|
163
|
+
entry = new FileDescriptor(index, fd, mappedPath, realPath, type, rightsBase, rightsInheriting, preopen);
|
|
164
|
+
}
|
|
165
|
+
this.fds[index] = entry;
|
|
166
|
+
this.used++;
|
|
167
|
+
return entry;
|
|
168
|
+
}
|
|
169
|
+
get(id, base, inheriting) {
|
|
170
|
+
if (id >= this.size) {
|
|
171
|
+
throw new error_1.WasiError('Invalid fd', types_1.WasiErrno.EBADF);
|
|
172
|
+
}
|
|
173
|
+
const entry = this.fds[id];
|
|
174
|
+
if (!entry || entry.id !== id) {
|
|
175
|
+
throw new error_1.WasiError('Bad file descriptor', types_1.WasiErrno.EBADF);
|
|
176
|
+
}
|
|
177
|
+
/* Validate that the fd has the necessary rights. */
|
|
178
|
+
if ((~entry.rightsBase & base) !== BigInt(0) || (~entry.rightsInheriting & inheriting) !== BigInt(0)) {
|
|
179
|
+
throw new error_1.WasiError('Capabilities insufficient', types_1.WasiErrno.ENOTCAPABLE);
|
|
180
|
+
}
|
|
181
|
+
return entry;
|
|
182
|
+
}
|
|
183
|
+
remove(id) {
|
|
184
|
+
if (id >= this.size) {
|
|
185
|
+
throw new error_1.WasiError('Invalid fd', types_1.WasiErrno.EBADF);
|
|
186
|
+
}
|
|
187
|
+
const entry = this.fds[id];
|
|
188
|
+
if (!entry || entry.id !== id) {
|
|
189
|
+
throw new error_1.WasiError('Bad file descriptor', types_1.WasiErrno.EBADF);
|
|
190
|
+
}
|
|
191
|
+
this.fds[id] = undefined;
|
|
192
|
+
this.used--;
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
exports.FileDescriptorTable = FileDescriptorTable;
|
|
196
|
+
class SyncTable extends FileDescriptorTable {
|
|
197
|
+
constructor(options) {
|
|
198
|
+
super(options);
|
|
199
|
+
this.fs = options.fs;
|
|
200
|
+
}
|
|
201
|
+
getFileTypeByFd(fd) {
|
|
202
|
+
const stats = this.fs.fstatSync(fd, { bigint: true });
|
|
203
|
+
return toFileType(stats);
|
|
204
|
+
}
|
|
205
|
+
insertPreopen(fd, mappedPath, realPath) {
|
|
206
|
+
const type = this.getFileTypeByFd(fd);
|
|
207
|
+
if (type !== types_1.WasiFileType.DIRECTORY) {
|
|
208
|
+
throw new error_1.WasiError(`Preopen not dir: ["${mappedPath}", "${realPath}"]`, types_1.WasiErrno.ENOTDIR);
|
|
209
|
+
}
|
|
210
|
+
const result = (0, rights_1.getRights)(this.stdio, fd, 0, type);
|
|
211
|
+
return this.insert(fd, mappedPath, realPath, type, result.base, result.inheriting, 1);
|
|
212
|
+
}
|
|
213
|
+
renumber(dst, src) {
|
|
214
|
+
if (dst === src)
|
|
215
|
+
return;
|
|
216
|
+
if (dst >= this.size || src >= this.size) {
|
|
217
|
+
throw new error_1.WasiError('Invalid fd', types_1.WasiErrno.EBADF);
|
|
218
|
+
}
|
|
219
|
+
const dstEntry = this.fds[dst];
|
|
220
|
+
const srcEntry = this.fds[src];
|
|
221
|
+
if (!dstEntry || !srcEntry || dstEntry.id !== dst || srcEntry.id !== src) {
|
|
222
|
+
throw new error_1.WasiError('Invalid fd', types_1.WasiErrno.EBADF);
|
|
223
|
+
}
|
|
224
|
+
this.fs.closeSync(dstEntry.fd);
|
|
225
|
+
this.fds[dst] = this.fds[src];
|
|
226
|
+
this.fds[dst].id = dst;
|
|
227
|
+
this.fds[src] = undefined;
|
|
228
|
+
this.used--;
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
exports.SyncTable = SyncTable;
|
|
232
|
+
class AsyncTable extends FileDescriptorTable {
|
|
233
|
+
// eslint-disable-next-line @typescript-eslint/no-useless-constructor
|
|
234
|
+
constructor(options) {
|
|
235
|
+
super(options);
|
|
236
|
+
}
|
|
237
|
+
async getFileTypeByFd(fd) {
|
|
238
|
+
const stats = await fd.stat({ bigint: true });
|
|
239
|
+
return toFileType(stats);
|
|
240
|
+
}
|
|
241
|
+
async insertPreopen(fd, mappedPath, realPath) {
|
|
242
|
+
const type = await this.getFileTypeByFd(fd);
|
|
243
|
+
if (type !== types_1.WasiFileType.DIRECTORY) {
|
|
244
|
+
throw new error_1.WasiError(`Preopen not dir: ["${mappedPath}", "${realPath}"]`, types_1.WasiErrno.ENOTDIR);
|
|
245
|
+
}
|
|
246
|
+
const result = (0, rights_1.getRights)(this.stdio, fd.fd, 0, type);
|
|
247
|
+
return this.insert(fd, mappedPath, realPath, type, result.base, result.inheriting, 1);
|
|
248
|
+
}
|
|
249
|
+
async renumber(dst, src) {
|
|
250
|
+
if (dst === src)
|
|
251
|
+
return;
|
|
252
|
+
if (dst >= this.size || src >= this.size) {
|
|
253
|
+
throw new error_1.WasiError('Invalid fd', types_1.WasiErrno.EBADF);
|
|
254
|
+
}
|
|
255
|
+
const dstEntry = this.fds[dst];
|
|
256
|
+
const srcEntry = this.fds[src];
|
|
257
|
+
if (!dstEntry || !srcEntry || dstEntry.id !== dst || srcEntry.id !== src) {
|
|
258
|
+
throw new error_1.WasiError('Invalid fd', types_1.WasiErrno.EBADF);
|
|
259
|
+
}
|
|
260
|
+
await dstEntry.fd.close();
|
|
261
|
+
this.fds[dst] = this.fds[src];
|
|
262
|
+
this.fds[dst].id = dst;
|
|
263
|
+
this.fds[src] = undefined;
|
|
264
|
+
this.used--;
|
|
265
|
+
}
|
|
266
|
+
}
|
|
267
|
+
exports.AsyncTable = AsyncTable;
|
|
268
|
+
//# sourceMappingURL=fd.js.map
|
|
@@ -0,0 +1,192 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.createAsyncWASI = exports.WASI = void 0;
|
|
4
|
+
const preview1_1 = require("./preview1");
|
|
5
|
+
const util_1 = require("./util");
|
|
6
|
+
// eslint-disable-next-line spaced-comment
|
|
7
|
+
const kEmptyObject = /*#__PURE__*/ Object.freeze(/*#__PURE__*/ Object.create(null));
|
|
8
|
+
const kExitCode = Symbol('kExitCode');
|
|
9
|
+
const kSetMemory = Symbol('kSetMemory');
|
|
10
|
+
const kStarted = Symbol('kStarted');
|
|
11
|
+
const kInstance = Symbol('kInstance');
|
|
12
|
+
const kBindingName = Symbol('kBindingName');
|
|
13
|
+
function validateOptions(options) {
|
|
14
|
+
var _a;
|
|
15
|
+
(0, util_1.validateObject)(options, 'options');
|
|
16
|
+
let _WASI;
|
|
17
|
+
if (options.version !== undefined) {
|
|
18
|
+
(0, util_1.validateString)(options.version, 'options.version');
|
|
19
|
+
switch (options.version) {
|
|
20
|
+
case 'unstable':
|
|
21
|
+
_WASI = preview1_1.WASI;
|
|
22
|
+
this[kBindingName] = 'wasi_unstable';
|
|
23
|
+
break;
|
|
24
|
+
case 'preview1':
|
|
25
|
+
_WASI = preview1_1.WASI;
|
|
26
|
+
this[kBindingName] = 'wasi_snapshot_preview1';
|
|
27
|
+
break;
|
|
28
|
+
default:
|
|
29
|
+
throw new TypeError(`unsupported WASI version "${options.version}"`);
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
else {
|
|
33
|
+
_WASI = preview1_1.WASI;
|
|
34
|
+
this[kBindingName] = 'wasi_snapshot_preview1';
|
|
35
|
+
}
|
|
36
|
+
if (options.args !== undefined) {
|
|
37
|
+
(0, util_1.validateArray)(options.args, 'options.args');
|
|
38
|
+
}
|
|
39
|
+
const args = ((_a = options.args) !== null && _a !== void 0 ? _a : []).map(String);
|
|
40
|
+
const env = [];
|
|
41
|
+
if (options.env !== undefined) {
|
|
42
|
+
(0, util_1.validateObject)(options.env, 'options.env');
|
|
43
|
+
Object.entries(options.env).forEach(({ 0: key, 1: value }) => {
|
|
44
|
+
if (value !== undefined) {
|
|
45
|
+
env.push(`${key}=${value}`);
|
|
46
|
+
}
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
const preopens = [];
|
|
50
|
+
if (options.preopens !== undefined) {
|
|
51
|
+
(0, util_1.validateObject)(options.preopens, 'options.preopens');
|
|
52
|
+
Object.entries(options.preopens).forEach(({ 0: key, 1: value }) => preopens.push({ mappedPath: String(key), realPath: String(value) }));
|
|
53
|
+
}
|
|
54
|
+
if (preopens.length > 0) {
|
|
55
|
+
if (options.fs === undefined) {
|
|
56
|
+
throw new Error('filesystem is disabled, can not preopen directory');
|
|
57
|
+
}
|
|
58
|
+
try {
|
|
59
|
+
(0, util_1.validateObject)(options.fs, 'options.fs');
|
|
60
|
+
}
|
|
61
|
+
catch (_) {
|
|
62
|
+
throw new TypeError('Node.js fs like implementation is not provided');
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
// if (options.filesystem !== undefined) {
|
|
66
|
+
// validateObject(options.filesystem, 'options.filesystem')
|
|
67
|
+
// validateString(options.filesystem.type, 'options.filesystem.type')
|
|
68
|
+
// if (options.filesystem.type !== 'memfs' && options.filesystem.type !== 'file-system-access-api') {
|
|
69
|
+
// throw new Error(`Filesystem type ${(options.filesystem as any).type as string} is not supported, only "memfs" and "file-system-access-api" is supported currently`)
|
|
70
|
+
// }
|
|
71
|
+
// try {
|
|
72
|
+
// validateObject(options.filesystem.fs, 'options.filesystem.fs')
|
|
73
|
+
// } catch (_) {
|
|
74
|
+
// throw new Error('Node.js fs like implementation is not provided')
|
|
75
|
+
// }
|
|
76
|
+
// }
|
|
77
|
+
if (options.print !== undefined)
|
|
78
|
+
(0, util_1.validateFunction)(options.print, 'options.print');
|
|
79
|
+
if (options.printErr !== undefined)
|
|
80
|
+
(0, util_1.validateFunction)(options.printErr, 'options.printErr');
|
|
81
|
+
if (options.returnOnExit !== undefined) {
|
|
82
|
+
(0, util_1.validateBoolean)(options.returnOnExit, 'options.returnOnExit');
|
|
83
|
+
}
|
|
84
|
+
// const { stdin = 0, stdout = 1, stderr = 2 } = options
|
|
85
|
+
// validateInt32(stdin, 'options.stdin', 0)
|
|
86
|
+
// validateInt32(stdout, 'options.stdout', 0)
|
|
87
|
+
// validateInt32(stderr, 'options.stderr', 0)
|
|
88
|
+
// const stdio = [stdin, stdout, stderr] as const
|
|
89
|
+
const stdio = [0, 1, 2];
|
|
90
|
+
return {
|
|
91
|
+
args,
|
|
92
|
+
env,
|
|
93
|
+
preopens,
|
|
94
|
+
stdio,
|
|
95
|
+
_WASI
|
|
96
|
+
};
|
|
97
|
+
}
|
|
98
|
+
function initWASI(setMemory, wrap) {
|
|
99
|
+
this[kSetMemory] = setMemory;
|
|
100
|
+
this.wasiImport = wrap;
|
|
101
|
+
this[kStarted] = false;
|
|
102
|
+
this[kExitCode] = 0;
|
|
103
|
+
this[kInstance] = undefined;
|
|
104
|
+
}
|
|
105
|
+
/** @public */
|
|
106
|
+
class WASI {
|
|
107
|
+
constructor(options = kEmptyObject) {
|
|
108
|
+
const { args, env, preopens, stdio, _WASI } = validateOptions.call(this, options);
|
|
109
|
+
const wrap = _WASI.createSync(args, env, preopens, stdio, options.fs, options.print, options.printErr);
|
|
110
|
+
const setMemory = wrap._setMemory;
|
|
111
|
+
delete wrap._setMemory;
|
|
112
|
+
initWASI.call(this, setMemory, wrap);
|
|
113
|
+
if (options.returnOnExit) {
|
|
114
|
+
wrap.proc_exit = wasiReturnOnProcExit.bind(this);
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
finalizeBindings(instance, _a) {
|
|
118
|
+
var _b;
|
|
119
|
+
var { memory = (_b = instance === null || instance === void 0 ? void 0 : instance.exports) === null || _b === void 0 ? void 0 : _b.memory } = _a === void 0 ? {} : _a;
|
|
120
|
+
if (this[kStarted]) {
|
|
121
|
+
throw new Error('WASI instance has already started');
|
|
122
|
+
}
|
|
123
|
+
(0, util_1.validateObject)(instance, 'instance');
|
|
124
|
+
(0, util_1.validateObject)(instance.exports, 'instance.exports');
|
|
125
|
+
this[kSetMemory](memory);
|
|
126
|
+
this[kInstance] = instance;
|
|
127
|
+
this[kStarted] = true;
|
|
128
|
+
}
|
|
129
|
+
// Must not export _initialize, must export _start
|
|
130
|
+
start(instance) {
|
|
131
|
+
this.finalizeBindings(instance);
|
|
132
|
+
const { _start, _initialize } = this[kInstance].exports;
|
|
133
|
+
(0, util_1.validateFunction)(_start, 'instance.exports._start');
|
|
134
|
+
(0, util_1.validateUndefined)(_initialize, 'instance.exports._initialize');
|
|
135
|
+
let ret;
|
|
136
|
+
try {
|
|
137
|
+
ret = _start();
|
|
138
|
+
}
|
|
139
|
+
catch (err) {
|
|
140
|
+
if (err !== kExitCode) {
|
|
141
|
+
throw err;
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
if (ret instanceof Promise) {
|
|
145
|
+
return ret.then(() => this[kExitCode], (err) => {
|
|
146
|
+
if (err !== kExitCode) {
|
|
147
|
+
throw err;
|
|
148
|
+
}
|
|
149
|
+
return this[kExitCode];
|
|
150
|
+
});
|
|
151
|
+
}
|
|
152
|
+
return this[kExitCode];
|
|
153
|
+
}
|
|
154
|
+
// Must not export _start, may optionally export _initialize
|
|
155
|
+
initialize(instance) {
|
|
156
|
+
this.finalizeBindings(instance);
|
|
157
|
+
const { _start, _initialize } = this[kInstance].exports;
|
|
158
|
+
(0, util_1.validateUndefined)(_start, 'instance.exports._start');
|
|
159
|
+
if (_initialize !== undefined) {
|
|
160
|
+
(0, util_1.validateFunction)(_initialize, 'instance.exports._initialize');
|
|
161
|
+
return _initialize();
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
getImportObject() {
|
|
165
|
+
return { [this[kBindingName]]: this.wasiImport };
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
exports.WASI = WASI;
|
|
169
|
+
function wasiReturnOnProcExit(rval) {
|
|
170
|
+
this[kExitCode] = rval;
|
|
171
|
+
// eslint-disable-next-line @typescript-eslint/no-throw-literal
|
|
172
|
+
throw kExitCode;
|
|
173
|
+
}
|
|
174
|
+
/** @public */
|
|
175
|
+
async function createAsyncWASI(options = kEmptyObject) {
|
|
176
|
+
const _this = Object.create(WASI.prototype);
|
|
177
|
+
const { args, env, preopens, stdio, _WASI } = validateOptions.call(_this, options);
|
|
178
|
+
if (options.asyncify !== undefined) {
|
|
179
|
+
(0, util_1.validateObject)(options.asyncify, 'options.asyncify');
|
|
180
|
+
(0, util_1.validateFunction)(options.asyncify.wrapImportFunction, 'options.asyncify.wrapImportFunction');
|
|
181
|
+
}
|
|
182
|
+
const wrap = await _WASI.createAsync(args, env, preopens, stdio, options.fs, options.print, options.printErr, options.asyncify);
|
|
183
|
+
const setMemory = wrap._setMemory;
|
|
184
|
+
delete wrap._setMemory;
|
|
185
|
+
initWASI.call(_this, setMemory, wrap);
|
|
186
|
+
if (options.returnOnExit) {
|
|
187
|
+
wrap.proc_exit = wasiReturnOnProcExit.bind(_this);
|
|
188
|
+
}
|
|
189
|
+
return _this;
|
|
190
|
+
}
|
|
191
|
+
exports.createAsyncWASI = createAsyncWASI;
|
|
192
|
+
//# sourceMappingURL=index.js.map
|