@adaas/a-utils 0.1.23 → 0.1.25
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 +1 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.mjs +1 -1
- package/dist/index.mjs.map +1 -1
- package/package.json +2 -2
- package/src/lib/A-Command/A-Command.entity.ts +9 -2
- package/tests/A-Command.test.ts +65 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@adaas/a-utils",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.25",
|
|
4
4
|
"description": "A-Utils is a set of utilities that are used across the ADAAS ecosystem. This package is designed to be a collection of utilities that are used across the ADAAS ecosystem.",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"main": "./dist/index.cjs",
|
|
@@ -80,7 +80,7 @@
|
|
|
80
80
|
"build": "tsup --config tsup.config.ts"
|
|
81
81
|
},
|
|
82
82
|
"dependencies": {
|
|
83
|
-
"@adaas/a-concept": "^0.1.
|
|
83
|
+
"@adaas/a-concept": "^0.1.47"
|
|
84
84
|
},
|
|
85
85
|
"devDependencies": {
|
|
86
86
|
"@types/chai": "^4.3.14",
|
|
@@ -478,8 +478,6 @@ export class A_Command<
|
|
|
478
478
|
await new Promise<void>(async (resolve, reject) => {
|
|
479
479
|
|
|
480
480
|
try {
|
|
481
|
-
|
|
482
|
-
|
|
483
481
|
const onBeforeExecuteFeature = new A_Feature({
|
|
484
482
|
name: A_CommandFeatures.onBeforeExecute,
|
|
485
483
|
component: this,
|
|
@@ -509,6 +507,15 @@ export class A_Command<
|
|
|
509
507
|
resolve();
|
|
510
508
|
});
|
|
511
509
|
|
|
510
|
+
this.on(A_CommandEvent.onFail, () => {
|
|
511
|
+
|
|
512
|
+
onBeforeExecuteFeature.interrupt();
|
|
513
|
+
onExecuteFeature.interrupt();
|
|
514
|
+
onAfterExecuteFeature.interrupt();
|
|
515
|
+
|
|
516
|
+
reject(this.error);
|
|
517
|
+
});
|
|
518
|
+
|
|
512
519
|
|
|
513
520
|
await onBeforeExecuteFeature.process(this.scope);
|
|
514
521
|
|
package/tests/A-Command.test.ts
CHANGED
|
@@ -612,6 +612,71 @@ describe('A-Command tests', () => {
|
|
|
612
612
|
expect([A_Command_Status.COMPLETED, A_Command_Status.FAILED])
|
|
613
613
|
.toContain(command.status);
|
|
614
614
|
});
|
|
615
|
+
|
|
616
|
+
it('Should stop command execution in case of error', async () => {
|
|
617
|
+
|
|
618
|
+
class FailingProcessor extends A_Component {
|
|
619
|
+
|
|
620
|
+
@A_Feature.Extend({
|
|
621
|
+
name: A_CommandFeatures.onExecute
|
|
622
|
+
})
|
|
623
|
+
async step1(
|
|
624
|
+
@A_Inject(A_Caller) command: ErrorTestCommand
|
|
625
|
+
) {
|
|
626
|
+
await new Promise(resolve => setTimeout(resolve, 500));
|
|
627
|
+
|
|
628
|
+
testExecutionLog.push('Step 1 executed');
|
|
629
|
+
}
|
|
630
|
+
|
|
631
|
+
@A_Feature.Extend({
|
|
632
|
+
name: A_CommandFeatures.onExecute
|
|
633
|
+
})
|
|
634
|
+
async step2(
|
|
635
|
+
@A_Inject(A_Caller) command: ErrorTestCommand
|
|
636
|
+
) {
|
|
637
|
+
await new Promise(resolve => setTimeout(resolve, 500));
|
|
638
|
+
testExecutionLog.push('Step 2 executed');
|
|
639
|
+
throw new Error('Simulated error in step 2');
|
|
640
|
+
}
|
|
641
|
+
|
|
642
|
+
@A_Feature.Extend({
|
|
643
|
+
name: A_CommandFeatures.onExecute
|
|
644
|
+
})
|
|
645
|
+
async step3(
|
|
646
|
+
@A_Inject(A_Caller) command: ErrorTestCommand
|
|
647
|
+
) {
|
|
648
|
+
testExecutionLog.push('Step 3 executed');
|
|
649
|
+
}
|
|
650
|
+
}
|
|
651
|
+
|
|
652
|
+
const container = new A_Container({
|
|
653
|
+
name: 'Error Stop Test Container',
|
|
654
|
+
components: [
|
|
655
|
+
FailingProcessor,
|
|
656
|
+
A_StateMachine
|
|
657
|
+
],
|
|
658
|
+
entities: [ErrorTestCommand]
|
|
659
|
+
});
|
|
660
|
+
|
|
661
|
+
const concept = new A_Concept({
|
|
662
|
+
containers: [container]
|
|
663
|
+
});
|
|
664
|
+
|
|
665
|
+
await concept.load();
|
|
666
|
+
|
|
667
|
+
const command = new ErrorTestCommand({ shouldFail: true });
|
|
668
|
+
container.scope.register(command);
|
|
669
|
+
|
|
670
|
+
await command.execute();
|
|
671
|
+
|
|
672
|
+
expect(command.status).toBe(A_Command_Status.FAILED);
|
|
673
|
+
expect(command.error).toBeDefined();
|
|
674
|
+
expect(command.isProcessed).toBe(true);
|
|
675
|
+
expect(testExecutionLog).toEqual([
|
|
676
|
+
'Step 1 executed',
|
|
677
|
+
'Step 2 executed'
|
|
678
|
+
]); // Step 3 should not be executed
|
|
679
|
+
});
|
|
615
680
|
});
|
|
616
681
|
|
|
617
682
|
// =============================================================================
|