@adaas/a-utils 0.1.20 → 0.1.22
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 +8 -8
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.mts +180 -20
- package/dist/index.d.ts +180 -20
- package/dist/index.mjs +8 -8
- package/dist/index.mjs.map +1 -1
- package/package.json +2 -2
- package/src/index.ts +28 -2
- package/src/lib/A-Command/A-Command.entity.ts +21 -4
- package/src/lib/A-Command/A-Command.types.ts +19 -11
- package/src/lib/A-Config/A-Config.context.ts +38 -59
- package/src/lib/A-Config/components/ConfigReader.component.ts +17 -15
- package/src/lib/A-Execution/A-Execution.context.ts +67 -0
- package/src/lib/A-Execution/A-Execution.types.ts +0 -0
- package/src/lib/A-Memory/A-Memory.component.ts +1 -1
- package/src/lib/A-Memory/A-Memory.context.ts +18 -9
- package/src/lib/A-Memory/A-Memory.types.ts +12 -1
- package/src/lib/A-Operation/A-Operation.context.ts +3 -2
- package/tests/A-Config.test.ts +5 -11
- package/tests/A-Manifest.test.ts +3 -3
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@adaas/a-utils",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.22",
|
|
4
4
|
"description": "A-Utils is a set of utilities that are used across the ADAAS ecosystem. This package is designed to be a collection of utilities that are used across the ADAAS ecosystem.",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"main": "./dist/index.cjs",
|
|
@@ -80,7 +80,7 @@
|
|
|
80
80
|
"build": "tsup --config tsup.config.ts"
|
|
81
81
|
},
|
|
82
82
|
"dependencies": {
|
|
83
|
-
"@adaas/a-concept": "^0.1.
|
|
83
|
+
"@adaas/a-concept": "^0.1.46"
|
|
84
84
|
},
|
|
85
85
|
"devDependencies": {
|
|
86
86
|
"@types/chai": "^4.3.14",
|
package/src/index.ts
CHANGED
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
// A-Channel Components
|
|
4
4
|
// ============================================================================
|
|
5
5
|
export { A_Channel } from './lib/A-Channel/A-Channel.component';
|
|
6
|
+
export { A_ChannelRequest } from './lib/A-Channel/A-ChannelRequest.context';
|
|
6
7
|
export { A_ChannelError } from './lib/A-Channel/A-Channel.error';
|
|
7
8
|
export * from './lib/A-Channel/A-Channel.types';
|
|
8
9
|
export * from './lib/A-Channel/A-Channel.constants';
|
|
@@ -34,7 +35,10 @@ export * from './lib/A-Config/A-Config.constants';
|
|
|
34
35
|
// A-Logger Components
|
|
35
36
|
// ============================================================================
|
|
36
37
|
export { A_Logger } from './lib/A-Logger/A-Logger.component';
|
|
37
|
-
|
|
38
|
+
export * from './lib/A-Logger/A-Logger.types';
|
|
39
|
+
export * from './lib/A-Logger/A-Logger.constants';
|
|
40
|
+
export * from './lib/A-Logger/A-Logger.env';
|
|
41
|
+
|
|
38
42
|
|
|
39
43
|
|
|
40
44
|
// ============================================================================
|
|
@@ -50,7 +54,22 @@ export * from './lib/A-Manifest/A-Manifest.types';
|
|
|
50
54
|
// A-Memory Components
|
|
51
55
|
// ============================================================================
|
|
52
56
|
export { A_Memory } from './lib/A-Memory/A-Memory.component';
|
|
57
|
+
export { A_MemoryContext } from './lib/A-Memory/A-Memory.context';
|
|
58
|
+
export { A_MemoryError } from './lib/A-Memory/A-Memory.error';
|
|
59
|
+
export * from './lib/A-Memory/A-Memory.constants';
|
|
60
|
+
export * from './lib/A-Memory/A-Memory.types';
|
|
53
61
|
|
|
62
|
+
// ============================================================================
|
|
63
|
+
// A-Execution Components
|
|
64
|
+
// ============================================================================
|
|
65
|
+
export { A_ExecutionContext } from './lib/A-Execution/A-Execution.context';
|
|
66
|
+
// export * from './lib/A-Execution/A-Execution.types';
|
|
67
|
+
|
|
68
|
+
// ============================================================================
|
|
69
|
+
// A-Operation Components
|
|
70
|
+
// ============================================================================
|
|
71
|
+
export { A_OperationContext } from './lib/A-Operation/A-Operation.context';
|
|
72
|
+
export * from './lib/A-Operation/A-Operation.types';
|
|
54
73
|
|
|
55
74
|
// ============================================================================
|
|
56
75
|
// A-Polyfill Components
|
|
@@ -68,4 +87,11 @@ export { A_Deferred } from './lib/A-Schedule/A-Deferred.class';
|
|
|
68
87
|
export * from './lib/A-Schedule/A-Schedule.types';
|
|
69
88
|
|
|
70
89
|
|
|
71
|
-
|
|
90
|
+
// ============================================================================
|
|
91
|
+
// A-State Machine Components
|
|
92
|
+
// ============================================================================
|
|
93
|
+
export { A_StateMachine } from './lib/A-StateMachine/A-StateMachine.component';
|
|
94
|
+
export { A_StateMachineTransition } from './lib/A-StateMachine/A-StateMachineTransition.context';
|
|
95
|
+
export { A_StateMachineError } from './lib/A-StateMachine/A-StateMachine.error';
|
|
96
|
+
export * from './lib/A-StateMachine/A-StateMachine.types';
|
|
97
|
+
export * from './lib/A-StateMachine/A-StateMachine.constants';
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import {
|
|
2
|
+
A_Command_ExecutionContext,
|
|
2
3
|
A_TYPES__Command_Init,
|
|
3
4
|
A_TYPES__Command_Listener,
|
|
4
5
|
A_TYPES__Command_Serialized
|
|
@@ -9,13 +10,13 @@ import {
|
|
|
9
10
|
A_Command_Status,
|
|
10
11
|
A_CommandTransitions
|
|
11
12
|
} from "./A-Command.constants";
|
|
12
|
-
import {
|
|
13
|
+
import { A_Context, A_Dependency, A_Entity, A_Error, A_Feature, A_Inject, A_Scope } from "@adaas/a-concept";
|
|
13
14
|
import { A_CommandError } from "./A-Command.error";
|
|
14
|
-
import { A_OperationContext } from "../A-Operation/A-Operation.context";
|
|
15
15
|
import { A_StateMachine } from "../A-StateMachine/A-StateMachine.component";
|
|
16
16
|
import { A_StateMachineFeatures } from "../A-StateMachine/A-StateMachine.constants";
|
|
17
17
|
import { A_Logger } from "../A-Logger/A-Logger.component";
|
|
18
18
|
import { A_StateMachineTransition } from "../A-StateMachine/A-StateMachineTransition.context";
|
|
19
|
+
import { A_ExecutionContext } from "../A-Execution/A-Execution.context";
|
|
19
20
|
|
|
20
21
|
/**
|
|
21
22
|
* A_Command - Advanced Command Pattern Implementation
|
|
@@ -173,6 +174,12 @@ export class A_Command<
|
|
|
173
174
|
get scope(): A_Scope {
|
|
174
175
|
return this._executionScope;
|
|
175
176
|
}
|
|
177
|
+
/**
|
|
178
|
+
* Execution context associated with the command
|
|
179
|
+
*/
|
|
180
|
+
get context(): A_ExecutionContext<A_Command_ExecutionContext<InvokeType, ResultType>> {
|
|
181
|
+
return this.scope.resolve(A_ExecutionContext<A_Command_ExecutionContext<InvokeType, ResultType>>)!;
|
|
182
|
+
}
|
|
176
183
|
|
|
177
184
|
/**
|
|
178
185
|
* Unique command type identifier
|
|
@@ -438,7 +445,7 @@ export class A_Command<
|
|
|
438
445
|
protected async [A_CommandFeatures.onFail](
|
|
439
446
|
@A_Dependency.Required()
|
|
440
447
|
@A_Inject(A_StateMachine) stateMachine: A_StateMachine,
|
|
441
|
-
@A_Inject(
|
|
448
|
+
@A_Inject(A_ExecutionContext) operation: A_ExecutionContext<A_Command_ExecutionContext<InvokeType, ResultType>>,
|
|
442
449
|
...args: any[]
|
|
443
450
|
): Promise<void> {
|
|
444
451
|
await stateMachine.transition(A_Command_Status.EXECUTING, A_Command_Status.FAILED);
|
|
@@ -464,7 +471,7 @@ export class A_Command<
|
|
|
464
471
|
try {
|
|
465
472
|
this.checkScopeInheritance();
|
|
466
473
|
|
|
467
|
-
const context = new
|
|
474
|
+
const context = new A_ExecutionContext<A_Command_ExecutionContext<InvokeType, ResultType>>('execute-command');
|
|
468
475
|
|
|
469
476
|
this.scope.register(context);
|
|
470
477
|
|
|
@@ -536,6 +543,16 @@ export class A_Command<
|
|
|
536
543
|
|
|
537
544
|
/**
|
|
538
545
|
* Marks the command as completed
|
|
546
|
+
*
|
|
547
|
+
*
|
|
548
|
+
* Calling This method will set the command status to COMPLETED, record the end time,
|
|
549
|
+
* store the result, emit the onComplete event, and destroy the execution scope.
|
|
550
|
+
*
|
|
551
|
+
* [!] After Calling this method, the command is considered fully processed And further processing will be INTERRUPTED.
|
|
552
|
+
* [!] If the command is already processed (COMPLETED or FAILED), this method does nothing.
|
|
553
|
+
* [!] This method can be called with optional result data to store with the command.
|
|
554
|
+
*
|
|
555
|
+
* @param result - Optional result data to store with the command
|
|
539
556
|
*/
|
|
540
557
|
async complete(result?: ResultType) {
|
|
541
558
|
if (this.isProcessed) return;
|
|
@@ -58,55 +58,55 @@ export type A_TYPES__Command_Serialized<
|
|
|
58
58
|
* Unique identifier for the command type (derived from class name)
|
|
59
59
|
*/
|
|
60
60
|
code: string;
|
|
61
|
-
|
|
61
|
+
|
|
62
62
|
/**
|
|
63
63
|
* Current execution status of the command
|
|
64
64
|
*/
|
|
65
65
|
status: A_Command_Status;
|
|
66
|
-
|
|
66
|
+
|
|
67
67
|
/**
|
|
68
68
|
* Parameters used to initialize the command
|
|
69
69
|
*/
|
|
70
70
|
params: ParamsType;
|
|
71
|
-
|
|
71
|
+
|
|
72
72
|
// --------------------------------------------------
|
|
73
73
|
// Timing Information
|
|
74
74
|
// --------------------------------------------------
|
|
75
|
-
|
|
75
|
+
|
|
76
76
|
/**
|
|
77
77
|
* ISO timestamp when the command was created
|
|
78
78
|
*/
|
|
79
79
|
createdAt: string;
|
|
80
|
-
|
|
80
|
+
|
|
81
81
|
/**
|
|
82
82
|
* ISO timestamp when command execution started (if started)
|
|
83
83
|
*/
|
|
84
84
|
startedAt?: string;
|
|
85
|
-
|
|
85
|
+
|
|
86
86
|
/**
|
|
87
87
|
* ISO timestamp when command execution ended (if completed/failed)
|
|
88
88
|
*/
|
|
89
89
|
endedAt?: string;
|
|
90
|
-
|
|
90
|
+
|
|
91
91
|
/**
|
|
92
92
|
* Total execution duration in milliseconds (if completed/failed)
|
|
93
93
|
*/
|
|
94
94
|
duration?: number;
|
|
95
|
-
|
|
95
|
+
|
|
96
96
|
/**
|
|
97
97
|
* Time between creation and execution start in milliseconds
|
|
98
98
|
*/
|
|
99
99
|
idleTime?: number;
|
|
100
|
-
|
|
100
|
+
|
|
101
101
|
// --------------------------------------------------
|
|
102
102
|
// Execution Results
|
|
103
103
|
// --------------------------------------------------
|
|
104
|
-
|
|
104
|
+
|
|
105
105
|
/**
|
|
106
106
|
* Result data produced by successful command execution
|
|
107
107
|
*/
|
|
108
108
|
result?: ResultType;
|
|
109
|
-
|
|
109
|
+
|
|
110
110
|
/**
|
|
111
111
|
* Array of serialized errors that occurred during execution
|
|
112
112
|
*/
|
|
@@ -146,3 +146,11 @@ export type A_TYPES__Command_Listener<
|
|
|
146
146
|
|
|
147
147
|
|
|
148
148
|
|
|
149
|
+
|
|
150
|
+
export type A_Command_ExecutionContext<
|
|
151
|
+
InvokeType extends A_TYPES__Command_Init = A_TYPES__Command_Init,
|
|
152
|
+
ResultType extends Record<string, any> = Record<string, any>,
|
|
153
|
+
> = {
|
|
154
|
+
result: ResultType,
|
|
155
|
+
params: InvokeType,
|
|
156
|
+
}
|
|
@@ -1,20 +1,21 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { A_CONSTANTS__DEFAULT_ENV_VARIABLES_ARRAY, A_FormatterHelper, A_TYPES__ConceptENVVariables } from "@adaas/a-concept";
|
|
2
2
|
import { A_TYPES__ConfigContainerConstructor } from "./A-Config.types";
|
|
3
|
+
import { A_ExecutionContext } from "../A-Execution/A-Execution.context";
|
|
3
4
|
import { A_CONSTANTS__CONFIG_ENV_VARIABLES_ARRAY } from "./A-Config.constants";
|
|
5
|
+
import { A_ConfigError } from "./A-Config.error";
|
|
4
6
|
|
|
5
7
|
|
|
6
8
|
export class A_Config<
|
|
7
9
|
T extends Array<string | A_TYPES__ConceptENVVariables[number]> = any[]
|
|
8
|
-
> extends
|
|
9
|
-
[key in T[number]]: any
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
CONFIG_PROPERTIES!: T;
|
|
10
|
+
> extends A_ExecutionContext<
|
|
11
|
+
{ [key in T[number]]: any; } & {
|
|
12
|
+
[key in typeof A_CONSTANTS__DEFAULT_ENV_VARIABLES_ARRAY[number]]: any
|
|
13
|
+
} & {
|
|
14
|
+
[key in typeof A_CONSTANTS__CONFIG_ENV_VARIABLES_ARRAY[number]]: any
|
|
15
|
+
}
|
|
16
|
+
> {
|
|
17
|
+
protected _strict: boolean;
|
|
18
|
+
protected _configProperties!: T;
|
|
18
19
|
|
|
19
20
|
protected DEFAULT_ALLOWED_TO_READ_PROPERTIES = [
|
|
20
21
|
...A_CONSTANTS__DEFAULT_ENV_VARIABLES_ARRAY,
|
|
@@ -25,60 +26,45 @@ export class A_Config<
|
|
|
25
26
|
constructor(
|
|
26
27
|
config: Partial<A_TYPES__ConfigContainerConstructor<T>>
|
|
27
28
|
) {
|
|
28
|
-
super(
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
this.CONFIG_PROPERTIES = this.config.variables ? this.config.variables : [] as any as T;
|
|
39
|
-
|
|
40
|
-
this.config.variables.forEach((variable) => {
|
|
41
|
-
this.VARIABLES.set(
|
|
42
|
-
A_FormatterHelper.toUpperSnakeCase(variable),
|
|
43
|
-
this.config.defaults[variable]
|
|
29
|
+
super('a-config');
|
|
30
|
+
|
|
31
|
+
this._strict = config.strict ?? false;
|
|
32
|
+
this._configProperties = config.variables ?? [] as any;
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
for (const key in config.defaults) {
|
|
36
|
+
this.set(
|
|
37
|
+
A_FormatterHelper.toUpperSnakeCase(key),
|
|
38
|
+
config.defaults[key as T[number]]
|
|
44
39
|
);
|
|
45
|
-
}
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
get strict(): boolean {
|
|
45
|
+
return this._strict;
|
|
46
46
|
}
|
|
47
47
|
|
|
48
48
|
|
|
49
49
|
/**
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
50
|
+
* This method is used to get the configuration property by name
|
|
51
|
+
*
|
|
52
|
+
* @param property
|
|
53
|
+
* @returns
|
|
54
|
+
*/
|
|
55
55
|
get<K extends T[number]>(
|
|
56
56
|
property: K | typeof this.DEFAULT_ALLOWED_TO_READ_PROPERTIES[number]
|
|
57
57
|
): { [key in T[number]]: any; }[K] | undefined {
|
|
58
|
-
if (this.
|
|
58
|
+
if (this._configProperties.includes(property as any)
|
|
59
59
|
|| this.DEFAULT_ALLOWED_TO_READ_PROPERTIES.includes(property as any)
|
|
60
|
-
|| !
|
|
60
|
+
|| !this._strict
|
|
61
61
|
)
|
|
62
|
-
return
|
|
63
|
-
|
|
64
|
-
throw new Error('Property not exists or not allowed to read') as never;
|
|
65
|
-
// return this.concept.Errors.throw(A_SDK_CONSTANTS__ERROR_CODES.CONFIGURATION_PROPERTY_NOT_EXISTS_OR_NOT_ALLOWED_TO_READ) as never;
|
|
62
|
+
return super.get(A_FormatterHelper.toUpperSnakeCase(property));
|
|
66
63
|
|
|
64
|
+
throw new A_ConfigError('Property not exists or not allowed to read');
|
|
67
65
|
}
|
|
68
66
|
|
|
69
67
|
|
|
70
|
-
// get<_OutType = any>(
|
|
71
|
-
// property: T[number] | typeof this.DEFAULT_ALLOWED_TO_READ_PROPERTIES[number] | string
|
|
72
|
-
// ): _OutType {
|
|
73
|
-
// if (this.CONFIG_PROPERTIES.includes(property as any)
|
|
74
|
-
// || this.DEFAULT_ALLOWED_TO_READ_PROPERTIES.includes(property as any)
|
|
75
|
-
// || !(this.config.strict)
|
|
76
|
-
// )
|
|
77
|
-
// return this.VARIABLES.get(A_FormatterHelper.toUpperSnakeCase(property)) as _OutType;
|
|
78
|
-
|
|
79
|
-
// throw new Error('Property not exists or not allowed to read') as never;
|
|
80
|
-
// // return this.concept.Errors.throw(A_SDK_CONSTANTS__ERROR_CODES.CONFIGURATION_PROPERTY_NOT_EXISTS_OR_NOT_ALLOWED_TO_READ) as never;
|
|
81
|
-
// }
|
|
82
68
|
/**
|
|
83
69
|
*
|
|
84
70
|
* This method is used to set the configuration property by name
|
|
@@ -118,14 +104,7 @@ export class A_Config<
|
|
|
118
104
|
}));
|
|
119
105
|
|
|
120
106
|
for (const { property, value } of array) {
|
|
121
|
-
|
|
122
|
-
let targetValue = value
|
|
123
|
-
? value
|
|
124
|
-
: this.config?.defaults
|
|
125
|
-
? this.config.defaults[property as T[number]]
|
|
126
|
-
: undefined;
|
|
127
|
-
|
|
128
|
-
this.VARIABLES.set(A_FormatterHelper.toUpperSnakeCase(property), targetValue);
|
|
107
|
+
super.set(A_FormatterHelper.toUpperSnakeCase(property), value);
|
|
129
108
|
}
|
|
130
109
|
}
|
|
131
110
|
}
|
|
@@ -1,14 +1,21 @@
|
|
|
1
|
-
import { A_Component, A_Concept, A_CONSTANTS__DEFAULT_ENV_VARIABLES_ARRAY, A_Container, A_Feature, A_Inject } from "@adaas/a-concept";
|
|
1
|
+
import { A_Component, A_Concept, A_CONSTANTS__DEFAULT_ENV_VARIABLES_ARRAY, A_Container, A_Context, A_Dependency, A_Feature, A_Inject, A_Scope } from "@adaas/a-concept";
|
|
2
2
|
import { A_Config } from "../A-Config.context";
|
|
3
3
|
import { A_CONSTANTS__CONFIG_ENV_VARIABLES_ARRAY } from "../A-Config.constants";
|
|
4
4
|
import { A_Polyfill } from "../../A-Polyfill/A-Polyfill.component";
|
|
5
|
+
import { A_Memory } from "../../A-Memory/A-Memory.component";
|
|
5
6
|
|
|
6
7
|
/**
|
|
7
8
|
* Config Reader
|
|
8
9
|
*/
|
|
9
10
|
export class ConfigReader extends A_Component {
|
|
10
11
|
|
|
12
|
+
protected DEFAULT_ALLOWED_TO_READ_PROPERTIES = [
|
|
13
|
+
...A_CONSTANTS__DEFAULT_ENV_VARIABLES_ARRAY,
|
|
14
|
+
...A_CONSTANTS__CONFIG_ENV_VARIABLES_ARRAY
|
|
15
|
+
];
|
|
16
|
+
|
|
11
17
|
constructor(
|
|
18
|
+
@A_Dependency.Required()
|
|
12
19
|
@A_Inject(A_Polyfill) protected polyfill: A_Polyfill,
|
|
13
20
|
) {
|
|
14
21
|
super();
|
|
@@ -17,15 +24,11 @@ export class ConfigReader extends A_Component {
|
|
|
17
24
|
@A_Concept.Load()
|
|
18
25
|
async attachContext(
|
|
19
26
|
@A_Inject(A_Container) container: A_Container,
|
|
20
|
-
@A_Inject(
|
|
27
|
+
@A_Inject(A_Scope) context: A_Scope,
|
|
21
28
|
@A_Inject(A_Config) config?: A_Config<any>,
|
|
22
29
|
) {
|
|
23
30
|
if (!config) {
|
|
24
|
-
config= new A_Config({
|
|
25
|
-
variables: [
|
|
26
|
-
...A_CONSTANTS__DEFAULT_ENV_VARIABLES_ARRAY,
|
|
27
|
-
...A_CONSTANTS__CONFIG_ENV_VARIABLES_ARRAY
|
|
28
|
-
] as const,
|
|
31
|
+
config = new A_Config({
|
|
29
32
|
defaults: {}
|
|
30
33
|
});
|
|
31
34
|
|
|
@@ -39,19 +42,16 @@ export class ConfigReader extends A_Component {
|
|
|
39
42
|
|
|
40
43
|
@A_Concept.Load()
|
|
41
44
|
async initialize(
|
|
45
|
+
@A_Dependency.Required()
|
|
42
46
|
@A_Inject(A_Config) config: A_Config,
|
|
43
47
|
) {
|
|
44
|
-
const data = await this.read(
|
|
45
|
-
...config.CONFIG_PROPERTIES,
|
|
46
|
-
...A_CONSTANTS__DEFAULT_ENV_VARIABLES_ARRAY,
|
|
47
|
-
...A_CONSTANTS__CONFIG_ENV_VARIABLES_ARRAY
|
|
48
|
-
]);
|
|
48
|
+
const data = await this.read();
|
|
49
49
|
|
|
50
|
-
|
|
50
|
+
for (const key in data) {
|
|
51
|
+
config.set(key, data[key]);
|
|
52
|
+
}
|
|
51
53
|
}
|
|
52
54
|
|
|
53
|
-
|
|
54
|
-
|
|
55
55
|
/**
|
|
56
56
|
* Get the configuration property by Name
|
|
57
57
|
* @param property
|
|
@@ -79,6 +79,8 @@ export class ConfigReader extends A_Component {
|
|
|
79
79
|
* @returns {string|null} - The path to the root directory or null if package.json is not found
|
|
80
80
|
*/
|
|
81
81
|
protected async getProjectRoot(startPath = __dirname) {
|
|
82
|
+
const process = await this.polyfill.process();
|
|
83
|
+
|
|
82
84
|
return process.cwd();
|
|
83
85
|
}
|
|
84
86
|
}
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import { A_Fragment, A_Meta, A_TYPES__Fragment_Serialized } from "@adaas/a-concept";
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
export class A_ExecutionContext<
|
|
6
|
+
_MetaType extends Record<string, any> = Record<string, any>,
|
|
7
|
+
_SerializedType extends Record<string, any> = Record<string, any>
|
|
8
|
+
> extends A_Fragment {
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
protected _meta: A_Meta<_MetaType, _SerializedType>;
|
|
12
|
+
|
|
13
|
+
constructor(
|
|
14
|
+
name: string,
|
|
15
|
+
defaults?: Partial<_MetaType>,
|
|
16
|
+
) {
|
|
17
|
+
super({ name });
|
|
18
|
+
this._meta = new A_Meta<_MetaType, _SerializedType>();
|
|
19
|
+
|
|
20
|
+
for (const key in defaults) {
|
|
21
|
+
this._meta.set(key as keyof _MetaType, defaults[key as keyof _MetaType] as _MetaType[keyof _MetaType]);
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
[Symbol.iterator](): Iterator<[keyof _MetaType, _MetaType[keyof _MetaType]]> {
|
|
27
|
+
return this._meta[Symbol.iterator]();
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
get meta(): A_Meta<_MetaType> {
|
|
32
|
+
return this._meta;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
get(key: keyof _MetaType): _MetaType[keyof _MetaType] | undefined {
|
|
37
|
+
return this._meta.get(key);
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
set(key: keyof _MetaType, value: _MetaType[keyof _MetaType]): void {
|
|
41
|
+
this._meta.set(key, value);
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
has(key: keyof _MetaType): boolean {
|
|
45
|
+
return this._meta.has(key);
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
drop(key: keyof _MetaType): void {
|
|
49
|
+
this._meta.delete(key);
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
clear(): void {
|
|
53
|
+
this._meta.clear();
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
|
|
57
|
+
toRaw(): _SerializedType {
|
|
58
|
+
return this._meta.toJSON();
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
toJSON(): A_TYPES__Fragment_Serialized {
|
|
62
|
+
return {
|
|
63
|
+
name: this.name,
|
|
64
|
+
...this.meta.toJSON(),
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
}
|
|
File without changes
|
|
@@ -7,20 +7,29 @@ import { error } from "console";
|
|
|
7
7
|
export class A_MemoryContext<
|
|
8
8
|
_MemoryType extends Record<string, any> = Record<string, any>,
|
|
9
9
|
_SerializedType extends A_TYPES__Fragment_Serialized = A_TYPES__Fragment_Serialized
|
|
10
|
-
> extends A_Fragment
|
|
10
|
+
> extends A_Fragment {
|
|
11
|
+
protected _storage: Map<keyof _MemoryType, _MemoryType[keyof _MemoryType]> = new Map();
|
|
12
|
+
|
|
13
|
+
set<K extends keyof _MemoryType>(param: K, value: _MemoryType[K]): void {
|
|
14
|
+
this._storage.set(param, value);
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
get<K extends keyof _MemoryType>(param: K): _MemoryType[K] | undefined {
|
|
19
|
+
return this._storage.get(param);
|
|
20
|
+
}
|
|
11
21
|
|
|
12
22
|
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
set<K extends keyof _MemoryType>(param: K | 'error', value: _MemoryType[K]): void {
|
|
16
|
-
super.set(param , value);
|
|
23
|
+
delete<K extends keyof _MemoryType>(param: K): void {
|
|
24
|
+
this._storage.delete(param);
|
|
17
25
|
}
|
|
18
26
|
|
|
19
27
|
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
get<K extends keyof _MemoryType>(param: K | 'error'): _MemoryType[K] | undefined {
|
|
23
|
-
return super.get(param);
|
|
28
|
+
has<K extends keyof _MemoryType>(param: K): boolean {
|
|
29
|
+
return this._storage.has(param);
|
|
24
30
|
}
|
|
25
31
|
|
|
32
|
+
clear(): void {
|
|
33
|
+
this._storage.clear();
|
|
34
|
+
}
|
|
26
35
|
}
|
|
@@ -18,4 +18,15 @@ export type A_MemoryOperationContext<T extends any = any> = A_OperationContext<
|
|
|
18
18
|
A_MemoryOperations,
|
|
19
19
|
{ key: string, value?: any },
|
|
20
20
|
T
|
|
21
|
-
>;
|
|
21
|
+
>;
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
export type A_MemoryOperationContextMeta<
|
|
25
|
+
T extends any = any,
|
|
26
|
+
I extends any = any
|
|
27
|
+
> = {
|
|
28
|
+
result: T,
|
|
29
|
+
operation: A_MemoryOperations,
|
|
30
|
+
key: string,
|
|
31
|
+
value?: I,
|
|
32
|
+
}
|
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
import { A_Error, A_Fragment } from "@adaas/a-concept";
|
|
2
2
|
import { A_Operation_Serialized, A_Operation_Storage } from "./A-Operation.types";
|
|
3
|
+
import { A_ExecutionContext } from "../A-Execution/A-Execution.context";
|
|
3
4
|
|
|
4
5
|
export class A_OperationContext<
|
|
5
6
|
_AllowedOperations extends string = string,
|
|
6
7
|
_ParamsType extends Record<string, any> = Record<string, any>,
|
|
7
8
|
_ResultType = any,
|
|
8
9
|
_StorageType extends A_Operation_Storage<_ResultType, _ParamsType> = A_Operation_Storage<_ResultType, _ParamsType>
|
|
9
|
-
> extends
|
|
10
|
+
> extends A_ExecutionContext<
|
|
10
11
|
_StorageType,
|
|
11
12
|
A_Operation_Serialized<_ResultType, _ParamsType>
|
|
12
13
|
> {
|
|
@@ -15,7 +16,7 @@ export class A_OperationContext<
|
|
|
15
16
|
operation: _AllowedOperations,
|
|
16
17
|
params?: _ParamsType
|
|
17
18
|
) {
|
|
18
|
-
super();
|
|
19
|
+
super('operation-context');
|
|
19
20
|
|
|
20
21
|
this.meta.set('name', operation);
|
|
21
22
|
this.meta.set('params', params || {} as _ParamsType);
|
package/tests/A-Config.test.ts
CHANGED
|
@@ -32,17 +32,11 @@ describe('A-Config tests', () => {
|
|
|
32
32
|
expect(config.get('TEST_VAR2')).toBeUndefined();
|
|
33
33
|
});
|
|
34
34
|
it('Should Allow to create a config object with ENV values', async () => {
|
|
35
|
+
|
|
35
36
|
process.env['TEST_VAR1'] = 'env1';
|
|
36
37
|
process.env['TEST_VAR2'] = 'env2';
|
|
37
38
|
|
|
38
|
-
|
|
39
|
-
// It does automatically by jest.setup.ts script
|
|
40
|
-
const { A_ConfigLoader } = await import('@adaas/a-utils/lib/A-Config/A-Config.container');
|
|
41
|
-
const { FileConfigReader } = await import('@adaas/a-utils/lib/A-Config/components/FileConfigReader.component');
|
|
42
|
-
const { ENVConfigReader } = await import('@adaas/a-utils/lib/A-Config/components/ENVConfigReader.component');
|
|
43
|
-
|
|
44
|
-
const config = new A_Config({
|
|
45
|
-
variables: ['TEST_VAR1', 'TEST_VAR2'] as const,
|
|
39
|
+
const config = new A_Config<['TEST_VAR1', 'TEST_VAR2']>({
|
|
46
40
|
defaults: {
|
|
47
41
|
TEST_VAR1: 'default1',
|
|
48
42
|
}
|
|
@@ -130,7 +124,7 @@ describe('A-Config tests', () => {
|
|
|
130
124
|
const configLoader = new A_ConfigLoader({
|
|
131
125
|
name: 'test-config-loader',
|
|
132
126
|
fragments: [config],
|
|
133
|
-
components: [A_Logger,A_Polyfill, FileConfigReader]
|
|
127
|
+
components: [A_Logger, A_Polyfill, FileConfigReader]
|
|
134
128
|
})
|
|
135
129
|
|
|
136
130
|
const concept = new A_Concept({
|
|
@@ -147,7 +141,7 @@ describe('A-Config tests', () => {
|
|
|
147
141
|
fs.unlinkSync('a-concept.conf.json');
|
|
148
142
|
});
|
|
149
143
|
it('Should Allow to create a config object with variables from File with different variable cases', async () => {
|
|
150
|
-
|
|
144
|
+
|
|
151
145
|
// 1. create a config file
|
|
152
146
|
fs.writeFileSync('a-concept.conf.json', JSON.stringify({
|
|
153
147
|
testVar2: 'env2'
|
|
@@ -163,7 +157,7 @@ describe('A-Config tests', () => {
|
|
|
163
157
|
const configLoader = new A_ConfigLoader({
|
|
164
158
|
name: 'test-config-loader',
|
|
165
159
|
fragments: [config],
|
|
166
|
-
components: [A_Logger,A_Polyfill, FileConfigReader]
|
|
160
|
+
components: [A_Logger, A_Polyfill, FileConfigReader]
|
|
167
161
|
})
|
|
168
162
|
|
|
169
163
|
const concept = new A_Concept({
|
package/tests/A-Manifest.test.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { A_Component } from "@adaas/a-concept";
|
|
1
|
+
import { A_Component, A_Entity } from "@adaas/a-concept";
|
|
2
2
|
import { A_Manifest } from "../src/lib/A-Manifest/A-Manifest.context";
|
|
3
3
|
|
|
4
4
|
describe('A_Manifest', () => {
|
|
@@ -84,8 +84,8 @@ describe('A_Manifest', () => {
|
|
|
84
84
|
put() { return 'user.put'; }
|
|
85
85
|
delete() { return 'user.delete'; }
|
|
86
86
|
}
|
|
87
|
-
class GuestUser extends
|
|
88
|
-
class RegisteredUser extends
|
|
87
|
+
class GuestUser extends A_Entity {}
|
|
88
|
+
class RegisteredUser extends A_Entity {}
|
|
89
89
|
|
|
90
90
|
const manifest = new A_Manifest([
|
|
91
91
|
{
|