@adaas/a-concept 0.0.56 → 0.0.57

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 (93) hide show
  1. package/.nvmrc +1 -1
  2. package/dist/src/base/A-Command/A_Command.constants.d.ts +12 -0
  3. package/dist/src/base/A-Command/A_Command.constants.js +17 -0
  4. package/dist/src/base/A-Command/A_Command.constants.js.map +1 -0
  5. package/dist/src/base/A-Command/A_Command.entity.d.ts +123 -0
  6. package/dist/src/base/A-Command/A_Command.entity.js +259 -0
  7. package/dist/src/base/A-Command/A_Command.entity.js.map +1 -0
  8. package/dist/src/base/A-Command/A_Command.types.d.ts +15 -0
  9. package/dist/src/base/A-Command/A_Command.types.js +3 -0
  10. package/dist/src/base/A-Command/A_Command.types.js.map +1 -0
  11. package/dist/src/base/A-Command/context/A_Command.context.d.ts +64 -0
  12. package/dist/src/base/A-Command/context/A_Command.context.js +85 -0
  13. package/dist/src/base/A-Command/context/A_Command.context.js.map +1 -0
  14. package/dist/src/base/A-Command/context/A_CommandFactory.context.js +2 -0
  15. package/dist/src/base/A-Command/context/A_CommandFactory.context.js.map +1 -0
  16. package/dist/src/base/A-Config/A-Config.context.d.ts +7 -6
  17. package/dist/src/base/A-Config/A-Config.context.js +2 -6
  18. package/dist/src/base/A-Config/A-Config.context.js.map +1 -1
  19. package/dist/src/base/A-Config/components/ConfigReader.component.js +2 -12
  20. package/dist/src/base/A-Config/components/ConfigReader.component.js.map +1 -1
  21. package/dist/src/constants/env.constants.d.ts +26 -0
  22. package/dist/src/constants/env.constants.js +40 -0
  23. package/dist/src/constants/env.constants.js.map +1 -0
  24. package/dist/src/decorators/A-Inject/A-Inject.decorator.d.ts +3 -3
  25. package/dist/src/decorators/A-Inject/A-Inject.decorator.types.d.ts +9 -10
  26. package/dist/src/global/A-Channel/A-Channel.class.d.ts +2 -0
  27. package/dist/src/global/A-Channel/A-Channel.class.js +2 -0
  28. package/dist/src/global/A-Channel/A-Channel.class.js.map +1 -1
  29. package/dist/src/global/A-Concept/A_Concept.class.d.ts +5 -3
  30. package/dist/src/global/A-Concept/A_Concept.class.js +32 -27
  31. package/dist/src/global/A-Concept/A_Concept.class.js.map +1 -1
  32. package/dist/src/global/A-Concept/A_Concept.meta.d.ts +1 -8
  33. package/dist/src/global/A-Concept/A_Concept.meta.js +1 -25
  34. package/dist/src/global/A-Concept/A_Concept.meta.js.map +1 -1
  35. package/dist/src/global/A-Concept/A_Concept.types.d.ts +10 -1
  36. package/dist/src/global/A-Container/A-Container.class.d.ts +5 -0
  37. package/dist/src/global/A-Container/A-Container.class.js +5 -0
  38. package/dist/src/global/A-Container/A-Container.class.js.map +1 -1
  39. package/dist/src/global/A-Context/A-Context.class.d.ts +19 -1
  40. package/dist/src/global/A-Context/A-Context.class.js +20 -0
  41. package/dist/src/global/A-Context/A-Context.class.js.map +1 -1
  42. package/dist/src/global/A-Entity/A-Entity.class.d.ts +124 -23
  43. package/dist/src/global/A-Entity/A-Entity.class.js +159 -49
  44. package/dist/src/global/A-Entity/A-Entity.class.js.map +1 -1
  45. package/dist/src/global/A-Scope/A-Scope.class.d.ts +7 -6
  46. package/dist/src/global/A-Scope/A-Scope.class.js +57 -20
  47. package/dist/src/global/A-Scope/A-Scope.class.js.map +1 -1
  48. package/dist/src/global/A-Stage/A-Stage.class.d.ts +3 -2
  49. package/dist/src/global/A-Stage/A-Stage.class.js +9 -6
  50. package/dist/src/global/A-Stage/A-Stage.class.js.map +1 -1
  51. package/dist/src/global/A-Stage/A-Stage.types.d.ts +1 -1
  52. package/dist/src/helpers/StepsManager.class.js +1 -1
  53. package/dist/src/helpers/StepsManager.class.js.map +1 -1
  54. package/examples/simple/components/A.component.ts +9 -2
  55. package/examples/simple/concept.ts +6 -0
  56. package/examples/simple/entities/EntityA.entity.ts +18 -0
  57. package/jest.config.ts +1 -1
  58. package/package.json +3 -3
  59. package/src/base/A-Command/A_Command.constants.ts +20 -0
  60. package/src/base/A-Command/A_Command.entity.ts +287 -0
  61. package/src/base/A-Command/A_Command.types.ts +34 -0
  62. package/src/base/A-Command/context/A_Command.context.ts +114 -0
  63. package/src/base/A-Command/context/A_CommandFactory.context.ts +0 -0
  64. package/src/base/A-Config/A-Config.context.ts +13 -17
  65. package/src/base/A-Config/components/ConfigReader.component.ts +2 -15
  66. package/src/constants/env.constants.ts +47 -0
  67. package/src/decorators/A-Inject/A-Inject.decorator.ts +3 -3
  68. package/src/decorators/A-Inject/A-Inject.decorator.types.ts +10 -9
  69. package/src/global/A-Channel/A-Channel.class.ts +2 -0
  70. package/src/global/A-Concept/A_Concept.class.ts +49 -32
  71. package/src/global/A-Concept/A_Concept.meta.ts +3 -41
  72. package/src/global/A-Concept/A_Concept.types.ts +6 -4
  73. package/src/global/A-Container/A-Container.class.ts +5 -2
  74. package/src/global/A-Context/A-Context.class.ts +44 -7
  75. package/src/global/A-Entity/A-Entity.class.ts +203 -73
  76. package/src/global/A-Scope/A-Scope.class.ts +88 -39
  77. package/src/global/A-Stage/A-Stage.class.ts +11 -7
  78. package/src/global/A-Stage/A-Stage.types.ts +1 -1
  79. package/src/helpers/StepsManager.class.ts +2 -2
  80. package/tests/A-Command.test.ts +130 -0
  81. package/tests/A-Component.test.ts +25 -0
  82. package/tests/A-Entity.test.ts +186 -0
  83. package/tests/A-Feature.test.ts +131 -0
  84. package/tests/A-Scope.test.ts +163 -0
  85. package/dist/src/constants/A_ConceptLifecycle.constants.js +0 -11
  86. package/dist/src/constants/A_ConceptLifecycle.constants.js.map +0 -1
  87. package/src/constants/A_ConceptLifecycle.constants.ts +0 -12
  88. package/tests/channel.ts +0 -213
  89. package/tests/context.test.ts +0 -124
  90. package/tests/default.test.ts +0 -159
  91. package/tests/log.ts +0 -102
  92. package/tests/polyfill.test.ts +0 -37
  93. /package/dist/src/{constants/A_ConceptLifecycle.constants.d.ts → base/A-Command/context/A_CommandFactory.context.d.ts} +0 -0
@@ -1,14 +1,10 @@
1
- import { A_TYPES__ConceptStage, A_TYPES__ConceptAbstractionCallParams, A_TYPES__IConceptConstructor, A_TYPES__ConceptAbstractionMeta } from "./A_Concept.types";
1
+ import { A_TYPES__ConceptStage, A_TYPES__IConceptConstructor } from "./A_Concept.types";
2
2
  import { A_Container } from "../A-Container/A-Container.class";
3
3
  import { A_Abstraction } from "../A-Abstraction/A-Abstraction.class";
4
4
  import { A_ConceptMeta } from "./A_Concept.meta";
5
5
  import { A_Abstraction_Extend } from "@adaas/a-concept/decorators/A-Abstraction/A-Abstraction-Extend.decorator";
6
6
  import { A_Scope } from "../A-Scope/A-Scope.class";
7
- import { A_TYPES__A_InjectDecorator_EntityInjectionInstructions, A_TYPES__A_InjectDecorator_Injectable } from "@adaas/a-concept/decorators/A-Inject/A-Inject.decorator.types";
8
-
9
-
10
- // export type RunParams<T> = T extends A_Container<any, infer Params> ? Params : never;
11
-
7
+ import { A_Context } from "../A-Context/A-Context.class";
12
8
 
13
9
 
14
10
  /**
@@ -24,7 +20,7 @@ import { A_TYPES__A_InjectDecorator_EntityInjectionInstructions, A_TYPES__A_Inje
24
20
  *
25
21
  */
26
22
  export class A_Concept<
27
- _Imports extends A_Container[] = any
23
+ _Imports extends A_Container[] = A_Container[]
28
24
  > {
29
25
 
30
26
  // ==============================================================================
@@ -85,8 +81,8 @@ export class A_Concept<
85
81
  }
86
82
 
87
83
 
88
- private sharedBase!: A_Container;
89
84
  private meta!: A_ConceptMeta
85
+ private _name!: string;
90
86
 
91
87
 
92
88
 
@@ -99,44 +95,41 @@ export class A_Concept<
99
95
  constructor(
100
96
  protected props: A_TYPES__IConceptConstructor<_Imports>
101
97
  ) {
102
- this.sharedBase = new A_Container({
103
- name: `${props.name}::base`,
104
- fragments: props.fragments || [],
105
- entities: props.entities || [],
106
- components: [
107
- // A_Logger,
108
- ],
109
- });
98
+ this._name = props.name || A_Context.root.name;
110
99
 
111
- this.containers = (props.containers || []).map(container => {
112
- container.Scope.parent(this.Scope);
113
- return container;
114
- });
100
+ if (props.components && props.components.length)
101
+ props.components.forEach(component => this.Scope.register(component))
102
+
103
+ if (props.fragments && props.fragments.length)
104
+ props.fragments.forEach(fragment => this.Scope.register(fragment))
115
105
 
116
- this.meta = new A_ConceptMeta(this.containers, this.sharedBase);
106
+ if (props.entities && props.entities.length)
107
+ props.entities.forEach(entity => this.Scope.register(entity))
108
+
109
+ this.containers = props.containers || [];
117
110
  }
118
111
 
119
112
 
120
113
  get namespace() {
121
- return this.sharedBase.name;
114
+ return A_Context.root.name;
122
115
  }
123
116
 
124
117
  get Scope() {
125
- return this.sharedBase.Scope;
118
+ return A_Context.root;
126
119
  }
127
120
 
128
121
  /**
129
122
  * Register a class or value in the concept scope.
130
123
  */
131
124
  get register(): A_Scope['register'] {
132
- return this.sharedBase.Scope.register.bind(this.sharedBase.Scope);
125
+ return this.Scope.register.bind(this.Scope);
133
126
  }
134
127
 
135
128
  /**
136
129
  * Resolve a class or value from the concept scope.
137
130
  */
138
131
  get resolve(): A_Scope['resolve'] {
139
- return this.sharedBase.Scope.resolve.bind(this.sharedBase.Scope);
132
+ return this.Scope.resolve.bind(this.Scope);
140
133
  }
141
134
 
142
135
 
@@ -153,7 +146,7 @@ export class A_Concept<
153
146
  ) {
154
147
  scope = scope ? scope.inherit(this.Scope) : this.Scope;
155
148
 
156
- const abstraction = this.meta.abstraction(A_TYPES__ConceptStage.Load, scope);
149
+ const abstraction = this.abstraction(A_TYPES__ConceptStage.Load, scope);
157
150
 
158
151
  await abstraction.process();
159
152
  }
@@ -168,7 +161,7 @@ export class A_Concept<
168
161
  ) {
169
162
  scope = scope ? scope.inherit(this.Scope) : this.Scope;
170
163
 
171
- const abstraction = this.meta.abstraction(A_TYPES__ConceptStage.Run, scope);
164
+ const abstraction = this.abstraction(A_TYPES__ConceptStage.Run, scope);
172
165
 
173
166
  await abstraction.process();
174
167
  }
@@ -184,7 +177,7 @@ export class A_Concept<
184
177
  ) {
185
178
  scope = scope ? scope.inherit(this.Scope) : this.Scope;
186
179
 
187
- const abstraction = this.meta.abstraction(A_TYPES__ConceptStage.Start, scope);
180
+ const abstraction = this.abstraction(A_TYPES__ConceptStage.Start, scope);
188
181
 
189
182
  await abstraction.process();
190
183
  }
@@ -200,7 +193,7 @@ export class A_Concept<
200
193
  ) {
201
194
  scope = scope ? scope.inherit(this.Scope) : this.Scope;
202
195
 
203
- const abstraction = this.meta.abstraction(A_TYPES__ConceptStage.Stop, scope);
196
+ const abstraction = this.abstraction(A_TYPES__ConceptStage.Stop, scope);
204
197
 
205
198
  await abstraction.process();
206
199
  }
@@ -214,7 +207,7 @@ export class A_Concept<
214
207
  ) {
215
208
  scope = scope ? scope.inherit(this.Scope) : this.Scope;
216
209
 
217
- const abstraction = this.meta.abstraction(A_TYPES__ConceptStage.Build, scope);
210
+ const abstraction = this.abstraction(A_TYPES__ConceptStage.Build, scope);
218
211
 
219
212
  await abstraction.process();
220
213
  }
@@ -228,7 +221,7 @@ export class A_Concept<
228
221
  ) {
229
222
  scope = scope ? scope.inherit(this.Scope) : this.Scope;
230
223
 
231
- const abstraction = this.meta.abstraction(A_TYPES__ConceptStage.Deploy, scope);
224
+ const abstraction = this.abstraction(A_TYPES__ConceptStage.Deploy, scope);
232
225
 
233
226
  await abstraction.process();
234
227
 
@@ -243,7 +236,7 @@ export class A_Concept<
243
236
  ) {
244
237
  scope = scope ? scope.inherit(this.Scope) : this.Scope;
245
238
 
246
- const abstraction = this.meta.abstraction(A_TYPES__ConceptStage.Publish, scope);
239
+ const abstraction = this.abstraction(A_TYPES__ConceptStage.Publish, scope);
247
240
 
248
241
  await abstraction.process();
249
242
  }
@@ -272,6 +265,30 @@ export class A_Concept<
272
265
  // await feature.process();
273
266
  }
274
267
 
268
+
269
+
270
+ protected abstraction(
271
+ method: A_TYPES__ConceptStage,
272
+ scope: A_Scope
273
+ ): A_Abstraction {
274
+
275
+ const featureDefinitions = this.containers.map(container => {
276
+ const definition = A_Context.abstractionDefinition(container, method, container.Scope);
277
+
278
+ return {
279
+ ...definition,
280
+ steps: definition.steps.map(step => ({ ...step, component: step.component ? step.component : container }))
281
+ }
282
+ });
283
+
284
+ const definition = {
285
+ name: `${this.namespace}.${method}`,
286
+ features: featureDefinitions,
287
+ scope
288
+ };
289
+
290
+ return new A_Abstraction(definition);
291
+ }
275
292
  }
276
293
 
277
294
 
@@ -10,6 +10,7 @@ import { A_TYPES__A_FeatureDecoratorConfig } from "@adaas/a-concept/decorators/A
10
10
  import { A_TYPES__A_AbstractionConstructor } from "../A-Abstraction/A-Abstraction.types";
11
11
  import { A_Abstraction } from "../A-Abstraction/A-Abstraction.class";
12
12
  import { A_Scope } from "../A-Scope/A-Scope.class";
13
+ import { A_Concept } from "./A_Concept.class";
13
14
  // import { A_TYPES__ComponentMeta } from "./A-Component.types";
14
15
 
15
16
 
@@ -18,53 +19,14 @@ export class A_ConceptMeta extends A_Meta<any> {
18
19
 
19
20
  constructor(
20
21
  private containers: Array<A_Container>,
21
- private base: A_Container
22
22
  ) {
23
23
  super();
24
24
  }
25
25
 
26
- abstractionDefinition(
27
- method: A_TYPES__ConceptStage,
28
- scope: A_Scope
29
- ): A_TYPES__A_AbstractionConstructor {
26
+
30
27
 
31
- const featureDefinitions = this.containers.map(container =>
32
- A_Context.abstractionDefinition(container, method, scope)
33
- );
34
28
 
35
- const definition = {
36
- name: `${this.base.name}.${method}`,
37
- features: featureDefinitions,
38
- scope
39
- };
40
29
 
41
- return definition;
42
- }
43
-
44
-
45
-
46
- abstraction(
47
- method: A_TYPES__ConceptStage,
48
- scope: A_Scope
49
- ): A_Abstraction {
50
-
51
- const featureDefinitions = this.containers.map(container => {
52
- const definition = A_Context.abstractionDefinition(container, method, container.Scope);
53
-
54
- return {
55
- ...definition,
56
- steps: definition.steps.map(step => ({ ...step, component: step.component ? step.component : container }))
57
- }
58
- });
59
-
60
-
61
- const definition = {
62
- name: `${this.base.name}.${method}`,
63
- features: featureDefinitions,
64
- scope
65
- };
66
-
67
- return new A_Abstraction(definition);
68
- }
30
+
69
31
 
70
32
  }
@@ -37,7 +37,7 @@ export enum A_TYPES__ConceptMetaKey {
37
37
  export interface A_TYPES__IConceptConstructor<
38
38
  T extends Array<A_Container>
39
39
  > {
40
- name: string,
40
+ name?: string,
41
41
 
42
42
  /**
43
43
  * A set of Context Fragments to register globally for the concept.
@@ -62,10 +62,12 @@ export interface A_TYPES__IConceptConstructor<
62
62
 
63
63
 
64
64
  /**
65
- * A set of external Concepts that can be used in the current Concept.
66
- * To provide additional functionality or extend the current Concept.
65
+ * A set of Components available for all containers and fragments in the concept.
66
+ * These components will be registered in the root scope of the concept.
67
+ *
68
+ * [!] Note that these components will be available in all containers and fragments in the concept.
67
69
  */
68
- // import?: Array<A_Concept>
70
+ components?: Array<{ new(...args: any[]): A_Component }>
69
71
  }
70
72
 
71
73
 
@@ -18,8 +18,6 @@ import { A_TYPES__FeatureCallParams, A_TYPES__FeatureConstructor } from "../A-Fe
18
18
  * - etc.
19
19
  */
20
20
  export class A_Container {
21
- // scope!: A_Scope
22
-
23
21
  protected readonly config!: Partial<A_TYPES__ContainerConstructor<any>>;
24
22
 
25
23
  /**
@@ -36,6 +34,11 @@ export class A_Container {
36
34
  }
37
35
 
38
36
 
37
+ /**
38
+ * Creates a new instance of A_Container
39
+ *
40
+ * @param config
41
+ */
39
42
  constructor(
40
43
  /**
41
44
  * Configuration of the container that will be used to run it.
@@ -1,5 +1,6 @@
1
1
  import {
2
2
  A_CommonHelper,
3
+ A_Error,
3
4
  A_Polyfills,
4
5
  } from "@adaas/a-utils";
5
6
  import { A_Component } from "../A-Component/A-Component.class";
@@ -147,6 +148,10 @@ export class A_Context {
147
148
 
148
149
  const newScope = param2 instanceof A_Scope ? param2 : new A_Scope(param2, param2);
149
150
 
151
+ if (!newScope.isInheritedFrom(A_Context.root)) {
152
+ newScope.inherit(A_Context.root);
153
+ }
154
+
150
155
  switch (true) {
151
156
  case param1 instanceof A_Container:
152
157
  instance.containers.set(param1, newScope);
@@ -169,6 +174,14 @@ export class A_Context {
169
174
 
170
175
 
171
176
 
177
+ /**
178
+ * Get or Create Meta for the specific class or instance.
179
+ * This method will return the existing meta if it exists, or create a new one if it doesn't.
180
+ *
181
+ * Meta object contains custom metadata based on the class type.
182
+ *
183
+ * @param container
184
+ */
172
185
  static meta(
173
186
  container: typeof A_Container,
174
187
  ): A_ContainerMeta
@@ -181,6 +194,9 @@ export class A_Context {
181
194
  static meta(
182
195
  entity: typeof A_Entity,
183
196
  ): A_ContainerMeta
197
+ static meta(
198
+ component: string,
199
+ ): A_ComponentMeta
184
200
  static meta(
185
201
  component: typeof A_Component,
186
202
  ): A_ComponentMeta
@@ -193,6 +209,7 @@ export class A_Context {
193
209
  | A_Entity
194
210
  | typeof A_Entity
195
211
  | { new(...args: any[]): any }
212
+ | string
196
213
  ): A_Meta<T>
197
214
  static meta<T extends Record<string, any>>(
198
215
  param1: typeof A_Component | typeof A_Container | A_Container
@@ -200,9 +217,9 @@ export class A_Context {
200
217
  | A_Entity
201
218
  | typeof A_Entity
202
219
  | { new(...args: any[]): any }
220
+ | string
203
221
  ): A_ContainerMeta | A_ComponentMeta | A_Meta<T> {
204
222
 
205
-
206
223
  const instance = this.getInstance();
207
224
 
208
225
  let metaStorage: WeakMap<typeof A_Container.constructor, A_Meta<any>>;
@@ -211,6 +228,7 @@ export class A_Context {
211
228
 
212
229
 
213
230
  switch (true) {
231
+ // 1) If param1 is instance of A_Container
214
232
  case param1 instanceof A_Container: {
215
233
 
216
234
  metaStorage = instance.containersMeta;
@@ -219,7 +237,7 @@ export class A_Context {
219
237
 
220
238
  break;
221
239
  }
222
-
240
+ // 2) If param1 is class of A_Container
223
241
  case A_CommonHelper.isInheritedFrom(param1, A_Container): {
224
242
  metaStorage = instance.containersMeta;
225
243
  property = param1 as typeof A_Container;
@@ -227,7 +245,7 @@ export class A_Context {
227
245
 
228
246
  break;
229
247
  }
230
-
248
+ // 3) If param1 is instance of A_Component
231
249
  case param1 instanceof A_Component: {
232
250
  metaStorage = instance.componentsMeta;
233
251
  property = param1.constructor;
@@ -235,7 +253,7 @@ export class A_Context {
235
253
 
236
254
  break;
237
255
  }
238
-
256
+ // 4) If param1 is class of A_Component
239
257
  case A_CommonHelper.isInheritedFrom(param1, A_Component): {
240
258
  metaStorage = instance.componentsMeta;
241
259
  property = param1 as typeof A_Component;
@@ -243,7 +261,7 @@ export class A_Context {
243
261
 
244
262
  break;
245
263
  }
246
-
264
+ // 5) If param1 is instance of A_Entity
247
265
  case param1 instanceof A_Entity: {
248
266
  metaStorage = instance.entitiesMeta;
249
267
  property = param1.constructor;
@@ -251,15 +269,25 @@ export class A_Context {
251
269
 
252
270
  break;
253
271
  }
254
-
272
+ // 6) If param1 is class of A_Entity
255
273
  case A_CommonHelper.isInheritedFrom(param1, A_Entity): {
256
274
  metaStorage = instance.entitiesMeta;
257
275
  property = param1 as typeof A_Entity;
258
276
  metaType = A_EntityMeta;
277
+
259
278
  break;
260
279
  }
280
+ // 7) If param1 is string then we need to find the component by its name
281
+ case typeof param1 === 'string': {
282
+ metaStorage = instance.componentsMeta;
283
+ const found = Array.from(instance.componentsMeta).find(([c]) => c.name === param1)!;
284
+ if (!(found && found.length)) throw new A_Error(`Component with name ${param1} not found`);
285
+ property = found[0];
286
+ metaType = A_ComponentMeta;
261
287
 
262
-
288
+ break;
289
+ }
290
+ // 8) If param1 is any other class or function
263
291
  default: {
264
292
  metaStorage = instance.customMeta;
265
293
  property = typeof (param1 as any) === 'function' ? param1 : param1.constructor;
@@ -281,6 +309,15 @@ export class A_Context {
281
309
 
282
310
 
283
311
 
312
+ /**
313
+ * Get the scope of the specific class or instance.
314
+ *
315
+ * Every execution in Concept has its own scope.
316
+ *
317
+ * This method will return the scope of the specific class or instance.
318
+ *
319
+ * @param entity
320
+ */
284
321
  static scope(
285
322
  entity: A_Entity
286
323
  ): A_Scope