@adaas/a-utils 0.1.21 → 0.1.23
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 +5 -5
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.mts +136 -54
- package/dist/index.d.ts +136 -54
- package/dist/index.mjs +5 -5
- package/dist/index.mjs.map +1 -1
- package/package.json +2 -2
- package/src/index.ts +6 -0
- package/src/lib/A-Channel/A-Channel.constants.ts +12 -12
- package/src/lib/A-Command/A-Command.constants.ts +60 -18
- package/src/lib/A-Command/A-Command.entity.ts +33 -16
- package/src/lib/A-Command/A-Command.types.ts +21 -13
- package/src/lib/A-Config/A-Config.context.ts +38 -59
- package/src/lib/A-Config/components/ConfigReader.component.ts +17 -15
- package/src/lib/A-Execution/A-Execution.context.ts +67 -0
- package/src/lib/A-Execution/A-Execution.types.ts +0 -0
- package/src/lib/A-Memory/A-Memory.component.ts +1 -1
- package/src/lib/A-Memory/A-Memory.constants.ts +10 -10
- package/src/lib/A-Memory/A-Memory.context.ts +18 -9
- package/src/lib/A-Memory/A-Memory.types.ts +12 -1
- package/src/lib/A-Operation/A-Operation.context.ts +3 -2
- package/src/lib/A-StateMachine/A-StateMachine.constants.ts +4 -4
- package/tests/A-Command.test.ts +6 -6
- package/tests/A-Config.test.ts +5 -11
- package/tests/A-Manifest.test.ts +3 -3
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@adaas/a-utils",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.23",
|
|
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.46"
|
|
84
84
|
},
|
|
85
85
|
"devDependencies": {
|
|
86
86
|
"@types/chai": "^4.3.14",
|
package/src/index.ts
CHANGED
|
@@ -59,6 +59,12 @@ export { A_MemoryError } from './lib/A-Memory/A-Memory.error';
|
|
|
59
59
|
export * from './lib/A-Memory/A-Memory.constants';
|
|
60
60
|
export * from './lib/A-Memory/A-Memory.types';
|
|
61
61
|
|
|
62
|
+
// ============================================================================
|
|
63
|
+
// A-Execution Components
|
|
64
|
+
// ============================================================================
|
|
65
|
+
export { A_ExecutionContext } from './lib/A-Execution/A-Execution.context';
|
|
66
|
+
// export * from './lib/A-Execution/A-Execution.types';
|
|
67
|
+
|
|
62
68
|
// ============================================================================
|
|
63
69
|
// A-Operation Components
|
|
64
70
|
// ============================================================================
|
|
@@ -7,53 +7,53 @@ export enum A_ChannelFeatures {
|
|
|
7
7
|
/**
|
|
8
8
|
* Allows to extend timeout logic and behavior
|
|
9
9
|
*/
|
|
10
|
-
onTimeout = '
|
|
10
|
+
onTimeout = '_A_Channel_onTimeout',
|
|
11
11
|
/**
|
|
12
12
|
* Allows to extend retry logic and behavior
|
|
13
13
|
*/
|
|
14
|
-
onRetry = '
|
|
14
|
+
onRetry = '_A_Channel_onRetry',
|
|
15
15
|
/**
|
|
16
16
|
* Allows to extend circuit breaker logic and behavior
|
|
17
17
|
*/
|
|
18
|
-
onCircuitBreakerOpen = '
|
|
18
|
+
onCircuitBreakerOpen = '_A_Channel_onCircuitBreakerOpen',
|
|
19
19
|
/**
|
|
20
20
|
* Allows to extend cache logic and behavior
|
|
21
21
|
*/
|
|
22
|
-
onCache = '
|
|
22
|
+
onCache = '_A_Channel_onCache',
|
|
23
23
|
/**
|
|
24
24
|
* Allows to extend connection logic and behavior
|
|
25
25
|
*/
|
|
26
|
-
onConnect = '
|
|
26
|
+
onConnect = '_A_Channel_onConnect',
|
|
27
27
|
/**
|
|
28
28
|
* Allows to extend disconnection logic and behavior
|
|
29
29
|
*/
|
|
30
|
-
onDisconnect = '
|
|
30
|
+
onDisconnect = '_A_Channel_onDisconnect',
|
|
31
31
|
/**
|
|
32
32
|
* Allows to extend request preparation logic and behavior
|
|
33
33
|
*/
|
|
34
|
-
onBeforeRequest = '
|
|
34
|
+
onBeforeRequest = '_A_Channel_onBeforeRequest',
|
|
35
35
|
/**
|
|
36
36
|
* Allows to extend request sending logic and behavior
|
|
37
37
|
*/
|
|
38
|
-
onRequest = '
|
|
38
|
+
onRequest = '_A_Channel_onRequest',
|
|
39
39
|
/**
|
|
40
40
|
* Allows to extend request post-processing logic and behavior
|
|
41
41
|
*/
|
|
42
|
-
onAfterRequest = '
|
|
42
|
+
onAfterRequest = '_A_Channel_onAfterRequest',
|
|
43
43
|
/**
|
|
44
44
|
* Allows to extend error handling logic and behavior
|
|
45
45
|
*
|
|
46
46
|
* [!] The same approach uses for ALL errors within the channel
|
|
47
47
|
*/
|
|
48
|
-
onError = '
|
|
48
|
+
onError = '_A_Channel_onError',
|
|
49
49
|
/**
|
|
50
50
|
* Allows to extend send logic and behavior
|
|
51
51
|
*/
|
|
52
|
-
onSend = '
|
|
52
|
+
onSend = '_A_Channel_onSend',
|
|
53
53
|
/**
|
|
54
54
|
* Allows to extend consume logic and behavior
|
|
55
55
|
*/
|
|
56
|
-
onConsume = '
|
|
56
|
+
onConsume = '_A_Channel_onConsume',
|
|
57
57
|
}
|
|
58
58
|
|
|
59
59
|
|
|
@@ -10,27 +10,27 @@ export enum A_Command_Status {
|
|
|
10
10
|
* Initial state when command is instantiated but not yet ready for execution
|
|
11
11
|
*/
|
|
12
12
|
CREATED = 'CREATED',
|
|
13
|
-
|
|
13
|
+
|
|
14
14
|
/**
|
|
15
15
|
* Command has been initialized with execution scope and dependencies
|
|
16
16
|
*/
|
|
17
17
|
INITIALIZED = 'INITIALIZED',
|
|
18
|
-
|
|
18
|
+
|
|
19
19
|
/**
|
|
20
20
|
* Command has been compiled and is ready for execution
|
|
21
21
|
*/
|
|
22
22
|
COMPILED = 'COMPILED',
|
|
23
|
-
|
|
23
|
+
|
|
24
24
|
/**
|
|
25
25
|
* Command is currently being executed
|
|
26
26
|
*/
|
|
27
27
|
EXECUTING = 'EXECUTING',
|
|
28
|
-
|
|
28
|
+
|
|
29
29
|
/**
|
|
30
30
|
* Command has completed successfully
|
|
31
31
|
*/
|
|
32
32
|
COMPLETED = 'COMPLETED',
|
|
33
|
-
|
|
33
|
+
|
|
34
34
|
/**
|
|
35
35
|
* Command execution has failed with errors
|
|
36
36
|
*/
|
|
@@ -47,13 +47,13 @@ export enum A_Command_Status {
|
|
|
47
47
|
export enum A_CommandTransitions {
|
|
48
48
|
/** Transition from CREATED to INITIALIZED state */
|
|
49
49
|
CREATED_TO_INITIALIZED = 'created_initialized',
|
|
50
|
-
|
|
50
|
+
|
|
51
51
|
/** Transition from INITIALIZED to EXECUTING state */
|
|
52
52
|
INITIALIZED_TO_EXECUTING = 'initialized_executing',
|
|
53
|
-
|
|
53
|
+
|
|
54
54
|
/** Transition from EXECUTING to COMPLETED state (success path) */
|
|
55
55
|
EXECUTING_TO_COMPLETED = 'executing_completed',
|
|
56
|
-
|
|
56
|
+
|
|
57
57
|
/** Transition from EXECUTING to FAILED state (error path) */
|
|
58
58
|
EXECUTING_TO_FAILED = 'executing_failed',
|
|
59
59
|
}
|
|
@@ -68,42 +68,87 @@ export enum A_CommandTransitions {
|
|
|
68
68
|
* to inject custom logic into command execution.
|
|
69
69
|
*/
|
|
70
70
|
export enum A_CommandFeatures {
|
|
71
|
+
/**
|
|
72
|
+
* Triggered during command initialization phase
|
|
73
|
+
* Use to set up execution environment, validate parameters, or prepare resources
|
|
74
|
+
*/
|
|
75
|
+
onInit = '_A_Command_onInit',
|
|
76
|
+
|
|
77
|
+
/**
|
|
78
|
+
* Triggered before command execution starts
|
|
79
|
+
* Use for pre-execution validation, logging, or setup tasks
|
|
80
|
+
*/
|
|
81
|
+
onBeforeExecute = '_A_Command_onBeforeExecute',
|
|
82
|
+
|
|
83
|
+
/**
|
|
84
|
+
* Main command execution logic
|
|
85
|
+
* Core business logic should be implemented here
|
|
86
|
+
*/
|
|
87
|
+
onExecute = '_A_Command_onExecute',
|
|
88
|
+
|
|
89
|
+
/**
|
|
90
|
+
* Triggered after command execution completes (success or failure)
|
|
91
|
+
* Use for cleanup, logging, or post-processing tasks
|
|
92
|
+
*/
|
|
93
|
+
onAfterExecute = '_A_Command_onAfterExecute',
|
|
94
|
+
|
|
95
|
+
/**
|
|
96
|
+
* Triggered when command completes successfully
|
|
97
|
+
* Use for success-specific operations like notifications or result processing
|
|
98
|
+
*/
|
|
99
|
+
onComplete = '_A_Command_onComplete',
|
|
100
|
+
|
|
101
|
+
/**
|
|
102
|
+
* Triggered when command execution fails
|
|
103
|
+
* Use for error handling, cleanup, or failure notifications
|
|
104
|
+
*/
|
|
105
|
+
onFail = '_A_Command_onFail',
|
|
106
|
+
|
|
107
|
+
/**
|
|
108
|
+
* Triggered when an error occurs during execution
|
|
109
|
+
* Use for error logging, transformation, or recovery attempts
|
|
110
|
+
*/
|
|
111
|
+
onError = '_A_Command_onError',
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
|
|
115
|
+
export enum A_CommandEvent {
|
|
71
116
|
/**
|
|
72
117
|
* Triggered during command initialization phase
|
|
73
118
|
* Use to set up execution environment, validate parameters, or prepare resources
|
|
74
119
|
*/
|
|
75
120
|
onInit = 'onInit',
|
|
76
|
-
|
|
121
|
+
|
|
77
122
|
/**
|
|
78
123
|
* Triggered before command execution starts
|
|
79
124
|
* Use for pre-execution validation, logging, or setup tasks
|
|
80
125
|
*/
|
|
81
126
|
onBeforeExecute = 'onBeforeExecute',
|
|
82
|
-
|
|
127
|
+
|
|
83
128
|
/**
|
|
84
129
|
* Main command execution logic
|
|
85
130
|
* Core business logic should be implemented here
|
|
86
131
|
*/
|
|
87
132
|
onExecute = 'onExecute',
|
|
88
|
-
|
|
133
|
+
|
|
89
134
|
/**
|
|
90
135
|
* Triggered after command execution completes (success or failure)
|
|
91
136
|
* Use for cleanup, logging, or post-processing tasks
|
|
92
137
|
*/
|
|
93
138
|
onAfterExecute = 'onAfterExecute',
|
|
94
|
-
|
|
139
|
+
|
|
95
140
|
/**
|
|
96
141
|
* Triggered when command completes successfully
|
|
97
142
|
* Use for success-specific operations like notifications or result processing
|
|
98
143
|
*/
|
|
99
144
|
onComplete = 'onComplete',
|
|
100
|
-
|
|
145
|
+
|
|
101
146
|
/**
|
|
102
147
|
* Triggered when command execution fails
|
|
103
148
|
* Use for error handling, cleanup, or failure notifications
|
|
104
149
|
*/
|
|
105
150
|
onFail = 'onFail',
|
|
106
|
-
|
|
151
|
+
|
|
107
152
|
/**
|
|
108
153
|
* Triggered when an error occurs during execution
|
|
109
154
|
* Use for error logging, transformation, or recovery attempts
|
|
@@ -111,14 +156,11 @@ export enum A_CommandFeatures {
|
|
|
111
156
|
onError = 'onError',
|
|
112
157
|
}
|
|
113
158
|
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
159
|
/**
|
|
118
160
|
* Type alias for command lifecycle event names
|
|
119
161
|
* Represents all available events that can be listened to on a command instance
|
|
120
162
|
*/
|
|
121
|
-
export type
|
|
163
|
+
export type A_CommandEvents = keyof typeof A_CommandEvent;
|
|
122
164
|
|
|
123
165
|
|
|
124
166
|
|
|
@@ -1,21 +1,22 @@
|
|
|
1
1
|
import {
|
|
2
|
+
A_Command_ExecutionContext,
|
|
2
3
|
A_TYPES__Command_Init,
|
|
3
4
|
A_TYPES__Command_Listener,
|
|
4
5
|
A_TYPES__Command_Serialized
|
|
5
6
|
} from "./A-Command.types";
|
|
6
7
|
import {
|
|
7
8
|
A_CommandFeatures,
|
|
8
|
-
A_Command_Event,
|
|
9
9
|
A_Command_Status,
|
|
10
|
-
A_CommandTransitions
|
|
10
|
+
A_CommandTransitions,
|
|
11
|
+
A_CommandEvent
|
|
11
12
|
} from "./A-Command.constants";
|
|
12
|
-
import {
|
|
13
|
+
import { A_Context, A_Dependency, A_Entity, A_Error, A_Feature, A_Inject, A_Scope } from "@adaas/a-concept";
|
|
13
14
|
import { A_CommandError } from "./A-Command.error";
|
|
14
|
-
import { A_OperationContext } from "../A-Operation/A-Operation.context";
|
|
15
15
|
import { A_StateMachine } from "../A-StateMachine/A-StateMachine.component";
|
|
16
16
|
import { A_StateMachineFeatures } from "../A-StateMachine/A-StateMachine.constants";
|
|
17
17
|
import { A_Logger } from "../A-Logger/A-Logger.component";
|
|
18
18
|
import { A_StateMachineTransition } from "../A-StateMachine/A-StateMachineTransition.context";
|
|
19
|
+
import { A_ExecutionContext } from "../A-Execution/A-Execution.context";
|
|
19
20
|
|
|
20
21
|
/**
|
|
21
22
|
* A_Command - Advanced Command Pattern Implementation
|
|
@@ -79,7 +80,7 @@ import { A_StateMachineTransition } from "../A-StateMachine/A-StateMachineTransi
|
|
|
79
80
|
export class A_Command<
|
|
80
81
|
InvokeType extends A_TYPES__Command_Init = A_TYPES__Command_Init,
|
|
81
82
|
ResultType extends Record<string, any> = Record<string, any>,
|
|
82
|
-
LifecycleEvents extends string |
|
|
83
|
+
LifecycleEvents extends string | keyof typeof A_CommandEvent = keyof typeof A_CommandEvent,
|
|
83
84
|
> extends A_Entity<InvokeType, A_TYPES__Command_Serialized<InvokeType, ResultType>> {
|
|
84
85
|
|
|
85
86
|
// ====================================================================
|
|
@@ -118,7 +119,7 @@ export class A_Command<
|
|
|
118
119
|
|
|
119
120
|
/** Map of event listeners organized by event name */
|
|
120
121
|
protected _listeners: Map<
|
|
121
|
-
LifecycleEvents |
|
|
122
|
+
LifecycleEvents | keyof typeof A_CommandEvent,
|
|
122
123
|
Set<A_TYPES__Command_Listener<InvokeType, ResultType, LifecycleEvents>>
|
|
123
124
|
> = new Map();
|
|
124
125
|
|
|
@@ -173,6 +174,12 @@ export class A_Command<
|
|
|
173
174
|
get scope(): A_Scope {
|
|
174
175
|
return this._executionScope;
|
|
175
176
|
}
|
|
177
|
+
/**
|
|
178
|
+
* Execution context associated with the command
|
|
179
|
+
*/
|
|
180
|
+
get context(): A_ExecutionContext<A_Command_ExecutionContext<InvokeType, ResultType>> {
|
|
181
|
+
return this.scope.resolve(A_ExecutionContext<A_Command_ExecutionContext<InvokeType, ResultType>>)!;
|
|
182
|
+
}
|
|
176
183
|
|
|
177
184
|
/**
|
|
178
185
|
* Unique command type identifier
|
|
@@ -325,7 +332,7 @@ export class A_Command<
|
|
|
325
332
|
this._createdAt = new Date();
|
|
326
333
|
this._status = A_Command_Status.INITIALIZED;
|
|
327
334
|
|
|
328
|
-
this.emit(
|
|
335
|
+
this.emit(A_CommandEvent.onInit);
|
|
329
336
|
}
|
|
330
337
|
|
|
331
338
|
@A_Feature.Extend()
|
|
@@ -342,7 +349,7 @@ export class A_Command<
|
|
|
342
349
|
this._startTime = new Date();
|
|
343
350
|
this._status = A_Command_Status.EXECUTING;
|
|
344
351
|
|
|
345
|
-
this.emit(
|
|
352
|
+
this.emit(A_CommandEvent.onExecute);
|
|
346
353
|
}
|
|
347
354
|
|
|
348
355
|
@A_Feature.Extend()
|
|
@@ -358,7 +365,7 @@ export class A_Command<
|
|
|
358
365
|
this._endTime = new Date();
|
|
359
366
|
this._status = A_Command_Status.COMPLETED;
|
|
360
367
|
|
|
361
|
-
this.emit(
|
|
368
|
+
this.emit(A_CommandEvent.onComplete);
|
|
362
369
|
}
|
|
363
370
|
|
|
364
371
|
@A_Feature.Extend()
|
|
@@ -376,7 +383,7 @@ export class A_Command<
|
|
|
376
383
|
|
|
377
384
|
this._status = A_Command_Status.FAILED;
|
|
378
385
|
|
|
379
|
-
this.emit(
|
|
386
|
+
this.emit(A_CommandEvent.onFail);
|
|
380
387
|
}
|
|
381
388
|
|
|
382
389
|
|
|
@@ -438,7 +445,7 @@ export class A_Command<
|
|
|
438
445
|
protected async [A_CommandFeatures.onFail](
|
|
439
446
|
@A_Dependency.Required()
|
|
440
447
|
@A_Inject(A_StateMachine) stateMachine: A_StateMachine,
|
|
441
|
-
@A_Inject(
|
|
448
|
+
@A_Inject(A_ExecutionContext) operation: A_ExecutionContext<A_Command_ExecutionContext<InvokeType, ResultType>>,
|
|
442
449
|
...args: any[]
|
|
443
450
|
): Promise<void> {
|
|
444
451
|
await stateMachine.transition(A_Command_Status.EXECUTING, A_Command_Status.FAILED);
|
|
@@ -464,7 +471,7 @@ export class A_Command<
|
|
|
464
471
|
try {
|
|
465
472
|
this.checkScopeInheritance();
|
|
466
473
|
|
|
467
|
-
const context = new
|
|
474
|
+
const context = new A_ExecutionContext<A_Command_ExecutionContext<InvokeType, ResultType>>('execute-command');
|
|
468
475
|
|
|
469
476
|
this.scope.register(context);
|
|
470
477
|
|
|
@@ -493,7 +500,7 @@ export class A_Command<
|
|
|
493
500
|
|
|
494
501
|
|
|
495
502
|
|
|
496
|
-
this.on(
|
|
503
|
+
this.on(A_CommandEvent.onComplete, () => {
|
|
497
504
|
|
|
498
505
|
onBeforeExecuteFeature.interrupt();
|
|
499
506
|
onExecuteFeature.interrupt();
|
|
@@ -536,6 +543,16 @@ export class A_Command<
|
|
|
536
543
|
|
|
537
544
|
/**
|
|
538
545
|
* Marks the command as completed
|
|
546
|
+
*
|
|
547
|
+
*
|
|
548
|
+
* Calling This method will set the command status to COMPLETED, record the end time,
|
|
549
|
+
* store the result, emit the onComplete event, and destroy the execution scope.
|
|
550
|
+
*
|
|
551
|
+
* [!] After Calling this method, the command is considered fully processed And further processing will be INTERRUPTED.
|
|
552
|
+
* [!] If the command is already processed (COMPLETED or FAILED), this method does nothing.
|
|
553
|
+
* [!] This method can be called with optional result data to store with the command.
|
|
554
|
+
*
|
|
555
|
+
* @param result - Optional result data to store with the command
|
|
539
556
|
*/
|
|
540
557
|
async complete(result?: ResultType) {
|
|
541
558
|
if (this.isProcessed) return;
|
|
@@ -579,7 +596,7 @@ export class A_Command<
|
|
|
579
596
|
* @param event
|
|
580
597
|
* @param listener
|
|
581
598
|
*/
|
|
582
|
-
on(event: LifecycleEvents |
|
|
599
|
+
on(event: LifecycleEvents | A_CommandEvent, listener: A_TYPES__Command_Listener<InvokeType, ResultType, LifecycleEvents>) {
|
|
583
600
|
if (!this._listeners.has(event)) {
|
|
584
601
|
this._listeners.set(event, new Set());
|
|
585
602
|
}
|
|
@@ -591,7 +608,7 @@ export class A_Command<
|
|
|
591
608
|
* @param event
|
|
592
609
|
* @param listener
|
|
593
610
|
*/
|
|
594
|
-
off(event: LifecycleEvents |
|
|
611
|
+
off(event: LifecycleEvents | A_CommandEvent, listener: A_TYPES__Command_Listener<InvokeType, ResultType, LifecycleEvents>) {
|
|
595
612
|
this._listeners.get(event)?.delete(listener);
|
|
596
613
|
}
|
|
597
614
|
/**
|
|
@@ -599,7 +616,7 @@ export class A_Command<
|
|
|
599
616
|
*
|
|
600
617
|
* @param event
|
|
601
618
|
*/
|
|
602
|
-
emit(event: LifecycleEvents |
|
|
619
|
+
emit(event: LifecycleEvents | keyof typeof A_CommandEvent) {
|
|
603
620
|
this._listeners.get(event)?.forEach(async listener => {
|
|
604
621
|
listener(this);
|
|
605
622
|
});
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { A_Command } from "./A-Command.entity";
|
|
2
|
-
import {
|
|
2
|
+
import { A_CommandEvent, A_Command_Status, } from "./A-Command.constants";
|
|
3
3
|
import { A_TYPES__Entity_Serialized, A_TYPES__Error_Serialized } from "@adaas/a-concept";
|
|
4
4
|
|
|
5
5
|
// ============================================================================
|
|
@@ -58,55 +58,55 @@ export type A_TYPES__Command_Serialized<
|
|
|
58
58
|
* Unique identifier for the command type (derived from class name)
|
|
59
59
|
*/
|
|
60
60
|
code: string;
|
|
61
|
-
|
|
61
|
+
|
|
62
62
|
/**
|
|
63
63
|
* Current execution status of the command
|
|
64
64
|
*/
|
|
65
65
|
status: A_Command_Status;
|
|
66
|
-
|
|
66
|
+
|
|
67
67
|
/**
|
|
68
68
|
* Parameters used to initialize the command
|
|
69
69
|
*/
|
|
70
70
|
params: ParamsType;
|
|
71
|
-
|
|
71
|
+
|
|
72
72
|
// --------------------------------------------------
|
|
73
73
|
// Timing Information
|
|
74
74
|
// --------------------------------------------------
|
|
75
|
-
|
|
75
|
+
|
|
76
76
|
/**
|
|
77
77
|
* ISO timestamp when the command was created
|
|
78
78
|
*/
|
|
79
79
|
createdAt: string;
|
|
80
|
-
|
|
80
|
+
|
|
81
81
|
/**
|
|
82
82
|
* ISO timestamp when command execution started (if started)
|
|
83
83
|
*/
|
|
84
84
|
startedAt?: string;
|
|
85
|
-
|
|
85
|
+
|
|
86
86
|
/**
|
|
87
87
|
* ISO timestamp when command execution ended (if completed/failed)
|
|
88
88
|
*/
|
|
89
89
|
endedAt?: string;
|
|
90
|
-
|
|
90
|
+
|
|
91
91
|
/**
|
|
92
92
|
* Total execution duration in milliseconds (if completed/failed)
|
|
93
93
|
*/
|
|
94
94
|
duration?: number;
|
|
95
|
-
|
|
95
|
+
|
|
96
96
|
/**
|
|
97
97
|
* Time between creation and execution start in milliseconds
|
|
98
98
|
*/
|
|
99
99
|
idleTime?: number;
|
|
100
|
-
|
|
100
|
+
|
|
101
101
|
// --------------------------------------------------
|
|
102
102
|
// Execution Results
|
|
103
103
|
// --------------------------------------------------
|
|
104
|
-
|
|
104
|
+
|
|
105
105
|
/**
|
|
106
106
|
* Result data produced by successful command execution
|
|
107
107
|
*/
|
|
108
108
|
result?: ResultType;
|
|
109
|
-
|
|
109
|
+
|
|
110
110
|
/**
|
|
111
111
|
* Array of serialized errors that occurred during execution
|
|
112
112
|
*/
|
|
@@ -141,8 +141,16 @@ export type A_TYPES__Command_Serialized<
|
|
|
141
141
|
export type A_TYPES__Command_Listener<
|
|
142
142
|
InvokeType extends A_TYPES__Command_Init = A_TYPES__Command_Init,
|
|
143
143
|
ResultType extends Record<string, any> = Record<string, any>,
|
|
144
|
-
LifecycleEvents extends string =
|
|
144
|
+
LifecycleEvents extends string = keyof typeof A_CommandEvent
|
|
145
145
|
> = (command?: A_Command<InvokeType, ResultType, LifecycleEvents>) => void;
|
|
146
146
|
|
|
147
147
|
|
|
148
148
|
|
|
149
|
+
|
|
150
|
+
export type A_Command_ExecutionContext<
|
|
151
|
+
InvokeType extends A_TYPES__Command_Init = A_TYPES__Command_Init,
|
|
152
|
+
ResultType extends Record<string, any> = Record<string, any>,
|
|
153
|
+
> = {
|
|
154
|
+
result: ResultType,
|
|
155
|
+
params: InvokeType,
|
|
156
|
+
}
|
|
@@ -1,20 +1,21 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { A_CONSTANTS__DEFAULT_ENV_VARIABLES_ARRAY, A_FormatterHelper, A_TYPES__ConceptENVVariables } from "@adaas/a-concept";
|
|
2
2
|
import { A_TYPES__ConfigContainerConstructor } from "./A-Config.types";
|
|
3
|
+
import { A_ExecutionContext } from "../A-Execution/A-Execution.context";
|
|
3
4
|
import { A_CONSTANTS__CONFIG_ENV_VARIABLES_ARRAY } from "./A-Config.constants";
|
|
5
|
+
import { A_ConfigError } from "./A-Config.error";
|
|
4
6
|
|
|
5
7
|
|
|
6
8
|
export class A_Config<
|
|
7
9
|
T extends Array<string | A_TYPES__ConceptENVVariables[number]> = any[]
|
|
8
|
-
> extends
|
|
9
|
-
[key in T[number]]: any
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
CONFIG_PROPERTIES!: T;
|
|
10
|
+
> extends A_ExecutionContext<
|
|
11
|
+
{ [key in T[number]]: any; } & {
|
|
12
|
+
[key in typeof A_CONSTANTS__DEFAULT_ENV_VARIABLES_ARRAY[number]]: any
|
|
13
|
+
} & {
|
|
14
|
+
[key in typeof A_CONSTANTS__CONFIG_ENV_VARIABLES_ARRAY[number]]: any
|
|
15
|
+
}
|
|
16
|
+
> {
|
|
17
|
+
protected _strict: boolean;
|
|
18
|
+
protected _configProperties!: T;
|
|
18
19
|
|
|
19
20
|
protected DEFAULT_ALLOWED_TO_READ_PROPERTIES = [
|
|
20
21
|
...A_CONSTANTS__DEFAULT_ENV_VARIABLES_ARRAY,
|
|
@@ -25,60 +26,45 @@ export class A_Config<
|
|
|
25
26
|
constructor(
|
|
26
27
|
config: Partial<A_TYPES__ConfigContainerConstructor<T>>
|
|
27
28
|
) {
|
|
28
|
-
super(
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
this.CONFIG_PROPERTIES = this.config.variables ? this.config.variables : [] as any as T;
|
|
39
|
-
|
|
40
|
-
this.config.variables.forEach((variable) => {
|
|
41
|
-
this.VARIABLES.set(
|
|
42
|
-
A_FormatterHelper.toUpperSnakeCase(variable),
|
|
43
|
-
this.config.defaults[variable]
|
|
29
|
+
super('a-config');
|
|
30
|
+
|
|
31
|
+
this._strict = config.strict ?? false;
|
|
32
|
+
this._configProperties = config.variables ?? [] as any;
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
for (const key in config.defaults) {
|
|
36
|
+
this.set(
|
|
37
|
+
A_FormatterHelper.toUpperSnakeCase(key),
|
|
38
|
+
config.defaults[key as T[number]]
|
|
44
39
|
);
|
|
45
|
-
}
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
get strict(): boolean {
|
|
45
|
+
return this._strict;
|
|
46
46
|
}
|
|
47
47
|
|
|
48
48
|
|
|
49
49
|
/**
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
50
|
+
* This method is used to get the configuration property by name
|
|
51
|
+
*
|
|
52
|
+
* @param property
|
|
53
|
+
* @returns
|
|
54
|
+
*/
|
|
55
55
|
get<K extends T[number]>(
|
|
56
56
|
property: K | typeof this.DEFAULT_ALLOWED_TO_READ_PROPERTIES[number]
|
|
57
57
|
): { [key in T[number]]: any; }[K] | undefined {
|
|
58
|
-
if (this.
|
|
58
|
+
if (this._configProperties.includes(property as any)
|
|
59
59
|
|| this.DEFAULT_ALLOWED_TO_READ_PROPERTIES.includes(property as any)
|
|
60
|
-
|| !
|
|
60
|
+
|| !this._strict
|
|
61
61
|
)
|
|
62
|
-
return
|
|
63
|
-
|
|
64
|
-
throw new Error('Property not exists or not allowed to read') as never;
|
|
65
|
-
// return this.concept.Errors.throw(A_SDK_CONSTANTS__ERROR_CODES.CONFIGURATION_PROPERTY_NOT_EXISTS_OR_NOT_ALLOWED_TO_READ) as never;
|
|
62
|
+
return super.get(A_FormatterHelper.toUpperSnakeCase(property));
|
|
66
63
|
|
|
64
|
+
throw new A_ConfigError('Property not exists or not allowed to read');
|
|
67
65
|
}
|
|
68
66
|
|
|
69
67
|
|
|
70
|
-
// get<_OutType = any>(
|
|
71
|
-
// property: T[number] | typeof this.DEFAULT_ALLOWED_TO_READ_PROPERTIES[number] | string
|
|
72
|
-
// ): _OutType {
|
|
73
|
-
// if (this.CONFIG_PROPERTIES.includes(property as any)
|
|
74
|
-
// || this.DEFAULT_ALLOWED_TO_READ_PROPERTIES.includes(property as any)
|
|
75
|
-
// || !(this.config.strict)
|
|
76
|
-
// )
|
|
77
|
-
// return this.VARIABLES.get(A_FormatterHelper.toUpperSnakeCase(property)) as _OutType;
|
|
78
|
-
|
|
79
|
-
// throw new Error('Property not exists or not allowed to read') as never;
|
|
80
|
-
// // return this.concept.Errors.throw(A_SDK_CONSTANTS__ERROR_CODES.CONFIGURATION_PROPERTY_NOT_EXISTS_OR_NOT_ALLOWED_TO_READ) as never;
|
|
81
|
-
// }
|
|
82
68
|
/**
|
|
83
69
|
*
|
|
84
70
|
* This method is used to set the configuration property by name
|
|
@@ -118,14 +104,7 @@ export class A_Config<
|
|
|
118
104
|
}));
|
|
119
105
|
|
|
120
106
|
for (const { property, value } of array) {
|
|
121
|
-
|
|
122
|
-
let targetValue = value
|
|
123
|
-
? value
|
|
124
|
-
: this.config?.defaults
|
|
125
|
-
? this.config.defaults[property as T[number]]
|
|
126
|
-
: undefined;
|
|
127
|
-
|
|
128
|
-
this.VARIABLES.set(A_FormatterHelper.toUpperSnakeCase(property), targetValue);
|
|
107
|
+
super.set(A_FormatterHelper.toUpperSnakeCase(property), value);
|
|
129
108
|
}
|
|
130
109
|
}
|
|
131
110
|
}
|