@adaas/a-concept 0.1.18 → 0.1.19

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 (52) hide show
  1. package/dist/index.d.ts +2 -0
  2. package/dist/index.js +5 -2
  3. package/dist/index.js.map +1 -1
  4. package/dist/src/global/A-Abstraction/A-Abstraction-Extend.decorator.js +11 -4
  5. package/dist/src/global/A-Abstraction/A-Abstraction-Extend.decorator.js.map +1 -1
  6. package/dist/src/global/A-Component/A-Component.meta.js +2 -1
  7. package/dist/src/global/A-Component/A-Component.meta.js.map +1 -1
  8. package/dist/src/global/A-Component/A-Component.types.d.ts +2 -11
  9. package/dist/src/global/A-Concept/A-Concept.types.d.ts +4 -21
  10. package/dist/src/global/A-Container/A-Container.meta.js +4 -2
  11. package/dist/src/global/A-Container/A-Container.meta.js.map +1 -1
  12. package/dist/src/global/A-Container/A-Container.types.d.ts +2 -11
  13. package/dist/src/global/A-Feature/A-Feature-Define.decorator.js +1 -1
  14. package/dist/src/global/A-Feature/A-Feature-Define.decorator.js.map +1 -1
  15. package/dist/src/global/A-Feature/A-Feature-Extend.decorator.js +14 -5
  16. package/dist/src/global/A-Feature/A-Feature-Extend.decorator.js.map +1 -1
  17. package/dist/src/global/A-Feature/A-Feature.class.d.ts +2 -1
  18. package/dist/src/global/A-Feature/A-Feature.class.js +7 -3
  19. package/dist/src/global/A-Feature/A-Feature.class.js.map +1 -1
  20. package/dist/src/global/A-Feature/A-Feature.types.d.ts +69 -27
  21. package/dist/src/global/A-Stage/A-Stage.class.d.ts +37 -28
  22. package/dist/src/global/A-Stage/A-Stage.class.js +62 -98
  23. package/dist/src/global/A-Stage/A-Stage.class.js.map +1 -1
  24. package/dist/src/global/A-Stage/A-Stage.types.d.ts +30 -3
  25. package/dist/src/global/A-Stage/A-Stage.types.js.map +1 -1
  26. package/dist/src/global/A-StepManager/A-StepManager.class.d.ts +20 -0
  27. package/dist/src/{helpers/A_StepsManager.class.js → global/A-StepManager/A-StepManager.class.js} +38 -64
  28. package/dist/src/global/A-StepManager/A-StepManager.class.js.map +1 -0
  29. package/dist/src/global/A-StepManager/A-StepManager.error.d.ts +4 -0
  30. package/dist/src/global/A-StepManager/A-StepManager.error.js +9 -0
  31. package/dist/src/global/A-StepManager/A-StepManager.error.js.map +1 -0
  32. package/index.ts +2 -1
  33. package/package.json +3 -3
  34. package/src/global/A-Abstraction/A-Abstraction-Extend.decorator.ts +18 -6
  35. package/src/global/A-Component/A-Component.meta.ts +2 -1
  36. package/src/global/A-Component/A-Component.types.ts +2 -11
  37. package/src/global/A-Concept/A-Concept.types.ts +4 -21
  38. package/src/global/A-Container/A-Container.meta.ts +4 -2
  39. package/src/global/A-Container/A-Container.types.ts +2 -11
  40. package/src/global/A-Feature/A-Feature-Define.decorator.ts +1 -0
  41. package/src/global/A-Feature/A-Feature-Extend.decorator.ts +21 -7
  42. package/src/global/A-Feature/A-Feature.class.ts +8 -1
  43. package/src/global/A-Feature/A-Feature.types.ts +80 -33
  44. package/src/global/A-Stage/A-Stage.class.ts +71 -143
  45. package/src/global/A-Stage/A-Stage.types.ts +34 -3
  46. package/src/{helpers/A_StepsManager.class.ts → global/A-StepManager/A-StepManager.class.ts} +53 -87
  47. package/src/global/A-StepManager/A-StepManager.error.ts +10 -0
  48. package/tests/A-Abstraction.test.ts +273 -255
  49. package/tests/A-Feature.test.ts +270 -271
  50. package/tests/A-StepManager.test.ts +346 -0
  51. package/dist/src/helpers/A_StepsManager.class.d.ts +0 -35
  52. package/dist/src/helpers/A_StepsManager.class.js.map +0 -1
package/index.ts CHANGED
@@ -75,6 +75,7 @@ export { A_Abstraction_Extend } from './src/global/A-Abstraction/A-Abstraction-E
75
75
  export { A_CommonHelper } from './src/helpers/A_Common.helper';
76
76
  export { A_FormatterHelper } from './src/helpers/A_Formatter.helper';
77
77
  export { A_IdentityHelper, A_ID_TYPES__TimeId_Parts } from './src/helpers/A_Identity.helper';
78
- // export { A_StepsManager } from './src/helpers/A_StepsManager.class';
78
+ export { A_StepsManager } from './src/global/A-StepManager/A-StepManager.class';
79
+ export { A_StepManagerError } from './src/global/A-StepManager/A-StepManager.error';
79
80
  export { A_TypeGuards } from './src/helpers/A_TypeGuards.helper';
80
81
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@adaas/a-concept",
3
- "version": "0.1.18",
3
+ "version": "0.1.19",
4
4
  "description": "A-Concept is a framework to build new Applications within or outside the ADAAS ecosystem. This framework is designed to be modular structure regardless environment and program goal.",
5
5
  "main": "./dist/index.js",
6
6
  "module": "./dist/index.mjs",
@@ -20,8 +20,8 @@
20
20
  "ext": "ts, js"
21
21
  },
22
22
  "scripts": {
23
- "test": "jest",
24
- "start": "nodemon ./tests/log.ts",
23
+ "test": "jest ",
24
+ "start": "nodemon ./tests/example-usage.ts",
25
25
  "example:simple": "nodemon ./examples/simple/concept.ts",
26
26
  "example:simple:trace": "node -r tsconfig-paths/register -r ts-node/register -r ./trace-require.js ./examples/simple/concept.ts",
27
27
  "example:http": "nodemon ./examples/simple-http-server/concept.ts",
@@ -81,18 +81,30 @@ export function A_Abstraction_Extend(
81
81
 
82
82
  const existedIndex = existedMetaValue.findIndex(item => item.handler === propertyKey);
83
83
 
84
- const abstraction = {
84
+ const abstraction = {
85
85
  name: setName,
86
86
  handler: propertyKey,
87
- before: config.before || [],
88
- after: config.after || [],
89
- behavior: config.behavior || 'sync'
87
+ behavior: config.behavior || 'sync',
88
+ throwOnError: config.throwOnError !== undefined ? config.throwOnError : true,
89
+
90
+ before: (config.before
91
+ ?.map(b =>
92
+ b instanceof RegExp
93
+ ? b.source
94
+ : new RegExp(`^.*${b.replace(/\./g, '\\.')}$`).source)
95
+ || []),
96
+ after: (config.after
97
+ ?.map(a =>
98
+ a instanceof RegExp
99
+ ? a.source
100
+ : new RegExp(`^.*${a.replace(/\./g, '\\.')}$`).source)
101
+ || []),
90
102
  }
91
103
 
92
- if(existedIndex !== -1) {
104
+ if (existedIndex !== -1) {
93
105
  // Update the existing method in the metadata
94
106
  existedMetaValue[existedIndex] = abstraction;
95
- }else{
107
+ } else {
96
108
  // Add the new method to the metadata
97
109
  existedMetaValue.push(abstraction);
98
110
  }
@@ -48,7 +48,8 @@ export class A_ComponentMeta extends A_Meta<A_TYPES__ComponentMeta> {
48
48
  handler: extension.handler,
49
49
  behavior: extension.behavior,
50
50
  before: extension.before || [],
51
- after: extension.after || []
51
+ after: extension.after || [],
52
+ throwOnError: extension.throwOnError || true,
52
53
  });
53
54
 
54
55
  });
@@ -3,7 +3,7 @@ import { A_Meta } from "../A-Meta/A-Meta.class"
3
3
  import { A_TYPES__ConceptAbstraction } from "../A-Concept/A-Concept.types"
4
4
  import { A_Component } from "./A-Component.class"
5
5
  import { A_TYPES__ComponentMetaKey } from "./A-Component.constants"
6
- import { A_TYPES__FeatureDefineDecoratorMeta, A_TYPES__FeatureExtendDecoratorBehaviorConfig, A_TYPES__FeatureExtendDecoratorMeta } from "../A-Feature/A-Feature.types"
6
+ import { A_TYPES__FeatureDefineDecoratorMeta, A_TYPES__FeatureExtendDecoratorMeta } from "../A-Feature/A-Feature.types"
7
7
 
8
8
 
9
9
 
@@ -91,15 +91,6 @@ export type A_TYPES__ComponentMeta = {
91
91
 
92
92
 
93
93
 
94
- export type A_TYPES__ComponentMetaExtension = {
95
- /**
96
- * The name of original Extension Definition
97
- */
98
- name: string,
99
- /**
100
- * The name of the handler that will be used to apply the extension
101
- */
102
- handler: string,
103
- } & A_TYPES__FeatureExtendDecoratorBehaviorConfig
94
+ export type A_TYPES__ComponentMetaExtension = A_TYPES__FeatureExtendDecoratorMeta
104
95
 
105
96
 
@@ -1,10 +1,10 @@
1
- import { A_TYPES__A_InjectDecorator_Meta } from "@adaas/a-concept/global/A-Inject/A-Inject.types";
2
1
  import { A_Container } from "../A-Container/A-Container.class";
3
2
  import { A_Concept } from "./A-Concept.class";
4
- import { A_TYPES__FeatureExtendDecoratorBehaviorConfig } from "../A-Feature/A-Feature.types";
3
+ import { A_TYPES__FeatureExtendDecoratorMeta } from "../A-Feature/A-Feature.types";
5
4
  import { A_TYPES__Component_Constructor } from "../A-Component/A-Component.types";
6
5
  import { A_TYPES__Fragment_Constructor } from "../A-Fragment/A-Fragment.types";
7
6
  import { A_TYPES__Entity_Constructor } from "../A-Entity/A-Entity.types";
7
+ import { A_TYPES__A_InjectDecorator_Meta } from "../A-Inject/A-Inject.types";
8
8
 
9
9
 
10
10
  // ============================================================================
@@ -69,32 +69,15 @@ export type A_TYPES__Concept_Serialized = {
69
69
  * Uses as a transfer object to pass configurations to Feature constructor
70
70
  */
71
71
  export type A_TYPES__ConceptAbstractionMeta = {
72
- /**
73
- * The name of original Extension Definition
74
- */
75
- name: string,
76
- /**
77
- * The name of the handler that will be used to apply the extension
78
- */
79
- handler: string,
80
72
  /**
81
73
  * The arguments that will be passed to the handler
82
74
  */
83
75
  args: A_TYPES__A_InjectDecorator_Meta
84
- } & A_TYPES__FeatureExtendDecoratorBehaviorConfig
76
+ } & A_TYPES__FeatureExtendDecoratorMeta
85
77
 
86
78
 
87
79
 
88
80
  /**
89
81
  * Uses to define the extension that will be applied to the Concept
90
82
  */
91
- export type A_TYPES__ConceptAbstraction = {
92
- /**
93
- * The name of original Extension Definition
94
- */
95
- name: string,
96
- /**
97
- * The name of the handler that will be used to apply the extension
98
- */
99
- handler: string,
100
- } & A_TYPES__FeatureExtendDecoratorBehaviorConfig
83
+ export type A_TYPES__ConceptAbstraction = A_TYPES__FeatureExtendDecoratorMeta
@@ -69,7 +69,8 @@ export class A_ContainerMeta extends A_Meta<A_TYPES__ContainerMeta> {
69
69
  args,
70
70
  before: extension.before,
71
71
  behavior: extension.behavior,
72
- after: extension.after
72
+ after: extension.after,
73
+ throwOnError: extension.throwOnError,
73
74
  });
74
75
 
75
76
  });
@@ -104,7 +105,8 @@ export class A_ContainerMeta extends A_Meta<A_TYPES__ContainerMeta> {
104
105
  handler: extension.handler,
105
106
  behavior: extension.behavior,
106
107
  before: extension.before || [],
107
- after: extension.after || []
108
+ after: extension.after || [],
109
+ throwOnError: extension.throwOnError || true,
108
110
  });
109
111
 
110
112
  });
@@ -4,7 +4,7 @@ import { A_Meta } from "../A-Meta/A-Meta.class";
4
4
  import { A_TYPES__Scope_Init } from "../A-Scope/A-Scope.types";
5
5
  import { A_TYPES__ContainerMetaKey } from "./A-Container.constants";
6
6
  import { A_Container } from "./A-Container.class";
7
- import { A_TYPES__FeatureDefineDecoratorMeta, A_TYPES__FeatureExtendDecoratorBehaviorConfig, A_TYPES__FeatureExtendDecoratorMeta } from "../A-Feature/A-Feature.types";
7
+ import { A_TYPES__FeatureDefineDecoratorMeta, A_TYPES__FeatureExtendDecoratorMeta } from "../A-Feature/A-Feature.types";
8
8
 
9
9
 
10
10
  // ============================================================================
@@ -85,13 +85,4 @@ export type A_TYPES__ContainerMeta = {
85
85
  }
86
86
 
87
87
 
88
- export type A_TYPES__ContainerMetaExtension = {
89
- /**
90
- * The name of original Extension Definition
91
- */
92
- name: string,
93
- /**
94
- * The name of the handler that will be used to apply the extension
95
- */
96
- handler: string,
97
- } & A_TYPES__FeatureExtendDecoratorBehaviorConfig
88
+ export type A_TYPES__ContainerMetaExtension = A_TYPES__FeatureExtendDecoratorMeta
@@ -90,6 +90,7 @@ export function A_Feature_Define(
90
90
  before: item.before || [],
91
91
  after: item.after || [],
92
92
  behavior: item.behavior || 'sync',
93
+ throwOnError: true
93
94
  })
94
95
  ) : [],
95
96
  });
@@ -1,4 +1,3 @@
1
- import { A_Component } from "@adaas/a-concept/global/A-Component/A-Component.class";
2
1
  import { A_Context } from "@adaas/a-concept/global/A-Context/A-Context.class";
3
2
  import { A_Meta } from "@adaas/a-concept/global/A-Meta/A-Meta.class";
4
3
  import { A_TYPES__FeatureExtendDecoratorConfig, A_TYPES__FeatureExtendDecoratorDescriptor, A_TYPES__FeatureExtendDecoratorScopeItem, A_TYPES__FeatureExtendDecoratorTarget } from "./A-Feature.types";
@@ -79,6 +78,7 @@ export function A_Feature_Extend(
79
78
  let after: string[] = [];
80
79
  let include: Array<A_TYPES__FeatureExtendDecoratorScopeItem> = [];
81
80
  let exclude: Array<A_TYPES__FeatureExtendDecoratorScopeItem> = [];
81
+ let throwOnError: boolean = true;
82
82
 
83
83
 
84
84
 
@@ -102,12 +102,25 @@ export function A_Feature_Extend(
102
102
  targetRegexp = buildTargetRegexp(param1, include, exclude, propertyKey);
103
103
 
104
104
  behavior = param1.behavior || behavior;
105
- before = param1.before || before;
106
- after = param1.after || after;
105
+ throwOnError = param1.throwOnError !== undefined ? param1.throwOnError : throwOnError;
106
+
107
+ before = param1.before
108
+ ?.map(e =>
109
+ e instanceof RegExp
110
+ ? e.source
111
+ : new RegExp(`^.*${e.replace(/\./g, '\\.')}$`).source)
112
+ || before;
113
+ after = param1.after
114
+ ?.map(e =>
115
+ e instanceof RegExp
116
+ ? e.source
117
+ : new RegExp(`^.*${e.replace(/\./g, '\\.')}$`).source)
118
+ || after;
119
+
107
120
  break;
108
121
 
109
122
  default:
110
- targetRegexp = new RegExp(`^.*\\.${propertyKey}$`);
123
+ targetRegexp = new RegExp(`^.*${propertyKey.replace(/\./g, '\\.')}$`);
111
124
  break;
112
125
  }
113
126
 
@@ -143,13 +156,14 @@ export function A_Feature_Extend(
143
156
  handler: propertyKey,
144
157
  behavior,
145
158
  before,
146
- after
159
+ after,
160
+ throwOnError
147
161
  }
148
162
 
149
- if (existedIndex !== -1){
163
+ if (existedIndex !== -1) {
150
164
  // Update the existing method in the metadata
151
165
  existedMetaValue[existedIndex] = extension;
152
- }else{
166
+ } else {
153
167
  // Add the new method to the metadata
154
168
  existedMetaValue.push(extension);
155
169
  }
@@ -8,7 +8,7 @@ import {
8
8
  import { A_Feature_Define } from "@adaas/a-concept/global/A-Feature/A-Feature-Define.decorator";
9
9
  import { A_Feature_Extend } from "@adaas/a-concept/global/A-Feature/A-Feature-Extend.decorator";
10
10
  import { A_Stage } from "../A-Stage/A-Stage.class";
11
- import { A_StepsManager } from "@adaas/a-concept/helpers/A_StepsManager.class";
11
+ import { A_StepsManager } from "@adaas/a-concept/global/A-StepManager/A-StepManager.class";
12
12
  import { A_StageError } from "../A-Stage/A-Stage.error";
13
13
  import { A_TypeGuards } from "@adaas/a-concept/helpers/A_TypeGuards.helper";
14
14
  import { A_FeatureError } from "./A-Feature.error";
@@ -391,4 +391,11 @@ export class A_Feature<T extends A_TYPES__FeatureAvailableComponents = A_TYPES__
391
391
 
392
392
  this._state = A_TYPES__FeatureState.INTERRUPTED;
393
393
  }
394
+
395
+
396
+
397
+
398
+ toString(): string {
399
+ return `A-Feature(${this.caller.component?.constructor?.name || 'Unknown'}::${this.name})`;
400
+ }
394
401
  }
@@ -1,4 +1,4 @@
1
- import { A_TYPES__A_StageStep } from "../A-Stage/A-Stage.types"
1
+ import { A_TYPES__A_StageStep, A_TYPES_StageExecutionBehavior } from "../A-Stage/A-Stage.types"
2
2
  import { A_Fragment } from "../A-Fragment/A-Fragment.class"
3
3
  import { A_Entity } from "@adaas/a-concept/global/A-Entity/A-Entity.class"
4
4
  import { A_Container } from "../A-Container/A-Container.class"
@@ -206,23 +206,11 @@ export type A_TYPES__FeatureExtendDecoratorDescriptor =
206
206
  * [!] Can be applied only on A-Components
207
207
  */
208
208
  export type A_TYPES__FeatureExtendDecoratorTarget = A_Component
209
- /**
210
- * Meta type for A_Extend decorator
211
- */
212
- export type A_TYPES__FeatureExtendDecoratorMeta = {
213
- /**
214
- * Original Feature Extension name
215
- *
216
- * [!] could be string or regex
217
- */
218
- name: string,
219
- /**
220
- * Actual method name in the class
221
- */
222
- handler: string
223
- } & A_TYPES__FeatureExtendDecoratorBehaviorConfig
209
+
224
210
  /**
225
211
  * Configuration type for A_Extend decorator
212
+ *
213
+ * This is an INPUT parameter provided by the user
226
214
  */
227
215
  export type A_TYPES__FeatureExtendDecoratorConfig = {
228
216
  /**
@@ -253,7 +241,54 @@ export type A_TYPES__FeatureExtendDecoratorConfig = {
253
241
  * ```
254
242
  */
255
243
  scope: Array<A_TYPES__FeatureExtendDecoratorScopeItem> | Partial<A_TYPES__FeatureExtendDecoratorScopeConfig>,
256
- } & A_TYPES__FeatureExtendDecoratorBehaviorConfig
244
+ /**
245
+ * The behavior of the method.
246
+ * In case its async it will be executed independently from the main thread.
247
+ *
248
+ * [!] However, in case of sync, it will be executed in the main thread.in the order of the declaration.
249
+ *
250
+ */
251
+ behavior: A_TYPES_StageExecutionBehavior
252
+ /**
253
+ * Allows to define the order of the execution of the method.
254
+ *
255
+ * [!] It applies for the following structure :'Component.methodName'
256
+ * [!] In case the method has circular dependencies it will Throw an error.
257
+ *
258
+ * Example:
259
+ * ```ts
260
+ * @A_Feature.Extend({
261
+ * name: 'load',
262
+ * before: ['Component1.methodName', /Component2\..+/]
263
+ * })
264
+ * ```
265
+ */
266
+ before: Array<string | RegExp>
267
+
268
+ /**
269
+ * Allows to define the order of the execution of the method.
270
+ *
271
+ * [!] It applies for the following structure :'Component.methodName'
272
+ * [!] In case the method has circular dependencies it will Throw an error.
273
+ *
274
+ * Example:
275
+ * ```ts
276
+ * @A_Feature.Extend({
277
+ * name: 'load',
278
+ * before: ['Component1.methodName', /Component2\..+/]
279
+ * })
280
+ * ```
281
+ *
282
+ */
283
+ after: Array<string | RegExp>
284
+
285
+ /**
286
+ * Indicates whether to throw an error if the step fails.
287
+ *
288
+ * [!] By default is true
289
+ */
290
+ throwOnError: boolean
291
+ }
257
292
  /**
258
293
  * Scope item that can be used in A_Extend decorator configuration
259
294
  */
@@ -270,13 +305,29 @@ export type A_TYPES__FeatureExtendDecoratorScopeConfig = {
270
305
  /**
271
306
  * A single item that can be used in scope configuration
272
307
  */
273
- export type A_TYPES__FeatureExtendDecoratorScopeItem = { new(...args: any[]): A_Container }
274
- | { new(...args: any[]): A_Entity }
275
- | { new(...args: any[]): A_Component }
308
+ export type A_TYPES__FeatureExtendDecoratorScopeItem = A_TYPES__Container_Constructor
309
+ | A_TYPES__Entity_Constructor
310
+ | A_TYPES__Component_Constructor
311
+
312
+
313
+
314
+ // =======================================================================
315
+ // --------------------------META TYPES-----------------------------------
316
+ // =======================================================================
276
317
  /**
277
- * Behavior configuration for A_Extend decorator
318
+ * Meta type for A_Extend decorator
278
319
  */
279
- export type A_TYPES__FeatureExtendDecoratorBehaviorConfig = {
320
+ export type A_TYPES__FeatureExtendDecoratorMeta = {
321
+ /**
322
+ * Original Feature Extension name
323
+ *
324
+ * [!] could be string or regex
325
+ */
326
+ name: string,
327
+ /**
328
+ * Actual method name in the class
329
+ */
330
+ handler: string
280
331
  /**
281
332
  * The behavior of the method.
282
333
  * In case its async it will be executed independently from the main thread.
@@ -284,9 +335,7 @@ export type A_TYPES__FeatureExtendDecoratorBehaviorConfig = {
284
335
  * [!] However, in case of sync, it will be executed in the main thread.in the order of the declaration.
285
336
  *
286
337
  */
287
- behavior: 'async' | 'sync'
288
-
289
-
338
+ behavior: A_TYPES_StageExecutionBehavior
290
339
  /**
291
340
  * Allows to define the order of the execution of the method.
292
341
  *
@@ -294,7 +343,6 @@ export type A_TYPES__FeatureExtendDecoratorBehaviorConfig = {
294
343
  *
295
344
  */
296
345
  before: string[]
297
-
298
346
  /**
299
347
  * Allows to define the order of the execution of the method.
300
348
  *
@@ -302,13 +350,12 @@ export type A_TYPES__FeatureExtendDecoratorBehaviorConfig = {
302
350
  *
303
351
  */
304
352
  after: string[]
353
+ /**
354
+ * Indicates whether to throw an error if the step fails.
355
+ *
356
+ * [!] By default is true
357
+ */
358
+ throwOnError: boolean
305
359
  }
306
360
 
307
361
 
308
-
309
-
310
-
311
-
312
-
313
-
314
-