assemblerjs 1.1.8 → 1.1.9
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/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/index29.js +38 -15
- package/dist/index29.mjs +37 -12
- package/dist/index3.js +1 -1
- package/dist/index3.mjs +1 -1
- package/dist/index30.js +130 -100
- package/dist/index30.mjs +130 -98
- package/dist/index31.js +36 -123
- package/dist/index31.mjs +36 -123
- package/dist/index32.js +70 -41
- package/dist/index32.mjs +70 -41
- package/dist/index33.js +37 -75
- package/dist/index33.mjs +37 -75
- package/dist/index34.js +29 -39
- package/dist/index34.mjs +29 -39
- package/dist/index35.js +151 -26
- package/dist/index35.mjs +151 -26
- package/dist/index36.js +16 -133
- package/dist/index36.mjs +13 -133
- package/dist/index37.js +100 -33
- package/dist/index37.mjs +98 -32
- package/dist/index38.js +101 -18
- package/dist/index38.mjs +101 -18
- package/dist/index39.js +24 -101
- package/dist/index39.mjs +24 -101
- package/dist/index4.js +6 -6
- package/dist/index4.mjs +6 -6
- package/dist/index40.js +18 -24
- package/dist/index40.mjs +18 -24
- package/dist/index44.js +4 -4
- package/dist/index44.mjs +4 -4
- package/dist/index48.js +1 -1
- package/dist/index48.mjs +1 -1
- package/dist/index49.js +2 -2
- package/dist/index49.mjs +2 -2
- package/dist/index50.js +1 -1
- package/dist/index50.mjs +1 -1
- package/package.json +1 -1
package/dist/index30.js
CHANGED
|
@@ -2,112 +2,142 @@
|
|
|
2
2
|
|
|
3
3
|
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
4
4
|
|
|
5
|
-
const
|
|
6
|
-
const
|
|
7
|
-
const
|
|
5
|
+
const hookManager = require('./index32.js');
|
|
6
|
+
const resolutionStrategies = require('./index41.js');
|
|
7
|
+
const debugLogger = require('./index35.js');
|
|
8
|
+
const core = require('@assemblerjs/core');
|
|
9
|
+
const use = require('./index42.js');
|
|
10
|
+
const inject = require('./index43.js');
|
|
11
|
+
const injectable = require('./index44.js');
|
|
8
12
|
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
return typeof r === 'undefined' ? true : r ? true : false;
|
|
13
|
+
function a(e) {
|
|
14
|
+
if (e === undefined) return 'undefined';
|
|
15
|
+
if (e === null) return 'null';
|
|
16
|
+
if (typeof e === 'function') {
|
|
17
|
+
if (e.name) return e.name;
|
|
18
|
+
if (e.constructor?.name && e.constructor.name !== 'Function') {
|
|
19
|
+
return e.constructor.name;
|
|
17
20
|
}
|
|
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
|
|
21
|
+
return 'AnonymousFunction';
|
|
75
22
|
}
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
throw new Error(`Property '${r}' is not a valid assemblage definition property.`);
|
|
23
|
+
if (typeof e === 'string') return e;
|
|
24
|
+
if (typeof e === 'symbol') return e.toString();
|
|
25
|
+
if (typeof e === 'number') return String(e);
|
|
26
|
+
if (typeof e === 'boolean') return String(e);
|
|
27
|
+
if (typeof e === 'object') {
|
|
28
|
+
if (e.name && typeof e.name === 'string') {
|
|
29
|
+
return e.name;
|
|
84
30
|
}
|
|
31
|
+
try {
|
|
32
|
+
const t = JSON.stringify(e);
|
|
33
|
+
if (t.length > 100) {
|
|
34
|
+
return t.substring(0, 100) + '...';
|
|
35
|
+
}
|
|
36
|
+
return t;
|
|
37
|
+
} catch {
|
|
38
|
+
const t = e.constructor?.name;
|
|
39
|
+
if (t && t !== 'Object') {
|
|
40
|
+
return `[${t}]`;
|
|
41
|
+
}
|
|
42
|
+
return '[UnknownObject]';
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
return String(e);
|
|
46
|
+
}
|
|
47
|
+
function f(e) {
|
|
48
|
+
if (core.isClass(e)) {
|
|
49
|
+
const t = e.prototype && Object.getOwnPropertyNames(e.prototype).length > 1;
|
|
50
|
+
return t ? 'class' : 'class';
|
|
51
|
+
}
|
|
52
|
+
if (typeof e === 'function') return 'function';
|
|
53
|
+
if (typeof e === 'string') return 'string';
|
|
54
|
+
if (typeof e === 'symbol') return 'symbol';
|
|
55
|
+
if (typeof e === 'object' && e !== null) return 'object';
|
|
56
|
+
return 'unknown';
|
|
57
|
+
}
|
|
58
|
+
class InjectableManager {
|
|
59
|
+
setContexts(e, t) {
|
|
60
|
+
this.privateContext = e;
|
|
61
|
+
this.publicContext = t;
|
|
62
|
+
}
|
|
63
|
+
register(i, o = false) {
|
|
64
|
+
const c = debugLogger.DebugLogger.getInstance();
|
|
65
|
+
const a = o === true ? use.resolveInstanceInjectionTuple(i) : inject.resolveInjectionTuple(i);
|
|
66
|
+
if (this.has(a.identifier)) {
|
|
67
|
+
const e = `An assemblage is already registered with identifier '${a.identifier.name}'.`;
|
|
68
|
+
c.log('error', 'Duplicate registration', {
|
|
69
|
+
identifier: a.identifier.name,
|
|
70
|
+
error: e
|
|
71
|
+
});
|
|
72
|
+
throw new Error(e);
|
|
73
|
+
}
|
|
74
|
+
const f = injectable.Injectable.of(a, this.privateContext, this.publicContext);
|
|
75
|
+
c.logRegistration(f);
|
|
76
|
+
this.injectables.set(f.identifier, f);
|
|
77
|
+
if (f.concrete) {
|
|
78
|
+
hookManager.HookManager.callHook(f.concrete, 'onRegister', this.publicContext, f.configuration);
|
|
79
|
+
}
|
|
80
|
+
return f;
|
|
81
|
+
}
|
|
82
|
+
has(e) {
|
|
83
|
+
return this.injectables.has(e);
|
|
85
84
|
}
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
o();
|
|
85
|
+
require(e, t, n) {
|
|
86
|
+
if (!this.injectables.has(e)) {
|
|
87
|
+
const t = this.resolvingStack.has(e);
|
|
88
|
+
const r = t ? 'Circular dependency detected' : 'Dependency not registered';
|
|
89
|
+
const i = a(e);
|
|
90
|
+
const o = f(e);
|
|
91
|
+
const c = t ? `Circular dependency detected: '${i}' is already being resolved.` : `Dependency '${i}' has not been registered (Class/Service not found in current assemblies).`;
|
|
92
|
+
debugLogger.DebugLogger.getInstance().log('error', r, {
|
|
93
|
+
identifier: i,
|
|
94
|
+
caller: n ? a(n) : 'unknown',
|
|
95
|
+
type: o,
|
|
96
|
+
error: c
|
|
97
|
+
});
|
|
98
|
+
throw new Error(c);
|
|
92
99
|
}
|
|
93
|
-
|
|
100
|
+
const r = this.injectables.get(e);
|
|
101
|
+
this.resolvingStack.add(r.identifier);
|
|
102
|
+
try {
|
|
103
|
+
if (r.isSingleton) {
|
|
104
|
+
return this.singletonStrategy.resolve(r, t);
|
|
105
|
+
} else {
|
|
106
|
+
return this.transientStrategy.resolve(r, t);
|
|
107
|
+
}
|
|
108
|
+
} finally{
|
|
109
|
+
this.resolvingStack.delete(r.identifier);
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
concrete(e) {
|
|
113
|
+
const t = this.injectables.get(e);
|
|
114
|
+
if (t) return t.concrete;
|
|
115
|
+
return;
|
|
116
|
+
}
|
|
117
|
+
tagged(...e) {
|
|
118
|
+
const t = [];
|
|
119
|
+
for (const n of e){
|
|
120
|
+
for (const [e, r] of this.injectables){
|
|
121
|
+
if (r.tags.includes(n)) t.push(r.build());
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
return t;
|
|
125
|
+
}
|
|
126
|
+
dispose() {
|
|
127
|
+
for (const [e, t] of this.injectables){
|
|
128
|
+
t.dispose();
|
|
129
|
+
}
|
|
130
|
+
this.resolvingStack.clear();
|
|
131
|
+
}
|
|
132
|
+
get size() {
|
|
133
|
+
return this.injectables.size;
|
|
94
134
|
}
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
135
|
+
constructor(){
|
|
136
|
+
this.injectables = new Map();
|
|
137
|
+
this.resolvingStack = new Set();
|
|
138
|
+
this.singletonStrategy = new resolutionStrategies.SingletonStrategy();
|
|
139
|
+
this.transientStrategy = new resolutionStrategies.TransientStrategy();
|
|
100
140
|
}
|
|
101
|
-
|
|
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
|
-
};
|
|
141
|
+
}
|
|
110
142
|
|
|
111
|
-
exports.
|
|
112
|
-
exports.setDefinitionValue = setDefinitionValue;
|
|
113
|
-
exports.validateDefinition = validateDefinition;
|
|
143
|
+
exports.InjectableManager = InjectableManager;
|
package/dist/index30.mjs
CHANGED
|
@@ -1,107 +1,139 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
1
|
+
import { HookManager } from './index32.mjs';
|
|
2
|
+
import { SingletonStrategy, TransientStrategy } from './index41.mjs';
|
|
3
|
+
import { DebugLogger } from './index35.mjs';
|
|
4
|
+
import { isClass } from '@assemblerjs/core';
|
|
5
|
+
import { resolveInstanceInjectionTuple } from './index42.mjs';
|
|
6
|
+
import { resolveInjectionTuple } from './index43.mjs';
|
|
7
|
+
import { Injectable } from './index44.mjs';
|
|
4
8
|
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
return typeof r === 'undefined' ? true : r ? true : false;
|
|
9
|
+
function a(e) {
|
|
10
|
+
if (e === undefined) return 'undefined';
|
|
11
|
+
if (e === null) return 'null';
|
|
12
|
+
if (typeof e === 'function') {
|
|
13
|
+
if (e.name) return e.name;
|
|
14
|
+
if (e.constructor?.name && e.constructor.name !== 'Function') {
|
|
15
|
+
return e.constructor.name;
|
|
13
16
|
}
|
|
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
|
|
17
|
+
return 'AnonymousFunction';
|
|
71
18
|
}
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
throw new Error(`Property '${r}' is not a valid assemblage definition property.`);
|
|
19
|
+
if (typeof e === 'string') return e;
|
|
20
|
+
if (typeof e === 'symbol') return e.toString();
|
|
21
|
+
if (typeof e === 'number') return String(e);
|
|
22
|
+
if (typeof e === 'boolean') return String(e);
|
|
23
|
+
if (typeof e === 'object') {
|
|
24
|
+
if (e.name && typeof e.name === 'string') {
|
|
25
|
+
return e.name;
|
|
80
26
|
}
|
|
27
|
+
try {
|
|
28
|
+
const t = JSON.stringify(e);
|
|
29
|
+
if (t.length > 100) {
|
|
30
|
+
return t.substring(0, 100) + '...';
|
|
31
|
+
}
|
|
32
|
+
return t;
|
|
33
|
+
} catch {
|
|
34
|
+
const t = e.constructor?.name;
|
|
35
|
+
if (t && t !== 'Object') {
|
|
36
|
+
return `[${t}]`;
|
|
37
|
+
}
|
|
38
|
+
return '[UnknownObject]';
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
return String(e);
|
|
42
|
+
}
|
|
43
|
+
function f(e) {
|
|
44
|
+
if (isClass(e)) {
|
|
45
|
+
const t = e.prototype && Object.getOwnPropertyNames(e.prototype).length > 1;
|
|
46
|
+
return t ? 'class' : 'class';
|
|
47
|
+
}
|
|
48
|
+
if (typeof e === 'function') return 'function';
|
|
49
|
+
if (typeof e === 'string') return 'string';
|
|
50
|
+
if (typeof e === 'symbol') return 'symbol';
|
|
51
|
+
if (typeof e === 'object' && e !== null) return 'object';
|
|
52
|
+
return 'unknown';
|
|
53
|
+
}
|
|
54
|
+
class InjectableManager {
|
|
55
|
+
setContexts(e, t) {
|
|
56
|
+
this.privateContext = e;
|
|
57
|
+
this.publicContext = t;
|
|
58
|
+
}
|
|
59
|
+
register(i, o = false) {
|
|
60
|
+
const c = DebugLogger.getInstance();
|
|
61
|
+
const a = o === true ? resolveInstanceInjectionTuple(i) : resolveInjectionTuple(i);
|
|
62
|
+
if (this.has(a.identifier)) {
|
|
63
|
+
const e = `An assemblage is already registered with identifier '${a.identifier.name}'.`;
|
|
64
|
+
c.log('error', 'Duplicate registration', {
|
|
65
|
+
identifier: a.identifier.name,
|
|
66
|
+
error: e
|
|
67
|
+
});
|
|
68
|
+
throw new Error(e);
|
|
69
|
+
}
|
|
70
|
+
const f = Injectable.of(a, this.privateContext, this.publicContext);
|
|
71
|
+
c.logRegistration(f);
|
|
72
|
+
this.injectables.set(f.identifier, f);
|
|
73
|
+
if (f.concrete) {
|
|
74
|
+
HookManager.callHook(f.concrete, 'onRegister', this.publicContext, f.configuration);
|
|
75
|
+
}
|
|
76
|
+
return f;
|
|
77
|
+
}
|
|
78
|
+
has(e) {
|
|
79
|
+
return this.injectables.has(e);
|
|
81
80
|
}
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
o();
|
|
81
|
+
require(e, t, n) {
|
|
82
|
+
if (!this.injectables.has(e)) {
|
|
83
|
+
const t = this.resolvingStack.has(e);
|
|
84
|
+
const r = t ? 'Circular dependency detected' : 'Dependency not registered';
|
|
85
|
+
const i = a(e);
|
|
86
|
+
const o = f(e);
|
|
87
|
+
const c = t ? `Circular dependency detected: '${i}' is already being resolved.` : `Dependency '${i}' has not been registered (Class/Service not found in current assemblies).`;
|
|
88
|
+
DebugLogger.getInstance().log('error', r, {
|
|
89
|
+
identifier: i,
|
|
90
|
+
caller: n ? a(n) : 'unknown',
|
|
91
|
+
type: o,
|
|
92
|
+
error: c
|
|
93
|
+
});
|
|
94
|
+
throw new Error(c);
|
|
88
95
|
}
|
|
89
|
-
|
|
96
|
+
const r = this.injectables.get(e);
|
|
97
|
+
this.resolvingStack.add(r.identifier);
|
|
98
|
+
try {
|
|
99
|
+
if (r.isSingleton) {
|
|
100
|
+
return this.singletonStrategy.resolve(r, t);
|
|
101
|
+
} else {
|
|
102
|
+
return this.transientStrategy.resolve(r, t);
|
|
103
|
+
}
|
|
104
|
+
} finally{
|
|
105
|
+
this.resolvingStack.delete(r.identifier);
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
concrete(e) {
|
|
109
|
+
const t = this.injectables.get(e);
|
|
110
|
+
if (t) return t.concrete;
|
|
111
|
+
return;
|
|
112
|
+
}
|
|
113
|
+
tagged(...e) {
|
|
114
|
+
const t = [];
|
|
115
|
+
for (const n of e){
|
|
116
|
+
for (const [e, r] of this.injectables){
|
|
117
|
+
if (r.tags.includes(n)) t.push(r.build());
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
return t;
|
|
121
|
+
}
|
|
122
|
+
dispose() {
|
|
123
|
+
for (const [e, t] of this.injectables){
|
|
124
|
+
t.dispose();
|
|
125
|
+
}
|
|
126
|
+
this.resolvingStack.clear();
|
|
127
|
+
}
|
|
128
|
+
get size() {
|
|
129
|
+
return this.injectables.size;
|
|
90
130
|
}
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
131
|
+
constructor(){
|
|
132
|
+
this.injectables = new Map();
|
|
133
|
+
this.resolvingStack = new Set();
|
|
134
|
+
this.singletonStrategy = new SingletonStrategy();
|
|
135
|
+
this.transientStrategy = new TransientStrategy();
|
|
96
136
|
}
|
|
97
|
-
|
|
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
|
-
};
|
|
137
|
+
}
|
|
106
138
|
|
|
107
|
-
export {
|
|
139
|
+
export { InjectableManager };
|
package/dist/index31.js
CHANGED
|
@@ -2,142 +2,55 @@
|
|
|
2
2
|
|
|
3
3
|
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
4
4
|
|
|
5
|
-
const
|
|
6
|
-
const resolutionStrategies = require('./index41.js');
|
|
7
|
-
const debugLogger = require('./index36.js');
|
|
8
|
-
const core = require('@assemblerjs/core');
|
|
9
|
-
const use = require('./index42.js');
|
|
10
|
-
const inject = require('./index43.js');
|
|
11
|
-
const injectable = require('./index44.js');
|
|
5
|
+
const debugLogger = require('./index35.js');
|
|
12
6
|
|
|
13
|
-
function
|
|
14
|
-
|
|
15
|
-
if (e === null) return 'null';
|
|
16
|
-
if (typeof e === 'function') {
|
|
17
|
-
if (e.name) return e.name;
|
|
18
|
-
if (e.constructor?.name && e.constructor.name !== 'Function') {
|
|
19
|
-
return e.constructor.name;
|
|
20
|
-
}
|
|
21
|
-
return 'AnonymousFunction';
|
|
22
|
-
}
|
|
23
|
-
if (typeof e === 'string') return e;
|
|
24
|
-
if (typeof e === 'symbol') return e.toString();
|
|
25
|
-
if (typeof e === 'number') return String(e);
|
|
26
|
-
if (typeof e === 'boolean') return String(e);
|
|
27
|
-
if (typeof e === 'object') {
|
|
28
|
-
if (e.name && typeof e.name === 'string') {
|
|
29
|
-
return e.name;
|
|
30
|
-
}
|
|
31
|
-
try {
|
|
32
|
-
const t = JSON.stringify(e);
|
|
33
|
-
if (t.length > 100) {
|
|
34
|
-
return t.substring(0, 100) + '...';
|
|
35
|
-
}
|
|
36
|
-
return t;
|
|
37
|
-
} catch {
|
|
38
|
-
const t = e.constructor?.name;
|
|
39
|
-
if (t && t !== 'Object') {
|
|
40
|
-
return `[${t}]`;
|
|
41
|
-
}
|
|
42
|
-
return '[UnknownObject]';
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
return String(e);
|
|
46
|
-
}
|
|
47
|
-
function f(e) {
|
|
48
|
-
if (core.isClass(e)) {
|
|
49
|
-
const t = e.prototype && Object.getOwnPropertyNames(e.prototype).length > 1;
|
|
50
|
-
return t ? 'class' : 'class';
|
|
51
|
-
}
|
|
52
|
-
if (typeof e === 'function') return 'function';
|
|
53
|
-
if (typeof e === 'string') return 'string';
|
|
54
|
-
if (typeof e === 'symbol') return 'symbol';
|
|
55
|
-
if (typeof e === 'object' && e !== null) return 'object';
|
|
56
|
-
return 'unknown';
|
|
7
|
+
function t(e) {
|
|
8
|
+
return typeof e === 'symbol' ? 'symbol' : 'string';
|
|
57
9
|
}
|
|
58
|
-
class
|
|
59
|
-
|
|
60
|
-
this.
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
const e = `An assemblage is already registered with identifier '${a.identifier.name}'.`;
|
|
68
|
-
c.log('error', 'Duplicate registration', {
|
|
69
|
-
identifier: a.identifier.name,
|
|
70
|
-
error: e
|
|
10
|
+
class ObjectManager {
|
|
11
|
+
use(r, o) {
|
|
12
|
+
if (this.has(r)) {
|
|
13
|
+
const o = typeof r === 'symbol' ? r.toString() : String(r);
|
|
14
|
+
const s = `Object/value '${o}' is already registered (cannot register twice).`;
|
|
15
|
+
debugLogger.DebugLogger.getInstance().log('error', 'Duplicate object/value registration', {
|
|
16
|
+
identifier: o,
|
|
17
|
+
type: t(r),
|
|
18
|
+
error: s
|
|
71
19
|
});
|
|
72
|
-
throw new Error(
|
|
73
|
-
}
|
|
74
|
-
const f = injectable.Injectable.of(a, this.privateContext, this.publicContext);
|
|
75
|
-
c.logRegistration(f);
|
|
76
|
-
this.injectables.set(f.identifier, f);
|
|
77
|
-
if (f.concrete) {
|
|
78
|
-
hookManager.HookManager.callHook(f.concrete, 'onRegister', this.publicContext, f.configuration);
|
|
20
|
+
throw new Error(s);
|
|
79
21
|
}
|
|
80
|
-
|
|
22
|
+
this.objects.set(r, o);
|
|
23
|
+
return o;
|
|
81
24
|
}
|
|
82
25
|
has(e) {
|
|
83
|
-
return this.
|
|
84
|
-
}
|
|
85
|
-
require(
|
|
86
|
-
if (!this.
|
|
87
|
-
const
|
|
88
|
-
const
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
identifier: i,
|
|
94
|
-
caller: n ? a(n) : 'unknown',
|
|
95
|
-
type: o,
|
|
96
|
-
error: c
|
|
26
|
+
return this.objects.has(e);
|
|
27
|
+
}
|
|
28
|
+
require(r) {
|
|
29
|
+
if (!this.objects.has(r)) {
|
|
30
|
+
const o = typeof r === 'symbol' ? r.toString() : String(r);
|
|
31
|
+
const s = `Object/value '${o}' has not been registered in the object store.`;
|
|
32
|
+
debugLogger.DebugLogger.getInstance().log('error', 'Object/value not found', {
|
|
33
|
+
identifier: o,
|
|
34
|
+
type: t(r),
|
|
35
|
+
error: s
|
|
97
36
|
});
|
|
98
|
-
throw new Error(
|
|
99
|
-
}
|
|
100
|
-
const r = this.injectables.get(e);
|
|
101
|
-
this.resolvingStack.add(r.identifier);
|
|
102
|
-
try {
|
|
103
|
-
if (r.isSingleton) {
|
|
104
|
-
return this.singletonStrategy.resolve(r, t);
|
|
105
|
-
} else {
|
|
106
|
-
return this.transientStrategy.resolve(r, t);
|
|
107
|
-
}
|
|
108
|
-
} finally{
|
|
109
|
-
this.resolvingStack.delete(r.identifier);
|
|
110
|
-
}
|
|
111
|
-
}
|
|
112
|
-
concrete(e) {
|
|
113
|
-
const t = this.injectables.get(e);
|
|
114
|
-
if (t) return t.concrete;
|
|
115
|
-
return;
|
|
116
|
-
}
|
|
117
|
-
tagged(...e) {
|
|
118
|
-
const t = [];
|
|
119
|
-
for (const n of e){
|
|
120
|
-
for (const [e, r] of this.injectables){
|
|
121
|
-
if (r.tags.includes(n)) t.push(r.build());
|
|
122
|
-
}
|
|
37
|
+
throw new Error(s);
|
|
123
38
|
}
|
|
124
|
-
return
|
|
39
|
+
return this.objects.get(r);
|
|
125
40
|
}
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
41
|
+
addGlobal(e, t) {
|
|
42
|
+
if (this.globals.has(e)) {
|
|
43
|
+
throw new Error(`Global value with key '${e}' has already been registered.`);
|
|
129
44
|
}
|
|
130
|
-
this.
|
|
45
|
+
this.globals.set(e, t);
|
|
131
46
|
}
|
|
132
|
-
|
|
133
|
-
return this.
|
|
47
|
+
global(e) {
|
|
48
|
+
return this.globals.get(e);
|
|
134
49
|
}
|
|
135
50
|
constructor(){
|
|
136
|
-
this.
|
|
137
|
-
this.
|
|
138
|
-
this.singletonStrategy = new resolutionStrategies.SingletonStrategy();
|
|
139
|
-
this.transientStrategy = new resolutionStrategies.TransientStrategy();
|
|
51
|
+
this.objects = new Map();
|
|
52
|
+
this.globals = new Map();
|
|
140
53
|
}
|
|
141
54
|
}
|
|
142
55
|
|
|
143
|
-
exports.
|
|
56
|
+
exports.ObjectManager = ObjectManager;
|