@adaas/a-concept 0.0.4 → 0.0.6
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/examples/simple/components/A.component.d.ts +4 -2
- package/dist/examples/simple/components/A.component.js +7 -4
- package/dist/examples/simple/components/A.component.js.map +1 -1
- package/dist/examples/simple/components/B.component.d.ts +6 -2
- package/dist/examples/simple/components/B.component.js +18 -7
- package/dist/examples/simple/components/B.component.js.map +1 -1
- package/dist/examples/simple/concept.js +59 -32
- package/dist/examples/simple/concept.js.map +1 -1
- package/dist/examples/simple/containers/Main.container.d.ts +2 -3
- package/dist/examples/simple/containers/Main.container.js +28 -8
- package/dist/examples/simple/containers/Main.container.js.map +1 -1
- package/dist/examples/simple-http-server/components/http-error-handler.component.d.ts +2 -1
- package/dist/examples/simple-http-server/components/http-error-handler.component.js +3 -1
- package/dist/examples/simple-http-server/components/http-error-handler.component.js.map +1 -1
- package/dist/examples/simple-http-server/components/http-request-handler.component.d.ts +2 -1
- package/dist/examples/simple-http-server/components/http-request-handler.component.js +2 -1
- package/dist/examples/simple-http-server/components/http-request-handler.component.js.map +1 -1
- package/dist/examples/simple-http-server/containers/http-server.container.d.ts +1 -2
- package/dist/index.d.ts +7 -1
- package/dist/index.js +13 -2
- package/dist/index.js.map +1 -1
- package/dist/src/base/A-Config/A-Config.container.d.ts +1 -3
- package/dist/src/base/A-Config/A-Config.container.js +6 -22
- package/dist/src/base/A-Config/A-Config.container.js.map +1 -1
- package/dist/src/base/A-Config/A-Config.context.d.ts +1 -0
- package/dist/src/base/A-Config/A-Config.context.js +20 -2
- package/dist/src/base/A-Config/A-Config.context.js.map +1 -1
- package/dist/src/base/A-Config/A-Config.types.d.ts +4 -2
- package/dist/src/base/A-Config/A-Config.types.js +4 -0
- package/dist/src/base/A-Config/A-Config.types.js.map +1 -1
- package/dist/src/base/A-Config/components/ConfigReader.component.d.ts +2 -1
- package/dist/src/base/A-Config/components/ConfigReader.component.js +3 -1
- package/dist/src/base/A-Config/components/ConfigReader.component.js.map +1 -1
- package/dist/src/base/A-Errors/A-Errors.component.d.ts +2 -1
- package/dist/src/base/A-Errors/A-Errors.component.js +3 -1
- package/dist/src/base/A-Errors/A-Errors.component.js.map +1 -1
- package/dist/src/base/A-Logger/A-Logger.component.d.ts +4 -2
- package/dist/src/base/A-Logger/A-Logger.component.js +11 -3
- package/dist/src/base/A-Logger/A-Logger.component.js.map +1 -1
- 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 +9 -9
- package/dist/src/decorators/A-Feature/A-Feature-Extend.decorator.js.map +1 -1
- package/dist/src/decorators/A-Inject/A-Inject.decorator.d.ts +0 -2
- package/dist/src/decorators/A-Inject/A-Inject.decorator.js +4 -2
- package/dist/src/decorators/A-Inject/A-Inject.decorator.js.map +1 -1
- package/dist/src/global/A-Component/A-Component.class.d.ts +28 -1
- package/dist/src/global/A-Component/A-Component.class.js +22 -0
- package/dist/src/global/A-Component/A-Component.class.js.map +1 -1
- package/dist/src/global/A-Component/A-Component.meta.d.ts +8 -1
- package/dist/src/global/A-Component/A-Component.meta.js +26 -0
- package/dist/src/global/A-Component/A-Component.meta.js.map +1 -1
- package/dist/src/global/A-Component/A-Component.types.d.ts +43 -6
- package/dist/src/global/A-Component/A-Component.types.js +5 -0
- package/dist/src/global/A-Component/A-Component.types.js.map +1 -1
- package/dist/src/global/A-Concept/A_Concept.class.d.ts +7 -7
- package/dist/src/global/A-Concept/A_Concept.class.js +1 -2
- package/dist/src/global/A-Concept/A_Concept.class.js.map +1 -1
- package/dist/src/global/A-Container/A-Container.class.d.ts +5 -4
- package/dist/src/global/A-Container/A-Container.class.js +13 -24
- package/dist/src/global/A-Container/A-Container.class.js.map +1 -1
- package/dist/src/global/A-Container/A-Container.meta.d.ts +0 -3
- package/dist/src/global/A-Container/A-Container.meta.js +0 -46
- package/dist/src/global/A-Container/A-Container.meta.js.map +1 -1
- package/dist/src/global/A-Context/A-Context.class.d.ts +35 -5
- package/dist/src/global/A-Context/A-Context.class.js +138 -54
- package/dist/src/global/A-Context/A-Context.class.js.map +1 -1
- package/dist/src/global/A-Context/A-Context.types.d.ts +0 -12
- package/dist/src/global/A-Context/A-Context.types.js +0 -1
- package/dist/src/global/A-Dependency/A-DependencyReference.class.d.ts +0 -17
- package/dist/src/global/A-Dependency/A-DependencyReference.class.js +47 -65
- package/dist/src/global/A-Dependency/A-DependencyReference.class.js.map +1 -1
- package/dist/src/global/A-Entity/A-Entity.class.d.ts +73 -2
- package/dist/src/global/A-Entity/A-Entity.class.js +107 -1
- package/dist/src/global/A-Entity/A-Entity.class.js.map +1 -1
- package/dist/src/global/A-Entity/A-Entity.meta.d.ts +4 -0
- package/dist/src/global/A-Entity/A-Entity.meta.js +8 -0
- package/dist/src/global/A-Entity/A-Entity.meta.js.map +1 -0
- package/dist/src/global/A-Entity/A-Entity.types.d.ts +56 -0
- package/dist/src/global/A-Entity/A-Entity.types.js +15 -0
- package/dist/src/global/A-Entity/A-Entity.types.js.map +1 -1
- package/dist/src/global/A-Feature/A-Feature.class.d.ts +11 -1
- package/dist/src/global/A-Feature/A-Feature.class.js +48 -12
- package/dist/src/global/A-Feature/A-Feature.class.js.map +1 -1
- package/dist/src/global/A-Feature/A-Feature.types.d.ts +5 -4
- package/dist/src/global/A-Feature/A-Feature.types.js.map +1 -1
- package/dist/src/global/A-Fragment/A-Fragment.class.js +1 -2
- package/dist/src/global/A-Fragment/A-Fragment.class.js.map +1 -1
- package/dist/src/global/A-Meta/A-Meta.class.d.ts +80 -1
- package/dist/src/global/A-Meta/A-Meta.class.js +121 -5
- package/dist/src/global/A-Meta/A-Meta.class.js.map +1 -1
- package/dist/src/global/A-Scope/A-Scope.class.d.ts +15 -6
- package/dist/src/global/A-Scope/A-Scope.class.js +61 -17
- package/dist/src/global/A-Scope/A-Scope.class.js.map +1 -1
- package/examples/simple/components/A.component.ts +6 -3
- package/examples/simple/components/B.component.ts +19 -6
- package/examples/simple/concept.ts +65 -33
- package/examples/simple/containers/Main.container.ts +36 -9
- package/examples/simple-http-server/components/http-error-handler.component.ts +5 -2
- package/examples/simple-http-server/components/http-request-handler.component.ts +3 -1
- package/index.ts +9 -1
- package/jest.config.ts +0 -4
- package/package.json +1 -1
- package/src/base/A-Config/A-Config.container.ts +5 -8
- package/src/base/A-Config/A-Config.context.ts +10 -2
- package/src/base/A-Config/A-Config.types.ts +8 -3
- package/src/base/A-Config/components/ConfigReader.component.ts +5 -2
- package/src/base/A-Errors/A-Errors.component.ts +3 -2
- package/src/base/A-Logger/A-Logger.component.ts +21 -3
- package/src/decorators/A-Feature/A-Feature-Define.decorator.ts +0 -1
- package/src/decorators/A-Feature/A-Feature-Extend.decorator.ts +15 -10
- package/src/decorators/A-Inject/A-Inject.decorator.ts +13 -12
- package/src/global/A-Component/A-Component.class.ts +56 -1
- package/src/global/A-Component/A-Component.meta.ts +40 -1
- package/src/global/A-Component/A-Component.types.ts +51 -19
- package/src/global/A-Concept/A_Concept.class.ts +2 -2
- package/src/global/A-Container/A-Container.class.ts +22 -39
- package/src/global/A-Container/A-Container.meta.ts +0 -64
- package/src/global/A-Context/A-Context.class.ts +240 -80
- package/src/global/A-Context/A-Context.types.ts +0 -15
- package/src/global/A-Dependency/A-DependencyReference.class.ts +61 -61
- package/src/global/A-Entity/A-Entity.class.ts +184 -2
- package/src/global/A-Entity/A-Entity.meta.ts +9 -0
- package/src/global/A-Entity/A-Entity.types.ts +75 -0
- package/src/global/A-Feature/A-Feature.class.ts +62 -20
- package/src/global/A-Feature/A-Feature.types.ts +8 -2
- package/src/global/A-Fragment/A-Fragment.class.ts +1 -5
- package/src/global/A-Meta/A-Meta.class.ts +140 -12
- package/src/global/A-Scope/A-Scope.class.ts +101 -31
- package/tsconfig.json +0 -4
- package/src/storage/A_Component.storage.ts +0 -28
- package/src/storage/A_Concept.storage.ts +0 -49
- package/src/storage/A_Container.storage.ts +0 -21
- package/src/storage/A_Inject.storage.ts +0 -30
|
@@ -1,61 +1,61 @@
|
|
|
1
|
-
class RealDependency {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
class DependencyReference<T> {
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
// Example usage:
|
|
53
|
-
(async () => {
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
})();
|
|
1
|
+
// class RealDependency {
|
|
2
|
+
// constructor(private name: string) { }
|
|
3
|
+
|
|
4
|
+
// getName() {
|
|
5
|
+
// return this.name;
|
|
6
|
+
// }
|
|
7
|
+
|
|
8
|
+
// performAction() {
|
|
9
|
+
// console.log(`${this.name} is performing an action.`);
|
|
10
|
+
// }
|
|
11
|
+
// }
|
|
12
|
+
|
|
13
|
+
// class DependencyReference<T> {
|
|
14
|
+
// private proxyInstance: T | null = null;
|
|
15
|
+
// private realInstance: T | null = null;
|
|
16
|
+
|
|
17
|
+
// constructor(private realClass: { new(...args: any[]): T }, private args: any[]) { }
|
|
18
|
+
|
|
19
|
+
// // Simulate async loading (e.g., dynamic imports, API calls, etc.)
|
|
20
|
+
// private async loadInstance(): Promise<T> {
|
|
21
|
+
// if (!this.realInstance) {
|
|
22
|
+
// console.log('Loading real dependency...');
|
|
23
|
+
// // Simulate async loading with a delay
|
|
24
|
+
// await new Promise((resolve) => setTimeout(resolve, 1000));
|
|
25
|
+
// this.realInstance = new this.realClass(...this.args);
|
|
26
|
+
// }
|
|
27
|
+
// return this.realInstance;
|
|
28
|
+
// }
|
|
29
|
+
|
|
30
|
+
// public async resolve(): Promise<T> {
|
|
31
|
+
// if (!this.proxyInstance) {
|
|
32
|
+
// const realInstance = await this.loadInstance();
|
|
33
|
+
|
|
34
|
+
// this.proxyInstance = new Proxy({}, {
|
|
35
|
+
// get: (target, prop) => {
|
|
36
|
+
// const value = (realInstance as any)[prop];
|
|
37
|
+
|
|
38
|
+
// // If the property is a method, return a bound function
|
|
39
|
+
// if (typeof value === 'function') {
|
|
40
|
+
// return value.bind(realInstance);
|
|
41
|
+
// }
|
|
42
|
+
// return value;
|
|
43
|
+
// }
|
|
44
|
+
// }) as T;
|
|
45
|
+
// }
|
|
46
|
+
|
|
47
|
+
// return this.proxyInstance;
|
|
48
|
+
// }
|
|
49
|
+
// }
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
// // Example usage:
|
|
53
|
+
// (async () => {
|
|
54
|
+
// const lazyDependency = new DependencyReference(RealDependency, ['ComponentA']);
|
|
55
|
+
|
|
56
|
+
// const proxy = await lazyDependency.resolve(); // Loads the instance asynchronously
|
|
57
|
+
|
|
58
|
+
// proxy.performAction(); // Will call the method on the real instance
|
|
59
|
+
|
|
60
|
+
// console.log(proxy.getName()); // Calls method on the real instance
|
|
61
|
+
// })();
|
|
@@ -1,3 +1,16 @@
|
|
|
1
|
+
import {
|
|
2
|
+
A_Error, A_TYPES__Required,
|
|
3
|
+
ASEID
|
|
4
|
+
} from "@adaas/a-utils";
|
|
5
|
+
import {
|
|
6
|
+
A_TYPES__Entity_JSON,
|
|
7
|
+
A_TYPES__EntityBaseMethods,
|
|
8
|
+
A_TYPES__EntityCallParams,
|
|
9
|
+
A_TYPES__IEntity
|
|
10
|
+
} from "./A-Entity.types";
|
|
11
|
+
import { A_CONSTANTS__DEFAULT_ERRORS } from "@adaas/a-utils/dist/src/constants/errors.constants";
|
|
12
|
+
import { A_Context } from "../A-Context/A-Context.class";
|
|
13
|
+
|
|
1
14
|
|
|
2
15
|
|
|
3
16
|
/**
|
|
@@ -7,10 +20,179 @@
|
|
|
7
20
|
*
|
|
8
21
|
* Each entity should be connected to the ContextFragment (Scope) and should be able to communicate with other entities.
|
|
9
22
|
*/
|
|
10
|
-
export class A_Entity
|
|
23
|
+
export class A_Entity<
|
|
24
|
+
_ConstructorType = any,
|
|
25
|
+
_SerializedType extends A_TYPES__Entity_JSON = A_TYPES__Entity_JSON,
|
|
26
|
+
_FeatureNames extends Array<string> = A_TYPES__EntityBaseMethods
|
|
27
|
+
>
|
|
28
|
+
implements A_TYPES__IEntity {
|
|
29
|
+
|
|
30
|
+
aseid!: ASEID;
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
constructor(
|
|
34
|
+
aseid: string
|
|
35
|
+
)
|
|
36
|
+
constructor(
|
|
37
|
+
aseid: ASEID
|
|
38
|
+
)
|
|
39
|
+
constructor(
|
|
40
|
+
serialized: _SerializedType
|
|
41
|
+
)
|
|
42
|
+
constructor(
|
|
43
|
+
newEntity: _ConstructorType
|
|
44
|
+
)
|
|
45
|
+
constructor(props: string | ASEID | _SerializedType | _ConstructorType) {
|
|
46
|
+
|
|
47
|
+
switch (true) {
|
|
48
|
+
case (typeof props === 'string' && ASEID.isASEID(props)):
|
|
49
|
+
this.aseid = new ASEID(props);
|
|
50
|
+
break;
|
|
51
|
+
case (props instanceof ASEID):
|
|
52
|
+
this.aseid = props;
|
|
53
|
+
break;
|
|
54
|
+
case (typeof props === 'object' && (props as any).aseid):
|
|
55
|
+
this.fromSerialized(props as _SerializedType);
|
|
56
|
+
break;
|
|
57
|
+
|
|
58
|
+
case (typeof props === 'object'):
|
|
59
|
+
this.fromNewEntity(props as _ConstructorType);
|
|
60
|
+
break
|
|
61
|
+
|
|
62
|
+
default:
|
|
63
|
+
throw new A_Error(A_CONSTANTS__DEFAULT_ERRORS.INCORRECT_A_ENTITY_CONSTRUCTOR);
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
// ====================================================================
|
|
68
|
+
// ================== DUPLICATED ASEID Getters ========================
|
|
69
|
+
// ====================================================================
|
|
70
|
+
|
|
71
|
+
/**
|
|
72
|
+
* Extracts the ID from the ASEID
|
|
73
|
+
* ID is the unique identifier of the entity
|
|
74
|
+
*/
|
|
75
|
+
get id(): string | number {
|
|
76
|
+
return this.aseid.id;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
/**
|
|
80
|
+
* Extracts the namespace from the ASEID
|
|
81
|
+
* namespace is an application specific identifier from where the entity is coming from
|
|
82
|
+
*/
|
|
83
|
+
get namespace(): string {
|
|
84
|
+
return this.aseid.namespace
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
/**
|
|
88
|
+
* Extracts the scope from the ASEID
|
|
89
|
+
* scope is the scope of the entity from Application Namespace
|
|
90
|
+
*/
|
|
91
|
+
get scope(): string {
|
|
92
|
+
return this.aseid.scope;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
/**
|
|
96
|
+
* Extracts the entity from the ASEID
|
|
97
|
+
* entity is the name of the entity from Application Namespace
|
|
98
|
+
*/
|
|
99
|
+
get entity(): string {
|
|
100
|
+
return this.aseid.entity;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
/**
|
|
104
|
+
* Extracts the version from the ASEID
|
|
105
|
+
* version is the version of the entity
|
|
106
|
+
*/
|
|
107
|
+
|
|
108
|
+
get version(): string | undefined {
|
|
109
|
+
return this.aseid.version;
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
/**
|
|
113
|
+
* Extracts the shard from the ASEID
|
|
114
|
+
* shard is the shard of the entity
|
|
115
|
+
*/
|
|
116
|
+
get shard(): string | undefined {
|
|
117
|
+
return this.aseid.shard;
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
|
|
121
|
+
/**
|
|
122
|
+
* Call a feature of the component
|
|
123
|
+
*
|
|
124
|
+
* @param lifecycleMethod
|
|
125
|
+
* @param args
|
|
126
|
+
*/
|
|
127
|
+
async call(
|
|
128
|
+
/**
|
|
129
|
+
* A-Feature method name to be called
|
|
130
|
+
*/
|
|
131
|
+
feature: _FeatureNames[number],
|
|
132
|
+
): Promise<any>
|
|
133
|
+
async call(
|
|
134
|
+
/**
|
|
135
|
+
* A-Feature name to be called
|
|
136
|
+
*/
|
|
137
|
+
params: A_TYPES__Required<Partial<A_TYPES__EntityCallParams<_FeatureNames[number]>>, ['name']>,
|
|
138
|
+
): Promise<any>
|
|
139
|
+
async call(
|
|
140
|
+
/**
|
|
141
|
+
* A-Feature method name to be called
|
|
142
|
+
*/
|
|
143
|
+
feature: string,
|
|
144
|
+
/**
|
|
145
|
+
* Parameters to provide additional data to the feature
|
|
146
|
+
*/
|
|
147
|
+
params: Partial<A_TYPES__EntityCallParams<_FeatureNames[number]>>,
|
|
148
|
+
): Promise<any>
|
|
149
|
+
|
|
150
|
+
async call(
|
|
151
|
+
param1: _FeatureNames[number] | A_TYPES__Required<Partial<A_TYPES__EntityCallParams<_FeatureNames[number]>>, ['name']>,
|
|
152
|
+
param2?: Partial<A_TYPES__EntityCallParams<_FeatureNames[number]>>
|
|
153
|
+
): Promise<any> {
|
|
154
|
+
|
|
155
|
+
const feature: string = typeof param1 === 'string'
|
|
156
|
+
? param1
|
|
157
|
+
: param1.name;
|
|
158
|
+
const params: Partial<A_TYPES__EntityCallParams<_FeatureNames[number]>> = typeof param1 === 'string'
|
|
159
|
+
? param2 || {}
|
|
160
|
+
: param1;
|
|
161
|
+
|
|
162
|
+
const newFeature = A_Context.feature(this, feature, params);
|
|
163
|
+
|
|
164
|
+
return await newFeature.process();
|
|
165
|
+
}
|
|
166
|
+
|
|
11
167
|
|
|
12
|
-
constructor() {
|
|
13
168
|
|
|
169
|
+
|
|
170
|
+
protected fromNewEntity(newEntity: _ConstructorType): void {
|
|
171
|
+
return;
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
protected fromSerialized(serialized: _SerializedType): void {
|
|
175
|
+
this.aseid = new ASEID((serialized).aseid);
|
|
176
|
+
return;
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
|
|
180
|
+
|
|
181
|
+
/**
|
|
182
|
+
* Converts the entity to a JSON object
|
|
183
|
+
*
|
|
184
|
+
*
|
|
185
|
+
* @returns
|
|
186
|
+
*/
|
|
187
|
+
toJSON(): _SerializedType {
|
|
188
|
+
return {
|
|
189
|
+
aseid: this.aseid.toString()
|
|
190
|
+
} as _SerializedType;
|
|
14
191
|
}
|
|
15
192
|
|
|
193
|
+
|
|
194
|
+
|
|
195
|
+
toString(): string {
|
|
196
|
+
return this.aseid.toString();
|
|
197
|
+
}
|
|
16
198
|
}
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import { ASEID } from "@adaas/a-utils";
|
|
2
|
+
import { A_Meta } from "../A-Meta/A-Meta.class";
|
|
3
|
+
import { A_Fragment } from "../A-Fragment/A-Fragment.class";
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
export type A_TYPES__EntityCallParams<T extends string> = {
|
|
7
|
+
name: T,
|
|
8
|
+
fragments: Array<A_Fragment>,
|
|
9
|
+
components: Array<{ new(...args: any[]): any }>
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
export type A_TYPES__EntityBaseMethods = [
|
|
14
|
+
A_TYPES__EntityBaseMethod.SAVE,
|
|
15
|
+
A_TYPES__EntityBaseMethod.UPDATE,
|
|
16
|
+
A_TYPES__EntityBaseMethod.DESTROY,
|
|
17
|
+
A_TYPES__EntityBaseMethod.LOAD
|
|
18
|
+
]
|
|
19
|
+
|
|
20
|
+
export enum A_TYPES__EntityBaseMethod {
|
|
21
|
+
SAVE = 'save',
|
|
22
|
+
UPDATE = 'update',
|
|
23
|
+
DESTROY = 'destroy',
|
|
24
|
+
LOAD = 'load'
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export interface A_TYPES__IEntity {
|
|
28
|
+
/**
|
|
29
|
+
* The ASEID of the entity
|
|
30
|
+
*/
|
|
31
|
+
aseid: ASEID
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
export type A_TYPES__Entity_JSON = {
|
|
36
|
+
/**
|
|
37
|
+
* The ASEID of the entity
|
|
38
|
+
*/
|
|
39
|
+
aseid: string
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
export type A_TYPES__EntityMeta = {
|
|
47
|
+
[A_TYPES__EntityMetaKey.EXTENSIONS]: A_Meta<{
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* Where Key the regexp for what to apply the extension
|
|
51
|
+
* A set of container names or a wildcard, or a regexp
|
|
52
|
+
*
|
|
53
|
+
*
|
|
54
|
+
* Where value is the extension instructions
|
|
55
|
+
*/
|
|
56
|
+
[Key: string]: A_TYPES__EntityMeta_ExtensionItem[]
|
|
57
|
+
|
|
58
|
+
}>, case
|
|
59
|
+
|
|
60
|
+
|
|
61
|
+
[A_TYPES__EntityMetaKey.FEATURES]: any[],
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
export enum A_TYPES__EntityMetaKey {
|
|
65
|
+
EXTENSIONS = 'a-component-extensions',
|
|
66
|
+
FEATURES = 'a-component-features',
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
|
|
70
|
+
export type A_TYPES__EntityMeta_ExtensionItem = {
|
|
71
|
+
name: string,
|
|
72
|
+
handler: string,
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { A_Feature_Define } from "@adaas/a-concept/decorators/A-Feature/A-Feature-Define.decorator";
|
|
2
2
|
import { A_Feature_Extend } from "@adaas/a-concept/decorators/A-Feature/A-Feature-Extend.decorator";
|
|
3
|
-
import { A_TYPES__FeatureConstructor, A_TYPES__FeatureState, A_TYPES__FeatureStep } from "./A-Feature.types";
|
|
4
|
-
import { A_Scope } from "../A-Scope/A-Scope.class";
|
|
3
|
+
import { A_TYPES__FeatureConstructor, A_TYPES__FeatureIteratorReturn, A_TYPES__FeatureState, A_TYPES__FeatureStep } from "./A-Feature.types";
|
|
5
4
|
import { A_Error, A_TYPES__Required } from "@adaas/a-utils";
|
|
6
5
|
import { A_Context } from "../A-Context/A-Context.class";
|
|
7
6
|
|
|
@@ -37,7 +36,9 @@ export class A_Feature {
|
|
|
37
36
|
|
|
38
37
|
|
|
39
38
|
// protected scope: A_Scope
|
|
40
|
-
protected steps: A_TYPES__FeatureStep[] = []
|
|
39
|
+
protected steps: A_TYPES__FeatureStep[] = [];
|
|
40
|
+
protected _current?: A_TYPES__FeatureStep;
|
|
41
|
+
protected _index: number = 0;
|
|
41
42
|
|
|
42
43
|
state: A_TYPES__FeatureState = A_TYPES__FeatureState.INITIALIZED;
|
|
43
44
|
|
|
@@ -55,6 +56,61 @@ export class A_Feature {
|
|
|
55
56
|
}
|
|
56
57
|
|
|
57
58
|
|
|
59
|
+
/**
|
|
60
|
+
* Custom iterator to iterate over the steps of the feature
|
|
61
|
+
*
|
|
62
|
+
* @returns
|
|
63
|
+
*/
|
|
64
|
+
[Symbol.iterator](): Iterator<A_TYPES__FeatureIteratorReturn, any> {
|
|
65
|
+
return {
|
|
66
|
+
// Custom next method
|
|
67
|
+
next: (): IteratorResult<A_TYPES__FeatureIteratorReturn, any> => {
|
|
68
|
+
if (this._index < this.steps.length) {
|
|
69
|
+
if (
|
|
70
|
+
(this.state as any) === A_TYPES__FeatureState.FAILED
|
|
71
|
+
||
|
|
72
|
+
(this.state as any) === A_TYPES__FeatureState.COMPLETED
|
|
73
|
+
) {
|
|
74
|
+
throw new Error('FEATURE_PROCESSING_INTERRUPTED');
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
this._current = this.steps[this._index];
|
|
78
|
+
|
|
79
|
+
const { component, handler, args } = this._current;
|
|
80
|
+
|
|
81
|
+
const instance = A_Context.scope(this).resolve(component);
|
|
82
|
+
|
|
83
|
+
return {
|
|
84
|
+
value: async () => {
|
|
85
|
+
|
|
86
|
+
if (instance[handler]) {
|
|
87
|
+
const callArgs = A_Context.scope(this).resolve(args);
|
|
88
|
+
await instance[handler](...callArgs);
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
this._index++;
|
|
92
|
+
},
|
|
93
|
+
done: false
|
|
94
|
+
};
|
|
95
|
+
} else {
|
|
96
|
+
this._current = undefined; // Reset current on end
|
|
97
|
+
return { value: undefined, done: true };
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
};
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
// Access the current element
|
|
104
|
+
get current(): A_TYPES__FeatureStep | undefined {
|
|
105
|
+
return this._current;
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
// Custom end strategy or stop condition (could be expanded if needed)
|
|
109
|
+
isDone(): boolean {
|
|
110
|
+
return this.current === null;
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
|
|
58
114
|
/**
|
|
59
115
|
* This method marks the feature as completed and returns the result
|
|
60
116
|
* Uses to interrupt or end the feature processing
|
|
@@ -94,28 +150,14 @@ export class A_Feature {
|
|
|
94
150
|
try {
|
|
95
151
|
this.state = A_TYPES__FeatureState.PROCESSING;
|
|
96
152
|
|
|
97
|
-
for (const
|
|
98
|
-
|
|
99
|
-
if (
|
|
100
|
-
(this.state as any) === A_TYPES__FeatureState.FAILED
|
|
101
|
-
||
|
|
102
|
-
(this.state as any) === A_TYPES__FeatureState.COMPLETED
|
|
103
|
-
) {
|
|
104
|
-
throw new Error('FEATURE_PROCESSING_INTERRUPTED');
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
const instance = A_Context.scope(this).resolve(component);
|
|
108
|
-
|
|
109
|
-
if (instance[handler]) {
|
|
110
|
-
const callArgs = A_Context.scope(this).resolve(args);
|
|
111
|
-
await instance[handler](...callArgs);
|
|
112
|
-
}
|
|
153
|
+
for (const step of this) {
|
|
154
|
+
await step();
|
|
113
155
|
}
|
|
114
156
|
|
|
115
157
|
await this.completed();
|
|
116
158
|
|
|
117
159
|
} catch (error) {
|
|
118
|
-
console.log('Feature processing error:', error);
|
|
160
|
+
console.log('[!] Feature processing error:', error);
|
|
119
161
|
|
|
120
162
|
await this.failed(error);
|
|
121
163
|
}
|
|
@@ -1,5 +1,11 @@
|
|
|
1
|
+
import { A_Component } from "../A-Component/A-Component.class"
|
|
2
|
+
import { A_TYPES__ComponentMeta_InjectionParam } from "../A-Component/A-Component.types"
|
|
1
3
|
import { A_TYPES__ScopeConfig, A_TYPES__ScopeConstructor } from "../A-Scope/A-Scope.types"
|
|
2
4
|
|
|
5
|
+
|
|
6
|
+
export type A_TYPES__FeatureIteratorReturn<T extends any = any> = () => Promise<T>
|
|
7
|
+
|
|
8
|
+
|
|
3
9
|
export type A_TYPES__FeatureConstructor = {
|
|
4
10
|
steps: A_TYPES__FeatureStep[]
|
|
5
11
|
} & A_TYPES__ScopeConstructor & A_TYPES__ScopeConfig
|
|
@@ -14,7 +20,7 @@ export enum A_TYPES__FeatureState {
|
|
|
14
20
|
|
|
15
21
|
|
|
16
22
|
export type A_TYPES__FeatureStep = {
|
|
17
|
-
component:
|
|
23
|
+
component: typeof A_Component,
|
|
18
24
|
handler: string,
|
|
19
|
-
args:
|
|
25
|
+
args: A_TYPES__ComponentMeta_InjectionParam[]
|
|
20
26
|
}
|
|
@@ -28,11 +28,7 @@ export class A_Fragment {
|
|
|
28
28
|
/**
|
|
29
29
|
* Register the Namespace in the global Namespace provider
|
|
30
30
|
*/
|
|
31
|
-
this.name =
|
|
32
|
-
.register(
|
|
33
|
-
this,
|
|
34
|
-
this.name
|
|
35
|
-
);
|
|
31
|
+
this.name = params.name || this.constructor.name;
|
|
36
32
|
|
|
37
33
|
/**
|
|
38
34
|
* Run Async Initialization
|