@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/dist/index.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 {
@@ -221,56 +387,8 @@ function registerClassAsInjectable(ctor, token) {
221
387
  }
222
388
  __name(registerClassAsInjectable, "registerClassAsInjectable");
223
389
 
224
- // src/lib/plugins/core/plugin-container.ts
225
- var Illuma = class _Illuma {
226
- static {
227
- __name(this, "Illuma");
228
- }
229
- static _diagnostics = [];
230
- static _scanners = [];
231
- static _middlewares = [];
232
- /** @internal */
233
- static get contextScanners() {
234
- return _Illuma._scanners;
235
- }
236
- /**
237
- * Extends the diagnostics with a new diagnostics module.
238
- * These will be run on diagnostics reports after container bootstrap.
239
- *
240
- * @param m - The diagnostics module instance to add
241
- */
242
- static extendDiagnostics(m) {
243
- _Illuma._diagnostics.push(m);
244
- }
245
- /**
246
- * Extends the context scanners with a new context scanner.
247
- * These will be run in injection context scans to detect additional injections (alongside `nodeInject` calls).
248
- *
249
- * @param scanner - The context scanner instance to add
250
- */
251
- static extendContextScanner(scanner) {
252
- _Illuma._scanners.push(scanner);
253
- }
254
- /**
255
- * Registers a global middleware to be applied during instance creation.
256
- * Typically used for cross-cutting concerns like logging, profiling, or custom instantiation logic.
257
- * Function should accept instantiation parameters and a `next` function to proceed with the next middleware or actual instantiation.
258
- *
259
- * @param m - The middleware function to register
260
- */
261
- static registerGlobalMiddleware(m) {
262
- _Illuma._middlewares.push(m);
263
- }
264
- middlewares = [];
265
- registerMiddleware(m) {
266
- this.middlewares.push(m);
267
- }
268
- static onReport(report) {
269
- for (const diag of _Illuma._diagnostics) diag.onReport(report);
270
- }
271
- };
272
-
273
390
  // src/lib/context/context.ts
391
+ init_plugin_container();
274
392
  var InjectionContext = class _InjectionContext {
275
393
  static {
276
394
  __name(this, "InjectionContext");
@@ -370,18 +488,8 @@ function nodeInject(provider, options) {
370
488
  }
371
489
  __name(nodeInject, "nodeInject");
372
490
 
373
- // src/lib/plugins/diagnostics/default-impl.ts
374
- var DiagnosticsDefaultReporter = class {
375
- static {
376
- __name(this, "DiagnosticsDefaultReporter");
377
- }
378
- onReport(report) {
379
- console.log("[Illuma] \u{1F9F9} Diagnostics:");
380
- console.log(` Total: ${report.totalNodes} node(s)`);
381
- console.log(` ${report.unusedNodes.length} were not used while bootstrap:`);
382
- for (const node of report.unusedNodes) console.log(` - ${node.toString()}`);
383
- }
384
- };
491
+ // src/lib/container/container.ts
492
+ init_plugin_container();
385
493
 
386
494
  // src/lib/provider/extractor.ts
387
495
  function extractProvider(provider) {
@@ -587,7 +695,11 @@ var TreeNodeSingle = class {
587
695
  const contextFactory = /* @__PURE__ */ __name(() => InjectionContext.instantiate(factory, retriever), "contextFactory");
588
696
  this._instance = runMiddlewares(middlewares, {
589
697
  token: this.proto.token,
590
- factory: contextFactory
698
+ factory: contextFactory,
699
+ deps: /* @__PURE__ */ new Set([
700
+ ...this._deps.keys(),
701
+ ...Array.from(this._transparent).map((n) => n.proto.parent.token)
702
+ ])
591
703
  });
592
704
  this._resolved = true;
593
705
  if (pool) pool.set(this.proto.token, this);
@@ -630,7 +742,11 @@ var TreeNodeTransparent = class _TreeNodeTransparent {
630
742
  const refFactory = /* @__PURE__ */ __name(() => InjectionContext.instantiate(this.proto.factory, retriever), "refFactory");
631
743
  this._instance = runMiddlewares(middlewares, {
632
744
  token: this.proto.parent.token,
633
- factory: refFactory
745
+ factory: refFactory,
746
+ deps: /* @__PURE__ */ new Set([
747
+ ...this._deps.keys(),
748
+ ...Array.from(this._transparent).map((n) => n.proto.parent.token)
749
+ ])
634
750
  });
635
751
  this._resolved = true;
636
752
  }
@@ -921,10 +1037,13 @@ var NodeContainer = class extends Illuma {
921
1037
  _multiProtoNodes = /* @__PURE__ */ new Map();
922
1038
  constructor(_opts) {
923
1039
  super(), this._opts = _opts;
924
- this._parent = _opts?.parent;
925
1040
  if (_opts?.diagnostics) {
926
- Illuma.extendDiagnostics(new DiagnosticsDefaultReporter());
1041
+ 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.");
1042
+ const m = (init_built_in(), __toCommonJS(built_in_exports));
1043
+ if (m.enabled) return;
1044
+ m.enableIllumaDiagnostics();
927
1045
  }
1046
+ this._parent = _opts?.parent;
928
1047
  }
929
1048
  /**
930
1049
  * Registers a provider in the container.
@@ -1099,7 +1218,7 @@ var NodeContainer = class extends Illuma {
1099
1218
  if (this._opts?.measurePerformance) {
1100
1219
  console.log(`[Illuma] \u{1F680} Bootstrapped in ${duration.toFixed(2)} ms`);
1101
1220
  }
1102
- if (this._opts?.diagnostics) {
1221
+ if (this._opts?.diagnostics || Illuma.hasDiagnostics()) {
1103
1222
  const allNodes = this._rootNode.dependencies.size;
1104
1223
  const unusedNodes = Array.from(this._rootNode.dependencies).filter((node) => node.allocations === 0).filter((node) => {
1105
1224
  if (!(node.proto instanceof ProtoNodeSingle)) return true;