fumadocs-openapi 10.6.8 → 10.7.1
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/css/generated/shared.css +0 -1
- package/dist/node_modules/.pnpm/@scalar_helpers@0.4.3/node_modules/@scalar/helpers/dist/general/create-limiter.js +43 -0
- package/dist/node_modules/.pnpm/@scalar_helpers@0.4.3/node_modules/@scalar/helpers/dist/object/is-object.js +26 -0
- package/dist/node_modules/.pnpm/@scalar_helpers@0.4.3/node_modules/@scalar/helpers/dist/object/prevent-pollution.js +33 -0
- package/dist/node_modules/.pnpm/@scalar_helpers@0.4.3/node_modules/@scalar/helpers/dist/queue/queue.js +106 -0
- package/dist/node_modules/.pnpm/@scalar_helpers@0.4.3/node_modules/@scalar/helpers/dist/string/generate-hash.js +120 -0
- package/dist/node_modules/.pnpm/@scalar_json-magic@0.12.5/node_modules/@scalar/json-magic/dist/bundle/bundle.js +346 -0
- package/dist/node_modules/.pnpm/@scalar_json-magic@0.12.5/node_modules/@scalar/json-magic/dist/bundle/plugins/fetch-urls/index.js +73 -0
- package/dist/node_modules/.pnpm/@scalar_json-magic@0.12.5/node_modules/@scalar/json-magic/dist/bundle/plugins/node.js +3 -0
- package/dist/node_modules/.pnpm/@scalar_json-magic@0.12.5/node_modules/@scalar/json-magic/dist/bundle/plugins/parse-yaml/index.js +1 -0
- package/dist/node_modules/.pnpm/@scalar_json-magic@0.12.5/node_modules/@scalar/json-magic/dist/bundle/plugins/read-files/index.js +51 -0
- package/dist/node_modules/.pnpm/@scalar_json-magic@0.12.5/node_modules/@scalar/json-magic/dist/bundle/value-generator.js +88 -0
- package/dist/node_modules/.pnpm/@scalar_json-magic@0.12.5/node_modules/@scalar/json-magic/dist/helpers/convert-to-local-ref.js +24 -0
- package/dist/node_modules/.pnpm/@scalar_json-magic@0.12.5/node_modules/@scalar/json-magic/dist/helpers/escape-json-pointer.js +11 -0
- package/dist/node_modules/.pnpm/@scalar_json-magic@0.12.5/node_modules/@scalar/json-magic/dist/helpers/get-schemas.js +44 -0
- package/dist/node_modules/.pnpm/@scalar_json-magic@0.12.5/node_modules/@scalar/json-magic/dist/helpers/get-segments-from-path.js +10 -0
- package/dist/node_modules/.pnpm/@scalar_json-magic@0.12.5/node_modules/@scalar/json-magic/dist/helpers/get-value-by-path.js +42 -0
- package/dist/node_modules/.pnpm/@scalar_json-magic@0.12.5/node_modules/@scalar/json-magic/dist/helpers/is-file-path.js +23 -0
- package/dist/node_modules/.pnpm/@scalar_json-magic@0.12.5/node_modules/@scalar/json-magic/dist/helpers/is-http-url.js +23 -0
- package/dist/node_modules/.pnpm/@scalar_json-magic@0.12.5/node_modules/@scalar/json-magic/dist/helpers/is-json-object.js +28 -0
- package/dist/node_modules/.pnpm/@scalar_json-magic@0.12.5/node_modules/@scalar/json-magic/dist/helpers/is-yaml.js +21 -0
- package/dist/node_modules/.pnpm/@scalar_json-magic@0.12.5/node_modules/@scalar/json-magic/dist/helpers/normalize.js +26 -0
- package/dist/node_modules/.pnpm/@scalar_json-magic@0.12.5/node_modules/@scalar/json-magic/dist/helpers/resolve-reference-path.js +30 -0
- package/dist/node_modules/.pnpm/@scalar_json-magic@0.12.5/node_modules/@scalar/json-magic/dist/helpers/set-value-at-path.js +70 -0
- package/dist/node_modules/.pnpm/@scalar_json-magic@0.12.5/node_modules/@scalar/json-magic/dist/helpers/to-relative-path.js +33 -0
- package/dist/node_modules/.pnpm/@scalar_json-magic@0.12.5/node_modules/@scalar/json-magic/dist/helpers/unescape-json-pointer.js +12 -0
- package/dist/node_modules/.pnpm/@scalar_openapi-upgrader@0.2.4/node_modules/@scalar/openapi-upgrader/dist/2.0-to-3.0/upgrade-from-two-to-three.js +487 -0
- package/dist/node_modules/.pnpm/@scalar_openapi-upgrader@0.2.4/node_modules/@scalar/openapi-upgrader/dist/3.0-to-3.1/upgrade-from-three-to-three-one.js +95 -0
- package/dist/node_modules/.pnpm/@scalar_openapi-upgrader@0.2.4/node_modules/@scalar/openapi-upgrader/dist/3.1-to-3.2/upgrade-from-three-one-to-three-two.js +59 -0
- package/dist/node_modules/.pnpm/@scalar_openapi-upgrader@0.2.4/node_modules/@scalar/openapi-upgrader/dist/helpers/traverse.js +25 -0
- package/dist/node_modules/.pnpm/@scalar_openapi-upgrader@0.2.4/node_modules/@scalar/openapi-upgrader/dist/upgrade.js +15 -0
- package/dist/node_modules/.pnpm/pathe@2.0.3/node_modules/pathe/dist/index.js +19 -0
- package/dist/node_modules/.pnpm/pathe@2.0.3/node_modules/pathe/dist/shared/pathe.M-eThtNZ.js +430 -0
- package/dist/node_modules/.pnpm/yaml@2.8.3/node_modules/yaml/browser/dist/compose/compose-collection.js +50 -0
- package/dist/node_modules/.pnpm/yaml@2.8.3/node_modules/yaml/browser/dist/compose/compose-doc.js +39 -0
- package/dist/node_modules/.pnpm/yaml@2.8.3/node_modules/yaml/browser/dist/compose/compose-node.js +85 -0
- package/dist/node_modules/.pnpm/yaml@2.8.3/node_modules/yaml/browser/dist/compose/compose-scalar.js +57 -0
- package/dist/node_modules/.pnpm/yaml@2.8.3/node_modules/yaml/browser/dist/compose/composer.js +193 -0
- package/dist/node_modules/.pnpm/yaml@2.8.3/node_modules/yaml/browser/dist/compose/resolve-block-map.js +82 -0
- package/dist/node_modules/.pnpm/yaml@2.8.3/node_modules/yaml/browser/dist/compose/resolve-block-scalar.js +174 -0
- package/dist/node_modules/.pnpm/yaml@2.8.3/node_modules/yaml/browser/dist/compose/resolve-block-seq.js +40 -0
- package/dist/node_modules/.pnpm/yaml@2.8.3/node_modules/yaml/browser/dist/compose/resolve-end.js +36 -0
- package/dist/node_modules/.pnpm/yaml@2.8.3/node_modules/yaml/browser/dist/compose/resolve-flow-collection.js +153 -0
- package/dist/node_modules/.pnpm/yaml@2.8.3/node_modules/yaml/browser/dist/compose/resolve-flow-scalar.js +206 -0
- package/dist/node_modules/.pnpm/yaml@2.8.3/node_modules/yaml/browser/dist/compose/resolve-props.js +105 -0
- package/dist/node_modules/.pnpm/yaml@2.8.3/node_modules/yaml/browser/dist/compose/util-contains-newline.js +27 -0
- package/dist/node_modules/.pnpm/yaml@2.8.3/node_modules/yaml/browser/dist/compose/util-empty-scalar-position.js +25 -0
- package/dist/node_modules/.pnpm/yaml@2.8.3/node_modules/yaml/browser/dist/compose/util-flow-indent-check.js +10 -0
- package/dist/node_modules/.pnpm/yaml@2.8.3/node_modules/yaml/browser/dist/compose/util-map-includes.js +10 -0
- package/dist/node_modules/.pnpm/yaml@2.8.3/node_modules/yaml/browser/dist/doc/Document.js +277 -0
- package/dist/node_modules/.pnpm/yaml@2.8.3/node_modules/yaml/browser/dist/doc/anchors.js +57 -0
- package/dist/node_modules/.pnpm/yaml@2.8.3/node_modules/yaml/browser/dist/doc/applyReviver.js +38 -0
- package/dist/node_modules/.pnpm/yaml@2.8.3/node_modules/yaml/browser/dist/doc/createNode.js +61 -0
- package/dist/node_modules/.pnpm/yaml@2.8.3/node_modules/yaml/browser/dist/doc/directives.js +163 -0
- package/dist/node_modules/.pnpm/yaml@2.8.3/node_modules/yaml/browser/dist/errors.js +48 -0
- package/dist/node_modules/.pnpm/yaml@2.8.3/node_modules/yaml/browser/dist/index.js +16 -0
- package/dist/node_modules/.pnpm/yaml@2.8.3/node_modules/yaml/browser/dist/log.js +6 -0
- package/dist/node_modules/.pnpm/yaml@2.8.3/node_modules/yaml/browser/dist/nodes/Alias.js +91 -0
- package/dist/node_modules/.pnpm/yaml@2.8.3/node_modules/yaml/browser/dist/nodes/Collection.js +117 -0
- package/dist/node_modules/.pnpm/yaml@2.8.3/node_modules/yaml/browser/dist/nodes/Node.js +32 -0
- package/dist/node_modules/.pnpm/yaml@2.8.3/node_modules/yaml/browser/dist/nodes/Pair.js +29 -0
- package/dist/node_modules/.pnpm/yaml@2.8.3/node_modules/yaml/browser/dist/nodes/Scalar.js +24 -0
- package/dist/node_modules/.pnpm/yaml@2.8.3/node_modules/yaml/browser/dist/nodes/YAMLMap.js +106 -0
- package/dist/node_modules/.pnpm/yaml@2.8.3/node_modules/yaml/browser/dist/nodes/YAMLSeq.js +104 -0
- package/dist/node_modules/.pnpm/yaml@2.8.3/node_modules/yaml/browser/dist/nodes/addPairToJSMap.js +49 -0
- package/dist/node_modules/.pnpm/yaml@2.8.3/node_modules/yaml/browser/dist/nodes/identity.js +33 -0
- package/dist/node_modules/.pnpm/yaml@2.8.3/node_modules/yaml/browser/dist/nodes/toJS.js +35 -0
- package/dist/node_modules/.pnpm/yaml@2.8.3/node_modules/yaml/browser/dist/parse/cst-scalar.js +3 -0
- package/dist/node_modules/.pnpm/yaml@2.8.3/node_modules/yaml/browser/dist/parse/cst-visit.js +89 -0
- package/dist/node_modules/.pnpm/yaml@2.8.3/node_modules/yaml/browser/dist/parse/cst.js +40 -0
- package/dist/node_modules/.pnpm/yaml@2.8.3/node_modules/yaml/browser/dist/parse/lexer.js +517 -0
- package/dist/node_modules/.pnpm/yaml@2.8.3/node_modules/yaml/browser/dist/parse/line-counter.js +45 -0
- package/dist/node_modules/.pnpm/yaml@2.8.3/node_modules/yaml/browser/dist/parse/parser.js +855 -0
- package/dist/node_modules/.pnpm/yaml@2.8.3/node_modules/yaml/browser/dist/public-api.js +44 -0
- package/dist/node_modules/.pnpm/yaml@2.8.3/node_modules/yaml/browser/dist/schema/Schema.js +27 -0
- package/dist/node_modules/.pnpm/yaml@2.8.3/node_modules/yaml/browser/dist/schema/common/map.js +16 -0
- package/dist/node_modules/.pnpm/yaml@2.8.3/node_modules/yaml/browser/dist/schema/common/null.js +13 -0
- package/dist/node_modules/.pnpm/yaml@2.8.3/node_modules/yaml/browser/dist/schema/common/seq.js +16 -0
- package/dist/node_modules/.pnpm/yaml@2.8.3/node_modules/yaml/browser/dist/schema/common/string.js +14 -0
- package/dist/node_modules/.pnpm/yaml@2.8.3/node_modules/yaml/browser/dist/schema/core/bool.js +17 -0
- package/dist/node_modules/.pnpm/yaml@2.8.3/node_modules/yaml/browser/dist/schema/core/float.js +38 -0
- package/dist/node_modules/.pnpm/yaml@2.8.3/node_modules/yaml/browser/dist/schema/core/int.js +37 -0
- package/dist/node_modules/.pnpm/yaml@2.8.3/node_modules/yaml/browser/dist/schema/core/schema.js +23 -0
- package/dist/node_modules/.pnpm/yaml@2.8.3/node_modules/yaml/browser/dist/schema/json/schema.js +61 -0
- package/dist/node_modules/.pnpm/yaml@2.8.3/node_modules/yaml/browser/dist/schema/tags.js +81 -0
- package/dist/node_modules/.pnpm/yaml@2.8.3/node_modules/yaml/browser/dist/schema/yaml-1.1/binary.js +44 -0
- package/dist/node_modules/.pnpm/yaml@2.8.3/node_modules/yaml/browser/dist/schema/yaml-1.1/bool.js +24 -0
- package/dist/node_modules/.pnpm/yaml@2.8.3/node_modules/yaml/browser/dist/schema/yaml-1.1/float.js +41 -0
- package/dist/node_modules/.pnpm/yaml@2.8.3/node_modules/yaml/browser/dist/schema/yaml-1.1/int.js +70 -0
- package/dist/node_modules/.pnpm/yaml@2.8.3/node_modules/yaml/browser/dist/schema/yaml-1.1/merge.js +36 -0
- package/dist/node_modules/.pnpm/yaml@2.8.3/node_modules/yaml/browser/dist/schema/yaml-1.1/omap.js +60 -0
- package/dist/node_modules/.pnpm/yaml@2.8.3/node_modules/yaml/browser/dist/schema/yaml-1.1/pairs.js +56 -0
- package/dist/node_modules/.pnpm/yaml@2.8.3/node_modules/yaml/browser/dist/schema/yaml-1.1/schema.js +39 -0
- package/dist/node_modules/.pnpm/yaml@2.8.3/node_modules/yaml/browser/dist/schema/yaml-1.1/set.js +65 -0
- package/dist/node_modules/.pnpm/yaml@2.8.3/node_modules/yaml/browser/dist/schema/yaml-1.1/timestamp.js +79 -0
- package/dist/node_modules/.pnpm/yaml@2.8.3/node_modules/yaml/browser/dist/stringify/foldFlowLines.js +111 -0
- package/dist/node_modules/.pnpm/yaml@2.8.3/node_modules/yaml/browser/dist/stringify/stringify.js +105 -0
- package/dist/node_modules/.pnpm/yaml@2.8.3/node_modules/yaml/browser/dist/stringify/stringifyCollection.js +116 -0
- package/dist/node_modules/.pnpm/yaml@2.8.3/node_modules/yaml/browser/dist/stringify/stringifyComment.js +16 -0
- package/dist/node_modules/.pnpm/yaml@2.8.3/node_modules/yaml/browser/dist/stringify/stringifyDocument.js +59 -0
- package/dist/node_modules/.pnpm/yaml@2.8.3/node_modules/yaml/browser/dist/stringify/stringifyNumber.js +19 -0
- package/dist/node_modules/.pnpm/yaml@2.8.3/node_modules/yaml/browser/dist/stringify/stringifyPair.js +95 -0
- package/dist/node_modules/.pnpm/yaml@2.8.3/node_modules/yaml/browser/dist/stringify/stringifyString.js +222 -0
- package/dist/node_modules/.pnpm/yaml@2.8.3/node_modules/yaml/browser/dist/visit.js +187 -0
- package/dist/node_modules/.pnpm/yaml@2.8.3/node_modules/yaml/browser/index.js +16 -0
- package/dist/scalar/client.js +1 -1
- package/dist/server/index.d.ts +2 -2
- package/dist/server/source-api.d.ts +8 -8
- package/dist/server/source-api.js +1 -1
- package/dist/utils/document/process.js +5 -3
- package/package.json +17 -17
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import { isHttpUrl } from "../../../helpers/is-http-url.js";
|
|
2
|
+
import { createLimiter } from "../../../../../../../../@scalar_helpers@0.4.3/node_modules/@scalar/helpers/dist/general/create-limiter.js";
|
|
3
|
+
import { normalize } from "../../../helpers/normalize.js";
|
|
4
|
+
//#region ../../node_modules/.pnpm/@scalar+json-magic@0.12.5/node_modules/@scalar/json-magic/dist/bundle/plugins/fetch-urls/index.js
|
|
5
|
+
/**
|
|
6
|
+
* Safely checks for host from a URL
|
|
7
|
+
* Needed because we cannot create a URL from a relative remote URL ex: examples/openapi.json
|
|
8
|
+
*/
|
|
9
|
+
const getHost = (url) => {
|
|
10
|
+
try {
|
|
11
|
+
return new URL(url).host;
|
|
12
|
+
} catch {
|
|
13
|
+
return null;
|
|
14
|
+
}
|
|
15
|
+
};
|
|
16
|
+
/**
|
|
17
|
+
* Fetches and normalizes data from a remote URL
|
|
18
|
+
* @param url - The URL to fetch data from
|
|
19
|
+
* @returns A promise that resolves to either the normalized data or an error result
|
|
20
|
+
* @example
|
|
21
|
+
* ```ts
|
|
22
|
+
* const result = await fetchUrl('https://api.example.com/data.json')
|
|
23
|
+
* if (result.ok) {
|
|
24
|
+
* console.log(result.data) // The normalized data
|
|
25
|
+
* } else {
|
|
26
|
+
* console.log('Failed to fetch data')
|
|
27
|
+
* }
|
|
28
|
+
* ```
|
|
29
|
+
*/
|
|
30
|
+
async function fetchUrl(url, limiter, config) {
|
|
31
|
+
try {
|
|
32
|
+
const host = getHost(url);
|
|
33
|
+
const headers = config?.headers?.find((a) => a.domains.find((d) => d === host) !== void 0)?.headers;
|
|
34
|
+
const exec = config?.fetch ?? fetch;
|
|
35
|
+
const result = await limiter(() => exec(url, { headers }));
|
|
36
|
+
if (result.ok) {
|
|
37
|
+
const body = await result.text();
|
|
38
|
+
return {
|
|
39
|
+
ok: true,
|
|
40
|
+
data: normalize(body),
|
|
41
|
+
raw: body
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
const contentType = result.headers.get("Content-Type") ?? "";
|
|
45
|
+
if (["text/html", "application/xml"].includes(contentType)) console.warn(`[WARN] We only support JSON/YAML formats, received ${contentType}`);
|
|
46
|
+
console.warn(`[WARN] Fetch failed with status ${result.status} ${result.statusText} for URL: ${url}`);
|
|
47
|
+
return { ok: false };
|
|
48
|
+
} catch {
|
|
49
|
+
console.warn(`[WARN] Failed to parse JSON/YAML from URL: ${url}`);
|
|
50
|
+
return { ok: false };
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Creates a plugin for handling remote URL references.
|
|
55
|
+
* This plugin validates and fetches data from HTTP/HTTPS URLs.
|
|
56
|
+
*
|
|
57
|
+
* @returns A plugin object with validate and exec functions
|
|
58
|
+
* @example
|
|
59
|
+
* const urlPlugin = fetchUrls()
|
|
60
|
+
* if (urlPlugin.validate('https://example.com/schema.json')) {
|
|
61
|
+
* const result = await urlPlugin.exec('https://example.com/schema.json')
|
|
62
|
+
* }
|
|
63
|
+
*/
|
|
64
|
+
function fetchUrls(config) {
|
|
65
|
+
const limiter = config?.limit ? createLimiter(config.limit) : (fn) => fn();
|
|
66
|
+
return {
|
|
67
|
+
type: "loader",
|
|
68
|
+
validate: isHttpUrl,
|
|
69
|
+
exec: (value) => fetchUrl(value, limiter, config)
|
|
70
|
+
};
|
|
71
|
+
}
|
|
72
|
+
//#endregion
|
|
73
|
+
export { fetchUrls };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import "../../../../../../../../yaml@2.8.3/node_modules/yaml/browser/index.js";
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { isFilePath } from "../../../helpers/is-file-path.js";
|
|
2
|
+
import { normalize } from "../../../helpers/normalize.js";
|
|
3
|
+
//#region ../../node_modules/.pnpm/@scalar+json-magic@0.12.5/node_modules/@scalar/json-magic/dist/bundle/plugins/read-files/index.js
|
|
4
|
+
/**
|
|
5
|
+
* Reads and normalizes data from a local file
|
|
6
|
+
* @param path - The file path to read from
|
|
7
|
+
* @returns A promise that resolves to either the normalized data or an error result
|
|
8
|
+
* @example
|
|
9
|
+
* ```ts
|
|
10
|
+
* const result = await readFile('./schemas/user.json')
|
|
11
|
+
* if (result.ok) {
|
|
12
|
+
* console.log(result.data) // The normalized data
|
|
13
|
+
* } else {
|
|
14
|
+
* console.log('Failed to read file')
|
|
15
|
+
* }
|
|
16
|
+
* ```
|
|
17
|
+
*/
|
|
18
|
+
async function readFile(path) {
|
|
19
|
+
const fs = typeof window === "undefined" ? await import("node:fs/promises") : void 0;
|
|
20
|
+
if (fs === void 0) throw "Can not use readFiles plugin outside of a node environment";
|
|
21
|
+
try {
|
|
22
|
+
const fileContents = await fs.readFile(path, { encoding: "utf-8" });
|
|
23
|
+
return {
|
|
24
|
+
ok: true,
|
|
25
|
+
data: normalize(fileContents),
|
|
26
|
+
raw: fileContents
|
|
27
|
+
};
|
|
28
|
+
} catch {
|
|
29
|
+
return { ok: false };
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Creates a plugin for handling local file references.
|
|
34
|
+
* This plugin validates and reads data from local filesystem paths.
|
|
35
|
+
*
|
|
36
|
+
* @returns A plugin object with validate and exec functions
|
|
37
|
+
* @example
|
|
38
|
+
* const filePlugin = readFiles()
|
|
39
|
+
* if (filePlugin.validate('./local-schema.json')) {
|
|
40
|
+
* const result = await filePlugin.exec('./local-schema.json')
|
|
41
|
+
* }
|
|
42
|
+
*/
|
|
43
|
+
function readFiles() {
|
|
44
|
+
return {
|
|
45
|
+
type: "loader",
|
|
46
|
+
validate: isFilePath,
|
|
47
|
+
exec: readFile
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
//#endregion
|
|
51
|
+
export { readFiles };
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
import { generateHash } from "../../../../../../@scalar_helpers@0.4.3/node_modules/@scalar/helpers/dist/string/generate-hash.js";
|
|
2
|
+
//#region ../../node_modules/.pnpm/@scalar+json-magic@0.12.5/node_modules/@scalar/json-magic/dist/bundle/value-generator.js
|
|
3
|
+
/**
|
|
4
|
+
* Generates a short hash from a string value using xxhash.
|
|
5
|
+
*
|
|
6
|
+
* This function is used to create unique identifiers for external references
|
|
7
|
+
* while keeping the hash length manageable. It uses xxhash-wasm instead of
|
|
8
|
+
* crypto.subtle because crypto.subtle is only available in secure contexts (HTTPS) or on localhost.
|
|
9
|
+
* Returns the first 7 characters of the hash string.
|
|
10
|
+
* If the hash would be all numbers, it ensures at least one letter is included.
|
|
11
|
+
*
|
|
12
|
+
* @param value - The string to hash
|
|
13
|
+
* @returns A Promise that resolves to a 7-character hexadecimal hash with at least one letter
|
|
14
|
+
* @example
|
|
15
|
+
* // Returns "2ae91d7"
|
|
16
|
+
* getHash("https://example.com/schema.json")
|
|
17
|
+
*/
|
|
18
|
+
function getHash(value) {
|
|
19
|
+
const hash = generateHash(value).substring(0, 7);
|
|
20
|
+
return hash.match(/^\d+$/) ? "a" + hash.substring(1) : hash;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Generates a unique compressed value for a string, handling collisions by recursively compressing
|
|
24
|
+
* until a unique value is found. This is used to create unique identifiers for external
|
|
25
|
+
* references in the bundled OpenAPI document.
|
|
26
|
+
*
|
|
27
|
+
* @param compress - Function that generates a compressed value from a string
|
|
28
|
+
* @param value - The original string value to compress
|
|
29
|
+
* @param compressedToValue - Object mapping compressed values to their original values
|
|
30
|
+
* @param prevCompressedValue - Optional previous compressed value to use as input for generating a new value
|
|
31
|
+
* @param depth - Current recursion depth to prevent infinite loops
|
|
32
|
+
* @returns A unique compressed value that doesn't conflict with existing values
|
|
33
|
+
*
|
|
34
|
+
* @example
|
|
35
|
+
* const valueMap = {}
|
|
36
|
+
* // First call generates compressed value for "example.com/schema.json"
|
|
37
|
+
* const value1 = await generateUniqueValue(compress, "example.com/schema.json", valueMap)
|
|
38
|
+
* // Returns something like "2ae91d7"
|
|
39
|
+
*
|
|
40
|
+
* // Second call with same value returns same compressed value
|
|
41
|
+
* const value2 = await generateUniqueValue(compress, "example.com/schema.json", valueMap)
|
|
42
|
+
* // Returns same value as value1
|
|
43
|
+
*
|
|
44
|
+
* // Call with different value generates new unique compressed value
|
|
45
|
+
* const value3 = await generateUniqueValue(compress, "example.com/other.json", valueMap)
|
|
46
|
+
* // Returns different value like "3bf82e9"
|
|
47
|
+
*/
|
|
48
|
+
async function generateUniqueValue(compress, value, compressedToValue, prevCompressedValue, depth = 0) {
|
|
49
|
+
if (depth >= 100) throw "Can not generate unique compressed values";
|
|
50
|
+
const compressedValue = await compress(prevCompressedValue ?? value);
|
|
51
|
+
if (compressedToValue[compressedValue] !== void 0 && compressedToValue[compressedValue] !== value) return generateUniqueValue(compress, value, compressedToValue, compressedValue, depth + 1);
|
|
52
|
+
compressedToValue[compressedValue] = value;
|
|
53
|
+
return compressedValue;
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* Factory function that creates a value generator with caching capabilities.
|
|
57
|
+
* The generator maintains a bidirectional mapping between original values and their compressed forms.
|
|
58
|
+
*
|
|
59
|
+
* @param compress - Function that generates a compressed value from a string
|
|
60
|
+
* @param compressedToValue - Initial mapping of compressed values to their original values
|
|
61
|
+
* @returns An object with a generate method that produces unique compressed values
|
|
62
|
+
*
|
|
63
|
+
* @example
|
|
64
|
+
* const compress = (value) => value.substring(0, 6) // Simple compression example
|
|
65
|
+
* const initialMap = { 'abc123': 'example.com/schema.json' }
|
|
66
|
+
* const generator = uniqueValueGeneratorFactory(compress, initialMap)
|
|
67
|
+
*
|
|
68
|
+
* // Generate compressed value for new string
|
|
69
|
+
* const compressed = await generator.generate('example.com/other.json')
|
|
70
|
+
* // Returns something like 'example'
|
|
71
|
+
*
|
|
72
|
+
* // Generate compressed value for existing string
|
|
73
|
+
* const cached = await generator.generate('example.com/schema.json')
|
|
74
|
+
* // Returns 'abc123' from cache
|
|
75
|
+
*/
|
|
76
|
+
const uniqueValueGeneratorFactory = (compress, compressedToValue) => {
|
|
77
|
+
const valueToCompressed = Object.fromEntries(Object.entries(compressedToValue).map(([key, value]) => [value, key]));
|
|
78
|
+
return { generate: async (value) => {
|
|
79
|
+
const cache = valueToCompressed[value];
|
|
80
|
+
if (cache) return cache;
|
|
81
|
+
const generatedValue = await generateUniqueValue(compress, value, compressedToValue);
|
|
82
|
+
const compressedValue = generatedValue.match(/^\d+$/) ? `a${generatedValue}` : generatedValue;
|
|
83
|
+
valueToCompressed[value] = compressedValue;
|
|
84
|
+
return compressedValue;
|
|
85
|
+
} };
|
|
86
|
+
};
|
|
87
|
+
//#endregion
|
|
88
|
+
export { getHash, uniqueValueGeneratorFactory };
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
//#region ../../node_modules/.pnpm/@scalar+json-magic@0.12.5/node_modules/@scalar/json-magic/dist/helpers/convert-to-local-ref.js
|
|
2
|
+
/**
|
|
3
|
+
* Translates a JSON Reference ($ref) to a local object path within the root schema.
|
|
4
|
+
*
|
|
5
|
+
* @param ref - The JSON Reference string (e.g., "#/foo/bar", "other.json#/baz", "other.json#anchor")
|
|
6
|
+
* @param currentContext - The current base context (usually the $id of the current schema or parent)
|
|
7
|
+
* @param schemas - A map of schema identifiers ($id, $anchor) to their local object paths
|
|
8
|
+
* @returns The local object path as a string, or undefined if the reference cannot be resolved
|
|
9
|
+
*/
|
|
10
|
+
const convertToLocalRef = (ref, currentContext, schemas) => {
|
|
11
|
+
const [baseUrl, pathOrAnchor] = ref.split("#", 2);
|
|
12
|
+
if (baseUrl) {
|
|
13
|
+
if (!schemas.has(baseUrl)) return;
|
|
14
|
+
if (!pathOrAnchor) return schemas.get(baseUrl);
|
|
15
|
+
if (pathOrAnchor.startsWith("/")) return `${schemas.get(baseUrl)}${pathOrAnchor}`;
|
|
16
|
+
return schemas.get(`${baseUrl}#${pathOrAnchor}`);
|
|
17
|
+
}
|
|
18
|
+
if (pathOrAnchor) {
|
|
19
|
+
if (pathOrAnchor.startsWith("/")) return pathOrAnchor.slice(1);
|
|
20
|
+
return schemas.get(`${currentContext}#${pathOrAnchor}`);
|
|
21
|
+
}
|
|
22
|
+
};
|
|
23
|
+
//#endregion
|
|
24
|
+
export { convertToLocalRef };
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
//#region ../../node_modules/.pnpm/@scalar+json-magic@0.12.5/node_modules/@scalar/json-magic/dist/helpers/escape-json-pointer.js
|
|
2
|
+
/**
|
|
3
|
+
* Escapes a JSON pointer string.
|
|
4
|
+
*
|
|
5
|
+
* Example: `/foo/bar~baz` -> `'~1foo~1bar~0baz'`
|
|
6
|
+
*/
|
|
7
|
+
function escapeJsonPointer(str) {
|
|
8
|
+
return str.replace(/~/g, "~0").replace(/\//g, "~1");
|
|
9
|
+
}
|
|
10
|
+
//#endregion
|
|
11
|
+
export { escapeJsonPointer };
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
//#region ../../node_modules/.pnpm/@scalar+json-magic@0.12.5/node_modules/@scalar/json-magic/dist/helpers/get-schemas.js
|
|
2
|
+
/**
|
|
3
|
+
* Retrieves the $id property from the input object if it exists and is a string.
|
|
4
|
+
*
|
|
5
|
+
* @param input - The object to extract the $id from.
|
|
6
|
+
* @returns The $id string if present, otherwise undefined.
|
|
7
|
+
*/
|
|
8
|
+
const getId = (input) => {
|
|
9
|
+
if (input && typeof input === "object" && input["$id"] && typeof input["$id"] === "string") return input["$id"];
|
|
10
|
+
};
|
|
11
|
+
/**
|
|
12
|
+
* Joins an array of path segments into a single string separated by '/'.
|
|
13
|
+
*
|
|
14
|
+
* @param segments - The array of path segments.
|
|
15
|
+
* @returns The joined path string.
|
|
16
|
+
*/
|
|
17
|
+
const getPath = (segments) => {
|
|
18
|
+
return segments.join("/");
|
|
19
|
+
};
|
|
20
|
+
/**
|
|
21
|
+
* Recursively traverses the input object to collect all schemas identified by $id and $anchor properties.
|
|
22
|
+
*
|
|
23
|
+
* - If an object has a $id property, it is added to the map with its $id as the key.
|
|
24
|
+
* - If an object has a $anchor property, it is added to the map with a key composed of the current base and the anchor.
|
|
25
|
+
* - The function performs a depth-first search (DFS) through all nested objects.
|
|
26
|
+
*
|
|
27
|
+
* @param input - The input object to traverse.
|
|
28
|
+
* @param base - The current base URI, used for resolving anchors.
|
|
29
|
+
* @param map - The map collecting found schemas.
|
|
30
|
+
* @returns A map of schema identifiers to their corresponding objects.
|
|
31
|
+
*/
|
|
32
|
+
const getSchemas = (input, base = "", segments = [], map = /* @__PURE__ */ new Map(), visited = /* @__PURE__ */ new WeakSet()) => {
|
|
33
|
+
if (typeof input !== "object" || input === null) return map;
|
|
34
|
+
if (visited.has(input)) return map;
|
|
35
|
+
visited.add(input);
|
|
36
|
+
const id = getId(input);
|
|
37
|
+
if (id) map.set(id, getPath(segments));
|
|
38
|
+
const newBase = id ?? base;
|
|
39
|
+
if (input["$anchor"] && typeof input["$anchor"] === "string") map.set(`${newBase}#${input["$anchor"]}`, getPath(segments));
|
|
40
|
+
for (const key in input) if (typeof input[key] === "object" && input[key] !== null) getSchemas(input[key], newBase, [...segments, key], map, visited);
|
|
41
|
+
return map;
|
|
42
|
+
};
|
|
43
|
+
//#endregion
|
|
44
|
+
export { getId, getSchemas };
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { unescapeJsonPointer } from "./unescape-json-pointer.js";
|
|
2
|
+
//#region ../../node_modules/.pnpm/@scalar+json-magic@0.12.5/node_modules/@scalar/json-magic/dist/helpers/get-segments-from-path.js
|
|
3
|
+
/**
|
|
4
|
+
* Translate `/paths/~1test` to `['paths', '/test']`
|
|
5
|
+
*/
|
|
6
|
+
function getSegmentsFromPath(path) {
|
|
7
|
+
return path.split("/").slice(1).map(unescapeJsonPointer);
|
|
8
|
+
}
|
|
9
|
+
//#endregion
|
|
10
|
+
export { getSegmentsFromPath };
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { getId } from "./get-schemas.js";
|
|
2
|
+
//#region ../../node_modules/.pnpm/@scalar+json-magic@0.12.5/node_modules/@scalar/json-magic/dist/helpers/get-value-by-path.js
|
|
3
|
+
/**
|
|
4
|
+
* Traverses an object using an array of string segments (path keys) and returns
|
|
5
|
+
* the value at the specified path along with its context (id if available).
|
|
6
|
+
*
|
|
7
|
+
* @param target - The root object to traverse.
|
|
8
|
+
* @param segments - An array of string keys representing the path to traverse.
|
|
9
|
+
* @returns An object containing the final context (id or previous context) and the value at the path.
|
|
10
|
+
*
|
|
11
|
+
* @example
|
|
12
|
+
* const obj = {
|
|
13
|
+
* foo: {
|
|
14
|
+
* bar: {
|
|
15
|
+
* baz: 42
|
|
16
|
+
* }
|
|
17
|
+
* }
|
|
18
|
+
* };
|
|
19
|
+
* // Returns: { context: '', value: 42 }
|
|
20
|
+
* getValueByPath(obj, ['foo', 'bar', 'baz']);
|
|
21
|
+
*/
|
|
22
|
+
function getValueByPath(target, segments) {
|
|
23
|
+
return segments.reduce((acc, key) => {
|
|
24
|
+
if (acc.value === void 0) return {
|
|
25
|
+
context: "",
|
|
26
|
+
value: void 0
|
|
27
|
+
};
|
|
28
|
+
if (typeof acc.value !== "object" || acc.value === null) return {
|
|
29
|
+
context: "",
|
|
30
|
+
value: void 0
|
|
31
|
+
};
|
|
32
|
+
return {
|
|
33
|
+
context: getId(acc.value) ?? acc.context,
|
|
34
|
+
value: acc.value?.[key]
|
|
35
|
+
};
|
|
36
|
+
}, {
|
|
37
|
+
context: "",
|
|
38
|
+
value: target
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
//#endregion
|
|
42
|
+
export { getValueByPath };
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { isHttpUrl } from "./is-http-url.js";
|
|
2
|
+
import { isJsonObject } from "./is-json-object.js";
|
|
3
|
+
import { isYaml } from "./is-yaml.js";
|
|
4
|
+
//#region ../../node_modules/.pnpm/@scalar+json-magic@0.12.5/node_modules/@scalar/json-magic/dist/helpers/is-file-path.js
|
|
5
|
+
/**
|
|
6
|
+
* Checks if a string represents a file path by ensuring it's not a remote URL,
|
|
7
|
+
* YAML content, or JSON content.
|
|
8
|
+
*
|
|
9
|
+
* @param value - The string to check
|
|
10
|
+
* @returns true if the string appears to be a file path, false otherwise
|
|
11
|
+
* @example
|
|
12
|
+
* ```ts
|
|
13
|
+
* isFilePath('./schemas/user.json') // true
|
|
14
|
+
* isFilePath('https://example.com/schema.json') // false
|
|
15
|
+
* isFilePath('{"type": "object"}') // false
|
|
16
|
+
* isFilePath('type: object') // false
|
|
17
|
+
* ```
|
|
18
|
+
*/
|
|
19
|
+
function isFilePath(value) {
|
|
20
|
+
return !isHttpUrl(value) && !isYaml(value) && !isJsonObject(value);
|
|
21
|
+
}
|
|
22
|
+
//#endregion
|
|
23
|
+
export { isFilePath };
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
//#region ../../node_modules/.pnpm/@scalar+json-magic@0.12.5/node_modules/@scalar/json-magic/dist/helpers/is-http-url.js
|
|
2
|
+
/**
|
|
3
|
+
* Checks if a string is a remote URL (starts with http:// or https://)
|
|
4
|
+
* @param value - The URL string to check
|
|
5
|
+
* @returns true if the string is a remote URL, false otherwise
|
|
6
|
+
* @example
|
|
7
|
+
* ```ts
|
|
8
|
+
* isHttpUrl('https://example.com/schema.json') // true
|
|
9
|
+
* isHttpUrl('http://api.example.com/schemas/user.json') // true
|
|
10
|
+
* isHttpUrl('#/components/schemas/User') // false
|
|
11
|
+
* isHttpUrl('./local-schema.json') // false
|
|
12
|
+
* ```
|
|
13
|
+
*/
|
|
14
|
+
function isHttpUrl(value) {
|
|
15
|
+
try {
|
|
16
|
+
const url = new URL(value);
|
|
17
|
+
return url.protocol === "http:" || url.protocol === "https:";
|
|
18
|
+
} catch {
|
|
19
|
+
return false;
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
//#endregion
|
|
23
|
+
export { isHttpUrl };
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { isObject } from "../../../../../../@scalar_helpers@0.4.3/node_modules/@scalar/helpers/dist/object/is-object.js";
|
|
2
|
+
//#region ../../node_modules/.pnpm/@scalar+json-magic@0.12.5/node_modules/@scalar/json-magic/dist/helpers/is-json-object.js
|
|
3
|
+
/**
|
|
4
|
+
* Determines if a string represents a valid JSON object (i.e., a plain object, not an array, primitive, or null).
|
|
5
|
+
* The function first checks if the string appears to start with an opening curly brace (ignoring leading whitespace),
|
|
6
|
+
* which is a quick heuristic to rule out arrays, primitives, and most invalid JSON. If this check passes,
|
|
7
|
+
* it attempts to parse the string with JSON.parse. The result is then checked to ensure it is a plain object
|
|
8
|
+
* (not an array, null, or primitive) using the isObject utility.
|
|
9
|
+
*
|
|
10
|
+
* @param value - The string to evaluate
|
|
11
|
+
* @returns true if the string is valid JSON and parses to a plain object, false otherwise
|
|
12
|
+
*
|
|
13
|
+
* @example
|
|
14
|
+
* isJsonObject('{"foo": "bar"}') // true
|
|
15
|
+
* isJsonObject('[1,2,3]') // false
|
|
16
|
+
* isJsonObject('not json') // false
|
|
17
|
+
* isJsonObject('42') // false
|
|
18
|
+
*/
|
|
19
|
+
function isJsonObject(value) {
|
|
20
|
+
if (!/^\s*(\{)/.test(value.slice(0, 500))) return false;
|
|
21
|
+
try {
|
|
22
|
+
return isObject(JSON.parse(value));
|
|
23
|
+
} catch {
|
|
24
|
+
return false;
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
//#endregion
|
|
28
|
+
export { isJsonObject };
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
//#region ../../node_modules/.pnpm/@scalar+json-magic@0.12.5/node_modules/@scalar/json-magic/dist/helpers/is-yaml.js
|
|
2
|
+
/**
|
|
3
|
+
* Checks if a string appears to be YAML content.
|
|
4
|
+
* This function uses a simple heuristic: it looks for a line that starts with an optional dash,
|
|
5
|
+
* followed by a key (alphanumeric or dash), a colon, and a value, and then at least one more line.
|
|
6
|
+
* This is not a full YAML parser, but works for basic detection.
|
|
7
|
+
*
|
|
8
|
+
* @param value - The string to check
|
|
9
|
+
* @returns true if the string looks like YAML, false otherwise
|
|
10
|
+
*
|
|
11
|
+
* @example
|
|
12
|
+
* isYaml('openapi: 3.0.0\ninfo:\n title: Example') // true
|
|
13
|
+
* isYaml('{"openapi": "3.0.0", "info": {"title": "Example"}}') // false
|
|
14
|
+
* isYaml('- name: value\n- name: value2') // true
|
|
15
|
+
* isYaml('type: object') // false (only one line)
|
|
16
|
+
*/
|
|
17
|
+
function isYaml(value) {
|
|
18
|
+
return /^\s*(?:-\s*)?[\w\-]+\s*:\s*.+\n.*/.test(value);
|
|
19
|
+
}
|
|
20
|
+
//#endregion
|
|
21
|
+
export { isYaml };
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { parse } from "../../../../../../yaml@2.8.3/node_modules/yaml/browser/dist/public-api.js";
|
|
2
|
+
import "../../../../../../yaml@2.8.3/node_modules/yaml/browser/index.js";
|
|
3
|
+
//#region ../../node_modules/.pnpm/@scalar+json-magic@0.12.5/node_modules/@scalar/json-magic/dist/helpers/normalize.js
|
|
4
|
+
/**
|
|
5
|
+
* Normalize a string (YAML, JSON, object) to a JavaScript datatype.
|
|
6
|
+
*/
|
|
7
|
+
function normalize(content) {
|
|
8
|
+
if (content === null) return;
|
|
9
|
+
if (typeof content === "string") {
|
|
10
|
+
if (content.trim() === "") return;
|
|
11
|
+
try {
|
|
12
|
+
return JSON.parse(content);
|
|
13
|
+
} catch (_error) {
|
|
14
|
+
const hasColon = /^[^:]+:/.test(content);
|
|
15
|
+
const isJson = content.slice(0, 50).trimStart().startsWith("{");
|
|
16
|
+
if (!hasColon || isJson) return;
|
|
17
|
+
return parse(content, {
|
|
18
|
+
maxAliasCount: 1e4,
|
|
19
|
+
merge: true
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
return content;
|
|
24
|
+
}
|
|
25
|
+
//#endregion
|
|
26
|
+
export { normalize };
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { isHttpUrl } from "./is-http-url.js";
|
|
2
|
+
import { posix } from "../../../../../../pathe@2.0.3/node_modules/pathe/dist/index.js";
|
|
3
|
+
//#region ../../node_modules/.pnpm/@scalar+json-magic@0.12.5/node_modules/@scalar/json-magic/dist/helpers/resolve-reference-path.js
|
|
4
|
+
/**
|
|
5
|
+
* Resolves a reference path by combining a base path with a relative path.
|
|
6
|
+
* Handles both remote URLs and local file paths.
|
|
7
|
+
*
|
|
8
|
+
* @param base - The base path (can be a URL or local file path)
|
|
9
|
+
* @param relativePath - The relative path to resolve against the base
|
|
10
|
+
* @returns The resolved absolute path
|
|
11
|
+
* @example
|
|
12
|
+
* // Resolve remote URL
|
|
13
|
+
* resolveReferencePath('https://example.com/api/schema.json', 'user.json')
|
|
14
|
+
* // Returns: 'https://example.com/api/user.json'
|
|
15
|
+
*
|
|
16
|
+
* // Resolve local path
|
|
17
|
+
* resolveReferencePath('/path/to/schema.json', 'user.json')
|
|
18
|
+
* // Returns: '/path/to/user.json'
|
|
19
|
+
*/
|
|
20
|
+
const resolveReferencePath = (base, relativePath) => {
|
|
21
|
+
if (isHttpUrl(relativePath)) return relativePath;
|
|
22
|
+
if (isHttpUrl(base)) {
|
|
23
|
+
const baseUrl = new URL(base);
|
|
24
|
+
baseUrl.pathname = posix.posix.resolve("/", posix.dirname(baseUrl.pathname), relativePath);
|
|
25
|
+
return baseUrl.toString();
|
|
26
|
+
}
|
|
27
|
+
return posix.resolve(posix.dirname(base), relativePath);
|
|
28
|
+
};
|
|
29
|
+
//#endregion
|
|
30
|
+
export { resolveReferencePath };
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import { preventPollution } from "../../../../../../@scalar_helpers@0.4.3/node_modules/@scalar/helpers/dist/object/prevent-pollution.js";
|
|
2
|
+
import { getSegmentsFromPath } from "./get-segments-from-path.js";
|
|
3
|
+
//#region ../../node_modules/.pnpm/@scalar+json-magic@0.12.5/node_modules/@scalar/json-magic/dist/helpers/set-value-at-path.js
|
|
4
|
+
/**
|
|
5
|
+
* Sets a value at a specified path in an object, creating intermediate objects/arrays as needed.
|
|
6
|
+
* This function traverses the object structure and creates any missing intermediate objects
|
|
7
|
+
* or arrays based on the path segments. If the next segment is a numeric string, it creates
|
|
8
|
+
* an array instead of an object.
|
|
9
|
+
*
|
|
10
|
+
* ⚠️ Warning: Be careful with object keys that look like numbers (e.g. "123") as this function
|
|
11
|
+
* will interpret them as array indices and create arrays instead of objects. If you need to
|
|
12
|
+
* use numeric-looking keys, consider prefixing them with a non-numeric character.
|
|
13
|
+
*
|
|
14
|
+
* @param obj - The target object to set the value in
|
|
15
|
+
* @param path - The JSON pointer path where the value should be set
|
|
16
|
+
* @param value - The value to set at the specified path
|
|
17
|
+
* @throws {Error} If attempting to set a value at the root path ('')
|
|
18
|
+
*
|
|
19
|
+
* @example
|
|
20
|
+
* const obj = {}
|
|
21
|
+
* setValueAtPath(obj, '/foo/bar/0', 'value')
|
|
22
|
+
* // Result:
|
|
23
|
+
* // {
|
|
24
|
+
* // foo: {
|
|
25
|
+
* // bar: ['value']
|
|
26
|
+
* // }
|
|
27
|
+
* // }
|
|
28
|
+
*
|
|
29
|
+
* @example
|
|
30
|
+
* const obj = { existing: { path: 'old' } }
|
|
31
|
+
* setValueAtPath(obj, '/existing/path', 'new')
|
|
32
|
+
* // Result:
|
|
33
|
+
* // {
|
|
34
|
+
* // existing: {
|
|
35
|
+
* // path: 'new'
|
|
36
|
+
* // }
|
|
37
|
+
* // }
|
|
38
|
+
*
|
|
39
|
+
* @example
|
|
40
|
+
* // ⚠️ Warning: This will create an array instead of an object with key "123"
|
|
41
|
+
* setValueAtPath(obj, '/foo/123/bar', 'value')
|
|
42
|
+
* // Result:
|
|
43
|
+
* // {
|
|
44
|
+
* // foo: [
|
|
45
|
+
* // undefined,
|
|
46
|
+
* // undefined,
|
|
47
|
+
* // undefined,
|
|
48
|
+
* // { bar: 'value' }
|
|
49
|
+
* // ]
|
|
50
|
+
* // }
|
|
51
|
+
*/
|
|
52
|
+
function setValueAtPath(obj, path, value) {
|
|
53
|
+
if (path === "") throw new Error("Cannot set value at root ('') pointer");
|
|
54
|
+
const parts = getSegmentsFromPath(path);
|
|
55
|
+
parts.forEach((part) => preventPollution(part));
|
|
56
|
+
let current = obj;
|
|
57
|
+
for (let i = 0; i < parts.length; i++) {
|
|
58
|
+
const key = parts[i];
|
|
59
|
+
const isLast = i === parts.length - 1;
|
|
60
|
+
const nextKey = parts[i + 1];
|
|
61
|
+
const shouldBeArray = /^\d+$/.test(nextKey ?? "");
|
|
62
|
+
if (isLast) current[key] = value;
|
|
63
|
+
else {
|
|
64
|
+
if (!(key in current) || typeof current[key] !== "object") current[key] = shouldBeArray ? [] : {};
|
|
65
|
+
current = current[key];
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
//#endregion
|
|
70
|
+
export { setValueAtPath };
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { isHttpUrl } from "./is-http-url.js";
|
|
2
|
+
import { posix } from "../../../../../../pathe@2.0.3/node_modules/pathe/dist/index.js";
|
|
3
|
+
//#region ../../node_modules/.pnpm/@scalar+json-magic@0.12.5/node_modules/@scalar/json-magic/dist/helpers/to-relative-path.js
|
|
4
|
+
/**
|
|
5
|
+
* Converts an input path or URL to a relative path based on the provided base.
|
|
6
|
+
* Handles both remote URLs and local file system paths.
|
|
7
|
+
* - If both input and base are remote URLs and share the same origin, computes the relative pathname.
|
|
8
|
+
* - If base is a remote URL but input is local, returns a remote URL with a relative pathname.
|
|
9
|
+
* - If input is a remote URL but base is local, returns input as is.
|
|
10
|
+
* - Otherwise, computes the relative path between two local paths.
|
|
11
|
+
*/
|
|
12
|
+
const toRelativePath = (input, base) => {
|
|
13
|
+
if (isHttpUrl(input) && isHttpUrl(base)) {
|
|
14
|
+
const inputUrl = new URL(input);
|
|
15
|
+
const baseUrl = new URL(base);
|
|
16
|
+
if (inputUrl.origin !== baseUrl.origin) return input;
|
|
17
|
+
const baseDir = posix.dirname(posix.posix.resolve("/", baseUrl.pathname));
|
|
18
|
+
const inputPath = posix.posix.resolve("/", inputUrl.pathname);
|
|
19
|
+
return posix.posix.relative(baseDir, inputPath);
|
|
20
|
+
}
|
|
21
|
+
if (isHttpUrl(base)) {
|
|
22
|
+
const baseUrl = new URL(base);
|
|
23
|
+
const baseDir = posix.dirname(posix.posix.resolve("/", baseUrl.pathname));
|
|
24
|
+
baseUrl.pathname = posix.posix.relative(baseDir, posix.posix.resolve("/", input));
|
|
25
|
+
return baseUrl.toString();
|
|
26
|
+
}
|
|
27
|
+
if (isHttpUrl(input)) return input;
|
|
28
|
+
const baseDir = posix.dirname(posix.resolve(base));
|
|
29
|
+
const inputPath = posix.resolve(input);
|
|
30
|
+
return posix.relative(baseDir, inputPath);
|
|
31
|
+
};
|
|
32
|
+
//#endregion
|
|
33
|
+
export { toRelativePath };
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
//#region ../../node_modules/.pnpm/@scalar+json-magic@0.12.5/node_modules/@scalar/json-magic/dist/helpers/unescape-json-pointer.js
|
|
2
|
+
/**
|
|
3
|
+
* Unescape JSON pointer
|
|
4
|
+
*
|
|
5
|
+
* Examples:
|
|
6
|
+
* /foo~1bar~0baz -> /foo/bar~baz
|
|
7
|
+
*/
|
|
8
|
+
function unescapeJsonPointer(uri) {
|
|
9
|
+
return decodeURI(uri.replace(/~1/g, "/").replace(/~0/g, "~"));
|
|
10
|
+
}
|
|
11
|
+
//#endregion
|
|
12
|
+
export { unescapeJsonPointer };
|