@homedev/objector 1.2.41 → 1.2.42
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 +240 -31
- package/dist/index.js +11 -11
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -1,12 +1,53 @@
|
|
|
1
1
|
/**
|
|
2
|
+
* Maps an array asynchronously using Promise.all for parallel execution
|
|
3
|
+
* @typeParam T - Type of input array items
|
|
4
|
+
* @typeParam U - Type of async result items
|
|
5
|
+
* @param arr - Array to map
|
|
6
|
+
* @param fn - Async mapping function
|
|
7
|
+
* @returns Promise of mapped array
|
|
2
8
|
* @public
|
|
3
9
|
*/
|
|
4
10
|
declare const asyncMap: <T, U>(arr: T[], fn: (item: T, index: number, array: T[]) => Promise<U>) => Promise<U[]>;
|
|
5
11
|
|
|
12
|
+
/**
|
|
13
|
+
* Converts a string to camelCase (lowerCamelCase).
|
|
14
|
+
* Handles spaces, underscores, and hyphens as word separators.
|
|
15
|
+
*
|
|
16
|
+
* @example
|
|
17
|
+
* camel('hello_world') // 'helloWorld'
|
|
18
|
+
* camel('hello world') // 'helloWorld'
|
|
19
|
+
* camel('HelloWorld') // 'helloWorld'
|
|
20
|
+
*
|
|
21
|
+
* @param v - The string to convert
|
|
22
|
+
* @returns The string in camelCase
|
|
23
|
+
*/
|
|
6
24
|
declare const camel: (v: string) => string;
|
|
7
25
|
|
|
26
|
+
/**
|
|
27
|
+
* Converts a string to Capital Case (each word capitalized, spaces preserved).
|
|
28
|
+
* Only capitalizes words following spaces.
|
|
29
|
+
*
|
|
30
|
+
* @example
|
|
31
|
+
* capital('hello world') // 'Hello World'
|
|
32
|
+
* capital('hello_world') // 'hello_World'
|
|
33
|
+
*
|
|
34
|
+
* @param v - The string to convert
|
|
35
|
+
* @returns The string with each space-separated word capitalized
|
|
36
|
+
*/
|
|
8
37
|
declare const capital: (v: string) => string;
|
|
9
38
|
|
|
39
|
+
/**
|
|
40
|
+
* Changes the case of a string to uppercase, lowercase, or returns unchanged.
|
|
41
|
+
*
|
|
42
|
+
* @example
|
|
43
|
+
* changeCase('Hello', 'upper') // 'HELLO'
|
|
44
|
+
* changeCase('Hello', 'lower') // 'hello'
|
|
45
|
+
* changeCase('Hello') // 'Hello'
|
|
46
|
+
*
|
|
47
|
+
* @param v - The string to transform
|
|
48
|
+
* @param arg - The case type: 'upper', 'lower', or undefined to return unchanged
|
|
49
|
+
* @returns The transformed string
|
|
50
|
+
*/
|
|
10
51
|
declare const changeCase: (v: string, arg?: string) => string;
|
|
11
52
|
|
|
12
53
|
/**
|
|
@@ -15,11 +56,24 @@ declare const changeCase: (v: string, arg?: string) => string;
|
|
|
15
56
|
declare const conditionPredicates: Record<string, (...args: any[]) => boolean>;
|
|
16
57
|
|
|
17
58
|
/**
|
|
59
|
+
* Deep clones an object using structuredClone (faster) with JSON fallback
|
|
60
|
+
* - Uses structuredClone for better performance and broader type support (Date, RegExp, etc.)
|
|
61
|
+
* - Falls back to JSON serialization if structuredClone fails or is unavailable
|
|
62
|
+
* - Note: Functions, symbols, and undefined values are lost in JSON fallback
|
|
63
|
+
* @typeParam T - Type of object to clone
|
|
64
|
+
* @param model - Object to clone
|
|
65
|
+
* @returns Deep clone of the object
|
|
18
66
|
* @public
|
|
19
67
|
*/
|
|
20
|
-
declare const deepClone: (model:
|
|
68
|
+
declare const deepClone: <T>(model: T) => T;
|
|
21
69
|
|
|
22
70
|
/**
|
|
71
|
+
* Asserts that a value is defined, throwing an error if undefined
|
|
72
|
+
* @typeParam T - Type of the value
|
|
73
|
+
* @param value - Value to check
|
|
74
|
+
* @param msg - Error message to throw if value is undefined
|
|
75
|
+
* @returns The value if defined
|
|
76
|
+
* @throws Error if value is undefined
|
|
23
77
|
* @public
|
|
24
78
|
*/
|
|
25
79
|
declare const defined: <T>(value: T | undefined, msg?: string) => T;
|
|
@@ -56,6 +110,12 @@ declare interface FieldProcessorOptions {
|
|
|
56
110
|
types?: Record<number, string | any[] | ((value: string, root: any, index: number, quoted: boolean) => any)> | FieldProcessorTypeChecker;
|
|
57
111
|
}
|
|
58
112
|
|
|
113
|
+
declare interface FieldProcessorSection {
|
|
114
|
+
name: string;
|
|
115
|
+
config: Record<string, any>;
|
|
116
|
+
content: string;
|
|
117
|
+
}
|
|
118
|
+
|
|
59
119
|
declare type FieldProcessorTypeChecker = (n: number, value: any, args: any[]) => any;
|
|
60
120
|
|
|
61
121
|
declare type FieldProcessorTypeCheckers<T = unknown> = Record<keyof T, FieldProcessorTypeChecker>;
|
|
@@ -71,12 +131,21 @@ declare interface FilePatternOptions {
|
|
|
71
131
|
}
|
|
72
132
|
|
|
73
133
|
/**
|
|
134
|
+
* Finds values in an object tree that match a predicate function.
|
|
135
|
+
*
|
|
74
136
|
* @public
|
|
75
|
-
* @param from
|
|
76
|
-
* @param cb
|
|
77
|
-
* @returns
|
|
137
|
+
* @param from - The object to search through
|
|
138
|
+
* @param cb - Predicate function that receives the path and value, returns true for matches
|
|
139
|
+
* @returns Array of matching values
|
|
140
|
+
*
|
|
141
|
+
* @example
|
|
142
|
+
* ```typescript
|
|
143
|
+
* const obj = { a: { b: 1 }, c: { d: 2 } }
|
|
144
|
+
* const results = await find(obj, (path, value) => value === 2)
|
|
145
|
+
* // results: [2]
|
|
146
|
+
* ```
|
|
78
147
|
*/
|
|
79
|
-
declare const find: (from: any, cb: (path: string, value:
|
|
148
|
+
declare const find: (from: any, cb: (path: string, value: any) => boolean) => Promise<any[]>;
|
|
80
149
|
|
|
81
150
|
declare const globMap: <T>(pattern: string | string[], options: FilePatternOptions) => Promise<T[] | T>;
|
|
82
151
|
|
|
@@ -104,12 +173,12 @@ declare interface ImportOptions {
|
|
|
104
173
|
declare namespace libs {
|
|
105
174
|
export {
|
|
106
175
|
conditionPredicates,
|
|
107
|
-
deepClone,
|
|
108
176
|
FieldContext,
|
|
109
177
|
FieldProcessor,
|
|
110
178
|
FieldProcessorFunc,
|
|
111
179
|
FieldProcessorMap,
|
|
112
180
|
FieldProcessorOptions,
|
|
181
|
+
FieldProcessorSection,
|
|
113
182
|
FieldProcessorTypeChecker,
|
|
114
183
|
FieldProcessorTypeCheckers,
|
|
115
184
|
FieldProcessorTypedFunc,
|
|
@@ -144,6 +213,7 @@ declare namespace libs {
|
|
|
144
213
|
NavigateContext,
|
|
145
214
|
NavigateResult,
|
|
146
215
|
asyncMap,
|
|
216
|
+
deepClone,
|
|
147
217
|
defined,
|
|
148
218
|
nonNullMap,
|
|
149
219
|
sortBy,
|
|
@@ -165,9 +235,12 @@ declare namespace libs {
|
|
|
165
235
|
}
|
|
166
236
|
export default libs;
|
|
167
237
|
|
|
168
|
-
|
|
238
|
+
/**
|
|
239
|
+
* @public
|
|
240
|
+
*/
|
|
241
|
+
export declare interface LoadContext {
|
|
169
242
|
included: string[];
|
|
170
|
-
document:
|
|
243
|
+
document: unknown;
|
|
171
244
|
}
|
|
172
245
|
|
|
173
246
|
/**
|
|
@@ -242,9 +315,20 @@ declare interface MergeOptions {
|
|
|
242
315
|
}
|
|
243
316
|
|
|
244
317
|
/**
|
|
318
|
+
* Recursively navigates through an object tree, invoking a callback for each property.
|
|
319
|
+
* Supports various actions like replacing, deleting, or merging values during traversal.
|
|
320
|
+
* Includes circular reference detection to prevent infinite loops.
|
|
321
|
+
*
|
|
322
|
+
* Performance optimizations:
|
|
323
|
+
* - Caches static NavigateResult instances
|
|
324
|
+
* - Uses WeakSet for O(1) circular reference detection
|
|
325
|
+
* - Avoids Object.entries() to prevent array allocations
|
|
326
|
+
* - Optimizes switch statement order for common cases
|
|
327
|
+
*
|
|
245
328
|
* @public
|
|
246
|
-
* @param o
|
|
247
|
-
* @param cb
|
|
329
|
+
* @param o - The object to navigate
|
|
330
|
+
* @param cb - Callback function invoked for each property
|
|
331
|
+
* @throws {Error} When attempting to replace the root object
|
|
248
332
|
*/
|
|
249
333
|
declare const navigate: (o: any, cb: NavigateCallback) => Promise<void>;
|
|
250
334
|
|
|
@@ -284,9 +368,13 @@ declare interface NavigateContext {
|
|
|
284
368
|
declare class NavigateResult {
|
|
285
369
|
readonly action: NavigateAction;
|
|
286
370
|
by?: any | undefined;
|
|
287
|
-
|
|
371
|
+
skipSiblings?: boolean | undefined;
|
|
288
372
|
reexplore?: boolean | undefined;
|
|
289
|
-
constructor(action: NavigateAction, by?: any | undefined,
|
|
373
|
+
constructor(action: NavigateAction, by?: any | undefined, skipSiblings?: boolean | undefined, reexplore?: boolean | undefined);
|
|
374
|
+
private static readonly _explore;
|
|
375
|
+
private static readonly _noExplore;
|
|
376
|
+
private static readonly _skipSiblings;
|
|
377
|
+
private static readonly _deleteParent;
|
|
290
378
|
static ReplaceParent(by: any, reexplore?: boolean): NavigateResult;
|
|
291
379
|
static SkipSiblings(): NavigateResult;
|
|
292
380
|
static Explore(): NavigateResult;
|
|
@@ -298,6 +386,13 @@ declare class NavigateResult {
|
|
|
298
386
|
}
|
|
299
387
|
|
|
300
388
|
/**
|
|
389
|
+
* Maps an array while filtering out null/undefined values (performance optimized)
|
|
390
|
+
* Combines filter and map operations to avoid double iteration
|
|
391
|
+
* @typeParam T - Type of input array items
|
|
392
|
+
* @typeParam U - Type of mapped result items
|
|
393
|
+
* @param arr - Array to map (can be undefined)
|
|
394
|
+
* @param fn - Mapping function
|
|
395
|
+
* @returns Mapped array with nulls/undefined filtered out, or empty array if input is undefined
|
|
301
396
|
* @public
|
|
302
397
|
*/
|
|
303
398
|
declare const nonNullMap: <T, U>(arr: T[] | undefined, fn: (item: T, index: number, array: T[]) => U) => U[];
|
|
@@ -306,14 +401,15 @@ declare const nonNullMap: <T, U>(arr: T[] | undefined, fn: (item: T, index: numb
|
|
|
306
401
|
* @public
|
|
307
402
|
*/
|
|
308
403
|
export declare class Objector {
|
|
309
|
-
private
|
|
310
|
-
private
|
|
404
|
+
private includeManager;
|
|
405
|
+
private includeProcessor;
|
|
406
|
+
private cacheManager;
|
|
311
407
|
private outputs;
|
|
312
408
|
private vars;
|
|
313
|
-
private cache;
|
|
314
409
|
private fields;
|
|
315
410
|
private objectMetadata;
|
|
316
411
|
private currentContext;
|
|
412
|
+
private sections;
|
|
317
413
|
constructor();
|
|
318
414
|
use(handler: (o: Objector) => void): this;
|
|
319
415
|
includeDirectory(...dirs: string[]): this;
|
|
@@ -321,18 +417,22 @@ export declare class Objector {
|
|
|
321
417
|
include(...files: string[]): this;
|
|
322
418
|
keys(keys: FieldProcessorMap): this;
|
|
323
419
|
sources(sources: FieldProcessorMap): this;
|
|
324
|
-
variables(vars: Record<string,
|
|
420
|
+
variables(vars: Record<string, unknown>): this;
|
|
325
421
|
getOutputs(): Output[];
|
|
326
422
|
output(o: Output): this;
|
|
327
|
-
metadata(path: string, o:
|
|
328
|
-
getMetadata(path: string):
|
|
329
|
-
getAllMetadata(): Record<string,
|
|
423
|
+
metadata(path: string, o: unknown): this;
|
|
424
|
+
getMetadata(path: string): unknown;
|
|
425
|
+
getAllMetadata(): Record<string, unknown>;
|
|
426
|
+
setCacheMaxSize(size: number): this;
|
|
427
|
+
clearCache(): this;
|
|
330
428
|
getCurrentContext(): LoadContext | null;
|
|
429
|
+
fieldOptions(options: ProcessFieldsOptions): this;
|
|
430
|
+
section(section: FieldProcessorSection): this;
|
|
431
|
+
getSection(name: string): FieldProcessorSection | undefined;
|
|
331
432
|
filter(f: RegExp): this;
|
|
332
|
-
private docIncludes;
|
|
333
433
|
loadObject<T = any>(data: T, container?: any, options?: LoadObjectOptions): Promise<T>;
|
|
334
|
-
load<T =
|
|
335
|
-
|
|
434
|
+
load<T = unknown>(fileName: string, cwd?: string, container?: unknown, noProcess?: boolean, ld?: LoadContext): Promise<T | null>;
|
|
435
|
+
writeAll(option?: WriteOutputsOption): Promise<void>;
|
|
336
436
|
}
|
|
337
437
|
|
|
338
438
|
declare interface Output {
|
|
@@ -342,8 +442,34 @@ declare interface Output {
|
|
|
342
442
|
class?: string;
|
|
343
443
|
}
|
|
344
444
|
|
|
445
|
+
/**
|
|
446
|
+
* Adds indentation to each line of a string.
|
|
447
|
+
* Useful for formatting multi-line text with consistent indentation.
|
|
448
|
+
*
|
|
449
|
+
* @example
|
|
450
|
+
* padBlock('hello\\nworld', 2) // ' hello\\n world'
|
|
451
|
+
* padBlock('a|b|c', 1, '|', '-') // '-a|-b|-c'
|
|
452
|
+
*
|
|
453
|
+
* @param str - The string to indent
|
|
454
|
+
* @param indent - The number of padding units to add
|
|
455
|
+
* @param separator - The separator between lines (default: '\\n')
|
|
456
|
+
* @param padder - The character to repeat for padding (default: ' ')
|
|
457
|
+
* @returns The indented string
|
|
458
|
+
*/
|
|
345
459
|
declare const padBlock: (str: string, indent: number, separator?: string, padder?: string) => string;
|
|
346
460
|
|
|
461
|
+
/**
|
|
462
|
+
* Converts a string to PascalCase (UpperCamelCase).
|
|
463
|
+
* Handles spaces, underscores, and hyphens as word separators.
|
|
464
|
+
*
|
|
465
|
+
* @example
|
|
466
|
+
* pascal('hello_world') // 'HelloWorld'
|
|
467
|
+
* pascal('hello world') // 'HelloWorld'
|
|
468
|
+
* pascal('helloWorld') // 'HelloWorld'
|
|
469
|
+
*
|
|
470
|
+
* @param v - The string to convert
|
|
471
|
+
* @returns The string in PascalCase
|
|
472
|
+
*/
|
|
347
473
|
declare const pascal: (v: string) => string;
|
|
348
474
|
|
|
349
475
|
/**
|
|
@@ -360,28 +486,76 @@ declare interface ProcessFieldsOptions {
|
|
|
360
486
|
filters?: RegExp[];
|
|
361
487
|
root?: Record<any, any>;
|
|
362
488
|
globalContext?: any;
|
|
489
|
+
onSection?: (section: FieldProcessorSection, path: string, root: Record<string, any>, options: ProcessFieldsOptions) => Promise<void | boolean | string> | void | boolean | string;
|
|
363
490
|
}
|
|
364
491
|
|
|
365
492
|
/**
|
|
493
|
+
* Selects a value from a nested object using a path string with advanced querying capabilities
|
|
494
|
+
*
|
|
495
|
+
* Supports:
|
|
496
|
+
* - Dot notation: 'user.profile.name'
|
|
497
|
+
* - Array indexing: 'users.0' or 'users[0]'
|
|
498
|
+
* - Array filtering: 'users.[name=John].age'
|
|
499
|
+
* - References: 'users.\{activeUserId\}.name'
|
|
500
|
+
* - Optional paths: 'user.profile?.bio'
|
|
501
|
+
* - Default values: 'config.timeout?=5000'
|
|
502
|
+
*
|
|
366
503
|
* @public
|
|
367
|
-
* @param from
|
|
368
|
-
* @param path
|
|
369
|
-
* @param
|
|
370
|
-
* @returns
|
|
504
|
+
* @param from - The root object to select from
|
|
505
|
+
* @param path - The path string to navigate
|
|
506
|
+
* @param options - Optional configuration
|
|
507
|
+
* @returns The selected value or undefined
|
|
508
|
+
*
|
|
509
|
+
* @example
|
|
510
|
+
* ```typescript
|
|
511
|
+
* const obj = { user: { name: 'Alice', age: 30 } }
|
|
512
|
+
* select(obj, 'user.name') // 'Alice'
|
|
513
|
+
* select(obj, 'user.email', { defaultValue: 'N/A' }) // 'N/A'
|
|
514
|
+
* ```
|
|
371
515
|
*/
|
|
372
516
|
declare const select: <T = any>(from: any, path: string, options?: SelectOptions) => T | undefined;
|
|
373
517
|
|
|
518
|
+
/**
|
|
519
|
+
* Options for configuring the select function behavior
|
|
520
|
+
* @public
|
|
521
|
+
*/
|
|
374
522
|
declare interface SelectOptions {
|
|
523
|
+
/** Value to set at the selected path */
|
|
375
524
|
set?: any;
|
|
525
|
+
/** Alternative key to use (currently unused) */
|
|
376
526
|
key?: string;
|
|
527
|
+
/** Path separator character (default: '.') */
|
|
377
528
|
separator?: string;
|
|
529
|
+
/** Default value to return when path is not found */
|
|
378
530
|
defaultValue?: any;
|
|
531
|
+
/** If true, returns undefined instead of throwing on missing paths */
|
|
379
532
|
optional?: boolean;
|
|
380
533
|
}
|
|
381
534
|
|
|
382
|
-
|
|
535
|
+
/**
|
|
536
|
+
* Converts a string to snake_case or custom_case.
|
|
537
|
+
* Inserts the separator between lowercase and uppercase characters.
|
|
538
|
+
*
|
|
539
|
+
* @example
|
|
540
|
+
* snake('helloWorld', '_') // 'hello_world'
|
|
541
|
+
* snake('HelloWorld', '-') // 'hello-world'
|
|
542
|
+
* snake('hello world', '_') // 'hello_world'
|
|
543
|
+
*
|
|
544
|
+
* @param v - The string to convert
|
|
545
|
+
* @param separator - The separator to use between words (default: '_')
|
|
546
|
+
* @returns The string in snake case with the specified separator
|
|
547
|
+
*/
|
|
548
|
+
declare const snake: (v: string, separator?: string) => string;
|
|
383
549
|
|
|
384
550
|
/**
|
|
551
|
+
* Sorts an array by a selector function with custom comparison
|
|
552
|
+
* Uses a shallow copy to avoid mutating the original array
|
|
553
|
+
* @typeParam T - Type of array items
|
|
554
|
+
* @typeParam U - Type of comparison values
|
|
555
|
+
* @param arr - Array to sort
|
|
556
|
+
* @param selector - Function to extract comparison value from item
|
|
557
|
+
* @param compare - Comparison function (default: numeric comparison)
|
|
558
|
+
* @returns New sorted array
|
|
385
559
|
* @public
|
|
386
560
|
*/
|
|
387
561
|
declare const sortBy: <T, U>(arr: T[], selector: (item: T) => U, compare?: (a: U, b: U) => number) => T[];
|
|
@@ -420,22 +594,57 @@ declare const splitWithQuotes: (input: string, separator?: string) => {
|
|
|
420
594
|
quoted: boolean;
|
|
421
595
|
}[];
|
|
422
596
|
|
|
423
|
-
|
|
597
|
+
/**
|
|
598
|
+
* Replaces tokens in a string with values from an object.
|
|
599
|
+
* Tokens are in the format `$\{key\}`.
|
|
600
|
+
*
|
|
601
|
+
* @example
|
|
602
|
+
* tokenize('Hello $\{name\}', { name: 'World' }) // 'Hello World'
|
|
603
|
+
* tokenize('$\{greeting\} $\{name\}!', { greeting: 'Hi', name: 'Alice' }) // 'Hi Alice!'
|
|
604
|
+
* tokenize('$\{missing\}', {}) // ''
|
|
605
|
+
*
|
|
606
|
+
* @param str - The string containing tokens
|
|
607
|
+
* @param from - An object with key-value pairs for token replacement
|
|
608
|
+
* @param tokenizer - The regex pattern for token matching (default: `/\$\{([^}]+)\}/g`)
|
|
609
|
+
* @returns The string with tokens replaced by values from the object
|
|
610
|
+
*/
|
|
611
|
+
declare const tokenize: (str: string, from: Record<string, unknown>, tokenizer?: RegExp) => string;
|
|
424
612
|
|
|
425
613
|
/**
|
|
614
|
+
* Converts an object's entries into an array of objects with a key property
|
|
615
|
+
* @typeParam T - The type of items in the resulting array
|
|
616
|
+
* @param from - Object to convert
|
|
617
|
+
* @param key - Property name to use for keys (default: 'name')
|
|
618
|
+
* @returns Array of objects with key properties
|
|
619
|
+
* @example
|
|
620
|
+
* toList({ a: { value: 1 }, b: { value: 2 } }) // [{ name: 'a', value: 1 }, { name: 'b', value: 2 }]
|
|
426
621
|
* @public
|
|
427
622
|
*/
|
|
428
|
-
declare const toList: <T>(from:
|
|
623
|
+
declare const toList: <T>(from: Record<string, unknown>, key?: string) => T[];
|
|
429
624
|
|
|
430
625
|
/**
|
|
626
|
+
* Converts an array into an object indexed by a key property, excluding the key from items
|
|
627
|
+
* @typeParam T - The type of the resulting object values
|
|
628
|
+
* @param from - Array to convert
|
|
629
|
+
* @param key - Property name to use as key (default: 'name')
|
|
630
|
+
* @returns Object indexed by key values, without the key property in values
|
|
631
|
+
* @example
|
|
632
|
+
* toObject([{ name: 'a', value: 1 }]) // { a: { value: 1 } }
|
|
431
633
|
* @public
|
|
432
634
|
*/
|
|
433
|
-
declare const toObject: <T
|
|
635
|
+
declare const toObject: <T extends Record<string, unknown>>(from: T[], key?: string) => Record<string, Omit<T, typeof key>>;
|
|
434
636
|
|
|
435
637
|
/**
|
|
638
|
+
* Converts an array into an object indexed by a key property, keeping the full items
|
|
639
|
+
* @typeParam T - The type of the resulting object
|
|
640
|
+
* @param from - Array to convert
|
|
641
|
+
* @param key - Property name to use as key (default: 'name')
|
|
642
|
+
* @returns Object indexed by key values
|
|
643
|
+
* @example
|
|
644
|
+
* toObjectWithKey([{ name: 'a', value: 1 }]) // { a: { name: 'a', value: 1 } }
|
|
436
645
|
* @public
|
|
437
646
|
*/
|
|
438
|
-
declare const toObjectWithKey: <T
|
|
647
|
+
declare const toObjectWithKey: <T extends Record<string, unknown>>(from: T[], key?: string) => Record<string, T>;
|
|
439
648
|
|
|
440
649
|
declare const writeFormat: (filePath: string, content: any, format?: "yaml" | "json" | "text") => Promise<void>;
|
|
441
650
|
|
package/dist/index.js
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
var st=Object.create;var{getPrototypeOf:it,defineProperty:W,getOwnPropertyNames:re}=Object;var te=Object.prototype.hasOwnProperty,u=(e,r,t)=>{for(let o of re(r))if(!te.call(e,o)&&o!=="default")W(e,o,{get:()=>r[o],enumerable:!0});if(t){for(let o of re(r))if(!te.call(t,o)&&o!=="default")W(t,o,{get:()=>r[o],enumerable:!0});return t}},m=(e,r,t)=>{t=e!=null?st(it(e)):{};let o=r||!e||!e.__esModule?W(t,"default",{value:e,enumerable:!0}):t;for(let n of re(e))if(!te.call(o,n))W(o,n,{get:()=>e[n],enumerable:!0});return o};var I=(e,r)=>()=>(r||e((r={exports:{}}).exports,r),r.exports);var C=(e,r)=>{for(var t in r)W(e,t,{get:r[t],enumerable:!0,configurable:!0,set:(o)=>r[t]=()=>o})};var Y=I((no,Oe)=>{var{defineProperty:oe,getOwnPropertyNames:lt,getOwnPropertyDescriptor:ut}=Object,ft=Object.prototype.hasOwnProperty,ke=new WeakMap,pt=(e)=>{var r=ke.get(e),t;if(r)return r;if(r=oe({},"__esModule",{value:!0}),e&&typeof e==="object"||typeof e==="function")lt(e).map((o)=>!ft.call(r,o)&&oe(r,o,{get:()=>e[o],enumerable:!(t=ut(e,o))||t.enumerable}));return ke.set(e,r),r},mt=(e,r)=>{for(var t in r)oe(e,t,{get:r[t],enumerable:!0,configurable:!0,set:(o)=>r[t]=()=>o})},Ae={};mt(Ae,{splitWithQuotes:()=>yt,splitNested:()=>ct});Oe.exports=pt(Ae);var ct=(e,r,t="(",o=")")=>{let n=0,a="",i=[];for(let s of e){if(a+=s,s===t)n++;if(s===o)n--;if(n===0&&s===r)i.push(a.slice(0,-1)),a=""}if(a)i.push(a);return i},yt=(e,r=",")=>{let t=[],o=e.length,n=r.length,a=0,i=(s)=>{if(s+n>o)return!1;for(let f=0;f<n;f++)if(e[s+f]!==r[f])return!1;return!0};while(a<o){while(a<o&&e[a]===" ")a++;if(a>=o)break;let s="",f=e[a]==='"'||e[a]==="'";if(f){let c=e[a++];while(a<o&&e[a]!==c)s+=e[a++];if(a<o)a++}else{while(a<o&&!i(a)){let c=e[a];if(c==='"'||c==="'"){s+=c,a++;while(a<o&&e[a]!==c)s+=e[a++];if(a<o)s+=e[a++]}else s+=e[a++]}s=s.trim()}if(s)t.push({value:s,quoted:f});if(i(a))a+=n}return t}});var w=I((ao,Ce)=>{var{defineProperty:ne,getOwnPropertyNames:gt,getOwnPropertyDescriptor:dt}=Object,wt=Object.prototype.hasOwnProperty,Me=new WeakMap,bt=(e)=>{var r=Me.get(e),t;if(r)return r;if(r=ne({},"__esModule",{value:!0}),e&&typeof e==="object"||typeof e==="function")gt(e).map((o)=>!wt.call(r,o)&&ne(r,o,{get:()=>e[o],enumerable:!(t=dt(e,o))||t.enumerable}));return Me.set(e,r),r},vt=(e,r)=>{for(var t in r)ne(e,t,{get:r[t],enumerable:!0,configurable:!0,set:(o)=>r[t]=()=>o})},$e={};vt($e,{navigate:()=>Ne,find:()=>ht,NavigateResult:()=>h,NavigateAction:()=>Pe});Ce.exports=bt($e);var Pe;((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"})(Pe||={});class h{action;by;skipSibilings;reexplore;constructor(e,r,t,o){this.action=e,this.by=r,this.skipSibilings=t,this.reexplore=o}static ReplaceParent(e,r){return new h(3,e,void 0,r)}static SkipSiblings(){return new h(1)}static Explore(){return new h(0)}static NoExplore(){return new h(2)}static DeleteParent(){return new h(4)}static MergeParent(e){return new h(5,e)}static ReplaceItem(e,r){return new h(6,e,r)}static DeleteItem(e){return new h(7,void 0,e)}}var Ne=async(e,r)=>{let t=async(n)=>{let a=n.key===null,i=a?{action:0}:await r(n);if(n.value&&typeof n.value==="object"&&i.action==0){if(!a)n.path.push(n.key),n.parents.push(n.parent);while(await o(n));if(!a)n.parents.pop(),n.path.pop()}return i},o=async(n)=>{for(let[a,i]of Object.entries(n.value)){let s=await t({key:a,value:i,path:n.path,parent:n.value,parents:n.parents});switch(s.action){case 3:if(!n.key)throw Error("Cannot replace root");if(n.parent[n.key]=s.by,s.reexplore)return n.value=s.by,!0;return;case 4:delete n.parent[n.key];return;case 5:delete n.value[a],Object.assign(n.value,s.by);break;case 1:return;case 6:if(n.value[a]=s.by,s.skipSibilings)return;break;case 7:if(delete n.value[a],s.skipSibilings)return;break}}};await t({key:null,value:e,path:[],parent:null,parents:[]})},ht=async(e,r)=>{let t=[];return await Ne(e,(o)=>{if(r([...o.path,o.key].join("."),o.value))t.push(o.value);return h.Explore()}),t}});var b=I((so,je)=>{var{defineProperty:se,getOwnPropertyNames:kt,getOwnPropertyDescriptor:At}=Object,Ot=Object.prototype.hasOwnProperty,Re=new WeakMap,Mt=(e)=>{var r=Re.get(e),t;if(r)return r;if(r=se({},"__esModule",{value:!0}),e&&typeof e==="object"||typeof e==="function")kt(e).map((o)=>!Ot.call(r,o)&&se(r,o,{get:()=>e[o],enumerable:!(t=At(e,o))||t.enumerable}));return Re.set(e,r),r},$t=(e,r)=>{for(var t in r)se(e,t,{get:r[t],enumerable:!0,configurable:!0,set:(o)=>r[t]=()=>o})},Ee={};$t(Ee,{select:()=>ie});je.exports=Mt(Ee);var Pt=Y(),ae=(e,r,t,o)=>{if(e.startsWith("{")){let n=e.substring(1,e.length-1);return ie(r,n,t).toString()}return o?e:void 0},Nt=(e,r,t,o)=>{let n=ae(r,t,o);if(n)return ie(e,n,o);let a=/^\[([^=\]]*)([=]*)([^\]]*)\]$/.exec(r);if(a){let[s,f,c,p]=a,y=ae(f.trim(),t,o,!0),P=ae(p.trim(),t,o,!0);if(Array.isArray(e))switch(c){case"==":case"=":return e.find((O)=>O[y]==P)}}let i=/^([^[\]]*)\[([^\]]*)]/.exec(r);if(i)return e[i[1]][i[2]];return e[r]},ie=(e,r,t)=>{let o=void 0,n=void 0;r??="";let a=(p)=>p?.endsWith("?")?[p.substring(0,p.length-1),!0]:[p,!1],i=(p,y)=>{let[P,O]=a(y.pop());if(P){let K=Nt(p,P,e,t);if(K===void 0){if(O||t?.defaultValue!==void 0||t?.optional)return;throw Error(`Unknown path element: "${P}" in "${r}"`)}return o=p,n=P,i(K,y)}if(t?.set&&n)o[n]=t?.set;return p},s=Pt.splitNested(r,t?.separator??".","{","}"),f=s.length>0&&s[s.length-1].startsWith("?=")?s.pop()?.substring(2):void 0;s.reverse();let c=i(e,s);if(c===void 0)return f??t?.defaultValue;return c}});var v=I((io,Ye)=>{var{defineProperty:le,getOwnPropertyNames:Ct,getOwnPropertyDescriptor:Rt}=Object,Et=Object.prototype.hasOwnProperty,De=new WeakMap,jt=(e)=>{var r=De.get(e),t;if(r)return r;if(r=le({},"__esModule",{value:!0}),e&&typeof e==="object"||typeof e==="function")Ct(e).map((o)=>!Et.call(r,o)&&le(r,o,{get:()=>e[o],enumerable:!(t=Rt(e,o))||t.enumerable}));return De.set(e,r),r},Dt=(e,r)=>{for(var t in r)le(e,t,{get:r[t],enumerable:!0,configurable:!0,set:(o)=>r[t]=()=>o})},Te={};Dt(Te,{processFields:()=>Ke,makeFieldProcessorMap:()=>xt,makeFieldProcessorList:()=>St,makeFieldProcessor:()=>pe,getProcessor:()=>ue,getArgs:()=>Se});Ye.exports=jt(Te);var Lt=Y(),Le=w(),_e=b(),We=(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((o)=>{let n=o.trim();if(!isNaN(+n))return+n;return n})}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)},H=(e,r,t,o,n,a)=>{let i=o?.(e)??e,s=n(i);if(s[0])return s[1];if(!r){let f=_e.select(t,e),c=n(f);if(c[0])return c[1]}throw Error(a)},Ue=(e,r,t,o,n)=>{let a=typeof e.types==="function"?e.types(o,r.value,n):e.types?.[o];if(!a||a==="ref")return We(r,(s)=>_e.select(t,s));let i=We(r,()=>r.value);if(Array.isArray(a)){if(!a.includes(i))throw Error(`Argument ${o.toString()} must be one of [${a.join(", ")}]: ${i}`);return i}if(typeof a==="string"){if(a.endsWith("?")){let s=a.slice(0,-1);if(r.value==="null")return Le.NavigateResult.ReplaceItem(null);if(r.value==="undefined")return Le.NavigateResult.ReplaceItem(void 0);if(r.value==="")return"";a=s}switch(a){case"any":return i;case"array":return H(i,r.quoted,t,null,(s)=>[Array.isArray(s),s],`Argument ${o.toString()} must be an array: ${i}`);case"object":return H(i,r.quoted,t,null,(s)=>[typeof s==="object"&&s!==null,s],`Argument ${o.toString()} must be an object: ${i}`);case"number":return H(i,r.quoted,t,(s)=>Number(s),(s)=>[!isNaN(s),s],`Argument ${o.toString()} must be a number: ${i}`);case"boolean":return H(i,r.quoted,t,null,(s)=>{if([!0,"true","1",1,"yes","on"].includes(s))return[!0,!0];if([!1,"false","0",0,"no","off"].includes(s))return[!0,!1];if([null,"null","undefined",void 0,""].includes(s))return[!0,!1];if(Array.isArray(s))return[!0,s.length>0];return[!1,!1]},`Argument ${o.toString()} must be a boolean: ${i}`);case"string":return i.toString();default:throw Error(`Unknown type for argument ${o.toString()}: ${a}`)}}return a(i,t,o,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}},Je=(e)=>!e.quoted&&e.value.startsWith("."),Wt=(e)=>{let r={};for(let t of e){if(!Je(t))continue;let o=t.value.indexOf("="),n=o>-1?t.value.slice(1,o):t.value.slice(1),a=o>-1?t.value.slice(o+1):"";if(a.length>=2){let i=a[0],s=a[a.length-1];if(i==='"'&&s==='"'||i==="'"&&s==="'")a=a.slice(1,-1)}if(!r[n])r[n]=[];r[n].push(a)}return r},Se=(e,r,t)=>{let o=Lt.splitWithQuotes(e??""),n=Wt(o),a=o.filter((s)=>!Je(s)),i=r.options.processArgs===!1?[]:a.map((s,f)=>Ue(r.options,s,t,f,a));return{rawArgs:a,parsedArgs:i,tags:n}},R=w(),Ie=w(),It=(e,r)=>r.keys!==void 0&&e.key.startsWith(".")&&r.keys[e.key.substring(1)]!==void 0,Tt=async(e,r,t,o)=>{let{key:n,parent:a}=e,i=ue(o.keys,n.substring(1));if(i.options.processArgs!==!1&&(typeof i.options.types==="function"||i.options.types?.[0]!==void 0))e.value=Ue(i.options,{value:e.value,quoted:!1},t,0,[]);if(typeof e.value!=="string")await Ke(e.value,{...o,root:{...t,parent:e.parent,parents:e.parents},filters:[...o.filters??[],...i.options.filters??[]]});let s=await i.fn({path:r,root:t,parent:a,key:n,options:o,value:e.value,args:[e.value],rawArgs:[],tags:{}});return s instanceof Ie.NavigateResult?s:Ie.NavigateResult.ReplaceParent(s)},Q=w(),_t=b(),xe=(e)=>{let r=[],t=0;while(t<e.length)if(e[t]==="$"&&e[t+1]==="("&&(t===0||e[t-1]!=="\\")){let o=t;t+=2;let n=1;for(;t<e.length;t++)if(e[t]==="(")n++;else if(e[t]===")"){if(n--,n===0){r.push([o,t]);break}}if(n!==0)throw Error(`Unmatched opening $( at position ${o.toString()}`);t++}else t++;return r};class fe{value;constructor(e){this.value=e}}var Be=async(e,r,t)=>{for(let o=r.length-1;o>=0;o--){let[n,a]=r[o],i=e.slice(n+2,a),s=await Be(i,xe(i),t);if(typeof s==="object")return s;let f=await t(s,e);if(f instanceof fe)return f.value;e=e.slice(0,n)+f+e.slice(a+1)}return e},Ut=async(e,r)=>Be(e,xe(e),r),Jt=async(e,r,t,o)=>{let n=await(async()=>{let a=/([\w\d.-_/]+):(.+)/.exec(e);if(!a)return await _t.select(r,e);let[i,s,f]=a,c=ue(o.sources,s),p=Se(f,c,r);return await c.fn({args:p.parsedArgs,rawArgs:p.rawArgs,tags:p.tags,key:s,options:o,root:r,path:t,value:null})})();if(n===null||n===void 0)return"";if(typeof n==="object")return new fe(n);return n},Ge=async(e,r,t,o)=>{let n=await Ut(r,(a)=>Jt(a,t,e,o));if(n instanceof Q.NavigateResult)return n;if(n===r)return Q.NavigateResult.Explore();if(typeof n==="string"){let a=await Ge(e,n,t,o);if(a.action!==Q.NavigateAction.Explore)return a}return Q.NavigateResult.ReplaceItem(n)},Ke=async(e,r)=>{return r??={},await R.navigate(e,async(t)=>{let o=[...t.path,t.key].join(".");if(r?.filters?.length&&r.filters.some((s)=>s.test(o)))return R.NavigateResult.NoExplore();let n=t.path.length===0,a=t.parents.length>0?t.parents.toReversed():[];if(n){if(a.length>0)throw Error("Root object should not have a parent");a=r?.root?.parents?[r.root.parent,...r.root.parents.toReversed()]:[]}let i={...e,...r.root,this:t.parent,parent:a.length>0?a[0]:null,parents:a};try{if(t.key.startsWith("$"))return R.NavigateResult.NoExplore();let s=R.NavigateResult.Explore();if(typeof t.value==="string")switch(s=await Ge(o,t.value,i,r),s.action){case R.NavigateAction.Explore:break;case R.NavigateAction.ReplaceItem:t.value=s.by;break;default:return s}if(It(t,r))s=await Tt(t,o,i,r);return s}catch(s){throw Error(`${s.message}
|
|
2
|
-
(${o})`)}}),e},pe=(e,r)=>r?{fn:(t)=>e(...t.args),types:r}:(t)=>e(...t.args),St=(e,r)=>Object.fromEntries(e.map((t)=>[t.name,pe(t,r?.types?.[t.name])])),xt=(e,r)=>Object.fromEntries((r?.keys??Object.keys(e)).map((t)=>[t,pe(e[t],r?.types?.[t])]))});var S=I((sn,Wr)=>{var{defineProperty:be,getOwnPropertyNames:Yt,getOwnPropertyDescriptor:Ht}=Object,Qt=Object.prototype.hasOwnProperty,jr=new WeakMap,Zt=(e)=>{var r=jr.get(e),t;if(r)return r;if(r=be({},"__esModule",{value:!0}),e&&typeof e==="object"||typeof e==="function")Yt(e).map((o)=>!Qt.call(r,o)&&be(r,o,{get:()=>e[o],enumerable:!(t=Ht(e,o))||t.enumerable}));return jr.set(e,r),r},Xt=(e,r)=>{for(var t in r)be(e,t,{get:r[t],enumerable:!0,configurable:!0,set:(o)=>r[t]=()=>o})},Dr={};Xt(Dr,{tokenize:()=>ro,snake:()=>qt,pascal:()=>Lr,padBlock:()=>eo,changeCase:()=>zt,capital:()=>Vt,camel:()=>Ft});Wr.exports=Zt(Dr);var Lr=(e)=>e.replace(/((?:[_ ]+)\w|^\w)/g,(r,t)=>t.toUpperCase()).replace(/[_ ]/g,""),Vt=(e)=>e.replace(/((?:[ ]+)\w|^\w)/g,(r,t)=>t.toUpperCase()),Ft=(e)=>Lr(e).replace(/((?:[ ]+\w)|^\w)/g,(r,t)=>t.toLowerCase()),qt=(e,r)=>e.replace(/([a-z])([A-Z])/g,`$1${r}$2`).replace(/\s+/g,r),zt=(e,r)=>{switch(r){case"upper":return e.toUpperCase();case"lower":return e.toLowerCase();default:return e}},eo=(e,r,t=`
|
|
3
|
-
`,o=" ")=>{let n=o.repeat(r);return e.split(t).map((a)=>n+a).join(t)},ro=(e,r,t=/\${([^}]+)}/g)=>{return e.replace(t,(o,n)=>r[n]??"")}});var at=m(v(),1);var ze={};C(ze,{writeOutputs:()=>V,writeOutput:()=>ye,writeFormat:()=>ce,locate:()=>E,loadFormat:()=>Z,importList:()=>ge,importGlob:()=>qe,globMap:()=>X,exists:()=>T});import He from"fs/promises";import me from"path";import Bt from"path";import Gt from"fs/promises";import Ve from"fs/promises";import Qe from"path";import Ze from"path";import Xe from"path";var T=async(e)=>{try{return await He.access(e,He.constants.R_OK),!0}catch{return!1}},E=async(e,r)=>{let t=!me.isAbsolute(e)&&r?["",...r]:[""];for(let o of t){let n=me.join(o,e);if(await T(n))return me.resolve(n)}throw Error(`File not found: "${e}"`)},Z=async(e,r)=>{let t=await E(e,r?.dirs),o=await Bun.file(t).text(),n=Bt.dirname(t),a={"[.]json$":JSON.parse,"[.](yml|yaml)$":Bun.YAML.parse,"[.]toml$":Bun.TOML.parse,...r?.parsers},i=Object.entries(a).find((s)=>t.match(s[0]));if(!i)throw Error(`Unhandled file type: ${e}`);return{content:i[1](o),fullPath:t,folderPath:n}},ce=async(e,r,t="text")=>{switch(t){case"yaml":await Bun.write(e,Bun.YAML.stringify(r));break;case"json":await Bun.write(e,JSON.stringify(r));break;case"text":default:await Bun.write(e,r.toString())}},X=async(e,r)=>{if(typeof e==="string"&&!e.includes("*"))return await r.map(e,0,[]);let t=await Array.fromAsync(Gt.glob(e,{cwd:r.cwd})),o=r.filter?t.filter(r.filter):t;return await Promise.all(o.map(r.map))},V=async(e,r)=>{if(r?.targetDirectory&&r?.removeFirst)try{await Ve.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 ye(t,r)},ye=async(e,r)=>{let t=Qe.join(r?.targetDirectory??".",e.name),o=Qe.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 Ve.mkdir(o,{recursive:!0})}catch(n){throw Error(`Failed to create target directory "${o}" for output "${t}": ${n.message}`)}try{await ce(t,e.value,e.type??"text")}catch(n){throw Error(`Failed to write output "${t}": ${n.message}`)}},Fe=(e)=>e?Xe.isAbsolute(e)?e:Xe.join(process.cwd(),e):process.cwd(),ge=async(e,r)=>{let t=[];for(let o of e)try{let n=!Ze.isAbsolute(o)?Ze.join(Fe(r?.cwd),o):o;if(r?.filter?.(n)===!1)continue;let a=await import(n);if(r?.resolveDefault==="only"&&!a.default)throw Error(`Module ${o} does not have a default export`);let i=r?.resolveDefault?a.default??a:a,s=r?.map?await r.map(i,o):i;if(s!==void 0)t.push(s)}catch(n){if(r?.fail?.(o,n)===!1)continue;throw Error(`Failed to import module ${o}: ${n.message??n}`)}return t},qe=async(e,r)=>{let t=[];for(let o of e){let n=await Array.fromAsync(new Bun.Glob(o).scan({cwd:Fe(r?.cwd),absolute:!0}));t.push(...await ge(n,r))}return t};var er={};C(er,{mergeAll:()=>_,merge:()=>M});var M=(e,r,t)=>{for(let o of Object.keys(r)){if(e[o]===void 0)continue;let n=r[o],a=e[o];if(typeof a!==typeof n||Array.isArray(a)!==Array.isArray(n)){let s=t?.mismatch?.(o,a,n,e,r);if(s!==void 0){r[o]=s;continue}throw Error(`Type mismatch: ${o}`)}let i=t?.mode?.(o,a,n,e,r)??r[".merge"]??"merge";switch(i){case"source":r[o]=a;continue;case"target":continue;case"skip":delete r[o],delete e[o];continue;case"merge":break;default:throw Error(`Unknown merge mode: ${i}`)}if(typeof a==="object")if(Array.isArray(a))n.push(...a);else{if(t?.navigate?.(o,a,n,e,r)===!1)continue;M(a,n,t)}else{if(a===n)continue;let s=t?.conflict?.(o,a,n,e,r);r[o]=s===void 0?n:s}}for(let o of Object.keys(e))if(r[o]===void 0)r[o]=e[o]},_=(e,r)=>{let t={};for(let o of e.toReversed())M(o,t,r);return t};import z from"path";var rr=m(w(),1),tr=(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 rr.NavigateResult.SkipSiblings()}});var or=m(w(),1);import Kt from"path";var nr=(e)=>({load:async(r)=>{let t=r.options.globalContext;for(let{file:o}of Array.isArray(r.value)?r.value:[r.value]){if(!o)throw Error("File reference required");await e.load(o,t.file&&Kt.dirname(t.file))}return or.NavigateResult.DeleteItem()}});var cr=m(v(),1);var ar=m(b(),1),sr=(e)=>{if(typeof e.value==="string")return e.parent;let r=e.value.model;if(!r)return e.parent;if(typeof r==="string")return ar.select(e.root,r);return r};var de=m(b(),1),ir=(e)=>{if(typeof e.value==="string")return de.select(e.root,e.value);if(Array.isArray(e.value))return e.value;let r=e.value;if(typeof r.from==="string")return de.select(e.root,r.from);return r.from};var lr=m(v(),1),ur=m(b(),1),fr=async(e,r)=>{let t=e.value;if(t.selector===void 0)return r;if(typeof t.selector!=="string"){let o=JSON.parse(JSON.stringify(t.selector));return await lr.processFields(o,{...e.options,root:{...e.root,result:r}}),o}return await ur.select({...e.root,result:r},t.selector)};var pr={};C(pr,{deepClone:()=>k});var k=(e)=>globalThis.structuredClone!==void 0?structuredClone(e):JSON.parse(JSON.stringify(e));var mr={};C(mr,{conditionPredicatesTypes:()=>U,conditionPredicates:()=>A});var A={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)=>!A.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!=="")},U={and:()=>"boolean",or:()=>"boolean",xor:()=>"boolean",true:()=>"boolean",false:()=>"boolean",lt:()=>"number",le:()=>"number",gt:()=>"number",ge:()=>"number"};var yr=()=>({each:{filters:[/select|model/],fn:async(e)=>{let r=e.value;delete e.parent[e.key];let t=await ir(e),o=await sr(e);if(!Array.isArray(t))throw Error('Key "each" requires a source list');if(o===void 0)throw Error('Key "each" must define a model');if(r.extend?.model)o=_([r.model,...Array.isArray(r.extend.model)?r.extend.model:[r.extend.model]]);let n=[];for(let a=0;a<t.length;a++){let i=k(o);if(await cr.processFields(i,{...e.options,root:{...e.root,index:a,item:t[a],instance:i}}),r.extend?.result){let s=r.extend.result;i=_([i,...Array.isArray(s)?s:[s]])}n.push(await fr(e,i))}return n}}});var gr=m(b(),1),dr=()=>({concat:async(e)=>{let r=[];for(let t of Array.isArray(e.value)?e.value:[e.value])r.push(...await gr.select(e.root,t));return r.filter((t)=>t!==void 0)}});var wr=m(v(),1);var we=m(w(),1),br=m(b(),1);var vr=()=>({extends:async(e)=>{let r=async(t,o)=>{for(let n of Array.isArray(o)?o:[o]){let a=await br.select(e.root,n),i=k(a);if(i[e.key])await r(i,i[e.key]);await wr.processFields(i,{...e.options}),M(i,t),delete t[e.key]}};return await r(e.parent,e.value),we.NavigateResult.Explore()},group:(e)=>{let r=e.root.parent,t=e.value,{items:o,...n}=t;return t.items.forEach((a)=>r.push({...n,...a})),we.NavigateResult.DeleteParent()}});var hr=m(v(),1),$=m(w(),1),kr=(e)=>({skip:{types:{0:"boolean"},fn:(r)=>r.value?$.NavigateResult.DeleteParent():$.NavigateResult.DeleteItem()},metadata:({path:r,value:t})=>{return e.metadata(r,t),$.NavigateResult.DeleteItem()},if:{types:{0:"boolean"},fn:async(r)=>{let t=r.parent[".then"],o=r.parent[".else"];if(t!==void 0)delete r.parent[".then"];if(o!==void 0)delete r.parent[".else"];let n=r.value?t:o;if(n===void 0)return $.NavigateResult.DeleteItem();if(typeof n==="string")return(await hr.processFields({value:n},{...r.options,root:{...r.root}})).value;return $.NavigateResult.ReplaceParent(n,!0)}},switch:(r)=>{let t=r.value;if(!t.cases)throw Error("Missing cases for switch");if(t.cases[t.from]!==void 0)return $.NavigateResult.ReplaceParent(t.cases[t.from],!0);if(t.default!==void 0)return $.NavigateResult.ReplaceParent(t.default,!0);return $.NavigateResult.DeleteParent()}});var Ar=m(b(),1),Or=()=>({from:async({root:e,parent:r,value:t})=>{let o=await Ar.select(e,t);if(o===null||o===void 0)throw Error(`Unable to resolve reference: ${t}`);if(r.content){if(Array.isArray(r.content)&&Array.isArray(o))return[...o,...r.content];return M(o,r.content),r.content}return o}});var $r=m(w(),1);import Mr from"node:vm";var Pr=(e)=>({modules:async(r)=>{for(let[t,o]of Object.entries(r.value)){let n=Mr.createContext({console,objector:e,document:r.root}),a=new Mr.SourceTextModule(o,{identifier:t,context:n});await a.link((i)=>{throw Error(`Module ${i} is not allowed`)}),await a.evaluate(),e.sources(Object.fromEntries(Object.entries(a.namespace).map(([i,s])=>[`${t}.${i}`,(f)=>s(f,...f.args)])))}return $r.NavigateResult.DeleteItem()}});import Nr from"fs/promises";import J from"path";var Cr=(e)=>({include:async(r)=>{let{file:t}=r.options.globalContext;return await X(r.args[0],{cwd:J.dirname(t),filter:(o)=>J.basename(t)!==o,map:async(o)=>e.load(o,J.dirname(t),{parent:r.root})})},exists:async({args:[r]})=>await T(r),file:async(r)=>await Nr.readFile(await E(r.args[0],e.getIncludeDirectories())).then((t)=>t.toString()),scan:async(r)=>{let t=[],n=(()=>{let s=r.args[2]??["**/node_modules/**"],f=typeof s==="string"?s.split(",").map((c)=>c.trim()):s;if(!Array.isArray(f))throw Error("Scan exclusion must be a list");return f})(),{file:a}=r.options.globalContext,i=r.args[1]?await E(r.args[1],e.getIncludeDirectories()):J.dirname(a);for await(let s of Nr.glob(r.args[0],{cwd:i,exclude:(f)=>n.some((c)=>J.matchesGlob(f,c))}))t.push(s);return t}});var Rr=m(v(),1),Er=()=>Rr.makeFieldProcessorMap({env:(e)=>process.env[e]});var Ir=m(v(),1),d=m(S(),1);var F=(e,r=0,t)=>{let o=" ".repeat(r),n=" ".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`[
|
|
4
|
-
${e.map((
|
|
1
|
+
var Mr=Object.create;var{getPrototypeOf:jr,defineProperty:U,getOwnPropertyNames:ae}=Object;var le=Object.prototype.hasOwnProperty,M=(e,r,t)=>{for(let o of ae(r))if(!le.call(e,o)&&o!=="default")U(e,o,{get:()=>r[o],enumerable:!0});if(t){for(let o of ae(r))if(!le.call(t,o)&&o!=="default")U(t,o,{get:()=>r[o],enumerable:!0});return t}},Nr=(e,r,t)=>{t=e!=null?Mr(jr(e)):{};let o=r||!e||!e.__esModule?U(t,"default",{value:e,enumerable:!0}):t;for(let i of ae(e))if(!le.call(o,i))U(o,i,{get:()=>e[i],enumerable:!0});return o};var Wr=(e,r)=>()=>(r||e((r={exports:{}}).exports,r),r.exports);var W=(e,r)=>{for(var t in r)U(e,t,{get:r[t],enumerable:!0,configurable:!0,set:(o)=>r[t]=()=>o})};var _r=Wr((ri,Fr)=>{var{defineProperty:Ee,getOwnPropertyNames:Ot,getOwnPropertyDescriptor:At}=Object,$t=Object.prototype.hasOwnProperty,$r=new WeakMap,St=(e)=>{var r=$r.get(e),t;if(r)return r;if(r=Ee({},"__esModule",{value:!0}),e&&typeof e==="object"||typeof e==="function")Ot(e).map((o)=>!$t.call(r,o)&&Ee(r,o,{get:()=>e[o],enumerable:!(t=At(e,o))||t.enumerable}));return $r.set(e,r),r},Ft=(e,r)=>{for(var t in r)Ee(e,t,{get:r[t],enumerable:!0,configurable:!0,set:(o)=>r[t]=()=>o})},Sr={};Ft(Sr,{splitWithQuotes:()=>Mt,splitNested:()=>_t});Fr.exports=St(Sr);var _t=(e,r,t="(",o=")")=>{let i=0,n="",a=[];for(let s of e){if(n+=s,s===t)i++;if(s===o)i--;if(i===0&&s===r)a.push(n.slice(0,-1)),n=""}if(n)a.push(n);return a},Mt=(e,r=",")=>{let t=[],o=e.length,i=r.length,n=0,a=(s)=>{if(s+i>o)return!1;for(let u=0;u<i;u++)if(e[s+u]!==r[u])return!1;return!0};while(n<o){while(n<o&&e[n]===" ")n++;if(n>=o)break;let s="",u=e[n]==='"'||e[n]==="'";if(u){let m=e[n++];while(n<o&&e[n]!==m)s+=e[n++];if(n<o)n++}else{while(n<o&&!a(n)){let m=e[n];if(m==='"'||m==="'"){s+=m,n++;while(n<o&&e[n]!==m)s+=e[n++];if(n<o)s+=e[n++]}else s+=e[n++]}s=s.trim()}if(s)t.push({value:s,quoted:u});if(a(n))n+=i}return t}});var We={};W(We,{processFields:()=>$,makeFieldProcessorMap:()=>F,makeFieldProcessorList:()=>Ne,makeFieldProcessor:()=>z,getProcessor:()=>q,getArgs:()=>pe});var Cr=Object.create,{getPrototypeOf:Rr,defineProperty:Oe,getOwnPropertyNames:xr}=Object,Lr=Object.prototype.hasOwnProperty,Ir=(e,r,t)=>{t=e!=null?Cr(Rr(e)):{};let o=r||!e||!e.__esModule?Oe(t,"default",{value:e,enumerable:!0}):t;for(let i of xr(e))if(!Lr.call(o,i))Oe(o,i,{get:()=>e[i],enumerable:!0});return o},Ur=(e,r)=>()=>(r||e((r={exports:{}}).exports,r),r.exports),Dr=Ur((e,r)=>{var{defineProperty:t,getOwnPropertyNames:o,getOwnPropertyDescriptor:i}=Object,n=Object.prototype.hasOwnProperty,a=new WeakMap,s=(l)=>{var c=a.get(l),b;if(c)return c;if(c=t({},"__esModule",{value:!0}),l&&typeof l==="object"||typeof l==="function")o(l).map((p)=>!n.call(c,p)&&t(c,p,{get:()=>l[p],enumerable:!(b=i(l,p))||b.enumerable}));return a.set(l,c),c},u=(l,c)=>{for(var b in c)t(l,b,{get:c[b],enumerable:!0,configurable:!0,set:(p)=>c[b]=()=>p})},m={};u(m,{splitWithQuotes:()=>g,splitNested:()=>y}),r.exports=s(m);var y=(l,c,b="(",p=")")=>{let d=0,f="",k=[];for(let w of l){if(f+=w,w===b)d++;if(w===p)d--;if(d===0&&w===c)k.push(f.slice(0,-1)),f=""}if(f)k.push(f);return k},g=(l,c=",")=>{let b=[],p=l.length,d=c.length,f=0,k=(w)=>{if(w+d>p)return!1;for(let E=0;E<d;E++)if(l[w+E]!==c[E])return!1;return!0};while(f<p){while(f<p&&l[f]===" ")f++;if(f>=p)break;let w="",E=l[f]==='"'||l[f]==="'";if(E){let A=l[f++];while(f<p&&l[f]!==A)w+=l[f++];if(f<p)f++}else{while(f<p&&!k(f)){let A=l[f];if(A==='"'||A==="'"){w+=A,f++;while(f<p&&l[f]!==A)w+=l[f++];if(f<p)w+=l[f++]}else w+=l[f++]}w=w.trim()}if(w)b.push({value:w,quoted:E});if(k(f))f+=d}return b}}),Br=Ir(Dr(),1),H;((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"})(H||={});class O{action;by;skipSiblings;reexplore;constructor(e,r,t,o){this.action=e,this.by=r,this.skipSiblings=t,this.reexplore=o}static _explore=new O(0);static _noExplore=new O(2);static _skipSiblings=new O(1);static _deleteParent=new O(4);static ReplaceParent(e,r){return new O(3,e,void 0,r)}static SkipSiblings(){return O._skipSiblings}static Explore(){return O._explore}static NoExplore(){return O._noExplore}static DeleteParent(){return O._deleteParent}static MergeParent(e){return new O(5,e)}static ReplaceItem(e,r){return new O(6,e,r)}static DeleteItem(e){return new O(7,void 0,e)}}var Jr=async(e,r)=>{let t=new WeakSet,o=[],i=[],n=async(s,u,m)=>{let y=s===null,g=y?O.Explore():await r({key:s,value:u,path:o,parent:m,parents:i});if(u&&typeof u==="object"&&g.action===0){if(t.has(u))return g;if(t.add(u),!y)o.push(s),i.push(m);let l=u;while(await a(l,s,m))l=m[s];if(!y)i.pop(),o.pop()}return g},a=async(s,u,m)=>{let y=Object.keys(s),g=y.length;for(let l=0;l<g;l++){let c=y[l],b=s[c],p=await n(c,b,s),d=p.action;if(d===0||d===2)continue;if(d===6){if(s[c]=p.by,p.skipSiblings)return;continue}if(d===7){if(delete s[c],p.skipSiblings)return;continue}if(d===1)return;if(d===3){if(u===null)throw Error("Cannot replace root object");if(m[u]=p.by,p.reexplore)return!0;return}if(d===4){if(u===null)throw Error("Cannot delete root object");delete m[u];return}if(d===5)delete s[c],Object.assign(s,p.by)}};await n(null,e,null)},Yr=Object.create,{getPrototypeOf:Tr,defineProperty:Ae,getOwnPropertyNames:Qr}=Object,Gr=Object.prototype.hasOwnProperty,Kr=(e,r,t)=>{t=e!=null?Yr(Tr(e)):{};let o=r||!e||!e.__esModule?Ae(t,"default",{value:e,enumerable:!0}):t;for(let i of Qr(e))if(!Gr.call(o,i))Ae(o,i,{get:()=>e[i],enumerable:!0});return o},Zr=(e,r)=>()=>(r||e((r={exports:{}}).exports,r),r.exports),Vr=Zr((e,r)=>{var{defineProperty:t,getOwnPropertyNames:o,getOwnPropertyDescriptor:i}=Object,n=Object.prototype.hasOwnProperty,a=new WeakMap,s=(l)=>{var c=a.get(l),b;if(c)return c;if(c=t({},"__esModule",{value:!0}),l&&typeof l==="object"||typeof l==="function")o(l).map((p)=>!n.call(c,p)&&t(c,p,{get:()=>l[p],enumerable:!(b=i(l,p))||b.enumerable}));return a.set(l,c),c},u=(l,c)=>{for(var b in c)t(l,b,{get:c[b],enumerable:!0,configurable:!0,set:(p)=>c[b]=()=>p})},m={};u(m,{splitWithQuotes:()=>g,splitNested:()=>y}),r.exports=s(m);var y=(l,c,b="(",p=")")=>{let d=0,f="",k=[];for(let w of l){if(f+=w,w===b)d++;if(w===p)d--;if(d===0&&w===c)k.push(f.slice(0,-1)),f=""}if(f)k.push(f);return k},g=(l,c=",")=>{let b=[],p=l.length,d=c.length,f=0,k=(w)=>{if(w+d>p)return!1;for(let E=0;E<d;E++)if(l[w+E]!==c[E])return!1;return!0};while(f<p){while(f<p&&l[f]===" ")f++;if(f>=p)break;let w="",E=l[f]==='"'||l[f]==="'";if(E){let A=l[f++];while(f<p&&l[f]!==A)w+=l[f++];if(f<p)f++}else{while(f<p&&!k(f)){let A=l[f];if(A==='"'||A==="'"){w+=A,f++;while(f<p&&l[f]!==A)w+=l[f++];if(f<p)w+=l[f++]}else w+=l[f++]}w=w.trim()}if(w)b.push({value:w,quoted:E});if(k(f))f+=d}return b}}),Xr=Kr(Vr(),1),Hr=/^\[([^=\]]*)([=]*)([^\]]*)\]$/,qr=/^([^[\]]*)\[([^\]]*)]$/,ue=(e,r,t,o)=>{if(e.startsWith("{")&&e.endsWith("}")){let i=e.substring(1,e.length-1);return D(r,i,t)?.toString()}return o?e:void 0},zr=(e,r,t,o)=>{let i=ue(r,t,o);if(i)return D(e,i,o);let n=Hr.exec(r);if(n){let[,s,u,m]=n,y=ue(s.trim(),t,o,!0),g=ue(m.trim(),t,o,!0);if(Array.isArray(e)&&(u==="="||u==="==")&&y)return e.find((l)=>l?.[y]==g)}let a=qr.exec(r);if(a){let[,s,u]=a;return e?.[s]?.[u]}return e?.[r]},D=(e,r,t)=>{let o=void 0,i=void 0,n=r??"",a=(g)=>{if(!g)return[g,!1];return g.endsWith("?")?[g.substring(0,g.length-1),!0]:[g,!1]},s=(g,l)=>{let[c,b]=a(l.pop());if(!c){if(t?.set!==void 0&&i!==void 0&&o!==void 0)o[i]=t.set;return g}let p=zr(g,c,e,t);if(p===void 0){if(b||t?.optional||t?.defaultValue!==void 0)return;throw Error(`Unknown path element: "${c}" in "${n}"`)}return o=g,i=c,s(p,l)},u=Xr.splitNested(n,t?.separator??".","{","}"),m=void 0;if(u.length>0&&u[u.length-1].startsWith("?="))m=u.pop()?.substring(2);u.reverse();let y=s(e,u);if(y===void 0)return m??t?.defaultValue;return y},$e=(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((o)=>{let i=o.trim();if(!isNaN(+i))return+i;return i})}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)},X=(e,r,t,o,i,n)=>{let a=o?.(e)??e,s=i(a);if(s[0])return s[1];if(!r){let u=D(t,e),m=i(u);if(m[0])return m[1]}throw Error(n)},Se=(e,r,t,o,i)=>{let n=typeof e.types==="function"?e.types(o,r.value,i):e.types?.[o];if(!n||n==="ref")return $e(r,(s)=>D(t,s));let a=$e(r,()=>r.value);if(Array.isArray(n)){if(!n.includes(a))throw Error(`Argument ${o.toString()} must be one of [${n.join(", ")}]: ${a}`);return a}if(typeof n==="string"){if(n.endsWith("?")){let s=n.slice(0,-1);if(r.value==="null")return O.ReplaceItem(null);if(r.value==="undefined")return O.ReplaceItem(void 0);if(r.value==="")return"";n=s}switch(n){case"any":return a;case"array":return X(a,r.quoted,t,null,(s)=>[Array.isArray(s),s],`Argument ${o.toString()} must be an array: ${a}`);case"object":return X(a,r.quoted,t,null,(s)=>[typeof s==="object"&&s!==null,s],`Argument ${o.toString()} must be an object: ${a}`);case"number":return X(a,r.quoted,t,(s)=>Number(s),(s)=>[!isNaN(s),s],`Argument ${o.toString()} must be a number: ${a}`);case"boolean":return X(a,r.quoted,t,null,(s)=>{if([!0,"true","1",1,"yes","on"].includes(s))return[!0,!0];if([!1,"false","0",0,"no","off"].includes(s))return[!0,!1];if([null,"null","undefined",void 0,""].includes(s))return[!0,!1];if(Array.isArray(s))return[!0,s.length>0];return[!1,!1]},`Argument ${o.toString()} must be a boolean: ${a}`);case"string":return a.toString();default:throw Error(`Unknown type for argument ${o.toString()}: ${n}`)}}return n(a,t,o,r.quoted)},q=(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}},Fe=(e)=>!e.quoted&&e.value.startsWith("."),Pr=(e)=>{let r={};for(let t of e){if(!Fe(t))continue;let o=t.value.indexOf("="),i=o>-1?t.value.slice(1,o):t.value.slice(1),n=o>-1?t.value.slice(o+1):"";if(n.length>=2){let a=n[0],s=n[n.length-1];if(a==='"'&&s==='"'||a==="'"&&s==="'")n=n.slice(1,-1)}if(!r[i])r[i]=[];r[i].push(n)}return r},pe=(e,r,t)=>{let o=Br.splitWithQuotes(e??""),i=Pr(o),n=o.filter((s)=>!Fe(s)),a=r.options.processArgs===!1?[]:n.map((s,u)=>Se(r.options,s,t,u,n));return{rawArgs:n,parsedArgs:a,tags:i}},et=(e)=>{return e!==null&&typeof e==="object"&&"action"in e},rt=(e,r)=>r.keys!==void 0&&e.key.startsWith(".")&&r.keys[e.key.substring(1)]!==void 0,tt=async(e,r,t,o)=>{let{key:i,parent:n}=e,a=q(o.keys,i.substring(1));if(a.options.processArgs!==!1&&(typeof a.options.types==="function"||a.options.types?.[0]!==void 0))e.value=Se(a.options,{value:e.value,quoted:!1},t,0,[]);if(typeof e.value!=="string")await $(e.value,{...o,root:{...t,parent:e.parent,parents:e.parents},filters:[...o.filters??[],...a.options.filters??[]]});let s=await a.fn({path:r,root:t,parent:n,key:i,options:o,value:e.value,args:[],rawArgs:[],tags:{}});return et(s)?s:O.ReplaceParent(s)},_e=(e)=>{let r=[],t=0;while(t<e.length)if(e[t]==="$"&&e[t+1]==="("&&(t===0||e[t-1]!=="\\")){let o=t;t+=2;let i=1;for(;t<e.length;t++)if(e[t]==="(")i++;else if(e[t]===")"){if(i--,i===0){r.push([o,t]);break}}if(i!==0)throw Error(`Unmatched opening $( at position ${o.toString()}`);t++}else t++;return r},fe=Symbol.for("@homedev/fields:OverrideResult"),ot=(e)=>({[fe]:!0,value:e}),nt=(e)=>{return e!==null&&typeof e==="object"&&fe in e&&e[fe]===!0},Me=async(e,r,t)=>{for(let o=r.length-1;o>=0;o--){let[i,n]=r[o],a=e.slice(i+2,n),s=await Me(a,_e(a),t);if(typeof s==="object")return s;let u=await t(s,e);if(nt(u))return u.value;e=e.slice(0,i)+u+e.slice(n+1)}return e},it=async(e,r)=>Me(e,_e(e),r),st=(e)=>{return e!==null&&typeof e==="object"&&"action"in e},at=async(e,r,t,o)=>{let i=await(async()=>{let n=/([\w\d.-_/]+):(.+)/.exec(e);if(!n)return await D(r,e);let[a,s,u]=n,m=q(o.sources,s),y=pe(u,m,r);return await m.fn({args:y.parsedArgs,rawArgs:y.rawArgs,tags:y.tags,key:s,options:o,root:r,path:t,value:null})})();if(i===null||i===void 0)return"";if(typeof i==="object")return ot(i);return i},lt=(e)=>{let r=/{%\s*section\s+([\w\d_-]+)\s*%}([\s\S]*?){%\s*endsection\s+\1\s*%}/g,t,o=[],i=[];while((t=r.exec(e))!==null){let[a,s,u]=t;i.push({fullMatch:a,name:s,body:u})}let n=e;for(let{fullMatch:a,name:s,body:u}of i){let m={},y=u.trim(),g=y.indexOf("---");if(g!==-1){let l=y.slice(0,g).trim();y=y.slice(g+3).trim();try{m=Bun.YAML.parse(l)??{}}catch(c){throw Error(`Failed to parse YAML config for section ${s}: ${c.message}`)}}o.push({name:s,config:m,content:y}),n=n.replace(a,"")}return{sections:o,content:n.trim()}},je=async(e,r,t,o)=>{let i=o?.onSection?lt(r):null,n=r;if(i){n=i.content;for(let s of i.sections){if(Object.keys(s.config).length>0)await $(s.config,o);let u=await o.onSection(s,e,t,o);if(u===!0)n=n+s.content;else if(typeof u==="string")n=n+u}}let a=await it(n,(s)=>at(s,t,e,o));if(st(a))return a;if(a===n){if(i?.sections.length)return O.ReplaceItem(a);return O.Explore()}if(typeof a==="string"){let s=await je(e,a,t,o);if(s.action!==H.Explore)return s}return O.ReplaceItem(a)},$=async(e,r)=>{return r??={},await Jr(e,async(t)=>{let o=[...t.path,t.key].join(".");if(r?.filters?.length&&r.filters.some((s)=>s.test(o)))return O.NoExplore();let i=t.path.length===0,n=t.parents.length>0?t.parents.toReversed():[];if(i){if(n.length>0)throw Error("Root object should not have a parent");n=r?.root?.parents?[r.root.parent,...r.root.parents.toReversed()]:[]}let a={...e,...r.root,this:t.parent,parent:n.length>0?n[0]:null,parents:n};try{if(t.key.startsWith("$"))return O.NoExplore();let s=O.Explore();if(typeof t.value==="string")switch(s=await je(o,t.value,a,r),s.action){case H.Explore:break;case H.ReplaceItem:t.value=s.by;break;default:return s}if(rt(t,r))s=await tt(t,o,a,r);return s}catch(s){throw Error(`${s.message}
|
|
2
|
+
(${o})`)}}),e},z=(e,r)=>r?{fn:(t)=>e(...t.args),types:r}:(t)=>e(...t.args),Ne=(e,r)=>Object.fromEntries(e.map((t)=>[t.name,z(t,r?.types?.[t.name])])),F=(e,r)=>Object.fromEntries((r?.keys??Object.keys(e)).map((t)=>[t,z(e[t],r?.types?.[t])]));var Be={};W(Be,{writeOutputs:()=>re,writeOutput:()=>ye,writeFormat:()=>me,locate:()=>R,loadFormat:()=>P,importList:()=>ge,importGlob:()=>De,globMap:()=>ee,exists:()=>B});import Ce from"fs/promises";import ce from"path";import ut from"path";import ft from"fs/promises";import Ie from"fs/promises";import Re from"path";import xe from"path";import Le from"path";var B=async(e)=>{try{return await Ce.access(e,Ce.constants.R_OK),!0}catch{return!1}},R=async(e,r)=>{let t=!ce.isAbsolute(e)&&r?["",...r]:[""];for(let o of t){let i=ce.join(o,e);if(await B(i))return ce.resolve(i)}throw Error(`File not found: "${e}"`)},P=async(e,r)=>{let t=await R(e,r?.dirs),o=await Bun.file(t).text(),i=ut.dirname(t),n={"[.]json$":JSON.parse,"[.](yml|yaml)$":Bun.YAML.parse,"[.]toml$":Bun.TOML.parse,...r?.parsers},a=Object.entries(n).find((s)=>t.match(s[0]));if(!a)throw Error(`Unhandled file type: ${e}`);return{content:a[1](o),fullPath:t,folderPath:i}},me=async(e,r,t="text")=>{switch(t){case"yaml":await Bun.write(e,Bun.YAML.stringify(r));break;case"json":await Bun.write(e,JSON.stringify(r));break;case"text":default:await Bun.write(e,r.toString())}},ee=async(e,r)=>{if(typeof e==="string"&&!e.includes("*"))return await r.map(e,0,[]);let t=await Array.fromAsync(ft.glob(e,{cwd:r.cwd})),o=r.filter?t.filter(r.filter):t;return await Promise.all(o.map(r.map))},re=async(e,r)=>{if(r?.targetDirectory&&r?.removeFirst)try{await Ie.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 ye(t,r)},ye=async(e,r)=>{let t=Re.join(r?.targetDirectory??".",e.name),o=Re.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 Ie.mkdir(o,{recursive:!0})}catch(i){throw Error(`Failed to create target directory "${o}" for output "${t}": ${i.message}`)}try{await me(t,e.value,e.type??"text")}catch(i){throw Error(`Failed to write output "${t}": ${i.message}`)}},Ue=(e)=>e?Le.isAbsolute(e)?e:Le.join(process.cwd(),e):process.cwd(),ge=async(e,r)=>{let t=[];for(let o of e)try{let i=!xe.isAbsolute(o)?xe.join(Ue(r?.cwd),o):o;if(r?.filter?.(i)===!1)continue;let n=await import(i);if(r?.resolveDefault==="only"&&!n.default)throw Error(`Module ${o} does not have a default export`);let a=r?.resolveDefault?n.default??n:n,s=r?.map?await r.map(a,o):a;if(s!==void 0)t.push(s)}catch(i){if(r?.fail?.(o,i)===!1)continue;throw Error(`Failed to import module ${o}: ${i.message??i}`)}return t},De=async(e,r)=>{let t=[];for(let o of e){let i=await Array.fromAsync(new Bun.Glob(o).scan({cwd:Ue(r?.cwd),absolute:!0}));t.push(...await ge(i,r))}return t};var Ke={};W(Ke,{toObjectWithKey:()=>Je,toObject:()=>te,toList:()=>x,sortBy:()=>Qe,nonNullMap:()=>Ye,defined:()=>Te,deepClone:()=>j,asyncMap:()=>Ge});var x=(e,r="name")=>Object.entries(e).map(([t,o])=>({[r]:t,...o})),Je=(e,r="name")=>Object.fromEntries(e.map((t)=>[t[r],t])),te=(e,r="name")=>Object.fromEntries(e.map((t)=>{let{[r]:o,...i}=t;return[o,i]})),Ye=(e,r)=>{if(!e)return[];let t=[],o=0;for(let i of e)if(i!==null&&i!==void 0)t.push(r(i,o,e)),o++;return t},Te=(e,r="Value is undefined")=>{if(e===void 0)throw Error(r);return e},Qe=(e,r,t=(o,i)=>o-i)=>e.slice().sort((o,i)=>t(r(o),r(i))),Ge=async(e,r)=>Promise.all(e.map(r)),j=(e)=>{if(typeof structuredClone<"u")try{return structuredClone(e)}catch{}return JSON.parse(JSON.stringify(e))};var Ve={};W(Ve,{navigate:()=>de,find:()=>Ze,NavigateResult:()=>h,NavigateAction:()=>we});var we;((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"})(we||={});class h{action;by;skipSiblings;reexplore;constructor(e,r,t,o){this.action=e,this.by=r,this.skipSiblings=t,this.reexplore=o}static _explore=new h(0);static _noExplore=new h(2);static _skipSiblings=new h(1);static _deleteParent=new h(4);static ReplaceParent(e,r){return new h(3,e,void 0,r)}static SkipSiblings(){return h._skipSiblings}static Explore(){return h._explore}static NoExplore(){return h._noExplore}static DeleteParent(){return h._deleteParent}static MergeParent(e){return new h(5,e)}static ReplaceItem(e,r){return new h(6,e,r)}static DeleteItem(e){return new h(7,void 0,e)}}var de=async(e,r)=>{let t=new WeakSet,o=[],i=[],n=async(s,u,m)=>{let y=s===null,g=y?h.Explore():await r({key:s,value:u,path:o,parent:m,parents:i});if(u&&typeof u==="object"&&g.action===0){if(t.has(u))return g;if(t.add(u),!y)o.push(s),i.push(m);let l=u;while(await a(l,s,m))l=m[s];if(!y)i.pop(),o.pop()}return g},a=async(s,u,m)=>{let y=Object.keys(s),g=y.length;for(let l=0;l<g;l++){let c=y[l],b=s[c],p=await n(c,b,s),d=p.action;if(d===0||d===2)continue;if(d===6){if(s[c]=p.by,p.skipSiblings)return;continue}if(d===7){if(delete s[c],p.skipSiblings)return;continue}if(d===1)return;if(d===3){if(u===null)throw Error("Cannot replace root object");if(m[u]=p.by,p.reexplore)return!0;return}if(d===4){if(u===null)throw Error("Cannot delete root object");delete m[u];return}if(d===5)delete s[c],Object.assign(s,p.by)}};await n(null,e,null)},Ze=async(e,r)=>{let t=[];return await de(e,(o)=>{if(r([...o.path,o.key].join("."),o.value))t.push(o.value);return h.Explore()}),t};var Xe=(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 h.SkipSiblings()}});import pt from"path";var He=(e)=>({load:async(r)=>{let t=r.options.globalContext;for(let{file:o}of Array.isArray(r.value)?r.value:[r.value]){if(!o)throw Error("File reference required");await e.load(o,t.file&&pt.dirname(t.file))}return h.DeleteItem()}});var qe={};W(qe,{mergeAll:()=>J,merge:()=>N});var N=(e,r,t)=>{for(let o of Object.keys(r)){if(e[o]===void 0)continue;let i=r[o],n=e[o];if(typeof n!==typeof i||Array.isArray(n)!==Array.isArray(i)){let s=t?.mismatch?.(o,n,i,e,r);if(s!==void 0){r[o]=s;continue}throw Error(`Type mismatch: ${o}`)}let a=t?.mode?.(o,n,i,e,r)??r[".merge"]??"merge";switch(a){case"source":r[o]=n;continue;case"target":continue;case"skip":delete r[o],delete e[o];continue;case"merge":break;default:throw Error(`Unknown merge mode: ${a}`)}if(typeof n==="object")if(Array.isArray(n))i.push(...n);else{if(t?.navigate?.(o,n,i,e,r)===!1)continue;N(n,i,t)}else{if(n===i)continue;let s=t?.conflict?.(o,n,i,e,r);r[o]=s===void 0?i:s}}for(let o of Object.keys(e))if(r[o]===void 0)r[o]=e[o]},J=(e,r)=>{let t={};for(let o of e.toReversed())N(o,t,r);return t};class be{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,o]of this.cache.entries())if(o.timestamp<r)r=o.timestamp,e=t;if(e)this.cache.delete(e)}}}var Pe={};W(Pe,{select:()=>v});var ct=Object.create,{getPrototypeOf:mt,defineProperty:ze,getOwnPropertyNames:yt}=Object,gt=Object.prototype.hasOwnProperty,wt=(e,r,t)=>{t=e!=null?ct(mt(e)):{};let o=r||!e||!e.__esModule?ze(t,"default",{value:e,enumerable:!0}):t;for(let i of yt(e))if(!gt.call(o,i))ze(o,i,{get:()=>e[i],enumerable:!0});return o},dt=(e,r)=>()=>(r||e((r={exports:{}}).exports,r),r.exports),bt=dt((e,r)=>{var{defineProperty:t,getOwnPropertyNames:o,getOwnPropertyDescriptor:i}=Object,n=Object.prototype.hasOwnProperty,a=new WeakMap,s=(l)=>{var c=a.get(l),b;if(c)return c;if(c=t({},"__esModule",{value:!0}),l&&typeof l==="object"||typeof l==="function")o(l).map((p)=>!n.call(c,p)&&t(c,p,{get:()=>l[p],enumerable:!(b=i(l,p))||b.enumerable}));return a.set(l,c),c},u=(l,c)=>{for(var b in c)t(l,b,{get:c[b],enumerable:!0,configurable:!0,set:(p)=>c[b]=()=>p})},m={};u(m,{splitWithQuotes:()=>g,splitNested:()=>y}),r.exports=s(m);var y=(l,c,b="(",p=")")=>{let d=0,f="",k=[];for(let w of l){if(f+=w,w===b)d++;if(w===p)d--;if(d===0&&w===c)k.push(f.slice(0,-1)),f=""}if(f)k.push(f);return k},g=(l,c=",")=>{let b=[],p=l.length,d=c.length,f=0,k=(w)=>{if(w+d>p)return!1;for(let E=0;E<d;E++)if(l[w+E]!==c[E])return!1;return!0};while(f<p){while(f<p&&l[f]===" ")f++;if(f>=p)break;let w="",E=l[f]==='"'||l[f]==="'";if(E){let A=l[f++];while(f<p&&l[f]!==A)w+=l[f++];if(f<p)f++}else{while(f<p&&!k(f)){let A=l[f];if(A==='"'||A==="'"){w+=A,f++;while(f<p&&l[f]!==A)w+=l[f++];if(f<p)w+=l[f++]}else w+=l[f++]}w=w.trim()}if(w)b.push({value:w,quoted:E});if(k(f))f+=d}return b}}),ht=wt(bt(),1),vt=/^\[([^=\]]*)([=]*)([^\]]*)\]$/,kt=/^([^[\]]*)\[([^\]]*)]$/,he=(e,r,t,o)=>{if(e.startsWith("{")&&e.endsWith("}")){let i=e.substring(1,e.length-1);return v(r,i,t)?.toString()}return o?e:void 0},Et=(e,r,t,o)=>{let i=he(r,t,o);if(i)return v(e,i,o);let n=vt.exec(r);if(n){let[,s,u,m]=n,y=he(s.trim(),t,o,!0),g=he(m.trim(),t,o,!0);if(Array.isArray(e)&&(u==="="||u==="==")&&y)return e.find((l)=>l?.[y]==g)}let a=kt.exec(r);if(a){let[,s,u]=a;return e?.[s]?.[u]}return e?.[r]},v=(e,r,t)=>{let o=void 0,i=void 0,n=r??"",a=(g)=>{if(!g)return[g,!1];return g.endsWith("?")?[g.substring(0,g.length-1),!0]:[g,!1]},s=(g,l)=>{let[c,b]=a(l.pop());if(!c){if(t?.set!==void 0&&i!==void 0&&o!==void 0)o[i]=t.set;return g}let p=Et(g,c,e,t);if(p===void 0){if(b||t?.optional||t?.defaultValue!==void 0)return;throw Error(`Unknown path element: "${c}" in "${n}"`)}return o=g,i=c,s(p,l)},u=ht.splitNested(n,t?.separator??".","{","}"),m=void 0;if(u.length>0&&u[u.length-1].startsWith("?="))m=u.pop()?.substring(2);u.reverse();let y=s(e,u);if(y===void 0)return m??t?.defaultValue;return y};var er=(e)=>{if(typeof e.value==="string")return e.parent;let r=e.value.model;if(!r)return e.parent;if(typeof r==="string")return v(e.root,r);return r};var rr=(e)=>{if(typeof e.value==="string")return v(e.root,e.value);if(Array.isArray(e.value))return e.value;let r=e.value;if(typeof r.from==="string")return v(e.root,r.from);return r.from};var tr=async(e,r)=>{let t=e.value;if(t.selector===void 0)return r;if(typeof t.selector!=="string"){let o=JSON.parse(JSON.stringify(t.selector));return await $(o,{...e.options,root:{...e.root,result:r}}),o}return await v({...e.root,result:r},t.selector)};import L from"path";class I{constructor(){}static normalize(e){return L.normalize(L.resolve(e))}static resolveInContext(e,r){let t=r??process.cwd(),o=L.isAbsolute(e)?e:L.join(t,e);return this.normalize(o)}static isDirectoryPattern(e){return e.endsWith("/")}static isGlobPattern(e){return e.includes("*")}static toAbsolute(e,r){if(L.isAbsolute(e))return e;return L.join(r??process.cwd(),e)}}var or={};W(or,{conditionPredicatesTypes:()=>Y,conditionPredicates:()=>_});var _={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)=>!_.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!=="")},Y={and:()=>"boolean",or:()=>"boolean",xor:()=>"boolean",true:()=>"boolean",false:()=>"boolean",lt:()=>"number",le:()=>"number",gt:()=>"number",ge:()=>"number"};var nr=()=>({each:{filters:[/select|model/],fn:async(e)=>{let r=e.value;delete e.parent[e.key];let t=await rr(e),o=await er(e);if(!Array.isArray(t))throw Error('Key "each" requires a source list');if(o===void 0)throw Error('Key "each" must define a model');if(r.extend?.model)o=J([r.model,...Array.isArray(r.extend.model)?r.extend.model:[r.extend.model]]);let i=[];for(let n=0;n<t.length;n++){let a=j(o);if(await $(a,{...e.options,root:{...e.root,index:n,item:t[n],instance:a}}),r.extend?.result){let s=r.extend.result;a=J([a,...Array.isArray(s)?s:[s]])}i.push(await tr(e,a))}return i}}});var ir=()=>({concat:async(e)=>{let r=[];for(let t of Array.isArray(e.value)?e.value:[e.value])r.push(...await v(e.root,t));return r.filter((t)=>t!==void 0)}});var sr=()=>({extends:async(e)=>{let r=async(t,o)=>{for(let i of Array.isArray(o)?o:[o]){let n=await v(e.root,i),a=j(n);if(a[e.key])await r(a,a[e.key]);await $(a,{...e.options}),N(a,t),delete t[e.key]}};return await r(e.parent,e.value),h.Explore()},group:(e)=>{let r=e.root.parent,t=e.value,{items:o,...i}=t;return t.items.forEach((n)=>r.push({...i,...n})),h.DeleteParent()}});var ar=(e)=>({skip:{types:{0:"boolean"},fn:(r)=>r.value?h.DeleteParent():h.DeleteItem()},metadata:({path:r,value:t})=>{return e.metadata(r,t),h.DeleteItem()},if:{types:{0:"boolean"},fn:async(r)=>{let t=r.parent[".then"],o=r.parent[".else"];if(t!==void 0)delete r.parent[".then"];if(o!==void 0)delete r.parent[".else"];let i=r.value?t:o;if(i===void 0)return h.DeleteItem();if(typeof i==="string")return(await $({value:i},{...r.options,root:{...r.root}})).value;return h.ReplaceParent(i,!0)}},switch:(r)=>{let t=r.value;if(!t.cases)throw Error("Missing cases for switch");if(t.cases[t.from]!==void 0)return h.ReplaceParent(t.cases[t.from],!0);if(t.default!==void 0)return h.ReplaceParent(t.default,!0);return h.DeleteParent()}});var lr=()=>({from:async({root:e,parent:r,value:t})=>{let o=await v(e,t);if(o===null||o===void 0)throw Error(`Unable to resolve reference: ${t}`);if(r.content){if(Array.isArray(r.content)&&Array.isArray(o))return[...o,...r.content];return N(o,r.content),r.content}return o}});import ur from"node:vm";var fr=(e)=>({modules:async(r)=>{for(let[t,o]of Object.entries(r.value)){let i=ur.createContext({console,objector:e,document:r.root}),n=new ur.SourceTextModule(o,{identifier:t,context:i});await n.link((a)=>{throw Error(`Module ${a} is not allowed`)}),await n.evaluate(),e.sources(Object.fromEntries(Object.entries(n.namespace).map(([a,s])=>[`${t}.${a}`,(u)=>s(u,...u.args)])))}return h.DeleteItem()}});import pr from"fs/promises";import T from"path";var cr=(e)=>({include:async(r)=>{let{file:t}=r.options.globalContext;return await ee(r.args[0],{cwd:T.dirname(t),filter:(o)=>T.basename(t)!==o,map:async(o)=>e.load(o,T.dirname(t),{parent:r.root})})},exists:async({args:[r]})=>await B(r),file:async(r)=>await pr.readFile(await R(r.args[0],e.getIncludeDirectories())).then((t)=>t.toString()),scan:async(r)=>{let t=[],i=(()=>{let s=r.args[2]??["**/node_modules/**"],u=typeof s==="string"?s.split(",").map((m)=>m.trim()):s;if(!Array.isArray(u))throw Error("Scan exclusion must be a list");return u})(),{file:n}=r.options.globalContext,a=r.args[1]?await R(r.args[1],e.getIncludeDirectories()):T.dirname(n);for await(let s of pr.glob(r.args[0],{cwd:a,exclude:(u)=>i.some((m)=>T.matchesGlob(u,m))}))t.push(s);return t}});var mr=()=>F({env:(e)=>process.env[e]});var gr={};W(gr,{tokenize:()=>yr,snake:()=>G,pascal:()=>Q,padBlock:()=>C,changeCase:()=>K,capital:()=>oe,camel:()=>ne});var Q=(e)=>e.replace(/((?:[_ ]+)\w|^\w)/g,(r,t)=>t.toUpperCase()).replace(/[_ ]/g,""),oe=(e)=>e.replace(/((?:[ ]+)\w|^\w)/g,(r,t)=>t.toUpperCase()),ne=(e)=>{let r=Q(e);return r.charAt(0).toLowerCase()+r.slice(1)},G=(e,r="_")=>e.replace(/([a-z])([A-Z])/g,`$1${r}$2`).replace(/\s+/g,r).toLowerCase(),K=(e,r)=>{switch(r){case"upper":return e.toUpperCase();case"lower":return e.toLowerCase();default:return e}},C=(e,r,t=`
|
|
3
|
+
`,o=" ")=>{let i=o.repeat(r);return e.split(t).map((n)=>i+n).join(t)},yr=(e,r,t=/\${([^}]+)}/g)=>{return e.replace(t,(o,i)=>{let n=r[i];if(n===null||n===void 0)return"";if(typeof n==="string")return n;if(typeof n==="number"||typeof n==="boolean")return String(n);return String(n)})};var ie=(e,r=0,t)=>{let o=" ".repeat(r),i=" ".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`[
|
|
4
|
+
${e.map((a)=>`${i}${ie(a,r+1)},`).join(`
|
|
5
5
|
`)}
|
|
6
|
-
${o}]`}else if(typeof e==="object"){let
|
|
7
|
-
${
|
|
6
|
+
${o}]`}else if(typeof e==="object"){let n=Object.entries(e).sort((s,u)=>t?.sortKeys?s[0].localeCompare(u[0]):0);if(n.length===0)return"{}";return`{
|
|
7
|
+
${n.map(([s,u])=>`${i}${s} = ${ie(u,r+1,t)}`).join(`
|
|
8
8
|
`)}
|
|
9
|
-
${o}}`}else return String(e)},
|
|
10
|
-
`).replaceAll("\\$","$").replaceAll("\\t","\t")};var
|
|
11
|
-
`,
|
|
12
|
-
`,
|
|
13
|
-
`,
|
|
9
|
+
${o}}`}else return String(e)},Z=(e)=>{if(!e)return e;return e.replaceAll("\\n",`
|
|
10
|
+
`).replaceAll("\\$","$").replaceAll("\\t","\t")};var wr=()=>({substring:{types:{0:"ref",1:"number",2:"number"},fn:(e)=>e.args[0].substring(e.args[1],e.args[2])},repeat:{types:{0:"ref",1:"number"},fn:({args:[e,r]})=>e.repeat(r)},uuid:(e)=>crypto.randomUUID(),pad:{types:{0:"ref",1:"number",2:"string"},fn:({args:[e,r],tags:t})=>{let o=t.join?.[0]??`
|
|
11
|
+
`,i=t.padChar?.[0]??" ";return C(e,r??2,o,i)}},formatAs:{types:{1:["json","yaml","terraform"]},fn:({args:[e,r],tags:t})=>{switch(r){case"json":return JSON.stringify(e,null,2);case"yaml":return Bun.YAML.stringify(e,null,2);case"terraform":{let o=!!(t?.sort?.length||t?.sortKeys?.length);return ie(e,0,{sortKeys:o})}}throw Error("Unsupported format: "+String(r))}},...F({pascal:Q,camel:ne,capital:oe,fromYaml:Bun.YAML.parse,fromJson:JSON.parse,toYaml:(e,r)=>Bun.YAML.stringify(e,null,r??2),toJson:(e,r)=>JSON.stringify(e,null,r!==0?r??2:void 0),concat:(...e)=>e.join(""),len:(e)=>e.length,reverse:(e)=>e.split("").reverse().join(""),trim:(e)=>e.trim(),ltrim:(e)=>e.trimStart(),rtrim:(e)=>e.trimEnd(),lower:(e)=>e.toLowerCase(),upper:(e)=>e.toUpperCase(),snake:(e,r)=>K(G(e,"_"),r),kebab:(e,r)=>K(G(e,"-"),r),encode:(e,r)=>Buffer.from(e).toString(r??"base64"),decode:(e,r)=>Buffer.from(e,r??"base64").toString()})});var dr=()=>({...F({merge:(...e)=>e.flatMap((r)=>r)}),join:({args:[e],root:r,tags:t})=>{let o=t.key?.[0],i=t.separator?.[0]??t.sep?.[0],n=t.finalize?.length>0,a=Z(i);if(typeof e==="string"){if(n&&e.length&&a)return e+a;return e}if(!Array.isArray(e))throw Error("Object is not a list");let s=((o?.length)?e.map((g)=>v({...r,...g},o)):e).join(a),u=t.pad?.[0]??"0",m=t.padChar?.[0]??" ",y=n&&s.length&&a?s+a:s;return u?C(y,parseInt(u),`
|
|
12
|
+
`,m):y},list:({args:e})=>x(e[0],e[1]),object:({args:e})=>te(e[0],e[1]),range:({args:[e,r,t]})=>{let o=parseInt(e),i=parseInt(r),n=parseInt(t)||1;if(isNaN(o))throw Error("Invalid range: start value '"+String(e)+"' is not a number");if(isNaN(i))throw Error("Invalid range: end value '"+String(r)+"' is not a number");if(n===0)throw Error("Invalid range: step cannot be zero");if((i-o)/n<0)throw Error("Invalid range: step "+String(n)+" has wrong direction for range "+String(o)+" to "+String(i));return Array.from({length:Math.floor((i-o)/n)+1},(a,s)=>o+s*n)},filter:{types:(e,r,t)=>{switch(e){case 0:return"array";case 1:return Object.keys(_)}return Y[t[1].value]?.(e-2,r,t.slice(2))},fn:({args:[e,r,t],root:o,tags:i})=>{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 n=i.key?.[0],a=_[r];if(n){let u=Array(e.length);for(let y=0;y<e.length;y++)try{u[y]=v({...o,...e[y]},n)}catch{u[y]=Symbol("invalid")}let m=[];for(let y=0;y<e.length;y++){let g=u[y];if(typeof g!=="symbol"&&t===void 0?a(g):a(g,t))m.push(e[y])}return m}let s=[];for(let u of e)if(t===void 0?a(u):a(u,t))s.push(u);return s}}});var br=()=>({each:{processArgs:!1,fn:async({rawArgs:[e,r,...t],root:o,options:i,tags:n})=>{let a=async(p)=>p.quoted?Z(p.value):await v(o,p.value),s=await v(o,e.value),u=await a(r),m=n.key?.[0],y=Array.isArray(s)?s:x(s),g=[],l=await Promise.all(t.map(async(p)=>await a(p))),c={...o,item:void 0,index:0,params:l,instance:void 0,parent:o.this,tags:n},b={...i,root:c};for(let p=0;p<y.length;p++){let d=j(u),f={instance:d},k=typeof u==="string"?f:d;if(c.item=y[p],c.index=p,c.instance=d,n?.root?.[0])Object.assign(c,await v(c,n.root[0]));if(await $(k,b),m!==void 0)g.push(await v(f.instance,m));else g.push(f.instance)}if(n.join?.length){if(g.length===0)return"";let p=Z(n.join[0]),d=n.pad?.[0]??"0",f=n.padChar?.[0]??" ",k=n.finalize?.length&&p?p:"",w=`${g.join(p)}${k}`;return d?C(w,parseInt(d),`
|
|
13
|
+
`,f):w}return g}}});var V=async(e,r,t)=>e.rawArgs[r].quoted?e.rawArgs[r].value:await v(e.root,e.rawArgs[r].value,{defaultValue:t}),hr=()=>({switch:{processArgs:!1,fn:async(e)=>{let r=await V(e,0,!1),t=await V(e,1);if(t[r]===void 0){if(e.rawArgs.length>2)return V(e,2);throw Error(`Unhandled switch case: ${r}`)}return t[r]}}});var vr=()=>F({log:console.log});var kr=()=>({if:{types:{0:"boolean"},fn:(e)=>e.args[0]?e.args[1]:e.args[2]},check:{types:{0:Object.keys(_)},fn:(e)=>_[e.args[0]](...e.args.slice(1))},...F(_,{types:Y})});var Er=(e)=>({default:{processArgs:!1,fn:async(r)=>{for(let t=0;t<r.rawArgs.length;t++)if(r.rawArgs[t]?.value!==void 0){let i=await V(r,t,null);if(i!==null)return i}if(r.tags.nullable?.length)return h.DeleteItem();if(r.tags.fail?.length)throw Error(`No valid value found for default (${r.rawArgs.map((t)=>t.value).join(", ")})`);return""}},section:(r)=>{let t=r.args[0],o=e.getSection(t);if(!o)throw Error(`Section not found: ${t}`);return o.content}});var Or=()=>({convert:({args:[e,r,t]})=>{switch(r){case"string":return String(e);case"number":{let o=Number(e);if(!isNaN(o))return h.ReplaceItem(o);break}case"boolean":if(e==="true"||e===!0||e===1||e==="1"||e==="yes"||e==="on")return h.ReplaceItem(!0);else if(e==="false"||e===!1||e===0||e==="0"||e==="no"||e==="off")return h.ReplaceItem(!1);break;default:throw Error(`Unsupported type for convert: ${r}`)}if(t!==void 0)return h.ReplaceItem(t);throw Error(`Failed to convert value to ${r}`)},isType:({args:[e,r]})=>{let o=(()=>{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 h.ReplaceItem(o)},typeOf:({args:[e]})=>{if(e===null)return"null";else if(Array.isArray(e))return"array";else return typeof e}});var Ar=(e)=>e.keys(Xe(e)).keys(He(e)).keys(nr()).keys(lr()).keys(ir()).keys(sr()).keys(ar(e)).keys(fr(e)).sources(cr(e)).sources(mr()).sources(wr()).sources(Or()).sources(dr()).sources(br()).sources(hr()).sources(vr()).sources(kr()).sources(Er(e)).fieldOptions({onSection:(r)=>{e.section(r)}});import se 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,r,t){let o=[];for(let i of e)if(I.isGlobPattern(i)){let n=new Bun.Glob(i);for await(let a of n.scan({cwd:r,absolute:!0}))if(!t.included.includes(a))o.push(a)}else if(I.isDirectoryPattern(i)){let n=se.isAbsolute(i)?i:se.join(r,i);if(!this.includeDirectories.includes(n))this.includeDirectories.push(n)}else o.push(i);return o}buildSearchDirs(e){let r=e?[e]:[];return r.push(...this.includeDirectories.map((t)=>se.isAbsolute(t)?t:se.join(e??process.cwd(),t))),r}}class ke{includeManager;loadFn;constructor(e,r){this.includeManager=e;this.loadFn=r}async processIncludes(e,r,t){let o=[];if(e.content.includes)o.push(...e.content.includes),delete e.content.includes;o.push(...this.includeManager.getPendingAndClear());let i=await this.includeManager.processPatterns(o,e.folderPath,t);for(let n of i)N(await this.loadFn(n,e.folderPath,{parent:e.content,...r},!0,t),e.content)}}var S={};W(S,{writeOutputs:()=>re,writeOutput:()=>ye,writeFormat:()=>me,tokenize:()=>yr,toObjectWithKey:()=>Je,toObject:()=>te,toList:()=>x,sortBy:()=>Qe,snake:()=>G,select:()=>v,processFields:()=>$,pascal:()=>Q,padBlock:()=>C,nonNullMap:()=>Ye,navigate:()=>de,mergeAll:()=>J,merge:()=>N,makeFieldProcessorMap:()=>F,makeFieldProcessorList:()=>Ne,makeFieldProcessor:()=>z,locate:()=>R,loadFormat:()=>P,importList:()=>ge,importGlob:()=>De,globMap:()=>ee,getProcessor:()=>q,getArgs:()=>pe,find:()=>Ze,exists:()=>B,defined:()=>Te,deepClone:()=>j,conditionPredicates:()=>_,changeCase:()=>K,capital:()=>oe,camel:()=>ne,asyncMap:()=>Ge,NavigateResult:()=>h,NavigateAction:()=>we});M(S,Nr(_r(),1));var Ai=S;class jt{includeManager=new ve;includeProcessor;cacheManager=new be(100);outputs=[];vars={};fields={sources:{},keys:{}};objectMetadata={};currentContext=null;sections={};constructor(){this.includeProcessor=new ke(this.includeManager,this.load.bind(this)),this.use(Ar)}use(e){return e(this),this}includeDirectory(...e){return this.includeManager.addDirectories(...e),this}getIncludeDirectories(){return this.includeManager.getDirectories()}include(...e){return this.includeManager.addFiles(...e),this}keys(e){return Object.assign(this.fields.keys,{...this.fields.keys,...e}),this}sources(e){return Object.assign(this.fields.sources,{...this.fields.sources,...e}),this}variables(e){return this.vars={...this.vars,...e},this}getOutputs(){return this.outputs}output(e){return this.outputs.push(e),this}metadata(e,r){return this.objectMetadata[e]=r,this}getMetadata(e){return this.objectMetadata[e]}getAllMetadata(){return this.objectMetadata}setCacheMaxSize(e){return this.cacheManager.setMaxSize(e),this}clearCache(){return this.cacheManager.clear(),this}getCurrentContext(){return this.currentContext}fieldOptions(e){return this.fields={...this.fields,...e},this}section(e){return this.sections[e.name]=e,this}getSection(e){return this.sections[e]}filter(e){return this.fields.filters??=[],this.fields.filters?.push(e),this}async loadObject(e,r,t){return await $(e,{...this.fields,globalContext:{file:t?.fullPath??"@internal"},root:{...r,...this.fields.root,...this.vars,context:this.currentContext,sections:this.sections,$document:{root:{content:e},fileName:t?.fileName??"@internal",folder:t?.folderPath??"@internal",fullPath:t?.fullPath??"@internal"}}}),e}async load(e,r,t,o,i){let n=this.includeManager.snapshot();try{this.includeManager.reset();let a=this.includeManager.buildSearchDirs(r);if(i)this.currentContext=i;this.currentContext??={included:[],document:null};let s=await P(e,{dirs:a}),u=I.normalize(s.fullPath);if(this.currentContext.included.push(u),!s.content)return null;let m=this.cacheManager.get(u),y;if(m)y=m.raw;else y=s.content,this.cacheManager.set(u,{raw:y,timestamp:Date.now()});let g=j(y);s.content=g,await this.includeProcessor.processIncludes(s,t,this.currentContext);let l;if(o!==!0)l=await this.loadObject(s.content,t,{fileName:s.fullPath,folderPath:s.folderPath,fullPath:s.fullPath});else l=s.content;return this.currentContext.document=l,l}catch(a){throw this.includeManager.restore(n),a}finally{this.includeManager.restore(n)}}async writeAll(e){await re(this.getOutputs(),e)}}export{Ai as default,jt as Objector};
|