@adaas/a-concept 0.1.38 → 0.1.41
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 +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.mjs +2 -2
- package/dist/index.mjs.map +1 -1
- package/package.json +2 -2
- package/src/global/A-Context/A-Context.class.ts +10 -13
- package/src/global/A-Error/A_Error.class.ts +14 -1
- package/src/global/A-Feature/A-Feature.class.ts +5 -0
- package/src/global/A-Scope/A-Scope.class.ts +1 -4
- package/tests/A-Feature.test.ts +429 -334
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@adaas/a-concept",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.41",
|
|
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",
|
|
@@ -45,7 +45,7 @@
|
|
|
45
45
|
"ext": "ts, js"
|
|
46
46
|
},
|
|
47
47
|
"scripts": {
|
|
48
|
-
"test": "jest ",
|
|
48
|
+
"test": "jest --detectOpenHandles",
|
|
49
49
|
"start": "nodemon ./tests/example-usage.ts",
|
|
50
50
|
"example:simple": "nodemon ./examples/simple/concept.ts",
|
|
51
51
|
"example:http": "nodemon ./examples/simple-http-server/concept.ts",
|
|
@@ -321,23 +321,20 @@ export class A_Context {
|
|
|
321
321
|
) {
|
|
322
322
|
const instance = this.getInstance();
|
|
323
323
|
|
|
324
|
-
|
|
325
324
|
const scope = A_TypeGuards.isScopeInstance(param1)
|
|
326
325
|
? param1
|
|
327
326
|
: instance._registry.get(param1);
|
|
328
327
|
|
|
329
328
|
if (!scope) return;
|
|
330
329
|
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
: this.issuer(scope);
|
|
330
|
+
const component = A_TypeGuards.isComponentInstance(param1)
|
|
331
|
+
? param1
|
|
332
|
+
: this.issuer(scope);
|
|
335
333
|
|
|
334
|
+
if (component)
|
|
336
335
|
instance._registry.delete(component);
|
|
336
|
+
if (scope)
|
|
337
337
|
instance._scopeIssuers.delete(scope);
|
|
338
|
-
} catch (error) {
|
|
339
|
-
return
|
|
340
|
-
}
|
|
341
338
|
}
|
|
342
339
|
|
|
343
340
|
|
|
@@ -520,7 +517,7 @@ export class A_Context {
|
|
|
520
517
|
* Provide the scope to get its issuer.
|
|
521
518
|
*/
|
|
522
519
|
scope: A_Scope
|
|
523
|
-
): A_TYPES__ScopeLinkedComponents {
|
|
520
|
+
): A_TYPES__ScopeLinkedComponents | undefined {
|
|
524
521
|
|
|
525
522
|
const instance = this.getInstance();
|
|
526
523
|
|
|
@@ -529,10 +526,10 @@ export class A_Context {
|
|
|
529
526
|
`Invalid parameter provided to get scope issuer. Parameter cannot be null or undefined.`
|
|
530
527
|
);
|
|
531
528
|
|
|
532
|
-
if (!instance._scopeIssuers.has(scope)) throw new A_ContextError(
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
);
|
|
529
|
+
// if (!instance._scopeIssuers.has(scope)) throw new A_ContextError(
|
|
530
|
+
// A_ContextError.ScopeNotFoundError,
|
|
531
|
+
// `Invalid parameter provided to get scope issuer. Provided scope does not have an issuer registered.`
|
|
532
|
+
// );
|
|
536
533
|
|
|
537
534
|
return instance._scopeIssuers.get(scope)!;
|
|
538
535
|
}
|
|
@@ -404,7 +404,20 @@ export class A_Error<
|
|
|
404
404
|
|
|
405
405
|
this._description = params.description;
|
|
406
406
|
this._link = params.link;
|
|
407
|
-
|
|
407
|
+
|
|
408
|
+
// Handle originalError: if it's an A_Error, we should trace back to the root cause
|
|
409
|
+
// to avoid infinite nesting of A_Error instances
|
|
410
|
+
if (params.originalError instanceof A_Error) {
|
|
411
|
+
// Find the root original error by traversing the chain
|
|
412
|
+
let rootError = params.originalError;
|
|
413
|
+
while (rootError.originalError instanceof A_Error) {
|
|
414
|
+
rootError = rootError.originalError;
|
|
415
|
+
}
|
|
416
|
+
// Set the root cause as the original error
|
|
417
|
+
this._originalError = rootError.originalError || rootError;
|
|
418
|
+
} else {
|
|
419
|
+
this._originalError = params.originalError;
|
|
420
|
+
}
|
|
408
421
|
}
|
|
409
422
|
|
|
410
423
|
/**
|
|
@@ -403,6 +403,8 @@ export class A_Feature<T extends A_TYPES__FeatureAvailableComponents = A_TYPES__
|
|
|
403
403
|
* @returns
|
|
404
404
|
*/
|
|
405
405
|
async completed(): Promise<void> {
|
|
406
|
+
if (this.isDone) return;
|
|
407
|
+
|
|
406
408
|
|
|
407
409
|
this._state = A_TYPES__FeatureState.COMPLETED;
|
|
408
410
|
|
|
@@ -415,6 +417,7 @@ export class A_Feature<T extends A_TYPES__FeatureAvailableComponents = A_TYPES__
|
|
|
415
417
|
* @param error
|
|
416
418
|
*/
|
|
417
419
|
async failed(error: A_FeatureError) {
|
|
420
|
+
if (this.isDone) return;
|
|
418
421
|
|
|
419
422
|
this._state = A_TYPES__FeatureState.FAILED;
|
|
420
423
|
|
|
@@ -436,6 +439,8 @@ export class A_Feature<T extends A_TYPES__FeatureAvailableComponents = A_TYPES__
|
|
|
436
439
|
*/
|
|
437
440
|
reason?: string | A_StageError | Error
|
|
438
441
|
) {
|
|
442
|
+
if (this.isDone) return;
|
|
443
|
+
|
|
439
444
|
switch (true) {
|
|
440
445
|
case A_TypeGuards.isString(reason):
|
|
441
446
|
this._error = new A_FeatureError(A_FeatureError.Interruption, reason);
|
|
@@ -294,6 +294,7 @@ export class A_Scope<
|
|
|
294
294
|
this._entities.clear();
|
|
295
295
|
|
|
296
296
|
if (this.issuer()) {
|
|
297
|
+
|
|
297
298
|
A_Context.deallocate(this);
|
|
298
299
|
}
|
|
299
300
|
}
|
|
@@ -311,11 +312,7 @@ export class A_Scope<
|
|
|
311
312
|
* @returns
|
|
312
313
|
*/
|
|
313
314
|
issuer<T extends A_TYPES__ScopeLinkedComponents>(): T | undefined {
|
|
314
|
-
try {
|
|
315
315
|
return A_Context.issuer(this) as T;
|
|
316
|
-
} catch (error) {
|
|
317
|
-
return undefined;
|
|
318
|
-
}
|
|
319
316
|
}
|
|
320
317
|
|
|
321
318
|
|