@adaas/a-concept 0.3.2 → 0.3.3
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/browser/index.d.mts +40 -3
- package/dist/browser/index.mjs +2 -2
- package/dist/browser/index.mjs.map +1 -1
- package/dist/node/index.cjs +38 -1
- package/dist/node/index.cjs.map +1 -1
- package/dist/node/index.d.mts +40 -3
- package/dist/node/index.d.ts +40 -3
- package/dist/node/index.mjs +38 -1
- package/dist/node/index.mjs.map +1 -1
- package/package.json +1 -1
- package/src/lib/A-Context/A-Context.class.ts +3 -3
- package/src/lib/A-Meta/A-Meta.class.ts +22 -26
- package/src/lib/A-Scope/A-Scope.class.ts +59 -6
- package/tests/A-Meta.test.ts +44 -1
- package/tests/A-Scope.test.ts +17 -0
package/dist/node/index.d.mts
CHANGED
|
@@ -738,6 +738,12 @@ declare class A_Meta<_StorageItems extends Record<any, any> = any, _SerializedTy
|
|
|
738
738
|
* @returns
|
|
739
739
|
*/
|
|
740
740
|
from(meta: A_Meta<_StorageItems>): A_Meta<_StorageItems>;
|
|
741
|
+
/**
|
|
742
|
+
* Allows to create a copy of the meta object with the same values, this is needed to ensure that when we inherit meta from the parent component, we create a copy of it, not a reference to the same object. This allows us to modify the meta of the child component without affecting the meta of the parent component.
|
|
743
|
+
*
|
|
744
|
+
* @returns
|
|
745
|
+
*/
|
|
746
|
+
clone(): A_Meta<_StorageItems>;
|
|
741
747
|
/**
|
|
742
748
|
* Method to set values in the map
|
|
743
749
|
*
|
|
@@ -813,7 +819,18 @@ declare class A_Meta<_StorageItems extends Record<any, any> = any, _SerializedTy
|
|
|
813
819
|
* Method to clear the map
|
|
814
820
|
*/
|
|
815
821
|
clear(): void;
|
|
822
|
+
/**
|
|
823
|
+
* Method to convert the meta to an array of key-value pairs
|
|
824
|
+
*
|
|
825
|
+
* @returns
|
|
826
|
+
*/
|
|
816
827
|
toArray(): Array<[keyof _StorageItems, _StorageItems[keyof _StorageItems]]>;
|
|
828
|
+
/**
|
|
829
|
+
* Helper method to recursively convert the meta object to a JSON-compatible format. It handles nested A_Meta instances, Maps, Arrays, and plain objects.
|
|
830
|
+
*
|
|
831
|
+
* @param value
|
|
832
|
+
* @returns
|
|
833
|
+
*/
|
|
817
834
|
protected recursiveToJSON(value: any): any;
|
|
818
835
|
/**
|
|
819
836
|
* Serializes the meta to a JSON object
|
|
@@ -3330,7 +3347,27 @@ declare class A_Scope<_MetaItems extends Record<string, any> = any, _ComponentTy
|
|
|
3330
3347
|
* Provide the fragment name in PascalCase to retrieve its constructor
|
|
3331
3348
|
*/
|
|
3332
3349
|
name: string): A_TYPES__Fragment_Constructor<T>;
|
|
3333
|
-
resolveConstructor<T extends
|
|
3350
|
+
resolveConstructor<T extends A_Component>(
|
|
3351
|
+
/**
|
|
3352
|
+
* Provide the component constructor or its name to retrieve its constructor
|
|
3353
|
+
*/
|
|
3354
|
+
component: A_TYPES__Ctor<T>): A_TYPES__Component_Constructor<T> | undefined;
|
|
3355
|
+
resolveConstructor<T extends A_Entity>(
|
|
3356
|
+
/**
|
|
3357
|
+
* Provide the entity constructor or its name to retrieve its constructor
|
|
3358
|
+
*/
|
|
3359
|
+
entity: A_TYPES__Ctor<T>): A_TYPES__Entity_Constructor<T> | undefined;
|
|
3360
|
+
resolveConstructor<T extends A_Fragment>(
|
|
3361
|
+
/**
|
|
3362
|
+
* Provide the fragment constructor or its name to retrieve its constructor
|
|
3363
|
+
*/
|
|
3364
|
+
fragment: A_TYPES__Ctor<T>): A_TYPES__Fragment_Constructor<T> | undefined;
|
|
3365
|
+
resolveConstructor<T extends A_Error>(
|
|
3366
|
+
/**
|
|
3367
|
+
* Provide the error constructor or its name to retrieve its constructor
|
|
3368
|
+
*/
|
|
3369
|
+
error: A_TYPES__Ctor<T>): A_TYPES__Error_Constructor<T> | undefined;
|
|
3370
|
+
resolveConstructor<T extends A_TYPES__A_DependencyInjectable>(name: string | A_TYPES__Ctor<T>): A_TYPES__Entity_Constructor<T> | A_TYPES__Component_Constructor<T> | A_TYPES__Fragment_Constructor<T> | undefined;
|
|
3334
3371
|
/**
|
|
3335
3372
|
* This method should resolve all instances of the components, or entities within the scope, by provided parent class
|
|
3336
3373
|
* So in case of providing a base class it should return all instances that extends this base class
|
|
@@ -4200,11 +4237,11 @@ declare class A_Context {
|
|
|
4200
4237
|
* Get meta for the specific entity class by constructor.
|
|
4201
4238
|
*/
|
|
4202
4239
|
entity: A_TYPES__Entity_Constructor): T;
|
|
4203
|
-
static meta<T extends A_EntityMeta>(
|
|
4240
|
+
static meta<T extends A_EntityMeta, E extends A_Entity>(
|
|
4204
4241
|
/**
|
|
4205
4242
|
* Get meta for the specific entity instance.
|
|
4206
4243
|
*/
|
|
4207
|
-
entity:
|
|
4244
|
+
entity: E): T;
|
|
4208
4245
|
static meta<T extends A_ComponentMeta>(
|
|
4209
4246
|
/**
|
|
4210
4247
|
* Get meta for the specific component class by constructor.
|
package/dist/node/index.d.ts
CHANGED
|
@@ -738,6 +738,12 @@ declare class A_Meta<_StorageItems extends Record<any, any> = any, _SerializedTy
|
|
|
738
738
|
* @returns
|
|
739
739
|
*/
|
|
740
740
|
from(meta: A_Meta<_StorageItems>): A_Meta<_StorageItems>;
|
|
741
|
+
/**
|
|
742
|
+
* Allows to create a copy of the meta object with the same values, this is needed to ensure that when we inherit meta from the parent component, we create a copy of it, not a reference to the same object. This allows us to modify the meta of the child component without affecting the meta of the parent component.
|
|
743
|
+
*
|
|
744
|
+
* @returns
|
|
745
|
+
*/
|
|
746
|
+
clone(): A_Meta<_StorageItems>;
|
|
741
747
|
/**
|
|
742
748
|
* Method to set values in the map
|
|
743
749
|
*
|
|
@@ -813,7 +819,18 @@ declare class A_Meta<_StorageItems extends Record<any, any> = any, _SerializedTy
|
|
|
813
819
|
* Method to clear the map
|
|
814
820
|
*/
|
|
815
821
|
clear(): void;
|
|
822
|
+
/**
|
|
823
|
+
* Method to convert the meta to an array of key-value pairs
|
|
824
|
+
*
|
|
825
|
+
* @returns
|
|
826
|
+
*/
|
|
816
827
|
toArray(): Array<[keyof _StorageItems, _StorageItems[keyof _StorageItems]]>;
|
|
828
|
+
/**
|
|
829
|
+
* Helper method to recursively convert the meta object to a JSON-compatible format. It handles nested A_Meta instances, Maps, Arrays, and plain objects.
|
|
830
|
+
*
|
|
831
|
+
* @param value
|
|
832
|
+
* @returns
|
|
833
|
+
*/
|
|
817
834
|
protected recursiveToJSON(value: any): any;
|
|
818
835
|
/**
|
|
819
836
|
* Serializes the meta to a JSON object
|
|
@@ -3330,7 +3347,27 @@ declare class A_Scope<_MetaItems extends Record<string, any> = any, _ComponentTy
|
|
|
3330
3347
|
* Provide the fragment name in PascalCase to retrieve its constructor
|
|
3331
3348
|
*/
|
|
3332
3349
|
name: string): A_TYPES__Fragment_Constructor<T>;
|
|
3333
|
-
resolveConstructor<T extends
|
|
3350
|
+
resolveConstructor<T extends A_Component>(
|
|
3351
|
+
/**
|
|
3352
|
+
* Provide the component constructor or its name to retrieve its constructor
|
|
3353
|
+
*/
|
|
3354
|
+
component: A_TYPES__Ctor<T>): A_TYPES__Component_Constructor<T> | undefined;
|
|
3355
|
+
resolveConstructor<T extends A_Entity>(
|
|
3356
|
+
/**
|
|
3357
|
+
* Provide the entity constructor or its name to retrieve its constructor
|
|
3358
|
+
*/
|
|
3359
|
+
entity: A_TYPES__Ctor<T>): A_TYPES__Entity_Constructor<T> | undefined;
|
|
3360
|
+
resolveConstructor<T extends A_Fragment>(
|
|
3361
|
+
/**
|
|
3362
|
+
* Provide the fragment constructor or its name to retrieve its constructor
|
|
3363
|
+
*/
|
|
3364
|
+
fragment: A_TYPES__Ctor<T>): A_TYPES__Fragment_Constructor<T> | undefined;
|
|
3365
|
+
resolveConstructor<T extends A_Error>(
|
|
3366
|
+
/**
|
|
3367
|
+
* Provide the error constructor or its name to retrieve its constructor
|
|
3368
|
+
*/
|
|
3369
|
+
error: A_TYPES__Ctor<T>): A_TYPES__Error_Constructor<T> | undefined;
|
|
3370
|
+
resolveConstructor<T extends A_TYPES__A_DependencyInjectable>(name: string | A_TYPES__Ctor<T>): A_TYPES__Entity_Constructor<T> | A_TYPES__Component_Constructor<T> | A_TYPES__Fragment_Constructor<T> | undefined;
|
|
3334
3371
|
/**
|
|
3335
3372
|
* This method should resolve all instances of the components, or entities within the scope, by provided parent class
|
|
3336
3373
|
* So in case of providing a base class it should return all instances that extends this base class
|
|
@@ -4200,11 +4237,11 @@ declare class A_Context {
|
|
|
4200
4237
|
* Get meta for the specific entity class by constructor.
|
|
4201
4238
|
*/
|
|
4202
4239
|
entity: A_TYPES__Entity_Constructor): T;
|
|
4203
|
-
static meta<T extends A_EntityMeta>(
|
|
4240
|
+
static meta<T extends A_EntityMeta, E extends A_Entity>(
|
|
4204
4241
|
/**
|
|
4205
4242
|
* Get meta for the specific entity instance.
|
|
4206
4243
|
*/
|
|
4207
|
-
entity:
|
|
4244
|
+
entity: E): T;
|
|
4208
4245
|
static meta<T extends A_ComponentMeta>(
|
|
4209
4246
|
/**
|
|
4210
4247
|
* Get meta for the specific component class by constructor.
|
package/dist/node/index.mjs
CHANGED
|
@@ -1256,6 +1256,17 @@ var A_Meta = class _A_Meta {
|
|
|
1256
1256
|
this.meta = new Map(meta.meta);
|
|
1257
1257
|
return this;
|
|
1258
1258
|
}
|
|
1259
|
+
/**
|
|
1260
|
+
* Allows to create a copy of the meta object with the same values, this is needed to ensure that when we inherit meta from the parent component, we create a copy of it, not a reference to the same object. This allows us to modify the meta of the child component without affecting the meta of the parent component.
|
|
1261
|
+
*
|
|
1262
|
+
* @returns
|
|
1263
|
+
*/
|
|
1264
|
+
clone() {
|
|
1265
|
+
const ctor = this.constructor;
|
|
1266
|
+
const copy = new ctor();
|
|
1267
|
+
copy.meta = new Map(this.meta);
|
|
1268
|
+
return copy;
|
|
1269
|
+
}
|
|
1259
1270
|
/**
|
|
1260
1271
|
* Method to set values in the map
|
|
1261
1272
|
*
|
|
@@ -1367,9 +1378,20 @@ var A_Meta = class _A_Meta {
|
|
|
1367
1378
|
clear() {
|
|
1368
1379
|
this.meta.clear();
|
|
1369
1380
|
}
|
|
1381
|
+
/**
|
|
1382
|
+
* Method to convert the meta to an array of key-value pairs
|
|
1383
|
+
*
|
|
1384
|
+
* @returns
|
|
1385
|
+
*/
|
|
1370
1386
|
toArray() {
|
|
1371
1387
|
return Array.from(this.meta.entries());
|
|
1372
1388
|
}
|
|
1389
|
+
/**
|
|
1390
|
+
* Helper method to recursively convert the meta object to a JSON-compatible format. It handles nested A_Meta instances, Maps, Arrays, and plain objects.
|
|
1391
|
+
*
|
|
1392
|
+
* @param value
|
|
1393
|
+
* @returns
|
|
1394
|
+
*/
|
|
1373
1395
|
recursiveToJSON(value) {
|
|
1374
1396
|
switch (true) {
|
|
1375
1397
|
case value instanceof _A_Meta:
|
|
@@ -4122,6 +4144,21 @@ var A_Scope = class {
|
|
|
4122
4144
|
return slice.length === 1 && count !== -1 ? slice[0] : slice.length ? slice : void 0;
|
|
4123
4145
|
}
|
|
4124
4146
|
resolveConstructor(name) {
|
|
4147
|
+
switch (true) {
|
|
4148
|
+
case A_TypeGuards.isComponentConstructor(name):
|
|
4149
|
+
return Array.from(this.allowedComponents).find((c) => A_CommonHelper.isInheritedFrom(c, name));
|
|
4150
|
+
case A_TypeGuards.isEntityConstructor(name):
|
|
4151
|
+
return Array.from(this.allowedEntities).find((e) => A_CommonHelper.isInheritedFrom(e, name));
|
|
4152
|
+
case A_TypeGuards.isFragmentConstructor(name):
|
|
4153
|
+
return Array.from(this.allowedFragments).find((f) => A_CommonHelper.isInheritedFrom(f, name));
|
|
4154
|
+
case A_TypeGuards.isErrorConstructor(name):
|
|
4155
|
+
return Array.from(this.allowedErrors).find((e) => A_CommonHelper.isInheritedFrom(e, name));
|
|
4156
|
+
}
|
|
4157
|
+
if (!A_TypeGuards.isString(name))
|
|
4158
|
+
throw new A_ScopeError(
|
|
4159
|
+
A_ScopeError.ResolutionError,
|
|
4160
|
+
`Invalid constructor name provided: ${name}`
|
|
4161
|
+
);
|
|
4125
4162
|
const component = Array.from(this.allowedComponents).find(
|
|
4126
4163
|
(c) => c.name === name || c.name === A_FormatterHelper.toPascalCase(name)
|
|
4127
4164
|
);
|
|
@@ -5024,7 +5061,7 @@ var A_Context = class _A_Context {
|
|
|
5024
5061
|
}
|
|
5025
5062
|
if (!inheritedMeta)
|
|
5026
5063
|
inheritedMeta = new metaType();
|
|
5027
|
-
instance._metaStorage.set(property,
|
|
5064
|
+
instance._metaStorage.set(property, inheritedMeta.clone());
|
|
5028
5065
|
}
|
|
5029
5066
|
return instance._metaStorage.get(property);
|
|
5030
5067
|
}
|