@adaas/a-concept 0.1.23 → 0.1.25
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/index.cjs +3 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.mts +3952 -0
- package/dist/index.d.ts +3952 -50
- package/dist/index.mjs +3 -0
- package/dist/index.mjs.map +1 -0
- package/package.json +5 -6
- package/src/global/A-Abstraction/A-Abstraction-Extend.decorator.ts +18 -13
- package/src/global/A-Component/A-Component.meta.ts +3 -2
- package/src/global/A-Container/A-Container.meta.ts +5 -8
- package/src/global/A-Context/A-Context.class.ts +81 -7
- package/src/global/A-Context/A-Context.error.ts +4 -0
- package/src/global/A-Dependency/A-Dependency-Default.decorator.ts +75 -0
- package/src/global/A-Dependency/A-Dependency-Load.decorator.ts +80 -0
- package/src/global/A-Dependency/A-Dependency-Require.decorator.ts +68 -0
- package/src/global/A-Dependency/A-Dependency.class.ts +33 -0
- package/src/global/A-Dependency/A-Dependency.error.ts +13 -0
- package/src/global/A-Dependency/A-Dependency.types.ts +28 -0
- package/src/global/A-Entity/A-Entity.class.ts +2 -1
- package/src/global/A-Feature/A-Feature-Define.decorator.ts +7 -4
- package/src/global/A-Feature/A-Feature-Extend.decorator.ts +23 -17
- package/src/global/A-Feature/A-Feature.class.ts +12 -1
- package/src/global/A-Feature/A-Feature.types.ts +33 -8
- package/src/global/A-Inject/A-Inject.decorator.ts +4 -2
- package/src/global/A-Inject/A-Inject.types.ts +5 -3
- package/src/global/A-Scope/A-Scope.class.ts +85 -57
- package/src/global/A-Stage/A-Stage.class.ts +22 -2
- package/src/global/A-Stage/A-Stage.error.ts +2 -0
- package/src/global/A-Stage/A-Stage.types.ts +7 -2
- package/src/global/A-StepManager/A-StepManager.class.ts +19 -13
- package/src/helpers/A_Common.helper.ts +101 -0
- package/src/helpers/A_TypeGuards.helper.ts +8 -0
- package/src/index.ts +88 -0
- package/tests/A-Component.test.ts +1 -1
- package/tests/A-Concept.test.ts +58 -10
- package/tests/A-Dependency.test.ts +93 -0
- package/tests/A-Feature.test.ts +11 -11
- package/tests/A-Scope.test.ts +10 -10
- package/tests/A-StepManager.test.ts +60 -11
- package/tsconfig.json +2 -2
- package/tsup.config.ts +32 -0
- package/dist/index.js +0 -112
- package/dist/index.js.map +0 -1
- package/dist/src/constants/env.constants.d.ts +0 -33
- package/dist/src/constants/env.constants.js +0 -47
- package/dist/src/constants/env.constants.js.map +0 -1
- package/dist/src/global/A-Abstraction/A-Abstraction-Extend.decorator.d.ts +0 -23
- package/dist/src/global/A-Abstraction/A-Abstraction-Extend.decorator.js +0 -89
- package/dist/src/global/A-Abstraction/A-Abstraction-Extend.decorator.js.map +0 -1
- package/dist/src/global/A-Abstraction/A-Abstraction.class.d.ts +0 -74
- package/dist/src/global/A-Abstraction/A-Abstraction.class.js +0 -130
- package/dist/src/global/A-Abstraction/A-Abstraction.class.js.map +0 -1
- package/dist/src/global/A-Abstraction/A-Abstraction.error.d.ts +0 -7
- package/dist/src/global/A-Abstraction/A-Abstraction.error.js +0 -12
- package/dist/src/global/A-Abstraction/A-Abstraction.error.js.map +0 -1
- package/dist/src/global/A-Abstraction/A-Abstraction.types.d.ts +0 -38
- package/dist/src/global/A-Abstraction/A-Abstraction.types.js +0 -3
- package/dist/src/global/A-Abstraction/A-Abstraction.types.js.map +0 -1
- package/dist/src/global/A-Caller/A_Caller.class.d.ts +0 -33
- package/dist/src/global/A-Caller/A_Caller.class.js +0 -44
- package/dist/src/global/A-Caller/A_Caller.class.js.map +0 -1
- package/dist/src/global/A-Caller/A_Caller.error.d.ts +0 -7
- package/dist/src/global/A-Caller/A_Caller.error.js +0 -12
- package/dist/src/global/A-Caller/A_Caller.error.js.map +0 -1
- package/dist/src/global/A-Caller/A_Caller.types.d.ts +0 -18
- package/dist/src/global/A-Caller/A_Caller.types.js +0 -3
- package/dist/src/global/A-Caller/A_Caller.types.js.map +0 -1
- package/dist/src/global/A-Component/A-Component.class.d.ts +0 -34
- package/dist/src/global/A-Component/A-Component.class.js +0 -56
- package/dist/src/global/A-Component/A-Component.class.js.map +0 -1
- package/dist/src/global/A-Component/A-Component.constants.d.ts +0 -6
- package/dist/src/global/A-Component/A-Component.constants.js +0 -11
- package/dist/src/global/A-Component/A-Component.constants.js.map +0 -1
- package/dist/src/global/A-Component/A-Component.meta.d.ts +0 -34
- package/dist/src/global/A-Component/A-Component.meta.js +0 -77
- package/dist/src/global/A-Component/A-Component.meta.js.map +0 -1
- package/dist/src/global/A-Component/A-Component.types.d.ts +0 -76
- package/dist/src/global/A-Component/A-Component.types.js +0 -4
- package/dist/src/global/A-Component/A-Component.types.js.map +0 -1
- package/dist/src/global/A-Concept/A-Concept.class.d.ts +0 -153
- package/dist/src/global/A-Concept/A-Concept.class.js +0 -260
- package/dist/src/global/A-Concept/A-Concept.class.js.map +0 -1
- package/dist/src/global/A-Concept/A-Concept.constants.d.ts +0 -33
- package/dist/src/global/A-Concept/A-Concept.constants.js +0 -39
- package/dist/src/global/A-Concept/A-Concept.constants.js.map +0 -1
- package/dist/src/global/A-Concept/A-Concept.meta.d.ts +0 -6
- package/dist/src/global/A-Concept/A-Concept.meta.js +0 -12
- package/dist/src/global/A-Concept/A-Concept.meta.js.map +0 -1
- package/dist/src/global/A-Concept/A-Concept.types.d.ts +0 -66
- package/dist/src/global/A-Concept/A-Concept.types.js +0 -3
- package/dist/src/global/A-Concept/A-Concept.types.js.map +0 -1
- package/dist/src/global/A-Container/A-Container.class.d.ts +0 -52
- package/dist/src/global/A-Container/A-Container.class.js +0 -78
- package/dist/src/global/A-Container/A-Container.class.js.map +0 -1
- package/dist/src/global/A-Container/A-Container.constants.d.ts +0 -6
- package/dist/src/global/A-Container/A-Container.constants.js +0 -11
- package/dist/src/global/A-Container/A-Container.constants.js.map +0 -1
- package/dist/src/global/A-Container/A-Container.meta.d.ts +0 -35
- package/dist/src/global/A-Container/A-Container.meta.js +0 -83
- package/dist/src/global/A-Container/A-Container.meta.js.map +0 -1
- package/dist/src/global/A-Container/A-Container.types.d.ts +0 -75
- package/dist/src/global/A-Container/A-Container.types.js +0 -4
- package/dist/src/global/A-Container/A-Container.types.js.map +0 -1
- package/dist/src/global/A-Context/A-Context.class.d.ts +0 -361
- package/dist/src/global/A-Context/A-Context.class.js +0 -603
- package/dist/src/global/A-Context/A-Context.class.js.map +0 -1
- package/dist/src/global/A-Context/A-Context.error.d.ts +0 -20
- package/dist/src/global/A-Context/A-Context.error.js +0 -25
- package/dist/src/global/A-Context/A-Context.error.js.map +0 -1
- package/dist/src/global/A-Context/A-Context.types.d.ts +0 -5
- package/dist/src/global/A-Context/A-Context.types.js +0 -3
- package/dist/src/global/A-Context/A-Context.types.js.map +0 -1
- package/dist/src/global/A-Dependency/A-DependencyReference.class.d.ts +0 -0
- package/dist/src/global/A-Dependency/A-DependencyReference.class.js +0 -49
- package/dist/src/global/A-Dependency/A-DependencyReference.class.js.map +0 -1
- package/dist/src/global/A-Dependency/A-DependencyReference.types.d.ts +0 -0
- package/dist/src/global/A-Dependency/A-DependencyReference.types.js +0 -58
- package/dist/src/global/A-Dependency/A-DependencyReference.types.js.map +0 -1
- package/dist/src/global/A-Entity/A-Entity.class.d.ts +0 -214
- package/dist/src/global/A-Entity/A-Entity.class.js +0 -281
- package/dist/src/global/A-Entity/A-Entity.class.js.map +0 -1
- package/dist/src/global/A-Entity/A-Entity.constants.d.ts +0 -11
- package/dist/src/global/A-Entity/A-Entity.constants.js +0 -17
- package/dist/src/global/A-Entity/A-Entity.constants.js.map +0 -1
- package/dist/src/global/A-Entity/A-Entity.error.d.ts +0 -7
- package/dist/src/global/A-Entity/A-Entity.error.js +0 -12
- package/dist/src/global/A-Entity/A-Entity.error.js.map +0 -1
- package/dist/src/global/A-Entity/A-Entity.meta.d.ts +0 -11
- package/dist/src/global/A-Entity/A-Entity.meta.js +0 -18
- package/dist/src/global/A-Entity/A-Entity.meta.js.map +0 -1
- package/dist/src/global/A-Entity/A-Entity.types.d.ts +0 -56
- package/dist/src/global/A-Entity/A-Entity.types.js +0 -5
- package/dist/src/global/A-Entity/A-Entity.types.js.map +0 -1
- package/dist/src/global/A-Error/A_Error.class.d.ts +0 -229
- package/dist/src/global/A-Error/A_Error.class.js +0 -296
- package/dist/src/global/A-Error/A_Error.class.js.map +0 -1
- package/dist/src/global/A-Error/A_Error.constants.d.ts +0 -5
- package/dist/src/global/A-Error/A_Error.constants.js +0 -9
- package/dist/src/global/A-Error/A_Error.constants.js.map +0 -1
- package/dist/src/global/A-Error/A_Error.types.d.ts +0 -93
- package/dist/src/global/A-Error/A_Error.types.js +0 -3
- package/dist/src/global/A-Error/A_Error.types.js.map +0 -1
- package/dist/src/global/A-Feature/A-Feature-Define.decorator.d.ts +0 -15
- package/dist/src/global/A-Feature/A-Feature-Define.decorator.js +0 -76
- package/dist/src/global/A-Feature/A-Feature-Define.decorator.js.map +0 -1
- package/dist/src/global/A-Feature/A-Feature-Extend.decorator.d.ts +0 -56
- package/dist/src/global/A-Feature/A-Feature-Extend.decorator.js +0 -119
- package/dist/src/global/A-Feature/A-Feature-Extend.decorator.js.map +0 -1
- package/dist/src/global/A-Feature/A-Feature.class.d.ts +0 -175
- package/dist/src/global/A-Feature/A-Feature.class.js +0 -318
- package/dist/src/global/A-Feature/A-Feature.class.js.map +0 -1
- package/dist/src/global/A-Feature/A-Feature.error.d.ts +0 -25
- package/dist/src/global/A-Feature/A-Feature.error.js +0 -33
- package/dist/src/global/A-Feature/A-Feature.error.js.map +0 -1
- package/dist/src/global/A-Feature/A-Feature.types.d.ts +0 -310
- package/dist/src/global/A-Feature/A-Feature.types.js +0 -26
- package/dist/src/global/A-Feature/A-Feature.types.js.map +0 -1
- package/dist/src/global/A-Fragment/A-Fragment.class.d.ts +0 -36
- package/dist/src/global/A-Fragment/A-Fragment.class.js +0 -46
- package/dist/src/global/A-Fragment/A-Fragment.class.js.map +0 -1
- package/dist/src/global/A-Fragment/A-Fragment.types.d.ts +0 -21
- package/dist/src/global/A-Fragment/A-Fragment.types.js +0 -6
- package/dist/src/global/A-Fragment/A-Fragment.types.js.map +0 -1
- package/dist/src/global/A-Inject/A-Inject.decorator.d.ts +0 -80
- package/dist/src/global/A-Inject/A-Inject.decorator.js +0 -49
- package/dist/src/global/A-Inject/A-Inject.decorator.js.map +0 -1
- package/dist/src/global/A-Inject/A-Inject.error.d.ts +0 -5
- package/dist/src/global/A-Inject/A-Inject.error.js +0 -10
- package/dist/src/global/A-Inject/A-Inject.error.js.map +0 -1
- package/dist/src/global/A-Inject/A-Inject.types.d.ts +0 -42
- package/dist/src/global/A-Inject/A-Inject.types.js +0 -3
- package/dist/src/global/A-Inject/A-Inject.types.js.map +0 -1
- package/dist/src/global/A-Meta/A-Meta.class.d.ts +0 -97
- package/dist/src/global/A-Meta/A-Meta.class.js +0 -164
- package/dist/src/global/A-Meta/A-Meta.class.js.map +0 -1
- package/dist/src/global/A-Meta/A-Meta.types.d.ts +0 -14
- package/dist/src/global/A-Meta/A-Meta.types.js +0 -3
- package/dist/src/global/A-Meta/A-Meta.types.js.map +0 -1
- package/dist/src/global/A-Scope/A-Scope.class.d.ts +0 -466
- package/dist/src/global/A-Scope/A-Scope.class.js +0 -791
- package/dist/src/global/A-Scope/A-Scope.class.js.map +0 -1
- package/dist/src/global/A-Scope/A-Scope.error.d.ts +0 -8
- package/dist/src/global/A-Scope/A-Scope.error.js +0 -13
- package/dist/src/global/A-Scope/A-Scope.error.js.map +0 -1
- package/dist/src/global/A-Scope/A-Scope.types.d.ts +0 -81
- package/dist/src/global/A-Scope/A-Scope.types.js +0 -3
- package/dist/src/global/A-Scope/A-Scope.types.js.map +0 -1
- package/dist/src/global/A-Stage/A-Stage.class.d.ts +0 -112
- package/dist/src/global/A-Stage/A-Stage.class.js +0 -240
- package/dist/src/global/A-Stage/A-Stage.class.js.map +0 -1
- package/dist/src/global/A-Stage/A-Stage.error.d.ts +0 -4
- package/dist/src/global/A-Stage/A-Stage.error.js +0 -11
- package/dist/src/global/A-Stage/A-Stage.error.js.map +0 -1
- package/dist/src/global/A-Stage/A-Stage.types.d.ts +0 -97
- package/dist/src/global/A-Stage/A-Stage.types.js +0 -43
- package/dist/src/global/A-Stage/A-Stage.types.js.map +0 -1
- package/dist/src/global/A-StepManager/A-StepManager.class.d.ts +0 -20
- package/dist/src/global/A-StepManager/A-StepManager.class.js +0 -111
- package/dist/src/global/A-StepManager/A-StepManager.class.js.map +0 -1
- package/dist/src/global/A-StepManager/A-StepManager.error.d.ts +0 -4
- package/dist/src/global/A-StepManager/A-StepManager.error.js +0 -9
- package/dist/src/global/A-StepManager/A-StepManager.error.js.map +0 -1
- package/dist/src/global/ASEID/ASEID.class.d.ts +0 -130
- package/dist/src/global/ASEID/ASEID.class.js +0 -167
- package/dist/src/global/ASEID/ASEID.class.js.map +0 -1
- package/dist/src/global/ASEID/ASEID.constants.d.ts +0 -0
- package/dist/src/global/ASEID/ASEID.constants.js +0 -2
- package/dist/src/global/ASEID/ASEID.constants.js.map +0 -1
- package/dist/src/global/ASEID/ASEID.error.d.ts +0 -5
- package/dist/src/global/ASEID/ASEID.error.js +0 -10
- package/dist/src/global/ASEID/ASEID.error.js.map +0 -1
- package/dist/src/global/ASEID/ASEID.types.d.ts +0 -65
- package/dist/src/global/ASEID/ASEID.types.js +0 -5
- package/dist/src/global/ASEID/ASEID.types.js.map +0 -1
- package/dist/src/helpers/A_Common.helper.d.ts +0 -28
- package/dist/src/helpers/A_Common.helper.js +0 -170
- package/dist/src/helpers/A_Common.helper.js.map +0 -1
- package/dist/src/helpers/A_Formatter.helper.d.ts +0 -35
- package/dist/src/helpers/A_Formatter.helper.js +0 -62
- package/dist/src/helpers/A_Formatter.helper.js.map +0 -1
- package/dist/src/helpers/A_Identity.helper.d.ts +0 -29
- package/dist/src/helpers/A_Identity.helper.js +0 -43
- package/dist/src/helpers/A_Identity.helper.js.map +0 -1
- package/dist/src/helpers/A_TypeGuards.helper.d.ts +0 -207
- package/dist/src/helpers/A_TypeGuards.helper.js +0 -296
- package/dist/src/helpers/A_TypeGuards.helper.js.map +0 -1
- package/dist/src/types/A_Common.types.d.ts +0 -36
- package/dist/src/types/A_Common.types.js +0 -3
- package/dist/src/types/A_Common.types.js.map +0 -1
- package/index.ts +0 -81
- package/src/global/A-Dependency/A-DependencyReference.class.ts +0 -61
- package/src/global/A-Dependency/A-DependencyReference.types.ts +0 -61
- package/trace-require.js +0 -46
- package/tsconfig.build.json +0 -58
|
@@ -28,16 +28,16 @@ export class A_StepsManager {
|
|
|
28
28
|
private prepareSteps(
|
|
29
29
|
entities: Array<A_TYPES__FeatureDefineDecoratorTemplateItem>
|
|
30
30
|
): Array<A_TYPES__A_StageStep> {
|
|
31
|
-
return entities
|
|
32
|
-
|
|
31
|
+
return entities
|
|
32
|
+
.map(step => ({
|
|
33
33
|
...step,
|
|
34
34
|
|
|
35
35
|
behavior: step.behavior || 'sync',
|
|
36
|
-
before: step.before ||
|
|
37
|
-
after: step.after ||
|
|
36
|
+
before: step.before || '',
|
|
37
|
+
after: step.after || '',
|
|
38
|
+
override: step.override || '',
|
|
38
39
|
throwOnError: false
|
|
39
|
-
};
|
|
40
|
-
});
|
|
40
|
+
}));
|
|
41
41
|
}
|
|
42
42
|
|
|
43
43
|
private ID(step: A_TYPES__A_StageStep) {
|
|
@@ -47,36 +47,42 @@ export class A_StepsManager {
|
|
|
47
47
|
private buildGraph() {
|
|
48
48
|
if (this._isBuilt) return;
|
|
49
49
|
this._isBuilt = true;
|
|
50
|
+
|
|
51
|
+
// Filter override
|
|
52
|
+
this.entities = this.entities
|
|
53
|
+
.filter((step, i, self) =>
|
|
54
|
+
!self.some(s => s.override ? new RegExp(s.override).test(this.ID(step)) : false)
|
|
55
|
+
);
|
|
56
|
+
|
|
50
57
|
// Initialize graph nodes
|
|
51
58
|
this.entities.forEach(entity => this.graph.set(this.ID(entity), new Set()));
|
|
52
59
|
|
|
53
60
|
// Add directed edges based on 'before' and 'after'
|
|
54
61
|
this.entities.forEach(entity => {
|
|
55
62
|
const entityId = this.ID(entity);
|
|
56
|
-
const { before = [], after = [] } = entity;
|
|
57
63
|
|
|
58
64
|
// Add edges for 'before' dependencies
|
|
59
65
|
// If entity should execute before targets, then targets depend on entity
|
|
60
66
|
// So we add edges: target -> entity (target depends on entity)
|
|
61
|
-
before
|
|
62
|
-
const targets = this.matchEntities(entityId,
|
|
67
|
+
if (entity.before) {
|
|
68
|
+
const targets = this.matchEntities(entityId, entity.before);
|
|
63
69
|
targets.forEach(target => {
|
|
64
70
|
if (!this.graph.has(target)) this.graph.set(target, new Set());
|
|
65
71
|
this.graph.get(target)!.add(entityId); // target depends on entity
|
|
66
72
|
});
|
|
67
|
-
}
|
|
73
|
+
}
|
|
68
74
|
|
|
69
75
|
// Add edges for 'after' dependencies
|
|
70
76
|
// If entity should execute after sources, then entity depends on sources
|
|
71
77
|
// So we add edges: entity -> source (entity depends on source)
|
|
72
|
-
after
|
|
73
|
-
const sources = this.matchEntities(entityId,
|
|
78
|
+
if (entity.after) {
|
|
79
|
+
const sources = this.matchEntities(entityId, entity.after);
|
|
74
80
|
|
|
75
81
|
sources.forEach(source => {
|
|
76
82
|
if (!this.graph.has(entityId)) this.graph.set(entityId, new Set());
|
|
77
83
|
this.graph.get(entityId)!.add(source); // entity depends on source
|
|
78
84
|
});
|
|
79
|
-
}
|
|
85
|
+
}
|
|
80
86
|
});
|
|
81
87
|
}
|
|
82
88
|
|
|
@@ -201,4 +201,105 @@ export class A_CommonHelper {
|
|
|
201
201
|
// For any other cases
|
|
202
202
|
throw new Error('Unable to clone the object. Unsupported type.');
|
|
203
203
|
}
|
|
204
|
+
|
|
205
|
+
/**
|
|
206
|
+
* Get a readable name for a component (string, class, function, React element, instance, etc.)
|
|
207
|
+
*
|
|
208
|
+
* Covers:
|
|
209
|
+
* - string tags ("div")
|
|
210
|
+
* - symbols (Symbol.for('xxx'))
|
|
211
|
+
* - functions and classes (with name or displayName)
|
|
212
|
+
* - React elements (object with `type`)
|
|
213
|
+
* - component instances (constructor.name)
|
|
214
|
+
* - objects with custom toString returning meaningful info
|
|
215
|
+
*
|
|
216
|
+
* Falls back to sensible defaults ("Unknown" / "Anonymous").
|
|
217
|
+
*/
|
|
218
|
+
static getComponentName(component: any): string {
|
|
219
|
+
const UNKNOWN = 'Unknown';
|
|
220
|
+
const ANONYMOUS = 'Anonymous';
|
|
221
|
+
|
|
222
|
+
if (component === null || component === undefined) {
|
|
223
|
+
return UNKNOWN;
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
// Strings (HTML tags or explicit names)
|
|
227
|
+
if (typeof component === 'string') {
|
|
228
|
+
return component || UNKNOWN;
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
// Symbols
|
|
232
|
+
if (typeof component === 'symbol') {
|
|
233
|
+
try {
|
|
234
|
+
return component.toString();
|
|
235
|
+
} catch {
|
|
236
|
+
return UNKNOWN;
|
|
237
|
+
}
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
// Arrays - try to derive from first element
|
|
241
|
+
if (Array.isArray(component)) {
|
|
242
|
+
if (component.length === 0) return UNKNOWN;
|
|
243
|
+
return this.getComponentName(component[0]);
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
// Functions and classes
|
|
247
|
+
if (typeof component === 'function') {
|
|
248
|
+
const fnAny = component as any;
|
|
249
|
+
// Common React convention
|
|
250
|
+
if (fnAny.displayName) return String(fnAny.displayName);
|
|
251
|
+
if (fnAny.name) return String(fnAny.name);
|
|
252
|
+
|
|
253
|
+
// Try to extract a name from source if possible
|
|
254
|
+
try {
|
|
255
|
+
const src = Function.prototype.toString.call(component);
|
|
256
|
+
// class Foo { ... } or function foo() { ... } or foo => ...
|
|
257
|
+
const match = src.match(/^(?:class\s+([A-Za-z0-9_$]+)|function\s+([A-Za-z0-9_$]+)|([A-Za-z0-9_$]+)\s*=>)/);
|
|
258
|
+
if (match) {
|
|
259
|
+
return match[1] || match[2] || match[3] || ANONYMOUS;
|
|
260
|
+
}
|
|
261
|
+
} catch {
|
|
262
|
+
// fallthrough
|
|
263
|
+
}
|
|
264
|
+
return ANONYMOUS;
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
// Objects (instances, React elements, plain objects)
|
|
268
|
+
if (typeof component === 'object') {
|
|
269
|
+
const objAny = component as any;
|
|
270
|
+
|
|
271
|
+
// React element: { type: ComponentOrString, props: ... }
|
|
272
|
+
if (objAny.type) {
|
|
273
|
+
return this.getComponentName(objAny.type);
|
|
274
|
+
}
|
|
275
|
+
|
|
276
|
+
// React forwardRef / memo wrappers often expose displayName
|
|
277
|
+
if (objAny.displayName) return String(objAny.displayName);
|
|
278
|
+
if (objAny.name) return String(objAny.name);
|
|
279
|
+
|
|
280
|
+
// Instance: use constructor name if available and not Object
|
|
281
|
+
if (objAny.constructor && objAny.constructor.name && objAny.constructor.name !== 'Object') {
|
|
282
|
+
return String(objAny.constructor.name);
|
|
283
|
+
}
|
|
284
|
+
|
|
285
|
+
// If object implements a meaningful toString, try it
|
|
286
|
+
try {
|
|
287
|
+
const s = objAny.toString();
|
|
288
|
+
if (typeof s === 'string' && s !== '[object Object]') {
|
|
289
|
+
return s;
|
|
290
|
+
}
|
|
291
|
+
} catch {
|
|
292
|
+
// ignore
|
|
293
|
+
}
|
|
294
|
+
|
|
295
|
+
return ANONYMOUS;
|
|
296
|
+
}
|
|
297
|
+
|
|
298
|
+
// Fallback for other types
|
|
299
|
+
try {
|
|
300
|
+
return String(component);
|
|
301
|
+
} catch {
|
|
302
|
+
return UNKNOWN;
|
|
303
|
+
}
|
|
304
|
+
}
|
|
204
305
|
}
|
|
@@ -315,6 +315,14 @@ export class A_TypeGuards {
|
|
|
315
315
|
|| A_TypeGuards.isComponentInstance(param);
|
|
316
316
|
}
|
|
317
317
|
|
|
318
|
+
static isAllowedForDependencyDefaultCreation(param: any): param is A_TYPES__Entity_Constructor | A_TYPES__Component_Constructor {
|
|
319
|
+
return A_TypeGuards.isComponentConstructor(param)
|
|
320
|
+
|| A_CommonHelper.isInheritedFrom(param, A_Component)
|
|
321
|
+
|| A_TypeGuards.isEntityConstructor(param)
|
|
322
|
+
|| A_CommonHelper.isInheritedFrom(param, A_Entity)
|
|
323
|
+
|
|
324
|
+
}
|
|
325
|
+
|
|
318
326
|
/**
|
|
319
327
|
* Allows to check if the provided param is of constructor type.
|
|
320
328
|
*
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
// =================================================================================================
|
|
2
|
+
// ============================= Export Framework Components =======================================
|
|
3
|
+
// =================================================================================================
|
|
4
|
+
export * from './constants/env.constants';
|
|
5
|
+
export * from './types/A_Common.types';
|
|
6
|
+
|
|
7
|
+
// ---------------------- Major Components ----------------------
|
|
8
|
+
export { A_Context } from './global/A-Context/A-Context.class';
|
|
9
|
+
export * from './global/A-Context/A-Context.types';
|
|
10
|
+
|
|
11
|
+
export { A_Concept } from './global/A-Concept/A-Concept.class';
|
|
12
|
+
export { A_ConceptMeta } from './global/A-Concept/A-Concept.meta';
|
|
13
|
+
export * from './global/A-Concept/A-Concept.types';
|
|
14
|
+
|
|
15
|
+
export { A_Container } from './global/A-Container/A-Container.class';
|
|
16
|
+
export { A_ContainerMeta } from './global/A-Container/A-Container.meta';
|
|
17
|
+
export * from './global/A-Container/A-Container.class';
|
|
18
|
+
|
|
19
|
+
export { A_Component } from './global/A-Component/A-Component.class';
|
|
20
|
+
export { A_ComponentMeta } from './global/A-Component/A-Component.meta';
|
|
21
|
+
export * from './global/A-Component/A-Component.types';
|
|
22
|
+
|
|
23
|
+
export { A_Entity } from './global/A-Entity/A-Entity.class';
|
|
24
|
+
export * from './global/A-Entity/A-Entity.types';
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
// ---------------------- Common Components ----------------------
|
|
28
|
+
export { A_Abstraction } from './global/A-Abstraction/A-Abstraction.class';
|
|
29
|
+
export { A_AbstractionError } from './global/A-Abstraction/A-Abstraction.error';
|
|
30
|
+
export * from './global/A-Abstraction/A-Abstraction.types';
|
|
31
|
+
|
|
32
|
+
export { A_Caller } from './global/A-Caller/A_Caller.class';
|
|
33
|
+
export { A_CallerError } from './global/A-Caller/A_Caller.error';
|
|
34
|
+
export * from './global/A-Caller/A_Caller.types';
|
|
35
|
+
|
|
36
|
+
export { A_Error } from './global/A-Error/A_Error.class';
|
|
37
|
+
export * from './global/A-Error/A_Error.types';
|
|
38
|
+
|
|
39
|
+
export { ASEID } from './global/ASEID/ASEID.class';
|
|
40
|
+
export { ASEID_Error } from './global/ASEID/ASEID.error';
|
|
41
|
+
export * from './global/ASEID/ASEID.types';
|
|
42
|
+
|
|
43
|
+
export { A_Feature } from './global/A-Feature/A-Feature.class';
|
|
44
|
+
export { A_FeatureError } from './global/A-Feature/A-Feature.error';
|
|
45
|
+
export * from './global/A-Feature/A-Feature.types';
|
|
46
|
+
|
|
47
|
+
export { A_Stage } from './global/A-Stage/A-Stage.class';
|
|
48
|
+
export { A_StageError } from './global/A-Stage/A-Stage.error';
|
|
49
|
+
export * from './global/A-Stage/A-Stage.types';
|
|
50
|
+
|
|
51
|
+
export { A_Scope } from './global/A-Scope/A-Scope.class';
|
|
52
|
+
export { A_ScopeError } from './global/A-Scope/A-Scope.error';
|
|
53
|
+
export * from './global/A-Scope/A-Scope.types';
|
|
54
|
+
|
|
55
|
+
export { A_Meta } from './global/A-Meta/A-Meta.class';
|
|
56
|
+
export * from './global/A-Meta/A-Meta.types';
|
|
57
|
+
|
|
58
|
+
export { A_Fragment } from './global/A-Fragment/A-Fragment.class';
|
|
59
|
+
export * from './global/A-Fragment/A-Fragment.types';
|
|
60
|
+
|
|
61
|
+
export { A_Dependency } from './global/A-Dependency/A-Dependency.class';
|
|
62
|
+
export { A_DependencyError } from './global/A-Dependency/A-Dependency.error';
|
|
63
|
+
export * from './global/A-Dependency/A-Dependency.types';
|
|
64
|
+
|
|
65
|
+
|
|
66
|
+
// =================================================================================================
|
|
67
|
+
// =============================== Export Decorators ===============================================
|
|
68
|
+
// =================================================================================================
|
|
69
|
+
export { A_Inject } from './global/A-Inject/A-Inject.decorator';
|
|
70
|
+
export * from './global/A-Inject/A-Inject.types';
|
|
71
|
+
export { A_Feature_Define } from './global/A-Feature/A-Feature-Define.decorator';
|
|
72
|
+
export { A_Feature_Extend } from './global/A-Feature/A-Feature-Extend.decorator';
|
|
73
|
+
export { A_Abstraction_Extend } from './global/A-Abstraction/A-Abstraction-Extend.decorator';
|
|
74
|
+
export { A_Dependency_Require } from './global/A-Dependency/A-Dependency-Require.decorator';
|
|
75
|
+
export { A_Dependency_Load } from './global/A-Dependency/A-Dependency-Load.decorator';
|
|
76
|
+
export { A_Dependency_Default } from './global/A-Dependency/A-Dependency-Default.decorator';
|
|
77
|
+
|
|
78
|
+
|
|
79
|
+
// =================================================================================================
|
|
80
|
+
// =============================== Export Helpers ================================================
|
|
81
|
+
// =================================================================================================
|
|
82
|
+
export { A_CommonHelper } from './helpers/A_Common.helper';
|
|
83
|
+
export { A_FormatterHelper } from './helpers/A_Formatter.helper';
|
|
84
|
+
export { A_IdentityHelper, A_ID_TYPES__TimeId_Parts } from './helpers/A_Identity.helper';
|
|
85
|
+
export { A_StepsManager } from './global/A-StepManager/A-StepManager.class';
|
|
86
|
+
export { A_StepManagerError } from './global/A-StepManager/A-StepManager.error';
|
|
87
|
+
export { A_TypeGuards } from './helpers/A_TypeGuards.helper';
|
|
88
|
+
|
|
@@ -27,7 +27,7 @@ describe('A-Component tests', () => {
|
|
|
27
27
|
A_Context.root.register(MyComponent);
|
|
28
28
|
A_Context.root.register(DependentComponent);
|
|
29
29
|
|
|
30
|
-
const dependentComponent = A_Context.root.resolve(DependentComponent)
|
|
30
|
+
const dependentComponent = A_Context.root.resolve(DependentComponent)!;
|
|
31
31
|
|
|
32
32
|
expect(dependentComponent.dependency).toBeInstanceOf(MyComponent);
|
|
33
33
|
});
|
package/tests/A-Concept.test.ts
CHANGED
|
@@ -1,11 +1,16 @@
|
|
|
1
|
+
import { A_Caller } from '@adaas/a-concept/global/A-Caller/A_Caller.class';
|
|
1
2
|
import './test.setup';
|
|
2
3
|
import { A_Component } from "@adaas/a-concept/global/A-Component/A-Component.class";
|
|
3
4
|
import { A_Concept } from "@adaas/a-concept/global/A-Concept/A-Concept.class";
|
|
4
5
|
import { A_Container } from "@adaas/a-concept/global/A-Container/A-Container.class";
|
|
5
6
|
import { A_Context } from "@adaas/a-concept/global/A-Context/A-Context.class";
|
|
6
7
|
import { A_Entity } from "@adaas/a-concept/global/A-Entity/A-Entity.class";
|
|
8
|
+
import { A_TYPES__Entity_Init, A_TYPES__Entity_Serialized } from '@adaas/a-concept/global/A-Entity/A-Entity.types';
|
|
7
9
|
import { A_Fragment } from "@adaas/a-concept/global/A-Fragment/A-Fragment.class";
|
|
10
|
+
import { A_Inject } from '@adaas/a-concept/global/A-Inject/A-Inject.decorator';
|
|
8
11
|
import { A_Scope } from "@adaas/a-concept/global/A-Scope/A-Scope.class";
|
|
12
|
+
import { A_Feature } from '@adaas/a-concept/global/A-Feature/A-Feature.class';
|
|
13
|
+
import { A_TYPES__EntityFeatures } from '@adaas/a-concept/global/A-Entity/A-Entity.constants';
|
|
9
14
|
|
|
10
15
|
|
|
11
16
|
jest.retryTimes(0);
|
|
@@ -93,19 +98,18 @@ describe('A-Concept tests', () => {
|
|
|
93
98
|
const containerBScope = A_Context.scope(containerB)
|
|
94
99
|
|
|
95
100
|
expect(containerAScope.resolveConstructor('MyEntityA')).toBe(MyEntityA);
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
}).toThrow();
|
|
101
|
+
const undefinedMyEntityB = containerAScope.resolveConstructor('MyEntityB');
|
|
102
|
+
expect(undefinedMyEntityB).toBeUndefined();
|
|
99
103
|
|
|
100
104
|
expect(containerBScope.resolveConstructor('MyEntityB')).toBe(MyEntityB);
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
105
|
+
const undefinedMyEntityA = containerBScope.resolveConstructor('MyEntityA');
|
|
106
|
+
|
|
107
|
+
expect(undefinedMyEntityA).toBeUndefined();
|
|
104
108
|
|
|
105
109
|
expect(concept.scope.resolve(MyContext)).toEqual(sharedContext);
|
|
106
110
|
expect(concept.scope.resolve(MyContext)).toEqual(sharedContext);
|
|
107
111
|
});
|
|
108
|
-
|
|
112
|
+
it('Should allow to register multiple containers', async () => {
|
|
109
113
|
A_Context.reset();
|
|
110
114
|
|
|
111
115
|
class MyContainerA extends A_Container { }
|
|
@@ -123,9 +127,53 @@ describe('A-Concept tests', () => {
|
|
|
123
127
|
});
|
|
124
128
|
|
|
125
129
|
expect(containerA.scope.resolve(MyContainerA)).toBeInstanceOf(MyContainerA);
|
|
126
|
-
expect(containerB.scope.resolve(MyContainerB)).toBeInstanceOf(MyContainerB);
|
|
130
|
+
expect(containerB.scope.resolve(MyContainerB)).toBeInstanceOf(MyContainerB);
|
|
131
|
+
})
|
|
132
|
+
it('Should have different entity behavior depending on the container', async () => {
|
|
133
|
+
A_Context.reset();
|
|
134
|
+
class MyEntityA extends A_Entity { testValue!: string; }
|
|
135
|
+
|
|
136
|
+
class ComponentA extends A_Component {
|
|
137
|
+
@A_Feature.Extend({ name: A_TYPES__EntityFeatures.LOAD })
|
|
138
|
+
async createEntityInstance(
|
|
139
|
+
@A_Inject(A_Caller) caller: MyEntityA
|
|
140
|
+
) {
|
|
141
|
+
caller.testValue = 'ContainerA';
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
class ComponentB extends A_Component {
|
|
146
|
+
@A_Feature.Extend({ name: A_TYPES__EntityFeatures.LOAD })
|
|
147
|
+
async createEntityInstance(
|
|
148
|
+
@A_Inject(A_Caller) caller: MyEntityA
|
|
149
|
+
) {
|
|
150
|
+
caller.testValue = 'ContainerB';
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
const containerA = new A_Container({ name: 'ContainerA', components: [ComponentA], entities: [MyEntityA] });
|
|
155
|
+
const containerB = new A_Container({ name: 'ContainerB', components: [ComponentB], entities: [MyEntityA] });
|
|
156
|
+
|
|
157
|
+
const concept = new A_Concept({
|
|
158
|
+
name: 'TestConcept',
|
|
159
|
+
containers: [
|
|
160
|
+
containerA,
|
|
161
|
+
containerB
|
|
162
|
+
]
|
|
163
|
+
});
|
|
164
|
+
|
|
165
|
+
const entityFromContainerA = new MyEntityA();
|
|
166
|
+
const entityFromContainerB = new MyEntityA();
|
|
167
|
+
|
|
168
|
+
// with registration
|
|
169
|
+
containerB.scope.register(entityFromContainerB)
|
|
170
|
+
await entityFromContainerB.load();
|
|
171
|
+
|
|
172
|
+
// without registration
|
|
173
|
+
await entityFromContainerA.load(containerA.scope);
|
|
127
174
|
|
|
128
|
-
|
|
129
|
-
|
|
175
|
+
expect(entityFromContainerA.testValue).toBe('ContainerA');
|
|
176
|
+
expect(entityFromContainerB.testValue).toBe('ContainerB');
|
|
177
|
+
})
|
|
130
178
|
|
|
131
179
|
});
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
import { A_Component, A_Dependency, A_Entity, A_Error, A_Inject, A_Scope, A_ScopeError } from "../src";
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
describe('A-Dependency tests', () => {
|
|
6
|
+
|
|
7
|
+
it('Should Allow to define a dependency', async () => {
|
|
8
|
+
|
|
9
|
+
class Test extends A_Component {
|
|
10
|
+
constructor(
|
|
11
|
+
@A_Dependency.Required()
|
|
12
|
+
@A_Inject(A_Component) component: A_Component,
|
|
13
|
+
) {
|
|
14
|
+
super();
|
|
15
|
+
expect(component).toBeInstanceOf(A_Component);
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
});
|
|
19
|
+
it('Should Resolve a component with undefined dependency', async () => {
|
|
20
|
+
class DependencyRequiredComponent extends A_Component { }
|
|
21
|
+
|
|
22
|
+
class Test extends A_Component {
|
|
23
|
+
constructor(
|
|
24
|
+
@A_Inject(DependencyRequiredComponent) public component?: A_Component,
|
|
25
|
+
) {
|
|
26
|
+
super();
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
const scope = new A_Scope({ components: [Test] });
|
|
31
|
+
const instance = scope.resolve(Test);
|
|
32
|
+
|
|
33
|
+
expect(instance).toBeDefined();
|
|
34
|
+
expect(instance).toBeInstanceOf(Test);
|
|
35
|
+
expect(instance!.component).toBeUndefined();
|
|
36
|
+
|
|
37
|
+
});
|
|
38
|
+
it('Should throw an error if required dependency is not provided', async () => {
|
|
39
|
+
class DependencyRequiredComponent extends A_Component { }
|
|
40
|
+
|
|
41
|
+
class Test extends A_Component {
|
|
42
|
+
constructor(
|
|
43
|
+
@A_Dependency.Required()
|
|
44
|
+
@A_Inject(DependencyRequiredComponent) component: A_Component,
|
|
45
|
+
) {
|
|
46
|
+
super();
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
const scope = new A_Scope({ components: [Test] });
|
|
51
|
+
|
|
52
|
+
try {
|
|
53
|
+
scope.resolve(Test);
|
|
54
|
+
} catch (error) {
|
|
55
|
+
expect(error).toBeInstanceOf(A_ScopeError);
|
|
56
|
+
expect((error as A_ScopeError).title).toBe(A_ScopeError.ResolutionError);
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
const dependency = scope.resolve(DependencyRequiredComponent);
|
|
60
|
+
|
|
61
|
+
expect(dependency).toBeUndefined();
|
|
62
|
+
});
|
|
63
|
+
it('Should resolve a component if it has default constructor for dependency', async () => {
|
|
64
|
+
class MyCustomEntity extends A_Entity<{ foo: string }> {
|
|
65
|
+
foo!: string;
|
|
66
|
+
|
|
67
|
+
fromNew(newEntity: { foo: string; }): void {
|
|
68
|
+
super.fromNew(newEntity);
|
|
69
|
+
this.foo = newEntity.foo;
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
class TestC extends A_Component {
|
|
74
|
+
constructor(
|
|
75
|
+
@A_Dependency.Default({ foo: 'bar' })
|
|
76
|
+
@A_Dependency.Required()
|
|
77
|
+
@A_Inject(MyCustomEntity) public component: MyCustomEntity,
|
|
78
|
+
) {
|
|
79
|
+
super();
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
const scope = new A_Scope({ components: [TestC], entities: [MyCustomEntity] });
|
|
84
|
+
|
|
85
|
+
const instance = scope.resolve(TestC);
|
|
86
|
+
|
|
87
|
+
expect(instance).toBeDefined();
|
|
88
|
+
expect(instance).toBeInstanceOf(TestC);
|
|
89
|
+
expect(instance!.component).toBeInstanceOf(MyCustomEntity);
|
|
90
|
+
expect(instance!.component.foo).toBe('bar');
|
|
91
|
+
});
|
|
92
|
+
|
|
93
|
+
});
|
package/tests/A-Feature.test.ts
CHANGED
|
@@ -63,8 +63,8 @@ describe('A-Feature tests', () => {
|
|
|
63
63
|
component: MyExtendedComponent,
|
|
64
64
|
handler: 'testHandler',
|
|
65
65
|
behavior: 'sync',
|
|
66
|
-
before:
|
|
67
|
-
after:
|
|
66
|
+
before: '',
|
|
67
|
+
after: ''
|
|
68
68
|
},
|
|
69
69
|
{
|
|
70
70
|
name: 'MyExtendedComponent.testHandler',
|
|
@@ -82,7 +82,7 @@ describe('A-Feature tests', () => {
|
|
|
82
82
|
scope.register(MyComponent);
|
|
83
83
|
|
|
84
84
|
// 4) create an instance of the component from the scope
|
|
85
|
-
const myComponent = scope.resolve(MyComponent)
|
|
85
|
+
const myComponent = scope.resolve(MyComponent)!;
|
|
86
86
|
expect(myComponent).toBeInstanceOf(MyComponent);
|
|
87
87
|
expect(myComponent.sum).toBe(0);
|
|
88
88
|
|
|
@@ -115,8 +115,8 @@ describe('A-Feature tests', () => {
|
|
|
115
115
|
component: 'MyExtendedComponent2',
|
|
116
116
|
handler: 'testHandler',
|
|
117
117
|
behavior: 'sync',
|
|
118
|
-
before:
|
|
119
|
-
after:
|
|
118
|
+
before: '',
|
|
119
|
+
after: ''
|
|
120
120
|
}]
|
|
121
121
|
})
|
|
122
122
|
async testHandler() { }
|
|
@@ -129,7 +129,7 @@ describe('A-Feature tests', () => {
|
|
|
129
129
|
scope.register(MyComponent2);
|
|
130
130
|
|
|
131
131
|
// 4) create an instance of the component from the scope
|
|
132
|
-
const myComponent = scope.resolve(MyComponent2)
|
|
132
|
+
const myComponent = scope.resolve(MyComponent2)!;
|
|
133
133
|
expect(myComponent).toBeInstanceOf(MyComponent2);
|
|
134
134
|
expect(myComponent.sum).toBe(0);
|
|
135
135
|
|
|
@@ -179,7 +179,7 @@ describe('A-Feature tests', () => {
|
|
|
179
179
|
const scope = new A_Scope({ name: 'TestScope', components: [My_Component] });
|
|
180
180
|
|
|
181
181
|
// 3) create an instance of the component from the scope
|
|
182
|
-
const myComponent = scope.resolve(My_Component)
|
|
182
|
+
const myComponent = scope.resolve(My_Component)!;
|
|
183
183
|
expect(myComponent).toBeInstanceOf(My_Component);
|
|
184
184
|
|
|
185
185
|
// 4) call the feature caller to execute the feature
|
|
@@ -220,7 +220,7 @@ describe('A-Feature tests', () => {
|
|
|
220
220
|
const scope = new A_Scope({ name: 'TestScope', components: [My_Component] });
|
|
221
221
|
|
|
222
222
|
// 3) create an instance of the component from the scope
|
|
223
|
-
const myComponent = scope.resolve(My_Component)
|
|
223
|
+
const myComponent = scope.resolve(My_Component)!;
|
|
224
224
|
expect(myComponent).toBeInstanceOf(My_Component);
|
|
225
225
|
|
|
226
226
|
// 4) call the feature caller to execute the feature
|
|
@@ -271,7 +271,7 @@ describe('A-Feature tests', () => {
|
|
|
271
271
|
const scope = new A_Scope({ name: 'TestScope', components: [My_Component] });
|
|
272
272
|
|
|
273
273
|
// 3) create an instance of the component from the scope
|
|
274
|
-
const myComponent = scope.resolve(My_Component)
|
|
274
|
+
const myComponent = scope.resolve(My_Component)!;
|
|
275
275
|
expect(myComponent).toBeInstanceOf(My_Component);
|
|
276
276
|
|
|
277
277
|
// 4) call the feature caller to execute the feature
|
|
@@ -313,7 +313,7 @@ describe('A-Feature tests', () => {
|
|
|
313
313
|
const scope = new A_Scope({ name: 'TestScope', components: [My_Child_Component] });
|
|
314
314
|
|
|
315
315
|
// 3) create an instance of the component from the scope
|
|
316
|
-
const myComponent = scope.resolve(My_Child_Component)
|
|
316
|
+
const myComponent = scope.resolve(My_Child_Component)!;
|
|
317
317
|
expect(myComponent).toBeInstanceOf(My_Child_Component);
|
|
318
318
|
|
|
319
319
|
await myComponent.feature1();
|
|
@@ -357,7 +357,7 @@ describe('A-Feature tests', () => {
|
|
|
357
357
|
const scope = new A_Scope({ name: 'TestScope', components: [My_Child_Component] });
|
|
358
358
|
|
|
359
359
|
// 3) create an instance of the component from the scope
|
|
360
|
-
const myComponent = scope.resolve(My_Child_Component)
|
|
360
|
+
const myComponent = scope.resolve(My_Child_Component)!;
|
|
361
361
|
expect(myComponent).toBeInstanceOf(My_Child_Component);
|
|
362
362
|
|
|
363
363
|
await myComponent.feature1();
|
package/tests/A-Scope.test.ts
CHANGED
|
@@ -32,9 +32,10 @@ describe('A-Scope tests', () => {
|
|
|
32
32
|
const resolved = scope.resolve(A_Component);
|
|
33
33
|
expect(resolved).toBe(component);
|
|
34
34
|
});
|
|
35
|
-
it('Should return an
|
|
35
|
+
it('Should return an undefined when resolving a non-registered component', async () => {
|
|
36
36
|
const scope = new A_Scope({ name: 'TestScope' });
|
|
37
|
-
|
|
37
|
+
const resolved = scope.resolve(A_Component);
|
|
38
|
+
expect(resolved).toBeUndefined();
|
|
38
39
|
});
|
|
39
40
|
it('Should allow to register and resolve a component with dependencies', async () => {
|
|
40
41
|
class DependentComponent extends A_Component {
|
|
@@ -50,7 +51,7 @@ describe('A-Scope tests', () => {
|
|
|
50
51
|
scope.register(component);
|
|
51
52
|
scope.register(new DependentComponent(component));
|
|
52
53
|
|
|
53
|
-
const resolved = scope.resolve(DependentComponent)
|
|
54
|
+
const resolved = scope.resolve(DependentComponent)!;
|
|
54
55
|
expect(resolved).toBeInstanceOf(DependentComponent);
|
|
55
56
|
expect(resolved.dependency).toBe(component);
|
|
56
57
|
});
|
|
@@ -188,11 +189,10 @@ describe('A-Scope tests', () => {
|
|
|
188
189
|
expect(resolved2).toBe(MyEntity);
|
|
189
190
|
expect(resolved3).toBe(MyEntity);
|
|
190
191
|
|
|
191
|
-
|
|
192
|
-
|
|
192
|
+
const wrongConstructor = scope.resolveConstructor<MyEntity>('mya__entity');
|
|
193
|
+
|
|
194
|
+
expect(wrongConstructor).toBeUndefined();
|
|
193
195
|
|
|
194
|
-
console.log('RESOLVED:::: ', res)
|
|
195
|
-
}).toThrow();
|
|
196
196
|
|
|
197
197
|
const instance = new resolved();
|
|
198
198
|
|
|
@@ -221,9 +221,9 @@ describe('A-Scope tests', () => {
|
|
|
221
221
|
expect(resolved2).toBe(MyEntity);
|
|
222
222
|
expect(resolved3).toBe(MyEntity);
|
|
223
223
|
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
224
|
+
const wrongConstructor = scope.resolveConstructor<MyEntity>('myS-entity');
|
|
225
|
+
|
|
226
|
+
expect(wrongConstructor).toBeUndefined();
|
|
227
227
|
|
|
228
228
|
|
|
229
229
|
const instance = new resolved({ foo: 'bar' });
|