assemblerjs 1.1.11 → 1.1.13

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 (56) hide show
  1. package/dist/index.d.ts +1 -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 +16 -131
  21. package/dist/index31.mjs +16 -131
  22. package/dist/index32.js +99 -44
  23. package/dist/index32.mjs +99 -44
  24. package/dist/index33.js +23 -74
  25. package/dist/index33.mjs +23 -74
  26. package/dist/index34.js +138 -42
  27. package/dist/index34.mjs +138 -42
  28. package/dist/index35.js +47 -28
  29. package/dist/index35.mjs +47 -28
  30. package/dist/index36.js +66 -149
  31. package/dist/index36.mjs +66 -149
  32. package/dist/index37.js +41 -37
  33. package/dist/index37.mjs +41 -36
  34. package/dist/index38.js +28 -19
  35. package/dist/index38.mjs +28 -19
  36. package/dist/index39.js +151 -94
  37. package/dist/index39.mjs +151 -94
  38. package/dist/index4.js +6 -6
  39. package/dist/index4.mjs +6 -6
  40. package/dist/index40.js +36 -24
  41. package/dist/index40.mjs +35 -24
  42. package/dist/index43.js +941 -28
  43. package/dist/index43.mjs +941 -27
  44. package/dist/index44.js +2 -194
  45. package/dist/index44.mjs +2 -194
  46. package/dist/index45.js +2 -942
  47. package/dist/index45.mjs +2 -942
  48. package/dist/index46.js +29 -2
  49. package/dist/index46.mjs +28 -2
  50. package/dist/index47.js +194 -2
  51. package/dist/index47.mjs +194 -2
  52. package/dist/index48.js +1 -1
  53. package/dist/index48.mjs +1 -1
  54. package/dist/index49.js +2 -2
  55. package/dist/index49.mjs +2 -2
  56. package/package.json +1 -1
package/dist/index32.mjs CHANGED
@@ -1,52 +1,107 @@
1
- import { DebugLogger } from './index36.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/index33.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('./index36.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/index33.mjs CHANGED
@@ -1,81 +1,30 @@
1
- import { isAsync } from '@assemblerjs/core';
2
- import { DebugLogger } from './index36.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/index34.js CHANGED
@@ -2,49 +2,145 @@
2
2
 
3
3
  Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
4
4
 
5
- const hookManager = require('./index33.js');
6
- const debugLogger = require('./index36.js');
7
- const schema = require('./index30.js');
5
+ const hookManager = require('./index36.js');
6
+ const resolutionStrategies = require('./index46.js');
7
+ const debugLogger = require('./index39.js');
8
+ const core = require('@assemblerjs/core');
9
+ const use = require('./index42.js');
10
+ const inject = require('./index41.js');
11
+ const injectable = require('./index47.js');
8
12
 
9
- class AssemblerBuilder {
10
- build(t, a) {
11
- const n = debugLogger.DebugLogger.getInstance();
12
- schema.setDefinitionValue('singleton', true, t);
13
- n.logPhaseStart('registration');
14
- const r = this.assembler.register([
15
- t
16
- ]);
17
- const i = Array.from(this.assembler.injectables.keys()).map((e)=>e?.name || String(e));
18
- n.logPhaseEnd('registration', undefined, {
19
- registered: i
20
- });
21
- n.logPhaseStart('resolution');
22
- const l = this.assembler.require(r.identifier, a);
23
- n.logPhaseEnd('resolution');
24
- const h = this.assembler.hookManager.getCache().find((e)=>e.instance === l);
25
- if (!h) {
26
- throw new Error('Root instance not found in assemblages cache.');
27
- }
28
- const c = this.assembler.hookManager.getCache().indexOf(h);
29
- this.assembler.hookManager.getCache().splice(c, 1);
30
- n.logPhaseStart('hooks:onInit');
31
- this.assembler.hookManager.callInitHooks(this.assembler.publicContext);
32
- const g = a ? {
33
- ...r.configuration,
34
- ...a
35
- } : r.configuration;
36
- hookManager.HookManager.callHookImmediate(l, 'onInit', this.assembler.publicContext, g);
37
- n.logPhaseEnd('hooks:onInit');
38
- n.logPhaseStart('hooks:onInited');
39
- this.assembler.hookManager.callInitedHooks(this.assembler.publicContext);
40
- hookManager.HookManager.callHookImmediate(l, 'onInited', this.assembler.publicContext, g);
41
- n.logPhaseEnd('hooks:onInited');
42
- this.assembler.hookManager.clearCache();
43
- return l;
44
- }
45
- constructor(e){
46
- this.assembler = e;
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
+ }
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) + '...';
39
+ }
40
+ return t;
41
+ } catch {
42
+ return '[UnknownObject]';
43
+ }
44
+ }
45
+ return String(e);
46
+ }
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';
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, s = false) {
64
+ const c = debugLogger.DebugLogger.getInstance();
65
+ const a = s === 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,
70
+ error: e
71
+ });
72
+ throw new Error(e);
73
+ }
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);
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 t = this.resolvingStack.has(e);
88
+ const r = t ? 'Circular dependency detected' : 'Dependency not registered';
89
+ const i = a(e);
90
+ const s = 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, {
93
+ identifier: i,
94
+ caller: n ? a(n) : 'unknown',
95
+ type: s,
96
+ error: c
97
+ });
98
+ throw new Error(c);
99
+ }
100
+ const r = this.injectables.get(e);
101
+ this.resolvingStack.add(r.identifier);
102
+ try {
103
+ if (r.isSingleton) {
104
+ return this.singletonStrategy.resolve(r, t);
105
+ } else {
106
+ return this.transientStrategy.resolve(r, t);
107
+ }
108
+ } finally{
109
+ this.resolvingStack.delete(r.identifier);
110
+ }
111
+ }
112
+ concrete(e) {
113
+ const t = this.injectables.get(e);
114
+ if (t) return t.concrete;
115
+ return;
116
+ }
117
+ tagged(...e) {
118
+ const t = [];
119
+ for (const n of e){
120
+ for (const [e, r] of this.injectables){
121
+ if (r.tags.includes(n)) t.push(r.build());
122
+ }
123
+ }
124
+ return t;
125
+ }
126
+ dispose() {
127
+ for (const [e, t] of this.injectables){
128
+ t.dispose();
129
+ }
130
+ this.resolvingStack.clear();
131
+ }
132
+ get size() {
133
+ return this.injectables.size;
134
+ }
135
+ getRegisteredIdentifiers() {
136
+ return Array.from(this.injectables.keys()).map((e)=>e?.name || String(e));
137
+ }
138
+ constructor(){
139
+ this.injectables = new Map();
140
+ this.resolvingStack = new Set();
141
+ this.singletonStrategy = new resolutionStrategies.SingletonStrategy();
142
+ this.transientStrategy = new resolutionStrategies.TransientStrategy();
47
143
  }
48
144
  }
49
145
 
50
- exports.AssemblerBuilder = AssemblerBuilder;
146
+ exports.InjectableManager = InjectableManager;