assemblerjs 1.1.2 → 1.1.4
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.d.ts +29 -3
- package/dist/index11.js +2 -2
- package/dist/index11.mjs +2 -2
- package/dist/index13.js +2 -2
- package/dist/index13.mjs +2 -2
- package/dist/index16.js +1 -1
- package/dist/index16.mjs +1 -1
- package/dist/index17.js +1 -1
- package/dist/index17.mjs +1 -1
- package/dist/index18.js +1 -1
- package/dist/index18.mjs +1 -1
- package/dist/index19.js +1 -1
- package/dist/index19.mjs +1 -1
- package/dist/index2.js +2 -2
- package/dist/index2.mjs +2 -2
- package/dist/index20.js +1 -1
- package/dist/index20.mjs +1 -1
- package/dist/index21.js +1 -1
- package/dist/index21.mjs +1 -1
- package/dist/index22.js +2 -2
- package/dist/index22.mjs +2 -2
- package/dist/index23.js +2 -2
- package/dist/index23.mjs +2 -2
- package/dist/index24.js +2 -2
- package/dist/index24.mjs +2 -2
- package/dist/index25.js +1 -1
- package/dist/index25.mjs +1 -1
- package/dist/index26.js +1 -1
- package/dist/index26.mjs +1 -1
- package/dist/index27.js +1 -1
- package/dist/index27.mjs +1 -1
- package/dist/index29.js +15 -38
- package/dist/index29.mjs +12 -37
- package/dist/index3.js +1 -1
- package/dist/index3.mjs +1 -1
- package/dist/index30.js +100 -58
- package/dist/index30.mjs +98 -58
- package/dist/index31.js +63 -20
- package/dist/index31.mjs +63 -20
- package/dist/index32.js +23 -57
- package/dist/index32.mjs +23 -57
- package/dist/index33.js +75 -27
- package/dist/index33.mjs +75 -27
- package/dist/index34.js +39 -29
- package/dist/index34.mjs +39 -29
- package/dist/index35.js +32 -18
- package/dist/index35.mjs +32 -15
- package/dist/index36.js +128 -101
- package/dist/index36.mjs +128 -99
- package/dist/index37.js +35 -100
- package/dist/index37.mjs +34 -100
- package/dist/index38.js +18 -24
- package/dist/index38.mjs +18 -24
- package/dist/index39.js +101 -18
- package/dist/index39.mjs +101 -18
- package/dist/index4.js +23 -10
- package/dist/index4.mjs +23 -10
- package/dist/index40.js +25 -25
- package/dist/index40.mjs +25 -24
- package/dist/index41.js +44 -18
- package/dist/index41.mjs +44 -17
- package/dist/index42.js +18 -44
- package/dist/index42.mjs +17 -44
- package/dist/index43.js +26 -191
- package/dist/index43.mjs +25 -191
- package/dist/index44.js +192 -940
- package/dist/index44.mjs +192 -940
- package/dist/index45.js +942 -2
- package/dist/index45.mjs +942 -2
- package/dist/index46.js +2 -2
- package/dist/index46.mjs +2 -2
- package/dist/index47.js +2 -14
- package/dist/index47.mjs +2 -14
- package/dist/index48.js +9 -34
- package/dist/index48.mjs +9 -34
- package/dist/index49.js +32 -55
- package/dist/index49.mjs +32 -54
- package/dist/index50.js +67 -0
- package/dist/index50.mjs +62 -0
- package/package.json +1 -1
package/dist/index30.js
CHANGED
|
@@ -2,70 +2,112 @@
|
|
|
2
2
|
|
|
3
3
|
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
4
4
|
|
|
5
|
-
const
|
|
6
|
-
const
|
|
7
|
-
const
|
|
8
|
-
const inject = require('./index42.js');
|
|
9
|
-
const injectable = require('./index43.js');
|
|
5
|
+
const constants = require('./index28.js');
|
|
6
|
+
const reflection = require('./index29.js');
|
|
7
|
+
const helpers = require('./index3.js');
|
|
10
8
|
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
throw new Error(`An assemblage is already registered with identifier '${o.identifier.name}'.`);
|
|
20
|
-
}
|
|
21
|
-
const a = injectable.Injectable.of(o, this.privateContext, this.publicContext);
|
|
22
|
-
this.injectables.set(a.identifier, a);
|
|
23
|
-
if (a.concrete) {
|
|
24
|
-
hookManager.HookManager.callHook(a.concrete, 'onRegister', this.publicContext, a.configuration);
|
|
25
|
-
}
|
|
26
|
-
return a;
|
|
27
|
-
}
|
|
28
|
-
has(e) {
|
|
29
|
-
return this.injectables.has(e);
|
|
30
|
-
}
|
|
31
|
-
require(e, t) {
|
|
32
|
-
if (!this.injectables.has(e)) {
|
|
33
|
-
throw new Error(`Class with identifier '${e.name}' has not been registered or is a circular dependency.`);
|
|
34
|
-
}
|
|
35
|
-
const i = this.injectables.get(e);
|
|
36
|
-
if (i.isSingleton) {
|
|
37
|
-
return this.singletonStrategy.resolve(i, t);
|
|
38
|
-
} else {
|
|
39
|
-
return this.transientStrategy.resolve(i, t);
|
|
9
|
+
const n = {
|
|
10
|
+
singleton: {
|
|
11
|
+
test: (r)=>typeof r === 'boolean' || typeof r === 'undefined',
|
|
12
|
+
throw: ()=>{
|
|
13
|
+
throw new Error(`'singleton' property must be of type 'boolean' or 'undefined'.`);
|
|
14
|
+
},
|
|
15
|
+
transform: (r)=>{
|
|
16
|
+
return typeof r === 'undefined' ? true : r ? true : false;
|
|
40
17
|
}
|
|
18
|
+
},
|
|
19
|
+
events: {
|
|
20
|
+
test: (r)=>typeof r === 'undefined' || Array.isArray(r) && r.every((r)=>typeof r === 'string'),
|
|
21
|
+
throw: ()=>{
|
|
22
|
+
throw new Error(`'events' property must be an array of strings or 'undefined'.`);
|
|
23
|
+
},
|
|
24
|
+
transform: (r)=>r
|
|
25
|
+
},
|
|
26
|
+
inject: {
|
|
27
|
+
test: (r)=>typeof r === 'undefined' || Array.isArray(r) && r.every((r)=>Array.isArray(r) && r.length >= 1 && r.length <= 3),
|
|
28
|
+
throw: ()=>{
|
|
29
|
+
throw new Error(`'inject' property must be an array of tuples of length 1, 2 or 3.`);
|
|
30
|
+
},
|
|
31
|
+
transform: (r)=>r
|
|
32
|
+
},
|
|
33
|
+
use: {
|
|
34
|
+
test: (r)=>typeof r === 'undefined' || Array.isArray(r) && r.every((r)=>{
|
|
35
|
+
if (!Array.isArray(r) || r.length !== 2) {
|
|
36
|
+
return false;
|
|
37
|
+
}
|
|
38
|
+
const e = r[1];
|
|
39
|
+
return typeof e !== 'undefined';
|
|
40
|
+
}),
|
|
41
|
+
throw: ()=>{
|
|
42
|
+
throw new Error(`'use' property must be an array of tuples of length 2 with [identifier, instance | factory].`);
|
|
43
|
+
},
|
|
44
|
+
transform: (r)=>r
|
|
45
|
+
},
|
|
46
|
+
engage: {
|
|
47
|
+
test: (r)=>typeof r === 'undefined' || Array.isArray(r) && r.every((r)=>Array.isArray(r) && r.length >= 1 && r.length <= 3),
|
|
48
|
+
throw: ()=>{
|
|
49
|
+
throw new Error(`'engage' property must be an array of tuples of length 1, 2 or 3.`);
|
|
50
|
+
},
|
|
51
|
+
transform: (r)=>r
|
|
52
|
+
},
|
|
53
|
+
tags: {
|
|
54
|
+
test: (r)=>typeof r === 'undefined' || typeof r === 'string' || Array.isArray(r) && r.every((r)=>typeof r === 'string'),
|
|
55
|
+
throw: ()=>{
|
|
56
|
+
throw new Error(`'tags' property must be a string or an array of strings.`);
|
|
57
|
+
},
|
|
58
|
+
transform: (r)=>typeof r === 'string' ? [
|
|
59
|
+
r
|
|
60
|
+
] : r
|
|
61
|
+
},
|
|
62
|
+
metadata: {
|
|
63
|
+
test: (r)=>(typeof r === 'object' || typeof r === 'undefined') && !Array.isArray(r),
|
|
64
|
+
throw: ()=>{
|
|
65
|
+
throw new Error(`'metadata' property must be of type 'object' or 'undefined'.`);
|
|
66
|
+
},
|
|
67
|
+
transform: (r)=>r
|
|
68
|
+
},
|
|
69
|
+
global: {
|
|
70
|
+
test: (r)=>(typeof r === 'object' || typeof r === 'undefined') && !Array.isArray(r),
|
|
71
|
+
throw: ()=>{
|
|
72
|
+
throw new Error(`'global' property must be of type 'object' or 'undefined'.`);
|
|
73
|
+
},
|
|
74
|
+
transform: (r)=>r
|
|
41
75
|
}
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
for (const [e, s] of this.injectables){
|
|
51
|
-
if (s.tags.includes(i)) t.push(s.build());
|
|
52
|
-
}
|
|
76
|
+
};
|
|
77
|
+
const validateDefinition = (r)=>{
|
|
78
|
+
const e = {
|
|
79
|
+
...r
|
|
80
|
+
};
|
|
81
|
+
for(const r in e){
|
|
82
|
+
if (!Object.keys(n).includes(r)) {
|
|
83
|
+
throw new Error(`Property '${r}' is not a valid assemblage definition property.`);
|
|
53
84
|
}
|
|
54
|
-
return t;
|
|
55
85
|
}
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
86
|
+
for(const r in n){
|
|
87
|
+
const t = n[r].test;
|
|
88
|
+
const o = n[r].throw;
|
|
89
|
+
const s = n[r].transform;
|
|
90
|
+
if (!t(e[r])) {
|
|
91
|
+
o();
|
|
59
92
|
}
|
|
93
|
+
e[r] = s(e[r]);
|
|
60
94
|
}
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
this.singletonStrategy = new resolutionStrategies.SingletonStrategy();
|
|
67
|
-
this.transientStrategy = new resolutionStrategies.TransientStrategy();
|
|
95
|
+
return e;
|
|
96
|
+
};
|
|
97
|
+
const getDefinition = (e)=>{
|
|
98
|
+
if (!helpers.isAssemblage(e)) {
|
|
99
|
+
throw new Error(`Class '${e.name}' is not an assemblage or transversal.`);
|
|
68
100
|
}
|
|
69
|
-
|
|
101
|
+
return reflection.getOwnCustomMetadata(constants.ReflectValue.AssemblageDefinition, e);
|
|
102
|
+
};
|
|
103
|
+
const setDefinitionValue = (t, o, n)=>{
|
|
104
|
+
const s = getDefinition(n);
|
|
105
|
+
s[t] = o;
|
|
106
|
+
const a = validateDefinition(s);
|
|
107
|
+
reflection.defineCustomMetadata(constants.ReflectValue.AssemblageDefinition, a, n);
|
|
108
|
+
return a;
|
|
109
|
+
};
|
|
70
110
|
|
|
71
|
-
exports.
|
|
111
|
+
exports.getDefinition = getDefinition;
|
|
112
|
+
exports.setDefinitionValue = setDefinitionValue;
|
|
113
|
+
exports.validateDefinition = validateDefinition;
|
package/dist/index30.mjs
CHANGED
|
@@ -1,67 +1,107 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import { resolveInjectionTuple } from './index42.mjs';
|
|
5
|
-
import { Injectable } from './index43.mjs';
|
|
1
|
+
import { ReflectValue } from './index28.mjs';
|
|
2
|
+
import { getOwnCustomMetadata, defineCustomMetadata } from './index29.mjs';
|
|
3
|
+
import { isAssemblage } from './index3.mjs';
|
|
6
4
|
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
throw new Error(`An assemblage is already registered with identifier '${o.identifier.name}'.`);
|
|
16
|
-
}
|
|
17
|
-
const a = Injectable.of(o, this.privateContext, this.publicContext);
|
|
18
|
-
this.injectables.set(a.identifier, a);
|
|
19
|
-
if (a.concrete) {
|
|
20
|
-
HookManager.callHook(a.concrete, 'onRegister', this.publicContext, a.configuration);
|
|
21
|
-
}
|
|
22
|
-
return a;
|
|
23
|
-
}
|
|
24
|
-
has(e) {
|
|
25
|
-
return this.injectables.has(e);
|
|
26
|
-
}
|
|
27
|
-
require(e, t) {
|
|
28
|
-
if (!this.injectables.has(e)) {
|
|
29
|
-
throw new Error(`Class with identifier '${e.name}' has not been registered or is a circular dependency.`);
|
|
30
|
-
}
|
|
31
|
-
const i = this.injectables.get(e);
|
|
32
|
-
if (i.isSingleton) {
|
|
33
|
-
return this.singletonStrategy.resolve(i, t);
|
|
34
|
-
} else {
|
|
35
|
-
return this.transientStrategy.resolve(i, t);
|
|
5
|
+
const n = {
|
|
6
|
+
singleton: {
|
|
7
|
+
test: (r)=>typeof r === 'boolean' || typeof r === 'undefined',
|
|
8
|
+
throw: ()=>{
|
|
9
|
+
throw new Error(`'singleton' property must be of type 'boolean' or 'undefined'.`);
|
|
10
|
+
},
|
|
11
|
+
transform: (r)=>{
|
|
12
|
+
return typeof r === 'undefined' ? true : r ? true : false;
|
|
36
13
|
}
|
|
14
|
+
},
|
|
15
|
+
events: {
|
|
16
|
+
test: (r)=>typeof r === 'undefined' || Array.isArray(r) && r.every((r)=>typeof r === 'string'),
|
|
17
|
+
throw: ()=>{
|
|
18
|
+
throw new Error(`'events' property must be an array of strings or 'undefined'.`);
|
|
19
|
+
},
|
|
20
|
+
transform: (r)=>r
|
|
21
|
+
},
|
|
22
|
+
inject: {
|
|
23
|
+
test: (r)=>typeof r === 'undefined' || Array.isArray(r) && r.every((r)=>Array.isArray(r) && r.length >= 1 && r.length <= 3),
|
|
24
|
+
throw: ()=>{
|
|
25
|
+
throw new Error(`'inject' property must be an array of tuples of length 1, 2 or 3.`);
|
|
26
|
+
},
|
|
27
|
+
transform: (r)=>r
|
|
28
|
+
},
|
|
29
|
+
use: {
|
|
30
|
+
test: (r)=>typeof r === 'undefined' || Array.isArray(r) && r.every((r)=>{
|
|
31
|
+
if (!Array.isArray(r) || r.length !== 2) {
|
|
32
|
+
return false;
|
|
33
|
+
}
|
|
34
|
+
const e = r[1];
|
|
35
|
+
return typeof e !== 'undefined';
|
|
36
|
+
}),
|
|
37
|
+
throw: ()=>{
|
|
38
|
+
throw new Error(`'use' property must be an array of tuples of length 2 with [identifier, instance | factory].`);
|
|
39
|
+
},
|
|
40
|
+
transform: (r)=>r
|
|
41
|
+
},
|
|
42
|
+
engage: {
|
|
43
|
+
test: (r)=>typeof r === 'undefined' || Array.isArray(r) && r.every((r)=>Array.isArray(r) && r.length >= 1 && r.length <= 3),
|
|
44
|
+
throw: ()=>{
|
|
45
|
+
throw new Error(`'engage' property must be an array of tuples of length 1, 2 or 3.`);
|
|
46
|
+
},
|
|
47
|
+
transform: (r)=>r
|
|
48
|
+
},
|
|
49
|
+
tags: {
|
|
50
|
+
test: (r)=>typeof r === 'undefined' || typeof r === 'string' || Array.isArray(r) && r.every((r)=>typeof r === 'string'),
|
|
51
|
+
throw: ()=>{
|
|
52
|
+
throw new Error(`'tags' property must be a string or an array of strings.`);
|
|
53
|
+
},
|
|
54
|
+
transform: (r)=>typeof r === 'string' ? [
|
|
55
|
+
r
|
|
56
|
+
] : r
|
|
57
|
+
},
|
|
58
|
+
metadata: {
|
|
59
|
+
test: (r)=>(typeof r === 'object' || typeof r === 'undefined') && !Array.isArray(r),
|
|
60
|
+
throw: ()=>{
|
|
61
|
+
throw new Error(`'metadata' property must be of type 'object' or 'undefined'.`);
|
|
62
|
+
},
|
|
63
|
+
transform: (r)=>r
|
|
64
|
+
},
|
|
65
|
+
global: {
|
|
66
|
+
test: (r)=>(typeof r === 'object' || typeof r === 'undefined') && !Array.isArray(r),
|
|
67
|
+
throw: ()=>{
|
|
68
|
+
throw new Error(`'global' property must be of type 'object' or 'undefined'.`);
|
|
69
|
+
},
|
|
70
|
+
transform: (r)=>r
|
|
37
71
|
}
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
for (const [e, s] of this.injectables){
|
|
47
|
-
if (s.tags.includes(i)) t.push(s.build());
|
|
48
|
-
}
|
|
72
|
+
};
|
|
73
|
+
const validateDefinition = (r)=>{
|
|
74
|
+
const e = {
|
|
75
|
+
...r
|
|
76
|
+
};
|
|
77
|
+
for(const r in e){
|
|
78
|
+
if (!Object.keys(n).includes(r)) {
|
|
79
|
+
throw new Error(`Property '${r}' is not a valid assemblage definition property.`);
|
|
49
80
|
}
|
|
50
|
-
return t;
|
|
51
81
|
}
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
82
|
+
for(const r in n){
|
|
83
|
+
const t = n[r].test;
|
|
84
|
+
const o = n[r].throw;
|
|
85
|
+
const s = n[r].transform;
|
|
86
|
+
if (!t(e[r])) {
|
|
87
|
+
o();
|
|
55
88
|
}
|
|
89
|
+
e[r] = s(e[r]);
|
|
56
90
|
}
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
this.singletonStrategy = new SingletonStrategy();
|
|
63
|
-
this.transientStrategy = new TransientStrategy();
|
|
91
|
+
return e;
|
|
92
|
+
};
|
|
93
|
+
const getDefinition = (e)=>{
|
|
94
|
+
if (!isAssemblage(e)) {
|
|
95
|
+
throw new Error(`Class '${e.name}' is not an assemblage or transversal.`);
|
|
64
96
|
}
|
|
65
|
-
|
|
97
|
+
return getOwnCustomMetadata(ReflectValue.AssemblageDefinition, e);
|
|
98
|
+
};
|
|
99
|
+
const setDefinitionValue = (t, o, n)=>{
|
|
100
|
+
const s = getDefinition(n);
|
|
101
|
+
s[t] = o;
|
|
102
|
+
const a = validateDefinition(s);
|
|
103
|
+
defineCustomMetadata(ReflectValue.AssemblageDefinition, a, n);
|
|
104
|
+
return a;
|
|
105
|
+
};
|
|
66
106
|
|
|
67
|
-
export {
|
|
107
|
+
export { getDefinition, setDefinitionValue, validateDefinition };
|
package/dist/index31.js
CHANGED
|
@@ -2,36 +2,79 @@
|
|
|
2
2
|
|
|
3
3
|
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
4
4
|
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
5
|
+
const hookManager = require('./index33.js');
|
|
6
|
+
const resolutionStrategies = require('./index43.js');
|
|
7
|
+
const debugLogger = require('./index36.js');
|
|
8
|
+
const use = require('./index42.js');
|
|
9
|
+
const inject = require('./index41.js');
|
|
10
|
+
const injectable = require('./index44.js');
|
|
11
|
+
|
|
12
|
+
class InjectableManager {
|
|
13
|
+
setContexts(e, t) {
|
|
14
|
+
this.privateContext = e;
|
|
15
|
+
this.publicContext = t;
|
|
16
|
+
}
|
|
17
|
+
register(s, n = false) {
|
|
18
|
+
const a = debugLogger.DebugLogger.getInstance();
|
|
19
|
+
const c = n === true ? use.resolveInstanceInjectionTuple(s) : inject.resolveInjectionTuple(s);
|
|
20
|
+
if (this.has(c.identifier)) {
|
|
21
|
+
throw new Error(`An assemblage is already registered with identifier '${c.identifier.name}'.`);
|
|
9
22
|
}
|
|
10
|
-
|
|
11
|
-
|
|
23
|
+
const l = injectable.Injectable.of(c, this.privateContext, this.publicContext);
|
|
24
|
+
a.logRegistration(l);
|
|
25
|
+
this.injectables.set(l.identifier, l);
|
|
26
|
+
if (l.concrete) {
|
|
27
|
+
hookManager.HookManager.callHook(l.concrete, 'onRegister', this.publicContext, l.configuration);
|
|
28
|
+
}
|
|
29
|
+
return l;
|
|
12
30
|
}
|
|
13
31
|
has(e) {
|
|
14
|
-
return this.
|
|
32
|
+
return this.injectables.has(e);
|
|
15
33
|
}
|
|
16
|
-
require(e) {
|
|
17
|
-
if (!this.
|
|
18
|
-
|
|
34
|
+
require(e, t, i) {
|
|
35
|
+
if (!this.injectables.has(e)) {
|
|
36
|
+
const t = `Class with identifier '${e.name}' has not been registered or is a circular dependency.`;
|
|
37
|
+
debugLogger.DebugLogger.getInstance().log('error', 'Resolution failed', {
|
|
38
|
+
identifier: e.name,
|
|
39
|
+
caller: i ? i?.name || String(i) : 'unknown',
|
|
40
|
+
error: t
|
|
41
|
+
});
|
|
42
|
+
throw new Error(t);
|
|
43
|
+
}
|
|
44
|
+
const r = this.injectables.get(e);
|
|
45
|
+
if (r.isSingleton) {
|
|
46
|
+
return this.singletonStrategy.resolve(r, t);
|
|
47
|
+
} else {
|
|
48
|
+
return this.transientStrategy.resolve(r, t);
|
|
19
49
|
}
|
|
20
|
-
return this.objects.get(e);
|
|
21
50
|
}
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
51
|
+
concrete(e) {
|
|
52
|
+
const t = this.injectables.get(e);
|
|
53
|
+
if (t) return t.concrete;
|
|
54
|
+
return;
|
|
55
|
+
}
|
|
56
|
+
tagged(...e) {
|
|
57
|
+
const t = [];
|
|
58
|
+
for (const i of e){
|
|
59
|
+
for (const [e, r] of this.injectables){
|
|
60
|
+
if (r.tags.includes(i)) t.push(r.build());
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
return t;
|
|
64
|
+
}
|
|
65
|
+
dispose() {
|
|
66
|
+
for (const [e, t] of this.injectables){
|
|
67
|
+
t.dispose();
|
|
25
68
|
}
|
|
26
|
-
this.globals.set(e, t);
|
|
27
69
|
}
|
|
28
|
-
|
|
29
|
-
return this.
|
|
70
|
+
get size() {
|
|
71
|
+
return this.injectables.size;
|
|
30
72
|
}
|
|
31
73
|
constructor(){
|
|
32
|
-
this.
|
|
33
|
-
this.
|
|
74
|
+
this.injectables = new Map();
|
|
75
|
+
this.singletonStrategy = new resolutionStrategies.SingletonStrategy();
|
|
76
|
+
this.transientStrategy = new resolutionStrategies.TransientStrategy();
|
|
34
77
|
}
|
|
35
78
|
}
|
|
36
79
|
|
|
37
|
-
exports.
|
|
80
|
+
exports.InjectableManager = InjectableManager;
|
package/dist/index31.mjs
CHANGED
|
@@ -1,33 +1,76 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
import { HookManager } from './index33.mjs';
|
|
2
|
+
import { SingletonStrategy, TransientStrategy } from './index43.mjs';
|
|
3
|
+
import { DebugLogger } from './index36.mjs';
|
|
4
|
+
import { resolveInstanceInjectionTuple } from './index42.mjs';
|
|
5
|
+
import { resolveInjectionTuple } from './index41.mjs';
|
|
6
|
+
import { Injectable } from './index44.mjs';
|
|
7
|
+
|
|
8
|
+
class InjectableManager {
|
|
9
|
+
setContexts(e, t) {
|
|
10
|
+
this.privateContext = e;
|
|
11
|
+
this.publicContext = t;
|
|
12
|
+
}
|
|
13
|
+
register(s, n = false) {
|
|
14
|
+
const a = DebugLogger.getInstance();
|
|
15
|
+
const c = n === true ? resolveInstanceInjectionTuple(s) : resolveInjectionTuple(s);
|
|
16
|
+
if (this.has(c.identifier)) {
|
|
17
|
+
throw new Error(`An assemblage is already registered with identifier '${c.identifier.name}'.`);
|
|
5
18
|
}
|
|
6
|
-
|
|
7
|
-
|
|
19
|
+
const l = Injectable.of(c, this.privateContext, this.publicContext);
|
|
20
|
+
a.logRegistration(l);
|
|
21
|
+
this.injectables.set(l.identifier, l);
|
|
22
|
+
if (l.concrete) {
|
|
23
|
+
HookManager.callHook(l.concrete, 'onRegister', this.publicContext, l.configuration);
|
|
24
|
+
}
|
|
25
|
+
return l;
|
|
8
26
|
}
|
|
9
27
|
has(e) {
|
|
10
|
-
return this.
|
|
28
|
+
return this.injectables.has(e);
|
|
11
29
|
}
|
|
12
|
-
require(e) {
|
|
13
|
-
if (!this.
|
|
14
|
-
|
|
30
|
+
require(e, t, i) {
|
|
31
|
+
if (!this.injectables.has(e)) {
|
|
32
|
+
const t = `Class with identifier '${e.name}' has not been registered or is a circular dependency.`;
|
|
33
|
+
DebugLogger.getInstance().log('error', 'Resolution failed', {
|
|
34
|
+
identifier: e.name,
|
|
35
|
+
caller: i ? i?.name || String(i) : 'unknown',
|
|
36
|
+
error: t
|
|
37
|
+
});
|
|
38
|
+
throw new Error(t);
|
|
39
|
+
}
|
|
40
|
+
const r = this.injectables.get(e);
|
|
41
|
+
if (r.isSingleton) {
|
|
42
|
+
return this.singletonStrategy.resolve(r, t);
|
|
43
|
+
} else {
|
|
44
|
+
return this.transientStrategy.resolve(r, t);
|
|
15
45
|
}
|
|
16
|
-
return this.objects.get(e);
|
|
17
46
|
}
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
47
|
+
concrete(e) {
|
|
48
|
+
const t = this.injectables.get(e);
|
|
49
|
+
if (t) return t.concrete;
|
|
50
|
+
return;
|
|
51
|
+
}
|
|
52
|
+
tagged(...e) {
|
|
53
|
+
const t = [];
|
|
54
|
+
for (const i of e){
|
|
55
|
+
for (const [e, r] of this.injectables){
|
|
56
|
+
if (r.tags.includes(i)) t.push(r.build());
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
return t;
|
|
60
|
+
}
|
|
61
|
+
dispose() {
|
|
62
|
+
for (const [e, t] of this.injectables){
|
|
63
|
+
t.dispose();
|
|
21
64
|
}
|
|
22
|
-
this.globals.set(e, t);
|
|
23
65
|
}
|
|
24
|
-
|
|
25
|
-
return this.
|
|
66
|
+
get size() {
|
|
67
|
+
return this.injectables.size;
|
|
26
68
|
}
|
|
27
69
|
constructor(){
|
|
28
|
-
this.
|
|
29
|
-
this.
|
|
70
|
+
this.injectables = new Map();
|
|
71
|
+
this.singletonStrategy = new SingletonStrategy();
|
|
72
|
+
this.transientStrategy = new TransientStrategy();
|
|
30
73
|
}
|
|
31
74
|
}
|
|
32
75
|
|
|
33
|
-
export {
|
|
76
|
+
export { InjectableManager };
|
package/dist/index32.js
CHANGED
|
@@ -2,70 +2,36 @@
|
|
|
2
2
|
|
|
3
3
|
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
4
4
|
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
this.initCache.push({
|
|
10
|
-
instance: e,
|
|
11
|
-
configuration: t
|
|
12
|
-
});
|
|
13
|
-
return this.initCache;
|
|
14
|
-
}
|
|
15
|
-
callInitHooks(e) {
|
|
16
|
-
for (const t of this.initCache){
|
|
17
|
-
HookManager.callHookImmediate(t.instance, 'onInit', e, t.configuration);
|
|
5
|
+
class ObjectManager {
|
|
6
|
+
use(e, t) {
|
|
7
|
+
if (this.has(e)) {
|
|
8
|
+
throw new Error(`A value is already registered with identifier '${String(e)}'.`);
|
|
18
9
|
}
|
|
10
|
+
this.objects.set(e, t);
|
|
11
|
+
return t;
|
|
19
12
|
}
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
13
|
+
has(e) {
|
|
14
|
+
return this.objects.has(e);
|
|
15
|
+
}
|
|
16
|
+
require(e) {
|
|
17
|
+
if (!this.objects.has(e)) {
|
|
18
|
+
throw new Error(`Injected object with identifier '${String(e)}' has not been registered.`);
|
|
25
19
|
}
|
|
20
|
+
return this.objects.get(e);
|
|
26
21
|
}
|
|
27
|
-
|
|
28
|
-
this.
|
|
22
|
+
addGlobal(e, t) {
|
|
23
|
+
if (this.globals.has(e)) {
|
|
24
|
+
throw new Error(`Global value with key '${e}' has already been registered.`);
|
|
25
|
+
}
|
|
26
|
+
this.globals.set(e, t);
|
|
29
27
|
}
|
|
30
|
-
|
|
31
|
-
return this.
|
|
28
|
+
global(e) {
|
|
29
|
+
return this.globals.get(e);
|
|
32
30
|
}
|
|
33
31
|
constructor(){
|
|
34
|
-
this.
|
|
32
|
+
this.objects = new Map();
|
|
33
|
+
this.globals = new Map();
|
|
35
34
|
}
|
|
36
35
|
}
|
|
37
|
-
HookManager.callHook = (t, i, o, n)=>{
|
|
38
|
-
return new Promise((a, c)=>{
|
|
39
|
-
const r = t[i];
|
|
40
|
-
if (r) {
|
|
41
|
-
if (core.isAsync(r)) {
|
|
42
|
-
r.bind(t)(o, n).then(()=>{
|
|
43
|
-
a();
|
|
44
|
-
}).catch((e)=>{
|
|
45
|
-
c(e);
|
|
46
|
-
});
|
|
47
|
-
return;
|
|
48
|
-
}
|
|
49
|
-
try {
|
|
50
|
-
r.bind(t)(o, n);
|
|
51
|
-
a();
|
|
52
|
-
} catch (e) {
|
|
53
|
-
c(e);
|
|
54
|
-
}
|
|
55
|
-
} else {
|
|
56
|
-
a();
|
|
57
|
-
}
|
|
58
|
-
});
|
|
59
|
-
};
|
|
60
|
-
HookManager.callHookImmediate = (t, i, o, n)=>{
|
|
61
|
-
const a = t[i];
|
|
62
|
-
if (a) {
|
|
63
|
-
if (core.isAsync(a)) {
|
|
64
|
-
a.bind(t)(o, n).catch(()=>{});
|
|
65
|
-
return;
|
|
66
|
-
}
|
|
67
|
-
a.bind(t)(o, n);
|
|
68
|
-
}
|
|
69
|
-
};
|
|
70
36
|
|
|
71
|
-
exports.
|
|
37
|
+
exports.ObjectManager = ObjectManager;
|