@adaas/a-concept 0.1.3 → 0.1.5
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/src/global/A-Abstraction/A-Abstraction-Extend.decorator.js +5 -4
- package/dist/src/global/A-Abstraction/A-Abstraction-Extend.decorator.js.map +1 -1
- package/dist/src/global/A-Abstraction/A-Abstraction.class.d.ts +2 -1
- package/dist/src/global/A-Abstraction/A-Abstraction.class.js +7 -1
- package/dist/src/global/A-Abstraction/A-Abstraction.class.js.map +1 -1
- package/dist/src/global/A-Abstraction/A-Abstraction.types.d.ts +2 -1
- package/dist/src/global/A-Component/A-Component.meta.js +1 -1
- package/dist/src/global/A-Component/A-Component.meta.js.map +1 -1
- package/dist/src/global/A-Container/A-Container.constants.d.ts +2 -1
- package/dist/src/global/A-Container/A-Container.constants.js +1 -0
- package/dist/src/global/A-Container/A-Container.constants.js.map +1 -1
- package/dist/src/global/A-Container/A-Container.meta.d.ts +11 -3
- package/dist/src/global/A-Container/A-Container.meta.js +25 -0
- package/dist/src/global/A-Container/A-Container.meta.js.map +1 -1
- package/dist/src/global/A-Container/A-Container.types.d.ts +24 -1
- package/dist/src/global/A-Context/A-Context.class.d.ts +6 -14
- package/dist/src/global/A-Context/A-Context.class.js +16 -20
- package/dist/src/global/A-Context/A-Context.class.js.map +1 -1
- package/dist/src/global/A-Feature/A-Feature.class.d.ts +1 -1
- package/dist/src/global/A-Feature/A-Feature.class.js +6 -4
- package/dist/src/global/A-Feature/A-Feature.class.js.map +1 -1
- package/dist/src/global/A-Feature/A-Feature.types.d.ts +9 -2
- package/dist/src/global/A-Feature/A-Feature.types.js.map +1 -1
- package/dist/src/global/A-Scope/A-Scope.class.d.ts +8 -2
- package/dist/src/global/A-Scope/A-Scope.class.js +23 -3
- package/dist/src/global/A-Scope/A-Scope.class.js.map +1 -1
- package/dist/src/global/A-Scope/A-Scope.error.d.ts +1 -0
- package/dist/src/global/A-Scope/A-Scope.error.js +1 -0
- package/dist/src/global/A-Scope/A-Scope.error.js.map +1 -1
- package/dist/src/global/A-Scope/A-Scope.types.d.ts +7 -1
- package/dist/src/global/A-Stage/A-Stage.class.js.map +1 -1
- package/dist/src/helpers/A_TypeGuards.helper.d.ts +3 -1
- package/dist/src/helpers/A_TypeGuards.helper.js +10 -2
- package/dist/src/helpers/A_TypeGuards.helper.js.map +1 -1
- package/package.json +1 -1
- package/src/global/A-Abstraction/A-Abstraction-Extend.decorator.ts +5 -4
- package/src/global/A-Abstraction/A-Abstraction.class.ts +12 -2
- package/src/global/A-Abstraction/A-Abstraction.types.ts +2 -1
- package/src/global/A-Component/A-Component.meta.ts +1 -1
- package/src/global/A-Container/A-Container.constants.ts +1 -0
- package/src/global/A-Container/A-Container.meta.ts +38 -3
- package/src/global/A-Container/A-Container.types.ts +27 -2
- package/src/global/A-Context/A-Context.class.ts +22 -21
- package/src/global/A-Feature/A-Feature.class.ts +7 -5
- package/src/global/A-Feature/A-Feature.types.ts +9 -2
- package/src/global/A-Scope/A-Scope.class.ts +68 -16
- package/src/global/A-Scope/A-Scope.error.ts +1 -0
- package/src/global/A-Scope/A-Scope.types.ts +7 -3
- package/src/global/A-Stage/A-Stage.class.ts +0 -1
- package/src/helpers/A_TypeGuards.helper.ts +12 -3
- package/tests/A-Abstraction.test.ts +72 -0
- package/tests/A-Common.test.ts +2 -1
- package/tests/A-Scope.test.ts +1 -1
- package/tsconfig.json +2 -2
|
@@ -36,6 +36,7 @@ import { A_FormatterHelper } from "@adaas/a-concept/helpers/A_Formatter.helper";
|
|
|
36
36
|
import { A_Fragment } from "../A-Fragment/A-Fragment.class";
|
|
37
37
|
import { A_TYPES__InjectableTargets } from "../A-Inject/A-Inject.types";
|
|
38
38
|
import { A_TYPES__ConceptAbstraction } from "../A-Concept/A-Concept.types";
|
|
39
|
+
import { A_TYPES__ConceptAbstractions } from "../A-Concept/A-Concept.constants";
|
|
39
40
|
|
|
40
41
|
|
|
41
42
|
|
|
@@ -577,7 +578,7 @@ export class A_Context {
|
|
|
577
578
|
/**
|
|
578
579
|
* Provide the scope that dictates which components are active and can provide extensions for the feature.
|
|
579
580
|
*/
|
|
580
|
-
scope: A_Scope
|
|
581
|
+
scope: A_Scope = this.scope(component)
|
|
581
582
|
): Array<A_TYPES__A_StageStep> {
|
|
582
583
|
// name for error messages
|
|
583
584
|
const componentName = (component as any)?.constructor?.name || String(component);
|
|
@@ -643,18 +644,22 @@ export class A_Context {
|
|
|
643
644
|
const steps: A_TYPES__A_StageStep[] = [];
|
|
644
645
|
|
|
645
646
|
// We need to get all components that has extensions for the feature in component
|
|
646
|
-
for (const [
|
|
647
|
+
for (const [cmp, meta] of instance._metaStorage) {
|
|
647
648
|
// Just try to make sure that component not only Indexed but also presented in scope
|
|
648
|
-
if (scope.has(
|
|
649
|
+
if (scope.has(cmp) && (
|
|
650
|
+
A_TypeGuards.isComponentMetaInstance(meta)
|
|
651
|
+
|| A_TypeGuards.isContainerMetaInstance(meta)
|
|
652
|
+
)) {
|
|
649
653
|
// Get all extensions for the feature
|
|
650
654
|
meta
|
|
651
655
|
.extensions(callName)
|
|
652
656
|
.forEach((declaration) => {
|
|
653
657
|
steps.push({
|
|
654
|
-
component,
|
|
658
|
+
component: cmp,
|
|
655
659
|
...declaration
|
|
656
660
|
});
|
|
657
661
|
});
|
|
662
|
+
}
|
|
658
663
|
}
|
|
659
664
|
|
|
660
665
|
return steps;
|
|
@@ -729,15 +734,11 @@ export class A_Context {
|
|
|
729
734
|
/**
|
|
730
735
|
* Provide the abstraction stage to get the definition for.
|
|
731
736
|
*/
|
|
732
|
-
abstraction:
|
|
737
|
+
abstraction: A_TYPES__ConceptAbstractions,
|
|
733
738
|
/**
|
|
734
739
|
* Provide the component to get the abstraction definition from.
|
|
735
740
|
*/
|
|
736
741
|
component: A_TYPES__FeatureAvailableComponents,
|
|
737
|
-
/**
|
|
738
|
-
* Provide the scope that dictates which components are active and can provide extensions for the abstraction.
|
|
739
|
-
*/
|
|
740
|
-
scope: A_Scope
|
|
741
742
|
): Array<A_TYPES__A_StageStep> {
|
|
742
743
|
// name for error messages
|
|
743
744
|
const componentName = (component as any)?.constructor?.name || String(component);
|
|
@@ -761,7 +762,7 @@ export class A_Context {
|
|
|
761
762
|
// ...this.abstractionDefinition(abstraction, component),
|
|
762
763
|
|
|
763
764
|
// 2) Get all extensions for the abstraction from other components in the scope
|
|
764
|
-
...this.abstractionExtensions(abstraction, component
|
|
765
|
+
...this.abstractionExtensions(abstraction, component)
|
|
765
766
|
];
|
|
766
767
|
|
|
767
768
|
return steps;
|
|
@@ -775,15 +776,11 @@ export class A_Context {
|
|
|
775
776
|
/**
|
|
776
777
|
* Provide the abstraction name to get the definition for.
|
|
777
778
|
*/
|
|
778
|
-
abstraction:
|
|
779
|
+
abstraction: A_TYPES__ConceptAbstractions,
|
|
779
780
|
/**
|
|
780
781
|
* Provide the component to get the abstraction definition from.
|
|
781
782
|
*/
|
|
782
783
|
component: A_TYPES__FeatureAvailableComponents,
|
|
783
|
-
/**
|
|
784
|
-
* Provide the scope that dictates which components are active and can provide extensions for the abstraction.
|
|
785
|
-
*/
|
|
786
|
-
scope: A_Scope
|
|
787
784
|
): Array<A_TYPES__A_StageStep> {
|
|
788
785
|
const instance = this.getInstance();
|
|
789
786
|
// name for error messages
|
|
@@ -805,23 +802,27 @@ export class A_Context {
|
|
|
805
802
|
`Unable to get feature template. Component of type ${componentName} is not allowed for feature definition.`
|
|
806
803
|
);
|
|
807
804
|
|
|
808
|
-
const callName = `${component.constructor.name}.${abstraction}`;
|
|
809
|
-
|
|
810
805
|
const steps: A_TYPES__A_StageStep[] = [];
|
|
811
806
|
|
|
807
|
+
const scope = this.scope(component);
|
|
808
|
+
|
|
812
809
|
// We need to get all components that has extensions for the feature in component
|
|
813
|
-
for (const [
|
|
810
|
+
for (const [cmp, meta] of instance._metaStorage) {
|
|
814
811
|
// Just try to make sure that component not only Indexed but also presented in scope
|
|
815
|
-
if (scope.has(
|
|
812
|
+
if (scope.has(cmp) && (
|
|
813
|
+
A_TypeGuards.isComponentMetaInstance(meta)
|
|
814
|
+
|| A_TypeGuards.isContainerMetaInstance(meta)
|
|
815
|
+
)) {
|
|
816
816
|
// Get all extensions for the feature
|
|
817
817
|
meta
|
|
818
|
-
.abstractions(
|
|
818
|
+
.abstractions(abstraction)
|
|
819
819
|
.forEach((declaration) => {
|
|
820
820
|
steps.push({
|
|
821
|
-
component,
|
|
821
|
+
component: cmp,
|
|
822
822
|
...declaration
|
|
823
823
|
});
|
|
824
824
|
});
|
|
825
|
+
}
|
|
825
826
|
}
|
|
826
827
|
|
|
827
828
|
return steps;
|
|
@@ -203,7 +203,7 @@ export class A_Feature<T extends A_TYPES__FeatureAvailableComponents = A_TYPES__
|
|
|
203
203
|
): (param1: any) => void | (() => void) {
|
|
204
204
|
|
|
205
205
|
switch (true) {
|
|
206
|
-
case '
|
|
206
|
+
case !('template' in params):
|
|
207
207
|
return this.fromComponent;
|
|
208
208
|
|
|
209
209
|
case 'template' in params:
|
|
@@ -221,7 +221,7 @@ export class A_Feature<T extends A_TYPES__FeatureAvailableComponents = A_TYPES__
|
|
|
221
221
|
* @param params
|
|
222
222
|
*/
|
|
223
223
|
protected fromTemplate(
|
|
224
|
-
params: A_TYPES__Feature_InitWithTemplate
|
|
224
|
+
params: A_TYPES__Feature_InitWithTemplate<T>
|
|
225
225
|
) {
|
|
226
226
|
if (!params.template || !Array.isArray(params.template)) {
|
|
227
227
|
throw new A_FeatureError(
|
|
@@ -230,7 +230,7 @@ export class A_Feature<T extends A_TYPES__FeatureAvailableComponents = A_TYPES__
|
|
|
230
230
|
);
|
|
231
231
|
}
|
|
232
232
|
|
|
233
|
-
if (!params.scope || !(params.scope instanceof A_Scope)) {
|
|
233
|
+
if (!params.component && (!params.scope || !(params.scope instanceof A_Scope))) {
|
|
234
234
|
throw new A_FeatureError(
|
|
235
235
|
A_FeatureError.FeatureInitializationError,
|
|
236
236
|
`Invalid A-Feature scope provided of type: ${typeof params.scope} with value: ${JSON.stringify(params.scope).slice(0, 100)}...`
|
|
@@ -241,12 +241,14 @@ export class A_Feature<T extends A_TYPES__FeatureAvailableComponents = A_TYPES__
|
|
|
241
241
|
this._name = params.name;
|
|
242
242
|
|
|
243
243
|
// 2) get scope from where feature is called
|
|
244
|
-
const componentScope = params.
|
|
244
|
+
const componentScope = params.component
|
|
245
|
+
? A_Context.scope(params.component)
|
|
246
|
+
: params.scope as A_Scope;
|
|
245
247
|
|
|
246
248
|
// 3) create caller wrapper for the simple injection of the caller component
|
|
247
249
|
// - Just to prevent issues with undefined caller in features without component
|
|
248
250
|
// - TODO: maybe would be better to allow passing caller in params?
|
|
249
|
-
this._caller = new A_Caller<T>(new A_Component() as T);
|
|
251
|
+
this._caller = new A_Caller<T>(params.component || new A_Component() as T);
|
|
250
252
|
|
|
251
253
|
// 4) allocate new scope for the feature
|
|
252
254
|
const scope = A_Context.allocate(this);
|
|
@@ -22,7 +22,7 @@ export type A_TYPES__Feature_Constructor<T = A_Feature> = new (...args: any[]) =
|
|
|
22
22
|
/**
|
|
23
23
|
* Feature initialization type
|
|
24
24
|
*/
|
|
25
|
-
export type A_TYPES__Feature_Init<T extends A_TYPES__FeatureAvailableComponents = A_TYPES__FeatureAvailableComponents> = A_TYPES__Feature_InitWithComponent<T> | A_TYPES__Feature_InitWithTemplate
|
|
25
|
+
export type A_TYPES__Feature_Init<T extends A_TYPES__FeatureAvailableComponents = A_TYPES__FeatureAvailableComponents> = A_TYPES__Feature_InitWithComponent<T> | A_TYPES__Feature_InitWithTemplate<T>
|
|
26
26
|
/**
|
|
27
27
|
* Feature initialization type using component
|
|
28
28
|
*/
|
|
@@ -42,7 +42,7 @@ export type A_TYPES__Feature_InitWithComponent<T extends A_TYPES__FeatureAvailab
|
|
|
42
42
|
/**
|
|
43
43
|
* Feature initialization type using template
|
|
44
44
|
*/
|
|
45
|
-
export type A_TYPES__Feature_InitWithTemplate = {
|
|
45
|
+
export type A_TYPES__Feature_InitWithTemplate<T extends A_TYPES__FeatureAvailableComponents = A_TYPES__FeatureAvailableComponents> = {
|
|
46
46
|
/**
|
|
47
47
|
* Feature Name
|
|
48
48
|
*/
|
|
@@ -53,6 +53,13 @@ export type A_TYPES__Feature_InitWithTemplate = {
|
|
|
53
53
|
* [!] Important for proper scoping.
|
|
54
54
|
*/
|
|
55
55
|
scope: A_Scope
|
|
56
|
+
/**
|
|
57
|
+
* The component from where the feature is calling. It's important for proper scoping.
|
|
58
|
+
* Based on the component would be retrieved connected components, entities and containers.
|
|
59
|
+
*
|
|
60
|
+
* [!] Could be Container, Entity, Component or Command
|
|
61
|
+
*/
|
|
62
|
+
component?: T,
|
|
56
63
|
/**
|
|
57
64
|
* Optional Feature template to be used instead of building it from decorators
|
|
58
65
|
*/
|
|
@@ -3,7 +3,8 @@ import {
|
|
|
3
3
|
A_TYPES__Scope_Init,
|
|
4
4
|
A_TYPES__ScopeLinkedComponents,
|
|
5
5
|
A_TYPES__ScopeResolvableComponents,
|
|
6
|
-
A_TYPES__Scope_Constructor
|
|
6
|
+
A_TYPES__Scope_Constructor,
|
|
7
|
+
A_TYPES__ScopeLinkedConstructors
|
|
7
8
|
} from './A-Scope.types'
|
|
8
9
|
import {
|
|
9
10
|
A_TYPES__A_InjectDecorator_EntityInjectionInstructions,
|
|
@@ -401,6 +402,11 @@ export class A_Scope<
|
|
|
401
402
|
|
|
402
403
|
break;
|
|
403
404
|
}
|
|
405
|
+
// check scope issuer
|
|
406
|
+
case this.issuer().constructor === ctor: {
|
|
407
|
+
found = true;
|
|
408
|
+
break;
|
|
409
|
+
}
|
|
404
410
|
}
|
|
405
411
|
|
|
406
412
|
if (!found && !!this._parent)
|
|
@@ -498,7 +504,10 @@ export class A_Scope<
|
|
|
498
504
|
return this._parent.resolveConstructor(name) as any;
|
|
499
505
|
}
|
|
500
506
|
|
|
501
|
-
throw new
|
|
507
|
+
throw new A_ScopeError(
|
|
508
|
+
A_ScopeError.ResolutionError,
|
|
509
|
+
`Component or Entity with name ${name} not found in the scope ${this.name}`
|
|
510
|
+
);
|
|
502
511
|
}
|
|
503
512
|
|
|
504
513
|
|
|
@@ -561,9 +570,9 @@ export class A_Scope<
|
|
|
561
570
|
*/
|
|
562
571
|
instructions: Partial<A_TYPES__A_InjectDecorator_EntityInjectionInstructions<T>>
|
|
563
572
|
): Array<T>
|
|
564
|
-
resolve(
|
|
573
|
+
resolve<T extends A_TYPES__ScopeResolvableComponents>(
|
|
565
574
|
constructorName: string
|
|
566
|
-
):
|
|
575
|
+
): T
|
|
567
576
|
// base definition
|
|
568
577
|
resolve<T extends A_TYPES__ScopeResolvableComponents>(
|
|
569
578
|
/**
|
|
@@ -571,6 +580,13 @@ export class A_Scope<
|
|
|
571
580
|
*/
|
|
572
581
|
param1: A_TYPES__InjectableConstructors,
|
|
573
582
|
|
|
583
|
+
): T | Array<T>
|
|
584
|
+
resolve<T extends A_TYPES__ScopeLinkedConstructors>(
|
|
585
|
+
/**
|
|
586
|
+
* Provide a component, fragment or entity constructor or an array of constructors to resolve its instance(s) from the scope
|
|
587
|
+
*/
|
|
588
|
+
param1: T,
|
|
589
|
+
|
|
574
590
|
): T | Array<T>
|
|
575
591
|
resolve<T extends A_TYPES__ScopeResolvableComponents>(
|
|
576
592
|
/**
|
|
@@ -590,7 +606,7 @@ export class A_Scope<
|
|
|
590
606
|
}
|
|
591
607
|
|
|
592
608
|
case A_TypeGuards.isFunction(param1): {
|
|
593
|
-
return this.resolveOnce(param1, param2);
|
|
609
|
+
return this.resolveOnce(param1, param2) as T;
|
|
594
610
|
}
|
|
595
611
|
|
|
596
612
|
case A_TypeGuards.isString(param1): {
|
|
@@ -662,33 +678,66 @@ export class A_Scope<
|
|
|
662
678
|
* @param instructions
|
|
663
679
|
* @returns
|
|
664
680
|
*/
|
|
665
|
-
private resolveOnce
|
|
666
|
-
component:
|
|
681
|
+
private resolveOnce(
|
|
682
|
+
component: any,
|
|
667
683
|
instructions?: Partial<A_TYPES__A_InjectDecorator_EntityInjectionInstructions>
|
|
668
|
-
):
|
|
684
|
+
): A_TYPES__ScopeResolvableComponents | A_Scope | A_TYPES__ScopeLinkedComponents | Array<A_TYPES__ScopeResolvableComponents> {
|
|
685
|
+
|
|
686
|
+
if (!component || !this.has(component))
|
|
687
|
+
throw new A_ScopeError(
|
|
688
|
+
A_ScopeError.ResolutionError,
|
|
689
|
+
`Injected Component ${component} not found in the scope`
|
|
690
|
+
);
|
|
669
691
|
|
|
670
692
|
if (A_TypeGuards.isScopeConstructor(component))
|
|
671
693
|
component
|
|
672
694
|
|
|
673
|
-
if (typeof component == 'function' &&
|
|
695
|
+
if (typeof component == 'function' && component.name === 'A_Scope')
|
|
674
696
|
component
|
|
675
697
|
|
|
698
|
+
|
|
699
|
+
|
|
700
|
+
|
|
676
701
|
switch (true) {
|
|
702
|
+
case A_TypeGuards.isConstructorAllowedForScopeAllocation(component): {
|
|
703
|
+
return this.resolveIssuer(component);
|
|
704
|
+
}
|
|
677
705
|
case A_TypeGuards.isEntityConstructor(component): {
|
|
678
|
-
return this.resolveEntity(component, instructions)
|
|
706
|
+
return this.resolveEntity(component, instructions);
|
|
679
707
|
}
|
|
680
708
|
case A_TypeGuards.isFragmentConstructor(component): {
|
|
681
|
-
return this.resolveFragment(component)
|
|
709
|
+
return this.resolveFragment(component);
|
|
682
710
|
}
|
|
683
711
|
case A_TypeGuards.isScopeConstructor(component): {
|
|
684
|
-
return this.resolveScope(component)
|
|
712
|
+
return this.resolveScope(component);
|
|
685
713
|
}
|
|
686
714
|
case A_TypeGuards.isComponentConstructor(component): {
|
|
687
|
-
return this.resolveComponent(component)
|
|
715
|
+
return this.resolveComponent(component);
|
|
688
716
|
}
|
|
689
717
|
default:
|
|
690
|
-
throw new
|
|
718
|
+
throw new A_ScopeError(
|
|
719
|
+
A_ScopeError.ResolutionError,
|
|
720
|
+
`Injected Component ${component} not found in the scope`
|
|
721
|
+
);
|
|
722
|
+
}
|
|
723
|
+
}
|
|
724
|
+
|
|
725
|
+
private resolveIssuer(
|
|
726
|
+
ctor: A_TYPES__ScopeLinkedConstructors
|
|
727
|
+
): A_TYPES__ScopeLinkedComponents {
|
|
728
|
+
const isCurrent = ctor === this.issuer().constructor;
|
|
729
|
+
|
|
730
|
+
if (isCurrent) {
|
|
731
|
+
return this.issuer();
|
|
732
|
+
}
|
|
733
|
+
if (!!this._parent) {
|
|
734
|
+
return this._parent.resolveIssuer(ctor);
|
|
691
735
|
}
|
|
736
|
+
|
|
737
|
+
throw new A_ScopeError(
|
|
738
|
+
A_ScopeError.ResolutionError,
|
|
739
|
+
`Issuer ${ctor.name} not found in the scope ${this.name}`
|
|
740
|
+
);
|
|
692
741
|
}
|
|
693
742
|
|
|
694
743
|
/**
|
|
@@ -703,7 +752,7 @@ export class A_Scope<
|
|
|
703
752
|
private resolveEntity<T extends A_Entity>(
|
|
704
753
|
entity: A_TYPES__Entity_Constructor<T>,
|
|
705
754
|
instructions?: Partial<A_TYPES__A_InjectDecorator_EntityInjectionInstructions<T>>
|
|
706
|
-
): T | Array<T>
|
|
755
|
+
): T | Array<T> {
|
|
707
756
|
|
|
708
757
|
const query = instructions?.query || {} as Partial<A_TYPES__A_InjectDecorator_EntityInjectionQuery<T>>;
|
|
709
758
|
const count = instructions?.pagination?.count || 1;
|
|
@@ -726,7 +775,10 @@ export class A_Scope<
|
|
|
726
775
|
return this._parent.resolveEntity(entity, instructions);
|
|
727
776
|
|
|
728
777
|
default:
|
|
729
|
-
throw new
|
|
778
|
+
throw new A_ScopeError(
|
|
779
|
+
A_ScopeError.ResolutionError,
|
|
780
|
+
`Entity ${entity.name} not found in the scope ${this.name}`
|
|
781
|
+
);
|
|
730
782
|
}
|
|
731
783
|
}
|
|
732
784
|
/**
|
|
@@ -7,6 +7,7 @@ export class A_ScopeError extends A_Error {
|
|
|
7
7
|
|
|
8
8
|
static readonly ConstructorError = 'Unable to construct A-Scope instance';
|
|
9
9
|
|
|
10
|
+
static readonly ResolutionError = 'A-Scope Resolution Error';
|
|
10
11
|
|
|
11
12
|
static readonly CircularInheritanceError = 'A-Scope Circular Inheritance Error';
|
|
12
13
|
|
|
@@ -9,6 +9,8 @@ import { A_Caller } from "../A-Caller/A_Caller.class"
|
|
|
9
9
|
import { A_Error } from "../A-Error/A_Error.class"
|
|
10
10
|
import { A_TYPES__Error_Constructor } from "../A-Error/A_Error.types"
|
|
11
11
|
import { A_Scope } from "./A-Scope.class"
|
|
12
|
+
import { A_TYPES__Container_Constructor } from "../A-Container/A-Container.types"
|
|
13
|
+
import { A_TYPES__Feature_Constructor } from "../A-Feature/A-Feature.types"
|
|
12
14
|
|
|
13
15
|
|
|
14
16
|
// ============================================================================
|
|
@@ -68,8 +70,10 @@ export type A_TYPES__ScopeConfig = {
|
|
|
68
70
|
export type A_TYPES__Scope_Serialized = {}
|
|
69
71
|
|
|
70
72
|
|
|
71
|
-
|
|
72
|
-
|
|
73
|
+
/**
|
|
74
|
+
*
|
|
75
|
+
*/
|
|
76
|
+
export type A_TYPES__ScopeLinkedConstructors = A_TYPES__Container_Constructor | A_TYPES__Feature_Constructor;
|
|
73
77
|
/**
|
|
74
78
|
* A list of components that can have a scope associated with them
|
|
75
79
|
*/
|
|
@@ -77,7 +81,7 @@ export type A_TYPES__ScopeLinkedComponents = A_Container | A_Feature;
|
|
|
77
81
|
/**
|
|
78
82
|
* A list of components that can be resolved by a scope
|
|
79
83
|
*/
|
|
80
|
-
export type A_TYPES__ScopeResolvableComponents = A_Component | A_Fragment | A_Entity
|
|
84
|
+
export type A_TYPES__ScopeResolvableComponents = A_Component | A_Fragment | A_Entity
|
|
81
85
|
/**
|
|
82
86
|
* A list of components that are dependent on a scope and do not have their own scope
|
|
83
87
|
*/
|
|
@@ -11,7 +11,6 @@ import { A_TypeGuards } from "@adaas/a-concept/helpers/A_TypeGuards.helper";
|
|
|
11
11
|
import { A_TYPES__ScopeResolvableComponents } from "../A-Scope/A-Scope.types";
|
|
12
12
|
import { A_TYPES__Container_Constructor } from "../A-Container/A-Container.types";
|
|
13
13
|
import { A_TYPES__Component_Constructor } from "../A-Component/A-Component.types";
|
|
14
|
-
import { A_TYPES__InjectableConstructors } from "@adaas/a-concept/global/A-Inject/A-Inject.types";
|
|
15
14
|
|
|
16
15
|
|
|
17
16
|
|
|
@@ -25,7 +25,7 @@ import { A_TYPES__Caller_Constructor } from "../global/A-Caller/A_Caller.types";
|
|
|
25
25
|
import { A_Error } from "../global/A-Error/A_Error.class";
|
|
26
26
|
import { A_CommonHelper } from "./A_Common.helper";
|
|
27
27
|
import { A_TYPES__AbstractionAvailableComponents } from "../global/A-Abstraction/A-Abstraction.types";
|
|
28
|
-
import { A_TYPES__Scope_Constructor } from "../global/A-Scope/A-Scope.types";
|
|
28
|
+
import { A_TYPES__Scope_Constructor, A_TYPES__ScopeLinkedComponents, A_TYPES__ScopeLinkedConstructors } from "../global/A-Scope/A-Scope.types";
|
|
29
29
|
import { A_TYPES__InjectableTargets } from "../global/A-Inject/A-Inject.types";
|
|
30
30
|
|
|
31
31
|
|
|
@@ -273,9 +273,18 @@ export class A_TypeGuards {
|
|
|
273
273
|
// ==========================================================================
|
|
274
274
|
// ========================= SPECIAL Type Guards =============================
|
|
275
275
|
// ===========================================================================
|
|
276
|
-
static
|
|
276
|
+
static isConstructorAllowedForScopeAllocation(target: any): target is A_TYPES__ScopeLinkedConstructors {
|
|
277
277
|
return A_TypeGuards.isContainerConstructor(target)
|
|
278
|
-
|| A_TypeGuards.
|
|
278
|
+
|| A_TypeGuards.isFeatureConstructor(target);
|
|
279
|
+
}
|
|
280
|
+
static isInstanceAllowedForScopeAllocation(target: any): target is A_TYPES__ScopeLinkedComponents {
|
|
281
|
+
return A_TypeGuards.isContainerInstance(target)
|
|
282
|
+
|| A_TypeGuards.isFeatureInstance(target);
|
|
283
|
+
}
|
|
284
|
+
|
|
285
|
+
static isConstructorAvailableForAbstraction(target: any): target is A_TYPES__AbstractionAvailableComponents {
|
|
286
|
+
return A_TypeGuards.isContainerInstance(target)
|
|
287
|
+
|| A_TypeGuards.isComponentInstance(target);
|
|
279
288
|
}
|
|
280
289
|
|
|
281
290
|
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import { A_Component } from '@adaas/a-concept/global/A-Component/A-Component.class';
|
|
2
|
+
import './test.setup'
|
|
3
|
+
import { A_Concept } from '@adaas/a-concept/global/A-Concept/A-Concept.class';
|
|
4
|
+
import { A_Container } from '@adaas/a-concept/global/A-Container/A-Container.class';
|
|
5
|
+
|
|
6
|
+
jest.retryTimes(0);
|
|
7
|
+
|
|
8
|
+
describe('A-Abstraction Tests', () => {
|
|
9
|
+
it('It should be possible to extend abstraction on A-Component level', async () => {
|
|
10
|
+
class MyComponent extends A_Component {
|
|
11
|
+
private _test: number = 0
|
|
12
|
+
|
|
13
|
+
@A_Concept.Load()
|
|
14
|
+
myMethod() {
|
|
15
|
+
this._test++;
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
it('It should be possible to extend abstraction on A-Container level', async () => {
|
|
21
|
+
class MyContainer extends A_Container {
|
|
22
|
+
private _test: number = 0
|
|
23
|
+
|
|
24
|
+
@A_Concept.Load()
|
|
25
|
+
myMethod() {
|
|
26
|
+
this._test++;
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
it('It should be possible to proceed Concept Abstraction', async () => {
|
|
33
|
+
class MyComponent extends A_Component {
|
|
34
|
+
_test2: number = 0
|
|
35
|
+
|
|
36
|
+
@A_Concept.Load()
|
|
37
|
+
myMethod() {
|
|
38
|
+
this._test2++;
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
class MyContainer extends A_Container {
|
|
43
|
+
_test: number = 0
|
|
44
|
+
|
|
45
|
+
@A_Concept.Load()
|
|
46
|
+
myMethod() {
|
|
47
|
+
this._test++;
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
const myContainer = new MyContainer({
|
|
52
|
+
name: 'MyContainer',
|
|
53
|
+
components: [MyComponent]
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
const testConcept = new A_Concept({
|
|
57
|
+
name: 'TestConcept',
|
|
58
|
+
containers: [myContainer]
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
await testConcept.load();
|
|
62
|
+
|
|
63
|
+
|
|
64
|
+
const resolvedComponent = myContainer.scope.resolve(MyComponent);
|
|
65
|
+
|
|
66
|
+
expect(resolvedComponent).toBeInstanceOf(MyComponent);
|
|
67
|
+
expect(myContainer._test).toBe(1);
|
|
68
|
+
expect(resolvedComponent._test2).toBe(1);
|
|
69
|
+
|
|
70
|
+
});
|
|
71
|
+
});
|
|
72
|
+
|
package/tests/A-Common.test.ts
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
|
+
import './test.setup'
|
|
1
2
|
import { A_CommonHelper } from "@adaas/a-concept/helpers/A_Common.helper";
|
|
2
3
|
import { A_IdentityHelper } from "@adaas/a-concept/helpers/A_Identity.helper";
|
|
3
4
|
import { A_TYPES__DeepPartial } from "@adaas/a-concept/types/A_Common.types";
|
|
4
5
|
jest.retryTimes(0);
|
|
5
6
|
|
|
6
|
-
describe('
|
|
7
|
+
describe('A-Common Tests', () => {
|
|
7
8
|
it('Deep Clone and Merge ', async () => {
|
|
8
9
|
|
|
9
10
|
type TestType = {
|
package/tests/A-Scope.test.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import './test.setup';
|
|
2
2
|
|
|
3
|
-
import { A_Command } from "@adaas/a-concept/base/A-Command/A-Command.
|
|
3
|
+
import { A_Command } from "@adaas/a-concept/base/A-Command/A-Command.entity";
|
|
4
4
|
import { A_Component } from "@adaas/a-concept/global/A-Component/A-Component.class";
|
|
5
5
|
import { A_Concept } from '@adaas/a-concept/global/A-Concept/A-Concept.class';
|
|
6
6
|
import { A_Container } from '@adaas/a-concept/global/A-Container/A-Container.class';
|
package/tsconfig.json
CHANGED
|
@@ -35,7 +35,7 @@
|
|
|
35
35
|
"@adaas/a-concept/types/*": ["src/types/*"],
|
|
36
36
|
"@adaas/a-concept/helpers/*": ["src/helpers/*"],
|
|
37
37
|
"@adaas/a-concept/decorators/*": ["src/decorators/*"],
|
|
38
|
-
"@adaas/a-concept/base/*": ["../adaas-a-utils/src/
|
|
38
|
+
"@adaas/a-concept/base/*": ["../adaas-a-utils/src/lib/*"],
|
|
39
39
|
"@adaas/a-concept/utils/*": ["src/utils/*"]
|
|
40
40
|
},
|
|
41
41
|
"lib": [
|
|
@@ -51,7 +51,7 @@
|
|
|
51
51
|
"tests/**/*",
|
|
52
52
|
"examples/**/*",
|
|
53
53
|
"index.ts"
|
|
54
|
-
, "../adaas-a-utils/src/
|
|
54
|
+
, "../adaas-a-utils/src/lib" ],
|
|
55
55
|
"exclude": [
|
|
56
56
|
"node_modules/**/*",
|
|
57
57
|
"dist/**/*",
|