@adaas/a-utils 0.1.17 → 0.1.19
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.d.mts +964 -354
- package/dist/index.d.ts +964 -354
- package/dist/index.js +1426 -714
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +1426 -714
- package/dist/index.mjs.map +1 -1
- package/examples/A-Channel-examples.ts +13 -11
- package/examples/A-Command-examples-2.ts +429 -0
- package/examples/A-Command-examples.ts +487 -202
- package/examples/A-StateMachine-examples.ts +609 -0
- package/package.json +3 -2
- package/src/index.ts +1 -2
- package/src/lib/A-Channel/A-Channel.component.ts +14 -74
- package/src/lib/A-Channel/A-Channel.error.ts +5 -5
- package/src/lib/A-Channel/A-Channel.types.ts +2 -10
- package/src/lib/A-Channel/A-ChannelRequest.context.ts +25 -74
- package/src/lib/A-Command/A-Command.constants.ts +78 -23
- package/src/lib/A-Command/A-Command.entity.ts +447 -119
- package/src/lib/A-Command/A-Command.error.ts +11 -0
- package/src/lib/A-Command/A-Command.types.ts +96 -20
- package/src/lib/A-Command/A-CommandExecution.context.ts +0 -0
- package/src/lib/A-Command/README.md +164 -68
- package/src/lib/A-Config/A-Config.container.ts +2 -2
- package/src/lib/A-Config/A-Config.context.ts +19 -5
- package/src/lib/A-Config/components/ConfigReader.component.ts +1 -1
- package/src/lib/A-Logger/A-Logger.component.ts +211 -35
- package/src/lib/A-Logger/A-Logger.constants.ts +50 -10
- package/src/lib/A-Logger/A-Logger.env.ts +17 -1
- package/src/lib/A-Memory/A-Memory.component.ts +440 -0
- package/src/lib/A-Memory/A-Memory.constants.ts +49 -0
- package/src/lib/A-Memory/A-Memory.context.ts +14 -118
- package/src/lib/A-Memory/A-Memory.error.ts +21 -0
- package/src/lib/A-Memory/A-Memory.types.ts +21 -0
- package/src/lib/A-Operation/A-Operation.context.ts +58 -0
- package/src/lib/A-Operation/A-Operation.types.ts +47 -0
- package/src/lib/A-StateMachine/A-StateMachine.component.ts +258 -0
- package/src/lib/A-StateMachine/A-StateMachine.constants.ts +18 -0
- package/src/lib/A-StateMachine/A-StateMachine.error.ts +10 -0
- package/src/lib/A-StateMachine/A-StateMachine.types.ts +20 -0
- package/src/lib/A-StateMachine/A-StateMachineTransition.context.ts +41 -0
- package/src/lib/A-StateMachine/README.md +391 -0
- package/tests/A-Channel.test.ts +17 -14
- package/tests/A-Command.test.ts +548 -460
- package/tests/A-Logger.test.ts +8 -4
- package/tests/A-Memory.test.ts +151 -115
- package/tests/A-Schedule.test.ts +2 -2
- package/tests/A-StateMachine.test.ts +760 -0
|
@@ -5,4 +5,15 @@ export class A_CommandError extends A_Error {
|
|
|
5
5
|
|
|
6
6
|
|
|
7
7
|
static readonly CommandScopeBindingError = 'A-Command Scope Binding Error';
|
|
8
|
+
|
|
9
|
+
static readonly ExecutionError = 'A-Command Execution Error';
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
static readonly ResultProcessingError = 'A-Command Result Processing Error';
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Error indicating that the command was interrupted during execution
|
|
17
|
+
*/
|
|
18
|
+
static readonly CommandInterruptedError = 'A-Command Interrupted Error';
|
|
8
19
|
}
|
|
@@ -1,72 +1,148 @@
|
|
|
1
1
|
import { A_Command } from "./A-Command.entity";
|
|
2
|
-
import {
|
|
2
|
+
import { A_Command_Event, 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
|
-
|
|
6
|
-
|
|
7
5
|
// ============================================================================
|
|
8
6
|
// --------------------------- Primary Types ----------------------------------
|
|
9
7
|
// ============================================================================
|
|
8
|
+
|
|
10
9
|
/**
|
|
11
|
-
* Command
|
|
12
|
-
*
|
|
10
|
+
* Command Constructor Type
|
|
11
|
+
*
|
|
12
|
+
* Generic constructor type for creating command instances.
|
|
13
|
+
* Used for dependency injection and factory patterns.
|
|
14
|
+
*
|
|
15
|
+
* @template T - The command class type extending A_Command
|
|
13
16
|
*/
|
|
14
17
|
export type A_TYPES__Command_Constructor<T = A_Command> = new (...args: any[]) => T;
|
|
18
|
+
|
|
15
19
|
/**
|
|
16
|
-
* Command
|
|
20
|
+
* Command Initialization Parameters
|
|
21
|
+
*
|
|
22
|
+
* Base type for command parameters. Commands should extend this with
|
|
23
|
+
* specific parameter types for their use case.
|
|
24
|
+
*
|
|
25
|
+
* @example
|
|
26
|
+
* ```typescript
|
|
27
|
+
* interface UserCommandParams extends A_TYPES__Command_Init {
|
|
28
|
+
* userId: string;
|
|
29
|
+
* action: 'create' | 'update' | 'delete';
|
|
30
|
+
* }
|
|
31
|
+
* ```
|
|
17
32
|
*/
|
|
18
33
|
export type A_TYPES__Command_Init = Record<string, any>;
|
|
34
|
+
|
|
19
35
|
/**
|
|
20
|
-
* Command
|
|
36
|
+
* Command Serialized Format
|
|
37
|
+
*
|
|
38
|
+
* Complete serialized representation of a command including all state,
|
|
39
|
+
* timing information, results, and errors. Used for persistence,
|
|
40
|
+
* transmission between services, and state restoration.
|
|
41
|
+
*
|
|
42
|
+
* @template ParamsType - Type of command parameters
|
|
43
|
+
* @template ResultType - Type of command execution result
|
|
44
|
+
*
|
|
45
|
+
* @example
|
|
46
|
+
* ```typescript
|
|
47
|
+
* const serialized: A_TYPES__Command_Serialized<
|
|
48
|
+
* { userId: string },
|
|
49
|
+
* { success: boolean }
|
|
50
|
+
* > = command.toJSON();
|
|
51
|
+
* ```
|
|
21
52
|
*/
|
|
22
53
|
export type A_TYPES__Command_Serialized<
|
|
23
54
|
ParamsType extends Record<string, any> = Record<string, any>,
|
|
24
55
|
ResultType extends Record<string, any> = Record<string, any>
|
|
25
56
|
> = {
|
|
26
57
|
/**
|
|
27
|
-
* Unique
|
|
58
|
+
* Unique identifier for the command type (derived from class name)
|
|
28
59
|
*/
|
|
29
60
|
code: string;
|
|
61
|
+
|
|
30
62
|
/**
|
|
31
|
-
* Current status of the command
|
|
63
|
+
* Current execution status of the command
|
|
32
64
|
*/
|
|
33
|
-
status:
|
|
65
|
+
status: A_Command_Status;
|
|
66
|
+
|
|
34
67
|
/**
|
|
35
|
-
* Parameters used to
|
|
68
|
+
* Parameters used to initialize the command
|
|
36
69
|
*/
|
|
37
70
|
params: ParamsType;
|
|
71
|
+
|
|
72
|
+
// --------------------------------------------------
|
|
73
|
+
// Timing Information
|
|
38
74
|
// --------------------------------------------------
|
|
75
|
+
|
|
76
|
+
/**
|
|
77
|
+
* ISO timestamp when the command was created
|
|
78
|
+
*/
|
|
79
|
+
createdAt: string;
|
|
80
|
+
|
|
39
81
|
/**
|
|
40
|
-
*
|
|
82
|
+
* ISO timestamp when command execution started (if started)
|
|
41
83
|
*/
|
|
42
84
|
startedAt?: string;
|
|
85
|
+
|
|
43
86
|
/**
|
|
44
|
-
*
|
|
87
|
+
* ISO timestamp when command execution ended (if completed/failed)
|
|
45
88
|
*/
|
|
46
89
|
endedAt?: string;
|
|
90
|
+
|
|
47
91
|
/**
|
|
48
|
-
*
|
|
92
|
+
* Total execution duration in milliseconds (if completed/failed)
|
|
49
93
|
*/
|
|
50
94
|
duration?: number;
|
|
95
|
+
|
|
96
|
+
/**
|
|
97
|
+
* Time between creation and execution start in milliseconds
|
|
98
|
+
*/
|
|
99
|
+
idleTime?: number;
|
|
100
|
+
|
|
51
101
|
// --------------------------------------------------
|
|
102
|
+
// Execution Results
|
|
103
|
+
// --------------------------------------------------
|
|
104
|
+
|
|
52
105
|
/**
|
|
53
|
-
* Result
|
|
106
|
+
* Result data produced by successful command execution
|
|
54
107
|
*/
|
|
55
108
|
result?: ResultType;
|
|
109
|
+
|
|
56
110
|
/**
|
|
57
|
-
*
|
|
111
|
+
* Array of serialized errors that occurred during execution
|
|
58
112
|
*/
|
|
59
|
-
|
|
113
|
+
error?: A_TYPES__Error_Serialized;
|
|
60
114
|
} & A_TYPES__Entity_Serialized
|
|
61
115
|
|
|
62
116
|
// ============================================================================
|
|
63
|
-
// ----------------------------
|
|
117
|
+
// ---------------------------- Event Types -----------------------------------
|
|
64
118
|
// ============================================================================
|
|
119
|
+
|
|
65
120
|
/**
|
|
66
|
-
* Command
|
|
121
|
+
* Command Event Listener Function
|
|
122
|
+
*
|
|
123
|
+
* Type definition for event listener functions that can be registered
|
|
124
|
+
* to respond to command lifecycle events.
|
|
125
|
+
*
|
|
126
|
+
* @template InvokeType - Type of command initialization parameters
|
|
127
|
+
* @template ResultType - Type of command execution result
|
|
128
|
+
* @template LifecycleEvents - Union type of custom lifecycle event names
|
|
129
|
+
*
|
|
130
|
+
* @param command - The command instance that triggered the event
|
|
131
|
+
*
|
|
132
|
+
* @example
|
|
133
|
+
* ```typescript
|
|
134
|
+
* const listener: A_TYPES__Command_Listener<UserParams, UserResult> = (command) => {
|
|
135
|
+
* console.log(`Command ${command?.code} triggered event`);
|
|
136
|
+
* };
|
|
137
|
+
*
|
|
138
|
+
* command.on('onExecute', listener);
|
|
139
|
+
* ```
|
|
67
140
|
*/
|
|
68
141
|
export type A_TYPES__Command_Listener<
|
|
69
142
|
InvokeType extends A_TYPES__Command_Init = A_TYPES__Command_Init,
|
|
70
143
|
ResultType extends Record<string, any> = Record<string, any>,
|
|
71
|
-
LifecycleEvents extends string =
|
|
144
|
+
LifecycleEvents extends string = A_Command_Event
|
|
72
145
|
> = (command?: A_Command<InvokeType, ResultType, LifecycleEvents>) => void;
|
|
146
|
+
|
|
147
|
+
|
|
148
|
+
|
|
File without changes
|
|
@@ -43,22 +43,24 @@ npm install @adaas/a-utils
|
|
|
43
43
|
|
|
44
44
|
```typescript
|
|
45
45
|
import { A_Command } from '@adaas/a-utils/lib/A-Command/A-Command.entity';
|
|
46
|
-
import {
|
|
46
|
+
import { A_Scope } from '@adaas/a-concept';
|
|
47
47
|
|
|
48
|
-
// Create a basic command
|
|
48
|
+
// Create a basic command with parameters
|
|
49
49
|
const command = new A_Command({
|
|
50
50
|
action: 'greet',
|
|
51
51
|
name: 'World'
|
|
52
52
|
});
|
|
53
53
|
|
|
54
|
-
// Register command in
|
|
55
|
-
|
|
54
|
+
// Register command in scope for dependency injection
|
|
55
|
+
const scope = A_Scope.context();
|
|
56
|
+
scope.register(command);
|
|
56
57
|
|
|
57
|
-
// Execute the command
|
|
58
|
+
// Execute the command (automatically handles complete lifecycle)
|
|
58
59
|
await command.execute();
|
|
59
60
|
|
|
60
|
-
console.log(`Command status: ${command.status}`);
|
|
61
|
+
console.log(`Command status: ${command.status}`); // COMPLETED
|
|
61
62
|
console.log(`Execution duration: ${command.duration}ms`);
|
|
63
|
+
console.log(`Command result:`, command.result);
|
|
62
64
|
```
|
|
63
65
|
|
|
64
66
|
### Typed Command with Custom Parameters and Result
|
|
@@ -99,7 +101,7 @@ console.log(`Created user: ${result?.userId}`);
|
|
|
99
101
|
```typescript
|
|
100
102
|
import { A_Component, A_Feature, A_Inject } from '@adaas/a-concept';
|
|
101
103
|
import { A_Memory } from '@adaas/a-utils/lib/A-Memory/A-Memory.context';
|
|
102
|
-
import {
|
|
104
|
+
import { A_CommandFeatures } from '@adaas/a-utils/lib/A-Command/A-Command.constants';
|
|
103
105
|
|
|
104
106
|
// Define command types
|
|
105
107
|
interface OrderProcessParams {
|
|
@@ -115,37 +117,75 @@ interface OrderProcessResult {
|
|
|
115
117
|
paymentProcessed: boolean;
|
|
116
118
|
}
|
|
117
119
|
|
|
118
|
-
class ProcessOrderCommand extends A_Command<OrderProcessParams, OrderProcessResult> {
|
|
120
|
+
class ProcessOrderCommand extends A_Command<OrderProcessParams, OrderProcessResult> {
|
|
121
|
+
|
|
122
|
+
/**
|
|
123
|
+
* Custom execution logic with feature-based processing
|
|
124
|
+
* This method is automatically called during command execution
|
|
125
|
+
*/
|
|
126
|
+
@A_Feature.Define({
|
|
127
|
+
template: [
|
|
128
|
+
{
|
|
129
|
+
name: 'orderNumber',
|
|
130
|
+
component: 'OrderProcessor',
|
|
131
|
+
handler: 'generateOrderNumber'
|
|
132
|
+
},
|
|
133
|
+
{
|
|
134
|
+
name: 'totalAmount',
|
|
135
|
+
component: 'OrderProcessor',
|
|
136
|
+
handler: 'calculateTotal'
|
|
137
|
+
},
|
|
138
|
+
{
|
|
139
|
+
name: 'paymentProcessed',
|
|
140
|
+
component: 'PaymentProcessor',
|
|
141
|
+
handler: 'processPayment'
|
|
142
|
+
}
|
|
143
|
+
]
|
|
144
|
+
})
|
|
145
|
+
protected async [A_CommandFeatures.onExecute](): Promise<void> {
|
|
146
|
+
console.log(`Processing order ${this.params.orderId} for customer ${this.params.customerId}`);
|
|
147
|
+
}
|
|
148
|
+
}
|
|
119
149
|
|
|
120
|
-
// Create
|
|
150
|
+
// Create components with specialized handlers
|
|
121
151
|
class OrderProcessor extends A_Component {
|
|
122
152
|
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
const { orderId, items, customerId } = command.params;
|
|
130
|
-
|
|
131
|
-
// Process the order
|
|
132
|
-
const orderNumber = `ORD-${Date.now()}`;
|
|
133
|
-
const totalAmount = items.reduce((sum, item) => sum + (item.quantity * 10), 0);
|
|
134
|
-
const estimatedDelivery = new Date(Date.now() + 7 * 24 * 60 * 60 * 1000).toISOString();
|
|
135
|
-
|
|
136
|
-
// Store results in memory
|
|
137
|
-
await memory.set('orderNumber', orderNumber);
|
|
138
|
-
await memory.set('totalAmount', totalAmount);
|
|
139
|
-
await memory.set('estimatedDelivery', estimatedDelivery);
|
|
140
|
-
await memory.set('paymentProcessed', true);
|
|
141
|
-
|
|
142
|
-
console.log(`Processed order ${orderNumber} for customer ${customerId}`);
|
|
153
|
+
generateOrderNumber() {
|
|
154
|
+
return `ORD-${Date.now()}`;
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
calculateTotal(@A_Inject(ProcessOrderCommand) command: ProcessOrderCommand) {
|
|
158
|
+
return command.params.items.reduce((sum, item) => sum + (item.quantity * 10), 0);
|
|
143
159
|
}
|
|
144
160
|
}
|
|
145
161
|
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
162
|
+
class PaymentProcessor extends A_Component {
|
|
163
|
+
|
|
164
|
+
async processPayment(@A_Inject(ProcessOrderCommand) command: ProcessOrderCommand) {
|
|
165
|
+
console.log(`Processing payment for order ${command.params.orderId}`);
|
|
166
|
+
// Simulate payment processing
|
|
167
|
+
await new Promise(resolve => setTimeout(resolve, 100));
|
|
168
|
+
return true;
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
// Usage with A_Concept architecture
|
|
173
|
+
const concept = new A_Concept({
|
|
174
|
+
containers: [
|
|
175
|
+
new A_Container({
|
|
176
|
+
name: 'Order Processing',
|
|
177
|
+
components: [
|
|
178
|
+
ProcessOrderCommand,
|
|
179
|
+
OrderProcessor,
|
|
180
|
+
PaymentProcessor,
|
|
181
|
+
A_Memory,
|
|
182
|
+
A_Logger
|
|
183
|
+
]
|
|
184
|
+
})
|
|
185
|
+
]
|
|
186
|
+
});
|
|
187
|
+
|
|
188
|
+
await concept.load();
|
|
149
189
|
|
|
150
190
|
const command = new ProcessOrderCommand({
|
|
151
191
|
orderId: 'order-123',
|
|
@@ -156,7 +196,7 @@ const command = new ProcessOrderCommand({
|
|
|
156
196
|
]
|
|
157
197
|
});
|
|
158
198
|
|
|
159
|
-
|
|
199
|
+
concept.scope.register(command);
|
|
160
200
|
await command.execute();
|
|
161
201
|
|
|
162
202
|
console.log('Order processed:', command.result);
|
|
@@ -193,11 +233,24 @@ console.log('Duration:', command.duration, 'ms');
|
|
|
193
233
|
|
|
194
234
|
### Lifecycle Phases
|
|
195
235
|
|
|
236
|
+
A-Command follows a structured lifecycle with automatic state transitions:
|
|
237
|
+
|
|
196
238
|
1. **CREATED** - Initial state when command is instantiated
|
|
197
|
-
2. **
|
|
198
|
-
3. **
|
|
199
|
-
4. **
|
|
200
|
-
5. **
|
|
239
|
+
2. **INITIALIZED** - Dependencies resolved and scope configured
|
|
240
|
+
3. **COMPILED** - Execution environment prepared and validated
|
|
241
|
+
4. **EXECUTING** - Command is currently running
|
|
242
|
+
5. **COMPLETED** - Execution finished successfully
|
|
243
|
+
6. **FAILED** - Execution encountered errors and terminated
|
|
244
|
+
|
|
245
|
+
### Status Transitions
|
|
246
|
+
|
|
247
|
+
The command automatically transitions through states during execution:
|
|
248
|
+
|
|
249
|
+
```
|
|
250
|
+
CREATED → INITIALIZED → COMPILED → EXECUTING → COMPLETED/FAILED
|
|
251
|
+
```
|
|
252
|
+
|
|
253
|
+
Each transition triggers corresponding lifecycle events that you can subscribe to for monitoring and custom logic.
|
|
201
254
|
6. **COMPLETED** - Successfully finished execution
|
|
202
255
|
7. **FAILED** - Execution failed with errors
|
|
203
256
|
|
|
@@ -443,43 +496,86 @@ enum A_CONSTANTS_A_Command_Features {
|
|
|
443
496
|
|
|
444
497
|
## Examples
|
|
445
498
|
|
|
446
|
-
|
|
499
|
+
The A-Command library comes with comprehensive examples demonstrating various usage patterns and architectures. These examples are fully documented with detailed explanations of concepts and implementation patterns.
|
|
500
|
+
|
|
501
|
+
### 📁 Example Files
|
|
502
|
+
|
|
503
|
+
#### Multi-Service Distributed Processing
|
|
504
|
+
**File:** `examples/A-Command-examples.ts`
|
|
505
|
+
|
|
506
|
+
This example demonstrates advanced multi-service command processing architecture:
|
|
507
|
+
|
|
508
|
+
- **Multi-Service Architecture**: Commands distributed across Service A and Service B
|
|
509
|
+
- **Inter-Service Communication**: Commands routed between services using channels
|
|
510
|
+
- **Shared Memory**: State sharing between services for coordinated processing
|
|
511
|
+
- **Lifecycle Management**: Complete command lifecycle across distributed services
|
|
512
|
+
- **Component-Based Processing**: Specialized processors for different execution phases
|
|
447
513
|
|
|
448
514
|
```typescript
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
515
|
+
// Example: Command processing across multiple services
|
|
516
|
+
const command = new TestCommand({ userId: '123' });
|
|
517
|
+
const channel = scope.resolve(SimpleChannel);
|
|
518
|
+
const result = await channel.execute(command); // Distributed execution
|
|
519
|
+
```
|
|
520
|
+
|
|
521
|
+
**Key Concepts Covered:**
|
|
522
|
+
- Service container registration and discovery
|
|
523
|
+
- Command routing and channel implementation
|
|
524
|
+
- Cross-service state management with shared memory
|
|
525
|
+
- Pre/main/post execution phases across services
|
|
526
|
+
- Result aggregation from distributed processing
|
|
454
527
|
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
528
|
+
#### Feature-Driven Template Processing
|
|
529
|
+
**File:** `examples/A-Command-examples-2.ts`
|
|
530
|
+
|
|
531
|
+
This example showcases feature-driven command architecture using templates:
|
|
532
|
+
|
|
533
|
+
- **Template-Based Execution**: Result properties mapped to component handlers
|
|
534
|
+
- **Automated Processing**: Framework automatically calls mapped component methods
|
|
535
|
+
- **Modular Components**: Specialized components for different result aspects
|
|
536
|
+
- **Result Compilation**: Handler outputs automatically compiled into result object
|
|
537
|
+
- **Container-Based Execution**: Integrated execution environment with dependency injection
|
|
538
|
+
|
|
539
|
+
```typescript
|
|
540
|
+
// Example: Feature template mapping result properties to handlers
|
|
541
|
+
@A_Feature.Define({
|
|
542
|
+
template: [
|
|
543
|
+
{ name: 'itemName', component: 'ComponentA', handler: 'resolveItemName' },
|
|
544
|
+
{ name: 'itemPrice', component: 'ComponentB', handler: 'calculatePrice' }
|
|
545
|
+
]
|
|
546
|
+
})
|
|
547
|
+
protected async [A_CommandFeatures.onExecute](): Promise<void> {
|
|
548
|
+
// Template processing happens automatically after this method
|
|
460
549
|
}
|
|
550
|
+
```
|
|
461
551
|
|
|
462
|
-
|
|
552
|
+
**Key Concepts Covered:**
|
|
553
|
+
- Feature template configuration and mapping
|
|
554
|
+
- Component handler automatic execution
|
|
555
|
+
- Result property compilation from handler outputs
|
|
556
|
+
- Container-based dependency injection
|
|
557
|
+
- Modular component architecture
|
|
463
558
|
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
559
|
+
### 🚀 Running the Examples
|
|
560
|
+
|
|
561
|
+
```bash
|
|
562
|
+
# Clone the repository
|
|
563
|
+
git clone <repository-url>
|
|
564
|
+
cd adaas-a-utils
|
|
565
|
+
|
|
566
|
+
# Install dependencies
|
|
567
|
+
npm install
|
|
568
|
+
|
|
569
|
+
# Run multi-service distributed processing example
|
|
570
|
+
npx ts-node examples/A-Command-examples.ts
|
|
571
|
+
|
|
572
|
+
# Run feature-driven template processing example
|
|
573
|
+
npx ts-node examples/A-Command-examples-2.ts
|
|
574
|
+
```
|
|
575
|
+
|
|
576
|
+
### 📚 Additional Examples
|
|
577
|
+
|
|
578
|
+
#### Basic Command Creation
|
|
483
579
|
await memory.set('processingTime', endTime - startTime);
|
|
484
580
|
}
|
|
485
581
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { A_Caller, A_Concept, A_CONSTANTS__DEFAULT_ENV_VARIABLES_ARRAY, A_Container, A_Context, A_Inject, A_Scope, A_ScopeError } from "@adaas/a-concept";
|
|
1
|
+
import { A_Caller, A_Concept, A_CONSTANTS__DEFAULT_ENV_VARIABLES_ARRAY, A_Container, A_Context, A_Fragment, A_Inject, A_Scope, A_ScopeError } from "@adaas/a-concept";
|
|
2
2
|
import { ConfigReader } from "./components/ConfigReader.component";
|
|
3
3
|
import { A_Config } from "./A-Config.context";
|
|
4
4
|
import { A_Polyfill } from "../A-Polyfill/A-Polyfill.component";
|
|
@@ -28,7 +28,7 @@ export class A_ConfigLoader extends A_Container {
|
|
|
28
28
|
defaults: {}
|
|
29
29
|
});
|
|
30
30
|
|
|
31
|
-
this.scope.register(newConfig);
|
|
31
|
+
this.scope.register<A_Fragment>(newConfig);
|
|
32
32
|
}
|
|
33
33
|
|
|
34
34
|
|
|
@@ -5,7 +5,9 @@ import { A_CONSTANTS__CONFIG_ENV_VARIABLES_ARRAY } from "./A-Config.constants";
|
|
|
5
5
|
|
|
6
6
|
export class A_Config<
|
|
7
7
|
T extends Array<string | A_TYPES__ConceptENVVariables[number]> = any[]
|
|
8
|
-
> extends A_Fragment
|
|
8
|
+
> extends A_Fragment<{
|
|
9
|
+
[key in T[number]]: any
|
|
10
|
+
}> {
|
|
9
11
|
|
|
10
12
|
config: A_TYPES__ConfigContainerConstructor<T>;
|
|
11
13
|
|
|
@@ -50,21 +52,33 @@ export class A_Config<
|
|
|
50
52
|
* @param property
|
|
51
53
|
* @returns
|
|
52
54
|
*/
|
|
53
|
-
get<
|
|
54
|
-
property:
|
|
55
|
-
):
|
|
55
|
+
get<K extends T[number]>(
|
|
56
|
+
property: K | typeof this.DEFAULT_ALLOWED_TO_READ_PROPERTIES[number]
|
|
57
|
+
): { [key in T[number]]: any; }[K] | undefined {
|
|
56
58
|
if (this.CONFIG_PROPERTIES.includes(property as any)
|
|
57
59
|
|| this.DEFAULT_ALLOWED_TO_READ_PROPERTIES.includes(property as any)
|
|
58
60
|
|| !(this.config.strict)
|
|
59
61
|
)
|
|
60
|
-
return this.VARIABLES.get(A_FormatterHelper.toUpperSnakeCase(property))
|
|
62
|
+
return this.VARIABLES.get(A_FormatterHelper.toUpperSnakeCase(property));
|
|
61
63
|
|
|
62
64
|
throw new Error('Property not exists or not allowed to read') as never;
|
|
63
65
|
// return this.concept.Errors.throw(A_SDK_CONSTANTS__ERROR_CODES.CONFIGURATION_PROPERTY_NOT_EXISTS_OR_NOT_ALLOWED_TO_READ) as never;
|
|
66
|
+
|
|
64
67
|
}
|
|
65
68
|
|
|
66
69
|
|
|
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;
|
|
67
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
|
+
// }
|
|
68
82
|
/**
|
|
69
83
|
*
|
|
70
84
|
* This method is used to set the configuration property by name
|
|
@@ -18,7 +18,7 @@ export class ConfigReader extends A_Component {
|
|
|
18
18
|
async attachContext(
|
|
19
19
|
@A_Inject(A_Container) container: A_Container,
|
|
20
20
|
@A_Inject(A_Feature) feature: A_Feature,
|
|
21
|
-
@A_Inject(A_Config) config?: A_Config
|
|
21
|
+
@A_Inject(A_Config) config?: A_Config<any>,
|
|
22
22
|
) {
|
|
23
23
|
if (!config) {
|
|
24
24
|
config= new A_Config({
|