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