@adaas/a-utils 0.1.14 → 0.1.16

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.
Files changed (34) hide show
  1. package/README.md +92 -18
  2. package/dist/index.d.mts +335 -71
  3. package/dist/index.d.ts +335 -71
  4. package/dist/index.js +491 -210
  5. package/dist/index.js.map +1 -1
  6. package/dist/index.mjs +489 -210
  7. package/dist/index.mjs.map +1 -1
  8. package/examples/{channel-examples.ts → A-Channel-examples.ts} +15 -15
  9. package/examples/{command-examples.ts → A-Command-examples.ts} +47 -45
  10. package/examples/A-Logger-examples.ts +308 -0
  11. package/examples/config.ts +1 -1
  12. package/package.json +26 -7
  13. package/src/index.ts +3 -1
  14. package/src/lib/A-Channel/A-Channel.component.ts +84 -17
  15. package/src/lib/A-Channel/A-Channel.error.ts +5 -5
  16. package/src/lib/A-Channel/A-ChannelRequest.context.ts +1 -1
  17. package/src/lib/A-Channel/README.md +24 -24
  18. package/src/lib/A-Command/A-Command.constants.ts +49 -13
  19. package/src/lib/A-Command/A-Command.entity.ts +21 -15
  20. package/src/lib/A-Command/A-Command.types.ts +2 -35
  21. package/src/lib/A-Config/A-Config.container.ts +3 -3
  22. package/src/lib/A-Config/components/ConfigReader.component.ts +4 -6
  23. package/src/lib/A-Logger/A-Logger.component.ts +369 -130
  24. package/src/lib/A-Logger/A-Logger.constants.ts +69 -0
  25. package/src/lib/A-Logger/A-Logger.env.ts +27 -0
  26. package/src/lib/A-Logger/A-Logger.types.ts +3 -0
  27. package/src/lib/A-Logger/README.md +383 -0
  28. package/src/lib/A-Manifest/A-Manifest.types.ts +1 -2
  29. package/src/lib/A-Memory/A-Memory.context.ts +1 -1
  30. package/tests/A-Channel.test.ts +14 -14
  31. package/tests/A-Command.test.ts +26 -26
  32. package/tests/A-Logger.test.ts +520 -0
  33. package/tests/A-Memory.test.ts +5 -5
  34. package/tests/A-Polyfill.test.ts +3 -2
@@ -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('init');
163
- await this.call('init', this.scope);
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('compile');
177
- await this.call('compile', this.scope);
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('execute');
194
+ this.emit(A_CommandFeatures.onExecute);
195
195
 
196
- await this.call('execute', this.scope);
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).toJSON() as ResultType;
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).Errors;
246
+ this._errors = this.scope.resolve(A_Memory)!.Errors;
240
247
 
241
- this.emit('fail');
242
- return await this.call('fail', this.scope);
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, A_TYPES__CommandMetaKey } from "./A-Command.constants";
3
- import { A_Meta, A_TYPES__Entity_Serialized, A_TYPES__Error_Serialized, A_TYPES__FeatureDefineDecoratorMeta, A_TYPES__FeatureExtendDecoratorMeta } from "@adaas/a-concept";
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 (!container.scope.has(A_Config)) {
23
- const newConfig = new A_Config({
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(newConfig);
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);