@homedev/objector 1.2.43 → 1.2.45
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 +90 -126
- package/dist/index.js +13 -10
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
* @returns Promise of mapped array
|
|
8
8
|
* @public
|
|
9
9
|
*/
|
|
10
|
-
declare const asyncMap: <T, U>(arr: T[], fn: (item: T, index: number, array: T[]) => Promise<U>) => Promise<U[]>;
|
|
10
|
+
export declare const asyncMap: <T, U>(arr: T[], fn: (item: T, index: number, array: T[]) => Promise<U>) => Promise<U[]>;
|
|
11
11
|
|
|
12
12
|
/**
|
|
13
13
|
* Converts a string to camelCase (lowerCamelCase).
|
|
@@ -21,7 +21,7 @@ declare const asyncMap: <T, U>(arr: T[], fn: (item: T, index: number, array: T[]
|
|
|
21
21
|
* @param v - The string to convert
|
|
22
22
|
* @returns The string in camelCase
|
|
23
23
|
*/
|
|
24
|
-
declare const camel: (v: string) => string;
|
|
24
|
+
export declare const camel: (v: string) => string;
|
|
25
25
|
|
|
26
26
|
/**
|
|
27
27
|
* Converts a string to Capital Case (each word capitalized, spaces preserved).
|
|
@@ -34,7 +34,7 @@ declare const camel: (v: string) => string;
|
|
|
34
34
|
* @param v - The string to convert
|
|
35
35
|
* @returns The string with each space-separated word capitalized
|
|
36
36
|
*/
|
|
37
|
-
declare const capital: (v: string) => string;
|
|
37
|
+
export declare const capital: (v: string) => string;
|
|
38
38
|
|
|
39
39
|
/**
|
|
40
40
|
* Changes the case of a string to uppercase, lowercase, or returns unchanged.
|
|
@@ -48,12 +48,12 @@ declare const capital: (v: string) => string;
|
|
|
48
48
|
* @param arg - The case type: 'upper', 'lower', or undefined to return unchanged
|
|
49
49
|
* @returns The transformed string
|
|
50
50
|
*/
|
|
51
|
-
declare const changeCase: (v: string, arg?: string) => string;
|
|
51
|
+
export declare const changeCase: (v: string, arg?: string) => string;
|
|
52
52
|
|
|
53
53
|
/**
|
|
54
54
|
* @public
|
|
55
55
|
*/
|
|
56
|
-
declare const conditionPredicates: Record<string, (...args: any[]) => boolean>;
|
|
56
|
+
export declare const conditionPredicates: Record<string, (...args: any[]) => boolean>;
|
|
57
57
|
|
|
58
58
|
/**
|
|
59
59
|
* Deep clones an object using structuredClone (faster) with JSON fallback
|
|
@@ -65,22 +65,22 @@ declare const conditionPredicates: Record<string, (...args: any[]) => boolean>;
|
|
|
65
65
|
* @returns Deep clone of the object
|
|
66
66
|
* @public
|
|
67
67
|
*/
|
|
68
|
-
declare const deepClone: <T>(model: T) => T;
|
|
68
|
+
export declare const deepClone: <T>(model: T) => T;
|
|
69
69
|
|
|
70
70
|
/**
|
|
71
71
|
* Asserts that a value is defined, throwing an error if undefined
|
|
72
72
|
* @typeParam T - Type of the value
|
|
73
73
|
* @param value - Value to check
|
|
74
|
-
* @param msg - Error message to throw if value is undefined
|
|
74
|
+
* @param msg - Error message to throw if value is undefined or null
|
|
75
75
|
* @returns The value if defined
|
|
76
76
|
* @throws Error if value is undefined
|
|
77
77
|
* @public
|
|
78
78
|
*/
|
|
79
|
-
declare const defined: <T>(value: T | undefined, msg?: string) => T;
|
|
79
|
+
export declare const defined: <T>(value: T | undefined | null, msg?: string) => T;
|
|
80
80
|
|
|
81
|
-
declare const exists: (fileName: string) => Promise<boolean>;
|
|
81
|
+
export declare const exists: (fileName: string) => Promise<boolean>;
|
|
82
82
|
|
|
83
|
-
declare interface FieldContext {
|
|
83
|
+
export declare interface FieldContext {
|
|
84
84
|
path: string;
|
|
85
85
|
root: any;
|
|
86
86
|
options: ProcessFieldsOptions;
|
|
@@ -95,32 +95,35 @@ declare interface FieldContext {
|
|
|
95
95
|
parent?: any;
|
|
96
96
|
}
|
|
97
97
|
|
|
98
|
-
declare interface FieldProcessor {
|
|
98
|
+
export declare interface FieldProcessor {
|
|
99
99
|
fn: FieldProcessorFunc;
|
|
100
100
|
options: FieldProcessorOptions;
|
|
101
101
|
}
|
|
102
102
|
|
|
103
|
-
declare type FieldProcessorFunc = (context: FieldContext) => any;
|
|
103
|
+
export declare type FieldProcessorFunc = (context: FieldContext) => any;
|
|
104
104
|
|
|
105
|
-
declare type FieldProcessorMap = Record<string, FieldProcessorTypedFunc>;
|
|
105
|
+
export declare type FieldProcessorMap = Record<string, FieldProcessorTypedFunc>;
|
|
106
106
|
|
|
107
|
-
declare interface FieldProcessorOptions {
|
|
107
|
+
export declare interface FieldProcessorOptions {
|
|
108
108
|
filters?: RegExp[];
|
|
109
109
|
processArgs?: boolean;
|
|
110
110
|
types?: Record<number, string | any[] | ((value: string, root: any, index: number, quoted: boolean) => any)> | FieldProcessorTypeChecker;
|
|
111
111
|
}
|
|
112
112
|
|
|
113
|
-
declare interface FieldProcessorSection {
|
|
113
|
+
export declare interface FieldProcessorSection {
|
|
114
114
|
name: string;
|
|
115
115
|
config: Record<string, any>;
|
|
116
116
|
content: string;
|
|
117
|
+
trim?: boolean;
|
|
118
|
+
indent?: number;
|
|
119
|
+
show?: boolean;
|
|
117
120
|
}
|
|
118
121
|
|
|
119
|
-
declare type FieldProcessorTypeChecker = (n: number, value: any, args: any[]) => any;
|
|
122
|
+
export declare type FieldProcessorTypeChecker = (n: number, value: any, args: any[]) => any;
|
|
120
123
|
|
|
121
|
-
declare type FieldProcessorTypeCheckers<T = unknown> = Record<keyof T, FieldProcessorTypeChecker>;
|
|
124
|
+
export declare type FieldProcessorTypeCheckers<T = unknown> = Record<keyof T, FieldProcessorTypeChecker>;
|
|
122
125
|
|
|
123
|
-
declare type FieldProcessorTypedFunc = FieldProcessorFunc | (FieldProcessorOptions & {
|
|
126
|
+
export declare type FieldProcessorTypedFunc = FieldProcessorFunc | (FieldProcessorOptions & {
|
|
124
127
|
fn: FieldProcessorFunc;
|
|
125
128
|
});
|
|
126
129
|
|
|
@@ -145,24 +148,24 @@ declare interface FilePatternOptions {
|
|
|
145
148
|
* // results: [2]
|
|
146
149
|
* ```
|
|
147
150
|
*/
|
|
148
|
-
declare const find: (from: any, cb: (path: string, value: any) => boolean) => Promise<any[]>;
|
|
151
|
+
export declare const find: (from: any, cb: (path: string, value: any) => boolean) => Promise<any[]>;
|
|
149
152
|
|
|
150
|
-
declare const globMap: <T>(pattern: string | string[], options: FilePatternOptions) => Promise<T[] | T>;
|
|
153
|
+
export declare const globMap: <T>(pattern: string | string[], options: FilePatternOptions) => Promise<T[] | T>;
|
|
151
154
|
|
|
152
155
|
/**
|
|
153
156
|
* @public
|
|
154
157
|
*/
|
|
155
|
-
declare const importGlob: (patterns: string[], options?: ImportOptions) => Promise<any[]>;
|
|
158
|
+
export declare const importGlob: (patterns: string[], options?: ImportOptions) => Promise<any[]>;
|
|
156
159
|
|
|
157
160
|
/**
|
|
158
161
|
* @public
|
|
159
162
|
*/
|
|
160
|
-
declare const importList: (modules: string[], options?: ImportOptions) => Promise<any[]>;
|
|
163
|
+
export declare const importList: (modules: string[], options?: ImportOptions) => Promise<any[]>;
|
|
161
164
|
|
|
162
165
|
/**
|
|
163
166
|
* @public
|
|
164
167
|
*/
|
|
165
|
-
declare interface ImportOptions {
|
|
168
|
+
export declare interface ImportOptions {
|
|
166
169
|
cwd?: string;
|
|
167
170
|
resolveDefault?: boolean | 'only';
|
|
168
171
|
filter?: (name: string) => boolean | undefined;
|
|
@@ -170,71 +173,6 @@ declare interface ImportOptions {
|
|
|
170
173
|
map?: (module: any, name: string) => any;
|
|
171
174
|
}
|
|
172
175
|
|
|
173
|
-
declare namespace libs {
|
|
174
|
-
export {
|
|
175
|
-
conditionPredicates,
|
|
176
|
-
FieldContext,
|
|
177
|
-
FieldProcessor,
|
|
178
|
-
FieldProcessorFunc,
|
|
179
|
-
FieldProcessorMap,
|
|
180
|
-
FieldProcessorOptions,
|
|
181
|
-
FieldProcessorSection,
|
|
182
|
-
FieldProcessorTypeChecker,
|
|
183
|
-
FieldProcessorTypeCheckers,
|
|
184
|
-
FieldProcessorTypedFunc,
|
|
185
|
-
makeFieldProcessor,
|
|
186
|
-
makeFieldProcessorList,
|
|
187
|
-
makeFieldProcessorMap,
|
|
188
|
-
processFields,
|
|
189
|
-
ProcessFieldsOptions,
|
|
190
|
-
exists,
|
|
191
|
-
globMap,
|
|
192
|
-
importGlob,
|
|
193
|
-
importList,
|
|
194
|
-
ImportOptions,
|
|
195
|
-
loadFormat,
|
|
196
|
-
LoadOptions,
|
|
197
|
-
LoadResult,
|
|
198
|
-
locate,
|
|
199
|
-
Output,
|
|
200
|
-
writeFormat,
|
|
201
|
-
writeOutput,
|
|
202
|
-
WriteOutputOption,
|
|
203
|
-
writeOutputs,
|
|
204
|
-
WriteOutputsOption,
|
|
205
|
-
merge,
|
|
206
|
-
mergeAll,
|
|
207
|
-
MergeMode,
|
|
208
|
-
MergeOptions,
|
|
209
|
-
find,
|
|
210
|
-
navigate,
|
|
211
|
-
NavigateAction,
|
|
212
|
-
NavigateCallback,
|
|
213
|
-
NavigateContext,
|
|
214
|
-
NavigateResult,
|
|
215
|
-
asyncMap,
|
|
216
|
-
deepClone,
|
|
217
|
-
defined,
|
|
218
|
-
nonNullMap,
|
|
219
|
-
sortBy,
|
|
220
|
-
toList,
|
|
221
|
-
toObject,
|
|
222
|
-
toObjectWithKey,
|
|
223
|
-
select,
|
|
224
|
-
SelectOptions,
|
|
225
|
-
splitNested,
|
|
226
|
-
splitWithQuotes,
|
|
227
|
-
camel,
|
|
228
|
-
capital,
|
|
229
|
-
changeCase,
|
|
230
|
-
padBlock,
|
|
231
|
-
pascal,
|
|
232
|
-
snake,
|
|
233
|
-
tokenize
|
|
234
|
-
}
|
|
235
|
-
}
|
|
236
|
-
export default libs;
|
|
237
|
-
|
|
238
176
|
/**
|
|
239
177
|
* @public
|
|
240
178
|
*/
|
|
@@ -249,9 +187,12 @@ export declare interface LoadContext {
|
|
|
249
187
|
* @param options
|
|
250
188
|
* @returns
|
|
251
189
|
*/
|
|
252
|
-
declare const loadFormat: <T = any>(fileName: string, options?: LoadOptions) => Promise<LoadResult<T>>;
|
|
190
|
+
export declare const loadFormat: <T = any>(fileName: string, options?: LoadOptions) => Promise<LoadResult<T>>;
|
|
253
191
|
|
|
254
|
-
|
|
192
|
+
/**
|
|
193
|
+
* @public
|
|
194
|
+
*/
|
|
195
|
+
export declare interface LoadObjectOptions {
|
|
255
196
|
fileName: string;
|
|
256
197
|
fullPath: string;
|
|
257
198
|
folderPath: string;
|
|
@@ -260,26 +201,48 @@ declare interface LoadObjectOptions {
|
|
|
260
201
|
/**
|
|
261
202
|
* @public
|
|
262
203
|
*/
|
|
263
|
-
declare interface LoadOptions {
|
|
204
|
+
export declare interface LoadOptions {
|
|
264
205
|
dirs?: string[];
|
|
265
206
|
parsers?: Record<string, (data: string) => any>;
|
|
266
207
|
}
|
|
267
208
|
|
|
268
|
-
declare interface LoadResult<T> {
|
|
209
|
+
export declare interface LoadResult<T> {
|
|
269
210
|
fullPath: string;
|
|
270
211
|
folderPath: string;
|
|
271
212
|
content: T;
|
|
272
213
|
}
|
|
273
214
|
|
|
274
|
-
declare const locate: (fileName: string, dirs?: string[]) => Promise<string>;
|
|
215
|
+
export declare const locate: (fileName: string, dirs?: string[]) => Promise<string>;
|
|
216
|
+
|
|
217
|
+
declare type LogFunction = (className: string, ...args: any[]) => void;
|
|
218
|
+
|
|
219
|
+
export declare class Logger {
|
|
220
|
+
options: LoggerOptions;
|
|
221
|
+
constructor(options?: Partial<LoggerOptions>);
|
|
222
|
+
write(className: string, ...args: any[]): void;
|
|
223
|
+
log(...args: any[]): void;
|
|
224
|
+
error(...args: any[]): void;
|
|
225
|
+
warn(...args: any[]): void;
|
|
226
|
+
debug(...args: any[]): void;
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
declare interface LoggerOptions {
|
|
230
|
+
level: string;
|
|
231
|
+
showClass: boolean;
|
|
232
|
+
levels: string[];
|
|
233
|
+
timeStamp: boolean;
|
|
234
|
+
timeLocale?: string;
|
|
235
|
+
timeOptions?: Intl.DateTimeFormatOptions;
|
|
236
|
+
logFunction: LogFunction;
|
|
237
|
+
}
|
|
275
238
|
|
|
276
|
-
declare const makeFieldProcessor: (fn: SourceFunc, types?: FieldProcessorTypeChecker) => FieldProcessorTypedFunc;
|
|
239
|
+
export declare const makeFieldProcessor: (fn: SourceFunc, types?: FieldProcessorTypeChecker) => FieldProcessorTypedFunc;
|
|
277
240
|
|
|
278
|
-
declare const makeFieldProcessorList: <T = unknown>(source: SourceFunc[], options?: {
|
|
241
|
+
export declare const makeFieldProcessorList: <T = unknown>(source: SourceFunc[], options?: {
|
|
279
242
|
types?: FieldProcessorTypeCheckers<T>;
|
|
280
243
|
}) => FieldProcessorMap;
|
|
281
244
|
|
|
282
|
-
declare const makeFieldProcessorMap: <T = unknown>(source: Record<keyof T, SourceFunc>, options?: {
|
|
245
|
+
export declare const makeFieldProcessorMap: <T = unknown>(source: Record<keyof T, SourceFunc>, options?: {
|
|
283
246
|
types?: FieldProcessorTypeCheckers<T>;
|
|
284
247
|
keys?: (keyof T)[];
|
|
285
248
|
}) => FieldProcessorMap;
|
|
@@ -290,24 +253,24 @@ declare const makeFieldProcessorMap: <T = unknown>(source: Record<keyof T, Sourc
|
|
|
290
253
|
* @param target
|
|
291
254
|
* @param options
|
|
292
255
|
*/
|
|
293
|
-
declare const merge: (source: any, target: any, options?: MergeOptions) => void;
|
|
256
|
+
export declare const merge: (source: any, target: any, options?: MergeOptions) => void;
|
|
294
257
|
|
|
295
258
|
/**
|
|
296
259
|
* @public
|
|
297
260
|
* @param elements
|
|
298
261
|
* @param options
|
|
299
262
|
*/
|
|
300
|
-
declare const mergeAll: (elements: any[], options?: MergeOptions) => any;
|
|
263
|
+
export declare const mergeAll: (elements: any[], options?: MergeOptions) => any;
|
|
301
264
|
|
|
302
265
|
/**
|
|
303
266
|
* @public
|
|
304
267
|
*/
|
|
305
|
-
declare type MergeMode = 'merge' | 'source' | 'target' | 'skip';
|
|
268
|
+
export declare type MergeMode = 'merge' | 'source' | 'target' | 'skip';
|
|
306
269
|
|
|
307
270
|
/**
|
|
308
271
|
* @public
|
|
309
272
|
*/
|
|
310
|
-
declare interface MergeOptions {
|
|
273
|
+
export declare interface MergeOptions {
|
|
311
274
|
conflict?: (key: string, source: any, target: any, sourceContainer: any, targetContainer: any) => any;
|
|
312
275
|
mismatch?: (key: string, source: any, target: any, sourceContainer: any, targetContainer: any) => any;
|
|
313
276
|
navigate?: (key: string, source: any, target: any, sourceContainer: any, targetContainer: any) => boolean | undefined;
|
|
@@ -330,12 +293,12 @@ declare interface MergeOptions {
|
|
|
330
293
|
* @param cb - Callback function invoked for each property
|
|
331
294
|
* @throws {Error} When attempting to replace the root object
|
|
332
295
|
*/
|
|
333
|
-
declare const navigate: (o: any, cb: NavigateCallback) => Promise<void>;
|
|
296
|
+
export declare const navigate: (o: any, cb: NavigateCallback) => Promise<void>;
|
|
334
297
|
|
|
335
298
|
/**
|
|
336
299
|
* @public
|
|
337
300
|
*/
|
|
338
|
-
declare enum NavigateAction {
|
|
301
|
+
export declare enum NavigateAction {
|
|
339
302
|
Explore = 0,
|
|
340
303
|
SkipSiblings = 1,
|
|
341
304
|
NoExplore = 2,
|
|
@@ -349,12 +312,12 @@ declare enum NavigateAction {
|
|
|
349
312
|
/**
|
|
350
313
|
* @public
|
|
351
314
|
*/
|
|
352
|
-
declare type NavigateCallback = (context: NavigateContext) => Promise<NavigateResult> | NavigateResult;
|
|
315
|
+
export declare type NavigateCallback = (context: NavigateContext) => Promise<NavigateResult> | NavigateResult;
|
|
353
316
|
|
|
354
317
|
/**
|
|
355
318
|
* @public
|
|
356
319
|
*/
|
|
357
|
-
declare interface NavigateContext {
|
|
320
|
+
export declare interface NavigateContext {
|
|
358
321
|
key: string;
|
|
359
322
|
value: any;
|
|
360
323
|
path: string[];
|
|
@@ -365,7 +328,7 @@ declare interface NavigateContext {
|
|
|
365
328
|
/**
|
|
366
329
|
* @public
|
|
367
330
|
*/
|
|
368
|
-
declare class NavigateResult {
|
|
331
|
+
export declare class NavigateResult {
|
|
369
332
|
readonly action: NavigateAction;
|
|
370
333
|
by?: any | undefined;
|
|
371
334
|
skipSiblings?: boolean | undefined;
|
|
@@ -395,7 +358,7 @@ declare class NavigateResult {
|
|
|
395
358
|
* @returns Mapped array with nulls/undefined filtered out, or empty array if input is undefined
|
|
396
359
|
* @public
|
|
397
360
|
*/
|
|
398
|
-
declare const nonNullMap: <T, U>(arr: T[] | undefined, fn: (item: T, index: number, array: T[]) => U) => U[];
|
|
361
|
+
export declare const nonNullMap: <T, U>(arr: T[] | undefined, fn: (item: T, index: number, array: T[]) => U) => U[];
|
|
399
362
|
|
|
400
363
|
/**
|
|
401
364
|
* @public
|
|
@@ -435,7 +398,7 @@ export declare class Objector {
|
|
|
435
398
|
writeAll(option?: WriteOutputsOption): Promise<void>;
|
|
436
399
|
}
|
|
437
400
|
|
|
438
|
-
declare interface Output {
|
|
401
|
+
export declare interface Output {
|
|
439
402
|
name: string;
|
|
440
403
|
type?: 'json' | 'yaml' | 'text';
|
|
441
404
|
value: any;
|
|
@@ -456,7 +419,7 @@ declare interface Output {
|
|
|
456
419
|
* @param padder - The character to repeat for padding (default: ' ')
|
|
457
420
|
* @returns The indented string
|
|
458
421
|
*/
|
|
459
|
-
declare const padBlock: (str: string, indent: number, separator?: string, padder?: string) => string;
|
|
422
|
+
export declare const padBlock: (str: string, indent: number, separator?: string, padder?: string) => string;
|
|
460
423
|
|
|
461
424
|
/**
|
|
462
425
|
* Converts a string to PascalCase (UpperCamelCase).
|
|
@@ -470,7 +433,7 @@ declare const padBlock: (str: string, indent: number, separator?: string, padder
|
|
|
470
433
|
* @param v - The string to convert
|
|
471
434
|
* @returns The string in PascalCase
|
|
472
435
|
*/
|
|
473
|
-
declare const pascal: (v: string) => string;
|
|
436
|
+
export declare const pascal: (v: string) => string;
|
|
474
437
|
|
|
475
438
|
/**
|
|
476
439
|
* @public
|
|
@@ -478,15 +441,16 @@ declare const pascal: (v: string) => string;
|
|
|
478
441
|
* @param options
|
|
479
442
|
* @returns
|
|
480
443
|
*/
|
|
481
|
-
declare const processFields: (obj: any, options?: ProcessFieldsOptions) => Promise<any>;
|
|
444
|
+
export declare const processFields: (obj: any, options?: ProcessFieldsOptions) => Promise<any>;
|
|
482
445
|
|
|
483
|
-
declare interface ProcessFieldsOptions {
|
|
446
|
+
export declare interface ProcessFieldsOptions {
|
|
484
447
|
sources?: FieldProcessorMap;
|
|
485
448
|
keys?: FieldProcessorMap;
|
|
486
449
|
filters?: RegExp[];
|
|
487
450
|
root?: Record<any, any>;
|
|
488
451
|
globalContext?: any;
|
|
489
452
|
onSection?: (section: FieldProcessorSection, path: string, root: Record<string, any>, options: ProcessFieldsOptions) => Promise<void | boolean | string> | void | boolean | string;
|
|
453
|
+
onSectionConfig?: (section: FieldProcessorSection, path: string, root: Record<string, any>, options: ProcessFieldsOptions) => Promise<boolean | void> | boolean | void;
|
|
490
454
|
}
|
|
491
455
|
|
|
492
456
|
/**
|
|
@@ -513,13 +477,13 @@ declare interface ProcessFieldsOptions {
|
|
|
513
477
|
* select(obj, 'user.email', { defaultValue: 'N/A' }) // 'N/A'
|
|
514
478
|
* ```
|
|
515
479
|
*/
|
|
516
|
-
declare const select: <T = any>(from: any, path: string, options?: SelectOptions) => T | undefined;
|
|
480
|
+
export declare const select: <T = any>(from: any, path: string, options?: SelectOptions) => T | undefined;
|
|
517
481
|
|
|
518
482
|
/**
|
|
519
483
|
* Options for configuring the select function behavior
|
|
520
484
|
* @public
|
|
521
485
|
*/
|
|
522
|
-
declare interface SelectOptions {
|
|
486
|
+
export declare interface SelectOptions {
|
|
523
487
|
/** Value to set at the selected path */
|
|
524
488
|
set?: any;
|
|
525
489
|
/** Alternative key to use (currently unused) */
|
|
@@ -545,7 +509,7 @@ declare interface SelectOptions {
|
|
|
545
509
|
* @param separator - The separator to use between words (default: '_')
|
|
546
510
|
* @returns The string in snake case with the specified separator
|
|
547
511
|
*/
|
|
548
|
-
declare const snake: (v: string, separator?: string) => string;
|
|
512
|
+
export declare const snake: (v: string, separator?: string) => string;
|
|
549
513
|
|
|
550
514
|
/**
|
|
551
515
|
* Sorts an array by a selector function with custom comparison
|
|
@@ -558,11 +522,11 @@ declare const snake: (v: string, separator?: string) => string;
|
|
|
558
522
|
* @returns New sorted array
|
|
559
523
|
* @public
|
|
560
524
|
*/
|
|
561
|
-
declare const sortBy: <T, U>(arr: T[], selector: (item: T) => U, compare?: (a: U, b: U) => number) => T[];
|
|
525
|
+
export declare const sortBy: <T, U>(arr: T[], selector: (item: T) => U, compare?: (a: U, b: U) => number) => T[];
|
|
562
526
|
|
|
563
527
|
declare type SourceFunc = (...args: any[]) => any;
|
|
564
528
|
|
|
565
|
-
declare const splitNested: (str: string, separator: string, open?: string, close?: string) => string[];
|
|
529
|
+
export declare const splitNested: (str: string, separator: string, open?: string, close?: string) => string[];
|
|
566
530
|
|
|
567
531
|
/**
|
|
568
532
|
* Splits a string by a separator while respecting quoted values.
|
|
@@ -589,7 +553,7 @@ declare const splitNested: (str: string, separator: string, open?: string, close
|
|
|
589
553
|
* // { value: 'd', quoted: false }
|
|
590
554
|
* // ]
|
|
591
555
|
*/
|
|
592
|
-
declare const splitWithQuotes: (input: string, separator?: string) => {
|
|
556
|
+
export declare const splitWithQuotes: (input: string, separator?: string) => {
|
|
593
557
|
value: string;
|
|
594
558
|
quoted: boolean;
|
|
595
559
|
}[];
|
|
@@ -608,7 +572,7 @@ declare const splitWithQuotes: (input: string, separator?: string) => {
|
|
|
608
572
|
* @param tokenizer - The regex pattern for token matching (default: `/\$\{([^}]+)\}/g`)
|
|
609
573
|
* @returns The string with tokens replaced by values from the object
|
|
610
574
|
*/
|
|
611
|
-
declare const tokenize: (str: string, from: Record<string, unknown>, tokenizer?: RegExp) => string;
|
|
575
|
+
export declare const tokenize: (str: string, from: Record<string, unknown>, tokenizer?: RegExp) => string;
|
|
612
576
|
|
|
613
577
|
/**
|
|
614
578
|
* Converts an object's entries into an array of objects with a key property
|
|
@@ -620,7 +584,7 @@ declare const tokenize: (str: string, from: Record<string, unknown>, tokenizer?:
|
|
|
620
584
|
* toList({ a: { value: 1 }, b: { value: 2 } }) // [{ name: 'a', value: 1 }, { name: 'b', value: 2 }]
|
|
621
585
|
* @public
|
|
622
586
|
*/
|
|
623
|
-
declare const toList: <T>(from: Record<string, unknown>, key?: string) => T[];
|
|
587
|
+
export declare const toList: <T>(from: Record<string, unknown>, key?: string) => T[];
|
|
624
588
|
|
|
625
589
|
/**
|
|
626
590
|
* Converts an array into an object indexed by a key property, excluding the key from items
|
|
@@ -632,7 +596,7 @@ declare const toList: <T>(from: Record<string, unknown>, key?: string) => T[];
|
|
|
632
596
|
* toObject([{ name: 'a', value: 1 }]) // { a: { value: 1 } }
|
|
633
597
|
* @public
|
|
634
598
|
*/
|
|
635
|
-
declare const toObject: <T extends Record<string, unknown>>(from: T[], key?: string) => Record<string, Omit<T, typeof key>>;
|
|
599
|
+
export declare const toObject: <T extends Record<string, unknown>>(from: T[], key?: string) => Record<string, Omit<T, typeof key>>;
|
|
636
600
|
|
|
637
601
|
/**
|
|
638
602
|
* Converts an array into an object indexed by a key property, keeping the full items
|
|
@@ -644,22 +608,22 @@ declare const toObject: <T extends Record<string, unknown>>(from: T[], key?: str
|
|
|
644
608
|
* toObjectWithKey([{ name: 'a', value: 1 }]) // { a: { name: 'a', value: 1 } }
|
|
645
609
|
* @public
|
|
646
610
|
*/
|
|
647
|
-
declare const toObjectWithKey: <T extends Record<string, unknown>>(from: T[], key?: string) => Record<string, T>;
|
|
611
|
+
export declare const toObjectWithKey: <T extends Record<string, unknown>>(from: T[], key?: string) => Record<string, T>;
|
|
648
612
|
|
|
649
|
-
declare const writeFormat: (filePath: string, content: any, format?: "yaml" | "json" | "text") => Promise<void>;
|
|
613
|
+
export declare const writeFormat: (filePath: string, content: any, format?: "yaml" | "json" | "text") => Promise<void>;
|
|
650
614
|
|
|
651
|
-
declare const writeOutput: (o: Output, options?: WriteOutputOption) => Promise<void>;
|
|
615
|
+
export declare const writeOutput: (o: Output, options?: WriteOutputOption) => Promise<void>;
|
|
652
616
|
|
|
653
|
-
declare interface WriteOutputOption {
|
|
617
|
+
export declare interface WriteOutputOption {
|
|
654
618
|
targetDirectory?: string;
|
|
655
619
|
writing?: (output: Output) => boolean | undefined | void;
|
|
656
620
|
classes?: string[];
|
|
657
621
|
classRequired?: boolean;
|
|
658
622
|
}
|
|
659
623
|
|
|
660
|
-
declare const writeOutputs: (outputs: Output[], options?: WriteOutputsOption) => Promise<void>;
|
|
624
|
+
export declare const writeOutputs: (outputs: Output[], options?: WriteOutputsOption) => Promise<void>;
|
|
661
625
|
|
|
662
|
-
declare interface WriteOutputsOption extends WriteOutputOption {
|
|
626
|
+
export declare interface WriteOutputsOption extends WriteOutputOption {
|
|
663
627
|
removeFirst?: boolean;
|
|
664
628
|
}
|
|
665
629
|
|
package/dist/index.js
CHANGED
|
@@ -1,13 +1,16 @@
|
|
|
1
|
-
var Tr=Object.create;var{getPrototypeOf:Yr,defineProperty:U,getOwnPropertyNames:pe}=Object;var ce=Object.prototype.hasOwnProperty,j=(e,r,t)=>{for(let n of pe(r))if(!ce.call(e,n)&&n!=="default")U(e,n,{get:()=>r[n],enumerable:!0});if(t){for(let n of pe(r))if(!ce.call(t,n)&&n!=="default")U(t,n,{get:()=>r[n],enumerable:!0});return t}},Qr=(e,r,t)=>{t=e!=null?Tr(Yr(e)):{};let n=r||!e||!e.__esModule?U(t,"default",{value:e,enumerable:!0}):t;for(let o of pe(e))if(!ce.call(n,o))U(n,o,{get:()=>e[o],enumerable:!0});return n};var Kr=(e,r)=>()=>(r||e((r={exports:{}}).exports,r),r.exports);var N=(e,r)=>{for(var t in r)U(e,t,{get:r[t],enumerable:!0,configurable:!0,set:(n)=>r[t]=()=>n})};var Jr=Kr((Ps,Br)=>{var{defineProperty:Se,getOwnPropertyNames:Jt,getOwnPropertyDescriptor:Tt}=Object,Yt=Object.prototype.hasOwnProperty,Ir=new WeakMap,Qt=(e)=>{var r=Ir.get(e),t;if(r)return r;if(r=Se({},"__esModule",{value:!0}),e&&typeof e==="object"||typeof e==="function")Jt(e).map((n)=>!Yt.call(r,n)&&Se(r,n,{get:()=>e[n],enumerable:!(t=Tt(e,n))||t.enumerable}));return Ir.set(e,r),r},Kt=(e,r)=>{for(var t in r)Se(e,t,{get:r[t],enumerable:!0,configurable:!0,set:(n)=>r[t]=()=>n})},Ur={};Kt(Ur,{splitWithQuotes:()=>Vt,splitNested:()=>Gt});Br.exports=Qt(Ur);var Gt=(e,r,t="(",n=")")=>{let o=0,s="",i=[];for(let a of e){if(s+=a,a===t)o++;if(a===n)o--;if(o===0&&a===r)i.push(s.slice(0,-1)),s=""}if(s)i.push(s);return i},Vt=(e,r=",")=>{let t=[],n=e.length,o=r.length,s=0,i=(a)=>{if(a+o>n)return!1;for(let u=0;u<o;u++)if(e[a+u]!==r[u])return!1;return!0};while(s<n){while(s<n&&e[s]===" ")s++;if(s>=n)break;let a="",u=e[s]==='"'||e[s]==="'";if(u){let m=e[s++];while(s<n&&e[s]!==m)a+=e[s++];if(s<n)s++}else{while(s<n&&!i(s)){let m=e[s];if(m==='"'||m==="'"){a+=m,s++;while(s<n&&e[s]!==m)a+=e[s++];if(s<n)a+=e[s++]}else a+=e[s++]}a=a.trim()}if(a)t.push({value:a,quoted:u});if(i(s))s+=o}return t}});var Le={};N(Le,{processFields:()=>O,makeFieldProcessorMap:()=>S,makeFieldProcessorList:()=>De,makeFieldProcessor:()=>z,getProcessor:()=>P,getArgs:()=>ye});var Gr=Object.create,{getPrototypeOf:Vr,defineProperty:Fe,getOwnPropertyNames:Zr}=Object,Hr=Object.prototype.hasOwnProperty,Xr=(e,r,t)=>{t=e!=null?Gr(Vr(e)):{};let n=r||!e||!e.__esModule?Fe(t,"default",{value:e,enumerable:!0}):t;for(let o of Zr(e))if(!Hr.call(n,o))Fe(n,o,{get:()=>e[o],enumerable:!0});return n},qr=(e,r)=>()=>(r||e((r={exports:{}}).exports,r),r.exports),xr=qr((e,r)=>{var{defineProperty:t,getOwnPropertyNames:n,getOwnPropertyDescriptor:o}=Object,s=Object.prototype.hasOwnProperty,i=new WeakMap,a=(l)=>{var c=i.get(l),h;if(c)return c;if(c=t({},"__esModule",{value:!0}),l&&typeof l==="object"||typeof l==="function")n(l).map((p)=>!s.call(c,p)&&t(c,p,{get:()=>l[p],enumerable:!(h=o(l,p))||h.enumerable}));return i.set(l,c),c},u=(l,c)=>{for(var h in c)t(l,h,{get:c[h],enumerable:!0,configurable:!0,set:(p)=>c[h]=()=>p})},m={};u(m,{splitWithQuotes:()=>y,splitNested:()=>g}),r.exports=a(m);var g=(l,c,h="(",p=")")=>{let w=0,f="",E=[];for(let d of l){if(f+=d,d===h)w++;if(d===p)w--;if(w===0&&d===c)E.push(f.slice(0,-1)),f=""}if(f)E.push(f);return E},y=(l,c=",")=>{let h=[],p=l.length,w=c.length,f=0,E=(d)=>{if(d+w>p)return!1;for(let A=0;A<w;A++)if(l[d+A]!==c[A])return!1;return!0};while(f<p){while(f<p&&l[f]===" ")f++;if(f>=p)break;let d="",A=l[f]==='"'||l[f]==="'";if(A){let M=l[f++];while(f<p&&l[f]!==M)d+=l[f++];if(f<p)f++}else{while(f<p&&!E(f)){let M=l[f];if(M==='"'||M==="'"){d+=M,f++;while(f<p&&l[f]!==M)d+=l[f++];if(f<p)d+=l[f++]}else d+=l[f++]}d=d.trim()}if(d)h.push({value:d,quoted:A});if(E(f))f+=w}return h}}),Pr=Xr(xr(),1),x;((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"})(x||={});class k{action;by;skipSiblings;reexplore;constructor(e,r,t,n){this.action=e,this.by=r,this.skipSiblings=t,this.reexplore=n}static _explore=new k(0);static _noExplore=new k(2);static _skipSiblings=new k(1);static _deleteParent=new k(4);static ReplaceParent(e,r){return new k(3,e,void 0,r)}static SkipSiblings(){return k._skipSiblings}static Explore(){return k._explore}static NoExplore(){return k._noExplore}static DeleteParent(){return k._deleteParent}static MergeParent(e){return new k(5,e)}static ReplaceItem(e,r){return new k(6,e,r)}static DeleteItem(e){return new k(7,void 0,e)}}var zr=async(e,r)=>{let t=new WeakSet,n=[],o=[],s=async(a,u,m)=>{let g=a===null,y=g?k.Explore():await r({key:a,value:u,path:n,parent:m,parents:o});if(u&&typeof u==="object"&&y.action===0){if(t.has(u))return y;if(t.add(u),!g)n.push(a),o.push(m);let l=u;while(await i(l,a,m))l=m[a];if(!g)o.pop(),n.pop()}return y},i=async(a,u,m)=>{let g=Object.keys(a),y=g.length;for(let l=0;l<y;l++){let c=g[l],h=a[c],p=await s(c,h,a),w=p.action;if(w===0||w===2)continue;if(w===6){if(a[c]=p.by,p.skipSiblings)return;continue}if(w===7){if(delete a[c],p.skipSiblings)return;continue}if(w===1)return;if(w===3){if(u===null)throw Error("Cannot replace root object");if(m[u]=p.by,p.reexplore)return!0;return}if(w===4){if(u===null)throw Error("Cannot delete root object");delete m[u];return}if(w===5)delete a[c],Object.assign(a,p.by)}};await s(null,e,null)},et=Object.create,{getPrototypeOf:rt,defineProperty:$e,getOwnPropertyNames:tt}=Object,nt=Object.prototype.hasOwnProperty,ot=(e,r,t)=>{t=e!=null?et(rt(e)):{};let n=r||!e||!e.__esModule?$e(t,"default",{value:e,enumerable:!0}):t;for(let o of tt(e))if(!nt.call(n,o))$e(n,o,{get:()=>e[o],enumerable:!0});return n},st=(e,r)=>()=>(r||e((r={exports:{}}).exports,r),r.exports),at=st((e,r)=>{var{defineProperty:t,getOwnPropertyNames:n,getOwnPropertyDescriptor:o}=Object,s=Object.prototype.hasOwnProperty,i=new WeakMap,a=(l)=>{var c=i.get(l),h;if(c)return c;if(c=t({},"__esModule",{value:!0}),l&&typeof l==="object"||typeof l==="function")n(l).map((p)=>!s.call(c,p)&&t(c,p,{get:()=>l[p],enumerable:!(h=o(l,p))||h.enumerable}));return i.set(l,c),c},u=(l,c)=>{for(var h in c)t(l,h,{get:c[h],enumerable:!0,configurable:!0,set:(p)=>c[h]=()=>p})},m={};u(m,{splitWithQuotes:()=>y,splitNested:()=>g}),r.exports=a(m);var g=(l,c,h="(",p=")")=>{let w=0,f="",E=[];for(let d of l){if(f+=d,d===h)w++;if(d===p)w--;if(w===0&&d===c)E.push(f.slice(0,-1)),f=""}if(f)E.push(f);return E},y=(l,c=",")=>{let h=[],p=l.length,w=c.length,f=0,E=(d)=>{if(d+w>p)return!1;for(let A=0;A<w;A++)if(l[d+A]!==c[A])return!1;return!0};while(f<p){while(f<p&&l[f]===" ")f++;if(f>=p)break;let d="",A=l[f]==='"'||l[f]==="'";if(A){let M=l[f++];while(f<p&&l[f]!==M)d+=l[f++];if(f<p)f++}else{while(f<p&&!E(f)){let M=l[f];if(M==='"'||M==="'"){d+=M,f++;while(f<p&&l[f]!==M)d+=l[f++];if(f<p)d+=l[f++]}else d+=l[f++]}d=d.trim()}if(d)h.push({value:d,quoted:A});if(E(f))f+=w}return h}}),it=ot(at(),1),lt=/^\[([^=\]]*)([=]*)([^\]]*)\]$/,ut=/^([^[\]]*)\[([^\]]*)]$/,me=(e,r,t,n)=>{if(e.startsWith("{")&&e.endsWith("}")){let o=e.substring(1,e.length-1);return B(r,o,t)?.toString()}return n?e:void 0},ft=(e,r,t,n)=>{let o=me(r,t,n);if(o)return B(e,o,n);let s=lt.exec(r);if(s){let[,a,u,m]=s,g=me(a.trim(),t,n,!0),y=me(m.trim(),t,n,!0);if(Array.isArray(e)&&(u==="="||u==="==")&&g)return e.find((l)=>l?.[g]==y)}let i=ut.exec(r);if(i){let[,a,u]=i;return e?.[a]?.[u]}return e?.[r]},B=(e,r,t)=>{let n=void 0,o=void 0,s=r??"",i=(y)=>{if(!y)return[y,!1];return y.endsWith("?")?[y.substring(0,y.length-1),!0]:[y,!1]},a=(y,l)=>{let[c,h]=i(l.pop());if(!c){if(t?.set!==void 0&&o!==void 0&&n!==void 0)n[o]=t.set;return y}let p=ft(y,c,e,t);if(p===void 0){if(h||t?.optional||t?.defaultValue!==void 0)return;throw Error(`Unknown path element: "${c}" in "${s}"`)}return n=y,o=c,a(p,l)},u=it.splitNested(s,t?.separator??".","{","}"),m=void 0;if(u.length>0&&u[u.length-1].startsWith("?="))m=u.pop()?.substring(2);u.reverse();let g=a(e,u);if(g===void 0)return m??t?.defaultValue;return g},_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((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)},q=(e,r,t,n,o,s)=>{let i=n?.(e)??e,a=o(i);if(a[0])return a[1];if(!r){let u=B(t,e),m=o(u);if(m[0])return m[1]}throw Error(s)},je=(e,r,t,n,o)=>{let s=typeof e.types==="function"?e.types(n,r.value,o):e.types?.[n];if(!s||s==="ref")return _e(r,(a)=>B(t,a));let i=_e(r,()=>r.value);if(Array.isArray(s)){if(!s.includes(i))throw Error(`Argument ${n.toString()} must be one of [${s.join(", ")}]: ${i}`);return i}if(typeof s==="string"){if(s.endsWith("?")){let a=s.slice(0,-1);if(r.value==="null")return k.ReplaceItem(null);if(r.value==="undefined")return k.ReplaceItem(void 0);if(r.value==="")return"";s=a}switch(s){case"any":return i;case"array":return q(i,r.quoted,t,null,(a)=>[Array.isArray(a),a],`Argument ${n.toString()} must be an array: ${i}`);case"object":return q(i,r.quoted,t,null,(a)=>[typeof a==="object"&&a!==null,a],`Argument ${n.toString()} must be an object: ${i}`);case"number":return q(i,r.quoted,t,(a)=>Number(a),(a)=>[!isNaN(a),a],`Argument ${n.toString()} must be a number: ${i}`);case"boolean":return q(i,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: ${i}`);case"string":return i.toString();default:throw Error(`Unknown type for argument ${n.toString()}: ${s}`)}}return s(i,t,n,r.quoted)},P=(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}},Re=(e)=>!e.quoted&&e.value.startsWith("."),pt=(e)=>{let r={};for(let t of e){if(!Re(t))continue;let n=t.value.indexOf("="),o=n>-1?t.value.slice(1,n):t.value.slice(1),s=n>-1?t.value.slice(n+1):"";if(s.length>=2){let i=s[0],a=s[s.length-1];if(i==='"'&&a==='"'||i==="'"&&a==="'")s=s.slice(1,-1)}if(!r[o])r[o]=[];r[o].push(s)}return r},ye=(e,r,t)=>{let n=Pr.splitWithQuotes(e??""),o=pt(n),s=n.filter((a)=>!Re(a)),i=r.options.processArgs===!1?[]:s.map((a,u)=>je(r.options,a,t,u,s));return{rawArgs:s,parsedArgs:i,tags:o}},ct=(e)=>{return e!==null&&typeof e==="object"&&"action"in e},mt=(e,r)=>r.keys!==void 0&&e.key.startsWith(".")&&r.keys[e.key.substring(1)]!==void 0,gt=async(e,r,t,n)=>{let{key:o,parent:s}=e,i=P(n.keys,o.substring(1));if(i.options.processArgs!==!1&&(typeof i.options.types==="function"||i.options.types?.[0]!==void 0))e.value=je(i.options,{value:e.value,quoted:!1},t,0,[]);if(typeof e.value!=="string")await O(e.value,{...n,root:{...t,parent:e.parent,parents:e.parents},filters:[...n.filters??[],...i.options.filters??[]]});let a=await i.fn({path:r,root:t,parent:s,key:o,options:n,value:e.value,args:[],rawArgs:[],tags:{}});return ct(a)?a:k.ReplaceParent(a)},Ne=(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},ge=Symbol.for("@homedev/fields:OverrideResult"),yt=(e)=>({[ge]:!0,value:e}),dt=(e)=>{return e!==null&&typeof e==="object"&&ge in e&&e[ge]===!0},We=async(e,r,t)=>{for(let n=r.length-1;n>=0;n--){let[o,s]=r[n],i=e.slice(o+2,s),a=await We(i,Ne(i),t);if(typeof a==="object")return a;let u=await t(a,e);if(dt(u))return u.value;e=e.slice(0,o)+u+e.slice(s+1)}return e},wt=async(e,r)=>We(e,Ne(e),r),bt=(e)=>{return e!==null&&typeof e==="object"&&"action"in e},ht=async(e,r,t,n)=>{let o=await(async()=>{let s=/([\w\d.-_/]+):(.+)/.exec(e);if(!s)return await B(r,e);let[i,a,u]=s,m=P(n.sources,a),g=ye(u,m,r);return await m.fn({args:g.parsedArgs,rawArgs:g.rawArgs,tags:g.tags,key:a,options:n,root:r,path:t,value:null})})();if(o===null||o===void 0)return"";if(typeof o==="object")return yt(o);return o},vt=(e)=>{let r=/{%\s*section\s+([\w\d_-]+)\s*%}([\s\S]*?){%\s*endsection\s+\1\s*%}/g,t,n=[],o=[];while((t=r.exec(e))!==null){let[i,a,u]=t;o.push({fullMatch:i,name:a,body:u})}let s=e;for(let{fullMatch:i,name:a,body:u}of o){let m={},g=u.trim(),y=g.indexOf("---");if(y!==-1){let l=g.slice(0,y).trim();g=g.slice(y+3).trim();try{m=Bun.YAML.parse(l)??{}}catch(c){throw Error(`Failed to parse YAML config for section ${a}: ${c.message}`)}}n.push({name:a,config:m,content:g}),s=s.replace(i,"")}return{sections:n,content:s.trim()}},Ce=async(e,r,t,n)=>{let o=n?.onSection?vt(r):null,s=r;if(o){s=o.content;for(let a of o.sections){if(Object.keys(a.config).length>0)await O(a.config,n);let u=await n.onSection(a,e,t,n);if(u===!0)s=s+a.content;else if(typeof u==="string")s=s+u}}let i=await wt(s,(a)=>ht(a,t,e,n));if(bt(i))return i;if(i===s){if(o?.sections.length)return k.ReplaceItem(i);return k.Explore()}if(typeof i==="string"){let a=await Ce(e,i,t,n);if(a.action!==x.Explore)return a}return k.ReplaceItem(i)},O=async(e,r)=>{return r??={},await zr(e,async(t)=>{let n=[...t.path,t.key].join(".");if(r?.filters?.length&&r.filters.some((a)=>a.test(n)))return k.NoExplore();let o=t.path.length===0,s=t.parents.length>0?t.parents.toReversed():[];if(o){if(s.length>0)throw Error("Root object should not have a parent");s=r?.root?.parents?[r.root.parent,...r.root.parents.toReversed()]:[]}let i={...e,...r.root,this:t.parent,parent:s.length>0?s[0]:null,parents:s};try{if(t.key.startsWith("$"))return k.NoExplore();let a=k.Explore();if(typeof t.value==="string")switch(a=await Ce(n,t.value,i,r),a.action){case x.Explore:break;case x.ReplaceItem:t.value=a.by;break;default:return a}if(mt(t,r))a=await gt(t,n,i,r);return a}catch(a){throw Error(`${a.message}
|
|
2
|
-
(${n})`)}}),e},z=(e,r)=>r?{fn:(t)=>e(...t.args),types:r}:(t)=>e(...t.args),De=(e,r)=>Object.fromEntries(e.map((t)=>[t.name,z(t,r?.types?.[t.name])])),S=(e,r)=>Object.fromEntries((r?.keys??Object.keys(e)).map((t)=>[t,z(e[t],r?.types?.[t])]));var Ke={};N(Ke,{writeOutputs:()=>te,writeOutput:()=>be,writeFormat:()=>we,locate:()=>C,loadFormat:()=>ee,importList:()=>he,importGlob:()=>Qe,globMap:()=>re,exists:()=>J});import Ie from"fs/promises";import de from"path";import Et from"path";import At from"fs/promises";import Te from"fs/promises";import Ue from"path";import Be from"path";import Je from"path";var J=async(e)=>{try{return await Ie.access(e,Ie.constants.R_OK),!0}catch{return!1}},C=async(e,r)=>{let t=!de.isAbsolute(e)&&r?["",...r]:[""];for(let n of t){let o=de.join(n,e);if(await J(o))return de.resolve(o)}throw Error(`File not found: "${e}"`)},ee=async(e,r)=>{let t=await C(e,r?.dirs),n=await Bun.file(t).text(),o=Et.dirname(t),s={"[.]json$":JSON.parse,"[.](yml|yaml)$":Bun.YAML.parse,"[.]toml$":Bun.TOML.parse,...r?.parsers},i=Object.entries(s).find((a)=>t.match(a[0]));if(!i)throw Error(`Unhandled file type: ${e}`);return{content:i[1](n),fullPath:t,folderPath:o}},we=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())}},re=async(e,r)=>{if(typeof e==="string"&&!e.includes("*"))return await r.map(e,0,[]);let t=await Array.fromAsync(At.glob(e,{cwd:r.cwd})),n=r.filter?t.filter(r.filter):t;return await Promise.all(n.map(r.map))},te=async(e,r)=>{if(r?.targetDirectory&&r?.removeFirst)try{await Te.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 be(t,r)},be=async(e,r)=>{let t=Ue.join(r?.targetDirectory??".",e.name),n=Ue.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 Te.mkdir(n,{recursive:!0})}catch(o){throw Error(`Failed to create target directory "${n}" for output "${t}": ${o.message}`)}try{await we(t,e.value,e.type??"text")}catch(o){throw Error(`Failed to write output "${t}": ${o.message}`)}},Ye=(e)=>e?Je.isAbsolute(e)?e:Je.join(process.cwd(),e):process.cwd(),he=async(e,r)=>{let t=[];for(let n of e)try{let o=!Be.isAbsolute(n)?Be.join(Ye(r?.cwd),n):n;if(r?.filter?.(o)===!1)continue;let s=await import(o);if(r?.resolveDefault==="only"&&!s.default)throw Error(`Module ${n} does not have a default export`);let i=r?.resolveDefault?s.default??s:s,a=r?.map?await r.map(i,n):i;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},Qe=async(e,r)=>{let t=[];for(let n of e){let o=await Array.fromAsync(new Bun.Glob(n).scan({cwd:Ye(r?.cwd),absolute:!0}));t.push(...await he(o,r))}return t};var qe={};N(qe,{toObjectWithKey:()=>Ge,toObject:()=>ne,toList:()=>D,sortBy:()=>He,nonNullMap:()=>Ve,defined:()=>Ze,deepClone:()=>$,asyncMap:()=>Xe});var D=(e,r="name")=>Object.entries(e).map(([t,n])=>({[r]:t,...n})),Ge=(e,r="name")=>Object.fromEntries(e.map((t)=>[t[r],t])),ne=(e,r="name")=>Object.fromEntries(e.map((t)=>{let{[r]:n,...o}=t;return[n,o]})),Ve=(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},Ze=(e,r="Value is undefined")=>{if(e===void 0)throw Error(r);return e},He=(e,r,t=(n,o)=>n-o)=>e.slice().sort((n,o)=>t(r(n),r(o))),Xe=async(e,r)=>Promise.all(e.map(r)),$=(e)=>{if(typeof structuredClone<"u")try{return structuredClone(e)}catch{}return JSON.parse(JSON.stringify(e))};var Pe={};N(Pe,{navigate:()=>Ee,find:()=>xe,NavigateResult:()=>b,NavigateAction:()=>ve});var ve;((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"})(ve||={});class b{action;by;skipSiblings;reexplore;constructor(e,r,t,n){this.action=e,this.by=r,this.skipSiblings=t,this.reexplore=n}static _explore=new b(0);static _noExplore=new b(2);static _skipSiblings=new b(1);static _deleteParent=new b(4);static ReplaceParent(e,r){return new b(3,e,void 0,r)}static SkipSiblings(){return b._skipSiblings}static Explore(){return b._explore}static NoExplore(){return b._noExplore}static DeleteParent(){return b._deleteParent}static MergeParent(e){return new b(5,e)}static ReplaceItem(e,r){return new b(6,e,r)}static DeleteItem(e){return new b(7,void 0,e)}}var Ee=async(e,r)=>{let t=new WeakSet,n=[],o=[],s=async(a,u,m)=>{let g=a===null,y=g?b.Explore():await r({key:a,value:u,path:n,parent:m,parents:o});if(u&&typeof u==="object"&&y.action===0){if(t.has(u))return y;if(t.add(u),!g)n.push(a),o.push(m);let l=u;while(await i(l,a,m))l=m[a];if(!g)o.pop(),n.pop()}return y},i=async(a,u,m)=>{let g=Object.keys(a),y=g.length;for(let l=0;l<y;l++){let c=g[l],h=a[c],p=await s(c,h,a),w=p.action;if(w===0||w===2)continue;if(w===6){if(a[c]=p.by,p.skipSiblings)return;continue}if(w===7){if(delete a[c],p.skipSiblings)return;continue}if(w===1)return;if(w===3){if(u===null)throw Error("Cannot replace root object");if(m[u]=p.by,p.reexplore)return!0;return}if(w===4){if(u===null)throw Error("Cannot delete root object");delete m[u];return}if(w===5)delete a[c],Object.assign(a,p.by)}};await s(null,e,null)},xe=async(e,r)=>{let t=[];return await Ee(e,(n)=>{if(r([...n.path,n.key].join("."),n.value))t.push(n.value);return b.Explore()}),t};var ze=(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 b.SkipSiblings()}});import kt from"path";var er=(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&&kt.dirname(t.file))}return b.DeleteItem()}});var rr={};N(rr,{mergeAll:()=>T,merge:()=>R});var R=(e,r,t)=>{for(let n of Object.keys(r)){if(e[n]===void 0)continue;let o=r[n],s=e[n];if(typeof s!==typeof o||Array.isArray(s)!==Array.isArray(o)){let a=t?.mismatch?.(n,s,o,e,r);if(a!==void 0){r[n]=a;continue}throw Error(`Type mismatch: ${n}`)}let i=t?.mode?.(n,s,o,e,r)??r[".merge"]??"merge";switch(i){case"source":r[n]=s;continue;case"target":continue;case"skip":delete r[n],delete e[n];continue;case"merge":break;default:throw Error(`Unknown merge mode: ${i}`)}if(typeof s==="object")if(Array.isArray(s))o.push(...s);else{if(t?.navigate?.(n,s,o,e,r)===!1)continue;R(s,o,t)}else{if(s===o)continue;let a=t?.conflict?.(n,s,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]},T=(e,r)=>{let t={};for(let n of e.toReversed())R(n,t,r);return t};class Ae{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 nr={};N(nr,{select:()=>v});var Mt=Object.create,{getPrototypeOf:Ot,defineProperty:tr,getOwnPropertyNames:St}=Object,Ft=Object.prototype.hasOwnProperty,$t=(e,r,t)=>{t=e!=null?Mt(Ot(e)):{};let n=r||!e||!e.__esModule?tr(t,"default",{value:e,enumerable:!0}):t;for(let o of St(e))if(!Ft.call(n,o))tr(n,o,{get:()=>e[o],enumerable:!0});return n},_t=(e,r)=>()=>(r||e((r={exports:{}}).exports,r),r.exports),jt=_t((e,r)=>{var{defineProperty:t,getOwnPropertyNames:n,getOwnPropertyDescriptor:o}=Object,s=Object.prototype.hasOwnProperty,i=new WeakMap,a=(l)=>{var c=i.get(l),h;if(c)return c;if(c=t({},"__esModule",{value:!0}),l&&typeof l==="object"||typeof l==="function")n(l).map((p)=>!s.call(c,p)&&t(c,p,{get:()=>l[p],enumerable:!(h=o(l,p))||h.enumerable}));return i.set(l,c),c},u=(l,c)=>{for(var h in c)t(l,h,{get:c[h],enumerable:!0,configurable:!0,set:(p)=>c[h]=()=>p})},m={};u(m,{splitWithQuotes:()=>y,splitNested:()=>g}),r.exports=a(m);var g=(l,c,h="(",p=")")=>{let w=0,f="",E=[];for(let d of l){if(f+=d,d===h)w++;if(d===p)w--;if(w===0&&d===c)E.push(f.slice(0,-1)),f=""}if(f)E.push(f);return E},y=(l,c=",")=>{let h=[],p=l.length,w=c.length,f=0,E=(d)=>{if(d+w>p)return!1;for(let A=0;A<w;A++)if(l[d+A]!==c[A])return!1;return!0};while(f<p){while(f<p&&l[f]===" ")f++;if(f>=p)break;let d="",A=l[f]==='"'||l[f]==="'";if(A){let M=l[f++];while(f<p&&l[f]!==M)d+=l[f++];if(f<p)f++}else{while(f<p&&!E(f)){let M=l[f];if(M==='"'||M==="'"){d+=M,f++;while(f<p&&l[f]!==M)d+=l[f++];if(f<p)d+=l[f++]}else d+=l[f++]}d=d.trim()}if(d)h.push({value:d,quoted:A});if(E(f))f+=w}return h}}),Rt=$t(jt(),1),Nt=/^\[([^=\]]*)([=]*)([^\]]*)\]$/,Wt=/^([^[\]]*)\[([^\]]*)]$/,ke=(e,r,t,n)=>{if(e.startsWith("{")&&e.endsWith("}")){let o=e.substring(1,e.length-1);return v(r,o,t)?.toString()}return n?e:void 0},Ct=(e,r,t,n)=>{let o=ke(r,t,n);if(o)return v(e,o,n);let s=Nt.exec(r);if(s){let[,a,u,m]=s,g=ke(a.trim(),t,n,!0),y=ke(m.trim(),t,n,!0);if(Array.isArray(e)&&(u==="="||u==="==")&&g)return e.find((l)=>l?.[g]==y)}let i=Wt.exec(r);if(i){let[,a,u]=i;return e?.[a]?.[u]}return e?.[r]},v=(e,r,t)=>{let n=void 0,o=void 0,s=r??"",i=(y)=>{if(!y)return[y,!1];return y.endsWith("?")?[y.substring(0,y.length-1),!0]:[y,!1]},a=(y,l)=>{let[c,h]=i(l.pop());if(!c){if(t?.set!==void 0&&o!==void 0&&n!==void 0)n[o]=t.set;return y}let p=Ct(y,c,e,t);if(p===void 0){if(h||t?.optional||t?.defaultValue!==void 0)return;throw Error(`Unknown path element: "${c}" in "${s}"`)}return n=y,o=c,a(p,l)},u=Rt.splitNested(s,t?.separator??".","{","}"),m=void 0;if(u.length>0&&u[u.length-1].startsWith("?="))m=u.pop()?.substring(2);u.reverse();let g=a(e,u);if(g===void 0)return m??t?.defaultValue;return g};var oe=(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 se=(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 ae=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 O(n,{...e.options,root:{...e.root,result:r}}),n}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(),n=L.isAbsolute(e)?e:L.join(t,e);return this.normalize(n)}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={};N(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 sr=()=>({each:{filters:[/select|model/],fn:async(e)=>{let r=e.value;delete e.parent[e.key];let t=await se(e),n=await oe(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=T([r.model,...Array.isArray(r.extend.model)?r.extend.model:[r.extend.model]]);let o=[];for(let s=0;s<t.length;s++){let i=$(n);if(await O(i,{...e.options,root:{...e.root,index:s,item:t[s],instance:i}}),r.extend?.result){let a=r.extend.result;i=T([i,...Array.isArray(a)?a:[a]])}o.push(await ae(e,i))}return o}}});var ar=()=>({map:{filters:[/select|model/],fn:async(e)=>{delete e.parent[e.key];let r=await se(e),t=await oe(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 s=$(t);await O(s,{...e.options,root:{...e.root,index:o,item:r[o],instance:s}}),n.push(await ae(e,s))}return n}}});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 lr=()=>({extends:async(e)=>{let r=async(t,n)=>{for(let o of Array.isArray(n)?n:[n]){let s=await v(e.root,o),i=$(s);if(i[e.key])await r(i,i[e.key]);await O(i,{...e.options}),R(i,t),delete t[e.key]}};return await r(e.parent,e.value),b.Explore()},group:(e)=>{let r=e.root.parent,t=e.value,{items:n,...o}=t;return t.items.forEach((s)=>r.push({...o,...s})),b.DeleteParent()}});var ur=(e)=>({skip:{types:{0:"boolean"},fn:(r)=>r.value?b.DeleteParent():b.DeleteItem()},metadata:({path:r,value:t})=>{return e.metadata(r,t),b.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 b.DeleteItem();if(typeof o==="string")return(await O({value:o},{...r.options,root:{...r.root}})).value;return b.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 b.ReplaceParent(t.cases[t.from],!0);if(t.default!==void 0)return b.ReplaceParent(t.default,!0);return b.DeleteParent()}});var fr=()=>({from:async({root:e,parent:r,value:t})=>{let n=await v(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 R(n,r.content),r.content}return n}});import pr from"node:vm";var cr=(e)=>({modules:async(r)=>{for(let[t,n]of Object.entries(r.value)){let o=pr.createContext({console,objector:e,document:r.root}),s=new pr.SourceTextModule(n,{identifier:t,context:o});await s.link((i)=>{throw Error(`Module ${i} is not allowed`)}),await s.evaluate(),e.sources(Object.fromEntries(Object.entries(s.namespace).map(([i,a])=>[`${t}.${i}`,(u)=>a(u,...u.args)])))}return b.DeleteItem()}});var mr=()=>({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 b.DeleteItem()}}}});var gr=()=>({let:{fn:(e)=>{let r=e.value;return Object.assign(e.root,r),b.DeleteItem()}}});var yr=()=>({tap:{fn:(e)=>{return console.log(`[tap] ${e.path}:`,e.value),e.value}}});import dr from"fs/promises";import Q from"path";var wr=(e)=>({include:async(r)=>{let{file:t}=r.options.globalContext;return await re(r.args[0],{cwd:Q.dirname(t),filter:(n)=>Q.basename(t)!==n,map:async(n)=>e.load(n,Q.dirname(t),r.root)})},exists:async({args:[r]})=>await J(r),file:async(r)=>await dr.readFile(await C(r.args[0],e.getIncludeDirectories())).then((t)=>t.toString()),scan:async(r)=>{let t=[],o=(()=>{let a=r.args[2]??["**/node_modules/**"],u=typeof a==="string"?a.split(",").map((m)=>m.trim()):a;if(!Array.isArray(u))throw Error("Scan exclusion must be a list");return u})(),{file:s}=r.options.globalContext,i=r.args[1]?await C(r.args[1],e.getIncludeDirectories()):Q.dirname(s);for await(let a of dr.glob(r.args[0],{cwd:i,exclude:(u)=>o.some((m)=>Q.matchesGlob(u,m))}))t.push(a);return t}});var br=()=>S({env:(e)=>process.env[e]});var vr={};N(vr,{tokenize:()=>hr,snake:()=>G,pascal:()=>K,padBlock:()=>W,changeCase:()=>V,capital:()=>ie,camel:()=>le});var K=(e)=>e.replace(/((?:[_ ]+)\w|^\w)/g,(r,t)=>t.toUpperCase()).replace(/[_ ]/g,""),ie=(e)=>e.replace(/((?:[ ]+)\w|^\w)/g,(r,t)=>t.toUpperCase()),le=(e)=>{let r=K(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(),V=(e,r)=>{switch(r){case"upper":return e.toUpperCase();case"lower":return e.toLowerCase();default:return e}},W=(e,r,t=`
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
var Hr=Object.create;var{getPrototypeOf:xr,defineProperty:Z,getOwnPropertyNames:Me}=Object;var Ee=Object.prototype.hasOwnProperty,k=(e,r,t)=>{for(let n of Me(r))if(!Ee.call(e,n)&&n!=="default")Z(e,n,{get:()=>r[n],enumerable:!0});if(t){for(let n of Me(r))if(!Ee.call(t,n)&&n!=="default")Z(t,n,{get:()=>r[n],enumerable:!0});return t}},qr=(e,r,t)=>{t=e!=null?Hr(xr(e)):{};let n=r||!e||!e.__esModule?Z(t,"default",{value:e,enumerable:!0}):t;for(let o of Me(e))if(!Ee.call(n,o))Z(n,o,{get:()=>e[o],enumerable:!0});return n};var Pr=(e,r)=>()=>(r||e((r={exports:{}}).exports,r),r.exports);var R=(e,r)=>{for(var t in r)Z(e,t,{get:r[t],enumerable:!0,configurable:!0,set:(n)=>r[t]=()=>n})};var Kr=Pr((ta,Gr)=>{var{defineProperty:Je,getOwnPropertyNames:xt,getOwnPropertyDescriptor:qt}=Object,Pt=Object.prototype.hasOwnProperty,Qr=new WeakMap,Xt=(e)=>{var r=Qr.get(e),t;if(r)return r;if(r=Je({},"__esModule",{value:!0}),e&&typeof e==="object"||typeof e==="function")xt(e).map((n)=>!Pt.call(r,n)&&Je(r,n,{get:()=>e[n],enumerable:!(t=qt(e,n))||t.enumerable}));return Qr.set(e,r),r},zt=(e,r)=>{for(var t in r)Je(e,t,{get:r[t],enumerable:!0,configurable:!0,set:(n)=>r[t]=()=>n})},Zr={};zt(Zr,{splitWithQuotes:()=>rn,splitNested:()=>en});Gr.exports=Xt(Zr);var en=(e,r,t="(",n=")")=>{let o=0,s="",i=[];for(let a of e){if(s+=a,a===t)o++;if(a===n)o--;if(o===0&&a===r)i.push(s.slice(0,-1)),s=""}if(s)i.push(s);return i},rn=(e,r=",")=>{let t=[],n=e.length,o=r.length,s=0,i=(a)=>{if(a+o>n)return!1;for(let u=0;u<o;u++)if(e[a+u]!==r[u])return!1;return!0};while(s<n){while(s<n&&e[s]===" ")s++;if(s>=n)break;let a="",u=e[s]==='"'||e[s]==="'";if(u){let m=e[s++];while(s<n&&e[s]!==m)a+=e[s++];if(s<n)s++}else{while(s<n&&!i(s)){let m=e[s];if(m==='"'||m==="'"){a+=m,s++;while(s<n&&e[s]!==m)a+=e[s++];if(s<n)a+=e[s++]}else a+=e[s++]}a=a.trim()}if(a)t.push({value:a,quoted:u});if(i(s))s+=o}return t}});var N={};R(N,{writeOutputs:()=>P,writeOutput:()=>ue,writeFormat:()=>le,tokenize:()=>Be,toObjectWithKey:()=>_e,toObject:()=>X,toList:()=>W,sortBy:()=>Le,snake:()=>Y,select:()=>v,processFields:()=>j,pascal:()=>J,padBlock:()=>L,nonNullMap:()=>Ne,navigate:()=>ce,mergeAll:()=>B,merge:()=>F,makeFieldProcessorMap:()=>D,makeFieldProcessorList:()=>Se,makeFieldProcessor:()=>H,locate:()=>C,loadFormat:()=>x,importList:()=>fe,importGlob:()=>Re,globMap:()=>q,getProcessor:()=>V,getArgs:()=>ie,find:()=>Ie,exists:()=>U,defined:()=>Fe,deepClone:()=>$,conditionPredicates:()=>_,changeCase:()=>Q,capital:()=>re,camel:()=>te,asyncMap:()=>Ce,Objector:()=>Vr,NavigateResult:()=>b,NavigateAction:()=>pe,Logger:()=>Ye});var je={};R(je,{processFields:()=>j,makeFieldProcessorMap:()=>D,makeFieldProcessorList:()=>Se,makeFieldProcessor:()=>H,getProcessor:()=>V,getArgs:()=>ie});var Xr=Object.create,{getPrototypeOf:zr,defineProperty:Qe,getOwnPropertyNames:et}=Object,rt=Object.prototype.hasOwnProperty,tt=(e,r,t)=>{t=e!=null?Xr(zr(e)):{};let n=r||!e||!e.__esModule?Qe(t,"default",{value:e,enumerable:!0}):t;for(let o of et(e))if(!rt.call(n,o))Qe(n,o,{get:()=>e[o],enumerable:!0});return n},nt=(e,r)=>()=>(r||e((r={exports:{}}).exports,r),r.exports),ot=nt((e,r)=>{var{defineProperty:t,getOwnPropertyNames:n,getOwnPropertyDescriptor:o}=Object,s=Object.prototype.hasOwnProperty,i=new WeakMap,a=(l)=>{var c=i.get(l),h;if(c)return c;if(c=t({},"__esModule",{value:!0}),l&&typeof l==="object"||typeof l==="function")n(l).map((p)=>!s.call(c,p)&&t(c,p,{get:()=>l[p],enumerable:!(h=o(l,p))||h.enumerable}));return i.set(l,c),c},u=(l,c)=>{for(var h in c)t(l,h,{get:c[h],enumerable:!0,configurable:!0,set:(p)=>c[h]=()=>p})},m={};u(m,{splitWithQuotes:()=>y,splitNested:()=>g}),r.exports=a(m);var g=(l,c,h="(",p=")")=>{let w=0,f="",M=[];for(let d of l){if(f+=d,d===h)w++;if(d===p)w--;if(w===0&&d===c)M.push(f.slice(0,-1)),f=""}if(f)M.push(f);return M},y=(l,c=",")=>{let h=[],p=l.length,w=c.length,f=0,M=(d)=>{if(d+w>p)return!1;for(let O=0;O<w;O++)if(l[d+O]!==c[O])return!1;return!0};while(f<p){while(f<p&&l[f]===" ")f++;if(f>=p)break;let d="",O=l[f]==='"'||l[f]==="'";if(O){let S=l[f++];while(f<p&&l[f]!==S)d+=l[f++];if(f<p)f++}else{while(f<p&&!M(f)){let S=l[f];if(S==='"'||S==="'"){d+=S,f++;while(f<p&&l[f]!==S)d+=l[f++];if(f<p)d+=l[f++]}else d+=l[f++]}d=d.trim()}if(d)h.push({value:d,quoted:O});if(M(f))f+=w}return h}}),st=tt(ot(),1),G;((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"})(G||={});class A{action;by;skipSiblings;reexplore;constructor(e,r,t,n){this.action=e,this.by=r,this.skipSiblings=t,this.reexplore=n}static _explore=new A(0);static _noExplore=new A(2);static _skipSiblings=new A(1);static _deleteParent=new A(4);static ReplaceParent(e,r){return new A(3,e,void 0,r)}static SkipSiblings(){return A._skipSiblings}static Explore(){return A._explore}static NoExplore(){return A._noExplore}static DeleteParent(){return A._deleteParent}static MergeParent(e){return new A(5,e)}static ReplaceItem(e,r){return new A(6,e,r)}static DeleteItem(e){return new A(7,void 0,e)}}var at=async(e,r)=>{let t=new WeakSet,n=[],o=[],s=async(a,u,m)=>{let g=a===null,y=g?A.Explore():await r({key:a,value:u,path:n,parent:m,parents:o});if(u&&typeof u==="object"&&y.action===0){if(t.has(u))return y;if(t.add(u),!g)n.push(a),o.push(m);let l=u;while(await i(l,a,m))l=m[a];if(!g)o.pop(),n.pop()}return y},i=async(a,u,m)=>{let g=Object.keys(a),y=g.length;for(let l=0;l<y;l++){let c=g[l],h=a[c],p=await s(c,h,a),w=p.action;if(w===0||w===2)continue;if(w===6){if(a[c]=p.by,p.skipSiblings)return;continue}if(w===7){if(delete a[c],p.skipSiblings)return;continue}if(w===1)return;if(w===3){if(u===null)throw Error("Cannot replace root object");if(m[u]=p.by,p.reexplore)return!0;return}if(w===4){if(u===null)throw Error("Cannot delete root object");delete m[u];return}if(w===5)delete a[c],Object.assign(a,p.by)}};await s(null,e,null)},it=Object.create,{getPrototypeOf:lt,defineProperty:Ze,getOwnPropertyNames:ut}=Object,ft=Object.prototype.hasOwnProperty,pt=(e,r,t)=>{t=e!=null?it(lt(e)):{};let n=r||!e||!e.__esModule?Ze(t,"default",{value:e,enumerable:!0}):t;for(let o of ut(e))if(!ft.call(n,o))Ze(n,o,{get:()=>e[o],enumerable:!0});return n},ct=(e,r)=>()=>(r||e((r={exports:{}}).exports,r),r.exports),mt=ct((e,r)=>{var{defineProperty:t,getOwnPropertyNames:n,getOwnPropertyDescriptor:o}=Object,s=Object.prototype.hasOwnProperty,i=new WeakMap,a=(l)=>{var c=i.get(l),h;if(c)return c;if(c=t({},"__esModule",{value:!0}),l&&typeof l==="object"||typeof l==="function")n(l).map((p)=>!s.call(c,p)&&t(c,p,{get:()=>l[p],enumerable:!(h=o(l,p))||h.enumerable}));return i.set(l,c),c},u=(l,c)=>{for(var h in c)t(l,h,{get:c[h],enumerable:!0,configurable:!0,set:(p)=>c[h]=()=>p})},m={};u(m,{splitWithQuotes:()=>y,splitNested:()=>g}),r.exports=a(m);var g=(l,c,h="(",p=")")=>{let w=0,f="",M=[];for(let d of l){if(f+=d,d===h)w++;if(d===p)w--;if(w===0&&d===c)M.push(f.slice(0,-1)),f=""}if(f)M.push(f);return M},y=(l,c=",")=>{let h=[],p=l.length,w=c.length,f=0,M=(d)=>{if(d+w>p)return!1;for(let O=0;O<w;O++)if(l[d+O]!==c[O])return!1;return!0};while(f<p){while(f<p&&l[f]===" ")f++;if(f>=p)break;let d="",O=l[f]==='"'||l[f]==="'";if(O){let S=l[f++];while(f<p&&l[f]!==S)d+=l[f++];if(f<p)f++}else{while(f<p&&!M(f)){let S=l[f];if(S==='"'||S==="'"){d+=S,f++;while(f<p&&l[f]!==S)d+=l[f++];if(f<p)d+=l[f++]}else d+=l[f++]}d=d.trim()}if(d)h.push({value:d,quoted:O});if(M(f))f+=w}return h}}),gt=pt(mt(),1),yt=/^\[([^=\]]*)([=]*)([^\]]*)\]$/,dt=/^([^[\]]*)\[([^\]]*)]$/,Oe=(e,r,t,n)=>{if(e.startsWith("{")&&e.endsWith("}")){let o=e.substring(1,e.length-1);return K(r,o,t)?.toString()}return n?e:void 0},wt=(e,r,t,n)=>{let o=Oe(r,t,n);if(o)return K(e,o,n);let s=yt.exec(r);if(s){let[,a,u,m]=s,g=Oe(a.trim(),t,n,!0),y=Oe(m.trim(),t,n,!0);if(Array.isArray(e)&&(u==="="||u==="==")&&g)return e.find((l)=>l?.[g]==y)}let i=dt.exec(r);if(i){let[,a,u]=i;return e?.[a]?.[u]}return e?.[r]},K=(e,r,t)=>{let n=void 0,o=void 0,s=r??"",i=(y)=>{if(!y)return[y,!1];return y.endsWith("?")?[y.substring(0,y.length-1),!0]:[y,!1]},a=(y,l)=>{let[c,h]=i(l.pop());if(!c){if(t?.set!==void 0&&o!==void 0&&n!==void 0)n[o]=t.set;return y}let p=wt(y,c,e,t);if(p===void 0){if(h||t?.optional||t?.defaultValue!==void 0)return;throw Error(`Unknown path element: "${c}" in "${s}"`)}return n=y,o=c,a(p,l)},u=gt.splitNested(s,t?.separator??".","{","}"),m=void 0;if(u.length>0&&u[u.length-1].startsWith("?="))m=u.pop()?.substring(2);u.reverse();let g=a(e,u);if(g===void 0)return m??t?.defaultValue;return g},Ge=(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)},ae=(e,r,t,n,o,s)=>{let i=n?.(e)??e,a=o(i);if(a[0])return a[1];if(!r){let u=K(t,e),m=o(u);if(m[0])return m[1]}throw Error(s)},Ke=(e,r,t,n,o)=>{let s=typeof e.types==="function"?e.types(n,r.value,o):e.types?.[n];if(!s||s==="ref")return Ge(r,(a)=>K(t,a));let i=Ge(r,()=>r.value);if(Array.isArray(s)){if(!s.includes(i))throw Error(`Argument ${n.toString()} must be one of [${s.join(", ")}]: ${i}`);return i}if(typeof s==="string"){if(s.endsWith("?")){let a=s.slice(0,-1);if(r.value==="null")return A.ReplaceItem(null);if(r.value==="undefined")return A.ReplaceItem(void 0);if(r.value==="")return"";s=a}switch(s){case"any":return i;case"array":return ae(i,r.quoted,t,null,(a)=>[Array.isArray(a),a],`Argument ${n.toString()} must be an array: ${i}`);case"object":return ae(i,r.quoted,t,null,(a)=>[typeof a==="object"&&a!==null,a],`Argument ${n.toString()} must be an object: ${i}`);case"number":return ae(i,r.quoted,t,(a)=>Number(a),(a)=>[!isNaN(a),a],`Argument ${n.toString()} must be a number: ${i}`);case"boolean":return ae(i,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: ${i}`);case"string":return i.toString();default:throw Error(`Unknown type for argument ${n.toString()}: ${s}`)}}return s(i,t,n,r.quoted)},V=(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}},Ve=(e)=>!e.quoted&&e.value.startsWith("."),bt=(e)=>{let r={};for(let t of e){if(!Ve(t))continue;let n=t.value.indexOf("="),o=n>-1?t.value.slice(1,n):t.value.slice(1),s=n>-1?t.value.slice(n+1):"";if(s.length>=2){let i=s[0],a=s[s.length-1];if(i==='"'&&a==='"'||i==="'"&&a==="'")s=s.slice(1,-1)}if(!r[o])r[o]=[];r[o].push(s)}return r},ie=(e,r,t)=>{let n=st.splitWithQuotes(e??""),o=bt(n),s=n.filter((a)=>!Ve(a)),i=r.options.processArgs===!1?[]:s.map((a,u)=>Ke(r.options,a,t,u,s));return{rawArgs:s,parsedArgs:i,tags:o}},ht=(e)=>{return e!==null&&typeof e==="object"&&"action"in e},vt=(e,r)=>r.keys!==void 0&&e.key.startsWith(".")&&r.keys[e.key.substring(1)]!==void 0,Mt=async(e,r,t,n)=>{let{key:o,parent:s}=e,i=V(n.keys,o.substring(1));if(i.options.processArgs!==!1&&(typeof i.options.types==="function"||i.options.types?.[0]!==void 0))e.value=Ke(i.options,{value:e.value,quoted:!1},t,0,[]);if(typeof e.value!=="string")await j(e.value,{...n,root:{...t,parent:e.parent,parents:e.parents},filters:[...n.filters??[],...i.options.filters??[]]});let a=await i.fn({path:r,root:t,parent:s,key:o,options:n,value:e.value,args:[],rawArgs:[],tags:{}});return ht(a)?a:A.ReplaceParent(a)},He=(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},Ae=Symbol.for("@homedev/fields:OverrideResult"),Et=(e)=>({[Ae]:!0,value:e}),Ot=(e)=>{return e!==null&&typeof e==="object"&&Ae in e&&e[Ae]===!0},xe=async(e,r,t)=>{for(let n=r.length-1;n>=0;n--){let[o,s]=r[n],i=e.slice(o+2,s),a=await xe(i,He(i),t);if(typeof a==="object")return a;let u=await t(a,e);if(Ot(u))return u.value;e=e.slice(0,o)+u+e.slice(s+1)}return e},At=async(e,r)=>xe(e,He(e),r),kt=(e)=>{let r=/%{\s*section\s+([\w\d_-]+)\s*}([\s\S]*?)%{\s*endsection\s+\1\s*}/g,t,n=[],o=[];while((t=r.exec(e))!==null){let[a,u,m]=t,g=t.index,y=g+a.length;if(e[y]===`
|
|
2
|
+
`)y++;o.push({start:g,end:y,name:u,body:m})}let s=[],i=0;for(let{start:a,end:u,name:m,body:g}of o){if(a>i)s.push(e.slice(i,a));i=u;let y={},l=g,c=/(^|\r?\n)[ \t]*---[ \t]*(\r?\n|$)/m.exec(g);if(c){let h=g.slice(0,c.index),p=c.index+c[0].length;l=g.slice(p);let w=h.trim();if(w.length>0)try{y=Bun.YAML.parse(w)??{}}catch(f){throw Error(`Failed to parse YAML config for section ${m}: ${f.message}`)}}else if(/^\r?\n/.test(l))l=l.replace(/^\r?\n/,"");if(/[ \t]*\r?\n$/.test(l))l=l.replace(/[\t]*\r?\n$/,"");n.push({name:m,config:y,content:l})}if(i<e.length)s.push(e.slice(i));return{sections:n,content:s.join("")}},St=async(e,r,t,n)=>{let o=r?.onSection?kt(e):null;if(!o)return[e,null];let s=o.content;for(let i of o.sections){let a=await ke(t,i.name,n,r);if(a.action===G.ReplaceItem)i.name=a.by;if(Object.keys(i.config).length>0){if(await r.onSectionConfig?.(i,t,n,r)!==!1)await j(i.config,r)}let u=await r.onSection(i,t,n,r);if(i.trim)i.content=i.content.trim();if(i.indent)i.content=i.content.split(`
|
|
3
|
+
`).map((m)=>" ".repeat(i.indent)+m).join(`
|
|
4
|
+
`);if(u===!0||i.show)s=s+i.content;else if(typeof u==="string")s=s+u}return[s,o]},jt=(e)=>{return e!==null&&typeof e==="object"&&"action"in e},Dt=/([\w\d.-_/]+):(.+)/,Rt=async(e,r,t,n)=>{let o=await(async()=>{let s=Dt.exec(e);if(!s)return await K(r,e);let[i,a,u]=s,m=V(n.sources,a),g=ie(u,m,r);return await m.fn({args:g.parsedArgs,rawArgs:g.rawArgs,tags:g.tags,key:a,options:n,root:r,path:t,value:null})})();if(o===null||o===void 0)return"";if(typeof o==="object")return Et(o);return o},ke=async(e,r,t,n)=>{let[o,s]=await St(r,n,e,t),i=await At(o,(a)=>Rt(a,t,e,n));if(jt(i))return i;if(i===o){if(s?.sections.length)return A.ReplaceItem(i);return A.Explore()}if(typeof i==="string"){let a=await ke(e,i,t,n);if(a.action!==G.Explore)return a}return A.ReplaceItem(i)},j=async(e,r)=>{return r??={},await at(e,async(t)=>{let n=[...t.path,t.key].join(".");if(r?.filters?.length&&r.filters.some((a)=>a.test(n)))return A.NoExplore();let o=t.path.length===0,s=t.parents.length>0?t.parents.toReversed():[];if(o){if(s.length>0)throw Error("Root object should not have a parent");s=r?.root?.parents?[r.root.parent,...r.root.parents.toReversed()]:[]}let i={...e,...r.root,this:t.parent,parent:s.length>0?s[0]:null,parents:s};try{if(t.key.startsWith("$"))return A.NoExplore();let a=A.Explore();if(typeof t.value==="string")switch(a=await ke(n,t.value,i,r),a.action){case G.Explore:break;case G.ReplaceItem:t.value=a.by;break;default:return a}if(vt(t,r))a=await Mt(t,n,i,r);return a}catch(a){throw Error(`${a.message}
|
|
5
|
+
(${n})`)}}),e},H=(e,r)=>r?{fn:(t)=>e(...t.args),types:r}:(t)=>e(...t.args),Se=(e,r)=>Object.fromEntries(e.map((t)=>[t.name,H(t,r?.types?.[t.name])])),D=(e,r)=>Object.fromEntries((r?.keys??Object.keys(e)).map((t)=>[t,H(e[t],r?.types?.[t])]));var $e={};R($e,{writeOutputs:()=>P,writeOutput:()=>ue,writeFormat:()=>le,locate:()=>C,loadFormat:()=>x,importList:()=>fe,importGlob:()=>Re,globMap:()=>q,exists:()=>U});import qe from"fs/promises";import De from"path";import $t from"path";import _t from"fs/promises";import er from"fs/promises";import Pe from"path";import Xe from"path";import ze from"path";var U=async(e)=>{try{return await qe.access(e,qe.constants.R_OK),!0}catch{return!1}},C=async(e,r)=>{let t=!De.isAbsolute(e)&&r?["",...r]:[""];for(let n of t){let o=De.join(n,e);if(await U(o))return De.resolve(o)}throw Error(`File not found: "${e}"`)},x=async(e,r)=>{let t=await C(e,r?.dirs),n=await Bun.file(t).text(),o=$t.dirname(t),s={"[.]json$":JSON.parse,"[.](yml|yaml)$":Bun.YAML.parse,"[.]toml$":Bun.TOML.parse,...r?.parsers},i=Object.entries(s).find((a)=>t.match(a[0]));if(!i)throw Error(`Unhandled file type: ${e}`);return{content:i[1](n),fullPath:t,folderPath:o}},le=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())}},q=async(e,r)=>{if(typeof e==="string"&&!e.includes("*"))return await r.map(e,0,[]);let t=await Array.fromAsync(_t.glob(e,{cwd:r.cwd})),n=r.filter?t.filter(r.filter):t;return await Promise.all(n.map(r.map))},P=async(e,r)=>{if(r?.targetDirectory&&r?.removeFirst)try{await er.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 ue(t,r)},ue=async(e,r)=>{let t=Pe.join(r?.targetDirectory??".",e.name),n=Pe.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 er.mkdir(n,{recursive:!0})}catch(o){throw Error(`Failed to create target directory "${n}" for output "${t}": ${o.message}`)}try{await le(t,e.value,e.type??"text")}catch(o){throw Error(`Failed to write output "${t}": ${o.message}`)}},rr=(e)=>e?ze.isAbsolute(e)?e:ze.join(process.cwd(),e):process.cwd(),fe=async(e,r)=>{let t=[];for(let n of e)try{let o=!Xe.isAbsolute(n)?Xe.join(rr(r?.cwd),n):n;if(r?.filter?.(o)===!1)continue;let s=await import(o);if(r?.resolveDefault==="only"&&!s.default)throw Error(`Module ${n} does not have a default export`);let i=r?.resolveDefault?s.default??s:s,a=r?.map?await r.map(i,n):i;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},Re=async(e,r)=>{let t=[];for(let n of e){let o=await Array.fromAsync(new Bun.Glob(n).scan({cwd:rr(r?.cwd),absolute:!0}));t.push(...await fe(o,r))}return t};var We={};R(We,{toObjectWithKey:()=>_e,toObject:()=>X,toList:()=>W,sortBy:()=>Le,nonNullMap:()=>Ne,defined:()=>Fe,deepClone:()=>$,asyncMap:()=>Ce});var W=(e,r="name")=>Object.entries(e).map(([t,n])=>({[r]:t,...n})),_e=(e,r="name")=>Object.fromEntries(e.map((t)=>[t[r],t])),X=(e,r="name")=>Object.fromEntries(e.map((t)=>{let{[r]:n,...o}=t;return[n,o]})),Ne=(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},Fe=(e,r="Value is undefined")=>{if(e===void 0||e===null)throw Error(r);return e},Le=(e,r,t=(n,o)=>n-o)=>e.slice().sort((n,o)=>t(r(n),r(o))),Ce=async(e,r)=>Promise.all(e.map(r)),$=(e)=>{if(typeof structuredClone<"u")try{return structuredClone(e)}catch{}return JSON.parse(JSON.stringify(e))};var Jr={};R(Jr,{defaultProcessors:()=>Te});var tr={};R(tr,{navigate:()=>ce,find:()=>Ie,NavigateResult:()=>b,NavigateAction:()=>pe});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 b{action;by;skipSiblings;reexplore;constructor(e,r,t,n){this.action=e,this.by=r,this.skipSiblings=t,this.reexplore=n}static _explore=new b(0);static _noExplore=new b(2);static _skipSiblings=new b(1);static _deleteParent=new b(4);static ReplaceParent(e,r){return new b(3,e,void 0,r)}static SkipSiblings(){return b._skipSiblings}static Explore(){return b._explore}static NoExplore(){return b._noExplore}static DeleteParent(){return b._deleteParent}static MergeParent(e){return new b(5,e)}static ReplaceItem(e,r){return new b(6,e,r)}static DeleteItem(e){return new b(7,void 0,e)}}var ce=async(e,r)=>{let t=new WeakSet,n=[],o=[],s=async(a,u,m)=>{let g=a===null,y=g?b.Explore():await r({key:a,value:u,path:n,parent:m,parents:o});if(u&&typeof u==="object"&&y.action===0){if(t.has(u))return y;if(t.add(u),!g)n.push(a),o.push(m);let l=u;while(await i(l,a,m))l=m[a];if(!g)o.pop(),n.pop()}return y},i=async(a,u,m)=>{let g=Object.keys(a),y=g.length;for(let l=0;l<y;l++){let c=g[l],h=a[c],p=await s(c,h,a),w=p.action;if(w===0||w===2)continue;if(w===6){if(a[c]=p.by,p.skipSiblings)return;continue}if(w===7){if(delete a[c],p.skipSiblings)return;continue}if(w===1)return;if(w===3){if(u===null)throw Error("Cannot replace root object");if(m[u]=p.by,p.reexplore)return!0;return}if(w===4){if(u===null)throw Error("Cannot delete root object");delete m[u];return}if(w===5)delete a[c],Object.assign(a,p.by)}};await s(null,e,null)},Ie=async(e,r)=>{let t=[];return await ce(e,(n)=>{if(r([...n.path,n.key].join("."),n.value))t.push(n.value);return b.Explore()}),t};var nr=(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 b.SkipSiblings()}});import Nt from"path";var or=(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&&Nt.dirname(t.file))}return b.DeleteItem()}});var sr={};R(sr,{mergeAll:()=>B,merge:()=>F});var F=(e,r,t)=>{for(let n of Object.keys(r)){if(e[n]===void 0)continue;let o=r[n],s=e[n];if(typeof s!==typeof o||Array.isArray(s)!==Array.isArray(o)){let a=t?.mismatch?.(n,s,o,e,r);if(a!==void 0){r[n]=a;continue}throw Error(`Type mismatch: ${n}`)}let i=t?.mode?.(n,s,o,e,r)??r[".merge"]??"merge";switch(i){case"source":r[n]=s;continue;case"target":continue;case"skip":delete r[n],delete e[n];continue;case"merge":break;default:throw Error(`Unknown merge mode: ${i}`)}if(typeof s==="object")if(Array.isArray(s))o.push(...s);else{if(t?.navigate?.(n,s,o,e,r)===!1)continue;F(s,o,t)}else{if(s===o)continue;let a=t?.conflict?.(n,s,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]},B=(e,r)=>{let t={};for(let n of e.toReversed())F(n,t,r);return t};var ar={};R(ar,{CacheManager:()=>me});class me{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 lr={};R(lr,{select:()=>v});var Ft=Object.create,{getPrototypeOf:Lt,defineProperty:ir,getOwnPropertyNames:Ct}=Object,Wt=Object.prototype.hasOwnProperty,It=(e,r,t)=>{t=e!=null?Ft(Lt(e)):{};let n=r||!e||!e.__esModule?ir(t,"default",{value:e,enumerable:!0}):t;for(let o of Ct(e))if(!Wt.call(n,o))ir(n,o,{get:()=>e[o],enumerable:!0});return n},Ut=(e,r)=>()=>(r||e((r={exports:{}}).exports,r),r.exports),Bt=Ut((e,r)=>{var{defineProperty:t,getOwnPropertyNames:n,getOwnPropertyDescriptor:o}=Object,s=Object.prototype.hasOwnProperty,i=new WeakMap,a=(l)=>{var c=i.get(l),h;if(c)return c;if(c=t({},"__esModule",{value:!0}),l&&typeof l==="object"||typeof l==="function")n(l).map((p)=>!s.call(c,p)&&t(c,p,{get:()=>l[p],enumerable:!(h=o(l,p))||h.enumerable}));return i.set(l,c),c},u=(l,c)=>{for(var h in c)t(l,h,{get:c[h],enumerable:!0,configurable:!0,set:(p)=>c[h]=()=>p})},m={};u(m,{splitWithQuotes:()=>y,splitNested:()=>g}),r.exports=a(m);var g=(l,c,h="(",p=")")=>{let w=0,f="",M=[];for(let d of l){if(f+=d,d===h)w++;if(d===p)w--;if(w===0&&d===c)M.push(f.slice(0,-1)),f=""}if(f)M.push(f);return M},y=(l,c=",")=>{let h=[],p=l.length,w=c.length,f=0,M=(d)=>{if(d+w>p)return!1;for(let O=0;O<w;O++)if(l[d+O]!==c[O])return!1;return!0};while(f<p){while(f<p&&l[f]===" ")f++;if(f>=p)break;let d="",O=l[f]==='"'||l[f]==="'";if(O){let S=l[f++];while(f<p&&l[f]!==S)d+=l[f++];if(f<p)f++}else{while(f<p&&!M(f)){let S=l[f];if(S==='"'||S==="'"){d+=S,f++;while(f<p&&l[f]!==S)d+=l[f++];if(f<p)d+=l[f++]}else d+=l[f++]}d=d.trim()}if(d)h.push({value:d,quoted:O});if(M(f))f+=w}return h}}),Tt=It(Bt(),1),Jt=/^\[([^=\]]*)([=]*)([^\]]*)\]$/,Yt=/^([^[\]]*)\[([^\]]*)]$/,Ue=(e,r,t,n)=>{if(e.startsWith("{")&&e.endsWith("}")){let o=e.substring(1,e.length-1);return v(r,o,t)?.toString()}return n?e:void 0},Qt=(e,r,t,n)=>{let o=Ue(r,t,n);if(o)return v(e,o,n);let s=Jt.exec(r);if(s){let[,a,u,m]=s,g=Ue(a.trim(),t,n,!0),y=Ue(m.trim(),t,n,!0);if(Array.isArray(e)&&(u==="="||u==="==")&&g)return e.find((l)=>l?.[g]==y)}let i=Yt.exec(r);if(i){let[,a,u]=i;return e?.[a]?.[u]}return e?.[r]},v=(e,r,t)=>{let n=void 0,o=void 0,s=r??"",i=(y)=>{if(!y)return[y,!1];return y.endsWith("?")?[y.substring(0,y.length-1),!0]:[y,!1]},a=(y,l)=>{let[c,h]=i(l.pop());if(!c){if(t?.set!==void 0&&o!==void 0&&n!==void 0)n[o]=t.set;return y}let p=Qt(y,c,e,t);if(p===void 0){if(h||t?.optional||t?.defaultValue!==void 0)return;throw Error(`Unknown path element: "${c}" in "${s}"`)}return n=y,o=c,a(p,l)},u=Tt.splitNested(s,t?.separator??".","{","}"),m=void 0;if(u.length>0&&u[u.length-1].startsWith("?="))m=u.pop()?.substring(2);u.reverse();let g=a(e,u);if(g===void 0)return m??t?.defaultValue;return g};var ge=(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 ye=(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 de=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 j(n,{...e.options,root:{...e.root,result:r}}),n}return await v({...e.root,result:r},t.selector)};var ur={};R(ur,{PathManager:()=>I});import T from"path";class I{constructor(){}static normalize(e){return T.normalize(T.resolve(e))}static resolveInContext(e,r){let t=r??process.cwd(),n=T.isAbsolute(e)?e:T.join(t,e);return this.normalize(n)}static isDirectoryPattern(e){return e.endsWith("/")}static isGlobPattern(e){return e.includes("*")}static toAbsolute(e,r){if(T.isAbsolute(e))return e;return T.join(r??process.cwd(),e)}}var fr={};R(fr,{conditionPredicatesTypes:()=>z,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!=="")},z={and:()=>"boolean",or:()=>"boolean",xor:()=>"boolean",true:()=>"boolean",false:()=>"boolean",lt:()=>"number",le:()=>"number",gt:()=>"number",ge:()=>"number"};var pr=()=>({each:{filters:[/select|model/],fn:async(e)=>{let r=e.value;delete e.parent[e.key];let t=await ye(e),n=await ge(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=B([r.model,...Array.isArray(r.extend.model)?r.extend.model:[r.extend.model]]);let o=[];for(let s=0;s<t.length;s++){let i=$(n);if(await j(i,{...e.options,root:{...e.root,index:s,item:t[s],instance:i}}),r.extend?.result){let a=r.extend.result;i=B([i,...Array.isArray(a)?a:[a]])}o.push(await de(e,i))}return o}}});var cr=()=>({map:{filters:[/select|model/],fn:async(e)=>{delete e.parent[e.key];let r=await ye(e),t=await ge(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 s=$(t);await j(s,{...e.options,root:{...e.root,index:o,item:r[o],instance:s}}),n.push(await de(e,s))}return n}}});var mr=()=>({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 gr=()=>({extends:async(e)=>{let r=async(t,n)=>{for(let o of Array.isArray(n)?n:[n]){let s=await v(e.root,o),i=$(s);if(i[e.key])await r(i,i[e.key]);await j(i,{...e.options}),F(i,t),delete t[e.key]}};return await r(e.parent,e.value),b.Explore()},group:(e)=>{let r=e.root.parent,t=e.value,{items:n,...o}=t;return t.items.forEach((s)=>r.push({...o,...s})),b.DeleteParent()}});var yr=(e)=>({skip:{types:{0:"boolean"},fn:(r)=>r.value?b.DeleteParent():b.DeleteItem()},metadata:({path:r,value:t})=>{return e.metadata(r,t),b.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 b.DeleteItem();if(typeof o==="string")return(await j({value:o},{...r.options,root:{...r.root}})).value;return b.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 b.ReplaceParent(t.cases[t.from],!0);if(t.default!==void 0)return b.ReplaceParent(t.default,!0);return b.DeleteParent()}});var dr=()=>({from:async({root:e,parent:r,value:t})=>{let n=await v(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 F(n,r.content),r.content}return n}});import wr from"node:vm";var br=(e)=>({modules:async(r)=>{for(let[t,n]of Object.entries(r.value)){let o=wr.createContext({console,objector:e,document:r.root}),s=new wr.SourceTextModule(n,{identifier:t,context:o});await s.link((i)=>{throw Error(`Module ${i} is not allowed`)}),await s.evaluate(),e.sources(Object.fromEntries(Object.entries(s.namespace).map(([i,a])=>[`${t}.${i}`,(u)=>a(u,...u.args)])))}return b.DeleteItem()}});var hr=()=>({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 b.DeleteItem()}}}});var vr=()=>({let:{fn:(e)=>{let r=e.value;return Object.assign(e.root,r),b.DeleteItem()}}});var Mr=()=>({tap:{fn:(e)=>{return console.log(`[tap] ${e.path}:`,e.value),e.value}}});import Er from"fs/promises";import ee from"path";var Or=(e)=>({include:async(r)=>{let{file:t}=r.options.globalContext;return await q(r.args[0],{cwd:ee.dirname(t),filter:(n)=>ee.basename(t)!==n,map:async(n)=>e.load(n,ee.dirname(t),r.root)})},exists:async({args:[r]})=>await U(r),file:async(r)=>await Er.readFile(await C(r.args[0],e.getIncludeDirectories())).then((t)=>t.toString()),scan:async(r)=>{let t=[],o=(()=>{let a=r.args[2]??["**/node_modules/**"],u=typeof a==="string"?a.split(",").map((m)=>m.trim()):a;if(!Array.isArray(u))throw Error("Scan exclusion must be a list");return u})(),{file:s}=r.options.globalContext,i=r.args[1]?await C(r.args[1],e.getIncludeDirectories()):ee.dirname(s);for await(let a of Er.glob(r.args[0],{cwd:i,exclude:(u)=>o.some((m)=>ee.matchesGlob(u,m))}))t.push(a);return t}});var Ar=()=>D({env:(e)=>process.env[e]});var kr={};R(kr,{tokenize:()=>Be,snake:()=>Y,pascal:()=>J,padBlock:()=>L,changeCase:()=>Q,capital:()=>re,camel:()=>te});var J=(e)=>e.replace(/((?:[_ ]+)\w|^\w)/g,(r,t)=>t.toUpperCase()).replace(/[_ ]/g,""),re=(e)=>e.replace(/((?:[ ]+)\w|^\w)/g,(r,t)=>t.toUpperCase()),te=(e)=>{let r=J(e);return r.charAt(0).toLowerCase()+r.slice(1)},Y=(e,r="_")=>e.replace(/([a-z])([A-Z])/g,`$1${r}$2`).replace(/\s+/g,r).toLowerCase(),Q=(e,r)=>{switch(r){case"upper":return e.toUpperCase();case"lower":return e.toLowerCase();default:return e}},L=(e,r,t=`
|
|
6
|
+
`,n=" ")=>{let o=n.repeat(r);return e.split(t).map((s)=>o+s).join(t)},Be=(e,r,t=/\${([^}]+)}/g)=>{return e.replace(t,(n,o)=>{let s=r[o];if(s===null||s===void 0)return"";if(typeof s==="string")return s;if(typeof s==="number"||typeof s==="boolean")return String(s);return String(s)})};var we=(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`[
|
|
7
|
+
${e.map((i)=>`${o}${we(i,r+1)},`).join(`
|
|
5
8
|
`)}
|
|
6
9
|
${n}]`}else if(typeof e==="object"){let s=Object.entries(e).sort((a,u)=>t?.sortKeys?a[0].localeCompare(u[0]):0);if(s.length===0)return"{}";return`{
|
|
7
|
-
${s.map(([a,u])=>`${o}${a} = ${
|
|
10
|
+
${s.map(([a,u])=>`${o}${a} = ${we(u,r+1,t)}`).join(`
|
|
8
11
|
`)}
|
|
9
|
-
${n}}`}else return String(e)},
|
|
10
|
-
`).replaceAll("\\$","$").replaceAll("\\t","\t")};var
|
|
11
|
-
`,o=t.padChar?.[0]??" ";return
|
|
12
|
-
`,m):g},list:({args:e})=>
|
|
13
|
-
`,f):d}return y}}});var H=async(e,r,t)=>e.rawArgs[r].quoted?e.rawArgs[r].value:await v(e.root,e.rawArgs[r].value,{defaultValue:t}),Mr=()=>({switch:{processArgs:!1,fn:async(e)=>{let r=await H(e,0,!1),t=await H(e,1);if(t[r]===void 0){if(e.rawArgs.length>2)return H(e,2);throw Error(`Unhandled switch case: ${r}`)}return t[r]}}});var Or=()=>S({log:console.log});var Sr=()=>({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))},...S(_,{types:Y})});var Fr=(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 H(r,t,null);if(o!==null)return o}if(r.tags.nullable?.length)return b.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],n=e.getSection(t);if(!n)throw Error(`Section not found: ${t}`);return n.content}});var $r=()=>({convert:({args:[e,r,t]})=>{switch(r){case"string":return String(e);case"number":{let n=Number(e);if(!isNaN(n))return b.ReplaceItem(n);break}case"boolean":if(e==="true"||e===!0||e===1||e==="1"||e==="yes"||e==="on")return b.ReplaceItem(!0);else if(e==="false"||e===!1||e===0||e==="0"||e==="no"||e==="off")return b.ReplaceItem(!1);break;default:throw Error(`Unsupported type for convert: ${r}`)}if(t!==void 0)return b.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 b.ReplaceItem(n)},typeOf:({args:[e]})=>{if(e===null)return"null";else if(Array.isArray(e))return"array";else return typeof e}});var _r=()=>({...S({add:(...e)=>e.reduce((r,t)=>r+t,0),subtract:(e,r)=>e-r,multiply:(...e)=>e.reduce((r,t)=>r*t,1),divide:(e,r)=>{if(r===0)throw Error("Division by zero");return e/r},modulo:(e,r)=>e%r,power:(e,r)=>Math.pow(e,r),sqrt:(e)=>Math.sqrt(e),abs:(e)=>Math.abs(e),floor:(e)=>Math.floor(e),ceil:(e)=>Math.ceil(e),round:(e,r)=>{let t=Math.pow(10,r??0);return Math.round(e*t)/t},min:(...e)=>Math.min(...e),max:(...e)=>Math.max(...e),clamp:(e,r,t)=>Math.max(r,Math.min(t,e)),random:(e,r)=>{let t=e??0,n=r??1;return Math.random()*(n-t)+t}})});var jr=()=>({now:()=>new Date,timestamp:(e)=>{let r=e.args?.[0];return(r?new Date(r):new Date).getTime()},iso:(e)=>{let r=e.args?.[0];return(r?new Date(r):new Date).toISOString()},utc:(e)=>{let r=e.args?.[0];return(r?new Date(r):new Date).toUTCString()},format:(e)=>{let r=e.args?.[0],t=e.args?.[1],n=new Date(r),o=n.getFullYear(),s=String(n.getMonth()+1).padStart(2,"0"),i=String(n.getDate()).padStart(2,"0"),a=String(n.getHours()).padStart(2,"0"),u=String(n.getMinutes()).padStart(2,"0"),m=String(n.getSeconds()).padStart(2,"0");return t.replace("YYYY",String(o)).replace("MM",s).replace("DD",i).replace("HH",a).replace("mm",u).replace("ss",m)},parse:(e)=>{let r=e.args?.[0];return new Date(r).getTime()},year:(e)=>{let r=e.args?.[0];return(r?new Date(r):new Date).getFullYear()},month:(e)=>{let r=e.args?.[0];return(r?new Date(r):new Date).getMonth()+1},day:(e)=>{let r=e.args?.[0];return(r?new Date(r):new Date).getDate()},dayOfWeek:(e)=>{let r=e.args?.[0];return(r?new Date(r):new Date).getDay()},hours:(e)=>{let r=e.args?.[0];return(r?new Date(r):new Date).getHours()},minutes:(e)=>{let r=e.args?.[0];return(r?new Date(r):new Date).getMinutes()},seconds:(e)=>{let r=e.args?.[0];return(r?new Date(r):new Date).getSeconds()}});var Rr=()=>{return{unique:(e)=>{let r=e.args?.[0]??e.value,t=e.args?.[1];if(!Array.isArray(r))return r;let n=new Set;return r.filter((o)=>{let s=typeof t==="function"?t(o):t?o[t]:o;if(n.has(s))return!1;return n.add(s),!0})},groupBy:(e)=>{let r=e.args?.[0]??e.value,t=e.args?.[1];if(!Array.isArray(r))return r;let n={};return r.forEach((o)=>{let s=typeof t==="function"?String(t(o)):String(o[t]);if(!n[s])n[s]=[];n[s].push(o)}),n},partition:(e)=>{let r=e.args?.[0]??e.value,t=e.args?.[1];if(!Array.isArray(r))return[[],[]];if(typeof t!=="function")return[r,[]];let n=[],o=[];return r.forEach((s)=>{(t(s)?n:o).push(s)}),[n,o]},chunk:(e)=>{let r=e.args?.[0]??e.value,t=e.args?.[1]??1;if(!Array.isArray(r))return[];let n=[];for(let o=0;o<r.length;o+=t)n.push(r.slice(o,o+t));return n},flatten:(e)=>{let r=e.args?.[0]??e.value,t=e.args?.[1]??1;if(!Array.isArray(r))return[r];let n=[],o=(s,i)=>{for(let a of s)if(Array.isArray(a)&&i>0)o(a,i-1);else n.push(a)};return o(r,t),n},compact:(e)=>{let r=e.args?.[0]??e.value;if(!Array.isArray(r))return r;return r.filter((t)=>t!==null&&t!==void 0)},head:(e)=>{let r=e.args?.[0]??e.value,t=e.args?.[1];if(!Array.isArray(r))return r;return t?r.slice(0,t):r[0]},tail:(e)=>{let r=e.args?.[0]??e.value,t=e.args?.[1];if(!Array.isArray(r))return r;return t?r.slice(-t):r[r.length-1]}}};import{createHash as X}from"crypto";var Nr=()=>({md5:(e)=>{let r=e.args?.[0]??e.value;return X("md5").update(r).digest("hex")},sha1:(e)=>{let r=e.args?.[0]??e.value;return X("sha1").update(r).digest("hex")},sha256:(e)=>{let r=e.args?.[0]??e.value;return X("sha256").update(r).digest("hex")},sha512:(e)=>{let r=e.args?.[0]??e.value;return X("sha512").update(r).digest("hex")},hash:(e)=>{let r=e.args?.[0]??e.value,t=e.args?.[1]??"sha256";return X(t).update(r).digest("hex")},base64Encode:(e)=>{let r=e.args?.[0]??e.value,t=typeof r==="string"?r:JSON.stringify(r);return Buffer.from(t).toString("base64")},base64Decode:(e)=>{let r=e.args?.[0]??e.value;return Buffer.from(r,"base64").toString("utf-8")},hexEncode:(e)=>{let r=e.args?.[0]??e.value;return Buffer.from(r).toString("hex")},hexDecode:(e)=>{let r=e.args?.[0]??e.value;return Buffer.from(r,"hex").toString("utf-8")}});var Wr=()=>({test:(e)=>{let r=e.args?.[0],t=e.args?.[1],n=e.args?.[2];return new RegExp(r,n).test(t)},match:(e)=>{let r=e.args?.[0],t=e.args?.[1],n=e.args?.[2],o=new RegExp(r,n);return t.match(o)},matchAll:(e)=>{let r=e.args?.[0],t=e.args?.[1],n=e.args?.[2],o=new RegExp(r,n);return Array.from(t.matchAll(o))},replace:(e)=>{let r=e.args?.[0],t=e.args?.[1],n=e.args?.[2],o=e.args?.[3],s=new RegExp(r,o);return n.replace(s,t)},replaceAll:(e)=>{let r=e.args?.[0],t=e.args?.[1],n=e.args?.[2],o=e.args?.[3]??"g",s=new RegExp(r,o);return n.replace(s,t)},split:(e)=>{let r=e.args?.[0],t=e.args?.[1],n=e.args?.[2],o=new RegExp(r,n);return t.split(o)},exec:(e)=>{let r=e.args?.[0],t=e.args?.[1],n=e.args?.[2];return new RegExp(r,n).exec(t)},search:(e)=>{let r=e.args?.[0],t=e.args?.[1],n=e.args?.[2],o=new RegExp(r,n);return t.search(o)}});import{resolve as Dt,dirname as Lt,basename as It,normalize as Ut,join as Bt}from"path";var Cr=()=>({...S({pathJoin:(...e)=>Bt(...e),resolve:(...e)=>Dt(...e),dirname:(e)=>Lt(e),basename:(e,r)=>It(e,r),normalize:(e)=>Ut(e),extname:(e)=>{let r=/\.[^.]*$/.exec(e);return r?r[0]:""},relative:(e,r)=>{let t=e.split("/"),n=r.split("/"),o=0;while(o<t.length&&o<n.length&&t[o]===n[o])o++;let s=t.length-o,i=n.slice(o);return[...Array(s).fill("..")].concat(i).join("/")},isAbsolute:(e)=>e.startsWith("/"),segments:(e)=>e.split("/").filter(Boolean)})});var Dr=()=>({isEmail:(e)=>{let r=e.args?.[0]??e.value;return/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(r)},isUrl:(e)=>{let r=e.args?.[0]??e.value;try{return new URL(r),!0}catch{return!1}},isJson:(e)=>{let r=e.args?.[0]??e.value;try{return JSON.parse(r),!0}catch{return!1}},isUuid:(e)=>{let r=e.args?.[0]??e.value;return/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i.test(r)},minLength:(e)=>{let r=e.args?.[0]??e.value,t=e.args?.[1];return r?.length>=t},maxLength:(e)=>{let r=e.args?.[0]??e.value,t=e.args?.[1];return r?.length<=t},length:(e)=>{let r=e.args?.[0]??e.value,t=e.args?.[1];return r?.length===t},isNumber:(e)=>{let r=e.args?.[0]??e.value;return typeof r==="number"&&!isNaN(r)},isString:(e)=>{return typeof(e.args?.[0]??e.value)==="string"},isBoolean:(e)=>{return typeof(e.args?.[0]??e.value)==="boolean"},isArray:(e)=>{let r=e.args?.[0]??e.value;return Array.isArray(r)},isObject:(e)=>{let r=e.args?.[0]??e.value;return r!==null&&typeof r==="object"&&!Array.isArray(r)},isEmpty:(e)=>{let r=e.args?.[0]??e.value;if(r===null||r===void 0)return!0;if(typeof r==="string"||Array.isArray(r))return r.length===0;if(typeof r==="object")return Object.keys(r).length===0;return!1},isTruthy:(e)=>{return!!(e.args?.[0]??e.value)},isFalsy:(e)=>{return!(e.args?.[0]??e.value)},inRange:(e)=>{let r=e.args?.[0],t=e.args?.[1],n=e.args?.[2];return r>=t&&r<=n},matches:(e)=>{let r=e.args?.[0],t=e.args?.[1];return new RegExp(t).test(r)},includes:(e)=>{let r=e.args?.[0],t=e.args?.[1];if(typeof r==="string")return r.includes(String(t));return Array.isArray(r)&&r.includes(t)},startsWith:(e)=>{let r=e.args?.[0],t=e.args?.[1];return r.startsWith(t)},endsWith:(e)=>{let r=e.args?.[0],t=e.args?.[1];return r.endsWith(t)}});var Lr=(e)=>e.keys(ze(e)).keys(er(e)).keys(sr()).keys(ar()).keys(fr()).keys(ir()).keys(lr()).keys(ur(e)).keys(cr(e)).keys(mr()).keys(gr()).keys(yr()).sources(wr(e)).sources(br()).sources(Er()).sources($r()).sources(Ar()).sources(kr()).sources(Mr()).sources(Or()).sources(Sr()).sources(Fr(e)).sources(_r()).sources(jr()).sources(Rr()).sources(Nr()).sources(Wr()).sources(Cr()).sources(Dr()).fieldOptions({onSection:(r)=>{e.section(r)}});import fe from"path";class Me{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(I.isGlobPattern(o)){let s=new Bun.Glob(o);for await(let i of s.scan({cwd:r,absolute:!0}))if(!t.included.includes(i))n.push(i)}else if(I.isDirectoryPattern(o)){let s=fe.isAbsolute(o)?o:fe.join(r,o);if(!this.includeDirectories.includes(s))this.includeDirectories.push(s)}else n.push(o);return n}buildSearchDirs(e){let r=e?[e]:[];return r.push(...this.includeDirectories.map((t)=>fe.isAbsolute(t)?t:fe.join(e??process.cwd(),t))),r}}class Oe{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 s of o)R(await this.loadFn(s,e.folderPath,{parent:e.content,...r},!0,t),e.content)}}var F={};N(F,{writeOutputs:()=>te,writeOutput:()=>be,writeFormat:()=>we,tokenize:()=>hr,toObjectWithKey:()=>Ge,toObject:()=>ne,toList:()=>D,sortBy:()=>He,snake:()=>G,select:()=>v,processFields:()=>O,pascal:()=>K,padBlock:()=>W,nonNullMap:()=>Ve,navigate:()=>Ee,mergeAll:()=>T,merge:()=>R,makeFieldProcessorMap:()=>S,makeFieldProcessorList:()=>De,makeFieldProcessor:()=>z,locate:()=>C,loadFormat:()=>ee,importList:()=>he,importGlob:()=>Qe,globMap:()=>re,getProcessor:()=>P,getArgs:()=>ye,find:()=>xe,exists:()=>J,defined:()=>Ze,deepClone:()=>$,conditionPredicates:()=>_,changeCase:()=>V,capital:()=>ie,camel:()=>le,asyncMap:()=>Xe,NavigateResult:()=>b,NavigateAction:()=>ve});j(F,Qr(Jr(),1));var Ea=F;class Zt{includeManager=new Me;includeProcessor;cacheManager=new Ae(100);outputs=[];vars={};fields={sources:{},keys:{}};objectMetadata={};currentContext=null;sections={};constructor(){this.includeProcessor=new Oe(this.includeManager,this.load.bind(this)),this.use(Lr)}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 O(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,n,o){let s=this.includeManager.snapshot();try{this.includeManager.reset();let i=this.includeManager.buildSearchDirs(r);if(o)this.currentContext=o;this.currentContext??={included:[],document:null};let a=await ee(e,{dirs:i}),u=I.normalize(a.fullPath);if(this.currentContext.included.push(u),!a.content)return null;let m=this.cacheManager.get(u),g;if(m)g=m.raw;else g=a.content,this.cacheManager.set(u,{raw:g,timestamp:Date.now()});let y=$(g);a.content=y,await this.includeProcessor.processIncludes(a,t,this.currentContext);let l;if(n!==!0)l=await this.loadObject(a.content,t,{fileName:a.fullPath,folderPath:a.folderPath,fullPath:a.fullPath});else l=a.content;return this.currentContext.document=l,l}catch(i){throw this.includeManager.restore(s),i}finally{this.includeManager.restore(s)}}async writeAll(e){await te(this.getOutputs(),e)}}export{Ea as default,Zt as Objector};
|
|
12
|
+
${n}}`}else return String(e)},ne=(e)=>{if(!e)return e;return e.replaceAll("\\n",`
|
|
13
|
+
`).replaceAll("\\$","$").replaceAll("\\t","\t")};var Sr=()=>({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 n=t.join?.[0]??`
|
|
14
|
+
`,o=t.padChar?.[0]??" ";return L(e,r??2,n,o)}},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 n=!!(t?.sort?.length||t?.sortKeys?.length);return we(e,0,{sortKeys:n})}}throw Error("Unsupported format: "+String(r))}},...D({pascal:J,camel:te,capital:re,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)=>Q(Y(e,"_"),r),kebab:(e,r)=>Q(Y(e,"-"),r),encode:(e,r)=>Buffer.from(e).toString(r??"base64"),decode:(e,r)=>Buffer.from(e,r??"base64").toString()})});var jr=()=>({...D({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],s=t.finalize?.length>0,i=ne(o);if(typeof e==="string"){if(s&&e.length&&i)return e+i;return e}if(!Array.isArray(e))throw Error("Object is not a list");let a=((n?.length)?e.map((y)=>v({...r,...y},n)):e).join(i),u=t.pad?.[0]??"0",m=t.padChar?.[0]??" ",g=s&&a.length&&i?a+i:a;return u?L(g,parseInt(u),`
|
|
15
|
+
`,m):g},list:({args:e})=>W(e[0],e[1]),object:({args:e})=>X(e[0],e[1]),range:({args:[e,r,t]})=>{let n=parseInt(e),o=parseInt(r),s=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(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},(i,a)=>n+a*s)},filter:{types:(e,r,t)=>{switch(e){case 0:return"array";case 1:return Object.keys(_)}return z[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 s=o.key?.[0],i=_[r];if(s){let u=Array(e.length);for(let g=0;g<e.length;g++)try{u[g]=v({...n,...e[g]},s)}catch{u[g]=Symbol("invalid")}let m=[];for(let g=0;g<e.length;g++){let y=u[g];if(typeof y!=="symbol"&&t===void 0?i(y):i(y,t))m.push(e[g])}return m}let a=[];for(let u of e)if(t===void 0?i(u):i(u,t))a.push(u);return a}}});var Dr=()=>({each:{processArgs:!1,fn:async({rawArgs:[e,r,...t],root:n,options:o,tags:s})=>{let i=async(p)=>p.quoted?ne(p.value):await v(n,p.value),a=await v(n,e.value),u=await i(r),m=s.key?.[0],g=Array.isArray(a)?a:W(a),y=[],l=await Promise.all(t.map(async(p)=>await i(p))),c={...n,item:void 0,index:0,params:l,instance:void 0,parent:n.this,tags:s},h={...o,root:c};for(let p=0;p<g.length;p++){let w=$(u),f={instance:w},M=typeof u==="string"?f:w;if(c.item=g[p],c.index=p,c.instance=w,s?.root?.[0])Object.assign(c,await v(c,s.root[0]));if(await j(M,h),m!==void 0)y.push(await v(f.instance,m));else y.push(f.instance)}if(s.join?.length){if(y.length===0)return"";let p=ne(s.join[0]),w=s.pad?.[0]??"0",f=s.padChar?.[0]??" ",M=s.finalize?.length&&p?p:"",d=`${y.join(p)}${M}`;return w?L(d,parseInt(w),`
|
|
16
|
+
`,f):d}return y}}});var oe=async(e,r,t)=>e.rawArgs[r].quoted?e.rawArgs[r].value:await v(e.root,e.rawArgs[r].value,{defaultValue:t}),Rr=()=>({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 $r=()=>D({log:console.log});var _r=()=>({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))},...D(_,{types:z})});var Nr=(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 b.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 Fr=()=>({convert:({args:[e,r,t]})=>{switch(r){case"string":return String(e);case"number":{let n=Number(e);if(!isNaN(n))return b.ReplaceItem(n);break}case"boolean":if(e==="true"||e===!0||e===1||e==="1"||e==="yes"||e==="on")return b.ReplaceItem(!0);else if(e==="false"||e===!1||e===0||e==="0"||e==="no"||e==="off")return b.ReplaceItem(!1);break;default:throw Error(`Unsupported type for convert: ${r}`)}if(t!==void 0)return b.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 b.ReplaceItem(n)},typeOf:({args:[e]})=>{if(e===null)return"null";else if(Array.isArray(e))return"array";else return typeof e}});var Lr=()=>({...D({add:(...e)=>e.reduce((r,t)=>r+t,0),subtract:(e,r)=>e-r,multiply:(...e)=>e.reduce((r,t)=>r*t,1),divide:(e,r)=>{if(r===0)throw Error("Division by zero");return e/r},modulo:(e,r)=>e%r,power:(e,r)=>Math.pow(e,r),sqrt:(e)=>Math.sqrt(e),abs:(e)=>Math.abs(e),floor:(e)=>Math.floor(e),ceil:(e)=>Math.ceil(e),round:(e,r)=>{let t=Math.pow(10,r??0);return Math.round(e*t)/t},min:(...e)=>Math.min(...e),max:(...e)=>Math.max(...e),clamp:(e,r,t)=>Math.max(r,Math.min(t,e)),random:(e,r)=>{let t=e??0,n=r??1;return Math.random()*(n-t)+t}})});var Cr=()=>({now:()=>new Date,timestamp:(e)=>{let r=e.args?.[0];return(r?new Date(r):new Date).getTime()},iso:(e)=>{let r=e.args?.[0];return(r?new Date(r):new Date).toISOString()},utc:(e)=>{let r=e.args?.[0];return(r?new Date(r):new Date).toUTCString()},format:(e)=>{let r=e.args?.[0],t=e.args?.[1],n=new Date(r),o=n.getFullYear(),s=String(n.getMonth()+1).padStart(2,"0"),i=String(n.getDate()).padStart(2,"0"),a=String(n.getHours()).padStart(2,"0"),u=String(n.getMinutes()).padStart(2,"0"),m=String(n.getSeconds()).padStart(2,"0");return t.replace("YYYY",String(o)).replace("MM",s).replace("DD",i).replace("HH",a).replace("mm",u).replace("ss",m)},parse:(e)=>{let r=e.args?.[0];return new Date(r).getTime()},year:(e)=>{let r=e.args?.[0];return(r?new Date(r):new Date).getFullYear()},month:(e)=>{let r=e.args?.[0];return(r?new Date(r):new Date).getMonth()+1},day:(e)=>{let r=e.args?.[0];return(r?new Date(r):new Date).getDate()},dayOfWeek:(e)=>{let r=e.args?.[0];return(r?new Date(r):new Date).getDay()},hours:(e)=>{let r=e.args?.[0];return(r?new Date(r):new Date).getHours()},minutes:(e)=>{let r=e.args?.[0];return(r?new Date(r):new Date).getMinutes()},seconds:(e)=>{let r=e.args?.[0];return(r?new Date(r):new Date).getSeconds()}});var Wr=()=>{return{unique:(e)=>{let r=e.args?.[0]??e.value,t=e.args?.[1];if(!Array.isArray(r))return r;let n=new Set;return r.filter((o)=>{let s=typeof t==="function"?t(o):t?o[t]:o;if(n.has(s))return!1;return n.add(s),!0})},groupBy:(e)=>{let r=e.args?.[0]??e.value,t=e.args?.[1];if(!Array.isArray(r))return r;let n={};return r.forEach((o)=>{let s=typeof t==="function"?String(t(o)):String(o[t]);if(!n[s])n[s]=[];n[s].push(o)}),n},partition:(e)=>{let r=e.args?.[0]??e.value,t=e.args?.[1];if(!Array.isArray(r))return[[],[]];if(typeof t!=="function")return[r,[]];let n=[],o=[];return r.forEach((s)=>{(t(s)?n:o).push(s)}),[n,o]},chunk:(e)=>{let r=e.args?.[0]??e.value,t=e.args?.[1]??1;if(!Array.isArray(r))return[];let n=[];for(let o=0;o<r.length;o+=t)n.push(r.slice(o,o+t));return n},flatten:(e)=>{let r=e.args?.[0]??e.value,t=e.args?.[1]??1;if(!Array.isArray(r))return[r];let n=[],o=(s,i)=>{for(let a of s)if(Array.isArray(a)&&i>0)o(a,i-1);else n.push(a)};return o(r,t),n},compact:(e)=>{let r=e.args?.[0]??e.value;if(!Array.isArray(r))return r;return r.filter((t)=>t!==null&&t!==void 0)},head:(e)=>{let r=e.args?.[0]??e.value,t=e.args?.[1];if(!Array.isArray(r))return r;return t?r.slice(0,t):r[0]},tail:(e)=>{let r=e.args?.[0]??e.value,t=e.args?.[1];if(!Array.isArray(r))return r;return t?r.slice(-t):r[r.length-1]}}};import{createHash as se}from"crypto";var Ir=()=>({md5:(e)=>{let r=e.args?.[0]??e.value;return se("md5").update(r).digest("hex")},sha1:(e)=>{let r=e.args?.[0]??e.value;return se("sha1").update(r).digest("hex")},sha256:(e)=>{let r=e.args?.[0]??e.value;return se("sha256").update(r).digest("hex")},sha512:(e)=>{let r=e.args?.[0]??e.value;return se("sha512").update(r).digest("hex")},hash:(e)=>{let r=e.args?.[0]??e.value,t=e.args?.[1]??"sha256";return se(t).update(r).digest("hex")},base64Encode:(e)=>{let r=e.args?.[0]??e.value,t=typeof r==="string"?r:JSON.stringify(r);return Buffer.from(t).toString("base64")},base64Decode:(e)=>{let r=e.args?.[0]??e.value;return Buffer.from(r,"base64").toString("utf-8")},hexEncode:(e)=>{let r=e.args?.[0]??e.value;return Buffer.from(r).toString("hex")},hexDecode:(e)=>{let r=e.args?.[0]??e.value;return Buffer.from(r,"hex").toString("utf-8")}});var Ur=()=>({test:(e)=>{let r=e.args?.[0],t=e.args?.[1],n=e.args?.[2];return new RegExp(r,n).test(t)},match:(e)=>{let r=e.args?.[0],t=e.args?.[1],n=e.args?.[2],o=new RegExp(r,n);return t.match(o)},matchAll:(e)=>{let r=e.args?.[0],t=e.args?.[1],n=e.args?.[2],o=new RegExp(r,n);return Array.from(t.matchAll(o))},replace:(e)=>{let r=e.args?.[0],t=e.args?.[1],n=e.args?.[2],o=e.args?.[3],s=new RegExp(r,o);return n.replace(s,t)},replaceAll:(e)=>{let r=e.args?.[0],t=e.args?.[1],n=e.args?.[2],o=e.args?.[3]??"g",s=new RegExp(r,o);return n.replace(s,t)},split:(e)=>{let r=e.args?.[0],t=e.args?.[1],n=e.args?.[2],o=new RegExp(r,n);return t.split(o)},exec:(e)=>{let r=e.args?.[0],t=e.args?.[1],n=e.args?.[2];return new RegExp(r,n).exec(t)},search:(e)=>{let r=e.args?.[0],t=e.args?.[1],n=e.args?.[2],o=new RegExp(r,n);return t.search(o)}});import{resolve as Zt,dirname as Gt,basename as Kt,normalize as Vt,join as Ht}from"path";var Br=()=>({...D({pathJoin:(...e)=>Ht(...e),resolve:(...e)=>Zt(...e),dirname:(e)=>Gt(e),basename:(e,r)=>Kt(e,r),normalize:(e)=>Vt(e),extname:(e)=>{let r=/\.[^.]*$/.exec(e);return r?r[0]:""},relative:(e,r)=>{let t=e.split("/"),n=r.split("/"),o=0;while(o<t.length&&o<n.length&&t[o]===n[o])o++;let s=t.length-o,i=n.slice(o);return[...Array(s).fill("..")].concat(i).join("/")},isAbsolute:(e)=>e.startsWith("/"),segments:(e)=>e.split("/").filter(Boolean)})});var Tr=()=>({isEmail:(e)=>{let r=e.args?.[0]??e.value;return/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(r)},isUrl:(e)=>{let r=e.args?.[0]??e.value;try{return new URL(r),!0}catch{return!1}},isJson:(e)=>{let r=e.args?.[0]??e.value;try{return JSON.parse(r),!0}catch{return!1}},isUuid:(e)=>{let r=e.args?.[0]??e.value;return/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i.test(r)},minLength:(e)=>{let r=e.args?.[0]??e.value,t=e.args?.[1];return r?.length>=t},maxLength:(e)=>{let r=e.args?.[0]??e.value,t=e.args?.[1];return r?.length<=t},length:(e)=>{let r=e.args?.[0]??e.value,t=e.args?.[1];return r?.length===t},isNumber:(e)=>{let r=e.args?.[0]??e.value;return typeof r==="number"&&!isNaN(r)},isString:(e)=>{return typeof(e.args?.[0]??e.value)==="string"},isBoolean:(e)=>{return typeof(e.args?.[0]??e.value)==="boolean"},isArray:(e)=>{let r=e.args?.[0]??e.value;return Array.isArray(r)},isObject:(e)=>{let r=e.args?.[0]??e.value;return r!==null&&typeof r==="object"&&!Array.isArray(r)},isEmpty:(e)=>{let r=e.args?.[0]??e.value;if(r===null||r===void 0)return!0;if(typeof r==="string"||Array.isArray(r))return r.length===0;if(typeof r==="object")return Object.keys(r).length===0;return!1},isTruthy:(e)=>{return!!(e.args?.[0]??e.value)},isFalsy:(e)=>{return!(e.args?.[0]??e.value)},inRange:(e)=>{let r=e.args?.[0],t=e.args?.[1],n=e.args?.[2];return r>=t&&r<=n},matches:(e)=>{let r=e.args?.[0],t=e.args?.[1];return new RegExp(t).test(r)},includes:(e)=>{let r=e.args?.[0],t=e.args?.[1];if(typeof r==="string")return r.includes(String(t));return Array.isArray(r)&&r.includes(t)},startsWith:(e)=>{let r=e.args?.[0],t=e.args?.[1];return r.startsWith(t)},endsWith:(e)=>{let r=e.args?.[0],t=e.args?.[1];return r.endsWith(t)}});var Te=(e)=>e.keys(nr(e)).keys(or(e)).keys(pr()).keys(cr()).keys(dr()).keys(mr()).keys(gr()).keys(yr(e)).keys(br(e)).keys(hr()).keys(vr()).keys(Mr()).sources(Or(e)).sources(Ar()).sources(Sr()).sources(Fr()).sources(jr()).sources(Dr()).sources(Rr()).sources($r()).sources(_r()).sources(Nr(e)).sources(Lr()).sources(Cr()).sources(Wr()).sources(Ir()).sources(Ur()).sources(Br()).sources(Tr()).fieldOptions({onSection:(r)=>{e.section(r)}});var Yr={};R(Yr,{IncludeManager:()=>he,DocumentIncludeProcessor:()=>ve});import be from"path";class he{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(I.isGlobPattern(o)){let s=new Bun.Glob(o);for await(let i of s.scan({cwd:r,absolute:!0}))if(!t.included.includes(i))n.push(i)}else if(I.isDirectoryPattern(o)){let s=be.isAbsolute(o)?o:be.join(r,o);if(!this.includeDirectories.includes(s))this.includeDirectories.push(s)}else n.push(o);return n}buildSearchDirs(e){let r=e?[e]:[];return r.push(...this.includeDirectories.map((t)=>be.isAbsolute(t)?t:be.join(e??process.cwd(),t))),r}}class ve{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 s of o)F(await this.loadFn(s,e.folderPath,{parent:e.content,...r},!0,t),e.content)}}var E={};R(E,{writeOutputs:()=>P,writeOutput:()=>ue,writeFormat:()=>le,tokenize:()=>Be,toObjectWithKey:()=>_e,toObject:()=>X,toList:()=>W,sortBy:()=>Le,snake:()=>Y,select:()=>v,processFields:()=>j,pascal:()=>J,padBlock:()=>L,nonNullMap:()=>Ne,navigate:()=>ce,mergeAll:()=>B,merge:()=>F,makeFieldProcessorMap:()=>D,makeFieldProcessorList:()=>Se,makeFieldProcessor:()=>H,locate:()=>C,loadFormat:()=>x,importList:()=>fe,importGlob:()=>Re,globMap:()=>q,getProcessor:()=>V,getArgs:()=>ie,find:()=>Ie,exists:()=>U,defined:()=>Fe,deepClone:()=>$,conditionPredicates:()=>_,changeCase:()=>Q,capital:()=>re,camel:()=>te,asyncMap:()=>Ce,NavigateResult:()=>b,NavigateAction:()=>pe,Logger:()=>Ye});k(E,qr(Kr(),1));class Ye{options;constructor(e){this.options={level:"LOG",showClass:!1,levels:["DEBUG","LOG","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;default:console.log(...t)}},...e}}write(e,...r){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 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)}log(...e){this.write("LOG",...e)}error(...e){this.write("ERROR",...e)}warn(...e){this.write("WARN",...e)}debug(...e){this.write("DEBUG",...e)}}k(N,E);class Vr{includeManager=new he;includeProcessor;cacheManager=new me(100);outputs=[];vars={};fields={sources:{},keys:{}};objectMetadata={};currentContext=null;sections={};constructor(){this.includeProcessor=new ve(this.includeManager,this.load.bind(this)),this.use(Te)}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 j(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,n,o){let s=this.includeManager.snapshot();try{this.includeManager.reset();let i=this.includeManager.buildSearchDirs(r);if(o)this.currentContext=o;this.currentContext??={included:[],document:null};let a=await x(e,{dirs:i}),u=I.normalize(a.fullPath);if(this.currentContext.included.push(u),!a.content)return null;let m=this.cacheManager.get(u),g;if(m)g=m.raw;else g=a.content,this.cacheManager.set(u,{raw:g,timestamp:Date.now()});let y=$(g);a.content=y,await this.includeProcessor.processIncludes(a,t,this.currentContext);let l;if(n!==!0)l=await this.loadObject(a.content,t,{fileName:a.fullPath,folderPath:a.folderPath,fullPath:a.fullPath});else l=a.content;return this.currentContext.document=l,l}catch(i){throw this.includeManager.restore(s),i}finally{this.includeManager.restore(s)}}async writeAll(e){await P(this.getOutputs(),e)}}export{P as writeOutputs,ue as writeOutput,le as writeFormat,Be as tokenize,_e as toObjectWithKey,X as toObject,W as toList,Le as sortBy,Y as snake,v as select,j as processFields,J as pascal,L as padBlock,Ne as nonNullMap,ce as navigate,B as mergeAll,F as merge,D as makeFieldProcessorMap,Se as makeFieldProcessorList,H as makeFieldProcessor,C as locate,x as loadFormat,fe as importList,Re as importGlob,q as globMap,V as getProcessor,ie as getArgs,Ie as find,U as exists,Fe as defined,$ as deepClone,_ as conditionPredicates,Q as changeCase,re as capital,te as camel,Ce as asyncMap,Vr as Objector,b as NavigateResult,pe as NavigateAction,Ye as Logger};
|