@adaas/a-concept 0.0.56 → 0.0.57
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/.nvmrc +1 -1
- package/dist/src/base/A-Command/A_Command.constants.d.ts +12 -0
- package/dist/src/base/A-Command/A_Command.constants.js +17 -0
- package/dist/src/base/A-Command/A_Command.constants.js.map +1 -0
- package/dist/src/base/A-Command/A_Command.entity.d.ts +123 -0
- package/dist/src/base/A-Command/A_Command.entity.js +259 -0
- package/dist/src/base/A-Command/A_Command.entity.js.map +1 -0
- package/dist/src/base/A-Command/A_Command.types.d.ts +15 -0
- package/dist/src/base/A-Command/A_Command.types.js +3 -0
- package/dist/src/base/A-Command/A_Command.types.js.map +1 -0
- package/dist/src/base/A-Command/context/A_Command.context.d.ts +64 -0
- package/dist/src/base/A-Command/context/A_Command.context.js +85 -0
- package/dist/src/base/A-Command/context/A_Command.context.js.map +1 -0
- package/dist/src/base/A-Command/context/A_CommandFactory.context.js +2 -0
- package/dist/src/base/A-Command/context/A_CommandFactory.context.js.map +1 -0
- package/dist/src/base/A-Config/A-Config.context.d.ts +7 -6
- package/dist/src/base/A-Config/A-Config.context.js +2 -6
- package/dist/src/base/A-Config/A-Config.context.js.map +1 -1
- package/dist/src/base/A-Config/components/ConfigReader.component.js +2 -12
- package/dist/src/base/A-Config/components/ConfigReader.component.js.map +1 -1
- package/dist/src/constants/env.constants.d.ts +26 -0
- package/dist/src/constants/env.constants.js +40 -0
- package/dist/src/constants/env.constants.js.map +1 -0
- package/dist/src/decorators/A-Inject/A-Inject.decorator.d.ts +3 -3
- package/dist/src/decorators/A-Inject/A-Inject.decorator.types.d.ts +9 -10
- package/dist/src/global/A-Channel/A-Channel.class.d.ts +2 -0
- package/dist/src/global/A-Channel/A-Channel.class.js +2 -0
- package/dist/src/global/A-Channel/A-Channel.class.js.map +1 -1
- package/dist/src/global/A-Concept/A_Concept.class.d.ts +5 -3
- package/dist/src/global/A-Concept/A_Concept.class.js +32 -27
- package/dist/src/global/A-Concept/A_Concept.class.js.map +1 -1
- package/dist/src/global/A-Concept/A_Concept.meta.d.ts +1 -8
- package/dist/src/global/A-Concept/A_Concept.meta.js +1 -25
- package/dist/src/global/A-Concept/A_Concept.meta.js.map +1 -1
- package/dist/src/global/A-Concept/A_Concept.types.d.ts +10 -1
- package/dist/src/global/A-Container/A-Container.class.d.ts +5 -0
- package/dist/src/global/A-Container/A-Container.class.js +5 -0
- package/dist/src/global/A-Container/A-Container.class.js.map +1 -1
- package/dist/src/global/A-Context/A-Context.class.d.ts +19 -1
- package/dist/src/global/A-Context/A-Context.class.js +20 -0
- package/dist/src/global/A-Context/A-Context.class.js.map +1 -1
- package/dist/src/global/A-Entity/A-Entity.class.d.ts +124 -23
- package/dist/src/global/A-Entity/A-Entity.class.js +159 -49
- package/dist/src/global/A-Entity/A-Entity.class.js.map +1 -1
- package/dist/src/global/A-Scope/A-Scope.class.d.ts +7 -6
- package/dist/src/global/A-Scope/A-Scope.class.js +57 -20
- package/dist/src/global/A-Scope/A-Scope.class.js.map +1 -1
- package/dist/src/global/A-Stage/A-Stage.class.d.ts +3 -2
- package/dist/src/global/A-Stage/A-Stage.class.js +9 -6
- package/dist/src/global/A-Stage/A-Stage.class.js.map +1 -1
- package/dist/src/global/A-Stage/A-Stage.types.d.ts +1 -1
- package/dist/src/helpers/StepsManager.class.js +1 -1
- package/dist/src/helpers/StepsManager.class.js.map +1 -1
- package/examples/simple/components/A.component.ts +9 -2
- package/examples/simple/concept.ts +6 -0
- package/examples/simple/entities/EntityA.entity.ts +18 -0
- package/jest.config.ts +1 -1
- package/package.json +3 -3
- package/src/base/A-Command/A_Command.constants.ts +20 -0
- package/src/base/A-Command/A_Command.entity.ts +287 -0
- package/src/base/A-Command/A_Command.types.ts +34 -0
- package/src/base/A-Command/context/A_Command.context.ts +114 -0
- package/src/base/A-Command/context/A_CommandFactory.context.ts +0 -0
- package/src/base/A-Config/A-Config.context.ts +13 -17
- package/src/base/A-Config/components/ConfigReader.component.ts +2 -15
- package/src/constants/env.constants.ts +47 -0
- package/src/decorators/A-Inject/A-Inject.decorator.ts +3 -3
- package/src/decorators/A-Inject/A-Inject.decorator.types.ts +10 -9
- package/src/global/A-Channel/A-Channel.class.ts +2 -0
- package/src/global/A-Concept/A_Concept.class.ts +49 -32
- package/src/global/A-Concept/A_Concept.meta.ts +3 -41
- package/src/global/A-Concept/A_Concept.types.ts +6 -4
- package/src/global/A-Container/A-Container.class.ts +5 -2
- package/src/global/A-Context/A-Context.class.ts +44 -7
- package/src/global/A-Entity/A-Entity.class.ts +203 -73
- package/src/global/A-Scope/A-Scope.class.ts +88 -39
- package/src/global/A-Stage/A-Stage.class.ts +11 -7
- package/src/global/A-Stage/A-Stage.types.ts +1 -1
- package/src/helpers/StepsManager.class.ts +2 -2
- package/tests/A-Command.test.ts +130 -0
- package/tests/A-Component.test.ts +25 -0
- package/tests/A-Entity.test.ts +186 -0
- package/tests/A-Feature.test.ts +131 -0
- package/tests/A-Scope.test.ts +163 -0
- package/dist/src/constants/A_ConceptLifecycle.constants.js +0 -11
- package/dist/src/constants/A_ConceptLifecycle.constants.js.map +0 -1
- package/src/constants/A_ConceptLifecycle.constants.ts +0 -12
- package/tests/channel.ts +0 -213
- package/tests/context.test.ts +0 -124
- package/tests/default.test.ts +0 -159
- package/tests/log.ts +0 -102
- package/tests/polyfill.test.ts +0 -37
- /package/dist/src/{constants/A_ConceptLifecycle.constants.d.ts → base/A-Command/context/A_CommandFactory.context.d.ts} +0 -0
package/.nvmrc
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
|
|
1
|
+
v22.20.0
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export declare enum A_CONSTANTS__A_Command_Status {
|
|
2
|
+
INITIALIZED = "INITIALIZED",
|
|
3
|
+
IN_PROGRESS = "IN_PROGRESS",
|
|
4
|
+
COMPLETED = "COMPLETED",
|
|
5
|
+
FAILED = "FAILED"
|
|
6
|
+
}
|
|
7
|
+
export declare enum A_CONSTANTS_A_Command_Features {
|
|
8
|
+
EXECUTE = "execute",
|
|
9
|
+
COMPLETE = "complete",
|
|
10
|
+
FAIL = "fail"
|
|
11
|
+
}
|
|
12
|
+
export type A_CONSTANTS__A_Command_Event = 'create' | 'start' | 'execute' | 'complete' | 'fail';
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.A_CONSTANTS_A_Command_Features = exports.A_CONSTANTS__A_Command_Status = void 0;
|
|
4
|
+
var A_CONSTANTS__A_Command_Status;
|
|
5
|
+
(function (A_CONSTANTS__A_Command_Status) {
|
|
6
|
+
A_CONSTANTS__A_Command_Status["INITIALIZED"] = "INITIALIZED";
|
|
7
|
+
A_CONSTANTS__A_Command_Status["IN_PROGRESS"] = "IN_PROGRESS";
|
|
8
|
+
A_CONSTANTS__A_Command_Status["COMPLETED"] = "COMPLETED";
|
|
9
|
+
A_CONSTANTS__A_Command_Status["FAILED"] = "FAILED";
|
|
10
|
+
})(A_CONSTANTS__A_Command_Status || (exports.A_CONSTANTS__A_Command_Status = A_CONSTANTS__A_Command_Status = {}));
|
|
11
|
+
var A_CONSTANTS_A_Command_Features;
|
|
12
|
+
(function (A_CONSTANTS_A_Command_Features) {
|
|
13
|
+
A_CONSTANTS_A_Command_Features["EXECUTE"] = "execute";
|
|
14
|
+
A_CONSTANTS_A_Command_Features["COMPLETE"] = "complete";
|
|
15
|
+
A_CONSTANTS_A_Command_Features["FAIL"] = "fail";
|
|
16
|
+
})(A_CONSTANTS_A_Command_Features || (exports.A_CONSTANTS_A_Command_Features = A_CONSTANTS_A_Command_Features = {}));
|
|
17
|
+
//# sourceMappingURL=A_Command.constants.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"A_Command.constants.js","sourceRoot":"","sources":["../../../../src/base/A-Command/A_Command.constants.ts"],"names":[],"mappings":";;;AAEA,IAAY,6BAKX;AALD,WAAY,6BAA6B;IACrC,4DAA2B,CAAA;IAC3B,4DAA2B,CAAA;IAC3B,wDAAuB,CAAA;IACvB,kDAAiB,CAAA;AACrB,CAAC,EALW,6BAA6B,6CAA7B,6BAA6B,QAKxC;AAED,IAAY,8BAIX;AAJD,WAAY,8BAA8B;IACtC,qDAAmB,CAAA;IACnB,uDAAqB,CAAA;IACrB,+CAAa,CAAA;AACjB,CAAC,EAJW,8BAA8B,8CAA9B,8BAA8B,QAIzC"}
|
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
import { A_Entity } from "../../global/A-Entity/A-Entity.class";
|
|
2
|
+
import { A_TYPES__Command_Constructor, A_TYPES__Command_Listener, A_TYPES__Command_Serialized } from "./A_Command.types";
|
|
3
|
+
import { A_Error } from "@adaas/a-utils";
|
|
4
|
+
import { A_Scope } from "../../global/A-Scope/A-Scope.class";
|
|
5
|
+
import { A_CONSTANTS__A_Command_Event, A_CONSTANTS__A_Command_Status, A_CONSTANTS_A_Command_Features } from "./A_Command.constants";
|
|
6
|
+
export declare class A_Command<InvokeType extends A_TYPES__Command_Constructor = A_TYPES__Command_Constructor, ResultType extends Record<string, any> = Record<string, any>> extends A_Entity<InvokeType, A_TYPES__Command_Serialized<ResultType>> {
|
|
7
|
+
protected _scope: A_Scope;
|
|
8
|
+
protected _result?: ResultType;
|
|
9
|
+
protected _errors?: Set<A_Error>;
|
|
10
|
+
protected _params: InvokeType;
|
|
11
|
+
protected _status: A_CONSTANTS__A_Command_Status;
|
|
12
|
+
protected _listeners: Map<A_CONSTANTS__A_Command_Event, Set<A_TYPES__Command_Listener<ResultType>>>;
|
|
13
|
+
protected _startTime?: Date;
|
|
14
|
+
protected _endTime?: Date;
|
|
15
|
+
/**
|
|
16
|
+
* Execution Duration in milliseconds
|
|
17
|
+
*/
|
|
18
|
+
get Duration(): number | undefined;
|
|
19
|
+
/**
|
|
20
|
+
* Command Execution A-Scope that inherits from scope where command was created
|
|
21
|
+
*
|
|
22
|
+
* Command execution context is stored in A_CommandContext fragment within this scope
|
|
23
|
+
*/
|
|
24
|
+
get Scope(): A_Scope;
|
|
25
|
+
/**
|
|
26
|
+
* Unique code identifying the command type
|
|
27
|
+
* Example: 'user.create', 'task.complete', etc.
|
|
28
|
+
*
|
|
29
|
+
*/
|
|
30
|
+
get Code(): string;
|
|
31
|
+
/**
|
|
32
|
+
* Current status of the command
|
|
33
|
+
*/
|
|
34
|
+
get Status(): A_CONSTANTS__A_Command_Status;
|
|
35
|
+
/**
|
|
36
|
+
* Start time of the command execution
|
|
37
|
+
*/
|
|
38
|
+
get StartedAt(): Date | undefined;
|
|
39
|
+
/**
|
|
40
|
+
* End time of the command execution
|
|
41
|
+
*/
|
|
42
|
+
get EndedAt(): Date | undefined;
|
|
43
|
+
/**
|
|
44
|
+
* Result of the command execution stored in the context
|
|
45
|
+
*/
|
|
46
|
+
get Result(): ResultType | undefined;
|
|
47
|
+
/**
|
|
48
|
+
* Errors encountered during the command execution stored in the context
|
|
49
|
+
*/
|
|
50
|
+
get Errors(): Set<A_Error> | undefined;
|
|
51
|
+
/**
|
|
52
|
+
* Parameters used to invoke the command
|
|
53
|
+
*/
|
|
54
|
+
get Params(): InvokeType;
|
|
55
|
+
/**
|
|
56
|
+
*
|
|
57
|
+
* A-Command represents an executable command with a specific code and parameters.
|
|
58
|
+
* It can be executed within a given scope and stores execution results and errors.
|
|
59
|
+
*
|
|
60
|
+
*
|
|
61
|
+
* A-Command should be context independent and execution logic should be based on attached components
|
|
62
|
+
*
|
|
63
|
+
* @param code
|
|
64
|
+
* @param params
|
|
65
|
+
*/
|
|
66
|
+
constructor(
|
|
67
|
+
/**
|
|
68
|
+
* Command invocation parameters
|
|
69
|
+
*/
|
|
70
|
+
params: InvokeType | A_TYPES__Command_Serialized<ResultType>);
|
|
71
|
+
/**
|
|
72
|
+
* Executes the command logic.
|
|
73
|
+
*/
|
|
74
|
+
[A_CONSTANTS_A_Command_Features.EXECUTE](): Promise<any>;
|
|
75
|
+
/**
|
|
76
|
+
* Marks the command as completed
|
|
77
|
+
*/
|
|
78
|
+
[A_CONSTANTS_A_Command_Features.COMPLETE](): Promise<void>;
|
|
79
|
+
/**
|
|
80
|
+
* Marks the command as failed
|
|
81
|
+
*/
|
|
82
|
+
[A_CONSTANTS_A_Command_Features.FAIL](): Promise<void>;
|
|
83
|
+
/**
|
|
84
|
+
* Registers an event listener for a specific event
|
|
85
|
+
*
|
|
86
|
+
* @param event
|
|
87
|
+
* @param listener
|
|
88
|
+
*/
|
|
89
|
+
on(event: A_CONSTANTS__A_Command_Event, listener: A_TYPES__Command_Listener<ResultType>): void;
|
|
90
|
+
/**
|
|
91
|
+
* Removes an event listener for a specific event
|
|
92
|
+
*
|
|
93
|
+
* @param event
|
|
94
|
+
* @param listener
|
|
95
|
+
*/
|
|
96
|
+
off(event: A_CONSTANTS__A_Command_Event, listener: A_TYPES__Command_Listener<ResultType>): void;
|
|
97
|
+
/**
|
|
98
|
+
* Emits an event to all registered listeners
|
|
99
|
+
*
|
|
100
|
+
* @param event
|
|
101
|
+
*/
|
|
102
|
+
emit(event: A_CONSTANTS__A_Command_Event): void;
|
|
103
|
+
/**
|
|
104
|
+
* Allows to create a Command instance from new data
|
|
105
|
+
*
|
|
106
|
+
* @param newEntity
|
|
107
|
+
*/
|
|
108
|
+
fromNew(newEntity: InvokeType): void;
|
|
109
|
+
/**
|
|
110
|
+
* Allows to convert serialized data to Command instance
|
|
111
|
+
*
|
|
112
|
+
* [!] By default it omits params as they are not stored in the serialized data
|
|
113
|
+
*
|
|
114
|
+
* @param serialized
|
|
115
|
+
*/
|
|
116
|
+
fromJSON(serialized: A_TYPES__Command_Serialized<ResultType>): void;
|
|
117
|
+
/**
|
|
118
|
+
* Converts the Command instance to a plain object
|
|
119
|
+
*
|
|
120
|
+
* @returns
|
|
121
|
+
*/
|
|
122
|
+
toJSON(): A_TYPES__Command_Serialized<ResultType>;
|
|
123
|
+
}
|
|
@@ -0,0 +1,259 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
+
};
|
|
8
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
9
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
10
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
11
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
12
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
13
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
14
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
15
|
+
});
|
|
16
|
+
};
|
|
17
|
+
var _a, _b, _c;
|
|
18
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
19
|
+
exports.A_Command = void 0;
|
|
20
|
+
const A_Entity_class_1 = require("../../global/A-Entity/A-Entity.class");
|
|
21
|
+
const a_utils_1 = require("@adaas/a-utils");
|
|
22
|
+
const A_Scope_class_1 = require("../../global/A-Scope/A-Scope.class");
|
|
23
|
+
const A_Feature_class_1 = require("../../global/A-Feature/A-Feature.class");
|
|
24
|
+
const A_Command_context_1 = require("./context/A_Command.context");
|
|
25
|
+
const A_Command_constants_1 = require("./A_Command.constants");
|
|
26
|
+
class A_Command extends A_Entity_class_1.A_Entity {
|
|
27
|
+
/**
|
|
28
|
+
* Execution Duration in milliseconds
|
|
29
|
+
*/
|
|
30
|
+
get Duration() {
|
|
31
|
+
return this._endTime && this._startTime
|
|
32
|
+
? this._endTime.getTime() - this._startTime.getTime()
|
|
33
|
+
: this._startTime
|
|
34
|
+
? new Date().getTime() - this._startTime.getTime()
|
|
35
|
+
: undefined;
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Command Execution A-Scope that inherits from scope where command was created
|
|
39
|
+
*
|
|
40
|
+
* Command execution context is stored in A_CommandContext fragment within this scope
|
|
41
|
+
*/
|
|
42
|
+
get Scope() {
|
|
43
|
+
return this._scope;
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Unique code identifying the command type
|
|
47
|
+
* Example: 'user.create', 'task.complete', etc.
|
|
48
|
+
*
|
|
49
|
+
*/
|
|
50
|
+
get Code() {
|
|
51
|
+
return this.constructor.name;
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Current status of the command
|
|
55
|
+
*/
|
|
56
|
+
get Status() {
|
|
57
|
+
return this._status;
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* Start time of the command execution
|
|
61
|
+
*/
|
|
62
|
+
get StartedAt() {
|
|
63
|
+
return this._startTime;
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* End time of the command execution
|
|
67
|
+
*/
|
|
68
|
+
get EndedAt() {
|
|
69
|
+
return this._endTime;
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* Result of the command execution stored in the context
|
|
73
|
+
*/
|
|
74
|
+
get Result() {
|
|
75
|
+
return this._result;
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* Errors encountered during the command execution stored in the context
|
|
79
|
+
*/
|
|
80
|
+
get Errors() {
|
|
81
|
+
return this._errors;
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* Parameters used to invoke the command
|
|
85
|
+
*/
|
|
86
|
+
get Params() {
|
|
87
|
+
return this._params;
|
|
88
|
+
}
|
|
89
|
+
/**
|
|
90
|
+
*
|
|
91
|
+
* A-Command represents an executable command with a specific code and parameters.
|
|
92
|
+
* It can be executed within a given scope and stores execution results and errors.
|
|
93
|
+
*
|
|
94
|
+
*
|
|
95
|
+
* A-Command should be context independent and execution logic should be based on attached components
|
|
96
|
+
*
|
|
97
|
+
* @param code
|
|
98
|
+
* @param params
|
|
99
|
+
*/
|
|
100
|
+
constructor(
|
|
101
|
+
/**
|
|
102
|
+
* Command invocation parameters
|
|
103
|
+
*/
|
|
104
|
+
params) {
|
|
105
|
+
super(params);
|
|
106
|
+
this._listeners = new Map();
|
|
107
|
+
}
|
|
108
|
+
// --------------------------------------------------------------------------
|
|
109
|
+
// A-Command Core Features
|
|
110
|
+
// --------------------------------------------------------------------------
|
|
111
|
+
/**
|
|
112
|
+
* Executes the command logic.
|
|
113
|
+
*/
|
|
114
|
+
[_a = A_Command_constants_1.A_CONSTANTS_A_Command_Features.EXECUTE]() {
|
|
115
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
116
|
+
this._status = A_Command_constants_1.A_CONSTANTS__A_Command_Status.IN_PROGRESS;
|
|
117
|
+
this._startTime = new Date();
|
|
118
|
+
try {
|
|
119
|
+
yield this.call('execute', this._scope);
|
|
120
|
+
yield this.complete();
|
|
121
|
+
}
|
|
122
|
+
catch (error) {
|
|
123
|
+
yield this.fail();
|
|
124
|
+
}
|
|
125
|
+
});
|
|
126
|
+
}
|
|
127
|
+
/**
|
|
128
|
+
* Marks the command as completed
|
|
129
|
+
*/
|
|
130
|
+
[_b = A_Command_constants_1.A_CONSTANTS_A_Command_Features.COMPLETE]() {
|
|
131
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
132
|
+
this._status = A_Command_constants_1.A_CONSTANTS__A_Command_Status.COMPLETED;
|
|
133
|
+
this._endTime = new Date();
|
|
134
|
+
this._result = this.Scope.resolve(A_Command_context_1.A_CommandContext).toJSON();
|
|
135
|
+
this.call('complete', this._scope);
|
|
136
|
+
});
|
|
137
|
+
}
|
|
138
|
+
/**
|
|
139
|
+
* Marks the command as failed
|
|
140
|
+
*/
|
|
141
|
+
[_c = A_Command_constants_1.A_CONSTANTS_A_Command_Features.FAIL]() {
|
|
142
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
143
|
+
this._status = A_Command_constants_1.A_CONSTANTS__A_Command_Status.FAILED;
|
|
144
|
+
this._endTime = new Date();
|
|
145
|
+
this._errors = this.Scope.resolve(A_Command_context_1.A_CommandContext).Errors;
|
|
146
|
+
this.call('fail', this._scope);
|
|
147
|
+
});
|
|
148
|
+
}
|
|
149
|
+
// --------------------------------------------------------------------------
|
|
150
|
+
// A-Command Event-Emitter methods
|
|
151
|
+
// --------------------------------------------------------------------------
|
|
152
|
+
/**
|
|
153
|
+
* Registers an event listener for a specific event
|
|
154
|
+
*
|
|
155
|
+
* @param event
|
|
156
|
+
* @param listener
|
|
157
|
+
*/
|
|
158
|
+
on(event, listener) {
|
|
159
|
+
if (!this._listeners.has(event)) {
|
|
160
|
+
this._listeners.set(event, new Set());
|
|
161
|
+
}
|
|
162
|
+
this._listeners.get(event).add(listener);
|
|
163
|
+
}
|
|
164
|
+
/**
|
|
165
|
+
* Removes an event listener for a specific event
|
|
166
|
+
*
|
|
167
|
+
* @param event
|
|
168
|
+
* @param listener
|
|
169
|
+
*/
|
|
170
|
+
off(event, listener) {
|
|
171
|
+
var _d;
|
|
172
|
+
(_d = this._listeners.get(event)) === null || _d === void 0 ? void 0 : _d.delete(listener);
|
|
173
|
+
}
|
|
174
|
+
/**
|
|
175
|
+
* Emits an event to all registered listeners
|
|
176
|
+
*
|
|
177
|
+
* @param event
|
|
178
|
+
*/
|
|
179
|
+
emit(event) {
|
|
180
|
+
var _d;
|
|
181
|
+
(_d = this._listeners.get(event)) === null || _d === void 0 ? void 0 : _d.forEach(listener => {
|
|
182
|
+
listener(this);
|
|
183
|
+
});
|
|
184
|
+
}
|
|
185
|
+
// --------------------------------------------------------------------------
|
|
186
|
+
// A-Entity Base Class Overrides
|
|
187
|
+
// --------------------------------------------------------------------------
|
|
188
|
+
// Serialization / Deserialization
|
|
189
|
+
// -------------------------------------------------------------------------
|
|
190
|
+
/**
|
|
191
|
+
* Allows to create a Command instance from new data
|
|
192
|
+
*
|
|
193
|
+
* @param newEntity
|
|
194
|
+
*/
|
|
195
|
+
fromNew(newEntity) {
|
|
196
|
+
super.fromNew(newEntity);
|
|
197
|
+
this._params = newEntity;
|
|
198
|
+
this._status = A_Command_constants_1.A_CONSTANTS__A_Command_Status.INITIALIZED;
|
|
199
|
+
this._scope = new A_Scope_class_1.A_Scope({
|
|
200
|
+
name: `a-command-scope::${this.id}`,
|
|
201
|
+
fragments: [
|
|
202
|
+
new A_Command_context_1.A_CommandContext()
|
|
203
|
+
]
|
|
204
|
+
});
|
|
205
|
+
}
|
|
206
|
+
/**
|
|
207
|
+
* Allows to convert serialized data to Command instance
|
|
208
|
+
*
|
|
209
|
+
* [!] By default it omits params as they are not stored in the serialized data
|
|
210
|
+
*
|
|
211
|
+
* @param serialized
|
|
212
|
+
*/
|
|
213
|
+
fromJSON(serialized) {
|
|
214
|
+
super.fromJSON(serialized);
|
|
215
|
+
if (serialized.startedAt)
|
|
216
|
+
this._startTime = new Date(serialized.startedAt);
|
|
217
|
+
if (serialized.endedAt)
|
|
218
|
+
this._endTime = new Date(serialized.endedAt);
|
|
219
|
+
const context = new A_Command_context_1.A_CommandContext();
|
|
220
|
+
this._scope = new A_Scope_class_1.A_Scope({
|
|
221
|
+
name: `a-command-scope::${this.id}`,
|
|
222
|
+
fragments: [
|
|
223
|
+
context
|
|
224
|
+
]
|
|
225
|
+
});
|
|
226
|
+
// Restore result and errors in the context
|
|
227
|
+
if (serialized.result) {
|
|
228
|
+
Object.entries(serialized.result).forEach(([key, value]) => {
|
|
229
|
+
context.save(key, value);
|
|
230
|
+
});
|
|
231
|
+
}
|
|
232
|
+
if (serialized.errors) {
|
|
233
|
+
serialized.errors.forEach(err => {
|
|
234
|
+
context.error(new a_utils_1.A_Error(err));
|
|
235
|
+
});
|
|
236
|
+
}
|
|
237
|
+
this._status = serialized.status || A_Command_constants_1.A_CONSTANTS__A_Command_Status.INITIALIZED;
|
|
238
|
+
}
|
|
239
|
+
/**
|
|
240
|
+
* Converts the Command instance to a plain object
|
|
241
|
+
*
|
|
242
|
+
* @returns
|
|
243
|
+
*/
|
|
244
|
+
toJSON() {
|
|
245
|
+
return Object.assign(Object.assign({}, super.toJSON()), { code: this.Code, status: this._status, startedAt: this._startTime ? this._startTime.toISOString() : undefined, endedAt: this._endTime ? this._endTime.toISOString() : undefined, duration: this.Duration, result: this.Result, errors: this.Errors ? Array.from(this.Errors).map(err => err.toJSON()) : undefined });
|
|
246
|
+
}
|
|
247
|
+
;
|
|
248
|
+
}
|
|
249
|
+
exports.A_Command = A_Command;
|
|
250
|
+
__decorate([
|
|
251
|
+
A_Feature_class_1.A_Feature.Define()
|
|
252
|
+
], A_Command.prototype, _a, null);
|
|
253
|
+
__decorate([
|
|
254
|
+
A_Feature_class_1.A_Feature.Define()
|
|
255
|
+
], A_Command.prototype, _b, null);
|
|
256
|
+
__decorate([
|
|
257
|
+
A_Feature_class_1.A_Feature.Define()
|
|
258
|
+
], A_Command.prototype, _c, null);
|
|
259
|
+
//# sourceMappingURL=A_Command.entity.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"A_Command.entity.js","sourceRoot":"","sources":["../../../../src/base/A-Command/A_Command.entity.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;AAAA,oFAA2E;AAE3E,4CAAyC;AACzC,iFAAwE;AACxE,uFAA8E;AAC9E,mEAA+D;AAC/D,+DAAoI;AAGpI,MAAa,SAGX,SAAQ,yBAGT;IAcG;;OAEG;IACH,IAAI,QAAQ;QACR,OAAO,IAAI,CAAC,QAAQ,IAAI,IAAI,CAAC,UAAU;YACnC,CAAC,CAAC,IAAI,CAAC,QAAQ,CAAC,OAAO,EAAE,GAAG,IAAI,CAAC,UAAU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AM,CAAC,CAAC,CAAC,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,GAAG,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,CAAC,MAAM,EAAE,CAAC,CAAC,CAAC,CAAC,SAAS,IACrF;IACL,CAAC;IAAA,CAAC;CAEL;AArRD,8BAqRC;AAhKS;IADL,2BAAS,CAAC,MAAM,EAAE;iCAUlB;AAMK;IADL,2BAAS,CAAC,MAAM,EAAE;iCAOlB;AAOK;IADL,2BAAS,CAAC,MAAM,EAAE;iCAOlB"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { A_TYPES__Entity_JSON } from "../../global/A-Entity/A-Entity.types";
|
|
2
|
+
import { A_Command } from "./A_Command.entity";
|
|
3
|
+
import { A_CONSTANTS__A_Command_Status } from "./A_Command.constants";
|
|
4
|
+
import { A_TYPES__Error } from "@adaas/a-utils";
|
|
5
|
+
export type A_TYPES__Command_Constructor = {};
|
|
6
|
+
export type A_TYPES__Command_Serialized<ResultType extends Record<string, any> = Record<string, any>> = {
|
|
7
|
+
code: string;
|
|
8
|
+
status: A_CONSTANTS__A_Command_Status;
|
|
9
|
+
startedAt?: string;
|
|
10
|
+
endedAt?: string;
|
|
11
|
+
duration?: number;
|
|
12
|
+
result?: ResultType;
|
|
13
|
+
errors?: Array<A_TYPES__Error>;
|
|
14
|
+
} & A_TYPES__Entity_JSON;
|
|
15
|
+
export type A_TYPES__Command_Listener<T extends Record<string, any> = Record<string, any>> = (command?: A_Command<any, T>) => void;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"A_Command.types.js","sourceRoot":"","sources":["../../../../src/base/A-Command/A_Command.types.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import { A_Fragment } from "../../../global/A-Fragment/A-Fragment.class";
|
|
2
|
+
import { A_Error } from "@adaas/a-utils";
|
|
3
|
+
export declare class A_CommandContext<T extends Record<string, any> = Record<string, any>> extends A_Fragment {
|
|
4
|
+
/**
|
|
5
|
+
* Internal storage of all intermediate values
|
|
6
|
+
*/
|
|
7
|
+
protected _memory: Map<keyof T, T[keyof T]>;
|
|
8
|
+
/**
|
|
9
|
+
* Errors encountered during the execution
|
|
10
|
+
*/
|
|
11
|
+
protected _errors: Set<A_Error>;
|
|
12
|
+
/**
|
|
13
|
+
* ExecutionContext for the A-Command
|
|
14
|
+
*
|
|
15
|
+
*/
|
|
16
|
+
constructor(initialValues?: T);
|
|
17
|
+
get Errors(): Set<A_Error> | undefined;
|
|
18
|
+
/**
|
|
19
|
+
* Verifies that all required keys are present in the proxy values
|
|
20
|
+
*
|
|
21
|
+
* @param requiredKeys
|
|
22
|
+
* @returns
|
|
23
|
+
*/
|
|
24
|
+
verifyPrerequisites(requiredKeys: Array<keyof T>): boolean;
|
|
25
|
+
/**
|
|
26
|
+
* Adds an error to the context
|
|
27
|
+
*
|
|
28
|
+
* @param error
|
|
29
|
+
*/
|
|
30
|
+
error(error: A_Error): void;
|
|
31
|
+
/**
|
|
32
|
+
* Saves a value in the context memory
|
|
33
|
+
*
|
|
34
|
+
* @param key
|
|
35
|
+
* @param value
|
|
36
|
+
*/
|
|
37
|
+
save<K extends keyof T>(
|
|
38
|
+
/**
|
|
39
|
+
* Key to save the value under
|
|
40
|
+
*/
|
|
41
|
+
key: K,
|
|
42
|
+
/**
|
|
43
|
+
* Value to save
|
|
44
|
+
*/
|
|
45
|
+
value: T[K]): void;
|
|
46
|
+
/**
|
|
47
|
+
* Removes a value from the context memory by key
|
|
48
|
+
*
|
|
49
|
+
* @param key
|
|
50
|
+
*/
|
|
51
|
+
drop(key: keyof T): void;
|
|
52
|
+
/**
|
|
53
|
+
* Clears all stored values in the context memory
|
|
54
|
+
*/
|
|
55
|
+
clear(): void;
|
|
56
|
+
/**
|
|
57
|
+
* Converts all stored values to a plain object
|
|
58
|
+
*
|
|
59
|
+
* [!] By default uses all saved in memory values
|
|
60
|
+
*
|
|
61
|
+
* @returns
|
|
62
|
+
*/
|
|
63
|
+
toJSON(): Record<string, any>;
|
|
64
|
+
}
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.A_CommandContext = void 0;
|
|
4
|
+
const A_Fragment_class_1 = require("../../../global/A-Fragment/A-Fragment.class");
|
|
5
|
+
class A_CommandContext extends A_Fragment_class_1.A_Fragment {
|
|
6
|
+
/**
|
|
7
|
+
* ExecutionContext for the A-Command
|
|
8
|
+
*
|
|
9
|
+
*/
|
|
10
|
+
constructor(initialValues = {}) {
|
|
11
|
+
super();
|
|
12
|
+
this._memory = new Map(Object.entries(initialValues));
|
|
13
|
+
this._errors = new Set();
|
|
14
|
+
}
|
|
15
|
+
get Errors() {
|
|
16
|
+
return this._errors.size > 0 ? this._errors : undefined;
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Verifies that all required keys are present in the proxy values
|
|
20
|
+
*
|
|
21
|
+
* @param requiredKeys
|
|
22
|
+
* @returns
|
|
23
|
+
*/
|
|
24
|
+
verifyPrerequisites(requiredKeys) {
|
|
25
|
+
return requiredKeys.every(key => this._memory.has(key));
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Adds an error to the context
|
|
29
|
+
*
|
|
30
|
+
* @param error
|
|
31
|
+
*/
|
|
32
|
+
error(error) {
|
|
33
|
+
this._errors.add(error);
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Saves a value in the context memory
|
|
37
|
+
*
|
|
38
|
+
* @param key
|
|
39
|
+
* @param value
|
|
40
|
+
*/
|
|
41
|
+
save(
|
|
42
|
+
/**
|
|
43
|
+
* Key to save the value under
|
|
44
|
+
*/
|
|
45
|
+
key,
|
|
46
|
+
/**
|
|
47
|
+
* Value to save
|
|
48
|
+
*/
|
|
49
|
+
value) {
|
|
50
|
+
this._memory.set(key, value);
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Removes a value from the context memory by key
|
|
54
|
+
*
|
|
55
|
+
* @param key
|
|
56
|
+
*/
|
|
57
|
+
drop(key) {
|
|
58
|
+
this._memory.delete(key);
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* Clears all stored values in the context memory
|
|
62
|
+
*/
|
|
63
|
+
clear() {
|
|
64
|
+
this._memory.clear();
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* Converts all stored values to a plain object
|
|
68
|
+
*
|
|
69
|
+
* [!] By default uses all saved in memory values
|
|
70
|
+
*
|
|
71
|
+
* @returns
|
|
72
|
+
*/
|
|
73
|
+
toJSON() {
|
|
74
|
+
const obj = {};
|
|
75
|
+
this._memory.forEach((value, key) => {
|
|
76
|
+
obj[key] =
|
|
77
|
+
typeof value === 'object' && value !== null && 'toJSON' in value && typeof value.toJSON === 'function'
|
|
78
|
+
? value.toJSON()
|
|
79
|
+
: value;
|
|
80
|
+
});
|
|
81
|
+
return obj;
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
exports.A_CommandContext = A_CommandContext;
|
|
85
|
+
//# sourceMappingURL=A_Command.context.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"A_Command.context.js","sourceRoot":"","sources":["../../../../../src/base/A-Command/context/A_Command.context.ts"],"names":[],"mappings":";;;AAAA,0FAAiF;AAIjF,MAAa,gBAEX,SAAQ,6BAAU;IAchB;;;OAGG;IACH,YAAY,gBAAmB,EAAO;QAClC,KAAK,EAAE,CAAC;QACR,IAAI,CAAC,OAAO,GAAG,IAAI,GAAG,CAAC,MAAM,CAAC,OAAO,CAAC,aAAa,CAAC,CAAC,CAAC;QACtD,IAAI,CAAC,OAAO,GAAG,IAAI,GAAG,EAAE,CAAC;IAC7B,CAAC;IAGD,IAAI,MAAM;QACN,OAAO,IAAI,CAAC,OAAO,CAAC,IAAI,GAAG,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,OAAO,CAAC,CA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actory.context.ts"],"names":[],"mappings":""}
|
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
import { A_TYPES__Required } from "@adaas/a-utils";
|
|
2
2
|
import { A_TYPES__ConfigContainerConstructor } from "./A-Config.types";
|
|
3
3
|
import { A_Fragment } from "../../global/A-Fragment/A-Fragment.class";
|
|
4
|
-
|
|
4
|
+
import { A_CONSTANTS__DEFAULT_ENV_VARIABLES_ARRAY, A_TYPES__ConceptENVVariables } from "../../constants/env.constants";
|
|
5
|
+
export declare class A_Config<T extends string = A_TYPES__ConceptENVVariables> extends A_Fragment {
|
|
5
6
|
config: A_TYPES__ConfigContainerConstructor<T>;
|
|
6
7
|
private VARIABLES;
|
|
7
8
|
CONFIG_PROPERTIES: T[];
|
|
8
|
-
protected DEFAULT_ALLOWED_TO_READ_PROPERTIES: readonly ["
|
|
9
|
+
protected DEFAULT_ALLOWED_TO_READ_PROPERTIES: readonly ["A_CONCEPT_NAMESPACE", "A_CONCEPT_ENVIRONMENT", "A_CONCEPT_ROOT_FOLDER", "CONFIG_VERBOSE", "CONFIG_IGNORE_ERRORS"];
|
|
9
10
|
constructor(config: A_TYPES__Required<Partial<A_TYPES__ConfigContainerConstructor<T>>, ['variables']>);
|
|
10
11
|
protected onInit(): Promise<void>;
|
|
11
12
|
/**
|
|
@@ -22,10 +23,10 @@ export declare class A_Config<T extends string = any> extends A_Fragment {
|
|
|
22
23
|
*
|
|
23
24
|
* @param variables
|
|
24
25
|
*/
|
|
25
|
-
set
|
|
26
|
-
property:
|
|
26
|
+
set(variables: Array<{
|
|
27
|
+
property: T | typeof A_CONSTANTS__DEFAULT_ENV_VARIABLES_ARRAY[number];
|
|
27
28
|
value: any;
|
|
28
29
|
}>): any;
|
|
29
|
-
set<
|
|
30
|
-
set
|
|
30
|
+
set(variables: Partial<Record<T | typeof A_CONSTANTS__DEFAULT_ENV_VARIABLES_ARRAY[number], any>>): any;
|
|
31
|
+
set(property: T | typeof A_CONSTANTS__DEFAULT_ENV_VARIABLES_ARRAY[number], value: any): any;
|
|
31
32
|
}
|
|
@@ -12,18 +12,14 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
12
12
|
exports.A_Config = void 0;
|
|
13
13
|
const a_utils_1 = require("@adaas/a-utils");
|
|
14
14
|
const A_Fragment_class_1 = require("../../global/A-Fragment/A-Fragment.class");
|
|
15
|
+
const env_constants_1 = require("../../constants/env.constants");
|
|
15
16
|
class A_Config extends A_Fragment_class_1.A_Fragment {
|
|
16
17
|
constructor(config) {
|
|
17
18
|
super(config);
|
|
18
19
|
// Custom properties
|
|
19
20
|
this.VARIABLES = new Map();
|
|
20
21
|
this.CONFIG_PROPERTIES = [];
|
|
21
|
-
this.DEFAULT_ALLOWED_TO_READ_PROPERTIES =
|
|
22
|
-
'CONFIG_SDK_VALIDATION',
|
|
23
|
-
'CONFIG_VERBOSE',
|
|
24
|
-
'CONFIG_IGNORE_ERRORS',
|
|
25
|
-
'CONCEPT_ROOT_FOLDER',
|
|
26
|
-
];
|
|
22
|
+
this.DEFAULT_ALLOWED_TO_READ_PROPERTIES = env_constants_1.A_CONSTANTS__DEFAULT_ENV_VARIABLES_ARRAY;
|
|
27
23
|
this.config = a_utils_1.A_CommonHelper.deepCloneAndMerge(config, {
|
|
28
24
|
name: this.name,
|
|
29
25
|
strict: false,
|