@homedev/objector 1.2.50 → 1.2.52

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
@@ -78,6 +78,15 @@ export declare const deepClone: <T>(model: T) => T;
78
78
  */
79
79
  export declare const defined: <T>(value: T | undefined | null, msg?: string) => T;
80
80
 
81
+ declare interface Encoder {
82
+ fn: (data: unknown, ...args: any[]) => string | Promise<string>;
83
+ options?: EncoderOptions;
84
+ }
85
+
86
+ declare interface EncoderOptions {
87
+ includeTags?: boolean;
88
+ }
89
+
81
90
  export declare const exists: (fileName: string) => Promise<boolean>;
82
91
 
83
92
  export declare interface FieldContext {
@@ -202,6 +211,14 @@ export declare interface LoadContext {
202
211
  */
203
212
  export declare const loadFormat: <T = any>(fileName: string, options?: LoadOptions) => Promise<LoadResult<T>>;
204
213
 
214
+ /**
215
+ * @public
216
+ */
217
+ export declare interface LoadFormatParser {
218
+ matching?: string[];
219
+ fn: (data: string) => any;
220
+ }
221
+
205
222
  /**
206
223
  * @public
207
224
  */
@@ -216,7 +233,8 @@ export declare interface LoadObjectOptions {
216
233
  */
217
234
  export declare interface LoadOptions {
218
235
  dirs?: string[];
219
- parsers?: Record<string, (data: string) => any>;
236
+ parsers?: Record<string, LoadFormatParser>;
237
+ format?: string;
220
238
  }
221
239
 
222
240
  export declare interface LoadResult<T> {
@@ -386,6 +404,8 @@ export declare class Objector {
386
404
  private objectMetadata;
387
405
  private currentContext;
388
406
  private storedSections;
407
+ private dataEncoders;
408
+ private dataDecoders;
389
409
  constructor();
390
410
  use(handler: (o: Objector) => void): this;
391
411
  includeDirectory(...dirs: string[]): this;
@@ -406,6 +426,10 @@ export declare class Objector {
406
426
  fieldOptions(options: ProcessFieldsOptions): this;
407
427
  section(section: FieldProcessorSection): this;
408
428
  getSection(name: string): FieldProcessorSection | undefined;
429
+ encoders(encoders: Record<string, Encoder>): this;
430
+ decoders(decoders: Record<string, LoadFormatParser>): this;
431
+ getEncoder(name: string): Encoder | undefined;
432
+ getDecoder(name: string): LoadFormatParser | undefined;
409
433
  filter(f: RegExp): this;
410
434
  loadObject<T = any>(data: T, container?: any, options?: LoadObjectOptions): Promise<T>;
411
435
  load<T = unknown>(fileName: string, cwd?: string, container?: unknown, noProcess?: boolean, ld?: LoadContext): Promise<T | null>;
@@ -466,6 +490,7 @@ export declare interface ProcessFieldsOptions {
466
490
  globalContext?: any;
467
491
  onSection?: FieldProcessorSectionFunc;
468
492
  onSectionConfig?: FieldProcessorSectionConfigFunc;
493
+ configParser?: (configText: string) => any;
469
494
  }
470
495
 
471
496
  /**
@@ -627,7 +652,23 @@ export declare const toObject: <T extends Record<string, unknown>>(from: T[], ke
627
652
  */
628
653
  export declare const toObjectWithKey: <T extends Record<string, unknown>>(from: T[], key?: string) => Record<string, T>;
629
654
 
630
- export declare const writeFormat: (filePath: string, content: any, format?: "yaml" | "json" | "text") => Promise<void>;
655
+ export declare const writeFormat: (filePath: string, content: any, options?: WriteFormatOptions) => Promise<void>;
656
+
657
+ /**
658
+ * @public
659
+ */
660
+ export declare interface WriteFormatEncoder {
661
+ matching?: string[];
662
+ fn: (data: any) => Promise<string> | string;
663
+ }
664
+
665
+ /**
666
+ * @public
667
+ */
668
+ export declare interface WriteFormatOptions {
669
+ format: string;
670
+ encoders?: Record<string, WriteFormatEncoder>;
671
+ }
631
672
 
632
673
  export declare const writeOutput: (o: Output, options?: WriteOutputOption) => Promise<void>;
633
674
 
package/dist/index.js CHANGED
@@ -1,21 +1,21 @@
1
- var st=Object.create;var{getPrototypeOf:at,defineProperty:X,getOwnPropertyNames:ke}=Object;var Ee=Object.prototype.hasOwnProperty,S=(e,r,t)=>{for(let n of ke(r))if(!Ee.call(e,n)&&n!=="default")X(e,n,{get:()=>r[n],enumerable:!0});if(t){for(let n of ke(r))if(!Ee.call(t,n)&&n!=="default")X(t,n,{get:()=>r[n],enumerable:!0});return t}},it=(e,r,t)=>{t=e!=null?st(at(e)):{};let n=r||!e||!e.__esModule?X(t,"default",{value:e,enumerable:!0}):t;for(let o of ke(e))if(!Ee.call(n,o))X(n,o,{get:()=>e[o],enumerable:!0});return n};var lt=(e,r)=>()=>(r||e((r={exports:{}}).exports,r),r.exports);var R=(e,r)=>{for(var t in r)X(e,t,{get:r[t],enumerable:!0,configurable:!0,set:(n)=>r[t]=()=>n})};var rt=lt((ca,et)=>{var{defineProperty:Ge,getOwnPropertyNames:sn,getOwnPropertyDescriptor:an}=Object,ln=Object.prototype.hasOwnProperty,Zr=new WeakMap,un=(e)=>{var r=Zr.get(e),t;if(r)return r;if(r=Ge({},"__esModule",{value:!0}),e&&typeof e==="object"||typeof e==="function")sn(e).map((n)=>!ln.call(r,n)&&Ge(r,n,{get:()=>e[n],enumerable:!(t=an(e,n))||t.enumerable}));return Zr.set(e,r),r},pn=(e,r)=>{for(var t in r)Ge(e,t,{get:r[t],enumerable:!0,configurable:!0,set:(n)=>r[t]=()=>n})},zr={};pn(zr,{splitWithQuotes:()=>cn,splitNested:()=>fn});et.exports=un(zr);var fn=(e,r,t="(",n=")")=>{let o=0,s="",i=[];for(let a of e){if(s+=a,a===t)o++;if(a===n)o--;if(o===0&&a===r)i.push(s.slice(0,-1)),s=""}if(s)i.push(s);return i},cn=(e,r=",")=>{let t=[],n=e.length,o=r.length,s=0,i=(a)=>{if(a+o>n)return!1;for(let u=0;u<o;u++)if(e[a+u]!==r[u])return!1;return!0};while(s<n){while(s<n&&e[s]===" ")s++;if(s>=n)break;let a="",u=e[s]==='"'||e[s]==="'";if(u){let m=e[s++];while(s<n&&e[s]!==m)a+=e[s++];if(s<n)s++}else{while(s<n&&!i(s)){let m=e[s];if(m==='"'||m==="'"){a+=m,s++;while(s<n&&e[s]!==m)a+=e[s++];if(s<n)a+=e[s++]}else a+=e[s++]}a=a.trim()}if(a)t.push({value:a,quoted:u});if(i(s))s+=o}return t}});var W={};R(W,{writeOutputs:()=>z,writeOutput:()=>fe,writeFormat:()=>pe,tokenize:()=>Ye,toObjectWithKey:()=>Ne,toObject:()=>ee,toList:()=>I,stripIndent:()=>Je,sortBy:()=>_e,snake:()=>Q,select:()=>O,processFields:()=>D,pascal:()=>J,padBlock:()=>C,nonNullMap:()=>Ce,navigate:()=>ge,mergeAll:()=>T,merge:()=>N,makeFieldProcessorMap:()=>F,makeFieldProcessorList:()=>Fe,makeFieldProcessor:()=>q,locate:()=>_,loadFormat:()=>P,importList:()=>ce,importGlob:()=>je,globMap:()=>Z,getProcessor:()=>x,getArgs:()=>ue,find:()=>Be,exists:()=>B,defined:()=>Le,deepClone:()=>$,conditionPredicates:()=>j,changeCase:()=>G,capital:()=>ne,camel:()=>oe,asyncMap:()=>Ie,Objector:()=>tt,NavigateResult:()=>b,NavigateAction:()=>me,Logger:()=>Ke});var Re={};R(Re,{processFields:()=>D,makeFieldProcessorMap:()=>F,makeFieldProcessorList:()=>Fe,makeFieldProcessor:()=>q,getProcessor:()=>x,getArgs:()=>ue});var ut=Object.create,{getPrototypeOf:pt,defineProperty:qe,getOwnPropertyNames:ft}=Object,ct=Object.prototype.hasOwnProperty,mt=(e,r,t)=>{t=e!=null?ut(pt(e)):{};let n=r||!e||!e.__esModule?qe(t,"default",{value:e,enumerable:!0}):t;for(let o of ft(e))if(!ct.call(n,o))qe(n,o,{get:()=>e[o],enumerable:!0});return n},gt=(e,r)=>()=>(r||e((r={exports:{}}).exports,r),r.exports),yt=gt((e,r)=>{var{defineProperty:t,getOwnPropertyNames:n,getOwnPropertyDescriptor:o}=Object,s=Object.prototype.hasOwnProperty,i=new WeakMap,a=(l)=>{var c=i.get(l),h;if(c)return c;if(c=t({},"__esModule",{value:!0}),l&&typeof l==="object"||typeof l==="function")n(l).map((f)=>!s.call(c,f)&&t(c,f,{get:()=>l[f],enumerable:!(h=o(l,f))||h.enumerable}));return i.set(l,c),c},u=(l,c)=>{for(var h in c)t(l,h,{get:c[h],enumerable:!0,configurable:!0,set:(f)=>c[h]=()=>f})},m={};u(m,{splitWithQuotes:()=>g,splitNested:()=>d}),r.exports=a(m);var d=(l,c,h="(",f=")")=>{let w=0,p="",v=[];for(let y of l){if(p+=y,y===h)w++;if(y===f)w--;if(w===0&&y===c)v.push(p.slice(0,-1)),p=""}if(p)v.push(p);return v},g=(l,c=",")=>{let h=[],f=l.length,w=c.length,p=0,v=(y)=>{if(y+w>f)return!1;for(let M=0;M<w;M++)if(l[y+M]!==c[M])return!1;return!0};while(p<f){while(p<f&&l[p]===" ")p++;if(p>=f)break;let y="",M=l[p]==='"'||l[p]==="'";if(M){let k=l[p++];while(p<f&&l[p]!==k)y+=l[p++];if(p<f)p++}else{while(p<f&&!v(p)){let k=l[p];if(k==='"'||k==="'"){y+=k,p++;while(p<f&&l[p]!==k)y+=l[p++];if(p<f)y+=l[p++]}else y+=l[p++]}y=y.trim()}if(y)h.push({value:y,quoted:M});if(v(p))p+=w}return h}}),dt=mt(yt(),1),V;((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"})(V||={});class E{action;by;skipSiblings;reexplore;constructor(e,r,t,n){this.action=e,this.by=r,this.skipSiblings=t,this.reexplore=n}static _explore=new E(0);static _noExplore=new E(2);static _skipSiblings=new E(1);static _deleteParent=new E(4);static ReplaceParent(e,r){return new E(3,e,void 0,r)}static SkipSiblings(){return E._skipSiblings}static Explore(){return E._explore}static NoExplore(){return E._noExplore}static DeleteParent(){return E._deleteParent}static MergeParent(e){return new E(5,e)}static ReplaceItem(e,r){return new E(6,e,r)}static DeleteItem(e){return new E(7,void 0,e)}}var wt=async(e,r)=>{let t=new WeakSet,n=[],o=[],s=async(a,u,m)=>{let d=a===null,g=d?E.Explore():await r({key:a,value:u,path:n,parent:m,parents:o});if(u&&typeof u==="object"&&g.action===0){if(t.has(u))return g;if(t.add(u),!d)n.push(a),o.push(m);let l=u;while(await i(l,a,m))l=m[a];if(!d)o.pop(),n.pop()}return g},i=async(a,u,m)=>{let d=Object.keys(a),g=d.length;for(let l=0;l<g;l++){let c=d[l],h=a[c],f=await s(c,h,a),w=f.action;if(w===0||w===2)continue;if(w===6){if(a[c]=f.by,f.skipSiblings)return;continue}if(w===7){if(delete a[c],f.skipSiblings)return;continue}if(w===1)return;if(w===3){if(u===null)throw Error("Cannot replace root object");if(m[u]=f.by,f.reexplore)return!0;return}if(w===4){if(u===null)throw Error("Cannot delete root object");delete m[u];return}if(w===5)delete a[c],Object.assign(a,f.by)}};await s(null,e,null)},ht=Object.create,{getPrototypeOf:bt,defineProperty:Pe,getOwnPropertyNames:vt}=Object,Mt=Object.prototype.hasOwnProperty,Ot=(e,r,t)=>{t=e!=null?ht(bt(e)):{};let n=r||!e||!e.__esModule?Pe(t,"default",{value:e,enumerable:!0}):t;for(let o of vt(e))if(!Mt.call(n,o))Pe(n,o,{get:()=>e[o],enumerable:!0});return n},At=(e,r)=>()=>(r||e((r={exports:{}}).exports,r),r.exports),kt=At((e,r)=>{var{defineProperty:t,getOwnPropertyNames:n,getOwnPropertyDescriptor:o}=Object,s=Object.prototype.hasOwnProperty,i=new WeakMap,a=(l)=>{var c=i.get(l),h;if(c)return c;if(c=t({},"__esModule",{value:!0}),l&&typeof l==="object"||typeof l==="function")n(l).map((f)=>!s.call(c,f)&&t(c,f,{get:()=>l[f],enumerable:!(h=o(l,f))||h.enumerable}));return i.set(l,c),c},u=(l,c)=>{for(var h in c)t(l,h,{get:c[h],enumerable:!0,configurable:!0,set:(f)=>c[h]=()=>f})},m={};u(m,{splitWithQuotes:()=>g,splitNested:()=>d}),r.exports=a(m);var d=(l,c,h="(",f=")")=>{let w=0,p="",v=[];for(let y of l){if(p+=y,y===h)w++;if(y===f)w--;if(w===0&&y===c)v.push(p.slice(0,-1)),p=""}if(p)v.push(p);return v},g=(l,c=",")=>{let h=[],f=l.length,w=c.length,p=0,v=(y)=>{if(y+w>f)return!1;for(let M=0;M<w;M++)if(l[y+M]!==c[M])return!1;return!0};while(p<f){while(p<f&&l[p]===" ")p++;if(p>=f)break;let y="",M=l[p]==='"'||l[p]==="'";if(M){let k=l[p++];while(p<f&&l[p]!==k)y+=l[p++];if(p<f)p++}else{while(p<f&&!v(p)){let k=l[p];if(k==='"'||k==="'"){y+=k,p++;while(p<f&&l[p]!==k)y+=l[p++];if(p<f)y+=l[p++]}else y+=l[p++]}y=y.trim()}if(y)h.push({value:y,quoted:M});if(v(p))p+=w}return h}}),Et=Ot(kt(),1),St=/^\[([^=\]]*)([=]*)([^\]]*)\]$/,Dt=/^([^[\]]*)\[([^\]]*)]$/,Se=(e,r,t,n)=>{if(e.startsWith("{")&&e.endsWith("}")){let o=e.substring(1,e.length-1);return H(r,o,t)?.toString()}return n?e:void 0},Ft=(e,r,t,n)=>{let o=Se(r,t,n);if(o)return H(e,o,n);let s=St.exec(r);if(s){let[,a,u,m]=s,d=Se(a.trim(),t,n,!0),g=Se(m.trim(),t,n,!0);if(Array.isArray(e)&&(u==="="||u==="==")&&d)return e.find((l)=>l?.[d]==g)}let i=Dt.exec(r);if(i){let[,a,u]=i;return e?.[a]?.[u]}return e?.[r]},H=(e,r,t)=>{let n=void 0,o=void 0,s=r??"",i=(g)=>{if(!g)return[g,!1];return g.endsWith("?")?[g.substring(0,g.length-1),!0]:[g,!1]},a=(g,l)=>{let[c,h]=i(l.pop());if(!c){if(t?.set!==void 0&&o!==void 0&&n!==void 0)n[o]=t.set;return g}let f=Ft(g,c,e,t);if(f===void 0){if(h||t?.optional||t?.defaultValue!==void 0)return;throw Error(`Unknown path element: "${c}" in "${s}"`)}return n=g,o=c,a(f,l)},u=Et.splitNested(s,t?.separator??".","{","}"),m=void 0;if(u.length>0&&u[u.length-1].startsWith("?="))m=u.pop()?.substring(2);u.reverse();let d=a(e,u);if(d===void 0)return m??t?.defaultValue;return d},Ze=(e,r)=>{if(typeof e.value==="string"){if(e.quoted)return e.value;if(e.value.startsWith("[")&&e.value.endsWith("]")){let t=e.value.slice(1,-1);if(t.trim()==="")return[];return t.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 r(e.value)},le=(e,r,t,n,o,s)=>{let i=n?.(e)??e,a=o(i);if(a[0])return a[1];if(!r){let u=H(t,e),m=o(u);if(m[0])return m[1]}throw Error(s)},er=(e,r,t,n,o)=>{let s=typeof e.types==="function"?e.types(n,r.value,o):e.types?.[n];if(!s||s==="ref")return Ze(r,(a)=>H(t,a));let i=Ze(r,()=>r.value);if(Array.isArray(s)){if(!s.includes(i))throw Error(`Argument ${n.toString()} must be one of [${s.join(", ")}]: ${i}`);return i}if(typeof s==="string"){if(s.endsWith("?")){let a=s.slice(0,-1);if(r.value==="null")return E.ReplaceItem(null);if(r.value==="undefined")return E.ReplaceItem(void 0);if(r.value==="")return"";s=a}switch(s){case"any":return i;case"array":return le(i,r.quoted,t,null,(a)=>[Array.isArray(a),a],`Argument ${n.toString()} must be an array: ${i}`);case"object":return le(i,r.quoted,t,null,(a)=>[typeof a==="object"&&a!==null,a],`Argument ${n.toString()} must be an object: ${i}`);case"number":return le(i,r.quoted,t,(a)=>Number(a),(a)=>[!isNaN(a),a],`Argument ${n.toString()} must be a number: ${i}`);case"boolean":return le(i,r.quoted,t,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: ${i}`);case"string":return i.toString();default:throw Error(`Unknown type for argument ${n.toString()}: ${s}`)}}return s(i,t,n,r.quoted)},x=(e,r)=>{let t=e?.[r];if(t===void 0)throw Error(`Unhandled field processor type: ${r}`);return typeof t==="function"?{options:{},fn:t}:{options:t,fn:t.fn}},rr=(e)=>!e.quoted&&e.value.startsWith("."),Rt=(e)=>{let r={};for(let t of e){if(!rr(t))continue;let n=t.value.indexOf("="),o=n>-1?t.value.slice(1,n):t.value.slice(1),s=n>-1?t.value.slice(n+1):"";if(s.length>=2){let i=s[0],a=s[s.length-1];if(i==='"'&&a==='"'||i==="'"&&a==="'")s=s.slice(1,-1)}if(!r[o])r[o]=[];r[o].push(s)}return r},ue=(e,r,t)=>{let n=dt.splitWithQuotes(e??""),o=Rt(n),s=n.filter((a)=>!rr(a)),i=r.options.processArgs===!1?[]:s.map((a,u)=>er(r.options,a,t,u,s));return{rawArgs:s,parsedArgs:i,tags:o}},$t=(e)=>{return e!==null&&typeof e==="object"&&"action"in e},jt=(e,r)=>r.keys!==void 0&&e.key.startsWith(".")&&r.keys[e.key.substring(1)]!==void 0,Wt=async(e,r,t,n)=>{let{key:o,parent:s}=e,i=x(n.keys,o.substring(1));if(i.options.processArgs!==!1&&(typeof i.options.types==="function"||i.options.types?.[0]!==void 0))e.value=er(i.options,{value:e.value,quoted:!1},t,0,[]);if(typeof e.value!=="string")await D(e.value,{...n,root:{...t,parent:e.parent,parents:e.parents},filters:[...n.filters??[],...i.options.filters??[]]});let a=await i.fn({path:r,root:t,parent:s,key:o,options:n,value:e.value,args:[],rawArgs:[],tags:{}});return $t(a)?a:E.ReplaceParent(a)},ze=(e)=>{let r=e.split(/\r?\n/),t=r.filter((o)=>o.trim().length>0).map((o)=>/^[ \t]*/.exec(o)?.[0].length??0),n=t.length>0?Math.min(...t):0;if(n===0)return e;return r.map((o)=>o.slice(n)).join(`
2
- `)},Nt=async(e,r,t,n)=>{if(!r?.onSection&&!r?.onSectionConfig&&!r?.sections)return[e,!1];let o=/%{\s*section\s*}%([\s\S]*?)%{\s*endsection\s*}%/g,s,i=e,a=0,u=!1,m={content:i,root:n,path:t,options:r,section:{}};while((s=o.exec(e))!==null){u=!0;let[d,g]=s,l=s.index,c=l+d.length,h=e[c]===`
3
- `;if(h)c++;let f=l+a,w=c+a,p={},v=g,y=/(^|\r?\n)[ \t]*---[ \t]*(\r?\n|$)/m.exec(g);if(y){let Ae=g.slice(0,y.index),nt=y.index+y[0].length;v=g.slice(nt);let xe=ze(Ae).trim();if(xe.length>0)try{p=Bun.YAML.parse(xe)??{}}catch(ot){throw Error(`Failed to parse YAML config for section: ${ot.message}`)}}else if(/^\r?\n/.test(v))v=v.replace(/^\r?\n/,"");v=ze(v),v=v.replace(/(?:\r?\n[ \t]*)+$/,""),v=v.replace(/[ \t]+$/,"");let M={config:p,content:v};if(m.content=i,m.section=M,Object.keys(M.config).length>0){if(await r.onSectionConfig?.(m)!==!1)await D(M.config,{...r,root:n})}let k=m.section.config.type?r.sections?.[m.section.config.type]:void 0,K;if(k)K=await k(m);else if(r.onSection)K=await r.onSection(m);if(M.trim)M.content=M.content.trim();if(M.indent)M.content=M.content.split(`
4
- `).map((Ae)=>" ".repeat(M.indent)+Ae).join(`
5
- `);let L="";if(K===!0||M.show)L=M.content;else if(typeof K==="string")L=K;if(h&&L!==""&&!L.endsWith(`
1
+ var st=Object.create;var{getPrototypeOf:at,defineProperty:X,getOwnPropertyNames:ke}=Object;var Ae=Object.prototype.hasOwnProperty,S=(e,r,t)=>{for(let n of ke(r))if(!Ae.call(e,n)&&n!=="default")X(e,n,{get:()=>r[n],enumerable:!0});if(t){for(let n of ke(r))if(!Ae.call(t,n)&&n!=="default")X(t,n,{get:()=>r[n],enumerable:!0});return t}},it=(e,r,t)=>{t=e!=null?st(at(e)):{};let n=r||!e||!e.__esModule?X(t,"default",{value:e,enumerable:!0}):t;for(let o of ke(e))if(!Ae.call(n,o))X(n,o,{get:()=>e[o],enumerable:!0});return n};var lt=(e,r)=>()=>(r||e((r={exports:{}}).exports,r),r.exports);var $=(e,r)=>{for(var t in r)X(e,t,{get:r[t],enumerable:!0,configurable:!0,set:(n)=>r[t]=()=>n})};var rt=lt((ba,et)=>{var{defineProperty:xe,getOwnPropertyNames:pn,getOwnPropertyDescriptor:fn}=Object,cn=Object.prototype.hasOwnProperty,Zr=new WeakMap,mn=(e)=>{var r=Zr.get(e),t;if(r)return r;if(r=xe({},"__esModule",{value:!0}),e&&typeof e==="object"||typeof e==="function")pn(e).map((n)=>!cn.call(r,n)&&xe(r,n,{get:()=>e[n],enumerable:!(t=fn(e,n))||t.enumerable}));return Zr.set(e,r),r},gn=(e,r)=>{for(var t in r)xe(e,t,{get:r[t],enumerable:!0,configurable:!0,set:(n)=>r[t]=()=>n})},zr={};gn(zr,{splitWithQuotes:()=>dn,splitNested:()=>yn});et.exports=mn(zr);var yn=(e,r,t="(",n=")")=>{let o=0,s="",i=[];for(let a of e){if(s+=a,a===t)o++;if(a===n)o--;if(o===0&&a===r)i.push(s.slice(0,-1)),s=""}if(s)i.push(s);return i},dn=(e,r=",")=>{let t=[],n=e.length,o=r.length,s=0,i=(a)=>{if(a+o>n)return!1;for(let l=0;l<o;l++)if(e[a+l]!==r[l])return!1;return!0};while(s<n){while(s<n&&e[s]===" ")s++;if(s>=n)break;let a="",l=e[s]==='"'||e[s]==="'";if(l){let m=e[s++];while(s<n&&e[s]!==m)a+=e[s++];if(s<n)s++}else{while(s<n&&!i(s)){let m=e[s];if(m==='"'||m==="'"){a+=m,s++;while(s<n&&e[s]!==m)a+=e[s++];if(s<n)a+=e[s++]}else a+=e[s++]}a=a.trim()}if(a)t.push({value:a,quoted:l});if(i(s))s+=o}return t}});var W={};$(W,{writeOutputs:()=>z,writeOutput:()=>ce,writeFormat:()=>fe,tokenize:()=>Qe,toObjectWithKey:()=>Le,toObject:()=>ee,toList:()=>_,stripIndent:()=>Ke,sortBy:()=>_e,snake:()=>K,select:()=>O,processFields:()=>F,pascal:()=>Q,padBlock:()=>C,nonNullMap:()=>Ue,navigate:()=>ye,mergeAll:()=>B,merge:()=>N,makeFieldProcessorMap:()=>D,makeFieldProcessorList:()=>De,makeFieldProcessor:()=>q,locate:()=>I,loadFormat:()=>P,importList:()=>me,importGlob:()=>Ne,globMap:()=>Z,getProcessor:()=>H,getArgs:()=>pe,find:()=>Be,exists:()=>Y,defined:()=>Ie,deepClone:()=>R,conditionPredicates:()=>j,changeCase:()=>G,capital:()=>ne,camel:()=>oe,asyncMap:()=>Te,Objector:()=>tt,NavigateResult:()=>b,NavigateAction:()=>ge,Logger:()=>Xe});var $e={};$($e,{processFields:()=>F,makeFieldProcessorMap:()=>D,makeFieldProcessorList:()=>De,makeFieldProcessor:()=>q,getProcessor:()=>H,getArgs:()=>pe});var ut=Object.create,{getPrototypeOf:pt,defineProperty:Ze,getOwnPropertyNames:ft}=Object,ct=Object.prototype.hasOwnProperty,mt=(e,r,t)=>{t=e!=null?ut(pt(e)):{};let n=r||!e||!e.__esModule?Ze(t,"default",{value:e,enumerable:!0}):t;for(let o of ft(e))if(!ct.call(n,o))Ze(n,o,{get:()=>e[o],enumerable:!0});return n},gt=(e,r)=>()=>(r||e((r={exports:{}}).exports,r),r.exports),yt=gt((e,r)=>{var{defineProperty:t,getOwnPropertyNames:n,getOwnPropertyDescriptor:o}=Object,s=Object.prototype.hasOwnProperty,i=new WeakMap,a=(u)=>{var c=i.get(u),h;if(c)return c;if(c=t({},"__esModule",{value:!0}),u&&typeof u==="object"||typeof u==="function")n(u).map((f)=>!s.call(c,f)&&t(c,f,{get:()=>u[f],enumerable:!(h=o(u,f))||h.enumerable}));return i.set(u,c),c},l=(u,c)=>{for(var h in c)t(u,h,{get:c[h],enumerable:!0,configurable:!0,set:(f)=>c[h]=()=>f})},m={};l(m,{splitWithQuotes:()=>g,splitNested:()=>y}),r.exports=a(m);var y=(u,c,h="(",f=")")=>{let w=0,p="",v=[];for(let d of u){if(p+=d,d===h)w++;if(d===f)w--;if(w===0&&d===c)v.push(p.slice(0,-1)),p=""}if(p)v.push(p);return v},g=(u,c=",")=>{let h=[],f=u.length,w=c.length,p=0,v=(d)=>{if(d+w>f)return!1;for(let M=0;M<w;M++)if(u[d+M]!==c[M])return!1;return!0};while(p<f){while(p<f&&u[p]===" ")p++;if(p>=f)break;let d="",M=u[p]==='"'||u[p]==="'";if(M){let A=u[p++];while(p<f&&u[p]!==A)d+=u[p++];if(p<f)p++}else{while(p<f&&!v(p)){let A=u[p];if(A==='"'||A==="'"){d+=A,p++;while(p<f&&u[p]!==A)d+=u[p++];if(p<f)d+=u[p++]}else d+=u[p++]}d=d.trim()}if(d)h.push({value:d,quoted:M});if(v(p))p+=w}return h}}),dt=mt(yt(),1),U;((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"})(U||={});class E{action;by;skipSiblings;reexplore;constructor(e,r,t,n){this.action=e,this.by=r,this.skipSiblings=t,this.reexplore=n}static _explore=new E(0);static _noExplore=new E(2);static _skipSiblings=new E(1);static _deleteParent=new E(4);static ReplaceParent(e,r){return new E(3,e,void 0,r)}static SkipSiblings(){return E._skipSiblings}static Explore(){return E._explore}static NoExplore(){return E._noExplore}static DeleteParent(){return E._deleteParent}static MergeParent(e){return new E(5,e)}static ReplaceItem(e,r){return new E(6,e,r)}static DeleteItem(e){return new E(7,void 0,e)}}var wt=async(e,r)=>{let t=new WeakSet,n=[],o=[],s=async(a,l,m)=>{let y=a===null,g=y?E.Explore():await r({key:a,value:l,path:n,parent:m,parents:o});if(l&&typeof l==="object"&&g.action===0){if(t.has(l))return g;if(t.add(l),!y)n.push(a),o.push(m);let u=l;while(await i(u,a,m))u=m[a];if(!y)o.pop(),n.pop()}return g},i=async(a,l,m)=>{let y=Object.keys(a),g=y.length;for(let u=0;u<g;u++){let c=y[u],h=a[c],f=await s(c,h,a),w=f.action;if(w===0||w===2)continue;if(w===6){if(a[c]=f.by,f.skipSiblings)return;continue}if(w===7){if(delete a[c],f.skipSiblings)return;continue}if(w===1)return;if(w===3){if(l===null)throw Error("Cannot replace root object");if(m[l]=f.by,f.reexplore)return!0;return}if(w===4){if(l===null)throw Error("Cannot delete root object");delete m[l];return}if(w===5)delete a[c],Object.assign(a,f.by)}};await s(null,e,null)},ht=Object.create,{getPrototypeOf:bt,defineProperty:ze,getOwnPropertyNames:vt}=Object,Mt=Object.prototype.hasOwnProperty,Ot=(e,r,t)=>{t=e!=null?ht(bt(e)):{};let n=r||!e||!e.__esModule?ze(t,"default",{value:e,enumerable:!0}):t;for(let o of vt(e))if(!Mt.call(n,o))ze(n,o,{get:()=>e[o],enumerable:!0});return n},Et=(e,r)=>()=>(r||e((r={exports:{}}).exports,r),r.exports),kt=Et((e,r)=>{var{defineProperty:t,getOwnPropertyNames:n,getOwnPropertyDescriptor:o}=Object,s=Object.prototype.hasOwnProperty,i=new WeakMap,a=(u)=>{var c=i.get(u),h;if(c)return c;if(c=t({},"__esModule",{value:!0}),u&&typeof u==="object"||typeof u==="function")n(u).map((f)=>!s.call(c,f)&&t(c,f,{get:()=>u[f],enumerable:!(h=o(u,f))||h.enumerable}));return i.set(u,c),c},l=(u,c)=>{for(var h in c)t(u,h,{get:c[h],enumerable:!0,configurable:!0,set:(f)=>c[h]=()=>f})},m={};l(m,{splitWithQuotes:()=>g,splitNested:()=>y}),r.exports=a(m);var y=(u,c,h="(",f=")")=>{let w=0,p="",v=[];for(let d of u){if(p+=d,d===h)w++;if(d===f)w--;if(w===0&&d===c)v.push(p.slice(0,-1)),p=""}if(p)v.push(p);return v},g=(u,c=",")=>{let h=[],f=u.length,w=c.length,p=0,v=(d)=>{if(d+w>f)return!1;for(let M=0;M<w;M++)if(u[d+M]!==c[M])return!1;return!0};while(p<f){while(p<f&&u[p]===" ")p++;if(p>=f)break;let d="",M=u[p]==='"'||u[p]==="'";if(M){let A=u[p++];while(p<f&&u[p]!==A)d+=u[p++];if(p<f)p++}else{while(p<f&&!v(p)){let A=u[p];if(A==='"'||A==="'"){d+=A,p++;while(p<f&&u[p]!==A)d+=u[p++];if(p<f)d+=u[p++]}else d+=u[p++]}d=d.trim()}if(d)h.push({value:d,quoted:M});if(v(p))p+=w}return h}}),At=Ot(kt(),1),St=/^\[([^=\]]*)([=]*)([^\]]*)\]$/,Ft=/^([^[\]]*)\[([^\]]*)]$/,Se=(e,r,t,n)=>{if(e.startsWith("{")&&e.endsWith("}")){let o=e.substring(1,e.length-1);return V(r,o,t)?.toString()}return n?e:void 0},Dt=(e,r,t,n)=>{let o=Se(r,t,n);if(o)return V(e,o,n);let s=St.exec(r);if(s){let[,a,l,m]=s,y=Se(a.trim(),t,n,!0),g=Se(m.trim(),t,n,!0);if(Array.isArray(e)&&(l==="="||l==="==")&&y)return e.find((u)=>u?.[y]==g)}let i=Ft.exec(r);if(i){let[,a,l]=i;return e?.[a]?.[l]}return e?.[r]},V=(e,r,t)=>{let n=void 0,o=void 0,s=r??"",i=(g)=>{if(!g)return[g,!1];return g.endsWith("?")?[g.substring(0,g.length-1),!0]:[g,!1]},a=(g,u)=>{let[c,h]=i(u.pop());if(!c){if(t?.set!==void 0&&o!==void 0&&n!==void 0)n[o]=t.set;return g}let f=Dt(g,c,e,t);if(f===void 0){if(h||t?.optional||t?.defaultValue!==void 0)return;throw Error(`Unknown path element: "${c}" in "${s}"`)}return n=g,o=c,a(f,u)},l=At.splitNested(s,t?.separator??".","{","}"),m=void 0;if(l.length>0&&l[l.length-1].startsWith("?="))m=l.pop()?.substring(2);l.reverse();let y=a(e,l);if(y===void 0)return m??t?.defaultValue;return y},er=(e,r)=>{if(typeof e.value==="string"){if(e.quoted)return e.value;if(e.value.startsWith("[")&&e.value.endsWith("]")){let t=e.value.slice(1,-1);if(t.trim()==="")return[];return t.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 r(e.value)},ue=(e,r,t,n,o,s)=>{let i=n?.(e)??e,a=o(i);if(a[0])return a[1];if(!r){let l=V(t,e),m=o(l);if(m[0])return m[1]}throw Error(s)},tr=(e,r,t,n,o)=>{let s=typeof e.types==="function"?e.types(n,r.value,o):e.types?.[n];if(!s||s==="ref")return er(r,(a)=>V(t,a));let i=er(r,()=>r.value);if(Array.isArray(s)){if(!s.includes(i))throw Error(`Argument ${n.toString()} must be one of [${s.join(", ")}]: ${i}`);return i}if(typeof s==="string"){if(s.endsWith("?")){let a=s.slice(0,-1);if(r.value==="null")return E.ReplaceItem(null);if(r.value==="undefined")return E.ReplaceItem(void 0);if(r.value==="")return"";s=a}switch(s){case"any":return i;case"array":return ue(i,r.quoted,t,null,(a)=>[Array.isArray(a),a],`Argument ${n.toString()} must be an array: ${i}`);case"object":return ue(i,r.quoted,t,null,(a)=>[typeof a==="object"&&a!==null,a],`Argument ${n.toString()} must be an object: ${i}`);case"number":return ue(i,r.quoted,t,(a)=>Number(a),(a)=>[!isNaN(a),a],`Argument ${n.toString()} must be a number: ${i}`);case"boolean":return ue(i,r.quoted,t,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: ${i}`);case"string":return i.toString();default:throw Error(`Unknown type for argument ${n.toString()}: ${s}`)}}return s(i,t,n,r.quoted)},H=(e,r)=>{let t=e?.[r];if(t===void 0)throw Error(`Unhandled field processor type: ${r}`);return typeof t==="function"?{options:{},fn:t}:{options:t,fn:t.fn}},nr=(e)=>!e.quoted&&e.value.startsWith("."),$t=(e)=>{let r={};for(let t of e){if(!nr(t))continue;let n=t.value.indexOf("="),o=n>-1?t.value.slice(1,n):t.value.slice(1),s=n>-1?t.value.slice(n+1):"";if(s.length>=2){let i=s[0],a=s[s.length-1];if(i==='"'&&a==='"'||i==="'"&&a==="'")s=s.slice(1,-1)}if(!r[o])r[o]=[];r[o].push(s)}return r},pe=(e,r,t)=>{let n=dt.splitWithQuotes(e??""),o=$t(n),s=n.filter((a)=>!nr(a)),i=r.options.processArgs===!1?[]:s.map((a,l)=>tr(r.options,a,t,l,s));return{rawArgs:s,parsedArgs:i,tags:o}},Rt=(e)=>{return e!==null&&typeof e==="object"&&"action"in e},jt=(e,r)=>r.keys!==void 0&&e.key.startsWith(".")&&r.keys[e.key.substring(1)]!==void 0,Wt=async(e,r,t,n)=>{let{key:o,parent:s}=e,i=H(n.keys,o.substring(1));if(i.options.processArgs!==!1&&(typeof i.options.types==="function"||i.options.types?.[0]!==void 0))e.value=tr(i.options,{value:e.value,quoted:!1},t,0,[]);if(typeof e.value!=="string")await F(e.value,{...n,root:{...t,parent:e.parent,parents:e.parents},filters:[...n.filters??[],...i.options.filters??[]]});let a=await i.fn({path:r,root:t,parent:s,key:o,options:n,value:e.value,args:[],rawArgs:[],tags:{}});return Rt(a)?a:E.ReplaceParent(a)},rr=(e)=>{let r=e.split(/\r?\n/),t=r.filter((o)=>o.trim().length>0).map((o)=>/^[ \t]*/.exec(o)?.[0].length??0),n=t.length>0?Math.min(...t):0;if(n===0)return e;return r.map((o)=>o.slice(n)).join(`
2
+ `)},Nt=async(e,r,t,n)=>{if(!r?.onSection&&!r?.onSectionConfig&&!r?.sections)return[e,!1];let o=/%{\s*section\s*}%([\s\S]*?)%{\s*endsection\s*}%/g,s,i=e,a=0,l=!1,m={content:i,root:n,path:t,options:r,section:{}};while((s=o.exec(e))!==null){l=!0;let[y,g]=s,u=s.index,c=u+y.length,h=e[c]===`
3
+ `;if(h)c++;let f=u+a,w=c+a,p={},v=g,d=/(^|\r?\n)[ \t]*---[ \t]*(\r?\n|$)/m.exec(g);if(d){let Ee=g.slice(0,d.index),nt=d.index+d[0].length;v=g.slice(nt);let Pe=rr(Ee).trim();if(Pe.length>0)try{p=r?.configParser?.(Pe)??{}}catch(ot){throw Error(`Failed to parse YAML config for section: ${ot.message}`)}}else if(/^\r?\n/.test(v))v=v.replace(/^\r?\n/,"");v=rr(v),v=v.replace(/(?:\r?\n[ \t]*)+$/,""),v=v.replace(/[ \t]+$/,"");let M={config:p,content:v};if(m.content=i,m.section=M,Object.keys(M.config).length>0){if(await r.onSectionConfig?.(m)!==!1)await F(M.config,{...r,root:n})}let A=m.section.config.type?r.sections?.[m.section.config.type]:void 0,x;if(A)x=await A(m);else if(r.onSection)x=await r.onSection(m);if(M.trim)M.content=M.content.trim();if(M.indent)M.content=M.content.split(`
4
+ `).map((Ee)=>" ".repeat(M.indent)+Ee).join(`
5
+ `);let L="";if(x===!0||M.show)L=M.content;else if(typeof x==="string")L=x;if(h&&L!==""&&!L.endsWith(`
6
6
  `))L+=`
7
- `;let Xe=i.lastIndexOf(`
8
- `,f-1),Ve=Xe===-1?0:Xe+1,He=i.slice(Ve,f).trim().length===0?Ve:f;i=i.slice(0,He)+L+i.slice(w),a+=L.length-(w-He),m.content=i}return[i,u]},tr=(e)=>{let r=[],t=0;while(t<e.length)if(e[t]==="$"&&e[t+1]==="("&&(t===0||e[t-1]!=="\\")){let n=t;t+=2;let o=1;for(;t<e.length;t++)if(e[t]==="(")o++;else if(e[t]===")"){if(o--,o===0){r.push([n,t]);break}}if(o!==0)throw Error(`Unmatched opening $( at position ${n.toString()}`);t++}else t++;return r},De=Symbol.for("@homedev/fields:OverrideResult"),Ct=(e)=>({[De]:!0,value:e}),Lt=(e)=>{return e!==null&&typeof e==="object"&&De in e&&e[De]===!0},nr=async(e,r,t)=>{for(let n=r.length-1;n>=0;n--){let[o,s]=r[n],i=e.slice(o+2,s),a=await nr(i,tr(i),t);if(typeof a==="object")return a;let u=await t(a,e);if(Lt(u))return u.value;e=e.slice(0,o)+u+e.slice(s+1)}return e},_t=async(e,r)=>nr(e,tr(e),r),It=(e)=>{return e!==null&&typeof e==="object"&&"action"in e},Ut=/([\w\d.-_/]+):(.+)/,Bt=async(e,r,t,n)=>{let o=await(async()=>{let s=Ut.exec(e);if(!s)return await H(r,e);let[i,a,u]=s,m=x(n.sources,a),d=ue(u,m,r);return await m.fn({args:d.parsedArgs,rawArgs:d.rawArgs,tags:d.tags,key:a,options:n,root:r,path:t,value:null})})();if(o===null||o===void 0)return"";if(typeof o==="object")return Ct(o);return o},or=async(e,r,t,n)=>{let o=await _t(r,(s)=>Bt(s,t,e,n));if(It(o))return o;if(o===r)return E.Explore();if(typeof o==="string"){let s=await or(e,o,t,n);if(s.action!==V.Explore)return s}return E.ReplaceItem(o)},D=async(e,r)=>{return r??={},await wt(e,async(t)=>{let n=[...t.path,t.key].join(".");if(r?.filters?.length&&r.filters.some((a)=>a.test(n)))return E.NoExplore();let o=t.path.length===0,s=t.parents.length>0?t.parents.toReversed():[];if(o){if(s.length>0)throw Error("Root object should not have a parent");s=r?.root?.parents?[r.root.parent,...r.root.parents.toReversed()]:[]}let i={...e,...r.root,this:t.parent,parent:s.length>0?s[0]:null,parents:s};try{if(t.key.startsWith("$"))return E.NoExplore();let a=E.Explore();if(typeof t.value==="string"){let[u,m]=await Nt(t.value,r,n,i);if(a=await or(n,u,i,r),a.action===V.Explore&&m&&u!==t.value)a=E.ReplaceItem(u);switch(a.action){case V.Explore:break;case V.ReplaceItem:t.value=a.by;break;default:return a}}if(jt(t,r))a=await Wt(t,n,i,r);return a}catch(a){throw Error(`${a.message}
9
- (${n})`)}}),e},q=(e,r)=>r?{fn:(t)=>e(...t.args),types:r}:(t)=>e(...t.args),Fe=(e,r)=>Object.fromEntries(e.map((t)=>[t.name,q(t,r?.types?.[t.name])])),F=(e,r)=>Object.fromEntries((r?.keys??Object.keys(e)).map((t)=>[t,q(e[t],r?.types?.[t])]));var We={};R(We,{writeOutputs:()=>z,writeOutput:()=>fe,writeFormat:()=>pe,locate:()=>_,loadFormat:()=>P,importList:()=>ce,importGlob:()=>je,globMap:()=>Z,exists:()=>B});import sr from"fs/promises";import $e from"path";import Tt from"path";import Yt from"fs/promises";import ur from"fs/promises";import ar from"path";import ir from"path";import lr from"path";var B=async(e)=>{try{return await sr.access(e,sr.constants.R_OK),!0}catch{return!1}},_=async(e,r)=>{let t=!$e.isAbsolute(e)&&r?["",...r]:[""];for(let n of t){let o=$e.join(n,e);if(await B(o))return $e.resolve(o)}throw Error(`File not found: "${e}"`)},P=async(e,r)=>{let t=await _(e,r?.dirs),n=await Bun.file(t).text(),o=Tt.dirname(t),s={"[.]json$":JSON.parse,"[.](yml|yaml)$":Bun.YAML.parse,"[.]toml$":Bun.TOML.parse,...r?.parsers},i=Object.entries(s).find((a)=>t.match(a[0]));if(!i)throw Error(`Unhandled file type: ${e}`);return{content:i[1](n),fullPath:t,folderPath:o}},pe=async(e,r,t="text")=>{switch(t){case"yaml":await Bun.write(e,Bun.YAML.stringify(r));break;case"json":await Bun.write(e,JSON.stringify(r));break;case"text":default:await Bun.write(e,r.toString())}},Z=async(e,r)=>{if(typeof e==="string"&&!e.includes("*"))return await r.map(e,0,[]);let t=await Array.fromAsync(Yt.glob(e,{cwd:r.cwd})),n=r.filter?t.filter(r.filter):t;return await Promise.all(n.map(r.map))},z=async(e,r)=>{if(r?.targetDirectory&&r?.removeFirst)try{await ur.rm(r?.targetDirectory,{recursive:!0,force:!0})}catch(t){throw Error(`Failed to clean the output directory: ${t.message}`)}for(let t of e)await fe(t,r)},fe=async(e,r)=>{let t=ar.join(r?.targetDirectory??".",e.name),n=ar.dirname(t);if(r?.classes){if(e.class!==void 0&&!r.classes.includes(e.class))return;if(r.classRequired&&e.class===void 0)throw Error(`Output "${e.name}" is missing class field`)}if(r?.writing?.(e)===!1)return;try{await ur.mkdir(n,{recursive:!0})}catch(o){throw Error(`Failed to create target directory "${n}" for output "${t}": ${o.message}`)}try{await pe(t,e.value,e.type??"text")}catch(o){throw Error(`Failed to write output "${t}": ${o.message}`)}},pr=(e)=>e?lr.isAbsolute(e)?e:lr.join(process.cwd(),e):process.cwd(),ce=async(e,r)=>{let t=[];for(let n of e)try{let o=!ir.isAbsolute(n)?ir.join(pr(r?.cwd),n):n;if(r?.filter?.(o)===!1)continue;let s=await import(o);if(r?.resolveDefault==="only"&&!s.default)throw Error(`Module ${n} does not have a default export`);let i=r?.resolveDefault?s.default??s:s,a=r?.map?await r.map(i,n):i;if(a!==void 0)t.push(a)}catch(o){if(r?.fail?.(n,o)===!1)continue;throw Error(`Failed to import module ${n}: ${o.message??o}`)}return t},je=async(e,r)=>{let t=[];for(let n of e){let o=await Array.fromAsync(new Bun.Glob(n).scan({cwd:pr(r?.cwd),absolute:!0}));t.push(...await ce(o,r))}return t};var Ue={};R(Ue,{toObjectWithKey:()=>Ne,toObject:()=>ee,toList:()=>I,sortBy:()=>_e,nonNullMap:()=>Ce,defined:()=>Le,deepClone:()=>$,asyncMap:()=>Ie});var I=(e,r="name")=>Object.entries(e).map(([t,n])=>({[r]:t,...n})),Ne=(e,r="name")=>Object.fromEntries(e.map((t)=>[t[r],t])),ee=(e,r="name")=>Object.fromEntries(e.map((t)=>{let{[r]:n,...o}=t;return[n,o]})),Ce=(e,r)=>{if(!e)return[];let t=[],n=0;for(let o of e)if(o!==null&&o!==void 0)t.push(r(o,n,e)),n++;return t},Le=(e,r="Value is undefined")=>{if(e===void 0||e===null)throw Error(r);return e},_e=(e,r,t=(n,o)=>n-o)=>e.slice().sort((n,o)=>t(r(n),r(o))),Ie=async(e,r)=>Promise.all(e.map(r)),$=(e)=>{if(typeof structuredClone<"u")try{return structuredClone(e)}catch{}return JSON.parse(JSON.stringify(e))};var qr={};R(qr,{defaultProcessors:()=>Qe});var fr={};R(fr,{navigate:()=>ge,find:()=>Be,NavigateResult:()=>b,NavigateAction:()=>me});var me;((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"})(me||={});class b{action;by;skipSiblings;reexplore;constructor(e,r,t,n){this.action=e,this.by=r,this.skipSiblings=t,this.reexplore=n}static _explore=new b(0);static _noExplore=new b(2);static _skipSiblings=new b(1);static _deleteParent=new b(4);static ReplaceParent(e,r){return new b(3,e,void 0,r)}static SkipSiblings(){return b._skipSiblings}static Explore(){return b._explore}static NoExplore(){return b._noExplore}static DeleteParent(){return b._deleteParent}static MergeParent(e){return new b(5,e)}static ReplaceItem(e,r){return new b(6,e,r)}static DeleteItem(e){return new b(7,void 0,e)}}var ge=async(e,r)=>{let t=new WeakSet,n=[],o=[],s=async(a,u,m)=>{let d=a===null,g=d?b.Explore():await r({key:a,value:u,path:n,parent:m,parents:o});if(u&&typeof u==="object"&&g.action===0){if(t.has(u))return g;if(t.add(u),!d)n.push(a),o.push(m);let l=u;while(await i(l,a,m))l=m[a];if(!d)o.pop(),n.pop()}return g},i=async(a,u,m)=>{let d=Object.keys(a),g=d.length;for(let l=0;l<g;l++){let c=d[l],h=a[c],f=await s(c,h,a),w=f.action;if(w===0||w===2)continue;if(w===6){if(a[c]=f.by,f.skipSiblings)return;continue}if(w===7){if(delete a[c],f.skipSiblings)return;continue}if(w===1)return;if(w===3){if(u===null)throw Error("Cannot replace root object");if(m[u]=f.by,f.reexplore)return!0;return}if(w===4){if(u===null)throw Error("Cannot delete root object");delete m[u];return}if(w===5)delete a[c],Object.assign(a,f.by)}};await s(null,e,null)},Be=async(e,r)=>{let t=[];return await ge(e,(n)=>{if(r([...n.path,n.key].join("."),n.value))t.push(n.value);return b.Explore()}),t};var cr=(e)=>({output:(r)=>{delete r.parent[r.key];for(let t of Array.isArray(r.value)?r.value:[r.value])if(typeof t==="string")e.output({name:t,value:r.parent});else e.output({...t,value:t.value??r.parent});return b.SkipSiblings()}});import Jt from"path";var mr=(e)=>({load:async(r)=>{let t=r.options.globalContext;for(let{file:n}of Array.isArray(r.value)?r.value:[r.value]){if(!n)throw Error("File reference required");await e.load(n,t.file&&Jt.dirname(t.file))}return b.DeleteItem()}});var gr={};R(gr,{mergeAll:()=>T,merge:()=>N});var N=(e,r,t)=>{for(let n of Object.keys(r)){if(e[n]===void 0)continue;let o=r[n],s=e[n];if(typeof s!==typeof o||Array.isArray(s)!==Array.isArray(o)){let a=t?.mismatch?.(n,s,o,e,r);if(a!==void 0){r[n]=a;continue}throw Error(`Type mismatch: ${n}`)}let i=t?.mode?.(n,s,o,e,r)??r[".merge"]??"merge";switch(i){case"source":r[n]=s;continue;case"target":continue;case"skip":delete r[n],delete e[n];continue;case"merge":break;default:throw Error(`Unknown merge mode: ${i}`)}if(typeof s==="object")if(Array.isArray(s))o.push(...s);else{if(t?.navigate?.(n,s,o,e,r)===!1)continue;N(s,o,t)}else{if(s===o)continue;let a=t?.conflict?.(n,s,o,e,r);r[n]=a===void 0?o:a}}for(let n of Object.keys(e))if(r[n]===void 0)r[n]=e[n]},T=(e,r)=>{let t={};for(let n of e.toReversed())N(n,t,r);return t};var yr={};R(yr,{CacheManager:()=>ye});class ye{cache=new Map;maxSize;constructor(e=100){this.maxSize=e}get(e){return this.cache.get(e)}set(e,r){this.evictIfNeeded(),this.cache.set(e,r)}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,r=1/0;for(let[t,n]of this.cache.entries())if(n.timestamp<r)r=n.timestamp,e=t;if(e)this.cache.delete(e)}}}var wr={};R(wr,{select:()=>O});var Qt=Object.create,{getPrototypeOf:Gt,defineProperty:dr,getOwnPropertyNames:Kt}=Object,Xt=Object.prototype.hasOwnProperty,Vt=(e,r,t)=>{t=e!=null?Qt(Gt(e)):{};let n=r||!e||!e.__esModule?dr(t,"default",{value:e,enumerable:!0}):t;for(let o of Kt(e))if(!Xt.call(n,o))dr(n,o,{get:()=>e[o],enumerable:!0});return n},Ht=(e,r)=>()=>(r||e((r={exports:{}}).exports,r),r.exports),xt=Ht((e,r)=>{var{defineProperty:t,getOwnPropertyNames:n,getOwnPropertyDescriptor:o}=Object,s=Object.prototype.hasOwnProperty,i=new WeakMap,a=(l)=>{var c=i.get(l),h;if(c)return c;if(c=t({},"__esModule",{value:!0}),l&&typeof l==="object"||typeof l==="function")n(l).map((f)=>!s.call(c,f)&&t(c,f,{get:()=>l[f],enumerable:!(h=o(l,f))||h.enumerable}));return i.set(l,c),c},u=(l,c)=>{for(var h in c)t(l,h,{get:c[h],enumerable:!0,configurable:!0,set:(f)=>c[h]=()=>f})},m={};u(m,{splitWithQuotes:()=>g,splitNested:()=>d}),r.exports=a(m);var d=(l,c,h="(",f=")")=>{let w=0,p="",v=[];for(let y of l){if(p+=y,y===h)w++;if(y===f)w--;if(w===0&&y===c)v.push(p.slice(0,-1)),p=""}if(p)v.push(p);return v},g=(l,c=",")=>{let h=[],f=l.length,w=c.length,p=0,v=(y)=>{if(y+w>f)return!1;for(let M=0;M<w;M++)if(l[y+M]!==c[M])return!1;return!0};while(p<f){while(p<f&&l[p]===" ")p++;if(p>=f)break;let y="",M=l[p]==='"'||l[p]==="'";if(M){let k=l[p++];while(p<f&&l[p]!==k)y+=l[p++];if(p<f)p++}else{while(p<f&&!v(p)){let k=l[p];if(k==='"'||k==="'"){y+=k,p++;while(p<f&&l[p]!==k)y+=l[p++];if(p<f)y+=l[p++]}else y+=l[p++]}y=y.trim()}if(y)h.push({value:y,quoted:M});if(v(p))p+=w}return h}}),qt=Vt(xt(),1),Pt=/^\[([^=\]]*)([=]*)([^\]]*)\]$/,Zt=/^([^[\]]*)\[([^\]]*)]$/,Te=(e,r,t,n)=>{if(e.startsWith("{")&&e.endsWith("}")){let o=e.substring(1,e.length-1);return O(r,o,t)?.toString()}return n?e:void 0},zt=(e,r,t,n)=>{let o=Te(r,t,n);if(o)return O(e,o,n);let s=Pt.exec(r);if(s){let[,a,u,m]=s,d=Te(a.trim(),t,n,!0),g=Te(m.trim(),t,n,!0);if(Array.isArray(e)&&(u==="="||u==="==")&&d)return e.find((l)=>l?.[d]==g)}let i=Zt.exec(r);if(i){let[,a,u]=i;return e?.[a]?.[u]}return e?.[r]},O=(e,r,t)=>{let n=void 0,o=void 0,s=r??"",i=(g)=>{if(!g)return[g,!1];return g.endsWith("?")?[g.substring(0,g.length-1),!0]:[g,!1]},a=(g,l)=>{let[c,h]=i(l.pop());if(!c){if(t?.set!==void 0&&o!==void 0&&n!==void 0)n[o]=t.set;return g}let f=zt(g,c,e,t);if(f===void 0){if(h||t?.optional||t?.defaultValue!==void 0)return;throw Error(`Unknown path element: "${c}" in "${s}"`)}return n=g,o=c,a(f,l)},u=qt.splitNested(s,t?.separator??".","{","}"),m=void 0;if(u.length>0&&u[u.length-1].startsWith("?="))m=u.pop()?.substring(2);u.reverse();let d=a(e,u);if(d===void 0)return m??t?.defaultValue;return d};var de=(e)=>{if(typeof e.value==="string")return e.parent;let r=e.value.model;if(!r)return e.parent;if(typeof r==="string")return O(e.root,r);return r};var we=(e)=>{if(typeof e.value==="string")return O(e.root,e.value);if(Array.isArray(e.value))return e.value;let r=e.value;if(typeof r.from==="string")return O(e.root,r.from);return r.from};var he=async(e,r)=>{let t=e.value;if(t.selector===void 0)return r;if(typeof t.selector!=="string"){let n=JSON.parse(JSON.stringify(t.selector));return await D(n,{...e.options,root:{...e.root,result:r}}),n}return await O({...e.root,result:r},t.selector)};var hr={};R(hr,{PathManager:()=>U});import Y from"path";class U{constructor(){}static normalize(e){return Y.normalize(Y.resolve(e))}static resolveInContext(e,r){let t=r??process.cwd(),n=Y.isAbsolute(e)?e:Y.join(t,e);return this.normalize(n)}static isDirectoryPattern(e){return e.endsWith("/")}static isGlobPattern(e){return e.includes("*")}static toAbsolute(e,r){if(Y.isAbsolute(e))return e;return Y.join(r??process.cwd(),e)}}var br={};R(br,{conditionPredicatesTypes:()=>re,conditionPredicates:()=>j});var j={and:(...e)=>e.every((r)=>!!r),or:(...e)=>e.some((r)=>!!r),xor:(...e)=>e.filter((r)=>!!r).length===1,true:(...e)=>e.every((r)=>!!r),false:(...e)=>e.every((r)=>!r),eq:(...e)=>e.every((r)=>r===e[0]),ne:(...e)=>e.some((r)=>r!==e[0]),lt:(...e)=>typeof e[0]==="number"&&e.slice(1).every((r)=>typeof r==="number"&&e[0]<r),le:(...e)=>typeof e[0]==="number"&&e.slice(1).every((r)=>typeof r==="number"&&e[0]<=r),gt:(...e)=>typeof e[0]==="number"&&e.slice(1).every((r)=>typeof r==="number"&&e[0]>r),ge:(...e)=>typeof e[0]==="number"&&e.slice(1).every((r)=>typeof r==="number"&&e[0]>=r),in:(e,r)=>{if(Array.isArray(r))return r.includes(e);if(typeof e==="string")return e.includes(r);if(Array.isArray(e))return e.includes(r);return!1},notin:(e,r)=>!j.in(e,r),contains:(e,r)=>e.includes(r),notcontains:(e,r)=>!e.includes(r),containsi:(e,r)=>e.toLowerCase().includes(r.toLowerCase()),notcontainsi:(e,r)=>!e.toLowerCase().includes(r.toLowerCase()),null:(...e)=>e.every((r)=>r===null||r===void 0),notnull:(...e)=>e.every((r)=>r!==null&&r!==void 0),empty:(...e)=>e.every((r)=>r===""),notempty:(...e)=>e.every((r)=>r!==""),nullorempty:(...e)=>e.every((r)=>r===null||r===void 0||r===""),notnullorempty:(...e)=>e.every((r)=>r!==null&&r!==void 0&&r!=="")},re={and:()=>"boolean",or:()=>"boolean",xor:()=>"boolean",true:()=>"boolean",false:()=>"boolean",lt:()=>"number",le:()=>"number",gt:()=>"number",ge:()=>"number"};var vr=()=>({each:{filters:[/select|model/],fn:async(e)=>{let r=e.value;delete e.parent[e.key];let t=await we(e),n=await de(e);if(!Array.isArray(t))throw Error('Key "each" requires a source list');if(n===void 0)throw Error('Key "each" must define a model');if(r.extend?.model)n=T([r.model,...Array.isArray(r.extend.model)?r.extend.model:[r.extend.model]]);let o=[];for(let s=0;s<t.length;s++){let i=$(n);if(await D(i,{...e.options,root:{...e.root,index:s,item:t[s],instance:i}}),r.extend?.result){let a=r.extend.result;i=T([i,...Array.isArray(a)?a:[a]])}o.push(await he(e,i))}return o}}});var Mr=()=>({map:{filters:[/select|model/],fn:async(e)=>{delete e.parent[e.key];let r=await we(e),t=await de(e);if(!Array.isArray(r))throw Error('Key "map" requires a source list');if(t===void 0)throw Error('Key "map" must define a model');let n=[];for(let o=0;o<r.length;o++){let s=$(t);await D(s,{...e.options,root:{...e.root,index:o,item:r[o],instance:s}}),n.push(await he(e,s))}return n}}});var Or=()=>({concat:async(e)=>{let r=[];for(let t of Array.isArray(e.value)?e.value:[e.value])r.push(...await O(e.root,t));return r.filter((t)=>t!==void 0)}});var Ar=()=>({extends:async(e)=>{let r=async(t,n)=>{for(let o of Array.isArray(n)?n:[n]){let s=await O(e.root,o),i=$(s);if(i[e.key])await r(i,i[e.key]);await D(i,{...e.options}),N(i,t),delete t[e.key]}};return await r(e.parent,e.value),b.Explore()},group:(e)=>{let r=e.root.parent,t=e.value,{items:n,...o}=t;return t.items.forEach((s)=>r.push({...o,...s})),b.DeleteParent()}});var kr=(e)=>({skip:{types:{0:"boolean"},fn:(r)=>r.value?b.DeleteParent():b.DeleteItem()},metadata:({path:r,value:t})=>{return e.metadata(r,t),b.DeleteItem()},if:{types:{0:"boolean"},fn:async(r)=>{let t=r.parent[".then"],n=r.parent[".else"];if(t!==void 0)delete r.parent[".then"];if(n!==void 0)delete r.parent[".else"];let o=r.value?t:n;if(o===void 0)return b.DeleteItem();if(typeof o==="string")return(await D({value:o},{...r.options,root:{...r.root}})).value;return b.ReplaceParent(o,!0)}},switch:(r)=>{let t=r.value;if(!t.cases)throw Error("Missing cases for switch");if(t.cases[t.from]!==void 0)return b.ReplaceParent(t.cases[t.from],!0);if(t.default!==void 0)return b.ReplaceParent(t.default,!0);return b.DeleteParent()}});var Er=()=>({from:async({root:e,parent:r,value:t})=>{let n=await O(e,t);if(n===null||n===void 0)throw Error(`Unable to resolve reference: ${t}`);if(r.content){if(Array.isArray(r.content)&&Array.isArray(n))return[...n,...r.content];return N(n,r.content),r.content}return n}});import Sr from"node:vm";var Dr=(e)=>({modules:async(r)=>{for(let[t,n]of Object.entries(r.value)){let o=Sr.createContext({console,objector:e,document:r.root}),s=new Sr.SourceTextModule(n,{identifier:t,context:o});await s.link((i)=>{throw Error(`Module ${i} is not allowed`)}),await s.evaluate(),e.sources(Object.fromEntries(Object.entries(s.namespace).map(([i,a])=>[`${t}.${i}`,(u)=>a(u,...u.args)])))}return b.DeleteItem()}});var Fr=()=>({try:{fn:(e)=>{let r=e.parent[".catch"];if(r!==void 0)delete e.parent[".catch"];try{return e.value}catch(t){if(r!==void 0)return r;return b.DeleteItem()}}}});var Rr=()=>({let:{fn:(e)=>{let r=e.value;return Object.assign(e.root,r),b.DeleteItem()}}});var $r=()=>({tap:{fn:(e)=>{return console.log(`[tap] ${e.path}:`,e.value),e.value}}});import jr from"fs/promises";import te from"path";var Wr=(e)=>({include:async(r)=>{let{file:t}=r.options.globalContext;return await Z(r.args[0],{cwd:te.dirname(t),filter:(n)=>te.basename(t)!==n,map:async(n)=>e.load(n,te.dirname(t),r.root)})},exists:async({args:[r]})=>await B(r),file:async(r)=>await jr.readFile(await _(r.args[0],e.getIncludeDirectories())).then((t)=>t.toString()),scan:async(r)=>{let t=[],o=(()=>{let a=r.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}=r.options.globalContext,i=r.args[1]?await _(r.args[1],e.getIncludeDirectories()):te.dirname(s);for await(let a of jr.glob(r.args[0],{cwd:i,exclude:(u)=>o.some((m)=>te.matchesGlob(u,m))}))t.push(a);return t}});var Nr=()=>F({env:(e)=>process.env[e]});var Cr={};R(Cr,{tokenize:()=>Ye,stripIndent:()=>Je,snake:()=>Q,pascal:()=>J,padBlock:()=>C,changeCase:()=>G,capital:()=>ne,camel:()=>oe});var J=(e)=>e.replace(/((?:[_ ]+)\w|^\w)/g,(r,t)=>t.toUpperCase()).replace(/[_ ]/g,""),ne=(e)=>e.replace(/((?:[ ]+)\w|^\w)/g,(r,t)=>t.toUpperCase()),oe=(e)=>{let r=J(e);return r.charAt(0).toLowerCase()+r.slice(1)},Q=(e,r="_")=>e.replace(/([a-z])([A-Z])/g,`$1${r}$2`).replace(/\s+/g,r).toLowerCase(),G=(e,r)=>{switch(r){case"upper":return e.toUpperCase();case"lower":return e.toLowerCase();default:return e}},C=(e,r,t=`
10
- `,n=" ")=>{let o=n.repeat(r);return e.split(t).map((s)=>o+s).join(t)},Ye=(e,r,t=/\${([^}]+)}/g)=>{return e.replace(t,(n,o)=>{let s=r[o];if(s===null||s===void 0)return"";if(typeof s==="string")return s;if(typeof s==="number"||typeof s==="boolean")return String(s);return String(s)})},Je=(e)=>{let r=e.split(/\r?\n/),t=r.filter((o)=>o.trim().length>0).map((o)=>/^[ \t]*/.exec(o)?.[0].length??0),n=t.length>0?Math.min(...t):0;if(n===0)return e;return r.map((o)=>o.slice(n)).join(`
11
- `)};var be=(e,r=0,t)=>{let n=" ".repeat(r),o=" ".repeat(r+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`[
12
- ${e.map((i)=>`${o}${be(i,r+1)},`).join(`
7
+ `;let Ve=i.lastIndexOf(`
8
+ `,f-1),He=Ve===-1?0:Ve+1,qe=i.slice(He,f).trim().length===0?He:f;i=i.slice(0,qe)+L+i.slice(w),a+=L.length-(w-qe),m.content=i}return[i,l]},or=(e)=>{let r=[],t=0;while(t<e.length)if(e[t]==="$"&&e[t+1]==="("&&(t===0||e[t-1]!=="\\")){let n=t;t+=2;let o=1;for(;t<e.length;t++)if(e[t]==="(")o++;else if(e[t]===")"){if(o--,o===0){r.push([n,t]);break}}if(o!==0)throw Error(`Unmatched opening $( at position ${n.toString()}`);t++}else t++;return r},Fe=Symbol.for("@homedev/fields:OverrideResult"),Ct=(e)=>({[Fe]:!0,value:e}),Lt=(e)=>{return e!==null&&typeof e==="object"&&Fe in e&&e[Fe]===!0},sr=async(e,r,t)=>{for(let n=r.length-1;n>=0;n--){let[o,s]=r[n],i=e.slice(o+2,s),a=await sr(i,or(i),t);if(typeof a==="object")return a;let l=await t(a,e);if(Lt(l))return l.value;e=e.slice(0,o)+l+e.slice(s+1)}return e},Ut=async(e,r)=>sr(e,or(e),r),It=(e)=>{return e!==null&&typeof e==="object"&&"action"in e},_t=/([\w\d.-_/]+):(.+)/,Tt=async(e,r,t,n)=>{let o=await(async()=>{let s=_t.exec(e);if(!s)return await V(r,e);let[i,a,l]=s,m=H(n.sources,a),y=pe(l,m,r);return await m.fn({args:y.parsedArgs,rawArgs:y.rawArgs,tags:y.tags,key:a,options:n,root:r,path:t,value:null})})();if(o===null||o===void 0)return"";if(typeof o==="object")return Ct(o);return o},ar=async(e,r,t,n)=>{let o=await Ut(r,(s)=>Tt(s,t,e,n));if(It(o))return o;if(o===r)return E.Explore();if(typeof o==="string"){let s=await ar(e,o,t,n);if(s.action!==U.Explore)return s;return E.ReplaceItem(o)}return E.ReplaceItem(o)},F=async(e,r)=>{return r??={},await wt(e,async(t)=>{let n=[...t.path,t.key].join(".");if(r?.filters?.length&&r.filters.some((a)=>a.test(n)))return E.NoExplore();let o=t.path.length===0,s=t.parents.length>0?t.parents.toReversed():[];if(o){if(s.length>0)throw Error("Root object should not have a parent");s=r?.root?.parents?[r.root.parent,...r.root.parents.toReversed()]:[]}let i={...e,...r.root,this:t.parent,parent:s.length>0?s[0]:null,parents:s};try{if(t.key.startsWith("$"))return E.NoExplore();let a=E.Explore();if(typeof t.value==="string"){let l=t.value,m=!1;while(!0){let[y,g]=await Nt(l,r,n,i);if(m=m||g,a=await ar(n,y,i,r),a.action===U.ReplaceItem&&typeof a.by==="string"){l=a.by;continue}if(a.action===U.Explore&&g&&y!==l)a=E.ReplaceItem(y);break}if(a.action===U.Explore&&l!==t.value)a=E.ReplaceItem(l);switch(a.action){case U.Explore:break;case U.ReplaceItem:t.value=a.by;break;default:return a}}if(jt(t,r))a=await Wt(t,n,i,r);return a}catch(a){throw Error(`${a.message}
9
+ (${n})`)}}),e},q=(e,r)=>r?{fn:(t)=>e(...t.args),types:r}:(t)=>e(...t.args),De=(e,r)=>Object.fromEntries(e.map((t)=>[t.name,q(t,r?.types?.[t.name])])),D=(e,r)=>Object.fromEntries((r?.keys??Object.keys(e)).map((t)=>[t,q(e[t],r?.types?.[t])]));var Ce={};$(Ce,{writeOutputs:()=>z,writeOutput:()=>ce,writeFormat:()=>fe,locate:()=>I,loadFormat:()=>P,importList:()=>me,importGlob:()=>Ne,globMap:()=>Z,exists:()=>Y});import ir from"fs/promises";import Re from"path";import Yt from"fs/promises";import Bt from"path";import Jt from"fs/promises";import Qt from"fs/promises";import pr from"fs/promises";import lr from"path";import Kt from"fs/promises";import je from"path";import ur from"path";var Y=async(e)=>{try{return await ir.access(e,ir.constants.R_OK),!0}catch{return!1}},I=async(e,r)=>{let t=!Re.isAbsolute(e)&&r?["",...r]:[""];for(let n of t){let o=Re.join(n,e);if(await Y(o))return Re.resolve(o)}throw Error(`File not found: "${e}"`)},P=async(e,r)=>{let t=await I(e,r?.dirs),n=await Yt.readFile(t,"utf-8"),o=Bt.dirname(t),s={text:{fn:(a)=>a,matching:["\\.txt$","\\.text$"]},json:{fn:JSON.parse,matching:["\\.json$"]},...r?.parsers},i=r?.format?s[r.format]:Object.values(s).find((a)=>a.matching?.some((l)=>new RegExp(l).test(e)));if(!i)throw Error(`Unsupported format for file "${e}" and no matching parser found`);return{content:await i.fn(n),fullPath:t,folderPath:o}},fe=async(e,r,t)=>{let n={text:{fn:(s)=>s,matching:["\\.txt$","\\.text$"]},json:{fn:JSON.stringify,matching:["\\.json$"]},...t?.encoders},o=t?.format?n[t.format]:Object.values(n).find((s)=>s.matching?.some((i)=>new RegExp(i).test(e)));if(!o)throw Error(`Unsupported format for file "${e}" and no matching encoder found`);await Jt.writeFile(e,await o.fn(r))},Z=async(e,r)=>{if(typeof e==="string"&&!e.includes("*"))return await r.map(e,0,[]);let t=await Array.fromAsync(Qt.glob(e,{cwd:r.cwd})),n=r.filter?t.filter(r.filter):t;return await Promise.all(n.map(r.map))},z=async(e,r)=>{if(r?.targetDirectory&&r?.removeFirst)try{await pr.rm(r?.targetDirectory,{recursive:!0,force:!0})}catch(t){throw Error(`Failed to clean the output directory: ${t.message}`)}for(let t of e)await ce(t,r)},ce=async(e,r)=>{let t=lr.join(r?.targetDirectory??".",e.name),n=lr.dirname(t);if(r?.classes){if(e.class!==void 0&&!r.classes.includes(e.class))return;if(r.classRequired&&e.class===void 0)throw Error(`Output "${e.name}" is missing class field`)}if(r?.writing?.(e)===!1)return;try{await pr.mkdir(n,{recursive:!0})}catch(o){throw Error(`Failed to create target directory "${n}" for output "${t}": ${o.message}`)}try{await fe(t,e.value,{format:e.type??"text"})}catch(o){throw Error(`Failed to write output "${t}": ${o.message}`)}},We=(e)=>e?ur.isAbsolute(e)?e:ur.join(process.cwd(),e):process.cwd(),me=async(e,r)=>{let t=[];for(let n of e)try{let o=!je.isAbsolute(n)?je.join(We(r?.cwd),n):n;if(r?.filter?.(o)===!1)continue;let s=await import(o);if(r?.resolveDefault==="only"&&!s.default)throw Error(`Module ${n} does not have a default export`);let i=r?.resolveDefault?s.default??s:s,a=r?.map?await r.map(i,n):i;if(a!==void 0)t.push(a)}catch(o){if(r?.fail?.(n,o)===!1)continue;throw Error(`Failed to import module ${n}: ${o.message??o}`)}return t},Ne=async(e,r)=>{let t=[];for(let n of e){let o=(await Array.fromAsync(Kt.glob(n,{cwd:We(r?.cwd)}))).map((s)=>je.join(We(r?.cwd),s));t.push(...await me(o,r))}return t};var Ye={};$(Ye,{toObjectWithKey:()=>Le,toObject:()=>ee,toList:()=>_,sortBy:()=>_e,nonNullMap:()=>Ue,defined:()=>Ie,deepClone:()=>R,asyncMap:()=>Te});var _=(e,r="name")=>Object.entries(e).map(([t,n])=>({[r]:t,...n})),Le=(e,r="name")=>Object.fromEntries(e.map((t)=>[t[r],t])),ee=(e,r="name")=>Object.fromEntries(e.map((t)=>{let{[r]:n,...o}=t;return[n,o]})),Ue=(e,r)=>{if(!e)return[];let t=[],n=0;for(let o of e)if(o!==null&&o!==void 0)t.push(r(o,n,e)),n++;return t},Ie=(e,r="Value is undefined")=>{if(e===void 0||e===null)throw Error(r);return e},_e=(e,r,t=(n,o)=>n-o)=>e.slice().sort((n,o)=>t(r(n),r(o))),Te=async(e,r)=>Promise.all(e.map(r)),R=(e)=>{if(typeof structuredClone<"u")try{return structuredClone(e)}catch{}return JSON.parse(JSON.stringify(e))};var qr={};$(qr,{defaultProcessors:()=>Ge});var fr={};$(fr,{navigate:()=>ye,find:()=>Be,NavigateResult:()=>b,NavigateAction:()=>ge});var ge;((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"})(ge||={});class b{action;by;skipSiblings;reexplore;constructor(e,r,t,n){this.action=e,this.by=r,this.skipSiblings=t,this.reexplore=n}static _explore=new b(0);static _noExplore=new b(2);static _skipSiblings=new b(1);static _deleteParent=new b(4);static ReplaceParent(e,r){return new b(3,e,void 0,r)}static SkipSiblings(){return b._skipSiblings}static Explore(){return b._explore}static NoExplore(){return b._noExplore}static DeleteParent(){return b._deleteParent}static MergeParent(e){return new b(5,e)}static ReplaceItem(e,r){return new b(6,e,r)}static DeleteItem(e){return new b(7,void 0,e)}}var ye=async(e,r)=>{let t=new WeakSet,n=[],o=[],s=async(a,l,m)=>{let y=a===null,g=y?b.Explore():await r({key:a,value:l,path:n,parent:m,parents:o});if(l&&typeof l==="object"&&g.action===0){if(t.has(l))return g;if(t.add(l),!y)n.push(a),o.push(m);let u=l;while(await i(u,a,m))u=m[a];if(!y)o.pop(),n.pop()}return g},i=async(a,l,m)=>{let y=Object.keys(a),g=y.length;for(let u=0;u<g;u++){let c=y[u],h=a[c],f=await s(c,h,a),w=f.action;if(w===0||w===2)continue;if(w===6){if(a[c]=f.by,f.skipSiblings)return;continue}if(w===7){if(delete a[c],f.skipSiblings)return;continue}if(w===1)return;if(w===3){if(l===null)throw Error("Cannot replace root object");if(m[l]=f.by,f.reexplore)return!0;return}if(w===4){if(l===null)throw Error("Cannot delete root object");delete m[l];return}if(w===5)delete a[c],Object.assign(a,f.by)}};await s(null,e,null)},Be=async(e,r)=>{let t=[];return await ye(e,(n)=>{if(r([...n.path,n.key].join("."),n.value))t.push(n.value);return b.Explore()}),t};var cr=(e)=>({output:(r)=>{delete r.parent[r.key];for(let t of Array.isArray(r.value)?r.value:[r.value])if(typeof t==="string")e.output({name:t,value:r.parent});else e.output({...t,value:t.value??r.parent});return b.SkipSiblings()}});import Gt from"path";var mr=(e)=>({load:async(r)=>{let t=r.options.globalContext;for(let{file:n}of Array.isArray(r.value)?r.value:[r.value]){if(!n)throw Error("File reference required");await e.load(n,t.file&&Gt.dirname(t.file))}return b.DeleteItem()}});var gr={};$(gr,{mergeAll:()=>B,merge:()=>N});var N=(e,r,t)=>{for(let n of Object.keys(r)){if(e[n]===void 0)continue;let o=r[n],s=e[n];if(typeof s!==typeof o||Array.isArray(s)!==Array.isArray(o)){let a=t?.mismatch?.(n,s,o,e,r);if(a!==void 0){r[n]=a;continue}throw Error(`Type mismatch: ${n}`)}let i=t?.mode?.(n,s,o,e,r)??r[".merge"]??"merge";switch(i){case"source":r[n]=s;continue;case"target":continue;case"skip":delete r[n],delete e[n];continue;case"merge":break;default:throw Error(`Unknown merge mode: ${i}`)}if(typeof s==="object")if(Array.isArray(s))o.push(...s);else{if(t?.navigate?.(n,s,o,e,r)===!1)continue;N(s,o,t)}else{if(s===o)continue;let a=t?.conflict?.(n,s,o,e,r);r[n]=a===void 0?o:a}}for(let n of Object.keys(e))if(r[n]===void 0)r[n]=e[n]},B=(e,r)=>{let t={};for(let n of e.toReversed())N(n,t,r);return t};var yr={};$(yr,{CacheManager:()=>de});class de{cache=new Map;maxSize;constructor(e=100){this.maxSize=e}get(e){return this.cache.get(e)}set(e,r){this.evictIfNeeded(),this.cache.set(e,r)}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,r=1/0;for(let[t,n]of this.cache.entries())if(n.timestamp<r)r=n.timestamp,e=t;if(e)this.cache.delete(e)}}}var wr={};$(wr,{select:()=>O});var xt=Object.create,{getPrototypeOf:Xt,defineProperty:dr,getOwnPropertyNames:Vt}=Object,Ht=Object.prototype.hasOwnProperty,qt=(e,r,t)=>{t=e!=null?xt(Xt(e)):{};let n=r||!e||!e.__esModule?dr(t,"default",{value:e,enumerable:!0}):t;for(let o of Vt(e))if(!Ht.call(n,o))dr(n,o,{get:()=>e[o],enumerable:!0});return n},Pt=(e,r)=>()=>(r||e((r={exports:{}}).exports,r),r.exports),Zt=Pt((e,r)=>{var{defineProperty:t,getOwnPropertyNames:n,getOwnPropertyDescriptor:o}=Object,s=Object.prototype.hasOwnProperty,i=new WeakMap,a=(u)=>{var c=i.get(u),h;if(c)return c;if(c=t({},"__esModule",{value:!0}),u&&typeof u==="object"||typeof u==="function")n(u).map((f)=>!s.call(c,f)&&t(c,f,{get:()=>u[f],enumerable:!(h=o(u,f))||h.enumerable}));return i.set(u,c),c},l=(u,c)=>{for(var h in c)t(u,h,{get:c[h],enumerable:!0,configurable:!0,set:(f)=>c[h]=()=>f})},m={};l(m,{splitWithQuotes:()=>g,splitNested:()=>y}),r.exports=a(m);var y=(u,c,h="(",f=")")=>{let w=0,p="",v=[];for(let d of u){if(p+=d,d===h)w++;if(d===f)w--;if(w===0&&d===c)v.push(p.slice(0,-1)),p=""}if(p)v.push(p);return v},g=(u,c=",")=>{let h=[],f=u.length,w=c.length,p=0,v=(d)=>{if(d+w>f)return!1;for(let M=0;M<w;M++)if(u[d+M]!==c[M])return!1;return!0};while(p<f){while(p<f&&u[p]===" ")p++;if(p>=f)break;let d="",M=u[p]==='"'||u[p]==="'";if(M){let A=u[p++];while(p<f&&u[p]!==A)d+=u[p++];if(p<f)p++}else{while(p<f&&!v(p)){let A=u[p];if(A==='"'||A==="'"){d+=A,p++;while(p<f&&u[p]!==A)d+=u[p++];if(p<f)d+=u[p++]}else d+=u[p++]}d=d.trim()}if(d)h.push({value:d,quoted:M});if(v(p))p+=w}return h}}),zt=qt(Zt(),1),en=/^\[([^=\]]*)([=]*)([^\]]*)\]$/,rn=/^([^[\]]*)\[([^\]]*)]$/,Je=(e,r,t,n)=>{if(e.startsWith("{")&&e.endsWith("}")){let o=e.substring(1,e.length-1);return O(r,o,t)?.toString()}return n?e:void 0},tn=(e,r,t,n)=>{let o=Je(r,t,n);if(o)return O(e,o,n);let s=en.exec(r);if(s){let[,a,l,m]=s,y=Je(a.trim(),t,n,!0),g=Je(m.trim(),t,n,!0);if(Array.isArray(e)&&(l==="="||l==="==")&&y)return e.find((u)=>u?.[y]==g)}let i=rn.exec(r);if(i){let[,a,l]=i;return e?.[a]?.[l]}return e?.[r]},O=(e,r,t)=>{let n=void 0,o=void 0,s=r??"",i=(g)=>{if(!g)return[g,!1];return g.endsWith("?")?[g.substring(0,g.length-1),!0]:[g,!1]},a=(g,u)=>{let[c,h]=i(u.pop());if(!c){if(t?.set!==void 0&&o!==void 0&&n!==void 0)n[o]=t.set;return g}let f=tn(g,c,e,t);if(f===void 0){if(h||t?.optional||t?.defaultValue!==void 0)return;throw Error(`Unknown path element: "${c}" in "${s}"`)}return n=g,o=c,a(f,u)},l=zt.splitNested(s,t?.separator??".","{","}"),m=void 0;if(l.length>0&&l[l.length-1].startsWith("?="))m=l.pop()?.substring(2);l.reverse();let y=a(e,l);if(y===void 0)return m??t?.defaultValue;return y};var we=(e)=>{if(typeof e.value==="string")return e.parent;let r=e.value.model;if(!r)return e.parent;if(typeof r==="string")return O(e.root,r);return r};var he=(e)=>{if(typeof e.value==="string")return O(e.root,e.value);if(Array.isArray(e.value))return e.value;let r=e.value;if(typeof r.from==="string")return O(e.root,r.from);return r.from};var be=async(e,r)=>{let t=e.value;if(t.selector===void 0)return r;if(typeof t.selector!=="string"){let n=JSON.parse(JSON.stringify(t.selector));return await F(n,{...e.options,root:{...e.root,result:r}}),n}return await O({...e.root,result:r},t.selector)};var hr={};$(hr,{PathManager:()=>T});import J from"path";class T{constructor(){}static normalize(e){return J.normalize(J.resolve(e))}static resolveInContext(e,r){let t=r??process.cwd(),n=J.isAbsolute(e)?e:J.join(t,e);return this.normalize(n)}static isDirectoryPattern(e){return e.endsWith("/")}static isGlobPattern(e){return e.includes("*")}static toAbsolute(e,r){if(J.isAbsolute(e))return e;return J.join(r??process.cwd(),e)}}var br={};$(br,{conditionPredicatesTypes:()=>re,conditionPredicates:()=>j});var j={and:(...e)=>e.every((r)=>!!r),or:(...e)=>e.some((r)=>!!r),xor:(...e)=>e.filter((r)=>!!r).length===1,true:(...e)=>e.every((r)=>!!r),false:(...e)=>e.every((r)=>!r),eq:(...e)=>e.every((r)=>r===e[0]),ne:(...e)=>e.some((r)=>r!==e[0]),lt:(...e)=>typeof e[0]==="number"&&e.slice(1).every((r)=>typeof r==="number"&&e[0]<r),le:(...e)=>typeof e[0]==="number"&&e.slice(1).every((r)=>typeof r==="number"&&e[0]<=r),gt:(...e)=>typeof e[0]==="number"&&e.slice(1).every((r)=>typeof r==="number"&&e[0]>r),ge:(...e)=>typeof e[0]==="number"&&e.slice(1).every((r)=>typeof r==="number"&&e[0]>=r),in:(e,r)=>{if(Array.isArray(r))return r.includes(e);if(typeof e==="string")return e.includes(r);if(Array.isArray(e))return e.includes(r);return!1},notin:(e,r)=>!j.in(e,r),contains:(e,r)=>e.includes(r),notcontains:(e,r)=>!e.includes(r),containsi:(e,r)=>e.toLowerCase().includes(r.toLowerCase()),notcontainsi:(e,r)=>!e.toLowerCase().includes(r.toLowerCase()),null:(...e)=>e.every((r)=>r===null||r===void 0),notnull:(...e)=>e.every((r)=>r!==null&&r!==void 0),empty:(...e)=>e.every((r)=>r===""),notempty:(...e)=>e.every((r)=>r!==""),nullorempty:(...e)=>e.every((r)=>r===null||r===void 0||r===""),notnullorempty:(...e)=>e.every((r)=>r!==null&&r!==void 0&&r!=="")},re={and:()=>"boolean",or:()=>"boolean",xor:()=>"boolean",true:()=>"boolean",false:()=>"boolean",lt:()=>"number",le:()=>"number",gt:()=>"number",ge:()=>"number"};var vr=()=>({each:{filters:[/select|model/],fn:async(e)=>{let r=e.value;delete e.parent[e.key];let t=await he(e),n=await we(e);if(!Array.isArray(t))throw Error('Key "each" requires a source list');if(n===void 0)throw Error('Key "each" must define a model');if(r.extend?.model)n=B([r.model,...Array.isArray(r.extend.model)?r.extend.model:[r.extend.model]]);let o=[];for(let s=0;s<t.length;s++){let i=R(n);if(await F(i,{...e.options,root:{...e.root,index:s,item:t[s],instance:i}}),r.extend?.result){let a=r.extend.result;i=B([i,...Array.isArray(a)?a:[a]])}o.push(await be(e,i))}return o}}});var Mr=()=>({map:{filters:[/select|model/],fn:async(e)=>{delete e.parent[e.key];let r=await he(e),t=await we(e);if(!Array.isArray(r))throw Error('Key "map" requires a source list');if(t===void 0)throw Error('Key "map" must define a model');let n=[];for(let o=0;o<r.length;o++){let s=R(t);await F(s,{...e.options,root:{...e.root,index:o,item:r[o],instance:s}}),n.push(await be(e,s))}return n}}});var Or=()=>({concat:async(e)=>{let r=[];for(let t of Array.isArray(e.value)?e.value:[e.value])r.push(...await O(e.root,t));return r.filter((t)=>t!==void 0)}});var Er=()=>({extends:async(e)=>{let r=async(t,n)=>{for(let o of Array.isArray(n)?n:[n]){let s=await O(e.root,o),i=R(s);if(i[e.key])await r(i,i[e.key]);await F(i,{...e.options}),N(i,t),delete t[e.key]}};return await r(e.parent,e.value),b.Explore()},group:(e)=>{let r=e.root.parent,t=e.value,{items:n,...o}=t;return t.items.forEach((s)=>r.push({...o,...s})),b.DeleteParent()}});var kr=(e)=>({skip:{types:{0:"boolean"},fn:(r)=>r.value?b.DeleteParent():b.DeleteItem()},metadata:({path:r,value:t})=>{return e.metadata(r,t),b.DeleteItem()},if:{types:{0:"boolean"},fn:async(r)=>{let t=r.parent[".then"],n=r.parent[".else"];if(t!==void 0)delete r.parent[".then"];if(n!==void 0)delete r.parent[".else"];let o=r.value?t:n;if(o===void 0)return b.DeleteItem();if(typeof o==="string")return(await F({value:o},{...r.options,root:{...r.root}})).value;return b.ReplaceParent(o,!0)}},switch:(r)=>{let t=r.value;if(!t.cases)throw Error("Missing cases for switch");if(t.cases[t.from]!==void 0)return b.ReplaceParent(t.cases[t.from],!0);if(t.default!==void 0)return b.ReplaceParent(t.default,!0);return b.DeleteParent()}});var Ar=()=>({from:async({root:e,parent:r,value:t})=>{let n=await O(e,t);if(n===null||n===void 0)throw Error(`Unable to resolve reference: ${t}`);if(r.content){if(Array.isArray(r.content)&&Array.isArray(n))return[...n,...r.content];return N(n,r.content),r.content}return n}});import Sr from"node:vm";var Fr=(e)=>({modules:async(r)=>{for(let[t,n]of Object.entries(r.value)){let o=Sr.createContext({console,objector:e,document:r.root}),s=new Sr.SourceTextModule(n,{identifier:t,context:o});await s.link((i)=>{throw Error(`Module ${i} is not allowed`)}),await s.evaluate(),e.sources(Object.fromEntries(Object.entries(s.namespace).map(([i,a])=>[`${t}.${i}`,(l)=>a(l,...l.args)])))}return b.DeleteItem()}});var Dr=()=>({try:{fn:(e)=>{let r=e.parent[".catch"];if(r!==void 0)delete e.parent[".catch"];try{return e.value}catch(t){if(r!==void 0)return r;return b.DeleteItem()}}}});var $r=()=>({let:{fn:(e)=>{let r=e.value;return Object.assign(e.root,r),b.DeleteItem()}}});var Rr=()=>({tap:{fn:(e)=>{return console.log(`[tap] ${e.path}:`,e.value),e.value}}});import jr from"fs/promises";import te from"path";var Wr=(e)=>({include:async(r)=>{let{file:t}=r.options.globalContext;return await Z(r.args[0],{cwd:te.dirname(t),filter:(n)=>te.basename(t)!==n,map:async(n)=>e.load(n,te.dirname(t),r.root)})},exists:async({args:[r]})=>await Y(r),file:async(r)=>await jr.readFile(await I(r.args[0],e.getIncludeDirectories())).then((t)=>t.toString()),scan:async(r)=>{let t=[],o=(()=>{let a=r.args[2]??["**/node_modules/**"],l=typeof a==="string"?a.split(",").map((m)=>m.trim()):a;if(!Array.isArray(l))throw Error("Scan exclusion must be a list");return l})(),{file:s}=r.options.globalContext,i=r.args[1]?await I(r.args[1],e.getIncludeDirectories()):te.dirname(s);for await(let a of jr.glob(r.args[0],{cwd:i,exclude:(l)=>o.some((m)=>te.matchesGlob(l,m))}))t.push(a);return t}});var Nr=()=>D({env:(e)=>process.env[e]});var Cr={};$(Cr,{tokenize:()=>Qe,stripIndent:()=>Ke,snake:()=>K,pascal:()=>Q,padBlock:()=>C,changeCase:()=>G,capital:()=>ne,camel:()=>oe});var Q=(e)=>e.replace(/((?:[_ ]+)\w|^\w)/g,(r,t)=>t.toUpperCase()).replace(/[_ ]/g,""),ne=(e)=>e.replace(/((?:[ ]+)\w|^\w)/g,(r,t)=>t.toUpperCase()),oe=(e)=>{let r=Q(e);return r.charAt(0).toLowerCase()+r.slice(1)},K=(e,r="_")=>e.replace(/([a-z])([A-Z])/g,`$1${r}$2`).replace(/\s+/g,r).toLowerCase(),G=(e,r)=>{switch(r){case"upper":return e.toUpperCase();case"lower":return e.toLowerCase();default:return e}},C=(e,r,t=`
10
+ `,n=" ")=>{let o=n.repeat(r);return e.split(t).map((s)=>o+s).join(t)},Qe=(e,r,t=/\${([^}]+)}/g)=>{return e.replace(t,(n,o)=>{let s=r[o];if(s===null||s===void 0)return"";if(typeof s==="string")return s;if(typeof s==="number"||typeof s==="boolean")return String(s);return String(s)})},Ke=(e)=>{let r=e.split(/\r?\n/),t=r.filter((o)=>o.trim().length>0).map((o)=>/^[ \t]*/.exec(o)?.[0].length??0),n=t.length>0?Math.min(...t):0;if(n===0)return e;return r.map((o)=>o.slice(n)).join(`
11
+ `)};var Lr=(e)=>({substring:{types:{0:"ref",1:"number",2:"number"},fn:(r)=>r.args[0].substring(r.args[1],r.args[2])},repeat:{types:{0:"ref",1:"number"},fn:({args:[r,t]})=>r.repeat(t)},uuid:(r)=>crypto.randomUUID(),pad:{types:{0:"ref",1:"number",2:"string"},fn:({args:[r,t],tags:n})=>{let o=n.join?.[0]??`
12
+ `,s=n.padChar?.[0]??" ";return C(r,t??2,o,s)}},formatAs:{fn:({args:[r,t],tags:n})=>{let o=e.getEncoder(t);if(!o)throw Error("Unsupported format: "+String(t));let s=[];if(o.options?.includeTags)s=[n];return o.fn(r,...s)}},...D({pascal:Q,camel:oe,capital:ne,concat:(...r)=>r.join(""),len:(r)=>r.length,reverse:(r)=>r.split("").reverse().join(""),trim:(r)=>r.trim(),ltrim:(r)=>r.trimStart(),rtrim:(r)=>r.trimEnd(),lower:(r)=>r.toLowerCase(),upper:(r)=>r.toUpperCase(),snake:(r,t)=>G(K(r,"_"),t),kebab:(r,t)=>G(K(r,"-"),t),encode:(r,t)=>Buffer.from(r).toString(t??"base64"),decode:(r,t)=>Buffer.from(r,t??"base64").toString()})});var ve=(e,r=0,t)=>{let n=" ".repeat(r),o=" ".repeat(r+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`[
13
+ ${e.map((i)=>`${o}${ve(i,r+1)},`).join(`
13
14
  `)}
14
- ${n}]`}else if(typeof e==="object"){let s=Object.entries(e).sort((a,u)=>t?.sortKeys?a[0].localeCompare(u[0]):0);if(s.length===0)return"{}";return`{
15
- ${s.map(([a,u])=>`${o}${a} = ${be(u,r+1,t)}`).join(`
15
+ ${n}]`}else if(typeof e==="object"){let s=Object.entries(e).sort((a,l)=>t?.sortKeys?a[0].localeCompare(l[0]):0);if(s.length===0)return"{}";return`{
16
+ ${s.map(([a,l])=>`${o}${a} = ${ve(l,r+1,t)}`).join(`
16
17
  `)}
17
18
  ${n}}`}else return String(e)},se=(e)=>{if(!e)return e;return e.replaceAll("\\n",`
18
- `).replaceAll("\\$","$").replaceAll("\\t","\t")};var Lr=()=>({substring:{types:{0:"ref",1:"number",2:"number"},fn:(e)=>e.args[0].substring(e.args[1],e.args[2])},repeat:{types:{0:"ref",1:"number"},fn:({args:[e,r]})=>e.repeat(r)},uuid:(e)=>crypto.randomUUID(),pad:{types:{0:"ref",1:"number",2:"string"},fn:({args:[e,r],tags:t})=>{let n=t.join?.[0]??`
19
- `,o=t.padChar?.[0]??" ";return C(e,r??2,n,o)}},formatAs:{types:{1:["json","yaml","terraform"]},fn:({args:[e,r],tags:t})=>{switch(r){case"json":return JSON.stringify(e,null,2);case"yaml":return Bun.YAML.stringify(e,null,2);case"terraform":{let n=!!(t?.sort?.length||t?.sortKeys?.length);return be(e,0,{sortKeys:n})}}throw Error("Unsupported format: "+String(r))}},...F({pascal:J,camel:oe,capital:ne,fromYaml:Bun.YAML.parse,fromJson:JSON.parse,toYaml:(e,r)=>Bun.YAML.stringify(e,null,r??2),toJson:(e,r)=>JSON.stringify(e,null,r!==0?r??2:void 0),concat:(...e)=>e.join(""),len:(e)=>e.length,reverse:(e)=>e.split("").reverse().join(""),trim:(e)=>e.trim(),ltrim:(e)=>e.trimStart(),rtrim:(e)=>e.trimEnd(),lower:(e)=>e.toLowerCase(),upper:(e)=>e.toUpperCase(),snake:(e,r)=>G(Q(e,"_"),r),kebab:(e,r)=>G(Q(e,"-"),r),encode:(e,r)=>Buffer.from(e).toString(r??"base64"),decode:(e,r)=>Buffer.from(e,r??"base64").toString()})});var _r=()=>({...F({merge:(...e)=>e.flatMap((r)=>r)}),join:({args:[e],root:r,tags:t})=>{let n=t.key?.[0],o=t.separator?.[0]??t.sep?.[0],s=t.finalize?.length>0,i=se(o);if(typeof e==="string"){if(s&&e.length&&i)return e+i;return e}if(!Array.isArray(e))throw Error("Object is not a list");let a=((n?.length)?e.map((g)=>O({...r,...g},n)):e).join(i),u=t.pad?.[0]??"0",m=t.padChar?.[0]??" ",d=s&&a.length&&i?a+i:a;return u?C(d,parseInt(u),`
20
- `,m):d},list:({args:e})=>I(e[0],e[1]),object:({args:e})=>ee(e[0],e[1]),range:({args:[e,r,t]})=>{let n=parseInt(e),o=parseInt(r),s=parseInt(t)||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(r)+"' 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},(i,a)=>n+a*s)},filter:{types:(e,r,t)=>{switch(e){case 0:return"array";case 1:return Object.keys(j)}return re[t[1].value]?.(e-2,r,t.slice(2))},fn:({args:[e,r,t],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],i=j[r];if(s){let u=Array(e.length);for(let d=0;d<e.length;d++)try{u[d]=O({...n,...e[d]},s)}catch{u[d]=Symbol("invalid")}let m=[];for(let d=0;d<e.length;d++){let g=u[d];if(typeof g!=="symbol"&&t===void 0?i(g):i(g,t))m.push(e[d])}return m}let a=[];for(let u of e)if(t===void 0?i(u):i(u,t))a.push(u);return a}}});var Ir=()=>({each:{processArgs:!1,fn:async({rawArgs:[e,r,...t],root:n,options:o,tags:s})=>{let i=async(f)=>f.quoted?se(f.value):await O(n,f.value),a=await O(n,e.value),u=await i(r),m=s.key?.[0],d=Array.isArray(a)?a:I(a),g=[],l=await Promise.all(t.map(async(f)=>await i(f))),c={...n,item:void 0,index:0,params:l,instance:void 0,parent:n.this,tags:s},h={...o,root:c};for(let f=0;f<d.length;f++){let w=$(u),p={instance:w},v=typeof u==="string"?p:w;if(c.item=d[f],c.index=f,c.instance=w,s?.root?.[0])Object.assign(c,await O(c,s.root[0]));if(await D(v,h),m!==void 0)g.push(await O(p.instance,m));else g.push(p.instance)}if(s.join?.length){if(g.length===0)return"";let f=se(s.join[0]),w=s.pad?.[0]??"0",p=s.padChar?.[0]??" ",v=s.finalize?.length&&f?f:"",y=`${g.join(f)}${v}`;return w?C(y,parseInt(w),`
21
- `,p):y}return g}}});var ae=async(e,r,t)=>e.rawArgs[r].quoted?e.rawArgs[r].value:await O(e.root,e.rawArgs[r].value,{defaultValue:t}),Ur=()=>({switch:{processArgs:!1,fn:async(e)=>{let r=await ae(e,0,!1),t=await ae(e,1);if(t[r]===void 0){if(e.rawArgs.length>2)return ae(e,2);throw Error(`Unhandled switch case: ${r}`)}return t[r]}}});var Br=()=>F({log:console.log});var Tr=()=>({if:{types:{0:"boolean"},fn:(e)=>e.args[0]?e.args[1]:e.args[2]},check:{types:{0:Object.keys(j)},fn:(e)=>j[e.args[0]](...e.args.slice(1))},...F(j,{types:re})});var Yr=(e)=>({default:{processArgs:!1,fn:async(r)=>{for(let t=0;t<r.rawArgs.length;t++)if(r.rawArgs[t]?.value!==void 0){let o=await ae(r,t,null);if(o!==null)return o}if(r.tags.nullable?.length)return b.DeleteItem();if(r.tags.fail?.length)throw Error(`No valid value found for default (${r.rawArgs.map((t)=>t.value).join(", ")})`);return""}},section:{types:["string","boolean"],fn:(r)=>{let t=r.args[0];if(!(r.args[1]??!0))return null;let o=e.getSection(t);if(!o)throw Error(`Section not found: ${t}`);return o.content}}});var Jr=()=>({convert:({args:[e,r,t]})=>{switch(r){case"string":return String(e);case"number":{let n=Number(e);if(!isNaN(n))return b.ReplaceItem(n);break}case"boolean":if(e==="true"||e===!0||e===1||e==="1"||e==="yes"||e==="on")return b.ReplaceItem(!0);else if(e==="false"||e===!1||e===0||e==="0"||e==="no"||e==="off")return b.ReplaceItem(!1);break;default:throw Error(`Unsupported type for convert: ${r}`)}if(t!==void 0)return b.ReplaceItem(t);throw Error(`Failed to convert value to ${r}`)},isType:({args:[e,r]})=>{let n=(()=>{switch(r){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: ${r}`)}})();return b.ReplaceItem(n)},typeOf:({args:[e]})=>{if(e===null)return"null";else if(Array.isArray(e))return"array";else return typeof e}});var Qr=()=>({...F({add:(...e)=>e.reduce((r,t)=>r+t,0),subtract:(e,r)=>e-r,multiply:(...e)=>e.reduce((r,t)=>r*t,1),divide:(e,r)=>{if(r===0)throw Error("Division by zero");return e/r},modulo:(e,r)=>e%r,power:(e,r)=>Math.pow(e,r),sqrt:(e)=>Math.sqrt(e),abs:(e)=>Math.abs(e),floor:(e)=>Math.floor(e),ceil:(e)=>Math.ceil(e),round:(e,r)=>{let t=Math.pow(10,r??0);return Math.round(e*t)/t},min:(...e)=>Math.min(...e),max:(...e)=>Math.max(...e),clamp:(e,r,t)=>Math.max(r,Math.min(t,e)),random:(e,r)=>{let t=e??0,n=r??1;return Math.random()*(n-t)+t}})});var Gr=()=>({now:()=>new Date,timestamp:(e)=>{let r=e.args?.[0];return(r?new Date(r):new Date).getTime()},iso:(e)=>{let r=e.args?.[0];return(r?new Date(r):new Date).toISOString()},utc:(e)=>{let r=e.args?.[0];return(r?new Date(r):new Date).toUTCString()},format:(e)=>{let r=e.args?.[0],t=e.args?.[1],n=new Date(r),o=n.getFullYear(),s=String(n.getMonth()+1).padStart(2,"0"),i=String(n.getDate()).padStart(2,"0"),a=String(n.getHours()).padStart(2,"0"),u=String(n.getMinutes()).padStart(2,"0"),m=String(n.getSeconds()).padStart(2,"0");return t.replace("YYYY",String(o)).replace("MM",s).replace("DD",i).replace("HH",a).replace("mm",u).replace("ss",m)},parse:(e)=>{let r=e.args?.[0];return new Date(r).getTime()},year:(e)=>{let r=e.args?.[0];return(r?new Date(r):new Date).getFullYear()},month:(e)=>{let r=e.args?.[0];return(r?new Date(r):new Date).getMonth()+1},day:(e)=>{let r=e.args?.[0];return(r?new Date(r):new Date).getDate()},dayOfWeek:(e)=>{let r=e.args?.[0];return(r?new Date(r):new Date).getDay()},hours:(e)=>{let r=e.args?.[0];return(r?new Date(r):new Date).getHours()},minutes:(e)=>{let r=e.args?.[0];return(r?new Date(r):new Date).getMinutes()},seconds:(e)=>{let r=e.args?.[0];return(r?new Date(r):new Date).getSeconds()}});var Kr=()=>{return{unique:(e)=>{let r=e.args?.[0]??e.value,t=e.args?.[1];if(!Array.isArray(r))return r;let n=new Set;return r.filter((o)=>{let s=typeof t==="function"?t(o):t?o[t]:o;if(n.has(s))return!1;return n.add(s),!0})},groupBy:(e)=>{let r=e.args?.[0]??e.value,t=e.args?.[1];if(!Array.isArray(r))return r;let n={};return r.forEach((o)=>{let s=typeof t==="function"?String(t(o)):String(o[t]);if(!n[s])n[s]=[];n[s].push(o)}),n},partition:(e)=>{let r=e.args?.[0]??e.value,t=e.args?.[1];if(!Array.isArray(r))return[[],[]];if(typeof t!=="function")return[r,[]];let n=[],o=[];return r.forEach((s)=>{(t(s)?n:o).push(s)}),[n,o]},chunk:(e)=>{let r=e.args?.[0]??e.value,t=e.args?.[1]??1;if(!Array.isArray(r))return[];let n=[];for(let o=0;o<r.length;o+=t)n.push(r.slice(o,o+t));return n},flatten:(e)=>{let r=e.args?.[0]??e.value,t=e.args?.[1]??1;if(!Array.isArray(r))return[r];let n=[],o=(s,i)=>{for(let a of s)if(Array.isArray(a)&&i>0)o(a,i-1);else n.push(a)};return o(r,t),n},compact:(e)=>{let r=e.args?.[0]??e.value;if(!Array.isArray(r))return r;return r.filter((t)=>t!==null&&t!==void 0)},head:(e)=>{let r=e.args?.[0]??e.value,t=e.args?.[1];if(!Array.isArray(r))return r;return t?r.slice(0,t):r[0]},tail:(e)=>{let r=e.args?.[0]??e.value,t=e.args?.[1];if(!Array.isArray(r))return r;return t?r.slice(-t):r[r.length-1]}}};import{createHash as ie}from"crypto";var Xr=()=>({md5:(e)=>{let r=e.args?.[0]??e.value;return ie("md5").update(r).digest("hex")},sha1:(e)=>{let r=e.args?.[0]??e.value;return ie("sha1").update(r).digest("hex")},sha256:(e)=>{let r=e.args?.[0]??e.value;return ie("sha256").update(r).digest("hex")},sha512:(e)=>{let r=e.args?.[0]??e.value;return ie("sha512").update(r).digest("hex")},hash:(e)=>{let r=e.args?.[0]??e.value,t=e.args?.[1]??"sha256";return ie(t).update(r).digest("hex")},base64Encode:(e)=>{let r=e.args?.[0]??e.value,t=typeof r==="string"?r:JSON.stringify(r);return Buffer.from(t).toString("base64")},base64Decode:(e)=>{let r=e.args?.[0]??e.value;return Buffer.from(r,"base64").toString("utf-8")},hexEncode:(e)=>{let r=e.args?.[0]??e.value;return Buffer.from(r).toString("hex")},hexDecode:(e)=>{let r=e.args?.[0]??e.value;return Buffer.from(r,"hex").toString("utf-8")}});var Vr=()=>({test:(e)=>{let r=e.args?.[0],t=e.args?.[1],n=e.args?.[2];return new RegExp(r,n).test(t)},match:(e)=>{let r=e.args?.[0],t=e.args?.[1],n=e.args?.[2],o=new RegExp(r,n);return t.match(o)},matchAll:(e)=>{let r=e.args?.[0],t=e.args?.[1],n=e.args?.[2],o=new RegExp(r,n);return Array.from(t.matchAll(o))},replace:(e)=>{let r=e.args?.[0],t=e.args?.[1],n=e.args?.[2],o=e.args?.[3],s=new RegExp(r,o);return n.replace(s,t)},replaceAll:(e)=>{let r=e.args?.[0],t=e.args?.[1],n=e.args?.[2],o=e.args?.[3]??"g",s=new RegExp(r,o);return n.replace(s,t)},split:(e)=>{let r=e.args?.[0],t=e.args?.[1],n=e.args?.[2],o=new RegExp(r,n);return t.split(o)},exec:(e)=>{let r=e.args?.[0],t=e.args?.[1],n=e.args?.[2];return new RegExp(r,n).exec(t)},search:(e)=>{let r=e.args?.[0],t=e.args?.[1],n=e.args?.[2],o=new RegExp(r,n);return t.search(o)}});import{resolve as en,dirname as rn,basename as tn,normalize as nn,join as on}from"path";var Hr=()=>({...F({pathJoin:(...e)=>on(...e),resolve:(...e)=>en(...e),dirname:(e)=>rn(e),basename:(e,r)=>tn(e,r),normalize:(e)=>nn(e),extname:(e)=>{let r=/\.[^.]*$/.exec(e);return r?r[0]:""},relative:(e,r)=>{let t=e.split("/"),n=r.split("/"),o=0;while(o<t.length&&o<n.length&&t[o]===n[o])o++;let s=t.length-o,i=n.slice(o);return[...Array(s).fill("..")].concat(i).join("/")},isAbsolute:(e)=>e.startsWith("/"),segments:(e)=>e.split("/").filter(Boolean)})});var xr=()=>({isEmail:(e)=>{let r=e.args?.[0]??e.value;return/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(r)},isUrl:(e)=>{let r=e.args?.[0]??e.value;try{return new URL(r),!0}catch{return!1}},isJson:(e)=>{let r=e.args?.[0]??e.value;try{return JSON.parse(r),!0}catch{return!1}},isUuid:(e)=>{let r=e.args?.[0]??e.value;return/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i.test(r)},minLength:(e)=>{let r=e.args?.[0]??e.value,t=e.args?.[1];return r?.length>=t},maxLength:(e)=>{let r=e.args?.[0]??e.value,t=e.args?.[1];return r?.length<=t},length:(e)=>{let r=e.args?.[0]??e.value,t=e.args?.[1];return r?.length===t},isNumber:(e)=>{let r=e.args?.[0]??e.value;return typeof r==="number"&&!isNaN(r)},isString:(e)=>{return typeof(e.args?.[0]??e.value)==="string"},isBoolean:(e)=>{return typeof(e.args?.[0]??e.value)==="boolean"},isArray:(e)=>{let r=e.args?.[0]??e.value;return Array.isArray(r)},isObject:(e)=>{let r=e.args?.[0]??e.value;return r!==null&&typeof r==="object"&&!Array.isArray(r)},isEmpty:(e)=>{let r=e.args?.[0]??e.value;if(r===null||r===void 0)return!0;if(typeof r==="string"||Array.isArray(r))return r.length===0;if(typeof r==="object")return Object.keys(r).length===0;return!1},isTruthy:(e)=>{return!!(e.args?.[0]??e.value)},isFalsy:(e)=>{return!(e.args?.[0]??e.value)},inRange:(e)=>{let r=e.args?.[0],t=e.args?.[1],n=e.args?.[2];return r>=t&&r<=n},matches:(e)=>{let r=e.args?.[0],t=e.args?.[1];return new RegExp(t).test(r)},includes:(e)=>{let r=e.args?.[0],t=e.args?.[1];if(typeof r==="string")return r.includes(String(t));return Array.isArray(r)&&r.includes(t)},startsWith:(e)=>{let r=e.args?.[0],t=e.args?.[1];return r.startsWith(t)},endsWith:(e)=>{let r=e.args?.[0],t=e.args?.[1];return r.endsWith(t)}});var Qe=(e)=>e.keys(cr(e)).keys(mr(e)).keys(vr()).keys(Mr()).keys(Er()).keys(Or()).keys(Ar()).keys(kr(e)).keys(Dr(e)).keys(Fr()).keys(Rr()).keys($r()).sources(Wr(e)).sources(Nr()).sources(Lr()).sources(Jr()).sources(_r()).sources(Ir()).sources(Ur()).sources(Br()).sources(Tr()).sources(Yr(e)).sources(Qr()).sources(Gr()).sources(Kr()).sources(Xr()).sources(Vr()).sources(Hr()).sources(xr()).fieldOptions({onSection:(r)=>{if(r.section.config.name)e.section(r.section)}});var Pr={};R(Pr,{IncludeManager:()=>Me,DocumentIncludeProcessor:()=>Oe});import ve from"path";class Me{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,r,t){let n=[];for(let o of e)if(U.isGlobPattern(o)){let s=new Bun.Glob(o);for await(let i of s.scan({cwd:r,absolute:!0}))if(!t.included.includes(i))n.push(i)}else if(U.isDirectoryPattern(o)){let s=ve.isAbsolute(o)?o:ve.join(r,o);if(!this.includeDirectories.includes(s))this.includeDirectories.push(s)}else n.push(o);return n}buildSearchDirs(e){let r=e?[e]:[];return r.push(...this.includeDirectories.map((t)=>ve.isAbsolute(t)?t:ve.join(e??process.cwd(),t))),r}}class Oe{includeManager;loadFn;constructor(e,r){this.includeManager=e;this.loadFn=r}async processIncludes(e,r,t){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,t);for(let s of o)N(await this.loadFn(s,e.folderPath,{parent:e.content,...r},!0,t),e.content)}}var A={};R(A,{writeOutputs:()=>z,writeOutput:()=>fe,writeFormat:()=>pe,tokenize:()=>Ye,toObjectWithKey:()=>Ne,toObject:()=>ee,toList:()=>I,stripIndent:()=>Je,sortBy:()=>_e,snake:()=>Q,select:()=>O,processFields:()=>D,pascal:()=>J,padBlock:()=>C,nonNullMap:()=>Ce,navigate:()=>ge,mergeAll:()=>T,merge:()=>N,makeFieldProcessorMap:()=>F,makeFieldProcessorList:()=>Fe,makeFieldProcessor:()=>q,locate:()=>_,loadFormat:()=>P,importList:()=>ce,importGlob:()=>je,globMap:()=>Z,getProcessor:()=>x,getArgs:()=>ue,find:()=>Be,exists:()=>B,defined:()=>Le,deepClone:()=>$,conditionPredicates:()=>j,changeCase:()=>G,capital:()=>ne,camel:()=>oe,asyncMap:()=>Ie,NavigateResult:()=>b,NavigateAction:()=>me,Logger:()=>Ke});S(A,it(rt(),1));class Ke{options;constructor(e){this.options={level:"INFO",showClass:!1,levels:["DEBUG","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:(r,...t)=>{switch(r){case"ERROR":console.error(...t);break;case"WARN":console.warn(...t);break;case"DEBUG":console.debug(...t);break;default:console.log(...t)}},...e}}write(e,...r){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 t=[],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)t.push(`[${n.join(" ")}]`);t.push(...r),this.options.logFunction(e,...t)}info(...e){this.write("INFO",...e)}error(...e){this.write("ERROR",...e)}warn(...e){this.write("WARN",...e)}debug(...e){this.write("DEBUG",...e)}}S(W,A);class tt{includeManager=new Me;includeProcessor;cacheManager=new ye(100);outputs=[];vars={};fields={sources:{},keys:{},sections:{}};objectMetadata={};currentContext=null;storedSections={};constructor(){this.includeProcessor=new Oe(this.includeManager,this.load.bind(this)),this.use(Qe)}use(e){return e(this),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}getOutputs(){return this.outputs}output(e){return this.outputs.push(e),this}metadata(e,r){return this.objectMetadata[e]=r,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]}filter(e){return this.fields.filters??=[],this.fields.filters.push(e),this}async loadObject(e,r,t){return await D(e,{...this.fields,globalContext:{file:t?.fullPath??"@internal"},root:{...r,...this.fields.root,...this.vars,context:this.currentContext,sections:this.storedSections,$document:{root:{content:e},fileName:t?.fileName??"@internal",folder:t?.folderPath??"@internal",fullPath:t?.fullPath??"@internal"}}}),e}async load(e,r,t,n,o){let s=this.includeManager.snapshot();try{this.includeManager.reset();let i=this.includeManager.buildSearchDirs(r);if(o)this.currentContext=o;this.currentContext??={included:[],document:null};let a=await P(e,{dirs:i}),u=U.normalize(a.fullPath);if(this.currentContext.included.push(u),!a.content)return null;let m=this.cacheManager.get(u),d;if(m)d=m.raw;else d=a.content,this.cacheManager.set(u,{raw:d,timestamp:Date.now()});let g=$(d);a.content=g,await this.includeProcessor.processIncludes(a,t,this.currentContext);let l;if(n!==!0)l=await this.loadObject(a.content,t,{fileName:a.fullPath,folderPath:a.folderPath,fullPath:a.fullPath});else l=a.content;return this.currentContext.document=l,l}catch(i){throw this.includeManager.restore(s),i}finally{this.includeManager.restore(s)}}async writeAll(e){await z(this.getOutputs(),e)}}export{z as writeOutputs,fe as writeOutput,pe as writeFormat,Ye as tokenize,Ne as toObjectWithKey,ee as toObject,I as toList,Je as stripIndent,_e as sortBy,Q as snake,O as select,D as processFields,J as pascal,C as padBlock,Ce as nonNullMap,ge as navigate,T as mergeAll,N as merge,F as makeFieldProcessorMap,Fe as makeFieldProcessorList,q as makeFieldProcessor,_ as locate,P as loadFormat,ce as importList,je as importGlob,Z as globMap,x as getProcessor,ue as getArgs,Be as find,B as exists,Le as defined,$ as deepClone,j as conditionPredicates,G as changeCase,ne as capital,oe as camel,Ie as asyncMap,tt as Objector,b as NavigateResult,me as NavigateAction,Ke as Logger};
19
+ `).replaceAll("\\$","$").replaceAll("\\t","\t")};var Ur=()=>({...D({merge:(...e)=>e.flatMap((r)=>r)}),join:({args:[e],root:r,tags:t})=>{let n=t.key?.[0],o=t.separator?.[0]??t.sep?.[0],s=t.finalize?.length>0,i=se(o);if(typeof e==="string"){if(s&&e.length&&i)return e+i;return e}if(!Array.isArray(e))throw Error("Object is not a list");let a=((n?.length)?e.map((g)=>O({...r,...g},n)):e).join(i),l=t.pad?.[0]??"0",m=t.padChar?.[0]??" ",y=s&&a.length&&i?a+i:a;return l?C(y,parseInt(l),`
20
+ `,m):y},list:({args:e})=>_(e[0],e[1]),object:({args:e})=>ee(e[0],e[1]),range:({args:[e,r,t]})=>{let n=parseInt(e),o=parseInt(r),s=parseInt(t)||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(r)+"' 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},(i,a)=>n+a*s)},filter:{types:(e,r,t)=>{switch(e){case 0:return"array";case 1:return Object.keys(j)}return re[t[1].value]?.(e-2,r,t.slice(2))},fn:({args:[e,r,t],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],i=j[r];if(s){let l=Array(e.length);for(let y=0;y<e.length;y++)try{l[y]=O({...n,...e[y]},s)}catch{l[y]=Symbol("invalid")}let m=[];for(let y=0;y<e.length;y++){let g=l[y];if(typeof g!=="symbol"&&t===void 0?i(g):i(g,t))m.push(e[y])}return m}let a=[];for(let l of e)if(t===void 0?i(l):i(l,t))a.push(l);return a}}});var Ir=()=>({each:{processArgs:!1,fn:async({rawArgs:[e,r,...t],root:n,options:o,tags:s})=>{let i=async(f)=>f.quoted?se(f.value):await O(n,f.value),a=await O(n,e.value),l=await i(r),m=s.key?.[0],y=Array.isArray(a)?a:_(a),g=[],u=await Promise.all(t.map(async(f)=>await i(f))),c={...n,item:void 0,index:0,params:u,instance:void 0,parent:n.this,tags:s},h={...o,root:c};for(let f=0;f<y.length;f++){let w=R(l),p={instance:w},v=typeof l==="string"?p:w;if(c.item=y[f],c.index=f,c.instance=w,s?.root?.[0])Object.assign(c,await O(c,s.root[0]));if(await F(v,h),m!==void 0)g.push(await O(p.instance,m));else g.push(p.instance)}if(s.join?.length){if(g.length===0)return"";let f=se(s.join[0]),w=s.pad?.[0]??"0",p=s.padChar?.[0]??" ",v=s.finalize?.length&&f?f:"",d=`${g.join(f)}${v}`;return w?C(d,parseInt(w),`
21
+ `,p):d}return g}}});var ae=async(e,r,t)=>e.rawArgs[r].quoted?e.rawArgs[r].value:await O(e.root,e.rawArgs[r].value,{defaultValue:t}),_r=()=>({switch:{processArgs:!1,fn:async(e)=>{let r=await ae(e,0,!1),t=await ae(e,1);if(t[r]===void 0){if(e.rawArgs.length>2)return ae(e,2);throw Error(`Unhandled switch case: ${r}`)}return t[r]}}});var Tr=()=>D({log:console.log});var Yr=()=>({if:{types:{0:"boolean"},fn:(e)=>e.args[0]?e.args[1]:e.args[2]},check:{types:{0:Object.keys(j)},fn:(e)=>j[e.args[0]](...e.args.slice(1))},...D(j,{types:re})});var Br=(e)=>({default:{processArgs:!1,fn:async(r)=>{for(let t=0;t<r.rawArgs.length;t++)if(r.rawArgs[t]?.value!==void 0){let o=await ae(r,t,null);if(o!==null)return o}if(r.tags.nullable?.length)return b.DeleteItem();if(r.tags.fail?.length)throw Error(`No valid value found for default (${r.rawArgs.map((t)=>t.value).join(", ")})`);return""}},section:{types:["string","boolean"],fn:(r)=>{let t=r.args[0];if(!(r.args[1]??!0))return null;let o=e.getSection(t);if(!o)throw Error(`Section not found: ${t}`);return o.content}}});var Jr=()=>({convert:({args:[e,r,t]})=>{switch(r){case"string":return String(e);case"number":{let n=Number(e);if(!isNaN(n))return b.ReplaceItem(n);break}case"boolean":if(e==="true"||e===!0||e===1||e==="1"||e==="yes"||e==="on")return b.ReplaceItem(!0);else if(e==="false"||e===!1||e===0||e==="0"||e==="no"||e==="off")return b.ReplaceItem(!1);break;default:throw Error(`Unsupported type for convert: ${r}`)}if(t!==void 0)return b.ReplaceItem(t);throw Error(`Failed to convert value to ${r}`)},isType:({args:[e,r]})=>{let n=(()=>{switch(r){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: ${r}`)}})();return b.ReplaceItem(n)},typeOf:({args:[e]})=>{if(e===null)return"null";else if(Array.isArray(e))return"array";else return typeof e}});var Qr=()=>({...D({add:(...e)=>e.reduce((r,t)=>r+t,0),subtract:(e,r)=>e-r,multiply:(...e)=>e.reduce((r,t)=>r*t,1),divide:(e,r)=>{if(r===0)throw Error("Division by zero");return e/r},modulo:(e,r)=>e%r,power:(e,r)=>Math.pow(e,r),sqrt:(e)=>Math.sqrt(e),abs:(e)=>Math.abs(e),floor:(e)=>Math.floor(e),ceil:(e)=>Math.ceil(e),round:(e,r)=>{let t=Math.pow(10,r??0);return Math.round(e*t)/t},min:(...e)=>Math.min(...e),max:(...e)=>Math.max(...e),clamp:(e,r,t)=>Math.max(r,Math.min(t,e)),random:(e,r)=>{let t=e??0,n=r??1;return Math.random()*(n-t)+t}})});var Kr=()=>({now:()=>new Date,timestamp:(e)=>{let r=e.args?.[0];return(r?new Date(r):new Date).getTime()},iso:(e)=>{let r=e.args?.[0];return(r?new Date(r):new Date).toISOString()},utc:(e)=>{let r=e.args?.[0];return(r?new Date(r):new Date).toUTCString()},format:(e)=>{let r=e.args?.[0],t=e.args?.[1],n=new Date(r),o=n.getFullYear(),s=String(n.getMonth()+1).padStart(2,"0"),i=String(n.getDate()).padStart(2,"0"),a=String(n.getHours()).padStart(2,"0"),l=String(n.getMinutes()).padStart(2,"0"),m=String(n.getSeconds()).padStart(2,"0");return t.replace("YYYY",String(o)).replace("MM",s).replace("DD",i).replace("HH",a).replace("mm",l).replace("ss",m)},parse:(e)=>{let r=e.args?.[0];return new Date(r).getTime()},year:(e)=>{let r=e.args?.[0];return(r?new Date(r):new Date).getFullYear()},month:(e)=>{let r=e.args?.[0];return(r?new Date(r):new Date).getMonth()+1},day:(e)=>{let r=e.args?.[0];return(r?new Date(r):new Date).getDate()},dayOfWeek:(e)=>{let r=e.args?.[0];return(r?new Date(r):new Date).getDay()},hours:(e)=>{let r=e.args?.[0];return(r?new Date(r):new Date).getHours()},minutes:(e)=>{let r=e.args?.[0];return(r?new Date(r):new Date).getMinutes()},seconds:(e)=>{let r=e.args?.[0];return(r?new Date(r):new Date).getSeconds()}});var Gr=()=>{return{unique:(e)=>{let r=e.args?.[0]??e.value,t=e.args?.[1];if(!Array.isArray(r))return r;let n=new Set;return r.filter((o)=>{let s=typeof t==="function"?t(o):t?o[t]:o;if(n.has(s))return!1;return n.add(s),!0})},groupBy:(e)=>{let r=e.args?.[0]??e.value,t=e.args?.[1];if(!Array.isArray(r))return r;let n={};return r.forEach((o)=>{let s=typeof t==="function"?String(t(o)):String(o[t]);if(!n[s])n[s]=[];n[s].push(o)}),n},partition:(e)=>{let r=e.args?.[0]??e.value,t=e.args?.[1];if(!Array.isArray(r))return[[],[]];if(typeof t!=="function")return[r,[]];let n=[],o=[];return r.forEach((s)=>{(t(s)?n:o).push(s)}),[n,o]},chunk:(e)=>{let r=e.args?.[0]??e.value,t=e.args?.[1]??1;if(!Array.isArray(r))return[];let n=[];for(let o=0;o<r.length;o+=t)n.push(r.slice(o,o+t));return n},flatten:(e)=>{let r=e.args?.[0]??e.value,t=e.args?.[1]??1;if(!Array.isArray(r))return[r];let n=[],o=(s,i)=>{for(let a of s)if(Array.isArray(a)&&i>0)o(a,i-1);else n.push(a)};return o(r,t),n},compact:(e)=>{let r=e.args?.[0]??e.value;if(!Array.isArray(r))return r;return r.filter((t)=>t!==null&&t!==void 0)},head:(e)=>{let r=e.args?.[0]??e.value,t=e.args?.[1];if(!Array.isArray(r))return r;return t?r.slice(0,t):r[0]},tail:(e)=>{let r=e.args?.[0]??e.value,t=e.args?.[1];if(!Array.isArray(r))return r;return t?r.slice(-t):r[r.length-1]}}};import{createHash as ie}from"crypto";var xr=()=>({md5:(e)=>{let r=e.args?.[0]??e.value;return ie("md5").update(r).digest("hex")},sha1:(e)=>{let r=e.args?.[0]??e.value;return ie("sha1").update(r).digest("hex")},sha256:(e)=>{let r=e.args?.[0]??e.value;return ie("sha256").update(r).digest("hex")},sha512:(e)=>{let r=e.args?.[0]??e.value;return ie("sha512").update(r).digest("hex")},hash:(e)=>{let r=e.args?.[0]??e.value,t=e.args?.[1]??"sha256";return ie(t).update(r).digest("hex")},base64Encode:(e)=>{let r=e.args?.[0]??e.value,t=typeof r==="string"?r:JSON.stringify(r);return Buffer.from(t).toString("base64")},base64Decode:(e)=>{let r=e.args?.[0]??e.value;return Buffer.from(r,"base64").toString("utf-8")},hexEncode:(e)=>{let r=e.args?.[0]??e.value;return Buffer.from(r).toString("hex")},hexDecode:(e)=>{let r=e.args?.[0]??e.value;return Buffer.from(r,"hex").toString("utf-8")}});var Xr=()=>({test:(e)=>{let r=e.args?.[0],t=e.args?.[1],n=e.args?.[2];return new RegExp(r,n).test(t)},match:(e)=>{let r=e.args?.[0],t=e.args?.[1],n=e.args?.[2],o=new RegExp(r,n);return t.match(o)},matchAll:(e)=>{let r=e.args?.[0],t=e.args?.[1],n=e.args?.[2],o=new RegExp(r,n);return Array.from(t.matchAll(o))},replace:(e)=>{let r=e.args?.[0],t=e.args?.[1],n=e.args?.[2],o=e.args?.[3],s=new RegExp(r,o);return n.replace(s,t)},replaceAll:(e)=>{let r=e.args?.[0],t=e.args?.[1],n=e.args?.[2],o=e.args?.[3]??"g",s=new RegExp(r,o);return n.replace(s,t)},split:(e)=>{let r=e.args?.[0],t=e.args?.[1],n=e.args?.[2],o=new RegExp(r,n);return t.split(o)},exec:(e)=>{let r=e.args?.[0],t=e.args?.[1],n=e.args?.[2];return new RegExp(r,n).exec(t)},search:(e)=>{let r=e.args?.[0],t=e.args?.[1],n=e.args?.[2],o=new RegExp(r,n);return t.search(o)}});import{resolve as nn,dirname as on,basename as sn,normalize as an,join as ln}from"path";var Vr=()=>({...D({pathJoin:(...e)=>ln(...e),resolve:(...e)=>nn(...e),dirname:(e)=>on(e),basename:(e,r)=>sn(e,r),normalize:(e)=>an(e),extname:(e)=>{let r=/\.[^.]*$/.exec(e);return r?r[0]:""},relative:(e,r)=>{let t=e.split("/"),n=r.split("/"),o=0;while(o<t.length&&o<n.length&&t[o]===n[o])o++;let s=t.length-o,i=n.slice(o);return[...Array(s).fill("..")].concat(i).join("/")},isAbsolute:(e)=>e.startsWith("/"),segments:(e)=>e.split("/").filter(Boolean)})});var Hr=()=>({isEmail:(e)=>{let r=e.args?.[0]??e.value;return/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(r)},isUrl:(e)=>{let r=e.args?.[0]??e.value;try{return new URL(r),!0}catch{return!1}},isJson:(e)=>{let r=e.args?.[0]??e.value;try{return JSON.parse(r),!0}catch{return!1}},isUuid:(e)=>{let r=e.args?.[0]??e.value;return/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i.test(r)},minLength:(e)=>{let r=e.args?.[0]??e.value,t=e.args?.[1];return r?.length>=t},maxLength:(e)=>{let r=e.args?.[0]??e.value,t=e.args?.[1];return r?.length<=t},length:(e)=>{let r=e.args?.[0]??e.value,t=e.args?.[1];return r?.length===t},isNumber:(e)=>{let r=e.args?.[0]??e.value;return typeof r==="number"&&!isNaN(r)},isString:(e)=>{return typeof(e.args?.[0]??e.value)==="string"},isBoolean:(e)=>{return typeof(e.args?.[0]??e.value)==="boolean"},isArray:(e)=>{let r=e.args?.[0]??e.value;return Array.isArray(r)},isObject:(e)=>{let r=e.args?.[0]??e.value;return r!==null&&typeof r==="object"&&!Array.isArray(r)},isEmpty:(e)=>{let r=e.args?.[0]??e.value;if(r===null||r===void 0)return!0;if(typeof r==="string"||Array.isArray(r))return r.length===0;if(typeof r==="object")return Object.keys(r).length===0;return!1},isTruthy:(e)=>{return!!(e.args?.[0]??e.value)},isFalsy:(e)=>{return!(e.args?.[0]??e.value)},inRange:(e)=>{let r=e.args?.[0],t=e.args?.[1],n=e.args?.[2];return r>=t&&r<=n},matches:(e)=>{let r=e.args?.[0],t=e.args?.[1];return new RegExp(t).test(r)},includes:(e)=>{let r=e.args?.[0],t=e.args?.[1];if(typeof r==="string")return r.includes(String(t));return Array.isArray(r)&&r.includes(t)},startsWith:(e)=>{let r=e.args?.[0],t=e.args?.[1];return r.startsWith(t)},endsWith:(e)=>{let r=e.args?.[0],t=e.args?.[1];return r.endsWith(t)}});var Ge=(e)=>e.keys(cr(e)).keys(mr(e)).keys(vr()).keys(Mr()).keys(Ar()).keys(Or()).keys(Er()).keys(kr(e)).keys(Fr(e)).keys(Dr()).keys($r()).keys(Rr()).sources(Wr(e)).sources(Nr()).sources(Lr(e)).sources(Jr()).sources(Ur()).sources(Ir()).sources(_r()).sources(Tr()).sources(Yr()).sources(Br(e)).sources(Qr()).sources(Kr()).sources(Gr()).sources(xr()).sources(Xr()).sources(Vr()).sources(Hr()).fieldOptions({configParser:Bun.YAML.parse,onSection:(r)=>{if(r.section.config.name)e.section(r.section)}}).decoders({yaml:{matching:["\\.yml$","\\.yaml$"],fn:Bun.YAML.parse}}).encoders({json:{fn:(r)=>JSON.stringify(r,null,2)},yaml:{fn:(r)=>Bun.YAML.stringify(r,null,2)},terraform:{options:{includeTags:!0},fn:(r,t)=>ve(r,0,{sortKeys:!!(t?.sort?.length??t?.sortKeys?.length)})}});var Pr={};$(Pr,{IncludeManager:()=>Me,DocumentIncludeProcessor:()=>Oe});import un from"fs/promises";import le from"path";class Me{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,r,t){let n=[];for(let o of e)if(T.isGlobPattern(o)){let s=(await Array.fromAsync(un.glob(o,{cwd:r}))).map((i)=>le.join(r,i));for(let i of s)if(!t.included.includes(i))n.push(i)}else if(T.isDirectoryPattern(o)){let s=le.isAbsolute(o)?o:le.join(r,o);if(!this.includeDirectories.includes(s))this.includeDirectories.push(s)}else n.push(o);return n}buildSearchDirs(e){let r=e?[e]:[];return r.push(...this.includeDirectories.map((t)=>le.isAbsolute(t)?t:le.join(e??process.cwd(),t))),r}}class Oe{includeManager;loadFn;constructor(e,r){this.includeManager=e;this.loadFn=r}async processIncludes(e,r,t){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,t);for(let s of o)N(await this.loadFn(s,e.folderPath,{parent:e.content,...r},!0,t),e.content)}}var k={};$(k,{writeOutputs:()=>z,writeOutput:()=>ce,writeFormat:()=>fe,tokenize:()=>Qe,toObjectWithKey:()=>Le,toObject:()=>ee,toList:()=>_,stripIndent:()=>Ke,sortBy:()=>_e,snake:()=>K,select:()=>O,processFields:()=>F,pascal:()=>Q,padBlock:()=>C,nonNullMap:()=>Ue,navigate:()=>ye,mergeAll:()=>B,merge:()=>N,makeFieldProcessorMap:()=>D,makeFieldProcessorList:()=>De,makeFieldProcessor:()=>q,locate:()=>I,loadFormat:()=>P,importList:()=>me,importGlob:()=>Ne,globMap:()=>Z,getProcessor:()=>H,getArgs:()=>pe,find:()=>Be,exists:()=>Y,defined:()=>Ie,deepClone:()=>R,conditionPredicates:()=>j,changeCase:()=>G,capital:()=>ne,camel:()=>oe,asyncMap:()=>Te,NavigateResult:()=>b,NavigateAction:()=>ge,Logger:()=>Xe});S(k,it(rt(),1));class Xe{options;constructor(e){this.options={level:"INFO",showClass:!1,levels:["DEBUG","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:(r,...t)=>{switch(r){case"ERROR":console.error(...t);break;case"WARN":console.warn(...t);break;case"DEBUG":console.debug(...t);break;default:console.log(...t)}},...e}}write(e,...r){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 t=[],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)t.push(`[${n.join(" ")}]`);t.push(...r),this.options.logFunction(e,...t)}info(...e){this.write("INFO",...e)}error(...e){this.write("ERROR",...e)}warn(...e){this.write("WARN",...e)}debug(...e){this.write("DEBUG",...e)}}S(W,k);class tt{includeManager=new Me;includeProcessor;cacheManager=new de(100);outputs=[];vars={};fields={sources:{},keys:{},sections:{}};objectMetadata={};currentContext=null;storedSections={};dataEncoders={};dataDecoders={};constructor(){this.includeProcessor=new Oe(this.includeManager,this.load.bind(this)),this.use(Ge)}use(e){return e(this),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}getOutputs(){return this.outputs}output(e){return this.outputs.push(e),this}metadata(e,r){return this.objectMetadata[e]=r,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,r,t){return await F(e,{...this.fields,globalContext:{file:t?.fullPath??"@internal"},root:{...r,...this.fields.root,...this.vars,context:this.currentContext,sections:this.storedSections,$document:{root:{content:e},fileName:t?.fileName??"@internal",folder:t?.folderPath??"@internal",fullPath:t?.fullPath??"@internal"}}}),e}async load(e,r,t,n,o){let s=this.includeManager.snapshot();try{this.includeManager.reset();let i=this.includeManager.buildSearchDirs(r);if(o)this.currentContext=o;this.currentContext??={included:[],document:null};let a=await P(e,{dirs:i,parsers:this.dataDecoders,format:"yaml"}),l=T.normalize(a.fullPath);if(this.currentContext.included.push(l),!a.content)return null;let m=this.cacheManager.get(l),y;if(m)y=m.raw;else y=a.content,this.cacheManager.set(l,{raw:y,timestamp:Date.now()});let g=R(y);a.content=g,await this.includeProcessor.processIncludes(a,t,this.currentContext);let u;if(n!==!0)u=await this.loadObject(a.content,t,{fileName:a.fullPath,folderPath:a.folderPath,fullPath:a.fullPath});else u=a.content;return this.currentContext.document=u,u}catch(i){throw this.includeManager.restore(s),i}finally{this.includeManager.restore(s)}}async writeAll(e){await z(this.getOutputs(),e)}}export{z as writeOutputs,ce as writeOutput,fe as writeFormat,Qe as tokenize,Le as toObjectWithKey,ee as toObject,_ as toList,Ke as stripIndent,_e as sortBy,K as snake,O as select,F as processFields,Q as pascal,C as padBlock,Ue as nonNullMap,ye as navigate,B as mergeAll,N as merge,D as makeFieldProcessorMap,De as makeFieldProcessorList,q as makeFieldProcessor,I as locate,P as loadFormat,me as importList,Ne as importGlob,Z as globMap,H as getProcessor,pe as getArgs,Be as find,Y as exists,Ie as defined,R as deepClone,j as conditionPredicates,G as changeCase,ne as capital,oe as camel,Te as asyncMap,tt as Objector,b as NavigateResult,ge as NavigateAction,Xe as Logger};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@homedev/objector",
3
- "version": "1.2.50",
3
+ "version": "1.2.52",
4
4
  "description": "object extensions for YAML/JSON",
5
5
  "author": "julzor",
6
6
  "license": "ISC",