assemblerjs 1.0.1 → 1.1.0

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 (89) hide show
  1. package/README.md +8 -5
  2. package/dist/index.d.ts +430 -9
  3. package/dist/index.js +24 -12
  4. package/dist/index.mjs +16 -12
  5. package/dist/index11.js +82 -20
  6. package/dist/index11.mjs +78 -20
  7. package/dist/index12.js +17 -8
  8. package/dist/index12.mjs +16 -8
  9. package/dist/index13.js +148 -73
  10. package/dist/index13.mjs +148 -73
  11. package/dist/index14.js +4 -17
  12. package/dist/index14.mjs +4 -17
  13. package/dist/index15.js +21 -16
  14. package/dist/index15.mjs +21 -16
  15. package/dist/index16.js +10 -16
  16. package/dist/index16.mjs +10 -16
  17. package/dist/index17.js +88 -16
  18. package/dist/index17.mjs +88 -16
  19. package/dist/index18.js +11 -20
  20. package/dist/index18.mjs +11 -19
  21. package/dist/index19.js +11 -20
  22. package/dist/index19.mjs +11 -19
  23. package/dist/index2.js +3 -3
  24. package/dist/index2.mjs +3 -3
  25. package/dist/index20.js +11 -20
  26. package/dist/index20.mjs +11 -20
  27. package/dist/index21.js +14 -25
  28. package/dist/index21.mjs +14 -21
  29. package/dist/index22.js +24 -46
  30. package/dist/index22.mjs +23 -45
  31. package/dist/index23.js +22 -37
  32. package/dist/index23.mjs +21 -36
  33. package/dist/index24.js +26 -15
  34. package/dist/index24.mjs +26 -13
  35. package/dist/index25.js +24 -10
  36. package/dist/index25.mjs +20 -8
  37. package/dist/index26.js +45 -92
  38. package/dist/index26.mjs +44 -90
  39. package/dist/index27.js +2 -66
  40. package/dist/index27.mjs +2 -64
  41. package/dist/index28.js +17 -32
  42. package/dist/index28.mjs +15 -32
  43. package/dist/index29.js +53 -55
  44. package/dist/index29.mjs +53 -55
  45. package/dist/index3.js +2 -2
  46. package/dist/index3.mjs +2 -2
  47. package/dist/index30.js +28 -28
  48. package/dist/index30.mjs +28 -28
  49. package/dist/index31.js +62 -28
  50. package/dist/index31.mjs +62 -28
  51. package/dist/index32.js +28 -19
  52. package/dist/index32.mjs +28 -19
  53. package/dist/index33.js +32 -49
  54. package/dist/index33.mjs +32 -49
  55. package/dist/index34.js +17 -8
  56. package/dist/index34.mjs +14 -8
  57. package/dist/index35.js +18 -24
  58. package/dist/index35.mjs +18 -23
  59. package/dist/index36.js +37 -108
  60. package/dist/index36.mjs +36 -108
  61. package/dist/index37.js +98 -10
  62. package/dist/index37.mjs +96 -10
  63. package/dist/index38.js +95 -20
  64. package/dist/index38.mjs +95 -20
  65. package/dist/index39.js +23 -44
  66. package/dist/index39.mjs +23 -43
  67. package/dist/index4.js +5 -5
  68. package/dist/index4.mjs +5 -5
  69. package/dist/index40.js +34 -0
  70. package/dist/index40.mjs +29 -0
  71. package/dist/index41.js +14 -0
  72. package/dist/index41.mjs +10 -0
  73. package/dist/index42.js +54 -0
  74. package/dist/index42.mjs +50 -0
  75. package/dist/index43.js +177 -0
  76. package/dist/index43.mjs +173 -0
  77. package/dist/index44.js +947 -0
  78. package/dist/index44.mjs +943 -0
  79. package/dist/index45.js +7 -0
  80. package/dist/index45.mjs +3 -0
  81. package/dist/index46.js +7 -0
  82. package/dist/index46.mjs +3 -0
  83. package/dist/index47.js +19 -0
  84. package/dist/index47.mjs +15 -0
  85. package/dist/index48.js +33 -0
  86. package/dist/index48.mjs +29 -0
  87. package/dist/index49.js +67 -0
  88. package/dist/index49.mjs +62 -0
  89. package/package.json +2 -2
package/dist/index28.mjs CHANGED
@@ -1,33 +1,16 @@
1
- class ObjectManager {
2
- use(e, t) {
3
- if (this.has(e)) {
4
- throw new Error(`A value is already registered with identifier '${String(e)}'.`);
5
- }
6
- this.objects.set(e, t);
7
- return t;
8
- }
9
- has(e) {
10
- return this.objects.has(e);
11
- }
12
- require(e) {
13
- if (!this.objects.has(e)) {
14
- throw new Error(`Injected object with identifier '${String(e)}' has not been registered.`);
15
- }
16
- return this.objects.get(e);
17
- }
18
- addGlobal(e, t) {
19
- if (this.globals.has(e)) {
20
- throw new Error(`Global value with key '${e}' has already been registered.`);
21
- }
22
- this.globals.set(e, t);
23
- }
24
- global(e) {
25
- return this.globals.get(e);
26
- }
27
- constructor(){
28
- this.objects = new Map();
29
- this.globals = new Map();
30
- }
31
- }
1
+ const ReflectParamTypes = 'design:paramtypes';
2
+ const ReflectPrefix = '__';
3
+ const ReflectSuffix = '__';
4
+ var ReflectFlags;
5
+ (function(e) {
6
+ e["IsAssemblage"] = "is_assemblage";
7
+ })(ReflectFlags || (ReflectFlags = {}));
8
+ var ReflectValue;
9
+ (function(e) {
10
+ e["AssemblageDefinition"] = "assemblage:definition.value";
11
+ e["AssemblageContext"] = "assemblage:context.value";
12
+ e["TransversalAdvices"] = "transversal:advices";
13
+ e["AffectedMethods"] = "method:applied-aspects";
14
+ })(ReflectValue || (ReflectValue = {}));
32
15
 
33
- export { ObjectManager };
16
+ export { ReflectFlags, ReflectParamTypes, ReflectPrefix, ReflectSuffix, ReflectValue };
package/dist/index29.js CHANGED
@@ -2,70 +2,68 @@
2
2
 
3
3
  Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
4
4
 
5
- const core = require('@assemblerjs/core');
5
+ const hookManager = require('./index31.js');
6
+ const resolutionStrategies = require('./index40.js');
7
+ const use = require('./index41.js');
8
+ const inject = require('./index42.js');
9
+ const injectable = require('./index43.js');
6
10
 
7
- class HookManager {
8
- prepareInitHook(e, t) {
9
- this.initCache.push({
10
- instance: e,
11
- configuration: t
12
- });
13
- return this.initCache;
11
+ class InjectableManager {
12
+ setContexts(e, t) {
13
+ this.privateContext = e;
14
+ this.publicContext = t;
14
15
  }
15
- callInitHooks(e) {
16
- for (const t of this.initCache){
17
- HookManager.callHookImmediate(t.instance, 'onInit', e, t.configuration);
16
+ register(r, n = false) {
17
+ const o = n === true ? use.resolveInstanceInjectionTuple(r) : inject.resolveInjectionTuple(r);
18
+ if (this.has(o.identifier)) {
19
+ throw new Error(`An assemblage is already registered with identifier '${o.identifier.name}'.`);
18
20
  }
21
+ const a = injectable.Injectable.of(o, this.privateContext, this.publicContext);
22
+ this.injectables.set(a.identifier, a);
23
+ hookManager.HookManager.callHook(a.concrete, 'onRegister', this.publicContext, a.configuration);
24
+ return a;
19
25
  }
20
- callInitedHooks(e) {
21
- for (const t of [
22
- ...this.initCache
23
- ].reverse()){
24
- HookManager.callHookImmediate(t.instance, 'onInited', e, t.configuration);
25
- }
26
- }
27
- clearCache() {
28
- this.initCache.length = 0;
26
+ has(e) {
27
+ return this.injectables.has(e);
29
28
  }
30
- getCache() {
31
- return this.initCache;
29
+ require(e, t) {
30
+ if (!this.injectables.has(e)) {
31
+ throw new Error(`Class with identifier '${e.name}' has not been registered or is a circular dependency.`);
32
+ }
33
+ const i = this.injectables.get(e);
34
+ if (i.isSingleton) {
35
+ return this.singletonStrategy.resolve(i, t);
36
+ } else {
37
+ return this.transientStrategy.resolve(i, t);
38
+ }
32
39
  }
33
- constructor(){
34
- this.initCache = [];
40
+ concrete(e) {
41
+ const t = this.injectables.get(e);
42
+ if (t) return t.concrete;
43
+ return;
35
44
  }
36
- }
37
- HookManager.callHook = (t, i, o, n)=>{
38
- return new Promise((a, c)=>{
39
- const r = t[i];
40
- if (r) {
41
- if (core.isAsync(r)) {
42
- r.bind(t)(o, n).then(()=>{
43
- a();
44
- }).catch((e)=>{
45
- c(e);
46
- });
47
- return;
45
+ tagged(...e) {
46
+ const t = [];
47
+ for (const i of e){
48
+ for (const [e, s] of this.injectables){
49
+ if (s.tags.includes(i)) t.push(s.build());
48
50
  }
49
- try {
50
- r.bind(t)(o, n);
51
- a();
52
- } catch (e) {
53
- c(e);
54
- }
55
- } else {
56
- a();
57
51
  }
58
- });
59
- };
60
- HookManager.callHookImmediate = (t, i, o, n)=>{
61
- const a = t[i];
62
- if (a) {
63
- if (core.isAsync(a)) {
64
- a.bind(t)(o, n).catch(()=>{});
65
- return;
52
+ return t;
53
+ }
54
+ dispose() {
55
+ for (const [e, t] of this.injectables){
56
+ t.dispose();
66
57
  }
67
- a.bind(t)(o, n);
68
58
  }
69
- };
59
+ get size() {
60
+ return this.injectables.size;
61
+ }
62
+ constructor(){
63
+ this.injectables = new Map();
64
+ this.singletonStrategy = new resolutionStrategies.SingletonStrategy();
65
+ this.transientStrategy = new resolutionStrategies.TransientStrategy();
66
+ }
67
+ }
70
68
 
71
- exports.HookManager = HookManager;
69
+ exports.InjectableManager = InjectableManager;
package/dist/index29.mjs CHANGED
@@ -1,67 +1,65 @@
1
- import { isAsync } from '@assemblerjs/core';
1
+ import { HookManager } from './index31.mjs';
2
+ import { SingletonStrategy, TransientStrategy } from './index40.mjs';
3
+ import { resolveInstanceInjectionTuple } from './index41.mjs';
4
+ import { resolveInjectionTuple } from './index42.mjs';
5
+ import { Injectable } from './index43.mjs';
2
6
 
3
- class HookManager {
4
- prepareInitHook(e, t) {
5
- this.initCache.push({
6
- instance: e,
7
- configuration: t
8
- });
9
- return this.initCache;
7
+ class InjectableManager {
8
+ setContexts(e, t) {
9
+ this.privateContext = e;
10
+ this.publicContext = t;
10
11
  }
11
- callInitHooks(e) {
12
- for (const t of this.initCache){
13
- HookManager.callHookImmediate(t.instance, 'onInit', e, t.configuration);
12
+ register(r, n = false) {
13
+ const o = n === true ? resolveInstanceInjectionTuple(r) : resolveInjectionTuple(r);
14
+ if (this.has(o.identifier)) {
15
+ throw new Error(`An assemblage is already registered with identifier '${o.identifier.name}'.`);
14
16
  }
17
+ const a = Injectable.of(o, this.privateContext, this.publicContext);
18
+ this.injectables.set(a.identifier, a);
19
+ HookManager.callHook(a.concrete, 'onRegister', this.publicContext, a.configuration);
20
+ return a;
15
21
  }
16
- callInitedHooks(e) {
17
- for (const t of [
18
- ...this.initCache
19
- ].reverse()){
20
- HookManager.callHookImmediate(t.instance, 'onInited', e, t.configuration);
21
- }
22
- }
23
- clearCache() {
24
- this.initCache.length = 0;
22
+ has(e) {
23
+ return this.injectables.has(e);
25
24
  }
26
- getCache() {
27
- return this.initCache;
25
+ require(e, t) {
26
+ if (!this.injectables.has(e)) {
27
+ throw new Error(`Class with identifier '${e.name}' has not been registered or is a circular dependency.`);
28
+ }
29
+ const i = this.injectables.get(e);
30
+ if (i.isSingleton) {
31
+ return this.singletonStrategy.resolve(i, t);
32
+ } else {
33
+ return this.transientStrategy.resolve(i, t);
34
+ }
28
35
  }
29
- constructor(){
30
- this.initCache = [];
36
+ concrete(e) {
37
+ const t = this.injectables.get(e);
38
+ if (t) return t.concrete;
39
+ return;
31
40
  }
32
- }
33
- HookManager.callHook = (t, i, o, n)=>{
34
- return new Promise((a, c)=>{
35
- const r = t[i];
36
- if (r) {
37
- if (isAsync(r)) {
38
- r.bind(t)(o, n).then(()=>{
39
- a();
40
- }).catch((e)=>{
41
- c(e);
42
- });
43
- return;
41
+ tagged(...e) {
42
+ const t = [];
43
+ for (const i of e){
44
+ for (const [e, s] of this.injectables){
45
+ if (s.tags.includes(i)) t.push(s.build());
44
46
  }
45
- try {
46
- r.bind(t)(o, n);
47
- a();
48
- } catch (e) {
49
- c(e);
50
- }
51
- } else {
52
- a();
53
47
  }
54
- });
55
- };
56
- HookManager.callHookImmediate = (t, i, o, n)=>{
57
- const a = t[i];
58
- if (a) {
59
- if (isAsync(a)) {
60
- a.bind(t)(o, n).catch(()=>{});
61
- return;
48
+ return t;
49
+ }
50
+ dispose() {
51
+ for (const [e, t] of this.injectables){
52
+ t.dispose();
62
53
  }
63
- a.bind(t)(o, n);
64
54
  }
65
- };
55
+ get size() {
56
+ return this.injectables.size;
57
+ }
58
+ constructor(){
59
+ this.injectables = new Map();
60
+ this.singletonStrategy = new SingletonStrategy();
61
+ this.transientStrategy = new TransientStrategy();
62
+ }
63
+ }
66
64
 
67
- export { HookManager };
65
+ export { InjectableManager };
package/dist/index3.js CHANGED
@@ -2,8 +2,8 @@
2
2
 
3
3
  Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
4
4
 
5
- const constants = require('./index24.js');
6
- const reflection = require('./index25.js');
5
+ const constants = require('./index28.js');
6
+ const reflection = require('./index34.js');
7
7
 
8
8
  const isAssemblage = (s)=>{
9
9
  return reflection.getOwnCustomMetadata(constants.ReflectFlags.IsAssemblage, s) || false;
package/dist/index3.mjs CHANGED
@@ -1,5 +1,5 @@
1
- import { ReflectFlags, ReflectValue } from './index24.mjs';
2
- import { getOwnCustomMetadata } from './index25.mjs';
1
+ import { ReflectFlags, ReflectValue } from './index28.mjs';
2
+ import { getOwnCustomMetadata } from './index34.mjs';
3
3
 
4
4
  const isAssemblage = (s)=>{
5
5
  return getOwnCustomMetadata(ReflectFlags.IsAssemblage, s) || false;
package/dist/index30.js CHANGED
@@ -2,36 +2,36 @@
2
2
 
3
3
  Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
4
4
 
5
- const hookManager = require('./index29.js');
6
- const schema = require('./index26.js');
7
-
8
- class AssemblerBuilder {
9
- build(t, o) {
10
- schema.setDefinitionValue('singleton', true, t);
11
- const a = this.assembler.register([
12
- t
13
- ]);
14
- const r = this.assembler.require(a.identifier, o);
15
- const i = this.assembler.hookManager.getCache().find((e)=>e.instance === r);
16
- if (!i) {
17
- throw new Error('Root instance not found in assemblages cache.');
5
+ class ObjectManager {
6
+ use(e, t) {
7
+ if (this.has(e)) {
8
+ throw new Error(`A value is already registered with identifier '${String(e)}'.`);
9
+ }
10
+ this.objects.set(e, t);
11
+ return t;
12
+ }
13
+ has(e) {
14
+ return this.objects.has(e);
15
+ }
16
+ require(e) {
17
+ if (!this.objects.has(e)) {
18
+ throw new Error(`Injected object with identifier '${String(e)}' has not been registered.`);
18
19
  }
19
- const n = this.assembler.hookManager.getCache().indexOf(i);
20
- this.assembler.hookManager.getCache().splice(n, 1);
21
- this.assembler.hookManager.callInitHooks(this.assembler.publicContext);
22
- const l = o ? {
23
- ...a.configuration,
24
- ...o
25
- } : a.configuration;
26
- hookManager.HookManager.callHookImmediate(r, 'onInit', this.assembler.publicContext, l);
27
- this.assembler.hookManager.callInitedHooks(this.assembler.publicContext);
28
- hookManager.HookManager.callHookImmediate(r, 'onInited', this.assembler.publicContext, l);
29
- this.assembler.hookManager.clearCache();
30
- return r;
20
+ return this.objects.get(e);
21
+ }
22
+ addGlobal(e, t) {
23
+ if (this.globals.has(e)) {
24
+ throw new Error(`Global value with key '${e}' has already been registered.`);
25
+ }
26
+ this.globals.set(e, t);
27
+ }
28
+ global(e) {
29
+ return this.globals.get(e);
31
30
  }
32
- constructor(e){
33
- this.assembler = e;
31
+ constructor(){
32
+ this.objects = new Map();
33
+ this.globals = new Map();
34
34
  }
35
35
  }
36
36
 
37
- exports.AssemblerBuilder = AssemblerBuilder;
37
+ exports.ObjectManager = ObjectManager;
package/dist/index30.mjs CHANGED
@@ -1,33 +1,33 @@
1
- import { HookManager } from './index29.mjs';
2
- import { setDefinitionValue } from './index26.mjs';
3
-
4
- class AssemblerBuilder {
5
- build(t, o) {
6
- setDefinitionValue('singleton', true, t);
7
- const a = this.assembler.register([
8
- t
9
- ]);
10
- const r = this.assembler.require(a.identifier, o);
11
- const i = this.assembler.hookManager.getCache().find((e)=>e.instance === r);
12
- if (!i) {
13
- throw new Error('Root instance not found in assemblages cache.');
1
+ class ObjectManager {
2
+ use(e, t) {
3
+ if (this.has(e)) {
4
+ throw new Error(`A value is already registered with identifier '${String(e)}'.`);
5
+ }
6
+ this.objects.set(e, t);
7
+ return t;
8
+ }
9
+ has(e) {
10
+ return this.objects.has(e);
11
+ }
12
+ require(e) {
13
+ if (!this.objects.has(e)) {
14
+ throw new Error(`Injected object with identifier '${String(e)}' has not been registered.`);
14
15
  }
15
- const n = this.assembler.hookManager.getCache().indexOf(i);
16
- this.assembler.hookManager.getCache().splice(n, 1);
17
- this.assembler.hookManager.callInitHooks(this.assembler.publicContext);
18
- const l = o ? {
19
- ...a.configuration,
20
- ...o
21
- } : a.configuration;
22
- HookManager.callHookImmediate(r, 'onInit', this.assembler.publicContext, l);
23
- this.assembler.hookManager.callInitedHooks(this.assembler.publicContext);
24
- HookManager.callHookImmediate(r, 'onInited', this.assembler.publicContext, l);
25
- this.assembler.hookManager.clearCache();
26
- return r;
16
+ return this.objects.get(e);
17
+ }
18
+ addGlobal(e, t) {
19
+ if (this.globals.has(e)) {
20
+ throw new Error(`Global value with key '${e}' has already been registered.`);
21
+ }
22
+ this.globals.set(e, t);
23
+ }
24
+ global(e) {
25
+ return this.globals.get(e);
27
26
  }
28
- constructor(e){
29
- this.assembler = e;
27
+ constructor(){
28
+ this.objects = new Map();
29
+ this.globals = new Map();
30
30
  }
31
31
  }
32
32
 
33
- export { AssemblerBuilder };
33
+ export { ObjectManager };
package/dist/index31.js CHANGED
@@ -2,36 +2,70 @@
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
- };
5
+ const core = require('@assemblerjs/core');
6
+
7
+ class HookManager {
8
+ prepareInitHook(e, t) {
9
+ this.initCache.push({
10
+ instance: e,
11
+ configuration: t
12
+ });
13
+ return this.initCache;
14
+ }
15
+ callInitHooks(e) {
16
+ for (const t of this.initCache){
17
+ HookManager.callHookImmediate(t.instance, 'onInit', e, t.configuration);
18
+ }
19
+ }
20
+ callInitedHooks(e) {
21
+ for (const t of [
22
+ ...this.initCache
23
+ ].reverse()){
24
+ HookManager.callHookImmediate(t.instance, 'onInited', e, t.configuration);
25
+ }
19
26
  }
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
+ clearCache() {
28
+ this.initCache.length = 0;
31
29
  }
32
- constructor(s){
33
- this.assembler = s;
30
+ getCache() {
31
+ return this.initCache;
32
+ }
33
+ constructor(){
34
+ this.initCache = [];
34
35
  }
35
36
  }
37
+ HookManager.callHook = (t, i, o, n)=>{
38
+ return new Promise((a, c)=>{
39
+ const r = t[i];
40
+ if (r) {
41
+ if (core.isAsync(r)) {
42
+ r.bind(t)(o, n).then(()=>{
43
+ a();
44
+ }).catch((e)=>{
45
+ c(e);
46
+ });
47
+ return;
48
+ }
49
+ try {
50
+ r.bind(t)(o, n);
51
+ a();
52
+ } catch (e) {
53
+ c(e);
54
+ }
55
+ } else {
56
+ a();
57
+ }
58
+ });
59
+ };
60
+ HookManager.callHookImmediate = (t, i, o, n)=>{
61
+ const a = t[i];
62
+ if (a) {
63
+ if (core.isAsync(a)) {
64
+ a.bind(t)(o, n).catch(()=>{});
65
+ return;
66
+ }
67
+ a.bind(t)(o, n);
68
+ }
69
+ };
36
70
 
37
- exports.ContextProvider = ContextProvider;
71
+ exports.HookManager = HookManager;
package/dist/index31.mjs CHANGED
@@ -1,33 +1,67 @@
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
- };
1
+ import { isAsync } from '@assemblerjs/core';
2
+
3
+ class HookManager {
4
+ prepareInitHook(e, t) {
5
+ this.initCache.push({
6
+ instance: e,
7
+ configuration: t
8
+ });
9
+ return this.initCache;
10
+ }
11
+ callInitHooks(e) {
12
+ for (const t of this.initCache){
13
+ HookManager.callHookImmediate(t.instance, 'onInit', e, t.configuration);
14
+ }
15
+ }
16
+ callInitedHooks(e) {
17
+ for (const t of [
18
+ ...this.initCache
19
+ ].reverse()){
20
+ HookManager.callHookImmediate(t.instance, 'onInited', e, t.configuration);
21
+ }
15
22
  }
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
+ clearCache() {
24
+ this.initCache.length = 0;
27
25
  }
28
- constructor(s){
29
- this.assembler = s;
26
+ getCache() {
27
+ return this.initCache;
28
+ }
29
+ constructor(){
30
+ this.initCache = [];
30
31
  }
31
32
  }
33
+ HookManager.callHook = (t, i, o, n)=>{
34
+ return new Promise((a, c)=>{
35
+ const r = t[i];
36
+ if (r) {
37
+ if (isAsync(r)) {
38
+ r.bind(t)(o, n).then(()=>{
39
+ a();
40
+ }).catch((e)=>{
41
+ c(e);
42
+ });
43
+ return;
44
+ }
45
+ try {
46
+ r.bind(t)(o, n);
47
+ a();
48
+ } catch (e) {
49
+ c(e);
50
+ }
51
+ } else {
52
+ a();
53
+ }
54
+ });
55
+ };
56
+ HookManager.callHookImmediate = (t, i, o, n)=>{
57
+ const a = t[i];
58
+ if (a) {
59
+ if (isAsync(a)) {
60
+ a.bind(t)(o, n).catch(()=>{});
61
+ return;
62
+ }
63
+ a.bind(t)(o, n);
64
+ }
65
+ };
32
66
 
33
- export { ContextProvider };
67
+ export { HookManager };