@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.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { A_Inject, A_Scope, A_Feature, A_Concept, A_Container, A_Error, A_TypeGuards, A_Fragment, A_Component, A_CONSTANTS__DEFAULT_ENV_VARIABLES_ARRAY, A_CommonHelper, A_FormatterHelper, A_Context, A_IdentityHelper, A_Entity, A_ScopeError } from '@adaas/a-concept';
|
|
2
2
|
|
|
3
3
|
var __defProp = Object.defineProperty;
|
|
4
4
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
@@ -11,7 +11,32 @@ var __decorateClass = (decorators, target, key, kind) => {
|
|
|
11
11
|
return result;
|
|
12
12
|
};
|
|
13
13
|
var __decorateParam = (index, decorator) => (target, key) => decorator(target, key, index);
|
|
14
|
-
|
|
14
|
+
|
|
15
|
+
// src/lib/A-Channel/A-Channel.constants.ts
|
|
16
|
+
var A_ChannelFeatures = /* @__PURE__ */ ((A_ChannelFeatures2) => {
|
|
17
|
+
A_ChannelFeatures2["onTimeout"] = "onTimeout";
|
|
18
|
+
A_ChannelFeatures2["onRetry"] = "onRetry";
|
|
19
|
+
A_ChannelFeatures2["onCircuitBreakerOpen"] = "onCircuitBreakerOpen";
|
|
20
|
+
A_ChannelFeatures2["onCache"] = "onCache";
|
|
21
|
+
A_ChannelFeatures2["onConnect"] = "onConnect";
|
|
22
|
+
A_ChannelFeatures2["onDisconnect"] = "onDisconnect";
|
|
23
|
+
A_ChannelFeatures2["onBeforeRequest"] = "onBeforeRequest";
|
|
24
|
+
A_ChannelFeatures2["onRequest"] = "onRequest";
|
|
25
|
+
A_ChannelFeatures2["onAfterRequest"] = "onAfterRequest";
|
|
26
|
+
A_ChannelFeatures2["onError"] = "onError";
|
|
27
|
+
A_ChannelFeatures2["onSend"] = "onSend";
|
|
28
|
+
A_ChannelFeatures2["onConsume"] = "onConsume";
|
|
29
|
+
return A_ChannelFeatures2;
|
|
30
|
+
})(A_ChannelFeatures || {});
|
|
31
|
+
var A_ChannelRequestStatuses = /* @__PURE__ */ ((A_ChannelRequestStatuses2) => {
|
|
32
|
+
A_ChannelRequestStatuses2["PENDING"] = "PENDING";
|
|
33
|
+
A_ChannelRequestStatuses2["SUCCESS"] = "SUCCESS";
|
|
34
|
+
A_ChannelRequestStatuses2["FAILED"] = "FAILED";
|
|
35
|
+
return A_ChannelRequestStatuses2;
|
|
36
|
+
})(A_ChannelRequestStatuses || {});
|
|
37
|
+
|
|
38
|
+
// src/lib/A-Channel/A-ChannelRequest.context.ts
|
|
39
|
+
var A_ChannelRequest = class extends A_Fragment {
|
|
15
40
|
constructor(params = {}) {
|
|
16
41
|
super();
|
|
17
42
|
this._errors = /* @__PURE__ */ new Set();
|
|
@@ -95,7 +120,7 @@ var A_ChannelError = class extends A_Error {
|
|
|
95
120
|
super(originalError, context);
|
|
96
121
|
else
|
|
97
122
|
super(originalError);
|
|
98
|
-
if (context instanceof
|
|
123
|
+
if (context instanceof A_ChannelRequest)
|
|
99
124
|
this._context = context;
|
|
100
125
|
}
|
|
101
126
|
/***
|
|
@@ -110,6 +135,178 @@ var A_ChannelError = class extends A_Error {
|
|
|
110
135
|
// ==========================================================
|
|
111
136
|
A_ChannelError.MethodNotImplemented = "A-Channel Method Not Implemented";
|
|
112
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.component.ts
|
|
190
|
+
var A_Logger = class extends A_Component {
|
|
191
|
+
constructor(scope) {
|
|
192
|
+
super();
|
|
193
|
+
this.scope = scope;
|
|
194
|
+
this.colors = {
|
|
195
|
+
green: "32",
|
|
196
|
+
blue: "34",
|
|
197
|
+
red: "31",
|
|
198
|
+
yellow: "33",
|
|
199
|
+
gray: "90",
|
|
200
|
+
magenta: "35",
|
|
201
|
+
cyan: "36",
|
|
202
|
+
white: "37",
|
|
203
|
+
pink: "95"
|
|
204
|
+
};
|
|
205
|
+
this.config = this.scope.has(A_Config) ? this.scope.resolve(A_Config) : void 0;
|
|
206
|
+
}
|
|
207
|
+
get scopeLength() {
|
|
208
|
+
return this.scope.name.length;
|
|
209
|
+
}
|
|
210
|
+
compile(color, ...args) {
|
|
211
|
+
return [
|
|
212
|
+
`\x1B[${this.colors[color]}m[${this.scope.name}] |${this.getTime()}|`,
|
|
213
|
+
args.length > 1 ? `
|
|
214
|
+
${" ".repeat(this.scopeLength + 3)}|-------------------------------` : "",
|
|
215
|
+
...args.map((arg, i) => {
|
|
216
|
+
switch (true) {
|
|
217
|
+
case arg instanceof A_Error:
|
|
218
|
+
return this.compile_A_Error(arg);
|
|
219
|
+
case arg instanceof Error:
|
|
220
|
+
return this.compile_Error(arg);
|
|
221
|
+
case typeof arg === "object":
|
|
222
|
+
return JSON.stringify(arg, null, 2).replace(/\n/g, `
|
|
223
|
+
${" ".repeat(this.scopeLength + 3)}| `);
|
|
224
|
+
default:
|
|
225
|
+
return String(
|
|
226
|
+
(i > 0 || args.length > 1 ? "\n" : "") + arg
|
|
227
|
+
).replace(/\n/g, `
|
|
228
|
+
${" ".repeat(this.scopeLength + 3)}| `);
|
|
229
|
+
}
|
|
230
|
+
}),
|
|
231
|
+
args.length > 1 ? `
|
|
232
|
+
${" ".repeat(this.scopeLength + 3)}|-------------------------------\x1B[0m` : "\x1B[0m"
|
|
233
|
+
];
|
|
234
|
+
}
|
|
235
|
+
get allowedToLog() {
|
|
236
|
+
return this.config ? this.config.get("CONFIG_VERBOSE") !== void 0 && this.config.get("CONFIG_VERBOSE") !== "false" && this.config.get("CONFIG_VERBOSE") !== false : true;
|
|
237
|
+
}
|
|
238
|
+
log(param1, ...args) {
|
|
239
|
+
if (!this.allowedToLog)
|
|
240
|
+
return;
|
|
241
|
+
if (typeof param1 === "string" && this.colors[param1]) {
|
|
242
|
+
console.log(...this.compile(param1, ...args));
|
|
243
|
+
return;
|
|
244
|
+
} else {
|
|
245
|
+
console.log(...this.compile("blue", param1, ...args));
|
|
246
|
+
}
|
|
247
|
+
}
|
|
248
|
+
warning(...args) {
|
|
249
|
+
if (!this.allowedToLog)
|
|
250
|
+
return;
|
|
251
|
+
console.log(...this.compile("yellow", ...args));
|
|
252
|
+
}
|
|
253
|
+
error(...args) {
|
|
254
|
+
if (this.config && this.config.get("CONFIG_IGNORE_ERRORS"))
|
|
255
|
+
return;
|
|
256
|
+
return console.log(...this.compile("red", ...args));
|
|
257
|
+
}
|
|
258
|
+
log_A_Error(error) {
|
|
259
|
+
const time = this.getTime();
|
|
260
|
+
console.log(`\x1B[31m[${this.scope.name}] |${time}| ERROR ${error.code}
|
|
261
|
+
${" ".repeat(this.scopeLength + 3)}| ${error.message}
|
|
262
|
+
${" ".repeat(this.scopeLength + 3)}| ${error.description}
|
|
263
|
+
${" ".repeat(this.scopeLength + 3)}|-------------------------------
|
|
264
|
+
${" ".repeat(this.scopeLength + 3)}| ${error.stack?.split("\n").map((line, index) => index === 0 ? line : `${" ".repeat(this.scopeLength + 3)}| ${line}`).join("\n") || "No stack trace"}
|
|
265
|
+
${" ".repeat(this.scopeLength + 3)}|-------------------------------
|
|
266
|
+
\x1B[0m` + (error.originalError ? `\x1B[31m${" ".repeat(this.scopeLength + 3)}| Wrapped From ${error.originalError.message}
|
|
267
|
+
${" ".repeat(this.scopeLength + 3)}|-------------------------------
|
|
268
|
+
${" ".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"}
|
|
269
|
+
${" ".repeat(this.scopeLength + 3)}|-------------------------------
|
|
270
|
+
\x1B[0m` : "") + (error.link ? `\x1B[31m${" ".repeat(this.scopeLength + 3)}| Read in docs: ${error.link}
|
|
271
|
+
${" ".repeat(this.scopeLength + 3)}|-------------------------------
|
|
272
|
+
\x1B[0m` : ""));
|
|
273
|
+
}
|
|
274
|
+
compile_A_Error(error) {
|
|
275
|
+
this.getTime();
|
|
276
|
+
return `
|
|
277
|
+
${" ".repeat(this.scopeLength + 3)}|-------------------------------
|
|
278
|
+
${" ".repeat(this.scopeLength + 3)}| Error: | ${error.code}
|
|
279
|
+
${" ".repeat(this.scopeLength + 3)}|-------------------------------
|
|
280
|
+
${" ".repeat(this.scopeLength + 3)}|${" ".repeat(10)}| ${error.message}
|
|
281
|
+
${" ".repeat(this.scopeLength + 3)}|${" ".repeat(10)}| ${error.description}
|
|
282
|
+
${" ".repeat(this.scopeLength + 3)}|-------------------------------
|
|
283
|
+
${" ".repeat(this.scopeLength + 3)}| ${error.stack?.split("\n").map((line, index) => index === 0 ? line : `${" ".repeat(this.scopeLength + 3)}| ${line}`).join("\n") || "No stack trace"}
|
|
284
|
+
${" ".repeat(this.scopeLength + 3)}|-------------------------------` + (error.originalError ? `${" ".repeat(this.scopeLength + 3)}| Wrapped From ${error.originalError.message}
|
|
285
|
+
${" ".repeat(this.scopeLength + 3)}|-------------------------------
|
|
286
|
+
${" ".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"}
|
|
287
|
+
${" ".repeat(this.scopeLength + 3)}|-------------------------------` : "") + (error.link ? `${" ".repeat(this.scopeLength + 3)}| Read in docs: ${error.link}
|
|
288
|
+
${" ".repeat(this.scopeLength + 3)}|-------------------------------` : "");
|
|
289
|
+
}
|
|
290
|
+
compile_Error(error) {
|
|
291
|
+
return JSON.stringify({
|
|
292
|
+
name: error.name,
|
|
293
|
+
message: error.message,
|
|
294
|
+
stack: error.stack?.split("\n").map((line, index) => index === 0 ? line : `${" ".repeat(this.scopeLength + 3)}| ${line}`).join("\n")
|
|
295
|
+
}, null, 2).replace(/\n/g, `
|
|
296
|
+
${" ".repeat(this.scopeLength + 3)}| `).replace(/\\n/g, "\n");
|
|
297
|
+
}
|
|
298
|
+
getTime() {
|
|
299
|
+
const now = /* @__PURE__ */ new Date();
|
|
300
|
+
const minutes = String(now.getMinutes()).padStart(2, "0");
|
|
301
|
+
const seconds = String(now.getSeconds()).padStart(2, "0");
|
|
302
|
+
const milliseconds = String(now.getMilliseconds()).padStart(4, "0");
|
|
303
|
+
return `${minutes}:${seconds}:${milliseconds}`;
|
|
304
|
+
}
|
|
305
|
+
};
|
|
306
|
+
A_Logger = __decorateClass([
|
|
307
|
+
__decorateParam(0, A_Inject(A_Scope))
|
|
308
|
+
], A_Logger);
|
|
309
|
+
|
|
113
310
|
// src/lib/A-Channel/A-Channel.component.ts
|
|
114
311
|
var A_Channel = class extends A_Component {
|
|
115
312
|
/**
|
|
@@ -216,7 +413,7 @@ var A_Channel = class extends A_Component {
|
|
|
216
413
|
* @template _ParamsType The type of request parameters
|
|
217
414
|
* @template _ResultType The type of response data
|
|
218
415
|
* @param params The request parameters
|
|
219
|
-
* @returns {Promise<
|
|
416
|
+
* @returns {Promise<A_ChannelRequest<_ParamsType, _ResultType>>} Request context with response
|
|
220
417
|
*
|
|
221
418
|
* @example
|
|
222
419
|
* ```typescript
|
|
@@ -242,7 +439,7 @@ var A_Channel = class extends A_Component {
|
|
|
242
439
|
const requestScope = new A_Scope({
|
|
243
440
|
name: `a-channel@scope:request:${A_IdentityHelper.generateTimeId()}`
|
|
244
441
|
});
|
|
245
|
-
const context = new
|
|
442
|
+
const context = new A_ChannelRequest(params);
|
|
246
443
|
try {
|
|
247
444
|
requestScope.inherit(A_Context.scope(this));
|
|
248
445
|
requestScope.register(context);
|
|
@@ -307,7 +504,7 @@ var A_Channel = class extends A_Component {
|
|
|
307
504
|
const requestScope = new A_Scope({
|
|
308
505
|
name: `a-channel@scope:send:${A_IdentityHelper.generateTimeId()}`
|
|
309
506
|
});
|
|
310
|
-
const context = new
|
|
507
|
+
const context = new A_ChannelRequest(message);
|
|
311
508
|
try {
|
|
312
509
|
requestScope.inherit(A_Context.scope(this));
|
|
313
510
|
requestScope.register(context);
|
|
@@ -332,7 +529,7 @@ var A_Channel = class extends A_Component {
|
|
|
332
529
|
await this.initialize;
|
|
333
530
|
this._processing = true;
|
|
334
531
|
const requestScope = new A_Scope({ name: `a-channel@scope:consume:${A_IdentityHelper.generateTimeId()}` });
|
|
335
|
-
const context = new
|
|
532
|
+
const context = new A_ChannelRequest();
|
|
336
533
|
try {
|
|
337
534
|
requestScope.inherit(A_Context.scope(this));
|
|
338
535
|
requestScope.register(context);
|
|
@@ -383,6 +580,37 @@ __decorateClass([
|
|
|
383
580
|
name: "onSend" /* onSend */
|
|
384
581
|
})
|
|
385
582
|
], A_Channel.prototype, "onSend", 1);
|
|
583
|
+
var HttpChannel = class extends A_Channel {
|
|
584
|
+
};
|
|
585
|
+
var PollyspotChannel = class extends HttpChannel {
|
|
586
|
+
constructor() {
|
|
587
|
+
super();
|
|
588
|
+
this.baseUrl = "https://pollyspot.example.com";
|
|
589
|
+
}
|
|
590
|
+
};
|
|
591
|
+
var GlobalErrorhandler = class extends A_Component {
|
|
592
|
+
async handleError(context, logger, config) {
|
|
593
|
+
}
|
|
594
|
+
async anotherError(context, logger, config) {
|
|
595
|
+
}
|
|
596
|
+
};
|
|
597
|
+
__decorateClass([
|
|
598
|
+
A_Feature.Extend({
|
|
599
|
+
name: "onError" /* onError */,
|
|
600
|
+
scope: [PollyspotChannel]
|
|
601
|
+
}),
|
|
602
|
+
__decorateParam(0, A_Inject(A_ChannelRequest)),
|
|
603
|
+
__decorateParam(1, A_Inject(A_Logger)),
|
|
604
|
+
__decorateParam(2, A_Inject(A_Config))
|
|
605
|
+
], GlobalErrorhandler.prototype, "handleError", 1);
|
|
606
|
+
__decorateClass([
|
|
607
|
+
A_Feature.Extend({
|
|
608
|
+
name: "onError" /* onError */
|
|
609
|
+
}),
|
|
610
|
+
__decorateParam(0, A_Inject(A_ChannelRequest)),
|
|
611
|
+
__decorateParam(1, A_Inject(A_Logger)),
|
|
612
|
+
__decorateParam(2, A_Inject(A_Config))
|
|
613
|
+
], GlobalErrorhandler.prototype, "anotherError", 1);
|
|
386
614
|
|
|
387
615
|
// src/lib/A-Command/A-Command.constants.ts
|
|
388
616
|
var A_TYPES__CommandMetaKey = /* @__PURE__ */ ((A_TYPES__CommandMetaKey2) => {
|
|
@@ -773,176 +1001,6 @@ var A_Command = class extends A_Entity {
|
|
|
773
1001
|
}
|
|
774
1002
|
}
|
|
775
1003
|
};
|
|
776
|
-
|
|
777
|
-
// src/lib/A-Config/A-Config.constants.ts
|
|
778
|
-
var A_CONSTANTS__CONFIG_ENV_VARIABLES = {};
|
|
779
|
-
var A_CONSTANTS__CONFIG_ENV_VARIABLES_ARRAY = [];
|
|
780
|
-
|
|
781
|
-
// src/lib/A-Config/A-Config.context.ts
|
|
782
|
-
var A_Config = class extends A_Fragment {
|
|
783
|
-
constructor(config) {
|
|
784
|
-
super({
|
|
785
|
-
name: "A_Config"
|
|
786
|
-
});
|
|
787
|
-
this.VARIABLES = /* @__PURE__ */ new Map();
|
|
788
|
-
this.DEFAULT_ALLOWED_TO_READ_PROPERTIES = [
|
|
789
|
-
...A_CONSTANTS__DEFAULT_ENV_VARIABLES_ARRAY,
|
|
790
|
-
...A_CONSTANTS__CONFIG_ENV_VARIABLES_ARRAY
|
|
791
|
-
];
|
|
792
|
-
this.config = A_CommonHelper.deepCloneAndMerge(config, {
|
|
793
|
-
strict: false,
|
|
794
|
-
defaults: {},
|
|
795
|
-
variables: A_CONSTANTS__DEFAULT_ENV_VARIABLES_ARRAY
|
|
796
|
-
});
|
|
797
|
-
this.CONFIG_PROPERTIES = this.config.variables ? this.config.variables : [];
|
|
798
|
-
this.config.variables.forEach((variable) => {
|
|
799
|
-
this.VARIABLES.set(
|
|
800
|
-
A_FormatterHelper.toUpperSnakeCase(variable),
|
|
801
|
-
this.config.defaults[variable]
|
|
802
|
-
);
|
|
803
|
-
});
|
|
804
|
-
}
|
|
805
|
-
/**
|
|
806
|
-
* This method is used to get the configuration property by name
|
|
807
|
-
*
|
|
808
|
-
* @param property
|
|
809
|
-
* @returns
|
|
810
|
-
*/
|
|
811
|
-
get(property) {
|
|
812
|
-
if (this.CONFIG_PROPERTIES.includes(property) || this.DEFAULT_ALLOWED_TO_READ_PROPERTIES.includes(property) || !this.config.strict)
|
|
813
|
-
return this.VARIABLES.get(A_FormatterHelper.toUpperSnakeCase(property));
|
|
814
|
-
throw new Error("Property not exists or not allowed to read");
|
|
815
|
-
}
|
|
816
|
-
set(property, value) {
|
|
817
|
-
const array = Array.isArray(property) ? property : typeof property === "string" ? [{ property, value }] : Object.keys(property).map((key) => ({
|
|
818
|
-
property: key,
|
|
819
|
-
value: property[key]
|
|
820
|
-
}));
|
|
821
|
-
for (const { property: property2, value: value2 } of array) {
|
|
822
|
-
let targetValue = value2 ? value2 : this.config?.defaults ? this.config.defaults[property2] : void 0;
|
|
823
|
-
this.VARIABLES.set(A_FormatterHelper.toUpperSnakeCase(property2), targetValue);
|
|
824
|
-
}
|
|
825
|
-
}
|
|
826
|
-
};
|
|
827
|
-
var A_Logger = class extends A_Component {
|
|
828
|
-
constructor(scope) {
|
|
829
|
-
super();
|
|
830
|
-
this.scope = scope;
|
|
831
|
-
this.colors = {
|
|
832
|
-
green: "32",
|
|
833
|
-
blue: "34",
|
|
834
|
-
red: "31",
|
|
835
|
-
yellow: "33",
|
|
836
|
-
gray: "90",
|
|
837
|
-
magenta: "35",
|
|
838
|
-
cyan: "36",
|
|
839
|
-
white: "37",
|
|
840
|
-
pink: "95"
|
|
841
|
-
};
|
|
842
|
-
this.config = this.scope.has(A_Config) ? this.scope.resolve(A_Config) : void 0;
|
|
843
|
-
}
|
|
844
|
-
get scopeLength() {
|
|
845
|
-
return this.scope.name.length;
|
|
846
|
-
}
|
|
847
|
-
compile(color, ...args) {
|
|
848
|
-
return [
|
|
849
|
-
`\x1B[${this.colors[color]}m[${this.scope.name}] |${this.getTime()}|`,
|
|
850
|
-
args.length > 1 ? `
|
|
851
|
-
${" ".repeat(this.scopeLength + 3)}|-------------------------------` : "",
|
|
852
|
-
...args.map((arg, i) => {
|
|
853
|
-
switch (true) {
|
|
854
|
-
case arg instanceof A_Error:
|
|
855
|
-
return this.compile_A_Error(arg);
|
|
856
|
-
case arg instanceof Error:
|
|
857
|
-
return this.compile_Error(arg);
|
|
858
|
-
case typeof arg === "object":
|
|
859
|
-
return JSON.stringify(arg, null, 2).replace(/\n/g, `
|
|
860
|
-
${" ".repeat(this.scopeLength + 3)}| `);
|
|
861
|
-
default:
|
|
862
|
-
return String(
|
|
863
|
-
(i > 0 || args.length > 1 ? "\n" : "") + arg
|
|
864
|
-
).replace(/\n/g, `
|
|
865
|
-
${" ".repeat(this.scopeLength + 3)}| `);
|
|
866
|
-
}
|
|
867
|
-
}),
|
|
868
|
-
args.length > 1 ? `
|
|
869
|
-
${" ".repeat(this.scopeLength + 3)}|-------------------------------\x1B[0m` : "\x1B[0m"
|
|
870
|
-
];
|
|
871
|
-
}
|
|
872
|
-
get allowedToLog() {
|
|
873
|
-
return this.config ? this.config.get("CONFIG_VERBOSE") !== void 0 && this.config.get("CONFIG_VERBOSE") !== "false" && this.config.get("CONFIG_VERBOSE") !== false : true;
|
|
874
|
-
}
|
|
875
|
-
log(param1, ...args) {
|
|
876
|
-
if (!this.allowedToLog)
|
|
877
|
-
return;
|
|
878
|
-
if (typeof param1 === "string" && this.colors[param1]) {
|
|
879
|
-
console.log(...this.compile(param1, ...args));
|
|
880
|
-
return;
|
|
881
|
-
} else {
|
|
882
|
-
console.log(...this.compile("blue", param1, ...args));
|
|
883
|
-
}
|
|
884
|
-
}
|
|
885
|
-
warning(...args) {
|
|
886
|
-
if (!this.allowedToLog)
|
|
887
|
-
return;
|
|
888
|
-
console.log(...this.compile("yellow", ...args));
|
|
889
|
-
}
|
|
890
|
-
error(...args) {
|
|
891
|
-
if (this.config && this.config.get("CONFIG_IGNORE_ERRORS"))
|
|
892
|
-
return;
|
|
893
|
-
return console.log(...this.compile("red", ...args));
|
|
894
|
-
}
|
|
895
|
-
log_A_Error(error) {
|
|
896
|
-
const time = this.getTime();
|
|
897
|
-
console.log(`\x1B[31m[${this.scope.name}] |${time}| ERROR ${error.code}
|
|
898
|
-
${" ".repeat(this.scopeLength + 3)}| ${error.message}
|
|
899
|
-
${" ".repeat(this.scopeLength + 3)}| ${error.description}
|
|
900
|
-
${" ".repeat(this.scopeLength + 3)}|-------------------------------
|
|
901
|
-
${" ".repeat(this.scopeLength + 3)}| ${error.stack?.split("\n").map((line, index) => index === 0 ? line : `${" ".repeat(this.scopeLength + 3)}| ${line}`).join("\n") || "No stack trace"}
|
|
902
|
-
${" ".repeat(this.scopeLength + 3)}|-------------------------------
|
|
903
|
-
\x1B[0m` + (error.originalError ? `\x1B[31m${" ".repeat(this.scopeLength + 3)}| Wrapped From ${error.originalError.message}
|
|
904
|
-
${" ".repeat(this.scopeLength + 3)}|-------------------------------
|
|
905
|
-
${" ".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"}
|
|
906
|
-
${" ".repeat(this.scopeLength + 3)}|-------------------------------
|
|
907
|
-
\x1B[0m` : "") + (error.link ? `\x1B[31m${" ".repeat(this.scopeLength + 3)}| Read in docs: ${error.link}
|
|
908
|
-
${" ".repeat(this.scopeLength + 3)}|-------------------------------
|
|
909
|
-
\x1B[0m` : ""));
|
|
910
|
-
}
|
|
911
|
-
compile_A_Error(error) {
|
|
912
|
-
this.getTime();
|
|
913
|
-
return `
|
|
914
|
-
${" ".repeat(this.scopeLength + 3)}|-------------------------------
|
|
915
|
-
${" ".repeat(this.scopeLength + 3)}| Error: | ${error.code}
|
|
916
|
-
${" ".repeat(this.scopeLength + 3)}|-------------------------------
|
|
917
|
-
${" ".repeat(this.scopeLength + 3)}|${" ".repeat(10)}| ${error.message}
|
|
918
|
-
${" ".repeat(this.scopeLength + 3)}|${" ".repeat(10)}| ${error.description}
|
|
919
|
-
${" ".repeat(this.scopeLength + 3)}|-------------------------------
|
|
920
|
-
${" ".repeat(this.scopeLength + 3)}| ${error.stack?.split("\n").map((line, index) => index === 0 ? line : `${" ".repeat(this.scopeLength + 3)}| ${line}`).join("\n") || "No stack trace"}
|
|
921
|
-
${" ".repeat(this.scopeLength + 3)}|-------------------------------` + (error.originalError ? `${" ".repeat(this.scopeLength + 3)}| Wrapped From ${error.originalError.message}
|
|
922
|
-
${" ".repeat(this.scopeLength + 3)}|-------------------------------
|
|
923
|
-
${" ".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"}
|
|
924
|
-
${" ".repeat(this.scopeLength + 3)}|-------------------------------` : "") + (error.link ? `${" ".repeat(this.scopeLength + 3)}| Read in docs: ${error.link}
|
|
925
|
-
${" ".repeat(this.scopeLength + 3)}|-------------------------------` : "");
|
|
926
|
-
}
|
|
927
|
-
compile_Error(error) {
|
|
928
|
-
return JSON.stringify({
|
|
929
|
-
name: error.name,
|
|
930
|
-
message: error.message,
|
|
931
|
-
stack: error.stack?.split("\n").map((line, index) => index === 0 ? line : `${" ".repeat(this.scopeLength + 3)}| ${line}`).join("\n")
|
|
932
|
-
}, null, 2).replace(/\n/g, `
|
|
933
|
-
${" ".repeat(this.scopeLength + 3)}| `).replace(/\\n/g, "\n");
|
|
934
|
-
}
|
|
935
|
-
getTime() {
|
|
936
|
-
const now = /* @__PURE__ */ new Date();
|
|
937
|
-
const minutes = String(now.getMinutes()).padStart(2, "0");
|
|
938
|
-
const seconds = String(now.getSeconds()).padStart(2, "0");
|
|
939
|
-
const milliseconds = String(now.getMilliseconds()).padStart(4, "0");
|
|
940
|
-
return `${minutes}:${seconds}:${milliseconds}`;
|
|
941
|
-
}
|
|
942
|
-
};
|
|
943
|
-
A_Logger = __decorateClass([
|
|
944
|
-
__decorateParam(0, A_Inject(A_Scope))
|
|
945
|
-
], A_Logger);
|
|
946
1004
|
var A_FSPolyfillClass = class {
|
|
947
1005
|
constructor(logger) {
|
|
948
1006
|
this.logger = logger;
|
|
@@ -2089,6 +2147,6 @@ var A_Schedule = class extends A_Component {
|
|
|
2089
2147
|
}
|
|
2090
2148
|
};
|
|
2091
2149
|
|
|
2092
|
-
export { A_CONSTANTS_A_Command_Features, A_CONSTANTS__A_Command_Status, A_CONSTANTS__CONFIG_ENV_VARIABLES, A_CONSTANTS__CONFIG_ENV_VARIABLES_ARRAY, A_Channel, A_ChannelError, A_Command, A_CommandError, 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__CommandMetaKey, A_TYPES__ConfigFeature, ConfigReader, ENVConfigReader, FileConfigReader };
|
|
2150
|
+
export { A_CONSTANTS_A_Command_Features, 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_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__CommandMetaKey, A_TYPES__ConfigFeature, ConfigReader, ENVConfigReader, FileConfigReader };
|
|
2093
2151
|
//# sourceMappingURL=index.mjs.map
|
|
2094
2152
|
//# sourceMappingURL=index.mjs.map
|