@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/testkit.js
CHANGED
|
@@ -1,5 +1,171 @@
|
|
|
1
1
|
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
2
5
|
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
6
|
+
var __esm = (fn, res) => function __init() {
|
|
7
|
+
return fn && (res = (0, fn[__getOwnPropNames(fn)[0]])(fn = 0)), res;
|
|
8
|
+
};
|
|
9
|
+
var __export = (target, all) => {
|
|
10
|
+
for (var name in all)
|
|
11
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
12
|
+
};
|
|
13
|
+
var __copyProps = (to, from, except, desc) => {
|
|
14
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
15
|
+
for (let key of __getOwnPropNames(from))
|
|
16
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
17
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
18
|
+
}
|
|
19
|
+
return to;
|
|
20
|
+
};
|
|
21
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
22
|
+
|
|
23
|
+
// src/lib/plugins/core/plugin-container.ts
|
|
24
|
+
var Illuma;
|
|
25
|
+
var init_plugin_container = __esm({
|
|
26
|
+
"src/lib/plugins/core/plugin-container.ts"() {
|
|
27
|
+
"use strict";
|
|
28
|
+
Illuma = class _Illuma {
|
|
29
|
+
static {
|
|
30
|
+
__name(this, "Illuma");
|
|
31
|
+
}
|
|
32
|
+
static _diagnostics = /* @__PURE__ */ new Set();
|
|
33
|
+
static _scanners = [];
|
|
34
|
+
static _middlewares = [];
|
|
35
|
+
/** @internal */
|
|
36
|
+
static get contextScanners() {
|
|
37
|
+
return _Illuma._scanners;
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Extends the diagnostics with a new diagnostics module.
|
|
41
|
+
* These will be run on diagnostics reports after container bootstrap.
|
|
42
|
+
*
|
|
43
|
+
* @param m - The diagnostics module instance to add
|
|
44
|
+
*/
|
|
45
|
+
static extendDiagnostics(m) {
|
|
46
|
+
_Illuma._diagnostics.add(m);
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Extends the context scanners with a new context scanner.
|
|
50
|
+
* These will be run in injection context scans to detect additional injections (alongside `nodeInject` calls).
|
|
51
|
+
*
|
|
52
|
+
* @param scanner - The context scanner instance to add
|
|
53
|
+
*/
|
|
54
|
+
static extendContextScanner(scanner) {
|
|
55
|
+
_Illuma._scanners.push(scanner);
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* Registers a global middleware to be applied during instance creation.
|
|
59
|
+
* Typically used for cross-cutting concerns like logging, profiling, or custom instantiation logic.
|
|
60
|
+
* Function should accept instantiation parameters and a `next` function to proceed with the next middleware or actual instantiation.
|
|
61
|
+
*
|
|
62
|
+
* @param m - The middleware function to register
|
|
63
|
+
*/
|
|
64
|
+
static registerGlobalMiddleware(m) {
|
|
65
|
+
_Illuma._middlewares.push(m);
|
|
66
|
+
}
|
|
67
|
+
middlewares = [];
|
|
68
|
+
registerMiddleware(m) {
|
|
69
|
+
this.middlewares.push(m);
|
|
70
|
+
}
|
|
71
|
+
static onReport(report) {
|
|
72
|
+
for (const diag of _Illuma._diagnostics) diag.onReport(report);
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* @internal
|
|
76
|
+
* Check if diagnostics modules are registered
|
|
77
|
+
*/
|
|
78
|
+
static hasDiagnostics() {
|
|
79
|
+
return _Illuma._diagnostics.size > 0;
|
|
80
|
+
}
|
|
81
|
+
/**
|
|
82
|
+
* @internal
|
|
83
|
+
* Reset all plugin registrations
|
|
84
|
+
*/
|
|
85
|
+
static __resetPlugins() {
|
|
86
|
+
_Illuma._diagnostics.clear();
|
|
87
|
+
_Illuma._scanners.length = 0;
|
|
88
|
+
_Illuma._middlewares.length = 0;
|
|
89
|
+
}
|
|
90
|
+
};
|
|
91
|
+
}
|
|
92
|
+
});
|
|
93
|
+
|
|
94
|
+
// src/lib/plugins/core/index.ts
|
|
95
|
+
var init_core = __esm({
|
|
96
|
+
"src/lib/plugins/core/index.ts"() {
|
|
97
|
+
"use strict";
|
|
98
|
+
init_plugin_container();
|
|
99
|
+
}
|
|
100
|
+
});
|
|
101
|
+
|
|
102
|
+
// src/lib/plugins/middlewares/diagnostics.middleware.ts
|
|
103
|
+
var performanceDiagnostics;
|
|
104
|
+
var init_diagnostics_middleware = __esm({
|
|
105
|
+
"src/lib/plugins/middlewares/diagnostics.middleware.ts"() {
|
|
106
|
+
"use strict";
|
|
107
|
+
performanceDiagnostics = /* @__PURE__ */ __name((params, next) => {
|
|
108
|
+
if (!params.deps.size) {
|
|
109
|
+
return next(params);
|
|
110
|
+
}
|
|
111
|
+
const start = performance.now();
|
|
112
|
+
const instance = next(params);
|
|
113
|
+
const end = performance.now();
|
|
114
|
+
const duration = end - start;
|
|
115
|
+
console.log(`Instantiated ${params.token.name} in ${duration.toFixed(2)} ms`);
|
|
116
|
+
return instance;
|
|
117
|
+
}, "performanceDiagnostics");
|
|
118
|
+
}
|
|
119
|
+
});
|
|
120
|
+
|
|
121
|
+
// src/lib/plugins/diagnostics/default-impl.ts
|
|
122
|
+
var DiagnosticsDefaultReporter;
|
|
123
|
+
var init_default_impl = __esm({
|
|
124
|
+
"src/lib/plugins/diagnostics/default-impl.ts"() {
|
|
125
|
+
"use strict";
|
|
126
|
+
DiagnosticsDefaultReporter = class {
|
|
127
|
+
static {
|
|
128
|
+
__name(this, "DiagnosticsDefaultReporter");
|
|
129
|
+
}
|
|
130
|
+
onReport(report) {
|
|
131
|
+
console.log("[Illuma] \u{1F9F9} Diagnostics:");
|
|
132
|
+
console.log(` Total: ${report.totalNodes} node(s)`);
|
|
133
|
+
console.log(` ${report.unusedNodes.length} were not used while bootstrap:`);
|
|
134
|
+
for (const node of report.unusedNodes) console.log(` - ${node.toString()}`);
|
|
135
|
+
}
|
|
136
|
+
};
|
|
137
|
+
}
|
|
138
|
+
});
|
|
139
|
+
|
|
140
|
+
// src/lib/plugins/diagnostics/built-in.ts
|
|
141
|
+
var built_in_exports = {};
|
|
142
|
+
__export(built_in_exports, {
|
|
143
|
+
__resetDiagnosticsState: () => __resetDiagnosticsState,
|
|
144
|
+
enableIllumaDiagnostics: () => enableIllumaDiagnostics
|
|
145
|
+
});
|
|
146
|
+
function enableIllumaDiagnostics() {
|
|
147
|
+
if (state.enabled) return;
|
|
148
|
+
state.enabled = true;
|
|
149
|
+
Illuma.extendDiagnostics(new DiagnosticsDefaultReporter());
|
|
150
|
+
Illuma.registerGlobalMiddleware(performanceDiagnostics);
|
|
151
|
+
}
|
|
152
|
+
function __resetDiagnosticsState() {
|
|
153
|
+
state.enabled = false;
|
|
154
|
+
}
|
|
155
|
+
var state;
|
|
156
|
+
var init_built_in = __esm({
|
|
157
|
+
"src/lib/plugins/diagnostics/built-in.ts"() {
|
|
158
|
+
"use strict";
|
|
159
|
+
init_core();
|
|
160
|
+
init_diagnostics_middleware();
|
|
161
|
+
init_default_impl();
|
|
162
|
+
state = {
|
|
163
|
+
enabled: false
|
|
164
|
+
};
|
|
165
|
+
__name(enableIllumaDiagnostics, "enableIllumaDiagnostics");
|
|
166
|
+
__name(__resetDiagnosticsState, "__resetDiagnosticsState");
|
|
167
|
+
}
|
|
168
|
+
});
|
|
3
169
|
|
|
4
170
|
// src/lib/api/token.ts
|
|
5
171
|
var NodeBase = class {
|
|
@@ -195,56 +361,8 @@ function isConstructor(fn) {
|
|
|
195
361
|
}
|
|
196
362
|
__name(isConstructor, "isConstructor");
|
|
197
363
|
|
|
198
|
-
// src/lib/plugins/core/plugin-container.ts
|
|
199
|
-
var Illuma = class _Illuma {
|
|
200
|
-
static {
|
|
201
|
-
__name(this, "Illuma");
|
|
202
|
-
}
|
|
203
|
-
static _diagnostics = [];
|
|
204
|
-
static _scanners = [];
|
|
205
|
-
static _middlewares = [];
|
|
206
|
-
/** @internal */
|
|
207
|
-
static get contextScanners() {
|
|
208
|
-
return _Illuma._scanners;
|
|
209
|
-
}
|
|
210
|
-
/**
|
|
211
|
-
* Extends the diagnostics with a new diagnostics module.
|
|
212
|
-
* These will be run on diagnostics reports after container bootstrap.
|
|
213
|
-
*
|
|
214
|
-
* @param m - The diagnostics module instance to add
|
|
215
|
-
*/
|
|
216
|
-
static extendDiagnostics(m) {
|
|
217
|
-
_Illuma._diagnostics.push(m);
|
|
218
|
-
}
|
|
219
|
-
/**
|
|
220
|
-
* Extends the context scanners with a new context scanner.
|
|
221
|
-
* These will be run in injection context scans to detect additional injections (alongside `nodeInject` calls).
|
|
222
|
-
*
|
|
223
|
-
* @param scanner - The context scanner instance to add
|
|
224
|
-
*/
|
|
225
|
-
static extendContextScanner(scanner) {
|
|
226
|
-
_Illuma._scanners.push(scanner);
|
|
227
|
-
}
|
|
228
|
-
/**
|
|
229
|
-
* Registers a global middleware to be applied during instance creation.
|
|
230
|
-
* Typically used for cross-cutting concerns like logging, profiling, or custom instantiation logic.
|
|
231
|
-
* Function should accept instantiation parameters and a `next` function to proceed with the next middleware or actual instantiation.
|
|
232
|
-
*
|
|
233
|
-
* @param m - The middleware function to register
|
|
234
|
-
*/
|
|
235
|
-
static registerGlobalMiddleware(m) {
|
|
236
|
-
_Illuma._middlewares.push(m);
|
|
237
|
-
}
|
|
238
|
-
middlewares = [];
|
|
239
|
-
registerMiddleware(m) {
|
|
240
|
-
this.middlewares.push(m);
|
|
241
|
-
}
|
|
242
|
-
static onReport(report) {
|
|
243
|
-
for (const diag of _Illuma._diagnostics) diag.onReport(report);
|
|
244
|
-
}
|
|
245
|
-
};
|
|
246
|
-
|
|
247
364
|
// src/lib/context/context.ts
|
|
365
|
+
init_plugin_container();
|
|
248
366
|
var InjectionContext = class _InjectionContext {
|
|
249
367
|
static {
|
|
250
368
|
__name(this, "InjectionContext");
|
|
@@ -344,18 +462,8 @@ function nodeInject(provider, options) {
|
|
|
344
462
|
}
|
|
345
463
|
__name(nodeInject, "nodeInject");
|
|
346
464
|
|
|
347
|
-
// src/lib/
|
|
348
|
-
|
|
349
|
-
static {
|
|
350
|
-
__name(this, "DiagnosticsDefaultReporter");
|
|
351
|
-
}
|
|
352
|
-
onReport(report) {
|
|
353
|
-
console.log("[Illuma] \u{1F9F9} Diagnostics:");
|
|
354
|
-
console.log(` Total: ${report.totalNodes} node(s)`);
|
|
355
|
-
console.log(` ${report.unusedNodes.length} were not used while bootstrap:`);
|
|
356
|
-
for (const node of report.unusedNodes) console.log(` - ${node.toString()}`);
|
|
357
|
-
}
|
|
358
|
-
};
|
|
465
|
+
// src/lib/container/container.ts
|
|
466
|
+
init_plugin_container();
|
|
359
467
|
|
|
360
468
|
// src/lib/provider/extractor.ts
|
|
361
469
|
function extractProvider(provider) {
|
|
@@ -561,7 +669,11 @@ var TreeNodeSingle = class {
|
|
|
561
669
|
const contextFactory = /* @__PURE__ */ __name(() => InjectionContext.instantiate(factory, retriever), "contextFactory");
|
|
562
670
|
this._instance = runMiddlewares(middlewares, {
|
|
563
671
|
token: this.proto.token,
|
|
564
|
-
factory: contextFactory
|
|
672
|
+
factory: contextFactory,
|
|
673
|
+
deps: /* @__PURE__ */ new Set([
|
|
674
|
+
...this._deps.keys(),
|
|
675
|
+
...Array.from(this._transparent).map((n) => n.proto.parent.token)
|
|
676
|
+
])
|
|
565
677
|
});
|
|
566
678
|
this._resolved = true;
|
|
567
679
|
if (pool) pool.set(this.proto.token, this);
|
|
@@ -604,7 +716,11 @@ var TreeNodeTransparent = class _TreeNodeTransparent {
|
|
|
604
716
|
const refFactory = /* @__PURE__ */ __name(() => InjectionContext.instantiate(this.proto.factory, retriever), "refFactory");
|
|
605
717
|
this._instance = runMiddlewares(middlewares, {
|
|
606
718
|
token: this.proto.parent.token,
|
|
607
|
-
factory: refFactory
|
|
719
|
+
factory: refFactory,
|
|
720
|
+
deps: /* @__PURE__ */ new Set([
|
|
721
|
+
...this._deps.keys(),
|
|
722
|
+
...Array.from(this._transparent).map((n) => n.proto.parent.token)
|
|
723
|
+
])
|
|
608
724
|
});
|
|
609
725
|
this._resolved = true;
|
|
610
726
|
}
|
|
@@ -799,10 +915,13 @@ var NodeContainer = class extends Illuma {
|
|
|
799
915
|
_multiProtoNodes = /* @__PURE__ */ new Map();
|
|
800
916
|
constructor(_opts) {
|
|
801
917
|
super(), this._opts = _opts;
|
|
802
|
-
this._parent = _opts?.parent;
|
|
803
918
|
if (_opts?.diagnostics) {
|
|
804
|
-
|
|
919
|
+
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.");
|
|
920
|
+
const m = (init_built_in(), __toCommonJS(built_in_exports));
|
|
921
|
+
if (m.enabled) return;
|
|
922
|
+
m.enableIllumaDiagnostics();
|
|
805
923
|
}
|
|
924
|
+
this._parent = _opts?.parent;
|
|
806
925
|
}
|
|
807
926
|
/**
|
|
808
927
|
* Registers a provider in the container.
|
|
@@ -977,7 +1096,7 @@ var NodeContainer = class extends Illuma {
|
|
|
977
1096
|
if (this._opts?.measurePerformance) {
|
|
978
1097
|
console.log(`[Illuma] \u{1F680} Bootstrapped in ${duration.toFixed(2)} ms`);
|
|
979
1098
|
}
|
|
980
|
-
if (this._opts?.diagnostics) {
|
|
1099
|
+
if (this._opts?.diagnostics || Illuma.hasDiagnostics()) {
|
|
981
1100
|
const allNodes = this._rootNode.dependencies.size;
|
|
982
1101
|
const unusedNodes = Array.from(this._rootNode.dependencies).filter((node) => node.allocations === 0).filter((node) => {
|
|
983
1102
|
if (!(node.proto instanceof ProtoNodeSingle)) return true;
|