@illuma/core 1.3.1 → 1.5.0

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.
@@ -1,4 +1,4 @@
1
- import { N as NodeToken, M as MultiNodeToken, a as NodeBase } from './types-zryyqrii.js';
1
+ import { N as NodeToken, M as MultiNodeToken, a as NodeBase, T as Token } from './types-zryyqrii.cjs';
2
2
 
3
3
  /**
4
4
  * Represents a single dependency injection point in the dependency graph.
@@ -29,6 +29,17 @@ interface iContextScanner {
29
29
  scan(factory: any): Set<iInjectionNode<any>>;
30
30
  }
31
31
 
32
+ /**
33
+ * Instantiation parameters for creating a new instance of a type `T`.
34
+ * @template T - The type of the instance to be created.
35
+ */
36
+ interface iInstantiationParams<T = unknown> {
37
+ readonly token: NodeBase<T>;
38
+ readonly factory: () => T;
39
+ readonly deps: Set<Token<unknown>>;
40
+ }
41
+ type iMiddleware<T = unknown> = (params: iInstantiationParams<T>, next: (params: iInstantiationParams<T>) => T) => T;
42
+
32
43
  declare class ProtoNodeSingle<T = any> {
33
44
  readonly token: NodeToken<T>;
34
45
  readonly injections: Set<iInjectionNode<any>>;
@@ -67,7 +78,7 @@ declare class TreeNodeSingle<T = any> {
67
78
  constructor(proto: ProtoNodeSingle<T>);
68
79
  addDependency(node: TreeNode<any>): void;
69
80
  collectPool(pool: InjectionPool): void;
70
- instantiate(pool?: InjectionPool): void;
81
+ instantiate(pool?: InjectionPool, middlewares?: iMiddleware[]): void;
71
82
  toString(): string;
72
83
  }
73
84
  declare class TreeNodeTransparent<T = any> {
@@ -81,7 +92,7 @@ declare class TreeNodeTransparent<T = any> {
81
92
  constructor(proto: ProtoNodeTransparent<T>);
82
93
  addDependency(node: TreeNode<any>): void;
83
94
  collectPool(pool: InjectionPool): void;
84
- instantiate(pool?: InjectionPool): void;
95
+ instantiate(pool?: InjectionPool, middlewares?: iMiddleware[]): void;
85
96
  toString(): string;
86
97
  }
87
98
  declare class TreeNodeMulti<T = any> {
@@ -92,7 +103,7 @@ declare class TreeNodeMulti<T = any> {
92
103
  allocations: number;
93
104
  constructor(proto: ProtoNodeMulti<T>);
94
105
  collectPool(pool: InjectionPool): void;
95
- instantiate(pool?: InjectionPool): void;
106
+ instantiate(pool?: InjectionPool, middlewares?: iMiddleware[]): void;
96
107
  addDependency(...nodes: TreeNode[]): void;
97
108
  toString(): string;
98
109
  }
@@ -117,6 +128,7 @@ interface iDiagnosticsModule {
117
128
  declare abstract class Illuma {
118
129
  private static readonly _diagnostics;
119
130
  private static readonly _scanners;
131
+ protected static readonly _middlewares: iMiddleware[];
120
132
  /** @internal */
121
133
  static get contextScanners(): ReadonlyArray<iContextScanner>;
122
134
  /**
@@ -133,7 +145,27 @@ declare abstract class Illuma {
133
145
  * @param scanner - The context scanner instance to add
134
146
  */
135
147
  static extendContextScanner(scanner: iContextScanner): void;
148
+ /**
149
+ * Registers a global middleware to be applied during instance creation.
150
+ * Typically used for cross-cutting concerns like logging, profiling, or custom instantiation logic.
151
+ * Function should accept instantiation parameters and a `next` function to proceed with the next middleware or actual instantiation.
152
+ *
153
+ * @param m - The middleware function to register
154
+ */
155
+ static registerGlobalMiddleware(m: iMiddleware): void;
156
+ protected readonly middlewares: iMiddleware[];
157
+ registerMiddleware(m: iMiddleware): void;
136
158
  protected static onReport(report: iDiagnosticsReport): void;
159
+ /**
160
+ * @internal
161
+ * Check if diagnostics modules are registered
162
+ */
163
+ protected static hasDiagnostics(): boolean;
164
+ /**
165
+ * @internal
166
+ * Reset all plugin registrations
167
+ */
168
+ protected static __resetPlugins(): void;
137
169
  }
138
170
 
139
- export { Illuma as I, type TreeNode as T, type iDiagnosticsModule as a, type iDiagnosticsReport as b, type iContextScanner as c, type iInjectionNode as i };
171
+ export { Illuma as I, type TreeNode as T, type iInjectionNode as a, type iDiagnosticsModule as b, type iDiagnosticsReport as c, type iContextScanner as d, type iInstantiationParams as e, type iMiddleware as i };
package/dist/plugins.cjs CHANGED
@@ -22,7 +22,8 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
22
22
  var plugins_exports = {};
23
23
  __export(plugins_exports, {
24
24
  DiagnosticsDefaultReporter: () => DiagnosticsDefaultReporter,
25
- Illuma: () => Illuma
25
+ Illuma: () => Illuma,
26
+ enableIllumaDiagnostics: () => enableIllumaDiagnostics
26
27
  });
27
28
  module.exports = __toCommonJS(plugins_exports);
28
29
 
@@ -31,8 +32,9 @@ var Illuma = class _Illuma {
31
32
  static {
32
33
  __name(this, "Illuma");
33
34
  }
34
- static _diagnostics = [];
35
+ static _diagnostics = /* @__PURE__ */ new Set();
35
36
  static _scanners = [];
37
+ static _middlewares = [];
36
38
  /** @internal */
37
39
  static get contextScanners() {
38
40
  return _Illuma._scanners;
@@ -44,7 +46,7 @@ var Illuma = class _Illuma {
44
46
  * @param m - The diagnostics module instance to add
45
47
  */
46
48
  static extendDiagnostics(m) {
47
- _Illuma._diagnostics.push(m);
49
+ _Illuma._diagnostics.add(m);
48
50
  }
49
51
  /**
50
52
  * Extends the context scanners with a new context scanner.
@@ -55,11 +57,54 @@ var Illuma = class _Illuma {
55
57
  static extendContextScanner(scanner) {
56
58
  _Illuma._scanners.push(scanner);
57
59
  }
60
+ /**
61
+ * Registers a global middleware to be applied during instance creation.
62
+ * Typically used for cross-cutting concerns like logging, profiling, or custom instantiation logic.
63
+ * Function should accept instantiation parameters and a `next` function to proceed with the next middleware or actual instantiation.
64
+ *
65
+ * @param m - The middleware function to register
66
+ */
67
+ static registerGlobalMiddleware(m) {
68
+ _Illuma._middlewares.push(m);
69
+ }
70
+ middlewares = [];
71
+ registerMiddleware(m) {
72
+ this.middlewares.push(m);
73
+ }
58
74
  static onReport(report) {
59
75
  for (const diag of _Illuma._diagnostics) diag.onReport(report);
60
76
  }
77
+ /**
78
+ * @internal
79
+ * Check if diagnostics modules are registered
80
+ */
81
+ static hasDiagnostics() {
82
+ return _Illuma._diagnostics.size > 0;
83
+ }
84
+ /**
85
+ * @internal
86
+ * Reset all plugin registrations
87
+ */
88
+ static __resetPlugins() {
89
+ _Illuma._diagnostics.clear();
90
+ _Illuma._scanners.length = 0;
91
+ _Illuma._middlewares.length = 0;
92
+ }
61
93
  };
62
94
 
95
+ // src/lib/plugins/middlewares/diagnostics.middleware.ts
96
+ var performanceDiagnostics = /* @__PURE__ */ __name((params, next) => {
97
+ if (!params.deps.size) {
98
+ return next(params);
99
+ }
100
+ const start = performance.now();
101
+ const instance = next(params);
102
+ const end = performance.now();
103
+ const duration = end - start;
104
+ console.log(`Instantiated ${params.token.name} in ${duration.toFixed(2)} ms`);
105
+ return instance;
106
+ }, "performanceDiagnostics");
107
+
63
108
  // src/lib/plugins/diagnostics/default-impl.ts
64
109
  var DiagnosticsDefaultReporter = class {
65
110
  static {
@@ -72,9 +117,22 @@ var DiagnosticsDefaultReporter = class {
72
117
  for (const node of report.unusedNodes) console.log(` - ${node.toString()}`);
73
118
  }
74
119
  };
120
+
121
+ // src/lib/plugins/diagnostics/built-in.ts
122
+ var state = {
123
+ enabled: false
124
+ };
125
+ function enableIllumaDiagnostics() {
126
+ if (state.enabled) return;
127
+ state.enabled = true;
128
+ Illuma.extendDiagnostics(new DiagnosticsDefaultReporter());
129
+ Illuma.registerGlobalMiddleware(performanceDiagnostics);
130
+ }
131
+ __name(enableIllumaDiagnostics, "enableIllumaDiagnostics");
75
132
  // Annotate the CommonJS export names for ESM import in node:
76
133
  0 && (module.exports = {
77
134
  DiagnosticsDefaultReporter,
78
- Illuma
135
+ Illuma,
136
+ enableIllumaDiagnostics
79
137
  });
80
138
  //# sourceMappingURL=plugins.cjs.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/plugins.ts","../src/lib/plugins/core/plugin-container.ts","../src/lib/plugins/diagnostics/default-impl.ts"],"sourcesContent":["export * from \"./lib/plugins\";\n","import type { iContextScanner } from \"../context\";\nimport type { iDiagnosticsModule, iDiagnosticsReport } from \"../diagnostics/types\";\n\n/**\n * Global plugin container for managing core plugins such as diagnostics and context scanners.\n */\nexport abstract class Illuma {\n private static readonly _diagnostics = [] as iDiagnosticsModule[];\n private static readonly _scanners = [] as iContextScanner[];\n\n /** @internal */\n public static get contextScanners(): ReadonlyArray<iContextScanner> {\n return Illuma._scanners;\n }\n\n /**\n * Extends the diagnostics with a new diagnostics module.\n * These will be run on diagnostics reports after container bootstrap.\n *\n * @param m - The diagnostics module instance to add\n */\n public static extendDiagnostics(m: iDiagnosticsModule): void {\n Illuma._diagnostics.push(m);\n }\n\n /**\n * Extends the context scanners with a new context scanner.\n * These will be run in injection context scans to detect additional injections (alongside `nodeInject` calls).\n *\n * @param scanner - The context scanner instance to add\n */\n public static extendContextScanner(scanner: iContextScanner): void {\n Illuma._scanners.push(scanner);\n }\n\n protected static onReport(report: iDiagnosticsReport): void {\n for (const diag of Illuma._diagnostics) diag.onReport(report);\n }\n}\n","import type { iDiagnosticsModule, iDiagnosticsReport } from \"./types\";\n\nexport class DiagnosticsDefaultReporter implements iDiagnosticsModule {\n public onReport(report: iDiagnosticsReport): void {\n console.log(\"[Illuma] 🧹 Diagnostics:\");\n console.log(` Total: ${report.totalNodes} node(s)`);\n console.log(` ${report.unusedNodes.length} were not used while bootstrap:`);\n for (const node of report.unusedNodes) console.log(` - ${node.toString()}`);\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;AAAA;;;;;;;;ACMO,IAAeA,SAAf,MAAeA,QAAAA;EAHtB,OAGsBA;;;EACpB,OAAwBC,eAAe,CAAA;EACvC,OAAwBC,YAAY,CAAA;;EAGpC,WAAkBC,kBAAkD;AAClE,WAAOH,QAAOE;EAChB;;;;;;;EAQA,OAAcE,kBAAkBC,GAA6B;AAC3DL,YAAOC,aAAaK,KAAKD,CAAAA;EAC3B;;;;;;;EAQA,OAAcE,qBAAqBC,SAAgC;AACjER,YAAOE,UAAUI,KAAKE,OAAAA;EACxB;EAEA,OAAiBC,SAASC,QAAkC;AAC1D,eAAWC,QAAQX,QAAOC,aAAcU,MAAKF,SAASC,MAAAA;EACxD;AACF;;;ACpCO,IAAME,6BAAN,MAAMA;EAAb,OAAaA;;;EACJC,SAASC,QAAkC;AAChDC,YAAQC,IAAI,iCAAA;AACZD,YAAQC,IAAI,YAAYF,OAAOG,UAAU,UAAU;AACnDF,YAAQC,IAAI,KAAKF,OAAOI,YAAYC,MAAM,iCAAiC;AAC3E,eAAWC,QAAQN,OAAOI,YAAaH,SAAQC,IAAI,SAASI,KAAKC,SAAQ,CAAA,EAAI;EAC/E;AACF;","names":["Illuma","_diagnostics","_scanners","contextScanners","extendDiagnostics","m","push","extendContextScanner","scanner","onReport","report","diag","DiagnosticsDefaultReporter","onReport","report","console","log","totalNodes","unusedNodes","length","node","toString"]}
1
+ {"version":3,"sources":["../src/plugins.ts","../src/lib/plugins/core/plugin-container.ts","../src/lib/plugins/middlewares/diagnostics.middleware.ts","../src/lib/plugins/diagnostics/default-impl.ts","../src/lib/plugins/diagnostics/built-in.ts"],"sourcesContent":["export * from \"./lib/plugins\";\n","import type { iContextScanner } from \"../context\";\nimport type { iDiagnosticsModule, iDiagnosticsReport } from \"../diagnostics/types\";\nimport type { iMiddleware } from \"../middlewares/types\";\n\n/**\n * Global plugin container for managing core plugins such as diagnostics and context scanners.\n */\nexport abstract class Illuma {\n private static readonly _diagnostics = new Set<iDiagnosticsModule>();\n private static readonly _scanners = [] as iContextScanner[];\n protected static readonly _middlewares = [] as iMiddleware[];\n\n /** @internal */\n public static get contextScanners(): ReadonlyArray<iContextScanner> {\n return Illuma._scanners;\n }\n\n /**\n * Extends the diagnostics with a new diagnostics module.\n * These will be run on diagnostics reports after container bootstrap.\n *\n * @param m - The diagnostics module instance to add\n */\n public static extendDiagnostics(m: iDiagnosticsModule): void {\n Illuma._diagnostics.add(m);\n }\n\n /**\n * Extends the context scanners with a new context scanner.\n * These will be run in injection context scans to detect additional injections (alongside `nodeInject` calls).\n *\n * @param scanner - The context scanner instance to add\n */\n public static extendContextScanner(scanner: iContextScanner): void {\n Illuma._scanners.push(scanner);\n }\n\n /**\n * Registers a global middleware to be applied during instance creation.\n * Typically used for cross-cutting concerns like logging, profiling, or custom instantiation logic.\n * Function should accept instantiation parameters and a `next` function to proceed with the next middleware or actual instantiation.\n *\n * @param m - The middleware function to register\n */\n public static registerGlobalMiddleware(m: iMiddleware): void {\n Illuma._middlewares.push(m);\n }\n\n protected readonly middlewares = [] as iMiddleware[];\n public registerMiddleware(m: iMiddleware): void {\n this.middlewares.push(m);\n }\n\n protected static onReport(report: iDiagnosticsReport): void {\n for (const diag of Illuma._diagnostics) diag.onReport(report);\n }\n\n /**\n * @internal\n * Check if diagnostics modules are registered\n */\n protected static hasDiagnostics(): boolean {\n return Illuma._diagnostics.size > 0;\n }\n\n /**\n * @internal\n * Reset all plugin registrations\n */\n protected static __resetPlugins(): void {\n Illuma._diagnostics.clear();\n Illuma._scanners.length = 0;\n Illuma._middlewares.length = 0;\n }\n}\n","import type { iMiddleware } from \"./types\";\n\nexport const performanceDiagnostics: iMiddleware = (params, next) => {\n if (!params.deps.size) {\n return next(params);\n }\n\n const start = performance.now();\n const instance = next(params);\n const end = performance.now();\n const duration = end - start;\n\n console.log(`Instantiated ${params.token.name} in ${duration.toFixed(2)} ms`);\n return instance;\n};\n","import type { iDiagnosticsModule, iDiagnosticsReport } from \"./types\";\n\nexport class DiagnosticsDefaultReporter implements iDiagnosticsModule {\n public onReport(report: iDiagnosticsReport): void {\n console.log(\"[Illuma] 🧹 Diagnostics:\");\n console.log(` Total: ${report.totalNodes} node(s)`);\n console.log(` ${report.unusedNodes.length} were not used while bootstrap:`);\n for (const node of report.unusedNodes) console.log(` - ${node.toString()}`);\n }\n}\n","import { Illuma } from \"../core\";\nimport { performanceDiagnostics } from \"../middlewares/diagnostics.middleware\";\nimport { DiagnosticsDefaultReporter } from \"./default-impl\";\n\nconst state = { enabled: false };\n\nexport function enableIllumaDiagnostics() {\n if (state.enabled) return;\n state.enabled = true;\n\n Illuma.extendDiagnostics(new DiagnosticsDefaultReporter());\n Illuma.registerGlobalMiddleware(performanceDiagnostics);\n}\n\n/**\n * @internal\n * Reset diagnostics state (for testing only)\n */\nexport function __resetDiagnosticsState() {\n state.enabled = false;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;AAAA;;;;;;;;;ACOO,IAAeA,SAAf,MAAeA,QAAAA;EAHtB,OAGsBA;;;EACpB,OAAwBC,eAAe,oBAAIC,IAAAA;EAC3C,OAAwBC,YAAY,CAAA;EACpC,OAA0BC,eAAe,CAAA;;EAGzC,WAAkBC,kBAAkD;AAClE,WAAOL,QAAOG;EAChB;;;;;;;EAQA,OAAcG,kBAAkBC,GAA6B;AAC3DP,YAAOC,aAAaO,IAAID,CAAAA;EAC1B;;;;;;;EAQA,OAAcE,qBAAqBC,SAAgC;AACjEV,YAAOG,UAAUQ,KAAKD,OAAAA;EACxB;;;;;;;;EASA,OAAcE,yBAAyBL,GAAsB;AAC3DP,YAAOI,aAAaO,KAAKJ,CAAAA;EAC3B;EAEmBM,cAAc,CAAA;EAC1BC,mBAAmBP,GAAsB;AAC9C,SAAKM,YAAYF,KAAKJ,CAAAA;EACxB;EAEA,OAAiBQ,SAASC,QAAkC;AAC1D,eAAWC,QAAQjB,QAAOC,aAAcgB,MAAKF,SAASC,MAAAA;EACxD;;;;;EAMA,OAAiBE,iBAA0B;AACzC,WAAOlB,QAAOC,aAAakB,OAAO;EACpC;;;;;EAMA,OAAiBC,iBAAuB;AACtCpB,YAAOC,aAAaoB,MAAK;AACzBrB,YAAOG,UAAUmB,SAAS;AAC1BtB,YAAOI,aAAakB,SAAS;EAC/B;AACF;;;ACxEO,IAAMC,yBAAsC,wBAACC,QAAQC,SAAAA;AAC1D,MAAI,CAACD,OAAOE,KAAKC,MAAM;AACrB,WAAOF,KAAKD,MAAAA;EACd;AAEA,QAAMI,QAAQC,YAAYC,IAAG;AAC7B,QAAMC,WAAWN,KAAKD,MAAAA;AACtB,QAAMQ,MAAMH,YAAYC,IAAG;AAC3B,QAAMG,WAAWD,MAAMJ;AAEvBM,UAAQC,IAAI,gBAAgBX,OAAOY,MAAMC,IAAI,OAAOJ,SAASK,QAAQ,CAAA,CAAA,KAAO;AAC5E,SAAOP;AACT,GAZmD;;;ACA5C,IAAMQ,6BAAN,MAAMA;EAAb,OAAaA;;;EACJC,SAASC,QAAkC;AAChDC,YAAQC,IAAI,iCAAA;AACZD,YAAQC,IAAI,YAAYF,OAAOG,UAAU,UAAU;AACnDF,YAAQC,IAAI,KAAKF,OAAOI,YAAYC,MAAM,iCAAiC;AAC3E,eAAWC,QAAQN,OAAOI,YAAaH,SAAQC,IAAI,SAASI,KAAKC,SAAQ,CAAA,EAAI;EAC/E;AACF;;;ACLA,IAAMC,QAAQ;EAAEC,SAAS;AAAM;AAExB,SAASC,0BAAAA;AACd,MAAIF,MAAMC,QAAS;AACnBD,QAAMC,UAAU;AAEhBE,SAAOC,kBAAkB,IAAIC,2BAAAA,CAAAA;AAC7BF,SAAOG,yBAAyBC,sBAAAA;AAClC;AANgBL;","names":["Illuma","_diagnostics","Set","_scanners","_middlewares","contextScanners","extendDiagnostics","m","add","extendContextScanner","scanner","push","registerGlobalMiddleware","middlewares","registerMiddleware","onReport","report","diag","hasDiagnostics","size","__resetPlugins","clear","length","performanceDiagnostics","params","next","deps","size","start","performance","now","instance","end","duration","console","log","token","name","toFixed","DiagnosticsDefaultReporter","onReport","report","console","log","totalNodes","unusedNodes","length","node","toString","state","enabled","enableIllumaDiagnostics","Illuma","extendDiagnostics","DiagnosticsDefaultReporter","registerGlobalMiddleware","performanceDiagnostics"]}
@@ -1,9 +1,11 @@
1
- import { a as iDiagnosticsModule, b as iDiagnosticsReport } from './plugin-container-CSWXa9hU.cjs';
2
- export { I as Illuma, c as iContextScanner } from './plugin-container-CSWXa9hU.cjs';
1
+ import { b as iDiagnosticsModule, c as iDiagnosticsReport } from './plugin-container-OWBUHjSf.cjs';
2
+ export { I as Illuma, d as iContextScanner, e as iInstantiationParams, i as iMiddleware } from './plugin-container-OWBUHjSf.cjs';
3
3
  import './types-zryyqrii.cjs';
4
4
 
5
+ declare function enableIllumaDiagnostics(): void;
6
+
5
7
  declare class DiagnosticsDefaultReporter implements iDiagnosticsModule {
6
8
  onReport(report: iDiagnosticsReport): void;
7
9
  }
8
10
 
9
- export { DiagnosticsDefaultReporter, iDiagnosticsModule, iDiagnosticsReport };
11
+ export { DiagnosticsDefaultReporter, enableIllumaDiagnostics, iDiagnosticsModule, iDiagnosticsReport };
package/dist/plugins.d.ts CHANGED
@@ -1,9 +1,11 @@
1
- import { a as iDiagnosticsModule, b as iDiagnosticsReport } from './plugin-container-jg0-7wgh.js';
2
- export { I as Illuma, c as iContextScanner } from './plugin-container-jg0-7wgh.js';
1
+ import { b as iDiagnosticsModule, c as iDiagnosticsReport } from './plugin-container-DZj4vSLu.js';
2
+ export { I as Illuma, d as iContextScanner, e as iInstantiationParams, i as iMiddleware } from './plugin-container-DZj4vSLu.js';
3
3
  import './types-zryyqrii.js';
4
4
 
5
+ declare function enableIllumaDiagnostics(): void;
6
+
5
7
  declare class DiagnosticsDefaultReporter implements iDiagnosticsModule {
6
8
  onReport(report: iDiagnosticsReport): void;
7
9
  }
8
10
 
9
- export { DiagnosticsDefaultReporter, iDiagnosticsModule, iDiagnosticsReport };
11
+ export { DiagnosticsDefaultReporter, enableIllumaDiagnostics, iDiagnosticsModule, iDiagnosticsReport };
package/dist/plugins.js CHANGED
@@ -6,8 +6,9 @@ var Illuma = class _Illuma {
6
6
  static {
7
7
  __name(this, "Illuma");
8
8
  }
9
- static _diagnostics = [];
9
+ static _diagnostics = /* @__PURE__ */ new Set();
10
10
  static _scanners = [];
11
+ static _middlewares = [];
11
12
  /** @internal */
12
13
  static get contextScanners() {
13
14
  return _Illuma._scanners;
@@ -19,7 +20,7 @@ var Illuma = class _Illuma {
19
20
  * @param m - The diagnostics module instance to add
20
21
  */
21
22
  static extendDiagnostics(m) {
22
- _Illuma._diagnostics.push(m);
23
+ _Illuma._diagnostics.add(m);
23
24
  }
24
25
  /**
25
26
  * Extends the context scanners with a new context scanner.
@@ -30,11 +31,54 @@ var Illuma = class _Illuma {
30
31
  static extendContextScanner(scanner) {
31
32
  _Illuma._scanners.push(scanner);
32
33
  }
34
+ /**
35
+ * Registers a global middleware to be applied during instance creation.
36
+ * Typically used for cross-cutting concerns like logging, profiling, or custom instantiation logic.
37
+ * Function should accept instantiation parameters and a `next` function to proceed with the next middleware or actual instantiation.
38
+ *
39
+ * @param m - The middleware function to register
40
+ */
41
+ static registerGlobalMiddleware(m) {
42
+ _Illuma._middlewares.push(m);
43
+ }
44
+ middlewares = [];
45
+ registerMiddleware(m) {
46
+ this.middlewares.push(m);
47
+ }
33
48
  static onReport(report) {
34
49
  for (const diag of _Illuma._diagnostics) diag.onReport(report);
35
50
  }
51
+ /**
52
+ * @internal
53
+ * Check if diagnostics modules are registered
54
+ */
55
+ static hasDiagnostics() {
56
+ return _Illuma._diagnostics.size > 0;
57
+ }
58
+ /**
59
+ * @internal
60
+ * Reset all plugin registrations
61
+ */
62
+ static __resetPlugins() {
63
+ _Illuma._diagnostics.clear();
64
+ _Illuma._scanners.length = 0;
65
+ _Illuma._middlewares.length = 0;
66
+ }
36
67
  };
37
68
 
69
+ // src/lib/plugins/middlewares/diagnostics.middleware.ts
70
+ var performanceDiagnostics = /* @__PURE__ */ __name((params, next) => {
71
+ if (!params.deps.size) {
72
+ return next(params);
73
+ }
74
+ const start = performance.now();
75
+ const instance = next(params);
76
+ const end = performance.now();
77
+ const duration = end - start;
78
+ console.log(`Instantiated ${params.token.name} in ${duration.toFixed(2)} ms`);
79
+ return instance;
80
+ }, "performanceDiagnostics");
81
+
38
82
  // src/lib/plugins/diagnostics/default-impl.ts
39
83
  var DiagnosticsDefaultReporter = class {
40
84
  static {
@@ -47,8 +91,21 @@ var DiagnosticsDefaultReporter = class {
47
91
  for (const node of report.unusedNodes) console.log(` - ${node.toString()}`);
48
92
  }
49
93
  };
94
+
95
+ // src/lib/plugins/diagnostics/built-in.ts
96
+ var state = {
97
+ enabled: false
98
+ };
99
+ function enableIllumaDiagnostics() {
100
+ if (state.enabled) return;
101
+ state.enabled = true;
102
+ Illuma.extendDiagnostics(new DiagnosticsDefaultReporter());
103
+ Illuma.registerGlobalMiddleware(performanceDiagnostics);
104
+ }
105
+ __name(enableIllumaDiagnostics, "enableIllumaDiagnostics");
50
106
  export {
51
107
  DiagnosticsDefaultReporter,
52
- Illuma
108
+ Illuma,
109
+ enableIllumaDiagnostics
53
110
  };
54
111
  //# sourceMappingURL=plugins.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/lib/plugins/core/plugin-container.ts","../src/lib/plugins/diagnostics/default-impl.ts"],"sourcesContent":["import type { iContextScanner } from \"../context\";\nimport type { iDiagnosticsModule, iDiagnosticsReport } from \"../diagnostics/types\";\n\n/**\n * Global plugin container for managing core plugins such as diagnostics and context scanners.\n */\nexport abstract class Illuma {\n private static readonly _diagnostics = [] as iDiagnosticsModule[];\n private static readonly _scanners = [] as iContextScanner[];\n\n /** @internal */\n public static get contextScanners(): ReadonlyArray<iContextScanner> {\n return Illuma._scanners;\n }\n\n /**\n * Extends the diagnostics with a new diagnostics module.\n * These will be run on diagnostics reports after container bootstrap.\n *\n * @param m - The diagnostics module instance to add\n */\n public static extendDiagnostics(m: iDiagnosticsModule): void {\n Illuma._diagnostics.push(m);\n }\n\n /**\n * Extends the context scanners with a new context scanner.\n * These will be run in injection context scans to detect additional injections (alongside `nodeInject` calls).\n *\n * @param scanner - The context scanner instance to add\n */\n public static extendContextScanner(scanner: iContextScanner): void {\n Illuma._scanners.push(scanner);\n }\n\n protected static onReport(report: iDiagnosticsReport): void {\n for (const diag of Illuma._diagnostics) diag.onReport(report);\n }\n}\n","import type { iDiagnosticsModule, iDiagnosticsReport } from \"./types\";\n\nexport class DiagnosticsDefaultReporter implements iDiagnosticsModule {\n public onReport(report: iDiagnosticsReport): void {\n console.log(\"[Illuma] 🧹 Diagnostics:\");\n console.log(` Total: ${report.totalNodes} node(s)`);\n console.log(` ${report.unusedNodes.length} were not used while bootstrap:`);\n for (const node of report.unusedNodes) console.log(` - ${node.toString()}`);\n }\n}\n"],"mappings":";;;;AAMO,IAAeA,SAAf,MAAeA,QAAAA;EAHtB,OAGsBA;;;EACpB,OAAwBC,eAAe,CAAA;EACvC,OAAwBC,YAAY,CAAA;;EAGpC,WAAkBC,kBAAkD;AAClE,WAAOH,QAAOE;EAChB;;;;;;;EAQA,OAAcE,kBAAkBC,GAA6B;AAC3DL,YAAOC,aAAaK,KAAKD,CAAAA;EAC3B;;;;;;;EAQA,OAAcE,qBAAqBC,SAAgC;AACjER,YAAOE,UAAUI,KAAKE,OAAAA;EACxB;EAEA,OAAiBC,SAASC,QAAkC;AAC1D,eAAWC,QAAQX,QAAOC,aAAcU,MAAKF,SAASC,MAAAA;EACxD;AACF;;;ACpCO,IAAME,6BAAN,MAAMA;EAAb,OAAaA;;;EACJC,SAASC,QAAkC;AAChDC,YAAQC,IAAI,iCAAA;AACZD,YAAQC,IAAI,YAAYF,OAAOG,UAAU,UAAU;AACnDF,YAAQC,IAAI,KAAKF,OAAOI,YAAYC,MAAM,iCAAiC;AAC3E,eAAWC,QAAQN,OAAOI,YAAaH,SAAQC,IAAI,SAASI,KAAKC,SAAQ,CAAA,EAAI;EAC/E;AACF;","names":["Illuma","_diagnostics","_scanners","contextScanners","extendDiagnostics","m","push","extendContextScanner","scanner","onReport","report","diag","DiagnosticsDefaultReporter","onReport","report","console","log","totalNodes","unusedNodes","length","node","toString"]}
1
+ {"version":3,"sources":["../src/lib/plugins/core/plugin-container.ts","../src/lib/plugins/middlewares/diagnostics.middleware.ts","../src/lib/plugins/diagnostics/default-impl.ts","../src/lib/plugins/diagnostics/built-in.ts"],"sourcesContent":["import type { iContextScanner } from \"../context\";\nimport type { iDiagnosticsModule, iDiagnosticsReport } from \"../diagnostics/types\";\nimport type { iMiddleware } from \"../middlewares/types\";\n\n/**\n * Global plugin container for managing core plugins such as diagnostics and context scanners.\n */\nexport abstract class Illuma {\n private static readonly _diagnostics = new Set<iDiagnosticsModule>();\n private static readonly _scanners = [] as iContextScanner[];\n protected static readonly _middlewares = [] as iMiddleware[];\n\n /** @internal */\n public static get contextScanners(): ReadonlyArray<iContextScanner> {\n return Illuma._scanners;\n }\n\n /**\n * Extends the diagnostics with a new diagnostics module.\n * These will be run on diagnostics reports after container bootstrap.\n *\n * @param m - The diagnostics module instance to add\n */\n public static extendDiagnostics(m: iDiagnosticsModule): void {\n Illuma._diagnostics.add(m);\n }\n\n /**\n * Extends the context scanners with a new context scanner.\n * These will be run in injection context scans to detect additional injections (alongside `nodeInject` calls).\n *\n * @param scanner - The context scanner instance to add\n */\n public static extendContextScanner(scanner: iContextScanner): void {\n Illuma._scanners.push(scanner);\n }\n\n /**\n * Registers a global middleware to be applied during instance creation.\n * Typically used for cross-cutting concerns like logging, profiling, or custom instantiation logic.\n * Function should accept instantiation parameters and a `next` function to proceed with the next middleware or actual instantiation.\n *\n * @param m - The middleware function to register\n */\n public static registerGlobalMiddleware(m: iMiddleware): void {\n Illuma._middlewares.push(m);\n }\n\n protected readonly middlewares = [] as iMiddleware[];\n public registerMiddleware(m: iMiddleware): void {\n this.middlewares.push(m);\n }\n\n protected static onReport(report: iDiagnosticsReport): void {\n for (const diag of Illuma._diagnostics) diag.onReport(report);\n }\n\n /**\n * @internal\n * Check if diagnostics modules are registered\n */\n protected static hasDiagnostics(): boolean {\n return Illuma._diagnostics.size > 0;\n }\n\n /**\n * @internal\n * Reset all plugin registrations\n */\n protected static __resetPlugins(): void {\n Illuma._diagnostics.clear();\n Illuma._scanners.length = 0;\n Illuma._middlewares.length = 0;\n }\n}\n","import type { iMiddleware } from \"./types\";\n\nexport const performanceDiagnostics: iMiddleware = (params, next) => {\n if (!params.deps.size) {\n return next(params);\n }\n\n const start = performance.now();\n const instance = next(params);\n const end = performance.now();\n const duration = end - start;\n\n console.log(`Instantiated ${params.token.name} in ${duration.toFixed(2)} ms`);\n return instance;\n};\n","import type { iDiagnosticsModule, iDiagnosticsReport } from \"./types\";\n\nexport class DiagnosticsDefaultReporter implements iDiagnosticsModule {\n public onReport(report: iDiagnosticsReport): void {\n console.log(\"[Illuma] 🧹 Diagnostics:\");\n console.log(` Total: ${report.totalNodes} node(s)`);\n console.log(` ${report.unusedNodes.length} were not used while bootstrap:`);\n for (const node of report.unusedNodes) console.log(` - ${node.toString()}`);\n }\n}\n","import { Illuma } from \"../core\";\nimport { performanceDiagnostics } from \"../middlewares/diagnostics.middleware\";\nimport { DiagnosticsDefaultReporter } from \"./default-impl\";\n\nconst state = { enabled: false };\n\nexport function enableIllumaDiagnostics() {\n if (state.enabled) return;\n state.enabled = true;\n\n Illuma.extendDiagnostics(new DiagnosticsDefaultReporter());\n Illuma.registerGlobalMiddleware(performanceDiagnostics);\n}\n\n/**\n * @internal\n * Reset diagnostics state (for testing only)\n */\nexport function __resetDiagnosticsState() {\n state.enabled = false;\n}\n"],"mappings":";;;;AAOO,IAAeA,SAAf,MAAeA,QAAAA;EAHtB,OAGsBA;;;EACpB,OAAwBC,eAAe,oBAAIC,IAAAA;EAC3C,OAAwBC,YAAY,CAAA;EACpC,OAA0BC,eAAe,CAAA;;EAGzC,WAAkBC,kBAAkD;AAClE,WAAOL,QAAOG;EAChB;;;;;;;EAQA,OAAcG,kBAAkBC,GAA6B;AAC3DP,YAAOC,aAAaO,IAAID,CAAAA;EAC1B;;;;;;;EAQA,OAAcE,qBAAqBC,SAAgC;AACjEV,YAAOG,UAAUQ,KAAKD,OAAAA;EACxB;;;;;;;;EASA,OAAcE,yBAAyBL,GAAsB;AAC3DP,YAAOI,aAAaO,KAAKJ,CAAAA;EAC3B;EAEmBM,cAAc,CAAA;EAC1BC,mBAAmBP,GAAsB;AAC9C,SAAKM,YAAYF,KAAKJ,CAAAA;EACxB;EAEA,OAAiBQ,SAASC,QAAkC;AAC1D,eAAWC,QAAQjB,QAAOC,aAAcgB,MAAKF,SAASC,MAAAA;EACxD;;;;;EAMA,OAAiBE,iBAA0B;AACzC,WAAOlB,QAAOC,aAAakB,OAAO;EACpC;;;;;EAMA,OAAiBC,iBAAuB;AACtCpB,YAAOC,aAAaoB,MAAK;AACzBrB,YAAOG,UAAUmB,SAAS;AAC1BtB,YAAOI,aAAakB,SAAS;EAC/B;AACF;;;ACxEO,IAAMC,yBAAsC,wBAACC,QAAQC,SAAAA;AAC1D,MAAI,CAACD,OAAOE,KAAKC,MAAM;AACrB,WAAOF,KAAKD,MAAAA;EACd;AAEA,QAAMI,QAAQC,YAAYC,IAAG;AAC7B,QAAMC,WAAWN,KAAKD,MAAAA;AACtB,QAAMQ,MAAMH,YAAYC,IAAG;AAC3B,QAAMG,WAAWD,MAAMJ;AAEvBM,UAAQC,IAAI,gBAAgBX,OAAOY,MAAMC,IAAI,OAAOJ,SAASK,QAAQ,CAAA,CAAA,KAAO;AAC5E,SAAOP;AACT,GAZmD;;;ACA5C,IAAMQ,6BAAN,MAAMA;EAAb,OAAaA;;;EACJC,SAASC,QAAkC;AAChDC,YAAQC,IAAI,iCAAA;AACZD,YAAQC,IAAI,YAAYF,OAAOG,UAAU,UAAU;AACnDF,YAAQC,IAAI,KAAKF,OAAOI,YAAYC,MAAM,iCAAiC;AAC3E,eAAWC,QAAQN,OAAOI,YAAaH,SAAQC,IAAI,SAASI,KAAKC,SAAQ,CAAA,EAAI;EAC/E;AACF;;;ACLA,IAAMC,QAAQ;EAAEC,SAAS;AAAM;AAExB,SAASC,0BAAAA;AACd,MAAIF,MAAMC,QAAS;AACnBD,QAAMC,UAAU;AAEhBE,SAAOC,kBAAkB,IAAIC,2BAAAA,CAAAA;AAC7BF,SAAOG,yBAAyBC,sBAAAA;AAClC;AANgBL;","names":["Illuma","_diagnostics","Set","_scanners","_middlewares","contextScanners","extendDiagnostics","m","add","extendContextScanner","scanner","push","registerGlobalMiddleware","middlewares","registerMiddleware","onReport","report","diag","hasDiagnostics","size","__resetPlugins","clear","length","performanceDiagnostics","params","next","deps","size","start","performance","now","instance","end","duration","console","log","token","name","toFixed","DiagnosticsDefaultReporter","onReport","report","console","log","totalNodes","unusedNodes","length","node","toString","state","enabled","enableIllumaDiagnostics","Illuma","extendDiagnostics","DiagnosticsDefaultReporter","registerGlobalMiddleware","performanceDiagnostics"]}