@adaas/a-concept 0.1.58 → 0.1.59
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 +2 -2
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.mts +13 -0
- package/dist/index.d.ts +13 -0
- package/dist/index.mjs +2 -2
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
- package/src/global/A-Context/A-Context.class.ts +4 -1
- package/src/global/A-Feature/A-Feature-Extend.decorator.ts +18 -3
- package/src/global/A-Scope/A-Scope.class.ts +12 -3
- package/tests/A-Feature.test.ts +92 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@adaas/a-concept",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.59",
|
|
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",
|
|
@@ -714,7 +714,10 @@ export class A_Context {
|
|
|
714
714
|
.filter(c => c !== A_Component && c !== A_Container && c !== A_Entity)
|
|
715
715
|
.map(c => `${c.name}.${name}`);
|
|
716
716
|
|
|
717
|
-
|
|
717
|
+
|
|
718
|
+
|
|
719
|
+
// const callNames = [`${component.constructor.name}.${name}`];
|
|
720
|
+
// const callNames = [`BaseComponent.testFeature`];
|
|
718
721
|
|
|
719
722
|
const steps: A_TYPES__A_StageStep[] = [];
|
|
720
723
|
|
|
@@ -153,7 +153,6 @@ export function A_Feature_Extend(
|
|
|
153
153
|
.meta(target)
|
|
154
154
|
.get(metaKey);
|
|
155
155
|
|
|
156
|
-
|
|
157
156
|
// Get the existed metadata or create a new one
|
|
158
157
|
const meta = A_Context
|
|
159
158
|
.meta(target)
|
|
@@ -177,6 +176,23 @@ export function A_Feature_Extend(
|
|
|
177
176
|
...(existedMeta.get(targetRegexp.source) || [])
|
|
178
177
|
];
|
|
179
178
|
|
|
179
|
+
// ensure that other regexps are preserved
|
|
180
|
+
for (const [key, handlers] of existedMeta.entries()) {
|
|
181
|
+
|
|
182
|
+
const indexInAnother = handlers.findIndex(item => item.handler === propertyKey);
|
|
183
|
+
|
|
184
|
+
// if the same handler exists in another regexp, remove it
|
|
185
|
+
if (key !== targetRegexp.source && indexInAnother !== -1) {
|
|
186
|
+
handlers.splice(indexInAnother, 1);
|
|
187
|
+
// if no handlers left for this regexp, remove the regexp entry
|
|
188
|
+
if (handlers.length === 0) {
|
|
189
|
+
existedMeta.delete(key);
|
|
190
|
+
} else {
|
|
191
|
+
existedMeta.set(key, handlers);
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
|
|
180
196
|
const existedIndex = existedMetaValue.findIndex(item => item.handler === propertyKey);
|
|
181
197
|
|
|
182
198
|
const extension = {
|
|
@@ -197,8 +213,7 @@ export function A_Feature_Extend(
|
|
|
197
213
|
existedMetaValue.push(extension);
|
|
198
214
|
}
|
|
199
215
|
|
|
200
|
-
|
|
201
|
-
existedMetaValue.push();
|
|
216
|
+
|
|
202
217
|
|
|
203
218
|
// Set the metadata of the method to define a custom Feature with name
|
|
204
219
|
existedMeta.set(targetRegexp.source, existedMetaValue);
|
|
@@ -933,7 +933,16 @@ export class A_Scope<
|
|
|
933
933
|
*/
|
|
934
934
|
entity: A_TYPES__Entity_Constructor<T>
|
|
935
935
|
): T | undefined
|
|
936
|
-
|
|
936
|
+
resolve<T extends A_Entity>(
|
|
937
|
+
/**
|
|
938
|
+
* Provide an entity constructor to resolve its instance or an array of instances from the scope
|
|
939
|
+
*/
|
|
940
|
+
entity: A_TYPES__Entity_Constructor<T>,
|
|
941
|
+
/**
|
|
942
|
+
* Only Aseid Provided, in this case one entity will be returned
|
|
943
|
+
*/
|
|
944
|
+
instructions: { query: { aseid: string | ASEID } }
|
|
945
|
+
): T | undefined
|
|
937
946
|
resolve<T extends A_Entity>(
|
|
938
947
|
/**
|
|
939
948
|
* Provide an entity constructor to resolve its instance or an array of instances from the scope
|
|
@@ -963,7 +972,7 @@ export class A_Scope<
|
|
|
963
972
|
resolve<T extends A_TYPES__ScopeResolvableComponents>(
|
|
964
973
|
constructorName: string
|
|
965
974
|
): T | undefined
|
|
966
|
-
// base definition
|
|
975
|
+
// ------------------------------------ base definition ------------------------------------
|
|
967
976
|
resolve<T extends A_TYPES__ScopeResolvableComponents>(
|
|
968
977
|
/**
|
|
969
978
|
* Provide a component, fragment or entity constructor or an array of constructors to resolve its instance(s) from the scope
|
|
@@ -1460,7 +1469,7 @@ export class A_Scope<
|
|
|
1460
1469
|
// 2) Parent resolution
|
|
1461
1470
|
case parent && typeof parent.layerOffset === 'number': {
|
|
1462
1471
|
const targetParent = this.parentOffset(parent.layerOffset);
|
|
1463
|
-
if(!targetParent) {
|
|
1472
|
+
if (!targetParent) {
|
|
1464
1473
|
throw new A_ScopeError(
|
|
1465
1474
|
A_ScopeError.ResolutionError,
|
|
1466
1475
|
`Unable to resolve parent scope at offset ${parent.layerOffset} for dependency ${componentName} for component ${component.name} in scope ${this.name}`
|
package/tests/A-Feature.test.ts
CHANGED
|
@@ -666,4 +666,96 @@ describe('A-Feature tests', () => {
|
|
|
666
666
|
|
|
667
667
|
|
|
668
668
|
});
|
|
669
|
+
it('Should override extensions meta for inherited method with the same name', async () => {
|
|
670
|
+
|
|
671
|
+
const resultChain: string[] = [];
|
|
672
|
+
|
|
673
|
+
class BaseComponent extends A_Component {
|
|
674
|
+
|
|
675
|
+
@A_Feature.Extend({
|
|
676
|
+
name: 'testFeature',
|
|
677
|
+
scope: [BaseComponent]
|
|
678
|
+
})
|
|
679
|
+
async test() {
|
|
680
|
+
resultChain.push('BaseComponent.test');
|
|
681
|
+
}
|
|
682
|
+
|
|
683
|
+
@A_Feature.Extend({
|
|
684
|
+
name: 'testFeature',
|
|
685
|
+
scope: [BaseComponent]
|
|
686
|
+
})
|
|
687
|
+
async test2() {
|
|
688
|
+
resultChain.push('BaseComponent.test2');
|
|
689
|
+
}
|
|
690
|
+
}
|
|
691
|
+
|
|
692
|
+
|
|
693
|
+
class ChildComponent_A extends BaseComponent {
|
|
694
|
+
@A_Feature.Extend({
|
|
695
|
+
name: 'testFeature',
|
|
696
|
+
scope: [ChildComponent_A]
|
|
697
|
+
})
|
|
698
|
+
async test() {
|
|
699
|
+
resultChain.push('ChildComponent_A.test');
|
|
700
|
+
}
|
|
701
|
+
}
|
|
702
|
+
|
|
703
|
+
|
|
704
|
+
const testScope = new A_Scope({ name: 'TestScope', components: [ChildComponent_A] });
|
|
705
|
+
|
|
706
|
+
const extensionsMeta = A_Context.meta(ChildComponent_A).get(A_TYPES__ComponentMetaKey.EXTENSIONS)!.entries();
|
|
707
|
+
|
|
708
|
+
await testScope.resolve(ChildComponent_A)!.call('testFeature');
|
|
709
|
+
|
|
710
|
+
expect(resultChain).toEqual([
|
|
711
|
+
'ChildComponent_A.test',
|
|
712
|
+
'BaseComponent.test2'
|
|
713
|
+
]);
|
|
714
|
+
})
|
|
715
|
+
|
|
716
|
+
it('Should properly define inheritance chain of the features', async () => {
|
|
717
|
+
|
|
718
|
+
const resultChain: string[] = [];
|
|
719
|
+
|
|
720
|
+
class BaseComponent extends A_Component {
|
|
721
|
+
|
|
722
|
+
@A_Feature.Extend({
|
|
723
|
+
name: 'testFeature',
|
|
724
|
+
scope: [BaseComponent]
|
|
725
|
+
})
|
|
726
|
+
async test() {
|
|
727
|
+
resultChain.push('BaseComponent.test');
|
|
728
|
+
}
|
|
729
|
+
}
|
|
730
|
+
|
|
731
|
+
class ChildComponent_A extends BaseComponent {
|
|
732
|
+
@A_Feature.Extend({
|
|
733
|
+
name: 'testFeature',
|
|
734
|
+
scope: [ChildComponent_A]
|
|
735
|
+
})
|
|
736
|
+
async test() {
|
|
737
|
+
resultChain.push('ChildComponent_A.test');
|
|
738
|
+
}
|
|
739
|
+
}
|
|
740
|
+
|
|
741
|
+
class ChildComponent_B extends BaseComponent {
|
|
742
|
+
@A_Feature.Extend({
|
|
743
|
+
name: 'testFeature',
|
|
744
|
+
scope: [ChildComponent_B]
|
|
745
|
+
})
|
|
746
|
+
async test() {
|
|
747
|
+
resultChain.push('ChildComponent_B.test');
|
|
748
|
+
}
|
|
749
|
+
}
|
|
750
|
+
|
|
751
|
+
|
|
752
|
+
const testScope = new A_Scope({ name: 'TestScope', components: [ChildComponent_A, ChildComponent_B] });
|
|
753
|
+
|
|
754
|
+
await testScope.resolve(ChildComponent_A)!.call('testFeature');
|
|
755
|
+
|
|
756
|
+
expect(resultChain).toEqual([
|
|
757
|
+
'ChildComponent_A.test'
|
|
758
|
+
]);
|
|
759
|
+
|
|
760
|
+
})
|
|
669
761
|
});
|