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 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('./index43.js');
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('./index41.js');
10
+ const inject = require('./index43.js');
11
11
  const injectable = require('./index44.js');
12
12
 
13
- function c(e) {
14
- if (e?.name) return e.name;
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' && e !== null) {
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
- return `[${e.constructor?.name || 'Object'}]`;
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 l(e) {
33
- if (core.isClass(e)) return 'class';
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, s = false) {
44
- const a = debugLogger.DebugLogger.getInstance();
45
- const c = s === true ? use.resolveInstanceInjectionTuple(i) : inject.resolveInjectionTuple(i);
46
- if (this.has(c.identifier)) {
47
- const e = `An assemblage is already registered with identifier '${c.identifier.name}'.`;
48
- a.log('error', 'Duplicate registration', {
49
- identifier: c.identifier.name,
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 l = injectable.Injectable.of(c, this.privateContext, this.publicContext);
55
- a.logRegistration(l);
56
- this.injectables.set(l.identifier, l);
57
- if (l.concrete) {
58
- hookManager.HookManager.callHook(l.concrete, 'onRegister', this.publicContext, l.configuration);
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 l;
80
+ return f;
61
81
  }
62
82
  has(e) {
63
83
  return this.injectables.has(e);
64
84
  }
65
- require(e, t, r) {
85
+ require(e, t, n) {
66
86
  if (!this.injectables.has(e)) {
67
87
  const t = this.resolvingStack.has(e);
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, {
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: r ? c(r) : 'unknown',
75
- type: s,
76
- error: a
94
+ caller: n ? a(n) : 'unknown',
95
+ type: o,
96
+ error: c
77
97
  });
78
- throw new Error(a);
98
+ throw new Error(c);
79
99
  }
80
- const n = this.injectables.get(e);
81
- this.resolvingStack.add(n.identifier);
100
+ const r = this.injectables.get(e);
101
+ this.resolvingStack.add(r.identifier);
82
102
  try {
83
- if (n.isSingleton) {
84
- return this.singletonStrategy.resolve(n, t);
103
+ if (r.isSingleton) {
104
+ return this.singletonStrategy.resolve(r, t);
85
105
  } else {
86
- return this.transientStrategy.resolve(n, t);
106
+ return this.transientStrategy.resolve(r, t);
87
107
  }
88
108
  } finally{
89
- this.resolvingStack.delete(n.identifier);
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 r of e){
100
- for (const [e, n] of this.injectables){
101
- if (n.tags.includes(r)) t.push(n.build());
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 './index43.mjs';
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 './index41.mjs';
6
+ import { resolveInjectionTuple } from './index43.mjs';
7
7
  import { Injectable } from './index44.mjs';
8
8
 
9
- function c(e) {
10
- if (e?.name) return e.name;
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' && e !== null) {
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
- return `[${e.constructor?.name || 'Object'}]`;
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 l(e) {
29
- if (isClass(e)) return 'class';
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, s = false) {
40
- const a = DebugLogger.getInstance();
41
- const c = s === true ? resolveInstanceInjectionTuple(i) : resolveInjectionTuple(i);
42
- if (this.has(c.identifier)) {
43
- const e = `An assemblage is already registered with identifier '${c.identifier.name}'.`;
44
- a.log('error', 'Duplicate registration', {
45
- identifier: c.identifier.name,
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 l = Injectable.of(c, this.privateContext, this.publicContext);
51
- a.logRegistration(l);
52
- this.injectables.set(l.identifier, l);
53
- if (l.concrete) {
54
- HookManager.callHook(l.concrete, 'onRegister', this.publicContext, l.configuration);
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 l;
76
+ return f;
57
77
  }
58
78
  has(e) {
59
79
  return this.injectables.has(e);
60
80
  }
61
- require(e, t, r) {
81
+ require(e, t, n) {
62
82
  if (!this.injectables.has(e)) {
63
83
  const t = this.resolvingStack.has(e);
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, {
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: r ? c(r) : 'unknown',
71
- type: s,
72
- error: a
90
+ caller: n ? a(n) : 'unknown',
91
+ type: o,
92
+ error: c
73
93
  });
74
- throw new Error(a);
94
+ throw new Error(c);
75
95
  }
76
- const n = this.injectables.get(e);
77
- this.resolvingStack.add(n.identifier);
96
+ const r = this.injectables.get(e);
97
+ this.resolvingStack.add(r.identifier);
78
98
  try {
79
- if (n.isSingleton) {
80
- return this.singletonStrategy.resolve(n, t);
99
+ if (r.isSingleton) {
100
+ return this.singletonStrategy.resolve(r, t);
81
101
  } else {
82
- return this.transientStrategy.resolve(n, t);
102
+ return this.transientStrategy.resolve(r, t);
83
103
  }
84
104
  } finally{
85
- this.resolvingStack.delete(n.identifier);
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 r of e){
96
- for (const [e, n] of this.injectables){
97
- if (n.tags.includes(r)) t.push(n.build());
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
- const core = require('@assemblerjs/core');
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
- 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;
33
+ exports.SingletonStrategy = SingletonStrategy;
34
+ exports.TransientStrategy = TransientStrategy;
package/dist/index41.mjs CHANGED
@@ -1,50 +1,29 @@
1
- import { switchCase, pipe, conditionally, isClass, isObject } from '@assemblerjs/core';
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
- 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 };
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
- 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
- }
5
+ const core = require('@assemblerjs/core');
32
6
 
33
- exports.SingletonStrategy = SingletonStrategy;
34
- exports.TransientStrategy = TransientStrategy;
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
- 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
- }
1
+ import { switchCase, pipe, conditionally, isClass, isObject } from '@assemblerjs/core';
28
2
 
29
- export { SingletonStrategy, TransientStrategy };
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.7",
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",