@homedev/objector 1.3.3 → 1.3.4

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
@@ -7,28 +7,6 @@ export declare const decoder: (options?: DecoderOptions) => (_: any, ctx: ClassM
7
7
 
8
8
  declare type DecoderOptions = ObjectorDecoratorOptions;
9
9
 
10
- /**
11
- * Guards against undefined and null values.
12
- * Throws an error if the value is nullish, otherwise returns the value.
13
- *
14
- * @param value - The value to check
15
- * @param message - Custom error message (default: 'Value is undefined')
16
- * @returns The value if it is not nullish
17
- * @throws {Error} When value is undefined or null
18
- *
19
- * @example
20
- * ```typescript
21
- * const value = defined(maybeUndefined, 'Required value missing')
22
- * // value is guaranteed to be non-nullish here
23
- *
24
- * defined(0) // 0 (falsy but not nullish)
25
- * defined(false) // false (falsy but not nullish)
26
- * defined(null) // throws Error: Value is undefined
27
- * ```
28
- */
29
- declare function defined_2<T>(value: T | undefined | null, message?: string): T;
30
- export { defined_2 as defined }
31
-
32
10
  declare interface Encoder {
33
11
  fn: (data: unknown, ...args: any[]) => string | Promise<string>;
34
12
  options?: EncoderOptions;
@@ -277,14 +255,15 @@ export declare const makeFieldProcessorMap: <T = unknown>(source: Record<keyof T
277
255
  export declare class Markdown extends StringBuilder {
278
256
  #private;
279
257
  header(text: string, level?: number): this;
280
- codeBlock(code: string, language?: string): this;
258
+ codeBlock(code?: string, language?: string): this;
259
+ endCodeBlock(): this;
281
260
  link(text: string, url: string): this;
282
261
  table(headers: string[], rows: string[][]): this;
283
262
  blockquote(text: string): this;
284
263
  bold(text: string): this;
285
264
  italic(text: string): this;
286
265
  item(text: string): this;
287
- list(items: string[]): this;
266
+ items(items: string[]): this;
288
267
  orderedList(items: string[], start?: number): this;
289
268
  code(text: string): this;
290
269
  horizontalRule(): this;
@@ -514,12 +493,29 @@ declare type SourceFunc = (...args: any[]) => any;
514
493
 
515
494
  export declare class StringBuilder {
516
495
  #private;
517
- constructor(initial?: string | string[]);
518
- append(...args: any[]): this;
519
- appendLine(...args: any[]): this;
496
+ options: StringBuilderOptions;
497
+ constructor(initial?: string | string[] | StringBuilder, options?: StringBuilderOptions);
498
+ setOptions(options: StringBuilderOptions): this;
520
499
  clear(): this;
521
500
  isEmpty(): boolean;
522
501
  toString(): string;
502
+ indent(): this;
503
+ dedent(): this;
504
+ getCurrentIndent(): number;
505
+ getLines(): string[];
506
+ formatLine(line: string): string;
507
+ write(...args: any[]): this;
508
+ writeLine(...args: any[]): this;
509
+ writeMap<T>(items: T[], fn: (item: T, index: number, builder: StringBuilder) => string | StringBuilder): this;
510
+ }
511
+
512
+ export declare interface StringBuilderOptions {
513
+ indentChar?: string;
514
+ indentSize?: number;
515
+ trim?: boolean;
516
+ lineSeparator?: string;
517
+ linePrefix?: string;
518
+ lineSuffix?: string;
523
519
  }
524
520
 
525
521
  export declare const variable: (options?: VariableOptions) => (_: any, ctx: ClassFieldDecoratorContext<ObjectorPlugin, any>) => void;
@@ -571,6 +567,18 @@ declare global {
571
567
  var defined: <T>(value: T | undefined | null, msg?: string) => T;
572
568
  }
573
569
 
570
+ declare global {
571
+ interface ObjectConstructor {
572
+ mapEntries<T extends object, U>(obj: T, callback: (key: keyof T, value: T[keyof T]) => [string | number | symbol, U]): Record<string | number | symbol, U>;
573
+ toList<T extends object, U extends object, X extends string>(obj: T, key: X): (Record<X, string> & U)[];
574
+ deepClone<T extends object>(obj: T): T;
575
+ merge(source: any, target: any, options?: MergeOptions): void;
576
+ navigate(o: any, cb: NavigateCallback): Promise<void>;
577
+ find(from: any, cb: (path: string, value: any) => boolean): Promise<any[]>;
578
+ select(from: any, path: string, options?: SelectOptions): any;
579
+ }
580
+ }
581
+
574
582
  declare global {
575
583
  interface Array<T> {
576
584
  mapAsync<U>(callback: (value: T, index: number, array: T[]) => Promise<U>): Promise<U[]>;
@@ -593,18 +601,6 @@ declare global {
593
601
  }
594
602
  }
595
603
 
596
- declare global {
597
- interface ObjectConstructor {
598
- mapEntries<T extends object, U>(obj: T, callback: (key: keyof T, value: T[keyof T]) => [string | number | symbol, U]): Record<string | number | symbol, U>;
599
- toList<T extends object, U extends object, X extends string>(obj: T, key: X): (Record<X, string> & U)[];
600
- deepClone<T extends object>(obj: T): T;
601
- merge(source: any, target: any, options?: MergeOptions): void;
602
- navigate(o: any, cb: NavigateCallback): Promise<void>;
603
- find(from: any, cb: (path: string, value: any) => boolean): Promise<any[]>;
604
- select(from: any, path: string, options?: SelectOptions): any;
605
- }
606
- }
607
-
608
604
  declare global {
609
605
  interface String {
610
606
  capitalize(): string;
@@ -623,6 +619,12 @@ declare global {
623
619
  stripIndent(): string;
624
620
  toHtmlLink(path?: string): string;
625
621
  toStringBuilder(): StringBuilder;
622
+ toRgb(): string;
623
+ toArgb(): string;
624
+ single(char: string): string;
625
+ remove(char: string): string;
626
+ toAlphanum(): string;
627
+ toAlpha(): string;
626
628
  }
627
629
  }
628
630
 
package/dist/index.js CHANGED
@@ -1,28 +1,26 @@
1
- var qt=Object.create;var kr=Object.defineProperty;var Ht=Object.getOwnPropertyDescriptor;var Dr=(r,e)=>{return Object.defineProperty(r,"name",{value:e,enumerable:!1,configurable:!0}),r};var Cr=(r,e)=>(e=Symbol[r])?e:Symbol.for("Symbol."+r),Y=(r)=>{throw TypeError(r)},Gt=(r,e,t)=>(e in r)?kr(r,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):r[e]=t;var pr=(r,e,t)=>e.has(r)||Y("Cannot "+t),zt=(r,e)=>Object(e)!==e?Y('Cannot use the "in" operator on this value'):r.has(e),Pr=(r,e,t)=>(pr(r,e,"read from private field"),t?t.call(r):e.get(r));var $r=(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),Lr=(r)=>[,,,qt(r?.[Cr("metadata")]??null)],Rr=["class","method","getter","setter","accessor","field","value","get","set"],K=(r)=>r!==void 0&&typeof r!=="function"?Y("Function expected"):r,Zt=(r,e,t,n,o)=>({kind:Rr[r],name:e,metadata:n,addInitializer:(s)=>t._?Y("Already initialized"):o.push(K(s||null))}),lr=(r,e)=>Gt(e,Cr("metadata"),r[3]),Ur=(r,e,t,n)=>{for(var o=0,s=r[e>>1],f=s&&s.length;o<f;o++)e&1?s[o].call(t):n=s[o].call(t,n);return n},u=(r,e,t,n,o,s)=>{var f,a,p,g,h,l=e&7,w=!!(e&8),b=!!(e&16),P=l>3?r.length+1:l?w?1:2:0,O=Rr[l+5],A=l>3&&(r[P-1]=[]),$=r[P]||(r[P]=[]),j=l&&(!b&&!w&&(o=o.prototype),l<5&&(l>3||!b)&&Ht(l<4?o:{get[t](){return Pr(this,s)},set[t](E){$r(this,s,E)}},t));l?b&&l<4&&Dr(s,(l>2?"set ":l>1?"get ":"")+t):Dr(o,t);for(var S=n.length-1;S>=0;S--){if(g=Zt(l,t,p={},r[3],$),l){if(g.static=w,g.private=b,h=g.access={has:b?(E)=>zt(o,E):(E)=>(t in E)},l^3)h.get=b?(E)=>(l^1?Pr:Qt)(E,o,l^4?s:j.get):(E)=>E[t];if(l>2)h.set=b?(E,M)=>$r(E,o,M,l^4?s:j.set):(E,M)=>E[t]=M}if(a=(0,n[S])(l?l<4?b?s:j[O]:l>4?void 0:{get:j.get,set:j.set}:o,g),p._=1,l^4||a===void 0)K(a)&&(l>4?A.unshift(a):l?b?s=a:j[O]=a:o=a);else if(typeof a!=="object"||a===null)Y("Object expected");else K(f=a.get)&&(j.get=f),K(f=a.set)&&(j.set=f),K(f=a.init)&&A.unshift(f)}return l||lr(r,o),j&&kr(o,t,j),b?l^4?s:j:o};import _r from"fs/promises";import yr from"path";import Xt from"fs/promises";import Tt from"path";import xt from"fs/promises";import vt from"fs/promises";import Jr from"fs/promises";import Br from"path";import en from"fs/promises";import gr from"path";import Ir from"path";var hr=async(r)=>{try{return await _r.access(r,_r.constants.R_OK),!0}catch{return!1}},er=async(r,e)=>{let t=!yr.isAbsolute(r)&&e?["",...e]:[""];for(let n of t){let o=yr.join(n,r);if(await hr(o))return yr.resolve(o)}throw Error(`File not found: "${r}"`)},Nr=async(r,e)=>{let t=await er(r,e?.dirs),n=await Xt.readFile(t,"utf-8"),o=Tt.dirname(t),s={text:{fn:(a)=>a,matching:["\\.txt$","\\.text$"]},json:{fn:JSON.parse,matching:["\\.json$"]},...e?.parsers},f=e?.format?s[e.format]:Object.values(s).find((a)=>a.matching?.some((p)=>new RegExp(p).test(r)));if(!f)throw Error(`Unsupported format for file "${r}" and no matching parser found`);return{content:await f.fn(n),fullPath:t,folderPath:o}},Vt=async(r,e,t)=>{let n={text:{fn:(s)=>s,matching:["\\.txt$","\\.text$"]},json:{fn:JSON.stringify,matching:["\\.json$"]},...t?.encoders},o=t?.format?n[t.format]:Object.values(n).find((s)=>s.matching?.some((f)=>new RegExp(f).test(r)));if(!o)throw Error(`Unsupported format for file "${r}" and no matching encoder found`);await xt.writeFile(r,await o.fn(e))},Wr=async(r,e)=>{if(typeof r==="string"&&!r.includes("*"))return await e.map(r,0,[]);let t=await Array.fromAsync(vt.glob(r,{cwd:e.cwd})),n=e.filter?t.filter(e.filter):t;return await Promise.all(n.map(e.map))},Kr=async(r,e)=>{if(e?.targetDirectory&&e?.removeFirst)try{await Jr.rm(e?.targetDirectory,{recursive:!0,force:!0})}catch(t){throw Error(`Failed to clean the output directory: ${t.message}`)}for(let t of r)await rn(t,e)},rn=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 Jr.mkdir(n,{recursive:!0})}catch(o){throw Error(`Failed to create target directory "${n}" for output "${t}": ${o.message}`)}try{await Vt(t,r.value,{format:r.type??"text"})}catch(o){throw Error(`Failed to write output "${t}": ${o.message}`)}},dr=(r)=>r?Ir.isAbsolute(r)?r:Ir.join(process.cwd(),r):process.cwd(),tn=async(r,e)=>{let t=[];for(let n of r)try{let o=!gr.isAbsolute(n)?gr.join(dr(e?.cwd),n):n;if(e?.filter?.(o)===!1)continue;let s=await import(o);if(e?.resolveDefault==="only"&&!s.default)throw Error(`Module ${n} does not have a default export`);let f=e?.resolveDefault?s.default??s:s,a=e?.map?await e.map(f,n):f;if(a!==void 0)t.push(a)}catch(o){if(e?.fail?.(n,o)===!1)continue;throw Error(`Failed to import module ${n}: ${o.message??o}`)}return t},Rn=async(r,e)=>{let t=[];for(let n of r){let o=(await Array.fromAsync(en.glob(n,{cwd:dr(e?.cwd)}))).map((s)=>gr.join(dr(e?.cwd),s));t.push(...await tn(o,e))}return t};class q{o;context;constructor(r){this.o=r}}var c=(r)=>(e,t)=>{t.addInitializer(function(){let n=this[t.name],o=r?.name??t.name;this.o.sources({[o]:(s)=>n.apply({...this,context:s},s.args)})})},_n=(r)=>(e,t)=>{t.addInitializer(function(){let n=this[t.name],o=r?.name??t.name;this.o.sections({[o]:(s)=>{return n.call({...this,context:s},s.section)}})})},Bn=(r)=>(e,t)=>{t.addInitializer(function(){let n=this[t.name],o=r?.name??t.name;this.o.keys({[o]:(s)=>n.call({...this,context:s},s.value)})})},In=(r)=>(e,t)=>{t.addInitializer(function(){let n=this[t.name],o=r?.name??t.name;this.o.variables({[o]:n})})},Nn=(r)=>(e,t)=>{t.addInitializer(function(){let n=this[t.name],o=r?.name??t.name;this.o.functions({[o]:n})})},Wn=(r)=>(e,t)=>{t.addInitializer(function(){let n=this[t.name],o=r?.name??t.name;this.o.encoders({[o]:{fn:n}})})},Jn=(r)=>(e,t)=>{t.addInitializer(function(){let n=this[t.name],o=r?.name??t.name;this.o.decoders({[o]:{fn:n}})})};import{createHash as N}from"crypto";import U from"path";var Yr=(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 nn from"path";var qr=(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&&nn.dirname(t.file))}return y.DeleteItem()}});class br{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 tr=(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 nr=(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};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.toReversed())Object.merge(t,e,r);return e};Array.prototype.toObject=function(r,e){return Object.fromEntries(this.map((t)=>{let n=r(t),o=e?e(t):t;return[n,o]}))};Array.prototype.toObjectWithKey=function(r){return Object.fromEntries(this.map((e)=>[String(e[r]),e]))};Array.prototype.selectFor=function(r,e,t,n){let o=this.find(r,n);if(o===void 0)throw Error(t??"Element not found");return e(o)};Array.prototype.sortBy=function(r,e=!0){return this.slice().sort((t,n)=>{let o=r(t),s=r(n);if(o<s)return e?-1:1;if(o>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=[],o=[],s=async(a,p,g)=>{let h=a===null,l=h?y.Explore():await e({key:a,value:p,path:n,parent:g,parents:o});if(p&&typeof p==="object"&&l.action===0){if(t.has(p))return l;if(t.add(p),!h)n.push(a),o.push(g);let w=p;while(await f(w,a,g))w=g[a];if(!h)o.pop(),n.pop()}return l},f=async(a,p,g)=>{let h=Object.keys(a),l=h.length;for(let w=0;w<l;w++){let b=h[w],P=a[b],O=await s(b,P,a),A=O.action;if(A===0||A===2)continue;if(A===6){if(a[b]=O.by,O.skipSiblings)return;continue}if(A===7){if(delete a[b],O.skipSiblings)return;continue}if(A===1)return;if(A===3){if(p===null)throw Error("Cannot replace root object");if(g[p]=O.by,O.reexplore)return!0;return}if(A===4){if(p===null)throw Error("Cannot delete root object");delete g[p];return}if(A===5)delete a[b],Object.assign(a,O.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 o=e[n],s=r[n];if(typeof s!==typeof o||Array.isArray(s)!==Array.isArray(o)){let a=t?.mismatch?.(n,s,o,r,e);if(a!==void 0){e[n]=a;continue}throw Error(`Type mismatch: ${n}`)}let f=t?.mode?.(n,s,o,r,e)??e[".merge"]??"merge";switch(f){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: ${f}`)}if(typeof s==="object")if(Array.isArray(s))o.push(...s);else{if(t?.navigate?.(n,s,o,r,e)===!1)continue;Object.merge(s,o,t)}else{if(s===o)continue;let a=t?.conflict?.(n,s,o,r,e);e[n]=a===void 0?o:a}}for(let n of Object.keys(r))if(e[n]===void 0)e[n]=r[n]};var on=/^\[([^=\]]*)([=]*)([^\]]*)\]$/,sn=/^([^[\]]*)\[([^\]]*)]$/,wr=(r,e,t,n)=>{if(r.startsWith("{")&&r.endsWith("}")){let o=r.substring(1,r.length-1);return Object.select(e,o,t)?.toString()}return n?r:void 0},an=(r,e,t,n)=>{let o=wr(e,t,n);if(o)return Object.select(r,o,n);let s=on.exec(e);if(s){let[,a,p,g]=s,h=wr(a.trim(),t,n,!0),l=wr(g.trim(),t,n,!0);if(Array.isArray(r)&&(p==="="||p==="==")&&h)return r.find((w)=>w?.[h]==l)}let f=sn.exec(e);if(f){let[,a,p]=f;return r?.[a]?.[p]}return r?.[e]};Object.select=(r,e,t)=>{let n=void 0,o=void 0,s=e??"",f=(l)=>{if(!l)return[l,!1];return l.endsWith("?")?[l.substring(0,l.length-1),!0]:[l,!1]},a=(l,w)=>{let[b,P]=f(w.pop());if(!b){if(t?.set!==void 0&&o!==void 0&&n!==void 0)n[o]=t.set;return l}let O=an(l,b,r,t);if(O===void 0){if(P||t?.optional||t?.defaultValue!==void 0)return;throw Error(`Unknown path element: "${b}" in "${s}"`)}return n=l,o=b,a(O,w)},p=s.splitNested(t?.separator??".","{","}"),g=void 0;if(p.length>0&&p[p.length-1].startsWith("?="))g=p.pop()?.substring(2);p.reverse();let h=a(r,p);if(h===void 0)return g??t?.defaultValue;return h};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,o])=>e(n,o));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 o=r[n];if(o===null||o===void 0)return"";if(typeof o==="string")return o;if(typeof o==="number"||typeof o==="boolean")return String(o);return String(o)})};String.prototype.toPascal=function(){return this.replace(/((?:[_ ]+)\w|^\w)/g,(r,e)=>e.toUpperCase()).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,o=0,s=(f)=>{if(f+n>t)return!1;for(let a=0;a<n;a++)if(this[f+a]!==r[a])return!1;return!0};while(o<t){while(o<t&&this[o]===" ")o++;if(o>=t)break;let f="",a=this[o]==='"'||this[o]==="'";if(a){let p=this[o++];while(o<t&&this[o]!==p)f+=this[o++];if(o<t)o++}else{while(o<t&&!s(o)){let p=this[o];if(p==='"'||p==="'"){f+=p,o++;while(o<t&&this[o]!==p)f+=this[o++];if(o<t)f+=this[o++]}else f+=this[o++]}f=f.trim()}if(f)e.push({value:f,quoted:a});if(s(o))o+=n}return e};String.prototype.splitNested=function(r,e,t){let n=0,o="",s=[];for(let f of this){if(o+=f,f===e)n++;if(f===t)n--;if(n===0&&f===r)s.push(o.slice(0,-1)),o=""}if(o)s.push(o);return s};String.prototype.toStringBuilder=function(){return new Or(this.split(`
1
+ var zt=Object.create;var kr=Object.defineProperty;var qt=Object.getOwnPropertyDescriptor;var $r=(r,e)=>{return Object.defineProperty(r,"name",{value:e,enumerable:!1,configurable:!0}),r};var Cr=(r,e)=>(e=Symbol[r])?e:Symbol.for("Symbol."+r),Y=(r)=>{throw TypeError(r)},Ht=(r,e,t)=>(e in r)?kr(r,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):r[e]=t;var mr=(r,e,t)=>e.has(r)||Y("Cannot "+t),Gt=(r,e)=>Object(e)!==e?Y('Cannot use the "in" operator on this value'):r.has(e),Pr=(r,e,t)=>(mr(r,e,"read from private field"),t?t.call(r):e.get(r));var Dr=(r,e,t,n)=>(mr(r,e,"write to private field"),n?n.call(r,t):e.set(r,t),t),Zt=(r,e,t)=>(mr(r,e,"access private method"),t),Lr=(r)=>[,,,zt(r?.[Cr("metadata")]??null)],Rr=["class","method","getter","setter","accessor","field","value","get","set"],K=(r)=>r!==void 0&&typeof r!=="function"?Y("Function expected"):r,Qt=(r,e,t,n,i)=>({kind:Rr[r],name:e,metadata:n,addInitializer:(s)=>t._?Y("Already initialized"):i.push(K(s||null))}),gr=(r,e)=>Ht(e,Cr("metadata"),r[3]),Ir=(r,e,t,n)=>{for(var i=0,s=r[e>>1],f=s&&s.length;i<f;i++)e&1?s[i].call(t):n=s[i].call(t,n);return n},u=(r,e,t,n,i,s)=>{var f,a,p,y,d,m=e&7,w=!!(e&8),b=!!(e&16),P=m>3?r.length+1:m?w?1:2:0,O=Rr[m+5],A=m>3&&(r[P-1]=[]),D=r[P]||(r[P]=[]),j=m&&(!b&&!w&&(i=i.prototype),m<5&&(m>3||!b)&&qt(m<4?i:{get[t](){return Pr(this,s)},set[t](F){Dr(this,s,F)}},t));m?b&&m<4&&$r(s,(m>2?"set ":m>1?"get ":"")+t):$r(i,t);for(var E=n.length-1;E>=0;E--){if(y=Qt(m,t,p={},r[3],D),m){if(y.static=w,y.private=b,d=y.access={has:b?(F)=>Gt(i,F):(F)=>(t in F)},m^3)d.get=b?(F)=>(m^1?Pr:Zt)(F,i,m^4?s:j.get):(F)=>F[t];if(m>2)d.set=b?(F,M)=>Dr(F,i,M,m^4?s:j.set):(F,M)=>F[t]=M}if(a=(0,n[E])(m?m<4?b?s:j[O]:m>4?void 0:{get:j.get,set:j.set}:i,y),p._=1,m^4||a===void 0)K(a)&&(m>4?A.unshift(a):m?b?s=a:j[O]=a:i=a);else if(typeof a!=="object"||a===null)Y("Object expected");else K(f=a.get)&&(j.get=f),K(f=a.set)&&(j.set=f),K(f=a.init)&&A.unshift(f)}return m||gr(r,i),j&&kr(i,t,j),b?m^4?s:j:i};import Br from"fs/promises";import yr from"path";import Xt from"fs/promises";import Tt from"path";import xt from"fs/promises";import vt from"fs/promises";import Jr from"fs/promises";import Ur from"path";import en from"fs/promises";import hr from"path";import _r from"path";var br=async(r)=>{try{return await Br.access(r,Br.constants.R_OK),!0}catch{return!1}},tr=async(r,e)=>{let t=!yr.isAbsolute(r)&&e?["",...e]:[""];for(let n of t){let i=yr.join(n,r);if(await br(i))return yr.resolve(i)}throw Error(`File not found: "${r}"`)},Nr=async(r,e)=>{let t=await tr(r,e?.dirs),n=await Xt.readFile(t,"utf-8"),i=Tt.dirname(t),s={text:{fn:(a)=>a,matching:["\\.txt$","\\.text$"]},json:{fn:JSON.parse,matching:["\\.json$"]},...e?.parsers},f=e?.format?s[e.format]:Object.values(s).find((a)=>a.matching?.some((p)=>new RegExp(p).test(r)));if(!f)throw Error(`Unsupported format for file "${r}" and no matching parser found`);return{content:await f.fn(n),fullPath:t,folderPath:i}},Vt=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)=>s.matching?.some((f)=>new RegExp(f).test(r)));if(!i)throw Error(`Unsupported format for file "${r}" and no matching encoder found`);await xt.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(vt.glob(r,{cwd:e.cwd})),n=e.filter?t.filter(e.filter):t;return await Promise.all(n.map(e.map))},Kr=async(r,e)=>{if(e?.targetDirectory&&e?.removeFirst)try{await Jr.rm(e?.targetDirectory,{recursive:!0,force:!0})}catch(t){throw Error(`Failed to clean the output directory: ${t.message}`)}for(let t of r)await rn(t,e)},rn=async(r,e)=>{let t=Ur.join(e?.targetDirectory??".",r.name),n=Ur.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 Jr.mkdir(n,{recursive:!0})}catch(i){throw Error(`Failed to create target directory "${n}" for output "${t}": ${i.message}`)}try{await Vt(t,r.value,{format:r.type??"text"})}catch(i){throw Error(`Failed to write output "${t}": ${i.message}`)}},dr=(r)=>r?_r.isAbsolute(r)?r:_r.join(process.cwd(),r):process.cwd(),tn=async(r,e)=>{let t=[];for(let n of r)try{let i=!hr.isAbsolute(n)?hr.join(dr(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 f=e?.resolveDefault?s.default??s:s,a=e?.map?await e.map(f,n):f;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}`)}return t},Rn=async(r,e)=>{let t=[];for(let n of r){let i=(await Array.fromAsync(en.glob(n,{cwd:dr(e?.cwd)}))).map((s)=>hr.join(dr(e?.cwd),s));t.push(...await tn(i,e))}return t};class z{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)})})},Bn=(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)}})})},Un=(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)})})},_n=(r)=>(e,t)=>{t.addInitializer(function(){let n=this[t.name],i=r?.name??t.name;this.o.variables({[i]:n})})},Nn=(r)=>(e,t)=>{t.addInitializer(function(){let n=this[t.name],i=r?.name??t.name;this.o.functions({[i]:n})})},Wn=(r)=>(e,t)=>{t.addInitializer(function(){let n=this[t.name],i=r?.name??t.name;this.o.encoders({[i]:{fn:n}})})},Jn=(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 N}from"crypto";import I from"path";var Yr=(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 g.SkipSiblings()}});import nn from"path";var zr=(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&&nn.dirname(t.file))}return g.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 nr=(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 ir=(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};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.toReversed())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 g{action;by;skipSiblings;reexplore;constructor(r,e,t,n){this.action=r,this.by=e,this.skipSiblings=t,this.reexplore=n}static _explore=new g(0);static _noExplore=new g(2);static _skipSiblings=new g(1);static _deleteParent=new g(4);static ReplaceParent(r,e){return new g(3,r,void 0,e)}static SkipSiblings(){return g._skipSiblings}static Explore(){return g._explore}static NoExplore(){return g._noExplore}static DeleteParent(){return g._deleteParent}static MergeParent(r){return new g(5,r)}static ReplaceItem(r,e){return new g(6,r,e)}static DeleteItem(r){return new g(7,void 0,r)}}Object.navigate=async(r,e)=>{let t=new WeakSet,n=[],i=[],s=async(a,p,y)=>{let d=a===null,m=d?g.Explore():await e({key:a,value:p,path:n,parent:y,parents:i});if(p&&typeof p==="object"&&m.action===0){if(t.has(p))return m;if(t.add(p),!d)n.push(a),i.push(y);let w=p;while(await f(w,a,y))w=y[a];if(!d)i.pop(),n.pop()}return m},f=async(a,p,y)=>{let d=Object.keys(a),m=d.length;for(let w=0;w<m;w++){let b=d[w],P=a[b],O=await s(b,P,a),A=O.action;if(A===0||A===2)continue;if(A===6){if(a[b]=O.by,O.skipSiblings)return;continue}if(A===7){if(delete a[b],O.skipSiblings)return;continue}if(A===1)return;if(A===3){if(p===null)throw Error("Cannot replace root object");if(y[p]=O.by,O.reexplore)return!0;return}if(A===4){if(p===null)throw Error("Cannot delete root object");delete y[p];return}if(A===5)delete a[b],Object.assign(a,O.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 g.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 f=t?.mode?.(n,s,i,r,e)??e[".merge"]??"merge";switch(f){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: ${f}`)}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 on=/^\[([^=\]]*)([=]*)([^\]]*)\]$/,sn=/^([^[\]]*)\[([^\]]*)]$/,Or=(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},an=(r,e,t,n)=>{let i=Or(e,t,n);if(i)return Object.select(r,i,n);let s=on.exec(e);if(s){let[,a,p,y]=s,d=Or(a.trim(),t,n,!0),m=Or(y.trim(),t,n,!0);if(Array.isArray(r)&&(p==="="||p==="==")&&d)return r.find((w)=>w?.[d]==m)}let f=sn.exec(e);if(f){let[,a,p]=f;return r?.[a]?.[p]}return r?.[e]};Object.select=(r,e,t)=>{let n=void 0,i=void 0,s=e??"",f=(m)=>{if(!m)return[m,!1];return m.endsWith("?")?[m.substring(0,m.length-1),!0]:[m,!1]},a=(m,w)=>{let[b,P]=f(w.pop());if(!b){if(t?.set!==void 0&&i!==void 0&&n!==void 0)n[i]=t.set;return m}let O=an(m,b,r,t);if(O===void 0){if(P||t?.optional||t?.defaultValue!==void 0)return;throw Error(`Unknown path element: "${b}" in "${s}"`)}return n=m,i=b,a(O,w)},p=s.splitNested(t?.separator??".","{","}"),y=void 0;if(p.length>0&&p[p.length-1].startsWith("?="))y=p.pop()?.substring(2);p.reverse();let d=a(r,p);if(d===void 0)return y??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=(f)=>{if(f+n>t)return!1;for(let a=0;a<n;a++)if(this[f+a]!==r[a])return!1;return!0};while(i<t){while(i<t&&this[i]===" ")i++;if(i>=t)break;let f="",a=this[i]==='"'||this[i]==="'";if(a){let p=this[i++];while(i<t&&this[i]!==p)f+=this[i++];if(i<t)i++}else{while(i<t&&!s(i)){let p=this[i];if(p==='"'||p==="'"){f+=p,i++;while(i<t&&this[i]!==p)f+=this[i++];if(i<t)f+=this[i++]}else f+=this[i++]}f=f.trim()}if(f)e.push({value:f,quoted:a});if(s(i))i+=n}return e};String.prototype.splitNested=function(r,e,t){let n=0,i="",s=[];for(let f of this){if(i+=f,f===e)n++;if(f===t)n--;if(n===0&&f===r)s.push(i.slice(0,-1)),i=""}if(i)s.push(i);return s};String.prototype.toStringBuilder=function(){return new q(this.split(`
2
2
  `))};String.prototype.padBlock=function(r,e=`
3
- `,t=" "){let n=t.repeat(r);return this.split(e).map((o)=>n+o).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
- `)};String.prototype.toHtmlLink=function(r){return`<a href="${r??this.toString()}">${this.toString()}</a>`};function Vn(r,e="Value is undefined"){if(r===void 0||r===null)throw Error(e);return r}class fn{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 o=this.options.levels.indexOf(this.options.level)??-1,s=this.options.levels.indexOf(r);if(s===-1)throw Error(`Unknown log level: ${r}`);if(s<o)return}let t=[],n=[];if(this.options.timeStamp)n.push(new Date().toLocaleString(this.options.timeLocale,this.options.timeOptions));if(this.options.showClass)n.push(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 Or{#r=[];constructor(r){if(r)if(Array.isArray(r))this.#r.push(...r);else this.#r.push(r)}append(...r){return this.#r.push(...r),this}appendLine(...r){return this.append(...r.map((e)=>{if(e===null||e===void 0)return`
5
- `;return`${e.toString()}
6
- `})),this}clear(){return this.#r.length=0,this}isEmpty(){return this.#r.length===0}toString(){return this.#r.join("")}}class un extends Or{header(r,e=1){return this.appendLine(`${"#".repeat(e)} ${r}`)}codeBlock(r,e=""){return this.appendLine(`\`\`\`${e}
7
- ${r}
8
- \`\`\``)}link(r,e){return this.append(`[${r}](${e})`)}table(r,e){let t=r.map((s,f)=>{let a=s.length;return e.forEach((p)=>{if(p[f])a=Math.max(a,p[f].length)}),a}),n=r.map((s,f)=>s.padEnd(t[f]));this.appendLine("| "+n.join(" | ")+" |");let o=t.map((s)=>"-".repeat(s));return this.appendLine("| "+o.join(" | ")+" |"),e.forEach((s)=>{let f=s.map((a,p)=>a.padEnd(t[p]));this.appendLine("| "+f.join(" | ")+" |")}),this}blockquote(r){let e=r.split(`
9
- `);this.appendLine("> "+e[0]);for(let t=1;t<e.length;t++)this.appendLine("> "+e[t]);return this}bold(r){return this.append(`**${r}**`)}italic(r){return this.append(`*${r}*`)}item(r){return this.appendLine(`- ${r}`)}list(r){return r.forEach((e)=>this.item(e)),this}orderedList(r,e=1){return r.forEach((t,n)=>this.appendLine(`${(n+e).toString()}. ${t}`)),this}code(r){return this.append(`\`${r}\``)}horizontalRule(){return this.appendLine("---")}image(r,e){return this.appendLine(`![${r}](${e})`)}strikethrough(r){return this.append(`~~${r}~~`)}highlight(r){return this.append(`==${r}==`)}subscript(r){return this.append(`~${r}~`)}superscript(r){return this.append(`^${r}^`)}taskList(r){return r.forEach((e)=>this.appendLine(`- [${e.checked?"x":" "}] ${e.text}`)),this}#r=0;section(r){return this.#r++,this.header(r,this.#r)}endSection(){if(this.#r>0)this.#r--;return this}setSectionLevel(r){return this.#r=r,this}}var Hr=(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 o=n.trim();if(!isNaN(+o))return+o;return o})}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)},or=(r,e,t,n,o,s)=>{let f=n?.(r)??r,a=o(f);if(a[0])return a[1];if(!e){let p=Object.select(t,r),g=o(p);if(g[0])return g[1]}throw Error(s)},ir=(r,e,t,n,o)=>{let s=typeof r.types==="function"?r.types(n,e.value,o):r.types?.[n];if(!s||s==="ref")return Hr(e,(a)=>Object.select(t,a));let f=Hr(e,()=>e.value);if(Array.isArray(s)){if(!s.includes(f))throw Error(`Argument ${n.toString()} must be one of [${s.join(", ")}]: ${f}`);return f}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 f;case"array":return or(f,e.quoted,t,null,(a)=>[Array.isArray(a),a],`Argument ${n.toString()} must be an array: ${f}`);case"object":return or(f,e.quoted,t,null,(a)=>[typeof a==="object"&&a!==null,a],`Argument ${n.toString()} must be an object: ${f}`);case"number":return or(f,e.quoted,t,(a)=>Number(a),(a)=>[!isNaN(a),a],`Argument ${n.toString()} must be a number: ${f}`);case"boolean":return or(f,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: ${f}`);case"string":return f.toString();default:throw Error(`Unknown type for argument ${n.toString()}: ${s}`)}}return s(f,t,n,e.quoted)};var sr=(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}},Gr=(r)=>!r.quoted&&r.value.startsWith("."),cn=(r)=>{let e={};for(let t of r){if(!Gr(t))continue;let n=t.value.indexOf("="),o=n>-1?t.value.slice(1,n):t.value.slice(1),s=n>-1?t.value.slice(n+1):"";if(s.length>=2){let f=s[0],a=s[s.length-1];if(f==='"'&&a==='"'||f==="'"&&a==="'")s=s.slice(1,-1)}if(!e[o])e[o]=[];e[o].push(s)}return e},zr=(r,e,t)=>{let n=(r??"").splitWithQuotes(),o=cn(n),s=n.filter((a)=>!Gr(a)),f=e.options.processArgs===!1?[]:s.map((a,p)=>ir(e.options,a,t,p,s));return{rawArgs:s,parsedArgs:f,tags:o}};var mn=(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,Zr=async(r,e,t,n)=>{let{key:o,parent:s}=r,f=sr(n.keys,o.substring(1));if(f.options.processArgs!==!1&&(typeof f.options.types==="function"||f.options.types?.[0]!==void 0))r.value=ir(f.options,{value:r.value,quoted:!1},t,0,[]);if(typeof r.value!=="string")await D(r.value,{...n,root:{...t,parent:r.parent,parents:r.parents},filters:[...n.filters??[],...f.options.filters??[]]});let a=await f.fn({path:e,root:t,parent:s,key:o,options:n,value:r.value,args:[],rawArgs:[],tags:{}});return mn(a)?a:y.ReplaceParent(a)};var Xr=async(r,e,t,n)=>{if(!e?.onSection&&!e?.onSectionConfig&&!e?.sections)return[r,!1];let o=/<@\s*section(?:\s*:\s*([\w-]+))?\s*@>([\s\S]*?)<@\s*\/\s*section\s*@>/g,s,f=r,a=0,p=!1,g={content:f,root:n,path:t,options:e,section:{}};while((s=o.exec(r))!==null){p=!0;let[h,l,w]=s,b=s.index,P=b+h.length,O=r[P]===`
10
- `;if(O)P++;let A=b+a,$=P+a,j={},S=w,E=/(^|\r?\n)[ \t]*---[ \t]*(\r?\n|$)/m.exec(w);if(E){let W=w.slice(0,E.index),cr=E.index+E[0].length;S=w.slice(cr);let v=W.stripIndent().trim();if(v.length>0)try{j=e?.configParser?.(v)??{}}catch(mr){throw Error(`Failed to parse YAML config for section: ${mr.message}`)}}else if(/^\r?\n/.test(S))S=S.replace(/^\r?\n/,"");S=S.stripIndent().replace(/(?:\r?\n[ \t]*)+$/,"").replace(/[ \t]+$/,"");let M={config:l?{...j,type:l}:j,content:S};if(g.content=f,g.section=M,Object.keys(M.config).length>0){if(await e.onSectionConfig?.(g)!==!1)await D(M.config,{...e,root:n})}let X=g.section.config.type?e.sections?.[g.section.config.type]:void 0,_;if(X)_=await X(g);else if(e.onSection)_=await e.onSection(g);if(M.trim)M.content=M.content.trim();if(M.indent)M.content=M.content.split(`
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
+ `)};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(){return this.replace(/[^a-z0-9]/gi,"")};String.prototype.toAlpha=function(){return this.replace(/[^a-z]/gi,"")};class fn{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)??-1,s=this.options.levels.indexOf(r);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 q{#r=[];#e=0;options;constructor(r,e){if(r instanceof q)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(`
5
+ `)}formatLine(r){let e=(this.options.indentChar??" ").repeat(this.#e*(this.options.indentSize??2));if(this.options.trim)r=r.trim();return(this.options.linePrefix??"")+e+r+(this.options.lineSuffix??"")}write(...r){return this.#r.push(...r.flatMap((e)=>{if(e===void 0)return;if(typeof e==="string")return e;if(e instanceof q)return e.toString();if(typeof e==="function")return e(this);return String(e)}).filter((e)=>e!==void 0)),this}writeLine(...r){return this.write(...r.flatMap((e)=>{return[this.formatLine(e),this.options.lineSeparator??`
6
+ `]}))}writeMap(r,e){return r.forEach((t,n)=>this.write(e(t,n,this))),this}}class un extends q{header(r,e=1){return this.writeLine(`${"#".repeat(e)} ${r}`)}codeBlock(r,e){if(this.write("```"),e!==void 0)this.write(e);if(r!==void 0)this.writeLine("",r).endCodeBlock();return this}endCodeBlock(){return this.writeLine("```")}link(r,e){return this.write(`[${r}](${e})`)}table(r,e){let t=r.map((s,f)=>{let a=s.length;return e.forEach((p)=>{if(p[f])a=Math.max(a,p[f].length)}),a}),n=r.map((s,f)=>s.padEnd(t[f]));this.writeLine("| "+n.join(" | ")+" |");let i=t.map((s)=>"-".repeat(s));return this.writeLine("| "+i.join(" | ")+" |"),e.forEach((s)=>{let f=s.map((a,p)=>a.padEnd(t[p]));this.writeLine("| "+f.join(" | ")+" |")}),this}blockquote(r){let e=r.split(`
7
+ `);this.writeLine("> "+e[0]);for(let t=1;t<e.length;t++)this.writeLine("> "+e[t]);return this}bold(r){return this.write(`**${r}**`)}italic(r){return this.write(`*${r}*`)}item(r){return this.writeLine(`- ${r}`)}items(r){return r.forEach((e)=>this.item(e)),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}#r=0;section(r){return this.#r++,this.header(r,this.#r)}endSection(){if(this.#r>0)this.#r--;return this}setSectionLevel(r){return this.#r=r,this}}var qr=(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)},or=(r,e,t,n,i,s)=>{let f=n?.(r)??r,a=i(f);if(a[0])return a[1];if(!e){let p=Object.select(t,r),y=i(p);if(y[0])return y[1]}throw Error(s)},sr=(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 qr(e,(a)=>Object.select(t,a));let f=qr(e,()=>e.value);if(Array.isArray(s)){if(!s.includes(f))throw Error(`Argument ${n.toString()} must be one of [${s.join(", ")}]: ${f}`);return f}if(typeof s==="string"){if(s.endsWith("?")){let a=s.slice(0,-1);if(e.value==="null")return g.ReplaceItem(null);if(e.value==="undefined")return g.ReplaceItem(void 0);if(e.value==="")return"";s=a}switch(s){case"any":return f;case"array":return or(f,e.quoted,t,null,(a)=>[Array.isArray(a),a],`Argument ${n.toString()} must be an array: ${f}`);case"object":return or(f,e.quoted,t,null,(a)=>[typeof a==="object"&&a!==null,a],`Argument ${n.toString()} must be an object: ${f}`);case"number":return or(f,e.quoted,t,(a)=>Number(a),(a)=>[!isNaN(a),a],`Argument ${n.toString()} must be a number: ${f}`);case"boolean":return or(f,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: ${f}`);case"string":return f.toString();default:throw Error(`Unknown type for argument ${n.toString()}: ${s}`)}}return s(f,t,n,e.quoted)};var ar=(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}},Hr=(r)=>!r.quoted&&r.value.startsWith("."),cn=(r)=>{let e={};for(let t of r){if(!Hr(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 f=s[0],a=s[s.length-1];if(f==='"'&&a==='"'||f==="'"&&a==="'")s=s.slice(1,-1)}if(!e[i])e[i]=[];e[i].push(s)}return e},Gr=(r,e,t)=>{let n=(r??"").splitWithQuotes(),i=cn(n),s=n.filter((a)=>!Hr(a)),f=e.options.processArgs===!1?[]:s.map((a,p)=>sr(e.options,a,t,p,s));return{rawArgs:s,parsedArgs:f,tags:i}};var ln=(r)=>{return r!==null&&typeof r==="object"&&"action"in r},Zr=(r,e)=>e.keys!==void 0&&r.key.startsWith(".")&&e.keys[r.key.substring(1)]!==void 0,Qr=async(r,e,t,n)=>{let{key:i,parent:s}=r,f=ar(n.keys,i.substring(1));if(f.options.processArgs!==!1&&(typeof f.options.types==="function"||f.options.types?.[0]!==void 0))r.value=sr(f.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??[],...f.options.filters??[]]});let a=await f.fn({path:e,root:t,parent:s,key:i,options:n,value:r.value,args:[],rawArgs:[],tags:{}});return ln(a)?a:g.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,f=r,a=0,p=!1,y={content:f,root:n,path:t,options:e,section:{}};while((s=i.exec(r))!==null){p=!0;let[d,m,w]=s,b=s.index,P=b+d.length,O=r[P]===`
8
+ `;if(O)P++;let A=b+a,D=P+a,j={},E=w,F=/(^|\r?\n)[ \t]*---[ \t]*(\r?\n|$)/m.exec(w);if(F){let W=w.slice(0,F.index),lr=F.index+F[0].length;E=w.slice(lr);let rr=W.stripIndent().trim();if(rr.length>0)try{j=e?.configParser?.(rr)??{}}catch(pr){throw Error(`Failed to parse YAML config for section: ${pr.message}`)}}else if(/^\r?\n/.test(E))E=E.replace(/^\r?\n/,"");E=E.stripIndent().replace(/(?:\r?\n[ \t]*)+$/,"").replace(/[ \t]+$/,"");let M={config:m?{...j,type:m}:j,content:E};if(y.content=f,y.section=M,Object.keys(M.config).length>0){if(await e.onSectionConfig?.(y)!==!1)await $(M.config,{...e,root:n})}let T=y.section.config.type?e.sections?.[y.section.config.type]:void 0,B;if(T)B=await T(y);else if(e.onSection)B=await e.onSection(y);if(M.trim)M.content=M.content.trim();if(M.indent)M.content=M.content.split(`
11
9
  `).map((W)=>" ".repeat(M.indent)+W).join(`
12
- `);let C="";if(_===!0||M.show)C=M.content;else if(typeof _==="string")C=_;if(O&&C!==""&&!C.endsWith(`
10
+ `);let C="";if(B===!0||M.show)C=M.content;else if(typeof B==="string")C=B;if(O&&C!==""&&!C.endsWith(`
13
11
  `))C+=`
14
- `;let T=f.lastIndexOf(`
15
- `,A-1),x=T===-1?0:T+1,V=f.slice(x,A).trim().length===0?x:A;f=f.slice(0,V)+C+f.slice($),a+=C.length-($-V),g.content=f}return[f,p]};var jr=(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 o=1;for(;t<r.length;t++)if(r[t]==="(")o++;else if(r[t]===")"){if(o--,o===0){e.push([n,t]);break}}if(o!==0)throw Error(`Unmatched opening $( at position ${n.toString()}`);t++}else t++;return e};var Tr=(r)=>({value:r}),pn=(r)=>{return r!==null&&typeof r==="object"},xr=async(r,e,t)=>{for(let n=e.length-1;n>=0;n--){let[o,s]=e[n],f=r.slice(o+2,s),a=await xr(f,jr(f),t);if(typeof a==="object")return a;let p=await t(a,r);if(pn(p))return p.value;r=r.slice(0,o)+p+r.slice(s+1)}return r},Vr=async(r,e)=>xr(r,jr(r),e);var ln=(r)=>{return r!==null&&typeof r==="object"&&"action"in r},yn=/([\w\d.-_/]+):(.+)/,gn=async(r,e,t,n)=>{let o=await(async()=>{let s=yn.exec(r);if(!s)return await Object.select(e,r);let[f,a,p]=s,g=sr(n.sources,a),h=zr(p,g,e);return await g.fn({args:h.parsedArgs,rawArgs:h.rawArgs,tags:h.tags,key:a,options:n,root:e,path:t,value:null})})();if(o===null||o===void 0)return"";if(typeof o==="object")return Tr(o);return o},Ar=async(r,e,t,n)=>{let o=await Vr(e,(s)=>gn(s,t,r,n));if(ln(o))return o;if(o===e)return y.Explore();if(typeof o==="string"){let s=await Ar(r,o,t,n);if(s.action!==L.Explore)return s}return y.ReplaceItem(o)};var D=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 o=t.path.length===0,s=t.parents.length>0?t.parents.toReversed():[];if(o){if(s.length>0)throw Error("Root object should not have a parent");s=e?.root?.parents?[e.root.parent,...e.root.parents.toReversed()]:[]}let f={...r,...e.root,this:t.parent,parent:s.length>0?s[0]:null,parents:s};try{if(t.key.startsWith("$"))return y.NoExplore();let a=y.Explore();if(typeof t.value==="string"){let p=t.value,g=!1;while(!0){let[h,l]=await Xr(p,e,n,f);if(g=g||l,a=await Ar(n,h,f,e),a.action===L.ReplaceItem&&typeof a.by==="string"){p=a.by;continue}if(a.action===L.Explore&&l&&h!==p)a=y.ReplaceItem(h);break}if(a.action===L.Explore&&p!==t.value)a=y.ReplaceItem(p);switch(a.action){case L.Explore:break;case L.ReplaceItem:t.value=a.by;break;default:return a}}if(Qr(t,e))a=await Zr(t,n,f,e);return a}catch(a){throw Error(`${a.message}
16
- (${n})`)}}),r};var vr=(r,e)=>e?{fn:(t)=>r(...t.args),types:e}:(t)=>r(...t.args),ko=(r,e)=>Object.fromEntries(r.map((t)=>[t.name,vr(t,e?.types?.[t.name])])),H=(r,e)=>Object.fromEntries((e?.keys??Object.keys(r)).map((t)=>[t,vr(r[t],e?.types?.[t])]));var ar=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 D(n,{...r.options,root:{...r.root,result:e}}),n}return await Object.select({...r.root,result:e},t.selector)};import B from"path";class I{constructor(){}static normalize(r){return B.normalize(B.resolve(r))}static resolveInContext(r,e){let t=e??process.cwd(),n=B.isAbsolute(r)?r:B.join(t,r);return this.normalize(n)}static isDirectoryPattern(r){return r.endsWith("/")}static isGlobPattern(r){return r.includes("*")}static toAbsolute(r,e){if(B.isAbsolute(r))return r;return B.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!=="")},fr={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 nr(r),n=await tr(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 o=[];for(let s=0;s<t.length;s++){let f=Object.deepClone(n);if(await D(f,{...r.options,root:{...r.root,index:s,item:t[s],instance:f}}),e.extend?.result){let a=e.extend.result;f=[f,...Array.isArray(a)?a:[a]].mergeAll()}o.push(await ar(r,f))}return o}}});var ee=()=>({map:{filters:[/select|model/],fn:async(r)=>{delete r.parent[r.key];let e=await nr(r),t=await tr(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(o,s)=>{let f=Object.deepClone(t);await D(f,{...r.options,root:{...r.root,index:s,item:o,instance:f}}),n.push(await ar(r,f))}),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 o of Array.isArray(n)?n:[n]){let s=await Object.select(r.root,o),f=Object.deepClone(s);if(f[r.key])await e(f,f[r.key]);await D(f,{...r.options}),Object.merge(f,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,...o}=t;return t.items.forEach((s)=>e.push({...o,...s})),y.DeleteParent()}});var oe=(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 o=e.value?t:n;if(o===void 0)return y.DeleteItem();if(typeof o==="string")return(await D({value:o},{...e.options,root:{...e.root}})).value;return y.ReplaceParent(o,!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 ie=()=>({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 o=se.createContext({console,objector:r,document:e.root}),s=new se.SourceTextModule(n,{identifier:t,context:o});await s.link((f)=>{throw Error(`Module ${f} is not allowed`)}),await s.evaluate(),r.sources(Object.fromEntries(Object.entries(s.namespace).map(([f,a])=>[`${t}.${f}`,(p)=>a(p,...p.args)])))}return y.DeleteItem()}});var fe=()=>({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 ue=()=>({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 dn=(r,e)=>{let t=e.section.config.using,n=r.getFunctions();if(!t)return n;let o={};return t.forEach((s)=>{if(s in n){o[s]=n[s];return}if(s in e.root){o[s]=e.root[s];return}throw Error(`Function or variable "${s}" not found for script section`)}),o},Fr=(r,e,t,n,o=[])=>{let s=dn(r,t),f=["section","context","config","system",...Object.keys(s),...o],a=[e,t.root,t.section.config,r,...Object.values(s)];return[new AsyncFunction(...f,n).bind(t),a]},hn=(r,e)=>{let t={write:(...n)=>{return e.push(...n),t},writeLine:(...n)=>{return e.push(...n.map((o)=>o+`
17
- `)),t},clear:()=>{return e.splice(0,e.length),t},prepend:(...n)=>{return e.unshift(...n),t},prependLine:(...n)=>{return e.unshift(...n.map((o)=>o+`
18
- `)),t},setOptions:(n)=>{return Object.assign(r.section,n),t},use:(n)=>{return n(t),t},getLines:()=>e};return t},bn=async(r,e,t)=>{let n=t.section.config.condition;if(n!==void 0){let[o,s]=Fr(r,e,t,`return (${n})`);if(!await o(...s))return!1}return!0},me=(r)=>async(e)=>{let t=[],n=hn(e,t);if(!await bn(r,n,e))return!1;let[o,s]=Fr(r,n,e,e.section.content,["item"]),f=e.section.config.each;if(f){let[a,p]=Fr(r,n,e,`return (${f})`),g=Array.isArray(f)?f:await a(...p);if(!Array.isArray(g))throw Error('The "each" property of a script section must return an array');for(let h of g){let l=await o(...s,h);if(typeof l<"u")t.push(l)}}else{let a=await o(...s);if(typeof a<"u")return a}if(t.length===0)return!1;return t.join("")};var pe=(r)=>({script:me(r)});import le from"fs/promises";import G from"path";var ye=(r)=>({include:async(e)=>{let{file:t}=e.options.globalContext;return await Wr(e.args[0],{cwd:G.dirname(t),filter:(n)=>G.basename(t)!==n,map:async(n)=>r.load(n,G.dirname(t),e.root)})},exists:async({args:[e]})=>await hr(e),file:async(e)=>await le.readFile(await er(e.args[0],r.getIncludeDirectories())).then((t)=>t.toString()),scan:async(e)=>{let t=[],o=(()=>{let a=e.args[2]??["**/node_modules/**"],p=typeof a==="string"?a.split(",").map((g)=>g.trim()):a;if(!Array.isArray(p))throw Error("Scan exclusion must be a list");return p})(),{file:s}=e.options.globalContext,f=e.args[1]?await er(e.args[1],r.getIncludeDirectories()):G.dirname(s);for await(let a of le.glob(e.args[0],{cwd:f,exclude:(p)=>o.some((g)=>G.matchesGlob(p,g))}))t.push(a);return t}});var ge=(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 o=n.join?.[0]??`
19
- `,s=n.padChar?.[0]??" ";return e.padBlock(t??2,o,s)}},formatAs:{fn:({args:[e,t],tags:n})=>{let o=r.getEncoder(t);if(!o)throw Error("Unsupported format: "+String(t));let s=[];if(o.options?.includeTags)s=[n];return o.fn(e,...s)}}});var ur=(r,e=0,t)=>{let n=" ".repeat(e),o=" ".repeat(e+1);if(r===null||r===void 0)return"null";else if(typeof r==="boolean")return String(r);else if(typeof r==="number")return String(r);else if(typeof r==="string")return`"${r.replace(/\\/g,"\\\\").replace(/"/g,"\\\"").replace(/\n/g,"\\n").replace(/\r/g,"\\r").replace(/\t/g,"\\t")}"`;else if(Array.isArray(r)){if(r.length===0)return"[]";return`[
20
- ${r.map((f)=>`${o}${ur(f,e+1)},`).join(`
12
+ `;let x=f.lastIndexOf(`
13
+ `,A-1),V=x===-1?0:x+1,v=f.slice(V,A).trim().length===0?V:A;f=f.slice(0,v)+C+f.slice(D),a+=C.length-(D-v),y.content=f}return[f,p]};var jr=(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 Tr=(r)=>({value:r}),pn=(r)=>{return r!==null&&typeof r==="object"},xr=async(r,e,t)=>{for(let n=e.length-1;n>=0;n--){let[i,s]=e[n],f=r.slice(i+2,s),a=await xr(f,jr(f),t);if(typeof a==="object")return a;let p=await t(a,r);if(pn(p))return p.value;r=r.slice(0,i)+p+r.slice(s+1)}return r},Vr=async(r,e)=>xr(r,jr(r),e);var mn=(r)=>{return r!==null&&typeof r==="object"&&"action"in r},gn=/([\w\d.-_/]+):(.+)/,yn=async(r,e,t,n)=>{let i=await(async()=>{let s=gn.exec(r);if(!s)return await Object.select(e,r);let[f,a,p]=s,y=ar(n.sources,a),d=Gr(p,y,e);return await y.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 Tr(i);return i},Ar=async(r,e,t,n)=>{let i=await Vr(e,(s)=>yn(s,t,r,n));if(mn(i))return i;if(i===e)return g.Explore();if(typeof i==="string"){let s=await Ar(r,i,t,n);if(s.action!==L.Explore)return s}return g.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 g.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 f={...r,...e.root,this:t.parent,parent:s.length>0?s[0]:null,parents:s};try{if(t.key.startsWith("$"))return g.NoExplore();let a=g.Explore();if(typeof t.value==="string"){let p=t.value,y=!1;while(!0){let[d,m]=await Xr(p,e,n,f);if(y=y||m,a=await Ar(n,d,f,e),a.action===L.ReplaceItem&&typeof a.by==="string"){p=a.by;continue}if(a.action===L.Explore&&m&&d!==p)a=g.ReplaceItem(d);break}if(a.action===L.Explore&&p!==t.value)a=g.ReplaceItem(p);switch(a.action){case L.Explore:break;case L.ReplaceItem:t.value=a.by;break;default:return a}}if(Zr(t,e))a=await Qr(t,n,f,e);return a}catch(a){throw Error(`${a.message}
14
+ (${n})`)}}),r};var vr=(r,e)=>e?{fn:(t)=>r(...t.args),types:e}:(t)=>r(...t.args),Pi=(r,e)=>Object.fromEntries(r.map((t)=>[t.name,vr(t,e?.types?.[t.name])])),H=(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 U from"path";class _{constructor(){}static normalize(r){return U.normalize(U.resolve(r))}static resolveInContext(r,e){let t=e??process.cwd(),n=U.isAbsolute(r)?r:U.join(t,r);return this.normalize(n)}static isDirectoryPattern(r){return r.endsWith("/")}static isGlobPattern(r){return r.includes("*")}static toAbsolute(r,e){if(U.isAbsolute(r))return r;return U.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!=="")},ur={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 ir(r),n=await nr(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 f=Object.deepClone(n);if(await $(f,{...r.options,root:{...r.root,index:s,item:t[s],instance:f}}),e.extend?.result){let a=e.extend.result;f=[f,...Array.isArray(a)?a:[a]].mergeAll()}i.push(await fr(r,f))}return i}}});var ee=()=>({map:{filters:[/select|model/],fn:async(r)=>{delete r.parent[r.key];let e=await ir(r),t=await nr(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 f=Object.deepClone(t);await $(f,{...r.options,root:{...r.root,index:s,item:i,instance:f}}),n.push(await fr(r,f))}),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),f=Object.deepClone(s);if(f[r.key])await e(f,f[r.key]);await $(f,{...r.options}),Object.merge(f,t),delete t[r.key]}};return await e(r.parent,r.value),g.Explore()},group:(r)=>{let e=r.root.parent,t=r.value,{items:n,...i}=t;return t.items.forEach((s)=>e.push({...i,...s})),g.DeleteParent()}});var ie=(r)=>({skip:{types:{0:"boolean"},fn:(e)=>e.value?g.DeleteParent():g.DeleteItem()},metadata:({path:e,value:t})=>{return r.metadata(e,t),g.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 g.DeleteItem();if(typeof i==="string")return(await $({value:i},{...e.options,root:{...e.root}})).value;return g.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 g.ReplaceParent(t.cases[t.from],!0);if(t.default!==void 0)return g.ReplaceParent(t.default,!0);return g.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((f)=>{throw Error(`Module ${f} is not allowed`)}),await s.evaluate(),r.sources(Object.fromEntries(Object.entries(s.namespace).map(([f,a])=>[`${t}.${f}`,(p)=>a(p,...p.args)])))}return g.DeleteItem()}});var fe=()=>({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 g.DeleteItem()}}}});var ue=()=>({let:{fn:(r)=>{let e=r.value;return Object.assign(r.root,e),g.DeleteItem()}}});var ce=()=>({tap:{fn:(r)=>{return console.log(`[tap] ${r.path}:`,r.value),r.value}}});var hn=(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},Sr=(r,e,t,n,i=[])=>{let s=hn(r,t),f=["section","context","config","system",...Object.keys(s),...i],a=[e,t.root,t.section.config,r,...Object.values(s)];return[new AsyncFunction(...f,n).bind(t),a]},dn=(r,e)=>{let t={write:(...n)=>{return e.push(...n),t},writeLine:(...n)=>{return e.push(...n.map((i)=>i+`
15
+ `)),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+`
16
+ `)),t},setOptions:(n)=>{return Object.assign(r.section,n),t},use:(n)=>{return n(t),t},getLines:()=>e};return t},bn=async(r,e,t)=>{let n=t.section.config.condition;if(n!==void 0){let[i,s]=Sr(r,e,t,`return (${n})`);if(!await i(...s))return!1}return!0},le=(r)=>async(e)=>{let t=[],n=dn(e,t);if(!await bn(r,n,e))return!1;let[i,s]=Sr(r,n,e,e.section.content,["item"]),f=e.section.config.each;if(f){let[a,p]=Sr(r,n,e,`return (${f})`),y=Array.isArray(f)?f:await a(...p);if(!Array.isArray(y))throw Error('The "each" property of a script section must return an array');for(let d of y){let m=await i(...s,d);if(typeof m<"u")t.push(m)}}else{let a=await i(...s);if(typeof a<"u")return a}if(t.length===0)return!1;return t.join("")};var pe=(r)=>({script:le(r)});import me from"fs/promises";import G from"path";var ge=(r)=>({include:async(e)=>{let{file:t}=e.options.globalContext;return await Wr(e.args[0],{cwd:G.dirname(t),filter:(n)=>G.basename(t)!==n,map:async(n)=>r.load(n,G.dirname(t),e.root)})},exists:async({args:[e]})=>await br(e),file:async(e)=>await me.readFile(await tr(e.args[0],r.getIncludeDirectories())).then((t)=>t.toString()),scan:async(e)=>{let t=[],i=(()=>{let a=e.args[2]??["**/node_modules/**"],p=typeof a==="string"?a.split(",").map((y)=>y.trim()):a;if(!Array.isArray(p))throw Error("Scan exclusion must be a list");return p})(),{file:s}=e.options.globalContext,f=e.args[1]?await tr(e.args[1],r.getIncludeDirectories()):G.dirname(s);for await(let a of me.glob(e.args[0],{cwd:f,exclude:(p)=>i.some((y)=>G.matchesGlob(p,y))}))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]??`
17
+ `,s=n.padChar?.[0]??" ";return e.padBlock(t??2,i,s)}},formatAs:{fn:({args:[e,t],tags:n})=>{let i=r.getEncoder(t);if(!i)throw Error("Unsupported format: "+String(t));let s=[];if(i.options?.includeTags)s=[n];return i.fn(e,...s)}}});var cr=(r,e=0,t)=>{let n=" ".repeat(e),i=" ".repeat(e+1);if(r===null||r===void 0)return"null";else if(typeof r==="boolean")return String(r);else if(typeof r==="number")return String(r);else if(typeof r==="string")return`"${r.replace(/\\/g,"\\\\").replace(/"/g,"\\\"").replace(/\n/g,"\\n").replace(/\r/g,"\\r").replace(/\t/g,"\\t")}"`;else if(Array.isArray(r)){if(r.length===0)return"[]";return`[
18
+ ${r.map((f)=>`${i}${cr(f,e+1)},`).join(`
21
19
  `)}
22
20
  ${n}]`}else if(typeof r==="object"){let s=Object.entries(r).sort((a,p)=>t?.sortKeys?a[0].localeCompare(p[0]):0);if(s.length===0)return"{}";return`{
23
- ${s.map(([a,p])=>`${o}${a} = ${ur(p,e+1,t)}`).join(`
21
+ ${s.map(([a,p])=>`${i}${a} = ${cr(p,e+1,t)}`).join(`
24
22
  `)}
25
- ${n}}`}else return String(r)},z=(r)=>{if(!r)return r;return r.replaceAll("\\n",`
26
- `).replaceAll("\\$","$").replaceAll("\\t","\t")};var de=()=>({...H({merge:(...r)=>r.flatMap((e)=>e)}),join:({args:[r],root:e,tags:t})=>{let n=defined(r,"Join source cannot be null or undefined"),o=t.key?.[0],s=t.separator?.[0]??t.sep?.[0],f=t.finalize?.length>0,a=z(s);if(typeof n==="string"){if(f&&n.length&&a)return n+a;return n}if(!Array.isArray(n))throw Error("Object is not a list");let p=((o?.length)?n.map((w)=>Object.select({...e,...w},o)):n).join(a),g=t.pad?.[0]??"0",h=t.padChar?.[0]??" ",l=f&&p.length&&a?p+a:p;return g?l.padBlock(parseInt(g),`
27
- `,h):l},range:({args:[r,e,t]})=>{let n=parseInt(r),o=parseInt(e),s=parseInt(t)||1;if(isNaN(n))throw Error("Invalid range: start value '"+String(r)+"' is not a number");if(isNaN(o))throw Error("Invalid range: end value '"+String(e)+"' is not a number");if(s===0)throw Error("Invalid range: step cannot be zero");if((o-n)/s<0)throw Error("Invalid range: step "+String(s)+" has wrong direction for range "+String(n)+" to "+String(o));return Array.from({length:Math.floor((o-n)/s)+1},(f,a)=>n+a*s)},filter:{types:(r,e,t)=>{switch(r){case 0:return"array";case 1:return Object.keys(R)}return fr[t[1].value]?.(r-2,e,t.slice(2))},fn:({args:[r,e,t],root:n,tags:o})=>{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=o.key?.[0],f=R[e];if(s){let p=Array(r.length);for(let h=0;h<r.length;h++)try{p[h]=Object.select({...n,...r[h]},s)}catch{p[h]=Symbol("invalid")}let g=[];for(let h=0;h<r.length;h++){let l=p[h];if(typeof l!=="symbol"&&t===void 0?f(l):f(l,t))g.push(r[h])}return g}let a=[];for(let p of r)if(t===void 0?f(p):f(p,t))a.push(p);return a}}});var he=()=>({each:{processArgs:!1,fn:async({rawArgs:[r,e,...t],root:n,options:o,tags:s})=>{let f=async(O)=>O.quoted?z(O.value):await Object.select(n,O.value),a=await Object.select(n,r.value),p=await f(e),g=s.key?.[0],h=Array.isArray(a)?a:Object.toList(a,"name"),l=[],w=await t.mapAsync(async(O)=>await f(O)),b={...n,item:void 0,index:0,params:w,instance:void 0,parent:n.this,tags:s},P={...o,root:b};if(await h.forEachAsync(async(O,A)=>{let $=Object.deepClone(p),j={instance:$},S=typeof p==="string"?j:$;if(b.item=O,b.index=A,b.instance=$,s?.root?.[0])Object.assign(b,await Object.select(b,s.root[0]));if(await D(S,P),g!==void 0)l.push(await Object.select(j.instance,g));else l.push(j.instance)}),s.join?.length){if(l.length===0)return"";let O=z(s.join[0]),A=s.pad?.[0]??"0",$=s.padChar?.[0]??" ",j=s.finalize?.length&&O?O:"",S=`${l.join(O)}${j}`;return A?S.padBlock(parseInt(A),`
28
- `,$):S}return l}}});var Q=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 Q(r,0,!1),t=await Q(r,1);if(t[e]===void 0){if(r.rawArgs.length>2)return Q(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))},...H(R,{types:fr})});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 o=await Q(e,t,null);if(o!==null)return o}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 o=r.getSection(t);if(!o)throw Error(`Section not found: ${t}`);return o.content}}});var je=()=>({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 Ae=(r)=>{var e,t,n,o,s,f,a,p,g,h,l,w,b,P,O,A,$,j,S,E,M,X,_,C,T,x,Mr,V,W,cr,v,mr,Fe,Ee,Se,Me,De,Pe,$e,ke,Ce,Le,Re,Ue,_e,Be,Ie,Ne,We,Je,Ke,Ye,qe,He,Ge,ze,Qe,Ze,Xe,Te,xe,Ve,ve,rt,et,tt,nt,ot,it,st,at,ft,ut,ct,mt,pt,lt,yt,gt,dt,ht,bt,wt,Ot,jt,At,Ft,Et,St,Mt,Dt,Pt,$t,kt,Ct,Lt,Rt,Ut,_t,Bt,It,Nt,Wt,Jt,o,s,f,a,p,g,h,l,w,b,P,O,A,$,j,S,E,M,X,_,C,T,x,Mr,V,W,cr,v,mr,Fe,Ee,Se,Me,De,Pe,$e,ke,Ce,Le,Re,Ue,_e,Be,Ie,Ne,We,Je,Ke,Ye,qe,He,Ge,ze,Qe,Ze,Xe,Te,xe,Ve,ve,rt,et,tt,nt,ot,it,st,at,ft,ut,ct,mt,pt,lt,yt,gt,dt,ht,bt,wt,Ot,jt,At,Ft,Et,St,Mt,Dt,Pt,$t,kt,Ct,Lt,Rt,Ut,_t,Bt,It,Nt,Wt,Jt;return r.use((n=q,o=[c()],s=[c()],f=[c()],a=[c()],p=[c()],g=[c()],h=[c()],l=[c()],w=[c()],b=[c()],P=[c()],O=[c()],A=[c()],$=[c()],j=[c()],S=[c()],E=[c()],M=[c()],X=[c()],_=[c()],C=[c()],T=[c()],x=[c()],Mr=[c()],V=[c()],W=[c()],cr=[c()],v=[c()],mr=[c()],Fe=[c()],Ee=[c()],Se=[c()],Me=[c()],De=[c()],Pe=[c()],$e=[c()],ke=[c()],Ce=[c()],Le=[c()],Re=[c()],Ue=[c()],_e=[c()],Be=[c()],Ie=[c()],Ne=[c()],We=[c()],Je=[c()],Ke=[c()],Ye=[c()],qe=[c()],He=[c()],Ge=[c()],ze=[c()],Qe=[c()],Ze=[c()],Xe=[c()],Te=[c()],xe=[c()],Ve=[c()],ve=[c()],rt=[c()],et=[c()],tt=[c()],nt=[c()],ot=[c()],it=[c()],st=[c()],at=[c()],ft=[c()],ut=[c()],ct=[c()],mt=[c()],pt=[c()],lt=[c()],yt=[c()],gt=[c()],dt=[c()],ht=[c()],bt=[c()],wt=[c()],Ot=[c()],jt=[c()],At=[c()],Ft=[c()],Et=[c()],St=[c()],Mt=[c()],Dt=[c()],Pt=[c()],$t=[c()],kt=[c()],Ct=[c()],Lt=[c()],Rt=[c()],Ut=[c()],_t=[c()],Bt=[c()],It=[c()],Nt=[c()],Wt=[c()],Jt=[c()],t=Lr(n),e=class extends n{constructor(){super(...arguments);Ur(t,5,this)}env(i){return process.env[i]}uuid(){return crypto.randomUUID()}pascal(i){return i.toPascal()}camel(i){return i.toCamel()}capital(i){return i.capitalize()}snake(i,m="lower"){return i.changeCase(m).toSnake()}kebab(i,m="lower"){return i.changeCase(m).toKebab()}len(i){return i.length}reverse(i){return i.split("").reverse().join("")}concat(...i){return i.join("")}trim(i){return i.trim()}ltrim(i){return i.trimStart()}rtrim(i){return i.trimEnd()}lower(i){return i.toLowerCase()}upper(i){return i.toUpperCase()}encode(i,m){return Buffer.from(i).toString(m??"base64")}decode(i,m){return Buffer.from(i,m??"base64").toString()}list(i,m="name"){return Object.toList(i,m)}object(i,m="name"){return i.toObject((d)=>d[m],(d)=>{let{[m]:F,...k}=d;return k})}pathJoin(...i){return U.join(...i)}resolve(...i){return U.resolve(...i)}dirname(i){return U.dirname(i)}basename(i,m){return U.basename(i,m)}normalize(i){return U.normalize(i)}extname(i){return U.extname(i)}relative(i,m){return U.relative(i,m)}isAbsolute(i){return U.isAbsolute(i)}segments(i){return i.split("/").filter(Boolean)}log(...i){console.log(...i)}md5(i){return N("md5").update(i).digest("hex")}sha1(i){return N("sha1").update(i).digest("hex")}sha256(i){return N("sha256").update(i).digest("hex")}sha512(i){return N("sha512").update(i).digest("hex")}hash(i,m="sha256"){return N(m).update(i).digest("hex")}hmac(i,m,d="sha256"){return N(d).update(i).digest("hex")}base64Encode(i){return Buffer.from(i).toString("base64")}base64Decode(i){return Buffer.from(i,"base64").toString("utf-8")}hexEncode(i){return Buffer.from(i).toString("hex")}hexDecode(i){return Buffer.from(i,"hex").toString("utf-8")}add(...i){return i.reduce((m,d)=>m+d,0)}subtract(i,m){return i-m}multiply(...i){return i.reduce((m,d)=>m*d,1)}divide(i,m){if(m===0)throw Error("Division by zero");return i/m}modulo(i,m){return i%m}power(i,m){return Math.pow(i,m)}sqrt(i){return Math.sqrt(i)}abs(i){return Math.abs(i)}floor(i){return Math.floor(i)}ceil(i){return Math.ceil(i)}round(i,m){let d=Math.pow(10,m??0);return Math.round(i*d)/d}min(...i){return Math.min(...i)}max(...i){return Math.max(...i)}clamp(i,m,d){return Math.max(m,Math.min(d,i))}random(i,m){let d=i??0,F=m??1;return Math.random()*(F-d)+d}timestamp(i){return new Date(i).getTime()}iso(i){return new Date(i).toISOString()}utc(i){return new Date(i).toUTCString()}formatDate(i,m){let d=new Date(i),F=d.getFullYear(),k=String(d.getMonth()+1).padStart(2,"0"),rr=String(d.getDate()).padStart(2,"0"),J=String(d.getHours()).padStart(2,"0"),Kt=String(d.getMinutes()).padStart(2,"0"),Yt=String(d.getSeconds()).padStart(2,"0");return m.replace("YYYY",String(F)).replace("MM",k).replace("DD",rr).replace("HH",J).replace("mm",Kt).replace("ss",Yt)}parseDate(i){return new Date(i).getTime()}year(i){return new Date(i).getFullYear()}month(i){return new Date(i).getMonth()+1}day(i){return new Date(i).getDate()}dayOfWeek(i){return new Date(i).getDay()}hours(i){return new Date(i).getHours()}minutes(i){return new Date(i).getMinutes()}seconds(i){return new Date(i).getSeconds()}regexTest(i,m,d){return new RegExp(i,d).test(m)}regexMatch(i,m,d){return new RegExp(i,d).exec(m)}regexMatchAll(i,m,d){return Array.from(m.matchAll(new RegExp(i,d)))}regexReplace(i,m,d,F){return d.replace(new RegExp(i,F),m)}regexReplaceAll(i,m,d,F){return d.replace(new RegExp(i,F??"g"),m)}regexSplit(i,m,d){return m.split(new RegExp(i,d))}regexExec(i,m,d){return new RegExp(i,d).exec(m)}regexSearch(i,m,d){return m.search(new RegExp(i,d))}unique(i,m){if(!Array.isArray(i))return i;let d=new Set;return i.filter((F)=>{let k=m?F[m]:F;if(d.has(k))return!1;return d.add(k),!0})}groupBy(i,m){if(!Array.isArray(i))return i;let d={};return i.forEach((F)=>{let k=String(F[m]);if(!d[k])d[k]=[];d[k].push(F)}),d}chunk(i,m=1){if(!Array.isArray(i))return[];let d=[];for(let F=0;F<i.length;F+=m)d.push(i.slice(F,F+m));return d}flatten(i,m=1){if(!Array.isArray(i))return[i];let d=[],F=(k,rr)=>{for(let J of k)if(Array.isArray(J)&&rr>0)F(J,rr-1);else d.push(J)};return F(i,m),d}compact(i){if(!Array.isArray(i))return i;return i.filter((m)=>m!==null&&m!==void 0)}head(i,m){if(!Array.isArray(i))return i;return m?i.slice(0,m):i[0]}tail(i,m){if(!Array.isArray(i))return i;return m?i.slice(-m):i[i.length-1]}isEmail(i){return/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(i)}isUrl(i){try{return new URL(i),!0}catch{return!1}}isJson(i){try{return JSON.parse(i),!0}catch{return!1}}isUuid(i){return/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i.test(i)}minLength(i,m){return i?.length>=m}maxLength(i,m){return i?.length<=m}lengthEquals(i,m){return i?.length===m}isNumber(i){return typeof i==="number"&&!isNaN(i)}isString(i){return typeof i==="string"}isBoolean(i){return typeof i==="boolean"}isArray(i){return Array.isArray(i)}isObject(i){return i!==null&&typeof i==="object"&&!Array.isArray(i)}isEmpty(i){if(i===null||i===void 0)return!0;if(typeof i==="string"||Array.isArray(i))return i.length===0;if(typeof i==="object")return Object.keys(i).length===0;return!1}isTruthy(i){return!!i}isFalsy(i){return!i}inRange(i,m,d){return i>=m&&i<=d}matchesPattern(i,m){return new RegExp(m).test(i)}includes(i,m){if(typeof i==="string")return i.includes(String(m));return Array.isArray(i)&&i.includes(m)}startsWith(i,m){return i.startsWith(m)}endsWith(i,m){return i.endsWith(m)}},u(t,1,"env",o,e),u(t,1,"uuid",s,e),u(t,1,"pascal",f,e),u(t,1,"camel",a,e),u(t,1,"capital",p,e),u(t,1,"snake",g,e),u(t,1,"kebab",h,e),u(t,1,"len",l,e),u(t,1,"reverse",w,e),u(t,1,"concat",b,e),u(t,1,"trim",P,e),u(t,1,"ltrim",O,e),u(t,1,"rtrim",A,e),u(t,1,"lower",$,e),u(t,1,"upper",j,e),u(t,1,"encode",S,e),u(t,1,"decode",E,e),u(t,1,"list",M,e),u(t,1,"object",X,e),u(t,1,"pathJoin",_,e),u(t,1,"resolve",C,e),u(t,1,"dirname",T,e),u(t,1,"basename",x,e),u(t,1,"normalize",Mr,e),u(t,1,"extname",V,e),u(t,1,"relative",W,e),u(t,1,"isAbsolute",cr,e),u(t,1,"segments",v,e),u(t,1,"log",mr,e),u(t,1,"md5",Fe,e),u(t,1,"sha1",Ee,e),u(t,1,"sha256",Se,e),u(t,1,"sha512",Me,e),u(t,1,"hash",De,e),u(t,1,"hmac",Pe,e),u(t,1,"base64Encode",$e,e),u(t,1,"base64Decode",ke,e),u(t,1,"hexEncode",Ce,e),u(t,1,"hexDecode",Le,e),u(t,1,"add",Re,e),u(t,1,"subtract",Ue,e),u(t,1,"multiply",_e,e),u(t,1,"divide",Be,e),u(t,1,"modulo",Ie,e),u(t,1,"power",Ne,e),u(t,1,"sqrt",We,e),u(t,1,"abs",Je,e),u(t,1,"floor",Ke,e),u(t,1,"ceil",Ye,e),u(t,1,"round",qe,e),u(t,1,"min",He,e),u(t,1,"max",Ge,e),u(t,1,"clamp",ze,e),u(t,1,"random",Qe,e),u(t,1,"timestamp",Ze,e),u(t,1,"iso",Xe,e),u(t,1,"utc",Te,e),u(t,1,"formatDate",xe,e),u(t,1,"parseDate",Ve,e),u(t,1,"year",ve,e),u(t,1,"month",rt,e),u(t,1,"day",et,e),u(t,1,"dayOfWeek",tt,e),u(t,1,"hours",nt,e),u(t,1,"minutes",ot,e),u(t,1,"seconds",it,e),u(t,1,"regexTest",st,e),u(t,1,"regexMatch",at,e),u(t,1,"regexMatchAll",ft,e),u(t,1,"regexReplace",ut,e),u(t,1,"regexReplaceAll",ct,e),u(t,1,"regexSplit",mt,e),u(t,1,"regexExec",pt,e),u(t,1,"regexSearch",lt,e),u(t,1,"unique",yt,e),u(t,1,"groupBy",gt,e),u(t,1,"chunk",dt,e),u(t,1,"flatten",ht,e),u(t,1,"compact",bt,e),u(t,1,"head",wt,e),u(t,1,"tail",Ot,e),u(t,1,"isEmail",jt,e),u(t,1,"isUrl",At,e),u(t,1,"isJson",Ft,e),u(t,1,"isUuid",Et,e),u(t,1,"minLength",St,e),u(t,1,"maxLength",Mt,e),u(t,1,"lengthEquals",Dt,e),u(t,1,"isNumber",Pt,e),u(t,1,"isString",$t,e),u(t,1,"isBoolean",kt,e),u(t,1,"isArray",Ct,e),u(t,1,"isObject",Lt,e),u(t,1,"isEmpty",Rt,e),u(t,1,"isTruthy",Ut,e),u(t,1,"isFalsy",_t,e),u(t,1,"inRange",Bt,e),u(t,1,"matchesPattern",It,e),u(t,1,"includes",Nt,e),u(t,1,"startsWith",Wt,e),u(t,1,"endsWith",Jt,e),lr(t,e),e)).keys({...Yr(r),...qr(r),...re(),...ee(),...ie(),...te(),...ne(),...oe(r),...ae(r),...fe(),...ue(),...ce()}).sources({...ye(r),...ge(r),...je(),...de(),...he(),...be(),...we(),...Oe(r)}).sections(pe(r)).fieldOptions({configParser:Bun.YAML.parse,onSection:(i)=>{if(i.section.config.name)r.section(i.section)}}).decoders({yaml:{matching:["\\.yml$","\\.yaml$"],fn:Bun.YAML.parse}}).encoders({json:{fn:(i)=>JSON.stringify(i,null,2)},yaml:{fn:(i)=>Bun.YAML.stringify(i,null,2)},terraform:{options:{includeTags:!0},fn:(i,m)=>ur(i,0,{sortKeys:!!(m?.sort?.length??m?.sortKeys?.length)})}})};import wn from"fs/promises";import Z from"path";class Er{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 o of r)if(I.isGlobPattern(o)){let s=(await Array.fromAsync(wn.glob(o,{cwd:e}))).map((f)=>Z.join(e,f));n.push(...s.filter((f)=>!t.included.includes(f)))}else if(I.isDirectoryPattern(o)){let s=Z.isAbsolute(o)?o:Z.join(e,o);if(!this.includeDirectories.includes(s))this.includeDirectories.push(s)}else n.push(o);return n.unique()}buildSearchDirs(r){let e=r?[r]:[];return e.push(...this.includeDirectories.map((t)=>Z.isAbsolute(t)?t:Z.join(r??process.cwd(),t))),e}}class Sr{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 o=await this.includeManager.processPatterns(n,r.folderPath,t);for(let s of o)Object.merge(await this.loadFn(s,r.folderPath,{parent:r.content,...e},!0,t),r.content)}}class On{includeManager=new Er;includeProcessor;cacheManager=new br(100);outputs=[];vars={};funcs={};fields={sources:{},keys:{},sections:{}};objectMetadata={};currentContext=null;storedSections={};dataEncoders={};dataDecoders={};constructor(){this.includeProcessor=new Sr(this.includeManager,this.load.bind(this)),this.use(Ae)}use(r){if(r.prototype instanceof q)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}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}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 D(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,o){let s=this.includeManager.snapshot();try{this.includeManager.reset();let f=this.includeManager.buildSearchDirs(e);if(o)this.currentContext=o;this.currentContext??={included:[],document:null};let a=await Nr(r,{dirs:f,parsers:this.dataDecoders,format:"yaml"}),p=I.normalize(a.fullPath);if(this.currentContext.included.push(p),!a.content)return null;let g=this.cacheManager.get(p),h;if(g)h=g.raw;else h=a.content,this.cacheManager.set(p,{raw:h,timestamp:Date.now()});let l=Object.deepClone(h);a.content=l,await this.includeProcessor.processIncludes(a,t,this.currentContext);let w;if(n!==!0)w=await this.loadObject(a.content,t,{fileName:a.fullPath,folderPath:a.folderPath,fullPath:a.fullPath});else w=a.content;return this.currentContext.document=w,w}catch(f){throw this.includeManager.restore(s),f}finally{this.includeManager.restore(s)}}async writeAll(r){await Kr(this.getOutputs(),r)}}export{Kr as writeOutputs,rn as writeOutput,Vt as writeFormat,In as variable,Nn as sharedFunction,_n as section,D as processFields,H as makeFieldProcessorMap,ko as makeFieldProcessorList,vr as makeFieldProcessor,c as macro,er as locate,Nr as loadFormat,Bn as key,tn as importList,Rn as importGlob,Wr as globMap,sr as getProcessor,zr as getArgs,hr as exists,Wn as encoder,Vn as defined,Jn as decoder,R as conditionPredicates,Or as StringBuilder,q as ObjectorPlugin,On as Objector,y as NavigateResult,L as NavigateAction,un as Markdown,fn as Logger};
23
+ ${n}}`}else return String(r)},Z=(r)=>{if(!r)return r;return r.replaceAll("\\n",`
24
+ `).replaceAll("\\$","$").replaceAll("\\t","\t")};var he=()=>({...H({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],f=t.finalize?.length>0,a=Z(s);if(typeof n==="string"){if(f&&n.length&&a)return n+a;return n}if(!Array.isArray(n))throw Error("Object is not a list");let p=((i?.length)?n.map((w)=>Object.select({...e,...w},i)):n).join(a),y=t.pad?.[0]??"0",d=t.padChar?.[0]??" ",m=f&&p.length&&a?p+a:p;return y?m.padBlock(parseInt(y),`
25
+ `,d):m},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},(f,a)=>n+a*s)},filter:{types:(r,e,t)=>{switch(r){case 0:return"array";case 1:return Object.keys(R)}return ur[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],f=R[e];if(s){let p=Array(r.length);for(let d=0;d<r.length;d++)try{p[d]=Object.select({...n,...r[d]},s)}catch{p[d]=Symbol("invalid")}let y=[];for(let d=0;d<r.length;d++){let m=p[d];if(typeof m!=="symbol"&&t===void 0?f(m):f(m,t))y.push(r[d])}return y}let a=[];for(let p of r)if(t===void 0?f(p):f(p,t))a.push(p);return a}}});var de=()=>({each:{processArgs:!1,fn:async({rawArgs:[r,e,...t],root:n,options:i,tags:s})=>{let f=async(O)=>O.quoted?Z(O.value):await Object.select(n,O.value),a=await Object.select(n,r.value),p=await f(e),y=s.key?.[0],d=Array.isArray(a)?a:Object.toList(a,"name"),m=[],w=await t.mapAsync(async(O)=>await f(O)),b={...n,item:void 0,index:0,params:w,instance:void 0,parent:n.this,tags:s},P={...i,root:b};if(await d.forEachAsync(async(O,A)=>{let D=Object.deepClone(p),j={instance:D},E=typeof p==="string"?j:D;if(b.item=O,b.index=A,b.instance=D,s?.root?.[0])Object.assign(b,await Object.select(b,s.root[0]));if(await $(E,P),y!==void 0)m.push(await Object.select(j.instance,y));else m.push(j.instance)}),s.join?.length){if(m.length===0)return"";let O=Z(s.join[0]),A=s.pad?.[0]??"0",D=s.padChar?.[0]??" ",j=s.finalize?.length&&O?O:"",E=`${m.join(O)}${j}`;return A?E.padBlock(parseInt(A),`
26
+ `,D):E}return m}}});var Q=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 Q(r,0,!1),t=await Q(r,1);if(t[e]===void 0){if(r.rawArgs.length>2)return Q(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))},...H(R,{types:ur})});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 Q(e,t,null);if(i!==null)return i}if(e.tags.nullable?.length)return g.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 je=()=>({convert:({args:[r,e,t]})=>{switch(e){case"string":return String(r);case"number":{let n=Number(r);if(!isNaN(n))return g.ReplaceItem(n);break}case"boolean":if(r==="true"||r===!0||r===1||r==="1"||r==="yes"||r==="on")return g.ReplaceItem(!0);else if(r==="false"||r===!1||r===0||r==="0"||r==="no"||r==="off")return g.ReplaceItem(!1);break;default:throw Error(`Unsupported type for convert: ${e}`)}if(t!==void 0)return g.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 g.ReplaceItem(n)},typeOf:({args:[r]})=>{if(r===null)return"null";else if(Array.isArray(r))return"array";else return typeof r}});var Ae=(r)=>{var e,t,n,i,s,f,a,p,y,d,m,w,b,P,O,A,D,j,E,F,M,T,B,C,x,V,Mr,v,W,lr,rr,pr,Se,Fe,Ee,Me,$e,Pe,De,ke,Ce,Le,Re,Ie,Be,Ue,_e,Ne,We,Je,Ke,Ye,ze,qe,He,Ge,Ze,Qe,Xe,Te,xe,Ve,ve,rt,et,tt,nt,it,ot,st,at,ft,ut,ct,lt,pt,mt,gt,yt,ht,dt,bt,wt,Ot,jt,At,St,Ft,Et,Mt,$t,Pt,Dt,kt,Ct,Lt,Rt,It,Bt,Ut,_t,Nt,Wt,Jt,i,s,f,a,p,y,d,m,w,b,P,O,A,D,j,E,F,M,T,B,C,x,V,Mr,v,W,lr,rr,pr,Se,Fe,Ee,Me,$e,Pe,De,ke,Ce,Le,Re,Ie,Be,Ue,_e,Ne,We,Je,Ke,Ye,ze,qe,He,Ge,Ze,Qe,Xe,Te,xe,Ve,ve,rt,et,tt,nt,it,ot,st,at,ft,ut,ct,lt,pt,mt,gt,yt,ht,dt,bt,wt,Ot,jt,At,St,Ft,Et,Mt,$t,Pt,Dt,kt,Ct,Lt,Rt,It,Bt,Ut,_t,Nt,Wt,Jt;return r.use((n=z,i=[c()],s=[c()],f=[c()],a=[c()],p=[c()],y=[c()],d=[c()],m=[c()],w=[c()],b=[c()],P=[c()],O=[c()],A=[c()],D=[c()],j=[c()],E=[c()],F=[c()],M=[c()],T=[c()],B=[c()],C=[c()],x=[c()],V=[c()],Mr=[c()],v=[c()],W=[c()],lr=[c()],rr=[c()],pr=[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()],Ue=[c()],_e=[c()],Ne=[c()],We=[c()],Je=[c()],Ke=[c()],Ye=[c()],ze=[c()],qe=[c()],He=[c()],Ge=[c()],Ze=[c()],Qe=[c()],Xe=[c()],Te=[c()],xe=[c()],Ve=[c()],ve=[c()],rt=[c()],et=[c()],tt=[c()],nt=[c()],it=[c()],ot=[c()],st=[c()],at=[c()],ft=[c()],ut=[c()],ct=[c()],lt=[c()],pt=[c()],mt=[c()],gt=[c()],yt=[c()],ht=[c()],dt=[c()],bt=[c()],wt=[c()],Ot=[c()],jt=[c()],At=[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()],Ut=[c()],_t=[c()],Nt=[c()],Wt=[c()],Jt=[c()],t=Lr(n),e=class extends n{constructor(){super(...arguments);Ir(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,l="lower"){return o.changeCase(l).toSnake()}kebab(o,l="lower"){return o.changeCase(l).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,l){return Buffer.from(o).toString(l??"base64")}decode(o,l){return Buffer.from(o,l??"base64").toString()}list(o,l="name"){return Object.toList(o,l)}object(o,l="name"){return o.toObject((h)=>h[l],(h)=>{let{[l]: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,l){return I.basename(o,l)}normalize(o){return I.normalize(o)}extname(o){return I.extname(o)}relative(o,l){return I.relative(o,l)}isAbsolute(o){return I.isAbsolute(o)}segments(o){return o.split("/").filter(Boolean)}log(...o){console.log(...o)}md5(o){return N("md5").update(o).digest("hex")}sha1(o){return N("sha1").update(o).digest("hex")}sha256(o){return N("sha256").update(o).digest("hex")}sha512(o){return N("sha512").update(o).digest("hex")}hash(o,l="sha256"){return N(l).update(o).digest("hex")}hmac(o,l,h="sha256"){return N(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((l,h)=>l+h,0)}subtract(o,l){return o-l}multiply(...o){return o.reduce((l,h)=>l*h,1)}divide(o,l){if(l===0)throw Error("Division by zero");return o/l}modulo(o,l){return o%l}power(o,l){return Math.pow(o,l)}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,l){let h=Math.pow(10,l??0);return Math.round(o*h)/h}min(...o){return Math.min(...o)}max(...o){return Math.max(...o)}clamp(o,l,h){return Math.max(l,Math.min(h,o))}random(o,l){let h=o??0,S=l??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,l){let h=new Date(o),S=h.getFullYear(),k=String(h.getMonth()+1).padStart(2,"0"),er=String(h.getDate()).padStart(2,"0"),J=String(h.getHours()).padStart(2,"0"),Kt=String(h.getMinutes()).padStart(2,"0"),Yt=String(h.getSeconds()).padStart(2,"0");return l.replace("YYYY",String(S)).replace("MM",k).replace("DD",er).replace("HH",J).replace("mm",Kt).replace("ss",Yt)}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,l,h){return new RegExp(o,h).test(l)}regexMatch(o,l,h){return new RegExp(o,h).exec(l)}regexMatchAll(o,l,h){return Array.from(l.matchAll(new RegExp(o,h)))}regexReplace(o,l,h,S){return h.replace(new RegExp(o,S),l)}regexReplaceAll(o,l,h,S){return h.replace(new RegExp(o,S??"g"),l)}regexSplit(o,l,h){return l.split(new RegExp(o,h))}regexExec(o,l,h){return new RegExp(o,h).exec(l)}regexSearch(o,l,h){return l.search(new RegExp(o,h))}unique(o,l){if(!Array.isArray(o))return o;let h=new Set;return o.filter((S)=>{let k=l?S[l]:S;if(h.has(k))return!1;return h.add(k),!0})}groupBy(o,l){if(!Array.isArray(o))return o;let h={};return o.forEach((S)=>{let k=String(S[l]);if(!h[k])h[k]=[];h[k].push(S)}),h}chunk(o,l=1){if(!Array.isArray(o))return[];let h=[];for(let S=0;S<o.length;S+=l)h.push(o.slice(S,S+l));return h}flatten(o,l=1){if(!Array.isArray(o))return[o];let h=[],S=(k,er)=>{for(let J of k)if(Array.isArray(J)&&er>0)S(J,er-1);else h.push(J)};return S(o,l),h}compact(o){if(!Array.isArray(o))return o;return o.filter((l)=>l!==null&&l!==void 0)}head(o,l){if(!Array.isArray(o))return o;return l?o.slice(0,l):o[0]}tail(o,l){if(!Array.isArray(o))return o;return l?o.slice(-l):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,l){return o?.length>=l}maxLength(o,l){return o?.length<=l}lengthEquals(o,l){return o?.length===l}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,l,h){return o>=l&&o<=h}matchesPattern(o,l){return new RegExp(l).test(o)}includes(o,l){if(typeof o==="string")return o.includes(String(l));return Array.isArray(o)&&o.includes(l)}startsWith(o,l){return o.startsWith(l)}endsWith(o,l){return o.endsWith(l)}},u(t,1,"env",i,e),u(t,1,"uuid",s,e),u(t,1,"pascal",f,e),u(t,1,"camel",a,e),u(t,1,"capital",p,e),u(t,1,"snake",y,e),u(t,1,"kebab",d,e),u(t,1,"len",m,e),u(t,1,"reverse",w,e),u(t,1,"concat",b,e),u(t,1,"trim",P,e),u(t,1,"ltrim",O,e),u(t,1,"rtrim",A,e),u(t,1,"lower",D,e),u(t,1,"upper",j,e),u(t,1,"encode",E,e),u(t,1,"decode",F,e),u(t,1,"list",M,e),u(t,1,"object",T,e),u(t,1,"pathJoin",B,e),u(t,1,"resolve",C,e),u(t,1,"dirname",x,e),u(t,1,"basename",V,e),u(t,1,"normalize",Mr,e),u(t,1,"extname",v,e),u(t,1,"relative",W,e),u(t,1,"isAbsolute",lr,e),u(t,1,"segments",rr,e),u(t,1,"log",pr,e),u(t,1,"md5",Se,e),u(t,1,"sha1",Fe,e),u(t,1,"sha256",Ee,e),u(t,1,"sha512",Me,e),u(t,1,"hash",$e,e),u(t,1,"hmac",Pe,e),u(t,1,"base64Encode",De,e),u(t,1,"base64Decode",ke,e),u(t,1,"hexEncode",Ce,e),u(t,1,"hexDecode",Le,e),u(t,1,"add",Re,e),u(t,1,"subtract",Ie,e),u(t,1,"multiply",Be,e),u(t,1,"divide",Ue,e),u(t,1,"modulo",_e,e),u(t,1,"power",Ne,e),u(t,1,"sqrt",We,e),u(t,1,"abs",Je,e),u(t,1,"floor",Ke,e),u(t,1,"ceil",Ye,e),u(t,1,"round",ze,e),u(t,1,"min",qe,e),u(t,1,"max",He,e),u(t,1,"clamp",Ge,e),u(t,1,"random",Ze,e),u(t,1,"timestamp",Qe,e),u(t,1,"iso",Xe,e),u(t,1,"utc",Te,e),u(t,1,"formatDate",xe,e),u(t,1,"parseDate",Ve,e),u(t,1,"year",ve,e),u(t,1,"month",rt,e),u(t,1,"day",et,e),u(t,1,"dayOfWeek",tt,e),u(t,1,"hours",nt,e),u(t,1,"minutes",it,e),u(t,1,"seconds",ot,e),u(t,1,"regexTest",st,e),u(t,1,"regexMatch",at,e),u(t,1,"regexMatchAll",ft,e),u(t,1,"regexReplace",ut,e),u(t,1,"regexReplaceAll",ct,e),u(t,1,"regexSplit",lt,e),u(t,1,"regexExec",pt,e),u(t,1,"regexSearch",mt,e),u(t,1,"unique",gt,e),u(t,1,"groupBy",yt,e),u(t,1,"chunk",ht,e),u(t,1,"flatten",dt,e),u(t,1,"compact",bt,e),u(t,1,"head",wt,e),u(t,1,"tail",Ot,e),u(t,1,"isEmail",jt,e),u(t,1,"isUrl",At,e),u(t,1,"isJson",St,e),u(t,1,"isUuid",Ft,e),u(t,1,"minLength",Et,e),u(t,1,"maxLength",Mt,e),u(t,1,"lengthEquals",$t,e),u(t,1,"isNumber",Pt,e),u(t,1,"isString",Dt,e),u(t,1,"isBoolean",kt,e),u(t,1,"isArray",Ct,e),u(t,1,"isObject",Lt,e),u(t,1,"isEmpty",Rt,e),u(t,1,"isTruthy",It,e),u(t,1,"isFalsy",Bt,e),u(t,1,"inRange",Ut,e),u(t,1,"matchesPattern",_t,e),u(t,1,"includes",Nt,e),u(t,1,"startsWith",Wt,e),u(t,1,"endsWith",Jt,e),gr(t,e),e)).keys({...Yr(r),...zr(r),...re(),...ee(),...oe(),...te(),...ne(),...ie(r),...ae(r),...fe(),...ue(),...ce()}).sources({...ge(r),...ye(r),...je(),...he(),...de(),...be(),...we(),...Oe(r)}).sections(pe(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,l)=>cr(o,0,{sortKeys:!!(l?.sort?.length??l?.sortKeys?.length)})}})};import wn from"fs/promises";import X from"path";class Fr{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(_.isGlobPattern(i)){let s=(await Array.fromAsync(wn.glob(i,{cwd:e}))).map((f)=>X.join(e,f));n.push(...s.filter((f)=>!t.included.includes(f)))}else if(_.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 Er{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 On{includeManager=new Fr;includeProcessor;cacheManager=new wr(100);outputs=[];vars={};funcs={};fields={sources:{},keys:{},sections:{}};objectMetadata={};currentContext=null;storedSections={};dataEncoders={};dataDecoders={};constructor(){this.includeProcessor=new Er(this.includeManager,this.load.bind(this)),this.use(Ae)}use(r){if(r.prototype instanceof z)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}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}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 f=this.includeManager.buildSearchDirs(e);if(i)this.currentContext=i;this.currentContext??={included:[],document:null};let a=await Nr(r,{dirs:f,parsers:this.dataDecoders,format:"yaml"}),p=_.normalize(a.fullPath);if(this.currentContext.included.push(p),!a.content)return null;let y=this.cacheManager.get(p),d;if(y)d=y.raw;else d=a.content,this.cacheManager.set(p,{raw:d,timestamp:Date.now()});let m=Object.deepClone(d);a.content=m,await this.includeProcessor.processIncludes(a,t,this.currentContext);let w;if(n!==!0)w=await this.loadObject(a.content,t,{fileName:a.fullPath,folderPath:a.folderPath,fullPath:a.fullPath});else w=a.content;return this.currentContext.document=w,w}catch(f){throw this.includeManager.restore(s),f}finally{this.includeManager.restore(s)}}async writeAll(r){await Kr(this.getOutputs(),r)}}export{Kr as writeOutputs,rn as writeOutput,Vt as writeFormat,_n as variable,Nn as sharedFunction,Bn as section,$ as processFields,H as makeFieldProcessorMap,Pi as makeFieldProcessorList,vr as makeFieldProcessor,c as macro,tr as locate,Nr as loadFormat,Un as key,tn as importList,Rn as importGlob,Wr as globMap,ar as getProcessor,Gr as getArgs,br as exists,Wn as encoder,Jn as decoder,R as conditionPredicates,q as StringBuilder,z as ObjectorPlugin,On as Objector,g as NavigateResult,L as NavigateAction,un as Markdown,fn as Logger};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@homedev/objector",
3
- "version": "1.3.3",
3
+ "version": "1.3.4",
4
4
  "description": "object extensions for YAML/JSON",
5
5
  "author": "julzor",
6
6
  "license": "ISC",