@nostale/cli 0.1.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/LICENSE +21 -0
- package/README.md +36 -0
- package/assets/docker-compose.server.yml +70 -0
- package/dist/commands/config/generation.js +23 -0
- package/dist/commands/config/providers.js +138 -0
- package/dist/commands/config/sources.js +145 -0
- package/dist/commands/config/templates.js +117 -0
- package/dist/commands/config/tokens.js +83 -0
- package/dist/commands/config.js +43 -0
- package/dist/commands/doctor.js +98 -0
- package/dist/commands/setup.js +5 -0
- package/dist/commands/start.js +23 -0
- package/dist/commands/status.js +17 -0
- package/dist/commands/stop.js +16 -0
- package/dist/index.js +23 -0
- package/dist/lib/api-config.js +21 -0
- package/dist/lib/env-writer.js +41 -0
- package/dist/lib/http.js +117 -0
- package/dist/lib/install-root.js +75 -0
- package/dist/lib/paths.js +12 -0
- package/dist/lib/ports.js +19 -0
- package/dist/lib/process-manager.js +151 -0
- package/dist/lib/repo-root.js +34 -0
- package/dist/lib/wizard.js +267 -0
- package/dist/tui/prompts.js +54 -0
- package/package.json +69 -0
- package/services/mcp-server/index.cjs +48326 -0
- package/services/migrations/001_init_rag_v1.sql +128 -0
- package/services/migrations/002_doc_lifecycle.sql +96 -0
- package/services/migrations/004_mcp_tokens.sql +11 -0
- package/services/migrations/005_settings.sql +28 -0
- package/services/migrations/006_document_sources.sql +14 -0
- package/services/migrations/007_generation_settings.sql +9 -0
- package/services/migrations/008_llm_provider_configs_unique.sql +5 -0
- package/services/wasm/tree-sitter-c.wasm +0 -0
- package/services/wasm/tree-sitter-c_sharp.wasm +0 -0
- package/services/wasm/tree-sitter-cpp.wasm +0 -0
- package/services/wasm/tree-sitter-dart.wasm +0 -0
- package/services/wasm/tree-sitter-go.wasm +0 -0
- package/services/wasm/tree-sitter-java.wasm +0 -0
- package/services/wasm/tree-sitter-javascript.wasm +0 -0
- package/services/wasm/tree-sitter-kotlin.wasm +0 -0
- package/services/wasm/tree-sitter-php.wasm +0 -0
- package/services/wasm/tree-sitter-python.wasm +0 -0
- package/services/wasm/tree-sitter-rust.wasm +0 -0
- package/services/wasm/tree-sitter-tsx.wasm +0 -0
- package/services/wasm/tree-sitter-typescript.wasm +0 -0
- package/services/wasm/tree-sitter.wasm +0 -0
- package/services/wiki-api/index.cjs +82370 -0
- package/services/wiki-web/.output/nitro.json +15 -0
- package/services/wiki-web/.output/public/_nuxt/68caad34b1e80fa12b3a.4Cpu5VkB.woff +0 -0
- package/services/wiki-web/.output/public/_nuxt/6b042d50787d4a81d659.D7JGeKLp.svg +1835 -0
- package/services/wiki-web/.output/public/_nuxt/9065bfe481020b04b68a.CMveUrS1.woff2 +0 -0
- package/services/wiki-web/.output/public/_nuxt/B5j-AdCY.js +1 -0
- package/services/wiki-web/.output/public/_nuxt/BAgZ2ZFT.js +1 -0
- package/services/wiki-web/.output/public/_nuxt/BcxnhBGC.js +1 -0
- package/services/wiki-web/.output/public/_nuxt/BeIDAJKt.js +1 -0
- package/services/wiki-web/.output/public/_nuxt/BebqDWPm.js +1 -0
- package/services/wiki-web/.output/public/_nuxt/CFx_Wb7e.js +1 -0
- package/services/wiki-web/.output/public/_nuxt/CSEkmdhK.js +1 -0
- package/services/wiki-web/.output/public/_nuxt/CXYMfke_.js +1 -0
- package/services/wiki-web/.output/public/_nuxt/Cap3hpB7.js +1 -0
- package/services/wiki-web/.output/public/_nuxt/Ckd7UvSj.js +3 -0
- package/services/wiki-web/.output/public/_nuxt/D0DJQL09.js +1 -0
- package/services/wiki-web/.output/public/_nuxt/DRDlUXmk.js +66 -0
- package/services/wiki-web/.output/public/_nuxt/DW42QLqA.js +1 -0
- package/services/wiki-web/.output/public/_nuxt/DdDtdYim.js +1 -0
- package/services/wiki-web/.output/public/_nuxt/Dm1y7TW1.js +1 -0
- package/services/wiki-web/.output/public/_nuxt/DptiLPkM.js +4 -0
- package/services/wiki-web/.output/public/_nuxt/QFl-TMXl.js +1 -0
- package/services/wiki-web/.output/public/_nuxt/_id_.JvKV2jiN.css +1 -0
- package/services/wiki-web/.output/public/_nuxt/a9c9056a643325579e2a.CCNAgZDa.ttf +0 -0
- package/services/wiki-web/.output/public/_nuxt/bojElwT6.js +1 -0
- package/services/wiki-web/.output/public/_nuxt/builds/latest.json +1 -0
- package/services/wiki-web/.output/public/_nuxt/builds/meta/f68e5546-2919-478b-b4ad-702826e8383c.json +1 -0
- package/services/wiki-web/.output/public/_nuxt/d495aba62101f856c80f.DJ4Lg1TH.eot +0 -0
- package/services/wiki-web/.output/public/_nuxt/entry.isoIPAS3.css +1 -0
- package/services/wiki-web/.output/public/_nuxt/f8QtLg7g.js +1 -0
- package/services/wiki-web/.output/public/_nuxt/nhMvlSQm.js +1 -0
- package/services/wiki-web/.output/public/_nuxt/pFBugkEL.js +1 -0
- package/services/wiki-web/.output/public/_nuxt/plus-jakarta-sans-latin-ext-wght-normal.DmpS2jIq.woff2 +0 -0
- package/services/wiki-web/.output/public/_nuxt/plus-jakarta-sans-latin-wght-normal.eXO_dkmS.woff2 +0 -0
- package/services/wiki-web/.output/public/_nuxt/plus-jakarta-sans-vietnamese-wght-normal.qRpaaN48.woff2 +0 -0
- package/services/wiki-web/.output/public/favicon.svg +6 -0
- package/services/wiki-web/.output/public/robots.txt +2 -0
- package/services/wiki-web/.output/server/chunks/_/error-500.mjs +19 -0
- package/services/wiki-web/.output/server/chunks/_/error-500.mjs.map +1 -0
- package/services/wiki-web/.output/server/chunks/build/client.precomputed.mjs +4 -0
- package/services/wiki-web/.output/server/chunks/build/client.precomputed.mjs.map +1 -0
- package/services/wiki-web/.output/server/chunks/nitro/nitro.mjs +5352 -0
- package/services/wiki-web/.output/server/chunks/nitro/nitro.mjs.map +1 -0
- package/services/wiki-web/.output/server/chunks/routes/api-proxy/_...path_.mjs +34 -0
- package/services/wiki-web/.output/server/chunks/routes/api-proxy/_...path_.mjs.map +1 -0
- package/services/wiki-web/.output/server/chunks/routes/renderer.mjs +369 -0
- package/services/wiki-web/.output/server/chunks/routes/renderer.mjs.map +1 -0
- package/services/wiki-web/.output/server/chunks/virtual/_virtual_spa-template.mjs +4 -0
- package/services/wiki-web/.output/server/chunks/virtual/_virtual_spa-template.mjs.map +1 -0
- package/services/wiki-web/.output/server/index.mjs +10 -0
- package/services/wiki-web/.output/server/index.mjs.map +1 -0
- package/services/wiki-web/.output/server/node_modules/@babel/parser/lib/index.js +14599 -0
- package/services/wiki-web/.output/server/node_modules/@babel/parser/package.json +50 -0
- package/services/wiki-web/.output/server/node_modules/@vue/compiler-core/dist/compiler-core.cjs.prod.js +6759 -0
- package/services/wiki-web/.output/server/node_modules/@vue/compiler-core/package.json +58 -0
- package/services/wiki-web/.output/server/node_modules/@vue/compiler-dom/dist/compiler-dom.cjs.prod.js +689 -0
- package/services/wiki-web/.output/server/node_modules/@vue/compiler-dom/package.json +57 -0
- package/services/wiki-web/.output/server/node_modules/@vue/compiler-ssr/dist/compiler-ssr.cjs.js +1413 -0
- package/services/wiki-web/.output/server/node_modules/@vue/compiler-ssr/package.json +34 -0
- package/services/wiki-web/.output/server/node_modules/@vue/reactivity/dist/reactivity.cjs.prod.js +1899 -0
- package/services/wiki-web/.output/server/node_modules/@vue/reactivity/package.json +55 -0
- package/services/wiki-web/.output/server/node_modules/@vue/runtime-core/dist/runtime-core.cjs.prod.js +6940 -0
- package/services/wiki-web/.output/server/node_modules/@vue/runtime-core/package.json +52 -0
- package/services/wiki-web/.output/server/node_modules/@vue/runtime-dom/dist/runtime-dom.cjs.prod.js +1822 -0
- package/services/wiki-web/.output/server/node_modules/@vue/runtime-dom/package.json +60 -0
- package/services/wiki-web/.output/server/node_modules/@vue/server-renderer/dist/server-renderer.cjs.prod.js +896 -0
- package/services/wiki-web/.output/server/node_modules/@vue/server-renderer/package.json +55 -0
- package/services/wiki-web/.output/server/node_modules/@vue/shared/dist/shared.cjs.prod.js +604 -0
- package/services/wiki-web/.output/server/node_modules/@vue/shared/package.json +47 -0
- package/services/wiki-web/.output/server/node_modules/devalue/index.js +4 -0
- package/services/wiki-web/.output/server/node_modules/devalue/package.json +40 -0
- package/services/wiki-web/.output/server/node_modules/devalue/src/base64.js +60 -0
- package/services/wiki-web/.output/server/node_modules/devalue/src/constants.js +12 -0
- package/services/wiki-web/.output/server/node_modules/devalue/src/parse.js +283 -0
- package/services/wiki-web/.output/server/node_modules/devalue/src/stringify.js +401 -0
- package/services/wiki-web/.output/server/node_modules/devalue/src/uneval.js +552 -0
- package/services/wiki-web/.output/server/node_modules/devalue/src/utils.js +160 -0
- package/services/wiki-web/.output/server/node_modules/entities/dist/commonjs/decode-codepoint.js +77 -0
- package/services/wiki-web/.output/server/node_modules/entities/dist/commonjs/decode.js +568 -0
- package/services/wiki-web/.output/server/node_modules/entities/dist/commonjs/generated/decode-data-html.js +7 -0
- package/services/wiki-web/.output/server/node_modules/entities/dist/commonjs/generated/decode-data-xml.js +7 -0
- package/services/wiki-web/.output/server/node_modules/entities/dist/commonjs/internal/bin-trie-flags.js +21 -0
- package/services/wiki-web/.output/server/node_modules/entities/dist/commonjs/internal/decode-shared.js +31 -0
- package/services/wiki-web/.output/server/node_modules/entities/dist/commonjs/package.json +3 -0
- package/services/wiki-web/.output/server/node_modules/entities/package.json +120 -0
- package/services/wiki-web/.output/server/node_modules/estree-walker/dist/umd/estree-walker.js +344 -0
- package/services/wiki-web/.output/server/node_modules/estree-walker/package.json +37 -0
- package/services/wiki-web/.output/server/node_modules/hookable/dist/index.mjs +257 -0
- package/services/wiki-web/.output/server/node_modules/hookable/package.json +53 -0
- package/services/wiki-web/.output/server/node_modules/source-map-js/lib/array-set.js +121 -0
- package/services/wiki-web/.output/server/node_modules/source-map-js/lib/base64-vlq.js +140 -0
- package/services/wiki-web/.output/server/node_modules/source-map-js/lib/base64.js +67 -0
- package/services/wiki-web/.output/server/node_modules/source-map-js/lib/binary-search.js +111 -0
- package/services/wiki-web/.output/server/node_modules/source-map-js/lib/mapping-list.js +79 -0
- package/services/wiki-web/.output/server/node_modules/source-map-js/lib/quick-sort.js +132 -0
- package/services/wiki-web/.output/server/node_modules/source-map-js/lib/source-map-consumer.js +1188 -0
- package/services/wiki-web/.output/server/node_modules/source-map-js/lib/source-map-generator.js +444 -0
- package/services/wiki-web/.output/server/node_modules/source-map-js/lib/source-node.js +413 -0
- package/services/wiki-web/.output/server/node_modules/source-map-js/lib/util.js +594 -0
- package/services/wiki-web/.output/server/node_modules/source-map-js/package.json +71 -0
- package/services/wiki-web/.output/server/node_modules/source-map-js/source-map.js +8 -0
- package/services/wiki-web/.output/server/node_modules/ufo/dist/index.mjs +645 -0
- package/services/wiki-web/.output/server/node_modules/ufo/package.json +48 -0
- package/services/wiki-web/.output/server/node_modules/unhead/dist/parser.mjs +508 -0
- package/services/wiki-web/.output/server/node_modules/unhead/dist/plugins.mjs +101 -0
- package/services/wiki-web/.output/server/node_modules/unhead/dist/server.mjs +180 -0
- package/services/wiki-web/.output/server/node_modules/unhead/dist/shared/unhead.B3VbJo7Y.mjs +207 -0
- package/services/wiki-web/.output/server/node_modules/unhead/dist/shared/unhead.BYvz9V1x.mjs +43 -0
- package/services/wiki-web/.output/server/node_modules/unhead/dist/shared/unhead.CaI5ZD4O.mjs +182 -0
- package/services/wiki-web/.output/server/node_modules/unhead/dist/shared/unhead.CbpEuj3y.mjs +71 -0
- package/services/wiki-web/.output/server/node_modules/unhead/dist/shared/unhead.D4vSFytZ.mjs +236 -0
- package/services/wiki-web/.output/server/node_modules/unhead/dist/shared/unhead.DQc16pHI.mjs +196 -0
- package/services/wiki-web/.output/server/node_modules/unhead/dist/shared/unhead.TxTMM7cM.mjs +166 -0
- package/services/wiki-web/.output/server/node_modules/unhead/dist/shared/unhead.yem5I2v_.mjs +38 -0
- package/services/wiki-web/.output/server/node_modules/unhead/dist/utils.mjs +5 -0
- package/services/wiki-web/.output/server/node_modules/unhead/package.json +105 -0
- package/services/wiki-web/.output/server/node_modules/vue/dist/vue.cjs.js +80 -0
- package/services/wiki-web/.output/server/node_modules/vue/dist/vue.cjs.prod.js +66 -0
- package/services/wiki-web/.output/server/node_modules/vue/index.js +7 -0
- package/services/wiki-web/.output/server/node_modules/vue/index.mjs +1 -0
- package/services/wiki-web/.output/server/node_modules/vue/package.json +112 -0
- package/services/wiki-web/.output/server/node_modules/vue/server-renderer/index.mjs +1 -0
- package/services/wiki-web/.output/server/node_modules/vue-bundle-renderer/dist/runtime.mjs +249 -0
- package/services/wiki-web/.output/server/node_modules/vue-bundle-renderer/package.json +57 -0
- package/services/wiki-web/.output/server/package.json +26 -0
- package/services/wiki-worker/index.cjs +66661 -0
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@vue/shared",
|
|
3
|
+
"version": "3.5.39",
|
|
4
|
+
"description": "internal utils shared across @vue packages",
|
|
5
|
+
"main": "index.js",
|
|
6
|
+
"module": "dist/shared.esm-bundler.js",
|
|
7
|
+
"types": "dist/shared.d.ts",
|
|
8
|
+
"files": [
|
|
9
|
+
"index.js",
|
|
10
|
+
"dist"
|
|
11
|
+
],
|
|
12
|
+
"exports": {
|
|
13
|
+
".": {
|
|
14
|
+
"types": "./dist/shared.d.ts",
|
|
15
|
+
"node": {
|
|
16
|
+
"production": "./dist/shared.cjs.prod.js",
|
|
17
|
+
"development": "./dist/shared.cjs.js",
|
|
18
|
+
"default": "./dist/shared.cjs.prod.js"
|
|
19
|
+
},
|
|
20
|
+
"module": "./dist/shared.esm-bundler.js",
|
|
21
|
+
"import": "./dist/shared.esm-bundler.js",
|
|
22
|
+
"require": "./index.js"
|
|
23
|
+
},
|
|
24
|
+
"./*": "./*"
|
|
25
|
+
},
|
|
26
|
+
"sideEffects": false,
|
|
27
|
+
"buildOptions": {
|
|
28
|
+
"formats": [
|
|
29
|
+
"esm-bundler",
|
|
30
|
+
"cjs"
|
|
31
|
+
]
|
|
32
|
+
},
|
|
33
|
+
"repository": {
|
|
34
|
+
"type": "git",
|
|
35
|
+
"url": "git+https://github.com/vuejs/core.git",
|
|
36
|
+
"directory": "packages/shared"
|
|
37
|
+
},
|
|
38
|
+
"keywords": [
|
|
39
|
+
"vue"
|
|
40
|
+
],
|
|
41
|
+
"author": "Evan You",
|
|
42
|
+
"license": "MIT",
|
|
43
|
+
"bugs": {
|
|
44
|
+
"url": "https://github.com/vuejs/core/issues"
|
|
45
|
+
},
|
|
46
|
+
"homepage": "https://github.com/vuejs/core/tree/main/packages/shared#readme"
|
|
47
|
+
}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "devalue",
|
|
3
|
+
"description": "Gets the job done when JSON.stringify can't",
|
|
4
|
+
"version": "5.8.1",
|
|
5
|
+
"repository": "sveltejs/devalue",
|
|
6
|
+
"sideEffects": false,
|
|
7
|
+
"exports": {
|
|
8
|
+
".": {
|
|
9
|
+
"types": "./types/index.d.ts",
|
|
10
|
+
"import": "./index.js",
|
|
11
|
+
"default": "./index.js"
|
|
12
|
+
}
|
|
13
|
+
},
|
|
14
|
+
"files": [
|
|
15
|
+
"index.js",
|
|
16
|
+
"src",
|
|
17
|
+
"types"
|
|
18
|
+
],
|
|
19
|
+
"types": "./types/index.d.ts",
|
|
20
|
+
"devDependencies": {
|
|
21
|
+
"@changesets/cli": "^2.29.6",
|
|
22
|
+
"@js-temporal/polyfill": "^0.5.1",
|
|
23
|
+
"@types/node": "^24.12.0",
|
|
24
|
+
"dts-buddy": "^0.6.2",
|
|
25
|
+
"publint": "^0.3.12",
|
|
26
|
+
"typescript": "^5.9.2",
|
|
27
|
+
"uvu": "^0.5.6"
|
|
28
|
+
},
|
|
29
|
+
"license": "MIT",
|
|
30
|
+
"type": "module",
|
|
31
|
+
"packageManager": "pnpm@8.15.9",
|
|
32
|
+
"scripts": {
|
|
33
|
+
"changeset:version": "changeset version",
|
|
34
|
+
"changeset:publish": "changeset publish",
|
|
35
|
+
"build": "dts-buddy",
|
|
36
|
+
"test": "uvu",
|
|
37
|
+
"bench": "node --allow-natives-syntax ./benchmarking/run.js",
|
|
38
|
+
"bench:compare": "node --allow-natives-syntax ./benchmarking/compare/index.js"
|
|
39
|
+
}
|
|
40
|
+
}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
/* Baseline 2025 runtimes */
|
|
2
|
+
|
|
3
|
+
/** @type {(array_buffer: ArrayBuffer) => string} */
|
|
4
|
+
export function encode_native(array_buffer) {
|
|
5
|
+
return new Uint8Array(array_buffer).toBase64();
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
/** @type {(base64: string) => ArrayBuffer} */
|
|
9
|
+
export function decode_native(base64) {
|
|
10
|
+
return Uint8Array.fromBase64(base64).buffer;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
/* Node-compatible runtimes */
|
|
14
|
+
|
|
15
|
+
/** @type {(array_buffer: ArrayBuffer) => string} */
|
|
16
|
+
export function encode_buffer(array_buffer) {
|
|
17
|
+
return Buffer.from(array_buffer).toString('base64');
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
/** @type {(base64: string) => ArrayBuffer} */
|
|
21
|
+
export function decode_buffer(base64) {
|
|
22
|
+
return Uint8Array.from(Buffer.from(base64, 'base64')).buffer;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
/* Legacy runtimes */
|
|
26
|
+
|
|
27
|
+
/** @type {(array_buffer: ArrayBuffer) => string} */
|
|
28
|
+
export function encode_legacy(array_buffer) {
|
|
29
|
+
const array = new Uint8Array(array_buffer);
|
|
30
|
+
let binary = '';
|
|
31
|
+
|
|
32
|
+
// the maximum number of arguments to String.fromCharCode.apply
|
|
33
|
+
// should be around 0xFFFF in modern engines
|
|
34
|
+
const chunk_size = 0x8000;
|
|
35
|
+
for (let i = 0; i < array.length; i += chunk_size) {
|
|
36
|
+
const chunk = array.subarray(i, i + chunk_size);
|
|
37
|
+
binary += String.fromCharCode.apply(null, chunk);
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
return btoa(binary);
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/** @type {(base64: string) => ArrayBuffer} */
|
|
44
|
+
export function decode_legacy(base64) {
|
|
45
|
+
const binary_string = atob(base64);
|
|
46
|
+
const len = binary_string.length;
|
|
47
|
+
const array = new Uint8Array(len);
|
|
48
|
+
|
|
49
|
+
for (let i = 0; i < len; i++) {
|
|
50
|
+
array[i] = binary_string.charCodeAt(i);
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
return array.buffer;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
const native = typeof Uint8Array.fromBase64 === 'function';
|
|
57
|
+
const buffer = typeof process === 'object' && process.versions?.node !== undefined;
|
|
58
|
+
|
|
59
|
+
export const encode64 = native ? encode_native : buffer ? encode_buffer : encode_legacy;
|
|
60
|
+
export const decode64 = native ? decode_native : buffer ? decode_buffer : decode_legacy;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export const UNDEFINED = -1;
|
|
2
|
+
export const HOLE = -2;
|
|
3
|
+
export const NAN = -3;
|
|
4
|
+
export const POSITIVE_INFINITY = -4;
|
|
5
|
+
export const NEGATIVE_INFINITY = -5;
|
|
6
|
+
export const NEGATIVE_ZERO = -6;
|
|
7
|
+
export const SPARSE = -7;
|
|
8
|
+
|
|
9
|
+
// The largest valid value for a JavaScript array's `length` property,
|
|
10
|
+
// and the largest valid array index (one less than the max length).
|
|
11
|
+
export const MAX_ARRAY_LEN = 2 ** 32 - 1;
|
|
12
|
+
export const MAX_ARRAY_INDEX = MAX_ARRAY_LEN - 1;
|
|
@@ -0,0 +1,283 @@
|
|
|
1
|
+
import { decode64 } from './base64.js';
|
|
2
|
+
import {
|
|
3
|
+
HOLE,
|
|
4
|
+
MAX_ARRAY_INDEX,
|
|
5
|
+
NAN,
|
|
6
|
+
NEGATIVE_INFINITY,
|
|
7
|
+
NEGATIVE_ZERO,
|
|
8
|
+
POSITIVE_INFINITY,
|
|
9
|
+
SPARSE,
|
|
10
|
+
UNDEFINED
|
|
11
|
+
} from './constants.js';
|
|
12
|
+
import { is_valid_array_index, is_valid_array_len } from './utils.js';
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Revive a value serialized with `devalue.stringify`
|
|
16
|
+
* @param {string} serialized
|
|
17
|
+
* @param {Record<string, (value: any) => any>} [revivers]
|
|
18
|
+
*/
|
|
19
|
+
export function parse(serialized, revivers) {
|
|
20
|
+
return unflatten(JSON.parse(serialized), revivers);
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* Revive a value flattened with `devalue.stringify`
|
|
25
|
+
* @param {number | any[]} parsed
|
|
26
|
+
* @param {Record<string, (value: any) => any>} [revivers]
|
|
27
|
+
*/
|
|
28
|
+
export function unflatten(parsed, revivers) {
|
|
29
|
+
if (typeof parsed === 'number') return hydrate(parsed, true);
|
|
30
|
+
|
|
31
|
+
if (!Array.isArray(parsed) || parsed.length === 0) {
|
|
32
|
+
throw new Error('Invalid input');
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
const values = /** @type {any[]} */ (parsed);
|
|
36
|
+
|
|
37
|
+
const hydrated = Array(values.length);
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* A set of values currently being hydrated with custom revivers,
|
|
41
|
+
* used to detect invalid cyclical dependencies
|
|
42
|
+
* @type {Set<number> | null}
|
|
43
|
+
*/
|
|
44
|
+
let hydrating = null;
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* @param {number} index
|
|
48
|
+
* @returns {any}
|
|
49
|
+
*/
|
|
50
|
+
function hydrate(index, standalone = false) {
|
|
51
|
+
if (index === UNDEFINED) return undefined;
|
|
52
|
+
if (index === NAN) return NaN;
|
|
53
|
+
if (index === POSITIVE_INFINITY) return Infinity;
|
|
54
|
+
if (index === NEGATIVE_INFINITY) return -Infinity;
|
|
55
|
+
if (index === NEGATIVE_ZERO) return -0;
|
|
56
|
+
|
|
57
|
+
if (standalone || typeof index !== 'number') {
|
|
58
|
+
throw new Error(`Invalid input`);
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
if (index in hydrated) return hydrated[index];
|
|
62
|
+
|
|
63
|
+
const value = values[index];
|
|
64
|
+
|
|
65
|
+
if (!value || typeof value !== 'object') {
|
|
66
|
+
hydrated[index] = value;
|
|
67
|
+
} else if (Array.isArray(value)) {
|
|
68
|
+
if (typeof value[0] === 'string') {
|
|
69
|
+
const type = value[0];
|
|
70
|
+
|
|
71
|
+
const reviver = revivers && Object.hasOwn(revivers, type) ? revivers[type] : undefined;
|
|
72
|
+
|
|
73
|
+
if (reviver) {
|
|
74
|
+
let i = value[1];
|
|
75
|
+
if (typeof i !== 'number') {
|
|
76
|
+
// if it's not a number, it was serialized by a builtin reviver
|
|
77
|
+
// so we need to munge it into the format expected by a custom reviver
|
|
78
|
+
i = values.push(value[1]) - 1;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
hydrating ??= new Set();
|
|
82
|
+
|
|
83
|
+
if (hydrating.has(i)) {
|
|
84
|
+
throw new Error('Invalid circular reference');
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
hydrating.add(i);
|
|
88
|
+
hydrated[index] = reviver(hydrate(i));
|
|
89
|
+
hydrating.delete(i);
|
|
90
|
+
|
|
91
|
+
return hydrated[index];
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
switch (type) {
|
|
95
|
+
case 'Date':
|
|
96
|
+
hydrated[index] = new Date(value[1]);
|
|
97
|
+
break;
|
|
98
|
+
|
|
99
|
+
case 'Set':
|
|
100
|
+
const set = new Set();
|
|
101
|
+
hydrated[index] = set;
|
|
102
|
+
for (let i = 1; i < value.length; i += 1) {
|
|
103
|
+
set.add(hydrate(value[i]));
|
|
104
|
+
}
|
|
105
|
+
break;
|
|
106
|
+
|
|
107
|
+
case 'Map':
|
|
108
|
+
const map = new Map();
|
|
109
|
+
hydrated[index] = map;
|
|
110
|
+
for (let i = 1; i < value.length; i += 2) {
|
|
111
|
+
map.set(hydrate(value[i]), hydrate(value[i + 1]));
|
|
112
|
+
}
|
|
113
|
+
break;
|
|
114
|
+
|
|
115
|
+
case 'RegExp':
|
|
116
|
+
hydrated[index] = new RegExp(value[1], value[2]);
|
|
117
|
+
break;
|
|
118
|
+
|
|
119
|
+
case 'Object': {
|
|
120
|
+
const wrapped_index = value[1];
|
|
121
|
+
|
|
122
|
+
if (
|
|
123
|
+
typeof values[wrapped_index] === 'object' &&
|
|
124
|
+
values[wrapped_index][0] !== 'BigInt'
|
|
125
|
+
) {
|
|
126
|
+
// avoid infinite recusion in case of malformed input
|
|
127
|
+
throw new Error('Invalid input');
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
hydrated[index] = Object(hydrate(wrapped_index));
|
|
131
|
+
break;
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
case 'BigInt':
|
|
135
|
+
hydrated[index] = BigInt(value[1]);
|
|
136
|
+
break;
|
|
137
|
+
|
|
138
|
+
case 'null':
|
|
139
|
+
const obj = Object.create(null);
|
|
140
|
+
hydrated[index] = obj;
|
|
141
|
+
for (let i = 1; i < value.length; i += 2) {
|
|
142
|
+
if (value[i] === '__proto__') {
|
|
143
|
+
throw new Error('Cannot parse an object with a `__proto__` property');
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
obj[value[i]] = hydrate(value[i + 1]);
|
|
147
|
+
}
|
|
148
|
+
break;
|
|
149
|
+
|
|
150
|
+
case 'Int8Array':
|
|
151
|
+
case 'Uint8Array':
|
|
152
|
+
case 'Uint8ClampedArray':
|
|
153
|
+
case 'Int16Array':
|
|
154
|
+
case 'Uint16Array':
|
|
155
|
+
case 'Float16Array':
|
|
156
|
+
case 'Int32Array':
|
|
157
|
+
case 'Uint32Array':
|
|
158
|
+
case 'Float32Array':
|
|
159
|
+
case 'Float64Array':
|
|
160
|
+
case 'BigInt64Array':
|
|
161
|
+
case 'BigUint64Array':
|
|
162
|
+
case 'DataView': {
|
|
163
|
+
if (values[value[1]][0] !== 'ArrayBuffer') {
|
|
164
|
+
// without this, if we receive malformed input we could
|
|
165
|
+
// end up trying to hydrate in a circle or allocate
|
|
166
|
+
// huge amounts of memory when we call `new TypedArrayConstructor(buffer)`
|
|
167
|
+
throw new Error('Invalid data');
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
const TypedArrayConstructor = globalThis[type];
|
|
171
|
+
const buffer = hydrate(value[1]);
|
|
172
|
+
|
|
173
|
+
hydrated[index] =
|
|
174
|
+
value[2] !== undefined
|
|
175
|
+
? new TypedArrayConstructor(buffer, value[2], value[3])
|
|
176
|
+
: new TypedArrayConstructor(buffer);
|
|
177
|
+
|
|
178
|
+
break;
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
case 'ArrayBuffer': {
|
|
182
|
+
const base64 = value[1];
|
|
183
|
+
if (typeof base64 !== 'string') {
|
|
184
|
+
throw new Error('Invalid ArrayBuffer encoding');
|
|
185
|
+
}
|
|
186
|
+
const arraybuffer = decode64(base64);
|
|
187
|
+
hydrated[index] = arraybuffer;
|
|
188
|
+
break;
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
case 'Temporal.Duration':
|
|
192
|
+
case 'Temporal.Instant':
|
|
193
|
+
case 'Temporal.PlainDate':
|
|
194
|
+
case 'Temporal.PlainTime':
|
|
195
|
+
case 'Temporal.PlainDateTime':
|
|
196
|
+
case 'Temporal.PlainMonthDay':
|
|
197
|
+
case 'Temporal.PlainYearMonth':
|
|
198
|
+
case 'Temporal.ZonedDateTime': {
|
|
199
|
+
const temporalName = type.slice(9);
|
|
200
|
+
// @ts-expect-error TS doesn't know about Temporal yet
|
|
201
|
+
hydrated[index] = Temporal[temporalName].from(value[1]);
|
|
202
|
+
break;
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
case 'URL': {
|
|
206
|
+
const url = new URL(value[1]);
|
|
207
|
+
hydrated[index] = url;
|
|
208
|
+
break;
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
case 'URLSearchParams': {
|
|
212
|
+
const url = new URLSearchParams(value[1]);
|
|
213
|
+
hydrated[index] = url;
|
|
214
|
+
break;
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
default:
|
|
218
|
+
throw new Error(`Unknown type ${type}`);
|
|
219
|
+
}
|
|
220
|
+
} else if (value[0] === SPARSE) {
|
|
221
|
+
// Sparse array encoding: [SPARSE, length, idx, val, idx, val, ...]
|
|
222
|
+
const len = value[1];
|
|
223
|
+
|
|
224
|
+
if (!is_valid_array_len(len)) {
|
|
225
|
+
throw new Error('Invalid input');
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
/** @type {any[]} */
|
|
229
|
+
const array = [];
|
|
230
|
+
hydrated[index] = array;
|
|
231
|
+
|
|
232
|
+
// Setting `array.length = len` (or equivalently calling `new Array(len)`)
|
|
233
|
+
// on an untrusted `len` is a DoS vector: V8 eagerly allocates a
|
|
234
|
+
// contiguous backing store for array lengths below ~10^8, so a
|
|
235
|
+
// small payload with a huge declared length can force arbitrary
|
|
236
|
+
// memory allocation. Touching the largest-possible index first
|
|
237
|
+
// forces V8 into dictionary-elements mode, where `length` is
|
|
238
|
+
// just a number and no contiguous allocation occurs.
|
|
239
|
+
array[MAX_ARRAY_INDEX] = undefined;
|
|
240
|
+
delete array[MAX_ARRAY_INDEX];
|
|
241
|
+
|
|
242
|
+
for (let i = 2; i < value.length; i += 2) {
|
|
243
|
+
const idx = value[i];
|
|
244
|
+
|
|
245
|
+
if (!is_valid_array_index(idx) || idx >= len) {
|
|
246
|
+
throw new Error('Invalid input');
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
array[idx] = hydrate(value[i + 1]);
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
array.length = len;
|
|
253
|
+
} else {
|
|
254
|
+
const array = new Array(value.length);
|
|
255
|
+
hydrated[index] = array;
|
|
256
|
+
|
|
257
|
+
for (let i = 0; i < value.length; i += 1) {
|
|
258
|
+
const n = value[i];
|
|
259
|
+
if (n === HOLE) continue;
|
|
260
|
+
|
|
261
|
+
array[i] = hydrate(n);
|
|
262
|
+
}
|
|
263
|
+
}
|
|
264
|
+
} else {
|
|
265
|
+
/** @type {Record<string, any>} */
|
|
266
|
+
const object = {};
|
|
267
|
+
hydrated[index] = object;
|
|
268
|
+
|
|
269
|
+
for (const key of Object.keys(value)) {
|
|
270
|
+
if (key === '__proto__') {
|
|
271
|
+
throw new Error('Cannot parse an object with a `__proto__` property');
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
const n = value[key];
|
|
275
|
+
object[key] = hydrate(n);
|
|
276
|
+
}
|
|
277
|
+
}
|
|
278
|
+
|
|
279
|
+
return hydrated[index];
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
return hydrate(0);
|
|
283
|
+
}
|