@adaas/a-utils 0.1.11 → 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 +25 -6
- package/dist/index.d.ts +25 -6
- package/dist/index.js +33 -7
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +33 -7
- package/dist/index.mjs.map +1 -1
- package/examples/command-examples.ts +268 -0
- package/package.json +1 -1
- 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-Memory/A-Memory.context.ts +15 -0
- package/tests/A-Command.test.ts +447 -2
- package/tests/A-Memory.test.ts +189 -0
package/dist/index.mjs
CHANGED
|
@@ -90,7 +90,11 @@ var A_TYPES__CommandMetaKey = /* @__PURE__ */ ((A_TYPES__CommandMetaKey2) => {
|
|
|
90
90
|
return A_TYPES__CommandMetaKey2;
|
|
91
91
|
})(A_TYPES__CommandMetaKey || {});
|
|
92
92
|
var A_CONSTANTS__A_Command_Status = /* @__PURE__ */ ((A_CONSTANTS__A_Command_Status2) => {
|
|
93
|
+
A_CONSTANTS__A_Command_Status2["CREATED"] = "CREATED";
|
|
94
|
+
A_CONSTANTS__A_Command_Status2["INITIALIZATION"] = "INITIALIZATION";
|
|
93
95
|
A_CONSTANTS__A_Command_Status2["INITIALIZED"] = "INITIALIZED";
|
|
96
|
+
A_CONSTANTS__A_Command_Status2["COMPILATION"] = "COMPILATION";
|
|
97
|
+
A_CONSTANTS__A_Command_Status2["COMPILED"] = "COMPILED";
|
|
94
98
|
A_CONSTANTS__A_Command_Status2["IN_PROGRESS"] = "IN_PROGRESS";
|
|
95
99
|
A_CONSTANTS__A_Command_Status2["COMPLETED"] = "COMPLETED";
|
|
96
100
|
A_CONSTANTS__A_Command_Status2["FAILED"] = "FAILED";
|
|
@@ -135,6 +139,15 @@ var A_Memory = class extends A_Fragment {
|
|
|
135
139
|
async error(error) {
|
|
136
140
|
this._errors.add(error);
|
|
137
141
|
}
|
|
142
|
+
/**
|
|
143
|
+
* Retrieves a value from the context memory
|
|
144
|
+
*
|
|
145
|
+
* @param key
|
|
146
|
+
* @returns
|
|
147
|
+
*/
|
|
148
|
+
get(key) {
|
|
149
|
+
return this._memory.get(key);
|
|
150
|
+
}
|
|
138
151
|
/**
|
|
139
152
|
* Saves a value in the context memory
|
|
140
153
|
*
|
|
@@ -273,18 +286,27 @@ var A_Command = class extends A_Entity {
|
|
|
273
286
|
// --------------------------------------------------------------------------
|
|
274
287
|
// should create a new Task in DB with basic records
|
|
275
288
|
async init() {
|
|
276
|
-
this._status
|
|
289
|
+
if (this._status !== "CREATED" /* CREATED */) {
|
|
290
|
+
return;
|
|
291
|
+
}
|
|
292
|
+
this._status = "INITIALIZATION" /* INITIALIZATION */;
|
|
277
293
|
this._startTime = /* @__PURE__ */ new Date();
|
|
278
294
|
if (!this.scope.isInheritedFrom(A_Context.scope(this))) {
|
|
279
295
|
this.scope.inherit(A_Context.scope(this));
|
|
280
296
|
}
|
|
281
297
|
this.emit("init");
|
|
282
|
-
|
|
298
|
+
await this.call("init", this.scope);
|
|
299
|
+
this._status = "INITIALIZED" /* INITIALIZED */;
|
|
283
300
|
}
|
|
284
301
|
// Should compile everything before execution
|
|
285
302
|
async compile() {
|
|
303
|
+
if (this._status !== "INITIALIZED" /* INITIALIZED */) {
|
|
304
|
+
return;
|
|
305
|
+
}
|
|
306
|
+
this._status = "COMPILATION" /* COMPILATION */;
|
|
286
307
|
this.emit("compile");
|
|
287
|
-
|
|
308
|
+
await this.call("compile", this.scope);
|
|
309
|
+
this._status = "COMPILED" /* COMPILED */;
|
|
288
310
|
}
|
|
289
311
|
/**
|
|
290
312
|
* Executes the command logic.
|
|
@@ -293,8 +315,10 @@ var A_Command = class extends A_Entity {
|
|
|
293
315
|
try {
|
|
294
316
|
await this.init();
|
|
295
317
|
await this.compile();
|
|
296
|
-
this.
|
|
297
|
-
|
|
318
|
+
if (this._status === "COMPILED" /* COMPILED */) {
|
|
319
|
+
this.emit("execute");
|
|
320
|
+
await this.call("execute", this.scope);
|
|
321
|
+
}
|
|
298
322
|
await this.complete();
|
|
299
323
|
} catch (error) {
|
|
300
324
|
await this.fail();
|
|
@@ -369,7 +393,7 @@ var A_Command = class extends A_Entity {
|
|
|
369
393
|
this._executionScope = new A_Scope();
|
|
370
394
|
this._executionScope.register(new A_Memory());
|
|
371
395
|
this._params = newEntity;
|
|
372
|
-
this._status = "
|
|
396
|
+
this._status = "CREATED" /* CREATED */;
|
|
373
397
|
}
|
|
374
398
|
/**
|
|
375
399
|
* Allows to convert serialized data to Command instance
|
|
@@ -395,7 +419,8 @@ var A_Command = class extends A_Entity {
|
|
|
395
419
|
memory.error(new A_Error(err));
|
|
396
420
|
});
|
|
397
421
|
}
|
|
398
|
-
this.
|
|
422
|
+
this._params = serialized.params;
|
|
423
|
+
this._status = serialized.status || "CREATED" /* CREATED */;
|
|
399
424
|
}
|
|
400
425
|
/**
|
|
401
426
|
* Converts the Command instance to a plain object
|
|
@@ -407,6 +432,7 @@ var A_Command = class extends A_Entity {
|
|
|
407
432
|
...super.toJSON(),
|
|
408
433
|
code: this.code,
|
|
409
434
|
status: this._status,
|
|
435
|
+
params: this._params,
|
|
410
436
|
startedAt: this._startTime ? this._startTime.toISOString() : void 0,
|
|
411
437
|
endedAt: this._endTime ? this._endTime.toISOString() : void 0,
|
|
412
438
|
duration: this.duration,
|