@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/dist/index.mjs
CHANGED
|
@@ -186,6 +186,9 @@ var A_Memory = class extends A_Fragment {
|
|
|
186
186
|
return obj;
|
|
187
187
|
}
|
|
188
188
|
};
|
|
189
|
+
var A_CommandError = class extends A_Error {
|
|
190
|
+
};
|
|
191
|
+
A_CommandError.CommandScopeBindingError = "A-Command Scope Binding Error";
|
|
189
192
|
|
|
190
193
|
// src/lib/A-Command/A-Command.entity.ts
|
|
191
194
|
var A_Command = class extends A_Entity {
|
|
@@ -291,9 +294,7 @@ var A_Command = class extends A_Entity {
|
|
|
291
294
|
}
|
|
292
295
|
this._status = "INITIALIZATION" /* INITIALIZATION */;
|
|
293
296
|
this._startTime = /* @__PURE__ */ new Date();
|
|
294
|
-
|
|
295
|
-
this.scope.inherit(A_Context.scope(this));
|
|
296
|
-
}
|
|
297
|
+
this.checkScopeInheritance();
|
|
297
298
|
this.emit("init");
|
|
298
299
|
await this.call("init", this.scope);
|
|
299
300
|
this._status = "INITIALIZED" /* INITIALIZED */;
|
|
@@ -303,22 +304,34 @@ var A_Command = class extends A_Entity {
|
|
|
303
304
|
if (this._status !== "INITIALIZED" /* INITIALIZED */) {
|
|
304
305
|
return;
|
|
305
306
|
}
|
|
307
|
+
this.checkScopeInheritance();
|
|
306
308
|
this._status = "COMPILATION" /* COMPILATION */;
|
|
307
309
|
this.emit("compile");
|
|
308
310
|
await this.call("compile", this.scope);
|
|
309
311
|
this._status = "COMPILED" /* COMPILED */;
|
|
310
312
|
}
|
|
313
|
+
/**
|
|
314
|
+
* Processes the command execution
|
|
315
|
+
*
|
|
316
|
+
* @returns
|
|
317
|
+
*/
|
|
318
|
+
async process() {
|
|
319
|
+
if (this._status !== "COMPILED" /* COMPILED */)
|
|
320
|
+
return;
|
|
321
|
+
this._status = "IN_PROGRESS" /* IN_PROGRESS */;
|
|
322
|
+
this.checkScopeInheritance();
|
|
323
|
+
this.emit("execute");
|
|
324
|
+
await this.call("execute", this.scope);
|
|
325
|
+
}
|
|
311
326
|
/**
|
|
312
327
|
* Executes the command logic.
|
|
313
328
|
*/
|
|
314
329
|
async execute() {
|
|
330
|
+
this.checkScopeInheritance();
|
|
315
331
|
try {
|
|
316
332
|
await this.init();
|
|
317
333
|
await this.compile();
|
|
318
|
-
|
|
319
|
-
this.emit("execute");
|
|
320
|
-
await this.call("execute", this.scope);
|
|
321
|
-
}
|
|
334
|
+
await this.process();
|
|
322
335
|
await this.complete();
|
|
323
336
|
} catch (error) {
|
|
324
337
|
await this.fail();
|
|
@@ -328,6 +341,7 @@ var A_Command = class extends A_Entity {
|
|
|
328
341
|
* Marks the command as completed
|
|
329
342
|
*/
|
|
330
343
|
async complete() {
|
|
344
|
+
this.checkScopeInheritance();
|
|
331
345
|
this._status = "COMPLETED" /* COMPLETED */;
|
|
332
346
|
this._endTime = /* @__PURE__ */ new Date();
|
|
333
347
|
this._result = this.scope.resolve(A_Memory).toJSON();
|
|
@@ -338,6 +352,7 @@ var A_Command = class extends A_Entity {
|
|
|
338
352
|
* Marks the command as failed
|
|
339
353
|
*/
|
|
340
354
|
async fail() {
|
|
355
|
+
this.checkScopeInheritance();
|
|
341
356
|
this._status = "FAILED" /* FAILED */;
|
|
342
357
|
this._endTime = /* @__PURE__ */ new Date();
|
|
343
358
|
this._errors = this.scope.resolve(A_Memory).Errors;
|
|
@@ -440,8 +455,21 @@ var A_Command = class extends A_Entity {
|
|
|
440
455
|
errors: this.errors ? Array.from(this.errors).map((err) => err.toJSON()) : void 0
|
|
441
456
|
};
|
|
442
457
|
}
|
|
443
|
-
|
|
444
|
-
|
|
458
|
+
checkScopeInheritance() {
|
|
459
|
+
let attachedScope;
|
|
460
|
+
try {
|
|
461
|
+
attachedScope = A_Context.scope(this);
|
|
462
|
+
} catch (error) {
|
|
463
|
+
throw new A_CommandError({
|
|
464
|
+
title: A_CommandError.CommandScopeBindingError,
|
|
465
|
+
description: `Command ${this.code} is not bound to any context scope. Ensure the command is properly registered within a context before execution.`,
|
|
466
|
+
originalError: error
|
|
467
|
+
});
|
|
468
|
+
}
|
|
469
|
+
if (!this.scope.isInheritedFrom(A_Context.scope(this))) {
|
|
470
|
+
this.scope.inherit(A_Context.scope(this));
|
|
471
|
+
}
|
|
472
|
+
}
|
|
445
473
|
};
|
|
446
474
|
|
|
447
475
|
// src/lib/A-Config/A-Config.constants.ts
|