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