@illuma/core 1.5.0 → 1.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.
package/CHANGELOG.md CHANGED
@@ -7,6 +7,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
7
7
 
8
8
  ## Unreleased
9
9
 
10
+ ## 1.5.1 - 2026-01-11
11
+
10
12
  ## 1.5.0 - 2026-01-10
11
13
 
12
14
  ## 1.4.0 - 2026-01-10
package/dist/index.cjs CHANGED
@@ -521,6 +521,17 @@ __name(nodeInject, "nodeInject");
521
521
  // src/lib/container/container.ts
522
522
  init_plugin_container();
523
523
 
524
+ // src/lib/plugins/middlewares/runner.ts
525
+ function runMiddlewares(middlewares, params) {
526
+ const ms = middlewares;
527
+ const next = /* @__PURE__ */ __name((i, current) => {
528
+ if (i >= ms.length) return current.factory();
529
+ return ms[i](current, (nextParams) => next(i + 1, nextParams));
530
+ }, "next");
531
+ return next(0, params);
532
+ }
533
+ __name(runMiddlewares, "runMiddlewares");
534
+
524
535
  // src/lib/provider/extractor.ts
525
536
  function extractProvider(provider) {
526
537
  if ("value" in provider) return () => provider.value;
@@ -626,24 +637,15 @@ var InjectorImpl = class {
626
637
  var Injector = new NodeToken("Injector");
627
638
 
628
639
  // src/lib/provider/tree-node.ts
629
- function runMiddlewares(middlewares, params) {
630
- const ms = middlewares;
631
- const next = /* @__PURE__ */ __name((i, current) => {
632
- if (i >= ms.length) return current.factory();
633
- return ms[i](current, (nextParams) => next(i + 1, nextParams));
634
- }, "next");
635
- return next(0, params);
636
- }
637
- __name(runMiddlewares, "runMiddlewares");
638
640
  function retrieverFactory(node, deps, transparentDeps) {
639
641
  return (token, optional) => {
640
642
  const depNode = deps.get(token);
641
643
  if (!depNode && !optional) {
642
- const transparent = Array.from(transparentDeps).find((n) => "proto" in n && n.proto.parent.token === token);
644
+ const transparent = transparentDeps.get(token);
643
645
  if (transparent) return transparent.instance;
644
646
  throw InjectionError.untracked(token, node);
645
647
  }
646
- return depNode?.instance ?? null;
648
+ return depNode ? depNode.instance : null;
647
649
  };
648
650
  }
649
651
  __name(retrieverFactory, "retrieverFactory");
@@ -654,7 +656,7 @@ var TreeRootNode = class {
654
656
  instant;
655
657
  middlewares;
656
658
  _deps = /* @__PURE__ */ new Set();
657
- _treePool = /* @__PURE__ */ new WeakMap();
659
+ _treePool = /* @__PURE__ */ new Map();
658
660
  constructor(instant = true, middlewares = []) {
659
661
  this.instant = instant;
660
662
  this.middlewares = middlewares;
@@ -719,7 +721,11 @@ var TreeNodeSingle = class {
719
721
  if (this._resolved) return;
720
722
  for (const node of this._deps.values()) node.instantiate(pool, middlewares);
721
723
  for (const dep of this._transparent) dep.instantiate(pool, middlewares);
722
- const retriever = retrieverFactory(this.proto.token, this._deps, this._transparent);
724
+ const transparentMap = /* @__PURE__ */ new Map();
725
+ for (const tNode of this._transparent) {
726
+ transparentMap.set(tNode.proto.parent.token, tNode);
727
+ }
728
+ const retriever = retrieverFactory(this.proto.token, this._deps, transparentMap);
723
729
  const factory = this.proto.factory ?? this.proto.token.opts?.factory;
724
730
  if (!factory) throw InjectionError.notFound(this.proto.token);
725
731
  const contextFactory = /* @__PURE__ */ __name(() => InjectionContext.instantiate(factory, retriever), "contextFactory");
@@ -768,7 +774,11 @@ var TreeNodeTransparent = class _TreeNodeTransparent {
768
774
  if (this._resolved) return;
769
775
  for (const dep of this._transparent) dep.instantiate(pool, middlewares);
770
776
  for (const node of this._deps.values()) node.instantiate(pool, middlewares);
771
- const retriever = retrieverFactory(this.proto.parent.token, this._deps, this._transparent);
777
+ const transparentMap = /* @__PURE__ */ new Map();
778
+ for (const tNode of this._transparent) {
779
+ transparentMap.set(tNode.proto.parent.token, tNode);
780
+ }
781
+ const retriever = retrieverFactory(this.proto.parent.token, this._deps, transparentMap);
772
782
  const refFactory = /* @__PURE__ */ __name(() => InjectionContext.instantiate(this.proto.factory, retriever), "refFactory");
773
783
  this._instance = runMiddlewares(middlewares, {
774
784
  token: this.proto.parent.token,
@@ -1301,12 +1311,33 @@ var NodeContainer = class extends Illuma {
1301
1311
  if (isConstructor(fn) && !isInjectable(fn)) {
1302
1312
  throw InjectionError.invalidCtor(fn);
1303
1313
  }
1304
- const factory = isInjectable(fn) ? () => new fn() : fn;
1305
- return InjectionContext.instantiate(factory, (t, optional) => {
1306
- if (!this._rootNode) throw InjectionError.notBootstrapped();
1307
- const node = this._rootNode.find(t);
1308
- if (!node && !optional) throw InjectionError.notFound(t);
1314
+ let factory;
1315
+ if (isInjectable(fn)) {
1316
+ const f = getInjectableToken(fn).opts?.factory;
1317
+ if (!f) factory = /* @__PURE__ */ __name(() => new fn(), "factory");
1318
+ else factory = /* @__PURE__ */ __name(() => getInjectableToken(fn).opts?.factory?.(), "factory");
1319
+ } else {
1320
+ factory = fn;
1321
+ }
1322
+ const rootNode = this._rootNode;
1323
+ if (!rootNode) throw InjectionError.notBootstrapped();
1324
+ const retriever = /* @__PURE__ */ __name((token, optional) => {
1325
+ const node = rootNode.find(token);
1326
+ if (!node && !optional) throw InjectionError.notFound(token);
1309
1327
  return node ? node.instance : null;
1328
+ }, "retriever");
1329
+ const deps = InjectionContext.scan(factory);
1330
+ const middlewares = [
1331
+ ...Illuma._middlewares,
1332
+ ...this.collectMiddlewares()
1333
+ ];
1334
+ const contextFactory = /* @__PURE__ */ __name(() => InjectionContext.instantiate(factory, retriever), "contextFactory");
1335
+ return runMiddlewares(middlewares, {
1336
+ token: new NodeToken("ProducedNode"),
1337
+ deps: new Set([
1338
+ ...deps.values()
1339
+ ].map((d) => d.token)),
1340
+ factory: contextFactory
1310
1341
  });
1311
1342
  }
1312
1343
  };