fumadocs-openapi 10.6.7 → 10.7.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/css/generated/shared.css +2 -5
- package/dist/_virtual/_rolldown/runtime.js +2 -1
- package/dist/i18n.js +3 -2
- package/dist/node_modules/.pnpm/@fastify_deepmerge@3.2.1/node_modules/@fastify/deepmerge/index.js +108 -0
- 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/fast-content-type-parse@3.0.0/node_modules/fast-content-type-parse/index.js +115 -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 +173 -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 +204 -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 +852 -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/playground/components/oauth-dialog.js +17 -11
- package/dist/playground/components/result-display.js +3 -2
- package/dist/playground/schema.js +1 -1
- package/dist/scalar/client.js +15 -24
- package/dist/ui/operation/get-example-requests.js +1 -1
- package/dist/ui/operation/response-tabs.js +1 -1
- package/dist/utils/document/process.js +5 -3
- package/dist/utils/schema/sample.js +442 -0
- package/package.json +26 -25
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { isNode } from "../nodes/identity.js";
|
|
2
|
+
import { indentComment, lineComment } from "./stringifyComment.js";
|
|
3
|
+
import { createStringifyContext, stringify } from "./stringify.js";
|
|
4
|
+
//#region ../../node_modules/.pnpm/yaml@2.8.3/node_modules/yaml/browser/dist/stringify/stringifyDocument.js
|
|
5
|
+
function stringifyDocument(doc, options) {
|
|
6
|
+
const lines = [];
|
|
7
|
+
let hasDirectives = options.directives === true;
|
|
8
|
+
if (options.directives !== false && doc.directives) {
|
|
9
|
+
const dir = doc.directives.toString(doc);
|
|
10
|
+
if (dir) {
|
|
11
|
+
lines.push(dir);
|
|
12
|
+
hasDirectives = true;
|
|
13
|
+
} else if (doc.directives.docStart) hasDirectives = true;
|
|
14
|
+
}
|
|
15
|
+
if (hasDirectives) lines.push("---");
|
|
16
|
+
const ctx = createStringifyContext(doc, options);
|
|
17
|
+
const { commentString } = ctx.options;
|
|
18
|
+
if (doc.commentBefore) {
|
|
19
|
+
if (lines.length !== 1) lines.unshift("");
|
|
20
|
+
const cs = commentString(doc.commentBefore);
|
|
21
|
+
lines.unshift(indentComment(cs, ""));
|
|
22
|
+
}
|
|
23
|
+
let chompKeep = false;
|
|
24
|
+
let contentComment = null;
|
|
25
|
+
if (doc.contents) {
|
|
26
|
+
if (isNode(doc.contents)) {
|
|
27
|
+
if (doc.contents.spaceBefore && hasDirectives) lines.push("");
|
|
28
|
+
if (doc.contents.commentBefore) {
|
|
29
|
+
const cs = commentString(doc.contents.commentBefore);
|
|
30
|
+
lines.push(indentComment(cs, ""));
|
|
31
|
+
}
|
|
32
|
+
ctx.forceBlockIndent = !!doc.comment;
|
|
33
|
+
contentComment = doc.contents.comment;
|
|
34
|
+
}
|
|
35
|
+
const onChompKeep = contentComment ? void 0 : () => chompKeep = true;
|
|
36
|
+
let body = stringify(doc.contents, ctx, () => contentComment = null, onChompKeep);
|
|
37
|
+
if (contentComment) body += lineComment(body, "", commentString(contentComment));
|
|
38
|
+
if ((body[0] === "|" || body[0] === ">") && lines[lines.length - 1] === "---") lines[lines.length - 1] = `--- ${body}`;
|
|
39
|
+
else lines.push(body);
|
|
40
|
+
} else lines.push(stringify(doc.contents, ctx));
|
|
41
|
+
if (doc.directives?.docEnd) if (doc.comment) {
|
|
42
|
+
const cs = commentString(doc.comment);
|
|
43
|
+
if (cs.includes("\n")) {
|
|
44
|
+
lines.push("...");
|
|
45
|
+
lines.push(indentComment(cs, ""));
|
|
46
|
+
} else lines.push(`... ${cs}`);
|
|
47
|
+
} else lines.push("...");
|
|
48
|
+
else {
|
|
49
|
+
let dc = doc.comment;
|
|
50
|
+
if (dc && chompKeep) dc = dc.replace(/^\n+/, "");
|
|
51
|
+
if (dc) {
|
|
52
|
+
if ((!chompKeep || contentComment) && lines[lines.length - 1] !== "") lines.push("");
|
|
53
|
+
lines.push(indentComment(commentString(dc), ""));
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
return lines.join("\n") + "\n";
|
|
57
|
+
}
|
|
58
|
+
//#endregion
|
|
59
|
+
export { stringifyDocument };
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
//#region ../../node_modules/.pnpm/yaml@2.8.3/node_modules/yaml/browser/dist/stringify/stringifyNumber.js
|
|
2
|
+
function stringifyNumber({ format, minFractionDigits, tag, value }) {
|
|
3
|
+
if (typeof value === "bigint") return String(value);
|
|
4
|
+
const num = typeof value === "number" ? value : Number(value);
|
|
5
|
+
if (!isFinite(num)) return isNaN(num) ? ".nan" : num < 0 ? "-.inf" : ".inf";
|
|
6
|
+
let n = Object.is(value, -0) ? "-0" : JSON.stringify(value);
|
|
7
|
+
if (!format && minFractionDigits && (!tag || tag === "tag:yaml.org,2002:float") && /^\d/.test(n)) {
|
|
8
|
+
let i = n.indexOf(".");
|
|
9
|
+
if (i < 0) {
|
|
10
|
+
i = n.length;
|
|
11
|
+
n += ".";
|
|
12
|
+
}
|
|
13
|
+
let d = minFractionDigits - (n.length - i - 1);
|
|
14
|
+
while (d-- > 0) n += "0";
|
|
15
|
+
}
|
|
16
|
+
return n;
|
|
17
|
+
}
|
|
18
|
+
//#endregion
|
|
19
|
+
export { stringifyNumber };
|
package/dist/node_modules/.pnpm/yaml@2.8.3/node_modules/yaml/browser/dist/stringify/stringifyPair.js
ADDED
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
import { isCollection, isNode, isScalar, isSeq } from "../nodes/identity.js";
|
|
2
|
+
import { Scalar } from "../nodes/Scalar.js";
|
|
3
|
+
import { indentComment, lineComment } from "./stringifyComment.js";
|
|
4
|
+
import { stringify } from "./stringify.js";
|
|
5
|
+
//#region ../../node_modules/.pnpm/yaml@2.8.3/node_modules/yaml/browser/dist/stringify/stringifyPair.js
|
|
6
|
+
function stringifyPair({ key, value }, ctx, onComment, onChompKeep) {
|
|
7
|
+
const { allNullValues, doc, indent, indentStep, options: { commentString, indentSeq, simpleKeys } } = ctx;
|
|
8
|
+
let keyComment = isNode(key) && key.comment || null;
|
|
9
|
+
if (simpleKeys) {
|
|
10
|
+
if (keyComment) throw new Error("With simple keys, key nodes cannot have comments");
|
|
11
|
+
if (isCollection(key) || !isNode(key) && typeof key === "object") throw new Error("With simple keys, collection cannot be used as a key value");
|
|
12
|
+
}
|
|
13
|
+
let explicitKey = !simpleKeys && (!key || keyComment && value == null && !ctx.inFlow || isCollection(key) || (isScalar(key) ? key.type === Scalar.BLOCK_FOLDED || key.type === Scalar.BLOCK_LITERAL : typeof key === "object"));
|
|
14
|
+
ctx = Object.assign({}, ctx, {
|
|
15
|
+
allNullValues: false,
|
|
16
|
+
implicitKey: !explicitKey && (simpleKeys || !allNullValues),
|
|
17
|
+
indent: indent + indentStep
|
|
18
|
+
});
|
|
19
|
+
let keyCommentDone = false;
|
|
20
|
+
let chompKeep = false;
|
|
21
|
+
let str = stringify(key, ctx, () => keyCommentDone = true, () => chompKeep = true);
|
|
22
|
+
if (!explicitKey && !ctx.inFlow && str.length > 1024) {
|
|
23
|
+
if (simpleKeys) throw new Error("With simple keys, single line scalar must not span more than 1024 characters");
|
|
24
|
+
explicitKey = true;
|
|
25
|
+
}
|
|
26
|
+
if (ctx.inFlow) {
|
|
27
|
+
if (allNullValues || value == null) {
|
|
28
|
+
if (keyCommentDone && onComment) onComment();
|
|
29
|
+
return str === "" ? "?" : explicitKey ? `? ${str}` : str;
|
|
30
|
+
}
|
|
31
|
+
} else if (allNullValues && !simpleKeys || value == null && explicitKey) {
|
|
32
|
+
str = `? ${str}`;
|
|
33
|
+
if (keyComment && !keyCommentDone) str += lineComment(str, ctx.indent, commentString(keyComment));
|
|
34
|
+
else if (chompKeep && onChompKeep) onChompKeep();
|
|
35
|
+
return str;
|
|
36
|
+
}
|
|
37
|
+
if (keyCommentDone) keyComment = null;
|
|
38
|
+
if (explicitKey) {
|
|
39
|
+
if (keyComment) str += lineComment(str, ctx.indent, commentString(keyComment));
|
|
40
|
+
str = `? ${str}\n${indent}:`;
|
|
41
|
+
} else {
|
|
42
|
+
str = `${str}:`;
|
|
43
|
+
if (keyComment) str += lineComment(str, ctx.indent, commentString(keyComment));
|
|
44
|
+
}
|
|
45
|
+
let vsb, vcb, valueComment;
|
|
46
|
+
if (isNode(value)) {
|
|
47
|
+
vsb = !!value.spaceBefore;
|
|
48
|
+
vcb = value.commentBefore;
|
|
49
|
+
valueComment = value.comment;
|
|
50
|
+
} else {
|
|
51
|
+
vsb = false;
|
|
52
|
+
vcb = null;
|
|
53
|
+
valueComment = null;
|
|
54
|
+
if (value && typeof value === "object") value = doc.createNode(value);
|
|
55
|
+
}
|
|
56
|
+
ctx.implicitKey = false;
|
|
57
|
+
if (!explicitKey && !keyComment && isScalar(value)) ctx.indentAtStart = str.length + 1;
|
|
58
|
+
chompKeep = false;
|
|
59
|
+
if (!indentSeq && indentStep.length >= 2 && !ctx.inFlow && !explicitKey && isSeq(value) && !value.flow && !value.tag && !value.anchor) ctx.indent = ctx.indent.substring(2);
|
|
60
|
+
let valueCommentDone = false;
|
|
61
|
+
const valueStr = stringify(value, ctx, () => valueCommentDone = true, () => chompKeep = true);
|
|
62
|
+
let ws = " ";
|
|
63
|
+
if (keyComment || vsb || vcb) {
|
|
64
|
+
ws = vsb ? "\n" : "";
|
|
65
|
+
if (vcb) {
|
|
66
|
+
const cs = commentString(vcb);
|
|
67
|
+
ws += `\n${indentComment(cs, ctx.indent)}`;
|
|
68
|
+
}
|
|
69
|
+
if (valueStr === "" && !ctx.inFlow) {
|
|
70
|
+
if (ws === "\n" && valueComment) ws = "\n\n";
|
|
71
|
+
} else ws += `\n${ctx.indent}`;
|
|
72
|
+
} else if (!explicitKey && isCollection(value)) {
|
|
73
|
+
const vs0 = valueStr[0];
|
|
74
|
+
const nl0 = valueStr.indexOf("\n");
|
|
75
|
+
const hasNewline = nl0 !== -1;
|
|
76
|
+
const flow = ctx.inFlow ?? value.flow ?? value.items.length === 0;
|
|
77
|
+
if (hasNewline || !flow) {
|
|
78
|
+
let hasPropsLine = false;
|
|
79
|
+
if (hasNewline && (vs0 === "&" || vs0 === "!")) {
|
|
80
|
+
let sp0 = valueStr.indexOf(" ");
|
|
81
|
+
if (vs0 === "&" && sp0 !== -1 && sp0 < nl0 && valueStr[sp0 + 1] === "!") sp0 = valueStr.indexOf(" ", sp0 + 1);
|
|
82
|
+
if (sp0 === -1 || nl0 < sp0) hasPropsLine = true;
|
|
83
|
+
}
|
|
84
|
+
if (!hasPropsLine) ws = `\n${ctx.indent}`;
|
|
85
|
+
}
|
|
86
|
+
} else if (valueStr === "" || valueStr[0] === "\n") ws = "";
|
|
87
|
+
str += ws + valueStr;
|
|
88
|
+
if (ctx.inFlow) {
|
|
89
|
+
if (valueCommentDone && onComment) onComment();
|
|
90
|
+
} else if (valueComment && !valueCommentDone) str += lineComment(str, ctx.indent, commentString(valueComment));
|
|
91
|
+
else if (chompKeep && onChompKeep) onChompKeep();
|
|
92
|
+
return str;
|
|
93
|
+
}
|
|
94
|
+
//#endregion
|
|
95
|
+
export { stringifyPair };
|
|
@@ -0,0 +1,222 @@
|
|
|
1
|
+
import { Scalar } from "../nodes/Scalar.js";
|
|
2
|
+
import { FOLD_BLOCK, FOLD_FLOW, FOLD_QUOTED, foldFlowLines } from "./foldFlowLines.js";
|
|
3
|
+
//#region ../../node_modules/.pnpm/yaml@2.8.3/node_modules/yaml/browser/dist/stringify/stringifyString.js
|
|
4
|
+
const getFoldOptions = (ctx, isBlock) => ({
|
|
5
|
+
indentAtStart: isBlock ? ctx.indent.length : ctx.indentAtStart,
|
|
6
|
+
lineWidth: ctx.options.lineWidth,
|
|
7
|
+
minContentWidth: ctx.options.minContentWidth
|
|
8
|
+
});
|
|
9
|
+
const containsDocumentMarker = (str) => /^(%|---|\.\.\.)/m.test(str);
|
|
10
|
+
function lineLengthOverLimit(str, lineWidth, indentLength) {
|
|
11
|
+
if (!lineWidth || lineWidth < 0) return false;
|
|
12
|
+
const limit = lineWidth - indentLength;
|
|
13
|
+
const strLen = str.length;
|
|
14
|
+
if (strLen <= limit) return false;
|
|
15
|
+
for (let i = 0, start = 0; i < strLen; ++i) if (str[i] === "\n") {
|
|
16
|
+
if (i - start > limit) return true;
|
|
17
|
+
start = i + 1;
|
|
18
|
+
if (strLen - start <= limit) return false;
|
|
19
|
+
}
|
|
20
|
+
return true;
|
|
21
|
+
}
|
|
22
|
+
function doubleQuotedString(value, ctx) {
|
|
23
|
+
const json = JSON.stringify(value);
|
|
24
|
+
if (ctx.options.doubleQuotedAsJSON) return json;
|
|
25
|
+
const { implicitKey } = ctx;
|
|
26
|
+
const minMultiLineLength = ctx.options.doubleQuotedMinMultiLineLength;
|
|
27
|
+
const indent = ctx.indent || (containsDocumentMarker(value) ? " " : "");
|
|
28
|
+
let str = "";
|
|
29
|
+
let start = 0;
|
|
30
|
+
for (let i = 0, ch = json[i]; ch; ch = json[++i]) {
|
|
31
|
+
if (ch === " " && json[i + 1] === "\\" && json[i + 2] === "n") {
|
|
32
|
+
str += json.slice(start, i) + "\\ ";
|
|
33
|
+
i += 1;
|
|
34
|
+
start = i;
|
|
35
|
+
ch = "\\";
|
|
36
|
+
}
|
|
37
|
+
if (ch === "\\") switch (json[i + 1]) {
|
|
38
|
+
case "u":
|
|
39
|
+
{
|
|
40
|
+
str += json.slice(start, i);
|
|
41
|
+
const code = json.substr(i + 2, 4);
|
|
42
|
+
switch (code) {
|
|
43
|
+
case "0000":
|
|
44
|
+
str += "\\0";
|
|
45
|
+
break;
|
|
46
|
+
case "0007":
|
|
47
|
+
str += "\\a";
|
|
48
|
+
break;
|
|
49
|
+
case "000b":
|
|
50
|
+
str += "\\v";
|
|
51
|
+
break;
|
|
52
|
+
case "001b":
|
|
53
|
+
str += "\\e";
|
|
54
|
+
break;
|
|
55
|
+
case "0085":
|
|
56
|
+
str += "\\N";
|
|
57
|
+
break;
|
|
58
|
+
case "00a0":
|
|
59
|
+
str += "\\_";
|
|
60
|
+
break;
|
|
61
|
+
case "2028":
|
|
62
|
+
str += "\\L";
|
|
63
|
+
break;
|
|
64
|
+
case "2029":
|
|
65
|
+
str += "\\P";
|
|
66
|
+
break;
|
|
67
|
+
default: if (code.substr(0, 2) === "00") str += "\\x" + code.substr(2);
|
|
68
|
+
else str += json.substr(i, 6);
|
|
69
|
+
}
|
|
70
|
+
i += 5;
|
|
71
|
+
start = i + 1;
|
|
72
|
+
}
|
|
73
|
+
break;
|
|
74
|
+
case "n":
|
|
75
|
+
if (implicitKey || json[i + 2] === "\"" || json.length < minMultiLineLength) i += 1;
|
|
76
|
+
else {
|
|
77
|
+
str += json.slice(start, i) + "\n\n";
|
|
78
|
+
while (json[i + 2] === "\\" && json[i + 3] === "n" && json[i + 4] !== "\"") {
|
|
79
|
+
str += "\n";
|
|
80
|
+
i += 2;
|
|
81
|
+
}
|
|
82
|
+
str += indent;
|
|
83
|
+
if (json[i + 2] === " ") str += "\\";
|
|
84
|
+
i += 1;
|
|
85
|
+
start = i + 1;
|
|
86
|
+
}
|
|
87
|
+
break;
|
|
88
|
+
default: i += 1;
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
str = start ? str + json.slice(start) : json;
|
|
92
|
+
return implicitKey ? str : foldFlowLines(str, indent, FOLD_QUOTED, getFoldOptions(ctx, false));
|
|
93
|
+
}
|
|
94
|
+
function singleQuotedString(value, ctx) {
|
|
95
|
+
if (ctx.options.singleQuote === false || ctx.implicitKey && value.includes("\n") || /[ \t]\n|\n[ \t]/.test(value)) return doubleQuotedString(value, ctx);
|
|
96
|
+
const indent = ctx.indent || (containsDocumentMarker(value) ? " " : "");
|
|
97
|
+
const res = "'" + value.replace(/'/g, "''").replace(/\n+/g, `$&\n${indent}`) + "'";
|
|
98
|
+
return ctx.implicitKey ? res : foldFlowLines(res, indent, FOLD_FLOW, getFoldOptions(ctx, false));
|
|
99
|
+
}
|
|
100
|
+
function quotedString(value, ctx) {
|
|
101
|
+
const { singleQuote } = ctx.options;
|
|
102
|
+
let qs;
|
|
103
|
+
if (singleQuote === false) qs = doubleQuotedString;
|
|
104
|
+
else {
|
|
105
|
+
const hasDouble = value.includes("\"");
|
|
106
|
+
const hasSingle = value.includes("'");
|
|
107
|
+
if (hasDouble && !hasSingle) qs = singleQuotedString;
|
|
108
|
+
else if (hasSingle && !hasDouble) qs = doubleQuotedString;
|
|
109
|
+
else qs = singleQuote ? singleQuotedString : doubleQuotedString;
|
|
110
|
+
}
|
|
111
|
+
return qs(value, ctx);
|
|
112
|
+
}
|
|
113
|
+
let blockEndNewlines;
|
|
114
|
+
try {
|
|
115
|
+
blockEndNewlines = /* @__PURE__ */ new RegExp("(^|(?<!\n))\n+(?!\n|$)", "g");
|
|
116
|
+
} catch {
|
|
117
|
+
blockEndNewlines = /\n+(?!\n|$)/g;
|
|
118
|
+
}
|
|
119
|
+
function blockString({ comment, type, value }, ctx, onComment, onChompKeep) {
|
|
120
|
+
const { blockQuote, commentString, lineWidth } = ctx.options;
|
|
121
|
+
if (!blockQuote || /\n[\t ]+$/.test(value)) return quotedString(value, ctx);
|
|
122
|
+
const indent = ctx.indent || (ctx.forceBlockIndent || containsDocumentMarker(value) ? " " : "");
|
|
123
|
+
const literal = blockQuote === "literal" ? true : blockQuote === "folded" || type === Scalar.BLOCK_FOLDED ? false : type === Scalar.BLOCK_LITERAL ? true : !lineLengthOverLimit(value, lineWidth, indent.length);
|
|
124
|
+
if (!value) return literal ? "|\n" : ">\n";
|
|
125
|
+
let chomp;
|
|
126
|
+
let endStart;
|
|
127
|
+
for (endStart = value.length; endStart > 0; --endStart) {
|
|
128
|
+
const ch = value[endStart - 1];
|
|
129
|
+
if (ch !== "\n" && ch !== " " && ch !== " ") break;
|
|
130
|
+
}
|
|
131
|
+
let end = value.substring(endStart);
|
|
132
|
+
const endNlPos = end.indexOf("\n");
|
|
133
|
+
if (endNlPos === -1) chomp = "-";
|
|
134
|
+
else if (value === end || endNlPos !== end.length - 1) {
|
|
135
|
+
chomp = "+";
|
|
136
|
+
if (onChompKeep) onChompKeep();
|
|
137
|
+
} else chomp = "";
|
|
138
|
+
if (end) {
|
|
139
|
+
value = value.slice(0, -end.length);
|
|
140
|
+
if (end[end.length - 1] === "\n") end = end.slice(0, -1);
|
|
141
|
+
end = end.replace(blockEndNewlines, `$&${indent}`);
|
|
142
|
+
}
|
|
143
|
+
let startWithSpace = false;
|
|
144
|
+
let startEnd;
|
|
145
|
+
let startNlPos = -1;
|
|
146
|
+
for (startEnd = 0; startEnd < value.length; ++startEnd) {
|
|
147
|
+
const ch = value[startEnd];
|
|
148
|
+
if (ch === " ") startWithSpace = true;
|
|
149
|
+
else if (ch === "\n") startNlPos = startEnd;
|
|
150
|
+
else break;
|
|
151
|
+
}
|
|
152
|
+
let start = value.substring(0, startNlPos < startEnd ? startNlPos + 1 : startEnd);
|
|
153
|
+
if (start) {
|
|
154
|
+
value = value.substring(start.length);
|
|
155
|
+
start = start.replace(/\n+/g, `$&${indent}`);
|
|
156
|
+
}
|
|
157
|
+
let header = (startWithSpace ? indent ? "2" : "1" : "") + chomp;
|
|
158
|
+
if (comment) {
|
|
159
|
+
header += " " + commentString(comment.replace(/ ?[\r\n]+/g, " "));
|
|
160
|
+
if (onComment) onComment();
|
|
161
|
+
}
|
|
162
|
+
if (!literal) {
|
|
163
|
+
const foldedValue = value.replace(/\n+/g, "\n$&").replace(/(?:^|\n)([\t ].*)(?:([\n\t ]*)\n(?![\n\t ]))?/g, "$1$2").replace(/\n+/g, `$&${indent}`);
|
|
164
|
+
let literalFallback = false;
|
|
165
|
+
const foldOptions = getFoldOptions(ctx, true);
|
|
166
|
+
if (blockQuote !== "folded" && type !== Scalar.BLOCK_FOLDED) foldOptions.onOverflow = () => {
|
|
167
|
+
literalFallback = true;
|
|
168
|
+
};
|
|
169
|
+
const body = foldFlowLines(`${start}${foldedValue}${end}`, indent, FOLD_BLOCK, foldOptions);
|
|
170
|
+
if (!literalFallback) return `>${header}\n${indent}${body}`;
|
|
171
|
+
}
|
|
172
|
+
value = value.replace(/\n+/g, `$&${indent}`);
|
|
173
|
+
return `|${header}\n${indent}${start}${value}${end}`;
|
|
174
|
+
}
|
|
175
|
+
function plainString(item, ctx, onComment, onChompKeep) {
|
|
176
|
+
const { type, value } = item;
|
|
177
|
+
const { actualString, implicitKey, indent, indentStep, inFlow } = ctx;
|
|
178
|
+
if (implicitKey && value.includes("\n") || inFlow && /[[\]{},]/.test(value)) return quotedString(value, ctx);
|
|
179
|
+
if (/^[\n\t ,[\]{}#&*!|>'"%@`]|^[?-]$|^[?-][ \t]|[\n:][ \t]|[ \t]\n|[\n\t ]#|[\n\t :]$/.test(value)) return implicitKey || inFlow || !value.includes("\n") ? quotedString(value, ctx) : blockString(item, ctx, onComment, onChompKeep);
|
|
180
|
+
if (!implicitKey && !inFlow && type !== Scalar.PLAIN && value.includes("\n")) return blockString(item, ctx, onComment, onChompKeep);
|
|
181
|
+
if (containsDocumentMarker(value)) {
|
|
182
|
+
if (indent === "") {
|
|
183
|
+
ctx.forceBlockIndent = true;
|
|
184
|
+
return blockString(item, ctx, onComment, onChompKeep);
|
|
185
|
+
} else if (implicitKey && indent === indentStep) return quotedString(value, ctx);
|
|
186
|
+
}
|
|
187
|
+
const str = value.replace(/\n+/g, `$&\n${indent}`);
|
|
188
|
+
if (actualString) {
|
|
189
|
+
const test = (tag) => tag.default && tag.tag !== "tag:yaml.org,2002:str" && tag.test?.test(str);
|
|
190
|
+
const { compat, tags } = ctx.doc.schema;
|
|
191
|
+
if (tags.some(test) || compat?.some(test)) return quotedString(value, ctx);
|
|
192
|
+
}
|
|
193
|
+
return implicitKey ? str : foldFlowLines(str, indent, FOLD_FLOW, getFoldOptions(ctx, false));
|
|
194
|
+
}
|
|
195
|
+
function stringifyString(item, ctx, onComment, onChompKeep) {
|
|
196
|
+
const { implicitKey, inFlow } = ctx;
|
|
197
|
+
const ss = typeof item.value === "string" ? item : Object.assign({}, item, { value: String(item.value) });
|
|
198
|
+
let { type } = item;
|
|
199
|
+
if (type !== Scalar.QUOTE_DOUBLE) {
|
|
200
|
+
if (/[\x00-\x08\x0b-\x1f\x7f-\x9f\u{D800}-\u{DFFF}]/u.test(ss.value)) type = Scalar.QUOTE_DOUBLE;
|
|
201
|
+
}
|
|
202
|
+
const _stringify = (_type) => {
|
|
203
|
+
switch (_type) {
|
|
204
|
+
case Scalar.BLOCK_FOLDED:
|
|
205
|
+
case Scalar.BLOCK_LITERAL: return implicitKey || inFlow ? quotedString(ss.value, ctx) : blockString(ss, ctx, onComment, onChompKeep);
|
|
206
|
+
case Scalar.QUOTE_DOUBLE: return doubleQuotedString(ss.value, ctx);
|
|
207
|
+
case Scalar.QUOTE_SINGLE: return singleQuotedString(ss.value, ctx);
|
|
208
|
+
case Scalar.PLAIN: return plainString(ss, ctx, onComment, onChompKeep);
|
|
209
|
+
default: return null;
|
|
210
|
+
}
|
|
211
|
+
};
|
|
212
|
+
let res = _stringify(type);
|
|
213
|
+
if (res === null) {
|
|
214
|
+
const { defaultKeyType, defaultStringType } = ctx.options;
|
|
215
|
+
const t = implicitKey && defaultKeyType || defaultStringType;
|
|
216
|
+
res = _stringify(t);
|
|
217
|
+
if (res === null) throw new Error(`Unsupported default string type ${t}`);
|
|
218
|
+
}
|
|
219
|
+
return res;
|
|
220
|
+
}
|
|
221
|
+
//#endregion
|
|
222
|
+
export { stringifyString };
|
|
@@ -0,0 +1,187 @@
|
|
|
1
|
+
import { isAlias, isCollection, isDocument, isMap, isNode, isPair, isScalar, isSeq } from "./nodes/identity.js";
|
|
2
|
+
//#region ../../node_modules/.pnpm/yaml@2.8.3/node_modules/yaml/browser/dist/visit.js
|
|
3
|
+
const BREAK = Symbol("break visit");
|
|
4
|
+
const SKIP = Symbol("skip children");
|
|
5
|
+
const REMOVE = Symbol("remove node");
|
|
6
|
+
/**
|
|
7
|
+
* Apply a visitor to an AST node or document.
|
|
8
|
+
*
|
|
9
|
+
* Walks through the tree (depth-first) starting from `node`, calling a
|
|
10
|
+
* `visitor` function with three arguments:
|
|
11
|
+
* - `key`: For sequence values and map `Pair`, the node's index in the
|
|
12
|
+
* collection. Within a `Pair`, `'key'` or `'value'`, correspondingly.
|
|
13
|
+
* `null` for the root node.
|
|
14
|
+
* - `node`: The current node.
|
|
15
|
+
* - `path`: The ancestry of the current node.
|
|
16
|
+
*
|
|
17
|
+
* The return value of the visitor may be used to control the traversal:
|
|
18
|
+
* - `undefined` (default): Do nothing and continue
|
|
19
|
+
* - `visit.SKIP`: Do not visit the children of this node, continue with next
|
|
20
|
+
* sibling
|
|
21
|
+
* - `visit.BREAK`: Terminate traversal completely
|
|
22
|
+
* - `visit.REMOVE`: Remove the current node, then continue with the next one
|
|
23
|
+
* - `Node`: Replace the current node, then continue by visiting it
|
|
24
|
+
* - `number`: While iterating the items of a sequence or map, set the index
|
|
25
|
+
* of the next step. This is useful especially if the index of the current
|
|
26
|
+
* node has changed.
|
|
27
|
+
*
|
|
28
|
+
* If `visitor` is a single function, it will be called with all values
|
|
29
|
+
* encountered in the tree, including e.g. `null` values. Alternatively,
|
|
30
|
+
* separate visitor functions may be defined for each `Map`, `Pair`, `Seq`,
|
|
31
|
+
* `Alias` and `Scalar` node. To define the same visitor function for more than
|
|
32
|
+
* one node type, use the `Collection` (map and seq), `Value` (map, seq & scalar)
|
|
33
|
+
* and `Node` (alias, map, seq & scalar) targets. Of all these, only the most
|
|
34
|
+
* specific defined one will be used for each node.
|
|
35
|
+
*/
|
|
36
|
+
function visit(node, visitor) {
|
|
37
|
+
const visitor_ = initVisitor(visitor);
|
|
38
|
+
if (isDocument(node)) {
|
|
39
|
+
if (visit_(null, node.contents, visitor_, Object.freeze([node])) === REMOVE) node.contents = null;
|
|
40
|
+
} else visit_(null, node, visitor_, Object.freeze([]));
|
|
41
|
+
}
|
|
42
|
+
/** Terminate visit traversal completely */
|
|
43
|
+
visit.BREAK = BREAK;
|
|
44
|
+
/** Do not visit the children of the current node */
|
|
45
|
+
visit.SKIP = SKIP;
|
|
46
|
+
/** Remove the current node */
|
|
47
|
+
visit.REMOVE = REMOVE;
|
|
48
|
+
function visit_(key, node, visitor, path) {
|
|
49
|
+
const ctrl = callVisitor(key, node, visitor, path);
|
|
50
|
+
if (isNode(ctrl) || isPair(ctrl)) {
|
|
51
|
+
replaceNode(key, path, ctrl);
|
|
52
|
+
return visit_(key, ctrl, visitor, path);
|
|
53
|
+
}
|
|
54
|
+
if (typeof ctrl !== "symbol") {
|
|
55
|
+
if (isCollection(node)) {
|
|
56
|
+
path = Object.freeze(path.concat(node));
|
|
57
|
+
for (let i = 0; i < node.items.length; ++i) {
|
|
58
|
+
const ci = visit_(i, node.items[i], visitor, path);
|
|
59
|
+
if (typeof ci === "number") i = ci - 1;
|
|
60
|
+
else if (ci === BREAK) return BREAK;
|
|
61
|
+
else if (ci === REMOVE) {
|
|
62
|
+
node.items.splice(i, 1);
|
|
63
|
+
i -= 1;
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
} else if (isPair(node)) {
|
|
67
|
+
path = Object.freeze(path.concat(node));
|
|
68
|
+
const ck = visit_("key", node.key, visitor, path);
|
|
69
|
+
if (ck === BREAK) return BREAK;
|
|
70
|
+
else if (ck === REMOVE) node.key = null;
|
|
71
|
+
const cv = visit_("value", node.value, visitor, path);
|
|
72
|
+
if (cv === BREAK) return BREAK;
|
|
73
|
+
else if (cv === REMOVE) node.value = null;
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
return ctrl;
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* Apply an async visitor to an AST node or document.
|
|
80
|
+
*
|
|
81
|
+
* Walks through the tree (depth-first) starting from `node`, calling a
|
|
82
|
+
* `visitor` function with three arguments:
|
|
83
|
+
* - `key`: For sequence values and map `Pair`, the node's index in the
|
|
84
|
+
* collection. Within a `Pair`, `'key'` or `'value'`, correspondingly.
|
|
85
|
+
* `null` for the root node.
|
|
86
|
+
* - `node`: The current node.
|
|
87
|
+
* - `path`: The ancestry of the current node.
|
|
88
|
+
*
|
|
89
|
+
* The return value of the visitor may be used to control the traversal:
|
|
90
|
+
* - `Promise`: Must resolve to one of the following values
|
|
91
|
+
* - `undefined` (default): Do nothing and continue
|
|
92
|
+
* - `visit.SKIP`: Do not visit the children of this node, continue with next
|
|
93
|
+
* sibling
|
|
94
|
+
* - `visit.BREAK`: Terminate traversal completely
|
|
95
|
+
* - `visit.REMOVE`: Remove the current node, then continue with the next one
|
|
96
|
+
* - `Node`: Replace the current node, then continue by visiting it
|
|
97
|
+
* - `number`: While iterating the items of a sequence or map, set the index
|
|
98
|
+
* of the next step. This is useful especially if the index of the current
|
|
99
|
+
* node has changed.
|
|
100
|
+
*
|
|
101
|
+
* If `visitor` is a single function, it will be called with all values
|
|
102
|
+
* encountered in the tree, including e.g. `null` values. Alternatively,
|
|
103
|
+
* separate visitor functions may be defined for each `Map`, `Pair`, `Seq`,
|
|
104
|
+
* `Alias` and `Scalar` node. To define the same visitor function for more than
|
|
105
|
+
* one node type, use the `Collection` (map and seq), `Value` (map, seq & scalar)
|
|
106
|
+
* and `Node` (alias, map, seq & scalar) targets. Of all these, only the most
|
|
107
|
+
* specific defined one will be used for each node.
|
|
108
|
+
*/
|
|
109
|
+
async function visitAsync(node, visitor) {
|
|
110
|
+
const visitor_ = initVisitor(visitor);
|
|
111
|
+
if (isDocument(node)) {
|
|
112
|
+
if (await visitAsync_(null, node.contents, visitor_, Object.freeze([node])) === REMOVE) node.contents = null;
|
|
113
|
+
} else await visitAsync_(null, node, visitor_, Object.freeze([]));
|
|
114
|
+
}
|
|
115
|
+
/** Terminate visit traversal completely */
|
|
116
|
+
visitAsync.BREAK = BREAK;
|
|
117
|
+
/** Do not visit the children of the current node */
|
|
118
|
+
visitAsync.SKIP = SKIP;
|
|
119
|
+
/** Remove the current node */
|
|
120
|
+
visitAsync.REMOVE = REMOVE;
|
|
121
|
+
async function visitAsync_(key, node, visitor, path) {
|
|
122
|
+
const ctrl = await callVisitor(key, node, visitor, path);
|
|
123
|
+
if (isNode(ctrl) || isPair(ctrl)) {
|
|
124
|
+
replaceNode(key, path, ctrl);
|
|
125
|
+
return visitAsync_(key, ctrl, visitor, path);
|
|
126
|
+
}
|
|
127
|
+
if (typeof ctrl !== "symbol") {
|
|
128
|
+
if (isCollection(node)) {
|
|
129
|
+
path = Object.freeze(path.concat(node));
|
|
130
|
+
for (let i = 0; i < node.items.length; ++i) {
|
|
131
|
+
const ci = await visitAsync_(i, node.items[i], visitor, path);
|
|
132
|
+
if (typeof ci === "number") i = ci - 1;
|
|
133
|
+
else if (ci === BREAK) return BREAK;
|
|
134
|
+
else if (ci === REMOVE) {
|
|
135
|
+
node.items.splice(i, 1);
|
|
136
|
+
i -= 1;
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
} else if (isPair(node)) {
|
|
140
|
+
path = Object.freeze(path.concat(node));
|
|
141
|
+
const ck = await visitAsync_("key", node.key, visitor, path);
|
|
142
|
+
if (ck === BREAK) return BREAK;
|
|
143
|
+
else if (ck === REMOVE) node.key = null;
|
|
144
|
+
const cv = await visitAsync_("value", node.value, visitor, path);
|
|
145
|
+
if (cv === BREAK) return BREAK;
|
|
146
|
+
else if (cv === REMOVE) node.value = null;
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
return ctrl;
|
|
150
|
+
}
|
|
151
|
+
function initVisitor(visitor) {
|
|
152
|
+
if (typeof visitor === "object" && (visitor.Collection || visitor.Node || visitor.Value)) return Object.assign({
|
|
153
|
+
Alias: visitor.Node,
|
|
154
|
+
Map: visitor.Node,
|
|
155
|
+
Scalar: visitor.Node,
|
|
156
|
+
Seq: visitor.Node
|
|
157
|
+
}, visitor.Value && {
|
|
158
|
+
Map: visitor.Value,
|
|
159
|
+
Scalar: visitor.Value,
|
|
160
|
+
Seq: visitor.Value
|
|
161
|
+
}, visitor.Collection && {
|
|
162
|
+
Map: visitor.Collection,
|
|
163
|
+
Seq: visitor.Collection
|
|
164
|
+
}, visitor);
|
|
165
|
+
return visitor;
|
|
166
|
+
}
|
|
167
|
+
function callVisitor(key, node, visitor, path) {
|
|
168
|
+
if (typeof visitor === "function") return visitor(key, node, path);
|
|
169
|
+
if (isMap(node)) return visitor.Map?.(key, node, path);
|
|
170
|
+
if (isSeq(node)) return visitor.Seq?.(key, node, path);
|
|
171
|
+
if (isPair(node)) return visitor.Pair?.(key, node, path);
|
|
172
|
+
if (isScalar(node)) return visitor.Scalar?.(key, node, path);
|
|
173
|
+
if (isAlias(node)) return visitor.Alias?.(key, node, path);
|
|
174
|
+
}
|
|
175
|
+
function replaceNode(key, path, node) {
|
|
176
|
+
const parent = path[path.length - 1];
|
|
177
|
+
if (isCollection(parent)) parent.items[key] = node;
|
|
178
|
+
else if (isPair(parent)) if (key === "key") parent.key = node;
|
|
179
|
+
else parent.value = node;
|
|
180
|
+
else if (isDocument(parent)) parent.contents = node;
|
|
181
|
+
else {
|
|
182
|
+
const pt = isAlias(parent) ? "alias" : "scalar";
|
|
183
|
+
throw new Error(`Cannot replace node with ${pt} parent`);
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
//#endregion
|
|
187
|
+
export { visit, visitAsync };
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import "./dist/nodes/identity.js";
|
|
2
|
+
import "./dist/visit.js";
|
|
3
|
+
import "./dist/nodes/Alias.js";
|
|
4
|
+
import "./dist/nodes/Scalar.js";
|
|
5
|
+
import "./dist/nodes/Pair.js";
|
|
6
|
+
import "./dist/nodes/YAMLMap.js";
|
|
7
|
+
import "./dist/nodes/YAMLSeq.js";
|
|
8
|
+
import "./dist/schema/Schema.js";
|
|
9
|
+
import "./dist/doc/Document.js";
|
|
10
|
+
import "./dist/errors.js";
|
|
11
|
+
import "./dist/compose/composer.js";
|
|
12
|
+
import "./dist/parse/lexer.js";
|
|
13
|
+
import "./dist/parse/line-counter.js";
|
|
14
|
+
import "./dist/parse/parser.js";
|
|
15
|
+
import "./dist/public-api.js";
|
|
16
|
+
import "./dist/index.js";
|