@illuma/core 0.2.0 → 1.1.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/README.md +170 -170
- package/dist/index.cjs +20 -101
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +76 -120
- package/dist/index.d.ts +76 -120
- package/dist/index.js +20 -99
- package/dist/index.js.map +1 -1
- package/dist/{injection-D22uAh1O.d.ts → injection-CSxu56ds.d.cts} +1 -1
- package/dist/{injection-CJGqGWJ6.d.cts → injection-Y_bVmBSk.d.ts} +1 -1
- package/dist/{plugin-container-CUw26ZhP.d.ts → plugin-container-CwkVlVS4.d.ts} +18 -21
- package/dist/{plugin-container-n0FIqLbh.d.cts → plugin-container-D8Zwpigq.d.cts} +18 -21
- package/dist/plugins.d.cts +3 -3
- package/dist/plugins.d.ts +3 -3
- package/dist/{token-BvQrvm-Q.d.cts → providers-D9YA8L_g.d.cts} +73 -73
- package/dist/{token-BvQrvm-Q.d.ts → providers-D9YA8L_g.d.ts} +73 -73
- package/dist/testkit.cjs +20 -62
- 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 +20 -62
- package/dist/testkit.js.map +1 -1
- package/package.json +74 -74
- package/CHANGELOG.md +0 -12
package/dist/index.js
CHANGED
|
@@ -2,29 +2,6 @@ var __defProp = Object.defineProperty;
|
|
|
2
2
|
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
3
3
|
|
|
4
4
|
// src/lib/errors.ts
|
|
5
|
-
var ERR_CODES = {
|
|
6
|
-
// Provider errors
|
|
7
|
-
DUPLICATE_PROVIDER: 100,
|
|
8
|
-
DUPLICATE_FACTORY: 101,
|
|
9
|
-
INVALID_CTOR: 102,
|
|
10
|
-
INVALID_PROVIDER: 103,
|
|
11
|
-
// Alias errors
|
|
12
|
-
INVALID_ALIAS: 200,
|
|
13
|
-
LOOP_ALIAS: 201,
|
|
14
|
-
// Bootstrap errors
|
|
15
|
-
NOT_BOOTSTRAPPED: 300,
|
|
16
|
-
BOOTSTRAPPED: 301,
|
|
17
|
-
DOUBLE_BOOTSTRAP: 302,
|
|
18
|
-
// Retrieval errors
|
|
19
|
-
NOT_FOUND: 400,
|
|
20
|
-
CIRCULAR_DEPENDENCY: 401,
|
|
21
|
-
// Instantiation errors
|
|
22
|
-
UNTRACKED: 500,
|
|
23
|
-
OUTSIDE_CONTEXT: 501,
|
|
24
|
-
CALLED_UTILS_OUTSIDE_CONTEXT: 502,
|
|
25
|
-
INSTANCE_ACCESS_FAILED: 503,
|
|
26
|
-
ACCESS_FAILED: 504
|
|
27
|
-
};
|
|
28
5
|
var InjectionError = class _InjectionError extends Error {
|
|
29
6
|
static {
|
|
30
7
|
__name(this, "InjectionError");
|
|
@@ -36,70 +13,66 @@ var InjectionError = class _InjectionError extends Error {
|
|
|
36
13
|
}
|
|
37
14
|
// Provider errors
|
|
38
15
|
static duplicate(token) {
|
|
39
|
-
return new _InjectionError(
|
|
16
|
+
return new _InjectionError(100, `Duplicate provider for token "${token.toString()}" detected.`);
|
|
40
17
|
}
|
|
41
18
|
static duplicateFactory(token) {
|
|
42
|
-
return new _InjectionError(
|
|
19
|
+
return new _InjectionError(101, `Tried to re-provide factory for token "${token.toString()}" detected.`);
|
|
43
20
|
}
|
|
44
21
|
static invalidCtor(ctor) {
|
|
45
|
-
return new _InjectionError(
|
|
22
|
+
return new _InjectionError(102, `Cannot use constructor for token "${ctor.name}". Please make sure to use @nodeInjectable() decorator`);
|
|
46
23
|
}
|
|
47
24
|
static invalidProvider(provider) {
|
|
48
|
-
return new _InjectionError(
|
|
25
|
+
return new _InjectionError(103, `Cannot use provider as it is neither a NodeToken nor MultiNodeToken nor a valid constructor.:
|
|
49
26
|
${provider}`);
|
|
50
27
|
}
|
|
51
28
|
// Alias errors
|
|
52
29
|
static invalidAlias(alias) {
|
|
53
30
|
const aliasStr = typeof alias === "function" ? alias.name || "Unknown" : String(alias);
|
|
54
|
-
return new _InjectionError(
|
|
31
|
+
return new _InjectionError(200, `Invalid alias target "${aliasStr}". Alias must be a NodeToken, MultiNodeToken, or a class decorated with @NodeInjectable().`);
|
|
55
32
|
}
|
|
56
33
|
static loopAlias(alias) {
|
|
57
|
-
return new _InjectionError(
|
|
34
|
+
return new _InjectionError(201, `Token "${alias.toString()}" cannot alias itself in a loop.`);
|
|
58
35
|
}
|
|
59
36
|
// Bootstrap errors
|
|
60
37
|
static notBootstrapped() {
|
|
61
|
-
return new _InjectionError(
|
|
38
|
+
return new _InjectionError(300, "Cannot retrieve providers before the container has been bootstrapped.");
|
|
62
39
|
}
|
|
63
40
|
static bootstrapped() {
|
|
64
|
-
return new _InjectionError(
|
|
41
|
+
return new _InjectionError(301, "Cannot modify providers after the container has been bootstrapped.");
|
|
65
42
|
}
|
|
66
43
|
static doubleBootstrap() {
|
|
67
|
-
return new _InjectionError(
|
|
44
|
+
return new _InjectionError(302, "Container has already been bootstrapped and cannot be bootstrapped again.");
|
|
68
45
|
}
|
|
69
46
|
// Retrieval errors
|
|
70
47
|
static notFound(token) {
|
|
71
|
-
return new _InjectionError(
|
|
48
|
+
return new _InjectionError(400, `No provider found for "${token.toString()}".`);
|
|
72
49
|
}
|
|
73
50
|
static circularDependency(provider, path) {
|
|
74
51
|
const providerStr = provider instanceof NodeBase ? provider.toString() : provider.name;
|
|
75
52
|
const pathStr = path.map((p) => p instanceof NodeBase ? p.toString() : p.name).join(" -> ");
|
|
76
|
-
return new _InjectionError(
|
|
53
|
+
return new _InjectionError(401, `Circular dependency detected while resolving "${providerStr}":
|
|
77
54
|
${pathStr}`);
|
|
78
55
|
}
|
|
79
56
|
// Instantiation errors
|
|
80
57
|
static untracked(token, parent) {
|
|
81
58
|
const tokenStr = token instanceof NodeBase ? token.toString() : token.name;
|
|
82
59
|
const parentStr = parent instanceof NodeBase ? parent.toString() : parent.name;
|
|
83
|
-
return new _InjectionError(
|
|
60
|
+
return new _InjectionError(500, `Cannot instantiate ${parentStr} because it depends on untracked injection ${tokenStr}. Please make sure all injections are properly tracked.`);
|
|
84
61
|
}
|
|
85
62
|
static outsideContext(token) {
|
|
86
63
|
const tokenStr = token instanceof NodeBase ? token.toString() : token.name;
|
|
87
|
-
return new _InjectionError(
|
|
64
|
+
return new _InjectionError(501, `Cannot inject "${tokenStr}" outside of an injection context.`);
|
|
88
65
|
}
|
|
89
66
|
static calledUtilsOutsideContext() {
|
|
90
|
-
return new _InjectionError(
|
|
67
|
+
return new _InjectionError(502, "Cannot call injection utilities outside of an injection context.");
|
|
91
68
|
}
|
|
92
69
|
static instanceAccessFailed(token) {
|
|
93
|
-
return new _InjectionError(
|
|
70
|
+
return new _InjectionError(503, `Failed to access instance for token "${token.toString()}". It was not properly instantiated.`);
|
|
94
71
|
}
|
|
95
72
|
static accessFailed() {
|
|
96
|
-
return new _InjectionError(
|
|
73
|
+
return new _InjectionError(504, "Failed to access the requested instance due to an unknown error.");
|
|
97
74
|
}
|
|
98
75
|
};
|
|
99
|
-
function isNotFoundError(error) {
|
|
100
|
-
return error instanceof InjectionError && error.code === ERR_CODES.NOT_FOUND;
|
|
101
|
-
}
|
|
102
|
-
__name(isNotFoundError, "isNotFoundError");
|
|
103
76
|
|
|
104
77
|
// src/lib/api/token.ts
|
|
105
78
|
var NodeBase = class {
|
|
@@ -462,29 +435,23 @@ var TreeRootNode = class {
|
|
|
462
435
|
static {
|
|
463
436
|
__name(this, "TreeRootNode");
|
|
464
437
|
}
|
|
465
|
-
instant;
|
|
466
438
|
_deps = /* @__PURE__ */ new Set();
|
|
467
439
|
_treePool = /* @__PURE__ */ new Map();
|
|
468
|
-
constructor(instant = true) {
|
|
469
|
-
this.instant = instant;
|
|
470
|
-
}
|
|
471
440
|
get dependencies() {
|
|
472
441
|
return this._deps;
|
|
473
442
|
}
|
|
474
443
|
addDependency(node) {
|
|
475
444
|
this._deps.add(node);
|
|
476
445
|
}
|
|
477
|
-
|
|
446
|
+
instantiate() {
|
|
478
447
|
for (const dep of this._deps) {
|
|
448
|
+
dep.instantiate(this._treePool);
|
|
479
449
|
if ("token" in dep.proto) this._treePool.set(dep.proto.token, dep);
|
|
480
|
-
if (this.instant) dep.instantiate(this._treePool);
|
|
481
|
-
else dep.collectPool(this._treePool);
|
|
482
450
|
}
|
|
483
451
|
}
|
|
484
452
|
find(token) {
|
|
485
453
|
const node = this._treePool.get(token);
|
|
486
454
|
if (!node) return null;
|
|
487
|
-
if (!this.instant) node.instantiate(this._treePool);
|
|
488
455
|
return node;
|
|
489
456
|
}
|
|
490
457
|
toString() {
|
|
@@ -515,11 +482,6 @@ var TreeNodeSingle = class {
|
|
|
515
482
|
else this._deps.set(node.proto.token, node);
|
|
516
483
|
node.allocations++;
|
|
517
484
|
}
|
|
518
|
-
collectPool(pool) {
|
|
519
|
-
for (const node of this._deps.values()) node.collectPool(pool);
|
|
520
|
-
for (const dep of this._transparent) dep.collectPool(pool);
|
|
521
|
-
pool.set(this.proto.token, this);
|
|
522
|
-
}
|
|
523
485
|
instantiate(pool) {
|
|
524
486
|
if (this._resolved) return;
|
|
525
487
|
for (const node of this._deps.values()) node.instantiate(pool);
|
|
@@ -557,10 +519,6 @@ var TreeNodeTransparent = class _TreeNodeTransparent {
|
|
|
557
519
|
else this._deps.set(node.proto.token, node);
|
|
558
520
|
node.allocations++;
|
|
559
521
|
}
|
|
560
|
-
collectPool(pool) {
|
|
561
|
-
for (const node of this._deps.values()) node.collectPool(pool);
|
|
562
|
-
for (const dep of this._transparent) dep.collectPool(pool);
|
|
563
|
-
}
|
|
564
522
|
instantiate(pool) {
|
|
565
523
|
if (this._resolved) return;
|
|
566
524
|
for (const dep of this._transparent) dep.instantiate(pool);
|
|
@@ -585,10 +543,6 @@ var TreeNodeMulti = class _TreeNodeMulti {
|
|
|
585
543
|
constructor(proto) {
|
|
586
544
|
this.proto = proto;
|
|
587
545
|
}
|
|
588
|
-
collectPool(pool) {
|
|
589
|
-
for (const dep of this._deps) dep.collectPool(pool);
|
|
590
|
-
pool.set(this.proto.token, this);
|
|
591
|
-
}
|
|
592
546
|
instantiate(pool) {
|
|
593
547
|
if (this._resolved) return;
|
|
594
548
|
for (const dep of this._deps) {
|
|
@@ -765,37 +719,6 @@ var InjectorImpl = class {
|
|
|
765
719
|
};
|
|
766
720
|
var Injector = new NodeToken("Injector");
|
|
767
721
|
|
|
768
|
-
// src/lib/utils/defer.ts
|
|
769
|
-
function injectDefer(provider, options) {
|
|
770
|
-
const injector = nodeInject(Injector);
|
|
771
|
-
let token = provider;
|
|
772
|
-
if (isInjectable(provider)) token = getInjectableToken(provider);
|
|
773
|
-
if (!isNodeBase(token)) throw InjectionError.invalidProvider(String(token));
|
|
774
|
-
let resolved = false;
|
|
775
|
-
let instance = SHAPE_SHIFTER;
|
|
776
|
-
return () => {
|
|
777
|
-
if (resolved) return instance;
|
|
778
|
-
if (options?.optional) {
|
|
779
|
-
try {
|
|
780
|
-
instance = injector.get(token);
|
|
781
|
-
resolved = true;
|
|
782
|
-
return instance;
|
|
783
|
-
} catch (e) {
|
|
784
|
-
if (isNotFoundError(e)) {
|
|
785
|
-
resolved = true;
|
|
786
|
-
instance = null;
|
|
787
|
-
return instance;
|
|
788
|
-
}
|
|
789
|
-
throw e;
|
|
790
|
-
}
|
|
791
|
-
}
|
|
792
|
-
instance = injector.get(token);
|
|
793
|
-
resolved = true;
|
|
794
|
-
return instance;
|
|
795
|
-
};
|
|
796
|
-
}
|
|
797
|
-
__name(injectDefer, "injectDefer");
|
|
798
|
-
|
|
799
722
|
// src/lib/utils/inheritance.ts
|
|
800
723
|
function injectGroupAsync(fn, opts) {
|
|
801
724
|
const { container: parent } = nodeInject(Injector);
|
|
@@ -990,7 +913,7 @@ var NodeContainer = class extends Illuma {
|
|
|
990
913
|
return parentNode.findNode(token);
|
|
991
914
|
}
|
|
992
915
|
_buildInjectionTree() {
|
|
993
|
-
const root = new TreeRootNode(
|
|
916
|
+
const root = new TreeRootNode();
|
|
994
917
|
const cache = /* @__PURE__ */ new Map();
|
|
995
918
|
const nodes = [
|
|
996
919
|
...this._protoNodes.values(),
|
|
@@ -1035,7 +958,7 @@ var NodeContainer = class extends Illuma {
|
|
|
1035
958
|
value: new InjectorImpl(this)
|
|
1036
959
|
});
|
|
1037
960
|
this._rootNode = this._buildInjectionTree();
|
|
1038
|
-
this._rootNode.
|
|
961
|
+
this._rootNode.instantiate();
|
|
1039
962
|
this._bootstrapped = true;
|
|
1040
963
|
const end = performance.now();
|
|
1041
964
|
const duration = end - start;
|
|
@@ -1105,7 +1028,6 @@ var NodeContainer = class extends Illuma {
|
|
|
1105
1028
|
}
|
|
1106
1029
|
};
|
|
1107
1030
|
export {
|
|
1108
|
-
ERR_CODES as ILLUMA_ERR_CODES,
|
|
1109
1031
|
INJECTION_SYMBOL,
|
|
1110
1032
|
InjectionContext,
|
|
1111
1033
|
InjectionError,
|
|
@@ -1119,7 +1041,6 @@ export {
|
|
|
1119
1041
|
extractToken,
|
|
1120
1042
|
getInjectableToken,
|
|
1121
1043
|
injectAsync,
|
|
1122
|
-
injectDefer,
|
|
1123
1044
|
injectEntryAsync,
|
|
1124
1045
|
injectGroupAsync,
|
|
1125
1046
|
isConstructor,
|