@adaas/a-utils 0.1.18 → 0.1.20
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 +45 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.mts +964 -354
- package/dist/index.d.ts +964 -354
- package/dist/index.mjs +44 -2372
- 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
- package/tsup.config.ts +30 -13
- package/dist/index.js +0 -2398
- package/dist/index.js.map +0 -1
package/dist/index.d.mts
CHANGED
|
@@ -1,4 +1,52 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { A_Error, A_TYPES__Error_Serialized, A_Fragment, A_Component, A_TYPES__Entity_Serialized, A_TYPES__ConceptENVVariables, A_TYPES__Fragment_Constructor, A_Scope, A_Entity, A_Container, A_Feature, A_TYPES__Component_Constructor, A_TYPES__Entity_Constructor, A_TYPES__Container_Constructor, A_TYPES__Fragment_Serialized } from '@adaas/a-concept';
|
|
2
|
+
|
|
3
|
+
type A_Operation_Storage<_Result_type extends any = any, _ParamsType extends Record<string, any> = Record<string, any>> = {
|
|
4
|
+
/**
|
|
5
|
+
* The name of the operation
|
|
6
|
+
*/
|
|
7
|
+
name: string;
|
|
8
|
+
/**
|
|
9
|
+
* The parameters for the operation
|
|
10
|
+
*/
|
|
11
|
+
params: _ParamsType;
|
|
12
|
+
/**
|
|
13
|
+
* The result of the operation
|
|
14
|
+
*/
|
|
15
|
+
result: _Result_type;
|
|
16
|
+
/**
|
|
17
|
+
* Any error that occurred during the operation
|
|
18
|
+
*/
|
|
19
|
+
error?: A_Error;
|
|
20
|
+
};
|
|
21
|
+
type A_Operation_Serialized<_Result_type extends any = any, _ParamsType extends Record<string, any> = Record<string, any>> = {
|
|
22
|
+
/**
|
|
23
|
+
* The name of the operation
|
|
24
|
+
*/
|
|
25
|
+
name: string;
|
|
26
|
+
/**
|
|
27
|
+
* The parameters for the operation
|
|
28
|
+
*/
|
|
29
|
+
params: _ParamsType;
|
|
30
|
+
/**
|
|
31
|
+
* The result of the operation
|
|
32
|
+
*/
|
|
33
|
+
result: _Result_type;
|
|
34
|
+
/**
|
|
35
|
+
* Any error that occurred during the operation
|
|
36
|
+
*/
|
|
37
|
+
error?: A_TYPES__Error_Serialized;
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
declare class A_OperationContext<_AllowedOperations extends string = string, _ParamsType extends Record<string, any> = Record<string, any>, _ResultType = any, _StorageType extends A_Operation_Storage<_ResultType, _ParamsType> = A_Operation_Storage<_ResultType, _ParamsType>> extends A_Fragment<_StorageType, A_Operation_Serialized<_ResultType, _ParamsType>> {
|
|
41
|
+
constructor(operation: _AllowedOperations, params?: _ParamsType);
|
|
42
|
+
get name(): _AllowedOperations;
|
|
43
|
+
get result(): _ResultType | undefined;
|
|
44
|
+
get error(): A_Error | undefined;
|
|
45
|
+
get params(): _ParamsType;
|
|
46
|
+
fail(error: A_Error): void;
|
|
47
|
+
succeed(result: _ResultType): void;
|
|
48
|
+
toJSON(): A_Operation_Serialized<_ResultType, _ParamsType>;
|
|
49
|
+
}
|
|
2
50
|
|
|
3
51
|
declare enum A_ChannelFeatures {
|
|
4
52
|
/**
|
|
@@ -67,54 +115,14 @@ declare enum A_ChannelRequestStatuses {
|
|
|
67
115
|
FAILED = "FAILED"
|
|
68
116
|
}
|
|
69
117
|
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
declare class A_ChannelRequest<_ParamsType extends Record<string, any> = Record<string, any>, _ResultType extends Record<string, any> = Record<string, any>> extends A_Fragment {
|
|
78
|
-
protected _params: _ParamsType;
|
|
79
|
-
protected _result?: _ResultType;
|
|
80
|
-
protected _errors: Set<Error>;
|
|
81
|
-
protected _status: A_ChannelRequestStatuses;
|
|
82
|
-
constructor(params?: Partial<_ParamsType>);
|
|
83
|
-
/**
|
|
84
|
-
* Returns the status of the request
|
|
85
|
-
*/
|
|
86
|
-
get status(): A_ChannelRequestStatuses;
|
|
87
|
-
/**
|
|
88
|
-
* Returns the parameters of the request
|
|
89
|
-
*/
|
|
90
|
-
get failed(): boolean;
|
|
91
|
-
/**
|
|
92
|
-
* Returns the Params of the Request
|
|
93
|
-
*/
|
|
94
|
-
get params(): _ParamsType;
|
|
95
|
-
/**
|
|
96
|
-
* Returns the Result of the Request
|
|
97
|
-
*/
|
|
118
|
+
declare class A_ChannelRequest<_ParamsType extends Record<string, any> = Record<string, any>, _ResultType extends Record<string, any> = Record<string, any>> extends A_OperationContext<'request', _ParamsType, {
|
|
119
|
+
data?: _ResultType;
|
|
120
|
+
status?: A_ChannelRequestStatuses;
|
|
121
|
+
}> {
|
|
122
|
+
constructor(params?: _ParamsType);
|
|
123
|
+
get status(): A_ChannelRequestStatuses | undefined;
|
|
98
124
|
get data(): _ResultType | undefined;
|
|
99
|
-
get errors(): Set<Error> | undefined;
|
|
100
|
-
/**
|
|
101
|
-
* Adds an error to the context
|
|
102
|
-
*
|
|
103
|
-
* @param error
|
|
104
|
-
*/
|
|
105
|
-
fail(error: A_Error): void;
|
|
106
|
-
/**
|
|
107
|
-
* Sets the result of the request
|
|
108
|
-
*
|
|
109
|
-
* @param result
|
|
110
|
-
*/
|
|
111
125
|
succeed(result: _ResultType): void;
|
|
112
|
-
/**
|
|
113
|
-
* Serializes the context to a JSON object
|
|
114
|
-
*
|
|
115
|
-
* @returns
|
|
116
|
-
*/
|
|
117
|
-
toJSON(): A_ChannelRequestContext_Serialized<_ParamsType, _ResultType>;
|
|
118
126
|
}
|
|
119
127
|
|
|
120
128
|
/**
|
|
@@ -471,12 +479,12 @@ declare class A_Channel extends A_Component {
|
|
|
471
479
|
* For fire-and-forget pattern: Use send()
|
|
472
480
|
* For consumer patterns: Implement custom consumer logic using request() in a loop
|
|
473
481
|
*/
|
|
474
|
-
consume<T extends Record<string, any> = Record<string, any>>(): Promise<
|
|
482
|
+
consume<T extends Record<string, any> = Record<string, any>>(): Promise<A_OperationContext<any, T>>;
|
|
475
483
|
}
|
|
476
484
|
|
|
477
485
|
declare class A_ChannelError extends A_Error {
|
|
478
486
|
static readonly MethodNotImplemented = "A-Channel Method Not Implemented";
|
|
479
|
-
protected _context?:
|
|
487
|
+
protected _context?: A_OperationContext;
|
|
480
488
|
/**
|
|
481
489
|
* Channel Error allows to keep track of errors within a channel if something goes wrong
|
|
482
490
|
*
|
|
@@ -484,390 +492,494 @@ declare class A_ChannelError extends A_Error {
|
|
|
484
492
|
* @param originalError
|
|
485
493
|
* @param context
|
|
486
494
|
*/
|
|
487
|
-
constructor(originalError: string | A_Error | Error | any, context?:
|
|
495
|
+
constructor(originalError: string | A_Error | Error | any, context?: A_OperationContext | string);
|
|
488
496
|
/***
|
|
489
497
|
* Returns Context of the error
|
|
490
498
|
*/
|
|
491
|
-
get context():
|
|
499
|
+
get context(): A_OperationContext | undefined;
|
|
492
500
|
}
|
|
493
501
|
|
|
494
502
|
/**
|
|
495
|
-
* A-Command
|
|
503
|
+
* A-Command Status Enumeration
|
|
504
|
+
*
|
|
505
|
+
* Defines all possible states a command can be in during its lifecycle.
|
|
506
|
+
* Commands progress through these states in a specific order:
|
|
507
|
+
* CREATED → INITIALIZED → COMPILED → EXECUTING → COMPLETED/FAILED
|
|
496
508
|
*/
|
|
497
|
-
declare enum
|
|
509
|
+
declare enum A_Command_Status {
|
|
498
510
|
/**
|
|
499
|
-
*
|
|
511
|
+
* Initial state when command is instantiated but not yet ready for execution
|
|
500
512
|
*/
|
|
501
513
|
CREATED = "CREATED",
|
|
502
514
|
/**
|
|
503
|
-
* Command
|
|
504
|
-
*/
|
|
505
|
-
INITIALIZATION = "INITIALIZATION",
|
|
506
|
-
/**
|
|
507
|
-
* Command has been initialized
|
|
515
|
+
* Command has been initialized with execution scope and dependencies
|
|
508
516
|
*/
|
|
509
517
|
INITIALIZED = "INITIALIZED",
|
|
510
518
|
/**
|
|
511
|
-
* Command is
|
|
512
|
-
*/
|
|
513
|
-
COMPILATION = "COMPILATION",
|
|
514
|
-
/**
|
|
515
|
-
* Command is compiled
|
|
519
|
+
* Command has been compiled and is ready for execution
|
|
516
520
|
*/
|
|
517
521
|
COMPILED = "COMPILED",
|
|
518
522
|
/**
|
|
519
|
-
* Command is
|
|
523
|
+
* Command is currently being executed
|
|
520
524
|
*/
|
|
521
|
-
|
|
525
|
+
EXECUTING = "EXECUTING",
|
|
522
526
|
/**
|
|
523
527
|
* Command has completed successfully
|
|
524
528
|
*/
|
|
525
529
|
COMPLETED = "COMPLETED",
|
|
526
530
|
/**
|
|
527
|
-
* Command has failed
|
|
531
|
+
* Command execution has failed with errors
|
|
528
532
|
*/
|
|
529
533
|
FAILED = "FAILED"
|
|
530
534
|
}
|
|
535
|
+
/**
|
|
536
|
+
* A-Command State Transitions
|
|
537
|
+
*
|
|
538
|
+
* Defines valid state transitions for command lifecycle management.
|
|
539
|
+
* These transitions are used by the StateMachine to enforce proper command flow.
|
|
540
|
+
*/
|
|
541
|
+
declare enum A_CommandTransitions {
|
|
542
|
+
/** Transition from CREATED to INITIALIZED state */
|
|
543
|
+
CREATED_TO_INITIALIZED = "created_initialized",
|
|
544
|
+
/** Transition from INITIALIZED to EXECUTING state */
|
|
545
|
+
INITIALIZED_TO_EXECUTING = "initialized_executing",
|
|
546
|
+
/** Transition from EXECUTING to COMPLETED state (success path) */
|
|
547
|
+
EXECUTING_TO_COMPLETED = "executing_completed",
|
|
548
|
+
/** Transition from EXECUTING to FAILED state (error path) */
|
|
549
|
+
EXECUTING_TO_FAILED = "executing_failed"
|
|
550
|
+
}
|
|
531
551
|
/**
|
|
532
552
|
* A-Command Lifecycle Features
|
|
553
|
+
*
|
|
554
|
+
* Defines feature extension points that components can implement to customize
|
|
555
|
+
* command behavior at different stages of the lifecycle.
|
|
556
|
+
*
|
|
557
|
+
* Components can use @A_Feature.Extend() decorator with these feature names
|
|
558
|
+
* to inject custom logic into command execution.
|
|
533
559
|
*/
|
|
534
560
|
declare enum A_CommandFeatures {
|
|
535
561
|
/**
|
|
536
|
-
*
|
|
562
|
+
* Triggered during command initialization phase
|
|
563
|
+
* Use to set up execution environment, validate parameters, or prepare resources
|
|
537
564
|
*/
|
|
538
565
|
onInit = "onInit",
|
|
539
566
|
/**
|
|
540
|
-
*
|
|
567
|
+
* Triggered before command execution starts
|
|
568
|
+
* Use for pre-execution validation, logging, or setup tasks
|
|
541
569
|
*/
|
|
542
|
-
|
|
570
|
+
onBeforeExecute = "onBeforeExecute",
|
|
543
571
|
/**
|
|
544
|
-
*
|
|
572
|
+
* Main command execution logic
|
|
573
|
+
* Core business logic should be implemented here
|
|
545
574
|
*/
|
|
546
575
|
onExecute = "onExecute",
|
|
547
576
|
/**
|
|
548
|
-
*
|
|
577
|
+
* Triggered after command execution completes (success or failure)
|
|
578
|
+
* Use for cleanup, logging, or post-processing tasks
|
|
579
|
+
*/
|
|
580
|
+
onAfterExecute = "onAfterExecute",
|
|
581
|
+
/**
|
|
582
|
+
* Triggered when command completes successfully
|
|
583
|
+
* Use for success-specific operations like notifications or result processing
|
|
549
584
|
*/
|
|
550
585
|
onComplete = "onComplete",
|
|
551
586
|
/**
|
|
552
|
-
*
|
|
587
|
+
* Triggered when command execution fails
|
|
588
|
+
* Use for error handling, cleanup, or failure notifications
|
|
553
589
|
*/
|
|
554
|
-
onFail = "onFail"
|
|
590
|
+
onFail = "onFail",
|
|
591
|
+
/**
|
|
592
|
+
* Triggered when an error occurs during execution
|
|
593
|
+
* Use for error logging, transformation, or recovery attempts
|
|
594
|
+
*/
|
|
595
|
+
onError = "onError"
|
|
555
596
|
}
|
|
556
|
-
|
|
597
|
+
/**
|
|
598
|
+
* Type alias for command lifecycle event names
|
|
599
|
+
* Represents all available events that can be listened to on a command instance
|
|
600
|
+
*/
|
|
601
|
+
type A_Command_Event = keyof typeof A_CommandFeatures;
|
|
557
602
|
|
|
558
603
|
/**
|
|
559
|
-
* Command
|
|
560
|
-
*
|
|
604
|
+
* Command Constructor Type
|
|
605
|
+
*
|
|
606
|
+
* Generic constructor type for creating command instances.
|
|
607
|
+
* Used for dependency injection and factory patterns.
|
|
608
|
+
*
|
|
609
|
+
* @template T - The command class type extending A_Command
|
|
561
610
|
*/
|
|
562
611
|
type A_TYPES__Command_Constructor<T = A_Command> = new (...args: any[]) => T;
|
|
563
612
|
/**
|
|
564
|
-
* Command
|
|
613
|
+
* Command Initialization Parameters
|
|
614
|
+
*
|
|
615
|
+
* Base type for command parameters. Commands should extend this with
|
|
616
|
+
* specific parameter types for their use case.
|
|
617
|
+
*
|
|
618
|
+
* @example
|
|
619
|
+
* ```typescript
|
|
620
|
+
* interface UserCommandParams extends A_TYPES__Command_Init {
|
|
621
|
+
* userId: string;
|
|
622
|
+
* action: 'create' | 'update' | 'delete';
|
|
623
|
+
* }
|
|
624
|
+
* ```
|
|
565
625
|
*/
|
|
566
626
|
type A_TYPES__Command_Init = Record<string, any>;
|
|
567
627
|
/**
|
|
568
|
-
* Command
|
|
628
|
+
* Command Serialized Format
|
|
629
|
+
*
|
|
630
|
+
* Complete serialized representation of a command including all state,
|
|
631
|
+
* timing information, results, and errors. Used for persistence,
|
|
632
|
+
* transmission between services, and state restoration.
|
|
633
|
+
*
|
|
634
|
+
* @template ParamsType - Type of command parameters
|
|
635
|
+
* @template ResultType - Type of command execution result
|
|
636
|
+
*
|
|
637
|
+
* @example
|
|
638
|
+
* ```typescript
|
|
639
|
+
* const serialized: A_TYPES__Command_Serialized<
|
|
640
|
+
* { userId: string },
|
|
641
|
+
* { success: boolean }
|
|
642
|
+
* > = command.toJSON();
|
|
643
|
+
* ```
|
|
569
644
|
*/
|
|
570
645
|
type A_TYPES__Command_Serialized<ParamsType extends Record<string, any> = Record<string, any>, ResultType extends Record<string, any> = Record<string, any>> = {
|
|
571
646
|
/**
|
|
572
|
-
* Unique
|
|
647
|
+
* Unique identifier for the command type (derived from class name)
|
|
573
648
|
*/
|
|
574
649
|
code: string;
|
|
575
650
|
/**
|
|
576
|
-
* Current status of the command
|
|
651
|
+
* Current execution status of the command
|
|
577
652
|
*/
|
|
578
|
-
status:
|
|
653
|
+
status: A_Command_Status;
|
|
579
654
|
/**
|
|
580
|
-
* Parameters used to
|
|
655
|
+
* Parameters used to initialize the command
|
|
581
656
|
*/
|
|
582
657
|
params: ParamsType;
|
|
583
658
|
/**
|
|
584
|
-
*
|
|
659
|
+
* ISO timestamp when the command was created
|
|
660
|
+
*/
|
|
661
|
+
createdAt: string;
|
|
662
|
+
/**
|
|
663
|
+
* ISO timestamp when command execution started (if started)
|
|
585
664
|
*/
|
|
586
665
|
startedAt?: string;
|
|
587
666
|
/**
|
|
588
|
-
*
|
|
667
|
+
* ISO timestamp when command execution ended (if completed/failed)
|
|
589
668
|
*/
|
|
590
669
|
endedAt?: string;
|
|
591
670
|
/**
|
|
592
|
-
*
|
|
671
|
+
* Total execution duration in milliseconds (if completed/failed)
|
|
593
672
|
*/
|
|
594
673
|
duration?: number;
|
|
595
674
|
/**
|
|
596
|
-
*
|
|
675
|
+
* Time between creation and execution start in milliseconds
|
|
676
|
+
*/
|
|
677
|
+
idleTime?: number;
|
|
678
|
+
/**
|
|
679
|
+
* Result data produced by successful command execution
|
|
597
680
|
*/
|
|
598
681
|
result?: ResultType;
|
|
599
682
|
/**
|
|
600
|
-
*
|
|
683
|
+
* Array of serialized errors that occurred during execution
|
|
601
684
|
*/
|
|
602
|
-
|
|
685
|
+
error?: A_TYPES__Error_Serialized;
|
|
603
686
|
} & A_TYPES__Entity_Serialized;
|
|
604
687
|
/**
|
|
605
|
-
* Command
|
|
688
|
+
* Command Event Listener Function
|
|
689
|
+
*
|
|
690
|
+
* Type definition for event listener functions that can be registered
|
|
691
|
+
* to respond to command lifecycle events.
|
|
692
|
+
*
|
|
693
|
+
* @template InvokeType - Type of command initialization parameters
|
|
694
|
+
* @template ResultType - Type of command execution result
|
|
695
|
+
* @template LifecycleEvents - Union type of custom lifecycle event names
|
|
696
|
+
*
|
|
697
|
+
* @param command - The command instance that triggered the event
|
|
698
|
+
*
|
|
699
|
+
* @example
|
|
700
|
+
* ```typescript
|
|
701
|
+
* const listener: A_TYPES__Command_Listener<UserParams, UserResult> = (command) => {
|
|
702
|
+
* console.log(`Command ${command?.code} triggered event`);
|
|
703
|
+
* };
|
|
704
|
+
*
|
|
705
|
+
* command.on('onExecute', listener);
|
|
706
|
+
* ```
|
|
606
707
|
*/
|
|
607
|
-
type A_TYPES__Command_Listener<InvokeType extends A_TYPES__Command_Init = A_TYPES__Command_Init, ResultType extends Record<string, any> = Record<string, any>, LifecycleEvents extends string =
|
|
708
|
+
type A_TYPES__Command_Listener<InvokeType extends A_TYPES__Command_Init = A_TYPES__Command_Init, ResultType extends Record<string, any> = Record<string, any>, LifecycleEvents extends string = A_Command_Event> = (command?: A_Command<InvokeType, ResultType, LifecycleEvents>) => void;
|
|
608
709
|
|
|
609
|
-
declare
|
|
610
|
-
/**
|
|
611
|
-
* Command Identifier that corresponds to the class name
|
|
612
|
-
*/
|
|
613
|
-
static get code(): string;
|
|
614
|
-
protected _result?: ResultType;
|
|
615
|
-
protected _executionScope: A_Scope;
|
|
616
|
-
protected _errors?: Set<A_Error>;
|
|
617
|
-
protected _params: InvokeType;
|
|
618
|
-
protected _status: A_CONSTANTS__A_Command_Status;
|
|
619
|
-
protected _listeners: Map<LifecycleEvents | A_CONSTANTS__A_Command_Event, Set<A_TYPES__Command_Listener<InvokeType, ResultType, LifecycleEvents>>>;
|
|
620
|
-
protected _startTime?: Date;
|
|
621
|
-
protected _endTime?: Date;
|
|
622
|
-
/**
|
|
623
|
-
* Execution Duration in milliseconds
|
|
624
|
-
*/
|
|
625
|
-
get duration(): number | undefined;
|
|
710
|
+
declare enum A_StateMachineFeatures {
|
|
626
711
|
/**
|
|
627
|
-
*
|
|
712
|
+
* Allows to extend error handling logic and behavior
|
|
628
713
|
*/
|
|
629
|
-
|
|
714
|
+
onError = "onError",
|
|
630
715
|
/**
|
|
631
|
-
*
|
|
632
|
-
* Example: 'user.create', 'task.complete', etc.
|
|
633
|
-
*
|
|
716
|
+
* Allows to extend initialization logic and behavior
|
|
634
717
|
*/
|
|
635
|
-
|
|
718
|
+
onInitialize = "onInitialize",
|
|
636
719
|
/**
|
|
637
|
-
*
|
|
720
|
+
* Allows to extend transition validation logic and behavior
|
|
638
721
|
*/
|
|
639
|
-
|
|
722
|
+
onBeforeTransition = "onBeforeTransition",
|
|
640
723
|
/**
|
|
641
|
-
*
|
|
724
|
+
* Allows to extend post-transition logic and behavior
|
|
642
725
|
*/
|
|
643
|
-
|
|
726
|
+
onAfterTransition = "onAfterTransition"
|
|
727
|
+
}
|
|
728
|
+
|
|
729
|
+
/**
|
|
730
|
+
* A_StateMachine is a powerful state machine implementation that allows you to define and manage
|
|
731
|
+
* complex state transitions with validation, hooks, and error handling.
|
|
732
|
+
*
|
|
733
|
+
* @template T - A record type defining the state transitions and their associated data types.
|
|
734
|
+
* Each key represents a state name, and the value represents the data type for that state.
|
|
735
|
+
*
|
|
736
|
+
* @example
|
|
737
|
+
* ```typescript
|
|
738
|
+
* interface OrderStates {
|
|
739
|
+
* pending: { orderId: string };
|
|
740
|
+
* processing: { orderId: string; processedBy: string };
|
|
741
|
+
* completed: { orderId: string; completedAt: Date };
|
|
742
|
+
* cancelled: { orderId: string; reason: string };
|
|
743
|
+
* }
|
|
744
|
+
*
|
|
745
|
+
* class OrderStateMachine extends A_StateMachine<OrderStates> {
|
|
746
|
+
* // Define custom transition logic
|
|
747
|
+
* async pending_processing(scope: A_Scope) {
|
|
748
|
+
* const operation = scope.resolve(A_StateMachineTransition)!;
|
|
749
|
+
* const { orderId } = operation.props;
|
|
750
|
+
* // Custom validation and business logic
|
|
751
|
+
* }
|
|
752
|
+
* }
|
|
753
|
+
* ```
|
|
754
|
+
*/
|
|
755
|
+
declare class A_StateMachine<T extends Record<string, any> = Record<string, any>> extends A_Component {
|
|
644
756
|
/**
|
|
645
|
-
*
|
|
757
|
+
* Internal promise that tracks the initialization state of the state machine.
|
|
758
|
+
* Used to ensure the state machine is properly initialized before allowing transitions.
|
|
646
759
|
*/
|
|
647
|
-
|
|
760
|
+
protected _initialized?: Promise<void>;
|
|
648
761
|
/**
|
|
649
|
-
*
|
|
762
|
+
* Gets a promise that resolves when the state machine is fully initialized and ready for transitions.
|
|
763
|
+
* This ensures that all initialization hooks have been executed before allowing state transitions.
|
|
764
|
+
*
|
|
765
|
+
* @returns Promise<void> that resolves when initialization is complete
|
|
766
|
+
*
|
|
767
|
+
* @example
|
|
768
|
+
* ```typescript
|
|
769
|
+
* const stateMachine = new MyStateMachine();
|
|
770
|
+
* await stateMachine.ready; // Wait for initialization
|
|
771
|
+
* await stateMachine.transition('idle', 'running');
|
|
772
|
+
* ```
|
|
650
773
|
*/
|
|
651
|
-
get
|
|
774
|
+
get ready(): Promise<void>;
|
|
652
775
|
/**
|
|
653
|
-
*
|
|
776
|
+
* Initialization hook that runs when the state machine is first created.
|
|
777
|
+
* This method can be extended to add custom initialization logic.
|
|
778
|
+
*
|
|
779
|
+
* @param args - Variable arguments passed during initialization
|
|
780
|
+
* @returns Promise<void>
|
|
781
|
+
*
|
|
782
|
+
* @example
|
|
783
|
+
* ```typescript
|
|
784
|
+
* class MyStateMachine extends A_StateMachine {
|
|
785
|
+
* @A_Feature.Extend()
|
|
786
|
+
* async [A_StateMachineFeatures.onInitialize]() {
|
|
787
|
+
* // Custom initialization logic
|
|
788
|
+
* console.log('State machine initialized');
|
|
789
|
+
* }
|
|
790
|
+
* }
|
|
791
|
+
* ```
|
|
654
792
|
*/
|
|
655
|
-
|
|
793
|
+
[A_StateMachineFeatures.onInitialize](...args: any[]): Promise<void>;
|
|
656
794
|
/**
|
|
657
|
-
*
|
|
795
|
+
* Hook that runs before any state transition occurs.
|
|
796
|
+
* Use this to add validation, logging, or preparation logic that should run for all transitions.
|
|
797
|
+
*
|
|
798
|
+
* @param args - Variable arguments, typically includes the transition scope
|
|
799
|
+
* @returns Promise<void>
|
|
800
|
+
*
|
|
801
|
+
* @example
|
|
802
|
+
* ```typescript
|
|
803
|
+
* class MyStateMachine extends A_StateMachine {
|
|
804
|
+
* @A_Feature.Extend()
|
|
805
|
+
* async [A_StateMachineFeatures.onBeforeTransition](scope: A_Scope) {
|
|
806
|
+
* const operation = scope.resolve(A_StateMachineTransition)!;
|
|
807
|
+
* console.log(`Transitioning from ${operation.props.from} to ${operation.props.to}`);
|
|
808
|
+
* }
|
|
809
|
+
* }
|
|
810
|
+
* ```
|
|
658
811
|
*/
|
|
659
|
-
|
|
812
|
+
[A_StateMachineFeatures.onBeforeTransition](...args: any[]): Promise<void>;
|
|
660
813
|
/**
|
|
661
|
-
*
|
|
814
|
+
* Hook that runs after a successful state transition.
|
|
815
|
+
* Use this to add cleanup, logging, or post-transition logic that should run for all transitions.
|
|
816
|
+
*
|
|
817
|
+
* @param args - Variable arguments, typically includes the transition scope
|
|
818
|
+
* @returns Promise<void>
|
|
819
|
+
*
|
|
820
|
+
* @example
|
|
821
|
+
* ```typescript
|
|
822
|
+
* class MyStateMachine extends A_StateMachine {
|
|
823
|
+
* @A_Feature.Extend()
|
|
824
|
+
* async [A_StateMachineFeatures.onAfterTransition](scope: A_Scope) {
|
|
825
|
+
* const operation = scope.resolve(A_StateMachineTransition)!;
|
|
826
|
+
* console.log(`Successfully transitioned to ${operation.props.to}`);
|
|
827
|
+
* }
|
|
828
|
+
* }
|
|
829
|
+
* ```
|
|
662
830
|
*/
|
|
663
|
-
|
|
831
|
+
[A_StateMachineFeatures.onAfterTransition](...args: any[]): Promise<void>;
|
|
664
832
|
/**
|
|
665
|
-
*
|
|
833
|
+
* Error handling hook that runs when a transition fails.
|
|
834
|
+
* Use this to add custom error handling, logging, or recovery logic.
|
|
835
|
+
*
|
|
836
|
+
* @param args - Variable arguments, typically includes the error scope
|
|
837
|
+
* @returns Promise<void>
|
|
838
|
+
*
|
|
839
|
+
* @example
|
|
840
|
+
* ```typescript
|
|
841
|
+
* class MyStateMachine extends A_StateMachine {
|
|
842
|
+
* @A_Feature.Extend()
|
|
843
|
+
* async [A_StateMachineFeatures.onError](scope: A_Scope) {
|
|
844
|
+
* const error = scope.resolve(A_StateMachineError);
|
|
845
|
+
* console.error('Transition failed:', error?.message);
|
|
846
|
+
* }
|
|
847
|
+
* }
|
|
848
|
+
* ```
|
|
666
849
|
*/
|
|
667
|
-
|
|
850
|
+
[A_StateMachineFeatures.onError](...args: any[]): Promise<void>;
|
|
668
851
|
/**
|
|
852
|
+
* Executes a state transition from one state to another.
|
|
853
|
+
* This is the core method of the state machine that handles the complete transition lifecycle.
|
|
669
854
|
*
|
|
670
|
-
*
|
|
671
|
-
*
|
|
855
|
+
* @param from - The state to transition from (must be a key of T)
|
|
856
|
+
* @param to - The state to transition to (must be a key of T)
|
|
857
|
+
* @param props - Optional properties to pass to the transition context (should match T[keyof T])
|
|
858
|
+
* @returns Promise<void> that resolves when the transition is complete
|
|
672
859
|
*
|
|
860
|
+
* @throws {A_StateMachineError} When the transition fails for any reason
|
|
673
861
|
*
|
|
674
|
-
*
|
|
862
|
+
* @example
|
|
863
|
+
* ```typescript
|
|
864
|
+
* interface OrderStates {
|
|
865
|
+
* pending: { orderId: string };
|
|
866
|
+
* processing: { orderId: string; processedBy: string };
|
|
867
|
+
* }
|
|
675
868
|
*
|
|
676
|
-
*
|
|
677
|
-
*
|
|
869
|
+
* const orderMachine = new A_StateMachine<OrderStates>();
|
|
870
|
+
*
|
|
871
|
+
* // Transition with props
|
|
872
|
+
* await orderMachine.transition('pending', 'processing', {
|
|
873
|
+
* orderId: '12345',
|
|
874
|
+
* processedBy: 'user-456'
|
|
875
|
+
* });
|
|
876
|
+
* ```
|
|
877
|
+
*
|
|
878
|
+
* The transition process follows this lifecycle:
|
|
879
|
+
* 1. Wait for state machine initialization (ready)
|
|
880
|
+
* 2. Create transition name in camelCase format (e.g., "pending_processing")
|
|
881
|
+
* 3. Create operation context with transition data
|
|
882
|
+
* 4. Create isolated scope for the transition
|
|
883
|
+
* 5. Call onBeforeTransition hook
|
|
884
|
+
* 6. Execute the specific transition method (if defined)
|
|
885
|
+
* 7. Call onAfterTransition hook
|
|
886
|
+
* 8. Clean up scope and return result
|
|
887
|
+
*
|
|
888
|
+
* If any step fails, the onError hook is called and a wrapped error is thrown.
|
|
678
889
|
*/
|
|
679
|
-
|
|
890
|
+
transition(
|
|
680
891
|
/**
|
|
681
|
-
*
|
|
892
|
+
* The state to transition from
|
|
682
893
|
*/
|
|
683
|
-
|
|
684
|
-
init(): Promise<void>;
|
|
685
|
-
compile(): Promise<void>;
|
|
894
|
+
from: keyof T,
|
|
686
895
|
/**
|
|
687
|
-
*
|
|
688
|
-
*
|
|
689
|
-
* @returns
|
|
896
|
+
* The state to transition to
|
|
690
897
|
*/
|
|
691
|
-
|
|
898
|
+
to: keyof T,
|
|
692
899
|
/**
|
|
693
|
-
*
|
|
900
|
+
* Optional properties to pass to the transition context
|
|
694
901
|
*/
|
|
695
|
-
|
|
902
|
+
props?: T[keyof T]): Promise<void>;
|
|
903
|
+
}
|
|
904
|
+
|
|
905
|
+
declare enum A_TYPES__ConfigFeature {
|
|
906
|
+
}
|
|
907
|
+
type A_TYPES__ConfigContainerConstructor<T extends Array<string | A_TYPES__ConceptENVVariables[number]>> = {
|
|
696
908
|
/**
|
|
697
|
-
*
|
|
909
|
+
* If set to true, the SDK will throw an error if the variable is not defined OR not presented in the defaults
|
|
698
910
|
*/
|
|
699
|
-
|
|
911
|
+
strict: boolean;
|
|
700
912
|
/**
|
|
701
|
-
*
|
|
913
|
+
* Allows to define the names of variable to be loaded
|
|
702
914
|
*/
|
|
703
|
-
|
|
915
|
+
variables: T;
|
|
704
916
|
/**
|
|
705
|
-
*
|
|
706
|
-
*
|
|
707
|
-
* @param event
|
|
708
|
-
* @param listener
|
|
917
|
+
* Allows to set the default values for the variables
|
|
709
918
|
*/
|
|
710
|
-
|
|
919
|
+
defaults: {
|
|
920
|
+
[key in T[number]]?: any;
|
|
921
|
+
};
|
|
922
|
+
} & A_TYPES__Fragment_Constructor;
|
|
923
|
+
|
|
924
|
+
declare class A_Config<T extends Array<string | A_TYPES__ConceptENVVariables[number]> = any[]> extends A_Fragment<{
|
|
925
|
+
[key in T[number]]: any;
|
|
926
|
+
}> {
|
|
927
|
+
config: A_TYPES__ConfigContainerConstructor<T>;
|
|
928
|
+
private VARIABLES;
|
|
929
|
+
CONFIG_PROPERTIES: T;
|
|
930
|
+
protected DEFAULT_ALLOWED_TO_READ_PROPERTIES: ("A_CONCEPT_NAME" | "A_CONCEPT_ROOT_SCOPE" | "A_CONCEPT_ENVIRONMENT" | "A_CONCEPT_ROOT_FOLDER" | "A_ERROR_DEFAULT_DESCRIPTION")[];
|
|
931
|
+
constructor(config: Partial<A_TYPES__ConfigContainerConstructor<T>>);
|
|
711
932
|
/**
|
|
712
|
-
*
|
|
933
|
+
* This method is used to get the configuration property by name
|
|
713
934
|
*
|
|
714
|
-
* @param
|
|
715
|
-
* @
|
|
935
|
+
* @param property
|
|
936
|
+
* @returns
|
|
716
937
|
*/
|
|
717
|
-
|
|
938
|
+
get<K extends T[number]>(property: K | typeof this.DEFAULT_ALLOWED_TO_READ_PROPERTIES[number]): {
|
|
939
|
+
[key in T[number]]: any;
|
|
940
|
+
}[K] | undefined;
|
|
718
941
|
/**
|
|
719
|
-
* Emits an event to all registered listeners
|
|
720
942
|
*
|
|
721
|
-
*
|
|
943
|
+
* This method is used to set the configuration property by name
|
|
944
|
+
* OR set multiple properties at once by passing an array of objects
|
|
945
|
+
*
|
|
946
|
+
* @param variables
|
|
722
947
|
*/
|
|
723
|
-
|
|
948
|
+
set(variables: Array<{
|
|
949
|
+
property: T[number] | A_TYPES__ConceptENVVariables[number];
|
|
950
|
+
value: any;
|
|
951
|
+
}>): any;
|
|
952
|
+
set(variables: Partial<Record<T[number] | A_TYPES__ConceptENVVariables[number], any>>): any;
|
|
953
|
+
set(property: T[number] | A_TYPES__ConceptENVVariables[number], value: any): any;
|
|
954
|
+
}
|
|
955
|
+
|
|
956
|
+
declare const A_LoggerEnvVariables: {
|
|
724
957
|
/**
|
|
725
|
-
*
|
|
958
|
+
* Sets the log level for the logger
|
|
726
959
|
*
|
|
727
|
-
* @
|
|
960
|
+
* @example 'debug', 'info', 'warn', 'error'
|
|
728
961
|
*/
|
|
729
|
-
|
|
962
|
+
readonly A_LOGGER_LEVEL: "A_LOGGER_LEVEL";
|
|
730
963
|
/**
|
|
731
|
-
*
|
|
964
|
+
* Sets the default scope length for log messages
|
|
732
965
|
*
|
|
733
|
-
*
|
|
966
|
+
* @example 'A_LOGGER_DEFAULT_SCOPE_LENGTH'
|
|
967
|
+
*/
|
|
968
|
+
readonly A_LOGGER_DEFAULT_SCOPE_LENGTH: "A_LOGGER_DEFAULT_SCOPE_LENGTH";
|
|
969
|
+
/**
|
|
970
|
+
* Sets the default color for scope display in log messages
|
|
734
971
|
*
|
|
735
|
-
* @
|
|
972
|
+
* @example 'green', 'blue', 'red', 'yellow', 'gray', 'magenta', 'cyan', 'white', 'pink'
|
|
736
973
|
*/
|
|
737
|
-
|
|
974
|
+
readonly A_LOGGER_DEFAULT_SCOPE_COLOR: "A_LOGGER_DEFAULT_SCOPE_COLOR";
|
|
738
975
|
/**
|
|
739
|
-
*
|
|
976
|
+
* Sets the default color for log message content
|
|
740
977
|
*
|
|
741
|
-
* @
|
|
978
|
+
* @example 'green', 'blue', 'red', 'yellow', 'gray', 'magenta', 'cyan', 'white', 'pink'
|
|
742
979
|
*/
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
|
|
747
|
-
declare class A_CommandError extends A_Error {
|
|
748
|
-
static readonly CommandScopeBindingError = "A-Command Scope Binding Error";
|
|
749
|
-
}
|
|
750
|
-
|
|
751
|
-
interface Ifspolyfill {
|
|
752
|
-
readFileSync: (path: string, encoding: string) => string;
|
|
753
|
-
existsSync: (path: string) => boolean;
|
|
754
|
-
createReadStream: (path: string, options?: BufferEncoding) => any;
|
|
755
|
-
}
|
|
756
|
-
interface IcryptoInterface {
|
|
757
|
-
createTextHash(text: string, algorithm: string): Promise<string>;
|
|
758
|
-
createFileHash(filePath: string, algorithm: string): Promise<string>;
|
|
759
|
-
}
|
|
760
|
-
interface IhttpInterface {
|
|
761
|
-
request: (options: any, callback?: (res: any) => void) => any;
|
|
762
|
-
get: (url: string | any, callback?: (res: any) => void) => any;
|
|
763
|
-
createServer: (requestListener?: (req: any, res: any) => void) => any;
|
|
764
|
-
}
|
|
765
|
-
interface IhttpsInterface {
|
|
766
|
-
request: (options: any, callback?: (res: any) => void) => any;
|
|
767
|
-
get: (url: string | any, callback?: (res: any) => void) => any;
|
|
768
|
-
createServer: (options: any, requestListener?: (req: any, res: any) => void) => any;
|
|
769
|
-
}
|
|
770
|
-
interface IpathInterface {
|
|
771
|
-
join: (...paths: string[]) => string;
|
|
772
|
-
resolve: (...paths: string[]) => string;
|
|
773
|
-
dirname: (path: string) => string;
|
|
774
|
-
basename: (path: string, ext?: string) => string;
|
|
775
|
-
extname: (path: string) => string;
|
|
776
|
-
relative: (from: string, to: string) => string;
|
|
777
|
-
normalize: (path: string) => string;
|
|
778
|
-
isAbsolute: (path: string) => boolean;
|
|
779
|
-
parse: (path: string) => any;
|
|
780
|
-
format: (pathObject: any) => string;
|
|
781
|
-
sep: string;
|
|
782
|
-
delimiter: string;
|
|
783
|
-
}
|
|
784
|
-
interface IurlInterface {
|
|
785
|
-
parse: (urlString: string) => any;
|
|
786
|
-
format: (urlObject: any) => string;
|
|
787
|
-
resolve: (from: string, to: string) => string;
|
|
788
|
-
URL: typeof URL;
|
|
789
|
-
URLSearchParams: typeof URLSearchParams;
|
|
790
|
-
}
|
|
791
|
-
interface IbufferInterface {
|
|
792
|
-
from: (data: any, encoding?: string) => any;
|
|
793
|
-
alloc: (size: number, fill?: any) => any;
|
|
794
|
-
allocUnsafe: (size: number) => any;
|
|
795
|
-
isBuffer: (obj: any) => boolean;
|
|
796
|
-
concat: (list: any[], totalLength?: number) => any;
|
|
797
|
-
}
|
|
798
|
-
interface IprocessInterface {
|
|
799
|
-
env: Record<string, string | undefined>;
|
|
800
|
-
argv: string[];
|
|
801
|
-
platform: string;
|
|
802
|
-
version: string;
|
|
803
|
-
versions: Record<string, string>;
|
|
804
|
-
cwd: () => string;
|
|
805
|
-
exit: (code?: number) => never;
|
|
806
|
-
nextTick: (callback: Function, ...args: any[]) => void;
|
|
807
|
-
}
|
|
808
|
-
|
|
809
|
-
declare enum A_TYPES__ConfigFeature {
|
|
810
|
-
}
|
|
811
|
-
type A_TYPES__ConfigContainerConstructor<T extends Array<string | A_TYPES__ConceptENVVariables[number]>> = {
|
|
812
|
-
/**
|
|
813
|
-
* If set to true, the SDK will throw an error if the variable is not defined OR not presented in the defaults
|
|
814
|
-
*/
|
|
815
|
-
strict: boolean;
|
|
816
|
-
/**
|
|
817
|
-
* Allows to define the names of variable to be loaded
|
|
818
|
-
*/
|
|
819
|
-
variables: T;
|
|
820
|
-
/**
|
|
821
|
-
* Allows to set the default values for the variables
|
|
822
|
-
*/
|
|
823
|
-
defaults: {
|
|
824
|
-
[key in T[number]]?: any;
|
|
825
|
-
};
|
|
826
|
-
} & A_TYPES__Fragment_Constructor;
|
|
827
|
-
|
|
828
|
-
declare class A_Config<T extends Array<string | A_TYPES__ConceptENVVariables[number]> = any[]> extends A_Fragment {
|
|
829
|
-
config: A_TYPES__ConfigContainerConstructor<T>;
|
|
830
|
-
private VARIABLES;
|
|
831
|
-
CONFIG_PROPERTIES: T;
|
|
832
|
-
protected DEFAULT_ALLOWED_TO_READ_PROPERTIES: ("A_CONCEPT_NAME" | "A_CONCEPT_ROOT_SCOPE" | "A_CONCEPT_ENVIRONMENT" | "A_CONCEPT_ROOT_FOLDER" | "A_ERROR_DEFAULT_DESCRIPTION")[];
|
|
833
|
-
constructor(config: Partial<A_TYPES__ConfigContainerConstructor<T>>);
|
|
834
|
-
/**
|
|
835
|
-
* This method is used to get the configuration property by name
|
|
836
|
-
*
|
|
837
|
-
* @param property
|
|
838
|
-
* @returns
|
|
839
|
-
*/
|
|
840
|
-
get<_OutType = any>(property: T[number] | typeof this.DEFAULT_ALLOWED_TO_READ_PROPERTIES[number]): _OutType;
|
|
841
|
-
/**
|
|
842
|
-
*
|
|
843
|
-
* This method is used to set the configuration property by name
|
|
844
|
-
* OR set multiple properties at once by passing an array of objects
|
|
845
|
-
*
|
|
846
|
-
* @param variables
|
|
847
|
-
*/
|
|
848
|
-
set(variables: Array<{
|
|
849
|
-
property: T[number] | A_TYPES__ConceptENVVariables[number];
|
|
850
|
-
value: any;
|
|
851
|
-
}>): any;
|
|
852
|
-
set(variables: Partial<Record<T[number] | A_TYPES__ConceptENVVariables[number], any>>): any;
|
|
853
|
-
set(property: T[number] | A_TYPES__ConceptENVVariables[number], value: any): any;
|
|
854
|
-
}
|
|
855
|
-
|
|
856
|
-
declare const A_LoggerEnvVariables: {
|
|
857
|
-
/**
|
|
858
|
-
* Sets the log level for the logger
|
|
859
|
-
*
|
|
860
|
-
* @example 'debug', 'info', 'warn', 'error'
|
|
861
|
-
*/
|
|
862
|
-
readonly A_LOGGER_LEVEL: "A_LOGGER_LEVEL";
|
|
863
|
-
/**
|
|
864
|
-
* Sets the default scope length for log messages
|
|
865
|
-
*
|
|
866
|
-
* @example 'A_LOGGER_DEFAULT_SCOPE_LENGTH'
|
|
867
|
-
*/
|
|
868
|
-
readonly A_LOGGER_DEFAULT_SCOPE_LENGTH: "A_LOGGER_DEFAULT_SCOPE_LENGTH";
|
|
869
|
-
};
|
|
870
|
-
type A_LoggerEnvVariablesType = (typeof A_LoggerEnvVariables)[keyof typeof A_LoggerEnvVariables][];
|
|
980
|
+
readonly A_LOGGER_DEFAULT_LOG_COLOR: "A_LOGGER_DEFAULT_LOG_COLOR";
|
|
981
|
+
};
|
|
982
|
+
type A_LoggerEnvVariablesType = (typeof A_LoggerEnvVariables)[keyof typeof A_LoggerEnvVariables][];
|
|
871
983
|
|
|
872
984
|
/**
|
|
873
985
|
* A_Logger - Advanced Logging Component with Scope-based Output Formatting
|
|
@@ -890,21 +1002,33 @@ type A_LoggerEnvVariablesType = (typeof A_LoggerEnvVariables)[keyof typeof A_Log
|
|
|
890
1002
|
*
|
|
891
1003
|
* @example
|
|
892
1004
|
* ```typescript
|
|
893
|
-
* // Basic usage with dependency injection
|
|
1005
|
+
* // Basic usage with dependency injection (uses deterministic colors based on scope name)
|
|
894
1006
|
* class MyService {
|
|
895
1007
|
* constructor(@A_Inject(A_Logger) private logger: A_Logger) {}
|
|
896
1008
|
*
|
|
897
1009
|
* doSomething() {
|
|
898
|
-
* this.logger.
|
|
899
|
-
* this.logger.
|
|
1010
|
+
* this.logger.info('Processing started'); // Uses scope-name-based colors, always shows
|
|
1011
|
+
* this.logger.debug('Debug information'); // Only shows when debug level enabled
|
|
1012
|
+
* this.logger.info('green', 'Custom message color'); // Green message, scope stays default
|
|
900
1013
|
* this.logger.warning('Something might be wrong');
|
|
901
1014
|
* this.logger.error(new Error('Something failed'));
|
|
902
1015
|
* }
|
|
903
1016
|
* }
|
|
904
1017
|
*
|
|
905
|
-
* //
|
|
906
|
-
*
|
|
907
|
-
*
|
|
1018
|
+
* // Same scope names will always get the same colors automatically
|
|
1019
|
+
* const logger1 = new A_Logger(new A_Scope({name: 'UserService'})); // Gets consistent colors
|
|
1020
|
+
* const logger2 = new A_Logger(new A_Scope({name: 'UserService'})); // Gets same colors as logger1
|
|
1021
|
+
*
|
|
1022
|
+
* // Configuration via environment variables or A_Config (overrides automatic selection)
|
|
1023
|
+
* process.env.A_LOGGER_DEFAULT_SCOPE_COLOR = 'magenta';
|
|
1024
|
+
* process.env.A_LOGGER_DEFAULT_LOG_COLOR = 'green';
|
|
1025
|
+
*
|
|
1026
|
+
* // Or through A_Config instance
|
|
1027
|
+
* const config = new A_Config({
|
|
1028
|
+
* A_LOGGER_DEFAULT_SCOPE_COLOR: 'red',
|
|
1029
|
+
* A_LOGGER_DEFAULT_LOG_COLOR: 'white'
|
|
1030
|
+
* });
|
|
1031
|
+
* const logger = new A_Logger(scope, config);
|
|
908
1032
|
* ```
|
|
909
1033
|
*/
|
|
910
1034
|
declare class A_Logger extends A_Component {
|
|
@@ -920,13 +1044,49 @@ declare class A_Logger extends A_Component {
|
|
|
920
1044
|
* This ensures all log messages align properly regardless of scope name length
|
|
921
1045
|
*/
|
|
922
1046
|
private readonly STANDARD_SCOPE_LENGTH;
|
|
1047
|
+
/**
|
|
1048
|
+
* Default color for the scope portion of log messages
|
|
1049
|
+
* This color is used for the scope brackets and content, and remains consistent
|
|
1050
|
+
* for this logger instance regardless of message color overrides
|
|
1051
|
+
*/
|
|
1052
|
+
private readonly DEFAULT_SCOPE_COLOR;
|
|
1053
|
+
/**
|
|
1054
|
+
* Default color for log message content when no explicit color is provided
|
|
1055
|
+
* This color is used for the message body when logging without specifying a color
|
|
1056
|
+
*/
|
|
1057
|
+
private readonly DEFAULT_LOG_COLOR;
|
|
923
1058
|
/**
|
|
924
1059
|
* Initialize A_Logger with dependency injection
|
|
1060
|
+
* Colors are configured through A_Config or generated randomly if not provided
|
|
925
1061
|
*
|
|
926
1062
|
* @param scope - The current scope context for message prefixing
|
|
927
|
-
* @param config - Optional configuration for log level filtering
|
|
1063
|
+
* @param config - Optional configuration for log level filtering and color settings
|
|
928
1064
|
*/
|
|
929
1065
|
constructor(scope: A_Scope, config?: A_Config<A_LoggerEnvVariablesType> | undefined);
|
|
1066
|
+
/**
|
|
1067
|
+
* Generate a simple hash from a string
|
|
1068
|
+
* Used to create deterministic color selection based on scope name
|
|
1069
|
+
*
|
|
1070
|
+
* @param str - The string to hash
|
|
1071
|
+
* @returns A numeric hash value
|
|
1072
|
+
*/
|
|
1073
|
+
private simpleHash;
|
|
1074
|
+
/**
|
|
1075
|
+
* Generate a deterministic color based on scope name
|
|
1076
|
+
* Same scope names will always get the same color, but uses safe color palette
|
|
1077
|
+
*
|
|
1078
|
+
* @param scopeName - The scope name to generate color for
|
|
1079
|
+
* @returns A color key from the safe colors palette
|
|
1080
|
+
*/
|
|
1081
|
+
private generateColorFromScopeName;
|
|
1082
|
+
/**
|
|
1083
|
+
* Generate a pair of complementary colors based on scope name
|
|
1084
|
+
* Ensures visual harmony between scope and message colors while being deterministic
|
|
1085
|
+
*
|
|
1086
|
+
* @param scopeName - The scope name to base colors on
|
|
1087
|
+
* @returns Object with scopeColor and logColor that work well together
|
|
1088
|
+
*/
|
|
1089
|
+
private generateComplementaryColorsFromScope;
|
|
930
1090
|
/**
|
|
931
1091
|
* Get the formatted scope length for consistent message alignment
|
|
932
1092
|
* Uses a standard length to ensure all messages align properly regardless of scope name
|
|
@@ -935,26 +1095,26 @@ declare class A_Logger extends A_Component {
|
|
|
935
1095
|
*/
|
|
936
1096
|
get scopeLength(): number;
|
|
937
1097
|
/**
|
|
938
|
-
* Get the formatted scope name with proper padding
|
|
939
|
-
* Ensures consistent width for all scope names in log output
|
|
1098
|
+
* Get the formatted scope name with proper padding, centered within the container
|
|
1099
|
+
* Ensures consistent width for all scope names in log output with centered alignment
|
|
940
1100
|
*
|
|
941
|
-
* @returns
|
|
1101
|
+
* @returns Centered and padded scope name for consistent formatting
|
|
942
1102
|
*/
|
|
943
1103
|
get formattedScope(): string;
|
|
944
1104
|
/**
|
|
945
1105
|
* Compile log arguments into formatted console output with colors and proper alignment
|
|
946
1106
|
*
|
|
947
1107
|
* This method handles the core formatting logic for all log messages:
|
|
948
|
-
* - Applies
|
|
1108
|
+
* - Applies separate colors for scope and message content
|
|
949
1109
|
* - Formats scope names with consistent padding
|
|
950
1110
|
* - Handles different data types appropriately
|
|
951
1111
|
* - Maintains proper indentation for multi-line content
|
|
952
1112
|
*
|
|
953
|
-
* @param
|
|
1113
|
+
* @param messageColor - The color key to apply to the message content
|
|
954
1114
|
* @param args - Variable arguments to format and display
|
|
955
1115
|
* @returns Array of formatted strings ready for console output
|
|
956
1116
|
*/
|
|
957
|
-
compile(
|
|
1117
|
+
compile(messageColor: keyof typeof this.COLORS, ...args: any[]): Array<string>;
|
|
958
1118
|
/**
|
|
959
1119
|
* Format an object for display with proper JSON indentation
|
|
960
1120
|
*
|
|
@@ -977,7 +1137,7 @@ declare class A_Logger extends A_Component {
|
|
|
977
1137
|
* Determine if a log message should be output based on configured log level
|
|
978
1138
|
*
|
|
979
1139
|
* Log level hierarchy:
|
|
980
|
-
* - debug: Shows all messages
|
|
1140
|
+
* - debug: Shows all messages (debug, info, warning, error)
|
|
981
1141
|
* - info: Shows info, warning, and error messages
|
|
982
1142
|
* - warn: Shows warning and error messages only
|
|
983
1143
|
* - error: Shows error messages only
|
|
@@ -986,24 +1146,60 @@ declare class A_Logger extends A_Component {
|
|
|
986
1146
|
* @param logMethod - The type of log method being called
|
|
987
1147
|
* @returns True if the message should be logged, false otherwise
|
|
988
1148
|
*/
|
|
989
|
-
protected shouldLog(logMethod: '
|
|
1149
|
+
protected shouldLog(logMethod: 'debug' | 'info' | 'warning' | 'error'): boolean;
|
|
1150
|
+
/**
|
|
1151
|
+
* Debug logging method with optional color specification
|
|
1152
|
+
* Only logs when debug level is enabled
|
|
1153
|
+
*
|
|
1154
|
+
* Supports two usage patterns:
|
|
1155
|
+
* 1. debug(message, ...args) - Uses instance's default log color
|
|
1156
|
+
* 2. debug(color, message, ...args) - Uses specified color for message content only
|
|
1157
|
+
*
|
|
1158
|
+
* Note: The scope color always remains the instance's default scope color,
|
|
1159
|
+
* only the message content color changes when explicitly specified.
|
|
1160
|
+
*
|
|
1161
|
+
* @param color - Optional color key or the first message argument
|
|
1162
|
+
* @param args - Additional arguments to log
|
|
1163
|
+
*
|
|
1164
|
+
* @example
|
|
1165
|
+
* ```typescript
|
|
1166
|
+
* logger.debug('Debug information'); // Uses instance default colors
|
|
1167
|
+
* logger.debug('gray', 'Debug message'); // Gray message, scope stays instance color
|
|
1168
|
+
* logger.debug('Processing user:', { id: 1, name: 'John' });
|
|
1169
|
+
* ```
|
|
1170
|
+
*/
|
|
1171
|
+
debug(color: keyof typeof this.COLORS, ...args: any[]): void;
|
|
1172
|
+
debug(...args: any[]): void;
|
|
990
1173
|
/**
|
|
991
|
-
*
|
|
1174
|
+
* Info logging method with optional color specification
|
|
1175
|
+
* Logs without any restrictions (always shows regardless of log level)
|
|
992
1176
|
*
|
|
993
1177
|
* Supports two usage patterns:
|
|
994
|
-
* 1.
|
|
995
|
-
* 2.
|
|
1178
|
+
* 1. info(message, ...args) - Uses instance's default log color
|
|
1179
|
+
* 2. info(color, message, ...args) - Uses specified color for message content only
|
|
1180
|
+
*
|
|
1181
|
+
* Note: The scope color always remains the instance's default scope color,
|
|
1182
|
+
* only the message content color changes when explicitly specified.
|
|
996
1183
|
*
|
|
997
1184
|
* @param color - Optional color key or the first message argument
|
|
998
1185
|
* @param args - Additional arguments to log
|
|
999
1186
|
*
|
|
1000
1187
|
* @example
|
|
1001
1188
|
* ```typescript
|
|
1002
|
-
* logger.
|
|
1003
|
-
* logger.
|
|
1004
|
-
* logger.
|
|
1189
|
+
* logger.info('Hello World'); // Uses instance default colors
|
|
1190
|
+
* logger.info('green', 'Success message'); // Green message, scope stays instance color
|
|
1191
|
+
* logger.info('Processing user:', { id: 1, name: 'John' });
|
|
1005
1192
|
* ```
|
|
1006
1193
|
*/
|
|
1194
|
+
info(color: keyof typeof this.COLORS, ...args: any[]): void;
|
|
1195
|
+
info(...args: any[]): void;
|
|
1196
|
+
/**
|
|
1197
|
+
* Legacy log method (kept for backward compatibility)
|
|
1198
|
+
* @deprecated Use info() method instead
|
|
1199
|
+
*
|
|
1200
|
+
* @param color - Optional color key or the first message argument
|
|
1201
|
+
* @param args - Additional arguments to log
|
|
1202
|
+
*/
|
|
1007
1203
|
log(color: keyof typeof this.COLORS, ...args: any[]): void;
|
|
1008
1204
|
log(...args: any[]): void;
|
|
1009
1205
|
/**
|
|
@@ -1081,6 +1277,365 @@ declare class A_Logger extends A_Component {
|
|
|
1081
1277
|
protected getTime(): string;
|
|
1082
1278
|
}
|
|
1083
1279
|
|
|
1280
|
+
type A_StateMachineTransitionParams<T = any> = {
|
|
1281
|
+
from: string;
|
|
1282
|
+
to: string;
|
|
1283
|
+
props?: T;
|
|
1284
|
+
};
|
|
1285
|
+
type A_StateMachineTransitionStorage<_ResultType extends any = any, _ParamsType extends any = any> = {
|
|
1286
|
+
from: string;
|
|
1287
|
+
to: string;
|
|
1288
|
+
} & A_Operation_Storage<_ResultType, A_StateMachineTransitionParams<_ParamsType>>;
|
|
1289
|
+
|
|
1290
|
+
declare class A_StateMachineTransition<_ParamsType = any, _ResultType = any> extends A_OperationContext<'a-state-machine-transition', A_StateMachineTransitionParams<_ParamsType>, _ResultType, A_StateMachineTransitionStorage<_ResultType, _ParamsType>> {
|
|
1291
|
+
constructor(params: A_StateMachineTransitionParams<_ParamsType>);
|
|
1292
|
+
get from(): string;
|
|
1293
|
+
get to(): string;
|
|
1294
|
+
}
|
|
1295
|
+
|
|
1296
|
+
/**
|
|
1297
|
+
* A_Command - Advanced Command Pattern Implementation
|
|
1298
|
+
*
|
|
1299
|
+
* A comprehensive command pattern implementation that encapsulates business logic
|
|
1300
|
+
* as executable commands with full lifecycle management, event handling, and
|
|
1301
|
+
* state persistence capabilities.
|
|
1302
|
+
*
|
|
1303
|
+
* ## Key Features
|
|
1304
|
+
* - **Structured Lifecycle**: Automatic progression through init → compile → execute → complete/fail
|
|
1305
|
+
* - **Event-Driven**: Subscribe to lifecycle events and emit custom events
|
|
1306
|
+
* - **State Persistence**: Full serialization/deserialization for cross-service communication
|
|
1307
|
+
* - **Type Safety**: Generic types for parameters, results, and custom events
|
|
1308
|
+
* - **Dependency Injection**: Integrated with A-Concept's DI system
|
|
1309
|
+
* - **Error Management**: Comprehensive error capture and handling
|
|
1310
|
+
* - **Execution Tracking**: Built-in timing and performance metrics
|
|
1311
|
+
*
|
|
1312
|
+
* ## Lifecycle Phases
|
|
1313
|
+
* 1. **CREATED** - Command instantiated but not initialized
|
|
1314
|
+
* 2. **INITIALIZED** - Execution scope and dependencies set up
|
|
1315
|
+
* 3. **COMPILED** - Ready for execution with all resources prepared
|
|
1316
|
+
* 4. **EXECUTING** - Currently running business logic
|
|
1317
|
+
* 5. **COMPLETED** - Successfully finished execution
|
|
1318
|
+
* 6. **FAILED** - Execution failed with errors captured
|
|
1319
|
+
*
|
|
1320
|
+
* @template InvokeType - Type definition for command parameters
|
|
1321
|
+
* @template ResultType - Type definition for command execution result
|
|
1322
|
+
* @template LifecycleEvents - Union type of custom lifecycle event names
|
|
1323
|
+
*
|
|
1324
|
+
* @example
|
|
1325
|
+
* ```typescript
|
|
1326
|
+
* // Define parameter and result types
|
|
1327
|
+
* interface UserCreateParams {
|
|
1328
|
+
* name: string;
|
|
1329
|
+
* email: string;
|
|
1330
|
+
* role: 'admin' | 'user';
|
|
1331
|
+
* }
|
|
1332
|
+
*
|
|
1333
|
+
* interface UserCreateResult {
|
|
1334
|
+
* userId: string;
|
|
1335
|
+
* success: boolean;
|
|
1336
|
+
* }
|
|
1337
|
+
*
|
|
1338
|
+
* // Create custom command
|
|
1339
|
+
* class CreateUserCommand extends A_Command<UserCreateParams, UserCreateResult> {}
|
|
1340
|
+
*
|
|
1341
|
+
* // Execute command
|
|
1342
|
+
* const command = new CreateUserCommand({
|
|
1343
|
+
* name: 'John Doe',
|
|
1344
|
+
* email: 'john@example.com',
|
|
1345
|
+
* role: 'user'
|
|
1346
|
+
* });
|
|
1347
|
+
*
|
|
1348
|
+
* scope.register(command);
|
|
1349
|
+
* await command.execute();
|
|
1350
|
+
*
|
|
1351
|
+
* console.log('Result:', command.result);
|
|
1352
|
+
* console.log('Status:', command.status);
|
|
1353
|
+
* ```
|
|
1354
|
+
*/
|
|
1355
|
+
declare class A_Command<InvokeType extends A_TYPES__Command_Init = A_TYPES__Command_Init, ResultType extends Record<string, any> = Record<string, any>, LifecycleEvents extends string | A_Command_Event = A_Command_Event> extends A_Entity<InvokeType, A_TYPES__Command_Serialized<InvokeType, ResultType>> {
|
|
1356
|
+
/**
|
|
1357
|
+
* Static command identifier derived from the class name
|
|
1358
|
+
* Used for command registration and serialization
|
|
1359
|
+
*/
|
|
1360
|
+
static get code(): string;
|
|
1361
|
+
/** The origin of the command, used to know has it been created from serialization or invoked */
|
|
1362
|
+
protected _origin: 'invoked' | 'serialized';
|
|
1363
|
+
/** Command execution scope for dependency injection and feature resolution */
|
|
1364
|
+
protected _executionScope: A_Scope;
|
|
1365
|
+
/** Result data produced by successful command execution */
|
|
1366
|
+
protected _result?: ResultType;
|
|
1367
|
+
/** Set of errors that occurred during command execution */
|
|
1368
|
+
protected _error: A_Error;
|
|
1369
|
+
/** Command initialization parameters */
|
|
1370
|
+
protected _params: InvokeType;
|
|
1371
|
+
/** Current lifecycle status of the command */
|
|
1372
|
+
protected _status: A_Command_Status;
|
|
1373
|
+
/** Map of event listeners organized by event name */
|
|
1374
|
+
protected _listeners: Map<LifecycleEvents | A_Command_Event, Set<A_TYPES__Command_Listener<InvokeType, ResultType, LifecycleEvents>>>;
|
|
1375
|
+
/** Timestamp when command execution started */
|
|
1376
|
+
protected _startTime?: Date;
|
|
1377
|
+
/** Timestamp when command execution ended */
|
|
1378
|
+
protected _endTime?: Date;
|
|
1379
|
+
/** Timestamp when command was created */
|
|
1380
|
+
protected _createdAt: Date;
|
|
1381
|
+
/**
|
|
1382
|
+
* Total execution duration in milliseconds
|
|
1383
|
+
*
|
|
1384
|
+
* - If completed/failed: Returns total time from start to end
|
|
1385
|
+
* - If currently executing: Returns elapsed time since start
|
|
1386
|
+
* - If not started: Returns undefined
|
|
1387
|
+
*/
|
|
1388
|
+
get duration(): number | undefined;
|
|
1389
|
+
/**
|
|
1390
|
+
* Idle time before execution started in milliseconds
|
|
1391
|
+
*
|
|
1392
|
+
* Time between command creation and execution start.
|
|
1393
|
+
* Useful for monitoring command queue performance.
|
|
1394
|
+
*/
|
|
1395
|
+
get idleTime(): number | undefined;
|
|
1396
|
+
/**
|
|
1397
|
+
* Command execution scope for dependency injection
|
|
1398
|
+
*
|
|
1399
|
+
* Provides access to components, services, and shared resources
|
|
1400
|
+
* during command execution. Inherits from the scope where the
|
|
1401
|
+
* command was registered.
|
|
1402
|
+
*/
|
|
1403
|
+
get scope(): A_Scope;
|
|
1404
|
+
/**
|
|
1405
|
+
* Unique command type identifier
|
|
1406
|
+
*
|
|
1407
|
+
* Derived from the class name and used for:
|
|
1408
|
+
* - Command registration and resolution
|
|
1409
|
+
* - Serialization and deserialization
|
|
1410
|
+
* - Logging and debugging
|
|
1411
|
+
*
|
|
1412
|
+
* @example 'create-user-command', 'process-order-command'
|
|
1413
|
+
*/
|
|
1414
|
+
get code(): string;
|
|
1415
|
+
/**
|
|
1416
|
+
* Current lifecycle status of the command
|
|
1417
|
+
*
|
|
1418
|
+
* Indicates the current phase in the command execution lifecycle.
|
|
1419
|
+
* Used to track progress and determine available operations.
|
|
1420
|
+
*/
|
|
1421
|
+
get status(): A_Command_Status;
|
|
1422
|
+
/**
|
|
1423
|
+
* Timestamp when the command was created
|
|
1424
|
+
*
|
|
1425
|
+
* Marks the initial instantiation time, useful for tracking
|
|
1426
|
+
* command age and queue performance metrics.
|
|
1427
|
+
*/
|
|
1428
|
+
get createdAt(): Date;
|
|
1429
|
+
/**
|
|
1430
|
+
* Timestamp when command execution started
|
|
1431
|
+
*
|
|
1432
|
+
* Undefined until execution begins. Used for calculating
|
|
1433
|
+
* execution duration and idle time.
|
|
1434
|
+
*/
|
|
1435
|
+
get startedAt(): Date | undefined;
|
|
1436
|
+
/**
|
|
1437
|
+
* Timestamp when command execution ended
|
|
1438
|
+
*
|
|
1439
|
+
* Set when command reaches COMPLETED or FAILED status.
|
|
1440
|
+
* Used for calculating total execution duration.
|
|
1441
|
+
*/
|
|
1442
|
+
get endedAt(): Date | undefined;
|
|
1443
|
+
/**
|
|
1444
|
+
* Result data produced by command execution
|
|
1445
|
+
*
|
|
1446
|
+
* Contains the output data from successful command execution.
|
|
1447
|
+
* Undefined until command completes successfully.
|
|
1448
|
+
*/
|
|
1449
|
+
get result(): ResultType | undefined;
|
|
1450
|
+
/**
|
|
1451
|
+
* Array of errors that occurred during execution
|
|
1452
|
+
*
|
|
1453
|
+
* Automatically wraps native errors in A_Error instances
|
|
1454
|
+
* for consistent error handling. Empty array if no errors occurred.
|
|
1455
|
+
*/
|
|
1456
|
+
get error(): A_Error | undefined;
|
|
1457
|
+
/**
|
|
1458
|
+
* Command initialization parameters
|
|
1459
|
+
*
|
|
1460
|
+
* Contains the input data used to create and configure the command.
|
|
1461
|
+
* These parameters are immutable during command execution.
|
|
1462
|
+
return new A_Error(err);
|
|
1463
|
+
}
|
|
1464
|
+
});
|
|
1465
|
+
}
|
|
1466
|
+
|
|
1467
|
+
/**
|
|
1468
|
+
* Command initialization parameters
|
|
1469
|
+
*
|
|
1470
|
+
* Contains the input data used to create and configure the command.
|
|
1471
|
+
* These parameters are immutable during command execution.
|
|
1472
|
+
*/
|
|
1473
|
+
get params(): InvokeType;
|
|
1474
|
+
/**
|
|
1475
|
+
* Indicates if the command has been processed (completed or failed)
|
|
1476
|
+
*
|
|
1477
|
+
* Returns true if the command has completed or failed, false otherwise.
|
|
1478
|
+
*/
|
|
1479
|
+
get isProcessed(): boolean;
|
|
1480
|
+
/**
|
|
1481
|
+
*
|
|
1482
|
+
* A-Command represents an executable command with a specific code and parameters.
|
|
1483
|
+
* It can be executed within a given scope and stores execution results and errors.
|
|
1484
|
+
*
|
|
1485
|
+
*
|
|
1486
|
+
* A-Command should be context independent and execution logic should be based on attached components
|
|
1487
|
+
*
|
|
1488
|
+
* @param code
|
|
1489
|
+
* @param params
|
|
1490
|
+
*/
|
|
1491
|
+
constructor(
|
|
1492
|
+
/**
|
|
1493
|
+
* Command invocation parameters
|
|
1494
|
+
*/
|
|
1495
|
+
params: InvokeType | A_TYPES__Command_Serialized<InvokeType, ResultType> | string);
|
|
1496
|
+
protected [A_StateMachineFeatures.onBeforeTransition](transition: A_StateMachineTransition, logger?: A_Logger, ...args: any[]): Promise<void>;
|
|
1497
|
+
protected [A_CommandTransitions.CREATED_TO_INITIALIZED](transition: A_StateMachineTransition, ...args: any[]): Promise<void>;
|
|
1498
|
+
protected [A_CommandTransitions.INITIALIZED_TO_EXECUTING](transition: A_StateMachineTransition, ...args: any[]): Promise<void>;
|
|
1499
|
+
protected [A_CommandTransitions.EXECUTING_TO_COMPLETED](transition: A_StateMachineTransition, ...args: any[]): Promise<void>;
|
|
1500
|
+
protected [A_CommandTransitions.EXECUTING_TO_FAILED](transition: A_StateMachineTransition, error: A_Error, ...args: any[]): Promise<void>;
|
|
1501
|
+
protected [A_CommandFeatures.onInit](stateMachine: A_StateMachine, ...args: any[]): Promise<void>;
|
|
1502
|
+
protected [A_CommandFeatures.onBeforeExecute](stateMachine: A_StateMachine, ...args: any[]): Promise<void>;
|
|
1503
|
+
protected [A_CommandFeatures.onExecute](...args: any[]): Promise<void>;
|
|
1504
|
+
protected [A_CommandFeatures.onAfterExecute](...args: any[]): Promise<void>;
|
|
1505
|
+
protected [A_CommandFeatures.onComplete](stateMachine: A_StateMachine, ...args: any[]): Promise<void>;
|
|
1506
|
+
protected [A_CommandFeatures.onFail](stateMachine: A_StateMachine, operation: A_OperationContext, ...args: any[]): Promise<void>;
|
|
1507
|
+
/**
|
|
1508
|
+
* Initializes the command before execution.
|
|
1509
|
+
*/
|
|
1510
|
+
init(): Promise<void>;
|
|
1511
|
+
/**
|
|
1512
|
+
* Executes the command logic.
|
|
1513
|
+
*/
|
|
1514
|
+
execute(): Promise<any>;
|
|
1515
|
+
/**
|
|
1516
|
+
* Marks the command as completed
|
|
1517
|
+
*/
|
|
1518
|
+
complete(result?: ResultType): Promise<void>;
|
|
1519
|
+
/**
|
|
1520
|
+
* Marks the command as failed
|
|
1521
|
+
*/
|
|
1522
|
+
fail(error?: A_Error): Promise<void>;
|
|
1523
|
+
/**
|
|
1524
|
+
* Registers an event listener for a specific event
|
|
1525
|
+
*
|
|
1526
|
+
* @param event
|
|
1527
|
+
* @param listener
|
|
1528
|
+
*/
|
|
1529
|
+
on(event: LifecycleEvents | A_Command_Event, listener: A_TYPES__Command_Listener<InvokeType, ResultType, LifecycleEvents>): void;
|
|
1530
|
+
/**
|
|
1531
|
+
* Removes an event listener for a specific event
|
|
1532
|
+
*
|
|
1533
|
+
* @param event
|
|
1534
|
+
* @param listener
|
|
1535
|
+
*/
|
|
1536
|
+
off(event: LifecycleEvents | A_Command_Event, listener: A_TYPES__Command_Listener<InvokeType, ResultType, LifecycleEvents>): void;
|
|
1537
|
+
/**
|
|
1538
|
+
* Emits an event to all registered listeners
|
|
1539
|
+
*
|
|
1540
|
+
* @param event
|
|
1541
|
+
*/
|
|
1542
|
+
emit(event: LifecycleEvents | A_Command_Event): void;
|
|
1543
|
+
/**
|
|
1544
|
+
* Allows to create a Command instance from new data
|
|
1545
|
+
*
|
|
1546
|
+
* @param newEntity
|
|
1547
|
+
*/
|
|
1548
|
+
fromNew(newEntity: InvokeType): void;
|
|
1549
|
+
/**
|
|
1550
|
+
* Allows to convert serialized data to Command instance
|
|
1551
|
+
*
|
|
1552
|
+
* [!] By default it omits params as they are not stored in the serialized data
|
|
1553
|
+
*
|
|
1554
|
+
* @param serialized
|
|
1555
|
+
*/
|
|
1556
|
+
fromJSON(serialized: A_TYPES__Command_Serialized<InvokeType, ResultType>): void;
|
|
1557
|
+
/**
|
|
1558
|
+
* Converts the Command instance to a plain object
|
|
1559
|
+
*
|
|
1560
|
+
* @returns
|
|
1561
|
+
*/
|
|
1562
|
+
toJSON(): A_TYPES__Command_Serialized<InvokeType, ResultType>;
|
|
1563
|
+
/**
|
|
1564
|
+
* Ensures that the command's execution scope inherits from the context scope
|
|
1565
|
+
*
|
|
1566
|
+
* Throws an error if the command is not bound to any context scope
|
|
1567
|
+
*/
|
|
1568
|
+
protected checkScopeInheritance(): void;
|
|
1569
|
+
}
|
|
1570
|
+
|
|
1571
|
+
declare class A_CommandError extends A_Error {
|
|
1572
|
+
static readonly CommandScopeBindingError = "A-Command Scope Binding Error";
|
|
1573
|
+
static readonly ExecutionError = "A-Command Execution Error";
|
|
1574
|
+
static readonly ResultProcessingError = "A-Command Result Processing Error";
|
|
1575
|
+
/**
|
|
1576
|
+
* Error indicating that the command was interrupted during execution
|
|
1577
|
+
*/
|
|
1578
|
+
static readonly CommandInterruptedError = "A-Command Interrupted Error";
|
|
1579
|
+
}
|
|
1580
|
+
|
|
1581
|
+
interface Ifspolyfill {
|
|
1582
|
+
readFileSync: (path: string, encoding: string) => string;
|
|
1583
|
+
existsSync: (path: string) => boolean;
|
|
1584
|
+
createReadStream: (path: string, options?: BufferEncoding) => any;
|
|
1585
|
+
}
|
|
1586
|
+
interface IcryptoInterface {
|
|
1587
|
+
createTextHash(text: string, algorithm: string): Promise<string>;
|
|
1588
|
+
createFileHash(filePath: string, algorithm: string): Promise<string>;
|
|
1589
|
+
}
|
|
1590
|
+
interface IhttpInterface {
|
|
1591
|
+
request: (options: any, callback?: (res: any) => void) => any;
|
|
1592
|
+
get: (url: string | any, callback?: (res: any) => void) => any;
|
|
1593
|
+
createServer: (requestListener?: (req: any, res: any) => void) => any;
|
|
1594
|
+
}
|
|
1595
|
+
interface IhttpsInterface {
|
|
1596
|
+
request: (options: any, callback?: (res: any) => void) => any;
|
|
1597
|
+
get: (url: string | any, callback?: (res: any) => void) => any;
|
|
1598
|
+
createServer: (options: any, requestListener?: (req: any, res: any) => void) => any;
|
|
1599
|
+
}
|
|
1600
|
+
interface IpathInterface {
|
|
1601
|
+
join: (...paths: string[]) => string;
|
|
1602
|
+
resolve: (...paths: string[]) => string;
|
|
1603
|
+
dirname: (path: string) => string;
|
|
1604
|
+
basename: (path: string, ext?: string) => string;
|
|
1605
|
+
extname: (path: string) => string;
|
|
1606
|
+
relative: (from: string, to: string) => string;
|
|
1607
|
+
normalize: (path: string) => string;
|
|
1608
|
+
isAbsolute: (path: string) => boolean;
|
|
1609
|
+
parse: (path: string) => any;
|
|
1610
|
+
format: (pathObject: any) => string;
|
|
1611
|
+
sep: string;
|
|
1612
|
+
delimiter: string;
|
|
1613
|
+
}
|
|
1614
|
+
interface IurlInterface {
|
|
1615
|
+
parse: (urlString: string) => any;
|
|
1616
|
+
format: (urlObject: any) => string;
|
|
1617
|
+
resolve: (from: string, to: string) => string;
|
|
1618
|
+
URL: typeof URL;
|
|
1619
|
+
URLSearchParams: typeof URLSearchParams;
|
|
1620
|
+
}
|
|
1621
|
+
interface IbufferInterface {
|
|
1622
|
+
from: (data: any, encoding?: string) => any;
|
|
1623
|
+
alloc: (size: number, fill?: any) => any;
|
|
1624
|
+
allocUnsafe: (size: number) => any;
|
|
1625
|
+
isBuffer: (obj: any) => boolean;
|
|
1626
|
+
concat: (list: any[], totalLength?: number) => any;
|
|
1627
|
+
}
|
|
1628
|
+
interface IprocessInterface {
|
|
1629
|
+
env: Record<string, string | undefined>;
|
|
1630
|
+
argv: string[];
|
|
1631
|
+
platform: string;
|
|
1632
|
+
version: string;
|
|
1633
|
+
versions: Record<string, string>;
|
|
1634
|
+
cwd: () => string;
|
|
1635
|
+
exit: (code?: number) => never;
|
|
1636
|
+
nextTick: (callback: Function, ...args: any[]) => void;
|
|
1637
|
+
}
|
|
1638
|
+
|
|
1084
1639
|
declare class A_FSPolyfillClass {
|
|
1085
1640
|
protected logger: A_Logger;
|
|
1086
1641
|
private _fs;
|
|
@@ -1276,7 +1831,7 @@ declare class A_ConfigError extends A_Error {
|
|
|
1276
1831
|
declare class ConfigReader extends A_Component {
|
|
1277
1832
|
protected polyfill: A_Polyfill;
|
|
1278
1833
|
constructor(polyfill: A_Polyfill);
|
|
1279
|
-
attachContext(container: A_Container, feature: A_Feature, config?: A_Config): Promise<void>;
|
|
1834
|
+
attachContext(container: A_Container, feature: A_Feature, config?: A_Config<any>): Promise<void>;
|
|
1280
1835
|
initialize(config: A_Config): Promise<void>;
|
|
1281
1836
|
/**
|
|
1282
1837
|
* Get the configuration property by Name
|
|
@@ -1432,53 +1987,110 @@ declare class A_ManifestError extends A_Error {
|
|
|
1432
1987
|
static readonly ManifestInitializationError = "A-Manifest Initialization Error";
|
|
1433
1988
|
}
|
|
1434
1989
|
|
|
1435
|
-
declare
|
|
1990
|
+
declare enum A_MemoryFeatures {
|
|
1436
1991
|
/**
|
|
1437
|
-
*
|
|
1992
|
+
* Allows to extend initialization logic and behavior
|
|
1438
1993
|
*/
|
|
1439
|
-
|
|
1994
|
+
onInit = "onInit",
|
|
1440
1995
|
/**
|
|
1441
|
-
*
|
|
1996
|
+
* Allows to extend destruction logic and behavior
|
|
1442
1997
|
*/
|
|
1443
|
-
|
|
1998
|
+
onDestroy = "onDestroy",
|
|
1444
1999
|
/**
|
|
1445
|
-
*
|
|
1446
|
-
*
|
|
1447
|
-
* @param initialValues
|
|
2000
|
+
* Allows to extend expiration logic and behavior
|
|
1448
2001
|
*/
|
|
1449
|
-
|
|
1450
|
-
get Errors(): Set<A_Error> | undefined;
|
|
2002
|
+
onExpire = "onExpire",
|
|
1451
2003
|
/**
|
|
1452
|
-
*
|
|
1453
|
-
|
|
1454
|
-
|
|
1455
|
-
|
|
2004
|
+
* Allows to extend error handling logic and behavior
|
|
2005
|
+
*/
|
|
2006
|
+
onError = "onError",
|
|
2007
|
+
/**
|
|
2008
|
+
* Allows to extend serialization logic and behavior
|
|
1456
2009
|
*/
|
|
1457
|
-
|
|
2010
|
+
onSerialize = "onSerialize",
|
|
1458
2011
|
/**
|
|
1459
|
-
*
|
|
1460
|
-
*
|
|
1461
|
-
* @param error
|
|
2012
|
+
* Allows to extend set operation logic and behavior
|
|
1462
2013
|
*/
|
|
1463
|
-
|
|
2014
|
+
onSet = "onSet",
|
|
1464
2015
|
/**
|
|
1465
|
-
*
|
|
2016
|
+
* Allows to extend get operation logic and behavior
|
|
2017
|
+
*/
|
|
2018
|
+
onGet = "onGet",
|
|
2019
|
+
/**
|
|
2020
|
+
* Allows to extend drop operation logic and behavior
|
|
2021
|
+
*/
|
|
2022
|
+
onDrop = "onDrop",
|
|
2023
|
+
/**
|
|
2024
|
+
* Allows to extend clear operation logic and behavior
|
|
2025
|
+
*/
|
|
2026
|
+
onClear = "onClear",
|
|
2027
|
+
/**
|
|
2028
|
+
* Allows to extend has operation logic and behavior
|
|
2029
|
+
*/
|
|
2030
|
+
onHas = "onHas"
|
|
2031
|
+
}
|
|
2032
|
+
|
|
2033
|
+
declare class A_MemoryContext<_MemoryType extends Record<string, any> = Record<string, any>, _SerializedType extends A_TYPES__Fragment_Serialized = A_TYPES__Fragment_Serialized> extends A_Fragment<_MemoryType, _MemoryType & _SerializedType> {
|
|
2034
|
+
set<K extends keyof _MemoryType>(param: 'error', value: A_Error): void;
|
|
2035
|
+
set<K extends keyof _MemoryType>(param: K, value: _MemoryType[K]): void;
|
|
2036
|
+
get<K extends keyof A_Error>(param: 'error'): A_Error | undefined;
|
|
2037
|
+
get<K extends keyof _MemoryType>(param: K): _MemoryType[K] | undefined;
|
|
2038
|
+
}
|
|
2039
|
+
|
|
2040
|
+
type A_MemoryOperations = 'get' | 'set' | 'drop' | 'clear' | 'has' | 'serialize';
|
|
2041
|
+
type A_MemoryOperationContext<T extends any = any> = A_OperationContext<A_MemoryOperations, {
|
|
2042
|
+
key: string;
|
|
2043
|
+
value?: any;
|
|
2044
|
+
}, T>;
|
|
2045
|
+
|
|
2046
|
+
declare class A_Memory<_StorageType extends Record<string, any> = Record<string, any>, _SerializedType extends Record<string, any> = Record<string, any>> extends A_Component {
|
|
2047
|
+
protected _ready?: Promise<void>;
|
|
2048
|
+
get ready(): Promise<void>;
|
|
2049
|
+
[A_MemoryFeatures.onError](...args: any[]): Promise<void>;
|
|
2050
|
+
[A_MemoryFeatures.onExpire](...args: any[]): Promise<void>;
|
|
2051
|
+
[A_MemoryFeatures.onInit](context: A_MemoryContext<_StorageType>, ...args: any[]): Promise<void>;
|
|
2052
|
+
[A_MemoryFeatures.onDestroy](context: A_MemoryContext<_StorageType>, ...args: any[]): Promise<void>;
|
|
2053
|
+
[A_MemoryFeatures.onGet](operation: A_MemoryOperationContext, context: A_MemoryContext<_StorageType>, ...args: any[]): Promise<void>;
|
|
2054
|
+
[A_MemoryFeatures.onHas](operation: A_MemoryOperationContext<boolean>, context: A_MemoryContext<_StorageType>, ...args: any[]): Promise<void>;
|
|
2055
|
+
[A_MemoryFeatures.onSet](operation: A_MemoryOperationContext, context: A_MemoryContext<_StorageType>, ...args: any[]): Promise<void>;
|
|
2056
|
+
[A_MemoryFeatures.onDrop](operation: A_MemoryOperationContext, context: A_MemoryContext<_StorageType>, ...args: any[]): Promise<void>;
|
|
2057
|
+
[A_MemoryFeatures.onClear](operation: A_MemoryOperationContext, context: A_MemoryContext<_StorageType>, ...args: any[]): Promise<void>;
|
|
2058
|
+
/**
|
|
2059
|
+
* Initializes the memory context
|
|
2060
|
+
*/
|
|
2061
|
+
init(): Promise<void>;
|
|
2062
|
+
/**
|
|
2063
|
+
* Destroys the memory context
|
|
1466
2064
|
*
|
|
1467
|
-
*
|
|
1468
|
-
*
|
|
2065
|
+
* This method is responsible for cleaning up any resources
|
|
2066
|
+
* used by the memory context and resetting its state.
|
|
1469
2067
|
*/
|
|
1470
|
-
|
|
2068
|
+
destroy(): Promise<void>;
|
|
2069
|
+
/**
|
|
2070
|
+
* Retrieves a value from the context memory
|
|
2071
|
+
*
|
|
2072
|
+
* @param key - memory key to retrieve
|
|
2073
|
+
* @returns - value associated with the key or undefined if not found
|
|
2074
|
+
*/
|
|
2075
|
+
get<K extends keyof _StorageType>(
|
|
1471
2076
|
/**
|
|
1472
2077
|
* Key to retrieve the value for
|
|
1473
2078
|
*/
|
|
1474
|
-
key: K):
|
|
2079
|
+
key: K): Promise<_StorageType[K] | undefined>;
|
|
2080
|
+
/**
|
|
2081
|
+
* Checks if a value exists in the context memory
|
|
2082
|
+
*
|
|
2083
|
+
* @param key - memory key to check
|
|
2084
|
+
* @returns - true if key exists, false otherwise
|
|
2085
|
+
*/
|
|
2086
|
+
has(key: keyof _StorageType): Promise<boolean>;
|
|
1475
2087
|
/**
|
|
1476
2088
|
* Saves a value in the context memory
|
|
1477
2089
|
*
|
|
1478
2090
|
* @param key
|
|
1479
2091
|
* @param value
|
|
1480
2092
|
*/
|
|
1481
|
-
set<K extends keyof
|
|
2093
|
+
set<K extends keyof _StorageType>(
|
|
1482
2094
|
/**
|
|
1483
2095
|
* Key to save the value under
|
|
1484
2096
|
*/
|
|
@@ -1486,25 +2098,23 @@ declare class A_Memory<_MemoryType extends Record<string, any> = Record<string,
|
|
|
1486
2098
|
/**
|
|
1487
2099
|
* Value to save
|
|
1488
2100
|
*/
|
|
1489
|
-
value:
|
|
2101
|
+
value: _StorageType[K]): Promise<void>;
|
|
1490
2102
|
/**
|
|
1491
2103
|
* Removes a value from the context memory by key
|
|
1492
2104
|
*
|
|
1493
2105
|
* @param key
|
|
1494
2106
|
*/
|
|
1495
|
-
drop(key: keyof
|
|
2107
|
+
drop(key: keyof _StorageType): Promise<void>;
|
|
1496
2108
|
/**
|
|
1497
2109
|
* Clears all stored values in the context memory
|
|
1498
2110
|
*/
|
|
1499
2111
|
clear(): Promise<void>;
|
|
1500
2112
|
/**
|
|
1501
|
-
*
|
|
1502
|
-
*
|
|
1503
|
-
* [!] By default uses all saved in memory values
|
|
2113
|
+
* Serializes the memory context to a JSON object
|
|
1504
2114
|
*
|
|
1505
|
-
* @returns
|
|
2115
|
+
* @returns - serialized memory object
|
|
1506
2116
|
*/
|
|
1507
|
-
toJSON(): _SerializedType
|
|
2117
|
+
toJSON(): Promise<_SerializedType>;
|
|
1508
2118
|
}
|
|
1509
2119
|
|
|
1510
2120
|
type A_UTILS_TYPES__ScheduleObjectConfig = {
|
|
@@ -1615,4 +2225,4 @@ declare class A_Deferred<T> {
|
|
|
1615
2225
|
reject(reason?: any): void;
|
|
1616
2226
|
}
|
|
1617
2227
|
|
|
1618
|
-
export {
|
|
2228
|
+
export { A_CONSTANTS__CONFIG_ENV_VARIABLES, A_CONSTANTS__CONFIG_ENV_VARIABLES_ARRAY, A_Channel, A_ChannelError, A_ChannelFeatures, A_ChannelRequestStatuses, A_Command, A_CommandError, A_CommandFeatures, A_CommandTransitions, type A_Command_Event, A_Command_Status, A_Config, A_ConfigError, A_ConfigLoader, A_Deferred, A_Logger, A_Manifest, A_ManifestChecker, A_ManifestError, A_Memory, A_Polyfill, A_Schedule, A_ScheduleObject, type A_TYPES__Command_Constructor, type A_TYPES__Command_Init, type A_TYPES__Command_Listener, type A_TYPES__Command_Serialized, type A_TYPES__ConfigContainerConstructor, type A_TYPES__ConfigENVVariables, A_TYPES__ConfigFeature, type A_UTILS_TYPES__ManifestQuery, type A_UTILS_TYPES__ManifestRule, type A_UTILS_TYPES__Manifest_AllowedComponents, type A_UTILS_TYPES__Manifest_ComponentLevelConfig, type A_UTILS_TYPES__Manifest_Init, type A_UTILS_TYPES__Manifest_MethodLevelConfig, type A_UTILS_TYPES__Manifest_Rules, type A_UTILS_TYPES__ScheduleObjectCallback, type A_UTILS_TYPES__ScheduleObjectConfig, ConfigReader, ENVConfigReader, FileConfigReader, type IbufferInterface, type IcryptoInterface, type Ifspolyfill, type IhttpInterface, type IhttpsInterface, type IpathInterface, type IprocessInterface, type IurlInterface };
|