@homedev/objector 1.2.67 → 1.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.ts CHANGED
@@ -1,5 +1,3 @@
1
- import { NavigateResult as NavigateResult_2 } from '@homedev/navigate';
2
-
3
1
  /**
4
2
  * @public
5
3
  */
@@ -50,7 +48,7 @@ export declare interface FieldContext {
50
48
  path: string;
51
49
  root: any;
52
50
  options: ProcessFieldsOptions;
53
- value: string | object | number | NavigateResult_2 | null;
51
+ value: string | object | number | NavigateResult | null;
54
52
  key: string;
55
53
  args: any[];
56
54
  rawArgs: {
package/dist/index.js CHANGED
@@ -1,23 +1,24 @@
1
- var Yr=Object.create;var Fe=Object.defineProperty;var Gr=Object.getOwnPropertyDescriptor;var Se=(e,t)=>{return Object.defineProperty(e,"name",{value:t,enumerable:!1,configurable:!0}),e};var De=(e,t)=>(t=Symbol[e])?t:Symbol.for("Symbol."+e),Y=(e)=>{throw TypeError(e)},Tr=(e,t,r)=>(t in e)?Fe(e,t,{enumerable:!0,configurable:!0,writable:!0,value:r}):e[t]=r;var pe=(e,t,r)=>t.has(e)||Y("Cannot "+r),Vr=(e,t)=>Object(t)!==t?Y('Cannot use the "in" operator on this value'):e.has(t),ke=(e,t,r)=>(pe(e,t,"read from private field"),r?r.call(e):t.get(e));var Me=(e,t,r,n)=>(pe(e,t,"write to private field"),n?n.call(e,r):t.set(e,r),r),Xr=(e,t,r)=>(pe(e,t,"access private method"),r),Re=(e)=>[,,,Yr(e?.[De("metadata")]??null)],$e=["class","method","getter","setter","accessor","field","value","get","set"],K=(e)=>e!==void 0&&typeof e!=="function"?Y("Function expected"):e,Hr=(e,t,r,n,o)=>({kind:$e[e],name:t,metadata:n,addInitializer:(s)=>r._?Y("Already initialized"):o.push(K(s||null))}),ge=(e,t)=>Tr(t,De("metadata"),e[3]),Ce=(e,t,r,n)=>{for(var o=0,s=e[t>>1],l=s&&s.length;o<l;o++)t&1?s[o].call(r):n=s[o].call(r,n);return n},c=(e,t,r,n,o,s)=>{var l,a,u,b,w,m=t&7,g=!!(t&8),d=!!(t&16),E=m>3?e.length+1:m?g?1:2:0,y=$e[m+5],j=m>3&&(e[E-1]=[]),h=e[E]||(e[E]=[]),k=m&&(!d&&!g&&(o=o.prototype),m<5&&(m>3||!d)&&Gr(m<4?o:{get[r](){return ke(this,s)},set[r](S){Me(this,s,S)}},r));m?d&&m<4&&Se(s,(m>2?"set ":m>1?"get ":"")+r):Se(o,r);for(var O=n.length-1;O>=0;O--){if(b=Hr(m,r,u={},e[3],h),m){if(b.static=g,b.private=d,w=b.access={has:d?(S)=>Vr(o,S):(S)=>(r in S)},m^3)w.get=d?(S)=>(m^1?ke:Xr)(S,o,m^4?s:k.get):(S)=>S[r];if(m>2)w.set=d?(S,M)=>Me(S,o,M,m^4?s:k.set):(S,M)=>S[r]=M}if(a=(0,n[O])(m?m<4?d?s:k[y]:m>4?void 0:{get:k.get,set:k.set}:o,b),u._=1,m^4||a===void 0)K(a)&&(m>4?j.unshift(a):m?d?s=a:k[y]=a:o=a);else if(typeof a!=="object"||a===null)Y("Object expected");else K(l=a.get)&&(k.get=l),K(l=a.set)&&(k.set=l),K(l=a.init)&&j.unshift(l)}return m||ge(e,o),k&&Fe(o,r,k),d?m^4?s:k:o};var Qr=Object.create,{getPrototypeOf:zr,defineProperty:xe,getOwnPropertyNames:Zr}=Object,Pr=Object.prototype.hasOwnProperty,Jr=(e,t,r)=>{r=e!=null?Qr(zr(e)):{};let n=t||!e||!e.__esModule?xe(r,"default",{value:e,enumerable:!0}):r;for(let o of Zr(e))if(!Pr.call(n,o))xe(n,o,{get:()=>e[o],enumerable:!0});return n},en=(e,t)=>()=>(t||e((t={exports:{}}).exports,t),t.exports),tn=en((e,t)=>{var{defineProperty:r,getOwnPropertyNames:n,getOwnPropertyDescriptor:o}=Object,s=Object.prototype.hasOwnProperty,l=new WeakMap,a=(g)=>{var d=l.get(g),E;if(d)return d;if(d=r({},"__esModule",{value:!0}),g&&typeof g==="object"||typeof g==="function")n(g).map((y)=>!s.call(d,y)&&r(d,y,{get:()=>g[y],enumerable:!(E=o(g,y))||E.enumerable}));return l.set(g,d),d},u=(g,d)=>{for(var E in d)r(g,E,{get:d[E],enumerable:!0,configurable:!0,set:(y)=>d[E]=()=>y})},b={};u(b,{splitWithQuotes:()=>m,splitNested:()=>w}),t.exports=a(b);var w=(g,d,E="(",y=")")=>{let j=0,h="",k=[];for(let O of g){if(h+=O,O===E)j++;if(O===y)j--;if(j===0&&O===d)k.push(h.slice(0,-1)),h=""}if(h)k.push(h);return k},m=(g,d=",")=>{let E=[],y=g.length,j=d.length,h=0,k=(O)=>{if(O+j>y)return!1;for(let S=0;S<j;S++)if(g[O+S]!==d[S])return!1;return!0};while(h<y){while(h<y&&g[h]===" ")h++;if(h>=y)break;let O="",S=g[h]==='"'||g[h]==="'";if(S){let M=g[h++];while(h<y&&g[h]!==M)O+=g[h++];if(h<y)h++}else{while(h<y&&!k(h)){let M=g[h];if(M==='"'||M==="'"){O+=M,h++;while(h<y&&g[h]!==M)O+=g[h++];if(h<y)O+=g[h++]}else O+=g[h++]}O=O.trim()}if(O)E.push({value:O,quoted:S});if(k(h))h+=j}return E}}),rn=Jr(tn(),1),I;((e)=>{e[e.Explore=0]="Explore",e[e.SkipSiblings=1]="SkipSiblings",e[e.NoExplore=2]="NoExplore",e[e.ReplaceParent=3]="ReplaceParent",e[e.DeleteParent=4]="DeleteParent",e[e.MergeParent=5]="MergeParent",e[e.ReplaceItem=6]="ReplaceItem",e[e.DeleteItem=7]="DeleteItem"})(I||={});class F{action;by;skipSiblings;reexplore;constructor(e,t,r,n){this.action=e,this.by=t,this.skipSiblings=r,this.reexplore=n}static _explore=new F(0);static _noExplore=new F(2);static _skipSiblings=new F(1);static _deleteParent=new F(4);static ReplaceParent(e,t){return new F(3,e,void 0,t)}static SkipSiblings(){return F._skipSiblings}static Explore(){return F._explore}static NoExplore(){return F._noExplore}static DeleteParent(){return F._deleteParent}static MergeParent(e){return new F(5,e)}static ReplaceItem(e,t){return new F(6,e,t)}static DeleteItem(e){return new F(7,void 0,e)}}var nn=async(e,t)=>{let r=new WeakSet,n=[],o=[],s=async(a,u,b)=>{let w=a===null,m=w?F.Explore():await t({key:a,value:u,path:n,parent:b,parents:o});if(u&&typeof u==="object"&&m.action===0){if(r.has(u))return m;if(r.add(u),!w)n.push(a),o.push(b);let g=u;while(await l(g,a,b))g=b[a];if(!w)o.pop(),n.pop()}return m},l=async(a,u,b)=>{let w=Object.keys(a),m=w.length;for(let g=0;g<m;g++){let d=w[g],E=a[d],y=await s(d,E,a),j=y.action;if(j===0||j===2)continue;if(j===6){if(a[d]=y.by,y.skipSiblings)return;continue}if(j===7){if(delete a[d],y.skipSiblings)return;continue}if(j===1)return;if(j===3){if(u===null)throw Error("Cannot replace root object");if(b[u]=y.by,y.reexplore)return!0;return}if(j===4){if(u===null)throw Error("Cannot delete root object");delete b[u];return}if(j===5)delete a[d],Object.assign(a,y.by)}};await s(null,e,null)},on=Object.create,{getPrototypeOf:sn,defineProperty:Ne,getOwnPropertyNames:an}=Object,ln=Object.prototype.hasOwnProperty,un=(e,t,r)=>{r=e!=null?on(sn(e)):{};let n=t||!e||!e.__esModule?Ne(r,"default",{value:e,enumerable:!0}):r;for(let o of an(e))if(!ln.call(n,o))Ne(n,o,{get:()=>e[o],enumerable:!0});return n},cn=(e,t)=>()=>(t||e((t={exports:{}}).exports,t),t.exports),fn=cn((e,t)=>{var{defineProperty:r,getOwnPropertyNames:n,getOwnPropertyDescriptor:o}=Object,s=Object.prototype.hasOwnProperty,l=new WeakMap,a=(g)=>{var d=l.get(g),E;if(d)return d;if(d=r({},"__esModule",{value:!0}),g&&typeof g==="object"||typeof g==="function")n(g).map((y)=>!s.call(d,y)&&r(d,y,{get:()=>g[y],enumerable:!(E=o(g,y))||E.enumerable}));return l.set(g,d),d},u=(g,d)=>{for(var E in d)r(g,E,{get:d[E],enumerable:!0,configurable:!0,set:(y)=>d[E]=()=>y})},b={};u(b,{splitWithQuotes:()=>m,splitNested:()=>w}),t.exports=a(b);var w=(g,d,E="(",y=")")=>{let j=0,h="",k=[];for(let O of g){if(h+=O,O===E)j++;if(O===y)j--;if(j===0&&O===d)k.push(h.slice(0,-1)),h=""}if(h)k.push(h);return k},m=(g,d=",")=>{let E=[],y=g.length,j=d.length,h=0,k=(O)=>{if(O+j>y)return!1;for(let S=0;S<j;S++)if(g[O+S]!==d[S])return!1;return!0};while(h<y){while(h<y&&g[h]===" ")h++;if(h>=y)break;let O="",S=g[h]==='"'||g[h]==="'";if(S){let M=g[h++];while(h<y&&g[h]!==M)O+=g[h++];if(h<y)h++}else{while(h<y&&!k(h)){let M=g[h];if(M==='"'||M==="'"){O+=M,h++;while(h<y&&g[h]!==M)O+=g[h++];if(h<y)O+=g[h++]}else O+=g[h++]}O=O.trim()}if(O)E.push({value:O,quoted:S});if(k(h))h+=j}return E}}),pn=un(fn(),1),gn=/^\[([^=\]]*)([=]*)([^\]]*)\]$/,mn=/^([^[\]]*)\[([^\]]*)]$/,me=(e,t,r,n)=>{if(e.startsWith("{")&&e.endsWith("}")){let o=e.substring(1,e.length-1);return G(t,o,r)?.toString()}return n?e:void 0},yn=(e,t,r,n)=>{let o=me(t,r,n);if(o)return G(e,o,n);let s=gn.exec(t);if(s){let[,a,u,b]=s,w=me(a.trim(),r,n,!0),m=me(b.trim(),r,n,!0);if(Array.isArray(e)&&(u==="="||u==="==")&&w)return e.find((g)=>g?.[w]==m)}let l=mn.exec(t);if(l){let[,a,u]=l;return e?.[a]?.[u]}return e?.[t]},G=(e,t,r)=>{let n=void 0,o=void 0,s=t??"",l=(m)=>{if(!m)return[m,!1];return m.endsWith("?")?[m.substring(0,m.length-1),!0]:[m,!1]},a=(m,g)=>{let[d,E]=l(g.pop());if(!d){if(r?.set!==void 0&&o!==void 0&&n!==void 0)n[o]=r.set;return m}let y=yn(m,d,e,r);if(y===void 0){if(E||r?.optional||r?.defaultValue!==void 0)return;throw Error(`Unknown path element: "${d}" in "${s}"`)}return n=m,o=d,a(y,g)},u=pn.splitNested(s,r?.separator??".","{","}"),b=void 0;if(u.length>0&&u[u.length-1].startsWith("?="))b=u.pop()?.substring(2);u.reverse();let w=a(e,u);if(w===void 0)return b??r?.defaultValue;return w},We=(e,t)=>{if(typeof e.value==="string"){if(e.quoted)return e.value;if(e.value.startsWith("[")&&e.value.endsWith("]")){let r=e.value.slice(1,-1);if(r.trim()==="")return[];return r.split(";").map((n)=>{let o=n.trim();if(!isNaN(+o))return+o;return o})}if(e.value.startsWith("{")&&e.value.endsWith("}")){if(e.value.slice(1,-1).trim()==="")return{}}if(e.value==="null")return null;if(e.value==="undefined")return;if(e.value.startsWith("@"))return e.value.slice(1);if(!isNaN(+e.value))return+e.value}return t(e.value)},ne=(e,t,r,n,o,s)=>{let l=n?.(e)??e,a=o(l);if(a[0])return a[1];if(!t){let u=G(r,e),b=o(u);if(b[0])return b[1]}throw Error(s)},Le=(e,t,r,n,o)=>{let s=typeof e.types==="function"?e.types(n,t.value,o):e.types?.[n];if(!s||s==="ref")return We(t,(a)=>G(r,a));let l=We(t,()=>t.value);if(Array.isArray(s)){if(!s.includes(l))throw Error(`Argument ${n.toString()} must be one of [${s.join(", ")}]: ${l}`);return l}if(typeof s==="string"){if(s.endsWith("?")){let a=s.slice(0,-1);if(t.value==="null")return F.ReplaceItem(null);if(t.value==="undefined")return F.ReplaceItem(void 0);if(t.value==="")return"";s=a}switch(s){case"any":return l;case"array":return ne(l,t.quoted,r,null,(a)=>[Array.isArray(a),a],`Argument ${n.toString()} must be an array: ${l}`);case"object":return ne(l,t.quoted,r,null,(a)=>[typeof a==="object"&&a!==null,a],`Argument ${n.toString()} must be an object: ${l}`);case"number":return ne(l,t.quoted,r,(a)=>Number(a),(a)=>[!isNaN(a),a],`Argument ${n.toString()} must be a number: ${l}`);case"boolean":return ne(l,t.quoted,r,null,(a)=>{if([!0,"true","1",1,"yes","on"].includes(a))return[!0,!0];if([!1,"false","0",0,"no","off"].includes(a))return[!0,!1];if([null,"null","undefined",void 0,""].includes(a))return[!0,!1];if(Array.isArray(a))return[!0,a.length>0];return[!1,!1]},`Argument ${n.toString()} must be a boolean: ${l}`);case"string":return l.toString();default:throw Error(`Unknown type for argument ${n.toString()}: ${s}`)}}return s(l,r,n,t.quoted)},_e=(e,t)=>{let r=e?.[t];if(r===void 0)throw Error(`Unhandled field processor type: ${t}`);return typeof r==="function"?{options:{},fn:r}:{options:r,fn:r.fn}},Ue=(e)=>!e.quoted&&e.value.startsWith("."),dn=(e)=>{let t={};for(let r of e){if(!Ue(r))continue;let n=r.value.indexOf("="),o=n>-1?r.value.slice(1,n):r.value.slice(1),s=n>-1?r.value.slice(n+1):"";if(s.length>=2){let l=s[0],a=s[s.length-1];if(l==='"'&&a==='"'||l==="'"&&a==="'")s=s.slice(1,-1)}if(!t[o])t[o]=[];t[o].push(s)}return t},hn=(e,t,r)=>{let n=rn.splitWithQuotes(e??""),o=dn(n),s=n.filter((a)=>!Ue(a)),l=t.options.processArgs===!1?[]:s.map((a,u)=>Le(t.options,a,r,u,s));return{rawArgs:s,parsedArgs:l,tags:o}},bn=(e)=>{return e!==null&&typeof e==="object"&&"action"in e},wn=(e,t)=>t.keys!==void 0&&e.key.startsWith(".")&&t.keys[e.key.substring(1)]!==void 0,On=async(e,t,r,n)=>{let{key:o,parent:s}=e,l=_e(n.keys,o.substring(1));if(l.options.processArgs!==!1&&(typeof l.options.types==="function"||l.options.types?.[0]!==void 0))e.value=Le(l.options,{value:e.value,quoted:!1},r,0,[]);if(typeof e.value!=="string")await R(e.value,{...n,root:{...r,parent:e.parent,parents:e.parents},filters:[...n.filters??[],...l.options.filters??[]]});let a=await l.fn({path:t,root:r,parent:s,key:o,options:n,value:e.value,args:[],rawArgs:[],tags:{}});return bn(a)?a:F.ReplaceParent(a)},Ie=(e)=>{let t=e.split(/\r?\n/),r=t.filter((o)=>o.trim().length>0).map((o)=>/^[ \t]*/.exec(o)?.[0].length??0),n=r.length>0?Math.min(...r):0;if(n===0)return e;return t.map((o)=>o.slice(n)).join(`
2
- `)},An=async(e,t,r,n)=>{if(!t?.onSection&&!t?.onSectionConfig&&!t?.sections)return[e,!1];let o=/<@\s*section(?:\s*:\s*([\w-]+))?\s*@>([\s\S]*?)<@\s*\/\s*section\s*@>/g,s,l=e,a=0,u=!1,b={content:l,root:n,path:r,options:t,section:{}};while((s=o.exec(e))!==null){u=!0;let[w,m,g]=s,d=s.index,E=d+w.length,y=e[E]===`
3
- `;if(y)E++;let j=d+a,h=E+a,k={},O=g,S=/(^|\r?\n)[ \t]*---[ \t]*(\r?\n|$)/m.exec(g);if(S){let B=g.slice(0,S.index),ce=S.index+S[0].length;O=g.slice(ce);let te=Ie(B).trim();if(te.length>0)try{k=t?.configParser?.(te)??{}}catch(fe){throw Error(`Failed to parse YAML config for section: ${fe.message}`)}}else if(/^\r?\n/.test(O))O=O.replace(/^\r?\n/,"");O=Ie(O),O=O.replace(/(?:\r?\n[ \t]*)+$/,""),O=O.replace(/[ \t]+$/,"");let M={config:m?{...k,type:m}:k,content:O};if(b.content=l,b.section=M,Object.keys(M.config).length>0){if(await t.onSectionConfig?.(b)!==!1)await R(M.config,{...t,root:n})}let Z=b.section.config.type?t.sections?.[b.section.config.type]:void 0,W;if(Z)W=await Z(b);else if(t.onSection)W=await t.onSection(b);if(M.trim)M.content=M.content.trim();if(M.indent)M.content=M.content.split(`
4
- `).map((B)=>" ".repeat(M.indent)+B).join(`
5
- `);let C="";if(W===!0||M.show)C=M.content;else if(typeof W==="string")C=W;if(y&&C!==""&&!C.endsWith(`
1
+ var Lr=Object.create;var Fe=Object.defineProperty;var Wr=Object.getOwnPropertyDescriptor;var ve=(e,t)=>{return Object.defineProperty(e,"name",{value:t,enumerable:!1,configurable:!0}),e};var Pe=(e,t)=>(t=Symbol[e])?t:Symbol.for("Symbol."+e),K=(e)=>{throw TypeError(e)},Br=(e,t,r)=>(t in e)?Fe(e,t,{enumerable:!0,configurable:!0,writable:!0,value:r}):e[t]=r;var fe=(e,t,r)=>t.has(e)||K("Cannot "+r),qr=(e,t)=>Object(t)!==t?K('Cannot use the "in" operator on this value'):e.has(t),Ee=(e,t,r)=>(fe(e,t,"read from private field"),r?r.call(e):t.get(e));var ke=(e,t,r,n)=>(fe(e,t,"write to private field"),n?n.call(e,r):t.set(e,r),r),Kr=(e,t,r)=>(fe(e,t,"access private method"),r),$e=(e)=>[,,,Lr(e?.[Pe("metadata")]??null)],Me=["class","method","getter","setter","accessor","field","value","get","set"],q=(e)=>e!==void 0&&typeof e!=="function"?K("Function expected"):e,Jr=(e,t,r,n,o)=>({kind:Me[e],name:t,metadata:n,addInitializer:(s)=>r._?K("Already initialized"):o.push(q(s||null))}),pe=(e,t)=>Br(t,Pe("metadata"),e[3]),Re=(e,t,r,n)=>{for(var o=0,s=e[t>>1],l=s&&s.length;o<l;o++)t&1?s[o].call(r):n=s[o].call(r,n);return n},c=(e,t,r,n,o,s)=>{var l,a,u,m,y,g=t&7,O=!!(t&8),b=!!(t&16),k=g>3?e.length+1:g?O?1:2:0,w=Me[g+5],A=g>3&&(e[k-1]=[]),M=e[k]||(e[k]=[]),v=g&&(!b&&!O&&(o=o.prototype),g<5&&(g>3||!b)&&Wr(g<4?o:{get[r](){return Ee(this,s)},set[r](E){ke(this,s,E)}},r));g?b&&g<4&&ve(s,(g>2?"set ":g>1?"get ":"")+r):ve(o,r);for(var P=n.length-1;P>=0;P--){if(m=Jr(g,r,u={},e[3],M),g){if(m.static=O,m.private=b,y=m.access={has:b?(E)=>qr(o,E):(E)=>(r in E)},g^3)y.get=b?(E)=>(g^1?Ee:Kr)(E,o,g^4?s:v.get):(E)=>E[r];if(g>2)y.set=b?(E,F)=>ke(E,o,F,g^4?s:v.set):(E,F)=>E[r]=F}if(a=(0,n[P])(g?g<4?b?s:v[w]:g>4?void 0:{get:v.get,set:v.set}:o,m),u._=1,g^4||a===void 0)q(a)&&(g>4?A.unshift(a):g?b?s=a:v[w]=a:o=a);else if(typeof a!=="object"||a===null)K("Object expected");else q(l=a.get)&&(v.get=l),q(l=a.set)&&(v.set=l),q(l=a.init)&&A.unshift(l)}return g||pe(e,o),v&&Fe(o,r,v),b?g^4?s:v:o};Array.prototype.findOrFail=function(e,t,r){let n=this.find(e,r);if(n===void 0)throw Error(t??"Element not found");return n};Array.flat=function(e){if(Array.isArray(e))return e.flat(2);else return[e]};Array.prototype.forEachAsync=async function(e){for(let t=0;t<this.length;t++)await e(this[t],t,this)};Array.prototype.groupBy=function(e){return this.reduce((t,r)=>{let n=e(r);if(!t[n])t[n]=[];return t[n].push(r),t},{})};Array.prototype.createInstances=function(e,...t){return this.map((r,n)=>new e(...t,r,n))};Array.prototype.mapAsync=async function(e){return Promise.all(this.map(e))};Array.prototype.nonNullMap=function(e){let t=[];for(let r=0;r<this.length;r++){let n=e(this[r],r,this);if(n!=null)t.push(n)}return t};Array.prototype.nonNullMapAsync=async function(e){let t=[];for(let r=0;r<this.length;r++){let n=await e(this[r],r,this);if(n!=null)t.push(n)}return t};Array.prototype.mergeAll=function(e){let t={};for(let r of this.toReversed())Object.merge(r,t,e);return t};Array.prototype.toObject=function(e,t){return Object.fromEntries(this.map((r)=>{let n=e(r),o=t?t(r):r;return[n,o]}))};Array.prototype.toObjectWithKey=function(e){return Object.fromEntries(this.map((t)=>[String(t[e]),t]))};Array.prototype.selectFor=function(e,t,r,n){let o=this.find(e,n);if(o===void 0)throw Error(r??"Element not found");return t(o)};Array.prototype.sortBy=function(e,t=!0){return this.slice().sort((r,n)=>{let o=e(r),s=e(n);if(o<s)return t?-1:1;if(o>s)return t?1:-1;return 0})};Array.prototype.unique=function(){return Array.from(new Set(this))};Array.prototype.uniqueBy=function(e){let t=new Set;return this.filter((r)=>{let n=e(r);if(t.has(n))return!1;else return t.add(n),!0})};var I;((e)=>{e[e.Explore=0]="Explore",e[e.SkipSiblings=1]="SkipSiblings",e[e.NoExplore=2]="NoExplore",e[e.ReplaceParent=3]="ReplaceParent",e[e.DeleteParent=4]="DeleteParent",e[e.MergeParent=5]="MergeParent",e[e.ReplaceItem=6]="ReplaceItem",e[e.DeleteItem=7]="DeleteItem"})(I||={});class j{action;by;skipSiblings;reexplore;constructor(e,t,r,n){this.action=e,this.by=t,this.skipSiblings=r,this.reexplore=n}static _explore=new j(0);static _noExplore=new j(2);static _skipSiblings=new j(1);static _deleteParent=new j(4);static ReplaceParent(e,t){return new j(3,e,void 0,t)}static SkipSiblings(){return j._skipSiblings}static Explore(){return j._explore}static NoExplore(){return j._noExplore}static DeleteParent(){return j._deleteParent}static MergeParent(e){return new j(5,e)}static ReplaceItem(e,t){return new j(6,e,t)}static DeleteItem(e){return new j(7,void 0,e)}}Object.navigate=async(e,t)=>{let r=new WeakSet,n=[],o=[],s=async(a,u,m)=>{let y=a===null,g=y?j.Explore():await t({key:a,value:u,path:n,parent:m,parents:o});if(u&&typeof u==="object"&&g.action===0){if(r.has(u))return g;if(r.add(u),!y)n.push(a),o.push(m);let O=u;while(await l(O,a,m))O=m[a];if(!y)o.pop(),n.pop()}return g},l=async(a,u,m)=>{let y=Object.keys(a),g=y.length;for(let O=0;O<g;O++){let b=y[O],k=a[b],w=await s(b,k,a),A=w.action;if(A===0||A===2)continue;if(A===6){if(a[b]=w.by,w.skipSiblings)return;continue}if(A===7){if(delete a[b],w.skipSiblings)return;continue}if(A===1)return;if(A===3){if(u===null)throw Error("Cannot replace root object");if(m[u]=w.by,w.reexplore)return!0;return}if(A===4){if(u===null)throw Error("Cannot delete root object");delete m[u];return}if(A===5)delete a[b],Object.assign(a,w.by)}};await s(null,e,null)};Object.find=async function(e,t){let r=[];return await Object.navigate(e,(n)=>{if(t([...n.path,n.key].join("."),n.value))r.push(n.value);return j.Explore()}),r};Object.merge=(e,t,r)=>{for(let n of Object.keys(t)){if(e[n]===void 0)continue;let o=t[n],s=e[n];if(typeof s!==typeof o||Array.isArray(s)!==Array.isArray(o)){let a=r?.mismatch?.(n,s,o,e,t);if(a!==void 0){t[n]=a;continue}throw Error(`Type mismatch: ${n}`)}let l=r?.mode?.(n,s,o,e,t)??t[".merge"]??"merge";switch(l){case"source":t[n]=s;continue;case"target":continue;case"skip":delete t[n],delete e[n];continue;case"merge":break;default:throw Error(`Unknown merge mode: ${l}`)}if(typeof s==="object")if(Array.isArray(s))o.push(...s);else{if(r?.navigate?.(n,s,o,e,t)===!1)continue;Object.merge(s,o,r)}else{if(s===o)continue;let a=r?.conflict?.(n,s,o,e,t);t[n]=a===void 0?o:a}}for(let n of Object.keys(e))if(t[n]===void 0)t[n]=e[n]};var Yr=/^\[([^=\]]*)([=]*)([^\]]*)\]$/,Tr=/^([^[\]]*)\[([^\]]*)]$/,ge=(e,t,r,n)=>{if(e.startsWith("{")&&e.endsWith("}")){let o=e.substring(1,e.length-1);return Object.select(t,o,r)?.toString()}return n?e:void 0},Vr=(e,t,r,n)=>{let o=ge(t,r,n);if(o)return Object.select(e,o,n);let s=Yr.exec(t);if(s){let[,a,u,m]=s,y=ge(a.trim(),r,n,!0),g=ge(m.trim(),r,n,!0);if(Array.isArray(e)&&(u==="="||u==="==")&&y)return e.find((O)=>O?.[y]==g)}let l=Tr.exec(t);if(l){let[,a,u]=l;return e?.[a]?.[u]}return e?.[t]};Object.select=(e,t,r)=>{let n=void 0,o=void 0,s=t??"",l=(g)=>{if(!g)return[g,!1];return g.endsWith("?")?[g.substring(0,g.length-1),!0]:[g,!1]},a=(g,O)=>{let[b,k]=l(O.pop());if(!b){if(r?.set!==void 0&&o!==void 0&&n!==void 0)n[o]=r.set;return g}let w=Vr(g,b,e,r);if(w===void 0){if(k||r?.optional||r?.defaultValue!==void 0)return;throw Error(`Unknown path element: "${b}" in "${s}"`)}return n=g,o=b,a(w,O)},u=s.splitNested(r?.separator??".","{","}"),m=void 0;if(u.length>0&&u[u.length-1].startsWith("?="))m=u.pop()?.substring(2);u.reverse();let y=a(e,u);if(y===void 0)return m??r?.defaultValue;return y};Object.deepClone=function(e){if(typeof structuredClone<"u")try{return structuredClone(e)}catch{}return JSON.parse(JSON.stringify(e))};Object.toList=function(e,t){return Object.entries(e).map(([r,n])=>({[t]:r,...n}))};Object.mapEntries=function(e,t){let r=Object.entries(e).map(([n,o])=>t(n,o));return Object.fromEntries(r)};global.AsyncFunction=Object.getPrototypeOf(async function(){}).constructor;global.defined=(e,t="Value is undefined")=>{if(e===void 0||e===null)throw Error(t);return e};String.prototype.tokenize=function(e,t=/\${([^}]+)}/g){return this.replace(t,(r,n)=>{let o=e[n];if(o===null||o===void 0)return"";if(typeof o==="string")return o;if(typeof o==="number"||typeof o==="boolean")return String(o);return String(o)})};String.prototype.toPascal=function(){return this.replace(/((?:[_ ]+)\w|^\w)/g,(e,t)=>t.toUpperCase()).replace(/[_ ]/g,"")};String.prototype.capitalize=function(){return this.replace(/((?:[ ]+)\w|^\w)/g,(e,t)=>t.toUpperCase())};String.prototype.toCamel=function(){return this.toPascal().replace(/((?:[ ]+\w)|^\w)/g,(e,t)=>t.toLowerCase())};String.prototype.toSnake=function(){return this.replace(/([a-z])([A-Z])/g,"$1_$2").replace(/\s+/g,"_")};String.prototype.toKebab=function(){return this.replace(/([a-z])([A-Z])/g,"$1-$2").replace(/\s+/g,"-")};String.prototype.changeCase=function(e){switch(e){case"upper":return this.toUpperCase();case"lower":return this.toLowerCase();case"pascal":return this.toPascal();case"camel":return this.toCamel();case"snake":return this.toSnake();case"kebab":return this.toKebab();default:throw Error(`Unsupported case type: ${e}`)}};String.prototype.splitWithQuotes=function(e=","){let t=[],r=this.length,n=e.length,o=0,s=(l)=>{if(l+n>r)return!1;for(let a=0;a<n;a++)if(this[l+a]!==e[a])return!1;return!0};while(o<r){while(o<r&&this[o]===" ")o++;if(o>=r)break;let l="",a=this[o]==='"'||this[o]==="'";if(a){let u=this[o++];while(o<r&&this[o]!==u)l+=this[o++];if(o<r)o++}else{while(o<r&&!s(o)){let u=this[o];if(u==='"'||u==="'"){l+=u,o++;while(o<r&&this[o]!==u)l+=this[o++];if(o<r)l+=this[o++]}else l+=this[o++]}l=l.trim()}if(l)t.push({value:l,quoted:a});if(s(o))o+=n}return t};String.prototype.splitNested=function(e,t,r){let n=0,o="",s=[];for(let l of this){if(o+=l,l===t)n++;if(l===r)n--;if(n===0&&l===e)s.push(o.slice(0,-1)),o=""}if(o)s.push(o);return s};String.prototype.padBlock=function(e,t=`
2
+ `,r=" "){let n=r.repeat(e);return this.split(t).map((o)=>n+o).join(t)};String.prototype.stripIndent=function(){let e=this.split(/\r?\n/),t=e.filter((n)=>n.trim().length>0).map((n)=>/^[ \t]*/.exec(n)?.[0].length??0),r=t.length>0?Math.min(...t):0;if(r===0)return this;return e.map((n)=>n.slice(r)).join(`
3
+ `)};var Ce=(e,t)=>{if(typeof e.value==="string"){if(e.quoted)return e.value;if(e.value.startsWith("[")&&e.value.endsWith("]")){let r=e.value.slice(1,-1);if(r.trim()==="")return[];return r.split(";").map((n)=>{let o=n.trim();if(!isNaN(+o))return+o;return o})}if(e.value.startsWith("{")&&e.value.endsWith("}")){if(e.value.slice(1,-1).trim()==="")return{}}if(e.value==="null")return null;if(e.value==="undefined")return;if(e.value.startsWith("@"))return e.value.slice(1);if(!isNaN(+e.value))return+e.value}return t(e.value)},re=(e,t,r,n,o,s)=>{let l=n?.(e)??e,a=o(l);if(a[0])return a[1];if(!t){let u=Object.select(r,e),m=o(u);if(m[0])return m[1]}throw Error(s)},De=(e,t,r,n,o)=>{let s=typeof e.types==="function"?e.types(n,t.value,o):e.types?.[n];if(!s||s==="ref")return Ce(t,(a)=>Object.select(r,a));let l=Ce(t,()=>t.value);if(Array.isArray(s)){if(!s.includes(l))throw Error(`Argument ${n.toString()} must be one of [${s.join(", ")}]: ${l}`);return l}if(typeof s==="string"){if(s.endsWith("?")){let a=s.slice(0,-1);if(t.value==="null")return j.ReplaceItem(null);if(t.value==="undefined")return j.ReplaceItem(void 0);if(t.value==="")return"";s=a}switch(s){case"any":return l;case"array":return re(l,t.quoted,r,null,(a)=>[Array.isArray(a),a],`Argument ${n.toString()} must be an array: ${l}`);case"object":return re(l,t.quoted,r,null,(a)=>[typeof a==="object"&&a!==null,a],`Argument ${n.toString()} must be an object: ${l}`);case"number":return re(l,t.quoted,r,(a)=>Number(a),(a)=>[!isNaN(a),a],`Argument ${n.toString()} must be a number: ${l}`);case"boolean":return re(l,t.quoted,r,null,(a)=>{if([!0,"true","1",1,"yes","on"].includes(a))return[!0,!0];if([!1,"false","0",0,"no","off"].includes(a))return[!0,!1];if([null,"null","undefined",void 0,""].includes(a))return[!0,!1];if(Array.isArray(a))return[!0,a.length>0];return[!1,!1]},`Argument ${n.toString()} must be a boolean: ${l}`);case"string":return l.toString();default:throw Error(`Unknown type for argument ${n.toString()}: ${s}`)}}return s(l,r,n,t.quoted)},Ne=(e,t)=>{let r=e?.[t];if(r===void 0)throw Error(`Unhandled field processor type: ${t}`);return typeof r==="function"?{options:{},fn:r}:{options:r,fn:r.fn}},xe=(e)=>!e.quoted&&e.value.startsWith("."),zr=(e)=>{let t={};for(let r of e){if(!xe(r))continue;let n=r.value.indexOf("="),o=n>-1?r.value.slice(1,n):r.value.slice(1),s=n>-1?r.value.slice(n+1):"";if(s.length>=2){let l=s[0],a=s[s.length-1];if(l==='"'&&a==='"'||l==="'"&&a==="'")s=s.slice(1,-1)}if(!t[o])t[o]=[];t[o].push(s)}return t},Hr=(e,t,r)=>{let n=(e??"").splitWithQuotes(),o=zr(n),s=n.filter((a)=>!xe(a)),l=t.options.processArgs===!1?[]:s.map((a,u)=>De(t.options,a,r,u,s));return{rawArgs:s,parsedArgs:l,tags:o}},Gr=(e)=>{return e!==null&&typeof e==="object"&&"action"in e},Qr=(e,t)=>t.keys!==void 0&&e.key.startsWith(".")&&t.keys[e.key.substring(1)]!==void 0,Zr=async(e,t,r,n)=>{let{key:o,parent:s}=e,l=Ne(n.keys,o.substring(1));if(l.options.processArgs!==!1&&(typeof l.options.types==="function"||l.options.types?.[0]!==void 0))e.value=De(l.options,{value:e.value,quoted:!1},r,0,[]);if(typeof e.value!=="string")await $(e.value,{...n,root:{...r,parent:e.parent,parents:e.parents},filters:[...n.filters??[],...l.options.filters??[]]});let a=await l.fn({path:t,root:r,parent:s,key:o,options:n,value:e.value,args:[],rawArgs:[],tags:{}});return Gr(a)?a:j.ReplaceParent(a)},Xr=async(e,t,r,n)=>{if(!t?.onSection&&!t?.onSectionConfig&&!t?.sections)return[e,!1];let o=/<@\s*section(?:\s*:\s*([\w-]+))?\s*@>([\s\S]*?)<@\s*\/\s*section\s*@>/g,s,l=e,a=0,u=!1,m={content:l,root:n,path:r,options:t,section:{}};while((s=o.exec(e))!==null){u=!0;let[y,g,O]=s,b=s.index,k=b+y.length,w=e[k]===`
4
+ `;if(w)k++;let A=b+a,M=k+a,v={},P=O,E=/(^|\r?\n)[ \t]*---[ \t]*(\r?\n|$)/m.exec(O);if(E){let W=O.slice(0,E.index),ue=E.index+E[0].length;P=O.slice(ue);let ee=W.stripIndent().trim();if(ee.length>0)try{v=t?.configParser?.(ee)??{}}catch(ce){throw Error(`Failed to parse YAML config for section: ${ce.message}`)}}else if(/^\r?\n/.test(P))P=P.replace(/^\r?\n/,"");P=P.stripIndent().replace(/(?:\r?\n[ \t]*)+$/,"").replace(/[ \t]+$/,"");let F={config:g?{...v,type:g}:v,content:P};if(m.content=l,m.section=F,Object.keys(F.config).length>0){if(await t.onSectionConfig?.(m)!==!1)await $(F.config,{...t,root:n})}let G=m.section.config.type?t.sections?.[m.section.config.type]:void 0,x;if(G)x=await G(m);else if(t.onSection)x=await t.onSection(m);if(F.trim)F.content=F.content.trim();if(F.indent)F.content=F.content.split(`
5
+ `).map((W)=>" ".repeat(F.indent)+W).join(`
6
+ `);let C="";if(x===!0||F.show)C=F.content;else if(typeof x==="string")C=x;if(w&&C!==""&&!C.endsWith(`
6
7
  `))C+=`
7
- `;let P=l.lastIndexOf(`
8
- `,j-1),J=P===-1?0:P+1,ee=l.slice(J,j).trim().length===0?J:j;l=l.slice(0,ee)+C+l.slice(h),a+=C.length-(h-ee),b.content=l}return[l,u]},Be=(e)=>{let t=[],r=0;while(r<e.length)if(e[r]==="$"&&e[r+1]==="("&&(r===0||e[r-1]!=="\\")){let n=r;r+=2;let o=1;for(;r<e.length;r++)if(e[r]==="(")o++;else if(e[r]===")"){if(o--,o===0){t.push([n,r]);break}}if(o!==0)throw Error(`Unmatched opening $( at position ${n.toString()}`);r++}else r++;return t},ye=Symbol.for("@homedev/fields:OverrideResult"),jn=(e)=>({[ye]:!0,value:e}),vn=(e)=>{return e!==null&&typeof e==="object"&&ye in e&&e[ye]===!0},qe=async(e,t,r)=>{for(let n=t.length-1;n>=0;n--){let[o,s]=t[n],l=e.slice(o+2,s),a=await qe(l,Be(l),r);if(typeof a==="object")return a;let u=await r(a,e);if(vn(u))return u.value;e=e.slice(0,o)+u+e.slice(s+1)}return e},En=async(e,t)=>qe(e,Be(e),t),Sn=(e)=>{return e!==null&&typeof e==="object"&&"action"in e},kn=/([\w\d.-_/]+):(.+)/,Mn=async(e,t,r,n)=>{let o=await(async()=>{let s=kn.exec(e);if(!s)return await G(t,e);let[l,a,u]=s,b=_e(n.sources,a),w=hn(u,b,t);return await b.fn({args:w.parsedArgs,rawArgs:w.rawArgs,tags:w.tags,key:a,options:n,root:t,path:r,value:null})})();if(o===null||o===void 0)return"";if(typeof o==="object")return jn(o);return o},Ke=async(e,t,r,n)=>{let o=await En(t,(s)=>Mn(s,r,e,n));if(Sn(o))return o;if(o===t)return F.Explore();if(typeof o==="string"){let s=await Ke(e,o,r,n);if(s.action!==I.Explore)return s;return F.ReplaceItem(o)}return F.ReplaceItem(o)},R=async(e,t)=>{return t??={},await nn(e,async(r)=>{let n=[...r.path,r.key].join(".");if(t?.filters?.length&&t.filters.some((a)=>a.test(n)))return F.NoExplore();let o=r.path.length===0,s=r.parents.length>0?r.parents.toReversed():[];if(o){if(s.length>0)throw Error("Root object should not have a parent");s=t?.root?.parents?[t.root.parent,...t.root.parents.toReversed()]:[]}let l={...e,...t.root,this:r.parent,parent:s.length>0?s[0]:null,parents:s};try{if(r.key.startsWith("$"))return F.NoExplore();let a=F.Explore();if(typeof r.value==="string"){let u=r.value,b=!1;while(!0){let[w,m]=await An(u,t,n,l);if(b=b||m,a=await Ke(n,w,l,t),a.action===I.ReplaceItem&&typeof a.by==="string"){u=a.by;continue}if(a.action===I.Explore&&m&&w!==u)a=F.ReplaceItem(w);break}if(a.action===I.Explore&&u!==r.value)a=F.ReplaceItem(u);switch(a.action){case I.Explore:break;case I.ReplaceItem:r.value=a.by;break;default:return a}}if(wn(r,t))a=await On(r,n,l,t);return a}catch(a){throw Error(`${a.message}
9
- (${n})`)}}),e},Ye=(e,t)=>t?{fn:(r)=>e(...r.args),types:t}:(r)=>e(...r.args),Hn=(e,t)=>Object.fromEntries(e.map((r)=>[r.name,Ye(r,t?.types?.[r.name])])),T=(e,t)=>Object.fromEntries((t?.keys??Object.keys(e)).map((r)=>[r,Ye(e[r],t?.types?.[r])]));import Ge from"fs/promises";import de from"path";import Fn from"fs/promises";import Dn from"path";import Rn from"fs/promises";import Cn from"fs/promises";import Qe from"fs/promises";import Te from"path";import Nn from"fs/promises";import he from"path";import Ve from"path";var we=async(e)=>{try{return await Ge.access(e,Ge.constants.R_OK),!0}catch{return!1}},oe=async(e,t)=>{let r=!de.isAbsolute(e)&&t?["",...t]:[""];for(let n of r){let o=de.join(n,e);if(await we(o))return de.resolve(o)}throw Error(`File not found: "${e}"`)},Xe=async(e,t)=>{let r=await oe(e,t?.dirs),n=await Fn.readFile(r,"utf-8"),o=Dn.dirname(r),s={text:{fn:(a)=>a,matching:["\\.txt$","\\.text$"]},json:{fn:JSON.parse,matching:["\\.json$"]},...t?.parsers},l=t?.format?s[t.format]:Object.values(s).find((a)=>a.matching?.some((u)=>new RegExp(u).test(e)));if(!l)throw Error(`Unsupported format for file "${e}" and no matching parser found`);return{content:await l.fn(n),fullPath:r,folderPath:o}},$n=async(e,t,r)=>{let n={text:{fn:(s)=>s,matching:["\\.txt$","\\.text$"]},json:{fn:JSON.stringify,matching:["\\.json$"]},...r?.encoders},o=r?.format?n[r.format]:Object.values(n).find((s)=>s.matching?.some((l)=>new RegExp(l).test(e)));if(!o)throw Error(`Unsupported format for file "${e}" and no matching encoder found`);await Rn.writeFile(e,await o.fn(t))},He=async(e,t)=>{if(typeof e==="string"&&!e.includes("*"))return await t.map(e,0,[]);let r=await Array.fromAsync(Cn.glob(e,{cwd:t.cwd})),n=t.filter?r.filter(t.filter):r;return await Promise.all(n.map(t.map))},ze=async(e,t)=>{if(t?.targetDirectory&&t?.removeFirst)try{await Qe.rm(t?.targetDirectory,{recursive:!0,force:!0})}catch(r){throw Error(`Failed to clean the output directory: ${r.message}`)}for(let r of e)await xn(r,t)},xn=async(e,t)=>{let r=Te.join(t?.targetDirectory??".",e.name),n=Te.dirname(r);if(t?.classes){if(e.class!==void 0&&!t.classes.includes(e.class))return;if(t.classRequired&&e.class===void 0)throw Error(`Output "${e.name}" is missing class field`)}if(t?.writing?.(e)===!1)return;try{await Qe.mkdir(n,{recursive:!0})}catch(o){throw Error(`Failed to create target directory "${n}" for output "${r}": ${o.message}`)}try{await $n(r,e.value,{format:e.type??"text"})}catch(o){throw Error(`Failed to write output "${r}": ${o.message}`)}},be=(e)=>e?Ve.isAbsolute(e)?e:Ve.join(process.cwd(),e):process.cwd(),Wn=async(e,t)=>{let r=[];for(let n of e)try{let o=!he.isAbsolute(n)?he.join(be(t?.cwd),n):n;if(t?.filter?.(o)===!1)continue;let s=await import(o);if(t?.resolveDefault==="only"&&!s.default)throw Error(`Module ${n} does not have a default export`);let l=t?.resolveDefault?s.default??s:s,a=t?.map?await t.map(l,n):l;if(a!==void 0)r.push(a)}catch(o){if(t?.fail?.(n,o)===!1)continue;throw Error(`Failed to import module ${n}: ${o.message??o}`)}return r},ao=async(e,t)=>{let r=[];for(let n of e){let o=(await Array.fromAsync(Nn.glob(n,{cwd:be(t?.cwd)}))).map((s)=>he.join(be(t?.cwd),s));r.push(...await Wn(o,t))}return r};class V{o;context;constructor(e){this.o=e}}var f=(e)=>(t,r)=>{r.addInitializer(function(){let n=this[r.name],o=e?.name??r.name;this.o.sources({[o]:(s)=>n.apply({...this,context:s},s.args)})})},uo=(e)=>(t,r)=>{r.addInitializer(function(){let n=this[r.name],o=e?.name??r.name;this.o.sections({[o]:(s)=>{return n.call({...this,context:s},s.section)}})})},co=(e)=>(t,r)=>{r.addInitializer(function(){let n=this[r.name],o=e?.name??r.name;this.o.keys({[o]:(s)=>n.call({...this,context:s},s.value)})})},fo=(e)=>(t,r)=>{r.addInitializer(function(){let n=this[r.name],o=e?.name??r.name;this.o.variables({[o]:n})})},po=(e)=>(t,r)=>{r.addInitializer(function(){let n=this[r.name],o=e?.name??r.name;this.o.functions({[o]:n})})},go=(e)=>(t,r)=>{r.addInitializer(function(){let n=this[r.name],o=e?.name??r.name;this.o.encoders({[o]:{fn:n}})})},mo=(e)=>(t,r)=>{r.addInitializer(function(){let n=this[r.name],o=e?.name??r.name;this.o.decoders({[o]:{fn:n}})})};import{createHash as U}from"crypto";import N from"path";var Ze=(e)=>({output:(t)=>{delete t.parent[t.key];for(let r of Array.isArray(t.value)?t.value:[t.value])if(typeof r==="string")e.output({name:r,value:t.parent});else e.output({...r,value:r.value??t.parent});return v.SkipSiblings()}});import In from"path";var Pe=(e)=>({load:async(t)=>{let r=t.options.globalContext;for(let{file:n}of Array.isArray(t.value)?t.value:[t.value]){if(!n)throw Error("File reference required");await e.load(n,r.file&&In.dirname(r.file))}return v.DeleteItem()}});class Oe{cache=new Map;maxSize;constructor(e=100){this.maxSize=e}get(e){return this.cache.get(e)}set(e,t){this.evictIfNeeded(),this.cache.set(e,t)}has(e){return this.cache.has(e)}clear(){this.cache.clear()}setMaxSize(e){this.maxSize=e}size(){return this.cache.size}evictIfNeeded(){if(this.cache.size>=this.maxSize){let e=null,t=1/0;for(let[r,n]of this.cache.entries())if(n.timestamp<t)t=n.timestamp,e=r;if(e)this.cache.delete(e)}}}var ie=(e)=>{if(typeof e.value==="string")return e.parent;let t=e.value.model;if(!t)return e.parent;if(typeof t==="string")return Object.select(e.root,t);return t};var se=(e)=>{if(typeof e.value==="string")return Object.select(e.root,e.value);if(Array.isArray(e.value))return e.value;let t=e.value;if(typeof t.from==="string")return Object.select(e.root,t.from);return t.from};var ae=async(e,t)=>{let r=e.value;if(r.selector===void 0)return t;if(typeof r.selector!=="string"){let n=JSON.parse(JSON.stringify(r.selector));return await R(n,{...e.options,root:{...e.root,result:t}}),n}return await Object.select({...e.root,result:t},r.selector)};import L from"path";class _{constructor(){}static normalize(e){return L.normalize(L.resolve(e))}static resolveInContext(e,t){let r=t??process.cwd(),n=L.isAbsolute(e)?e:L.join(r,e);return this.normalize(n)}static isDirectoryPattern(e){return e.endsWith("/")}static isGlobPattern(e){return e.includes("*")}static toAbsolute(e,t){if(L.isAbsolute(e))return e;return L.join(t??process.cwd(),e)}}var x={and:(...e)=>e.every((t)=>!!t),or:(...e)=>e.some((t)=>!!t),xor:(...e)=>e.filter((t)=>!!t).length===1,true:(...e)=>e.every((t)=>!!t),false:(...e)=>e.every((t)=>!t),eq:(...e)=>e.every((t)=>t===e[0]),ne:(...e)=>e.some((t)=>t!==e[0]),lt:(...e)=>typeof e[0]==="number"&&e.slice(1).every((t)=>typeof t==="number"&&e[0]<t),le:(...e)=>typeof e[0]==="number"&&e.slice(1).every((t)=>typeof t==="number"&&e[0]<=t),gt:(...e)=>typeof e[0]==="number"&&e.slice(1).every((t)=>typeof t==="number"&&e[0]>t),ge:(...e)=>typeof e[0]==="number"&&e.slice(1).every((t)=>typeof t==="number"&&e[0]>=t),in:(e,t)=>{if(Array.isArray(t))return t.includes(e);if(typeof e==="string")return e.includes(t);if(Array.isArray(e))return e.includes(t);return!1},notin:(e,t)=>!x.in(e,t),contains:(e,t)=>e.includes(t),notcontains:(e,t)=>!e.includes(t),containsi:(e,t)=>e.toLowerCase().includes(t.toLowerCase()),notcontainsi:(e,t)=>!e.toLowerCase().includes(t.toLowerCase()),null:(...e)=>e.every((t)=>t===null||t===void 0),notnull:(...e)=>e.every((t)=>t!==null&&t!==void 0),empty:(...e)=>e.every((t)=>t===""),notempty:(...e)=>e.every((t)=>t!==""),nullorempty:(...e)=>e.every((t)=>t===null||t===void 0||t===""),notnullorempty:(...e)=>e.every((t)=>t!==null&&t!==void 0&&t!=="")},le={and:()=>"boolean",or:()=>"boolean",xor:()=>"boolean",true:()=>"boolean",false:()=>"boolean",lt:()=>"number",le:()=>"number",gt:()=>"number",ge:()=>"number"};var Je=()=>({each:{filters:[/select|model/],fn:async(e)=>{let t=e.value;delete e.parent[e.key];let r=await se(e),n=await ie(e);if(!Array.isArray(r))throw Error('Key "each" requires a source list');if(n===void 0)throw Error('Key "each" must define a model');if(t.extend?.model)n=[t.model,...Array.isArray(t.extend.model)?t.extend.model:[t.extend.model]].mergeAll();let o=[];for(let s=0;s<r.length;s++){let l=Object.deepClone(n);if(await R(l,{...e.options,root:{...e.root,index:s,item:r[s],instance:l}}),t.extend?.result){let a=t.extend.result;l=[l,...Array.isArray(a)?a:[a]].mergeAll()}o.push(await ae(e,l))}return o}}});var et=()=>({map:{filters:[/select|model/],fn:async(e)=>{delete e.parent[e.key];let t=await se(e),r=await ie(e);if(!Array.isArray(t))throw Error('Key "map" requires a source list');if(r===void 0)throw Error('Key "map" must define a model');let n=[];for(let o=0;o<t.length;o++){let s=Object.deepClone(r);await R(s,{...e.options,root:{...e.root,index:o,item:t[o],instance:s}}),n.push(await ae(e,s))}return n}}});var tt=()=>({concat:async(e)=>{let t=[];for(let r of Array.isArray(e.value)?e.value:[e.value])t.push(...await Object.select(e.root,r));return t.filter((r)=>r!==void 0)}});Array.prototype.findOrFail=function(e,t,r){let n=this.find(e,r);if(n===void 0)throw Error(t??"Element not found");return n};Array.flat=function(e){if(Array.isArray(e))return e.flat(2);else return[e]};Array.prototype.forEachAsync=async function(e){for(let t=0;t<this.length;t++)await e(this[t],t,this)};Array.prototype.groupBy=function(e){return this.reduce((t,r)=>{let n=e(r);if(!t[n])t[n]=[];return t[n].push(r),t},{})};Array.prototype.createInstances=function(e,...t){return this.map((r,n)=>new e(...t,r,n))};Array.prototype.mapAsync=async function(e){return Promise.all(this.map(e))};Array.prototype.nonNullMap=function(e){let t=[];for(let r=0;r<this.length;r++){let n=e(this[r],r,this);if(n!=null)t.push(n)}return t};Array.prototype.nonNullMapAsync=async function(e){let t=[];for(let r=0;r<this.length;r++){let n=await e(this[r],r,this);if(n!=null)t.push(n)}return t};Array.prototype.mergeAll=function(e){let t={};for(let r of this.toReversed())Object.merge(r,t,e);return t};Array.prototype.toObject=function(e,t){return Object.fromEntries(this.map((r)=>{let n=e(r),o=t?t(r):r;return[n,o]}))};Array.prototype.toObjectWithKey=function(e){return Object.fromEntries(this.map((t)=>[String(t[e]),t]))};Array.prototype.selectFor=function(e,t,r,n){let o=this.find(e,n);if(o===void 0)throw Error(r??"Element not found");return t(o)};Array.prototype.sortBy=function(e,t=!0){return this.slice().sort((r,n)=>{let o=e(r),s=e(n);if(o<s)return t?-1:1;if(o>s)return t?1:-1;return 0})};Array.prototype.unique=function(){return Array.from(new Set(this))};Array.prototype.uniqueBy=function(e){let t=new Set;return this.filter((r)=>{let n=e(r);if(t.has(n))return!1;else return t.add(n),!0})};var Ln;((e)=>{e[e.Explore=0]="Explore",e[e.SkipSiblings=1]="SkipSiblings",e[e.NoExplore=2]="NoExplore",e[e.ReplaceParent=3]="ReplaceParent",e[e.DeleteParent=4]="DeleteParent",e[e.MergeParent=5]="MergeParent",e[e.ReplaceItem=6]="ReplaceItem",e[e.DeleteItem=7]="DeleteItem"})(Ln||={});class v{action;by;skipSiblings;reexplore;constructor(e,t,r,n){this.action=e,this.by=t,this.skipSiblings=r,this.reexplore=n}static _explore=new v(0);static _noExplore=new v(2);static _skipSiblings=new v(1);static _deleteParent=new v(4);static ReplaceParent(e,t){return new v(3,e,void 0,t)}static SkipSiblings(){return v._skipSiblings}static Explore(){return v._explore}static NoExplore(){return v._noExplore}static DeleteParent(){return v._deleteParent}static MergeParent(e){return new v(5,e)}static ReplaceItem(e,t){return new v(6,e,t)}static DeleteItem(e){return new v(7,void 0,e)}}Object.navigate=async(e,t)=>{let r=new WeakSet,n=[],o=[],s=async(a,u,b)=>{let w=a===null,m=w?v.Explore():await t({key:a,value:u,path:n,parent:b,parents:o});if(u&&typeof u==="object"&&m.action===0){if(r.has(u))return m;if(r.add(u),!w)n.push(a),o.push(b);let g=u;while(await l(g,a,b))g=b[a];if(!w)o.pop(),n.pop()}return m},l=async(a,u,b)=>{let w=Object.keys(a),m=w.length;for(let g=0;g<m;g++){let d=w[g],E=a[d],y=await s(d,E,a),j=y.action;if(j===0||j===2)continue;if(j===6){if(a[d]=y.by,y.skipSiblings)return;continue}if(j===7){if(delete a[d],y.skipSiblings)return;continue}if(j===1)return;if(j===3){if(u===null)throw Error("Cannot replace root object");if(b[u]=y.by,y.reexplore)return!0;return}if(j===4){if(u===null)throw Error("Cannot delete root object");delete b[u];return}if(j===5)delete a[d],Object.assign(a,y.by)}};await s(null,e,null)};Object.find=async function(e,t){let r=[];return await Object.navigate(e,(n)=>{if(t([...n.path,n.key].join("."),n.value))r.push(n.value);return v.Explore()}),r};Object.merge=(e,t,r)=>{for(let n of Object.keys(t)){if(e[n]===void 0)continue;let o=t[n],s=e[n];if(typeof s!==typeof o||Array.isArray(s)!==Array.isArray(o)){let a=r?.mismatch?.(n,s,o,e,t);if(a!==void 0){t[n]=a;continue}throw Error(`Type mismatch: ${n}`)}let l=r?.mode?.(n,s,o,e,t)??t[".merge"]??"merge";switch(l){case"source":t[n]=s;continue;case"target":continue;case"skip":delete t[n],delete e[n];continue;case"merge":break;default:throw Error(`Unknown merge mode: ${l}`)}if(typeof s==="object")if(Array.isArray(s))o.push(...s);else{if(r?.navigate?.(n,s,o,e,t)===!1)continue;Object.merge(s,o,r)}else{if(s===o)continue;let a=r?.conflict?.(n,s,o,e,t);t[n]=a===void 0?o:a}}for(let n of Object.keys(e))if(t[n]===void 0)t[n]=e[n]};var _n=/^\[([^=\]]*)([=]*)([^\]]*)\]$/,Un=/^([^[\]]*)\[([^\]]*)]$/,Ae=(e,t,r,n)=>{if(e.startsWith("{")&&e.endsWith("}")){let o=e.substring(1,e.length-1);return Object.select(t,o,r)?.toString()}return n?e:void 0},Bn=(e,t,r,n)=>{let o=Ae(t,r,n);if(o)return Object.select(e,o,n);let s=_n.exec(t);if(s){let[,a,u,b]=s,w=Ae(a.trim(),r,n,!0),m=Ae(b.trim(),r,n,!0);if(Array.isArray(e)&&(u==="="||u==="==")&&w)return e.find((g)=>g?.[w]==m)}let l=Un.exec(t);if(l){let[,a,u]=l;return e?.[a]?.[u]}return e?.[t]};Object.select=(e,t,r)=>{let n=void 0,o=void 0,s=t??"",l=(m)=>{if(!m)return[m,!1];return m.endsWith("?")?[m.substring(0,m.length-1),!0]:[m,!1]},a=(m,g)=>{let[d,E]=l(g.pop());if(!d){if(r?.set!==void 0&&o!==void 0&&n!==void 0)n[o]=r.set;return m}let y=Bn(m,d,e,r);if(y===void 0){if(E||r?.optional||r?.defaultValue!==void 0)return;throw Error(`Unknown path element: "${d}" in "${s}"`)}return n=m,o=d,a(y,g)},u=s.splitNested(r?.separator??".","{","}"),b=void 0;if(u.length>0&&u[u.length-1].startsWith("?="))b=u.pop()?.substring(2);u.reverse();let w=a(e,u);if(w===void 0)return b??r?.defaultValue;return w};Object.deepClone=function(e){if(typeof structuredClone<"u")try{return structuredClone(e)}catch{}return JSON.parse(JSON.stringify(e))};Object.toList=function(e,t){return Object.entries(e).map(([r,n])=>({[t]:r,...n}))};Object.mapEntries=function(e,t){let r=Object.entries(e).map(([n,o])=>t(n,o));return Object.fromEntries(r)};global.AsyncFunction=Object.getPrototypeOf(async function(){}).constructor;global.defined=(e,t="Value is undefined")=>{if(e===void 0||e===null)throw Error(t);return e};String.prototype.tokenize=function(e,t=/\${([^}]+)}/g){return this.replace(t,(r,n)=>{let o=e[n];if(o===null||o===void 0)return"";if(typeof o==="string")return o;if(typeof o==="number"||typeof o==="boolean")return String(o);return String(o)})};String.prototype.toPascal=function(){return this.replace(/((?:[_ ]+)\w|^\w)/g,(e,t)=>t.toUpperCase()).replace(/[_ ]/g,"")};String.prototype.capitalize=function(){return this.replace(/((?:[ ]+)\w|^\w)/g,(e,t)=>t.toUpperCase())};String.prototype.toCamel=function(){return this.toPascal().replace(/((?:[ ]+\w)|^\w)/g,(e,t)=>t.toLowerCase())};String.prototype.toSnake=function(){return this.replace(/([a-z])([A-Z])/g,"$1_$2").replace(/\s+/g,"_")};String.prototype.toKebab=function(){return this.replace(/([a-z])([A-Z])/g,"$1-$2").replace(/\s+/g,"-")};String.prototype.changeCase=function(e){switch(e){case"upper":return this.toUpperCase();case"lower":return this.toLowerCase();case"pascal":return this.toPascal();case"camel":return this.toCamel();case"snake":return this.toSnake();case"kebab":return this.toKebab();default:throw Error(`Unsupported case type: ${e}`)}};String.prototype.splitWithQuotes=function(e=","){let t=[],r=this.length,n=e.length,o=0,s=(l)=>{if(l+n>r)return!1;for(let a=0;a<n;a++)if(this[l+a]!==e[a])return!1;return!0};while(o<r){while(o<r&&this[o]===" ")o++;if(o>=r)break;let l="",a=this[o]==='"'||this[o]==="'";if(a){let u=this[o++];while(o<r&&this[o]!==u)l+=this[o++];if(o<r)o++}else{while(o<r&&!s(o)){let u=this[o];if(u==='"'||u==="'"){l+=u,o++;while(o<r&&this[o]!==u)l+=this[o++];if(o<r)l+=this[o++]}else l+=this[o++]}l=l.trim()}if(l)t.push({value:l,quoted:a});if(s(o))o+=n}return t};String.prototype.splitNested=function(e,t,r){let n=0,o="",s=[];for(let l of this){if(o+=l,l===t)n++;if(l===r)n--;if(n===0&&l===e)s.push(o.slice(0,-1)),o=""}if(o)s.push(o);return s};String.prototype.padBlock=function(e,t=`
8
+ `;let Q=l.lastIndexOf(`
9
+ `,A-1),Z=Q===-1?0:Q+1,X=l.slice(Z,A).trim().length===0?Z:A;l=l.slice(0,X)+C+l.slice(M),a+=C.length-(M-X),m.content=l}return[l,u]},Ie=(e)=>{let t=[],r=0;while(r<e.length)if(e[r]==="$"&&e[r+1]==="("&&(r===0||e[r-1]!=="\\")){let n=r;r+=2;let o=1;for(;r<e.length;r++)if(e[r]==="(")o++;else if(e[r]===")"){if(o--,o===0){t.push([n,r]);break}}if(o!==0)throw Error(`Unmatched opening $( at position ${n.toString()}`);r++}else r++;return t},me=Symbol.for("@homedev/fields:OverrideResult"),en=(e)=>({[me]:!0,value:e}),tn=(e)=>{return e!==null&&typeof e==="object"&&me in e&&e[me]===!0},_e=async(e,t,r)=>{for(let n=t.length-1;n>=0;n--){let[o,s]=t[n],l=e.slice(o+2,s),a=await _e(l,Ie(l),r);if(typeof a==="object")return a;let u=await r(a,e);if(tn(u))return u.value;e=e.slice(0,o)+u+e.slice(s+1)}return e},rn=async(e,t)=>_e(e,Ie(e),t),nn=(e)=>{return e!==null&&typeof e==="object"&&"action"in e},on=/([\w\d.-_/]+):(.+)/,sn=async(e,t,r,n)=>{let o=await(async()=>{let s=on.exec(e);if(!s)return await Object.select(t,e);let[l,a,u]=s,m=Ne(n.sources,a),y=Hr(u,m,t);return await m.fn({args:y.parsedArgs,rawArgs:y.rawArgs,tags:y.tags,key:a,options:n,root:t,path:r,value:null})})();if(o===null||o===void 0)return"";if(typeof o==="object")return en(o);return o},Ue=async(e,t,r,n)=>{let o=await rn(t,(s)=>sn(s,r,e,n));if(nn(o))return o;if(o===t)return j.Explore();if(typeof o==="string"){let s=await Ue(e,o,r,n);if(s.action!==I.Explore)return s;return j.ReplaceItem(o)}return j.ReplaceItem(o)},$=async(e,t)=>{return t??={},await Object.navigate(e,async(r)=>{let n=[...r.path,r.key].join(".");if(t?.filters?.length&&t.filters.some((a)=>a.test(n)))return j.NoExplore();let o=r.path.length===0,s=r.parents.length>0?r.parents.toReversed():[];if(o){if(s.length>0)throw Error("Root object should not have a parent");s=t?.root?.parents?[t.root.parent,...t.root.parents.toReversed()]:[]}let l={...e,...t.root,this:r.parent,parent:s.length>0?s[0]:null,parents:s};try{if(r.key.startsWith("$"))return j.NoExplore();let a=j.Explore();if(typeof r.value==="string"){let u=r.value,m=!1;while(!0){let[y,g]=await Xr(u,t,n,l);if(m=m||g,a=await Ue(n,y,l,t),a.action===I.ReplaceItem&&typeof a.by==="string"){u=a.by;continue}if(a.action===I.Explore&&g&&y!==u)a=j.ReplaceItem(y);break}if(a.action===I.Explore&&u!==r.value)a=j.ReplaceItem(u);switch(a.action){case I.Explore:break;case I.ReplaceItem:r.value=a.by;break;default:return a}}if(Qr(r,t))a=await Zr(r,n,l,t);return a}catch(a){throw Error(`${a.message}
10
+ (${n})`)}}),e},Le=(e,t)=>t?{fn:(r)=>e(...r.args),types:t}:(r)=>e(...r.args),Fn=(e,t)=>Object.fromEntries(e.map((r)=>[r.name,Le(r,t?.types?.[r.name])])),J=(e,t)=>Object.fromEntries((t?.keys??Object.keys(e)).map((r)=>[r,Le(e[r],t?.types?.[r])]));import We from"fs/promises";import ye from"path";import an from"fs/promises";import ln from"path";import un from"fs/promises";import fn from"fs/promises";import Ye from"fs/promises";import Be from"path";import gn from"fs/promises";import he from"path";import qe from"path";var be=async(e)=>{try{return await We.access(e,We.constants.R_OK),!0}catch{return!1}},ne=async(e,t)=>{let r=!ye.isAbsolute(e)&&t?["",...t]:[""];for(let n of r){let o=ye.join(n,e);if(await be(o))return ye.resolve(o)}throw Error(`File not found: "${e}"`)},Ke=async(e,t)=>{let r=await ne(e,t?.dirs),n=await an.readFile(r,"utf-8"),o=ln.dirname(r),s={text:{fn:(a)=>a,matching:["\\.txt$","\\.text$"]},json:{fn:JSON.parse,matching:["\\.json$"]},...t?.parsers},l=t?.format?s[t.format]:Object.values(s).find((a)=>a.matching?.some((u)=>new RegExp(u).test(e)));if(!l)throw Error(`Unsupported format for file "${e}" and no matching parser found`);return{content:await l.fn(n),fullPath:r,folderPath:o}},cn=async(e,t,r)=>{let n={text:{fn:(s)=>s,matching:["\\.txt$","\\.text$"]},json:{fn:JSON.stringify,matching:["\\.json$"]},...r?.encoders},o=r?.format?n[r.format]:Object.values(n).find((s)=>s.matching?.some((l)=>new RegExp(l).test(e)));if(!o)throw Error(`Unsupported format for file "${e}" and no matching encoder found`);await un.writeFile(e,await o.fn(t))},Je=async(e,t)=>{if(typeof e==="string"&&!e.includes("*"))return await t.map(e,0,[]);let r=await Array.fromAsync(fn.glob(e,{cwd:t.cwd})),n=t.filter?r.filter(t.filter):r;return await Promise.all(n.map(t.map))},Te=async(e,t)=>{if(t?.targetDirectory&&t?.removeFirst)try{await Ye.rm(t?.targetDirectory,{recursive:!0,force:!0})}catch(r){throw Error(`Failed to clean the output directory: ${r.message}`)}for(let r of e)await pn(r,t)},pn=async(e,t)=>{let r=Be.join(t?.targetDirectory??".",e.name),n=Be.dirname(r);if(t?.classes){if(e.class!==void 0&&!t.classes.includes(e.class))return;if(t.classRequired&&e.class===void 0)throw Error(`Output "${e.name}" is missing class field`)}if(t?.writing?.(e)===!1)return;try{await Ye.mkdir(n,{recursive:!0})}catch(o){throw Error(`Failed to create target directory "${n}" for output "${r}": ${o.message}`)}try{await cn(r,e.value,{format:e.type??"text"})}catch(o){throw Error(`Failed to write output "${r}": ${o.message}`)}},de=(e)=>e?qe.isAbsolute(e)?e:qe.join(process.cwd(),e):process.cwd(),mn=async(e,t)=>{let r=[];for(let n of e)try{let o=!he.isAbsolute(n)?he.join(de(t?.cwd),n):n;if(t?.filter?.(o)===!1)continue;let s=await import(o);if(t?.resolveDefault==="only"&&!s.default)throw Error(`Module ${n} does not have a default export`);let l=t?.resolveDefault?s.default??s:s,a=t?.map?await t.map(l,n):l;if(a!==void 0)r.push(a)}catch(o){if(t?.fail?.(n,o)===!1)continue;throw Error(`Failed to import module ${n}: ${o.message??o}`)}return r},Wn=async(e,t)=>{let r=[];for(let n of e){let o=(await Array.fromAsync(gn.glob(n,{cwd:de(t?.cwd)}))).map((s)=>he.join(de(t?.cwd),s));r.push(...await mn(o,t))}return r};class Y{o;context;constructor(e){this.o=e}}var f=(e)=>(t,r)=>{r.addInitializer(function(){let n=this[r.name],o=e?.name??r.name;this.o.sources({[o]:(s)=>n.apply({...this,context:s},s.args)})})},qn=(e)=>(t,r)=>{r.addInitializer(function(){let n=this[r.name],o=e?.name??r.name;this.o.sections({[o]:(s)=>{return n.call({...this,context:s},s.section)}})})},Kn=(e)=>(t,r)=>{r.addInitializer(function(){let n=this[r.name],o=e?.name??r.name;this.o.keys({[o]:(s)=>n.call({...this,context:s},s.value)})})},Jn=(e)=>(t,r)=>{r.addInitializer(function(){let n=this[r.name],o=e?.name??r.name;this.o.variables({[o]:n})})},Yn=(e)=>(t,r)=>{r.addInitializer(function(){let n=this[r.name],o=e?.name??r.name;this.o.functions({[o]:n})})},Tn=(e)=>(t,r)=>{r.addInitializer(function(){let n=this[r.name],o=e?.name??r.name;this.o.encoders({[o]:{fn:n}})})},Vn=(e)=>(t,r)=>{r.addInitializer(function(){let n=this[r.name],o=e?.name??r.name;this.o.decoders({[o]:{fn:n}})})};import{createHash as L}from"crypto";import N from"path";var Ve=(e)=>({output:(t)=>{delete t.parent[t.key];for(let r of Array.isArray(t.value)?t.value:[t.value])if(typeof r==="string")e.output({name:r,value:t.parent});else e.output({...r,value:r.value??t.parent});return d.SkipSiblings()}});import yn from"path";var ze=(e)=>({load:async(t)=>{let r=t.options.globalContext;for(let{file:n}of Array.isArray(t.value)?t.value:[t.value]){if(!n)throw Error("File reference required");await e.load(n,r.file&&yn.dirname(r.file))}return d.DeleteItem()}});class we{cache=new Map;maxSize;constructor(e=100){this.maxSize=e}get(e){return this.cache.get(e)}set(e,t){this.evictIfNeeded(),this.cache.set(e,t)}has(e){return this.cache.has(e)}clear(){this.cache.clear()}setMaxSize(e){this.maxSize=e}size(){return this.cache.size}evictIfNeeded(){if(this.cache.size>=this.maxSize){let e=null,t=1/0;for(let[r,n]of this.cache.entries())if(n.timestamp<t)t=n.timestamp,e=r;if(e)this.cache.delete(e)}}}var oe=(e)=>{if(typeof e.value==="string")return e.parent;let t=e.value.model;if(!t)return e.parent;if(typeof t==="string")return Object.select(e.root,t);return t};var ie=(e)=>{if(typeof e.value==="string")return Object.select(e.root,e.value);if(Array.isArray(e.value))return e.value;let t=e.value;if(typeof t.from==="string")return Object.select(e.root,t.from);return t.from};var se=async(e,t)=>{let r=e.value;if(r.selector===void 0)return t;if(typeof r.selector!=="string"){let n=JSON.parse(JSON.stringify(r.selector));return await $(n,{...e.options,root:{...e.root,result:t}}),n}return await Object.select({...e.root,result:t},r.selector)};import _ from"path";class U{constructor(){}static normalize(e){return _.normalize(_.resolve(e))}static resolveInContext(e,t){let r=t??process.cwd(),n=_.isAbsolute(e)?e:_.join(r,e);return this.normalize(n)}static isDirectoryPattern(e){return e.endsWith("/")}static isGlobPattern(e){return e.includes("*")}static toAbsolute(e,t){if(_.isAbsolute(e))return e;return _.join(t??process.cwd(),e)}}var D={and:(...e)=>e.every((t)=>!!t),or:(...e)=>e.some((t)=>!!t),xor:(...e)=>e.filter((t)=>!!t).length===1,true:(...e)=>e.every((t)=>!!t),false:(...e)=>e.every((t)=>!t),eq:(...e)=>e.every((t)=>t===e[0]),ne:(...e)=>e.some((t)=>t!==e[0]),lt:(...e)=>typeof e[0]==="number"&&e.slice(1).every((t)=>typeof t==="number"&&e[0]<t),le:(...e)=>typeof e[0]==="number"&&e.slice(1).every((t)=>typeof t==="number"&&e[0]<=t),gt:(...e)=>typeof e[0]==="number"&&e.slice(1).every((t)=>typeof t==="number"&&e[0]>t),ge:(...e)=>typeof e[0]==="number"&&e.slice(1).every((t)=>typeof t==="number"&&e[0]>=t),in:(e,t)=>{if(Array.isArray(t))return t.includes(e);if(typeof e==="string")return e.includes(t);if(Array.isArray(e))return e.includes(t);return!1},notin:(e,t)=>!D.in(e,t),contains:(e,t)=>e.includes(t),notcontains:(e,t)=>!e.includes(t),containsi:(e,t)=>e.toLowerCase().includes(t.toLowerCase()),notcontainsi:(e,t)=>!e.toLowerCase().includes(t.toLowerCase()),null:(...e)=>e.every((t)=>t===null||t===void 0),notnull:(...e)=>e.every((t)=>t!==null&&t!==void 0),empty:(...e)=>e.every((t)=>t===""),notempty:(...e)=>e.every((t)=>t!==""),nullorempty:(...e)=>e.every((t)=>t===null||t===void 0||t===""),notnullorempty:(...e)=>e.every((t)=>t!==null&&t!==void 0&&t!=="")},ae={and:()=>"boolean",or:()=>"boolean",xor:()=>"boolean",true:()=>"boolean",false:()=>"boolean",lt:()=>"number",le:()=>"number",gt:()=>"number",ge:()=>"number"};var He=()=>({each:{filters:[/select|model/],fn:async(e)=>{let t=e.value;delete e.parent[e.key];let r=await ie(e),n=await oe(e);if(!Array.isArray(r))throw Error('Key "each" requires a source list');if(n===void 0)throw Error('Key "each" must define a model');if(t.extend?.model)n=[t.model,...Array.isArray(t.extend.model)?t.extend.model:[t.extend.model]].mergeAll();let o=[];for(let s=0;s<r.length;s++){let l=Object.deepClone(n);if(await $(l,{...e.options,root:{...e.root,index:s,item:r[s],instance:l}}),t.extend?.result){let a=t.extend.result;l=[l,...Array.isArray(a)?a:[a]].mergeAll()}o.push(await se(e,l))}return o}}});var Ge=()=>({map:{filters:[/select|model/],fn:async(e)=>{delete e.parent[e.key];let t=await ie(e),r=await oe(e);if(!Array.isArray(t))throw Error('Key "map" requires a source list');if(r===void 0)throw Error('Key "map" must define a model');let n=[];for(let o=0;o<t.length;o++){let s=Object.deepClone(r);await $(s,{...e.options,root:{...e.root,index:o,item:t[o],instance:s}}),n.push(await se(e,s))}return n}}});var Qe=()=>({concat:async(e)=>{let t=[];for(let r of Array.isArray(e.value)?e.value:[e.value])t.push(...await Object.select(e.root,r));return t.filter((r)=>r!==void 0)}});Array.prototype.findOrFail=function(e,t,r){let n=this.find(e,r);if(n===void 0)throw Error(t??"Element not found");return n};Array.flat=function(e){if(Array.isArray(e))return e.flat(2);else return[e]};Array.prototype.forEachAsync=async function(e){for(let t=0;t<this.length;t++)await e(this[t],t,this)};Array.prototype.groupBy=function(e){return this.reduce((t,r)=>{let n=e(r);if(!t[n])t[n]=[];return t[n].push(r),t},{})};Array.prototype.createInstances=function(e,...t){return this.map((r,n)=>new e(...t,r,n))};Array.prototype.mapAsync=async function(e){return Promise.all(this.map(e))};Array.prototype.nonNullMap=function(e){let t=[];for(let r=0;r<this.length;r++){let n=e(this[r],r,this);if(n!=null)t.push(n)}return t};Array.prototype.nonNullMapAsync=async function(e){let t=[];for(let r=0;r<this.length;r++){let n=await e(this[r],r,this);if(n!=null)t.push(n)}return t};Array.prototype.mergeAll=function(e){let t={};for(let r of this.toReversed())Object.merge(r,t,e);return t};Array.prototype.toObject=function(e,t){return Object.fromEntries(this.map((r)=>{let n=e(r),o=t?t(r):r;return[n,o]}))};Array.prototype.toObjectWithKey=function(e){return Object.fromEntries(this.map((t)=>[String(t[e]),t]))};Array.prototype.selectFor=function(e,t,r,n){let o=this.find(e,n);if(o===void 0)throw Error(r??"Element not found");return t(o)};Array.prototype.sortBy=function(e,t=!0){return this.slice().sort((r,n)=>{let o=e(r),s=e(n);if(o<s)return t?-1:1;if(o>s)return t?1:-1;return 0})};Array.prototype.unique=function(){return Array.from(new Set(this))};Array.prototype.uniqueBy=function(e){let t=new Set;return this.filter((r)=>{let n=e(r);if(t.has(n))return!1;else return t.add(n),!0})};var hn;((e)=>{e[e.Explore=0]="Explore",e[e.SkipSiblings=1]="SkipSiblings",e[e.NoExplore=2]="NoExplore",e[e.ReplaceParent=3]="ReplaceParent",e[e.DeleteParent=4]="DeleteParent",e[e.MergeParent=5]="MergeParent",e[e.ReplaceItem=6]="ReplaceItem",e[e.DeleteItem=7]="DeleteItem"})(hn||={});class d{action;by;skipSiblings;reexplore;constructor(e,t,r,n){this.action=e,this.by=t,this.skipSiblings=r,this.reexplore=n}static _explore=new d(0);static _noExplore=new d(2);static _skipSiblings=new d(1);static _deleteParent=new d(4);static ReplaceParent(e,t){return new d(3,e,void 0,t)}static SkipSiblings(){return d._skipSiblings}static Explore(){return d._explore}static NoExplore(){return d._noExplore}static DeleteParent(){return d._deleteParent}static MergeParent(e){return new d(5,e)}static ReplaceItem(e,t){return new d(6,e,t)}static DeleteItem(e){return new d(7,void 0,e)}}Object.navigate=async(e,t)=>{let r=new WeakSet,n=[],o=[],s=async(a,u,m)=>{let y=a===null,g=y?d.Explore():await t({key:a,value:u,path:n,parent:m,parents:o});if(u&&typeof u==="object"&&g.action===0){if(r.has(u))return g;if(r.add(u),!y)n.push(a),o.push(m);let O=u;while(await l(O,a,m))O=m[a];if(!y)o.pop(),n.pop()}return g},l=async(a,u,m)=>{let y=Object.keys(a),g=y.length;for(let O=0;O<g;O++){let b=y[O],k=a[b],w=await s(b,k,a),A=w.action;if(A===0||A===2)continue;if(A===6){if(a[b]=w.by,w.skipSiblings)return;continue}if(A===7){if(delete a[b],w.skipSiblings)return;continue}if(A===1)return;if(A===3){if(u===null)throw Error("Cannot replace root object");if(m[u]=w.by,w.reexplore)return!0;return}if(A===4){if(u===null)throw Error("Cannot delete root object");delete m[u];return}if(A===5)delete a[b],Object.assign(a,w.by)}};await s(null,e,null)};Object.find=async function(e,t){let r=[];return await Object.navigate(e,(n)=>{if(t([...n.path,n.key].join("."),n.value))r.push(n.value);return d.Explore()}),r};Object.merge=(e,t,r)=>{for(let n of Object.keys(t)){if(e[n]===void 0)continue;let o=t[n],s=e[n];if(typeof s!==typeof o||Array.isArray(s)!==Array.isArray(o)){let a=r?.mismatch?.(n,s,o,e,t);if(a!==void 0){t[n]=a;continue}throw Error(`Type mismatch: ${n}`)}let l=r?.mode?.(n,s,o,e,t)??t[".merge"]??"merge";switch(l){case"source":t[n]=s;continue;case"target":continue;case"skip":delete t[n],delete e[n];continue;case"merge":break;default:throw Error(`Unknown merge mode: ${l}`)}if(typeof s==="object")if(Array.isArray(s))o.push(...s);else{if(r?.navigate?.(n,s,o,e,t)===!1)continue;Object.merge(s,o,r)}else{if(s===o)continue;let a=r?.conflict?.(n,s,o,e,t);t[n]=a===void 0?o:a}}for(let n of Object.keys(e))if(t[n]===void 0)t[n]=e[n]};var dn=/^\[([^=\]]*)([=]*)([^\]]*)\]$/,bn=/^([^[\]]*)\[([^\]]*)]$/,Oe=(e,t,r,n)=>{if(e.startsWith("{")&&e.endsWith("}")){let o=e.substring(1,e.length-1);return Object.select(t,o,r)?.toString()}return n?e:void 0},wn=(e,t,r,n)=>{let o=Oe(t,r,n);if(o)return Object.select(e,o,n);let s=dn.exec(t);if(s){let[,a,u,m]=s,y=Oe(a.trim(),r,n,!0),g=Oe(m.trim(),r,n,!0);if(Array.isArray(e)&&(u==="="||u==="==")&&y)return e.find((O)=>O?.[y]==g)}let l=bn.exec(t);if(l){let[,a,u]=l;return e?.[a]?.[u]}return e?.[t]};Object.select=(e,t,r)=>{let n=void 0,o=void 0,s=t??"",l=(g)=>{if(!g)return[g,!1];return g.endsWith("?")?[g.substring(0,g.length-1),!0]:[g,!1]},a=(g,O)=>{let[b,k]=l(O.pop());if(!b){if(r?.set!==void 0&&o!==void 0&&n!==void 0)n[o]=r.set;return g}let w=wn(g,b,e,r);if(w===void 0){if(k||r?.optional||r?.defaultValue!==void 0)return;throw Error(`Unknown path element: "${b}" in "${s}"`)}return n=g,o=b,a(w,O)},u=s.splitNested(r?.separator??".","{","}"),m=void 0;if(u.length>0&&u[u.length-1].startsWith("?="))m=u.pop()?.substring(2);u.reverse();let y=a(e,u);if(y===void 0)return m??r?.defaultValue;return y};Object.deepClone=function(e){if(typeof structuredClone<"u")try{return structuredClone(e)}catch{}return JSON.parse(JSON.stringify(e))};Object.toList=function(e,t){return Object.entries(e).map(([r,n])=>({[t]:r,...n}))};Object.mapEntries=function(e,t){let r=Object.entries(e).map(([n,o])=>t(n,o));return Object.fromEntries(r)};global.AsyncFunction=Object.getPrototypeOf(async function(){}).constructor;global.defined=(e,t="Value is undefined")=>{if(e===void 0||e===null)throw Error(t);return e};String.prototype.tokenize=function(e,t=/\${([^}]+)}/g){return this.replace(t,(r,n)=>{let o=e[n];if(o===null||o===void 0)return"";if(typeof o==="string")return o;if(typeof o==="number"||typeof o==="boolean")return String(o);return String(o)})};String.prototype.toPascal=function(){return this.replace(/((?:[_ ]+)\w|^\w)/g,(e,t)=>t.toUpperCase()).replace(/[_ ]/g,"")};String.prototype.capitalize=function(){return this.replace(/((?:[ ]+)\w|^\w)/g,(e,t)=>t.toUpperCase())};String.prototype.toCamel=function(){return this.toPascal().replace(/((?:[ ]+\w)|^\w)/g,(e,t)=>t.toLowerCase())};String.prototype.toSnake=function(){return this.replace(/([a-z])([A-Z])/g,"$1_$2").replace(/\s+/g,"_")};String.prototype.toKebab=function(){return this.replace(/([a-z])([A-Z])/g,"$1-$2").replace(/\s+/g,"-")};String.prototype.changeCase=function(e){switch(e){case"upper":return this.toUpperCase();case"lower":return this.toLowerCase();case"pascal":return this.toPascal();case"camel":return this.toCamel();case"snake":return this.toSnake();case"kebab":return this.toKebab();default:throw Error(`Unsupported case type: ${e}`)}};String.prototype.splitWithQuotes=function(e=","){let t=[],r=this.length,n=e.length,o=0,s=(l)=>{if(l+n>r)return!1;for(let a=0;a<n;a++)if(this[l+a]!==e[a])return!1;return!0};while(o<r){while(o<r&&this[o]===" ")o++;if(o>=r)break;let l="",a=this[o]==='"'||this[o]==="'";if(a){let u=this[o++];while(o<r&&this[o]!==u)l+=this[o++];if(o<r)o++}else{while(o<r&&!s(o)){let u=this[o];if(u==='"'||u==="'"){l+=u,o++;while(o<r&&this[o]!==u)l+=this[o++];if(o<r)l+=this[o++]}else l+=this[o++]}l=l.trim()}if(l)t.push({value:l,quoted:a});if(s(o))o+=n}return t};String.prototype.splitNested=function(e,t,r){let n=0,o="",s=[];for(let l of this){if(o+=l,l===t)n++;if(l===r)n--;if(n===0&&l===e)s.push(o.slice(0,-1)),o=""}if(o)s.push(o);return s};String.prototype.padBlock=function(e,t=`
10
11
  `,r=" "){let n=r.repeat(e);return this.split(t).map((o)=>n+o).join(t)};String.prototype.stripIndent=function(){let e=this.split(/\r?\n/),t=e.filter((n)=>n.trim().length>0).map((n)=>/^[ \t]*/.exec(n)?.[0].length??0),r=t.length>0?Math.min(...t):0;if(r===0)return this;return e.map((n)=>n.slice(r)).join(`
11
- `)};function Qo(e,t="Value is undefined"){if(e===void 0||e===null)throw Error(t);return e}class qn{options;constructor(e){this.options={level:"INFO",showClass:!1,levels:["DEBUG","VERBOSE","INFO","WARN","ERROR"],timeStamp:!1,timeOptions:{second:"2-digit",minute:"2-digit",hour:"2-digit",day:"2-digit",month:"2-digit",year:"2-digit"},logFunction:(t,...r)=>{switch(t){case"ERROR":console.error(...r);break;case"WARN":console.warn(...r);break;case"DEBUG":console.debug(...r);break;case"VERBOSE":console.log(...r);break;default:console.log(...r)}},...e}}write(e,...t){if(this.options.level){let o=this.options.levels.indexOf(this.options.level)??-1,s=this.options.levels.indexOf(e);if(s===-1)throw Error(`Unknown log level: ${e}`);if(s<o)return}let r=[],n=[];if(this.options.timeStamp)n.push(new Date().toLocaleString(this.options.timeLocale,this.options.timeOptions));if(this.options.showClass)n.push(e);if(n.length>0)r.push(`[${n.join(" ")}]`);r.push(...t),this.options.logFunction(e,...r)}info(...e){this.write("INFO",...e)}error(...e){this.write("ERROR",...e)}warn(...e){this.write("WARN",...e)}debug(...e){this.write("DEBUG",...e)}verbose(...e){this.write("VERBOSE",...e)}}var rt=()=>({extends:async(e)=>{let t=async(r,n)=>{for(let o of Array.isArray(n)?n:[n]){let s=await Object.select(e.root,o),l=Object.deepClone(s);if(l[e.key])await t(l,l[e.key]);await R(l,{...e.options}),Object.merge(l,r),delete r[e.key]}};return await t(e.parent,e.value),v.Explore()},group:(e)=>{let t=e.root.parent,r=e.value,{items:n,...o}=r;return r.items.forEach((s)=>t.push({...o,...s})),v.DeleteParent()}});var nt=(e)=>({skip:{types:{0:"boolean"},fn:(t)=>t.value?v.DeleteParent():v.DeleteItem()},metadata:({path:t,value:r})=>{return e.metadata(t,r),v.DeleteItem()},if:{types:{0:"boolean"},fn:async(t)=>{let r=t.parent[".then"],n=t.parent[".else"];if(r!==void 0)delete t.parent[".then"];if(n!==void 0)delete t.parent[".else"];let o=t.value?r:n;if(o===void 0)return v.DeleteItem();if(typeof o==="string")return(await R({value:o},{...t.options,root:{...t.root}})).value;return v.ReplaceParent(o,!0)}},switch:(t)=>{let r=t.value;if(!r.cases)throw Error("Missing cases for switch");if(r.cases[r.from]!==void 0)return v.ReplaceParent(r.cases[r.from],!0);if(r.default!==void 0)return v.ReplaceParent(r.default,!0);return v.DeleteParent()}});var ot=()=>({from:async({root:e,parent:t,value:r})=>{let n=await Object.select(e,r);if(n===null||n===void 0)throw Error(`Unable to resolve reference: ${r}`);if(t.content){if(Array.isArray(t.content)&&Array.isArray(n))return[...n,...t.content];return Object.merge(n,t.content),t.content}return n}});import it from"node:vm";var st=(e)=>({modules:async(t)=>{for(let[r,n]of Object.entries(t.value)){let o=it.createContext({console,objector:e,document:t.root}),s=new it.SourceTextModule(n,{identifier:r,context:o});await s.link((l)=>{throw Error(`Module ${l} is not allowed`)}),await s.evaluate(),e.sources(Object.fromEntries(Object.entries(s.namespace).map(([l,a])=>[`${r}.${l}`,(u)=>a(u,...u.args)])))}return v.DeleteItem()}});var at=()=>({try:{fn:(e)=>{let t=e.parent[".catch"];if(t!==void 0)delete e.parent[".catch"];try{return e.value}catch(r){if(t!==void 0)return t;return v.DeleteItem()}}}});var lt=()=>({let:{fn:(e)=>{let t=e.value;return Object.assign(e.root,t),v.DeleteItem()}}});var ut=()=>({tap:{fn:(e)=>{return console.log(`[tap] ${e.path}:`,e.value),e.value}}});var Kn=(e,t)=>{let r=t.section.config.using,n=e.getFunctions();return r?Object.fromEntries(r.map((o)=>{if(o in n)return[o,n[o]];if(o in t.root)return[o,t.root[o]];throw Error(`Function or variable "${o}" not found for script section`)})):n},je=(e,t,r,n,o=[])=>{let s=Kn(e,r),l=["section","context","config","system",...Object.keys(s),...o],a=[t,r.root,r.section.config,e,...Object.values(s)];return[new AsyncFunction(...l,n).bind(r),a]},Yn=(e,t)=>{let r={write:(...n)=>{return t.push(...n),r},writeLine:(...n)=>{return t.push(...n.map((o)=>o+`
12
+ `)};function Po(e,t="Value is undefined"){if(e===void 0||e===null)throw Error(t);return e}class On{options;constructor(e){this.options={level:"INFO",showClass:!1,levels:["DEBUG","VERBOSE","INFO","WARN","ERROR"],timeStamp:!1,timeOptions:{second:"2-digit",minute:"2-digit",hour:"2-digit",day:"2-digit",month:"2-digit",year:"2-digit"},logFunction:(t,...r)=>{switch(t){case"ERROR":console.error(...r);break;case"WARN":console.warn(...r);break;case"DEBUG":console.debug(...r);break;case"VERBOSE":console.log(...r);break;default:console.log(...r)}},...e}}write(e,...t){if(this.options.level){let o=this.options.levels.indexOf(this.options.level)??-1,s=this.options.levels.indexOf(e);if(s===-1)throw Error(`Unknown log level: ${e}`);if(s<o)return}let r=[],n=[];if(this.options.timeStamp)n.push(new Date().toLocaleString(this.options.timeLocale,this.options.timeOptions));if(this.options.showClass)n.push(e);if(n.length>0)r.push(`[${n.join(" ")}]`);r.push(...t),this.options.logFunction(e,...r)}info(...e){this.write("INFO",...e)}error(...e){this.write("ERROR",...e)}warn(...e){this.write("WARN",...e)}debug(...e){this.write("DEBUG",...e)}verbose(...e){this.write("VERBOSE",...e)}}var Ze=()=>({extends:async(e)=>{let t=async(r,n)=>{for(let o of Array.isArray(n)?n:[n]){let s=await Object.select(e.root,o),l=Object.deepClone(s);if(l[e.key])await t(l,l[e.key]);await $(l,{...e.options}),Object.merge(l,r),delete r[e.key]}};return await t(e.parent,e.value),d.Explore()},group:(e)=>{let t=e.root.parent,r=e.value,{items:n,...o}=r;return r.items.forEach((s)=>t.push({...o,...s})),d.DeleteParent()}});var Xe=(e)=>({skip:{types:{0:"boolean"},fn:(t)=>t.value?d.DeleteParent():d.DeleteItem()},metadata:({path:t,value:r})=>{return e.metadata(t,r),d.DeleteItem()},if:{types:{0:"boolean"},fn:async(t)=>{let r=t.parent[".then"],n=t.parent[".else"];if(r!==void 0)delete t.parent[".then"];if(n!==void 0)delete t.parent[".else"];let o=t.value?r:n;if(o===void 0)return d.DeleteItem();if(typeof o==="string")return(await $({value:o},{...t.options,root:{...t.root}})).value;return d.ReplaceParent(o,!0)}},switch:(t)=>{let r=t.value;if(!r.cases)throw Error("Missing cases for switch");if(r.cases[r.from]!==void 0)return d.ReplaceParent(r.cases[r.from],!0);if(r.default!==void 0)return d.ReplaceParent(r.default,!0);return d.DeleteParent()}});var et=()=>({from:async({root:e,parent:t,value:r})=>{let n=await Object.select(e,r);if(n===null||n===void 0)throw Error(`Unable to resolve reference: ${r}`);if(t.content){if(Array.isArray(t.content)&&Array.isArray(n))return[...n,...t.content];return Object.merge(n,t.content),t.content}return n}});import tt from"node:vm";var rt=(e)=>({modules:async(t)=>{for(let[r,n]of Object.entries(t.value)){let o=tt.createContext({console,objector:e,document:t.root}),s=new tt.SourceTextModule(n,{identifier:r,context:o});await s.link((l)=>{throw Error(`Module ${l} is not allowed`)}),await s.evaluate(),e.sources(Object.fromEntries(Object.entries(s.namespace).map(([l,a])=>[`${r}.${l}`,(u)=>a(u,...u.args)])))}return d.DeleteItem()}});var nt=()=>({try:{fn:(e)=>{let t=e.parent[".catch"];if(t!==void 0)delete e.parent[".catch"];try{return e.value}catch(r){if(t!==void 0)return t;return d.DeleteItem()}}}});var ot=()=>({let:{fn:(e)=>{let t=e.value;return Object.assign(e.root,t),d.DeleteItem()}}});var it=()=>({tap:{fn:(e)=>{return console.log(`[tap] ${e.path}:`,e.value),e.value}}});var An=(e,t)=>{let r=t.section.config.using,n=e.getFunctions();return r?Object.fromEntries(r.map((o)=>{if(o in n)return[o,n[o]];if(o in t.root)return[o,t.root[o]];throw Error(`Function or variable "${o}" not found for script section`)})):n},Ae=(e,t,r,n,o=[])=>{let s=An(e,r),l=["section","context","config","system",...Object.keys(s),...o],a=[t,r.root,r.section.config,e,...Object.values(s)];return[new AsyncFunction(...l,n).bind(r),a]},jn=(e,t)=>{let r={write:(...n)=>{return t.push(...n),r},writeLine:(...n)=>{return t.push(...n.map((o)=>o+`
12
13
  `)),r},clear:()=>{return t.splice(0,t.length),r},prepend:(...n)=>{return t.unshift(...n),r},prependLine:(...n)=>{return t.unshift(...n.map((o)=>o+`
13
- `)),r},setOptions:(n)=>{return Object.assign(e.section,n),r},use:(n)=>{return n(r),r},getLines:()=>t};return r},Gn=async(e,t,r)=>{let n=r.section.config.condition;if(n!==void 0){let[o,s]=je(e,t,r,`return (${n})`);if(!await o(...s))return!1}return!0},ct=(e)=>async(t)=>{let r=[],n=Yn(t,r);if(!await Gn(e,n,t))return!1;let[o,s]=je(e,n,t,t.section.content,["item"]),l=t.section.config.each;if(l){let[a,u]=je(e,n,t,`return (${l})`),b=Array.isArray(l)?l:await a(...u);if(!Array.isArray(b))throw Error('The "each" property of a script section must return an array');for(let w of b){let m=await o(...s,w);if(typeof m<"u")r.push(m)}}else{let a=await o(...s);if(typeof a<"u")return a}if(r.length===0)return!1;return r.join("")};var ft=(e)=>({script:ct(e)});import pt from"fs/promises";import X from"path";var gt=(e)=>({include:async(t)=>{let{file:r}=t.options.globalContext;return await He(t.args[0],{cwd:X.dirname(r),filter:(n)=>X.basename(r)!==n,map:async(n)=>e.load(n,X.dirname(r),t.root)})},exists:async({args:[t]})=>await we(t),file:async(t)=>await pt.readFile(await oe(t.args[0],e.getIncludeDirectories())).then((r)=>r.toString()),scan:async(t)=>{let r=[],o=(()=>{let a=t.args[2]??["**/node_modules/**"],u=typeof a==="string"?a.split(",").map((b)=>b.trim()):a;if(!Array.isArray(u))throw Error("Scan exclusion must be a list");return u})(),{file:s}=t.options.globalContext,l=t.args[1]?await oe(t.args[1],e.getIncludeDirectories()):X.dirname(s);for await(let a of pt.glob(t.args[0],{cwd:l,exclude:(u)=>o.some((b)=>X.matchesGlob(u,b))}))r.push(a);return r}});var mt=(e)=>({substring:{types:{0:"ref",1:"number",2:"number"},fn:(t)=>t.args[0].substring(t.args[1],t.args[2])},repeat:{types:{0:"ref",1:"number"},fn:({args:[t,r]})=>t.repeat(r)},pad:{types:{0:"ref",1:"number",2:"string"},fn:({args:[t,r],tags:n})=>{let o=n.join?.[0]??`
14
- `,s=n.padChar?.[0]??" ";return t.padBlock(r??2,o,s)}},formatAs:{fn:({args:[t,r],tags:n})=>{let o=e.getEncoder(r);if(!o)throw Error("Unsupported format: "+String(r));let s=[];if(o.options?.includeTags)s=[n];return o.fn(t,...s)}}});var ue=(e,t=0,r)=>{let n=" ".repeat(t),o=" ".repeat(t+1);if(e===null||e===void 0)return"null";else if(typeof e==="boolean")return String(e);else if(typeof e==="number")return String(e);else if(typeof e==="string")return`"${e.replace(/\\/g,"\\\\").replace(/"/g,"\\\"").replace(/\n/g,"\\n").replace(/\r/g,"\\r").replace(/\t/g,"\\t")}"`;else if(Array.isArray(e)){if(e.length===0)return"[]";return`[
15
- ${e.map((l)=>`${o}${ue(l,t+1)},`).join(`
14
+ `)),r},setOptions:(n)=>{return Object.assign(e.section,n),r},use:(n)=>{return n(r),r},getLines:()=>t};return r},Sn=async(e,t,r)=>{let n=r.section.config.condition;if(n!==void 0){let[o,s]=Ae(e,t,r,`return (${n})`);if(!await o(...s))return!1}return!0},st=(e)=>async(t)=>{let r=[],n=jn(t,r);if(!await Sn(e,n,t))return!1;let[o,s]=Ae(e,n,t,t.section.content,["item"]),l=t.section.config.each;if(l){let[a,u]=Ae(e,n,t,`return (${l})`),m=Array.isArray(l)?l:await a(...u);if(!Array.isArray(m))throw Error('The "each" property of a script section must return an array');for(let y of m){let g=await o(...s,y);if(typeof g<"u")r.push(g)}}else{let a=await o(...s);if(typeof a<"u")return a}if(r.length===0)return!1;return r.join("")};var at=(e)=>({script:st(e)});import lt from"fs/promises";import T from"path";var ut=(e)=>({include:async(t)=>{let{file:r}=t.options.globalContext;return await Je(t.args[0],{cwd:T.dirname(r),filter:(n)=>T.basename(r)!==n,map:async(n)=>e.load(n,T.dirname(r),t.root)})},exists:async({args:[t]})=>await be(t),file:async(t)=>await lt.readFile(await ne(t.args[0],e.getIncludeDirectories())).then((r)=>r.toString()),scan:async(t)=>{let r=[],o=(()=>{let a=t.args[2]??["**/node_modules/**"],u=typeof a==="string"?a.split(",").map((m)=>m.trim()):a;if(!Array.isArray(u))throw Error("Scan exclusion must be a list");return u})(),{file:s}=t.options.globalContext,l=t.args[1]?await ne(t.args[1],e.getIncludeDirectories()):T.dirname(s);for await(let a of lt.glob(t.args[0],{cwd:l,exclude:(u)=>o.some((m)=>T.matchesGlob(u,m))}))r.push(a);return r}});var ct=(e)=>({substring:{types:{0:"ref",1:"number",2:"number"},fn:(t)=>t.args[0].substring(t.args[1],t.args[2])},repeat:{types:{0:"ref",1:"number"},fn:({args:[t,r]})=>t.repeat(r)},pad:{types:{0:"ref",1:"number",2:"string"},fn:({args:[t,r],tags:n})=>{let o=n.join?.[0]??`
15
+ `,s=n.padChar?.[0]??" ";return t.padBlock(r??2,o,s)}},formatAs:{fn:({args:[t,r],tags:n})=>{let o=e.getEncoder(r);if(!o)throw Error("Unsupported format: "+String(r));let s=[];if(o.options?.includeTags)s=[n];return o.fn(t,...s)}}});var le=(e,t=0,r)=>{let n=" ".repeat(t),o=" ".repeat(t+1);if(e===null||e===void 0)return"null";else if(typeof e==="boolean")return String(e);else if(typeof e==="number")return String(e);else if(typeof e==="string")return`"${e.replace(/\\/g,"\\\\").replace(/"/g,"\\\"").replace(/\n/g,"\\n").replace(/\r/g,"\\r").replace(/\t/g,"\\t")}"`;else if(Array.isArray(e)){if(e.length===0)return"[]";return`[
16
+ ${e.map((l)=>`${o}${le(l,t+1)},`).join(`
16
17
  `)}
17
18
  ${n}]`}else if(typeof e==="object"){let s=Object.entries(e).sort((a,u)=>r?.sortKeys?a[0].localeCompare(u[0]):0);if(s.length===0)return"{}";return`{
18
- ${s.map(([a,u])=>`${o}${a} = ${ue(u,t+1,r)}`).join(`
19
+ ${s.map(([a,u])=>`${o}${a} = ${le(u,t+1,r)}`).join(`
19
20
  `)}
20
- ${n}}`}else return String(e)},H=(e)=>{if(!e)return e;return e.replaceAll("\\n",`
21
- `).replaceAll("\\$","$").replaceAll("\\t","\t")};var yt=()=>({...T({merge:(...e)=>e.flatMap((t)=>t)}),join:({args:[e],root:t,tags:r})=>{let n=r.key?.[0],o=r.separator?.[0]??r.sep?.[0],s=r.finalize?.length>0,l=H(o);if(typeof e==="string"){if(s&&e.length&&l)return e+l;return e}if(!Array.isArray(e))throw Error("Object is not a list");let a=((n?.length)?e.map((m)=>Object.select({...t,...m},n)):e).join(l),u=r.pad?.[0]??"0",b=r.padChar?.[0]??" ",w=s&&a.length&&l?a+l:a;return u?w.padBlock(parseInt(u),`
22
- `,b):w},range:({args:[e,t,r]})=>{let n=parseInt(e),o=parseInt(t),s=parseInt(r)||1;if(isNaN(n))throw Error("Invalid range: start value '"+String(e)+"' is not a number");if(isNaN(o))throw Error("Invalid range: end value '"+String(t)+"' is not a number");if(s===0)throw Error("Invalid range: step cannot be zero");if((o-n)/s<0)throw Error("Invalid range: step "+String(s)+" has wrong direction for range "+String(n)+" to "+String(o));return Array.from({length:Math.floor((o-n)/s)+1},(l,a)=>n+a*s)},filter:{types:(e,t,r)=>{switch(e){case 0:return"array";case 1:return Object.keys(x)}return le[r[1].value]?.(e-2,t,r.slice(2))},fn:({args:[e,t,r],root:n,tags:o})=>{if(e===null||e===void 0)throw Error("Filter source cannot be null or undefined");if(!Array.isArray(e))throw Error("Filter source must be an array");let s=o.key?.[0],l=x[t];if(s){let u=Array(e.length);for(let w=0;w<e.length;w++)try{u[w]=Object.select({...n,...e[w]},s)}catch{u[w]=Symbol("invalid")}let b=[];for(let w=0;w<e.length;w++){let m=u[w];if(typeof m!=="symbol"&&r===void 0?l(m):l(m,r))b.push(e[w])}return b}let a=[];for(let u of e)if(r===void 0?l(u):l(u,r))a.push(u);return a}}});var dt=()=>({each:{processArgs:!1,fn:async({rawArgs:[e,t,...r],root:n,options:o,tags:s})=>{let l=async(y)=>y.quoted?H(y.value):await Object.select(n,y.value),a=await Object.select(n,e.value),u=await l(t),b=s.key?.[0],w=Array.isArray(a)?a:Object.toList(a,"name"),m=[],g=await Promise.all(r.map(async(y)=>await l(y))),d={...n,item:void 0,index:0,params:g,instance:void 0,parent:n.this,tags:s},E={...o,root:d};for(let y=0;y<w.length;y++){let j=Object.deepClone(u),h={instance:j},k=typeof u==="string"?h:j;if(d.item=w[y],d.index=y,d.instance=j,s?.root?.[0])Object.assign(d,await Object.select(d,s.root[0]));if(await R(k,E),b!==void 0)m.push(await Object.select(h.instance,b));else m.push(h.instance)}if(s.join?.length){if(m.length===0)return"";let y=H(s.join[0]),j=s.pad?.[0]??"0",h=s.padChar?.[0]??" ",k=s.finalize?.length&&y?y:"",O=`${m.join(y)}${k}`;return j?O.padBlock(parseInt(j),`
23
- `,h):O}return m}}});var Q=async(e,t,r)=>e.rawArgs[t].quoted?e.rawArgs[t].value:await Object.select(e.root,e.rawArgs[t].value,{defaultValue:r}),ht=()=>({switch:{processArgs:!1,fn:async(e)=>{let t=await Q(e,0,!1),r=await Q(e,1);if(r[t]===void 0){if(e.rawArgs.length>2)return Q(e,2);throw Error(`Unhandled switch case: ${t}`)}return r[t]}}});var bt=()=>({if:{types:{0:"boolean"},fn:(e)=>e.args[0]?e.args[1]:e.args[2]},check:{types:{0:Object.keys(x)},fn:(e)=>x[e.args[0]](...e.args.slice(1))},...T(x,{types:le})});var wt=(e)=>({default:{processArgs:!1,fn:async(t)=>{for(let r=0;r<t.rawArgs.length;r++)if(t.rawArgs[r]?.value!==void 0){let o=await Q(t,r,null);if(o!==null)return o}if(t.tags.nullable?.length)return v.DeleteItem();if(t.tags.fail?.length)throw Error(`No valid value found for default (${t.rawArgs.map((r)=>r.value).join(", ")})`);return""}},section:{types:["string","boolean"],fn:(t)=>{let r=t.args[0];if(!(t.args[1]??!0))return null;let o=e.getSection(r);if(!o)throw Error(`Section not found: ${r}`);return o.content}}});var Ot=()=>({convert:({args:[e,t,r]})=>{switch(t){case"string":return String(e);case"number":{let n=Number(e);if(!isNaN(n))return v.ReplaceItem(n);break}case"boolean":if(e==="true"||e===!0||e===1||e==="1"||e==="yes"||e==="on")return v.ReplaceItem(!0);else if(e==="false"||e===!1||e===0||e==="0"||e==="no"||e==="off")return v.ReplaceItem(!1);break;default:throw Error(`Unsupported type for convert: ${t}`)}if(r!==void 0)return v.ReplaceItem(r);throw Error(`Failed to convert value to ${t}`)},isType:({args:[e,t]})=>{let n=(()=>{switch(t){case"string":return typeof e==="string";case"number":return typeof e==="number";case"boolean":return typeof e==="boolean";case"object":return e!==null&&typeof e==="object"&&!Array.isArray(e);case"array":return Array.isArray(e);case"null":return e===null;case"undefined":return e===void 0;case"function":return typeof e==="function";default:throw Error(`Unknown type for isType: ${t}`)}})();return v.ReplaceItem(n)},typeOf:({args:[e]})=>{if(e===null)return"null";else if(Array.isArray(e))return"array";else return typeof e}});var At=(e)=>{var t,r,n,o,s,l,a,u,b,w,m,g,d,E,y,j,h,k,O,S,M,Z,W,C,P,J,ee,B,ce,te,fe,jt,vt,Et,St,kt,Mt,Ft,Dt,Rt,$t,Ct,xt,Nt,Wt,It,Lt,_t,Ut,Bt,qt,Kt,Yt,Gt,Tt,Vt,Xt,Ht,Qt,zt,Zt,Pt,Jt,er,tr,rr,nr,or,ir,sr,ar,lr,ur,cr,fr,pr,gr,mr,yr,dr,hr,br,wr,Or,Ar,jr,vr,Er,Sr,kr,Mr,Fr,Dr,Rr,$r,Cr,xr,Nr,Wr,Ir,Lr,_r,Ur,Br,o,s,l,a,u,b,w,m,g,d,E,y,j,h,k,O,S,M,Z,W,C,P,J,ee,B,ce,te,fe,jt,vt,Et,St,kt,Mt,Ft,Dt,Rt,$t,Ct,xt,Nt,Wt,It,Lt,_t,Ut,Bt,qt,Kt,Yt,Gt,Tt,Vt,Xt,Ht,Qt,zt,Zt,Pt,Jt,er,tr,rr,nr,or,ir,sr,ar,lr,ur,cr,fr,pr,gr,mr,yr,dr,hr,br,wr,Or,Ar,jr,vr,Er,Sr,kr,Mr,Fr,Dr,Rr,$r,Cr,xr,Nr,Wr,Ir,Lr,_r,Ur,Br;return e.use((n=V,o=[f()],s=[f()],l=[f()],a=[f()],u=[f()],b=[f()],w=[f()],m=[f()],g=[f()],d=[f()],E=[f()],y=[f()],j=[f()],h=[f()],k=[f()],O=[f()],S=[f()],M=[f()],Z=[f()],W=[f()],C=[f()],P=[f()],J=[f()],ee=[f()],B=[f()],ce=[f()],te=[f()],fe=[f()],jt=[f()],vt=[f()],Et=[f()],St=[f()],kt=[f()],Mt=[f()],Ft=[f()],Dt=[f()],Rt=[f()],$t=[f()],Ct=[f()],xt=[f()],Nt=[f()],Wt=[f()],It=[f()],Lt=[f()],_t=[f()],Ut=[f()],Bt=[f()],qt=[f()],Kt=[f()],Yt=[f()],Gt=[f()],Tt=[f()],Vt=[f()],Xt=[f()],Ht=[f()],Qt=[f()],zt=[f()],Zt=[f()],Pt=[f()],Jt=[f()],er=[f()],tr=[f()],rr=[f()],nr=[f()],or=[f()],ir=[f()],sr=[f()],ar=[f()],lr=[f()],ur=[f()],cr=[f()],fr=[f()],pr=[f()],gr=[f()],mr=[f()],yr=[f()],dr=[f()],hr=[f()],br=[f()],wr=[f()],Or=[f()],Ar=[f()],jr=[f()],vr=[f()],Er=[f()],Sr=[f()],kr=[f()],Mr=[f()],Fr=[f()],Dr=[f()],Rr=[f()],$r=[f()],Cr=[f()],xr=[f()],Nr=[f()],Wr=[f()],Ir=[f()],Lr=[f()],_r=[f()],Ur=[f()],Br=[f()],r=Re(n),t=class extends n{constructor(){super(...arguments);Ce(r,5,this)}env(i){return process.env[i]}uuid(){return crypto.randomUUID()}pascal(i){return i.toPascal()}camel(i){return i.toCamel()}capital(i){return i.capitalize()}snake(i,p="lower"){return i.changeCase(p).toSnake()}kebab(i,p="lower"){return i.changeCase(p).toKebab()}len(i){return i.length}reverse(i){return i.split("").reverse().join("")}concat(...i){return i.join("")}trim(i){return i.trim()}ltrim(i){return i.trimStart()}rtrim(i){return i.trimEnd()}lower(i){return i.toLowerCase()}upper(i){return i.toUpperCase()}encode(i,p){return Buffer.from(i).toString(p??"base64")}decode(i,p){return Buffer.from(i,p??"base64").toString()}list(i,p="name"){return Object.toList(i,p)}object(i,p="name"){return i.toObject((A)=>A[p],(A)=>{let{[p]:D,...$}=A;return $})}pathJoin(...i){return N.join(...i)}resolve(...i){return N.resolve(...i)}dirname(i){return N.dirname(i)}basename(i,p){return N.basename(i,p)}normalize(i){return N.normalize(i)}extname(i){return N.extname(i)}relative(i,p){return N.relative(i,p)}isAbsolute(i){return N.isAbsolute(i)}segments(i){return i.split("/").filter(Boolean)}log(...i){console.log(...i)}md5(i){return U("md5").update(i).digest("hex")}sha1(i){return U("sha1").update(i).digest("hex")}sha256(i){return U("sha256").update(i).digest("hex")}sha512(i){return U("sha512").update(i).digest("hex")}hash(i,p="sha256"){return U(p).update(i).digest("hex")}hmac(i,p,A="sha256"){return U(A).update(i).digest("hex")}base64Encode(i){return Buffer.from(i).toString("base64")}base64Decode(i){return Buffer.from(i,"base64").toString("utf-8")}hexEncode(i){return Buffer.from(i).toString("hex")}hexDecode(i){return Buffer.from(i,"hex").toString("utf-8")}add(...i){return i.reduce((p,A)=>p+A,0)}subtract(i,p){return i-p}multiply(...i){return i.reduce((p,A)=>p*A,1)}divide(i,p){if(p===0)throw Error("Division by zero");return i/p}modulo(i,p){return i%p}power(i,p){return Math.pow(i,p)}sqrt(i){return Math.sqrt(i)}abs(i){return Math.abs(i)}floor(i){return Math.floor(i)}ceil(i){return Math.ceil(i)}round(i,p){let A=Math.pow(10,p??0);return Math.round(i*A)/A}min(...i){return Math.min(...i)}max(...i){return Math.max(...i)}clamp(i,p,A){return Math.max(p,Math.min(A,i))}random(i,p){let A=i??0,D=p??1;return Math.random()*(D-A)+A}timestamp(i){return new Date(i).getTime()}iso(i){return new Date(i).toISOString()}utc(i){return new Date(i).toUTCString()}formatDate(i,p){let A=new Date(i),D=A.getFullYear(),$=String(A.getMonth()+1).padStart(2,"0"),re=String(A.getDate()).padStart(2,"0"),q=String(A.getHours()).padStart(2,"0"),qr=String(A.getMinutes()).padStart(2,"0"),Kr=String(A.getSeconds()).padStart(2,"0");return p.replace("YYYY",String(D)).replace("MM",$).replace("DD",re).replace("HH",q).replace("mm",qr).replace("ss",Kr)}parseDate(i){return new Date(i).getTime()}year(i){return new Date(i).getFullYear()}month(i){return new Date(i).getMonth()+1}day(i){return new Date(i).getDate()}dayOfWeek(i){return new Date(i).getDay()}hours(i){return new Date(i).getHours()}minutes(i){return new Date(i).getMinutes()}seconds(i){return new Date(i).getSeconds()}regexTest(i,p,A){return new RegExp(i,A).test(p)}regexMatch(i,p,A){return new RegExp(i,A).exec(p)}regexMatchAll(i,p,A){return Array.from(p.matchAll(new RegExp(i,A)))}regexReplace(i,p,A,D){return A.replace(new RegExp(i,D),p)}regexReplaceAll(i,p,A,D){return A.replace(new RegExp(i,D??"g"),p)}regexSplit(i,p,A){return p.split(new RegExp(i,A))}regexExec(i,p,A){return new RegExp(i,A).exec(p)}regexSearch(i,p,A){return p.search(new RegExp(i,A))}unique(i,p){if(!Array.isArray(i))return i;let A=new Set;return i.filter((D)=>{let $=p?D[p]:D;if(A.has($))return!1;return A.add($),!0})}groupBy(i,p){if(!Array.isArray(i))return i;let A={};return i.forEach((D)=>{let $=String(D[p]);if(!A[$])A[$]=[];A[$].push(D)}),A}chunk(i,p=1){if(!Array.isArray(i))return[];let A=[];for(let D=0;D<i.length;D+=p)A.push(i.slice(D,D+p));return A}flatten(i,p=1){if(!Array.isArray(i))return[i];let A=[],D=($,re)=>{for(let q of $)if(Array.isArray(q)&&re>0)D(q,re-1);else A.push(q)};return D(i,p),A}compact(i){if(!Array.isArray(i))return i;return i.filter((p)=>p!==null&&p!==void 0)}head(i,p){if(!Array.isArray(i))return i;return p?i.slice(0,p):i[0]}tail(i,p){if(!Array.isArray(i))return i;return p?i.slice(-p):i[i.length-1]}isEmail(i){return/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(i)}isUrl(i){try{return new URL(i),!0}catch{return!1}}isJson(i){try{return JSON.parse(i),!0}catch{return!1}}isUuid(i){return/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i.test(i)}minLength(i,p){return i?.length>=p}maxLength(i,p){return i?.length<=p}lengthEquals(i,p){return i?.length===p}isNumber(i){return typeof i==="number"&&!isNaN(i)}isString(i){return typeof i==="string"}isBoolean(i){return typeof i==="boolean"}isArray(i){return Array.isArray(i)}isObject(i){return i!==null&&typeof i==="object"&&!Array.isArray(i)}isEmpty(i){if(i===null||i===void 0)return!0;if(typeof i==="string"||Array.isArray(i))return i.length===0;if(typeof i==="object")return Object.keys(i).length===0;return!1}isTruthy(i){return!!i}isFalsy(i){return!i}inRange(i,p,A){return i>=p&&i<=A}matchesPattern(i,p){return new RegExp(p).test(i)}includes(i,p){if(typeof i==="string")return i.includes(String(p));return Array.isArray(i)&&i.includes(p)}startsWith(i,p){return i.startsWith(p)}endsWith(i,p){return i.endsWith(p)}},c(r,1,"env",o,t),c(r,1,"uuid",s,t),c(r,1,"pascal",l,t),c(r,1,"camel",a,t),c(r,1,"capital",u,t),c(r,1,"snake",b,t),c(r,1,"kebab",w,t),c(r,1,"len",m,t),c(r,1,"reverse",g,t),c(r,1,"concat",d,t),c(r,1,"trim",E,t),c(r,1,"ltrim",y,t),c(r,1,"rtrim",j,t),c(r,1,"lower",h,t),c(r,1,"upper",k,t),c(r,1,"encode",O,t),c(r,1,"decode",S,t),c(r,1,"list",M,t),c(r,1,"object",Z,t),c(r,1,"pathJoin",W,t),c(r,1,"resolve",C,t),c(r,1,"dirname",P,t),c(r,1,"basename",J,t),c(r,1,"normalize",ee,t),c(r,1,"extname",B,t),c(r,1,"relative",ce,t),c(r,1,"isAbsolute",te,t),c(r,1,"segments",fe,t),c(r,1,"log",jt,t),c(r,1,"md5",vt,t),c(r,1,"sha1",Et,t),c(r,1,"sha256",St,t),c(r,1,"sha512",kt,t),c(r,1,"hash",Mt,t),c(r,1,"hmac",Ft,t),c(r,1,"base64Encode",Dt,t),c(r,1,"base64Decode",Rt,t),c(r,1,"hexEncode",$t,t),c(r,1,"hexDecode",Ct,t),c(r,1,"add",xt,t),c(r,1,"subtract",Nt,t),c(r,1,"multiply",Wt,t),c(r,1,"divide",It,t),c(r,1,"modulo",Lt,t),c(r,1,"power",_t,t),c(r,1,"sqrt",Ut,t),c(r,1,"abs",Bt,t),c(r,1,"floor",qt,t),c(r,1,"ceil",Kt,t),c(r,1,"round",Yt,t),c(r,1,"min",Gt,t),c(r,1,"max",Tt,t),c(r,1,"clamp",Vt,t),c(r,1,"random",Xt,t),c(r,1,"timestamp",Ht,t),c(r,1,"iso",Qt,t),c(r,1,"utc",zt,t),c(r,1,"formatDate",Zt,t),c(r,1,"parseDate",Pt,t),c(r,1,"year",Jt,t),c(r,1,"month",er,t),c(r,1,"day",tr,t),c(r,1,"dayOfWeek",rr,t),c(r,1,"hours",nr,t),c(r,1,"minutes",or,t),c(r,1,"seconds",ir,t),c(r,1,"regexTest",sr,t),c(r,1,"regexMatch",ar,t),c(r,1,"regexMatchAll",lr,t),c(r,1,"regexReplace",ur,t),c(r,1,"regexReplaceAll",cr,t),c(r,1,"regexSplit",fr,t),c(r,1,"regexExec",pr,t),c(r,1,"regexSearch",gr,t),c(r,1,"unique",mr,t),c(r,1,"groupBy",yr,t),c(r,1,"chunk",dr,t),c(r,1,"flatten",hr,t),c(r,1,"compact",br,t),c(r,1,"head",wr,t),c(r,1,"tail",Or,t),c(r,1,"isEmail",Ar,t),c(r,1,"isUrl",jr,t),c(r,1,"isJson",vr,t),c(r,1,"isUuid",Er,t),c(r,1,"minLength",Sr,t),c(r,1,"maxLength",kr,t),c(r,1,"lengthEquals",Mr,t),c(r,1,"isNumber",Fr,t),c(r,1,"isString",Dr,t),c(r,1,"isBoolean",Rr,t),c(r,1,"isArray",$r,t),c(r,1,"isObject",Cr,t),c(r,1,"isEmpty",xr,t),c(r,1,"isTruthy",Nr,t),c(r,1,"isFalsy",Wr,t),c(r,1,"inRange",Ir,t),c(r,1,"matchesPattern",Lr,t),c(r,1,"includes",_r,t),c(r,1,"startsWith",Ur,t),c(r,1,"endsWith",Br,t),ge(r,t),t)).keys({...Ze(e),...Pe(e),...Je(),...et(),...ot(),...tt(),...rt(),...nt(e),...st(e),...at(),...lt(),...ut()}).sources({...gt(e),...mt(e),...Ot(),...yt(),...dt(),...ht(),...bt(),...wt(e)}).sections(ft(e)).fieldOptions({configParser:Bun.YAML.parse,onSection:(i)=>{if(i.section.config.name)e.section(i.section)}}).decoders({yaml:{matching:["\\.yml$","\\.yaml$"],fn:Bun.YAML.parse}}).encoders({json:{fn:(i)=>JSON.stringify(i,null,2)},yaml:{fn:(i)=>Bun.YAML.stringify(i,null,2)},terraform:{options:{includeTags:!0},fn:(i,p)=>ue(i,0,{sortKeys:!!(p?.sort?.length??p?.sortKeys?.length)})}})};import Tn from"fs/promises";import z from"path";class ve{includeDirectories=[];baseIncludeDirectories=[];includes=[];addDirectories(...e){this.includeDirectories.push(...e),this.baseIncludeDirectories.push(...e)}getDirectories(){return this.includeDirectories}reset(){this.includeDirectories=[...this.baseIncludeDirectories]}restore(e){this.includeDirectories=[...e]}snapshot(){return[...this.includeDirectories]}addFiles(...e){this.includes.push(...e)}getPendingAndClear(){let e=[...this.includes];return this.includes.length=0,e}async processPatterns(e,t,r){let n=[];for(let o of e)if(_.isGlobPattern(o)){let s=(await Array.fromAsync(Tn.glob(o,{cwd:t}))).map((l)=>z.join(t,l));for(let l of s)if(!r.included.includes(l))n.push(l)}else if(_.isDirectoryPattern(o)){let s=z.isAbsolute(o)?o:z.join(t,o);if(!this.includeDirectories.includes(s))this.includeDirectories.push(s)}else n.push(o);return n}buildSearchDirs(e){let t=e?[e]:[];return t.push(...this.includeDirectories.map((r)=>z.isAbsolute(r)?r:z.join(e??process.cwd(),r))),t}}class Ee{includeManager;loadFn;constructor(e,t){this.includeManager=e;this.loadFn=t}async processIncludes(e,t,r){let n=[];if(e.content.includes)n.push(...e.content.includes),delete e.content.includes;n.push(...this.includeManager.getPendingAndClear());let o=await this.includeManager.processPatterns(n,e.folderPath,r);for(let s of o)Object.merge(await this.loadFn(s,e.folderPath,{parent:e.content,...t},!0,r),e.content)}}class Vn{includeManager=new ve;includeProcessor;cacheManager=new Oe(100);outputs=[];vars={};funcs={};fields={sources:{},keys:{},sections:{}};objectMetadata={};currentContext=null;storedSections={};dataEncoders={};dataDecoders={};constructor(){this.includeProcessor=new Ee(this.includeManager,this.load.bind(this)),this.use(At)}use(e){if(e.prototype instanceof V)new e(this);else e(this);return this}includeDirectory(...e){return this.includeManager.addDirectories(...e),this}getIncludeDirectories(){return this.includeManager.getDirectories()}include(...e){return this.includeManager.addFiles(...e),this}keys(e){return Object.assign(this.fields.keys,{...this.fields.keys,...e}),this}sources(e){return Object.assign(this.fields.sources,{...this.fields.sources,...e}),this}sections(e){return Object.assign(this.fields.sections,{...this.fields.sections,...e}),this}variables(e){return this.vars={...this.vars,...e},this}functions(e){return this.funcs={...this.funcs,...e},this}getFunctions(){return this.funcs}getOutputs(){return this.outputs}output(e){return this.outputs.push(e),this}metadata(e,t){return this.objectMetadata[e]=t,this}getMetadata(e){return this.objectMetadata[e]}getAllMetadata(){return this.objectMetadata}setCacheMaxSize(e){return this.cacheManager.setMaxSize(e),this}clearCache(){return this.cacheManager.clear(),this}getCurrentContext(){return this.currentContext}fieldOptions(e){return this.fields={...this.fields,...e},this}section(e){return this.storedSections[e.config.name]=e,this}getSection(e){return this.storedSections[e]}encoders(e){return this.dataEncoders={...this.dataEncoders,...e},this}decoders(e){return this.dataDecoders={...this.dataDecoders,...e},this}getEncoder(e){return this.dataEncoders[e]}getDecoder(e){return this.dataDecoders[e]}filter(e){return this.fields.filters??=[],this.fields.filters.push(e),this}async loadObject(e,t,r){return R(e,{...this.fields,globalContext:{file:r?.fullPath??"@internal"},root:{...t,...this.fields.root,...this.vars,functions:this.funcs,context:this.currentContext,sections:this.storedSections,$document:{root:{content:e},fileName:r?.fileName??"@internal",folder:r?.folderPath??"@internal",fullPath:r?.fullPath??"@internal"}}})}async load(e,t,r,n,o){let s=this.includeManager.snapshot();try{this.includeManager.reset();let l=this.includeManager.buildSearchDirs(t);if(o)this.currentContext=o;this.currentContext??={included:[],document:null};let a=await Xe(e,{dirs:l,parsers:this.dataDecoders,format:"yaml"}),u=_.normalize(a.fullPath);if(this.currentContext.included.push(u),!a.content)return null;let b=this.cacheManager.get(u),w;if(b)w=b.raw;else w=a.content,this.cacheManager.set(u,{raw:w,timestamp:Date.now()});let m=Object.deepClone(w);a.content=m,await this.includeProcessor.processIncludes(a,r,this.currentContext);let g;if(n!==!0)g=await this.loadObject(a.content,r,{fileName:a.fullPath,folderPath:a.folderPath,fullPath:a.fullPath});else g=a.content;return this.currentContext.document=g,g}catch(l){throw this.includeManager.restore(s),l}finally{this.includeManager.restore(s)}}async writeAll(e){await ze(this.getOutputs(),e)}}export{ze as writeOutputs,xn as writeOutput,$n as writeFormat,fo as variable,po as sharedFunction,uo as section,R as processFields,T as makeFieldProcessorMap,Hn as makeFieldProcessorList,Ye as makeFieldProcessor,f as macro,oe as locate,Xe as loadFormat,co as key,Wn as importList,ao as importGlob,He as globMap,_e as getProcessor,hn as getArgs,we as exists,go as encoder,Qo as defined,mo as decoder,x as conditionPredicates,V as ObjectorPlugin,Vn as Objector,v as NavigateResult,Ln as NavigateAction,qn as Logger};
21
+ ${n}}`}else return String(e)},V=(e)=>{if(!e)return e;return e.replaceAll("\\n",`
22
+ `).replaceAll("\\$","$").replaceAll("\\t","\t")};var ft=()=>({...J({merge:(...e)=>e.flatMap((t)=>t)}),join:({args:[e],root:t,tags:r})=>{let n=r.key?.[0],o=r.separator?.[0]??r.sep?.[0],s=r.finalize?.length>0,l=V(o);if(typeof e==="string"){if(s&&e.length&&l)return e+l;return e}if(!Array.isArray(e))throw Error("Object is not a list");let a=((n?.length)?e.map((g)=>Object.select({...t,...g},n)):e).join(l),u=r.pad?.[0]??"0",m=r.padChar?.[0]??" ",y=s&&a.length&&l?a+l:a;return u?y.padBlock(parseInt(u),`
23
+ `,m):y},range:({args:[e,t,r]})=>{let n=parseInt(e),o=parseInt(t),s=parseInt(r)||1;if(isNaN(n))throw Error("Invalid range: start value '"+String(e)+"' is not a number");if(isNaN(o))throw Error("Invalid range: end value '"+String(t)+"' is not a number");if(s===0)throw Error("Invalid range: step cannot be zero");if((o-n)/s<0)throw Error("Invalid range: step "+String(s)+" has wrong direction for range "+String(n)+" to "+String(o));return Array.from({length:Math.floor((o-n)/s)+1},(l,a)=>n+a*s)},filter:{types:(e,t,r)=>{switch(e){case 0:return"array";case 1:return Object.keys(D)}return ae[r[1].value]?.(e-2,t,r.slice(2))},fn:({args:[e,t,r],root:n,tags:o})=>{if(e===null||e===void 0)throw Error("Filter source cannot be null or undefined");if(!Array.isArray(e))throw Error("Filter source must be an array");let s=o.key?.[0],l=D[t];if(s){let u=Array(e.length);for(let y=0;y<e.length;y++)try{u[y]=Object.select({...n,...e[y]},s)}catch{u[y]=Symbol("invalid")}let m=[];for(let y=0;y<e.length;y++){let g=u[y];if(typeof g!=="symbol"&&r===void 0?l(g):l(g,r))m.push(e[y])}return m}let a=[];for(let u of e)if(r===void 0?l(u):l(u,r))a.push(u);return a}}});var pt=()=>({each:{processArgs:!1,fn:async({rawArgs:[e,t,...r],root:n,options:o,tags:s})=>{let l=async(w)=>w.quoted?V(w.value):await Object.select(n,w.value),a=await Object.select(n,e.value),u=await l(t),m=s.key?.[0],y=Array.isArray(a)?a:Object.toList(a,"name"),g=[],O=await Promise.all(r.map(async(w)=>await l(w))),b={...n,item:void 0,index:0,params:O,instance:void 0,parent:n.this,tags:s},k={...o,root:b};for(let w=0;w<y.length;w++){let A=Object.deepClone(u),M={instance:A},v=typeof u==="string"?M:A;if(b.item=y[w],b.index=w,b.instance=A,s?.root?.[0])Object.assign(b,await Object.select(b,s.root[0]));if(await $(v,k),m!==void 0)g.push(await Object.select(M.instance,m));else g.push(M.instance)}if(s.join?.length){if(g.length===0)return"";let w=V(s.join[0]),A=s.pad?.[0]??"0",M=s.padChar?.[0]??" ",v=s.finalize?.length&&w?w:"",P=`${g.join(w)}${v}`;return A?P.padBlock(parseInt(A),`
24
+ `,M):P}return g}}});var z=async(e,t,r)=>e.rawArgs[t].quoted?e.rawArgs[t].value:await Object.select(e.root,e.rawArgs[t].value,{defaultValue:r}),gt=()=>({switch:{processArgs:!1,fn:async(e)=>{let t=await z(e,0,!1),r=await z(e,1);if(r[t]===void 0){if(e.rawArgs.length>2)return z(e,2);throw Error(`Unhandled switch case: ${t}`)}return r[t]}}});var mt=()=>({if:{types:{0:"boolean"},fn:(e)=>e.args[0]?e.args[1]:e.args[2]},check:{types:{0:Object.keys(D)},fn:(e)=>D[e.args[0]](...e.args.slice(1))},...J(D,{types:ae})});var yt=(e)=>({default:{processArgs:!1,fn:async(t)=>{for(let r=0;r<t.rawArgs.length;r++)if(t.rawArgs[r]?.value!==void 0){let o=await z(t,r,null);if(o!==null)return o}if(t.tags.nullable?.length)return d.DeleteItem();if(t.tags.fail?.length)throw Error(`No valid value found for default (${t.rawArgs.map((r)=>r.value).join(", ")})`);return""}},section:{types:["string","boolean"],fn:(t)=>{let r=t.args[0];if(!(t.args[1]??!0))return null;let o=e.getSection(r);if(!o)throw Error(`Section not found: ${r}`);return o.content}}});var ht=()=>({convert:({args:[e,t,r]})=>{switch(t){case"string":return String(e);case"number":{let n=Number(e);if(!isNaN(n))return d.ReplaceItem(n);break}case"boolean":if(e==="true"||e===!0||e===1||e==="1"||e==="yes"||e==="on")return d.ReplaceItem(!0);else if(e==="false"||e===!1||e===0||e==="0"||e==="no"||e==="off")return d.ReplaceItem(!1);break;default:throw Error(`Unsupported type for convert: ${t}`)}if(r!==void 0)return d.ReplaceItem(r);throw Error(`Failed to convert value to ${t}`)},isType:({args:[e,t]})=>{let n=(()=>{switch(t){case"string":return typeof e==="string";case"number":return typeof e==="number";case"boolean":return typeof e==="boolean";case"object":return e!==null&&typeof e==="object"&&!Array.isArray(e);case"array":return Array.isArray(e);case"null":return e===null;case"undefined":return e===void 0;case"function":return typeof e==="function";default:throw Error(`Unknown type for isType: ${t}`)}})();return d.ReplaceItem(n)},typeOf:({args:[e]})=>{if(e===null)return"null";else if(Array.isArray(e))return"array";else return typeof e}});var dt=(e)=>{var t,r,n,o,s,l,a,u,m,y,g,O,b,k,w,A,M,v,P,E,F,G,x,C,Q,Z,X,W,ue,ee,ce,bt,wt,Ot,At,jt,St,vt,Et,kt,Ft,Pt,$t,Mt,Rt,Ct,Dt,Nt,xt,It,_t,Ut,Lt,Wt,Bt,qt,Kt,Jt,Yt,Tt,Vt,zt,Ht,Gt,Qt,Zt,Xt,er,tr,rr,nr,or,ir,sr,ar,lr,ur,cr,fr,pr,gr,mr,yr,hr,dr,br,wr,Or,Ar,jr,Sr,vr,Er,kr,Fr,Pr,$r,Mr,Rr,Cr,Dr,Nr,xr,Ir,o,s,l,a,u,m,y,g,O,b,k,w,A,M,v,P,E,F,G,x,C,Q,Z,X,W,ue,ee,ce,bt,wt,Ot,At,jt,St,vt,Et,kt,Ft,Pt,$t,Mt,Rt,Ct,Dt,Nt,xt,It,_t,Ut,Lt,Wt,Bt,qt,Kt,Jt,Yt,Tt,Vt,zt,Ht,Gt,Qt,Zt,Xt,er,tr,rr,nr,or,ir,sr,ar,lr,ur,cr,fr,pr,gr,mr,yr,hr,dr,br,wr,Or,Ar,jr,Sr,vr,Er,kr,Fr,Pr,$r,Mr,Rr,Cr,Dr,Nr,xr,Ir;return e.use((n=Y,o=[f()],s=[f()],l=[f()],a=[f()],u=[f()],m=[f()],y=[f()],g=[f()],O=[f()],b=[f()],k=[f()],w=[f()],A=[f()],M=[f()],v=[f()],P=[f()],E=[f()],F=[f()],G=[f()],x=[f()],C=[f()],Q=[f()],Z=[f()],X=[f()],W=[f()],ue=[f()],ee=[f()],ce=[f()],bt=[f()],wt=[f()],Ot=[f()],At=[f()],jt=[f()],St=[f()],vt=[f()],Et=[f()],kt=[f()],Ft=[f()],Pt=[f()],$t=[f()],Mt=[f()],Rt=[f()],Ct=[f()],Dt=[f()],Nt=[f()],xt=[f()],It=[f()],_t=[f()],Ut=[f()],Lt=[f()],Wt=[f()],Bt=[f()],qt=[f()],Kt=[f()],Jt=[f()],Yt=[f()],Tt=[f()],Vt=[f()],zt=[f()],Ht=[f()],Gt=[f()],Qt=[f()],Zt=[f()],Xt=[f()],er=[f()],tr=[f()],rr=[f()],nr=[f()],or=[f()],ir=[f()],sr=[f()],ar=[f()],lr=[f()],ur=[f()],cr=[f()],fr=[f()],pr=[f()],gr=[f()],mr=[f()],yr=[f()],hr=[f()],dr=[f()],br=[f()],wr=[f()],Or=[f()],Ar=[f()],jr=[f()],Sr=[f()],vr=[f()],Er=[f()],kr=[f()],Fr=[f()],Pr=[f()],$r=[f()],Mr=[f()],Rr=[f()],Cr=[f()],Dr=[f()],Nr=[f()],xr=[f()],Ir=[f()],r=$e(n),t=class extends n{constructor(){super(...arguments);Re(r,5,this)}env(i){return process.env[i]}uuid(){return crypto.randomUUID()}pascal(i){return i.toPascal()}camel(i){return i.toCamel()}capital(i){return i.capitalize()}snake(i,p="lower"){return i.changeCase(p).toSnake()}kebab(i,p="lower"){return i.changeCase(p).toKebab()}len(i){return i.length}reverse(i){return i.split("").reverse().join("")}concat(...i){return i.join("")}trim(i){return i.trim()}ltrim(i){return i.trimStart()}rtrim(i){return i.trimEnd()}lower(i){return i.toLowerCase()}upper(i){return i.toUpperCase()}encode(i,p){return Buffer.from(i).toString(p??"base64")}decode(i,p){return Buffer.from(i,p??"base64").toString()}list(i,p="name"){return Object.toList(i,p)}object(i,p="name"){return i.toObject((h)=>h[p],(h)=>{let{[p]:S,...R}=h;return R})}pathJoin(...i){return N.join(...i)}resolve(...i){return N.resolve(...i)}dirname(i){return N.dirname(i)}basename(i,p){return N.basename(i,p)}normalize(i){return N.normalize(i)}extname(i){return N.extname(i)}relative(i,p){return N.relative(i,p)}isAbsolute(i){return N.isAbsolute(i)}segments(i){return i.split("/").filter(Boolean)}log(...i){console.log(...i)}md5(i){return L("md5").update(i).digest("hex")}sha1(i){return L("sha1").update(i).digest("hex")}sha256(i){return L("sha256").update(i).digest("hex")}sha512(i){return L("sha512").update(i).digest("hex")}hash(i,p="sha256"){return L(p).update(i).digest("hex")}hmac(i,p,h="sha256"){return L(h).update(i).digest("hex")}base64Encode(i){return Buffer.from(i).toString("base64")}base64Decode(i){return Buffer.from(i,"base64").toString("utf-8")}hexEncode(i){return Buffer.from(i).toString("hex")}hexDecode(i){return Buffer.from(i,"hex").toString("utf-8")}add(...i){return i.reduce((p,h)=>p+h,0)}subtract(i,p){return i-p}multiply(...i){return i.reduce((p,h)=>p*h,1)}divide(i,p){if(p===0)throw Error("Division by zero");return i/p}modulo(i,p){return i%p}power(i,p){return Math.pow(i,p)}sqrt(i){return Math.sqrt(i)}abs(i){return Math.abs(i)}floor(i){return Math.floor(i)}ceil(i){return Math.ceil(i)}round(i,p){let h=Math.pow(10,p??0);return Math.round(i*h)/h}min(...i){return Math.min(...i)}max(...i){return Math.max(...i)}clamp(i,p,h){return Math.max(p,Math.min(h,i))}random(i,p){let h=i??0,S=p??1;return Math.random()*(S-h)+h}timestamp(i){return new Date(i).getTime()}iso(i){return new Date(i).toISOString()}utc(i){return new Date(i).toUTCString()}formatDate(i,p){let h=new Date(i),S=h.getFullYear(),R=String(h.getMonth()+1).padStart(2,"0"),te=String(h.getDate()).padStart(2,"0"),B=String(h.getHours()).padStart(2,"0"),_r=String(h.getMinutes()).padStart(2,"0"),Ur=String(h.getSeconds()).padStart(2,"0");return p.replace("YYYY",String(S)).replace("MM",R).replace("DD",te).replace("HH",B).replace("mm",_r).replace("ss",Ur)}parseDate(i){return new Date(i).getTime()}year(i){return new Date(i).getFullYear()}month(i){return new Date(i).getMonth()+1}day(i){return new Date(i).getDate()}dayOfWeek(i){return new Date(i).getDay()}hours(i){return new Date(i).getHours()}minutes(i){return new Date(i).getMinutes()}seconds(i){return new Date(i).getSeconds()}regexTest(i,p,h){return new RegExp(i,h).test(p)}regexMatch(i,p,h){return new RegExp(i,h).exec(p)}regexMatchAll(i,p,h){return Array.from(p.matchAll(new RegExp(i,h)))}regexReplace(i,p,h,S){return h.replace(new RegExp(i,S),p)}regexReplaceAll(i,p,h,S){return h.replace(new RegExp(i,S??"g"),p)}regexSplit(i,p,h){return p.split(new RegExp(i,h))}regexExec(i,p,h){return new RegExp(i,h).exec(p)}regexSearch(i,p,h){return p.search(new RegExp(i,h))}unique(i,p){if(!Array.isArray(i))return i;let h=new Set;return i.filter((S)=>{let R=p?S[p]:S;if(h.has(R))return!1;return h.add(R),!0})}groupBy(i,p){if(!Array.isArray(i))return i;let h={};return i.forEach((S)=>{let R=String(S[p]);if(!h[R])h[R]=[];h[R].push(S)}),h}chunk(i,p=1){if(!Array.isArray(i))return[];let h=[];for(let S=0;S<i.length;S+=p)h.push(i.slice(S,S+p));return h}flatten(i,p=1){if(!Array.isArray(i))return[i];let h=[],S=(R,te)=>{for(let B of R)if(Array.isArray(B)&&te>0)S(B,te-1);else h.push(B)};return S(i,p),h}compact(i){if(!Array.isArray(i))return i;return i.filter((p)=>p!==null&&p!==void 0)}head(i,p){if(!Array.isArray(i))return i;return p?i.slice(0,p):i[0]}tail(i,p){if(!Array.isArray(i))return i;return p?i.slice(-p):i[i.length-1]}isEmail(i){return/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(i)}isUrl(i){try{return new URL(i),!0}catch{return!1}}isJson(i){try{return JSON.parse(i),!0}catch{return!1}}isUuid(i){return/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i.test(i)}minLength(i,p){return i?.length>=p}maxLength(i,p){return i?.length<=p}lengthEquals(i,p){return i?.length===p}isNumber(i){return typeof i==="number"&&!isNaN(i)}isString(i){return typeof i==="string"}isBoolean(i){return typeof i==="boolean"}isArray(i){return Array.isArray(i)}isObject(i){return i!==null&&typeof i==="object"&&!Array.isArray(i)}isEmpty(i){if(i===null||i===void 0)return!0;if(typeof i==="string"||Array.isArray(i))return i.length===0;if(typeof i==="object")return Object.keys(i).length===0;return!1}isTruthy(i){return!!i}isFalsy(i){return!i}inRange(i,p,h){return i>=p&&i<=h}matchesPattern(i,p){return new RegExp(p).test(i)}includes(i,p){if(typeof i==="string")return i.includes(String(p));return Array.isArray(i)&&i.includes(p)}startsWith(i,p){return i.startsWith(p)}endsWith(i,p){return i.endsWith(p)}},c(r,1,"env",o,t),c(r,1,"uuid",s,t),c(r,1,"pascal",l,t),c(r,1,"camel",a,t),c(r,1,"capital",u,t),c(r,1,"snake",m,t),c(r,1,"kebab",y,t),c(r,1,"len",g,t),c(r,1,"reverse",O,t),c(r,1,"concat",b,t),c(r,1,"trim",k,t),c(r,1,"ltrim",w,t),c(r,1,"rtrim",A,t),c(r,1,"lower",M,t),c(r,1,"upper",v,t),c(r,1,"encode",P,t),c(r,1,"decode",E,t),c(r,1,"list",F,t),c(r,1,"object",G,t),c(r,1,"pathJoin",x,t),c(r,1,"resolve",C,t),c(r,1,"dirname",Q,t),c(r,1,"basename",Z,t),c(r,1,"normalize",X,t),c(r,1,"extname",W,t),c(r,1,"relative",ue,t),c(r,1,"isAbsolute",ee,t),c(r,1,"segments",ce,t),c(r,1,"log",bt,t),c(r,1,"md5",wt,t),c(r,1,"sha1",Ot,t),c(r,1,"sha256",At,t),c(r,1,"sha512",jt,t),c(r,1,"hash",St,t),c(r,1,"hmac",vt,t),c(r,1,"base64Encode",Et,t),c(r,1,"base64Decode",kt,t),c(r,1,"hexEncode",Ft,t),c(r,1,"hexDecode",Pt,t),c(r,1,"add",$t,t),c(r,1,"subtract",Mt,t),c(r,1,"multiply",Rt,t),c(r,1,"divide",Ct,t),c(r,1,"modulo",Dt,t),c(r,1,"power",Nt,t),c(r,1,"sqrt",xt,t),c(r,1,"abs",It,t),c(r,1,"floor",_t,t),c(r,1,"ceil",Ut,t),c(r,1,"round",Lt,t),c(r,1,"min",Wt,t),c(r,1,"max",Bt,t),c(r,1,"clamp",qt,t),c(r,1,"random",Kt,t),c(r,1,"timestamp",Jt,t),c(r,1,"iso",Yt,t),c(r,1,"utc",Tt,t),c(r,1,"formatDate",Vt,t),c(r,1,"parseDate",zt,t),c(r,1,"year",Ht,t),c(r,1,"month",Gt,t),c(r,1,"day",Qt,t),c(r,1,"dayOfWeek",Zt,t),c(r,1,"hours",Xt,t),c(r,1,"minutes",er,t),c(r,1,"seconds",tr,t),c(r,1,"regexTest",rr,t),c(r,1,"regexMatch",nr,t),c(r,1,"regexMatchAll",or,t),c(r,1,"regexReplace",ir,t),c(r,1,"regexReplaceAll",sr,t),c(r,1,"regexSplit",ar,t),c(r,1,"regexExec",lr,t),c(r,1,"regexSearch",ur,t),c(r,1,"unique",cr,t),c(r,1,"groupBy",fr,t),c(r,1,"chunk",pr,t),c(r,1,"flatten",gr,t),c(r,1,"compact",mr,t),c(r,1,"head",yr,t),c(r,1,"tail",hr,t),c(r,1,"isEmail",dr,t),c(r,1,"isUrl",br,t),c(r,1,"isJson",wr,t),c(r,1,"isUuid",Or,t),c(r,1,"minLength",Ar,t),c(r,1,"maxLength",jr,t),c(r,1,"lengthEquals",Sr,t),c(r,1,"isNumber",vr,t),c(r,1,"isString",Er,t),c(r,1,"isBoolean",kr,t),c(r,1,"isArray",Fr,t),c(r,1,"isObject",Pr,t),c(r,1,"isEmpty",$r,t),c(r,1,"isTruthy",Mr,t),c(r,1,"isFalsy",Rr,t),c(r,1,"inRange",Cr,t),c(r,1,"matchesPattern",Dr,t),c(r,1,"includes",Nr,t),c(r,1,"startsWith",xr,t),c(r,1,"endsWith",Ir,t),pe(r,t),t)).keys({...Ve(e),...ze(e),...He(),...Ge(),...et(),...Qe(),...Ze(),...Xe(e),...rt(e),...nt(),...ot(),...it()}).sources({...ut(e),...ct(e),...ht(),...ft(),...pt(),...gt(),...mt(),...yt(e)}).sections(at(e)).fieldOptions({configParser:Bun.YAML.parse,onSection:(i)=>{if(i.section.config.name)e.section(i.section)}}).decoders({yaml:{matching:["\\.yml$","\\.yaml$"],fn:Bun.YAML.parse}}).encoders({json:{fn:(i)=>JSON.stringify(i,null,2)},yaml:{fn:(i)=>Bun.YAML.stringify(i,null,2)},terraform:{options:{includeTags:!0},fn:(i,p)=>le(i,0,{sortKeys:!!(p?.sort?.length??p?.sortKeys?.length)})}})};import vn from"fs/promises";import H from"path";class je{includeDirectories=[];baseIncludeDirectories=[];includes=[];addDirectories(...e){this.includeDirectories.push(...e),this.baseIncludeDirectories.push(...e)}getDirectories(){return this.includeDirectories}reset(){this.includeDirectories=[...this.baseIncludeDirectories]}restore(e){this.includeDirectories=[...e]}snapshot(){return[...this.includeDirectories]}addFiles(...e){this.includes.push(...e)}getPendingAndClear(){let e=[...this.includes];return this.includes.length=0,e}async processPatterns(e,t,r){let n=[];for(let o of e)if(U.isGlobPattern(o)){let s=(await Array.fromAsync(vn.glob(o,{cwd:t}))).map((l)=>H.join(t,l));for(let l of s)if(!r.included.includes(l))n.push(l)}else if(U.isDirectoryPattern(o)){let s=H.isAbsolute(o)?o:H.join(t,o);if(!this.includeDirectories.includes(s))this.includeDirectories.push(s)}else n.push(o);return n}buildSearchDirs(e){let t=e?[e]:[];return t.push(...this.includeDirectories.map((r)=>H.isAbsolute(r)?r:H.join(e??process.cwd(),r))),t}}class Se{includeManager;loadFn;constructor(e,t){this.includeManager=e;this.loadFn=t}async processIncludes(e,t,r){let n=[];if(e.content.includes)n.push(...e.content.includes),delete e.content.includes;n.push(...this.includeManager.getPendingAndClear());let o=await this.includeManager.processPatterns(n,e.folderPath,r);for(let s of o)Object.merge(await this.loadFn(s,e.folderPath,{parent:e.content,...t},!0,r),e.content)}}class En{includeManager=new je;includeProcessor;cacheManager=new we(100);outputs=[];vars={};funcs={};fields={sources:{},keys:{},sections:{}};objectMetadata={};currentContext=null;storedSections={};dataEncoders={};dataDecoders={};constructor(){this.includeProcessor=new Se(this.includeManager,this.load.bind(this)),this.use(dt)}use(e){if(e.prototype instanceof Y)new e(this);else e(this);return this}includeDirectory(...e){return this.includeManager.addDirectories(...e),this}getIncludeDirectories(){return this.includeManager.getDirectories()}include(...e){return this.includeManager.addFiles(...e),this}keys(e){return Object.assign(this.fields.keys,{...this.fields.keys,...e}),this}sources(e){return Object.assign(this.fields.sources,{...this.fields.sources,...e}),this}sections(e){return Object.assign(this.fields.sections,{...this.fields.sections,...e}),this}variables(e){return this.vars={...this.vars,...e},this}functions(e){return this.funcs={...this.funcs,...e},this}getFunctions(){return this.funcs}getOutputs(){return this.outputs}output(e){return this.outputs.push(e),this}metadata(e,t){return this.objectMetadata[e]=t,this}getMetadata(e){return this.objectMetadata[e]}getAllMetadata(){return this.objectMetadata}setCacheMaxSize(e){return this.cacheManager.setMaxSize(e),this}clearCache(){return this.cacheManager.clear(),this}getCurrentContext(){return this.currentContext}fieldOptions(e){return this.fields={...this.fields,...e},this}section(e){return this.storedSections[e.config.name]=e,this}getSection(e){return this.storedSections[e]}encoders(e){return this.dataEncoders={...this.dataEncoders,...e},this}decoders(e){return this.dataDecoders={...this.dataDecoders,...e},this}getEncoder(e){return this.dataEncoders[e]}getDecoder(e){return this.dataDecoders[e]}filter(e){return this.fields.filters??=[],this.fields.filters.push(e),this}async loadObject(e,t,r){return $(e,{...this.fields,globalContext:{file:r?.fullPath??"@internal"},root:{...t,...this.fields.root,...this.vars,functions:this.funcs,context:this.currentContext,sections:this.storedSections,$document:{root:{content:e},fileName:r?.fileName??"@internal",folder:r?.folderPath??"@internal",fullPath:r?.fullPath??"@internal"}}})}async load(e,t,r,n,o){let s=this.includeManager.snapshot();try{this.includeManager.reset();let l=this.includeManager.buildSearchDirs(t);if(o)this.currentContext=o;this.currentContext??={included:[],document:null};let a=await Ke(e,{dirs:l,parsers:this.dataDecoders,format:"yaml"}),u=U.normalize(a.fullPath);if(this.currentContext.included.push(u),!a.content)return null;let m=this.cacheManager.get(u),y;if(m)y=m.raw;else y=a.content,this.cacheManager.set(u,{raw:y,timestamp:Date.now()});let g=Object.deepClone(y);a.content=g,await this.includeProcessor.processIncludes(a,r,this.currentContext);let O;if(n!==!0)O=await this.loadObject(a.content,r,{fileName:a.fullPath,folderPath:a.folderPath,fullPath:a.fullPath});else O=a.content;return this.currentContext.document=O,O}catch(l){throw this.includeManager.restore(s),l}finally{this.includeManager.restore(s)}}async writeAll(e){await Te(this.getOutputs(),e)}}export{Te as writeOutputs,pn as writeOutput,cn as writeFormat,Jn as variable,Yn as sharedFunction,qn as section,$ as processFields,J as makeFieldProcessorMap,Fn as makeFieldProcessorList,Le as makeFieldProcessor,f as macro,ne as locate,Ke as loadFormat,Kn as key,mn as importList,Wn as importGlob,Je as globMap,Ne as getProcessor,Hr as getArgs,be as exists,Tn as encoder,Po as defined,Vn as decoder,D as conditionPredicates,Y as ObjectorPlugin,En as Objector,d as NavigateResult,hn as NavigateAction,On as Logger};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@homedev/objector",
3
- "version": "1.2.67",
3
+ "version": "1.3.0",
4
4
  "description": "object extensions for YAML/JSON",
5
5
  "author": "julzor",
6
6
  "license": "ISC",