@homedev/objector 1.3.12 → 1.3.13

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
@@ -81,23 +81,23 @@ export declare interface CommandLineOption {
81
81
  */
82
82
  export declare const conditionPredicates: Record<string, (...args: any[]) => boolean>;
83
83
 
84
- export declare const decoder: (options?: DecoderOptions) => (_: any, ctx: ClassMethodDecoratorContext<ObjectorPlugin, (data: string) => unknown>) => void;
84
+ export declare const decoder: (options?: DecoratorDecoderOptions) => (_: any, ctx: ClassMethodDecoratorContext<ObjectorPlugin, (data: string) => unknown>) => void;
85
85
 
86
- declare type DecoderOptions = ObjectorDecoratorOptions;
86
+ declare type DecoratorDecoderOptions = ObjectorDecoratorOptions;
87
+
88
+ declare type DecoratorEncoderOptions = ObjectorDecoratorOptions;
87
89
 
88
90
  declare interface Encoder {
89
91
  fn: (data: unknown, ...args: any[]) => string | Promise<string>;
90
92
  options?: EncoderOptions;
91
93
  }
92
94
 
93
- export declare const encoder: (options?: EncoderOptions_2) => (_: any, ctx: ClassMethodDecoratorContext<ObjectorPlugin, (data: unknown) => string | Promise<string>>) => void;
95
+ export declare const encoder: (options?: DecoratorEncoderOptions) => (_: any, ctx: ClassMethodDecoratorContext<ObjectorPlugin, (data: unknown) => string | Promise<string>>) => void;
94
96
 
95
97
  declare interface EncoderOptions {
96
98
  includeTags?: boolean;
97
99
  }
98
100
 
99
- declare type EncoderOptions_2 = ObjectorDecoratorOptions;
100
-
101
101
  /**
102
102
  * Checks whether a file is readable.
103
103
  *
@@ -122,18 +122,7 @@ export declare interface FieldContext {
122
122
  parent?: any;
123
123
  }
124
124
 
125
- declare interface FieldContext_2 {
126
- path: string
127
- root: any
128
- options: ProcessFieldsOptions_2
129
- value: string | object | number | NavigateResult | null
130
- key: string
131
- args: any[]
132
- rawArgs: { value: string, quoted: boolean }[]
133
- tags: Record<string, string[]>
134
-
135
- parent?: any
136
- }
125
+ export declare type FieldContextModifier = (context: FieldContext, navContext: NavigateContext) => Promise<FieldContext | void> | FieldContext | void;
137
126
 
138
127
  export declare interface FieldProcessor {
139
128
  fn: FieldProcessorFunc;
@@ -142,24 +131,14 @@ export declare interface FieldProcessor {
142
131
 
143
132
  export declare type FieldProcessorFunc = (context: FieldContext) => any;
144
133
 
145
- declare type FieldProcessorFunc_2 = (context: FieldContext_2) => any
146
-
147
134
  export declare type FieldProcessorMap = Record<string, FieldProcessorTypedFunc>;
148
135
 
149
- declare type FieldProcessorMap_2 = Record<string, FieldProcessorTypedFunc_2>
150
-
151
136
  export declare interface FieldProcessorOptions {
152
137
  filters?: RegExp[];
153
138
  processArgs?: boolean;
154
139
  types?: Record<number, string | any[] | ((value: string, root: any, index: number, quoted: boolean) => any)> | FieldProcessorTypeChecker;
155
140
  }
156
141
 
157
- declare interface FieldProcessorOptions_2 {
158
- filters?: RegExp[]
159
- processArgs?: boolean
160
- types?: Record<number, string | any[] | ((value: string, root: any, index: number, quoted: boolean) => any)> | FieldProcessorTypeChecker_2
161
- }
162
-
163
142
  export declare interface FieldProcessorSection {
164
143
  config: Record<string, any>;
165
144
  content: string;
@@ -168,18 +147,8 @@ export declare interface FieldProcessorSection {
168
147
  show?: boolean;
169
148
  }
170
149
 
171
- declare interface FieldProcessorSection_2 {
172
- config: Record<string, any>
173
- content: string
174
- trim?: boolean
175
- indent?: number
176
- show?: boolean
177
- }
178
-
179
150
  export declare type FieldProcessorSectionConfigFunc = (context: FieldProcessorSectionContext) => Promise<boolean | void> | boolean | void;
180
151
 
181
- declare type FieldProcessorSectionConfigFunc_2 = (context: FieldProcessorSectionContext_2) => Promise<boolean | void> | boolean | void
182
-
183
152
  export declare interface FieldProcessorSectionContext {
184
153
  section: FieldProcessorSection;
185
154
  content: string;
@@ -188,34 +157,18 @@ export declare interface FieldProcessorSectionContext {
188
157
  options: ProcessFieldsOptions;
189
158
  }
190
159
 
191
- declare interface FieldProcessorSectionContext_2 {
192
- section: FieldProcessorSection_2
193
- content: string
194
- path: string
195
- root: Record<string, any>
196
- options: ProcessFieldsOptions_2
197
- }
198
-
199
160
  export declare type FieldProcessorSectionFunc = (context: FieldProcessorSectionContext) => Promise<void | boolean | string> | void | boolean | string;
200
161
 
201
- declare type FieldProcessorSectionFunc_2 = (context: FieldProcessorSectionContext_2) => Promise<void | boolean | string> | void | boolean | string
202
-
203
162
  export declare type FieldProcessorSectionMap = Record<string, FieldProcessorSectionFunc>;
204
163
 
205
- declare type FieldProcessorSectionMap_2 = Record<string, FieldProcessorSectionFunc_2>
206
-
207
164
  export declare type FieldProcessorTypeChecker = (n: number, value: any, args: any[]) => any;
208
165
 
209
- declare type FieldProcessorTypeChecker_2 = (n: number, value: any, args: any[]) => any
210
-
211
166
  export declare type FieldProcessorTypeCheckers<T = unknown> = Record<keyof T, FieldProcessorTypeChecker>;
212
167
 
213
168
  export declare type FieldProcessorTypedFunc = FieldProcessorFunc | (FieldProcessorOptions & {
214
169
  fn: FieldProcessorFunc;
215
170
  });
216
171
 
217
- declare type FieldProcessorTypedFunc_2 = FieldProcessorFunc_2 | (FieldProcessorOptions_2 & { fn: FieldProcessorFunc_2 })
218
-
219
172
  /**
220
173
  * @public
221
174
  */
@@ -578,12 +531,12 @@ export declare class Objector {
578
531
  includeDirectory(...dirs: string[]): this;
579
532
  getIncludeDirectories(): string[];
580
533
  include(...files: string[]): this;
581
- keys(keys: FieldProcessorMap_2): this;
582
- sources(sources: FieldProcessorMap_2): this;
583
- sections(sections: Record<string, FieldProcessorSectionFunc_2>): this;
534
+ keys(keys: FieldProcessorMap): this;
535
+ sources(sources: FieldProcessorMap): this;
536
+ sections(sections: Record<string, FieldProcessorSectionFunc>): this;
584
537
  variables(vars: Record<string, any>): this;
585
538
  functions(funcs: Record<string, AsyncFunction | Function>): this;
586
- onCreateContext(fn: ProcessFieldsOptions_2['onCreateContext']): this;
539
+ onCreateContext(fn: FieldContextModifier): this;
587
540
  getFunctions(): Record<string, AsyncFunction | Function>;
588
541
  getOutputs(): Output[];
589
542
  output(o: Output): this;
@@ -594,9 +547,9 @@ export declare class Objector {
594
547
  clearCache(): this;
595
548
  getCurrentContext(): LoadContext | null;
596
549
  getDocument<T>(): T | null;
597
- fieldOptions(options: ProcessFieldsOptions_2): this;
598
- section(section: FieldProcessorSection_2): this;
599
- getSection(name: string): FieldProcessorSection_2 | undefined;
550
+ fieldOptions(options: ProcessFieldsOptions): this;
551
+ section(section: FieldProcessorSection): this;
552
+ getSection(name: string): FieldProcessorSection | undefined;
600
553
  encoders(encoders: Record<string, Encoder>): this;
601
554
  decoders(decoders: Record<string, LoadFormatParser>): this;
602
555
  getEncoder(name: string): Encoder | undefined;
@@ -663,20 +616,7 @@ export declare interface ProcessFieldsOptions {
663
616
  onSection?: FieldProcessorSectionFunc;
664
617
  onSectionConfig?: FieldProcessorSectionConfigFunc;
665
618
  configParser?: (configText: string) => any;
666
- onCreateContext?: (context: FieldContext, navContext: NavigateContext) => Promise<FieldContext | undefined> | FieldContext | undefined;
667
- }
668
-
669
- declare interface ProcessFieldsOptions_2 {
670
- sources?: FieldProcessorMap_2
671
- keys?: FieldProcessorMap_2
672
- sections?: FieldProcessorSectionMap_2
673
- filters?: RegExp[]
674
- root?: Record<any, any>
675
- globalContext?: any
676
- onSection?: FieldProcessorSectionFunc_2
677
- onSectionConfig?: FieldProcessorSectionConfigFunc_2
678
- configParser?: (configText: string) => any
679
- onCreateContext?: (context: FieldContext_2, navContext: NavigateContext) => Promise<FieldContext_2 | undefined> | FieldContext_2 | undefined
619
+ onCreateContext?: FieldContextModifier;
680
620
  }
681
621
 
682
622
  export declare const section: (options?: SectionOptions) => (_: any, ctx: ClassMethodDecoratorContext<ObjectorPlugin, (section: FieldProcessorSection) => any>) => void;
package/dist/index.js CHANGED
@@ -1,4 +1,4 @@
1
- var Ht=Object.create;var Dr=Object.defineProperty;var Gt=Object.getOwnPropertyDescriptor;var Mr=(r,e)=>{return Object.defineProperty(r,"name",{value:e,enumerable:!1,configurable:!0}),r};var kr=(r,e)=>(e=Symbol[r])?e:Symbol.for("Symbol."+r),z=(r)=>{throw TypeError(r)},Jt=(r,e,t)=>(e in r)?Dr(r,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):r[e]=t;var pr=(r,e,t)=>e.has(r)||z("Cannot "+t),Zt=(r,e)=>Object(e)!==e?z('Cannot use the "in" operator on this value'):r.has(e),$r=(r,e,t)=>(pr(r,e,"read from private field"),t?t.call(r):e.get(r));var Pr=(r,e,t,n)=>(pr(r,e,"write to private field"),n?n.call(r,t):e.set(r,t),t),Qt=(r,e,t)=>(pr(r,e,"access private method"),t),Cr=(r)=>[,,,Ht(r?.[kr("metadata")]??null)],Lr=["class","method","getter","setter","accessor","field","value","get","set"],Y=(r)=>r!==void 0&&typeof r!=="function"?z("Function expected"):r,xt=(r,e,t,n,i)=>({kind:Lr[r],name:e,metadata:n,addInitializer:(s)=>t._?z("Already initialized"):i.push(Y(s||null))}),gr=(r,e)=>Jt(e,kr("metadata"),r[3]),Rr=(r,e,t,n)=>{for(var i=0,s=r[e>>1],u=s&&s.length;i<u;i++)e&1?s[i].call(t):n=s[i].call(t,n);return n},f=(r,e,t,n,i,s)=>{var u,a,l,g,d,p=e&7,O=!!(e&8),b=!!(e&16),P=p>3?r.length+1:p?O?1:2:0,w=Lr[p+5],j=p>3&&(r[P-1]=[]),D=r[P]||(r[P]=[]),A=p&&(!b&&!O&&(i=i.prototype),p<5&&(p>3||!b)&&Gt(p<4?i:{get[t](){return $r(this,s)},set[t](F){Pr(this,s,F)}},t));p?b&&p<4&&Mr(s,(p>2?"set ":p>1?"get ":"")+t):Mr(i,t);for(var E=n.length-1;E>=0;E--){if(g=xt(p,t,l={},r[3],D),p){if(g.static=O,g.private=b,d=g.access={has:b?(F)=>Zt(i,F):(F)=>(t in F)},p^3)d.get=b?(F)=>(p^1?$r:Qt)(F,i,p^4?s:A.get):(F)=>F[t];if(p>2)d.set=b?(F,M)=>Pr(F,i,M,p^4?s:A.set):(F,M)=>F[t]=M}if(a=(0,n[E])(p?p<4?b?s:A[w]:p>4?void 0:{get:A.get,set:A.set}:i,g),l._=1,p^4||a===void 0)Y(a)&&(p>4?j.unshift(a):p?b?s=a:A[w]=a:i=a);else if(typeof a!=="object"||a===null)z("Object expected");else Y(u=a.get)&&(A.get=u),Y(u=a.set)&&(A.set=u),Y(u=a.init)&&j.unshift(u)}return p||gr(r,i),A&&Dr(i,t,A),b?p^4?s:A:i};import Ir from"fs/promises";import hr from"path";import en from"fs/promises";import tn from"path";import on from"fs/promises";import un from"fs/promises";import Nr from"fs/promises";import Br from"path";import cn from"fs/promises";import dr from"path";import _r from"path";Array.prototype.findOrFail=function(r,e,t){let n=this.find(r,t);if(n===void 0)throw Error(e??"Element not found");return n};Array.flat=function(r){if(Array.isArray(r))return r.flat(2);else return[r]};Array.prototype.forEachAsync=async function(r){for(let e=0;e<this.length;e++)await r(this[e],e,this)};Array.prototype.groupBy=function(r){return this.reduce((e,t)=>{let n=r(t);if(!e[n])e[n]=[];return e[n].push(t),e},{})};Array.prototype.createInstances=function(r,...e){return this.map((t,n)=>new r(...e,t,n))};Array.prototype.mapAsync=async function(r){return Promise.all(this.map(r))};Array.prototype.nonNullMap=function(r){let e=[];for(let t=0;t<this.length;t++){let n=r(this[t],t,this);if(n!=null)e.push(n)}return e};Array.prototype.nonNullMapAsync=async function(r){let e=[];for(let t=0;t<this.length;t++){let n=await r(this[t],t,this);if(n!=null)e.push(n)}return e};Array.prototype.mergeAll=function(r){let e={};for(let t of this.slice().reverse())Object.merge(t,e,r);return e};Array.prototype.toObject=function(r,e){return Object.fromEntries(this.map((t)=>{let n=r(t),i=e?e(t):t;return[n,i]}))};Array.prototype.toObjectWithKey=function(r){return Object.fromEntries(this.map((e)=>[String(e[r]),e]))};Array.prototype.selectFor=function(r,e,t,n){let i=this.find(r,n);if(i===void 0)throw Error(t??"Element not found");return e(i)};Array.prototype.sortBy=function(r,e=!0){return this.slice().sort((t,n)=>{let i=r(t),s=r(n);if(i<s)return e?-1:1;if(i>s)return e?1:-1;return 0})};Array.prototype.unique=function(){return Array.from(new Set(this))};Array.prototype.uniqueBy=function(r){let e=new Set;return this.filter((t)=>{let n=r(t);if(e.has(n))return!1;else return e.add(n),!0})};var L;((r)=>{r[r.Explore=0]="Explore",r[r.SkipSiblings=1]="SkipSiblings",r[r.NoExplore=2]="NoExplore",r[r.ReplaceParent=3]="ReplaceParent",r[r.DeleteParent=4]="DeleteParent",r[r.MergeParent=5]="MergeParent",r[r.ReplaceItem=6]="ReplaceItem",r[r.DeleteItem=7]="DeleteItem"})(L||={});class y{action;by;skipSiblings;reexplore;constructor(r,e,t,n){this.action=r,this.by=e,this.skipSiblings=t,this.reexplore=n}static _explore=new y(0);static _noExplore=new y(2);static _skipSiblings=new y(1);static _deleteParent=new y(4);static ReplaceParent(r,e){return new y(3,r,void 0,e)}static SkipSiblings(){return y._skipSiblings}static Explore(){return y._explore}static NoExplore(){return y._noExplore}static DeleteParent(){return y._deleteParent}static MergeParent(r){return new y(5,r)}static ReplaceItem(r,e){return new y(6,r,e)}static DeleteItem(r){return new y(7,void 0,r)}}Object.navigate=async(r,e)=>{let t=new WeakSet,n=[],i=[],s=async(a,l,g)=>{let d=a===null,p=d?y.Explore():await e({key:a,value:l,path:n,parent:g,parents:i});if(l&&typeof l==="object"&&p.action===0){if(t.has(l))return p;if(t.add(l),!d)n.push(a),i.push(g);let O=l;while(await u(O,a,g))O=g[a];if(!d)i.pop(),n.pop()}return p},u=async(a,l,g)=>{let d=Object.keys(a),p=d.length;for(let O=0;O<p;O++){let b=d[O],P=a[b],w=await s(b,P,a),j=w.action;if(j===0||j===2)continue;if(j===6){if(a[b]=w.by,w.skipSiblings)return;continue}if(j===7){if(delete a[b],w.skipSiblings)return;continue}if(j===1)return;if(j===3){if(l===null)throw Error("Cannot replace root object");if(g[l]=w.by,w.reexplore)return!0;return}if(j===4){if(l===null)throw Error("Cannot delete root object");delete g[l];return}if(j===5)delete a[b],Object.assign(a,w.by)}};await s(null,r,null)};Object.find=async function(r,e){let t=[];return await Object.navigate(r,(n)=>{if(e([...n.path,n.key].join("."),n.value))t.push(n.value);return y.Explore()}),t};Object.merge=(r,e,t)=>{for(let n of Object.keys(e)){if(r[n]===void 0)continue;let i=e[n],s=r[n];if(typeof s!==typeof i||Array.isArray(s)!==Array.isArray(i)){let a=t?.mismatch?.(n,s,i,r,e);if(a!==void 0){e[n]=a;continue}throw Error(`Type mismatch: ${n}`)}let u=t?.mode?.(n,s,i,r,e)??e[".merge"]??"merge";switch(u){case"source":e[n]=s;continue;case"target":continue;case"skip":delete e[n],delete r[n];continue;case"merge":break;default:throw Error(`Unknown merge mode: ${u}`)}if(typeof s==="object")if(Array.isArray(s))i.push(...s);else{if(t?.navigate?.(n,s,i,r,e)===!1)continue;Object.merge(s,i,t)}else{if(s===i)continue;let a=t?.conflict?.(n,s,i,r,e);e[n]=a===void 0?i:a}}for(let n of Object.keys(r))if(e[n]===void 0)e[n]=r[n]};var Xt=/^\[([^=\]]*)([=]*)([^\]]*)\]$/,Ut=/^([^[\]]*)\[([^\]]*)]$/,yr=(r,e,t,n)=>{if(r.startsWith("{")&&r.endsWith("}")){let i=r.substring(1,r.length-1);return Object.select(e,i,t)?.toString()}return n?r:void 0},Tt=(r,e,t,n)=>{let i=yr(e,t,n);if(i)return Object.select(r,i,n);let s=Xt.exec(e);if(s){let[,a,l,g]=s,d=yr(a.trim(),t,n,!0),p=yr(g.trim(),t,n,!0);if(Array.isArray(r)&&(l==="="||l==="==")&&d)return r.find((O)=>O?.[d]==p)}let u=Ut.exec(e);if(u){let[,a,l]=u;return r?.[a]?.[l]}return r?.[e]};Object.select=(r,e,t)=>{let n=void 0,i=void 0,s=e??"",u=(p)=>{if(!p)return[p,!1];return p.endsWith("?")?[p.substring(0,p.length-1),!0]:[p,!1]},a=(p,O)=>{let[b,P]=u(O.pop());if(!b){if(t?.set!==void 0&&i!==void 0&&n!==void 0)n[i]=t.set;return p}let w=Tt(p,b,r,t);if(w===void 0){if(P||t?.optional||t?.defaultValue!==void 0)return;throw Error(`Unknown path element: "${b}" in "${s}"`)}return n=p,i=b,a(w,O)},l=s.splitNested(t?.separator??".","{","}"),g=void 0;if(l.length>0&&l[l.length-1].startsWith("?="))g=l.pop()?.substring(2);l.reverse();let d=a(r,l);if(d===void 0)return g??t?.defaultValue;return d};Object.deepClone=function(r){if(typeof structuredClone<"u")try{return structuredClone(r)}catch{}return JSON.parse(JSON.stringify(r))};Object.toList=function(r,e){return Object.entries(r).map(([t,n])=>({[e]:t,...n}))};Object.mapEntries=function(r,e){let t=Object.entries(r).map(([n,i])=>e(n,i));return Object.fromEntries(t)};global.AsyncFunction=Object.getPrototypeOf(async function(){}).constructor;global.defined=(r,e="Value is undefined")=>{if(r===void 0||r===null)throw Error(e);return r};String.prototype.tokenize=function(r,e=/\${([^}]+)}/g){return this.replace(e,(t,n)=>{let i=r[n];if(i===null||i===void 0)return"";if(typeof i==="string")return i;if(typeof i==="number"||typeof i==="boolean")return String(i);return String(i)})};String.prototype.toPascal=function(){return this.replace(/((?:[_ ]+)\w|^\w)/g,(r,e)=>e.toUpperCase()).replace(/[^a-zA-Z0-9 ]/g,"").replace(/[_ ]/g,"")};String.prototype.capitalize=function(){return this.replace(/((?:[ ]+)\w|^\w)/g,(r,e)=>e.toUpperCase())};String.prototype.toCamel=function(){return this.toPascal().replace(/((?:[ ]+\w)|^\w)/g,(r,e)=>e.toLowerCase())};String.prototype.toSnake=function(){return this.replace(/([a-z])([A-Z])/g,"$1_$2").replace(/\s+/g,"_")};String.prototype.toKebab=function(){return this.replace(/([a-z])([A-Z])/g,"$1-$2").replace(/\s+/g,"-")};String.prototype.changeCase=function(r){switch(r){case"upper":return this.toUpperCase();case"lower":return this.toLowerCase();case"pascal":return this.toPascal();case"camel":return this.toCamel();case"snake":return this.toSnake();case"kebab":return this.toKebab();default:throw Error(`Unsupported case type: ${r}`)}};String.prototype.splitWithQuotes=function(r=","){let e=[],t=this.length,n=r.length,i=0,s=(u)=>{if(u+n>t)return!1;for(let a=0;a<n;a++)if(this[u+a]!==r[a])return!1;return!0};while(i<t){while(i<t&&this[i]===" ")i++;if(i>=t)break;let u="",a=this[i]==='"'||this[i]==="'";if(a){let l=this[i++];while(i<t&&this[i]!==l)u+=this[i++];if(i<t)i++}else{while(i<t&&!s(i)){let l=this[i];if(l==='"'||l==="'"){u+=l,i++;while(i<t&&this[i]!==l)u+=this[i++];if(i<t)u+=this[i++]}else u+=this[i++]}u=u.trim()}if(u)e.push({value:u,quoted:a});if(s(i))i+=n}return e};String.prototype.splitNested=function(r,e,t){let n=0,i="",s=[];for(let u of this){if(i+=u,u===e)n++;if(u===t)n--;if(n===0&&u===r)s.push(i.slice(0,-1)),i=""}if(i)s.push(i);return s};String.prototype.toStringBuilder=function(){return new H(this.split(`
1
+ var Ht=Object.create;var Pr=Object.defineProperty;var Gt=Object.getOwnPropertyDescriptor;var Mr=(r,e)=>{return Object.defineProperty(r,"name",{value:e,enumerable:!1,configurable:!0}),r};var kr=(r,e)=>(e=Symbol[r])?e:Symbol.for("Symbol."+r),z=(r)=>{throw TypeError(r)},Jt=(r,e,t)=>(e in r)?Pr(r,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):r[e]=t;var pr=(r,e,t)=>e.has(r)||z("Cannot "+t),Zt=(r,e)=>Object(e)!==e?z('Cannot use the "in" operator on this value'):r.has(e),$r=(r,e,t)=>(pr(r,e,"read from private field"),t?t.call(r):e.get(r));var Dr=(r,e,t,n)=>(pr(r,e,"write to private field"),n?n.call(r,t):e.set(r,t),t),Qt=(r,e,t)=>(pr(r,e,"access private method"),t),Cr=(r)=>[,,,Ht(r?.[kr("metadata")]??null)],Lr=["class","method","getter","setter","accessor","field","value","get","set"],Y=(r)=>r!==void 0&&typeof r!=="function"?z("Function expected"):r,xt=(r,e,t,n,i)=>({kind:Lr[r],name:e,metadata:n,addInitializer:(s)=>t._?z("Already initialized"):i.push(Y(s||null))}),gr=(r,e)=>Jt(e,kr("metadata"),r[3]),Rr=(r,e,t,n)=>{for(var i=0,s=r[e>>1],u=s&&s.length;i<u;i++)e&1?s[i].call(t):n=s[i].call(t,n);return n},f=(r,e,t,n,i,s)=>{var u,a,l,g,d,p=e&7,O=!!(e&8),b=!!(e&16),D=p>3?r.length+1:p?O?1:2:0,w=Lr[p+5],j=p>3&&(r[D-1]=[]),P=r[D]||(r[D]=[]),A=p&&(!b&&!O&&(i=i.prototype),p<5&&(p>3||!b)&&Gt(p<4?i:{get[t](){return $r(this,s)},set[t](F){Dr(this,s,F)}},t));p?b&&p<4&&Mr(s,(p>2?"set ":p>1?"get ":"")+t):Mr(i,t);for(var E=n.length-1;E>=0;E--){if(g=xt(p,t,l={},r[3],P),p){if(g.static=O,g.private=b,d=g.access={has:b?(F)=>Zt(i,F):(F)=>(t in F)},p^3)d.get=b?(F)=>(p^1?$r:Qt)(F,i,p^4?s:A.get):(F)=>F[t];if(p>2)d.set=b?(F,M)=>Dr(F,i,M,p^4?s:A.set):(F,M)=>F[t]=M}if(a=(0,n[E])(p?p<4?b?s:A[w]:p>4?void 0:{get:A.get,set:A.set}:i,g),l._=1,p^4||a===void 0)Y(a)&&(p>4?j.unshift(a):p?b?s=a:A[w]=a:i=a);else if(typeof a!=="object"||a===null)z("Object expected");else Y(u=a.get)&&(A.get=u),Y(u=a.set)&&(A.set=u),Y(u=a.init)&&j.unshift(u)}return p||gr(r,i),A&&Pr(i,t,A),b?p^4?s:A:i};import Ir from"fs/promises";import hr from"path";import en from"fs/promises";import tn from"path";import on from"fs/promises";import un from"fs/promises";import Nr from"fs/promises";import Br from"path";import cn from"fs/promises";import dr from"path";import _r from"path";Array.prototype.findOrFail=function(r,e,t){let n=this.find(r,t);if(n===void 0)throw Error(e??"Element not found");return n};Array.flat=function(r){if(Array.isArray(r))return r.flat(2);else return[r]};Array.prototype.forEachAsync=async function(r){for(let e=0;e<this.length;e++)await r(this[e],e,this)};Array.prototype.groupBy=function(r){return this.reduce((e,t)=>{let n=r(t);if(!e[n])e[n]=[];return e[n].push(t),e},{})};Array.prototype.createInstances=function(r,...e){return this.map((t,n)=>new r(...e,t,n))};Array.prototype.mapAsync=async function(r){return Promise.all(this.map(r))};Array.prototype.nonNullMap=function(r){let e=[];for(let t=0;t<this.length;t++){let n=r(this[t],t,this);if(n!=null)e.push(n)}return e};Array.prototype.nonNullMapAsync=async function(r){let e=[];for(let t=0;t<this.length;t++){let n=await r(this[t],t,this);if(n!=null)e.push(n)}return e};Array.prototype.mergeAll=function(r){let e={};for(let t of this.slice().reverse())Object.merge(t,e,r);return e};Array.prototype.toObject=function(r,e){return Object.fromEntries(this.map((t)=>{let n=r(t),i=e?e(t):t;return[n,i]}))};Array.prototype.toObjectWithKey=function(r){return Object.fromEntries(this.map((e)=>[String(e[r]),e]))};Array.prototype.selectFor=function(r,e,t,n){let i=this.find(r,n);if(i===void 0)throw Error(t??"Element not found");return e(i)};Array.prototype.sortBy=function(r,e=!0){return this.slice().sort((t,n)=>{let i=r(t),s=r(n);if(i<s)return e?-1:1;if(i>s)return e?1:-1;return 0})};Array.prototype.unique=function(){return Array.from(new Set(this))};Array.prototype.uniqueBy=function(r){let e=new Set;return this.filter((t)=>{let n=r(t);if(e.has(n))return!1;else return e.add(n),!0})};var L;((r)=>{r[r.Explore=0]="Explore",r[r.SkipSiblings=1]="SkipSiblings",r[r.NoExplore=2]="NoExplore",r[r.ReplaceParent=3]="ReplaceParent",r[r.DeleteParent=4]="DeleteParent",r[r.MergeParent=5]="MergeParent",r[r.ReplaceItem=6]="ReplaceItem",r[r.DeleteItem=7]="DeleteItem"})(L||={});class y{action;by;skipSiblings;reexplore;constructor(r,e,t,n){this.action=r,this.by=e,this.skipSiblings=t,this.reexplore=n}static _explore=new y(0);static _noExplore=new y(2);static _skipSiblings=new y(1);static _deleteParent=new y(4);static ReplaceParent(r,e){return new y(3,r,void 0,e)}static SkipSiblings(){return y._skipSiblings}static Explore(){return y._explore}static NoExplore(){return y._noExplore}static DeleteParent(){return y._deleteParent}static MergeParent(r){return new y(5,r)}static ReplaceItem(r,e){return new y(6,r,e)}static DeleteItem(r){return new y(7,void 0,r)}}Object.navigate=async(r,e)=>{let t=new WeakSet,n=[],i=[],s=async(a,l,g)=>{let d=a===null,p=d?y.Explore():await e({key:a,value:l,path:n,parent:g,parents:i});if(l&&typeof l==="object"&&p.action===0){if(t.has(l))return p;if(t.add(l),!d)n.push(a),i.push(g);let O=l;while(await u(O,a,g))O=g[a];if(!d)i.pop(),n.pop()}return p},u=async(a,l,g)=>{let d=Object.keys(a),p=d.length;for(let O=0;O<p;O++){let b=d[O],D=a[b],w=await s(b,D,a),j=w.action;if(j===0||j===2)continue;if(j===6){if(a[b]=w.by,w.skipSiblings)return;continue}if(j===7){if(delete a[b],w.skipSiblings)return;continue}if(j===1)return;if(j===3){if(l===null)throw Error("Cannot replace root object");if(g[l]=w.by,w.reexplore)return!0;return}if(j===4){if(l===null)throw Error("Cannot delete root object");delete g[l];return}if(j===5)delete a[b],Object.assign(a,w.by)}};await s(null,r,null)};Object.find=async function(r,e){let t=[];return await Object.navigate(r,(n)=>{if(e([...n.path,n.key].join("."),n.value))t.push(n.value);return y.Explore()}),t};Object.merge=(r,e,t)=>{for(let n of Object.keys(e)){if(r[n]===void 0)continue;let i=e[n],s=r[n];if(typeof s!==typeof i||Array.isArray(s)!==Array.isArray(i)){let a=t?.mismatch?.(n,s,i,r,e);if(a!==void 0){e[n]=a;continue}throw Error(`Type mismatch: ${n}`)}let u=t?.mode?.(n,s,i,r,e)??e[".merge"]??"merge";switch(u){case"source":e[n]=s;continue;case"target":continue;case"skip":delete e[n],delete r[n];continue;case"merge":break;default:throw Error(`Unknown merge mode: ${u}`)}if(typeof s==="object")if(Array.isArray(s))i.push(...s);else{if(t?.navigate?.(n,s,i,r,e)===!1)continue;Object.merge(s,i,t)}else{if(s===i)continue;let a=t?.conflict?.(n,s,i,r,e);e[n]=a===void 0?i:a}}for(let n of Object.keys(r))if(e[n]===void 0)e[n]=r[n]};var Xt=/^\[([^=\]]*)([=]*)([^\]]*)\]$/,Ut=/^([^[\]]*)\[([^\]]*)]$/,yr=(r,e,t,n)=>{if(r.startsWith("{")&&r.endsWith("}")){let i=r.substring(1,r.length-1);return Object.select(e,i,t)?.toString()}return n?r:void 0},Tt=(r,e,t,n)=>{let i=yr(e,t,n);if(i)return Object.select(r,i,n);let s=Xt.exec(e);if(s){let[,a,l,g]=s,d=yr(a.trim(),t,n,!0),p=yr(g.trim(),t,n,!0);if(Array.isArray(r)&&(l==="="||l==="==")&&d)return r.find((O)=>O?.[d]==p)}let u=Ut.exec(e);if(u){let[,a,l]=u;return r?.[a]?.[l]}return r?.[e]};Object.select=(r,e,t)=>{let n=void 0,i=void 0,s=e??"",u=(p)=>{if(!p)return[p,!1];return p.endsWith("?")?[p.substring(0,p.length-1),!0]:[p,!1]},a=(p,O)=>{let[b,D]=u(O.pop());if(!b){if(t?.set!==void 0&&i!==void 0&&n!==void 0)n[i]=t.set;return p}let w=Tt(p,b,r,t);if(w===void 0){if(D||t?.optional||t?.defaultValue!==void 0)return;throw Error(`Unknown path element: "${b}" in "${s}"`)}return n=p,i=b,a(w,O)},l=s.splitNested(t?.separator??".","{","}"),g=void 0;if(l.length>0&&l[l.length-1].startsWith("?="))g=l.pop()?.substring(2);l.reverse();let d=a(r,l);if(d===void 0)return g??t?.defaultValue;return d};Object.deepClone=function(r){if(typeof structuredClone<"u")try{return structuredClone(r)}catch{}return JSON.parse(JSON.stringify(r))};Object.toList=function(r,e){return Object.entries(r).map(([t,n])=>({[e]:t,...n}))};Object.mapEntries=function(r,e){let t=Object.entries(r).map(([n,i])=>e(n,i));return Object.fromEntries(t)};global.AsyncFunction=Object.getPrototypeOf(async function(){}).constructor;global.defined=(r,e="Value is undefined")=>{if(r===void 0||r===null)throw Error(e);return r};String.prototype.tokenize=function(r,e=/\${([^}]+)}/g){return this.replace(e,(t,n)=>{let i=r[n];if(i===null||i===void 0)return"";if(typeof i==="string")return i;if(typeof i==="number"||typeof i==="boolean")return String(i);return String(i)})};String.prototype.toPascal=function(){return this.replace(/((?:[_ ]+)\w|^\w)/g,(r,e)=>e.toUpperCase()).replace(/[^a-zA-Z0-9 ]/g,"").replace(/[_ ]/g,"")};String.prototype.capitalize=function(){return this.replace(/((?:[ ]+)\w|^\w)/g,(r,e)=>e.toUpperCase())};String.prototype.toCamel=function(){return this.toPascal().replace(/((?:[ ]+\w)|^\w)/g,(r,e)=>e.toLowerCase())};String.prototype.toSnake=function(){return this.replace(/([a-z])([A-Z])/g,"$1_$2").replace(/\s+/g,"_")};String.prototype.toKebab=function(){return this.replace(/([a-z])([A-Z])/g,"$1-$2").replace(/\s+/g,"-")};String.prototype.changeCase=function(r){switch(r){case"upper":return this.toUpperCase();case"lower":return this.toLowerCase();case"pascal":return this.toPascal();case"camel":return this.toCamel();case"snake":return this.toSnake();case"kebab":return this.toKebab();default:throw Error(`Unsupported case type: ${r}`)}};String.prototype.splitWithQuotes=function(r=","){let e=[],t=this.length,n=r.length,i=0,s=(u)=>{if(u+n>t)return!1;for(let a=0;a<n;a++)if(this[u+a]!==r[a])return!1;return!0};while(i<t){while(i<t&&this[i]===" ")i++;if(i>=t)break;let u="",a=this[i]==='"'||this[i]==="'";if(a){let l=this[i++];while(i<t&&this[i]!==l)u+=this[i++];if(i<t)i++}else{while(i<t&&!s(i)){let l=this[i];if(l==='"'||l==="'"){u+=l,i++;while(i<t&&this[i]!==l)u+=this[i++];if(i<t)u+=this[i++]}else u+=this[i++]}u=u.trim()}if(u)e.push({value:u,quoted:a});if(s(i))i+=n}return e};String.prototype.splitNested=function(r,e,t){let n=0,i="",s=[];for(let u of this){if(i+=u,u===e)n++;if(u===t)n--;if(n===0&&u===r)s.push(i.slice(0,-1)),i=""}if(i)s.push(i);return s};String.prototype.toStringBuilder=function(){return new H(this.split(`
2
2
  `))};String.prototype.padBlock=function(r,e=`
3
3
  `,t=" "){let n=t.repeat(r);return this.split(e).map((i)=>n+i).join(e)};String.prototype.stripIndent=function(){let r=this.split(/\r?\n/),e=r.filter((n)=>n.trim().length>0).map((n)=>/^[ \t]*/.exec(n)?.[0].length??0),t=e.length>0?Math.min(...e):0;if(t===0)return this;return r.map((n)=>n.slice(t)).join(`
4
4
  `)};String.prototype.toHtmlLink=function(r){return`<a href="${r??this.toString()}">${this.toString()}</a>`};String.prototype.toRgb=function(){let r=this.toString().replace("#","");if(r.length!==6)throw Error("Invalid hex color");let e=parseInt(r.substring(0,2),16),t=parseInt(r.substring(2,4),16),n=parseInt(r.substring(4,6),16);return`rgb(${e.toString()}, ${t.toString()}, ${n.toString()})`};String.prototype.toArgb=function(){let r=this.toString().replace("#","");if(r.length!==8)throw Error("Invalid hex color");let e=parseInt(r.substring(0,2),16),t=parseInt(r.substring(2,4),16),n=parseInt(r.substring(4,6),16),i=parseInt(r.substring(6,8),16);return`argb(${e.toString()}, ${t.toString()}, ${n.toString()}, ${i.toString()})`};String.prototype.single=function(r){return this.replaceAll(new RegExp(`(${r})+`,"g"),"$1")};String.prototype.remove=function(r){return this.replaceAll(new RegExp(r,"g"),"")};String.prototype.toAlphanum=function(r=""){return this.replace(/[^a-z0-9]/gi,r)};String.prototype.toAlpha=function(r=""){return this.replace(/[^a-z]/gi,r)};class Vt{options;constructor(r){this.options={level:"INFO",showClass:!1,levels:["DEBUG","VERBOSE","INFO","WARN","ERROR"],timeStamp:!1,timeOptions:{second:"2-digit",minute:"2-digit",hour:"2-digit",day:"2-digit",month:"2-digit",year:"2-digit"},logFunction:(e,...t)=>{switch(e){case"ERROR":console.error(...t);break;case"WARN":console.warn(...t);break;case"DEBUG":console.debug(...t);break;case"VERBOSE":console.log(...t);break;default:console.log(...t)}},...r}}write(r,...e){if(this.options.level){let i=this.options.levels.indexOf(this.options.level),s=this.options.levels.indexOf(r);if(i===-1)throw Error(`Unknown configured log level: ${this.options.level}`);if(s===-1)throw Error(`Unknown log level: ${r}`);if(s<i)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(r);if(n.length>0)t.push(`[${n.join(" ")}]`);t.push(...e),this.options.logFunction(r,...t)}info(...r){this.write("INFO",...r)}error(...r){this.write("ERROR",...r)}warn(...r){this.write("WARN",...r)}debug(...r){this.write("DEBUG",...r)}verbose(...r){this.write("VERBOSE",...r)}}class H{#r=[];#e=0;options;constructor(r,e){if(r instanceof H)this.options={...r.options,...e},this.#r.push(...r.#r);else if(this.options=e??{},r)if(Array.isArray(r))this.#r.push(...r);else this.#r.push(r)}setOptions(r){return this.options=r,this}clear(){return this.#r.length=0,this}isEmpty(){return this.#r.length===0}toString(){return this.#r.join("")}indent(){return this.#e+=1,this}dedent(){if(this.#e>0)this.#e-=1;return this}getCurrentIndent(){return this.#e}getLines(){return this.toString().split(`
@@ -8,13 +8,13 @@ var Ht=Object.create;var Dr=Object.defineProperty;var Gt=Object.getOwnPropertyDe
8
8
  `)}writeMap(r,e){return r.forEach((t,n)=>e(t,n,this)),this}}class vt extends H{#r=0;#e="```";#t(r){return Math.min(6,Math.max(1,Math.floor(r)))}#n(r){if(r===void 0)return"```";let e=0;for(let t of r.matchAll(/`+/g))e=Math.max(e,t[0].length);return"`".repeat(Math.max(3,e+1))}header(r,e=1){let t=this.#t(e);return this.writeLine(`${"#".repeat(t)} ${r}`,"")}codeBlock(r,e){let t=this.#n(r);if(this.#e=t,e??="",this.writeLine(t+e),r!==void 0)this.writeLine(r).endCodeBlock();return this}endCodeBlock(){let r=this.#e;return this.#e="```",this.writeLine(r)}link(r,e,t){if(t)return this.write(`[${r}](${e} "${t}")`);return this.write(`[${r}](${e})`)}table(r,e){if(r.length===0)throw Error("Table requires at least one header");let t=r.map((s,u)=>{let a=s.length;return e.forEach((l)=>{if(l[u])a=Math.max(a,l[u].length)}),a}),n=r.map((s,u)=>s.padEnd(t[u]));this.writeLine("| "+n.join(" | ")+" |");let i=t.map((s)=>"-".repeat(s));return this.writeLine("| "+i.join(" | ")+" |"),e.forEach((s)=>{let u=r.map((a,l)=>(s[l]??"").padEnd(t[l]));this.writeLine("| "+u.join(" | ")+" |")}),this}blockquote(r){return r.split(`
9
9
  `).forEach((e)=>this.writeLine("> "+e)),this}bold(r){return this.write(`**${r}**`)}italic(r){return this.write(`*${r}*`)}item(r){return this.writeLine(`- ${r}`)}items(r){if(Array.isArray(r))r.forEach((e)=>this.item(e));else Object.entries(r).forEach(([e,t])=>t!==void 0&&this.item(`${e}: ${t!==void 0?String(t):""}`));return this}orderedList(r,e=1){return r.forEach((t,n)=>this.writeLine(`${(n+e).toString()}. ${t}`)),this}code(r){return this.write(`\`${r}\``)}horizontalRule(){return this.writeLine("---")}image(r,e){return this.writeLine(`![${r}](${e})`)}strikethrough(r){return this.write(`~~${r}~~`)}highlight(r){return this.write(`==${r}==`)}subscript(r){return this.write(`~${r}~`)}superscript(r){return this.write(`^${r}^`)}taskList(r){return r.forEach((e)=>this.writeLine(`- [${e.checked?"x":" "}] ${e.text}`)),this}section(r,e){if(e!==void 0)this.#r=this.#t(e);else this.#r=Math.min(6,this.#r+1);return this.header(r,this.#r)}endSection(){if(this.#r>0)this.#r--;return this}setSectionLevel(r){return this.#r=Math.min(6,Math.max(0,Math.floor(r))),this}}class rn{#r;#e;#t=new Map;#n=[];constructor(r,e=[]){this.#r=[...r],this.#e=[...e],this.#s()}get args(){return[...this.#r]}get positionals(){return[...this.#n]}has(r){return this.#t.has(this.#i(r))}getArgs(r){return[...this.#t.get(this.#i(r))?.values??[]]}get(r){let e=this.#t.get(this.#i(r))?.values;if(!e)return;if(e.length===0)return!0;return e[0]}toObject(){let r={};for(let[e,t]of this.#t.entries())r[e]=t.values.length>0?[...t.values]:!0;return r}usage(r="command"){let e=[`Usage: ${r} [options]`];if(this.#n.length>0)e[0]+=" [values]";if(this.#e.length===0)return e.join(`
10
10
  `);e.push("","Options:");for(let t of this.#e){let n=`--${t.name}`,i=t.alias?`-${t.alias}`:void 0,s=t.valueName??"value",u=t.takesValue?t.multiple?` <${s}...>`:` <${s}>`:"",a=i?`${i}, ${n}`:n,l=t.description?` ${t.description}`:"";e.push(` ${a}${u}${l}`)}return e.join(`
11
- `)}#s(){for(let r=0;r<this.#r.length;r++){let e=this.#r[r];if(!e.startsWith("-")||e==="-"){this.#n.push(e);continue}if(e.startsWith("--")&&e.includes("=")){let i=e.indexOf("="),s=this.#i(e.slice(0,i)),u=e.slice(i+1);this.#o(s,u.length>0?[u]:[""],!0);continue}let t=this.#i(e),n=[];while(r+1<this.#r.length){let i=this.#r[r+1];if(i.startsWith("-")&&i!=="-")break;n.push(i),r++}this.#o(t,n,!1)}}#o(r,e,t){let n=this.#t.get(r);if(!n){this.#t.set(r,{values:[...e],sawEqualsStyle:t});return}n.values.push(...e),n.sawEqualsStyle=n.sawEqualsStyle||t}#i(r){return r.replace(/^-+/,"").trim()}}var br=async(r)=>{try{return await Ir.access(r,Ir.constants.R_OK),!0}catch{return!1}},nr=async(r,e)=>{let t=!hr.isAbsolute(r)&&e?["",...e]:[""];for(let n of t){let i=hr.join(n,r);if(await br(i))return hr.resolve(i)}throw Error(`File not found: "${r}"`)},nn=(r,e)=>e?.some((t)=>new RegExp(t).test(r))===!0,Kr=async(r,e)=>{let t=await nr(r,e?.dirs),n=await en.readFile(t,"utf-8"),i=tn.dirname(t),s={text:{fn:(a)=>a,matching:["\\.txt$","\\.text$"]},json:{fn:JSON.parse,matching:["\\.json$"]},...e?.parsers},u=e?.format?s[e.format]:Object.values(s).find((a)=>nn(r,a.matching));if(!u)throw Error(`Unsupported format for file "${r}" and no matching parser found`);return{content:await u.fn(n),fullPath:t,folderPath:i}},sn=(r,e)=>e?.some((t)=>new RegExp(t).test(r))===!0,an=async(r,e,t)=>{let n={text:{fn:(s)=>s,matching:["\\.txt$","\\.text$"]},json:{fn:JSON.stringify,matching:["\\.json$"]},...t?.encoders},i=t?.format?n[t.format]:Object.values(n).find((s)=>sn(r,s.matching));if(!i)throw Error(`Unsupported format for file "${r}" and no matching encoder found`);await on.writeFile(r,await i.fn(e))},Wr=async(r,e)=>{if(typeof r==="string"&&!r.includes("*"))return await e.map(r,0,[]);let t=await Array.fromAsync(un.glob(r,{cwd:e.cwd})),n=e.filter?t.filter(e.filter):t;return await Promise.all(n.map(e.map))},qr=async(r,e)=>{if(e?.targetDirectory&&e?.removeFirst)try{await Nr.rm(e?.targetDirectory,{recursive:!0,force:!0})}catch(t){throw Error(`Failed to clean the output directory: ${t.message}`,{cause:t})}for(let t of r)await fn(t,e)},fn=async(r,e)=>{let t=Br.join(e?.targetDirectory??".",r.name),n=Br.dirname(t);if(e?.classes){if(r.class!==void 0&&!e.classes.includes(r.class))return;if(e.classRequired&&r.class===void 0)throw Error(`Output "${r.name}" is missing class field`)}if(e?.writing?.(r)===!1)return;try{await Nr.mkdir(n,{recursive:!0})}catch(i){throw Error(`Failed to create target directory "${n}" for output "${t}": ${i.message}`,{cause:i})}try{await an(t,r.value,{format:r.type??"text"})}catch(i){throw Error(`Failed to write output "${t}": ${i.message}`,{cause:i})}},Yr=(r)=>r?_r.isAbsolute(r)?r:_r.join(process.cwd(),r):process.cwd(),ln=async(r,e)=>{let t=[];for(let n of r)try{let i=!dr.isAbsolute(n)?dr.join(Yr(e?.cwd),n):n;if(e?.filter?.(i)===!1)continue;let s=await import(i);if(e?.resolveDefault==="only"&&!s.default)throw Error(`Module ${n} does not have a default export`);let u=e?.resolveDefault?s.default??s:s,a=e?.map?await e.map(u,n):u;if(a!==void 0)t.push(a)}catch(i){if(e?.fail?.(n,i)===!1)continue;throw Error(`Failed to import module ${n}: ${i.message??i}`,{cause:i})}return t},_n=async(r,e)=>{let t=[],n=Yr(e?.cwd);for(let i of r){let s=(await Array.fromAsync(cn.glob(i,{cwd:n}))).map((u)=>dr.join(n,u));t.push(...await ln(s,e))}return t};class G{o;context;constructor(r){this.o=r}}var c=(r)=>(e,t)=>{t.addInitializer(function(){let n=this[t.name],i=r?.name??t.name;this.o.sources({[i]:(s)=>n.apply({...this,context:s},s.args)})})},Wn=(r)=>(e,t)=>{t.addInitializer(function(){let n=this[t.name],i=r?.name??t.name;this.o.sections({[i]:(s)=>{return n.call({...this,context:s},s.section)}})})},Nn=(r)=>(e,t)=>{t.addInitializer(function(){let n=this[t.name],i=r?.name??t.name;this.o.keys({[i]:(s)=>n.call({...this,context:s},s.value)})})},qn=(r)=>(e,t)=>{t.addInitializer(function(){let n=this[t.name],i=r?.name??t.name;this.o.variables({[i]:n})})},Yn=(r)=>(e,t)=>{t.addInitializer(function(){let n=this[t.name],i=r?.name??t.name;this.o.functions({[i]:n})})},zn=(r)=>(e,t)=>{t.addInitializer(function(){let n=this[t.name],i=r?.name??t.name;this.o.encoders({[i]:{fn:n}})})},Hn=(r)=>(e,t)=>{t.addInitializer(function(){let n=this[t.name],i=r?.name??t.name;this.o.decoders({[i]:{fn:n}})})};import{createHash as W}from"crypto";import I from"path";var zr=(r)=>({output:(e)=>{delete e.parent[e.key];for(let t of Array.isArray(e.value)?e.value:[e.value])if(typeof t==="string")r.output({name:t,value:e.parent});else r.output({...t,value:t.value??e.parent});return y.SkipSiblings()}});import mn from"path";var Hr=(r)=>({load:async(e)=>{let t=e.options.globalContext;for(let{file:n}of Array.isArray(e.value)?e.value:[e.value]){if(!n)throw Error("File reference required");await r.load(n,t.file&&mn.dirname(t.file))}return y.DeleteItem()}});class wr{cache=new Map;maxSize;constructor(r=100){this.maxSize=r}get(r){return this.cache.get(r)}set(r,e){this.evictIfNeeded(),this.cache.set(r,e)}has(r){return this.cache.has(r)}clear(){this.cache.clear()}setMaxSize(r){this.maxSize=r}size(){return this.cache.size}evictIfNeeded(){if(this.cache.size>=this.maxSize){let r=null,e=1/0;for(let[t,n]of this.cache.entries())if(n.timestamp<e)e=n.timestamp,r=t;if(r)this.cache.delete(r)}}}var ir=(r)=>{let e=defined(r.value,"Model value cannot be null or undefined");if(typeof e==="string")return r.parent;let t=e.model;if(!t)return r.parent;if(typeof t==="string")return Object.select(r.root,t);return t};var or=(r)=>{let e=defined(r.value,"Source value cannot be null or undefined");if(typeof e==="string")return Object.select(r.root,e);if(Array.isArray(e))return e;let t=e;if(typeof t.from==="string")return Object.select(r.root,t.from);return t.from};var Gr=(r,e)=>{if(typeof r.value==="string"){if(r.quoted)return r.value;if(r.value.startsWith("[")&&r.value.endsWith("]")){let t=r.value.slice(1,-1);if(t.trim()==="")return[];return t.split(";").map((n)=>{let i=n.trim();if(!isNaN(+i))return+i;return i})}if(r.value.startsWith("{")&&r.value.endsWith("}")){if(r.value.slice(1,-1).trim()==="")return{}}if(r.value==="null")return null;if(r.value==="undefined")return;if(r.value.startsWith("@"))return r.value.slice(1);if(!isNaN(+r.value))return+r.value}return e(r.value)},sr=(r,e,t,n,i,s)=>{let u=n?.(r)??r,a=i(u);if(a[0])return a[1];if(!e){let l=Object.select(t,r),g=i(l);if(g[0])return g[1]}throw Error(s)},ar=(r,e,t,n,i)=>{let s=typeof r.types==="function"?r.types(n,e.value,i):r.types?.[n];if(!s||s==="ref")return Gr(e,(a)=>Object.select(t,a));let u=Gr(e,()=>e.value);if(Array.isArray(s)){if(!s.includes(u))throw Error(`Argument ${n.toString()} must be one of [${s.join(", ")}]: ${u}`);return u}if(typeof s==="string"){if(s.endsWith("?")){let a=s.slice(0,-1);if(e.value==="null")return y.ReplaceItem(null);if(e.value==="undefined")return y.ReplaceItem(void 0);if(e.value==="")return"";s=a}switch(s){case"any":return u;case"array":return sr(u,e.quoted,t,null,(a)=>[Array.isArray(a),a],`Argument ${n.toString()} must be an array: ${u}`);case"object":return sr(u,e.quoted,t,null,(a)=>[typeof a==="object"&&a!==null,a],`Argument ${n.toString()} must be an object: ${u}`);case"number":return sr(u,e.quoted,t,(a)=>Number(a),(a)=>[!isNaN(a),a],`Argument ${n.toString()} must be a number: ${u}`);case"boolean":return sr(u,e.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: ${u}`);case"string":return u.toString();default:throw Error(`Unknown type for argument ${n.toString()}: ${s}`)}}return s(u,t,n,e.quoted)};var ur=(r,e)=>{let t=r?.[e];if(t===void 0)throw Error(`Unhandled field processor type: ${e}`);return typeof t==="function"?{options:{},fn:t}:{options:t,fn:t.fn}},Jr=(r)=>!r.quoted&&r.value.startsWith("."),pn=(r)=>{let e={};for(let t of r){if(!Jr(t))continue;let n=t.value.indexOf("="),i=n>-1?t.value.slice(1,n):t.value.slice(1),s=n>-1?t.value.slice(n+1):"";if(s.length>=2){let u=s[0],a=s[s.length-1];if(u==='"'&&a==='"'||u==="'"&&a==="'")s=s.slice(1,-1)}if(!e[i])e[i]=[];e[i].push(s)}return e},Zr=(r,e,t)=>{let n=(r??"").splitWithQuotes(),i=pn(n),s=n.filter((a)=>!Jr(a)),u=e.options.processArgs===!1?[]:s.map((a,l)=>ar(e.options,a,t,l,s));return{rawArgs:s,parsedArgs:u,tags:i}};var gn=(r)=>{return r!==null&&typeof r==="object"&&"action"in r},Qr=(r,e)=>e.keys!==void 0&&r.key.startsWith(".")&&e.keys[r.key.substring(1)]!==void 0,xr=async(r,e,t,n)=>{let{key:i,parent:s}=r,u=ur(n.keys,i.substring(1));if(u.options.processArgs!==!1&&(typeof u.options.types==="function"||u.options.types?.[0]!==void 0))r.value=ar(u.options,{value:r.value,quoted:!1},t,0,[]);if(typeof r.value!=="string")await $(r.value,{...n,root:{...t,parent:r.parent,parents:r.parents},filters:[...n.filters??[],...u.options.filters??[]]});let a=await u.fn({path:e,root:t,parent:s,key:i,options:n,value:r.value,args:[],rawArgs:[],tags:{}});return gn(a)?a:y.ReplaceParent(a)};var Xr=async(r,e,t,n)=>{if(!e?.onSection&&!e?.onSectionConfig&&!e?.sections)return[r,!1];let i=/<@\s*section(?:\s*:\s*([\w-]+))?\s*@>([\s\S]*?)<@\s*\/\s*section\s*@>/g,s,u=r,a=0,l=!1,g={content:u,root:n,path:t,options:e,section:{}};while((s=i.exec(r))!==null){l=!0;let[d,p,O]=s,b=s.index,P=b+d.length,w=r[P]===`
12
- `;if(w)P++;let j=b+a,D=P+a,A={},E=O,F=/(^|\r?\n)[ \t]*---[ \t]*(\r?\n|$)/m.exec(O);if(F){let N=O.slice(0,F.index),mr=F.index+F[0].length;E=O.slice(mr);let rr=N.stripIndent().trim();if(rr.length>0)try{A=e?.configParser?.(rr)??{}}catch(er){throw Error(`Failed to parse YAML config for section: ${er.message}`,{cause:er})}}else if(/^\r?\n/.test(E))E=E.replace(/^\r?\n/,"");E=E.stripIndent().replace(/(?:\r?\n[ \t]*)+$/,"").replace(/[ \t]+$/,"");let M={config:p?{...A,type:p}:A,content:E};if(g.content=u,g.section=M,Object.keys(M.config).length>0){if(await e.onSectionConfig?.(g)!==!1)await $(M.config,{...e,root:n})}let U=g.section.config.type?e.sections?.[g.section.config.type]:void 0,B;if(U)B=await U(g);else if(e.onSection)B=await e.onSection(g);if(M.trim)M.content=M.content.trim();if(M.indent)M.content=M.content.split(`
11
+ `)}#s(){for(let r=0;r<this.#r.length;r++){let e=this.#r[r];if(!e.startsWith("-")||e==="-"){this.#n.push(e);continue}if(e.startsWith("--")&&e.includes("=")){let i=e.indexOf("="),s=this.#i(e.slice(0,i)),u=e.slice(i+1);this.#o(s,u.length>0?[u]:[""],!0);continue}let t=this.#i(e),n=[];while(r+1<this.#r.length){let i=this.#r[r+1];if(i.startsWith("-")&&i!=="-")break;n.push(i),r++}this.#o(t,n,!1)}}#o(r,e,t){let n=this.#t.get(r);if(!n){this.#t.set(r,{values:[...e],sawEqualsStyle:t});return}n.values.push(...e),n.sawEqualsStyle=n.sawEqualsStyle||t}#i(r){return r.replace(/^-+/,"").trim()}}var br=async(r)=>{try{return await Ir.access(r,Ir.constants.R_OK),!0}catch{return!1}},nr=async(r,e)=>{let t=!hr.isAbsolute(r)&&e?["",...e]:[""];for(let n of t){let i=hr.join(n,r);if(await br(i))return hr.resolve(i)}throw Error(`File not found: "${r}"`)},nn=(r,e)=>e?.some((t)=>new RegExp(t).test(r))===!0,Kr=async(r,e)=>{let t=await nr(r,e?.dirs),n=await en.readFile(t,"utf-8"),i=tn.dirname(t),s={text:{fn:(a)=>a,matching:["\\.txt$","\\.text$"]},json:{fn:JSON.parse,matching:["\\.json$"]},...e?.parsers},u=e?.format?s[e.format]:Object.values(s).find((a)=>nn(r,a.matching));if(!u)throw Error(`Unsupported format for file "${r}" and no matching parser found`);return{content:await u.fn(n),fullPath:t,folderPath:i}},sn=(r,e)=>e?.some((t)=>new RegExp(t).test(r))===!0,an=async(r,e,t)=>{let n={text:{fn:(s)=>s,matching:["\\.txt$","\\.text$"]},json:{fn:JSON.stringify,matching:["\\.json$"]},...t?.encoders},i=t?.format?n[t.format]:Object.values(n).find((s)=>sn(r,s.matching));if(!i)throw Error(`Unsupported format for file "${r}" and no matching encoder found`);await on.writeFile(r,await i.fn(e))},Wr=async(r,e)=>{if(typeof r==="string"&&!r.includes("*"))return await e.map(r,0,[]);let t=await Array.fromAsync(un.glob(r,{cwd:e.cwd})),n=e.filter?t.filter(e.filter):t;return await Promise.all(n.map(e.map))},qr=async(r,e)=>{if(e?.targetDirectory&&e?.removeFirst)try{await Nr.rm(e?.targetDirectory,{recursive:!0,force:!0})}catch(t){throw Error(`Failed to clean the output directory: ${t.message}`,{cause:t})}for(let t of r)await fn(t,e)},fn=async(r,e)=>{let t=Br.join(e?.targetDirectory??".",r.name),n=Br.dirname(t);if(e?.classes){if(r.class!==void 0&&!e.classes.includes(r.class))return;if(e.classRequired&&r.class===void 0)throw Error(`Output "${r.name}" is missing class field`)}if(e?.writing?.(r)===!1)return;try{await Nr.mkdir(n,{recursive:!0})}catch(i){throw Error(`Failed to create target directory "${n}" for output "${t}": ${i.message}`,{cause:i})}try{await an(t,r.value,{format:r.type??"text"})}catch(i){throw Error(`Failed to write output "${t}": ${i.message}`,{cause:i})}},Yr=(r)=>r?_r.isAbsolute(r)?r:_r.join(process.cwd(),r):process.cwd(),ln=async(r,e)=>{let t=[];for(let n of r)try{let i=!dr.isAbsolute(n)?dr.join(Yr(e?.cwd),n):n;if(e?.filter?.(i)===!1)continue;let s=await import(i);if(e?.resolveDefault==="only"&&!s.default)throw Error(`Module ${n} does not have a default export`);let u=e?.resolveDefault?s.default??s:s,a=e?.map?await e.map(u,n):u;if(a!==void 0)t.push(a)}catch(i){if(e?.fail?.(n,i)===!1)continue;throw Error(`Failed to import module ${n}: ${i.message??i}`,{cause:i})}return t},_n=async(r,e)=>{let t=[],n=Yr(e?.cwd);for(let i of r){let s=(await Array.fromAsync(cn.glob(i,{cwd:n}))).map((u)=>dr.join(n,u));t.push(...await ln(s,e))}return t};class G{o;context;constructor(r){this.o=r}}var c=(r)=>(e,t)=>{t.addInitializer(function(){let n=this[t.name],i=r?.name??t.name;this.o.sources({[i]:(s)=>n.apply({...this,context:s},s.args)})})},Wn=(r)=>(e,t)=>{t.addInitializer(function(){let n=this[t.name],i=r?.name??t.name;this.o.sections({[i]:(s)=>{return n.call({...this,context:s},s.section)}})})},Nn=(r)=>(e,t)=>{t.addInitializer(function(){let n=this[t.name],i=r?.name??t.name;this.o.keys({[i]:(s)=>n.call({...this,context:s},s.value)})})},qn=(r)=>(e,t)=>{t.addInitializer(function(){let n=this[t.name],i=r?.name??t.name;this.o.variables({[i]:n})})},Yn=(r)=>(e,t)=>{t.addInitializer(function(){let n=this[t.name],i=r?.name??t.name;this.o.functions({[i]:n})})},zn=(r)=>(e,t)=>{t.addInitializer(function(){let n=this[t.name],i=r?.name??t.name;this.o.encoders({[i]:{fn:n}})})},Hn=(r)=>(e,t)=>{t.addInitializer(function(){let n=this[t.name],i=r?.name??t.name;this.o.decoders({[i]:{fn:n}})})};import{createHash as W}from"crypto";import I from"path";var zr=(r)=>({output:(e)=>{delete e.parent[e.key];for(let t of Array.isArray(e.value)?e.value:[e.value])if(typeof t==="string")r.output({name:t,value:e.parent});else r.output({...t,value:t.value??e.parent});return y.SkipSiblings()}});import mn from"path";var Hr=(r)=>({load:async(e)=>{let t=e.options.globalContext;for(let{file:n}of Array.isArray(e.value)?e.value:[e.value]){if(!n)throw Error("File reference required");await r.load(n,t.file&&mn.dirname(t.file))}return y.DeleteItem()}});class wr{cache=new Map;maxSize;constructor(r=100){this.maxSize=r}get(r){return this.cache.get(r)}set(r,e){this.evictIfNeeded(),this.cache.set(r,e)}has(r){return this.cache.has(r)}clear(){this.cache.clear()}setMaxSize(r){this.maxSize=r}size(){return this.cache.size}evictIfNeeded(){if(this.cache.size>=this.maxSize){let r=null,e=1/0;for(let[t,n]of this.cache.entries())if(n.timestamp<e)e=n.timestamp,r=t;if(r)this.cache.delete(r)}}}var ir=(r)=>{let e=defined(r.value,"Model value cannot be null or undefined");if(typeof e==="string")return r.parent;let t=e.model;if(!t)return r.parent;if(typeof t==="string")return Object.select(r.root,t);return t};var or=(r)=>{let e=defined(r.value,"Source value cannot be null or undefined");if(typeof e==="string")return Object.select(r.root,e);if(Array.isArray(e))return e;let t=e;if(typeof t.from==="string")return Object.select(r.root,t.from);return t.from};var Gr=(r,e)=>{if(typeof r.value==="string"){if(r.quoted)return r.value;if(r.value.startsWith("[")&&r.value.endsWith("]")){let t=r.value.slice(1,-1);if(t.trim()==="")return[];return t.split(";").map((n)=>{let i=n.trim();if(!isNaN(+i))return+i;return i})}if(r.value.startsWith("{")&&r.value.endsWith("}")){if(r.value.slice(1,-1).trim()==="")return{}}if(r.value==="null")return null;if(r.value==="undefined")return;if(r.value.startsWith("@"))return r.value.slice(1);if(!isNaN(+r.value))return+r.value}return e(r.value)},sr=(r,e,t,n,i,s)=>{let u=n?.(r)??r,a=i(u);if(a[0])return a[1];if(!e){let l=Object.select(t,r),g=i(l);if(g[0])return g[1]}throw Error(s)},ar=(r,e,t,n,i)=>{let s=typeof r.types==="function"?r.types(n,e.value,i):r.types?.[n];if(!s||s==="ref")return Gr(e,(a)=>Object.select(t,a));let u=Gr(e,()=>e.value);if(Array.isArray(s)){if(!s.includes(u))throw Error(`Argument ${n.toString()} must be one of [${s.join(", ")}]: ${u}`);return u}if(typeof s==="string"){if(s.endsWith("?")){let a=s.slice(0,-1);if(e.value==="null")return y.ReplaceItem(null);if(e.value==="undefined")return y.ReplaceItem(void 0);if(e.value==="")return"";s=a}switch(s){case"any":return u;case"array":return sr(u,e.quoted,t,null,(a)=>[Array.isArray(a),a],`Argument ${n.toString()} must be an array: ${u}`);case"object":return sr(u,e.quoted,t,null,(a)=>[typeof a==="object"&&a!==null,a],`Argument ${n.toString()} must be an object: ${u}`);case"number":return sr(u,e.quoted,t,(a)=>Number(a),(a)=>[!isNaN(a),a],`Argument ${n.toString()} must be a number: ${u}`);case"boolean":return sr(u,e.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: ${u}`);case"string":return u.toString();default:throw Error(`Unknown type for argument ${n.toString()}: ${s}`)}}return s(u,t,n,e.quoted)};var ur=(r,e)=>{let t=r?.[e];if(t===void 0)throw Error(`Unhandled field processor type: ${e}`);return typeof t==="function"?{options:{},fn:t}:{options:t,fn:t.fn}},Jr=(r)=>!r.quoted&&r.value.startsWith("."),pn=(r)=>{let e={};for(let t of r){if(!Jr(t))continue;let n=t.value.indexOf("="),i=n>-1?t.value.slice(1,n):t.value.slice(1),s=n>-1?t.value.slice(n+1):"";if(s.length>=2){let u=s[0],a=s[s.length-1];if(u==='"'&&a==='"'||u==="'"&&a==="'")s=s.slice(1,-1)}if(!e[i])e[i]=[];e[i].push(s)}return e},Zr=(r,e,t)=>{let n=(r??"").splitWithQuotes(),i=pn(n),s=n.filter((a)=>!Jr(a)),u=e.options.processArgs===!1?[]:s.map((a,l)=>ar(e.options,a,t,l,s));return{rawArgs:s,parsedArgs:u,tags:i}};var gn=(r)=>{return r!==null&&typeof r==="object"&&"action"in r},Qr=(r,e)=>e.keys!==void 0&&r.key.startsWith(".")&&e.keys[r.key.substring(1)]!==void 0,xr=async(r,e,t,n)=>{let{key:i,parent:s}=r,u=ur(n.keys,i.substring(1));if(u.options.processArgs!==!1&&(typeof u.options.types==="function"||u.options.types?.[0]!==void 0))r.value=ar(u.options,{value:r.value,quoted:!1},t,0,[]);if(typeof r.value!=="string")await $(r.value,{...n,root:{...t,parent:r.parent,parents:r.parents},filters:[...n.filters??[],...u.options.filters??[]]});let a=await u.fn({path:e,root:t,parent:s,key:i,options:n,value:r.value,args:[],rawArgs:[],tags:{}});return gn(a)?a:y.ReplaceParent(a)};var Xr=async(r,e,t,n)=>{if(!e?.onSection&&!e?.onSectionConfig&&!e?.sections)return[r,!1];let i=/<@\s*section(?:\s*:\s*([\w-]+))?\s*@>([\s\S]*?)<@\s*\/\s*section\s*@>/g,s,u=r,a=0,l=!1,g={content:u,root:n,path:t,options:e,section:{}};while((s=i.exec(r))!==null){l=!0;let[d,p,O]=s,b=s.index,D=b+d.length,w=r[D]===`
12
+ `;if(w)D++;let j=b+a,P=D+a,A={},E=O,F=/(^|\r?\n)[ \t]*---[ \t]*(\r?\n|$)/m.exec(O);if(F){let N=O.slice(0,F.index),mr=F.index+F[0].length;E=O.slice(mr);let rr=N.stripIndent().trim();if(rr.length>0)try{A=e?.configParser?.(rr)??{}}catch(er){throw Error(`Failed to parse YAML config for section: ${er.message}`,{cause:er})}}else if(/^\r?\n/.test(E))E=E.replace(/^\r?\n/,"");E=E.stripIndent().replace(/(?:\r?\n[ \t]*)+$/,"").replace(/[ \t]+$/,"");let M={config:p?{...A,type:p}:A,content:E};if(g.content=u,g.section=M,Object.keys(M.config).length>0){if(await e.onSectionConfig?.(g)!==!1)await $(M.config,{...e,root:n})}let U=g.section.config.type?e.sections?.[g.section.config.type]:void 0,B;if(U)B=await U(g);else if(e.onSection)B=await e.onSection(g);if(M.trim)M.content=M.content.trim();if(M.indent)M.content=M.content.split(`
13
13
  `).map((N)=>" ".repeat(M.indent)+N).join(`
14
14
  `);let C="";if(B===!0||M.show)C=M.content;else if(typeof B==="string")C=B;if(w&&C!==""&&!C.endsWith(`
15
15
  `))C+=`
16
16
  `;let T=u.lastIndexOf(`
17
- `,j-1),V=T===-1?0:T+1,v=u.slice(V,j).trim().length===0?V:j;u=u.slice(0,v)+C+u.slice(D),a+=C.length-(D-v),g.content=u}return[u,l]};var Or=(r)=>{let e=[],t=0;while(t<r.length)if(r[t]==="$"&&r[t+1]==="("&&(t===0||r[t-1]!=="\\")){let n=t;t+=2;let i=1;for(;t<r.length;t++)if(r[t]==="(")i++;else if(r[t]===")"){if(i--,i===0){e.push([n,t]);break}}if(i!==0)throw Error(`Unmatched opening $( at position ${n.toString()}`);t++}else t++;return e};var Ur=(r)=>({value:r}),yn=(r)=>{return r!==null&&typeof r==="object"},Tr=async(r,e,t)=>{for(let n=e.length-1;n>=0;n--){let[i,s]=e[n],u=r.slice(i+2,s),a=await Tr(u,Or(u),t);if(typeof a==="object")return a;let l=await t(a,r);if(yn(l))return l.value;r=r.slice(0,i)+l+r.slice(s+1)}return r},Vr=async(r,e)=>Tr(r,Or(r),e);var hn=(r)=>{return r!==null&&typeof r==="object"&&"action"in r},dn=/([\w\d.-_/]+):(.+)/,bn=async(r,e,t,n)=>{let i=await(async()=>{let s=dn.exec(r);if(!s)return await Object.select(e,r);let[u,a,l]=s,g=ur(n.sources,a),d=Zr(l,g,e);return await g.fn({args:d.parsedArgs,rawArgs:d.rawArgs,tags:d.tags,key:a,options:n,root:e,path:t,value:null})})();if(i===null||i===void 0)return"";if(typeof i==="object")return Ur(i);return i},Ar=async(r,e,t,n)=>{let i=await Vr(e,(s)=>bn(s,t,r,n));if(hn(i))return i;if(i===e)return y.Explore();if(typeof i==="string"){let s=await Ar(r,i,t,n);if(s.action!==L.Explore)return s}return y.ReplaceItem(i)};var $=async(r,e)=>{return e??={},await Object.navigate(r,async(t)=>{let n=[...t.path,t.key].join(".");if(e?.filters?.length&&e.filters.some((a)=>a.test(n)))return y.NoExplore();let i=t.path.length===0,s=t.parents.length>0?t.parents.toReversed():[];if(i){if(s.length>0)throw Error("Root object should not have a parent");s=e?.root?.parents?[e.root.parent,...e.root.parents.toReversed()]:[]}let u={...r,...e.root,this:t.parent,parent:s.length>0?s[0]:null,parents:s};if(e?.onCreateContext){let a=await e.onCreateContext(u,t);if(a)u=a}try{let a=y.Explore();if(typeof t.value==="string"){let l=t.value,g=!1;while(!0){let[d,p]=await Xr(l,e,n,u);if(g=g||p,a=await Ar(n,d,u,e),a.action===L.ReplaceItem&&typeof a.by==="string"){l=a.by;continue}if(a.action===L.Explore&&p&&d!==l)a=y.ReplaceItem(d);break}if(a.action===L.Explore&&l!==t.value)a=y.ReplaceItem(l);switch(a.action){case L.Explore:break;case L.ReplaceItem:t.value=a.by;break;default:return a}}if(Qr(t,e))a=await xr(t,n,u,e);return a}catch(a){throw Error(`${a.message}
17
+ `,j-1),V=T===-1?0:T+1,v=u.slice(V,j).trim().length===0?V:j;u=u.slice(0,v)+C+u.slice(P),a+=C.length-(P-v),g.content=u}return[u,l]};var Or=(r)=>{let e=[],t=0;while(t<r.length)if(r[t]==="$"&&r[t+1]==="("&&(t===0||r[t-1]!=="\\")){let n=t;t+=2;let i=1;for(;t<r.length;t++)if(r[t]==="(")i++;else if(r[t]===")"){if(i--,i===0){e.push([n,t]);break}}if(i!==0)throw Error(`Unmatched opening $( at position ${n.toString()}`);t++}else t++;return e};var Ur=(r)=>({value:r}),yn=(r)=>{return r!==null&&typeof r==="object"},Tr=async(r,e,t)=>{for(let n=e.length-1;n>=0;n--){let[i,s]=e[n],u=r.slice(i+2,s),a=await Tr(u,Or(u),t);if(typeof a==="object")return a;let l=await t(a,r);if(yn(l))return l.value;r=r.slice(0,i)+l+r.slice(s+1)}return r},Vr=async(r,e)=>Tr(r,Or(r),e);var hn=(r)=>{return r!==null&&typeof r==="object"&&"action"in r},dn=/([\w\d.-_/]+):(.+)/,bn=async(r,e,t,n)=>{let i=await(async()=>{let s=dn.exec(r);if(!s)return await Object.select(e,r);let[u,a,l]=s,g=ur(n.sources,a),d=Zr(l,g,e);return await g.fn({args:d.parsedArgs,rawArgs:d.rawArgs,tags:d.tags,key:a,options:n,root:e,path:t,value:null})})();if(i===null||i===void 0)return"";if(typeof i==="object")return Ur(i);return i},Ar=async(r,e,t,n)=>{let i=await Vr(e,(s)=>bn(s,t,r,n));if(hn(i))return i;if(i===e)return y.Explore();if(typeof i==="string"){let s=await Ar(r,i,t,n);if(s.action!==L.Explore)return s}return y.ReplaceItem(i)};var $=async(r,e)=>{return e??={},await Object.navigate(r,async(t)=>{let n=[...t.path,t.key].join(".");if(e?.filters?.length&&e.filters.some((a)=>a.test(n)))return y.NoExplore();let i=t.path.length===0,s=t.parents.length>0?t.parents.toReversed():[];if(i){if(s.length>0)throw Error("Root object should not have a parent");s=e?.root?.parents?[e.root.parent,...e.root.parents.toReversed()]:[]}let u={...r,...e.root,this:t.parent,parent:s.length>0?s[0]:null,parents:s};if(e?.onCreateContext){let a=await e.onCreateContext(u,t);if(a)u=a}try{let a=y.Explore();if(typeof t.value==="string"){let l=t.value,g=!1;while(!0){let[d,p]=await Xr(l,e,n,u);if(g=g||p,a=await Ar(n,d,u,e),a.action===L.ReplaceItem&&typeof a.by==="string"){l=a.by;continue}if(a.action===L.Explore&&p&&d!==l)a=y.ReplaceItem(d);break}if(a.action===L.Explore&&l!==t.value)a=y.ReplaceItem(l);switch(a.action){case L.Explore:break;case L.ReplaceItem:t.value=a.by;break;default:return a}}if(Qr(t,e))a=await xr(t,n,u,e);return a}catch(a){throw Error(`${a.message}
18
18
  (${n})`,{cause:a})}}),r};var vr=(r,e)=>e?{fn:(t)=>r(...t.args),types:e}:(t)=>r(...t.args),ki=(r,e)=>Object.fromEntries(r.map((t)=>[t.name,vr(t,e?.types?.[t.name])])),J=(r,e)=>Object.fromEntries((e?.keys??Object.keys(r)).map((t)=>[t,vr(r[t],e?.types?.[t])]));var fr=async(r,e)=>{let t=r.value;if(t.selector===void 0)return e;if(typeof t.selector!=="string"){let n=JSON.parse(JSON.stringify(t.selector));return await $(n,{...r.options,root:{...r.root,result:e}}),n}return await Object.select({...r.root,result:e},t.selector)};import _ from"path";class K{constructor(){}static normalize(r){return _.normalize(_.resolve(r))}static resolveInContext(r,e){let t=e??process.cwd(),n=_.isAbsolute(r)?r:_.join(t,r);return this.normalize(n)}static isDirectoryPattern(r){return r.endsWith("/")}static isGlobPattern(r){return r.includes("*")}static toAbsolute(r,e){if(_.isAbsolute(r))return r;return _.join(e??process.cwd(),r)}}var R={and:(...r)=>r.every((e)=>!!e),or:(...r)=>r.some((e)=>!!e),xor:(...r)=>r.filter((e)=>!!e).length===1,true:(...r)=>r.every((e)=>!!e),false:(...r)=>r.every((e)=>!e),eq:(...r)=>r.every((e)=>e===r[0]),ne:(...r)=>r.some((e)=>e!==r[0]),lt:(...r)=>typeof r[0]==="number"&&r.slice(1).every((e)=>typeof e==="number"&&r[0]<e),le:(...r)=>typeof r[0]==="number"&&r.slice(1).every((e)=>typeof e==="number"&&r[0]<=e),gt:(...r)=>typeof r[0]==="number"&&r.slice(1).every((e)=>typeof e==="number"&&r[0]>e),ge:(...r)=>typeof r[0]==="number"&&r.slice(1).every((e)=>typeof e==="number"&&r[0]>=e),in:(r,e)=>{if(Array.isArray(e))return e.includes(r);if(typeof r==="string")return r.includes(e);if(Array.isArray(r))return r.includes(e);return!1},notin:(r,e)=>!R.in(r,e),contains:(r,e)=>r.includes(e),notcontains:(r,e)=>!r.includes(e),containsi:(r,e)=>r.toLowerCase().includes(e.toLowerCase()),notcontainsi:(r,e)=>!r.toLowerCase().includes(e.toLowerCase()),null:(...r)=>r.every((e)=>e===null||e===void 0),notnull:(...r)=>r.every((e)=>e!==null&&e!==void 0),empty:(...r)=>r.every((e)=>e===""),notempty:(...r)=>r.every((e)=>e!==""),nullorempty:(...r)=>r.every((e)=>e===null||e===void 0||e===""),notnullorempty:(...r)=>r.every((e)=>e!==null&&e!==void 0&&e!=="")},cr={and:()=>"boolean",or:()=>"boolean",xor:()=>"boolean",true:()=>"boolean",false:()=>"boolean",lt:()=>"number",le:()=>"number",gt:()=>"number",ge:()=>"number"};var re=()=>({each:{filters:[/select|model/],fn:async(r)=>{let e=r.value;delete r.parent[r.key];let t=await or(r),n=await ir(r);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(e.extend?.model)n=[e.model,...Array.isArray(e.extend.model)?e.extend.model:[e.extend.model]].mergeAll();let i=[];for(let s=0;s<t.length;s++){let u=Object.deepClone(n);if(await $(u,{...r.options,root:{...r.root,index:s,item:t[s],instance:u}}),e.extend?.result){let a=e.extend.result;u=[u,...Array.isArray(a)?a:[a]].mergeAll()}i.push(await fr(r,u))}return i}}});var ee=()=>({map:{filters:[/select|model/],fn:async(r)=>{delete r.parent[r.key];let e=await or(r),t=await ir(r);if(!Array.isArray(e))throw Error('Key "map" requires a source list');if(t===void 0)throw Error('Key "map" must define a model');let n=[];return await e.forEachAsync(async(i,s)=>{let u=Object.deepClone(t);await $(u,{...r.options,root:{...r.root,index:s,item:i,instance:u}}),n.push(await fr(r,u))}),n}}});var te=()=>({concat:async(r)=>{let e=[];for(let t of Array.isArray(r.value)?r.value:[r.value])e.push(...await Object.select(r.root,t));return e.filter((t)=>t!==void 0)}});var ne=()=>({extends:async(r)=>{let e=async(t,n)=>{for(let i of Array.isArray(n)?n:[n]){let s=await Object.select(r.root,i),u=Object.deepClone(s);if(u[r.key])await e(u,u[r.key]);await $(u,{...r.options}),Object.merge(u,t),delete t[r.key]}};return await e(r.parent,r.value),y.Explore()},group:(r)=>{let e=r.root.parent,t=r.value,{items:n,...i}=t;return t.items.forEach((s)=>e.push({...i,...s})),y.DeleteParent()}});var ie=(r)=>({skip:{types:{0:"boolean"},fn:(e)=>e.value?y.DeleteParent():y.DeleteItem()},metadata:({path:e,value:t})=>{return r.metadata(e,t),y.DeleteItem()},if:{types:{0:"boolean"},fn:async(e)=>{let t=e.parent[".then"],n=e.parent[".else"];if(t!==void 0)delete e.parent[".then"];if(n!==void 0)delete e.parent[".else"];let i=e.value?t:n;if(i===void 0)return y.DeleteItem();if(typeof i==="string")return(await $({value:i},{...e.options,root:{...e.root}})).value;return y.ReplaceParent(i,!0)}},switch:(e)=>{let t=e.value;if(!t.cases)throw Error("Missing cases for switch");if(t.cases[t.from]!==void 0)return y.ReplaceParent(t.cases[t.from],!0);if(t.default!==void 0)return y.ReplaceParent(t.default,!0);return y.DeleteParent()}});var oe=()=>({from:async({root:r,parent:e,value:t})=>{let n=await Object.select(r,t);if(n===null||n===void 0)throw Error(`Unable to resolve reference: ${t}`);if(e.content){if(Array.isArray(e.content)&&Array.isArray(n))return[...n,...e.content];return Object.merge(n,e.content),e.content}return n}});import se from"node:vm";var ae=(r)=>({modules:async(e)=>{for(let[t,n]of Object.entries(e.value)){let i=se.createContext({console,objector:r,document:e.root}),s=new se.SourceTextModule(n,{identifier:t,context:i});await s.link((u)=>{throw Error(`Module ${u} is not allowed`)}),await s.evaluate(),r.sources(Object.fromEntries(Object.entries(s.namespace).map(([u,a])=>[`${t}.${u}`,(l)=>a(l,...l.args)])))}return y.DeleteItem()}});var ue=()=>({try:{fn:(r)=>{let e=r.parent[".catch"];if(e!==void 0)delete r.parent[".catch"];try{return r.value}catch(t){if(e!==void 0)return e;return y.DeleteItem()}}}});var fe=()=>({let:{fn:(r)=>{let e=r.value;return Object.assign(r.root,e),y.DeleteItem()}}});var ce=()=>({tap:{fn:(r)=>{return console.log(`[tap] ${r.path}:`,r.value),r.value}}});var wn=(r,e)=>{let t=e.section.config.using,n=r.getFunctions();if(!t)return n;let i={};return t.forEach((s)=>{if(s in n){i[s]=n[s];return}if(s in e.root){i[s]=e.root[s];return}throw Error(`Function or variable "${s}" not found for script section`)}),i},jr=(r,e,t,n,i=[])=>{let s=wn(r,t),u=["section","context","config","system",...Object.keys(s),...i],a=[e,t.root,t.section.config,r,...Object.values(s)];return[new AsyncFunction(...u,n).bind(t),a]},On=(r,e)=>{let t={write:(...n)=>{return e.push(...n),t},writeLine:(...n)=>{return e.push(...n.map((i)=>i+`
19
19
  `)),t},clear:()=>{return e.splice(0,e.length),t},prepend:(...n)=>{return e.unshift(...n),t},prependLine:(...n)=>{return e.unshift(...n.map((i)=>i+`
20
20
  `)),t},setOptions:(n)=>{return Object.assign(r.section,n),t},use:(n)=>{return n(t),t},getLines:()=>e};return t},An=async(r,e,t)=>{let n=t.section.config.condition;if(n!==void 0){let[i,s]=jr(r,e,t,`return (${n})`);if(!await i(...s))return!1}return!0},le=(r)=>async(e)=>{let t=[],n=On(e,t);if(!await An(r,n,e))return!1;let[i,s]=jr(r,n,e,e.section.content,["item"]),u=e.section.config.each;if(u){let[a,l]=jr(r,n,e,`return (${u})`),g=Array.isArray(u)?u:await a(...l);if(!Array.isArray(g))throw Error('The "each" property of a script section must return an array');for(let d of g){let p=await i(...s,d);if(typeof p<"u")t.push(p)}}else{let a=await i(...s,e.root.item);if(typeof a<"u")return a}if(t.length===0)return!1;return t.join("")};var me=(r)=>({script:le(r)});import pe from"fs/promises";import Z from"path";var ge=(r)=>({include:async(e)=>{let{file:t}=e.options.globalContext;return await Wr(e.args[0],{cwd:Z.dirname(t),filter:(n)=>Z.basename(t)!==n,map:async(n)=>r.load(n,Z.dirname(t),e.root)})},exists:async({args:[e]})=>await br(e),file:async(e)=>await pe.readFile(await nr(e.args[0],r.getIncludeDirectories())).then((t)=>t.toString()),scan:async(e)=>{let t=[],i=(()=>{let a=e.args[2]??["**/node_modules/**"],l=typeof a==="string"?a.split(",").map((g)=>g.trim()):a;if(!Array.isArray(l))throw Error("Scan exclusion must be a list");return l})(),{file:s}=e.options.globalContext,u=e.args[1]?await nr(e.args[1],r.getIncludeDirectories()):Z.dirname(s);for await(let a of pe.glob(e.args[0],{cwd:u,exclude:(l)=>i.some((g)=>Z.matchesGlob(l,g))}))t.push(a);return t}});var ye=(r)=>({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,t]})=>e.repeat(t)},pad:{types:{0:"ref",1:"number",2:"string"},fn:({args:[e,t],tags:n})=>{let i=n.join?.[0]??`
@@ -26,5 +26,5 @@ ${s.map(([a,l])=>`${i}${a} = ${lr(l,e+1,t)}`).join(`
26
26
  `)}
27
27
  ${n}}`}else return String(r)},Q=(r)=>{if(!r)return r;return r.replaceAll("\\n",`
28
28
  `).replaceAll("\\$","$").replaceAll("\\t","\t")};var he=()=>({...J({merge:(...r)=>r.flatMap((e)=>e)}),join:({args:[r],root:e,tags:t})=>{let n=defined(r,"Join source cannot be null or undefined"),i=t.key?.[0],s=t.separator?.[0]??t.sep?.[0],u=t.finalize?.length>0,a=Q(s);if(typeof n==="string"){if(u&&n.length&&a)return n+a;return n}if(!Array.isArray(n))throw Error("Object is not a list");let l=((i?.length)?n.map((O)=>Object.select({...e,...O},i)):n).join(a),g=t.pad?.[0]??"0",d=t.padChar?.[0]??" ",p=u&&l.length&&a?l+a:l;return g?p.padBlock(parseInt(g),`
29
- `,d):p},range:({args:[r,e,t]})=>{let n=parseInt(r),i=parseInt(e),s=parseInt(t)||1;if(isNaN(n))throw Error("Invalid range: start value '"+String(r)+"' is not a number");if(isNaN(i))throw Error("Invalid range: end value '"+String(e)+"' is not a number");if(s===0)throw Error("Invalid range: step cannot be zero");if((i-n)/s<0)throw Error("Invalid range: step "+String(s)+" has wrong direction for range "+String(n)+" to "+String(i));return Array.from({length:Math.floor((i-n)/s)+1},(u,a)=>n+a*s)},filter:{types:(r,e,t)=>{switch(r){case 0:return"array";case 1:return Object.keys(R)}return cr[t[1].value]?.(r-2,e,t.slice(2))},fn:({args:[r,e,t],root:n,tags:i})=>{if(r===null||r===void 0)throw Error("Filter source cannot be null or undefined");if(!Array.isArray(r))throw Error("Filter source must be an array");let s=i.key?.[0],u=R[e];if(s){let l=Array(r.length);for(let d=0;d<r.length;d++)try{l[d]=Object.select({...n,...r[d]},s)}catch{l[d]=Symbol("invalid")}let g=[];for(let d=0;d<r.length;d++){let p=l[d];if(typeof p!=="symbol"&&t===void 0?u(p):u(p,t))g.push(r[d])}return g}let a=[];for(let l of r)if(t===void 0?u(l):u(l,t))a.push(l);return a}}});var de=()=>({each:{processArgs:!1,fn:async({rawArgs:[r,e,...t],root:n,options:i,tags:s})=>{let u=async(w)=>w.quoted?Q(w.value):await Object.select(n,w.value),a=await Object.select(n,r.value),l=await u(e),g=s.key?.[0],d=Array.isArray(a)?a:Object.toList(a,"name"),p=[],O=await t.mapAsync(async(w)=>await u(w)),b={...n,item:void 0,index:0,params:O,instance:void 0,parent:n.this,tags:s},P={...i,root:b};if(await d.forEachAsync(async(w,j)=>{let D=Object.deepClone(l),A={instance:D},E=typeof l==="string"?A:D;if(b.item=w,b.index=j,b.instance=D,s?.root?.[0])Object.assign(b,await Object.select(b,s.root[0]));if(await $(E,P),g!==void 0)p.push(await Object.select(A.instance,g));else p.push(A.instance)}),s.join?.length){if(p.length===0)return"";let w=Q(s.join[0]),j=s.pad?.[0]??"0",D=s.padChar?.[0]??" ",A=s.finalize?.length&&w?w:"",E=`${p.join(w)}${A}`;return j?E.padBlock(parseInt(j),`
30
- `,D):E}return p}}});var x=async(r,e,t)=>r.rawArgs[e].quoted?r.rawArgs[e].value:await Object.select(r.root,r.rawArgs[e].value,{defaultValue:t}),be=()=>({switch:{processArgs:!1,fn:async(r)=>{let e=await x(r,0,!1),t=await x(r,1);if(t[e]===void 0){if(r.rawArgs.length>2)return x(r,2);throw Error(`Unhandled switch case: ${e}`)}return t[e]}}});var we=()=>({if:{types:{0:"boolean"},fn:(r)=>r.args[0]?r.args[1]:r.args[2]},check:{types:{0:Object.keys(R)},fn:(r)=>R[r.args[0]](...r.args.slice(1))},...J(R,{types:cr})});var Oe=(r)=>({default:{processArgs:!1,fn:async(e)=>{for(let t=0;t<e.rawArgs.length;t++)if(e.rawArgs[t]?.value!==void 0){let i=await x(e,t,null);if(i!==null)return i}if(e.tags.nullable?.length)return y.DeleteItem();if(e.tags.fail?.length)throw Error(`No valid value found for default (${e.rawArgs.map((t)=>t.value).join(", ")})`);return""}},section:{types:["string","boolean"],fn:(e)=>{let t=e.args[0];if(!(e.args[1]??!0))return null;let i=r.getSection(t);if(!i)throw Error(`Section not found: ${t}`);return i.content}}});var Ae=()=>({convert:({args:[r,e,t]})=>{switch(e){case"string":return String(r);case"number":{let n=Number(r);if(!isNaN(n))return y.ReplaceItem(n);break}case"boolean":if(r==="true"||r===!0||r===1||r==="1"||r==="yes"||r==="on")return y.ReplaceItem(!0);else if(r==="false"||r===!1||r===0||r==="0"||r==="no"||r==="off")return y.ReplaceItem(!1);break;default:throw Error(`Unsupported type for convert: ${e}`)}if(t!==void 0)return y.ReplaceItem(t);throw Error(`Failed to convert value to ${e}`)},isType:({args:[r,e]})=>{let n=(()=>{switch(e){case"string":return typeof r==="string";case"number":return typeof r==="number";case"boolean":return typeof r==="boolean";case"object":return r!==null&&typeof r==="object"&&!Array.isArray(r);case"array":return Array.isArray(r);case"null":return r===null;case"undefined":return r===void 0;case"function":return typeof r==="function";default:throw Error(`Unknown type for isType: ${e}`)}})();return y.ReplaceItem(n)},typeOf:({args:[r]})=>{if(r===null)return"null";else if(Array.isArray(r))return"array";else return typeof r}});var je=(r)=>{var e,t,n,i,s,u,a,l,g,d,p,O,b,P,w,j,D,A,E,F,M,U,B,C,T,V,Er,v,N,mr,rr,er,Se,Fe,Ee,Me,$e,Pe,De,ke,Ce,Le,Re,Ie,Be,_e,Ke,We,Ne,qe,Ye,ze,He,Ge,Je,Ze,Qe,xe,Xe,Ue,Te,Ve,ve,rt,et,tt,nt,it,ot,st,at,ut,ft,ct,lt,mt,pt,gt,yt,ht,dt,bt,wt,Ot,At,jt,St,Ft,Et,Mt,$t,Pt,Dt,kt,Ct,Lt,Rt,It,Bt,_t,Kt,Wt,Nt,qt,i,s,u,a,l,g,d,p,O,b,P,w,j,D,A,E,F,M,U,B,C,T,V,Er,v,N,mr,rr,er,Se,Fe,Ee,Me,$e,Pe,De,ke,Ce,Le,Re,Ie,Be,_e,Ke,We,Ne,qe,Ye,ze,He,Ge,Je,Ze,Qe,xe,Xe,Ue,Te,Ve,ve,rt,et,tt,nt,it,ot,st,at,ut,ft,ct,lt,mt,pt,gt,yt,ht,dt,bt,wt,Ot,At,jt,St,Ft,Et,Mt,$t,Pt,Dt,kt,Ct,Lt,Rt,It,Bt,_t,Kt,Wt,Nt,qt;return r.use((n=G,i=[c()],s=[c()],u=[c()],a=[c()],l=[c()],g=[c()],d=[c()],p=[c()],O=[c()],b=[c()],P=[c()],w=[c()],j=[c()],D=[c()],A=[c()],E=[c()],F=[c()],M=[c()],U=[c()],B=[c()],C=[c()],T=[c()],V=[c()],Er=[c()],v=[c()],N=[c()],mr=[c()],rr=[c()],er=[c()],Se=[c()],Fe=[c()],Ee=[c()],Me=[c()],$e=[c()],Pe=[c()],De=[c()],ke=[c()],Ce=[c()],Le=[c()],Re=[c()],Ie=[c()],Be=[c()],_e=[c()],Ke=[c()],We=[c()],Ne=[c()],qe=[c()],Ye=[c()],ze=[c()],He=[c()],Ge=[c()],Je=[c()],Ze=[c()],Qe=[c()],xe=[c()],Xe=[c()],Ue=[c()],Te=[c()],Ve=[c()],ve=[c()],rt=[c()],et=[c()],tt=[c()],nt=[c()],it=[c()],ot=[c()],st=[c()],at=[c()],ut=[c()],ft=[c()],ct=[c()],lt=[c()],mt=[c()],pt=[c()],gt=[c()],yt=[c()],ht=[c()],dt=[c()],bt=[c()],wt=[c()],Ot=[c()],At=[c()],jt=[c()],St=[c()],Ft=[c()],Et=[c()],Mt=[c()],$t=[c()],Pt=[c()],Dt=[c()],kt=[c()],Ct=[c()],Lt=[c()],Rt=[c()],It=[c()],Bt=[c()],_t=[c()],Kt=[c()],Wt=[c()],Nt=[c()],qt=[c()],t=Cr(n),e=class extends n{constructor(){super(...arguments);Rr(t,5,this)}env(o){return process.env[o]}uuid(){return crypto.randomUUID()}pascal(o){return o.toPascal()}camel(o){return o.toCamel()}capital(o){return o.capitalize()}snake(o,m="lower"){return o.changeCase(m).toSnake()}kebab(o,m="lower"){return o.changeCase(m).toKebab()}len(o){return o.length}reverse(o){return o.split("").reverse().join("")}concat(...o){return o.join("")}trim(o){return o.trim()}ltrim(o){return o.trimStart()}rtrim(o){return o.trimEnd()}lower(o){return o.toLowerCase()}upper(o){return o.toUpperCase()}encode(o,m){return Buffer.from(o).toString(m??"base64")}decode(o,m){return Buffer.from(o,m??"base64").toString()}list(o,m="name"){return Object.toList(o,m)}object(o,m="name"){return o.toObject((h)=>h[m],(h)=>{let{[m]:S,...k}=h;return k})}pathJoin(...o){return I.join(...o)}resolve(...o){return I.resolve(...o)}dirname(o){return I.dirname(o)}basename(o,m){return I.basename(o,m)}normalize(o){return I.normalize(o)}extname(o){return I.extname(o)}relative(o,m){return I.relative(o,m)}isAbsolute(o){return I.isAbsolute(o)}segments(o){return o.split("/").filter(Boolean)}log(...o){console.log(...o)}md5(o){return W("md5").update(o).digest("hex")}sha1(o){return W("sha1").update(o).digest("hex")}sha256(o){return W("sha256").update(o).digest("hex")}sha512(o){return W("sha512").update(o).digest("hex")}hash(o,m="sha256"){return W(m).update(o).digest("hex")}hmac(o,m,h="sha256"){return W(h).update(o).digest("hex")}base64Encode(o){return Buffer.from(o).toString("base64")}base64Decode(o){return Buffer.from(o,"base64").toString("utf-8")}hexEncode(o){return Buffer.from(o).toString("hex")}hexDecode(o){return Buffer.from(o,"hex").toString("utf-8")}add(...o){return o.reduce((m,h)=>m+h,0)}subtract(o,m){return o-m}multiply(...o){return o.reduce((m,h)=>m*h,1)}divide(o,m){if(m===0)throw Error("Division by zero");return o/m}modulo(o,m){return o%m}power(o,m){return Math.pow(o,m)}sqrt(o){return Math.sqrt(o)}abs(o){return Math.abs(o)}floor(o){return Math.floor(o)}ceil(o){return Math.ceil(o)}round(o,m){let h=Math.pow(10,m??0);return Math.round(o*h)/h}min(...o){return Math.min(...o)}max(...o){return Math.max(...o)}clamp(o,m,h){return Math.max(m,Math.min(h,o))}random(o,m){let h=o??0,S=m??1;return Math.random()*(S-h)+h}timestamp(o){return new Date(o).getTime()}iso(o){return new Date(o).toISOString()}utc(o){return new Date(o).toUTCString()}formatDate(o,m){let h=new Date(o),S=h.getFullYear(),k=String(h.getMonth()+1).padStart(2,"0"),tr=String(h.getDate()).padStart(2,"0"),q=String(h.getHours()).padStart(2,"0"),Yt=String(h.getMinutes()).padStart(2,"0"),zt=String(h.getSeconds()).padStart(2,"0");return m.replace("YYYY",String(S)).replace("MM",k).replace("DD",tr).replace("HH",q).replace("mm",Yt).replace("ss",zt)}parseDate(o){return new Date(o).getTime()}year(o){return new Date(o).getFullYear()}month(o){return new Date(o).getMonth()+1}day(o){return new Date(o).getDate()}dayOfWeek(o){return new Date(o).getDay()}hours(o){return new Date(o).getHours()}minutes(o){return new Date(o).getMinutes()}seconds(o){return new Date(o).getSeconds()}regexTest(o,m,h){return new RegExp(o,h).test(m)}regexMatch(o,m,h){return new RegExp(o,h).exec(m)}regexMatchAll(o,m,h){return Array.from(m.matchAll(new RegExp(o,h)))}regexReplace(o,m,h,S){return h.replace(new RegExp(o,S),m)}regexReplaceAll(o,m,h,S){return h.replace(new RegExp(o,S??"g"),m)}regexSplit(o,m,h){return m.split(new RegExp(o,h))}regexExec(o,m,h){return new RegExp(o,h).exec(m)}regexSearch(o,m,h){return m.search(new RegExp(o,h))}unique(o,m){if(!Array.isArray(o))return o;let h=new Set;return o.filter((S)=>{let k=m?S[m]:S;if(h.has(k))return!1;return h.add(k),!0})}groupBy(o,m){if(!Array.isArray(o))return o;let h={};return o.forEach((S)=>{let k=String(S[m]);if(!h[k])h[k]=[];h[k].push(S)}),h}chunk(o,m=1){if(!Array.isArray(o))return[];let h=[];for(let S=0;S<o.length;S+=m)h.push(o.slice(S,S+m));return h}flatten(o,m=1){if(!Array.isArray(o))return[o];let h=[],S=(k,tr)=>{for(let q of k)if(Array.isArray(q)&&tr>0)S(q,tr-1);else h.push(q)};return S(o,m),h}compact(o){if(!Array.isArray(o))return o;return o.filter((m)=>m!==null&&m!==void 0)}head(o,m){if(!Array.isArray(o))return o;return m?o.slice(0,m):o[0]}tail(o,m){if(!Array.isArray(o))return o;return m?o.slice(-m):o[o.length-1]}isEmail(o){return/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(o)}isUrl(o){try{return new URL(o),!0}catch{return!1}}isJson(o){try{return JSON.parse(o),!0}catch{return!1}}isUuid(o){return/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i.test(o)}minLength(o,m){return o?.length>=m}maxLength(o,m){return o?.length<=m}lengthEquals(o,m){return o?.length===m}isNumber(o){return typeof o==="number"&&!isNaN(o)}isString(o){return typeof o==="string"}isBoolean(o){return typeof o==="boolean"}isArray(o){return Array.isArray(o)}isObject(o){return o!==null&&typeof o==="object"&&!Array.isArray(o)}isEmpty(o){if(o===null||o===void 0)return!0;if(typeof o==="string"||Array.isArray(o))return o.length===0;if(typeof o==="object")return Object.keys(o).length===0;return!1}isTruthy(o){return!!o}isFalsy(o){return!o}inRange(o,m,h){return o>=m&&o<=h}matchesPattern(o,m){return new RegExp(m).test(o)}includes(o,m){if(typeof o==="string")return o.includes(String(m));return Array.isArray(o)&&o.includes(m)}startsWith(o,m){return o.startsWith(m)}endsWith(o,m){return o.endsWith(m)}},f(t,1,"env",i,e),f(t,1,"uuid",s,e),f(t,1,"pascal",u,e),f(t,1,"camel",a,e),f(t,1,"capital",l,e),f(t,1,"snake",g,e),f(t,1,"kebab",d,e),f(t,1,"len",p,e),f(t,1,"reverse",O,e),f(t,1,"concat",b,e),f(t,1,"trim",P,e),f(t,1,"ltrim",w,e),f(t,1,"rtrim",j,e),f(t,1,"lower",D,e),f(t,1,"upper",A,e),f(t,1,"encode",E,e),f(t,1,"decode",F,e),f(t,1,"list",M,e),f(t,1,"object",U,e),f(t,1,"pathJoin",B,e),f(t,1,"resolve",C,e),f(t,1,"dirname",T,e),f(t,1,"basename",V,e),f(t,1,"normalize",Er,e),f(t,1,"extname",v,e),f(t,1,"relative",N,e),f(t,1,"isAbsolute",mr,e),f(t,1,"segments",rr,e),f(t,1,"log",er,e),f(t,1,"md5",Se,e),f(t,1,"sha1",Fe,e),f(t,1,"sha256",Ee,e),f(t,1,"sha512",Me,e),f(t,1,"hash",$e,e),f(t,1,"hmac",Pe,e),f(t,1,"base64Encode",De,e),f(t,1,"base64Decode",ke,e),f(t,1,"hexEncode",Ce,e),f(t,1,"hexDecode",Le,e),f(t,1,"add",Re,e),f(t,1,"subtract",Ie,e),f(t,1,"multiply",Be,e),f(t,1,"divide",_e,e),f(t,1,"modulo",Ke,e),f(t,1,"power",We,e),f(t,1,"sqrt",Ne,e),f(t,1,"abs",qe,e),f(t,1,"floor",Ye,e),f(t,1,"ceil",ze,e),f(t,1,"round",He,e),f(t,1,"min",Ge,e),f(t,1,"max",Je,e),f(t,1,"clamp",Ze,e),f(t,1,"random",Qe,e),f(t,1,"timestamp",xe,e),f(t,1,"iso",Xe,e),f(t,1,"utc",Ue,e),f(t,1,"formatDate",Te,e),f(t,1,"parseDate",Ve,e),f(t,1,"year",ve,e),f(t,1,"month",rt,e),f(t,1,"day",et,e),f(t,1,"dayOfWeek",tt,e),f(t,1,"hours",nt,e),f(t,1,"minutes",it,e),f(t,1,"seconds",ot,e),f(t,1,"regexTest",st,e),f(t,1,"regexMatch",at,e),f(t,1,"regexMatchAll",ut,e),f(t,1,"regexReplace",ft,e),f(t,1,"regexReplaceAll",ct,e),f(t,1,"regexSplit",lt,e),f(t,1,"regexExec",mt,e),f(t,1,"regexSearch",pt,e),f(t,1,"unique",gt,e),f(t,1,"groupBy",yt,e),f(t,1,"chunk",ht,e),f(t,1,"flatten",dt,e),f(t,1,"compact",bt,e),f(t,1,"head",wt,e),f(t,1,"tail",Ot,e),f(t,1,"isEmail",At,e),f(t,1,"isUrl",jt,e),f(t,1,"isJson",St,e),f(t,1,"isUuid",Ft,e),f(t,1,"minLength",Et,e),f(t,1,"maxLength",Mt,e),f(t,1,"lengthEquals",$t,e),f(t,1,"isNumber",Pt,e),f(t,1,"isString",Dt,e),f(t,1,"isBoolean",kt,e),f(t,1,"isArray",Ct,e),f(t,1,"isObject",Lt,e),f(t,1,"isEmpty",Rt,e),f(t,1,"isTruthy",It,e),f(t,1,"isFalsy",Bt,e),f(t,1,"inRange",_t,e),f(t,1,"matchesPattern",Kt,e),f(t,1,"includes",Wt,e),f(t,1,"startsWith",Nt,e),f(t,1,"endsWith",qt,e),gr(t,e),e)).keys({...zr(r),...Hr(r),...re(),...ee(),...oe(),...te(),...ne(),...ie(r),...ae(r),...ue(),...fe(),...ce()}).sources({...ge(r),...ye(r),...Ae(),...he(),...de(),...be(),...we(),...Oe(r)}).sections(me(r)).fieldOptions({configParser:Bun.YAML.parse,onSection:(o)=>{if(o.section.config.name)r.section(o.section)}}).decoders({yaml:{matching:["\\.yml$","\\.yaml$"],fn:Bun.YAML.parse}}).encoders({json:{fn:(o)=>JSON.stringify(o,null,2)},yaml:{fn:(o)=>Bun.YAML.stringify(o,null,2)},terraform:{options:{includeTags:!0},fn:(o,m)=>lr(o,0,{sortKeys:!!(m?.sort?.length??m?.sortKeys?.length)})}}).filter(/^\$/)};import jn from"fs/promises";import X from"path";class Sr{includeDirectories=[];baseIncludeDirectories=[];includes=[];addDirectories(...r){this.includeDirectories.push(...r),this.baseIncludeDirectories.push(...r)}getDirectories(){return this.includeDirectories}reset(){this.includeDirectories=[...this.baseIncludeDirectories]}restore(r){this.includeDirectories=[...r]}snapshot(){return[...this.includeDirectories]}addFiles(...r){this.includes.push(...r)}getPendingAndClear(){let r=[...this.includes];return this.includes.length=0,r}async processPatterns(r,e,t){let n=[];for(let i of r)if(K.isGlobPattern(i)){let s=(await Array.fromAsync(jn.glob(i,{cwd:e}))).map((u)=>X.join(e,u));n.push(...s.filter((u)=>!t.included.includes(u)))}else if(K.isDirectoryPattern(i)){let s=X.isAbsolute(i)?i:X.join(e,i);if(!this.includeDirectories.includes(s))this.includeDirectories.push(s)}else n.push(i);return n.unique()}buildSearchDirs(r){let e=r?[r]:[];return e.push(...this.includeDirectories.map((t)=>X.isAbsolute(t)?t:X.join(r??process.cwd(),t))),e}}class Fr{includeManager;loadFn;constructor(r,e){this.includeManager=r;this.loadFn=e}async processIncludes(r,e,t){let n=[];if(r.content.includes)n.push(...r.content.includes),delete r.content.includes;n.push(...this.includeManager.getPendingAndClear());let i=await this.includeManager.processPatterns(n,r.folderPath,t);for(let s of i)Object.merge(await this.loadFn(s,r.folderPath,{parent:r.content,...e},!0,t),r.content)}}class Sn{includeManager=new Sr;includeProcessor;cacheManager=new wr(100);outputs=[];vars={};funcs={};fields={sources:{},keys:{},sections:{}};objectMetadata={};currentContext=null;storedSections={};dataEncoders={};dataDecoders={};constructor(){this.includeProcessor=new Fr(this.includeManager,this.load.bind(this)),this.use(je)}use(r){if(r.prototype instanceof G)new r(this);else r(this);return this}includeDirectory(...r){return this.includeManager.addDirectories(...r),this}getIncludeDirectories(){return this.includeManager.getDirectories()}include(...r){return this.includeManager.addFiles(...r),this}keys(r){return Object.assign(this.fields.keys,{...this.fields.keys,...r}),this}sources(r){return Object.assign(this.fields.sources,{...this.fields.sources,...r}),this}sections(r){return Object.assign(this.fields.sections,{...this.fields.sections,...r}),this}variables(r){return Object.assign(this.vars,{...this.vars,...r}),this}functions(r){return Object.assign(this.funcs,{...this.funcs,...r}),this}onCreateContext(r){return this.fields.onCreateContext=r,this}getFunctions(){return this.funcs}getOutputs(){return this.outputs}output(r){return this.outputs.push(r),this}metadata(r,e){return this.objectMetadata[r]=e,this}getMetadata(r){return this.objectMetadata[r]}getAllMetadata(){return this.objectMetadata}setCacheMaxSize(r){return this.cacheManager.setMaxSize(r),this}clearCache(){return this.cacheManager.clear(),this}getCurrentContext(){return this.currentContext}getDocument(){return this.currentContext?.document||null}fieldOptions(r){return Object.assign(this.fields,{...this.fields,...r}),this}section(r){return this.storedSections[r.config.name]=r,this}getSection(r){return this.storedSections[r]}encoders(r){return Object.assign(this.dataEncoders,{...this.dataEncoders,...r}),this}decoders(r){return Object.assign(this.dataDecoders,{...this.dataDecoders,...r}),this}getEncoder(r){return this.dataEncoders[r]}getDecoder(r){return this.dataDecoders[r]}filter(r){return this.fields.filters??=[],this.fields.filters.push(r),this}async loadObject(r,e,t){return $(r,{...this.fields,globalContext:{file:t?.fullPath??"@internal"},root:{...e,...this.fields.root,...this.vars,functions:this.funcs,context:this.currentContext,sections:this.storedSections,$document:{root:{content:r},fileName:t?.fileName??"@internal",folder:t?.folderPath??"@internal",fullPath:t?.fullPath??"@internal"}}})}async load(r,e,t,n,i){let s=this.includeManager.snapshot();try{this.includeManager.reset();let u=this.includeManager.buildSearchDirs(e);if(i)this.currentContext=i;this.currentContext??={included:[],document:null};let a=typeof r==="string"?await Kr(r,{dirs:u,parsers:this.dataDecoders,format:"yaml"}):{content:r,fullPath:"",folderPath:""};if(typeof r==="string"){let g=K.normalize(a.fullPath);if(this.currentContext.included.push(g),!a.content)return null;let d=this.cacheManager.get(g),p;if(d)p=d.raw;else p=a.content,this.cacheManager.set(g,{raw:p,timestamp:Date.now()});let O=Object.deepClone(p);a.content=O}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(u){throw this.includeManager.restore(s),u}finally{this.includeManager.restore(s)}}async writeAll(r){await qr(this.getOutputs(),r)}}export{qr as writeOutputs,fn as writeOutput,an as writeFormat,qn as variable,Yn as sharedFunction,Wn as section,$ as processFields,J as makeFieldProcessorMap,ki as makeFieldProcessorList,vr as makeFieldProcessor,c as macro,nr as locate,Kr as loadFormat,Nn as key,ln as importList,_n as importGlob,Wr as globMap,ur as getProcessor,Yr as getCwd,Zr as getArgs,br as exists,zn as encoder,Hn as decoder,R as conditionPredicates,H as StringBuilder,G as ObjectorPlugin,Sn as Objector,y as NavigateResult,L as NavigateAction,vt as Markdown,Vt as Logger,rn as CommandLineArgs};
29
+ `,d):p},range:({args:[r,e,t]})=>{let n=parseInt(r),i=parseInt(e),s=parseInt(t)||1;if(isNaN(n))throw Error("Invalid range: start value '"+String(r)+"' is not a number");if(isNaN(i))throw Error("Invalid range: end value '"+String(e)+"' is not a number");if(s===0)throw Error("Invalid range: step cannot be zero");if((i-n)/s<0)throw Error("Invalid range: step "+String(s)+" has wrong direction for range "+String(n)+" to "+String(i));return Array.from({length:Math.floor((i-n)/s)+1},(u,a)=>n+a*s)},filter:{types:(r,e,t)=>{switch(r){case 0:return"array";case 1:return Object.keys(R)}return cr[t[1].value]?.(r-2,e,t.slice(2))},fn:({args:[r,e,t],root:n,tags:i})=>{if(r===null||r===void 0)throw Error("Filter source cannot be null or undefined");if(!Array.isArray(r))throw Error("Filter source must be an array");let s=i.key?.[0],u=R[e];if(s){let l=Array(r.length);for(let d=0;d<r.length;d++)try{l[d]=Object.select({...n,...r[d]},s)}catch{l[d]=Symbol("invalid")}let g=[];for(let d=0;d<r.length;d++){let p=l[d];if(typeof p!=="symbol"&&t===void 0?u(p):u(p,t))g.push(r[d])}return g}let a=[];for(let l of r)if(t===void 0?u(l):u(l,t))a.push(l);return a}}});var de=()=>({each:{processArgs:!1,fn:async({rawArgs:[r,e,...t],root:n,options:i,tags:s})=>{let u=async(w)=>w.quoted?Q(w.value):await Object.select(n,w.value),a=await Object.select(n,r.value),l=await u(e),g=s.key?.[0],d=Array.isArray(a)?a:Object.toList(a,"name"),p=[],O=await t.mapAsync(async(w)=>await u(w)),b={...n,item:void 0,index:0,params:O,instance:void 0,parent:n.this,tags:s},D={...i,root:b};if(await d.forEachAsync(async(w,j)=>{let P=Object.deepClone(l),A={instance:P},E=typeof l==="string"?A:P;if(b.item=w,b.index=j,b.instance=P,s?.root?.[0])Object.assign(b,await Object.select(b,s.root[0]));if(await $(E,D),g!==void 0)p.push(await Object.select(A.instance,g));else p.push(A.instance)}),s.join?.length){if(p.length===0)return"";let w=Q(s.join[0]),j=s.pad?.[0]??"0",P=s.padChar?.[0]??" ",A=s.finalize?.length&&w?w:"",E=`${p.join(w)}${A}`;return j?E.padBlock(parseInt(j),`
30
+ `,P):E}return p}}});var x=async(r,e,t)=>r.rawArgs[e].quoted?r.rawArgs[e].value:await Object.select(r.root,r.rawArgs[e].value,{defaultValue:t}),be=()=>({switch:{processArgs:!1,fn:async(r)=>{let e=await x(r,0,!1),t=await x(r,1);if(t[e]===void 0){if(r.rawArgs.length>2)return x(r,2);throw Error(`Unhandled switch case: ${e}`)}return t[e]}}});var we=()=>({if:{types:{0:"boolean"},fn:(r)=>r.args[0]?r.args[1]:r.args[2]},check:{types:{0:Object.keys(R)},fn:(r)=>R[r.args[0]](...r.args.slice(1))},...J(R,{types:cr})});var Oe=(r)=>({default:{processArgs:!1,fn:async(e)=>{for(let t=0;t<e.rawArgs.length;t++)if(e.rawArgs[t]?.value!==void 0){let i=await x(e,t,null);if(i!==null)return i}if(e.tags.nullable?.length)return y.DeleteItem();if(e.tags.fail?.length)throw Error(`No valid value found for default (${e.rawArgs.map((t)=>t.value).join(", ")})`);return""}},section:{types:["string","boolean"],fn:(e)=>{let t=e.args[0];if(!(e.args[1]??!0))return null;let i=r.getSection(t);if(!i)throw Error(`Section not found: ${t}`);return i.content}}});var Ae=()=>({convert:({args:[r,e,t]})=>{switch(e){case"string":return String(r);case"number":{let n=Number(r);if(!isNaN(n))return y.ReplaceItem(n);break}case"boolean":if(r==="true"||r===!0||r===1||r==="1"||r==="yes"||r==="on")return y.ReplaceItem(!0);else if(r==="false"||r===!1||r===0||r==="0"||r==="no"||r==="off")return y.ReplaceItem(!1);break;default:throw Error(`Unsupported type for convert: ${e}`)}if(t!==void 0)return y.ReplaceItem(t);throw Error(`Failed to convert value to ${e}`)},isType:({args:[r,e]})=>{let n=(()=>{switch(e){case"string":return typeof r==="string";case"number":return typeof r==="number";case"boolean":return typeof r==="boolean";case"object":return r!==null&&typeof r==="object"&&!Array.isArray(r);case"array":return Array.isArray(r);case"null":return r===null;case"undefined":return r===void 0;case"function":return typeof r==="function";default:throw Error(`Unknown type for isType: ${e}`)}})();return y.ReplaceItem(n)},typeOf:({args:[r]})=>{if(r===null)return"null";else if(Array.isArray(r))return"array";else return typeof r}});var je=(r)=>{var e,t,n,i,s,u,a,l,g,d,p,O,b,D,w,j,P,A,E,F,M,U,B,C,T,V,Er,v,N,mr,rr,er,Se,Fe,Ee,Me,$e,De,Pe,ke,Ce,Le,Re,Ie,Be,_e,Ke,We,Ne,qe,Ye,ze,He,Ge,Je,Ze,Qe,xe,Xe,Ue,Te,Ve,ve,rt,et,tt,nt,it,ot,st,at,ut,ft,ct,lt,mt,pt,gt,yt,ht,dt,bt,wt,Ot,At,jt,St,Ft,Et,Mt,$t,Dt,Pt,kt,Ct,Lt,Rt,It,Bt,_t,Kt,Wt,Nt,qt,i,s,u,a,l,g,d,p,O,b,D,w,j,P,A,E,F,M,U,B,C,T,V,Er,v,N,mr,rr,er,Se,Fe,Ee,Me,$e,De,Pe,ke,Ce,Le,Re,Ie,Be,_e,Ke,We,Ne,qe,Ye,ze,He,Ge,Je,Ze,Qe,xe,Xe,Ue,Te,Ve,ve,rt,et,tt,nt,it,ot,st,at,ut,ft,ct,lt,mt,pt,gt,yt,ht,dt,bt,wt,Ot,At,jt,St,Ft,Et,Mt,$t,Dt,Pt,kt,Ct,Lt,Rt,It,Bt,_t,Kt,Wt,Nt,qt;return r.use((n=G,i=[c()],s=[c()],u=[c()],a=[c()],l=[c()],g=[c()],d=[c()],p=[c()],O=[c()],b=[c()],D=[c()],w=[c()],j=[c()],P=[c()],A=[c()],E=[c()],F=[c()],M=[c()],U=[c()],B=[c()],C=[c()],T=[c()],V=[c()],Er=[c()],v=[c()],N=[c()],mr=[c()],rr=[c()],er=[c()],Se=[c()],Fe=[c()],Ee=[c()],Me=[c()],$e=[c()],De=[c()],Pe=[c()],ke=[c()],Ce=[c()],Le=[c()],Re=[c()],Ie=[c()],Be=[c()],_e=[c()],Ke=[c()],We=[c()],Ne=[c()],qe=[c()],Ye=[c()],ze=[c()],He=[c()],Ge=[c()],Je=[c()],Ze=[c()],Qe=[c()],xe=[c()],Xe=[c()],Ue=[c()],Te=[c()],Ve=[c()],ve=[c()],rt=[c()],et=[c()],tt=[c()],nt=[c()],it=[c()],ot=[c()],st=[c()],at=[c()],ut=[c()],ft=[c()],ct=[c()],lt=[c()],mt=[c()],pt=[c()],gt=[c()],yt=[c()],ht=[c()],dt=[c()],bt=[c()],wt=[c()],Ot=[c()],At=[c()],jt=[c()],St=[c()],Ft=[c()],Et=[c()],Mt=[c()],$t=[c()],Dt=[c()],Pt=[c()],kt=[c()],Ct=[c()],Lt=[c()],Rt=[c()],It=[c()],Bt=[c()],_t=[c()],Kt=[c()],Wt=[c()],Nt=[c()],qt=[c()],t=Cr(n),e=class extends n{constructor(){super(...arguments);Rr(t,5,this)}env(o){return process.env[o]}uuid(){return crypto.randomUUID()}pascal(o){return o.toPascal()}camel(o){return o.toCamel()}capital(o){return o.capitalize()}snake(o,m="lower"){return o.changeCase(m).toSnake()}kebab(o,m="lower"){return o.changeCase(m).toKebab()}len(o){return o.length}reverse(o){return o.split("").reverse().join("")}concat(...o){return o.join("")}trim(o){return o.trim()}ltrim(o){return o.trimStart()}rtrim(o){return o.trimEnd()}lower(o){return o.toLowerCase()}upper(o){return o.toUpperCase()}encode(o,m){return Buffer.from(o).toString(m??"base64")}decode(o,m){return Buffer.from(o,m??"base64").toString()}list(o,m="name"){return Object.toList(o,m)}object(o,m="name"){return o.toObject((h)=>h[m],(h)=>{let{[m]:S,...k}=h;return k})}pathJoin(...o){return I.join(...o)}resolve(...o){return I.resolve(...o)}dirname(o){return I.dirname(o)}basename(o,m){return I.basename(o,m)}normalize(o){return I.normalize(o)}extname(o){return I.extname(o)}relative(o,m){return I.relative(o,m)}isAbsolute(o){return I.isAbsolute(o)}segments(o){return o.split("/").filter(Boolean)}log(...o){console.log(...o)}md5(o){return W("md5").update(o).digest("hex")}sha1(o){return W("sha1").update(o).digest("hex")}sha256(o){return W("sha256").update(o).digest("hex")}sha512(o){return W("sha512").update(o).digest("hex")}hash(o,m="sha256"){return W(m).update(o).digest("hex")}hmac(o,m,h="sha256"){return W(h).update(o).digest("hex")}base64Encode(o){return Buffer.from(o).toString("base64")}base64Decode(o){return Buffer.from(o,"base64").toString("utf-8")}hexEncode(o){return Buffer.from(o).toString("hex")}hexDecode(o){return Buffer.from(o,"hex").toString("utf-8")}add(...o){return o.reduce((m,h)=>m+h,0)}subtract(o,m){return o-m}multiply(...o){return o.reduce((m,h)=>m*h,1)}divide(o,m){if(m===0)throw Error("Division by zero");return o/m}modulo(o,m){return o%m}power(o,m){return Math.pow(o,m)}sqrt(o){return Math.sqrt(o)}abs(o){return Math.abs(o)}floor(o){return Math.floor(o)}ceil(o){return Math.ceil(o)}round(o,m){let h=Math.pow(10,m??0);return Math.round(o*h)/h}min(...o){return Math.min(...o)}max(...o){return Math.max(...o)}clamp(o,m,h){return Math.max(m,Math.min(h,o))}random(o,m){let h=o??0,S=m??1;return Math.random()*(S-h)+h}timestamp(o){return new Date(o).getTime()}iso(o){return new Date(o).toISOString()}utc(o){return new Date(o).toUTCString()}formatDate(o,m){let h=new Date(o),S=h.getFullYear(),k=String(h.getMonth()+1).padStart(2,"0"),tr=String(h.getDate()).padStart(2,"0"),q=String(h.getHours()).padStart(2,"0"),Yt=String(h.getMinutes()).padStart(2,"0"),zt=String(h.getSeconds()).padStart(2,"0");return m.replace("YYYY",String(S)).replace("MM",k).replace("DD",tr).replace("HH",q).replace("mm",Yt).replace("ss",zt)}parseDate(o){return new Date(o).getTime()}year(o){return new Date(o).getFullYear()}month(o){return new Date(o).getMonth()+1}day(o){return new Date(o).getDate()}dayOfWeek(o){return new Date(o).getDay()}hours(o){return new Date(o).getHours()}minutes(o){return new Date(o).getMinutes()}seconds(o){return new Date(o).getSeconds()}regexTest(o,m,h){return new RegExp(o,h).test(m)}regexMatch(o,m,h){return new RegExp(o,h).exec(m)}regexMatchAll(o,m,h){return Array.from(m.matchAll(new RegExp(o,h)))}regexReplace(o,m,h,S){return h.replace(new RegExp(o,S),m)}regexReplaceAll(o,m,h,S){return h.replace(new RegExp(o,S??"g"),m)}regexSplit(o,m,h){return m.split(new RegExp(o,h))}regexExec(o,m,h){return new RegExp(o,h).exec(m)}regexSearch(o,m,h){return m.search(new RegExp(o,h))}unique(o,m){if(!Array.isArray(o))return o;let h=new Set;return o.filter((S)=>{let k=m?S[m]:S;if(h.has(k))return!1;return h.add(k),!0})}groupBy(o,m){if(!Array.isArray(o))return o;let h={};return o.forEach((S)=>{let k=String(S[m]);if(!h[k])h[k]=[];h[k].push(S)}),h}chunk(o,m=1){if(!Array.isArray(o))return[];let h=[];for(let S=0;S<o.length;S+=m)h.push(o.slice(S,S+m));return h}flatten(o,m=1){if(!Array.isArray(o))return[o];let h=[],S=(k,tr)=>{for(let q of k)if(Array.isArray(q)&&tr>0)S(q,tr-1);else h.push(q)};return S(o,m),h}compact(o){if(!Array.isArray(o))return o;return o.filter((m)=>m!==null&&m!==void 0)}head(o,m){if(!Array.isArray(o))return o;return m?o.slice(0,m):o[0]}tail(o,m){if(!Array.isArray(o))return o;return m?o.slice(-m):o[o.length-1]}isEmail(o){return/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(o)}isUrl(o){try{return new URL(o),!0}catch{return!1}}isJson(o){try{return JSON.parse(o),!0}catch{return!1}}isUuid(o){return/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i.test(o)}minLength(o,m){return o?.length>=m}maxLength(o,m){return o?.length<=m}lengthEquals(o,m){return o?.length===m}isNumber(o){return typeof o==="number"&&!isNaN(o)}isString(o){return typeof o==="string"}isBoolean(o){return typeof o==="boolean"}isArray(o){return Array.isArray(o)}isObject(o){return o!==null&&typeof o==="object"&&!Array.isArray(o)}isEmpty(o){if(o===null||o===void 0)return!0;if(typeof o==="string"||Array.isArray(o))return o.length===0;if(typeof o==="object")return Object.keys(o).length===0;return!1}isTruthy(o){return!!o}isFalsy(o){return!o}inRange(o,m,h){return o>=m&&o<=h}matchesPattern(o,m){return new RegExp(m).test(o)}includes(o,m){if(typeof o==="string")return o.includes(String(m));return Array.isArray(o)&&o.includes(m)}startsWith(o,m){return o.startsWith(m)}endsWith(o,m){return o.endsWith(m)}},f(t,1,"env",i,e),f(t,1,"uuid",s,e),f(t,1,"pascal",u,e),f(t,1,"camel",a,e),f(t,1,"capital",l,e),f(t,1,"snake",g,e),f(t,1,"kebab",d,e),f(t,1,"len",p,e),f(t,1,"reverse",O,e),f(t,1,"concat",b,e),f(t,1,"trim",D,e),f(t,1,"ltrim",w,e),f(t,1,"rtrim",j,e),f(t,1,"lower",P,e),f(t,1,"upper",A,e),f(t,1,"encode",E,e),f(t,1,"decode",F,e),f(t,1,"list",M,e),f(t,1,"object",U,e),f(t,1,"pathJoin",B,e),f(t,1,"resolve",C,e),f(t,1,"dirname",T,e),f(t,1,"basename",V,e),f(t,1,"normalize",Er,e),f(t,1,"extname",v,e),f(t,1,"relative",N,e),f(t,1,"isAbsolute",mr,e),f(t,1,"segments",rr,e),f(t,1,"log",er,e),f(t,1,"md5",Se,e),f(t,1,"sha1",Fe,e),f(t,1,"sha256",Ee,e),f(t,1,"sha512",Me,e),f(t,1,"hash",$e,e),f(t,1,"hmac",De,e),f(t,1,"base64Encode",Pe,e),f(t,1,"base64Decode",ke,e),f(t,1,"hexEncode",Ce,e),f(t,1,"hexDecode",Le,e),f(t,1,"add",Re,e),f(t,1,"subtract",Ie,e),f(t,1,"multiply",Be,e),f(t,1,"divide",_e,e),f(t,1,"modulo",Ke,e),f(t,1,"power",We,e),f(t,1,"sqrt",Ne,e),f(t,1,"abs",qe,e),f(t,1,"floor",Ye,e),f(t,1,"ceil",ze,e),f(t,1,"round",He,e),f(t,1,"min",Ge,e),f(t,1,"max",Je,e),f(t,1,"clamp",Ze,e),f(t,1,"random",Qe,e),f(t,1,"timestamp",xe,e),f(t,1,"iso",Xe,e),f(t,1,"utc",Ue,e),f(t,1,"formatDate",Te,e),f(t,1,"parseDate",Ve,e),f(t,1,"year",ve,e),f(t,1,"month",rt,e),f(t,1,"day",et,e),f(t,1,"dayOfWeek",tt,e),f(t,1,"hours",nt,e),f(t,1,"minutes",it,e),f(t,1,"seconds",ot,e),f(t,1,"regexTest",st,e),f(t,1,"regexMatch",at,e),f(t,1,"regexMatchAll",ut,e),f(t,1,"regexReplace",ft,e),f(t,1,"regexReplaceAll",ct,e),f(t,1,"regexSplit",lt,e),f(t,1,"regexExec",mt,e),f(t,1,"regexSearch",pt,e),f(t,1,"unique",gt,e),f(t,1,"groupBy",yt,e),f(t,1,"chunk",ht,e),f(t,1,"flatten",dt,e),f(t,1,"compact",bt,e),f(t,1,"head",wt,e),f(t,1,"tail",Ot,e),f(t,1,"isEmail",At,e),f(t,1,"isUrl",jt,e),f(t,1,"isJson",St,e),f(t,1,"isUuid",Ft,e),f(t,1,"minLength",Et,e),f(t,1,"maxLength",Mt,e),f(t,1,"lengthEquals",$t,e),f(t,1,"isNumber",Dt,e),f(t,1,"isString",Pt,e),f(t,1,"isBoolean",kt,e),f(t,1,"isArray",Ct,e),f(t,1,"isObject",Lt,e),f(t,1,"isEmpty",Rt,e),f(t,1,"isTruthy",It,e),f(t,1,"isFalsy",Bt,e),f(t,1,"inRange",_t,e),f(t,1,"matchesPattern",Kt,e),f(t,1,"includes",Wt,e),f(t,1,"startsWith",Nt,e),f(t,1,"endsWith",qt,e),gr(t,e),e)).keys({...zr(r),...Hr(r),...re(),...ee(),...oe(),...te(),...ne(),...ie(r),...ae(r),...ue(),...fe(),...ce()}).sources({...ge(r),...ye(r),...Ae(),...he(),...de(),...be(),...we(),...Oe(r)}).sections(me(r)).fieldOptions({configParser:Bun.YAML.parse,onSection:(o)=>{if(o.section.config.name)r.section(o.section)}}).decoders({yaml:{matching:["\\.yml$","\\.yaml$"],fn:Bun.YAML.parse}}).encoders({json:{fn:(o)=>JSON.stringify(o,null,2)},yaml:{fn:(o)=>Bun.YAML.stringify(o,null,2)},terraform:{options:{includeTags:!0},fn:(o,m)=>lr(o,0,{sortKeys:!!(m?.sort?.length??m?.sortKeys?.length)})}}).filter(/^\$/)};import jn from"fs/promises";import X from"path";class Sr{includeDirectories=[];baseIncludeDirectories=[];includes=[];addDirectories(...r){this.includeDirectories.push(...r),this.baseIncludeDirectories.push(...r)}getDirectories(){return this.includeDirectories}reset(){this.includeDirectories=[...this.baseIncludeDirectories]}restore(r){this.includeDirectories=[...r]}snapshot(){return[...this.includeDirectories]}addFiles(...r){this.includes.push(...r)}getPendingAndClear(){let r=[...this.includes];return this.includes.length=0,r}async processPatterns(r,e,t){let n=[];for(let i of r)if(K.isGlobPattern(i)){let s=(await Array.fromAsync(jn.glob(i,{cwd:e}))).map((u)=>X.join(e,u));n.push(...s.filter((u)=>!t.included.includes(u)))}else if(K.isDirectoryPattern(i)){let s=X.isAbsolute(i)?i:X.join(e,i);if(!this.includeDirectories.includes(s))this.includeDirectories.push(s)}else n.push(i);return n.unique()}buildSearchDirs(r){let e=r?[r]:[];return e.push(...this.includeDirectories.map((t)=>X.isAbsolute(t)?t:X.join(r??process.cwd(),t))),e}}class Fr{includeManager;loadFn;constructor(r,e){this.includeManager=r;this.loadFn=e}async processIncludes(r,e,t){let n=[];if(r.content.includes)n.push(...r.content.includes),delete r.content.includes;n.push(...this.includeManager.getPendingAndClear());let i=await this.includeManager.processPatterns(n,r.folderPath,t);for(let s of i)Object.merge(await this.loadFn(s,r.folderPath,{parent:r.content,...e},!0,t),r.content)}}class Sn{includeManager=new Sr;includeProcessor;cacheManager=new wr(100);outputs=[];vars={};funcs={};fields={sources:{},keys:{},sections:{}};objectMetadata={};currentContext=null;storedSections={};dataEncoders={};dataDecoders={};constructor(){this.includeProcessor=new Fr(this.includeManager,this.load.bind(this)),this.use(je)}use(r){if(r.prototype instanceof G)new r(this);else r(this);return this}includeDirectory(...r){return this.includeManager.addDirectories(...r),this}getIncludeDirectories(){return this.includeManager.getDirectories()}include(...r){return this.includeManager.addFiles(...r),this}keys(r){return Object.assign(this.fields.keys,{...this.fields.keys,...r}),this}sources(r){return Object.assign(this.fields.sources,{...this.fields.sources,...r}),this}sections(r){return Object.assign(this.fields.sections,{...this.fields.sections,...r}),this}variables(r){return Object.assign(this.vars,{...this.vars,...r}),this}functions(r){return Object.assign(this.funcs,{...this.funcs,...r}),this}onCreateContext(r){return this.fields.onCreateContext=r,this}getFunctions(){return this.funcs}getOutputs(){return this.outputs}output(r){return this.outputs.push(r),this}metadata(r,e){return this.objectMetadata[r]=e,this}getMetadata(r){return this.objectMetadata[r]}getAllMetadata(){return this.objectMetadata}setCacheMaxSize(r){return this.cacheManager.setMaxSize(r),this}clearCache(){return this.cacheManager.clear(),this}getCurrentContext(){return this.currentContext}getDocument(){return this.currentContext?.document||null}fieldOptions(r){return Object.assign(this.fields,{...this.fields,...r}),this}section(r){return this.storedSections[r.config.name]=r,this}getSection(r){return this.storedSections[r]}encoders(r){return Object.assign(this.dataEncoders,{...this.dataEncoders,...r}),this}decoders(r){return Object.assign(this.dataDecoders,{...this.dataDecoders,...r}),this}getEncoder(r){return this.dataEncoders[r]}getDecoder(r){return this.dataDecoders[r]}filter(r){return this.fields.filters??=[],this.fields.filters.push(r),this}async loadObject(r,e,t){return $(r,{...this.fields,globalContext:{file:t?.fullPath??"@internal"},root:{...e,...this.fields.root,...this.vars,functions:this.funcs,context:this.currentContext,sections:this.storedSections,$document:{root:{content:r},fileName:t?.fileName??"@internal",folder:t?.folderPath??"@internal",fullPath:t?.fullPath??"@internal"}}})}async load(r,e,t,n,i){let s=this.includeManager.snapshot();try{this.includeManager.reset();let u=this.includeManager.buildSearchDirs(e);if(i)this.currentContext=i;this.currentContext??={included:[],document:null};let a=typeof r==="string"?await Kr(r,{dirs:u,parsers:this.dataDecoders,format:"yaml"}):{content:r,fullPath:"",folderPath:""};if(typeof r==="string"){let g=K.normalize(a.fullPath);if(this.currentContext.included.push(g),!a.content)return null;let d=this.cacheManager.get(g),p;if(d)p=d.raw;else p=a.content,this.cacheManager.set(g,{raw:p,timestamp:Date.now()});let O=Object.deepClone(p);a.content=O}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(u){throw this.includeManager.restore(s),u}finally{this.includeManager.restore(s)}}async writeAll(r){await qr(this.getOutputs(),r)}}export{qr as writeOutputs,fn as writeOutput,an as writeFormat,qn as variable,Yn as sharedFunction,Wn as section,$ as processFields,J as makeFieldProcessorMap,ki as makeFieldProcessorList,vr as makeFieldProcessor,c as macro,nr as locate,Kr as loadFormat,Nn as key,ln as importList,_n as importGlob,Wr as globMap,ur as getProcessor,Yr as getCwd,Zr as getArgs,br as exists,zn as encoder,Hn as decoder,R as conditionPredicates,H as StringBuilder,G as ObjectorPlugin,Sn as Objector,y as NavigateResult,L as NavigateAction,vt as Markdown,Vt as Logger,rn as CommandLineArgs};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@homedev/objector",
3
- "version": "1.3.12",
3
+ "version": "1.3.13",
4
4
  "description": "object extensions for YAML/JSON",
5
5
  "author": "julzor",
6
6
  "license": "ISC",