@adaas/a-utils 0.1.15 → 0.1.17
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/LICENSE +10 -19
- package/README.md +74 -18
- package/dist/index.d.mts +270 -58
- package/dist/index.d.ts +270 -58
- package/dist/index.js +323 -103
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +324 -103
- package/dist/index.mjs.map +1 -1
- package/examples/{channel-examples.ts → A-Channel-examples.ts} +2 -2
- package/examples/{command-examples.ts → A-Command-examples.ts} +47 -45
- package/examples/A-Logger-examples.ts +308 -0
- package/examples/config.ts +1 -1
- package/package.json +45 -34
- package/src/lib/A-Command/A-Command.constants.ts +49 -13
- package/src/lib/A-Command/A-Command.entity.ts +21 -15
- package/src/lib/A-Command/A-Command.types.ts +2 -35
- package/src/lib/A-Config/A-Config.container.ts +3 -3
- package/src/lib/A-Config/components/ConfigReader.component.ts +4 -6
- package/src/lib/A-Logger/A-Logger.component.ts +369 -130
- package/src/lib/A-Logger/A-Logger.constants.ts +69 -0
- package/src/lib/A-Logger/A-Logger.env.ts +27 -0
- package/src/lib/A-Logger/A-Logger.types.ts +3 -0
- package/src/lib/A-Logger/README.md +383 -0
- package/src/lib/A-Manifest/A-Manifest.types.ts +1 -2
- package/src/lib/A-Memory/A-Memory.context.ts +1 -1
- package/tests/A-Command.test.ts +26 -26
- package/tests/A-Logger.test.ts +520 -0
- package/tests/A-Memory.test.ts +5 -5
- package/tests/A-Polyfill.test.ts +3 -2
|
@@ -1,35 +1,71 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
ABSTRACTIONS = 'a-command-abstractions',
|
|
5
|
-
}
|
|
6
|
-
|
|
1
|
+
/**
|
|
2
|
+
* A-Command Statuses
|
|
3
|
+
*/
|
|
7
4
|
export enum A_CONSTANTS__A_Command_Status {
|
|
5
|
+
/**
|
|
6
|
+
* Command has been created but not yet initialized
|
|
7
|
+
*/
|
|
8
8
|
CREATED = 'CREATED',
|
|
9
|
+
/**
|
|
10
|
+
* Command is initializing
|
|
11
|
+
*/
|
|
9
12
|
INITIALIZATION = 'INITIALIZATION',
|
|
13
|
+
/**
|
|
14
|
+
* Command has been initialized
|
|
15
|
+
*/
|
|
10
16
|
INITIALIZED = 'INITIALIZED',
|
|
17
|
+
/**
|
|
18
|
+
* Command is compiling
|
|
19
|
+
*/
|
|
11
20
|
COMPILATION = 'COMPILATION',
|
|
21
|
+
/**
|
|
22
|
+
* Command is compiled
|
|
23
|
+
*/
|
|
12
24
|
COMPILED = 'COMPILED',
|
|
25
|
+
/**
|
|
26
|
+
* Command is executing
|
|
27
|
+
*/
|
|
13
28
|
IN_PROGRESS = 'IN_PROGRESS',
|
|
29
|
+
/**
|
|
30
|
+
* Command has completed successfully
|
|
31
|
+
*/
|
|
14
32
|
COMPLETED = 'COMPLETED',
|
|
33
|
+
/**
|
|
34
|
+
* Command has failed
|
|
35
|
+
*/
|
|
15
36
|
FAILED = 'FAILED',
|
|
16
37
|
}
|
|
17
38
|
|
|
18
39
|
/**
|
|
19
40
|
* A-Command Lifecycle Features
|
|
20
41
|
*/
|
|
21
|
-
export enum
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
42
|
+
export enum A_CommandFeatures {
|
|
43
|
+
/**
|
|
44
|
+
* Allows to extend initialization logic and behavior
|
|
45
|
+
*/
|
|
46
|
+
onInit = 'onInit',
|
|
47
|
+
/**
|
|
48
|
+
* Allows to extend compilation logic and behavior
|
|
49
|
+
*/
|
|
50
|
+
onCompile = 'onCompile',
|
|
51
|
+
/**
|
|
52
|
+
* Allows to extend execution logic and behavior
|
|
53
|
+
*/
|
|
54
|
+
onExecute = 'onExecute',
|
|
55
|
+
/**
|
|
56
|
+
* Allows to extend completion logic and behavior
|
|
57
|
+
*/
|
|
58
|
+
onComplete = 'onComplete',
|
|
59
|
+
/**
|
|
60
|
+
*
|
|
61
|
+
*/
|
|
62
|
+
onFail = 'onFail',
|
|
27
63
|
}
|
|
28
64
|
|
|
29
65
|
|
|
30
66
|
|
|
31
67
|
|
|
32
|
-
export type A_CONSTANTS__A_Command_Event =
|
|
68
|
+
export type A_CONSTANTS__A_Command_Event = keyof typeof A_CommandFeatures;
|
|
33
69
|
|
|
34
70
|
|
|
35
71
|
|
|
@@ -4,10 +4,11 @@ import {
|
|
|
4
4
|
A_TYPES__Command_Serialized
|
|
5
5
|
} from "./A-Command.types";
|
|
6
6
|
import {
|
|
7
|
+
A_CommandFeatures,
|
|
7
8
|
A_CONSTANTS__A_Command_Event,
|
|
8
9
|
A_CONSTANTS__A_Command_Status
|
|
9
10
|
} from "./A-Command.constants";
|
|
10
|
-
import { A_Context, A_Entity, A_Error, A_Scope } from "@adaas/a-concept";
|
|
11
|
+
import { A_Component, A_Context, A_Entity, A_Error, A_Feature, A_Scope } from "@adaas/a-concept";
|
|
11
12
|
import { A_Memory } from "../A-Memory/A-Memory.context";
|
|
12
13
|
import { A_CommandError } from "./A-Command.error";
|
|
13
14
|
|
|
@@ -157,10 +158,9 @@ export class A_Command<
|
|
|
157
158
|
this._status = A_CONSTANTS__A_Command_Status.INITIALIZATION;
|
|
158
159
|
this._startTime = new Date();
|
|
159
160
|
|
|
160
|
-
this.checkScopeInheritance();
|
|
161
161
|
|
|
162
|
-
this.emit(
|
|
163
|
-
await this.call(
|
|
162
|
+
this.emit(A_CommandFeatures.onInit);
|
|
163
|
+
await this.call(A_CommandFeatures.onInit, this.scope);
|
|
164
164
|
this._status = A_CONSTANTS__A_Command_Status.INITIALIZED;
|
|
165
165
|
}
|
|
166
166
|
|
|
@@ -173,8 +173,8 @@ export class A_Command<
|
|
|
173
173
|
this.checkScopeInheritance();
|
|
174
174
|
|
|
175
175
|
this._status = A_CONSTANTS__A_Command_Status.COMPILATION;
|
|
176
|
-
this.emit(
|
|
177
|
-
await this.call(
|
|
176
|
+
this.emit(A_CommandFeatures.onCompile);
|
|
177
|
+
await this.call(A_CommandFeatures.onCompile, this.scope);
|
|
178
178
|
this._status = A_CONSTANTS__A_Command_Status.COMPILED;
|
|
179
179
|
}
|
|
180
180
|
|
|
@@ -191,9 +191,9 @@ export class A_Command<
|
|
|
191
191
|
|
|
192
192
|
this.checkScopeInheritance();
|
|
193
193
|
|
|
194
|
-
this.emit(
|
|
194
|
+
this.emit(A_CommandFeatures.onExecute);
|
|
195
195
|
|
|
196
|
-
await this.call(
|
|
196
|
+
await this.call(A_CommandFeatures.onExecute, this.scope);
|
|
197
197
|
}
|
|
198
198
|
|
|
199
199
|
/**
|
|
@@ -204,13 +204,19 @@ export class A_Command<
|
|
|
204
204
|
|
|
205
205
|
try {
|
|
206
206
|
await this.init();
|
|
207
|
+
|
|
207
208
|
await this.compile();
|
|
209
|
+
|
|
208
210
|
await this.process();
|
|
211
|
+
|
|
209
212
|
await this.complete();
|
|
210
213
|
|
|
214
|
+
|
|
211
215
|
} catch (error) {
|
|
212
216
|
await this.fail();
|
|
213
217
|
}
|
|
218
|
+
|
|
219
|
+
this._executionScope.destroy();
|
|
214
220
|
}
|
|
215
221
|
|
|
216
222
|
/**
|
|
@@ -221,10 +227,11 @@ export class A_Command<
|
|
|
221
227
|
|
|
222
228
|
this._status = A_CONSTANTS__A_Command_Status.COMPLETED;
|
|
223
229
|
this._endTime = new Date();
|
|
224
|
-
this._result = this.scope.resolve(A_Memory)
|
|
230
|
+
this._result = this.scope.resolve(A_Memory)!.toJSON() as ResultType;
|
|
231
|
+
|
|
232
|
+
this.emit(A_CommandFeatures.onComplete);
|
|
233
|
+
await this.call(A_CommandFeatures.onComplete, this.scope);
|
|
225
234
|
|
|
226
|
-
this.emit('complete');
|
|
227
|
-
return await this.call('complete', this.scope);
|
|
228
235
|
}
|
|
229
236
|
|
|
230
237
|
|
|
@@ -236,10 +243,10 @@ export class A_Command<
|
|
|
236
243
|
|
|
237
244
|
this._status = A_CONSTANTS__A_Command_Status.FAILED;
|
|
238
245
|
this._endTime = new Date();
|
|
239
|
-
this._errors = this.scope.resolve(A_Memory)
|
|
246
|
+
this._errors = this.scope.resolve(A_Memory)!.Errors;
|
|
240
247
|
|
|
241
|
-
this.emit(
|
|
242
|
-
|
|
248
|
+
this.emit(A_CommandFeatures.onFail);
|
|
249
|
+
await this.call(A_CommandFeatures.onFail, this.scope);
|
|
243
250
|
}
|
|
244
251
|
|
|
245
252
|
|
|
@@ -382,5 +389,4 @@ export class A_Command<
|
|
|
382
389
|
this.scope.inherit(A_Context.scope(this));
|
|
383
390
|
}
|
|
384
391
|
}
|
|
385
|
-
|
|
386
392
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { A_Command } from "./A-Command.entity";
|
|
2
|
-
import { A_CONSTANTS__A_Command_Event, A_CONSTANTS__A_Command_Status,
|
|
3
|
-
import {
|
|
2
|
+
import { A_CONSTANTS__A_Command_Event, A_CONSTANTS__A_Command_Status, } from "./A-Command.constants";
|
|
3
|
+
import { A_TYPES__Entity_Serialized, A_TYPES__Error_Serialized } from "@adaas/a-concept";
|
|
4
4
|
|
|
5
5
|
|
|
6
6
|
|
|
@@ -70,36 +70,3 @@ export type A_TYPES__Command_Listener<
|
|
|
70
70
|
ResultType extends Record<string, any> = Record<string, any>,
|
|
71
71
|
LifecycleEvents extends string = A_CONSTANTS__A_Command_Event
|
|
72
72
|
> = (command?: A_Command<InvokeType, ResultType, LifecycleEvents>) => void;
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
// ============================================================================
|
|
76
|
-
// --------------------------- Meta Types -------------------------------------
|
|
77
|
-
// ============================================================================
|
|
78
|
-
/**
|
|
79
|
-
* Command meta type
|
|
80
|
-
*/
|
|
81
|
-
export type A_TYPES__CommandMeta = {
|
|
82
|
-
[A_TYPES__CommandMetaKey.EXTENSIONS]: A_Meta<{
|
|
83
|
-
|
|
84
|
-
/**
|
|
85
|
-
* Where Key the regexp for what to apply the extension
|
|
86
|
-
* A set of container names or a wildcard, or a regexp
|
|
87
|
-
*
|
|
88
|
-
*
|
|
89
|
-
* Where value is the extension instructions
|
|
90
|
-
*/
|
|
91
|
-
[Key: string]: A_TYPES__FeatureExtendDecoratorMeta[]
|
|
92
|
-
|
|
93
|
-
}>, case
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
[A_TYPES__CommandMetaKey.FEATURES]: A_Meta<{
|
|
97
|
-
/**
|
|
98
|
-
* Where Key is the name of the feature
|
|
99
|
-
*
|
|
100
|
-
* Where value is the list of features
|
|
101
|
-
*/
|
|
102
|
-
[Key: string]: A_TYPES__FeatureDefineDecoratorMeta
|
|
103
|
-
}>
|
|
104
|
-
}
|
|
105
|
-
|
|
@@ -38,15 +38,15 @@ export class A_ConfigLoader extends A_Container {
|
|
|
38
38
|
switch (true) {
|
|
39
39
|
|
|
40
40
|
case A_Context.environment === 'server' && !!fs.existsSync(`${A_Context.concept}.conf.json`):
|
|
41
|
-
this.reader = this.scope.resolve<ConfigReader>(FileConfigReader)
|
|
41
|
+
this.reader = this.scope.resolve<ConfigReader>(FileConfigReader)!;
|
|
42
42
|
break;
|
|
43
43
|
|
|
44
44
|
case A_Context.environment === 'server' && !fs.existsSync(`${A_Context.concept}.conf.json`):
|
|
45
|
-
this.reader = this.scope.resolve<ConfigReader>(ENVConfigReader)
|
|
45
|
+
this.reader = this.scope.resolve<ConfigReader>(ENVConfigReader)!;
|
|
46
46
|
break;
|
|
47
47
|
|
|
48
48
|
case A_Context.environment === 'browser':
|
|
49
|
-
this.reader = this.scope.resolve<ConfigReader>(ENVConfigReader)
|
|
49
|
+
this.reader = this.scope.resolve<ConfigReader>(ENVConfigReader)!;
|
|
50
50
|
break;
|
|
51
51
|
|
|
52
52
|
default:
|
|
@@ -18,9 +18,10 @@ export class ConfigReader extends A_Component {
|
|
|
18
18
|
async attachContext(
|
|
19
19
|
@A_Inject(A_Container) container: A_Container,
|
|
20
20
|
@A_Inject(A_Feature) feature: A_Feature,
|
|
21
|
+
@A_Inject(A_Config) config?: A_Config,
|
|
21
22
|
) {
|
|
22
|
-
if (!
|
|
23
|
-
|
|
23
|
+
if (!config) {
|
|
24
|
+
config= new A_Config({
|
|
24
25
|
variables: [
|
|
25
26
|
...A_CONSTANTS__DEFAULT_ENV_VARIABLES_ARRAY,
|
|
26
27
|
...A_CONSTANTS__CONFIG_ENV_VARIABLES_ARRAY
|
|
@@ -28,12 +29,9 @@ export class ConfigReader extends A_Component {
|
|
|
28
29
|
defaults: {}
|
|
29
30
|
});
|
|
30
31
|
|
|
31
|
-
container.scope.register(
|
|
32
|
+
container.scope.register(config);
|
|
32
33
|
}
|
|
33
34
|
|
|
34
|
-
|
|
35
|
-
const config = container.scope.resolve<A_Config>(A_Config);
|
|
36
|
-
|
|
37
35
|
const rootDir = await this.getProjectRoot();
|
|
38
36
|
|
|
39
37
|
config.set('A_CONCEPT_ROOT_FOLDER', rootDir);
|