@adaas/a-concept 0.1.17 → 0.1.19

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 (56) hide show
  1. package/dist/index.d.ts +2 -0
  2. package/dist/index.js +5 -2
  3. package/dist/index.js.map +1 -1
  4. package/dist/src/global/A-Abstraction/A-Abstraction-Extend.decorator.js +22 -7
  5. package/dist/src/global/A-Abstraction/A-Abstraction-Extend.decorator.js.map +1 -1
  6. package/dist/src/global/A-Component/A-Component.meta.js +2 -1
  7. package/dist/src/global/A-Component/A-Component.meta.js.map +1 -1
  8. package/dist/src/global/A-Component/A-Component.types.d.ts +2 -11
  9. package/dist/src/global/A-Concept/A-Concept.types.d.ts +4 -21
  10. package/dist/src/global/A-Container/A-Container.meta.js +4 -2
  11. package/dist/src/global/A-Container/A-Container.meta.js.map +1 -1
  12. package/dist/src/global/A-Container/A-Container.types.d.ts +2 -11
  13. package/dist/src/global/A-Context/A-Context.class.d.ts +8 -0
  14. package/dist/src/global/A-Context/A-Context.class.js +30 -2
  15. package/dist/src/global/A-Context/A-Context.class.js.map +1 -1
  16. package/dist/src/global/A-Feature/A-Feature-Define.decorator.js +1 -1
  17. package/dist/src/global/A-Feature/A-Feature-Define.decorator.js.map +1 -1
  18. package/dist/src/global/A-Feature/A-Feature-Extend.decorator.js +27 -8
  19. package/dist/src/global/A-Feature/A-Feature-Extend.decorator.js.map +1 -1
  20. package/dist/src/global/A-Feature/A-Feature.class.d.ts +2 -1
  21. package/dist/src/global/A-Feature/A-Feature.class.js +7 -3
  22. package/dist/src/global/A-Feature/A-Feature.class.js.map +1 -1
  23. package/dist/src/global/A-Feature/A-Feature.types.d.ts +69 -27
  24. package/dist/src/global/A-Stage/A-Stage.class.d.ts +37 -28
  25. package/dist/src/global/A-Stage/A-Stage.class.js +62 -98
  26. package/dist/src/global/A-Stage/A-Stage.class.js.map +1 -1
  27. package/dist/src/global/A-Stage/A-Stage.types.d.ts +30 -3
  28. package/dist/src/global/A-Stage/A-Stage.types.js.map +1 -1
  29. package/dist/src/global/A-StepManager/A-StepManager.class.d.ts +20 -0
  30. package/dist/src/{helpers/A_StepsManager.class.js → global/A-StepManager/A-StepManager.class.js} +38 -64
  31. package/dist/src/global/A-StepManager/A-StepManager.class.js.map +1 -0
  32. package/dist/src/global/A-StepManager/A-StepManager.error.d.ts +4 -0
  33. package/dist/src/global/A-StepManager/A-StepManager.error.js +9 -0
  34. package/dist/src/global/A-StepManager/A-StepManager.error.js.map +1 -0
  35. package/index.ts +2 -1
  36. package/package.json +3 -3
  37. package/src/global/A-Abstraction/A-Abstraction-Extend.decorator.ts +27 -7
  38. package/src/global/A-Component/A-Component.meta.ts +2 -1
  39. package/src/global/A-Component/A-Component.types.ts +2 -11
  40. package/src/global/A-Concept/A-Concept.types.ts +4 -21
  41. package/src/global/A-Container/A-Container.meta.ts +4 -2
  42. package/src/global/A-Container/A-Container.types.ts +2 -11
  43. package/src/global/A-Context/A-Context.class.ts +40 -3
  44. package/src/global/A-Feature/A-Feature-Define.decorator.ts +1 -0
  45. package/src/global/A-Feature/A-Feature-Extend.decorator.ts +34 -8
  46. package/src/global/A-Feature/A-Feature.class.ts +8 -1
  47. package/src/global/A-Feature/A-Feature.types.ts +80 -33
  48. package/src/global/A-Stage/A-Stage.class.ts +71 -143
  49. package/src/global/A-Stage/A-Stage.types.ts +34 -3
  50. package/src/{helpers/A_StepsManager.class.ts → global/A-StepManager/A-StepManager.class.ts} +53 -87
  51. package/src/global/A-StepManager/A-StepManager.error.ts +10 -0
  52. package/tests/A-Abstraction.test.ts +274 -190
  53. package/tests/A-Feature.test.ts +84 -1
  54. package/tests/A-StepManager.test.ts +346 -0
  55. package/dist/src/helpers/A_StepsManager.class.d.ts +0 -35
  56. package/dist/src/helpers/A_StepsManager.class.js.map +0 -1
@@ -1,8 +1,8 @@
1
- import { A_Error } from "../global/A-Error/A_Error.class";
2
- import { A_Feature } from "../global/A-Feature/A-Feature.class";
3
- import { A_TYPES__FeatureDefineDecoratorTemplateItem } from "../global/A-Feature/A-Feature.types";
4
- import { A_Stage } from "../global/A-Stage/A-Stage.class";
5
- import { A_TYPES__A_StageStep } from "../global/A-Stage/A-Stage.types";
1
+ import { A_Feature } from "../A-Feature/A-Feature.class";
2
+ import { A_TYPES__FeatureDefineDecoratorTemplateItem } from "../A-Feature/A-Feature.types";
3
+ import { A_Stage } from "../A-Stage/A-Stage.class";
4
+ import { A_TYPES__A_StageStep } from "../A-Stage/A-Stage.types";
5
+ import { A_StepManagerError } from "./A-StepManager.error";
6
6
 
7
7
  export class A_StepsManager {
8
8
 
@@ -13,6 +13,8 @@ export class A_StepsManager {
13
13
  public sortedEntities: string[];
14
14
 
15
15
 
16
+ private _isBuilt: boolean = false;
17
+
16
18
  constructor(entities: Array<A_TYPES__FeatureDefineDecoratorTemplateItem>) {
17
19
  this.entities = this.prepareSteps(entities);
18
20
 
@@ -29,10 +31,11 @@ export class A_StepsManager {
29
31
  return entities.map(step => {
30
32
  return {
31
33
  ...step,
32
-
34
+
33
35
  behavior: step.behavior || 'sync',
34
36
  before: step.before || [],
35
37
  after: step.after || [],
38
+ throwOnError: false
36
39
  };
37
40
  });
38
41
  }
@@ -42,6 +45,8 @@ export class A_StepsManager {
42
45
  }
43
46
 
44
47
  private buildGraph() {
48
+ if (this._isBuilt) return;
49
+ this._isBuilt = true;
45
50
  // Initialize graph nodes
46
51
  this.entities.forEach(entity => this.graph.set(this.ID(entity), new Set()));
47
52
 
@@ -54,7 +59,7 @@ export class A_StepsManager {
54
59
  // If entity should execute before targets, then targets depend on entity
55
60
  // So we add edges: target -> entity (target depends on entity)
56
61
  before.forEach(dep => {
57
- const targets = this.matchEntities(dep);
62
+ const targets = this.matchEntities(entityId, dep);
58
63
  targets.forEach(target => {
59
64
  if (!this.graph.has(target)) this.graph.set(target, new Set());
60
65
  this.graph.get(target)!.add(entityId); // target depends on entity
@@ -65,7 +70,7 @@ export class A_StepsManager {
65
70
  // If entity should execute after sources, then entity depends on sources
66
71
  // So we add edges: entity -> source (entity depends on source)
67
72
  after.forEach(dep => {
68
- const sources = this.matchEntities(dep);
73
+ const sources = this.matchEntities(entityId, dep);
69
74
 
70
75
  sources.forEach(source => {
71
76
  if (!this.graph.has(entityId)) this.graph.set(entityId, new Set());
@@ -76,28 +81,51 @@ export class A_StepsManager {
76
81
  }
77
82
 
78
83
  // Match entities by name or regex
79
- private matchEntities(pattern: string): string[] {
80
- const regex = new RegExp(`^${pattern}$`);
84
+ private matchEntities(entityId: string, pattern: string): string[] {
85
+ const regex = new RegExp(pattern);
86
+
81
87
  return this.entities
82
- .filter(entity => regex.test(this.ID(entity)))
88
+ .filter(entity => regex.test(this.ID(entity)) && this.ID(entity) !== entityId)
83
89
  .map(entity => this.ID(entity));
84
90
  }
85
91
 
86
92
  // Topological sort with cycle detection
87
93
  private visit(node: string): void {
88
- if (this.tempMark.has(node)) throw new A_Error("Circular dependency detected");
94
+ if (this.tempMark.has(node)) {
95
+ return;
96
+ // TODO: maybe we have to keep this error but only for partial cases
97
+ throw new A_StepManagerError(
98
+ A_StepManagerError.CircularDependencyError,
99
+ `Circular dependency detected involving step: ${node}. Make sure that your 'before' and 'after' dependencies do not create cycles.`
100
+ );
101
+ }
89
102
 
90
103
  if (!this.visited.has(node)) {
91
104
  this.tempMark.add(node);
105
+
106
+
92
107
  (this.graph.get(node) || []).forEach(neighbor => this.visit(neighbor));
93
108
  this.tempMark.delete(node);
94
109
  this.visited.add(node);
95
110
  this.sortedEntities.push(node);
111
+
112
+ // // Visit neighbors in stable order (preserving original order)
113
+ // const neighbors = Array.from(this.graph.get(node) || []);
114
+ // // neighbors.sort((a, b) => {
115
+ // // const orderA = this.originalOrder.get(a) || 0;
116
+ // // const orderB = this.originalOrder.get(b) || 0;
117
+ // // return orderA - orderB;
118
+ // // });
119
+
120
+ // neighbors.forEach(neighbor => this.visit(neighbor));
121
+ // this.tempMark.delete(node);
122
+ // this.visited.add(node);
123
+ // this.sortedEntities.push(node);
96
124
  }
97
125
  }
98
126
 
99
- // Sort the entities based on dependencies
100
- toStages(feature: A_Feature): Array<A_Stage> {
127
+
128
+ toSortedArray(): Array<string> {
101
129
  this.buildGraph();
102
130
 
103
131
  // Start topological sort
@@ -105,87 +133,25 @@ export class A_StepsManager {
105
133
  if (!this.visited.has(this.ID(entity))) this.visit(this.ID(entity));
106
134
  });
107
135
 
108
- const stages: A_TmpStage[] = [];
109
-
110
- // Map sorted names back to entity objects
111
- this.sortedEntities
112
- .map(id => {
113
- const step = this.entities.find(entity => this.ID(entity) === id)!;
114
-
115
- let stage = stages.find(stage => {
116
- return stage.after.every(after => step.after.includes(after))
117
- && step.before.every(before => stage.after.includes(before));
118
- });
119
-
120
-
121
- if (!stage) {
122
- stage = new A_TmpStage();
123
- stages.push(stage);
124
- }
125
-
126
- stage.add(step);
127
- });
128
-
129
- return stages.map(stage => new A_Stage(feature, stage.steps));
130
- }
131
- }
132
-
133
-
134
-
135
-
136
-
137
- export class A_TmpStage {
138
-
139
- readonly name: string = 'A_TmpStage';
140
-
141
- private readonly _steps!: A_TYPES__A_StageStep[];
142
-
143
- constructor(
144
- _steps: A_TYPES__A_StageStep[] = []
145
- ) {
146
- this._steps = _steps;
136
+ return this.sortedEntities;
147
137
  }
148
138
 
139
+ // Sort the entities based on dependencies
140
+ toStages(feature: A_Feature): Array<A_Stage> {
149
141
 
150
- get before(): string[] {
151
- return this._steps.reduce((acc, step) => ([
152
- ...acc,
153
- ...step.before
154
- ]), [] as string[]);
155
- }
156
142
 
157
- get after(): string[] {
158
- return this._steps.reduce((acc, step) => ([
159
- ...acc,
160
- ...step.after
161
- ]), [] as string[]);
162
- }
143
+ const sortedNames = this.toSortedArray();
163
144
 
164
- get steps(): A_TYPES__A_StageStep[] {
165
- return this._steps;
166
- }
167
145
 
146
+ // Map sorted names back to entity objects
147
+ return sortedNames
148
+ .map(id => {
149
+ const step = this.entities.find(entity => this.ID(entity) === id)!;
168
150
 
169
- get asyncSteps(): A_TYPES__A_StageStep[] {
170
- return this._steps.filter(step => step.behavior === 'async');
171
- }
172
151
 
173
- get syncSteps(): A_TYPES__A_StageStep[] {
174
- return this._steps.filter(step => step.behavior === 'sync');
152
+ return new A_Stage(feature, step);
153
+ });
175
154
  }
155
+ }
176
156
 
177
157
 
178
- /**
179
- * Adds a step to the stage
180
- *
181
- * @param step
182
- * @returns
183
- */
184
- add(
185
- step: A_TYPES__A_StageStep
186
- ): this {
187
- this._steps.push(step);
188
-
189
- return this;
190
- }
191
- }
@@ -0,0 +1,10 @@
1
+ import { A_Error } from "../A-Error/A_Error.class";
2
+
3
+
4
+
5
+ export class A_StepManagerError extends A_Error {
6
+
7
+
8
+ static readonly CircularDependencyError = 'A-StepManager Circular Dependency Error';
9
+
10
+ }