@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.
- package/dist/src/decorators/A-Feature/A-Feature-Define.decorator.js +1 -0
- package/dist/src/decorators/A-Feature/A-Feature-Define.decorator.js.map +1 -1
- package/dist/src/decorators/A-Feature/A-Feature-Extend.decorator.js +10 -0
- package/dist/src/decorators/A-Feature/A-Feature-Extend.decorator.js.map +1 -1
- package/dist/src/decorators/A-Feature/A-Feature.decorator.types.d.ts +1 -0
- package/dist/src/global/A-Abstraction/A-Abstraction.class.d.ts +8 -2
- package/dist/src/global/A-Abstraction/A-Abstraction.class.js +5 -1
- package/dist/src/global/A-Abstraction/A-Abstraction.class.js.map +1 -1
- package/dist/src/global/A-Abstraction/A-Abstraction.types.d.ts +13 -4
- package/dist/src/global/A-Abstraction/A-Abstraction.types.js.map +1 -1
- package/dist/src/global/A-Component/A-Component.class.d.ts +11 -4
- package/dist/src/global/A-Component/A-Component.class.js +13 -4
- package/dist/src/global/A-Component/A-Component.class.js.map +1 -1
- package/dist/src/global/A-Concept/A_Concept.class.d.ts +11 -10
- package/dist/src/global/A-Concept/A_Concept.class.js +24 -20
- package/dist/src/global/A-Concept/A_Concept.class.js.map +1 -1
- package/dist/src/global/A-Concept/A_Concept.meta.d.ts +4 -4
- package/dist/src/global/A-Concept/A_Concept.meta.js +14 -6
- package/dist/src/global/A-Concept/A_Concept.meta.js.map +1 -1
- package/dist/src/global/A-Container/A-Container.class.d.ts +3 -4
- package/dist/src/global/A-Container/A-Container.class.js +8 -8
- package/dist/src/global/A-Container/A-Container.class.js.map +1 -1
- package/dist/src/global/A-Context/A-Context.class.d.ts +6 -11
- package/dist/src/global/A-Context/A-Context.class.js +32 -32
- package/dist/src/global/A-Context/A-Context.class.js.map +1 -1
- package/dist/src/global/A-Entity/A-Entity.class.d.ts +2 -2
- package/dist/src/global/A-Entity/A-Entity.class.js +4 -4
- package/dist/src/global/A-Entity/A-Entity.class.js.map +1 -1
- package/dist/src/global/A-Feature/A-Feature.class.d.ts +10 -8
- package/dist/src/global/A-Feature/A-Feature.class.js +20 -28
- package/dist/src/global/A-Feature/A-Feature.class.js.map +1 -1
- package/dist/src/global/A-Feature/A-Feature.types.d.ts +13 -2
- package/dist/src/global/A-Feature/A-Feature.types.js.map +1 -1
- package/dist/src/global/A-Meta/A-Meta.class.d.ts +6 -0
- package/dist/src/global/A-Meta/A-Meta.class.js +8 -0
- package/dist/src/global/A-Meta/A-Meta.class.js.map +1 -1
- package/dist/src/global/A-Scope/A-Scope.class.d.ts +14 -0
- package/dist/src/global/A-Scope/A-Scope.class.js +48 -5
- package/dist/src/global/A-Scope/A-Scope.class.js.map +1 -1
- package/dist/src/global/A-Stage/A-Stage.class.d.ts +3 -2
- package/dist/src/global/A-Stage/A-Stage.class.js +18 -5
- package/dist/src/global/A-Stage/A-Stage.class.js.map +1 -1
- package/dist/src/global/A-Stage/A-Stage.error.d.ts +3 -0
- package/dist/src/global/A-Stage/A-Stage.error.js +8 -0
- package/dist/src/global/A-Stage/A-Stage.error.js.map +1 -0
- package/dist/src/helpers/StepsManager.class.d.ts +17 -0
- package/dist/src/helpers/StepsManager.class.js +41 -3
- package/dist/src/helpers/StepsManager.class.js.map +1 -1
- package/examples/simple/components/A.component.ts +12 -3
- package/examples/simple/concept.ts +10 -4
- package/examples/simple/containers/Main.container.ts +6 -5
- package/examples/simple-http-server/concept.ts +1 -0
- package/examples/simple-http-server/containers/http-server.container.ts +4 -2
- package/package.json +1 -1
- package/src/decorators/A-Feature/A-Feature-Define.decorator.ts +1 -0
- package/src/decorators/A-Feature/A-Feature-Extend.decorator.ts +17 -0
- package/src/decorators/A-Feature/A-Feature.decorator.types.ts +1 -0
- package/src/global/A-Abstraction/A-Abstraction.class.ts +11 -3
- package/src/global/A-Abstraction/A-Abstraction.types.ts +13 -6
- package/src/global/A-Component/A-Component.class.ts +12 -7
- package/src/global/A-Concept/A_Concept.class.ts +29 -21
- package/src/global/A-Concept/A_Concept.meta.ts +8 -15
- package/src/global/A-Container/A-Container.class.ts +13 -11
- package/src/global/A-Context/A-Context.class.ts +37 -99
- package/src/global/A-Entity/A-Entity.class.ts +5 -4
- package/src/global/A-Feature/A-Feature.class.ts +40 -36
- package/src/global/A-Feature/A-Feature.types.ts +14 -2
- package/src/global/A-Meta/A-Meta.class.ts +10 -0
- package/src/global/A-Scope/A-Scope.class.ts +61 -5
- package/src/global/A-Stage/A-Stage.class.ts +34 -11
- package/src/global/A-Stage/A-Stage.error.ts +9 -0
- 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.
|
|
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
|
-
|
|
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
|
-
|
|
23
|
-
|
|
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
|
-
:
|
|
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
|
|
|
@@ -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:
|
|
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
|
|
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
|
}
|