assemblerjs 1.1.15 → 1.1.17

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 (64) hide show
  1. package/dist/index.d.ts +5 -0
  2. package/dist/index13.js +1 -1
  3. package/dist/index13.mjs +1 -1
  4. package/dist/index18.js +1 -1
  5. package/dist/index18.mjs +1 -1
  6. package/dist/index19.js +1 -1
  7. package/dist/index19.mjs +1 -1
  8. package/dist/index20.js +1 -1
  9. package/dist/index20.mjs +1 -1
  10. package/dist/index21.js +1 -1
  11. package/dist/index21.mjs +1 -1
  12. package/dist/index22.js +1 -1
  13. package/dist/index22.mjs +1 -1
  14. package/dist/index23.js +1 -1
  15. package/dist/index23.mjs +1 -1
  16. package/dist/index24.js +1 -1
  17. package/dist/index24.mjs +1 -1
  18. package/dist/index27.js +1 -1
  19. package/dist/index27.mjs +1 -1
  20. package/dist/index31.js +38 -20
  21. package/dist/index31.mjs +37 -20
  22. package/dist/index32.js +93 -142
  23. package/dist/index32.mjs +93 -142
  24. package/dist/index33.js +23 -45
  25. package/dist/index33.mjs +23 -45
  26. package/dist/index34.js +16 -73
  27. package/dist/index34.mjs +16 -73
  28. package/dist/index35.js +156 -42
  29. package/dist/index35.mjs +155 -42
  30. package/dist/index36.js +47 -28
  31. package/dist/index36.mjs +47 -28
  32. package/dist/index37.js +66 -149
  33. package/dist/index37.mjs +66 -149
  34. package/dist/index38.js +48 -98
  35. package/dist/index38.mjs +48 -98
  36. package/dist/index39.js +29 -26
  37. package/dist/index39.mjs +29 -26
  38. package/dist/index4.js +11 -6
  39. package/dist/index4.mjs +11 -6
  40. package/dist/index40.js +158 -32
  41. package/dist/index40.mjs +158 -31
  42. package/dist/index41.js +61 -46
  43. package/dist/index41.mjs +61 -46
  44. package/dist/index42.js +44 -18
  45. package/dist/index42.mjs +44 -17
  46. package/dist/index43.js +22 -28
  47. package/dist/index43.mjs +21 -27
  48. package/dist/index44.js +940 -192
  49. package/dist/index44.mjs +940 -192
  50. package/dist/index45.js +2 -942
  51. package/dist/index45.mjs +2 -942
  52. package/dist/index46.js +2 -2
  53. package/dist/index46.mjs +2 -2
  54. package/dist/index47.js +29 -2
  55. package/dist/index47.mjs +28 -2
  56. package/dist/index48.js +189 -9
  57. package/dist/index48.mjs +189 -9
  58. package/dist/index49.js +9 -34
  59. package/dist/index49.mjs +9 -34
  60. package/dist/index50.js +32 -59
  61. package/dist/index50.mjs +32 -58
  62. package/dist/index51.js +74 -0
  63. package/dist/index51.mjs +69 -0
  64. package/package.json +1 -1
package/dist/index38.mjs CHANGED
@@ -1,107 +1,57 @@
1
- import { TransversalManager } from './index13.mjs';
2
- import { getAffectedMethods } from './index12.mjs';
1
+ import { HookManager } from './index37.mjs';
2
+ import { DebugLogger } from './index40.mjs';
3
+ import { CycleDetector } from './index41.mjs';
4
+ import { formatIdentifier } from './index35.mjs';
5
+ import { setDefinitionValue } from './index30.mjs';
3
6
 
4
- class TransversalWeaver {
5
- static weave(n, r, o) {
6
- const c = TransversalManager.getInstance(o);
7
- const s = c.getAspectsForTarget(r);
8
- const a = Object.getPrototypeOf(n);
9
- const f = Object.getOwnPropertyNames(a).some((t)=>{
10
- if (t === 'constructor') return false;
11
- const n = Object.getOwnPropertyDescriptor(a, t);
12
- if (!n) return false;
13
- const r = n.value && typeof n.value === 'function';
14
- const o = n.get && typeof n.get === 'function';
15
- if (!r && !o) return false;
16
- const c = getAffectedMethods(a, t);
17
- return c.length > 0;
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
18
  });
19
- if (s.length === 0 && !f) {
20
- return n;
21
- }
22
- return new Proxy(n, {
23
- get (t, e, n) {
24
- const r = Reflect.get(t, e, n);
25
- if (typeof r !== 'function') {
26
- return r;
27
- }
28
- return function(...n) {
29
- const o = String(e);
30
- const a = {
31
- target: t,
32
- methodName: o,
33
- args: n
34
- };
35
- const f = c.getAdvicesForJoinPoint(a, s, t, e);
36
- return TransversalWeaver.executeAdviceChain(f, r, t, n, a);
37
- };
38
- }
39
- });
40
- }
41
- static executeAdviceChain(t, e, n, r, o) {
42
- const c = t.filter((t)=>t.type === 'before');
43
- const s = t.filter((t)=>t.type === 'around');
44
- const a = t.filter((t)=>t.type === 'after');
45
- try {
46
- for (const t of c){
47
- const e = {
48
- ...o,
49
- config: t.config
50
- };
51
- t.method.call(t.transversalInstance, e);
52
- }
53
- let t;
54
- if (s.length > 0) {
55
- t = this.buildAroundChain(s, e, n, r, o);
56
- } else {
57
- t = e.apply(n, r);
58
- }
59
- if (t instanceof Promise) {
60
- return t.then((t)=>{
61
- for (const e of a){
62
- const n = {
63
- ...o,
64
- result: t
65
- };
66
- e.method.call(e.transversalInstance, n);
67
- }
68
- return t;
69
- }).catch((t)=>{
70
- o.error = t;
71
- throw t;
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
72
25
  });
73
26
  }
74
- for (const e of a){
75
- const n = {
76
- ...o,
77
- result: t,
78
- config: e.config
79
- };
80
- e.method.call(e.transversalInstance, n);
81
- }
82
- return t;
83
- } catch (t) {
84
- o.error = t;
85
- throw t;
86
27
  }
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.');
34
+ }
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;
87
51
  }
88
- static buildAroundChain(t, e, n, r, o) {
89
- let c = 0;
90
- const s = ()=>{
91
- if (c < t.length) {
92
- const e = t[c++];
93
- const n = {
94
- ...o,
95
- proceed: s,
96
- config: e.config
97
- };
98
- return e.method.call(e.transversalInstance, n);
99
- } else {
100
- return e.apply(n, r);
101
- }
102
- };
103
- return s();
52
+ constructor(e){
53
+ this.assembler = e;
104
54
  }
105
55
  }
106
56
 
107
- export { TransversalWeaver };
57
+ export { AssemblerBuilder };
package/dist/index39.js CHANGED
@@ -2,33 +2,36 @@
2
2
 
3
3
  Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
4
4
 
5
- class PointcutMatcher {
6
- static parse(t) {
7
- const e = t.match(/^execution\(([^.]+)\.([^)]+)\)$/);
8
- if (!e) {
9
- throw new Error(`Invalid pointcut expression: ${t}`);
10
- }
11
- const [, c, r] = e;
12
- return new ExecutionPointcutMatcher(c, r);
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
+ };
13
19
  }
14
- }
15
- let ExecutionPointcutMatcher = class ExecutionPointcutMatcher {
16
- matches(t) {
17
- const e = t.target.constructor.name;
18
- const c = t.methodName;
19
- return this.classRegex.test(e) && this.methodRegex.test(c);
20
- }
21
- patternToRegex(t) {
22
- if (t === '*') {
23
- return /.*/;
24
- }
25
- const e = t.replace(/[.+?^${}()|[\]\\]/g, '\\$&').replace(/\*/g, '.*');
26
- return new RegExp(`^${e}$`);
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
+ };
27
31
  }
28
- constructor(t, e){
29
- this.classRegex = this.patternToRegex(t);
30
- this.methodRegex = this.patternToRegex(e);
32
+ constructor(s){
33
+ this.assembler = s;
31
34
  }
32
- };
35
+ }
33
36
 
34
- exports.PointcutMatcher = PointcutMatcher;
37
+ exports.ContextProvider = ContextProvider;
package/dist/index39.mjs CHANGED
@@ -1,30 +1,33 @@
1
- class PointcutMatcher {
2
- static parse(t) {
3
- const e = t.match(/^execution\(([^.]+)\.([^)]+)\)$/);
4
- if (!e) {
5
- throw new Error(`Invalid pointcut expression: ${t}`);
6
- }
7
- const [, c, r] = e;
8
- return new ExecutionPointcutMatcher(c, r);
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
+ };
9
15
  }
10
- }
11
- let ExecutionPointcutMatcher = class ExecutionPointcutMatcher {
12
- matches(t) {
13
- const e = t.target.constructor.name;
14
- const c = t.methodName;
15
- return this.classRegex.test(e) && this.methodRegex.test(c);
16
- }
17
- patternToRegex(t) {
18
- if (t === '*') {
19
- return /.*/;
20
- }
21
- const e = t.replace(/[.+?^${}()|[\]\\]/g, '\\$&').replace(/\*/g, '.*');
22
- return new RegExp(`^${e}$`);
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
+ };
23
27
  }
24
- constructor(t, e){
25
- this.classRegex = this.patternToRegex(t);
26
- this.methodRegex = this.patternToRegex(e);
28
+ constructor(s){
29
+ this.assembler = s;
27
30
  }
28
- };
31
+ }
29
32
 
30
- export { PointcutMatcher };
33
+ export { ContextProvider };
package/dist/index4.js CHANGED
@@ -3,20 +3,25 @@
3
3
  Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
4
4
 
5
5
  const core = require('@assemblerjs/core');
6
- const injectableManager = require('./index32.js');
7
- const objectManager = require('./index33.js');
8
- const hookManager = require('./index34.js');
9
- const assemblerBuilder = require('./index35.js');
10
- const contextProvider = require('./index36.js');
11
- const debugLogger = require('./index37.js');
6
+ const injectableManager = require('./index35.js');
7
+ const objectManager = require('./index36.js');
8
+ const hookManager = require('./index37.js');
9
+ const assemblerBuilder = require('./index38.js');
10
+ const contextProvider = require('./index39.js');
11
+ const debugLogger = require('./index40.js');
12
+ const cycleDetector = require('./index41.js');
12
13
  const eventManager = require('./index6.js');
13
14
 
14
15
  class Assembler extends eventManager.EventManager {
15
16
  static enableDebug(e) {
16
17
  debugLogger.DebugLogger.enable(e);
18
+ if (e?.enabled !== false && e?.detectCycles === true) {
19
+ cycleDetector.CycleDetector.enable();
20
+ }
17
21
  }
18
22
  static disableDebug() {
19
23
  debugLogger.DebugLogger.disable();
24
+ cycleDetector.CycleDetector.disable();
20
25
  }
21
26
  static build(e, t) {
22
27
  const r = debugLogger.DebugLogger.getInstance();
package/dist/index4.mjs CHANGED
@@ -1,18 +1,23 @@
1
1
  import { clearInstance } from '@assemblerjs/core';
2
- import { InjectableManager } from './index32.mjs';
3
- import { ObjectManager } from './index33.mjs';
4
- import { HookManager } from './index34.mjs';
5
- import { AssemblerBuilder } from './index35.mjs';
6
- import { ContextProvider } from './index36.mjs';
7
- import { DebugLogger } from './index37.mjs';
2
+ import { InjectableManager } from './index35.mjs';
3
+ import { ObjectManager } from './index36.mjs';
4
+ import { HookManager } from './index37.mjs';
5
+ import { AssemblerBuilder } from './index38.mjs';
6
+ import { ContextProvider } from './index39.mjs';
7
+ import { DebugLogger } from './index40.mjs';
8
+ import { CycleDetector } from './index41.mjs';
8
9
  import { EventManager } from './index6.mjs';
9
10
 
10
11
  class Assembler extends EventManager {
11
12
  static enableDebug(e) {
12
13
  DebugLogger.enable(e);
14
+ if (e?.enabled !== false && e?.detectCycles === true) {
15
+ CycleDetector.enable();
16
+ }
13
17
  }
14
18
  static disableDebug() {
15
19
  DebugLogger.disable();
20
+ CycleDetector.disable();
16
21
  }
17
22
  static build(e, t) {
18
23
  const r = DebugLogger.getInstance();
package/dist/index40.js CHANGED
@@ -2,45 +2,171 @@
2
2
 
3
3
  Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
4
4
 
5
- const eventManager = require('./index6.js');
6
-
7
- const registerEvents = (t, n)=>{
8
- const o = t.concrete !== undefined && t.concrete.prototype instanceof eventManager.EventManager;
9
- if (o) {
10
- const e = n;
11
- const o = e.channels;
12
- for (const n of t.events){
13
- if (!o.has(n)) e.addChannels(n);
14
- if (!t.privateContext.events.has(n)) t.privateContext.addChannels(n);
5
+ function o(o) {
6
+ if (o === undefined) return 'undefined';
7
+ if (o === null) return 'null';
8
+ if (typeof o === 'function') {
9
+ if (o.name) return o.name;
10
+ if (o.constructor?.name && o.constructor.name !== 'Function') {
11
+ return o.constructor.name;
15
12
  }
16
- for (const e of t.events){
17
- n.on(e, (...n)=>{
18
- t.privateContext.emit(e, ...n);
19
- });
13
+ return 'AnonymousFunction';
14
+ }
15
+ if (typeof o === 'object') {
16
+ if (o.name && typeof o.name === 'string') {
17
+ return o.name;
20
18
  }
21
- } else {
22
- for (const e of t.events){
23
- if (!t.privateContext.events.has(e)) t.privateContext.addChannels(e);
19
+ const e = o.constructor?.name;
20
+ if (e && e !== 'Object') {
21
+ return e;
24
22
  }
23
+ return '[Object]';
25
24
  }
25
+ return String(o);
26
+ }
27
+ let NoOpDebugLogger = class NoOpDebugLogger {
28
+ configure(o) {}
29
+ log(o, e, t) {}
30
+ logBuildStart(o) {}
31
+ logBuildEnd(o, e) {}
32
+ logRegistration(o) {}
33
+ logHook(o, e, t) {}
34
+ logPhaseStart(o, e) {}
35
+ logPhaseEnd(o, e, t) {}
36
+ logResolution(o, e, t) {}
37
+ logConstruction(o) {}
26
38
  };
27
- const unregisterEvents = (t, n)=>{
28
- const o = t.concrete !== undefined && t.concrete.prototype instanceof eventManager.EventManager;
29
- if (o) {
30
- const e = n;
31
- for (const n of t.events){
32
- e.off(n);
33
- }
34
- e.removeChannels(...t.events);
35
- t.privateContext.removeChannels(...t.events);
36
- } else {
37
- for (const e of t.events){
38
- if (t.privateContext.events.has(e)) {
39
- t.privateContext.removeChannels(e);
39
+ let ActiveDebugLogger = class ActiveDebugLogger {
40
+ configure(o) {
41
+ this.options = {
42
+ ...this.options,
43
+ ...o,
44
+ logPhases: {
45
+ ...this.options.logPhases,
46
+ ...o.logPhases || {}
47
+ }
48
+ };
49
+ }
50
+ logBuildStart(o) {
51
+ this.log('info', 'Build started', {
52
+ entry: o.name
53
+ });
54
+ }
55
+ logBuildEnd(o, e) {
56
+ const t = {
57
+ entry: o.name
58
+ };
59
+ if (e !== undefined) t.duration = `${e.toFixed(2)}ms`;
60
+ this.log('info', 'Build completed', t);
61
+ }
62
+ logRegistration(e) {
63
+ if (!this.shouldLog('registration')) return;
64
+ this.log('info', 'Registration', {
65
+ identifier: o(e.identifier),
66
+ isSingleton: e.isSingleton,
67
+ dependencies: e.dependencies.map((e)=>o(e)),
68
+ tags: e.tags
69
+ });
70
+ }
71
+ logHook(e, t, n) {
72
+ if (!this.shouldLog('hooks')) return;
73
+ const s = this.options.logTimings ? performance.now() : 0;
74
+ this.log('info', `Hook: ${e}`, {
75
+ target: o(t),
76
+ config: n
77
+ });
78
+ if (this.options.logTimings) {
79
+ return ()=>{
80
+ const o = performance.now() - s;
81
+ this.log('info', `Hook: ${e} completed`, {
82
+ duration: `${o.toFixed(2)}ms`
83
+ });
84
+ };
85
+ }
86
+ }
87
+ logPhaseStart(o, e) {
88
+ this.log('info', `Phase: ${o} started`, e);
89
+ }
90
+ logPhaseEnd(o, e, t) {
91
+ const n = e !== undefined ? {
92
+ duration: `${e.toFixed(2)}ms`
93
+ } : {};
94
+ if (t) {
95
+ Object.assign(n, t);
96
+ }
97
+ this.log('info', `Phase: ${o} ended`, Object.keys(n).length > 0 ? n : undefined);
98
+ }
99
+ logResolution(o, e, t) {
100
+ if (!this.shouldLog('resolution')) return;
101
+ this.log('info', `Resolving: ${o}`, {
102
+ strategy: `${e} strategy`,
103
+ cache: t ? 'hit' : 'miss'
104
+ });
105
+ }
106
+ logConstruction(o) {
107
+ if (!this.shouldLog('construction')) return;
108
+ this.log('info', `Constructing: ${o}`);
109
+ }
110
+ shouldLog(o) {
111
+ return !this.options.logPhases || this.options.logPhases[o] !== false;
112
+ }
113
+ log(o, e, t) {
114
+ if (this.options.logger) {
115
+ this.options.logger(o, e, t);
116
+ } else {
117
+ const n = `[Assembler:${o}]`;
118
+ const s = this.options.useColors !== false ? this.colorize(o, n) : n;
119
+ if (t) {
120
+ console.log(`${s} ${e}`, t);
121
+ } else {
122
+ console.log(`${s} ${e}`);
40
123
  }
41
124
  }
42
125
  }
126
+ colorize(o, e) {
127
+ const t = {
128
+ info: '\x1b[36m',
129
+ warn: '\x1b[33m',
130
+ error: '\x1b[31m',
131
+ reset: '\x1b[0m'
132
+ };
133
+ const n = t[o] || t.info;
134
+ return `${n}${e}${t.reset}`;
135
+ }
136
+ constructor(){
137
+ this.options = {
138
+ enabled: true,
139
+ logPhases: {
140
+ registration: true,
141
+ resolution: true,
142
+ construction: true,
143
+ hooks: true,
144
+ cache: true
145
+ },
146
+ logTimings: false,
147
+ logDependencyTree: true,
148
+ useColors: true
149
+ };
150
+ }
43
151
  };
152
+ class DebugLogger {
153
+ static getInstance() {
154
+ return DebugLogger.instance;
155
+ }
156
+ static enable(o) {
157
+ if (o?.enabled === false) {
158
+ DebugLogger.instance = new NoOpDebugLogger();
159
+ return;
160
+ }
161
+ DebugLogger.instance = new ActiveDebugLogger();
162
+ if (o) {
163
+ DebugLogger.instance.configure(o);
164
+ }
165
+ }
166
+ static disable() {
167
+ DebugLogger.instance = new NoOpDebugLogger();
168
+ }
169
+ }
170
+ DebugLogger.instance = new NoOpDebugLogger();
44
171
 
45
- exports.registerEvents = registerEvents;
46
- exports.unregisterEvents = unregisterEvents;
172
+ exports.DebugLogger = DebugLogger;