@adaas/a-utils 0.1.18 → 0.1.19
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 +964 -354
- package/dist/index.d.ts +964 -354
- package/dist/index.js +1426 -714
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +1426 -714
- package/dist/index.mjs.map +1 -1
- package/examples/A-Channel-examples.ts +13 -11
- package/examples/A-Command-examples-2.ts +429 -0
- package/examples/A-Command-examples.ts +487 -202
- package/examples/A-StateMachine-examples.ts +609 -0
- package/package.json +3 -2
- package/src/index.ts +1 -2
- package/src/lib/A-Channel/A-Channel.component.ts +14 -74
- package/src/lib/A-Channel/A-Channel.error.ts +5 -5
- package/src/lib/A-Channel/A-Channel.types.ts +2 -10
- package/src/lib/A-Channel/A-ChannelRequest.context.ts +25 -74
- package/src/lib/A-Command/A-Command.constants.ts +78 -23
- package/src/lib/A-Command/A-Command.entity.ts +447 -119
- package/src/lib/A-Command/A-Command.error.ts +11 -0
- package/src/lib/A-Command/A-Command.types.ts +96 -20
- package/src/lib/A-Command/A-CommandExecution.context.ts +0 -0
- package/src/lib/A-Command/README.md +164 -68
- package/src/lib/A-Config/A-Config.container.ts +2 -2
- package/src/lib/A-Config/A-Config.context.ts +19 -5
- package/src/lib/A-Config/components/ConfigReader.component.ts +1 -1
- package/src/lib/A-Logger/A-Logger.component.ts +211 -35
- package/src/lib/A-Logger/A-Logger.constants.ts +50 -10
- package/src/lib/A-Logger/A-Logger.env.ts +17 -1
- package/src/lib/A-Memory/A-Memory.component.ts +440 -0
- package/src/lib/A-Memory/A-Memory.constants.ts +49 -0
- package/src/lib/A-Memory/A-Memory.context.ts +14 -118
- package/src/lib/A-Memory/A-Memory.error.ts +21 -0
- package/src/lib/A-Memory/A-Memory.types.ts +21 -0
- package/src/lib/A-Operation/A-Operation.context.ts +58 -0
- package/src/lib/A-Operation/A-Operation.types.ts +47 -0
- package/src/lib/A-StateMachine/A-StateMachine.component.ts +258 -0
- package/src/lib/A-StateMachine/A-StateMachine.constants.ts +18 -0
- package/src/lib/A-StateMachine/A-StateMachine.error.ts +10 -0
- package/src/lib/A-StateMachine/A-StateMachine.types.ts +20 -0
- package/src/lib/A-StateMachine/A-StateMachineTransition.context.ts +41 -0
- package/src/lib/A-StateMachine/README.md +391 -0
- package/tests/A-Channel.test.ts +17 -14
- package/tests/A-Command.test.ts +548 -460
- package/tests/A-Logger.test.ts +8 -4
- package/tests/A-Memory.test.ts +151 -115
- package/tests/A-Schedule.test.ts +2 -2
- package/tests/A-StateMachine.test.ts +760 -0
package/dist/index.js
CHANGED
|
@@ -13,97 +13,36 @@ var __decorateClass = (decorators, target, key, kind) => {
|
|
|
13
13
|
return result;
|
|
14
14
|
};
|
|
15
15
|
var __decorateParam = (index, decorator) => (target, key) => decorator(target, key, index);
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
var A_ChannelFeatures = /* @__PURE__ */ ((A_ChannelFeatures2) => {
|
|
19
|
-
A_ChannelFeatures2["onTimeout"] = "onTimeout";
|
|
20
|
-
A_ChannelFeatures2["onRetry"] = "onRetry";
|
|
21
|
-
A_ChannelFeatures2["onCircuitBreakerOpen"] = "onCircuitBreakerOpen";
|
|
22
|
-
A_ChannelFeatures2["onCache"] = "onCache";
|
|
23
|
-
A_ChannelFeatures2["onConnect"] = "onConnect";
|
|
24
|
-
A_ChannelFeatures2["onDisconnect"] = "onDisconnect";
|
|
25
|
-
A_ChannelFeatures2["onBeforeRequest"] = "onBeforeRequest";
|
|
26
|
-
A_ChannelFeatures2["onRequest"] = "onRequest";
|
|
27
|
-
A_ChannelFeatures2["onAfterRequest"] = "onAfterRequest";
|
|
28
|
-
A_ChannelFeatures2["onError"] = "onError";
|
|
29
|
-
A_ChannelFeatures2["onSend"] = "onSend";
|
|
30
|
-
A_ChannelFeatures2["onConsume"] = "onConsume";
|
|
31
|
-
return A_ChannelFeatures2;
|
|
32
|
-
})(A_ChannelFeatures || {});
|
|
33
|
-
var A_ChannelRequestStatuses = /* @__PURE__ */ ((A_ChannelRequestStatuses2) => {
|
|
34
|
-
A_ChannelRequestStatuses2["PENDING"] = "PENDING";
|
|
35
|
-
A_ChannelRequestStatuses2["SUCCESS"] = "SUCCESS";
|
|
36
|
-
A_ChannelRequestStatuses2["FAILED"] = "FAILED";
|
|
37
|
-
return A_ChannelRequestStatuses2;
|
|
38
|
-
})(A_ChannelRequestStatuses || {});
|
|
39
|
-
|
|
40
|
-
// src/lib/A-Channel/A-ChannelRequest.context.ts
|
|
41
|
-
var A_ChannelRequest = class extends aConcept.A_Fragment {
|
|
42
|
-
constructor(params = {}) {
|
|
16
|
+
var A_OperationContext = class extends aConcept.A_Fragment {
|
|
17
|
+
constructor(operation, params) {
|
|
43
18
|
super();
|
|
44
|
-
this.
|
|
45
|
-
this.
|
|
46
|
-
this._params = params;
|
|
47
|
-
}
|
|
48
|
-
/**
|
|
49
|
-
* Returns the status of the request
|
|
50
|
-
*/
|
|
51
|
-
get status() {
|
|
52
|
-
return this._status;
|
|
19
|
+
this.meta.set("name", operation);
|
|
20
|
+
this.meta.set("params", params || {});
|
|
53
21
|
}
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
*/
|
|
57
|
-
get failed() {
|
|
58
|
-
return this._errors.size > 0;
|
|
22
|
+
get name() {
|
|
23
|
+
return this._meta.get("name") || this._name;
|
|
59
24
|
}
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
*/
|
|
63
|
-
get params() {
|
|
64
|
-
return this._params;
|
|
25
|
+
get result() {
|
|
26
|
+
return this._meta.get("result");
|
|
65
27
|
}
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
*/
|
|
69
|
-
get data() {
|
|
70
|
-
return this._result;
|
|
28
|
+
get error() {
|
|
29
|
+
return this._meta.get("error");
|
|
71
30
|
}
|
|
72
|
-
get
|
|
73
|
-
return this.
|
|
31
|
+
get params() {
|
|
32
|
+
return this._meta.get("params") || {};
|
|
74
33
|
}
|
|
75
|
-
// ==========================================================
|
|
76
|
-
// ==================== Mutations ===========================
|
|
77
|
-
// ==========================================================
|
|
78
|
-
/**
|
|
79
|
-
* Adds an error to the context
|
|
80
|
-
*
|
|
81
|
-
* @param error
|
|
82
|
-
*/
|
|
83
34
|
fail(error) {
|
|
84
|
-
this.
|
|
85
|
-
this._errors.add(error);
|
|
35
|
+
this._meta.set("error", error);
|
|
86
36
|
}
|
|
87
|
-
/**
|
|
88
|
-
* Sets the result of the request
|
|
89
|
-
*
|
|
90
|
-
* @param result
|
|
91
|
-
*/
|
|
92
37
|
succeed(result) {
|
|
93
|
-
this.
|
|
94
|
-
this._result = result;
|
|
38
|
+
this._meta.set("result", result);
|
|
95
39
|
}
|
|
96
|
-
/**
|
|
97
|
-
* Serializes the context to a JSON object
|
|
98
|
-
*
|
|
99
|
-
* @returns
|
|
100
|
-
*/
|
|
101
40
|
toJSON() {
|
|
102
41
|
return {
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
42
|
+
name: this.name,
|
|
43
|
+
params: this.params,
|
|
44
|
+
result: this.result || {},
|
|
45
|
+
error: this.error?.toJSON()
|
|
107
46
|
};
|
|
108
47
|
}
|
|
109
48
|
};
|
|
@@ -122,7 +61,7 @@ var A_ChannelError = class extends aConcept.A_Error {
|
|
|
122
61
|
super(originalError, context);
|
|
123
62
|
else
|
|
124
63
|
super(originalError);
|
|
125
|
-
if (context instanceof
|
|
64
|
+
if (context instanceof A_OperationContext)
|
|
126
65
|
this._context = context;
|
|
127
66
|
}
|
|
128
67
|
/***
|
|
@@ -137,475 +76,120 @@ var A_ChannelError = class extends aConcept.A_Error {
|
|
|
137
76
|
// ==========================================================
|
|
138
77
|
A_ChannelError.MethodNotImplemented = "A-Channel Method Not Implemented";
|
|
139
78
|
|
|
140
|
-
// src/lib/A-
|
|
141
|
-
var
|
|
142
|
-
|
|
79
|
+
// src/lib/A-Channel/A-Channel.constants.ts
|
|
80
|
+
var A_ChannelFeatures = /* @__PURE__ */ ((A_ChannelFeatures2) => {
|
|
81
|
+
A_ChannelFeatures2["onTimeout"] = "onTimeout";
|
|
82
|
+
A_ChannelFeatures2["onRetry"] = "onRetry";
|
|
83
|
+
A_ChannelFeatures2["onCircuitBreakerOpen"] = "onCircuitBreakerOpen";
|
|
84
|
+
A_ChannelFeatures2["onCache"] = "onCache";
|
|
85
|
+
A_ChannelFeatures2["onConnect"] = "onConnect";
|
|
86
|
+
A_ChannelFeatures2["onDisconnect"] = "onDisconnect";
|
|
87
|
+
A_ChannelFeatures2["onBeforeRequest"] = "onBeforeRequest";
|
|
88
|
+
A_ChannelFeatures2["onRequest"] = "onRequest";
|
|
89
|
+
A_ChannelFeatures2["onAfterRequest"] = "onAfterRequest";
|
|
90
|
+
A_ChannelFeatures2["onError"] = "onError";
|
|
91
|
+
A_ChannelFeatures2["onSend"] = "onSend";
|
|
92
|
+
A_ChannelFeatures2["onConsume"] = "onConsume";
|
|
93
|
+
return A_ChannelFeatures2;
|
|
94
|
+
})(A_ChannelFeatures || {});
|
|
95
|
+
var A_ChannelRequestStatuses = /* @__PURE__ */ ((A_ChannelRequestStatuses2) => {
|
|
96
|
+
A_ChannelRequestStatuses2["PENDING"] = "PENDING";
|
|
97
|
+
A_ChannelRequestStatuses2["SUCCESS"] = "SUCCESS";
|
|
98
|
+
A_ChannelRequestStatuses2["FAILED"] = "FAILED";
|
|
99
|
+
return A_ChannelRequestStatuses2;
|
|
100
|
+
})(A_ChannelRequestStatuses || {});
|
|
143
101
|
|
|
144
|
-
// src/lib/A-
|
|
145
|
-
var
|
|
146
|
-
constructor(
|
|
147
|
-
super(
|
|
148
|
-
name: "A_Config"
|
|
149
|
-
});
|
|
150
|
-
this.VARIABLES = /* @__PURE__ */ new Map();
|
|
151
|
-
this.DEFAULT_ALLOWED_TO_READ_PROPERTIES = [
|
|
152
|
-
...aConcept.A_CONSTANTS__DEFAULT_ENV_VARIABLES_ARRAY,
|
|
153
|
-
...A_CONSTANTS__CONFIG_ENV_VARIABLES_ARRAY
|
|
154
|
-
];
|
|
155
|
-
this.config = aConcept.A_CommonHelper.deepCloneAndMerge(config, {
|
|
156
|
-
strict: false,
|
|
157
|
-
defaults: {},
|
|
158
|
-
variables: aConcept.A_CONSTANTS__DEFAULT_ENV_VARIABLES_ARRAY
|
|
159
|
-
});
|
|
160
|
-
this.CONFIG_PROPERTIES = this.config.variables ? this.config.variables : [];
|
|
161
|
-
this.config.variables.forEach((variable) => {
|
|
162
|
-
this.VARIABLES.set(
|
|
163
|
-
aConcept.A_FormatterHelper.toUpperSnakeCase(variable),
|
|
164
|
-
this.config.defaults[variable]
|
|
165
|
-
);
|
|
166
|
-
});
|
|
102
|
+
// src/lib/A-Channel/A-ChannelRequest.context.ts
|
|
103
|
+
var A_ChannelRequest = class extends A_OperationContext {
|
|
104
|
+
constructor(params) {
|
|
105
|
+
super("request", params);
|
|
167
106
|
}
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
*
|
|
171
|
-
* @param property
|
|
172
|
-
* @returns
|
|
173
|
-
*/
|
|
174
|
-
get(property) {
|
|
175
|
-
if (this.CONFIG_PROPERTIES.includes(property) || this.DEFAULT_ALLOWED_TO_READ_PROPERTIES.includes(property) || !this.config.strict)
|
|
176
|
-
return this.VARIABLES.get(aConcept.A_FormatterHelper.toUpperSnakeCase(property));
|
|
177
|
-
throw new Error("Property not exists or not allowed to read");
|
|
107
|
+
get status() {
|
|
108
|
+
return this.result?.status;
|
|
178
109
|
}
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
110
|
+
get data() {
|
|
111
|
+
return this.result?.data;
|
|
112
|
+
}
|
|
113
|
+
succeed(result) {
|
|
114
|
+
const existed = this.result;
|
|
115
|
+
super.succeed({
|
|
116
|
+
...existed,
|
|
117
|
+
data: result,
|
|
118
|
+
status: "SUCCESS" /* SUCCESS */
|
|
119
|
+
});
|
|
188
120
|
}
|
|
189
121
|
};
|
|
190
122
|
|
|
191
|
-
// src/lib/A-
|
|
192
|
-
var
|
|
193
|
-
var A_LOGGER_COLORS = {
|
|
194
|
-
green: "32",
|
|
195
|
-
// Success, completion messages
|
|
196
|
-
blue: "34",
|
|
197
|
-
// Info, general messages
|
|
198
|
-
red: "31",
|
|
199
|
-
// Errors, critical issues
|
|
200
|
-
yellow: "33",
|
|
201
|
-
// Warnings, caution messages
|
|
202
|
-
gray: "90",
|
|
203
|
-
// Debug, less important info
|
|
204
|
-
magenta: "35",
|
|
205
|
-
// Special highlighting
|
|
206
|
-
cyan: "36",
|
|
207
|
-
// Headers, titles
|
|
208
|
-
white: "37",
|
|
209
|
-
// Default text
|
|
210
|
-
pink: "95"
|
|
211
|
-
// Custom highlighting
|
|
212
|
-
};
|
|
213
|
-
var A_LOGGER_ANSI = {
|
|
214
|
-
RESET: "\x1B[0m",
|
|
215
|
-
PREFIX: "\x1B[",
|
|
216
|
-
SUFFIX: "m"
|
|
217
|
-
};
|
|
218
|
-
var A_LOGGER_TIME_FORMAT = {
|
|
219
|
-
MINUTES_PAD: 2,
|
|
220
|
-
SECONDS_PAD: 2,
|
|
221
|
-
MILLISECONDS_PAD: 3,
|
|
222
|
-
SEPARATOR: ":"
|
|
223
|
-
};
|
|
224
|
-
var A_LOGGER_FORMAT = {
|
|
225
|
-
SCOPE_OPEN: "[",
|
|
226
|
-
SCOPE_CLOSE: "]",
|
|
227
|
-
TIME_OPEN: "|",
|
|
228
|
-
TIME_CLOSE: "|",
|
|
229
|
-
SEPARATOR: "-------------------------------",
|
|
230
|
-
PIPE: "| "
|
|
231
|
-
};
|
|
232
|
-
var A_LOGGER_ENV_KEYS = {
|
|
233
|
-
LOG_LEVEL: "A_LOGGER_LEVEL"
|
|
234
|
-
};
|
|
235
|
-
|
|
236
|
-
// src/lib/A-Logger/A-Logger.component.ts
|
|
237
|
-
exports.A_Logger = class A_Logger extends aConcept.A_Component {
|
|
238
|
-
// =============================================
|
|
239
|
-
// Constructor and Initialization
|
|
240
|
-
// =============================================
|
|
123
|
+
// src/lib/A-Channel/A-Channel.component.ts
|
|
124
|
+
var A_Channel = class extends aConcept.A_Component {
|
|
241
125
|
/**
|
|
242
|
-
*
|
|
126
|
+
* Creates a new A_Channel instance.
|
|
243
127
|
*
|
|
244
|
-
*
|
|
245
|
-
*
|
|
128
|
+
* The channel must be registered with A_Context before use:
|
|
129
|
+
* ```typescript
|
|
130
|
+
* const channel = new A_Channel();
|
|
131
|
+
* A_Context.root.register(channel);
|
|
132
|
+
* ```
|
|
246
133
|
*/
|
|
247
|
-
constructor(
|
|
134
|
+
constructor() {
|
|
248
135
|
super();
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
136
|
+
/**
|
|
137
|
+
* Indicates whether the channel is currently processing requests.
|
|
138
|
+
* This flag is managed automatically during request/send operations.
|
|
139
|
+
*
|
|
140
|
+
* @readonly
|
|
141
|
+
*/
|
|
142
|
+
this._processing = false;
|
|
143
|
+
/**
|
|
144
|
+
* Internal cache storage for channel-specific data.
|
|
145
|
+
* Can be used by custom implementations for caching responses,
|
|
146
|
+
* connection pools, or other channel-specific state.
|
|
147
|
+
*
|
|
148
|
+
* @protected
|
|
149
|
+
*/
|
|
150
|
+
this._cache = /* @__PURE__ */ new Map();
|
|
253
151
|
}
|
|
254
|
-
// =============================================
|
|
255
|
-
// Scope and Formatting Utilities
|
|
256
|
-
// =============================================
|
|
257
152
|
/**
|
|
258
|
-
*
|
|
259
|
-
* Uses a standard length to ensure all messages align properly regardless of scope name
|
|
153
|
+
* Indicates whether the channel is currently processing requests.
|
|
260
154
|
*
|
|
261
|
-
* @returns
|
|
155
|
+
* @returns {boolean} True if channel is processing, false otherwise
|
|
262
156
|
*/
|
|
263
|
-
get
|
|
264
|
-
return
|
|
157
|
+
get processing() {
|
|
158
|
+
return this._processing;
|
|
265
159
|
}
|
|
266
160
|
/**
|
|
267
|
-
*
|
|
268
|
-
*
|
|
161
|
+
* Promise that resolves when the channel is fully initialized.
|
|
162
|
+
*
|
|
163
|
+
* Automatically calls the onConnect lifecycle hook if not already called.
|
|
164
|
+
* This ensures the channel is ready for communication operations.
|
|
269
165
|
*
|
|
270
|
-
* @returns
|
|
166
|
+
* @returns {Promise<void>} Promise that resolves when initialization is complete
|
|
271
167
|
*/
|
|
272
|
-
get
|
|
273
|
-
|
|
168
|
+
get initialize() {
|
|
169
|
+
if (!this._initialized) {
|
|
170
|
+
this._initialized = this.connect();
|
|
171
|
+
}
|
|
172
|
+
return this._initialized;
|
|
274
173
|
}
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
174
|
+
async onConnect(...args) {
|
|
175
|
+
}
|
|
176
|
+
async onDisconnect(...args) {
|
|
177
|
+
}
|
|
178
|
+
async onBeforeRequest(...args) {
|
|
179
|
+
}
|
|
180
|
+
async onRequest(...args) {
|
|
181
|
+
}
|
|
182
|
+
async onAfterRequest(...args) {
|
|
183
|
+
}
|
|
184
|
+
async onError(...args) {
|
|
185
|
+
}
|
|
186
|
+
async onSend(...args) {
|
|
187
|
+
}
|
|
188
|
+
// ==========================================================
|
|
189
|
+
// ================= Public API Methods ===================
|
|
190
|
+
// ==========================================================
|
|
278
191
|
/**
|
|
279
|
-
*
|
|
280
|
-
*
|
|
281
|
-
* This method handles the core formatting logic for all log messages:
|
|
282
|
-
* - Applies terminal color codes for visual distinction
|
|
283
|
-
* - Formats scope names with consistent padding
|
|
284
|
-
* - Handles different data types appropriately
|
|
285
|
-
* - Maintains proper indentation for multi-line content
|
|
286
|
-
*
|
|
287
|
-
* @param color - The color key to apply to the message
|
|
288
|
-
* @param args - Variable arguments to format and display
|
|
289
|
-
* @returns Array of formatted strings ready for console output
|
|
290
|
-
*/
|
|
291
|
-
compile(color, ...args) {
|
|
292
|
-
const timeString = this.getTime();
|
|
293
|
-
const scopePadding = " ".repeat(this.scopeLength + 3);
|
|
294
|
-
const isMultiArg = args.length > 1;
|
|
295
|
-
return [
|
|
296
|
-
// Header with color, scope, and timestamp
|
|
297
|
-
`${A_LOGGER_ANSI.PREFIX}${this.COLORS[color]}${A_LOGGER_ANSI.SUFFIX}${A_LOGGER_FORMAT.SCOPE_OPEN}${this.formattedScope}${A_LOGGER_FORMAT.SCOPE_CLOSE} ${A_LOGGER_FORMAT.TIME_OPEN}${timeString}${A_LOGGER_FORMAT.TIME_CLOSE}`,
|
|
298
|
-
// Top separator for multi-argument messages
|
|
299
|
-
isMultiArg ? `
|
|
300
|
-
${scopePadding}${A_LOGGER_FORMAT.TIME_OPEN}${A_LOGGER_FORMAT.SEPARATOR}` : "",
|
|
301
|
-
// Process each argument with appropriate formatting
|
|
302
|
-
...args.map((arg, i) => {
|
|
303
|
-
const shouldAddNewline = i > 0 || isMultiArg;
|
|
304
|
-
switch (true) {
|
|
305
|
-
case arg instanceof aConcept.A_Error:
|
|
306
|
-
return this.compile_A_Error(arg);
|
|
307
|
-
case arg instanceof Error:
|
|
308
|
-
return this.compile_Error(arg);
|
|
309
|
-
case (typeof arg === "object" && arg !== null):
|
|
310
|
-
return this.formatObject(arg, shouldAddNewline, scopePadding);
|
|
311
|
-
default:
|
|
312
|
-
return this.formatString(String(arg), shouldAddNewline, scopePadding);
|
|
313
|
-
}
|
|
314
|
-
}),
|
|
315
|
-
// Bottom separator and color reset
|
|
316
|
-
isMultiArg ? `
|
|
317
|
-
${scopePadding}${A_LOGGER_FORMAT.TIME_OPEN}${A_LOGGER_FORMAT.SEPARATOR}${A_LOGGER_ANSI.RESET}` : A_LOGGER_ANSI.RESET
|
|
318
|
-
];
|
|
319
|
-
}
|
|
320
|
-
/**
|
|
321
|
-
* Format an object for display with proper JSON indentation
|
|
322
|
-
*
|
|
323
|
-
* @param obj - The object to format
|
|
324
|
-
* @param shouldAddNewline - Whether to add a newline prefix
|
|
325
|
-
* @param scopePadding - The padding string for consistent alignment
|
|
326
|
-
* @returns Formatted object string
|
|
327
|
-
*/
|
|
328
|
-
formatObject(obj, shouldAddNewline, scopePadding) {
|
|
329
|
-
let jsonString;
|
|
330
|
-
try {
|
|
331
|
-
jsonString = JSON.stringify(obj, null, 2);
|
|
332
|
-
} catch (error) {
|
|
333
|
-
const seen = /* @__PURE__ */ new WeakSet();
|
|
334
|
-
jsonString = JSON.stringify(obj, (key, value) => {
|
|
335
|
-
if (typeof value === "object" && value !== null) {
|
|
336
|
-
if (seen.has(value)) {
|
|
337
|
-
return "[Circular Reference]";
|
|
338
|
-
}
|
|
339
|
-
seen.add(value);
|
|
340
|
-
}
|
|
341
|
-
return value;
|
|
342
|
-
}, 2);
|
|
343
|
-
}
|
|
344
|
-
const formatted = jsonString.replace(/\n/g, `
|
|
345
|
-
${scopePadding}${A_LOGGER_FORMAT.PIPE}`);
|
|
346
|
-
return shouldAddNewline ? `
|
|
347
|
-
${scopePadding}${A_LOGGER_FORMAT.PIPE}` + formatted : formatted;
|
|
348
|
-
}
|
|
349
|
-
/**
|
|
350
|
-
* Format a string for display with proper indentation
|
|
351
|
-
*
|
|
352
|
-
* @param str - The string to format
|
|
353
|
-
* @param shouldAddNewline - Whether to add a newline prefix
|
|
354
|
-
* @param scopePadding - The padding string for consistent alignment
|
|
355
|
-
* @returns Formatted string
|
|
356
|
-
*/
|
|
357
|
-
formatString(str, shouldAddNewline, scopePadding) {
|
|
358
|
-
const prefix = shouldAddNewline ? "\n" : "";
|
|
359
|
-
return (prefix + str).replace(/\n/g, `
|
|
360
|
-
${scopePadding}${A_LOGGER_FORMAT.PIPE}`);
|
|
361
|
-
}
|
|
362
|
-
// =============================================
|
|
363
|
-
// Log Level Management
|
|
364
|
-
// =============================================
|
|
365
|
-
/**
|
|
366
|
-
* Determine if a log message should be output based on configured log level
|
|
367
|
-
*
|
|
368
|
-
* Log level hierarchy:
|
|
369
|
-
* - debug: Shows all messages
|
|
370
|
-
* - info: Shows info, warning, and error messages
|
|
371
|
-
* - warn: Shows warning and error messages only
|
|
372
|
-
* - error: Shows error messages only
|
|
373
|
-
* - all: Shows all messages (alias for debug)
|
|
374
|
-
*
|
|
375
|
-
* @param logMethod - The type of log method being called
|
|
376
|
-
* @returns True if the message should be logged, false otherwise
|
|
377
|
-
*/
|
|
378
|
-
shouldLog(logMethod) {
|
|
379
|
-
const shouldLog = this.config?.get(A_LOGGER_ENV_KEYS.LOG_LEVEL) || "all";
|
|
380
|
-
switch (shouldLog) {
|
|
381
|
-
case "debug":
|
|
382
|
-
return true;
|
|
383
|
-
case "info":
|
|
384
|
-
return logMethod === "log" || logMethod === "warning" || logMethod === "error";
|
|
385
|
-
case "warn":
|
|
386
|
-
return logMethod === "warning" || logMethod === "error";
|
|
387
|
-
case "error":
|
|
388
|
-
return logMethod === "error";
|
|
389
|
-
case "all":
|
|
390
|
-
return true;
|
|
391
|
-
default:
|
|
392
|
-
return false;
|
|
393
|
-
}
|
|
394
|
-
}
|
|
395
|
-
log(param1, ...args) {
|
|
396
|
-
if (!this.shouldLog("log")) return;
|
|
397
|
-
if (typeof param1 === "string" && this.COLORS[param1]) {
|
|
398
|
-
console.log(...this.compile(param1, ...args));
|
|
399
|
-
} else {
|
|
400
|
-
console.log(...this.compile("blue", param1, ...args));
|
|
401
|
-
}
|
|
402
|
-
}
|
|
403
|
-
/**
|
|
404
|
-
* Log warning messages with yellow color coding
|
|
405
|
-
*
|
|
406
|
-
* Use for non-critical issues that should be brought to attention
|
|
407
|
-
* but don't prevent normal operation
|
|
408
|
-
*
|
|
409
|
-
* @param args - Arguments to log as warnings
|
|
410
|
-
*
|
|
411
|
-
* @example
|
|
412
|
-
* ```typescript
|
|
413
|
-
* logger.warning('Deprecated method used');
|
|
414
|
-
* logger.warning('Rate limit approaching:', { current: 95, limit: 100 });
|
|
415
|
-
* ```
|
|
416
|
-
*/
|
|
417
|
-
warning(...args) {
|
|
418
|
-
if (!this.shouldLog("warning")) return;
|
|
419
|
-
console.log(...this.compile("yellow", ...args));
|
|
420
|
-
}
|
|
421
|
-
/**
|
|
422
|
-
* Log error messages with red color coding
|
|
423
|
-
*
|
|
424
|
-
* Use for critical issues, exceptions, and failures that need immediate attention
|
|
425
|
-
*
|
|
426
|
-
* @param args - Arguments to log as errors
|
|
427
|
-
* @returns void (for compatibility with console.log)
|
|
428
|
-
*
|
|
429
|
-
* @example
|
|
430
|
-
* ```typescript
|
|
431
|
-
* logger.error('Database connection failed');
|
|
432
|
-
* logger.error(new Error('Validation failed'));
|
|
433
|
-
* logger.error('Critical error:', error, { context: 'user-registration' });
|
|
434
|
-
* ```
|
|
435
|
-
*/
|
|
436
|
-
error(...args) {
|
|
437
|
-
if (!this.shouldLog("error")) return;
|
|
438
|
-
console.log(...this.compile("red", ...args));
|
|
439
|
-
}
|
|
440
|
-
// =============================================
|
|
441
|
-
// Specialized Error Formatting
|
|
442
|
-
// =============================================
|
|
443
|
-
/**
|
|
444
|
-
* Legacy method for A_Error logging (kept for backward compatibility)
|
|
445
|
-
*
|
|
446
|
-
* @deprecated Use error() method instead which handles A_Error automatically
|
|
447
|
-
* @param error - The A_Error instance to log
|
|
448
|
-
*/
|
|
449
|
-
log_A_Error(error) {
|
|
450
|
-
const time = this.getTime();
|
|
451
|
-
const scopePadding = " ".repeat(this.scopeLength + 3);
|
|
452
|
-
console.log(`\x1B[31m[${this.formattedScope}] |${time}| ERROR ${error.code}
|
|
453
|
-
${scopePadding}| ${error.message}
|
|
454
|
-
${scopePadding}| ${error.description}
|
|
455
|
-
${scopePadding}|-------------------------------
|
|
456
|
-
${scopePadding}| ${error.stack?.split("\n").map((line, index) => index === 0 ? line : `${scopePadding}| ${line}`).join("\n") || "No stack trace"}
|
|
457
|
-
${scopePadding}|-------------------------------
|
|
458
|
-
\x1B[0m` + (error.originalError ? `\x1B[31m${scopePadding}| Wrapped From ${error.originalError.message}
|
|
459
|
-
${scopePadding}|-------------------------------
|
|
460
|
-
${scopePadding}| ${error.originalError.stack?.split("\n").map((line, index) => index === 0 ? line : `${scopePadding}| ${line}`).join("\n") || "No stack trace"}
|
|
461
|
-
${scopePadding}|-------------------------------
|
|
462
|
-
\x1B[0m` : "") + (error.link ? `\x1B[31m${scopePadding}| Read in docs: ${error.link}
|
|
463
|
-
${scopePadding}|-------------------------------
|
|
464
|
-
\x1B[0m` : ""));
|
|
465
|
-
}
|
|
466
|
-
/**
|
|
467
|
-
* Format A_Error instances for inline display within compiled messages
|
|
468
|
-
*
|
|
469
|
-
* Provides detailed formatting for A_Error objects including:
|
|
470
|
-
* - Error code and message
|
|
471
|
-
* - Description and stack trace
|
|
472
|
-
* - Original error information (if wrapped)
|
|
473
|
-
* - Documentation links (if available)
|
|
474
|
-
*
|
|
475
|
-
* @param error - The A_Error instance to format
|
|
476
|
-
* @returns Formatted string ready for display
|
|
477
|
-
*/
|
|
478
|
-
compile_A_Error(error) {
|
|
479
|
-
const scopePadding = " ".repeat(this.scopeLength + 3);
|
|
480
|
-
return `
|
|
481
|
-
${scopePadding}|-------------------------------
|
|
482
|
-
${scopePadding}| Error: | ${error.code}
|
|
483
|
-
${scopePadding}|-------------------------------
|
|
484
|
-
${scopePadding}|${" ".repeat(10)}| ${error.message}
|
|
485
|
-
${scopePadding}|${" ".repeat(10)}| ${error.description}
|
|
486
|
-
${scopePadding}|-------------------------------
|
|
487
|
-
${scopePadding}| ${error.stack?.split("\n").map((line, index) => index === 0 ? line : `${scopePadding}| ${line}`).join("\n") || "No stack trace"}
|
|
488
|
-
${scopePadding}|-------------------------------` + (error.originalError ? `${scopePadding}| Wrapped From ${error.originalError.message}
|
|
489
|
-
${scopePadding}|-------------------------------
|
|
490
|
-
${scopePadding}| ${error.originalError.stack?.split("\n").map((line, index) => index === 0 ? line : `${scopePadding}| ${line}`).join("\n") || "No stack trace"}
|
|
491
|
-
${scopePadding}|-------------------------------` : "") + (error.link ? `${scopePadding}| Read in docs: ${error.link}
|
|
492
|
-
${scopePadding}|-------------------------------` : "");
|
|
493
|
-
}
|
|
494
|
-
/**
|
|
495
|
-
* Format standard Error instances for inline display within compiled messages
|
|
496
|
-
*
|
|
497
|
-
* Converts standard JavaScript Error objects into a readable JSON format
|
|
498
|
-
* with proper indentation and stack trace formatting
|
|
499
|
-
*
|
|
500
|
-
* @param error - The Error instance to format
|
|
501
|
-
* @returns Formatted string ready for display
|
|
502
|
-
*/
|
|
503
|
-
compile_Error(error) {
|
|
504
|
-
const scopePadding = " ".repeat(this.scopeLength + 3);
|
|
505
|
-
return JSON.stringify({
|
|
506
|
-
name: error.name,
|
|
507
|
-
message: error.message,
|
|
508
|
-
stack: error.stack?.split("\n").map((line, index) => index === 0 ? line : `${scopePadding}| ${line}`).join("\n")
|
|
509
|
-
}, null, 2).replace(/\n/g, `
|
|
510
|
-
${scopePadding}| `).replace(/\\n/g, "\n");
|
|
511
|
-
}
|
|
512
|
-
// =============================================
|
|
513
|
-
// Utility Methods
|
|
514
|
-
// =============================================
|
|
515
|
-
/**
|
|
516
|
-
* Generate timestamp string for log messages
|
|
517
|
-
*
|
|
518
|
-
* Format: MM:SS:mmm (minutes:seconds:milliseconds)
|
|
519
|
-
* This provides sufficient precision for debugging while remaining readable
|
|
520
|
-
*
|
|
521
|
-
* @returns Formatted timestamp string
|
|
522
|
-
*
|
|
523
|
-
* @example
|
|
524
|
-
* Returns: "15:42:137" for 3:42:15 PM and 137 milliseconds
|
|
525
|
-
*/
|
|
526
|
-
getTime() {
|
|
527
|
-
const now = /* @__PURE__ */ new Date();
|
|
528
|
-
const minutes = String(now.getMinutes()).padStart(A_LOGGER_TIME_FORMAT.MINUTES_PAD, "0");
|
|
529
|
-
const seconds = String(now.getSeconds()).padStart(A_LOGGER_TIME_FORMAT.SECONDS_PAD, "0");
|
|
530
|
-
const milliseconds = String(now.getMilliseconds()).padStart(A_LOGGER_TIME_FORMAT.MILLISECONDS_PAD, "0");
|
|
531
|
-
return `${minutes}${A_LOGGER_TIME_FORMAT.SEPARATOR}${seconds}${A_LOGGER_TIME_FORMAT.SEPARATOR}${milliseconds}`;
|
|
532
|
-
}
|
|
533
|
-
};
|
|
534
|
-
exports.A_Logger = __decorateClass([
|
|
535
|
-
__decorateParam(0, aConcept.A_Inject(aConcept.A_Scope)),
|
|
536
|
-
__decorateParam(1, aConcept.A_Inject(A_Config))
|
|
537
|
-
], exports.A_Logger);
|
|
538
|
-
|
|
539
|
-
// src/lib/A-Channel/A-Channel.component.ts
|
|
540
|
-
var A_Channel = class extends aConcept.A_Component {
|
|
541
|
-
/**
|
|
542
|
-
* Creates a new A_Channel instance.
|
|
543
|
-
*
|
|
544
|
-
* The channel must be registered with A_Context before use:
|
|
545
|
-
* ```typescript
|
|
546
|
-
* const channel = new A_Channel();
|
|
547
|
-
* A_Context.root.register(channel);
|
|
548
|
-
* ```
|
|
549
|
-
*/
|
|
550
|
-
constructor() {
|
|
551
|
-
super();
|
|
552
|
-
/**
|
|
553
|
-
* Indicates whether the channel is currently processing requests.
|
|
554
|
-
* This flag is managed automatically during request/send operations.
|
|
555
|
-
*
|
|
556
|
-
* @readonly
|
|
557
|
-
*/
|
|
558
|
-
this._processing = false;
|
|
559
|
-
/**
|
|
560
|
-
* Internal cache storage for channel-specific data.
|
|
561
|
-
* Can be used by custom implementations for caching responses,
|
|
562
|
-
* connection pools, or other channel-specific state.
|
|
563
|
-
*
|
|
564
|
-
* @protected
|
|
565
|
-
*/
|
|
566
|
-
this._cache = /* @__PURE__ */ new Map();
|
|
567
|
-
}
|
|
568
|
-
/**
|
|
569
|
-
* Indicates whether the channel is currently processing requests.
|
|
570
|
-
*
|
|
571
|
-
* @returns {boolean} True if channel is processing, false otherwise
|
|
572
|
-
*/
|
|
573
|
-
get processing() {
|
|
574
|
-
return this._processing;
|
|
575
|
-
}
|
|
576
|
-
/**
|
|
577
|
-
* Promise that resolves when the channel is fully initialized.
|
|
578
|
-
*
|
|
579
|
-
* Automatically calls the onConnect lifecycle hook if not already called.
|
|
580
|
-
* This ensures the channel is ready for communication operations.
|
|
581
|
-
*
|
|
582
|
-
* @returns {Promise<void>} Promise that resolves when initialization is complete
|
|
583
|
-
*/
|
|
584
|
-
get initialize() {
|
|
585
|
-
if (!this._initialized) {
|
|
586
|
-
this._initialized = this.connect();
|
|
587
|
-
}
|
|
588
|
-
return this._initialized;
|
|
589
|
-
}
|
|
590
|
-
async onConnect(...args) {
|
|
591
|
-
}
|
|
592
|
-
async onDisconnect(...args) {
|
|
593
|
-
}
|
|
594
|
-
async onBeforeRequest(...args) {
|
|
595
|
-
}
|
|
596
|
-
async onRequest(...args) {
|
|
597
|
-
}
|
|
598
|
-
async onAfterRequest(...args) {
|
|
599
|
-
}
|
|
600
|
-
async onError(...args) {
|
|
601
|
-
}
|
|
602
|
-
async onSend(...args) {
|
|
603
|
-
}
|
|
604
|
-
// ==========================================================
|
|
605
|
-
// ================= Public API Methods ===================
|
|
606
|
-
// ==========================================================
|
|
607
|
-
/**
|
|
608
|
-
* Initializes the channel by calling the onConnect lifecycle hook.
|
|
192
|
+
* Initializes the channel by calling the onConnect lifecycle hook.
|
|
609
193
|
*
|
|
610
194
|
* This method is called automatically when accessing the `initialize` property.
|
|
611
195
|
* You can also call it manually if needed.
|
|
@@ -670,7 +254,6 @@ var A_Channel = class extends aConcept.A_Component {
|
|
|
670
254
|
});
|
|
671
255
|
const context = new A_ChannelRequest(params);
|
|
672
256
|
try {
|
|
673
|
-
requestScope.inherit(aConcept.A_Context.scope(this));
|
|
674
257
|
requestScope.register(context);
|
|
675
258
|
await this.call("onBeforeRequest" /* onBeforeRequest */, requestScope);
|
|
676
259
|
await this.call("onRequest" /* onRequest */, requestScope);
|
|
@@ -681,8 +264,10 @@ var A_Channel = class extends aConcept.A_Component {
|
|
|
681
264
|
this._processing = false;
|
|
682
265
|
const channelError = new A_ChannelError(error);
|
|
683
266
|
context.fail(channelError);
|
|
267
|
+
requestScope.register(channelError);
|
|
684
268
|
await this.call("onError" /* onError */, requestScope);
|
|
685
|
-
|
|
269
|
+
requestScope.destroy();
|
|
270
|
+
throw channelError;
|
|
686
271
|
}
|
|
687
272
|
}
|
|
688
273
|
/**
|
|
@@ -733,7 +318,7 @@ var A_Channel = class extends aConcept.A_Component {
|
|
|
733
318
|
const requestScope = new aConcept.A_Scope({
|
|
734
319
|
name: `a-channel@scope:send:${aConcept.A_IdentityHelper.generateTimeId()}`
|
|
735
320
|
});
|
|
736
|
-
const context = new
|
|
321
|
+
const context = new A_OperationContext("send", message);
|
|
737
322
|
try {
|
|
738
323
|
requestScope.inherit(aConcept.A_Context.scope(this));
|
|
739
324
|
requestScope.register(context);
|
|
@@ -742,8 +327,10 @@ var A_Channel = class extends aConcept.A_Component {
|
|
|
742
327
|
} catch (error) {
|
|
743
328
|
this._processing = false;
|
|
744
329
|
const channelError = new A_ChannelError(error);
|
|
330
|
+
requestScope.register(channelError);
|
|
745
331
|
context.fail(channelError);
|
|
746
332
|
await this.call("onError" /* onError */, requestScope);
|
|
333
|
+
requestScope.destroy();
|
|
747
334
|
}
|
|
748
335
|
}
|
|
749
336
|
/**
|
|
@@ -758,7 +345,7 @@ var A_Channel = class extends aConcept.A_Component {
|
|
|
758
345
|
await this.initialize;
|
|
759
346
|
this._processing = true;
|
|
760
347
|
const requestScope = new aConcept.A_Scope({ name: `a-channel@scope:consume:${aConcept.A_IdentityHelper.generateTimeId()}` });
|
|
761
|
-
const context = new
|
|
348
|
+
const context = new A_OperationContext("consume", {});
|
|
762
349
|
try {
|
|
763
350
|
requestScope.inherit(aConcept.A_Context.scope(this));
|
|
764
351
|
requestScope.register(context);
|
|
@@ -809,141 +396,741 @@ __decorateClass([
|
|
|
809
396
|
name: "onSend" /* onSend */
|
|
810
397
|
})
|
|
811
398
|
], A_Channel.prototype, "onSend", 1);
|
|
812
|
-
|
|
399
|
+
|
|
400
|
+
// src/lib/A-Command/A-Command.constants.ts
|
|
401
|
+
var A_Command_Status = /* @__PURE__ */ ((A_Command_Status2) => {
|
|
402
|
+
A_Command_Status2["CREATED"] = "CREATED";
|
|
403
|
+
A_Command_Status2["INITIALIZED"] = "INITIALIZED";
|
|
404
|
+
A_Command_Status2["COMPILED"] = "COMPILED";
|
|
405
|
+
A_Command_Status2["EXECUTING"] = "EXECUTING";
|
|
406
|
+
A_Command_Status2["COMPLETED"] = "COMPLETED";
|
|
407
|
+
A_Command_Status2["FAILED"] = "FAILED";
|
|
408
|
+
return A_Command_Status2;
|
|
409
|
+
})(A_Command_Status || {});
|
|
410
|
+
var A_CommandTransitions = /* @__PURE__ */ ((A_CommandTransitions2) => {
|
|
411
|
+
A_CommandTransitions2["CREATED_TO_INITIALIZED"] = "created_initialized";
|
|
412
|
+
A_CommandTransitions2["INITIALIZED_TO_EXECUTING"] = "initialized_executing";
|
|
413
|
+
A_CommandTransitions2["EXECUTING_TO_COMPLETED"] = "executing_completed";
|
|
414
|
+
A_CommandTransitions2["EXECUTING_TO_FAILED"] = "executing_failed";
|
|
415
|
+
return A_CommandTransitions2;
|
|
416
|
+
})(A_CommandTransitions || {});
|
|
417
|
+
var A_CommandFeatures = /* @__PURE__ */ ((A_CommandFeatures2) => {
|
|
418
|
+
A_CommandFeatures2["onInit"] = "onInit";
|
|
419
|
+
A_CommandFeatures2["onBeforeExecute"] = "onBeforeExecute";
|
|
420
|
+
A_CommandFeatures2["onExecute"] = "onExecute";
|
|
421
|
+
A_CommandFeatures2["onAfterExecute"] = "onAfterExecute";
|
|
422
|
+
A_CommandFeatures2["onComplete"] = "onComplete";
|
|
423
|
+
A_CommandFeatures2["onFail"] = "onFail";
|
|
424
|
+
A_CommandFeatures2["onError"] = "onError";
|
|
425
|
+
return A_CommandFeatures2;
|
|
426
|
+
})(A_CommandFeatures || {});
|
|
427
|
+
var A_CommandError = class extends aConcept.A_Error {
|
|
813
428
|
};
|
|
814
|
-
|
|
815
|
-
|
|
429
|
+
A_CommandError.CommandScopeBindingError = "A-Command Scope Binding Error";
|
|
430
|
+
A_CommandError.ExecutionError = "A-Command Execution Error";
|
|
431
|
+
A_CommandError.ResultProcessingError = "A-Command Result Processing Error";
|
|
432
|
+
/**
|
|
433
|
+
* Error indicating that the command was interrupted during execution
|
|
434
|
+
*/
|
|
435
|
+
A_CommandError.CommandInterruptedError = "A-Command Interrupted Error";
|
|
436
|
+
var A_StateMachineError = class extends aConcept.A_Error {
|
|
437
|
+
};
|
|
438
|
+
A_StateMachineError.InitializationError = "A-StateMachine Initialization Error";
|
|
439
|
+
A_StateMachineError.TransitionError = "A-StateMachine Transition Error";
|
|
440
|
+
|
|
441
|
+
// src/lib/A-StateMachine/A-StateMachineTransition.context.ts
|
|
442
|
+
var A_StateMachineTransition = class extends A_OperationContext {
|
|
443
|
+
constructor(params) {
|
|
444
|
+
super(
|
|
445
|
+
"a-state-machine-transition",
|
|
446
|
+
params
|
|
447
|
+
);
|
|
448
|
+
this._meta.set("from", params.from);
|
|
449
|
+
this._meta.set("to", params.to);
|
|
450
|
+
}
|
|
451
|
+
get from() {
|
|
452
|
+
return this._meta.get("from");
|
|
453
|
+
}
|
|
454
|
+
get to() {
|
|
455
|
+
return this._meta.get("to");
|
|
456
|
+
}
|
|
457
|
+
};
|
|
458
|
+
|
|
459
|
+
// src/lib/A-StateMachine/A-StateMachine.component.ts
|
|
460
|
+
var _a, _b, _c, _d;
|
|
461
|
+
var A_StateMachine = class extends aConcept.A_Component {
|
|
462
|
+
/**
|
|
463
|
+
* Gets a promise that resolves when the state machine is fully initialized and ready for transitions.
|
|
464
|
+
* This ensures that all initialization hooks have been executed before allowing state transitions.
|
|
465
|
+
*
|
|
466
|
+
* @returns Promise<void> that resolves when initialization is complete
|
|
467
|
+
*
|
|
468
|
+
* @example
|
|
469
|
+
* ```typescript
|
|
470
|
+
* const stateMachine = new MyStateMachine();
|
|
471
|
+
* await stateMachine.ready; // Wait for initialization
|
|
472
|
+
* await stateMachine.transition('idle', 'running');
|
|
473
|
+
* ```
|
|
474
|
+
*/
|
|
475
|
+
get ready() {
|
|
476
|
+
if (!this._initialized) {
|
|
477
|
+
this._initialized = this.call("onInitialize" /* onInitialize */);
|
|
478
|
+
}
|
|
479
|
+
return this._initialized;
|
|
480
|
+
}
|
|
481
|
+
async [_d = "onInitialize" /* onInitialize */](...args) {
|
|
482
|
+
}
|
|
483
|
+
async [_c = "onBeforeTransition" /* onBeforeTransition */](...args) {
|
|
484
|
+
}
|
|
485
|
+
async [_b = "onAfterTransition" /* onAfterTransition */](...args) {
|
|
486
|
+
}
|
|
487
|
+
async [_a = "onError" /* onError */](...args) {
|
|
488
|
+
}
|
|
489
|
+
/**
|
|
490
|
+
* Executes a state transition from one state to another.
|
|
491
|
+
* This is the core method of the state machine that handles the complete transition lifecycle.
|
|
492
|
+
*
|
|
493
|
+
* @param from - The state to transition from (must be a key of T)
|
|
494
|
+
* @param to - The state to transition to (must be a key of T)
|
|
495
|
+
* @param props - Optional properties to pass to the transition context (should match T[keyof T])
|
|
496
|
+
* @returns Promise<void> that resolves when the transition is complete
|
|
497
|
+
*
|
|
498
|
+
* @throws {A_StateMachineError} When the transition fails for any reason
|
|
499
|
+
*
|
|
500
|
+
* @example
|
|
501
|
+
* ```typescript
|
|
502
|
+
* interface OrderStates {
|
|
503
|
+
* pending: { orderId: string };
|
|
504
|
+
* processing: { orderId: string; processedBy: string };
|
|
505
|
+
* }
|
|
506
|
+
*
|
|
507
|
+
* const orderMachine = new A_StateMachine<OrderStates>();
|
|
508
|
+
*
|
|
509
|
+
* // Transition with props
|
|
510
|
+
* await orderMachine.transition('pending', 'processing', {
|
|
511
|
+
* orderId: '12345',
|
|
512
|
+
* processedBy: 'user-456'
|
|
513
|
+
* });
|
|
514
|
+
* ```
|
|
515
|
+
*
|
|
516
|
+
* The transition process follows this lifecycle:
|
|
517
|
+
* 1. Wait for state machine initialization (ready)
|
|
518
|
+
* 2. Create transition name in camelCase format (e.g., "pending_processing")
|
|
519
|
+
* 3. Create operation context with transition data
|
|
520
|
+
* 4. Create isolated scope for the transition
|
|
521
|
+
* 5. Call onBeforeTransition hook
|
|
522
|
+
* 6. Execute the specific transition method (if defined)
|
|
523
|
+
* 7. Call onAfterTransition hook
|
|
524
|
+
* 8. Clean up scope and return result
|
|
525
|
+
*
|
|
526
|
+
* If any step fails, the onError hook is called and a wrapped error is thrown.
|
|
527
|
+
*/
|
|
528
|
+
async transition(from, to, props) {
|
|
529
|
+
await this.ready;
|
|
530
|
+
const transitionName = `${aConcept.A_FormatterHelper.toCamelCase(String(from))}_${aConcept.A_FormatterHelper.toCamelCase(String(to))}`;
|
|
531
|
+
const transition = new A_StateMachineTransition({
|
|
532
|
+
from: String(from),
|
|
533
|
+
to: String(to),
|
|
534
|
+
props
|
|
535
|
+
});
|
|
536
|
+
const scope = new aConcept.A_Scope({
|
|
537
|
+
name: `A-StateMachine-Transition-Scope-${transitionName}`,
|
|
538
|
+
fragments: [transition]
|
|
539
|
+
});
|
|
540
|
+
try {
|
|
541
|
+
await this.call("onBeforeTransition" /* onBeforeTransition */, scope);
|
|
542
|
+
await this.call(transitionName, scope);
|
|
543
|
+
await this.call("onAfterTransition" /* onAfterTransition */, scope);
|
|
544
|
+
scope.destroy();
|
|
545
|
+
return transition.result;
|
|
546
|
+
} catch (error) {
|
|
547
|
+
const wrappedError = new A_StateMachineError({
|
|
548
|
+
title: A_StateMachineError.TransitionError,
|
|
549
|
+
description: `An error occurred while transitioning to "${transitionName}"`,
|
|
550
|
+
originalError: error
|
|
551
|
+
});
|
|
552
|
+
scope.register(wrappedError);
|
|
553
|
+
await this.call("onError" /* onError */, scope);
|
|
554
|
+
scope.destroy();
|
|
555
|
+
throw wrappedError;
|
|
556
|
+
}
|
|
557
|
+
}
|
|
558
|
+
};
|
|
559
|
+
__decorateClass([
|
|
560
|
+
aConcept.A_Feature.Extend()
|
|
561
|
+
], A_StateMachine.prototype, _d, 1);
|
|
562
|
+
__decorateClass([
|
|
563
|
+
aConcept.A_Feature.Extend()
|
|
564
|
+
], A_StateMachine.prototype, _c, 1);
|
|
565
|
+
__decorateClass([
|
|
566
|
+
aConcept.A_Feature.Extend()
|
|
567
|
+
], A_StateMachine.prototype, _b, 1);
|
|
568
|
+
__decorateClass([
|
|
569
|
+
aConcept.A_Feature.Extend()
|
|
570
|
+
], A_StateMachine.prototype, _a, 1);
|
|
571
|
+
|
|
572
|
+
// src/lib/A-Config/A-Config.constants.ts
|
|
573
|
+
var A_CONSTANTS__CONFIG_ENV_VARIABLES = {};
|
|
574
|
+
var A_CONSTANTS__CONFIG_ENV_VARIABLES_ARRAY = [];
|
|
575
|
+
|
|
576
|
+
// src/lib/A-Config/A-Config.context.ts
|
|
577
|
+
var A_Config = class extends aConcept.A_Fragment {
|
|
578
|
+
constructor(config) {
|
|
579
|
+
super({
|
|
580
|
+
name: "A_Config"
|
|
581
|
+
});
|
|
582
|
+
this.VARIABLES = /* @__PURE__ */ new Map();
|
|
583
|
+
this.DEFAULT_ALLOWED_TO_READ_PROPERTIES = [
|
|
584
|
+
...aConcept.A_CONSTANTS__DEFAULT_ENV_VARIABLES_ARRAY,
|
|
585
|
+
...A_CONSTANTS__CONFIG_ENV_VARIABLES_ARRAY
|
|
586
|
+
];
|
|
587
|
+
this.config = aConcept.A_CommonHelper.deepCloneAndMerge(config, {
|
|
588
|
+
strict: false,
|
|
589
|
+
defaults: {},
|
|
590
|
+
variables: aConcept.A_CONSTANTS__DEFAULT_ENV_VARIABLES_ARRAY
|
|
591
|
+
});
|
|
592
|
+
this.CONFIG_PROPERTIES = this.config.variables ? this.config.variables : [];
|
|
593
|
+
this.config.variables.forEach((variable) => {
|
|
594
|
+
this.VARIABLES.set(
|
|
595
|
+
aConcept.A_FormatterHelper.toUpperSnakeCase(variable),
|
|
596
|
+
this.config.defaults[variable]
|
|
597
|
+
);
|
|
598
|
+
});
|
|
599
|
+
}
|
|
600
|
+
/**
|
|
601
|
+
* This method is used to get the configuration property by name
|
|
602
|
+
*
|
|
603
|
+
* @param property
|
|
604
|
+
* @returns
|
|
605
|
+
*/
|
|
606
|
+
get(property) {
|
|
607
|
+
if (this.CONFIG_PROPERTIES.includes(property) || this.DEFAULT_ALLOWED_TO_READ_PROPERTIES.includes(property) || !this.config.strict)
|
|
608
|
+
return this.VARIABLES.get(aConcept.A_FormatterHelper.toUpperSnakeCase(property));
|
|
609
|
+
throw new Error("Property not exists or not allowed to read");
|
|
610
|
+
}
|
|
611
|
+
set(property, value) {
|
|
612
|
+
const array = Array.isArray(property) ? property : typeof property === "string" ? [{ property, value }] : Object.keys(property).map((key) => ({
|
|
613
|
+
property: key,
|
|
614
|
+
value: property[key]
|
|
615
|
+
}));
|
|
616
|
+
for (const { property: property2, value: value2 } of array) {
|
|
617
|
+
let targetValue = value2 ? value2 : this.config?.defaults ? this.config.defaults[property2] : void 0;
|
|
618
|
+
this.VARIABLES.set(aConcept.A_FormatterHelper.toUpperSnakeCase(property2), targetValue);
|
|
619
|
+
}
|
|
620
|
+
}
|
|
621
|
+
};
|
|
622
|
+
|
|
623
|
+
// src/lib/A-Logger/A-Logger.constants.ts
|
|
624
|
+
var A_LOGGER_DEFAULT_SCOPE_LENGTH = 20;
|
|
625
|
+
var A_LOGGER_COLORS = {
|
|
626
|
+
// System colors (reserved for specific purposes)
|
|
627
|
+
red: "31",
|
|
628
|
+
// Errors, critical issues
|
|
629
|
+
yellow: "33",
|
|
630
|
+
// Warnings, caution messages
|
|
631
|
+
green: "32",
|
|
632
|
+
// Success, completion messages
|
|
633
|
+
// Safe palette for random selection (grey-blue-violet theme)
|
|
634
|
+
blue: "34",
|
|
635
|
+
// Info, general messages
|
|
636
|
+
cyan: "36",
|
|
637
|
+
// Headers, titles
|
|
638
|
+
magenta: "35",
|
|
639
|
+
// Special highlighting
|
|
640
|
+
gray: "90",
|
|
641
|
+
// Debug, less important info
|
|
642
|
+
brightBlue: "94",
|
|
643
|
+
// Bright blue variant
|
|
644
|
+
brightCyan: "96",
|
|
645
|
+
// Bright cyan variant
|
|
646
|
+
brightMagenta: "95",
|
|
647
|
+
// Bright magenta variant
|
|
648
|
+
darkGray: "30",
|
|
649
|
+
// Dark gray
|
|
650
|
+
lightGray: "37",
|
|
651
|
+
// Light gray (white)
|
|
652
|
+
// Extended blue-violet palette
|
|
653
|
+
indigo: "38;5;54",
|
|
654
|
+
// Deep indigo
|
|
655
|
+
violet: "38;5;93",
|
|
656
|
+
// Violet
|
|
657
|
+
purple: "38;5;129",
|
|
658
|
+
// Purple
|
|
659
|
+
lavender: "38;5;183",
|
|
660
|
+
// Lavender
|
|
661
|
+
skyBlue: "38;5;117",
|
|
662
|
+
// Sky blue
|
|
663
|
+
steelBlue: "38;5;67",
|
|
664
|
+
// Steel blue
|
|
665
|
+
slateBlue: "38;5;62",
|
|
666
|
+
// Slate blue
|
|
667
|
+
deepBlue: "38;5;18",
|
|
668
|
+
// Deep blue
|
|
669
|
+
lightBlue: "38;5;153",
|
|
670
|
+
// Light blue
|
|
671
|
+
periwinkle: "38;5;111",
|
|
672
|
+
// Periwinkle
|
|
673
|
+
cornflower: "38;5;69",
|
|
674
|
+
// Cornflower blue
|
|
675
|
+
powder: "38;5;152",
|
|
676
|
+
// Powder blue
|
|
677
|
+
// Additional grays for variety
|
|
678
|
+
charcoal: "38;5;236",
|
|
679
|
+
// Charcoal
|
|
680
|
+
silver: "38;5;250",
|
|
681
|
+
// Silver
|
|
682
|
+
smoke: "38;5;244",
|
|
683
|
+
// Smoke gray
|
|
684
|
+
slate: "38;5;240"
|
|
685
|
+
// Slate gray
|
|
686
|
+
};
|
|
687
|
+
var A_LOGGER_SAFE_RANDOM_COLORS = [
|
|
688
|
+
"blue",
|
|
689
|
+
"cyan",
|
|
690
|
+
"magenta",
|
|
691
|
+
"gray",
|
|
692
|
+
"brightBlue",
|
|
693
|
+
"brightCyan",
|
|
694
|
+
"brightMagenta",
|
|
695
|
+
"darkGray",
|
|
696
|
+
"lightGray",
|
|
697
|
+
"indigo",
|
|
698
|
+
"violet",
|
|
699
|
+
"purple",
|
|
700
|
+
"lavender",
|
|
701
|
+
"skyBlue",
|
|
702
|
+
"steelBlue",
|
|
703
|
+
"slateBlue",
|
|
704
|
+
"deepBlue",
|
|
705
|
+
"lightBlue",
|
|
706
|
+
"periwinkle",
|
|
707
|
+
"cornflower",
|
|
708
|
+
"powder",
|
|
709
|
+
"charcoal",
|
|
710
|
+
"silver",
|
|
711
|
+
"smoke",
|
|
712
|
+
"slate"
|
|
713
|
+
];
|
|
714
|
+
var A_LOGGER_ANSI = {
|
|
715
|
+
RESET: "\x1B[0m",
|
|
716
|
+
PREFIX: "\x1B[",
|
|
717
|
+
SUFFIX: "m"
|
|
718
|
+
};
|
|
719
|
+
var A_LOGGER_TIME_FORMAT = {
|
|
720
|
+
MINUTES_PAD: 2,
|
|
721
|
+
SECONDS_PAD: 2,
|
|
722
|
+
MILLISECONDS_PAD: 3,
|
|
723
|
+
SEPARATOR: ":"
|
|
724
|
+
};
|
|
725
|
+
var A_LOGGER_FORMAT = {
|
|
726
|
+
SCOPE_OPEN: "[",
|
|
727
|
+
SCOPE_CLOSE: "]",
|
|
728
|
+
TIME_OPEN: "|",
|
|
729
|
+
TIME_CLOSE: "|",
|
|
730
|
+
SEPARATOR: "-------------------------------",
|
|
731
|
+
PIPE: "| "
|
|
732
|
+
};
|
|
733
|
+
var A_LOGGER_ENV_KEYS = {
|
|
734
|
+
LOG_LEVEL: "A_LOGGER_LEVEL",
|
|
735
|
+
DEFAULT_SCOPE_LENGTH: "A_LOGGER_DEFAULT_SCOPE_LENGTH",
|
|
736
|
+
DEFAULT_SCOPE_COLOR: "A_LOGGER_DEFAULT_SCOPE_COLOR",
|
|
737
|
+
DEFAULT_LOG_COLOR: "A_LOGGER_DEFAULT_LOG_COLOR"
|
|
738
|
+
};
|
|
739
|
+
|
|
740
|
+
// src/lib/A-Logger/A-Logger.component.ts
|
|
741
|
+
exports.A_Logger = class A_Logger extends aConcept.A_Component {
|
|
742
|
+
// =============================================
|
|
743
|
+
// Constructor and Initialization
|
|
744
|
+
// =============================================
|
|
745
|
+
/**
|
|
746
|
+
* Initialize A_Logger with dependency injection
|
|
747
|
+
* Colors are configured through A_Config or generated randomly if not provided
|
|
748
|
+
*
|
|
749
|
+
* @param scope - The current scope context for message prefixing
|
|
750
|
+
* @param config - Optional configuration for log level filtering and color settings
|
|
751
|
+
*/
|
|
752
|
+
constructor(scope, config) {
|
|
816
753
|
super();
|
|
817
|
-
this.
|
|
754
|
+
this.scope = scope;
|
|
755
|
+
this.config = config;
|
|
756
|
+
this.COLORS = A_LOGGER_COLORS;
|
|
757
|
+
this.STANDARD_SCOPE_LENGTH = config?.get(A_LOGGER_ENV_KEYS.DEFAULT_SCOPE_LENGTH) || A_LOGGER_DEFAULT_SCOPE_LENGTH;
|
|
758
|
+
const configScopeColor = config?.get(A_LOGGER_ENV_KEYS.DEFAULT_SCOPE_COLOR);
|
|
759
|
+
const configLogColor = config?.get(A_LOGGER_ENV_KEYS.DEFAULT_LOG_COLOR);
|
|
760
|
+
if (configScopeColor || configLogColor) {
|
|
761
|
+
this.DEFAULT_SCOPE_COLOR = configScopeColor || this.generateColorFromScopeName(this.scope.name);
|
|
762
|
+
this.DEFAULT_LOG_COLOR = configLogColor || this.generateColorFromScopeName(this.scope.name);
|
|
763
|
+
} else {
|
|
764
|
+
const complementaryColors = this.generateComplementaryColorsFromScope(this.scope.name);
|
|
765
|
+
this.DEFAULT_SCOPE_COLOR = complementaryColors.scopeColor;
|
|
766
|
+
this.DEFAULT_LOG_COLOR = complementaryColors.logColor;
|
|
767
|
+
}
|
|
768
|
+
}
|
|
769
|
+
// =============================================
|
|
770
|
+
// Color Generation Utilities
|
|
771
|
+
// =============================================
|
|
772
|
+
/**
|
|
773
|
+
* Generate a simple hash from a string
|
|
774
|
+
* Used to create deterministic color selection based on scope name
|
|
775
|
+
*
|
|
776
|
+
* @param str - The string to hash
|
|
777
|
+
* @returns A numeric hash value
|
|
778
|
+
*/
|
|
779
|
+
simpleHash(str) {
|
|
780
|
+
let hash = 0;
|
|
781
|
+
for (let i = 0; i < str.length; i++) {
|
|
782
|
+
const char = str.charCodeAt(i);
|
|
783
|
+
hash = (hash << 5) - hash + char;
|
|
784
|
+
hash = hash & hash;
|
|
785
|
+
}
|
|
786
|
+
return Math.abs(hash);
|
|
787
|
+
}
|
|
788
|
+
/**
|
|
789
|
+
* Generate a deterministic color based on scope name
|
|
790
|
+
* Same scope names will always get the same color, but uses safe color palette
|
|
791
|
+
*
|
|
792
|
+
* @param scopeName - The scope name to generate color for
|
|
793
|
+
* @returns A color key from the safe colors palette
|
|
794
|
+
*/
|
|
795
|
+
generateColorFromScopeName(scopeName) {
|
|
796
|
+
const safeColors = A_LOGGER_SAFE_RANDOM_COLORS;
|
|
797
|
+
const hash = this.simpleHash(scopeName);
|
|
798
|
+
const colorIndex = hash % safeColors.length;
|
|
799
|
+
return safeColors[colorIndex];
|
|
800
|
+
}
|
|
801
|
+
/**
|
|
802
|
+
* Generate a pair of complementary colors based on scope name
|
|
803
|
+
* Ensures visual harmony between scope and message colors while being deterministic
|
|
804
|
+
*
|
|
805
|
+
* @param scopeName - The scope name to base colors on
|
|
806
|
+
* @returns Object with scopeColor and logColor that work well together
|
|
807
|
+
*/
|
|
808
|
+
generateComplementaryColorsFromScope(scopeName) {
|
|
809
|
+
const colorPairs = [
|
|
810
|
+
{ scopeColor: "indigo", logColor: "lightBlue" },
|
|
811
|
+
{ scopeColor: "deepBlue", logColor: "cyan" },
|
|
812
|
+
{ scopeColor: "purple", logColor: "lavender" },
|
|
813
|
+
{ scopeColor: "steelBlue", logColor: "skyBlue" },
|
|
814
|
+
{ scopeColor: "slateBlue", logColor: "periwinkle" },
|
|
815
|
+
{ scopeColor: "charcoal", logColor: "silver" },
|
|
816
|
+
{ scopeColor: "violet", logColor: "brightMagenta" },
|
|
817
|
+
{ scopeColor: "darkGray", logColor: "lightGray" },
|
|
818
|
+
{ scopeColor: "cornflower", logColor: "powder" },
|
|
819
|
+
{ scopeColor: "slate", logColor: "smoke" }
|
|
820
|
+
];
|
|
821
|
+
const hash = this.simpleHash(scopeName);
|
|
822
|
+
const pairIndex = hash % colorPairs.length;
|
|
823
|
+
return colorPairs[pairIndex];
|
|
824
|
+
}
|
|
825
|
+
// =============================================
|
|
826
|
+
// Factory Methods
|
|
827
|
+
// =============================================
|
|
828
|
+
// =============================================
|
|
829
|
+
// Scope and Formatting Utilities
|
|
830
|
+
// =============================================
|
|
831
|
+
/**
|
|
832
|
+
* Get the formatted scope length for consistent message alignment
|
|
833
|
+
* Uses a standard length to ensure all messages align properly regardless of scope name
|
|
834
|
+
*
|
|
835
|
+
* @returns The scope length to use for padding calculations
|
|
836
|
+
*/
|
|
837
|
+
get scopeLength() {
|
|
838
|
+
return Math.max(this.scope.name.length, this.STANDARD_SCOPE_LENGTH);
|
|
818
839
|
}
|
|
819
|
-
|
|
820
|
-
|
|
821
|
-
|
|
840
|
+
/**
|
|
841
|
+
* Get the formatted scope name with proper padding, centered within the container
|
|
842
|
+
* Ensures consistent width for all scope names in log output with centered alignment
|
|
843
|
+
*
|
|
844
|
+
* @returns Centered and padded scope name for consistent formatting
|
|
845
|
+
*/
|
|
846
|
+
get formattedScope() {
|
|
847
|
+
const scopeName = this.scope.name;
|
|
848
|
+
const totalLength = this.STANDARD_SCOPE_LENGTH;
|
|
849
|
+
if (scopeName.length >= totalLength) {
|
|
850
|
+
return scopeName.substring(0, totalLength);
|
|
851
|
+
}
|
|
852
|
+
const totalPadding = totalLength - scopeName.length;
|
|
853
|
+
const leftPadding = Math.floor(totalPadding / 2);
|
|
854
|
+
const rightPadding = totalPadding - leftPadding;
|
|
855
|
+
return " ".repeat(leftPadding) + scopeName + " ".repeat(rightPadding);
|
|
822
856
|
}
|
|
823
|
-
|
|
857
|
+
// =============================================
|
|
858
|
+
// Message Compilation and Formatting
|
|
859
|
+
// =============================================
|
|
860
|
+
/**
|
|
861
|
+
* Compile log arguments into formatted console output with colors and proper alignment
|
|
862
|
+
*
|
|
863
|
+
* This method handles the core formatting logic for all log messages:
|
|
864
|
+
* - Applies separate colors for scope and message content
|
|
865
|
+
* - Formats scope names with consistent padding
|
|
866
|
+
* - Handles different data types appropriately
|
|
867
|
+
* - Maintains proper indentation for multi-line content
|
|
868
|
+
*
|
|
869
|
+
* @param messageColor - The color key to apply to the message content
|
|
870
|
+
* @param args - Variable arguments to format and display
|
|
871
|
+
* @returns Array of formatted strings ready for console output
|
|
872
|
+
*/
|
|
873
|
+
compile(messageColor, ...args) {
|
|
874
|
+
const timeString = this.getTime();
|
|
875
|
+
const scopePadding = " ".repeat(this.scopeLength + 3);
|
|
876
|
+
const isMultiArg = args.length > 1;
|
|
877
|
+
return [
|
|
878
|
+
// Header with separate colors for scope and message content
|
|
879
|
+
`${A_LOGGER_ANSI.PREFIX}${this.COLORS[this.DEFAULT_SCOPE_COLOR]}${A_LOGGER_ANSI.SUFFIX}${A_LOGGER_FORMAT.SCOPE_OPEN}${this.formattedScope}${A_LOGGER_FORMAT.SCOPE_CLOSE}${A_LOGGER_ANSI.RESET} ${A_LOGGER_ANSI.PREFIX}${this.COLORS[messageColor]}${A_LOGGER_ANSI.SUFFIX}${A_LOGGER_FORMAT.TIME_OPEN}${timeString}${A_LOGGER_FORMAT.TIME_CLOSE}`,
|
|
880
|
+
// Top separator for multi-argument messages
|
|
881
|
+
isMultiArg ? `
|
|
882
|
+
${scopePadding}${A_LOGGER_FORMAT.TIME_OPEN}${A_LOGGER_FORMAT.SEPARATOR}` : "",
|
|
883
|
+
// Process each argument with appropriate formatting
|
|
884
|
+
...args.map((arg, i) => {
|
|
885
|
+
const shouldAddNewline = i > 0 || isMultiArg;
|
|
886
|
+
switch (true) {
|
|
887
|
+
case arg instanceof aConcept.A_Error:
|
|
888
|
+
return this.compile_A_Error(arg);
|
|
889
|
+
case arg instanceof Error:
|
|
890
|
+
return this.compile_Error(arg);
|
|
891
|
+
case (typeof arg === "object" && arg !== null):
|
|
892
|
+
return this.formatObject(arg, shouldAddNewline, scopePadding);
|
|
893
|
+
default:
|
|
894
|
+
return this.formatString(String(arg), shouldAddNewline, scopePadding);
|
|
895
|
+
}
|
|
896
|
+
}),
|
|
897
|
+
// Bottom separator and color reset
|
|
898
|
+
isMultiArg ? `
|
|
899
|
+
${scopePadding}${A_LOGGER_FORMAT.TIME_OPEN}${A_LOGGER_FORMAT.SEPARATOR}${A_LOGGER_ANSI.RESET}` : A_LOGGER_ANSI.RESET
|
|
900
|
+
];
|
|
824
901
|
}
|
|
825
|
-
};
|
|
826
|
-
__decorateClass([
|
|
827
|
-
aConcept.A_Feature.Extend({
|
|
828
|
-
name: "onError" /* onError */,
|
|
829
|
-
scope: [PollyspotChannel]
|
|
830
|
-
}),
|
|
831
|
-
__decorateParam(0, aConcept.A_Inject(A_ChannelRequest)),
|
|
832
|
-
__decorateParam(1, aConcept.A_Inject(exports.A_Logger)),
|
|
833
|
-
__decorateParam(2, aConcept.A_Inject(A_Config))
|
|
834
|
-
], GlobalErrorhandler.prototype, "handleError", 1);
|
|
835
|
-
__decorateClass([
|
|
836
|
-
aConcept.A_Feature.Extend({
|
|
837
|
-
name: "onError" /* onError */
|
|
838
|
-
}),
|
|
839
|
-
__decorateParam(0, aConcept.A_Inject(A_ChannelRequest)),
|
|
840
|
-
__decorateParam(1, aConcept.A_Inject(exports.A_Logger)),
|
|
841
|
-
__decorateParam(2, aConcept.A_Inject(A_Config))
|
|
842
|
-
], GlobalErrorhandler.prototype, "anotherError", 1);
|
|
843
|
-
|
|
844
|
-
// src/lib/A-Command/A-Command.constants.ts
|
|
845
|
-
var A_CONSTANTS__A_Command_Status = /* @__PURE__ */ ((A_CONSTANTS__A_Command_Status2) => {
|
|
846
|
-
A_CONSTANTS__A_Command_Status2["CREATED"] = "CREATED";
|
|
847
|
-
A_CONSTANTS__A_Command_Status2["INITIALIZATION"] = "INITIALIZATION";
|
|
848
|
-
A_CONSTANTS__A_Command_Status2["INITIALIZED"] = "INITIALIZED";
|
|
849
|
-
A_CONSTANTS__A_Command_Status2["COMPILATION"] = "COMPILATION";
|
|
850
|
-
A_CONSTANTS__A_Command_Status2["COMPILED"] = "COMPILED";
|
|
851
|
-
A_CONSTANTS__A_Command_Status2["IN_PROGRESS"] = "IN_PROGRESS";
|
|
852
|
-
A_CONSTANTS__A_Command_Status2["COMPLETED"] = "COMPLETED";
|
|
853
|
-
A_CONSTANTS__A_Command_Status2["FAILED"] = "FAILED";
|
|
854
|
-
return A_CONSTANTS__A_Command_Status2;
|
|
855
|
-
})(A_CONSTANTS__A_Command_Status || {});
|
|
856
|
-
var A_CommandFeatures = /* @__PURE__ */ ((A_CommandFeatures2) => {
|
|
857
|
-
A_CommandFeatures2["onInit"] = "onInit";
|
|
858
|
-
A_CommandFeatures2["onCompile"] = "onCompile";
|
|
859
|
-
A_CommandFeatures2["onExecute"] = "onExecute";
|
|
860
|
-
A_CommandFeatures2["onComplete"] = "onComplete";
|
|
861
|
-
A_CommandFeatures2["onFail"] = "onFail";
|
|
862
|
-
return A_CommandFeatures2;
|
|
863
|
-
})(A_CommandFeatures || {});
|
|
864
|
-
var A_Memory = class extends aConcept.A_Fragment {
|
|
865
902
|
/**
|
|
866
|
-
*
|
|
903
|
+
* Format an object for display with proper JSON indentation
|
|
867
904
|
*
|
|
868
|
-
* @param
|
|
905
|
+
* @param obj - The object to format
|
|
906
|
+
* @param shouldAddNewline - Whether to add a newline prefix
|
|
907
|
+
* @param scopePadding - The padding string for consistent alignment
|
|
908
|
+
* @returns Formatted object string
|
|
869
909
|
*/
|
|
870
|
-
|
|
871
|
-
|
|
872
|
-
|
|
873
|
-
|
|
910
|
+
formatObject(obj, shouldAddNewline, scopePadding) {
|
|
911
|
+
let jsonString;
|
|
912
|
+
try {
|
|
913
|
+
jsonString = JSON.stringify(obj, null, 2);
|
|
914
|
+
} catch (error) {
|
|
915
|
+
const seen = /* @__PURE__ */ new WeakSet();
|
|
916
|
+
jsonString = JSON.stringify(obj, (key, value) => {
|
|
917
|
+
if (typeof value === "object" && value !== null) {
|
|
918
|
+
if (seen.has(value)) {
|
|
919
|
+
return "[Circular Reference]";
|
|
920
|
+
}
|
|
921
|
+
seen.add(value);
|
|
922
|
+
}
|
|
923
|
+
return value;
|
|
924
|
+
}, 2);
|
|
925
|
+
}
|
|
926
|
+
const formatted = jsonString.replace(/\n/g, `
|
|
927
|
+
${scopePadding}${A_LOGGER_FORMAT.PIPE}`);
|
|
928
|
+
return shouldAddNewline ? `
|
|
929
|
+
${scopePadding}${A_LOGGER_FORMAT.PIPE}` + formatted : formatted;
|
|
874
930
|
}
|
|
875
|
-
|
|
876
|
-
|
|
931
|
+
/**
|
|
932
|
+
* Format a string for display with proper indentation
|
|
933
|
+
*
|
|
934
|
+
* @param str - The string to format
|
|
935
|
+
* @param shouldAddNewline - Whether to add a newline prefix
|
|
936
|
+
* @param scopePadding - The padding string for consistent alignment
|
|
937
|
+
* @returns Formatted string
|
|
938
|
+
*/
|
|
939
|
+
formatString(str, shouldAddNewline, scopePadding) {
|
|
940
|
+
const prefix = shouldAddNewline ? "\n" : "";
|
|
941
|
+
return (prefix + str).replace(/\n/g, `
|
|
942
|
+
${scopePadding}${A_LOGGER_FORMAT.PIPE}`);
|
|
877
943
|
}
|
|
944
|
+
// =============================================
|
|
945
|
+
// Log Level Management
|
|
946
|
+
// =============================================
|
|
878
947
|
/**
|
|
879
|
-
*
|
|
948
|
+
* Determine if a log message should be output based on configured log level
|
|
880
949
|
*
|
|
881
|
-
*
|
|
882
|
-
*
|
|
950
|
+
* Log level hierarchy:
|
|
951
|
+
* - debug: Shows all messages (debug, info, warning, error)
|
|
952
|
+
* - info: Shows info, warning, and error messages
|
|
953
|
+
* - warn: Shows warning and error messages only
|
|
954
|
+
* - error: Shows error messages only
|
|
955
|
+
* - all: Shows all messages (alias for debug)
|
|
956
|
+
*
|
|
957
|
+
* @param logMethod - The type of log method being called
|
|
958
|
+
* @returns True if the message should be logged, false otherwise
|
|
883
959
|
*/
|
|
884
|
-
|
|
885
|
-
|
|
960
|
+
shouldLog(logMethod) {
|
|
961
|
+
const shouldLog = this.config?.get(A_LOGGER_ENV_KEYS.LOG_LEVEL) || "info";
|
|
962
|
+
switch (shouldLog) {
|
|
963
|
+
case "debug":
|
|
964
|
+
return true;
|
|
965
|
+
case "info":
|
|
966
|
+
return logMethod === "info" || logMethod === "warning" || logMethod === "error";
|
|
967
|
+
case "warn":
|
|
968
|
+
return logMethod === "warning" || logMethod === "error";
|
|
969
|
+
case "error":
|
|
970
|
+
return logMethod === "error";
|
|
971
|
+
case "all":
|
|
972
|
+
return true;
|
|
973
|
+
default:
|
|
974
|
+
return false;
|
|
975
|
+
}
|
|
976
|
+
}
|
|
977
|
+
debug(param1, ...args) {
|
|
978
|
+
if (!this.shouldLog("debug")) return;
|
|
979
|
+
if (typeof param1 === "string" && this.COLORS[param1]) {
|
|
980
|
+
console.log(...this.compile(param1, ...args));
|
|
981
|
+
} else {
|
|
982
|
+
console.log(...this.compile(this.DEFAULT_LOG_COLOR, param1, ...args));
|
|
983
|
+
}
|
|
984
|
+
}
|
|
985
|
+
info(param1, ...args) {
|
|
986
|
+
if (!this.shouldLog("info")) return;
|
|
987
|
+
if (typeof param1 === "string" && this.COLORS[param1]) {
|
|
988
|
+
console.log(...this.compile(param1, ...args));
|
|
989
|
+
} else {
|
|
990
|
+
console.log(...this.compile(this.DEFAULT_LOG_COLOR, param1, ...args));
|
|
991
|
+
}
|
|
992
|
+
}
|
|
993
|
+
log(param1, ...args) {
|
|
994
|
+
this.info(param1, ...args);
|
|
886
995
|
}
|
|
887
996
|
/**
|
|
888
|
-
*
|
|
997
|
+
* Log warning messages with yellow color coding
|
|
998
|
+
*
|
|
999
|
+
* Use for non-critical issues that should be brought to attention
|
|
1000
|
+
* but don't prevent normal operation
|
|
1001
|
+
*
|
|
1002
|
+
* @param args - Arguments to log as warnings
|
|
889
1003
|
*
|
|
890
|
-
* @
|
|
1004
|
+
* @example
|
|
1005
|
+
* ```typescript
|
|
1006
|
+
* logger.warning('Deprecated method used');
|
|
1007
|
+
* logger.warning('Rate limit approaching:', { current: 95, limit: 100 });
|
|
1008
|
+
* ```
|
|
891
1009
|
*/
|
|
892
|
-
|
|
893
|
-
this.
|
|
1010
|
+
warning(...args) {
|
|
1011
|
+
if (!this.shouldLog("warning")) return;
|
|
1012
|
+
console.log(...this.compile("yellow", ...args));
|
|
894
1013
|
}
|
|
895
1014
|
/**
|
|
896
|
-
*
|
|
1015
|
+
* Log error messages with red color coding
|
|
897
1016
|
*
|
|
898
|
-
*
|
|
899
|
-
*
|
|
1017
|
+
* Use for critical issues, exceptions, and failures that need immediate attention
|
|
1018
|
+
*
|
|
1019
|
+
* @param args - Arguments to log as errors
|
|
1020
|
+
* @returns void (for compatibility with console.log)
|
|
1021
|
+
*
|
|
1022
|
+
* @example
|
|
1023
|
+
* ```typescript
|
|
1024
|
+
* logger.error('Database connection failed');
|
|
1025
|
+
* logger.error(new Error('Validation failed'));
|
|
1026
|
+
* logger.error('Critical error:', error, { context: 'user-registration' });
|
|
1027
|
+
* ```
|
|
900
1028
|
*/
|
|
901
|
-
|
|
902
|
-
|
|
1029
|
+
error(...args) {
|
|
1030
|
+
if (!this.shouldLog("error")) return;
|
|
1031
|
+
console.log(...this.compile("red", ...args));
|
|
903
1032
|
}
|
|
1033
|
+
// =============================================
|
|
1034
|
+
// Specialized Error Formatting
|
|
1035
|
+
// =============================================
|
|
904
1036
|
/**
|
|
905
|
-
*
|
|
1037
|
+
* Legacy method for A_Error logging (kept for backward compatibility)
|
|
906
1038
|
*
|
|
907
|
-
* @
|
|
908
|
-
* @param
|
|
1039
|
+
* @deprecated Use error() method instead which handles A_Error automatically
|
|
1040
|
+
* @param error - The A_Error instance to log
|
|
909
1041
|
*/
|
|
910
|
-
|
|
911
|
-
this.
|
|
1042
|
+
log_A_Error(error) {
|
|
1043
|
+
const time = this.getTime();
|
|
1044
|
+
const scopePadding = " ".repeat(this.scopeLength + 3);
|
|
1045
|
+
console.log(`\x1B[31m[${this.formattedScope}] |${time}| ERROR ${error.code}
|
|
1046
|
+
${scopePadding}| ${error.message}
|
|
1047
|
+
${scopePadding}| ${error.description}
|
|
1048
|
+
${scopePadding}|-------------------------------
|
|
1049
|
+
${scopePadding}| ${error.stack?.split("\n").map((line, index) => index === 0 ? line : `${scopePadding}| ${line}`).join("\n") || "No stack trace"}
|
|
1050
|
+
${scopePadding}|-------------------------------
|
|
1051
|
+
\x1B[0m` + (error.originalError ? `\x1B[31m${scopePadding}| Wrapped From ${error.originalError.message}
|
|
1052
|
+
${scopePadding}|-------------------------------
|
|
1053
|
+
${scopePadding}| ${error.originalError.stack?.split("\n").map((line, index) => index === 0 ? line : `${scopePadding}| ${line}`).join("\n") || "No stack trace"}
|
|
1054
|
+
${scopePadding}|-------------------------------
|
|
1055
|
+
\x1B[0m` : "") + (error.link ? `\x1B[31m${scopePadding}| Read in docs: ${error.link}
|
|
1056
|
+
${scopePadding}|-------------------------------
|
|
1057
|
+
\x1B[0m` : ""));
|
|
912
1058
|
}
|
|
913
1059
|
/**
|
|
914
|
-
*
|
|
1060
|
+
* Format A_Error instances for inline display within compiled messages
|
|
915
1061
|
*
|
|
916
|
-
*
|
|
1062
|
+
* Provides detailed formatting for A_Error objects including:
|
|
1063
|
+
* - Error code and message
|
|
1064
|
+
* - Description and stack trace
|
|
1065
|
+
* - Original error information (if wrapped)
|
|
1066
|
+
* - Documentation links (if available)
|
|
1067
|
+
*
|
|
1068
|
+
* @param error - The A_Error instance to format
|
|
1069
|
+
* @returns Formatted string ready for display
|
|
917
1070
|
*/
|
|
918
|
-
|
|
919
|
-
this.
|
|
1071
|
+
compile_A_Error(error) {
|
|
1072
|
+
const scopePadding = " ".repeat(this.scopeLength + 3);
|
|
1073
|
+
return `
|
|
1074
|
+
${scopePadding}|-------------------------------
|
|
1075
|
+
${scopePadding}| Error: | ${error.code}
|
|
1076
|
+
${scopePadding}|-------------------------------
|
|
1077
|
+
${scopePadding}|${" ".repeat(10)}| ${error.message}
|
|
1078
|
+
${scopePadding}|${" ".repeat(10)}| ${error.description}
|
|
1079
|
+
${scopePadding}|-------------------------------
|
|
1080
|
+
${scopePadding}| ${error.stack?.split("\n").map((line, index) => index === 0 ? line : `${scopePadding}| ${line}`).join("\n") || "No stack trace"}
|
|
1081
|
+
${scopePadding}|-------------------------------` + (error.originalError ? `${scopePadding}| Wrapped From ${error.originalError.message}
|
|
1082
|
+
${scopePadding}|-------------------------------
|
|
1083
|
+
${scopePadding}| ${error.originalError.stack?.split("\n").map((line, index) => index === 0 ? line : `${scopePadding}| ${line}`).join("\n") || "No stack trace"}
|
|
1084
|
+
${scopePadding}|-------------------------------` : "") + (error.link ? `${scopePadding}| Read in docs: ${error.link}
|
|
1085
|
+
${scopePadding}|-------------------------------` : "");
|
|
920
1086
|
}
|
|
921
1087
|
/**
|
|
922
|
-
*
|
|
1088
|
+
* Format standard Error instances for inline display within compiled messages
|
|
1089
|
+
*
|
|
1090
|
+
* Converts standard JavaScript Error objects into a readable JSON format
|
|
1091
|
+
* with proper indentation and stack trace formatting
|
|
1092
|
+
*
|
|
1093
|
+
* @param error - The Error instance to format
|
|
1094
|
+
* @returns Formatted string ready for display
|
|
923
1095
|
*/
|
|
924
|
-
|
|
925
|
-
this.
|
|
1096
|
+
compile_Error(error) {
|
|
1097
|
+
const scopePadding = " ".repeat(this.scopeLength + 3);
|
|
1098
|
+
return JSON.stringify({
|
|
1099
|
+
name: error.name,
|
|
1100
|
+
message: error.message,
|
|
1101
|
+
stack: error.stack?.split("\n").map((line, index) => index === 0 ? line : `${scopePadding}| ${line}`).join("\n")
|
|
1102
|
+
}, null, 2).replace(/\n/g, `
|
|
1103
|
+
${scopePadding}| `).replace(/\\n/g, "\n");
|
|
926
1104
|
}
|
|
1105
|
+
// =============================================
|
|
1106
|
+
// Utility Methods
|
|
1107
|
+
// =============================================
|
|
927
1108
|
/**
|
|
928
|
-
*
|
|
1109
|
+
* Generate timestamp string for log messages
|
|
1110
|
+
*
|
|
1111
|
+
* Format: MM:SS:mmm (minutes:seconds:milliseconds)
|
|
1112
|
+
* This provides sufficient precision for debugging while remaining readable
|
|
929
1113
|
*
|
|
930
|
-
*
|
|
1114
|
+
* @returns Formatted timestamp string
|
|
931
1115
|
*
|
|
932
|
-
* @
|
|
1116
|
+
* @example
|
|
1117
|
+
* Returns: "15:42:137" for 3:42:15 PM and 137 milliseconds
|
|
933
1118
|
*/
|
|
934
|
-
|
|
935
|
-
const
|
|
936
|
-
|
|
937
|
-
|
|
938
|
-
|
|
939
|
-
return
|
|
1119
|
+
getTime() {
|
|
1120
|
+
const now = /* @__PURE__ */ new Date();
|
|
1121
|
+
const minutes = String(now.getMinutes()).padStart(A_LOGGER_TIME_FORMAT.MINUTES_PAD, "0");
|
|
1122
|
+
const seconds = String(now.getSeconds()).padStart(A_LOGGER_TIME_FORMAT.SECONDS_PAD, "0");
|
|
1123
|
+
const milliseconds = String(now.getMilliseconds()).padStart(A_LOGGER_TIME_FORMAT.MILLISECONDS_PAD, "0");
|
|
1124
|
+
return `${minutes}${A_LOGGER_TIME_FORMAT.SEPARATOR}${seconds}${A_LOGGER_TIME_FORMAT.SEPARATOR}${milliseconds}`;
|
|
940
1125
|
}
|
|
941
1126
|
};
|
|
942
|
-
|
|
943
|
-
|
|
944
|
-
|
|
1127
|
+
exports.A_Logger = __decorateClass([
|
|
1128
|
+
__decorateParam(0, aConcept.A_Inject(aConcept.A_Scope)),
|
|
1129
|
+
__decorateParam(1, aConcept.A_Inject(A_Config))
|
|
1130
|
+
], exports.A_Logger);
|
|
945
1131
|
|
|
946
1132
|
// src/lib/A-Command/A-Command.entity.ts
|
|
1133
|
+
var _a2, _b2, _c2, _d2, _e, _f, _g, _h, _i, _j, _k;
|
|
947
1134
|
var A_Command = class extends aConcept.A_Entity {
|
|
948
1135
|
/**
|
|
949
1136
|
*
|
|
@@ -958,159 +1145,292 @@ var A_Command = class extends aConcept.A_Entity {
|
|
|
958
1145
|
*/
|
|
959
1146
|
constructor(params) {
|
|
960
1147
|
super(params);
|
|
1148
|
+
/** Map of event listeners organized by event name */
|
|
961
1149
|
this._listeners = /* @__PURE__ */ new Map();
|
|
962
1150
|
}
|
|
963
1151
|
// ====================================================================
|
|
964
|
-
// ================== Static
|
|
1152
|
+
// ================== Static Command Information ======================
|
|
965
1153
|
// ====================================================================
|
|
966
1154
|
/**
|
|
967
|
-
*
|
|
1155
|
+
* Static command identifier derived from the class name
|
|
1156
|
+
* Used for command registration and serialization
|
|
968
1157
|
*/
|
|
969
1158
|
static get code() {
|
|
970
1159
|
return super.entity;
|
|
971
1160
|
}
|
|
1161
|
+
// ====================================================================
|
|
1162
|
+
// ================== Public Getter Properties =======================
|
|
1163
|
+
// ====================================================================
|
|
972
1164
|
/**
|
|
973
|
-
*
|
|
1165
|
+
* Total execution duration in milliseconds
|
|
1166
|
+
*
|
|
1167
|
+
* - If completed/failed: Returns total time from start to end
|
|
1168
|
+
* - If currently executing: Returns elapsed time since start
|
|
1169
|
+
* - If not started: Returns undefined
|
|
974
1170
|
*/
|
|
975
1171
|
get duration() {
|
|
976
1172
|
return this._endTime && this._startTime ? this._endTime.getTime() - this._startTime.getTime() : this._startTime ? (/* @__PURE__ */ new Date()).getTime() - this._startTime.getTime() : void 0;
|
|
977
1173
|
}
|
|
978
1174
|
/**
|
|
979
|
-
*
|
|
1175
|
+
* Idle time before execution started in milliseconds
|
|
1176
|
+
*
|
|
1177
|
+
* Time between command creation and execution start.
|
|
1178
|
+
* Useful for monitoring command queue performance.
|
|
1179
|
+
*/
|
|
1180
|
+
get idleTime() {
|
|
1181
|
+
return this._startTime && this._createdAt ? this._startTime.getTime() - this._createdAt.getTime() : void 0;
|
|
1182
|
+
}
|
|
1183
|
+
/**
|
|
1184
|
+
* Command execution scope for dependency injection
|
|
1185
|
+
*
|
|
1186
|
+
* Provides access to components, services, and shared resources
|
|
1187
|
+
* during command execution. Inherits from the scope where the
|
|
1188
|
+
* command was registered.
|
|
980
1189
|
*/
|
|
981
1190
|
get scope() {
|
|
982
1191
|
return this._executionScope;
|
|
983
1192
|
}
|
|
984
1193
|
/**
|
|
985
|
-
* Unique
|
|
986
|
-
* Example: 'user.create', 'task.complete', etc.
|
|
1194
|
+
* Unique command type identifier
|
|
987
1195
|
*
|
|
1196
|
+
* Derived from the class name and used for:
|
|
1197
|
+
* - Command registration and resolution
|
|
1198
|
+
* - Serialization and deserialization
|
|
1199
|
+
* - Logging and debugging
|
|
1200
|
+
*
|
|
1201
|
+
* @example 'create-user-command', 'process-order-command'
|
|
988
1202
|
*/
|
|
989
1203
|
get code() {
|
|
990
1204
|
return this.constructor.code;
|
|
991
1205
|
}
|
|
992
1206
|
/**
|
|
993
|
-
* Current status of the command
|
|
1207
|
+
* Current lifecycle status of the command
|
|
1208
|
+
*
|
|
1209
|
+
* Indicates the current phase in the command execution lifecycle.
|
|
1210
|
+
* Used to track progress and determine available operations.
|
|
994
1211
|
*/
|
|
995
1212
|
get status() {
|
|
996
1213
|
return this._status;
|
|
997
1214
|
}
|
|
998
1215
|
/**
|
|
999
|
-
*
|
|
1216
|
+
* Timestamp when the command was created
|
|
1217
|
+
*
|
|
1218
|
+
* Marks the initial instantiation time, useful for tracking
|
|
1219
|
+
* command age and queue performance metrics.
|
|
1220
|
+
*/
|
|
1221
|
+
get createdAt() {
|
|
1222
|
+
return this._createdAt;
|
|
1223
|
+
}
|
|
1224
|
+
/**
|
|
1225
|
+
* Timestamp when command execution started
|
|
1226
|
+
*
|
|
1227
|
+
* Undefined until execution begins. Used for calculating
|
|
1228
|
+
* execution duration and idle time.
|
|
1000
1229
|
*/
|
|
1001
1230
|
get startedAt() {
|
|
1002
1231
|
return this._startTime;
|
|
1003
1232
|
}
|
|
1004
1233
|
/**
|
|
1005
|
-
*
|
|
1234
|
+
* Timestamp when command execution ended
|
|
1235
|
+
*
|
|
1236
|
+
* Set when command reaches COMPLETED or FAILED status.
|
|
1237
|
+
* Used for calculating total execution duration.
|
|
1006
1238
|
*/
|
|
1007
1239
|
get endedAt() {
|
|
1008
1240
|
return this._endTime;
|
|
1009
1241
|
}
|
|
1010
1242
|
/**
|
|
1011
|
-
* Result
|
|
1243
|
+
* Result data produced by command execution
|
|
1244
|
+
*
|
|
1245
|
+
* Contains the output data from successful command execution.
|
|
1246
|
+
* Undefined until command completes successfully.
|
|
1012
1247
|
*/
|
|
1013
1248
|
get result() {
|
|
1014
1249
|
return this._result;
|
|
1015
1250
|
}
|
|
1016
1251
|
/**
|
|
1017
|
-
*
|
|
1252
|
+
* Array of errors that occurred during execution
|
|
1253
|
+
*
|
|
1254
|
+
* Automatically wraps native errors in A_Error instances
|
|
1255
|
+
* for consistent error handling. Empty array if no errors occurred.
|
|
1018
1256
|
*/
|
|
1019
|
-
get
|
|
1020
|
-
return this.
|
|
1257
|
+
get error() {
|
|
1258
|
+
return this._error;
|
|
1021
1259
|
}
|
|
1022
1260
|
/**
|
|
1023
|
-
|
|
1024
|
-
|
|
1261
|
+
* Command initialization parameters
|
|
1262
|
+
*
|
|
1263
|
+
* Contains the input data used to create and configure the command.
|
|
1264
|
+
* These parameters are immutable during command execution.
|
|
1265
|
+
return new A_Error(err);
|
|
1266
|
+
}
|
|
1267
|
+
});
|
|
1268
|
+
}
|
|
1269
|
+
|
|
1270
|
+
/**
|
|
1271
|
+
* Command initialization parameters
|
|
1272
|
+
*
|
|
1273
|
+
* Contains the input data used to create and configure the command.
|
|
1274
|
+
* These parameters are immutable during command execution.
|
|
1275
|
+
*/
|
|
1025
1276
|
get params() {
|
|
1026
1277
|
return this._params;
|
|
1027
1278
|
}
|
|
1028
1279
|
/**
|
|
1029
|
-
* Indicates if the command has failed
|
|
1280
|
+
* Indicates if the command has been processed (completed or failed)
|
|
1281
|
+
*
|
|
1282
|
+
* Returns true if the command has completed or failed, false otherwise.
|
|
1030
1283
|
*/
|
|
1031
|
-
get
|
|
1032
|
-
return this._status === "FAILED" /* FAILED */;
|
|
1284
|
+
get isProcessed() {
|
|
1285
|
+
return this._status === "COMPLETED" /* COMPLETED */ || this._status === "FAILED" /* FAILED */;
|
|
1033
1286
|
}
|
|
1034
|
-
|
|
1035
|
-
|
|
1036
|
-
|
|
1037
|
-
get isCompleted() {
|
|
1038
|
-
return this._status === "COMPLETED" /* COMPLETED */;
|
|
1287
|
+
async [_k = "onBeforeTransition" /* onBeforeTransition */](transition, logger, ...args) {
|
|
1288
|
+
this.checkScopeInheritance();
|
|
1289
|
+
logger?.debug("yellow", `Command ${this.aseid.toString()} transitioning from ${transition.from} to ${transition.to}`);
|
|
1039
1290
|
}
|
|
1040
|
-
|
|
1041
|
-
// A-Command Lifecycle Methods
|
|
1042
|
-
// --------------------------------------------------------------------------
|
|
1043
|
-
// should create a new Task in DB with basic records
|
|
1044
|
-
async init() {
|
|
1291
|
+
async [_j = "created_initialized" /* CREATED_TO_INITIALIZED */](transition, ...args) {
|
|
1045
1292
|
if (this._status !== "CREATED" /* CREATED */) {
|
|
1046
1293
|
return;
|
|
1047
1294
|
}
|
|
1048
|
-
this.
|
|
1049
|
-
this._startTime = /* @__PURE__ */ new Date();
|
|
1050
|
-
this.emit("onInit" /* onInit */);
|
|
1051
|
-
await this.call("onInit" /* onInit */, this.scope);
|
|
1295
|
+
this._createdAt = /* @__PURE__ */ new Date();
|
|
1052
1296
|
this._status = "INITIALIZED" /* INITIALIZED */;
|
|
1297
|
+
this.emit("onInit" /* onInit */);
|
|
1053
1298
|
}
|
|
1054
|
-
|
|
1055
|
-
|
|
1056
|
-
if (this._status !== "INITIALIZED" /* INITIALIZED */) {
|
|
1299
|
+
async [_i = "initialized_executing" /* INITIALIZED_TO_EXECUTING */](transition, ...args) {
|
|
1300
|
+
if (this._status !== "INITIALIZED" /* INITIALIZED */ && this._status !== "CREATED" /* CREATED */) {
|
|
1057
1301
|
return;
|
|
1058
1302
|
}
|
|
1059
|
-
this.
|
|
1060
|
-
this._status = "
|
|
1061
|
-
this.emit("
|
|
1062
|
-
await this.call("onCompile" /* onCompile */, this.scope);
|
|
1063
|
-
this._status = "COMPILED" /* COMPILED */;
|
|
1303
|
+
this._startTime = /* @__PURE__ */ new Date();
|
|
1304
|
+
this._status = "EXECUTING" /* EXECUTING */;
|
|
1305
|
+
this.emit("onExecute" /* onExecute */);
|
|
1064
1306
|
}
|
|
1065
1307
|
/**
|
|
1066
|
-
*
|
|
1308
|
+
* Handles command completion after successful execution
|
|
1067
1309
|
*
|
|
1068
|
-
*
|
|
1310
|
+
* EXECUTION -> COMPLETED transition
|
|
1069
1311
|
*/
|
|
1070
|
-
async
|
|
1071
|
-
|
|
1072
|
-
|
|
1073
|
-
this.
|
|
1074
|
-
|
|
1075
|
-
|
|
1076
|
-
|
|
1312
|
+
async [_h = "executing_completed" /* EXECUTING_TO_COMPLETED */](transition, ...args) {
|
|
1313
|
+
this._endTime = /* @__PURE__ */ new Date();
|
|
1314
|
+
this._status = "COMPLETED" /* COMPLETED */;
|
|
1315
|
+
this.emit("onComplete" /* onComplete */);
|
|
1316
|
+
}
|
|
1317
|
+
/**
|
|
1318
|
+
* Handles command failure during execution
|
|
1319
|
+
*
|
|
1320
|
+
* EXECUTION -> FAILED transition
|
|
1321
|
+
*/
|
|
1322
|
+
async [_g = "executing_failed" /* EXECUTING_TO_FAILED */](transition, error, ...args) {
|
|
1323
|
+
this._endTime = /* @__PURE__ */ new Date();
|
|
1324
|
+
this._status = "FAILED" /* FAILED */;
|
|
1325
|
+
this.emit("onFail" /* onFail */);
|
|
1326
|
+
}
|
|
1327
|
+
/**
|
|
1328
|
+
* Default behavior for Command Initialization uses StateMachine to transition states
|
|
1329
|
+
*/
|
|
1330
|
+
async [_f = "onInit" /* onInit */](stateMachine, ...args) {
|
|
1331
|
+
await stateMachine.transition("CREATED" /* CREATED */, "INITIALIZED" /* INITIALIZED */);
|
|
1332
|
+
}
|
|
1333
|
+
async [_e = "onBeforeExecute" /* onBeforeExecute */](stateMachine, ...args) {
|
|
1334
|
+
await stateMachine.transition("INITIALIZED" /* INITIALIZED */, "EXECUTING" /* EXECUTING */);
|
|
1335
|
+
}
|
|
1336
|
+
async [_d2 = "onExecute" /* onExecute */](...args) {
|
|
1337
|
+
}
|
|
1338
|
+
/**
|
|
1339
|
+
* By Default on AfterExecute calls the Completion method to mark the command as completed
|
|
1340
|
+
*
|
|
1341
|
+
* [!] This can be overridden to implement custom behavior using A_Feature overrides
|
|
1342
|
+
*/
|
|
1343
|
+
async [_c2 = "onAfterExecute" /* onAfterExecute */](...args) {
|
|
1344
|
+
}
|
|
1345
|
+
async [_b2 = "onComplete" /* onComplete */](stateMachine, ...args) {
|
|
1346
|
+
await stateMachine.transition("EXECUTING" /* EXECUTING */, "COMPLETED" /* COMPLETED */);
|
|
1347
|
+
}
|
|
1348
|
+
async [_a2 = "onFail" /* onFail */](stateMachine, operation, ...args) {
|
|
1349
|
+
await stateMachine.transition("EXECUTING" /* EXECUTING */, "FAILED" /* FAILED */);
|
|
1350
|
+
}
|
|
1351
|
+
// --------------------------------------------------------------------------
|
|
1352
|
+
// A-Command Lifecycle Methods
|
|
1353
|
+
// --------------------------------------------------------------------------
|
|
1354
|
+
/**
|
|
1355
|
+
* Initializes the command before execution.
|
|
1356
|
+
*/
|
|
1357
|
+
async init() {
|
|
1358
|
+
await this.call("onInit" /* onInit */, this.scope);
|
|
1077
1359
|
}
|
|
1078
1360
|
/**
|
|
1079
1361
|
* Executes the command logic.
|
|
1080
1362
|
*/
|
|
1081
1363
|
async execute() {
|
|
1082
|
-
this.
|
|
1364
|
+
if (this.isProcessed) return;
|
|
1083
1365
|
try {
|
|
1084
|
-
|
|
1085
|
-
|
|
1086
|
-
|
|
1087
|
-
await
|
|
1366
|
+
this.checkScopeInheritance();
|
|
1367
|
+
const context = new A_OperationContext("execute-command");
|
|
1368
|
+
this.scope.register(context);
|
|
1369
|
+
await new Promise(async (resolve, reject) => {
|
|
1370
|
+
try {
|
|
1371
|
+
const onBeforeExecuteFeature = new aConcept.A_Feature({
|
|
1372
|
+
name: "onBeforeExecute" /* onBeforeExecute */,
|
|
1373
|
+
component: this,
|
|
1374
|
+
scope: this.scope
|
|
1375
|
+
});
|
|
1376
|
+
const onExecuteFeature = new aConcept.A_Feature({
|
|
1377
|
+
name: "onExecute" /* onExecute */,
|
|
1378
|
+
component: this,
|
|
1379
|
+
scope: this.scope
|
|
1380
|
+
});
|
|
1381
|
+
const onAfterExecuteFeature = new aConcept.A_Feature({
|
|
1382
|
+
name: "onAfterExecute" /* onAfterExecute */,
|
|
1383
|
+
component: this,
|
|
1384
|
+
scope: this.scope
|
|
1385
|
+
});
|
|
1386
|
+
this.on("onComplete" /* onComplete */, () => {
|
|
1387
|
+
onBeforeExecuteFeature.interrupt();
|
|
1388
|
+
onExecuteFeature.interrupt();
|
|
1389
|
+
onAfterExecuteFeature.interrupt();
|
|
1390
|
+
resolve();
|
|
1391
|
+
});
|
|
1392
|
+
await onBeforeExecuteFeature.process(this.scope);
|
|
1393
|
+
await onExecuteFeature.process(this.scope);
|
|
1394
|
+
await onAfterExecuteFeature.process(this.scope);
|
|
1395
|
+
if (this._origin === "invoked") {
|
|
1396
|
+
await this.complete();
|
|
1397
|
+
}
|
|
1398
|
+
resolve();
|
|
1399
|
+
} catch (error) {
|
|
1400
|
+
reject(error);
|
|
1401
|
+
}
|
|
1402
|
+
});
|
|
1088
1403
|
} catch (error) {
|
|
1089
|
-
|
|
1404
|
+
let targetError = error instanceof aConcept.A_Error ? error : new A_CommandError({
|
|
1405
|
+
title: A_CommandError.ExecutionError,
|
|
1406
|
+
description: `An error occurred while executing command "${this.aseid.toString()}".`,
|
|
1407
|
+
originalError: error
|
|
1408
|
+
});
|
|
1409
|
+
await this.fail(targetError);
|
|
1090
1410
|
}
|
|
1091
|
-
this._executionScope.destroy();
|
|
1092
1411
|
}
|
|
1093
1412
|
/**
|
|
1094
1413
|
* Marks the command as completed
|
|
1095
1414
|
*/
|
|
1096
|
-
async complete() {
|
|
1097
|
-
this.
|
|
1415
|
+
async complete(result) {
|
|
1416
|
+
if (this.isProcessed) return;
|
|
1098
1417
|
this._status = "COMPLETED" /* COMPLETED */;
|
|
1099
|
-
this.
|
|
1100
|
-
this._result = this.scope.resolve(A_Memory).toJSON();
|
|
1101
|
-
this.emit("onComplete" /* onComplete */);
|
|
1418
|
+
this._result = result;
|
|
1102
1419
|
await this.call("onComplete" /* onComplete */, this.scope);
|
|
1420
|
+
this.scope.destroy();
|
|
1103
1421
|
}
|
|
1104
1422
|
/**
|
|
1105
1423
|
* Marks the command as failed
|
|
1106
1424
|
*/
|
|
1107
|
-
async fail() {
|
|
1108
|
-
this.
|
|
1425
|
+
async fail(error) {
|
|
1426
|
+
if (this.isProcessed) return;
|
|
1109
1427
|
this._status = "FAILED" /* FAILED */;
|
|
1110
|
-
|
|
1111
|
-
|
|
1112
|
-
|
|
1428
|
+
if (error) {
|
|
1429
|
+
this._error = error;
|
|
1430
|
+
this.scope.register(error);
|
|
1431
|
+
}
|
|
1113
1432
|
await this.call("onFail" /* onFail */, this.scope);
|
|
1433
|
+
this.scope.destroy();
|
|
1114
1434
|
}
|
|
1115
1435
|
// --------------------------------------------------------------------------
|
|
1116
1436
|
// A-Command Event-Emitter methods
|
|
@@ -1142,7 +1462,7 @@ var A_Command = class extends aConcept.A_Entity {
|
|
|
1142
1462
|
* @param event
|
|
1143
1463
|
*/
|
|
1144
1464
|
emit(event) {
|
|
1145
|
-
this._listeners.get(event)?.forEach((listener) => {
|
|
1465
|
+
this._listeners.get(event)?.forEach(async (listener) => {
|
|
1146
1466
|
listener(this);
|
|
1147
1467
|
});
|
|
1148
1468
|
}
|
|
@@ -1158,8 +1478,12 @@ var A_Command = class extends aConcept.A_Entity {
|
|
|
1158
1478
|
*/
|
|
1159
1479
|
fromNew(newEntity) {
|
|
1160
1480
|
super.fromNew(newEntity);
|
|
1161
|
-
this.
|
|
1162
|
-
this._executionScope
|
|
1481
|
+
this._origin = "invoked";
|
|
1482
|
+
this._executionScope = new aConcept.A_Scope({
|
|
1483
|
+
name: `A-Command-Execution-Scope-${this.aseid.toString()}`,
|
|
1484
|
+
components: [A_StateMachine]
|
|
1485
|
+
});
|
|
1486
|
+
this._createdAt = /* @__PURE__ */ new Date();
|
|
1163
1487
|
this._params = newEntity;
|
|
1164
1488
|
this._status = "CREATED" /* CREATED */;
|
|
1165
1489
|
}
|
|
@@ -1172,23 +1496,20 @@ var A_Command = class extends aConcept.A_Entity {
|
|
|
1172
1496
|
*/
|
|
1173
1497
|
fromJSON(serialized) {
|
|
1174
1498
|
super.fromJSON(serialized);
|
|
1175
|
-
this.
|
|
1176
|
-
|
|
1177
|
-
|
|
1499
|
+
this._origin = "serialized";
|
|
1500
|
+
this._executionScope = new aConcept.A_Scope({
|
|
1501
|
+
name: `A-Command-Execution-Scope-${this.aseid.toString()}`,
|
|
1502
|
+
components: [A_StateMachine]
|
|
1503
|
+
});
|
|
1504
|
+
if (serialized.createdAt) this._createdAt = new Date(serialized.createdAt);
|
|
1178
1505
|
if (serialized.startedAt) this._startTime = new Date(serialized.startedAt);
|
|
1179
1506
|
if (serialized.endedAt) this._endTime = new Date(serialized.endedAt);
|
|
1180
|
-
if (serialized.result) {
|
|
1181
|
-
Object.entries(serialized.result).forEach(([key, value]) => {
|
|
1182
|
-
memory.set(key, value);
|
|
1183
|
-
});
|
|
1184
|
-
}
|
|
1185
|
-
if (serialized.errors) {
|
|
1186
|
-
serialized.errors.forEach((err) => {
|
|
1187
|
-
memory.error(new aConcept.A_Error(err));
|
|
1188
|
-
});
|
|
1189
|
-
}
|
|
1190
1507
|
this._params = serialized.params;
|
|
1191
|
-
this._status = serialized.status
|
|
1508
|
+
this._status = serialized.status;
|
|
1509
|
+
if (serialized.error)
|
|
1510
|
+
this._error = new A_CommandError(serialized.error);
|
|
1511
|
+
if (serialized.result)
|
|
1512
|
+
this._result = serialized.result;
|
|
1192
1513
|
}
|
|
1193
1514
|
/**
|
|
1194
1515
|
* Converts the Command instance to a plain object
|
|
@@ -1201,13 +1522,23 @@ var A_Command = class extends aConcept.A_Entity {
|
|
|
1201
1522
|
code: this.code,
|
|
1202
1523
|
status: this._status,
|
|
1203
1524
|
params: this._params,
|
|
1525
|
+
createdAt: this._createdAt.toISOString(),
|
|
1204
1526
|
startedAt: this._startTime ? this._startTime.toISOString() : void 0,
|
|
1205
1527
|
endedAt: this._endTime ? this._endTime.toISOString() : void 0,
|
|
1206
1528
|
duration: this.duration,
|
|
1529
|
+
idleTime: this.idleTime,
|
|
1207
1530
|
result: this.result,
|
|
1208
|
-
|
|
1531
|
+
error: this.error ? this.error.toJSON() : void 0
|
|
1209
1532
|
};
|
|
1210
1533
|
}
|
|
1534
|
+
//============================================================================================
|
|
1535
|
+
// Helpers Methods
|
|
1536
|
+
//============================================================================================
|
|
1537
|
+
/**
|
|
1538
|
+
* Ensures that the command's execution scope inherits from the context scope
|
|
1539
|
+
*
|
|
1540
|
+
* Throws an error if the command is not bound to any context scope
|
|
1541
|
+
*/
|
|
1211
1542
|
checkScopeInheritance() {
|
|
1212
1543
|
let attachedScope;
|
|
1213
1544
|
try {
|
|
@@ -1215,7 +1546,7 @@ var A_Command = class extends aConcept.A_Entity {
|
|
|
1215
1546
|
} catch (error) {
|
|
1216
1547
|
throw new A_CommandError({
|
|
1217
1548
|
title: A_CommandError.CommandScopeBindingError,
|
|
1218
|
-
description: `Command ${this.
|
|
1549
|
+
description: `Command ${this.aseid.toString()} is not bound to any context scope. Ensure the command is properly registered within a context before execution.`,
|
|
1219
1550
|
originalError: error
|
|
1220
1551
|
});
|
|
1221
1552
|
}
|
|
@@ -1224,6 +1555,59 @@ var A_Command = class extends aConcept.A_Entity {
|
|
|
1224
1555
|
}
|
|
1225
1556
|
}
|
|
1226
1557
|
};
|
|
1558
|
+
__decorateClass([
|
|
1559
|
+
aConcept.A_Feature.Extend(),
|
|
1560
|
+
__decorateParam(0, aConcept.A_Inject(A_StateMachineTransition)),
|
|
1561
|
+
__decorateParam(1, aConcept.A_Inject(exports.A_Logger))
|
|
1562
|
+
], A_Command.prototype, _k, 1);
|
|
1563
|
+
__decorateClass([
|
|
1564
|
+
aConcept.A_Feature.Extend(),
|
|
1565
|
+
__decorateParam(0, aConcept.A_Inject(A_StateMachineTransition))
|
|
1566
|
+
], A_Command.prototype, _j, 1);
|
|
1567
|
+
__decorateClass([
|
|
1568
|
+
aConcept.A_Feature.Extend(),
|
|
1569
|
+
__decorateParam(0, aConcept.A_Inject(A_StateMachineTransition))
|
|
1570
|
+
], A_Command.prototype, _i, 1);
|
|
1571
|
+
__decorateClass([
|
|
1572
|
+
aConcept.A_Feature.Extend(),
|
|
1573
|
+
__decorateParam(0, aConcept.A_Inject(A_StateMachineTransition))
|
|
1574
|
+
], A_Command.prototype, _h, 1);
|
|
1575
|
+
__decorateClass([
|
|
1576
|
+
aConcept.A_Feature.Extend(),
|
|
1577
|
+
__decorateParam(0, aConcept.A_Inject(A_StateMachineTransition)),
|
|
1578
|
+
__decorateParam(1, aConcept.A_Inject(aConcept.A_Error))
|
|
1579
|
+
], A_Command.prototype, _g, 1);
|
|
1580
|
+
__decorateClass([
|
|
1581
|
+
aConcept.A_Feature.Extend(),
|
|
1582
|
+
__decorateParam(0, aConcept.A_Inject(A_StateMachine))
|
|
1583
|
+
], A_Command.prototype, _f, 1);
|
|
1584
|
+
__decorateClass([
|
|
1585
|
+
aConcept.A_Feature.Extend({
|
|
1586
|
+
after: /.*/
|
|
1587
|
+
}),
|
|
1588
|
+
__decorateParam(0, aConcept.A_Dependency.Required()),
|
|
1589
|
+
__decorateParam(0, aConcept.A_Inject(A_StateMachine))
|
|
1590
|
+
], A_Command.prototype, _e, 1);
|
|
1591
|
+
__decorateClass([
|
|
1592
|
+
aConcept.A_Feature.Extend()
|
|
1593
|
+
], A_Command.prototype, _d2, 1);
|
|
1594
|
+
__decorateClass([
|
|
1595
|
+
aConcept.A_Feature.Extend()
|
|
1596
|
+
], A_Command.prototype, _c2, 1);
|
|
1597
|
+
__decorateClass([
|
|
1598
|
+
aConcept.A_Feature.Extend({
|
|
1599
|
+
after: /.*/
|
|
1600
|
+
}),
|
|
1601
|
+
__decorateParam(0, aConcept.A_Inject(A_StateMachine))
|
|
1602
|
+
], A_Command.prototype, _b2, 1);
|
|
1603
|
+
__decorateClass([
|
|
1604
|
+
aConcept.A_Feature.Extend({
|
|
1605
|
+
after: /.*/
|
|
1606
|
+
}),
|
|
1607
|
+
__decorateParam(0, aConcept.A_Dependency.Required()),
|
|
1608
|
+
__decorateParam(0, aConcept.A_Inject(A_StateMachine)),
|
|
1609
|
+
__decorateParam(1, aConcept.A_Inject(A_OperationContext))
|
|
1610
|
+
], A_Command.prototype, _a2, 1);
|
|
1227
1611
|
var A_FSPolyfillClass = class {
|
|
1228
1612
|
constructor(logger) {
|
|
1229
1613
|
this.logger = logger;
|
|
@@ -2284,6 +2668,334 @@ var A_Manifest = class extends aConcept.A_Fragment {
|
|
|
2284
2668
|
return new A_ManifestChecker(this, componentCtor, method, true);
|
|
2285
2669
|
}
|
|
2286
2670
|
};
|
|
2671
|
+
var A_MemoryContext = class extends aConcept.A_Fragment {
|
|
2672
|
+
set(param, value) {
|
|
2673
|
+
super.set(param, value);
|
|
2674
|
+
}
|
|
2675
|
+
get(param) {
|
|
2676
|
+
return super.get(param);
|
|
2677
|
+
}
|
|
2678
|
+
};
|
|
2679
|
+
var A_MemoryError = class extends aConcept.A_Error {
|
|
2680
|
+
};
|
|
2681
|
+
A_MemoryError.MemoryInitializationError = "Memory initialization error";
|
|
2682
|
+
A_MemoryError.MemoryDestructionError = "Memory destruction error";
|
|
2683
|
+
A_MemoryError.MemoryGetError = "Memory GET operation failed";
|
|
2684
|
+
A_MemoryError.MemorySetError = "Memory SET operation failed";
|
|
2685
|
+
A_MemoryError.MemoryDropError = "Memory DROP operation failed";
|
|
2686
|
+
A_MemoryError.MemoryClearError = "Memory CLEAR operation failed";
|
|
2687
|
+
A_MemoryError.MemoryHasError = "Memory HAS operation failed";
|
|
2688
|
+
A_MemoryError.MemorySerializeError = "Memory toJSON operation failed";
|
|
2689
|
+
|
|
2690
|
+
// src/lib/A-Memory/A-Memory.component.ts
|
|
2691
|
+
var _a3, _b3, _c3, _d3, _e2, _f2, _g2, _h2, _i2;
|
|
2692
|
+
var A_Memory = class extends aConcept.A_Component {
|
|
2693
|
+
get ready() {
|
|
2694
|
+
if (!this._ready) {
|
|
2695
|
+
this._ready = this.init();
|
|
2696
|
+
}
|
|
2697
|
+
return this._ready;
|
|
2698
|
+
}
|
|
2699
|
+
/**
|
|
2700
|
+
* Handles errors during memory operations
|
|
2701
|
+
*/
|
|
2702
|
+
async [_i2 = "onError" /* onError */](...args) {
|
|
2703
|
+
}
|
|
2704
|
+
/**
|
|
2705
|
+
* Handles memory expiration
|
|
2706
|
+
*/
|
|
2707
|
+
async [_h2 = "onExpire" /* onExpire */](...args) {
|
|
2708
|
+
}
|
|
2709
|
+
/**
|
|
2710
|
+
* Initializes the memory context
|
|
2711
|
+
*/
|
|
2712
|
+
async [_g2 = "onInit" /* onInit */](context, ...args) {
|
|
2713
|
+
if (!context) {
|
|
2714
|
+
context = new A_MemoryContext();
|
|
2715
|
+
aConcept.A_Context.scope(this).register(context);
|
|
2716
|
+
}
|
|
2717
|
+
}
|
|
2718
|
+
async [_f2 = "onDestroy" /* onDestroy */](context, ...args) {
|
|
2719
|
+
context.clear();
|
|
2720
|
+
}
|
|
2721
|
+
/**
|
|
2722
|
+
* Handles the 'get' operation for retrieving a value from memory
|
|
2723
|
+
*/
|
|
2724
|
+
async [_e2 = "onGet" /* onGet */](operation, context, ...args) {
|
|
2725
|
+
operation.succeed(context.get(operation.params.key));
|
|
2726
|
+
}
|
|
2727
|
+
/**
|
|
2728
|
+
* Handles the 'has' operation for checking existence of a key in memory
|
|
2729
|
+
*/
|
|
2730
|
+
async [_d3 = "onHas" /* onHas */](operation, context, ...args) {
|
|
2731
|
+
operation.succeed(context.has(operation.params.key));
|
|
2732
|
+
}
|
|
2733
|
+
/**
|
|
2734
|
+
* Handles the 'set' operation for saving a value in memory
|
|
2735
|
+
*/
|
|
2736
|
+
async [_c3 = "onSet" /* onSet */](operation, context, ...args) {
|
|
2737
|
+
context.set(operation.params.key, operation.params.value);
|
|
2738
|
+
}
|
|
2739
|
+
/**
|
|
2740
|
+
* Handles the 'drop' operation for removing a value from memory
|
|
2741
|
+
*/
|
|
2742
|
+
async [_b3 = "onDrop" /* onDrop */](operation, context, ...args) {
|
|
2743
|
+
context.drop(operation.params.key);
|
|
2744
|
+
}
|
|
2745
|
+
/**
|
|
2746
|
+
* Handles the 'clear' operation for clearing all values from memory
|
|
2747
|
+
*/
|
|
2748
|
+
async [_a3 = "onClear" /* onClear */](operation, context, ...args) {
|
|
2749
|
+
context.clear();
|
|
2750
|
+
}
|
|
2751
|
+
// ======================================================================
|
|
2752
|
+
// =========================A-Memory Methods=============================
|
|
2753
|
+
// ======================================================================
|
|
2754
|
+
/**
|
|
2755
|
+
* Initializes the memory context
|
|
2756
|
+
*/
|
|
2757
|
+
async init() {
|
|
2758
|
+
if (this._ready)
|
|
2759
|
+
return this._ready;
|
|
2760
|
+
const scope = new aConcept.A_Scope({ name: "A-Memory-Init-Scope" }).inherit(aConcept.A_Context.scope(this));
|
|
2761
|
+
try {
|
|
2762
|
+
await this.call("onInit" /* onInit */, scope);
|
|
2763
|
+
} catch (error) {
|
|
2764
|
+
const initError = new A_MemoryError({
|
|
2765
|
+
title: A_MemoryError.MemoryInitializationError,
|
|
2766
|
+
description: "An error occurred during memory initialization",
|
|
2767
|
+
originalError: error
|
|
2768
|
+
});
|
|
2769
|
+
scope.register(initError);
|
|
2770
|
+
await this.call("onError" /* onError */, scope);
|
|
2771
|
+
scope.destroy();
|
|
2772
|
+
throw initError;
|
|
2773
|
+
}
|
|
2774
|
+
}
|
|
2775
|
+
/**
|
|
2776
|
+
* Destroys the memory context
|
|
2777
|
+
*
|
|
2778
|
+
* This method is responsible for cleaning up any resources
|
|
2779
|
+
* used by the memory context and resetting its state.
|
|
2780
|
+
*/
|
|
2781
|
+
async destroy() {
|
|
2782
|
+
const scope = new aConcept.A_Scope({ name: "A-Memory-Destroy-Scope" }).inherit(aConcept.A_Context.scope(this));
|
|
2783
|
+
try {
|
|
2784
|
+
this._ready = void 0;
|
|
2785
|
+
await this.call("onDestroy" /* onDestroy */, scope);
|
|
2786
|
+
} catch (error) {
|
|
2787
|
+
const destroyError = new A_MemoryError({
|
|
2788
|
+
title: A_MemoryError.MemoryDestructionError,
|
|
2789
|
+
description: "An error occurred during memory destruction",
|
|
2790
|
+
originalError: error
|
|
2791
|
+
});
|
|
2792
|
+
scope.register(destroyError);
|
|
2793
|
+
await this.call("onError" /* onError */, scope);
|
|
2794
|
+
scope.destroy();
|
|
2795
|
+
throw destroyError;
|
|
2796
|
+
}
|
|
2797
|
+
}
|
|
2798
|
+
/**
|
|
2799
|
+
* Retrieves a value from the context memory
|
|
2800
|
+
*
|
|
2801
|
+
* @param key - memory key to retrieve
|
|
2802
|
+
* @returns - value associated with the key or undefined if not found
|
|
2803
|
+
*/
|
|
2804
|
+
async get(key) {
|
|
2805
|
+
const operation = new A_OperationContext("get", { key });
|
|
2806
|
+
const scope = new aConcept.A_Scope({
|
|
2807
|
+
name: "A-Memory-Get-Operation-Scope",
|
|
2808
|
+
fragments: [operation]
|
|
2809
|
+
});
|
|
2810
|
+
try {
|
|
2811
|
+
await this.call("onGet" /* onGet */, scope);
|
|
2812
|
+
scope.destroy();
|
|
2813
|
+
return operation.result;
|
|
2814
|
+
} catch (error) {
|
|
2815
|
+
const getError = new A_MemoryError({
|
|
2816
|
+
title: A_MemoryError.MemoryGetError,
|
|
2817
|
+
description: `An error occurred while getting the value for key "${String(key)}"`,
|
|
2818
|
+
originalError: error
|
|
2819
|
+
});
|
|
2820
|
+
scope.register(getError);
|
|
2821
|
+
await this.call("onError" /* onError */, scope);
|
|
2822
|
+
scope.destroy();
|
|
2823
|
+
throw getError;
|
|
2824
|
+
}
|
|
2825
|
+
}
|
|
2826
|
+
/**
|
|
2827
|
+
* Checks if a value exists in the context memory
|
|
2828
|
+
*
|
|
2829
|
+
* @param key - memory key to check
|
|
2830
|
+
* @returns - true if key exists, false otherwise
|
|
2831
|
+
*/
|
|
2832
|
+
async has(key) {
|
|
2833
|
+
const operation = new A_OperationContext("has", { key });
|
|
2834
|
+
const scope = new aConcept.A_Scope({
|
|
2835
|
+
name: "A-Memory-Has-Operation-Scope",
|
|
2836
|
+
fragments: [operation]
|
|
2837
|
+
});
|
|
2838
|
+
try {
|
|
2839
|
+
await this.call("onHas" /* onHas */, scope);
|
|
2840
|
+
scope.destroy();
|
|
2841
|
+
return operation.result;
|
|
2842
|
+
} catch (error) {
|
|
2843
|
+
const getError = new A_MemoryError({
|
|
2844
|
+
title: A_MemoryError.MemoryHasError,
|
|
2845
|
+
description: `An error occurred while checking existence for key "${String(key)}"`,
|
|
2846
|
+
originalError: error
|
|
2847
|
+
});
|
|
2848
|
+
scope.register(getError);
|
|
2849
|
+
await this.call("onError" /* onError */, scope);
|
|
2850
|
+
scope.destroy();
|
|
2851
|
+
throw getError;
|
|
2852
|
+
}
|
|
2853
|
+
}
|
|
2854
|
+
/**
|
|
2855
|
+
* Saves a value in the context memory
|
|
2856
|
+
*
|
|
2857
|
+
* @param key
|
|
2858
|
+
* @param value
|
|
2859
|
+
*/
|
|
2860
|
+
async set(key, value) {
|
|
2861
|
+
const operation = new A_OperationContext("set", { key, value });
|
|
2862
|
+
const scope = new aConcept.A_Scope({
|
|
2863
|
+
name: "A-Memory-Set-Operation-Scope",
|
|
2864
|
+
fragments: [operation]
|
|
2865
|
+
});
|
|
2866
|
+
try {
|
|
2867
|
+
await this.call("onSet" /* onSet */, scope);
|
|
2868
|
+
} catch (error) {
|
|
2869
|
+
const setError = new A_MemoryError({
|
|
2870
|
+
title: A_MemoryError.MemorySetError,
|
|
2871
|
+
description: `An error occurred while setting the value for key "${String(key)}"`,
|
|
2872
|
+
originalError: error
|
|
2873
|
+
});
|
|
2874
|
+
scope.register(setError);
|
|
2875
|
+
await this.call("onError" /* onError */, scope);
|
|
2876
|
+
scope.destroy();
|
|
2877
|
+
throw setError;
|
|
2878
|
+
}
|
|
2879
|
+
}
|
|
2880
|
+
/**
|
|
2881
|
+
* Removes a value from the context memory by key
|
|
2882
|
+
*
|
|
2883
|
+
* @param key
|
|
2884
|
+
*/
|
|
2885
|
+
async drop(key) {
|
|
2886
|
+
const operation = new A_OperationContext("drop", { key });
|
|
2887
|
+
const scope = new aConcept.A_Scope({
|
|
2888
|
+
name: "A-Memory-Drop-Operation-Scope",
|
|
2889
|
+
fragments: [operation]
|
|
2890
|
+
});
|
|
2891
|
+
try {
|
|
2892
|
+
await this.call("onDrop" /* onDrop */, scope);
|
|
2893
|
+
} catch (error) {
|
|
2894
|
+
const dropError = new A_MemoryError({
|
|
2895
|
+
title: A_MemoryError.MemoryDropError,
|
|
2896
|
+
description: `An error occurred while dropping the value for key "${String(key)}"`,
|
|
2897
|
+
originalError: error
|
|
2898
|
+
});
|
|
2899
|
+
scope.register(dropError);
|
|
2900
|
+
await this.call("onError" /* onError */, scope);
|
|
2901
|
+
scope.destroy();
|
|
2902
|
+
throw dropError;
|
|
2903
|
+
}
|
|
2904
|
+
}
|
|
2905
|
+
/**
|
|
2906
|
+
* Clears all stored values in the context memory
|
|
2907
|
+
*/
|
|
2908
|
+
async clear() {
|
|
2909
|
+
const operation = new A_OperationContext("clear");
|
|
2910
|
+
const scope = new aConcept.A_Scope({
|
|
2911
|
+
name: "A-Memory-Clear-Operation-Scope",
|
|
2912
|
+
fragments: [operation]
|
|
2913
|
+
});
|
|
2914
|
+
try {
|
|
2915
|
+
await this.call("onClear" /* onClear */, scope);
|
|
2916
|
+
} catch (error) {
|
|
2917
|
+
const clearError = new A_MemoryError({
|
|
2918
|
+
title: A_MemoryError.MemoryClearError,
|
|
2919
|
+
description: `An error occurred while clearing the memory`,
|
|
2920
|
+
originalError: error
|
|
2921
|
+
});
|
|
2922
|
+
scope.register(clearError);
|
|
2923
|
+
await this.call("onError" /* onError */, scope);
|
|
2924
|
+
scope.destroy();
|
|
2925
|
+
throw clearError;
|
|
2926
|
+
}
|
|
2927
|
+
}
|
|
2928
|
+
/**
|
|
2929
|
+
* Serializes the memory context to a JSON object
|
|
2930
|
+
*
|
|
2931
|
+
* @returns - serialized memory object
|
|
2932
|
+
*/
|
|
2933
|
+
async toJSON() {
|
|
2934
|
+
const operation = new A_OperationContext("serialize");
|
|
2935
|
+
const scope = new aConcept.A_Scope({
|
|
2936
|
+
name: "A-Memory-Serialize-Operation-Scope",
|
|
2937
|
+
fragments: [operation]
|
|
2938
|
+
});
|
|
2939
|
+
try {
|
|
2940
|
+
await this.call("onSerialize" /* onSerialize */, scope);
|
|
2941
|
+
return operation.result;
|
|
2942
|
+
} catch (error) {
|
|
2943
|
+
const serializeError = new A_MemoryError({
|
|
2944
|
+
title: A_MemoryError.MemorySerializeError,
|
|
2945
|
+
description: `An error occurred while serializing the memory`,
|
|
2946
|
+
originalError: error
|
|
2947
|
+
});
|
|
2948
|
+
scope.register(serializeError);
|
|
2949
|
+
await this.call("onError" /* onError */, scope);
|
|
2950
|
+
scope.destroy();
|
|
2951
|
+
throw serializeError;
|
|
2952
|
+
}
|
|
2953
|
+
}
|
|
2954
|
+
};
|
|
2955
|
+
__decorateClass([
|
|
2956
|
+
aConcept.A_Feature.Extend()
|
|
2957
|
+
], A_Memory.prototype, _i2, 1);
|
|
2958
|
+
__decorateClass([
|
|
2959
|
+
aConcept.A_Feature.Extend()
|
|
2960
|
+
], A_Memory.prototype, _h2, 1);
|
|
2961
|
+
__decorateClass([
|
|
2962
|
+
aConcept.A_Feature.Extend(),
|
|
2963
|
+
__decorateParam(0, aConcept.A_Inject(A_MemoryContext))
|
|
2964
|
+
], A_Memory.prototype, _g2, 1);
|
|
2965
|
+
__decorateClass([
|
|
2966
|
+
aConcept.A_Feature.Extend(),
|
|
2967
|
+
__decorateParam(0, aConcept.A_Inject(A_MemoryContext))
|
|
2968
|
+
], A_Memory.prototype, _f2, 1);
|
|
2969
|
+
__decorateClass([
|
|
2970
|
+
aConcept.A_Feature.Extend(),
|
|
2971
|
+
__decorateParam(0, aConcept.A_Dependency.Required()),
|
|
2972
|
+
__decorateParam(0, aConcept.A_Inject(A_OperationContext)),
|
|
2973
|
+
__decorateParam(1, aConcept.A_Inject(A_MemoryContext))
|
|
2974
|
+
], A_Memory.prototype, _e2, 1);
|
|
2975
|
+
__decorateClass([
|
|
2976
|
+
aConcept.A_Feature.Extend(),
|
|
2977
|
+
__decorateParam(0, aConcept.A_Dependency.Required()),
|
|
2978
|
+
__decorateParam(0, aConcept.A_Inject(A_OperationContext)),
|
|
2979
|
+
__decorateParam(1, aConcept.A_Inject(A_MemoryContext))
|
|
2980
|
+
], A_Memory.prototype, _d3, 1);
|
|
2981
|
+
__decorateClass([
|
|
2982
|
+
aConcept.A_Feature.Extend(),
|
|
2983
|
+
__decorateParam(0, aConcept.A_Dependency.Required()),
|
|
2984
|
+
__decorateParam(0, aConcept.A_Inject(A_OperationContext)),
|
|
2985
|
+
__decorateParam(1, aConcept.A_Inject(A_MemoryContext))
|
|
2986
|
+
], A_Memory.prototype, _c3, 1);
|
|
2987
|
+
__decorateClass([
|
|
2988
|
+
aConcept.A_Feature.Extend(),
|
|
2989
|
+
__decorateParam(0, aConcept.A_Dependency.Required()),
|
|
2990
|
+
__decorateParam(0, aConcept.A_Inject(A_OperationContext)),
|
|
2991
|
+
__decorateParam(1, aConcept.A_Inject(A_MemoryContext))
|
|
2992
|
+
], A_Memory.prototype, _b3, 1);
|
|
2993
|
+
__decorateClass([
|
|
2994
|
+
aConcept.A_Feature.Extend(),
|
|
2995
|
+
__decorateParam(0, aConcept.A_Dependency.Required()),
|
|
2996
|
+
__decorateParam(0, aConcept.A_Inject(A_OperationContext)),
|
|
2997
|
+
__decorateParam(1, aConcept.A_Inject(A_MemoryContext))
|
|
2998
|
+
], A_Memory.prototype, _a3, 1);
|
|
2287
2999
|
|
|
2288
3000
|
// src/lib/A-Schedule/A-Deferred.class.ts
|
|
2289
3001
|
var A_Deferred = class {
|
|
@@ -2370,17 +3082,17 @@ var A_Schedule = class extends aConcept.A_Component {
|
|
|
2370
3082
|
}
|
|
2371
3083
|
};
|
|
2372
3084
|
|
|
2373
|
-
exports.A_CONSTANTS__A_Command_Status = A_CONSTANTS__A_Command_Status;
|
|
2374
3085
|
exports.A_CONSTANTS__CONFIG_ENV_VARIABLES = A_CONSTANTS__CONFIG_ENV_VARIABLES;
|
|
2375
3086
|
exports.A_CONSTANTS__CONFIG_ENV_VARIABLES_ARRAY = A_CONSTANTS__CONFIG_ENV_VARIABLES_ARRAY;
|
|
2376
3087
|
exports.A_Channel = A_Channel;
|
|
2377
3088
|
exports.A_ChannelError = A_ChannelError;
|
|
2378
3089
|
exports.A_ChannelFeatures = A_ChannelFeatures;
|
|
2379
|
-
exports.A_ChannelRequest = A_ChannelRequest;
|
|
2380
3090
|
exports.A_ChannelRequestStatuses = A_ChannelRequestStatuses;
|
|
2381
3091
|
exports.A_Command = A_Command;
|
|
2382
3092
|
exports.A_CommandError = A_CommandError;
|
|
2383
3093
|
exports.A_CommandFeatures = A_CommandFeatures;
|
|
3094
|
+
exports.A_CommandTransitions = A_CommandTransitions;
|
|
3095
|
+
exports.A_Command_Status = A_Command_Status;
|
|
2384
3096
|
exports.A_Config = A_Config;
|
|
2385
3097
|
exports.A_ConfigError = A_ConfigError;
|
|
2386
3098
|
exports.A_ConfigLoader = A_ConfigLoader;
|