@adaas/a-concept 0.1.34 → 0.1.36
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.map +1 -1
- package/dist/index.d.mts +10 -10
- package/dist/index.d.ts +10 -10
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
- package/src/global/A-Fragment/A-Fragment.class.ts +6 -6
- package/src/global/A-Scope/A-Scope.class.ts +8 -8
- package/tests/A-Fragment.test.ts +40 -2
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@adaas/a-concept",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.36",
|
|
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",
|
|
@@ -153,7 +153,7 @@ export class A_Fragment<
|
|
|
153
153
|
* }
|
|
154
154
|
* ```
|
|
155
155
|
*/
|
|
156
|
-
get
|
|
156
|
+
get(param: keyof _MetaItems): _MetaItems[typeof param] | undefined {
|
|
157
157
|
return this._meta.get(param);
|
|
158
158
|
}
|
|
159
159
|
|
|
@@ -169,7 +169,7 @@ export class A_Fragment<
|
|
|
169
169
|
* fragment.set('role', 'admin');
|
|
170
170
|
* ```
|
|
171
171
|
*/
|
|
172
|
-
set
|
|
172
|
+
set(param: keyof _MetaItems, value: _MetaItems[typeof param]): void {
|
|
173
173
|
this._meta.set(param, value);
|
|
174
174
|
}
|
|
175
175
|
|
|
@@ -268,15 +268,15 @@ export class A_Fragment<
|
|
|
268
268
|
* ```
|
|
269
269
|
*/
|
|
270
270
|
clone(newName?: string): A_Fragment<_MetaItems, _SerializedType> {
|
|
271
|
-
const cloned = new (this.constructor as any)({
|
|
272
|
-
name: newName || `${this._name}_copy`
|
|
271
|
+
const cloned = new (this.constructor as any)({
|
|
272
|
+
name: newName || `${this._name}_copy`
|
|
273
273
|
});
|
|
274
|
-
|
|
274
|
+
|
|
275
275
|
// Copy all meta data
|
|
276
276
|
this._meta.toArray().forEach(([key, value]) => {
|
|
277
277
|
cloned.set(key, value);
|
|
278
278
|
});
|
|
279
|
-
|
|
279
|
+
|
|
280
280
|
return cloned;
|
|
281
281
|
}
|
|
282
282
|
|
|
@@ -1082,11 +1082,11 @@ export class A_Scope<
|
|
|
1082
1082
|
*/
|
|
1083
1083
|
component: A_TYPES__Component_Constructor<T>
|
|
1084
1084
|
): void
|
|
1085
|
-
register(
|
|
1085
|
+
register<T extends A_Component>(
|
|
1086
1086
|
/**
|
|
1087
1087
|
* Provide a command instance to register it in the scope
|
|
1088
1088
|
*/
|
|
1089
|
-
component:
|
|
1089
|
+
component: T
|
|
1090
1090
|
): void
|
|
1091
1091
|
register<T extends A_Error>(
|
|
1092
1092
|
/**
|
|
@@ -1094,11 +1094,11 @@ export class A_Scope<
|
|
|
1094
1094
|
*/
|
|
1095
1095
|
error: A_TYPES__Error_Constructor<T>
|
|
1096
1096
|
): void
|
|
1097
|
-
register(
|
|
1097
|
+
register<T extends A_Error>(
|
|
1098
1098
|
/**
|
|
1099
1099
|
* Provide an error instance to register it in the scope
|
|
1100
1100
|
*/
|
|
1101
|
-
error:
|
|
1101
|
+
error: T
|
|
1102
1102
|
): void
|
|
1103
1103
|
register<T extends A_Fragment>(
|
|
1104
1104
|
/**
|
|
@@ -1106,11 +1106,11 @@ export class A_Scope<
|
|
|
1106
1106
|
*/
|
|
1107
1107
|
fragment: A_TYPES__Fragment_Constructor<T>
|
|
1108
1108
|
): void
|
|
1109
|
-
register(
|
|
1109
|
+
register<T extends A_Fragment>(
|
|
1110
1110
|
/**
|
|
1111
1111
|
* Provide a fragment instance to register it in the scope
|
|
1112
1112
|
*/
|
|
1113
|
-
fragment:
|
|
1113
|
+
fragment: T
|
|
1114
1114
|
): void
|
|
1115
1115
|
register<T extends A_Entity>(
|
|
1116
1116
|
/**
|
|
@@ -1118,11 +1118,11 @@ export class A_Scope<
|
|
|
1118
1118
|
*/
|
|
1119
1119
|
entity: A_TYPES__Entity_Constructor<T>
|
|
1120
1120
|
): void
|
|
1121
|
-
register(
|
|
1121
|
+
register<T extends A_Entity>(
|
|
1122
1122
|
/**
|
|
1123
1123
|
* Provide an entity instance to register it in the scope
|
|
1124
1124
|
*/
|
|
1125
|
-
entity:
|
|
1125
|
+
entity: T
|
|
1126
1126
|
): void
|
|
1127
1127
|
|
|
1128
1128
|
register(
|
package/tests/A-Fragment.test.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { A_Fragment } from "@adaas/a-concept/global/A-Fragment/A-Fragment.class";
|
|
2
|
+
import { A_Scope } from "../src";
|
|
2
3
|
|
|
3
4
|
jest.retryTimes(0);
|
|
4
5
|
|
|
@@ -182,7 +183,7 @@ describe('A-Fragment Tests', () => {
|
|
|
182
183
|
});
|
|
183
184
|
|
|
184
185
|
it('It Should be possible to create an inherited A_Fragment instance', async () => {
|
|
185
|
-
|
|
186
|
+
|
|
186
187
|
class CustomFragment extends A_Fragment<{ sessionId: string; timestamp: number }> {
|
|
187
188
|
constructor() {
|
|
188
189
|
super({ name: 'CustomFragment' });
|
|
@@ -209,7 +210,7 @@ describe('A-Fragment Tests', () => {
|
|
|
209
210
|
});
|
|
210
211
|
|
|
211
212
|
it('It Should be possible to create a fragment with custom serialization', async () => {
|
|
212
|
-
|
|
213
|
+
|
|
213
214
|
class SessionFragment extends A_Fragment<
|
|
214
215
|
{ sessionId: string; timestamp: number },
|
|
215
216
|
{ name: string; sessionData: string }
|
|
@@ -286,5 +287,42 @@ describe('A-Fragment Tests', () => {
|
|
|
286
287
|
expect(fragment.has('c')).toBe(true);
|
|
287
288
|
expect(fragment.size()).toBe(2);
|
|
288
289
|
});
|
|
290
|
+
it('It Should allow override get method correctly', async () => {
|
|
291
|
+
|
|
292
|
+
const scope = new A_Scope();
|
|
293
|
+
|
|
294
|
+
class CustomFragment<T extends string[]> extends A_Fragment<{
|
|
295
|
+
[key in T[number]]: any
|
|
296
|
+
}> {
|
|
297
|
+
|
|
298
|
+
constructor(properties: T) {
|
|
299
|
+
super({ name: 'CustomFragment' });
|
|
300
|
+
properties.forEach((prop) => {
|
|
301
|
+
this.set(prop, `value_of_${prop}`);
|
|
302
|
+
});
|
|
303
|
+
}
|
|
304
|
+
get<K extends T[number]>(param: K): { [key in T[number]]: any; }[K] | undefined {
|
|
305
|
+
const originalValue = super.get(param);
|
|
306
|
+
if (originalValue !== undefined) {
|
|
307
|
+
return `custom_${originalValue}`;
|
|
308
|
+
}
|
|
309
|
+
return undefined;
|
|
310
|
+
}
|
|
311
|
+
|
|
289
312
|
|
|
313
|
+
}
|
|
314
|
+
|
|
315
|
+
|
|
316
|
+
const fragment = new CustomFragment<['key1', 'key2']>(['key1', 'key2']);
|
|
317
|
+
|
|
318
|
+
scope.register(fragment);
|
|
319
|
+
|
|
320
|
+
|
|
321
|
+
expect(fragment.get('key1')).toBe('custom_value_of_key1');
|
|
322
|
+
expect(fragment.get('key2')).toBe('custom_value_of_key2');
|
|
323
|
+
expect(fragment.get('key3' as any)).toBeUndefined();
|
|
324
|
+
|
|
325
|
+
scope.destroy();
|
|
326
|
+
|
|
327
|
+
});
|
|
290
328
|
});
|