@adaas/a-concept 0.1.45 → 0.1.47
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 +64 -7
- package/dist/index.d.ts +64 -7
- package/dist/index.mjs +2 -2
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
- package/src/global/A-Entity/A-Entity.class.ts +2 -2
- package/src/global/A-Entity/A-Entity.error.ts +1 -1
- package/src/global/A-Scope/A-Scope.class.ts +22 -8
- package/src/global/A-Scope/A-Scope.types.ts +3 -0
- package/src/index.ts +16 -10
- package/tests/A-Scope.test.ts +27 -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.47",
|
|
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",
|
|
@@ -8,7 +8,7 @@ import { A_Scope } from "../A-Scope/A-Scope.class";
|
|
|
8
8
|
import { A_FormatterHelper } from "@adaas/a-concept/helpers/A_Formatter.helper";
|
|
9
9
|
import { ASEID } from "../ASEID/ASEID.class";
|
|
10
10
|
import { A_IdentityHelper } from "@adaas/a-concept/helpers/A_Identity.helper";
|
|
11
|
-
import {
|
|
11
|
+
import { A_EntityError } from "./A-Entity.error";
|
|
12
12
|
import { A_Feature } from "../A-Feature/A-Feature.class";
|
|
13
13
|
|
|
14
14
|
|
|
@@ -236,7 +236,7 @@ export class A_Entity<
|
|
|
236
236
|
}
|
|
237
237
|
|
|
238
238
|
// none of the above -> throw consistent error
|
|
239
|
-
throw new
|
|
239
|
+
throw new A_EntityError(A_EntityError.ValidationError, 'Unable to determine A-Entity constructor initialization method. Please check the provided parameters.');
|
|
240
240
|
}
|
|
241
241
|
|
|
242
242
|
|
|
@@ -184,14 +184,14 @@ export class A_Scope<
|
|
|
184
184
|
/**
|
|
185
185
|
* A set of constructors that are allowed in the scope
|
|
186
186
|
*/
|
|
187
|
-
params: Partial<A_TYPES__Scope_Init<_ComponentType, _ErrorType, _EntityType, _FragmentType>>,
|
|
187
|
+
params: Partial<A_TYPES__Scope_Init<_MetaItems, _ComponentType, _ErrorType, _EntityType, _FragmentType>>,
|
|
188
188
|
/**
|
|
189
189
|
* Configuration options for the scope
|
|
190
190
|
*/
|
|
191
191
|
config?: Partial<A_TYPES__ScopeConfig>
|
|
192
192
|
)
|
|
193
193
|
constructor(
|
|
194
|
-
param1?: Partial<A_TYPES__Scope_Init<_ComponentType, _ErrorType, _EntityType, _FragmentType>>,
|
|
194
|
+
param1?: Partial<A_TYPES__Scope_Init<_MetaItems, _ComponentType, _ErrorType, _EntityType, _FragmentType>>,
|
|
195
195
|
param2?: Partial<A_TYPES__ScopeConfig>
|
|
196
196
|
) {
|
|
197
197
|
const initializer = this.getInitializer(param1);
|
|
@@ -209,7 +209,7 @@ export class A_Scope<
|
|
|
209
209
|
* @returns
|
|
210
210
|
*/
|
|
211
211
|
protected getInitializer(
|
|
212
|
-
param1?: Partial<A_TYPES__Scope_Init<_ComponentType, _ErrorType, _EntityType, _FragmentType>>,
|
|
212
|
+
param1?: Partial<A_TYPES__Scope_Init<_MetaItems, _ComponentType, _ErrorType, _EntityType, _FragmentType>>,
|
|
213
213
|
param2?: Partial<A_TYPES__ScopeConfig>
|
|
214
214
|
): (param1: any, param2: any) => void | (() => void) {
|
|
215
215
|
switch (true) {
|
|
@@ -226,7 +226,7 @@ export class A_Scope<
|
|
|
226
226
|
|
|
227
227
|
|
|
228
228
|
protected defaultInitialized(
|
|
229
|
-
params: Partial<A_TYPES__Scope_Init<_ComponentType, _ErrorType, _EntityType, _FragmentType>> = {},
|
|
229
|
+
params: Partial<A_TYPES__Scope_Init<_MetaItems, _ComponentType, _ErrorType, _EntityType, _FragmentType>> = {},
|
|
230
230
|
config: Partial<A_TYPES__ScopeConfig> = {}
|
|
231
231
|
) {
|
|
232
232
|
this._name = params.name || this.constructor.name
|
|
@@ -235,6 +235,7 @@ export class A_Scope<
|
|
|
235
235
|
this.initErrors(params.errors);
|
|
236
236
|
this.initFragments(params.fragments);
|
|
237
237
|
this.initEntities(params.entities);
|
|
238
|
+
this.initMeta(params.meta);
|
|
238
239
|
|
|
239
240
|
if (config.parent) {
|
|
240
241
|
this._parent = config.parent;
|
|
@@ -282,6 +283,20 @@ export class A_Scope<
|
|
|
282
283
|
* @param _fragments
|
|
283
284
|
*/
|
|
284
285
|
protected initFragments(_fragments?: _FragmentType) { _fragments?.forEach(this.register.bind(this)); }
|
|
286
|
+
/**
|
|
287
|
+
* This method is used to initialize the meta in the scope
|
|
288
|
+
*
|
|
289
|
+
* This method only sets the meta values in the scope in case they are not set yet
|
|
290
|
+
*
|
|
291
|
+
* @param _meta
|
|
292
|
+
*/
|
|
293
|
+
protected initMeta(_meta?: Partial<_MetaItems>) {
|
|
294
|
+
if (_meta) {
|
|
295
|
+
Object.entries(_meta).forEach(([key, value]) => {
|
|
296
|
+
this._meta.set(key as keyof _MetaItems, value as _MetaItems[keyof _MetaItems]);
|
|
297
|
+
});
|
|
298
|
+
}
|
|
299
|
+
}
|
|
285
300
|
|
|
286
301
|
|
|
287
302
|
// ==========================================================================
|
|
@@ -324,7 +339,7 @@ export class A_Scope<
|
|
|
324
339
|
* }
|
|
325
340
|
* ```
|
|
326
341
|
*/
|
|
327
|
-
get(param:
|
|
342
|
+
get<K extends keyof _MetaItems>(param: K): _MetaItems[K] | undefined {
|
|
328
343
|
return this._meta.get(param);
|
|
329
344
|
}
|
|
330
345
|
|
|
@@ -340,7 +355,7 @@ export class A_Scope<
|
|
|
340
355
|
* scope.set('role', 'admin');
|
|
341
356
|
* ```
|
|
342
357
|
*/
|
|
343
|
-
set(param:
|
|
358
|
+
set<K extends keyof _MetaItems>(param: K, value: _MetaItems[K]): void {
|
|
344
359
|
this._meta.set(param, value);
|
|
345
360
|
}
|
|
346
361
|
|
|
@@ -1537,5 +1552,4 @@ export class A_Scope<
|
|
|
1537
1552
|
|
|
1538
1553
|
console.log(chain.join(' -> '));
|
|
1539
1554
|
}
|
|
1540
|
-
}
|
|
1541
|
-
|
|
1555
|
+
}
|
|
@@ -25,6 +25,7 @@ export type A_TYPES__Scope_Constructor<T = A_Scope> = new (...args: any[]) => T;
|
|
|
25
25
|
* Scope initialization type
|
|
26
26
|
*/
|
|
27
27
|
export type A_TYPES__Scope_Init<
|
|
28
|
+
_MetaItems extends Record<string, any> = any,
|
|
28
29
|
_ComponentType extends A_TYPES__Component_Constructor[] = A_TYPES__Component_Constructor[],
|
|
29
30
|
_ErrorType extends A_TYPES__Error_Constructor[] = A_TYPES__Error_Constructor[],
|
|
30
31
|
_EntityType extends A_TYPES__Entity_Constructor[] = A_TYPES__Entity_Constructor[],
|
|
@@ -54,6 +55,8 @@ export type A_TYPES__Scope_Init<
|
|
|
54
55
|
..._EntityType,
|
|
55
56
|
...InstanceType<_EntityType[number]>[]
|
|
56
57
|
];
|
|
58
|
+
|
|
59
|
+
meta: Partial<_MetaItems>;
|
|
57
60
|
};
|
|
58
61
|
/**
|
|
59
62
|
* Scope configuration type
|
package/src/index.ts
CHANGED
|
@@ -6,27 +6,35 @@ export * from './types/A_Common.types';
|
|
|
6
6
|
|
|
7
7
|
// ---------------------- Major Components ----------------------
|
|
8
8
|
export { A_Context } from './global/A-Context/A-Context.class';
|
|
9
|
+
export { A_ContextError } from './global/A-Context/A-Context.error';
|
|
9
10
|
export * from './global/A-Context/A-Context.types';
|
|
10
11
|
|
|
11
12
|
export { A_Concept } from './global/A-Concept/A-Concept.class';
|
|
12
13
|
export { A_ConceptMeta } from './global/A-Concept/A-Concept.meta';
|
|
13
14
|
export * from './global/A-Concept/A-Concept.types';
|
|
15
|
+
export * from './global/A-Concept/A-Concept.constants';
|
|
14
16
|
|
|
15
17
|
export { A_Container } from './global/A-Container/A-Container.class';
|
|
16
18
|
export { A_ContainerMeta } from './global/A-Container/A-Container.meta';
|
|
17
19
|
export * from './global/A-Container/A-Container.types';
|
|
20
|
+
export * from './global/A-Container/A-Container.constants';
|
|
18
21
|
|
|
19
22
|
export { A_Component } from './global/A-Component/A-Component.class';
|
|
20
23
|
export { A_ComponentMeta } from './global/A-Component/A-Component.meta';
|
|
21
24
|
export * from './global/A-Component/A-Component.types';
|
|
25
|
+
export * from './global/A-Component/A-Component.constants';
|
|
22
26
|
|
|
23
27
|
export { A_Entity } from './global/A-Entity/A-Entity.class';
|
|
28
|
+
export { A_EntityError } from './global/A-Entity/A-Entity.error';
|
|
29
|
+
export { A_EntityMeta } from './global/A-Entity/A-Entity.meta';
|
|
24
30
|
export * from './global/A-Entity/A-Entity.types';
|
|
31
|
+
export * from './global/A-Entity/A-Entity.constants';
|
|
25
32
|
|
|
26
33
|
|
|
27
34
|
// ---------------------- Common Components ----------------------
|
|
28
35
|
export { A_Abstraction } from './global/A-Abstraction/A-Abstraction.class';
|
|
29
36
|
export { A_AbstractionError } from './global/A-Abstraction/A-Abstraction.error';
|
|
37
|
+
export { A_Abstraction_Extend } from './global/A-Abstraction/A-Abstraction-Extend.decorator';
|
|
30
38
|
export * from './global/A-Abstraction/A-Abstraction.types';
|
|
31
39
|
|
|
32
40
|
export { A_Caller } from './global/A-Caller/A_Caller.class';
|
|
@@ -35,13 +43,17 @@ export * from './global/A-Caller/A_Caller.types';
|
|
|
35
43
|
|
|
36
44
|
export { A_Error } from './global/A-Error/A_Error.class';
|
|
37
45
|
export * from './global/A-Error/A_Error.types';
|
|
46
|
+
export * from './global/A-Error/A_Error.constants';
|
|
38
47
|
|
|
39
48
|
export { ASEID } from './global/ASEID/ASEID.class';
|
|
40
49
|
export { ASEID_Error } from './global/ASEID/ASEID.error';
|
|
41
50
|
export * from './global/ASEID/ASEID.types';
|
|
51
|
+
// export * from './global/ASEID/ASEID.constants';
|
|
42
52
|
|
|
43
53
|
export { A_Feature } from './global/A-Feature/A-Feature.class';
|
|
44
54
|
export { A_FeatureError } from './global/A-Feature/A-Feature.error';
|
|
55
|
+
export { A_Feature_Define } from './global/A-Feature/A-Feature-Define.decorator';
|
|
56
|
+
export { A_Feature_Extend } from './global/A-Feature/A-Feature-Extend.decorator';
|
|
45
57
|
export * from './global/A-Feature/A-Feature.types';
|
|
46
58
|
|
|
47
59
|
export { A_Stage } from './global/A-Stage/A-Stage.class';
|
|
@@ -60,20 +72,14 @@ export * from './global/A-Fragment/A-Fragment.types';
|
|
|
60
72
|
|
|
61
73
|
export { A_Dependency } from './global/A-Dependency/A-Dependency.class';
|
|
62
74
|
export { A_DependencyError } from './global/A-Dependency/A-Dependency.error';
|
|
75
|
+
export { A_Dependency_Require } from './global/A-Dependency/A-Dependency-Require.decorator';
|
|
76
|
+
export { A_Dependency_Load } from './global/A-Dependency/A-Dependency-Load.decorator';
|
|
77
|
+
export { A_Dependency_Default } from './global/A-Dependency/A-Dependency-Default.decorator';
|
|
63
78
|
export * from './global/A-Dependency/A-Dependency.types';
|
|
64
79
|
|
|
65
|
-
|
|
66
|
-
// =================================================================================================
|
|
67
|
-
// =============================== Export Decorators ===============================================
|
|
68
|
-
// =================================================================================================
|
|
80
|
+
export { A_InjectError } from './global/A-Inject/A-Inject.error';
|
|
69
81
|
export { A_Inject } from './global/A-Inject/A-Inject.decorator';
|
|
70
82
|
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
83
|
|
|
78
84
|
|
|
79
85
|
// =================================================================================================
|
package/tests/A-Scope.test.ts
CHANGED
|
@@ -47,6 +47,33 @@ describe('A-Scope tests', () => {
|
|
|
47
47
|
expect(userId).toBe('12345');
|
|
48
48
|
expect(role).toBe('admin');
|
|
49
49
|
});
|
|
50
|
+
it('Should be possible to set meta via constructor', async () => {
|
|
51
|
+
const scope = new A_Scope<{ userId: string, role: string }>({
|
|
52
|
+
name: 'TestScope',
|
|
53
|
+
meta: {
|
|
54
|
+
userId: '12345',
|
|
55
|
+
role: 'admin'
|
|
56
|
+
}
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
const userId = scope.get('userId');
|
|
60
|
+
const role = scope.get('role');
|
|
61
|
+
|
|
62
|
+
expect(userId).toBe('12345');
|
|
63
|
+
expect(role).toBe('admin');
|
|
64
|
+
});
|
|
65
|
+
it('Should properly use types and generics', async () => {
|
|
66
|
+
const scope = new A_Scope<{ userId: string, role: { name: string } }>({ name: 'TestScope' });
|
|
67
|
+
|
|
68
|
+
scope.set('userId', '12345');
|
|
69
|
+
scope.set('role', { name: 'admin' });
|
|
70
|
+
|
|
71
|
+
const userId = scope.get('userId');
|
|
72
|
+
const role = scope.get('role');
|
|
73
|
+
|
|
74
|
+
expect(userId).toBe('12345');
|
|
75
|
+
expect(role).toEqual({ name: 'admin' });
|
|
76
|
+
});
|
|
50
77
|
it('Should allow to register and resolve a component with dependencies', async () => {
|
|
51
78
|
class DependentComponent extends A_Component {
|
|
52
79
|
constructor(
|