@adaas/a-concept 0.0.5 → 0.0.7
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 +1 -2
- package/dist/examples/simple/containers/Main.container.js +18 -5
- 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 +5 -1
- package/dist/index.js +10 -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 +2 -2
- 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 +135 -53
- 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-Entity/A-Entity.class.d.ts +28 -4
- package/dist/src/global/A-Entity/A-Entity.class.js +23 -3
- 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 +43 -0
- package/dist/src/global/A-Entity/A-Entity.types.js +13 -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 +75 -1
- package/dist/src/global/A-Meta/A-Meta.class.js +100 -10
- 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 +53 -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 +28 -7
- 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 +6 -1
- 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 +2 -2
- 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 -11
- 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 -34
- package/src/global/A-Container/A-Container.meta.ts +0 -64
- package/src/global/A-Context/A-Context.class.ts +240 -79
- package/src/global/A-Context/A-Context.types.ts +0 -15
- package/src/global/A-Entity/A-Entity.class.ts +65 -8
- package/src/global/A-Entity/A-Entity.meta.ts +9 -0
- package/src/global/A-Entity/A-Entity.types.ts +58 -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 +114 -22
- package/src/global/A-Scope/A-Scope.class.ts +93 -33
|
@@ -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
|
|
@@ -1,7 +1,9 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
//
|
|
2
|
+
//
|
|
3
|
+
//
|
|
4
|
+
//
|
|
5
|
+
//
|
|
6
|
+
//
|
|
5
7
|
|
|
6
8
|
|
|
7
9
|
/**
|
|
@@ -12,11 +14,34 @@ import { A_Container } from "../A-Container/A-Container.class";
|
|
|
12
14
|
export class A_Meta<
|
|
13
15
|
_StorageItems extends Record<string, any>
|
|
14
16
|
// _StorageItems extends Record<string, Map<string | Symbol, any> | Array<any> | A_TYPES__Dictionary<any>>
|
|
15
|
-
> {
|
|
17
|
+
> implements Iterable<[keyof _StorageItems, _StorageItems[keyof _StorageItems]]> {
|
|
16
18
|
|
|
17
19
|
protected meta: Map<keyof _StorageItems, _StorageItems[keyof _StorageItems]> = new Map();
|
|
18
20
|
|
|
19
21
|
|
|
22
|
+
/**
|
|
23
|
+
* Method to get the iterator for the meta object
|
|
24
|
+
*
|
|
25
|
+
* @returns
|
|
26
|
+
*/
|
|
27
|
+
[Symbol.iterator](): Iterator<[keyof _StorageItems, _StorageItems[keyof _StorageItems]]> {
|
|
28
|
+
const iterator = this.meta.entries();
|
|
29
|
+
return {
|
|
30
|
+
next: () => iterator.next()
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
// ===================================================================================================
|
|
37
|
+
// ================================ META OPERATIONS ==================================================
|
|
38
|
+
// ===================================================================================================
|
|
39
|
+
/**
|
|
40
|
+
* Allows to replicate received meta object by replacing internal meta to the received one
|
|
41
|
+
*
|
|
42
|
+
* @param meta
|
|
43
|
+
* @returns
|
|
44
|
+
*/
|
|
20
45
|
from(
|
|
21
46
|
meta: A_Meta<_StorageItems>
|
|
22
47
|
): A_Meta<_StorageItems> {
|
|
@@ -26,11 +51,12 @@ export class A_Meta<
|
|
|
26
51
|
}
|
|
27
52
|
|
|
28
53
|
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
54
|
+
/**
|
|
55
|
+
* Method to set values in the map
|
|
56
|
+
*
|
|
57
|
+
* @param key
|
|
58
|
+
* @param value
|
|
59
|
+
*/
|
|
34
60
|
set<K extends keyof _StorageItems>(key: K, value: _StorageItems[K]) {
|
|
35
61
|
|
|
36
62
|
const inheritedValue = this.meta.get(key)
|
|
@@ -51,18 +77,76 @@ export class A_Meta<
|
|
|
51
77
|
|
|
52
78
|
}
|
|
53
79
|
|
|
54
|
-
|
|
80
|
+
|
|
81
|
+
|
|
82
|
+
/**
|
|
83
|
+
* Method to get values from the map
|
|
84
|
+
*
|
|
85
|
+
* @param key
|
|
86
|
+
* @returns
|
|
87
|
+
*/
|
|
55
88
|
get<K extends keyof _StorageItems>(key: K): _StorageItems[K] | undefined {
|
|
56
89
|
return this.meta.get(key) as _StorageItems[K];
|
|
57
90
|
}
|
|
58
91
|
|
|
59
92
|
|
|
60
|
-
|
|
93
|
+
/**
|
|
94
|
+
* Method to delete values from the map
|
|
95
|
+
*
|
|
96
|
+
* @param key
|
|
97
|
+
* @returns
|
|
98
|
+
*/
|
|
61
99
|
delete(key: keyof _StorageItems): boolean {
|
|
62
100
|
return this.meta.delete(key);
|
|
63
101
|
}
|
|
64
102
|
|
|
65
|
-
|
|
103
|
+
|
|
104
|
+
/**
|
|
105
|
+
* This method is needed to convert the key to a regular expression and cover cases like:
|
|
106
|
+
*
|
|
107
|
+
* simple * e.g. "a*" instead of "a.*"
|
|
108
|
+
*
|
|
109
|
+
* simple ? e.g. "a?" instead of "a."
|
|
110
|
+
*
|
|
111
|
+
* etc.
|
|
112
|
+
*
|
|
113
|
+
* @param key
|
|
114
|
+
* @returns
|
|
115
|
+
*/
|
|
116
|
+
private convertToRegExp(key: string | RegExp): RegExp {
|
|
117
|
+
return key instanceof RegExp
|
|
118
|
+
? key
|
|
119
|
+
: new RegExp(key);
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
|
|
123
|
+
/**
|
|
124
|
+
* Method to find values in the map by name.
|
|
125
|
+
*
|
|
126
|
+
* Converts the Key in Map to a regular expression and then compares to the name
|
|
127
|
+
*
|
|
128
|
+
* @param name
|
|
129
|
+
* @returns
|
|
130
|
+
*/
|
|
131
|
+
find(name: string) {
|
|
132
|
+
const results: Array<[keyof _StorageItems, _StorageItems[keyof _StorageItems]]> = [];
|
|
133
|
+
for (const [key, value] of this.meta.entries()) {
|
|
134
|
+
if (this.convertToRegExp(name).test(key as string)) {
|
|
135
|
+
results.push([key, value]);
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
return results;
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
|
|
142
|
+
/**
|
|
143
|
+
* Method to find values in the map by regular expression
|
|
144
|
+
*
|
|
145
|
+
* Compares Map Key to the input regular expression
|
|
146
|
+
*
|
|
147
|
+
* @param regex
|
|
148
|
+
* @returns
|
|
149
|
+
*/
|
|
66
150
|
findByRegex(regex: RegExp): Array<[keyof _StorageItems, _StorageItems[keyof _StorageItems]]> {
|
|
67
151
|
const results: Array<[keyof _StorageItems, _StorageItems[keyof _StorageItems]]> = [];
|
|
68
152
|
for (const [key, value] of this.meta.entries()) {
|
|
@@ -73,24 +157,32 @@ export class A_Meta<
|
|
|
73
157
|
return results;
|
|
74
158
|
}
|
|
75
159
|
|
|
76
|
-
|
|
160
|
+
|
|
161
|
+
/**
|
|
162
|
+
* Method to check if the map has a specific key
|
|
163
|
+
*
|
|
164
|
+
* @param key
|
|
165
|
+
* @returns
|
|
166
|
+
*/
|
|
77
167
|
has(key: keyof _StorageItems): boolean {
|
|
78
168
|
return this.meta.has(key);
|
|
79
169
|
}
|
|
80
170
|
|
|
81
|
-
|
|
171
|
+
|
|
172
|
+
/**
|
|
173
|
+
* Method to get the size of the map
|
|
174
|
+
*
|
|
175
|
+
* @returns
|
|
176
|
+
*/
|
|
82
177
|
entries(): IterableIterator<[keyof _StorageItems, _StorageItems[keyof _StorageItems]]> {
|
|
83
178
|
return this.meta.entries();
|
|
84
179
|
}
|
|
85
180
|
|
|
86
181
|
|
|
87
|
-
|
|
182
|
+
/**
|
|
183
|
+
* Method to clear the map
|
|
184
|
+
*/
|
|
88
185
|
clear(): void {
|
|
89
186
|
this.meta.clear();
|
|
90
187
|
}
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
|
|
188
|
+
}
|
|
@@ -2,7 +2,9 @@ import { A_CommonHelper } from "@adaas/a-utils";
|
|
|
2
2
|
import { A_TYPES__ScopeConfig, A_TYPES__ScopeConstructor } from "./A-Scope.types";
|
|
3
3
|
import { A_Fragment } from "../A-Fragment/A-Fragment.class";
|
|
4
4
|
import { A_Context } from "../A-Context/A-Context.class";
|
|
5
|
-
import { A_TYPES__ComponentMetaKey } from "../A-Component/A-Component.types";
|
|
5
|
+
import { A_TYPES__ComponentMeta_InjectionParam, A_TYPES__ComponentMetaKey } from "../A-Component/A-Component.types";
|
|
6
|
+
import { A_Component } from "../A-Component/A-Component.class";
|
|
7
|
+
import { A_Entity } from "../A-Entity/A-Entity.class";
|
|
6
8
|
|
|
7
9
|
/**
|
|
8
10
|
*
|
|
@@ -21,8 +23,9 @@ export class A_Scope {
|
|
|
21
23
|
|
|
22
24
|
name: string = '';
|
|
23
25
|
|
|
24
|
-
private _components: WeakMap<
|
|
26
|
+
private _components: WeakMap<typeof A_Component.constructor, any> = new WeakMap();
|
|
25
27
|
private _fragments: WeakMap<typeof A_Fragment.constructor, any> = new WeakMap();
|
|
28
|
+
private _entities: Map<string, A_Entity> = new Map();
|
|
26
29
|
|
|
27
30
|
private parent?: A_Scope;
|
|
28
31
|
|
|
@@ -126,10 +129,10 @@ export class A_Scope {
|
|
|
126
129
|
* @param component
|
|
127
130
|
* @returns
|
|
128
131
|
*/
|
|
129
|
-
resolve<T extends
|
|
130
|
-
resolve<T extends
|
|
132
|
+
resolve<T extends A_TYPES__ComponentMeta_InjectionParam>(component: T): InstanceType<T>
|
|
133
|
+
resolve<T extends A_TYPES__ComponentMeta_InjectionParam>(component: Array<T>): Array<InstanceType<T>>
|
|
131
134
|
// base definition
|
|
132
|
-
resolve<T extends
|
|
135
|
+
resolve<T extends A_TYPES__ComponentMeta_InjectionParam>(
|
|
133
136
|
param1: Array<T> | T,
|
|
134
137
|
param2?: string
|
|
135
138
|
): Array<InstanceType<T>> | InstanceType<T> {
|
|
@@ -151,46 +154,28 @@ export class A_Scope {
|
|
|
151
154
|
|
|
152
155
|
|
|
153
156
|
|
|
154
|
-
|
|
155
|
-
private resolveOnce<T extends { new(...args: any[]): any }>(component: T): InstanceType<T> {
|
|
157
|
+
private resolveOnce<T extends A_TYPES__ComponentMeta_InjectionParam>(component: T): InstanceType<T> {
|
|
156
158
|
switch (true) {
|
|
157
159
|
case A_CommonHelper.isInheritedFrom(component, A_Fragment): {
|
|
158
|
-
return this.resolveFragment(component)
|
|
160
|
+
return this.resolveFragment(component as typeof A_Fragment) as InstanceType<T>;
|
|
159
161
|
}
|
|
160
162
|
|
|
161
|
-
case
|
|
162
|
-
|
|
163
|
-
return this._components.get(component);
|
|
163
|
+
case A_CommonHelper.isInheritedFrom(component, A_Scope): {
|
|
164
|
+
return this.resolveScope(component as typeof A_Scope) as InstanceType<T>;
|
|
164
165
|
}
|
|
165
|
-
case this.components.includes(component) && !this._components.has(component): {
|
|
166
|
-
|
|
167
|
-
const componentMeta = A_Context.meta(component)
|
|
168
|
-
|
|
169
|
-
const argsMeta = componentMeta.get(A_TYPES__ComponentMetaKey.INJECTIONS);
|
|
170
|
-
|
|
171
|
-
let resolvedArgs: Array<any> = [];
|
|
172
|
-
|
|
173
|
-
if (argsMeta)
|
|
174
|
-
resolvedArgs = (argsMeta.get('constructor') || [])
|
|
175
|
-
.map(arg => this.resolve(arg));
|
|
176
166
|
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
return this._components.get(component);
|
|
167
|
+
case A_CommonHelper.isInheritedFrom(component, A_Component): {
|
|
168
|
+
return this.resolveComponent(component as typeof A_Component) as InstanceType<T>;
|
|
180
169
|
}
|
|
181
170
|
|
|
182
|
-
case !this.components.includes(component) && !!this.parent: {
|
|
183
|
-
|
|
184
|
-
return this.parent.resolve(component);
|
|
185
|
-
}
|
|
186
171
|
default:
|
|
187
|
-
throw new Error(`Component ${component
|
|
172
|
+
throw new Error(`Injected Component ${component} not found in the scope`);
|
|
188
173
|
}
|
|
189
174
|
}
|
|
190
175
|
|
|
191
176
|
|
|
192
177
|
|
|
193
|
-
private resolveFragment<T extends
|
|
178
|
+
private resolveFragment<T extends typeof A_Fragment>(fragment: T): InstanceType<T> {
|
|
194
179
|
|
|
195
180
|
if (this._fragments.has(fragment)) {
|
|
196
181
|
return this._fragments.get(fragment);
|
|
@@ -203,9 +188,84 @@ export class A_Scope {
|
|
|
203
188
|
throw new Error(`Fragment ${fragment.name} not found in the scope ${this.name}`);
|
|
204
189
|
}
|
|
205
190
|
|
|
191
|
+
private resolveScope(scope: typeof A_Scope): A_Scope {
|
|
192
|
+
return this;
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
|
|
196
|
+
private resolveComponent<T extends A_Component>(component: {
|
|
197
|
+
new(...args: any[]): T
|
|
198
|
+
}): T {
|
|
199
|
+
|
|
200
|
+
if (this.components.includes(component) && this._components.has(component))
|
|
201
|
+
return this._components.get(component);
|
|
202
|
+
|
|
203
|
+
else if (this.components.includes(component) && !this._components.has(component)) {
|
|
204
|
+
const componentMeta = A_Context.meta(component)
|
|
205
|
+
|
|
206
|
+
const argsMeta = componentMeta.get(A_TYPES__ComponentMetaKey.INJECTIONS);
|
|
207
|
+
|
|
208
|
+
const resolvedArgs = (argsMeta?.get('constructor') || [])
|
|
209
|
+
.map(arg => this.resolve(arg));
|
|
210
|
+
|
|
211
|
+
const newComponent = new component(...resolvedArgs)
|
|
212
|
+
|
|
213
|
+
this.register(newComponent);
|
|
214
|
+
|
|
215
|
+
return this._components.get(component);
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
else if (!this.components.includes(component) && !!this.parent) {
|
|
219
|
+
return this.parent.resolveComponent(component);
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
else {
|
|
223
|
+
throw new Error(`Component ${component.name} not found in the scope`);
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
|
|
228
|
+
|
|
229
|
+
/**
|
|
230
|
+
* This method is used to register the component in the scope
|
|
231
|
+
*
|
|
232
|
+
* @param fragment
|
|
233
|
+
*/
|
|
234
|
+
register(fragment: A_Entity): void
|
|
235
|
+
register(fragment: A_Component): void
|
|
236
|
+
register(fragment: A_Fragment): void
|
|
237
|
+
register(
|
|
238
|
+
param1: A_Fragment | A_Component | A_Entity
|
|
239
|
+
): void {
|
|
240
|
+
|
|
241
|
+
|
|
242
|
+
switch (true) {
|
|
243
|
+
case param1 instanceof A_Fragment && !this._fragments.has(param1.constructor): {
|
|
244
|
+
this._fragments.set(param1.constructor, param1);
|
|
245
|
+
// The same situation. Have not idea how to fix it
|
|
246
|
+
A_Context.register(this, param1 as any);
|
|
247
|
+
break;
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
case param1 instanceof A_Entity && !this._entities.has(param1.aseid.toString()): {
|
|
251
|
+
this._entities.set(param1.aseid.toString(), param1);
|
|
252
|
+
// The same situation. Have not idea how to fix it
|
|
253
|
+
A_Context.register(this, param1 as any);
|
|
254
|
+
break;
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
case param1 instanceof A_Component: {
|
|
258
|
+
this._components.set(param1.constructor, param1);
|
|
259
|
+
// The same situation. Have not idea how to fix it
|
|
260
|
+
A_Context.register(this, param1 as any);
|
|
261
|
+
break;
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
default:
|
|
265
|
+
throw new Error('Invalid arguments provided');
|
|
266
|
+
}
|
|
267
|
+
|
|
206
268
|
|
|
207
269
|
|
|
208
|
-
register(fragment: A_Fragment): void {
|
|
209
|
-
this._fragments.set(fragment.constructor, fragment);
|
|
210
270
|
}
|
|
211
271
|
}
|