assemblerjs 1.1.3 → 1.1.5

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 (48) hide show
  1. package/dist/index.d.ts +3 -3
  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/index31.js +71 -32
  19. package/dist/index31.mjs +71 -31
  20. package/dist/index32.js +37 -16
  21. package/dist/index32.mjs +37 -16
  22. package/dist/index33.js +68 -57
  23. package/dist/index33.mjs +68 -57
  24. package/dist/index34.js +38 -28
  25. package/dist/index34.mjs +38 -28
  26. package/dist/index35.js +28 -76
  27. package/dist/index35.mjs +28 -76
  28. package/dist/index36.js +132 -39
  29. package/dist/index36.mjs +132 -39
  30. package/dist/index37.js +39 -30
  31. package/dist/index37.mjs +38 -30
  32. package/dist/index38.js +97 -125
  33. package/dist/index38.mjs +97 -125
  34. package/dist/index39.js +24 -101
  35. package/dist/index39.mjs +24 -101
  36. package/dist/index4.js +8 -8
  37. package/dist/index4.mjs +8 -8
  38. package/dist/index40.js +18 -24
  39. package/dist/index40.mjs +18 -24
  40. package/dist/index44.js +2 -2
  41. package/dist/index44.mjs +2 -2
  42. package/dist/index48.js +1 -1
  43. package/dist/index48.mjs +1 -1
  44. package/dist/index49.js +2 -2
  45. package/dist/index49.mjs +2 -2
  46. package/dist/index50.js +12 -12
  47. package/dist/index50.mjs +12 -12
  48. package/package.json +1 -1
package/dist/index36.js CHANGED
@@ -2,46 +2,139 @@
2
2
 
3
3
  Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
4
4
 
5
- const hookManager = require('./index35.js');
6
- const debugLogger = require('./index38.js');
7
- const schema = require('./index30.js');
8
-
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
- n.logPhaseEnd('registration');
18
- n.logPhaseStart('resolution');
19
- const i = this.assembler.require(r.identifier, a);
20
- n.logPhaseEnd('resolution');
21
- const l = this.assembler.hookManager.getCache().find((e)=>e.instance === i);
22
- if (!l) {
23
- throw new Error('Root instance not found in assemblages cache.');
5
+ let NoOpDebugLogger = class NoOpDebugLogger {
6
+ configure(o) {}
7
+ log(o, e, t) {}
8
+ logBuildStart(o) {}
9
+ logBuildEnd(o, e) {}
10
+ logRegistration(o) {}
11
+ logHook(o, e, t) {}
12
+ logPhaseStart(o, e) {}
13
+ logPhaseEnd(o, e) {}
14
+ logResolution(o, e, t) {}
15
+ logConstruction(o) {}
16
+ };
17
+ let ActiveDebugLogger = class ActiveDebugLogger {
18
+ configure(o) {
19
+ this.options = {
20
+ ...this.options,
21
+ ...o,
22
+ logPhases: {
23
+ ...this.options.logPhases,
24
+ ...o.logPhases || {}
25
+ }
26
+ };
27
+ }
28
+ logBuildStart(o) {
29
+ this.log('info', 'Build started', {
30
+ entry: o.name
31
+ });
32
+ }
33
+ logBuildEnd(o, e) {
34
+ const t = {
35
+ entry: o.name
36
+ };
37
+ if (e !== undefined) t.duration = `${e.toFixed(2)}ms`;
38
+ this.log('info', 'Build completed', t);
39
+ }
40
+ logRegistration(o) {
41
+ if (!this.shouldLog('registration')) return;
42
+ this.log('info', 'Registration', {
43
+ identifier: o.identifier?.name || String(o.identifier),
44
+ isSingleton: o.isSingleton,
45
+ dependencies: o.dependencies.map((o)=>o?.name || String(o)),
46
+ tags: o.tags
47
+ });
48
+ }
49
+ logHook(o, e, t) {
50
+ if (!this.shouldLog('hooks')) return;
51
+ const s = this.options.logTimings ? performance.now() : 0;
52
+ this.log('info', `Hook: ${o}`, {
53
+ target: e.constructor?.name || e.name,
54
+ config: t
55
+ });
56
+ if (this.options.logTimings) {
57
+ return ()=>{
58
+ const e = performance.now() - s;
59
+ this.log('info', `Hook: ${o} completed`, {
60
+ duration: `${e.toFixed(2)}ms`
61
+ });
62
+ };
63
+ }
64
+ }
65
+ logPhaseStart(o, e) {
66
+ this.log('info', `Phase: ${o} started`, e);
67
+ }
68
+ logPhaseEnd(o, e) {
69
+ const t = e !== undefined ? {
70
+ duration: `${e.toFixed(2)}ms`
71
+ } : undefined;
72
+ this.log('info', `Phase: ${o} ended`, t);
73
+ }
74
+ logResolution(o, e, t) {
75
+ if (!this.shouldLog('resolution')) return;
76
+ this.log('info', `Resolving: ${o}`, {
77
+ strategy: `${e} strategy`,
78
+ cache: t ? 'hit' : 'miss'
79
+ });
80
+ }
81
+ logConstruction(o) {
82
+ if (!this.shouldLog('construction')) return;
83
+ this.log('info', `Constructing: ${o}`);
84
+ }
85
+ shouldLog(o) {
86
+ return !this.options.logPhases || this.options.logPhases[o] !== false;
87
+ }
88
+ log(o, e, t) {
89
+ if (this.options.logger) {
90
+ this.options.logger(o, e, t);
91
+ } else {
92
+ const s = `[Assembler:${o}]`;
93
+ const i = this.options.useColors !== false ? this.colorize(o, s) : s;
94
+ const n = t ? ` ${JSON.stringify(t)}` : '';
95
+ console.log(`${i} ${e}${n}`);
24
96
  }
25
- const h = this.assembler.hookManager.getCache().indexOf(l);
26
- this.assembler.hookManager.getCache().splice(h, 1);
27
- n.logPhaseStart('hooks:onInit');
28
- this.assembler.hookManager.callInitHooks(this.assembler.publicContext);
29
- const c = a ? {
30
- ...r.configuration,
31
- ...a
32
- } : r.configuration;
33
- hookManager.HookManager.callHookImmediate(i, 'onInit', this.assembler.publicContext, c);
34
- n.logPhaseEnd('hooks:onInit');
35
- n.logPhaseStart('hooks:onInited');
36
- this.assembler.hookManager.callInitedHooks(this.assembler.publicContext);
37
- hookManager.HookManager.callHookImmediate(i, 'onInited', this.assembler.publicContext, c);
38
- n.logPhaseEnd('hooks:onInited');
39
- this.assembler.hookManager.clearCache();
40
- return i;
41
- }
42
- constructor(e){
43
- this.assembler = e;
97
+ }
98
+ colorize(o, e) {
99
+ const t = {
100
+ info: '\x1b[36m',
101
+ warn: '\x1b[33m',
102
+ error: '\x1b[31m',
103
+ reset: '\x1b[0m'
104
+ };
105
+ const s = t[o] || t.info;
106
+ return `${s}${e}${t.reset}`;
107
+ }
108
+ constructor(){
109
+ this.options = {
110
+ enabled: true,
111
+ logPhases: {
112
+ registration: true,
113
+ resolution: true,
114
+ construction: true,
115
+ hooks: true,
116
+ cache: true
117
+ },
118
+ logTimings: false,
119
+ logDependencyTree: true,
120
+ useColors: true
121
+ };
122
+ }
123
+ };
124
+ class DebugLogger {
125
+ static getInstance() {
126
+ return DebugLogger.instance;
127
+ }
128
+ static enable(o) {
129
+ DebugLogger.instance = new ActiveDebugLogger();
130
+ if (o) {
131
+ DebugLogger.instance.configure(o);
132
+ }
133
+ }
134
+ static disable() {
135
+ DebugLogger.instance = new NoOpDebugLogger();
44
136
  }
45
137
  }
138
+ DebugLogger.instance = new NoOpDebugLogger();
46
139
 
47
- exports.AssemblerBuilder = AssemblerBuilder;
140
+ exports.DebugLogger = DebugLogger;
package/dist/index36.mjs CHANGED
@@ -1,43 +1,136 @@
1
- import { HookManager } from './index35.mjs';
2
- import { DebugLogger } from './index38.mjs';
3
- import { setDefinitionValue } from './index30.mjs';
4
-
5
- class AssemblerBuilder {
6
- build(t, a) {
7
- const n = DebugLogger.getInstance();
8
- setDefinitionValue('singleton', true, t);
9
- n.logPhaseStart('registration');
10
- const r = this.assembler.register([
11
- t
12
- ]);
13
- n.logPhaseEnd('registration');
14
- n.logPhaseStart('resolution');
15
- const i = this.assembler.require(r.identifier, a);
16
- n.logPhaseEnd('resolution');
17
- const l = this.assembler.hookManager.getCache().find((e)=>e.instance === i);
18
- if (!l) {
19
- throw new Error('Root instance not found in assemblages cache.');
1
+ let NoOpDebugLogger = class NoOpDebugLogger {
2
+ configure(o) {}
3
+ log(o, e, t) {}
4
+ logBuildStart(o) {}
5
+ logBuildEnd(o, e) {}
6
+ logRegistration(o) {}
7
+ logHook(o, e, t) {}
8
+ logPhaseStart(o, e) {}
9
+ logPhaseEnd(o, e) {}
10
+ logResolution(o, e, t) {}
11
+ logConstruction(o) {}
12
+ };
13
+ let ActiveDebugLogger = class ActiveDebugLogger {
14
+ configure(o) {
15
+ this.options = {
16
+ ...this.options,
17
+ ...o,
18
+ logPhases: {
19
+ ...this.options.logPhases,
20
+ ...o.logPhases || {}
21
+ }
22
+ };
23
+ }
24
+ logBuildStart(o) {
25
+ this.log('info', 'Build started', {
26
+ entry: o.name
27
+ });
28
+ }
29
+ logBuildEnd(o, e) {
30
+ const t = {
31
+ entry: o.name
32
+ };
33
+ if (e !== undefined) t.duration = `${e.toFixed(2)}ms`;
34
+ this.log('info', 'Build completed', t);
35
+ }
36
+ logRegistration(o) {
37
+ if (!this.shouldLog('registration')) return;
38
+ this.log('info', 'Registration', {
39
+ identifier: o.identifier?.name || String(o.identifier),
40
+ isSingleton: o.isSingleton,
41
+ dependencies: o.dependencies.map((o)=>o?.name || String(o)),
42
+ tags: o.tags
43
+ });
44
+ }
45
+ logHook(o, e, t) {
46
+ if (!this.shouldLog('hooks')) return;
47
+ const s = this.options.logTimings ? performance.now() : 0;
48
+ this.log('info', `Hook: ${o}`, {
49
+ target: e.constructor?.name || e.name,
50
+ config: t
51
+ });
52
+ if (this.options.logTimings) {
53
+ return ()=>{
54
+ const e = performance.now() - s;
55
+ this.log('info', `Hook: ${o} completed`, {
56
+ duration: `${e.toFixed(2)}ms`
57
+ });
58
+ };
59
+ }
60
+ }
61
+ logPhaseStart(o, e) {
62
+ this.log('info', `Phase: ${o} started`, e);
63
+ }
64
+ logPhaseEnd(o, e) {
65
+ const t = e !== undefined ? {
66
+ duration: `${e.toFixed(2)}ms`
67
+ } : undefined;
68
+ this.log('info', `Phase: ${o} ended`, t);
69
+ }
70
+ logResolution(o, e, t) {
71
+ if (!this.shouldLog('resolution')) return;
72
+ this.log('info', `Resolving: ${o}`, {
73
+ strategy: `${e} strategy`,
74
+ cache: t ? 'hit' : 'miss'
75
+ });
76
+ }
77
+ logConstruction(o) {
78
+ if (!this.shouldLog('construction')) return;
79
+ this.log('info', `Constructing: ${o}`);
80
+ }
81
+ shouldLog(o) {
82
+ return !this.options.logPhases || this.options.logPhases[o] !== false;
83
+ }
84
+ log(o, e, t) {
85
+ if (this.options.logger) {
86
+ this.options.logger(o, e, t);
87
+ } else {
88
+ const s = `[Assembler:${o}]`;
89
+ const i = this.options.useColors !== false ? this.colorize(o, s) : s;
90
+ const n = t ? ` ${JSON.stringify(t)}` : '';
91
+ console.log(`${i} ${e}${n}`);
20
92
  }
21
- const h = this.assembler.hookManager.getCache().indexOf(l);
22
- this.assembler.hookManager.getCache().splice(h, 1);
23
- n.logPhaseStart('hooks:onInit');
24
- this.assembler.hookManager.callInitHooks(this.assembler.publicContext);
25
- const c = a ? {
26
- ...r.configuration,
27
- ...a
28
- } : r.configuration;
29
- HookManager.callHookImmediate(i, 'onInit', this.assembler.publicContext, c);
30
- n.logPhaseEnd('hooks:onInit');
31
- n.logPhaseStart('hooks:onInited');
32
- this.assembler.hookManager.callInitedHooks(this.assembler.publicContext);
33
- HookManager.callHookImmediate(i, 'onInited', this.assembler.publicContext, c);
34
- n.logPhaseEnd('hooks:onInited');
35
- this.assembler.hookManager.clearCache();
36
- return i;
37
- }
38
- constructor(e){
39
- this.assembler = e;
93
+ }
94
+ colorize(o, e) {
95
+ const t = {
96
+ info: '\x1b[36m',
97
+ warn: '\x1b[33m',
98
+ error: '\x1b[31m',
99
+ reset: '\x1b[0m'
100
+ };
101
+ const s = t[o] || t.info;
102
+ return `${s}${e}${t.reset}`;
103
+ }
104
+ constructor(){
105
+ this.options = {
106
+ enabled: true,
107
+ logPhases: {
108
+ registration: true,
109
+ resolution: true,
110
+ construction: true,
111
+ hooks: true,
112
+ cache: true
113
+ },
114
+ logTimings: false,
115
+ logDependencyTree: true,
116
+ useColors: true
117
+ };
118
+ }
119
+ };
120
+ class DebugLogger {
121
+ static getInstance() {
122
+ return DebugLogger.instance;
123
+ }
124
+ static enable(o) {
125
+ DebugLogger.instance = new ActiveDebugLogger();
126
+ if (o) {
127
+ DebugLogger.instance.configure(o);
128
+ }
129
+ }
130
+ static disable() {
131
+ DebugLogger.instance = new NoOpDebugLogger();
40
132
  }
41
133
  }
134
+ DebugLogger.instance = new NoOpDebugLogger();
42
135
 
43
- export { AssemblerBuilder };
136
+ export { DebugLogger };
package/dist/index37.js CHANGED
@@ -2,36 +2,45 @@
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
- };
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);
15
+ }
16
+ for (const e of t.events){
17
+ n.on(e, (...n)=>{
18
+ t.privateContext.emit(e, ...n);
19
+ });
20
+ }
21
+ } else {
22
+ for (const e of t.events){
23
+ if (!t.privateContext.events.has(e)) t.privateContext.addChannels(e);
24
+ }
31
25
  }
32
- constructor(s){
33
- this.assembler = s;
26
+ };
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);
40
+ }
41
+ }
34
42
  }
35
- }
43
+ };
36
44
 
37
- exports.ContextProvider = ContextProvider;
45
+ exports.registerEvents = registerEvents;
46
+ exports.unregisterEvents = unregisterEvents;
package/dist/index37.mjs CHANGED
@@ -1,33 +1,41 @@
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
- };
1
+ import { EventManager } from './index6.mjs';
2
+
3
+ const registerEvents = (t, n)=>{
4
+ const o = t.concrete !== undefined && t.concrete.prototype instanceof EventManager;
5
+ if (o) {
6
+ const e = n;
7
+ const o = e.channels;
8
+ for (const n of t.events){
9
+ if (!o.has(n)) e.addChannels(n);
10
+ if (!t.privateContext.events.has(n)) t.privateContext.addChannels(n);
11
+ }
12
+ for (const e of t.events){
13
+ n.on(e, (...n)=>{
14
+ t.privateContext.emit(e, ...n);
15
+ });
16
+ }
17
+ } else {
18
+ for (const e of t.events){
19
+ if (!t.privateContext.events.has(e)) t.privateContext.addChannels(e);
20
+ }
27
21
  }
28
- constructor(s){
29
- this.assembler = s;
22
+ };
23
+ const unregisterEvents = (t, n)=>{
24
+ const o = t.concrete !== undefined && t.concrete.prototype instanceof EventManager;
25
+ if (o) {
26
+ const e = n;
27
+ for (const n of t.events){
28
+ e.off(n);
29
+ }
30
+ e.removeChannels(...t.events);
31
+ t.privateContext.removeChannels(...t.events);
32
+ } else {
33
+ for (const e of t.events){
34
+ if (t.privateContext.events.has(e)) {
35
+ t.privateContext.removeChannels(e);
36
+ }
37
+ }
30
38
  }
31
- }
39
+ };
32
40
 
33
- export { ContextProvider };
41
+ export { registerEvents, unregisterEvents };