@homedev/objector 1.2.67 → 1.3.1
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 +68 -9
- package/dist/index.js +20 -21
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
import { NavigateResult as NavigateResult_2 } from '@homedev/navigate';
|
|
2
|
-
|
|
3
1
|
/**
|
|
4
2
|
* @public
|
|
5
3
|
*/
|
|
@@ -50,7 +48,7 @@ export declare interface FieldContext {
|
|
|
50
48
|
path: string;
|
|
51
49
|
root: any;
|
|
52
50
|
options: ProcessFieldsOptions;
|
|
53
|
-
value: string | object | number |
|
|
51
|
+
value: string | object | number | NavigateResult | null;
|
|
54
52
|
key: string;
|
|
55
53
|
args: any[];
|
|
56
54
|
rawArgs: {
|
|
@@ -61,6 +59,19 @@ export declare interface FieldContext {
|
|
|
61
59
|
parent?: any;
|
|
62
60
|
}
|
|
63
61
|
|
|
62
|
+
declare interface FieldContext_2 {
|
|
63
|
+
path: string
|
|
64
|
+
root: any
|
|
65
|
+
options: ProcessFieldsOptions_2
|
|
66
|
+
value: string | object | number | NavigateResult | null
|
|
67
|
+
key: string
|
|
68
|
+
args: any[]
|
|
69
|
+
rawArgs: { value: string, quoted: boolean }[]
|
|
70
|
+
tags: Record<string, string[]>
|
|
71
|
+
|
|
72
|
+
parent?: any
|
|
73
|
+
}
|
|
74
|
+
|
|
64
75
|
export declare interface FieldProcessor {
|
|
65
76
|
fn: FieldProcessorFunc;
|
|
66
77
|
options: FieldProcessorOptions;
|
|
@@ -68,14 +79,24 @@ export declare interface FieldProcessor {
|
|
|
68
79
|
|
|
69
80
|
export declare type FieldProcessorFunc = (context: FieldContext) => any;
|
|
70
81
|
|
|
82
|
+
declare type FieldProcessorFunc_2 = (context: FieldContext_2) => any
|
|
83
|
+
|
|
71
84
|
export declare type FieldProcessorMap = Record<string, FieldProcessorTypedFunc>;
|
|
72
85
|
|
|
86
|
+
declare type FieldProcessorMap_2 = Record<string, FieldProcessorTypedFunc_2>
|
|
87
|
+
|
|
73
88
|
export declare interface FieldProcessorOptions {
|
|
74
89
|
filters?: RegExp[];
|
|
75
90
|
processArgs?: boolean;
|
|
76
91
|
types?: Record<number, string | any[] | ((value: string, root: any, index: number, quoted: boolean) => any)> | FieldProcessorTypeChecker;
|
|
77
92
|
}
|
|
78
93
|
|
|
94
|
+
declare interface FieldProcessorOptions_2 {
|
|
95
|
+
filters?: RegExp[]
|
|
96
|
+
processArgs?: boolean
|
|
97
|
+
types?: Record<number, string | any[] | ((value: string, root: any, index: number, quoted: boolean) => any)> | FieldProcessorTypeChecker_2
|
|
98
|
+
}
|
|
99
|
+
|
|
79
100
|
export declare interface FieldProcessorSection {
|
|
80
101
|
config: Record<string, any>;
|
|
81
102
|
content: string;
|
|
@@ -84,8 +105,18 @@ export declare interface FieldProcessorSection {
|
|
|
84
105
|
show?: boolean;
|
|
85
106
|
}
|
|
86
107
|
|
|
108
|
+
declare interface FieldProcessorSection_2 {
|
|
109
|
+
config: Record<string, any>
|
|
110
|
+
content: string
|
|
111
|
+
trim?: boolean
|
|
112
|
+
indent?: number
|
|
113
|
+
show?: boolean
|
|
114
|
+
}
|
|
115
|
+
|
|
87
116
|
export declare type FieldProcessorSectionConfigFunc = (context: FieldProcessorSectionContext) => Promise<boolean | void> | boolean | void;
|
|
88
117
|
|
|
118
|
+
declare type FieldProcessorSectionConfigFunc_2 = (context: FieldProcessorSectionContext_2) => Promise<boolean | void> | boolean | void
|
|
119
|
+
|
|
89
120
|
export declare interface FieldProcessorSectionContext {
|
|
90
121
|
section: FieldProcessorSection;
|
|
91
122
|
content: string;
|
|
@@ -94,18 +125,34 @@ export declare interface FieldProcessorSectionContext {
|
|
|
94
125
|
options: ProcessFieldsOptions;
|
|
95
126
|
}
|
|
96
127
|
|
|
128
|
+
declare interface FieldProcessorSectionContext_2 {
|
|
129
|
+
section: FieldProcessorSection_2
|
|
130
|
+
content: string
|
|
131
|
+
path: string
|
|
132
|
+
root: Record<string, any>
|
|
133
|
+
options: ProcessFieldsOptions_2
|
|
134
|
+
}
|
|
135
|
+
|
|
97
136
|
export declare type FieldProcessorSectionFunc = (context: FieldProcessorSectionContext) => Promise<void | boolean | string> | void | boolean | string;
|
|
98
137
|
|
|
138
|
+
declare type FieldProcessorSectionFunc_2 = (context: FieldProcessorSectionContext_2) => Promise<void | boolean | string> | void | boolean | string
|
|
139
|
+
|
|
99
140
|
export declare type FieldProcessorSectionMap = Record<string, FieldProcessorSectionFunc>;
|
|
100
141
|
|
|
142
|
+
declare type FieldProcessorSectionMap_2 = Record<string, FieldProcessorSectionFunc_2>
|
|
143
|
+
|
|
101
144
|
export declare type FieldProcessorTypeChecker = (n: number, value: any, args: any[]) => any;
|
|
102
145
|
|
|
146
|
+
declare type FieldProcessorTypeChecker_2 = (n: number, value: any, args: any[]) => any
|
|
147
|
+
|
|
103
148
|
export declare type FieldProcessorTypeCheckers<T = unknown> = Record<keyof T, FieldProcessorTypeChecker>;
|
|
104
149
|
|
|
105
150
|
export declare type FieldProcessorTypedFunc = FieldProcessorFunc | (FieldProcessorOptions & {
|
|
106
151
|
fn: FieldProcessorFunc;
|
|
107
152
|
});
|
|
108
153
|
|
|
154
|
+
declare type FieldProcessorTypedFunc_2 = FieldProcessorFunc_2 | (FieldProcessorOptions_2 & { fn: FieldProcessorFunc_2 })
|
|
155
|
+
|
|
109
156
|
declare interface FilePatternOptions {
|
|
110
157
|
cwd: string;
|
|
111
158
|
filter?: (fileName: string, index: number, array: string[]) => boolean;
|
|
@@ -316,9 +363,9 @@ export declare class Objector {
|
|
|
316
363
|
includeDirectory(...dirs: string[]): this;
|
|
317
364
|
getIncludeDirectories(): string[];
|
|
318
365
|
include(...files: string[]): this;
|
|
319
|
-
keys(keys:
|
|
320
|
-
sources(sources:
|
|
321
|
-
sections(sections: Record<string,
|
|
366
|
+
keys(keys: FieldProcessorMap_2): this;
|
|
367
|
+
sources(sources: FieldProcessorMap_2): this;
|
|
368
|
+
sections(sections: Record<string, FieldProcessorSectionFunc_2>): this;
|
|
322
369
|
variables(vars: Record<string, unknown>): this;
|
|
323
370
|
functions(funcs: Record<string, AsyncFunction>): this;
|
|
324
371
|
getFunctions(): Record<string, AsyncFunction>;
|
|
@@ -330,9 +377,9 @@ export declare class Objector {
|
|
|
330
377
|
setCacheMaxSize(size: number): this;
|
|
331
378
|
clearCache(): this;
|
|
332
379
|
getCurrentContext(): LoadContext | null;
|
|
333
|
-
fieldOptions(options:
|
|
334
|
-
section(section:
|
|
335
|
-
getSection(name: string):
|
|
380
|
+
fieldOptions(options: ProcessFieldsOptions_2): this;
|
|
381
|
+
section(section: FieldProcessorSection_2): this;
|
|
382
|
+
getSection(name: string): FieldProcessorSection_2 | undefined;
|
|
336
383
|
encoders(encoders: Record<string, Encoder>): this;
|
|
337
384
|
decoders(decoders: Record<string, LoadFormatParser>): this;
|
|
338
385
|
getEncoder(name: string): Encoder | undefined;
|
|
@@ -398,6 +445,18 @@ export declare interface ProcessFieldsOptions {
|
|
|
398
445
|
configParser?: (configText: string) => any;
|
|
399
446
|
}
|
|
400
447
|
|
|
448
|
+
declare interface ProcessFieldsOptions_2 {
|
|
449
|
+
sources?: FieldProcessorMap_2
|
|
450
|
+
keys?: FieldProcessorMap_2
|
|
451
|
+
sections?: FieldProcessorSectionMap_2
|
|
452
|
+
filters?: RegExp[]
|
|
453
|
+
root?: Record<any, any>
|
|
454
|
+
globalContext?: any
|
|
455
|
+
onSection?: FieldProcessorSectionFunc_2
|
|
456
|
+
onSectionConfig?: FieldProcessorSectionConfigFunc_2
|
|
457
|
+
configParser?: (configText: string) => any
|
|
458
|
+
}
|
|
459
|
+
|
|
401
460
|
export declare const section: (options?: SectionOptions) => (_: any, ctx: ClassMethodDecoratorContext<ObjectorPlugin, (section: FieldProcessorSection) => any>) => void;
|
|
402
461
|
|
|
403
462
|
declare type SectionOptions = ObjectorDecoratorOptions;
|
package/dist/index.js
CHANGED
|
@@ -1,23 +1,22 @@
|
|
|
1
|
-
var Yr=Object.create;var Fe=Object.defineProperty;var Gr=Object.getOwnPropertyDescriptor;var Se=(e,t)=>{return Object.defineProperty(e,"name",{value:t,enumerable:!1,configurable:!0}),e};var De=(e,t)=>(t=Symbol[e])?t:Symbol.for("Symbol."+e),Y=(e)=>{throw TypeError(e)},Tr=(e,t,r)=>(t in e)?Fe(e,t,{enumerable:!0,configurable:!0,writable:!0,value:r}):e[t]=r;var pe=(e,t,r)=>t.has(e)||Y("Cannot "+r),Vr=(e,t)=>Object(t)!==t?Y('Cannot use the "in" operator on this value'):e.has(t),ke=(e,t,r)=>(pe(e,t,"read from private field"),r?r.call(e):t.get(e));var Me=(e,t,r,n)=>(pe(e,t,"write to private field"),n?n.call(e,r):t.set(e,r),r),Xr=(e,t,r)=>(pe(e,t,"access private method"),r),Re=(e)=>[,,,Yr(e?.[De("metadata")]??null)],$e=["class","method","getter","setter","accessor","field","value","get","set"],K=(e)=>e!==void 0&&typeof e!=="function"?Y("Function expected"):e,Hr=(e,t,r,n,o)=>({kind:$e[e],name:t,metadata:n,addInitializer:(s)=>r._?Y("Already initialized"):o.push(K(s||null))}),ge=(e,t)=>Tr(t,De("metadata"),e[3]),Ce=(e,t,r,n)=>{for(var o=0,s=e[t>>1],l=s&&s.length;o<l;o++)t&1?s[o].call(r):n=s[o].call(r,n);return n},c=(e,t,r,n,o,s)=>{var l,a,u,b,w,m=t&7,g=!!(t&8),d=!!(t&16),E=m>3?e.length+1:m?g?1:2:0,y=$e[m+5],j=m>3&&(e[E-1]=[]),h=e[E]||(e[E]=[]),k=m&&(!d&&!g&&(o=o.prototype),m<5&&(m>3||!d)&&Gr(m<4?o:{get[r](){return ke(this,s)},set[r](S){Me(this,s,S)}},r));m?d&&m<4&&Se(s,(m>2?"set ":m>1?"get ":"")+r):Se(o,r);for(var O=n.length-1;O>=0;O--){if(b=Hr(m,r,u={},e[3],h),m){if(b.static=g,b.private=d,w=b.access={has:d?(S)=>Vr(o,S):(S)=>(r in S)},m^3)w.get=d?(S)=>(m^1?ke:Xr)(S,o,m^4?s:k.get):(S)=>S[r];if(m>2)w.set=d?(S,M)=>Me(S,o,M,m^4?s:k.set):(S,M)=>S[r]=M}if(a=(0,n[O])(m?m<4?d?s:k[y]:m>4?void 0:{get:k.get,set:k.set}:o,b),u._=1,m^4||a===void 0)K(a)&&(m>4?j.unshift(a):m?d?s=a:k[y]=a:o=a);else if(typeof a!=="object"||a===null)Y("Object expected");else K(l=a.get)&&(k.get=l),K(l=a.set)&&(k.set=l),K(l=a.init)&&j.unshift(l)}return m||ge(e,o),k&&Fe(o,r,k),d?m^4?s:k:o};var Qr=Object.create,{getPrototypeOf:zr,defineProperty:xe,getOwnPropertyNames:Zr}=Object,Pr=Object.prototype.hasOwnProperty,Jr=(e,t,r)=>{r=e!=null?Qr(zr(e)):{};let n=t||!e||!e.__esModule?xe(r,"default",{value:e,enumerable:!0}):r;for(let o of Zr(e))if(!Pr.call(n,o))xe(n,o,{get:()=>e[o],enumerable:!0});return n},en=(e,t)=>()=>(t||e((t={exports:{}}).exports,t),t.exports),tn=en((e,t)=>{var{defineProperty:r,getOwnPropertyNames:n,getOwnPropertyDescriptor:o}=Object,s=Object.prototype.hasOwnProperty,l=new WeakMap,a=(g)=>{var d=l.get(g),E;if(d)return d;if(d=r({},"__esModule",{value:!0}),g&&typeof g==="object"||typeof g==="function")n(g).map((y)=>!s.call(d,y)&&r(d,y,{get:()=>g[y],enumerable:!(E=o(g,y))||E.enumerable}));return l.set(g,d),d},u=(g,d)=>{for(var E in d)r(g,E,{get:d[E],enumerable:!0,configurable:!0,set:(y)=>d[E]=()=>y})},b={};u(b,{splitWithQuotes:()=>m,splitNested:()=>w}),t.exports=a(b);var w=(g,d,E="(",y=")")=>{let j=0,h="",k=[];for(let O of g){if(h+=O,O===E)j++;if(O===y)j--;if(j===0&&O===d)k.push(h.slice(0,-1)),h=""}if(h)k.push(h);return k},m=(g,d=",")=>{let E=[],y=g.length,j=d.length,h=0,k=(O)=>{if(O+j>y)return!1;for(let S=0;S<j;S++)if(g[O+S]!==d[S])return!1;return!0};while(h<y){while(h<y&&g[h]===" ")h++;if(h>=y)break;let O="",S=g[h]==='"'||g[h]==="'";if(S){let M=g[h++];while(h<y&&g[h]!==M)O+=g[h++];if(h<y)h++}else{while(h<y&&!k(h)){let M=g[h];if(M==='"'||M==="'"){O+=M,h++;while(h<y&&g[h]!==M)O+=g[h++];if(h<y)O+=g[h++]}else O+=g[h++]}O=O.trim()}if(O)E.push({value:O,quoted:S});if(k(h))h+=j}return E}}),rn=Jr(tn(),1),I;((e)=>{e[e.Explore=0]="Explore",e[e.SkipSiblings=1]="SkipSiblings",e[e.NoExplore=2]="NoExplore",e[e.ReplaceParent=3]="ReplaceParent",e[e.DeleteParent=4]="DeleteParent",e[e.MergeParent=5]="MergeParent",e[e.ReplaceItem=6]="ReplaceItem",e[e.DeleteItem=7]="DeleteItem"})(I||={});class F{action;by;skipSiblings;reexplore;constructor(e,t,r,n){this.action=e,this.by=t,this.skipSiblings=r,this.reexplore=n}static _explore=new F(0);static _noExplore=new F(2);static _skipSiblings=new F(1);static _deleteParent=new F(4);static ReplaceParent(e,t){return new F(3,e,void 0,t)}static SkipSiblings(){return F._skipSiblings}static Explore(){return F._explore}static NoExplore(){return F._noExplore}static DeleteParent(){return F._deleteParent}static MergeParent(e){return new F(5,e)}static ReplaceItem(e,t){return new F(6,e,t)}static DeleteItem(e){return new F(7,void 0,e)}}var nn=async(e,t)=>{let r=new WeakSet,n=[],o=[],s=async(a,u,b)=>{let w=a===null,m=w?F.Explore():await t({key:a,value:u,path:n,parent:b,parents:o});if(u&&typeof u==="object"&&m.action===0){if(r.has(u))return m;if(r.add(u),!w)n.push(a),o.push(b);let g=u;while(await l(g,a,b))g=b[a];if(!w)o.pop(),n.pop()}return m},l=async(a,u,b)=>{let w=Object.keys(a),m=w.length;for(let g=0;g<m;g++){let d=w[g],E=a[d],y=await s(d,E,a),j=y.action;if(j===0||j===2)continue;if(j===6){if(a[d]=y.by,y.skipSiblings)return;continue}if(j===7){if(delete a[d],y.skipSiblings)return;continue}if(j===1)return;if(j===3){if(u===null)throw Error("Cannot replace root object");if(b[u]=y.by,y.reexplore)return!0;return}if(j===4){if(u===null)throw Error("Cannot delete root object");delete b[u];return}if(j===5)delete a[d],Object.assign(a,y.by)}};await s(null,e,null)},on=Object.create,{getPrototypeOf:sn,defineProperty:Ne,getOwnPropertyNames:an}=Object,ln=Object.prototype.hasOwnProperty,un=(e,t,r)=>{r=e!=null?on(sn(e)):{};let n=t||!e||!e.__esModule?Ne(r,"default",{value:e,enumerable:!0}):r;for(let o of an(e))if(!ln.call(n,o))Ne(n,o,{get:()=>e[o],enumerable:!0});return n},cn=(e,t)=>()=>(t||e((t={exports:{}}).exports,t),t.exports),fn=cn((e,t)=>{var{defineProperty:r,getOwnPropertyNames:n,getOwnPropertyDescriptor:o}=Object,s=Object.prototype.hasOwnProperty,l=new WeakMap,a=(g)=>{var d=l.get(g),E;if(d)return d;if(d=r({},"__esModule",{value:!0}),g&&typeof g==="object"||typeof g==="function")n(g).map((y)=>!s.call(d,y)&&r(d,y,{get:()=>g[y],enumerable:!(E=o(g,y))||E.enumerable}));return l.set(g,d),d},u=(g,d)=>{for(var E in d)r(g,E,{get:d[E],enumerable:!0,configurable:!0,set:(y)=>d[E]=()=>y})},b={};u(b,{splitWithQuotes:()=>m,splitNested:()=>w}),t.exports=a(b);var w=(g,d,E="(",y=")")=>{let j=0,h="",k=[];for(let O of g){if(h+=O,O===E)j++;if(O===y)j--;if(j===0&&O===d)k.push(h.slice(0,-1)),h=""}if(h)k.push(h);return k},m=(g,d=",")=>{let E=[],y=g.length,j=d.length,h=0,k=(O)=>{if(O+j>y)return!1;for(let S=0;S<j;S++)if(g[O+S]!==d[S])return!1;return!0};while(h<y){while(h<y&&g[h]===" ")h++;if(h>=y)break;let O="",S=g[h]==='"'||g[h]==="'";if(S){let M=g[h++];while(h<y&&g[h]!==M)O+=g[h++];if(h<y)h++}else{while(h<y&&!k(h)){let M=g[h];if(M==='"'||M==="'"){O+=M,h++;while(h<y&&g[h]!==M)O+=g[h++];if(h<y)O+=g[h++]}else O+=g[h++]}O=O.trim()}if(O)E.push({value:O,quoted:S});if(k(h))h+=j}return E}}),pn=un(fn(),1),gn=/^\[([^=\]]*)([=]*)([^\]]*)\]$/,mn=/^([^[\]]*)\[([^\]]*)]$/,me=(e,t,r,n)=>{if(e.startsWith("{")&&e.endsWith("}")){let o=e.substring(1,e.length-1);return G(t,o,r)?.toString()}return n?e:void 0},yn=(e,t,r,n)=>{let o=me(t,r,n);if(o)return G(e,o,n);let s=gn.exec(t);if(s){let[,a,u,b]=s,w=me(a.trim(),r,n,!0),m=me(b.trim(),r,n,!0);if(Array.isArray(e)&&(u==="="||u==="==")&&w)return e.find((g)=>g?.[w]==m)}let l=mn.exec(t);if(l){let[,a,u]=l;return e?.[a]?.[u]}return e?.[t]},G=(e,t,r)=>{let n=void 0,o=void 0,s=t??"",l=(m)=>{if(!m)return[m,!1];return m.endsWith("?")?[m.substring(0,m.length-1),!0]:[m,!1]},a=(m,g)=>{let[d,E]=l(g.pop());if(!d){if(r?.set!==void 0&&o!==void 0&&n!==void 0)n[o]=r.set;return m}let y=yn(m,d,e,r);if(y===void 0){if(E||r?.optional||r?.defaultValue!==void 0)return;throw Error(`Unknown path element: "${d}" in "${s}"`)}return n=m,o=d,a(y,g)},u=pn.splitNested(s,r?.separator??".","{","}"),b=void 0;if(u.length>0&&u[u.length-1].startsWith("?="))b=u.pop()?.substring(2);u.reverse();let w=a(e,u);if(w===void 0)return b??r?.defaultValue;return w},We=(e,t)=>{if(typeof e.value==="string"){if(e.quoted)return e.value;if(e.value.startsWith("[")&&e.value.endsWith("]")){let r=e.value.slice(1,-1);if(r.trim()==="")return[];return r.split(";").map((n)=>{let o=n.trim();if(!isNaN(+o))return+o;return o})}if(e.value.startsWith("{")&&e.value.endsWith("}")){if(e.value.slice(1,-1).trim()==="")return{}}if(e.value==="null")return null;if(e.value==="undefined")return;if(e.value.startsWith("@"))return e.value.slice(1);if(!isNaN(+e.value))return+e.value}return t(e.value)},ne=(e,t,r,n,o,s)=>{let l=n?.(e)??e,a=o(l);if(a[0])return a[1];if(!t){let u=G(r,e),b=o(u);if(b[0])return b[1]}throw Error(s)},Le=(e,t,r,n,o)=>{let s=typeof e.types==="function"?e.types(n,t.value,o):e.types?.[n];if(!s||s==="ref")return We(t,(a)=>G(r,a));let l=We(t,()=>t.value);if(Array.isArray(s)){if(!s.includes(l))throw Error(`Argument ${n.toString()} must be one of [${s.join(", ")}]: ${l}`);return l}if(typeof s==="string"){if(s.endsWith("?")){let a=s.slice(0,-1);if(t.value==="null")return F.ReplaceItem(null);if(t.value==="undefined")return F.ReplaceItem(void 0);if(t.value==="")return"";s=a}switch(s){case"any":return l;case"array":return ne(l,t.quoted,r,null,(a)=>[Array.isArray(a),a],`Argument ${n.toString()} must be an array: ${l}`);case"object":return ne(l,t.quoted,r,null,(a)=>[typeof a==="object"&&a!==null,a],`Argument ${n.toString()} must be an object: ${l}`);case"number":return ne(l,t.quoted,r,(a)=>Number(a),(a)=>[!isNaN(a),a],`Argument ${n.toString()} must be a number: ${l}`);case"boolean":return ne(l,t.quoted,r,null,(a)=>{if([!0,"true","1",1,"yes","on"].includes(a))return[!0,!0];if([!1,"false","0",0,"no","off"].includes(a))return[!0,!1];if([null,"null","undefined",void 0,""].includes(a))return[!0,!1];if(Array.isArray(a))return[!0,a.length>0];return[!1,!1]},`Argument ${n.toString()} must be a boolean: ${l}`);case"string":return l.toString();default:throw Error(`Unknown type for argument ${n.toString()}: ${s}`)}}return s(l,r,n,t.quoted)},_e=(e,t)=>{let r=e?.[t];if(r===void 0)throw Error(`Unhandled field processor type: ${t}`);return typeof r==="function"?{options:{},fn:r}:{options:r,fn:r.fn}},Ue=(e)=>!e.quoted&&e.value.startsWith("."),dn=(e)=>{let t={};for(let r of e){if(!Ue(r))continue;let n=r.value.indexOf("="),o=n>-1?r.value.slice(1,n):r.value.slice(1),s=n>-1?r.value.slice(n+1):"";if(s.length>=2){let l=s[0],a=s[s.length-1];if(l==='"'&&a==='"'||l==="'"&&a==="'")s=s.slice(1,-1)}if(!t[o])t[o]=[];t[o].push(s)}return t},hn=(e,t,r)=>{let n=rn.splitWithQuotes(e??""),o=dn(n),s=n.filter((a)=>!Ue(a)),l=t.options.processArgs===!1?[]:s.map((a,u)=>Le(t.options,a,r,u,s));return{rawArgs:s,parsedArgs:l,tags:o}},bn=(e)=>{return e!==null&&typeof e==="object"&&"action"in e},wn=(e,t)=>t.keys!==void 0&&e.key.startsWith(".")&&t.keys[e.key.substring(1)]!==void 0,On=async(e,t,r,n)=>{let{key:o,parent:s}=e,l=_e(n.keys,o.substring(1));if(l.options.processArgs!==!1&&(typeof l.options.types==="function"||l.options.types?.[0]!==void 0))e.value=Le(l.options,{value:e.value,quoted:!1},r,0,[]);if(typeof e.value!=="string")await R(e.value,{...n,root:{...r,parent:e.parent,parents:e.parents},filters:[...n.filters??[],...l.options.filters??[]]});let a=await l.fn({path:t,root:r,parent:s,key:o,options:n,value:e.value,args:[],rawArgs:[],tags:{}});return bn(a)?a:F.ReplaceParent(a)},Ie=(e)=>{let t=e.split(/\r?\n/),r=t.filter((o)=>o.trim().length>0).map((o)=>/^[ \t]*/.exec(o)?.[0].length??0),n=r.length>0?Math.min(...r):0;if(n===0)return e;return t.map((o)=>o.slice(n)).join(`
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
`).
|
|
5
|
-
`)
|
|
6
|
-
`))
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
(${n})`)}}),e},Ye=(e,t)=>t?{fn:(r)=>e(...r.args),types:t}:(r)=>e(...r.args),Hn=(e,t)=>Object.fromEntries(e.map((r)=>[r.name,Ye(r,t?.types?.[r.name])])),T=(e,t)=>Object.fromEntries((t?.keys??Object.keys(e)).map((r)=>[r,Ye(e[r],t?.types?.[r])]));import Ge from"fs/promises";import de from"path";import Fn from"fs/promises";import Dn from"path";import Rn from"fs/promises";import Cn from"fs/promises";import Qe from"fs/promises";import Te from"path";import Nn from"fs/promises";import he from"path";import Ve from"path";var we=async(e)=>{try{return await Ge.access(e,Ge.constants.R_OK),!0}catch{return!1}},oe=async(e,t)=>{let r=!de.isAbsolute(e)&&t?["",...t]:[""];for(let n of r){let o=de.join(n,e);if(await we(o))return de.resolve(o)}throw Error(`File not found: "${e}"`)},Xe=async(e,t)=>{let r=await oe(e,t?.dirs),n=await Fn.readFile(r,"utf-8"),o=Dn.dirname(r),s={text:{fn:(a)=>a,matching:["\\.txt$","\\.text$"]},json:{fn:JSON.parse,matching:["\\.json$"]},...t?.parsers},l=t?.format?s[t.format]:Object.values(s).find((a)=>a.matching?.some((u)=>new RegExp(u).test(e)));if(!l)throw Error(`Unsupported format for file "${e}" and no matching parser found`);return{content:await l.fn(n),fullPath:r,folderPath:o}},$n=async(e,t,r)=>{let n={text:{fn:(s)=>s,matching:["\\.txt$","\\.text$"]},json:{fn:JSON.stringify,matching:["\\.json$"]},...r?.encoders},o=r?.format?n[r.format]:Object.values(n).find((s)=>s.matching?.some((l)=>new RegExp(l).test(e)));if(!o)throw Error(`Unsupported format for file "${e}" and no matching encoder found`);await Rn.writeFile(e,await o.fn(t))},He=async(e,t)=>{if(typeof e==="string"&&!e.includes("*"))return await t.map(e,0,[]);let r=await Array.fromAsync(Cn.glob(e,{cwd:t.cwd})),n=t.filter?r.filter(t.filter):r;return await Promise.all(n.map(t.map))},ze=async(e,t)=>{if(t?.targetDirectory&&t?.removeFirst)try{await Qe.rm(t?.targetDirectory,{recursive:!0,force:!0})}catch(r){throw Error(`Failed to clean the output directory: ${r.message}`)}for(let r of e)await xn(r,t)},xn=async(e,t)=>{let r=Te.join(t?.targetDirectory??".",e.name),n=Te.dirname(r);if(t?.classes){if(e.class!==void 0&&!t.classes.includes(e.class))return;if(t.classRequired&&e.class===void 0)throw Error(`Output "${e.name}" is missing class field`)}if(t?.writing?.(e)===!1)return;try{await Qe.mkdir(n,{recursive:!0})}catch(o){throw Error(`Failed to create target directory "${n}" for output "${r}": ${o.message}`)}try{await $n(r,e.value,{format:e.type??"text"})}catch(o){throw Error(`Failed to write output "${r}": ${o.message}`)}},be=(e)=>e?Ve.isAbsolute(e)?e:Ve.join(process.cwd(),e):process.cwd(),Wn=async(e,t)=>{let r=[];for(let n of e)try{let o=!he.isAbsolute(n)?he.join(be(t?.cwd),n):n;if(t?.filter?.(o)===!1)continue;let s=await import(o);if(t?.resolveDefault==="only"&&!s.default)throw Error(`Module ${n} does not have a default export`);let l=t?.resolveDefault?s.default??s:s,a=t?.map?await t.map(l,n):l;if(a!==void 0)r.push(a)}catch(o){if(t?.fail?.(n,o)===!1)continue;throw Error(`Failed to import module ${n}: ${o.message??o}`)}return r},ao=async(e,t)=>{let r=[];for(let n of e){let o=(await Array.fromAsync(Nn.glob(n,{cwd:be(t?.cwd)}))).map((s)=>he.join(be(t?.cwd),s));r.push(...await Wn(o,t))}return r};class V{o;context;constructor(e){this.o=e}}var f=(e)=>(t,r)=>{r.addInitializer(function(){let n=this[r.name],o=e?.name??r.name;this.o.sources({[o]:(s)=>n.apply({...this,context:s},s.args)})})},uo=(e)=>(t,r)=>{r.addInitializer(function(){let n=this[r.name],o=e?.name??r.name;this.o.sections({[o]:(s)=>{return n.call({...this,context:s},s.section)}})})},co=(e)=>(t,r)=>{r.addInitializer(function(){let n=this[r.name],o=e?.name??r.name;this.o.keys({[o]:(s)=>n.call({...this,context:s},s.value)})})},fo=(e)=>(t,r)=>{r.addInitializer(function(){let n=this[r.name],o=e?.name??r.name;this.o.variables({[o]:n})})},po=(e)=>(t,r)=>{r.addInitializer(function(){let n=this[r.name],o=e?.name??r.name;this.o.functions({[o]:n})})},go=(e)=>(t,r)=>{r.addInitializer(function(){let n=this[r.name],o=e?.name??r.name;this.o.encoders({[o]:{fn:n}})})},mo=(e)=>(t,r)=>{r.addInitializer(function(){let n=this[r.name],o=e?.name??r.name;this.o.decoders({[o]:{fn:n}})})};import{createHash as U}from"crypto";import N from"path";var Ze=(e)=>({output:(t)=>{delete t.parent[t.key];for(let r of Array.isArray(t.value)?t.value:[t.value])if(typeof r==="string")e.output({name:r,value:t.parent});else e.output({...r,value:r.value??t.parent});return v.SkipSiblings()}});import In from"path";var Pe=(e)=>({load:async(t)=>{let r=t.options.globalContext;for(let{file:n}of Array.isArray(t.value)?t.value:[t.value]){if(!n)throw Error("File reference required");await e.load(n,r.file&&In.dirname(r.file))}return v.DeleteItem()}});class Oe{cache=new Map;maxSize;constructor(e=100){this.maxSize=e}get(e){return this.cache.get(e)}set(e,t){this.evictIfNeeded(),this.cache.set(e,t)}has(e){return this.cache.has(e)}clear(){this.cache.clear()}setMaxSize(e){this.maxSize=e}size(){return this.cache.size}evictIfNeeded(){if(this.cache.size>=this.maxSize){let e=null,t=1/0;for(let[r,n]of this.cache.entries())if(n.timestamp<t)t=n.timestamp,e=r;if(e)this.cache.delete(e)}}}var ie=(e)=>{if(typeof e.value==="string")return e.parent;let t=e.value.model;if(!t)return e.parent;if(typeof t==="string")return Object.select(e.root,t);return t};var se=(e)=>{if(typeof e.value==="string")return Object.select(e.root,e.value);if(Array.isArray(e.value))return e.value;let t=e.value;if(typeof t.from==="string")return Object.select(e.root,t.from);return t.from};var ae=async(e,t)=>{let r=e.value;if(r.selector===void 0)return t;if(typeof r.selector!=="string"){let n=JSON.parse(JSON.stringify(r.selector));return await R(n,{...e.options,root:{...e.root,result:t}}),n}return await Object.select({...e.root,result:t},r.selector)};import L from"path";class _{constructor(){}static normalize(e){return L.normalize(L.resolve(e))}static resolveInContext(e,t){let r=t??process.cwd(),n=L.isAbsolute(e)?e:L.join(r,e);return this.normalize(n)}static isDirectoryPattern(e){return e.endsWith("/")}static isGlobPattern(e){return e.includes("*")}static toAbsolute(e,t){if(L.isAbsolute(e))return e;return L.join(t??process.cwd(),e)}}var x={and:(...e)=>e.every((t)=>!!t),or:(...e)=>e.some((t)=>!!t),xor:(...e)=>e.filter((t)=>!!t).length===1,true:(...e)=>e.every((t)=>!!t),false:(...e)=>e.every((t)=>!t),eq:(...e)=>e.every((t)=>t===e[0]),ne:(...e)=>e.some((t)=>t!==e[0]),lt:(...e)=>typeof e[0]==="number"&&e.slice(1).every((t)=>typeof t==="number"&&e[0]<t),le:(...e)=>typeof e[0]==="number"&&e.slice(1).every((t)=>typeof t==="number"&&e[0]<=t),gt:(...e)=>typeof e[0]==="number"&&e.slice(1).every((t)=>typeof t==="number"&&e[0]>t),ge:(...e)=>typeof e[0]==="number"&&e.slice(1).every((t)=>typeof t==="number"&&e[0]>=t),in:(e,t)=>{if(Array.isArray(t))return t.includes(e);if(typeof e==="string")return e.includes(t);if(Array.isArray(e))return e.includes(t);return!1},notin:(e,t)=>!x.in(e,t),contains:(e,t)=>e.includes(t),notcontains:(e,t)=>!e.includes(t),containsi:(e,t)=>e.toLowerCase().includes(t.toLowerCase()),notcontainsi:(e,t)=>!e.toLowerCase().includes(t.toLowerCase()),null:(...e)=>e.every((t)=>t===null||t===void 0),notnull:(...e)=>e.every((t)=>t!==null&&t!==void 0),empty:(...e)=>e.every((t)=>t===""),notempty:(...e)=>e.every((t)=>t!==""),nullorempty:(...e)=>e.every((t)=>t===null||t===void 0||t===""),notnullorempty:(...e)=>e.every((t)=>t!==null&&t!==void 0&&t!=="")},le={and:()=>"boolean",or:()=>"boolean",xor:()=>"boolean",true:()=>"boolean",false:()=>"boolean",lt:()=>"number",le:()=>"number",gt:()=>"number",ge:()=>"number"};var Je=()=>({each:{filters:[/select|model/],fn:async(e)=>{let t=e.value;delete e.parent[e.key];let r=await se(e),n=await ie(e);if(!Array.isArray(r))throw Error('Key "each" requires a source list');if(n===void 0)throw Error('Key "each" must define a model');if(t.extend?.model)n=[t.model,...Array.isArray(t.extend.model)?t.extend.model:[t.extend.model]].mergeAll();let o=[];for(let s=0;s<r.length;s++){let l=Object.deepClone(n);if(await R(l,{...e.options,root:{...e.root,index:s,item:r[s],instance:l}}),t.extend?.result){let a=t.extend.result;l=[l,...Array.isArray(a)?a:[a]].mergeAll()}o.push(await ae(e,l))}return o}}});var et=()=>({map:{filters:[/select|model/],fn:async(e)=>{delete e.parent[e.key];let t=await se(e),r=await ie(e);if(!Array.isArray(t))throw Error('Key "map" requires a source list');if(r===void 0)throw Error('Key "map" must define a model');let n=[];for(let o=0;o<t.length;o++){let s=Object.deepClone(r);await R(s,{...e.options,root:{...e.root,index:o,item:t[o],instance:s}}),n.push(await ae(e,s))}return n}}});var tt=()=>({concat:async(e)=>{let t=[];for(let r of Array.isArray(e.value)?e.value:[e.value])t.push(...await Object.select(e.root,r));return t.filter((r)=>r!==void 0)}});Array.prototype.findOrFail=function(e,t,r){let n=this.find(e,r);if(n===void 0)throw Error(t??"Element not found");return n};Array.flat=function(e){if(Array.isArray(e))return e.flat(2);else return[e]};Array.prototype.forEachAsync=async function(e){for(let t=0;t<this.length;t++)await e(this[t],t,this)};Array.prototype.groupBy=function(e){return this.reduce((t,r)=>{let n=e(r);if(!t[n])t[n]=[];return t[n].push(r),t},{})};Array.prototype.createInstances=function(e,...t){return this.map((r,n)=>new e(...t,r,n))};Array.prototype.mapAsync=async function(e){return Promise.all(this.map(e))};Array.prototype.nonNullMap=function(e){let t=[];for(let r=0;r<this.length;r++){let n=e(this[r],r,this);if(n!=null)t.push(n)}return t};Array.prototype.nonNullMapAsync=async function(e){let t=[];for(let r=0;r<this.length;r++){let n=await e(this[r],r,this);if(n!=null)t.push(n)}return t};Array.prototype.mergeAll=function(e){let t={};for(let r of this.toReversed())Object.merge(r,t,e);return t};Array.prototype.toObject=function(e,t){return Object.fromEntries(this.map((r)=>{let n=e(r),o=t?t(r):r;return[n,o]}))};Array.prototype.toObjectWithKey=function(e){return Object.fromEntries(this.map((t)=>[String(t[e]),t]))};Array.prototype.selectFor=function(e,t,r,n){let o=this.find(e,n);if(o===void 0)throw Error(r??"Element not found");return t(o)};Array.prototype.sortBy=function(e,t=!0){return this.slice().sort((r,n)=>{let o=e(r),s=e(n);if(o<s)return t?-1:1;if(o>s)return t?1:-1;return 0})};Array.prototype.unique=function(){return Array.from(new Set(this))};Array.prototype.uniqueBy=function(e){let t=new Set;return this.filter((r)=>{let n=e(r);if(t.has(n))return!1;else return t.add(n),!0})};var Ln;((e)=>{e[e.Explore=0]="Explore",e[e.SkipSiblings=1]="SkipSiblings",e[e.NoExplore=2]="NoExplore",e[e.ReplaceParent=3]="ReplaceParent",e[e.DeleteParent=4]="DeleteParent",e[e.MergeParent=5]="MergeParent",e[e.ReplaceItem=6]="ReplaceItem",e[e.DeleteItem=7]="DeleteItem"})(Ln||={});class v{action;by;skipSiblings;reexplore;constructor(e,t,r,n){this.action=e,this.by=t,this.skipSiblings=r,this.reexplore=n}static _explore=new v(0);static _noExplore=new v(2);static _skipSiblings=new v(1);static _deleteParent=new v(4);static ReplaceParent(e,t){return new v(3,e,void 0,t)}static SkipSiblings(){return v._skipSiblings}static Explore(){return v._explore}static NoExplore(){return v._noExplore}static DeleteParent(){return v._deleteParent}static MergeParent(e){return new v(5,e)}static ReplaceItem(e,t){return new v(6,e,t)}static DeleteItem(e){return new v(7,void 0,e)}}Object.navigate=async(e,t)=>{let r=new WeakSet,n=[],o=[],s=async(a,u,b)=>{let w=a===null,m=w?v.Explore():await t({key:a,value:u,path:n,parent:b,parents:o});if(u&&typeof u==="object"&&m.action===0){if(r.has(u))return m;if(r.add(u),!w)n.push(a),o.push(b);let g=u;while(await l(g,a,b))g=b[a];if(!w)o.pop(),n.pop()}return m},l=async(a,u,b)=>{let w=Object.keys(a),m=w.length;for(let g=0;g<m;g++){let d=w[g],E=a[d],y=await s(d,E,a),j=y.action;if(j===0||j===2)continue;if(j===6){if(a[d]=y.by,y.skipSiblings)return;continue}if(j===7){if(delete a[d],y.skipSiblings)return;continue}if(j===1)return;if(j===3){if(u===null)throw Error("Cannot replace root object");if(b[u]=y.by,y.reexplore)return!0;return}if(j===4){if(u===null)throw Error("Cannot delete root object");delete b[u];return}if(j===5)delete a[d],Object.assign(a,y.by)}};await s(null,e,null)};Object.find=async function(e,t){let r=[];return await Object.navigate(e,(n)=>{if(t([...n.path,n.key].join("."),n.value))r.push(n.value);return v.Explore()}),r};Object.merge=(e,t,r)=>{for(let n of Object.keys(t)){if(e[n]===void 0)continue;let o=t[n],s=e[n];if(typeof s!==typeof o||Array.isArray(s)!==Array.isArray(o)){let a=r?.mismatch?.(n,s,o,e,t);if(a!==void 0){t[n]=a;continue}throw Error(`Type mismatch: ${n}`)}let l=r?.mode?.(n,s,o,e,t)??t[".merge"]??"merge";switch(l){case"source":t[n]=s;continue;case"target":continue;case"skip":delete t[n],delete e[n];continue;case"merge":break;default:throw Error(`Unknown merge mode: ${l}`)}if(typeof s==="object")if(Array.isArray(s))o.push(...s);else{if(r?.navigate?.(n,s,o,e,t)===!1)continue;Object.merge(s,o,r)}else{if(s===o)continue;let a=r?.conflict?.(n,s,o,e,t);t[n]=a===void 0?o:a}}for(let n of Object.keys(e))if(t[n]===void 0)t[n]=e[n]};var _n=/^\[([^=\]]*)([=]*)([^\]]*)\]$/,Un=/^([^[\]]*)\[([^\]]*)]$/,Ae=(e,t,r,n)=>{if(e.startsWith("{")&&e.endsWith("}")){let o=e.substring(1,e.length-1);return Object.select(t,o,r)?.toString()}return n?e:void 0},Bn=(e,t,r,n)=>{let o=Ae(t,r,n);if(o)return Object.select(e,o,n);let s=_n.exec(t);if(s){let[,a,u,b]=s,w=Ae(a.trim(),r,n,!0),m=Ae(b.trim(),r,n,!0);if(Array.isArray(e)&&(u==="="||u==="==")&&w)return e.find((g)=>g?.[w]==m)}let l=Un.exec(t);if(l){let[,a,u]=l;return e?.[a]?.[u]}return e?.[t]};Object.select=(e,t,r)=>{let n=void 0,o=void 0,s=t??"",l=(m)=>{if(!m)return[m,!1];return m.endsWith("?")?[m.substring(0,m.length-1),!0]:[m,!1]},a=(m,g)=>{let[d,E]=l(g.pop());if(!d){if(r?.set!==void 0&&o!==void 0&&n!==void 0)n[o]=r.set;return m}let y=Bn(m,d,e,r);if(y===void 0){if(E||r?.optional||r?.defaultValue!==void 0)return;throw Error(`Unknown path element: "${d}" in "${s}"`)}return n=m,o=d,a(y,g)},u=s.splitNested(r?.separator??".","{","}"),b=void 0;if(u.length>0&&u[u.length-1].startsWith("?="))b=u.pop()?.substring(2);u.reverse();let w=a(e,u);if(w===void 0)return b??r?.defaultValue;return w};Object.deepClone=function(e){if(typeof structuredClone<"u")try{return structuredClone(e)}catch{}return JSON.parse(JSON.stringify(e))};Object.toList=function(e,t){return Object.entries(e).map(([r,n])=>({[t]:r,...n}))};Object.mapEntries=function(e,t){let r=Object.entries(e).map(([n,o])=>t(n,o));return Object.fromEntries(r)};global.AsyncFunction=Object.getPrototypeOf(async function(){}).constructor;global.defined=(e,t="Value is undefined")=>{if(e===void 0||e===null)throw Error(t);return e};String.prototype.tokenize=function(e,t=/\${([^}]+)}/g){return this.replace(t,(r,n)=>{let o=e[n];if(o===null||o===void 0)return"";if(typeof o==="string")return o;if(typeof o==="number"||typeof o==="boolean")return String(o);return String(o)})};String.prototype.toPascal=function(){return this.replace(/((?:[_ ]+)\w|^\w)/g,(e,t)=>t.toUpperCase()).replace(/[_ ]/g,"")};String.prototype.capitalize=function(){return this.replace(/((?:[ ]+)\w|^\w)/g,(e,t)=>t.toUpperCase())};String.prototype.toCamel=function(){return this.toPascal().replace(/((?:[ ]+\w)|^\w)/g,(e,t)=>t.toLowerCase())};String.prototype.toSnake=function(){return this.replace(/([a-z])([A-Z])/g,"$1_$2").replace(/\s+/g,"_")};String.prototype.toKebab=function(){return this.replace(/([a-z])([A-Z])/g,"$1-$2").replace(/\s+/g,"-")};String.prototype.changeCase=function(e){switch(e){case"upper":return this.toUpperCase();case"lower":return this.toLowerCase();case"pascal":return this.toPascal();case"camel":return this.toCamel();case"snake":return this.toSnake();case"kebab":return this.toKebab();default:throw Error(`Unsupported case type: ${e}`)}};String.prototype.splitWithQuotes=function(e=","){let t=[],r=this.length,n=e.length,o=0,s=(l)=>{if(l+n>r)return!1;for(let a=0;a<n;a++)if(this[l+a]!==e[a])return!1;return!0};while(o<r){while(o<r&&this[o]===" ")o++;if(o>=r)break;let l="",a=this[o]==='"'||this[o]==="'";if(a){let u=this[o++];while(o<r&&this[o]!==u)l+=this[o++];if(o<r)o++}else{while(o<r&&!s(o)){let u=this[o];if(u==='"'||u==="'"){l+=u,o++;while(o<r&&this[o]!==u)l+=this[o++];if(o<r)l+=this[o++]}else l+=this[o++]}l=l.trim()}if(l)t.push({value:l,quoted:a});if(s(o))o+=n}return t};String.prototype.splitNested=function(e,t,r){let n=0,o="",s=[];for(let l of this){if(o+=l,l===t)n++;if(l===r)n--;if(n===0&&l===e)s.push(o.slice(0,-1)),o=""}if(o)s.push(o);return s};String.prototype.padBlock=function(e,t=`
|
|
10
|
-
|
|
11
|
-
`)
|
|
12
|
-
`)),r},
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
${e.map((l)=>`${o}${ue(l,t+1)},`).join(`
|
|
1
|
+
var Yt=Object.create;var Cr=Object.defineProperty;var qt=Object.getOwnPropertyDescriptor;var Mr=(r,e)=>{return Object.defineProperty(r,"name",{value:e,enumerable:!1,configurable:!0}),r};var kr=(r,e)=>(e=Symbol[r])?e:Symbol.for("Symbol."+r),Y=(r)=>{throw TypeError(r)},Gt=(r,e,t)=>(e in r)?Cr(r,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):r[e]=t;var yr=(r,e,t)=>e.has(r)||Y("Cannot "+t),Ht=(r,e)=>Object(e)!==e?Y('Cannot use the "in" operator on this value'):r.has(e),Dr=(r,e,t)=>(yr(r,e,"read from private field"),t?t.call(r):e.get(r));var Pr=(r,e,t,n)=>(yr(r,e,"write to private field"),n?n.call(r,t):e.set(r,t),t),zt=(r,e,t)=>(yr(r,e,"access private method"),t),$r=(r)=>[,,,Yt(r?.[kr("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,o)=>({kind:Rr[r],name:e,metadata:n,addInitializer:(s)=>t._?Y("Already initialized"):o.push(K(s||null))}),lr=(r,e)=>Gt(e,kr("metadata"),r[3]),Lr=(r,e,t,n)=>{for(var o=0,s=r[e>>1],a=s&&s.length;o<a;o++)e&1?s[o].call(t):n=s[o].call(t,n);return n},u=(r,e,t,n,o,s)=>{var a,f,y,g,b,l=e&7,O=!!(e&8),h=!!(e&16),P=l>3?r.length+1:l?O?1:2:0,w=Rr[l+5],j=l>3&&(r[P-1]=[]),C=r[P]||(r[P]=[]),A=l&&(!h&&!O&&(o=o.prototype),l<5&&(l>3||!h)&&qt(l<4?o:{get[t](){return Dr(this,s)},set[t](E){Pr(this,s,E)}},t));l?h&&l<4&&Mr(s,(l>2?"set ":l>1?"get ":"")+t):Mr(o,t);for(var D=n.length-1;D>=0;D--){if(g=Qt(l,t,y={},r[3],C),l){if(g.static=O,g.private=h,b=g.access={has:h?(E)=>Ht(o,E):(E)=>(t in E)},l^3)b.get=h?(E)=>(l^1?Dr:zt)(E,o,l^4?s:A.get):(E)=>E[t];if(l>2)b.set=h?(E,S)=>Pr(E,o,S,l^4?s:A.set):(E,S)=>E[t]=S}if(f=(0,n[D])(l?l<4?h?s:A[w]:l>4?void 0:{get:A.get,set:A.set}:o,g),y._=1,l^4||f===void 0)K(f)&&(l>4?j.unshift(f):l?h?s=f:A[w]=f:o=f);else if(typeof f!=="object"||f===null)Y("Object expected");else K(a=f.get)&&(A.get=a),K(a=f.set)&&(A.set=a),K(a=f.init)&&j.unshift(a)}return l||lr(r,o),A&&Cr(o,t,A),h?l^4?s:A:o};import Ur from"fs/promises";import pr from"path";import Zt from"fs/promises";import Tt from"path";import Xt from"fs/promises";import Vt from"fs/promises";import Wr from"fs/promises";import _r from"path";import rn from"fs/promises";import gr from"path";import Br from"path";var br=async(r)=>{try{return await Ur.access(r,Ur.constants.R_OK),!0}catch{return!1}},er=async(r,e)=>{let t=!pr.isAbsolute(r)&&e?["",...e]:[""];for(let n of t){let o=pr.join(n,r);if(await br(o))return pr.resolve(o)}throw Error(`File not found: "${r}"`)},Ir=async(r,e)=>{let t=await er(r,e?.dirs),n=await Zt.readFile(t,"utf-8"),o=Tt.dirname(t),s={text:{fn:(f)=>f,matching:["\\.txt$","\\.text$"]},json:{fn:JSON.parse,matching:["\\.json$"]},...e?.parsers},a=e?.format?s[e.format]:Object.values(s).find((f)=>f.matching?.some((y)=>new RegExp(y).test(r)));if(!a)throw Error(`Unsupported format for file "${r}" and no matching parser found`);return{content:await a.fn(n),fullPath:t,folderPath:o}},xt=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((a)=>new RegExp(a).test(r)));if(!o)throw Error(`Unsupported format for file "${r}" and no matching encoder found`);await Xt.writeFile(r,await o.fn(e))},Nr=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))},Jr=async(r,e)=>{if(e?.targetDirectory&&e?.removeFirst)try{await Wr.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 vt(t,e)},vt=async(r,e)=>{let t=_r.join(e?.targetDirectory??".",r.name),n=_r.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 Wr.mkdir(n,{recursive:!0})}catch(o){throw Error(`Failed to create target directory "${n}" for output "${t}": ${o.message}`)}try{await xt(t,r.value,{format:r.type??"text"})}catch(o){throw Error(`Failed to write output "${t}": ${o.message}`)}},dr=(r)=>r?Br.isAbsolute(r)?r:Br.join(process.cwd(),r):process.cwd(),en=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 a=e?.resolveDefault?s.default??s:s,f=e?.map?await e.map(a,n):a;if(f!==void 0)t.push(f)}catch(o){if(e?.fail?.(n,o)===!1)continue;throw Error(`Failed to import module ${n}: ${o.message??o}`)}return t},$n=async(r,e)=>{let t=[];for(let n of r){let o=(await Array.fromAsync(rn.glob(n,{cwd:dr(e?.cwd)}))).map((s)=>gr.join(dr(e?.cwd),s));t.push(...await en(o,e))}return t};class q{o;context;constructor(r){this.o=r}}var m=(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)})})},Ln=(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)}})})},Un=(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)})})},_n=(r)=>(e,t)=>{t.addInitializer(function(){let n=this[t.name],o=r?.name??t.name;this.o.variables({[o]:n})})},Bn=(r)=>(e,t)=>{t.addInitializer(function(){let n=this[t.name],o=r?.name??t.name;this.o.functions({[o]:n})})},In=(r)=>(e,t)=>{t.addInitializer(function(){let n=this[t.name],o=r?.name??t.name;this.o.encoders({[o]:{fn:n}})})},Nn=(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 Kr=(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 p.SkipSiblings()}});import tn from"path";var Yr=(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&&tn.dirname(t.file))}return p.DeleteItem()}});class hr{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)=>{if(typeof r.value==="string")return r.parent;let e=r.value.model;if(!e)return r.parent;if(typeof e==="string")return Object.select(r.root,e);return e};var nr=(r)=>{if(typeof r.value==="string")return Object.select(r.root,r.value);if(Array.isArray(r.value))return r.value;let e=r.value;if(typeof e.from==="string")return Object.select(r.root,e.from);return e.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 R;((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"})(R||={});class p{action;by;skipSiblings;reexplore;constructor(r,e,t,n){this.action=r,this.by=e,this.skipSiblings=t,this.reexplore=n}static _explore=new p(0);static _noExplore=new p(2);static _skipSiblings=new p(1);static _deleteParent=new p(4);static ReplaceParent(r,e){return new p(3,r,void 0,e)}static SkipSiblings(){return p._skipSiblings}static Explore(){return p._explore}static NoExplore(){return p._noExplore}static DeleteParent(){return p._deleteParent}static MergeParent(r){return new p(5,r)}static ReplaceItem(r,e){return new p(6,r,e)}static DeleteItem(r){return new p(7,void 0,r)}}Object.navigate=async(r,e)=>{let t=new WeakSet,n=[],o=[],s=async(f,y,g)=>{let b=f===null,l=b?p.Explore():await e({key:f,value:y,path:n,parent:g,parents:o});if(y&&typeof y==="object"&&l.action===0){if(t.has(y))return l;if(t.add(y),!b)n.push(f),o.push(g);let O=y;while(await a(O,f,g))O=g[f];if(!b)o.pop(),n.pop()}return l},a=async(f,y,g)=>{let b=Object.keys(f),l=b.length;for(let O=0;O<l;O++){let h=b[O],P=f[h],w=await s(h,P,f),j=w.action;if(j===0||j===2)continue;if(j===6){if(f[h]=w.by,w.skipSiblings)return;continue}if(j===7){if(delete f[h],w.skipSiblings)return;continue}if(j===1)return;if(j===3){if(y===null)throw Error("Cannot replace root object");if(g[y]=w.by,w.reexplore)return!0;return}if(j===4){if(y===null)throw Error("Cannot delete root object");delete g[y];return}if(j===5)delete f[h],Object.assign(f,w.by)}};await s(null,r,null)};Object.find=async function(r,e){let t=[];return await Object.navigate(r,(n)=>{if(e([...n.path,n.key].join("."),n.value))t.push(n.value);return p.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 f=t?.mismatch?.(n,s,o,r,e);if(f!==void 0){e[n]=f;continue}throw Error(`Type mismatch: ${n}`)}let a=t?.mode?.(n,s,o,r,e)??e[".merge"]??"merge";switch(a){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: ${a}`)}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 f=t?.conflict?.(n,s,o,r,e);e[n]=f===void 0?o:f}}for(let n of Object.keys(r))if(e[n]===void 0)e[n]=r[n]};var nn=/^\[([^=\]]*)([=]*)([^\]]*)\]$/,on=/^([^[\]]*)\[([^\]]*)]$/,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},sn=(r,e,t,n)=>{let o=wr(e,t,n);if(o)return Object.select(r,o,n);let s=nn.exec(e);if(s){let[,f,y,g]=s,b=wr(f.trim(),t,n,!0),l=wr(g.trim(),t,n,!0);if(Array.isArray(r)&&(y==="="||y==="==")&&b)return r.find((O)=>O?.[b]==l)}let a=on.exec(e);if(a){let[,f,y]=a;return r?.[f]?.[y]}return r?.[e]};Object.select=(r,e,t)=>{let n=void 0,o=void 0,s=e??"",a=(l)=>{if(!l)return[l,!1];return l.endsWith("?")?[l.substring(0,l.length-1),!0]:[l,!1]},f=(l,O)=>{let[h,P]=a(O.pop());if(!h){if(t?.set!==void 0&&o!==void 0&&n!==void 0)n[o]=t.set;return l}let w=sn(l,h,r,t);if(w===void 0){if(P||t?.optional||t?.defaultValue!==void 0)return;throw Error(`Unknown path element: "${h}" in "${s}"`)}return n=l,o=h,f(w,O)},y=s.splitNested(t?.separator??".","{","}"),g=void 0;if(y.length>0&&y[y.length-1].startsWith("?="))g=y.pop()?.substring(2);y.reverse();let b=f(r,y);if(b===void 0)return g??t?.defaultValue;return b};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=(a)=>{if(a+n>t)return!1;for(let f=0;f<n;f++)if(this[a+f]!==r[f])return!1;return!0};while(o<t){while(o<t&&this[o]===" ")o++;if(o>=t)break;let a="",f=this[o]==='"'||this[o]==="'";if(f){let y=this[o++];while(o<t&&this[o]!==y)a+=this[o++];if(o<t)o++}else{while(o<t&&!s(o)){let y=this[o];if(y==='"'||y==="'"){a+=y,o++;while(o<t&&this[o]!==y)a+=this[o++];if(o<t)a+=this[o++]}else a+=this[o++]}a=a.trim()}if(a)e.push({value:a,quoted:f});if(s(o))o+=n}return e};String.prototype.splitNested=function(r,e,t){let n=0,o="",s=[];for(let a of this){if(o+=a,a===e)n++;if(a===t)n--;if(n===0&&a===r)s.push(o.slice(0,-1)),o=""}if(o)s.push(o);return s};String.prototype.padBlock=function(r,e=`
|
|
2
|
+
`,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(`
|
|
3
|
+
`)};function Xn(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)}}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 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 a=n?.(r)??r,f=o(a);if(f[0])return f[1];if(!e){let y=Object.select(t,r),g=o(y);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 qr(e,(f)=>Object.select(t,f));let a=qr(e,()=>e.value);if(Array.isArray(s)){if(!s.includes(a))throw Error(`Argument ${n.toString()} must be one of [${s.join(", ")}]: ${a}`);return a}if(typeof s==="string"){if(s.endsWith("?")){let f=s.slice(0,-1);if(e.value==="null")return p.ReplaceItem(null);if(e.value==="undefined")return p.ReplaceItem(void 0);if(e.value==="")return"";s=f}switch(s){case"any":return a;case"array":return or(a,e.quoted,t,null,(f)=>[Array.isArray(f),f],`Argument ${n.toString()} must be an array: ${a}`);case"object":return or(a,e.quoted,t,null,(f)=>[typeof f==="object"&&f!==null,f],`Argument ${n.toString()} must be an object: ${a}`);case"number":return or(a,e.quoted,t,(f)=>Number(f),(f)=>[!isNaN(f),f],`Argument ${n.toString()} must be a number: ${a}`);case"boolean":return or(a,e.quoted,t,null,(f)=>{if([!0,"true","1",1,"yes","on"].includes(f))return[!0,!0];if([!1,"false","0",0,"no","off"].includes(f))return[!0,!1];if([null,"null","undefined",void 0,""].includes(f))return[!0,!1];if(Array.isArray(f))return[!0,f.length>0];return[!1,!1]},`Argument ${n.toString()} must be a boolean: ${a}`);case"string":return a.toString();default:throw Error(`Unknown type for argument ${n.toString()}: ${s}`)}}return s(a,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("."),an=(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 a=s[0],f=s[s.length-1];if(a==='"'&&f==='"'||a==="'"&&f==="'")s=s.slice(1,-1)}if(!e[o])e[o]=[];e[o].push(s)}return e},Hr=(r,e,t)=>{let n=(r??"").splitWithQuotes(),o=an(n),s=n.filter((f)=>!Gr(f)),a=e.options.processArgs===!1?[]:s.map((f,y)=>ir(e.options,f,t,y,s));return{rawArgs:s,parsedArgs:a,tags:o}};var un=(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:o,parent:s}=r,a=sr(n.keys,o.substring(1));if(a.options.processArgs!==!1&&(typeof a.options.types==="function"||a.options.types?.[0]!==void 0))r.value=ir(a.options,{value:r.value,quoted:!1},t,0,[]);if(typeof r.value!=="string")await M(r.value,{...n,root:{...t,parent:r.parent,parents:r.parents},filters:[...n.filters??[],...a.options.filters??[]]});let f=await a.fn({path:e,root:t,parent:s,key:o,options:n,value:r.value,args:[],rawArgs:[],tags:{}});return un(f)?f:p.ReplaceParent(f)};var Zr=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,a=r,f=0,y=!1,g={content:a,root:n,path:t,options:e,section:{}};while((s=o.exec(r))!==null){y=!0;let[b,l,O]=s,h=s.index,P=h+b.length,w=r[P]===`
|
|
4
|
+
`;if(w)P++;let j=h+f,C=P+f,A={},D=O,E=/(^|\r?\n)[ \t]*---[ \t]*(\r?\n|$)/m.exec(O);if(E){let W=O.slice(0,E.index),mr=E.index+E[0].length;D=O.slice(mr);let v=W.stripIndent().trim();if(v.length>0)try{A=e?.configParser?.(v)??{}}catch(cr){throw Error(`Failed to parse YAML config for section: ${cr.message}`)}}else if(/^\r?\n/.test(D))D=D.replace(/^\r?\n/,"");D=D.stripIndent().replace(/(?:\r?\n[ \t]*)+$/,"").replace(/[ \t]+$/,"");let S={config:l?{...A,type:l}:A,content:D};if(g.content=a,g.section=S,Object.keys(S.config).length>0){if(await e.onSectionConfig?.(g)!==!1)await M(S.config,{...e,root:n})}let T=g.section.config.type?e.sections?.[g.section.config.type]:void 0,_;if(T)_=await T(g);else if(e.onSection)_=await e.onSection(g);if(S.trim)S.content=S.content.trim();if(S.indent)S.content=S.content.split(`
|
|
5
|
+
`).map((W)=>" ".repeat(S.indent)+W).join(`
|
|
6
|
+
`);let $="";if(_===!0||S.show)$=S.content;else if(typeof _==="string")$=_;if(w&&$!==""&&!$.endsWith(`
|
|
7
|
+
`))$+=`
|
|
8
|
+
`;let X=a.lastIndexOf(`
|
|
9
|
+
`,j-1),x=X===-1?0:X+1,V=a.slice(x,j).trim().length===0?x:j;a=a.slice(0,V)+$+a.slice(C),f+=$.length-(C-V),g.content=a}return[a,y]};var Or=(r)=>{let e=[],t=0;while(t<r.length)if(r[t]==="$"&&r[t+1]==="("&&(t===0||r[t-1]!=="\\")){let n=t;t+=2;let 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}),mn=(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],a=r.slice(o+2,s),f=await Xr(a,Or(a),t);if(typeof f==="object")return f;let y=await t(f,r);if(mn(y))return y.value;r=r.slice(0,o)+y+r.slice(s+1)}return r},xr=async(r,e)=>Xr(r,Or(r),e);var cn=(r)=>{return r!==null&&typeof r==="object"&&"action"in r},yn=/([\w\d.-_/]+):(.+)/,ln=async(r,e,t,n)=>{let o=await(async()=>{let s=yn.exec(r);if(!s)return await Object.select(e,r);let[a,f,y]=s,g=sr(n.sources,f),b=Hr(y,g,e);return await g.fn({args:b.parsedArgs,rawArgs:b.rawArgs,tags:b.tags,key:f,options:n,root:e,path:t,value:null})})();if(o===null||o===void 0)return"";if(typeof o==="object")return Tr(o);return o},jr=async(r,e,t,n)=>{let o=await xr(e,(s)=>ln(s,t,r,n));if(cn(o))return o;if(o===e)return p.Explore();if(typeof o==="string"){let s=await jr(r,o,t,n);if(s.action!==R.Explore)return s;return p.ReplaceItem(o)}return p.ReplaceItem(o)};var M=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((f)=>f.test(n)))return p.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 a={...r,...e.root,this:t.parent,parent:s.length>0?s[0]:null,parents:s};try{if(t.key.startsWith("$"))return p.NoExplore();let f=p.Explore();if(typeof t.value==="string"){let y=t.value,g=!1;while(!0){let[b,l]=await Zr(y,e,n,a);if(g=g||l,f=await jr(n,b,a,e),f.action===R.ReplaceItem&&typeof f.by==="string"){y=f.by;continue}if(f.action===R.Explore&&l&&b!==y)f=p.ReplaceItem(b);break}if(f.action===R.Explore&&y!==t.value)f=p.ReplaceItem(y);switch(f.action){case R.Explore:break;case R.ReplaceItem:t.value=f.by;break;default:return f}}if(zr(t,e))f=await Qr(t,n,a,e);return f}catch(f){throw Error(`${f.message}
|
|
10
|
+
(${n})`)}}),r};var Vr=(r,e)=>e?{fn:(t)=>r(...t.args),types:e}:(t)=>r(...t.args),Po=(r,e)=>Object.fromEntries(r.map((t)=>[t.name,Vr(t,e?.types?.[t.name])])),G=(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 M(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 L={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)=>!L.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!=="")},ar={and:()=>"boolean",or:()=>"boolean",xor:()=>"boolean",true:()=>"boolean",false:()=>"boolean",lt:()=>"number",le:()=>"number",gt:()=>"number",ge:()=>"number"};var vr=()=>({each:{filters:[/select|model/],fn:async(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 a=Object.deepClone(n);if(await M(a,{...r.options,root:{...r.root,index:s,item:t[s],instance:a}}),e.extend?.result){let f=e.extend.result;a=[a,...Array.isArray(f)?f:[f]].mergeAll()}o.push(await fr(r,a))}return o}}});var re=()=>({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=[];for(let o=0;o<e.length;o++){let s=Object.deepClone(t);await M(s,{...r.options,root:{...r.root,index:o,item:e[o],instance:s}}),n.push(await fr(r,s))}return n}}});var ee=()=>({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 te=()=>({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),a=Object.deepClone(s);if(a[r.key])await e(a,a[r.key]);await M(a,{...r.options}),Object.merge(a,t),delete t[r.key]}};return await e(r.parent,r.value),p.Explore()},group:(r)=>{let e=r.root.parent,t=r.value,{items:n,...o}=t;return t.items.forEach((s)=>e.push({...o,...s})),p.DeleteParent()}});var ne=(r)=>({skip:{types:{0:"boolean"},fn:(e)=>e.value?p.DeleteParent():p.DeleteItem()},metadata:({path:e,value:t})=>{return r.metadata(e,t),p.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 p.DeleteItem();if(typeof o==="string")return(await M({value:o},{...e.options,root:{...e.root}})).value;return p.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 p.ReplaceParent(t.cases[t.from],!0);if(t.default!==void 0)return p.ReplaceParent(t.default,!0);return p.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 ie from"node:vm";var se=(r)=>({modules:async(e)=>{for(let[t,n]of Object.entries(e.value)){let o=ie.createContext({console,objector:r,document:e.root}),s=new ie.SourceTextModule(n,{identifier:t,context:o});await s.link((a)=>{throw Error(`Module ${a} is not allowed`)}),await s.evaluate(),r.sources(Object.fromEntries(Object.entries(s.namespace).map(([a,f])=>[`${t}.${a}`,(y)=>f(y,...y.args)])))}return p.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 p.DeleteItem()}}}});var ae=()=>({let:{fn:(r)=>{let e=r.value;return Object.assign(r.root,e),p.DeleteItem()}}});var ue=()=>({tap:{fn:(r)=>{return console.log(`[tap] ${r.path}:`,r.value),r.value}}});var pn=(r,e)=>{let t=e.section.config.using,n=r.getFunctions();return t?Object.fromEntries(t.map((o)=>{if(o in n)return[o,n[o]];if(o in e.root)return[o,e.root[o]];throw Error(`Function or variable "${o}" not found for script section`)})):n},Fr=(r,e,t,n,o=[])=>{let s=pn(r,t),a=["section","context","config","system",...Object.keys(s),...o],f=[e,t.root,t.section.config,r,...Object.values(s)];return[new AsyncFunction(...a,n).bind(t),f]},gn=(r,e)=>{let t={write:(...n)=>{return e.push(...n),t},writeLine:(...n)=>{return e.push(...n.map((o)=>o+`
|
|
11
|
+
`)),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+`
|
|
12
|
+
`)),t},setOptions:(n)=>{return Object.assign(r.section,n),t},use:(n)=>{return n(t),t},getLines:()=>e};return t},dn=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=gn(e,t);if(!await dn(r,n,e))return!1;let[o,s]=Fr(r,n,e,e.section.content,["item"]),a=e.section.config.each;if(a){let[f,y]=Fr(r,n,e,`return (${a})`),g=Array.isArray(a)?a:await f(...y);if(!Array.isArray(g))throw Error('The "each" property of a script section must return an array');for(let b of g){let l=await o(...s,b);if(typeof l<"u")t.push(l)}}else{let f=await o(...s);if(typeof f<"u")return f}if(t.length===0)return!1;return t.join("")};var ce=(r)=>({script:me(r)});import ye from"fs/promises";import H from"path";var le=(r)=>({include:async(e)=>{let{file:t}=e.options.globalContext;return await Nr(e.args[0],{cwd:H.dirname(t),filter:(n)=>H.basename(t)!==n,map:async(n)=>r.load(n,H.dirname(t),e.root)})},exists:async({args:[e]})=>await br(e),file:async(e)=>await ye.readFile(await er(e.args[0],r.getIncludeDirectories())).then((t)=>t.toString()),scan:async(e)=>{let t=[],o=(()=>{let f=e.args[2]??["**/node_modules/**"],y=typeof f==="string"?f.split(",").map((g)=>g.trim()):f;if(!Array.isArray(y))throw Error("Scan exclusion must be a list");return y})(),{file:s}=e.options.globalContext,a=e.args[1]?await er(e.args[1],r.getIncludeDirectories()):H.dirname(s);for await(let f of ye.glob(e.args[0],{cwd:a,exclude:(y)=>o.some((g)=>H.matchesGlob(y,g))}))t.push(f);return t}});var pe=(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]??`
|
|
13
|
+
`,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`[
|
|
14
|
+
${r.map((a)=>`${o}${ur(a,e+1)},`).join(`
|
|
16
15
|
`)}
|
|
17
|
-
${n}]`}else if(typeof
|
|
18
|
-
${s.map(([
|
|
16
|
+
${n}]`}else if(typeof r==="object"){let s=Object.entries(r).sort((f,y)=>t?.sortKeys?f[0].localeCompare(y[0]):0);if(s.length===0)return"{}";return`{
|
|
17
|
+
${s.map(([f,y])=>`${o}${f} = ${ur(y,e+1,t)}`).join(`
|
|
19
18
|
`)}
|
|
20
|
-
${n}}`}else return String(
|
|
21
|
-
`).replaceAll("\\$","$").replaceAll("\\t","\t")};var
|
|
22
|
-
`,
|
|
23
|
-
`,h):O}return m}}});var Q=async(e,t,r)=>e.rawArgs[t].quoted?e.rawArgs[t].value:await Object.select(e.root,e.rawArgs[t].value,{defaultValue:r}),ht=()=>({switch:{processArgs:!1,fn:async(e)=>{let t=await Q(e,0,!1),r=await Q(e,1);if(r[t]===void 0){if(e.rawArgs.length>2)return Q(e,2);throw Error(`Unhandled switch case: ${t}`)}return r[t]}}});var bt=()=>({if:{types:{0:"boolean"},fn:(e)=>e.args[0]?e.args[1]:e.args[2]},check:{types:{0:Object.keys(x)},fn:(e)=>x[e.args[0]](...e.args.slice(1))},...T(x,{types:le})});var wt=(e)=>({default:{processArgs:!1,fn:async(t)=>{for(let r=0;r<t.rawArgs.length;r++)if(t.rawArgs[r]?.value!==void 0){let o=await Q(t,r,null);if(o!==null)return o}if(t.tags.nullable?.length)return v.DeleteItem();if(t.tags.fail?.length)throw Error(`No valid value found for default (${t.rawArgs.map((r)=>r.value).join(", ")})`);return""}},section:{types:["string","boolean"],fn:(t)=>{let r=t.args[0];if(!(t.args[1]??!0))return null;let o=e.getSection(r);if(!o)throw Error(`Section not found: ${r}`);return o.content}}});var Ot=()=>({convert:({args:[e,t,r]})=>{switch(t){case"string":return String(e);case"number":{let n=Number(e);if(!isNaN(n))return v.ReplaceItem(n);break}case"boolean":if(e==="true"||e===!0||e===1||e==="1"||e==="yes"||e==="on")return v.ReplaceItem(!0);else if(e==="false"||e===!1||e===0||e==="0"||e==="no"||e==="off")return v.ReplaceItem(!1);break;default:throw Error(`Unsupported type for convert: ${t}`)}if(r!==void 0)return v.ReplaceItem(r);throw Error(`Failed to convert value to ${t}`)},isType:({args:[e,t]})=>{let n=(()=>{switch(t){case"string":return typeof e==="string";case"number":return typeof e==="number";case"boolean":return typeof e==="boolean";case"object":return e!==null&&typeof e==="object"&&!Array.isArray(e);case"array":return Array.isArray(e);case"null":return e===null;case"undefined":return e===void 0;case"function":return typeof e==="function";default:throw Error(`Unknown type for isType: ${t}`)}})();return v.ReplaceItem(n)},typeOf:({args:[e]})=>{if(e===null)return"null";else if(Array.isArray(e))return"array";else return typeof e}});var At=(e)=>{var t,r,n,o,s,l,a,u,b,w,m,g,d,E,y,j,h,k,O,S,M,Z,W,C,P,J,ee,B,ce,te,fe,jt,vt,Et,St,kt,Mt,Ft,Dt,Rt,$t,Ct,xt,Nt,Wt,It,Lt,_t,Ut,Bt,qt,Kt,Yt,Gt,Tt,Vt,Xt,Ht,Qt,zt,Zt,Pt,Jt,er,tr,rr,nr,or,ir,sr,ar,lr,ur,cr,fr,pr,gr,mr,yr,dr,hr,br,wr,Or,Ar,jr,vr,Er,Sr,kr,Mr,Fr,Dr,Rr,$r,Cr,xr,Nr,Wr,Ir,Lr,_r,Ur,Br,o,s,l,a,u,b,w,m,g,d,E,y,j,h,k,O,S,M,Z,W,C,P,J,ee,B,ce,te,fe,jt,vt,Et,St,kt,Mt,Ft,Dt,Rt,$t,Ct,xt,Nt,Wt,It,Lt,_t,Ut,Bt,qt,Kt,Yt,Gt,Tt,Vt,Xt,Ht,Qt,zt,Zt,Pt,Jt,er,tr,rr,nr,or,ir,sr,ar,lr,ur,cr,fr,pr,gr,mr,yr,dr,hr,br,wr,Or,Ar,jr,vr,Er,Sr,kr,Mr,Fr,Dr,Rr,$r,Cr,xr,Nr,Wr,Ir,Lr,_r,Ur,Br;return e.use((n=V,o=[f()],s=[f()],l=[f()],a=[f()],u=[f()],b=[f()],w=[f()],m=[f()],g=[f()],d=[f()],E=[f()],y=[f()],j=[f()],h=[f()],k=[f()],O=[f()],S=[f()],M=[f()],Z=[f()],W=[f()],C=[f()],P=[f()],J=[f()],ee=[f()],B=[f()],ce=[f()],te=[f()],fe=[f()],jt=[f()],vt=[f()],Et=[f()],St=[f()],kt=[f()],Mt=[f()],Ft=[f()],Dt=[f()],Rt=[f()],$t=[f()],Ct=[f()],xt=[f()],Nt=[f()],Wt=[f()],It=[f()],Lt=[f()],_t=[f()],Ut=[f()],Bt=[f()],qt=[f()],Kt=[f()],Yt=[f()],Gt=[f()],Tt=[f()],Vt=[f()],Xt=[f()],Ht=[f()],Qt=[f()],zt=[f()],Zt=[f()],Pt=[f()],Jt=[f()],er=[f()],tr=[f()],rr=[f()],nr=[f()],or=[f()],ir=[f()],sr=[f()],ar=[f()],lr=[f()],ur=[f()],cr=[f()],fr=[f()],pr=[f()],gr=[f()],mr=[f()],yr=[f()],dr=[f()],hr=[f()],br=[f()],wr=[f()],Or=[f()],Ar=[f()],jr=[f()],vr=[f()],Er=[f()],Sr=[f()],kr=[f()],Mr=[f()],Fr=[f()],Dr=[f()],Rr=[f()],$r=[f()],Cr=[f()],xr=[f()],Nr=[f()],Wr=[f()],Ir=[f()],Lr=[f()],_r=[f()],Ur=[f()],Br=[f()],r=Re(n),t=class extends n{constructor(){super(...arguments);Ce(r,5,this)}env(i){return process.env[i]}uuid(){return crypto.randomUUID()}pascal(i){return i.toPascal()}camel(i){return i.toCamel()}capital(i){return i.capitalize()}snake(i,p="lower"){return i.changeCase(p).toSnake()}kebab(i,p="lower"){return i.changeCase(p).toKebab()}len(i){return i.length}reverse(i){return i.split("").reverse().join("")}concat(...i){return i.join("")}trim(i){return i.trim()}ltrim(i){return i.trimStart()}rtrim(i){return i.trimEnd()}lower(i){return i.toLowerCase()}upper(i){return i.toUpperCase()}encode(i,p){return Buffer.from(i).toString(p??"base64")}decode(i,p){return Buffer.from(i,p??"base64").toString()}list(i,p="name"){return Object.toList(i,p)}object(i,p="name"){return i.toObject((A)=>A[p],(A)=>{let{[p]:D,...$}=A;return $})}pathJoin(...i){return N.join(...i)}resolve(...i){return N.resolve(...i)}dirname(i){return N.dirname(i)}basename(i,p){return N.basename(i,p)}normalize(i){return N.normalize(i)}extname(i){return N.extname(i)}relative(i,p){return N.relative(i,p)}isAbsolute(i){return N.isAbsolute(i)}segments(i){return i.split("/").filter(Boolean)}log(...i){console.log(...i)}md5(i){return U("md5").update(i).digest("hex")}sha1(i){return U("sha1").update(i).digest("hex")}sha256(i){return U("sha256").update(i).digest("hex")}sha512(i){return U("sha512").update(i).digest("hex")}hash(i,p="sha256"){return U(p).update(i).digest("hex")}hmac(i,p,A="sha256"){return U(A).update(i).digest("hex")}base64Encode(i){return Buffer.from(i).toString("base64")}base64Decode(i){return Buffer.from(i,"base64").toString("utf-8")}hexEncode(i){return Buffer.from(i).toString("hex")}hexDecode(i){return Buffer.from(i,"hex").toString("utf-8")}add(...i){return i.reduce((p,A)=>p+A,0)}subtract(i,p){return i-p}multiply(...i){return i.reduce((p,A)=>p*A,1)}divide(i,p){if(p===0)throw Error("Division by zero");return i/p}modulo(i,p){return i%p}power(i,p){return Math.pow(i,p)}sqrt(i){return Math.sqrt(i)}abs(i){return Math.abs(i)}floor(i){return Math.floor(i)}ceil(i){return Math.ceil(i)}round(i,p){let A=Math.pow(10,p??0);return Math.round(i*A)/A}min(...i){return Math.min(...i)}max(...i){return Math.max(...i)}clamp(i,p,A){return Math.max(p,Math.min(A,i))}random(i,p){let A=i??0,D=p??1;return Math.random()*(D-A)+A}timestamp(i){return new Date(i).getTime()}iso(i){return new Date(i).toISOString()}utc(i){return new Date(i).toUTCString()}formatDate(i,p){let A=new Date(i),D=A.getFullYear(),$=String(A.getMonth()+1).padStart(2,"0"),re=String(A.getDate()).padStart(2,"0"),q=String(A.getHours()).padStart(2,"0"),qr=String(A.getMinutes()).padStart(2,"0"),Kr=String(A.getSeconds()).padStart(2,"0");return p.replace("YYYY",String(D)).replace("MM",$).replace("DD",re).replace("HH",q).replace("mm",qr).replace("ss",Kr)}parseDate(i){return new Date(i).getTime()}year(i){return new Date(i).getFullYear()}month(i){return new Date(i).getMonth()+1}day(i){return new Date(i).getDate()}dayOfWeek(i){return new Date(i).getDay()}hours(i){return new Date(i).getHours()}minutes(i){return new Date(i).getMinutes()}seconds(i){return new Date(i).getSeconds()}regexTest(i,p,A){return new RegExp(i,A).test(p)}regexMatch(i,p,A){return new RegExp(i,A).exec(p)}regexMatchAll(i,p,A){return Array.from(p.matchAll(new RegExp(i,A)))}regexReplace(i,p,A,D){return A.replace(new RegExp(i,D),p)}regexReplaceAll(i,p,A,D){return A.replace(new RegExp(i,D??"g"),p)}regexSplit(i,p,A){return p.split(new RegExp(i,A))}regexExec(i,p,A){return new RegExp(i,A).exec(p)}regexSearch(i,p,A){return p.search(new RegExp(i,A))}unique(i,p){if(!Array.isArray(i))return i;let A=new Set;return i.filter((D)=>{let $=p?D[p]:D;if(A.has($))return!1;return A.add($),!0})}groupBy(i,p){if(!Array.isArray(i))return i;let A={};return i.forEach((D)=>{let $=String(D[p]);if(!A[$])A[$]=[];A[$].push(D)}),A}chunk(i,p=1){if(!Array.isArray(i))return[];let A=[];for(let D=0;D<i.length;D+=p)A.push(i.slice(D,D+p));return A}flatten(i,p=1){if(!Array.isArray(i))return[i];let A=[],D=($,re)=>{for(let q of $)if(Array.isArray(q)&&re>0)D(q,re-1);else A.push(q)};return D(i,p),A}compact(i){if(!Array.isArray(i))return i;return i.filter((p)=>p!==null&&p!==void 0)}head(i,p){if(!Array.isArray(i))return i;return p?i.slice(0,p):i[0]}tail(i,p){if(!Array.isArray(i))return i;return p?i.slice(-p):i[i.length-1]}isEmail(i){return/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(i)}isUrl(i){try{return new URL(i),!0}catch{return!1}}isJson(i){try{return JSON.parse(i),!0}catch{return!1}}isUuid(i){return/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i.test(i)}minLength(i,p){return i?.length>=p}maxLength(i,p){return i?.length<=p}lengthEquals(i,p){return i?.length===p}isNumber(i){return typeof i==="number"&&!isNaN(i)}isString(i){return typeof i==="string"}isBoolean(i){return typeof i==="boolean"}isArray(i){return Array.isArray(i)}isObject(i){return i!==null&&typeof i==="object"&&!Array.isArray(i)}isEmpty(i){if(i===null||i===void 0)return!0;if(typeof i==="string"||Array.isArray(i))return i.length===0;if(typeof i==="object")return Object.keys(i).length===0;return!1}isTruthy(i){return!!i}isFalsy(i){return!i}inRange(i,p,A){return i>=p&&i<=A}matchesPattern(i,p){return new RegExp(p).test(i)}includes(i,p){if(typeof i==="string")return i.includes(String(p));return Array.isArray(i)&&i.includes(p)}startsWith(i,p){return i.startsWith(p)}endsWith(i,p){return i.endsWith(p)}},c(r,1,"env",o,t),c(r,1,"uuid",s,t),c(r,1,"pascal",l,t),c(r,1,"camel",a,t),c(r,1,"capital",u,t),c(r,1,"snake",b,t),c(r,1,"kebab",w,t),c(r,1,"len",m,t),c(r,1,"reverse",g,t),c(r,1,"concat",d,t),c(r,1,"trim",E,t),c(r,1,"ltrim",y,t),c(r,1,"rtrim",j,t),c(r,1,"lower",h,t),c(r,1,"upper",k,t),c(r,1,"encode",O,t),c(r,1,"decode",S,t),c(r,1,"list",M,t),c(r,1,"object",Z,t),c(r,1,"pathJoin",W,t),c(r,1,"resolve",C,t),c(r,1,"dirname",P,t),c(r,1,"basename",J,t),c(r,1,"normalize",ee,t),c(r,1,"extname",B,t),c(r,1,"relative",ce,t),c(r,1,"isAbsolute",te,t),c(r,1,"segments",fe,t),c(r,1,"log",jt,t),c(r,1,"md5",vt,t),c(r,1,"sha1",Et,t),c(r,1,"sha256",St,t),c(r,1,"sha512",kt,t),c(r,1,"hash",Mt,t),c(r,1,"hmac",Ft,t),c(r,1,"base64Encode",Dt,t),c(r,1,"base64Decode",Rt,t),c(r,1,"hexEncode",$t,t),c(r,1,"hexDecode",Ct,t),c(r,1,"add",xt,t),c(r,1,"subtract",Nt,t),c(r,1,"multiply",Wt,t),c(r,1,"divide",It,t),c(r,1,"modulo",Lt,t),c(r,1,"power",_t,t),c(r,1,"sqrt",Ut,t),c(r,1,"abs",Bt,t),c(r,1,"floor",qt,t),c(r,1,"ceil",Kt,t),c(r,1,"round",Yt,t),c(r,1,"min",Gt,t),c(r,1,"max",Tt,t),c(r,1,"clamp",Vt,t),c(r,1,"random",Xt,t),c(r,1,"timestamp",Ht,t),c(r,1,"iso",Qt,t),c(r,1,"utc",zt,t),c(r,1,"formatDate",Zt,t),c(r,1,"parseDate",Pt,t),c(r,1,"year",Jt,t),c(r,1,"month",er,t),c(r,1,"day",tr,t),c(r,1,"dayOfWeek",rr,t),c(r,1,"hours",nr,t),c(r,1,"minutes",or,t),c(r,1,"seconds",ir,t),c(r,1,"regexTest",sr,t),c(r,1,"regexMatch",ar,t),c(r,1,"regexMatchAll",lr,t),c(r,1,"regexReplace",ur,t),c(r,1,"regexReplaceAll",cr,t),c(r,1,"regexSplit",fr,t),c(r,1,"regexExec",pr,t),c(r,1,"regexSearch",gr,t),c(r,1,"unique",mr,t),c(r,1,"groupBy",yr,t),c(r,1,"chunk",dr,t),c(r,1,"flatten",hr,t),c(r,1,"compact",br,t),c(r,1,"head",wr,t),c(r,1,"tail",Or,t),c(r,1,"isEmail",Ar,t),c(r,1,"isUrl",jr,t),c(r,1,"isJson",vr,t),c(r,1,"isUuid",Er,t),c(r,1,"minLength",Sr,t),c(r,1,"maxLength",kr,t),c(r,1,"lengthEquals",Mr,t),c(r,1,"isNumber",Fr,t),c(r,1,"isString",Dr,t),c(r,1,"isBoolean",Rr,t),c(r,1,"isArray",$r,t),c(r,1,"isObject",Cr,t),c(r,1,"isEmpty",xr,t),c(r,1,"isTruthy",Nr,t),c(r,1,"isFalsy",Wr,t),c(r,1,"inRange",Ir,t),c(r,1,"matchesPattern",Lr,t),c(r,1,"includes",_r,t),c(r,1,"startsWith",Ur,t),c(r,1,"endsWith",Br,t),ge(r,t),t)).keys({...Ze(e),...Pe(e),...Je(),...et(),...ot(),...tt(),...rt(),...nt(e),...st(e),...at(),...lt(),...ut()}).sources({...gt(e),...mt(e),...Ot(),...yt(),...dt(),...ht(),...bt(),...wt(e)}).sections(ft(e)).fieldOptions({configParser:Bun.YAML.parse,onSection:(i)=>{if(i.section.config.name)e.section(i.section)}}).decoders({yaml:{matching:["\\.yml$","\\.yaml$"],fn:Bun.YAML.parse}}).encoders({json:{fn:(i)=>JSON.stringify(i,null,2)},yaml:{fn:(i)=>Bun.YAML.stringify(i,null,2)},terraform:{options:{includeTags:!0},fn:(i,p)=>ue(i,0,{sortKeys:!!(p?.sort?.length??p?.sortKeys?.length)})}})};import Tn from"fs/promises";import z from"path";class ve{includeDirectories=[];baseIncludeDirectories=[];includes=[];addDirectories(...e){this.includeDirectories.push(...e),this.baseIncludeDirectories.push(...e)}getDirectories(){return this.includeDirectories}reset(){this.includeDirectories=[...this.baseIncludeDirectories]}restore(e){this.includeDirectories=[...e]}snapshot(){return[...this.includeDirectories]}addFiles(...e){this.includes.push(...e)}getPendingAndClear(){let e=[...this.includes];return this.includes.length=0,e}async processPatterns(e,t,r){let n=[];for(let o of e)if(_.isGlobPattern(o)){let s=(await Array.fromAsync(Tn.glob(o,{cwd:t}))).map((l)=>z.join(t,l));for(let l of s)if(!r.included.includes(l))n.push(l)}else if(_.isDirectoryPattern(o)){let s=z.isAbsolute(o)?o:z.join(t,o);if(!this.includeDirectories.includes(s))this.includeDirectories.push(s)}else n.push(o);return n}buildSearchDirs(e){let t=e?[e]:[];return t.push(...this.includeDirectories.map((r)=>z.isAbsolute(r)?r:z.join(e??process.cwd(),r))),t}}class Ee{includeManager;loadFn;constructor(e,t){this.includeManager=e;this.loadFn=t}async processIncludes(e,t,r){let n=[];if(e.content.includes)n.push(...e.content.includes),delete e.content.includes;n.push(...this.includeManager.getPendingAndClear());let o=await this.includeManager.processPatterns(n,e.folderPath,r);for(let s of o)Object.merge(await this.loadFn(s,e.folderPath,{parent:e.content,...t},!0,r),e.content)}}class Vn{includeManager=new ve;includeProcessor;cacheManager=new Oe(100);outputs=[];vars={};funcs={};fields={sources:{},keys:{},sections:{}};objectMetadata={};currentContext=null;storedSections={};dataEncoders={};dataDecoders={};constructor(){this.includeProcessor=new Ee(this.includeManager,this.load.bind(this)),this.use(At)}use(e){if(e.prototype instanceof V)new e(this);else e(this);return this}includeDirectory(...e){return this.includeManager.addDirectories(...e),this}getIncludeDirectories(){return this.includeManager.getDirectories()}include(...e){return this.includeManager.addFiles(...e),this}keys(e){return Object.assign(this.fields.keys,{...this.fields.keys,...e}),this}sources(e){return Object.assign(this.fields.sources,{...this.fields.sources,...e}),this}sections(e){return Object.assign(this.fields.sections,{...this.fields.sections,...e}),this}variables(e){return this.vars={...this.vars,...e},this}functions(e){return this.funcs={...this.funcs,...e},this}getFunctions(){return this.funcs}getOutputs(){return this.outputs}output(e){return this.outputs.push(e),this}metadata(e,t){return this.objectMetadata[e]=t,this}getMetadata(e){return this.objectMetadata[e]}getAllMetadata(){return this.objectMetadata}setCacheMaxSize(e){return this.cacheManager.setMaxSize(e),this}clearCache(){return this.cacheManager.clear(),this}getCurrentContext(){return this.currentContext}fieldOptions(e){return this.fields={...this.fields,...e},this}section(e){return this.storedSections[e.config.name]=e,this}getSection(e){return this.storedSections[e]}encoders(e){return this.dataEncoders={...this.dataEncoders,...e},this}decoders(e){return this.dataDecoders={...this.dataDecoders,...e},this}getEncoder(e){return this.dataEncoders[e]}getDecoder(e){return this.dataDecoders[e]}filter(e){return this.fields.filters??=[],this.fields.filters.push(e),this}async loadObject(e,t,r){return R(e,{...this.fields,globalContext:{file:r?.fullPath??"@internal"},root:{...t,...this.fields.root,...this.vars,functions:this.funcs,context:this.currentContext,sections:this.storedSections,$document:{root:{content:e},fileName:r?.fileName??"@internal",folder:r?.folderPath??"@internal",fullPath:r?.fullPath??"@internal"}}})}async load(e,t,r,n,o){let s=this.includeManager.snapshot();try{this.includeManager.reset();let l=this.includeManager.buildSearchDirs(t);if(o)this.currentContext=o;this.currentContext??={included:[],document:null};let a=await Xe(e,{dirs:l,parsers:this.dataDecoders,format:"yaml"}),u=_.normalize(a.fullPath);if(this.currentContext.included.push(u),!a.content)return null;let b=this.cacheManager.get(u),w;if(b)w=b.raw;else w=a.content,this.cacheManager.set(u,{raw:w,timestamp:Date.now()});let m=Object.deepClone(w);a.content=m,await this.includeProcessor.processIncludes(a,r,this.currentContext);let g;if(n!==!0)g=await this.loadObject(a.content,r,{fileName:a.fullPath,folderPath:a.folderPath,fullPath:a.fullPath});else g=a.content;return this.currentContext.document=g,g}catch(l){throw this.includeManager.restore(s),l}finally{this.includeManager.restore(s)}}async writeAll(e){await ze(this.getOutputs(),e)}}export{ze as writeOutputs,xn as writeOutput,$n as writeFormat,fo as variable,po as sharedFunction,uo as section,R as processFields,T as makeFieldProcessorMap,Hn as makeFieldProcessorList,Ye as makeFieldProcessor,f as macro,oe as locate,Xe as loadFormat,co as key,Wn as importList,ao as importGlob,He as globMap,_e as getProcessor,hn as getArgs,we as exists,go as encoder,Qo as defined,mo as decoder,x as conditionPredicates,V as ObjectorPlugin,Vn as Objector,v as NavigateResult,Ln as NavigateAction,qn as Logger};
|
|
19
|
+
${n}}`}else return String(r)},z=(r)=>{if(!r)return r;return r.replaceAll("\\n",`
|
|
20
|
+
`).replaceAll("\\$","$").replaceAll("\\t","\t")};var ge=()=>({...G({merge:(...r)=>r.flatMap((e)=>e)}),join:({args:[r],root:e,tags:t})=>{let n=t.key?.[0],o=t.separator?.[0]??t.sep?.[0],s=t.finalize?.length>0,a=z(o);if(typeof r==="string"){if(s&&r.length&&a)return r+a;return r}if(!Array.isArray(r))throw Error("Object is not a list");let f=((n?.length)?r.map((l)=>Object.select({...e,...l},n)):r).join(a),y=t.pad?.[0]??"0",g=t.padChar?.[0]??" ",b=s&&f.length&&a?f+a:f;return y?b.padBlock(parseInt(y),`
|
|
21
|
+
`,g):b},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},(a,f)=>n+f*s)},filter:{types:(r,e,t)=>{switch(r){case 0:return"array";case 1:return Object.keys(L)}return ar[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],a=L[e];if(s){let y=Array(r.length);for(let b=0;b<r.length;b++)try{y[b]=Object.select({...n,...r[b]},s)}catch{y[b]=Symbol("invalid")}let g=[];for(let b=0;b<r.length;b++){let l=y[b];if(typeof l!=="symbol"&&t===void 0?a(l):a(l,t))g.push(r[b])}return g}let f=[];for(let y of r)if(t===void 0?a(y):a(y,t))f.push(y);return f}}});var de=()=>({each:{processArgs:!1,fn:async({rawArgs:[r,e,...t],root:n,options:o,tags:s})=>{let a=async(w)=>w.quoted?z(w.value):await Object.select(n,w.value),f=await Object.select(n,r.value),y=await a(e),g=s.key?.[0],b=Array.isArray(f)?f:Object.toList(f,"name"),l=[],O=await Promise.all(t.map(async(w)=>await a(w))),h={...n,item:void 0,index:0,params:O,instance:void 0,parent:n.this,tags:s},P={...o,root:h};for(let w=0;w<b.length;w++){let j=Object.deepClone(y),C={instance:j},A=typeof y==="string"?C:j;if(h.item=b[w],h.index=w,h.instance=j,s?.root?.[0])Object.assign(h,await Object.select(h,s.root[0]));if(await M(A,P),g!==void 0)l.push(await Object.select(C.instance,g));else l.push(C.instance)}if(s.join?.length){if(l.length===0)return"";let w=z(s.join[0]),j=s.pad?.[0]??"0",C=s.padChar?.[0]??" ",A=s.finalize?.length&&w?w:"",D=`${l.join(w)}${A}`;return j?D.padBlock(parseInt(j),`
|
|
22
|
+
`,C):D}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 he=()=>({if:{types:{0:"boolean"},fn:(r)=>r.args[0]?r.args[1]:r.args[2]},check:{types:{0:Object.keys(L)},fn:(r)=>L[r.args[0]](...r.args.slice(1))},...G(L,{types:ar})});var we=(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 p.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 Oe=()=>({convert:({args:[r,e,t]})=>{switch(e){case"string":return String(r);case"number":{let n=Number(r);if(!isNaN(n))return p.ReplaceItem(n);break}case"boolean":if(r==="true"||r===!0||r===1||r==="1"||r==="yes"||r==="on")return p.ReplaceItem(!0);else if(r==="false"||r===!1||r===0||r==="0"||r==="no"||r==="off")return p.ReplaceItem(!1);break;default:throw Error(`Unsupported type for convert: ${e}`)}if(t!==void 0)return p.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 p.ReplaceItem(n)},typeOf:({args:[r]})=>{if(r===null)return"null";else if(Array.isArray(r))return"array";else return typeof r}});var je=(r)=>{var e,t,n,o,s,a,f,y,g,b,l,O,h,P,w,j,C,A,D,E,S,T,_,$,X,x,Sr,V,W,mr,v,cr,Fe,Ae,Ee,Se,Me,De,Pe,Ce,ke,$e,Re,Le,Ue,_e,Be,Ie,Ne,We,Je,Ke,Ye,qe,Ge,He,ze,Qe,Ze,Te,Xe,xe,Ve,ve,rt,et,tt,nt,ot,it,st,ft,at,ut,mt,ct,yt,lt,pt,gt,dt,bt,ht,wt,Ot,jt,Ft,At,Et,St,Mt,Dt,Pt,Ct,kt,$t,Rt,Lt,Ut,_t,Bt,It,Nt,Wt,o,s,a,f,y,g,b,l,O,h,P,w,j,C,A,D,E,S,T,_,$,X,x,Sr,V,W,mr,v,cr,Fe,Ae,Ee,Se,Me,De,Pe,Ce,ke,$e,Re,Le,Ue,_e,Be,Ie,Ne,We,Je,Ke,Ye,qe,Ge,He,ze,Qe,Ze,Te,Xe,xe,Ve,ve,rt,et,tt,nt,ot,it,st,ft,at,ut,mt,ct,yt,lt,pt,gt,dt,bt,ht,wt,Ot,jt,Ft,At,Et,St,Mt,Dt,Pt,Ct,kt,$t,Rt,Lt,Ut,_t,Bt,It,Nt,Wt;return r.use((n=q,o=[m()],s=[m()],a=[m()],f=[m()],y=[m()],g=[m()],b=[m()],l=[m()],O=[m()],h=[m()],P=[m()],w=[m()],j=[m()],C=[m()],A=[m()],D=[m()],E=[m()],S=[m()],T=[m()],_=[m()],$=[m()],X=[m()],x=[m()],Sr=[m()],V=[m()],W=[m()],mr=[m()],v=[m()],cr=[m()],Fe=[m()],Ae=[m()],Ee=[m()],Se=[m()],Me=[m()],De=[m()],Pe=[m()],Ce=[m()],ke=[m()],$e=[m()],Re=[m()],Le=[m()],Ue=[m()],_e=[m()],Be=[m()],Ie=[m()],Ne=[m()],We=[m()],Je=[m()],Ke=[m()],Ye=[m()],qe=[m()],Ge=[m()],He=[m()],ze=[m()],Qe=[m()],Ze=[m()],Te=[m()],Xe=[m()],xe=[m()],Ve=[m()],ve=[m()],rt=[m()],et=[m()],tt=[m()],nt=[m()],ot=[m()],it=[m()],st=[m()],ft=[m()],at=[m()],ut=[m()],mt=[m()],ct=[m()],yt=[m()],lt=[m()],pt=[m()],gt=[m()],dt=[m()],bt=[m()],ht=[m()],wt=[m()],Ot=[m()],jt=[m()],Ft=[m()],At=[m()],Et=[m()],St=[m()],Mt=[m()],Dt=[m()],Pt=[m()],Ct=[m()],kt=[m()],$t=[m()],Rt=[m()],Lt=[m()],Ut=[m()],_t=[m()],Bt=[m()],It=[m()],Nt=[m()],Wt=[m()],t=$r(n),e=class extends n{constructor(){super(...arguments);Lr(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,c="lower"){return i.changeCase(c).toSnake()}kebab(i,c="lower"){return i.changeCase(c).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,c){return Buffer.from(i).toString(c??"base64")}decode(i,c){return Buffer.from(i,c??"base64").toString()}list(i,c="name"){return Object.toList(i,c)}object(i,c="name"){return i.toObject((d)=>d[c],(d)=>{let{[c]: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,c){return U.basename(i,c)}normalize(i){return U.normalize(i)}extname(i){return U.extname(i)}relative(i,c){return U.relative(i,c)}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,c="sha256"){return N(c).update(i).digest("hex")}hmac(i,c,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((c,d)=>c+d,0)}subtract(i,c){return i-c}multiply(...i){return i.reduce((c,d)=>c*d,1)}divide(i,c){if(c===0)throw Error("Division by zero");return i/c}modulo(i,c){return i%c}power(i,c){return Math.pow(i,c)}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,c){let d=Math.pow(10,c??0);return Math.round(i*d)/d}min(...i){return Math.min(...i)}max(...i){return Math.max(...i)}clamp(i,c,d){return Math.max(c,Math.min(d,i))}random(i,c){let d=i??0,F=c??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,c){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"),Jt=String(d.getMinutes()).padStart(2,"0"),Kt=String(d.getSeconds()).padStart(2,"0");return c.replace("YYYY",String(F)).replace("MM",k).replace("DD",rr).replace("HH",J).replace("mm",Jt).replace("ss",Kt)}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,c,d){return new RegExp(i,d).test(c)}regexMatch(i,c,d){return new RegExp(i,d).exec(c)}regexMatchAll(i,c,d){return Array.from(c.matchAll(new RegExp(i,d)))}regexReplace(i,c,d,F){return d.replace(new RegExp(i,F),c)}regexReplaceAll(i,c,d,F){return d.replace(new RegExp(i,F??"g"),c)}regexSplit(i,c,d){return c.split(new RegExp(i,d))}regexExec(i,c,d){return new RegExp(i,d).exec(c)}regexSearch(i,c,d){return c.search(new RegExp(i,d))}unique(i,c){if(!Array.isArray(i))return i;let d=new Set;return i.filter((F)=>{let k=c?F[c]:F;if(d.has(k))return!1;return d.add(k),!0})}groupBy(i,c){if(!Array.isArray(i))return i;let d={};return i.forEach((F)=>{let k=String(F[c]);if(!d[k])d[k]=[];d[k].push(F)}),d}chunk(i,c=1){if(!Array.isArray(i))return[];let d=[];for(let F=0;F<i.length;F+=c)d.push(i.slice(F,F+c));return d}flatten(i,c=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,c),d}compact(i){if(!Array.isArray(i))return i;return i.filter((c)=>c!==null&&c!==void 0)}head(i,c){if(!Array.isArray(i))return i;return c?i.slice(0,c):i[0]}tail(i,c){if(!Array.isArray(i))return i;return c?i.slice(-c):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,c){return i?.length>=c}maxLength(i,c){return i?.length<=c}lengthEquals(i,c){return i?.length===c}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,c,d){return i>=c&&i<=d}matchesPattern(i,c){return new RegExp(c).test(i)}includes(i,c){if(typeof i==="string")return i.includes(String(c));return Array.isArray(i)&&i.includes(c)}startsWith(i,c){return i.startsWith(c)}endsWith(i,c){return i.endsWith(c)}},u(t,1,"env",o,e),u(t,1,"uuid",s,e),u(t,1,"pascal",a,e),u(t,1,"camel",f,e),u(t,1,"capital",y,e),u(t,1,"snake",g,e),u(t,1,"kebab",b,e),u(t,1,"len",l,e),u(t,1,"reverse",O,e),u(t,1,"concat",h,e),u(t,1,"trim",P,e),u(t,1,"ltrim",w,e),u(t,1,"rtrim",j,e),u(t,1,"lower",C,e),u(t,1,"upper",A,e),u(t,1,"encode",D,e),u(t,1,"decode",E,e),u(t,1,"list",S,e),u(t,1,"object",T,e),u(t,1,"pathJoin",_,e),u(t,1,"resolve",$,e),u(t,1,"dirname",X,e),u(t,1,"basename",x,e),u(t,1,"normalize",Sr,e),u(t,1,"extname",V,e),u(t,1,"relative",W,e),u(t,1,"isAbsolute",mr,e),u(t,1,"segments",v,e),u(t,1,"log",cr,e),u(t,1,"md5",Fe,e),u(t,1,"sha1",Ae,e),u(t,1,"sha256",Ee,e),u(t,1,"sha512",Se,e),u(t,1,"hash",Me,e),u(t,1,"hmac",De,e),u(t,1,"base64Encode",Pe,e),u(t,1,"base64Decode",Ce,e),u(t,1,"hexEncode",ke,e),u(t,1,"hexDecode",$e,e),u(t,1,"add",Re,e),u(t,1,"subtract",Le,e),u(t,1,"multiply",Ue,e),u(t,1,"divide",_e,e),u(t,1,"modulo",Be,e),u(t,1,"power",Ie,e),u(t,1,"sqrt",Ne,e),u(t,1,"abs",We,e),u(t,1,"floor",Je,e),u(t,1,"ceil",Ke,e),u(t,1,"round",Ye,e),u(t,1,"min",qe,e),u(t,1,"max",Ge,e),u(t,1,"clamp",He,e),u(t,1,"random",ze,e),u(t,1,"timestamp",Qe,e),u(t,1,"iso",Ze,e),u(t,1,"utc",Te,e),u(t,1,"formatDate",Xe,e),u(t,1,"parseDate",xe,e),u(t,1,"year",Ve,e),u(t,1,"month",ve,e),u(t,1,"day",rt,e),u(t,1,"dayOfWeek",et,e),u(t,1,"hours",tt,e),u(t,1,"minutes",nt,e),u(t,1,"seconds",ot,e),u(t,1,"regexTest",it,e),u(t,1,"regexMatch",st,e),u(t,1,"regexMatchAll",ft,e),u(t,1,"regexReplace",at,e),u(t,1,"regexReplaceAll",ut,e),u(t,1,"regexSplit",mt,e),u(t,1,"regexExec",ct,e),u(t,1,"regexSearch",yt,e),u(t,1,"unique",lt,e),u(t,1,"groupBy",pt,e),u(t,1,"chunk",gt,e),u(t,1,"flatten",dt,e),u(t,1,"compact",bt,e),u(t,1,"head",ht,e),u(t,1,"tail",wt,e),u(t,1,"isEmail",Ot,e),u(t,1,"isUrl",jt,e),u(t,1,"isJson",Ft,e),u(t,1,"isUuid",At,e),u(t,1,"minLength",Et,e),u(t,1,"maxLength",St,e),u(t,1,"lengthEquals",Mt,e),u(t,1,"isNumber",Dt,e),u(t,1,"isString",Pt,e),u(t,1,"isBoolean",Ct,e),u(t,1,"isArray",kt,e),u(t,1,"isObject",$t,e),u(t,1,"isEmpty",Rt,e),u(t,1,"isTruthy",Lt,e),u(t,1,"isFalsy",Ut,e),u(t,1,"inRange",_t,e),u(t,1,"matchesPattern",Bt,e),u(t,1,"includes",It,e),u(t,1,"startsWith",Nt,e),u(t,1,"endsWith",Wt,e),lr(t,e),e)).keys({...Kr(r),...Yr(r),...vr(),...re(),...oe(),...ee(),...te(),...ne(r),...se(r),...fe(),...ae(),...ue()}).sources({...le(r),...pe(r),...Oe(),...ge(),...de(),...be(),...he(),...we(r)}).sections(ce(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,c)=>ur(i,0,{sortKeys:!!(c?.sort?.length??c?.sortKeys?.length)})}})};import bn from"fs/promises";import Z from"path";class Ar{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(bn.glob(o,{cwd:e}))).map((a)=>Z.join(e,a));for(let a of s)if(!t.included.includes(a))n.push(a)}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}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 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 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 hn{includeManager=new Ar;includeProcessor;cacheManager=new hr(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(je)}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 M(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 a=this.includeManager.buildSearchDirs(e);if(o)this.currentContext=o;this.currentContext??={included:[],document:null};let f=await Ir(r,{dirs:a,parsers:this.dataDecoders,format:"yaml"}),y=I.normalize(f.fullPath);if(this.currentContext.included.push(y),!f.content)return null;let g=this.cacheManager.get(y),b;if(g)b=g.raw;else b=f.content,this.cacheManager.set(y,{raw:b,timestamp:Date.now()});let l=Object.deepClone(b);f.content=l,await this.includeProcessor.processIncludes(f,t,this.currentContext);let O;if(n!==!0)O=await this.loadObject(f.content,t,{fileName:f.fullPath,folderPath:f.folderPath,fullPath:f.fullPath});else O=f.content;return this.currentContext.document=O,O}catch(a){throw this.includeManager.restore(s),a}finally{this.includeManager.restore(s)}}async writeAll(r){await Jr(this.getOutputs(),r)}}export{Jr as writeOutputs,vt as writeOutput,xt as writeFormat,_n as variable,Bn as sharedFunction,Ln as section,M as processFields,G as makeFieldProcessorMap,Po as makeFieldProcessorList,Vr as makeFieldProcessor,m as macro,er as locate,Ir as loadFormat,Un as key,en as importList,$n as importGlob,Nr as globMap,sr as getProcessor,Hr as getArgs,br as exists,In as encoder,Xn as defined,Nn as decoder,L as conditionPredicates,q as ObjectorPlugin,hn as Objector,p as NavigateResult,R as NavigateAction,fn as Logger};
|