@adaas/a-concept 0.1.7 → 0.1.9
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/src/global/A-Error/A_Error.class.d.ts +22 -12
- package/dist/src/global/A-Error/A_Error.class.js +71 -42
- package/dist/src/global/A-Error/A_Error.class.js.map +1 -1
- package/dist/src/global/A-Error/A_Error.types.d.ts +6 -2
- package/dist/src/global/A-Feature/A-Feature.class.js +1 -1
- package/dist/src/global/A-Feature/A-Feature.class.js.map +1 -1
- package/dist/src/global/A-Scope/A-Scope.class.js +15 -4
- package/dist/src/global/A-Scope/A-Scope.class.js.map +1 -1
- package/dist/src/helpers/A_TypeGuards.helper.js +1 -1
- package/dist/src/helpers/A_TypeGuards.helper.js.map +1 -1
- package/package.json +2 -2
- package/src/global/A-Error/A_Error.class.ts +102 -46
- package/src/global/A-Error/A_Error.types.ts +6 -3
- package/src/global/A-Feature/A-Feature.class.ts +1 -1
- package/src/global/A-Scope/A-Scope.class.ts +15 -4
- package/src/helpers/A_TypeGuards.helper.ts +1 -1
- package/tests/A-Abstraction.test.ts +83 -1
- package/tests/A-Component.test.ts +25 -1
- package/tests/A-Concept.test.ts +22 -0
- package/tests/A-Container.test.ts +16 -0
- package/tests/A-Error.test.ts +22 -9
- package/tests/A-Scope.test.ts +57 -0
|
@@ -10,6 +10,7 @@ import { A_FormatterHelper } from '@adaas/a-concept/helpers/A_Formatter.helper';
|
|
|
10
10
|
import { A_Context } from '../A-Context/A-Context.class';
|
|
11
11
|
import { A_TypeGuards } from '@adaas/a-concept/helpers/A_TypeGuards.helper';
|
|
12
12
|
import { ASEID } from '../ASEID/ASEID.class';
|
|
13
|
+
import { A_CONSTANTS__DEFAULT_ENV_VARIABLES } from '@adaas/a-concept/constants/env.constants';
|
|
13
14
|
|
|
14
15
|
|
|
15
16
|
export class A_Error<
|
|
@@ -51,6 +52,10 @@ export class A_Error<
|
|
|
51
52
|
* ASEID of the error instance
|
|
52
53
|
*/
|
|
53
54
|
protected _aseid!: ASEID;
|
|
55
|
+
/**
|
|
56
|
+
* Title of the error
|
|
57
|
+
*/
|
|
58
|
+
protected _title!: string;
|
|
54
59
|
/**
|
|
55
60
|
* Possible Scope if needed to identify the error by it's execution environment
|
|
56
61
|
*/
|
|
@@ -133,39 +138,49 @@ export class A_Error<
|
|
|
133
138
|
/**
|
|
134
139
|
* Error message
|
|
135
140
|
*/
|
|
136
|
-
|
|
141
|
+
title: string,
|
|
137
142
|
/**
|
|
138
143
|
* Detailed description of the error
|
|
139
144
|
*/
|
|
140
145
|
description: string
|
|
141
146
|
)
|
|
142
|
-
|
|
143
147
|
constructor(
|
|
144
148
|
param1: _ConstructorType | Error | string | A_Error,
|
|
145
|
-
param2?: string
|
|
149
|
+
param2?: string
|
|
146
150
|
) {
|
|
147
151
|
// to prevent errors accumulation in the stack trace it returns the original error if provided param1 is A_Error
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
super(param1.message);
|
|
152
|
-
} else if (param1 instanceof Error) {
|
|
153
|
-
super(param1.message);
|
|
154
|
-
} else if (A_TypeGuards.isString(param1)) {
|
|
155
|
-
super(param1);
|
|
156
|
-
} else {
|
|
157
|
-
console.log('INVALID PARAMS PROVIDED TO A_ERROR CONSTRUCTOR: ', param1);
|
|
152
|
+
switch (true) {
|
|
153
|
+
case param1 instanceof A_Error:
|
|
154
|
+
return param1 as A_Error<_ConstructorType, _SerializedType>;
|
|
158
155
|
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
156
|
+
case param1 instanceof Error:
|
|
157
|
+
super(param1.message);
|
|
158
|
+
break;
|
|
159
|
+
|
|
160
|
+
case A_TypeGuards.isConstructorType<_ConstructorType>(param1) && 'description' in param1:
|
|
161
|
+
super(`[${param1.title}]: ${param1.description}`);
|
|
162
|
+
break;
|
|
163
|
+
|
|
164
|
+
case A_TypeGuards.isConstructorType<_ConstructorType>(param1) && !('description' in param1):
|
|
165
|
+
super(param1.title);
|
|
166
|
+
break;
|
|
164
167
|
|
|
165
|
-
|
|
166
|
-
|
|
168
|
+
case A_TypeGuards.isString(param1) && !param2:
|
|
169
|
+
super(param1);
|
|
170
|
+
break;
|
|
171
|
+
|
|
172
|
+
case A_TypeGuards.isString(param1) && !!param2:
|
|
173
|
+
super(`[${param1}]: ${param2}`);
|
|
174
|
+
break;
|
|
175
|
+
|
|
176
|
+
default:
|
|
177
|
+
throw new A_Error(
|
|
178
|
+
A_CONSTANTS__ERROR_CODES.VALIDATION_ERROR,
|
|
179
|
+
'Invalid parameters provided to A_Error constructor'
|
|
180
|
+
);
|
|
181
|
+
}
|
|
167
182
|
|
|
168
|
-
const initializer = this.getInitializer(param1);
|
|
183
|
+
const initializer = this.getInitializer(param1, param2);
|
|
169
184
|
// the returned initializer is already bound to `this` (we used .bind(this)),
|
|
170
185
|
// so calling it will run the appropriate logic on this instance:
|
|
171
186
|
initializer.call(this, param1, param2);
|
|
@@ -183,13 +198,20 @@ export class A_Error<
|
|
|
183
198
|
return this._aseid;
|
|
184
199
|
}
|
|
185
200
|
/**
|
|
186
|
-
* Returns
|
|
201
|
+
* Returns the title of the error
|
|
187
202
|
*
|
|
188
203
|
* Example: 'User not found', 'Validation error', 'Unauthorized access', etc.
|
|
189
204
|
*
|
|
190
|
-
* [!] Note: This
|
|
191
|
-
* [!] Note: If
|
|
192
|
-
* [!] Note: This
|
|
205
|
+
* [!] Note: This title should be short and concise, less than 60 characters
|
|
206
|
+
* [!] Note: If title exceeds 60 characters, there would be an error thrown
|
|
207
|
+
* [!] Note: This title is intended to be human-readable and can be displayed in UI or logs
|
|
208
|
+
*/
|
|
209
|
+
get title(): string {
|
|
210
|
+
return this._title;
|
|
211
|
+
}
|
|
212
|
+
/**
|
|
213
|
+
* Returns an Error message what is a brief title of the error
|
|
214
|
+
*
|
|
193
215
|
*/
|
|
194
216
|
get message(): string {
|
|
195
217
|
return super.message;
|
|
@@ -205,7 +227,7 @@ export class A_Error<
|
|
|
205
227
|
* [!] Note: If not provided would be used a kebab-case message of the error
|
|
206
228
|
*/
|
|
207
229
|
get code(): string {
|
|
208
|
-
return this._code || A_FormatterHelper.toKebabCase(this.
|
|
230
|
+
return this._code || A_FormatterHelper.toKebabCase(this.title);
|
|
209
231
|
}
|
|
210
232
|
/**
|
|
211
233
|
* Returns the type of the error which corresponds to the static entity of the class
|
|
@@ -257,7 +279,7 @@ export class A_Error<
|
|
|
257
279
|
* [!] Note: This description is intended to provide more context about the error and can be used for debugging or logging purposes
|
|
258
280
|
*/
|
|
259
281
|
get description(): string {
|
|
260
|
-
return this._description || process.env.A_ERROR_DEFAULT_DESCRIPTION || A_CONSTANTS__ERROR_DESCRIPTION;
|
|
282
|
+
return this._description || process.env[A_CONSTANTS__DEFAULT_ENV_VARIABLES.A_ERROR_DEFAULT_DESCRIPTION] || A_CONSTANTS__ERROR_DESCRIPTION;
|
|
261
283
|
}
|
|
262
284
|
/**
|
|
263
285
|
* Returns the original error if any
|
|
@@ -280,10 +302,14 @@ export class A_Error<
|
|
|
280
302
|
*/
|
|
281
303
|
protected getInitializer(
|
|
282
304
|
param1: _ConstructorType | Error | string | any,
|
|
305
|
+
param2?: string
|
|
283
306
|
): (param1: any, param2: any) => void | (() => void) {
|
|
284
307
|
switch (true) {
|
|
285
|
-
case A_TypeGuards.isString(param1):
|
|
286
|
-
return this.
|
|
308
|
+
case A_TypeGuards.isString(param1) && !param2:
|
|
309
|
+
return this.fromMessage;
|
|
310
|
+
|
|
311
|
+
case A_TypeGuards.isString(param1) && !!param2:
|
|
312
|
+
return this.fromTitle;
|
|
287
313
|
|
|
288
314
|
case param1 instanceof Error:
|
|
289
315
|
return this.fromError;
|
|
@@ -309,7 +335,7 @@ export class A_Error<
|
|
|
309
335
|
* @param error
|
|
310
336
|
*/
|
|
311
337
|
protected fromError(error: Error): void {
|
|
312
|
-
this.
|
|
338
|
+
this._title = A_CONSTANTS__ERROR_CODES.UNEXPECTED_ERROR;
|
|
313
339
|
|
|
314
340
|
this._aseid = new ASEID({
|
|
315
341
|
concept: (this.constructor as typeof A_Error).concept,
|
|
@@ -318,19 +344,16 @@ export class A_Error<
|
|
|
318
344
|
id: this.code
|
|
319
345
|
});
|
|
320
346
|
|
|
321
|
-
this._description = 'If you see this error please let us know.';
|
|
322
347
|
this._originalError = error;
|
|
323
348
|
}
|
|
324
349
|
/**
|
|
325
|
-
* Initializes the A_Error instance from a
|
|
350
|
+
* Initializes the A_Error instance from a message.
|
|
326
351
|
*
|
|
327
|
-
* @param
|
|
352
|
+
* @param title
|
|
328
353
|
* @param description
|
|
329
354
|
*/
|
|
330
|
-
protected
|
|
331
|
-
this.
|
|
332
|
-
this._scope = A_TypeGuards.isScopeInstance(description) ? description.name : undefined;
|
|
333
|
-
|
|
355
|
+
protected fromMessage(message: string): void {
|
|
356
|
+
this._title = A_CONSTANTS__ERROR_CODES.UNEXPECTED_ERROR;
|
|
334
357
|
|
|
335
358
|
this._aseid = new ASEID({
|
|
336
359
|
concept: (this.constructor as typeof A_Error).concept,
|
|
@@ -339,7 +362,23 @@ export class A_Error<
|
|
|
339
362
|
id: this.code
|
|
340
363
|
});
|
|
341
364
|
|
|
342
|
-
this.
|
|
365
|
+
this._link = undefined;
|
|
366
|
+
this._originalError = undefined;
|
|
367
|
+
}
|
|
368
|
+
|
|
369
|
+
|
|
370
|
+
fromTitle(title: string, description: string): void {
|
|
371
|
+
this.validateTitle(title);
|
|
372
|
+
|
|
373
|
+
this._title = title;
|
|
374
|
+
this._description = description;
|
|
375
|
+
|
|
376
|
+
this._aseid = new ASEID({
|
|
377
|
+
concept: (this.constructor as typeof A_Error).concept,
|
|
378
|
+
scope: this._scope || (this.constructor as typeof A_Error).scope,
|
|
379
|
+
entity: (this.constructor as typeof A_Error).entity,
|
|
380
|
+
id: this.code
|
|
381
|
+
});
|
|
343
382
|
|
|
344
383
|
this._link = undefined;
|
|
345
384
|
this._originalError = undefined;
|
|
@@ -350,6 +389,9 @@ export class A_Error<
|
|
|
350
389
|
* @param params
|
|
351
390
|
*/
|
|
352
391
|
protected fromConstructor(params: _ConstructorType): void {
|
|
392
|
+
this.validateTitle(params.title);
|
|
393
|
+
|
|
394
|
+
this._title = params.title;
|
|
353
395
|
this._code = params.code;
|
|
354
396
|
this._scope = params.scope ? (A_TypeGuards.isScopeInstance(params.scope) ? params.scope.name : params.scope) : undefined;
|
|
355
397
|
|
|
@@ -374,6 +416,7 @@ export class A_Error<
|
|
|
374
416
|
toJSON(): _SerializedType {
|
|
375
417
|
return {
|
|
376
418
|
aseid: this.aseid.toString(),
|
|
419
|
+
title: this.title,
|
|
377
420
|
code: this.code,
|
|
378
421
|
type: this.type,
|
|
379
422
|
message: this.message,
|
|
@@ -390,19 +433,32 @@ export class A_Error<
|
|
|
390
433
|
// ----------------------- PROTECTED HELPERS --------------------------------
|
|
391
434
|
// --------------------------------------------------------------------------
|
|
392
435
|
/**
|
|
393
|
-
* Checks if the provided
|
|
436
|
+
* Checks if the provided title exceeds 60 characters.
|
|
394
437
|
* If it does, throws a validation A_Error.
|
|
395
438
|
*
|
|
396
|
-
* @param
|
|
439
|
+
* @param title
|
|
397
440
|
*/
|
|
398
|
-
protected
|
|
399
|
-
if (
|
|
400
|
-
throw new A_Error(
|
|
441
|
+
protected validateTitle(title: string) {
|
|
442
|
+
if (title.length > 60) {
|
|
443
|
+
throw new A_Error(
|
|
444
|
+
A_CONSTANTS__ERROR_CODES.VALIDATION_ERROR,
|
|
445
|
+
'A-Error title exceeds 60 characters limit.'
|
|
446
|
+
);
|
|
401
447
|
}
|
|
402
|
-
if (
|
|
403
|
-
throw new A_Error(
|
|
448
|
+
if (title.length === 0) {
|
|
449
|
+
throw new A_Error(
|
|
450
|
+
A_CONSTANTS__ERROR_CODES.VALIDATION_ERROR,
|
|
451
|
+
'A-Error title cannot be empty.'
|
|
452
|
+
);
|
|
404
453
|
}
|
|
405
454
|
}
|
|
455
|
+
}
|
|
456
|
+
|
|
457
|
+
|
|
458
|
+
|
|
459
|
+
|
|
406
460
|
|
|
461
|
+
// message = title + description for better printing in the console
|
|
462
|
+
// description = detailed information about the error
|
|
463
|
+
// code = kebabcase (title)
|
|
407
464
|
|
|
408
|
-
}
|
|
@@ -15,12 +15,11 @@ export type A_TYPES__Error_Constructor<T = A_Error> = new (...args: any[]) => T;
|
|
|
15
15
|
*/
|
|
16
16
|
export type A_TYPES__Error_Init = {
|
|
17
17
|
/**
|
|
18
|
-
* Error
|
|
18
|
+
* Error title
|
|
19
19
|
*
|
|
20
20
|
* A short description of the error
|
|
21
21
|
*/
|
|
22
|
-
|
|
23
|
-
|
|
22
|
+
title: string;
|
|
24
23
|
|
|
25
24
|
/**
|
|
26
25
|
* Error code representing the type of error
|
|
@@ -65,6 +64,10 @@ export type A_TYPES__Error_Serialized = {
|
|
|
65
64
|
* ASEID of the error
|
|
66
65
|
*/
|
|
67
66
|
aseid: string,
|
|
67
|
+
/**
|
|
68
|
+
* A brief title of the error
|
|
69
|
+
*/
|
|
70
|
+
title: string,
|
|
68
71
|
/**
|
|
69
72
|
* Error message
|
|
70
73
|
*/
|
|
@@ -378,7 +378,7 @@ export class A_Feature<T extends A_TYPES__FeatureAvailableComponents = A_TYPES__
|
|
|
378
378
|
case A_TypeGuards.isErrorInstance(reason):
|
|
379
379
|
this._error = new A_FeatureError({
|
|
380
380
|
code: A_FeatureError.Interruption,
|
|
381
|
-
|
|
381
|
+
title: reason.title,
|
|
382
382
|
description: reason.description,
|
|
383
383
|
originalError: reason
|
|
384
384
|
});
|
|
@@ -386,22 +386,29 @@ export class A_Scope<
|
|
|
386
386
|
}
|
|
387
387
|
// 2) Check if it's a Component
|
|
388
388
|
case A_TypeGuards.isComponentConstructor(ctor): {
|
|
389
|
-
found = this.isAllowedComponent(ctor)
|
|
389
|
+
found = this.isAllowedComponent(ctor)
|
|
390
|
+
|| !![...this.allowedComponents]
|
|
391
|
+
.find(c => A_CommonHelper.isInheritedFrom(c, ctor));
|
|
390
392
|
|
|
391
393
|
break;
|
|
392
394
|
}
|
|
393
395
|
// 3) Check if it's an Entity
|
|
394
396
|
case A_TypeGuards.isEntityConstructor(ctor): {
|
|
395
|
-
found = this.isAllowedEntity(ctor)
|
|
397
|
+
found = this.isAllowedEntity(ctor)
|
|
398
|
+
|| !![...this.allowedEntities]
|
|
399
|
+
.find(e => A_CommonHelper.isInheritedFrom(e, ctor));
|
|
396
400
|
|
|
397
401
|
break;
|
|
398
402
|
}
|
|
399
403
|
// 4) Check if it's a Fragment
|
|
400
404
|
case A_TypeGuards.isFragmentConstructor(ctor): {
|
|
401
|
-
found = this.isAllowedFragment(ctor)
|
|
405
|
+
found = this.isAllowedFragment(ctor)
|
|
406
|
+
|| !![...this.allowedFragments]
|
|
407
|
+
.find(f => A_CommonHelper.isInheritedFrom(f, ctor));
|
|
402
408
|
|
|
403
409
|
break;
|
|
404
410
|
}
|
|
411
|
+
|
|
405
412
|
// check scope issuer
|
|
406
413
|
case this.issuer().constructor === ctor: {
|
|
407
414
|
found = true;
|
|
@@ -410,7 +417,11 @@ export class A_Scope<
|
|
|
410
417
|
}
|
|
411
418
|
|
|
412
419
|
if (!found && !!this._parent)
|
|
413
|
-
|
|
420
|
+
try {
|
|
421
|
+
return this._parent.has(ctor as any);
|
|
422
|
+
} catch (error) {
|
|
423
|
+
return false;
|
|
424
|
+
}
|
|
414
425
|
|
|
415
426
|
|
|
416
427
|
return found;
|
|
@@ -322,6 +322,6 @@ export class A_TypeGuards {
|
|
|
322
322
|
* @returns
|
|
323
323
|
*/
|
|
324
324
|
static isConstructorType<T extends A_TYPES__Error_Init>(param: any): param is T {
|
|
325
|
-
return !!param && A_TypeGuards.isObject(param) && !(param instanceof Error) && "
|
|
325
|
+
return !!param && A_TypeGuards.isObject(param) && !(param instanceof Error) && "title" in param;
|
|
326
326
|
}
|
|
327
327
|
}
|
|
@@ -2,6 +2,8 @@ import { A_Component } from '@adaas/a-concept/global/A-Component/A-Component.cla
|
|
|
2
2
|
import './test.setup'
|
|
3
3
|
import { A_Concept } from '@adaas/a-concept/global/A-Concept/A-Concept.class';
|
|
4
4
|
import { A_Container } from '@adaas/a-concept/global/A-Container/A-Container.class';
|
|
5
|
+
import { A_Context } from '@adaas/a-concept/global/A-Context/A-Context.class';
|
|
6
|
+
import { A_ScopeError } from '@adaas/a-concept/global/A-Scope/A-Scope.error';
|
|
5
7
|
|
|
6
8
|
jest.retryTimes(0);
|
|
7
9
|
|
|
@@ -68,5 +70,85 @@ describe('A-Abstraction Tests', () => {
|
|
|
68
70
|
expect(resolvedComponent._test2).toBe(1);
|
|
69
71
|
|
|
70
72
|
});
|
|
71
|
-
|
|
73
|
+
it('Should allow to extend abstraction with multiple containers', async () => {
|
|
74
|
+
A_Context.reset();
|
|
72
75
|
|
|
76
|
+
class MyContainerA extends A_Container {
|
|
77
|
+
_test: number = 0
|
|
78
|
+
|
|
79
|
+
@A_Concept.Load()
|
|
80
|
+
myMethod() {
|
|
81
|
+
this._test++;
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
class MyContainerB extends A_Container {
|
|
85
|
+
_test: number = 0
|
|
86
|
+
|
|
87
|
+
@A_Concept.Load()
|
|
88
|
+
myMethod() {
|
|
89
|
+
this._test++;
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
const containerA = new MyContainerA({ name: 'ContainerA' });
|
|
94
|
+
const containerB = new MyContainerB({ name: 'ContainerB' });
|
|
95
|
+
|
|
96
|
+
const concept = new A_Concept({
|
|
97
|
+
name: 'TestConcept',
|
|
98
|
+
containers: [
|
|
99
|
+
containerA,
|
|
100
|
+
containerB
|
|
101
|
+
]
|
|
102
|
+
});
|
|
103
|
+
|
|
104
|
+
await concept.load();
|
|
105
|
+
|
|
106
|
+
expect(containerA.scope.resolve(MyContainerA)).toBeInstanceOf(MyContainerA);
|
|
107
|
+
expect(containerB.scope.resolve(MyContainerB)).toBeInstanceOf(MyContainerB);
|
|
108
|
+
|
|
109
|
+
expect(containerA._test).toBe(1);
|
|
110
|
+
expect(containerB._test).toBe(1);
|
|
111
|
+
|
|
112
|
+
})
|
|
113
|
+
it('Should allow to define an async abstraction extension', async () => {
|
|
114
|
+
A_Context.reset();
|
|
115
|
+
|
|
116
|
+
class MyContainerA extends A_Container {
|
|
117
|
+
_test: number = 0
|
|
118
|
+
|
|
119
|
+
@A_Concept.Load()
|
|
120
|
+
async myMethod() {
|
|
121
|
+
this._test = 5;
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
class MyContainerB extends A_Container {
|
|
125
|
+
_test: number = 0
|
|
126
|
+
|
|
127
|
+
@A_Concept.Load()
|
|
128
|
+
myMethod() {
|
|
129
|
+
this._test++;
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
|
|
134
|
+
const containerA = new MyContainerA({ name: 'ContainerA' });
|
|
135
|
+
const containerB = new MyContainerB({ name: 'ContainerB' });
|
|
136
|
+
|
|
137
|
+
const concept = new A_Concept({
|
|
138
|
+
name: 'TestConcept',
|
|
139
|
+
containers: [
|
|
140
|
+
containerA,
|
|
141
|
+
containerB
|
|
142
|
+
]
|
|
143
|
+
});
|
|
144
|
+
|
|
145
|
+
await concept.load();
|
|
146
|
+
|
|
147
|
+
expect(containerA.scope.resolve(MyContainerA)).toBeInstanceOf(MyContainerA);
|
|
148
|
+
expect(containerB.scope.resolve(MyContainerB)).toBeInstanceOf(MyContainerB);
|
|
149
|
+
|
|
150
|
+
expect(containerA._test).toBe(5);
|
|
151
|
+
expect(containerB._test).toBe(1);
|
|
152
|
+
})
|
|
153
|
+
|
|
154
|
+
});
|
|
@@ -3,6 +3,8 @@ import './test.setup';
|
|
|
3
3
|
|
|
4
4
|
import { A_Component } from "@adaas/a-concept/global/A-Component/A-Component.class";
|
|
5
5
|
import { A_Context } from '@adaas/a-concept/global/A-Context/A-Context.class';
|
|
6
|
+
import { A_Concept } from '@adaas/a-concept/global/A-Concept/A-Concept.class';
|
|
7
|
+
import { A_TYPES__ComponentMetaKey } from '@adaas/a-concept/global/A-Component/A-Component.constants';
|
|
6
8
|
|
|
7
9
|
jest.retryTimes(0);
|
|
8
10
|
|
|
@@ -29,4 +31,26 @@ describe('A-Component tests', () => {
|
|
|
29
31
|
|
|
30
32
|
expect(dependentComponent.dependency).toBeInstanceOf(MyComponent);
|
|
31
33
|
});
|
|
32
|
-
|
|
34
|
+
it('Should inherit component meta correctly', async () => {
|
|
35
|
+
class BaseComponent extends A_Component {
|
|
36
|
+
@A_Concept.Load()
|
|
37
|
+
test() {
|
|
38
|
+
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
class ChildComponent extends BaseComponent { }
|
|
43
|
+
|
|
44
|
+
const baseMeta = A_Context.meta(BaseComponent);
|
|
45
|
+
const childMeta = A_Context.meta(ChildComponent);
|
|
46
|
+
|
|
47
|
+
const baseAbstractions = baseMeta.get(A_TYPES__ComponentMetaKey.ABSTRACTIONS)
|
|
48
|
+
const childAbstractions = childMeta.get(A_TYPES__ComponentMetaKey.ABSTRACTIONS)
|
|
49
|
+
|
|
50
|
+
for (const [key, value] of baseAbstractions!) {
|
|
51
|
+
expect(childAbstractions!.has(key)).toBe(true);
|
|
52
|
+
expect(childAbstractions!.get(key)).toBe(value);
|
|
53
|
+
}
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
});
|
package/tests/A-Concept.test.ts
CHANGED
|
@@ -105,5 +105,27 @@ describe('A-Concept tests', () => {
|
|
|
105
105
|
expect(concept.scope.resolve(MyContext)).toEqual(sharedContext);
|
|
106
106
|
expect(concept.scope.resolve(MyContext)).toEqual(sharedContext);
|
|
107
107
|
});
|
|
108
|
+
it('Should allow to register multiple containers', async () => {
|
|
109
|
+
A_Context.reset();
|
|
110
|
+
|
|
111
|
+
class MyContainerA extends A_Container { }
|
|
112
|
+
class MyContainerB extends A_Container { }
|
|
113
|
+
|
|
114
|
+
const containerA = new MyContainerA({ name: 'ContainerA' });
|
|
115
|
+
const containerB = new MyContainerB({ name: 'ContainerB' });
|
|
116
|
+
|
|
117
|
+
const concept = new A_Concept({
|
|
118
|
+
name: 'TestConcept',
|
|
119
|
+
containers: [
|
|
120
|
+
containerA,
|
|
121
|
+
containerB
|
|
122
|
+
]
|
|
123
|
+
});
|
|
124
|
+
|
|
125
|
+
expect(containerA.scope.resolve(MyContainerA)).toBeInstanceOf(MyContainerA);
|
|
126
|
+
expect(containerB.scope.resolve(MyContainerB)).toBeInstanceOf(MyContainerB);
|
|
127
|
+
|
|
128
|
+
})
|
|
129
|
+
|
|
108
130
|
|
|
109
131
|
});
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { A_Container } from '@adaas/a-concept/global/A-Container/A-Container.class';
|
|
2
|
+
import './test.setup';
|
|
3
|
+
import { A_Scope } from '@adaas/a-concept/global/A-Scope/A-Scope.class';
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
describe('A-Container tests', () => {
|
|
7
|
+
|
|
8
|
+
it('Should Allow to create a concept', async () => {
|
|
9
|
+
const container = new A_Container();
|
|
10
|
+
expect(container).toBeInstanceOf(A_Container);
|
|
11
|
+
expect(container.scope).toBeDefined();
|
|
12
|
+
expect(container.scope).toBeInstanceOf(A_Scope);
|
|
13
|
+
});
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
});
|
package/tests/A-Error.test.ts
CHANGED
|
@@ -2,6 +2,7 @@ import { A_CONSTANTS__DEFAULT_ENV_VARIABLES } from "@adaas/a-concept/constants/e
|
|
|
2
2
|
import { A_Context } from "@adaas/a-concept/global/A-Context/A-Context.class";
|
|
3
3
|
import { A_Error } from "@adaas/a-concept/global/A-Error/A_Error.class";
|
|
4
4
|
import { A_CONSTANTS__ERROR_CODES, A_CONSTANTS__ERROR_DESCRIPTION } from "@adaas/a-concept/global/A-Error/A_Error.constants";
|
|
5
|
+
import { A_FormatterHelper } from "@adaas/a-concept/helpers/A_Formatter.helper";
|
|
5
6
|
|
|
6
7
|
jest.retryTimes(0);
|
|
7
8
|
|
|
@@ -13,7 +14,8 @@ describe('A-Error Tests', () => {
|
|
|
13
14
|
|
|
14
15
|
expect(error).toBeDefined();
|
|
15
16
|
expect(error.message).toBe('Test error');
|
|
16
|
-
expect(error.
|
|
17
|
+
expect(error.title).toBe(A_CONSTANTS__ERROR_CODES.UNEXPECTED_ERROR);
|
|
18
|
+
expect(error.code).toBe(A_FormatterHelper.toKebabCase(A_CONSTANTS__ERROR_CODES.UNEXPECTED_ERROR));
|
|
17
19
|
expect(error.type).toBe('a-error');
|
|
18
20
|
});
|
|
19
21
|
|
|
@@ -24,7 +26,8 @@ describe('A-Error Tests', () => {
|
|
|
24
26
|
|
|
25
27
|
expect(error).toBeDefined();
|
|
26
28
|
expect(error.message).toBe('Original error');
|
|
27
|
-
expect(error.
|
|
29
|
+
expect(error.title).toBe(A_CONSTANTS__ERROR_CODES.UNEXPECTED_ERROR);
|
|
30
|
+
expect(error.code).toBe(A_FormatterHelper.toKebabCase(A_CONSTANTS__ERROR_CODES.UNEXPECTED_ERROR));
|
|
28
31
|
expect(error.type).toBe('a-error');
|
|
29
32
|
expect(error.originalError).toBe(originalError);
|
|
30
33
|
});
|
|
@@ -36,7 +39,8 @@ describe('A-Error Tests', () => {
|
|
|
36
39
|
|
|
37
40
|
expect(error).toBeDefined();
|
|
38
41
|
expect(error).toBe(originalError);
|
|
39
|
-
expect(error.
|
|
42
|
+
expect(error.title).toBe('Original A_Error');
|
|
43
|
+
expect(error.message).toBe('[Original A_Error]: This is the original error');
|
|
40
44
|
expect(error.code).toBe('original-a-error');
|
|
41
45
|
expect(error.type).toBe('a-error');
|
|
42
46
|
expect(error.description).toBe('This is the original error');
|
|
@@ -48,13 +52,14 @@ describe('A-Error Tests', () => {
|
|
|
48
52
|
const originalError = new A_Error('Original A_Error', 'This is the original error');
|
|
49
53
|
const error = new A_Error({
|
|
50
54
|
code: 'test-code',
|
|
51
|
-
|
|
55
|
+
title: 'Custom error message',
|
|
52
56
|
description: 'This is a custom error description',
|
|
53
57
|
originalError
|
|
54
58
|
});
|
|
55
59
|
|
|
56
60
|
expect(error).toBeDefined();
|
|
57
|
-
expect(error.
|
|
61
|
+
expect(error.title).toBe('Custom error message');
|
|
62
|
+
expect(error.message).toBe('[Custom error message]: This is a custom error description');
|
|
58
63
|
expect(error.code).toBe('test-code');
|
|
59
64
|
expect(error.type).toBe('a-error');
|
|
60
65
|
expect(error.description).toBe('This is a custom error description');
|
|
@@ -66,11 +71,12 @@ describe('A-Error Tests', () => {
|
|
|
66
71
|
const originalError = new A_Error('Original A_Error', 'This is the original error');
|
|
67
72
|
|
|
68
73
|
const error = new A_Error({
|
|
69
|
-
|
|
74
|
+
title: 'Custom error message',
|
|
70
75
|
originalError: originalError
|
|
71
76
|
});
|
|
72
77
|
|
|
73
78
|
expect(error).toBeDefined();
|
|
79
|
+
expect(error.title).toBe('Custom error message');
|
|
74
80
|
expect(error.message).toBe('Custom error message');
|
|
75
81
|
expect(error.code).toBe('custom-error-message');
|
|
76
82
|
expect(error.type).toBe('a-error');
|
|
@@ -84,20 +90,26 @@ describe('A-Error Tests', () => {
|
|
|
84
90
|
const error = new MyError('Test inherited error');
|
|
85
91
|
|
|
86
92
|
expect(error).toBeDefined();
|
|
93
|
+
expect(error.title).toBe(A_CONSTANTS__ERROR_CODES.UNEXPECTED_ERROR);
|
|
94
|
+
expect(error.code).toBe(A_FormatterHelper.toKebabCase(A_CONSTANTS__ERROR_CODES.UNEXPECTED_ERROR));
|
|
87
95
|
expect(error.message).toBe('Test inherited error');
|
|
88
|
-
expect(error.code).toBe('test-inherited-error');
|
|
89
96
|
expect(error.type).toBe('my-error');
|
|
90
97
|
});
|
|
91
98
|
|
|
92
99
|
it('It should be possible to serialize an A_Error instance', async () => {
|
|
93
100
|
|
|
94
101
|
const originalError = new A_Error('Original A_Error', 'This is the original error');
|
|
102
|
+
|
|
103
|
+
expect(originalError.title).toBe('Original A_Error');
|
|
104
|
+
|
|
105
|
+
|
|
95
106
|
const error = new A_Error(originalError);
|
|
96
107
|
|
|
97
108
|
const serialized = error.toJSON();
|
|
98
109
|
|
|
99
110
|
expect(serialized).toBeDefined();
|
|
100
|
-
expect(serialized.
|
|
111
|
+
expect(serialized.title).toBe('Original A_Error');
|
|
112
|
+
expect(serialized.message).toBe('[Original A_Error]: This is the original error');
|
|
101
113
|
expect(serialized.code).toBe('original-a-error');
|
|
102
114
|
expect(serialized.type).toBe('a-error');
|
|
103
115
|
expect(serialized.scope).toBe('root');
|
|
@@ -115,7 +127,8 @@ describe('A-Error Tests', () => {
|
|
|
115
127
|
|
|
116
128
|
expect(error).toBeDefined();
|
|
117
129
|
expect(error.message).toBe('Test error in custom concept and scope');
|
|
118
|
-
expect(error.
|
|
130
|
+
expect(error.title).toBe(A_CONSTANTS__ERROR_CODES.UNEXPECTED_ERROR);
|
|
131
|
+
expect(error.code).toBe(A_FormatterHelper.toKebabCase(A_CONSTANTS__ERROR_CODES.UNEXPECTED_ERROR));
|
|
119
132
|
expect(error.type).toBe('a-error');
|
|
120
133
|
expect(error.aseid.concept).toBe('my-project');
|
|
121
134
|
expect(error.aseid.scope).toBe('my-scope');
|