@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 +2 -0
- package/dist/index.cjs +50 -19
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +50 -19
- package/dist/index.js.map +1 -1
- package/dist/testkit.cjs +50 -19
- package/dist/testkit.cjs.map +1 -1
- package/dist/testkit.js +50 -19
- package/dist/testkit.js.map +1 -1
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
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 =
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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
|
-
|
|
1305
|
-
|
|
1306
|
-
|
|
1307
|
-
|
|
1308
|
-
|
|
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
|
};
|