@adaas/a-concept 0.2.7 → 0.2.8
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.mjs +2 -2
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
- package/src/global/A-Scope/A-Scope.class.ts +55 -1
- package/tests/A-Scope.test.ts +105 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@adaas/a-concept",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.8",
|
|
4
4
|
"description": "A-Concept is a framework of the new generation that is tailored to use AI, enabling developers to create AI-powered applications with ease. It provides a structured approach to building, managing, and deploying AI-driven solutions.",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"main": "./dist/index.cjs",
|
|
@@ -1814,6 +1814,13 @@ export class A_Scope<
|
|
|
1814
1814
|
this._components.delete(param1.constructor as _ComponentType[number]);
|
|
1815
1815
|
A_Context.deregister(param1);
|
|
1816
1816
|
|
|
1817
|
+
const ctor = param1.constructor as _ComponentType[number];
|
|
1818
|
+
|
|
1819
|
+
const hasComponent = this._components.has(ctor);
|
|
1820
|
+
if (!hasComponent) {
|
|
1821
|
+
this.allowedComponents.delete(ctor);
|
|
1822
|
+
}
|
|
1823
|
+
|
|
1817
1824
|
break;
|
|
1818
1825
|
}
|
|
1819
1826
|
// 3) In case when it's a A-Entity instance
|
|
@@ -1821,14 +1828,28 @@ export class A_Scope<
|
|
|
1821
1828
|
|
|
1822
1829
|
this._entities.delete(param1.aseid.toString());
|
|
1823
1830
|
A_Context.deregister(param1);
|
|
1831
|
+
|
|
1832
|
+
const ctor = param1.constructor as _EntityType[number];
|
|
1833
|
+
|
|
1834
|
+
const hasEntity = Array.from(this._entities.values()).some(entity => entity instanceof ctor);
|
|
1835
|
+
if (!hasEntity) {
|
|
1836
|
+
this.allowedEntities.delete(ctor);
|
|
1837
|
+
}
|
|
1838
|
+
|
|
1824
1839
|
break;
|
|
1825
1840
|
}
|
|
1826
1841
|
// 4) In case when it's a A-Fragment instance
|
|
1827
1842
|
case A_TypeGuards.isFragmentInstance(param1): {
|
|
1828
|
-
|
|
1829
1843
|
this._fragments.delete(param1.constructor as A_TYPES__Fragment_Constructor<_FragmentType[number]>);
|
|
1830
1844
|
A_Context.deregister(param1);
|
|
1831
1845
|
|
|
1846
|
+
const ctor = param1.constructor as A_TYPES__Fragment_Constructor<_FragmentType[number]>;
|
|
1847
|
+
|
|
1848
|
+
const hasFragment = Array.from(this._fragments.values()).some(fragment => fragment instanceof ctor);
|
|
1849
|
+
if (!hasFragment) {
|
|
1850
|
+
this.allowedFragments.delete(ctor);
|
|
1851
|
+
}
|
|
1852
|
+
|
|
1832
1853
|
break;
|
|
1833
1854
|
}
|
|
1834
1855
|
// 5) In case when it's a A-Error instance
|
|
@@ -1836,6 +1857,14 @@ export class A_Scope<
|
|
|
1836
1857
|
|
|
1837
1858
|
this._errors.delete(param1.code);
|
|
1838
1859
|
A_Context.deregister(param1);
|
|
1860
|
+
|
|
1861
|
+
const ctor = param1.constructor as _ErrorType[number];
|
|
1862
|
+
|
|
1863
|
+
const hasError = Array.from(this._errors.values()).some(error => error instanceof ctor);
|
|
1864
|
+
if (!hasError) {
|
|
1865
|
+
this.allowedErrors.delete(ctor);
|
|
1866
|
+
}
|
|
1867
|
+
|
|
1839
1868
|
break;
|
|
1840
1869
|
}
|
|
1841
1870
|
|
|
@@ -1850,16 +1879,40 @@ export class A_Scope<
|
|
|
1850
1879
|
// 8) In case when it's a A-Fragment constructor
|
|
1851
1880
|
case A_TypeGuards.isFragmentConstructor(param1): {
|
|
1852
1881
|
this.allowedFragments.delete(param1 as A_TYPES__Fragment_Constructor<_FragmentType[number]>);
|
|
1882
|
+
// and then deregister all instances of this fragment
|
|
1883
|
+
Array.from(this._fragments.entries()).forEach(([ctor, instance]) => {
|
|
1884
|
+
if (A_CommonHelper.isInheritedFrom(ctor, param1)) {
|
|
1885
|
+
this._fragments.delete(ctor);
|
|
1886
|
+
A_Context.deregister(instance);
|
|
1887
|
+
}
|
|
1888
|
+
});
|
|
1889
|
+
|
|
1853
1890
|
break;
|
|
1854
1891
|
}
|
|
1855
1892
|
// 9) In case when it's a A-Entity constructor
|
|
1856
1893
|
case A_TypeGuards.isEntityConstructor(param1): {
|
|
1857
1894
|
this.allowedEntities.delete(param1 as _EntityType[number]);
|
|
1895
|
+
// and then deregister all instances of this entity
|
|
1896
|
+
Array.from(this._entities.entries()).forEach(([aseid, instance]) => {
|
|
1897
|
+
if (A_CommonHelper.isInheritedFrom(instance.constructor, param1)) {
|
|
1898
|
+
this._entities.delete(aseid);
|
|
1899
|
+
A_Context.deregister(instance);
|
|
1900
|
+
}
|
|
1901
|
+
});
|
|
1902
|
+
|
|
1858
1903
|
break;
|
|
1859
1904
|
}
|
|
1860
1905
|
// 10) In case when it's a A-Error constructor
|
|
1861
1906
|
case A_TypeGuards.isErrorConstructor(param1): {
|
|
1862
1907
|
this.allowedErrors.delete(param1 as _ErrorType[number]);
|
|
1908
|
+
// and then deregister all instances of this error
|
|
1909
|
+
Array.from(this._errors.entries()).forEach(([code, instance]) => {
|
|
1910
|
+
if (A_CommonHelper.isInheritedFrom(instance.constructor, param1)) {
|
|
1911
|
+
this._errors.delete(code);
|
|
1912
|
+
A_Context.deregister(instance);
|
|
1913
|
+
}
|
|
1914
|
+
});
|
|
1915
|
+
|
|
1863
1916
|
break;
|
|
1864
1917
|
}
|
|
1865
1918
|
|
|
@@ -1875,6 +1928,7 @@ export class A_Scope<
|
|
|
1875
1928
|
`Cannot deregister ${componentName} from the scope ${this.name}`
|
|
1876
1929
|
);
|
|
1877
1930
|
}
|
|
1931
|
+
|
|
1878
1932
|
}
|
|
1879
1933
|
|
|
1880
1934
|
/**
|
package/tests/A-Scope.test.ts
CHANGED
|
@@ -705,4 +705,109 @@ describe('A-Scope tests', () => {
|
|
|
705
705
|
expect(resolvedA).toBeInstanceOf(MyEntity_B);
|
|
706
706
|
expect(resolvedA?.name).toBe('Entity1');
|
|
707
707
|
});
|
|
708
|
+
|
|
709
|
+
it('Should deregister entities properly', async () => {
|
|
710
|
+
|
|
711
|
+
class MyEntity extends A_Entity { }
|
|
712
|
+
|
|
713
|
+
class MyFragment extends A_Fragment { }
|
|
714
|
+
|
|
715
|
+
class MyComponent extends A_Component { }
|
|
716
|
+
|
|
717
|
+
const scope = new A_Scope({ name: 'TestScope' });
|
|
718
|
+
|
|
719
|
+
|
|
720
|
+
|
|
721
|
+
const entity = new MyEntity();
|
|
722
|
+
const fragment = new MyFragment();
|
|
723
|
+
|
|
724
|
+
scope.register(entity);
|
|
725
|
+
scope.register(fragment);
|
|
726
|
+
scope.register(MyComponent);
|
|
727
|
+
|
|
728
|
+
expect(scope.has(MyEntity)).toBe(true);
|
|
729
|
+
expect(scope.has(MyFragment)).toBe(true);
|
|
730
|
+
expect(scope.has(MyComponent)).toBe(true);
|
|
731
|
+
|
|
732
|
+
scope.deregister(entity);
|
|
733
|
+
scope.deregister(fragment);
|
|
734
|
+
scope.deregister(MyComponent);
|
|
735
|
+
|
|
736
|
+
expect(scope.has(MyEntity)).toBe(false);
|
|
737
|
+
expect(scope.has(MyFragment)).toBe(false);
|
|
738
|
+
expect(scope.has(MyComponent)).toBe(false);
|
|
739
|
+
});
|
|
740
|
+
|
|
741
|
+
it('Should deregister all entities by class', async () => {
|
|
742
|
+
|
|
743
|
+
class BaseEntity extends A_Entity { }
|
|
744
|
+
|
|
745
|
+
class MyEntityA extends A_Entity { }
|
|
746
|
+
class MyEntityB extends BaseEntity { }
|
|
747
|
+
|
|
748
|
+
|
|
749
|
+
const scope = new A_Scope({ name: 'TestScope' });
|
|
750
|
+
|
|
751
|
+
|
|
752
|
+
|
|
753
|
+
const entityA1 = new MyEntityA();
|
|
754
|
+
const entityA2 = new MyEntityA();
|
|
755
|
+
const entityB1 = new MyEntityB();
|
|
756
|
+
|
|
757
|
+
scope.register(entityA1);
|
|
758
|
+
scope.register(entityA2);
|
|
759
|
+
scope.register(entityB1);
|
|
760
|
+
|
|
761
|
+
expect(scope.resolveAll(MyEntityA).length).toBe(2);
|
|
762
|
+
expect(scope.resolveAll(BaseEntity).length).toBe(1);
|
|
763
|
+
|
|
764
|
+
scope.deregister(MyEntityA);
|
|
765
|
+
|
|
766
|
+
expect(scope.resolveAll(MyEntityA).length).toBe(0);
|
|
767
|
+
expect(scope.resolveAll(BaseEntity).length).toBe(1);
|
|
768
|
+
|
|
769
|
+
const entityB2 = new MyEntityB();
|
|
770
|
+
scope.register(entityB2);
|
|
771
|
+
|
|
772
|
+
expect(scope.resolveAll(BaseEntity).length).toBe(2);
|
|
773
|
+
|
|
774
|
+
scope.deregister(BaseEntity);
|
|
775
|
+
|
|
776
|
+
expect(scope.resolveAll(BaseEntity).length).toBe(0);
|
|
777
|
+
});
|
|
778
|
+
it('Should register/deregister fragments with the same names', async () => {
|
|
779
|
+
|
|
780
|
+
class MyFragment extends A_Fragment {
|
|
781
|
+
|
|
782
|
+
array: string[] = [];
|
|
783
|
+
|
|
784
|
+
constructor(name: string) {
|
|
785
|
+
super({ name });
|
|
786
|
+
}
|
|
787
|
+
}
|
|
788
|
+
|
|
789
|
+
const scope = new A_Scope({ name: 'TestScope' });
|
|
790
|
+
|
|
791
|
+
const fragmentA1 = new MyFragment('fragmentA');
|
|
792
|
+
|
|
793
|
+
scope.register(fragmentA1);
|
|
794
|
+
|
|
795
|
+
expect(scope.has(MyFragment)).toBe(true);
|
|
796
|
+
expect(scope.resolve(MyFragment)).toBe(fragmentA1);
|
|
797
|
+
|
|
798
|
+
scope.deregister(fragmentA1);
|
|
799
|
+
|
|
800
|
+
fragmentA1.array.push('newData');
|
|
801
|
+
|
|
802
|
+
|
|
803
|
+
expect(scope.has(MyFragment)).toBe(false);
|
|
804
|
+
|
|
805
|
+
const fragmentA2 = new MyFragment('fragmentA');
|
|
806
|
+
|
|
807
|
+
scope.register(fragmentA2);
|
|
808
|
+
|
|
809
|
+
expect(scope.has(MyFragment)).toBe(true);
|
|
810
|
+
expect(scope.resolve(MyFragment)).toBe(fragmentA2);
|
|
811
|
+
expect(fragmentA2.array.length).toBe(0);
|
|
812
|
+
});
|
|
708
813
|
});
|