@homedev/objector 1.2.65 → 1.2.67

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.ts CHANGED
@@ -1,57 +1,4 @@
1
- declare const AsyncFunction_2: FunctionConstructor;
2
- export { AsyncFunction_2 as AsyncFunction }
3
-
4
- /**
5
- * Maps an array asynchronously using Promise.all for parallel execution
6
- * @typeParam T - Type of input array items
7
- * @typeParam U - Type of async result items
8
- * @param arr - Array to map
9
- * @param fn - Async mapping function
10
- * @returns Promise of mapped array
11
- * @public
12
- */
13
- export declare const asyncMap: <T, U>(arr: T[], fn: (item: T, index: number, array: T[]) => Promise<U>) => Promise<U[]>;
14
-
15
- /**
16
- * Converts a string to camelCase (lowerCamelCase).
17
- * Handles spaces, underscores, and hyphens as word separators.
18
- *
19
- * @example
20
- * camel('hello_world') // 'helloWorld'
21
- * camel('hello world') // 'helloWorld'
22
- * camel('HelloWorld') // 'helloWorld'
23
- *
24
- * @param v - The string to convert
25
- * @returns The string in camelCase
26
- */
27
- export declare const camel: (v: string) => string;
28
-
29
- /**
30
- * Converts a string to Capital Case (each word capitalized, spaces preserved).
31
- * Only capitalizes words following spaces.
32
- *
33
- * @example
34
- * capital('hello world') // 'Hello World'
35
- * capital('hello_world') // 'hello_World'
36
- *
37
- * @param v - The string to convert
38
- * @returns The string with each space-separated word capitalized
39
- */
40
- export declare const capital: (v: string) => string;
41
-
42
- /**
43
- * Changes the case of a string to uppercase, lowercase, or returns unchanged.
44
- *
45
- * @example
46
- * changeCase('Hello', 'upper') // 'HELLO'
47
- * changeCase('Hello', 'lower') // 'hello'
48
- * changeCase('Hello') // 'Hello'
49
- *
50
- * @param v - The string to transform
51
- * @param arg - The case type: 'upper', 'lower', or undefined to return unchanged
52
- * @returns The transformed string
53
- */
54
- export declare const changeCase: (v: string, arg?: string) => string;
1
+ import { NavigateResult as NavigateResult_2 } from '@homedev/navigate';
55
2
 
56
3
  /**
57
4
  * @public
@@ -63,27 +10,26 @@ export declare const decoder: (options?: DecoderOptions) => (_: any, ctx: ClassM
63
10
  declare type DecoderOptions = ObjectorDecoratorOptions;
64
11
 
65
12
  /**
66
- * Deep clones an object using structuredClone (faster) with JSON fallback
67
- * - Uses structuredClone for better performance and broader type support (Date, RegExp, etc.)
68
- * - Falls back to JSON serialization if structuredClone fails or is unavailable
69
- * - Note: Functions, symbols, and undefined values are lost in JSON fallback
70
- * @typeParam T - Type of object to clone
71
- * @param model - Object to clone
72
- * @returns Deep clone of the object
73
- * @public
74
- */
75
- export declare const deepClone: <T>(model: T) => T;
76
-
77
- /**
78
- * Asserts that a value is defined, throwing an error if undefined
79
- * @typeParam T - Type of the value
80
- * @param value - Value to check
81
- * @param msg - Error message to throw if value is undefined or null
82
- * @returns The value if defined
83
- * @throws Error if value is undefined
84
- * @public
13
+ * Guards against undefined and null values.
14
+ * Throws an error if the value is nullish, otherwise returns the value.
15
+ *
16
+ * @param value - The value to check
17
+ * @param message - Custom error message (default: 'Value is undefined')
18
+ * @returns The value if it is not nullish
19
+ * @throws {Error} When value is undefined or null
20
+ *
21
+ * @example
22
+ * ```typescript
23
+ * const value = defined(maybeUndefined, 'Required value missing')
24
+ * // value is guaranteed to be non-nullish here
25
+ *
26
+ * defined(0) // 0 (falsy but not nullish)
27
+ * defined(false) // false (falsy but not nullish)
28
+ * defined(null) // throws Error: Value is undefined
29
+ * ```
85
30
  */
86
- export declare const defined: <T>(value: T | undefined | null, msg?: string) => T;
31
+ declare function defined_2<T>(value: T | undefined | null, message?: string): T;
32
+ export { defined_2 as defined }
87
33
 
88
34
  declare interface Encoder {
89
35
  fn: (data: unknown, ...args: any[]) => string | Promise<string>;
@@ -104,7 +50,7 @@ export declare interface FieldContext {
104
50
  path: string;
105
51
  root: any;
106
52
  options: ProcessFieldsOptions;
107
- value: string | object | number | NavigateResult | null;
53
+ value: string | object | number | NavigateResult_2 | null;
108
54
  key: string;
109
55
  args: any[];
110
56
  rawArgs: {
@@ -166,23 +112,6 @@ declare interface FilePatternOptions {
166
112
  map: (fileName: string, index: number, array: string[]) => Promise<any>;
167
113
  }
168
114
 
169
- /**
170
- * Finds values in an object tree that match a predicate function.
171
- *
172
- * @public
173
- * @param from - The object to search through
174
- * @param cb - Predicate function that receives the path and value, returns true for matches
175
- * @returns Array of matching values
176
- *
177
- * @example
178
- * ```typescript
179
- * const obj = { a: { b: 1 }, c: { d: 2 } }
180
- * const results = await find(obj, (path, value) => value === 2)
181
- * // results: [2]
182
- * ```
183
- */
184
- export declare const find: (from: any, cb: (path: string, value: any) => boolean) => Promise<any[]>;
185
-
186
115
  export declare const globMap: <T>(pattern: string | string[], options: FilePatternOptions) => Promise<T[] | T>;
187
116
 
188
117
  /**
@@ -298,21 +227,6 @@ export declare const makeFieldProcessorMap: <T = unknown>(source: Record<keyof T
298
227
  keys?: (keyof T)[];
299
228
  }) => FieldProcessorMap;
300
229
 
301
- /**
302
- * @public
303
- * @param source
304
- * @param target
305
- * @param options
306
- */
307
- export declare const merge: (source: any, target: any, options?: MergeOptions) => void;
308
-
309
- /**
310
- * @public
311
- * @param elements
312
- * @param options
313
- */
314
- export declare const mergeAll: (elements: any[], options?: MergeOptions) => any;
315
-
316
230
  /**
317
231
  * @public
318
232
  */
@@ -328,24 +242,6 @@ export declare interface MergeOptions {
328
242
  mode?: (key: string, source: any, target: any, sourceContainer: any, targetContainer: any) => MergeMode | void;
329
243
  }
330
244
 
331
- /**
332
- * Recursively navigates through an object tree, invoking a callback for each property.
333
- * Supports various actions like replacing, deleting, or merging values during traversal.
334
- * Includes circular reference detection to prevent infinite loops.
335
- *
336
- * Performance optimizations:
337
- * - Caches static NavigateResult instances
338
- * - Uses WeakSet for O(1) circular reference detection
339
- * - Avoids Object.entries() to prevent array allocations
340
- * - Optimizes switch statement order for common cases
341
- *
342
- * @public
343
- * @param o - The object to navigate
344
- * @param cb - Callback function invoked for each property
345
- * @throws {Error} When attempting to replace the root object
346
- */
347
- export declare const navigate: (o: any, cb: NavigateCallback) => Promise<void>;
348
-
349
245
  /**
350
246
  * @public
351
247
  */
@@ -399,18 +295,6 @@ export declare class NavigateResult {
399
295
  static DeleteItem(skipSiblings?: boolean): NavigateResult;
400
296
  }
401
297
 
402
- /**
403
- * Maps an array while filtering out null/undefined values (performance optimized)
404
- * Combines filter and map operations to avoid double iteration
405
- * @typeParam T - Type of input array items
406
- * @typeParam U - Type of mapped result items
407
- * @param arr - Array to map (can be undefined)
408
- * @param fn - Mapping function
409
- * @returns Mapped array with nulls/undefined filtered out, or empty array if input is undefined
410
- * @public
411
- */
412
- export declare const nonNullMap: <T, U>(arr: T[] | undefined, fn: (item: T, index: number, array: T[]) => U) => U[];
413
-
414
298
  /**
415
299
  * @public
416
300
  */
@@ -494,36 +378,6 @@ export declare interface Output {
494
378
  class?: string;
495
379
  }
496
380
 
497
- /**
498
- * Adds indentation to each line of a string.
499
- * Useful for formatting multi-line text with consistent indentation.
500
- *
501
- * @example
502
- * padBlock('hello\\nworld', 2) // ' hello\\n world'
503
- * padBlock('a|b|c', 1, '|', '-') // '-a|-b|-c'
504
- *
505
- * @param str - The string to indent
506
- * @param indent - The number of padding units to add
507
- * @param separator - The separator between lines (default: '\\n')
508
- * @param padder - The character to repeat for padding (default: ' ')
509
- * @returns The indented string
510
- */
511
- export declare const padBlock: (str: string, indent: number, separator?: string, padder?: string) => string;
512
-
513
- /**
514
- * Converts a string to PascalCase (UpperCamelCase).
515
- * Handles spaces, underscores, and hyphens as word separators.
516
- *
517
- * @example
518
- * pascal('hello_world') // 'HelloWorld'
519
- * pascal('hello world') // 'HelloWorld'
520
- * pascal('helloWorld') // 'HelloWorld'
521
- *
522
- * @param v - The string to convert
523
- * @returns The string in PascalCase
524
- */
525
- export declare const pascal: (v: string) => string;
526
-
527
381
  /**
528
382
  * @public
529
383
  * @param obj
@@ -548,32 +402,6 @@ export declare const section: (options?: SectionOptions) => (_: any, ctx: ClassM
548
402
 
549
403
  declare type SectionOptions = ObjectorDecoratorOptions;
550
404
 
551
- /**
552
- * Selects a value from a nested object using a path string with advanced querying capabilities
553
- *
554
- * Supports:
555
- * - Dot notation: 'user.profile.name'
556
- * - Array indexing: 'users.0' or 'users[0]'
557
- * - Array filtering: 'users.[name=John].age'
558
- * - References: 'users.\{activeUserId\}.name'
559
- * - Optional paths: 'user.profile?.bio'
560
- * - Default values: 'config.timeout?=5000'
561
- *
562
- * @public
563
- * @param from - The root object to select from
564
- * @param path - The path string to navigate
565
- * @param options - Optional configuration
566
- * @returns The selected value or undefined
567
- *
568
- * @example
569
- * ```typescript
570
- * const obj = { user: { name: 'Alice', age: 30 } }
571
- * select(obj, 'user.name') // 'Alice'
572
- * select(obj, 'user.email', { defaultValue: 'N/A' }) // 'N/A'
573
- * ```
574
- */
575
- export declare const select: <T = any>(from: any, path: string, options?: SelectOptions) => T | undefined;
576
-
577
405
  /**
578
406
  * Options for configuring the select function behavior
579
407
  * @public
@@ -595,122 +423,8 @@ export declare const sharedFunction: (options?: SharedFunctionOptions) => (_: an
595
423
 
596
424
  declare type SharedFunctionOptions = ObjectorDecoratorOptions;
597
425
 
598
- /**
599
- * Converts a string to snake_case or custom_case.
600
- * Inserts the separator between lowercase and uppercase characters.
601
- *
602
- * @example
603
- * snake('helloWorld', '_') // 'hello_world'
604
- * snake('HelloWorld', '-') // 'hello-world'
605
- * snake('hello world', '_') // 'hello_world'
606
- *
607
- * @param v - The string to convert
608
- * @param separator - The separator to use between words (default: '_')
609
- * @returns The string in snake case with the specified separator
610
- */
611
- export declare const snake: (v: string, separator?: string) => string;
612
-
613
- /**
614
- * Sorts an array by a selector function with custom comparison
615
- * Uses a shallow copy to avoid mutating the original array
616
- * @typeParam T - Type of array items
617
- * @typeParam U - Type of comparison values
618
- * @param arr - Array to sort
619
- * @param selector - Function to extract comparison value from item
620
- * @param compare - Comparison function (default: numeric comparison)
621
- * @returns New sorted array
622
- * @public
623
- */
624
- export declare const sortBy: <T, U>(arr: T[], selector: (item: T) => U, compare?: (a: U, b: U) => number) => T[];
625
-
626
426
  declare type SourceFunc = (...args: any[]) => any;
627
427
 
628
- export declare const splitNested: (str: string, separator: string, open?: string, close?: string) => string[];
629
-
630
- /**
631
- * Splits a string by a separator while respecting quoted values.
632
- * Quoted values can contain the separator without being split.
633
- * Supports both single (') and double (") quotes.
634
- *
635
- * @param input - The string to split
636
- * @param separator - Single or multi-character separator (default: ',')
637
- * @returns Array of objects with value and quoted status
638
- *
639
- * @example
640
- * splitWithQuotes('hello, "world", test')
641
- * // Returns: [
642
- * // { value: 'hello', quoted: false },
643
- * // { value: 'world', quoted: true },
644
- * // { value: 'test', quoted: false }
645
- * // ]
646
- *
647
- * @example
648
- * splitWithQuotes('a:: "b:: c":: d', '::')
649
- * // Returns: [
650
- * // { value: 'a', quoted: false },
651
- * // { value: 'b:: c', quoted: true },
652
- * // { value: 'd', quoted: false }
653
- * // ]
654
- */
655
- export declare const splitWithQuotes: (input: string, separator?: string) => {
656
- value: string;
657
- quoted: boolean;
658
- }[];
659
-
660
- export declare const stripIndent: (value: string) => string;
661
-
662
- /**
663
- * Replaces tokens in a string with values from an object.
664
- * Tokens are in the format `$\{key\}`.
665
- *
666
- * @example
667
- * tokenize('Hello $\{name\}', { name: 'World' }) // 'Hello World'
668
- * tokenize('$\{greeting\} $\{name\}!', { greeting: 'Hi', name: 'Alice' }) // 'Hi Alice!'
669
- * tokenize('$\{missing\}', {}) // ''
670
- *
671
- * @param str - The string containing tokens
672
- * @param from - An object with key-value pairs for token replacement
673
- * @param tokenizer - The regex pattern for token matching (default: `/\$\{([^}]+)\}/g`)
674
- * @returns The string with tokens replaced by values from the object
675
- */
676
- export declare const tokenize: (str: string, from: Record<string, unknown>, tokenizer?: RegExp) => string;
677
-
678
- /**
679
- * Converts an object's entries into an array of objects with a key property
680
- * @typeParam T - The type of items in the resulting array
681
- * @param from - Object to convert
682
- * @param key - Property name to use for keys (default: 'name')
683
- * @returns Array of objects with key properties
684
- * @example
685
- * toList({ a: { value: 1 }, b: { value: 2 } }) // [{ name: 'a', value: 1 }, { name: 'b', value: 2 }]
686
- * @public
687
- */
688
- export declare const toList: <T>(from: Record<string, unknown>, key?: string) => T[];
689
-
690
- /**
691
- * Converts an array into an object indexed by a key property, excluding the key from items
692
- * @typeParam T - The type of the resulting object values
693
- * @param from - Array to convert
694
- * @param key - Property name to use as key (default: 'name')
695
- * @returns Object indexed by key values, without the key property in values
696
- * @example
697
- * toObject([{ name: 'a', value: 1 }]) // { a: { value: 1 } }
698
- * @public
699
- */
700
- export declare const toObject: <T extends Record<string, unknown>>(from: T[], key?: string) => Record<string, Omit<T, typeof key>>;
701
-
702
- /**
703
- * Converts an array into an object indexed by a key property, keeping the full items
704
- * @typeParam T - The type of the resulting object
705
- * @param from - Array to convert
706
- * @param key - Property name to use as key (default: 'name')
707
- * @returns Object indexed by key values
708
- * @example
709
- * toObjectWithKey([{ name: 'a', value: 1 }]) // { a: { name: 'a', value: 1 } }
710
- * @public
711
- */
712
- export declare const toObjectWithKey: <T extends Record<string, unknown>>(from: T[], key?: string) => Record<string, T>;
713
-
714
428
  export declare const variable: (options?: VariableOptions) => (_: any, ctx: ClassFieldDecoratorContext<ObjectorPlugin, any>) => void;
715
429
 
716
430
  declare type VariableOptions = ObjectorDecoratorOptions;
@@ -750,14 +464,14 @@ export declare interface WriteOutputsOption extends WriteOutputOption {
750
464
 
751
465
  export { }
752
466
 
753
-
754
- /* Global declarations from framework */
467
+ /* Global declarations */
755
468
 
756
469
  declare global {
757
470
  type Constructor<T = any> = new (...args: any[]) => T;
758
471
  type MaybePromise<T> = T | Promise<T>;
759
472
  type AsyncFunction<T = any> = (...args: any[]) => Promise<T>;
760
473
  var AsyncFunction: typeof Function;
474
+ var defined: <T>(value: T | undefined | null, msg?: string) => T;
761
475
  }
762
476
 
763
477
  declare global {
@@ -775,6 +489,7 @@ declare global {
775
489
  findOrFail(predicate: (value: T, index: number, array: T[]) => boolean, message?: string, thisArg?: any): T;
776
490
  selectFor<K>(predicate: (value: T, index: number, array: T[]) => boolean, selector: (value: T) => K, message?: string, thisArg?: any): K;
777
491
  createInstances<TTarget>(targetConstructor: new (...args: any[]) => TTarget, ...args: any[]): TTarget[];
492
+ mergeAll(options?: MergeOptions): any;
778
493
  }
779
494
  interface ArrayConstructor {
780
495
  flat<T>(v: T | T[] | T[][]): T[];
@@ -786,7 +501,29 @@ declare global {
786
501
  mapEntries<T extends object, U>(obj: T, callback: (key: keyof T, value: T[keyof T]) => [string | number | symbol, U]): Record<string | number | symbol, U>;
787
502
  toList<T extends object, U extends object, X extends string>(obj: T, key: X): (Record<X, string> & U)[];
788
503
  deepClone<T extends object>(obj: T): T;
789
- find<T extends object, K extends keyof T>(obj: Record<string, T>, predicate: (value: T, key: string) => boolean): [K, T] | undefined;
790
- findAll<T extends object, K extends keyof T>(obj: Record<string, T>, predicate: (value: T, key: string) => boolean): [K, T][];
504
+ merge(source: any, target: any, options?: MergeOptions): void;
505
+ navigate(o: any, cb: NavigateCallback): Promise<void>;
506
+ find(from: any, cb: (path: string, value: any) => boolean): Promise<any[]>;
507
+ select(from: any, path: string, options?: SelectOptions): any;
508
+ }
509
+ }
510
+
511
+ declare global {
512
+ interface String {
513
+ capitalize(): string;
514
+ toPascal(): string;
515
+ toCamel(): string;
516
+ toSnake(): string;
517
+ toKebab(): string;
518
+ changeCase(to: 'upper' | 'lower' | 'pascal' | 'camel' | 'snake' | 'kebab'): string;
519
+ splitWithQuotes(separator?: string): {
520
+ value: string;
521
+ quoted: boolean;
522
+ }[];
523
+ splitNested(separator: string, open: string, close: string): string[];
524
+ padBlock(indent: number, separator?: string, padder?: string): string;
525
+ tokenize(from: Record<string, unknown>, tokenizer?: RegExp): string;
526
+ stripIndent(): string;
791
527
  }
792
528
  }
529
+
package/dist/index.js CHANGED
@@ -1,23 +1,23 @@
1
- var xr=Object.create;var{getPrototypeOf:to,defineProperty:G,getOwnPropertyNames:Fr,getOwnPropertyDescriptor:no}=Object,Ye=Object.prototype.hasOwnProperty;function Ge(e){return this[e]}var D=(e,r,t)=>{var n=Fr(r);for(let o of n)if(!Ye.call(e,o)&&o!=="default")G(e,o,{get:Ge.bind(r,o),enumerable:!0});if(t){for(let o of n)if(!Ye.call(t,o)&&o!=="default")G(t,o,{get:Ge.bind(r,o),enumerable:!0});return t}},oo,io,so=(e,r,t)=>{var n=e!=null&&typeof e==="object";if(n){var o=r?oo??=new WeakMap:io??=new WeakMap,i=o.get(e);if(i)return i}t=e!=null?xr(to(e)):{};let l=r||!e||!e.__esModule?G(t,"default",{value:e,enumerable:!0}):t;for(let a of Fr(e))if(!Ye.call(l,a))G(l,a,{get:Ge.bind(e,a),enumerable:!0});if(n)o.set(e,l);return l};var ao=(e,r)=>()=>(r||e((r={exports:{}}).exports,r),r.exports),Mr=(e,r)=>{return Object.defineProperty(e,"name",{value:r,enumerable:!1,configurable:!0}),e},lo=(e)=>e;function uo(e,r){this[e]=lo.bind(null,r)}var C=(e,r)=>{for(var t in r)G(e,t,{get:r[t],enumerable:!0,configurable:!0,set:uo.bind(r,t)})};var Dr=(e,r)=>(r=Symbol[e])?r:Symbol.for("Symbol."+e),ae=(e)=>{throw TypeError(e)},co=(e,r,t)=>(r in e)?G(e,r,{enumerable:!0,configurable:!0,writable:!0,value:t}):e[r]=t;var Qe=(e,r,t)=>r.has(e)||ae("Cannot "+t),fo=(e,r)=>Object(r)!==r?ae('Cannot use the "in" operator on this value'):e.has(r),Sr=(e,r,t)=>(Qe(e,r,"read from private field"),t?t.call(e):r.get(e));var kr=(e,r,t,n)=>(Qe(e,r,"write to private field"),n?n.call(e,t):r.set(e,t),t),po=(e,r,t)=>(Qe(e,r,"access private method"),t),jr=(e)=>[,,,xr(e?.[Dr("metadata")]??null)],Rr=["class","method","getter","setter","accessor","field","value","get","set"],se=(e)=>e!==void 0&&typeof e!=="function"?ae("Function expected"):e,mo=(e,r,t,n,o)=>({kind:Rr[e],name:r,metadata:n,addInitializer:(i)=>t._?ae("Already initialized"):o.push(se(i||null))}),Xe=(e,r)=>co(r,Dr("metadata"),e[3]),$r=(e,r,t,n)=>{for(var o=0,i=e[r>>1],l=i&&i.length;o<l;o++)r&1?i[o].call(t):n=i[o].call(t,n);return n},m=(e,r,t,n,o,i)=>{var l,a,c,w,O,y=r&7,u=!!(r&8),d=!!(r&16),v=y>3?e.length+1:y?u?1:2:0,g=Rr[y+5],A=y>3&&(e[v-1]=[]),f=e[v]||(e[v]=[]),S=y&&(!d&&!u&&(o=o.prototype),y<5&&(y>3||!d)&&no(y<4?o:{get[t](){return Sr(this,i)},set[t](M){kr(this,i,M)}},t));y?d&&y<4&&Mr(i,(y>2?"set ":y>1?"get ":"")+t):Mr(o,t);for(var b=n.length-1;b>=0;b--){if(w=mo(y,t,c={},e[3],f),y){if(w.static=u,w.private=d,O=w.access={has:d?(M)=>fo(o,M):(M)=>(t in M)},y^3)O.get=d?(M)=>(y^1?Sr:po)(M,o,y^4?i:S.get):(M)=>M[t];if(y>2)O.set=d?(M,k)=>kr(M,o,k,y^4?i:S.set):(M,k)=>M[t]=k}if(a=(0,n[b])(y?y<4?d?i:S[g]:y>4?void 0:{get:S.get,set:S.set}:o,w),c._=1,y^4||a===void 0)se(a)&&(y>4?A.unshift(a):y?d?i=a:S[g]=a:o=a);else if(typeof a!=="object"||a===null)ae("Object expected");else se(l=a.get)&&(S.get=l),se(l=a.set)&&(S.set=l),se(l=a.init)&&A.unshift(l)}return y||Xe(e,o),S&&G(o,t,S),d?y^4?i:S:o};var Dt=ao((ol,Ft)=>{var{defineProperty:Tr,getOwnPropertyNames:mi,getOwnPropertyDescriptor:gi}=Object,yi=Object.prototype.hasOwnProperty,kt=new WeakMap,di=(e)=>{var r=kt.get(e),t;if(r)return r;if(r=Tr({},"__esModule",{value:!0}),e&&typeof e==="object"||typeof e==="function")mi(e).map((n)=>!yi.call(r,n)&&Tr(r,n,{get:()=>e[n],enumerable:!(t=gi(e,n))||t.enumerable}));return kt.set(e,r),r},hi=(e,r)=>{for(var t in r)Tr(e,t,{get:r[t],enumerable:!0,configurable:!0,set:(n)=>r[t]=()=>n})},xt={};hi(xt,{splitWithQuotes:()=>bi,splitNested:()=>wi});Ft.exports=di(xt);var wi=(e,r,t="(",n=")")=>{let o=0,i="",l=[];for(let a of e){if(i+=a,a===t)o++;if(a===n)o--;if(o===0&&a===r)l.push(i.slice(0,-1)),i=""}if(i)l.push(i);return l},bi=(e,r=",")=>{let t=[],n=e.length,o=r.length,i=0,l=(a)=>{if(a+o>n)return!1;for(let c=0;c<o;c++)if(e[a+c]!==r[c])return!1;return!0};while(i<n){while(i<n&&e[i]===" ")i++;if(i>=n)break;let a="",c=e[i]==='"'||e[i]==="'";if(c){let w=e[i++];while(i<n&&e[i]!==w)a+=e[i++];if(i<n)i++}else{while(i<n&&!l(i)){let w=e[i];if(w==='"'||w==="'"){a+=w,i++;while(i<n&&e[i]!==w)a+=e[i++];if(i<n)a+=e[i++]}else a+=e[i++]}a=a.trim()}if(a)t.push({value:a,quoted:c});if(l(i))i+=o}return t}});var N={};C(N,{writeOutputs:()=>me,writeOutput:()=>je,writeFormat:()=>De,variable:()=>pr,tokenize:()=>Or,toObjectWithKey:()=>or,toObject:()=>ge,toList:()=>Z,stripIndent:()=>Ar,sortBy:()=>ar,snake:()=>re,sharedFunction:()=>mr,select:()=>x,section:()=>cr,processFields:()=>$,pascal:()=>ee,padBlock:()=>_,nonNullMap:()=>ir,navigate:()=>Ce,mergeAll:()=>z,merge:()=>U,makeFieldProcessorMap:()=>B,makeFieldProcessorList:()=>qe,makeFieldProcessor:()=>ce,macro:()=>p,locate:()=>X,loadFormat:()=>fe,key:()=>fr,importList:()=>Re,importGlob:()=>tr,globMap:()=>pe,getProcessor:()=>ue,getArgs:()=>Fe,find:()=>hr,exists:()=>q,encoder:()=>gr,defined:()=>sr,deepClone:()=>W,decoder:()=>yr,conditionPredicates:()=>K,changeCase:()=>te,capital:()=>he,camel:()=>we,asyncMap:()=>lr,ObjectorPlugin:()=>P,Objector:()=>$t,NavigateResult:()=>E,NavigateAction:()=>$e,Logger:()=>Be,AsyncFunction:()=>Er});var ze={};C(ze,{processFields:()=>$,makeFieldProcessorMap:()=>B,makeFieldProcessorList:()=>qe,makeFieldProcessor:()=>ce,getProcessor:()=>ue,getArgs:()=>Fe});var go=Object.create,{getPrototypeOf:yo,defineProperty:Cr,getOwnPropertyNames:ho}=Object,wo=Object.prototype.hasOwnProperty,bo=(e,r,t)=>{t=e!=null?go(yo(e)):{};let n=r||!e||!e.__esModule?Cr(t,"default",{value:e,enumerable:!0}):t;for(let o of ho(e))if(!wo.call(n,o))Cr(n,o,{get:()=>e[o],enumerable:!0});return n},Oo=(e,r)=>()=>(r||e((r={exports:{}}).exports,r),r.exports),Ao=Oo((e,r)=>{var{defineProperty:t,getOwnPropertyNames:n,getOwnPropertyDescriptor:o}=Object,i=Object.prototype.hasOwnProperty,l=new WeakMap,a=(u)=>{var d=l.get(u),v;if(d)return d;if(d=t({},"__esModule",{value:!0}),u&&typeof u==="object"||typeof u==="function")n(u).map((g)=>!i.call(d,g)&&t(d,g,{get:()=>u[g],enumerable:!(v=o(u,g))||v.enumerable}));return l.set(u,d),d},c=(u,d)=>{for(var v in d)t(u,v,{get:d[v],enumerable:!0,configurable:!0,set:(g)=>d[v]=()=>g})},w={};c(w,{splitWithQuotes:()=>y,splitNested:()=>O}),r.exports=a(w);var O=(u,d,v="(",g=")")=>{let A=0,f="",S=[];for(let b of u){if(f+=b,b===v)A++;if(b===g)A--;if(A===0&&b===d)S.push(f.slice(0,-1)),f=""}if(f)S.push(f);return S},y=(u,d=",")=>{let v=[],g=u.length,A=d.length,f=0,S=(b)=>{if(b+A>g)return!1;for(let M=0;M<A;M++)if(u[b+M]!==d[M])return!1;return!0};while(f<g){while(f<g&&u[f]===" ")f++;if(f>=g)break;let b="",M=u[f]==='"'||u[f]==="'";if(M){let k=u[f++];while(f<g&&u[f]!==k)b+=u[f++];if(f<g)f++}else{while(f<g&&!S(f)){let k=u[f];if(k==='"'||k==="'"){b+=k,f++;while(f<g&&u[f]!==k)b+=u[f++];if(f<g)b+=u[f++]}else b+=u[f++]}b=b.trim()}if(b)v.push({value:b,quoted:M});if(S(f))f+=A}return v}}),vo=bo(Ao(),1),Q;((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"})(Q||={});class j{action;by;skipSiblings;reexplore;constructor(e,r,t,n){this.action=e,this.by=r,this.skipSiblings=t,this.reexplore=n}static _explore=new j(0);static _noExplore=new j(2);static _skipSiblings=new j(1);static _deleteParent=new j(4);static ReplaceParent(e,r){return new j(3,e,void 0,r)}static SkipSiblings(){return j._skipSiblings}static Explore(){return j._explore}static NoExplore(){return j._noExplore}static DeleteParent(){return j._deleteParent}static MergeParent(e){return new j(5,e)}static ReplaceItem(e,r){return new j(6,e,r)}static DeleteItem(e){return new j(7,void 0,e)}}var To=async(e,r)=>{let t=new WeakSet,n=[],o=[],i=async(a,c,w)=>{let O=a===null,y=O?j.Explore():await r({key:a,value:c,path:n,parent:w,parents:o});if(c&&typeof c==="object"&&y.action===0){if(t.has(c))return y;if(t.add(c),!O)n.push(a),o.push(w);let u=c;while(await l(u,a,w))u=w[a];if(!O)o.pop(),n.pop()}return y},l=async(a,c,w)=>{let O=Object.keys(a),y=O.length;for(let u=0;u<y;u++){let d=O[u],v=a[d],g=await i(d,v,a),A=g.action;if(A===0||A===2)continue;if(A===6){if(a[d]=g.by,g.skipSiblings)return;continue}if(A===7){if(delete a[d],g.skipSiblings)return;continue}if(A===1)return;if(A===3){if(c===null)throw Error("Cannot replace root object");if(w[c]=g.by,g.reexplore)return!0;return}if(A===4){if(c===null)throw Error("Cannot delete root object");delete w[c];return}if(A===5)delete a[d],Object.assign(a,g.by)}};await i(null,e,null)},Eo=Object.create,{getPrototypeOf:Mo,defineProperty:Wr,getOwnPropertyNames:So}=Object,ko=Object.prototype.hasOwnProperty,xo=(e,r,t)=>{t=e!=null?Eo(Mo(e)):{};let n=r||!e||!e.__esModule?Wr(t,"default",{value:e,enumerable:!0}):t;for(let o of So(e))if(!ko.call(n,o))Wr(n,o,{get:()=>e[o],enumerable:!0});return n},Fo=(e,r)=>()=>(r||e((r={exports:{}}).exports,r),r.exports),Do=Fo((e,r)=>{var{defineProperty:t,getOwnPropertyNames:n,getOwnPropertyDescriptor:o}=Object,i=Object.prototype.hasOwnProperty,l=new WeakMap,a=(u)=>{var d=l.get(u),v;if(d)return d;if(d=t({},"__esModule",{value:!0}),u&&typeof u==="object"||typeof u==="function")n(u).map((g)=>!i.call(d,g)&&t(d,g,{get:()=>u[g],enumerable:!(v=o(u,g))||v.enumerable}));return l.set(u,d),d},c=(u,d)=>{for(var v in d)t(u,v,{get:d[v],enumerable:!0,configurable:!0,set:(g)=>d[v]=()=>g})},w={};c(w,{splitWithQuotes:()=>y,splitNested:()=>O}),r.exports=a(w);var O=(u,d,v="(",g=")")=>{let A=0,f="",S=[];for(let b of u){if(f+=b,b===v)A++;if(b===g)A--;if(A===0&&b===d)S.push(f.slice(0,-1)),f=""}if(f)S.push(f);return S},y=(u,d=",")=>{let v=[],g=u.length,A=d.length,f=0,S=(b)=>{if(b+A>g)return!1;for(let M=0;M<A;M++)if(u[b+M]!==d[M])return!1;return!0};while(f<g){while(f<g&&u[f]===" ")f++;if(f>=g)break;let b="",M=u[f]==='"'||u[f]==="'";if(M){let k=u[f++];while(f<g&&u[f]!==k)b+=u[f++];if(f<g)f++}else{while(f<g&&!S(f)){let k=u[f];if(k==='"'||k==="'"){b+=k,f++;while(f<g&&u[f]!==k)b+=u[f++];if(f<g)b+=u[f++]}else b+=u[f++]}b=b.trim()}if(b)v.push({value:b,quoted:M});if(S(f))f+=A}return v}}),jo=xo(Do(),1),Ro=/^\[([^=\]]*)([=]*)([^\]]*)\]$/,$o=/^([^[\]]*)\[([^\]]*)]$/,Ze=(e,r,t,n)=>{if(e.startsWith("{")&&e.endsWith("}")){let o=e.substring(1,e.length-1);return le(r,o,t)?.toString()}return n?e:void 0},Co=(e,r,t,n)=>{let o=Ze(r,t,n);if(o)return le(e,o,n);let i=Ro.exec(r);if(i){let[,a,c,w]=i,O=Ze(a.trim(),t,n,!0),y=Ze(w.trim(),t,n,!0);if(Array.isArray(e)&&(c==="="||c==="==")&&O)return e.find((u)=>u?.[O]==y)}let l=$o.exec(r);if(l){let[,a,c]=l;return e?.[a]?.[c]}return e?.[r]},le=(e,r,t)=>{let n=void 0,o=void 0,i=r??"",l=(y)=>{if(!y)return[y,!1];return y.endsWith("?")?[y.substring(0,y.length-1),!0]:[y,!1]},a=(y,u)=>{let[d,v]=l(u.pop());if(!d){if(t?.set!==void 0&&o!==void 0&&n!==void 0)n[o]=t.set;return y}let g=Co(y,d,e,t);if(g===void 0){if(v||t?.optional||t?.defaultValue!==void 0)return;throw Error(`Unknown path element: "${d}" in "${i}"`)}return n=y,o=d,a(g,u)},c=jo.splitNested(i,t?.separator??".","{","}"),w=void 0;if(c.length>0&&c[c.length-1].startsWith("?="))w=c.pop()?.substring(2);c.reverse();let O=a(e,c);if(O===void 0)return w??t?.defaultValue;return O},Nr=(e,r)=>{if(typeof e.value==="string"){if(e.quoted)return e.value;if(e.value.startsWith("[")&&e.value.endsWith("]")){let t=e.value.slice(1,-1);if(t.trim()==="")return[];return t.split(";").map((n)=>{let o=n.trim();if(!isNaN(+o))return+o;return o})}if(e.value.startsWith("{")&&e.value.endsWith("}")){if(e.value.slice(1,-1).trim()==="")return{}}if(e.value==="null")return null;if(e.value==="undefined")return;if(e.value.startsWith("@"))return e.value.slice(1);if(!isNaN(+e.value))return+e.value}return r(e.value)},xe=(e,r,t,n,o,i)=>{let l=n?.(e)??e,a=o(l);if(a[0])return a[1];if(!r){let c=le(t,e),w=o(c);if(w[0])return w[1]}throw Error(i)},Ur=(e,r,t,n,o)=>{let i=typeof e.types==="function"?e.types(n,r.value,o):e.types?.[n];if(!i||i==="ref")return Nr(r,(a)=>le(t,a));let l=Nr(r,()=>r.value);if(Array.isArray(i)){if(!i.includes(l))throw Error(`Argument ${n.toString()} must be one of [${i.join(", ")}]: ${l}`);return l}if(typeof i==="string"){if(i.endsWith("?")){let a=i.slice(0,-1);if(r.value==="null")return j.ReplaceItem(null);if(r.value==="undefined")return j.ReplaceItem(void 0);if(r.value==="")return"";i=a}switch(i){case"any":return l;case"array":return xe(l,r.quoted,t,null,(a)=>[Array.isArray(a),a],`Argument ${n.toString()} must be an array: ${l}`);case"object":return xe(l,r.quoted,t,null,(a)=>[typeof a==="object"&&a!==null,a],`Argument ${n.toString()} must be an object: ${l}`);case"number":return xe(l,r.quoted,t,(a)=>Number(a),(a)=>[!isNaN(a),a],`Argument ${n.toString()} must be a number: ${l}`);case"boolean":return xe(l,r.quoted,t,null,(a)=>{if([!0,"true","1",1,"yes","on"].includes(a))return[!0,!0];if([!1,"false","0",0,"no","off"].includes(a))return[!0,!1];if([null,"null","undefined",void 0,""].includes(a))return[!0,!1];if(Array.isArray(a))return[!0,a.length>0];return[!1,!1]},`Argument ${n.toString()} must be a boolean: ${l}`);case"string":return l.toString();default:throw Error(`Unknown type for argument ${n.toString()}: ${i}`)}}return i(l,t,n,r.quoted)},ue=(e,r)=>{let t=e?.[r];if(t===void 0)throw Error(`Unhandled field processor type: ${r}`);return typeof t==="function"?{options:{},fn:t}:{options:t,fn:t.fn}},Ir=(e)=>!e.quoted&&e.value.startsWith("."),Wo=(e)=>{let r={};for(let t of e){if(!Ir(t))continue;let n=t.value.indexOf("="),o=n>-1?t.value.slice(1,n):t.value.slice(1),i=n>-1?t.value.slice(n+1):"";if(i.length>=2){let l=i[0],a=i[i.length-1];if(l==='"'&&a==='"'||l==="'"&&a==="'")i=i.slice(1,-1)}if(!r[o])r[o]=[];r[o].push(i)}return r},Fe=(e,r,t)=>{let n=vo.splitWithQuotes(e??""),o=Wo(n),i=n.filter((a)=>!Ir(a)),l=r.options.processArgs===!1?[]:i.map((a,c)=>Ur(r.options,a,t,c,i));return{rawArgs:i,parsedArgs:l,tags:o}},No=(e)=>{return e!==null&&typeof e==="object"&&"action"in e},Ko=(e,r)=>r.keys!==void 0&&e.key.startsWith(".")&&r.keys[e.key.substring(1)]!==void 0,Uo=async(e,r,t,n)=>{let{key:o,parent:i}=e,l=ue(n.keys,o.substring(1));if(l.options.processArgs!==!1&&(typeof l.options.types==="function"||l.options.types?.[0]!==void 0))e.value=Ur(l.options,{value:e.value,quoted:!1},t,0,[]);if(typeof e.value!=="string")await $(e.value,{...n,root:{...t,parent:e.parent,parents:e.parents},filters:[...n.filters??[],...l.options.filters??[]]});let a=await l.fn({path:r,root:t,parent:i,key:o,options:n,value:e.value,args:[],rawArgs:[],tags:{}});return No(a)?a:j.ReplaceParent(a)},Kr=(e)=>{let r=e.split(/\r?\n/),t=r.filter((o)=>o.trim().length>0).map((o)=>/^[ \t]*/.exec(o)?.[0].length??0),n=t.length>0?Math.min(...t):0;if(n===0)return e;return r.map((o)=>o.slice(n)).join(`
2
- `)},Io=async(e,r,t,n)=>{if(!r?.onSection&&!r?.onSectionConfig&&!r?.sections)return[e,!1];let o=/<@\s*section(?:\s*:\s*([\w-]+))?\s*@>([\s\S]*?)<@\s*\/\s*section\s*@>/g,i,l=e,a=0,c=!1,w={content:l,root:n,path:t,options:r,section:{}};while((i=o.exec(e))!==null){c=!0;let[O,y,u]=i,d=i.index,v=d+O.length,g=e[v]===`
3
- `;if(g)v++;let A=d+a,f=v+a,S={},b=u,M=/(^|\r?\n)[ \t]*---[ \t]*(\r?\n|$)/m.exec(u);if(M){let oe=u.slice(0,M.index),Pe=M.index+M[0].length;b=u.slice(Pe);let Se=Kr(oe).trim();if(Se.length>0)try{S=r?.configParser?.(Se)??{}}catch(Ve){throw Error(`Failed to parse YAML config for section: ${Ve.message}`)}}else if(/^\r?\n/.test(b))b=b.replace(/^\r?\n/,"");b=Kr(b),b=b.replace(/(?:\r?\n[ \t]*)+$/,""),b=b.replace(/[ \t]+$/,"");let k={config:y?{...S,type:y}:S,content:b};if(w.content=l,w.section=k,Object.keys(k.config).length>0){if(await r.onSectionConfig?.(w)!==!1)await $(k.config,{...r,root:n})}let ve=w.section.config.type?r.sections?.[w.section.config.type]:void 0,Y;if(ve)Y=await ve(w);else if(r.onSection)Y=await r.onSection(w);if(k.trim)k.content=k.content.trim();if(k.indent)k.content=k.content.split(`
4
- `).map((oe)=>" ".repeat(k.indent)+oe).join(`
5
- `);let L="";if(Y===!0||k.show)L=k.content;else if(typeof Y==="string")L=Y;if(g&&L!==""&&!L.endsWith(`
6
- `))L+=`
7
- `;let Te=l.lastIndexOf(`
8
- `,A-1),Ee=Te===-1?0:Te+1,Me=l.slice(Ee,A).trim().length===0?Ee:A;l=l.slice(0,Me)+L+l.slice(f),a+=L.length-(f-Me),w.content=l}return[l,c]},Lr=(e)=>{let r=[],t=0;while(t<e.length)if(e[t]==="$"&&e[t+1]==="("&&(t===0||e[t-1]!=="\\")){let n=t;t+=2;let o=1;for(;t<e.length;t++)if(e[t]==="(")o++;else if(e[t]===")"){if(o--,o===0){r.push([n,t]);break}}if(o!==0)throw Error(`Unmatched opening $( at position ${n.toString()}`);t++}else t++;return r},He=Symbol.for("@homedev/fields:OverrideResult"),Lo=(e)=>({[He]:!0,value:e}),_o=(e)=>{return e!==null&&typeof e==="object"&&He in e&&e[He]===!0},_r=async(e,r,t)=>{for(let n=r.length-1;n>=0;n--){let[o,i]=r[n],l=e.slice(o+2,i),a=await _r(l,Lr(l),t);if(typeof a==="object")return a;let c=await t(a,e);if(_o(c))return c.value;e=e.slice(0,o)+c+e.slice(i+1)}return e},Bo=async(e,r)=>_r(e,Lr(e),r),Po=(e)=>{return e!==null&&typeof e==="object"&&"action"in e},Vo=/([\w\d.-_/]+):(.+)/,Yo=async(e,r,t,n)=>{let o=await(async()=>{let i=Vo.exec(e);if(!i)return await le(r,e);let[l,a,c]=i,w=ue(n.sources,a),O=Fe(c,w,r);return await w.fn({args:O.parsedArgs,rawArgs:O.rawArgs,tags:O.tags,key:a,options:n,root:r,path:t,value:null})})();if(o===null||o===void 0)return"";if(typeof o==="object")return Lo(o);return o},Br=async(e,r,t,n)=>{let o=await Bo(r,(i)=>Yo(i,t,e,n));if(Po(o))return o;if(o===r)return j.Explore();if(typeof o==="string"){let i=await Br(e,o,t,n);if(i.action!==Q.Explore)return i;return j.ReplaceItem(o)}return j.ReplaceItem(o)},$=async(e,r)=>{return r??={},await To(e,async(t)=>{let n=[...t.path,t.key].join(".");if(r?.filters?.length&&r.filters.some((a)=>a.test(n)))return j.NoExplore();let o=t.path.length===0,i=t.parents.length>0?t.parents.toReversed():[];if(o){if(i.length>0)throw Error("Root object should not have a parent");i=r?.root?.parents?[r.root.parent,...r.root.parents.toReversed()]:[]}let l={...e,...r.root,this:t.parent,parent:i.length>0?i[0]:null,parents:i};try{if(t.key.startsWith("$"))return j.NoExplore();let a=j.Explore();if(typeof t.value==="string"){let c=t.value,w=!1;while(!0){let[O,y]=await Io(c,r,n,l);if(w=w||y,a=await Br(n,O,l,r),a.action===Q.ReplaceItem&&typeof a.by==="string"){c=a.by;continue}if(a.action===Q.Explore&&y&&O!==c)a=j.ReplaceItem(O);break}if(a.action===Q.Explore&&c!==t.value)a=j.ReplaceItem(c);switch(a.action){case Q.Explore:break;case Q.ReplaceItem:t.value=a.by;break;default:return a}}if(Ko(t,r))a=await Uo(t,n,l,r);return a}catch(a){throw Error(`${a.message}
9
- (${n})`)}}),e},ce=(e,r)=>r?{fn:(t)=>e(...t.args),types:r}:(t)=>e(...t.args),qe=(e,r)=>Object.fromEntries(e.map((t)=>[t.name,ce(t,r?.types?.[t.name])])),B=(e,r)=>Object.fromEntries((r?.keys??Object.keys(e)).map((t)=>[t,ce(e[t],r?.types?.[t])]));var nr={};C(nr,{writeOutputs:()=>me,writeOutput:()=>je,writeFormat:()=>De,locate:()=>X,loadFormat:()=>fe,importList:()=>Re,importGlob:()=>tr,globMap:()=>pe,exists:()=>q});import Pr from"fs/promises";import Je from"path";import Go from"fs/promises";import Qo from"path";import Xo from"fs/promises";import Zo from"fs/promises";import Gr from"fs/promises";import Vr from"path";import Ho from"fs/promises";import er from"path";import Yr from"path";var q=async(e)=>{try{return await Pr.access(e,Pr.constants.R_OK),!0}catch{return!1}},X=async(e,r)=>{let t=!Je.isAbsolute(e)&&r?["",...r]:[""];for(let n of t){let o=Je.join(n,e);if(await q(o))return Je.resolve(o)}throw Error(`File not found: "${e}"`)},fe=async(e,r)=>{let t=await X(e,r?.dirs),n=await Go.readFile(t,"utf-8"),o=Qo.dirname(t),i={text:{fn:(a)=>a,matching:["\\.txt$","\\.text$"]},json:{fn:JSON.parse,matching:["\\.json$"]},...r?.parsers},l=r?.format?i[r.format]:Object.values(i).find((a)=>a.matching?.some((c)=>new RegExp(c).test(e)));if(!l)throw Error(`Unsupported format for file "${e}" and no matching parser found`);return{content:await l.fn(n),fullPath:t,folderPath:o}},De=async(e,r,t)=>{let n={text:{fn:(i)=>i,matching:["\\.txt$","\\.text$"]},json:{fn:JSON.stringify,matching:["\\.json$"]},...t?.encoders},o=t?.format?n[t.format]:Object.values(n).find((i)=>i.matching?.some((l)=>new RegExp(l).test(e)));if(!o)throw Error(`Unsupported format for file "${e}" and no matching encoder found`);await Xo.writeFile(e,await o.fn(r))},pe=async(e,r)=>{if(typeof e==="string"&&!e.includes("*"))return await r.map(e,0,[]);let t=await Array.fromAsync(Zo.glob(e,{cwd:r.cwd})),n=r.filter?t.filter(r.filter):t;return await Promise.all(n.map(r.map))},me=async(e,r)=>{if(r?.targetDirectory&&r?.removeFirst)try{await Gr.rm(r?.targetDirectory,{recursive:!0,force:!0})}catch(t){throw Error(`Failed to clean the output directory: ${t.message}`)}for(let t of e)await je(t,r)},je=async(e,r)=>{let t=Vr.join(r?.targetDirectory??".",e.name),n=Vr.dirname(t);if(r?.classes){if(e.class!==void 0&&!r.classes.includes(e.class))return;if(r.classRequired&&e.class===void 0)throw Error(`Output "${e.name}" is missing class field`)}if(r?.writing?.(e)===!1)return;try{await Gr.mkdir(n,{recursive:!0})}catch(o){throw Error(`Failed to create target directory "${n}" for output "${t}": ${o.message}`)}try{await De(t,e.value,{format:e.type??"text"})}catch(o){throw Error(`Failed to write output "${t}": ${o.message}`)}},rr=(e)=>e?Yr.isAbsolute(e)?e:Yr.join(process.cwd(),e):process.cwd(),Re=async(e,r)=>{let t=[];for(let n of e)try{let o=!er.isAbsolute(n)?er.join(rr(r?.cwd),n):n;if(r?.filter?.(o)===!1)continue;let i=await import(o);if(r?.resolveDefault==="only"&&!i.default)throw Error(`Module ${n} does not have a default export`);let l=r?.resolveDefault?i.default??i:i,a=r?.map?await r.map(l,n):l;if(a!==void 0)t.push(a)}catch(o){if(r?.fail?.(n,o)===!1)continue;throw Error(`Failed to import module ${n}: ${o.message??o}`)}return t},tr=async(e,r)=>{let t=[];for(let n of e){let o=(await Array.fromAsync(Ho.glob(n,{cwd:rr(r?.cwd)}))).map((i)=>er.join(rr(r?.cwd),i));t.push(...await Re(o,r))}return t};var ur={};C(ur,{toObjectWithKey:()=>or,toObject:()=>ge,toList:()=>Z,sortBy:()=>ar,nonNullMap:()=>ir,defined:()=>sr,deepClone:()=>W,asyncMap:()=>lr});var Z=(e,r="name")=>Object.entries(e).map(([t,n])=>({[r]:t,...n})),or=(e,r="name")=>Object.fromEntries(e.map((t)=>[t[r],t])),ge=(e,r="name")=>Object.fromEntries(e.map((t)=>{let{[r]:n,...o}=t;return[n,o]})),ir=(e,r)=>{if(!e)return[];let t=[],n=0;for(let o of e)if(o!==null&&o!==void 0)t.push(r(o,n,e)),n++;return t},sr=(e,r="Value is undefined")=>{if(e===void 0||e===null)throw Error(r);return e},ar=(e,r,t=(n,o)=>n-o)=>e.slice().sort((n,o)=>t(r(n),r(o))),lr=async(e,r)=>Promise.all(e.map(r)),W=(e)=>{if(typeof structuredClone<"u")try{return structuredClone(e)}catch{}return JSON.parse(JSON.stringify(e))};var dr={};C(dr,{variable:()=>pr,sharedFunction:()=>mr,section:()=>cr,macro:()=>p,key:()=>fr,encoder:()=>gr,decoder:()=>yr,ObjectorPlugin:()=>P});class P{o;context;constructor(e){this.o=e}}var p=(e)=>(r,t)=>{t.addInitializer(function(){let n=this[t.name],o=e?.name??t.name;this.o.sources({[o]:(i)=>n.apply({...this,context:i},i.args)})})},cr=(e)=>(r,t)=>{t.addInitializer(function(){let n=this[t.name],o=e?.name??t.name;this.o.sections({[o]:(i)=>{return n.call({...this,context:i},i.section)}})})},fr=(e)=>(r,t)=>{t.addInitializer(function(){let n=this[t.name],o=e?.name??t.name;this.o.keys({[o]:(i)=>n.call({...this,context:i},i.value)})})},pr=(e)=>(r,t)=>{t.addInitializer(function(){let n=this[t.name],o=e?.name??t.name;this.o.variables({[o]:n})})},mr=(e)=>(r,t)=>{t.addInitializer(function(){let n=this[t.name],o=e?.name??t.name;this.o.functions({[o]:n})})},gr=(e)=>(r,t)=>{t.addInitializer(function(){let n=this[t.name],o=e?.name??t.name;this.o.encoders({[o]:{fn:n}})})},yr=(e)=>(r,t)=>{t.addInitializer(function(){let n=this[t.name],o=e?.name??t.name;this.o.decoders({[o]:{fn:n}})})};var Mt={};C(Mt,{defaultProcessors:()=>vr});import{createHash as ne}from"crypto";import V from"path";var Qr={};C(Qr,{navigate:()=>Ce,find:()=>hr,NavigateResult:()=>E,NavigateAction:()=>$e});var $e;((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"})($e||={});class E{action;by;skipSiblings;reexplore;constructor(e,r,t,n){this.action=e,this.by=r,this.skipSiblings=t,this.reexplore=n}static _explore=new E(0);static _noExplore=new E(2);static _skipSiblings=new E(1);static _deleteParent=new E(4);static ReplaceParent(e,r){return new E(3,e,void 0,r)}static SkipSiblings(){return E._skipSiblings}static Explore(){return E._explore}static NoExplore(){return E._noExplore}static DeleteParent(){return E._deleteParent}static MergeParent(e){return new E(5,e)}static ReplaceItem(e,r){return new E(6,e,r)}static DeleteItem(e){return new E(7,void 0,e)}}var Ce=async(e,r)=>{let t=new WeakSet,n=[],o=[],i=async(a,c,w)=>{let O=a===null,y=O?E.Explore():await r({key:a,value:c,path:n,parent:w,parents:o});if(c&&typeof c==="object"&&y.action===0){if(t.has(c))return y;if(t.add(c),!O)n.push(a),o.push(w);let u=c;while(await l(u,a,w))u=w[a];if(!O)o.pop(),n.pop()}return y},l=async(a,c,w)=>{let O=Object.keys(a),y=O.length;for(let u=0;u<y;u++){let d=O[u],v=a[d],g=await i(d,v,a),A=g.action;if(A===0||A===2)continue;if(A===6){if(a[d]=g.by,g.skipSiblings)return;continue}if(A===7){if(delete a[d],g.skipSiblings)return;continue}if(A===1)return;if(A===3){if(c===null)throw Error("Cannot replace root object");if(w[c]=g.by,g.reexplore)return!0;return}if(A===4){if(c===null)throw Error("Cannot delete root object");delete w[c];return}if(A===5)delete a[d],Object.assign(a,g.by)}};await i(null,e,null)},hr=async(e,r)=>{let t=[];return await Ce(e,(n)=>{if(r([...n.path,n.key].join("."),n.value))t.push(n.value);return E.Explore()}),t};var Xr=(e)=>({output:(r)=>{delete r.parent[r.key];for(let t of Array.isArray(r.value)?r.value:[r.value])if(typeof t==="string")e.output({name:t,value:r.parent});else e.output({...t,value:t.value??r.parent});return E.SkipSiblings()}});import qo from"path";var Zr=(e)=>({load:async(r)=>{let t=r.options.globalContext;for(let{file:n}of Array.isArray(r.value)?r.value:[r.value]){if(!n)throw Error("File reference required");await e.load(n,t.file&&qo.dirname(t.file))}return E.DeleteItem()}});var Hr={};C(Hr,{mergeAll:()=>z,merge:()=>U});var U=(e,r,t)=>{for(let n of Object.keys(r)){if(e[n]===void 0)continue;let o=r[n],i=e[n];if(typeof i!==typeof o||Array.isArray(i)!==Array.isArray(o)){let a=t?.mismatch?.(n,i,o,e,r);if(a!==void 0){r[n]=a;continue}throw Error(`Type mismatch: ${n}`)}let l=t?.mode?.(n,i,o,e,r)??r[".merge"]??"merge";switch(l){case"source":r[n]=i;continue;case"target":continue;case"skip":delete r[n],delete e[n];continue;case"merge":break;default:throw Error(`Unknown merge mode: ${l}`)}if(typeof i==="object")if(Array.isArray(i))o.push(...i);else{if(t?.navigate?.(n,i,o,e,r)===!1)continue;U(i,o,t)}else{if(i===o)continue;let a=t?.conflict?.(n,i,o,e,r);r[n]=a===void 0?o:a}}for(let n of Object.keys(e))if(r[n]===void 0)r[n]=e[n]},z=(e,r)=>{let t={};for(let n of e.toReversed())U(n,t,r);return t};var qr={};C(qr,{CacheManager:()=>We});class We{cache=new Map;maxSize;constructor(e=100){this.maxSize=e}get(e){return this.cache.get(e)}set(e,r){this.evictIfNeeded(),this.cache.set(e,r)}has(e){return this.cache.has(e)}clear(){this.cache.clear()}setMaxSize(e){this.maxSize=e}size(){return this.cache.size}evictIfNeeded(){if(this.cache.size>=this.maxSize){let e=null,r=1/0;for(let[t,n]of this.cache.entries())if(n.timestamp<r)r=n.timestamp,e=t;if(e)this.cache.delete(e)}}}var Jr={};C(Jr,{select:()=>x});var zo=Object.create,{getPrototypeOf:Jo,defineProperty:zr,getOwnPropertyNames:ei}=Object,ri=Object.prototype.hasOwnProperty,ti=(e,r,t)=>{t=e!=null?zo(Jo(e)):{};let n=r||!e||!e.__esModule?zr(t,"default",{value:e,enumerable:!0}):t;for(let o of ei(e))if(!ri.call(n,o))zr(n,o,{get:()=>e[o],enumerable:!0});return n},ni=(e,r)=>()=>(r||e((r={exports:{}}).exports,r),r.exports),oi=ni((e,r)=>{var{defineProperty:t,getOwnPropertyNames:n,getOwnPropertyDescriptor:o}=Object,i=Object.prototype.hasOwnProperty,l=new WeakMap,a=(u)=>{var d=l.get(u),v;if(d)return d;if(d=t({},"__esModule",{value:!0}),u&&typeof u==="object"||typeof u==="function")n(u).map((g)=>!i.call(d,g)&&t(d,g,{get:()=>u[g],enumerable:!(v=o(u,g))||v.enumerable}));return l.set(u,d),d},c=(u,d)=>{for(var v in d)t(u,v,{get:d[v],enumerable:!0,configurable:!0,set:(g)=>d[v]=()=>g})},w={};c(w,{splitWithQuotes:()=>y,splitNested:()=>O}),r.exports=a(w);var O=(u,d,v="(",g=")")=>{let A=0,f="",S=[];for(let b of u){if(f+=b,b===v)A++;if(b===g)A--;if(A===0&&b===d)S.push(f.slice(0,-1)),f=""}if(f)S.push(f);return S},y=(u,d=",")=>{let v=[],g=u.length,A=d.length,f=0,S=(b)=>{if(b+A>g)return!1;for(let M=0;M<A;M++)if(u[b+M]!==d[M])return!1;return!0};while(f<g){while(f<g&&u[f]===" ")f++;if(f>=g)break;let b="",M=u[f]==='"'||u[f]==="'";if(M){let k=u[f++];while(f<g&&u[f]!==k)b+=u[f++];if(f<g)f++}else{while(f<g&&!S(f)){let k=u[f];if(k==='"'||k==="'"){b+=k,f++;while(f<g&&u[f]!==k)b+=u[f++];if(f<g)b+=u[f++]}else b+=u[f++]}b=b.trim()}if(b)v.push({value:b,quoted:M});if(S(f))f+=A}return v}}),ii=ti(oi(),1),si=/^\[([^=\]]*)([=]*)([^\]]*)\]$/,ai=/^([^[\]]*)\[([^\]]*)]$/,wr=(e,r,t,n)=>{if(e.startsWith("{")&&e.endsWith("}")){let o=e.substring(1,e.length-1);return x(r,o,t)?.toString()}return n?e:void 0},li=(e,r,t,n)=>{let o=wr(r,t,n);if(o)return x(e,o,n);let i=si.exec(r);if(i){let[,a,c,w]=i,O=wr(a.trim(),t,n,!0),y=wr(w.trim(),t,n,!0);if(Array.isArray(e)&&(c==="="||c==="==")&&O)return e.find((u)=>u?.[O]==y)}let l=ai.exec(r);if(l){let[,a,c]=l;return e?.[a]?.[c]}return e?.[r]},x=(e,r,t)=>{let n=void 0,o=void 0,i=r??"",l=(y)=>{if(!y)return[y,!1];return y.endsWith("?")?[y.substring(0,y.length-1),!0]:[y,!1]},a=(y,u)=>{let[d,v]=l(u.pop());if(!d){if(t?.set!==void 0&&o!==void 0&&n!==void 0)n[o]=t.set;return y}let g=li(y,d,e,t);if(g===void 0){if(v||t?.optional||t?.defaultValue!==void 0)return;throw Error(`Unknown path element: "${d}" in "${i}"`)}return n=y,o=d,a(g,u)},c=ii.splitNested(i,t?.separator??".","{","}"),w=void 0;if(c.length>0&&c[c.length-1].startsWith("?="))w=c.pop()?.substring(2);c.reverse();let O=a(e,c);if(O===void 0)return w??t?.defaultValue;return O};var Ne=(e)=>{if(typeof e.value==="string")return e.parent;let r=e.value.model;if(!r)return e.parent;if(typeof r==="string")return x(e.root,r);return r};var Ke=(e)=>{if(typeof e.value==="string")return x(e.root,e.value);if(Array.isArray(e.value))return e.value;let r=e.value;if(typeof r.from==="string")return x(e.root,r.from);return r.from};var Ue=async(e,r)=>{let t=e.value;if(t.selector===void 0)return r;if(typeof t.selector!=="string"){let n=JSON.parse(JSON.stringify(t.selector));return await $(n,{...e.options,root:{...e.root,result:r}}),n}return await x({...e.root,result:r},t.selector)};var et={};C(et,{PathManager:()=>H});import J from"path";class H{constructor(){}static normalize(e){return J.normalize(J.resolve(e))}static resolveInContext(e,r){let t=r??process.cwd(),n=J.isAbsolute(e)?e:J.join(t,e);return this.normalize(n)}static isDirectoryPattern(e){return e.endsWith("/")}static isGlobPattern(e){return e.includes("*")}static toAbsolute(e,r){if(J.isAbsolute(e))return e;return J.join(r??process.cwd(),e)}}var rt={};C(rt,{conditionPredicatesTypes:()=>ye,conditionPredicates:()=>K});var K={and:(...e)=>e.every((r)=>!!r),or:(...e)=>e.some((r)=>!!r),xor:(...e)=>e.filter((r)=>!!r).length===1,true:(...e)=>e.every((r)=>!!r),false:(...e)=>e.every((r)=>!r),eq:(...e)=>e.every((r)=>r===e[0]),ne:(...e)=>e.some((r)=>r!==e[0]),lt:(...e)=>typeof e[0]==="number"&&e.slice(1).every((r)=>typeof r==="number"&&e[0]<r),le:(...e)=>typeof e[0]==="number"&&e.slice(1).every((r)=>typeof r==="number"&&e[0]<=r),gt:(...e)=>typeof e[0]==="number"&&e.slice(1).every((r)=>typeof r==="number"&&e[0]>r),ge:(...e)=>typeof e[0]==="number"&&e.slice(1).every((r)=>typeof r==="number"&&e[0]>=r),in:(e,r)=>{if(Array.isArray(r))return r.includes(e);if(typeof e==="string")return e.includes(r);if(Array.isArray(e))return e.includes(r);return!1},notin:(e,r)=>!K.in(e,r),contains:(e,r)=>e.includes(r),notcontains:(e,r)=>!e.includes(r),containsi:(e,r)=>e.toLowerCase().includes(r.toLowerCase()),notcontainsi:(e,r)=>!e.toLowerCase().includes(r.toLowerCase()),null:(...e)=>e.every((r)=>r===null||r===void 0),notnull:(...e)=>e.every((r)=>r!==null&&r!==void 0),empty:(...e)=>e.every((r)=>r===""),notempty:(...e)=>e.every((r)=>r!==""),nullorempty:(...e)=>e.every((r)=>r===null||r===void 0||r===""),notnullorempty:(...e)=>e.every((r)=>r!==null&&r!==void 0&&r!=="")},ye={and:()=>"boolean",or:()=>"boolean",xor:()=>"boolean",true:()=>"boolean",false:()=>"boolean",lt:()=>"number",le:()=>"number",gt:()=>"number",ge:()=>"number"};var tt=()=>({each:{filters:[/select|model/],fn:async(e)=>{let r=e.value;delete e.parent[e.key];let t=await Ke(e),n=await Ne(e);if(!Array.isArray(t))throw Error('Key "each" requires a source list');if(n===void 0)throw Error('Key "each" must define a model');if(r.extend?.model)n=z([r.model,...Array.isArray(r.extend.model)?r.extend.model:[r.extend.model]]);let o=[];for(let i=0;i<t.length;i++){let l=W(n);if(await $(l,{...e.options,root:{...e.root,index:i,item:t[i],instance:l}}),r.extend?.result){let a=r.extend.result;l=z([l,...Array.isArray(a)?a:[a]])}o.push(await Ue(e,l))}return o}}});var nt=()=>({map:{filters:[/select|model/],fn:async(e)=>{delete e.parent[e.key];let r=await Ke(e),t=await Ne(e);if(!Array.isArray(r))throw Error('Key "map" requires a source list');if(t===void 0)throw Error('Key "map" must define a model');let n=[];for(let o=0;o<r.length;o++){let i=W(t);await $(i,{...e.options,root:{...e.root,index:o,item:r[o],instance:i}}),n.push(await Ue(e,i))}return n}}});var ot=()=>({concat:async(e)=>{let r=[];for(let t of Array.isArray(e.value)?e.value:[e.value])r.push(...await x(e.root,t));return r.filter((t)=>t!==void 0)}});var it=()=>({extends:async(e)=>{let r=async(t,n)=>{for(let o of Array.isArray(n)?n:[n]){let i=await x(e.root,o),l=W(i);if(l[e.key])await r(l,l[e.key]);await $(l,{...e.options}),U(l,t),delete t[e.key]}};return await r(e.parent,e.value),E.Explore()},group:(e)=>{let r=e.root.parent,t=e.value,{items:n,...o}=t;return t.items.forEach((i)=>r.push({...o,...i})),E.DeleteParent()}});var st=(e)=>({skip:{types:{0:"boolean"},fn:(r)=>r.value?E.DeleteParent():E.DeleteItem()},metadata:({path:r,value:t})=>{return e.metadata(r,t),E.DeleteItem()},if:{types:{0:"boolean"},fn:async(r)=>{let t=r.parent[".then"],n=r.parent[".else"];if(t!==void 0)delete r.parent[".then"];if(n!==void 0)delete r.parent[".else"];let o=r.value?t:n;if(o===void 0)return E.DeleteItem();if(typeof o==="string")return(await $({value:o},{...r.options,root:{...r.root}})).value;return E.ReplaceParent(o,!0)}},switch:(r)=>{let t=r.value;if(!t.cases)throw Error("Missing cases for switch");if(t.cases[t.from]!==void 0)return E.ReplaceParent(t.cases[t.from],!0);if(t.default!==void 0)return E.ReplaceParent(t.default,!0);return E.DeleteParent()}});var at=()=>({from:async({root:e,parent:r,value:t})=>{let n=await x(e,t);if(n===null||n===void 0)throw Error(`Unable to resolve reference: ${t}`);if(r.content){if(Array.isArray(r.content)&&Array.isArray(n))return[...n,...r.content];return U(n,r.content),r.content}return n}});import lt from"node:vm";var ut=(e)=>({modules:async(r)=>{for(let[t,n]of Object.entries(r.value)){let o=lt.createContext({console,objector:e,document:r.root}),i=new lt.SourceTextModule(n,{identifier:t,context:o});await i.link((l)=>{throw Error(`Module ${l} is not allowed`)}),await i.evaluate(),e.sources(Object.fromEntries(Object.entries(i.namespace).map(([l,a])=>[`${t}.${l}`,(c)=>a(c,...c.args)])))}return E.DeleteItem()}});var ct=()=>({try:{fn:(e)=>{let r=e.parent[".catch"];if(r!==void 0)delete e.parent[".catch"];try{return e.value}catch(t){if(r!==void 0)return r;return E.DeleteItem()}}}});var ft=()=>({let:{fn:(e)=>{let r=e.value;return Object.assign(e.root,r),E.DeleteItem()}}});var pt=()=>({tap:{fn:(e)=>{return console.log(`[tap] ${e.path}:`,e.value),e.value}}});var ui=(e,r)=>{let t=r.section.config.using,n=e.getFunctions();return t?Object.fromEntries(t.map((o)=>{if(o in n)return[o,n[o]];if(o in r.root)return[o,r.root[o]];throw Error(`Function or variable "${o}" not found for script section`)})):n},br=(e,r,t,n,o=[])=>{let i=ui(e,t),l=["section","context","config","system",...Object.keys(i),...o],a=[r,t.root,t.section.config,e,...Object.values(i)];return[new AsyncFunction(...l,n).bind(t),a]},ci=(e,r)=>{let t={write:(...n)=>{return r.push(...n),t},writeLine:(...n)=>{return r.push(...n.map((o)=>o+`
10
- `)),t},clear:()=>{return r.splice(0,r.length),t},prepend:(...n)=>{return r.unshift(...n),t},prependLine:(...n)=>{return r.unshift(...n.map((o)=>o+`
11
- `)),t},setOptions:(n)=>{return Object.assign(e.section,n),t},use:(n)=>{return n(t),t},getLines:()=>r};return t},fi=async(e,r,t)=>{let n=t.section.config.condition;if(n!==void 0){let[o,i]=br(e,r,t,`return (${n})`);if(!await o(...i))return!1}return!0},mt=(e)=>async(r)=>{let t=[],n=ci(r,t);if(!await fi(e,n,r))return!1;let[o,i]=br(e,n,r,r.section.content,["item"]),l=r.section.config.each;if(l){let[a,c]=br(e,n,r,`return (${l})`),w=Array.isArray(l)?l:await a(...c);if(!Array.isArray(w))throw Error('The "each" property of a script section must return an array');for(let O of w){let y=await o(...i,O);if(typeof y<"u")t.push(y)}}else{let a=await o(...i);if(typeof a<"u")return a}if(t.length===0)return!1;return t.join("")};var gt=(e)=>({script:mt(e)});import yt from"fs/promises";import de from"path";var dt=(e)=>({include:async(r)=>{let{file:t}=r.options.globalContext;return await pe(r.args[0],{cwd:de.dirname(t),filter:(n)=>de.basename(t)!==n,map:async(n)=>e.load(n,de.dirname(t),r.root)})},exists:async({args:[r]})=>await q(r),file:async(r)=>await yt.readFile(await X(r.args[0],e.getIncludeDirectories())).then((t)=>t.toString()),scan:async(r)=>{let t=[],o=(()=>{let a=r.args[2]??["**/node_modules/**"],c=typeof a==="string"?a.split(",").map((w)=>w.trim()):a;if(!Array.isArray(c))throw Error("Scan exclusion must be a list");return c})(),{file:i}=r.options.globalContext,l=r.args[1]?await X(r.args[1],e.getIncludeDirectories()):de.dirname(i);for await(let a of yt.glob(r.args[0],{cwd:l,exclude:(c)=>o.some((w)=>de.matchesGlob(c,w))}))t.push(a);return t}});var ht={};C(ht,{tokenize:()=>Or,stripIndent:()=>Ar,snake:()=>re,pascal:()=>ee,padBlock:()=>_,changeCase:()=>te,capital:()=>he,camel:()=>we});var ee=(e)=>e.replace(/((?:[_ ]+)\w|^\w)/g,(r,t)=>t.toUpperCase()).replace(/[_ ]/g,""),he=(e)=>e.replace(/((?:[ ]+)\w|^\w)/g,(r,t)=>t.toUpperCase()),we=(e)=>{let r=ee(e);return r.charAt(0).toLowerCase()+r.slice(1)},re=(e,r="_")=>e.replace(/([a-z])([A-Z])/g,`$1${r}$2`).replace(/\s+/g,r).toLowerCase(),te=(e,r)=>{switch(r){case"upper":return e.toUpperCase();case"lower":return e.toLowerCase();default:return e}},_=(e,r,t=`
12
- `,n=" ")=>{let o=n.repeat(r);return e.split(t).map((i)=>o+i).join(t)},Or=(e,r,t=/\${([^}]+)}/g)=>{return e.replace(t,(n,o)=>{let i=r[o];if(i===null||i===void 0)return"";if(typeof i==="string")return i;if(typeof i==="number"||typeof i==="boolean")return String(i);return String(i)})},Ar=(e)=>{let r=e.split(/\r?\n/),t=r.filter((o)=>o.trim().length>0).map((o)=>/^[ \t]*/.exec(o)?.[0].length??0),n=t.length>0?Math.min(...t):0;if(n===0)return e;return r.map((o)=>o.slice(n)).join(`
13
- `)};var wt=(e)=>({substring:{types:{0:"ref",1:"number",2:"number"},fn:(r)=>r.args[0].substring(r.args[1],r.args[2])},repeat:{types:{0:"ref",1:"number"},fn:({args:[r,t]})=>r.repeat(t)},pad:{types:{0:"ref",1:"number",2:"string"},fn:({args:[r,t],tags:n})=>{let o=n.join?.[0]??`
14
- `,i=n.padChar?.[0]??" ";return _(r,t??2,o,i)}},formatAs:{fn:({args:[r,t],tags:n})=>{let o=e.getEncoder(t);if(!o)throw Error("Unsupported format: "+String(t));let i=[];if(o.options?.includeTags)i=[n];return o.fn(r,...i)}}});var Ie=(e,r=0,t)=>{let n=" ".repeat(r),o=" ".repeat(r+1);if(e===null||e===void 0)return"null";else if(typeof e==="boolean")return String(e);else if(typeof e==="number")return String(e);else if(typeof e==="string")return`"${e.replace(/\\/g,"\\\\").replace(/"/g,"\\\"").replace(/\n/g,"\\n").replace(/\r/g,"\\r").replace(/\t/g,"\\t")}"`;else if(Array.isArray(e)){if(e.length===0)return"[]";return`[
15
- ${e.map((l)=>`${o}${Ie(l,r+1)},`).join(`
1
+ var Yr=Object.create;var Fe=Object.defineProperty;var Gr=Object.getOwnPropertyDescriptor;var Se=(e,t)=>{return Object.defineProperty(e,"name",{value:t,enumerable:!1,configurable:!0}),e};var De=(e,t)=>(t=Symbol[e])?t:Symbol.for("Symbol."+e),Y=(e)=>{throw TypeError(e)},Tr=(e,t,r)=>(t in e)?Fe(e,t,{enumerable:!0,configurable:!0,writable:!0,value:r}):e[t]=r;var pe=(e,t,r)=>t.has(e)||Y("Cannot "+r),Vr=(e,t)=>Object(t)!==t?Y('Cannot use the "in" operator on this value'):e.has(t),ke=(e,t,r)=>(pe(e,t,"read from private field"),r?r.call(e):t.get(e));var Me=(e,t,r,n)=>(pe(e,t,"write to private field"),n?n.call(e,r):t.set(e,r),r),Xr=(e,t,r)=>(pe(e,t,"access private method"),r),Re=(e)=>[,,,Yr(e?.[De("metadata")]??null)],$e=["class","method","getter","setter","accessor","field","value","get","set"],K=(e)=>e!==void 0&&typeof e!=="function"?Y("Function expected"):e,Hr=(e,t,r,n,o)=>({kind:$e[e],name:t,metadata:n,addInitializer:(s)=>r._?Y("Already initialized"):o.push(K(s||null))}),ge=(e,t)=>Tr(t,De("metadata"),e[3]),Ce=(e,t,r,n)=>{for(var o=0,s=e[t>>1],l=s&&s.length;o<l;o++)t&1?s[o].call(r):n=s[o].call(r,n);return n},c=(e,t,r,n,o,s)=>{var l,a,u,b,w,m=t&7,g=!!(t&8),d=!!(t&16),E=m>3?e.length+1:m?g?1:2:0,y=$e[m+5],j=m>3&&(e[E-1]=[]),h=e[E]||(e[E]=[]),k=m&&(!d&&!g&&(o=o.prototype),m<5&&(m>3||!d)&&Gr(m<4?o:{get[r](){return ke(this,s)},set[r](S){Me(this,s,S)}},r));m?d&&m<4&&Se(s,(m>2?"set ":m>1?"get ":"")+r):Se(o,r);for(var O=n.length-1;O>=0;O--){if(b=Hr(m,r,u={},e[3],h),m){if(b.static=g,b.private=d,w=b.access={has:d?(S)=>Vr(o,S):(S)=>(r in S)},m^3)w.get=d?(S)=>(m^1?ke:Xr)(S,o,m^4?s:k.get):(S)=>S[r];if(m>2)w.set=d?(S,M)=>Me(S,o,M,m^4?s:k.set):(S,M)=>S[r]=M}if(a=(0,n[O])(m?m<4?d?s:k[y]:m>4?void 0:{get:k.get,set:k.set}:o,b),u._=1,m^4||a===void 0)K(a)&&(m>4?j.unshift(a):m?d?s=a:k[y]=a:o=a);else if(typeof a!=="object"||a===null)Y("Object expected");else K(l=a.get)&&(k.get=l),K(l=a.set)&&(k.set=l),K(l=a.init)&&j.unshift(l)}return m||ge(e,o),k&&Fe(o,r,k),d?m^4?s:k:o};var Qr=Object.create,{getPrototypeOf:zr,defineProperty:xe,getOwnPropertyNames:Zr}=Object,Pr=Object.prototype.hasOwnProperty,Jr=(e,t,r)=>{r=e!=null?Qr(zr(e)):{};let n=t||!e||!e.__esModule?xe(r,"default",{value:e,enumerable:!0}):r;for(let o of Zr(e))if(!Pr.call(n,o))xe(n,o,{get:()=>e[o],enumerable:!0});return n},en=(e,t)=>()=>(t||e((t={exports:{}}).exports,t),t.exports),tn=en((e,t)=>{var{defineProperty:r,getOwnPropertyNames:n,getOwnPropertyDescriptor:o}=Object,s=Object.prototype.hasOwnProperty,l=new WeakMap,a=(g)=>{var d=l.get(g),E;if(d)return d;if(d=r({},"__esModule",{value:!0}),g&&typeof g==="object"||typeof g==="function")n(g).map((y)=>!s.call(d,y)&&r(d,y,{get:()=>g[y],enumerable:!(E=o(g,y))||E.enumerable}));return l.set(g,d),d},u=(g,d)=>{for(var E in d)r(g,E,{get:d[E],enumerable:!0,configurable:!0,set:(y)=>d[E]=()=>y})},b={};u(b,{splitWithQuotes:()=>m,splitNested:()=>w}),t.exports=a(b);var w=(g,d,E="(",y=")")=>{let j=0,h="",k=[];for(let O of g){if(h+=O,O===E)j++;if(O===y)j--;if(j===0&&O===d)k.push(h.slice(0,-1)),h=""}if(h)k.push(h);return k},m=(g,d=",")=>{let E=[],y=g.length,j=d.length,h=0,k=(O)=>{if(O+j>y)return!1;for(let S=0;S<j;S++)if(g[O+S]!==d[S])return!1;return!0};while(h<y){while(h<y&&g[h]===" ")h++;if(h>=y)break;let O="",S=g[h]==='"'||g[h]==="'";if(S){let M=g[h++];while(h<y&&g[h]!==M)O+=g[h++];if(h<y)h++}else{while(h<y&&!k(h)){let M=g[h];if(M==='"'||M==="'"){O+=M,h++;while(h<y&&g[h]!==M)O+=g[h++];if(h<y)O+=g[h++]}else O+=g[h++]}O=O.trim()}if(O)E.push({value:O,quoted:S});if(k(h))h+=j}return E}}),rn=Jr(tn(),1),I;((e)=>{e[e.Explore=0]="Explore",e[e.SkipSiblings=1]="SkipSiblings",e[e.NoExplore=2]="NoExplore",e[e.ReplaceParent=3]="ReplaceParent",e[e.DeleteParent=4]="DeleteParent",e[e.MergeParent=5]="MergeParent",e[e.ReplaceItem=6]="ReplaceItem",e[e.DeleteItem=7]="DeleteItem"})(I||={});class F{action;by;skipSiblings;reexplore;constructor(e,t,r,n){this.action=e,this.by=t,this.skipSiblings=r,this.reexplore=n}static _explore=new F(0);static _noExplore=new F(2);static _skipSiblings=new F(1);static _deleteParent=new F(4);static ReplaceParent(e,t){return new F(3,e,void 0,t)}static SkipSiblings(){return F._skipSiblings}static Explore(){return F._explore}static NoExplore(){return F._noExplore}static DeleteParent(){return F._deleteParent}static MergeParent(e){return new F(5,e)}static ReplaceItem(e,t){return new F(6,e,t)}static DeleteItem(e){return new F(7,void 0,e)}}var nn=async(e,t)=>{let r=new WeakSet,n=[],o=[],s=async(a,u,b)=>{let w=a===null,m=w?F.Explore():await t({key:a,value:u,path:n,parent:b,parents:o});if(u&&typeof u==="object"&&m.action===0){if(r.has(u))return m;if(r.add(u),!w)n.push(a),o.push(b);let g=u;while(await l(g,a,b))g=b[a];if(!w)o.pop(),n.pop()}return m},l=async(a,u,b)=>{let w=Object.keys(a),m=w.length;for(let g=0;g<m;g++){let d=w[g],E=a[d],y=await s(d,E,a),j=y.action;if(j===0||j===2)continue;if(j===6){if(a[d]=y.by,y.skipSiblings)return;continue}if(j===7){if(delete a[d],y.skipSiblings)return;continue}if(j===1)return;if(j===3){if(u===null)throw Error("Cannot replace root object");if(b[u]=y.by,y.reexplore)return!0;return}if(j===4){if(u===null)throw Error("Cannot delete root object");delete b[u];return}if(j===5)delete a[d],Object.assign(a,y.by)}};await s(null,e,null)},on=Object.create,{getPrototypeOf:sn,defineProperty:Ne,getOwnPropertyNames:an}=Object,ln=Object.prototype.hasOwnProperty,un=(e,t,r)=>{r=e!=null?on(sn(e)):{};let n=t||!e||!e.__esModule?Ne(r,"default",{value:e,enumerable:!0}):r;for(let o of an(e))if(!ln.call(n,o))Ne(n,o,{get:()=>e[o],enumerable:!0});return n},cn=(e,t)=>()=>(t||e((t={exports:{}}).exports,t),t.exports),fn=cn((e,t)=>{var{defineProperty:r,getOwnPropertyNames:n,getOwnPropertyDescriptor:o}=Object,s=Object.prototype.hasOwnProperty,l=new WeakMap,a=(g)=>{var d=l.get(g),E;if(d)return d;if(d=r({},"__esModule",{value:!0}),g&&typeof g==="object"||typeof g==="function")n(g).map((y)=>!s.call(d,y)&&r(d,y,{get:()=>g[y],enumerable:!(E=o(g,y))||E.enumerable}));return l.set(g,d),d},u=(g,d)=>{for(var E in d)r(g,E,{get:d[E],enumerable:!0,configurable:!0,set:(y)=>d[E]=()=>y})},b={};u(b,{splitWithQuotes:()=>m,splitNested:()=>w}),t.exports=a(b);var w=(g,d,E="(",y=")")=>{let j=0,h="",k=[];for(let O of g){if(h+=O,O===E)j++;if(O===y)j--;if(j===0&&O===d)k.push(h.slice(0,-1)),h=""}if(h)k.push(h);return k},m=(g,d=",")=>{let E=[],y=g.length,j=d.length,h=0,k=(O)=>{if(O+j>y)return!1;for(let S=0;S<j;S++)if(g[O+S]!==d[S])return!1;return!0};while(h<y){while(h<y&&g[h]===" ")h++;if(h>=y)break;let O="",S=g[h]==='"'||g[h]==="'";if(S){let M=g[h++];while(h<y&&g[h]!==M)O+=g[h++];if(h<y)h++}else{while(h<y&&!k(h)){let M=g[h];if(M==='"'||M==="'"){O+=M,h++;while(h<y&&g[h]!==M)O+=g[h++];if(h<y)O+=g[h++]}else O+=g[h++]}O=O.trim()}if(O)E.push({value:O,quoted:S});if(k(h))h+=j}return E}}),pn=un(fn(),1),gn=/^\[([^=\]]*)([=]*)([^\]]*)\]$/,mn=/^([^[\]]*)\[([^\]]*)]$/,me=(e,t,r,n)=>{if(e.startsWith("{")&&e.endsWith("}")){let o=e.substring(1,e.length-1);return G(t,o,r)?.toString()}return n?e:void 0},yn=(e,t,r,n)=>{let o=me(t,r,n);if(o)return G(e,o,n);let s=gn.exec(t);if(s){let[,a,u,b]=s,w=me(a.trim(),r,n,!0),m=me(b.trim(),r,n,!0);if(Array.isArray(e)&&(u==="="||u==="==")&&w)return e.find((g)=>g?.[w]==m)}let l=mn.exec(t);if(l){let[,a,u]=l;return e?.[a]?.[u]}return e?.[t]},G=(e,t,r)=>{let n=void 0,o=void 0,s=t??"",l=(m)=>{if(!m)return[m,!1];return m.endsWith("?")?[m.substring(0,m.length-1),!0]:[m,!1]},a=(m,g)=>{let[d,E]=l(g.pop());if(!d){if(r?.set!==void 0&&o!==void 0&&n!==void 0)n[o]=r.set;return m}let y=yn(m,d,e,r);if(y===void 0){if(E||r?.optional||r?.defaultValue!==void 0)return;throw Error(`Unknown path element: "${d}" in "${s}"`)}return n=m,o=d,a(y,g)},u=pn.splitNested(s,r?.separator??".","{","}"),b=void 0;if(u.length>0&&u[u.length-1].startsWith("?="))b=u.pop()?.substring(2);u.reverse();let w=a(e,u);if(w===void 0)return b??r?.defaultValue;return w},We=(e,t)=>{if(typeof e.value==="string"){if(e.quoted)return e.value;if(e.value.startsWith("[")&&e.value.endsWith("]")){let r=e.value.slice(1,-1);if(r.trim()==="")return[];return r.split(";").map((n)=>{let o=n.trim();if(!isNaN(+o))return+o;return o})}if(e.value.startsWith("{")&&e.value.endsWith("}")){if(e.value.slice(1,-1).trim()==="")return{}}if(e.value==="null")return null;if(e.value==="undefined")return;if(e.value.startsWith("@"))return e.value.slice(1);if(!isNaN(+e.value))return+e.value}return t(e.value)},ne=(e,t,r,n,o,s)=>{let l=n?.(e)??e,a=o(l);if(a[0])return a[1];if(!t){let u=G(r,e),b=o(u);if(b[0])return b[1]}throw Error(s)},Le=(e,t,r,n,o)=>{let s=typeof e.types==="function"?e.types(n,t.value,o):e.types?.[n];if(!s||s==="ref")return We(t,(a)=>G(r,a));let l=We(t,()=>t.value);if(Array.isArray(s)){if(!s.includes(l))throw Error(`Argument ${n.toString()} must be one of [${s.join(", ")}]: ${l}`);return l}if(typeof s==="string"){if(s.endsWith("?")){let a=s.slice(0,-1);if(t.value==="null")return F.ReplaceItem(null);if(t.value==="undefined")return F.ReplaceItem(void 0);if(t.value==="")return"";s=a}switch(s){case"any":return l;case"array":return ne(l,t.quoted,r,null,(a)=>[Array.isArray(a),a],`Argument ${n.toString()} must be an array: ${l}`);case"object":return ne(l,t.quoted,r,null,(a)=>[typeof a==="object"&&a!==null,a],`Argument ${n.toString()} must be an object: ${l}`);case"number":return ne(l,t.quoted,r,(a)=>Number(a),(a)=>[!isNaN(a),a],`Argument ${n.toString()} must be a number: ${l}`);case"boolean":return ne(l,t.quoted,r,null,(a)=>{if([!0,"true","1",1,"yes","on"].includes(a))return[!0,!0];if([!1,"false","0",0,"no","off"].includes(a))return[!0,!1];if([null,"null","undefined",void 0,""].includes(a))return[!0,!1];if(Array.isArray(a))return[!0,a.length>0];return[!1,!1]},`Argument ${n.toString()} must be a boolean: ${l}`);case"string":return l.toString();default:throw Error(`Unknown type for argument ${n.toString()}: ${s}`)}}return s(l,r,n,t.quoted)},_e=(e,t)=>{let r=e?.[t];if(r===void 0)throw Error(`Unhandled field processor type: ${t}`);return typeof r==="function"?{options:{},fn:r}:{options:r,fn:r.fn}},Ue=(e)=>!e.quoted&&e.value.startsWith("."),dn=(e)=>{let t={};for(let r of e){if(!Ue(r))continue;let n=r.value.indexOf("="),o=n>-1?r.value.slice(1,n):r.value.slice(1),s=n>-1?r.value.slice(n+1):"";if(s.length>=2){let l=s[0],a=s[s.length-1];if(l==='"'&&a==='"'||l==="'"&&a==="'")s=s.slice(1,-1)}if(!t[o])t[o]=[];t[o].push(s)}return t},hn=(e,t,r)=>{let n=rn.splitWithQuotes(e??""),o=dn(n),s=n.filter((a)=>!Ue(a)),l=t.options.processArgs===!1?[]:s.map((a,u)=>Le(t.options,a,r,u,s));return{rawArgs:s,parsedArgs:l,tags:o}},bn=(e)=>{return e!==null&&typeof e==="object"&&"action"in e},wn=(e,t)=>t.keys!==void 0&&e.key.startsWith(".")&&t.keys[e.key.substring(1)]!==void 0,On=async(e,t,r,n)=>{let{key:o,parent:s}=e,l=_e(n.keys,o.substring(1));if(l.options.processArgs!==!1&&(typeof l.options.types==="function"||l.options.types?.[0]!==void 0))e.value=Le(l.options,{value:e.value,quoted:!1},r,0,[]);if(typeof e.value!=="string")await R(e.value,{...n,root:{...r,parent:e.parent,parents:e.parents},filters:[...n.filters??[],...l.options.filters??[]]});let a=await l.fn({path:t,root:r,parent:s,key:o,options:n,value:e.value,args:[],rawArgs:[],tags:{}});return bn(a)?a:F.ReplaceParent(a)},Ie=(e)=>{let t=e.split(/\r?\n/),r=t.filter((o)=>o.trim().length>0).map((o)=>/^[ \t]*/.exec(o)?.[0].length??0),n=r.length>0?Math.min(...r):0;if(n===0)return e;return t.map((o)=>o.slice(n)).join(`
2
+ `)},An=async(e,t,r,n)=>{if(!t?.onSection&&!t?.onSectionConfig&&!t?.sections)return[e,!1];let o=/<@\s*section(?:\s*:\s*([\w-]+))?\s*@>([\s\S]*?)<@\s*\/\s*section\s*@>/g,s,l=e,a=0,u=!1,b={content:l,root:n,path:r,options:t,section:{}};while((s=o.exec(e))!==null){u=!0;let[w,m,g]=s,d=s.index,E=d+w.length,y=e[E]===`
3
+ `;if(y)E++;let j=d+a,h=E+a,k={},O=g,S=/(^|\r?\n)[ \t]*---[ \t]*(\r?\n|$)/m.exec(g);if(S){let B=g.slice(0,S.index),ce=S.index+S[0].length;O=g.slice(ce);let te=Ie(B).trim();if(te.length>0)try{k=t?.configParser?.(te)??{}}catch(fe){throw Error(`Failed to parse YAML config for section: ${fe.message}`)}}else if(/^\r?\n/.test(O))O=O.replace(/^\r?\n/,"");O=Ie(O),O=O.replace(/(?:\r?\n[ \t]*)+$/,""),O=O.replace(/[ \t]+$/,"");let M={config:m?{...k,type:m}:k,content:O};if(b.content=l,b.section=M,Object.keys(M.config).length>0){if(await t.onSectionConfig?.(b)!==!1)await R(M.config,{...t,root:n})}let Z=b.section.config.type?t.sections?.[b.section.config.type]:void 0,W;if(Z)W=await Z(b);else if(t.onSection)W=await t.onSection(b);if(M.trim)M.content=M.content.trim();if(M.indent)M.content=M.content.split(`
4
+ `).map((B)=>" ".repeat(M.indent)+B).join(`
5
+ `);let C="";if(W===!0||M.show)C=M.content;else if(typeof W==="string")C=W;if(y&&C!==""&&!C.endsWith(`
6
+ `))C+=`
7
+ `;let P=l.lastIndexOf(`
8
+ `,j-1),J=P===-1?0:P+1,ee=l.slice(J,j).trim().length===0?J:j;l=l.slice(0,ee)+C+l.slice(h),a+=C.length-(h-ee),b.content=l}return[l,u]},Be=(e)=>{let t=[],r=0;while(r<e.length)if(e[r]==="$"&&e[r+1]==="("&&(r===0||e[r-1]!=="\\")){let n=r;r+=2;let o=1;for(;r<e.length;r++)if(e[r]==="(")o++;else if(e[r]===")"){if(o--,o===0){t.push([n,r]);break}}if(o!==0)throw Error(`Unmatched opening $( at position ${n.toString()}`);r++}else r++;return t},ye=Symbol.for("@homedev/fields:OverrideResult"),jn=(e)=>({[ye]:!0,value:e}),vn=(e)=>{return e!==null&&typeof e==="object"&&ye in e&&e[ye]===!0},qe=async(e,t,r)=>{for(let n=t.length-1;n>=0;n--){let[o,s]=t[n],l=e.slice(o+2,s),a=await qe(l,Be(l),r);if(typeof a==="object")return a;let u=await r(a,e);if(vn(u))return u.value;e=e.slice(0,o)+u+e.slice(s+1)}return e},En=async(e,t)=>qe(e,Be(e),t),Sn=(e)=>{return e!==null&&typeof e==="object"&&"action"in e},kn=/([\w\d.-_/]+):(.+)/,Mn=async(e,t,r,n)=>{let o=await(async()=>{let s=kn.exec(e);if(!s)return await G(t,e);let[l,a,u]=s,b=_e(n.sources,a),w=hn(u,b,t);return await b.fn({args:w.parsedArgs,rawArgs:w.rawArgs,tags:w.tags,key:a,options:n,root:t,path:r,value:null})})();if(o===null||o===void 0)return"";if(typeof o==="object")return jn(o);return o},Ke=async(e,t,r,n)=>{let o=await En(t,(s)=>Mn(s,r,e,n));if(Sn(o))return o;if(o===t)return F.Explore();if(typeof o==="string"){let s=await Ke(e,o,r,n);if(s.action!==I.Explore)return s;return F.ReplaceItem(o)}return F.ReplaceItem(o)},R=async(e,t)=>{return t??={},await nn(e,async(r)=>{let n=[...r.path,r.key].join(".");if(t?.filters?.length&&t.filters.some((a)=>a.test(n)))return F.NoExplore();let o=r.path.length===0,s=r.parents.length>0?r.parents.toReversed():[];if(o){if(s.length>0)throw Error("Root object should not have a parent");s=t?.root?.parents?[t.root.parent,...t.root.parents.toReversed()]:[]}let l={...e,...t.root,this:r.parent,parent:s.length>0?s[0]:null,parents:s};try{if(r.key.startsWith("$"))return F.NoExplore();let a=F.Explore();if(typeof r.value==="string"){let u=r.value,b=!1;while(!0){let[w,m]=await An(u,t,n,l);if(b=b||m,a=await Ke(n,w,l,t),a.action===I.ReplaceItem&&typeof a.by==="string"){u=a.by;continue}if(a.action===I.Explore&&m&&w!==u)a=F.ReplaceItem(w);break}if(a.action===I.Explore&&u!==r.value)a=F.ReplaceItem(u);switch(a.action){case I.Explore:break;case I.ReplaceItem:r.value=a.by;break;default:return a}}if(wn(r,t))a=await On(r,n,l,t);return a}catch(a){throw Error(`${a.message}
9
+ (${n})`)}}),e},Ye=(e,t)=>t?{fn:(r)=>e(...r.args),types:t}:(r)=>e(...r.args),Hn=(e,t)=>Object.fromEntries(e.map((r)=>[r.name,Ye(r,t?.types?.[r.name])])),T=(e,t)=>Object.fromEntries((t?.keys??Object.keys(e)).map((r)=>[r,Ye(e[r],t?.types?.[r])]));import Ge from"fs/promises";import de from"path";import Fn from"fs/promises";import Dn from"path";import Rn from"fs/promises";import Cn from"fs/promises";import Qe from"fs/promises";import Te from"path";import Nn from"fs/promises";import he from"path";import Ve from"path";var we=async(e)=>{try{return await Ge.access(e,Ge.constants.R_OK),!0}catch{return!1}},oe=async(e,t)=>{let r=!de.isAbsolute(e)&&t?["",...t]:[""];for(let n of r){let o=de.join(n,e);if(await we(o))return de.resolve(o)}throw Error(`File not found: "${e}"`)},Xe=async(e,t)=>{let r=await oe(e,t?.dirs),n=await Fn.readFile(r,"utf-8"),o=Dn.dirname(r),s={text:{fn:(a)=>a,matching:["\\.txt$","\\.text$"]},json:{fn:JSON.parse,matching:["\\.json$"]},...t?.parsers},l=t?.format?s[t.format]:Object.values(s).find((a)=>a.matching?.some((u)=>new RegExp(u).test(e)));if(!l)throw Error(`Unsupported format for file "${e}" and no matching parser found`);return{content:await l.fn(n),fullPath:r,folderPath:o}},$n=async(e,t,r)=>{let n={text:{fn:(s)=>s,matching:["\\.txt$","\\.text$"]},json:{fn:JSON.stringify,matching:["\\.json$"]},...r?.encoders},o=r?.format?n[r.format]:Object.values(n).find((s)=>s.matching?.some((l)=>new RegExp(l).test(e)));if(!o)throw Error(`Unsupported format for file "${e}" and no matching encoder found`);await Rn.writeFile(e,await o.fn(t))},He=async(e,t)=>{if(typeof e==="string"&&!e.includes("*"))return await t.map(e,0,[]);let r=await Array.fromAsync(Cn.glob(e,{cwd:t.cwd})),n=t.filter?r.filter(t.filter):r;return await Promise.all(n.map(t.map))},ze=async(e,t)=>{if(t?.targetDirectory&&t?.removeFirst)try{await Qe.rm(t?.targetDirectory,{recursive:!0,force:!0})}catch(r){throw Error(`Failed to clean the output directory: ${r.message}`)}for(let r of e)await xn(r,t)},xn=async(e,t)=>{let r=Te.join(t?.targetDirectory??".",e.name),n=Te.dirname(r);if(t?.classes){if(e.class!==void 0&&!t.classes.includes(e.class))return;if(t.classRequired&&e.class===void 0)throw Error(`Output "${e.name}" is missing class field`)}if(t?.writing?.(e)===!1)return;try{await Qe.mkdir(n,{recursive:!0})}catch(o){throw Error(`Failed to create target directory "${n}" for output "${r}": ${o.message}`)}try{await $n(r,e.value,{format:e.type??"text"})}catch(o){throw Error(`Failed to write output "${r}": ${o.message}`)}},be=(e)=>e?Ve.isAbsolute(e)?e:Ve.join(process.cwd(),e):process.cwd(),Wn=async(e,t)=>{let r=[];for(let n of e)try{let o=!he.isAbsolute(n)?he.join(be(t?.cwd),n):n;if(t?.filter?.(o)===!1)continue;let s=await import(o);if(t?.resolveDefault==="only"&&!s.default)throw Error(`Module ${n} does not have a default export`);let l=t?.resolveDefault?s.default??s:s,a=t?.map?await t.map(l,n):l;if(a!==void 0)r.push(a)}catch(o){if(t?.fail?.(n,o)===!1)continue;throw Error(`Failed to import module ${n}: ${o.message??o}`)}return r},ao=async(e,t)=>{let r=[];for(let n of e){let o=(await Array.fromAsync(Nn.glob(n,{cwd:be(t?.cwd)}))).map((s)=>he.join(be(t?.cwd),s));r.push(...await Wn(o,t))}return r};class V{o;context;constructor(e){this.o=e}}var f=(e)=>(t,r)=>{r.addInitializer(function(){let n=this[r.name],o=e?.name??r.name;this.o.sources({[o]:(s)=>n.apply({...this,context:s},s.args)})})},uo=(e)=>(t,r)=>{r.addInitializer(function(){let n=this[r.name],o=e?.name??r.name;this.o.sections({[o]:(s)=>{return n.call({...this,context:s},s.section)}})})},co=(e)=>(t,r)=>{r.addInitializer(function(){let n=this[r.name],o=e?.name??r.name;this.o.keys({[o]:(s)=>n.call({...this,context:s},s.value)})})},fo=(e)=>(t,r)=>{r.addInitializer(function(){let n=this[r.name],o=e?.name??r.name;this.o.variables({[o]:n})})},po=(e)=>(t,r)=>{r.addInitializer(function(){let n=this[r.name],o=e?.name??r.name;this.o.functions({[o]:n})})},go=(e)=>(t,r)=>{r.addInitializer(function(){let n=this[r.name],o=e?.name??r.name;this.o.encoders({[o]:{fn:n}})})},mo=(e)=>(t,r)=>{r.addInitializer(function(){let n=this[r.name],o=e?.name??r.name;this.o.decoders({[o]:{fn:n}})})};import{createHash as U}from"crypto";import N from"path";var Ze=(e)=>({output:(t)=>{delete t.parent[t.key];for(let r of Array.isArray(t.value)?t.value:[t.value])if(typeof r==="string")e.output({name:r,value:t.parent});else e.output({...r,value:r.value??t.parent});return v.SkipSiblings()}});import In from"path";var Pe=(e)=>({load:async(t)=>{let r=t.options.globalContext;for(let{file:n}of Array.isArray(t.value)?t.value:[t.value]){if(!n)throw Error("File reference required");await e.load(n,r.file&&In.dirname(r.file))}return v.DeleteItem()}});class Oe{cache=new Map;maxSize;constructor(e=100){this.maxSize=e}get(e){return this.cache.get(e)}set(e,t){this.evictIfNeeded(),this.cache.set(e,t)}has(e){return this.cache.has(e)}clear(){this.cache.clear()}setMaxSize(e){this.maxSize=e}size(){return this.cache.size}evictIfNeeded(){if(this.cache.size>=this.maxSize){let e=null,t=1/0;for(let[r,n]of this.cache.entries())if(n.timestamp<t)t=n.timestamp,e=r;if(e)this.cache.delete(e)}}}var ie=(e)=>{if(typeof e.value==="string")return e.parent;let t=e.value.model;if(!t)return e.parent;if(typeof t==="string")return Object.select(e.root,t);return t};var se=(e)=>{if(typeof e.value==="string")return Object.select(e.root,e.value);if(Array.isArray(e.value))return e.value;let t=e.value;if(typeof t.from==="string")return Object.select(e.root,t.from);return t.from};var ae=async(e,t)=>{let r=e.value;if(r.selector===void 0)return t;if(typeof r.selector!=="string"){let n=JSON.parse(JSON.stringify(r.selector));return await R(n,{...e.options,root:{...e.root,result:t}}),n}return await Object.select({...e.root,result:t},r.selector)};import L from"path";class _{constructor(){}static normalize(e){return L.normalize(L.resolve(e))}static resolveInContext(e,t){let r=t??process.cwd(),n=L.isAbsolute(e)?e:L.join(r,e);return this.normalize(n)}static isDirectoryPattern(e){return e.endsWith("/")}static isGlobPattern(e){return e.includes("*")}static toAbsolute(e,t){if(L.isAbsolute(e))return e;return L.join(t??process.cwd(),e)}}var x={and:(...e)=>e.every((t)=>!!t),or:(...e)=>e.some((t)=>!!t),xor:(...e)=>e.filter((t)=>!!t).length===1,true:(...e)=>e.every((t)=>!!t),false:(...e)=>e.every((t)=>!t),eq:(...e)=>e.every((t)=>t===e[0]),ne:(...e)=>e.some((t)=>t!==e[0]),lt:(...e)=>typeof e[0]==="number"&&e.slice(1).every((t)=>typeof t==="number"&&e[0]<t),le:(...e)=>typeof e[0]==="number"&&e.slice(1).every((t)=>typeof t==="number"&&e[0]<=t),gt:(...e)=>typeof e[0]==="number"&&e.slice(1).every((t)=>typeof t==="number"&&e[0]>t),ge:(...e)=>typeof e[0]==="number"&&e.slice(1).every((t)=>typeof t==="number"&&e[0]>=t),in:(e,t)=>{if(Array.isArray(t))return t.includes(e);if(typeof e==="string")return e.includes(t);if(Array.isArray(e))return e.includes(t);return!1},notin:(e,t)=>!x.in(e,t),contains:(e,t)=>e.includes(t),notcontains:(e,t)=>!e.includes(t),containsi:(e,t)=>e.toLowerCase().includes(t.toLowerCase()),notcontainsi:(e,t)=>!e.toLowerCase().includes(t.toLowerCase()),null:(...e)=>e.every((t)=>t===null||t===void 0),notnull:(...e)=>e.every((t)=>t!==null&&t!==void 0),empty:(...e)=>e.every((t)=>t===""),notempty:(...e)=>e.every((t)=>t!==""),nullorempty:(...e)=>e.every((t)=>t===null||t===void 0||t===""),notnullorempty:(...e)=>e.every((t)=>t!==null&&t!==void 0&&t!=="")},le={and:()=>"boolean",or:()=>"boolean",xor:()=>"boolean",true:()=>"boolean",false:()=>"boolean",lt:()=>"number",le:()=>"number",gt:()=>"number",ge:()=>"number"};var Je=()=>({each:{filters:[/select|model/],fn:async(e)=>{let t=e.value;delete e.parent[e.key];let r=await se(e),n=await ie(e);if(!Array.isArray(r))throw Error('Key "each" requires a source list');if(n===void 0)throw Error('Key "each" must define a model');if(t.extend?.model)n=[t.model,...Array.isArray(t.extend.model)?t.extend.model:[t.extend.model]].mergeAll();let o=[];for(let s=0;s<r.length;s++){let l=Object.deepClone(n);if(await R(l,{...e.options,root:{...e.root,index:s,item:r[s],instance:l}}),t.extend?.result){let a=t.extend.result;l=[l,...Array.isArray(a)?a:[a]].mergeAll()}o.push(await ae(e,l))}return o}}});var et=()=>({map:{filters:[/select|model/],fn:async(e)=>{delete e.parent[e.key];let t=await se(e),r=await ie(e);if(!Array.isArray(t))throw Error('Key "map" requires a source list');if(r===void 0)throw Error('Key "map" must define a model');let n=[];for(let o=0;o<t.length;o++){let s=Object.deepClone(r);await R(s,{...e.options,root:{...e.root,index:o,item:t[o],instance:s}}),n.push(await ae(e,s))}return n}}});var tt=()=>({concat:async(e)=>{let t=[];for(let r of Array.isArray(e.value)?e.value:[e.value])t.push(...await Object.select(e.root,r));return t.filter((r)=>r!==void 0)}});Array.prototype.findOrFail=function(e,t,r){let n=this.find(e,r);if(n===void 0)throw Error(t??"Element not found");return n};Array.flat=function(e){if(Array.isArray(e))return e.flat(2);else return[e]};Array.prototype.forEachAsync=async function(e){for(let t=0;t<this.length;t++)await e(this[t],t,this)};Array.prototype.groupBy=function(e){return this.reduce((t,r)=>{let n=e(r);if(!t[n])t[n]=[];return t[n].push(r),t},{})};Array.prototype.createInstances=function(e,...t){return this.map((r,n)=>new e(...t,r,n))};Array.prototype.mapAsync=async function(e){return Promise.all(this.map(e))};Array.prototype.nonNullMap=function(e){let t=[];for(let r=0;r<this.length;r++){let n=e(this[r],r,this);if(n!=null)t.push(n)}return t};Array.prototype.nonNullMapAsync=async function(e){let t=[];for(let r=0;r<this.length;r++){let n=await e(this[r],r,this);if(n!=null)t.push(n)}return t};Array.prototype.mergeAll=function(e){let t={};for(let r of this.toReversed())Object.merge(r,t,e);return t};Array.prototype.toObject=function(e,t){return Object.fromEntries(this.map((r)=>{let n=e(r),o=t?t(r):r;return[n,o]}))};Array.prototype.toObjectWithKey=function(e){return Object.fromEntries(this.map((t)=>[String(t[e]),t]))};Array.prototype.selectFor=function(e,t,r,n){let o=this.find(e,n);if(o===void 0)throw Error(r??"Element not found");return t(o)};Array.prototype.sortBy=function(e,t=!0){return this.slice().sort((r,n)=>{let o=e(r),s=e(n);if(o<s)return t?-1:1;if(o>s)return t?1:-1;return 0})};Array.prototype.unique=function(){return Array.from(new Set(this))};Array.prototype.uniqueBy=function(e){let t=new Set;return this.filter((r)=>{let n=e(r);if(t.has(n))return!1;else return t.add(n),!0})};var Ln;((e)=>{e[e.Explore=0]="Explore",e[e.SkipSiblings=1]="SkipSiblings",e[e.NoExplore=2]="NoExplore",e[e.ReplaceParent=3]="ReplaceParent",e[e.DeleteParent=4]="DeleteParent",e[e.MergeParent=5]="MergeParent",e[e.ReplaceItem=6]="ReplaceItem",e[e.DeleteItem=7]="DeleteItem"})(Ln||={});class v{action;by;skipSiblings;reexplore;constructor(e,t,r,n){this.action=e,this.by=t,this.skipSiblings=r,this.reexplore=n}static _explore=new v(0);static _noExplore=new v(2);static _skipSiblings=new v(1);static _deleteParent=new v(4);static ReplaceParent(e,t){return new v(3,e,void 0,t)}static SkipSiblings(){return v._skipSiblings}static Explore(){return v._explore}static NoExplore(){return v._noExplore}static DeleteParent(){return v._deleteParent}static MergeParent(e){return new v(5,e)}static ReplaceItem(e,t){return new v(6,e,t)}static DeleteItem(e){return new v(7,void 0,e)}}Object.navigate=async(e,t)=>{let r=new WeakSet,n=[],o=[],s=async(a,u,b)=>{let w=a===null,m=w?v.Explore():await t({key:a,value:u,path:n,parent:b,parents:o});if(u&&typeof u==="object"&&m.action===0){if(r.has(u))return m;if(r.add(u),!w)n.push(a),o.push(b);let g=u;while(await l(g,a,b))g=b[a];if(!w)o.pop(),n.pop()}return m},l=async(a,u,b)=>{let w=Object.keys(a),m=w.length;for(let g=0;g<m;g++){let d=w[g],E=a[d],y=await s(d,E,a),j=y.action;if(j===0||j===2)continue;if(j===6){if(a[d]=y.by,y.skipSiblings)return;continue}if(j===7){if(delete a[d],y.skipSiblings)return;continue}if(j===1)return;if(j===3){if(u===null)throw Error("Cannot replace root object");if(b[u]=y.by,y.reexplore)return!0;return}if(j===4){if(u===null)throw Error("Cannot delete root object");delete b[u];return}if(j===5)delete a[d],Object.assign(a,y.by)}};await s(null,e,null)};Object.find=async function(e,t){let r=[];return await Object.navigate(e,(n)=>{if(t([...n.path,n.key].join("."),n.value))r.push(n.value);return v.Explore()}),r};Object.merge=(e,t,r)=>{for(let n of Object.keys(t)){if(e[n]===void 0)continue;let o=t[n],s=e[n];if(typeof s!==typeof o||Array.isArray(s)!==Array.isArray(o)){let a=r?.mismatch?.(n,s,o,e,t);if(a!==void 0){t[n]=a;continue}throw Error(`Type mismatch: ${n}`)}let l=r?.mode?.(n,s,o,e,t)??t[".merge"]??"merge";switch(l){case"source":t[n]=s;continue;case"target":continue;case"skip":delete t[n],delete e[n];continue;case"merge":break;default:throw Error(`Unknown merge mode: ${l}`)}if(typeof s==="object")if(Array.isArray(s))o.push(...s);else{if(r?.navigate?.(n,s,o,e,t)===!1)continue;Object.merge(s,o,r)}else{if(s===o)continue;let a=r?.conflict?.(n,s,o,e,t);t[n]=a===void 0?o:a}}for(let n of Object.keys(e))if(t[n]===void 0)t[n]=e[n]};var _n=/^\[([^=\]]*)([=]*)([^\]]*)\]$/,Un=/^([^[\]]*)\[([^\]]*)]$/,Ae=(e,t,r,n)=>{if(e.startsWith("{")&&e.endsWith("}")){let o=e.substring(1,e.length-1);return Object.select(t,o,r)?.toString()}return n?e:void 0},Bn=(e,t,r,n)=>{let o=Ae(t,r,n);if(o)return Object.select(e,o,n);let s=_n.exec(t);if(s){let[,a,u,b]=s,w=Ae(a.trim(),r,n,!0),m=Ae(b.trim(),r,n,!0);if(Array.isArray(e)&&(u==="="||u==="==")&&w)return e.find((g)=>g?.[w]==m)}let l=Un.exec(t);if(l){let[,a,u]=l;return e?.[a]?.[u]}return e?.[t]};Object.select=(e,t,r)=>{let n=void 0,o=void 0,s=t??"",l=(m)=>{if(!m)return[m,!1];return m.endsWith("?")?[m.substring(0,m.length-1),!0]:[m,!1]},a=(m,g)=>{let[d,E]=l(g.pop());if(!d){if(r?.set!==void 0&&o!==void 0&&n!==void 0)n[o]=r.set;return m}let y=Bn(m,d,e,r);if(y===void 0){if(E||r?.optional||r?.defaultValue!==void 0)return;throw Error(`Unknown path element: "${d}" in "${s}"`)}return n=m,o=d,a(y,g)},u=s.splitNested(r?.separator??".","{","}"),b=void 0;if(u.length>0&&u[u.length-1].startsWith("?="))b=u.pop()?.substring(2);u.reverse();let w=a(e,u);if(w===void 0)return b??r?.defaultValue;return w};Object.deepClone=function(e){if(typeof structuredClone<"u")try{return structuredClone(e)}catch{}return JSON.parse(JSON.stringify(e))};Object.toList=function(e,t){return Object.entries(e).map(([r,n])=>({[t]:r,...n}))};Object.mapEntries=function(e,t){let r=Object.entries(e).map(([n,o])=>t(n,o));return Object.fromEntries(r)};global.AsyncFunction=Object.getPrototypeOf(async function(){}).constructor;global.defined=(e,t="Value is undefined")=>{if(e===void 0||e===null)throw Error(t);return e};String.prototype.tokenize=function(e,t=/\${([^}]+)}/g){return this.replace(t,(r,n)=>{let o=e[n];if(o===null||o===void 0)return"";if(typeof o==="string")return o;if(typeof o==="number"||typeof o==="boolean")return String(o);return String(o)})};String.prototype.toPascal=function(){return this.replace(/((?:[_ ]+)\w|^\w)/g,(e,t)=>t.toUpperCase()).replace(/[_ ]/g,"")};String.prototype.capitalize=function(){return this.replace(/((?:[ ]+)\w|^\w)/g,(e,t)=>t.toUpperCase())};String.prototype.toCamel=function(){return this.toPascal().replace(/((?:[ ]+\w)|^\w)/g,(e,t)=>t.toLowerCase())};String.prototype.toSnake=function(){return this.replace(/([a-z])([A-Z])/g,"$1_$2").replace(/\s+/g,"_")};String.prototype.toKebab=function(){return this.replace(/([a-z])([A-Z])/g,"$1-$2").replace(/\s+/g,"-")};String.prototype.changeCase=function(e){switch(e){case"upper":return this.toUpperCase();case"lower":return this.toLowerCase();case"pascal":return this.toPascal();case"camel":return this.toCamel();case"snake":return this.toSnake();case"kebab":return this.toKebab();default:throw Error(`Unsupported case type: ${e}`)}};String.prototype.splitWithQuotes=function(e=","){let t=[],r=this.length,n=e.length,o=0,s=(l)=>{if(l+n>r)return!1;for(let a=0;a<n;a++)if(this[l+a]!==e[a])return!1;return!0};while(o<r){while(o<r&&this[o]===" ")o++;if(o>=r)break;let l="",a=this[o]==='"'||this[o]==="'";if(a){let u=this[o++];while(o<r&&this[o]!==u)l+=this[o++];if(o<r)o++}else{while(o<r&&!s(o)){let u=this[o];if(u==='"'||u==="'"){l+=u,o++;while(o<r&&this[o]!==u)l+=this[o++];if(o<r)l+=this[o++]}else l+=this[o++]}l=l.trim()}if(l)t.push({value:l,quoted:a});if(s(o))o+=n}return t};String.prototype.splitNested=function(e,t,r){let n=0,o="",s=[];for(let l of this){if(o+=l,l===t)n++;if(l===r)n--;if(n===0&&l===e)s.push(o.slice(0,-1)),o=""}if(o)s.push(o);return s};String.prototype.padBlock=function(e,t=`
10
+ `,r=" "){let n=r.repeat(e);return this.split(t).map((o)=>n+o).join(t)};String.prototype.stripIndent=function(){let e=this.split(/\r?\n/),t=e.filter((n)=>n.trim().length>0).map((n)=>/^[ \t]*/.exec(n)?.[0].length??0),r=t.length>0?Math.min(...t):0;if(r===0)return this;return e.map((n)=>n.slice(r)).join(`
11
+ `)};function Qo(e,t="Value is undefined"){if(e===void 0||e===null)throw Error(t);return e}class qn{options;constructor(e){this.options={level:"INFO",showClass:!1,levels:["DEBUG","VERBOSE","INFO","WARN","ERROR"],timeStamp:!1,timeOptions:{second:"2-digit",minute:"2-digit",hour:"2-digit",day:"2-digit",month:"2-digit",year:"2-digit"},logFunction:(t,...r)=>{switch(t){case"ERROR":console.error(...r);break;case"WARN":console.warn(...r);break;case"DEBUG":console.debug(...r);break;case"VERBOSE":console.log(...r);break;default:console.log(...r)}},...e}}write(e,...t){if(this.options.level){let o=this.options.levels.indexOf(this.options.level)??-1,s=this.options.levels.indexOf(e);if(s===-1)throw Error(`Unknown log level: ${e}`);if(s<o)return}let r=[],n=[];if(this.options.timeStamp)n.push(new Date().toLocaleString(this.options.timeLocale,this.options.timeOptions));if(this.options.showClass)n.push(e);if(n.length>0)r.push(`[${n.join(" ")}]`);r.push(...t),this.options.logFunction(e,...r)}info(...e){this.write("INFO",...e)}error(...e){this.write("ERROR",...e)}warn(...e){this.write("WARN",...e)}debug(...e){this.write("DEBUG",...e)}verbose(...e){this.write("VERBOSE",...e)}}var rt=()=>({extends:async(e)=>{let t=async(r,n)=>{for(let o of Array.isArray(n)?n:[n]){let s=await Object.select(e.root,o),l=Object.deepClone(s);if(l[e.key])await t(l,l[e.key]);await R(l,{...e.options}),Object.merge(l,r),delete r[e.key]}};return await t(e.parent,e.value),v.Explore()},group:(e)=>{let t=e.root.parent,r=e.value,{items:n,...o}=r;return r.items.forEach((s)=>t.push({...o,...s})),v.DeleteParent()}});var nt=(e)=>({skip:{types:{0:"boolean"},fn:(t)=>t.value?v.DeleteParent():v.DeleteItem()},metadata:({path:t,value:r})=>{return e.metadata(t,r),v.DeleteItem()},if:{types:{0:"boolean"},fn:async(t)=>{let r=t.parent[".then"],n=t.parent[".else"];if(r!==void 0)delete t.parent[".then"];if(n!==void 0)delete t.parent[".else"];let o=t.value?r:n;if(o===void 0)return v.DeleteItem();if(typeof o==="string")return(await R({value:o},{...t.options,root:{...t.root}})).value;return v.ReplaceParent(o,!0)}},switch:(t)=>{let r=t.value;if(!r.cases)throw Error("Missing cases for switch");if(r.cases[r.from]!==void 0)return v.ReplaceParent(r.cases[r.from],!0);if(r.default!==void 0)return v.ReplaceParent(r.default,!0);return v.DeleteParent()}});var ot=()=>({from:async({root:e,parent:t,value:r})=>{let n=await Object.select(e,r);if(n===null||n===void 0)throw Error(`Unable to resolve reference: ${r}`);if(t.content){if(Array.isArray(t.content)&&Array.isArray(n))return[...n,...t.content];return Object.merge(n,t.content),t.content}return n}});import it from"node:vm";var st=(e)=>({modules:async(t)=>{for(let[r,n]of Object.entries(t.value)){let o=it.createContext({console,objector:e,document:t.root}),s=new it.SourceTextModule(n,{identifier:r,context:o});await s.link((l)=>{throw Error(`Module ${l} is not allowed`)}),await s.evaluate(),e.sources(Object.fromEntries(Object.entries(s.namespace).map(([l,a])=>[`${r}.${l}`,(u)=>a(u,...u.args)])))}return v.DeleteItem()}});var at=()=>({try:{fn:(e)=>{let t=e.parent[".catch"];if(t!==void 0)delete e.parent[".catch"];try{return e.value}catch(r){if(t!==void 0)return t;return v.DeleteItem()}}}});var lt=()=>({let:{fn:(e)=>{let t=e.value;return Object.assign(e.root,t),v.DeleteItem()}}});var ut=()=>({tap:{fn:(e)=>{return console.log(`[tap] ${e.path}:`,e.value),e.value}}});var Kn=(e,t)=>{let r=t.section.config.using,n=e.getFunctions();return r?Object.fromEntries(r.map((o)=>{if(o in n)return[o,n[o]];if(o in t.root)return[o,t.root[o]];throw Error(`Function or variable "${o}" not found for script section`)})):n},je=(e,t,r,n,o=[])=>{let s=Kn(e,r),l=["section","context","config","system",...Object.keys(s),...o],a=[t,r.root,r.section.config,e,...Object.values(s)];return[new AsyncFunction(...l,n).bind(r),a]},Yn=(e,t)=>{let r={write:(...n)=>{return t.push(...n),r},writeLine:(...n)=>{return t.push(...n.map((o)=>o+`
12
+ `)),r},clear:()=>{return t.splice(0,t.length),r},prepend:(...n)=>{return t.unshift(...n),r},prependLine:(...n)=>{return t.unshift(...n.map((o)=>o+`
13
+ `)),r},setOptions:(n)=>{return Object.assign(e.section,n),r},use:(n)=>{return n(r),r},getLines:()=>t};return r},Gn=async(e,t,r)=>{let n=r.section.config.condition;if(n!==void 0){let[o,s]=je(e,t,r,`return (${n})`);if(!await o(...s))return!1}return!0},ct=(e)=>async(t)=>{let r=[],n=Yn(t,r);if(!await Gn(e,n,t))return!1;let[o,s]=je(e,n,t,t.section.content,["item"]),l=t.section.config.each;if(l){let[a,u]=je(e,n,t,`return (${l})`),b=Array.isArray(l)?l:await a(...u);if(!Array.isArray(b))throw Error('The "each" property of a script section must return an array');for(let w of b){let m=await o(...s,w);if(typeof m<"u")r.push(m)}}else{let a=await o(...s);if(typeof a<"u")return a}if(r.length===0)return!1;return r.join("")};var ft=(e)=>({script:ct(e)});import pt from"fs/promises";import X from"path";var gt=(e)=>({include:async(t)=>{let{file:r}=t.options.globalContext;return await He(t.args[0],{cwd:X.dirname(r),filter:(n)=>X.basename(r)!==n,map:async(n)=>e.load(n,X.dirname(r),t.root)})},exists:async({args:[t]})=>await we(t),file:async(t)=>await pt.readFile(await oe(t.args[0],e.getIncludeDirectories())).then((r)=>r.toString()),scan:async(t)=>{let r=[],o=(()=>{let a=t.args[2]??["**/node_modules/**"],u=typeof a==="string"?a.split(",").map((b)=>b.trim()):a;if(!Array.isArray(u))throw Error("Scan exclusion must be a list");return u})(),{file:s}=t.options.globalContext,l=t.args[1]?await oe(t.args[1],e.getIncludeDirectories()):X.dirname(s);for await(let a of pt.glob(t.args[0],{cwd:l,exclude:(u)=>o.some((b)=>X.matchesGlob(u,b))}))r.push(a);return r}});var mt=(e)=>({substring:{types:{0:"ref",1:"number",2:"number"},fn:(t)=>t.args[0].substring(t.args[1],t.args[2])},repeat:{types:{0:"ref",1:"number"},fn:({args:[t,r]})=>t.repeat(r)},pad:{types:{0:"ref",1:"number",2:"string"},fn:({args:[t,r],tags:n})=>{let o=n.join?.[0]??`
14
+ `,s=n.padChar?.[0]??" ";return t.padBlock(r??2,o,s)}},formatAs:{fn:({args:[t,r],tags:n})=>{let o=e.getEncoder(r);if(!o)throw Error("Unsupported format: "+String(r));let s=[];if(o.options?.includeTags)s=[n];return o.fn(t,...s)}}});var ue=(e,t=0,r)=>{let n=" ".repeat(t),o=" ".repeat(t+1);if(e===null||e===void 0)return"null";else if(typeof e==="boolean")return String(e);else if(typeof e==="number")return String(e);else if(typeof e==="string")return`"${e.replace(/\\/g,"\\\\").replace(/"/g,"\\\"").replace(/\n/g,"\\n").replace(/\r/g,"\\r").replace(/\t/g,"\\t")}"`;else if(Array.isArray(e)){if(e.length===0)return"[]";return`[
15
+ ${e.map((l)=>`${o}${ue(l,t+1)},`).join(`
16
16
  `)}
17
- ${n}]`}else if(typeof e==="object"){let i=Object.entries(e).sort((a,c)=>t?.sortKeys?a[0].localeCompare(c[0]):0);if(i.length===0)return"{}";return`{
18
- ${i.map(([a,c])=>`${o}${a} = ${Ie(c,r+1,t)}`).join(`
17
+ ${n}]`}else if(typeof e==="object"){let s=Object.entries(e).sort((a,u)=>r?.sortKeys?a[0].localeCompare(u[0]):0);if(s.length===0)return"{}";return`{
18
+ ${s.map(([a,u])=>`${o}${a} = ${ue(u,t+1,r)}`).join(`
19
19
  `)}
20
- ${n}}`}else return String(e)},be=(e)=>{if(!e)return e;return e.replaceAll("\\n",`
21
- `).replaceAll("\\$","$").replaceAll("\\t","\t")};var bt=()=>({...B({merge:(...e)=>e.flatMap((r)=>r)}),join:({args:[e],root:r,tags:t})=>{let n=t.key?.[0],o=t.separator?.[0]??t.sep?.[0],i=t.finalize?.length>0,l=be(o);if(typeof e==="string"){if(i&&e.length&&l)return e+l;return e}if(!Array.isArray(e))throw Error("Object is not a list");let a=((n?.length)?e.map((y)=>x({...r,...y},n)):e).join(l),c=t.pad?.[0]??"0",w=t.padChar?.[0]??" ",O=i&&a.length&&l?a+l:a;return c?_(O,parseInt(c),`
22
- `,w):O},range:({args:[e,r,t]})=>{let n=parseInt(e),o=parseInt(r),i=parseInt(t)||1;if(isNaN(n))throw Error("Invalid range: start value '"+String(e)+"' is not a number");if(isNaN(o))throw Error("Invalid range: end value '"+String(r)+"' is not a number");if(i===0)throw Error("Invalid range: step cannot be zero");if((o-n)/i<0)throw Error("Invalid range: step "+String(i)+" has wrong direction for range "+String(n)+" to "+String(o));return Array.from({length:Math.floor((o-n)/i)+1},(l,a)=>n+a*i)},filter:{types:(e,r,t)=>{switch(e){case 0:return"array";case 1:return Object.keys(K)}return ye[t[1].value]?.(e-2,r,t.slice(2))},fn:({args:[e,r,t],root:n,tags:o})=>{if(e===null||e===void 0)throw Error("Filter source cannot be null or undefined");if(!Array.isArray(e))throw Error("Filter source must be an array");let i=o.key?.[0],l=K[r];if(i){let c=Array(e.length);for(let O=0;O<e.length;O++)try{c[O]=x({...n,...e[O]},i)}catch{c[O]=Symbol("invalid")}let w=[];for(let O=0;O<e.length;O++){let y=c[O];if(typeof y!=="symbol"&&t===void 0?l(y):l(y,t))w.push(e[O])}return w}let a=[];for(let c of e)if(t===void 0?l(c):l(c,t))a.push(c);return a}}});var Ot=()=>({each:{processArgs:!1,fn:async({rawArgs:[e,r,...t],root:n,options:o,tags:i})=>{let l=async(g)=>g.quoted?be(g.value):await x(n,g.value),a=await x(n,e.value),c=await l(r),w=i.key?.[0],O=Array.isArray(a)?a:Z(a),y=[],u=await Promise.all(t.map(async(g)=>await l(g))),d={...n,item:void 0,index:0,params:u,instance:void 0,parent:n.this,tags:i},v={...o,root:d};for(let g=0;g<O.length;g++){let A=W(c),f={instance:A},S=typeof c==="string"?f:A;if(d.item=O[g],d.index=g,d.instance=A,i?.root?.[0])Object.assign(d,await x(d,i.root[0]));if(await $(S,v),w!==void 0)y.push(await x(f.instance,w));else y.push(f.instance)}if(i.join?.length){if(y.length===0)return"";let g=be(i.join[0]),A=i.pad?.[0]??"0",f=i.padChar?.[0]??" ",S=i.finalize?.length&&g?g:"",b=`${y.join(g)}${S}`;return A?_(b,parseInt(A),`
23
- `,f):b}return y}}});var Oe=async(e,r,t)=>e.rawArgs[r].quoted?e.rawArgs[r].value:await x(e.root,e.rawArgs[r].value,{defaultValue:t}),At=()=>({switch:{processArgs:!1,fn:async(e)=>{let r=await Oe(e,0,!1),t=await Oe(e,1);if(t[r]===void 0){if(e.rawArgs.length>2)return Oe(e,2);throw Error(`Unhandled switch case: ${r}`)}return t[r]}}});var vt=()=>({if:{types:{0:"boolean"},fn:(e)=>e.args[0]?e.args[1]:e.args[2]},check:{types:{0:Object.keys(K)},fn:(e)=>K[e.args[0]](...e.args.slice(1))},...B(K,{types:ye})});var Tt=(e)=>({default:{processArgs:!1,fn:async(r)=>{for(let t=0;t<r.rawArgs.length;t++)if(r.rawArgs[t]?.value!==void 0){let o=await Oe(r,t,null);if(o!==null)return o}if(r.tags.nullable?.length)return E.DeleteItem();if(r.tags.fail?.length)throw Error(`No valid value found for default (${r.rawArgs.map((t)=>t.value).join(", ")})`);return""}},section:{types:["string","boolean"],fn:(r)=>{let t=r.args[0];if(!(r.args[1]??!0))return null;let o=e.getSection(t);if(!o)throw Error(`Section not found: ${t}`);return o.content}}});var Et=()=>({convert:({args:[e,r,t]})=>{switch(r){case"string":return String(e);case"number":{let n=Number(e);if(!isNaN(n))return E.ReplaceItem(n);break}case"boolean":if(e==="true"||e===!0||e===1||e==="1"||e==="yes"||e==="on")return E.ReplaceItem(!0);else if(e==="false"||e===!1||e===0||e==="0"||e==="no"||e==="off")return E.ReplaceItem(!1);break;default:throw Error(`Unsupported type for convert: ${r}`)}if(t!==void 0)return E.ReplaceItem(t);throw Error(`Failed to convert value to ${r}`)},isType:({args:[e,r]})=>{let n=(()=>{switch(r){case"string":return typeof e==="string";case"number":return typeof e==="number";case"boolean":return typeof e==="boolean";case"object":return e!==null&&typeof e==="object"&&!Array.isArray(e);case"array":return Array.isArray(e);case"null":return e===null;case"undefined":return e===void 0;case"function":return typeof e==="function";default:throw Error(`Unknown type for isType: ${r}`)}})();return E.ReplaceItem(n)},typeOf:({args:[e]})=>{if(e===null)return"null";else if(Array.isArray(e))return"array";else return typeof e}});var vr=(e)=>{var r,t,n,o,i,l,a,c,w,O,y,u,d,v,g,A,f,S,b,M,k,ve,Y,L,Te,Ee,Me,oe,Pe,Se,Ve,Ct,Wt,Nt,Kt,Ut,It,Lt,_t,Bt,Pt,Vt,Yt,Gt,Qt,Xt,Zt,Ht,qt,zt,Jt,en,rn,tn,nn,on,sn,an,ln,un,cn,fn,pn,mn,gn,yn,dn,hn,wn,bn,On,An,vn,Tn,En,Mn,Sn,kn,xn,Fn,Dn,jn,Rn,$n,Cn,Wn,Nn,Kn,Un,In,Ln,_n,Bn,Pn,Vn,Yn,Gn,Qn,Xn,Zn,Hn,qn,zn,Jn,o,i,l,a,c,w,O,y,u,d,v,g,A,f,S,b,M,k,ve,Y,L,Te,Ee,Me,oe,Pe,Se,Ve,Ct,Wt,Nt,Kt,Ut,It,Lt,_t,Bt,Pt,Vt,Yt,Gt,Qt,Xt,Zt,Ht,qt,zt,Jt,en,rn,tn,nn,on,sn,an,ln,un,cn,fn,pn,mn,gn,yn,dn,hn,wn,bn,On,An,vn,Tn,En,Mn,Sn,kn,xn,Fn,Dn,jn,Rn,$n,Cn,Wn,Nn,Kn,Un,In,Ln,_n,Bn,Pn,Vn,Yn,Gn,Qn,Xn,Zn,Hn,qn,zn,Jn;return e.use((n=P,o=[p()],i=[p()],l=[p()],a=[p()],c=[p()],w=[p()],O=[p()],y=[p()],u=[p()],d=[p()],v=[p()],g=[p()],A=[p()],f=[p()],S=[p()],b=[p()],M=[p()],k=[p()],ve=[p()],Y=[p()],L=[p()],Te=[p()],Ee=[p()],Me=[p()],oe=[p()],Pe=[p()],Se=[p()],Ve=[p()],Ct=[p()],Wt=[p()],Nt=[p()],Kt=[p()],Ut=[p()],It=[p()],Lt=[p()],_t=[p()],Bt=[p()],Pt=[p()],Vt=[p()],Yt=[p()],Gt=[p()],Qt=[p()],Xt=[p()],Zt=[p()],Ht=[p()],qt=[p()],zt=[p()],Jt=[p()],en=[p()],rn=[p()],tn=[p()],nn=[p()],on=[p()],sn=[p()],an=[p()],ln=[p()],un=[p()],cn=[p()],fn=[p()],pn=[p()],mn=[p()],gn=[p()],yn=[p()],dn=[p()],hn=[p()],wn=[p()],bn=[p()],On=[p()],An=[p()],vn=[p()],Tn=[p()],En=[p()],Mn=[p()],Sn=[p()],kn=[p()],xn=[p()],Fn=[p()],Dn=[p()],jn=[p()],Rn=[p()],$n=[p()],Cn=[p()],Wn=[p()],Nn=[p()],Kn=[p()],Un=[p()],In=[p()],Ln=[p()],_n=[p()],Bn=[p()],Pn=[p()],Vn=[p()],Yn=[p()],Gn=[p()],Qn=[p()],Xn=[p()],Zn=[p()],Hn=[p()],qn=[p()],zn=[p()],Jn=[p()],t=jr(n),r=class extends n{constructor(){super(...arguments);$r(t,5,this)}env(s){return process.env[s]}uuid(){return crypto.randomUUID()}pascal(s){return ee(s)}camel(s){return we(s)}capital(s){return he(s)}snake(s,h){return te(re(s,"_"),h)}kebab(s,h){return te(re(s,"-"),h)}len(s){return s.length}reverse(s){return s.split("").reverse().join("")}concat(...s){return s.join("")}trim(s){return s.trim()}ltrim(s){return s.trimStart()}rtrim(s){return s.trimEnd()}lower(s){return s.toLowerCase()}upper(s){return s.toUpperCase()}encode(s,h){return Buffer.from(s).toString(h??"base64")}decode(s,h){return Buffer.from(s,h??"base64").toString()}list(s,h){return Z(s,h)}object(s,h){return ge(s,h)}pathJoin(...s){return V.join(...s)}resolve(...s){return V.resolve(...s)}dirname(s){return V.dirname(s)}basename(s,h){return V.basename(s,h)}normalize(s){return V.normalize(s)}extname(s){return V.extname(s)}relative(s,h){return V.relative(s,h)}isAbsolute(s){return V.isAbsolute(s)}segments(s){return s.split("/").filter(Boolean)}log(...s){console.log(...s)}md5(s){return ne("md5").update(s).digest("hex")}sha1(s){return ne("sha1").update(s).digest("hex")}sha256(s){return ne("sha256").update(s).digest("hex")}sha512(s){return ne("sha512").update(s).digest("hex")}hash(s,h="sha256"){return ne(h).update(s).digest("hex")}hmac(s,h,T="sha256"){return ne(T).update(s).digest("hex")}base64Encode(s){return Buffer.from(s).toString("base64")}base64Decode(s){return Buffer.from(s,"base64").toString("utf-8")}hexEncode(s){return Buffer.from(s).toString("hex")}hexDecode(s){return Buffer.from(s,"hex").toString("utf-8")}add(...s){return s.reduce((h,T)=>h+T,0)}subtract(s,h){return s-h}multiply(...s){return s.reduce((h,T)=>h*T,1)}divide(s,h){if(h===0)throw Error("Division by zero");return s/h}modulo(s,h){return s%h}power(s,h){return Math.pow(s,h)}sqrt(s){return Math.sqrt(s)}abs(s){return Math.abs(s)}floor(s){return Math.floor(s)}ceil(s){return Math.ceil(s)}round(s,h){let T=Math.pow(10,h??0);return Math.round(s*T)/T}min(...s){return Math.min(...s)}max(...s){return Math.max(...s)}clamp(s,h,T){return Math.max(h,Math.min(T,s))}random(s,h){let T=s??0,R=h??1;return Math.random()*(R-T)+T}timestamp(s){return new Date(s).getTime()}iso(s){return new Date(s).toISOString()}utc(s){return new Date(s).toUTCString()}formatDate(s,h){let T=new Date(s),R=T.getFullYear(),I=String(T.getMonth()+1).padStart(2,"0"),ke=String(T.getDate()).padStart(2,"0"),ie=String(T.getHours()).padStart(2,"0"),eo=String(T.getMinutes()).padStart(2,"0"),ro=String(T.getSeconds()).padStart(2,"0");return h.replace("YYYY",String(R)).replace("MM",I).replace("DD",ke).replace("HH",ie).replace("mm",eo).replace("ss",ro)}parseDate(s){return new Date(s).getTime()}year(s){return new Date(s).getFullYear()}month(s){return new Date(s).getMonth()+1}day(s){return new Date(s).getDate()}dayOfWeek(s){return new Date(s).getDay()}hours(s){return new Date(s).getHours()}minutes(s){return new Date(s).getMinutes()}seconds(s){return new Date(s).getSeconds()}regexTest(s,h,T){return new RegExp(s,T).test(h)}regexMatch(s,h,T){return new RegExp(s,T).exec(h)}regexMatchAll(s,h,T){return Array.from(h.matchAll(new RegExp(s,T)))}regexReplace(s,h,T,R){return T.replace(new RegExp(s,R),h)}regexReplaceAll(s,h,T,R){return T.replace(new RegExp(s,R??"g"),h)}regexSplit(s,h,T){return h.split(new RegExp(s,T))}regexExec(s,h,T){return new RegExp(s,T).exec(h)}regexSearch(s,h,T){return h.search(new RegExp(s,T))}unique(s,h){if(!Array.isArray(s))return s;let T=new Set;return s.filter((R)=>{let I=h?R[h]:R;if(T.has(I))return!1;return T.add(I),!0})}groupBy(s,h){if(!Array.isArray(s))return s;let T={};return s.forEach((R)=>{let I=String(R[h]);if(!T[I])T[I]=[];T[I].push(R)}),T}chunk(s,h=1){if(!Array.isArray(s))return[];let T=[];for(let R=0;R<s.length;R+=h)T.push(s.slice(R,R+h));return T}flatten(s,h=1){if(!Array.isArray(s))return[s];let T=[],R=(I,ke)=>{for(let ie of I)if(Array.isArray(ie)&&ke>0)R(ie,ke-1);else T.push(ie)};return R(s,h),T}compact(s){if(!Array.isArray(s))return s;return s.filter((h)=>h!==null&&h!==void 0)}head(s,h){if(!Array.isArray(s))return s;return h?s.slice(0,h):s[0]}tail(s,h){if(!Array.isArray(s))return s;return h?s.slice(-h):s[s.length-1]}isEmail(s){return/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(s)}isUrl(s){try{return new URL(s),!0}catch{return!1}}isJson(s){try{return JSON.parse(s),!0}catch{return!1}}isUuid(s){return/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i.test(s)}minLength(s,h){return s?.length>=h}maxLength(s,h){return s?.length<=h}lengthEquals(s,h){return s?.length===h}isNumber(s){return typeof s==="number"&&!isNaN(s)}isString(s){return typeof s==="string"}isBoolean(s){return typeof s==="boolean"}isArray(s){return Array.isArray(s)}isObject(s){return s!==null&&typeof s==="object"&&!Array.isArray(s)}isEmpty(s){if(s===null||s===void 0)return!0;if(typeof s==="string"||Array.isArray(s))return s.length===0;if(typeof s==="object")return Object.keys(s).length===0;return!1}isTruthy(s){return!!s}isFalsy(s){return!s}inRange(s,h,T){return s>=h&&s<=T}matchesPattern(s,h){return new RegExp(h).test(s)}includes(s,h){if(typeof s==="string")return s.includes(String(h));return Array.isArray(s)&&s.includes(h)}startsWith(s,h){return s.startsWith(h)}endsWith(s,h){return s.endsWith(h)}},m(t,1,"env",o,r),m(t,1,"uuid",i,r),m(t,1,"pascal",l,r),m(t,1,"camel",a,r),m(t,1,"capital",c,r),m(t,1,"snake",w,r),m(t,1,"kebab",O,r),m(t,1,"len",y,r),m(t,1,"reverse",u,r),m(t,1,"concat",d,r),m(t,1,"trim",v,r),m(t,1,"ltrim",g,r),m(t,1,"rtrim",A,r),m(t,1,"lower",f,r),m(t,1,"upper",S,r),m(t,1,"encode",b,r),m(t,1,"decode",M,r),m(t,1,"list",k,r),m(t,1,"object",ve,r),m(t,1,"pathJoin",Y,r),m(t,1,"resolve",L,r),m(t,1,"dirname",Te,r),m(t,1,"basename",Ee,r),m(t,1,"normalize",Me,r),m(t,1,"extname",oe,r),m(t,1,"relative",Pe,r),m(t,1,"isAbsolute",Se,r),m(t,1,"segments",Ve,r),m(t,1,"log",Ct,r),m(t,1,"md5",Wt,r),m(t,1,"sha1",Nt,r),m(t,1,"sha256",Kt,r),m(t,1,"sha512",Ut,r),m(t,1,"hash",It,r),m(t,1,"hmac",Lt,r),m(t,1,"base64Encode",_t,r),m(t,1,"base64Decode",Bt,r),m(t,1,"hexEncode",Pt,r),m(t,1,"hexDecode",Vt,r),m(t,1,"add",Yt,r),m(t,1,"subtract",Gt,r),m(t,1,"multiply",Qt,r),m(t,1,"divide",Xt,r),m(t,1,"modulo",Zt,r),m(t,1,"power",Ht,r),m(t,1,"sqrt",qt,r),m(t,1,"abs",zt,r),m(t,1,"floor",Jt,r),m(t,1,"ceil",en,r),m(t,1,"round",rn,r),m(t,1,"min",tn,r),m(t,1,"max",nn,r),m(t,1,"clamp",on,r),m(t,1,"random",sn,r),m(t,1,"timestamp",an,r),m(t,1,"iso",ln,r),m(t,1,"utc",un,r),m(t,1,"formatDate",cn,r),m(t,1,"parseDate",fn,r),m(t,1,"year",pn,r),m(t,1,"month",mn,r),m(t,1,"day",gn,r),m(t,1,"dayOfWeek",yn,r),m(t,1,"hours",dn,r),m(t,1,"minutes",hn,r),m(t,1,"seconds",wn,r),m(t,1,"regexTest",bn,r),m(t,1,"regexMatch",On,r),m(t,1,"regexMatchAll",An,r),m(t,1,"regexReplace",vn,r),m(t,1,"regexReplaceAll",Tn,r),m(t,1,"regexSplit",En,r),m(t,1,"regexExec",Mn,r),m(t,1,"regexSearch",Sn,r),m(t,1,"unique",kn,r),m(t,1,"groupBy",xn,r),m(t,1,"chunk",Fn,r),m(t,1,"flatten",Dn,r),m(t,1,"compact",jn,r),m(t,1,"head",Rn,r),m(t,1,"tail",$n,r),m(t,1,"isEmail",Cn,r),m(t,1,"isUrl",Wn,r),m(t,1,"isJson",Nn,r),m(t,1,"isUuid",Kn,r),m(t,1,"minLength",Un,r),m(t,1,"maxLength",In,r),m(t,1,"lengthEquals",Ln,r),m(t,1,"isNumber",_n,r),m(t,1,"isString",Bn,r),m(t,1,"isBoolean",Pn,r),m(t,1,"isArray",Vn,r),m(t,1,"isObject",Yn,r),m(t,1,"isEmpty",Gn,r),m(t,1,"isTruthy",Qn,r),m(t,1,"isFalsy",Xn,r),m(t,1,"inRange",Zn,r),m(t,1,"matchesPattern",Hn,r),m(t,1,"includes",qn,r),m(t,1,"startsWith",zn,r),m(t,1,"endsWith",Jn,r),Xe(t,r),r)).keys({...Xr(e),...Zr(e),...tt(),...nt(),...at(),...ot(),...it(),...st(e),...ut(e),...ct(),...ft(),...pt()}).sources({...dt(e),...wt(e),...Et(),...bt(),...Ot(),...At(),...vt(),...Tt(e)}).sections(gt(e)).fieldOptions({configParser:Bun.YAML.parse,onSection:(s)=>{if(s.section.config.name)e.section(s.section)}}).decoders({yaml:{matching:["\\.yml$","\\.yaml$"],fn:Bun.YAML.parse}}).encoders({json:{fn:(s)=>JSON.stringify(s,null,2)},yaml:{fn:(s)=>Bun.YAML.stringify(s,null,2)},terraform:{options:{includeTags:!0},fn:(s,h)=>Ie(s,0,{sortKeys:!!(h?.sort?.length??h?.sortKeys?.length)})}})};var St={};C(St,{IncludeManager:()=>Le,DocumentIncludeProcessor:()=>_e});import pi from"fs/promises";import Ae from"path";class Le{includeDirectories=[];baseIncludeDirectories=[];includes=[];addDirectories(...e){this.includeDirectories.push(...e),this.baseIncludeDirectories.push(...e)}getDirectories(){return this.includeDirectories}reset(){this.includeDirectories=[...this.baseIncludeDirectories]}restore(e){this.includeDirectories=[...e]}snapshot(){return[...this.includeDirectories]}addFiles(...e){this.includes.push(...e)}getPendingAndClear(){let e=[...this.includes];return this.includes.length=0,e}async processPatterns(e,r,t){let n=[];for(let o of e)if(H.isGlobPattern(o)){let i=(await Array.fromAsync(pi.glob(o,{cwd:r}))).map((l)=>Ae.join(r,l));for(let l of i)if(!t.included.includes(l))n.push(l)}else if(H.isDirectoryPattern(o)){let i=Ae.isAbsolute(o)?o:Ae.join(r,o);if(!this.includeDirectories.includes(i))this.includeDirectories.push(i)}else n.push(o);return n}buildSearchDirs(e){let r=e?[e]:[];return r.push(...this.includeDirectories.map((t)=>Ae.isAbsolute(t)?t:Ae.join(e??process.cwd(),t))),r}}class _e{includeManager;loadFn;constructor(e,r){this.includeManager=e;this.loadFn=r}async processIncludes(e,r,t){let n=[];if(e.content.includes)n.push(...e.content.includes),delete e.content.includes;n.push(...this.includeManager.getPendingAndClear());let o=await this.includeManager.processPatterns(n,e.folderPath,t);for(let i of o)U(await this.loadFn(i,e.folderPath,{parent:e.content,...r},!0,t),e.content)}}var F={};C(F,{writeOutputs:()=>me,writeOutput:()=>je,writeFormat:()=>De,variable:()=>pr,tokenize:()=>Or,toObjectWithKey:()=>or,toObject:()=>ge,toList:()=>Z,stripIndent:()=>Ar,sortBy:()=>ar,snake:()=>re,sharedFunction:()=>mr,select:()=>x,section:()=>cr,processFields:()=>$,pascal:()=>ee,padBlock:()=>_,nonNullMap:()=>ir,navigate:()=>Ce,mergeAll:()=>z,merge:()=>U,makeFieldProcessorMap:()=>B,makeFieldProcessorList:()=>qe,makeFieldProcessor:()=>ce,macro:()=>p,locate:()=>X,loadFormat:()=>fe,key:()=>fr,importList:()=>Re,importGlob:()=>tr,globMap:()=>pe,getProcessor:()=>ue,getArgs:()=>Fe,find:()=>hr,exists:()=>q,encoder:()=>gr,defined:()=>sr,deepClone:()=>W,decoder:()=>yr,conditionPredicates:()=>K,changeCase:()=>te,capital:()=>he,camel:()=>we,asyncMap:()=>lr,ObjectorPlugin:()=>P,NavigateResult:()=>E,NavigateAction:()=>$e,Logger:()=>Be,AsyncFunction:()=>Er});D(F,so(Dt(),1));var jt={};C(jt,{Logger:()=>Be});class Be{options;constructor(e){this.options={level:"INFO",showClass:!1,levels:["DEBUG","VERBOSE","INFO","WARN","ERROR"],timeStamp:!1,timeOptions:{second:"2-digit",minute:"2-digit",hour:"2-digit",day:"2-digit",month:"2-digit",year:"2-digit"},logFunction:(r,...t)=>{switch(r){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)}},...e}}write(e,...r){if(this.options.level){let o=this.options.levels.indexOf(this.options.level)??-1,i=this.options.levels.indexOf(e);if(i===-1)throw Error(`Unknown log level: ${e}`);if(i<o)return}let t=[],n=[];if(this.options.timeStamp)n.push(new Date().toLocaleString(this.options.timeLocale,this.options.timeOptions));if(this.options.showClass)n.push(e);if(n.length>0)t.push(`[${n.join(" ")}]`);t.push(...r),this.options.logFunction(e,...t)}info(...e){this.write("INFO",...e)}error(...e){this.write("ERROR",...e)}warn(...e){this.write("WARN",...e)}debug(...e){this.write("DEBUG",...e)}verbose(...e){this.write("VERBOSE",...e)}}var Rt={};C(Rt,{AsyncFunction:()=>Er});Array.prototype.mapAsync=async function(e){let r=[];for(let t=0;t<this.length;t++)r.push(await e(this[t],t,this));return r};Array.prototype.nonNullMap=function(e){let r=[];for(let t=0;t<this.length;t++){let n=e(this[t],t,this);if(n!=null)r.push(n)}return r};Array.prototype.nonNullMapAsync=async function(e){let r=[];for(let t=0;t<this.length;t++){let n=await e(this[t],t,this);if(n!=null)r.push(n)}return r};Array.prototype.sortBy=function(e,r=!0){return this.slice().sort((t,n)=>{let o=e(t),i=e(n);if(o<i)return r?-1:1;if(o>i)return r?1:-1;return 0})};Array.prototype.forEachAsync=async function(e){for(let r=0;r<this.length;r++)await e(this[r],r,this)};Array.prototype.unique=function(){return Array.from(new Set(this))};Array.prototype.uniqueBy=function(e){let r=new Set;return this.filter((t)=>{let n=e(t);if(r.has(n))return!1;else return r.add(n),!0})};Array.prototype.groupBy=function(e){return this.reduce((r,t)=>{let n=e(t);if(!r[n])r[n]=[];return r[n].push(t),r},{})};Array.prototype.toObject=function(e,r){return Object.fromEntries(this.map((t)=>{let n=e(t),o=r?r(t):t;return[n,o]}))};Array.prototype.toObjectWithKey=function(e){return Object.fromEntries(this.map((r)=>[String(r[e]),r]))};Array.prototype.findOrFail=function(e,r,t){let n=this.find(e,t);if(n===void 0)throw Error(r??"Element not found");return n};Array.prototype.selectFor=function(e,r,t,n){let o=this.find(e,n);if(o===void 0)throw Error(t??"Element not found");return r(o)};Array.flat=function(e){if(Array.isArray(e))return e.flat(2);else return[e]};Array.prototype.createInstances=function(e,...r){return this.map((t,n)=>new e(...r,t,n))};Object.mapEntries=function(e,r){let n=Object.entries(e).map(([o,i])=>r(o,i));return Object.fromEntries(n)};Object.toList=function(e,r){return Object.entries(e).map(([t,n])=>({[r]:t,...n}))};Object.deepClone=function(e){if(typeof structuredClone<"u")try{return structuredClone(e)}catch{}return JSON.parse(JSON.stringify(e))};Object.find=function(e,r){for(let t in e)if(Object.prototype.hasOwnProperty.call(e,t)){let n=e[t];if(n!==void 0&&r(n,t))return[t,n]}return};Object.findAll=function(e,r){let t=[];for(let n in e)if(Object.prototype.hasOwnProperty.call(e,n)){let o=e[n];if(o!==void 0&&r(o,n))t.push([n,o])}return t};global.AsyncFunction=Object.getPrototypeOf(async function(){}).constructor;var Er=global.AsyncFunction;D(N,F);class $t{includeManager=new Le;includeProcessor;cacheManager=new We(100);outputs=[];vars={};funcs={};fields={sources:{},keys:{},sections:{}};objectMetadata={};currentContext=null;storedSections={};dataEncoders={};dataDecoders={};constructor(){this.includeProcessor=new _e(this.includeManager,this.load.bind(this)),this.use(vr)}use(e){if(e.prototype instanceof P)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,r){return this.objectMetadata[e]=r,this}getMetadata(e){return this.objectMetadata[e]}getAllMetadata(){return this.objectMetadata}setCacheMaxSize(e){return this.cacheManager.setMaxSize(e),this}clearCache(){return this.cacheManager.clear(),this}getCurrentContext(){return this.currentContext}fieldOptions(e){return this.fields={...this.fields,...e},this}section(e){return this.storedSections[e.config.name]=e,this}getSection(e){return this.storedSections[e]}encoders(e){return this.dataEncoders={...this.dataEncoders,...e},this}decoders(e){return this.dataDecoders={...this.dataDecoders,...e},this}getEncoder(e){return this.dataEncoders[e]}getDecoder(e){return this.dataDecoders[e]}filter(e){return this.fields.filters??=[],this.fields.filters.push(e),this}async loadObject(e,r,t){return $(e,{...this.fields,globalContext:{file:t?.fullPath??"@internal"},root:{...r,...this.fields.root,...this.vars,functions:this.funcs,context:this.currentContext,sections:this.storedSections,$document:{root:{content:e},fileName:t?.fileName??"@internal",folder:t?.folderPath??"@internal",fullPath:t?.fullPath??"@internal"}}})}async load(e,r,t,n,o){let i=this.includeManager.snapshot();try{this.includeManager.reset();let l=this.includeManager.buildSearchDirs(r);if(o)this.currentContext=o;this.currentContext??={included:[],document:null};let a=await fe(e,{dirs:l,parsers:this.dataDecoders,format:"yaml"}),c=H.normalize(a.fullPath);if(this.currentContext.included.push(c),!a.content)return null;let w=this.cacheManager.get(c),O;if(w)O=w.raw;else O=a.content,this.cacheManager.set(c,{raw:O,timestamp:Date.now()});let y=W(O);a.content=y,await this.includeProcessor.processIncludes(a,t,this.currentContext);let u;if(n!==!0)u=await this.loadObject(a.content,t,{fileName:a.fullPath,folderPath:a.folderPath,fullPath:a.fullPath});else u=a.content;return this.currentContext.document=u,u}catch(l){throw this.includeManager.restore(i),l}finally{this.includeManager.restore(i)}}async writeAll(e){await me(this.getOutputs(),e)}}export{me as writeOutputs,je as writeOutput,De as writeFormat,pr as variable,Or as tokenize,or as toObjectWithKey,ge as toObject,Z as toList,Ar as stripIndent,ar as sortBy,re as snake,mr as sharedFunction,x as select,cr as section,$ as processFields,ee as pascal,_ as padBlock,ir as nonNullMap,Ce as navigate,z as mergeAll,U as merge,B as makeFieldProcessorMap,qe as makeFieldProcessorList,ce as makeFieldProcessor,p as macro,X as locate,fe as loadFormat,fr as key,Re as importList,tr as importGlob,pe as globMap,ue as getProcessor,Fe as getArgs,hr as find,q as exists,gr as encoder,sr as defined,W as deepClone,yr as decoder,K as conditionPredicates,te as changeCase,he as capital,we as camel,lr as asyncMap,P as ObjectorPlugin,$t as Objector,E as NavigateResult,$e as NavigateAction,Be as Logger,Er as AsyncFunction};
20
+ ${n}}`}else return String(e)},H=(e)=>{if(!e)return e;return e.replaceAll("\\n",`
21
+ `).replaceAll("\\$","$").replaceAll("\\t","\t")};var yt=()=>({...T({merge:(...e)=>e.flatMap((t)=>t)}),join:({args:[e],root:t,tags:r})=>{let n=r.key?.[0],o=r.separator?.[0]??r.sep?.[0],s=r.finalize?.length>0,l=H(o);if(typeof e==="string"){if(s&&e.length&&l)return e+l;return e}if(!Array.isArray(e))throw Error("Object is not a list");let a=((n?.length)?e.map((m)=>Object.select({...t,...m},n)):e).join(l),u=r.pad?.[0]??"0",b=r.padChar?.[0]??" ",w=s&&a.length&&l?a+l:a;return u?w.padBlock(parseInt(u),`
22
+ `,b):w},range:({args:[e,t,r]})=>{let n=parseInt(e),o=parseInt(t),s=parseInt(r)||1;if(isNaN(n))throw Error("Invalid range: start value '"+String(e)+"' is not a number");if(isNaN(o))throw Error("Invalid range: end value '"+String(t)+"' is not a number");if(s===0)throw Error("Invalid range: step cannot be zero");if((o-n)/s<0)throw Error("Invalid range: step "+String(s)+" has wrong direction for range "+String(n)+" to "+String(o));return Array.from({length:Math.floor((o-n)/s)+1},(l,a)=>n+a*s)},filter:{types:(e,t,r)=>{switch(e){case 0:return"array";case 1:return Object.keys(x)}return le[r[1].value]?.(e-2,t,r.slice(2))},fn:({args:[e,t,r],root:n,tags:o})=>{if(e===null||e===void 0)throw Error("Filter source cannot be null or undefined");if(!Array.isArray(e))throw Error("Filter source must be an array");let s=o.key?.[0],l=x[t];if(s){let u=Array(e.length);for(let w=0;w<e.length;w++)try{u[w]=Object.select({...n,...e[w]},s)}catch{u[w]=Symbol("invalid")}let b=[];for(let w=0;w<e.length;w++){let m=u[w];if(typeof m!=="symbol"&&r===void 0?l(m):l(m,r))b.push(e[w])}return b}let a=[];for(let u of e)if(r===void 0?l(u):l(u,r))a.push(u);return a}}});var dt=()=>({each:{processArgs:!1,fn:async({rawArgs:[e,t,...r],root:n,options:o,tags:s})=>{let l=async(y)=>y.quoted?H(y.value):await Object.select(n,y.value),a=await Object.select(n,e.value),u=await l(t),b=s.key?.[0],w=Array.isArray(a)?a:Object.toList(a,"name"),m=[],g=await Promise.all(r.map(async(y)=>await l(y))),d={...n,item:void 0,index:0,params:g,instance:void 0,parent:n.this,tags:s},E={...o,root:d};for(let y=0;y<w.length;y++){let j=Object.deepClone(u),h={instance:j},k=typeof u==="string"?h:j;if(d.item=w[y],d.index=y,d.instance=j,s?.root?.[0])Object.assign(d,await Object.select(d,s.root[0]));if(await R(k,E),b!==void 0)m.push(await Object.select(h.instance,b));else m.push(h.instance)}if(s.join?.length){if(m.length===0)return"";let y=H(s.join[0]),j=s.pad?.[0]??"0",h=s.padChar?.[0]??" ",k=s.finalize?.length&&y?y:"",O=`${m.join(y)}${k}`;return j?O.padBlock(parseInt(j),`
23
+ `,h):O}return m}}});var Q=async(e,t,r)=>e.rawArgs[t].quoted?e.rawArgs[t].value:await Object.select(e.root,e.rawArgs[t].value,{defaultValue:r}),ht=()=>({switch:{processArgs:!1,fn:async(e)=>{let t=await Q(e,0,!1),r=await Q(e,1);if(r[t]===void 0){if(e.rawArgs.length>2)return Q(e,2);throw Error(`Unhandled switch case: ${t}`)}return r[t]}}});var bt=()=>({if:{types:{0:"boolean"},fn:(e)=>e.args[0]?e.args[1]:e.args[2]},check:{types:{0:Object.keys(x)},fn:(e)=>x[e.args[0]](...e.args.slice(1))},...T(x,{types:le})});var wt=(e)=>({default:{processArgs:!1,fn:async(t)=>{for(let r=0;r<t.rawArgs.length;r++)if(t.rawArgs[r]?.value!==void 0){let o=await Q(t,r,null);if(o!==null)return o}if(t.tags.nullable?.length)return v.DeleteItem();if(t.tags.fail?.length)throw Error(`No valid value found for default (${t.rawArgs.map((r)=>r.value).join(", ")})`);return""}},section:{types:["string","boolean"],fn:(t)=>{let r=t.args[0];if(!(t.args[1]??!0))return null;let o=e.getSection(r);if(!o)throw Error(`Section not found: ${r}`);return o.content}}});var Ot=()=>({convert:({args:[e,t,r]})=>{switch(t){case"string":return String(e);case"number":{let n=Number(e);if(!isNaN(n))return v.ReplaceItem(n);break}case"boolean":if(e==="true"||e===!0||e===1||e==="1"||e==="yes"||e==="on")return v.ReplaceItem(!0);else if(e==="false"||e===!1||e===0||e==="0"||e==="no"||e==="off")return v.ReplaceItem(!1);break;default:throw Error(`Unsupported type for convert: ${t}`)}if(r!==void 0)return v.ReplaceItem(r);throw Error(`Failed to convert value to ${t}`)},isType:({args:[e,t]})=>{let n=(()=>{switch(t){case"string":return typeof e==="string";case"number":return typeof e==="number";case"boolean":return typeof e==="boolean";case"object":return e!==null&&typeof e==="object"&&!Array.isArray(e);case"array":return Array.isArray(e);case"null":return e===null;case"undefined":return e===void 0;case"function":return typeof e==="function";default:throw Error(`Unknown type for isType: ${t}`)}})();return v.ReplaceItem(n)},typeOf:({args:[e]})=>{if(e===null)return"null";else if(Array.isArray(e))return"array";else return typeof e}});var At=(e)=>{var t,r,n,o,s,l,a,u,b,w,m,g,d,E,y,j,h,k,O,S,M,Z,W,C,P,J,ee,B,ce,te,fe,jt,vt,Et,St,kt,Mt,Ft,Dt,Rt,$t,Ct,xt,Nt,Wt,It,Lt,_t,Ut,Bt,qt,Kt,Yt,Gt,Tt,Vt,Xt,Ht,Qt,zt,Zt,Pt,Jt,er,tr,rr,nr,or,ir,sr,ar,lr,ur,cr,fr,pr,gr,mr,yr,dr,hr,br,wr,Or,Ar,jr,vr,Er,Sr,kr,Mr,Fr,Dr,Rr,$r,Cr,xr,Nr,Wr,Ir,Lr,_r,Ur,Br,o,s,l,a,u,b,w,m,g,d,E,y,j,h,k,O,S,M,Z,W,C,P,J,ee,B,ce,te,fe,jt,vt,Et,St,kt,Mt,Ft,Dt,Rt,$t,Ct,xt,Nt,Wt,It,Lt,_t,Ut,Bt,qt,Kt,Yt,Gt,Tt,Vt,Xt,Ht,Qt,zt,Zt,Pt,Jt,er,tr,rr,nr,or,ir,sr,ar,lr,ur,cr,fr,pr,gr,mr,yr,dr,hr,br,wr,Or,Ar,jr,vr,Er,Sr,kr,Mr,Fr,Dr,Rr,$r,Cr,xr,Nr,Wr,Ir,Lr,_r,Ur,Br;return e.use((n=V,o=[f()],s=[f()],l=[f()],a=[f()],u=[f()],b=[f()],w=[f()],m=[f()],g=[f()],d=[f()],E=[f()],y=[f()],j=[f()],h=[f()],k=[f()],O=[f()],S=[f()],M=[f()],Z=[f()],W=[f()],C=[f()],P=[f()],J=[f()],ee=[f()],B=[f()],ce=[f()],te=[f()],fe=[f()],jt=[f()],vt=[f()],Et=[f()],St=[f()],kt=[f()],Mt=[f()],Ft=[f()],Dt=[f()],Rt=[f()],$t=[f()],Ct=[f()],xt=[f()],Nt=[f()],Wt=[f()],It=[f()],Lt=[f()],_t=[f()],Ut=[f()],Bt=[f()],qt=[f()],Kt=[f()],Yt=[f()],Gt=[f()],Tt=[f()],Vt=[f()],Xt=[f()],Ht=[f()],Qt=[f()],zt=[f()],Zt=[f()],Pt=[f()],Jt=[f()],er=[f()],tr=[f()],rr=[f()],nr=[f()],or=[f()],ir=[f()],sr=[f()],ar=[f()],lr=[f()],ur=[f()],cr=[f()],fr=[f()],pr=[f()],gr=[f()],mr=[f()],yr=[f()],dr=[f()],hr=[f()],br=[f()],wr=[f()],Or=[f()],Ar=[f()],jr=[f()],vr=[f()],Er=[f()],Sr=[f()],kr=[f()],Mr=[f()],Fr=[f()],Dr=[f()],Rr=[f()],$r=[f()],Cr=[f()],xr=[f()],Nr=[f()],Wr=[f()],Ir=[f()],Lr=[f()],_r=[f()],Ur=[f()],Br=[f()],r=Re(n),t=class extends n{constructor(){super(...arguments);Ce(r,5,this)}env(i){return process.env[i]}uuid(){return crypto.randomUUID()}pascal(i){return i.toPascal()}camel(i){return i.toCamel()}capital(i){return i.capitalize()}snake(i,p="lower"){return i.changeCase(p).toSnake()}kebab(i,p="lower"){return i.changeCase(p).toKebab()}len(i){return i.length}reverse(i){return i.split("").reverse().join("")}concat(...i){return i.join("")}trim(i){return i.trim()}ltrim(i){return i.trimStart()}rtrim(i){return i.trimEnd()}lower(i){return i.toLowerCase()}upper(i){return i.toUpperCase()}encode(i,p){return Buffer.from(i).toString(p??"base64")}decode(i,p){return Buffer.from(i,p??"base64").toString()}list(i,p="name"){return Object.toList(i,p)}object(i,p="name"){return i.toObject((A)=>A[p],(A)=>{let{[p]:D,...$}=A;return $})}pathJoin(...i){return N.join(...i)}resolve(...i){return N.resolve(...i)}dirname(i){return N.dirname(i)}basename(i,p){return N.basename(i,p)}normalize(i){return N.normalize(i)}extname(i){return N.extname(i)}relative(i,p){return N.relative(i,p)}isAbsolute(i){return N.isAbsolute(i)}segments(i){return i.split("/").filter(Boolean)}log(...i){console.log(...i)}md5(i){return U("md5").update(i).digest("hex")}sha1(i){return U("sha1").update(i).digest("hex")}sha256(i){return U("sha256").update(i).digest("hex")}sha512(i){return U("sha512").update(i).digest("hex")}hash(i,p="sha256"){return U(p).update(i).digest("hex")}hmac(i,p,A="sha256"){return U(A).update(i).digest("hex")}base64Encode(i){return Buffer.from(i).toString("base64")}base64Decode(i){return Buffer.from(i,"base64").toString("utf-8")}hexEncode(i){return Buffer.from(i).toString("hex")}hexDecode(i){return Buffer.from(i,"hex").toString("utf-8")}add(...i){return i.reduce((p,A)=>p+A,0)}subtract(i,p){return i-p}multiply(...i){return i.reduce((p,A)=>p*A,1)}divide(i,p){if(p===0)throw Error("Division by zero");return i/p}modulo(i,p){return i%p}power(i,p){return Math.pow(i,p)}sqrt(i){return Math.sqrt(i)}abs(i){return Math.abs(i)}floor(i){return Math.floor(i)}ceil(i){return Math.ceil(i)}round(i,p){let A=Math.pow(10,p??0);return Math.round(i*A)/A}min(...i){return Math.min(...i)}max(...i){return Math.max(...i)}clamp(i,p,A){return Math.max(p,Math.min(A,i))}random(i,p){let A=i??0,D=p??1;return Math.random()*(D-A)+A}timestamp(i){return new Date(i).getTime()}iso(i){return new Date(i).toISOString()}utc(i){return new Date(i).toUTCString()}formatDate(i,p){let A=new Date(i),D=A.getFullYear(),$=String(A.getMonth()+1).padStart(2,"0"),re=String(A.getDate()).padStart(2,"0"),q=String(A.getHours()).padStart(2,"0"),qr=String(A.getMinutes()).padStart(2,"0"),Kr=String(A.getSeconds()).padStart(2,"0");return p.replace("YYYY",String(D)).replace("MM",$).replace("DD",re).replace("HH",q).replace("mm",qr).replace("ss",Kr)}parseDate(i){return new Date(i).getTime()}year(i){return new Date(i).getFullYear()}month(i){return new Date(i).getMonth()+1}day(i){return new Date(i).getDate()}dayOfWeek(i){return new Date(i).getDay()}hours(i){return new Date(i).getHours()}minutes(i){return new Date(i).getMinutes()}seconds(i){return new Date(i).getSeconds()}regexTest(i,p,A){return new RegExp(i,A).test(p)}regexMatch(i,p,A){return new RegExp(i,A).exec(p)}regexMatchAll(i,p,A){return Array.from(p.matchAll(new RegExp(i,A)))}regexReplace(i,p,A,D){return A.replace(new RegExp(i,D),p)}regexReplaceAll(i,p,A,D){return A.replace(new RegExp(i,D??"g"),p)}regexSplit(i,p,A){return p.split(new RegExp(i,A))}regexExec(i,p,A){return new RegExp(i,A).exec(p)}regexSearch(i,p,A){return p.search(new RegExp(i,A))}unique(i,p){if(!Array.isArray(i))return i;let A=new Set;return i.filter((D)=>{let $=p?D[p]:D;if(A.has($))return!1;return A.add($),!0})}groupBy(i,p){if(!Array.isArray(i))return i;let A={};return i.forEach((D)=>{let $=String(D[p]);if(!A[$])A[$]=[];A[$].push(D)}),A}chunk(i,p=1){if(!Array.isArray(i))return[];let A=[];for(let D=0;D<i.length;D+=p)A.push(i.slice(D,D+p));return A}flatten(i,p=1){if(!Array.isArray(i))return[i];let A=[],D=($,re)=>{for(let q of $)if(Array.isArray(q)&&re>0)D(q,re-1);else A.push(q)};return D(i,p),A}compact(i){if(!Array.isArray(i))return i;return i.filter((p)=>p!==null&&p!==void 0)}head(i,p){if(!Array.isArray(i))return i;return p?i.slice(0,p):i[0]}tail(i,p){if(!Array.isArray(i))return i;return p?i.slice(-p):i[i.length-1]}isEmail(i){return/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(i)}isUrl(i){try{return new URL(i),!0}catch{return!1}}isJson(i){try{return JSON.parse(i),!0}catch{return!1}}isUuid(i){return/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i.test(i)}minLength(i,p){return i?.length>=p}maxLength(i,p){return i?.length<=p}lengthEquals(i,p){return i?.length===p}isNumber(i){return typeof i==="number"&&!isNaN(i)}isString(i){return typeof i==="string"}isBoolean(i){return typeof i==="boolean"}isArray(i){return Array.isArray(i)}isObject(i){return i!==null&&typeof i==="object"&&!Array.isArray(i)}isEmpty(i){if(i===null||i===void 0)return!0;if(typeof i==="string"||Array.isArray(i))return i.length===0;if(typeof i==="object")return Object.keys(i).length===0;return!1}isTruthy(i){return!!i}isFalsy(i){return!i}inRange(i,p,A){return i>=p&&i<=A}matchesPattern(i,p){return new RegExp(p).test(i)}includes(i,p){if(typeof i==="string")return i.includes(String(p));return Array.isArray(i)&&i.includes(p)}startsWith(i,p){return i.startsWith(p)}endsWith(i,p){return i.endsWith(p)}},c(r,1,"env",o,t),c(r,1,"uuid",s,t),c(r,1,"pascal",l,t),c(r,1,"camel",a,t),c(r,1,"capital",u,t),c(r,1,"snake",b,t),c(r,1,"kebab",w,t),c(r,1,"len",m,t),c(r,1,"reverse",g,t),c(r,1,"concat",d,t),c(r,1,"trim",E,t),c(r,1,"ltrim",y,t),c(r,1,"rtrim",j,t),c(r,1,"lower",h,t),c(r,1,"upper",k,t),c(r,1,"encode",O,t),c(r,1,"decode",S,t),c(r,1,"list",M,t),c(r,1,"object",Z,t),c(r,1,"pathJoin",W,t),c(r,1,"resolve",C,t),c(r,1,"dirname",P,t),c(r,1,"basename",J,t),c(r,1,"normalize",ee,t),c(r,1,"extname",B,t),c(r,1,"relative",ce,t),c(r,1,"isAbsolute",te,t),c(r,1,"segments",fe,t),c(r,1,"log",jt,t),c(r,1,"md5",vt,t),c(r,1,"sha1",Et,t),c(r,1,"sha256",St,t),c(r,1,"sha512",kt,t),c(r,1,"hash",Mt,t),c(r,1,"hmac",Ft,t),c(r,1,"base64Encode",Dt,t),c(r,1,"base64Decode",Rt,t),c(r,1,"hexEncode",$t,t),c(r,1,"hexDecode",Ct,t),c(r,1,"add",xt,t),c(r,1,"subtract",Nt,t),c(r,1,"multiply",Wt,t),c(r,1,"divide",It,t),c(r,1,"modulo",Lt,t),c(r,1,"power",_t,t),c(r,1,"sqrt",Ut,t),c(r,1,"abs",Bt,t),c(r,1,"floor",qt,t),c(r,1,"ceil",Kt,t),c(r,1,"round",Yt,t),c(r,1,"min",Gt,t),c(r,1,"max",Tt,t),c(r,1,"clamp",Vt,t),c(r,1,"random",Xt,t),c(r,1,"timestamp",Ht,t),c(r,1,"iso",Qt,t),c(r,1,"utc",zt,t),c(r,1,"formatDate",Zt,t),c(r,1,"parseDate",Pt,t),c(r,1,"year",Jt,t),c(r,1,"month",er,t),c(r,1,"day",tr,t),c(r,1,"dayOfWeek",rr,t),c(r,1,"hours",nr,t),c(r,1,"minutes",or,t),c(r,1,"seconds",ir,t),c(r,1,"regexTest",sr,t),c(r,1,"regexMatch",ar,t),c(r,1,"regexMatchAll",lr,t),c(r,1,"regexReplace",ur,t),c(r,1,"regexReplaceAll",cr,t),c(r,1,"regexSplit",fr,t),c(r,1,"regexExec",pr,t),c(r,1,"regexSearch",gr,t),c(r,1,"unique",mr,t),c(r,1,"groupBy",yr,t),c(r,1,"chunk",dr,t),c(r,1,"flatten",hr,t),c(r,1,"compact",br,t),c(r,1,"head",wr,t),c(r,1,"tail",Or,t),c(r,1,"isEmail",Ar,t),c(r,1,"isUrl",jr,t),c(r,1,"isJson",vr,t),c(r,1,"isUuid",Er,t),c(r,1,"minLength",Sr,t),c(r,1,"maxLength",kr,t),c(r,1,"lengthEquals",Mr,t),c(r,1,"isNumber",Fr,t),c(r,1,"isString",Dr,t),c(r,1,"isBoolean",Rr,t),c(r,1,"isArray",$r,t),c(r,1,"isObject",Cr,t),c(r,1,"isEmpty",xr,t),c(r,1,"isTruthy",Nr,t),c(r,1,"isFalsy",Wr,t),c(r,1,"inRange",Ir,t),c(r,1,"matchesPattern",Lr,t),c(r,1,"includes",_r,t),c(r,1,"startsWith",Ur,t),c(r,1,"endsWith",Br,t),ge(r,t),t)).keys({...Ze(e),...Pe(e),...Je(),...et(),...ot(),...tt(),...rt(),...nt(e),...st(e),...at(),...lt(),...ut()}).sources({...gt(e),...mt(e),...Ot(),...yt(),...dt(),...ht(),...bt(),...wt(e)}).sections(ft(e)).fieldOptions({configParser:Bun.YAML.parse,onSection:(i)=>{if(i.section.config.name)e.section(i.section)}}).decoders({yaml:{matching:["\\.yml$","\\.yaml$"],fn:Bun.YAML.parse}}).encoders({json:{fn:(i)=>JSON.stringify(i,null,2)},yaml:{fn:(i)=>Bun.YAML.stringify(i,null,2)},terraform:{options:{includeTags:!0},fn:(i,p)=>ue(i,0,{sortKeys:!!(p?.sort?.length??p?.sortKeys?.length)})}})};import Tn from"fs/promises";import z from"path";class ve{includeDirectories=[];baseIncludeDirectories=[];includes=[];addDirectories(...e){this.includeDirectories.push(...e),this.baseIncludeDirectories.push(...e)}getDirectories(){return this.includeDirectories}reset(){this.includeDirectories=[...this.baseIncludeDirectories]}restore(e){this.includeDirectories=[...e]}snapshot(){return[...this.includeDirectories]}addFiles(...e){this.includes.push(...e)}getPendingAndClear(){let e=[...this.includes];return this.includes.length=0,e}async processPatterns(e,t,r){let n=[];for(let o of e)if(_.isGlobPattern(o)){let s=(await Array.fromAsync(Tn.glob(o,{cwd:t}))).map((l)=>z.join(t,l));for(let l of s)if(!r.included.includes(l))n.push(l)}else if(_.isDirectoryPattern(o)){let s=z.isAbsolute(o)?o:z.join(t,o);if(!this.includeDirectories.includes(s))this.includeDirectories.push(s)}else n.push(o);return n}buildSearchDirs(e){let t=e?[e]:[];return t.push(...this.includeDirectories.map((r)=>z.isAbsolute(r)?r:z.join(e??process.cwd(),r))),t}}class Ee{includeManager;loadFn;constructor(e,t){this.includeManager=e;this.loadFn=t}async processIncludes(e,t,r){let n=[];if(e.content.includes)n.push(...e.content.includes),delete e.content.includes;n.push(...this.includeManager.getPendingAndClear());let o=await this.includeManager.processPatterns(n,e.folderPath,r);for(let s of o)Object.merge(await this.loadFn(s,e.folderPath,{parent:e.content,...t},!0,r),e.content)}}class Vn{includeManager=new ve;includeProcessor;cacheManager=new Oe(100);outputs=[];vars={};funcs={};fields={sources:{},keys:{},sections:{}};objectMetadata={};currentContext=null;storedSections={};dataEncoders={};dataDecoders={};constructor(){this.includeProcessor=new Ee(this.includeManager,this.load.bind(this)),this.use(At)}use(e){if(e.prototype instanceof V)new e(this);else e(this);return this}includeDirectory(...e){return this.includeManager.addDirectories(...e),this}getIncludeDirectories(){return this.includeManager.getDirectories()}include(...e){return this.includeManager.addFiles(...e),this}keys(e){return Object.assign(this.fields.keys,{...this.fields.keys,...e}),this}sources(e){return Object.assign(this.fields.sources,{...this.fields.sources,...e}),this}sections(e){return Object.assign(this.fields.sections,{...this.fields.sections,...e}),this}variables(e){return this.vars={...this.vars,...e},this}functions(e){return this.funcs={...this.funcs,...e},this}getFunctions(){return this.funcs}getOutputs(){return this.outputs}output(e){return this.outputs.push(e),this}metadata(e,t){return this.objectMetadata[e]=t,this}getMetadata(e){return this.objectMetadata[e]}getAllMetadata(){return this.objectMetadata}setCacheMaxSize(e){return this.cacheManager.setMaxSize(e),this}clearCache(){return this.cacheManager.clear(),this}getCurrentContext(){return this.currentContext}fieldOptions(e){return this.fields={...this.fields,...e},this}section(e){return this.storedSections[e.config.name]=e,this}getSection(e){return this.storedSections[e]}encoders(e){return this.dataEncoders={...this.dataEncoders,...e},this}decoders(e){return this.dataDecoders={...this.dataDecoders,...e},this}getEncoder(e){return this.dataEncoders[e]}getDecoder(e){return this.dataDecoders[e]}filter(e){return this.fields.filters??=[],this.fields.filters.push(e),this}async loadObject(e,t,r){return R(e,{...this.fields,globalContext:{file:r?.fullPath??"@internal"},root:{...t,...this.fields.root,...this.vars,functions:this.funcs,context:this.currentContext,sections:this.storedSections,$document:{root:{content:e},fileName:r?.fileName??"@internal",folder:r?.folderPath??"@internal",fullPath:r?.fullPath??"@internal"}}})}async load(e,t,r,n,o){let s=this.includeManager.snapshot();try{this.includeManager.reset();let l=this.includeManager.buildSearchDirs(t);if(o)this.currentContext=o;this.currentContext??={included:[],document:null};let a=await Xe(e,{dirs:l,parsers:this.dataDecoders,format:"yaml"}),u=_.normalize(a.fullPath);if(this.currentContext.included.push(u),!a.content)return null;let b=this.cacheManager.get(u),w;if(b)w=b.raw;else w=a.content,this.cacheManager.set(u,{raw:w,timestamp:Date.now()});let m=Object.deepClone(w);a.content=m,await this.includeProcessor.processIncludes(a,r,this.currentContext);let g;if(n!==!0)g=await this.loadObject(a.content,r,{fileName:a.fullPath,folderPath:a.folderPath,fullPath:a.fullPath});else g=a.content;return this.currentContext.document=g,g}catch(l){throw this.includeManager.restore(s),l}finally{this.includeManager.restore(s)}}async writeAll(e){await ze(this.getOutputs(),e)}}export{ze as writeOutputs,xn as writeOutput,$n as writeFormat,fo as variable,po as sharedFunction,uo as section,R as processFields,T as makeFieldProcessorMap,Hn as makeFieldProcessorList,Ye as makeFieldProcessor,f as macro,oe as locate,Xe as loadFormat,co as key,Wn as importList,ao as importGlob,He as globMap,_e as getProcessor,hn as getArgs,we as exists,go as encoder,Qo as defined,mo as decoder,x as conditionPredicates,V as ObjectorPlugin,Vn as Objector,v as NavigateResult,Ln as NavigateAction,qn as Logger};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@homedev/objector",
3
- "version": "1.2.65",
3
+ "version": "1.2.67",
4
4
  "description": "object extensions for YAML/JSON",
5
5
  "author": "julzor",
6
6
  "license": "ISC",