@illuma/core 1.5.0 → 1.5.2
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/README.md +43 -31
- package/dist/index.cjs +51 -20
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +5 -5
- package/dist/index.d.ts +5 -5
- package/dist/index.js +51 -20
- package/dist/index.js.map +1 -1
- package/dist/{injection-uBc6Sjj_.d.cts → injection-DbD-KHxh.d.cts} +1 -1
- package/dist/{injection-CsNE009y.d.ts → injection-NAMHFl1Y.d.ts} +1 -1
- package/dist/{plugin-container-OWBUHjSf.d.cts → plugin-container-C3xE3HLf.d.cts} +1 -1
- package/dist/{plugin-container-DZj4vSLu.d.ts → plugin-container-XmDO_bdM.d.ts} +1 -1
- package/dist/plugins.d.cts +3 -3
- package/dist/plugins.d.ts +3 -3
- package/dist/testkit.cjs +51 -20
- package/dist/testkit.cjs.map +1 -1
- package/dist/testkit.d.cts +2 -2
- package/dist/testkit.d.ts +2 -2
- package/dist/testkit.js +51 -20
- package/dist/testkit.js.map +1 -1
- package/dist/{types-zryyqrii.d.cts → types-HBicpdg6.d.cts} +1 -1
- package/dist/{types-zryyqrii.d.ts → types-HBicpdg6.d.ts} +1 -1
- package/package.json +7 -8
- package/CHANGELOG.md +0 -22
package/dist/index.js
CHANGED
|
@@ -347,7 +347,7 @@ __name(isNotFoundError, "isNotFoundError");
|
|
|
347
347
|
|
|
348
348
|
// src/lib/api/decorator.ts
|
|
349
349
|
var tokenRegistry = /* @__PURE__ */ new WeakMap();
|
|
350
|
-
var INJECTION_SYMBOL = Symbol("Injectable");
|
|
350
|
+
var INJECTION_SYMBOL = /* @__PURE__ */ Symbol("Injectable");
|
|
351
351
|
function NodeInjectable() {
|
|
352
352
|
return (ctor) => {
|
|
353
353
|
const nodeToken = new NodeToken(`_${ctor.name}`, {
|
|
@@ -491,6 +491,17 @@ __name(nodeInject, "nodeInject");
|
|
|
491
491
|
// src/lib/container/container.ts
|
|
492
492
|
init_plugin_container();
|
|
493
493
|
|
|
494
|
+
// src/lib/plugins/middlewares/runner.ts
|
|
495
|
+
function runMiddlewares(middlewares, params) {
|
|
496
|
+
const ms = middlewares;
|
|
497
|
+
const next = /* @__PURE__ */ __name((i, current) => {
|
|
498
|
+
if (i >= ms.length) return current.factory();
|
|
499
|
+
return ms[i](current, (nextParams) => next(i + 1, nextParams));
|
|
500
|
+
}, "next");
|
|
501
|
+
return next(0, params);
|
|
502
|
+
}
|
|
503
|
+
__name(runMiddlewares, "runMiddlewares");
|
|
504
|
+
|
|
494
505
|
// src/lib/provider/extractor.ts
|
|
495
506
|
function extractProvider(provider) {
|
|
496
507
|
if ("value" in provider) return () => provider.value;
|
|
@@ -596,24 +607,15 @@ var InjectorImpl = class {
|
|
|
596
607
|
var Injector = new NodeToken("Injector");
|
|
597
608
|
|
|
598
609
|
// src/lib/provider/tree-node.ts
|
|
599
|
-
function runMiddlewares(middlewares, params) {
|
|
600
|
-
const ms = middlewares;
|
|
601
|
-
const next = /* @__PURE__ */ __name((i, current) => {
|
|
602
|
-
if (i >= ms.length) return current.factory();
|
|
603
|
-
return ms[i](current, (nextParams) => next(i + 1, nextParams));
|
|
604
|
-
}, "next");
|
|
605
|
-
return next(0, params);
|
|
606
|
-
}
|
|
607
|
-
__name(runMiddlewares, "runMiddlewares");
|
|
608
610
|
function retrieverFactory(node, deps, transparentDeps) {
|
|
609
611
|
return (token, optional) => {
|
|
610
612
|
const depNode = deps.get(token);
|
|
611
613
|
if (!depNode && !optional) {
|
|
612
|
-
const transparent =
|
|
614
|
+
const transparent = transparentDeps.get(token);
|
|
613
615
|
if (transparent) return transparent.instance;
|
|
614
616
|
throw InjectionError.untracked(token, node);
|
|
615
617
|
}
|
|
616
|
-
return depNode
|
|
618
|
+
return depNode ? depNode.instance : null;
|
|
617
619
|
};
|
|
618
620
|
}
|
|
619
621
|
__name(retrieverFactory, "retrieverFactory");
|
|
@@ -624,7 +626,7 @@ var TreeRootNode = class {
|
|
|
624
626
|
instant;
|
|
625
627
|
middlewares;
|
|
626
628
|
_deps = /* @__PURE__ */ new Set();
|
|
627
|
-
_treePool = /* @__PURE__ */ new
|
|
629
|
+
_treePool = /* @__PURE__ */ new Map();
|
|
628
630
|
constructor(instant = true, middlewares = []) {
|
|
629
631
|
this.instant = instant;
|
|
630
632
|
this.middlewares = middlewares;
|
|
@@ -689,7 +691,11 @@ var TreeNodeSingle = class {
|
|
|
689
691
|
if (this._resolved) return;
|
|
690
692
|
for (const node of this._deps.values()) node.instantiate(pool, middlewares);
|
|
691
693
|
for (const dep of this._transparent) dep.instantiate(pool, middlewares);
|
|
692
|
-
const
|
|
694
|
+
const transparentMap = /* @__PURE__ */ new Map();
|
|
695
|
+
for (const tNode of this._transparent) {
|
|
696
|
+
transparentMap.set(tNode.proto.parent.token, tNode);
|
|
697
|
+
}
|
|
698
|
+
const retriever = retrieverFactory(this.proto.token, this._deps, transparentMap);
|
|
693
699
|
const factory = this.proto.factory ?? this.proto.token.opts?.factory;
|
|
694
700
|
if (!factory) throw InjectionError.notFound(this.proto.token);
|
|
695
701
|
const contextFactory = /* @__PURE__ */ __name(() => InjectionContext.instantiate(factory, retriever), "contextFactory");
|
|
@@ -738,7 +744,11 @@ var TreeNodeTransparent = class _TreeNodeTransparent {
|
|
|
738
744
|
if (this._resolved) return;
|
|
739
745
|
for (const dep of this._transparent) dep.instantiate(pool, middlewares);
|
|
740
746
|
for (const node of this._deps.values()) node.instantiate(pool, middlewares);
|
|
741
|
-
const
|
|
747
|
+
const transparentMap = /* @__PURE__ */ new Map();
|
|
748
|
+
for (const tNode of this._transparent) {
|
|
749
|
+
transparentMap.set(tNode.proto.parent.token, tNode);
|
|
750
|
+
}
|
|
751
|
+
const retriever = retrieverFactory(this.proto.parent.token, this._deps, transparentMap);
|
|
742
752
|
const refFactory = /* @__PURE__ */ __name(() => InjectionContext.instantiate(this.proto.factory, retriever), "refFactory");
|
|
743
753
|
this._instance = runMiddlewares(middlewares, {
|
|
744
754
|
token: this.proto.parent.token,
|
|
@@ -1271,12 +1281,33 @@ var NodeContainer = class extends Illuma {
|
|
|
1271
1281
|
if (isConstructor(fn) && !isInjectable(fn)) {
|
|
1272
1282
|
throw InjectionError.invalidCtor(fn);
|
|
1273
1283
|
}
|
|
1274
|
-
|
|
1275
|
-
|
|
1276
|
-
|
|
1277
|
-
|
|
1278
|
-
|
|
1284
|
+
let factory;
|
|
1285
|
+
if (isInjectable(fn)) {
|
|
1286
|
+
const f = getInjectableToken(fn).opts?.factory;
|
|
1287
|
+
if (!f) factory = /* @__PURE__ */ __name(() => new fn(), "factory");
|
|
1288
|
+
else factory = /* @__PURE__ */ __name(() => getInjectableToken(fn).opts?.factory?.(), "factory");
|
|
1289
|
+
} else {
|
|
1290
|
+
factory = fn;
|
|
1291
|
+
}
|
|
1292
|
+
const rootNode = this._rootNode;
|
|
1293
|
+
if (!rootNode) throw InjectionError.notBootstrapped();
|
|
1294
|
+
const retriever = /* @__PURE__ */ __name((token, optional) => {
|
|
1295
|
+
const node = rootNode.find(token);
|
|
1296
|
+
if (!node && !optional) throw InjectionError.notFound(token);
|
|
1279
1297
|
return node ? node.instance : null;
|
|
1298
|
+
}, "retriever");
|
|
1299
|
+
const deps = InjectionContext.scan(factory);
|
|
1300
|
+
const middlewares = [
|
|
1301
|
+
...Illuma._middlewares,
|
|
1302
|
+
...this.collectMiddlewares()
|
|
1303
|
+
];
|
|
1304
|
+
const contextFactory = /* @__PURE__ */ __name(() => InjectionContext.instantiate(factory, retriever), "contextFactory");
|
|
1305
|
+
return runMiddlewares(middlewares, {
|
|
1306
|
+
token: new NodeToken("ProducedNode"),
|
|
1307
|
+
deps: new Set([
|
|
1308
|
+
...deps.values()
|
|
1309
|
+
].map((d) => d.token)),
|
|
1310
|
+
factory: contextFactory
|
|
1280
1311
|
});
|
|
1281
1312
|
}
|
|
1282
1313
|
};
|