@adaas/a-utils 0.1.22 → 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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@adaas/a-utils",
3
- "version": "0.1.22",
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",
@@ -7,53 +7,53 @@ export enum A_ChannelFeatures {
7
7
  /**
8
8
  * Allows to extend timeout logic and behavior
9
9
  */
10
- onTimeout = 'onTimeout',
10
+ onTimeout = '_A_Channel_onTimeout',
11
11
  /**
12
12
  * Allows to extend retry logic and behavior
13
13
  */
14
- onRetry = 'onRetry',
14
+ onRetry = '_A_Channel_onRetry',
15
15
  /**
16
16
  * Allows to extend circuit breaker logic and behavior
17
17
  */
18
- onCircuitBreakerOpen = 'onCircuitBreakerOpen',
18
+ onCircuitBreakerOpen = '_A_Channel_onCircuitBreakerOpen',
19
19
  /**
20
20
  * Allows to extend cache logic and behavior
21
21
  */
22
- onCache = 'onCache',
22
+ onCache = '_A_Channel_onCache',
23
23
  /**
24
24
  * Allows to extend connection logic and behavior
25
25
  */
26
- onConnect = 'onConnect',
26
+ onConnect = '_A_Channel_onConnect',
27
27
  /**
28
28
  * Allows to extend disconnection logic and behavior
29
29
  */
30
- onDisconnect = 'onDisconnect',
30
+ onDisconnect = '_A_Channel_onDisconnect',
31
31
  /**
32
32
  * Allows to extend request preparation logic and behavior
33
33
  */
34
- onBeforeRequest = 'onBeforeRequest',
34
+ onBeforeRequest = '_A_Channel_onBeforeRequest',
35
35
  /**
36
36
  * Allows to extend request sending logic and behavior
37
37
  */
38
- onRequest = 'onRequest',
38
+ onRequest = '_A_Channel_onRequest',
39
39
  /**
40
40
  * Allows to extend request post-processing logic and behavior
41
41
  */
42
- onAfterRequest = '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 = 'onError',
48
+ onError = '_A_Channel_onError',
49
49
  /**
50
50
  * Allows to extend send logic and behavior
51
51
  */
52
- onSend = 'onSend',
52
+ onSend = '_A_Channel_onSend',
53
53
  /**
54
54
  * Allows to extend consume logic and behavior
55
55
  */
56
- onConsume = '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 A_Command_Event = keyof typeof A_CommandFeatures;
163
+ export type A_CommandEvents = keyof typeof A_CommandEvent;
122
164
 
123
165
 
124
166
 
@@ -6,9 +6,9 @@ import {
6
6
  } from "./A-Command.types";
7
7
  import {
8
8
  A_CommandFeatures,
9
- A_Command_Event,
10
9
  A_Command_Status,
11
- A_CommandTransitions
10
+ A_CommandTransitions,
11
+ A_CommandEvent
12
12
  } from "./A-Command.constants";
13
13
  import { A_Context, A_Dependency, A_Entity, A_Error, A_Feature, A_Inject, A_Scope } from "@adaas/a-concept";
14
14
  import { A_CommandError } from "./A-Command.error";
@@ -80,7 +80,7 @@ import { A_ExecutionContext } from "../A-Execution/A-Execution.context";
80
80
  export class A_Command<
81
81
  InvokeType extends A_TYPES__Command_Init = A_TYPES__Command_Init,
82
82
  ResultType extends Record<string, any> = Record<string, any>,
83
- LifecycleEvents extends string | A_Command_Event = A_Command_Event,
83
+ LifecycleEvents extends string | keyof typeof A_CommandEvent = keyof typeof A_CommandEvent,
84
84
  > extends A_Entity<InvokeType, A_TYPES__Command_Serialized<InvokeType, ResultType>> {
85
85
 
86
86
  // ====================================================================
@@ -119,7 +119,7 @@ export class A_Command<
119
119
 
120
120
  /** Map of event listeners organized by event name */
121
121
  protected _listeners: Map<
122
- LifecycleEvents | A_Command_Event,
122
+ LifecycleEvents | keyof typeof A_CommandEvent,
123
123
  Set<A_TYPES__Command_Listener<InvokeType, ResultType, LifecycleEvents>>
124
124
  > = new Map();
125
125
 
@@ -332,7 +332,7 @@ export class A_Command<
332
332
  this._createdAt = new Date();
333
333
  this._status = A_Command_Status.INITIALIZED;
334
334
 
335
- this.emit(A_CommandFeatures.onInit);
335
+ this.emit(A_CommandEvent.onInit);
336
336
  }
337
337
 
338
338
  @A_Feature.Extend()
@@ -349,7 +349,7 @@ export class A_Command<
349
349
  this._startTime = new Date();
350
350
  this._status = A_Command_Status.EXECUTING;
351
351
 
352
- this.emit(A_CommandFeatures.onExecute);
352
+ this.emit(A_CommandEvent.onExecute);
353
353
  }
354
354
 
355
355
  @A_Feature.Extend()
@@ -365,7 +365,7 @@ export class A_Command<
365
365
  this._endTime = new Date();
366
366
  this._status = A_Command_Status.COMPLETED;
367
367
 
368
- this.emit(A_CommandFeatures.onComplete);
368
+ this.emit(A_CommandEvent.onComplete);
369
369
  }
370
370
 
371
371
  @A_Feature.Extend()
@@ -383,7 +383,7 @@ export class A_Command<
383
383
 
384
384
  this._status = A_Command_Status.FAILED;
385
385
 
386
- this.emit(A_CommandFeatures.onFail);
386
+ this.emit(A_CommandEvent.onFail);
387
387
  }
388
388
 
389
389
 
@@ -500,7 +500,7 @@ export class A_Command<
500
500
 
501
501
 
502
502
 
503
- this.on(A_CommandFeatures.onComplete, () => {
503
+ this.on(A_CommandEvent.onComplete, () => {
504
504
 
505
505
  onBeforeExecuteFeature.interrupt();
506
506
  onExecuteFeature.interrupt();
@@ -596,7 +596,7 @@ export class A_Command<
596
596
  * @param event
597
597
  * @param listener
598
598
  */
599
- on(event: LifecycleEvents | A_Command_Event, listener: A_TYPES__Command_Listener<InvokeType, ResultType, LifecycleEvents>) {
599
+ on(event: LifecycleEvents | A_CommandEvent, listener: A_TYPES__Command_Listener<InvokeType, ResultType, LifecycleEvents>) {
600
600
  if (!this._listeners.has(event)) {
601
601
  this._listeners.set(event, new Set());
602
602
  }
@@ -608,7 +608,7 @@ export class A_Command<
608
608
  * @param event
609
609
  * @param listener
610
610
  */
611
- off(event: LifecycleEvents | A_Command_Event, listener: A_TYPES__Command_Listener<InvokeType, ResultType, LifecycleEvents>) {
611
+ off(event: LifecycleEvents | A_CommandEvent, listener: A_TYPES__Command_Listener<InvokeType, ResultType, LifecycleEvents>) {
612
612
  this._listeners.get(event)?.delete(listener);
613
613
  }
614
614
  /**
@@ -616,7 +616,7 @@ export class A_Command<
616
616
  *
617
617
  * @param event
618
618
  */
619
- emit(event: LifecycleEvents | A_Command_Event) {
619
+ emit(event: LifecycleEvents | keyof typeof A_CommandEvent) {
620
620
  this._listeners.get(event)?.forEach(async listener => {
621
621
  listener(this);
622
622
  });
@@ -1,5 +1,5 @@
1
1
  import { A_Command } from "./A-Command.entity";
2
- import { A_Command_Event, A_Command_Status, } from "./A-Command.constants";
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
  // ============================================================================
@@ -141,7 +141,7 @@ 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 = A_Command_Event
144
+ LifecycleEvents extends string = keyof typeof A_CommandEvent
145
145
  > = (command?: A_Command<InvokeType, ResultType, LifecycleEvents>) => void;
146
146
 
147
147
 
@@ -4,46 +4,46 @@ export enum A_MemoryFeatures {
4
4
  /**
5
5
  * Allows to extend initialization logic and behavior
6
6
  */
7
- onInit = 'onInit',
7
+ onInit = '_A_Memory_onInit',
8
8
 
9
9
  /**
10
10
  * Allows to extend destruction logic and behavior
11
11
  */
12
- onDestroy = 'onDestroy',
12
+ onDestroy = '_A_Memory_onDestroy',
13
13
 
14
14
  /**
15
15
  * Allows to extend expiration logic and behavior
16
16
  */
17
- onExpire = 'onExpire',
17
+ onExpire = '_A_Memory_onExpire',
18
18
 
19
19
  /**
20
20
  * Allows to extend error handling logic and behavior
21
21
  */
22
- onError = 'onError',
22
+ onError = '_A_Memory_onError',
23
23
 
24
24
  /**
25
25
  * Allows to extend serialization logic and behavior
26
26
  */
27
- onSerialize = 'onSerialize',
27
+ onSerialize = '_A_Memory_onSerialize',
28
28
 
29
29
  /**
30
30
  * Allows to extend set operation logic and behavior
31
31
  */
32
- onSet = 'onSet',
32
+ onSet = '_A_Memory_onSet',
33
33
  /**
34
34
  * Allows to extend get operation logic and behavior
35
35
  */
36
- onGet = 'onGet',
36
+ onGet = '_A_Memory_onGet',
37
37
  /**
38
38
  * Allows to extend drop operation logic and behavior
39
39
  */
40
- onDrop = 'onDrop',
40
+ onDrop = '_A_Memory_onDrop',
41
41
  /**
42
42
  * Allows to extend clear operation logic and behavior
43
43
  */
44
- onClear = 'onClear',
44
+ onClear = '_A_Memory_onClear',
45
45
  /**
46
46
  * Allows to extend has operation logic and behavior
47
47
  */
48
- onHas = 'onHas',
48
+ onHas = '_A_Memory_onHas',
49
49
  }
@@ -2,17 +2,17 @@ export enum A_StateMachineFeatures {
2
2
  /**
3
3
  * Allows to extend error handling logic and behavior
4
4
  */
5
- onError = 'onError',
5
+ onError = '_A_StateMachine_onError',
6
6
  /**
7
7
  * Allows to extend initialization logic and behavior
8
8
  */
9
- onInitialize = 'onInitialize',
9
+ onInitialize = '_A_StateMachine_onInitialize',
10
10
  /**
11
11
  * Allows to extend transition validation logic and behavior
12
12
  */
13
- onBeforeTransition = 'onBeforeTransition',
13
+ onBeforeTransition = '_A_StateMachine_onBeforeTransition',
14
14
  /**
15
15
  * Allows to extend post-transition logic and behavior
16
16
  */
17
- onAfterTransition = 'onAfterTransition',
17
+ onAfterTransition = '_A_StateMachine_onAfterTransition',
18
18
  }
@@ -1,6 +1,6 @@
1
1
  import { A_Command } from '@adaas/a-utils/lib/A-Command/A-Command.entity';
2
2
  import { A_CommandError } from '@adaas/a-utils/lib/A-Command/A-Command.error';
3
- import { A_Command_Status, A_CommandFeatures } from '@adaas/a-utils/lib/A-Command/A-Command.constants';
3
+ import { A_Command_Status, A_CommandEvent, A_CommandFeatures } from '@adaas/a-utils/lib/A-Command/A-Command.constants';
4
4
  import { A_TYPES__Command_Serialized } from '@adaas/a-utils/lib/A-Command/A-Command.types';
5
5
  import { A_StateMachine } from '@adaas/a-utils/lib/A-StateMachine/A-StateMachine.component';
6
6
  import { A_Memory } from '@adaas/a-utils/lib/A-Memory/A-Memory.component';
@@ -73,8 +73,8 @@ describe('A-Command tests', () => {
73
73
  const command = new TestCommand({ userId: '123', action: 'create' });
74
74
  const listener = jest.fn();
75
75
 
76
- command.on(A_CommandFeatures.onComplete, listener);
77
- command.emit(A_CommandFeatures.onComplete);
76
+ command.on('onComplete', listener);
77
+ command.emit(A_CommandEvent.onComplete);
78
78
 
79
79
  expect(listener).toHaveBeenCalledWith(command);
80
80
  });
@@ -83,9 +83,9 @@ describe('A-Command tests', () => {
83
83
  const command = new TestCommand({ userId: '123', action: 'create' });
84
84
  const listener = jest.fn();
85
85
 
86
- command.on(A_CommandFeatures.onComplete, listener);
87
- command.off(A_CommandFeatures.onComplete, listener);
88
- command.emit(A_CommandFeatures.onComplete);
86
+ command.on(A_CommandEvent.onComplete, listener);
87
+ command.off(A_CommandEvent.onComplete, listener);
88
+ command.emit(A_CommandEvent.onComplete);
89
89
 
90
90
  expect(listener).not.toHaveBeenCalled();
91
91
  });