@adaas/a-utils 0.1.10 → 0.1.12
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/README.md +87 -32
- package/dist/index.d.mts +933 -0
- package/dist/index.d.ts +933 -27
- package/dist/index.js +1786 -90
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +1764 -0
- package/dist/index.mjs.map +1 -0
- package/examples/command-examples.ts +268 -0
- package/package.json +5 -3
- package/src/index.ts +70 -0
- package/src/lib/A-Command/A-Command.constants.ts +4 -0
- package/src/lib/A-Command/A-Command.entity.ts +31 -13
- package/src/lib/A-Command/A-Command.types.ts +6 -1
- package/src/lib/A-Command/README.md +645 -0
- package/src/lib/A-Logger/A-Logger.component.ts +10 -3
- package/src/lib/A-Memory/A-Memory.context.ts +15 -0
- package/src/lib/A-Polyfill/A-Polyfill.component.ts +153 -15
- package/src/lib/A-Polyfill/A-Polyfill.types.ts +54 -0
- package/src/lib/A-Polyfill/classes/A-Buffer-Polyfill.class.ts +85 -0
- package/src/lib/A-Polyfill/classes/A-Crypto-Polyfill.class.ts +87 -0
- package/src/lib/A-Polyfill/classes/A-FS-Polyfill.class.ts +61 -0
- package/src/lib/A-Polyfill/classes/A-Http-Polyfill.class.ts +100 -0
- package/src/lib/A-Polyfill/classes/A-Https-Polyfill.class.ts +100 -0
- package/src/lib/A-Polyfill/classes/A-Path-Polyfill.class.ts +97 -0
- package/src/lib/A-Polyfill/classes/A-Process-Polyfill.class.ts +73 -0
- package/src/lib/A-Polyfill/classes/A-Url-Polyfill.class.ts +88 -0
- package/tests/A-Command.test.ts +447 -2
- package/tests/A-Config.test.ts +5 -5
- package/tests/A-Memory.test.ts +189 -0
- package/tests/A-Polyfill.test.ts +446 -29
- package/tsconfig.json +1 -1
- package/tsup.config.ts +15 -0
- package/dist/src/constants/errors.constants.d.ts +0 -0
- package/dist/src/constants/errors.constants.js +0 -2
- package/dist/src/constants/errors.constants.js.map +0 -1
- package/dist/src/lib/A-Channel/A-Channel.component.d.ts +0 -22
- package/dist/src/lib/A-Channel/A-Channel.component.js +0 -84
- package/dist/src/lib/A-Channel/A-Channel.component.js.map +0 -1
- package/dist/src/lib/A-Channel/A-Channel.error.d.ts +0 -4
- package/dist/src/lib/A-Channel/A-Channel.error.js +0 -9
- package/dist/src/lib/A-Channel/A-Channel.error.js.map +0 -1
- package/dist/src/lib/A-Channel/A-Channel.types.d.ts +0 -0
- package/dist/src/lib/A-Channel/A-Channel.types.js +0 -2
- package/dist/src/lib/A-Channel/A-Channel.types.js.map +0 -1
- package/dist/src/lib/A-Command/A-Command.constants.d.ts +0 -22
- package/dist/src/lib/A-Command/A-Command.constants.js +0 -28
- package/dist/src/lib/A-Command/A-Command.constants.js.map +0 -1
- package/dist/src/lib/A-Command/A-Command.entity.d.ts +0 -133
- package/dist/src/lib/A-Command/A-Command.entity.js +0 -273
- package/dist/src/lib/A-Command/A-Command.entity.js.map +0 -1
- package/dist/src/lib/A-Command/A-Command.error.d.ts +0 -3
- package/dist/src/lib/A-Command/A-Command.error.js +0 -8
- package/dist/src/lib/A-Command/A-Command.error.js.map +0 -1
- package/dist/src/lib/A-Command/A-Command.types.d.ts +0 -73
- package/dist/src/lib/A-Command/A-Command.types.js +0 -4
- package/dist/src/lib/A-Command/A-Command.types.js.map +0 -1
- package/dist/src/lib/A-Config/A-Config.constants.d.ts +0 -3
- package/dist/src/lib/A-Config/A-Config.constants.js +0 -6
- package/dist/src/lib/A-Config/A-Config.constants.js.map +0 -1
- package/dist/src/lib/A-Config/A-Config.container.d.ts +0 -6
- package/dist/src/lib/A-Config/A-Config.container.js +0 -77
- package/dist/src/lib/A-Config/A-Config.container.js.map +0 -1
- package/dist/src/lib/A-Config/A-Config.context.d.ts +0 -29
- package/dist/src/lib/A-Config/A-Config.context.js +0 -63
- package/dist/src/lib/A-Config/A-Config.context.js.map +0 -1
- package/dist/src/lib/A-Config/A-Config.error.d.ts +0 -4
- package/dist/src/lib/A-Config/A-Config.error.js +0 -9
- package/dist/src/lib/A-Config/A-Config.error.js.map +0 -1
- package/dist/src/lib/A-Config/A-Config.types.d.ts +0 -19
- package/dist/src/lib/A-Config/A-Config.types.js +0 -7
- package/dist/src/lib/A-Config/A-Config.types.js.map +0 -1
- package/dist/src/lib/A-Config/components/ConfigReader.component.d.ts +0 -30
- package/dist/src/lib/A-Config/components/ConfigReader.component.js +0 -103
- package/dist/src/lib/A-Config/components/ConfigReader.component.js.map +0 -1
- package/dist/src/lib/A-Config/components/ENVConfigReader.component.d.ts +0 -14
- package/dist/src/lib/A-Config/components/ENVConfigReader.component.js +0 -72
- package/dist/src/lib/A-Config/components/ENVConfigReader.component.js.map +0 -1
- package/dist/src/lib/A-Config/components/FileConfigReader.component.d.ts +0 -11
- package/dist/src/lib/A-Config/components/FileConfigReader.component.js +0 -47
- package/dist/src/lib/A-Config/components/FileConfigReader.component.js.map +0 -1
- package/dist/src/lib/A-Logger/A-Logger.component.d.ts +0 -29
- package/dist/src/lib/A-Logger/A-Logger.component.js +0 -152
- package/dist/src/lib/A-Logger/A-Logger.component.js.map +0 -1
- package/dist/src/lib/A-Logger/A-Logger.types.d.ts +0 -0
- package/dist/src/lib/A-Logger/A-Logger.types.js +0 -2
- package/dist/src/lib/A-Logger/A-Logger.types.js.map +0 -1
- package/dist/src/lib/A-Manifest/A-Manifest.context.d.ts +0 -52
- package/dist/src/lib/A-Manifest/A-Manifest.context.js +0 -154
- package/dist/src/lib/A-Manifest/A-Manifest.context.js.map +0 -1
- package/dist/src/lib/A-Manifest/A-Manifest.error.d.ts +0 -4
- package/dist/src/lib/A-Manifest/A-Manifest.error.js +0 -9
- package/dist/src/lib/A-Manifest/A-Manifest.error.js.map +0 -1
- package/dist/src/lib/A-Manifest/A-Manifest.types.d.ts +0 -43
- package/dist/src/lib/A-Manifest/A-Manifest.types.js +0 -3
- package/dist/src/lib/A-Manifest/A-Manifest.types.js.map +0 -1
- package/dist/src/lib/A-Manifest/classes/A-ManifestChecker.class.d.ts +0 -14
- package/dist/src/lib/A-Manifest/classes/A-ManifestChecker.class.js +0 -24
- package/dist/src/lib/A-Manifest/classes/A-ManifestChecker.class.js.map +0 -1
- package/dist/src/lib/A-Memory/A-Memory.context.d.ts +0 -64
- package/dist/src/lib/A-Memory/A-Memory.context.js +0 -105
- package/dist/src/lib/A-Memory/A-Memory.context.js.map +0 -1
- package/dist/src/lib/A-Polyfill/A-Polyfill.component.d.ts +0 -20
- package/dist/src/lib/A-Polyfill/A-Polyfill.component.js +0 -53
- package/dist/src/lib/A-Polyfill/A-Polyfill.component.js.map +0 -1
- package/dist/src/lib/A-Polyfill/A-Polyfill.types.d.ts +0 -9
- package/dist/src/lib/A-Polyfill/A-Polyfill.types.js +0 -3
- package/dist/src/lib/A-Polyfill/A-Polyfill.types.js.map +0 -1
- package/dist/src/lib/A-Polyfill/A-Polyfills.class.d.ts +0 -11
- package/dist/src/lib/A-Polyfill/A-Polyfills.class.js +0 -123
- package/dist/src/lib/A-Polyfill/A-Polyfills.class.js.map +0 -1
- package/dist/src/lib/A-Schedule/A-Deferred.class.d.ts +0 -12
- package/dist/src/lib/A-Schedule/A-Deferred.class.js +0 -23
- package/dist/src/lib/A-Schedule/A-Deferred.class.js.map +0 -1
- package/dist/src/lib/A-Schedule/A-Schedule.component.d.ts +0 -57
- package/dist/src/lib/A-Schedule/A-Schedule.component.js +0 -49
- package/dist/src/lib/A-Schedule/A-Schedule.component.js.map +0 -1
- package/dist/src/lib/A-Schedule/A-Schedule.types.d.ts +0 -10
- package/dist/src/lib/A-Schedule/A-Schedule.types.js +0 -3
- package/dist/src/lib/A-Schedule/A-Schedule.types.js.map +0 -1
- package/dist/src/lib/A-Schedule/A-ScheduleObject.class.d.ts +0 -29
- package/dist/src/lib/A-Schedule/A-ScheduleObject.class.js +0 -58
- package/dist/src/lib/A-Schedule/A-ScheduleObject.class.js.map +0 -1
- package/index.ts +0 -71
- package/src/lib/A-Polyfill/A-Polyfills.class.ts +0 -99
- package/tsconfig.build.json +0 -56
package/src/index.ts
ADDED
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
|
|
2
|
+
// ============================================================================
|
|
3
|
+
// A-Channel Components
|
|
4
|
+
// ============================================================================
|
|
5
|
+
export { A_Channel } from './lib/A-Channel/A-Channel.component';
|
|
6
|
+
export { A_ChannelError } from './lib/A-Channel/A-Channel.error';
|
|
7
|
+
// export * from './src/lib/A-Channel/A-Channel.types'; // Empty file
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
// ============================================================================
|
|
11
|
+
// A-Command Components
|
|
12
|
+
// ============================================================================
|
|
13
|
+
export { A_Command } from './lib/A-Command/A-Command.entity';
|
|
14
|
+
export { A_CommandError } from './lib/A-Command/A-Command.error';
|
|
15
|
+
export * from './lib/A-Command/A-Command.types';
|
|
16
|
+
export * from './lib/A-Command/A-Command.constants';
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
// ============================================================================
|
|
20
|
+
// A-Config Components
|
|
21
|
+
// ============================================================================
|
|
22
|
+
export { A_ConfigLoader } from './lib/A-Config/A-Config.container';
|
|
23
|
+
export { A_Config } from './lib/A-Config/A-Config.context';
|
|
24
|
+
export { A_ConfigError } from './lib/A-Config/A-Config.error';
|
|
25
|
+
export { ConfigReader } from './lib/A-Config/components/ConfigReader.component';
|
|
26
|
+
export { ENVConfigReader } from './lib/A-Config/components/ENVConfigReader.component';
|
|
27
|
+
export { FileConfigReader } from './lib/A-Config/components/FileConfigReader.component';
|
|
28
|
+
export * from './lib/A-Config/A-Config.types';
|
|
29
|
+
export * from './lib/A-Config/A-Config.constants';
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
// ============================================================================
|
|
33
|
+
// A-Logger Components
|
|
34
|
+
// ============================================================================
|
|
35
|
+
export { A_Logger } from './lib/A-Logger/A-Logger.component';
|
|
36
|
+
// export * from './src/lib/A-Logger/A-Logger.types'; // Empty file
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
// ============================================================================
|
|
40
|
+
// A-Manifest Components
|
|
41
|
+
// ============================================================================
|
|
42
|
+
export { A_Manifest } from './lib/A-Manifest/A-Manifest.context';
|
|
43
|
+
export { A_ManifestError } from './lib/A-Manifest/A-Manifest.error';
|
|
44
|
+
export { A_ManifestChecker } from './lib/A-Manifest/classes/A-ManifestChecker.class';
|
|
45
|
+
export * from './lib/A-Manifest/A-Manifest.types';
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
// ============================================================================
|
|
49
|
+
// A-Memory Components
|
|
50
|
+
// ============================================================================
|
|
51
|
+
export { A_Memory } from './lib/A-Memory/A-Memory.context';
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+
// ============================================================================
|
|
55
|
+
// A-Polyfill Components
|
|
56
|
+
// ============================================================================
|
|
57
|
+
export { A_Polyfill } from './lib/A-Polyfill/A-Polyfill.component';
|
|
58
|
+
export * from './lib/A-Polyfill/A-Polyfill.types';
|
|
59
|
+
|
|
60
|
+
|
|
61
|
+
// ============================================================================
|
|
62
|
+
// A-Schedule Components
|
|
63
|
+
// ============================================================================
|
|
64
|
+
export { A_Schedule } from './lib/A-Schedule/A-Schedule.component';
|
|
65
|
+
export { A_ScheduleObject } from './lib/A-Schedule/A-ScheduleObject.class';
|
|
66
|
+
export { A_Deferred } from './lib/A-Schedule/A-Deferred.class';
|
|
67
|
+
export * from './lib/A-Schedule/A-Schedule.types';
|
|
68
|
+
|
|
69
|
+
|
|
70
|
+
|
|
@@ -5,7 +5,11 @@ export enum A_TYPES__CommandMetaKey {
|
|
|
5
5
|
}
|
|
6
6
|
|
|
7
7
|
export enum A_CONSTANTS__A_Command_Status {
|
|
8
|
+
CREATED = 'CREATED',
|
|
9
|
+
INITIALIZATION = 'INITIALIZATION',
|
|
8
10
|
INITIALIZED = 'INITIALIZED',
|
|
11
|
+
COMPILATION = 'COMPILATION',
|
|
12
|
+
COMPILED = 'COMPILED',
|
|
9
13
|
IN_PROGRESS = 'IN_PROGRESS',
|
|
10
14
|
COMPLETED = 'COMPLETED',
|
|
11
15
|
FAILED = 'FAILED',
|
|
@@ -14,8 +14,8 @@ import { A_Memory } from "../A-Memory/A-Memory.context";
|
|
|
14
14
|
export class A_Command<
|
|
15
15
|
InvokeType extends A_TYPES__Command_Init = A_TYPES__Command_Init,
|
|
16
16
|
ResultType extends Record<string, any> = Record<string, any>,
|
|
17
|
-
LifecycleEvents extends string = A_CONSTANTS__A_Command_Event
|
|
18
|
-
> extends A_Entity<InvokeType, A_TYPES__Command_Serialized<ResultType>> {
|
|
17
|
+
LifecycleEvents extends string | A_CONSTANTS__A_Command_Event = A_CONSTANTS__A_Command_Event
|
|
18
|
+
> extends A_Entity<InvokeType, A_TYPES__Command_Serialized<InvokeType, ResultType>> {
|
|
19
19
|
|
|
20
20
|
// ====================================================================
|
|
21
21
|
// ================== Static A-Command Information ====================
|
|
@@ -136,7 +136,7 @@ export class A_Command<
|
|
|
136
136
|
/**
|
|
137
137
|
* Command invocation parameters
|
|
138
138
|
*/
|
|
139
|
-
params: InvokeType | A_TYPES__Command_Serialized<ResultType> | string
|
|
139
|
+
params: InvokeType | A_TYPES__Command_Serialized<InvokeType, ResultType> | string
|
|
140
140
|
) {
|
|
141
141
|
super(params as any)
|
|
142
142
|
}
|
|
@@ -148,21 +148,32 @@ export class A_Command<
|
|
|
148
148
|
|
|
149
149
|
// should create a new Task in DB with basic records
|
|
150
150
|
async init(): Promise<void> {
|
|
151
|
-
|
|
151
|
+
// first check statuis if it passed then - skip
|
|
152
|
+
if (this._status !== A_CONSTANTS__A_Command_Status.CREATED) {
|
|
153
|
+
return;
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
this._status = A_CONSTANTS__A_Command_Status.INITIALIZATION;
|
|
152
157
|
this._startTime = new Date();
|
|
153
158
|
if (!this.scope.isInheritedFrom(A_Context.scope(this))) {
|
|
154
159
|
this.scope.inherit(A_Context.scope(this));
|
|
155
160
|
}
|
|
156
161
|
|
|
157
|
-
|
|
158
162
|
this.emit('init');
|
|
159
|
-
|
|
163
|
+
await this.call('init', this.scope);
|
|
164
|
+
this._status = A_CONSTANTS__A_Command_Status.INITIALIZED;
|
|
160
165
|
}
|
|
161
166
|
|
|
162
167
|
// Should compile everything before execution
|
|
163
168
|
async compile() {
|
|
169
|
+
if (this._status !== A_CONSTANTS__A_Command_Status.INITIALIZED) {
|
|
170
|
+
return;
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
this._status = A_CONSTANTS__A_Command_Status.COMPILATION;
|
|
164
174
|
this.emit('compile');
|
|
165
|
-
|
|
175
|
+
await this.call('compile', this.scope);
|
|
176
|
+
this._status = A_CONSTANTS__A_Command_Status.COMPILED;
|
|
166
177
|
}
|
|
167
178
|
|
|
168
179
|
/**
|
|
@@ -172,8 +183,11 @@ export class A_Command<
|
|
|
172
183
|
try {
|
|
173
184
|
await this.init();
|
|
174
185
|
await this.compile();
|
|
175
|
-
|
|
176
|
-
|
|
186
|
+
|
|
187
|
+
if (this._status === A_CONSTANTS__A_Command_Status.COMPILED) {
|
|
188
|
+
this.emit('execute');
|
|
189
|
+
await this.call('execute', this.scope);
|
|
190
|
+
}
|
|
177
191
|
await this.complete();
|
|
178
192
|
|
|
179
193
|
} catch (error) {
|
|
@@ -265,7 +279,7 @@ export class A_Command<
|
|
|
265
279
|
|
|
266
280
|
this._params = newEntity;
|
|
267
281
|
|
|
268
|
-
this._status = A_CONSTANTS__A_Command_Status.
|
|
282
|
+
this._status = A_CONSTANTS__A_Command_Status.CREATED;
|
|
269
283
|
}
|
|
270
284
|
|
|
271
285
|
|
|
@@ -277,7 +291,7 @@ export class A_Command<
|
|
|
277
291
|
*
|
|
278
292
|
* @param serialized
|
|
279
293
|
*/
|
|
280
|
-
fromJSON(serialized: A_TYPES__Command_Serialized<ResultType>): void {
|
|
294
|
+
fromJSON(serialized: A_TYPES__Command_Serialized<InvokeType, ResultType>): void {
|
|
281
295
|
super.fromJSON(serialized);
|
|
282
296
|
|
|
283
297
|
this._executionScope = new A_Scope();
|
|
@@ -303,7 +317,10 @@ export class A_Command<
|
|
|
303
317
|
});
|
|
304
318
|
}
|
|
305
319
|
|
|
306
|
-
this.
|
|
320
|
+
this._params = serialized.params
|
|
321
|
+
|
|
322
|
+
this._status = serialized.status || A_CONSTANTS__A_Command_Status.CREATED;
|
|
323
|
+
|
|
307
324
|
}
|
|
308
325
|
|
|
309
326
|
|
|
@@ -312,11 +329,12 @@ export class A_Command<
|
|
|
312
329
|
*
|
|
313
330
|
* @returns
|
|
314
331
|
*/
|
|
315
|
-
toJSON(): A_TYPES__Command_Serialized<ResultType> {
|
|
332
|
+
toJSON(): A_TYPES__Command_Serialized<InvokeType, ResultType> {
|
|
316
333
|
return {
|
|
317
334
|
...super.toJSON(),
|
|
318
335
|
code: this.code,
|
|
319
336
|
status: this._status,
|
|
337
|
+
params: this._params,
|
|
320
338
|
startedAt: this._startTime ? this._startTime.toISOString() : undefined,
|
|
321
339
|
endedAt: this._endTime ? this._endTime.toISOString() : undefined,
|
|
322
340
|
duration: this.duration,
|
|
@@ -15,11 +15,12 @@ export type A_TYPES__Command_Constructor<T = A_Command> = new (...args: any[]) =
|
|
|
15
15
|
/**
|
|
16
16
|
* Command initialization type
|
|
17
17
|
*/
|
|
18
|
-
export type A_TYPES__Command_Init = any
|
|
18
|
+
export type A_TYPES__Command_Init = Record<string, any>;
|
|
19
19
|
/**
|
|
20
20
|
* Command serialized type
|
|
21
21
|
*/
|
|
22
22
|
export type A_TYPES__Command_Serialized<
|
|
23
|
+
ParamsType extends Record<string, any> = Record<string, any>,
|
|
23
24
|
ResultType extends Record<string, any> = Record<string, any>
|
|
24
25
|
> = {
|
|
25
26
|
/**
|
|
@@ -30,6 +31,10 @@ export type A_TYPES__Command_Serialized<
|
|
|
30
31
|
* Current status of the command
|
|
31
32
|
*/
|
|
32
33
|
status: A_CONSTANTS__A_Command_Status;
|
|
34
|
+
/**
|
|
35
|
+
* Parameters used to invoke the command
|
|
36
|
+
*/
|
|
37
|
+
params: ParamsType;
|
|
33
38
|
// --------------------------------------------------
|
|
34
39
|
/**
|
|
35
40
|
* The time when the command was created
|