@homedev/objector 1.2.57 → 1.2.59
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 +694 -0
- package/dist/index.js +17 -17
- package/package.json +1 -1
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,694 @@
|
|
|
1
|
+
export declare const AsyncFunction: any;
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Maps an array asynchronously using Promise.all for parallel execution
|
|
5
|
+
* @typeParam T - Type of input array items
|
|
6
|
+
* @typeParam U - Type of async result items
|
|
7
|
+
* @param arr - Array to map
|
|
8
|
+
* @param fn - Async mapping function
|
|
9
|
+
* @returns Promise of mapped array
|
|
10
|
+
* @public
|
|
11
|
+
*/
|
|
12
|
+
export declare const asyncMap: <T, U>(arr: T[], fn: (item: T, index: number, array: T[]) => Promise<U>) => Promise<U[]>;
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Converts a string to camelCase (lowerCamelCase).
|
|
16
|
+
* Handles spaces, underscores, and hyphens as word separators.
|
|
17
|
+
*
|
|
18
|
+
* @example
|
|
19
|
+
* camel('hello_world') // 'helloWorld'
|
|
20
|
+
* camel('hello world') // 'helloWorld'
|
|
21
|
+
* camel('HelloWorld') // 'helloWorld'
|
|
22
|
+
*
|
|
23
|
+
* @param v - The string to convert
|
|
24
|
+
* @returns The string in camelCase
|
|
25
|
+
*/
|
|
26
|
+
export declare const camel: (v: string) => string;
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* Converts a string to Capital Case (each word capitalized, spaces preserved).
|
|
30
|
+
* Only capitalizes words following spaces.
|
|
31
|
+
*
|
|
32
|
+
* @example
|
|
33
|
+
* capital('hello world') // 'Hello World'
|
|
34
|
+
* capital('hello_world') // 'hello_World'
|
|
35
|
+
*
|
|
36
|
+
* @param v - The string to convert
|
|
37
|
+
* @returns The string with each space-separated word capitalized
|
|
38
|
+
*/
|
|
39
|
+
export declare const capital: (v: string) => string;
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* Changes the case of a string to uppercase, lowercase, or returns unchanged.
|
|
43
|
+
*
|
|
44
|
+
* @example
|
|
45
|
+
* changeCase('Hello', 'upper') // 'HELLO'
|
|
46
|
+
* changeCase('Hello', 'lower') // 'hello'
|
|
47
|
+
* changeCase('Hello') // 'Hello'
|
|
48
|
+
*
|
|
49
|
+
* @param v - The string to transform
|
|
50
|
+
* @param arg - The case type: 'upper', 'lower', or undefined to return unchanged
|
|
51
|
+
* @returns The transformed string
|
|
52
|
+
*/
|
|
53
|
+
export declare const changeCase: (v: string, arg?: string) => string;
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* @public
|
|
57
|
+
*/
|
|
58
|
+
export declare const conditionPredicates: Record<string, (...args: any[]) => boolean>;
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* Deep clones an object using structuredClone (faster) with JSON fallback
|
|
62
|
+
* - Uses structuredClone for better performance and broader type support (Date, RegExp, etc.)
|
|
63
|
+
* - Falls back to JSON serialization if structuredClone fails or is unavailable
|
|
64
|
+
* - Note: Functions, symbols, and undefined values are lost in JSON fallback
|
|
65
|
+
* @typeParam T - Type of object to clone
|
|
66
|
+
* @param model - Object to clone
|
|
67
|
+
* @returns Deep clone of the object
|
|
68
|
+
* @public
|
|
69
|
+
*/
|
|
70
|
+
export declare const deepClone: <T>(model: T) => T;
|
|
71
|
+
|
|
72
|
+
/**
|
|
73
|
+
* Asserts that a value is defined, throwing an error if undefined
|
|
74
|
+
* @typeParam T - Type of the value
|
|
75
|
+
* @param value - Value to check
|
|
76
|
+
* @param msg - Error message to throw if value is undefined or null
|
|
77
|
+
* @returns The value if defined
|
|
78
|
+
* @throws Error if value is undefined
|
|
79
|
+
* @public
|
|
80
|
+
*/
|
|
81
|
+
export declare const defined: <T>(value: T | undefined | null, msg?: string) => T;
|
|
82
|
+
|
|
83
|
+
declare interface Encoder {
|
|
84
|
+
fn: (data: unknown, ...args: any[]) => string | Promise<string>;
|
|
85
|
+
options?: EncoderOptions;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
declare interface EncoderOptions {
|
|
89
|
+
includeTags?: boolean;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
export declare const exists: (fileName: string) => Promise<boolean>;
|
|
93
|
+
|
|
94
|
+
export declare interface FieldContext {
|
|
95
|
+
path: string;
|
|
96
|
+
root: any;
|
|
97
|
+
options: ProcessFieldsOptions;
|
|
98
|
+
value: string | object | number | NavigateResult | null;
|
|
99
|
+
key: string;
|
|
100
|
+
args: any[];
|
|
101
|
+
rawArgs: {
|
|
102
|
+
value: string;
|
|
103
|
+
quoted: boolean;
|
|
104
|
+
}[];
|
|
105
|
+
tags: Record<string, string[]>;
|
|
106
|
+
parent?: any;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
export declare interface FieldProcessor {
|
|
110
|
+
fn: FieldProcessorFunc;
|
|
111
|
+
options: FieldProcessorOptions;
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
export declare type FieldProcessorFunc = (context: FieldContext) => any;
|
|
115
|
+
|
|
116
|
+
export declare type FieldProcessorMap = Record<string, FieldProcessorTypedFunc>;
|
|
117
|
+
|
|
118
|
+
export declare interface FieldProcessorOptions {
|
|
119
|
+
filters?: RegExp[];
|
|
120
|
+
processArgs?: boolean;
|
|
121
|
+
types?: Record<number, string | any[] | ((value: string, root: any, index: number, quoted: boolean) => any)> | FieldProcessorTypeChecker;
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
export declare interface FieldProcessorSection {
|
|
125
|
+
config: Record<string, any>;
|
|
126
|
+
content: string;
|
|
127
|
+
trim?: boolean;
|
|
128
|
+
indent?: number;
|
|
129
|
+
show?: boolean;
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
export declare type FieldProcessorSectionConfigFunc = (context: FieldProcessorSectionContext) => Promise<boolean | void> | boolean | void;
|
|
133
|
+
|
|
134
|
+
export declare interface FieldProcessorSectionContext {
|
|
135
|
+
section: FieldProcessorSection;
|
|
136
|
+
content: string;
|
|
137
|
+
path: string;
|
|
138
|
+
root: Record<string, any>;
|
|
139
|
+
options: ProcessFieldsOptions;
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
export declare type FieldProcessorSectionFunc = (context: FieldProcessorSectionContext) => Promise<void | boolean | string> | void | boolean | string;
|
|
143
|
+
|
|
144
|
+
export declare type FieldProcessorSectionMap = Record<string, FieldProcessorSectionFunc>;
|
|
145
|
+
|
|
146
|
+
export declare type FieldProcessorTypeChecker = (n: number, value: any, args: any[]) => any;
|
|
147
|
+
|
|
148
|
+
export declare type FieldProcessorTypeCheckers<T = unknown> = Record<keyof T, FieldProcessorTypeChecker>;
|
|
149
|
+
|
|
150
|
+
export declare type FieldProcessorTypedFunc = FieldProcessorFunc | (FieldProcessorOptions & {
|
|
151
|
+
fn: FieldProcessorFunc;
|
|
152
|
+
});
|
|
153
|
+
|
|
154
|
+
declare interface FilePatternOptions {
|
|
155
|
+
cwd: string;
|
|
156
|
+
filter?: (fileName: string, index: number, array: string[]) => boolean;
|
|
157
|
+
map: (fileName: string, index: number, array: string[]) => Promise<any>;
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
/**
|
|
161
|
+
* Finds values in an object tree that match a predicate function.
|
|
162
|
+
*
|
|
163
|
+
* @public
|
|
164
|
+
* @param from - The object to search through
|
|
165
|
+
* @param cb - Predicate function that receives the path and value, returns true for matches
|
|
166
|
+
* @returns Array of matching values
|
|
167
|
+
*
|
|
168
|
+
* @example
|
|
169
|
+
* ```typescript
|
|
170
|
+
* const obj = { a: { b: 1 }, c: { d: 2 } }
|
|
171
|
+
* const results = await find(obj, (path, value) => value === 2)
|
|
172
|
+
* // results: [2]
|
|
173
|
+
* ```
|
|
174
|
+
*/
|
|
175
|
+
export declare const find: (from: any, cb: (path: string, value: any) => boolean) => Promise<any[]>;
|
|
176
|
+
|
|
177
|
+
export declare const globMap: <T>(pattern: string | string[], options: FilePatternOptions) => Promise<T[] | T>;
|
|
178
|
+
|
|
179
|
+
/**
|
|
180
|
+
* @public
|
|
181
|
+
*/
|
|
182
|
+
export declare const importGlob: (patterns: string[], options?: ImportOptions) => Promise<any[]>;
|
|
183
|
+
|
|
184
|
+
/**
|
|
185
|
+
* @public
|
|
186
|
+
*/
|
|
187
|
+
export declare const importList: (modules: string[], options?: ImportOptions) => Promise<any[]>;
|
|
188
|
+
|
|
189
|
+
/**
|
|
190
|
+
* @public
|
|
191
|
+
*/
|
|
192
|
+
export declare interface ImportOptions {
|
|
193
|
+
cwd?: string;
|
|
194
|
+
resolveDefault?: boolean | 'only';
|
|
195
|
+
filter?: (name: string) => boolean | undefined;
|
|
196
|
+
fail?: (name: string, error: any) => boolean | undefined;
|
|
197
|
+
map?: (module: any, name: string) => any;
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
/**
|
|
201
|
+
* @public
|
|
202
|
+
*/
|
|
203
|
+
export declare interface LoadContext {
|
|
204
|
+
included: string[];
|
|
205
|
+
document: unknown;
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
/**
|
|
209
|
+
* @public
|
|
210
|
+
* @param fileName
|
|
211
|
+
* @param options
|
|
212
|
+
* @returns
|
|
213
|
+
*/
|
|
214
|
+
export declare const loadFormat: <T = any>(fileName: string, options?: LoadOptions) => Promise<LoadResult<T>>;
|
|
215
|
+
|
|
216
|
+
/**
|
|
217
|
+
* @public
|
|
218
|
+
*/
|
|
219
|
+
export declare interface LoadFormatParser {
|
|
220
|
+
matching?: string[];
|
|
221
|
+
fn: (data: string) => any;
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
/**
|
|
225
|
+
* @public
|
|
226
|
+
*/
|
|
227
|
+
export declare interface LoadObjectOptions {
|
|
228
|
+
fileName: string;
|
|
229
|
+
fullPath: string;
|
|
230
|
+
folderPath: string;
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
/**
|
|
234
|
+
* @public
|
|
235
|
+
*/
|
|
236
|
+
export declare interface LoadOptions {
|
|
237
|
+
dirs?: string[];
|
|
238
|
+
parsers?: Record<string, LoadFormatParser>;
|
|
239
|
+
format?: string;
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
export declare interface LoadResult<T> {
|
|
243
|
+
fullPath: string;
|
|
244
|
+
folderPath: string;
|
|
245
|
+
content: T;
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
export declare const locate: (fileName: string, dirs?: string[]) => Promise<string>;
|
|
249
|
+
|
|
250
|
+
export declare type LogFunction = (className: string, ...args: any[]) => void;
|
|
251
|
+
|
|
252
|
+
export declare class Logger {
|
|
253
|
+
options: LoggerOptions;
|
|
254
|
+
constructor(options?: Partial<LoggerOptions>);
|
|
255
|
+
write(className: string, ...args: any[]): void;
|
|
256
|
+
info(...args: any[]): void;
|
|
257
|
+
error(...args: any[]): void;
|
|
258
|
+
warn(...args: any[]): void;
|
|
259
|
+
debug(...args: any[]): void;
|
|
260
|
+
verbose(...args: any[]): void;
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
export declare interface LoggerOptions {
|
|
264
|
+
level: string;
|
|
265
|
+
showClass: boolean;
|
|
266
|
+
levels: string[];
|
|
267
|
+
timeStamp: boolean;
|
|
268
|
+
timeLocale?: string;
|
|
269
|
+
timeOptions?: Intl.DateTimeFormatOptions;
|
|
270
|
+
logFunction: LogFunction;
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
export declare const makeFieldProcessor: (fn: SourceFunc, types?: FieldProcessorTypeChecker) => FieldProcessorTypedFunc;
|
|
274
|
+
|
|
275
|
+
export declare const makeFieldProcessorList: <T = unknown>(source: SourceFunc[], options?: {
|
|
276
|
+
types?: FieldProcessorTypeCheckers<T>;
|
|
277
|
+
}) => FieldProcessorMap;
|
|
278
|
+
|
|
279
|
+
export declare const makeFieldProcessorMap: <T = unknown>(source: Record<keyof T, SourceFunc>, options?: {
|
|
280
|
+
types?: FieldProcessorTypeCheckers<T>;
|
|
281
|
+
keys?: (keyof T)[];
|
|
282
|
+
}) => FieldProcessorMap;
|
|
283
|
+
|
|
284
|
+
/**
|
|
285
|
+
* @public
|
|
286
|
+
* @param source
|
|
287
|
+
* @param target
|
|
288
|
+
* @param options
|
|
289
|
+
*/
|
|
290
|
+
export declare const merge: (source: any, target: any, options?: MergeOptions) => void;
|
|
291
|
+
|
|
292
|
+
/**
|
|
293
|
+
* @public
|
|
294
|
+
* @param elements
|
|
295
|
+
* @param options
|
|
296
|
+
*/
|
|
297
|
+
export declare const mergeAll: (elements: any[], options?: MergeOptions) => any;
|
|
298
|
+
|
|
299
|
+
/**
|
|
300
|
+
* @public
|
|
301
|
+
*/
|
|
302
|
+
export declare type MergeMode = 'merge' | 'source' | 'target' | 'skip';
|
|
303
|
+
|
|
304
|
+
/**
|
|
305
|
+
* @public
|
|
306
|
+
*/
|
|
307
|
+
export declare interface MergeOptions {
|
|
308
|
+
conflict?: (key: string, source: any, target: any, sourceContainer: any, targetContainer: any) => any;
|
|
309
|
+
mismatch?: (key: string, source: any, target: any, sourceContainer: any, targetContainer: any) => any;
|
|
310
|
+
navigate?: (key: string, source: any, target: any, sourceContainer: any, targetContainer: any) => boolean | undefined;
|
|
311
|
+
mode?: (key: string, source: any, target: any, sourceContainer: any, targetContainer: any) => MergeMode | void;
|
|
312
|
+
}
|
|
313
|
+
|
|
314
|
+
/**
|
|
315
|
+
* Recursively navigates through an object tree, invoking a callback for each property.
|
|
316
|
+
* Supports various actions like replacing, deleting, or merging values during traversal.
|
|
317
|
+
* Includes circular reference detection to prevent infinite loops.
|
|
318
|
+
*
|
|
319
|
+
* Performance optimizations:
|
|
320
|
+
* - Caches static NavigateResult instances
|
|
321
|
+
* - Uses WeakSet for O(1) circular reference detection
|
|
322
|
+
* - Avoids Object.entries() to prevent array allocations
|
|
323
|
+
* - Optimizes switch statement order for common cases
|
|
324
|
+
*
|
|
325
|
+
* @public
|
|
326
|
+
* @param o - The object to navigate
|
|
327
|
+
* @param cb - Callback function invoked for each property
|
|
328
|
+
* @throws {Error} When attempting to replace the root object
|
|
329
|
+
*/
|
|
330
|
+
export declare const navigate: (o: any, cb: NavigateCallback) => Promise<void>;
|
|
331
|
+
|
|
332
|
+
/**
|
|
333
|
+
* @public
|
|
334
|
+
*/
|
|
335
|
+
export declare enum NavigateAction {
|
|
336
|
+
Explore = 0,
|
|
337
|
+
SkipSiblings = 1,
|
|
338
|
+
NoExplore = 2,
|
|
339
|
+
ReplaceParent = 3,
|
|
340
|
+
DeleteParent = 4,
|
|
341
|
+
MergeParent = 5,
|
|
342
|
+
ReplaceItem = 6,
|
|
343
|
+
DeleteItem = 7
|
|
344
|
+
}
|
|
345
|
+
|
|
346
|
+
/**
|
|
347
|
+
* @public
|
|
348
|
+
*/
|
|
349
|
+
export declare type NavigateCallback = (context: NavigateContext) => Promise<NavigateResult> | NavigateResult;
|
|
350
|
+
|
|
351
|
+
/**
|
|
352
|
+
* @public
|
|
353
|
+
*/
|
|
354
|
+
export declare interface NavigateContext {
|
|
355
|
+
key: string;
|
|
356
|
+
value: any;
|
|
357
|
+
path: string[];
|
|
358
|
+
parent: any;
|
|
359
|
+
parents: any[];
|
|
360
|
+
}
|
|
361
|
+
|
|
362
|
+
/**
|
|
363
|
+
* @public
|
|
364
|
+
*/
|
|
365
|
+
export declare class NavigateResult {
|
|
366
|
+
readonly action: NavigateAction;
|
|
367
|
+
by?: any | undefined;
|
|
368
|
+
skipSiblings?: boolean | undefined;
|
|
369
|
+
reexplore?: boolean | undefined;
|
|
370
|
+
constructor(action: NavigateAction, by?: any | undefined, skipSiblings?: boolean | undefined, reexplore?: boolean | undefined);
|
|
371
|
+
private static readonly _explore;
|
|
372
|
+
private static readonly _noExplore;
|
|
373
|
+
private static readonly _skipSiblings;
|
|
374
|
+
private static readonly _deleteParent;
|
|
375
|
+
static ReplaceParent(by: any, reexplore?: boolean): NavigateResult;
|
|
376
|
+
static SkipSiblings(): NavigateResult;
|
|
377
|
+
static Explore(): NavigateResult;
|
|
378
|
+
static NoExplore(): NavigateResult;
|
|
379
|
+
static DeleteParent(): NavigateResult;
|
|
380
|
+
static MergeParent(by: any): NavigateResult;
|
|
381
|
+
static ReplaceItem(by: any, skipSiblings?: boolean): NavigateResult;
|
|
382
|
+
static DeleteItem(skipSiblings?: boolean): NavigateResult;
|
|
383
|
+
}
|
|
384
|
+
|
|
385
|
+
/**
|
|
386
|
+
* Maps an array while filtering out null/undefined values (performance optimized)
|
|
387
|
+
* Combines filter and map operations to avoid double iteration
|
|
388
|
+
* @typeParam T - Type of input array items
|
|
389
|
+
* @typeParam U - Type of mapped result items
|
|
390
|
+
* @param arr - Array to map (can be undefined)
|
|
391
|
+
* @param fn - Mapping function
|
|
392
|
+
* @returns Mapped array with nulls/undefined filtered out, or empty array if input is undefined
|
|
393
|
+
* @public
|
|
394
|
+
*/
|
|
395
|
+
export declare const nonNullMap: <T, U>(arr: T[] | undefined, fn: (item: T, index: number, array: T[]) => U) => U[];
|
|
396
|
+
|
|
397
|
+
/**
|
|
398
|
+
* @public
|
|
399
|
+
*/
|
|
400
|
+
export declare class Objector {
|
|
401
|
+
private includeManager;
|
|
402
|
+
private includeProcessor;
|
|
403
|
+
private cacheManager;
|
|
404
|
+
private outputs;
|
|
405
|
+
private vars;
|
|
406
|
+
private funcs;
|
|
407
|
+
private fields;
|
|
408
|
+
private objectMetadata;
|
|
409
|
+
private currentContext;
|
|
410
|
+
private storedSections;
|
|
411
|
+
private dataEncoders;
|
|
412
|
+
private dataDecoders;
|
|
413
|
+
constructor();
|
|
414
|
+
use(handler: (o: Objector) => void): this;
|
|
415
|
+
includeDirectory(...dirs: string[]): this;
|
|
416
|
+
getIncludeDirectories(): string[];
|
|
417
|
+
include(...files: string[]): this;
|
|
418
|
+
keys(keys: FieldProcessorMap): this;
|
|
419
|
+
sources(sources: FieldProcessorMap): this;
|
|
420
|
+
sections(sections: Record<string, FieldProcessorSectionFunc>): this;
|
|
421
|
+
variables(vars: Record<string, unknown>): this;
|
|
422
|
+
functions(funcs: Record<string, typeof AsyncFunction>): this;
|
|
423
|
+
getFunctions(): Record<string, typeof AsyncFunction>;
|
|
424
|
+
getOutputs(): Output[];
|
|
425
|
+
output(o: Output): this;
|
|
426
|
+
metadata(path: string, o: unknown): this;
|
|
427
|
+
getMetadata(path: string): unknown;
|
|
428
|
+
getAllMetadata(): Record<string, unknown>;
|
|
429
|
+
setCacheMaxSize(size: number): this;
|
|
430
|
+
clearCache(): this;
|
|
431
|
+
getCurrentContext(): LoadContext | null;
|
|
432
|
+
fieldOptions(options: ProcessFieldsOptions): this;
|
|
433
|
+
section(section: FieldProcessorSection): this;
|
|
434
|
+
getSection(name: string): FieldProcessorSection | undefined;
|
|
435
|
+
encoders(encoders: Record<string, Encoder>): this;
|
|
436
|
+
decoders(decoders: Record<string, LoadFormatParser>): this;
|
|
437
|
+
getEncoder(name: string): Encoder | undefined;
|
|
438
|
+
getDecoder(name: string): LoadFormatParser | undefined;
|
|
439
|
+
filter(f: RegExp): this;
|
|
440
|
+
loadObject<T = any>(data: T, container?: any, options?: LoadObjectOptions): Promise<T>;
|
|
441
|
+
load<T = unknown>(fileName: string, cwd?: string, container?: unknown, noProcess?: boolean, ld?: LoadContext): Promise<T | null>;
|
|
442
|
+
writeAll(option?: WriteOutputsOption): Promise<void>;
|
|
443
|
+
}
|
|
444
|
+
|
|
445
|
+
export declare interface Output {
|
|
446
|
+
name: string;
|
|
447
|
+
type?: 'json' | 'yaml' | 'text';
|
|
448
|
+
value: any;
|
|
449
|
+
class?: string;
|
|
450
|
+
}
|
|
451
|
+
|
|
452
|
+
/**
|
|
453
|
+
* Adds indentation to each line of a string.
|
|
454
|
+
* Useful for formatting multi-line text with consistent indentation.
|
|
455
|
+
*
|
|
456
|
+
* @example
|
|
457
|
+
* padBlock('hello\\nworld', 2) // ' hello\\n world'
|
|
458
|
+
* padBlock('a|b|c', 1, '|', '-') // '-a|-b|-c'
|
|
459
|
+
*
|
|
460
|
+
* @param str - The string to indent
|
|
461
|
+
* @param indent - The number of padding units to add
|
|
462
|
+
* @param separator - The separator between lines (default: '\\n')
|
|
463
|
+
* @param padder - The character to repeat for padding (default: ' ')
|
|
464
|
+
* @returns The indented string
|
|
465
|
+
*/
|
|
466
|
+
export declare const padBlock: (str: string, indent: number, separator?: string, padder?: string) => string;
|
|
467
|
+
|
|
468
|
+
/**
|
|
469
|
+
* Converts a string to PascalCase (UpperCamelCase).
|
|
470
|
+
* Handles spaces, underscores, and hyphens as word separators.
|
|
471
|
+
*
|
|
472
|
+
* @example
|
|
473
|
+
* pascal('hello_world') // 'HelloWorld'
|
|
474
|
+
* pascal('hello world') // 'HelloWorld'
|
|
475
|
+
* pascal('helloWorld') // 'HelloWorld'
|
|
476
|
+
*
|
|
477
|
+
* @param v - The string to convert
|
|
478
|
+
* @returns The string in PascalCase
|
|
479
|
+
*/
|
|
480
|
+
export declare const pascal: (v: string) => string;
|
|
481
|
+
|
|
482
|
+
/**
|
|
483
|
+
* @public
|
|
484
|
+
* @param obj
|
|
485
|
+
* @param options
|
|
486
|
+
* @returns
|
|
487
|
+
*/
|
|
488
|
+
export declare const processFields: (obj: any, options?: ProcessFieldsOptions) => Promise<any>;
|
|
489
|
+
|
|
490
|
+
export declare interface ProcessFieldsOptions {
|
|
491
|
+
sources?: FieldProcessorMap;
|
|
492
|
+
keys?: FieldProcessorMap;
|
|
493
|
+
sections?: FieldProcessorSectionMap;
|
|
494
|
+
filters?: RegExp[];
|
|
495
|
+
root?: Record<any, any>;
|
|
496
|
+
globalContext?: any;
|
|
497
|
+
onSection?: FieldProcessorSectionFunc;
|
|
498
|
+
onSectionConfig?: FieldProcessorSectionConfigFunc;
|
|
499
|
+
configParser?: (configText: string) => any;
|
|
500
|
+
}
|
|
501
|
+
|
|
502
|
+
/**
|
|
503
|
+
* Selects a value from a nested object using a path string with advanced querying capabilities
|
|
504
|
+
*
|
|
505
|
+
* Supports:
|
|
506
|
+
* - Dot notation: 'user.profile.name'
|
|
507
|
+
* - Array indexing: 'users.0' or 'users[0]'
|
|
508
|
+
* - Array filtering: 'users.[name=John].age'
|
|
509
|
+
* - References: 'users.\{activeUserId\}.name'
|
|
510
|
+
* - Optional paths: 'user.profile?.bio'
|
|
511
|
+
* - Default values: 'config.timeout?=5000'
|
|
512
|
+
*
|
|
513
|
+
* @public
|
|
514
|
+
* @param from - The root object to select from
|
|
515
|
+
* @param path - The path string to navigate
|
|
516
|
+
* @param options - Optional configuration
|
|
517
|
+
* @returns The selected value or undefined
|
|
518
|
+
*
|
|
519
|
+
* @example
|
|
520
|
+
* ```typescript
|
|
521
|
+
* const obj = { user: { name: 'Alice', age: 30 } }
|
|
522
|
+
* select(obj, 'user.name') // 'Alice'
|
|
523
|
+
* select(obj, 'user.email', { defaultValue: 'N/A' }) // 'N/A'
|
|
524
|
+
* ```
|
|
525
|
+
*/
|
|
526
|
+
export declare const select: <T = any>(from: any, path: string, options?: SelectOptions) => T | undefined;
|
|
527
|
+
|
|
528
|
+
/**
|
|
529
|
+
* Options for configuring the select function behavior
|
|
530
|
+
* @public
|
|
531
|
+
*/
|
|
532
|
+
export declare interface SelectOptions {
|
|
533
|
+
/** Value to set at the selected path */
|
|
534
|
+
set?: any;
|
|
535
|
+
/** Alternative key to use (currently unused) */
|
|
536
|
+
key?: string;
|
|
537
|
+
/** Path separator character (default: '.') */
|
|
538
|
+
separator?: string;
|
|
539
|
+
/** Default value to return when path is not found */
|
|
540
|
+
defaultValue?: any;
|
|
541
|
+
/** If true, returns undefined instead of throwing on missing paths */
|
|
542
|
+
optional?: boolean;
|
|
543
|
+
}
|
|
544
|
+
|
|
545
|
+
/**
|
|
546
|
+
* Converts a string to snake_case or custom_case.
|
|
547
|
+
* Inserts the separator between lowercase and uppercase characters.
|
|
548
|
+
*
|
|
549
|
+
* @example
|
|
550
|
+
* snake('helloWorld', '_') // 'hello_world'
|
|
551
|
+
* snake('HelloWorld', '-') // 'hello-world'
|
|
552
|
+
* snake('hello world', '_') // 'hello_world'
|
|
553
|
+
*
|
|
554
|
+
* @param v - The string to convert
|
|
555
|
+
* @param separator - The separator to use between words (default: '_')
|
|
556
|
+
* @returns The string in snake case with the specified separator
|
|
557
|
+
*/
|
|
558
|
+
export declare const snake: (v: string, separator?: string) => string;
|
|
559
|
+
|
|
560
|
+
/**
|
|
561
|
+
* Sorts an array by a selector function with custom comparison
|
|
562
|
+
* Uses a shallow copy to avoid mutating the original array
|
|
563
|
+
* @typeParam T - Type of array items
|
|
564
|
+
* @typeParam U - Type of comparison values
|
|
565
|
+
* @param arr - Array to sort
|
|
566
|
+
* @param selector - Function to extract comparison value from item
|
|
567
|
+
* @param compare - Comparison function (default: numeric comparison)
|
|
568
|
+
* @returns New sorted array
|
|
569
|
+
* @public
|
|
570
|
+
*/
|
|
571
|
+
export declare const sortBy: <T, U>(arr: T[], selector: (item: T) => U, compare?: (a: U, b: U) => number) => T[];
|
|
572
|
+
|
|
573
|
+
declare type SourceFunc = (...args: any[]) => any;
|
|
574
|
+
|
|
575
|
+
export declare const splitNested: (str: string, separator: string, open?: string, close?: string) => string[];
|
|
576
|
+
|
|
577
|
+
/**
|
|
578
|
+
* Splits a string by a separator while respecting quoted values.
|
|
579
|
+
* Quoted values can contain the separator without being split.
|
|
580
|
+
* Supports both single (') and double (") quotes.
|
|
581
|
+
*
|
|
582
|
+
* @param input - The string to split
|
|
583
|
+
* @param separator - Single or multi-character separator (default: ',')
|
|
584
|
+
* @returns Array of objects with value and quoted status
|
|
585
|
+
*
|
|
586
|
+
* @example
|
|
587
|
+
* splitWithQuotes('hello, "world", test')
|
|
588
|
+
* // Returns: [
|
|
589
|
+
* // { value: 'hello', quoted: false },
|
|
590
|
+
* // { value: 'world', quoted: true },
|
|
591
|
+
* // { value: 'test', quoted: false }
|
|
592
|
+
* // ]
|
|
593
|
+
*
|
|
594
|
+
* @example
|
|
595
|
+
* splitWithQuotes('a:: "b:: c":: d', '::')
|
|
596
|
+
* // Returns: [
|
|
597
|
+
* // { value: 'a', quoted: false },
|
|
598
|
+
* // { value: 'b:: c', quoted: true },
|
|
599
|
+
* // { value: 'd', quoted: false }
|
|
600
|
+
* // ]
|
|
601
|
+
*/
|
|
602
|
+
export declare const splitWithQuotes: (input: string, separator?: string) => {
|
|
603
|
+
value: string;
|
|
604
|
+
quoted: boolean;
|
|
605
|
+
}[];
|
|
606
|
+
|
|
607
|
+
export declare const stripIndent: (value: string) => string;
|
|
608
|
+
|
|
609
|
+
/**
|
|
610
|
+
* Replaces tokens in a string with values from an object.
|
|
611
|
+
* Tokens are in the format `$\{key\}`.
|
|
612
|
+
*
|
|
613
|
+
* @example
|
|
614
|
+
* tokenize('Hello $\{name\}', { name: 'World' }) // 'Hello World'
|
|
615
|
+
* tokenize('$\{greeting\} $\{name\}!', { greeting: 'Hi', name: 'Alice' }) // 'Hi Alice!'
|
|
616
|
+
* tokenize('$\{missing\}', {}) // ''
|
|
617
|
+
*
|
|
618
|
+
* @param str - The string containing tokens
|
|
619
|
+
* @param from - An object with key-value pairs for token replacement
|
|
620
|
+
* @param tokenizer - The regex pattern for token matching (default: `/\$\{([^}]+)\}/g`)
|
|
621
|
+
* @returns The string with tokens replaced by values from the object
|
|
622
|
+
*/
|
|
623
|
+
export declare const tokenize: (str: string, from: Record<string, unknown>, tokenizer?: RegExp) => string;
|
|
624
|
+
|
|
625
|
+
/**
|
|
626
|
+
* Converts an object's entries into an array of objects with a key property
|
|
627
|
+
* @typeParam T - The type of items in the resulting array
|
|
628
|
+
* @param from - Object to convert
|
|
629
|
+
* @param key - Property name to use for keys (default: 'name')
|
|
630
|
+
* @returns Array of objects with key properties
|
|
631
|
+
* @example
|
|
632
|
+
* toList({ a: { value: 1 }, b: { value: 2 } }) // [{ name: 'a', value: 1 }, { name: 'b', value: 2 }]
|
|
633
|
+
* @public
|
|
634
|
+
*/
|
|
635
|
+
export declare const toList: <T>(from: Record<string, unknown>, key?: string) => T[];
|
|
636
|
+
|
|
637
|
+
/**
|
|
638
|
+
* Converts an array into an object indexed by a key property, excluding the key from items
|
|
639
|
+
* @typeParam T - The type of the resulting object values
|
|
640
|
+
* @param from - Array to convert
|
|
641
|
+
* @param key - Property name to use as key (default: 'name')
|
|
642
|
+
* @returns Object indexed by key values, without the key property in values
|
|
643
|
+
* @example
|
|
644
|
+
* toObject([{ name: 'a', value: 1 }]) // { a: { value: 1 } }
|
|
645
|
+
* @public
|
|
646
|
+
*/
|
|
647
|
+
export declare const toObject: <T extends Record<string, unknown>>(from: T[], key?: string) => Record<string, Omit<T, typeof key>>;
|
|
648
|
+
|
|
649
|
+
/**
|
|
650
|
+
* Converts an array into an object indexed by a key property, keeping the full items
|
|
651
|
+
* @typeParam T - The type of the resulting object
|
|
652
|
+
* @param from - Array to convert
|
|
653
|
+
* @param key - Property name to use as key (default: 'name')
|
|
654
|
+
* @returns Object indexed by key values
|
|
655
|
+
* @example
|
|
656
|
+
* toObjectWithKey([{ name: 'a', value: 1 }]) // { a: { name: 'a', value: 1 } }
|
|
657
|
+
* @public
|
|
658
|
+
*/
|
|
659
|
+
export declare const toObjectWithKey: <T extends Record<string, unknown>>(from: T[], key?: string) => Record<string, T>;
|
|
660
|
+
|
|
661
|
+
export declare const writeFormat: (filePath: string, content: any, options?: WriteFormatOptions) => Promise<void>;
|
|
662
|
+
|
|
663
|
+
/**
|
|
664
|
+
* @public
|
|
665
|
+
*/
|
|
666
|
+
export declare interface WriteFormatEncoder {
|
|
667
|
+
matching?: string[];
|
|
668
|
+
fn: (data: any) => Promise<string> | string;
|
|
669
|
+
}
|
|
670
|
+
|
|
671
|
+
/**
|
|
672
|
+
* @public
|
|
673
|
+
*/
|
|
674
|
+
export declare interface WriteFormatOptions {
|
|
675
|
+
format: string;
|
|
676
|
+
encoders?: Record<string, WriteFormatEncoder>;
|
|
677
|
+
}
|
|
678
|
+
|
|
679
|
+
export declare const writeOutput: (o: Output, options?: WriteOutputOption) => Promise<void>;
|
|
680
|
+
|
|
681
|
+
export declare interface WriteOutputOption {
|
|
682
|
+
targetDirectory?: string;
|
|
683
|
+
writing?: (output: Output) => boolean | undefined | void;
|
|
684
|
+
classes?: string[];
|
|
685
|
+
classRequired?: boolean;
|
|
686
|
+
}
|
|
687
|
+
|
|
688
|
+
export declare const writeOutputs: (outputs: Output[], options?: WriteOutputsOption) => Promise<void>;
|
|
689
|
+
|
|
690
|
+
export declare interface WriteOutputsOption extends WriteOutputOption {
|
|
691
|
+
removeFirst?: boolean;
|
|
692
|
+
}
|
|
693
|
+
|
|
694
|
+
export { }
|
package/dist/index.js
CHANGED
|
@@ -1,23 +1,23 @@
|
|
|
1
|
-
var pt=Object.create;var{getPrototypeOf:ct,defineProperty:V,getOwnPropertyNames:rr}=Object;var ke=Object.prototype.hasOwnProperty;function Fe(e){return this[e]}var F=(e,r,t)=>{var n=rr(r);for(let o of n)if(!ke.call(e,o)&&o!=="default")V(e,o,{get:Fe.bind(r,o),enumerable:!0});if(t){for(let o of n)if(!ke.call(t,o)&&o!=="default")V(t,o,{get:Fe.bind(r,o),enumerable:!0});return t}},gt,mt,yt=(e,r,t)=>{var n=e!=null&&typeof e==="object";if(n){var o=r?gt??=new WeakMap:mt??=new WeakMap,s=o.get(e);if(s)return s}t=e!=null?pt(ct(e)):{};let a=r||!e||!e.__esModule?V(t,"default",{value:e,enumerable:!0}):t;for(let i of rr(e))if(!ke.call(a,i))V(a,i,{get:Fe.bind(e,i),enumerable:!0});if(n)o.set(e,a);return a};var dt=(e,r)=>()=>(r||e((r={exports:{}}).exports,r),r.exports);var wt=(e)=>e;function ht(e,r){this[e]=wt.bind(null,r)}var j=(e,r)=>{for(var t in r)V(e,t,{get:r[t],enumerable:!0,configurable:!0,set:ht.bind(r,t)})};var at=dt((Ii,it)=>{var{defineProperty:He,getOwnPropertyNames:On,getOwnPropertyDescriptor:Mn}=Object,An=Object.prototype.hasOwnProperty,ot=new WeakMap,En=(e)=>{var r=ot.get(e),t;if(r)return r;if(r=He({},"__esModule",{value:!0}),e&&typeof e==="object"||typeof e==="function")On(e).map((n)=>!An.call(r,n)&&He(r,n,{get:()=>e[n],enumerable:!(t=Mn(e,n))||t.enumerable}));return ot.set(e,r),r},kn=(e,r)=>{for(var t in r)He(e,t,{get:r[t],enumerable:!0,configurable:!0,set:(n)=>r[t]=()=>n})},st={};kn(st,{splitWithQuotes:()=>Sn,splitNested:()=>Fn});it.exports=En(st);var Fn=(e,r,t="(",n=")")=>{let o=0,s="",a=[];for(let i of e){if(s+=i,i===t)o++;if(i===n)o--;if(o===0&&i===r)a.push(s.slice(0,-1)),s=""}if(s)a.push(s);return a},Sn=(e,r=",")=>{let t=[],n=e.length,o=r.length,s=0,a=(i)=>{if(i+o>n)return!1;for(let l=0;l<o;l++)if(e[i+l]!==r[l])return!1;return!0};while(s<n){while(s<n&&e[s]===" ")s++;if(s>=n)break;let i="",l=e[s]==='"'||e[s]==="'";if(l){let g=e[s++];while(s<n&&e[s]!==g)i+=e[s++];if(s<n)s++}else{while(s<n&&!a(s)){let g=e[s];if(g==='"'||g==="'"){i+=g,s++;while(s<n&&e[s]!==g)i+=e[s++];if(s<n)i+=e[s++]}else i+=e[s++]}i=i.trim()}if(i)t.push({value:i,quoted:l});if(a(s))s+=o}return t}});var R={};j(R,{writeOutputs:()=>z,writeOutput:()=>ce,writeFormat:()=>pe,tokenize:()=>Ke,toObjectWithKey:()=>Ie,toObject:()=>ee,toList:()=>U,stripIndent:()=>Ze,sortBy:()=>Te,snake:()=>G,select:()=>A,processFields:()=>S,pascal:()=>X,padBlock:()=>C,nonNullMap:()=>_e,navigate:()=>ye,mergeAll:()=>Y,merge:()=>N,makeFieldProcessorMap:()=>D,makeFieldProcessorList:()=>je,makeFieldProcessor:()=>P,locate:()=>_,loadFormat:()=>x,importList:()=>ge,importGlob:()=>Ce,globMap:()=>J,getProcessor:()=>q,getArgs:()=>fe,find:()=>Qe,exists:()=>B,defined:()=>Ue,deepClone:()=>$,conditionPredicates:()=>W,changeCase:()=>K,capital:()=>ne,camel:()=>oe,asyncMap:()=>Be,Objector:()=>lt,NavigateResult:()=>b,NavigateAction:()=>me,Logger:()=>qe,AsyncFunction:()=>Ge});var $e={};j($e,{processFields:()=>S,makeFieldProcessorMap:()=>D,makeFieldProcessorList:()=>je,makeFieldProcessor:()=>P,getProcessor:()=>q,getArgs:()=>fe});var bt=Object.create,{getPrototypeOf:vt,defineProperty:tr,getOwnPropertyNames:Ot}=Object,Mt=Object.prototype.hasOwnProperty,At=(e,r,t)=>{t=e!=null?bt(vt(e)):{};let n=r||!e||!e.__esModule?tr(t,"default",{value:e,enumerable:!0}):t;for(let o of Ot(e))if(!Mt.call(n,o))tr(n,o,{get:()=>e[o],enumerable:!0});return n},Et=(e,r)=>()=>(r||e((r={exports:{}}).exports,r),r.exports),kt=Et((e,r)=>{var{defineProperty:t,getOwnPropertyNames:n,getOwnPropertyDescriptor:o}=Object,s=Object.prototype.hasOwnProperty,a=new WeakMap,i=(u)=>{var c=a.get(u),h;if(c)return c;if(c=t({},"__esModule",{value:!0}),u&&typeof u==="object"||typeof u==="function")n(u).map((p)=>!s.call(c,p)&&t(c,p,{get:()=>u[p],enumerable:!(h=o(u,p))||h.enumerable}));return a.set(u,c),c},l=(u,c)=>{for(var h in c)t(u,h,{get:c[h],enumerable:!0,configurable:!0,set:(p)=>c[h]=()=>p})},g={};l(g,{splitWithQuotes:()=>d,splitNested:()=>y}),r.exports=i(g);var y=(u,c,h="(",p=")")=>{let w=0,f="",O=[];for(let m of u){if(f+=m,m===h)w++;if(m===p)w--;if(w===0&&m===c)O.push(f.slice(0,-1)),f=""}if(f)O.push(f);return O},d=(u,c=",")=>{let h=[],p=u.length,w=c.length,f=0,O=(m)=>{if(m+w>p)return!1;for(let M=0;M<w;M++)if(u[m+M]!==c[M])return!1;return!0};while(f<p){while(f<p&&u[f]===" ")f++;if(f>=p)break;let m="",M=u[f]==='"'||u[f]==="'";if(M){let v=u[f++];while(f<p&&u[f]!==v)m+=u[f++];if(f<p)f++}else{while(f<p&&!O(f)){let v=u[f];if(v==='"'||v==="'"){m+=v,f++;while(f<p&&u[f]!==v)m+=u[f++];if(f<p)m+=u[f++]}else m+=u[f++]}m=m.trim()}if(m)h.push({value:m,quoted:M});if(O(f))f+=w}return h}}),Ft=At(kt(),1),I;((e)=>{e[e.Explore=0]="Explore",e[e.SkipSiblings=1]="SkipSiblings",e[e.NoExplore=2]="NoExplore",e[e.ReplaceParent=3]="ReplaceParent",e[e.DeleteParent=4]="DeleteParent",e[e.MergeParent=5]="MergeParent",e[e.ReplaceItem=6]="ReplaceItem",e[e.DeleteItem=7]="DeleteItem"})(I||={});class E{action;by;skipSiblings;reexplore;constructor(e,r,t,n){this.action=e,this.by=r,this.skipSiblings=t,this.reexplore=n}static _explore=new E(0);static _noExplore=new E(2);static _skipSiblings=new E(1);static _deleteParent=new E(4);static ReplaceParent(e,r){return new E(3,e,void 0,r)}static SkipSiblings(){return E._skipSiblings}static Explore(){return E._explore}static NoExplore(){return E._noExplore}static DeleteParent(){return E._deleteParent}static MergeParent(e){return new E(5,e)}static ReplaceItem(e,r){return new E(6,e,r)}static DeleteItem(e){return new E(7,void 0,e)}}var St=async(e,r)=>{let t=new WeakSet,n=[],o=[],s=async(i,l,g)=>{let y=i===null,d=y?E.Explore():await r({key:i,value:l,path:n,parent:g,parents:o});if(l&&typeof l==="object"&&d.action===0){if(t.has(l))return d;if(t.add(l),!y)n.push(i),o.push(g);let u=l;while(await a(u,i,g))u=g[i];if(!y)o.pop(),n.pop()}return d},a=async(i,l,g)=>{let y=Object.keys(i),d=y.length;for(let u=0;u<d;u++){let c=y[u],h=i[c],p=await s(c,h,i),w=p.action;if(w===0||w===2)continue;if(w===6){if(i[c]=p.by,p.skipSiblings)return;continue}if(w===7){if(delete i[c],p.skipSiblings)return;continue}if(w===1)return;if(w===3){if(l===null)throw Error("Cannot replace root object");if(g[l]=p.by,p.reexplore)return!0;return}if(w===4){if(l===null)throw Error("Cannot delete root object");delete g[l];return}if(w===5)delete i[c],Object.assign(i,p.by)}};await s(null,e,null)},Dt=Object.create,{getPrototypeOf:jt,defineProperty:nr,getOwnPropertyNames:$t}=Object,Rt=Object.prototype.hasOwnProperty,Wt=(e,r,t)=>{t=e!=null?Dt(jt(e)):{};let n=r||!e||!e.__esModule?nr(t,"default",{value:e,enumerable:!0}):t;for(let o of $t(e))if(!Rt.call(n,o))nr(n,o,{get:()=>e[o],enumerable:!0});return n},Nt=(e,r)=>()=>(r||e((r={exports:{}}).exports,r),r.exports),Ct=Nt((e,r)=>{var{defineProperty:t,getOwnPropertyNames:n,getOwnPropertyDescriptor:o}=Object,s=Object.prototype.hasOwnProperty,a=new WeakMap,i=(u)=>{var c=a.get(u),h;if(c)return c;if(c=t({},"__esModule",{value:!0}),u&&typeof u==="object"||typeof u==="function")n(u).map((p)=>!s.call(c,p)&&t(c,p,{get:()=>u[p],enumerable:!(h=o(u,p))||h.enumerable}));return a.set(u,c),c},l=(u,c)=>{for(var h in c)t(u,h,{get:c[h],enumerable:!0,configurable:!0,set:(p)=>c[h]=()=>p})},g={};l(g,{splitWithQuotes:()=>d,splitNested:()=>y}),r.exports=i(g);var y=(u,c,h="(",p=")")=>{let w=0,f="",O=[];for(let m of u){if(f+=m,m===h)w++;if(m===p)w--;if(w===0&&m===c)O.push(f.slice(0,-1)),f=""}if(f)O.push(f);return O},d=(u,c=",")=>{let h=[],p=u.length,w=c.length,f=0,O=(m)=>{if(m+w>p)return!1;for(let M=0;M<w;M++)if(u[m+M]!==c[M])return!1;return!0};while(f<p){while(f<p&&u[f]===" ")f++;if(f>=p)break;let m="",M=u[f]==='"'||u[f]==="'";if(M){let v=u[f++];while(f<p&&u[f]!==v)m+=u[f++];if(f<p)f++}else{while(f<p&&!O(f)){let v=u[f];if(v==='"'||v==="'"){m+=v,f++;while(f<p&&u[f]!==v)m+=u[f++];if(f<p)m+=u[f++]}else m+=u[f++]}m=m.trim()}if(m)h.push({value:m,quoted:M});if(O(f))f+=w}return h}}),Lt=Wt(Ct(),1),It=/^\[([^=\]]*)([=]*)([^\]]*)\]$/,_t=/^([^[\]]*)\[([^\]]*)]$/,Se=(e,r,t,n)=>{if(e.startsWith("{")&&e.endsWith("}")){let o=e.substring(1,e.length-1);return H(r,o,t)?.toString()}return n?e:void 0},Ut=(e,r,t,n)=>{let o=Se(r,t,n);if(o)return H(e,o,n);let s=It.exec(r);if(s){let[,i,l,g]=s,y=Se(i.trim(),t,n,!0),d=Se(g.trim(),t,n,!0);if(Array.isArray(e)&&(l==="="||l==="==")&&y)return e.find((u)=>u?.[y]==d)}let a=_t.exec(r);if(a){let[,i,l]=a;return e?.[i]?.[l]}return e?.[r]},H=(e,r,t)=>{let n=void 0,o=void 0,s=r??"",a=(d)=>{if(!d)return[d,!1];return d.endsWith("?")?[d.substring(0,d.length-1),!0]:[d,!1]},i=(d,u)=>{let[c,h]=a(u.pop());if(!c){if(t?.set!==void 0&&o!==void 0&&n!==void 0)n[o]=t.set;return d}let p=Ut(d,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=d,o=c,i(p,u)},l=Lt.splitNested(s,t?.separator??".","{","}"),g=void 0;if(l.length>0&&l[l.length-1].startsWith("?="))g=l.pop()?.substring(2);l.reverse();let y=i(e,l);if(y===void 0)return g??t?.defaultValue;return y},or=(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)},ue=(e,r,t,n,o,s)=>{let a=n?.(e)??e,i=o(a);if(i[0])return i[1];if(!r){let l=H(t,e),g=o(l);if(g[0])return g[1]}throw Error(s)},ir=(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 or(r,(i)=>H(t,i));let a=or(r,()=>r.value);if(Array.isArray(s)){if(!s.includes(a))throw Error(`Argument ${n.toString()} must be one of [${s.join(", ")}]: ${a}`);return a}if(typeof s==="string"){if(s.endsWith("?")){let i=s.slice(0,-1);if(r.value==="null")return E.ReplaceItem(null);if(r.value==="undefined")return E.ReplaceItem(void 0);if(r.value==="")return"";s=i}switch(s){case"any":return a;case"array":return ue(a,r.quoted,t,null,(i)=>[Array.isArray(i),i],`Argument ${n.toString()} must be an array: ${a}`);case"object":return ue(a,r.quoted,t,null,(i)=>[typeof i==="object"&&i!==null,i],`Argument ${n.toString()} must be an object: ${a}`);case"number":return ue(a,r.quoted,t,(i)=>Number(i),(i)=>[!isNaN(i),i],`Argument ${n.toString()} must be a number: ${a}`);case"boolean":return ue(a,r.quoted,t,null,(i)=>{if([!0,"true","1",1,"yes","on"].includes(i))return[!0,!0];if([!1,"false","0",0,"no","off"].includes(i))return[!0,!1];if([null,"null","undefined",void 0,""].includes(i))return[!0,!1];if(Array.isArray(i))return[!0,i.length>0];return[!1,!1]},`Argument ${n.toString()} must be a boolean: ${a}`);case"string":return a.toString();default:throw Error(`Unknown type for argument ${n.toString()}: ${s}`)}}return s(a,t,n,r.quoted)},q=(e,r)=>{let t=e?.[r];if(t===void 0)throw Error(`Unhandled field processor type: ${r}`);return typeof t==="function"?{options:{},fn:t}:{options:t,fn:t.fn}},ar=(e)=>!e.quoted&&e.value.startsWith("."),Tt=(e)=>{let r={};for(let t of e){if(!ar(t))continue;let n=t.value.indexOf("="),o=n>-1?t.value.slice(1,n):t.value.slice(1),s=n>-1?t.value.slice(n+1):"";if(s.length>=2){let a=s[0],i=s[s.length-1];if(a==='"'&&i==='"'||a==="'"&&i==="'")s=s.slice(1,-1)}if(!r[o])r[o]=[];r[o].push(s)}return r},fe=(e,r,t)=>{let n=Ft.splitWithQuotes(e??""),o=Tt(n),s=n.filter((i)=>!ar(i)),a=r.options.processArgs===!1?[]:s.map((i,l)=>ir(r.options,i,t,l,s));return{rawArgs:s,parsedArgs:a,tags:o}},Bt=(e)=>{return e!==null&&typeof e==="object"&&"action"in e},Yt=(e,r)=>r.keys!==void 0&&e.key.startsWith(".")&&r.keys[e.key.substring(1)]!==void 0,Qt=async(e,r,t,n)=>{let{key:o,parent:s}=e,a=q(n.keys,o.substring(1));if(a.options.processArgs!==!1&&(typeof a.options.types==="function"||a.options.types?.[0]!==void 0))e.value=ir(a.options,{value:e.value,quoted:!1},t,0,[]);if(typeof e.value!=="string")await S(e.value,{...n,root:{...t,parent:e.parent,parents:e.parents},filters:[...n.filters??[],...a.options.filters??[]]});let i=await a.fn({path:r,root:t,parent:s,key:o,options:n,value:e.value,args:[],rawArgs:[],tags:{}});return Bt(i)?i:E.ReplaceParent(i)},sr=(e)=>{let r=e.split(/\r?\n/),t=r.filter((o)=>o.trim().length>0).map((o)=>/^[ \t]*/.exec(o)?.[0].length??0),n=t.length>0?Math.min(...t):0;if(n===0)return e;return r.map((o)=>o.slice(n)).join(`
|
|
2
|
-
`)},
|
|
3
|
-
`;if(p)h++;let w=c+i,f=h+i,O={},m=u,M=/(^|\r?\n)[ \t]*---[ \t]*(\r?\n|$)/m.exec(u);if(M){let
|
|
4
|
-
`).map((
|
|
5
|
-
`);let L="";if(
|
|
1
|
+
var ct=Object.create;var{getPrototypeOf:gt,defineProperty:Z,getOwnPropertyNames:rr}=Object;var Se=Object.prototype.hasOwnProperty;function Fe(e){return this[e]}var F=(e,r,t)=>{var n=rr(r);for(let o of n)if(!Se.call(e,o)&&o!=="default")Z(e,o,{get:Fe.bind(r,o),enumerable:!0});if(t){for(let o of n)if(!Se.call(t,o)&&o!=="default")Z(t,o,{get:Fe.bind(r,o),enumerable:!0});return t}},mt,yt,dt=(e,r,t)=>{var n=e!=null&&typeof e==="object";if(n){var o=r?mt??=new WeakMap:yt??=new WeakMap,s=o.get(e);if(s)return s}t=e!=null?ct(gt(e)):{};let a=r||!e||!e.__esModule?Z(t,"default",{value:e,enumerable:!0}):t;for(let i of rr(e))if(!Se.call(a,i))Z(a,i,{get:Fe.bind(e,i),enumerable:!0});if(n)o.set(e,a);return a};var wt=(e,r)=>()=>(r||e((r={exports:{}}).exports,r),r.exports);var ht=(e)=>e;function bt(e,r){this[e]=ht.bind(null,r)}var j=(e,r)=>{for(var t in r)Z(e,t,{get:r[t],enumerable:!0,configurable:!0,set:bt.bind(r,t)})};var at=wt((Ti,it)=>{var{defineProperty:xe,getOwnPropertyNames:An,getOwnPropertyDescriptor:Sn}=Object,Fn=Object.prototype.hasOwnProperty,ot=new WeakMap,kn=(e)=>{var r=ot.get(e),t;if(r)return r;if(r=xe({},"__esModule",{value:!0}),e&&typeof e==="object"||typeof e==="function")An(e).map((n)=>!Fn.call(r,n)&&xe(r,n,{get:()=>e[n],enumerable:!(t=Sn(e,n))||t.enumerable}));return ot.set(e,r),r},Dn=(e,r)=>{for(var t in r)xe(e,t,{get:r[t],enumerable:!0,configurable:!0,set:(n)=>r[t]=()=>n})},st={};Dn(st,{splitWithQuotes:()=>Rn,splitNested:()=>jn});it.exports=kn(st);var jn=(e,r,t="(",n=")")=>{let o=0,s="",a=[];for(let i of e){if(s+=i,i===t)o++;if(i===n)o--;if(o===0&&i===r)a.push(s.slice(0,-1)),s=""}if(s)a.push(s);return a},Rn=(e,r=",")=>{let t=[],n=e.length,o=r.length,s=0,a=(i)=>{if(i+o>n)return!1;for(let l=0;l<o;l++)if(e[i+l]!==r[l])return!1;return!0};while(s<n){while(s<n&&e[s]===" ")s++;if(s>=n)break;let i="",l=e[s]==='"'||e[s]==="'";if(l){let g=e[s++];while(s<n&&e[s]!==g)i+=e[s++];if(s<n)s++}else{while(s<n&&!a(s)){let g=e[s];if(g==='"'||g==="'"){i+=g,s++;while(s<n&&e[s]!==g)i+=e[s++];if(s<n)i+=e[s++]}else i+=e[s++]}i=i.trim()}if(i)t.push({value:i,quoted:l});if(a(s))s+=o}return t}});var $={};j($,{writeOutputs:()=>z,writeOutput:()=>ce,writeFormat:()=>pe,tokenize:()=>Ve,toObjectWithKey:()=>Ie,toObject:()=>ee,toList:()=>U,stripIndent:()=>Ze,sortBy:()=>Te,snake:()=>G,select:()=>E,processFields:()=>k,pascal:()=>X,padBlock:()=>N,nonNullMap:()=>_e,navigate:()=>ye,mergeAll:()=>Y,merge:()=>C,makeFieldProcessorMap:()=>D,makeFieldProcessorList:()=>je,makeFieldProcessor:()=>q,locate:()=>_,loadFormat:()=>P,importList:()=>ge,importGlob:()=>Ne,globMap:()=>J,getProcessor:()=>x,getArgs:()=>fe,find:()=>Qe,exists:()=>B,defined:()=>Ue,deepClone:()=>R,conditionPredicates:()=>W,changeCase:()=>K,capital:()=>ne,camel:()=>oe,asyncMap:()=>Be,Objector:()=>ut,NavigateResult:()=>b,NavigateAction:()=>me,Logger:()=>Ee,AsyncFunction:()=>Ke});var Re={};j(Re,{processFields:()=>k,makeFieldProcessorMap:()=>D,makeFieldProcessorList:()=>je,makeFieldProcessor:()=>q,getProcessor:()=>x,getArgs:()=>fe});var vt=Object.create,{getPrototypeOf:Ot,defineProperty:tr,getOwnPropertyNames:Mt}=Object,Et=Object.prototype.hasOwnProperty,At=(e,r,t)=>{t=e!=null?vt(Ot(e)):{};let n=r||!e||!e.__esModule?tr(t,"default",{value:e,enumerable:!0}):t;for(let o of Mt(e))if(!Et.call(n,o))tr(n,o,{get:()=>e[o],enumerable:!0});return n},St=(e,r)=>()=>(r||e((r={exports:{}}).exports,r),r.exports),Ft=St((e,r)=>{var{defineProperty:t,getOwnPropertyNames:n,getOwnPropertyDescriptor:o}=Object,s=Object.prototype.hasOwnProperty,a=new WeakMap,i=(u)=>{var c=a.get(u),h;if(c)return c;if(c=t({},"__esModule",{value:!0}),u&&typeof u==="object"||typeof u==="function")n(u).map((p)=>!s.call(c,p)&&t(c,p,{get:()=>u[p],enumerable:!(h=o(u,p))||h.enumerable}));return a.set(u,c),c},l=(u,c)=>{for(var h in c)t(u,h,{get:c[h],enumerable:!0,configurable:!0,set:(p)=>c[h]=()=>p})},g={};l(g,{splitWithQuotes:()=>y,splitNested:()=>d}),r.exports=i(g);var d=(u,c,h="(",p=")")=>{let w=0,f="",O=[];for(let m of u){if(f+=m,m===h)w++;if(m===p)w--;if(w===0&&m===c)O.push(f.slice(0,-1)),f=""}if(f)O.push(f);return O},y=(u,c=",")=>{let h=[],p=u.length,w=c.length,f=0,O=(m)=>{if(m+w>p)return!1;for(let M=0;M<w;M++)if(u[m+M]!==c[M])return!1;return!0};while(f<p){while(f<p&&u[f]===" ")f++;if(f>=p)break;let m="",M=u[f]==='"'||u[f]==="'";if(M){let v=u[f++];while(f<p&&u[f]!==v)m+=u[f++];if(f<p)f++}else{while(f<p&&!O(f)){let v=u[f];if(v==='"'||v==="'"){m+=v,f++;while(f<p&&u[f]!==v)m+=u[f++];if(f<p)m+=u[f++]}else m+=u[f++]}m=m.trim()}if(m)h.push({value:m,quoted:M});if(O(f))f+=w}return h}}),kt=At(Ft(),1),I;((e)=>{e[e.Explore=0]="Explore",e[e.SkipSiblings=1]="SkipSiblings",e[e.NoExplore=2]="NoExplore",e[e.ReplaceParent=3]="ReplaceParent",e[e.DeleteParent=4]="DeleteParent",e[e.MergeParent=5]="MergeParent",e[e.ReplaceItem=6]="ReplaceItem",e[e.DeleteItem=7]="DeleteItem"})(I||={});class 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 Dt=async(e,r)=>{let t=new WeakSet,n=[],o=[],s=async(i,l,g)=>{let d=i===null,y=d?A.Explore():await r({key:i,value:l,path:n,parent:g,parents:o});if(l&&typeof l==="object"&&y.action===0){if(t.has(l))return y;if(t.add(l),!d)n.push(i),o.push(g);let u=l;while(await a(u,i,g))u=g[i];if(!d)o.pop(),n.pop()}return y},a=async(i,l,g)=>{let d=Object.keys(i),y=d.length;for(let u=0;u<y;u++){let c=d[u],h=i[c],p=await s(c,h,i),w=p.action;if(w===0||w===2)continue;if(w===6){if(i[c]=p.by,p.skipSiblings)return;continue}if(w===7){if(delete i[c],p.skipSiblings)return;continue}if(w===1)return;if(w===3){if(l===null)throw Error("Cannot replace root object");if(g[l]=p.by,p.reexplore)return!0;return}if(w===4){if(l===null)throw Error("Cannot delete root object");delete g[l];return}if(w===5)delete i[c],Object.assign(i,p.by)}};await s(null,e,null)},jt=Object.create,{getPrototypeOf:Rt,defineProperty:nr,getOwnPropertyNames:$t}=Object,Wt=Object.prototype.hasOwnProperty,Ct=(e,r,t)=>{t=e!=null?jt(Rt(e)):{};let n=r||!e||!e.__esModule?nr(t,"default",{value:e,enumerable:!0}):t;for(let o of $t(e))if(!Wt.call(n,o))nr(n,o,{get:()=>e[o],enumerable:!0});return n},Nt=(e,r)=>()=>(r||e((r={exports:{}}).exports,r),r.exports),Lt=Nt((e,r)=>{var{defineProperty:t,getOwnPropertyNames:n,getOwnPropertyDescriptor:o}=Object,s=Object.prototype.hasOwnProperty,a=new WeakMap,i=(u)=>{var c=a.get(u),h;if(c)return c;if(c=t({},"__esModule",{value:!0}),u&&typeof u==="object"||typeof u==="function")n(u).map((p)=>!s.call(c,p)&&t(c,p,{get:()=>u[p],enumerable:!(h=o(u,p))||h.enumerable}));return a.set(u,c),c},l=(u,c)=>{for(var h in c)t(u,h,{get:c[h],enumerable:!0,configurable:!0,set:(p)=>c[h]=()=>p})},g={};l(g,{splitWithQuotes:()=>y,splitNested:()=>d}),r.exports=i(g);var d=(u,c,h="(",p=")")=>{let w=0,f="",O=[];for(let m of u){if(f+=m,m===h)w++;if(m===p)w--;if(w===0&&m===c)O.push(f.slice(0,-1)),f=""}if(f)O.push(f);return O},y=(u,c=",")=>{let h=[],p=u.length,w=c.length,f=0,O=(m)=>{if(m+w>p)return!1;for(let M=0;M<w;M++)if(u[m+M]!==c[M])return!1;return!0};while(f<p){while(f<p&&u[f]===" ")f++;if(f>=p)break;let m="",M=u[f]==='"'||u[f]==="'";if(M){let v=u[f++];while(f<p&&u[f]!==v)m+=u[f++];if(f<p)f++}else{while(f<p&&!O(f)){let v=u[f];if(v==='"'||v==="'"){m+=v,f++;while(f<p&&u[f]!==v)m+=u[f++];if(f<p)m+=u[f++]}else m+=u[f++]}m=m.trim()}if(m)h.push({value:m,quoted:M});if(O(f))f+=w}return h}}),It=Ct(Lt(),1),_t=/^\[([^=\]]*)([=]*)([^\]]*)\]$/,Ut=/^([^[\]]*)\[([^\]]*)]$/,ke=(e,r,t,n)=>{if(e.startsWith("{")&&e.endsWith("}")){let o=e.substring(1,e.length-1);return H(r,o,t)?.toString()}return n?e:void 0},Tt=(e,r,t,n)=>{let o=ke(r,t,n);if(o)return H(e,o,n);let s=_t.exec(r);if(s){let[,i,l,g]=s,d=ke(i.trim(),t,n,!0),y=ke(g.trim(),t,n,!0);if(Array.isArray(e)&&(l==="="||l==="==")&&d)return e.find((u)=>u?.[d]==y)}let a=Ut.exec(r);if(a){let[,i,l]=a;return e?.[i]?.[l]}return e?.[r]},H=(e,r,t)=>{let n=void 0,o=void 0,s=r??"",a=(y)=>{if(!y)return[y,!1];return y.endsWith("?")?[y.substring(0,y.length-1),!0]:[y,!1]},i=(y,u)=>{let[c,h]=a(u.pop());if(!c){if(t?.set!==void 0&&o!==void 0&&n!==void 0)n[o]=t.set;return y}let p=Tt(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,i(p,u)},l=It.splitNested(s,t?.separator??".","{","}"),g=void 0;if(l.length>0&&l[l.length-1].startsWith("?="))g=l.pop()?.substring(2);l.reverse();let d=i(e,l);if(d===void 0)return g??t?.defaultValue;return d},or=(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)},ue=(e,r,t,n,o,s)=>{let a=n?.(e)??e,i=o(a);if(i[0])return i[1];if(!r){let l=H(t,e),g=o(l);if(g[0])return g[1]}throw Error(s)},ir=(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 or(r,(i)=>H(t,i));let a=or(r,()=>r.value);if(Array.isArray(s)){if(!s.includes(a))throw Error(`Argument ${n.toString()} must be one of [${s.join(", ")}]: ${a}`);return a}if(typeof s==="string"){if(s.endsWith("?")){let i=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=i}switch(s){case"any":return a;case"array":return ue(a,r.quoted,t,null,(i)=>[Array.isArray(i),i],`Argument ${n.toString()} must be an array: ${a}`);case"object":return ue(a,r.quoted,t,null,(i)=>[typeof i==="object"&&i!==null,i],`Argument ${n.toString()} must be an object: ${a}`);case"number":return ue(a,r.quoted,t,(i)=>Number(i),(i)=>[!isNaN(i),i],`Argument ${n.toString()} must be a number: ${a}`);case"boolean":return ue(a,r.quoted,t,null,(i)=>{if([!0,"true","1",1,"yes","on"].includes(i))return[!0,!0];if([!1,"false","0",0,"no","off"].includes(i))return[!0,!1];if([null,"null","undefined",void 0,""].includes(i))return[!0,!1];if(Array.isArray(i))return[!0,i.length>0];return[!1,!1]},`Argument ${n.toString()} must be a boolean: ${a}`);case"string":return a.toString();default:throw Error(`Unknown type for argument ${n.toString()}: ${s}`)}}return s(a,t,n,r.quoted)},x=(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}},ar=(e)=>!e.quoted&&e.value.startsWith("."),Bt=(e)=>{let r={};for(let t of e){if(!ar(t))continue;let n=t.value.indexOf("="),o=n>-1?t.value.slice(1,n):t.value.slice(1),s=n>-1?t.value.slice(n+1):"";if(s.length>=2){let a=s[0],i=s[s.length-1];if(a==='"'&&i==='"'||a==="'"&&i==="'")s=s.slice(1,-1)}if(!r[o])r[o]=[];r[o].push(s)}return r},fe=(e,r,t)=>{let n=kt.splitWithQuotes(e??""),o=Bt(n),s=n.filter((i)=>!ar(i)),a=r.options.processArgs===!1?[]:s.map((i,l)=>ir(r.options,i,t,l,s));return{rawArgs:s,parsedArgs:a,tags:o}},Yt=(e)=>{return e!==null&&typeof e==="object"&&"action"in e},Qt=(e,r)=>r.keys!==void 0&&e.key.startsWith(".")&&r.keys[e.key.substring(1)]!==void 0,Xt=async(e,r,t,n)=>{let{key:o,parent:s}=e,a=x(n.keys,o.substring(1));if(a.options.processArgs!==!1&&(typeof a.options.types==="function"||a.options.types?.[0]!==void 0))e.value=ir(a.options,{value:e.value,quoted:!1},t,0,[]);if(typeof e.value!=="string")await k(e.value,{...n,root:{...t,parent:e.parent,parents:e.parents},filters:[...n.filters??[],...a.options.filters??[]]});let i=await a.fn({path:r,root:t,parent:s,key:o,options:n,value:e.value,args:[],rawArgs:[],tags:{}});return Yt(i)?i:A.ReplaceParent(i)},sr=(e)=>{let r=e.split(/\r?\n/),t=r.filter((o)=>o.trim().length>0).map((o)=>/^[ \t]*/.exec(o)?.[0].length??0),n=t.length>0?Math.min(...t):0;if(n===0)return e;return r.map((o)=>o.slice(n)).join(`
|
|
2
|
+
`)},Gt=async(e,r,t,n)=>{if(!r?.onSection&&!r?.onSectionConfig&&!r?.sections)return[e,!1];let o=/<@\s*section(?:\s*:\s*([\w-]+))?\s*@>([\s\S]*?)<@\s*\/\s*section\s*@>/g,s,a=e,i=0,l=!1,g={content:a,root:n,path:t,options:r,section:{}};while((s=o.exec(e))!==null){l=!0;let[d,y,u]=s,c=s.index,h=c+d.length,p=e[h]===`
|
|
3
|
+
`;if(p)h++;let w=c+i,f=h+i,O={},m=u,M=/(^|\r?\n)[ \t]*---[ \t]*(\r?\n|$)/m.exec(u);if(M){let Ae=u.slice(0,M.index),ft=M.index+M[0].length;m=u.slice(ft);let er=sr(Ae).trim();if(er.length>0)try{O=r?.configParser?.(er)??{}}catch(pt){throw Error(`Failed to parse YAML config for section: ${pt.message}`)}}else if(/^\r?\n/.test(m))m=m.replace(/^\r?\n/,"");m=sr(m),m=m.replace(/(?:\r?\n[ \t]*)+$/,""),m=m.replace(/[ \t]+$/,"");let v={config:y?{...O,type:y}:O,content:m};if(g.content=a,g.section=v,Object.keys(v.config).length>0){if(await r.onSectionConfig?.(g)!==!1)await k(v.config,{...r,root:n})}let qe=g.section.config.type?r.sections?.[g.section.config.type]:void 0,V;if(qe)V=await qe(g);else if(r.onSection)V=await r.onSection(g);if(v.trim)v.content=v.content.trim();if(v.indent)v.content=v.content.split(`
|
|
4
|
+
`).map((Ae)=>" ".repeat(v.indent)+Ae).join(`
|
|
5
|
+
`);let L="";if(V===!0||v.show)L=v.content;else if(typeof V==="string")L=V;if(p&&L!==""&&!L.endsWith(`
|
|
6
6
|
`))L+=`
|
|
7
|
-
`;let
|
|
8
|
-
`,w-1),Je=
|
|
9
|
-
(${n})`)}}),e},P=(e,r)=>r?{fn:(t)=>e(...t.args),types:r}:(t)=>e(...t.args),je=(e,r)=>Object.fromEntries(e.map((t)=>[t.name,P(t,r?.types?.[t.name])])),D=(e,r)=>Object.fromEntries((r?.keys??Object.keys(e)).map((t)=>[t,P(e[t],r?.types?.[t])]));var Le={};j(Le,{writeOutputs:()=>z,writeOutput:()=>ce,writeFormat:()=>pe,locate:()=>_,loadFormat:()=>x,importList:()=>ge,importGlob:()=>Ce,globMap:()=>J,exists:()=>B});import pr from"fs/promises";import Re from"path";import Pt from"fs/promises";import xt from"path";import Jt from"fs/promises";import zt from"fs/promises";import mr from"fs/promises";import cr from"path";import en from"fs/promises";import We from"path";import gr from"path";var B=async(e)=>{try{return await pr.access(e,pr.constants.R_OK),!0}catch{return!1}},_=async(e,r)=>{let t=!Re.isAbsolute(e)&&r?["",...r]:[""];for(let n of t){let o=Re.join(n,e);if(await B(o))return Re.resolve(o)}throw Error(`File not found: "${e}"`)},x=async(e,r)=>{let t=await _(e,r?.dirs),n=await Pt.readFile(t,"utf-8"),o=xt.dirname(t),s={text:{fn:(i)=>i,matching:["\\.txt$","\\.text$"]},json:{fn:JSON.parse,matching:["\\.json$"]},...r?.parsers},a=r?.format?s[r.format]:Object.values(s).find((i)=>i.matching?.some((l)=>new RegExp(l).test(e)));if(!a)throw Error(`Unsupported format for file "${e}" and no matching parser found`);return{content:await a.fn(n),fullPath:t,folderPath:o}},pe=async(e,r,t)=>{let n={text:{fn:(s)=>s,matching:["\\.txt$","\\.text$"]},json:{fn:JSON.stringify,matching:["\\.json$"]},...t?.encoders},o=t?.format?n[t.format]:Object.values(n).find((s)=>s.matching?.some((a)=>new RegExp(a).test(e)));if(!o)throw Error(`Unsupported format for file "${e}" and no matching encoder found`);await Jt.writeFile(e,await o.fn(r))},J=async(e,r)=>{if(typeof e==="string"&&!e.includes("*"))return await r.map(e,0,[]);let t=await Array.fromAsync(zt.glob(e,{cwd:r.cwd})),n=r.filter?t.filter(r.filter):t;return await Promise.all(n.map(r.map))},z=async(e,r)=>{if(r?.targetDirectory&&r?.removeFirst)try{await mr.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 ce(t,r)},ce=async(e,r)=>{let t=cr.join(r?.targetDirectory??".",e.name),n=cr.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 mr.mkdir(n,{recursive:!0})}catch(o){throw Error(`Failed to create target directory "${n}" for output "${t}": ${o.message}`)}try{await pe(t,e.value,{format:e.type??"text"})}catch(o){throw Error(`Failed to write output "${t}": ${o.message}`)}},Ne=(e)=>e?gr.isAbsolute(e)?e:gr.join(process.cwd(),e):process.cwd(),ge=async(e,r)=>{let t=[];for(let n of e)try{let o=!We.isAbsolute(n)?We.join(Ne(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 a=r?.resolveDefault?s.default??s:s,i=r?.map?await r.map(a,n):a;if(i!==void 0)t.push(i)}catch(o){if(r?.fail?.(n,o)===!1)continue;throw Error(`Failed to import module ${n}: ${o.message??o}`)}return t},Ce=async(e,r)=>{let t=[];for(let n of e){let o=(await Array.fromAsync(en.glob(n,{cwd:Ne(r?.cwd)}))).map((s)=>We.join(Ne(r?.cwd),s));t.push(...await ge(o,r))}return t};var Ye={};j(Ye,{toObjectWithKey:()=>Ie,toObject:()=>ee,toList:()=>U,sortBy:()=>Te,nonNullMap:()=>_e,defined:()=>Ue,deepClone:()=>$,asyncMap:()=>Be});var U=(e,r="name")=>Object.entries(e).map(([t,n])=>({[r]:t,...n})),Ie=(e,r="name")=>Object.fromEntries(e.map((t)=>[t[r],t])),ee=(e,r="name")=>Object.fromEntries(e.map((t)=>{let{[r]:n,...o}=t;return[n,o]})),_e=(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},Ue=(e,r="Value is undefined")=>{if(e===void 0||e===null)throw Error(r);return e},Te=(e,r,t=(n,o)=>n-o)=>e.slice().sort((n,o)=>t(r(n),r(o))),Be=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 tt={};j(tt,{defaultProcessors:()=>Ve});var yr={};j(yr,{navigate:()=>ye,find:()=>Qe,NavigateResult:()=>b,NavigateAction:()=>me});var me;((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"})(me||={});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 ye=async(e,r)=>{let t=new WeakSet,n=[],o=[],s=async(i,l,g)=>{let y=i===null,d=y?b.Explore():await r({key:i,value:l,path:n,parent:g,parents:o});if(l&&typeof l==="object"&&d.action===0){if(t.has(l))return d;if(t.add(l),!y)n.push(i),o.push(g);let u=l;while(await a(u,i,g))u=g[i];if(!y)o.pop(),n.pop()}return d},a=async(i,l,g)=>{let y=Object.keys(i),d=y.length;for(let u=0;u<d;u++){let c=y[u],h=i[c],p=await s(c,h,i),w=p.action;if(w===0||w===2)continue;if(w===6){if(i[c]=p.by,p.skipSiblings)return;continue}if(w===7){if(delete i[c],p.skipSiblings)return;continue}if(w===1)return;if(w===3){if(l===null)throw Error("Cannot replace root object");if(g[l]=p.by,p.reexplore)return!0;return}if(w===4){if(l===null)throw Error("Cannot delete root object");delete g[l];return}if(w===5)delete i[c],Object.assign(i,p.by)}};await s(null,e,null)},Qe=async(e,r)=>{let t=[];return await ye(e,(n)=>{if(r([...n.path,n.key].join("."),n.value))t.push(n.value);return b.Explore()}),t};var dr=(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 rn from"path";var wr=(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&&rn.dirname(t.file))}return b.DeleteItem()}});var hr={};j(hr,{mergeAll:()=>Y,merge:()=>N});var N=(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 i=t?.mismatch?.(n,s,o,e,r);if(i!==void 0){r[n]=i;continue}throw Error(`Type mismatch: ${n}`)}let a=t?.mode?.(n,s,o,e,r)??r[".merge"]??"merge";switch(a){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: ${a}`)}if(typeof s==="object")if(Array.isArray(s))o.push(...s);else{if(t?.navigate?.(n,s,o,e,r)===!1)continue;N(s,o,t)}else{if(s===o)continue;let i=t?.conflict?.(n,s,o,e,r);r[n]=i===void 0?o:i}}for(let n of Object.keys(e))if(r[n]===void 0)r[n]=e[n]},Y=(e,r)=>{let t={};for(let n of e.toReversed())N(n,t,r);return t};var br={};j(br,{CacheManager:()=>de});class de{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 Or={};j(Or,{select:()=>A});var tn=Object.create,{getPrototypeOf:nn,defineProperty:vr,getOwnPropertyNames:on}=Object,sn=Object.prototype.hasOwnProperty,an=(e,r,t)=>{t=e!=null?tn(nn(e)):{};let n=r||!e||!e.__esModule?vr(t,"default",{value:e,enumerable:!0}):t;for(let o of on(e))if(!sn.call(n,o))vr(n,o,{get:()=>e[o],enumerable:!0});return n},ln=(e,r)=>()=>(r||e((r={exports:{}}).exports,r),r.exports),un=ln((e,r)=>{var{defineProperty:t,getOwnPropertyNames:n,getOwnPropertyDescriptor:o}=Object,s=Object.prototype.hasOwnProperty,a=new WeakMap,i=(u)=>{var c=a.get(u),h;if(c)return c;if(c=t({},"__esModule",{value:!0}),u&&typeof u==="object"||typeof u==="function")n(u).map((p)=>!s.call(c,p)&&t(c,p,{get:()=>u[p],enumerable:!(h=o(u,p))||h.enumerable}));return a.set(u,c),c},l=(u,c)=>{for(var h in c)t(u,h,{get:c[h],enumerable:!0,configurable:!0,set:(p)=>c[h]=()=>p})},g={};l(g,{splitWithQuotes:()=>d,splitNested:()=>y}),r.exports=i(g);var y=(u,c,h="(",p=")")=>{let w=0,f="",O=[];for(let m of u){if(f+=m,m===h)w++;if(m===p)w--;if(w===0&&m===c)O.push(f.slice(0,-1)),f=""}if(f)O.push(f);return O},d=(u,c=",")=>{let h=[],p=u.length,w=c.length,f=0,O=(m)=>{if(m+w>p)return!1;for(let M=0;M<w;M++)if(u[m+M]!==c[M])return!1;return!0};while(f<p){while(f<p&&u[f]===" ")f++;if(f>=p)break;let m="",M=u[f]==='"'||u[f]==="'";if(M){let v=u[f++];while(f<p&&u[f]!==v)m+=u[f++];if(f<p)f++}else{while(f<p&&!O(f)){let v=u[f];if(v==='"'||v==="'"){m+=v,f++;while(f<p&&u[f]!==v)m+=u[f++];if(f<p)m+=u[f++]}else m+=u[f++]}m=m.trim()}if(m)h.push({value:m,quoted:M});if(O(f))f+=w}return h}}),fn=an(un(),1),pn=/^\[([^=\]]*)([=]*)([^\]]*)\]$/,cn=/^([^[\]]*)\[([^\]]*)]$/,Xe=(e,r,t,n)=>{if(e.startsWith("{")&&e.endsWith("}")){let o=e.substring(1,e.length-1);return A(r,o,t)?.toString()}return n?e:void 0},gn=(e,r,t,n)=>{let o=Xe(r,t,n);if(o)return A(e,o,n);let s=pn.exec(r);if(s){let[,i,l,g]=s,y=Xe(i.trim(),t,n,!0),d=Xe(g.trim(),t,n,!0);if(Array.isArray(e)&&(l==="="||l==="==")&&y)return e.find((u)=>u?.[y]==d)}let a=cn.exec(r);if(a){let[,i,l]=a;return e?.[i]?.[l]}return e?.[r]},A=(e,r,t)=>{let n=void 0,o=void 0,s=r??"",a=(d)=>{if(!d)return[d,!1];return d.endsWith("?")?[d.substring(0,d.length-1),!0]:[d,!1]},i=(d,u)=>{let[c,h]=a(u.pop());if(!c){if(t?.set!==void 0&&o!==void 0&&n!==void 0)n[o]=t.set;return d}let p=gn(d,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=d,o=c,i(p,u)},l=fn.splitNested(s,t?.separator??".","{","}"),g=void 0;if(l.length>0&&l[l.length-1].startsWith("?="))g=l.pop()?.substring(2);l.reverse();let y=i(e,l);if(y===void 0)return g??t?.defaultValue;return y};var we=(e)=>{if(typeof e.value==="string")return e.parent;let r=e.value.model;if(!r)return e.parent;if(typeof r==="string")return A(e.root,r);return r};var he=(e)=>{if(typeof e.value==="string")return A(e.root,e.value);if(Array.isArray(e.value))return e.value;let r=e.value;if(typeof r.from==="string")return A(e.root,r.from);return r.from};var be=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 S(n,{...e.options,root:{...e.root,result:r}}),n}return await A({...e.root,result:r},t.selector)};var Mr={};j(Mr,{PathManager:()=>T});import Q from"path";class T{constructor(){}static normalize(e){return Q.normalize(Q.resolve(e))}static resolveInContext(e,r){let t=r??process.cwd(),n=Q.isAbsolute(e)?e:Q.join(t,e);return this.normalize(n)}static isDirectoryPattern(e){return e.endsWith("/")}static isGlobPattern(e){return e.includes("*")}static toAbsolute(e,r){if(Q.isAbsolute(e))return e;return Q.join(r??process.cwd(),e)}}var Ar={};j(Ar,{conditionPredicatesTypes:()=>re,conditionPredicates:()=>W});var W={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)=>!W.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!=="")},re={and:()=>"boolean",or:()=>"boolean",xor:()=>"boolean",true:()=>"boolean",false:()=>"boolean",lt:()=>"number",le:()=>"number",gt:()=>"number",ge:()=>"number"};var Er=()=>({each:{filters:[/select|model/],fn:async(e)=>{let r=e.value;delete e.parent[e.key];let t=await he(e),n=await we(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=Y([r.model,...Array.isArray(r.extend.model)?r.extend.model:[r.extend.model]]);let o=[];for(let s=0;s<t.length;s++){let a=$(n);if(await S(a,{...e.options,root:{...e.root,index:s,item:t[s],instance:a}}),r.extend?.result){let i=r.extend.result;a=Y([a,...Array.isArray(i)?i:[i]])}o.push(await be(e,a))}return o}}});var kr=()=>({map:{filters:[/select|model/],fn:async(e)=>{delete e.parent[e.key];let r=await he(e),t=await we(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 S(s,{...e.options,root:{...e.root,index:o,item:r[o],instance:s}}),n.push(await be(e,s))}return n}}});var Fr=()=>({concat:async(e)=>{let r=[];for(let t of Array.isArray(e.value)?e.value:[e.value])r.push(...await A(e.root,t));return r.filter((t)=>t!==void 0)}});var Sr=()=>({extends:async(e)=>{let r=async(t,n)=>{for(let o of Array.isArray(n)?n:[n]){let s=await A(e.root,o),a=$(s);if(a[e.key])await r(a,a[e.key]);await S(a,{...e.options}),N(a,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 Dr=(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 S({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 jr=()=>({from:async({root:e,parent:r,value:t})=>{let n=await A(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 N(n,r.content),r.content}return n}});import $r from"node:vm";var Rr=(e)=>({modules:async(r)=>{for(let[t,n]of Object.entries(r.value)){let o=$r.createContext({console,objector:e,document:r.root}),s=new $r.SourceTextModule(n,{identifier:t,context:o});await s.link((a)=>{throw Error(`Module ${a} is not allowed`)}),await s.evaluate(),e.sources(Object.fromEntries(Object.entries(s.namespace).map(([a,i])=>[`${t}.${a}`,(l)=>i(l,...l.args)])))}return b.DeleteItem()}});var Wr=()=>({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 Nr=()=>({let:{fn:(e)=>{let r=e.value;return Object.assign(e.root,r),b.DeleteItem()}}});var Cr=()=>({tap:{fn:(e)=>{return console.log(`[tap] ${e.path}:`,e.value),e.value}}});var mn=(e,r)=>{let t=r.section.config.using,n=e.getFunctions();return t?Object.fromEntries(t.map((o)=>{if(o in n)return[o,n[o]];if(o in r.root)return[o,r.root[o]];throw Error(`Function or variable "${o}" not found for script section`)})):n},ve=(e,r,t,n,o=[])=>{let s=mn(e,t),a=["section","context","config","system",...Object.keys(s),...o],i=[r,t.root,t.section.config,e,...Object.values(s)];return[new Ge(...a,n).bind(t),i]},Lr=(e)=>async(r)=>{let t=[],n={write:(...o)=>{return t.push(...o),n},writeLine:(...o)=>{return t.push(...o.map((s)=>s+`
|
|
10
|
-
`)),
|
|
11
|
-
`)),
|
|
12
|
-
`,n=" ")=>{let o=n.repeat(r);return e.split(t).map((s)=>o+s).join(t)},
|
|
7
|
+
`;let Pe=a.lastIndexOf(`
|
|
8
|
+
`,w-1),Je=Pe===-1?0:Pe+1,ze=a.slice(Je,w).trim().length===0?Je:w;a=a.slice(0,ze)+L+a.slice(f),i+=L.length-(f-ze),g.content=a}return[a,l]},lr=(e)=>{let r=[],t=0;while(t<e.length)if(e[t]==="$"&&e[t+1]==="("&&(t===0||e[t-1]!=="\\")){let n=t;t+=2;let o=1;for(;t<e.length;t++)if(e[t]==="(")o++;else if(e[t]===")"){if(o--,o===0){r.push([n,t]);break}}if(o!==0)throw Error(`Unmatched opening $( at position ${n.toString()}`);t++}else t++;return r},De=Symbol.for("@homedev/fields:OverrideResult"),Kt=(e)=>({[De]:!0,value:e}),Vt=(e)=>{return e!==null&&typeof e==="object"&&De in e&&e[De]===!0},ur=async(e,r,t)=>{for(let n=r.length-1;n>=0;n--){let[o,s]=r[n],a=e.slice(o+2,s),i=await ur(a,lr(a),t);if(typeof i==="object")return i;let l=await t(i,e);if(Vt(l))return l.value;e=e.slice(0,o)+l+e.slice(s+1)}return e},Zt=async(e,r)=>ur(e,lr(e),r),Ht=(e)=>{return e!==null&&typeof e==="object"&&"action"in e},xt=/([\w\d.-_/]+):(.+)/,qt=async(e,r,t,n)=>{let o=await(async()=>{let s=xt.exec(e);if(!s)return await H(r,e);let[a,i,l]=s,g=x(n.sources,i),d=fe(l,g,r);return await g.fn({args:d.parsedArgs,rawArgs:d.rawArgs,tags:d.tags,key:i,options:n,root:r,path:t,value:null})})();if(o===null||o===void 0)return"";if(typeof o==="object")return Kt(o);return o},fr=async(e,r,t,n)=>{let o=await Zt(r,(s)=>qt(s,t,e,n));if(Ht(o))return o;if(o===r)return A.Explore();if(typeof o==="string"){let s=await fr(e,o,t,n);if(s.action!==I.Explore)return s;return A.ReplaceItem(o)}return A.ReplaceItem(o)},k=async(e,r)=>{return r??={},await Dt(e,async(t)=>{let n=[...t.path,t.key].join(".");if(r?.filters?.length&&r.filters.some((i)=>i.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 a={...e,...r.root,this:t.parent,parent:s.length>0?s[0]:null,parents:s};try{if(t.key.startsWith("$"))return A.NoExplore();let i=A.Explore();if(typeof t.value==="string"){let l=t.value,g=!1;while(!0){let[d,y]=await Gt(l,r,n,a);if(g=g||y,i=await fr(n,d,a,r),i.action===I.ReplaceItem&&typeof i.by==="string"){l=i.by;continue}if(i.action===I.Explore&&y&&d!==l)i=A.ReplaceItem(d);break}if(i.action===I.Explore&&l!==t.value)i=A.ReplaceItem(l);switch(i.action){case I.Explore:break;case I.ReplaceItem:t.value=i.by;break;default:return i}}if(Qt(t,r))i=await Xt(t,n,a,r);return i}catch(i){throw Error(`${i.message}
|
|
9
|
+
(${n})`)}}),e},q=(e,r)=>r?{fn:(t)=>e(...t.args),types:r}:(t)=>e(...t.args),je=(e,r)=>Object.fromEntries(e.map((t)=>[t.name,q(t,r?.types?.[t.name])])),D=(e,r)=>Object.fromEntries((r?.keys??Object.keys(e)).map((t)=>[t,q(e[t],r?.types?.[t])]));var Le={};j(Le,{writeOutputs:()=>z,writeOutput:()=>ce,writeFormat:()=>pe,locate:()=>_,loadFormat:()=>P,importList:()=>ge,importGlob:()=>Ne,globMap:()=>J,exists:()=>B});import pr from"fs/promises";import $e from"path";import Pt from"fs/promises";import Jt from"path";import zt from"fs/promises";import en from"fs/promises";import mr from"fs/promises";import cr from"path";import rn from"fs/promises";import We from"path";import gr from"path";var B=async(e)=>{try{return await pr.access(e,pr.constants.R_OK),!0}catch{return!1}},_=async(e,r)=>{let t=!$e.isAbsolute(e)&&r?["",...r]:[""];for(let n of t){let o=$e.join(n,e);if(await B(o))return $e.resolve(o)}throw Error(`File not found: "${e}"`)},P=async(e,r)=>{let t=await _(e,r?.dirs),n=await Pt.readFile(t,"utf-8"),o=Jt.dirname(t),s={text:{fn:(i)=>i,matching:["\\.txt$","\\.text$"]},json:{fn:JSON.parse,matching:["\\.json$"]},...r?.parsers},a=r?.format?s[r.format]:Object.values(s).find((i)=>i.matching?.some((l)=>new RegExp(l).test(e)));if(!a)throw Error(`Unsupported format for file "${e}" and no matching parser found`);return{content:await a.fn(n),fullPath:t,folderPath:o}},pe=async(e,r,t)=>{let n={text:{fn:(s)=>s,matching:["\\.txt$","\\.text$"]},json:{fn:JSON.stringify,matching:["\\.json$"]},...t?.encoders},o=t?.format?n[t.format]:Object.values(n).find((s)=>s.matching?.some((a)=>new RegExp(a).test(e)));if(!o)throw Error(`Unsupported format for file "${e}" and no matching encoder found`);await zt.writeFile(e,await o.fn(r))},J=async(e,r)=>{if(typeof e==="string"&&!e.includes("*"))return await r.map(e,0,[]);let t=await Array.fromAsync(en.glob(e,{cwd:r.cwd})),n=r.filter?t.filter(r.filter):t;return await Promise.all(n.map(r.map))},z=async(e,r)=>{if(r?.targetDirectory&&r?.removeFirst)try{await mr.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 ce(t,r)},ce=async(e,r)=>{let t=cr.join(r?.targetDirectory??".",e.name),n=cr.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 mr.mkdir(n,{recursive:!0})}catch(o){throw Error(`Failed to create target directory "${n}" for output "${t}": ${o.message}`)}try{await pe(t,e.value,{format:e.type??"text"})}catch(o){throw Error(`Failed to write output "${t}": ${o.message}`)}},Ce=(e)=>e?gr.isAbsolute(e)?e:gr.join(process.cwd(),e):process.cwd(),ge=async(e,r)=>{let t=[];for(let n of e)try{let o=!We.isAbsolute(n)?We.join(Ce(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 a=r?.resolveDefault?s.default??s:s,i=r?.map?await r.map(a,n):a;if(i!==void 0)t.push(i)}catch(o){if(r?.fail?.(n,o)===!1)continue;throw Error(`Failed to import module ${n}: ${o.message??o}`)}return t},Ne=async(e,r)=>{let t=[];for(let n of e){let o=(await Array.fromAsync(rn.glob(n,{cwd:Ce(r?.cwd)}))).map((s)=>We.join(Ce(r?.cwd),s));t.push(...await ge(o,r))}return t};var Ye={};j(Ye,{toObjectWithKey:()=>Ie,toObject:()=>ee,toList:()=>U,sortBy:()=>Te,nonNullMap:()=>_e,defined:()=>Ue,deepClone:()=>R,asyncMap:()=>Be});var U=(e,r="name")=>Object.entries(e).map(([t,n])=>({[r]:t,...n})),Ie=(e,r="name")=>Object.fromEntries(e.map((t)=>[t[r],t])),ee=(e,r="name")=>Object.fromEntries(e.map((t)=>{let{[r]:n,...o}=t;return[n,o]})),_e=(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},Ue=(e,r="Value is undefined")=>{if(e===void 0||e===null)throw Error(r);return e},Te=(e,r,t=(n,o)=>n-o)=>e.slice().sort((n,o)=>t(r(n),r(o))),Be=async(e,r)=>Promise.all(e.map(r)),R=(e)=>{if(typeof structuredClone<"u")try{return structuredClone(e)}catch{}return JSON.parse(JSON.stringify(e))};var tt={};j(tt,{defaultProcessors:()=>He});var yr={};j(yr,{navigate:()=>ye,find:()=>Qe,NavigateResult:()=>b,NavigateAction:()=>me});var me;((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"})(me||={});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 ye=async(e,r)=>{let t=new WeakSet,n=[],o=[],s=async(i,l,g)=>{let d=i===null,y=d?b.Explore():await r({key:i,value:l,path:n,parent:g,parents:o});if(l&&typeof l==="object"&&y.action===0){if(t.has(l))return y;if(t.add(l),!d)n.push(i),o.push(g);let u=l;while(await a(u,i,g))u=g[i];if(!d)o.pop(),n.pop()}return y},a=async(i,l,g)=>{let d=Object.keys(i),y=d.length;for(let u=0;u<y;u++){let c=d[u],h=i[c],p=await s(c,h,i),w=p.action;if(w===0||w===2)continue;if(w===6){if(i[c]=p.by,p.skipSiblings)return;continue}if(w===7){if(delete i[c],p.skipSiblings)return;continue}if(w===1)return;if(w===3){if(l===null)throw Error("Cannot replace root object");if(g[l]=p.by,p.reexplore)return!0;return}if(w===4){if(l===null)throw Error("Cannot delete root object");delete g[l];return}if(w===5)delete i[c],Object.assign(i,p.by)}};await s(null,e,null)},Qe=async(e,r)=>{let t=[];return await ye(e,(n)=>{if(r([...n.path,n.key].join("."),n.value))t.push(n.value);return b.Explore()}),t};var dr=(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 tn from"path";var wr=(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&&tn.dirname(t.file))}return b.DeleteItem()}});var hr={};j(hr,{mergeAll:()=>Y,merge:()=>C});var C=(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 i=t?.mismatch?.(n,s,o,e,r);if(i!==void 0){r[n]=i;continue}throw Error(`Type mismatch: ${n}`)}let a=t?.mode?.(n,s,o,e,r)??r[".merge"]??"merge";switch(a){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: ${a}`)}if(typeof s==="object")if(Array.isArray(s))o.push(...s);else{if(t?.navigate?.(n,s,o,e,r)===!1)continue;C(s,o,t)}else{if(s===o)continue;let i=t?.conflict?.(n,s,o,e,r);r[n]=i===void 0?o:i}}for(let n of Object.keys(e))if(r[n]===void 0)r[n]=e[n]},Y=(e,r)=>{let t={};for(let n of e.toReversed())C(n,t,r);return t};var br={};j(br,{CacheManager:()=>de});class de{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 Or={};j(Or,{select:()=>E});var nn=Object.create,{getPrototypeOf:on,defineProperty:vr,getOwnPropertyNames:sn}=Object,an=Object.prototype.hasOwnProperty,ln=(e,r,t)=>{t=e!=null?nn(on(e)):{};let n=r||!e||!e.__esModule?vr(t,"default",{value:e,enumerable:!0}):t;for(let o of sn(e))if(!an.call(n,o))vr(n,o,{get:()=>e[o],enumerable:!0});return n},un=(e,r)=>()=>(r||e((r={exports:{}}).exports,r),r.exports),fn=un((e,r)=>{var{defineProperty:t,getOwnPropertyNames:n,getOwnPropertyDescriptor:o}=Object,s=Object.prototype.hasOwnProperty,a=new WeakMap,i=(u)=>{var c=a.get(u),h;if(c)return c;if(c=t({},"__esModule",{value:!0}),u&&typeof u==="object"||typeof u==="function")n(u).map((p)=>!s.call(c,p)&&t(c,p,{get:()=>u[p],enumerable:!(h=o(u,p))||h.enumerable}));return a.set(u,c),c},l=(u,c)=>{for(var h in c)t(u,h,{get:c[h],enumerable:!0,configurable:!0,set:(p)=>c[h]=()=>p})},g={};l(g,{splitWithQuotes:()=>y,splitNested:()=>d}),r.exports=i(g);var d=(u,c,h="(",p=")")=>{let w=0,f="",O=[];for(let m of u){if(f+=m,m===h)w++;if(m===p)w--;if(w===0&&m===c)O.push(f.slice(0,-1)),f=""}if(f)O.push(f);return O},y=(u,c=",")=>{let h=[],p=u.length,w=c.length,f=0,O=(m)=>{if(m+w>p)return!1;for(let M=0;M<w;M++)if(u[m+M]!==c[M])return!1;return!0};while(f<p){while(f<p&&u[f]===" ")f++;if(f>=p)break;let m="",M=u[f]==='"'||u[f]==="'";if(M){let v=u[f++];while(f<p&&u[f]!==v)m+=u[f++];if(f<p)f++}else{while(f<p&&!O(f)){let v=u[f];if(v==='"'||v==="'"){m+=v,f++;while(f<p&&u[f]!==v)m+=u[f++];if(f<p)m+=u[f++]}else m+=u[f++]}m=m.trim()}if(m)h.push({value:m,quoted:M});if(O(f))f+=w}return h}}),pn=ln(fn(),1),cn=/^\[([^=\]]*)([=]*)([^\]]*)\]$/,gn=/^([^[\]]*)\[([^\]]*)]$/,Xe=(e,r,t,n)=>{if(e.startsWith("{")&&e.endsWith("}")){let o=e.substring(1,e.length-1);return E(r,o,t)?.toString()}return n?e:void 0},mn=(e,r,t,n)=>{let o=Xe(r,t,n);if(o)return E(e,o,n);let s=cn.exec(r);if(s){let[,i,l,g]=s,d=Xe(i.trim(),t,n,!0),y=Xe(g.trim(),t,n,!0);if(Array.isArray(e)&&(l==="="||l==="==")&&d)return e.find((u)=>u?.[d]==y)}let a=gn.exec(r);if(a){let[,i,l]=a;return e?.[i]?.[l]}return e?.[r]},E=(e,r,t)=>{let n=void 0,o=void 0,s=r??"",a=(y)=>{if(!y)return[y,!1];return y.endsWith("?")?[y.substring(0,y.length-1),!0]:[y,!1]},i=(y,u)=>{let[c,h]=a(u.pop());if(!c){if(t?.set!==void 0&&o!==void 0&&n!==void 0)n[o]=t.set;return y}let p=mn(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,i(p,u)},l=pn.splitNested(s,t?.separator??".","{","}"),g=void 0;if(l.length>0&&l[l.length-1].startsWith("?="))g=l.pop()?.substring(2);l.reverse();let d=i(e,l);if(d===void 0)return g??t?.defaultValue;return d};var we=(e)=>{if(typeof e.value==="string")return e.parent;let r=e.value.model;if(!r)return e.parent;if(typeof r==="string")return E(e.root,r);return r};var he=(e)=>{if(typeof e.value==="string")return E(e.root,e.value);if(Array.isArray(e.value))return e.value;let r=e.value;if(typeof r.from==="string")return E(e.root,r.from);return r.from};var be=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 k(n,{...e.options,root:{...e.root,result:r}}),n}return await E({...e.root,result:r},t.selector)};var Mr={};j(Mr,{PathManager:()=>T});import Q from"path";class T{constructor(){}static normalize(e){return Q.normalize(Q.resolve(e))}static resolveInContext(e,r){let t=r??process.cwd(),n=Q.isAbsolute(e)?e:Q.join(t,e);return this.normalize(n)}static isDirectoryPattern(e){return e.endsWith("/")}static isGlobPattern(e){return e.includes("*")}static toAbsolute(e,r){if(Q.isAbsolute(e))return e;return Q.join(r??process.cwd(),e)}}var Er={};j(Er,{conditionPredicatesTypes:()=>re,conditionPredicates:()=>W});var W={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)=>!W.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!=="")},re={and:()=>"boolean",or:()=>"boolean",xor:()=>"boolean",true:()=>"boolean",false:()=>"boolean",lt:()=>"number",le:()=>"number",gt:()=>"number",ge:()=>"number"};var Ar=()=>({each:{filters:[/select|model/],fn:async(e)=>{let r=e.value;delete e.parent[e.key];let t=await he(e),n=await we(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=Y([r.model,...Array.isArray(r.extend.model)?r.extend.model:[r.extend.model]]);let o=[];for(let s=0;s<t.length;s++){let a=R(n);if(await k(a,{...e.options,root:{...e.root,index:s,item:t[s],instance:a}}),r.extend?.result){let i=r.extend.result;a=Y([a,...Array.isArray(i)?i:[i]])}o.push(await be(e,a))}return o}}});var Sr=()=>({map:{filters:[/select|model/],fn:async(e)=>{delete e.parent[e.key];let r=await he(e),t=await we(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=R(t);await k(s,{...e.options,root:{...e.root,index:o,item:r[o],instance:s}}),n.push(await be(e,s))}return n}}});var Fr=()=>({concat:async(e)=>{let r=[];for(let t of Array.isArray(e.value)?e.value:[e.value])r.push(...await E(e.root,t));return r.filter((t)=>t!==void 0)}});var kr=()=>({extends:async(e)=>{let r=async(t,n)=>{for(let o of Array.isArray(n)?n:[n]){let s=await E(e.root,o),a=R(s);if(a[e.key])await r(a,a[e.key]);await k(a,{...e.options}),C(a,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 Dr=(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 k({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 jr=()=>({from:async({root:e,parent:r,value:t})=>{let n=await E(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 C(n,r.content),r.content}return n}});import Rr from"node:vm";var $r=(e)=>({modules:async(r)=>{for(let[t,n]of Object.entries(r.value)){let o=Rr.createContext({console,objector:e,document:r.root}),s=new Rr.SourceTextModule(n,{identifier:t,context:o});await s.link((a)=>{throw Error(`Module ${a} is not allowed`)}),await s.evaluate(),e.sources(Object.fromEntries(Object.entries(s.namespace).map(([a,i])=>[`${t}.${a}`,(l)=>i(l,...l.args)])))}return b.DeleteItem()}});var Wr=()=>({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 Cr=()=>({let:{fn:(e)=>{let r=e.value;return Object.assign(e.root,r),b.DeleteItem()}}});var Nr=()=>({tap:{fn:(e)=>{return console.log(`[tap] ${e.path}:`,e.value),e.value}}});var yn=(e,r)=>{let t=r.section.config.using,n=e.getFunctions();return t?Object.fromEntries(t.map((o)=>{if(o in n)return[o,n[o]];if(o in r.root)return[o,r.root[o]];throw Error(`Function or variable "${o}" not found for script section`)})):n},Ge=(e,r,t,n,o=[])=>{let s=yn(e,t),a=["section","context","config","system",...Object.keys(s),...o],i=[r,t.root,t.section.config,e,...Object.values(s)];return[new Ke(...a,n).bind(t),i]},dn=(e,r)=>{let t={write:(...n)=>{return r.push(...n),t},writeLine:(...n)=>{return r.push(...n.map((o)=>o+`
|
|
10
|
+
`)),t},clear:()=>{return r.splice(0,r.length),t},prepend:(...n)=>{return r.unshift(...n),t},prependLine:(...n)=>{return r.unshift(...n.map((o)=>o+`
|
|
11
|
+
`)),t},setOptions:(n)=>{return Object.assign(e.section,n),t},use:(n)=>{return n(t),t},getLines:()=>r};return t},wn=async(e,r,t)=>{let n=t.section.config.condition;if(n!==void 0){let[o,s]=Ge(e,r,t,`return (${n})`);if(!await o(...s))return!1}return!0},Lr=(e)=>async(r)=>{let t=[],n=dn(r,t);if(!await wn(e,n,r))return!1;let[o,s]=Ge(e,n,r,r.section.content,["item"]),a=r.section.config.each;if(a){let[i,l]=Ge(e,n,r,`return (${a})`),g=Array.isArray(a)?a:await i(...l);if(!Array.isArray(g))throw Error('The "each" property of a script section must return an array');for(let d of g){let y=await o(...s,d);if(typeof y<"u")t.push(y)}}else{let i=await o(...s);if(typeof i<"u")return i}if(t.length===0)return!1;return t.join("")};var Ir=(e)=>({script:Lr(e)});import _r from"fs/promises";import te from"path";var Ur=(e)=>({include:async(r)=>{let{file:t}=r.options.globalContext;return await J(r.args[0],{cwd:te.dirname(t),filter:(n)=>te.basename(t)!==n,map:async(n)=>e.load(n,te.dirname(t),r.root)})},exists:async({args:[r]})=>await B(r),file:async(r)=>await _r.readFile(await _(r.args[0],e.getIncludeDirectories())).then((t)=>t.toString()),scan:async(r)=>{let t=[],o=(()=>{let i=r.args[2]??["**/node_modules/**"],l=typeof i==="string"?i.split(",").map((g)=>g.trim()):i;if(!Array.isArray(l))throw Error("Scan exclusion must be a list");return l})(),{file:s}=r.options.globalContext,a=r.args[1]?await _(r.args[1],e.getIncludeDirectories()):te.dirname(s);for await(let i of _r.glob(r.args[0],{cwd:a,exclude:(l)=>o.some((g)=>te.matchesGlob(l,g))}))t.push(i);return t}});var Tr=()=>D({env:(e)=>process.env[e]});var Br={};j(Br,{tokenize:()=>Ve,stripIndent:()=>Ze,snake:()=>G,pascal:()=>X,padBlock:()=>N,changeCase:()=>K,capital:()=>ne,camel:()=>oe});var X=(e)=>e.replace(/((?:[_ ]+)\w|^\w)/g,(r,t)=>t.toUpperCase()).replace(/[_ ]/g,""),ne=(e)=>e.replace(/((?:[ ]+)\w|^\w)/g,(r,t)=>t.toUpperCase()),oe=(e)=>{let r=X(e);return r.charAt(0).toLowerCase()+r.slice(1)},G=(e,r="_")=>e.replace(/([a-z])([A-Z])/g,`$1${r}$2`).replace(/\s+/g,r).toLowerCase(),K=(e,r)=>{switch(r){case"upper":return e.toUpperCase();case"lower":return e.toLowerCase();default:return e}},N=(e,r,t=`
|
|
12
|
+
`,n=" ")=>{let o=n.repeat(r);return e.split(t).map((s)=>o+s).join(t)},Ve=(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)})},Ze=(e)=>{let r=e.split(/\r?\n/),t=r.filter((o)=>o.trim().length>0).map((o)=>/^[ \t]*/.exec(o)?.[0].length??0),n=t.length>0?Math.min(...t):0;if(n===0)return e;return r.map((o)=>o.slice(n)).join(`
|
|
13
13
|
`)};var Yr=(e)=>({substring:{types:{0:"ref",1:"number",2:"number"},fn:(r)=>r.args[0].substring(r.args[1],r.args[2])},repeat:{types:{0:"ref",1:"number"},fn:({args:[r,t]})=>r.repeat(t)},uuid:(r)=>crypto.randomUUID(),pad:{types:{0:"ref",1:"number",2:"string"},fn:({args:[r,t],tags:n})=>{let o=n.join?.[0]??`
|
|
14
|
-
`,s=n.padChar?.[0]??" ";return
|
|
15
|
-
${e.map((a)=>`${o}${
|
|
14
|
+
`,s=n.padChar?.[0]??" ";return N(r,t??2,o,s)}},formatAs:{fn:({args:[r,t],tags:n})=>{let o=e.getEncoder(t);if(!o)throw Error("Unsupported format: "+String(t));let s=[];if(o.options?.includeTags)s=[n];return o.fn(r,...s)}},...D({pascal:X,camel:oe,capital:ne,concat:(...r)=>r.join(""),len:(r)=>r.length,reverse:(r)=>r.split("").reverse().join(""),trim:(r)=>r.trim(),ltrim:(r)=>r.trimStart(),rtrim:(r)=>r.trimEnd(),lower:(r)=>r.toLowerCase(),upper:(r)=>r.toUpperCase(),snake:(r,t)=>K(G(r,"_"),t),kebab:(r,t)=>K(G(r,"-"),t),encode:(r,t)=>Buffer.from(r).toString(t??"base64"),decode:(r,t)=>Buffer.from(r,t??"base64").toString()})});var ve=(e,r=0,t)=>{let n=" ".repeat(r),o=" ".repeat(r+1);if(e===null||e===void 0)return"null";else if(typeof e==="boolean")return String(e);else if(typeof e==="number")return String(e);else if(typeof e==="string")return`"${e.replace(/\\/g,"\\\\").replace(/"/g,"\\\"").replace(/\n/g,"\\n").replace(/\r/g,"\\r").replace(/\t/g,"\\t")}"`;else if(Array.isArray(e)){if(e.length===0)return"[]";return`[
|
|
15
|
+
${e.map((a)=>`${o}${ve(a,r+1)},`).join(`
|
|
16
16
|
`)}
|
|
17
17
|
${n}]`}else if(typeof e==="object"){let s=Object.entries(e).sort((i,l)=>t?.sortKeys?i[0].localeCompare(l[0]):0);if(s.length===0)return"{}";return`{
|
|
18
|
-
${s.map(([i,l])=>`${o}${i} = ${
|
|
18
|
+
${s.map(([i,l])=>`${o}${i} = ${ve(l,r+1,t)}`).join(`
|
|
19
19
|
`)}
|
|
20
20
|
${n}}`}else return String(e)},se=(e)=>{if(!e)return e;return e.replaceAll("\\n",`
|
|
21
|
-
`).replaceAll("\\$","$").replaceAll("\\t","\t")};var Qr=()=>({...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,a=se(o);if(typeof e==="string"){if(s&&e.length&&a)return e+a;return e}if(!Array.isArray(e))throw Error("Object is not a list");let i=((n?.length)?e.map((
|
|
22
|
-
`,g):
|
|
23
|
-
`,f):m}return d}}});var ie=async(e,r,t)=>e.rawArgs[r].quoted?e.rawArgs[r].value:await A(e.root,e.rawArgs[r].value,{defaultValue:t}),Gr=()=>({switch:{processArgs:!1,fn:async(e)=>{let r=await ie(e,0,!1),t=await ie(e,1);if(t[r]===void 0){if(e.rawArgs.length>2)return ie(e,2);throw Error(`Unhandled switch case: ${r}`)}return t[r]}}});var Kr=()=>D({log:console.log});var Zr=()=>({if:{types:{0:"boolean"},fn:(e)=>e.args[0]?e.args[1]:e.args[2]},check:{types:{0:Object.keys(W)},fn:(e)=>W[e.args[0]](...e.args.slice(1))},...D(W,{types:re})});var Vr=(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 ie(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 Hr=()=>({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 qr=()=>({...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 Pr=()=>({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"),a=String(n.getDate()).padStart(2,"0"),i=String(n.getHours()).padStart(2,"0"),l=String(n.getMinutes()).padStart(2,"0"),g=String(n.getSeconds()).padStart(2,"0");return t.replace("YYYY",String(o)).replace("MM",s).replace("DD",a).replace("HH",i).replace("mm",l).replace("ss",g)},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 xr=()=>{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,a)=>{for(let i of s)if(Array.isArray(i)&&a>0)o(i,a-1);else n.push(i)};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 ae}from"crypto";var Jr=()=>({md5:(e)=>{let r=e.args?.[0]??e.value;return ae("md5").update(r).digest("hex")},sha1:(e)=>{let r=e.args?.[0]??e.value;return ae("sha1").update(r).digest("hex")},sha256:(e)=>{let r=e.args?.[0]??e.value;return ae("sha256").update(r).digest("hex")},sha512:(e)=>{let r=e.args?.[0]??e.value;return ae("sha512").update(r).digest("hex")},hash:(e)=>{let r=e.args?.[0]??e.value,t=e.args?.[1]??"sha256";return ae(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 zr=()=>({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 yn,dirname as dn,basename as wn,normalize as hn,join as bn}from"path";var et=()=>({...D({pathJoin:(...e)=>bn(...e),resolve:(...e)=>yn(...e),dirname:(e)=>dn(e),basename:(e,r)=>wn(e,r),normalize:(e)=>hn(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,a=n.slice(o);return[...Array(s).fill("..")].concat(a).join("/")},isAbsolute:(e)=>e.startsWith("/"),segments:(e)=>e.split("/").filter(Boolean)})});var rt=()=>({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 Ve=(e)=>e.keys(dr(e)).keys(wr(e)).keys(Er()).keys(kr()).keys(jr()).keys(Fr()).keys(Sr()).keys(Dr(e)).keys(Rr(e)).keys(Wr()).keys(Nr()).keys(Cr()).sources(Ur(e)).sources(Tr()).sources(Yr(e)).sources(Hr()).sources(Qr()).sources(Xr()).sources(Gr()).sources(Kr()).sources(Zr()).sources(Vr(e)).sources(qr()).sources(Pr()).sources(xr()).sources(Jr()).sources(zr()).sources(et()).sources(rt()).sections(Ir(e)).fieldOptions({configParser:Bun.YAML.parse,onSection:(r)=>{if(r.section.config.name)e.section(r.section)}}).decoders({yaml:{matching:["\\.yml$","\\.yaml$"],fn:Bun.YAML.parse}}).encoders({json:{fn:(r)=>JSON.stringify(r,null,2)},yaml:{fn:(r)=>Bun.YAML.stringify(r,null,2)},terraform:{options:{includeTags:!0},fn:(r,t)=>Oe(r,0,{sortKeys:!!(t?.sort?.length??t?.sortKeys?.length)})}});var nt={};j(nt,{IncludeManager:()=>Me,DocumentIncludeProcessor:()=>Ae});import vn from"fs/promises";import le 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(T.isGlobPattern(o)){let s=(await Array.fromAsync(vn.glob(o,{cwd:r}))).map((a)=>le.join(r,a));for(let a of s)if(!t.included.includes(a))n.push(a)}else if(T.isDirectoryPattern(o)){let s=le.isAbsolute(o)?o:le.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)=>le.isAbsolute(t)?t:le.join(e??process.cwd(),t))),r}}class Ae{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)N(await this.loadFn(s,e.folderPath,{parent:e.content,...r},!0,t),e.content)}}var k={};j(k,{writeOutputs:()=>z,writeOutput:()=>ce,writeFormat:()=>pe,tokenize:()=>Ke,toObjectWithKey:()=>Ie,toObject:()=>ee,toList:()=>U,stripIndent:()=>Ze,sortBy:()=>Te,snake:()=>G,select:()=>A,processFields:()=>S,pascal:()=>X,padBlock:()=>C,nonNullMap:()=>_e,navigate:()=>ye,mergeAll:()=>Y,merge:()=>N,makeFieldProcessorMap:()=>D,makeFieldProcessorList:()=>je,makeFieldProcessor:()=>P,locate:()=>_,loadFormat:()=>x,importList:()=>ge,importGlob:()=>Ce,globMap:()=>J,getProcessor:()=>q,getArgs:()=>fe,find:()=>Qe,exists:()=>B,defined:()=>Ue,deepClone:()=>$,conditionPredicates:()=>W,changeCase:()=>K,capital:()=>ne,camel:()=>oe,asyncMap:()=>Be,NavigateResult:()=>b,NavigateAction:()=>me,Logger:()=>qe});F(k,yt(at(),1));class qe{options;constructor(e){this.options={level:"INFO",showClass:!1,levels:["DEBUG","INFO","WARN","ERROR"],timeStamp:!1,timeOptions:{second:"2-digit",minute:"2-digit",hour:"2-digit",day:"2-digit",month:"2-digit",year:"2-digit"},logFunction:(r,...t)=>{switch(r){case"ERROR":console.error(...t);break;case"WARN":console.warn(...t);break;case"DEBUG":console.debug(...t);break;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)}info(...e){this.write("INFO",...e)}error(...e){this.write("ERROR",...e)}warn(...e){this.write("WARN",...e)}debug(...e){this.write("DEBUG",...e)}}F(R,k);var Ge=Object.getPrototypeOf(async function(){}).constructor;class lt{includeManager=new Me;includeProcessor;cacheManager=new de(100);outputs=[];vars={};funcs={};fields={sources:{},keys:{},sections:{}};objectMetadata={};currentContext=null;storedSections={};dataEncoders={};dataDecoders={};constructor(){this.includeProcessor=new Ae(this.includeManager,this.load.bind(this)),this.use(Ve)}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}sections(e){return Object.assign(this.fields.sections,{...this.fields.sections,...e}),this}variables(e){return this.vars={...this.vars,...e},this}functions(e){return this.funcs={...this.funcs,...e},this}getFunctions(){return this.funcs}getOutputs(){return this.outputs}output(e){return this.outputs.push(e),this}metadata(e,r){return this.objectMetadata[e]=r,this}getMetadata(e){return this.objectMetadata[e]}getAllMetadata(){return this.objectMetadata}setCacheMaxSize(e){return this.cacheManager.setMaxSize(e),this}clearCache(){return this.cacheManager.clear(),this}getCurrentContext(){return this.currentContext}fieldOptions(e){return this.fields={...this.fields,...e},this}section(e){return this.storedSections[e.config.name]=e,this}getSection(e){return this.storedSections[e]}encoders(e){return this.dataEncoders={...this.dataEncoders,...e},this}decoders(e){return this.dataDecoders={...this.dataDecoders,...e},this}getEncoder(e){return this.dataEncoders[e]}getDecoder(e){return this.dataDecoders[e]}filter(e){return this.fields.filters??=[],this.fields.filters.push(e),this}async loadObject(e,r,t){return await S(e,{...this.fields,globalContext:{file:t?.fullPath??"@internal"},root:{...r,...this.fields.root,...this.vars,functions:this.funcs,context:this.currentContext,sections:this.storedSections,$document:{root:{content:e},fileName:t?.fileName??"@internal",folder:t?.folderPath??"@internal",fullPath:t?.fullPath??"@internal"}}}),e}async load(e,r,t,n,o){let s=this.includeManager.snapshot();try{this.includeManager.reset();let a=this.includeManager.buildSearchDirs(r);if(o)this.currentContext=o;this.currentContext??={included:[],document:null};let i=await x(e,{dirs:a,parsers:this.dataDecoders,format:"yaml"}),l=T.normalize(i.fullPath);if(this.currentContext.included.push(l),!i.content)return null;let g=this.cacheManager.get(l),y;if(g)y=g.raw;else y=i.content,this.cacheManager.set(l,{raw:y,timestamp:Date.now()});let d=$(y);i.content=d,await this.includeProcessor.processIncludes(i,t,this.currentContext);let u;if(n!==!0)u=await this.loadObject(i.content,t,{fileName:i.fullPath,folderPath:i.folderPath,fullPath:i.fullPath});else u=i.content;return this.currentContext.document=u,u}catch(a){throw this.includeManager.restore(s),a}finally{this.includeManager.restore(s)}}async writeAll(e){await z(this.getOutputs(),e)}}export{z as writeOutputs,ce as writeOutput,pe as writeFormat,Ke as tokenize,Ie as toObjectWithKey,ee as toObject,U as toList,Ze as stripIndent,Te as sortBy,G as snake,A as select,S as processFields,X as pascal,C as padBlock,_e as nonNullMap,ye as navigate,Y as mergeAll,N as merge,D as makeFieldProcessorMap,je as makeFieldProcessorList,P as makeFieldProcessor,_ as locate,x as loadFormat,ge as importList,Ce as importGlob,J as globMap,q as getProcessor,fe as getArgs,Qe as find,B as exists,Ue as defined,$ as deepClone,W as conditionPredicates,K as changeCase,ne as capital,oe as camel,Be as asyncMap,lt as Objector,b as NavigateResult,me as NavigateAction,qe as Logger,Ge as AsyncFunction};
|
|
21
|
+
`).replaceAll("\\$","$").replaceAll("\\t","\t")};var Qr=()=>({...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,a=se(o);if(typeof e==="string"){if(s&&e.length&&a)return e+a;return e}if(!Array.isArray(e))throw Error("Object is not a list");let i=((n?.length)?e.map((y)=>E({...r,...y},n)):e).join(a),l=t.pad?.[0]??"0",g=t.padChar?.[0]??" ",d=s&&i.length&&a?i+a:i;return l?N(d,parseInt(l),`
|
|
22
|
+
`,g):d},list:({args:e})=>U(e[0],e[1]),object:({args:e})=>ee(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},(a,i)=>n+i*s)},filter:{types:(e,r,t)=>{switch(e){case 0:return"array";case 1:return Object.keys(W)}return re[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],a=W[r];if(s){let l=Array(e.length);for(let d=0;d<e.length;d++)try{l[d]=E({...n,...e[d]},s)}catch{l[d]=Symbol("invalid")}let g=[];for(let d=0;d<e.length;d++){let y=l[d];if(typeof y!=="symbol"&&t===void 0?a(y):a(y,t))g.push(e[d])}return g}let i=[];for(let l of e)if(t===void 0?a(l):a(l,t))i.push(l);return i}}});var Xr=()=>({each:{processArgs:!1,fn:async({rawArgs:[e,r,...t],root:n,options:o,tags:s})=>{let a=async(p)=>p.quoted?se(p.value):await E(n,p.value),i=await E(n,e.value),l=await a(r),g=s.key?.[0],d=Array.isArray(i)?i:U(i),y=[],u=await Promise.all(t.map(async(p)=>await a(p))),c={...n,item:void 0,index:0,params:u,instance:void 0,parent:n.this,tags:s},h={...o,root:c};for(let p=0;p<d.length;p++){let w=R(l),f={instance:w},O=typeof l==="string"?f:w;if(c.item=d[p],c.index=p,c.instance=w,s?.root?.[0])Object.assign(c,await E(c,s.root[0]));if(await k(O,h),g!==void 0)y.push(await E(f.instance,g));else y.push(f.instance)}if(s.join?.length){if(y.length===0)return"";let p=se(s.join[0]),w=s.pad?.[0]??"0",f=s.padChar?.[0]??" ",O=s.finalize?.length&&p?p:"",m=`${y.join(p)}${O}`;return w?N(m,parseInt(w),`
|
|
23
|
+
`,f):m}return y}}});var ie=async(e,r,t)=>e.rawArgs[r].quoted?e.rawArgs[r].value:await E(e.root,e.rawArgs[r].value,{defaultValue:t}),Gr=()=>({switch:{processArgs:!1,fn:async(e)=>{let r=await ie(e,0,!1),t=await ie(e,1);if(t[r]===void 0){if(e.rawArgs.length>2)return ie(e,2);throw Error(`Unhandled switch case: ${r}`)}return t[r]}}});var Kr=()=>D({log:console.log});var Vr=()=>({if:{types:{0:"boolean"},fn:(e)=>e.args[0]?e.args[1]:e.args[2]},check:{types:{0:Object.keys(W)},fn:(e)=>W[e.args[0]](...e.args.slice(1))},...D(W,{types:re})});var Zr=(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 ie(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 Hr=()=>({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 xr=()=>({...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 qr=()=>({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"),a=String(n.getDate()).padStart(2,"0"),i=String(n.getHours()).padStart(2,"0"),l=String(n.getMinutes()).padStart(2,"0"),g=String(n.getSeconds()).padStart(2,"0");return t.replace("YYYY",String(o)).replace("MM",s).replace("DD",a).replace("HH",i).replace("mm",l).replace("ss",g)},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 Pr=()=>{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,a)=>{for(let i of s)if(Array.isArray(i)&&a>0)o(i,a-1);else n.push(i)};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 ae}from"crypto";var Jr=()=>({md5:(e)=>{let r=e.args?.[0]??e.value;return ae("md5").update(r).digest("hex")},sha1:(e)=>{let r=e.args?.[0]??e.value;return ae("sha1").update(r).digest("hex")},sha256:(e)=>{let r=e.args?.[0]??e.value;return ae("sha256").update(r).digest("hex")},sha512:(e)=>{let r=e.args?.[0]??e.value;return ae("sha512").update(r).digest("hex")},hash:(e)=>{let r=e.args?.[0]??e.value,t=e.args?.[1]??"sha256";return ae(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 zr=()=>({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 hn,dirname as bn,basename as vn,normalize as On,join as Mn}from"path";var et=()=>({...D({pathJoin:(...e)=>Mn(...e),resolve:(...e)=>hn(...e),dirname:(e)=>bn(e),basename:(e,r)=>vn(e,r),normalize:(e)=>On(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,a=n.slice(o);return[...Array(s).fill("..")].concat(a).join("/")},isAbsolute:(e)=>e.startsWith("/"),segments:(e)=>e.split("/").filter(Boolean)})});var rt=()=>({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 He=(e)=>e.keys({...dr(e),...wr(e),...Ar(),...Sr(),...jr(),...Fr(),...kr(),...Dr(e),...$r(e),...Wr(),...Cr(),...Nr()}).sources({...Ur(e),...Tr(),...Yr(e),...Hr(),...Qr(),...Xr(),...Gr(),...Kr(),...Vr(),...Zr(e),...xr(),...qr(),...Pr(),...Jr(),...zr(),...et(),...rt()}).sections(Ir(e)).fieldOptions({configParser:Bun.YAML.parse,onSection:(r)=>{if(r.section.config.name)e.section(r.section)}}).decoders({yaml:{matching:["\\.yml$","\\.yaml$"],fn:Bun.YAML.parse}}).encoders({json:{fn:(r)=>JSON.stringify(r,null,2)},yaml:{fn:(r)=>Bun.YAML.stringify(r,null,2)},terraform:{options:{includeTags:!0},fn:(r,t)=>ve(r,0,{sortKeys:!!(t?.sort?.length??t?.sortKeys?.length)})}});var nt={};j(nt,{IncludeManager:()=>Oe,DocumentIncludeProcessor:()=>Me});import En from"fs/promises";import le from"path";class Oe{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(T.isGlobPattern(o)){let s=(await Array.fromAsync(En.glob(o,{cwd:r}))).map((a)=>le.join(r,a));for(let a of s)if(!t.included.includes(a))n.push(a)}else if(T.isDirectoryPattern(o)){let s=le.isAbsolute(o)?o:le.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)=>le.isAbsolute(t)?t:le.join(e??process.cwd(),t))),r}}class Me{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)C(await this.loadFn(s,e.folderPath,{parent:e.content,...r},!0,t),e.content)}}var S={};j(S,{writeOutputs:()=>z,writeOutput:()=>ce,writeFormat:()=>pe,tokenize:()=>Ve,toObjectWithKey:()=>Ie,toObject:()=>ee,toList:()=>U,stripIndent:()=>Ze,sortBy:()=>Te,snake:()=>G,select:()=>E,processFields:()=>k,pascal:()=>X,padBlock:()=>N,nonNullMap:()=>_e,navigate:()=>ye,mergeAll:()=>Y,merge:()=>C,makeFieldProcessorMap:()=>D,makeFieldProcessorList:()=>je,makeFieldProcessor:()=>q,locate:()=>_,loadFormat:()=>P,importList:()=>ge,importGlob:()=>Ne,globMap:()=>J,getProcessor:()=>x,getArgs:()=>fe,find:()=>Qe,exists:()=>B,defined:()=>Ue,deepClone:()=>R,conditionPredicates:()=>W,changeCase:()=>K,capital:()=>ne,camel:()=>oe,asyncMap:()=>Be,NavigateResult:()=>b,NavigateAction:()=>me,Logger:()=>Ee});F(S,dt(at(),1));var lt={};j(lt,{Logger:()=>Ee});class Ee{options;constructor(e){this.options={level:"INFO",showClass:!1,levels:["DEBUG","VERBOSE","INFO","WARN","ERROR"],timeStamp:!1,timeOptions:{second:"2-digit",minute:"2-digit",hour:"2-digit",day:"2-digit",month:"2-digit",year:"2-digit"},logFunction:(r,...t)=>{switch(r){case"ERROR":console.error(...t);break;case"WARN":console.warn(...t);break;case"DEBUG":console.debug(...t);break;case"VERBOSE":console.log(...t);break;default:console.log(...t)}},...e}}write(e,...r){if(this.options.level){let o=this.options.levels.indexOf(this.options.level)??-1,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)}info(...e){this.write("INFO",...e)}error(...e){this.write("ERROR",...e)}warn(...e){this.write("WARN",...e)}debug(...e){this.write("DEBUG",...e)}verbose(...e){this.write("VERBOSE",...e)}}F($,S);var Ke=Object.getPrototypeOf(async function(){}).constructor;class ut{includeManager=new Oe;includeProcessor;cacheManager=new de(100);outputs=[];vars={};funcs={};fields={sources:{},keys:{},sections:{}};objectMetadata={};currentContext=null;storedSections={};dataEncoders={};dataDecoders={};constructor(){this.includeProcessor=new Me(this.includeManager,this.load.bind(this)),this.use(He)}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}sections(e){return Object.assign(this.fields.sections,{...this.fields.sections,...e}),this}variables(e){return this.vars={...this.vars,...e},this}functions(e){return this.funcs={...this.funcs,...e},this}getFunctions(){return this.funcs}getOutputs(){return this.outputs}output(e){return this.outputs.push(e),this}metadata(e,r){return this.objectMetadata[e]=r,this}getMetadata(e){return this.objectMetadata[e]}getAllMetadata(){return this.objectMetadata}setCacheMaxSize(e){return this.cacheManager.setMaxSize(e),this}clearCache(){return this.cacheManager.clear(),this}getCurrentContext(){return this.currentContext}fieldOptions(e){return this.fields={...this.fields,...e},this}section(e){return this.storedSections[e.config.name]=e,this}getSection(e){return this.storedSections[e]}encoders(e){return this.dataEncoders={...this.dataEncoders,...e},this}decoders(e){return this.dataDecoders={...this.dataDecoders,...e},this}getEncoder(e){return this.dataEncoders[e]}getDecoder(e){return this.dataDecoders[e]}filter(e){return this.fields.filters??=[],this.fields.filters.push(e),this}async loadObject(e,r,t){return k(e,{...this.fields,globalContext:{file:t?.fullPath??"@internal"},root:{...r,...this.fields.root,...this.vars,functions:this.funcs,context:this.currentContext,sections:this.storedSections,$document:{root:{content:e},fileName:t?.fileName??"@internal",folder:t?.folderPath??"@internal",fullPath:t?.fullPath??"@internal"}}})}async load(e,r,t,n,o){let s=this.includeManager.snapshot();try{this.includeManager.reset();let a=this.includeManager.buildSearchDirs(r);if(o)this.currentContext=o;this.currentContext??={included:[],document:null};let i=await P(e,{dirs:a,parsers:this.dataDecoders,format:"yaml"}),l=T.normalize(i.fullPath);if(this.currentContext.included.push(l),!i.content)return null;let g=this.cacheManager.get(l),d;if(g)d=g.raw;else d=i.content,this.cacheManager.set(l,{raw:d,timestamp:Date.now()});let y=R(d);i.content=y,await this.includeProcessor.processIncludes(i,t,this.currentContext);let u;if(n!==!0)u=await this.loadObject(i.content,t,{fileName:i.fullPath,folderPath:i.folderPath,fullPath:i.fullPath});else u=i.content;return this.currentContext.document=u,u}catch(a){throw this.includeManager.restore(s),a}finally{this.includeManager.restore(s)}}async writeAll(e){await z(this.getOutputs(),e)}}export{z as writeOutputs,ce as writeOutput,pe as writeFormat,Ve as tokenize,Ie as toObjectWithKey,ee as toObject,U as toList,Ze as stripIndent,Te as sortBy,G as snake,E as select,k as processFields,X as pascal,N as padBlock,_e as nonNullMap,ye as navigate,Y as mergeAll,C as merge,D as makeFieldProcessorMap,je as makeFieldProcessorList,q as makeFieldProcessor,_ as locate,P as loadFormat,ge as importList,Ne as importGlob,J as globMap,x as getProcessor,fe as getArgs,Qe as find,B as exists,Ue as defined,R as deepClone,W as conditionPredicates,K as changeCase,ne as capital,oe as camel,Be as asyncMap,ut as Objector,b as NavigateResult,me as NavigateAction,Ee as Logger,Ke as AsyncFunction};
|