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