@adaas/a-concept 0.0.38 → 0.0.40

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 (50) hide show
  1. package/dist/src/global/A-Abstraction/A-Abstraction.class.d.ts +8 -2
  2. package/dist/src/global/A-Abstraction/A-Abstraction.class.js +5 -1
  3. package/dist/src/global/A-Abstraction/A-Abstraction.class.js.map +1 -1
  4. package/dist/src/global/A-Abstraction/A-Abstraction.types.d.ts +13 -4
  5. package/dist/src/global/A-Abstraction/A-Abstraction.types.js.map +1 -1
  6. package/dist/src/global/A-Component/A-Component.class.d.ts +11 -4
  7. package/dist/src/global/A-Component/A-Component.class.js +13 -4
  8. package/dist/src/global/A-Component/A-Component.class.js.map +1 -1
  9. package/dist/src/global/A-Concept/A_Concept.class.d.ts +11 -10
  10. package/dist/src/global/A-Concept/A_Concept.class.js +24 -20
  11. package/dist/src/global/A-Concept/A_Concept.class.js.map +1 -1
  12. package/dist/src/global/A-Concept/A_Concept.meta.d.ts +4 -4
  13. package/dist/src/global/A-Concept/A_Concept.meta.js +14 -6
  14. package/dist/src/global/A-Concept/A_Concept.meta.js.map +1 -1
  15. package/dist/src/global/A-Container/A-Container.class.d.ts +3 -4
  16. package/dist/src/global/A-Container/A-Container.class.js +8 -8
  17. package/dist/src/global/A-Container/A-Container.class.js.map +1 -1
  18. package/dist/src/global/A-Context/A-Context.class.d.ts +8 -10
  19. package/dist/src/global/A-Context/A-Context.class.js +32 -34
  20. package/dist/src/global/A-Context/A-Context.class.js.map +1 -1
  21. package/dist/src/global/A-Entity/A-Entity.class.d.ts +2 -2
  22. package/dist/src/global/A-Entity/A-Entity.class.js +4 -4
  23. package/dist/src/global/A-Entity/A-Entity.class.js.map +1 -1
  24. package/dist/src/global/A-Feature/A-Feature.class.d.ts +10 -8
  25. package/dist/src/global/A-Feature/A-Feature.class.js +11 -11
  26. package/dist/src/global/A-Feature/A-Feature.class.js.map +1 -1
  27. package/dist/src/global/A-Feature/A-Feature.types.d.ts +13 -2
  28. package/dist/src/global/A-Feature/A-Feature.types.js.map +1 -1
  29. package/dist/src/global/A-Scope/A-Scope.class.d.ts +14 -0
  30. package/dist/src/global/A-Scope/A-Scope.class.js +48 -5
  31. package/dist/src/global/A-Scope/A-Scope.class.js.map +1 -1
  32. package/dist/src/global/A-Stage/A-Stage.class.js +2 -2
  33. package/dist/src/global/A-Stage/A-Stage.class.js.map +1 -1
  34. package/examples/simple/concept.ts +1 -0
  35. package/examples/simple/containers/Main.container.ts +6 -5
  36. package/examples/simple-http-server/concept.ts +1 -0
  37. package/examples/simple-http-server/containers/http-server.container.ts +4 -2
  38. package/package.json +1 -1
  39. package/src/global/A-Abstraction/A-Abstraction.class.ts +11 -3
  40. package/src/global/A-Abstraction/A-Abstraction.types.ts +13 -6
  41. package/src/global/A-Component/A-Component.class.ts +12 -7
  42. package/src/global/A-Concept/A_Concept.class.ts +29 -21
  43. package/src/global/A-Concept/A_Concept.meta.ts +8 -15
  44. package/src/global/A-Container/A-Container.class.ts +13 -11
  45. package/src/global/A-Context/A-Context.class.ts +49 -87
  46. package/src/global/A-Entity/A-Entity.class.ts +5 -4
  47. package/src/global/A-Feature/A-Feature.class.ts +22 -13
  48. package/src/global/A-Feature/A-Feature.types.ts +14 -2
  49. package/src/global/A-Scope/A-Scope.class.ts +61 -5
  50. package/src/global/A-Stage/A-Stage.class.ts +4 -2
@@ -10,6 +10,7 @@ import {
10
10
  import { A_CONSTANTS__DEFAULT_ERRORS } from "@adaas/a-utils/dist/src/constants/errors.constants";
11
11
  import { A_Context } from "../A-Context/A-Context.class";
12
12
  import { A_TYPES__FeatureCallParams } from "../A-Feature/A-Feature.types";
13
+ import { A_Scope } from "../A-Scope/A-Scope.class";
13
14
 
14
15
 
15
16
 
@@ -135,14 +136,14 @@ export class A_Entity<
135
136
  * @param lifecycleMethod
136
137
  * @param args
137
138
  */
138
- async call(
139
+ async call(
139
140
  feature: string,
140
- params: Partial<A_TYPES__FeatureCallParams> = {}
141
+ scope?: A_Scope,
141
142
  ) {
142
- params.entities = params.entities || [this];
143
143
 
144
+ scope = scope ? scope.inherit(A_Context.scope(this)) : A_Context.scope(this);
144
145
 
145
- const newFeature = A_Context.feature(A_Context.scope(this), this, feature, params);
146
+ const newFeature = A_Context.feature(this, feature, scope);
146
147
 
147
148
  return await newFeature.process();
148
149
  }
@@ -6,6 +6,7 @@ import { A_Error, A_TYPES__Required } from "@adaas/a-utils";
6
6
  import { A_TYPES__A_Feature_Extend } from "@adaas/a-concept/decorators/A-Feature/A-Feature.decorator.types";
7
7
  import { A_Stage } from "../A-Stage/A-Stage.class";
8
8
  import { StepsManager } from "@adaas/a-concept/helpers/StepsManager.class";
9
+ import { A_Scope } from "../A-Scope/A-Scope.class";
9
10
 
10
11
  /**
11
12
  * A_Feature is representing a feature that can be executed across multiple components
@@ -46,11 +47,14 @@ export class A_Feature {
46
47
  error?: A_Error
47
48
 
48
49
  readonly name: string;
50
+ readonly Scope!: A_Scope;
51
+
49
52
 
50
53
  constructor(
51
- params: A_TYPES__Required<Partial<A_TYPES__FeatureConstructor>, ['steps']>
54
+ params: A_TYPES__FeatureConstructor
52
55
  ) {
53
56
  this.name = params.name || this.constructor.name;
57
+ this.Scope = params.scope
54
58
 
55
59
  this.SM = new StepsManager(params.steps);
56
60
 
@@ -58,7 +62,17 @@ export class A_Feature {
58
62
 
59
63
  this._current = this.stages[0];
60
64
 
61
- A_Context.allocate(this, params);
65
+
66
+ this.Scope.printInheritanceChain();
67
+ }
68
+
69
+
70
+ /**
71
+ * Returns the current A-Feature Stage
72
+ *
73
+ */
74
+ get stage(): A_Stage | undefined {
75
+ return this._current;
62
76
  }
63
77
 
64
78
 
@@ -93,14 +107,6 @@ export class A_Feature {
93
107
  }
94
108
 
95
109
 
96
- /**
97
- * Returns the current A-Feature Stage
98
- *
99
- */
100
- get stage(): A_Stage | undefined {
101
- return this._current;
102
- }
103
-
104
110
 
105
111
 
106
112
  /**
@@ -144,7 +150,7 @@ export class A_Feature {
144
150
  */
145
151
  async completed<T extends any>(): Promise<T> {
146
152
 
147
- this.result = A_Context.scope(this).toJSON();
153
+ this.result = this.Scope.toJSON();
148
154
 
149
155
  this.state = A_TYPES__FeatureState.COMPLETED;
150
156
 
@@ -173,7 +179,10 @@ export class A_Feature {
173
179
  * This method processes the feature by executing all the stages
174
180
  *
175
181
  */
176
- async process() {
182
+ async process(
183
+ scope?: A_Scope
184
+ ) {
185
+
177
186
  if (this.isDone()) {
178
187
  return this.result;
179
188
  }
@@ -190,7 +199,7 @@ export class A_Feature {
190
199
  } catch (error) {
191
200
  await this.failed(error);
192
201
  }
193
-
202
+
194
203
  }
195
204
 
196
205
 
@@ -2,6 +2,7 @@ import { A_TYPES__ScopeConfig, A_TYPES__ScopeConstructor } from "../A-Scope/A-Sc
2
2
  import { A_TYPES__A_StageStep } from "../A-Stage/A-Stage.types"
3
3
  import { A_Fragment } from "../A-Fragment/A-Fragment.class"
4
4
  import { A_Entity } from "@adaas/a-concept/global/A-Entity/A-Entity.class"
5
+ import { A_Scope } from "../A-Scope/A-Scope.class"
5
6
 
6
7
 
7
8
  export type A_TYPES__FeatureIteratorReturn<T extends any = any> = () => Promise<T>
@@ -16,8 +17,19 @@ export type A_TYPES__FeatureCallParams = {
16
17
 
17
18
 
18
19
  export type A_TYPES__FeatureConstructor = {
19
- steps: A_TYPES__A_StageStep[]
20
- } & A_TYPES__ScopeConstructor & A_TYPES__ScopeConfig
20
+ /**
21
+ * Name of the A-Feature
22
+ */
23
+ name:string,
24
+ /**
25
+ * Steps that compose the A-Feature
26
+ */
27
+ steps: A_TYPES__A_StageStep[],
28
+ /**
29
+ * Scope in which the A-Feature will be executed
30
+ */
31
+ scope: A_Scope
32
+ }
21
33
 
22
34
  export enum A_TYPES__FeatureState {
23
35
  INITIALIZED = "INITIALIZED",
@@ -51,8 +51,6 @@ export class A_Scope {
51
51
  components: [],
52
52
  fragments: [],
53
53
  entities: [],
54
- // import: [],
55
- // export: [],
56
54
  };
57
55
 
58
56
 
@@ -102,14 +100,63 @@ export class A_Scope {
102
100
  setValue?: A_Scope
103
101
  ): A_Scope | undefined {
104
102
  if (setValue) {
105
- this._parent = setValue;
106
- return;
103
+ return this.inherit(setValue);
107
104
  }
108
105
 
109
106
  return this._parent;
110
107
  }
111
108
 
112
109
 
110
+ inherit(parent: A_Scope): A_Scope {
111
+ // Prevent circular inheritance
112
+ const circularCheck = this.checkCircularInheritance(parent);
113
+
114
+ if (circularCheck) {
115
+ throw new Error(`Circular inheritance detected: ${[...circularCheck, parent.name].join(' -> ')}`);
116
+ }
117
+
118
+ this._parent = parent;
119
+ return this;
120
+ }
121
+
122
+
123
+
124
+ /**
125
+ * Helper method to check circular inheritance
126
+ * Should return a full sequence of inheritance for logging purposes
127
+ *
128
+ * @param scope
129
+ * @returns
130
+ */
131
+ checkCircularInheritance(scope: A_Scope): Array<string> | false {
132
+ const inheritanceChain: Array<string> = [];
133
+ let current: A_Scope | undefined = this._parent;
134
+
135
+ while (current) {
136
+ inheritanceChain.push(current.name);
137
+ if (current === scope) {
138
+ return inheritanceChain;
139
+ }
140
+ current = current._parent;
141
+ }
142
+
143
+ return false;
144
+ }
145
+
146
+
147
+ printInheritanceChain(): void {
148
+ const chain: Array<string> = [];
149
+ let current: A_Scope | undefined = this;
150
+
151
+ while (current) {
152
+ chain.push(current.name);
153
+ current = current._parent;
154
+ }
155
+
156
+ console.log(chain.join(' -> '));
157
+ }
158
+
159
+
113
160
  /**
114
161
  * This method is used to check if the component is available in the scope
115
162
  *
@@ -169,6 +216,10 @@ export class A_Scope {
169
216
  /**
170
217
  * Merges two scopes into a new one
171
218
  *
219
+ * [!] Notes:
220
+ * - this method does NOT modify the existing scopes
221
+ * - parent of the new scope will be the parent of the current scope or the parent of anotherScope (if exists)
222
+ *
172
223
  * @param anotherScope
173
224
  * @returns
174
225
  */
@@ -462,7 +513,12 @@ export class A_Scope {
462
513
  }
463
514
 
464
515
  default:
465
- throw new Error('Invalid arguments provided');
516
+ if (param1 instanceof A_Entity)
517
+ throw new Error(`Entity with ASEID ${param1.aseid.toString()} is already registered in the scope ${this.name}`);
518
+ else if (param1 instanceof A_Fragment)
519
+ throw new Error(`Fragment ${param1.constructor.name} is already registered in the scope ${this.name}`);
520
+ else
521
+ throw new Error(`Cannot register ${param1} in the scope ${this.name}`);
466
522
  }
467
523
 
468
524
 
@@ -84,7 +84,6 @@ export class A_Stage {
84
84
  return this.feature;
85
85
 
86
86
  return scope
87
- .merge(A_Context.scope(this.feature))
88
87
  .resolve(arg.target)
89
88
  })
90
89
  )
@@ -119,7 +118,7 @@ export class A_Stage {
119
118
  // TODO: probably would be better to do it another way. let's think about it
120
119
  const instance = component instanceof A_Container
121
120
  ? component
122
- : A_Context.scope(this.feature).resolve(component);
121
+ : this.feature.Scope.resolve(component);
123
122
 
124
123
  if (!instance)
125
124
  throw new Error(`Unable to resolve component ${component.name}`);
@@ -161,6 +160,9 @@ export class A_Stage {
161
160
  scope: A_Scope = new A_Scope({}, {}),
162
161
  params?: Partial<A_TYPES__A_StageStepProcessingExtraParams>
163
162
  ): Promise<void> {
163
+
164
+ scope = scope.inherit(this.feature.Scope);
165
+
164
166
  if (!this.processed)
165
167
  this.processed = new Promise<void>(
166
168
  async (resolve, reject) => {