assemblerjs 1.1.7 → 1.1.8
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/index31.js +60 -40
- package/dist/index31.mjs +60 -40
- package/dist/index41.js +29 -49
- package/dist/index41.mjs +28 -49
- package/dist/index43.js +49 -29
- package/dist/index43.mjs +49 -28
- package/package.json +1 -1
package/dist/index31.js
CHANGED
|
@@ -3,20 +3,31 @@
|
|
|
3
3
|
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
4
4
|
|
|
5
5
|
const hookManager = require('./index33.js');
|
|
6
|
-
const resolutionStrategies = require('./
|
|
6
|
+
const resolutionStrategies = require('./index41.js');
|
|
7
7
|
const debugLogger = require('./index36.js');
|
|
8
8
|
const core = require('@assemblerjs/core');
|
|
9
9
|
const use = require('./index42.js');
|
|
10
|
-
const inject = require('./
|
|
10
|
+
const inject = require('./index43.js');
|
|
11
11
|
const injectable = require('./index44.js');
|
|
12
12
|
|
|
13
|
-
function
|
|
14
|
-
if (e
|
|
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;
|
|
20
|
+
}
|
|
21
|
+
return 'AnonymousFunction';
|
|
22
|
+
}
|
|
15
23
|
if (typeof e === 'string') return e;
|
|
16
24
|
if (typeof e === 'symbol') return e.toString();
|
|
17
25
|
if (typeof e === 'number') return String(e);
|
|
18
26
|
if (typeof e === 'boolean') return String(e);
|
|
19
|
-
if (typeof e === 'object'
|
|
27
|
+
if (typeof e === 'object') {
|
|
28
|
+
if (e.name && typeof e.name === 'string') {
|
|
29
|
+
return e.name;
|
|
30
|
+
}
|
|
20
31
|
try {
|
|
21
32
|
const t = JSON.stringify(e);
|
|
22
33
|
if (t.length > 100) {
|
|
@@ -24,15 +35,24 @@ function c(e) {
|
|
|
24
35
|
}
|
|
25
36
|
return t;
|
|
26
37
|
} catch {
|
|
27
|
-
|
|
38
|
+
const t = e.constructor?.name;
|
|
39
|
+
if (t && t !== 'Object') {
|
|
40
|
+
return `[${t}]`;
|
|
41
|
+
}
|
|
42
|
+
return '[UnknownObject]';
|
|
28
43
|
}
|
|
29
44
|
}
|
|
30
45
|
return String(e);
|
|
31
46
|
}
|
|
32
|
-
function
|
|
33
|
-
if (core.isClass(e))
|
|
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';
|
|
34
53
|
if (typeof e === 'string') return 'string';
|
|
35
54
|
if (typeof e === 'symbol') return 'symbol';
|
|
55
|
+
if (typeof e === 'object' && e !== null) return 'object';
|
|
36
56
|
return 'unknown';
|
|
37
57
|
}
|
|
38
58
|
class InjectableManager {
|
|
@@ -40,53 +60,53 @@ class InjectableManager {
|
|
|
40
60
|
this.privateContext = e;
|
|
41
61
|
this.publicContext = t;
|
|
42
62
|
}
|
|
43
|
-
register(i,
|
|
44
|
-
const
|
|
45
|
-
const
|
|
46
|
-
if (this.has(
|
|
47
|
-
const e = `An assemblage is already registered with identifier '${
|
|
48
|
-
|
|
49
|
-
identifier:
|
|
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,
|
|
50
70
|
error: e
|
|
51
71
|
});
|
|
52
72
|
throw new Error(e);
|
|
53
73
|
}
|
|
54
|
-
const
|
|
55
|
-
|
|
56
|
-
this.injectables.set(
|
|
57
|
-
if (
|
|
58
|
-
hookManager.HookManager.callHook(
|
|
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);
|
|
59
79
|
}
|
|
60
|
-
return
|
|
80
|
+
return f;
|
|
61
81
|
}
|
|
62
82
|
has(e) {
|
|
63
83
|
return this.injectables.has(e);
|
|
64
84
|
}
|
|
65
|
-
require(e, t,
|
|
85
|
+
require(e, t, n) {
|
|
66
86
|
if (!this.injectables.has(e)) {
|
|
67
87
|
const t = this.resolvingStack.has(e);
|
|
68
|
-
const
|
|
69
|
-
const i =
|
|
70
|
-
const
|
|
71
|
-
const
|
|
72
|
-
debugLogger.DebugLogger.getInstance().log('error',
|
|
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, {
|
|
73
93
|
identifier: i,
|
|
74
|
-
caller:
|
|
75
|
-
type:
|
|
76
|
-
error:
|
|
94
|
+
caller: n ? a(n) : 'unknown',
|
|
95
|
+
type: o,
|
|
96
|
+
error: c
|
|
77
97
|
});
|
|
78
|
-
throw new Error(
|
|
98
|
+
throw new Error(c);
|
|
79
99
|
}
|
|
80
|
-
const
|
|
81
|
-
this.resolvingStack.add(
|
|
100
|
+
const r = this.injectables.get(e);
|
|
101
|
+
this.resolvingStack.add(r.identifier);
|
|
82
102
|
try {
|
|
83
|
-
if (
|
|
84
|
-
return this.singletonStrategy.resolve(
|
|
103
|
+
if (r.isSingleton) {
|
|
104
|
+
return this.singletonStrategy.resolve(r, t);
|
|
85
105
|
} else {
|
|
86
|
-
return this.transientStrategy.resolve(
|
|
106
|
+
return this.transientStrategy.resolve(r, t);
|
|
87
107
|
}
|
|
88
108
|
} finally{
|
|
89
|
-
this.resolvingStack.delete(
|
|
109
|
+
this.resolvingStack.delete(r.identifier);
|
|
90
110
|
}
|
|
91
111
|
}
|
|
92
112
|
concrete(e) {
|
|
@@ -96,9 +116,9 @@ class InjectableManager {
|
|
|
96
116
|
}
|
|
97
117
|
tagged(...e) {
|
|
98
118
|
const t = [];
|
|
99
|
-
for (const
|
|
100
|
-
for (const [e,
|
|
101
|
-
if (
|
|
119
|
+
for (const n of e){
|
|
120
|
+
for (const [e, r] of this.injectables){
|
|
121
|
+
if (r.tags.includes(n)) t.push(r.build());
|
|
102
122
|
}
|
|
103
123
|
}
|
|
104
124
|
return t;
|
package/dist/index31.mjs
CHANGED
|
@@ -1,18 +1,29 @@
|
|
|
1
1
|
import { HookManager } from './index33.mjs';
|
|
2
|
-
import { SingletonStrategy, TransientStrategy } from './
|
|
2
|
+
import { SingletonStrategy, TransientStrategy } from './index41.mjs';
|
|
3
3
|
import { DebugLogger } from './index36.mjs';
|
|
4
4
|
import { isClass } from '@assemblerjs/core';
|
|
5
5
|
import { resolveInstanceInjectionTuple } from './index42.mjs';
|
|
6
|
-
import { resolveInjectionTuple } from './
|
|
6
|
+
import { resolveInjectionTuple } from './index43.mjs';
|
|
7
7
|
import { Injectable } from './index44.mjs';
|
|
8
8
|
|
|
9
|
-
function
|
|
10
|
-
if (e
|
|
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;
|
|
16
|
+
}
|
|
17
|
+
return 'AnonymousFunction';
|
|
18
|
+
}
|
|
11
19
|
if (typeof e === 'string') return e;
|
|
12
20
|
if (typeof e === 'symbol') return e.toString();
|
|
13
21
|
if (typeof e === 'number') return String(e);
|
|
14
22
|
if (typeof e === 'boolean') return String(e);
|
|
15
|
-
if (typeof e === 'object'
|
|
23
|
+
if (typeof e === 'object') {
|
|
24
|
+
if (e.name && typeof e.name === 'string') {
|
|
25
|
+
return e.name;
|
|
26
|
+
}
|
|
16
27
|
try {
|
|
17
28
|
const t = JSON.stringify(e);
|
|
18
29
|
if (t.length > 100) {
|
|
@@ -20,15 +31,24 @@ function c(e) {
|
|
|
20
31
|
}
|
|
21
32
|
return t;
|
|
22
33
|
} catch {
|
|
23
|
-
|
|
34
|
+
const t = e.constructor?.name;
|
|
35
|
+
if (t && t !== 'Object') {
|
|
36
|
+
return `[${t}]`;
|
|
37
|
+
}
|
|
38
|
+
return '[UnknownObject]';
|
|
24
39
|
}
|
|
25
40
|
}
|
|
26
41
|
return String(e);
|
|
27
42
|
}
|
|
28
|
-
function
|
|
29
|
-
if (isClass(e))
|
|
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';
|
|
30
49
|
if (typeof e === 'string') return 'string';
|
|
31
50
|
if (typeof e === 'symbol') return 'symbol';
|
|
51
|
+
if (typeof e === 'object' && e !== null) return 'object';
|
|
32
52
|
return 'unknown';
|
|
33
53
|
}
|
|
34
54
|
class InjectableManager {
|
|
@@ -36,53 +56,53 @@ class InjectableManager {
|
|
|
36
56
|
this.privateContext = e;
|
|
37
57
|
this.publicContext = t;
|
|
38
58
|
}
|
|
39
|
-
register(i,
|
|
40
|
-
const
|
|
41
|
-
const
|
|
42
|
-
if (this.has(
|
|
43
|
-
const e = `An assemblage is already registered with identifier '${
|
|
44
|
-
|
|
45
|
-
identifier:
|
|
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,
|
|
46
66
|
error: e
|
|
47
67
|
});
|
|
48
68
|
throw new Error(e);
|
|
49
69
|
}
|
|
50
|
-
const
|
|
51
|
-
|
|
52
|
-
this.injectables.set(
|
|
53
|
-
if (
|
|
54
|
-
HookManager.callHook(
|
|
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);
|
|
55
75
|
}
|
|
56
|
-
return
|
|
76
|
+
return f;
|
|
57
77
|
}
|
|
58
78
|
has(e) {
|
|
59
79
|
return this.injectables.has(e);
|
|
60
80
|
}
|
|
61
|
-
require(e, t,
|
|
81
|
+
require(e, t, n) {
|
|
62
82
|
if (!this.injectables.has(e)) {
|
|
63
83
|
const t = this.resolvingStack.has(e);
|
|
64
|
-
const
|
|
65
|
-
const i =
|
|
66
|
-
const
|
|
67
|
-
const
|
|
68
|
-
DebugLogger.getInstance().log('error',
|
|
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, {
|
|
69
89
|
identifier: i,
|
|
70
|
-
caller:
|
|
71
|
-
type:
|
|
72
|
-
error:
|
|
90
|
+
caller: n ? a(n) : 'unknown',
|
|
91
|
+
type: o,
|
|
92
|
+
error: c
|
|
73
93
|
});
|
|
74
|
-
throw new Error(
|
|
94
|
+
throw new Error(c);
|
|
75
95
|
}
|
|
76
|
-
const
|
|
77
|
-
this.resolvingStack.add(
|
|
96
|
+
const r = this.injectables.get(e);
|
|
97
|
+
this.resolvingStack.add(r.identifier);
|
|
78
98
|
try {
|
|
79
|
-
if (
|
|
80
|
-
return this.singletonStrategy.resolve(
|
|
99
|
+
if (r.isSingleton) {
|
|
100
|
+
return this.singletonStrategy.resolve(r, t);
|
|
81
101
|
} else {
|
|
82
|
-
return this.transientStrategy.resolve(
|
|
102
|
+
return this.transientStrategy.resolve(r, t);
|
|
83
103
|
}
|
|
84
104
|
} finally{
|
|
85
|
-
this.resolvingStack.delete(
|
|
105
|
+
this.resolvingStack.delete(r.identifier);
|
|
86
106
|
}
|
|
87
107
|
}
|
|
88
108
|
concrete(e) {
|
|
@@ -92,9 +112,9 @@ class InjectableManager {
|
|
|
92
112
|
}
|
|
93
113
|
tagged(...e) {
|
|
94
114
|
const t = [];
|
|
95
|
-
for (const
|
|
96
|
-
for (const [e,
|
|
97
|
-
if (
|
|
115
|
+
for (const n of e){
|
|
116
|
+
for (const [e, r] of this.injectables){
|
|
117
|
+
if (r.tags.includes(n)) t.push(r.build());
|
|
98
118
|
}
|
|
99
119
|
}
|
|
100
120
|
return t;
|
package/dist/index41.js
CHANGED
|
@@ -2,53 +2,33 @@
|
|
|
2
2
|
|
|
3
3
|
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
class SingletonStrategy {
|
|
6
|
+
resolve(t, e) {
|
|
7
|
+
const n = t.identifier;
|
|
8
|
+
if (this.cache.has(n)) {
|
|
9
|
+
return this.cache.get(n);
|
|
10
|
+
}
|
|
11
|
+
const o = t.build(e);
|
|
12
|
+
const r = e ? {
|
|
13
|
+
...t.configuration,
|
|
14
|
+
...e
|
|
15
|
+
} : t.configuration;
|
|
16
|
+
t.setSingletonInstance(o, r);
|
|
17
|
+
this.cache.set(n, o);
|
|
18
|
+
t.privateContext.prepareInitHook(o, t.configuration);
|
|
19
|
+
return o;
|
|
20
|
+
}
|
|
21
|
+
constructor(){
|
|
22
|
+
this.cache = new Map();
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
class TransientStrategy {
|
|
26
|
+
resolve(t, e) {
|
|
27
|
+
const n = t.build(e);
|
|
28
|
+
t.privateContext.prepareInitHook(n, t.configuration);
|
|
29
|
+
return n;
|
|
30
|
+
}
|
|
31
|
+
}
|
|
6
32
|
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
identifier: e[0],
|
|
10
|
-
concrete: e[0],
|
|
11
|
-
configuration: {}
|
|
12
|
-
};
|
|
13
|
-
};
|
|
14
|
-
const c = (o)=>{
|
|
15
|
-
const i = ()=>core.isClass(o[0]) && core.isClass(o[1]);
|
|
16
|
-
const c = ()=>core.isClass(o[0]) && core.isObject(o[1]);
|
|
17
|
-
const s = ()=>core.pipe(core.conditionally({
|
|
18
|
-
if: ()=>i(),
|
|
19
|
-
then: ()=>{
|
|
20
|
-
return {
|
|
21
|
-
identifier: o[0],
|
|
22
|
-
concrete: o[1],
|
|
23
|
-
configuration: {}
|
|
24
|
-
};
|
|
25
|
-
}
|
|
26
|
-
}), core.conditionally({
|
|
27
|
-
if: ()=>c(),
|
|
28
|
-
then: ()=>{
|
|
29
|
-
return {
|
|
30
|
-
identifier: o[0],
|
|
31
|
-
concrete: o[0],
|
|
32
|
-
configuration: o[1]
|
|
33
|
-
};
|
|
34
|
-
},
|
|
35
|
-
else: (e)=>e
|
|
36
|
-
}))();
|
|
37
|
-
return s();
|
|
38
|
-
};
|
|
39
|
-
const s = (e)=>{
|
|
40
|
-
return {
|
|
41
|
-
identifier: e[0],
|
|
42
|
-
concrete: e[1],
|
|
43
|
-
configuration: e[2]
|
|
44
|
-
};
|
|
45
|
-
};
|
|
46
|
-
const resolveInjectionTuple = (e)=>core.switchCase({
|
|
47
|
-
1: ()=>i(e),
|
|
48
|
-
2: ()=>c(e),
|
|
49
|
-
3: ()=>s(e)
|
|
50
|
-
}, ()=>{
|
|
51
|
-
throw new Error(`Injection tuple must be of length 1, 2 or 3.`);
|
|
52
|
-
})(e.length);
|
|
53
|
-
|
|
54
|
-
exports.resolveInjectionTuple = resolveInjectionTuple;
|
|
33
|
+
exports.SingletonStrategy = SingletonStrategy;
|
|
34
|
+
exports.TransientStrategy = TransientStrategy;
|
package/dist/index41.mjs
CHANGED
|
@@ -1,50 +1,29 @@
|
|
|
1
|
-
|
|
1
|
+
class SingletonStrategy {
|
|
2
|
+
resolve(t, e) {
|
|
3
|
+
const n = t.identifier;
|
|
4
|
+
if (this.cache.has(n)) {
|
|
5
|
+
return this.cache.get(n);
|
|
6
|
+
}
|
|
7
|
+
const o = t.build(e);
|
|
8
|
+
const r = e ? {
|
|
9
|
+
...t.configuration,
|
|
10
|
+
...e
|
|
11
|
+
} : t.configuration;
|
|
12
|
+
t.setSingletonInstance(o, r);
|
|
13
|
+
this.cache.set(n, o);
|
|
14
|
+
t.privateContext.prepareInitHook(o, t.configuration);
|
|
15
|
+
return o;
|
|
16
|
+
}
|
|
17
|
+
constructor(){
|
|
18
|
+
this.cache = new Map();
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
class TransientStrategy {
|
|
22
|
+
resolve(t, e) {
|
|
23
|
+
const n = t.build(e);
|
|
24
|
+
t.privateContext.prepareInitHook(n, t.configuration);
|
|
25
|
+
return n;
|
|
26
|
+
}
|
|
27
|
+
}
|
|
2
28
|
|
|
3
|
-
|
|
4
|
-
return {
|
|
5
|
-
identifier: e[0],
|
|
6
|
-
concrete: e[0],
|
|
7
|
-
configuration: {}
|
|
8
|
-
};
|
|
9
|
-
};
|
|
10
|
-
const c = (o)=>{
|
|
11
|
-
const i = ()=>isClass(o[0]) && isClass(o[1]);
|
|
12
|
-
const c = ()=>isClass(o[0]) && isObject(o[1]);
|
|
13
|
-
const s = ()=>pipe(conditionally({
|
|
14
|
-
if: ()=>i(),
|
|
15
|
-
then: ()=>{
|
|
16
|
-
return {
|
|
17
|
-
identifier: o[0],
|
|
18
|
-
concrete: o[1],
|
|
19
|
-
configuration: {}
|
|
20
|
-
};
|
|
21
|
-
}
|
|
22
|
-
}), conditionally({
|
|
23
|
-
if: ()=>c(),
|
|
24
|
-
then: ()=>{
|
|
25
|
-
return {
|
|
26
|
-
identifier: o[0],
|
|
27
|
-
concrete: o[0],
|
|
28
|
-
configuration: o[1]
|
|
29
|
-
};
|
|
30
|
-
},
|
|
31
|
-
else: (e)=>e
|
|
32
|
-
}))();
|
|
33
|
-
return s();
|
|
34
|
-
};
|
|
35
|
-
const s = (e)=>{
|
|
36
|
-
return {
|
|
37
|
-
identifier: e[0],
|
|
38
|
-
concrete: e[1],
|
|
39
|
-
configuration: e[2]
|
|
40
|
-
};
|
|
41
|
-
};
|
|
42
|
-
const resolveInjectionTuple = (e)=>switchCase({
|
|
43
|
-
1: ()=>i(e),
|
|
44
|
-
2: ()=>c(e),
|
|
45
|
-
3: ()=>s(e)
|
|
46
|
-
}, ()=>{
|
|
47
|
-
throw new Error(`Injection tuple must be of length 1, 2 or 3.`);
|
|
48
|
-
})(e.length);
|
|
49
|
-
|
|
50
|
-
export { resolveInjectionTuple };
|
|
29
|
+
export { SingletonStrategy, TransientStrategy };
|
package/dist/index43.js
CHANGED
|
@@ -2,33 +2,53 @@
|
|
|
2
2
|
|
|
3
3
|
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
4
4
|
|
|
5
|
-
|
|
6
|
-
resolve(t, e) {
|
|
7
|
-
const n = t.identifier;
|
|
8
|
-
if (this.cache.has(n)) {
|
|
9
|
-
return this.cache.get(n);
|
|
10
|
-
}
|
|
11
|
-
const o = t.build(e);
|
|
12
|
-
const r = e ? {
|
|
13
|
-
...t.configuration,
|
|
14
|
-
...e
|
|
15
|
-
} : t.configuration;
|
|
16
|
-
t.setSingletonInstance(o, r);
|
|
17
|
-
this.cache.set(n, o);
|
|
18
|
-
t.privateContext.prepareInitHook(o, t.configuration);
|
|
19
|
-
return o;
|
|
20
|
-
}
|
|
21
|
-
constructor(){
|
|
22
|
-
this.cache = new Map();
|
|
23
|
-
}
|
|
24
|
-
}
|
|
25
|
-
class TransientStrategy {
|
|
26
|
-
resolve(t, e) {
|
|
27
|
-
const n = t.build(e);
|
|
28
|
-
t.privateContext.prepareInitHook(n, t.configuration);
|
|
29
|
-
return n;
|
|
30
|
-
}
|
|
31
|
-
}
|
|
5
|
+
const core = require('@assemblerjs/core');
|
|
32
6
|
|
|
33
|
-
|
|
34
|
-
|
|
7
|
+
const i = (e)=>{
|
|
8
|
+
return {
|
|
9
|
+
identifier: e[0],
|
|
10
|
+
concrete: e[0],
|
|
11
|
+
configuration: {}
|
|
12
|
+
};
|
|
13
|
+
};
|
|
14
|
+
const c = (o)=>{
|
|
15
|
+
const i = ()=>core.isClass(o[0]) && core.isClass(o[1]);
|
|
16
|
+
const c = ()=>core.isClass(o[0]) && core.isObject(o[1]);
|
|
17
|
+
const s = ()=>core.pipe(core.conditionally({
|
|
18
|
+
if: ()=>i(),
|
|
19
|
+
then: ()=>{
|
|
20
|
+
return {
|
|
21
|
+
identifier: o[0],
|
|
22
|
+
concrete: o[1],
|
|
23
|
+
configuration: {}
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
}), core.conditionally({
|
|
27
|
+
if: ()=>c(),
|
|
28
|
+
then: ()=>{
|
|
29
|
+
return {
|
|
30
|
+
identifier: o[0],
|
|
31
|
+
concrete: o[0],
|
|
32
|
+
configuration: o[1]
|
|
33
|
+
};
|
|
34
|
+
},
|
|
35
|
+
else: (e)=>e
|
|
36
|
+
}))();
|
|
37
|
+
return s();
|
|
38
|
+
};
|
|
39
|
+
const s = (e)=>{
|
|
40
|
+
return {
|
|
41
|
+
identifier: e[0],
|
|
42
|
+
concrete: e[1],
|
|
43
|
+
configuration: e[2]
|
|
44
|
+
};
|
|
45
|
+
};
|
|
46
|
+
const resolveInjectionTuple = (e)=>core.switchCase({
|
|
47
|
+
1: ()=>i(e),
|
|
48
|
+
2: ()=>c(e),
|
|
49
|
+
3: ()=>s(e)
|
|
50
|
+
}, ()=>{
|
|
51
|
+
throw new Error(`Injection tuple must be of length 1, 2 or 3.`);
|
|
52
|
+
})(e.length);
|
|
53
|
+
|
|
54
|
+
exports.resolveInjectionTuple = resolveInjectionTuple;
|
package/dist/index43.mjs
CHANGED
|
@@ -1,29 +1,50 @@
|
|
|
1
|
-
|
|
2
|
-
resolve(t, e) {
|
|
3
|
-
const n = t.identifier;
|
|
4
|
-
if (this.cache.has(n)) {
|
|
5
|
-
return this.cache.get(n);
|
|
6
|
-
}
|
|
7
|
-
const o = t.build(e);
|
|
8
|
-
const r = e ? {
|
|
9
|
-
...t.configuration,
|
|
10
|
-
...e
|
|
11
|
-
} : t.configuration;
|
|
12
|
-
t.setSingletonInstance(o, r);
|
|
13
|
-
this.cache.set(n, o);
|
|
14
|
-
t.privateContext.prepareInitHook(o, t.configuration);
|
|
15
|
-
return o;
|
|
16
|
-
}
|
|
17
|
-
constructor(){
|
|
18
|
-
this.cache = new Map();
|
|
19
|
-
}
|
|
20
|
-
}
|
|
21
|
-
class TransientStrategy {
|
|
22
|
-
resolve(t, e) {
|
|
23
|
-
const n = t.build(e);
|
|
24
|
-
t.privateContext.prepareInitHook(n, t.configuration);
|
|
25
|
-
return n;
|
|
26
|
-
}
|
|
27
|
-
}
|
|
1
|
+
import { switchCase, pipe, conditionally, isClass, isObject } from '@assemblerjs/core';
|
|
28
2
|
|
|
29
|
-
|
|
3
|
+
const i = (e)=>{
|
|
4
|
+
return {
|
|
5
|
+
identifier: e[0],
|
|
6
|
+
concrete: e[0],
|
|
7
|
+
configuration: {}
|
|
8
|
+
};
|
|
9
|
+
};
|
|
10
|
+
const c = (o)=>{
|
|
11
|
+
const i = ()=>isClass(o[0]) && isClass(o[1]);
|
|
12
|
+
const c = ()=>isClass(o[0]) && isObject(o[1]);
|
|
13
|
+
const s = ()=>pipe(conditionally({
|
|
14
|
+
if: ()=>i(),
|
|
15
|
+
then: ()=>{
|
|
16
|
+
return {
|
|
17
|
+
identifier: o[0],
|
|
18
|
+
concrete: o[1],
|
|
19
|
+
configuration: {}
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
}), conditionally({
|
|
23
|
+
if: ()=>c(),
|
|
24
|
+
then: ()=>{
|
|
25
|
+
return {
|
|
26
|
+
identifier: o[0],
|
|
27
|
+
concrete: o[0],
|
|
28
|
+
configuration: o[1]
|
|
29
|
+
};
|
|
30
|
+
},
|
|
31
|
+
else: (e)=>e
|
|
32
|
+
}))();
|
|
33
|
+
return s();
|
|
34
|
+
};
|
|
35
|
+
const s = (e)=>{
|
|
36
|
+
return {
|
|
37
|
+
identifier: e[0],
|
|
38
|
+
concrete: e[1],
|
|
39
|
+
configuration: e[2]
|
|
40
|
+
};
|
|
41
|
+
};
|
|
42
|
+
const resolveInjectionTuple = (e)=>switchCase({
|
|
43
|
+
1: ()=>i(e),
|
|
44
|
+
2: ()=>c(e),
|
|
45
|
+
3: ()=>s(e)
|
|
46
|
+
}, ()=>{
|
|
47
|
+
throw new Error(`Injection tuple must be of length 1, 2 or 3.`);
|
|
48
|
+
})(e.length);
|
|
49
|
+
|
|
50
|
+
export { resolveInjectionTuple };
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "assemblerjs",
|
|
3
3
|
"description": "A general purpose Dependency Injection library for node and browser.",
|
|
4
|
-
"version": "1.1.
|
|
4
|
+
"version": "1.1.8",
|
|
5
5
|
"author": "Benoît LAHOZ <info@benoitlahoz.io>",
|
|
6
6
|
"bugs": "https://github.com/benoitlahoz/assemblerjs/issues",
|
|
7
7
|
"homepage": "https://github.com/benoitlahoz/assemblerjs#README",
|