assemblerjs 1.1.6 → 1.1.7
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 +48 -19
- package/dist/index31.mjs +48 -19
- package/dist/index32.js +24 -17
- package/dist/index32.mjs +24 -17
- package/package.json +1 -1
package/dist/index31.js
CHANGED
|
@@ -5,18 +5,44 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
|
5
5
|
const hookManager = require('./index33.js');
|
|
6
6
|
const resolutionStrategies = require('./index43.js');
|
|
7
7
|
const debugLogger = require('./index36.js');
|
|
8
|
+
const core = require('@assemblerjs/core');
|
|
8
9
|
const use = require('./index42.js');
|
|
9
10
|
const inject = require('./index41.js');
|
|
10
11
|
const injectable = require('./index44.js');
|
|
11
12
|
|
|
13
|
+
function c(e) {
|
|
14
|
+
if (e?.name) return e.name;
|
|
15
|
+
if (typeof e === 'string') return e;
|
|
16
|
+
if (typeof e === 'symbol') return e.toString();
|
|
17
|
+
if (typeof e === 'number') return String(e);
|
|
18
|
+
if (typeof e === 'boolean') return String(e);
|
|
19
|
+
if (typeof e === 'object' && e !== null) {
|
|
20
|
+
try {
|
|
21
|
+
const t = JSON.stringify(e);
|
|
22
|
+
if (t.length > 100) {
|
|
23
|
+
return t.substring(0, 100) + '...';
|
|
24
|
+
}
|
|
25
|
+
return t;
|
|
26
|
+
} catch {
|
|
27
|
+
return `[${e.constructor?.name || 'Object'}]`;
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
return String(e);
|
|
31
|
+
}
|
|
32
|
+
function l(e) {
|
|
33
|
+
if (core.isClass(e)) return 'class';
|
|
34
|
+
if (typeof e === 'string') return 'string';
|
|
35
|
+
if (typeof e === 'symbol') return 'symbol';
|
|
36
|
+
return 'unknown';
|
|
37
|
+
}
|
|
12
38
|
class InjectableManager {
|
|
13
39
|
setContexts(e, t) {
|
|
14
40
|
this.privateContext = e;
|
|
15
41
|
this.publicContext = t;
|
|
16
42
|
}
|
|
17
|
-
register(
|
|
43
|
+
register(i, s = false) {
|
|
18
44
|
const a = debugLogger.DebugLogger.getInstance();
|
|
19
|
-
const c = s === true ? use.resolveInstanceInjectionTuple(
|
|
45
|
+
const c = s === true ? use.resolveInstanceInjectionTuple(i) : inject.resolveInjectionTuple(i);
|
|
20
46
|
if (this.has(c.identifier)) {
|
|
21
47
|
const e = `An assemblage is already registered with identifier '${c.identifier.name}'.`;
|
|
22
48
|
a.log('error', 'Duplicate registration', {
|
|
@@ -36,28 +62,31 @@ class InjectableManager {
|
|
|
36
62
|
has(e) {
|
|
37
63
|
return this.injectables.has(e);
|
|
38
64
|
}
|
|
39
|
-
require(e, t,
|
|
65
|
+
require(e, t, r) {
|
|
40
66
|
if (!this.injectables.has(e)) {
|
|
41
67
|
const t = this.resolvingStack.has(e);
|
|
42
|
-
const
|
|
43
|
-
const
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
68
|
+
const n = t ? 'Circular dependency detected' : 'Dependency not registered';
|
|
69
|
+
const i = c(e);
|
|
70
|
+
const s = l(e);
|
|
71
|
+
const a = t ? `Circular dependency detected: '${i}' is already being resolved.` : `Dependency '${i}' has not been registered (Class/Service not found in current assemblies).`;
|
|
72
|
+
debugLogger.DebugLogger.getInstance().log('error', n, {
|
|
73
|
+
identifier: i,
|
|
74
|
+
caller: r ? c(r) : 'unknown',
|
|
75
|
+
type: s,
|
|
76
|
+
error: a
|
|
48
77
|
});
|
|
49
|
-
throw new Error(
|
|
78
|
+
throw new Error(a);
|
|
50
79
|
}
|
|
51
|
-
const
|
|
52
|
-
this.resolvingStack.add(
|
|
80
|
+
const n = this.injectables.get(e);
|
|
81
|
+
this.resolvingStack.add(n.identifier);
|
|
53
82
|
try {
|
|
54
|
-
if (
|
|
55
|
-
return this.singletonStrategy.resolve(
|
|
83
|
+
if (n.isSingleton) {
|
|
84
|
+
return this.singletonStrategy.resolve(n, t);
|
|
56
85
|
} else {
|
|
57
|
-
return this.transientStrategy.resolve(
|
|
86
|
+
return this.transientStrategy.resolve(n, t);
|
|
58
87
|
}
|
|
59
88
|
} finally{
|
|
60
|
-
this.resolvingStack.delete(
|
|
89
|
+
this.resolvingStack.delete(n.identifier);
|
|
61
90
|
}
|
|
62
91
|
}
|
|
63
92
|
concrete(e) {
|
|
@@ -67,9 +96,9 @@ class InjectableManager {
|
|
|
67
96
|
}
|
|
68
97
|
tagged(...e) {
|
|
69
98
|
const t = [];
|
|
70
|
-
for (const
|
|
71
|
-
for (const [e,
|
|
72
|
-
if (
|
|
99
|
+
for (const r of e){
|
|
100
|
+
for (const [e, n] of this.injectables){
|
|
101
|
+
if (n.tags.includes(r)) t.push(n.build());
|
|
73
102
|
}
|
|
74
103
|
}
|
|
75
104
|
return t;
|
package/dist/index31.mjs
CHANGED
|
@@ -1,18 +1,44 @@
|
|
|
1
1
|
import { HookManager } from './index33.mjs';
|
|
2
2
|
import { SingletonStrategy, TransientStrategy } from './index43.mjs';
|
|
3
3
|
import { DebugLogger } from './index36.mjs';
|
|
4
|
+
import { isClass } from '@assemblerjs/core';
|
|
4
5
|
import { resolveInstanceInjectionTuple } from './index42.mjs';
|
|
5
6
|
import { resolveInjectionTuple } from './index41.mjs';
|
|
6
7
|
import { Injectable } from './index44.mjs';
|
|
7
8
|
|
|
9
|
+
function c(e) {
|
|
10
|
+
if (e?.name) return e.name;
|
|
11
|
+
if (typeof e === 'string') return e;
|
|
12
|
+
if (typeof e === 'symbol') return e.toString();
|
|
13
|
+
if (typeof e === 'number') return String(e);
|
|
14
|
+
if (typeof e === 'boolean') return String(e);
|
|
15
|
+
if (typeof e === 'object' && e !== null) {
|
|
16
|
+
try {
|
|
17
|
+
const t = JSON.stringify(e);
|
|
18
|
+
if (t.length > 100) {
|
|
19
|
+
return t.substring(0, 100) + '...';
|
|
20
|
+
}
|
|
21
|
+
return t;
|
|
22
|
+
} catch {
|
|
23
|
+
return `[${e.constructor?.name || 'Object'}]`;
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
return String(e);
|
|
27
|
+
}
|
|
28
|
+
function l(e) {
|
|
29
|
+
if (isClass(e)) return 'class';
|
|
30
|
+
if (typeof e === 'string') return 'string';
|
|
31
|
+
if (typeof e === 'symbol') return 'symbol';
|
|
32
|
+
return 'unknown';
|
|
33
|
+
}
|
|
8
34
|
class InjectableManager {
|
|
9
35
|
setContexts(e, t) {
|
|
10
36
|
this.privateContext = e;
|
|
11
37
|
this.publicContext = t;
|
|
12
38
|
}
|
|
13
|
-
register(
|
|
39
|
+
register(i, s = false) {
|
|
14
40
|
const a = DebugLogger.getInstance();
|
|
15
|
-
const c = s === true ? resolveInstanceInjectionTuple(
|
|
41
|
+
const c = s === true ? resolveInstanceInjectionTuple(i) : resolveInjectionTuple(i);
|
|
16
42
|
if (this.has(c.identifier)) {
|
|
17
43
|
const e = `An assemblage is already registered with identifier '${c.identifier.name}'.`;
|
|
18
44
|
a.log('error', 'Duplicate registration', {
|
|
@@ -32,28 +58,31 @@ class InjectableManager {
|
|
|
32
58
|
has(e) {
|
|
33
59
|
return this.injectables.has(e);
|
|
34
60
|
}
|
|
35
|
-
require(e, t,
|
|
61
|
+
require(e, t, r) {
|
|
36
62
|
if (!this.injectables.has(e)) {
|
|
37
63
|
const t = this.resolvingStack.has(e);
|
|
38
|
-
const
|
|
39
|
-
const
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
64
|
+
const n = t ? 'Circular dependency detected' : 'Dependency not registered';
|
|
65
|
+
const i = c(e);
|
|
66
|
+
const s = l(e);
|
|
67
|
+
const a = t ? `Circular dependency detected: '${i}' is already being resolved.` : `Dependency '${i}' has not been registered (Class/Service not found in current assemblies).`;
|
|
68
|
+
DebugLogger.getInstance().log('error', n, {
|
|
69
|
+
identifier: i,
|
|
70
|
+
caller: r ? c(r) : 'unknown',
|
|
71
|
+
type: s,
|
|
72
|
+
error: a
|
|
44
73
|
});
|
|
45
|
-
throw new Error(
|
|
74
|
+
throw new Error(a);
|
|
46
75
|
}
|
|
47
|
-
const
|
|
48
|
-
this.resolvingStack.add(
|
|
76
|
+
const n = this.injectables.get(e);
|
|
77
|
+
this.resolvingStack.add(n.identifier);
|
|
49
78
|
try {
|
|
50
|
-
if (
|
|
51
|
-
return this.singletonStrategy.resolve(
|
|
79
|
+
if (n.isSingleton) {
|
|
80
|
+
return this.singletonStrategy.resolve(n, t);
|
|
52
81
|
} else {
|
|
53
|
-
return this.transientStrategy.resolve(
|
|
82
|
+
return this.transientStrategy.resolve(n, t);
|
|
54
83
|
}
|
|
55
84
|
} finally{
|
|
56
|
-
this.resolvingStack.delete(
|
|
85
|
+
this.resolvingStack.delete(n.identifier);
|
|
57
86
|
}
|
|
58
87
|
}
|
|
59
88
|
concrete(e) {
|
|
@@ -63,9 +92,9 @@ class InjectableManager {
|
|
|
63
92
|
}
|
|
64
93
|
tagged(...e) {
|
|
65
94
|
const t = [];
|
|
66
|
-
for (const
|
|
67
|
-
for (const [e,
|
|
68
|
-
if (
|
|
95
|
+
for (const r of e){
|
|
96
|
+
for (const [e, n] of this.injectables){
|
|
97
|
+
if (n.tags.includes(r)) t.push(n.build());
|
|
69
98
|
}
|
|
70
99
|
}
|
|
71
100
|
return t;
|
package/dist/index32.js
CHANGED
|
@@ -4,32 +4,39 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
|
4
4
|
|
|
5
5
|
const debugLogger = require('./index36.js');
|
|
6
6
|
|
|
7
|
+
function t(e) {
|
|
8
|
+
return typeof e === 'symbol' ? 'symbol' : 'string';
|
|
9
|
+
}
|
|
7
10
|
class ObjectManager {
|
|
8
|
-
use(
|
|
9
|
-
if (this.has(
|
|
10
|
-
const
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
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
|
|
14
19
|
});
|
|
15
|
-
throw new Error(
|
|
20
|
+
throw new Error(s);
|
|
16
21
|
}
|
|
17
|
-
this.objects.set(
|
|
18
|
-
return
|
|
22
|
+
this.objects.set(r, o);
|
|
23
|
+
return o;
|
|
19
24
|
}
|
|
20
25
|
has(e) {
|
|
21
26
|
return this.objects.has(e);
|
|
22
27
|
}
|
|
23
|
-
require(
|
|
24
|
-
if (!this.objects.has(
|
|
25
|
-
const
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
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
|
|
29
36
|
});
|
|
30
|
-
throw new Error(
|
|
37
|
+
throw new Error(s);
|
|
31
38
|
}
|
|
32
|
-
return this.objects.get(
|
|
39
|
+
return this.objects.get(r);
|
|
33
40
|
}
|
|
34
41
|
addGlobal(e, t) {
|
|
35
42
|
if (this.globals.has(e)) {
|
package/dist/index32.mjs
CHANGED
|
@@ -1,31 +1,38 @@
|
|
|
1
1
|
import { DebugLogger } from './index36.mjs';
|
|
2
2
|
|
|
3
|
+
function t(e) {
|
|
4
|
+
return typeof e === 'symbol' ? 'symbol' : 'string';
|
|
5
|
+
}
|
|
3
6
|
class ObjectManager {
|
|
4
|
-
use(
|
|
5
|
-
if (this.has(
|
|
6
|
-
const
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
7
|
+
use(r, o) {
|
|
8
|
+
if (this.has(r)) {
|
|
9
|
+
const o = typeof r === 'symbol' ? r.toString() : String(r);
|
|
10
|
+
const s = `Object/value '${o}' is already registered (cannot register twice).`;
|
|
11
|
+
DebugLogger.getInstance().log('error', 'Duplicate object/value registration', {
|
|
12
|
+
identifier: o,
|
|
13
|
+
type: t(r),
|
|
14
|
+
error: s
|
|
10
15
|
});
|
|
11
|
-
throw new Error(
|
|
16
|
+
throw new Error(s);
|
|
12
17
|
}
|
|
13
|
-
this.objects.set(
|
|
14
|
-
return
|
|
18
|
+
this.objects.set(r, o);
|
|
19
|
+
return o;
|
|
15
20
|
}
|
|
16
21
|
has(e) {
|
|
17
22
|
return this.objects.has(e);
|
|
18
23
|
}
|
|
19
|
-
require(
|
|
20
|
-
if (!this.objects.has(
|
|
21
|
-
const
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
24
|
+
require(r) {
|
|
25
|
+
if (!this.objects.has(r)) {
|
|
26
|
+
const o = typeof r === 'symbol' ? r.toString() : String(r);
|
|
27
|
+
const s = `Object/value '${o}' has not been registered in the object store.`;
|
|
28
|
+
DebugLogger.getInstance().log('error', 'Object/value not found', {
|
|
29
|
+
identifier: o,
|
|
30
|
+
type: t(r),
|
|
31
|
+
error: s
|
|
25
32
|
});
|
|
26
|
-
throw new Error(
|
|
33
|
+
throw new Error(s);
|
|
27
34
|
}
|
|
28
|
-
return this.objects.get(
|
|
35
|
+
return this.objects.get(r);
|
|
29
36
|
}
|
|
30
37
|
addGlobal(e, t) {
|
|
31
38
|
if (this.globals.has(e)) {
|
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.7",
|
|
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",
|