@adaas/a-utils 0.1.18 → 0.1.20
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.cjs +45 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.mts +964 -354
- package/dist/index.d.ts +964 -354
- package/dist/index.mjs +44 -2372
- 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/tsup.config.ts +30 -13
- package/dist/index.js +0 -2398
- package/dist/index.js.map +0 -1
package/dist/index.mjs
CHANGED
|
@@ -1,2373 +1,45 @@
|
|
|
1
|
-
import { A_Inject, A_Scope, A_Feature, A_Concept, A_Container, A_Error, 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
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
this._status = "PENDING" /* PENDING */;
|
|
44
|
-
this._params = params;
|
|
45
|
-
}
|
|
46
|
-
/**
|
|
47
|
-
* Returns the status of the request
|
|
48
|
-
*/
|
|
49
|
-
get status() {
|
|
50
|
-
return this._status;
|
|
51
|
-
}
|
|
52
|
-
/**
|
|
53
|
-
* Returns the parameters of the request
|
|
54
|
-
*/
|
|
55
|
-
get failed() {
|
|
56
|
-
return this._errors.size > 0;
|
|
57
|
-
}
|
|
58
|
-
/**
|
|
59
|
-
* Returns the Params of the Request
|
|
60
|
-
*/
|
|
61
|
-
get params() {
|
|
62
|
-
return this._params;
|
|
63
|
-
}
|
|
64
|
-
/**
|
|
65
|
-
* Returns the Result of the Request
|
|
66
|
-
*/
|
|
67
|
-
get data() {
|
|
68
|
-
return this._result;
|
|
69
|
-
}
|
|
70
|
-
get errors() {
|
|
71
|
-
return this._errors.size > 0 ? this._errors : void 0;
|
|
72
|
-
}
|
|
73
|
-
// ==========================================================
|
|
74
|
-
// ==================== Mutations ===========================
|
|
75
|
-
// ==========================================================
|
|
76
|
-
/**
|
|
77
|
-
* Adds an error to the context
|
|
78
|
-
*
|
|
79
|
-
* @param error
|
|
80
|
-
*/
|
|
81
|
-
fail(error) {
|
|
82
|
-
this._status = "FAILED" /* FAILED */;
|
|
83
|
-
this._errors.add(error);
|
|
84
|
-
}
|
|
85
|
-
/**
|
|
86
|
-
* Sets the result of the request
|
|
87
|
-
*
|
|
88
|
-
* @param result
|
|
89
|
-
*/
|
|
90
|
-
succeed(result) {
|
|
91
|
-
this._status = "SUCCESS" /* SUCCESS */;
|
|
92
|
-
this._result = result;
|
|
93
|
-
}
|
|
94
|
-
/**
|
|
95
|
-
* Serializes the context to a JSON object
|
|
96
|
-
*
|
|
97
|
-
* @returns
|
|
98
|
-
*/
|
|
99
|
-
toJSON() {
|
|
100
|
-
return {
|
|
101
|
-
params: this._params,
|
|
102
|
-
result: this._result,
|
|
103
|
-
status: this._status,
|
|
104
|
-
errors: this.errors ? Array.from(this._errors).map((err) => err.toString()) : void 0
|
|
105
|
-
};
|
|
106
|
-
}
|
|
107
|
-
};
|
|
108
|
-
|
|
109
|
-
// src/lib/A-Channel/A-Channel.error.ts
|
|
110
|
-
var A_ChannelError = class extends A_Error {
|
|
111
|
-
/**
|
|
112
|
-
* Channel Error allows to keep track of errors within a channel if something goes wrong
|
|
113
|
-
*
|
|
114
|
-
*
|
|
115
|
-
* @param originalError
|
|
116
|
-
* @param context
|
|
117
|
-
*/
|
|
118
|
-
constructor(originalError, context) {
|
|
119
|
-
if (A_TypeGuards.isString(context))
|
|
120
|
-
super(originalError, context);
|
|
121
|
-
else
|
|
122
|
-
super(originalError);
|
|
123
|
-
if (context instanceof A_ChannelRequest)
|
|
124
|
-
this._context = context;
|
|
125
|
-
}
|
|
126
|
-
/***
|
|
127
|
-
* Returns Context of the error
|
|
128
|
-
*/
|
|
129
|
-
get context() {
|
|
130
|
-
return this._context;
|
|
131
|
-
}
|
|
132
|
-
};
|
|
133
|
-
// ==========================================================
|
|
134
|
-
// ==================== Error Types =========================
|
|
135
|
-
// ==========================================================
|
|
136
|
-
A_ChannelError.MethodNotImplemented = "A-Channel Method Not Implemented";
|
|
137
|
-
|
|
138
|
-
// src/lib/A-Config/A-Config.constants.ts
|
|
139
|
-
var A_CONSTANTS__CONFIG_ENV_VARIABLES = {};
|
|
140
|
-
var A_CONSTANTS__CONFIG_ENV_VARIABLES_ARRAY = [];
|
|
141
|
-
|
|
142
|
-
// src/lib/A-Config/A-Config.context.ts
|
|
143
|
-
var A_Config = class extends A_Fragment {
|
|
144
|
-
constructor(config) {
|
|
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
|
-
});
|
|
165
|
-
}
|
|
166
|
-
/**
|
|
167
|
-
* This method is used to get the configuration property by name
|
|
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");
|
|
176
|
-
}
|
|
177
|
-
set(property, value) {
|
|
178
|
-
const array = Array.isArray(property) ? property : typeof property === "string" ? [{ property, value }] : Object.keys(property).map((key) => ({
|
|
179
|
-
property: key,
|
|
180
|
-
value: property[key]
|
|
181
|
-
}));
|
|
182
|
-
for (const { property: property2, value: value2 } of array) {
|
|
183
|
-
let targetValue = value2 ? value2 : this.config?.defaults ? this.config.defaults[property2] : void 0;
|
|
184
|
-
this.VARIABLES.set(A_FormatterHelper.toUpperSnakeCase(property2), targetValue);
|
|
185
|
-
}
|
|
186
|
-
}
|
|
187
|
-
};
|
|
188
|
-
|
|
189
|
-
// src/lib/A-Logger/A-Logger.constants.ts
|
|
190
|
-
var A_LOGGER_DEFAULT_SCOPE_LENGTH = 20;
|
|
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
|
-
// =============================================
|
|
239
|
-
/**
|
|
240
|
-
* Initialize A_Logger with dependency injection
|
|
241
|
-
*
|
|
242
|
-
* @param scope - The current scope context for message prefixing
|
|
243
|
-
* @param config - Optional configuration for log level filtering
|
|
244
|
-
*/
|
|
245
|
-
constructor(scope, config) {
|
|
246
|
-
super();
|
|
247
|
-
this.scope = scope;
|
|
248
|
-
this.config = config;
|
|
249
|
-
this.COLORS = A_LOGGER_COLORS;
|
|
250
|
-
this.STANDARD_SCOPE_LENGTH = config?.get("A_LOGGER_DEFAULT_SCOPE_LENGTH") || A_LOGGER_DEFAULT_SCOPE_LENGTH;
|
|
251
|
-
}
|
|
252
|
-
// =============================================
|
|
253
|
-
// Scope and Formatting Utilities
|
|
254
|
-
// =============================================
|
|
255
|
-
/**
|
|
256
|
-
* Get the formatted scope length for consistent message alignment
|
|
257
|
-
* Uses a standard length to ensure all messages align properly regardless of scope name
|
|
258
|
-
*
|
|
259
|
-
* @returns The scope length to use for padding calculations
|
|
260
|
-
*/
|
|
261
|
-
get scopeLength() {
|
|
262
|
-
return Math.max(this.scope.name.length, this.STANDARD_SCOPE_LENGTH);
|
|
263
|
-
}
|
|
264
|
-
/**
|
|
265
|
-
* Get the formatted scope name with proper padding
|
|
266
|
-
* Ensures consistent width for all scope names in log output
|
|
267
|
-
*
|
|
268
|
-
* @returns Padded scope name for consistent formatting
|
|
269
|
-
*/
|
|
270
|
-
get formattedScope() {
|
|
271
|
-
return this.scope.name.padEnd(this.STANDARD_SCOPE_LENGTH);
|
|
272
|
-
}
|
|
273
|
-
// =============================================
|
|
274
|
-
// Message Compilation and Formatting
|
|
275
|
-
// =============================================
|
|
276
|
-
/**
|
|
277
|
-
* Compile log arguments into formatted console output with colors and proper alignment
|
|
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.
|
|
607
|
-
*
|
|
608
|
-
* This method is called automatically when accessing the `initialize` property.
|
|
609
|
-
* You can also call it manually if needed.
|
|
610
|
-
*
|
|
611
|
-
* @returns {Promise<void>} Promise that resolves when connection is established
|
|
612
|
-
*/
|
|
613
|
-
async connect() {
|
|
614
|
-
await this.call("onConnect" /* onConnect */);
|
|
615
|
-
}
|
|
616
|
-
/**
|
|
617
|
-
* Disconnects the channel by calling the onDisconnect lifecycle hook.
|
|
618
|
-
*
|
|
619
|
-
* Use this method to properly cleanup resources when the channel is no longer needed.
|
|
620
|
-
*
|
|
621
|
-
* @returns {Promise<void>} Promise that resolves when cleanup is complete
|
|
622
|
-
*/
|
|
623
|
-
async disconnect() {
|
|
624
|
-
await this.call("onDisconnect" /* onDisconnect */);
|
|
625
|
-
}
|
|
626
|
-
/**
|
|
627
|
-
* Sends a request and waits for a response (Request/Response pattern).
|
|
628
|
-
*
|
|
629
|
-
* This method follows the complete request lifecycle:
|
|
630
|
-
* 1. Ensures channel is initialized
|
|
631
|
-
* 2. Creates request scope and context
|
|
632
|
-
* 3. Calls onBeforeRequest hook
|
|
633
|
-
* 4. Calls onRequest hook (main processing)
|
|
634
|
-
* 5. Calls onAfterRequest hook
|
|
635
|
-
* 6. Returns the response context
|
|
636
|
-
*
|
|
637
|
-
* If any step fails, the onError hook is called and the error is captured
|
|
638
|
-
* in the returned context.
|
|
639
|
-
*
|
|
640
|
-
* @template _ParamsType The type of request parameters
|
|
641
|
-
* @template _ResultType The type of response data
|
|
642
|
-
* @param params The request parameters
|
|
643
|
-
* @returns {Promise<A_ChannelRequest<_ParamsType, _ResultType>>} Request context with response
|
|
644
|
-
*
|
|
645
|
-
* @example
|
|
646
|
-
* ```typescript
|
|
647
|
-
* // Basic usage
|
|
648
|
-
* const response = await channel.request({ action: 'getData', id: 123 });
|
|
649
|
-
*
|
|
650
|
-
* // Typed usage
|
|
651
|
-
* interface UserRequest { userId: string; }
|
|
652
|
-
* interface UserResponse { name: string; email: string; }
|
|
653
|
-
*
|
|
654
|
-
* const userResponse = await channel.request<UserRequest, UserResponse>({
|
|
655
|
-
* userId: 'user-123'
|
|
656
|
-
* });
|
|
657
|
-
*
|
|
658
|
-
* if (!userResponse.failed) {
|
|
659
|
-
* console.log('User:', userResponse.data.name);
|
|
660
|
-
* }
|
|
661
|
-
* ```
|
|
662
|
-
*/
|
|
663
|
-
async request(params) {
|
|
664
|
-
await this.initialize;
|
|
665
|
-
this._processing = true;
|
|
666
|
-
const requestScope = new A_Scope({
|
|
667
|
-
name: `a-channel@scope:request:${A_IdentityHelper.generateTimeId()}`
|
|
668
|
-
});
|
|
669
|
-
const context = new A_ChannelRequest(params);
|
|
670
|
-
try {
|
|
671
|
-
requestScope.inherit(A_Context.scope(this));
|
|
672
|
-
requestScope.register(context);
|
|
673
|
-
await this.call("onBeforeRequest" /* onBeforeRequest */, requestScope);
|
|
674
|
-
await this.call("onRequest" /* onRequest */, requestScope);
|
|
675
|
-
await this.call("onAfterRequest" /* onAfterRequest */, requestScope);
|
|
676
|
-
this._processing = false;
|
|
677
|
-
return context;
|
|
678
|
-
} catch (error) {
|
|
679
|
-
this._processing = false;
|
|
680
|
-
const channelError = new A_ChannelError(error);
|
|
681
|
-
context.fail(channelError);
|
|
682
|
-
await this.call("onError" /* onError */, requestScope);
|
|
683
|
-
return context;
|
|
684
|
-
}
|
|
685
|
-
}
|
|
686
|
-
/**
|
|
687
|
-
* Sends a fire-and-forget message (Send pattern).
|
|
688
|
-
*
|
|
689
|
-
* This method is used for one-way communication where no response is expected:
|
|
690
|
-
* - Event broadcasting
|
|
691
|
-
* - Notification sending
|
|
692
|
-
* - Message queuing
|
|
693
|
-
* - Logging operations
|
|
694
|
-
*
|
|
695
|
-
* The method follows this lifecycle:
|
|
696
|
-
* 1. Ensures channel is initialized
|
|
697
|
-
* 2. Creates send scope and context
|
|
698
|
-
* 3. Calls onSend hook
|
|
699
|
-
* 4. Completes without returning data
|
|
700
|
-
*
|
|
701
|
-
* If the operation fails, the onError hook is called but no error is thrown
|
|
702
|
-
* to the caller (fire-and-forget semantics).
|
|
703
|
-
*
|
|
704
|
-
* @template _ParamsType The type of message parameters
|
|
705
|
-
* @param message The message to send
|
|
706
|
-
* @returns {Promise<void>} Promise that resolves when send is complete
|
|
707
|
-
*
|
|
708
|
-
* @example
|
|
709
|
-
* ```typescript
|
|
710
|
-
* // Send notification
|
|
711
|
-
* await channel.send({
|
|
712
|
-
* type: 'user.login',
|
|
713
|
-
* userId: 'user-123',
|
|
714
|
-
* timestamp: new Date().toISOString()
|
|
715
|
-
* });
|
|
716
|
-
*
|
|
717
|
-
* // Send to message queue
|
|
718
|
-
* await channel.send({
|
|
719
|
-
* queue: 'email-queue',
|
|
720
|
-
* payload: {
|
|
721
|
-
* to: 'user@example.com',
|
|
722
|
-
* subject: 'Welcome!',
|
|
723
|
-
* body: 'Welcome to our service!'
|
|
724
|
-
* }
|
|
725
|
-
* });
|
|
726
|
-
* ```
|
|
727
|
-
*/
|
|
728
|
-
async send(message) {
|
|
729
|
-
await this.initialize;
|
|
730
|
-
this._processing = true;
|
|
731
|
-
const requestScope = new A_Scope({
|
|
732
|
-
name: `a-channel@scope:send:${A_IdentityHelper.generateTimeId()}`
|
|
733
|
-
});
|
|
734
|
-
const context = new A_ChannelRequest(message);
|
|
735
|
-
try {
|
|
736
|
-
requestScope.inherit(A_Context.scope(this));
|
|
737
|
-
requestScope.register(context);
|
|
738
|
-
await this.call("onSend" /* onSend */, requestScope);
|
|
739
|
-
this._processing = false;
|
|
740
|
-
} catch (error) {
|
|
741
|
-
this._processing = false;
|
|
742
|
-
const channelError = new A_ChannelError(error);
|
|
743
|
-
context.fail(channelError);
|
|
744
|
-
await this.call("onError" /* onError */, requestScope);
|
|
745
|
-
}
|
|
746
|
-
}
|
|
747
|
-
/**
|
|
748
|
-
* @deprecated This method is deprecated and will be removed in future versions.
|
|
749
|
-
* Use request() or send() methods instead depending on your communication pattern.
|
|
750
|
-
*
|
|
751
|
-
* For request/response pattern: Use request()
|
|
752
|
-
* For fire-and-forget pattern: Use send()
|
|
753
|
-
* For consumer patterns: Implement custom consumer logic using request() in a loop
|
|
754
|
-
*/
|
|
755
|
-
async consume() {
|
|
756
|
-
await this.initialize;
|
|
757
|
-
this._processing = true;
|
|
758
|
-
const requestScope = new A_Scope({ name: `a-channel@scope:consume:${A_IdentityHelper.generateTimeId()}` });
|
|
759
|
-
const context = new A_ChannelRequest();
|
|
760
|
-
try {
|
|
761
|
-
requestScope.inherit(A_Context.scope(this));
|
|
762
|
-
requestScope.register(context);
|
|
763
|
-
await this.call("onConsume" /* onConsume */, requestScope);
|
|
764
|
-
this._processing = false;
|
|
765
|
-
return context;
|
|
766
|
-
} catch (error) {
|
|
767
|
-
this._processing = false;
|
|
768
|
-
const channelError = new A_ChannelError(error);
|
|
769
|
-
context.fail(channelError);
|
|
770
|
-
await this.call("onError" /* onError */, requestScope);
|
|
771
|
-
return context;
|
|
772
|
-
}
|
|
773
|
-
}
|
|
774
|
-
};
|
|
775
|
-
__decorateClass([
|
|
776
|
-
A_Feature.Extend({
|
|
777
|
-
name: "onConnect" /* onConnect */
|
|
778
|
-
})
|
|
779
|
-
], A_Channel.prototype, "onConnect", 1);
|
|
780
|
-
__decorateClass([
|
|
781
|
-
A_Feature.Extend({
|
|
782
|
-
name: "onDisconnect" /* onDisconnect */
|
|
783
|
-
})
|
|
784
|
-
], A_Channel.prototype, "onDisconnect", 1);
|
|
785
|
-
__decorateClass([
|
|
786
|
-
A_Feature.Extend({
|
|
787
|
-
name: "onBeforeRequest" /* onBeforeRequest */
|
|
788
|
-
})
|
|
789
|
-
], A_Channel.prototype, "onBeforeRequest", 1);
|
|
790
|
-
__decorateClass([
|
|
791
|
-
A_Feature.Extend({
|
|
792
|
-
name: "onRequest" /* onRequest */
|
|
793
|
-
})
|
|
794
|
-
], A_Channel.prototype, "onRequest", 1);
|
|
795
|
-
__decorateClass([
|
|
796
|
-
A_Feature.Extend({
|
|
797
|
-
name: "onAfterRequest" /* onAfterRequest */
|
|
798
|
-
})
|
|
799
|
-
], A_Channel.prototype, "onAfterRequest", 1);
|
|
800
|
-
__decorateClass([
|
|
801
|
-
A_Feature.Extend({
|
|
802
|
-
name: "onError" /* onError */
|
|
803
|
-
})
|
|
804
|
-
], A_Channel.prototype, "onError", 1);
|
|
805
|
-
__decorateClass([
|
|
806
|
-
A_Feature.Extend({
|
|
807
|
-
name: "onSend" /* onSend */
|
|
808
|
-
})
|
|
809
|
-
], A_Channel.prototype, "onSend", 1);
|
|
810
|
-
var HttpChannel = class extends A_Channel {
|
|
811
|
-
};
|
|
812
|
-
var PollyspotChannel = class extends HttpChannel {
|
|
813
|
-
constructor() {
|
|
814
|
-
super();
|
|
815
|
-
this.baseUrl = "https://pollyspot.example.com";
|
|
816
|
-
}
|
|
817
|
-
};
|
|
818
|
-
var GlobalErrorhandler = class extends A_Component {
|
|
819
|
-
async handleError(context, logger, config) {
|
|
820
|
-
}
|
|
821
|
-
async anotherError(context, logger, config) {
|
|
822
|
-
}
|
|
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
|
-
/**
|
|
864
|
-
* Memory object that allows to store intermediate values and errors
|
|
865
|
-
*
|
|
866
|
-
* @param initialValues
|
|
867
|
-
*/
|
|
868
|
-
constructor(initialValues) {
|
|
869
|
-
super();
|
|
870
|
-
this._memory = new Map(Object.entries(initialValues || {}));
|
|
871
|
-
this._errors = /* @__PURE__ */ new Set();
|
|
872
|
-
}
|
|
873
|
-
get Errors() {
|
|
874
|
-
return this._errors.size > 0 ? this._errors : void 0;
|
|
875
|
-
}
|
|
876
|
-
/**
|
|
877
|
-
* Verifies that all required keys are present in the proxy values
|
|
878
|
-
*
|
|
879
|
-
* @param requiredKeys
|
|
880
|
-
* @returns
|
|
881
|
-
*/
|
|
882
|
-
async prerequisites(requiredKeys) {
|
|
883
|
-
return requiredKeys.every((key) => this._memory.has(key));
|
|
884
|
-
}
|
|
885
|
-
/**
|
|
886
|
-
* Adds an error to the context
|
|
887
|
-
*
|
|
888
|
-
* @param error
|
|
889
|
-
*/
|
|
890
|
-
async error(error) {
|
|
891
|
-
this._errors.add(error);
|
|
892
|
-
}
|
|
893
|
-
/**
|
|
894
|
-
* Retrieves a value from the context memory
|
|
895
|
-
*
|
|
896
|
-
* @param key
|
|
897
|
-
* @returns
|
|
898
|
-
*/
|
|
899
|
-
get(key) {
|
|
900
|
-
return this._memory.get(key);
|
|
901
|
-
}
|
|
902
|
-
/**
|
|
903
|
-
* Saves a value in the context memory
|
|
904
|
-
*
|
|
905
|
-
* @param key
|
|
906
|
-
* @param value
|
|
907
|
-
*/
|
|
908
|
-
async set(key, value) {
|
|
909
|
-
this._memory.set(key, value);
|
|
910
|
-
}
|
|
911
|
-
/**
|
|
912
|
-
* Removes a value from the context memory by key
|
|
913
|
-
*
|
|
914
|
-
* @param key
|
|
915
|
-
*/
|
|
916
|
-
async drop(key) {
|
|
917
|
-
this._memory.delete(key);
|
|
918
|
-
}
|
|
919
|
-
/**
|
|
920
|
-
* Clears all stored values in the context memory
|
|
921
|
-
*/
|
|
922
|
-
async clear() {
|
|
923
|
-
this._memory.clear();
|
|
924
|
-
}
|
|
925
|
-
/**
|
|
926
|
-
* Converts all stored values to a plain object
|
|
927
|
-
*
|
|
928
|
-
* [!] By default uses all saved in memory values
|
|
929
|
-
*
|
|
930
|
-
* @returns
|
|
931
|
-
*/
|
|
932
|
-
toJSON() {
|
|
933
|
-
const obj = {};
|
|
934
|
-
this._memory.forEach((value, key) => {
|
|
935
|
-
obj[key] = typeof value === "object" && value !== null && "toJSON" in value && typeof value.toJSON === "function" ? value.toJSON() : value;
|
|
936
|
-
});
|
|
937
|
-
return obj;
|
|
938
|
-
}
|
|
939
|
-
};
|
|
940
|
-
var A_CommandError = class extends A_Error {
|
|
941
|
-
};
|
|
942
|
-
A_CommandError.CommandScopeBindingError = "A-Command Scope Binding Error";
|
|
943
|
-
|
|
944
|
-
// src/lib/A-Command/A-Command.entity.ts
|
|
945
|
-
var A_Command = class extends A_Entity {
|
|
946
|
-
/**
|
|
947
|
-
*
|
|
948
|
-
* A-Command represents an executable command with a specific code and parameters.
|
|
949
|
-
* It can be executed within a given scope and stores execution results and errors.
|
|
950
|
-
*
|
|
951
|
-
*
|
|
952
|
-
* A-Command should be context independent and execution logic should be based on attached components
|
|
953
|
-
*
|
|
954
|
-
* @param code
|
|
955
|
-
* @param params
|
|
956
|
-
*/
|
|
957
|
-
constructor(params) {
|
|
958
|
-
super(params);
|
|
959
|
-
this._listeners = /* @__PURE__ */ new Map();
|
|
960
|
-
}
|
|
961
|
-
// ====================================================================
|
|
962
|
-
// ================== Static A-Command Information ====================
|
|
963
|
-
// ====================================================================
|
|
964
|
-
/**
|
|
965
|
-
* Command Identifier that corresponds to the class name
|
|
966
|
-
*/
|
|
967
|
-
static get code() {
|
|
968
|
-
return super.entity;
|
|
969
|
-
}
|
|
970
|
-
/**
|
|
971
|
-
* Execution Duration in milliseconds
|
|
972
|
-
*/
|
|
973
|
-
get duration() {
|
|
974
|
-
return this._endTime && this._startTime ? this._endTime.getTime() - this._startTime.getTime() : this._startTime ? (/* @__PURE__ */ new Date()).getTime() - this._startTime.getTime() : void 0;
|
|
975
|
-
}
|
|
976
|
-
/**
|
|
977
|
-
* A shared scope between all features of the command during its execution
|
|
978
|
-
*/
|
|
979
|
-
get scope() {
|
|
980
|
-
return this._executionScope;
|
|
981
|
-
}
|
|
982
|
-
/**
|
|
983
|
-
* Unique code identifying the command type
|
|
984
|
-
* Example: 'user.create', 'task.complete', etc.
|
|
985
|
-
*
|
|
986
|
-
*/
|
|
987
|
-
get code() {
|
|
988
|
-
return this.constructor.code;
|
|
989
|
-
}
|
|
990
|
-
/**
|
|
991
|
-
* Current status of the command
|
|
992
|
-
*/
|
|
993
|
-
get status() {
|
|
994
|
-
return this._status;
|
|
995
|
-
}
|
|
996
|
-
/**
|
|
997
|
-
* Start time of the command execution
|
|
998
|
-
*/
|
|
999
|
-
get startedAt() {
|
|
1000
|
-
return this._startTime;
|
|
1001
|
-
}
|
|
1002
|
-
/**
|
|
1003
|
-
* End time of the command execution
|
|
1004
|
-
*/
|
|
1005
|
-
get endedAt() {
|
|
1006
|
-
return this._endTime;
|
|
1007
|
-
}
|
|
1008
|
-
/**
|
|
1009
|
-
* Result of the command execution stored in the context
|
|
1010
|
-
*/
|
|
1011
|
-
get result() {
|
|
1012
|
-
return this._result;
|
|
1013
|
-
}
|
|
1014
|
-
/**
|
|
1015
|
-
* Errors encountered during the command execution stored in the context
|
|
1016
|
-
*/
|
|
1017
|
-
get errors() {
|
|
1018
|
-
return this._errors;
|
|
1019
|
-
}
|
|
1020
|
-
/**
|
|
1021
|
-
* Parameters used to invoke the command
|
|
1022
|
-
*/
|
|
1023
|
-
get params() {
|
|
1024
|
-
return this._params;
|
|
1025
|
-
}
|
|
1026
|
-
/**
|
|
1027
|
-
* Indicates if the command has failed
|
|
1028
|
-
*/
|
|
1029
|
-
get isFailed() {
|
|
1030
|
-
return this._status === "FAILED" /* FAILED */;
|
|
1031
|
-
}
|
|
1032
|
-
/**
|
|
1033
|
-
* Indicates if the command has completed successfully
|
|
1034
|
-
*/
|
|
1035
|
-
get isCompleted() {
|
|
1036
|
-
return this._status === "COMPLETED" /* COMPLETED */;
|
|
1037
|
-
}
|
|
1038
|
-
// --------------------------------------------------------------------------
|
|
1039
|
-
// A-Command Lifecycle Methods
|
|
1040
|
-
// --------------------------------------------------------------------------
|
|
1041
|
-
// should create a new Task in DB with basic records
|
|
1042
|
-
async init() {
|
|
1043
|
-
if (this._status !== "CREATED" /* CREATED */) {
|
|
1044
|
-
return;
|
|
1045
|
-
}
|
|
1046
|
-
this._status = "INITIALIZATION" /* INITIALIZATION */;
|
|
1047
|
-
this._startTime = /* @__PURE__ */ new Date();
|
|
1048
|
-
this.emit("onInit" /* onInit */);
|
|
1049
|
-
await this.call("onInit" /* onInit */, this.scope);
|
|
1050
|
-
this._status = "INITIALIZED" /* INITIALIZED */;
|
|
1051
|
-
}
|
|
1052
|
-
// Should compile everything before execution
|
|
1053
|
-
async compile() {
|
|
1054
|
-
if (this._status !== "INITIALIZED" /* INITIALIZED */) {
|
|
1055
|
-
return;
|
|
1056
|
-
}
|
|
1057
|
-
this.checkScopeInheritance();
|
|
1058
|
-
this._status = "COMPILATION" /* COMPILATION */;
|
|
1059
|
-
this.emit("onCompile" /* onCompile */);
|
|
1060
|
-
await this.call("onCompile" /* onCompile */, this.scope);
|
|
1061
|
-
this._status = "COMPILED" /* COMPILED */;
|
|
1062
|
-
}
|
|
1063
|
-
/**
|
|
1064
|
-
* Processes the command execution
|
|
1065
|
-
*
|
|
1066
|
-
* @returns
|
|
1067
|
-
*/
|
|
1068
|
-
async process() {
|
|
1069
|
-
if (this._status !== "COMPILED" /* COMPILED */)
|
|
1070
|
-
return;
|
|
1071
|
-
this._status = "IN_PROGRESS" /* IN_PROGRESS */;
|
|
1072
|
-
this.checkScopeInheritance();
|
|
1073
|
-
this.emit("onExecute" /* onExecute */);
|
|
1074
|
-
await this.call("onExecute" /* onExecute */, this.scope);
|
|
1075
|
-
}
|
|
1076
|
-
/**
|
|
1077
|
-
* Executes the command logic.
|
|
1078
|
-
*/
|
|
1079
|
-
async execute() {
|
|
1080
|
-
this.checkScopeInheritance();
|
|
1081
|
-
try {
|
|
1082
|
-
await this.init();
|
|
1083
|
-
await this.compile();
|
|
1084
|
-
await this.process();
|
|
1085
|
-
await this.complete();
|
|
1086
|
-
} catch (error) {
|
|
1087
|
-
await this.fail();
|
|
1088
|
-
}
|
|
1089
|
-
this._executionScope.destroy();
|
|
1090
|
-
}
|
|
1091
|
-
/**
|
|
1092
|
-
* Marks the command as completed
|
|
1093
|
-
*/
|
|
1094
|
-
async complete() {
|
|
1095
|
-
this.checkScopeInheritance();
|
|
1096
|
-
this._status = "COMPLETED" /* COMPLETED */;
|
|
1097
|
-
this._endTime = /* @__PURE__ */ new Date();
|
|
1098
|
-
this._result = this.scope.resolve(A_Memory).toJSON();
|
|
1099
|
-
this.emit("onComplete" /* onComplete */);
|
|
1100
|
-
await this.call("onComplete" /* onComplete */, this.scope);
|
|
1101
|
-
}
|
|
1102
|
-
/**
|
|
1103
|
-
* Marks the command as failed
|
|
1104
|
-
*/
|
|
1105
|
-
async fail() {
|
|
1106
|
-
this.checkScopeInheritance();
|
|
1107
|
-
this._status = "FAILED" /* FAILED */;
|
|
1108
|
-
this._endTime = /* @__PURE__ */ new Date();
|
|
1109
|
-
this._errors = this.scope.resolve(A_Memory).Errors;
|
|
1110
|
-
this.emit("onFail" /* onFail */);
|
|
1111
|
-
await this.call("onFail" /* onFail */, this.scope);
|
|
1112
|
-
}
|
|
1113
|
-
// --------------------------------------------------------------------------
|
|
1114
|
-
// A-Command Event-Emitter methods
|
|
1115
|
-
// --------------------------------------------------------------------------
|
|
1116
|
-
/**
|
|
1117
|
-
* Registers an event listener for a specific event
|
|
1118
|
-
*
|
|
1119
|
-
* @param event
|
|
1120
|
-
* @param listener
|
|
1121
|
-
*/
|
|
1122
|
-
on(event, listener) {
|
|
1123
|
-
if (!this._listeners.has(event)) {
|
|
1124
|
-
this._listeners.set(event, /* @__PURE__ */ new Set());
|
|
1125
|
-
}
|
|
1126
|
-
this._listeners.get(event).add(listener);
|
|
1127
|
-
}
|
|
1128
|
-
/**
|
|
1129
|
-
* Removes an event listener for a specific event
|
|
1130
|
-
*
|
|
1131
|
-
* @param event
|
|
1132
|
-
* @param listener
|
|
1133
|
-
*/
|
|
1134
|
-
off(event, listener) {
|
|
1135
|
-
this._listeners.get(event)?.delete(listener);
|
|
1136
|
-
}
|
|
1137
|
-
/**
|
|
1138
|
-
* Emits an event to all registered listeners
|
|
1139
|
-
*
|
|
1140
|
-
* @param event
|
|
1141
|
-
*/
|
|
1142
|
-
emit(event) {
|
|
1143
|
-
this._listeners.get(event)?.forEach((listener) => {
|
|
1144
|
-
listener(this);
|
|
1145
|
-
});
|
|
1146
|
-
}
|
|
1147
|
-
// --------------------------------------------------------------------------
|
|
1148
|
-
// A-Entity Base Class Overrides
|
|
1149
|
-
// --------------------------------------------------------------------------
|
|
1150
|
-
// Serialization / Deserialization
|
|
1151
|
-
// -------------------------------------------------------------------------
|
|
1152
|
-
/**
|
|
1153
|
-
* Allows to create a Command instance from new data
|
|
1154
|
-
*
|
|
1155
|
-
* @param newEntity
|
|
1156
|
-
*/
|
|
1157
|
-
fromNew(newEntity) {
|
|
1158
|
-
super.fromNew(newEntity);
|
|
1159
|
-
this._executionScope = new A_Scope();
|
|
1160
|
-
this._executionScope.register(new A_Memory());
|
|
1161
|
-
this._params = newEntity;
|
|
1162
|
-
this._status = "CREATED" /* CREATED */;
|
|
1163
|
-
}
|
|
1164
|
-
/**
|
|
1165
|
-
* Allows to convert serialized data to Command instance
|
|
1166
|
-
*
|
|
1167
|
-
* [!] By default it omits params as they are not stored in the serialized data
|
|
1168
|
-
*
|
|
1169
|
-
* @param serialized
|
|
1170
|
-
*/
|
|
1171
|
-
fromJSON(serialized) {
|
|
1172
|
-
super.fromJSON(serialized);
|
|
1173
|
-
this._executionScope = new A_Scope();
|
|
1174
|
-
const memory = new A_Memory();
|
|
1175
|
-
this._executionScope.register(memory);
|
|
1176
|
-
if (serialized.startedAt) this._startTime = new Date(serialized.startedAt);
|
|
1177
|
-
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
|
-
this._params = serialized.params;
|
|
1189
|
-
this._status = serialized.status || "CREATED" /* CREATED */;
|
|
1190
|
-
}
|
|
1191
|
-
/**
|
|
1192
|
-
* Converts the Command instance to a plain object
|
|
1193
|
-
*
|
|
1194
|
-
* @returns
|
|
1195
|
-
*/
|
|
1196
|
-
toJSON() {
|
|
1197
|
-
return {
|
|
1198
|
-
...super.toJSON(),
|
|
1199
|
-
code: this.code,
|
|
1200
|
-
status: this._status,
|
|
1201
|
-
params: this._params,
|
|
1202
|
-
startedAt: this._startTime ? this._startTime.toISOString() : void 0,
|
|
1203
|
-
endedAt: this._endTime ? this._endTime.toISOString() : void 0,
|
|
1204
|
-
duration: this.duration,
|
|
1205
|
-
result: this.result,
|
|
1206
|
-
errors: this.errors ? Array.from(this.errors).map((err) => err.toJSON()) : void 0
|
|
1207
|
-
};
|
|
1208
|
-
}
|
|
1209
|
-
checkScopeInheritance() {
|
|
1210
|
-
let attachedScope;
|
|
1211
|
-
try {
|
|
1212
|
-
attachedScope = A_Context.scope(this);
|
|
1213
|
-
} catch (error) {
|
|
1214
|
-
throw new A_CommandError({
|
|
1215
|
-
title: A_CommandError.CommandScopeBindingError,
|
|
1216
|
-
description: `Command ${this.code} is not bound to any context scope. Ensure the command is properly registered within a context before execution.`,
|
|
1217
|
-
originalError: error
|
|
1218
|
-
});
|
|
1219
|
-
}
|
|
1220
|
-
if (!this.scope.isInheritedFrom(A_Context.scope(this))) {
|
|
1221
|
-
this.scope.inherit(A_Context.scope(this));
|
|
1222
|
-
}
|
|
1223
|
-
}
|
|
1224
|
-
};
|
|
1225
|
-
var A_FSPolyfillClass = class {
|
|
1226
|
-
constructor(logger) {
|
|
1227
|
-
this.logger = logger;
|
|
1228
|
-
this._initialized = false;
|
|
1229
|
-
}
|
|
1230
|
-
get isInitialized() {
|
|
1231
|
-
return this._initialized;
|
|
1232
|
-
}
|
|
1233
|
-
async get() {
|
|
1234
|
-
if (!this._initialized) {
|
|
1235
|
-
await this.init();
|
|
1236
|
-
}
|
|
1237
|
-
return this._fs;
|
|
1238
|
-
}
|
|
1239
|
-
async init() {
|
|
1240
|
-
try {
|
|
1241
|
-
if (A_Context.environment === "server") {
|
|
1242
|
-
await this.initServer();
|
|
1243
|
-
} else {
|
|
1244
|
-
this.initBrowser();
|
|
1245
|
-
}
|
|
1246
|
-
this._initialized = true;
|
|
1247
|
-
} catch (error) {
|
|
1248
|
-
this.initBrowser();
|
|
1249
|
-
this._initialized = true;
|
|
1250
|
-
}
|
|
1251
|
-
}
|
|
1252
|
-
async initServer() {
|
|
1253
|
-
this._fs = await import('fs');
|
|
1254
|
-
}
|
|
1255
|
-
initBrowser() {
|
|
1256
|
-
this._fs = {
|
|
1257
|
-
readFileSync: (path, encoding) => {
|
|
1258
|
-
this.logger.warning("fs.readFileSync not available in browser environment");
|
|
1259
|
-
return "";
|
|
1260
|
-
},
|
|
1261
|
-
existsSync: (path) => {
|
|
1262
|
-
this.logger.warning("fs.existsSync not available in browser environment");
|
|
1263
|
-
return false;
|
|
1264
|
-
},
|
|
1265
|
-
createReadStream: (path) => {
|
|
1266
|
-
this.logger.warning("fs.createReadStream not available in browser environment");
|
|
1267
|
-
return null;
|
|
1268
|
-
}
|
|
1269
|
-
};
|
|
1270
|
-
}
|
|
1271
|
-
};
|
|
1272
|
-
var A_CryptoPolyfillClass = class {
|
|
1273
|
-
constructor(logger) {
|
|
1274
|
-
this.logger = logger;
|
|
1275
|
-
this._initialized = false;
|
|
1276
|
-
}
|
|
1277
|
-
get isInitialized() {
|
|
1278
|
-
return this._initialized;
|
|
1279
|
-
}
|
|
1280
|
-
async get(fsPolyfill) {
|
|
1281
|
-
if (!this._initialized) {
|
|
1282
|
-
this._fsPolyfill = fsPolyfill;
|
|
1283
|
-
await this.init();
|
|
1284
|
-
}
|
|
1285
|
-
return this._crypto;
|
|
1286
|
-
}
|
|
1287
|
-
async init() {
|
|
1288
|
-
try {
|
|
1289
|
-
if (A_Context.environment === "server") {
|
|
1290
|
-
await this.initServer();
|
|
1291
|
-
} else {
|
|
1292
|
-
this.initBrowser();
|
|
1293
|
-
}
|
|
1294
|
-
this._initialized = true;
|
|
1295
|
-
} catch (error) {
|
|
1296
|
-
this.initBrowser();
|
|
1297
|
-
this._initialized = true;
|
|
1298
|
-
}
|
|
1299
|
-
}
|
|
1300
|
-
async initServer() {
|
|
1301
|
-
const crypto2 = await import('crypto');
|
|
1302
|
-
this._crypto = {
|
|
1303
|
-
createTextHash: (text, algorithm = "sha384") => Promise.resolve(
|
|
1304
|
-
`${algorithm}-${crypto2.createHash(algorithm).update(text).digest("base64")}`
|
|
1305
|
-
),
|
|
1306
|
-
createFileHash: (filePath, algorithm = "sha384") => new Promise(async (resolve, reject) => {
|
|
1307
|
-
try {
|
|
1308
|
-
if (!this._fsPolyfill) {
|
|
1309
|
-
throw new Error("FS polyfill is required for file hashing");
|
|
1310
|
-
}
|
|
1311
|
-
const hash = crypto2.createHash(algorithm);
|
|
1312
|
-
const fileStream = this._fsPolyfill.createReadStream(filePath);
|
|
1313
|
-
fileStream.on("data", (data) => hash.update(data));
|
|
1314
|
-
fileStream.on("end", () => resolve(`${algorithm}-${hash.digest("base64")}`));
|
|
1315
|
-
fileStream.on("error", (err) => reject(err));
|
|
1316
|
-
} catch (error) {
|
|
1317
|
-
reject(error);
|
|
1318
|
-
}
|
|
1319
|
-
})
|
|
1320
|
-
};
|
|
1321
|
-
}
|
|
1322
|
-
initBrowser() {
|
|
1323
|
-
this._crypto = {
|
|
1324
|
-
createFileHash: () => {
|
|
1325
|
-
this.logger.warning("File hash not available in browser environment");
|
|
1326
|
-
return Promise.resolve("");
|
|
1327
|
-
},
|
|
1328
|
-
createTextHash: (text, algorithm = "SHA-384") => new Promise(async (resolve, reject) => {
|
|
1329
|
-
try {
|
|
1330
|
-
if (!crypto.subtle) {
|
|
1331
|
-
throw new Error("SubtleCrypto not available");
|
|
1332
|
-
}
|
|
1333
|
-
const encoder = new TextEncoder();
|
|
1334
|
-
const data = encoder.encode(text);
|
|
1335
|
-
const hashBuffer = await crypto.subtle.digest(algorithm, data);
|
|
1336
|
-
const hashArray = Array.from(new Uint8Array(hashBuffer));
|
|
1337
|
-
const hashBase64 = btoa(String.fromCharCode(...hashArray));
|
|
1338
|
-
resolve(`${algorithm}-${hashBase64}`);
|
|
1339
|
-
} catch (error) {
|
|
1340
|
-
reject(error);
|
|
1341
|
-
}
|
|
1342
|
-
})
|
|
1343
|
-
};
|
|
1344
|
-
}
|
|
1345
|
-
};
|
|
1346
|
-
var A_HttpPolyfillClass = class {
|
|
1347
|
-
constructor(logger) {
|
|
1348
|
-
this.logger = logger;
|
|
1349
|
-
this._initialized = false;
|
|
1350
|
-
}
|
|
1351
|
-
get isInitialized() {
|
|
1352
|
-
return this._initialized;
|
|
1353
|
-
}
|
|
1354
|
-
async get() {
|
|
1355
|
-
if (!this._initialized) {
|
|
1356
|
-
await this.init();
|
|
1357
|
-
}
|
|
1358
|
-
return this._http;
|
|
1359
|
-
}
|
|
1360
|
-
async init() {
|
|
1361
|
-
try {
|
|
1362
|
-
if (A_Context.environment === "server") {
|
|
1363
|
-
await this.initServer();
|
|
1364
|
-
} else {
|
|
1365
|
-
this.initBrowser();
|
|
1366
|
-
}
|
|
1367
|
-
this._initialized = true;
|
|
1368
|
-
} catch (error) {
|
|
1369
|
-
this.initBrowser();
|
|
1370
|
-
this._initialized = true;
|
|
1371
|
-
}
|
|
1372
|
-
}
|
|
1373
|
-
async initServer() {
|
|
1374
|
-
const httpModule = await import('http');
|
|
1375
|
-
this._http = {
|
|
1376
|
-
request: httpModule.request,
|
|
1377
|
-
get: httpModule.get,
|
|
1378
|
-
createServer: httpModule.createServer
|
|
1379
|
-
};
|
|
1380
|
-
}
|
|
1381
|
-
initBrowser() {
|
|
1382
|
-
this._http = {
|
|
1383
|
-
request: (options, callback) => {
|
|
1384
|
-
this.logger.warning("http.request not available in browser/test environment, use fetch instead");
|
|
1385
|
-
return this.createMockRequest(options, callback, false);
|
|
1386
|
-
},
|
|
1387
|
-
get: (url, callback) => {
|
|
1388
|
-
this.logger.warning("http.get not available in browser/test environment, use fetch instead");
|
|
1389
|
-
return this.createMockRequest(typeof url === "string" ? { hostname: url } : url, callback, false);
|
|
1390
|
-
},
|
|
1391
|
-
createServer: () => {
|
|
1392
|
-
this.logger.error("http.createServer not available in browser/test environment");
|
|
1393
|
-
return null;
|
|
1394
|
-
}
|
|
1395
|
-
};
|
|
1396
|
-
}
|
|
1397
|
-
createMockRequest(options, callback, isHttps = false) {
|
|
1398
|
-
const request = {
|
|
1399
|
-
end: () => {
|
|
1400
|
-
if (callback) {
|
|
1401
|
-
const mockResponse = {
|
|
1402
|
-
statusCode: 200,
|
|
1403
|
-
headers: {},
|
|
1404
|
-
on: (event, handler) => {
|
|
1405
|
-
if (event === "data") {
|
|
1406
|
-
setTimeout(() => handler("mock data"), 0);
|
|
1407
|
-
} else if (event === "end") {
|
|
1408
|
-
setTimeout(() => handler(), 0);
|
|
1409
|
-
}
|
|
1410
|
-
},
|
|
1411
|
-
pipe: (dest) => {
|
|
1412
|
-
if (dest.write) dest.write("mock data");
|
|
1413
|
-
if (dest.end) dest.end();
|
|
1414
|
-
}
|
|
1415
|
-
};
|
|
1416
|
-
setTimeout(() => callback(mockResponse), 0);
|
|
1417
|
-
}
|
|
1418
|
-
},
|
|
1419
|
-
write: (data) => {
|
|
1420
|
-
},
|
|
1421
|
-
on: (event, handler) => {
|
|
1422
|
-
}
|
|
1423
|
-
};
|
|
1424
|
-
return request;
|
|
1425
|
-
}
|
|
1426
|
-
};
|
|
1427
|
-
var A_HttpsPolyfillClass = class {
|
|
1428
|
-
constructor(logger) {
|
|
1429
|
-
this.logger = logger;
|
|
1430
|
-
this._initialized = false;
|
|
1431
|
-
}
|
|
1432
|
-
get isInitialized() {
|
|
1433
|
-
return this._initialized;
|
|
1434
|
-
}
|
|
1435
|
-
async get() {
|
|
1436
|
-
if (!this._initialized) {
|
|
1437
|
-
await this.init();
|
|
1438
|
-
}
|
|
1439
|
-
return this._https;
|
|
1440
|
-
}
|
|
1441
|
-
async init() {
|
|
1442
|
-
try {
|
|
1443
|
-
if (A_Context.environment === "server") {
|
|
1444
|
-
await this.initServer();
|
|
1445
|
-
} else {
|
|
1446
|
-
this.initBrowser();
|
|
1447
|
-
}
|
|
1448
|
-
this._initialized = true;
|
|
1449
|
-
} catch (error) {
|
|
1450
|
-
this.initBrowser();
|
|
1451
|
-
this._initialized = true;
|
|
1452
|
-
}
|
|
1453
|
-
}
|
|
1454
|
-
async initServer() {
|
|
1455
|
-
const httpsModule = await import('https');
|
|
1456
|
-
this._https = {
|
|
1457
|
-
request: httpsModule.request,
|
|
1458
|
-
get: httpsModule.get,
|
|
1459
|
-
createServer: httpsModule.createServer
|
|
1460
|
-
};
|
|
1461
|
-
}
|
|
1462
|
-
initBrowser() {
|
|
1463
|
-
this._https = {
|
|
1464
|
-
request: (options, callback) => {
|
|
1465
|
-
this.logger.warning("https.request not available in browser/test environment, use fetch instead");
|
|
1466
|
-
return this.createMockRequest(options, callback, true);
|
|
1467
|
-
},
|
|
1468
|
-
get: (url, callback) => {
|
|
1469
|
-
this.logger.warning("https.get not available in browser/test environment, use fetch instead");
|
|
1470
|
-
return this.createMockRequest(typeof url === "string" ? { hostname: url } : url, callback, true);
|
|
1471
|
-
},
|
|
1472
|
-
createServer: () => {
|
|
1473
|
-
this.logger.error("https.createServer not available in browser/test environment");
|
|
1474
|
-
return null;
|
|
1475
|
-
}
|
|
1476
|
-
};
|
|
1477
|
-
}
|
|
1478
|
-
createMockRequest(options, callback, isHttps = true) {
|
|
1479
|
-
const request = {
|
|
1480
|
-
end: () => {
|
|
1481
|
-
if (callback) {
|
|
1482
|
-
const mockResponse = {
|
|
1483
|
-
statusCode: 200,
|
|
1484
|
-
headers: {},
|
|
1485
|
-
on: (event, handler) => {
|
|
1486
|
-
if (event === "data") {
|
|
1487
|
-
setTimeout(() => handler("mock data"), 0);
|
|
1488
|
-
} else if (event === "end") {
|
|
1489
|
-
setTimeout(() => handler(), 0);
|
|
1490
|
-
}
|
|
1491
|
-
},
|
|
1492
|
-
pipe: (dest) => {
|
|
1493
|
-
if (dest.write) dest.write("mock data");
|
|
1494
|
-
if (dest.end) dest.end();
|
|
1495
|
-
}
|
|
1496
|
-
};
|
|
1497
|
-
setTimeout(() => callback(mockResponse), 0);
|
|
1498
|
-
}
|
|
1499
|
-
},
|
|
1500
|
-
write: (data) => {
|
|
1501
|
-
},
|
|
1502
|
-
on: (event, handler) => {
|
|
1503
|
-
}
|
|
1504
|
-
};
|
|
1505
|
-
return request;
|
|
1506
|
-
}
|
|
1507
|
-
};
|
|
1508
|
-
var A_PathPolyfillClass = class {
|
|
1509
|
-
constructor(logger) {
|
|
1510
|
-
this.logger = logger;
|
|
1511
|
-
this._initialized = false;
|
|
1512
|
-
}
|
|
1513
|
-
get isInitialized() {
|
|
1514
|
-
return this._initialized;
|
|
1515
|
-
}
|
|
1516
|
-
async get() {
|
|
1517
|
-
if (!this._initialized) {
|
|
1518
|
-
await this.init();
|
|
1519
|
-
}
|
|
1520
|
-
return this._path;
|
|
1521
|
-
}
|
|
1522
|
-
async init() {
|
|
1523
|
-
try {
|
|
1524
|
-
if (A_Context.environment === "server") {
|
|
1525
|
-
await this.initServer();
|
|
1526
|
-
} else {
|
|
1527
|
-
this.initBrowser();
|
|
1528
|
-
}
|
|
1529
|
-
this._initialized = true;
|
|
1530
|
-
} catch (error) {
|
|
1531
|
-
this.initBrowser();
|
|
1532
|
-
this._initialized = true;
|
|
1533
|
-
}
|
|
1534
|
-
}
|
|
1535
|
-
async initServer() {
|
|
1536
|
-
this._path = await import('path');
|
|
1537
|
-
}
|
|
1538
|
-
initBrowser() {
|
|
1539
|
-
this._path = {
|
|
1540
|
-
join: (...paths) => {
|
|
1541
|
-
return paths.join("/").replace(/\/+/g, "/");
|
|
1542
|
-
},
|
|
1543
|
-
resolve: (...paths) => {
|
|
1544
|
-
let resolvedPath = "";
|
|
1545
|
-
for (const path of paths) {
|
|
1546
|
-
if (path.startsWith("/")) {
|
|
1547
|
-
resolvedPath = path;
|
|
1548
|
-
} else {
|
|
1549
|
-
resolvedPath = this._path.join(resolvedPath, path);
|
|
1550
|
-
}
|
|
1551
|
-
}
|
|
1552
|
-
return resolvedPath || "/";
|
|
1553
|
-
},
|
|
1554
|
-
dirname: (path) => {
|
|
1555
|
-
const parts = path.split("/");
|
|
1556
|
-
return parts.slice(0, -1).join("/") || "/";
|
|
1557
|
-
},
|
|
1558
|
-
basename: (path, ext) => {
|
|
1559
|
-
const base = path.split("/").pop() || "";
|
|
1560
|
-
return ext && base.endsWith(ext) ? base.slice(0, -ext.length) : base;
|
|
1561
|
-
},
|
|
1562
|
-
extname: (path) => {
|
|
1563
|
-
const parts = path.split(".");
|
|
1564
|
-
return parts.length > 1 ? "." + parts.pop() : "";
|
|
1565
|
-
},
|
|
1566
|
-
relative: (from, to) => {
|
|
1567
|
-
return to.replace(from, "").replace(/^\//, "");
|
|
1568
|
-
},
|
|
1569
|
-
normalize: (path) => {
|
|
1570
|
-
return path.replace(/\/+/g, "/").replace(/\/$/, "") || "/";
|
|
1571
|
-
},
|
|
1572
|
-
isAbsolute: (path) => {
|
|
1573
|
-
return path.startsWith("/") || /^[a-zA-Z]:/.test(path);
|
|
1574
|
-
},
|
|
1575
|
-
parse: (path) => {
|
|
1576
|
-
const ext = this._path.extname(path);
|
|
1577
|
-
const base = this._path.basename(path);
|
|
1578
|
-
const name = this._path.basename(path, ext);
|
|
1579
|
-
const dir = this._path.dirname(path);
|
|
1580
|
-
return { root: "/", dir, base, ext, name };
|
|
1581
|
-
},
|
|
1582
|
-
format: (pathObject) => {
|
|
1583
|
-
return this._path.join(pathObject.dir || "", pathObject.base || "");
|
|
1584
|
-
},
|
|
1585
|
-
sep: "/",
|
|
1586
|
-
delimiter: ":"
|
|
1587
|
-
};
|
|
1588
|
-
}
|
|
1589
|
-
};
|
|
1590
|
-
var A_UrlPolyfillClass = class {
|
|
1591
|
-
constructor(logger) {
|
|
1592
|
-
this.logger = logger;
|
|
1593
|
-
this._initialized = false;
|
|
1594
|
-
}
|
|
1595
|
-
get isInitialized() {
|
|
1596
|
-
return this._initialized;
|
|
1597
|
-
}
|
|
1598
|
-
async get() {
|
|
1599
|
-
if (!this._initialized) {
|
|
1600
|
-
await this.init();
|
|
1601
|
-
}
|
|
1602
|
-
return this._url;
|
|
1603
|
-
}
|
|
1604
|
-
async init() {
|
|
1605
|
-
try {
|
|
1606
|
-
if (A_Context.environment === "server") {
|
|
1607
|
-
await this.initServer();
|
|
1608
|
-
} else {
|
|
1609
|
-
this.initBrowser();
|
|
1610
|
-
}
|
|
1611
|
-
this._initialized = true;
|
|
1612
|
-
} catch (error) {
|
|
1613
|
-
this.initBrowser();
|
|
1614
|
-
this._initialized = true;
|
|
1615
|
-
}
|
|
1616
|
-
}
|
|
1617
|
-
async initServer() {
|
|
1618
|
-
const urlModule = await import('url');
|
|
1619
|
-
this._url = {
|
|
1620
|
-
parse: urlModule.parse,
|
|
1621
|
-
format: urlModule.format,
|
|
1622
|
-
resolve: urlModule.resolve,
|
|
1623
|
-
URL: urlModule.URL || globalThis.URL,
|
|
1624
|
-
URLSearchParams: urlModule.URLSearchParams || globalThis.URLSearchParams
|
|
1625
|
-
};
|
|
1626
|
-
}
|
|
1627
|
-
initBrowser() {
|
|
1628
|
-
this._url = {
|
|
1629
|
-
parse: (urlString) => {
|
|
1630
|
-
try {
|
|
1631
|
-
const url = new URL(urlString);
|
|
1632
|
-
return {
|
|
1633
|
-
protocol: url.protocol,
|
|
1634
|
-
hostname: url.hostname,
|
|
1635
|
-
port: url.port,
|
|
1636
|
-
pathname: url.pathname,
|
|
1637
|
-
search: url.search,
|
|
1638
|
-
hash: url.hash,
|
|
1639
|
-
host: url.host,
|
|
1640
|
-
href: url.href
|
|
1641
|
-
};
|
|
1642
|
-
} catch {
|
|
1643
|
-
return {};
|
|
1644
|
-
}
|
|
1645
|
-
},
|
|
1646
|
-
format: (urlObject) => {
|
|
1647
|
-
try {
|
|
1648
|
-
return new URL("", urlObject.href || `${urlObject.protocol}//${urlObject.host}${urlObject.pathname}${urlObject.search}${urlObject.hash}`).href;
|
|
1649
|
-
} catch {
|
|
1650
|
-
return "";
|
|
1651
|
-
}
|
|
1652
|
-
},
|
|
1653
|
-
resolve: (from, to) => {
|
|
1654
|
-
try {
|
|
1655
|
-
return new URL(to, from).href;
|
|
1656
|
-
} catch {
|
|
1657
|
-
return to;
|
|
1658
|
-
}
|
|
1659
|
-
},
|
|
1660
|
-
URL: globalThis.URL,
|
|
1661
|
-
URLSearchParams: globalThis.URLSearchParams
|
|
1662
|
-
};
|
|
1663
|
-
}
|
|
1664
|
-
};
|
|
1665
|
-
var A_BufferPolyfillClass = class {
|
|
1666
|
-
constructor(logger) {
|
|
1667
|
-
this.logger = logger;
|
|
1668
|
-
this._initialized = false;
|
|
1669
|
-
}
|
|
1670
|
-
get isInitialized() {
|
|
1671
|
-
return this._initialized;
|
|
1672
|
-
}
|
|
1673
|
-
async get() {
|
|
1674
|
-
if (!this._initialized) {
|
|
1675
|
-
await this.init();
|
|
1676
|
-
}
|
|
1677
|
-
return this._buffer;
|
|
1678
|
-
}
|
|
1679
|
-
async init() {
|
|
1680
|
-
try {
|
|
1681
|
-
if (A_Context.environment === "server") {
|
|
1682
|
-
await this.initServer();
|
|
1683
|
-
} else {
|
|
1684
|
-
this.initBrowser();
|
|
1685
|
-
}
|
|
1686
|
-
this._initialized = true;
|
|
1687
|
-
} catch (error) {
|
|
1688
|
-
this.initBrowser();
|
|
1689
|
-
this._initialized = true;
|
|
1690
|
-
}
|
|
1691
|
-
}
|
|
1692
|
-
async initServer() {
|
|
1693
|
-
const bufferModule = await import('buffer');
|
|
1694
|
-
this._buffer = {
|
|
1695
|
-
from: bufferModule.Buffer.from,
|
|
1696
|
-
alloc: bufferModule.Buffer.alloc,
|
|
1697
|
-
allocUnsafe: bufferModule.Buffer.allocUnsafe,
|
|
1698
|
-
isBuffer: bufferModule.Buffer.isBuffer,
|
|
1699
|
-
concat: bufferModule.Buffer.concat
|
|
1700
|
-
};
|
|
1701
|
-
}
|
|
1702
|
-
initBrowser() {
|
|
1703
|
-
this._buffer = {
|
|
1704
|
-
from: (data, encoding) => {
|
|
1705
|
-
if (typeof data === "string") {
|
|
1706
|
-
return new TextEncoder().encode(data);
|
|
1707
|
-
}
|
|
1708
|
-
return new Uint8Array(data);
|
|
1709
|
-
},
|
|
1710
|
-
alloc: (size, fill) => {
|
|
1711
|
-
const buffer = new Uint8Array(size);
|
|
1712
|
-
if (fill !== void 0) {
|
|
1713
|
-
buffer.fill(fill);
|
|
1714
|
-
}
|
|
1715
|
-
return buffer;
|
|
1716
|
-
},
|
|
1717
|
-
allocUnsafe: (size) => {
|
|
1718
|
-
return new Uint8Array(size);
|
|
1719
|
-
},
|
|
1720
|
-
isBuffer: (obj) => {
|
|
1721
|
-
return obj instanceof Uint8Array || obj instanceof ArrayBuffer;
|
|
1722
|
-
},
|
|
1723
|
-
concat: (list, totalLength) => {
|
|
1724
|
-
const length = totalLength || list.reduce((sum, buf) => sum + buf.length, 0);
|
|
1725
|
-
const result = new Uint8Array(length);
|
|
1726
|
-
let offset = 0;
|
|
1727
|
-
for (const buf of list) {
|
|
1728
|
-
result.set(buf, offset);
|
|
1729
|
-
offset += buf.length;
|
|
1730
|
-
}
|
|
1731
|
-
return result;
|
|
1732
|
-
}
|
|
1733
|
-
};
|
|
1734
|
-
}
|
|
1735
|
-
};
|
|
1736
|
-
var A_ProcessPolyfillClass = class {
|
|
1737
|
-
constructor(logger) {
|
|
1738
|
-
this.logger = logger;
|
|
1739
|
-
this._initialized = false;
|
|
1740
|
-
}
|
|
1741
|
-
get isInitialized() {
|
|
1742
|
-
return this._initialized;
|
|
1743
|
-
}
|
|
1744
|
-
async get() {
|
|
1745
|
-
if (!this._initialized) {
|
|
1746
|
-
await this.init();
|
|
1747
|
-
}
|
|
1748
|
-
return this._process;
|
|
1749
|
-
}
|
|
1750
|
-
async init() {
|
|
1751
|
-
try {
|
|
1752
|
-
if (A_Context.environment === "server") {
|
|
1753
|
-
this.initServer();
|
|
1754
|
-
} else {
|
|
1755
|
-
this.initBrowser();
|
|
1756
|
-
}
|
|
1757
|
-
this._initialized = true;
|
|
1758
|
-
} catch (error) {
|
|
1759
|
-
this.initBrowser();
|
|
1760
|
-
this._initialized = true;
|
|
1761
|
-
}
|
|
1762
|
-
}
|
|
1763
|
-
initServer() {
|
|
1764
|
-
this._process = {
|
|
1765
|
-
env: process.env,
|
|
1766
|
-
argv: process.argv,
|
|
1767
|
-
platform: process.platform,
|
|
1768
|
-
version: process.version,
|
|
1769
|
-
versions: process.versions,
|
|
1770
|
-
cwd: process.cwd,
|
|
1771
|
-
exit: process.exit,
|
|
1772
|
-
nextTick: process.nextTick
|
|
1773
|
-
};
|
|
1774
|
-
}
|
|
1775
|
-
initBrowser() {
|
|
1776
|
-
this._process = {
|
|
1777
|
-
env: {
|
|
1778
|
-
NODE_ENV: "browser",
|
|
1779
|
-
...globalThis.process?.env || {}
|
|
1780
|
-
},
|
|
1781
|
-
argv: ["browser"],
|
|
1782
|
-
platform: "browser",
|
|
1783
|
-
version: "browser",
|
|
1784
|
-
versions: { node: "browser" },
|
|
1785
|
-
cwd: () => "/",
|
|
1786
|
-
exit: (code) => {
|
|
1787
|
-
this.logger.warning("process.exit not available in browser");
|
|
1788
|
-
throw new Error(`Process exit with code ${code}`);
|
|
1789
|
-
},
|
|
1790
|
-
nextTick: (callback, ...args) => {
|
|
1791
|
-
setTimeout(() => callback(...args), 0);
|
|
1792
|
-
}
|
|
1793
|
-
};
|
|
1794
|
-
}
|
|
1795
|
-
};
|
|
1796
|
-
|
|
1797
|
-
// src/lib/A-Polyfill/A-Polyfill.component.ts
|
|
1798
|
-
var A_Polyfill = class extends A_Component {
|
|
1799
|
-
constructor(logger) {
|
|
1800
|
-
super();
|
|
1801
|
-
this.logger = logger;
|
|
1802
|
-
this._initializing = null;
|
|
1803
|
-
}
|
|
1804
|
-
/**
|
|
1805
|
-
* Indicates whether the channel is connected
|
|
1806
|
-
*/
|
|
1807
|
-
get ready() {
|
|
1808
|
-
if (!this._initialized) {
|
|
1809
|
-
this._initialized = this._loadInternal();
|
|
1810
|
-
}
|
|
1811
|
-
return this._initialized;
|
|
1812
|
-
}
|
|
1813
|
-
async load() {
|
|
1814
|
-
await this.ready;
|
|
1815
|
-
}
|
|
1816
|
-
async attachToWindow() {
|
|
1817
|
-
if (A_Context.environment !== "browser") return;
|
|
1818
|
-
globalThis.A_Polyfill = this;
|
|
1819
|
-
globalThis.process = { env: { NODE_ENV: "production" }, cwd: () => "/" };
|
|
1820
|
-
globalThis.__dirname = "/";
|
|
1821
|
-
}
|
|
1822
|
-
async _loadInternal() {
|
|
1823
|
-
this._fsPolyfill = new A_FSPolyfillClass(this.logger);
|
|
1824
|
-
this._cryptoPolyfill = new A_CryptoPolyfillClass(this.logger);
|
|
1825
|
-
this._httpPolyfill = new A_HttpPolyfillClass(this.logger);
|
|
1826
|
-
this._httpsPolyfill = new A_HttpsPolyfillClass(this.logger);
|
|
1827
|
-
this._pathPolyfill = new A_PathPolyfillClass(this.logger);
|
|
1828
|
-
this._urlPolyfill = new A_UrlPolyfillClass(this.logger);
|
|
1829
|
-
this._bufferPolyfill = new A_BufferPolyfillClass(this.logger);
|
|
1830
|
-
this._processPolyfill = new A_ProcessPolyfillClass(this.logger);
|
|
1831
|
-
await this._fsPolyfill.get();
|
|
1832
|
-
await this._cryptoPolyfill.get(await this._fsPolyfill.get());
|
|
1833
|
-
await this._httpPolyfill.get();
|
|
1834
|
-
await this._httpsPolyfill.get();
|
|
1835
|
-
await this._pathPolyfill.get();
|
|
1836
|
-
await this._urlPolyfill.get();
|
|
1837
|
-
await this._bufferPolyfill.get();
|
|
1838
|
-
await this._processPolyfill.get();
|
|
1839
|
-
}
|
|
1840
|
-
/**
|
|
1841
|
-
* Allows to use the 'fs' polyfill methods regardless of the environment
|
|
1842
|
-
* This method loads the 'fs' polyfill and returns its instance
|
|
1843
|
-
*
|
|
1844
|
-
* @returns
|
|
1845
|
-
*/
|
|
1846
|
-
async fs() {
|
|
1847
|
-
await this.ready;
|
|
1848
|
-
return await this._fsPolyfill.get();
|
|
1849
|
-
}
|
|
1850
|
-
/**
|
|
1851
|
-
* Allows to use the 'crypto' polyfill methods regardless of the environment
|
|
1852
|
-
* This method loads the 'crypto' polyfill and returns its instance
|
|
1853
|
-
*
|
|
1854
|
-
* @returns
|
|
1855
|
-
*/
|
|
1856
|
-
async crypto() {
|
|
1857
|
-
await this.ready;
|
|
1858
|
-
return await this._cryptoPolyfill.get();
|
|
1859
|
-
}
|
|
1860
|
-
/**
|
|
1861
|
-
* Allows to use the 'http' polyfill methods regardless of the environment
|
|
1862
|
-
* This method loads the 'http' polyfill and returns its instance
|
|
1863
|
-
*
|
|
1864
|
-
* @returns
|
|
1865
|
-
*/
|
|
1866
|
-
async http() {
|
|
1867
|
-
await this.ready;
|
|
1868
|
-
return await this._httpPolyfill.get();
|
|
1869
|
-
}
|
|
1870
|
-
/**
|
|
1871
|
-
* Allows to use the 'https' polyfill methods regardless of the environment
|
|
1872
|
-
* This method loads the 'https' polyfill and returns its instance
|
|
1873
|
-
*
|
|
1874
|
-
* @returns
|
|
1875
|
-
*/
|
|
1876
|
-
async https() {
|
|
1877
|
-
await this.ready;
|
|
1878
|
-
return await this._httpsPolyfill.get();
|
|
1879
|
-
}
|
|
1880
|
-
/**
|
|
1881
|
-
* Allows to use the 'path' polyfill methods regardless of the environment
|
|
1882
|
-
* This method loads the 'path' polyfill and returns its instance
|
|
1883
|
-
*
|
|
1884
|
-
* @returns
|
|
1885
|
-
*/
|
|
1886
|
-
async path() {
|
|
1887
|
-
await this.ready;
|
|
1888
|
-
return await this._pathPolyfill.get();
|
|
1889
|
-
}
|
|
1890
|
-
/**
|
|
1891
|
-
* Allows to use the 'url' polyfill methods regardless of the environment
|
|
1892
|
-
* This method loads the 'url' polyfill and returns its instance
|
|
1893
|
-
*
|
|
1894
|
-
* @returns
|
|
1895
|
-
*/
|
|
1896
|
-
async url() {
|
|
1897
|
-
await this.ready;
|
|
1898
|
-
return await this._urlPolyfill.get();
|
|
1899
|
-
}
|
|
1900
|
-
/**
|
|
1901
|
-
* Allows to use the 'buffer' polyfill methods regardless of the environment
|
|
1902
|
-
* This method loads the 'buffer' polyfill and returns its instance
|
|
1903
|
-
*
|
|
1904
|
-
* @returns
|
|
1905
|
-
*/
|
|
1906
|
-
async buffer() {
|
|
1907
|
-
await this.ready;
|
|
1908
|
-
return await this._bufferPolyfill.get();
|
|
1909
|
-
}
|
|
1910
|
-
/**
|
|
1911
|
-
* Allows to use the 'process' polyfill methods regardless of the environment
|
|
1912
|
-
* This method loads the 'process' polyfill and returns its instance
|
|
1913
|
-
*
|
|
1914
|
-
* @returns
|
|
1915
|
-
*/
|
|
1916
|
-
async process() {
|
|
1917
|
-
await this.ready;
|
|
1918
|
-
return await this._processPolyfill.get();
|
|
1919
|
-
}
|
|
1920
|
-
};
|
|
1921
|
-
__decorateClass([
|
|
1922
|
-
A_Concept.Load()
|
|
1923
|
-
], A_Polyfill.prototype, "load", 1);
|
|
1924
|
-
__decorateClass([
|
|
1925
|
-
A_Concept.Load()
|
|
1926
|
-
], A_Polyfill.prototype, "attachToWindow", 1);
|
|
1927
|
-
A_Polyfill = __decorateClass([
|
|
1928
|
-
__decorateParam(0, A_Inject(A_Logger))
|
|
1929
|
-
], A_Polyfill);
|
|
1930
|
-
var A_ConfigError = class extends A_Error {
|
|
1931
|
-
};
|
|
1932
|
-
A_ConfigError.InitializationError = "A-Config Initialization Error";
|
|
1933
|
-
var ConfigReader = class extends A_Component {
|
|
1934
|
-
constructor(polyfill) {
|
|
1935
|
-
super();
|
|
1936
|
-
this.polyfill = polyfill;
|
|
1937
|
-
}
|
|
1938
|
-
async attachContext(container, feature, config) {
|
|
1939
|
-
if (!config) {
|
|
1940
|
-
config = new A_Config({
|
|
1941
|
-
variables: [
|
|
1942
|
-
...A_CONSTANTS__DEFAULT_ENV_VARIABLES_ARRAY,
|
|
1943
|
-
...A_CONSTANTS__CONFIG_ENV_VARIABLES_ARRAY
|
|
1944
|
-
],
|
|
1945
|
-
defaults: {}
|
|
1946
|
-
});
|
|
1947
|
-
container.scope.register(config);
|
|
1948
|
-
}
|
|
1949
|
-
const rootDir = await this.getProjectRoot();
|
|
1950
|
-
config.set("A_CONCEPT_ROOT_FOLDER", rootDir);
|
|
1951
|
-
}
|
|
1952
|
-
async initialize(config) {
|
|
1953
|
-
const data = await this.read([
|
|
1954
|
-
...config.CONFIG_PROPERTIES,
|
|
1955
|
-
...A_CONSTANTS__DEFAULT_ENV_VARIABLES_ARRAY,
|
|
1956
|
-
...A_CONSTANTS__CONFIG_ENV_VARIABLES_ARRAY
|
|
1957
|
-
]);
|
|
1958
|
-
config.set(data);
|
|
1959
|
-
}
|
|
1960
|
-
/**
|
|
1961
|
-
* Get the configuration property by Name
|
|
1962
|
-
* @param property
|
|
1963
|
-
*/
|
|
1964
|
-
resolve(property) {
|
|
1965
|
-
return property;
|
|
1966
|
-
}
|
|
1967
|
-
/**
|
|
1968
|
-
* This method reads the configuration and sets the values to the context
|
|
1969
|
-
*
|
|
1970
|
-
* @returns
|
|
1971
|
-
*/
|
|
1972
|
-
async read(variables = []) {
|
|
1973
|
-
return {};
|
|
1974
|
-
}
|
|
1975
|
-
/**
|
|
1976
|
-
* Finds the root directory of the project by locating the folder containing package.json
|
|
1977
|
-
*
|
|
1978
|
-
* @param {string} startPath - The initial directory to start searching from (default is __dirname)
|
|
1979
|
-
* @returns {string|null} - The path to the root directory or null if package.json is not found
|
|
1980
|
-
*/
|
|
1981
|
-
async getProjectRoot(startPath = __dirname) {
|
|
1982
|
-
return process.cwd();
|
|
1983
|
-
}
|
|
1984
|
-
};
|
|
1985
|
-
__decorateClass([
|
|
1986
|
-
A_Concept.Load(),
|
|
1987
|
-
__decorateParam(0, A_Inject(A_Container)),
|
|
1988
|
-
__decorateParam(1, A_Inject(A_Feature)),
|
|
1989
|
-
__decorateParam(2, A_Inject(A_Config))
|
|
1990
|
-
], ConfigReader.prototype, "attachContext", 1);
|
|
1991
|
-
__decorateClass([
|
|
1992
|
-
A_Concept.Load(),
|
|
1993
|
-
__decorateParam(0, A_Inject(A_Config))
|
|
1994
|
-
], ConfigReader.prototype, "initialize", 1);
|
|
1995
|
-
ConfigReader = __decorateClass([
|
|
1996
|
-
__decorateParam(0, A_Inject(A_Polyfill))
|
|
1997
|
-
], ConfigReader);
|
|
1998
|
-
|
|
1999
|
-
// src/lib/A-Config/components/FileConfigReader.component.ts
|
|
2000
|
-
var FileConfigReader = class extends ConfigReader {
|
|
2001
|
-
constructor() {
|
|
2002
|
-
super(...arguments);
|
|
2003
|
-
this.FileData = /* @__PURE__ */ new Map();
|
|
2004
|
-
}
|
|
2005
|
-
/**
|
|
2006
|
-
* Get the configuration property Name
|
|
2007
|
-
* @param property
|
|
2008
|
-
*/
|
|
2009
|
-
getConfigurationProperty_File_Alias(property) {
|
|
2010
|
-
return A_FormatterHelper.toCamelCase(property);
|
|
2011
|
-
}
|
|
2012
|
-
resolve(property) {
|
|
2013
|
-
return this.FileData.get(this.getConfigurationProperty_File_Alias(property));
|
|
2014
|
-
}
|
|
2015
|
-
async read(variables) {
|
|
2016
|
-
const fs = await this.polyfill.fs();
|
|
2017
|
-
try {
|
|
2018
|
-
const data = fs.readFileSync(`${A_Context.concept}.conf.json`, "utf8");
|
|
2019
|
-
const config = JSON.parse(data);
|
|
2020
|
-
this.FileData = new Map(Object.entries(config));
|
|
2021
|
-
return config;
|
|
2022
|
-
} catch (error) {
|
|
2023
|
-
return {};
|
|
2024
|
-
}
|
|
2025
|
-
}
|
|
2026
|
-
};
|
|
2027
|
-
var ENVConfigReader = class extends ConfigReader {
|
|
2028
|
-
async readEnvFile(config, polyfill, feature) {
|
|
2029
|
-
const fs = await polyfill.fs();
|
|
2030
|
-
if (fs.existsSync(".env"))
|
|
2031
|
-
fs.readFileSync(`${config.get("A_CONCEPT_ROOT_FOLDER")}/.env`, "utf-8").split("\n").forEach((line) => {
|
|
2032
|
-
const [key, value] = line.split("=");
|
|
2033
|
-
if (key && value) {
|
|
2034
|
-
process.env[key.trim()] = value.trim();
|
|
2035
|
-
}
|
|
2036
|
-
});
|
|
2037
|
-
}
|
|
2038
|
-
/**
|
|
2039
|
-
* Get the configuration property Name
|
|
2040
|
-
* @param property
|
|
2041
|
-
*/
|
|
2042
|
-
getConfigurationProperty_ENV_Alias(property) {
|
|
2043
|
-
return A_FormatterHelper.toUpperSnakeCase(property);
|
|
2044
|
-
}
|
|
2045
|
-
resolve(property) {
|
|
2046
|
-
return process.env[this.getConfigurationProperty_ENV_Alias(property)];
|
|
2047
|
-
}
|
|
2048
|
-
async read(variables = []) {
|
|
2049
|
-
const allVariables = [
|
|
2050
|
-
...variables,
|
|
2051
|
-
...Object.keys(process.env)
|
|
2052
|
-
];
|
|
2053
|
-
const config = {};
|
|
2054
|
-
allVariables.forEach((variable) => {
|
|
2055
|
-
config[variable] = this.resolve(variable);
|
|
2056
|
-
});
|
|
2057
|
-
return config;
|
|
2058
|
-
}
|
|
2059
|
-
};
|
|
2060
|
-
__decorateClass([
|
|
2061
|
-
A_Concept.Load({
|
|
2062
|
-
before: ["ENVConfigReader.initialize"]
|
|
2063
|
-
}),
|
|
2064
|
-
__decorateParam(0, A_Inject(A_Config)),
|
|
2065
|
-
__decorateParam(1, A_Inject(A_Polyfill)),
|
|
2066
|
-
__decorateParam(2, A_Inject(A_Feature))
|
|
2067
|
-
], ENVConfigReader.prototype, "readEnvFile", 1);
|
|
2068
|
-
|
|
2069
|
-
// src/lib/A-Config/A-Config.container.ts
|
|
2070
|
-
var A_ConfigLoader = class extends A_Container {
|
|
2071
|
-
async prepare(polyfill) {
|
|
2072
|
-
if (!this.scope.has(A_Config)) {
|
|
2073
|
-
const newConfig = new A_Config({
|
|
2074
|
-
variables: [
|
|
2075
|
-
...A_CONSTANTS__DEFAULT_ENV_VARIABLES_ARRAY,
|
|
2076
|
-
...A_CONSTANTS__CONFIG_ENV_VARIABLES_ARRAY
|
|
2077
|
-
],
|
|
2078
|
-
defaults: {}
|
|
2079
|
-
});
|
|
2080
|
-
this.scope.register(newConfig);
|
|
2081
|
-
}
|
|
2082
|
-
const fs = await polyfill.fs();
|
|
2083
|
-
try {
|
|
2084
|
-
switch (true) {
|
|
2085
|
-
case (A_Context.environment === "server" && !!fs.existsSync(`${A_Context.concept}.conf.json`)):
|
|
2086
|
-
this.reader = this.scope.resolve(FileConfigReader);
|
|
2087
|
-
break;
|
|
2088
|
-
case (A_Context.environment === "server" && !fs.existsSync(`${A_Context.concept}.conf.json`)):
|
|
2089
|
-
this.reader = this.scope.resolve(ENVConfigReader);
|
|
2090
|
-
break;
|
|
2091
|
-
case A_Context.environment === "browser":
|
|
2092
|
-
this.reader = this.scope.resolve(ENVConfigReader);
|
|
2093
|
-
break;
|
|
2094
|
-
default:
|
|
2095
|
-
throw new A_ConfigError(
|
|
2096
|
-
A_ConfigError.InitializationError,
|
|
2097
|
-
`Environment ${A_Context.environment} is not supported`
|
|
2098
|
-
);
|
|
2099
|
-
}
|
|
2100
|
-
} catch (error) {
|
|
2101
|
-
if (error instanceof A_ScopeError) {
|
|
2102
|
-
throw new A_ConfigError({
|
|
2103
|
-
title: A_ConfigError.InitializationError,
|
|
2104
|
-
description: `Failed to initialize A_ConfigLoader. Reader not found for environment ${A_Context.environment}`,
|
|
2105
|
-
originalError: error
|
|
2106
|
-
});
|
|
2107
|
-
}
|
|
2108
|
-
}
|
|
2109
|
-
}
|
|
2110
|
-
};
|
|
2111
|
-
__decorateClass([
|
|
2112
|
-
A_Concept.Load({
|
|
2113
|
-
before: /.*/
|
|
2114
|
-
}),
|
|
2115
|
-
__decorateParam(0, A_Inject(A_Polyfill))
|
|
2116
|
-
], A_ConfigLoader.prototype, "prepare", 1);
|
|
2117
|
-
|
|
2118
|
-
// src/lib/A-Config/A-Config.types.ts
|
|
2119
|
-
var A_TYPES__ConfigFeature = /* @__PURE__ */ ((A_TYPES__ConfigFeature2) => {
|
|
2120
|
-
return A_TYPES__ConfigFeature2;
|
|
2121
|
-
})(A_TYPES__ConfigFeature || {});
|
|
2122
|
-
var A_ManifestError = class extends A_Error {
|
|
2123
|
-
};
|
|
2124
|
-
A_ManifestError.ManifestInitializationError = "A-Manifest Initialization Error";
|
|
2125
|
-
|
|
2126
|
-
// src/lib/A-Manifest/classes/A-ManifestChecker.class.ts
|
|
2127
|
-
var A_ManifestChecker = class {
|
|
2128
|
-
constructor(manifest, component, method, checkExclusion = false) {
|
|
2129
|
-
this.manifest = manifest;
|
|
2130
|
-
this.component = component;
|
|
2131
|
-
this.method = method;
|
|
2132
|
-
this.checkExclusion = checkExclusion;
|
|
2133
|
-
}
|
|
2134
|
-
for(target) {
|
|
2135
|
-
const result = this.manifest.internal_checkAccess({
|
|
2136
|
-
component: this.component,
|
|
2137
|
-
method: this.method,
|
|
2138
|
-
target
|
|
2139
|
-
});
|
|
2140
|
-
return this.checkExclusion ? !result : result;
|
|
2141
|
-
}
|
|
2142
|
-
};
|
|
2143
|
-
|
|
2144
|
-
// src/lib/A-Manifest/A-Manifest.context.ts
|
|
2145
|
-
var A_Manifest = class extends A_Fragment {
|
|
2146
|
-
/**
|
|
2147
|
-
* A-Manifest is a configuration set that allows to include or exclude component application for the particular methods.
|
|
2148
|
-
*
|
|
2149
|
-
* For example, if A-Scope provides polymorphic A-Component that applies for All A-Entities in it but you have another component that should be used for only One particular Entity, you can use A-Manifest to specify this behavior.
|
|
2150
|
-
*
|
|
2151
|
-
*
|
|
2152
|
-
* By default if Component is provided in the scope - it applies for all entities in it. However, if you want to exclude some entities or include only some entities for the particular component - you can use A-Manifest to define this behavior.
|
|
2153
|
-
*
|
|
2154
|
-
* @param config - Array of component configurations
|
|
2155
|
-
*/
|
|
2156
|
-
constructor(config = []) {
|
|
2157
|
-
super({
|
|
2158
|
-
name: "A-Manifest"
|
|
2159
|
-
});
|
|
2160
|
-
this.rules = [];
|
|
2161
|
-
this.prepare(config);
|
|
2162
|
-
}
|
|
2163
|
-
/**
|
|
2164
|
-
* Should convert received configuration into internal Regexp applicable for internal storage
|
|
2165
|
-
*/
|
|
2166
|
-
prepare(config) {
|
|
2167
|
-
if (!A_TypeGuards.isArray(config))
|
|
2168
|
-
throw new A_ManifestError(
|
|
2169
|
-
A_ManifestError.ManifestInitializationError,
|
|
2170
|
-
`A-Manifest configuration should be an array of configurations`
|
|
2171
|
-
);
|
|
2172
|
-
for (const item of config) {
|
|
2173
|
-
this.processConfigItem(item);
|
|
2174
|
-
}
|
|
2175
|
-
}
|
|
2176
|
-
/**
|
|
2177
|
-
* Process a single configuration item and convert it to internal rules
|
|
2178
|
-
*/
|
|
2179
|
-
processConfigItem(item) {
|
|
2180
|
-
if (!A_TypeGuards.isComponentConstructor(item.component))
|
|
2181
|
-
throw new A_ManifestError(
|
|
2182
|
-
A_ManifestError.ManifestInitializationError,
|
|
2183
|
-
`A-Manifest configuration item should be a A-Component constructor`
|
|
2184
|
-
);
|
|
2185
|
-
const componentRegex = this.constructorToRegex(item.component);
|
|
2186
|
-
if (item.apply || item.exclude) {
|
|
2187
|
-
const methodRegex = /.*/;
|
|
2188
|
-
this.rules.push({
|
|
2189
|
-
componentRegex,
|
|
2190
|
-
methodRegex,
|
|
2191
|
-
applyRegex: item.apply ? this.allowedComponentsToRegex(item.apply) : void 0,
|
|
2192
|
-
excludeRegex: item.exclude ? this.allowedComponentsToRegex(item.exclude) : void 0
|
|
2193
|
-
});
|
|
2194
|
-
}
|
|
2195
|
-
if (item.methods && item.methods.length > 0) {
|
|
2196
|
-
for (const methodConfig of item.methods) {
|
|
2197
|
-
const methodRegex = this.methodToRegex(methodConfig.method);
|
|
2198
|
-
this.rules.push({
|
|
2199
|
-
componentRegex,
|
|
2200
|
-
methodRegex,
|
|
2201
|
-
applyRegex: methodConfig.apply ? this.allowedComponentsToRegex(methodConfig.apply) : void 0,
|
|
2202
|
-
excludeRegex: methodConfig.exclude ? this.allowedComponentsToRegex(methodConfig.exclude) : void 0
|
|
2203
|
-
});
|
|
2204
|
-
}
|
|
2205
|
-
}
|
|
2206
|
-
}
|
|
2207
|
-
/**
|
|
2208
|
-
* Convert a constructor to a regex pattern
|
|
2209
|
-
*/
|
|
2210
|
-
constructorToRegex(ctor) {
|
|
2211
|
-
return new RegExp(`^${this.escapeRegex(ctor.name)}$`);
|
|
2212
|
-
}
|
|
2213
|
-
/**
|
|
2214
|
-
* Convert a method name or regex to a regex pattern
|
|
2215
|
-
*/
|
|
2216
|
-
methodToRegex(method) {
|
|
2217
|
-
if (method instanceof RegExp) {
|
|
2218
|
-
return method;
|
|
2219
|
-
}
|
|
2220
|
-
return new RegExp(`^${this.escapeRegex(method)}$`);
|
|
2221
|
-
}
|
|
2222
|
-
/**
|
|
2223
|
-
* Convert allowed components array or regex to a single regex
|
|
2224
|
-
*/
|
|
2225
|
-
allowedComponentsToRegex(components) {
|
|
2226
|
-
if (components instanceof RegExp) {
|
|
2227
|
-
return components;
|
|
2228
|
-
}
|
|
2229
|
-
const patterns = components.map((ctor) => this.escapeRegex(ctor.name));
|
|
2230
|
-
return new RegExp(`^(${patterns.join("|")})$`);
|
|
2231
|
-
}
|
|
2232
|
-
/**
|
|
2233
|
-
* Escape special regex characters in a string
|
|
2234
|
-
*/
|
|
2235
|
-
escapeRegex(str) {
|
|
2236
|
-
return str.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
2237
|
-
}
|
|
2238
|
-
configItemToRegexp(item) {
|
|
2239
|
-
return this.constructorToRegex(item);
|
|
2240
|
-
}
|
|
2241
|
-
ID(component, method) {
|
|
2242
|
-
return `${component.name}.${method}`;
|
|
2243
|
-
}
|
|
2244
|
-
/**
|
|
2245
|
-
* Check if a component and method combination is allowed for a target
|
|
2246
|
-
*/
|
|
2247
|
-
isAllowed(ctor, method) {
|
|
2248
|
-
const componentCtor = typeof ctor === "function" ? ctor : ctor.constructor;
|
|
2249
|
-
return new A_ManifestChecker(this, componentCtor, method);
|
|
2250
|
-
}
|
|
2251
|
-
/**
|
|
2252
|
-
* Internal method to check if access is allowed
|
|
2253
|
-
*/
|
|
2254
|
-
internal_checkAccess(query) {
|
|
2255
|
-
const componentName = query.component.name;
|
|
2256
|
-
const methodName = query.method;
|
|
2257
|
-
const targetName = query.target.name;
|
|
2258
|
-
const matchingRules = this.rules.filter(
|
|
2259
|
-
(rule) => rule.componentRegex.test(componentName) && rule.methodRegex.test(methodName)
|
|
2260
|
-
).sort((a, b) => {
|
|
2261
|
-
const aIsGeneral = a.methodRegex.source === ".*";
|
|
2262
|
-
const bIsGeneral = b.methodRegex.source === ".*";
|
|
2263
|
-
if (aIsGeneral && !bIsGeneral) return 1;
|
|
2264
|
-
if (!aIsGeneral && bIsGeneral) return -1;
|
|
2265
|
-
return 0;
|
|
2266
|
-
});
|
|
2267
|
-
if (matchingRules.length === 0) {
|
|
2268
|
-
return true;
|
|
2269
|
-
}
|
|
2270
|
-
for (const rule of matchingRules) {
|
|
2271
|
-
if (rule.excludeRegex && rule.excludeRegex.test(targetName)) {
|
|
2272
|
-
return false;
|
|
2273
|
-
}
|
|
2274
|
-
if (rule.applyRegex) {
|
|
2275
|
-
return rule.applyRegex.test(targetName);
|
|
2276
|
-
}
|
|
2277
|
-
}
|
|
2278
|
-
return true;
|
|
2279
|
-
}
|
|
2280
|
-
isExcluded(ctor, method) {
|
|
2281
|
-
const componentCtor = typeof ctor === "function" ? ctor : ctor.constructor;
|
|
2282
|
-
return new A_ManifestChecker(this, componentCtor, method, true);
|
|
2283
|
-
}
|
|
2284
|
-
};
|
|
2285
|
-
|
|
2286
|
-
// src/lib/A-Schedule/A-Deferred.class.ts
|
|
2287
|
-
var A_Deferred = class {
|
|
2288
|
-
/**
|
|
2289
|
-
* Creates a deferred promise
|
|
2290
|
-
* @returns A promise that can be resolved or rejected later
|
|
2291
|
-
*/
|
|
2292
|
-
constructor() {
|
|
2293
|
-
this.promise = new Promise((resolve, reject) => {
|
|
2294
|
-
this.resolveFn = resolve;
|
|
2295
|
-
this.rejectFn = reject;
|
|
2296
|
-
});
|
|
2297
|
-
}
|
|
2298
|
-
resolve(value) {
|
|
2299
|
-
this.resolveFn(value);
|
|
2300
|
-
}
|
|
2301
|
-
reject(reason) {
|
|
2302
|
-
this.rejectFn(reason);
|
|
2303
|
-
}
|
|
2304
|
-
};
|
|
2305
|
-
var A_ScheduleObject = class {
|
|
2306
|
-
/**
|
|
2307
|
-
* Creates a scheduled object that will execute the action after specified milliseconds
|
|
2308
|
-
*
|
|
2309
|
-
*
|
|
2310
|
-
* @param ms - milliseconds to wait before executing the action
|
|
2311
|
-
* @param action - the action to execute
|
|
2312
|
-
* @param config - configuration options for the schedule object
|
|
2313
|
-
*/
|
|
2314
|
-
constructor(ms, action, config) {
|
|
2315
|
-
this.config = {
|
|
2316
|
-
/**
|
|
2317
|
-
* If the timeout is cleared, should the promise resolve or reject?
|
|
2318
|
-
* BY Default it rejects
|
|
2319
|
-
*
|
|
2320
|
-
* !!!NOTE: If the property is set to true, the promise will resolve with undefined
|
|
2321
|
-
*/
|
|
2322
|
-
resolveOnClear: false
|
|
2323
|
-
};
|
|
2324
|
-
if (config)
|
|
2325
|
-
this.config = { ...this.config, ...config };
|
|
2326
|
-
this.deferred = new A_Deferred();
|
|
2327
|
-
this.timeout = setTimeout(
|
|
2328
|
-
() => action().then((...args) => this.deferred.resolve(...args)).catch((...args) => this.deferred.reject(...args)),
|
|
2329
|
-
ms
|
|
2330
|
-
);
|
|
2331
|
-
}
|
|
2332
|
-
get promise() {
|
|
2333
|
-
return this.deferred.promise;
|
|
2334
|
-
}
|
|
2335
|
-
clear() {
|
|
2336
|
-
if (this.timeout) {
|
|
2337
|
-
clearTimeout(this.timeout);
|
|
2338
|
-
if (this.config.resolveOnClear)
|
|
2339
|
-
this.deferred.resolve(void 0);
|
|
2340
|
-
else
|
|
2341
|
-
this.deferred.reject(new A_Error("Timeout Cleared"));
|
|
2342
|
-
}
|
|
2343
|
-
}
|
|
2344
|
-
};
|
|
2345
|
-
|
|
2346
|
-
// src/lib/A-Schedule/A-Schedule.component.ts
|
|
2347
|
-
var A_Schedule = class extends A_Component {
|
|
2348
|
-
async schedule(date, callback, config) {
|
|
2349
|
-
const timestamp = A_TypeGuards.isString(date) ? new Date(date).getTime() : date;
|
|
2350
|
-
return new A_ScheduleObject(
|
|
2351
|
-
timestamp - Date.now(),
|
|
2352
|
-
callback,
|
|
2353
|
-
config
|
|
2354
|
-
);
|
|
2355
|
-
}
|
|
2356
|
-
/**
|
|
2357
|
-
* Allows to execute callback after particular delay in milliseconds
|
|
2358
|
-
* So the callback will be executed after the specified delay
|
|
2359
|
-
*
|
|
2360
|
-
* @param ms
|
|
2361
|
-
*/
|
|
2362
|
-
async delay(ms, callback, config) {
|
|
2363
|
-
return new A_ScheduleObject(
|
|
2364
|
-
ms,
|
|
2365
|
-
callback,
|
|
2366
|
-
config
|
|
2367
|
-
);
|
|
2368
|
-
}
|
|
2369
|
-
};
|
|
2370
|
-
|
|
2371
|
-
export { A_CONSTANTS__A_Command_Status, A_CONSTANTS__CONFIG_ENV_VARIABLES, A_CONSTANTS__CONFIG_ENV_VARIABLES_ARRAY, A_Channel, A_ChannelError, A_ChannelFeatures, A_ChannelRequest, A_ChannelRequestStatuses, A_Command, A_CommandError, A_CommandFeatures, 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
|
-
//# sourceMappingURL=index.mjs.map
|
|
1
|
+
import {A_Feature,A_Inject,A_Scope,A_Error,A_Dependency,A_Concept,A_Container,A_TypeGuards,A_Component,A_IdentityHelper,A_Context,A_FormatterHelper,A_Fragment,A_CONSTANTS__DEFAULT_ENV_VARIABLES_ARRAY,A_CommonHelper,A_Entity,A_ScopeError}from'@adaas/a-concept';var He=Object.defineProperty;var at=Object.getOwnPropertyDescriptor;var i=(M,t)=>He(M,"name",{value:t,configurable:true});var l=(M,t,e,r)=>{for(var o=r>1?void 0:r?at(t,e):t,n=M.length-1,s;n>=0;n--)(s=M[n])&&(o=(r?s(t,e,o):s(o))||o);return r&&o&&He(t,e,o),o},c=(M,t)=>(e,r)=>t(e,r,M);var ue=class ue extends A_Fragment{constructor(t,e){super(),this.meta.set("name",t),this.meta.set("params",e||{});}get name(){return this._meta.get("name")||this._name}get result(){return this._meta.get("result")}get error(){return this._meta.get("error")}get params(){return this._meta.get("params")||{}}fail(t){this._meta.set("error",t);}succeed(t){this._meta.set("result",t);}toJSON(){return {name:this.name,params:this.params,result:this.result||{},error:this.error?.toJSON()}}};i(ue,"A_OperationContext");var p=ue;var te=class te extends A_Error{constructor(t,e){A_TypeGuards.isString(e)?super(t,e):super(t),e instanceof p&&(this._context=e);}get context(){return this._context}};i(te,"A_ChannelError"),te.MethodNotImplemented="A-Channel Method Not Implemented";var F=te;var _t=(y=>(y.onTimeout="onTimeout",y.onRetry="onRetry",y.onCircuitBreakerOpen="onCircuitBreakerOpen",y.onCache="onCache",y.onConnect="onConnect",y.onDisconnect="onDisconnect",y.onBeforeRequest="onBeforeRequest",y.onRequest="onRequest",y.onAfterRequest="onAfterRequest",y.onError="onError",y.onSend="onSend",y.onConsume="onConsume",y))(_t||{}),dt=(r=>(r.PENDING="PENDING",r.SUCCESS="SUCCESS",r.FAILED="FAILED",r))(dt||{});var ge=class ge extends p{constructor(t){super("request",t);}get status(){return this.result?.status}get data(){return this.result?.data}succeed(t){let e=this.result;super.succeed({...e,data:t,status:"SUCCESS"});}};i(ge,"A_ChannelRequest");var re=ge;var x=class x extends A_Component{constructor(){super();this._processing=false;this._cache=new Map;}get processing(){return this._processing}get initialize(){return this._initialized||(this._initialized=this.connect()),this._initialized}async onConnect(...e){}async onDisconnect(...e){}async onBeforeRequest(...e){}async onRequest(...e){}async onAfterRequest(...e){}async onError(...e){}async onSend(...e){}async connect(){await this.call("onConnect");}async disconnect(){await this.call("onDisconnect");}async request(e){await this.initialize,this._processing=true;let r=new A_Scope({name:`a-channel@scope:request:${A_IdentityHelper.generateTimeId()}`}),o=new re(e);try{return r.register(o),await this.call("onBeforeRequest",r),await this.call("onRequest",r),await this.call("onAfterRequest",r),this._processing=!1,o}catch(n){this._processing=false;let s=new F(n);throw o.fail(s),r.register(s),await this.call("onError",r),r.destroy(),s}}async send(e){await this.initialize,this._processing=true;let r=new A_Scope({name:`a-channel@scope:send:${A_IdentityHelper.generateTimeId()}`}),o=new p("send",e);try{r.inherit(A_Context.scope(this)),r.register(o),await this.call("onSend",r),this._processing=!1;}catch(n){this._processing=false;let s=new F(n);r.register(s),o.fail(s),await this.call("onError",r),r.destroy();}}async consume(){await this.initialize,this._processing=true;let e=new A_Scope({name:`a-channel@scope:consume:${A_IdentityHelper.generateTimeId()}`}),r=new p("consume",{});try{return e.inherit(A_Context.scope(this)),e.register(r),await this.call("onConsume",e),this._processing=!1,r}catch(o){this._processing=false;let n=new F(o);return r.fail(n),await this.call("onError",e),r}}};i(x,"A_Channel"),l([A_Feature.Extend({name:"onConnect"})],x.prototype,"onConnect",1),l([A_Feature.Extend({name:"onDisconnect"})],x.prototype,"onDisconnect",1),l([A_Feature.Extend({name:"onBeforeRequest"})],x.prototype,"onBeforeRequest",1),l([A_Feature.Extend({name:"onRequest"})],x.prototype,"onRequest",1),l([A_Feature.Extend({name:"onAfterRequest"})],x.prototype,"onAfterRequest",1),l([A_Feature.Extend({name:"onError"})],x.prototype,"onError",1),l([A_Feature.Extend({name:"onSend"})],x.prototype,"onSend",1);var Te=x;var ht=(s=>(s.CREATED="CREATED",s.INITIALIZED="INITIALIZED",s.COMPILED="COMPILED",s.EXECUTING="EXECUTING",s.COMPLETED="COMPLETED",s.FAILED="FAILED",s))(ht||{}),ft=(o=>(o.CREATED_TO_INITIALIZED="created_initialized",o.INITIALIZED_TO_EXECUTING="initialized_executing",o.EXECUTING_TO_COMPLETED="executing_completed",o.EXECUTING_TO_FAILED="executing_failed",o))(ft||{}),ut=(a=>(a.onInit="onInit",a.onBeforeExecute="onBeforeExecute",a.onExecute="onExecute",a.onAfterExecute="onAfterExecute",a.onComplete="onComplete",a.onFail="onFail",a.onError="onError",a))(ut||{});var z=class z extends A_Error{};i(z,"A_CommandError"),z.CommandScopeBindingError="A-Command Scope Binding Error",z.ExecutionError="A-Command Execution Error",z.ResultProcessingError="A-Command Result Processing Error",z.CommandInterruptedError="A-Command Interrupted Error";var P=z;var K=class K extends A_Error{};i(K,"A_StateMachineError"),K.InitializationError="A-StateMachine Initialization Error",K.TransitionError="A-StateMachine Transition Error";var X=K;var Ae=class Ae extends p{constructor(t){super("a-state-machine-transition",t),this._meta.set("from",t.from),this._meta.set("to",t.to);}get from(){return this._meta.get("from")}get to(){return this._meta.get("to")}};i(Ae,"A_StateMachineTransition");var R=Ae;var At,St,Ct,vt,U=class U extends A_Component{get ready(){return this._initialized||(this._initialized=this.call("onInitialize")),this._initialized}async[vt="onInitialize"](...t){}async[Ct="onBeforeTransition"](...t){}async[St="onAfterTransition"](...t){}async[At="onError"](...t){}async transition(t,e,r){await this.ready;let o=`${A_FormatterHelper.toCamelCase(String(t))}_${A_FormatterHelper.toCamelCase(String(e))}`,n=new R({from:String(t),to:String(e),props:r}),s=new A_Scope({name:`A-StateMachine-Transition-Scope-${o}`,fragments:[n]});try{return await this.call("onBeforeTransition",s),await this.call(o,s),await this.call("onAfterTransition",s),s.destroy(),n.result}catch(a){let d=new X({title:X.TransitionError,description:`An error occurred while transitioning to "${o}"`,originalError:a});throw s.register(d),await this.call("onError",s),s.destroy(),d}}};i(U,"A_StateMachine"),l([A_Feature.Extend()],U.prototype,vt,1),l([A_Feature.Extend()],U.prototype,Ct,1),l([A_Feature.Extend()],U.prototype,St,1),l([A_Feature.Extend()],U.prototype,At,1);var O=U;var yo={},B=[];var Ce=class Ce extends A_Fragment{constructor(e){super({name:"A_Config"});this.VARIABLES=new Map;this.DEFAULT_ALLOWED_TO_READ_PROPERTIES=[...A_CONSTANTS__DEFAULT_ENV_VARIABLES_ARRAY,...B];this.config=A_CommonHelper.deepCloneAndMerge(e,{strict:false,defaults:{},variables:A_CONSTANTS__DEFAULT_ENV_VARIABLES_ARRAY}),this.CONFIG_PROPERTIES=this.config.variables?this.config.variables:[],this.config.variables.forEach(r=>{this.VARIABLES.set(A_FormatterHelper.toUpperSnakeCase(r),this.config.defaults[r]);});}get(e){if(this.CONFIG_PROPERTIES.includes(e)||this.DEFAULT_ALLOWED_TO_READ_PROPERTIES.includes(e)||!this.config.strict)return this.VARIABLES.get(A_FormatterHelper.toUpperSnakeCase(e));throw new Error("Property not exists or not allowed to read")}set(e,r){let o=Array.isArray(e)?e:typeof e=="string"?[{property:e,value:r}]:Object.keys(e).map(n=>({property:n,value:e[n]}));for(let{property:n,value:s}of o){let a=s||(this.config?.defaults?this.config.defaults[n]:void 0);this.VARIABLES.set(A_FormatterHelper.toUpperSnakeCase(n),a);}}};i(Ce,"A_Config");var h=Ce;var Ze={red:"31",yellow:"33",green:"32",blue:"34",cyan:"36",magenta:"35",gray:"90",brightBlue:"94",brightCyan:"96",brightMagenta:"95",darkGray:"30",lightGray:"37",indigo:"38;5;54",violet:"38;5;93",purple:"38;5;129",lavender:"38;5;183",skyBlue:"38;5;117",steelBlue:"38;5;67",slateBlue:"38;5;62",deepBlue:"38;5;18",lightBlue:"38;5;153",periwinkle:"38;5;111",cornflower:"38;5;69",powder:"38;5;152",charcoal:"38;5;236",silver:"38;5;250",smoke:"38;5;244",slate:"38;5;240"},We=["blue","cyan","magenta","gray","brightBlue","brightCyan","brightMagenta","darkGray","lightGray","indigo","violet","purple","lavender","skyBlue","steelBlue","slateBlue","deepBlue","lightBlue","periwinkle","cornflower","powder","charcoal","silver","smoke","slate"],N={RESET:"\x1B[0m",PREFIX:"\x1B[",SUFFIX:"m"},V={MINUTES_PAD:2,SECONDS_PAD:2,MILLISECONDS_PAD:3,SEPARATOR:":"},E={SCOPE_OPEN:"[",SCOPE_CLOSE:"]",TIME_OPEN:"|",TIME_CLOSE:"|",SEPARATOR:"-------------------------------",PIPE:"| "},J={LOG_LEVEL:"A_LOGGER_LEVEL",DEFAULT_SCOPE_LENGTH:"A_LOGGER_DEFAULT_SCOPE_LENGTH",DEFAULT_SCOPE_COLOR:"A_LOGGER_DEFAULT_SCOPE_COLOR",DEFAULT_LOG_COLOR:"A_LOGGER_DEFAULT_LOG_COLOR"};var C=class extends A_Component{constructor(e,r){super();this.scope=e;this.config=r;this.COLORS=Ze,this.STANDARD_SCOPE_LENGTH=r?.get(J.DEFAULT_SCOPE_LENGTH)||20;let o=r?.get(J.DEFAULT_SCOPE_COLOR),n=r?.get(J.DEFAULT_LOG_COLOR);if(o||n)this.DEFAULT_SCOPE_COLOR=o||this.generateColorFromScopeName(this.scope.name),this.DEFAULT_LOG_COLOR=n||this.generateColorFromScopeName(this.scope.name);else {let s=this.generateComplementaryColorsFromScope(this.scope.name);this.DEFAULT_SCOPE_COLOR=s.scopeColor,this.DEFAULT_LOG_COLOR=s.logColor;}}simpleHash(e){let r=0;for(let o=0;o<e.length;o++){let n=e.charCodeAt(o);r=(r<<5)-r+n,r=r&r;}return Math.abs(r)}generateColorFromScopeName(e){let r=We,n=this.simpleHash(e)%r.length;return r[n]}generateComplementaryColorsFromScope(e){let r=[{scopeColor:"indigo",logColor:"lightBlue"},{scopeColor:"deepBlue",logColor:"cyan"},{scopeColor:"purple",logColor:"lavender"},{scopeColor:"steelBlue",logColor:"skyBlue"},{scopeColor:"slateBlue",logColor:"periwinkle"},{scopeColor:"charcoal",logColor:"silver"},{scopeColor:"violet",logColor:"brightMagenta"},{scopeColor:"darkGray",logColor:"lightGray"},{scopeColor:"cornflower",logColor:"powder"},{scopeColor:"slate",logColor:"smoke"}],n=this.simpleHash(e)%r.length;return r[n]}get scopeLength(){return Math.max(this.scope.name.length,this.STANDARD_SCOPE_LENGTH)}get formattedScope(){let e=this.scope.name,r=this.STANDARD_SCOPE_LENGTH;if(e.length>=r)return e.substring(0,r);let o=r-e.length,n=Math.floor(o/2),s=o-n;return " ".repeat(n)+e+" ".repeat(s)}compile(e,...r){let o=this.getTime(),n=" ".repeat(this.scopeLength+3),s=r.length>1;return [`${N.PREFIX}${this.COLORS[this.DEFAULT_SCOPE_COLOR]}${N.SUFFIX}${E.SCOPE_OPEN}${this.formattedScope}${E.SCOPE_CLOSE}${N.RESET} ${N.PREFIX}${this.COLORS[e]}${N.SUFFIX}${E.TIME_OPEN}${o}${E.TIME_CLOSE}`,s?`
|
|
2
|
+
${n}${E.TIME_OPEN}${E.SEPARATOR}`:"",...r.map((a,d)=>{let L=d>0||s;switch(true){case a instanceof A_Error:return this.compile_A_Error(a);case a instanceof Error:return this.compile_Error(a);case(typeof a=="object"&&a!==null):return this.formatObject(a,L,n);default:return this.formatString(String(a),L,n)}}),s?`
|
|
3
|
+
${n}${E.TIME_OPEN}${E.SEPARATOR}${N.RESET}`:N.RESET]}formatObject(e,r,o){let n;try{n=JSON.stringify(e,null,2);}catch{let d=new WeakSet;n=JSON.stringify(e,(L,b)=>{if(typeof b=="object"&&b!==null){if(d.has(b))return "[Circular Reference]";d.add(b);}return b},2);}let s=n.replace(/\n/g,`
|
|
4
|
+
${o}${E.PIPE}`);return r?`
|
|
5
|
+
${o}${E.PIPE}`+s:s}formatString(e,r,o){return ((r?`
|
|
6
|
+
`:"")+e).replace(/\n/g,`
|
|
7
|
+
${o}${E.PIPE}`)}shouldLog(e){switch(this.config?.get(J.LOG_LEVEL)||"info"){case "debug":return true;case "info":return e==="info"||e==="warning"||e==="error";case "warn":return e==="warning"||e==="error";case "error":return e==="error";case "all":return true;default:return false}}debug(e,...r){this.shouldLog("debug")&&(typeof e=="string"&&this.COLORS[e]?console.log(...this.compile(e,...r)):console.log(...this.compile(this.DEFAULT_LOG_COLOR,e,...r)));}info(e,...r){this.shouldLog("info")&&(typeof e=="string"&&this.COLORS[e]?console.log(...this.compile(e,...r)):console.log(...this.compile(this.DEFAULT_LOG_COLOR,e,...r)));}log(e,...r){this.info(e,...r);}warning(...e){this.shouldLog("warning")&&console.log(...this.compile("yellow",...e));}error(...e){this.shouldLog("error")&&console.log(...this.compile("red",...e));}log_A_Error(e){let r=this.getTime(),o=" ".repeat(this.scopeLength+3);console.log(`\x1B[31m[${this.formattedScope}] |${r}| ERROR ${e.code}
|
|
8
|
+
${o}| ${e.message}
|
|
9
|
+
${o}| ${e.description}
|
|
10
|
+
${o}|-------------------------------
|
|
11
|
+
${o}| ${e.stack?.split(`
|
|
12
|
+
`).map((n,s)=>s===0?n:`${o}| ${n}`).join(`
|
|
13
|
+
`)||"No stack trace"}
|
|
14
|
+
${o}|-------------------------------
|
|
15
|
+
\x1B[0m`+(e.originalError?`\x1B[31m${o}| Wrapped From ${e.originalError.message}
|
|
16
|
+
${o}|-------------------------------
|
|
17
|
+
${o}| ${e.originalError.stack?.split(`
|
|
18
|
+
`).map((n,s)=>s===0?n:`${o}| ${n}`).join(`
|
|
19
|
+
`)||"No stack trace"}
|
|
20
|
+
${o}|-------------------------------
|
|
21
|
+
\x1B[0m`:"")+(e.link?`\x1B[31m${o}| Read in docs: ${e.link}
|
|
22
|
+
${o}|-------------------------------
|
|
23
|
+
\x1B[0m`:""));}compile_A_Error(e){let r=" ".repeat(this.scopeLength+3);return `
|
|
24
|
+
${r}|-------------------------------
|
|
25
|
+
${r}| Error: | ${e.code}
|
|
26
|
+
${r}|-------------------------------
|
|
27
|
+
${r}|${" ".repeat(10)}| ${e.message}
|
|
28
|
+
${r}|${" ".repeat(10)}| ${e.description}
|
|
29
|
+
${r}|-------------------------------
|
|
30
|
+
${r}| ${e.stack?.split(`
|
|
31
|
+
`).map((o,n)=>n===0?o:`${r}| ${o}`).join(`
|
|
32
|
+
`)||"No stack trace"}
|
|
33
|
+
${r}|-------------------------------`+(e.originalError?`${r}| Wrapped From ${e.originalError.message}
|
|
34
|
+
${r}|-------------------------------
|
|
35
|
+
${r}| ${e.originalError.stack?.split(`
|
|
36
|
+
`).map((o,n)=>n===0?o:`${r}| ${o}`).join(`
|
|
37
|
+
`)||"No stack trace"}
|
|
38
|
+
${r}|-------------------------------`:"")+(e.link?`${r}| Read in docs: ${e.link}
|
|
39
|
+
${r}|-------------------------------`:"")}compile_Error(e){let r=" ".repeat(this.scopeLength+3);return JSON.stringify({name:e.name,message:e.message,stack:e.stack?.split(`
|
|
40
|
+
`).map((o,n)=>n===0?o:`${r}| ${o}`).join(`
|
|
41
|
+
`)},null,2).replace(/\n/g,`
|
|
42
|
+
${r}| `).replace(/\\n/g,`
|
|
43
|
+
`)}getTime(){let e=new Date,r=String(e.getMinutes()).padStart(V.MINUTES_PAD,"0"),o=String(e.getSeconds()).padStart(V.SECONDS_PAD,"0"),n=String(e.getMilliseconds()).padStart(V.MILLISECONDS_PAD,"0");return `${r}${V.SEPARATOR}${o}${V.SEPARATOR}${n}`}};i(C,"A_Logger"),C=l([c(0,A_Inject(A_Scope)),c(1,A_Inject(h))],C);var bt,Nt,Dt,$t,kt,Mt,Ft,Gt,zt,Ut,Bt,u=class u extends A_Entity{constructor(e){super(e);this._listeners=new Map;}static get code(){return super.entity}get duration(){return this._endTime&&this._startTime?this._endTime.getTime()-this._startTime.getTime():this._startTime?new Date().getTime()-this._startTime.getTime():void 0}get idleTime(){return this._startTime&&this._createdAt?this._startTime.getTime()-this._createdAt.getTime():void 0}get scope(){return this._executionScope}get code(){return this.constructor.code}get status(){return this._status}get createdAt(){return this._createdAt}get startedAt(){return this._startTime}get endedAt(){return this._endTime}get result(){return this._result}get error(){return this._error}get params(){return this._params}get isProcessed(){return this._status==="COMPLETED"||this._status==="FAILED"}async[Bt="onBeforeTransition"](e,r,...o){this.checkScopeInheritance(),r?.debug("yellow",`Command ${this.aseid.toString()} transitioning from ${e.from} to ${e.to}`);}async[Ut="created_initialized"](e,...r){this._status==="CREATED"&&(this._createdAt=new Date,this._status="INITIALIZED",this.emit("onInit"));}async[zt="initialized_executing"](e,...r){this._status!=="INITIALIZED"&&this._status!=="CREATED"||(this._startTime=new Date,this._status="EXECUTING",this.emit("onExecute"));}async[Gt="executing_completed"](e,...r){this._endTime=new Date,this._status="COMPLETED",this.emit("onComplete");}async[Ft="executing_failed"](e,r,...o){this._endTime=new Date,this._status="FAILED",this.emit("onFail");}async[Mt="onInit"](e,...r){await e.transition("CREATED","INITIALIZED");}async[kt="onBeforeExecute"](e,...r){await e.transition("INITIALIZED","EXECUTING");}async[$t="onExecute"](...e){}async[Dt="onAfterExecute"](...e){}async[Nt="onComplete"](e,...r){await e.transition("EXECUTING","COMPLETED");}async[bt="onFail"](e,r,...o){await e.transition("EXECUTING","FAILED");}async init(){await this.call("onInit",this.scope);}async execute(){if(!this.isProcessed)try{this.checkScopeInheritance();let e=new p("execute-command");this.scope.register(e),await new Promise(async(r,o)=>{try{let n=new A_Feature({name:"onBeforeExecute",component:this,scope:this.scope}),s=new A_Feature({name:"onExecute",component:this,scope:this.scope}),a=new A_Feature({name:"onAfterExecute",component:this,scope:this.scope});this.on("onComplete",()=>{n.interrupt(),s.interrupt(),a.interrupt(),r();}),await n.process(this.scope),await s.process(this.scope),await a.process(this.scope),this._origin==="invoked"&&await this.complete(),r();}catch(n){o(n);}});}catch(e){let r=e instanceof A_Error?e:new P({title:P.ExecutionError,description:`An error occurred while executing command "${this.aseid.toString()}".`,originalError:e});await this.fail(r);}}async complete(e){this.isProcessed||(this._status="COMPLETED",this._result=e,await this.call("onComplete",this.scope),this.scope.destroy());}async fail(e){this.isProcessed||(this._status="FAILED",e&&(this._error=e,this.scope.register(e)),await this.call("onFail",this.scope),this.scope.destroy());}on(e,r){this._listeners.has(e)||this._listeners.set(e,new Set),this._listeners.get(e).add(r);}off(e,r){this._listeners.get(e)?.delete(r);}emit(e){this._listeners.get(e)?.forEach(async r=>{r(this);});}fromNew(e){super.fromNew(e),this._origin="invoked",this._executionScope=new A_Scope({name:`A-Command-Execution-Scope-${this.aseid.toString()}`,components:[O]}),this._createdAt=new Date,this._params=e,this._status="CREATED";}fromJSON(e){super.fromJSON(e),this._origin="serialized",this._executionScope=new A_Scope({name:`A-Command-Execution-Scope-${this.aseid.toString()}`,components:[O]}),e.createdAt&&(this._createdAt=new Date(e.createdAt)),e.startedAt&&(this._startTime=new Date(e.startedAt)),e.endedAt&&(this._endTime=new Date(e.endedAt)),this._params=e.params,this._status=e.status,e.error&&(this._error=new P(e.error)),e.result&&(this._result=e.result);}toJSON(){return {...super.toJSON(),code:this.code,status:this._status,params:this._params,createdAt:this._createdAt.toISOString(),startedAt:this._startTime?this._startTime.toISOString():void 0,endedAt:this._endTime?this._endTime.toISOString():void 0,duration:this.duration,idleTime:this.idleTime,result:this.result,error:this.error?this.error.toJSON():void 0}}checkScopeInheritance(){let e;try{e=A_Context.scope(this);}catch(r){throw new P({title:P.CommandScopeBindingError,description:`Command ${this.aseid.toString()} is not bound to any context scope. Ensure the command is properly registered within a context before execution.`,originalError:r})}this.scope.isInheritedFrom(A_Context.scope(this))||this.scope.inherit(A_Context.scope(this));}};i(u,"A_Command"),l([A_Feature.Extend(),c(0,A_Inject(R)),c(1,A_Inject(C))],u.prototype,Bt,1),l([A_Feature.Extend(),c(0,A_Inject(R))],u.prototype,Ut,1),l([A_Feature.Extend(),c(0,A_Inject(R))],u.prototype,zt,1),l([A_Feature.Extend(),c(0,A_Inject(R))],u.prototype,Gt,1),l([A_Feature.Extend(),c(0,A_Inject(R)),c(1,A_Inject(A_Error))],u.prototype,Ft,1),l([A_Feature.Extend(),c(0,A_Inject(O))],u.prototype,Mt,1),l([A_Feature.Extend({after:/.*/}),c(0,A_Dependency.Required()),c(0,A_Inject(O))],u.prototype,kt,1),l([A_Feature.Extend()],u.prototype,$t,1),l([A_Feature.Extend()],u.prototype,Dt,1),l([A_Feature.Extend({after:/.*/}),c(0,A_Inject(O))],u.prototype,Nt,1),l([A_Feature.Extend({after:/.*/}),c(0,A_Dependency.Required()),c(0,A_Inject(O)),c(1,A_Inject(p))],u.prototype,bt,1);var we=u;var xe=class xe{constructor(t){this.logger=t;this._initialized=false;}get isInitialized(){return this._initialized}async get(){return this._initialized||await this.init(),this._fs}async init(){try{A_Context.environment==="server"?await this.initServer():this.initBrowser(),this._initialized=!0;}catch{this.initBrowser(),this._initialized=true;}}async initServer(){this._fs=await import('fs');}initBrowser(){this._fs={readFileSync:i((t,e)=>(this.logger.warning("fs.readFileSync not available in browser environment"),""),"readFileSync"),existsSync:i(t=>(this.logger.warning("fs.existsSync not available in browser environment"),false),"existsSync"),createReadStream:i(t=>(this.logger.warning("fs.createReadStream not available in browser environment"),null),"createReadStream")};}};i(xe,"A_FSPolyfillClass");var ie=xe;var Re=class Re{constructor(t){this.logger=t;this._initialized=false;}get isInitialized(){return this._initialized}async get(t){return this._initialized||(this._fsPolyfill=t,await this.init()),this._crypto}async init(){try{A_Context.environment==="server"?await this.initServer():this.initBrowser(),this._initialized=!0;}catch{this.initBrowser(),this._initialized=true;}}async initServer(){let t=await import('crypto');this._crypto={createTextHash:i((e,r="sha384")=>Promise.resolve(`${r}-${t.createHash(r).update(e).digest("base64")}`),"createTextHash"),createFileHash:i((e,r="sha384")=>new Promise(async(o,n)=>{try{if(!this._fsPolyfill)throw new Error("FS polyfill is required for file hashing");let s=t.createHash(r),a=this._fsPolyfill.createReadStream(e);a.on("data",d=>s.update(d)),a.on("end",()=>o(`${r}-${s.digest("base64")}`)),a.on("error",d=>n(d));}catch(s){n(s);}}),"createFileHash")};}initBrowser(){this._crypto={createFileHash:i(()=>(this.logger.warning("File hash not available in browser environment"),Promise.resolve("")),"createFileHash"),createTextHash:i((t,e="SHA-384")=>new Promise(async(r,o)=>{try{if(!crypto.subtle)throw new Error("SubtleCrypto not available");let s=new TextEncoder().encode(t),a=await crypto.subtle.digest(e,s),d=Array.from(new Uint8Array(a)),L=btoa(String.fromCharCode(...d));r(`${e}-${L}`);}catch(n){o(n);}}),"createTextHash")};}};i(Re,"A_CryptoPolyfillClass");var ne=Re;var Pe=class Pe{constructor(t){this.logger=t;this._initialized=false;}get isInitialized(){return this._initialized}async get(){return this._initialized||await this.init(),this._http}async init(){try{A_Context.environment==="server"?await this.initServer():this.initBrowser(),this._initialized=!0;}catch{this.initBrowser(),this._initialized=true;}}async initServer(){let t=await import('http');this._http={request:t.request,get:t.get,createServer:t.createServer};}initBrowser(){this._http={request:i((t,e)=>(this.logger.warning("http.request not available in browser/test environment, use fetch instead"),this.createMockRequest(t,e,false)),"request"),get:i((t,e)=>(this.logger.warning("http.get not available in browser/test environment, use fetch instead"),this.createMockRequest(typeof t=="string"?{hostname:t}:t,e,false)),"get"),createServer:i(()=>(this.logger.error("http.createServer not available in browser/test environment"),null),"createServer")};}createMockRequest(t,e,r=false){return {end:i(()=>{if(e){let n={statusCode:200,headers:{},on:i((s,a)=>{s==="data"?setTimeout(()=>a("mock data"),0):s==="end"&&setTimeout(()=>a(),0);},"on"),pipe:i(s=>{s.write&&s.write("mock data"),s.end&&s.end();},"pipe")};setTimeout(()=>e(n),0);}},"end"),write:i(n=>{},"write"),on:i((n,s)=>{},"on")}}};i(Pe,"A_HttpPolyfillClass");var se=Pe;var Oe=class Oe{constructor(t){this.logger=t;this._initialized=false;}get isInitialized(){return this._initialized}async get(){return this._initialized||await this.init(),this._https}async init(){try{A_Context.environment==="server"?await this.initServer():this.initBrowser(),this._initialized=!0;}catch{this.initBrowser(),this._initialized=true;}}async initServer(){let t=await import('https');this._https={request:t.request,get:t.get,createServer:t.createServer};}initBrowser(){this._https={request:i((t,e)=>(this.logger.warning("https.request not available in browser/test environment, use fetch instead"),this.createMockRequest(t,e,true)),"request"),get:i((t,e)=>(this.logger.warning("https.get not available in browser/test environment, use fetch instead"),this.createMockRequest(typeof t=="string"?{hostname:t}:t,e,true)),"get"),createServer:i(()=>(this.logger.error("https.createServer not available in browser/test environment"),null),"createServer")};}createMockRequest(t,e,r=true){return {end:i(()=>{if(e){let n={statusCode:200,headers:{},on:i((s,a)=>{s==="data"?setTimeout(()=>a("mock data"),0):s==="end"&&setTimeout(()=>a(),0);},"on"),pipe:i(s=>{s.write&&s.write("mock data"),s.end&&s.end();},"pipe")};setTimeout(()=>e(n),0);}},"end"),write:i(n=>{},"write"),on:i((n,s)=>{},"on")}}};i(Oe,"A_HttpsPolyfillClass");var ae=Oe;var Ie=class Ie{constructor(t){this.logger=t;this._initialized=false;}get isInitialized(){return this._initialized}async get(){return this._initialized||await this.init(),this._path}async init(){try{A_Context.environment==="server"?await this.initServer():this.initBrowser(),this._initialized=!0;}catch{this.initBrowser(),this._initialized=true;}}async initServer(){this._path=await import('path');}initBrowser(){this._path={join:i((...t)=>t.join("/").replace(/\/+/g,"/"),"join"),resolve:i((...t)=>{let e="";for(let r of t)r.startsWith("/")?e=r:e=this._path.join(e,r);return e||"/"},"resolve"),dirname:i(t=>t.split("/").slice(0,-1).join("/")||"/","dirname"),basename:i((t,e)=>{let r=t.split("/").pop()||"";return e&&r.endsWith(e)?r.slice(0,-e.length):r},"basename"),extname:i(t=>{let e=t.split(".");return e.length>1?"."+e.pop():""},"extname"),relative:i((t,e)=>e.replace(t,"").replace(/^\//,""),"relative"),normalize:i(t=>t.replace(/\/+/g,"/").replace(/\/$/,"")||"/","normalize"),isAbsolute:i(t=>t.startsWith("/")||/^[a-zA-Z]:/.test(t),"isAbsolute"),parse:i(t=>{let e=this._path.extname(t),r=this._path.basename(t),o=this._path.basename(t,e);return {root:"/",dir:this._path.dirname(t),base:r,ext:e,name:o}},"parse"),format:i(t=>this._path.join(t.dir||"",t.base||""),"format"),sep:"/",delimiter:":"};}};i(Ie,"A_PathPolyfillClass");var ce=Ie;var Le=class Le{constructor(t){this.logger=t;this._initialized=false;}get isInitialized(){return this._initialized}async get(){return this._initialized||await this.init(),this._url}async init(){try{A_Context.environment==="server"?await this.initServer():this.initBrowser(),this._initialized=!0;}catch{this.initBrowser(),this._initialized=true;}}async initServer(){let t=await import('url');this._url={parse:t.parse,format:t.format,resolve:t.resolve,URL:t.URL||globalThis.URL,URLSearchParams:t.URLSearchParams||globalThis.URLSearchParams};}initBrowser(){this._url={parse:i(t=>{try{let e=new URL(t);return {protocol:e.protocol,hostname:e.hostname,port:e.port,pathname:e.pathname,search:e.search,hash:e.hash,host:e.host,href:e.href}}catch{return {}}},"parse"),format:i(t=>{try{return new URL("",t.href||`${t.protocol}//${t.host}${t.pathname}${t.search}${t.hash}`).href}catch{return ""}},"format"),resolve:i((t,e)=>{try{return new URL(e,t).href}catch{return e}},"resolve"),URL:globalThis.URL,URLSearchParams:globalThis.URLSearchParams};}};i(Le,"A_UrlPolyfillClass");var le=Le;var be=class be{constructor(t){this.logger=t;this._initialized=false;}get isInitialized(){return this._initialized}async get(){return this._initialized||await this.init(),this._buffer}async init(){try{A_Context.environment==="server"?await this.initServer():this.initBrowser(),this._initialized=!0;}catch{this.initBrowser(),this._initialized=true;}}async initServer(){let t=await import('buffer');this._buffer={from:t.Buffer.from,alloc:t.Buffer.alloc,allocUnsafe:t.Buffer.allocUnsafe,isBuffer:t.Buffer.isBuffer,concat:t.Buffer.concat};}initBrowser(){this._buffer={from:i((t,e)=>typeof t=="string"?new TextEncoder().encode(t):new Uint8Array(t),"from"),alloc:i((t,e)=>{let r=new Uint8Array(t);return e!==void 0&&r.fill(e),r},"alloc"),allocUnsafe:i(t=>new Uint8Array(t),"allocUnsafe"),isBuffer:i(t=>t instanceof Uint8Array||t instanceof ArrayBuffer,"isBuffer"),concat:i((t,e)=>{let r=e||t.reduce((s,a)=>s+a.length,0),o=new Uint8Array(r),n=0;for(let s of t)o.set(s,n),n+=s.length;return o},"concat")};}};i(be,"A_BufferPolyfillClass");var pe=be;var Ne=class Ne{constructor(t){this.logger=t;this._initialized=false;}get isInitialized(){return this._initialized}async get(){return this._initialized||await this.init(),this._process}async init(){try{A_Context.environment==="server"?this.initServer():this.initBrowser(),this._initialized=!0;}catch{this.initBrowser(),this._initialized=true;}}initServer(){this._process={env:process.env,argv:process.argv,platform:process.platform,version:process.version,versions:process.versions,cwd:process.cwd,exit:process.exit,nextTick:process.nextTick};}initBrowser(){this._process={env:{NODE_ENV:"browser",...globalThis.process?.env||{}},argv:["browser"],platform:"browser",version:"browser",versions:{node:"browser"},cwd:i(()=>"/","cwd"),exit:i(t=>{throw this.logger.warning("process.exit not available in browser"),new Error(`Process exit with code ${t}`)},"exit"),nextTick:i((t,...e)=>{setTimeout(()=>t(...e),0);},"nextTick")};}};i(Ne,"A_ProcessPolyfillClass");var _e=Ne;var m=class extends A_Component{constructor(e){super();this.logger=e;this._initializing=null;}get ready(){return this._initialized||(this._initialized=this._loadInternal()),this._initialized}async load(){await this.ready;}async attachToWindow(){A_Context.environment==="browser"&&(globalThis.A_Polyfill=this,globalThis.process={env:{NODE_ENV:"production"},cwd:i(()=>"/","cwd")},globalThis.__dirname="/");}async _loadInternal(){this._fsPolyfill=new ie(this.logger),this._cryptoPolyfill=new ne(this.logger),this._httpPolyfill=new se(this.logger),this._httpsPolyfill=new ae(this.logger),this._pathPolyfill=new ce(this.logger),this._urlPolyfill=new le(this.logger),this._bufferPolyfill=new pe(this.logger),this._processPolyfill=new _e(this.logger),await this._fsPolyfill.get(),await this._cryptoPolyfill.get(await this._fsPolyfill.get()),await this._httpPolyfill.get(),await this._httpsPolyfill.get(),await this._pathPolyfill.get(),await this._urlPolyfill.get(),await this._bufferPolyfill.get(),await this._processPolyfill.get();}async fs(){return await this.ready,await this._fsPolyfill.get()}async crypto(){return await this.ready,await this._cryptoPolyfill.get()}async http(){return await this.ready,await this._httpPolyfill.get()}async https(){return await this.ready,await this._httpsPolyfill.get()}async path(){return await this.ready,await this._pathPolyfill.get()}async url(){return await this.ready,await this._urlPolyfill.get()}async buffer(){return await this.ready,await this._bufferPolyfill.get()}async process(){return await this.ready,await this._processPolyfill.get()}};i(m,"A_Polyfill"),l([A_Concept.Load()],m.prototype,"load",1),l([A_Concept.Load()],m.prototype,"attachToWindow",1),m=l([c(0,A_Inject(C))],m);var de=class de extends A_Error{};i(de,"A_ConfigError"),de.InitializationError="A-Config Initialization Error";var D=de;var g=class extends A_Component{constructor(e){super();this.polyfill=e;}async attachContext(e,r,o){o||(o=new h({variables:[...A_CONSTANTS__DEFAULT_ENV_VARIABLES_ARRAY,...B],defaults:{}}),e.scope.register(o));let n=await this.getProjectRoot();o.set("A_CONCEPT_ROOT_FOLDER",n);}async initialize(e){let r=await this.read([...e.CONFIG_PROPERTIES,...A_CONSTANTS__DEFAULT_ENV_VARIABLES_ARRAY,...B]);e.set(r);}resolve(e){return e}async read(e=[]){return {}}async getProjectRoot(e=__dirname){return process.cwd()}};i(g,"ConfigReader"),l([A_Concept.Load(),c(0,A_Inject(A_Container)),c(1,A_Inject(A_Feature)),c(2,A_Inject(h))],g.prototype,"attachContext",1),l([A_Concept.Load(),c(0,A_Inject(h))],g.prototype,"initialize",1),g=l([c(0,A_Inject(m))],g);var De=class De extends g{constructor(){super(...arguments);this.FileData=new Map;}getConfigurationProperty_File_Alias(e){return A_FormatterHelper.toCamelCase(e)}resolve(e){return this.FileData.get(this.getConfigurationProperty_File_Alias(e))}async read(e){let r=await this.polyfill.fs();try{let o=r.readFileSync(`${A_Context.concept}.conf.json`,"utf8"),n=JSON.parse(o);return this.FileData=new Map(Object.entries(n)),n}catch{return {}}}};i(De,"FileConfigReader");var W=De;var me=class me extends g{async readEnvFile(t,e,r){let o=await e.fs();o.existsSync(".env")&&o.readFileSync(`${t.get("A_CONCEPT_ROOT_FOLDER")}/.env`,"utf-8").split(`
|
|
44
|
+
`).forEach(n=>{let[s,a]=n.split("=");s&&a&&(process.env[s.trim()]=a.trim());});}getConfigurationProperty_ENV_Alias(t){return A_FormatterHelper.toUpperSnakeCase(t)}resolve(t){return process.env[this.getConfigurationProperty_ENV_Alias(t)]}async read(t=[]){let e=[...t,...Object.keys(process.env)],r={};return e.forEach(o=>{r[o]=this.resolve(o);}),r}};i(me,"ENVConfigReader"),l([A_Concept.Load({before:["ENVConfigReader.initialize"]}),c(0,A_Inject(h)),c(1,A_Inject(m)),c(2,A_Inject(A_Feature))],me.prototype,"readEnvFile",1);var j=me;var he=class he extends A_Container{async prepare(t){if(!this.scope.has(h)){let r=new h({variables:[...A_CONSTANTS__DEFAULT_ENV_VARIABLES_ARRAY,...B],defaults:{}});this.scope.register(r);}let e=await t.fs();try{switch(!0){case(A_Context.environment==="server"&&!!e.existsSync(`${A_Context.concept}.conf.json`)):this.reader=this.scope.resolve(W);break;case(A_Context.environment==="server"&&!e.existsSync(`${A_Context.concept}.conf.json`)):this.reader=this.scope.resolve(j);break;case A_Context.environment==="browser":this.reader=this.scope.resolve(j);break;default:throw new D(D.InitializationError,`Environment ${A_Context.environment} is not supported`)}}catch(r){if(r instanceof A_ScopeError)throw new D({title:D.InitializationError,description:`Failed to initialize A_ConfigLoader. Reader not found for environment ${A_Context.environment}`,originalError:r})}}};i(he,"A_ConfigLoader"),l([A_Concept.Load({before:/.*/}),c(0,A_Inject(m))],he.prototype,"prepare",1);var ke=he;var hr=(M=>M)(hr||{});var fe=class fe extends A_Error{};i(fe,"A_ManifestError"),fe.ManifestInitializationError="A-Manifest Initialization Error";var $=fe;var Me=class Me{constructor(t,e,r,o=false){this.manifest=t;this.component=e;this.method=r;this.checkExclusion=o;}for(t){let e=this.manifest.internal_checkAccess({component:this.component,method:this.method,target:t});return this.checkExclusion?!e:e}};i(Me,"A_ManifestChecker");var q=Me;var Ge=class Ge extends A_Fragment{constructor(e=[]){super({name:"A-Manifest"});this.rules=[];this.prepare(e);}prepare(e){if(!A_TypeGuards.isArray(e))throw new $($.ManifestInitializationError,"A-Manifest configuration should be an array of configurations");for(let r of e)this.processConfigItem(r);}processConfigItem(e){if(!A_TypeGuards.isComponentConstructor(e.component))throw new $($.ManifestInitializationError,"A-Manifest configuration item should be a A-Component constructor");let r=this.constructorToRegex(e.component);if(e.apply||e.exclude){let o=/.*/;this.rules.push({componentRegex:r,methodRegex:o,applyRegex:e.apply?this.allowedComponentsToRegex(e.apply):void 0,excludeRegex:e.exclude?this.allowedComponentsToRegex(e.exclude):void 0});}if(e.methods&&e.methods.length>0)for(let o of e.methods){let n=this.methodToRegex(o.method);this.rules.push({componentRegex:r,methodRegex:n,applyRegex:o.apply?this.allowedComponentsToRegex(o.apply):void 0,excludeRegex:o.exclude?this.allowedComponentsToRegex(o.exclude):void 0});}}constructorToRegex(e){return new RegExp(`^${this.escapeRegex(e.name)}$`)}methodToRegex(e){return e instanceof RegExp?e:new RegExp(`^${this.escapeRegex(e)}$`)}allowedComponentsToRegex(e){if(e instanceof RegExp)return e;let r=e.map(o=>this.escapeRegex(o.name));return new RegExp(`^(${r.join("|")})$`)}escapeRegex(e){return e.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}configItemToRegexp(e){return this.constructorToRegex(e)}ID(e,r){return `${e.name}.${r}`}isAllowed(e,r){let o=typeof e=="function"?e:e.constructor;return new q(this,o,r)}internal_checkAccess(e){let r=e.component.name,o=e.method,n=e.target.name,s=this.rules.filter(a=>a.componentRegex.test(r)&&a.methodRegex.test(o)).sort((a,d)=>{let L=a.methodRegex.source===".*",b=d.methodRegex.source===".*";return L&&!b?1:!L&&b?-1:0});if(s.length===0)return true;for(let a of s){if(a.excludeRegex&&a.excludeRegex.test(n))return false;if(a.applyRegex)return a.applyRegex.test(n)}return true}isExcluded(e,r){let o=typeof e=="function"?e:e.constructor;return new q(this,o,r,true)}};i(Ge,"A_Manifest");var Fe=Ge;var ze=class ze extends A_Fragment{set(t,e){super.set(t,e);}get(t){return super.get(t)}};i(ze,"A_MemoryContext");var v=ze;var w=class w extends A_Error{};i(w,"A_MemoryError"),w.MemoryInitializationError="Memory initialization error",w.MemoryDestructionError="Memory destruction error",w.MemoryGetError="Memory GET operation failed",w.MemorySetError="Memory SET operation failed",w.MemoryDropError="Memory DROP operation failed",w.MemoryClearError="Memory CLEAR operation failed",w.MemoryHasError="Memory HAS operation failed",w.MemorySerializeError="Memory toJSON operation failed";var _=w;var Tr,Ar,Sr,Cr,vr,wr,xr,Rr,Pr,S=class S extends A_Component{get ready(){return this._ready||(this._ready=this.init()),this._ready}async[Pr="onError"](...t){}async[Rr="onExpire"](...t){}async[xr="onInit"](t,...e){t||(t=new v,A_Context.scope(this).register(t));}async[wr="onDestroy"](t,...e){t.clear();}async[vr="onGet"](t,e,...r){t.succeed(e.get(t.params.key));}async[Cr="onHas"](t,e,...r){t.succeed(e.has(t.params.key));}async[Sr="onSet"](t,e,...r){e.set(t.params.key,t.params.value);}async[Ar="onDrop"](t,e,...r){e.drop(t.params.key);}async[Tr="onClear"](t,e,...r){e.clear();}async init(){if(this._ready)return this._ready;let t=new A_Scope({name:"A-Memory-Init-Scope"}).inherit(A_Context.scope(this));try{await this.call("onInit",t);}catch(e){let r=new _({title:_.MemoryInitializationError,description:"An error occurred during memory initialization",originalError:e});throw t.register(r),await this.call("onError",t),t.destroy(),r}}async destroy(){let t=new A_Scope({name:"A-Memory-Destroy-Scope"}).inherit(A_Context.scope(this));try{this._ready=void 0,await this.call("onDestroy",t);}catch(e){let r=new _({title:_.MemoryDestructionError,description:"An error occurred during memory destruction",originalError:e});throw t.register(r),await this.call("onError",t),t.destroy(),r}}async get(t){let e=new p("get",{key:t}),r=new A_Scope({name:"A-Memory-Get-Operation-Scope",fragments:[e]});try{return await this.call("onGet",r),r.destroy(),e.result}catch(o){let n=new _({title:_.MemoryGetError,description:`An error occurred while getting the value for key "${String(t)}"`,originalError:o});throw r.register(n),await this.call("onError",r),r.destroy(),n}}async has(t){let e=new p("has",{key:t}),r=new A_Scope({name:"A-Memory-Has-Operation-Scope",fragments:[e]});try{return await this.call("onHas",r),r.destroy(),e.result}catch(o){let n=new _({title:_.MemoryHasError,description:`An error occurred while checking existence for key "${String(t)}"`,originalError:o});throw r.register(n),await this.call("onError",r),r.destroy(),n}}async set(t,e){let r=new p("set",{key:t,value:e}),o=new A_Scope({name:"A-Memory-Set-Operation-Scope",fragments:[r]});try{await this.call("onSet",o);}catch(n){let s=new _({title:_.MemorySetError,description:`An error occurred while setting the value for key "${String(t)}"`,originalError:n});throw o.register(s),await this.call("onError",o),o.destroy(),s}}async drop(t){let e=new p("drop",{key:t}),r=new A_Scope({name:"A-Memory-Drop-Operation-Scope",fragments:[e]});try{await this.call("onDrop",r);}catch(o){let n=new _({title:_.MemoryDropError,description:`An error occurred while dropping the value for key "${String(t)}"`,originalError:o});throw r.register(n),await this.call("onError",r),r.destroy(),n}}async clear(){let t=new p("clear"),e=new A_Scope({name:"A-Memory-Clear-Operation-Scope",fragments:[t]});try{await this.call("onClear",e);}catch(r){let o=new _({title:_.MemoryClearError,description:"An error occurred while clearing the memory",originalError:r});throw e.register(o),await this.call("onError",e),e.destroy(),o}}async toJSON(){let t=new p("serialize"),e=new A_Scope({name:"A-Memory-Serialize-Operation-Scope",fragments:[t]});try{return await this.call("onSerialize",e),t.result}catch(r){let o=new _({title:_.MemorySerializeError,description:"An error occurred while serializing the memory",originalError:r});throw e.register(o),await this.call("onError",e),e.destroy(),o}}};i(S,"A_Memory"),l([A_Feature.Extend()],S.prototype,Pr,1),l([A_Feature.Extend()],S.prototype,Rr,1),l([A_Feature.Extend(),c(0,A_Inject(v))],S.prototype,xr,1),l([A_Feature.Extend(),c(0,A_Inject(v))],S.prototype,wr,1),l([A_Feature.Extend(),c(0,A_Dependency.Required()),c(0,A_Inject(p)),c(1,A_Inject(v))],S.prototype,vr,1),l([A_Feature.Extend(),c(0,A_Dependency.Required()),c(0,A_Inject(p)),c(1,A_Inject(v))],S.prototype,Cr,1),l([A_Feature.Extend(),c(0,A_Dependency.Required()),c(0,A_Inject(p)),c(1,A_Inject(v))],S.prototype,Sr,1),l([A_Feature.Extend(),c(0,A_Dependency.Required()),c(0,A_Inject(p)),c(1,A_Inject(v))],S.prototype,Ar,1),l([A_Feature.Extend(),c(0,A_Dependency.Required()),c(0,A_Inject(p)),c(1,A_Inject(v))],S.prototype,Tr,1);var Be=S;var Ye=class Ye{constructor(){this.promise=new Promise((t,e)=>{this.resolveFn=t,this.rejectFn=e;});}resolve(t){this.resolveFn(t);}reject(t){this.rejectFn(t);}};i(Ye,"A_Deferred");var ee=Ye;var Ve=class Ve{constructor(t,e,r){this.config={resolveOnClear:false};r&&(this.config={...this.config,...r}),this.deferred=new ee,this.timeout=setTimeout(()=>e().then((...o)=>this.deferred.resolve(...o)).catch((...o)=>this.deferred.reject(...o)),t);}get promise(){return this.deferred.promise}clear(){this.timeout&&(clearTimeout(this.timeout),this.config.resolveOnClear?this.deferred.resolve(void 0):this.deferred.reject(new A_Error("Timeout Cleared")));}};i(Ve,"A_ScheduleObject");var H=Ve;var qe=class qe extends A_Component{async schedule(t,e,r){let o=A_TypeGuards.isString(t)?new Date(t).getTime():t;return new H(o-Date.now(),e,r)}async delay(t,e,r){return new H(t,e,r)}};i(qe,"A_Schedule");var je=qe;export{yo as A_CONSTANTS__CONFIG_ENV_VARIABLES,B as A_CONSTANTS__CONFIG_ENV_VARIABLES_ARRAY,Te as A_Channel,F as A_ChannelError,_t as A_ChannelFeatures,dt as A_ChannelRequestStatuses,we as A_Command,P as A_CommandError,ut as A_CommandFeatures,ft as A_CommandTransitions,ht as A_Command_Status,h as A_Config,D as A_ConfigError,ke as A_ConfigLoader,ee as A_Deferred,C as A_Logger,Fe as A_Manifest,q as A_ManifestChecker,$ as A_ManifestError,Be as A_Memory,m as A_Polyfill,je as A_Schedule,H as A_ScheduleObject,hr as A_TYPES__ConfigFeature,g as ConfigReader,j as ENVConfigReader,W as FileConfigReader};//# sourceMappingURL=index.mjs.map
|
|
2373
45
|
//# sourceMappingURL=index.mjs.map
|