@adaas/a-concept 0.1.37 → 0.1.40

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@adaas/a-concept",
3
- "version": "0.1.37",
3
+ "version": "0.1.40",
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
  "license": "Apache-2.0",
6
6
  "main": "./dist/index.cjs",
@@ -45,7 +45,7 @@
45
45
  "ext": "ts, js"
46
46
  },
47
47
  "scripts": {
48
- "test": "jest ",
48
+ "test": "jest --detectOpenHandles",
49
49
  "start": "nodemon ./tests/example-usage.ts",
50
50
  "example:simple": "nodemon ./examples/simple/concept.ts",
51
51
  "example:http": "nodemon ./examples/simple-http-server/concept.ts",
@@ -321,23 +321,20 @@ export class A_Context {
321
321
  ) {
322
322
  const instance = this.getInstance();
323
323
 
324
-
325
324
  const scope = A_TypeGuards.isScopeInstance(param1)
326
325
  ? param1
327
326
  : instance._registry.get(param1);
328
327
 
329
328
  if (!scope) return;
330
329
 
331
- try {
332
- const component = A_TypeGuards.isComponentInstance(param1)
333
- ? param1
334
- : this.issuer(scope);
330
+ const component = A_TypeGuards.isComponentInstance(param1)
331
+ ? param1
332
+ : this.issuer(scope);
335
333
 
334
+ if (component)
336
335
  instance._registry.delete(component);
336
+ if (scope)
337
337
  instance._scopeIssuers.delete(scope);
338
- } catch (error) {
339
- return
340
- }
341
338
  }
342
339
 
343
340
 
@@ -520,7 +517,7 @@ export class A_Context {
520
517
  * Provide the scope to get its issuer.
521
518
  */
522
519
  scope: A_Scope
523
- ): A_TYPES__ScopeLinkedComponents {
520
+ ): A_TYPES__ScopeLinkedComponents | undefined {
524
521
 
525
522
  const instance = this.getInstance();
526
523
 
@@ -529,10 +526,10 @@ export class A_Context {
529
526
  `Invalid parameter provided to get scope issuer. Parameter cannot be null or undefined.`
530
527
  );
531
528
 
532
- if (!instance._scopeIssuers.has(scope)) throw new A_ContextError(
533
- A_ContextError.ScopeNotFoundError,
534
- `Invalid parameter provided to get scope issuer. Provided scope does not have an issuer registered.`
535
- );
529
+ // if (!instance._scopeIssuers.has(scope)) throw new A_ContextError(
530
+ // A_ContextError.ScopeNotFoundError,
531
+ // `Invalid parameter provided to get scope issuer. Provided scope does not have an issuer registered.`
532
+ // );
536
533
 
537
534
  return instance._scopeIssuers.get(scope)!;
538
535
  }
@@ -2,6 +2,7 @@ import { A_Meta } from "../A-Meta/A-Meta.class";
2
2
  import { A_TYPES__EntityMeta } from "./A-Entity.types";
3
3
  import { A_TYPES__EntityMetaKey } from "./A-Entity.constants";
4
4
  import { A_TYPES__FeatureDefineDecoratorMeta } from "../A-Feature/A-Feature.types";
5
+ import { A_TYPES__A_InjectDecorator_Meta } from "../A-Inject/A-Inject.types";
5
6
 
6
7
 
7
8
  export class A_EntityMeta extends A_Meta<A_TYPES__EntityMeta> {
@@ -20,4 +21,21 @@ export class A_EntityMeta extends A_Meta<A_TYPES__EntityMeta> {
20
21
  .map(([, feature]) => feature) || [];
21
22
  }
22
23
 
24
+
25
+ /**
26
+ * Allows to get all the injections for a given handler
27
+ *
28
+ * @param handler
29
+ * @returns
30
+ */
31
+ injections(
32
+ handler: string
33
+ ): A_TYPES__A_InjectDecorator_Meta {
34
+ const injections = this.get(A_TYPES__EntityMetaKey.INJECTIONS);
35
+
36
+ const args = injections?.get(handler) || [];
37
+
38
+ return args;
39
+ }
40
+
23
41
  }
@@ -3,6 +3,7 @@ import { A_Entity } from "./A-Entity.class";
3
3
  import { ASEID } from "../ASEID/ASEID.class";
4
4
  import { A_TYPES__EntityMetaKey } from "./A-Entity.constants";
5
5
  import { A_TYPES__FeatureDefineDecoratorMeta, A_TYPES__FeatureExtendDecoratorMeta } from "../A-Feature/A-Feature.types";
6
+ import { A_TYPES__A_InjectDecorator_Meta } from "../A-Inject/A-Inject.types";
6
7
 
7
8
 
8
9
  /**
@@ -67,6 +68,18 @@ export type A_TYPES__EntityMeta = {
67
68
  */
68
69
  [Key: string]: A_TYPES__FeatureDefineDecoratorMeta
69
70
  }>
71
+
72
+ /**
73
+ * Injections defined on the component per handler
74
+ */
75
+ [A_TYPES__EntityMetaKey.INJECTIONS]: A_Meta<{
76
+ /**
77
+ * Where Key is the name of the injection
78
+ *
79
+ * Where value is the list of injections
80
+ */
81
+ [Key: string]: A_TYPES__A_InjectDecorator_Meta
82
+ }>
70
83
  }
71
84
 
72
85
 
@@ -404,7 +404,20 @@ export class A_Error<
404
404
 
405
405
  this._description = params.description;
406
406
  this._link = params.link;
407
- this._originalError = params.originalError;
407
+
408
+ // Handle originalError: if it's an A_Error, we should trace back to the root cause
409
+ // to avoid infinite nesting of A_Error instances
410
+ if (params.originalError instanceof A_Error) {
411
+ // Find the root original error by traversing the chain
412
+ let rootError = params.originalError;
413
+ while (rootError.originalError instanceof A_Error) {
414
+ rootError = rootError.originalError;
415
+ }
416
+ // Set the root cause as the original error
417
+ this._originalError = rootError.originalError || rootError;
418
+ } else {
419
+ this._originalError = params.originalError;
420
+ }
408
421
  }
409
422
 
410
423
  /**
@@ -403,6 +403,8 @@ export class A_Feature<T extends A_TYPES__FeatureAvailableComponents = A_TYPES__
403
403
  * @returns
404
404
  */
405
405
  async completed(): Promise<void> {
406
+ if(this.isDone) return;
407
+
406
408
 
407
409
  this._state = A_TYPES__FeatureState.COMPLETED;
408
410
 
@@ -415,6 +417,7 @@ export class A_Feature<T extends A_TYPES__FeatureAvailableComponents = A_TYPES__
415
417
  * @param error
416
418
  */
417
419
  async failed(error: A_FeatureError) {
420
+ if(this.isDone) return;
418
421
 
419
422
  this._state = A_TYPES__FeatureState.FAILED;
420
423
 
@@ -25,6 +25,7 @@ import { A_Feature } from "@adaas/a-concept/global/A-Feature/A-Feature.class";
25
25
  import { A_CommonHelper } from "@adaas/a-concept/helpers/A_Common.helper";
26
26
  import { A_TYPES__Error_Constructor } from "../A-Error/A_Error.types";
27
27
  import { A_Error } from "../A-Error/A_Error.class";
28
+ import { A_TYPES__EntityMetaKey } from "../A-Entity/A-Entity.constants";
28
29
 
29
30
 
30
31
  /**
@@ -153,6 +154,10 @@ export function A_Inject(
153
154
  case A_TypeGuards.isContainerInstance(target):
154
155
  metaKey = A_TYPES__ContainerMetaKey.INJECTIONS;
155
156
  break;
157
+
158
+ case A_TypeGuards.isEntityInstance(target):
159
+ metaKey = A_TYPES__EntityMetaKey.INJECTIONS;
160
+ break;
156
161
  }
157
162
 
158
163
  // get existing meta or create a new one
@@ -294,6 +294,7 @@ export class A_Scope<
294
294
  this._entities.clear();
295
295
 
296
296
  if (this.issuer()) {
297
+
297
298
  A_Context.deallocate(this);
298
299
  }
299
300
  }
@@ -311,11 +312,7 @@ export class A_Scope<
311
312
  * @returns
312
313
  */
313
314
  issuer<T extends A_TYPES__ScopeLinkedComponents>(): T | undefined {
314
- try {
315
315
  return A_Context.issuer(this) as T;
316
- } catch (error) {
317
- return undefined;
318
- }
319
316
  }
320
317
 
321
318