@punks/backend-core 0.0.44 → 0.0.46
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/cjs/index.js +147 -138
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/types/utils/objects/index.d.ts +1 -0
- package/dist/esm/index.js +147 -138
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/types/utils/objects/index.d.ts +1 -0
- package/dist/index.d.ts +1 -0
- package/package.json +1 -1
package/dist/cjs/index.js
CHANGED
|
@@ -25,143 +25,6 @@ exports.MetaSerializationType = void 0;
|
|
|
25
25
|
MetaSerializationType[MetaSerializationType["JSON"] = 1] = "JSON";
|
|
26
26
|
})(exports.MetaSerializationType || (exports.MetaSerializationType = {}));
|
|
27
27
|
|
|
28
|
-
class DefaultLogger {
|
|
29
|
-
constructor(loggerName) {
|
|
30
|
-
this.loggerName = loggerName;
|
|
31
|
-
}
|
|
32
|
-
debug(message, meta) {
|
|
33
|
-
if (meta) {
|
|
34
|
-
console.log(`${this.loggerName ? `[${this.loggerName}] ` : ""}${message}`, meta);
|
|
35
|
-
}
|
|
36
|
-
else {
|
|
37
|
-
console.log(`${this.loggerName ? `[${this.loggerName}] ` : ""}${message}`);
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
info(message, meta) {
|
|
41
|
-
if (meta) {
|
|
42
|
-
console.info(`${this.loggerName ? `[${this.loggerName}] ` : ""}${message}`, meta);
|
|
43
|
-
}
|
|
44
|
-
else {
|
|
45
|
-
console.info(`${this.loggerName ? `[${this.loggerName}] ` : ""}${message}`);
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
warn(message, meta) {
|
|
49
|
-
if (meta) {
|
|
50
|
-
console.warn(`${this.loggerName ? `[${this.loggerName}] ` : ""}${message}`, meta);
|
|
51
|
-
}
|
|
52
|
-
else {
|
|
53
|
-
console.warn(`${this.loggerName ? `[${this.loggerName}] ` : ""}${message}`);
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
error(message, meta) {
|
|
57
|
-
if (meta) {
|
|
58
|
-
console.error(`${this.loggerName ? `[${this.loggerName}] ` : ""}${message}`, meta);
|
|
59
|
-
}
|
|
60
|
-
else {
|
|
61
|
-
console.error(`${this.loggerName ? `[${this.loggerName}] ` : ""}${message}`);
|
|
62
|
-
}
|
|
63
|
-
}
|
|
64
|
-
fatal(message, meta) {
|
|
65
|
-
if (meta) {
|
|
66
|
-
console.error(`${this.loggerName ? `[${this.loggerName}] ` : ""}${message}`, meta);
|
|
67
|
-
}
|
|
68
|
-
else {
|
|
69
|
-
console.error(`${this.loggerName ? `[${this.loggerName}] ` : ""}${message}`);
|
|
70
|
-
}
|
|
71
|
-
}
|
|
72
|
-
exception(message, error, meta) {
|
|
73
|
-
if (meta) {
|
|
74
|
-
console.error(`${this.loggerName ? `[${this.loggerName}] ` : ""}${message}`, error, meta);
|
|
75
|
-
}
|
|
76
|
-
else {
|
|
77
|
-
console.error(`${this.loggerName ? `[${this.loggerName}] ` : ""}${message}`, error);
|
|
78
|
-
}
|
|
79
|
-
}
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
class InternalLogger {
|
|
83
|
-
constructor(options, provider) {
|
|
84
|
-
this.options = options;
|
|
85
|
-
this.provider = provider;
|
|
86
|
-
}
|
|
87
|
-
debug(message, meta) {
|
|
88
|
-
if (this.options.enabled && this.options.level === exports.LogLevel.Debug) {
|
|
89
|
-
this.provider.debug(message, this.serializeMeta(meta));
|
|
90
|
-
}
|
|
91
|
-
}
|
|
92
|
-
info(message, meta) {
|
|
93
|
-
if (this.options.enabled && this.options.level <= exports.LogLevel.Info) {
|
|
94
|
-
this.provider.info(message, this.serializeMeta(meta));
|
|
95
|
-
}
|
|
96
|
-
}
|
|
97
|
-
warn(message, meta) {
|
|
98
|
-
if (this.options.enabled && this.options.level <= exports.LogLevel.Warn) {
|
|
99
|
-
this.provider.warn(message, this.serializeMeta(meta));
|
|
100
|
-
}
|
|
101
|
-
}
|
|
102
|
-
error(message, meta) {
|
|
103
|
-
if (this.options.enabled && this.options.level <= exports.LogLevel.Error) {
|
|
104
|
-
this.provider.error(message, this.serializeMeta(meta));
|
|
105
|
-
}
|
|
106
|
-
}
|
|
107
|
-
fatal(message, meta) {
|
|
108
|
-
if (this.options.enabled && this.options.level <= exports.LogLevel.Fatal) {
|
|
109
|
-
this.provider.fatal(message, this.serializeMeta(meta));
|
|
110
|
-
}
|
|
111
|
-
}
|
|
112
|
-
exception(message, error, meta) {
|
|
113
|
-
if (this.options.enabled && this.options.level <= exports.LogLevel.Error) {
|
|
114
|
-
this.provider.exception(message, error, this.serializeMeta(meta));
|
|
115
|
-
}
|
|
116
|
-
}
|
|
117
|
-
serializeMeta(meta) {
|
|
118
|
-
switch (this.options.serialization) {
|
|
119
|
-
case exports.MetaSerializationType.JSON:
|
|
120
|
-
return JSON.stringify(meta, null, 2);
|
|
121
|
-
case exports.MetaSerializationType.None:
|
|
122
|
-
default:
|
|
123
|
-
return meta;
|
|
124
|
-
}
|
|
125
|
-
}
|
|
126
|
-
}
|
|
127
|
-
const getLogger = ({ options, loggerName, }) => {
|
|
128
|
-
return new InternalLogger(options, new DefaultLogger(loggerName));
|
|
129
|
-
};
|
|
130
|
-
class Log {
|
|
131
|
-
static setSerializationType(type) {
|
|
132
|
-
this.options.serialization = type;
|
|
133
|
-
}
|
|
134
|
-
static setLevel(level) {
|
|
135
|
-
this.options.level = level;
|
|
136
|
-
this.options.level = level;
|
|
137
|
-
this.options.enabled = true;
|
|
138
|
-
}
|
|
139
|
-
static enable() {
|
|
140
|
-
this.options.enabled = true;
|
|
141
|
-
}
|
|
142
|
-
static disable() {
|
|
143
|
-
this.options.enabled = false;
|
|
144
|
-
}
|
|
145
|
-
static getLogger(loggerName) {
|
|
146
|
-
return getLogger({
|
|
147
|
-
options: this.options,
|
|
148
|
-
loggerName,
|
|
149
|
-
});
|
|
150
|
-
}
|
|
151
|
-
}
|
|
152
|
-
Log.options = {
|
|
153
|
-
enabled: true,
|
|
154
|
-
level: exports.LogLevel.Debug,
|
|
155
|
-
serialization: exports.MetaSerializationType.None,
|
|
156
|
-
};
|
|
157
|
-
|
|
158
|
-
const logMemoryUsage = () => {
|
|
159
|
-
const usedMemory = process.memoryUsage();
|
|
160
|
-
Log.getLogger("Diagnostics").debug(`Memory usage: \n${Object.keys(usedMemory)
|
|
161
|
-
.map((x) => `${x} ${Math.round((usedMemory[x] / 1024 / 1024) * 100) / 100} MB`)
|
|
162
|
-
.join("\n")}`);
|
|
163
|
-
};
|
|
164
|
-
|
|
165
28
|
const range = (start, end) => {
|
|
166
29
|
return new Array(end - start + 1).fill(undefined).map((x, i) => i + start);
|
|
167
30
|
};
|
|
@@ -434,8 +297,13 @@ const mergeDeep = (a, b) => {
|
|
|
434
297
|
return c;
|
|
435
298
|
};
|
|
436
299
|
const jsonSerialize = (obj, options) => {
|
|
437
|
-
const { stripBinaryData = true, prettify = false } = options ?? {};
|
|
300
|
+
const { stripBinaryData = true, prettify = false, maxStringsLength, } = options ?? {};
|
|
438
301
|
const replacer = (key, value) => {
|
|
302
|
+
if (typeof value === "string" && maxStringsLength) {
|
|
303
|
+
return value.length > maxStringsLength
|
|
304
|
+
? `${value.substring(0, maxStringsLength)}...`
|
|
305
|
+
: value;
|
|
306
|
+
}
|
|
439
307
|
if (stripBinaryData) {
|
|
440
308
|
if (value instanceof Buffer) {
|
|
441
309
|
return `<binary data (${value.length} bytes)>`;
|
|
@@ -28522,6 +28390,147 @@ const excelParse = (file, options) => {
|
|
|
28522
28390
|
.map((x) => aggregateRow(header, x, options));
|
|
28523
28391
|
};
|
|
28524
28392
|
|
|
28393
|
+
class DefaultLogger {
|
|
28394
|
+
constructor(loggerName) {
|
|
28395
|
+
this.loggerName = loggerName;
|
|
28396
|
+
}
|
|
28397
|
+
debug(message, meta) {
|
|
28398
|
+
if (meta) {
|
|
28399
|
+
console.log(`${this.loggerName ? `[${this.loggerName}] ` : ""}${message}`, meta);
|
|
28400
|
+
}
|
|
28401
|
+
else {
|
|
28402
|
+
console.log(`${this.loggerName ? `[${this.loggerName}] ` : ""}${message}`);
|
|
28403
|
+
}
|
|
28404
|
+
}
|
|
28405
|
+
info(message, meta) {
|
|
28406
|
+
if (meta) {
|
|
28407
|
+
console.info(`${this.loggerName ? `[${this.loggerName}] ` : ""}${message}`, meta);
|
|
28408
|
+
}
|
|
28409
|
+
else {
|
|
28410
|
+
console.info(`${this.loggerName ? `[${this.loggerName}] ` : ""}${message}`);
|
|
28411
|
+
}
|
|
28412
|
+
}
|
|
28413
|
+
warn(message, meta) {
|
|
28414
|
+
if (meta) {
|
|
28415
|
+
console.warn(`${this.loggerName ? `[${this.loggerName}] ` : ""}${message}`, meta);
|
|
28416
|
+
}
|
|
28417
|
+
else {
|
|
28418
|
+
console.warn(`${this.loggerName ? `[${this.loggerName}] ` : ""}${message}`);
|
|
28419
|
+
}
|
|
28420
|
+
}
|
|
28421
|
+
error(message, meta) {
|
|
28422
|
+
if (meta) {
|
|
28423
|
+
console.error(`${this.loggerName ? `[${this.loggerName}] ` : ""}${message}`, meta);
|
|
28424
|
+
}
|
|
28425
|
+
else {
|
|
28426
|
+
console.error(`${this.loggerName ? `[${this.loggerName}] ` : ""}${message}`);
|
|
28427
|
+
}
|
|
28428
|
+
}
|
|
28429
|
+
fatal(message, meta) {
|
|
28430
|
+
if (meta) {
|
|
28431
|
+
console.error(`${this.loggerName ? `[${this.loggerName}] ` : ""}${message}`, meta);
|
|
28432
|
+
}
|
|
28433
|
+
else {
|
|
28434
|
+
console.error(`${this.loggerName ? `[${this.loggerName}] ` : ""}${message}`);
|
|
28435
|
+
}
|
|
28436
|
+
}
|
|
28437
|
+
exception(message, error, meta) {
|
|
28438
|
+
if (meta) {
|
|
28439
|
+
console.error(`${this.loggerName ? `[${this.loggerName}] ` : ""}${message}`, error, meta);
|
|
28440
|
+
}
|
|
28441
|
+
else {
|
|
28442
|
+
console.error(`${this.loggerName ? `[${this.loggerName}] ` : ""}${message}`, error);
|
|
28443
|
+
}
|
|
28444
|
+
}
|
|
28445
|
+
}
|
|
28446
|
+
|
|
28447
|
+
class InternalLogger {
|
|
28448
|
+
constructor(options, provider) {
|
|
28449
|
+
this.options = options;
|
|
28450
|
+
this.provider = provider;
|
|
28451
|
+
}
|
|
28452
|
+
debug(message, meta) {
|
|
28453
|
+
if (this.options.enabled && this.options.level === exports.LogLevel.Debug) {
|
|
28454
|
+
this.provider.debug(message, this.serializeMeta(meta));
|
|
28455
|
+
}
|
|
28456
|
+
}
|
|
28457
|
+
info(message, meta) {
|
|
28458
|
+
if (this.options.enabled && this.options.level <= exports.LogLevel.Info) {
|
|
28459
|
+
this.provider.info(message, this.serializeMeta(meta));
|
|
28460
|
+
}
|
|
28461
|
+
}
|
|
28462
|
+
warn(message, meta) {
|
|
28463
|
+
if (this.options.enabled && this.options.level <= exports.LogLevel.Warn) {
|
|
28464
|
+
this.provider.warn(message, this.serializeMeta(meta));
|
|
28465
|
+
}
|
|
28466
|
+
}
|
|
28467
|
+
error(message, meta) {
|
|
28468
|
+
if (this.options.enabled && this.options.level <= exports.LogLevel.Error) {
|
|
28469
|
+
this.provider.error(message, this.serializeMeta(meta));
|
|
28470
|
+
}
|
|
28471
|
+
}
|
|
28472
|
+
fatal(message, meta) {
|
|
28473
|
+
if (this.options.enabled && this.options.level <= exports.LogLevel.Fatal) {
|
|
28474
|
+
this.provider.fatal(message, this.serializeMeta(meta));
|
|
28475
|
+
}
|
|
28476
|
+
}
|
|
28477
|
+
exception(message, error, meta) {
|
|
28478
|
+
if (this.options.enabled && this.options.level <= exports.LogLevel.Error) {
|
|
28479
|
+
this.provider.exception(message, error, this.serializeMeta(meta));
|
|
28480
|
+
}
|
|
28481
|
+
}
|
|
28482
|
+
serializeMeta(meta) {
|
|
28483
|
+
const serializedMeta = jsonSerialize(meta, {
|
|
28484
|
+
prettify: true,
|
|
28485
|
+
stripBinaryData: true,
|
|
28486
|
+
});
|
|
28487
|
+
switch (this.options.serialization) {
|
|
28488
|
+
case exports.MetaSerializationType.JSON:
|
|
28489
|
+
return serializedMeta;
|
|
28490
|
+
case exports.MetaSerializationType.None:
|
|
28491
|
+
default:
|
|
28492
|
+
return JSON.parse(serializedMeta);
|
|
28493
|
+
}
|
|
28494
|
+
}
|
|
28495
|
+
}
|
|
28496
|
+
const getLogger = ({ options, loggerName, }) => {
|
|
28497
|
+
return new InternalLogger(options, new DefaultLogger(loggerName));
|
|
28498
|
+
};
|
|
28499
|
+
class Log {
|
|
28500
|
+
static setSerializationType(type) {
|
|
28501
|
+
this.options.serialization = type;
|
|
28502
|
+
}
|
|
28503
|
+
static setLevel(level) {
|
|
28504
|
+
this.options.level = level;
|
|
28505
|
+
this.options.level = level;
|
|
28506
|
+
this.options.enabled = true;
|
|
28507
|
+
}
|
|
28508
|
+
static enable() {
|
|
28509
|
+
this.options.enabled = true;
|
|
28510
|
+
}
|
|
28511
|
+
static disable() {
|
|
28512
|
+
this.options.enabled = false;
|
|
28513
|
+
}
|
|
28514
|
+
static getLogger(loggerName) {
|
|
28515
|
+
return getLogger({
|
|
28516
|
+
options: this.options,
|
|
28517
|
+
loggerName,
|
|
28518
|
+
});
|
|
28519
|
+
}
|
|
28520
|
+
}
|
|
28521
|
+
Log.options = {
|
|
28522
|
+
enabled: true,
|
|
28523
|
+
level: exports.LogLevel.Debug,
|
|
28524
|
+
serialization: exports.MetaSerializationType.None,
|
|
28525
|
+
};
|
|
28526
|
+
|
|
28527
|
+
const logMemoryUsage = () => {
|
|
28528
|
+
const usedMemory = process.memoryUsage();
|
|
28529
|
+
Log.getLogger("Diagnostics").debug(`Memory usage: \n${Object.keys(usedMemory)
|
|
28530
|
+
.map((x) => `${x} ${Math.round((usedMemory[x] / 1024 / 1024) * 100) / 100} MB`)
|
|
28531
|
+
.join("\n")}`);
|
|
28532
|
+
};
|
|
28533
|
+
|
|
28525
28534
|
const processArrayDifferences = ({ elements, elementIdSelector, desiredItems, desiredItemSelector, }) => {
|
|
28526
28535
|
const currentElementsIds = elements.map(elementIdSelector);
|
|
28527
28536
|
const desiredItemsIds = desiredItems.map(desiredItemSelector);
|