@digital-alchemy/core 26.1.9 → 26.5.1

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.
Files changed (85) hide show
  1. package/CLAUDE.md +302 -0
  2. package/README.md +19 -3
  3. package/dist/helpers/async.d.mts +37 -0
  4. package/dist/helpers/async.mjs +50 -15
  5. package/dist/helpers/async.mjs.map +1 -1
  6. package/dist/helpers/config-environment-loader.d.mts +39 -0
  7. package/dist/helpers/config-environment-loader.mjs +51 -11
  8. package/dist/helpers/config-environment-loader.mjs.map +1 -1
  9. package/dist/helpers/config-file-loader.d.mts +66 -1
  10. package/dist/helpers/config-file-loader.mjs +82 -6
  11. package/dist/helpers/config-file-loader.mjs.map +1 -1
  12. package/dist/helpers/config.d.mts +202 -5
  13. package/dist/helpers/config.mjs +60 -0
  14. package/dist/helpers/config.mjs.map +1 -1
  15. package/dist/helpers/context.d.mts +12 -1
  16. package/dist/helpers/cron.d.mts +154 -7
  17. package/dist/helpers/cron.mjs +47 -4
  18. package/dist/helpers/cron.mjs.map +1 -1
  19. package/dist/helpers/errors.d.mts +45 -0
  20. package/dist/helpers/errors.mjs +45 -0
  21. package/dist/helpers/errors.mjs.map +1 -1
  22. package/dist/helpers/events.d.mts +23 -0
  23. package/dist/helpers/events.mjs +23 -0
  24. package/dist/helpers/events.mjs.map +1 -1
  25. package/dist/helpers/extend.d.mts +50 -0
  26. package/dist/helpers/extend.mjs +63 -0
  27. package/dist/helpers/extend.mjs.map +1 -1
  28. package/dist/helpers/index.d.mts +9 -0
  29. package/dist/helpers/index.mjs +9 -0
  30. package/dist/helpers/index.mjs.map +1 -1
  31. package/dist/helpers/lifecycle.d.mts +102 -16
  32. package/dist/helpers/lifecycle.mjs +19 -1
  33. package/dist/helpers/lifecycle.mjs.map +1 -1
  34. package/dist/helpers/logger.d.mts +178 -17
  35. package/dist/helpers/logger.mjs +41 -1
  36. package/dist/helpers/logger.mjs.map +1 -1
  37. package/dist/helpers/module.d.mts +110 -0
  38. package/dist/helpers/module.mjs +55 -6
  39. package/dist/helpers/module.mjs.map +1 -1
  40. package/dist/helpers/service-runner.d.mts +27 -1
  41. package/dist/helpers/service-runner.mjs +27 -1
  42. package/dist/helpers/service-runner.mjs.map +1 -1
  43. package/dist/helpers/utilities.d.mts +123 -3
  44. package/dist/helpers/utilities.mjs +110 -3
  45. package/dist/helpers/utilities.mjs.map +1 -1
  46. package/dist/helpers/wiring.d.mts +385 -0
  47. package/dist/helpers/wiring.mjs +120 -0
  48. package/dist/helpers/wiring.mjs.map +1 -1
  49. package/dist/services/als.service.d.mts +10 -0
  50. package/dist/services/als.service.mjs +49 -0
  51. package/dist/services/als.service.mjs.map +1 -1
  52. package/dist/services/configuration.service.d.mts +22 -0
  53. package/dist/services/configuration.service.mjs +140 -12
  54. package/dist/services/configuration.service.mjs.map +1 -1
  55. package/dist/services/index.d.mts +8 -0
  56. package/dist/services/index.mjs +8 -0
  57. package/dist/services/index.mjs.map +1 -1
  58. package/dist/services/internal.service.d.mts +98 -19
  59. package/dist/services/internal.service.mjs +91 -9
  60. package/dist/services/internal.service.mjs.map +1 -1
  61. package/dist/services/is.service.d.mts +64 -4
  62. package/dist/services/is.service.mjs +67 -4
  63. package/dist/services/is.service.mjs.map +1 -1
  64. package/dist/services/lifecycle.service.d.mts +26 -0
  65. package/dist/services/lifecycle.service.mjs +67 -9
  66. package/dist/services/lifecycle.service.mjs.map +1 -1
  67. package/dist/services/logger.service.d.mts +27 -0
  68. package/dist/services/logger.service.mjs +133 -9
  69. package/dist/services/logger.service.mjs.map +1 -1
  70. package/dist/services/scheduler.service.d.mts +19 -0
  71. package/dist/services/scheduler.service.mjs +87 -4
  72. package/dist/services/scheduler.service.mjs.map +1 -1
  73. package/dist/services/wiring.service.d.mts +29 -1
  74. package/dist/services/wiring.service.mjs +153 -20
  75. package/dist/services/wiring.service.mjs.map +1 -1
  76. package/dist/testing/index.d.mts +4 -0
  77. package/dist/testing/index.mjs +4 -0
  78. package/dist/testing/index.mjs.map +1 -1
  79. package/dist/testing/mock-logger.d.mts +8 -0
  80. package/dist/testing/mock-logger.mjs +9 -0
  81. package/dist/testing/mock-logger.mjs.map +1 -1
  82. package/dist/testing/test-module.d.mts +107 -27
  83. package/dist/testing/test-module.mjs +58 -1
  84. package/dist/testing/test-module.mjs.map +1 -1
  85. package/package.json +33 -31
@@ -1 +1 @@
1
- {"version":3,"file":"events.mjs","sourceRoot":"","sources":["../../src/helpers/events.mts"],"names":[],"mappings":"AAAA,OAAO,EAAE,EAAE,EAAE,MAAM,cAAc,CAAC;AAElC,MAAM,CAAC,MAAM,iCAAiC,GAAG,mCAAmC,CAAC;AACrF,MAAM,CAAC,MAAM,iCAAiC,GAAG,mCAAmC,CAAC;AACrF,MAAM,CAAC,MAAM,6BAA6B,GAAG,CAAC,OAAgB,EAAE,EAAE,CAChE,EAAE,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,+BAA+B,CAAC,CAAC,CAAC,iCAAiC,OAAO,EAAE,CAAC"}
1
+ {"version":3,"file":"events.mjs","sourceRoot":"","sources":["../../src/helpers/events.mts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,EAAE,EAAE,EAAE,MAAM,cAAc,CAAC;AAElC;;GAEG;AACH,MAAM,CAAC,MAAM,iCAAiC,GAAG,mCAAmC,CAAC;AAErF;;GAEG;AACH,MAAM,CAAC,MAAM,iCAAiC,GAAG,mCAAmC,CAAC;AAErF;;;;;;;;GAQG;AACH,MAAM,CAAC,MAAM,6BAA6B,GAAG,CAAC,OAAgB,EAAE,EAAE,CAChE,EAAE,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,+BAA+B,CAAC,CAAC,CAAC,iCAAiC,OAAO,EAAE,CAAC"}
@@ -1,4 +1,54 @@
1
+ /**
2
+ * Deep object merging and cloning utilities — recursive extend and array clone
3
+ * functions that preserve Date and RegExp instances.
4
+ *
5
+ * @remarks
6
+ * These utilities support the configuration system by enabling deep merging of
7
+ * config objects from multiple sources while preserving special value types.
8
+ * `deepExtend` mutates the target in place and returns it; `deepCloneArray`
9
+ * creates a new array with recursively cloned items.
10
+ */
11
+ /**
12
+ * Clone a Date or RegExp instance.
13
+ *
14
+ * @remarks
15
+ * Creates a new Date or RegExp with the same value as the input. Throws
16
+ * TypeError if the input is neither a Date nor a RegExp.
17
+ *
18
+ * @throws {TypeError} when the value is not a Date or RegExp.
19
+ *
20
+ * @internal
21
+ */
1
22
  export declare function cloneSpecificValue(value: unknown): RegExp | Date;
23
+ /**
24
+ * Recursively clone an array, preserving nested objects, arrays, Dates, and RegExps.
25
+ *
26
+ * @remarks
27
+ * Walks the array and clones each item: arrays are cloned recursively, Dates and
28
+ * RegExps are cloned using `cloneSpecificValue`, plain objects are merged with
29
+ * an empty target using `deepExtend`, and primitives are returned as-is.
30
+ */
2
31
  export declare function deepCloneArray<TYPE = unknown>(array: Array<TYPE>): Array<TYPE>;
32
+ /**
33
+ * Safely read a property from an object, blocking access to `__proto__`.
34
+ *
35
+ * @remarks
36
+ * Returns `undefined` if the key is `__proto__`, otherwise returns the value at
37
+ * `object[key]`. This prevents prototype pollution vulnerabilities during deep
38
+ * merges.
39
+ *
40
+ * @internal
41
+ */
3
42
  export declare function safeGetProperty(object: unknown, key: string): unknown;
43
+ /**
44
+ * Merge all own properties from `object` into `target`, recursively.
45
+ *
46
+ * @remarks
47
+ * Mutates `target` in place and returns the merged result. Primitive values
48
+ * overwrite target properties outright. Arrays from `object` are cloned into
49
+ * the target. Objects are recursively merged if both target and source values
50
+ * are plain objects; otherwise, a new deep clone is created. Dates and RegExps
51
+ * are cloned. Circular references (where `value === target`) are skipped to
52
+ * prevent infinite recursion.
53
+ */
4
54
  export declare function deepExtend<A, B>(target: A, object: B): A & B;
@@ -1,7 +1,33 @@
1
+ /**
2
+ * Deep object merging and cloning utilities — recursive extend and array clone
3
+ * functions that preserve Date and RegExp instances.
4
+ *
5
+ * @remarks
6
+ * These utilities support the configuration system by enabling deep merging of
7
+ * config objects from multiple sources while preserving special value types.
8
+ * `deepExtend` mutates the target in place and returns it; `deepCloneArray`
9
+ * creates a new array with recursively cloned items.
10
+ */
1
11
  import { is } from "../index.mjs";
12
+ /**
13
+ * Check whether a value is a Date or RegExp instance.
14
+ *
15
+ * @internal
16
+ */
2
17
  function isSpecificValue(value) {
3
18
  return value instanceof Date || value instanceof RegExp;
4
19
  }
20
+ /**
21
+ * Clone a Date or RegExp instance.
22
+ *
23
+ * @remarks
24
+ * Creates a new Date or RegExp with the same value as the input. Throws
25
+ * TypeError if the input is neither a Date nor a RegExp.
26
+ *
27
+ * @throws {TypeError} when the value is not a Date or RegExp.
28
+ *
29
+ * @internal
30
+ */
5
31
  export function cloneSpecificValue(value) {
6
32
  if (value instanceof Date) {
7
33
  return new Date(value.getTime());
@@ -11,6 +37,14 @@ export function cloneSpecificValue(value) {
11
37
  }
12
38
  throw new TypeError("Unexpected situation");
13
39
  }
40
+ /**
41
+ * Recursively clone an array, preserving nested objects, arrays, Dates, and RegExps.
42
+ *
43
+ * @remarks
44
+ * Walks the array and clones each item: arrays are cloned recursively, Dates and
45
+ * RegExps are cloned using `cloneSpecificValue`, plain objects are merged with
46
+ * an empty target using `deepExtend`, and primitives are returned as-is.
47
+ */
14
48
  export function deepCloneArray(array) {
15
49
  // eslint-disable-next-line sonarjs/function-return-type
16
50
  return array.map(item => {
@@ -26,35 +60,64 @@ export function deepCloneArray(array) {
26
60
  return item;
27
61
  });
28
62
  }
63
+ /**
64
+ * Safely read a property from an object, blocking access to `__proto__`.
65
+ *
66
+ * @remarks
67
+ * Returns `undefined` if the key is `__proto__`, otherwise returns the value at
68
+ * `object[key]`. This prevents prototype pollution vulnerabilities during deep
69
+ * merges.
70
+ *
71
+ * @internal
72
+ */
29
73
  export function safeGetProperty(object, key) {
74
+ // guard against prototype pollution
30
75
  return key === "__proto__" ? undefined : object[key];
31
76
  }
77
+ /**
78
+ * Merge all own properties from `object` into `target`, recursively.
79
+ *
80
+ * @remarks
81
+ * Mutates `target` in place and returns the merged result. Primitive values
82
+ * overwrite target properties outright. Arrays from `object` are cloned into
83
+ * the target. Objects are recursively merged if both target and source values
84
+ * are plain objects; otherwise, a new deep clone is created. Dates and RegExps
85
+ * are cloned. Circular references (where `value === target`) are skipped to
86
+ * prevent infinite recursion.
87
+ */
32
88
  export function deepExtend(target, object) {
89
+ // early exit if not merging an object
33
90
  if (!is.object(object)) {
34
91
  return target;
35
92
  }
36
93
  Object.keys(object).forEach(key => {
37
94
  const source = safeGetProperty(target, key);
38
95
  const value = safeGetProperty(object, key);
96
+ // skip circular references
39
97
  if (value === target) {
40
98
  return;
41
99
  }
100
+ // scalars and nulls overwrite directly
42
101
  if (typeof value !== "object" || value === null) {
43
102
  target[key] = value;
44
103
  return;
45
104
  }
105
+ // arrays are cloned into the target
46
106
  if (is.array(value)) {
47
107
  target[key] = deepCloneArray(value);
48
108
  return;
49
109
  }
110
+ // special values (Date, RegExp) are cloned
50
111
  if (isSpecificValue(value)) {
51
112
  target[key] = cloneSpecificValue(value);
52
113
  return;
53
114
  }
115
+ // if source is not an object or is an array, create a new clone of value
54
116
  if (typeof source !== "object" || source === null || is.array(source)) {
55
117
  target[key] = deepExtend({}, value);
56
118
  return;
57
119
  }
120
+ // both are plain objects — recurse
58
121
  target[key] = deepExtend(source, value);
59
122
  });
60
123
  return target;
@@ -1 +1 @@
1
- {"version":3,"file":"extend.mjs","sourceRoot":"","sources":["../../src/helpers/extend.mts"],"names":[],"mappings":"AAAA,OAAO,EAAE,EAAE,EAAE,MAAM,cAAc,CAAC;AAElC,SAAS,eAAe,CAAC,KAAc;IACrC,OAAO,KAAK,YAAY,IAAI,IAAI,KAAK,YAAY,MAAM,CAAC;AAC1D,CAAC;AAED,MAAM,UAAU,kBAAkB,CAAC,KAAc;IAC/C,IAAI,KAAK,YAAY,IAAI,EAAE,CAAC;QAC1B,OAAO,IAAI,IAAI,CAAC,KAAK,CAAC,OAAO,EAAE,CAA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AAG,eAAe,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;QAC5C,MAAM,KAAK,GAAG,eAAe,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;QAC3C,2BAA2B;QAC3B,IAAI,KAAK,KAAK,MAAM,EAAE,CAAC;YACrB,OAAO;QACT,CAAC;QACD,uCAAuC;QACvC,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,KAAK,IAAI,EAAE,CAAC;YAC/C,MAAkC,CAAC,GAAG,CAAC,GAAG,KAAK,CAAC;YACjD,OAAO;QACT,CAAC;QACD,oCAAoC;QACpC,IAAI,EAAE,CAAC,KAAK,CAAC,KAAK,CAAC,EAAE,CAAC;YACnB,MAAkC,CAAC,GAAG,CAAC,GAAG,cAAc,CAAC,KAAK,CAAC,CAAC;YACjE,OAAO;QACT,CAAC;QACD,2CAA2C;QAC3C,IAAI,eAAe,CAAC,KAAK,CAAC,EAAE,CAAC;YAC1B,MAAkC,CAAC,GAAG,CAAC,GAAG,kBAAkB,CAAC,KAAK,CAAC,CAAC;YACrE,OAAO;QACT,CAAC;QACD,yEAAyE;QACzE,IAAI,OAAO,MAAM,KAAK,QAAQ,IAAI,MAAM,KAAK,IAAI,IAAI,EAAE,CAAC,KAAK,CAAC,MAAM,CAAC,EAAE,CAAC;YACrE,MAAkC,CAAC,GAAG,CAAC,GAAG,UAAU,CAAC,EAAE,EAAE,KAAK,CAAC,CAAC;YACjE,OAAO;QACT,CAAC;QACD,mCAAmC;QAClC,MAAkC,CAAC,GAAG,CAAC,GAAG,UAAU,CAAC,MAAM,EAAE,KAAK,CAAC,CAAC;IACvE,CAAC,CAAC,CAAC;IACH,OAAO,MAAe,CAAC;AACzB,CAAC"}
@@ -1,3 +1,12 @@
1
+ /**
2
+ * Public helpers — pure-function modules and type definitions.
3
+ *
4
+ * @remarks
5
+ * This module re-exports all helper modules (async utilities, config loaders,
6
+ * lifecycle types, logging interfaces, cron schedules, etc.). Helpers are
7
+ * side-effect-free and differ from services in that they do not receive
8
+ * `TServiceParams` or participate in the DI graph.
9
+ */
1
10
  export * from "./async.mts";
2
11
  export * from "./config.mts";
3
12
  export * from "./config-environment-loader.mts";
@@ -1,3 +1,12 @@
1
+ /**
2
+ * Public helpers — pure-function modules and type definitions.
3
+ *
4
+ * @remarks
5
+ * This module re-exports all helper modules (async utilities, config loaders,
6
+ * lifecycle types, logging interfaces, cron schedules, etc.). Helpers are
7
+ * side-effect-free and differ from services in that they do not receive
8
+ * `TServiceParams` or participate in the DI graph.
9
+ */
1
10
  export * from "./async.mjs";
2
11
  export * from "./config.mjs";
3
12
  export * from "./config-environment-loader.mjs";
@@ -1 +1 @@
1
- {"version":3,"file":"index.mjs","sourceRoot":"","sources":["../../src/helpers/index.mts"],"names":[],"mappings":"AAAA,cAAc,aAAa,CAAC;AAC5B,cAAc,cAAc,CAAC;AAC7B,cAAc,iCAAiC,CAAC;AAChD,cAAc,0BAA0B,CAAC;AACzC,cAAc,eAAe,CAAC;AAC9B,cAAc,YAAY,CAAC;AAC3B,cAAc,cAAc,CAAC;AAC7B,cAAc,cAAc,CAAC;AAC7B,cAAc,cAAc,CAAC;AAC7B,cAAc,iBAAiB,CAAC;AAChC,cAAc,cAAc,CAAC;AAC7B,cAAc,cAAc,CAAC;AAC7B,cAAc,sBAAsB,CAAC;AACrC,cAAc,iBAAiB,CAAC;AAChC,cAAc,cAAc,CAAC"}
1
+ {"version":3,"file":"index.mjs","sourceRoot":"","sources":["../../src/helpers/index.mts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,cAAc,aAAa,CAAC;AAC5B,cAAc,cAAc,CAAC;AAC7B,cAAc,iCAAiC,CAAC;AAChD,cAAc,0BAA0B,CAAC;AACzC,cAAc,eAAe,CAAC;AAC9B,cAAc,YAAY,CAAC;AAC3B,cAAc,cAAc,CAAC;AAC7B,cAAc,cAAc,CAAC;AAC7B,cAAc,cAAc,CAAC;AAC7B,cAAc,iBAAiB,CAAC;AAChC,cAAc,cAAc,CAAC;AAC7B,cAAc,cAAc,CAAC;AAC7B,cAAc,sBAAsB,CAAC;AACrC,cAAc,iBAAiB,CAAC;AAChC,cAAc,cAAc,CAAC"}
@@ -1,54 +1,140 @@
1
+ /**
2
+ * Lifecycle types and stage definitions — the ordered callback hooks that
3
+ * frame application startup and shutdown.
4
+ *
5
+ * @remarks
6
+ * Services register callbacks at specific lifecycle stages; the wiring engine
7
+ * executes them in strict order. Callbacks can be prioritized (positive = early,
8
+ * negative = late, unspecified = parallel). Each stage represents a well-defined
9
+ * point where certain actions are safe: `onPreInit` before config,
10
+ * `onPostConfig` after, `onBootstrap` after all modules are wired, `onReady`
11
+ * when the app is running, and three shutdown stages for graceful termination.
12
+ */
1
13
  import type { TBlackHole } from "./utilities.mts";
14
+ /**
15
+ * Function signature for a lifecycle callback — takes no arguments, returns nothing.
16
+ */
2
17
  export type LifecycleCallback = () => TBlackHole;
18
+ /**
19
+ * Prioritized callback — a tuple of callback function and numeric priority.
20
+ *
21
+ * @remarks
22
+ * Used internally by the lifecycle engine to sort callbacks before execution.
23
+ * Higher priorities run first; unspecified (default) callbacks run in parallel;
24
+ * negative priorities run last.
25
+ *
26
+ * @internal
27
+ */
3
28
  export type LifecyclePrioritizedCallback = [callback: LifecycleCallback, priority: number];
29
+ /**
30
+ * Ordered collection of prioritized callbacks.
31
+ *
32
+ * @internal
33
+ */
4
34
  export type CallbackList = LifecyclePrioritizedCallback[];
35
+ /**
36
+ * Function signature for registering a lifecycle callback.
37
+ *
38
+ * @remarks
39
+ * Services call these methods to attach callbacks at specific lifecycle stages.
40
+ * The optional `priority` argument controls execution order:
41
+ * positive = early (high to low), undefined = parallel, negative = late.
42
+ */
5
43
  export type TLifeCycleRegister = (callback: LifecycleCallback, priority?: number) => void;
44
+ /**
45
+ * Core lifecycle interface — seven stages with callback registration methods.
46
+ *
47
+ * @remarks
48
+ * Each method (`onPreInit`, `onPostConfig`, etc.) accepts a callback and optional
49
+ * priority. Callbacks are invoked by the bootstrap engine in strict stage order,
50
+ * with priorities controlling execution within each stage.
51
+ */
6
52
  export type TLifecycleBase = {
7
53
  /**
8
- * Registers a callback for the bootstrap phase, executed during the initial startup process.
54
+ * Registers a callback for the pre-initialization phase, executed before config is loaded.
9
55
  *
10
- * Optional priority arg: negative values -> no value -> positive value
56
+ * @remarks
57
+ * Safe for basic state setup; do not read config values at this stage.
58
+ *
59
+ * Priority: positive = early, undefined = parallel, negative = late.
11
60
  */
12
- onBootstrap: TLifeCycleRegister;
61
+ onPreInit: TLifeCycleRegister;
13
62
  /**
14
- * Registers a callback for immediately after the configuration phase, allowing post-configuration adjustments.
63
+ * Registers a callback for the post-configuration phase, executed after config is ready.
15
64
  *
16
- * Optional priority arg: negative values -> no value -> positive value
65
+ * @remarks
66
+ * Safe to read and validate config values; all modules are not yet wired.
67
+ *
68
+ * Priority: positive = early, undefined = parallel, negative = late.
17
69
  */
18
70
  onPostConfig: TLifeCycleRegister;
19
71
  /**
20
- * Registers a callback for the pre-initialization phase, executed before the main initialization starts.
72
+ * Registers a callback for the bootstrap phase, executed when all modules are wired.
73
+ *
74
+ * @remarks
75
+ * Safe to call other services and set up inter-service dependencies.
21
76
  *
22
- * Optional priority arg: negative values -> no value -> positive value
77
+ * Priority: positive = early, undefined = parallel, negative = late.
23
78
  */
24
- onPreInit: TLifeCycleRegister;
79
+ onBootstrap: TLifeCycleRegister;
25
80
  /**
26
- * Registers a callback for when the system is fully initialized and ready.
81
+ * Registers a callback for the ready phase, executed when the app is fully running.
82
+ *
83
+ * @remarks
84
+ * Safe to start schedulers, timers, and external integrations.
27
85
  *
28
- * Optional priority arg: negative values -> no value -> positive value
86
+ * Priority: positive = early, undefined = parallel, negative = late.
29
87
  */
30
88
  onReady: TLifeCycleRegister;
31
89
  /**
32
- * Notification that the application intends to shut down.
90
+ * Registers a callback for the pre-shutdown phase, notification of intended shutdown.
91
+ *
92
+ * @remarks
93
+ * First shutdown hook; used for graceful degradation or cleanup signaling.
33
94
  *
34
- * Optional priority arg: negative values -> no value -> positive value
95
+ * Priority: positive = early, undefined = parallel, negative = late.
35
96
  */
36
97
  onPreShutdown: TLifeCycleRegister;
37
98
  /**
38
- * Begins the shutdown process, typically invoked when the system is about to shut down.
99
+ * Registers a callback for the shutdown-start phase, begins active teardown.
39
100
  *
40
- * Optional priority arg: negative values -> no value -> positive value
101
+ * @remarks
102
+ * Close connections, stop schedulers, and drain in-flight operations.
103
+ *
104
+ * Priority: positive = early, undefined = parallel, negative = late.
41
105
  */
42
106
  onShutdownStart: TLifeCycleRegister;
43
107
  /**
44
- * Completes the shutdown process, executed after all shutdown procedures are complete.
108
+ * Registers a callback for the shutdown-complete phase, final cleanup.
109
+ *
110
+ * @remarks
111
+ * Last-resort cleanup after all other teardown is done.
45
112
  *
46
- * Optional priority arg: negative values -> no value -> positive value
113
+ * Priority: positive = early, undefined = parallel, negative = late.
47
114
  */
48
115
  onShutdownComplete: TLifeCycleRegister;
49
116
  };
117
+ /**
118
+ * Extended lifecycle interface with child lifecycle factory.
119
+ *
120
+ * @remarks
121
+ * Used by scoped contexts (e.g., per-request) to create child lifecycle instances
122
+ * that fire callbacks within their own scope.
123
+ *
124
+ * @internal
125
+ */
50
126
  export type TParentLifecycle = TLifecycleBase & {
51
127
  child: () => TLifecycleBase;
52
128
  };
129
+ /**
130
+ * Ordered lifecycle stages — the canonical sequence of bootstrap and shutdown phases.
131
+ *
132
+ * @remarks
133
+ * This array defines the execution order. Do not change the order; it is relied
134
+ * upon by the wiring engine to route callbacks and ensure safe state transitions.
135
+ */
53
136
  export declare const LIFECYCLE_STAGES: readonly ["PreInit", "PostConfig", "Bootstrap", "Ready", "PreShutdown", "ShutdownStart", "ShutdownComplete"];
137
+ /**
138
+ * Union type of all lifecycle stage names.
139
+ */
54
140
  export type LifecycleStages = (typeof LIFECYCLE_STAGES)[number];
@@ -1,4 +1,22 @@
1
- // ! This is a sorted array! Don't change the order
1
+ /**
2
+ * Lifecycle types and stage definitions — the ordered callback hooks that
3
+ * frame application startup and shutdown.
4
+ *
5
+ * @remarks
6
+ * Services register callbacks at specific lifecycle stages; the wiring engine
7
+ * executes them in strict order. Callbacks can be prioritized (positive = early,
8
+ * negative = late, unspecified = parallel). Each stage represents a well-defined
9
+ * point where certain actions are safe: `onPreInit` before config,
10
+ * `onPostConfig` after, `onBootstrap` after all modules are wired, `onReady`
11
+ * when the app is running, and three shutdown stages for graceful termination.
12
+ */
13
+ /**
14
+ * Ordered lifecycle stages — the canonical sequence of bootstrap and shutdown phases.
15
+ *
16
+ * @remarks
17
+ * This array defines the execution order. Do not change the order; it is relied
18
+ * upon by the wiring engine to route callbacks and ensure safe state transitions.
19
+ */
2
20
  export const LIFECYCLE_STAGES = [
3
21
  "PreInit",
4
22
  "PostConfig",
@@ -1 +1 @@
1
- {"version":3,"file":"lifecycle.mjs","sourceRoot":"","sources":["../../src/helpers/lifecycle.mts"],"names":[],"mappings":"AA+DA,mDAAmD;AACnD,MAAM,CAAC,MAAM,gBAAgB,GAAG;IAC9B,SAAS;IACT,YAAY;IACZ,WAAW;IACX,OAAO;IACP,aAAa;IACb,eAAe;IACf,kBAAkB;CACV,CAAC"}
1
+ {"version":3,"file":"lifecycle.mjs","sourceRoot":"","sources":["../../src/helpers/lifecycle.mts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAmIH;;;;;;GAMG;AACH,MAAM,CAAC,MAAM,gBAAgB,GAAG;IAC9B,SAAS;IACT,YAAY;IACZ,WAAW;IACX,OAAO;IACP,aAAa;IACb,eAAe;IACf,kBAAkB;CACV,CAAC"}
@@ -1,67 +1,228 @@
1
+ /**
2
+ * Logger interface and configuration — dual-arity log methods, color schemes,
3
+ * and a last-resort stderr writer.
4
+ *
5
+ * @remarks
6
+ * The logger supports six severity levels (trace, debug, info, warn, error, fatal)
7
+ * and dual-arity calls: `logger.info("message")` or `logger.info({ context, id }, "message")`.
8
+ * The logger service wraps this interface with chalk/stdout formatting, ALS
9
+ * integration, and LOG_LEVEL filtering. `fatalLog` is the last-resort writer for
10
+ * fatal conditions that cannot use the logger (e.g., during bootstrap failure).
11
+ */
1
12
  import type { Get } from "type-fest";
2
13
  import type { TContext } from "./context.mts";
3
14
  import type { TBlackHole } from "./utilities.mts";
15
+ /**
16
+ * Extension hook for logger replacement via declaration merging.
17
+ *
18
+ * @remarks
19
+ * Downstream libraries can extend this interface to substitute their own logger
20
+ * type into `GetLogger`, allowing alternative logging implementations.
21
+ *
22
+ * @internal
23
+ */
4
24
  export interface ReplacementLogger {
5
25
  }
26
+ /**
27
+ * Resolved logger type — either a merged replacement logger or the default `ILogger`.
28
+ *
29
+ * @remarks
30
+ * When `ReplacementLogger` is extended with a `logger` property, that type is
31
+ * used; otherwise, `ILogger` is the default.
32
+ */
6
33
  export type GetLogger = Get<ReplacementLogger, "logger"> extends object ? Get<ReplacementLogger, "logger"> : ILogger;
34
+ /**
35
+ * Streaming log target — a function that receives formatted message and context data.
36
+ *
37
+ * @remarks
38
+ * Implementing libraries can add custom targets to send logs to external services
39
+ * (e.g., Datadog, CloudWatch) via the `logger.addTarget(...)` method.
40
+ */
7
41
  export type LogStreamTarget = (message: string, data: object) => TBlackHole;
42
+ /**
43
+ * Logger service interface — methods to emit logs, create scoped loggers, and
44
+ * configure targets and output formatting.
45
+ *
46
+ * @remarks
47
+ * Each method operates on a base logger (which can be replaced for testing or
48
+ * integration) and filters based on the current LOG_LEVEL configuration.
49
+ * The `systemLogger` is a pre-created instance for use in bootstrap and
50
+ * low-level operations.
51
+ */
8
52
  export type DigitalAlchemyLogger = {
53
+ /**
54
+ * Register an additional log target.
55
+ *
56
+ * @remarks
57
+ * Targets receive all logged messages and context data after filtering.
58
+ * Can be a logger instance (like `ILogger`) or a stream function that writes
59
+ * directly to an external service.
60
+ */
9
61
  addTarget: (logger: GetLogger | LogStreamTarget) => void;
10
62
  /**
11
- * Create a new logger instance for a given context
63
+ * Create a new logger instance scoped to a specific context.
64
+ *
65
+ * @remarks
66
+ * Returns an `ILogger` where all calls are implicitly tagged with the given context,
67
+ * enabling per-request log correlation and filtering.
12
68
  */
13
69
  context: (context: string | TContext) => ILogger;
14
70
  /**
15
- * Retrieve a reference to the base logger used to emit from
71
+ * Retrieve the underlying base logger implementation.
72
+ *
73
+ * @remarks
74
+ * Exposed for testing and low-level integrations; most code should use the logger
75
+ * returned by the injection, not this method.
76
+ *
77
+ * @internal
16
78
  */
17
79
  getBaseLogger: () => Record<keyof GetLogger, (context: TContext, ...data: Parameters<TLoggerFunction>) => void>;
80
+ /**
81
+ * Check whether pretty formatting is enabled.
82
+ *
83
+ * @remarks
84
+ * Exposed for testing.
85
+ *
86
+ * @internal
87
+ */
18
88
  getPrettyFormat: () => boolean;
19
89
  /**
20
- * exposed for testing
90
+ * Format a message string for display.
91
+ *
92
+ * @remarks
93
+ * Applies syntax highlighting or other transformations based on the current
94
+ * pretty-format setting. Exposed for testing.
95
+ *
96
+ * @internal
21
97
  */
22
98
  prettyFormatMessage: (message: string) => string;
23
99
  /**
24
- * Modify the base logger
100
+ * Replace the base logger implementation.
25
101
  *
26
- * Note: Extension still handles LOG_LEVEL logic
102
+ * @remarks
103
+ * Allows testing and framework integration by substituting a mock or wrapper logger.
104
+ * The service still enforces LOG_LEVEL filtering on top of the replacement.
27
105
  */
28
106
  setBaseLogger: (base: GetLogger) => GetLogger;
29
107
  /**
30
- * Set the enabled/disabled state of the message pretty formatting logic
108
+ * Enable or disable pretty formatting of log messages.
109
+ *
110
+ * @remarks
111
+ * When disabled, output is minimal (no colors, no extra formatting).
112
+ * Returns the new state.
31
113
  */
32
114
  setPrettyFormat: (state: boolean) => boolean;
33
115
  /**
34
- * Logger instance of last resort
116
+ * System logger instance ready-to-use logger for bootstrap and low-level code.
117
+ *
118
+ * @remarks
119
+ * Pre-created for convenience in places where context is unavailable or
120
+ * not yet initialized.
35
121
  */
36
122
  systemLogger: GetLogger;
37
123
  /**
38
- * exposed for testing
124
+ * Recompute log filtering based on current LOG_LEVEL config.
125
+ *
126
+ * @remarks
127
+ * Call after changing the LOG_LEVEL configuration to update filter state.
128
+ * Exposed for testing.
129
+ *
130
+ * @internal
39
131
  */
40
132
  updateShouldLog: () => void;
41
133
  };
134
+ /**
135
+ * Dual-arity logger function signature — message-only or object+message forms.
136
+ *
137
+ * @remarks
138
+ * Enables flexible calling styles:
139
+ * - `logger.info("message")`
140
+ * - `logger.info({data}, "message")`
141
+ * The logger extracts `name` from objects for call-site identification.
142
+ */
42
143
  export type TLoggerFunction = ((message: string, ...arguments_: unknown[]) => void) | ((object: object, message?: string, ...arguments_: unknown[]) => void);
144
+ /**
145
+ * Logger interface — six severity levels with dual-arity overloads.
146
+ *
147
+ * @remarks
148
+ * Each level (`trace`, `debug`, `info`, `warn`, `error`, `fatal`) accepts either
149
+ * a message string or an object with metadata plus an optional message. The
150
+ * object form typically includes a `name` field (function reference) for
151
+ * call-site identification.
152
+ */
43
153
  export interface ILogger {
154
+ /**
155
+ * Log at TRACE level — lowest severity, highest volume; decision points, entry/exit.
156
+ */
157
+ trace(...arguments_: Parameters<TLoggerFunction>): void;
158
+ trace(message: string, ...arguments_: unknown[]): void;
159
+ trace(object: object, message?: string, ...arguments_: unknown[]): void;
160
+ /**
161
+ * Log at DEBUG level — low severity; detailed operation flow.
162
+ */
44
163
  debug(...arguments_: Parameters<TLoggerFunction>): void;
45
164
  debug(message: string, ...arguments_: unknown[]): void;
46
165
  debug(object: object, message?: string, ...arguments_: unknown[]): void;
47
- error(...arguments_: Parameters<TLoggerFunction>): void;
48
- error(message: string, ...arguments_: unknown[]): void;
49
- error(object: object, message?: string, ...arguments_: unknown[]): void;
50
- fatal(...arguments_: Parameters<TLoggerFunction>): void;
51
- fatal(message: string, ...arguments_: unknown[]): void;
52
- fatal(object: object, message?: string, ...arguments_: unknown[]): void;
166
+ /**
167
+ * Log at INFO level — notable events; startup, shutdown, config changes.
168
+ */
53
169
  info(...arguments_: Parameters<TLoggerFunction>): void;
54
170
  info(message: string, ...arguments_: unknown[]): void;
55
171
  info(object: object, message?: string, ...arguments_: unknown[]): void;
56
- trace(...arguments_: Parameters<TLoggerFunction>): void;
57
- trace(message: string, ...arguments_: unknown[]): void;
58
- trace(object: object, message?: string, ...arguments_: unknown[]): void;
172
+ /**
173
+ * Log at WARN level — unexpected but non-fatal; potential issues worth investigating.
174
+ */
59
175
  warn(...arguments_: Parameters<TLoggerFunction>): void;
60
176
  warn(message: string, ...arguments_: unknown[]): void;
61
177
  warn(object: object, message?: string, ...arguments_: unknown[]): void;
178
+ /**
179
+ * Log at ERROR level — error conditions; failed operations, exceptions.
180
+ */
181
+ error(...arguments_: Parameters<TLoggerFunction>): void;
182
+ error(message: string, ...arguments_: unknown[]): void;
183
+ error(object: object, message?: string, ...arguments_: unknown[]): void;
184
+ /**
185
+ * Log at FATAL level — unrecoverable errors; application must shut down.
186
+ */
187
+ fatal(...arguments_: Parameters<TLoggerFunction>): void;
188
+ fatal(message: string, ...arguments_: unknown[]): void;
189
+ fatal(object: object, message?: string, ...arguments_: unknown[]): void;
62
190
  }
191
+ /**
192
+ * Configuration value type — log level or the special "silent" value.
193
+ */
63
194
  export type TConfigLogLevel = keyof ILogger | "silent";
195
+ /**
196
+ * Mapping from log level to console color for pretty-printed output.
197
+ */
64
198
  export declare const METHOD_COLORS: Map<keyof ILogger, CONTEXT_COLORS>;
199
+ /**
200
+ * Supported console color names for log output.
201
+ */
65
202
  export type CONTEXT_COLORS = "grey" | "blue" | "yellow" | "red" | "green" | "magenta";
203
+ /**
204
+ * Event name for log level configuration updates.
205
+ *
206
+ * @internal
207
+ */
66
208
  export declare const EVENT_UPDATE_LOG_LEVELS = "EVENT_UPDATE_LOG_LEVELS";
209
+ /**
210
+ * Last-resort logger for fatal conditions that cannot use the normal logger.
211
+ *
212
+ * @remarks
213
+ * Writes directly to `stderr` bypassing the logger service. Use only when the
214
+ * logger is not available (e.g., during bootstrap failure before services are
215
+ * wired). If `data` is an Error, extracts and formats `name`, `cause`, `message`,
216
+ * and stack trace; otherwise, JSON-stringifies it. Always adds a trailing newline.
217
+ *
218
+ * @example
219
+ * ```typescript
220
+ * try {
221
+ * await bootstrap();
222
+ * } catch (error) {
223
+ * fatalLog("bootstrap failed", error);
224
+ * process.exit(1);
225
+ * }
226
+ * ```
227
+ */
67
228
  export declare function fatalLog(message: string, data?: unknown): void;