json-schema-faker
Version:
JSON-Schema + fake data generators
1,613 lines (1,602 loc) • 203 kB
JavaScript
var __create = Object.create;
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __getProtoOf = Object.getPrototypeOf;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __commonJS = (cb, mod) => function __require() {
return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
};
var __copyProps = (to, from, except, desc) => {
if (from && typeof from === "object" || typeof from === "function") {
for (let key of __getOwnPropNames(from))
if (!__hasOwnProp.call(to, key) && key !== except)
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
}
return to;
};
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
// If the importer is in node compatibility mode or this is not an ESM
// file that has been converted to a CommonJS file using a Babel-
// compatible transform (i.e. "__esModule" has not been set), then set
// "default" to the CommonJS "module.exports" for node compatibility.
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
mod
));
// node_modules/ret/lib/types.js
var require_types = __commonJS({
"node_modules/ret/lib/types.js"(exports, module) {
module.exports = {
ROOT: 0,
GROUP: 1,
POSITION: 2,
SET: 3,
RANGE: 4,
REPETITION: 5,
REFERENCE: 6,
CHAR: 7
};
}
});
// node_modules/ret/lib/sets.js
var require_sets = __commonJS({
"node_modules/ret/lib/sets.js"(exports) {
var types2 = require_types();
var INTS = () => [{ type: types2.RANGE, from: 48, to: 57 }];
var WORDS = () => {
return [
{ type: types2.CHAR, value: 95 },
{ type: types2.RANGE, from: 97, to: 122 },
{ type: types2.RANGE, from: 65, to: 90 }
].concat(INTS());
};
var WHITESPACE = () => {
return [
{ type: types2.CHAR, value: 9 },
{ type: types2.CHAR, value: 10 },
{ type: types2.CHAR, value: 11 },
{ type: types2.CHAR, value: 12 },
{ type: types2.CHAR, value: 13 },
{ type: types2.CHAR, value: 32 },
{ type: types2.CHAR, value: 160 },
{ type: types2.CHAR, value: 5760 },
{ type: types2.RANGE, from: 8192, to: 8202 },
{ type: types2.CHAR, value: 8232 },
{ type: types2.CHAR, value: 8233 },
{ type: types2.CHAR, value: 8239 },
{ type: types2.CHAR, value: 8287 },
{ type: types2.CHAR, value: 12288 },
{ type: types2.CHAR, value: 65279 }
];
};
var NOTANYCHAR = () => {
return [
{ type: types2.CHAR, value: 10 },
{ type: types2.CHAR, value: 13 },
{ type: types2.CHAR, value: 8232 },
{ type: types2.CHAR, value: 8233 }
];
};
exports.words = () => ({ type: types2.SET, set: WORDS(), not: false });
exports.notWords = () => ({ type: types2.SET, set: WORDS(), not: true });
exports.ints = () => ({ type: types2.SET, set: INTS(), not: false });
exports.notInts = () => ({ type: types2.SET, set: INTS(), not: true });
exports.whitespace = () => ({ type: types2.SET, set: WHITESPACE(), not: false });
exports.notWhitespace = () => ({ type: types2.SET, set: WHITESPACE(), not: true });
exports.anyChar = () => ({ type: types2.SET, set: NOTANYCHAR(), not: true });
}
});
// node_modules/ret/lib/util.js
var require_util = __commonJS({
"node_modules/ret/lib/util.js"(exports) {
var types2 = require_types();
var sets = require_sets();
var CTRL = "@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^ ?";
var SLSH = { "0": 0, "t": 9, "n": 10, "v": 11, "f": 12, "r": 13 };
exports.strToChars = function(str) {
var chars_regex = /(\[\\b\])|(\\)?\\(?:u([A-F0-9]{4})|x([A-F0-9]{2})|(0?[0-7]{2})|c([@A-Z[\\\]^?])|([0tnvfr]))/g;
str = str.replace(chars_regex, function(s, b, lbs, a16, b16, c8, dctrl, eslsh) {
if (lbs) {
return s;
}
var code = b ? 8 : a16 ? parseInt(a16, 16) : b16 ? parseInt(b16, 16) : c8 ? parseInt(c8, 8) : dctrl ? CTRL.indexOf(dctrl) : SLSH[eslsh];
var c = String.fromCharCode(code);
if (/[[\]{}^$.|?*+()]/.test(c)) {
c = "\\" + c;
}
return c;
});
return str;
};
exports.tokenizeClass = (str, regexpStr) => {
var tokens = [];
var regexp = /\\(?:(w)|(d)|(s)|(W)|(D)|(S))|((?:(?:\\)(.)|([^\]\\]))-(?:\\)?([^\]]))|(\])|(?:\\)?([^])/g;
var rs, c;
while ((rs = regexp.exec(str)) != null) {
if (rs[1]) {
tokens.push(sets.words());
} else if (rs[2]) {
tokens.push(sets.ints());
} else if (rs[3]) {
tokens.push(sets.whitespace());
} else if (rs[4]) {
tokens.push(sets.notWords());
} else if (rs[5]) {
tokens.push(sets.notInts());
} else if (rs[6]) {
tokens.push(sets.notWhitespace());
} else if (rs[7]) {
tokens.push({
type: types2.RANGE,
from: (rs[8] || rs[9]).charCodeAt(0),
to: rs[10].charCodeAt(0)
});
} else if (c = rs[12]) {
tokens.push({
type: types2.CHAR,
value: c.charCodeAt(0)
});
} else {
return [tokens, regexp.lastIndex];
}
}
exports.error(regexpStr, "Unterminated character class");
};
exports.error = (regexp, msg) => {
throw new SyntaxError("Invalid regular expression: /" + regexp + "/: " + msg);
};
}
});
// node_modules/ret/lib/positions.js
var require_positions = __commonJS({
"node_modules/ret/lib/positions.js"(exports) {
var types2 = require_types();
exports.wordBoundary = () => ({ type: types2.POSITION, value: "b" });
exports.nonWordBoundary = () => ({ type: types2.POSITION, value: "B" });
exports.begin = () => ({ type: types2.POSITION, value: "^" });
exports.end = () => ({ type: types2.POSITION, value: "$" });
}
});
// node_modules/ret/lib/index.js
var require_lib = __commonJS({
"node_modules/ret/lib/index.js"(exports, module) {
var util = require_util();
var types2 = require_types();
var sets = require_sets();
var positions = require_positions();
module.exports = (regexpStr) => {
var i = 0, l, c, start = { type: types2.ROOT, stack: [] }, lastGroup = start, last = start.stack, groupStack = [];
var repeatErr = (i2) => {
util.error(regexpStr, `Nothing to repeat at column ${i2 - 1}`);
};
var str = util.strToChars(regexpStr);
l = str.length;
while (i < l) {
c = str[i++];
switch (c) {
case "\\":
c = str[i++];
switch (c) {
case "b":
last.push(positions.wordBoundary());
break;
case "B":
last.push(positions.nonWordBoundary());
break;
case "w":
last.push(sets.words());
break;
case "W":
last.push(sets.notWords());
break;
case "d":
last.push(sets.ints());
break;
case "D":
last.push(sets.notInts());
break;
case "s":
last.push(sets.whitespace());
break;
case "S":
last.push(sets.notWhitespace());
break;
default:
if (/\d/.test(c)) {
last.push({ type: types2.REFERENCE, value: parseInt(c, 10) });
} else {
last.push({ type: types2.CHAR, value: c.charCodeAt(0) });
}
}
break;
case "^":
last.push(positions.begin());
break;
case "$":
last.push(positions.end());
break;
case "[":
var not;
if (str[i] === "^") {
not = true;
i++;
} else {
not = false;
}
var classTokens = util.tokenizeClass(str.slice(i), regexpStr);
i += classTokens[1];
last.push({
type: types2.SET,
set: classTokens[0],
not
});
break;
case ".":
last.push(sets.anyChar());
break;
case "(":
var group = {
type: types2.GROUP,
stack: [],
remember: true
};
c = str[i];
if (c === "?") {
c = str[i + 1];
i += 2;
if (c === "=") {
group.followedBy = true;
} else if (c === "!") {
group.notFollowedBy = true;
} else if (c !== ":") {
util.error(
regexpStr,
`Invalid group, character '${c}' after '?' at column ${i - 1}`
);
}
group.remember = false;
}
last.push(group);
groupStack.push(lastGroup);
lastGroup = group;
last = group.stack;
break;
case ")":
if (groupStack.length === 0) {
util.error(regexpStr, `Unmatched ) at column ${i - 1}`);
}
lastGroup = groupStack.pop();
last = lastGroup.options ? lastGroup.options[lastGroup.options.length - 1] : lastGroup.stack;
break;
case "|":
if (!lastGroup.options) {
lastGroup.options = [lastGroup.stack];
delete lastGroup.stack;
}
var stack = [];
lastGroup.options.push(stack);
last = stack;
break;
case "{":
var rs = /^(\d+)(,(\d+)?)?\}/.exec(str.slice(i)), min, max;
if (rs !== null) {
if (last.length === 0) {
repeatErr(i);
}
min = parseInt(rs[1], 10);
max = rs[2] ? rs[3] ? parseInt(rs[3], 10) : Infinity : min;
i += rs[0].length;
last.push({
type: types2.REPETITION,
min,
max,
value: last.pop()
});
} else {
last.push({
type: types2.CHAR,
value: 123
});
}
break;
case "?":
if (last.length === 0) {
repeatErr(i);
}
last.push({
type: types2.REPETITION,
min: 0,
max: 1,
value: last.pop()
});
break;
case "+":
if (last.length === 0) {
repeatErr(i);
}
last.push({
type: types2.REPETITION,
min: 1,
max: Infinity,
value: last.pop()
});
break;
case "*":
if (last.length === 0) {
repeatErr(i);
}
last.push({
type: types2.REPETITION,
min: 0,
max: Infinity,
value: last.pop()
});
break;
default:
last.push({
type: types2.CHAR,
value: c.charCodeAt(0)
});
}
}
if (groupStack.length !== 0) {
util.error(regexpStr, "Unterminated group");
}
return start;
};
module.exports.types = types2;
}
});
// node_modules/drange/lib/index.js
var require_lib2 = __commonJS({
"node_modules/drange/lib/index.js"(exports, module) {
"use strict";
var SubRange = class _SubRange {
constructor(low, high) {
this.low = low;
this.high = high;
this.length = 1 + high - low;
}
overlaps(range) {
return !(this.high < range.low || this.low > range.high);
}
touches(range) {
return !(this.high + 1 < range.low || this.low - 1 > range.high);
}
// Returns inclusive combination of SubRanges as a SubRange.
add(range) {
return new _SubRange(
Math.min(this.low, range.low),
Math.max(this.high, range.high)
);
}
// Returns subtraction of SubRanges as an array of SubRanges.
// (There's a case where subtraction divides it in 2)
subtract(range) {
if (range.low <= this.low && range.high >= this.high) {
return [];
} else if (range.low > this.low && range.high < this.high) {
return [
new _SubRange(this.low, range.low - 1),
new _SubRange(range.high + 1, this.high)
];
} else if (range.low <= this.low) {
return [new _SubRange(range.high + 1, this.high)];
} else {
return [new _SubRange(this.low, range.low - 1)];
}
}
toString() {
return this.low == this.high ? this.low.toString() : this.low + "-" + this.high;
}
};
var DRange = class _DRange {
constructor(a, b) {
this.ranges = [];
this.length = 0;
if (a != null)
this.add(a, b);
}
_update_length() {
this.length = this.ranges.reduce((previous, range) => {
return previous + range.length;
}, 0);
}
add(a, b) {
var _add = (subrange) => {
var i = 0;
while (i < this.ranges.length && !subrange.touches(this.ranges[i])) {
i++;
}
var newRanges = this.ranges.slice(0, i);
while (i < this.ranges.length && subrange.touches(this.ranges[i])) {
subrange = subrange.add(this.ranges[i]);
i++;
}
newRanges.push(subrange);
this.ranges = newRanges.concat(this.ranges.slice(i));
this._update_length();
};
if (a instanceof _DRange) {
a.ranges.forEach(_add);
} else {
if (b == null)
b = a;
_add(new SubRange(a, b));
}
return this;
}
subtract(a, b) {
var _subtract = (subrange) => {
var i = 0;
while (i < this.ranges.length && !subrange.overlaps(this.ranges[i])) {
i++;
}
var newRanges = this.ranges.slice(0, i);
while (i < this.ranges.length && subrange.overlaps(this.ranges[i])) {
newRanges = newRanges.concat(this.ranges[i].subtract(subrange));
i++;
}
this.ranges = newRanges.concat(this.ranges.slice(i));
this._update_length();
};
if (a instanceof _DRange) {
a.ranges.forEach(_subtract);
} else {
if (b == null)
b = a;
_subtract(new SubRange(a, b));
}
return this;
}
intersect(a, b) {
var newRanges = [];
var _intersect = (subrange) => {
var i = 0;
while (i < this.ranges.length && !subrange.overlaps(this.ranges[i])) {
i++;
}
while (i < this.ranges.length && subrange.overlaps(this.ranges[i])) {
var low = Math.max(this.ranges[i].low, subrange.low);
var high = Math.min(this.ranges[i].high, subrange.high);
newRanges.push(new SubRange(low, high));
i++;
}
};
if (a instanceof _DRange) {
a.ranges.forEach(_intersect);
} else {
if (b == null)
b = a;
_intersect(new SubRange(a, b));
}
this.ranges = newRanges;
this._update_length();
return this;
}
index(index) {
var i = 0;
while (i < this.ranges.length && this.ranges[i].length <= index) {
index -= this.ranges[i].length;
i++;
}
return this.ranges[i].low + index;
}
toString() {
return "[ " + this.ranges.join(", ") + " ]";
}
clone() {
return new _DRange(this);
}
numbers() {
return this.ranges.reduce((result, subrange) => {
var i = subrange.low;
while (i <= subrange.high) {
result.push(i);
i++;
}
return result;
}, []);
}
subranges() {
return this.ranges.map((subrange) => ({
low: subrange.low,
high: subrange.high,
length: 1 + subrange.high - subrange.low
}));
}
};
module.exports = DRange;
}
});
// node_modules/randexp/lib/randexp.js
var require_randexp = __commonJS({
"node_modules/randexp/lib/randexp.js"(exports, module) {
var ret = require_lib();
var DRange = require_lib2();
var types2 = ret.types;
module.exports = class RandExp2 {
/**
* @constructor
* @param {RegExp|String} regexp
* @param {String} m
*/
constructor(regexp, m) {
this._setDefaults(regexp);
if (regexp instanceof RegExp) {
this.ignoreCase = regexp.ignoreCase;
this.multiline = regexp.multiline;
regexp = regexp.source;
} else if (typeof regexp === "string") {
this.ignoreCase = m && m.indexOf("i") !== -1;
this.multiline = m && m.indexOf("m") !== -1;
} else {
throw new Error("Expected a regexp or string");
}
this.tokens = ret(regexp);
}
/**
* Checks if some custom properties have been set for this regexp.
*
* @param {RandExp} randexp
* @param {RegExp} regexp
*/
_setDefaults(regexp) {
this.max = regexp.max != null ? regexp.max : RandExp2.prototype.max != null ? RandExp2.prototype.max : 100;
this.defaultRange = regexp.defaultRange ? regexp.defaultRange : this.defaultRange.clone();
if (regexp.randInt) {
this.randInt = regexp.randInt;
}
}
/**
* Generates the random string.
*
* @return {String}
*/
gen() {
return this._gen(this.tokens, []);
}
/**
* Generate random string modeled after given tokens.
*
* @param {Object} token
* @param {Array.<String>} groups
* @return {String}
*/
_gen(token, groups) {
var stack, str, n, i, l;
switch (token.type) {
case types2.ROOT:
case types2.GROUP:
if (token.followedBy || token.notFollowedBy) {
return "";
}
if (token.remember && token.groupNumber === void 0) {
token.groupNumber = groups.push(null) - 1;
}
stack = token.options ? this._randSelect(token.options) : token.stack;
str = "";
for (i = 0, l = stack.length; i < l; i++) {
str += this._gen(stack[i], groups);
}
if (token.remember) {
groups[token.groupNumber] = str;
}
return str;
case types2.POSITION:
return "";
case types2.SET:
var expandedSet = this._expand(token);
if (!expandedSet.length) {
return "";
}
return String.fromCharCode(this._randSelect(expandedSet));
case types2.REPETITION:
n = this.randInt(
token.min,
token.max === Infinity ? token.min + this.max : token.max
);
str = "";
for (i = 0; i < n; i++) {
str += this._gen(token.value, groups);
}
return str;
case types2.REFERENCE:
return groups[token.value - 1] || "";
case types2.CHAR:
var code = this.ignoreCase && this._randBool() ? this._toOtherCase(token.value) : token.value;
return String.fromCharCode(code);
}
}
/**
* If code is alphabetic, converts to other case.
* If not alphabetic, returns back code.
*
* @param {Number} code
* @return {Number}
*/
_toOtherCase(code) {
return code + (97 <= code && code <= 122 ? -32 : 65 <= code && code <= 90 ? 32 : 0);
}
/**
* Randomly returns a true or false value.
*
* @return {Boolean}
*/
_randBool() {
return !this.randInt(0, 1);
}
/**
* Randomly selects and returns a value from the array.
*
* @param {Array.<Object>} arr
* @return {Object}
*/
_randSelect(arr) {
if (arr instanceof DRange) {
return arr.index(this.randInt(0, arr.length - 1));
}
return arr[this.randInt(0, arr.length - 1)];
}
/**
* expands a token to a DiscontinuousRange of characters which has a
* length and an index function (for random selecting)
*
* @param {Object} token
* @return {DiscontinuousRange}
*/
_expand(token) {
if (token.type === ret.types.CHAR) {
return new DRange(token.value);
} else if (token.type === ret.types.RANGE) {
return new DRange(token.from, token.to);
} else {
let drange = new DRange();
for (let i = 0; i < token.set.length; i++) {
let subrange = this._expand(token.set[i]);
drange.add(subrange);
if (this.ignoreCase) {
for (let j = 0; j < subrange.length; j++) {
let code = subrange.index(j);
let otherCaseCode = this._toOtherCase(code);
if (code !== otherCaseCode) {
drange.add(otherCaseCode);
}
}
}
}
if (token.not) {
return this.defaultRange.clone().subtract(drange);
} else {
return this.defaultRange.clone().intersect(drange);
}
}
}
/**
* Randomly generates and returns a number between a and b (inclusive).
*
* @param {Number} a
* @param {Number} b
* @return {Number}
*/
randInt(a, b) {
return a + Math.floor(Math.random() * (1 + b - a));
}
/**
* Default range of characters to generate from.
*/
get defaultRange() {
return this._range = this._range || new DRange(32, 126);
}
set defaultRange(range) {
this._range = range;
}
/**
*
* Enables use of randexp with a shorter call.
*
* @param {RegExp|String| regexp}
* @param {String} m
* @return {String}
*/
static randexp(regexp, m) {
var randexp;
if (typeof regexp === "string") {
regexp = new RegExp(regexp, m);
}
if (regexp._randexp === void 0) {
randexp = new RandExp2(regexp, m);
regexp._randexp = randexp;
} else {
randexp = regexp._randexp;
randexp._setDefaults(regexp);
}
return randexp.gen();
}
/**
* Enables sugary /regexp/.gen syntax.
*/
static sugar() {
RegExp.prototype.gen = function() {
return RandExp2.randexp(this);
};
}
};
}
});
// node_modules/yaml/dist/PlainValue-ec8e588e.js
var require_PlainValue_ec8e588e = __commonJS({
"node_modules/yaml/dist/PlainValue-ec8e588e.js"(exports) {
"use strict";
var Char = {
ANCHOR: "&",
COMMENT: "#",
TAG: "!",
DIRECTIVES_END: "-",
DOCUMENT_END: "."
};
var Type = {
ALIAS: "ALIAS",
BLANK_LINE: "BLANK_LINE",
BLOCK_FOLDED: "BLOCK_FOLDED",
BLOCK_LITERAL: "BLOCK_LITERAL",
COMMENT: "COMMENT",
DIRECTIVE: "DIRECTIVE",
DOCUMENT: "DOCUMENT",
FLOW_MAP: "FLOW_MAP",
FLOW_SEQ: "FLOW_SEQ",
MAP: "MAP",
MAP_KEY: "MAP_KEY",
MAP_VALUE: "MAP_VALUE",
PLAIN: "PLAIN",
QUOTE_DOUBLE: "QUOTE_DOUBLE",
QUOTE_SINGLE: "QUOTE_SINGLE",
SEQ: "SEQ",
SEQ_ITEM: "SEQ_ITEM"
};
var defaultTagPrefix = "tag:yaml.org,2002:";
var defaultTags = {
MAP: "tag:yaml.org,2002:map",
SEQ: "tag:yaml.org,2002:seq",
STR: "tag:yaml.org,2002:str"
};
function findLineStarts(src) {
const ls = [0];
let offset = src.indexOf("\n");
while (offset !== -1) {
offset += 1;
ls.push(offset);
offset = src.indexOf("\n", offset);
}
return ls;
}
function getSrcInfo(cst) {
let lineStarts, src;
if (typeof cst === "string") {
lineStarts = findLineStarts(cst);
src = cst;
} else {
if (Array.isArray(cst))
cst = cst[0];
if (cst && cst.context) {
if (!cst.lineStarts)
cst.lineStarts = findLineStarts(cst.context.src);
lineStarts = cst.lineStarts;
src = cst.context.src;
}
}
return {
lineStarts,
src
};
}
function getLinePos(offset, cst) {
if (typeof offset !== "number" || offset < 0)
return null;
const {
lineStarts,
src
} = getSrcInfo(cst);
if (!lineStarts || !src || offset > src.length)
return null;
for (let i = 0; i < lineStarts.length; ++i) {
const start = lineStarts[i];
if (offset < start) {
return {
line: i,
col: offset - lineStarts[i - 1] + 1
};
}
if (offset === start)
return {
line: i + 1,
col: 1
};
}
const line = lineStarts.length;
return {
line,
col: offset - lineStarts[line - 1] + 1
};
}
function getLine(line, cst) {
const {
lineStarts,
src
} = getSrcInfo(cst);
if (!lineStarts || !(line >= 1) || line > lineStarts.length)
return null;
const start = lineStarts[line - 1];
let end = lineStarts[line];
while (end && end > start && src[end - 1] === "\n")
--end;
return src.slice(start, end);
}
function getPrettyContext({
start,
end
}, cst, maxWidth = 80) {
let src = getLine(start.line, cst);
if (!src)
return null;
let {
col
} = start;
if (src.length > maxWidth) {
if (col <= maxWidth - 10) {
src = src.substr(0, maxWidth - 1) + "\u2026";
} else {
const halfWidth = Math.round(maxWidth / 2);
if (src.length > col + halfWidth)
src = src.substr(0, col + halfWidth - 1) + "\u2026";
col -= src.length - maxWidth;
src = "\u2026" + src.substr(1 - maxWidth);
}
}
let errLen = 1;
let errEnd = "";
if (end) {
if (end.line === start.line && col + (end.col - start.col) <= maxWidth + 1) {
errLen = end.col - start.col;
} else {
errLen = Math.min(src.length + 1, maxWidth) - col;
errEnd = "\u2026";
}
}
const offset = col > 1 ? " ".repeat(col - 1) : "";
const err = "^".repeat(errLen);
return `${src}
${offset}${err}${errEnd}`;
}
var Range = class _Range {
static copy(orig) {
return new _Range(orig.start, orig.end);
}
constructor(start, end) {
this.start = start;
this.end = end || start;
}
isEmpty() {
return typeof this.start !== "number" || !this.end || this.end <= this.start;
}
/**
* Set `origStart` and `origEnd` to point to the original source range for
* this node, which may differ due to dropped CR characters.
*
* @param {number[]} cr - Positions of dropped CR characters
* @param {number} offset - Starting index of `cr` from the last call
* @returns {number} - The next offset, matching the one found for `origStart`
*/
setOrigRange(cr, offset) {
const {
start,
end
} = this;
if (cr.length === 0 || end <= cr[0]) {
this.origStart = start;
this.origEnd = end;
return offset;
}
let i = offset;
while (i < cr.length) {
if (cr[i] > start)
break;
else
++i;
}
this.origStart = start + i;
const nextOffset = i;
while (i < cr.length) {
if (cr[i] >= end)
break;
else
++i;
}
this.origEnd = end + i;
return nextOffset;
}
};
var Node2 = class _Node {
static addStringTerminator(src, offset, str) {
if (str[str.length - 1] === "\n")
return str;
const next = _Node.endOfWhiteSpace(src, offset);
return next >= src.length || src[next] === "\n" ? str + "\n" : str;
}
// ^(---|...)
static atDocumentBoundary(src, offset, sep) {
const ch0 = src[offset];
if (!ch0)
return true;
const prev = src[offset - 1];
if (prev && prev !== "\n")
return false;
if (sep) {
if (ch0 !== sep)
return false;
} else {
if (ch0 !== Char.DIRECTIVES_END && ch0 !== Char.DOCUMENT_END)
return false;
}
const ch1 = src[offset + 1];
const ch2 = src[offset + 2];
if (ch1 !== ch0 || ch2 !== ch0)
return false;
const ch3 = src[offset + 3];
return !ch3 || ch3 === "\n" || ch3 === " " || ch3 === " ";
}
static endOfIdentifier(src, offset) {
let ch = src[offset];
const isVerbatim = ch === "<";
const notOk = isVerbatim ? ["\n", " ", " ", ">"] : ["\n", " ", " ", "[", "]", "{", "}", ","];
while (ch && notOk.indexOf(ch) === -1)
ch = src[offset += 1];
if (isVerbatim && ch === ">")
offset += 1;
return offset;
}
static endOfIndent(src, offset) {
let ch = src[offset];
while (ch === " ")
ch = src[offset += 1];
return offset;
}
static endOfLine(src, offset) {
let ch = src[offset];
while (ch && ch !== "\n")
ch = src[offset += 1];
return offset;
}
static endOfWhiteSpace(src, offset) {
let ch = src[offset];
while (ch === " " || ch === " ")
ch = src[offset += 1];
return offset;
}
static startOfLine(src, offset) {
let ch = src[offset - 1];
if (ch === "\n")
return offset;
while (ch && ch !== "\n")
ch = src[offset -= 1];
return offset + 1;
}
/**
* End of indentation, or null if the line's indent level is not more
* than `indent`
*
* @param {string} src
* @param {number} indent
* @param {number} lineStart
* @returns {?number}
*/
static endOfBlockIndent(src, indent, lineStart) {
const inEnd = _Node.endOfIndent(src, lineStart);
if (inEnd > lineStart + indent) {
return inEnd;
} else {
const wsEnd = _Node.endOfWhiteSpace(src, inEnd);
const ch = src[wsEnd];
if (!ch || ch === "\n")
return wsEnd;
}
return null;
}
static atBlank(src, offset, endAsBlank) {
const ch = src[offset];
return ch === "\n" || ch === " " || ch === " " || endAsBlank && !ch;
}
static nextNodeIsIndented(ch, indentDiff, indicatorAsIndent) {
if (!ch || indentDiff < 0)
return false;
if (indentDiff > 0)
return true;
return indicatorAsIndent && ch === "-";
}
// should be at line or string end, or at next non-whitespace char
static normalizeOffset(src, offset) {
const ch = src[offset];
return !ch ? offset : ch !== "\n" && src[offset - 1] === "\n" ? offset - 1 : _Node.endOfWhiteSpace(src, offset);
}
// fold single newline into space, multiple newlines to N - 1 newlines
// presumes src[offset] === '\n'
static foldNewline(src, offset, indent) {
let inCount = 0;
let error = false;
let fold = "";
let ch = src[offset + 1];
while (ch === " " || ch === " " || ch === "\n") {
switch (ch) {
case "\n":
inCount = 0;
offset += 1;
fold += "\n";
break;
case " ":
if (inCount <= indent)
error = true;
offset = _Node.endOfWhiteSpace(src, offset + 2) - 1;
break;
case " ":
inCount += 1;
offset += 1;
break;
}
ch = src[offset + 1];
}
if (!fold)
fold = " ";
if (ch && inCount <= indent)
error = true;
return {
fold,
offset,
error
};
}
constructor(type, props, context) {
Object.defineProperty(this, "context", {
value: context || null,
writable: true
});
this.error = null;
this.range = null;
this.valueRange = null;
this.props = props || [];
this.type = type;
this.value = null;
}
getPropValue(idx, key, skipKey) {
if (!this.context)
return null;
const {
src
} = this.context;
const prop = this.props[idx];
return prop && src[prop.start] === key ? src.slice(prop.start + (skipKey ? 1 : 0), prop.end) : null;
}
get anchor() {
for (let i = 0; i < this.props.length; ++i) {
const anchor = this.getPropValue(i, Char.ANCHOR, true);
if (anchor != null)
return anchor;
}
return null;
}
get comment() {
const comments = [];
for (let i = 0; i < this.props.length; ++i) {
const comment = this.getPropValue(i, Char.COMMENT, true);
if (comment != null)
comments.push(comment);
}
return comments.length > 0 ? comments.join("\n") : null;
}
commentHasRequiredWhitespace(start) {
const {
src
} = this.context;
if (this.header && start === this.header.end)
return false;
if (!this.valueRange)
return false;
const {
end
} = this.valueRange;
return start !== end || _Node.atBlank(src, end - 1);
}
get hasComment() {
if (this.context) {
const {
src
} = this.context;
for (let i = 0; i < this.props.length; ++i) {
if (src[this.props[i].start] === Char.COMMENT)
return true;
}
}
return false;
}
get hasProps() {
if (this.context) {
const {
src
} = this.context;
for (let i = 0; i < this.props.length; ++i) {
if (src[this.props[i].start] !== Char.COMMENT)
return true;
}
}
return false;
}
get includesTrailingLines() {
return false;
}
get jsonLike() {
const jsonLikeTypes = [Type.FLOW_MAP, Type.FLOW_SEQ, Type.QUOTE_DOUBLE, Type.QUOTE_SINGLE];
return jsonLikeTypes.indexOf(this.type) !== -1;
}
get rangeAsLinePos() {
if (!this.range || !this.context)
return void 0;
const start = getLinePos(this.range.start, this.context.root);
if (!start)
return void 0;
const end = getLinePos(this.range.end, this.context.root);
return {
start,
end
};
}
get rawValue() {
if (!this.valueRange || !this.context)
return null;
const {
start,
end
} = this.valueRange;
return this.context.src.slice(start, end);
}
get tag() {
for (let i = 0; i < this.props.length; ++i) {
const tag = this.getPropValue(i, Char.TAG, false);
if (tag != null) {
if (tag[1] === "<") {
return {
verbatim: tag.slice(2, -1)
};
} else {
const [_, handle, suffix] = tag.match(/^(.*!)([^!]*)$/);
return {
handle,
suffix
};
}
}
}
return null;
}
get valueRangeContainsNewline() {
if (!this.valueRange || !this.context)
return false;
const {
start,
end
} = this.valueRange;
const {
src
} = this.context;
for (let i = start; i < end; ++i) {
if (src[i] === "\n")
return true;
}
return false;
}
parseComment(start) {
const {
src
} = this.context;
if (src[start] === Char.COMMENT) {
const end = _Node.endOfLine(src, start + 1);
const commentRange = new Range(start, end);
this.props.push(commentRange);
return end;
}
return start;
}
/**
* Populates the `origStart` and `origEnd` values of all ranges for this
* node. Extended by child classes to handle descendant nodes.
*
* @param {number[]} cr - Positions of dropped CR characters
* @param {number} offset - Starting index of `cr` from the last call
* @returns {number} - The next offset, matching the one found for `origStart`
*/
setOrigRanges(cr, offset) {
if (this.range)
offset = this.range.setOrigRange(cr, offset);
if (this.valueRange)
this.valueRange.setOrigRange(cr, offset);
this.props.forEach((prop) => prop.setOrigRange(cr, offset));
return offset;
}
toString() {
const {
context: {
src
},
range,
value
} = this;
if (value != null)
return value;
const str = src.slice(range.start, range.end);
return _Node.addStringTerminator(src, range.end, str);
}
};
var YAMLError = class extends Error {
constructor(name, source, message) {
if (!message || !(source instanceof Node2))
throw new Error(`Invalid arguments for new ${name}`);
super();
this.name = name;
this.message = message;
this.source = source;
}
makePretty() {
if (!this.source)
return;
this.nodeType = this.source.type;
const cst = this.source.context && this.source.context.root;
if (typeof this.offset === "number") {
this.range = new Range(this.offset, this.offset + 1);
const start = cst && getLinePos(this.offset, cst);
if (start) {
const end = {
line: start.line,
col: start.col + 1
};
this.linePos = {
start,
end
};
}
delete this.offset;
} else {
this.range = this.source.range;
this.linePos = this.source.rangeAsLinePos;
}
if (this.linePos) {
const {
line,
col
} = this.linePos.start;
this.message += ` at line ${line}, column ${col}`;
const ctx = cst && getPrettyContext(this.linePos, cst);
if (ctx)
this.message += `:
${ctx}
`;
}
delete this.source;
}
};
var YAMLReferenceError = class extends YAMLError {
constructor(source, message) {
super("YAMLReferenceError", source, message);
}
};
var YAMLSemanticError = class extends YAMLError {
constructor(source, message) {
super("YAMLSemanticError", source, message);
}
};
var YAMLSyntaxError = class extends YAMLError {
constructor(source, message) {
super("YAMLSyntaxError", source, message);
}
};
var YAMLWarning = class extends YAMLError {
constructor(source, message) {
super("YAMLWarning", source, message);
}
};
function _defineProperty(obj, key, value) {
if (key in obj) {
Object.defineProperty(obj, key, {
value,
enumerable: true,
configurable: true,
writable: true
});
} else {
obj[key] = value;
}
return obj;
}
var PlainValue = class _PlainValue extends Node2 {
static endOfLine(src, start, inFlow) {
let ch = src[start];
let offset = start;
while (ch && ch !== "\n") {
if (inFlow && (ch === "[" || ch === "]" || ch === "{" || ch === "}" || ch === ","))
break;
const next = src[offset + 1];
if (ch === ":" && (!next || next === "\n" || next === " " || next === " " || inFlow && next === ","))
break;
if ((ch === " " || ch === " ") && next === "#")
break;
offset += 1;
ch = next;
}
return offset;
}
get strValue() {
if (!this.valueRange || !this.context)
return null;
let {
start,
end
} = this.valueRange;
const {
src
} = this.context;
let ch = src[end - 1];
while (start < end && (ch === "\n" || ch === " " || ch === " "))
ch = src[--end - 1];
let str = "";
for (let i = start; i < end; ++i) {
const ch2 = src[i];
if (ch2 === "\n") {
const {
fold,
offset
} = Node2.foldNewline(src, i, -1);
str += fold;
i = offset;
} else if (ch2 === " " || ch2 === " ") {
const wsStart = i;
let next = src[i + 1];
while (i < end && (next === " " || next === " ")) {
i += 1;
next = src[i + 1];
}
if (next !== "\n")
str += i > wsStart ? src.slice(wsStart, i + 1) : ch2;
} else {
str += ch2;
}
}
const ch0 = src[start];
switch (ch0) {
case " ": {
const msg = "Plain value cannot start with a tab character";
const errors = [new YAMLSemanticError(this, msg)];
return {
errors,
str
};
}
case "@":
case "`": {
const msg = `Plain value cannot start with reserved character ${ch0}`;
const errors = [new YAMLSemanticError(this, msg)];
return {
errors,
str
};
}
default:
return str;
}
}
parseBlockValue(start) {
const {
indent,
inFlow,
src
} = this.context;
let offset = start;
let valueEnd = start;
for (let ch = src[offset]; ch === "\n"; ch = src[offset]) {
if (Node2.atDocumentBoundary(src, offset + 1))
break;
const end = Node2.endOfBlockIndent(src, indent, offset + 1);
if (end === null || src[end] === "#")
break;
if (src[end] === "\n") {
offset = end;
} else {
valueEnd = _PlainValue.endOfLine(src, end, inFlow);
offset = valueEnd;
}
}
if (this.valueRange.isEmpty())
this.valueRange.start = start;
this.valueRange.end = valueEnd;
return valueEnd;
}
/**
* Parses a plain value from the source
*
* Accepted forms are:
* ```
* #comment
*
* first line
*
* first line #comment
*
* first line
* block
* lines
*
* #comment
* block
* lines
* ```
* where block lines are empty or have an indent level greater than `indent`.
*
* @param {ParseContext} context
* @param {number} start - Index of first character
* @returns {number} - Index of the character after this scalar, may be `\n`
*/
parse(context, start) {
this.context = context;
const {
inFlow,
src
} = context;
let offset = start;
const ch = src[offset];
if (ch && ch !== "#" && ch !== "\n") {
offset = _PlainValue.endOfLine(src, start, inFlow);
}
this.valueRange = new Range(start, offset);
offset = Node2.endOfWhiteSpace(src, offset);
offset = this.parseComment(offset);
if (!this.hasComment || this.valueRange.isEmpty()) {
offset = this.parseBlockValue(offset);
}
return offset;
}
};
exports.Char = Char;
exports.Node = Node2;
exports.PlainValue = PlainValue;
exports.Range = Range;
exports.Type = Type;
exports.YAMLError = YAMLError;
exports.YAMLReferenceError = YAMLReferenceError;
exports.YAMLSemanticError = YAMLSemanticError;
exports.YAMLSyntaxError = YAMLSyntaxError;
exports.YAMLWarning = YAMLWarning;
exports._defineProperty = _defineProperty;
exports.defaultTagPrefix = defaultTagPrefix;
exports.defaultTags = defaultTags;
}
});
// node_modules/yaml/dist/resolveSeq-d03cb037.js
var require_resolveSeq_d03cb037 = __commonJS({
"node_modules/yaml/dist/resolveSeq-d03cb037.js"(exports) {
"use strict";
var PlainValue = require_PlainValue_ec8e588e();
function addCommentBefore(str, indent, comment) {
if (!comment)
return str;
const cc = comment.replace(/[\s\S]^/gm, `$&${indent}#`);
return `#${cc}
${indent}${str}`;
}
function addComment(str, indent, comment) {
return !comment ? str : comment.indexOf("\n") === -1 ? `${str} #${comment}` : `${str}
` + comment.replace(/^/gm, `${indent || ""}#`);
}
var Node2 = class {
};
function toJSON(value, arg, ctx) {
if (Array.isArray(value))
return value.map((v, i) => toJSON(v, String(i), ctx));
if (value && typeof value.toJSON === "function") {
const anchor = ctx && ctx.anchors && ctx.anchors.get(value);
if (anchor)
ctx.onCreate = (res2) => {
anchor.res = res2;
delete ctx.onCreate;
};
const res = value.toJSON(arg, ctx);
if (anchor && ctx.onCreate)
ctx.onCreate(res);
return res;
}
if ((!ctx || !ctx.keep) && typeof value === "bigint")
return Number(value);
return value;
}
var Scalar2 = class extends Node2 {
constructor(value) {
super();
this.value = value;
}
toJSON(arg, ctx) {
return ctx && ctx.keep ? this.value : toJSON(this.value, arg, ctx);
}
toString() {
return String(this.value);
}
};
function collectionFromPath(schema, path, value) {
let v = value;
for (let i = path.length - 1; i >= 0; --i) {
const k = path[i];
if (Number.isInteger(k) && k >= 0) {
const a = [];
a[k] = v;
v = a;
} else {
const o = {};
Object.defineProperty(o, k, {
value: v,
writable: true,
enumerable: true,
configurable: true
});
v = o;
}
}
return schema.createNode(v, false);
}
var isEmptyPath = (path) => path == null || typeof path === "object" && path[Symbol.iterator]().next().done;
var Collection2 = class _Collection extends Node2 {
constructor(schema) {
super();
PlainValue._defineProperty(this, "items", []);
this.schema = schema;
}
addIn(path, value) {
if (isEmptyPath(path))
this.add(value);
else {
const [key, ...rest] = path;
const node = this.get(key, true);
if (node instanceof _Collection)
node.addIn(rest, value);
else if (node === void 0 && this.schema)
this.set(key, collectionFromPath(this.schema, rest, value));
else
throw new Error(`Expected YAML collection at ${key}. Remaining path: ${rest}`);
}
}
deleteIn([key, ...rest]) {
if (rest.length === 0)
return this.delete(key);
const node = this.get(key, true);
if (node instanceof _Collection)
return node.deleteIn(rest);
else
throw new Error(`Expected YAML collection at ${key}. Remaining path: ${rest}`);
}
getIn([key, ...rest], keepScalar) {
const node = this.get(key, true);
if (rest.length === 0)
return !keepScalar && node instanceof Scalar2 ? node.value : node;
else
return node instanceof _Collection ? node.getIn(rest, keepScalar) : void 0;
}
hasAllNullValues() {
return this.items.every((node) => {
if (!node || node.type !== "PAIR")
return false;
const n = node.value;
return n == null || n instanceof Scalar2 && n.value == null && !n.commentBefore && !n.comment && !n.tag;
});
}
hasIn([key, ...rest]) {
if (rest.length === 0)
return this.has(key);
const node = this.get(key, true);
return node instanceof _Collection ? node.hasIn(rest) : false;
}
setIn([key, ...rest], value) {
if (rest.length === 0) {
this.set(key, value);