@adaas/a-utils 0.1.12 → 0.1.13
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.d.mts +8 -0
- package/dist/index.d.ts +8 -0
- package/dist/index.js +37 -9
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +37 -9
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
- package/src/lib/A-Command/A-Command.entity.ts +49 -8
- package/src/lib/A-Command/A-Command.error.ts +2 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@adaas/a-utils",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.13",
|
|
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
|
"main": "./dist/index.js",
|
|
6
6
|
"module": "./dist/index.mjs",
|
|
@@ -9,6 +9,7 @@ import {
|
|
|
9
9
|
} from "./A-Command.constants";
|
|
10
10
|
import { A_Context, A_Entity, A_Error, A_Scope } from "@adaas/a-concept";
|
|
11
11
|
import { A_Memory } from "../A-Memory/A-Memory.context";
|
|
12
|
+
import { A_CommandError } from "./A-Command.error";
|
|
12
13
|
|
|
13
14
|
|
|
14
15
|
export class A_Command<
|
|
@@ -155,9 +156,8 @@ export class A_Command<
|
|
|
155
156
|
|
|
156
157
|
this._status = A_CONSTANTS__A_Command_Status.INITIALIZATION;
|
|
157
158
|
this._startTime = new Date();
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
}
|
|
159
|
+
|
|
160
|
+
this.checkScopeInheritance();
|
|
161
161
|
|
|
162
162
|
this.emit('init');
|
|
163
163
|
await this.call('init', this.scope);
|
|
@@ -170,24 +170,42 @@ export class A_Command<
|
|
|
170
170
|
return;
|
|
171
171
|
}
|
|
172
172
|
|
|
173
|
+
this.checkScopeInheritance();
|
|
174
|
+
|
|
173
175
|
this._status = A_CONSTANTS__A_Command_Status.COMPILATION;
|
|
174
176
|
this.emit('compile');
|
|
175
177
|
await this.call('compile', this.scope);
|
|
176
178
|
this._status = A_CONSTANTS__A_Command_Status.COMPILED;
|
|
177
179
|
}
|
|
178
180
|
|
|
181
|
+
/**
|
|
182
|
+
* Processes the command execution
|
|
183
|
+
*
|
|
184
|
+
* @returns
|
|
185
|
+
*/
|
|
186
|
+
async process() {
|
|
187
|
+
if (this._status !== A_CONSTANTS__A_Command_Status.COMPILED)
|
|
188
|
+
return;
|
|
189
|
+
|
|
190
|
+
this._status = A_CONSTANTS__A_Command_Status.IN_PROGRESS;
|
|
191
|
+
|
|
192
|
+
this.checkScopeInheritance();
|
|
193
|
+
|
|
194
|
+
this.emit('execute');
|
|
195
|
+
|
|
196
|
+
await this.call('execute', this.scope);
|
|
197
|
+
}
|
|
198
|
+
|
|
179
199
|
/**
|
|
180
200
|
* Executes the command logic.
|
|
181
201
|
*/
|
|
182
202
|
async execute(): Promise<any> {
|
|
203
|
+
this.checkScopeInheritance();
|
|
204
|
+
|
|
183
205
|
try {
|
|
184
206
|
await this.init();
|
|
185
207
|
await this.compile();
|
|
186
|
-
|
|
187
|
-
if (this._status === A_CONSTANTS__A_Command_Status.COMPILED) {
|
|
188
|
-
this.emit('execute');
|
|
189
|
-
await this.call('execute', this.scope);
|
|
190
|
-
}
|
|
208
|
+
await this.process();
|
|
191
209
|
await this.complete();
|
|
192
210
|
|
|
193
211
|
} catch (error) {
|
|
@@ -199,6 +217,8 @@ export class A_Command<
|
|
|
199
217
|
* Marks the command as completed
|
|
200
218
|
*/
|
|
201
219
|
async complete() {
|
|
220
|
+
this.checkScopeInheritance();
|
|
221
|
+
|
|
202
222
|
this._status = A_CONSTANTS__A_Command_Status.COMPLETED;
|
|
203
223
|
this._endTime = new Date();
|
|
204
224
|
this._result = this.scope.resolve(A_Memory).toJSON() as ResultType;
|
|
@@ -212,6 +232,8 @@ export class A_Command<
|
|
|
212
232
|
* Marks the command as failed
|
|
213
233
|
*/
|
|
214
234
|
async fail() {
|
|
235
|
+
this.checkScopeInheritance();
|
|
236
|
+
|
|
215
237
|
this._status = A_CONSTANTS__A_Command_Status.FAILED;
|
|
216
238
|
this._endTime = new Date();
|
|
217
239
|
this._errors = this.scope.resolve(A_Memory).Errors;
|
|
@@ -342,4 +364,23 @@ export class A_Command<
|
|
|
342
364
|
errors: this.errors ? Array.from(this.errors).map(err => err.toJSON()) : undefined
|
|
343
365
|
}
|
|
344
366
|
};
|
|
367
|
+
|
|
368
|
+
|
|
369
|
+
protected checkScopeInheritance(): void {
|
|
370
|
+
let attachedScope: A_Scope;
|
|
371
|
+
try {
|
|
372
|
+
attachedScope = A_Context.scope(this);
|
|
373
|
+
} catch (error) {
|
|
374
|
+
throw new A_CommandError({
|
|
375
|
+
title: A_CommandError.CommandScopeBindingError,
|
|
376
|
+
description: `Command ${this.code} is not bound to any context scope. Ensure the command is properly registered within a context before execution.`,
|
|
377
|
+
originalError: error
|
|
378
|
+
});
|
|
379
|
+
}
|
|
380
|
+
|
|
381
|
+
if (!this.scope.isInheritedFrom(A_Context.scope(this))) {
|
|
382
|
+
this.scope.inherit(A_Context.scope(this));
|
|
383
|
+
}
|
|
384
|
+
}
|
|
385
|
+
|
|
345
386
|
}
|