@adaas/a-concept 0.0.39 → 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.
- 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 +8 -10
- package/dist/src/global/A-Context/A-Context.class.js +26 -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 +11 -11
- 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-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.js +2 -2
- package/dist/src/global/A-Stage/A-Stage.class.js.map +1 -1
- package/examples/simple/concept.ts +1 -0
- 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/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 +38 -85
- package/src/global/A-Entity/A-Entity.class.ts +5 -4
- package/src/global/A-Feature/A-Feature.class.ts +22 -13
- package/src/global/A-Feature/A-Feature.types.ts +14 -2
- package/src/global/A-Scope/A-Scope.class.ts +61 -5
- package/src/global/A-Stage/A-Stage.class.ts +4 -2
|
@@ -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:
|
|
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
|
-
|
|
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 =
|
|
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
|
-
|
|
20
|
-
|
|
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.
|
|
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
|
|
|
@@ -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
|
-
:
|
|
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) => {
|