@adaas/a-concept 0.1.35 → 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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@adaas/a-concept",
3
- "version": "0.1.35",
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<K extends keyof _MetaItems>(param: K): _MetaItems[K] | undefined {
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<K extends keyof _MetaItems>(param: K, value: _MetaItems[K]): void {
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
 
@@ -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
  });