@adaas/a-utils 0.1.14 → 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/README.md +26 -2
- package/dist/index.d.mts +66 -14
- package/dist/index.d.ts +66 -14
- package/dist/index.js +237 -176
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +236 -178
- package/dist/index.mjs.map +1 -1
- package/examples/channel-examples.ts +13 -13
- package/package.json +23 -5
- package/src/index.ts +3 -1
- package/src/lib/A-Channel/A-Channel.component.ts +84 -17
- package/src/lib/A-Channel/A-Channel.error.ts +5 -5
- package/src/lib/A-Channel/A-ChannelRequest.context.ts +1 -1
- package/src/lib/A-Channel/README.md +24 -24
- package/tests/A-Channel.test.ts +14 -14
package/dist/index.js
CHANGED
|
@@ -13,7 +13,32 @@ 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
|
-
|
|
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 {
|
|
17
42
|
constructor(params = {}) {
|
|
18
43
|
super();
|
|
19
44
|
this._errors = /* @__PURE__ */ new Set();
|
|
@@ -97,7 +122,7 @@ var A_ChannelError = class extends aConcept.A_Error {
|
|
|
97
122
|
super(originalError, context);
|
|
98
123
|
else
|
|
99
124
|
super(originalError);
|
|
100
|
-
if (context instanceof
|
|
125
|
+
if (context instanceof A_ChannelRequest)
|
|
101
126
|
this._context = context;
|
|
102
127
|
}
|
|
103
128
|
/***
|
|
@@ -112,6 +137,178 @@ var A_ChannelError = class extends aConcept.A_Error {
|
|
|
112
137
|
// ==========================================================
|
|
113
138
|
A_ChannelError.MethodNotImplemented = "A-Channel Method Not Implemented";
|
|
114
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
|
+
|
|
115
312
|
// src/lib/A-Channel/A-Channel.component.ts
|
|
116
313
|
var A_Channel = class extends aConcept.A_Component {
|
|
117
314
|
/**
|
|
@@ -218,7 +415,7 @@ var A_Channel = class extends aConcept.A_Component {
|
|
|
218
415
|
* @template _ParamsType The type of request parameters
|
|
219
416
|
* @template _ResultType The type of response data
|
|
220
417
|
* @param params The request parameters
|
|
221
|
-
* @returns {Promise<
|
|
418
|
+
* @returns {Promise<A_ChannelRequest<_ParamsType, _ResultType>>} Request context with response
|
|
222
419
|
*
|
|
223
420
|
* @example
|
|
224
421
|
* ```typescript
|
|
@@ -244,7 +441,7 @@ var A_Channel = class extends aConcept.A_Component {
|
|
|
244
441
|
const requestScope = new aConcept.A_Scope({
|
|
245
442
|
name: `a-channel@scope:request:${aConcept.A_IdentityHelper.generateTimeId()}`
|
|
246
443
|
});
|
|
247
|
-
const context = new
|
|
444
|
+
const context = new A_ChannelRequest(params);
|
|
248
445
|
try {
|
|
249
446
|
requestScope.inherit(aConcept.A_Context.scope(this));
|
|
250
447
|
requestScope.register(context);
|
|
@@ -309,7 +506,7 @@ var A_Channel = class extends aConcept.A_Component {
|
|
|
309
506
|
const requestScope = new aConcept.A_Scope({
|
|
310
507
|
name: `a-channel@scope:send:${aConcept.A_IdentityHelper.generateTimeId()}`
|
|
311
508
|
});
|
|
312
|
-
const context = new
|
|
509
|
+
const context = new A_ChannelRequest(message);
|
|
313
510
|
try {
|
|
314
511
|
requestScope.inherit(aConcept.A_Context.scope(this));
|
|
315
512
|
requestScope.register(context);
|
|
@@ -334,7 +531,7 @@ var A_Channel = class extends aConcept.A_Component {
|
|
|
334
531
|
await this.initialize;
|
|
335
532
|
this._processing = true;
|
|
336
533
|
const requestScope = new aConcept.A_Scope({ name: `a-channel@scope:consume:${aConcept.A_IdentityHelper.generateTimeId()}` });
|
|
337
|
-
const context = new
|
|
534
|
+
const context = new A_ChannelRequest();
|
|
338
535
|
try {
|
|
339
536
|
requestScope.inherit(aConcept.A_Context.scope(this));
|
|
340
537
|
requestScope.register(context);
|
|
@@ -385,6 +582,37 @@ __decorateClass([
|
|
|
385
582
|
name: "onSend" /* onSend */
|
|
386
583
|
})
|
|
387
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);
|
|
388
616
|
|
|
389
617
|
// src/lib/A-Command/A-Command.constants.ts
|
|
390
618
|
var A_TYPES__CommandMetaKey = /* @__PURE__ */ ((A_TYPES__CommandMetaKey2) => {
|
|
@@ -775,176 +1003,6 @@ var A_Command = class extends aConcept.A_Entity {
|
|
|
775
1003
|
}
|
|
776
1004
|
}
|
|
777
1005
|
};
|
|
778
|
-
|
|
779
|
-
// src/lib/A-Config/A-Config.constants.ts
|
|
780
|
-
var A_CONSTANTS__CONFIG_ENV_VARIABLES = {};
|
|
781
|
-
var A_CONSTANTS__CONFIG_ENV_VARIABLES_ARRAY = [];
|
|
782
|
-
|
|
783
|
-
// src/lib/A-Config/A-Config.context.ts
|
|
784
|
-
var A_Config = class extends aConcept.A_Fragment {
|
|
785
|
-
constructor(config) {
|
|
786
|
-
super({
|
|
787
|
-
name: "A_Config"
|
|
788
|
-
});
|
|
789
|
-
this.VARIABLES = /* @__PURE__ */ new Map();
|
|
790
|
-
this.DEFAULT_ALLOWED_TO_READ_PROPERTIES = [
|
|
791
|
-
...aConcept.A_CONSTANTS__DEFAULT_ENV_VARIABLES_ARRAY,
|
|
792
|
-
...A_CONSTANTS__CONFIG_ENV_VARIABLES_ARRAY
|
|
793
|
-
];
|
|
794
|
-
this.config = aConcept.A_CommonHelper.deepCloneAndMerge(config, {
|
|
795
|
-
strict: false,
|
|
796
|
-
defaults: {},
|
|
797
|
-
variables: aConcept.A_CONSTANTS__DEFAULT_ENV_VARIABLES_ARRAY
|
|
798
|
-
});
|
|
799
|
-
this.CONFIG_PROPERTIES = this.config.variables ? this.config.variables : [];
|
|
800
|
-
this.config.variables.forEach((variable) => {
|
|
801
|
-
this.VARIABLES.set(
|
|
802
|
-
aConcept.A_FormatterHelper.toUpperSnakeCase(variable),
|
|
803
|
-
this.config.defaults[variable]
|
|
804
|
-
);
|
|
805
|
-
});
|
|
806
|
-
}
|
|
807
|
-
/**
|
|
808
|
-
* This method is used to get the configuration property by name
|
|
809
|
-
*
|
|
810
|
-
* @param property
|
|
811
|
-
* @returns
|
|
812
|
-
*/
|
|
813
|
-
get(property) {
|
|
814
|
-
if (this.CONFIG_PROPERTIES.includes(property) || this.DEFAULT_ALLOWED_TO_READ_PROPERTIES.includes(property) || !this.config.strict)
|
|
815
|
-
return this.VARIABLES.get(aConcept.A_FormatterHelper.toUpperSnakeCase(property));
|
|
816
|
-
throw new Error("Property not exists or not allowed to read");
|
|
817
|
-
}
|
|
818
|
-
set(property, value) {
|
|
819
|
-
const array = Array.isArray(property) ? property : typeof property === "string" ? [{ property, value }] : Object.keys(property).map((key) => ({
|
|
820
|
-
property: key,
|
|
821
|
-
value: property[key]
|
|
822
|
-
}));
|
|
823
|
-
for (const { property: property2, value: value2 } of array) {
|
|
824
|
-
let targetValue = value2 ? value2 : this.config?.defaults ? this.config.defaults[property2] : void 0;
|
|
825
|
-
this.VARIABLES.set(aConcept.A_FormatterHelper.toUpperSnakeCase(property2), targetValue);
|
|
826
|
-
}
|
|
827
|
-
}
|
|
828
|
-
};
|
|
829
|
-
exports.A_Logger = class A_Logger extends aConcept.A_Component {
|
|
830
|
-
constructor(scope) {
|
|
831
|
-
super();
|
|
832
|
-
this.scope = scope;
|
|
833
|
-
this.colors = {
|
|
834
|
-
green: "32",
|
|
835
|
-
blue: "34",
|
|
836
|
-
red: "31",
|
|
837
|
-
yellow: "33",
|
|
838
|
-
gray: "90",
|
|
839
|
-
magenta: "35",
|
|
840
|
-
cyan: "36",
|
|
841
|
-
white: "37",
|
|
842
|
-
pink: "95"
|
|
843
|
-
};
|
|
844
|
-
this.config = this.scope.has(A_Config) ? this.scope.resolve(A_Config) : void 0;
|
|
845
|
-
}
|
|
846
|
-
get scopeLength() {
|
|
847
|
-
return this.scope.name.length;
|
|
848
|
-
}
|
|
849
|
-
compile(color, ...args) {
|
|
850
|
-
return [
|
|
851
|
-
`\x1B[${this.colors[color]}m[${this.scope.name}] |${this.getTime()}|`,
|
|
852
|
-
args.length > 1 ? `
|
|
853
|
-
${" ".repeat(this.scopeLength + 3)}|-------------------------------` : "",
|
|
854
|
-
...args.map((arg, i) => {
|
|
855
|
-
switch (true) {
|
|
856
|
-
case arg instanceof aConcept.A_Error:
|
|
857
|
-
return this.compile_A_Error(arg);
|
|
858
|
-
case arg instanceof Error:
|
|
859
|
-
return this.compile_Error(arg);
|
|
860
|
-
case typeof arg === "object":
|
|
861
|
-
return JSON.stringify(arg, null, 2).replace(/\n/g, `
|
|
862
|
-
${" ".repeat(this.scopeLength + 3)}| `);
|
|
863
|
-
default:
|
|
864
|
-
return String(
|
|
865
|
-
(i > 0 || args.length > 1 ? "\n" : "") + arg
|
|
866
|
-
).replace(/\n/g, `
|
|
867
|
-
${" ".repeat(this.scopeLength + 3)}| `);
|
|
868
|
-
}
|
|
869
|
-
}),
|
|
870
|
-
args.length > 1 ? `
|
|
871
|
-
${" ".repeat(this.scopeLength + 3)}|-------------------------------\x1B[0m` : "\x1B[0m"
|
|
872
|
-
];
|
|
873
|
-
}
|
|
874
|
-
get allowedToLog() {
|
|
875
|
-
return this.config ? this.config.get("CONFIG_VERBOSE") !== void 0 && this.config.get("CONFIG_VERBOSE") !== "false" && this.config.get("CONFIG_VERBOSE") !== false : true;
|
|
876
|
-
}
|
|
877
|
-
log(param1, ...args) {
|
|
878
|
-
if (!this.allowedToLog)
|
|
879
|
-
return;
|
|
880
|
-
if (typeof param1 === "string" && this.colors[param1]) {
|
|
881
|
-
console.log(...this.compile(param1, ...args));
|
|
882
|
-
return;
|
|
883
|
-
} else {
|
|
884
|
-
console.log(...this.compile("blue", param1, ...args));
|
|
885
|
-
}
|
|
886
|
-
}
|
|
887
|
-
warning(...args) {
|
|
888
|
-
if (!this.allowedToLog)
|
|
889
|
-
return;
|
|
890
|
-
console.log(...this.compile("yellow", ...args));
|
|
891
|
-
}
|
|
892
|
-
error(...args) {
|
|
893
|
-
if (this.config && this.config.get("CONFIG_IGNORE_ERRORS"))
|
|
894
|
-
return;
|
|
895
|
-
return console.log(...this.compile("red", ...args));
|
|
896
|
-
}
|
|
897
|
-
log_A_Error(error) {
|
|
898
|
-
const time = this.getTime();
|
|
899
|
-
console.log(`\x1B[31m[${this.scope.name}] |${time}| ERROR ${error.code}
|
|
900
|
-
${" ".repeat(this.scopeLength + 3)}| ${error.message}
|
|
901
|
-
${" ".repeat(this.scopeLength + 3)}| ${error.description}
|
|
902
|
-
${" ".repeat(this.scopeLength + 3)}|-------------------------------
|
|
903
|
-
${" ".repeat(this.scopeLength + 3)}| ${error.stack?.split("\n").map((line, index) => index === 0 ? line : `${" ".repeat(this.scopeLength + 3)}| ${line}`).join("\n") || "No stack trace"}
|
|
904
|
-
${" ".repeat(this.scopeLength + 3)}|-------------------------------
|
|
905
|
-
\x1B[0m` + (error.originalError ? `\x1B[31m${" ".repeat(this.scopeLength + 3)}| Wrapped From ${error.originalError.message}
|
|
906
|
-
${" ".repeat(this.scopeLength + 3)}|-------------------------------
|
|
907
|
-
${" ".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"}
|
|
908
|
-
${" ".repeat(this.scopeLength + 3)}|-------------------------------
|
|
909
|
-
\x1B[0m` : "") + (error.link ? `\x1B[31m${" ".repeat(this.scopeLength + 3)}| Read in docs: ${error.link}
|
|
910
|
-
${" ".repeat(this.scopeLength + 3)}|-------------------------------
|
|
911
|
-
\x1B[0m` : ""));
|
|
912
|
-
}
|
|
913
|
-
compile_A_Error(error) {
|
|
914
|
-
this.getTime();
|
|
915
|
-
return `
|
|
916
|
-
${" ".repeat(this.scopeLength + 3)}|-------------------------------
|
|
917
|
-
${" ".repeat(this.scopeLength + 3)}| Error: | ${error.code}
|
|
918
|
-
${" ".repeat(this.scopeLength + 3)}|-------------------------------
|
|
919
|
-
${" ".repeat(this.scopeLength + 3)}|${" ".repeat(10)}| ${error.message}
|
|
920
|
-
${" ".repeat(this.scopeLength + 3)}|${" ".repeat(10)}| ${error.description}
|
|
921
|
-
${" ".repeat(this.scopeLength + 3)}|-------------------------------
|
|
922
|
-
${" ".repeat(this.scopeLength + 3)}| ${error.stack?.split("\n").map((line, index) => index === 0 ? line : `${" ".repeat(this.scopeLength + 3)}| ${line}`).join("\n") || "No stack trace"}
|
|
923
|
-
${" ".repeat(this.scopeLength + 3)}|-------------------------------` + (error.originalError ? `${" ".repeat(this.scopeLength + 3)}| Wrapped From ${error.originalError.message}
|
|
924
|
-
${" ".repeat(this.scopeLength + 3)}|-------------------------------
|
|
925
|
-
${" ".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"}
|
|
926
|
-
${" ".repeat(this.scopeLength + 3)}|-------------------------------` : "") + (error.link ? `${" ".repeat(this.scopeLength + 3)}| Read in docs: ${error.link}
|
|
927
|
-
${" ".repeat(this.scopeLength + 3)}|-------------------------------` : "");
|
|
928
|
-
}
|
|
929
|
-
compile_Error(error) {
|
|
930
|
-
return JSON.stringify({
|
|
931
|
-
name: error.name,
|
|
932
|
-
message: error.message,
|
|
933
|
-
stack: error.stack?.split("\n").map((line, index) => index === 0 ? line : `${" ".repeat(this.scopeLength + 3)}| ${line}`).join("\n")
|
|
934
|
-
}, null, 2).replace(/\n/g, `
|
|
935
|
-
${" ".repeat(this.scopeLength + 3)}| `).replace(/\\n/g, "\n");
|
|
936
|
-
}
|
|
937
|
-
getTime() {
|
|
938
|
-
const now = /* @__PURE__ */ new Date();
|
|
939
|
-
const minutes = String(now.getMinutes()).padStart(2, "0");
|
|
940
|
-
const seconds = String(now.getSeconds()).padStart(2, "0");
|
|
941
|
-
const milliseconds = String(now.getMilliseconds()).padStart(4, "0");
|
|
942
|
-
return `${minutes}:${seconds}:${milliseconds}`;
|
|
943
|
-
}
|
|
944
|
-
};
|
|
945
|
-
exports.A_Logger = __decorateClass([
|
|
946
|
-
__decorateParam(0, aConcept.A_Inject(aConcept.A_Scope))
|
|
947
|
-
], exports.A_Logger);
|
|
948
1006
|
var A_FSPolyfillClass = class {
|
|
949
1007
|
constructor(logger) {
|
|
950
1008
|
this.logger = logger;
|
|
@@ -2097,6 +2155,9 @@ exports.A_CONSTANTS__CONFIG_ENV_VARIABLES = A_CONSTANTS__CONFIG_ENV_VARIABLES;
|
|
|
2097
2155
|
exports.A_CONSTANTS__CONFIG_ENV_VARIABLES_ARRAY = A_CONSTANTS__CONFIG_ENV_VARIABLES_ARRAY;
|
|
2098
2156
|
exports.A_Channel = A_Channel;
|
|
2099
2157
|
exports.A_ChannelError = A_ChannelError;
|
|
2158
|
+
exports.A_ChannelFeatures = A_ChannelFeatures;
|
|
2159
|
+
exports.A_ChannelRequest = A_ChannelRequest;
|
|
2160
|
+
exports.A_ChannelRequestStatuses = A_ChannelRequestStatuses;
|
|
2100
2161
|
exports.A_Command = A_Command;
|
|
2101
2162
|
exports.A_CommandError = A_CommandError;
|
|
2102
2163
|
exports.A_Config = A_Config;
|