assemblerjs 1.1.18 → 1.1.19

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 (71) hide show
  1. package/dist/index11.js +2 -2
  2. package/dist/index11.mjs +2 -2
  3. package/dist/index13.js +2 -2
  4. package/dist/index13.mjs +2 -2
  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 +2 -2
  20. package/dist/index22.mjs +2 -2
  21. package/dist/index23.js +2 -2
  22. package/dist/index23.mjs +2 -2
  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 +15 -38
  30. package/dist/index29.mjs +12 -37
  31. package/dist/index3.js +1 -1
  32. package/dist/index3.mjs +1 -1
  33. package/dist/index30.js +100 -151
  34. package/dist/index30.mjs +98 -150
  35. package/dist/index31.js +99 -44
  36. package/dist/index31.mjs +99 -44
  37. package/dist/index32.js +23 -74
  38. package/dist/index32.mjs +23 -74
  39. package/dist/index33.js +154 -51
  40. package/dist/index33.mjs +153 -51
  41. package/dist/index34.js +47 -28
  42. package/dist/index34.mjs +47 -28
  43. package/dist/index35.js +65 -152
  44. package/dist/index35.mjs +65 -152
  45. package/dist/index36.js +50 -58
  46. package/dist/index36.mjs +50 -58
  47. package/dist/index37.js +32 -18
  48. package/dist/index37.mjs +32 -15
  49. package/dist/index38.js +158 -99
  50. package/dist/index38.mjs +158 -97
  51. package/dist/index39.js +57 -16
  52. package/dist/index39.mjs +57 -16
  53. package/dist/index4.js +7 -7
  54. package/dist/index4.mjs +7 -7
  55. package/dist/index40.js +35 -100
  56. package/dist/index40.mjs +34 -100
  57. package/dist/index41.js +18 -24
  58. package/dist/index41.mjs +18 -24
  59. package/dist/index42.js +49 -29
  60. package/dist/index42.mjs +49 -28
  61. package/dist/index44.js +29 -49
  62. package/dist/index44.mjs +28 -49
  63. package/dist/index45.js +4 -4
  64. package/dist/index45.mjs +4 -4
  65. package/dist/index49.js +1 -1
  66. package/dist/index49.mjs +1 -1
  67. package/dist/index50.js +2 -2
  68. package/dist/index50.mjs +2 -2
  69. package/dist/index51.js +1 -1
  70. package/dist/index51.mjs +1 -1
  71. package/package.json +1 -1
package/dist/index31.mjs CHANGED
@@ -1,52 +1,107 @@
1
- import { DebugLogger } from './index35.mjs';
1
+ import { TransversalManager } from './index13.mjs';
2
+ import { getAffectedMethods } from './index12.mjs';
2
3
 
3
- function t(e) {
4
- return typeof e === 'symbol' ? 'symbol' : 'string';
5
- }
6
- class ObjectManager {
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
15
- });
16
- throw new Error(s);
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;
18
+ });
19
+ if (s.length === 0 && !f) {
20
+ return n;
17
21
  }
18
- this.objects.set(r, o);
19
- return o;
20
- }
21
- has(e) {
22
- return this.objects.has(e);
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
+ });
23
40
  }
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
32
- });
33
- throw new Error(s);
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;
72
+ });
73
+ }
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;
34
86
  }
35
- return this.objects.get(r);
36
- }
37
- addGlobal(e, t) {
38
- if (this.globals.has(e)) {
39
- throw new Error(`Global value with key '${e}' has already been registered.`);
40
- }
41
- this.globals.set(e, t);
42
- }
43
- global(e) {
44
- return this.globals.get(e);
45
87
  }
46
- constructor(){
47
- this.objects = new Map();
48
- this.globals = new Map();
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();
49
104
  }
50
105
  }
51
106
 
52
- export { ObjectManager };
107
+ export { TransversalWeaver };
package/dist/index32.js CHANGED
@@ -2,84 +2,33 @@
2
2
 
3
3
  Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
4
4
 
5
- const core = require('@assemblerjs/core');
6
- const debugLogger = require('./index35.js');
7
-
8
- class HookManager {
9
- prepareInitHook(o, t) {
10
- this.initCache.push({
11
- instance: o,
12
- configuration: t
13
- });
14
- return this.initCache;
15
- }
16
- callInitHooks(o) {
17
- for (const t of this.initCache){
18
- HookManager.callHookImmediate(t.instance, 'onInit', o, t.configuration);
19
- }
20
- }
21
- callInitedHooks(o) {
22
- for (const t of [
23
- ...this.initCache
24
- ].reverse()){
25
- HookManager.callHookImmediate(t.instance, 'onInited', o, t.configuration);
5
+ class PointcutMatcher {
6
+ static parse(t) {
7
+ const e = t.match(/^execution\(([^.]+)\.([^)]+)\)$/);
8
+ if (!e) {
9
+ throw new Error(`Invalid pointcut expression: ${t}`);
26
10
  }
27
- }
28
- clearCache() {
29
- this.initCache.length = 0;
30
- }
31
- getCache() {
32
- return this.initCache;
33
- }
34
- constructor(){
35
- this.initCache = [];
11
+ const [, c, r] = e;
12
+ return new ExecutionPointcutMatcher(c, r);
36
13
  }
37
14
  }
38
- HookManager.callHook = (e, i, n, a)=>{
39
- const c = debugLogger.DebugLogger.getInstance();
40
- const r = c.logHook(i, e, a);
41
- return new Promise((t, c)=>{
42
- const s = e[i];
43
- if (s) {
44
- if (core.isAsync(s)) {
45
- s.bind(e)(n, a).then(()=>{
46
- if (r) r();
47
- t();
48
- }).catch((o)=>{
49
- if (r) r();
50
- c(o);
51
- });
52
- return;
53
- }
54
- try {
55
- s.bind(e)(n, a);
56
- if (r) r();
57
- t();
58
- } catch (o) {
59
- if (r) r();
60
- c(o);
61
- }
62
- } else {
63
- if (r) r();
64
- t();
65
- }
66
- });
67
- };
68
- HookManager.callHookImmediate = (e, i, n, a)=>{
69
- const c = debugLogger.DebugLogger.getInstance();
70
- const r = c.logHook(i, e, a);
71
- const s = e[i];
72
- if (s) {
73
- if (core.isAsync(s)) {
74
- s.bind(e)(n, a).catch(()=>{});
75
- if (r) r();
76
- return;
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 /.*/;
77
24
  }
78
- s.bind(e)(n, a);
79
- if (r) r();
80
- } else {
81
- if (r) r();
25
+ const e = t.replace(/[.+?^${}()|[\]\\]/g, '\\$&').replace(/\*/g, '.*');
26
+ return new RegExp(`^${e}$`);
27
+ }
28
+ constructor(t, e){
29
+ this.classRegex = this.patternToRegex(t);
30
+ this.methodRegex = this.patternToRegex(e);
82
31
  }
83
32
  };
84
33
 
85
- exports.HookManager = HookManager;
34
+ exports.PointcutMatcher = PointcutMatcher;
package/dist/index32.mjs CHANGED
@@ -1,81 +1,30 @@
1
- import { isAsync } from '@assemblerjs/core';
2
- import { DebugLogger } from './index35.mjs';
3
-
4
- class HookManager {
5
- prepareInitHook(o, t) {
6
- this.initCache.push({
7
- instance: o,
8
- configuration: t
9
- });
10
- return this.initCache;
11
- }
12
- callInitHooks(o) {
13
- for (const t of this.initCache){
14
- HookManager.callHookImmediate(t.instance, 'onInit', o, t.configuration);
15
- }
16
- }
17
- callInitedHooks(o) {
18
- for (const t of [
19
- ...this.initCache
20
- ].reverse()){
21
- HookManager.callHookImmediate(t.instance, 'onInited', o, t.configuration);
1
+ class PointcutMatcher {
2
+ static parse(t) {
3
+ const e = t.match(/^execution\(([^.]+)\.([^)]+)\)$/);
4
+ if (!e) {
5
+ throw new Error(`Invalid pointcut expression: ${t}`);
22
6
  }
23
- }
24
- clearCache() {
25
- this.initCache.length = 0;
26
- }
27
- getCache() {
28
- return this.initCache;
29
- }
30
- constructor(){
31
- this.initCache = [];
7
+ const [, c, r] = e;
8
+ return new ExecutionPointcutMatcher(c, r);
32
9
  }
33
10
  }
34
- HookManager.callHook = (e, i, n, a)=>{
35
- const c = DebugLogger.getInstance();
36
- const r = c.logHook(i, e, a);
37
- return new Promise((t, c)=>{
38
- const s = e[i];
39
- if (s) {
40
- if (isAsync(s)) {
41
- s.bind(e)(n, a).then(()=>{
42
- if (r) r();
43
- t();
44
- }).catch((o)=>{
45
- if (r) r();
46
- c(o);
47
- });
48
- return;
49
- }
50
- try {
51
- s.bind(e)(n, a);
52
- if (r) r();
53
- t();
54
- } catch (o) {
55
- if (r) r();
56
- c(o);
57
- }
58
- } else {
59
- if (r) r();
60
- t();
61
- }
62
- });
63
- };
64
- HookManager.callHookImmediate = (e, i, n, a)=>{
65
- const c = DebugLogger.getInstance();
66
- const r = c.logHook(i, e, a);
67
- const s = e[i];
68
- if (s) {
69
- if (isAsync(s)) {
70
- s.bind(e)(n, a).catch(()=>{});
71
- if (r) r();
72
- return;
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 /.*/;
73
20
  }
74
- s.bind(e)(n, a);
75
- if (r) r();
76
- } else {
77
- if (r) r();
21
+ const e = t.replace(/[.+?^${}()|[\]\\]/g, '\\$&').replace(/\*/g, '.*');
22
+ return new RegExp(`^${e}$`);
23
+ }
24
+ constructor(t, e){
25
+ this.classRegex = this.patternToRegex(t);
26
+ this.methodRegex = this.patternToRegex(e);
78
27
  }
79
28
  };
80
29
 
81
- export { HookManager };
30
+ export { PointcutMatcher };
package/dist/index33.js CHANGED
@@ -2,60 +2,163 @@
2
2
 
3
3
  Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
4
4
 
5
- const hookManager = require('./index32.js');
6
- const debugLogger = require('./index35.js');
7
- const cycleDetector = require('./index36.js');
8
- const injectableManager = require('./index30.js');
9
- const schema = require('./index38.js');
5
+ const hookManager = require('./index35.js');
6
+ const resolutionStrategies = require('./index44.js');
7
+ const debugLogger = require('./index38.js');
8
+ const core = require('@assemblerjs/core');
9
+ const use = require('./index43.js');
10
+ const inject = require('./index42.js');
11
+ const injectable = require('./index45.js');
10
12
 
11
- class AssemblerBuilder {
12
- build(n, r) {
13
- const i = debugLogger.DebugLogger.getInstance();
14
- schema.setDefinitionValue('singleton', true, n);
15
- i.logPhaseStart('registration');
16
- const l = this.assembler.register([
17
- n
18
- ]);
19
- const c = this.assembler.injectableManager.getRegisteredIdentifiers();
20
- i.logPhaseEnd('registration', undefined, {
21
- registered: c
22
- });
23
- const h = cycleDetector.CycleDetector.getInstance().detect(this.assembler.injectableManager.getInjectables(), (e)=>injectableManager.formatIdentifier(e));
24
- if (h.length > 0) {
25
- for (const e of h){
26
- i.log('error', 'Circular dependency detected', {
27
- cycle: e.cycle,
28
- path: e.path
29
- });
13
+ function formatIdentifier(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
+ }
23
+ if (typeof e === 'string') return e;
24
+ if (typeof e === 'symbol') return e.toString();
25
+ if (typeof e === 'number') return String(e);
26
+ if (typeof e === 'boolean') return String(e);
27
+ if (typeof e === 'object') {
28
+ if (e.name && typeof e.name === 'string') {
29
+ return e.name;
30
+ }
31
+ const t = e.constructor?.name;
32
+ if (t && t !== 'Object') {
33
+ return t;
34
+ }
35
+ try {
36
+ const t = JSON.stringify(e);
37
+ if (t.length > 100) {
38
+ return t.substring(0, 100) + '...';
30
39
  }
40
+ return t;
41
+ } catch {
42
+ return '[UnknownObject]';
31
43
  }
32
- i.logPhaseStart('resolution');
33
- const g = this.assembler.require(l.identifier, r);
34
- i.logPhaseEnd('resolution');
35
- const m = this.assembler.hookManager.getCache().find((e)=>e.instance === g);
36
- if (!m) {
37
- throw new Error('Root instance not found in assemblages cache.');
38
- }
39
- const b = this.assembler.hookManager.getCache().indexOf(m);
40
- this.assembler.hookManager.getCache().splice(b, 1);
41
- i.logPhaseStart('hooks:onInit');
42
- this.assembler.hookManager.callInitHooks(this.assembler.publicContext);
43
- const d = r ? {
44
- ...l.configuration,
45
- ...r
46
- } : l.configuration;
47
- hookManager.HookManager.callHookImmediate(g, 'onInit', this.assembler.publicContext, d);
48
- i.logPhaseEnd('hooks:onInit');
49
- i.logPhaseStart('hooks:onInited');
50
- this.assembler.hookManager.callInitedHooks(this.assembler.publicContext);
51
- hookManager.HookManager.callHookImmediate(g, 'onInited', this.assembler.publicContext, d);
52
- i.logPhaseEnd('hooks:onInited');
53
- this.assembler.hookManager.clearCache();
54
- return g;
55
- }
56
- constructor(e){
57
- this.assembler = e;
44
+ }
45
+ return String(e);
46
+ }
47
+ function c(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';
53
+ if (typeof e === 'string') return 'string';
54
+ if (typeof e === 'symbol') return 'symbol';
55
+ if (typeof e === 'object' && e !== null) return 'object';
56
+ return 'unknown';
57
+ }
58
+ class InjectableManager {
59
+ setContexts(e, t) {
60
+ this.privateContext = e;
61
+ this.publicContext = t;
62
+ }
63
+ register(i, o = false) {
64
+ const a = debugLogger.DebugLogger.getInstance();
65
+ const c = o === true ? use.resolveInstanceInjectionTuple(i) : inject.resolveInjectionTuple(i);
66
+ if (this.has(c.identifier)) {
67
+ const e = `An assemblage is already registered with identifier '${c.identifier.name}'.`;
68
+ a.log('error', 'Duplicate registration', {
69
+ identifier: c.identifier.name,
70
+ error: e
71
+ });
72
+ throw new Error(e);
73
+ }
74
+ const f = injectable.Injectable.of(c, this.privateContext, this.publicContext);
75
+ a.logRegistration(f);
76
+ this.injectables.set(f.identifier, f);
77
+ if (f.concrete) {
78
+ hookManager.HookManager.callHook(f.concrete, 'onRegister', this.publicContext, f.configuration);
79
+ }
80
+ return f;
81
+ }
82
+ has(e) {
83
+ return this.injectables.has(e);
84
+ }
85
+ require(e, t, n) {
86
+ if (!this.injectables.has(e)) {
87
+ const r = this.resolvingStack.has(e);
88
+ const i = r ? 'Circular dependency detected' : 'Dependency not registered';
89
+ const o = formatIdentifier(e);
90
+ const a = c(e);
91
+ const f = t?.__paramIndex;
92
+ const u = t?.__paramCount;
93
+ const l = t?.__expectedType;
94
+ const g = r ? `Circular dependency detected: '${o}' is already being resolved.` : `Dependency '${o}' has not been registered (Class/Service not found in current assemblages).`;
95
+ const d = {
96
+ identifier: o,
97
+ caller: n ? formatIdentifier(n) : 'unknown',
98
+ type: a,
99
+ error: g
100
+ };
101
+ if (f !== undefined) {
102
+ d.paramIndex = f;
103
+ }
104
+ if (u !== undefined) {
105
+ d.paramCount = u;
106
+ }
107
+ if (l !== undefined) {
108
+ const e = l?.name || formatIdentifier(l);
109
+ d.expectedType = e;
110
+ }
111
+ debugLogger.DebugLogger.getInstance().log('error', i, d);
112
+ throw new Error(g);
113
+ }
114
+ const r = this.injectables.get(e);
115
+ this.resolvingStack.add(r.identifier);
116
+ try {
117
+ if (r.isSingleton) {
118
+ return this.singletonStrategy.resolve(r, t);
119
+ } else {
120
+ return this.transientStrategy.resolve(r, t);
121
+ }
122
+ } finally{
123
+ this.resolvingStack.delete(r.identifier);
124
+ }
125
+ }
126
+ concrete(e) {
127
+ const t = this.injectables.get(e);
128
+ if (t) return t.concrete;
129
+ return;
130
+ }
131
+ tagged(...e) {
132
+ const t = [];
133
+ for (const n of e){
134
+ for (const [e, r] of this.injectables){
135
+ if (r.tags.includes(n)) t.push(r.build());
136
+ }
137
+ }
138
+ return t;
139
+ }
140
+ dispose() {
141
+ for (const [e, t] of this.injectables){
142
+ t.dispose();
143
+ }
144
+ this.resolvingStack.clear();
145
+ }
146
+ get size() {
147
+ return this.injectables.size;
148
+ }
149
+ getRegisteredIdentifiers() {
150
+ return Array.from(this.injectables.keys()).map((e)=>e?.name || String(e));
151
+ }
152
+ getInjectables() {
153
+ return this.injectables;
154
+ }
155
+ constructor(){
156
+ this.injectables = new Map();
157
+ this.resolvingStack = new Set();
158
+ this.singletonStrategy = new resolutionStrategies.SingletonStrategy();
159
+ this.transientStrategy = new resolutionStrategies.TransientStrategy();
58
160
  }
59
161
  }
60
162
 
61
- exports.AssemblerBuilder = AssemblerBuilder;
163
+ exports.InjectableManager = InjectableManager;
164
+ exports.formatIdentifier = formatIdentifier;