@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,7 +1,7 @@
|
|
|
1
1
|
import { A_TYPES__ConceptStage, A_TYPES__ConceptStageParams, A_TYPES__IConceptConstructor } from "./A_Concept.types";
|
|
2
2
|
import { A_Context } from "../A-Context/A-Context.class";
|
|
3
3
|
import { A_Container } from "../A-Container/A-Container.class";
|
|
4
|
-
import { A_Logger } from "@adaas/a-concept/base/A-Logger/A-Logger.component";
|
|
4
|
+
// import { A_Logger } from "@adaas/a-concept/base/A-Logger/A-Logger.component";
|
|
5
5
|
import { A_Fragment } from "../A-Fragment/A-Fragment.class";
|
|
6
6
|
import { A_TYPES__ContainerMetaKey } from "../A-Container/A-Container.types";
|
|
7
7
|
import { A_Stage } from "@adaas/a-concept/decorators/A-Stage/A-Stage.decorator";
|
|
@@ -102,7 +102,7 @@ export class A_Concept<
|
|
|
102
102
|
fragments: props.fragments || [],
|
|
103
103
|
// containers: props.containers
|
|
104
104
|
components: [
|
|
105
|
-
A_Logger,
|
|
105
|
+
// A_Logger,
|
|
106
106
|
]
|
|
107
107
|
});
|
|
108
108
|
|
|
@@ -1,12 +1,8 @@
|
|
|
1
1
|
import { A_TYPES__ContainerCallParams, A_TYPES__ContainerConstructor } from "./A-Container.types";
|
|
2
|
-
import { A_Scope } from "../A-Scope/A-Scope.class";
|
|
3
2
|
import { A_TYPES__Required } from "@adaas/a-utils";
|
|
4
3
|
import { A_Feature } from "../A-Feature/A-Feature.class";
|
|
5
|
-
import { A_CONTAINER_Storage, A_CONTAINER_STORAGE__Definition__Lifecycle } from "@adaas/a-concept/storage/A_Container.storage";
|
|
6
|
-
import { A_COMPONENT_Storage } from "@adaas/a-concept/storage/A_Component.storage";
|
|
7
|
-
import { A_TYPES__FeatureStep } from "../A-Feature/A-Feature.types";
|
|
8
4
|
import { A_Context } from "../A-Context/A-Context.class";
|
|
9
|
-
import {
|
|
5
|
+
import { A_Scope } from "../A-Scope/A-Scope.class";
|
|
10
6
|
|
|
11
7
|
|
|
12
8
|
|
|
@@ -41,6 +37,10 @@ export class A_Container<
|
|
|
41
37
|
return this.config.name || this.constructor.name;
|
|
42
38
|
}
|
|
43
39
|
|
|
40
|
+
get Scope(): A_Scope {
|
|
41
|
+
return A_Context.scope(this);
|
|
42
|
+
}
|
|
43
|
+
|
|
44
44
|
|
|
45
45
|
constructor(
|
|
46
46
|
/**
|
|
@@ -53,10 +53,7 @@ export class A_Container<
|
|
|
53
53
|
const components = config.components || [];
|
|
54
54
|
const fragments = config.fragments || [];
|
|
55
55
|
|
|
56
|
-
A_Context.allocate(this,
|
|
57
|
-
components,
|
|
58
|
-
fragments
|
|
59
|
-
});
|
|
56
|
+
A_Context.allocate(this, config);
|
|
60
57
|
|
|
61
58
|
/**
|
|
62
59
|
* Run Async Initialization
|
|
@@ -105,20 +102,20 @@ export class A_Container<
|
|
|
105
102
|
* @param lifecycleMethod
|
|
106
103
|
* @param args
|
|
107
104
|
*/
|
|
108
|
-
call(
|
|
105
|
+
async call(
|
|
109
106
|
/**
|
|
110
107
|
* A-Feature method name to be called
|
|
111
108
|
*/
|
|
112
109
|
feature: _FeatureNames[number],
|
|
113
|
-
):
|
|
114
|
-
call(
|
|
110
|
+
): Promise<any>
|
|
111
|
+
async call(
|
|
115
112
|
/**
|
|
116
113
|
* A-Feature name to be called
|
|
117
114
|
*/
|
|
118
115
|
params: A_TYPES__Required<Partial<A_TYPES__ContainerCallParams<_FeatureNames[number]>>, ['name']>,
|
|
119
|
-
):
|
|
116
|
+
): Promise<any>
|
|
120
117
|
|
|
121
|
-
call(
|
|
118
|
+
async call(
|
|
122
119
|
/**
|
|
123
120
|
* A-Feature method name to be called
|
|
124
121
|
*/
|
|
@@ -127,37 +124,23 @@ export class A_Container<
|
|
|
127
124
|
* Parameters to provide additional data to the feature
|
|
128
125
|
*/
|
|
129
126
|
params: Partial<A_TYPES__ContainerCallParams<_FeatureNames[number]>>,
|
|
130
|
-
):
|
|
127
|
+
): Promise<any>
|
|
131
128
|
|
|
132
|
-
call(
|
|
129
|
+
async call(
|
|
133
130
|
param1: _FeatureNames[number] | A_TYPES__Required<Partial<A_TYPES__ContainerCallParams<_FeatureNames[number]>>, ['name']>,
|
|
134
131
|
param2?: Partial<A_TYPES__ContainerCallParams<_FeatureNames[number]>>
|
|
135
|
-
):
|
|
136
|
-
|
|
137
|
-
let feature: string;
|
|
138
|
-
let params: Partial<A_TYPES__ContainerCallParams<_FeatureNames[number]>>;
|
|
139
|
-
|
|
140
|
-
if (typeof param1 === 'string') {
|
|
141
|
-
feature = param1;
|
|
142
|
-
params = param2 || {};
|
|
143
|
-
} else {
|
|
144
|
-
feature = param1.name;
|
|
145
|
-
params = param1;
|
|
146
|
-
}
|
|
147
|
-
|
|
148
|
-
const meta = A_Context.meta(this);
|
|
132
|
+
): Promise<any> {
|
|
149
133
|
|
|
150
|
-
const
|
|
134
|
+
const feature: string = typeof param1 === 'string'
|
|
135
|
+
? param1
|
|
136
|
+
: param1.name;
|
|
137
|
+
const params: Partial<A_TYPES__ContainerCallParams<_FeatureNames[number]>> = typeof param1 === 'string'
|
|
138
|
+
? param2 || {}
|
|
139
|
+
: param1;
|
|
151
140
|
|
|
152
|
-
const newFeature =
|
|
153
|
-
name: `${this.constructor.name}.${feature}`,
|
|
154
|
-
fragments: param2?.fragments || [],
|
|
155
|
-
components: param2?.components || [],
|
|
156
|
-
steps,
|
|
157
|
-
parent: A_Context.scope(this)
|
|
158
|
-
});
|
|
141
|
+
const newFeature = A_Context.feature(this, feature, params);
|
|
159
142
|
|
|
160
|
-
return newFeature;
|
|
143
|
+
return await newFeature.process();
|
|
161
144
|
}
|
|
162
145
|
|
|
163
146
|
|
|
@@ -13,68 +13,4 @@ import {
|
|
|
13
13
|
export class A_ContainerMeta extends A_Meta<A_TYPES__ContainerMeta> {
|
|
14
14
|
|
|
15
15
|
|
|
16
|
-
feature<T extends string>(
|
|
17
|
-
container: A_Container<any>,
|
|
18
|
-
name: T,
|
|
19
|
-
// params:
|
|
20
|
-
) {
|
|
21
|
-
const scope = A_Context.scope(container);
|
|
22
|
-
|
|
23
|
-
// First lets validate that there'are registered method with the same name
|
|
24
|
-
const featureMeta = this.get(A_TYPES__ContainerMetaKey.FEATURES);
|
|
25
|
-
|
|
26
|
-
if (!featureMeta) {
|
|
27
|
-
throw new Error(`Container ${container.constructor.name} has no metadata defined`);
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
const instruction = featureMeta.get(name);
|
|
31
|
-
|
|
32
|
-
if (!instruction)
|
|
33
|
-
throw new Error(`Method ${name} is not defined in ${this.constructor.name}`);
|
|
34
|
-
|
|
35
|
-
// const scope = new A_Scope({
|
|
36
|
-
// name: `${this.constructor.name}.${feature}`,
|
|
37
|
-
// fragments: param2?.fragments || [],
|
|
38
|
-
// components: param2?.components || []
|
|
39
|
-
// }, {
|
|
40
|
-
// parent: this.scope
|
|
41
|
-
// });
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
// Now we need to resolve the method from all registered components
|
|
45
|
-
return scope
|
|
46
|
-
.components
|
|
47
|
-
.reduce((
|
|
48
|
-
acc, component
|
|
49
|
-
) => {
|
|
50
|
-
const componentMeta = A_Context.meta(component);
|
|
51
|
-
|
|
52
|
-
const extensions = componentMeta.get(A_TYPES__ComponentMetaKey.EXTENSIONS) || [];
|
|
53
|
-
const injections = componentMeta.get(A_TYPES__ComponentMetaKey.INJECTIONS);
|
|
54
|
-
|
|
55
|
-
const out: A_TYPES__FeatureStep[] = [];
|
|
56
|
-
|
|
57
|
-
extensions.forEach((extension, handler) => {
|
|
58
|
-
if (
|
|
59
|
-
extension.name === name
|
|
60
|
-
&&
|
|
61
|
-
(extension.container === container.constructor.name || extension.container === '*')
|
|
62
|
-
) {
|
|
63
|
-
const args = injections?.get(handler) || [];
|
|
64
|
-
|
|
65
|
-
out.push({
|
|
66
|
-
component,
|
|
67
|
-
handler,
|
|
68
|
-
args
|
|
69
|
-
});
|
|
70
|
-
}
|
|
71
|
-
});
|
|
72
|
-
|
|
73
|
-
return [
|
|
74
|
-
...acc,
|
|
75
|
-
...out
|
|
76
|
-
];
|
|
77
|
-
|
|
78
|
-
}, [] as A_TYPES__FeatureStep[])
|
|
79
|
-
}
|
|
80
16
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { A_CommonHelper, A_Polyfills
|
|
1
|
+
import { A_CommonHelper, A_Polyfills } from "@adaas/a-utils";
|
|
2
2
|
import { A_Component } from "../A-Component/A-Component.class";
|
|
3
3
|
import { A_Fragment } from "../A-Fragment/A-Fragment.class";
|
|
4
4
|
import { A_Feature } from "../A-Feature/A-Feature.class";
|
|
@@ -9,6 +9,10 @@ import { A_Meta } from "../A-Meta/A-Meta.class";
|
|
|
9
9
|
import { A_ComponentMeta } from "../A-Component/A-Component.meta";
|
|
10
10
|
import { A_ContainerMeta } from "../A-Container/A-Container.meta";
|
|
11
11
|
import { A_Concept } from "../A-Concept/A_Concept.class";
|
|
12
|
+
import { A_TYPES__EntityBaseMethod } from "../A-Entity/A-Entity.types";
|
|
13
|
+
import { A_Entity } from "../A-Entity/A-Entity.class";
|
|
14
|
+
import { A_EntityMeta } from "../A-Entity/A-Entity.meta";
|
|
15
|
+
import { A_TYPES__FeatureStep } from "../A-Feature/A-Feature.types";
|
|
12
16
|
|
|
13
17
|
|
|
14
18
|
/**
|
|
@@ -38,6 +42,21 @@ export class A_Context {
|
|
|
38
42
|
protected concepts: WeakMap<A_Concept<any>, A_Scope> = new WeakMap();
|
|
39
43
|
|
|
40
44
|
|
|
45
|
+
/**
|
|
46
|
+
* Uses to store the scope of every element in the program.
|
|
47
|
+
*/
|
|
48
|
+
protected registry: WeakMap<
|
|
49
|
+
A_Concept<any> |
|
|
50
|
+
A_Container<any> |
|
|
51
|
+
A_Feature |
|
|
52
|
+
A_Component |
|
|
53
|
+
A_Fragment |
|
|
54
|
+
A_Entity,
|
|
55
|
+
A_Scope
|
|
56
|
+
> = new WeakMap();
|
|
57
|
+
|
|
58
|
+
|
|
59
|
+
|
|
41
60
|
|
|
42
61
|
/**
|
|
43
62
|
* A set of allocated scopes per every element in the program.
|
|
@@ -46,7 +65,11 @@ export class A_Context {
|
|
|
46
65
|
|
|
47
66
|
protected conceptsMeta: Map<typeof A_Concept.constructor, A_Meta<any>> = new Map();
|
|
48
67
|
protected containersMeta: Map<typeof A_Container.constructor, A_ContainerMeta> = new Map();
|
|
49
|
-
protected componentsMeta: Map<typeof
|
|
68
|
+
protected componentsMeta: Map<typeof A_Component, A_ComponentMeta> = new Map();
|
|
69
|
+
protected entitiesMeta: Map<typeof A_Entity.constructor, A_EntityMeta> = new Map();
|
|
70
|
+
|
|
71
|
+
// uses to allow to store custom meta data
|
|
72
|
+
protected customMeta: Map<typeof A_Container.constructor, A_Meta<any>> = new Map();
|
|
50
73
|
|
|
51
74
|
|
|
52
75
|
/**
|
|
@@ -141,6 +164,9 @@ export class A_Context {
|
|
|
141
164
|
static meta(
|
|
142
165
|
container: A_Container<any>,
|
|
143
166
|
): A_ContainerMeta
|
|
167
|
+
static meta(
|
|
168
|
+
entity: A_Entity,
|
|
169
|
+
): A_ContainerMeta
|
|
144
170
|
static meta(
|
|
145
171
|
component: typeof A_Component,
|
|
146
172
|
): A_ComponentMeta
|
|
@@ -151,14 +177,13 @@ export class A_Context {
|
|
|
151
177
|
component: { new(...args: any[]): any },
|
|
152
178
|
): A_Meta<T>
|
|
153
179
|
static meta<T extends Record<string, any>>(
|
|
154
|
-
param1: typeof A_Container | A_Container<any> | { new(...args: any[]): any } | A_Component | typeof A_Component
|
|
180
|
+
param1: typeof A_Container | A_Container<any> | { new(...args: any[]): any } | A_Component | typeof A_Component | typeof A_Entity | A_Entity
|
|
155
181
|
): A_ContainerMeta | A_ComponentMeta | A_Meta<T> {
|
|
156
182
|
const instance = this.getInstance();
|
|
157
183
|
|
|
158
184
|
let metaStorage: WeakMap<typeof A_Container.constructor, A_Meta<any>>;
|
|
159
185
|
let property: Function;
|
|
160
|
-
|
|
161
|
-
let meta: A_Meta<any>;
|
|
186
|
+
let metaType: typeof A_Meta<T> | typeof A_ContainerMeta | typeof A_ComponentMeta | typeof A_EntityMeta
|
|
162
187
|
|
|
163
188
|
|
|
164
189
|
switch (true) {
|
|
@@ -166,14 +191,7 @@ export class A_Context {
|
|
|
166
191
|
|
|
167
192
|
metaStorage = instance.containersMeta;
|
|
168
193
|
property = param1.constructor;
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
if (!metaStorage.has(property)) {
|
|
172
|
-
const inheritMeta = metaStorage.get(Object.getPrototypeOf(property)) || new A_ContainerMeta();
|
|
173
|
-
metaStorage.set(property, new A_ContainerMeta().from(inheritMeta));
|
|
174
|
-
}
|
|
175
|
-
|
|
176
|
-
meta = metaStorage.get(property)!;
|
|
194
|
+
metaType = A_ContainerMeta;
|
|
177
195
|
|
|
178
196
|
break;
|
|
179
197
|
}
|
|
@@ -181,13 +199,7 @@ export class A_Context {
|
|
|
181
199
|
case A_CommonHelper.isInheritedFrom(param1, A_Container): {
|
|
182
200
|
metaStorage = instance.containersMeta;
|
|
183
201
|
property = param1 as typeof A_Container<any>;
|
|
184
|
-
|
|
185
|
-
if (!metaStorage.has(property)) {
|
|
186
|
-
const inheritMeta = metaStorage.get(Object.getPrototypeOf(property)) || new A_ContainerMeta();
|
|
187
|
-
metaStorage.set(property, new A_ContainerMeta().from(inheritMeta));
|
|
188
|
-
}
|
|
189
|
-
|
|
190
|
-
meta = metaStorage.get(property)!;
|
|
202
|
+
metaType = A_ContainerMeta;
|
|
191
203
|
|
|
192
204
|
break;
|
|
193
205
|
}
|
|
@@ -195,14 +207,7 @@ export class A_Context {
|
|
|
195
207
|
case param1 instanceof A_Component: {
|
|
196
208
|
metaStorage = instance.componentsMeta;
|
|
197
209
|
property = param1.constructor;
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
if (!metaStorage.has(property)) {
|
|
201
|
-
const inheritMeta = metaStorage.get(Object.getPrototypeOf(property)) || new A_ComponentMeta();
|
|
202
|
-
metaStorage.set(property, new A_ComponentMeta().from(inheritMeta));
|
|
203
|
-
}
|
|
204
|
-
|
|
205
|
-
meta = metaStorage.get(property)!;
|
|
210
|
+
metaType = A_ComponentMeta;
|
|
206
211
|
|
|
207
212
|
break;
|
|
208
213
|
}
|
|
@@ -210,55 +215,63 @@ export class A_Context {
|
|
|
210
215
|
case A_CommonHelper.isInheritedFrom(param1, A_Component): {
|
|
211
216
|
metaStorage = instance.componentsMeta;
|
|
212
217
|
property = param1 as typeof A_Component;
|
|
218
|
+
metaType = A_ComponentMeta;
|
|
213
219
|
|
|
220
|
+
break;
|
|
221
|
+
}
|
|
214
222
|
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
223
|
+
case param1 instanceof A_Entity: {
|
|
224
|
+
metaStorage = instance.entitiesMeta;
|
|
225
|
+
property = param1.constructor;
|
|
226
|
+
metaType = A_ComponentMeta;
|
|
219
227
|
|
|
220
|
-
|
|
228
|
+
break;
|
|
229
|
+
}
|
|
221
230
|
|
|
231
|
+
case A_CommonHelper.isInheritedFrom(param1, A_Entity): {
|
|
232
|
+
metaStorage = instance.entitiesMeta;
|
|
233
|
+
property = param1 as typeof A_Entity;
|
|
234
|
+
metaType = A_EntityMeta;
|
|
222
235
|
break;
|
|
223
236
|
}
|
|
224
237
|
|
|
238
|
+
|
|
225
239
|
default: {
|
|
226
|
-
metaStorage = instance.
|
|
240
|
+
metaStorage = instance.customMeta;
|
|
227
241
|
property = typeof (param1 as any) === 'function' ? param1 : param1.constructor;
|
|
228
|
-
|
|
229
|
-
if (!metaStorage.has(property)) {
|
|
230
|
-
const inheritMeta = metaStorage.get(Object.getPrototypeOf(property)) || new A_Meta();
|
|
231
|
-
metaStorage.set(property, new A_Meta().from(inheritMeta));
|
|
232
|
-
}
|
|
233
|
-
|
|
234
|
-
meta = metaStorage.get(property)!;
|
|
242
|
+
metaType = A_Meta;
|
|
235
243
|
|
|
236
244
|
break;
|
|
237
245
|
}
|
|
238
246
|
}
|
|
239
247
|
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
248
|
+
if (!metaStorage.has(property)) {
|
|
249
|
+
const inheritMeta = metaStorage.get(Object.getPrototypeOf(property)) || new metaType();
|
|
250
|
+
metaStorage.set(property, new metaType().from(inheritMeta as any));
|
|
251
|
+
}
|
|
243
252
|
|
|
244
|
-
return
|
|
253
|
+
return metaStorage.get(property)!;
|
|
245
254
|
}
|
|
246
255
|
|
|
247
256
|
|
|
248
257
|
|
|
249
|
-
|
|
250
|
-
|
|
258
|
+
static scope(
|
|
259
|
+
entity: A_Entity
|
|
260
|
+
): A_Scope
|
|
261
|
+
static scope(
|
|
262
|
+
component: A_Component
|
|
263
|
+
): A_Scope
|
|
251
264
|
static scope(
|
|
252
265
|
concept: A_Concept
|
|
253
266
|
): A_Scope
|
|
254
267
|
static scope(
|
|
255
|
-
|
|
268
|
+
container: A_Container<any>
|
|
256
269
|
): A_Scope
|
|
257
270
|
static scope(
|
|
258
|
-
|
|
271
|
+
feature: A_Feature
|
|
259
272
|
): A_Scope
|
|
260
273
|
static scope(
|
|
261
|
-
param1: A_Feature | A_Container<any> | A_Concept
|
|
274
|
+
param1: A_Feature | A_Container<any> | A_Concept | A_Component<any> | A_Entity
|
|
262
275
|
): A_Scope | undefined {
|
|
263
276
|
|
|
264
277
|
const instance = this.getInstance();
|
|
@@ -270,62 +283,209 @@ export class A_Context {
|
|
|
270
283
|
case param1 instanceof A_Feature:
|
|
271
284
|
return instance.features.get(param1);
|
|
272
285
|
|
|
273
|
-
|
|
274
286
|
case param1 instanceof A_Concept:
|
|
275
287
|
return instance.concepts.get(param1);
|
|
276
288
|
|
|
289
|
+
case param1 instanceof A_Entity:
|
|
290
|
+
return instance.registry.get(param1);
|
|
291
|
+
|
|
292
|
+
case param1 instanceof A_Component:
|
|
293
|
+
return instance.registry.get(param1);
|
|
294
|
+
|
|
295
|
+
case param1 instanceof A_Fragment:
|
|
296
|
+
return instance.registry.get(param1);
|
|
297
|
+
|
|
277
298
|
default:
|
|
278
299
|
throw new Error(`[!] A-Concept Context: Unknown type of the parameter.`);
|
|
279
300
|
}
|
|
280
301
|
}
|
|
281
302
|
|
|
282
303
|
|
|
304
|
+
/**
|
|
305
|
+
* This method returns a component by its meta.
|
|
306
|
+
*
|
|
307
|
+
* @param meta
|
|
308
|
+
* @returns
|
|
309
|
+
*/
|
|
310
|
+
static component(
|
|
311
|
+
meta: A_ComponentMeta
|
|
312
|
+
): typeof A_Component {
|
|
313
|
+
const instance = this.getInstance();
|
|
314
|
+
|
|
315
|
+
let component: typeof A_Component | undefined;
|
|
316
|
+
|
|
317
|
+
instance.componentsMeta.forEach((meta, constructor) => {
|
|
318
|
+
if (meta === meta) {
|
|
319
|
+
component = constructor;
|
|
320
|
+
}
|
|
321
|
+
});
|
|
322
|
+
|
|
323
|
+
if (!component) {
|
|
324
|
+
throw new Error(`[!] A-Concept Context: Component not found.`);
|
|
325
|
+
}
|
|
326
|
+
return component;
|
|
327
|
+
}
|
|
328
|
+
|
|
329
|
+
|
|
330
|
+
|
|
331
|
+
/**
|
|
332
|
+
* This method returns a step-by-step instructions of feature implementation depending on the feature name and the class.
|
|
333
|
+
*
|
|
334
|
+
* @param scope
|
|
335
|
+
* @returns
|
|
336
|
+
*/
|
|
337
|
+
static feature<T extends Array<string>>(
|
|
338
|
+
entity: A_Entity<any, any, T>,
|
|
339
|
+
feature: A_TYPES__EntityBaseMethod | string | T[number] | RegExp,
|
|
340
|
+
params?: Partial<A_TYPES__ScopeConstructor>
|
|
341
|
+
): A_Feature
|
|
342
|
+
static feature<T extends Array<string>>(
|
|
343
|
+
container: A_Container<T>,
|
|
344
|
+
feature: T[number],
|
|
345
|
+
params?: Partial<A_TYPES__ScopeConstructor>
|
|
346
|
+
): A_Feature
|
|
347
|
+
static feature(
|
|
348
|
+
component: A_Component,
|
|
349
|
+
feature: string,
|
|
350
|
+
params?: Partial<A_TYPES__ScopeConstructor>
|
|
351
|
+
): A_Feature
|
|
352
|
+
static feature<T extends Array<string>>(
|
|
353
|
+
param1: A_Component<T> | A_Container<T> | A_Entity<any, any, T>,
|
|
354
|
+
param2: string | T[number],
|
|
355
|
+
param3?: Partial<A_TYPES__ScopeConstructor>
|
|
356
|
+
): A_Feature {
|
|
357
|
+
|
|
358
|
+
|
|
359
|
+
const instance = this.getInstance();
|
|
360
|
+
|
|
361
|
+
const component = param1;
|
|
362
|
+
const feature: string = param2;
|
|
363
|
+
const config = param3 || {};
|
|
364
|
+
// TODO: have no idea why it's not working because of that "any"
|
|
365
|
+
const scope = this.scope(component as any);
|
|
366
|
+
const steps: A_TYPES__FeatureStep[] = [];
|
|
367
|
+
|
|
368
|
+
// Now we need to resolve the method from all registered components
|
|
369
|
+
|
|
370
|
+
// We need to get all components that has extensions for the feature in component
|
|
371
|
+
instance.componentsMeta
|
|
372
|
+
.forEach((meta, constructor) => {
|
|
373
|
+
try {
|
|
374
|
+
// Just try to make sure that component not only Indexed but also presented in scope
|
|
375
|
+
scope.resolve(constructor);
|
|
376
|
+
|
|
377
|
+
// Get all extensions for the feature
|
|
378
|
+
meta
|
|
379
|
+
.extensions(feature)
|
|
380
|
+
.forEach(({ handler, args }) => {
|
|
381
|
+
steps.push({
|
|
382
|
+
component: constructor,
|
|
383
|
+
handler,
|
|
384
|
+
args
|
|
385
|
+
});
|
|
386
|
+
});
|
|
387
|
+
|
|
388
|
+
} catch (error) {
|
|
389
|
+
// do nothing
|
|
390
|
+
}
|
|
391
|
+
});
|
|
392
|
+
|
|
393
|
+
const newFeature = new A_Feature({
|
|
394
|
+
name: `${component.constructor.name}.${feature}`,
|
|
395
|
+
fragments: config.fragments,
|
|
396
|
+
components: config.components,
|
|
397
|
+
steps,
|
|
398
|
+
parent: component instanceof A_Container ? this.scope(component) : undefined
|
|
399
|
+
});
|
|
400
|
+
|
|
401
|
+
return newFeature;
|
|
402
|
+
}
|
|
403
|
+
|
|
404
|
+
|
|
283
405
|
|
|
284
406
|
/**
|
|
285
407
|
* Register a Namespace in the provider.
|
|
286
408
|
* @param Namespace
|
|
287
409
|
*/
|
|
288
|
-
static register(Namespace: A_Fragment): string
|
|
289
410
|
static register(
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
)
|
|
411
|
+
scope: A_Scope,
|
|
412
|
+
container: A_Container<any>
|
|
413
|
+
)
|
|
414
|
+
static register(
|
|
415
|
+
scope: A_Scope,
|
|
416
|
+
entity: A_Entity
|
|
417
|
+
)
|
|
418
|
+
static register(
|
|
419
|
+
scope: A_Scope,
|
|
420
|
+
component: A_Component
|
|
421
|
+
)
|
|
422
|
+
static register(
|
|
423
|
+
scope: A_Scope,
|
|
424
|
+
fragment: A_Fragment
|
|
425
|
+
)
|
|
293
426
|
static register(
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
)
|
|
427
|
+
scope: A_Scope,
|
|
428
|
+
param1: A_Fragment | A_Container<any> | A_Entity | A_Component,
|
|
429
|
+
) {
|
|
297
430
|
|
|
298
431
|
const instance = this.getInstance();
|
|
299
432
|
|
|
300
|
-
|
|
301
|
-
|
|
433
|
+
switch (true) {
|
|
434
|
+
case param1 instanceof A_Component:
|
|
435
|
+
instance.registry.set(param1, scope);
|
|
436
|
+
break;
|
|
437
|
+
|
|
438
|
+
case param1 instanceof A_Container:
|
|
439
|
+
instance.registry.set(param1, scope);
|
|
440
|
+
break;
|
|
441
|
+
|
|
442
|
+
case param1 instanceof A_Entity:
|
|
443
|
+
instance.registry.set(param1, scope);
|
|
444
|
+
break;
|
|
445
|
+
|
|
446
|
+
case param1 instanceof A_Fragment:
|
|
447
|
+
instance.registry.set(param1, scope);
|
|
448
|
+
break;
|
|
449
|
+
|
|
450
|
+
default:
|
|
451
|
+
instance.registry.set(param1, scope);
|
|
302
452
|
|
|
303
|
-
if (typeof param2 === 'string') {
|
|
304
|
-
name = param2;
|
|
305
|
-
fragment = param1;
|
|
306
|
-
} else {
|
|
307
|
-
fragment = param1 as A_Fragment;
|
|
308
|
-
name = fragment.name;
|
|
309
453
|
}
|
|
310
454
|
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
455
|
+
|
|
456
|
+
// if (param1 instanceof A_Fragment) {
|
|
457
|
+
|
|
458
|
+
// const instance = this.getInstance();
|
|
459
|
+
|
|
460
|
+
// let fragment: A_Fragment;
|
|
461
|
+
// let name: string;
|
|
462
|
+
|
|
463
|
+
// if (typeof param2 === 'string') {
|
|
464
|
+
// name = param2;
|
|
465
|
+
// fragment = param1;
|
|
466
|
+
// } else {
|
|
467
|
+
// fragment = param1 as A_Fragment;
|
|
468
|
+
// name = fragment.name;
|
|
469
|
+
// }
|
|
470
|
+
|
|
471
|
+
// /**
|
|
472
|
+
// * If the namespace is not provided, then use the root namespace.
|
|
473
|
+
// * If the root namespace is not provided, then use the default namespace.
|
|
474
|
+
// */
|
|
475
|
+
// if (!name)
|
|
476
|
+
// name = this.root
|
|
477
|
+
// || process.env.ADAAS_NAMESPACE
|
|
478
|
+
// || process.env.A_NAMESPACE
|
|
479
|
+
// || process.env.ADAAS_APP_NAMESPACE
|
|
480
|
+
// || 'a-concept'
|
|
321
481
|
|
|
322
482
|
|
|
483
|
+
// if (!this.root)
|
|
484
|
+
// instance._root = name;
|
|
323
485
|
|
|
324
|
-
|
|
325
|
-
instance._root = name;
|
|
486
|
+
// // instance.namedFragments.set(namespace, Namespace);
|
|
326
487
|
|
|
327
|
-
//
|
|
488
|
+
// return name;
|
|
328
489
|
|
|
329
|
-
return name;
|
|
330
490
|
}
|
|
331
491
|
}
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import { A_Scope } from "../A-Scope/A-Scope.class"
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
export type A_TYPES__ContextExecutionPipeline = {
|
|
6
|
-
scope: A_Scope
|
|
7
|
-
steps: A_TYPES__ContextExecutionPipelineStep[]
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
export type A_TYPES__ContextExecutionPipelineStep = {
|
|
12
|
-
component: { new(...args: any[]): any },
|
|
13
|
-
handler: string,
|
|
14
|
-
args: any[]
|
|
15
|
-
}
|