UNPKG

miniflare

Version:

Fun, full-featured, fully-local simulator for Cloudflare Workers

934 lines (923 loc) • 150 kB
var __create = Object.create; var __defProp = Object.defineProperty; var __getOwnPropDesc = Object.getOwnPropertyDescriptor; var __getOwnPropNames = Object.getOwnPropertyNames; var __getProtoOf = Object.getPrototypeOf, __hasOwnProp = Object.prototype.hasOwnProperty; var __commonJS = (cb, mod) => function() { try { return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports; } catch (e) { throw mod = 0, e; } }; var __copyProps = (to, from, except, desc) => { if (from && typeof from == "object" || typeof from == "function") for (let key of __getOwnPropNames(from)) !__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: !0 }) : target, mod )); // ../../node_modules/.pnpm/fast-xml-parser@4.4.1/node_modules/fast-xml-parser/src/util.js var require_util = __commonJS({ "../../node_modules/.pnpm/fast-xml-parser@4.4.1/node_modules/fast-xml-parser/src/util.js"(exports) { "use strict"; var nameStartChar = ":A-Za-z_\\u00C0-\\u00D6\\u00D8-\\u00F6\\u00F8-\\u02FF\\u0370-\\u037D\\u037F-\\u1FFF\\u200C-\\u200D\\u2070-\\u218F\\u2C00-\\u2FEF\\u3001-\\uD7FF\\uF900-\\uFDCF\\uFDF0-\\uFFFD", nameChar = nameStartChar + "\\-.\\d\\u00B7\\u0300-\\u036F\\u203F-\\u2040", nameRegexp = "[" + nameStartChar + "][" + nameChar + "]*", regexName = new RegExp("^" + nameRegexp + "$"), getAllMatches = function(string, regex) { let matches = [], match = regex.exec(string); for (; match; ) { let allmatches = []; allmatches.startIndex = regex.lastIndex - match[0].length; let len = match.length; for (let index = 0; index < len; index++) allmatches.push(match[index]); matches.push(allmatches), match = regex.exec(string); } return matches; }, isName = function(string) { let match = regexName.exec(string); return !(match === null || typeof match > "u"); }; exports.isExist = function(v) { return typeof v < "u"; }; exports.isEmptyObject = function(obj) { return Object.keys(obj).length === 0; }; exports.merge = function(target, a, arrayMode) { if (a) { let keys = Object.keys(a), len = keys.length; for (let i = 0; i < len; i++) arrayMode === "strict" ? target[keys[i]] = [a[keys[i]]] : target[keys[i]] = a[keys[i]]; } }; exports.getValue = function(v) { return exports.isExist(v) ? v : ""; }; exports.isName = isName; exports.getAllMatches = getAllMatches; exports.nameRegexp = nameRegexp; } }); // ../../node_modules/.pnpm/fast-xml-parser@4.4.1/node_modules/fast-xml-parser/src/validator.js var require_validator = __commonJS({ "../../node_modules/.pnpm/fast-xml-parser@4.4.1/node_modules/fast-xml-parser/src/validator.js"(exports) { "use strict"; var util = require_util(), defaultOptions = { allowBooleanAttributes: !1, //A tag can have attributes without any value unpairedTags: [] }; exports.validate = function(xmlData, options) { options = Object.assign({}, defaultOptions, options); let tags = [], tagFound = !1, reachedRoot = !1; xmlData[0] === "\uFEFF" && (xmlData = xmlData.substr(1)); for (let i = 0; i < xmlData.length; i++) if (xmlData[i] === "<" && xmlData[i + 1] === "?") { if (i += 2, i = readPI(xmlData, i), i.err) return i; } else if (xmlData[i] === "<") { let tagStartPos = i; if (i++, xmlData[i] === "!") { i = readCommentAndCDATA(xmlData, i); continue; } else { let closingTag = !1; xmlData[i] === "/" && (closingTag = !0, i++); let tagName = ""; for (; i < xmlData.length && xmlData[i] !== ">" && xmlData[i] !== " " && xmlData[i] !== " " && xmlData[i] !== ` ` && xmlData[i] !== "\r"; i++) tagName += xmlData[i]; if (tagName = tagName.trim(), tagName[tagName.length - 1] === "/" && (tagName = tagName.substring(0, tagName.length - 1), i--), !validateTagName(tagName)) { let msg; return tagName.trim().length === 0 ? msg = "Invalid space after '<'." : msg = "Tag '" + tagName + "' is an invalid name.", getErrorObject("InvalidTag", msg, getLineNumberForPosition(xmlData, i)); } let result = readAttributeStr(xmlData, i); if (result === !1) return getErrorObject("InvalidAttr", "Attributes for '" + tagName + "' have open quote.", getLineNumberForPosition(xmlData, i)); let attrStr = result.value; if (i = result.index, attrStr[attrStr.length - 1] === "/") { let attrStrStart = i - attrStr.length; attrStr = attrStr.substring(0, attrStr.length - 1); let isValid = validateAttributeString(attrStr, options); if (isValid === !0) tagFound = !0; else return getErrorObject(isValid.err.code, isValid.err.msg, getLineNumberForPosition(xmlData, attrStrStart + isValid.err.line)); } else if (closingTag) if (result.tagClosed) { if (attrStr.trim().length > 0) return getErrorObject("InvalidTag", "Closing tag '" + tagName + "' can't have attributes or invalid starting.", getLineNumberForPosition(xmlData, tagStartPos)); if (tags.length === 0) return getErrorObject("InvalidTag", "Closing tag '" + tagName + "' has not been opened.", getLineNumberForPosition(xmlData, tagStartPos)); { let otg = tags.pop(); if (tagName !== otg.tagName) { let openPos = getLineNumberForPosition(xmlData, otg.tagStartPos); return getErrorObject( "InvalidTag", "Expected closing tag '" + otg.tagName + "' (opened in line " + openPos.line + ", col " + openPos.col + ") instead of closing tag '" + tagName + "'.", getLineNumberForPosition(xmlData, tagStartPos) ); } tags.length == 0 && (reachedRoot = !0); } } else return getErrorObject("InvalidTag", "Closing tag '" + tagName + "' doesn't have proper closing.", getLineNumberForPosition(xmlData, i)); else { let isValid = validateAttributeString(attrStr, options); if (isValid !== !0) return getErrorObject(isValid.err.code, isValid.err.msg, getLineNumberForPosition(xmlData, i - attrStr.length + isValid.err.line)); if (reachedRoot === !0) return getErrorObject("InvalidXml", "Multiple possible root nodes found.", getLineNumberForPosition(xmlData, i)); options.unpairedTags.indexOf(tagName) !== -1 || tags.push({ tagName, tagStartPos }), tagFound = !0; } for (i++; i < xmlData.length; i++) if (xmlData[i] === "<") if (xmlData[i + 1] === "!") { i++, i = readCommentAndCDATA(xmlData, i); continue; } else if (xmlData[i + 1] === "?") { if (i = readPI(xmlData, ++i), i.err) return i; } else break; else if (xmlData[i] === "&") { let afterAmp = validateAmpersand(xmlData, i); if (afterAmp == -1) return getErrorObject("InvalidChar", "char '&' is not expected.", getLineNumberForPosition(xmlData, i)); i = afterAmp; } else if (reachedRoot === !0 && !isWhiteSpace(xmlData[i])) return getErrorObject("InvalidXml", "Extra text at the end", getLineNumberForPosition(xmlData, i)); xmlData[i] === "<" && i--; } } else { if (isWhiteSpace(xmlData[i])) continue; return getErrorObject("InvalidChar", "char '" + xmlData[i] + "' is not expected.", getLineNumberForPosition(xmlData, i)); } if (tagFound) { if (tags.length == 1) return getErrorObject("InvalidTag", "Unclosed tag '" + tags[0].tagName + "'.", getLineNumberForPosition(xmlData, tags[0].tagStartPos)); if (tags.length > 0) return getErrorObject("InvalidXml", "Invalid '" + JSON.stringify(tags.map((t) => t.tagName), null, 4).replace(/\r?\n/g, "") + "' found.", { line: 1, col: 1 }); } else return getErrorObject("InvalidXml", "Start tag expected.", 1); return !0; }; function isWhiteSpace(char) { return char === " " || char === " " || char === ` ` || char === "\r"; } function readPI(xmlData, i) { let start = i; for (; i < xmlData.length; i++) if (xmlData[i] == "?" || xmlData[i] == " ") { let tagname = xmlData.substr(start, i - start); if (i > 5 && tagname === "xml") return getErrorObject("InvalidXml", "XML declaration allowed only at the start of the document.", getLineNumberForPosition(xmlData, i)); if (xmlData[i] == "?" && xmlData[i + 1] == ">") { i++; break; } else continue; } return i; } function readCommentAndCDATA(xmlData, i) { if (xmlData.length > i + 5 && xmlData[i + 1] === "-" && xmlData[i + 2] === "-") { for (i += 3; i < xmlData.length; i++) if (xmlData[i] === "-" && xmlData[i + 1] === "-" && xmlData[i + 2] === ">") { i += 2; break; } } else if (xmlData.length > i + 8 && xmlData[i + 1] === "D" && xmlData[i + 2] === "O" && xmlData[i + 3] === "C" && xmlData[i + 4] === "T" && xmlData[i + 5] === "Y" && xmlData[i + 6] === "P" && xmlData[i + 7] === "E") { let angleBracketsCount = 1; for (i += 8; i < xmlData.length; i++) if (xmlData[i] === "<") angleBracketsCount++; else if (xmlData[i] === ">" && (angleBracketsCount--, angleBracketsCount === 0)) break; } else if (xmlData.length > i + 9 && xmlData[i + 1] === "[" && xmlData[i + 2] === "C" && xmlData[i + 3] === "D" && xmlData[i + 4] === "A" && xmlData[i + 5] === "T" && xmlData[i + 6] === "A" && xmlData[i + 7] === "[") { for (i += 8; i < xmlData.length; i++) if (xmlData[i] === "]" && xmlData[i + 1] === "]" && xmlData[i + 2] === ">") { i += 2; break; } } return i; } var doubleQuote = '"', singleQuote = "'"; function readAttributeStr(xmlData, i) { let attrStr = "", startChar = "", tagClosed = !1; for (; i < xmlData.length; i++) { if (xmlData[i] === doubleQuote || xmlData[i] === singleQuote) startChar === "" ? startChar = xmlData[i] : startChar !== xmlData[i] || (startChar = ""); else if (xmlData[i] === ">" && startChar === "") { tagClosed = !0; break; } attrStr += xmlData[i]; } return startChar !== "" ? !1 : { value: attrStr, index: i, tagClosed }; } var validAttrStrRegxp = new RegExp(`(\\s*)([^\\s=]+)(\\s*=)?(\\s*(['"])(([\\s\\S])*?)\\5)?`, "g"); function validateAttributeString(attrStr, options) { let matches = util.getAllMatches(attrStr, validAttrStrRegxp), attrNames = {}; for (let i = 0; i < matches.length; i++) { if (matches[i][1].length === 0) return getErrorObject("InvalidAttr", "Attribute '" + matches[i][2] + "' has no space in starting.", getPositionFromMatch(matches[i])); if (matches[i][3] !== void 0 && matches[i][4] === void 0) return getErrorObject("InvalidAttr", "Attribute '" + matches[i][2] + "' is without value.", getPositionFromMatch(matches[i])); if (matches[i][3] === void 0 && !options.allowBooleanAttributes) return getErrorObject("InvalidAttr", "boolean attribute '" + matches[i][2] + "' is not allowed.", getPositionFromMatch(matches[i])); let attrName = matches[i][2]; if (!validateAttrName(attrName)) return getErrorObject("InvalidAttr", "Attribute '" + attrName + "' is an invalid name.", getPositionFromMatch(matches[i])); if (!attrNames.hasOwnProperty(attrName)) attrNames[attrName] = 1; else return getErrorObject("InvalidAttr", "Attribute '" + attrName + "' is repeated.", getPositionFromMatch(matches[i])); } return !0; } function validateNumberAmpersand(xmlData, i) { let re = /\d/; for (xmlData[i] === "x" && (i++, re = /[\da-fA-F]/); i < xmlData.length; i++) { if (xmlData[i] === ";") return i; if (!xmlData[i].match(re)) break; } return -1; } function validateAmpersand(xmlData, i) { if (i++, xmlData[i] === ";") return -1; if (xmlData[i] === "#") return i++, validateNumberAmpersand(xmlData, i); let count = 0; for (; i < xmlData.length; i++, count++) if (!(xmlData[i].match(/\w/) && count < 20)) { if (xmlData[i] === ";") break; return -1; } return i; } function getErrorObject(code, message, lineNumber) { return { err: { code, msg: message, line: lineNumber.line || lineNumber, col: lineNumber.col } }; } function validateAttrName(attrName) { return util.isName(attrName); } function validateTagName(tagname) { return util.isName(tagname); } function getLineNumberForPosition(xmlData, index) { let lines = xmlData.substring(0, index).split(/\r?\n/); return { line: lines.length, // column number is last line's length + 1, because column numbering starts at 1: col: lines[lines.length - 1].length + 1 }; } function getPositionFromMatch(match) { return match.startIndex + match[1].length; } } }); // ../../node_modules/.pnpm/fast-xml-parser@4.4.1/node_modules/fast-xml-parser/src/xmlparser/OptionsBuilder.js var require_OptionsBuilder = __commonJS({ "../../node_modules/.pnpm/fast-xml-parser@4.4.1/node_modules/fast-xml-parser/src/xmlparser/OptionsBuilder.js"(exports) { var defaultOptions = { preserveOrder: !1, attributeNamePrefix: "@_", attributesGroupName: !1, textNodeName: "#text", ignoreAttributes: !0, removeNSPrefix: !1, // remove NS from tag name or attribute name if true allowBooleanAttributes: !1, //a tag can have attributes without any value //ignoreRootElement : false, parseTagValue: !0, parseAttributeValue: !1, trimValues: !0, //Trim string values of tag and attributes cdataPropName: !1, numberParseOptions: { hex: !0, leadingZeros: !0, eNotation: !0 }, tagValueProcessor: function(tagName, val2) { return val2; }, attributeValueProcessor: function(attrName, val2) { return val2; }, stopNodes: [], //nested tags will not be parsed even for errors alwaysCreateTextNode: !1, isArray: () => !1, commentPropName: !1, unpairedTags: [], processEntities: !0, htmlEntities: !1, ignoreDeclaration: !1, ignorePiTags: !1, transformTagName: !1, transformAttributeName: !1, updateTag: function(tagName, jPath, attrs) { return tagName; } // skipEmptyListItem: false }, buildOptions = function(options) { return Object.assign({}, defaultOptions, options); }; exports.buildOptions = buildOptions; exports.defaultOptions = defaultOptions; } }); // ../../node_modules/.pnpm/fast-xml-parser@4.4.1/node_modules/fast-xml-parser/src/xmlparser/xmlNode.js var require_xmlNode = __commonJS({ "../../node_modules/.pnpm/fast-xml-parser@4.4.1/node_modules/fast-xml-parser/src/xmlparser/xmlNode.js"(exports, module) { "use strict"; var XmlNode = class { constructor(tagname) { this.tagname = tagname, this.child = [], this[":@"] = {}; } add(key, val2) { key === "__proto__" && (key = "#__proto__"), this.child.push({ [key]: val2 }); } addChild(node) { node.tagname === "__proto__" && (node.tagname = "#__proto__"), node[":@"] && Object.keys(node[":@"]).length > 0 ? this.child.push({ [node.tagname]: node.child, ":@": node[":@"] }) : this.child.push({ [node.tagname]: node.child }); } }; module.exports = XmlNode; } }); // ../../node_modules/.pnpm/fast-xml-parser@4.4.1/node_modules/fast-xml-parser/src/xmlparser/DocTypeReader.js var require_DocTypeReader = __commonJS({ "../../node_modules/.pnpm/fast-xml-parser@4.4.1/node_modules/fast-xml-parser/src/xmlparser/DocTypeReader.js"(exports, module) { var util = require_util(); function readDocType(xmlData, i) { let entities = {}; if (xmlData[i + 3] === "O" && xmlData[i + 4] === "C" && xmlData[i + 5] === "T" && xmlData[i + 6] === "Y" && xmlData[i + 7] === "P" && xmlData[i + 8] === "E") { i = i + 9; let angleBracketsCount = 1, hasBody = !1, comment = !1, exp = ""; for (; i < xmlData.length; i++) if (xmlData[i] === "<" && !comment) { if (hasBody && isEntity(xmlData, i)) i += 7, [entityName, val, i] = readEntityExp(xmlData, i + 1), val.indexOf("&") === -1 && (entities[validateEntityName(entityName)] = { regx: RegExp(`&${entityName};`, "g"), val }); else if (hasBody && isElement(xmlData, i)) i += 8; else if (hasBody && isAttlist(xmlData, i)) i += 8; else if (hasBody && isNotation(xmlData, i)) i += 9; else if (isComment) comment = !0; else throw new Error("Invalid DOCTYPE"); angleBracketsCount++, exp = ""; } else if (xmlData[i] === ">") { if (comment ? xmlData[i - 1] === "-" && xmlData[i - 2] === "-" && (comment = !1, angleBracketsCount--) : angleBracketsCount--, angleBracketsCount === 0) break; } else xmlData[i] === "[" ? hasBody = !0 : exp += xmlData[i]; if (angleBracketsCount !== 0) throw new Error("Unclosed DOCTYPE"); } else throw new Error("Invalid Tag instead of DOCTYPE"); return { entities, i }; } function readEntityExp(xmlData, i) { let entityName2 = ""; for (; i < xmlData.length && xmlData[i] !== "'" && xmlData[i] !== '"'; i++) entityName2 += xmlData[i]; if (entityName2 = entityName2.trim(), entityName2.indexOf(" ") !== -1) throw new Error("External entites are not supported"); let startChar = xmlData[i++], val2 = ""; for (; i < xmlData.length && xmlData[i] !== startChar; i++) val2 += xmlData[i]; return [entityName2, val2, i]; } function isComment(xmlData, i) { return xmlData[i + 1] === "!" && xmlData[i + 2] === "-" && xmlData[i + 3] === "-"; } function isEntity(xmlData, i) { return xmlData[i + 1] === "!" && xmlData[i + 2] === "E" && xmlData[i + 3] === "N" && xmlData[i + 4] === "T" && xmlData[i + 5] === "I" && xmlData[i + 6] === "T" && xmlData[i + 7] === "Y"; } function isElement(xmlData, i) { return xmlData[i + 1] === "!" && xmlData[i + 2] === "E" && xmlData[i + 3] === "L" && xmlData[i + 4] === "E" && xmlData[i + 5] === "M" && xmlData[i + 6] === "E" && xmlData[i + 7] === "N" && xmlData[i + 8] === "T"; } function isAttlist(xmlData, i) { return xmlData[i + 1] === "!" && xmlData[i + 2] === "A" && xmlData[i + 3] === "T" && xmlData[i + 4] === "T" && xmlData[i + 5] === "L" && xmlData[i + 6] === "I" && xmlData[i + 7] === "S" && xmlData[i + 8] === "T"; } function isNotation(xmlData, i) { return xmlData[i + 1] === "!" && xmlData[i + 2] === "N" && xmlData[i + 3] === "O" && xmlData[i + 4] === "T" && xmlData[i + 5] === "A" && xmlData[i + 6] === "T" && xmlData[i + 7] === "I" && xmlData[i + 8] === "O" && xmlData[i + 9] === "N"; } function validateEntityName(name) { if (util.isName(name)) return name; throw new Error(`Invalid entity name ${name}`); } module.exports = readDocType; } }); // ../../node_modules/.pnpm/strnum@1.0.5/node_modules/strnum/strnum.js var require_strnum = __commonJS({ "../../node_modules/.pnpm/strnum@1.0.5/node_modules/strnum/strnum.js"(exports, module) { var hexRegex = /^[-+]?0x[a-fA-F0-9]+$/, numRegex = /^([\-\+])?(0*)(\.[0-9]+([eE]\-?[0-9]+)?|[0-9]+(\.[0-9]+([eE]\-?[0-9]+)?)?)$/; !Number.parseInt && window.parseInt && (Number.parseInt = window.parseInt); !Number.parseFloat && window.parseFloat && (Number.parseFloat = window.parseFloat); var consider = { hex: !0, leadingZeros: !0, decimalPoint: ".", eNotation: !0 //skipLike: /regex/ }; function toNumber(str, options = {}) { if (options = Object.assign({}, consider, options), !str || typeof str != "string") return str; let trimmedStr = str.trim(); if (options.skipLike !== void 0 && options.skipLike.test(trimmedStr)) return str; if (options.hex && hexRegex.test(trimmedStr)) return Number.parseInt(trimmedStr, 16); { let match = numRegex.exec(trimmedStr); if (match) { let sign = match[1], leadingZeros = match[2], numTrimmedByZeros = trimZeros(match[3]), eNotation = match[4] || match[6]; if (!options.leadingZeros && leadingZeros.length > 0 && sign && trimmedStr[2] !== ".") return str; if (!options.leadingZeros && leadingZeros.length > 0 && !sign && trimmedStr[1] !== ".") return str; { let num = Number(trimmedStr), numStr = "" + num; return numStr.search(/[eE]/) !== -1 || eNotation ? options.eNotation ? num : str : trimmedStr.indexOf(".") !== -1 ? numStr === "0" && numTrimmedByZeros === "" || numStr === numTrimmedByZeros || sign && numStr === "-" + numTrimmedByZeros ? num : str : leadingZeros ? numTrimmedByZeros === numStr || sign + numTrimmedByZeros === numStr ? num : str : trimmedStr === numStr || trimmedStr === sign + numStr ? num : str; } } else return str; } } function trimZeros(numStr) { return numStr && numStr.indexOf(".") !== -1 && (numStr = numStr.replace(/0+$/, ""), numStr === "." ? numStr = "0" : numStr[0] === "." ? numStr = "0" + numStr : numStr[numStr.length - 1] === "." && (numStr = numStr.substr(0, numStr.length - 1))), numStr; } module.exports = toNumber; } }); // ../../node_modules/.pnpm/fast-xml-parser@4.4.1/node_modules/fast-xml-parser/src/xmlparser/OrderedObjParser.js var require_OrderedObjParser = __commonJS({ "../../node_modules/.pnpm/fast-xml-parser@4.4.1/node_modules/fast-xml-parser/src/xmlparser/OrderedObjParser.js"(exports, module) { "use strict"; var util = require_util(), xmlNode = require_xmlNode(), readDocType = require_DocTypeReader(), toNumber = require_strnum(), OrderedObjParser = class { constructor(options) { this.options = options, this.currentNode = null, this.tagsNodeStack = [], this.docTypeEntities = {}, this.lastEntities = { apos: { regex: /&(apos|#39|#x27);/g, val: "'" }, gt: { regex: /&(gt|#62|#x3E);/g, val: ">" }, lt: { regex: /&(lt|#60|#x3C);/g, val: "<" }, quot: { regex: /&(quot|#34|#x22);/g, val: '"' } }, this.ampEntity = { regex: /&(amp|#38|#x26);/g, val: "&" }, this.htmlEntities = { space: { regex: /&(nbsp|#160);/g, val: " " }, // "lt" : { regex: /&(lt|#60);/g, val: "<" }, // "gt" : { regex: /&(gt|#62);/g, val: ">" }, // "amp" : { regex: /&(amp|#38);/g, val: "&" }, // "quot" : { regex: /&(quot|#34);/g, val: "\"" }, // "apos" : { regex: /&(apos|#39);/g, val: "'" }, cent: { regex: /&(cent|#162);/g, val: "\xA2" }, pound: { regex: /&(pound|#163);/g, val: "\xA3" }, yen: { regex: /&(yen|#165);/g, val: "\xA5" }, euro: { regex: /&(euro|#8364);/g, val: "\u20AC" }, copyright: { regex: /&(copy|#169);/g, val: "\xA9" }, reg: { regex: /&(reg|#174);/g, val: "\xAE" }, inr: { regex: /&(inr|#8377);/g, val: "\u20B9" }, num_dec: { regex: /&#([0-9]{1,7});/g, val: (_, str) => String.fromCharCode(Number.parseInt(str, 10)) }, num_hex: { regex: /&#x([0-9a-fA-F]{1,6});/g, val: (_, str) => String.fromCharCode(Number.parseInt(str, 16)) } }, this.addExternalEntities = addExternalEntities, this.parseXml = parseXml, this.parseTextData = parseTextData, this.resolveNameSpace = resolveNameSpace, this.buildAttributesMap = buildAttributesMap, this.isItStopNode = isItStopNode, this.replaceEntitiesValue = replaceEntitiesValue, this.readStopNodeData = readStopNodeData, this.saveTextToParentTag = saveTextToParentTag, this.addChild = addChild; } }; function addExternalEntities(externalEntities) { let entKeys = Object.keys(externalEntities); for (let i = 0; i < entKeys.length; i++) { let ent = entKeys[i]; this.lastEntities[ent] = { regex: new RegExp("&" + ent + ";", "g"), val: externalEntities[ent] }; } } function parseTextData(val2, tagName, jPath, dontTrim, hasAttributes, isLeafNode, escapeEntities) { if (val2 !== void 0 && (this.options.trimValues && !dontTrim && (val2 = val2.trim()), val2.length > 0)) { escapeEntities || (val2 = this.replaceEntitiesValue(val2)); let newval = this.options.tagValueProcessor(tagName, val2, jPath, hasAttributes, isLeafNode); return newval == null ? val2 : typeof newval != typeof val2 || newval !== val2 ? newval : this.options.trimValues ? parseValue(val2, this.options.parseTagValue, this.options.numberParseOptions) : val2.trim() === val2 ? parseValue(val2, this.options.parseTagValue, this.options.numberParseOptions) : val2; } } function resolveNameSpace(tagname) { if (this.options.removeNSPrefix) { let tags = tagname.split(":"), prefix = tagname.charAt(0) === "/" ? "/" : ""; if (tags[0] === "xmlns") return ""; tags.length === 2 && (tagname = prefix + tags[1]); } return tagname; } var attrsRegx = new RegExp(`([^\\s=]+)\\s*(=\\s*(['"])([\\s\\S]*?)\\3)?`, "gm"); function buildAttributesMap(attrStr, jPath, tagName) { if (!this.options.ignoreAttributes && typeof attrStr == "string") { let matches = util.getAllMatches(attrStr, attrsRegx), len = matches.length, attrs = {}; for (let i = 0; i < len; i++) { let attrName = this.resolveNameSpace(matches[i][1]), oldVal = matches[i][4], aName = this.options.attributeNamePrefix + attrName; if (attrName.length) if (this.options.transformAttributeName && (aName = this.options.transformAttributeName(aName)), aName === "__proto__" && (aName = "#__proto__"), oldVal !== void 0) { this.options.trimValues && (oldVal = oldVal.trim()), oldVal = this.replaceEntitiesValue(oldVal); let newVal = this.options.attributeValueProcessor(attrName, oldVal, jPath); newVal == null ? attrs[aName] = oldVal : typeof newVal != typeof oldVal || newVal !== oldVal ? attrs[aName] = newVal : attrs[aName] = parseValue( oldVal, this.options.parseAttributeValue, this.options.numberParseOptions ); } else this.options.allowBooleanAttributes && (attrs[aName] = !0); } if (!Object.keys(attrs).length) return; if (this.options.attributesGroupName) { let attrCollection = {}; return attrCollection[this.options.attributesGroupName] = attrs, attrCollection; } return attrs; } } var parseXml = function(xmlData) { xmlData = xmlData.replace(/\r\n?/g, ` `); let xmlObj = new xmlNode("!xml"), currentNode = xmlObj, textData = "", jPath = ""; for (let i = 0; i < xmlData.length; i++) if (xmlData[i] === "<") if (xmlData[i + 1] === "/") { let closeIndex = findClosingIndex(xmlData, ">", i, "Closing Tag is not closed."), tagName = xmlData.substring(i + 2, closeIndex).trim(); if (this.options.removeNSPrefix) { let colonIndex = tagName.indexOf(":"); colonIndex !== -1 && (tagName = tagName.substr(colonIndex + 1)); } this.options.transformTagName && (tagName = this.options.transformTagName(tagName)), currentNode && (textData = this.saveTextToParentTag(textData, currentNode, jPath)); let lastTagName = jPath.substring(jPath.lastIndexOf(".") + 1); if (tagName && this.options.unpairedTags.indexOf(tagName) !== -1) throw new Error(`Unpaired tag can not be used as closing tag: </${tagName}>`); let propIndex = 0; lastTagName && this.options.unpairedTags.indexOf(lastTagName) !== -1 ? (propIndex = jPath.lastIndexOf(".", jPath.lastIndexOf(".") - 1), this.tagsNodeStack.pop()) : propIndex = jPath.lastIndexOf("."), jPath = jPath.substring(0, propIndex), currentNode = this.tagsNodeStack.pop(), textData = "", i = closeIndex; } else if (xmlData[i + 1] === "?") { let tagData = readTagExp(xmlData, i, !1, "?>"); if (!tagData) throw new Error("Pi Tag is not closed."); if (textData = this.saveTextToParentTag(textData, currentNode, jPath), !(this.options.ignoreDeclaration && tagData.tagName === "?xml" || this.options.ignorePiTags)) { let childNode = new xmlNode(tagData.tagName); childNode.add(this.options.textNodeName, ""), tagData.tagName !== tagData.tagExp && tagData.attrExpPresent && (childNode[":@"] = this.buildAttributesMap(tagData.tagExp, jPath, tagData.tagName)), this.addChild(currentNode, childNode, jPath); } i = tagData.closeIndex + 1; } else if (xmlData.substr(i + 1, 3) === "!--") { let endIndex = findClosingIndex(xmlData, "-->", i + 4, "Comment is not closed."); if (this.options.commentPropName) { let comment = xmlData.substring(i + 4, endIndex - 2); textData = this.saveTextToParentTag(textData, currentNode, jPath), currentNode.add(this.options.commentPropName, [{ [this.options.textNodeName]: comment }]); } i = endIndex; } else if (xmlData.substr(i + 1, 2) === "!D") { let result = readDocType(xmlData, i); this.docTypeEntities = result.entities, i = result.i; } else if (xmlData.substr(i + 1, 2) === "![") { let closeIndex = findClosingIndex(xmlData, "]]>", i, "CDATA is not closed.") - 2, tagExp = xmlData.substring(i + 9, closeIndex); textData = this.saveTextToParentTag(textData, currentNode, jPath); let val2 = this.parseTextData(tagExp, currentNode.tagname, jPath, !0, !1, !0, !0); val2 == null && (val2 = ""), this.options.cdataPropName ? currentNode.add(this.options.cdataPropName, [{ [this.options.textNodeName]: tagExp }]) : currentNode.add(this.options.textNodeName, val2), i = closeIndex + 2; } else { let result = readTagExp(xmlData, i, this.options.removeNSPrefix), tagName = result.tagName, rawTagName = result.rawTagName, tagExp = result.tagExp, attrExpPresent = result.attrExpPresent, closeIndex = result.closeIndex; this.options.transformTagName && (tagName = this.options.transformTagName(tagName)), currentNode && textData && currentNode.tagname !== "!xml" && (textData = this.saveTextToParentTag(textData, currentNode, jPath, !1)); let lastTag = currentNode; if (lastTag && this.options.unpairedTags.indexOf(lastTag.tagname) !== -1 && (currentNode = this.tagsNodeStack.pop(), jPath = jPath.substring(0, jPath.lastIndexOf("."))), tagName !== xmlObj.tagname && (jPath += jPath ? "." + tagName : tagName), this.isItStopNode(this.options.stopNodes, jPath, tagName)) { let tagContent = ""; if (tagExp.length > 0 && tagExp.lastIndexOf("/") === tagExp.length - 1) tagName[tagName.length - 1] === "/" ? (tagName = tagName.substr(0, tagName.length - 1), jPath = jPath.substr(0, jPath.length - 1), tagExp = tagName) : tagExp = tagExp.substr(0, tagExp.length - 1), i = result.closeIndex; else if (this.options.unpairedTags.indexOf(tagName) !== -1) i = result.closeIndex; else { let result2 = this.readStopNodeData(xmlData, rawTagName, closeIndex + 1); if (!result2) throw new Error(`Unexpected end of ${rawTagName}`); i = result2.i, tagContent = result2.tagContent; } let childNode = new xmlNode(tagName); tagName !== tagExp && attrExpPresent && (childNode[":@"] = this.buildAttributesMap(tagExp, jPath, tagName)), tagContent && (tagContent = this.parseTextData(tagContent, tagName, jPath, !0, attrExpPresent, !0, !0)), jPath = jPath.substr(0, jPath.lastIndexOf(".")), childNode.add(this.options.textNodeName, tagContent), this.addChild(currentNode, childNode, jPath); } else { if (tagExp.length > 0 && tagExp.lastIndexOf("/") === tagExp.length - 1) { tagName[tagName.length - 1] === "/" ? (tagName = tagName.substr(0, tagName.length - 1), jPath = jPath.substr(0, jPath.length - 1), tagExp = tagName) : tagExp = tagExp.substr(0, tagExp.length - 1), this.options.transformTagName && (tagName = this.options.transformTagName(tagName)); let childNode = new xmlNode(tagName); tagName !== tagExp && attrExpPresent && (childNode[":@"] = this.buildAttributesMap(tagExp, jPath, tagName)), this.addChild(currentNode, childNode, jPath), jPath = jPath.substr(0, jPath.lastIndexOf(".")); } else { let childNode = new xmlNode(tagName); this.tagsNodeStack.push(currentNode), tagName !== tagExp && attrExpPresent && (childNode[":@"] = this.buildAttributesMap(tagExp, jPath, tagName)), this.addChild(currentNode, childNode, jPath), currentNode = childNode; } textData = "", i = closeIndex; } } else textData += xmlData[i]; return xmlObj.child; }; function addChild(currentNode, childNode, jPath) { let result = this.options.updateTag(childNode.tagname, jPath, childNode[":@"]); result === !1 || (typeof result == "string" && (childNode.tagname = result), currentNode.addChild(childNode)); } var replaceEntitiesValue = function(val2) { if (this.options.processEntities) { for (let entityName2 in this.docTypeEntities) { let entity = this.docTypeEntities[entityName2]; val2 = val2.replace(entity.regx, entity.val); } for (let entityName2 in this.lastEntities) { let entity = this.lastEntities[entityName2]; val2 = val2.replace(entity.regex, entity.val); } if (this.options.htmlEntities) for (let entityName2 in this.htmlEntities) { let entity = this.htmlEntities[entityName2]; val2 = val2.replace(entity.regex, entity.val); } val2 = val2.replace(this.ampEntity.regex, this.ampEntity.val); } return val2; }; function saveTextToParentTag(textData, currentNode, jPath, isLeafNode) { return textData && (isLeafNode === void 0 && (isLeafNode = Object.keys(currentNode.child).length === 0), textData = this.parseTextData( textData, currentNode.tagname, jPath, !1, currentNode[":@"] ? Object.keys(currentNode[":@"]).length !== 0 : !1, isLeafNode ), textData !== void 0 && textData !== "" && currentNode.add(this.options.textNodeName, textData), textData = ""), textData; } function isItStopNode(stopNodes, jPath, currentTagName) { let allNodesExp = "*." + currentTagName; for (let stopNodePath in stopNodes) { let stopNodeExp = stopNodes[stopNodePath]; if (allNodesExp === stopNodeExp || jPath === stopNodeExp) return !0; } return !1; } function tagExpWithClosingIndex(xmlData, i, closingChar = ">") { let attrBoundary, tagExp = ""; for (let index = i; index < xmlData.length; index++) { let ch = xmlData[index]; if (attrBoundary) ch === attrBoundary && (attrBoundary = ""); else if (ch === '"' || ch === "'") attrBoundary = ch; else if (ch === closingChar[0]) if (closingChar[1]) { if (xmlData[index + 1] === closingChar[1]) return { data: tagExp, index }; } else return { data: tagExp, index }; else ch === " " && (ch = " "); tagExp += ch; } } function findClosingIndex(xmlData, str, i, errMsg) { let closingIndex = xmlData.indexOf(str, i); if (closingIndex === -1) throw new Error(errMsg); return closingIndex + str.length - 1; } function readTagExp(xmlData, i, removeNSPrefix, closingChar = ">") { let result = tagExpWithClosingIndex(xmlData, i + 1, closingChar); if (!result) return; let tagExp = result.data, closeIndex = result.index, separatorIndex = tagExp.search(/\s/), tagName = tagExp, attrExpPresent = !0; separatorIndex !== -1 && (tagName = tagExp.substring(0, separatorIndex), tagExp = tagExp.substring(separatorIndex + 1).trimStart()); let rawTagName = tagName; if (removeNSPrefix) { let colonIndex = tagName.indexOf(":"); colonIndex !== -1 && (tagName = tagName.substr(colonIndex + 1), attrExpPresent = tagName !== result.data.substr(colonIndex + 1)); } return { tagName, tagExp, closeIndex, attrExpPresent, rawTagName }; } function readStopNodeData(xmlData, tagName, i) { let startIndex = i, openTagCount = 1; for (; i < xmlData.length; i++) if (xmlData[i] === "<") if (xmlData[i + 1] === "/") { let closeIndex = findClosingIndex(xmlData, ">", i, `${tagName} is not closed`); if (xmlData.substring(i + 2, closeIndex).trim() === tagName && (openTagCount--, openTagCount === 0)) return { tagContent: xmlData.substring(startIndex, i), i: closeIndex }; i = closeIndex; } else if (xmlData[i + 1] === "?") i = findClosingIndex(xmlData, "?>", i + 1, "StopNode is not closed."); else if (xmlData.substr(i + 1, 3) === "!--") i = findClosingIndex(xmlData, "-->", i + 3, "StopNode is not closed."); else if (xmlData.substr(i + 1, 2) === "![") i = findClosingIndex(xmlData, "]]>", i, "StopNode is not closed.") - 2; else { let tagData = readTagExp(xmlData, i, ">"); tagData && ((tagData && tagData.tagName) === tagName && tagData.tagExp[tagData.tagExp.length - 1] !== "/" && openTagCount++, i = tagData.closeIndex); } } function parseValue(val2, shouldParse, options) { if (shouldParse && typeof val2 == "string") { let newval = val2.trim(); return newval === "true" ? !0 : newval === "false" ? !1 : toNumber(val2, options); } else return util.isExist(val2) ? val2 : ""; } module.exports = OrderedObjParser; } }); // ../../node_modules/.pnpm/fast-xml-parser@4.4.1/node_modules/fast-xml-parser/src/xmlparser/node2json.js var require_node2json = __commonJS({ "../../node_modules/.pnpm/fast-xml-parser@4.4.1/node_modules/fast-xml-parser/src/xmlparser/node2json.js"(exports) { "use strict"; function prettify(node, options) { return compress(node, options); } function compress(arr, options, jPath) { let text, compressedObj = {}; for (let i = 0; i < arr.length; i++) { let tagObj = arr[i], property = propName(tagObj), newJpath = ""; if (jPath === void 0 ? newJpath = property : newJpath = jPath + "." + property, property === options.textNodeName) text === void 0 ? text = tagObj[property] : text += "" + tagObj[property]; else { if (property === void 0) continue; if (tagObj[property]) { let val2 = compress(tagObj[property], options, newJpath), isLeaf = isLeafTag(val2, options); tagObj[":@"] ? assignAttributes(val2, tagObj[":@"], newJpath, options) : Object.keys(val2).length === 1 && val2[options.textNodeName] !== void 0 && !options.alwaysCreateTextNode ? val2 = val2[options.textNodeName] : Object.keys(val2).length === 0 && (options.alwaysCreateTextNode ? val2[options.textNodeName] = "" : val2 = ""), compressedObj[property] !== void 0 && compressedObj.hasOwnProperty(property) ? (Array.isArray(compressedObj[property]) || (compressedObj[property] = [compressedObj[property]]), compressedObj[property].push(val2)) : options.isArray(property, newJpath, isLeaf) ? compressedObj[property] = [val2] : compressedObj[property] = val2; } } } return typeof text == "string" ? text.length > 0 && (compressedObj[options.textNodeName] = text) : text !== void 0 && (compressedObj[options.textNodeName] = text), compressedObj; } function propName(obj) { let keys = Object.keys(obj); for (let i = 0; i < keys.length; i++) { let key = keys[i]; if (key !== ":@") return key; } } function assignAttributes(obj, attrMap, jpath, options) { if (attrMap) { let keys = Object.keys(attrMap), len = keys.length; for (let i = 0; i < len; i++) { let atrrName = keys[i]; options.isArray(atrrName, jpath + "." + atrrName, !0, !0) ? obj[atrrName] = [attrMap[atrrName]] : obj[atrrName] = attrMap[atrrName]; } } } function isLeafTag(obj, options) { let { textNodeName } = options, propCount = Object.keys(obj).length; return !!(propCount === 0 || propCount === 1 && (obj[textNodeName] || typeof obj[textNodeName] == "boolean" || obj[textNodeName] === 0)); } exports.prettify = prettify; } }); // ../../node_modules/.pnpm/fast-xml-parser@4.4.1/node_modules/fast-xml-parser/src/xmlparser/XMLParser.js var require_XMLParser = __commonJS({ "../../node_modules/.pnpm/fast-xml-parser@4.4.1/node_modules/fast-xml-parser/src/xmlparser/XMLParser.js"(exports, module) { var { buildOptions } = require_OptionsBuilder(), OrderedObjParser = require_OrderedObjParser(), { prettify } = require_node2json(), validator = require_validator(), XMLParser2 = class { constructor(options) { this.externalEntities = {}, this.options = buildOptions(options); } /** * Parse XML dats to JS object * @param {string|Buffer} xmlData * @param {boolean|Object} validationOption */ parse(xmlData, validationOption) { if (typeof xmlData != "string") if (xmlData.toString) xmlData = xmlData.toString(); else throw new Error("XML data is accepted in String or Bytes[] form."); if (validationOption) { validationOption === !0 && (validationOption = {}); let result = validator.validate(xmlData, validationOption); if (result !== !0) throw Error(`${result.err.msg}:${result.err.line}:${result.err.col}`); } let orderedObjParser = new OrderedObjParser(this.options); orderedObjParser.addExternalEntities(this.externalEntities); let orderedResult = orderedObjParser.parseXml(xmlData); return this.options.preserveOrder || orderedResult === void 0 ? orderedResult : prettify(orderedResult, this.options); } /** * Add Entity which is not by default supported by this library * @param {string} key * @param {string} value */ addEntity(key, value) { if (value.indexOf("&") !== -1) throw new Error("Entity value can't have '&'"); if (key.indexOf("&") !== -1 || key.indexOf(";") !== -1) throw new Error("An entity must be set without '&' and ';'. Eg. use '#xD' for '&#xD;'"); if (value === "&") throw new Error("An entity with value '&' is not permitted"); this.externalEntities[key] = value; } }; module.exports = XMLParser2; } }); // ../../node_modules/.pnpm/fast-xml-parser@4.4.1/node_modules/fast-xml-parser/src/xmlbuilder/orderedJs2Xml.js var require_orderedJs2Xml = __commonJS({ "../../node_modules/.pnpm/fast-xml-parser@4.4.1/node_modules/fast-xml-parser/src/xmlbuilder/orderedJs2Xml.js"(exports, module) { function toXml(jArray, options) { let indentation = ""; return options.format && options.indentBy.length > 0 && (indentation = ` `), arrToStr(jArray, options, "", indentation); } function arrToStr(arr, options, jPath, indentation) { let xmlStr = "", isPreviousElementTag = !1; for (let i = 0; i < arr.length; i++) { let tagObj = arr[i], tagName = propName(tagObj); if (tagName === void 0) continue; let newJPath = ""; if (jPath.length === 0 ? newJPath = tagName : newJPath = `${jPath}.${tagName}`, tagName === options.textNodeName) { let tagText = tagObj[tagName]; isStopNode(newJPath, options) || (tagText = options.tagValueProcessor(tagName, tagText), tagText = replaceEntitiesValue(tagText, options)), isPreviousElementTag && (xmlStr += indentation), xmlStr += tagText, isPreviousElementTag = !1; continue; } else if (tagName === options.cdataPropName) { isPreviousElementTag && (xmlStr += indentation), xmlStr += `<![CDATA[${tagObj[tagName][0][options.textNodeName]}]]>`, isPreviousElementTag = !1; continue; } else if (tagName === options.commentPropName) { xmlStr += indentation + `<!--${tagObj[tagName][0][options.textNodeName]}-->`, isPreviousElementTag = !0; continue; } else if (tagName[0] === "?") { let attStr2 = attr_to_str(tagObj[":@"], options), tempInd = tagName === "?xml" ? "" : indentation, piTextNodeName = tagObj[tagName][0][options.textNodeName]; piTextNodeName = piTextNodeName.length !== 0 ? " " + piTextNodeName : "", xmlStr += tempInd + `<${tagName}${piTextNodeName}${attStr2}?>`, isPreviousElementTag = !0; continue; } let newIdentation = indentation; newIdentation !== "" && (newIdentation += options.indentBy); let attStr = attr_to_str(tagObj[":@"], options), tagStart = indentation + `<${tagName}${attStr}`, tagValue = arrToStr(tagObj[tagName], options, newJPath, newIdentation); options.unpairedTags.indexOf(tagName) !== -1 ? options.suppressUnpairedNode ? xmlStr += tagStart + ">" : xmlStr += tagStart + "/>" : (!tagValue || tagValue.length === 0) && options.suppressEmptyNode ? xmlStr += tagStart + "/>" : tagValue && tagValue.endsWith(">") ? xmlStr += tagStart + `>${tagValue}${indentation}</${tagName}>` : (xmlStr += tagStart + ">", tagValue && indentation !== "" && (tagValue.includes("/>") || tagValue.includes("</")) ? xmlStr += indentation + options.indentBy + tagValue + indentation : xmlStr += tagValue, xmlStr += `</${tagName}>`), isPreviousElementTag = !0; } return xmlStr; } function propName(obj) { let keys = Object.keys(obj); for (let i = 0; i < keys.length; i++) { let key = keys[i]; if (obj.hasOwnProperty(key) && key !== ":@") return key; } } function attr_to_str(attrMap, options) { let attrStr = ""; if (attrMap && !options.ignoreAttributes) for (let attr in attrMap) { if (!attrMap.hasOwnProperty(attr)) continue; let attrVal = options.attributeValueProcessor(attr, attrMap[attr]); attrVal = replaceEntitiesValue(attrVal, options), attrVal === !0 && options.suppressBooleanAttributes ? attrStr += ` ${attr.substr(options.attributeNamePrefix.length)}` : attrStr += ` ${attr.substr(options.attributeNamePrefix.length)}="${attrVal}"`; } return attrStr; } function isStopNode(jPath, options) { jPath = jPath.substr(0, jPath.length - options.textNodeName.length - 1); let tagName = jPath.substr(jPath.lastIndexOf(".") + 1); for (let index in options.stopNodes) if (options.stopNodes[index] === jPath || options.stopNodes[index] === "*." + tagName) return !0; return !1; } function replaceEntitiesValue(textValue, options) { if (textValue && textValue.length > 0 && options.processEntities) for (let i = 0; i < options.entities.length; i++) { let entity = options.entities[i]; textValue = textValue.replace(entity.regex, entity.val); } return textValue; } module.exports = toXml; } }); // ../../node_modules/.pnpm/fast-xml-parser@4.4.1/node_modules/fast-xml-parser/src/xmlbuilder/json2xml.js var require_json2xml = __commonJS({ "../../node_modules/.pnpm/