@adaas/a-concept 0.0.5 → 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.
Files changed (121) hide show
  1. package/dist/examples/simple/components/A.component.d.ts +4 -2
  2. package/dist/examples/simple/components/A.component.js +7 -4
  3. package/dist/examples/simple/components/A.component.js.map +1 -1
  4. package/dist/examples/simple/components/B.component.d.ts +6 -2
  5. package/dist/examples/simple/components/B.component.js +18 -7
  6. package/dist/examples/simple/components/B.component.js.map +1 -1
  7. package/dist/examples/simple/concept.js +59 -32
  8. package/dist/examples/simple/concept.js.map +1 -1
  9. package/dist/examples/simple/containers/Main.container.d.ts +1 -2
  10. package/dist/examples/simple/containers/Main.container.js +18 -5
  11. package/dist/examples/simple/containers/Main.container.js.map +1 -1
  12. package/dist/examples/simple-http-server/components/http-error-handler.component.d.ts +2 -1
  13. package/dist/examples/simple-http-server/components/http-error-handler.component.js +3 -1
  14. package/dist/examples/simple-http-server/components/http-error-handler.component.js.map +1 -1
  15. package/dist/examples/simple-http-server/components/http-request-handler.component.d.ts +2 -1
  16. package/dist/examples/simple-http-server/components/http-request-handler.component.js +2 -1
  17. package/dist/examples/simple-http-server/components/http-request-handler.component.js.map +1 -1
  18. package/dist/examples/simple-http-server/containers/http-server.container.d.ts +1 -2
  19. package/dist/index.d.ts +5 -1
  20. package/dist/index.js +10 -2
  21. package/dist/index.js.map +1 -1
  22. package/dist/src/base/A-Config/A-Config.container.d.ts +1 -3
  23. package/dist/src/base/A-Config/A-Config.container.js +6 -22
  24. package/dist/src/base/A-Config/A-Config.container.js.map +1 -1
  25. package/dist/src/base/A-Config/A-Config.context.d.ts +1 -0
  26. package/dist/src/base/A-Config/A-Config.context.js +20 -2
  27. package/dist/src/base/A-Config/A-Config.context.js.map +1 -1
  28. package/dist/src/base/A-Config/A-Config.types.d.ts +2 -2
  29. package/dist/src/base/A-Config/components/ConfigReader.component.d.ts +2 -1
  30. package/dist/src/base/A-Config/components/ConfigReader.component.js +3 -1
  31. package/dist/src/base/A-Config/components/ConfigReader.component.js.map +1 -1
  32. package/dist/src/base/A-Errors/A-Errors.component.d.ts +2 -1
  33. package/dist/src/base/A-Errors/A-Errors.component.js +3 -1
  34. package/dist/src/base/A-Errors/A-Errors.component.js.map +1 -1
  35. package/dist/src/base/A-Logger/A-Logger.component.d.ts +4 -2
  36. package/dist/src/base/A-Logger/A-Logger.component.js +11 -3
  37. package/dist/src/base/A-Logger/A-Logger.component.js.map +1 -1
  38. package/dist/src/decorators/A-Feature/A-Feature-Define.decorator.js.map +1 -1
  39. package/dist/src/decorators/A-Feature/A-Feature-Extend.decorator.js +9 -9
  40. package/dist/src/decorators/A-Feature/A-Feature-Extend.decorator.js.map +1 -1
  41. package/dist/src/decorators/A-Inject/A-Inject.decorator.d.ts +0 -2
  42. package/dist/src/decorators/A-Inject/A-Inject.decorator.js +4 -2
  43. package/dist/src/decorators/A-Inject/A-Inject.decorator.js.map +1 -1
  44. package/dist/src/global/A-Component/A-Component.class.d.ts +28 -1
  45. package/dist/src/global/A-Component/A-Component.class.js +22 -0
  46. package/dist/src/global/A-Component/A-Component.class.js.map +1 -1
  47. package/dist/src/global/A-Component/A-Component.meta.d.ts +8 -1
  48. package/dist/src/global/A-Component/A-Component.meta.js +26 -0
  49. package/dist/src/global/A-Component/A-Component.meta.js.map +1 -1
  50. package/dist/src/global/A-Component/A-Component.types.d.ts +43 -6
  51. package/dist/src/global/A-Component/A-Component.types.js +5 -0
  52. package/dist/src/global/A-Component/A-Component.types.js.map +1 -1
  53. package/dist/src/global/A-Concept/A_Concept.class.d.ts +7 -7
  54. package/dist/src/global/A-Concept/A_Concept.class.js +1 -2
  55. package/dist/src/global/A-Concept/A_Concept.class.js.map +1 -1
  56. package/dist/src/global/A-Container/A-Container.class.d.ts +5 -4
  57. package/dist/src/global/A-Container/A-Container.class.js +13 -24
  58. package/dist/src/global/A-Container/A-Container.class.js.map +1 -1
  59. package/dist/src/global/A-Container/A-Container.meta.d.ts +0 -3
  60. package/dist/src/global/A-Container/A-Container.meta.js +0 -46
  61. package/dist/src/global/A-Container/A-Container.meta.js.map +1 -1
  62. package/dist/src/global/A-Context/A-Context.class.d.ts +34 -5
  63. package/dist/src/global/A-Context/A-Context.class.js +135 -53
  64. package/dist/src/global/A-Context/A-Context.class.js.map +1 -1
  65. package/dist/src/global/A-Context/A-Context.types.d.ts +0 -12
  66. package/dist/src/global/A-Context/A-Context.types.js +0 -1
  67. package/dist/src/global/A-Entity/A-Entity.class.d.ts +28 -4
  68. package/dist/src/global/A-Entity/A-Entity.class.js +23 -3
  69. package/dist/src/global/A-Entity/A-Entity.class.js.map +1 -1
  70. package/dist/src/global/A-Entity/A-Entity.meta.d.ts +4 -0
  71. package/dist/src/global/A-Entity/A-Entity.meta.js +8 -0
  72. package/dist/src/global/A-Entity/A-Entity.meta.js.map +1 -0
  73. package/dist/src/global/A-Entity/A-Entity.types.d.ts +43 -0
  74. package/dist/src/global/A-Entity/A-Entity.types.js +13 -0
  75. package/dist/src/global/A-Entity/A-Entity.types.js.map +1 -1
  76. package/dist/src/global/A-Feature/A-Feature.class.d.ts +11 -1
  77. package/dist/src/global/A-Feature/A-Feature.class.js +48 -12
  78. package/dist/src/global/A-Feature/A-Feature.class.js.map +1 -1
  79. package/dist/src/global/A-Feature/A-Feature.types.d.ts +5 -4
  80. package/dist/src/global/A-Feature/A-Feature.types.js.map +1 -1
  81. package/dist/src/global/A-Fragment/A-Fragment.class.js +1 -2
  82. package/dist/src/global/A-Fragment/A-Fragment.class.js.map +1 -1
  83. package/dist/src/global/A-Meta/A-Meta.class.d.ts +75 -1
  84. package/dist/src/global/A-Meta/A-Meta.class.js +100 -10
  85. package/dist/src/global/A-Meta/A-Meta.class.js.map +1 -1
  86. package/dist/src/global/A-Scope/A-Scope.class.d.ts +15 -6
  87. package/dist/src/global/A-Scope/A-Scope.class.js +59 -17
  88. package/dist/src/global/A-Scope/A-Scope.class.js.map +1 -1
  89. package/examples/simple/components/A.component.ts +6 -3
  90. package/examples/simple/components/B.component.ts +19 -6
  91. package/examples/simple/concept.ts +65 -33
  92. package/examples/simple/containers/Main.container.ts +28 -7
  93. package/examples/simple-http-server/components/http-error-handler.component.ts +5 -2
  94. package/examples/simple-http-server/components/http-request-handler.component.ts +3 -1
  95. package/index.ts +6 -1
  96. package/package.json +1 -1
  97. package/src/base/A-Config/A-Config.container.ts +5 -8
  98. package/src/base/A-Config/A-Config.context.ts +10 -2
  99. package/src/base/A-Config/A-Config.types.ts +2 -2
  100. package/src/base/A-Config/components/ConfigReader.component.ts +5 -2
  101. package/src/base/A-Errors/A-Errors.component.ts +3 -2
  102. package/src/base/A-Logger/A-Logger.component.ts +21 -3
  103. package/src/decorators/A-Feature/A-Feature-Define.decorator.ts +0 -1
  104. package/src/decorators/A-Feature/A-Feature-Extend.decorator.ts +15 -10
  105. package/src/decorators/A-Inject/A-Inject.decorator.ts +13 -11
  106. package/src/global/A-Component/A-Component.class.ts +56 -1
  107. package/src/global/A-Component/A-Component.meta.ts +40 -1
  108. package/src/global/A-Component/A-Component.types.ts +51 -19
  109. package/src/global/A-Concept/A_Concept.class.ts +2 -2
  110. package/src/global/A-Container/A-Container.class.ts +22 -34
  111. package/src/global/A-Container/A-Container.meta.ts +0 -64
  112. package/src/global/A-Context/A-Context.class.ts +237 -79
  113. package/src/global/A-Context/A-Context.types.ts +0 -15
  114. package/src/global/A-Entity/A-Entity.class.ts +65 -8
  115. package/src/global/A-Entity/A-Entity.meta.ts +9 -0
  116. package/src/global/A-Entity/A-Entity.types.ts +58 -0
  117. package/src/global/A-Feature/A-Feature.class.ts +62 -20
  118. package/src/global/A-Feature/A-Feature.types.ts +8 -2
  119. package/src/global/A-Fragment/A-Fragment.class.ts +1 -5
  120. package/src/global/A-Meta/A-Meta.class.ts +114 -22
  121. package/src/global/A-Scope/A-Scope.class.ts +100 -33
@@ -1,4 +1,4 @@
1
- import { A_CommonHelper, A_Polyfills, A_TYPES__Dictionary } from "@adaas/a-utils";
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 A_Container.constructor, A_ComponentMeta> = new Map();
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,63 @@ 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
- if (!metaStorage.has(property)) {
218
- const inheritMeta = metaStorage.get(Object.getPrototypeOf(property)) || new A_ComponentMeta();
219
- metaStorage.set(property, new A_ComponentMeta().from(inheritMeta));
220
- }
223
+ case param1 instanceof A_Entity: {
224
+ metaStorage = instance.entitiesMeta;
225
+ property = param1.constructor;
226
+ metaType = A_ComponentMeta;
221
227
 
222
- meta = metaStorage.get(property)!;
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
- // const inheritMeta: T = metaStorage.get(Object.getPrototypeOf(property)) || new A_Meta() as T;
243
- // // we just know that the type of parent meta is the same as the type of the current meta
244
- // const meta = metaStorage.get(property);
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 meta!;
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
- component: A_Container<any>
268
+ container: A_Container<any>
258
269
  ): A_Scope
259
270
  static scope(
260
- component: A_Feature
271
+ feature: A_Feature
261
272
  ): A_Scope
262
273
  static scope(
263
- param1: A_Feature | A_Container<any> | A_Concept
274
+ param1: A_Feature | A_Container<any> | A_Concept | A_Component<any> | A_Entity
264
275
  ): A_Scope | undefined {
265
276
 
266
277
  const instance = this.getInstance();
@@ -272,62 +283,209 @@ export class A_Context {
272
283
  case param1 instanceof A_Feature:
273
284
  return instance.features.get(param1);
274
285
 
275
-
276
286
  case param1 instanceof A_Concept:
277
287
  return instance.concepts.get(param1);
278
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
+
279
298
  default:
280
299
  throw new Error(`[!] A-Concept Context: Unknown type of the parameter.`);
281
300
  }
282
301
  }
283
302
 
284
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
+
285
405
 
286
406
  /**
287
407
  * Register a Namespace in the provider.
288
408
  * @param Namespace
289
409
  */
290
- static register(Namespace: A_Fragment): string
291
410
  static register(
292
- Namespace: A_Fragment,
293
- namespace?: string
294
- ): string
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
+ )
295
426
  static register(
296
- param1: A_Fragment,
297
- param2?: A_Fragment | string,
298
- ): string {
427
+ scope: A_Scope,
428
+ param1: A_Fragment | A_Container<any> | A_Entity | A_Component,
429
+ ) {
299
430
 
300
431
  const instance = this.getInstance();
301
432
 
302
- let fragment: A_Fragment;
303
- let name: string;
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);
304
452
 
305
- if (typeof param2 === 'string') {
306
- name = param2;
307
- fragment = param1;
308
- } else {
309
- fragment = param1 as A_Fragment;
310
- name = fragment.name;
311
453
  }
312
454
 
313
- /**
314
- * If the namespace is not provided, then use the root namespace.
315
- * If the root namespace is not provided, then use the default namespace.
316
- */
317
- if (!name)
318
- name = this.root
319
- || process.env.ADAAS_NAMESPACE
320
- || process.env.A_NAMESPACE
321
- || process.env.ADAAS_APP_NAMESPACE
322
- || 'a-concept'
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'
323
481
 
324
482
 
483
+ // if (!this.root)
484
+ // instance._root = name;
325
485
 
326
- if (!this.root)
327
- instance._root = name;
486
+ // // instance.namedFragments.set(namespace, Namespace);
328
487
 
329
- // instance.namedFragments.set(namespace, Namespace);
488
+ // return name;
330
489
 
331
- return name;
332
490
  }
333
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
- }
@@ -1,8 +1,17 @@
1
- import { A_Error, ASEID } from "@adaas/a-utils";
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 { A_TYPES__Entity_JSON, A_TYPES__IEntity } from "./A-Entity.types";
5
- import { A_Fragment } from "../A-Fragment/A-Fragment.class";
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
+ }
@@ -0,0 +1,9 @@
1
+ import { A_Meta } from "../A-Meta/A-Meta.class";
2
+ import { A_TYPES__EntityMeta } from "./A-Entity.types";
3
+
4
+
5
+ export class A_EntityMeta extends A_Meta<A_TYPES__EntityMeta> {
6
+
7
+
8
+
9
+ }
@@ -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
+