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,91 @@
|
|
|
1
|
+
import { ALIAS, hasAnchor, isAlias, isCollection, isPair } from "./identity.js";
|
|
2
|
+
import { visit } from "../visit.js";
|
|
3
|
+
import { anchorIsValid } from "../doc/anchors.js";
|
|
4
|
+
import { toJS } from "./toJS.js";
|
|
5
|
+
import { NodeBase } from "./Node.js";
|
|
6
|
+
//#region ../../node_modules/.pnpm/yaml@2.8.3/node_modules/yaml/browser/dist/nodes/Alias.js
|
|
7
|
+
var Alias = class extends NodeBase {
|
|
8
|
+
constructor(source) {
|
|
9
|
+
super(ALIAS);
|
|
10
|
+
this.source = source;
|
|
11
|
+
Object.defineProperty(this, "tag", { set() {
|
|
12
|
+
throw new Error("Alias nodes cannot have tags");
|
|
13
|
+
} });
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Resolve the value of this alias within `doc`, finding the last
|
|
17
|
+
* instance of the `source` anchor before this node.
|
|
18
|
+
*/
|
|
19
|
+
resolve(doc, ctx) {
|
|
20
|
+
let nodes;
|
|
21
|
+
if (ctx?.aliasResolveCache) nodes = ctx.aliasResolveCache;
|
|
22
|
+
else {
|
|
23
|
+
nodes = [];
|
|
24
|
+
visit(doc, { Node: (_key, node) => {
|
|
25
|
+
if (isAlias(node) || hasAnchor(node)) nodes.push(node);
|
|
26
|
+
} });
|
|
27
|
+
if (ctx) ctx.aliasResolveCache = nodes;
|
|
28
|
+
}
|
|
29
|
+
let found = void 0;
|
|
30
|
+
for (const node of nodes) {
|
|
31
|
+
if (node === this) break;
|
|
32
|
+
if (node.anchor === this.source) found = node;
|
|
33
|
+
}
|
|
34
|
+
return found;
|
|
35
|
+
}
|
|
36
|
+
toJSON(_arg, ctx) {
|
|
37
|
+
if (!ctx) return { source: this.source };
|
|
38
|
+
const { anchors, doc, maxAliasCount } = ctx;
|
|
39
|
+
const source = this.resolve(doc, ctx);
|
|
40
|
+
if (!source) {
|
|
41
|
+
const msg = `Unresolved alias (the anchor must be set before the alias): ${this.source}`;
|
|
42
|
+
throw new ReferenceError(msg);
|
|
43
|
+
}
|
|
44
|
+
let data = anchors.get(source);
|
|
45
|
+
if (!data) {
|
|
46
|
+
toJS(source, null, ctx);
|
|
47
|
+
data = anchors.get(source);
|
|
48
|
+
}
|
|
49
|
+
/* istanbul ignore if */
|
|
50
|
+
if (data?.res === void 0) throw new ReferenceError("This should not happen: Alias anchor was not resolved?");
|
|
51
|
+
if (maxAliasCount >= 0) {
|
|
52
|
+
data.count += 1;
|
|
53
|
+
if (data.aliasCount === 0) data.aliasCount = getAliasCount(doc, source, anchors);
|
|
54
|
+
if (data.count * data.aliasCount > maxAliasCount) throw new ReferenceError("Excessive alias count indicates a resource exhaustion attack");
|
|
55
|
+
}
|
|
56
|
+
return data.res;
|
|
57
|
+
}
|
|
58
|
+
toString(ctx, _onComment, _onChompKeep) {
|
|
59
|
+
const src = `*${this.source}`;
|
|
60
|
+
if (ctx) {
|
|
61
|
+
anchorIsValid(this.source);
|
|
62
|
+
if (ctx.options.verifyAliasOrder && !ctx.anchors.has(this.source)) {
|
|
63
|
+
const msg = `Unresolved alias (the anchor must be set before the alias): ${this.source}`;
|
|
64
|
+
throw new Error(msg);
|
|
65
|
+
}
|
|
66
|
+
if (ctx.implicitKey) return `${src} `;
|
|
67
|
+
}
|
|
68
|
+
return src;
|
|
69
|
+
}
|
|
70
|
+
};
|
|
71
|
+
function getAliasCount(doc, node, anchors) {
|
|
72
|
+
if (isAlias(node)) {
|
|
73
|
+
const source = node.resolve(doc);
|
|
74
|
+
const anchor = anchors && source && anchors.get(source);
|
|
75
|
+
return anchor ? anchor.count * anchor.aliasCount : 0;
|
|
76
|
+
} else if (isCollection(node)) {
|
|
77
|
+
let count = 0;
|
|
78
|
+
for (const item of node.items) {
|
|
79
|
+
const c = getAliasCount(doc, item, anchors);
|
|
80
|
+
if (c > count) count = c;
|
|
81
|
+
}
|
|
82
|
+
return count;
|
|
83
|
+
} else if (isPair(node)) {
|
|
84
|
+
const kc = getAliasCount(doc, node.key, anchors);
|
|
85
|
+
const vc = getAliasCount(doc, node.value, anchors);
|
|
86
|
+
return Math.max(kc, vc);
|
|
87
|
+
}
|
|
88
|
+
return 1;
|
|
89
|
+
}
|
|
90
|
+
//#endregion
|
|
91
|
+
export { Alias };
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
import { isCollection, isNode, isPair, isScalar } from "./identity.js";
|
|
2
|
+
import { NodeBase } from "./Node.js";
|
|
3
|
+
import { createNode } from "../doc/createNode.js";
|
|
4
|
+
//#region ../../node_modules/.pnpm/yaml@2.8.3/node_modules/yaml/browser/dist/nodes/Collection.js
|
|
5
|
+
function collectionFromPath(schema, path, value) {
|
|
6
|
+
let v = value;
|
|
7
|
+
for (let i = path.length - 1; i >= 0; --i) {
|
|
8
|
+
const k = path[i];
|
|
9
|
+
if (typeof k === "number" && Number.isInteger(k) && k >= 0) {
|
|
10
|
+
const a = [];
|
|
11
|
+
a[k] = v;
|
|
12
|
+
v = a;
|
|
13
|
+
} else v = new Map([[k, v]]);
|
|
14
|
+
}
|
|
15
|
+
return createNode(v, void 0, {
|
|
16
|
+
aliasDuplicateObjects: false,
|
|
17
|
+
keepUndefined: false,
|
|
18
|
+
onAnchor: () => {
|
|
19
|
+
throw new Error("This should not happen, please report a bug.");
|
|
20
|
+
},
|
|
21
|
+
schema,
|
|
22
|
+
sourceObjects: /* @__PURE__ */ new Map()
|
|
23
|
+
});
|
|
24
|
+
}
|
|
25
|
+
const isEmptyPath = (path) => path == null || typeof path === "object" && !!path[Symbol.iterator]().next().done;
|
|
26
|
+
var Collection = class extends NodeBase {
|
|
27
|
+
constructor(type, schema) {
|
|
28
|
+
super(type);
|
|
29
|
+
Object.defineProperty(this, "schema", {
|
|
30
|
+
value: schema,
|
|
31
|
+
configurable: true,
|
|
32
|
+
enumerable: false,
|
|
33
|
+
writable: true
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Create a copy of this collection.
|
|
38
|
+
*
|
|
39
|
+
* @param schema - If defined, overwrites the original's schema
|
|
40
|
+
*/
|
|
41
|
+
clone(schema) {
|
|
42
|
+
const copy = Object.create(Object.getPrototypeOf(this), Object.getOwnPropertyDescriptors(this));
|
|
43
|
+
if (schema) copy.schema = schema;
|
|
44
|
+
copy.items = copy.items.map((it) => isNode(it) || isPair(it) ? it.clone(schema) : it);
|
|
45
|
+
if (this.range) copy.range = this.range.slice();
|
|
46
|
+
return copy;
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Adds a value to the collection. For `!!map` and `!!omap` the value must
|
|
50
|
+
* be a Pair instance or a `{ key, value }` object, which may not have a key
|
|
51
|
+
* that already exists in the map.
|
|
52
|
+
*/
|
|
53
|
+
addIn(path, value) {
|
|
54
|
+
if (isEmptyPath(path)) this.add(value);
|
|
55
|
+
else {
|
|
56
|
+
const [key, ...rest] = path;
|
|
57
|
+
const node = this.get(key, true);
|
|
58
|
+
if (isCollection(node)) node.addIn(rest, value);
|
|
59
|
+
else if (node === void 0 && this.schema) this.set(key, collectionFromPath(this.schema, rest, value));
|
|
60
|
+
else throw new Error(`Expected YAML collection at ${key}. Remaining path: ${rest}`);
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* Removes a value from the collection.
|
|
65
|
+
* @returns `true` if the item was found and removed.
|
|
66
|
+
*/
|
|
67
|
+
deleteIn(path) {
|
|
68
|
+
const [key, ...rest] = path;
|
|
69
|
+
if (rest.length === 0) return this.delete(key);
|
|
70
|
+
const node = this.get(key, true);
|
|
71
|
+
if (isCollection(node)) return node.deleteIn(rest);
|
|
72
|
+
else throw new Error(`Expected YAML collection at ${key}. Remaining path: ${rest}`);
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* Returns item at `key`, or `undefined` if not found. By default unwraps
|
|
76
|
+
* scalar values from their surrounding node; to disable set `keepScalar` to
|
|
77
|
+
* `true` (collections are always returned intact).
|
|
78
|
+
*/
|
|
79
|
+
getIn(path, keepScalar) {
|
|
80
|
+
const [key, ...rest] = path;
|
|
81
|
+
const node = this.get(key, true);
|
|
82
|
+
if (rest.length === 0) return !keepScalar && isScalar(node) ? node.value : node;
|
|
83
|
+
else return isCollection(node) ? node.getIn(rest, keepScalar) : void 0;
|
|
84
|
+
}
|
|
85
|
+
hasAllNullValues(allowScalar) {
|
|
86
|
+
return this.items.every((node) => {
|
|
87
|
+
if (!isPair(node)) return false;
|
|
88
|
+
const n = node.value;
|
|
89
|
+
return n == null || allowScalar && isScalar(n) && n.value == null && !n.commentBefore && !n.comment && !n.tag;
|
|
90
|
+
});
|
|
91
|
+
}
|
|
92
|
+
/**
|
|
93
|
+
* Checks if the collection includes a value with the key `key`.
|
|
94
|
+
*/
|
|
95
|
+
hasIn(path) {
|
|
96
|
+
const [key, ...rest] = path;
|
|
97
|
+
if (rest.length === 0) return this.has(key);
|
|
98
|
+
const node = this.get(key, true);
|
|
99
|
+
return isCollection(node) ? node.hasIn(rest) : false;
|
|
100
|
+
}
|
|
101
|
+
/**
|
|
102
|
+
* Sets a value in this collection. For `!!set`, `value` needs to be a
|
|
103
|
+
* boolean to add/remove the item from the set.
|
|
104
|
+
*/
|
|
105
|
+
setIn(path, value) {
|
|
106
|
+
const [key, ...rest] = path;
|
|
107
|
+
if (rest.length === 0) this.set(key, value);
|
|
108
|
+
else {
|
|
109
|
+
const node = this.get(key, true);
|
|
110
|
+
if (isCollection(node)) node.setIn(rest, value);
|
|
111
|
+
else if (node === void 0 && this.schema) this.set(key, collectionFromPath(this.schema, rest, value));
|
|
112
|
+
else throw new Error(`Expected YAML collection at ${key}. Remaining path: ${rest}`);
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
};
|
|
116
|
+
//#endregion
|
|
117
|
+
export { Collection, collectionFromPath, isEmptyPath };
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { NODE_TYPE, isDocument } from "./identity.js";
|
|
2
|
+
import { applyReviver } from "../doc/applyReviver.js";
|
|
3
|
+
import { toJS } from "./toJS.js";
|
|
4
|
+
//#region ../../node_modules/.pnpm/yaml@2.8.3/node_modules/yaml/browser/dist/nodes/Node.js
|
|
5
|
+
var NodeBase = class {
|
|
6
|
+
constructor(type) {
|
|
7
|
+
Object.defineProperty(this, NODE_TYPE, { value: type });
|
|
8
|
+
}
|
|
9
|
+
/** Create a copy of this node. */
|
|
10
|
+
clone() {
|
|
11
|
+
const copy = Object.create(Object.getPrototypeOf(this), Object.getOwnPropertyDescriptors(this));
|
|
12
|
+
if (this.range) copy.range = this.range.slice();
|
|
13
|
+
return copy;
|
|
14
|
+
}
|
|
15
|
+
/** A plain JavaScript representation of this node. */
|
|
16
|
+
toJS(doc, { mapAsMap, maxAliasCount, onAnchor, reviver } = {}) {
|
|
17
|
+
if (!isDocument(doc)) throw new TypeError("A document argument is required");
|
|
18
|
+
const ctx = {
|
|
19
|
+
anchors: /* @__PURE__ */ new Map(),
|
|
20
|
+
doc,
|
|
21
|
+
keep: true,
|
|
22
|
+
mapAsMap: mapAsMap === true,
|
|
23
|
+
mapKeyWarned: false,
|
|
24
|
+
maxAliasCount: typeof maxAliasCount === "number" ? maxAliasCount : 100
|
|
25
|
+
};
|
|
26
|
+
const res = toJS(this, "", ctx);
|
|
27
|
+
if (typeof onAnchor === "function") for (const { count, res } of ctx.anchors.values()) onAnchor(res, count);
|
|
28
|
+
return typeof reviver === "function" ? applyReviver(reviver, { "": res }, "", res) : res;
|
|
29
|
+
}
|
|
30
|
+
};
|
|
31
|
+
//#endregion
|
|
32
|
+
export { NodeBase };
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { NODE_TYPE, PAIR, isNode } from "./identity.js";
|
|
2
|
+
import { createNode } from "../doc/createNode.js";
|
|
3
|
+
import { stringifyPair } from "../stringify/stringifyPair.js";
|
|
4
|
+
import { addPairToJSMap } from "./addPairToJSMap.js";
|
|
5
|
+
//#region ../../node_modules/.pnpm/yaml@2.8.3/node_modules/yaml/browser/dist/nodes/Pair.js
|
|
6
|
+
function createPair(key, value, ctx) {
|
|
7
|
+
return new Pair(createNode(key, void 0, ctx), createNode(value, void 0, ctx));
|
|
8
|
+
}
|
|
9
|
+
var Pair = class Pair {
|
|
10
|
+
constructor(key, value = null) {
|
|
11
|
+
Object.defineProperty(this, NODE_TYPE, { value: PAIR });
|
|
12
|
+
this.key = key;
|
|
13
|
+
this.value = value;
|
|
14
|
+
}
|
|
15
|
+
clone(schema) {
|
|
16
|
+
let { key, value } = this;
|
|
17
|
+
if (isNode(key)) key = key.clone(schema);
|
|
18
|
+
if (isNode(value)) value = value.clone(schema);
|
|
19
|
+
return new Pair(key, value);
|
|
20
|
+
}
|
|
21
|
+
toJSON(_, ctx) {
|
|
22
|
+
return addPairToJSMap(ctx, ctx?.mapAsMap ? /* @__PURE__ */ new Map() : {}, this);
|
|
23
|
+
}
|
|
24
|
+
toString(ctx, onComment, onChompKeep) {
|
|
25
|
+
return ctx?.doc ? stringifyPair(this, ctx, onComment, onChompKeep) : JSON.stringify(this);
|
|
26
|
+
}
|
|
27
|
+
};
|
|
28
|
+
//#endregion
|
|
29
|
+
export { Pair, createPair };
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { SCALAR } from "./identity.js";
|
|
2
|
+
import { toJS } from "./toJS.js";
|
|
3
|
+
import { NodeBase } from "./Node.js";
|
|
4
|
+
//#region ../../node_modules/.pnpm/yaml@2.8.3/node_modules/yaml/browser/dist/nodes/Scalar.js
|
|
5
|
+
const isScalarValue = (value) => !value || typeof value !== "function" && typeof value !== "object";
|
|
6
|
+
var Scalar = class extends NodeBase {
|
|
7
|
+
constructor(value) {
|
|
8
|
+
super(SCALAR);
|
|
9
|
+
this.value = value;
|
|
10
|
+
}
|
|
11
|
+
toJSON(arg, ctx) {
|
|
12
|
+
return ctx?.keep ? this.value : toJS(this.value, arg, ctx);
|
|
13
|
+
}
|
|
14
|
+
toString() {
|
|
15
|
+
return String(this.value);
|
|
16
|
+
}
|
|
17
|
+
};
|
|
18
|
+
Scalar.BLOCK_FOLDED = "BLOCK_FOLDED";
|
|
19
|
+
Scalar.BLOCK_LITERAL = "BLOCK_LITERAL";
|
|
20
|
+
Scalar.PLAIN = "PLAIN";
|
|
21
|
+
Scalar.QUOTE_DOUBLE = "QUOTE_DOUBLE";
|
|
22
|
+
Scalar.QUOTE_SINGLE = "QUOTE_SINGLE";
|
|
23
|
+
//#endregion
|
|
24
|
+
export { Scalar, isScalarValue };
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
import { MAP, isPair, isScalar } from "./identity.js";
|
|
2
|
+
import { isScalarValue } from "./Scalar.js";
|
|
3
|
+
import { Collection } from "./Collection.js";
|
|
4
|
+
import { addPairToJSMap } from "./addPairToJSMap.js";
|
|
5
|
+
import { Pair, createPair } from "./Pair.js";
|
|
6
|
+
import { stringifyCollection } from "../stringify/stringifyCollection.js";
|
|
7
|
+
//#region ../../node_modules/.pnpm/yaml@2.8.3/node_modules/yaml/browser/dist/nodes/YAMLMap.js
|
|
8
|
+
function findPair(items, key) {
|
|
9
|
+
const k = isScalar(key) ? key.value : key;
|
|
10
|
+
for (const it of items) if (isPair(it)) {
|
|
11
|
+
if (it.key === key || it.key === k) return it;
|
|
12
|
+
if (isScalar(it.key) && it.key.value === k) return it;
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
var YAMLMap = class extends Collection {
|
|
16
|
+
static get tagName() {
|
|
17
|
+
return "tag:yaml.org,2002:map";
|
|
18
|
+
}
|
|
19
|
+
constructor(schema) {
|
|
20
|
+
super(MAP, schema);
|
|
21
|
+
this.items = [];
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* A generic collection parsing method that can be extended
|
|
25
|
+
* to other node classes that inherit from YAMLMap
|
|
26
|
+
*/
|
|
27
|
+
static from(schema, obj, ctx) {
|
|
28
|
+
const { keepUndefined, replacer } = ctx;
|
|
29
|
+
const map = new this(schema);
|
|
30
|
+
const add = (key, value) => {
|
|
31
|
+
if (typeof replacer === "function") value = replacer.call(obj, key, value);
|
|
32
|
+
else if (Array.isArray(replacer) && !replacer.includes(key)) return;
|
|
33
|
+
if (value !== void 0 || keepUndefined) map.items.push(createPair(key, value, ctx));
|
|
34
|
+
};
|
|
35
|
+
if (obj instanceof Map) for (const [key, value] of obj) add(key, value);
|
|
36
|
+
else if (obj && typeof obj === "object") for (const key of Object.keys(obj)) add(key, obj[key]);
|
|
37
|
+
if (typeof schema.sortMapEntries === "function") map.items.sort(schema.sortMapEntries);
|
|
38
|
+
return map;
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Adds a value to the collection.
|
|
42
|
+
*
|
|
43
|
+
* @param overwrite - If not set `true`, using a key that is already in the
|
|
44
|
+
* collection will throw. Otherwise, overwrites the previous value.
|
|
45
|
+
*/
|
|
46
|
+
add(pair, overwrite) {
|
|
47
|
+
let _pair;
|
|
48
|
+
if (isPair(pair)) _pair = pair;
|
|
49
|
+
else if (!pair || typeof pair !== "object" || !("key" in pair)) _pair = new Pair(pair, pair?.value);
|
|
50
|
+
else _pair = new Pair(pair.key, pair.value);
|
|
51
|
+
const prev = findPair(this.items, _pair.key);
|
|
52
|
+
const sortEntries = this.schema?.sortMapEntries;
|
|
53
|
+
if (prev) {
|
|
54
|
+
if (!overwrite) throw new Error(`Key ${_pair.key} already set`);
|
|
55
|
+
if (isScalar(prev.value) && isScalarValue(_pair.value)) prev.value.value = _pair.value;
|
|
56
|
+
else prev.value = _pair.value;
|
|
57
|
+
} else if (sortEntries) {
|
|
58
|
+
const i = this.items.findIndex((item) => sortEntries(_pair, item) < 0);
|
|
59
|
+
if (i === -1) this.items.push(_pair);
|
|
60
|
+
else this.items.splice(i, 0, _pair);
|
|
61
|
+
} else this.items.push(_pair);
|
|
62
|
+
}
|
|
63
|
+
delete(key) {
|
|
64
|
+
const it = findPair(this.items, key);
|
|
65
|
+
if (!it) return false;
|
|
66
|
+
return this.items.splice(this.items.indexOf(it), 1).length > 0;
|
|
67
|
+
}
|
|
68
|
+
get(key, keepScalar) {
|
|
69
|
+
const node = findPair(this.items, key)?.value;
|
|
70
|
+
return (!keepScalar && isScalar(node) ? node.value : node) ?? void 0;
|
|
71
|
+
}
|
|
72
|
+
has(key) {
|
|
73
|
+
return !!findPair(this.items, key);
|
|
74
|
+
}
|
|
75
|
+
set(key, value) {
|
|
76
|
+
this.add(new Pair(key, value), true);
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* @param ctx - Conversion context, originally set in Document#toJS()
|
|
80
|
+
* @param {Class} Type - If set, forces the returned collection type
|
|
81
|
+
* @returns Instance of Type, Map, or Object
|
|
82
|
+
*/
|
|
83
|
+
toJSON(_, ctx, Type) {
|
|
84
|
+
const map = Type ? new Type() : ctx?.mapAsMap ? /* @__PURE__ */ new Map() : {};
|
|
85
|
+
if (ctx?.onCreate) ctx.onCreate(map);
|
|
86
|
+
for (const item of this.items) addPairToJSMap(ctx, map, item);
|
|
87
|
+
return map;
|
|
88
|
+
}
|
|
89
|
+
toString(ctx, onComment, onChompKeep) {
|
|
90
|
+
if (!ctx) return JSON.stringify(this);
|
|
91
|
+
for (const item of this.items) if (!isPair(item)) throw new Error(`Map items must all be pairs; found ${JSON.stringify(item)} instead`);
|
|
92
|
+
if (!ctx.allNullValues && this.hasAllNullValues(false)) ctx = Object.assign({}, ctx, { allNullValues: true });
|
|
93
|
+
return stringifyCollection(this, ctx, {
|
|
94
|
+
blockItemPrefix: "",
|
|
95
|
+
flowChars: {
|
|
96
|
+
start: "{",
|
|
97
|
+
end: "}"
|
|
98
|
+
},
|
|
99
|
+
itemIndent: ctx.indent || "",
|
|
100
|
+
onChompKeep,
|
|
101
|
+
onComment
|
|
102
|
+
});
|
|
103
|
+
}
|
|
104
|
+
};
|
|
105
|
+
//#endregion
|
|
106
|
+
export { YAMLMap, findPair };
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
import { SEQ, isScalar } from "./identity.js";
|
|
2
|
+
import { toJS } from "./toJS.js";
|
|
3
|
+
import { isScalarValue } from "./Scalar.js";
|
|
4
|
+
import { createNode } from "../doc/createNode.js";
|
|
5
|
+
import { Collection } from "./Collection.js";
|
|
6
|
+
import { stringifyCollection } from "../stringify/stringifyCollection.js";
|
|
7
|
+
//#region ../../node_modules/.pnpm/yaml@2.8.3/node_modules/yaml/browser/dist/nodes/YAMLSeq.js
|
|
8
|
+
var YAMLSeq = class extends Collection {
|
|
9
|
+
static get tagName() {
|
|
10
|
+
return "tag:yaml.org,2002:seq";
|
|
11
|
+
}
|
|
12
|
+
constructor(schema) {
|
|
13
|
+
super(SEQ, schema);
|
|
14
|
+
this.items = [];
|
|
15
|
+
}
|
|
16
|
+
add(value) {
|
|
17
|
+
this.items.push(value);
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Removes a value from the collection.
|
|
21
|
+
*
|
|
22
|
+
* `key` must contain a representation of an integer for this to succeed.
|
|
23
|
+
* It may be wrapped in a `Scalar`.
|
|
24
|
+
*
|
|
25
|
+
* @returns `true` if the item was found and removed.
|
|
26
|
+
*/
|
|
27
|
+
delete(key) {
|
|
28
|
+
const idx = asItemIndex(key);
|
|
29
|
+
if (typeof idx !== "number") return false;
|
|
30
|
+
return this.items.splice(idx, 1).length > 0;
|
|
31
|
+
}
|
|
32
|
+
get(key, keepScalar) {
|
|
33
|
+
const idx = asItemIndex(key);
|
|
34
|
+
if (typeof idx !== "number") return void 0;
|
|
35
|
+
const it = this.items[idx];
|
|
36
|
+
return !keepScalar && isScalar(it) ? it.value : it;
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Checks if the collection includes a value with the key `key`.
|
|
40
|
+
*
|
|
41
|
+
* `key` must contain a representation of an integer for this to succeed.
|
|
42
|
+
* It may be wrapped in a `Scalar`.
|
|
43
|
+
*/
|
|
44
|
+
has(key) {
|
|
45
|
+
const idx = asItemIndex(key);
|
|
46
|
+
return typeof idx === "number" && idx < this.items.length;
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Sets a value in this collection. For `!!set`, `value` needs to be a
|
|
50
|
+
* boolean to add/remove the item from the set.
|
|
51
|
+
*
|
|
52
|
+
* If `key` does not contain a representation of an integer, this will throw.
|
|
53
|
+
* It may be wrapped in a `Scalar`.
|
|
54
|
+
*/
|
|
55
|
+
set(key, value) {
|
|
56
|
+
const idx = asItemIndex(key);
|
|
57
|
+
if (typeof idx !== "number") throw new Error(`Expected a valid index, not ${key}.`);
|
|
58
|
+
const prev = this.items[idx];
|
|
59
|
+
if (isScalar(prev) && isScalarValue(value)) prev.value = value;
|
|
60
|
+
else this.items[idx] = value;
|
|
61
|
+
}
|
|
62
|
+
toJSON(_, ctx) {
|
|
63
|
+
const seq = [];
|
|
64
|
+
if (ctx?.onCreate) ctx.onCreate(seq);
|
|
65
|
+
let i = 0;
|
|
66
|
+
for (const item of this.items) seq.push(toJS(item, String(i++), ctx));
|
|
67
|
+
return seq;
|
|
68
|
+
}
|
|
69
|
+
toString(ctx, onComment, onChompKeep) {
|
|
70
|
+
if (!ctx) return JSON.stringify(this);
|
|
71
|
+
return stringifyCollection(this, ctx, {
|
|
72
|
+
blockItemPrefix: "- ",
|
|
73
|
+
flowChars: {
|
|
74
|
+
start: "[",
|
|
75
|
+
end: "]"
|
|
76
|
+
},
|
|
77
|
+
itemIndent: (ctx.indent || "") + " ",
|
|
78
|
+
onChompKeep,
|
|
79
|
+
onComment
|
|
80
|
+
});
|
|
81
|
+
}
|
|
82
|
+
static from(schema, obj, ctx) {
|
|
83
|
+
const { replacer } = ctx;
|
|
84
|
+
const seq = new this(schema);
|
|
85
|
+
if (obj && Symbol.iterator in Object(obj)) {
|
|
86
|
+
let i = 0;
|
|
87
|
+
for (let it of obj) {
|
|
88
|
+
if (typeof replacer === "function") {
|
|
89
|
+
const key = obj instanceof Set ? it : String(i++);
|
|
90
|
+
it = replacer.call(obj, key, it);
|
|
91
|
+
}
|
|
92
|
+
seq.items.push(createNode(it, void 0, ctx));
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
return seq;
|
|
96
|
+
}
|
|
97
|
+
};
|
|
98
|
+
function asItemIndex(key) {
|
|
99
|
+
let idx = isScalar(key) ? key.value : key;
|
|
100
|
+
if (idx && typeof idx === "string") idx = Number(idx);
|
|
101
|
+
return typeof idx === "number" && Number.isInteger(idx) && idx >= 0 ? idx : null;
|
|
102
|
+
}
|
|
103
|
+
//#endregion
|
|
104
|
+
export { YAMLSeq };
|
package/dist/node_modules/.pnpm/yaml@2.8.3/node_modules/yaml/browser/dist/nodes/addPairToJSMap.js
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { isNode } from "./identity.js";
|
|
2
|
+
import { toJS } from "./toJS.js";
|
|
3
|
+
import { createStringifyContext } from "../stringify/stringify.js";
|
|
4
|
+
import { warn } from "../log.js";
|
|
5
|
+
import { addMergeToJSMap, isMergeKey } from "../schema/yaml-1.1/merge.js";
|
|
6
|
+
//#region ../../node_modules/.pnpm/yaml@2.8.3/node_modules/yaml/browser/dist/nodes/addPairToJSMap.js
|
|
7
|
+
function addPairToJSMap(ctx, map, { key, value }) {
|
|
8
|
+
if (isNode(key) && key.addToJSMap) key.addToJSMap(ctx, map, value);
|
|
9
|
+
else if (isMergeKey(ctx, key)) addMergeToJSMap(ctx, map, value);
|
|
10
|
+
else {
|
|
11
|
+
const jsKey = toJS(key, "", ctx);
|
|
12
|
+
if (map instanceof Map) map.set(jsKey, toJS(value, jsKey, ctx));
|
|
13
|
+
else if (map instanceof Set) map.add(jsKey);
|
|
14
|
+
else {
|
|
15
|
+
const stringKey = stringifyKey(key, jsKey, ctx);
|
|
16
|
+
const jsValue = toJS(value, stringKey, ctx);
|
|
17
|
+
if (stringKey in map) Object.defineProperty(map, stringKey, {
|
|
18
|
+
value: jsValue,
|
|
19
|
+
writable: true,
|
|
20
|
+
enumerable: true,
|
|
21
|
+
configurable: true
|
|
22
|
+
});
|
|
23
|
+
else map[stringKey] = jsValue;
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
return map;
|
|
27
|
+
}
|
|
28
|
+
function stringifyKey(key, jsKey, ctx) {
|
|
29
|
+
if (jsKey === null) return "";
|
|
30
|
+
if (typeof jsKey !== "object") return String(jsKey);
|
|
31
|
+
if (isNode(key) && ctx?.doc) {
|
|
32
|
+
const strCtx = createStringifyContext(ctx.doc, {});
|
|
33
|
+
strCtx.anchors = /* @__PURE__ */ new Set();
|
|
34
|
+
for (const node of ctx.anchors.keys()) strCtx.anchors.add(node.anchor);
|
|
35
|
+
strCtx.inFlow = true;
|
|
36
|
+
strCtx.inStringifyKey = true;
|
|
37
|
+
const strKey = key.toString(strCtx);
|
|
38
|
+
if (!ctx.mapKeyWarned) {
|
|
39
|
+
let jsonStr = JSON.stringify(strKey);
|
|
40
|
+
if (jsonStr.length > 40) jsonStr = jsonStr.substring(0, 36) + "...\"";
|
|
41
|
+
warn(ctx.doc.options.logLevel, `Keys with collection values will be stringified due to JS Object restrictions: ${jsonStr}. Set mapAsMap: true to use object keys.`);
|
|
42
|
+
ctx.mapKeyWarned = true;
|
|
43
|
+
}
|
|
44
|
+
return strKey;
|
|
45
|
+
}
|
|
46
|
+
return JSON.stringify(jsKey);
|
|
47
|
+
}
|
|
48
|
+
//#endregion
|
|
49
|
+
export { addPairToJSMap };
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
//#region ../../node_modules/.pnpm/yaml@2.8.3/node_modules/yaml/browser/dist/nodes/identity.js
|
|
2
|
+
const ALIAS = Symbol.for("yaml.alias");
|
|
3
|
+
const DOC = Symbol.for("yaml.document");
|
|
4
|
+
const MAP = Symbol.for("yaml.map");
|
|
5
|
+
const PAIR = Symbol.for("yaml.pair");
|
|
6
|
+
const SCALAR = Symbol.for("yaml.scalar");
|
|
7
|
+
const SEQ = Symbol.for("yaml.seq");
|
|
8
|
+
const NODE_TYPE = Symbol.for("yaml.node.type");
|
|
9
|
+
const isAlias = (node) => !!node && typeof node === "object" && node[NODE_TYPE] === ALIAS;
|
|
10
|
+
const isDocument = (node) => !!node && typeof node === "object" && node[NODE_TYPE] === DOC;
|
|
11
|
+
const isMap = (node) => !!node && typeof node === "object" && node[NODE_TYPE] === MAP;
|
|
12
|
+
const isPair = (node) => !!node && typeof node === "object" && node[NODE_TYPE] === PAIR;
|
|
13
|
+
const isScalar = (node) => !!node && typeof node === "object" && node[NODE_TYPE] === SCALAR;
|
|
14
|
+
const isSeq = (node) => !!node && typeof node === "object" && node[NODE_TYPE] === SEQ;
|
|
15
|
+
function isCollection(node) {
|
|
16
|
+
if (node && typeof node === "object") switch (node[NODE_TYPE]) {
|
|
17
|
+
case MAP:
|
|
18
|
+
case SEQ: return true;
|
|
19
|
+
}
|
|
20
|
+
return false;
|
|
21
|
+
}
|
|
22
|
+
function isNode(node) {
|
|
23
|
+
if (node && typeof node === "object") switch (node[NODE_TYPE]) {
|
|
24
|
+
case ALIAS:
|
|
25
|
+
case MAP:
|
|
26
|
+
case SCALAR:
|
|
27
|
+
case SEQ: return true;
|
|
28
|
+
}
|
|
29
|
+
return false;
|
|
30
|
+
}
|
|
31
|
+
const hasAnchor = (node) => (isScalar(node) || isCollection(node)) && !!node.anchor;
|
|
32
|
+
//#endregion
|
|
33
|
+
export { ALIAS, DOC, MAP, NODE_TYPE, PAIR, SCALAR, SEQ, hasAnchor, isAlias, isCollection, isDocument, isMap, isNode, isPair, isScalar, isSeq };
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { hasAnchor } from "./identity.js";
|
|
2
|
+
//#region ../../node_modules/.pnpm/yaml@2.8.3/node_modules/yaml/browser/dist/nodes/toJS.js
|
|
3
|
+
/**
|
|
4
|
+
* Recursively convert any node or its contents to native JavaScript
|
|
5
|
+
*
|
|
6
|
+
* @param value - The input value
|
|
7
|
+
* @param arg - If `value` defines a `toJSON()` method, use this
|
|
8
|
+
* as its first argument
|
|
9
|
+
* @param ctx - Conversion context, originally set in Document#toJS(). If
|
|
10
|
+
* `{ keep: true }` is not set, output should be suitable for JSON
|
|
11
|
+
* stringification.
|
|
12
|
+
*/
|
|
13
|
+
function toJS(value, arg, ctx) {
|
|
14
|
+
if (Array.isArray(value)) return value.map((v, i) => toJS(v, String(i), ctx));
|
|
15
|
+
if (value && typeof value.toJSON === "function") {
|
|
16
|
+
if (!ctx || !hasAnchor(value)) return value.toJSON(arg, ctx);
|
|
17
|
+
const data = {
|
|
18
|
+
aliasCount: 0,
|
|
19
|
+
count: 1,
|
|
20
|
+
res: void 0
|
|
21
|
+
};
|
|
22
|
+
ctx.anchors.set(value, data);
|
|
23
|
+
ctx.onCreate = (res) => {
|
|
24
|
+
data.res = res;
|
|
25
|
+
delete ctx.onCreate;
|
|
26
|
+
};
|
|
27
|
+
const res = value.toJSON(arg, ctx);
|
|
28
|
+
if (ctx.onCreate) ctx.onCreate(res);
|
|
29
|
+
return res;
|
|
30
|
+
}
|
|
31
|
+
if (typeof value === "bigint" && !ctx?.keep) return Number(value);
|
|
32
|
+
return value;
|
|
33
|
+
}
|
|
34
|
+
//#endregion
|
|
35
|
+
export { toJS };
|