@scalar/api-client 0.12.17 → 1.0.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/CHANGELOG.md +22 -0
- package/dist/components/ApiClient/Response/ResponseBody.vue.d.ts.map +1 -1
- package/dist/fixtures/httpRequestMethods.d.ts +1 -2
- package/dist/fixtures/httpRequestMethods.d.ts.map +1 -1
- package/dist/helpers/index.d.ts +0 -1
- package/dist/helpers/index.d.ts.map +1 -1
- package/dist/helpers/prepareClientRequestConfig.d.ts.map +1 -1
- package/dist/index.js +1820 -23
- package/package.json +8 -6
- package/dist/helpers/isJsonString.d.ts +0 -5
- package/dist/helpers/isJsonString.d.ts.map +0 -1
package/dist/index.js
CHANGED
|
@@ -18966,10 +18966,10 @@ class Stack {
|
|
|
18966
18966
|
@internal
|
|
18967
18967
|
*/
|
|
18968
18968
|
recoverByDelete(next, nextEnd) {
|
|
18969
|
-
let
|
|
18970
|
-
if (
|
|
18969
|
+
let isNode2 = next <= this.p.parser.maxNode;
|
|
18970
|
+
if (isNode2)
|
|
18971
18971
|
this.storeNode(next, this.pos, nextEnd, 4);
|
|
18972
|
-
this.storeNode(0, this.pos, nextEnd,
|
|
18972
|
+
this.storeNode(0, this.pos, nextEnd, isNode2 ? 8 : 4);
|
|
18973
18973
|
this.pos = this.reducePos = nextEnd;
|
|
18974
18974
|
this.score -= 190;
|
|
18975
18975
|
}
|
|
@@ -23063,10 +23063,10 @@ const jsonLanguage = /* @__PURE__ */ LRLanguage.define({
|
|
|
23063
23063
|
indentOnInput: /^\s*[\}\]]$/
|
|
23064
23064
|
}
|
|
23065
23065
|
});
|
|
23066
|
-
function json() {
|
|
23066
|
+
function json$1() {
|
|
23067
23067
|
return new LanguageSupport(jsonLanguage);
|
|
23068
23068
|
}
|
|
23069
|
-
const blockEnd = 63, eof = 64, DirectiveEnd = 1, DocEnd = 2, sequenceStartMark = 3, sequenceContinueMark = 4, explicitMapStartMark = 5, explicitMapContinueMark = 6, flowMapMark = 7, mapStartMark = 65, mapContinueMark = 66, Literal = 8, QuotedLiteral = 9, Anchor = 10, Alias = 11, Tag2 = 12, BlockLiteralContent = 13, BracketL = 19, FlowSequence = 20, Colon = 29, BraceL = 33, FlowMapping = 34, BlockLiteralHeader = 47;
|
|
23069
|
+
const blockEnd = 63, eof = 64, DirectiveEnd = 1, DocEnd = 2, sequenceStartMark = 3, sequenceContinueMark = 4, explicitMapStartMark = 5, explicitMapContinueMark = 6, flowMapMark = 7, mapStartMark = 65, mapContinueMark = 66, Literal = 8, QuotedLiteral = 9, Anchor = 10, Alias$1 = 11, Tag2 = 12, BlockLiteralContent = 13, BracketL = 19, FlowSequence = 20, Colon = 29, BraceL = 33, FlowMapping = 34, BlockLiteralHeader = 47;
|
|
23070
23070
|
const type_Top = 0, type_Seq = 1, type_Map = 2, type_Flow = 3, type_Lit = 4;
|
|
23071
23071
|
const _Context = class _Context {
|
|
23072
23072
|
constructor(parent, depth, type) {
|
|
@@ -23358,7 +23358,7 @@ const literals = new ExternalTokenizer((input, stack) => {
|
|
|
23358
23358
|
readTag(input);
|
|
23359
23359
|
input.acceptToken(Tag2);
|
|
23360
23360
|
} else if (input.next == 38 || input.next == 42) {
|
|
23361
|
-
let token = input.next == 38 ? Anchor : Alias;
|
|
23361
|
+
let token = input.next == 38 ? Anchor : Alias$1;
|
|
23362
23362
|
readAnchor(input);
|
|
23363
23363
|
input.acceptToken(token);
|
|
23364
23364
|
} else if (input.next == 39 || input.next == 34) {
|
|
@@ -23784,7 +23784,7 @@ const useCodeMirror = (params) => {
|
|
|
23784
23784
|
};
|
|
23785
23785
|
const languageExtensions = {
|
|
23786
23786
|
html,
|
|
23787
|
-
json,
|
|
23787
|
+
json: json$1,
|
|
23788
23788
|
yaml,
|
|
23789
23789
|
css
|
|
23790
23790
|
};
|
|
@@ -24026,17 +24026,6 @@ function humanDiff(unixTimestamp) {
|
|
|
24026
24026
|
}
|
|
24027
24027
|
return "more than a year ago";
|
|
24028
24028
|
}
|
|
24029
|
-
const isJsonString = (value) => {
|
|
24030
|
-
if (typeof value !== "string") {
|
|
24031
|
-
return false;
|
|
24032
|
-
}
|
|
24033
|
-
try {
|
|
24034
|
-
JSON.parse(value);
|
|
24035
|
-
} catch {
|
|
24036
|
-
return false;
|
|
24037
|
-
}
|
|
24038
|
-
return true;
|
|
24039
|
-
};
|
|
24040
24029
|
function mapFromArray(arr, key, valueKey) {
|
|
24041
24030
|
const obj = {};
|
|
24042
24031
|
arr.forEach((entry) => {
|
|
@@ -24087,6 +24076,1815 @@ const normalizeUrl = (url) => {
|
|
|
24087
24076
|
}
|
|
24088
24077
|
return normalizedUrl;
|
|
24089
24078
|
};
|
|
24079
|
+
const ALIAS = Symbol.for("yaml.alias");
|
|
24080
|
+
const DOC = Symbol.for("yaml.document");
|
|
24081
|
+
const MAP = Symbol.for("yaml.map");
|
|
24082
|
+
const PAIR = Symbol.for("yaml.pair");
|
|
24083
|
+
const SCALAR = Symbol.for("yaml.scalar");
|
|
24084
|
+
const SEQ = Symbol.for("yaml.seq");
|
|
24085
|
+
const NODE_TYPE = Symbol.for("yaml.node.type");
|
|
24086
|
+
const isAlias = (node) => !!node && typeof node === "object" && node[NODE_TYPE] === ALIAS;
|
|
24087
|
+
const isDocument = (node) => !!node && typeof node === "object" && node[NODE_TYPE] === DOC;
|
|
24088
|
+
const isMap = (node) => !!node && typeof node === "object" && node[NODE_TYPE] === MAP;
|
|
24089
|
+
const isPair = (node) => !!node && typeof node === "object" && node[NODE_TYPE] === PAIR;
|
|
24090
|
+
const isScalar = (node) => !!node && typeof node === "object" && node[NODE_TYPE] === SCALAR;
|
|
24091
|
+
const isSeq = (node) => !!node && typeof node === "object" && node[NODE_TYPE] === SEQ;
|
|
24092
|
+
function isCollection(node) {
|
|
24093
|
+
if (node && typeof node === "object")
|
|
24094
|
+
switch (node[NODE_TYPE]) {
|
|
24095
|
+
case MAP:
|
|
24096
|
+
case SEQ:
|
|
24097
|
+
return true;
|
|
24098
|
+
}
|
|
24099
|
+
return false;
|
|
24100
|
+
}
|
|
24101
|
+
function isNode(node) {
|
|
24102
|
+
if (node && typeof node === "object")
|
|
24103
|
+
switch (node[NODE_TYPE]) {
|
|
24104
|
+
case ALIAS:
|
|
24105
|
+
case MAP:
|
|
24106
|
+
case SCALAR:
|
|
24107
|
+
case SEQ:
|
|
24108
|
+
return true;
|
|
24109
|
+
}
|
|
24110
|
+
return false;
|
|
24111
|
+
}
|
|
24112
|
+
const hasAnchor = (node) => (isScalar(node) || isCollection(node)) && !!node.anchor;
|
|
24113
|
+
const BREAK = Symbol("break visit");
|
|
24114
|
+
const SKIP = Symbol("skip children");
|
|
24115
|
+
const REMOVE = Symbol("remove node");
|
|
24116
|
+
function visit(node, visitor) {
|
|
24117
|
+
const visitor_ = initVisitor(visitor);
|
|
24118
|
+
if (isDocument(node)) {
|
|
24119
|
+
const cd = visit_(null, node.contents, visitor_, Object.freeze([node]));
|
|
24120
|
+
if (cd === REMOVE)
|
|
24121
|
+
node.contents = null;
|
|
24122
|
+
} else
|
|
24123
|
+
visit_(null, node, visitor_, Object.freeze([]));
|
|
24124
|
+
}
|
|
24125
|
+
visit.BREAK = BREAK;
|
|
24126
|
+
visit.SKIP = SKIP;
|
|
24127
|
+
visit.REMOVE = REMOVE;
|
|
24128
|
+
function visit_(key, node, visitor, path) {
|
|
24129
|
+
const ctrl = callVisitor(key, node, visitor, path);
|
|
24130
|
+
if (isNode(ctrl) || isPair(ctrl)) {
|
|
24131
|
+
replaceNode(key, path, ctrl);
|
|
24132
|
+
return visit_(key, ctrl, visitor, path);
|
|
24133
|
+
}
|
|
24134
|
+
if (typeof ctrl !== "symbol") {
|
|
24135
|
+
if (isCollection(node)) {
|
|
24136
|
+
path = Object.freeze(path.concat(node));
|
|
24137
|
+
for (let i = 0; i < node.items.length; ++i) {
|
|
24138
|
+
const ci = visit_(i, node.items[i], visitor, path);
|
|
24139
|
+
if (typeof ci === "number")
|
|
24140
|
+
i = ci - 1;
|
|
24141
|
+
else if (ci === BREAK)
|
|
24142
|
+
return BREAK;
|
|
24143
|
+
else if (ci === REMOVE) {
|
|
24144
|
+
node.items.splice(i, 1);
|
|
24145
|
+
i -= 1;
|
|
24146
|
+
}
|
|
24147
|
+
}
|
|
24148
|
+
} else if (isPair(node)) {
|
|
24149
|
+
path = Object.freeze(path.concat(node));
|
|
24150
|
+
const ck = visit_("key", node.key, visitor, path);
|
|
24151
|
+
if (ck === BREAK)
|
|
24152
|
+
return BREAK;
|
|
24153
|
+
else if (ck === REMOVE)
|
|
24154
|
+
node.key = null;
|
|
24155
|
+
const cv = visit_("value", node.value, visitor, path);
|
|
24156
|
+
if (cv === BREAK)
|
|
24157
|
+
return BREAK;
|
|
24158
|
+
else if (cv === REMOVE)
|
|
24159
|
+
node.value = null;
|
|
24160
|
+
}
|
|
24161
|
+
}
|
|
24162
|
+
return ctrl;
|
|
24163
|
+
}
|
|
24164
|
+
function initVisitor(visitor) {
|
|
24165
|
+
if (typeof visitor === "object" && (visitor.Collection || visitor.Node || visitor.Value)) {
|
|
24166
|
+
return Object.assign({
|
|
24167
|
+
Alias: visitor.Node,
|
|
24168
|
+
Map: visitor.Node,
|
|
24169
|
+
Scalar: visitor.Node,
|
|
24170
|
+
Seq: visitor.Node
|
|
24171
|
+
}, visitor.Value && {
|
|
24172
|
+
Map: visitor.Value,
|
|
24173
|
+
Scalar: visitor.Value,
|
|
24174
|
+
Seq: visitor.Value
|
|
24175
|
+
}, visitor.Collection && {
|
|
24176
|
+
Map: visitor.Collection,
|
|
24177
|
+
Seq: visitor.Collection
|
|
24178
|
+
}, visitor);
|
|
24179
|
+
}
|
|
24180
|
+
return visitor;
|
|
24181
|
+
}
|
|
24182
|
+
function callVisitor(key, node, visitor, path) {
|
|
24183
|
+
var _a2, _b, _c, _d, _e;
|
|
24184
|
+
if (typeof visitor === "function")
|
|
24185
|
+
return visitor(key, node, path);
|
|
24186
|
+
if (isMap(node))
|
|
24187
|
+
return (_a2 = visitor.Map) == null ? void 0 : _a2.call(visitor, key, node, path);
|
|
24188
|
+
if (isSeq(node))
|
|
24189
|
+
return (_b = visitor.Seq) == null ? void 0 : _b.call(visitor, key, node, path);
|
|
24190
|
+
if (isPair(node))
|
|
24191
|
+
return (_c = visitor.Pair) == null ? void 0 : _c.call(visitor, key, node, path);
|
|
24192
|
+
if (isScalar(node))
|
|
24193
|
+
return (_d = visitor.Scalar) == null ? void 0 : _d.call(visitor, key, node, path);
|
|
24194
|
+
if (isAlias(node))
|
|
24195
|
+
return (_e = visitor.Alias) == null ? void 0 : _e.call(visitor, key, node, path);
|
|
24196
|
+
return void 0;
|
|
24197
|
+
}
|
|
24198
|
+
function replaceNode(key, path, node) {
|
|
24199
|
+
const parent = path[path.length - 1];
|
|
24200
|
+
if (isCollection(parent)) {
|
|
24201
|
+
parent.items[key] = node;
|
|
24202
|
+
} else if (isPair(parent)) {
|
|
24203
|
+
if (key === "key")
|
|
24204
|
+
parent.key = node;
|
|
24205
|
+
else
|
|
24206
|
+
parent.value = node;
|
|
24207
|
+
} else if (isDocument(parent)) {
|
|
24208
|
+
parent.contents = node;
|
|
24209
|
+
} else {
|
|
24210
|
+
const pt = isAlias(parent) ? "alias" : "scalar";
|
|
24211
|
+
throw new Error(`Cannot replace node with ${pt} parent`);
|
|
24212
|
+
}
|
|
24213
|
+
}
|
|
24214
|
+
function anchorIsValid(anchor) {
|
|
24215
|
+
if (/[\x00-\x19\s,[\]{}]/.test(anchor)) {
|
|
24216
|
+
const sa = JSON.stringify(anchor);
|
|
24217
|
+
const msg = `Anchor must not contain whitespace or control characters: ${sa}`;
|
|
24218
|
+
throw new Error(msg);
|
|
24219
|
+
}
|
|
24220
|
+
return true;
|
|
24221
|
+
}
|
|
24222
|
+
function applyReviver(reviver, obj, key, val) {
|
|
24223
|
+
if (val && typeof val === "object") {
|
|
24224
|
+
if (Array.isArray(val)) {
|
|
24225
|
+
for (let i = 0, len = val.length; i < len; ++i) {
|
|
24226
|
+
const v0 = val[i];
|
|
24227
|
+
const v1 = applyReviver(reviver, val, String(i), v0);
|
|
24228
|
+
if (v1 === void 0)
|
|
24229
|
+
delete val[i];
|
|
24230
|
+
else if (v1 !== v0)
|
|
24231
|
+
val[i] = v1;
|
|
24232
|
+
}
|
|
24233
|
+
} else if (val instanceof Map) {
|
|
24234
|
+
for (const k of Array.from(val.keys())) {
|
|
24235
|
+
const v0 = val.get(k);
|
|
24236
|
+
const v1 = applyReviver(reviver, val, k, v0);
|
|
24237
|
+
if (v1 === void 0)
|
|
24238
|
+
val.delete(k);
|
|
24239
|
+
else if (v1 !== v0)
|
|
24240
|
+
val.set(k, v1);
|
|
24241
|
+
}
|
|
24242
|
+
} else if (val instanceof Set) {
|
|
24243
|
+
for (const v0 of Array.from(val)) {
|
|
24244
|
+
const v1 = applyReviver(reviver, val, v0, v0);
|
|
24245
|
+
if (v1 === void 0)
|
|
24246
|
+
val.delete(v0);
|
|
24247
|
+
else if (v1 !== v0) {
|
|
24248
|
+
val.delete(v0);
|
|
24249
|
+
val.add(v1);
|
|
24250
|
+
}
|
|
24251
|
+
}
|
|
24252
|
+
} else {
|
|
24253
|
+
for (const [k, v0] of Object.entries(val)) {
|
|
24254
|
+
const v1 = applyReviver(reviver, val, k, v0);
|
|
24255
|
+
if (v1 === void 0)
|
|
24256
|
+
delete val[k];
|
|
24257
|
+
else if (v1 !== v0)
|
|
24258
|
+
val[k] = v1;
|
|
24259
|
+
}
|
|
24260
|
+
}
|
|
24261
|
+
}
|
|
24262
|
+
return reviver.call(obj, key, val);
|
|
24263
|
+
}
|
|
24264
|
+
function toJS(value, arg, ctx) {
|
|
24265
|
+
if (Array.isArray(value))
|
|
24266
|
+
return value.map((v, i) => toJS(v, String(i), ctx));
|
|
24267
|
+
if (value && typeof value.toJSON === "function") {
|
|
24268
|
+
if (!ctx || !hasAnchor(value))
|
|
24269
|
+
return value.toJSON(arg, ctx);
|
|
24270
|
+
const data = { aliasCount: 0, count: 1, res: void 0 };
|
|
24271
|
+
ctx.anchors.set(value, data);
|
|
24272
|
+
ctx.onCreate = (res2) => {
|
|
24273
|
+
data.res = res2;
|
|
24274
|
+
delete ctx.onCreate;
|
|
24275
|
+
};
|
|
24276
|
+
const res = value.toJSON(arg, ctx);
|
|
24277
|
+
if (ctx.onCreate)
|
|
24278
|
+
ctx.onCreate(res);
|
|
24279
|
+
return res;
|
|
24280
|
+
}
|
|
24281
|
+
if (typeof value === "bigint" && !(ctx == null ? void 0 : ctx.keep))
|
|
24282
|
+
return Number(value);
|
|
24283
|
+
return value;
|
|
24284
|
+
}
|
|
24285
|
+
class NodeBase {
|
|
24286
|
+
constructor(type) {
|
|
24287
|
+
Object.defineProperty(this, NODE_TYPE, { value: type });
|
|
24288
|
+
}
|
|
24289
|
+
/** Create a copy of this node. */
|
|
24290
|
+
clone() {
|
|
24291
|
+
const copy = Object.create(Object.getPrototypeOf(this), Object.getOwnPropertyDescriptors(this));
|
|
24292
|
+
if (this.range)
|
|
24293
|
+
copy.range = this.range.slice();
|
|
24294
|
+
return copy;
|
|
24295
|
+
}
|
|
24296
|
+
/** A plain JavaScript representation of this node. */
|
|
24297
|
+
toJS(doc2, { mapAsMap, maxAliasCount, onAnchor, reviver } = {}) {
|
|
24298
|
+
if (!isDocument(doc2))
|
|
24299
|
+
throw new TypeError("A document argument is required");
|
|
24300
|
+
const ctx = {
|
|
24301
|
+
anchors: /* @__PURE__ */ new Map(),
|
|
24302
|
+
doc: doc2,
|
|
24303
|
+
keep: true,
|
|
24304
|
+
mapAsMap: mapAsMap === true,
|
|
24305
|
+
mapKeyWarned: false,
|
|
24306
|
+
maxAliasCount: typeof maxAliasCount === "number" ? maxAliasCount : 100
|
|
24307
|
+
};
|
|
24308
|
+
const res = toJS(this, "", ctx);
|
|
24309
|
+
if (typeof onAnchor === "function")
|
|
24310
|
+
for (const { count, res: res2 } of ctx.anchors.values())
|
|
24311
|
+
onAnchor(res2, count);
|
|
24312
|
+
return typeof reviver === "function" ? applyReviver(reviver, { "": res }, "", res) : res;
|
|
24313
|
+
}
|
|
24314
|
+
}
|
|
24315
|
+
class Alias extends NodeBase {
|
|
24316
|
+
constructor(source) {
|
|
24317
|
+
super(ALIAS);
|
|
24318
|
+
this.source = source;
|
|
24319
|
+
Object.defineProperty(this, "tag", {
|
|
24320
|
+
set() {
|
|
24321
|
+
throw new Error("Alias nodes cannot have tags");
|
|
24322
|
+
}
|
|
24323
|
+
});
|
|
24324
|
+
}
|
|
24325
|
+
/**
|
|
24326
|
+
* Resolve the value of this alias within `doc`, finding the last
|
|
24327
|
+
* instance of the `source` anchor before this node.
|
|
24328
|
+
*/
|
|
24329
|
+
resolve(doc2) {
|
|
24330
|
+
let found = void 0;
|
|
24331
|
+
visit(doc2, {
|
|
24332
|
+
Node: (_key, node) => {
|
|
24333
|
+
if (node === this)
|
|
24334
|
+
return visit.BREAK;
|
|
24335
|
+
if (node.anchor === this.source)
|
|
24336
|
+
found = node;
|
|
24337
|
+
}
|
|
24338
|
+
});
|
|
24339
|
+
return found;
|
|
24340
|
+
}
|
|
24341
|
+
toJSON(_arg, ctx) {
|
|
24342
|
+
if (!ctx)
|
|
24343
|
+
return { source: this.source };
|
|
24344
|
+
const { anchors, doc: doc2, maxAliasCount } = ctx;
|
|
24345
|
+
const source = this.resolve(doc2);
|
|
24346
|
+
if (!source) {
|
|
24347
|
+
const msg = `Unresolved alias (the anchor must be set before the alias): ${this.source}`;
|
|
24348
|
+
throw new ReferenceError(msg);
|
|
24349
|
+
}
|
|
24350
|
+
let data = anchors.get(source);
|
|
24351
|
+
if (!data) {
|
|
24352
|
+
toJS(source, null, ctx);
|
|
24353
|
+
data = anchors.get(source);
|
|
24354
|
+
}
|
|
24355
|
+
if (!data || data.res === void 0) {
|
|
24356
|
+
const msg = "This should not happen: Alias anchor was not resolved?";
|
|
24357
|
+
throw new ReferenceError(msg);
|
|
24358
|
+
}
|
|
24359
|
+
if (maxAliasCount >= 0) {
|
|
24360
|
+
data.count += 1;
|
|
24361
|
+
if (data.aliasCount === 0)
|
|
24362
|
+
data.aliasCount = getAliasCount(doc2, source, anchors);
|
|
24363
|
+
if (data.count * data.aliasCount > maxAliasCount) {
|
|
24364
|
+
const msg = "Excessive alias count indicates a resource exhaustion attack";
|
|
24365
|
+
throw new ReferenceError(msg);
|
|
24366
|
+
}
|
|
24367
|
+
}
|
|
24368
|
+
return data.res;
|
|
24369
|
+
}
|
|
24370
|
+
toString(ctx, _onComment, _onChompKeep) {
|
|
24371
|
+
const src = `*${this.source}`;
|
|
24372
|
+
if (ctx) {
|
|
24373
|
+
anchorIsValid(this.source);
|
|
24374
|
+
if (ctx.options.verifyAliasOrder && !ctx.anchors.has(this.source)) {
|
|
24375
|
+
const msg = `Unresolved alias (the anchor must be set before the alias): ${this.source}`;
|
|
24376
|
+
throw new Error(msg);
|
|
24377
|
+
}
|
|
24378
|
+
if (ctx.implicitKey)
|
|
24379
|
+
return `${src} `;
|
|
24380
|
+
}
|
|
24381
|
+
return src;
|
|
24382
|
+
}
|
|
24383
|
+
}
|
|
24384
|
+
function getAliasCount(doc2, node, anchors) {
|
|
24385
|
+
if (isAlias(node)) {
|
|
24386
|
+
const source = node.resolve(doc2);
|
|
24387
|
+
const anchor = anchors && source && anchors.get(source);
|
|
24388
|
+
return anchor ? anchor.count * anchor.aliasCount : 0;
|
|
24389
|
+
} else if (isCollection(node)) {
|
|
24390
|
+
let count = 0;
|
|
24391
|
+
for (const item of node.items) {
|
|
24392
|
+
const c = getAliasCount(doc2, item, anchors);
|
|
24393
|
+
if (c > count)
|
|
24394
|
+
count = c;
|
|
24395
|
+
}
|
|
24396
|
+
return count;
|
|
24397
|
+
} else if (isPair(node)) {
|
|
24398
|
+
const kc = getAliasCount(doc2, node.key, anchors);
|
|
24399
|
+
const vc = getAliasCount(doc2, node.value, anchors);
|
|
24400
|
+
return Math.max(kc, vc);
|
|
24401
|
+
}
|
|
24402
|
+
return 1;
|
|
24403
|
+
}
|
|
24404
|
+
const isScalarValue = (value) => !value || typeof value !== "function" && typeof value !== "object";
|
|
24405
|
+
class Scalar extends NodeBase {
|
|
24406
|
+
constructor(value) {
|
|
24407
|
+
super(SCALAR);
|
|
24408
|
+
this.value = value;
|
|
24409
|
+
}
|
|
24410
|
+
toJSON(arg, ctx) {
|
|
24411
|
+
return (ctx == null ? void 0 : ctx.keep) ? this.value : toJS(this.value, arg, ctx);
|
|
24412
|
+
}
|
|
24413
|
+
toString() {
|
|
24414
|
+
return String(this.value);
|
|
24415
|
+
}
|
|
24416
|
+
}
|
|
24417
|
+
Scalar.BLOCK_FOLDED = "BLOCK_FOLDED";
|
|
24418
|
+
Scalar.BLOCK_LITERAL = "BLOCK_LITERAL";
|
|
24419
|
+
Scalar.PLAIN = "PLAIN";
|
|
24420
|
+
Scalar.QUOTE_DOUBLE = "QUOTE_DOUBLE";
|
|
24421
|
+
Scalar.QUOTE_SINGLE = "QUOTE_SINGLE";
|
|
24422
|
+
const defaultTagPrefix = "tag:yaml.org,2002:";
|
|
24423
|
+
function findTagObject(value, tagName, tags2) {
|
|
24424
|
+
if (tagName) {
|
|
24425
|
+
const match = tags2.filter((t2) => t2.tag === tagName);
|
|
24426
|
+
const tagObj = match.find((t2) => !t2.format) ?? match[0];
|
|
24427
|
+
if (!tagObj)
|
|
24428
|
+
throw new Error(`Tag ${tagName} not found`);
|
|
24429
|
+
return tagObj;
|
|
24430
|
+
}
|
|
24431
|
+
return tags2.find((t2) => {
|
|
24432
|
+
var _a2;
|
|
24433
|
+
return ((_a2 = t2.identify) == null ? void 0 : _a2.call(t2, value)) && !t2.format;
|
|
24434
|
+
});
|
|
24435
|
+
}
|
|
24436
|
+
function createNode(value, tagName, ctx) {
|
|
24437
|
+
var _a2, _b, _c;
|
|
24438
|
+
if (isDocument(value))
|
|
24439
|
+
value = value.contents;
|
|
24440
|
+
if (isNode(value))
|
|
24441
|
+
return value;
|
|
24442
|
+
if (isPair(value)) {
|
|
24443
|
+
const map = (_b = (_a2 = ctx.schema[MAP]).createNode) == null ? void 0 : _b.call(_a2, ctx.schema, null, ctx);
|
|
24444
|
+
map.items.push(value);
|
|
24445
|
+
return map;
|
|
24446
|
+
}
|
|
24447
|
+
if (value instanceof String || value instanceof Number || value instanceof Boolean || typeof BigInt !== "undefined" && value instanceof BigInt) {
|
|
24448
|
+
value = value.valueOf();
|
|
24449
|
+
}
|
|
24450
|
+
const { aliasDuplicateObjects, onAnchor, onTagObj, schema, sourceObjects } = ctx;
|
|
24451
|
+
let ref2 = void 0;
|
|
24452
|
+
if (aliasDuplicateObjects && value && typeof value === "object") {
|
|
24453
|
+
ref2 = sourceObjects.get(value);
|
|
24454
|
+
if (ref2) {
|
|
24455
|
+
if (!ref2.anchor)
|
|
24456
|
+
ref2.anchor = onAnchor(value);
|
|
24457
|
+
return new Alias(ref2.anchor);
|
|
24458
|
+
} else {
|
|
24459
|
+
ref2 = { anchor: null, node: null };
|
|
24460
|
+
sourceObjects.set(value, ref2);
|
|
24461
|
+
}
|
|
24462
|
+
}
|
|
24463
|
+
if (tagName == null ? void 0 : tagName.startsWith("!!"))
|
|
24464
|
+
tagName = defaultTagPrefix + tagName.slice(2);
|
|
24465
|
+
let tagObj = findTagObject(value, tagName, schema.tags);
|
|
24466
|
+
if (!tagObj) {
|
|
24467
|
+
if (value && typeof value.toJSON === "function") {
|
|
24468
|
+
value = value.toJSON();
|
|
24469
|
+
}
|
|
24470
|
+
if (!value || typeof value !== "object") {
|
|
24471
|
+
const node2 = new Scalar(value);
|
|
24472
|
+
if (ref2)
|
|
24473
|
+
ref2.node = node2;
|
|
24474
|
+
return node2;
|
|
24475
|
+
}
|
|
24476
|
+
tagObj = value instanceof Map ? schema[MAP] : Symbol.iterator in Object(value) ? schema[SEQ] : schema[MAP];
|
|
24477
|
+
}
|
|
24478
|
+
if (onTagObj) {
|
|
24479
|
+
onTagObj(tagObj);
|
|
24480
|
+
delete ctx.onTagObj;
|
|
24481
|
+
}
|
|
24482
|
+
const node = (tagObj == null ? void 0 : tagObj.createNode) ? tagObj.createNode(ctx.schema, value, ctx) : typeof ((_c = tagObj == null ? void 0 : tagObj.nodeClass) == null ? void 0 : _c.from) === "function" ? tagObj.nodeClass.from(ctx.schema, value, ctx) : new Scalar(value);
|
|
24483
|
+
if (tagName)
|
|
24484
|
+
node.tag = tagName;
|
|
24485
|
+
else if (!tagObj.default)
|
|
24486
|
+
node.tag = tagObj.tag;
|
|
24487
|
+
if (ref2)
|
|
24488
|
+
ref2.node = node;
|
|
24489
|
+
return node;
|
|
24490
|
+
}
|
|
24491
|
+
function collectionFromPath(schema, path, value) {
|
|
24492
|
+
let v = value;
|
|
24493
|
+
for (let i = path.length - 1; i >= 0; --i) {
|
|
24494
|
+
const k = path[i];
|
|
24495
|
+
if (typeof k === "number" && Number.isInteger(k) && k >= 0) {
|
|
24496
|
+
const a = [];
|
|
24497
|
+
a[k] = v;
|
|
24498
|
+
v = a;
|
|
24499
|
+
} else {
|
|
24500
|
+
v = /* @__PURE__ */ new Map([[k, v]]);
|
|
24501
|
+
}
|
|
24502
|
+
}
|
|
24503
|
+
return createNode(v, void 0, {
|
|
24504
|
+
aliasDuplicateObjects: false,
|
|
24505
|
+
keepUndefined: false,
|
|
24506
|
+
onAnchor: () => {
|
|
24507
|
+
throw new Error("This should not happen, please report a bug.");
|
|
24508
|
+
},
|
|
24509
|
+
schema,
|
|
24510
|
+
sourceObjects: /* @__PURE__ */ new Map()
|
|
24511
|
+
});
|
|
24512
|
+
}
|
|
24513
|
+
const isEmptyPath = (path) => path == null || typeof path === "object" && !!path[Symbol.iterator]().next().done;
|
|
24514
|
+
class Collection extends NodeBase {
|
|
24515
|
+
constructor(type, schema) {
|
|
24516
|
+
super(type);
|
|
24517
|
+
Object.defineProperty(this, "schema", {
|
|
24518
|
+
value: schema,
|
|
24519
|
+
configurable: true,
|
|
24520
|
+
enumerable: false,
|
|
24521
|
+
writable: true
|
|
24522
|
+
});
|
|
24523
|
+
}
|
|
24524
|
+
/**
|
|
24525
|
+
* Create a copy of this collection.
|
|
24526
|
+
*
|
|
24527
|
+
* @param schema - If defined, overwrites the original's schema
|
|
24528
|
+
*/
|
|
24529
|
+
clone(schema) {
|
|
24530
|
+
const copy = Object.create(Object.getPrototypeOf(this), Object.getOwnPropertyDescriptors(this));
|
|
24531
|
+
if (schema)
|
|
24532
|
+
copy.schema = schema;
|
|
24533
|
+
copy.items = copy.items.map((it) => isNode(it) || isPair(it) ? it.clone(schema) : it);
|
|
24534
|
+
if (this.range)
|
|
24535
|
+
copy.range = this.range.slice();
|
|
24536
|
+
return copy;
|
|
24537
|
+
}
|
|
24538
|
+
/**
|
|
24539
|
+
* Adds a value to the collection. For `!!map` and `!!omap` the value must
|
|
24540
|
+
* be a Pair instance or a `{ key, value }` object, which may not have a key
|
|
24541
|
+
* that already exists in the map.
|
|
24542
|
+
*/
|
|
24543
|
+
addIn(path, value) {
|
|
24544
|
+
if (isEmptyPath(path))
|
|
24545
|
+
this.add(value);
|
|
24546
|
+
else {
|
|
24547
|
+
const [key, ...rest] = path;
|
|
24548
|
+
const node = this.get(key, true);
|
|
24549
|
+
if (isCollection(node))
|
|
24550
|
+
node.addIn(rest, value);
|
|
24551
|
+
else if (node === void 0 && this.schema)
|
|
24552
|
+
this.set(key, collectionFromPath(this.schema, rest, value));
|
|
24553
|
+
else
|
|
24554
|
+
throw new Error(`Expected YAML collection at ${key}. Remaining path: ${rest}`);
|
|
24555
|
+
}
|
|
24556
|
+
}
|
|
24557
|
+
/**
|
|
24558
|
+
* Removes a value from the collection.
|
|
24559
|
+
* @returns `true` if the item was found and removed.
|
|
24560
|
+
*/
|
|
24561
|
+
deleteIn(path) {
|
|
24562
|
+
const [key, ...rest] = path;
|
|
24563
|
+
if (rest.length === 0)
|
|
24564
|
+
return this.delete(key);
|
|
24565
|
+
const node = this.get(key, true);
|
|
24566
|
+
if (isCollection(node))
|
|
24567
|
+
return node.deleteIn(rest);
|
|
24568
|
+
else
|
|
24569
|
+
throw new Error(`Expected YAML collection at ${key}. Remaining path: ${rest}`);
|
|
24570
|
+
}
|
|
24571
|
+
/**
|
|
24572
|
+
* Returns item at `key`, or `undefined` if not found. By default unwraps
|
|
24573
|
+
* scalar values from their surrounding node; to disable set `keepScalar` to
|
|
24574
|
+
* `true` (collections are always returned intact).
|
|
24575
|
+
*/
|
|
24576
|
+
getIn(path, keepScalar) {
|
|
24577
|
+
const [key, ...rest] = path;
|
|
24578
|
+
const node = this.get(key, true);
|
|
24579
|
+
if (rest.length === 0)
|
|
24580
|
+
return !keepScalar && isScalar(node) ? node.value : node;
|
|
24581
|
+
else
|
|
24582
|
+
return isCollection(node) ? node.getIn(rest, keepScalar) : void 0;
|
|
24583
|
+
}
|
|
24584
|
+
hasAllNullValues(allowScalar) {
|
|
24585
|
+
return this.items.every((node) => {
|
|
24586
|
+
if (!isPair(node))
|
|
24587
|
+
return false;
|
|
24588
|
+
const n = node.value;
|
|
24589
|
+
return n == null || allowScalar && isScalar(n) && n.value == null && !n.commentBefore && !n.comment && !n.tag;
|
|
24590
|
+
});
|
|
24591
|
+
}
|
|
24592
|
+
/**
|
|
24593
|
+
* Checks if the collection includes a value with the key `key`.
|
|
24594
|
+
*/
|
|
24595
|
+
hasIn(path) {
|
|
24596
|
+
const [key, ...rest] = path;
|
|
24597
|
+
if (rest.length === 0)
|
|
24598
|
+
return this.has(key);
|
|
24599
|
+
const node = this.get(key, true);
|
|
24600
|
+
return isCollection(node) ? node.hasIn(rest) : false;
|
|
24601
|
+
}
|
|
24602
|
+
/**
|
|
24603
|
+
* Sets a value in this collection. For `!!set`, `value` needs to be a
|
|
24604
|
+
* boolean to add/remove the item from the set.
|
|
24605
|
+
*/
|
|
24606
|
+
setIn(path, value) {
|
|
24607
|
+
const [key, ...rest] = path;
|
|
24608
|
+
if (rest.length === 0) {
|
|
24609
|
+
this.set(key, value);
|
|
24610
|
+
} else {
|
|
24611
|
+
const node = this.get(key, true);
|
|
24612
|
+
if (isCollection(node))
|
|
24613
|
+
node.setIn(rest, value);
|
|
24614
|
+
else if (node === void 0 && this.schema)
|
|
24615
|
+
this.set(key, collectionFromPath(this.schema, rest, value));
|
|
24616
|
+
else
|
|
24617
|
+
throw new Error(`Expected YAML collection at ${key}. Remaining path: ${rest}`);
|
|
24618
|
+
}
|
|
24619
|
+
}
|
|
24620
|
+
}
|
|
24621
|
+
Collection.maxFlowStringSingleLineLength = 60;
|
|
24622
|
+
const stringifyComment = (str) => str.replace(/^(?!$)(?: $)?/gm, "#");
|
|
24623
|
+
function indentComment(comment2, indent) {
|
|
24624
|
+
if (/^\n+$/.test(comment2))
|
|
24625
|
+
return comment2.substring(1);
|
|
24626
|
+
return indent ? comment2.replace(/^(?! *$)/gm, indent) : comment2;
|
|
24627
|
+
}
|
|
24628
|
+
const lineComment = (str, indent, comment2) => str.endsWith("\n") ? indentComment(comment2, indent) : comment2.includes("\n") ? "\n" + indentComment(comment2, indent) : (str.endsWith(" ") ? "" : " ") + comment2;
|
|
24629
|
+
const FOLD_FLOW = "flow";
|
|
24630
|
+
const FOLD_BLOCK = "block";
|
|
24631
|
+
const FOLD_QUOTED = "quoted";
|
|
24632
|
+
function foldFlowLines(text, indent, mode = "flow", { indentAtStart, lineWidth = 80, minContentWidth = 20, onFold, onOverflow } = {}) {
|
|
24633
|
+
if (!lineWidth || lineWidth < 0)
|
|
24634
|
+
return text;
|
|
24635
|
+
const endStep = Math.max(1 + minContentWidth, 1 + lineWidth - indent.length);
|
|
24636
|
+
if (text.length <= endStep)
|
|
24637
|
+
return text;
|
|
24638
|
+
const folds = [];
|
|
24639
|
+
const escapedFolds = {};
|
|
24640
|
+
let end = lineWidth - indent.length;
|
|
24641
|
+
if (typeof indentAtStart === "number") {
|
|
24642
|
+
if (indentAtStart > lineWidth - Math.max(2, minContentWidth))
|
|
24643
|
+
folds.push(0);
|
|
24644
|
+
else
|
|
24645
|
+
end = lineWidth - indentAtStart;
|
|
24646
|
+
}
|
|
24647
|
+
let split = void 0;
|
|
24648
|
+
let prev = void 0;
|
|
24649
|
+
let overflow = false;
|
|
24650
|
+
let i = -1;
|
|
24651
|
+
let escStart = -1;
|
|
24652
|
+
let escEnd = -1;
|
|
24653
|
+
if (mode === FOLD_BLOCK) {
|
|
24654
|
+
i = consumeMoreIndentedLines(text, i, indent.length);
|
|
24655
|
+
if (i !== -1)
|
|
24656
|
+
end = i + endStep;
|
|
24657
|
+
}
|
|
24658
|
+
for (let ch; ch = text[i += 1]; ) {
|
|
24659
|
+
if (mode === FOLD_QUOTED && ch === "\\") {
|
|
24660
|
+
escStart = i;
|
|
24661
|
+
switch (text[i + 1]) {
|
|
24662
|
+
case "x":
|
|
24663
|
+
i += 3;
|
|
24664
|
+
break;
|
|
24665
|
+
case "u":
|
|
24666
|
+
i += 5;
|
|
24667
|
+
break;
|
|
24668
|
+
case "U":
|
|
24669
|
+
i += 9;
|
|
24670
|
+
break;
|
|
24671
|
+
default:
|
|
24672
|
+
i += 1;
|
|
24673
|
+
}
|
|
24674
|
+
escEnd = i;
|
|
24675
|
+
}
|
|
24676
|
+
if (ch === "\n") {
|
|
24677
|
+
if (mode === FOLD_BLOCK)
|
|
24678
|
+
i = consumeMoreIndentedLines(text, i, indent.length);
|
|
24679
|
+
end = i + indent.length + endStep;
|
|
24680
|
+
split = void 0;
|
|
24681
|
+
} else {
|
|
24682
|
+
if (ch === " " && prev && prev !== " " && prev !== "\n" && prev !== " ") {
|
|
24683
|
+
const next = text[i + 1];
|
|
24684
|
+
if (next && next !== " " && next !== "\n" && next !== " ")
|
|
24685
|
+
split = i;
|
|
24686
|
+
}
|
|
24687
|
+
if (i >= end) {
|
|
24688
|
+
if (split) {
|
|
24689
|
+
folds.push(split);
|
|
24690
|
+
end = split + endStep;
|
|
24691
|
+
split = void 0;
|
|
24692
|
+
} else if (mode === FOLD_QUOTED) {
|
|
24693
|
+
while (prev === " " || prev === " ") {
|
|
24694
|
+
prev = ch;
|
|
24695
|
+
ch = text[i += 1];
|
|
24696
|
+
overflow = true;
|
|
24697
|
+
}
|
|
24698
|
+
const j = i > escEnd + 1 ? i - 2 : escStart - 1;
|
|
24699
|
+
if (escapedFolds[j])
|
|
24700
|
+
return text;
|
|
24701
|
+
folds.push(j);
|
|
24702
|
+
escapedFolds[j] = true;
|
|
24703
|
+
end = j + endStep;
|
|
24704
|
+
split = void 0;
|
|
24705
|
+
} else {
|
|
24706
|
+
overflow = true;
|
|
24707
|
+
}
|
|
24708
|
+
}
|
|
24709
|
+
}
|
|
24710
|
+
prev = ch;
|
|
24711
|
+
}
|
|
24712
|
+
if (overflow && onOverflow)
|
|
24713
|
+
onOverflow();
|
|
24714
|
+
if (folds.length === 0)
|
|
24715
|
+
return text;
|
|
24716
|
+
if (onFold)
|
|
24717
|
+
onFold();
|
|
24718
|
+
let res = text.slice(0, folds[0]);
|
|
24719
|
+
for (let i2 = 0; i2 < folds.length; ++i2) {
|
|
24720
|
+
const fold = folds[i2];
|
|
24721
|
+
const end2 = folds[i2 + 1] || text.length;
|
|
24722
|
+
if (fold === 0)
|
|
24723
|
+
res = `
|
|
24724
|
+
${indent}${text.slice(0, end2)}`;
|
|
24725
|
+
else {
|
|
24726
|
+
if (mode === FOLD_QUOTED && escapedFolds[fold])
|
|
24727
|
+
res += `${text[fold]}\\`;
|
|
24728
|
+
res += `
|
|
24729
|
+
${indent}${text.slice(fold + 1, end2)}`;
|
|
24730
|
+
}
|
|
24731
|
+
}
|
|
24732
|
+
return res;
|
|
24733
|
+
}
|
|
24734
|
+
function consumeMoreIndentedLines(text, i, indent) {
|
|
24735
|
+
let end = i;
|
|
24736
|
+
let start = i + 1;
|
|
24737
|
+
let ch = text[start];
|
|
24738
|
+
while (ch === " " || ch === " ") {
|
|
24739
|
+
if (i < start + indent) {
|
|
24740
|
+
ch = text[++i];
|
|
24741
|
+
} else {
|
|
24742
|
+
do {
|
|
24743
|
+
ch = text[++i];
|
|
24744
|
+
} while (ch && ch !== "\n");
|
|
24745
|
+
end = i;
|
|
24746
|
+
start = i + 1;
|
|
24747
|
+
ch = text[start];
|
|
24748
|
+
}
|
|
24749
|
+
}
|
|
24750
|
+
return end;
|
|
24751
|
+
}
|
|
24752
|
+
const getFoldOptions = (ctx, isBlock) => ({
|
|
24753
|
+
indentAtStart: isBlock ? ctx.indent.length : ctx.indentAtStart,
|
|
24754
|
+
lineWidth: ctx.options.lineWidth,
|
|
24755
|
+
minContentWidth: ctx.options.minContentWidth
|
|
24756
|
+
});
|
|
24757
|
+
const containsDocumentMarker = (str) => /^(%|---|\.\.\.)/m.test(str);
|
|
24758
|
+
function lineLengthOverLimit(str, lineWidth, indentLength) {
|
|
24759
|
+
if (!lineWidth || lineWidth < 0)
|
|
24760
|
+
return false;
|
|
24761
|
+
const limit = lineWidth - indentLength;
|
|
24762
|
+
const strLen = str.length;
|
|
24763
|
+
if (strLen <= limit)
|
|
24764
|
+
return false;
|
|
24765
|
+
for (let i = 0, start = 0; i < strLen; ++i) {
|
|
24766
|
+
if (str[i] === "\n") {
|
|
24767
|
+
if (i - start > limit)
|
|
24768
|
+
return true;
|
|
24769
|
+
start = i + 1;
|
|
24770
|
+
if (strLen - start <= limit)
|
|
24771
|
+
return false;
|
|
24772
|
+
}
|
|
24773
|
+
}
|
|
24774
|
+
return true;
|
|
24775
|
+
}
|
|
24776
|
+
function doubleQuotedString(value, ctx) {
|
|
24777
|
+
const json2 = JSON.stringify(value);
|
|
24778
|
+
if (ctx.options.doubleQuotedAsJSON)
|
|
24779
|
+
return json2;
|
|
24780
|
+
const { implicitKey } = ctx;
|
|
24781
|
+
const minMultiLineLength = ctx.options.doubleQuotedMinMultiLineLength;
|
|
24782
|
+
const indent = ctx.indent || (containsDocumentMarker(value) ? " " : "");
|
|
24783
|
+
let str = "";
|
|
24784
|
+
let start = 0;
|
|
24785
|
+
for (let i = 0, ch = json2[i]; ch; ch = json2[++i]) {
|
|
24786
|
+
if (ch === " " && json2[i + 1] === "\\" && json2[i + 2] === "n") {
|
|
24787
|
+
str += json2.slice(start, i) + "\\ ";
|
|
24788
|
+
i += 1;
|
|
24789
|
+
start = i;
|
|
24790
|
+
ch = "\\";
|
|
24791
|
+
}
|
|
24792
|
+
if (ch === "\\")
|
|
24793
|
+
switch (json2[i + 1]) {
|
|
24794
|
+
case "u":
|
|
24795
|
+
{
|
|
24796
|
+
str += json2.slice(start, i);
|
|
24797
|
+
const code = json2.substr(i + 2, 4);
|
|
24798
|
+
switch (code) {
|
|
24799
|
+
case "0000":
|
|
24800
|
+
str += "\\0";
|
|
24801
|
+
break;
|
|
24802
|
+
case "0007":
|
|
24803
|
+
str += "\\a";
|
|
24804
|
+
break;
|
|
24805
|
+
case "000b":
|
|
24806
|
+
str += "\\v";
|
|
24807
|
+
break;
|
|
24808
|
+
case "001b":
|
|
24809
|
+
str += "\\e";
|
|
24810
|
+
break;
|
|
24811
|
+
case "0085":
|
|
24812
|
+
str += "\\N";
|
|
24813
|
+
break;
|
|
24814
|
+
case "00a0":
|
|
24815
|
+
str += "\\_";
|
|
24816
|
+
break;
|
|
24817
|
+
case "2028":
|
|
24818
|
+
str += "\\L";
|
|
24819
|
+
break;
|
|
24820
|
+
case "2029":
|
|
24821
|
+
str += "\\P";
|
|
24822
|
+
break;
|
|
24823
|
+
default:
|
|
24824
|
+
if (code.substr(0, 2) === "00")
|
|
24825
|
+
str += "\\x" + code.substr(2);
|
|
24826
|
+
else
|
|
24827
|
+
str += json2.substr(i, 6);
|
|
24828
|
+
}
|
|
24829
|
+
i += 5;
|
|
24830
|
+
start = i + 1;
|
|
24831
|
+
}
|
|
24832
|
+
break;
|
|
24833
|
+
case "n":
|
|
24834
|
+
if (implicitKey || json2[i + 2] === '"' || json2.length < minMultiLineLength) {
|
|
24835
|
+
i += 1;
|
|
24836
|
+
} else {
|
|
24837
|
+
str += json2.slice(start, i) + "\n\n";
|
|
24838
|
+
while (json2[i + 2] === "\\" && json2[i + 3] === "n" && json2[i + 4] !== '"') {
|
|
24839
|
+
str += "\n";
|
|
24840
|
+
i += 2;
|
|
24841
|
+
}
|
|
24842
|
+
str += indent;
|
|
24843
|
+
if (json2[i + 2] === " ")
|
|
24844
|
+
str += "\\";
|
|
24845
|
+
i += 1;
|
|
24846
|
+
start = i + 1;
|
|
24847
|
+
}
|
|
24848
|
+
break;
|
|
24849
|
+
default:
|
|
24850
|
+
i += 1;
|
|
24851
|
+
}
|
|
24852
|
+
}
|
|
24853
|
+
str = start ? str + json2.slice(start) : json2;
|
|
24854
|
+
return implicitKey ? str : foldFlowLines(str, indent, FOLD_QUOTED, getFoldOptions(ctx, false));
|
|
24855
|
+
}
|
|
24856
|
+
function singleQuotedString(value, ctx) {
|
|
24857
|
+
if (ctx.options.singleQuote === false || ctx.implicitKey && value.includes("\n") || /[ \t]\n|\n[ \t]/.test(value))
|
|
24858
|
+
return doubleQuotedString(value, ctx);
|
|
24859
|
+
const indent = ctx.indent || (containsDocumentMarker(value) ? " " : "");
|
|
24860
|
+
const res = "'" + value.replace(/'/g, "''").replace(/\n+/g, `$&
|
|
24861
|
+
${indent}`) + "'";
|
|
24862
|
+
return ctx.implicitKey ? res : foldFlowLines(res, indent, FOLD_FLOW, getFoldOptions(ctx, false));
|
|
24863
|
+
}
|
|
24864
|
+
function quotedString(value, ctx) {
|
|
24865
|
+
const { singleQuote } = ctx.options;
|
|
24866
|
+
let qs;
|
|
24867
|
+
if (singleQuote === false)
|
|
24868
|
+
qs = doubleQuotedString;
|
|
24869
|
+
else {
|
|
24870
|
+
const hasDouble = value.includes('"');
|
|
24871
|
+
const hasSingle = value.includes("'");
|
|
24872
|
+
if (hasDouble && !hasSingle)
|
|
24873
|
+
qs = singleQuotedString;
|
|
24874
|
+
else if (hasSingle && !hasDouble)
|
|
24875
|
+
qs = doubleQuotedString;
|
|
24876
|
+
else
|
|
24877
|
+
qs = singleQuote ? singleQuotedString : doubleQuotedString;
|
|
24878
|
+
}
|
|
24879
|
+
return qs(value, ctx);
|
|
24880
|
+
}
|
|
24881
|
+
let blockEndNewlines;
|
|
24882
|
+
try {
|
|
24883
|
+
blockEndNewlines = new RegExp("(^|(?<!\n))\n+(?!\n|$)", "g");
|
|
24884
|
+
} catch {
|
|
24885
|
+
blockEndNewlines = /\n+(?!\n|$)/g;
|
|
24886
|
+
}
|
|
24887
|
+
function blockString({ comment: comment2, type, value }, ctx, onComment, onChompKeep) {
|
|
24888
|
+
const { blockQuote, commentString, lineWidth } = ctx.options;
|
|
24889
|
+
if (!blockQuote || /\n[\t ]+$/.test(value) || /^\s*$/.test(value)) {
|
|
24890
|
+
return quotedString(value, ctx);
|
|
24891
|
+
}
|
|
24892
|
+
const indent = ctx.indent || (ctx.forceBlockIndent || containsDocumentMarker(value) ? " " : "");
|
|
24893
|
+
const literal2 = blockQuote === "literal" ? true : blockQuote === "folded" || type === Scalar.BLOCK_FOLDED ? false : type === Scalar.BLOCK_LITERAL ? true : !lineLengthOverLimit(value, lineWidth, indent.length);
|
|
24894
|
+
if (!value)
|
|
24895
|
+
return literal2 ? "|\n" : ">\n";
|
|
24896
|
+
let chomp;
|
|
24897
|
+
let endStart;
|
|
24898
|
+
for (endStart = value.length; endStart > 0; --endStart) {
|
|
24899
|
+
const ch = value[endStart - 1];
|
|
24900
|
+
if (ch !== "\n" && ch !== " " && ch !== " ")
|
|
24901
|
+
break;
|
|
24902
|
+
}
|
|
24903
|
+
let end = value.substring(endStart);
|
|
24904
|
+
const endNlPos = end.indexOf("\n");
|
|
24905
|
+
if (endNlPos === -1) {
|
|
24906
|
+
chomp = "-";
|
|
24907
|
+
} else if (value === end || endNlPos !== end.length - 1) {
|
|
24908
|
+
chomp = "+";
|
|
24909
|
+
if (onChompKeep)
|
|
24910
|
+
onChompKeep();
|
|
24911
|
+
} else {
|
|
24912
|
+
chomp = "";
|
|
24913
|
+
}
|
|
24914
|
+
if (end) {
|
|
24915
|
+
value = value.slice(0, -end.length);
|
|
24916
|
+
if (end[end.length - 1] === "\n")
|
|
24917
|
+
end = end.slice(0, -1);
|
|
24918
|
+
end = end.replace(blockEndNewlines, `$&${indent}`);
|
|
24919
|
+
}
|
|
24920
|
+
let startWithSpace = false;
|
|
24921
|
+
let startEnd;
|
|
24922
|
+
let startNlPos = -1;
|
|
24923
|
+
for (startEnd = 0; startEnd < value.length; ++startEnd) {
|
|
24924
|
+
const ch = value[startEnd];
|
|
24925
|
+
if (ch === " ")
|
|
24926
|
+
startWithSpace = true;
|
|
24927
|
+
else if (ch === "\n")
|
|
24928
|
+
startNlPos = startEnd;
|
|
24929
|
+
else
|
|
24930
|
+
break;
|
|
24931
|
+
}
|
|
24932
|
+
let start = value.substring(0, startNlPos < startEnd ? startNlPos + 1 : startEnd);
|
|
24933
|
+
if (start) {
|
|
24934
|
+
value = value.substring(start.length);
|
|
24935
|
+
start = start.replace(/\n+/g, `$&${indent}`);
|
|
24936
|
+
}
|
|
24937
|
+
const indentSize = indent ? "2" : "1";
|
|
24938
|
+
let header = (literal2 ? "|" : ">") + (startWithSpace ? indentSize : "") + chomp;
|
|
24939
|
+
if (comment2) {
|
|
24940
|
+
header += " " + commentString(comment2.replace(/ ?[\r\n]+/g, " "));
|
|
24941
|
+
if (onComment)
|
|
24942
|
+
onComment();
|
|
24943
|
+
}
|
|
24944
|
+
if (literal2) {
|
|
24945
|
+
value = value.replace(/\n+/g, `$&${indent}`);
|
|
24946
|
+
return `${header}
|
|
24947
|
+
${indent}${start}${value}${end}`;
|
|
24948
|
+
}
|
|
24949
|
+
value = value.replace(/\n+/g, "\n$&").replace(/(?:^|\n)([\t ].*)(?:([\n\t ]*)\n(?![\n\t ]))?/g, "$1$2").replace(/\n+/g, `$&${indent}`);
|
|
24950
|
+
const body = foldFlowLines(`${start}${value}${end}`, indent, FOLD_BLOCK, getFoldOptions(ctx, true));
|
|
24951
|
+
return `${header}
|
|
24952
|
+
${indent}${body}`;
|
|
24953
|
+
}
|
|
24954
|
+
function plainString(item, ctx, onComment, onChompKeep) {
|
|
24955
|
+
const { type, value } = item;
|
|
24956
|
+
const { actualString, implicitKey, indent, indentStep, inFlow } = ctx;
|
|
24957
|
+
if (implicitKey && value.includes("\n") || inFlow && /[[\]{},]/.test(value)) {
|
|
24958
|
+
return quotedString(value, ctx);
|
|
24959
|
+
}
|
|
24960
|
+
if (!value || /^[\n\t ,[\]{}#&*!|>'"%@`]|^[?-]$|^[?-][ \t]|[\n:][ \t]|[ \t]\n|[\n\t ]#|[\n\t :]$/.test(value)) {
|
|
24961
|
+
return implicitKey || inFlow || !value.includes("\n") ? quotedString(value, ctx) : blockString(item, ctx, onComment, onChompKeep);
|
|
24962
|
+
}
|
|
24963
|
+
if (!implicitKey && !inFlow && type !== Scalar.PLAIN && value.includes("\n")) {
|
|
24964
|
+
return blockString(item, ctx, onComment, onChompKeep);
|
|
24965
|
+
}
|
|
24966
|
+
if (containsDocumentMarker(value)) {
|
|
24967
|
+
if (indent === "") {
|
|
24968
|
+
ctx.forceBlockIndent = true;
|
|
24969
|
+
return blockString(item, ctx, onComment, onChompKeep);
|
|
24970
|
+
} else if (implicitKey && indent === indentStep) {
|
|
24971
|
+
return quotedString(value, ctx);
|
|
24972
|
+
}
|
|
24973
|
+
}
|
|
24974
|
+
const str = value.replace(/\n+/g, `$&
|
|
24975
|
+
${indent}`);
|
|
24976
|
+
if (actualString) {
|
|
24977
|
+
const test = (tag) => {
|
|
24978
|
+
var _a2;
|
|
24979
|
+
return tag.default && tag.tag !== "tag:yaml.org,2002:str" && ((_a2 = tag.test) == null ? void 0 : _a2.test(str));
|
|
24980
|
+
};
|
|
24981
|
+
const { compat, tags: tags2 } = ctx.doc.schema;
|
|
24982
|
+
if (tags2.some(test) || (compat == null ? void 0 : compat.some(test)))
|
|
24983
|
+
return quotedString(value, ctx);
|
|
24984
|
+
}
|
|
24985
|
+
return implicitKey ? str : foldFlowLines(str, indent, FOLD_FLOW, getFoldOptions(ctx, false));
|
|
24986
|
+
}
|
|
24987
|
+
function stringifyString(item, ctx, onComment, onChompKeep) {
|
|
24988
|
+
const { implicitKey, inFlow } = ctx;
|
|
24989
|
+
const ss = typeof item.value === "string" ? item : Object.assign({}, item, { value: String(item.value) });
|
|
24990
|
+
let { type } = item;
|
|
24991
|
+
if (type !== Scalar.QUOTE_DOUBLE) {
|
|
24992
|
+
if (/[\x00-\x08\x0b-\x1f\x7f-\x9f\u{D800}-\u{DFFF}]/u.test(ss.value))
|
|
24993
|
+
type = Scalar.QUOTE_DOUBLE;
|
|
24994
|
+
}
|
|
24995
|
+
const _stringify = (_type) => {
|
|
24996
|
+
switch (_type) {
|
|
24997
|
+
case Scalar.BLOCK_FOLDED:
|
|
24998
|
+
case Scalar.BLOCK_LITERAL:
|
|
24999
|
+
return implicitKey || inFlow ? quotedString(ss.value, ctx) : blockString(ss, ctx, onComment, onChompKeep);
|
|
25000
|
+
case Scalar.QUOTE_DOUBLE:
|
|
25001
|
+
return doubleQuotedString(ss.value, ctx);
|
|
25002
|
+
case Scalar.QUOTE_SINGLE:
|
|
25003
|
+
return singleQuotedString(ss.value, ctx);
|
|
25004
|
+
case Scalar.PLAIN:
|
|
25005
|
+
return plainString(ss, ctx, onComment, onChompKeep);
|
|
25006
|
+
default:
|
|
25007
|
+
return null;
|
|
25008
|
+
}
|
|
25009
|
+
};
|
|
25010
|
+
let res = _stringify(type);
|
|
25011
|
+
if (res === null) {
|
|
25012
|
+
const { defaultKeyType, defaultStringType } = ctx.options;
|
|
25013
|
+
const t2 = implicitKey && defaultKeyType || defaultStringType;
|
|
25014
|
+
res = _stringify(t2);
|
|
25015
|
+
if (res === null)
|
|
25016
|
+
throw new Error(`Unsupported default string type ${t2}`);
|
|
25017
|
+
}
|
|
25018
|
+
return res;
|
|
25019
|
+
}
|
|
25020
|
+
function createStringifyContext(doc2, options) {
|
|
25021
|
+
const opt = Object.assign({
|
|
25022
|
+
blockQuote: true,
|
|
25023
|
+
commentString: stringifyComment,
|
|
25024
|
+
defaultKeyType: null,
|
|
25025
|
+
defaultStringType: "PLAIN",
|
|
25026
|
+
directives: null,
|
|
25027
|
+
doubleQuotedAsJSON: false,
|
|
25028
|
+
doubleQuotedMinMultiLineLength: 40,
|
|
25029
|
+
falseStr: "false",
|
|
25030
|
+
flowCollectionPadding: true,
|
|
25031
|
+
indentSeq: true,
|
|
25032
|
+
lineWidth: 80,
|
|
25033
|
+
minContentWidth: 20,
|
|
25034
|
+
nullStr: "null",
|
|
25035
|
+
simpleKeys: false,
|
|
25036
|
+
singleQuote: null,
|
|
25037
|
+
trueStr: "true",
|
|
25038
|
+
verifyAliasOrder: true
|
|
25039
|
+
}, doc2.schema.toStringOptions, options);
|
|
25040
|
+
let inFlow;
|
|
25041
|
+
switch (opt.collectionStyle) {
|
|
25042
|
+
case "block":
|
|
25043
|
+
inFlow = false;
|
|
25044
|
+
break;
|
|
25045
|
+
case "flow":
|
|
25046
|
+
inFlow = true;
|
|
25047
|
+
break;
|
|
25048
|
+
default:
|
|
25049
|
+
inFlow = null;
|
|
25050
|
+
}
|
|
25051
|
+
return {
|
|
25052
|
+
anchors: /* @__PURE__ */ new Set(),
|
|
25053
|
+
doc: doc2,
|
|
25054
|
+
flowCollectionPadding: opt.flowCollectionPadding ? " " : "",
|
|
25055
|
+
indent: "",
|
|
25056
|
+
indentStep: typeof opt.indent === "number" ? " ".repeat(opt.indent) : " ",
|
|
25057
|
+
inFlow,
|
|
25058
|
+
options: opt
|
|
25059
|
+
};
|
|
25060
|
+
}
|
|
25061
|
+
function getTagObject(tags2, item) {
|
|
25062
|
+
var _a2;
|
|
25063
|
+
if (item.tag) {
|
|
25064
|
+
const match = tags2.filter((t2) => t2.tag === item.tag);
|
|
25065
|
+
if (match.length > 0)
|
|
25066
|
+
return match.find((t2) => t2.format === item.format) ?? match[0];
|
|
25067
|
+
}
|
|
25068
|
+
let tagObj = void 0;
|
|
25069
|
+
let obj;
|
|
25070
|
+
if (isScalar(item)) {
|
|
25071
|
+
obj = item.value;
|
|
25072
|
+
const match = tags2.filter((t2) => {
|
|
25073
|
+
var _a3;
|
|
25074
|
+
return (_a3 = t2.identify) == null ? void 0 : _a3.call(t2, obj);
|
|
25075
|
+
});
|
|
25076
|
+
tagObj = match.find((t2) => t2.format === item.format) ?? match.find((t2) => !t2.format);
|
|
25077
|
+
} else {
|
|
25078
|
+
obj = item;
|
|
25079
|
+
tagObj = tags2.find((t2) => t2.nodeClass && obj instanceof t2.nodeClass);
|
|
25080
|
+
}
|
|
25081
|
+
if (!tagObj) {
|
|
25082
|
+
const name2 = ((_a2 = obj == null ? void 0 : obj.constructor) == null ? void 0 : _a2.name) ?? typeof obj;
|
|
25083
|
+
throw new Error(`Tag not resolved for ${name2} value`);
|
|
25084
|
+
}
|
|
25085
|
+
return tagObj;
|
|
25086
|
+
}
|
|
25087
|
+
function stringifyProps(node, tagObj, { anchors, doc: doc2 }) {
|
|
25088
|
+
if (!doc2.directives)
|
|
25089
|
+
return "";
|
|
25090
|
+
const props = [];
|
|
25091
|
+
const anchor = (isScalar(node) || isCollection(node)) && node.anchor;
|
|
25092
|
+
if (anchor && anchorIsValid(anchor)) {
|
|
25093
|
+
anchors.add(anchor);
|
|
25094
|
+
props.push(`&${anchor}`);
|
|
25095
|
+
}
|
|
25096
|
+
const tag = node.tag ? node.tag : tagObj.default ? null : tagObj.tag;
|
|
25097
|
+
if (tag)
|
|
25098
|
+
props.push(doc2.directives.tagString(tag));
|
|
25099
|
+
return props.join(" ");
|
|
25100
|
+
}
|
|
25101
|
+
function stringify(item, ctx, onComment, onChompKeep) {
|
|
25102
|
+
var _a2;
|
|
25103
|
+
if (isPair(item))
|
|
25104
|
+
return item.toString(ctx, onComment, onChompKeep);
|
|
25105
|
+
if (isAlias(item)) {
|
|
25106
|
+
if (ctx.doc.directives)
|
|
25107
|
+
return item.toString(ctx);
|
|
25108
|
+
if ((_a2 = ctx.resolvedAliases) == null ? void 0 : _a2.has(item)) {
|
|
25109
|
+
throw new TypeError(`Cannot stringify circular structure without alias nodes`);
|
|
25110
|
+
} else {
|
|
25111
|
+
if (ctx.resolvedAliases)
|
|
25112
|
+
ctx.resolvedAliases.add(item);
|
|
25113
|
+
else
|
|
25114
|
+
ctx.resolvedAliases = /* @__PURE__ */ new Set([item]);
|
|
25115
|
+
item = item.resolve(ctx.doc);
|
|
25116
|
+
}
|
|
25117
|
+
}
|
|
25118
|
+
let tagObj = void 0;
|
|
25119
|
+
const node = isNode(item) ? item : ctx.doc.createNode(item, { onTagObj: (o) => tagObj = o });
|
|
25120
|
+
if (!tagObj)
|
|
25121
|
+
tagObj = getTagObject(ctx.doc.schema.tags, node);
|
|
25122
|
+
const props = stringifyProps(node, tagObj, ctx);
|
|
25123
|
+
if (props.length > 0)
|
|
25124
|
+
ctx.indentAtStart = (ctx.indentAtStart ?? 0) + props.length + 1;
|
|
25125
|
+
const str = typeof tagObj.stringify === "function" ? tagObj.stringify(node, ctx, onComment, onChompKeep) : isScalar(node) ? stringifyString(node, ctx, onComment, onChompKeep) : node.toString(ctx, onComment, onChompKeep);
|
|
25126
|
+
if (!props)
|
|
25127
|
+
return str;
|
|
25128
|
+
return isScalar(node) || str[0] === "{" || str[0] === "[" ? `${props} ${str}` : `${props}
|
|
25129
|
+
${ctx.indent}${str}`;
|
|
25130
|
+
}
|
|
25131
|
+
function stringifyPair({ key, value }, ctx, onComment, onChompKeep) {
|
|
25132
|
+
const { allNullValues, doc: doc2, indent, indentStep, options: { commentString, indentSeq, simpleKeys } } = ctx;
|
|
25133
|
+
let keyComment = isNode(key) && key.comment || null;
|
|
25134
|
+
if (simpleKeys) {
|
|
25135
|
+
if (keyComment) {
|
|
25136
|
+
throw new Error("With simple keys, key nodes cannot have comments");
|
|
25137
|
+
}
|
|
25138
|
+
if (isCollection(key)) {
|
|
25139
|
+
const msg = "With simple keys, collection cannot be used as a key value";
|
|
25140
|
+
throw new Error(msg);
|
|
25141
|
+
}
|
|
25142
|
+
}
|
|
25143
|
+
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"));
|
|
25144
|
+
ctx = Object.assign({}, ctx, {
|
|
25145
|
+
allNullValues: false,
|
|
25146
|
+
implicitKey: !explicitKey && (simpleKeys || !allNullValues),
|
|
25147
|
+
indent: indent + indentStep
|
|
25148
|
+
});
|
|
25149
|
+
let keyCommentDone = false;
|
|
25150
|
+
let chompKeep = false;
|
|
25151
|
+
let str = stringify(key, ctx, () => keyCommentDone = true, () => chompKeep = true);
|
|
25152
|
+
if (!explicitKey && !ctx.inFlow && str.length > 1024) {
|
|
25153
|
+
if (simpleKeys)
|
|
25154
|
+
throw new Error("With simple keys, single line scalar must not span more than 1024 characters");
|
|
25155
|
+
explicitKey = true;
|
|
25156
|
+
}
|
|
25157
|
+
if (ctx.inFlow) {
|
|
25158
|
+
if (allNullValues || value == null) {
|
|
25159
|
+
if (keyCommentDone && onComment)
|
|
25160
|
+
onComment();
|
|
25161
|
+
return str === "" ? "?" : explicitKey ? `? ${str}` : str;
|
|
25162
|
+
}
|
|
25163
|
+
} else if (allNullValues && !simpleKeys || value == null && explicitKey) {
|
|
25164
|
+
str = `? ${str}`;
|
|
25165
|
+
if (keyComment && !keyCommentDone) {
|
|
25166
|
+
str += lineComment(str, ctx.indent, commentString(keyComment));
|
|
25167
|
+
} else if (chompKeep && onChompKeep)
|
|
25168
|
+
onChompKeep();
|
|
25169
|
+
return str;
|
|
25170
|
+
}
|
|
25171
|
+
if (keyCommentDone)
|
|
25172
|
+
keyComment = null;
|
|
25173
|
+
if (explicitKey) {
|
|
25174
|
+
if (keyComment)
|
|
25175
|
+
str += lineComment(str, ctx.indent, commentString(keyComment));
|
|
25176
|
+
str = `? ${str}
|
|
25177
|
+
${indent}:`;
|
|
25178
|
+
} else {
|
|
25179
|
+
str = `${str}:`;
|
|
25180
|
+
if (keyComment)
|
|
25181
|
+
str += lineComment(str, ctx.indent, commentString(keyComment));
|
|
25182
|
+
}
|
|
25183
|
+
let vsb, vcb, valueComment;
|
|
25184
|
+
if (isNode(value)) {
|
|
25185
|
+
vsb = !!value.spaceBefore;
|
|
25186
|
+
vcb = value.commentBefore;
|
|
25187
|
+
valueComment = value.comment;
|
|
25188
|
+
} else {
|
|
25189
|
+
vsb = false;
|
|
25190
|
+
vcb = null;
|
|
25191
|
+
valueComment = null;
|
|
25192
|
+
if (value && typeof value === "object")
|
|
25193
|
+
value = doc2.createNode(value);
|
|
25194
|
+
}
|
|
25195
|
+
ctx.implicitKey = false;
|
|
25196
|
+
if (!explicitKey && !keyComment && isScalar(value))
|
|
25197
|
+
ctx.indentAtStart = str.length + 1;
|
|
25198
|
+
chompKeep = false;
|
|
25199
|
+
if (!indentSeq && indentStep.length >= 2 && !ctx.inFlow && !explicitKey && isSeq(value) && !value.flow && !value.tag && !value.anchor) {
|
|
25200
|
+
ctx.indent = ctx.indent.substring(2);
|
|
25201
|
+
}
|
|
25202
|
+
let valueCommentDone = false;
|
|
25203
|
+
const valueStr = stringify(value, ctx, () => valueCommentDone = true, () => chompKeep = true);
|
|
25204
|
+
let ws = " ";
|
|
25205
|
+
if (keyComment || vsb || vcb) {
|
|
25206
|
+
ws = vsb ? "\n" : "";
|
|
25207
|
+
if (vcb) {
|
|
25208
|
+
const cs = commentString(vcb);
|
|
25209
|
+
ws += `
|
|
25210
|
+
${indentComment(cs, ctx.indent)}`;
|
|
25211
|
+
}
|
|
25212
|
+
if (valueStr === "" && !ctx.inFlow) {
|
|
25213
|
+
if (ws === "\n")
|
|
25214
|
+
ws = "\n\n";
|
|
25215
|
+
} else {
|
|
25216
|
+
ws += `
|
|
25217
|
+
${ctx.indent}`;
|
|
25218
|
+
}
|
|
25219
|
+
} else if (!explicitKey && isCollection(value)) {
|
|
25220
|
+
const vs0 = valueStr[0];
|
|
25221
|
+
const nl0 = valueStr.indexOf("\n");
|
|
25222
|
+
const hasNewline = nl0 !== -1;
|
|
25223
|
+
const flow = ctx.inFlow ?? value.flow ?? value.items.length === 0;
|
|
25224
|
+
if (hasNewline || !flow) {
|
|
25225
|
+
let hasPropsLine = false;
|
|
25226
|
+
if (hasNewline && (vs0 === "&" || vs0 === "!")) {
|
|
25227
|
+
let sp0 = valueStr.indexOf(" ");
|
|
25228
|
+
if (vs0 === "&" && sp0 !== -1 && sp0 < nl0 && valueStr[sp0 + 1] === "!") {
|
|
25229
|
+
sp0 = valueStr.indexOf(" ", sp0 + 1);
|
|
25230
|
+
}
|
|
25231
|
+
if (sp0 === -1 || nl0 < sp0)
|
|
25232
|
+
hasPropsLine = true;
|
|
25233
|
+
}
|
|
25234
|
+
if (!hasPropsLine)
|
|
25235
|
+
ws = `
|
|
25236
|
+
${ctx.indent}`;
|
|
25237
|
+
}
|
|
25238
|
+
} else if (valueStr === "" || valueStr[0] === "\n") {
|
|
25239
|
+
ws = "";
|
|
25240
|
+
}
|
|
25241
|
+
str += ws + valueStr;
|
|
25242
|
+
if (ctx.inFlow) {
|
|
25243
|
+
if (valueCommentDone && onComment)
|
|
25244
|
+
onComment();
|
|
25245
|
+
} else if (valueComment && !valueCommentDone) {
|
|
25246
|
+
str += lineComment(str, ctx.indent, commentString(valueComment));
|
|
25247
|
+
} else if (chompKeep && onChompKeep) {
|
|
25248
|
+
onChompKeep();
|
|
25249
|
+
}
|
|
25250
|
+
return str;
|
|
25251
|
+
}
|
|
25252
|
+
function warn(logLevel, warning) {
|
|
25253
|
+
if (logLevel === "debug" || logLevel === "warn") {
|
|
25254
|
+
if (typeof process !== "undefined" && process.emitWarning)
|
|
25255
|
+
process.emitWarning(warning);
|
|
25256
|
+
else
|
|
25257
|
+
console.warn(warning);
|
|
25258
|
+
}
|
|
25259
|
+
}
|
|
25260
|
+
const MERGE_KEY = "<<";
|
|
25261
|
+
function addPairToJSMap(ctx, map, { key, value }) {
|
|
25262
|
+
if ((ctx == null ? void 0 : ctx.doc.schema.merge) && isMergeKey(key)) {
|
|
25263
|
+
value = isAlias(value) ? value.resolve(ctx.doc) : value;
|
|
25264
|
+
if (isSeq(value))
|
|
25265
|
+
for (const it of value.items)
|
|
25266
|
+
mergeToJSMap(ctx, map, it);
|
|
25267
|
+
else if (Array.isArray(value))
|
|
25268
|
+
for (const it of value)
|
|
25269
|
+
mergeToJSMap(ctx, map, it);
|
|
25270
|
+
else
|
|
25271
|
+
mergeToJSMap(ctx, map, value);
|
|
25272
|
+
} else {
|
|
25273
|
+
const jsKey = toJS(key, "", ctx);
|
|
25274
|
+
if (map instanceof Map) {
|
|
25275
|
+
map.set(jsKey, toJS(value, jsKey, ctx));
|
|
25276
|
+
} else if (map instanceof Set) {
|
|
25277
|
+
map.add(jsKey);
|
|
25278
|
+
} else {
|
|
25279
|
+
const stringKey = stringifyKey(key, jsKey, ctx);
|
|
25280
|
+
const jsValue = toJS(value, stringKey, ctx);
|
|
25281
|
+
if (stringKey in map)
|
|
25282
|
+
Object.defineProperty(map, stringKey, {
|
|
25283
|
+
value: jsValue,
|
|
25284
|
+
writable: true,
|
|
25285
|
+
enumerable: true,
|
|
25286
|
+
configurable: true
|
|
25287
|
+
});
|
|
25288
|
+
else
|
|
25289
|
+
map[stringKey] = jsValue;
|
|
25290
|
+
}
|
|
25291
|
+
}
|
|
25292
|
+
return map;
|
|
25293
|
+
}
|
|
25294
|
+
const isMergeKey = (key) => key === MERGE_KEY || isScalar(key) && key.value === MERGE_KEY && (!key.type || key.type === Scalar.PLAIN);
|
|
25295
|
+
function mergeToJSMap(ctx, map, value) {
|
|
25296
|
+
const source = ctx && isAlias(value) ? value.resolve(ctx.doc) : value;
|
|
25297
|
+
if (!isMap(source))
|
|
25298
|
+
throw new Error("Merge sources must be maps or map aliases");
|
|
25299
|
+
const srcMap = source.toJSON(null, ctx, Map);
|
|
25300
|
+
for (const [key, value2] of srcMap) {
|
|
25301
|
+
if (map instanceof Map) {
|
|
25302
|
+
if (!map.has(key))
|
|
25303
|
+
map.set(key, value2);
|
|
25304
|
+
} else if (map instanceof Set) {
|
|
25305
|
+
map.add(key);
|
|
25306
|
+
} else if (!Object.prototype.hasOwnProperty.call(map, key)) {
|
|
25307
|
+
Object.defineProperty(map, key, {
|
|
25308
|
+
value: value2,
|
|
25309
|
+
writable: true,
|
|
25310
|
+
enumerable: true,
|
|
25311
|
+
configurable: true
|
|
25312
|
+
});
|
|
25313
|
+
}
|
|
25314
|
+
}
|
|
25315
|
+
return map;
|
|
25316
|
+
}
|
|
25317
|
+
function stringifyKey(key, jsKey, ctx) {
|
|
25318
|
+
if (jsKey === null)
|
|
25319
|
+
return "";
|
|
25320
|
+
if (typeof jsKey !== "object")
|
|
25321
|
+
return String(jsKey);
|
|
25322
|
+
if (isNode(key) && (ctx == null ? void 0 : ctx.doc)) {
|
|
25323
|
+
const strCtx = createStringifyContext(ctx.doc, {});
|
|
25324
|
+
strCtx.anchors = /* @__PURE__ */ new Set();
|
|
25325
|
+
for (const node of ctx.anchors.keys())
|
|
25326
|
+
strCtx.anchors.add(node.anchor);
|
|
25327
|
+
strCtx.inFlow = true;
|
|
25328
|
+
strCtx.inStringifyKey = true;
|
|
25329
|
+
const strKey = key.toString(strCtx);
|
|
25330
|
+
if (!ctx.mapKeyWarned) {
|
|
25331
|
+
let jsonStr = JSON.stringify(strKey);
|
|
25332
|
+
if (jsonStr.length > 40)
|
|
25333
|
+
jsonStr = jsonStr.substring(0, 36) + '..."';
|
|
25334
|
+
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.`);
|
|
25335
|
+
ctx.mapKeyWarned = true;
|
|
25336
|
+
}
|
|
25337
|
+
return strKey;
|
|
25338
|
+
}
|
|
25339
|
+
return JSON.stringify(jsKey);
|
|
25340
|
+
}
|
|
25341
|
+
function createPair(key, value, ctx) {
|
|
25342
|
+
const k = createNode(key, void 0, ctx);
|
|
25343
|
+
const v = createNode(value, void 0, ctx);
|
|
25344
|
+
return new Pair(k, v);
|
|
25345
|
+
}
|
|
25346
|
+
class Pair {
|
|
25347
|
+
constructor(key, value = null) {
|
|
25348
|
+
Object.defineProperty(this, NODE_TYPE, { value: PAIR });
|
|
25349
|
+
this.key = key;
|
|
25350
|
+
this.value = value;
|
|
25351
|
+
}
|
|
25352
|
+
clone(schema) {
|
|
25353
|
+
let { key, value } = this;
|
|
25354
|
+
if (isNode(key))
|
|
25355
|
+
key = key.clone(schema);
|
|
25356
|
+
if (isNode(value))
|
|
25357
|
+
value = value.clone(schema);
|
|
25358
|
+
return new Pair(key, value);
|
|
25359
|
+
}
|
|
25360
|
+
toJSON(_, ctx) {
|
|
25361
|
+
const pair2 = (ctx == null ? void 0 : ctx.mapAsMap) ? /* @__PURE__ */ new Map() : {};
|
|
25362
|
+
return addPairToJSMap(ctx, pair2, this);
|
|
25363
|
+
}
|
|
25364
|
+
toString(ctx, onComment, onChompKeep) {
|
|
25365
|
+
return (ctx == null ? void 0 : ctx.doc) ? stringifyPair(this, ctx, onComment, onChompKeep) : JSON.stringify(this);
|
|
25366
|
+
}
|
|
25367
|
+
}
|
|
25368
|
+
function stringifyCollection(collection, ctx, options) {
|
|
25369
|
+
const flow = ctx.inFlow ?? collection.flow;
|
|
25370
|
+
const stringify2 = flow ? stringifyFlowCollection : stringifyBlockCollection;
|
|
25371
|
+
return stringify2(collection, ctx, options);
|
|
25372
|
+
}
|
|
25373
|
+
function stringifyBlockCollection({ comment: comment2, items }, ctx, { blockItemPrefix, flowChars, itemIndent, onChompKeep, onComment }) {
|
|
25374
|
+
const { indent, options: { commentString } } = ctx;
|
|
25375
|
+
const itemCtx = Object.assign({}, ctx, { indent: itemIndent, type: null });
|
|
25376
|
+
let chompKeep = false;
|
|
25377
|
+
const lines = [];
|
|
25378
|
+
for (let i = 0; i < items.length; ++i) {
|
|
25379
|
+
const item = items[i];
|
|
25380
|
+
let comment3 = null;
|
|
25381
|
+
if (isNode(item)) {
|
|
25382
|
+
if (!chompKeep && item.spaceBefore)
|
|
25383
|
+
lines.push("");
|
|
25384
|
+
addCommentBefore(ctx, lines, item.commentBefore, chompKeep);
|
|
25385
|
+
if (item.comment)
|
|
25386
|
+
comment3 = item.comment;
|
|
25387
|
+
} else if (isPair(item)) {
|
|
25388
|
+
const ik = isNode(item.key) ? item.key : null;
|
|
25389
|
+
if (ik) {
|
|
25390
|
+
if (!chompKeep && ik.spaceBefore)
|
|
25391
|
+
lines.push("");
|
|
25392
|
+
addCommentBefore(ctx, lines, ik.commentBefore, chompKeep);
|
|
25393
|
+
}
|
|
25394
|
+
}
|
|
25395
|
+
chompKeep = false;
|
|
25396
|
+
let str2 = stringify(item, itemCtx, () => comment3 = null, () => chompKeep = true);
|
|
25397
|
+
if (comment3)
|
|
25398
|
+
str2 += lineComment(str2, itemIndent, commentString(comment3));
|
|
25399
|
+
if (chompKeep && comment3)
|
|
25400
|
+
chompKeep = false;
|
|
25401
|
+
lines.push(blockItemPrefix + str2);
|
|
25402
|
+
}
|
|
25403
|
+
let str;
|
|
25404
|
+
if (lines.length === 0) {
|
|
25405
|
+
str = flowChars.start + flowChars.end;
|
|
25406
|
+
} else {
|
|
25407
|
+
str = lines[0];
|
|
25408
|
+
for (let i = 1; i < lines.length; ++i) {
|
|
25409
|
+
const line = lines[i];
|
|
25410
|
+
str += line ? `
|
|
25411
|
+
${indent}${line}` : "\n";
|
|
25412
|
+
}
|
|
25413
|
+
}
|
|
25414
|
+
if (comment2) {
|
|
25415
|
+
str += "\n" + indentComment(commentString(comment2), indent);
|
|
25416
|
+
if (onComment)
|
|
25417
|
+
onComment();
|
|
25418
|
+
} else if (chompKeep && onChompKeep)
|
|
25419
|
+
onChompKeep();
|
|
25420
|
+
return str;
|
|
25421
|
+
}
|
|
25422
|
+
function stringifyFlowCollection({ items }, ctx, { flowChars, itemIndent }) {
|
|
25423
|
+
const { indent, indentStep, flowCollectionPadding: fcPadding, options: { commentString } } = ctx;
|
|
25424
|
+
itemIndent += indentStep;
|
|
25425
|
+
const itemCtx = Object.assign({}, ctx, {
|
|
25426
|
+
indent: itemIndent,
|
|
25427
|
+
inFlow: true,
|
|
25428
|
+
type: null
|
|
25429
|
+
});
|
|
25430
|
+
let reqNewline = false;
|
|
25431
|
+
let linesAtValue = 0;
|
|
25432
|
+
const lines = [];
|
|
25433
|
+
for (let i = 0; i < items.length; ++i) {
|
|
25434
|
+
const item = items[i];
|
|
25435
|
+
let comment2 = null;
|
|
25436
|
+
if (isNode(item)) {
|
|
25437
|
+
if (item.spaceBefore)
|
|
25438
|
+
lines.push("");
|
|
25439
|
+
addCommentBefore(ctx, lines, item.commentBefore, false);
|
|
25440
|
+
if (item.comment)
|
|
25441
|
+
comment2 = item.comment;
|
|
25442
|
+
} else if (isPair(item)) {
|
|
25443
|
+
const ik = isNode(item.key) ? item.key : null;
|
|
25444
|
+
if (ik) {
|
|
25445
|
+
if (ik.spaceBefore)
|
|
25446
|
+
lines.push("");
|
|
25447
|
+
addCommentBefore(ctx, lines, ik.commentBefore, false);
|
|
25448
|
+
if (ik.comment)
|
|
25449
|
+
reqNewline = true;
|
|
25450
|
+
}
|
|
25451
|
+
const iv = isNode(item.value) ? item.value : null;
|
|
25452
|
+
if (iv) {
|
|
25453
|
+
if (iv.comment)
|
|
25454
|
+
comment2 = iv.comment;
|
|
25455
|
+
if (iv.commentBefore)
|
|
25456
|
+
reqNewline = true;
|
|
25457
|
+
} else if (item.value == null && (ik == null ? void 0 : ik.comment)) {
|
|
25458
|
+
comment2 = ik.comment;
|
|
25459
|
+
}
|
|
25460
|
+
}
|
|
25461
|
+
if (comment2)
|
|
25462
|
+
reqNewline = true;
|
|
25463
|
+
let str = stringify(item, itemCtx, () => comment2 = null);
|
|
25464
|
+
if (i < items.length - 1)
|
|
25465
|
+
str += ",";
|
|
25466
|
+
if (comment2)
|
|
25467
|
+
str += lineComment(str, itemIndent, commentString(comment2));
|
|
25468
|
+
if (!reqNewline && (lines.length > linesAtValue || str.includes("\n")))
|
|
25469
|
+
reqNewline = true;
|
|
25470
|
+
lines.push(str);
|
|
25471
|
+
linesAtValue = lines.length;
|
|
25472
|
+
}
|
|
25473
|
+
const { start, end } = flowChars;
|
|
25474
|
+
if (lines.length === 0) {
|
|
25475
|
+
return start + end;
|
|
25476
|
+
} else {
|
|
25477
|
+
if (!reqNewline) {
|
|
25478
|
+
const len = lines.reduce((sum, line) => sum + line.length + 2, 2);
|
|
25479
|
+
reqNewline = ctx.options.lineWidth > 0 && len > ctx.options.lineWidth;
|
|
25480
|
+
}
|
|
25481
|
+
if (reqNewline) {
|
|
25482
|
+
let str = start;
|
|
25483
|
+
for (const line of lines)
|
|
25484
|
+
str += line ? `
|
|
25485
|
+
${indentStep}${indent}${line}` : "\n";
|
|
25486
|
+
return `${str}
|
|
25487
|
+
${indent}${end}`;
|
|
25488
|
+
} else {
|
|
25489
|
+
return `${start}${fcPadding}${lines.join(" ")}${fcPadding}${end}`;
|
|
25490
|
+
}
|
|
25491
|
+
}
|
|
25492
|
+
}
|
|
25493
|
+
function addCommentBefore({ indent, options: { commentString } }, lines, comment2, chompKeep) {
|
|
25494
|
+
if (comment2 && chompKeep)
|
|
25495
|
+
comment2 = comment2.replace(/^\n+/, "");
|
|
25496
|
+
if (comment2) {
|
|
25497
|
+
const ic = indentComment(commentString(comment2), indent);
|
|
25498
|
+
lines.push(ic.trimStart());
|
|
25499
|
+
}
|
|
25500
|
+
}
|
|
25501
|
+
function findPair(items, key) {
|
|
25502
|
+
const k = isScalar(key) ? key.value : key;
|
|
25503
|
+
for (const it of items) {
|
|
25504
|
+
if (isPair(it)) {
|
|
25505
|
+
if (it.key === key || it.key === k)
|
|
25506
|
+
return it;
|
|
25507
|
+
if (isScalar(it.key) && it.key.value === k)
|
|
25508
|
+
return it;
|
|
25509
|
+
}
|
|
25510
|
+
}
|
|
25511
|
+
return void 0;
|
|
25512
|
+
}
|
|
25513
|
+
class YAMLMap extends Collection {
|
|
25514
|
+
static get tagName() {
|
|
25515
|
+
return "tag:yaml.org,2002:map";
|
|
25516
|
+
}
|
|
25517
|
+
constructor(schema) {
|
|
25518
|
+
super(MAP, schema);
|
|
25519
|
+
this.items = [];
|
|
25520
|
+
}
|
|
25521
|
+
/**
|
|
25522
|
+
* A generic collection parsing method that can be extended
|
|
25523
|
+
* to other node classes that inherit from YAMLMap
|
|
25524
|
+
*/
|
|
25525
|
+
static from(schema, obj, ctx) {
|
|
25526
|
+
const { keepUndefined, replacer } = ctx;
|
|
25527
|
+
const map = new this(schema);
|
|
25528
|
+
const add = (key, value) => {
|
|
25529
|
+
if (typeof replacer === "function")
|
|
25530
|
+
value = replacer.call(obj, key, value);
|
|
25531
|
+
else if (Array.isArray(replacer) && !replacer.includes(key))
|
|
25532
|
+
return;
|
|
25533
|
+
if (value !== void 0 || keepUndefined)
|
|
25534
|
+
map.items.push(createPair(key, value, ctx));
|
|
25535
|
+
};
|
|
25536
|
+
if (obj instanceof Map) {
|
|
25537
|
+
for (const [key, value] of obj)
|
|
25538
|
+
add(key, value);
|
|
25539
|
+
} else if (obj && typeof obj === "object") {
|
|
25540
|
+
for (const key of Object.keys(obj))
|
|
25541
|
+
add(key, obj[key]);
|
|
25542
|
+
}
|
|
25543
|
+
if (typeof schema.sortMapEntries === "function") {
|
|
25544
|
+
map.items.sort(schema.sortMapEntries);
|
|
25545
|
+
}
|
|
25546
|
+
return map;
|
|
25547
|
+
}
|
|
25548
|
+
/**
|
|
25549
|
+
* Adds a value to the collection.
|
|
25550
|
+
*
|
|
25551
|
+
* @param overwrite - If not set `true`, using a key that is already in the
|
|
25552
|
+
* collection will throw. Otherwise, overwrites the previous value.
|
|
25553
|
+
*/
|
|
25554
|
+
add(pair2, overwrite) {
|
|
25555
|
+
var _a2;
|
|
25556
|
+
let _pair;
|
|
25557
|
+
if (isPair(pair2))
|
|
25558
|
+
_pair = pair2;
|
|
25559
|
+
else if (!pair2 || typeof pair2 !== "object" || !("key" in pair2)) {
|
|
25560
|
+
_pair = new Pair(pair2, pair2 == null ? void 0 : pair2.value);
|
|
25561
|
+
} else
|
|
25562
|
+
_pair = new Pair(pair2.key, pair2.value);
|
|
25563
|
+
const prev = findPair(this.items, _pair.key);
|
|
25564
|
+
const sortEntries = (_a2 = this.schema) == null ? void 0 : _a2.sortMapEntries;
|
|
25565
|
+
if (prev) {
|
|
25566
|
+
if (!overwrite)
|
|
25567
|
+
throw new Error(`Key ${_pair.key} already set`);
|
|
25568
|
+
if (isScalar(prev.value) && isScalarValue(_pair.value))
|
|
25569
|
+
prev.value.value = _pair.value;
|
|
25570
|
+
else
|
|
25571
|
+
prev.value = _pair.value;
|
|
25572
|
+
} else if (sortEntries) {
|
|
25573
|
+
const i = this.items.findIndex((item) => sortEntries(_pair, item) < 0);
|
|
25574
|
+
if (i === -1)
|
|
25575
|
+
this.items.push(_pair);
|
|
25576
|
+
else
|
|
25577
|
+
this.items.splice(i, 0, _pair);
|
|
25578
|
+
} else {
|
|
25579
|
+
this.items.push(_pair);
|
|
25580
|
+
}
|
|
25581
|
+
}
|
|
25582
|
+
delete(key) {
|
|
25583
|
+
const it = findPair(this.items, key);
|
|
25584
|
+
if (!it)
|
|
25585
|
+
return false;
|
|
25586
|
+
const del = this.items.splice(this.items.indexOf(it), 1);
|
|
25587
|
+
return del.length > 0;
|
|
25588
|
+
}
|
|
25589
|
+
get(key, keepScalar) {
|
|
25590
|
+
const it = findPair(this.items, key);
|
|
25591
|
+
const node = it == null ? void 0 : it.value;
|
|
25592
|
+
return (!keepScalar && isScalar(node) ? node.value : node) ?? void 0;
|
|
25593
|
+
}
|
|
25594
|
+
has(key) {
|
|
25595
|
+
return !!findPair(this.items, key);
|
|
25596
|
+
}
|
|
25597
|
+
set(key, value) {
|
|
25598
|
+
this.add(new Pair(key, value), true);
|
|
25599
|
+
}
|
|
25600
|
+
/**
|
|
25601
|
+
* @param ctx - Conversion context, originally set in Document#toJS()
|
|
25602
|
+
* @param {Class} Type - If set, forces the returned collection type
|
|
25603
|
+
* @returns Instance of Type, Map, or Object
|
|
25604
|
+
*/
|
|
25605
|
+
toJSON(_, ctx, Type) {
|
|
25606
|
+
const map = Type ? new Type() : (ctx == null ? void 0 : ctx.mapAsMap) ? /* @__PURE__ */ new Map() : {};
|
|
25607
|
+
if (ctx == null ? void 0 : ctx.onCreate)
|
|
25608
|
+
ctx.onCreate(map);
|
|
25609
|
+
for (const item of this.items)
|
|
25610
|
+
addPairToJSMap(ctx, map, item);
|
|
25611
|
+
return map;
|
|
25612
|
+
}
|
|
25613
|
+
toString(ctx, onComment, onChompKeep) {
|
|
25614
|
+
if (!ctx)
|
|
25615
|
+
return JSON.stringify(this);
|
|
25616
|
+
for (const item of this.items) {
|
|
25617
|
+
if (!isPair(item))
|
|
25618
|
+
throw new Error(`Map items must all be pairs; found ${JSON.stringify(item)} instead`);
|
|
25619
|
+
}
|
|
25620
|
+
if (!ctx.allNullValues && this.hasAllNullValues(false))
|
|
25621
|
+
ctx = Object.assign({}, ctx, { allNullValues: true });
|
|
25622
|
+
return stringifyCollection(this, ctx, {
|
|
25623
|
+
blockItemPrefix: "",
|
|
25624
|
+
flowChars: { start: "{", end: "}" },
|
|
25625
|
+
itemIndent: ctx.indent || "",
|
|
25626
|
+
onChompKeep,
|
|
25627
|
+
onComment
|
|
25628
|
+
});
|
|
25629
|
+
}
|
|
25630
|
+
}
|
|
25631
|
+
class YAMLSeq extends Collection {
|
|
25632
|
+
static get tagName() {
|
|
25633
|
+
return "tag:yaml.org,2002:seq";
|
|
25634
|
+
}
|
|
25635
|
+
constructor(schema) {
|
|
25636
|
+
super(SEQ, schema);
|
|
25637
|
+
this.items = [];
|
|
25638
|
+
}
|
|
25639
|
+
add(value) {
|
|
25640
|
+
this.items.push(value);
|
|
25641
|
+
}
|
|
25642
|
+
/**
|
|
25643
|
+
* Removes a value from the collection.
|
|
25644
|
+
*
|
|
25645
|
+
* `key` must contain a representation of an integer for this to succeed.
|
|
25646
|
+
* It may be wrapped in a `Scalar`.
|
|
25647
|
+
*
|
|
25648
|
+
* @returns `true` if the item was found and removed.
|
|
25649
|
+
*/
|
|
25650
|
+
delete(key) {
|
|
25651
|
+
const idx = asItemIndex(key);
|
|
25652
|
+
if (typeof idx !== "number")
|
|
25653
|
+
return false;
|
|
25654
|
+
const del = this.items.splice(idx, 1);
|
|
25655
|
+
return del.length > 0;
|
|
25656
|
+
}
|
|
25657
|
+
get(key, keepScalar) {
|
|
25658
|
+
const idx = asItemIndex(key);
|
|
25659
|
+
if (typeof idx !== "number")
|
|
25660
|
+
return void 0;
|
|
25661
|
+
const it = this.items[idx];
|
|
25662
|
+
return !keepScalar && isScalar(it) ? it.value : it;
|
|
25663
|
+
}
|
|
25664
|
+
/**
|
|
25665
|
+
* Checks if the collection includes a value with the key `key`.
|
|
25666
|
+
*
|
|
25667
|
+
* `key` must contain a representation of an integer for this to succeed.
|
|
25668
|
+
* It may be wrapped in a `Scalar`.
|
|
25669
|
+
*/
|
|
25670
|
+
has(key) {
|
|
25671
|
+
const idx = asItemIndex(key);
|
|
25672
|
+
return typeof idx === "number" && idx < this.items.length;
|
|
25673
|
+
}
|
|
25674
|
+
/**
|
|
25675
|
+
* Sets a value in this collection. For `!!set`, `value` needs to be a
|
|
25676
|
+
* boolean to add/remove the item from the set.
|
|
25677
|
+
*
|
|
25678
|
+
* If `key` does not contain a representation of an integer, this will throw.
|
|
25679
|
+
* It may be wrapped in a `Scalar`.
|
|
25680
|
+
*/
|
|
25681
|
+
set(key, value) {
|
|
25682
|
+
const idx = asItemIndex(key);
|
|
25683
|
+
if (typeof idx !== "number")
|
|
25684
|
+
throw new Error(`Expected a valid index, not ${key}.`);
|
|
25685
|
+
const prev = this.items[idx];
|
|
25686
|
+
if (isScalar(prev) && isScalarValue(value))
|
|
25687
|
+
prev.value = value;
|
|
25688
|
+
else
|
|
25689
|
+
this.items[idx] = value;
|
|
25690
|
+
}
|
|
25691
|
+
toJSON(_, ctx) {
|
|
25692
|
+
const seq = [];
|
|
25693
|
+
if (ctx == null ? void 0 : ctx.onCreate)
|
|
25694
|
+
ctx.onCreate(seq);
|
|
25695
|
+
let i = 0;
|
|
25696
|
+
for (const item of this.items)
|
|
25697
|
+
seq.push(toJS(item, String(i++), ctx));
|
|
25698
|
+
return seq;
|
|
25699
|
+
}
|
|
25700
|
+
toString(ctx, onComment, onChompKeep) {
|
|
25701
|
+
if (!ctx)
|
|
25702
|
+
return JSON.stringify(this);
|
|
25703
|
+
return stringifyCollection(this, ctx, {
|
|
25704
|
+
blockItemPrefix: "- ",
|
|
25705
|
+
flowChars: { start: "[", end: "]" },
|
|
25706
|
+
itemIndent: (ctx.indent || "") + " ",
|
|
25707
|
+
onChompKeep,
|
|
25708
|
+
onComment
|
|
25709
|
+
});
|
|
25710
|
+
}
|
|
25711
|
+
static from(schema, obj, ctx) {
|
|
25712
|
+
const { replacer } = ctx;
|
|
25713
|
+
const seq = new this(schema);
|
|
25714
|
+
if (obj && Symbol.iterator in Object(obj)) {
|
|
25715
|
+
let i = 0;
|
|
25716
|
+
for (let it of obj) {
|
|
25717
|
+
if (typeof replacer === "function") {
|
|
25718
|
+
const key = obj instanceof Set ? it : String(i++);
|
|
25719
|
+
it = replacer.call(obj, key, it);
|
|
25720
|
+
}
|
|
25721
|
+
seq.items.push(createNode(it, void 0, ctx));
|
|
25722
|
+
}
|
|
25723
|
+
}
|
|
25724
|
+
return seq;
|
|
25725
|
+
}
|
|
25726
|
+
}
|
|
25727
|
+
function asItemIndex(key) {
|
|
25728
|
+
let idx = isScalar(key) ? key.value : key;
|
|
25729
|
+
if (idx && typeof idx === "string")
|
|
25730
|
+
idx = Number(idx);
|
|
25731
|
+
return typeof idx === "number" && Number.isInteger(idx) && idx >= 0 ? idx : null;
|
|
25732
|
+
}
|
|
25733
|
+
function createPairs(schema, iterable, ctx) {
|
|
25734
|
+
const { replacer } = ctx;
|
|
25735
|
+
const pairs = new YAMLSeq(schema);
|
|
25736
|
+
pairs.tag = "tag:yaml.org,2002:pairs";
|
|
25737
|
+
let i = 0;
|
|
25738
|
+
if (iterable && Symbol.iterator in Object(iterable))
|
|
25739
|
+
for (let it of iterable) {
|
|
25740
|
+
if (typeof replacer === "function")
|
|
25741
|
+
it = replacer.call(iterable, String(i++), it);
|
|
25742
|
+
let key, value;
|
|
25743
|
+
if (Array.isArray(it)) {
|
|
25744
|
+
if (it.length === 2) {
|
|
25745
|
+
key = it[0];
|
|
25746
|
+
value = it[1];
|
|
25747
|
+
} else
|
|
25748
|
+
throw new TypeError(`Expected [key, value] tuple: ${it}`);
|
|
25749
|
+
} else if (it && it instanceof Object) {
|
|
25750
|
+
const keys = Object.keys(it);
|
|
25751
|
+
if (keys.length === 1) {
|
|
25752
|
+
key = keys[0];
|
|
25753
|
+
value = it[key];
|
|
25754
|
+
} else {
|
|
25755
|
+
throw new TypeError(`Expected tuple with one key, not ${keys.length} keys`);
|
|
25756
|
+
}
|
|
25757
|
+
} else {
|
|
25758
|
+
key = it;
|
|
25759
|
+
}
|
|
25760
|
+
pairs.items.push(createPair(key, value, ctx));
|
|
25761
|
+
}
|
|
25762
|
+
return pairs;
|
|
25763
|
+
}
|
|
25764
|
+
class YAMLOMap extends YAMLSeq {
|
|
25765
|
+
constructor() {
|
|
25766
|
+
super();
|
|
25767
|
+
this.add = YAMLMap.prototype.add.bind(this);
|
|
25768
|
+
this.delete = YAMLMap.prototype.delete.bind(this);
|
|
25769
|
+
this.get = YAMLMap.prototype.get.bind(this);
|
|
25770
|
+
this.has = YAMLMap.prototype.has.bind(this);
|
|
25771
|
+
this.set = YAMLMap.prototype.set.bind(this);
|
|
25772
|
+
this.tag = YAMLOMap.tag;
|
|
25773
|
+
}
|
|
25774
|
+
/**
|
|
25775
|
+
* If `ctx` is given, the return type is actually `Map<unknown, unknown>`,
|
|
25776
|
+
* but TypeScript won't allow widening the signature of a child method.
|
|
25777
|
+
*/
|
|
25778
|
+
toJSON(_, ctx) {
|
|
25779
|
+
if (!ctx)
|
|
25780
|
+
return super.toJSON(_);
|
|
25781
|
+
const map = /* @__PURE__ */ new Map();
|
|
25782
|
+
if (ctx == null ? void 0 : ctx.onCreate)
|
|
25783
|
+
ctx.onCreate(map);
|
|
25784
|
+
for (const pair2 of this.items) {
|
|
25785
|
+
let key, value;
|
|
25786
|
+
if (isPair(pair2)) {
|
|
25787
|
+
key = toJS(pair2.key, "", ctx);
|
|
25788
|
+
value = toJS(pair2.value, key, ctx);
|
|
25789
|
+
} else {
|
|
25790
|
+
key = toJS(pair2, "", ctx);
|
|
25791
|
+
}
|
|
25792
|
+
if (map.has(key))
|
|
25793
|
+
throw new Error("Ordered maps must not include duplicate keys");
|
|
25794
|
+
map.set(key, value);
|
|
25795
|
+
}
|
|
25796
|
+
return map;
|
|
25797
|
+
}
|
|
25798
|
+
static from(schema, iterable, ctx) {
|
|
25799
|
+
const pairs = createPairs(schema, iterable, ctx);
|
|
25800
|
+
const omap = new this();
|
|
25801
|
+
omap.items = pairs.items;
|
|
25802
|
+
return omap;
|
|
25803
|
+
}
|
|
25804
|
+
}
|
|
25805
|
+
YAMLOMap.tag = "tag:yaml.org,2002:omap";
|
|
25806
|
+
class YAMLSet extends YAMLMap {
|
|
25807
|
+
constructor(schema) {
|
|
25808
|
+
super(schema);
|
|
25809
|
+
this.tag = YAMLSet.tag;
|
|
25810
|
+
}
|
|
25811
|
+
add(key) {
|
|
25812
|
+
let pair2;
|
|
25813
|
+
if (isPair(key))
|
|
25814
|
+
pair2 = key;
|
|
25815
|
+
else if (key && typeof key === "object" && "key" in key && "value" in key && key.value === null)
|
|
25816
|
+
pair2 = new Pair(key.key, null);
|
|
25817
|
+
else
|
|
25818
|
+
pair2 = new Pair(key, null);
|
|
25819
|
+
const prev = findPair(this.items, pair2.key);
|
|
25820
|
+
if (!prev)
|
|
25821
|
+
this.items.push(pair2);
|
|
25822
|
+
}
|
|
25823
|
+
/**
|
|
25824
|
+
* If `keepPair` is `true`, returns the Pair matching `key`.
|
|
25825
|
+
* Otherwise, returns the value of that Pair's key.
|
|
25826
|
+
*/
|
|
25827
|
+
get(key, keepPair) {
|
|
25828
|
+
const pair2 = findPair(this.items, key);
|
|
25829
|
+
return !keepPair && isPair(pair2) ? isScalar(pair2.key) ? pair2.key.value : pair2.key : pair2;
|
|
25830
|
+
}
|
|
25831
|
+
set(key, value) {
|
|
25832
|
+
if (typeof value !== "boolean")
|
|
25833
|
+
throw new Error(`Expected boolean value for set(key, value) in a YAML set, not ${typeof value}`);
|
|
25834
|
+
const prev = findPair(this.items, key);
|
|
25835
|
+
if (prev && !value) {
|
|
25836
|
+
this.items.splice(this.items.indexOf(prev), 1);
|
|
25837
|
+
} else if (!prev && value) {
|
|
25838
|
+
this.items.push(new Pair(key));
|
|
25839
|
+
}
|
|
25840
|
+
}
|
|
25841
|
+
toJSON(_, ctx) {
|
|
25842
|
+
return super.toJSON(_, ctx, Set);
|
|
25843
|
+
}
|
|
25844
|
+
toString(ctx, onComment, onChompKeep) {
|
|
25845
|
+
if (!ctx)
|
|
25846
|
+
return JSON.stringify(this);
|
|
25847
|
+
if (this.hasAllNullValues(true))
|
|
25848
|
+
return super.toString(Object.assign({}, ctx, { allNullValues: true }), onComment, onChompKeep);
|
|
25849
|
+
else
|
|
25850
|
+
throw new Error("Set items must all have null values");
|
|
25851
|
+
}
|
|
25852
|
+
static from(schema, iterable, ctx) {
|
|
25853
|
+
const { replacer } = ctx;
|
|
25854
|
+
const set = new this(schema);
|
|
25855
|
+
if (iterable && Symbol.iterator in Object(iterable))
|
|
25856
|
+
for (let value of iterable) {
|
|
25857
|
+
if (typeof replacer === "function")
|
|
25858
|
+
value = replacer.call(iterable, value, value);
|
|
25859
|
+
set.items.push(createPair(value, null, ctx));
|
|
25860
|
+
}
|
|
25861
|
+
return set;
|
|
25862
|
+
}
|
|
25863
|
+
}
|
|
25864
|
+
YAMLSet.tag = "tag:yaml.org,2002:set";
|
|
25865
|
+
const json = {
|
|
25866
|
+
/** Parse and throw if the return value is not an object */
|
|
25867
|
+
parse: (val) => {
|
|
25868
|
+
const jsonObject = JSON.parse(val);
|
|
25869
|
+
if (typeof jsonObject !== "object")
|
|
25870
|
+
throw Error("Invalid JSON object");
|
|
25871
|
+
return jsonObject;
|
|
25872
|
+
},
|
|
25873
|
+
/** Parse and return a fallback on failure */
|
|
25874
|
+
parseSafe(val, fallback) {
|
|
25875
|
+
try {
|
|
25876
|
+
return json.parse(val);
|
|
25877
|
+
} catch (err) {
|
|
25878
|
+
return typeof fallback === "function" ? fallback(err) : fallback;
|
|
25879
|
+
}
|
|
25880
|
+
},
|
|
25881
|
+
stringify: (val) => JSON.stringify(val)
|
|
25882
|
+
};
|
|
25883
|
+
const isJsonString = (value) => {
|
|
25884
|
+
if (typeof value !== "string")
|
|
25885
|
+
return false;
|
|
25886
|
+
return !!json.parseSafe(value, false);
|
|
25887
|
+
};
|
|
24090
25888
|
const prepareClientRequestConfig = (configuration) => {
|
|
24091
25889
|
var _a2;
|
|
24092
25890
|
const { authState: authState2, request } = configuration;
|
|
@@ -28248,20 +30046,20 @@ var prism = { exports: {} };
|
|
|
28248
30046
|
this.alias = alias;
|
|
28249
30047
|
this.length = (matchedStr || "").length | 0;
|
|
28250
30048
|
}
|
|
28251
|
-
Token.stringify = function
|
|
30049
|
+
Token.stringify = function stringify2(o, language2) {
|
|
28252
30050
|
if (typeof o == "string") {
|
|
28253
30051
|
return o;
|
|
28254
30052
|
}
|
|
28255
30053
|
if (Array.isArray(o)) {
|
|
28256
30054
|
var s = "";
|
|
28257
30055
|
o.forEach(function(e) {
|
|
28258
|
-
s +=
|
|
30056
|
+
s += stringify2(e, language2);
|
|
28259
30057
|
});
|
|
28260
30058
|
return s;
|
|
28261
30059
|
}
|
|
28262
30060
|
var env = {
|
|
28263
30061
|
type: o.type,
|
|
28264
|
-
content:
|
|
30062
|
+
content: stringify2(o.content, language2),
|
|
28265
30063
|
tag: "span",
|
|
28266
30064
|
classes: ["token", o.type],
|
|
28267
30065
|
attributes: {},
|
|
@@ -30595,7 +32393,7 @@ const _sfc_main$9 = /* @__PURE__ */ defineComponent({
|
|
|
30595
32393
|
}
|
|
30596
32394
|
});
|
|
30597
32395
|
const codeMirrorLanguage = computed(() => {
|
|
30598
|
-
if (mediaType.value === "application/json" || mediaType.value === "application/problem+json") {
|
|
32396
|
+
if (mediaType.value === "application/json" || mediaType.value === "application/problem+json" || mediaType.value === "application/vnd.api+json") {
|
|
30599
32397
|
return "json";
|
|
30600
32398
|
}
|
|
30601
32399
|
if (mediaType.value === "text/html") {
|
|
@@ -31042,7 +32840,6 @@ export {
|
|
|
31042
32840
|
httpHeaders,
|
|
31043
32841
|
httpStatusCodes,
|
|
31044
32842
|
humanDiff,
|
|
31045
|
-
isJsonString,
|
|
31046
32843
|
isRequestMethod,
|
|
31047
32844
|
mapFromArray,
|
|
31048
32845
|
normalizePath,
|