@adaas/a-concept 0.0.39 → 0.0.41

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 (72) hide show
  1. package/dist/src/decorators/A-Feature/A-Feature-Define.decorator.js +1 -0
  2. package/dist/src/decorators/A-Feature/A-Feature-Define.decorator.js.map +1 -1
  3. package/dist/src/decorators/A-Feature/A-Feature-Extend.decorator.js +10 -0
  4. package/dist/src/decorators/A-Feature/A-Feature-Extend.decorator.js.map +1 -1
  5. package/dist/src/decorators/A-Feature/A-Feature.decorator.types.d.ts +1 -0
  6. package/dist/src/global/A-Abstraction/A-Abstraction.class.d.ts +8 -2
  7. package/dist/src/global/A-Abstraction/A-Abstraction.class.js +5 -1
  8. package/dist/src/global/A-Abstraction/A-Abstraction.class.js.map +1 -1
  9. package/dist/src/global/A-Abstraction/A-Abstraction.types.d.ts +13 -4
  10. package/dist/src/global/A-Abstraction/A-Abstraction.types.js.map +1 -1
  11. package/dist/src/global/A-Component/A-Component.class.d.ts +11 -4
  12. package/dist/src/global/A-Component/A-Component.class.js +13 -4
  13. package/dist/src/global/A-Component/A-Component.class.js.map +1 -1
  14. package/dist/src/global/A-Concept/A_Concept.class.d.ts +11 -10
  15. package/dist/src/global/A-Concept/A_Concept.class.js +24 -20
  16. package/dist/src/global/A-Concept/A_Concept.class.js.map +1 -1
  17. package/dist/src/global/A-Concept/A_Concept.meta.d.ts +4 -4
  18. package/dist/src/global/A-Concept/A_Concept.meta.js +14 -6
  19. package/dist/src/global/A-Concept/A_Concept.meta.js.map +1 -1
  20. package/dist/src/global/A-Container/A-Container.class.d.ts +3 -4
  21. package/dist/src/global/A-Container/A-Container.class.js +8 -8
  22. package/dist/src/global/A-Container/A-Container.class.js.map +1 -1
  23. package/dist/src/global/A-Context/A-Context.class.d.ts +6 -11
  24. package/dist/src/global/A-Context/A-Context.class.js +32 -32
  25. package/dist/src/global/A-Context/A-Context.class.js.map +1 -1
  26. package/dist/src/global/A-Entity/A-Entity.class.d.ts +2 -2
  27. package/dist/src/global/A-Entity/A-Entity.class.js +4 -4
  28. package/dist/src/global/A-Entity/A-Entity.class.js.map +1 -1
  29. package/dist/src/global/A-Feature/A-Feature.class.d.ts +10 -8
  30. package/dist/src/global/A-Feature/A-Feature.class.js +20 -28
  31. package/dist/src/global/A-Feature/A-Feature.class.js.map +1 -1
  32. package/dist/src/global/A-Feature/A-Feature.types.d.ts +13 -2
  33. package/dist/src/global/A-Feature/A-Feature.types.js.map +1 -1
  34. package/dist/src/global/A-Meta/A-Meta.class.d.ts +6 -0
  35. package/dist/src/global/A-Meta/A-Meta.class.js +8 -0
  36. package/dist/src/global/A-Meta/A-Meta.class.js.map +1 -1
  37. package/dist/src/global/A-Scope/A-Scope.class.d.ts +14 -0
  38. package/dist/src/global/A-Scope/A-Scope.class.js +48 -5
  39. package/dist/src/global/A-Scope/A-Scope.class.js.map +1 -1
  40. package/dist/src/global/A-Stage/A-Stage.class.d.ts +3 -2
  41. package/dist/src/global/A-Stage/A-Stage.class.js +18 -5
  42. package/dist/src/global/A-Stage/A-Stage.class.js.map +1 -1
  43. package/dist/src/global/A-Stage/A-Stage.error.d.ts +3 -0
  44. package/dist/src/global/A-Stage/A-Stage.error.js +8 -0
  45. package/dist/src/global/A-Stage/A-Stage.error.js.map +1 -0
  46. package/dist/src/helpers/StepsManager.class.d.ts +17 -0
  47. package/dist/src/helpers/StepsManager.class.js +41 -3
  48. package/dist/src/helpers/StepsManager.class.js.map +1 -1
  49. package/examples/simple/components/A.component.ts +12 -3
  50. package/examples/simple/concept.ts +10 -4
  51. package/examples/simple/containers/Main.container.ts +6 -5
  52. package/examples/simple-http-server/concept.ts +1 -0
  53. package/examples/simple-http-server/containers/http-server.container.ts +4 -2
  54. package/package.json +1 -1
  55. package/src/decorators/A-Feature/A-Feature-Define.decorator.ts +1 -0
  56. package/src/decorators/A-Feature/A-Feature-Extend.decorator.ts +17 -0
  57. package/src/decorators/A-Feature/A-Feature.decorator.types.ts +1 -0
  58. package/src/global/A-Abstraction/A-Abstraction.class.ts +11 -3
  59. package/src/global/A-Abstraction/A-Abstraction.types.ts +13 -6
  60. package/src/global/A-Component/A-Component.class.ts +12 -7
  61. package/src/global/A-Concept/A_Concept.class.ts +29 -21
  62. package/src/global/A-Concept/A_Concept.meta.ts +8 -15
  63. package/src/global/A-Container/A-Container.class.ts +13 -11
  64. package/src/global/A-Context/A-Context.class.ts +37 -99
  65. package/src/global/A-Entity/A-Entity.class.ts +5 -4
  66. package/src/global/A-Feature/A-Feature.class.ts +40 -36
  67. package/src/global/A-Feature/A-Feature.types.ts +14 -2
  68. package/src/global/A-Meta/A-Meta.class.ts +10 -0
  69. package/src/global/A-Scope/A-Scope.class.ts +61 -5
  70. package/src/global/A-Stage/A-Stage.class.ts +34 -11
  71. package/src/global/A-Stage/A-Stage.error.ts +9 -0
  72. package/src/helpers/StepsManager.class.ts +63 -3
@@ -93,6 +93,16 @@ export class A_Meta<
93
93
  }
94
94
 
95
95
 
96
+ /**
97
+ * Method to get the size of the map
98
+ *
99
+ * @returns
100
+ */
101
+ size(): number {
102
+ return this.meta.size;
103
+ }
104
+
105
+
96
106
  /**
97
107
  * This method is needed to convert the key to a regular expression and cover cases like:
98
108
  *
@@ -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
 
@@ -3,8 +3,8 @@ import { A_Context } from "../A-Context/A-Context.class";
3
3
  import { A_Feature } from "../A-Feature/A-Feature.class";
4
4
  import { A_TYPES__A_Stage_JSON, A_TYPES__A_Stage_Status, A_TYPES__A_StageStep, A_TYPES__A_StageStepProcessingExtraParams } from "./A-Stage.types";
5
5
  import { A_Container } from "../A-Container/A-Container.class";
6
- import { A_TYPES__ScopeConstructor } from "../A-Scope/A-Scope.types";
7
6
  import { A_Scope } from "../A-Scope/A-Scope.class";
7
+ import { A_StageError } from "./A-Stage.error";
8
8
 
9
9
 
10
10
  /**
@@ -16,12 +16,24 @@ import { A_Scope } from "../A-Scope/A-Scope.class";
16
16
  */
17
17
  export class A_Stage {
18
18
 
19
+ readonly name: string = 'A_Stage';
19
20
 
21
+ private readonly feature!: A_Feature;
22
+ private readonly _steps!: A_TYPES__A_StageStep[];
20
23
 
21
24
  constructor(
22
- private feature: A_Feature,
23
- private _steps: A_TYPES__A_StageStep[] = []
25
+ feature: A_Feature,
26
+ _steps: A_TYPES__A_StageStep[] = []
24
27
  ) {
28
+ this.feature = feature;
29
+ this._steps = _steps;
30
+ this.name = `${this.feature.name}::a-stage:[sync:${this
31
+ .syncSteps
32
+ .map(s => s.component.name + '.' + s.handler)
33
+ .join(' -> ')}][async:${this
34
+ .asyncSteps
35
+ .map(s => s.component.name + '.' + s.handler)
36
+ .join(' -> ')}]`;
25
37
 
26
38
  }
27
39
 
@@ -54,10 +66,10 @@ export class A_Stage {
54
66
  get asyncSteps(): A_TYPES__A_StageStep[] {
55
67
  return this._steps.filter(step => step.behavior === 'async');
56
68
  }
57
-
69
+
58
70
  get syncSteps(): A_TYPES__A_StageStep[] {
59
71
  return this._steps.filter(step => step.behavior === 'sync');
60
- }
72
+ }
61
73
 
62
74
 
63
75
  /**
@@ -84,7 +96,6 @@ export class A_Stage {
84
96
  return this.feature;
85
97
 
86
98
  return scope
87
- .merge(A_Context.scope(this.feature))
88
99
  .resolve(arg.target)
89
100
  })
90
101
  )
@@ -119,7 +130,7 @@ export class A_Stage {
119
130
  // TODO: probably would be better to do it another way. let's think about it
120
131
  const instance = component instanceof A_Container
121
132
  ? component
122
- : A_Context.scope(this.feature).resolve(component);
133
+ : this.feature.Scope.resolve(component);
123
134
 
124
135
  if (!instance)
125
136
  throw new Error(`Unable to resolve component ${component.name}`);
@@ -140,12 +151,12 @@ export class A_Stage {
140
151
  */
141
152
  protected async callStepHandler(
142
153
  step: A_TYPES__A_StageStep,
143
- scope: A_Scope
154
+ scope: A_Scope
144
155
  ) {
145
156
  const instance = await this.getStepInstance(step);
146
157
  const callArgs = await this.getStepArgs(step, scope);
147
158
 
148
- return instance[step.handler](...callArgs);
159
+ return await instance[step.handler](...callArgs);
149
160
  }
150
161
 
151
162
 
@@ -161,6 +172,12 @@ export class A_Stage {
161
172
  scope: A_Scope = new A_Scope({}, {}),
162
173
  params?: Partial<A_TYPES__A_StageStepProcessingExtraParams>
163
174
  ): Promise<void> {
175
+
176
+ scope = scope.inherit(this.feature.Scope);
177
+
178
+
179
+ console.log(' -> Init stage processing:', this.name);
180
+
164
181
  if (!this.processed)
165
182
  this.processed = new Promise<void>(
166
183
  async (resolve, reject) => {
@@ -175,7 +192,7 @@ export class A_Stage {
175
192
  const asyncSteps = this.asyncSteps.filter(params?.filter || (() => true));
176
193
 
177
194
  // Run sync _steps
178
- await Promise
195
+ await Promise
179
196
  .all([
180
197
 
181
198
  // Run async _steps that are independent of each other
@@ -186,11 +203,16 @@ export class A_Stage {
186
203
  async (r, j) => {
187
204
  try {
188
205
  for (const step of syncSteps) {
206
+ console.log(' - -> Processing stage step:', step.handler, ' with Regexp: ', step.name);
207
+
189
208
  await this.callStepHandler(step, scope);
209
+
210
+ console.log(' - -> Finished processing stage step:', step.handler);
190
211
  }
191
212
 
192
213
  return r();
193
214
  } catch (error) {
215
+
194
216
  return j(error);
195
217
  }
196
218
  }
@@ -199,6 +221,7 @@ export class A_Stage {
199
221
 
200
222
  this.completed();
201
223
 
224
+ console.log(' -> Finished stage processing:', this.name);
202
225
  return resolve();
203
226
 
204
227
  } catch (error) {
@@ -241,7 +264,7 @@ export class A_Stage {
241
264
  ) {
242
265
  this.status = A_TYPES__A_Stage_Status.FAILED;
243
266
 
244
- this.feature.failed(error);
267
+ this.feature.failed(new A_StageError(error));
245
268
  }
246
269
 
247
270
 
@@ -0,0 +1,9 @@
1
+ import { A_Error } from "@adaas/a-utils";
2
+
3
+
4
+ export class A_StageError extends A_Error {
5
+
6
+
7
+
8
+
9
+ }
@@ -82,7 +82,7 @@ export class StepsManager {
82
82
  if (!this.visited.has(this.ID(entity))) this.visit(this.ID(entity));
83
83
  });
84
84
 
85
- const stages: A_Stage[] = [];
85
+ const stages: A_TmpStage[] = [];
86
86
 
87
87
  // Map sorted names back to entity objects
88
88
  this.sortedEntities
@@ -96,13 +96,73 @@ export class StepsManager {
96
96
 
97
97
 
98
98
  if (!stage) {
99
- stage = new A_Stage(feature);
99
+ stage = new A_TmpStage();
100
100
  stages.push(stage);
101
101
  }
102
102
 
103
103
  stage.add(step);
104
104
  });
105
105
 
106
- return stages;
106
+ return stages.map(stage => new A_Stage(feature, stage.steps) );
107
+ }
108
+ }
109
+
110
+
111
+
112
+
113
+
114
+ export class A_TmpStage {
115
+
116
+ readonly name: string = 'A_TmpStage';
117
+
118
+ private readonly _steps!: A_TYPES__A_StageStep[];
119
+
120
+ constructor(
121
+ _steps: A_TYPES__A_StageStep[] = []
122
+ ) {
123
+ this._steps = _steps;
124
+ }
125
+
126
+
127
+ get before(): string[] {
128
+ return this._steps.reduce((acc, step) => ([
129
+ ...acc,
130
+ ...step.before
131
+ ]), [] as string[]);
132
+ }
133
+
134
+ get after(): string[] {
135
+ return this._steps.reduce((acc, step) => ([
136
+ ...acc,
137
+ ...step.after
138
+ ]), [] as string[]);
139
+ }
140
+
141
+ get steps(): A_TYPES__A_StageStep[] {
142
+ return this._steps;
143
+ }
144
+
145
+
146
+ get asyncSteps(): A_TYPES__A_StageStep[] {
147
+ return this._steps.filter(step => step.behavior === 'async');
148
+ }
149
+
150
+ get syncSteps(): A_TYPES__A_StageStep[] {
151
+ return this._steps.filter(step => step.behavior === 'sync');
152
+ }
153
+
154
+
155
+ /**
156
+ * Adds a step to the stage
157
+ *
158
+ * @param step
159
+ * @returns
160
+ */
161
+ add(
162
+ step: A_TYPES__A_StageStep
163
+ ): this {
164
+ this._steps.push(step);
165
+
166
+ return this;
107
167
  }
108
168
  }