@illuma/core 1.4.0 → 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.
- package/CHANGELOG.md +2 -0
- package/README.md +3 -3
- package/dist/index.cjs +169 -66
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +5 -3
- package/dist/index.d.ts +5 -3
- package/dist/index.js +185 -66
- package/dist/index.js.map +1 -1
- package/dist/{plugin-container-CG_kjb35.d.ts → plugin-container-DZj4vSLu.d.ts} +12 -1
- package/dist/{plugin-container-CXuie89o.d.cts → plugin-container-OWBUHjSf.d.cts} +12 -1
- package/dist/plugins.cjs +47 -4
- package/dist/plugins.cjs.map +1 -1
- package/dist/plugins.d.cts +5 -3
- package/dist/plugins.d.ts +5 -3
- package/dist/plugins.js +45 -3
- package/dist/plugins.js.map +1 -1
- package/dist/testkit.cjs +169 -66
- package/dist/testkit.cjs.map +1 -1
- package/dist/testkit.js +185 -66
- package/dist/testkit.js.map +1 -1
- package/package.json +1 -1
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,7 +32,7 @@ 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 = [];
|
|
36
37
|
static _middlewares = [];
|
|
37
38
|
/** @internal */
|
|
@@ -45,7 +46,7 @@ var Illuma = class _Illuma {
|
|
|
45
46
|
* @param m - The diagnostics module instance to add
|
|
46
47
|
*/
|
|
47
48
|
static extendDiagnostics(m) {
|
|
48
|
-
_Illuma._diagnostics.
|
|
49
|
+
_Illuma._diagnostics.add(m);
|
|
49
50
|
}
|
|
50
51
|
/**
|
|
51
52
|
* Extends the context scanners with a new context scanner.
|
|
@@ -73,8 +74,37 @@ var Illuma = class _Illuma {
|
|
|
73
74
|
static onReport(report) {
|
|
74
75
|
for (const diag of _Illuma._diagnostics) diag.onReport(report);
|
|
75
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
|
+
}
|
|
76
93
|
};
|
|
77
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
|
+
|
|
78
108
|
// src/lib/plugins/diagnostics/default-impl.ts
|
|
79
109
|
var DiagnosticsDefaultReporter = class {
|
|
80
110
|
static {
|
|
@@ -87,9 +117,22 @@ var DiagnosticsDefaultReporter = class {
|
|
|
87
117
|
for (const node of report.unusedNodes) console.log(` - ${node.toString()}`);
|
|
88
118
|
}
|
|
89
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");
|
|
90
132
|
// Annotate the CommonJS export names for ESM import in node:
|
|
91
133
|
0 && (module.exports = {
|
|
92
134
|
DiagnosticsDefaultReporter,
|
|
93
|
-
Illuma
|
|
135
|
+
Illuma,
|
|
136
|
+
enableIllumaDiagnostics
|
|
94
137
|
});
|
|
95
138
|
//# sourceMappingURL=plugins.cjs.map
|
package/dist/plugins.cjs.map
CHANGED
|
@@ -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\";\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 =
|
|
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;AAC9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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"]}
|
package/dist/plugins.d.cts
CHANGED
|
@@ -1,9 +1,11 @@
|
|
|
1
|
-
import { b as iDiagnosticsModule, c as iDiagnosticsReport } from './plugin-container-
|
|
2
|
-
export { I as Illuma, d as iContextScanner, e as iInstantiationParams, i as iMiddleware } from './plugin-container-
|
|
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 { b as iDiagnosticsModule, c as iDiagnosticsReport } from './plugin-container-
|
|
2
|
-
export { I as Illuma, d as iContextScanner, e as iInstantiationParams, i as iMiddleware } from './plugin-container-
|
|
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,7 +6,7 @@ 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
11
|
static _middlewares = [];
|
|
12
12
|
/** @internal */
|
|
@@ -20,7 +20,7 @@ var Illuma = class _Illuma {
|
|
|
20
20
|
* @param m - The diagnostics module instance to add
|
|
21
21
|
*/
|
|
22
22
|
static extendDiagnostics(m) {
|
|
23
|
-
_Illuma._diagnostics.
|
|
23
|
+
_Illuma._diagnostics.add(m);
|
|
24
24
|
}
|
|
25
25
|
/**
|
|
26
26
|
* Extends the context scanners with a new context scanner.
|
|
@@ -48,8 +48,37 @@ var Illuma = class _Illuma {
|
|
|
48
48
|
static onReport(report) {
|
|
49
49
|
for (const diag of _Illuma._diagnostics) diag.onReport(report);
|
|
50
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
|
+
}
|
|
51
67
|
};
|
|
52
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
|
+
|
|
53
82
|
// src/lib/plugins/diagnostics/default-impl.ts
|
|
54
83
|
var DiagnosticsDefaultReporter = class {
|
|
55
84
|
static {
|
|
@@ -62,8 +91,21 @@ var DiagnosticsDefaultReporter = class {
|
|
|
62
91
|
for (const node of report.unusedNodes) console.log(` - ${node.toString()}`);
|
|
63
92
|
}
|
|
64
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");
|
|
65
106
|
export {
|
|
66
107
|
DiagnosticsDefaultReporter,
|
|
67
|
-
Illuma
|
|
108
|
+
Illuma,
|
|
109
|
+
enableIllumaDiagnostics
|
|
68
110
|
};
|
|
69
111
|
//# sourceMappingURL=plugins.js.map
|
package/dist/plugins.js.map
CHANGED
|
@@ -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\";\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 =
|
|
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 =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BAAN,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"]}
|
package/dist/testkit.cjs
CHANGED
|
@@ -4,6 +4,9 @@ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
|
4
4
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
5
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
6
|
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
7
|
+
var __esm = (fn, res) => function __init() {
|
|
8
|
+
return fn && (res = (0, fn[__getOwnPropNames(fn)[0]])(fn = 0)), res;
|
|
9
|
+
};
|
|
7
10
|
var __export = (target, all) => {
|
|
8
11
|
for (var name in all)
|
|
9
12
|
__defProp(target, name, { get: all[name], enumerable: true });
|
|
@@ -18,6 +21,153 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
18
21
|
};
|
|
19
22
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
20
23
|
|
|
24
|
+
// src/lib/plugins/core/plugin-container.ts
|
|
25
|
+
var Illuma;
|
|
26
|
+
var init_plugin_container = __esm({
|
|
27
|
+
"src/lib/plugins/core/plugin-container.ts"() {
|
|
28
|
+
"use strict";
|
|
29
|
+
Illuma = class _Illuma {
|
|
30
|
+
static {
|
|
31
|
+
__name(this, "Illuma");
|
|
32
|
+
}
|
|
33
|
+
static _diagnostics = /* @__PURE__ */ new Set();
|
|
34
|
+
static _scanners = [];
|
|
35
|
+
static _middlewares = [];
|
|
36
|
+
/** @internal */
|
|
37
|
+
static get contextScanners() {
|
|
38
|
+
return _Illuma._scanners;
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Extends the diagnostics with a new diagnostics module.
|
|
42
|
+
* These will be run on diagnostics reports after container bootstrap.
|
|
43
|
+
*
|
|
44
|
+
* @param m - The diagnostics module instance to add
|
|
45
|
+
*/
|
|
46
|
+
static extendDiagnostics(m) {
|
|
47
|
+
_Illuma._diagnostics.add(m);
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Extends the context scanners with a new context scanner.
|
|
51
|
+
* These will be run in injection context scans to detect additional injections (alongside `nodeInject` calls).
|
|
52
|
+
*
|
|
53
|
+
* @param scanner - The context scanner instance to add
|
|
54
|
+
*/
|
|
55
|
+
static extendContextScanner(scanner) {
|
|
56
|
+
_Illuma._scanners.push(scanner);
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* Registers a global middleware to be applied during instance creation.
|
|
60
|
+
* Typically used for cross-cutting concerns like logging, profiling, or custom instantiation logic.
|
|
61
|
+
* Function should accept instantiation parameters and a `next` function to proceed with the next middleware or actual instantiation.
|
|
62
|
+
*
|
|
63
|
+
* @param m - The middleware function to register
|
|
64
|
+
*/
|
|
65
|
+
static registerGlobalMiddleware(m) {
|
|
66
|
+
_Illuma._middlewares.push(m);
|
|
67
|
+
}
|
|
68
|
+
middlewares = [];
|
|
69
|
+
registerMiddleware(m) {
|
|
70
|
+
this.middlewares.push(m);
|
|
71
|
+
}
|
|
72
|
+
static onReport(report) {
|
|
73
|
+
for (const diag of _Illuma._diagnostics) diag.onReport(report);
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* @internal
|
|
77
|
+
* Check if diagnostics modules are registered
|
|
78
|
+
*/
|
|
79
|
+
static hasDiagnostics() {
|
|
80
|
+
return _Illuma._diagnostics.size > 0;
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* @internal
|
|
84
|
+
* Reset all plugin registrations
|
|
85
|
+
*/
|
|
86
|
+
static __resetPlugins() {
|
|
87
|
+
_Illuma._diagnostics.clear();
|
|
88
|
+
_Illuma._scanners.length = 0;
|
|
89
|
+
_Illuma._middlewares.length = 0;
|
|
90
|
+
}
|
|
91
|
+
};
|
|
92
|
+
}
|
|
93
|
+
});
|
|
94
|
+
|
|
95
|
+
// src/lib/plugins/core/index.ts
|
|
96
|
+
var init_core = __esm({
|
|
97
|
+
"src/lib/plugins/core/index.ts"() {
|
|
98
|
+
"use strict";
|
|
99
|
+
init_plugin_container();
|
|
100
|
+
}
|
|
101
|
+
});
|
|
102
|
+
|
|
103
|
+
// src/lib/plugins/middlewares/diagnostics.middleware.ts
|
|
104
|
+
var performanceDiagnostics;
|
|
105
|
+
var init_diagnostics_middleware = __esm({
|
|
106
|
+
"src/lib/plugins/middlewares/diagnostics.middleware.ts"() {
|
|
107
|
+
"use strict";
|
|
108
|
+
performanceDiagnostics = /* @__PURE__ */ __name((params, next) => {
|
|
109
|
+
if (!params.deps.size) {
|
|
110
|
+
return next(params);
|
|
111
|
+
}
|
|
112
|
+
const start = performance.now();
|
|
113
|
+
const instance = next(params);
|
|
114
|
+
const end = performance.now();
|
|
115
|
+
const duration = end - start;
|
|
116
|
+
console.log(`Instantiated ${params.token.name} in ${duration.toFixed(2)} ms`);
|
|
117
|
+
return instance;
|
|
118
|
+
}, "performanceDiagnostics");
|
|
119
|
+
}
|
|
120
|
+
});
|
|
121
|
+
|
|
122
|
+
// src/lib/plugins/diagnostics/default-impl.ts
|
|
123
|
+
var DiagnosticsDefaultReporter;
|
|
124
|
+
var init_default_impl = __esm({
|
|
125
|
+
"src/lib/plugins/diagnostics/default-impl.ts"() {
|
|
126
|
+
"use strict";
|
|
127
|
+
DiagnosticsDefaultReporter = class {
|
|
128
|
+
static {
|
|
129
|
+
__name(this, "DiagnosticsDefaultReporter");
|
|
130
|
+
}
|
|
131
|
+
onReport(report) {
|
|
132
|
+
console.log("[Illuma] \u{1F9F9} Diagnostics:");
|
|
133
|
+
console.log(` Total: ${report.totalNodes} node(s)`);
|
|
134
|
+
console.log(` ${report.unusedNodes.length} were not used while bootstrap:`);
|
|
135
|
+
for (const node of report.unusedNodes) console.log(` - ${node.toString()}`);
|
|
136
|
+
}
|
|
137
|
+
};
|
|
138
|
+
}
|
|
139
|
+
});
|
|
140
|
+
|
|
141
|
+
// src/lib/plugins/diagnostics/built-in.ts
|
|
142
|
+
var built_in_exports = {};
|
|
143
|
+
__export(built_in_exports, {
|
|
144
|
+
__resetDiagnosticsState: () => __resetDiagnosticsState,
|
|
145
|
+
enableIllumaDiagnostics: () => enableIllumaDiagnostics
|
|
146
|
+
});
|
|
147
|
+
function enableIllumaDiagnostics() {
|
|
148
|
+
if (state.enabled) return;
|
|
149
|
+
state.enabled = true;
|
|
150
|
+
Illuma.extendDiagnostics(new DiagnosticsDefaultReporter());
|
|
151
|
+
Illuma.registerGlobalMiddleware(performanceDiagnostics);
|
|
152
|
+
}
|
|
153
|
+
function __resetDiagnosticsState() {
|
|
154
|
+
state.enabled = false;
|
|
155
|
+
}
|
|
156
|
+
var state;
|
|
157
|
+
var init_built_in = __esm({
|
|
158
|
+
"src/lib/plugins/diagnostics/built-in.ts"() {
|
|
159
|
+
"use strict";
|
|
160
|
+
init_core();
|
|
161
|
+
init_diagnostics_middleware();
|
|
162
|
+
init_default_impl();
|
|
163
|
+
state = {
|
|
164
|
+
enabled: false
|
|
165
|
+
};
|
|
166
|
+
__name(enableIllumaDiagnostics, "enableIllumaDiagnostics");
|
|
167
|
+
__name(__resetDiagnosticsState, "__resetDiagnosticsState");
|
|
168
|
+
}
|
|
169
|
+
});
|
|
170
|
+
|
|
21
171
|
// src/testkit.ts
|
|
22
172
|
var testkit_exports = {};
|
|
23
173
|
__export(testkit_exports, {
|
|
@@ -219,56 +369,8 @@ function isConstructor(fn) {
|
|
|
219
369
|
}
|
|
220
370
|
__name(isConstructor, "isConstructor");
|
|
221
371
|
|
|
222
|
-
// src/lib/plugins/core/plugin-container.ts
|
|
223
|
-
var Illuma = class _Illuma {
|
|
224
|
-
static {
|
|
225
|
-
__name(this, "Illuma");
|
|
226
|
-
}
|
|
227
|
-
static _diagnostics = [];
|
|
228
|
-
static _scanners = [];
|
|
229
|
-
static _middlewares = [];
|
|
230
|
-
/** @internal */
|
|
231
|
-
static get contextScanners() {
|
|
232
|
-
return _Illuma._scanners;
|
|
233
|
-
}
|
|
234
|
-
/**
|
|
235
|
-
* Extends the diagnostics with a new diagnostics module.
|
|
236
|
-
* These will be run on diagnostics reports after container bootstrap.
|
|
237
|
-
*
|
|
238
|
-
* @param m - The diagnostics module instance to add
|
|
239
|
-
*/
|
|
240
|
-
static extendDiagnostics(m) {
|
|
241
|
-
_Illuma._diagnostics.push(m);
|
|
242
|
-
}
|
|
243
|
-
/**
|
|
244
|
-
* Extends the context scanners with a new context scanner.
|
|
245
|
-
* These will be run in injection context scans to detect additional injections (alongside `nodeInject` calls).
|
|
246
|
-
*
|
|
247
|
-
* @param scanner - The context scanner instance to add
|
|
248
|
-
*/
|
|
249
|
-
static extendContextScanner(scanner) {
|
|
250
|
-
_Illuma._scanners.push(scanner);
|
|
251
|
-
}
|
|
252
|
-
/**
|
|
253
|
-
* Registers a global middleware to be applied during instance creation.
|
|
254
|
-
* Typically used for cross-cutting concerns like logging, profiling, or custom instantiation logic.
|
|
255
|
-
* Function should accept instantiation parameters and a `next` function to proceed with the next middleware or actual instantiation.
|
|
256
|
-
*
|
|
257
|
-
* @param m - The middleware function to register
|
|
258
|
-
*/
|
|
259
|
-
static registerGlobalMiddleware(m) {
|
|
260
|
-
_Illuma._middlewares.push(m);
|
|
261
|
-
}
|
|
262
|
-
middlewares = [];
|
|
263
|
-
registerMiddleware(m) {
|
|
264
|
-
this.middlewares.push(m);
|
|
265
|
-
}
|
|
266
|
-
static onReport(report) {
|
|
267
|
-
for (const diag of _Illuma._diagnostics) diag.onReport(report);
|
|
268
|
-
}
|
|
269
|
-
};
|
|
270
|
-
|
|
271
372
|
// src/lib/context/context.ts
|
|
373
|
+
init_plugin_container();
|
|
272
374
|
var InjectionContext = class _InjectionContext {
|
|
273
375
|
static {
|
|
274
376
|
__name(this, "InjectionContext");
|
|
@@ -368,18 +470,8 @@ function nodeInject(provider, options) {
|
|
|
368
470
|
}
|
|
369
471
|
__name(nodeInject, "nodeInject");
|
|
370
472
|
|
|
371
|
-
// src/lib/
|
|
372
|
-
|
|
373
|
-
static {
|
|
374
|
-
__name(this, "DiagnosticsDefaultReporter");
|
|
375
|
-
}
|
|
376
|
-
onReport(report) {
|
|
377
|
-
console.log("[Illuma] \u{1F9F9} Diagnostics:");
|
|
378
|
-
console.log(` Total: ${report.totalNodes} node(s)`);
|
|
379
|
-
console.log(` ${report.unusedNodes.length} were not used while bootstrap:`);
|
|
380
|
-
for (const node of report.unusedNodes) console.log(` - ${node.toString()}`);
|
|
381
|
-
}
|
|
382
|
-
};
|
|
473
|
+
// src/lib/container/container.ts
|
|
474
|
+
init_plugin_container();
|
|
383
475
|
|
|
384
476
|
// src/lib/provider/extractor.ts
|
|
385
477
|
function extractProvider(provider) {
|
|
@@ -585,7 +677,11 @@ var TreeNodeSingle = class {
|
|
|
585
677
|
const contextFactory = /* @__PURE__ */ __name(() => InjectionContext.instantiate(factory, retriever), "contextFactory");
|
|
586
678
|
this._instance = runMiddlewares(middlewares, {
|
|
587
679
|
token: this.proto.token,
|
|
588
|
-
factory: contextFactory
|
|
680
|
+
factory: contextFactory,
|
|
681
|
+
deps: /* @__PURE__ */ new Set([
|
|
682
|
+
...this._deps.keys(),
|
|
683
|
+
...Array.from(this._transparent).map((n) => n.proto.parent.token)
|
|
684
|
+
])
|
|
589
685
|
});
|
|
590
686
|
this._resolved = true;
|
|
591
687
|
if (pool) pool.set(this.proto.token, this);
|
|
@@ -628,7 +724,11 @@ var TreeNodeTransparent = class _TreeNodeTransparent {
|
|
|
628
724
|
const refFactory = /* @__PURE__ */ __name(() => InjectionContext.instantiate(this.proto.factory, retriever), "refFactory");
|
|
629
725
|
this._instance = runMiddlewares(middlewares, {
|
|
630
726
|
token: this.proto.parent.token,
|
|
631
|
-
factory: refFactory
|
|
727
|
+
factory: refFactory,
|
|
728
|
+
deps: /* @__PURE__ */ new Set([
|
|
729
|
+
...this._deps.keys(),
|
|
730
|
+
...Array.from(this._transparent).map((n) => n.proto.parent.token)
|
|
731
|
+
])
|
|
632
732
|
});
|
|
633
733
|
this._resolved = true;
|
|
634
734
|
}
|
|
@@ -823,10 +923,13 @@ var NodeContainer = class extends Illuma {
|
|
|
823
923
|
_multiProtoNodes = /* @__PURE__ */ new Map();
|
|
824
924
|
constructor(_opts) {
|
|
825
925
|
super(), this._opts = _opts;
|
|
826
|
-
this._parent = _opts?.parent;
|
|
827
926
|
if (_opts?.diagnostics) {
|
|
828
|
-
|
|
927
|
+
console.warn("[Illuma] Deprecation Warning: The 'diagnostics' option in iContainerOptions is deprecated and will be removed in future versions. Please use the `enableIllumaDiagnostics` from '@illuma/core/plugins` instead.");
|
|
928
|
+
const m = (init_built_in(), __toCommonJS(built_in_exports));
|
|
929
|
+
if (m.enabled) return;
|
|
930
|
+
m.enableIllumaDiagnostics();
|
|
829
931
|
}
|
|
932
|
+
this._parent = _opts?.parent;
|
|
830
933
|
}
|
|
831
934
|
/**
|
|
832
935
|
* Registers a provider in the container.
|
|
@@ -1001,7 +1104,7 @@ var NodeContainer = class extends Illuma {
|
|
|
1001
1104
|
if (this._opts?.measurePerformance) {
|
|
1002
1105
|
console.log(`[Illuma] \u{1F680} Bootstrapped in ${duration.toFixed(2)} ms`);
|
|
1003
1106
|
}
|
|
1004
|
-
if (this._opts?.diagnostics) {
|
|
1107
|
+
if (this._opts?.diagnostics || Illuma.hasDiagnostics()) {
|
|
1005
1108
|
const allNodes = this._rootNode.dependencies.size;
|
|
1006
1109
|
const unusedNodes = Array.from(this._rootNode.dependencies).filter((node) => node.allocations === 0).filter((node) => {
|
|
1007
1110
|
if (!(node.proto instanceof ProtoNodeSingle)) return true;
|