@adaas/a-concept 0.0.5 → 0.0.6

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 (121) hide show
  1. package/dist/examples/simple/components/A.component.d.ts +4 -2
  2. package/dist/examples/simple/components/A.component.js +7 -4
  3. package/dist/examples/simple/components/A.component.js.map +1 -1
  4. package/dist/examples/simple/components/B.component.d.ts +6 -2
  5. package/dist/examples/simple/components/B.component.js +18 -7
  6. package/dist/examples/simple/components/B.component.js.map +1 -1
  7. package/dist/examples/simple/concept.js +59 -32
  8. package/dist/examples/simple/concept.js.map +1 -1
  9. package/dist/examples/simple/containers/Main.container.d.ts +1 -2
  10. package/dist/examples/simple/containers/Main.container.js +18 -5
  11. package/dist/examples/simple/containers/Main.container.js.map +1 -1
  12. package/dist/examples/simple-http-server/components/http-error-handler.component.d.ts +2 -1
  13. package/dist/examples/simple-http-server/components/http-error-handler.component.js +3 -1
  14. package/dist/examples/simple-http-server/components/http-error-handler.component.js.map +1 -1
  15. package/dist/examples/simple-http-server/components/http-request-handler.component.d.ts +2 -1
  16. package/dist/examples/simple-http-server/components/http-request-handler.component.js +2 -1
  17. package/dist/examples/simple-http-server/components/http-request-handler.component.js.map +1 -1
  18. package/dist/examples/simple-http-server/containers/http-server.container.d.ts +1 -2
  19. package/dist/index.d.ts +5 -1
  20. package/dist/index.js +10 -2
  21. package/dist/index.js.map +1 -1
  22. package/dist/src/base/A-Config/A-Config.container.d.ts +1 -3
  23. package/dist/src/base/A-Config/A-Config.container.js +6 -22
  24. package/dist/src/base/A-Config/A-Config.container.js.map +1 -1
  25. package/dist/src/base/A-Config/A-Config.context.d.ts +1 -0
  26. package/dist/src/base/A-Config/A-Config.context.js +20 -2
  27. package/dist/src/base/A-Config/A-Config.context.js.map +1 -1
  28. package/dist/src/base/A-Config/A-Config.types.d.ts +2 -2
  29. package/dist/src/base/A-Config/components/ConfigReader.component.d.ts +2 -1
  30. package/dist/src/base/A-Config/components/ConfigReader.component.js +3 -1
  31. package/dist/src/base/A-Config/components/ConfigReader.component.js.map +1 -1
  32. package/dist/src/base/A-Errors/A-Errors.component.d.ts +2 -1
  33. package/dist/src/base/A-Errors/A-Errors.component.js +3 -1
  34. package/dist/src/base/A-Errors/A-Errors.component.js.map +1 -1
  35. package/dist/src/base/A-Logger/A-Logger.component.d.ts +4 -2
  36. package/dist/src/base/A-Logger/A-Logger.component.js +11 -3
  37. package/dist/src/base/A-Logger/A-Logger.component.js.map +1 -1
  38. package/dist/src/decorators/A-Feature/A-Feature-Define.decorator.js.map +1 -1
  39. package/dist/src/decorators/A-Feature/A-Feature-Extend.decorator.js +9 -9
  40. package/dist/src/decorators/A-Feature/A-Feature-Extend.decorator.js.map +1 -1
  41. package/dist/src/decorators/A-Inject/A-Inject.decorator.d.ts +0 -2
  42. package/dist/src/decorators/A-Inject/A-Inject.decorator.js +4 -2
  43. package/dist/src/decorators/A-Inject/A-Inject.decorator.js.map +1 -1
  44. package/dist/src/global/A-Component/A-Component.class.d.ts +28 -1
  45. package/dist/src/global/A-Component/A-Component.class.js +22 -0
  46. package/dist/src/global/A-Component/A-Component.class.js.map +1 -1
  47. package/dist/src/global/A-Component/A-Component.meta.d.ts +8 -1
  48. package/dist/src/global/A-Component/A-Component.meta.js +26 -0
  49. package/dist/src/global/A-Component/A-Component.meta.js.map +1 -1
  50. package/dist/src/global/A-Component/A-Component.types.d.ts +43 -6
  51. package/dist/src/global/A-Component/A-Component.types.js +5 -0
  52. package/dist/src/global/A-Component/A-Component.types.js.map +1 -1
  53. package/dist/src/global/A-Concept/A_Concept.class.d.ts +7 -7
  54. package/dist/src/global/A-Concept/A_Concept.class.js +1 -2
  55. package/dist/src/global/A-Concept/A_Concept.class.js.map +1 -1
  56. package/dist/src/global/A-Container/A-Container.class.d.ts +5 -4
  57. package/dist/src/global/A-Container/A-Container.class.js +13 -24
  58. package/dist/src/global/A-Container/A-Container.class.js.map +1 -1
  59. package/dist/src/global/A-Container/A-Container.meta.d.ts +0 -3
  60. package/dist/src/global/A-Container/A-Container.meta.js +0 -46
  61. package/dist/src/global/A-Container/A-Container.meta.js.map +1 -1
  62. package/dist/src/global/A-Context/A-Context.class.d.ts +34 -5
  63. package/dist/src/global/A-Context/A-Context.class.js +135 -53
  64. package/dist/src/global/A-Context/A-Context.class.js.map +1 -1
  65. package/dist/src/global/A-Context/A-Context.types.d.ts +0 -12
  66. package/dist/src/global/A-Context/A-Context.types.js +0 -1
  67. package/dist/src/global/A-Entity/A-Entity.class.d.ts +28 -4
  68. package/dist/src/global/A-Entity/A-Entity.class.js +23 -3
  69. package/dist/src/global/A-Entity/A-Entity.class.js.map +1 -1
  70. package/dist/src/global/A-Entity/A-Entity.meta.d.ts +4 -0
  71. package/dist/src/global/A-Entity/A-Entity.meta.js +8 -0
  72. package/dist/src/global/A-Entity/A-Entity.meta.js.map +1 -0
  73. package/dist/src/global/A-Entity/A-Entity.types.d.ts +43 -0
  74. package/dist/src/global/A-Entity/A-Entity.types.js +13 -0
  75. package/dist/src/global/A-Entity/A-Entity.types.js.map +1 -1
  76. package/dist/src/global/A-Feature/A-Feature.class.d.ts +11 -1
  77. package/dist/src/global/A-Feature/A-Feature.class.js +48 -12
  78. package/dist/src/global/A-Feature/A-Feature.class.js.map +1 -1
  79. package/dist/src/global/A-Feature/A-Feature.types.d.ts +5 -4
  80. package/dist/src/global/A-Feature/A-Feature.types.js.map +1 -1
  81. package/dist/src/global/A-Fragment/A-Fragment.class.js +1 -2
  82. package/dist/src/global/A-Fragment/A-Fragment.class.js.map +1 -1
  83. package/dist/src/global/A-Meta/A-Meta.class.d.ts +75 -1
  84. package/dist/src/global/A-Meta/A-Meta.class.js +100 -10
  85. package/dist/src/global/A-Meta/A-Meta.class.js.map +1 -1
  86. package/dist/src/global/A-Scope/A-Scope.class.d.ts +15 -6
  87. package/dist/src/global/A-Scope/A-Scope.class.js +59 -17
  88. package/dist/src/global/A-Scope/A-Scope.class.js.map +1 -1
  89. package/examples/simple/components/A.component.ts +6 -3
  90. package/examples/simple/components/B.component.ts +19 -6
  91. package/examples/simple/concept.ts +65 -33
  92. package/examples/simple/containers/Main.container.ts +28 -7
  93. package/examples/simple-http-server/components/http-error-handler.component.ts +5 -2
  94. package/examples/simple-http-server/components/http-request-handler.component.ts +3 -1
  95. package/index.ts +6 -1
  96. package/package.json +1 -1
  97. package/src/base/A-Config/A-Config.container.ts +5 -8
  98. package/src/base/A-Config/A-Config.context.ts +10 -2
  99. package/src/base/A-Config/A-Config.types.ts +2 -2
  100. package/src/base/A-Config/components/ConfigReader.component.ts +5 -2
  101. package/src/base/A-Errors/A-Errors.component.ts +3 -2
  102. package/src/base/A-Logger/A-Logger.component.ts +21 -3
  103. package/src/decorators/A-Feature/A-Feature-Define.decorator.ts +0 -1
  104. package/src/decorators/A-Feature/A-Feature-Extend.decorator.ts +15 -10
  105. package/src/decorators/A-Inject/A-Inject.decorator.ts +13 -11
  106. package/src/global/A-Component/A-Component.class.ts +56 -1
  107. package/src/global/A-Component/A-Component.meta.ts +40 -1
  108. package/src/global/A-Component/A-Component.types.ts +51 -19
  109. package/src/global/A-Concept/A_Concept.class.ts +2 -2
  110. package/src/global/A-Container/A-Container.class.ts +22 -34
  111. package/src/global/A-Container/A-Container.meta.ts +0 -64
  112. package/src/global/A-Context/A-Context.class.ts +237 -79
  113. package/src/global/A-Context/A-Context.types.ts +0 -15
  114. package/src/global/A-Entity/A-Entity.class.ts +65 -8
  115. package/src/global/A-Entity/A-Entity.meta.ts +9 -0
  116. package/src/global/A-Entity/A-Entity.types.ts +58 -0
  117. package/src/global/A-Feature/A-Feature.class.ts +62 -20
  118. package/src/global/A-Feature/A-Feature.types.ts +8 -2
  119. package/src/global/A-Fragment/A-Fragment.class.ts +1 -5
  120. package/src/global/A-Meta/A-Meta.class.ts +114 -22
  121. package/src/global/A-Scope/A-Scope.class.ts +100 -33
@@ -1,7 +1,6 @@
1
1
  import { A_Feature_Define } from "@adaas/a-concept/decorators/A-Feature/A-Feature-Define.decorator";
2
2
  import { A_Feature_Extend } from "@adaas/a-concept/decorators/A-Feature/A-Feature-Extend.decorator";
3
- import { A_TYPES__FeatureConstructor, A_TYPES__FeatureState, A_TYPES__FeatureStep } from "./A-Feature.types";
4
- import { A_Scope } from "../A-Scope/A-Scope.class";
3
+ import { A_TYPES__FeatureConstructor, A_TYPES__FeatureIteratorReturn, A_TYPES__FeatureState, A_TYPES__FeatureStep } from "./A-Feature.types";
5
4
  import { A_Error, A_TYPES__Required } from "@adaas/a-utils";
6
5
  import { A_Context } from "../A-Context/A-Context.class";
7
6
 
@@ -37,7 +36,9 @@ export class A_Feature {
37
36
 
38
37
 
39
38
  // protected scope: A_Scope
40
- protected steps: A_TYPES__FeatureStep[] = []
39
+ protected steps: A_TYPES__FeatureStep[] = [];
40
+ protected _current?: A_TYPES__FeatureStep;
41
+ protected _index: number = 0;
41
42
 
42
43
  state: A_TYPES__FeatureState = A_TYPES__FeatureState.INITIALIZED;
43
44
 
@@ -55,6 +56,61 @@ export class A_Feature {
55
56
  }
56
57
 
57
58
 
59
+ /**
60
+ * Custom iterator to iterate over the steps of the feature
61
+ *
62
+ * @returns
63
+ */
64
+ [Symbol.iterator](): Iterator<A_TYPES__FeatureIteratorReturn, any> {
65
+ return {
66
+ // Custom next method
67
+ next: (): IteratorResult<A_TYPES__FeatureIteratorReturn, any> => {
68
+ if (this._index < this.steps.length) {
69
+ if (
70
+ (this.state as any) === A_TYPES__FeatureState.FAILED
71
+ ||
72
+ (this.state as any) === A_TYPES__FeatureState.COMPLETED
73
+ ) {
74
+ throw new Error('FEATURE_PROCESSING_INTERRUPTED');
75
+ }
76
+
77
+ this._current = this.steps[this._index];
78
+
79
+ const { component, handler, args } = this._current;
80
+
81
+ const instance = A_Context.scope(this).resolve(component);
82
+
83
+ return {
84
+ value: async () => {
85
+
86
+ if (instance[handler]) {
87
+ const callArgs = A_Context.scope(this).resolve(args);
88
+ await instance[handler](...callArgs);
89
+ }
90
+
91
+ this._index++;
92
+ },
93
+ done: false
94
+ };
95
+ } else {
96
+ this._current = undefined; // Reset current on end
97
+ return { value: undefined, done: true };
98
+ }
99
+ }
100
+ };
101
+ }
102
+
103
+ // Access the current element
104
+ get current(): A_TYPES__FeatureStep | undefined {
105
+ return this._current;
106
+ }
107
+
108
+ // Custom end strategy or stop condition (could be expanded if needed)
109
+ isDone(): boolean {
110
+ return this.current === null;
111
+ }
112
+
113
+
58
114
  /**
59
115
  * This method marks the feature as completed and returns the result
60
116
  * Uses to interrupt or end the feature processing
@@ -94,28 +150,14 @@ export class A_Feature {
94
150
  try {
95
151
  this.state = A_TYPES__FeatureState.PROCESSING;
96
152
 
97
- for (const { component, handler, args } of this.steps) {
98
-
99
- if (
100
- (this.state as any) === A_TYPES__FeatureState.FAILED
101
- ||
102
- (this.state as any) === A_TYPES__FeatureState.COMPLETED
103
- ) {
104
- throw new Error('FEATURE_PROCESSING_INTERRUPTED');
105
- }
106
-
107
- const instance = A_Context.scope(this).resolve(component);
108
-
109
- if (instance[handler]) {
110
- const callArgs = A_Context.scope(this).resolve(args);
111
- await instance[handler](...callArgs);
112
- }
153
+ for (const step of this) {
154
+ await step();
113
155
  }
114
156
 
115
157
  await this.completed();
116
158
 
117
159
  } catch (error) {
118
- console.log('Feature processing error:', error);
160
+ console.log('[!] Feature processing error:', error);
119
161
 
120
162
  await this.failed(error);
121
163
  }
@@ -1,5 +1,11 @@
1
+ import { A_Component } from "../A-Component/A-Component.class"
2
+ import { A_TYPES__ComponentMeta_InjectionParam } from "../A-Component/A-Component.types"
1
3
  import { A_TYPES__ScopeConfig, A_TYPES__ScopeConstructor } from "../A-Scope/A-Scope.types"
2
4
 
5
+
6
+ export type A_TYPES__FeatureIteratorReturn<T extends any = any> = () => Promise<T>
7
+
8
+
3
9
  export type A_TYPES__FeatureConstructor = {
4
10
  steps: A_TYPES__FeatureStep[]
5
11
  } & A_TYPES__ScopeConstructor & A_TYPES__ScopeConfig
@@ -14,7 +20,7 @@ export enum A_TYPES__FeatureState {
14
20
 
15
21
 
16
22
  export type A_TYPES__FeatureStep = {
17
- component: { new(...args: any[]): any },
23
+ component: typeof A_Component,
18
24
  handler: string,
19
- args: any[]
25
+ args: A_TYPES__ComponentMeta_InjectionParam[]
20
26
  }
@@ -28,11 +28,7 @@ export class A_Fragment {
28
28
  /**
29
29
  * Register the Namespace in the global Namespace provider
30
30
  */
31
- this.name = A_Context
32
- .register(
33
- this,
34
- this.name
35
- );
31
+ this.name = params.name || this.constructor.name;
36
32
 
37
33
  /**
38
34
  * Run Async Initialization
@@ -1,7 +1,9 @@
1
- import { A_TYPES__Dictionary } from "@adaas/a-utils";
2
- import { A_Component } from "../A-Component/A-Component.class";
3
- import { A_Container } from "../A-Container/A-Container.class";
4
-
1
+ //
2
+ //
3
+ //
4
+ //
5
+ //
6
+ //
5
7
 
6
8
 
7
9
  /**
@@ -12,11 +14,34 @@ import { A_Container } from "../A-Container/A-Container.class";
12
14
  export class A_Meta<
13
15
  _StorageItems extends Record<string, any>
14
16
  // _StorageItems extends Record<string, Map<string | Symbol, any> | Array<any> | A_TYPES__Dictionary<any>>
15
- > {
17
+ > implements Iterable<[keyof _StorageItems, _StorageItems[keyof _StorageItems]]> {
16
18
 
17
19
  protected meta: Map<keyof _StorageItems, _StorageItems[keyof _StorageItems]> = new Map();
18
20
 
19
21
 
22
+ /**
23
+ * Method to get the iterator for the meta object
24
+ *
25
+ * @returns
26
+ */
27
+ [Symbol.iterator](): Iterator<[keyof _StorageItems, _StorageItems[keyof _StorageItems]]> {
28
+ const iterator = this.meta.entries();
29
+ return {
30
+ next: () => iterator.next()
31
+ };
32
+ }
33
+
34
+
35
+
36
+ // ===================================================================================================
37
+ // ================================ META OPERATIONS ==================================================
38
+ // ===================================================================================================
39
+ /**
40
+ * Allows to replicate received meta object by replacing internal meta to the received one
41
+ *
42
+ * @param meta
43
+ * @returns
44
+ */
20
45
  from(
21
46
  meta: A_Meta<_StorageItems>
22
47
  ): A_Meta<_StorageItems> {
@@ -26,11 +51,12 @@ export class A_Meta<
26
51
  }
27
52
 
28
53
 
29
- // ===================================================================================================
30
- // ================================ META OPERATIONS ==================================================
31
- // ===================================================================================================
32
-
33
- // Method to set values in the map
54
+ /**
55
+ * Method to set values in the map
56
+ *
57
+ * @param key
58
+ * @param value
59
+ */
34
60
  set<K extends keyof _StorageItems>(key: K, value: _StorageItems[K]) {
35
61
 
36
62
  const inheritedValue = this.meta.get(key)
@@ -51,18 +77,76 @@ export class A_Meta<
51
77
 
52
78
  }
53
79
 
54
- // Method to get values from the map
80
+
81
+
82
+ /**
83
+ * Method to get values from the map
84
+ *
85
+ * @param key
86
+ * @returns
87
+ */
55
88
  get<K extends keyof _StorageItems>(key: K): _StorageItems[K] | undefined {
56
89
  return this.meta.get(key) as _StorageItems[K];
57
90
  }
58
91
 
59
92
 
60
- // Delete a key-value pair by key
93
+ /**
94
+ * Method to delete values from the map
95
+ *
96
+ * @param key
97
+ * @returns
98
+ */
61
99
  delete(key: keyof _StorageItems): boolean {
62
100
  return this.meta.delete(key);
63
101
  }
64
102
 
65
- // Search for keys by regex
103
+
104
+ /**
105
+ * This method is needed to convert the key to a regular expression and cover cases like:
106
+ *
107
+ * simple * e.g. "a*" instead of "a.*"
108
+ *
109
+ * simple ? e.g. "a?" instead of "a."
110
+ *
111
+ * etc.
112
+ *
113
+ * @param key
114
+ * @returns
115
+ */
116
+ private convertToRegExp(key: string | RegExp): RegExp {
117
+ return key instanceof RegExp
118
+ ? key
119
+ : new RegExp(key);
120
+ }
121
+
122
+
123
+ /**
124
+ * Method to find values in the map by name.
125
+ *
126
+ * Converts the Key in Map to a regular expression and then compares to the name
127
+ *
128
+ * @param name
129
+ * @returns
130
+ */
131
+ find(name: string) {
132
+ const results: Array<[keyof _StorageItems, _StorageItems[keyof _StorageItems]]> = [];
133
+ for (const [key, value] of this.meta.entries()) {
134
+ if (this.convertToRegExp(name).test(key as string)) {
135
+ results.push([key, value]);
136
+ }
137
+ }
138
+ return results;
139
+ }
140
+
141
+
142
+ /**
143
+ * Method to find values in the map by regular expression
144
+ *
145
+ * Compares Map Key to the input regular expression
146
+ *
147
+ * @param regex
148
+ * @returns
149
+ */
66
150
  findByRegex(regex: RegExp): Array<[keyof _StorageItems, _StorageItems[keyof _StorageItems]]> {
67
151
  const results: Array<[keyof _StorageItems, _StorageItems[keyof _StorageItems]]> = [];
68
152
  for (const [key, value] of this.meta.entries()) {
@@ -73,24 +157,32 @@ export class A_Meta<
73
157
  return results;
74
158
  }
75
159
 
76
- // Check if a key exists
160
+
161
+ /**
162
+ * Method to check if the map has a specific key
163
+ *
164
+ * @param key
165
+ * @returns
166
+ */
77
167
  has(key: keyof _StorageItems): boolean {
78
168
  return this.meta.has(key);
79
169
  }
80
170
 
81
- // Get all entries in the map
171
+
172
+ /**
173
+ * Method to get the size of the map
174
+ *
175
+ * @returns
176
+ */
82
177
  entries(): IterableIterator<[keyof _StorageItems, _StorageItems[keyof _StorageItems]]> {
83
178
  return this.meta.entries();
84
179
  }
85
180
 
86
181
 
87
- // Clear all entries
182
+ /**
183
+ * Method to clear the map
184
+ */
88
185
  clear(): void {
89
186
  this.meta.clear();
90
187
  }
91
-
92
-
93
-
94
- }
95
-
96
-
188
+ }
@@ -2,7 +2,9 @@ import { A_CommonHelper } from "@adaas/a-utils";
2
2
  import { A_TYPES__ScopeConfig, A_TYPES__ScopeConstructor } from "./A-Scope.types";
3
3
  import { A_Fragment } from "../A-Fragment/A-Fragment.class";
4
4
  import { A_Context } from "../A-Context/A-Context.class";
5
- import { A_TYPES__ComponentMetaKey } from "../A-Component/A-Component.types";
5
+ import { A_TYPES__ComponentMeta_InjectionParam, A_TYPES__ComponentMetaKey } from "../A-Component/A-Component.types";
6
+ import { A_Component } from "../A-Component/A-Component.class";
7
+ import { A_Entity } from "../A-Entity/A-Entity.class";
6
8
 
7
9
  /**
8
10
  *
@@ -21,8 +23,9 @@ export class A_Scope {
21
23
 
22
24
  name: string = '';
23
25
 
24
- private _components: WeakMap<{ new(...args: any[]): any }, any> = new WeakMap();
26
+ private _components: WeakMap<typeof A_Component.constructor, any> = new WeakMap();
25
27
  private _fragments: WeakMap<typeof A_Fragment.constructor, any> = new WeakMap();
28
+ private _entities: Map<string, A_Entity> = new Map();
26
29
 
27
30
  private parent?: A_Scope;
28
31
 
@@ -126,10 +129,10 @@ export class A_Scope {
126
129
  * @param component
127
130
  * @returns
128
131
  */
129
- resolve<T extends { new(...args: any[]): any }>(component: T): InstanceType<T>
130
- resolve<T extends { new(...args: any[]): any }>(component: Array<T>): Array<InstanceType<T>>
132
+ resolve<T extends A_TYPES__ComponentMeta_InjectionParam>(component: T): InstanceType<T>
133
+ resolve<T extends A_TYPES__ComponentMeta_InjectionParam>(component: Array<T>): Array<InstanceType<T>>
131
134
  // base definition
132
- resolve<T extends { new(...args: any[]): any }>(
135
+ resolve<T extends A_TYPES__ComponentMeta_InjectionParam>(
133
136
  param1: Array<T> | T,
134
137
  param2?: string
135
138
  ): Array<InstanceType<T>> | InstanceType<T> {
@@ -151,46 +154,28 @@ export class A_Scope {
151
154
 
152
155
 
153
156
 
154
-
155
- private resolveOnce<T extends { new(...args: any[]): any }>(component: T): InstanceType<T> {
157
+ private resolveOnce<T extends A_TYPES__ComponentMeta_InjectionParam>(component: T): InstanceType<T> {
156
158
  switch (true) {
157
159
  case A_CommonHelper.isInheritedFrom(component, A_Fragment): {
158
- return this.resolveFragment(component);
160
+ return this.resolveFragment(component as typeof A_Fragment) as InstanceType<T>;
159
161
  }
160
162
 
161
- case this.components.includes(component) && this._components.has(component): {
162
-
163
- return this._components.get(component);
163
+ case A_CommonHelper.isInheritedFrom(component, A_Scope): {
164
+ return this.resolveScope(component as typeof A_Scope) as InstanceType<T>;
164
165
  }
165
- case this.components.includes(component) && !this._components.has(component): {
166
-
167
- const componentMeta = A_Context.meta(component)
168
-
169
- const argsMeta = componentMeta.get(A_TYPES__ComponentMetaKey.INJECTIONS);
170
-
171
- let resolvedArgs: Array<any> = [];
172
-
173
- if (argsMeta)
174
- resolvedArgs = (argsMeta.get('constructor') || [])
175
- .map(arg => this.resolve(arg));
176
166
 
177
- this._components.set(component, new component());
178
-
179
- return this._components.get(component);
167
+ case A_CommonHelper.isInheritedFrom(component, A_Component): {
168
+ return this.resolveComponent(component as typeof A_Component) as InstanceType<T>;
180
169
  }
181
170
 
182
- case !this.components.includes(component) && !!this.parent: {
183
-
184
- return this.parent.resolve(component);
185
- }
186
171
  default:
187
- throw new Error(`Component ${component.name} not found in the scope`);
172
+ throw new Error(`Injected Component ${component} not found in the scope`);
188
173
  }
189
174
  }
190
175
 
191
176
 
192
177
 
193
- private resolveFragment<T extends { new(...args: any[]): any }>(fragment: T): InstanceType<T> {
178
+ private resolveFragment<T extends typeof A_Fragment>(fragment: T): InstanceType<T> {
194
179
 
195
180
  if (this._fragments.has(fragment)) {
196
181
  return this._fragments.get(fragment);
@@ -203,9 +188,91 @@ export class A_Scope {
203
188
  throw new Error(`Fragment ${fragment.name} not found in the scope ${this.name}`);
204
189
  }
205
190
 
191
+ private resolveScope<T extends { new(...args: any[]): A_Scope }>(scope: T): InstanceType<T> {
192
+
193
+ if (A_CommonHelper.isInheritedFrom(scope, this.constructor)) {
194
+ return this as InstanceType<T>;
195
+ } else if (this.parent) {
196
+ return this.parent.resolveScope(scope);
197
+ }
198
+
199
+ throw new Error(`Scope ${scope.name} not found in the scope ${this.name}`);
200
+ }
201
+
202
+
203
+ private resolveComponent<T extends A_Component>(component: {
204
+ new(...args: any[]): T
205
+ }): T {
206
+
207
+ if (this.components.includes(component) && this._components.has(component))
208
+ return this._components.get(component);
209
+
210
+ else if (this.components.includes(component) && !this._components.has(component)) {
211
+ const componentMeta = A_Context.meta(component)
212
+
213
+ const argsMeta = componentMeta.get(A_TYPES__ComponentMetaKey.INJECTIONS);
214
+
215
+ const resolvedArgs = (argsMeta?.get('constructor') || [])
216
+ .map(arg => this.resolve(arg));
217
+
218
+ const newComponent = new component(...resolvedArgs)
219
+
220
+ this.register(newComponent);
221
+
222
+ return this._components.get(component);
223
+ }
224
+
225
+ else if (!this.components.includes(component) && !!this.parent) {
226
+ return this.parent.resolveComponent(component);
227
+ }
228
+
229
+ else {
230
+ throw new Error(`Component ${component.name} not found in the scope`);
231
+ }
232
+ }
233
+
234
+
235
+
236
+ /**
237
+ * This method is used to register the component in the scope
238
+ *
239
+ * @param fragment
240
+ */
241
+ register(fragment: A_Entity): void
242
+ register(fragment: A_Component): void
243
+ register(fragment: A_Fragment): void
244
+ register(
245
+ param1: A_Fragment | A_Component | A_Entity
246
+ ): void {
247
+
248
+
249
+ switch (true) {
250
+ case param1 instanceof A_Fragment && !this._fragments.has(param1.constructor): {
251
+ this._fragments.set(param1.constructor, param1);
252
+ // The same situation. Have not idea how to fix it
253
+ A_Context.register(this, param1 as any);
254
+ break;
255
+ }
256
+
257
+ case param1 instanceof A_Entity && !this._entities.has(param1.aseid.toString()): {
258
+ this._entities.set(param1.aseid.toString(), param1);
259
+ // The same situation. Have not idea how to fix it
260
+ A_Context.register(this, param1 as any);
261
+ break;
262
+ }
263
+
264
+ case param1 instanceof A_Component: {
265
+ this._components.set(param1.constructor, param1);
266
+ // The same situation. Have not idea how to fix it
267
+ A_Context.register(this, param1 as any);
268
+ break;
269
+ }
270
+
271
+ default:
272
+ throw new Error('Invalid arguments provided');
273
+ }
274
+
206
275
 
207
276
 
208
- register(fragment: A_Fragment): void {
209
- this._fragments.set(fragment.constructor, fragment);
210
277
  }
211
278
  }