UNPKG

node-karin

Version:

Lightweight, efficient, concise, and stable robot framework.

2 lines 164 kB
#!/usr/bin/env node "use strict";const e=require("node:fs"),t=require("node:url"),n=require("node:path"),s=require("node:child_process"),i=require("node:stream/promises"),r=require("fs"),o=require("node:events"),a=require("node:process");var c="undefined"!=typeof document?document.currentScript:null;const l=(e,t={})=>{try{return{status:!0,error:null,stdout:s.execSync(e,t).toString(),stderr:""}}catch(n){return{status:!1,error:n,stdout:"",stderr:""}}},u=(e,t={})=>new Promise((n=>{s.exec(e,t,((e,t,s)=>{n({status:!e,error:e,stdout:t,stderr:s})}))})),h=n.join(process.cwd(),"@karinjs/config/pm2.json"),p=()=>e.existsSync(h)?JSON.parse(e.readFileSync(h,"utf-8")):(console.log(`[pm2] 配置文件不存在 请检查 ${h} 是否存在`),null),d=(e,t=2)=>{if(0===e)return"0 Bytes";const n=Math.floor(Math.log(e)/Math.log(1024));return`${parseFloat((e/Math.pow(1024,n)).toFixed(t))} ${["Bytes","KB","MB","GB","TB"][n]}`},f=async(t,s,r,o)=>{if(!e.existsSync(t))return!1;const a=e.statSync(t),c=1024*o*1024;if(console.log(`[pm2] 检查${r}日志文件: ${t}`),console.log(`[pm2] 当前大小: ${d(a.size)}, 切割阈值: ${d(c)}`),a.size<c)return console.log(`[pm2] ${r}日志文件大小未超过阈值,无需切割\n`),!1;const l=`${n.basename(t)}.${Date.now()}`,u=n.join(s,l);console.log(`\n[pm2] 准备切割${r}日志文件:`),console.log(`[pm2] - 源文件: ${t}`),console.log(`[pm2] - 归档文件名称: ${l}`),console.log(`[pm2] - 归档文件路径: ${u}`);try{const n=e.createReadStream(t),s=e.createWriteStream(u);await i.pipeline(n,s);const o=e.statSync(t).mode,c=a.size,h=Math.max(2097152,Math.floor(c/5));console.log(`[pm2] 将保留${d(h)}内容到新的日志文件中`);const p=Buffer.alloc(h),f=e.openSync(t,"r");return e.readSync(f,p,0,h,c-h),e.closeSync(f),e.writeFileSync(t,p),e.chmodSync(t,o),console.log(`[pm2] 日志已按大小切割: ${r} => ${l}`),console.log(`[pm2] 原始文件大小: ${d(a.size)}, 归档后保留: ${d(h)}`),console.log(`[pm2] 归档文件完整路径: ${u}`),!0}catch(h){return console.error(`[pm2] 切割日志失败: ${r}`,h),!1}},m=async()=>{const t=p();var s;if(t)try{let i=Number(t.maxLogDays)??14,r=Number(t.maxErrorLogSize),o=Number(t.maxOutLogSize);(isNaN(i)||i<0)&&(i=14),(isNaN(r)||r<1)&&(r=50),(isNaN(o)||o<1)&&(o=50),0===i?console.log("[pm2] 日志保留策略: 保留所有日志,不进行清理"):console.log(`[pm2] 日志保留策略: 最长${i}天`);const a=n.resolve(process.cwd(),t.apps[0].error_file),c=n.resolve(process.cwd(),t.apps[0].out_file),l=n.dirname(a);if(s=l,!e.existsSync(s)&&(e.mkdirSync(s,{recursive:!0}),console.log(`[pm2] 创建日志目录: ${s}`),1))return;const u=n.basename(a),h=n.basename(c);await f(c,l,"输出",o),await f(a,l,"错误",r),((t,s,i,r)=>{if(r<=0)return void console.log(`[pm2] 日志保留天数设置为${r},将保留所有日志文件`);const o=e.readdirSync(i),a=(t,s)=>{const a=new RegExp(`^${t.replace(/\./g,"\\.")}\\.(\\d+)$`),c=o.filter((e=>a.test(e))).map((e=>{const t=e.match(a);return{file:e,timestamp:t?parseInt(t[1],10):0}})).sort(((e,t)=>t.timestamp-e.timestamp)),l=Date.now(),u=24*r*60*60*1e3;let h=0;c.forEach((t=>{if(l-t.timestamp>u){const r=n.join(i,t.file);e.unlinkSync(r);const o=new Date(t.timestamp).toISOString().split("T")[0];h++,console.log(`[pm2] 删除过期${s}日志: ${t.file} (${o})`)}})),h>0&&console.log(`[pm2] 共删除${h}个超过${r}天的${s}日志文件`)};a(t,"错误"),a(s,"输出")})(u,h,l,i)}catch(i){console.error("[pm2] 日志切割过程中发生错误:",i)}},g=async()=>{m(),console.log("[pm2] 启动中...");const t=p();t||process.exit(1),(t=>{const n="index.mjs";t.apps[0].script!==n&&(t.apps[0].script=n,e.writeFileSync(h,JSON.stringify(t,null,2)))})(t),e.existsSync("index.mjs")||(console.log("正在升级到1.8.0版本..."),l("npx ki init",{cwd:process.cwd()}),console.log("升级成功 正在启动pm2服务..."));const{error:n}=l(`pm2 start ${h}`,{cwd:process.cwd()});n&&(console.log("[pm2] 启动失败"),console.log(n),process.exit(1)),console.log("[pm2] 启动成功"),console.log("[pm2] 重启服务: pnpm rs"),console.log("[pm2] 查看日志: pnpm log"),console.log("[pm2] 停止服务: pnpm stop"),console.log("[pm2] 查看监控: pm2 monit"),console.log("[pm2] 查看列表: pm2 list"),process.exit(0)},y=async()=>{m();const e=p();e||(console.log("[pm2] 如果是新项目,请先前台启动生成配置文件: pnpm app"),process.exit(1));try{const t="win32"===process.platform?"pm2.cmd":"pm2";s.spawn(t,["logs",e.apps[0].name,"--lines",e.lines||1e3],{stdio:"inherit",shell:!0})}catch(t){console.error("[pm2] 发生未知错误: 请检查pm2是否安装 【npm install -g pm2】"),console.error(t),process.exit(1)}},b=async()=>{m();const e=p();e||(console.log("[pm2] 如果是新项目,请先前台启动生成配置文件: pnpm app"),process.exit(1)),l(`pm2 stop ${e.apps[0].name}`,{cwd:process.cwd()}),console.log("[pm2] 停止成功"),process.exit(0)},w=async t=>{m();try{const n=()=>{const e=p()?.apps?.[0]?.name||"karin";l(`pm2 delete ${e}`,{cwd:process.cwd()}),l(`pm2 start ${h}`,{cwd:process.cwd()}),console.log("[pm2] 重启成功")};console.log("[pm2] 重启中..."),e.existsSync(h)||(console.log(`[pm2] 配置文件不存在 请检查 ${h} 是否存在`),console.log("[pm2] 如果是新项目,请先前台启动生成配置文件: pnpm app"),process.exit(1)),t&&(n(),process.exit(0));const s=p()?.apps?.[0]?.name||"karin";l(`pm2 restart ${s}`,{cwd:process.cwd()}),console.log("[pm2] 重启成功"),process.exit(0)}catch(n){console.log("[pm2] 尝试直接重启失败 尝试删除服务并重新启动");const e=p()?.apps?.[0]?.name||"karin";l(`pm2 delete ${e}`,{cwd:process.cwd()}),l(`pm2 start ${h}`,{cwd:process.cwd()}),console.log("[pm2] 重启成功"),process.exit(0)}},v=Symbol.for("yaml.alias"),k=Symbol.for("yaml.document"),_=Symbol.for("yaml.map"),O=Symbol.for("yaml.pair"),S=Symbol.for("yaml.scalar"),E=Symbol.for("yaml.seq"),A=Symbol.for("yaml.node.type"),C=e=>!!e&&"object"==typeof e&&e[A]===v,x=e=>!!e&&"object"==typeof e&&e[A]===k,N=e=>!!e&&"object"==typeof e&&e[A]===_,T=e=>!!e&&"object"==typeof e&&e[A]===O,$=e=>!!e&&"object"==typeof e&&e[A]===S,I=e=>!!e&&"object"==typeof e&&e[A]===E;function L(e){if(e&&"object"==typeof e)switch(e[A]){case _:case E:return!0}return!1}function j(e){if(e&&"object"==typeof e)switch(e[A]){case v:case _:case S:case E:return!0}return!1}const D=Symbol("break visit"),P=Symbol("skip children"),B=Symbol("remove node");function M(e,t){const n=H(t);if(x(e)){V(null,e.contents,n,Object.freeze([e]))===B&&(e.contents=null)}else V(null,e,n,Object.freeze([]))}function V(e,t,n,s){const i=K(e,t,n,s);if(j(i)||T(i))return U(e,s,i),V(e,i,n,s);if("symbol"!=typeof i)if(L(t)){s=Object.freeze(s.concat(t));for(let e=0;e<t.items.length;++e){const i=V(e,t.items[e],n,s);if("number"==typeof i)e=i-1;else{if(i===D)return D;i===B&&(t.items.splice(e,1),e-=1)}}}else if(T(t)){s=Object.freeze(s.concat(t));const e=V("key",t.key,n,s);if(e===D)return D;e===B&&(t.key=null);const i=V("value",t.value,n,s);if(i===D)return D;i===B&&(t.value=null)}return i}async function F(e,t){const n=H(t);if(x(e)){await q(null,e.contents,n,Object.freeze([e]))===B&&(e.contents=null)}else await q(null,e,n,Object.freeze([]))}async function q(e,t,n,s){const i=await K(e,t,n,s);if(j(i)||T(i))return U(e,s,i),q(e,i,n,s);if("symbol"!=typeof i)if(L(t)){s=Object.freeze(s.concat(t));for(let e=0;e<t.items.length;++e){const i=await q(e,t.items[e],n,s);if("number"==typeof i)e=i-1;else{if(i===D)return D;i===B&&(t.items.splice(e,1),e-=1)}}}else if(T(t)){s=Object.freeze(s.concat(t));const e=await q("key",t.key,n,s);if(e===D)return D;e===B&&(t.key=null);const i=await q("value",t.value,n,s);if(i===D)return D;i===B&&(t.value=null)}return i}function H(e){return"object"==typeof e&&(e.Collection||e.Node||e.Value)?Object.assign({Alias:e.Node,Map:e.Node,Scalar:e.Node,Seq:e.Node},e.Value&&{Map:e.Value,Scalar:e.Value,Seq:e.Value},e.Collection&&{Map:e.Collection,Seq:e.Collection},e):e}function K(e,t,n,s){return"function"==typeof n?n(e,t,s):N(t)?n.Map?.(e,t,s):I(t)?n.Seq?.(e,t,s):T(t)?n.Pair?.(e,t,s):$(t)?n.Scalar?.(e,t,s):C(t)?n.Alias?.(e,t,s):void 0}function U(e,t,n){const s=t[t.length-1];if(L(s))s.items[e]=n;else if(T(s))"key"===e?s.key=n:s.value=n;else{if(!x(s)){const e=C(s)?"alias":"scalar";throw new Error(`Cannot replace node with ${e} parent`)}s.contents=n}}M.BREAK=D,M.SKIP=P,M.REMOVE=B,F.BREAK=D,F.SKIP=P,F.REMOVE=B;const R={"!":"%21",",":"%2C","[":"%5B","]":"%5D","{":"%7B","}":"%7D"};class W{constructor(e,t){this.docStart=null,this.docEnd=!1,this.yaml=Object.assign({},W.defaultYaml,e),this.tags=Object.assign({},W.defaultTags,t)}clone(){const e=new W(this.yaml,this.tags);return e.docStart=this.docStart,e}atDocument(){const e=new W(this.yaml,this.tags);switch(this.yaml.version){case"1.1":this.atNextDocument=!0;break;case"1.2":this.atNextDocument=!1,this.yaml={explicit:W.defaultYaml.explicit,version:"1.2"},this.tags=Object.assign({},W.defaultTags)}return e}add(e,t){this.atNextDocument&&(this.yaml={explicit:W.defaultYaml.explicit,version:"1.1"},this.tags=Object.assign({},W.defaultTags),this.atNextDocument=!1);const n=e.trim().split(/[ \t]+/),s=n.shift();switch(s){case"%TAG":{if(2!==n.length&&(t(0,"%TAG directive should contain exactly two parts"),n.length<2))return!1;const[e,s]=n;return this.tags[e]=s,!0}case"%YAML":{if(this.yaml.explicit=!0,1!==n.length)return t(0,"%YAML directive should contain exactly one part"),!1;const[e]=n;if("1.1"===e||"1.2"===e)return this.yaml.version=e,!0;return t(6,`Unsupported YAML version ${e}`,/^\d+\.\d+$/.test(e)),!1}default:return t(0,`Unknown directive ${s}`,!0),!1}}tagName(e,t){if("!"===e)return"!";if("!"!==e[0])return t(`Not a valid tag: ${e}`),null;if("<"===e[1]){const n=e.slice(2,-1);return"!"===n||"!!"===n?(t(`Verbatim tags aren't resolved, so ${e} is invalid.`),null):(">"!==e[e.length-1]&&t("Verbatim tags must end with a >"),n)}const[,n,s]=e.match(/^(.*!)([^!]*)$/s);s||t(`The ${e} tag has no suffix`);const i=this.tags[n];if(i)try{return i+decodeURIComponent(s)}catch(r){return t(String(r)),null}return"!"===n?e:(t(`Could not resolve tag: ${e}`),null)}tagString(e){for(const[t,n]of Object.entries(this.tags))if(e.startsWith(n))return t+e.substring(n.length).replace(/[!,[\]{}]/g,(e=>R[e]));return"!"===e[0]?e:`!<${e}>`}toString(e){const t=this.yaml.explicit?[`%YAML ${this.yaml.version||"1.2"}`]:[],n=Object.entries(this.tags);let s;if(e&&n.length>0&&j(e.contents)){const t={};M(e.contents,((e,n)=>{j(n)&&n.tag&&(t[n.tag]=!0)})),s=Object.keys(t)}else s=[];for(const[i,r]of n)"!!"===i&&"tag:yaml.org,2002:"===r||e&&!s.some((e=>e.startsWith(r)))||t.push(`%TAG ${i} ${r}`);return t.join("\n")}}function J(e){if(/[\x00-\x19\s,[\]{}]/.test(e)){const t=JSON.stringify(e);throw new Error(`Anchor must not contain whitespace or control characters: ${t}`)}return!0}function G(e){const t=new Set;return M(e,{Value(e,n){n.anchor&&t.add(n.anchor)}}),t}function Y(e,t){for(let n=1;;++n){const s=`${e}${n}`;if(!t.has(s))return s}}function Q(e,t,n,s){if(s&&"object"==typeof s)if(Array.isArray(s))for(let i=0,r=s.length;i<r;++i){const t=s[i],n=Q(e,s,String(i),t);void 0===n?delete s[i]:n!==t&&(s[i]=n)}else if(s instanceof Map)for(const i of Array.from(s.keys())){const t=s.get(i),n=Q(e,s,i,t);void 0===n?s.delete(i):n!==t&&s.set(i,n)}else if(s instanceof Set)for(const i of Array.from(s)){const t=Q(e,s,i,i);void 0===t?s.delete(i):t!==i&&(s.delete(i),s.add(t))}else for(const[i,r]of Object.entries(s)){const t=Q(e,s,i,r);void 0===t?delete s[i]:t!==r&&(s[i]=t)}return e.call(t,n,s)}function X(e,t,n){if(Array.isArray(e))return e.map(((e,t)=>X(e,String(t),n)));if(e&&"function"==typeof e.toJSON){if(!n||(!$(s=e)&&!L(s)||!s.anchor))return e.toJSON(t,n);const i={aliasCount:0,count:1,res:void 0};n.anchors.set(e,i),n.onCreate=e=>{i.res=e,delete n.onCreate};const r=e.toJSON(t,n);return n.onCreate&&n.onCreate(r),r}var s;return"bigint"!=typeof e||n?.keep?e:Number(e)}W.defaultYaml={explicit:!1,version:"1.2"},W.defaultTags={"!!":"tag:yaml.org,2002:"};class z{constructor(e){Object.defineProperty(this,A,{value:e})}clone(){const e=Object.create(Object.getPrototypeOf(this),Object.getOwnPropertyDescriptors(this));return this.range&&(e.range=this.range.slice()),e}toJS(e,{mapAsMap:t,maxAliasCount:n,onAnchor:s,reviver:i}={}){if(!x(e))throw new TypeError("A document argument is required");const r={anchors:new Map,doc:e,keep:!0,mapAsMap:!0===t,mapKeyWarned:!1,maxAliasCount:"number"==typeof n?n:100},o=X(this,"",r);if("function"==typeof s)for(const{count:a,res:c}of r.anchors.values())s(c,a);return"function"==typeof i?Q(i,{"":o},"",o):o}}class Z extends z{constructor(e){super(v),this.source=e,Object.defineProperty(this,"tag",{set(){throw new Error("Alias nodes cannot have tags")}})}resolve(e){let t;return M(e,{Node:(e,n)=>{if(n===this)return M.BREAK;n.anchor===this.source&&(t=n)}}),t}toJSON(e,t){if(!t)return{source:this.source};const{anchors:n,doc:s,maxAliasCount:i}=t,r=this.resolve(s);if(!r){const e=`Unresolved alias (the anchor must be set before the alias): ${this.source}`;throw new ReferenceError(e)}let o=n.get(r);if(o||(X(r,null,t),o=n.get(r)),!o||void 0===o.res){throw new ReferenceError("This should not happen: Alias anchor was not resolved?")}if(i>=0&&(o.count+=1,0===o.aliasCount&&(o.aliasCount=ee(s,r,n)),o.count*o.aliasCount>i)){throw new ReferenceError("Excessive alias count indicates a resource exhaustion attack")}return o.res}toString(e,t,n){const s=`*${this.source}`;if(e){if(J(this.source),e.options.verifyAliasOrder&&!e.anchors.has(this.source)){const e=`Unresolved alias (the anchor must be set before the alias): ${this.source}`;throw new Error(e)}if(e.implicitKey)return`${s} `}return s}}function ee(e,t,n){if(C(t)){const s=t.resolve(e),i=n&&s&&n.get(s);return i?i.count*i.aliasCount:0}if(L(t)){let s=0;for(const i of t.items){const t=ee(e,i,n);t>s&&(s=t)}return s}if(T(t)){const s=ee(e,t.key,n),i=ee(e,t.value,n);return Math.max(s,i)}return 1}const te=e=>!e||"function"!=typeof e&&"object"!=typeof e;class ne extends z{constructor(e){super(S),this.value=e}toJSON(e,t){return t?.keep?this.value:X(this.value,e,t)}toString(){return String(this.value)}}ne.BLOCK_FOLDED="BLOCK_FOLDED",ne.BLOCK_LITERAL="BLOCK_LITERAL",ne.PLAIN="PLAIN",ne.QUOTE_DOUBLE="QUOTE_DOUBLE",ne.QUOTE_SINGLE="QUOTE_SINGLE";function se(e,t,n){if(x(e)&&(e=e.contents),j(e))return e;if(T(e)){const t=n.schema[_].createNode?.(n.schema,null,n);return t.items.push(e),t}(e instanceof String||e instanceof Number||e instanceof Boolean||"undefined"!=typeof BigInt&&e instanceof BigInt)&&(e=e.valueOf());const{aliasDuplicateObjects:s,onAnchor:i,onTagObj:r,schema:o,sourceObjects:a}=n;let c;if(s&&e&&"object"==typeof e){if(c=a.get(e),c)return c.anchor||(c.anchor=i(e)),new Z(c.anchor);c={anchor:null,node:null},a.set(e,c)}t?.startsWith("!!")&&(t="tag:yaml.org,2002:"+t.slice(2));let l=function(e,t,n){if(t){const e=n.filter((e=>e.tag===t)),s=e.find((e=>!e.format))??e[0];if(!s)throw new Error(`Tag ${t} not found`);return s}return n.find((t=>t.identify?.(e)&&!t.format))}(e,t,o.tags);if(!l){if(e&&"function"==typeof e.toJSON&&(e=e.toJSON()),!e||"object"!=typeof e){const t=new ne(e);return c&&(c.node=t),t}l=e instanceof Map?o[_]:Symbol.iterator in Object(e)?o[E]:o[_]}r&&(r(l),delete n.onTagObj);const u=l?.createNode?l.createNode(n.schema,e,n):"function"==typeof l?.nodeClass?.from?l.nodeClass.from(n.schema,e,n):new ne(e);return t?u.tag=t:l.default||(u.tag=l.tag),c&&(c.node=u),u}function ie(e,t,n){let s=n;for(let i=t.length-1;i>=0;--i){const e=t[i];if("number"==typeof e&&Number.isInteger(e)&&e>=0){const t=[];t[e]=s,s=t}else s=new Map([[e,s]])}return se(s,void 0,{aliasDuplicateObjects:!1,keepUndefined:!1,onAnchor:()=>{throw new Error("This should not happen, please report a bug.")},schema:e,sourceObjects:new Map})}const re=e=>null==e||"object"==typeof e&&!!e[Symbol.iterator]().next().done;class oe extends z{constructor(e,t){super(e),Object.defineProperty(this,"schema",{value:t,configurable:!0,enumerable:!1,writable:!0})}clone(e){const t=Object.create(Object.getPrototypeOf(this),Object.getOwnPropertyDescriptors(this));return e&&(t.schema=e),t.items=t.items.map((t=>j(t)||T(t)?t.clone(e):t)),this.range&&(t.range=this.range.slice()),t}addIn(e,t){if(re(e))this.add(t);else{const[n,...s]=e,i=this.get(n,!0);if(L(i))i.addIn(s,t);else{if(void 0!==i||!this.schema)throw new Error(`Expected YAML collection at ${n}. Remaining path: ${s}`);this.set(n,ie(this.schema,s,t))}}}deleteIn(e){const[t,...n]=e;if(0===n.length)return this.delete(t);const s=this.get(t,!0);if(L(s))return s.deleteIn(n);throw new Error(`Expected YAML collection at ${t}. Remaining path: ${n}`)}getIn(e,t){const[n,...s]=e,i=this.get(n,!0);return 0===s.length?!t&&$(i)?i.value:i:L(i)?i.getIn(s,t):void 0}hasAllNullValues(e){return this.items.every((t=>{if(!T(t))return!1;const n=t.value;return null==n||e&&$(n)&&null==n.value&&!n.commentBefore&&!n.comment&&!n.tag}))}hasIn(e){const[t,...n]=e;if(0===n.length)return this.has(t);const s=this.get(t,!0);return!!L(s)&&s.hasIn(n)}setIn(e,t){const[n,...s]=e;if(0===s.length)this.set(n,t);else{const e=this.get(n,!0);if(L(e))e.setIn(s,t);else{if(void 0!==e||!this.schema)throw new Error(`Expected YAML collection at ${n}. Remaining path: ${s}`);this.set(n,ie(this.schema,s,t))}}}}const ae=e=>e.replace(/^(?!$)(?: $)?/gm,"#");function ce(e,t){return/^\n+$/.test(e)?e.substring(1):t?e.replace(/^(?! *$)/gm,t):e}const le=(e,t,n)=>e.endsWith("\n")?ce(n,t):n.includes("\n")?"\n"+ce(n,t):(e.endsWith(" ")?"":" ")+n,ue="flow",he="block",pe="quoted";function de(e,t,n="flow",{indentAtStart:s,lineWidth:i=80,minContentWidth:r=20,onFold:o,onOverflow:a}={}){if(!i||i<0)return e;i<r&&(r=0);const c=Math.max(1+r,1+i-t.length);if(e.length<=c)return e;const l=[],u={};let h,p,d=i-t.length;"number"==typeof s&&(s>i-Math.max(2,r)?l.push(0):d=i-s);let f=!1,m=-1,g=-1,y=-1;n===he&&(m=fe(e,m,t.length),-1!==m&&(d=m+c));for(let w;w=e[m+=1];){if(n===pe&&"\\"===w){switch(g=m,e[m+1]){case"x":m+=3;break;case"u":m+=5;break;case"U":m+=9;break;default:m+=1}y=m}if("\n"===w)n===he&&(m=fe(e,m,t.length)),d=m+t.length+c,h=void 0;else{if(" "===w&&p&&" "!==p&&"\n"!==p&&"\t"!==p){const t=e[m+1];t&&" "!==t&&"\n"!==t&&"\t"!==t&&(h=m)}if(m>=d)if(h)l.push(h),d=h+c,h=void 0;else if(n===pe){for(;" "===p||"\t"===p;)p=w,w=e[m+=1],f=!0;const t=m>y+1?m-2:g-1;if(u[t])return e;l.push(t),u[t]=!0,d=t+c,h=void 0}else f=!0}p=w}if(f&&a&&a(),0===l.length)return e;o&&o();let b=e.slice(0,l[0]);for(let w=0;w<l.length;++w){const s=l[w],i=l[w+1]||e.length;0===s?b=`\n${t}${e.slice(0,i)}`:(n===pe&&u[s]&&(b+=`${e[s]}\\`),b+=`\n${t}${e.slice(s+1,i)}`)}return b}function fe(e,t,n){let s=t,i=t+1,r=e[i];for(;" "===r||"\t"===r;)if(t<i+n)r=e[++t];else{do{r=e[++t]}while(r&&"\n"!==r);s=t,i=t+1,r=e[i]}return s}const me=(e,t)=>({indentAtStart:t?e.indent.length:e.indentAtStart,lineWidth:e.options.lineWidth,minContentWidth:e.options.minContentWidth}),ge=e=>/^(%|---|\.\.\.)/m.test(e);function ye(e,t){const n=JSON.stringify(e);if(t.options.doubleQuotedAsJSON)return n;const{implicitKey:s}=t,i=t.options.doubleQuotedMinMultiLineLength,r=t.indent||(ge(e)?" ":"");let o="",a=0;for(let c=0,l=n[c];l;l=n[++c])if(" "===l&&"\\"===n[c+1]&&"n"===n[c+2]&&(o+=n.slice(a,c)+"\\ ",c+=1,a=c,l="\\"),"\\"===l)switch(n[c+1]){case"u":{o+=n.slice(a,c);const e=n.substr(c+2,4);switch(e){case"0000":o+="\\0";break;case"0007":o+="\\a";break;case"000b":o+="\\v";break;case"001b":o+="\\e";break;case"0085":o+="\\N";break;case"00a0":o+="\\_";break;case"2028":o+="\\L";break;case"2029":o+="\\P";break;default:"00"===e.substr(0,2)?o+="\\x"+e.substr(2):o+=n.substr(c,6)}c+=5,a=c+1}break;case"n":if(s||'"'===n[c+2]||n.length<i)c+=1;else{for(o+=n.slice(a,c)+"\n\n";"\\"===n[c+2]&&"n"===n[c+3]&&'"'!==n[c+4];)o+="\n",c+=2;o+=r," "===n[c+2]&&(o+="\\"),c+=1,a=c+1}break;default:c+=1}return o=a?o+n.slice(a):n,s?o:de(o,r,pe,me(t,!1))}function be(e,t){if(!1===t.options.singleQuote||t.implicitKey&&e.includes("\n")||/[ \t]\n|\n[ \t]/.test(e))return ye(e,t);const n=t.indent||(ge(e)?" ":""),s="'"+e.replace(/'/g,"''").replace(/\n+/g,`$&\n${n}`)+"'";return t.implicitKey?s:de(s,n,ue,me(t,!1))}function we(e,t){const{singleQuote:n}=t.options;let s;if(!1===n)s=ye;else{const t=e.includes('"'),i=e.includes("'");s=t&&!i?be:i&&!t?ye:n?be:ye}return s(e,t)}let ve;try{ve=new RegExp("(^|(?<!\n))\n+(?!\n|$)","g")}catch{ve=/\n+(?!\n|$)/g}function ke({comment:e,type:t,value:n},s,i,r){const{blockQuote:o,commentString:a,lineWidth:c}=s.options;if(!o||/\n[\t ]+$/.test(n)||/^\s*$/.test(n))return we(n,s);const l=s.indent||(s.forceBlockIndent||ge(n)?" ":""),u="literal"===o||"folded"!==o&&t!==ne.BLOCK_FOLDED&&(t===ne.BLOCK_LITERAL||!function(e,t,n){if(!t||t<0)return!1;const s=t-n,i=e.length;if(i<=s)return!1;for(let r=0,o=0;r<i;++r)if("\n"===e[r]){if(r-o>s)return!0;if(o=r+1,i-o<=s)return!1}return!0}(n,c,l.length));if(!n)return u?"|\n":">\n";let h,p;for(p=n.length;p>0;--p){const e=n[p-1];if("\n"!==e&&"\t"!==e&&" "!==e)break}let d=n.substring(p);const f=d.indexOf("\n");-1===f?h="-":n===d||f!==d.length-1?(h="+",r&&r()):h="",d&&(n=n.slice(0,-d.length),"\n"===d[d.length-1]&&(d=d.slice(0,-1)),d=d.replace(ve,`$&${l}`));let m,g=!1,y=-1;for(m=0;m<n.length;++m){const e=n[m];if(" "===e)g=!0;else{if("\n"!==e)break;y=m}}let b=n.substring(0,y<m?y+1:m);b&&(n=n.substring(b.length),b=b.replace(/\n+/g,`$&${l}`));let w=(g?l?"2":"1":"")+h;if(e&&(w+=" "+a(e.replace(/ ?[\r\n]+/g," ")),i&&i()),!u){const e=n.replace(/\n+/g,"\n$&").replace(/(?:^|\n)([\t ].*)(?:([\n\t ]*)\n(?![\n\t ]))?/g,"$1$2").replace(/\n+/g,`$&${l}`);let i=!1;const r=me(s,!0);"folded"!==o&&t!==ne.BLOCK_FOLDED&&(r.onOverflow=()=>{i=!0});const a=de(`${b}${e}${d}`,l,he,r);if(!i)return`>${w}\n${l}${a}`}return`|${w}\n${l}${b}${n=n.replace(/\n+/g,`$&${l}`)}${d}`}function _e(e,t,n,s){const{implicitKey:i,inFlow:r}=t,o="string"==typeof e.value?e:Object.assign({},e,{value:String(e.value)});let{type:a}=e;a!==ne.QUOTE_DOUBLE&&/[\x00-\x08\x0b-\x1f\x7f-\x9f\u{D800}-\u{DFFF}]/u.test(o.value)&&(a=ne.QUOTE_DOUBLE);const c=e=>{switch(e){case ne.BLOCK_FOLDED:case ne.BLOCK_LITERAL:return i||r?we(o.value,t):ke(o,t,n,s);case ne.QUOTE_DOUBLE:return ye(o.value,t);case ne.QUOTE_SINGLE:return be(o.value,t);case ne.PLAIN:return function(e,t,n,s){const{type:i,value:r}=e,{actualString:o,implicitKey:a,indent:c,indentStep:l,inFlow:u}=t;if(a&&r.includes("\n")||u&&/[[\]{},]/.test(r))return we(r,t);if(!r||/^[\n\t ,[\]{}#&*!|>'"%@`]|^[?-]$|^[?-][ \t]|[\n:][ \t]|[ \t]\n|[\n\t ]#|[\n\t :]$/.test(r))return a||u||!r.includes("\n")?we(r,t):ke(e,t,n,s);if(!a&&!u&&i!==ne.PLAIN&&r.includes("\n"))return ke(e,t,n,s);if(ge(r)){if(""===c)return t.forceBlockIndent=!0,ke(e,t,n,s);if(a&&c===l)return we(r,t)}const h=r.replace(/\n+/g,`$&\n${c}`);if(o){const e=e=>e.default&&"tag:yaml.org,2002:str"!==e.tag&&e.test?.test(h),{compat:n,tags:s}=t.doc.schema;if(s.some(e)||n?.some(e))return we(r,t)}return a?h:de(h,c,ue,me(t,!1))}(o,t,n,s);default:return null}};let l=c(a);if(null===l){const{defaultKeyType:e,defaultStringType:n}=t.options,s=i&&e||n;if(l=c(s),null===l)throw new Error(`Unsupported default string type ${s}`)}return l}function Oe(e,t){const n=Object.assign({blockQuote:!0,commentString:ae,defaultKeyType:null,defaultStringType:"PLAIN",directives:null,doubleQuotedAsJSON:!1,doubleQuotedMinMultiLineLength:40,falseStr:"false",flowCollectionPadding:!0,indentSeq:!0,lineWidth:80,minContentWidth:20,nullStr:"null",simpleKeys:!1,singleQuote:null,trueStr:"true",verifyAliasOrder:!0},e.schema.toStringOptions,t);let s;switch(n.collectionStyle){case"block":s=!1;break;case"flow":s=!0;break;default:s=null}return{anchors:new Set,doc:e,flowCollectionPadding:n.flowCollectionPadding?" ":"",indent:"",indentStep:"number"==typeof n.indent?" ".repeat(n.indent):" ",inFlow:s,options:n}}function Se(e,t,n,s){if(T(e))return e.toString(t,n,s);if(C(e)){if(t.doc.directives)return e.toString(t);if(t.resolvedAliases?.has(e))throw new TypeError("Cannot stringify circular structure without alias nodes");t.resolvedAliases?t.resolvedAliases.add(e):t.resolvedAliases=new Set([e]),e=e.resolve(t.doc)}let i;const r=j(e)?e:t.doc.createNode(e,{onTagObj:e=>i=e});i||(i=function(e,t){if(t.tag){const n=e.filter((e=>e.tag===t.tag));if(n.length>0)return n.find((e=>e.format===t.format))??n[0]}let n,s;if($(t)){s=t.value;let i=e.filter((e=>e.identify?.(s)));if(i.length>1){const e=i.filter((e=>e.test));e.length>0&&(i=e)}n=i.find((e=>e.format===t.format))??i.find((e=>!e.format))}else s=t,n=e.find((e=>e.nodeClass&&s instanceof e.nodeClass));if(!n)throw new Error(`Tag not resolved for ${s?.constructor?.name??typeof s} value`);return n}(t.doc.schema.tags,r));const o=function(e,t,{anchors:n,doc:s}){if(!s.directives)return"";const i=[],r=($(e)||L(e))&&e.anchor;r&&J(r)&&(n.add(r),i.push(`&${r}`));const o=e.tag?e.tag:t.default?null:t.tag;return o&&i.push(s.directives.tagString(o)),i.join(" ")}(r,i,t);o.length>0&&(t.indentAtStart=(t.indentAtStart??0)+o.length+1);const a="function"==typeof i.stringify?i.stringify(r,t,n,s):$(r)?_e(r,t,n,s):r.toString(t,n,s);return o?$(r)||"{"===a[0]||"["===a[0]?`${o} ${a}`:`${o}\n${t.indent}${a}`:a}function Ee(e,t){"debug"!==e&&"warn"!==e||console.warn(t)}const Ae="<<",Ce={identify:e=>e===Ae||"symbol"==typeof e&&e.description===Ae,default:"key",tag:"tag:yaml.org,2002:merge",test:/^<<$/,resolve:()=>Object.assign(new ne(Symbol(Ae)),{addToJSMap:xe}),stringify:()=>Ae};function xe(e,t,n){if(n=e&&C(n)?n.resolve(e.doc):n,I(n))for(const s of n.items)Ne(e,t,s);else if(Array.isArray(n))for(const s of n)Ne(e,t,s);else Ne(e,t,n)}function Ne(e,t,n){const s=e&&C(n)?n.resolve(e.doc):n;if(!N(s))throw new Error("Merge sources must be maps or map aliases");const i=s.toJSON(null,e,Map);for(const[r,o]of i)t instanceof Map?t.has(r)||t.set(r,o):t instanceof Set?t.add(r):Object.prototype.hasOwnProperty.call(t,r)||Object.defineProperty(t,r,{value:o,writable:!0,enumerable:!0,configurable:!0});return t}function Te(e,t,{key:n,value:s}){if(j(n)&&n.addToJSMap)n.addToJSMap(e,t,s);else if(((e,t)=>(Ce.identify(t)||$(t)&&(!t.type||t.type===ne.PLAIN)&&Ce.identify(t.value))&&e?.doc.schema.tags.some((e=>e.tag===Ce.tag&&e.default)))(e,n))xe(e,t,s);else{const i=X(n,"",e);if(t instanceof Map)t.set(i,X(s,i,e));else if(t instanceof Set)t.add(i);else{const r=function(e,t,n){if(null===t)return"";if("object"!=typeof t)return String(t);if(j(e)&&n?.doc){const t=Oe(n.doc,{});t.anchors=new Set;for(const e of n.anchors.keys())t.anchors.add(e.anchor);t.inFlow=!0,t.inStringifyKey=!0;const s=e.toString(t);if(!n.mapKeyWarned){let e=JSON.stringify(s);e.length>40&&(e=e.substring(0,36)+'..."'),Ee(n.doc.options.logLevel,`Keys with collection values will be stringified due to JS Object restrictions: ${e}. Set mapAsMap: true to use object keys.`),n.mapKeyWarned=!0}return s}return JSON.stringify(t)}(n,i,e),o=X(s,r,e);r in t?Object.defineProperty(t,r,{value:o,writable:!0,enumerable:!0,configurable:!0}):t[r]=o}}return t}function $e(e,t,n){const s=se(e,void 0,n),i=se(t,void 0,n);return new Ie(s,i)}class Ie{constructor(e,t=null){Object.defineProperty(this,A,{value:O}),this.key=e,this.value=t}clone(e){let{key:t,value:n}=this;return j(t)&&(t=t.clone(e)),j(n)&&(n=n.clone(e)),new Ie(t,n)}toJSON(e,t){return Te(t,t?.mapAsMap?new Map:{},this)}toString(e,t,n){return e?.doc?function({key:e,value:t},n,s,i){const{allNullValues:r,doc:o,indent:a,indentStep:c,options:{commentString:l,indentSeq:u,simpleKeys:h}}=n;let p=j(e)&&e.comment||null;if(h){if(p)throw new Error("With simple keys, key nodes cannot have comments");if(L(e)||!j(e)&&"object"==typeof e)throw new Error("With simple keys, collection cannot be used as a key value")}let d=!h&&(!e||p&&null==t&&!n.inFlow||L(e)||($(e)?e.type===ne.BLOCK_FOLDED||e.type===ne.BLOCK_LITERAL:"object"==typeof e));n=Object.assign({},n,{allNullValues:!1,implicitKey:!d&&(h||!r),indent:a+c});let f,m,g,y=!1,b=!1,w=Se(e,n,(()=>y=!0),(()=>b=!0));if(!d&&!n.inFlow&&w.length>1024){if(h)throw new Error("With simple keys, single line scalar must not span more than 1024 characters");d=!0}if(n.inFlow){if(r||null==t)return y&&s&&s(),""===w?"?":d?`? ${w}`:w}else if(r&&!h||null==t&&d)return w=`? ${w}`,p&&!y?w+=le(w,n.indent,l(p)):b&&i&&i(),w;y&&(p=null),d?(p&&(w+=le(w,n.indent,l(p))),w=`? ${w}\n${a}:`):(w=`${w}:`,p&&(w+=le(w,n.indent,l(p)))),j(t)?(f=!!t.spaceBefore,m=t.commentBefore,g=t.comment):(f=!1,m=null,g=null,t&&"object"==typeof t&&(t=o.createNode(t))),n.implicitKey=!1,d||p||!$(t)||(n.indentAtStart=w.length+1),b=!1,u||!(c.length>=2)||n.inFlow||d||!I(t)||t.flow||t.tag||t.anchor||(n.indent=n.indent.substring(2));let v=!1;const k=Se(t,n,(()=>v=!0),(()=>b=!0));let _=" ";if(p||f||m)_=f?"\n":"",m&&(_+=`\n${ce(l(m),n.indent)}`),""!==k||n.inFlow?_+=`\n${n.indent}`:"\n"===_&&(_="\n\n");else if(!d&&L(t)){const e=k[0],s=k.indexOf("\n"),i=-1!==s,r=n.inFlow??t.flow??0===t.items.length;if(i||!r){let t=!1;if(i&&("&"===e||"!"===e)){let n=k.indexOf(" ");"&"===e&&-1!==n&&n<s&&"!"===k[n+1]&&(n=k.indexOf(" ",n+1)),(-1===n||s<n)&&(t=!0)}t||(_=`\n${n.indent}`)}}else""!==k&&"\n"!==k[0]||(_="");return w+=_+k,n.inFlow?v&&s&&s():g&&!v?w+=le(w,n.indent,l(g)):b&&i&&i(),w}(this,e,t,n):JSON.stringify(this)}}function Le(e,t,n){return(t.inFlow??e.flow?De:je)(e,t,n)}function je({comment:e,items:t},n,{blockItemPrefix:s,flowChars:i,itemIndent:r,onChompKeep:o,onComment:a}){const{indent:c,options:{commentString:l}}=n,u=Object.assign({},n,{indent:r,type:null});let h=!1;const p=[];for(let f=0;f<t.length;++f){const e=t[f];let i=null;if(j(e))!h&&e.spaceBefore&&p.push(""),Pe(n,p,e.commentBefore,h),e.comment&&(i=e.comment);else if(T(e)){const t=j(e.key)?e.key:null;t&&(!h&&t.spaceBefore&&p.push(""),Pe(n,p,t.commentBefore,h))}h=!1;let o=Se(e,u,(()=>i=null),(()=>h=!0));i&&(o+=le(o,r,l(i))),h&&i&&(h=!1),p.push(s+o)}let d;if(0===p.length)d=i.start+i.end;else{d=p[0];for(let e=1;e<p.length;++e){const t=p[e];d+=t?`\n${c}${t}`:"\n"}}return e?(d+="\n"+ce(l(e),c),a&&a()):h&&o&&o(),d}function De({items:e},t,{flowChars:n,itemIndent:s}){const{indent:i,indentStep:r,flowCollectionPadding:o,options:{commentString:a}}=t;s+=r;const c=Object.assign({},t,{indent:s,inFlow:!0,type:null});let l=!1,u=0;const h=[];for(let f=0;f<e.length;++f){const n=e[f];let i=null;if(j(n))n.spaceBefore&&h.push(""),Pe(t,h,n.commentBefore,!1),n.comment&&(i=n.comment);else if(T(n)){const e=j(n.key)?n.key:null;e&&(e.spaceBefore&&h.push(""),Pe(t,h,e.commentBefore,!1),e.comment&&(l=!0));const s=j(n.value)?n.value:null;s?(s.comment&&(i=s.comment),s.commentBefore&&(l=!0)):null==n.value&&e?.comment&&(i=e.comment)}i&&(l=!0);let r=Se(n,c,(()=>i=null));f<e.length-1&&(r+=","),i&&(r+=le(r,s,a(i))),!l&&(h.length>u||r.includes("\n"))&&(l=!0),h.push(r),u=h.length}const{start:p,end:d}=n;if(0===h.length)return p+d;if(!l){const e=h.reduce(((e,t)=>e+t.length+2),2);l=t.options.lineWidth>0&&e>t.options.lineWidth}if(l){let e=p;for(const t of h)e+=t?`\n${r}${i}${t}`:"\n";return`${e}\n${i}${d}`}return`${p}${o}${h.join(" ")}${o}${d}`}function Pe({indent:e,options:{commentString:t}},n,s,i){if(s&&i&&(s=s.replace(/^\n+/,"")),s){const i=ce(t(s),e);n.push(i.trimStart())}}function Be(e,t){const n=$(t)?t.value:t;for(const s of e)if(T(s)){if(s.key===t||s.key===n)return s;if($(s.key)&&s.key.value===n)return s}}class Me extends oe{static get tagName(){return"tag:yaml.org,2002:map"}constructor(e){super(_,e),this.items=[]}static from(e,t,n){const{keepUndefined:s,replacer:i}=n,r=new this(e),o=(e,o)=>{if("function"==typeof i)o=i.call(t,e,o);else if(Array.isArray(i)&&!i.includes(e))return;(void 0!==o||s)&&r.items.push($e(e,o,n))};if(t instanceof Map)for(const[a,c]of t)o(a,c);else if(t&&"object"==typeof t)for(const a of Object.keys(t))o(a,t[a]);return"function"==typeof e.sortMapEntries&&r.items.sort(e.sortMapEntries),r}add(e,t){let n;n=T(e)?e:e&&"object"==typeof e&&"key"in e?new Ie(e.key,e.value):new Ie(e,e?.value);const s=Be(this.items,n.key),i=this.schema?.sortMapEntries;if(s){if(!t)throw new Error(`Key ${n.key} already set`);$(s.value)&&te(n.value)?s.value.value=n.value:s.value=n.value}else if(i){const e=this.items.findIndex((e=>i(n,e)<0));-1===e?this.items.push(n):this.items.splice(e,0,n)}else this.items.push(n)}delete(e){const t=Be(this.items,e);if(!t)return!1;return this.items.splice(this.items.indexOf(t),1).length>0}get(e,t){const n=Be(this.items,e),s=n?.value;return(!t&&$(s)?s.value:s)??void 0}has(e){return!!Be(this.items,e)}set(e,t){this.add(new Ie(e,t),!0)}toJSON(e,t,n){const s=n?new n:t?.mapAsMap?new Map:{};t?.onCreate&&t.onCreate(s);for(const i of this.items)Te(t,s,i);return s}toString(e,t,n){if(!e)return JSON.stringify(this);for(const s of this.items)if(!T(s))throw new Error(`Map items must all be pairs; found ${JSON.stringify(s)} instead`);return!e.allNullValues&&this.hasAllNullValues(!1)&&(e=Object.assign({},e,{allNullValues:!0})),Le(this,e,{blockItemPrefix:"",flowChars:{start:"{",end:"}"},itemIndent:e.indent||"",onChompKeep:n,onComment:t})}}const Ve={collection:"map",default:!0,nodeClass:Me,tag:"tag:yaml.org,2002:map",resolve:(e,t)=>(N(e)||t("Expected a mapping for this tag"),e),createNode:(e,t,n)=>Me.from(e,t,n)};class Fe extends oe{static get tagName(){return"tag:yaml.org,2002:seq"}constructor(e){super(E,e),this.items=[]}add(e){this.items.push(e)}delete(e){const t=qe(e);if("number"!=typeof t)return!1;return this.items.splice(t,1).length>0}get(e,t){const n=qe(e);if("number"!=typeof n)return;const s=this.items[n];return!t&&$(s)?s.value:s}has(e){const t=qe(e);return"number"==typeof t&&t<this.items.length}set(e,t){const n=qe(e);if("number"!=typeof n)throw new Error(`Expected a valid index, not ${e}.`);const s=this.items[n];$(s)&&te(t)?s.value=t:this.items[n]=t}toJSON(e,t){const n=[];t?.onCreate&&t.onCreate(n);let s=0;for(const i of this.items)n.push(X(i,String(s++),t));return n}toString(e,t,n){return e?Le(this,e,{blockItemPrefix:"- ",flowChars:{start:"[",end:"]"},itemIndent:(e.indent||"")+" ",onChompKeep:n,onComment:t}):JSON.stringify(this)}static from(e,t,n){const{replacer:s}=n,i=new this(e);if(t&&Symbol.iterator in Object(t)){let e=0;for(let r of t){if("function"==typeof s){const n=t instanceof Set?r:String(e++);r=s.call(t,n,r)}i.items.push(se(r,void 0,n))}}return i}}function qe(e){let t=$(e)?e.value:e;return t&&"string"==typeof t&&(t=Number(t)),"number"==typeof t&&Number.isInteger(t)&&t>=0?t:null}const He={collection:"seq",default:!0,nodeClass:Fe,tag:"tag:yaml.org,2002:seq",resolve:(e,t)=>(I(e)||t("Expected a sequence for this tag"),e),createNode:(e,t,n)=>Fe.from(e,t,n)},Ke={identify:e=>"string"==typeof e,default:!0,tag:"tag:yaml.org,2002:str",resolve:e=>e,stringify:(e,t,n,s)=>_e(e,t=Object.assign({actualString:!0},t),n,s)},Ue={identify:e=>null==e,createNode:()=>new ne(null),default:!0,tag:"tag:yaml.org,2002:null",test:/^(?:~|[Nn]ull|NULL)?$/,resolve:()=>new ne(null),stringify:({source:e},t)=>"string"==typeof e&&Ue.test.test(e)?e:t.options.nullStr},Re={identify:e=>"boolean"==typeof e,default:!0,tag:"tag:yaml.org,2002:bool",test:/^(?:[Tt]rue|TRUE|[Ff]alse|FALSE)$/,resolve:e=>new ne("t"===e[0]||"T"===e[0]),stringify({source:e,value:t},n){if(e&&Re.test.test(e)){if(t===("t"===e[0]||"T"===e[0]))return e}return t?n.options.trueStr:n.options.falseStr}};function We({format:e,minFractionDigits:t,tag:n,value:s}){if("bigint"==typeof s)return String(s);const i="number"==typeof s?s:Number(s);if(!isFinite(i))return isNaN(i)?".nan":i<0?"-.inf":".inf";let r=JSON.stringify(s);if(!e&&t&&(!n||"tag:yaml.org,2002:float"===n)&&/^\d/.test(r)){let e=r.indexOf(".");e<0&&(e=r.length,r+=".");let n=t-(r.length-e-1);for(;n-- >0;)r+="0"}return r}const Je={identify:e=>"number"==typeof e,default:!0,tag:"tag:yaml.org,2002:float",test:/^(?:[-+]?\.(?:inf|Inf|INF)|\.nan|\.NaN|\.NAN)$/,resolve:e=>"nan"===e.slice(-3).toLowerCase()?NaN:"-"===e[0]?Number.NEGATIVE_INFINITY:Number.POSITIVE_INFINITY,stringify:We},Ge={identify:e=>"number"==typeof e,default:!0,tag:"tag:yaml.org,2002:float",format:"EXP",test:/^[-+]?(?:\.[0-9]+|[0-9]+(?:\.[0-9]*)?)[eE][-+]?[0-9]+$/,resolve:e=>parseFloat(e),stringify(e){const t=Number(e.value);return isFinite(t)?t.toExponential():We(e)}},Ye={identify:e=>"number"==typeof e,default:!0,tag:"tag:yaml.org,2002:float",test:/^[-+]?(?:\.[0-9]+|[0-9]+\.[0-9]*)$/,resolve(e){const t=new ne(parseFloat(e)),n=e.indexOf(".");return-1!==n&&"0"===e[e.length-1]&&(t.minFractionDigits=e.length-n-1),t},stringify:We},Qe=e=>"bigint"==typeof e||Number.isInteger(e),Xe=(e,t,n,{intAsBigInt:s})=>s?BigInt(e):parseInt(e.substring(t),n);function ze(e,t,n){const{value:s}=e;return Qe(s)&&s>=0?n+s.toString(t):We(e)}const Ze={identify:e=>Qe(e)&&e>=0,default:!0,tag:"tag:yaml.org,2002:int",format:"OCT",test:/^0o[0-7]+$/,resolve:(e,t,n)=>Xe(e,2,8,n),stringify:e=>ze(e,8,"0o")},et={identify:Qe,default:!0,tag:"tag:yaml.org,2002:int",test:/^[-+]?[0-9]+$/,resolve:(e,t,n)=>Xe(e,0,10,n),stringify:We},tt={identify:e=>Qe(e)&&e>=0,default:!0,tag:"tag:yaml.org,2002:int",format:"HEX",test:/^0x[0-9a-fA-F]+$/,resolve:(e,t,n)=>Xe(e,2,16,n),stringify:e=>ze(e,16,"0x")},nt=[Ve,He,Ke,Ue,Re,Ze,et,tt,Je,Ge,Ye];function st(e){return"bigint"==typeof e||Number.isInteger(e)}const it=({value:e})=>JSON.stringify(e),rt=[Ve,He].concat([{identify:e=>"string"==typeof e,default:!0,tag:"tag:yaml.org,2002:str",resolve:e=>e,stringify:it},{identify:e=>null==e,createNode:()=>new ne(null),default:!0,tag:"tag:yaml.org,2002:null",test:/^null$/,resolve:()=>null,stringify:it},{identify:e=>"boolean"==typeof e,default:!0,tag:"tag:yaml.org,2002:bool",test:/^true$|^false$/,resolve:e=>"true"===e,stringify:it},{identify:st,default:!0,tag:"tag:yaml.org,2002:int",test:/^-?(?:0|[1-9][0-9]*)$/,resolve:(e,t,{intAsBigInt:n})=>n?BigInt(e):parseInt(e,10),stringify:({value:e})=>st(e)?e.toString():JSON.stringify(e)},{identify:e=>"number"==typeof e,default:!0,tag:"tag:yaml.org,2002:float",test:/^-?(?:0|[1-9][0-9]*)(?:\.[0-9]*)?(?:[eE][-+]?[0-9]+)?$/,resolve:e=>parseFloat(e),stringify:it}],{default:!0,tag:"",test:/^/,resolve:(e,t)=>(t(`Unresolved plain scalar ${JSON.stringify(e)}`),e)}),ot={identify:e=>e instanceof Uint8Array,default:!1,tag:"tag:yaml.org,2002:binary",resolve(e,t){if("function"==typeof atob){const t=atob(e.replace(/[\n\r]/g,"")),n=new Uint8Array(t.length);for(let e=0;e<t.length;++e)n[e]=t.charCodeAt(e);return n}return t("This environment does not support reading binary tags; either Buffer or atob is required"),e},stringify({comment:e,type:t,value:n},s,i,r){const o=n;let a;if("function"!=typeof btoa)throw new Error("This environment does not support writing binary tags; either Buffer or btoa is required");{let e="";for(let t=0;t<o.length;++t)e+=String.fromCharCode(o[t]);a=btoa(e)}if(t||(t=ne.BLOCK_LITERAL),t!==ne.QUOTE_DOUBLE){const e=Math.max(s.options.lineWidth-s.indent.length,s.options.minContentWidth),n=Math.ceil(a.length/e),i=new Array(n);for(let t=0,s=0;t<n;++t,s+=e)i[t]=a.substr(s,e);a=i.join(t===ne.BLOCK_LITERAL?"\n":" ")}return _e({comment:e,type:t,value:a},s,i,r)}};function at(e,t){if(I(e))for(let n=0;n<e.items.length;++n){let s=e.items[n];if(!T(s)){if(N(s)){s.items.length>1&&t("Each pair must have its own sequence indicator");const e=s.items[0]||new Ie(new ne(null));if(s.commentBefore&&(e.key.commentBefore=e.key.commentBefore?`${s.commentBefore}\n${e.key.commentBefore}`:s.commentBefore),s.comment){const t=e.value??e.key;t.comment=t.comment?`${s.comment}\n${t.comment}`:s.comment}s=e}e.items[n]=T(s)?s:new Ie(s)}}else t("Expected a sequence for this tag");return e}function ct(e,t,n){const{replacer:s}=n,i=new Fe(e);i.tag="tag:yaml.org,2002:pairs";let r=0;if(t&&Symbol.iterator in Object(t))for(let o of t){let e,a;if("function"==typeof s&&(o=s.call(t,String(r++),o)),Array.isArray(o)){if(2!==o.length)throw new TypeError(`Expected [key, value] tuple: ${o}`);e=o[0],a=o[1]}else if(o&&o instanceof Object){const t=Object.keys(o);if(1!==t.length)throw new TypeError(`Expected tuple with one key, not ${t.length} keys`);e=t[0],a=o[e]}else e=o;i.items.push($e(e,a,n))}return i}const lt={collection:"seq",default:!1,tag:"tag:yaml.org,2002:pairs",resolve:at,createNode:ct};class ut extends Fe{constructor(){super(),this.add=Me.prototype.add.bind(this),this.delete=Me.prototype.delete.bind(this),this.get=Me.prototype.get.bind(this),this.has=Me.prototype.has.bind(this),this.set=Me.prototype.set.bind(this),this.tag=ut.tag}toJSON(e,t){if(!t)return super.toJSON(e);const n=new Map;t?.onCreate&&t.onCreate(n);for(const s of this.items){let e,i;if(T(s)?(e=X(s.key,"",t),i=X(s.value,e,t)):e=X(s,"",t),n.has(e))throw new Error("Ordered maps must not include duplicate keys");n.set(e,i)}return n}static from(e,t,n){const s=ct(e,t,n),i=new this;return i.items=s.items,i}}ut.tag="tag:yaml.org,2002:omap";const ht={collection:"seq",identify:e=>e instanceof Map,nodeClass:ut,default:!1,tag:"tag:yaml.org,2002:omap",resolve(e,t){const n=at(e,t),s=[];for(const{key:i}of n.items)$(i)&&(s.includes(i.value)?t(`Ordered maps must not include duplicate keys: ${i.value}`):s.push(i.value));return Object.assign(new ut,n)},createNode:(e,t,n)=>ut.from(e,t,n)};function pt({value:e,source:t},n){return t&&(e?dt:ft).test.test(t)?t:e?n.options.trueStr:n.options.falseStr}const dt={identify:e=>!0===e,default:!0,tag:"tag:yaml.org,2002:bool",test:/^(?:Y|y|[Yy]es|YES|[Tt]rue|TRUE|[Oo]n|ON)$/,resolve:()=>new ne(!0),stringify:pt},ft={identify:e=>!1===e,default:!0,tag:"tag:yaml.org,2002:bool",test:/^(?:N|n|[Nn]o|NO|[Ff]alse|FALSE|[Oo]ff|OFF)$/,resolve:()=>new ne(!1),stringify:pt},mt={identify:e=>"number"==typeof e,default:!0,tag:"tag:yaml.org,2002:float",test:/^(?:[-+]?\.(?:inf|Inf|INF)|\.nan|\.NaN|\.NAN)$/,resolve:e=>"nan"===e.slice(-3).toLowerCase()?NaN:"-"===e[0]?Number.NEGATIVE_INFINITY:Number.POSITIVE_INFINITY,stringify:We},gt={identify:e=>"number"==typeof e,default:!0,tag:"tag:yaml.org,2002:float",format:"EXP",test:/^[-+]?(?:[0-9][0-9_]*)?(?:\.[0-9_]*)?[eE][-+]?[0-9]+$/,resolve:e=>parseFloat(e.replace(/_/g,"")),stringify(e){const t=Number(e.value);return isFinite(t)?t.toExponential():We(e)}},yt={identify:e=>"number"==typeof e,default:!0,tag:"tag:yaml.org,2002:float",test:/^[-+]?(?:[0-9][0-9_]*)?\.[0-9_]*$/,resolve(e){const t=new ne(parseFloat(e.replace(/_/g,""))),n=e.indexOf(".");if(-1!==n){const s=e.substring(n+1).replace(/_/g,"");"0"===s[s.length-1]&&(t.minFractionDigits=s.length)}return t},stringify:We},bt=e=>"bigint"==typeof e||Number.isInteger(e);function wt(e,t,n,{intAsBigInt:s}){const i=e[0];if("-"!==i&&"+"!==i||(t+=1),e=e.substring(t).replace(/_/g,""),s){switch(n){case 2:e=`0b${e}`;break;case 8:e=`0o${e}`;break;case 16:e=`0x${e}`}const t=BigInt(e);return"-"===i?BigInt(-1)*t:t}const r=parseInt(e,n);return"-"===i?-1*r:r}function vt(e,t,n){const{value:s}=e;if(bt(s)){const e=s.toString(t);return s<0?"-"+n+e.substr(1):n+e}return We(e)}const kt={identify:bt,default:!0,tag:"tag:yaml.org,2002:int",format:"BIN",test:/^[-+]?0b[0-1_]+$/,resolve:(e,t,n)=>wt(e,2,2,n),stringify:e=>vt(e,2,"0b")},_t={identify:bt,default:!0,tag:"tag:yaml.org,2002:int",format:"OCT",test:/^[-+]?0[0-7_]+$/,resolve:(e,t,n)=>wt(e,1,8,n),stringify:e=>vt(e,8,"0")},Ot={identify:bt,default:!0,tag:"tag:yaml.org,2002:int",test:/^[-+]?[0-9][0-9_]*$/,resolve:(e,t,n)=>wt(e,0,10,n),stringify:We},St={identify:bt,default:!0,tag:"tag:yaml.org,2002:int",format:"HEX",test:/^[-+]?0x[0-9a-fA-F_]+$/,resolve:(e,t,n)=>wt(e,2,16,n),stringify:e=>vt(e,16,"0x")};class Et extends Me{constructor(e){super(e),this.tag=Et.tag}add(e){let t;t=T(e)?e:e&&"object"==typeof e&&"key"in e&&"value"in e&&null===e.value?new Ie(e.key,null):new Ie(e,null);Be(this.items,t.key)||this.items.push(t)}get(e,t){const n=Be(this.items,e);return!t&&T(n)?$(n.key)?n.key.value:n.key:n}set(e,t){if("boolean"!=typeof t)throw new Error("Expected boolean value for set(key, value) in a YAML set, not "+typeof t);const n=Be(this.items,e);n&&!t?this.items.splice(this.items.indexOf(n),1):!n&&t&&this.items.push(new Ie(e))}toJSON(e,t){return super.toJSON(e,t,Set)}toString(e,t,n){if(!e)return JSON.stringify(this);if(this.hasAllNullValues(!0))return super.toString(Object.assign({},e,{allNullValues:!0}),t,n);throw new Error("Set items must all have null values")}static from(e,t,n){const{replacer:s}=n,i=new this(e);if(t&&Symbol.iterator in Object(t))for(let r of t)"function"==typeof s&&(r=s.call(t,r,r)),i.items.push($e(r,null,n));return i}}Et.tag="tag:yaml.org,2002:set";const At={collection:"map",identify:e=>e instanceof Set,nodeClass:Et,default:!1,tag:"tag:yaml.org,2002:set",createNode:(e,t,n)=>Et.from(e,t,n),resolve(e,t){if(N(e)){if(e.hasAllNullValues(!0))return Object.assign(new Et,e);t("Set items must all have null values")}else t("Expected a mapping for this tag");return e}};function Ct(e,t){const n=e[0],s="-"===n||"+"===n?e.substring(1):e,i=e=>t?BigInt(e):Number(e),r=s.replace(/_/g,"").split(":").reduce(((e,t)=>e*i(60)+i(t)),i(0));return"-"===n?i(-1)*r:r}function xt(e){let{value:t}=e,n=e=>e;if("bigint"==typeof t)n=e=>BigInt(e);else if(isNaN(t)||!isFinite(t))return We(e);let s="";t<0&&(s="-",t*=n(-1));const i=n(60),r=[t%i];return t<60?r.unshift(0):(t=(t-r[0])/i,r.unshift(t%i),t>=60&&(t=(t-r[0])/i,r.unshift(t))),s+r.map((e=>String(e).padStart(2,"0"))).join(":").replace(/000000\d*$/,"")}const Nt={identify:e=>"bigint"==typeof e||Number.isInteger(e),default:!0,tag:"tag:yaml.org,2002:int",format:"TIME",test:/^[-+]?[0-9][0-9_]*(?::[0-5]?[0-9])+$/,resolve:(e,t,{intAsBigInt:n})=>Ct(e,n),stringify:xt},Tt={identify:e=>"number"==typeof e,default:!0,tag:"tag:yaml.org,2002:float",format:"TIME",test:/^[-+]?[0-9][0-9_]*(?::[0-5]?[0-9])+\.[0-9_]*$/,resolve:e=>Ct(e,!1),stringify:xt},$t={identify:e=>e instanceof Date,default:!0,tag:"tag:yaml.org,2002:timestamp",test:RegExp("^([0-9]{4})-([0-9]{1,2})-([0-9]{1,2})(?:(?:t|T|[ \\t]+)([0-9]{1,2}):([0-9]{1,2}):([0-9]{1,2}(\\.[0-9]+)?)(?:[ \\t]*(Z|[-+][012]?[0-9](?::[0-9]{2})?))?)?$"),resolve(e){const t=e.match($t.test);if(!t)throw new Error("!!timestamp expects a date, starting with yyyy-mm-dd");const[,n,s,i,r,o,a]=t.map(Number),c=t[7]?Number((t[7]+"00").substr(1,3)):0;let l=Date.UTC(n,s-1,i,r||0,o||0,a||0,c);const u=t[8];if(u&&"Z"!==u){let e=Ct(u,!1);Math.abs(e)<30&&(e*=60),l-=6e4*e}return new Date(l)},stringify:({value:e})=>e.toISOString().replace(/(T00:00:00)?\.000Z$/,"")},It=[Ve,He,Ke,Ue,dt,ft,kt,_t,Ot,St,mt,gt,yt,ot,Ce,ht,lt,At,Nt,Tt,$t],Lt=new Map([["core",nt],["failsafe",[Ve,He,Ke]],["json",rt],["yaml11",It],["yaml-1.1",It]]),jt={binary:ot,bool:Re,float:Ye,floatExp:Ge,floatNaN:Je,floatTime:Tt,int:et,intHex:tt,intOct:Ze,intTime:Nt,map:Ve,merge:Ce,null:Ue,omap:ht,pairs:lt,seq:He,set:At,timestamp:$t},Dt={"tag:yaml.org,2002:binary":ot,"tag:yaml.org,2002:merge":Ce,"tag:yaml.org,2002:omap":ht,"tag:yaml.org,2002:pairs":lt,"tag:yaml.org,2002:set":At,"tag:yaml.org,2002:timestamp":$t};function Pt(e,t,n){const s=Lt.get(t);if(s&&!e)return n&&!s.includes(Ce)?s.concat(Ce):s.slice();let i=s;if(!i){if(!Array.isArray(e)){const e=Array.from(Lt.keys()).filter((e=>"yaml11"!==e)).map((e=>JSON.stringify(e))).join(", ");throw new Error(`Unknown schema "${t}"; use one of ${e} or define customTags array`)}i=[]}if(Array.isArray(e))for(const r of e)i=i.concat(r);else"function"==typeof e&&(i=e(i.slice()));return n&&(i=i.concat(Ce)),i.reduce(((e,t)=>{const n="string"==typeof t?jt[t]:t;if(!n){const e=JSON.stringify(t),n=Object.keys(jt).map((e=>JSON.stringify(e))).join(", ");throw new Error(`Unknown custom tag ${e}; use one of ${n}`)}return e.includes(n)||e.push(n),e}),[])}const Bt=(e,t)=>e.key<t.key?-1:e.key>t.key?1:0;class Mt{constructor({compat:e,customTags:t,merge:n,resolveKnownTags:s,schema:i,sortMapEntries:r,toStringDefaults:o}){this.compat=Array.isArray(e)?Pt(e,"compat"):e?Pt(null,e):null,this.name="string"==typeof i&&i||"core",this.knownTags=s?Dt:{},this.tags=Pt(t,this.name,n),this.toStringOptions=o??null,Object.defineProperty(this,_,{value:Ve}),Object.defineProperty(this,S,{value:Ke}),Object.defineProperty(this,E,{value:He}),this.sortMapEntries="function"==typeof r?r:!0===r?Bt:null}clone(){const e=Object.create(Mt.prototype,Object.getOwnPropertyDescriptors(this));return e.tags=this.tags.slice(),e}}class Vt{constructor(e,t,n){this.commentBefore=null,this.comment=null,this.errors=[],this.warnings=[],Object.defineProperty(this,A,{value:k});let s=null;"function"==typeof t||Array.isArray(t)?s=t:void 0===n&&t&&(n=t,t=void 0);const i=Object.assign({intAsBigInt:!1,keepSourceTokens:!1,logLevel:"warn",prettyErrors:!0,strict:!0,stringKeys:!1,uniqueKeys:!0,version:"1.2"},n);this.options=i;let{version:r}=i;n?._directives?(this.directives=n._directives.atDocument(),this.directives.yaml.explicit&&(r=this.directives.yaml.version)):this.directives=new W({version:r}),this.setSchema(r,n),this.contents=void 0===e?null:this.createNode(e,s,n)}clone(){const e=Object.create(Vt.prototype,{[A]:{value:k}});return e.commentBefore=this.commentBefore,e.comment=this.comment,e.errors=this.errors.slice(),e.warnings=this.warnings.slice(),e.options=Object.assign({},this.options),this.directives&&(e.directives=this.directives.clone()),e.schema=this.schema.clone(),e.contents=j(this.contents)?this.contents.clone(e.schema):this.contents,this.range&&(e.range=this.range.slice()),e}add(e){Ft(this.contents)&&this.contents.add(e)}addIn(e,t){Ft(this.contents)&&this.contents.addIn(e,t)}createAlias(e,t){if(!e.anchor){const n=G(this);e.anchor=!t||n.has(t)?Y(t||"a",n):t}return new Z(e.anchor)}createNode(e,t,n){let s;if("function"==typeof t)e=t.call({"":e},"",e),s=t;else if(Array.isArray(t)){const e=e=>"number"==typeof e||e instanceof String||e instanceof Number,n=t.filter(e).map(String);n.length>0&&(t=t.concat(n)),s=t}else void 0===n&&t&&(n=t,t=void 0);const{aliasDuplicateObjects:i,anchorPrefix:r,flow:o,keepUndefined:a,onTagObj:c,tag:l}=n??{},{onAnchor:u,setAnchors:h,sourceObjects:p}=function(e,t){const n=[],s=new Map;let i=null;return{onAnchor:s=>{n.push(s),i||(i=G(e));const r=Y(t,i);return i.add(r),r},setAnchors:()=>{for(const e of n){const t=s.get(e);if("object"!=typeof t||!t.anchor||!$(t.node)&&!L(t.node)){const t=new Error("Failed to resolve repeated object (this should not happen)");throw t.source=e,t}t.node.anchor=t.anchor}},sourceObjects:s}}(this,r||"a"),d=se(e,l,{aliasDuplicateObjects:i??!0,keepUndefined:a??!1,onAnchor:u,onTagObj:c,replacer:s,schema:this.schema,sourceObjects:p});return o&&L(d)&&(d.flow=!0),h(),d}createPair(e,t,n={}){const s=this.createNode(e,null,n),i=this.createNode(t,null,n);return new Ie(s,i)}delete(e){return!!Ft(this.contents)&&this.contents.delete(e)}deleteIn(e){return re(e)?null!=this.contents&&(this.contents=null,!0):!!Ft(this.contents)&&this.contents.deleteIn(e)}get(e,t){return L(this.contents)?this.contents.get(e,t):void 0}getIn(e,t){return re(e)?!t&&$(this.contents)?this.contents.value:this.contents:L(this.contents)?this.contents.getIn(e,t):void 0}has(e){return!!L(this.contents)&&this.contents.has(e)}hasIn(e){return re(e)?void 0!==this.contents:!!L(this.contents)&&this.contents.hasIn(e)}set(e,t){null==this.contents?this.contents=ie(this.schema,[e],t):Ft(this.contents)&&this.contents.set(e,t)}setIn(e,t){re(e)?this.contents=t:null==this.contents?this.content