assemblerjs 1.1.21 → 1.1.22

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.
Files changed (67) hide show
  1. package/dist/index11.js +2 -2
  2. package/dist/index11.mjs +2 -2
  3. package/dist/index13.js +1 -1
  4. package/dist/index13.mjs +1 -1
  5. package/dist/index16.js +1 -1
  6. package/dist/index16.mjs +1 -1
  7. package/dist/index17.js +1 -1
  8. package/dist/index17.mjs +1 -1
  9. package/dist/index18.js +1 -1
  10. package/dist/index18.mjs +1 -1
  11. package/dist/index19.js +1 -1
  12. package/dist/index19.mjs +1 -1
  13. package/dist/index2.js +2 -2
  14. package/dist/index2.mjs +2 -2
  15. package/dist/index20.js +1 -1
  16. package/dist/index20.mjs +1 -1
  17. package/dist/index21.js +1 -1
  18. package/dist/index21.mjs +1 -1
  19. package/dist/index22.js +3 -3
  20. package/dist/index22.mjs +3 -3
  21. package/dist/index23.js +3 -3
  22. package/dist/index23.mjs +3 -3
  23. package/dist/index24.js +2 -2
  24. package/dist/index24.mjs +2 -2
  25. package/dist/index25.js +1 -1
  26. package/dist/index25.mjs +1 -1
  27. package/dist/index26.js +1 -1
  28. package/dist/index26.mjs +1 -1
  29. package/dist/index29.js +158 -17
  30. package/dist/index29.mjs +157 -14
  31. package/dist/index3.js +1 -1
  32. package/dist/index3.mjs +1 -1
  33. package/dist/index30.js +43 -100
  34. package/dist/index30.mjs +43 -98
  35. package/dist/index31.js +71 -32
  36. package/dist/index31.mjs +71 -31
  37. package/dist/index32.js +51 -154
  38. package/dist/index32.mjs +51 -153
  39. package/dist/index33.js +28 -47
  40. package/dist/index33.mjs +28 -47
  41. package/dist/index34.js +161 -65
  42. package/dist/index34.mjs +161 -65
  43. package/dist/index35.js +58 -50
  44. package/dist/index35.mjs +58 -50
  45. package/dist/index36.js +18 -32
  46. package/dist/index36.mjs +15 -32
  47. package/dist/index37.js +99 -167
  48. package/dist/index37.mjs +97 -167
  49. package/dist/index38.js +16 -57
  50. package/dist/index38.mjs +16 -57
  51. package/dist/index39.js +38 -20
  52. package/dist/index39.mjs +37 -20
  53. package/dist/index4.js +7 -7
  54. package/dist/index4.mjs +7 -7
  55. package/dist/index42.js +29 -49
  56. package/dist/index42.mjs +28 -49
  57. package/dist/index44.js +49 -29
  58. package/dist/index44.mjs +49 -28
  59. package/dist/index45.js +25 -9
  60. package/dist/index45.mjs +25 -9
  61. package/dist/index49.js +1 -1
  62. package/dist/index49.mjs +1 -1
  63. package/dist/index50.js +1 -1
  64. package/dist/index50.mjs +1 -1
  65. package/dist/index51.js +1 -1
  66. package/dist/index51.mjs +1 -1
  67. package/package.json +1 -1
package/dist/index35.mjs CHANGED
@@ -1,57 +1,65 @@
1
- import { HookManager } from './index34.mjs';
2
- import { DebugLogger } from './index37.mjs';
3
- import { CycleDetector } from './index38.mjs';
4
- import { formatIdentifier } from './index32.mjs';
5
- import { setDefinitionValue } from './index30.mjs';
6
-
7
- class AssemblerBuilder {
8
- build(n, r) {
9
- const i = DebugLogger.getInstance();
10
- setDefinitionValue('singleton', true, n);
11
- i.logPhaseStart('registration');
12
- const l = this.assembler.register([
13
- n
14
- ]);
15
- const c = this.assembler.injectableManager.getRegisteredIdentifiers();
16
- i.logPhaseEnd('registration', undefined, {
17
- registered: c
18
- });
19
- const h = CycleDetector.getInstance().detect(this.assembler.injectableManager.getInjectables(), (e)=>formatIdentifier(e));
20
- if (h.length > 0) {
21
- for (const e of h){
22
- i.log('error', 'Circular dependency detected', {
23
- cycle: e.cycle,
24
- path: e.path
25
- });
1
+ let AbstractCycleDetector = class AbstractCycleDetector {
2
+ };
3
+ let NoOpCycleDetector = class NoOpCycleDetector extends AbstractCycleDetector {
4
+ detect() {
5
+ return [];
6
+ }
7
+ };
8
+ let ActiveCycleDetector = class ActiveCycleDetector extends AbstractCycleDetector {
9
+ detect(e, t) {
10
+ const c = [];
11
+ const s = new Set();
12
+ for (const [n] of e){
13
+ if (s.has(n)) continue;
14
+ const r = [];
15
+ const o = new Set();
16
+ if (this.hasCycleDFS(n, r, o, s, e)) {
17
+ const e = r.findIndex((e)=>e === n);
18
+ if (e >= 0) {
19
+ const s = r.slice(e).map((e)=>t(e));
20
+ c.push({
21
+ cycle: s,
22
+ path: s.join(' ')
23
+ });
24
+ }
26
25
  }
27
26
  }
28
- i.logPhaseStart('resolution');
29
- const g = this.assembler.require(l.identifier, r);
30
- i.logPhaseEnd('resolution');
31
- const m = this.assembler.hookManager.getCache().find((e)=>e.instance === g);
32
- if (!m) {
33
- throw new Error('Root instance not found in assemblages cache.');
27
+ return c;
28
+ }
29
+ hasCycleDFS(e, t, c, s, n) {
30
+ if (c.has(e)) {
31
+ t.push(e);
32
+ return true;
33
+ }
34
+ if (s.has(e)) {
35
+ return false;
34
36
  }
35
- const b = this.assembler.hookManager.getCache().indexOf(m);
36
- this.assembler.hookManager.getCache().splice(b, 1);
37
- i.logPhaseStart('hooks:onInit');
38
- this.assembler.hookManager.callInitHooks(this.assembler.publicContext);
39
- const d = r ? {
40
- ...l.configuration,
41
- ...r
42
- } : l.configuration;
43
- HookManager.callHookImmediate(g, 'onInit', this.assembler.publicContext, d);
44
- i.logPhaseEnd('hooks:onInit');
45
- i.logPhaseStart('hooks:onInited');
46
- this.assembler.hookManager.callInitedHooks(this.assembler.publicContext);
47
- HookManager.callHookImmediate(g, 'onInited', this.assembler.publicContext, d);
48
- i.logPhaseEnd('hooks:onInited');
49
- this.assembler.hookManager.clearCache();
50
- return g;
37
+ t.push(e);
38
+ c.add(e);
39
+ const r = n.get(e);
40
+ if (r?.dependencies && r.dependencies.length > 0) {
41
+ for (const e of r.dependencies){
42
+ if (this.hasCycleDFS(e, t, c, s, n)) {
43
+ return true;
44
+ }
45
+ }
46
+ }
47
+ c.delete(e);
48
+ s.add(e);
49
+ return false;
50
+ }
51
+ };
52
+ class CycleDetector {
53
+ static getInstance() {
54
+ return CycleDetector.instance;
55
+ }
56
+ static enable() {
57
+ CycleDetector.instance = new ActiveCycleDetector();
51
58
  }
52
- constructor(e){
53
- this.assembler = e;
59
+ static disable() {
60
+ CycleDetector.instance = new NoOpCycleDetector();
54
61
  }
55
62
  }
63
+ CycleDetector.instance = new NoOpCycleDetector();
56
64
 
57
- export { AssemblerBuilder };
65
+ export { CycleDetector };
package/dist/index36.js CHANGED
@@ -2,36 +2,22 @@
2
2
 
3
3
  Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
4
4
 
5
- class ContextProvider {
6
- createPublicContext() {
7
- return {
8
- has: this.assembler.has.bind(this.assembler),
9
- require: this.assembler.require.bind(this.assembler),
10
- concrete: this.assembler.concrete.bind(this.assembler),
11
- tagged: this.assembler.tagged.bind(this.assembler),
12
- dispose: this.assembler.dispose.bind(this.assembler),
13
- global: this.assembler.global.bind(this.assembler),
14
- on: this.assembler.on.bind(this.assembler),
15
- once: this.assembler.once.bind(this.assembler),
16
- off: this.assembler.off.bind(this.assembler),
17
- events: this.assembler.channels
18
- };
19
- }
20
- createPrivateContext(s) {
21
- return {
22
- ...s,
23
- register: this.assembler.register.bind(this.assembler),
24
- use: this.assembler.use.bind(this.assembler),
25
- addGlobal: this.assembler.addGlobal.bind(this.assembler),
26
- prepareInitHook: this.assembler.prepareInitHook.bind(this.assembler),
27
- emit: this.assembler.emit.bind(this.assembler),
28
- addChannels: this.assembler.addChannels.bind(this.assembler),
29
- removeChannels: this.assembler.removeChannels.bind(this.assembler)
30
- };
31
- }
32
- constructor(s){
33
- this.assembler = s;
34
- }
35
- }
5
+ const constants = require('./index28.js');
36
6
 
37
- exports.ContextProvider = ContextProvider;
7
+ const defineCustomMetadata = (t, o, n)=>{
8
+ Reflect.defineMetadata(`${constants.ReflectPrefix}${t}${constants.ReflectSuffix}`, o, n);
9
+ };
10
+ const getCustomMetadata = (t, o)=>{
11
+ return Reflect.getMetadata(`${constants.ReflectPrefix}${t}${constants.ReflectSuffix}`, o);
12
+ };
13
+ const getOwnCustomMetadata = (t, o)=>{
14
+ return Reflect.getOwnMetadata(`${constants.ReflectPrefix}${t}${constants.ReflectSuffix}`, o);
15
+ };
16
+ const getParamTypes = (e)=>{
17
+ return Reflect.getMetadata(constants.ReflectParamTypes, e) || [];
18
+ };
19
+
20
+ exports.defineCustomMetadata = defineCustomMetadata;
21
+ exports.getCustomMetadata = getCustomMetadata;
22
+ exports.getOwnCustomMetadata = getOwnCustomMetadata;
23
+ exports.getParamTypes = getParamTypes;
package/dist/index36.mjs CHANGED
@@ -1,33 +1,16 @@
1
- class ContextProvider {
2
- createPublicContext() {
3
- return {
4
- has: this.assembler.has.bind(this.assembler),
5
- require: this.assembler.require.bind(this.assembler),
6
- concrete: this.assembler.concrete.bind(this.assembler),
7
- tagged: this.assembler.tagged.bind(this.assembler),
8
- dispose: this.assembler.dispose.bind(this.assembler),
9
- global: this.assembler.global.bind(this.assembler),
10
- on: this.assembler.on.bind(this.assembler),
11
- once: this.assembler.once.bind(this.assembler),
12
- off: this.assembler.off.bind(this.assembler),
13
- events: this.assembler.channels
14
- };
15
- }
16
- createPrivateContext(s) {
17
- return {
18
- ...s,
19
- register: this.assembler.register.bind(this.assembler),
20
- use: this.assembler.use.bind(this.assembler),
21
- addGlobal: this.assembler.addGlobal.bind(this.assembler),
22
- prepareInitHook: this.assembler.prepareInitHook.bind(this.assembler),
23
- emit: this.assembler.emit.bind(this.assembler),
24
- addChannels: this.assembler.addChannels.bind(this.assembler),
25
- removeChannels: this.assembler.removeChannels.bind(this.assembler)
26
- };
27
- }
28
- constructor(s){
29
- this.assembler = s;
30
- }
31
- }
1
+ import { ReflectPrefix, ReflectSuffix, ReflectParamTypes } from './index28.mjs';
32
2
 
33
- export { ContextProvider };
3
+ const defineCustomMetadata = (t, o, n)=>{
4
+ Reflect.defineMetadata(`${ReflectPrefix}${t}${ReflectSuffix}`, o, n);
5
+ };
6
+ const getCustomMetadata = (t, o)=>{
7
+ return Reflect.getMetadata(`${ReflectPrefix}${t}${ReflectSuffix}`, o);
8
+ };
9
+ const getOwnCustomMetadata = (t, o)=>{
10
+ return Reflect.getOwnMetadata(`${ReflectPrefix}${t}${ReflectSuffix}`, o);
11
+ };
12
+ const getParamTypes = (e)=>{
13
+ return Reflect.getMetadata(ReflectParamTypes, e) || [];
14
+ };
15
+
16
+ export { defineCustomMetadata, getCustomMetadata, getOwnCustomMetadata, getParamTypes };
package/dist/index37.js CHANGED
@@ -2,180 +2,112 @@
2
2
 
3
3
  Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
4
4
 
5
- function e(e) {
6
- if (e === undefined) return 'undefined';
7
- if (e === null) return 'null';
8
- if (typeof e === 'function') {
9
- if (e.name) return e.name;
10
- if (e.constructor?.name && e.constructor.name !== 'Function') {
11
- return e.constructor.name;
12
- }
13
- return 'AnonymousFunction';
14
- }
15
- if (typeof e === 'object') {
16
- const o = e.constructor?.name;
17
- if (o && o !== 'Object') {
18
- return o;
19
- }
20
- if (e.name && typeof e.name === 'string') {
21
- return e.name;
5
+ const constants = require('./index28.js');
6
+ const reflection = require('./index36.js');
7
+ const helpers = require('./index3.js');
8
+
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;
22
17
  }
23
- return '[Object]';
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
24
75
  }
25
- return String(e);
26
- }
27
- let NoOpDebugLogger = class NoOpDebugLogger {
28
- configure(e) {}
29
- log(e, o, t) {}
30
- logBuildStart(e) {}
31
- logBuildEnd(e, o) {}
32
- logRegistration(e) {}
33
- logHook(e, o, t) {}
34
- logPhaseStart(e, o) {}
35
- logPhaseEnd(e, o, t) {}
36
- logResolution(e, o, t) {}
37
- logConstruction(e) {}
38
- logInjection(e, o) {}
39
76
  };
40
- let ActiveDebugLogger = class ActiveDebugLogger {
41
- configure(e) {
42
- this.options = {
43
- ...this.options,
44
- ...e,
45
- logPhases: {
46
- ...this.options.logPhases,
47
- ...e.logPhases || {}
48
- }
49
- };
50
- }
51
- logBuildStart(e) {
52
- this.log('info', 'Build started', {
53
- entry: e.name
54
- });
55
- }
56
- logBuildEnd(e, o) {
57
- const t = {
58
- entry: e.name
59
- };
60
- if (o !== undefined) t.duration = `${o.toFixed(2)}ms`;
61
- this.log('info', 'Build completed', t);
62
- }
63
- logRegistration(o) {
64
- if (!this.shouldLog('registration')) return;
65
- this.log('info', 'Registration', {
66
- identifier: e(o.identifier),
67
- isSingleton: o.isSingleton,
68
- dependencies: o.dependencies.map((o)=>e(o)),
69
- tags: o.tags
70
- });
71
- }
72
- logHook(o, t, n) {
73
- if (!this.shouldLog('hooks')) return;
74
- const i = this.options.logTimings ? performance.now() : 0;
75
- this.log('info', `Hook: ${o}`, {
76
- target: e(t),
77
- config: n
78
- });
79
- if (this.options.logTimings) {
80
- return ()=>{
81
- const e = performance.now() - i;
82
- this.log('info', `Hook: ${o} completed`, {
83
- duration: `${e.toFixed(2)}ms`
84
- });
85
- };
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.`);
86
84
  }
87
85
  }
88
- logPhaseStart(e, o) {
89
- this.log('info', `Phase: ${e} started`, o);
90
- }
91
- logPhaseEnd(e, o, t) {
92
- const n = o !== undefined ? {
93
- duration: `${o.toFixed(2)}ms`
94
- } : {};
95
- if (t) {
96
- Object.assign(n, t);
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();
97
92
  }
98
- this.log('info', `Phase: ${e} ended`, Object.keys(n).length > 0 ? n : undefined);
99
- }
100
- logResolution(e, o, t) {
101
- if (!this.shouldLog('resolution')) return;
102
- this.log('info', `Resolving: ${e}`, {
103
- strategy: `${o} strategy`,
104
- cache: t ? 'hit' : 'miss'
105
- });
106
- }
107
- logConstruction(e) {
108
- if (!this.shouldLog('construction')) return;
109
- this.log('info', `Constructing: ${e}`);
110
- }
111
- logInjection(e, o) {
112
- if (!this.shouldLog(e === 'use' ? 'injectionUse' : 'injectionGlobal')) return;
113
- this.log('info', `Injecting: @${e === 'use' ? 'Use' : 'Global'}`, o);
114
- }
115
- shouldLog(e) {
116
- return !this.options.logPhases || this.options.logPhases[e] !== false;
117
- }
118
- log(e, o, t) {
119
- if (this.options.logger) {
120
- this.options.logger(e, o, t);
121
- } else {
122
- const n = `[Assembler:${e}]`;
123
- const i = this.options.useColors !== false ? this.colorize(e, n) : n;
124
- if (t) {
125
- console.log(`${i} ${o}`, t);
126
- } else {
127
- console.log(`${i} ${o}`);
128
- }
129
- }
130
- }
131
- colorize(e, o) {
132
- const t = {
133
- info: '\x1b[36m',
134
- warn: '\x1b[33m',
135
- error: '\x1b[31m',
136
- reset: '\x1b[0m'
137
- };
138
- const n = t[e] || t.info;
139
- return `${n}${o}${t.reset}`;
140
- }
141
- constructor(){
142
- this.options = {
143
- enabled: true,
144
- logPhases: {
145
- registration: true,
146
- registrationUse: true,
147
- registrationGlobals: true,
148
- resolution: true,
149
- construction: true,
150
- hooks: true,
151
- cache: true,
152
- injectionUse: true,
153
- injectionGlobal: true
154
- },
155
- logTimings: false,
156
- logDependencyTree: true,
157
- useColors: true
158
- };
93
+ e[r] = s(e[r]);
159
94
  }
95
+ return e;
160
96
  };
161
- class DebugLogger {
162
- static getInstance() {
163
- return DebugLogger.instance;
97
+ const getDefinition = (e)=>{
98
+ if (!helpers.isAssemblage(e)) {
99
+ throw new Error(`Class '${e.name}' is not an assemblage or transversal.`);
164
100
  }
165
- static enable(e) {
166
- if (e?.enabled === false) {
167
- DebugLogger.instance = new NoOpDebugLogger();
168
- return;
169
- }
170
- DebugLogger.instance = new ActiveDebugLogger();
171
- if (e) {
172
- DebugLogger.instance.configure(e);
173
- }
174
- }
175
- static disable() {
176
- DebugLogger.instance = new NoOpDebugLogger();
177
- }
178
- }
179
- DebugLogger.instance = new NoOpDebugLogger();
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
+ };
180
110
 
181
- exports.DebugLogger = DebugLogger;
111
+ exports.getDefinition = getDefinition;
112
+ exports.setDefinitionValue = setDefinitionValue;
113
+ exports.validateDefinition = validateDefinition;