@adaas/a-utils 0.1.13 → 0.1.15

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.js CHANGED
@@ -13,27 +13,346 @@ var __decorateClass = (decorators, target, key, kind) => {
13
13
  return result;
14
14
  };
15
15
  var __decorateParam = (index, decorator) => (target, key) => decorator(target, key, index);
16
+
17
+ // src/lib/A-Channel/A-Channel.constants.ts
18
+ var A_ChannelFeatures = /* @__PURE__ */ ((A_ChannelFeatures2) => {
19
+ A_ChannelFeatures2["onTimeout"] = "onTimeout";
20
+ A_ChannelFeatures2["onRetry"] = "onRetry";
21
+ A_ChannelFeatures2["onCircuitBreakerOpen"] = "onCircuitBreakerOpen";
22
+ A_ChannelFeatures2["onCache"] = "onCache";
23
+ A_ChannelFeatures2["onConnect"] = "onConnect";
24
+ A_ChannelFeatures2["onDisconnect"] = "onDisconnect";
25
+ A_ChannelFeatures2["onBeforeRequest"] = "onBeforeRequest";
26
+ A_ChannelFeatures2["onRequest"] = "onRequest";
27
+ A_ChannelFeatures2["onAfterRequest"] = "onAfterRequest";
28
+ A_ChannelFeatures2["onError"] = "onError";
29
+ A_ChannelFeatures2["onSend"] = "onSend";
30
+ A_ChannelFeatures2["onConsume"] = "onConsume";
31
+ return A_ChannelFeatures2;
32
+ })(A_ChannelFeatures || {});
33
+ var A_ChannelRequestStatuses = /* @__PURE__ */ ((A_ChannelRequestStatuses2) => {
34
+ A_ChannelRequestStatuses2["PENDING"] = "PENDING";
35
+ A_ChannelRequestStatuses2["SUCCESS"] = "SUCCESS";
36
+ A_ChannelRequestStatuses2["FAILED"] = "FAILED";
37
+ return A_ChannelRequestStatuses2;
38
+ })(A_ChannelRequestStatuses || {});
39
+
40
+ // src/lib/A-Channel/A-ChannelRequest.context.ts
41
+ var A_ChannelRequest = class extends aConcept.A_Fragment {
42
+ constructor(params = {}) {
43
+ super();
44
+ this._errors = /* @__PURE__ */ new Set();
45
+ this._status = "PENDING" /* PENDING */;
46
+ this._params = params;
47
+ }
48
+ /**
49
+ * Returns the status of the request
50
+ */
51
+ get status() {
52
+ return this._status;
53
+ }
54
+ /**
55
+ * Returns the parameters of the request
56
+ */
57
+ get failed() {
58
+ return this._errors.size > 0;
59
+ }
60
+ /**
61
+ * Returns the Params of the Request
62
+ */
63
+ get params() {
64
+ return this._params;
65
+ }
66
+ /**
67
+ * Returns the Result of the Request
68
+ */
69
+ get data() {
70
+ return this._result;
71
+ }
72
+ get errors() {
73
+ return this._errors.size > 0 ? this._errors : void 0;
74
+ }
75
+ // ==========================================================
76
+ // ==================== Mutations ===========================
77
+ // ==========================================================
78
+ /**
79
+ * Adds an error to the context
80
+ *
81
+ * @param error
82
+ */
83
+ fail(error) {
84
+ this._status = "FAILED" /* FAILED */;
85
+ this._errors.add(error);
86
+ }
87
+ /**
88
+ * Sets the result of the request
89
+ *
90
+ * @param result
91
+ */
92
+ succeed(result) {
93
+ this._status = "SUCCESS" /* SUCCESS */;
94
+ this._result = result;
95
+ }
96
+ /**
97
+ * Serializes the context to a JSON object
98
+ *
99
+ * @returns
100
+ */
101
+ toJSON() {
102
+ return {
103
+ params: this._params,
104
+ result: this._result,
105
+ status: this._status,
106
+ errors: this.errors ? Array.from(this._errors).map((err) => err.toString()) : void 0
107
+ };
108
+ }
109
+ };
110
+
111
+ // src/lib/A-Channel/A-Channel.error.ts
16
112
  var A_ChannelError = class extends aConcept.A_Error {
113
+ /**
114
+ * Channel Error allows to keep track of errors within a channel if something goes wrong
115
+ *
116
+ *
117
+ * @param originalError
118
+ * @param context
119
+ */
120
+ constructor(originalError, context) {
121
+ if (aConcept.A_TypeGuards.isString(context))
122
+ super(originalError, context);
123
+ else
124
+ super(originalError);
125
+ if (context instanceof A_ChannelRequest)
126
+ this._context = context;
127
+ }
128
+ /***
129
+ * Returns Context of the error
130
+ */
131
+ get context() {
132
+ return this._context;
133
+ }
17
134
  };
135
+ // ==========================================================
136
+ // ==================== Error Types =========================
137
+ // ==========================================================
18
138
  A_ChannelError.MethodNotImplemented = "A-Channel Method Not Implemented";
19
139
 
140
+ // src/lib/A-Config/A-Config.constants.ts
141
+ var A_CONSTANTS__CONFIG_ENV_VARIABLES = {};
142
+ var A_CONSTANTS__CONFIG_ENV_VARIABLES_ARRAY = [];
143
+
144
+ // src/lib/A-Config/A-Config.context.ts
145
+ var A_Config = class extends aConcept.A_Fragment {
146
+ constructor(config) {
147
+ super({
148
+ name: "A_Config"
149
+ });
150
+ this.VARIABLES = /* @__PURE__ */ new Map();
151
+ this.DEFAULT_ALLOWED_TO_READ_PROPERTIES = [
152
+ ...aConcept.A_CONSTANTS__DEFAULT_ENV_VARIABLES_ARRAY,
153
+ ...A_CONSTANTS__CONFIG_ENV_VARIABLES_ARRAY
154
+ ];
155
+ this.config = aConcept.A_CommonHelper.deepCloneAndMerge(config, {
156
+ strict: false,
157
+ defaults: {},
158
+ variables: aConcept.A_CONSTANTS__DEFAULT_ENV_VARIABLES_ARRAY
159
+ });
160
+ this.CONFIG_PROPERTIES = this.config.variables ? this.config.variables : [];
161
+ this.config.variables.forEach((variable) => {
162
+ this.VARIABLES.set(
163
+ aConcept.A_FormatterHelper.toUpperSnakeCase(variable),
164
+ this.config.defaults[variable]
165
+ );
166
+ });
167
+ }
168
+ /**
169
+ * This method is used to get the configuration property by name
170
+ *
171
+ * @param property
172
+ * @returns
173
+ */
174
+ get(property) {
175
+ if (this.CONFIG_PROPERTIES.includes(property) || this.DEFAULT_ALLOWED_TO_READ_PROPERTIES.includes(property) || !this.config.strict)
176
+ return this.VARIABLES.get(aConcept.A_FormatterHelper.toUpperSnakeCase(property));
177
+ throw new Error("Property not exists or not allowed to read");
178
+ }
179
+ set(property, value) {
180
+ const array = Array.isArray(property) ? property : typeof property === "string" ? [{ property, value }] : Object.keys(property).map((key) => ({
181
+ property: key,
182
+ value: property[key]
183
+ }));
184
+ for (const { property: property2, value: value2 } of array) {
185
+ let targetValue = value2 ? value2 : this.config?.defaults ? this.config.defaults[property2] : void 0;
186
+ this.VARIABLES.set(aConcept.A_FormatterHelper.toUpperSnakeCase(property2), targetValue);
187
+ }
188
+ }
189
+ };
190
+
191
+ // src/lib/A-Logger/A-Logger.component.ts
192
+ exports.A_Logger = class A_Logger extends aConcept.A_Component {
193
+ constructor(scope) {
194
+ super();
195
+ this.scope = scope;
196
+ this.colors = {
197
+ green: "32",
198
+ blue: "34",
199
+ red: "31",
200
+ yellow: "33",
201
+ gray: "90",
202
+ magenta: "35",
203
+ cyan: "36",
204
+ white: "37",
205
+ pink: "95"
206
+ };
207
+ this.config = this.scope.has(A_Config) ? this.scope.resolve(A_Config) : void 0;
208
+ }
209
+ get scopeLength() {
210
+ return this.scope.name.length;
211
+ }
212
+ compile(color, ...args) {
213
+ return [
214
+ `\x1B[${this.colors[color]}m[${this.scope.name}] |${this.getTime()}|`,
215
+ args.length > 1 ? `
216
+ ${" ".repeat(this.scopeLength + 3)}|-------------------------------` : "",
217
+ ...args.map((arg, i) => {
218
+ switch (true) {
219
+ case arg instanceof aConcept.A_Error:
220
+ return this.compile_A_Error(arg);
221
+ case arg instanceof Error:
222
+ return this.compile_Error(arg);
223
+ case typeof arg === "object":
224
+ return JSON.stringify(arg, null, 2).replace(/\n/g, `
225
+ ${" ".repeat(this.scopeLength + 3)}| `);
226
+ default:
227
+ return String(
228
+ (i > 0 || args.length > 1 ? "\n" : "") + arg
229
+ ).replace(/\n/g, `
230
+ ${" ".repeat(this.scopeLength + 3)}| `);
231
+ }
232
+ }),
233
+ args.length > 1 ? `
234
+ ${" ".repeat(this.scopeLength + 3)}|-------------------------------\x1B[0m` : "\x1B[0m"
235
+ ];
236
+ }
237
+ get allowedToLog() {
238
+ return this.config ? this.config.get("CONFIG_VERBOSE") !== void 0 && this.config.get("CONFIG_VERBOSE") !== "false" && this.config.get("CONFIG_VERBOSE") !== false : true;
239
+ }
240
+ log(param1, ...args) {
241
+ if (!this.allowedToLog)
242
+ return;
243
+ if (typeof param1 === "string" && this.colors[param1]) {
244
+ console.log(...this.compile(param1, ...args));
245
+ return;
246
+ } else {
247
+ console.log(...this.compile("blue", param1, ...args));
248
+ }
249
+ }
250
+ warning(...args) {
251
+ if (!this.allowedToLog)
252
+ return;
253
+ console.log(...this.compile("yellow", ...args));
254
+ }
255
+ error(...args) {
256
+ if (this.config && this.config.get("CONFIG_IGNORE_ERRORS"))
257
+ return;
258
+ return console.log(...this.compile("red", ...args));
259
+ }
260
+ log_A_Error(error) {
261
+ const time = this.getTime();
262
+ console.log(`\x1B[31m[${this.scope.name}] |${time}| ERROR ${error.code}
263
+ ${" ".repeat(this.scopeLength + 3)}| ${error.message}
264
+ ${" ".repeat(this.scopeLength + 3)}| ${error.description}
265
+ ${" ".repeat(this.scopeLength + 3)}|-------------------------------
266
+ ${" ".repeat(this.scopeLength + 3)}| ${error.stack?.split("\n").map((line, index) => index === 0 ? line : `${" ".repeat(this.scopeLength + 3)}| ${line}`).join("\n") || "No stack trace"}
267
+ ${" ".repeat(this.scopeLength + 3)}|-------------------------------
268
+ \x1B[0m` + (error.originalError ? `\x1B[31m${" ".repeat(this.scopeLength + 3)}| Wrapped From ${error.originalError.message}
269
+ ${" ".repeat(this.scopeLength + 3)}|-------------------------------
270
+ ${" ".repeat(this.scopeLength + 3)}| ${error.originalError.stack?.split("\n").map((line, index) => index === 0 ? line : `${" ".repeat(this.scopeLength + 3)}| ${line}`).join("\n") || "No stack trace"}
271
+ ${" ".repeat(this.scopeLength + 3)}|-------------------------------
272
+ \x1B[0m` : "") + (error.link ? `\x1B[31m${" ".repeat(this.scopeLength + 3)}| Read in docs: ${error.link}
273
+ ${" ".repeat(this.scopeLength + 3)}|-------------------------------
274
+ \x1B[0m` : ""));
275
+ }
276
+ compile_A_Error(error) {
277
+ this.getTime();
278
+ return `
279
+ ${" ".repeat(this.scopeLength + 3)}|-------------------------------
280
+ ${" ".repeat(this.scopeLength + 3)}| Error: | ${error.code}
281
+ ${" ".repeat(this.scopeLength + 3)}|-------------------------------
282
+ ${" ".repeat(this.scopeLength + 3)}|${" ".repeat(10)}| ${error.message}
283
+ ${" ".repeat(this.scopeLength + 3)}|${" ".repeat(10)}| ${error.description}
284
+ ${" ".repeat(this.scopeLength + 3)}|-------------------------------
285
+ ${" ".repeat(this.scopeLength + 3)}| ${error.stack?.split("\n").map((line, index) => index === 0 ? line : `${" ".repeat(this.scopeLength + 3)}| ${line}`).join("\n") || "No stack trace"}
286
+ ${" ".repeat(this.scopeLength + 3)}|-------------------------------` + (error.originalError ? `${" ".repeat(this.scopeLength + 3)}| Wrapped From ${error.originalError.message}
287
+ ${" ".repeat(this.scopeLength + 3)}|-------------------------------
288
+ ${" ".repeat(this.scopeLength + 3)}| ${error.originalError.stack?.split("\n").map((line, index) => index === 0 ? line : `${" ".repeat(this.scopeLength + 3)}| ${line}`).join("\n") || "No stack trace"}
289
+ ${" ".repeat(this.scopeLength + 3)}|-------------------------------` : "") + (error.link ? `${" ".repeat(this.scopeLength + 3)}| Read in docs: ${error.link}
290
+ ${" ".repeat(this.scopeLength + 3)}|-------------------------------` : "");
291
+ }
292
+ compile_Error(error) {
293
+ return JSON.stringify({
294
+ name: error.name,
295
+ message: error.message,
296
+ stack: error.stack?.split("\n").map((line, index) => index === 0 ? line : `${" ".repeat(this.scopeLength + 3)}| ${line}`).join("\n")
297
+ }, null, 2).replace(/\n/g, `
298
+ ${" ".repeat(this.scopeLength + 3)}| `).replace(/\\n/g, "\n");
299
+ }
300
+ getTime() {
301
+ const now = /* @__PURE__ */ new Date();
302
+ const minutes = String(now.getMinutes()).padStart(2, "0");
303
+ const seconds = String(now.getSeconds()).padStart(2, "0");
304
+ const milliseconds = String(now.getMilliseconds()).padStart(4, "0");
305
+ return `${minutes}:${seconds}:${milliseconds}`;
306
+ }
307
+ };
308
+ exports.A_Logger = __decorateClass([
309
+ __decorateParam(0, aConcept.A_Inject(aConcept.A_Scope))
310
+ ], exports.A_Logger);
311
+
20
312
  // src/lib/A-Channel/A-Channel.component.ts
21
313
  var A_Channel = class extends aConcept.A_Component {
314
+ /**
315
+ * Creates a new A_Channel instance.
316
+ *
317
+ * The channel must be registered with A_Context before use:
318
+ * ```typescript
319
+ * const channel = new A_Channel();
320
+ * A_Context.root.register(channel);
321
+ * ```
322
+ */
22
323
  constructor() {
23
- super(...arguments);
324
+ super();
24
325
  /**
25
- * Indicates whether the channel is processing requests
326
+ * Indicates whether the channel is currently processing requests.
327
+ * This flag is managed automatically during request/send operations.
328
+ *
329
+ * @readonly
26
330
  */
27
331
  this._processing = false;
332
+ /**
333
+ * Internal cache storage for channel-specific data.
334
+ * Can be used by custom implementations for caching responses,
335
+ * connection pools, or other channel-specific state.
336
+ *
337
+ * @protected
338
+ */
339
+ this._cache = /* @__PURE__ */ new Map();
28
340
  }
29
341
  /**
30
- * Indicates whether the channel is processing requests
31
- */
342
+ * Indicates whether the channel is currently processing requests.
343
+ *
344
+ * @returns {boolean} True if channel is processing, false otherwise
345
+ */
32
346
  get processing() {
33
347
  return this._processing;
34
348
  }
35
349
  /**
36
- * Indicates whether the channel is connected
350
+ * Promise that resolves when the channel is fully initialized.
351
+ *
352
+ * Automatically calls the onConnect lifecycle hook if not already called.
353
+ * This ensures the channel is ready for communication operations.
354
+ *
355
+ * @returns {Promise<void>} Promise that resolves when initialization is complete
37
356
  */
38
357
  get initialize() {
39
358
  if (!this._initialized) {
@@ -41,48 +360,259 @@ var A_Channel = class extends aConcept.A_Component {
41
360
  }
42
361
  return this._initialized;
43
362
  }
363
+ async onConnect(...args) {
364
+ }
365
+ async onDisconnect(...args) {
366
+ }
367
+ async onBeforeRequest(...args) {
368
+ }
369
+ async onRequest(...args) {
370
+ }
371
+ async onAfterRequest(...args) {
372
+ }
373
+ async onError(...args) {
374
+ }
375
+ async onSend(...args) {
376
+ }
377
+ // ==========================================================
378
+ // ================= Public API Methods ===================
379
+ // ==========================================================
44
380
  /**
45
- * Initializes the channel before use
381
+ * Initializes the channel by calling the onConnect lifecycle hook.
382
+ *
383
+ * This method is called automatically when accessing the `initialize` property.
384
+ * You can also call it manually if needed.
385
+ *
386
+ * @returns {Promise<void>} Promise that resolves when connection is established
46
387
  */
47
388
  async connect() {
48
- throw new A_ChannelError(
49
- A_ChannelError.MethodNotImplemented,
50
- `The connect method is not implemented in ${this.constructor.name} channel. This method is required to initialize the channel before use. So please implement it in the derived class.`
51
- );
389
+ await this.call("onConnect" /* onConnect */);
52
390
  }
53
391
  /**
54
- * Allows to send a request through the channel
55
- *
56
- * @param req - The request parameters
57
- * @returns The response from the channel
392
+ * Disconnects the channel by calling the onDisconnect lifecycle hook.
393
+ *
394
+ * Use this method to properly cleanup resources when the channel is no longer needed.
395
+ *
396
+ * @returns {Promise<void>} Promise that resolves when cleanup is complete
397
+ */
398
+ async disconnect() {
399
+ await this.call("onDisconnect" /* onDisconnect */);
400
+ }
401
+ /**
402
+ * Sends a request and waits for a response (Request/Response pattern).
403
+ *
404
+ * This method follows the complete request lifecycle:
405
+ * 1. Ensures channel is initialized
406
+ * 2. Creates request scope and context
407
+ * 3. Calls onBeforeRequest hook
408
+ * 4. Calls onRequest hook (main processing)
409
+ * 5. Calls onAfterRequest hook
410
+ * 6. Returns the response context
411
+ *
412
+ * If any step fails, the onError hook is called and the error is captured
413
+ * in the returned context.
414
+ *
415
+ * @template _ParamsType The type of request parameters
416
+ * @template _ResultType The type of response data
417
+ * @param params The request parameters
418
+ * @returns {Promise<A_ChannelRequest<_ParamsType, _ResultType>>} Request context with response
419
+ *
420
+ * @example
421
+ * ```typescript
422
+ * // Basic usage
423
+ * const response = await channel.request({ action: 'getData', id: 123 });
424
+ *
425
+ * // Typed usage
426
+ * interface UserRequest { userId: string; }
427
+ * interface UserResponse { name: string; email: string; }
428
+ *
429
+ * const userResponse = await channel.request<UserRequest, UserResponse>({
430
+ * userId: 'user-123'
431
+ * });
432
+ *
433
+ * if (!userResponse.failed) {
434
+ * console.log('User:', userResponse.data.name);
435
+ * }
436
+ * ```
58
437
  */
59
438
  async request(params) {
60
- throw new A_ChannelError(
61
- A_ChannelError.MethodNotImplemented,
62
- `The request method is not implemented in ${this.constructor.name} channel.`
63
- );
439
+ await this.initialize;
440
+ this._processing = true;
441
+ const requestScope = new aConcept.A_Scope({
442
+ name: `a-channel@scope:request:${aConcept.A_IdentityHelper.generateTimeId()}`
443
+ });
444
+ const context = new A_ChannelRequest(params);
445
+ try {
446
+ requestScope.inherit(aConcept.A_Context.scope(this));
447
+ requestScope.register(context);
448
+ await this.call("onBeforeRequest" /* onBeforeRequest */, requestScope);
449
+ await this.call("onRequest" /* onRequest */, requestScope);
450
+ await this.call("onAfterRequest" /* onAfterRequest */, requestScope);
451
+ this._processing = false;
452
+ return context;
453
+ } catch (error) {
454
+ this._processing = false;
455
+ const channelError = new A_ChannelError(error);
456
+ context.fail(channelError);
457
+ await this.call("onError" /* onError */, requestScope);
458
+ return context;
459
+ }
64
460
  }
65
461
  /**
66
- * Uses for Fire-and-Forget messaging through the channel
462
+ * Sends a fire-and-forget message (Send pattern).
463
+ *
464
+ * This method is used for one-way communication where no response is expected:
465
+ * - Event broadcasting
466
+ * - Notification sending
467
+ * - Message queuing
468
+ * - Logging operations
469
+ *
470
+ * The method follows this lifecycle:
471
+ * 1. Ensures channel is initialized
472
+ * 2. Creates send scope and context
473
+ * 3. Calls onSend hook
474
+ * 4. Completes without returning data
475
+ *
476
+ * If the operation fails, the onError hook is called but no error is thrown
477
+ * to the caller (fire-and-forget semantics).
67
478
  *
68
- * @param message - can be of any type depending on the channel implementation
479
+ * @template _ParamsType The type of message parameters
480
+ * @param message The message to send
481
+ * @returns {Promise<void>} Promise that resolves when send is complete
482
+ *
483
+ * @example
484
+ * ```typescript
485
+ * // Send notification
486
+ * await channel.send({
487
+ * type: 'user.login',
488
+ * userId: 'user-123',
489
+ * timestamp: new Date().toISOString()
490
+ * });
491
+ *
492
+ * // Send to message queue
493
+ * await channel.send({
494
+ * queue: 'email-queue',
495
+ * payload: {
496
+ * to: 'user@example.com',
497
+ * subject: 'Welcome!',
498
+ * body: 'Welcome to our service!'
499
+ * }
500
+ * });
501
+ * ```
69
502
  */
70
503
  async send(message) {
71
- throw new A_ChannelError(
72
- A_ChannelError.MethodNotImplemented,
73
- `The send method is not implemented in ${this.constructor.name} channel.`
74
- );
504
+ await this.initialize;
505
+ this._processing = true;
506
+ const requestScope = new aConcept.A_Scope({
507
+ name: `a-channel@scope:send:${aConcept.A_IdentityHelper.generateTimeId()}`
508
+ });
509
+ const context = new A_ChannelRequest(message);
510
+ try {
511
+ requestScope.inherit(aConcept.A_Context.scope(this));
512
+ requestScope.register(context);
513
+ await this.call("onSend" /* onSend */, requestScope);
514
+ this._processing = false;
515
+ } catch (error) {
516
+ this._processing = false;
517
+ const channelError = new A_ChannelError(error);
518
+ context.fail(channelError);
519
+ await this.call("onError" /* onError */, requestScope);
520
+ }
521
+ }
522
+ /**
523
+ * @deprecated This method is deprecated and will be removed in future versions.
524
+ * Use request() or send() methods instead depending on your communication pattern.
525
+ *
526
+ * For request/response pattern: Use request()
527
+ * For fire-and-forget pattern: Use send()
528
+ * For consumer patterns: Implement custom consumer logic using request() in a loop
529
+ */
530
+ async consume() {
531
+ await this.initialize;
532
+ this._processing = true;
533
+ const requestScope = new aConcept.A_Scope({ name: `a-channel@scope:consume:${aConcept.A_IdentityHelper.generateTimeId()}` });
534
+ const context = new A_ChannelRequest();
535
+ try {
536
+ requestScope.inherit(aConcept.A_Context.scope(this));
537
+ requestScope.register(context);
538
+ await this.call("onConsume" /* onConsume */, requestScope);
539
+ this._processing = false;
540
+ return context;
541
+ } catch (error) {
542
+ this._processing = false;
543
+ const channelError = new A_ChannelError(error);
544
+ context.fail(channelError);
545
+ await this.call("onError" /* onError */, requestScope);
546
+ return context;
547
+ }
75
548
  }
76
549
  };
77
550
  __decorateClass([
78
- aConcept.A_Feature.Define()
79
- ], A_Channel.prototype, "connect", 1);
551
+ aConcept.A_Feature.Extend({
552
+ name: "onConnect" /* onConnect */
553
+ })
554
+ ], A_Channel.prototype, "onConnect", 1);
555
+ __decorateClass([
556
+ aConcept.A_Feature.Extend({
557
+ name: "onDisconnect" /* onDisconnect */
558
+ })
559
+ ], A_Channel.prototype, "onDisconnect", 1);
560
+ __decorateClass([
561
+ aConcept.A_Feature.Extend({
562
+ name: "onBeforeRequest" /* onBeforeRequest */
563
+ })
564
+ ], A_Channel.prototype, "onBeforeRequest", 1);
565
+ __decorateClass([
566
+ aConcept.A_Feature.Extend({
567
+ name: "onRequest" /* onRequest */
568
+ })
569
+ ], A_Channel.prototype, "onRequest", 1);
570
+ __decorateClass([
571
+ aConcept.A_Feature.Extend({
572
+ name: "onAfterRequest" /* onAfterRequest */
573
+ })
574
+ ], A_Channel.prototype, "onAfterRequest", 1);
80
575
  __decorateClass([
81
- aConcept.A_Feature.Define()
82
- ], A_Channel.prototype, "request", 1);
576
+ aConcept.A_Feature.Extend({
577
+ name: "onError" /* onError */
578
+ })
579
+ ], A_Channel.prototype, "onError", 1);
83
580
  __decorateClass([
84
- aConcept.A_Feature.Define()
85
- ], A_Channel.prototype, "send", 1);
581
+ aConcept.A_Feature.Extend({
582
+ name: "onSend" /* onSend */
583
+ })
584
+ ], A_Channel.prototype, "onSend", 1);
585
+ var HttpChannel = class extends A_Channel {
586
+ };
587
+ var PollyspotChannel = class extends HttpChannel {
588
+ constructor() {
589
+ super();
590
+ this.baseUrl = "https://pollyspot.example.com";
591
+ }
592
+ };
593
+ var GlobalErrorhandler = class extends aConcept.A_Component {
594
+ async handleError(context, logger, config) {
595
+ }
596
+ async anotherError(context, logger, config) {
597
+ }
598
+ };
599
+ __decorateClass([
600
+ aConcept.A_Feature.Extend({
601
+ name: "onError" /* onError */,
602
+ scope: [PollyspotChannel]
603
+ }),
604
+ __decorateParam(0, aConcept.A_Inject(A_ChannelRequest)),
605
+ __decorateParam(1, aConcept.A_Inject(exports.A_Logger)),
606
+ __decorateParam(2, aConcept.A_Inject(A_Config))
607
+ ], GlobalErrorhandler.prototype, "handleError", 1);
608
+ __decorateClass([
609
+ aConcept.A_Feature.Extend({
610
+ name: "onError" /* onError */
611
+ }),
612
+ __decorateParam(0, aConcept.A_Inject(A_ChannelRequest)),
613
+ __decorateParam(1, aConcept.A_Inject(exports.A_Logger)),
614
+ __decorateParam(2, aConcept.A_Inject(A_Config))
615
+ ], GlobalErrorhandler.prototype, "anotherError", 1);
86
616
 
87
617
  // src/lib/A-Command/A-Command.constants.ts
88
618
  var A_TYPES__CommandMetaKey = /* @__PURE__ */ ((A_TYPES__CommandMetaKey2) => {
@@ -473,176 +1003,6 @@ var A_Command = class extends aConcept.A_Entity {
473
1003
  }
474
1004
  }
475
1005
  };
476
-
477
- // src/lib/A-Config/A-Config.constants.ts
478
- var A_CONSTANTS__CONFIG_ENV_VARIABLES = {};
479
- var A_CONSTANTS__CONFIG_ENV_VARIABLES_ARRAY = [];
480
-
481
- // src/lib/A-Config/A-Config.context.ts
482
- var A_Config = class extends aConcept.A_Fragment {
483
- constructor(config) {
484
- super({
485
- name: "A_Config"
486
- });
487
- this.VARIABLES = /* @__PURE__ */ new Map();
488
- this.DEFAULT_ALLOWED_TO_READ_PROPERTIES = [
489
- ...aConcept.A_CONSTANTS__DEFAULT_ENV_VARIABLES_ARRAY,
490
- ...A_CONSTANTS__CONFIG_ENV_VARIABLES_ARRAY
491
- ];
492
- this.config = aConcept.A_CommonHelper.deepCloneAndMerge(config, {
493
- strict: false,
494
- defaults: {},
495
- variables: aConcept.A_CONSTANTS__DEFAULT_ENV_VARIABLES_ARRAY
496
- });
497
- this.CONFIG_PROPERTIES = this.config.variables ? this.config.variables : [];
498
- this.config.variables.forEach((variable) => {
499
- this.VARIABLES.set(
500
- aConcept.A_FormatterHelper.toUpperSnakeCase(variable),
501
- this.config.defaults[variable]
502
- );
503
- });
504
- }
505
- /**
506
- * This method is used to get the configuration property by name
507
- *
508
- * @param property
509
- * @returns
510
- */
511
- get(property) {
512
- if (this.CONFIG_PROPERTIES.includes(property) || this.DEFAULT_ALLOWED_TO_READ_PROPERTIES.includes(property) || !this.config.strict)
513
- return this.VARIABLES.get(aConcept.A_FormatterHelper.toUpperSnakeCase(property));
514
- throw new Error("Property not exists or not allowed to read");
515
- }
516
- set(property, value) {
517
- const array = Array.isArray(property) ? property : typeof property === "string" ? [{ property, value }] : Object.keys(property).map((key) => ({
518
- property: key,
519
- value: property[key]
520
- }));
521
- for (const { property: property2, value: value2 } of array) {
522
- let targetValue = value2 ? value2 : this.config?.defaults ? this.config.defaults[property2] : void 0;
523
- this.VARIABLES.set(aConcept.A_FormatterHelper.toUpperSnakeCase(property2), targetValue);
524
- }
525
- }
526
- };
527
- exports.A_Logger = class A_Logger extends aConcept.A_Component {
528
- constructor(scope) {
529
- super();
530
- this.scope = scope;
531
- this.colors = {
532
- green: "32",
533
- blue: "34",
534
- red: "31",
535
- yellow: "33",
536
- gray: "90",
537
- magenta: "35",
538
- cyan: "36",
539
- white: "37",
540
- pink: "95"
541
- };
542
- this.config = this.scope.has(A_Config) ? this.scope.resolve(A_Config) : void 0;
543
- }
544
- get scopeLength() {
545
- return this.scope.name.length;
546
- }
547
- compile(color, ...args) {
548
- return [
549
- `\x1B[${this.colors[color]}m[${this.scope.name}] |${this.getTime()}|`,
550
- args.length > 1 ? `
551
- ${" ".repeat(this.scopeLength + 3)}|-------------------------------` : "",
552
- ...args.map((arg, i) => {
553
- switch (true) {
554
- case arg instanceof aConcept.A_Error:
555
- return this.compile_A_Error(arg);
556
- case arg instanceof Error:
557
- return this.compile_Error(arg);
558
- case typeof arg === "object":
559
- return JSON.stringify(arg, null, 2).replace(/\n/g, `
560
- ${" ".repeat(this.scopeLength + 3)}| `);
561
- default:
562
- return String(
563
- (i > 0 || args.length > 1 ? "\n" : "") + arg
564
- ).replace(/\n/g, `
565
- ${" ".repeat(this.scopeLength + 3)}| `);
566
- }
567
- }),
568
- args.length > 1 ? `
569
- ${" ".repeat(this.scopeLength + 3)}|-------------------------------\x1B[0m` : "\x1B[0m"
570
- ];
571
- }
572
- get allowedToLog() {
573
- return this.config ? this.config.get("CONFIG_VERBOSE") !== void 0 && this.config.get("CONFIG_VERBOSE") !== "false" && this.config.get("CONFIG_VERBOSE") !== false : true;
574
- }
575
- log(param1, ...args) {
576
- if (!this.allowedToLog)
577
- return;
578
- if (typeof param1 === "string" && this.colors[param1]) {
579
- console.log(...this.compile(param1, ...args));
580
- return;
581
- } else {
582
- console.log(...this.compile("blue", param1, ...args));
583
- }
584
- }
585
- warning(...args) {
586
- if (!this.allowedToLog)
587
- return;
588
- console.log(...this.compile("yellow", ...args));
589
- }
590
- error(...args) {
591
- if (this.config && this.config.get("CONFIG_IGNORE_ERRORS"))
592
- return;
593
- return console.log(...this.compile("red", ...args));
594
- }
595
- log_A_Error(error) {
596
- const time = this.getTime();
597
- console.log(`\x1B[31m[${this.scope.name}] |${time}| ERROR ${error.code}
598
- ${" ".repeat(this.scopeLength + 3)}| ${error.message}
599
- ${" ".repeat(this.scopeLength + 3)}| ${error.description}
600
- ${" ".repeat(this.scopeLength + 3)}|-------------------------------
601
- ${" ".repeat(this.scopeLength + 3)}| ${error.stack?.split("\n").map((line, index) => index === 0 ? line : `${" ".repeat(this.scopeLength + 3)}| ${line}`).join("\n") || "No stack trace"}
602
- ${" ".repeat(this.scopeLength + 3)}|-------------------------------
603
- \x1B[0m` + (error.originalError ? `\x1B[31m${" ".repeat(this.scopeLength + 3)}| Wrapped From ${error.originalError.message}
604
- ${" ".repeat(this.scopeLength + 3)}|-------------------------------
605
- ${" ".repeat(this.scopeLength + 3)}| ${error.originalError.stack?.split("\n").map((line, index) => index === 0 ? line : `${" ".repeat(this.scopeLength + 3)}| ${line}`).join("\n") || "No stack trace"}
606
- ${" ".repeat(this.scopeLength + 3)}|-------------------------------
607
- \x1B[0m` : "") + (error.link ? `\x1B[31m${" ".repeat(this.scopeLength + 3)}| Read in docs: ${error.link}
608
- ${" ".repeat(this.scopeLength + 3)}|-------------------------------
609
- \x1B[0m` : ""));
610
- }
611
- compile_A_Error(error) {
612
- this.getTime();
613
- return `
614
- ${" ".repeat(this.scopeLength + 3)}|-------------------------------
615
- ${" ".repeat(this.scopeLength + 3)}| Error: | ${error.code}
616
- ${" ".repeat(this.scopeLength + 3)}|-------------------------------
617
- ${" ".repeat(this.scopeLength + 3)}|${" ".repeat(10)}| ${error.message}
618
- ${" ".repeat(this.scopeLength + 3)}|${" ".repeat(10)}| ${error.description}
619
- ${" ".repeat(this.scopeLength + 3)}|-------------------------------
620
- ${" ".repeat(this.scopeLength + 3)}| ${error.stack?.split("\n").map((line, index) => index === 0 ? line : `${" ".repeat(this.scopeLength + 3)}| ${line}`).join("\n") || "No stack trace"}
621
- ${" ".repeat(this.scopeLength + 3)}|-------------------------------` + (error.originalError ? `${" ".repeat(this.scopeLength + 3)}| Wrapped From ${error.originalError.message}
622
- ${" ".repeat(this.scopeLength + 3)}|-------------------------------
623
- ${" ".repeat(this.scopeLength + 3)}| ${error.originalError.stack?.split("\n").map((line, index) => index === 0 ? line : `${" ".repeat(this.scopeLength + 3)}| ${line}`).join("\n") || "No stack trace"}
624
- ${" ".repeat(this.scopeLength + 3)}|-------------------------------` : "") + (error.link ? `${" ".repeat(this.scopeLength + 3)}| Read in docs: ${error.link}
625
- ${" ".repeat(this.scopeLength + 3)}|-------------------------------` : "");
626
- }
627
- compile_Error(error) {
628
- return JSON.stringify({
629
- name: error.name,
630
- message: error.message,
631
- stack: error.stack?.split("\n").map((line, index) => index === 0 ? line : `${" ".repeat(this.scopeLength + 3)}| ${line}`).join("\n")
632
- }, null, 2).replace(/\n/g, `
633
- ${" ".repeat(this.scopeLength + 3)}| `).replace(/\\n/g, "\n");
634
- }
635
- getTime() {
636
- const now = /* @__PURE__ */ new Date();
637
- const minutes = String(now.getMinutes()).padStart(2, "0");
638
- const seconds = String(now.getSeconds()).padStart(2, "0");
639
- const milliseconds = String(now.getMilliseconds()).padStart(4, "0");
640
- return `${minutes}:${seconds}:${milliseconds}`;
641
- }
642
- };
643
- exports.A_Logger = __decorateClass([
644
- __decorateParam(0, aConcept.A_Inject(aConcept.A_Scope))
645
- ], exports.A_Logger);
646
1006
  var A_FSPolyfillClass = class {
647
1007
  constructor(logger) {
648
1008
  this.logger = logger;
@@ -1795,6 +2155,9 @@ exports.A_CONSTANTS__CONFIG_ENV_VARIABLES = A_CONSTANTS__CONFIG_ENV_VARIABLES;
1795
2155
  exports.A_CONSTANTS__CONFIG_ENV_VARIABLES_ARRAY = A_CONSTANTS__CONFIG_ENV_VARIABLES_ARRAY;
1796
2156
  exports.A_Channel = A_Channel;
1797
2157
  exports.A_ChannelError = A_ChannelError;
2158
+ exports.A_ChannelFeatures = A_ChannelFeatures;
2159
+ exports.A_ChannelRequest = A_ChannelRequest;
2160
+ exports.A_ChannelRequestStatuses = A_ChannelRequestStatuses;
1798
2161
  exports.A_Command = A_Command;
1799
2162
  exports.A_CommandError = A_CommandError;
1800
2163
  exports.A_Config = A_Config;