@arc-js/config-manager 0.0.1 → 0.0.2

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/index.js CHANGED
@@ -8,7 +8,7 @@ function __awaiter(thisArg, _arguments, P, generator) {
8
8
  function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
9
9
  function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
10
10
  function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
11
- step((generator = generator.apply(thisArg, [])).next());
11
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
12
12
  });
13
13
  }
14
14
 
@@ -2269,17 +2269,12 @@ var jsxRuntimeExports = requireJsxRuntime();
2269
2269
  var reactExports = requireReact();
2270
2270
 
2271
2271
  const mergeDeep = (target, source) => {
2272
- if (typeof target !== 'object' || typeof source !== 'object') {
2272
+ if (typeof target !== 'object' || typeof source !== 'object')
2273
2273
  return source;
2274
- }
2275
2274
  const output = Object.assign({}, target);
2276
2275
  for (const key in source) {
2277
2276
  if (source.hasOwnProperty(key)) {
2278
- if (target.hasOwnProperty(key) &&
2279
- typeof target[key] === 'object' &&
2280
- typeof source[key] === 'object' &&
2281
- !Array.isArray(target[key]) &&
2282
- !Array.isArray(source[key])) {
2277
+ if (target.hasOwnProperty(key)) {
2283
2278
  output[key] = mergeDeep(target[key], source[key]);
2284
2279
  }
2285
2280
  else {
@@ -2290,1166 +2285,235 @@ const mergeDeep = (target, source) => {
2290
2285
  return output;
2291
2286
  };
2292
2287
 
2293
- var cooks = {};
2294
-
2295
- var timez = {};
2296
-
2297
- var hasRequiredTimez;
2298
-
2299
- function requireTimez () {
2300
- if (hasRequiredTimez) return timez;
2301
- hasRequiredTimez = 1;
2302
-
2303
- Object.defineProperty(timez, '__esModule', { value: true });
2304
-
2305
- class Timez {
2306
- constructor(input, enableException = false) {
2307
- if (this.dateChecker(input) === false) {
2308
- this._date = undefined;
2309
- }
2310
- else {
2311
- if (input instanceof Timez && !!input && !!(input === null || input === void 0 ? void 0 : input._date)) {
2312
- this._date = new Date(input === null || input === void 0 ? void 0 : input._date);
2313
- }
2314
- else if (input instanceof Date) {
2315
- this._date = new Date(input);
2316
- }
2317
- else if (typeof input === 'string') {
2318
- this._date = Timez.parseString(input, enableException);
2319
- }
2320
- else if (typeof input === 'number') {
2321
- this._date = new Date(input);
2322
- }
2323
- else if (input === undefined ||
2324
- input === null ||
2325
- (typeof input === 'number' && isNaN(input))) {
2326
- this._date = new Date();
2327
- }
2328
- else {
2329
- this._date = undefined;
2330
- }
2331
- }
2332
- }
2333
- static now() {
2334
- return new Timez();
2335
- }
2336
- static parse(dateString, format) {
2337
- if (typeof format === 'string' &&
2338
- format.length > 0 && ((dateString instanceof Timez &&
2339
- !!dateString &&
2340
- !!(dateString === null || dateString === void 0 ? void 0 : dateString._date)) ||
2341
- dateString instanceof Date ||
2342
- typeof dateString === 'string' ||
2343
- typeof dateString === 'number' || (dateString === undefined ||
2344
- dateString === null ||
2345
- (typeof dateString === 'number' && isNaN(dateString))))) {
2346
- return Timez.parseWithFormat(dateString, format) || new Timez(dateString);
2347
- }
2348
- return new Timez(dateString);
2349
- }
2350
- static unix(timestamp) {
2351
- return new Timez(timestamp * 1000);
2352
- }
2353
- static utc() {
2354
- const now = new Date();
2355
- return new Timez(Date.UTC(now.getUTCFullYear(), now.getUTCMonth(), now.getUTCDate(), now.getUTCHours(), now.getUTCMinutes(), now.getUTCSeconds(), now.getUTCMilliseconds()));
2356
- }
2357
- year() {
2358
- var _a;
2359
- return (_a = this._date) === null || _a === void 0 ? void 0 : _a.getFullYear();
2360
- }
2361
- month() {
2362
- return !!this._date ? this._date.getMonth() + 1 : undefined;
2363
- }
2364
- date() {
2365
- var _a;
2366
- return (_a = this._date) === null || _a === void 0 ? void 0 : _a.getDate();
2367
- }
2368
- hour() {
2369
- var _a;
2370
- return (_a = this._date) === null || _a === void 0 ? void 0 : _a.getHours();
2371
- }
2372
- minute() {
2373
- var _a;
2374
- return (_a = this._date) === null || _a === void 0 ? void 0 : _a.getMinutes();
2375
- }
2376
- second() {
2377
- var _a;
2378
- return (_a = this._date) === null || _a === void 0 ? void 0 : _a.getSeconds();
2379
- }
2380
- millisecond() {
2381
- var _a;
2382
- return (_a = this._date) === null || _a === void 0 ? void 0 : _a.getMilliseconds();
2383
- }
2384
- day() {
2385
- var _a;
2386
- return (_a = this._date) === null || _a === void 0 ? void 0 : _a.getDay();
2387
- }
2388
- add(amount, unit) {
2389
- if (!this._date) {
2390
- return new Timez(undefined);
2391
- }
2392
- const newDate = new Date(this._date);
2393
- switch (unit) {
2394
- case 'years':
2395
- newDate.setFullYear(newDate.getFullYear() + amount);
2396
- break;
2397
- case 'months':
2398
- newDate.setMonth(newDate.getMonth() + amount);
2399
- break;
2400
- case 'days':
2401
- newDate.setDate(newDate.getDate() + amount);
2402
- break;
2403
- case 'hours':
2404
- newDate.setHours(newDate.getHours() + amount);
2405
- break;
2406
- case 'minutes':
2407
- newDate.setMinutes(newDate.getMinutes() + amount);
2408
- break;
2409
- case 'seconds':
2410
- newDate.setSeconds(newDate.getSeconds() + amount);
2411
- break;
2412
- case 'milliseconds':
2413
- newDate.setMilliseconds(newDate.getMilliseconds() + amount);
2414
- break;
2415
- }
2416
- return new Timez(newDate);
2417
- }
2418
- subtract(amount, unit) {
2419
- return this.add(-amount, unit);
2420
- }
2421
- startOf(unit) {
2422
- if (!this._date) {
2423
- return new Timez(undefined);
2424
- }
2425
- const newDate = new Date(this._date);
2426
- switch (unit) {
2427
- case 'year':
2428
- newDate.setMonth(0, 1);
2429
- newDate.setHours(0, 0, 0, 0);
2430
- break;
2431
- case 'month':
2432
- newDate.setDate(1);
2433
- newDate.setHours(0, 0, 0, 0);
2434
- break;
2435
- case 'day':
2436
- newDate.setHours(0, 0, 0, 0);
2437
- break;
2438
- case 'hour':
2439
- newDate.setMinutes(0, 0, 0);
2440
- break;
2441
- case 'minute':
2442
- newDate.setSeconds(0, 0);
2443
- break;
2444
- case 'second':
2445
- newDate.setMilliseconds(0);
2446
- break;
2447
- }
2448
- return new Timez(newDate);
2449
- }
2450
- endOf(unit) {
2451
- const start = this.startOf(unit);
2452
- switch (unit) {
2453
- case 'year':
2454
- return start.add(1, 'years').subtract(1, 'milliseconds');
2455
- case 'month':
2456
- return start.add(1, 'months').subtract(1, 'milliseconds');
2457
- case 'day':
2458
- return start.add(1, 'days').subtract(1, 'milliseconds');
2459
- case 'hour':
2460
- return start.add(1, 'hours').subtract(1, 'milliseconds');
2461
- case 'minute':
2462
- return start.add(1, 'minutes').subtract(1, 'milliseconds');
2463
- case 'second':
2464
- return start.add(1, 'seconds').subtract(1, 'milliseconds');
2465
- default:
2466
- return start;
2467
- }
2468
- }
2469
- isBefore(other, inclusivity = '()') {
2470
- const isIncluded = inclusivity[1] === ']';
2471
- const otherTimez = other instanceof Timez ? other : new Timez(other);
2472
- if (!this._date || !otherTimez._date) {
2473
- return false;
2474
- }
2475
- return ((!isIncluded &&
2476
- this._date < otherTimez._date) ||
2477
- (!!isIncluded &&
2478
- this._date <= otherTimez._date));
2479
- }
2480
- isAfter(other, inclusivity = '()') {
2481
- const isIncluded = inclusivity[0] === '[';
2482
- const otherTimez = other instanceof Timez ? other : new Timez(other);
2483
- if (!this._date || !otherTimez._date) {
2484
- return false;
2485
- }
2486
- return ((!isIncluded &&
2487
- this._date > otherTimez._date) ||
2488
- (!!isIncluded &&
2489
- this._date >= otherTimez._date));
2490
- }
2491
- isSame(other, unit) {
2492
- const otherTimez = other instanceof Timez ? other : new Timez(other);
2493
- if (!unit && this._date && otherTimez._date) {
2494
- return this._date.getTime() === otherTimez._date.getTime();
2495
- }
2496
- const thisStart = !!unit ? this.startOf(unit) : undefined;
2497
- const otherStart = !!unit ? otherTimez.startOf(unit) : undefined;
2498
- if (!thisStart || !(thisStart === null || thisStart === void 0 ? void 0 : thisStart._date) || !otherStart || !(otherStart === null || otherStart === void 0 ? void 0 : otherStart._date)) {
2499
- return false;
2500
- }
2501
- return thisStart._date.getTime() === otherStart._date.getTime();
2502
- }
2503
- isBetween(start, end, inclusivity = '()') {
2504
- const startTimez = start instanceof Timez ? start : new Timez(start);
2505
- const endTimez = end instanceof Timez ? end : new Timez(end);
2506
- const startIncluded = inclusivity[0] === '[';
2507
- const endIncluded = inclusivity[1] === ']';
2508
- const afterStart = startIncluded ?
2509
- this.isSame(startTimez) || this.isAfter(startTimez) :
2510
- this.isAfter(startTimez);
2511
- const beforeEnd = endIncluded ?
2512
- this.isSame(endTimez) || this.isBefore(endTimez) :
2513
- this.isBefore(endTimez);
2514
- return afterStart && beforeEnd;
2515
- }
2516
- format(formatString) {
2517
- if (!formatString) {
2518
- return this.toISOString();
2519
- }
2520
- const predefinedFormat = Timez.PREDEFINED_FORMATS[formatString];
2521
- if (predefinedFormat) {
2522
- return this.format(predefinedFormat);
2523
- }
2524
- let result = '';
2525
- let i = 0;
2526
- while (i < formatString.length) {
2527
- if (formatString[i] === '[') {
2528
- const endIndex = formatString.indexOf(']', i);
2529
- if (endIndex === -1) {
2530
- result += formatString[i];
2531
- i++;
2532
- continue;
2533
- }
2534
- const literal = formatString.substring(i + 1, endIndex);
2535
- result += literal;
2536
- i = endIndex + 1;
2537
- }
2538
- else if (formatString[i] === '%' && i + 1 < formatString.length) {
2539
- const token = `%${formatString[i + 1]}`;
2540
- const formatter = Timez.FORMAT_TOKENS[token];
2541
- if (formatter) {
2542
- result += formatter(this);
2543
- }
2544
- else {
2545
- result += token;
2546
- }
2547
- i += 2;
2548
- }
2549
- else {
2550
- result += formatString[i];
2551
- i++;
2552
- }
2553
- }
2554
- return result;
2555
- }
2556
- setTimezone(timezone) {
2557
- if (!this._date) {
2558
- return new Timez(undefined);
2559
- }
2560
- const currentOffset = this._date.getTimezoneOffset();
2561
- const targetOffset = this.parseTimezoneOffset(timezone);
2562
- const adjustedDate = new Date(this._date.getTime() + (targetOffset - currentOffset) * 60000);
2563
- return new Timez(adjustedDate);
2564
- }
2565
- utc() {
2566
- if (!this._date) {
2567
- return new Timez(undefined);
2568
- }
2569
- return new Timez(new Date(Date.UTC(this._date.getUTCFullYear(), this._date.getUTCMonth(), this._date.getUTCDate(), this._date.getUTCHours(), this._date.getUTCMinutes(), this._date.getUTCSeconds(), this._date.getUTCMilliseconds())));
2570
- }
2571
- local() {
2572
- if (!this._date) {
2573
- return new Timez(undefined);
2574
- }
2575
- return new Timez(new Date(this._date.getFullYear(), this._date.getMonth(), this._date.getDate(), this._date.getHours(), this._date.getMinutes(), this._date.getSeconds(), this._date.getMilliseconds()));
2576
- }
2577
- toString() {
2578
- var _a;
2579
- return (_a = this._date) === null || _a === void 0 ? void 0 : _a.toString();
2580
- }
2581
- toISOString() {
2582
- var _a;
2583
- return (_a = this._date) === null || _a === void 0 ? void 0 : _a.toISOString();
2584
- }
2585
- toDate() {
2586
- return !!this._date ? new Date(this._date) : undefined;
2587
- }
2588
- valueOf() {
2589
- var _a;
2590
- return (_a = this._date) === null || _a === void 0 ? void 0 : _a.getTime();
2591
- }
2592
- unix() {
2593
- return !!this._date ? Math.floor(this._date.getTime() / 1000) : undefined;
2594
- }
2595
- utcOffset() {
2596
- return this._date ? -this._date.getTimezoneOffset() : undefined;
2597
- }
2598
- isCorrect() {
2599
- return !!this._date && !isNaN(this._date.getTime());
2600
- }
2601
- timezone() {
2602
- if (!this._date)
2603
- return undefined;
2604
- try {
2605
- const formatter = new Intl.DateTimeFormat();
2606
- const timezone = formatter.resolvedOptions().timeZone;
2607
- return timezone || undefined;
2608
- }
2609
- catch (error) {
2610
- return this.timezoneFromOffset();
2611
- }
2612
- }
2613
- timezoneAbbr() {
2614
- if (!this._date)
2615
- return undefined;
2616
- try {
2617
- const formatter = new Intl.DateTimeFormat('en', {
2618
- timeZoneName: 'short'
2619
- });
2620
- const parts = formatter.formatToParts(this._date);
2621
- const timezonePart = parts.find(part => part.type === 'timeZoneName');
2622
- return (timezonePart === null || timezonePart === void 0 ? void 0 : timezonePart.value) || undefined;
2623
- }
2624
- catch (error) {
2625
- return this.timezoneAbbrFromOffset();
2626
- }
2627
- }
2628
- timezoneName() {
2629
- if (!this._date)
2630
- return undefined;
2631
- try {
2632
- const formatter = new Intl.DateTimeFormat('en', {
2633
- timeZoneName: 'long'
2634
- });
2635
- const parts = formatter.formatToParts(this._date);
2636
- const timezonePart = parts.find(part => part.type === 'timeZoneName');
2637
- return (timezonePart === null || timezonePart === void 0 ? void 0 : timezonePart.value) || undefined;
2638
- }
2639
- catch (error) {
2640
- return this.timezoneNameFromOffset();
2641
- }
2642
- }
2643
- timezoneOffsetString() {
2644
- const offset = this.utcOffset();
2645
- if (offset === undefined)
2646
- return undefined;
2647
- const sign = offset >= 0 ? '+' : '-';
2648
- const hours = Math.floor(Math.abs(offset) / 60).toString().padStart(2, '0');
2649
- const minutes = (Math.abs(offset) % 60).toString().padStart(2, '0');
2650
- return `${sign}${hours}:${minutes}`;
2651
- }
2652
- dateChecker(input) {
2653
- return ((input instanceof Timez &&
2654
- !!input &&
2655
- !!(input === null || input === void 0 ? void 0 : input._date)) ||
2656
- input instanceof Date ||
2657
- typeof input === 'string' ||
2658
- typeof input === 'number' || (input === undefined ||
2659
- input === null ||
2660
- (typeof input === 'number' && isNaN(input))));
2661
- }
2662
- timezoneFromOffset() {
2663
- const offset = this.utcOffset();
2664
- if (offset === undefined)
2665
- return undefined;
2666
- const offsetToTimezone = {
2667
- 0: 'Etc/UTC',
2668
- 60: 'Europe/Paris',
2669
- 120: 'Europe/Athens',
2670
- 180: 'Europe/Moscow',
2671
- 240: 'Asia/Dubai',
2672
- 270: 'Asia/Tehran',
2673
- 300: 'Asia/Karachi',
2674
- 330: 'Asia/Kolkata',
2675
- 345: 'Asia/Rangoon',
2676
- 360: 'Asia/Dhaka',
2677
- 390: 'Asia/Yangon',
2678
- 420: 'Asia/Bangkok',
2679
- 480: 'Asia/Shanghai',
2680
- 525: 'Asia/Kathmandu',
2681
- 540: 'Asia/Tokyo',
2682
- 570: 'Australia/Adelaide',
2683
- 600: 'Australia/Sydney',
2684
- 630: 'Australia/Lord_Howe',
2685
- 660: 'Pacific/Noumea',
2686
- 675: 'Australia/Eucla',
2687
- 720: 'Pacific/Auckland',
2688
- 780: 'Pacific/Chatham',
2689
- [-60]: 'Atlantic/Azores',
2690
- [-120]: 'America/Noronha',
2691
- [-180]: 'America/Argentina/Buenos_Aires',
2692
- [-210]: 'America/St_Johns',
2693
- [-240]: 'America/Halifax',
2694
- [-270]: 'America/Caracas',
2695
- [-300]: 'America/New_York',
2696
- [-360]: 'America/Chicago',
2697
- [-420]: 'America/Denver',
2698
- [-480]: 'America/Los_Angeles',
2699
- [-540]: 'America/Anchorage',
2700
- [-600]: 'Pacific/Honolulu',
2701
- [-660]: 'Pacific/Pago_Pago',
2702
- [-720]: 'Pacific/Kiritimati',
2703
- };
2704
- return offsetToTimezone[offset] || `Etc/GMT${offset >= 0 ? '-' : '+'}${Math.abs(offset) / 60}`;
2705
- }
2706
- timezoneAbbrFromOffset() {
2707
- const offset = this.utcOffset();
2708
- if (offset === undefined)
2709
- return undefined;
2710
- const offsetToAbbr = {
2711
- 0: 'GMT',
2712
- 60: 'CET',
2713
- [-300]: 'EST',
2714
- [-360]: 'CST',
2715
- [-420]: 'MST',
2716
- [-480]: 'PST',
2717
- };
2718
- return offsetToAbbr[offset] || `GMT${offset >= 0 ? '+' : ''}${offset / 60}`;
2719
- }
2720
- timezoneNameFromOffset() {
2721
- const offset = this.utcOffset();
2722
- if (offset === undefined)
2723
- return undefined;
2724
- const offsetToName = {
2725
- 0: 'Greenwich Mean Time',
2726
- 60: 'Central European Time',
2727
- [-300]: 'Eastern Standard Time',
2728
- [-360]: 'Central Standard Time',
2729
- [-420]: 'Mountain Standard Time',
2730
- [-480]: 'Pacific Standard Time',
2731
- };
2732
- return offsetToName[offset] || `GMT${offset >= 0 ? '+' : ''}${offset / 60}`;
2733
- }
2734
- isDST() {
2735
- if (!this._date)
2736
- return undefined;
2737
- try {
2738
- const jan = new Date(this._date.getFullYear(), 0, 1);
2739
- const jul = new Date(this._date.getFullYear(), 6, 1);
2740
- const stdOffset = Math.max(jan.getTimezoneOffset(), jul.getTimezoneOffset());
2741
- return this._date.getTimezoneOffset() < stdOffset;
2742
- }
2743
- catch (error) {
2744
- return undefined;
2745
- }
2746
- }
2747
- static parseString(dateString, enableException = false) {
2748
- const isoDate = new Date(dateString);
2749
- if (!isNaN(isoDate.getTime())) {
2750
- return isoDate;
2751
- }
2752
- const formats = [
2753
- /^(\d{4})-(\d{2})-(\d{2})T(\d{2}):(\d{2}):(\d{2})\.(\d{3})Z$/,
2754
- /^(\d{4})-(\d{2})-(\d{2})$/,
2755
- /^(\d{4})\/(\d{2})\/(\d{2}) (\d{2}):(\d{2}):(\d{2})$/,
2756
- /^(\d{4})(\d{2})(\d{2})(\d{2})(\d{2})(\d{2})$/
2757
- ];
2758
- for (const regex of formats) {
2759
- const match = dateString.match(regex);
2760
- if (match) {
2761
- const components = match.slice(1).map(Number);
2762
- if (regex === formats[0]) {
2763
- return new Date(Date.UTC(components[0], components[1] - 1, components[2], components[3], components[4], components[5], components[6]));
2764
- }
2765
- else if (regex === formats[1]) {
2766
- return new Date(components[0], components[1] - 1, components[2]);
2767
- }
2768
- else if (regex === formats[2]) {
2769
- return new Date(components[0], components[1] - 1, components[2], components[3], components[4], components[5]);
2770
- }
2771
- else if (regex === formats[3]) {
2772
- return new Date(components[0], components[1] - 1, components[2], components[3], components[4], components[5]);
2773
- }
2774
- }
2775
- }
2776
- const fallback = new Date(dateString);
2777
- if (!isNaN(fallback.getTime())) {
2778
- return fallback;
2779
- }
2780
- if (!!enableException) {
2781
- throw new Error(`Unable to parse date string: ${dateString}`);
2782
- }
2783
- }
2784
- static parseWithFormat(value, format) {
2785
- if (!value || !format)
2786
- return undefined;
2787
- const valueStr = String(value).trim();
2788
- if (!valueStr)
2789
- return undefined;
2790
- const tokenHandlers = {
2791
- 'Y': {
2792
- regex: /\d{4}/,
2793
- extract: (match) => parseInt(match, 10)
2794
- },
2795
- 'y': {
2796
- regex: /\d{2}/,
2797
- extract: (match) => {
2798
- const year = parseInt(match, 10);
2799
- return year >= 70 ? 1900 + year : 2000 + year;
2800
- }
2801
- },
2802
- 'm': {
2803
- regex: /\d{1,2}/,
2804
- extract: (match) => parseInt(match, 10)
2805
- },
2806
- 'd': {
2807
- regex: /\d{1,2}/,
2808
- extract: (match) => parseInt(match, 10)
2809
- },
2810
- 'H': {
2811
- regex: /\d{1,2}/,
2812
- extract: (match) => parseInt(match, 10)
2813
- },
2814
- 'M': {
2815
- regex: /\d{1,2}/,
2816
- extract: (match) => parseInt(match, 10)
2817
- },
2818
- 'S': {
2819
- regex: /\d{1,2}/,
2820
- extract: (match) => parseInt(match, 10)
2821
- },
2822
- 'f': {
2823
- regex: /\d{1,3}/,
2824
- extract: (match) => parseInt(match, 10)
2825
- }
2826
- };
2827
- const result = {
2828
- year: new Date().getFullYear(),
2829
- month: 1,
2830
- day: 1,
2831
- hour: 0,
2832
- minute: 0,
2833
- second: 0,
2834
- millisecond: 0
2835
- };
2836
- let valueIndex = 0;
2837
- let formatIndex = 0;
2838
- let inLiteral = false;
2839
- let currentLiteral = '';
2840
- while (formatIndex < format.length && valueIndex < valueStr.length) {
2841
- const formatChar = format[formatIndex];
2842
- if (formatChar === '[') {
2843
- inLiteral = true;
2844
- currentLiteral = '';
2845
- formatIndex++;
2846
- }
2847
- else if (formatChar === ']' && inLiteral) {
2848
- if (valueStr.substring(valueIndex, valueIndex + currentLiteral.length) === currentLiteral) {
2849
- valueIndex += currentLiteral.length;
2850
- }
2851
- else {
2852
- return undefined;
2853
- }
2854
- inLiteral = false;
2855
- currentLiteral = '';
2856
- formatIndex++;
2857
- }
2858
- else if (inLiteral) {
2859
- currentLiteral += formatChar;
2860
- formatIndex++;
2861
- }
2862
- else if (formatChar === '%' && formatIndex + 1 < format.length) {
2863
- const token = format[formatIndex + 1];
2864
- const handler = tokenHandlers[token];
2865
- if (handler) {
2866
- const remainingValue = valueStr.substring(valueIndex);
2867
- const match = remainingValue.match(handler.regex);
2868
- if (match && match.index === 0) {
2869
- const matchedValue = match[0];
2870
- const numericValue = handler.extract(matchedValue);
2871
- switch (token) {
2872
- case 'Y':
2873
- case 'y':
2874
- result.year = numericValue;
2875
- break;
2876
- case 'm':
2877
- result.month = numericValue;
2878
- break;
2879
- case 'd':
2880
- result.day = numericValue;
2881
- break;
2882
- case 'H':
2883
- result.hour = numericValue;
2884
- break;
2885
- case 'M':
2886
- result.minute = numericValue;
2887
- break;
2888
- case 'S':
2889
- result.second = numericValue;
2890
- break;
2891
- case 'f':
2892
- result.millisecond = numericValue;
2893
- break;
2894
- }
2895
- valueIndex += matchedValue.length;
2896
- }
2897
- else {
2898
- return undefined;
2899
- }
2900
- }
2901
- else {
2902
- valueIndex++;
2903
- }
2904
- formatIndex += 2;
2905
- }
2906
- else {
2907
- if (formatChar === valueStr[valueIndex]) {
2908
- valueIndex++;
2909
- formatIndex++;
2910
- }
2911
- else {
2912
- return undefined;
2913
- }
2914
- }
2915
- }
2916
- if (result.month < 1 || result.month > 12)
2917
- return undefined;
2918
- if (result.day < 1 || result.day > 31)
2919
- return undefined;
2920
- if (result.hour < 0 || result.hour > 23)
2921
- return undefined;
2922
- if (result.minute < 0 || result.minute > 59)
2923
- return undefined;
2924
- if (result.second < 0 || result.second > 59)
2925
- return undefined;
2926
- if (result.millisecond < 0 || result.millisecond > 999)
2927
- return undefined;
2928
- try {
2929
- const date = new Date(result.year, result.month - 1,
2930
- result.day, result.hour, result.minute, result.second, result.millisecond);
2931
- if (isNaN(date.getTime())) {
2932
- return undefined;
2933
- }
2934
- return new Timez(date);
2935
- }
2936
- catch (error) {
2937
- return undefined;
2938
- }
2939
- }
2940
- static getTokenLength(token) {
2941
- const tokenLengths = {
2942
- 'Y': 4,
2943
- 'y': 2,
2944
- 'm': 2,
2945
- 'd': 2,
2946
- 'H': 2,
2947
- 'M': 2,
2948
- 'S': 2,
2949
- 'f': 3,
2950
- 'z': 5
2951
- };
2952
- return tokenLengths[token] || 1;
2953
- }
2954
- parseTimezoneOffset(timezone) {
2955
- const offsets = {
2956
- 'UTC': 0,
2957
- 'EST': -300,
2958
- 'EDT': -240,
2959
- 'CST': -360,
2960
- 'CDT': -300,
2961
- 'PST': -480,
2962
- 'PDT': -420,
2963
- };
2964
- if (offsets[timezone.toUpperCase()] !== undefined) {
2965
- return offsets[timezone.toUpperCase()];
2966
- }
2967
- const match = timezone.match(/^([+-])(\d{1,2}):?(\d{2})?$/);
2968
- if (match) {
2969
- const sign = match[1] === '+' ? 1 : -1;
2970
- const hours = parseInt(match[2], 10);
2971
- const minutes = match[3] ? parseInt(match[3], 10) : 0;
2972
- return sign * (hours * 60 + minutes);
2973
- }
2974
- return this._date ? -this._date.getTimezoneOffset() : 0;
2975
- }
2976
- static get FORMATS() {
2977
- return Object.assign({}, Timez.PREDEFINED_FORMATS);
2978
- }
2979
- static exposeToGlobal() {
2980
- if (typeof window !== 'undefined') {
2981
- window.Timez = Timez;
2982
- }
2983
- }
2984
- }
2985
- Timez.FORMAT_TOKENS = {
2986
- '%Y': (t) => { var _a; return (_a = t.year()) === null || _a === void 0 ? void 0 : _a.toString().padStart(4, '0'); },
2987
- '%y': (t) => { var _a; return (_a = t.year()) === null || _a === void 0 ? void 0 : _a.toString().slice(-2).padStart(2, '0'); },
2988
- '%m': (t) => { var _a; return (_a = t.month()) === null || _a === void 0 ? void 0 : _a.toString().padStart(2, '0'); },
2989
- '%d': (t) => { var _a; return (_a = t.date()) === null || _a === void 0 ? void 0 : _a.toString().padStart(2, '0'); },
2990
- '%H': (t) => { var _a; return (_a = t.hour()) === null || _a === void 0 ? void 0 : _a.toString().padStart(2, '0'); },
2991
- '%M': (t) => { var _a; return (_a = t.minute()) === null || _a === void 0 ? void 0 : _a.toString().padStart(2, '0'); },
2992
- '%S': (t) => { var _a; return (_a = t.second()) === null || _a === void 0 ? void 0 : _a.toString().padStart(2, '0'); },
2993
- '%f': (t) => { var _a; return (_a = t.millisecond()) === null || _a === void 0 ? void 0 : _a.toString().padStart(3, '0'); },
2994
- '%z': (t) => {
2995
- const offset = t.utcOffset();
2996
- if (!offset) {
2997
- return undefined;
2998
- }
2999
- const sign = offset >= 0 ? '+' : '-';
3000
- const hours = Math.floor(Math.abs(offset) / 60).toString().padStart(2, '0');
3001
- const minutes = (Math.abs(offset) % 60).toString().padStart(2, '0');
3002
- return `${sign}${hours}${minutes}`;
3003
- },
3004
- '%s': (t) => {
3005
- const val = t.valueOf();
3006
- return !!val ? Math.floor(val / 1000).toString() : undefined;
3007
- },
3008
- };
3009
- Timez.PREDEFINED_FORMATS = {
3010
- ISO: '%Y-%m-%dT%H:%M:%S.%fZ',
3011
- ISO_DATE: '%Y-%m-%d',
3012
- ISO_TIME: '%H:%M:%S.%fZ',
3013
- COMPACT: '%Y%m%d%H%M%S',
3014
- SLASH_DATETIME: '%Y/%m/%d %H:%M:%S.%fZ',
3015
- SLASH_DATETIME_SEC: '%Y/%m/%d %H:%M:%S',
3016
- SLASH_DATETIME_MIN: '%Y/%m/%d %H:%M',
3017
- EUROPEAN: '%d/%m/%Y %H:%M:%S GMT%z',
3018
- SLASH_DATE: '%Y/%m/%d',
3019
- TIME_MICRO: '%H:%M:%S.%fZ',
3020
- TIME_SEC: '%H:%M:%S',
3021
- CUSTOM_GREETING: '[Bonjour celestin, ][la date actuelle est:: le] %d/%m/%Y [à] %H:%M:%S.%f[Z]',
3022
- };
3023
- if (typeof window !== 'undefined') {
3024
- window.Timez = Timez;
3025
- }
3026
-
3027
- timez.Timez = Timez;
3028
- timez.default = Timez;
3029
- return timez;
3030
- }
3031
-
3032
- var hasRequiredCooks;
3033
-
3034
- function requireCooks () {
3035
- if (hasRequiredCooks) return cooks;
3036
- hasRequiredCooks = 1;
3037
-
3038
- Object.defineProperty(cooks, '__esModule', { value: true });
3039
-
3040
- var timez = requireTimez();
3041
-
3042
- const tabAlphabetique = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z'];
3043
- [...tabAlphabetique, ...tabAlphabetique.map(x => x.toUpperCase())];
3044
-
3045
- class Cooks {
3046
- static set(key, value, options = {}) {
3047
- if (!this.isBrowser())
3048
- return;
3049
- try {
3050
- const serializedValue = this.serialize(value);
3051
- const encodedValue = encodeURIComponent(serializedValue);
3052
- const cookieString = this.buildCookieString(key, encodedValue, options);
3053
- document.cookie = cookieString;
3054
- }
3055
- catch (error) {
3056
- console.error(`Cooks: Error setting cookie "${key}":`, error);
3057
- }
3058
- }
3059
- static get(key) {
3060
- if (!this.isBrowser())
3061
- return null;
3062
- try {
3063
- const cookies = this.getAllCookies();
3064
- const encodedValue = cookies[key];
3065
- if (!encodedValue)
3066
- return null;
3067
- const decodedValue = decodeURIComponent(encodedValue);
3068
- return this.deserialize(decodedValue);
3069
- }
3070
- catch (error) {
3071
- console.error(`Cooks: Error getting cookie "${key}":`, error);
3072
- return null;
3073
- }
3074
- }
3075
- static remove(key, path = '/', domain) {
3076
- if (!this.isBrowser())
3077
- return;
3078
- const options = {
3079
- expires: new Date(0),
3080
- path,
3081
- domain
3082
- };
3083
- this.set(key, '', options);
3084
- }
3085
- static has(key) {
3086
- return this.get(key) !== null;
3087
- }
3088
- static keys() {
3089
- if (!this.isBrowser())
3090
- return [];
3091
- const cookies = this.getAllCookies();
3092
- return Object.keys(cookies);
3093
- }
3094
- static clear() {
3095
- if (!this.isBrowser())
3096
- return;
3097
- const cookies = this.getAllCookies();
3098
- Object.keys(cookies).forEach(key => {
3099
- this.remove(key);
3100
- });
3101
- }
3102
- static serialize(value) {
3103
- if (value instanceof Date) {
3104
- return JSON.stringify({
3105
- __type: 'Date',
3106
- __value: value.toISOString()
3107
- });
3108
- }
3109
- return JSON.stringify(value);
3110
- }
3111
- static deserialize(value) {
3112
- const parsed = JSON.parse(value);
3113
- if (parsed && typeof parsed === 'object' && parsed.__type === 'Date') {
3114
- return new Date(parsed.__value);
3115
- }
3116
- return parsed;
3117
- }
3118
- static buildCookieString(key, value, options) {
3119
- const mergedOptions = Object.assign(Object.assign({}, this.DEFAULT_OPTIONS), options);
3120
- let cookieString = `${key}=${value}`;
3121
- if (mergedOptions.expires !== undefined) {
3122
- let expirationDate;
3123
- if (typeof mergedOptions.expires === 'number') {
3124
- const expirationDateInitial = new timez.Timez().add(mergedOptions.expires, 'seconds').toDate();
3125
- if (!!expirationDateInitial) {
3126
- expirationDate = expirationDateInitial;
3127
- }
3128
- else {
3129
- expirationDate = new Date();
3130
- }
3131
- }
3132
- else {
3133
- expirationDate = mergedOptions.expires;
3134
- }
3135
- cookieString += `; expires=${expirationDate.toUTCString()}`;
3136
- }
3137
- if (mergedOptions.path)
3138
- cookieString += `; path=${mergedOptions.path}`;
3139
- if (mergedOptions.domain)
3140
- cookieString += `; domain=${mergedOptions.domain}`;
3141
- if (mergedOptions.secure)
3142
- cookieString += `; secure`;
3143
- if (mergedOptions.sameSite)
3144
- cookieString += `; samesite=${mergedOptions.sameSite}`;
3145
- {
3146
- console.log(`Cooks - buildCookieString | cookieString:: `, cookieString);
3147
- }
3148
- return cookieString;
3149
- }
3150
- static getAllCookies() {
3151
- return document.cookie
3152
- .split(';')
3153
- .reduce((cookies, cookie) => {
3154
- const [key, value] = cookie.split('=').map(part => part.trim());
3155
- if (key) {
3156
- cookies[key] = value || '';
3157
- }
3158
- return cookies;
3159
- }, {});
3160
- }
3161
- static isBrowser() {
3162
- return typeof window !== 'undefined' && typeof document !== 'undefined';
3163
- }
3164
- static exposeToGlobal() {
3165
- if (typeof window !== "undefined") {
3166
- window.Cooks = Cooks;
3167
- }
3168
- }
3169
- }
3170
- Cooks.DEFAULT_OPTIONS = {
3171
- path: '/',
3172
- secure: true,
3173
- sameSite: 'lax'
3174
- };
3175
- if (typeof window !== "undefined") {
3176
- window.Cooks = Cooks;
3177
- }
3178
-
3179
- cooks.Cooks = Cooks;
3180
- cooks.default = Cooks;
3181
- return cooks;
3182
- }
3183
-
3184
- requireCooks();
3185
-
3186
- var _a;
3187
- const SRC_DIR = ((_a = process === null || process === void 0 ? void 0 : process.env) === null || _a === void 0 ? void 0 : _a.VITE_APP_SRC_DIR) || '/src';
2288
+ let configManagerConfig = null;
2289
+ const setConfigManagerConfig = (config) => {
2290
+ configManagerConfig = config;
2291
+ };
3188
2292
 
3189
- const globalConfigGlob = import.meta.glob('@/config.json', { eager: false });
3190
- const moduleConfigsGlob = import.meta.glob('@/modules/*/config.json', { eager: false });
3191
- const loadGlobalConfig = () => __awaiter(void 0, void 0, void 0, function* () {
2293
+ const loadBaseConfig = () => __awaiter(void 0, void 0, void 0, function* () {
3192
2294
  try {
3193
- const path = `${SRC_DIR}/config.json`;
3194
- if (globalConfigGlob[path]) {
3195
- const module = yield globalConfigGlob[path]();
3196
- return module.default || module;
3197
- }
3198
- else {
3199
- const module = yield import(
3200
- path);
3201
- return module.default;
2295
+ if (!(configManagerConfig === null || configManagerConfig === void 0 ? void 0 : configManagerConfig.base)) {
2296
+ console.warn('No base config found');
2297
+ return {};
3202
2298
  }
2299
+ const baseConfigs = yield Promise.all(Object.entries(configManagerConfig.base).map((_a) => __awaiter(void 0, [_a], void 0, function* ([key, loader]) {
2300
+ try {
2301
+ const config = yield loader();
2302
+ return { key, config };
2303
+ }
2304
+ catch (error) {
2305
+ console.error(`Failed to load base config ${key}:`, error);
2306
+ return { key, config: {} };
2307
+ }
2308
+ })));
2309
+ return baseConfigs.reduce((acc, { key, config }) => {
2310
+ return Object.assign(Object.assign({}, acc), config);
2311
+ }, {});
3203
2312
  }
3204
2313
  catch (error) {
3205
- console.warn('Global config not found, using empty config');
2314
+ console.error('Failed to load base config:', error);
3206
2315
  return {};
3207
2316
  }
3208
2317
  });
3209
- const loadModuleConfig = (moduleName) => __awaiter(void 0, void 0, void 0, function* () {
3210
- try {
3211
- const path = `${SRC_DIR}/modules/${moduleName}/config.json`;
3212
- if (moduleConfigsGlob[path]) {
3213
- const module = yield moduleConfigsGlob[path]();
3214
- return module.default || module;
2318
+ const loadModulesConfigs = () => __awaiter(void 0, void 0, void 0, function* () {
2319
+ const results = [];
2320
+ if (!(configManagerConfig === null || configManagerConfig === void 0 ? void 0 : configManagerConfig.modules)) {
2321
+ return results;
2322
+ }
2323
+ for (const [moduleName, loader] of Object.entries(configManagerConfig.modules)) {
2324
+ try {
2325
+ const config = yield loader();
2326
+ results.push({
2327
+ moduleName,
2328
+ config
2329
+ });
3215
2330
  }
3216
- else {
3217
- const module = yield import(
3218
- path);
3219
- return module.default;
2331
+ catch (error) {
2332
+ console.error(`Failed to load config for module "${moduleName}"`, error);
3220
2333
  }
3221
2334
  }
3222
- catch (error) {
3223
- console.warn(`Module config "${moduleName}" not found, using empty config`);
3224
- return {};
3225
- }
2335
+ return results;
3226
2336
  });
3227
- const loadEnvConfig = () => {
3228
- const envConfig = {};
3229
- if (import.meta.env) {
3230
- Object.keys(import.meta.env).forEach(key => {
3231
- if (key.startsWith('VITE_')) {
3232
- const configKey = key
3233
- .replace(/^VITE_/, '')
3234
- .toLowerCase()
3235
- .split('_')
3236
- .map((part, index) => index === 0 ? part : part.charAt(0).toUpperCase() + part.slice(1))
3237
- .join('');
3238
- envConfig[configKey] = import.meta.env[key];
3239
- }
3240
- });
2337
+ const loadModuleConfig = (moduleName) => __awaiter(void 0, void 0, void 0, function* () {
2338
+ var _a;
2339
+ if (!((_a = configManagerConfig === null || configManagerConfig === void 0 ? void 0 : configManagerConfig.modules) === null || _a === void 0 ? void 0 : _a[moduleName])) {
2340
+ return undefined;
3241
2341
  }
3242
- if (typeof process !== 'undefined' && process.env) {
3243
- Object.keys(process.env).forEach(key => {
3244
- if (key.startsWith('VITE_') || key === 'NODE_ENV') {
3245
- const configKey = key
3246
- .replace(/^VITE_/, '')
3247
- .toLowerCase()
3248
- .split('_')
3249
- .map((part, index) => index === 0 ? part : part.charAt(0).toUpperCase() + part.slice(1))
3250
- .join('');
3251
- envConfig[configKey] = process.env[key];
3252
- }
3253
- });
2342
+ try {
2343
+ const loader = configManagerConfig.modules[moduleName];
2344
+ const config = yield loader();
2345
+ return {
2346
+ moduleName,
2347
+ config
2348
+ };
3254
2349
  }
3255
- return envConfig;
3256
- };
2350
+ catch (error) {
2351
+ console.error(`Failed to load config for module "${moduleName}"`, error);
2352
+ return undefined;
2353
+ }
2354
+ });
3257
2355
 
3258
- class ConfigurationService {
2356
+ class ConfigService {
3259
2357
  constructor() {
3260
- Object.defineProperty(this, "configs", {
3261
- enumerable: true,
3262
- configurable: true,
3263
- writable: true,
3264
- value: new Map()
3265
- });
3266
- Object.defineProperty(this, "envConfig", {
2358
+ Object.defineProperty(this, "resources", {
3267
2359
  enumerable: true,
3268
2360
  configurable: true,
3269
2361
  writable: true,
3270
2362
  value: {}
3271
2363
  });
3272
- Object.defineProperty(this, "globalConfig", {
2364
+ Object.defineProperty(this, "loadedModules", {
3273
2365
  enumerable: true,
3274
2366
  configurable: true,
3275
2367
  writable: true,
3276
- value: {}
3277
- });
3278
- Object.defineProperty(this, "initialized", {
3279
- enumerable: true,
3280
- configurable: true,
3281
- writable: true,
3282
- value: false
2368
+ value: new Set()
3283
2369
  });
3284
2370
  }
3285
2371
  initialize() {
3286
2372
  return __awaiter(this, void 0, void 0, function* () {
3287
- if (this.initialized)
3288
- return;
3289
- this.globalConfig = yield loadGlobalConfig();
3290
- this.envConfig = yield loadEnvConfig();
3291
- this.configs.set('global', this.globalConfig);
3292
- this.configs.set('ENV', this.envConfig);
3293
- this.initialized = true;
2373
+ yield this.loadAllConfigs();
3294
2374
  });
3295
2375
  }
3296
- loadModuleConfig(moduleName) {
2376
+ loadAllConfigs() {
3297
2377
  return __awaiter(this, void 0, void 0, function* () {
3298
- if (this.configs.has(moduleName))
3299
- return;
3300
- const moduleConfig = yield loadModuleConfig(moduleName);
3301
- const mergedConfig = mergeDeep(Object.assign({}, this.globalConfig), moduleConfig);
3302
- this.configs.set(moduleName, mergedConfig);
2378
+ const base = yield loadBaseConfig();
2379
+ const modules = yield loadModulesConfigs();
2380
+ this.resources = modules.reduce((acc, { moduleName, config }) => {
2381
+ return mergeDeep(acc, { [moduleName]: config });
2382
+ }, { base });
2383
+ modules.forEach(({ moduleName }) => {
2384
+ this.loadedModules.add(moduleName);
2385
+ });
3303
2386
  });
3304
2387
  }
3305
- get(path, options = {}) {
3306
- const { moduleName = 'global', defaultValue, required = false } = options;
3307
- const config = this.configs.get(moduleName) || this.globalConfig;
3308
- if (!this.configs.has(moduleName) && moduleName !== 'ENV') {
3309
- console.warn(`Module ${moduleName} config not loaded. Loading synchronously...`);
3310
- this.loadModuleConfig(moduleName).catch(console.error);
3311
- }
3312
- const value = this.resolvePath(config, path);
3313
- if (value === undefined && required) {
3314
- throw new Error(`Configuration path "${path}" is required but not found in module "${moduleName}"`);
3315
- }
3316
- return value !== undefined ? value : defaultValue;
3317
- }
3318
- getOrThrow(path, moduleName) {
3319
- const value = this.get(path, { moduleName, required: true });
3320
- if (value === undefined) {
3321
- throw new Error(`Configuration path "${path}" not found in module "${moduleName || 'global'}"`);
3322
- }
3323
- return value;
3324
- }
3325
- getAll(moduleName) {
3326
- if (moduleName) {
3327
- return this.configs.get(moduleName) || {};
3328
- }
3329
- const allConfigs = Object.assign({}, this.globalConfig);
3330
- for (const [name, config] of this.configs.entries()) {
3331
- if (name !== 'global' && name !== 'ENV') {
3332
- allConfigs[name] = config;
2388
+ loadModule(moduleName) {
2389
+ return __awaiter(this, void 0, void 0, function* () {
2390
+ if (this.loadedModules.has(moduleName))
2391
+ return;
2392
+ const moduleData = yield loadModuleConfig(moduleName);
2393
+ if (moduleData === null || moduleData === void 0 ? void 0 : moduleData.config) {
2394
+ this.resources[moduleName] = mergeDeep(this.resources[moduleName] || {}, moduleData.config);
2395
+ this.loadedModules.add(moduleName);
3333
2396
  }
3334
- }
3335
- return allConfigs;
3336
- }
3337
- has(path, moduleName) {
3338
- const config = moduleName ? this.configs.get(moduleName) : this.globalConfig;
3339
- if (!config)
3340
- return false;
3341
- return this.resolvePath(config, path) !== undefined;
3342
- }
3343
- set(path, value, moduleName) {
3344
- const targetConfig = moduleName
3345
- ? (this.configs.get(moduleName) || {})
3346
- : this.globalConfig;
3347
- this.setPath(targetConfig, path, value);
3348
- if (moduleName) {
3349
- this.configs.set(moduleName, targetConfig);
3350
- }
3351
- else {
3352
- this.globalConfig = targetConfig;
3353
- this.configs.set('global', targetConfig);
3354
- }
3355
- }
3356
- merge(config, moduleName) {
3357
- const targetConfig = moduleName
3358
- ? (this.configs.get(moduleName) || {})
3359
- : this.globalConfig;
3360
- const merged = mergeDeep(targetConfig, config);
3361
- if (moduleName) {
3362
- this.configs.set(moduleName, merged);
3363
- }
3364
- else {
3365
- this.globalConfig = merged;
3366
- this.configs.set('global', merged);
3367
- }
2397
+ });
3368
2398
  }
3369
- resolvePath(obj, path) {
3370
- if (typeof path === 'string') {
3371
- return path.split('.').reduce((acc, key) => {
3372
- return acc && acc[key] !== undefined ? acc[key] : undefined;
3373
- }, obj);
2399
+ get(key, options = {}) {
2400
+ const { moduleName = 'base', defaultValue = undefined, pathSeparator = '.' } = options;
2401
+ const resource = this.resources[moduleName];
2402
+ if (!resource) {
2403
+ return defaultValue;
3374
2404
  }
3375
- return path.reduce((acc, key) => {
3376
- return acc && acc[key] !== undefined ? acc[key] : undefined;
3377
- }, obj);
2405
+ const result = key.split(pathSeparator).reduce((acc, part) => {
2406
+ return acc && acc[part] !== undefined ? acc[part] : undefined;
2407
+ }, resource);
2408
+ return result !== undefined ? result : defaultValue;
3378
2409
  }
3379
- setPath(obj, path, value) {
3380
- const keys = typeof path === 'string' ? path.split('.') : path;
3381
- let current = obj;
3382
- for (let i = 0; i < keys.length - 1; i++) {
3383
- const key = keys[i];
3384
- if (!current[key] || typeof current[key] !== 'object') {
3385
- current[key] = {};
3386
- }
3387
- current = current[key];
3388
- }
3389
- current[keys[keys.length - 1]] = value;
2410
+ getConfig(moduleName = 'base') {
2411
+ return this.resources[moduleName] || {};
3390
2412
  }
3391
- getEnv(key, defaultValue) {
3392
- return this.envConfig[key] || defaultValue;
3393
- }
3394
- isProduction() {
3395
- return this.getEnv('NODE_ENV') === 'production';
3396
- }
3397
- isDevelopment() {
3398
- return this.getEnv('NODE_ENV') === 'development';
3399
- }
3400
- isTest() {
3401
- return this.getEnv('NODE_ENV') === 'test';
2413
+ reload() {
2414
+ return this.loadAllConfigs();
3402
2415
  }
3403
2416
  }
3404
2417
 
3405
- const ConfigContext = reactExports.createContext(null);
3406
- const useConfigValue = () => {
3407
- const [service] = reactExports.useState(() => new ConfigurationService());
2418
+ const ConfigManagerContext = reactExports.createContext(null);
2419
+ const useConfigManagerValue = (configManagerConfig) => {
2420
+ const [service] = reactExports.useState(() => new ConfigService());
3408
2421
  const [isLoading, setIsLoading] = reactExports.useState(true);
2422
+ reactExports.useEffect(() => {
2423
+ setConfigManagerConfig(configManagerConfig);
2424
+ }, [configManagerConfig]);
3409
2425
  reactExports.useEffect(() => {
3410
2426
  const initialize = () => __awaiter(void 0, void 0, void 0, function* () {
3411
- yield service.initialize();
3412
- setIsLoading(false);
2427
+ setIsLoading(true);
2428
+ try {
2429
+ yield service.initialize();
2430
+ }
2431
+ catch (error) {
2432
+ console.error('Failed to initialize config manager:', error);
2433
+ }
2434
+ finally {
2435
+ setIsLoading(false);
2436
+ }
3413
2437
  });
3414
2438
  initialize();
3415
- }, []);
3416
- const loadModuleConfig = (moduleName) => __awaiter(void 0, void 0, void 0, function* () {
2439
+ }, [service]);
2440
+ const reloadConfig = reactExports.useCallback(() => __awaiter(void 0, void 0, void 0, function* () {
3417
2441
  setIsLoading(true);
3418
- yield service.loadModuleConfig(moduleName);
3419
- setIsLoading(false);
3420
- });
3421
- const value = reactExports.useMemo(() => ({
3422
- get: service.get.bind(service),
3423
- getOrThrow: service.getOrThrow.bind(service),
3424
- getAll: service.getAll.bind(service),
3425
- has: service.has.bind(service),
3426
- set: service.set.bind(service),
3427
- merge: service.merge.bind(service),
3428
- getEnv: service.getEnv.bind(service),
3429
- isProduction: service.isProduction.bind(service),
3430
- isDevelopment: service.isDevelopment.bind(service),
3431
- isTest: service.isTest.bind(service),
3432
- loadModuleConfig,
2442
+ try {
2443
+ yield service.reload();
2444
+ }
2445
+ catch (error) {
2446
+ console.error('Failed to reload config:', error);
2447
+ }
2448
+ finally {
2449
+ setIsLoading(false);
2450
+ }
2451
+ }), [service]);
2452
+ const loadModuleConfig = reactExports.useCallback((moduleName) => __awaiter(void 0, void 0, void 0, function* () {
2453
+ setIsLoading(true);
2454
+ try {
2455
+ yield service.loadModule(moduleName);
2456
+ }
2457
+ catch (error) {
2458
+ console.error(`Failed to load module config ${moduleName}:`, error);
2459
+ }
2460
+ finally {
2461
+ setIsLoading(false);
2462
+ }
2463
+ }), [service]);
2464
+ const get = reactExports.useCallback((key, options) => {
2465
+ return service.get(key, options);
2466
+ }, [service]);
2467
+ const getConfig = reactExports.useCallback((moduleName) => {
2468
+ return service.getConfig(moduleName);
2469
+ }, [service]);
2470
+ return {
2471
+ get,
2472
+ getConfig,
2473
+ reloadConfig,
3433
2474
  isLoading,
3434
- }), [service, isLoading]);
3435
- return value;
2475
+ loadModuleConfig,
2476
+ };
3436
2477
  };
3437
- const ConfigProvider = ({ children, preloadModules = [] }) => {
3438
- const value = useConfigValue();
3439
- reactExports.useEffect(() => {
3440
- if (!value.isLoading) {
3441
- preloadModules.forEach(moduleName => {
3442
- value.loadModuleConfig(moduleName);
3443
- });
3444
- }
3445
- }, [value.isLoading]);
3446
- return jsxRuntimeExports.jsx(ConfigContext.Provider, { value: value, children: children });
2478
+ const ConfigManagerProvider = ({ configs, children, }) => {
2479
+ const value = useConfigManagerValue(configs);
2480
+ return jsxRuntimeExports.jsx(ConfigManagerContext.Provider, { value: value, children: children });
3447
2481
  };
3448
- const useConfig = () => {
3449
- const context = reactExports.useContext(ConfigContext);
2482
+ const useConfigManager = () => {
2483
+ const context = reactExports.useContext(ConfigManagerContext);
3450
2484
  if (!context)
3451
- throw new Error('useConfig must be used within a ConfigProvider');
2485
+ throw new Error('useConfigManager must be used within a ConfigManagerProvider');
3452
2486
  return context;
3453
2487
  };
3454
2488
 
3455
- export { ConfigProvider, useConfig };
2489
+ const useConfig = (moduleName) => {
2490
+ const configManager = useConfigManager();
2491
+ const [isModuleLoading, setIsModuleLoading] = reactExports.useState(false);
2492
+ const [moduleLoaded, setModuleLoaded] = reactExports.useState(!moduleName);
2493
+ const cf = reactExports.useCallback((key, options) => {
2494
+ const finalOptions = Object.assign(Object.assign({}, options), { moduleName: (options === null || options === void 0 ? void 0 : options.moduleName) || moduleName || 'base' });
2495
+ return configManager.get(key, finalOptions);
2496
+ }, [configManager, moduleName]);
2497
+ reactExports.useEffect(() => {
2498
+ if (moduleName && !moduleLoaded) {
2499
+ setIsModuleLoading(true);
2500
+ configManager.loadModuleConfig(moduleName)
2501
+ .then(() => {
2502
+ setModuleLoaded(true);
2503
+ })
2504
+ .finally(() => {
2505
+ setIsModuleLoading(false);
2506
+ });
2507
+ }
2508
+ }, [moduleName, moduleLoaded, configManager]);
2509
+ return {
2510
+ cf,
2511
+ getConfig: configManager.getConfig,
2512
+ reloadConfig: configManager.reloadConfig,
2513
+ isLoading: configManager.isLoading || isModuleLoading,
2514
+ isModuleLoaded: moduleLoaded,
2515
+ loadModuleConfig: configManager.loadModuleConfig,
2516
+ };
2517
+ };
2518
+
2519
+ export { ConfigManagerProvider, useConfig, useConfigManager };