@punks/backend-core 0.0.43 → 0.0.45
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 +160 -137
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/types/utils/objects/index.d.ts +4 -0
- package/dist/cjs/types/utils/objects/jsonSerialize.spec.d.ts +1 -0
- package/dist/esm/index.js +160 -138
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/types/utils/objects/index.d.ts +4 -0
- package/dist/esm/types/utils/objects/jsonSerialize.spec.d.ts +1 -0
- package/dist/index.d.ts +5 -1
- package/package.json +1 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
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
|
};
|
|
@@ -424,6 +287,24 @@ const mergeDeep = (a, b) => {
|
|
|
424
287
|
}
|
|
425
288
|
return c;
|
|
426
289
|
};
|
|
290
|
+
const jsonSerialize = (obj, options) => {
|
|
291
|
+
const { stripBinaryData = true, prettify = false } = options ?? {};
|
|
292
|
+
const replacer = (key, value) => {
|
|
293
|
+
if (stripBinaryData) {
|
|
294
|
+
if (value instanceof Buffer) {
|
|
295
|
+
return `<binary data (${value.length} bytes)>`;
|
|
296
|
+
}
|
|
297
|
+
if (typeof value === "object" &&
|
|
298
|
+
value.type === "Buffer" &&
|
|
299
|
+
Array.isArray(value.data)) {
|
|
300
|
+
return `<binary data (${value.data.length} bytes)>`;
|
|
301
|
+
}
|
|
302
|
+
}
|
|
303
|
+
return value;
|
|
304
|
+
};
|
|
305
|
+
const spaces = prettify ? 2 : undefined;
|
|
306
|
+
return JSON.stringify(obj, replacer, spaces);
|
|
307
|
+
};
|
|
427
308
|
|
|
428
309
|
const pluralize = (word) => {
|
|
429
310
|
return word.endsWith("s") ? `${word}es` : `${word}s`;
|
|
@@ -28495,6 +28376,147 @@ const excelParse = (file, options) => {
|
|
|
28495
28376
|
.map((x) => aggregateRow(header, x, options));
|
|
28496
28377
|
};
|
|
28497
28378
|
|
|
28379
|
+
class DefaultLogger {
|
|
28380
|
+
constructor(loggerName) {
|
|
28381
|
+
this.loggerName = loggerName;
|
|
28382
|
+
}
|
|
28383
|
+
debug(message, meta) {
|
|
28384
|
+
if (meta) {
|
|
28385
|
+
console.log(`${this.loggerName ? `[${this.loggerName}] ` : ""}${message}`, meta);
|
|
28386
|
+
}
|
|
28387
|
+
else {
|
|
28388
|
+
console.log(`${this.loggerName ? `[${this.loggerName}] ` : ""}${message}`);
|
|
28389
|
+
}
|
|
28390
|
+
}
|
|
28391
|
+
info(message, meta) {
|
|
28392
|
+
if (meta) {
|
|
28393
|
+
console.info(`${this.loggerName ? `[${this.loggerName}] ` : ""}${message}`, meta);
|
|
28394
|
+
}
|
|
28395
|
+
else {
|
|
28396
|
+
console.info(`${this.loggerName ? `[${this.loggerName}] ` : ""}${message}`);
|
|
28397
|
+
}
|
|
28398
|
+
}
|
|
28399
|
+
warn(message, meta) {
|
|
28400
|
+
if (meta) {
|
|
28401
|
+
console.warn(`${this.loggerName ? `[${this.loggerName}] ` : ""}${message}`, meta);
|
|
28402
|
+
}
|
|
28403
|
+
else {
|
|
28404
|
+
console.warn(`${this.loggerName ? `[${this.loggerName}] ` : ""}${message}`);
|
|
28405
|
+
}
|
|
28406
|
+
}
|
|
28407
|
+
error(message, meta) {
|
|
28408
|
+
if (meta) {
|
|
28409
|
+
console.error(`${this.loggerName ? `[${this.loggerName}] ` : ""}${message}`, meta);
|
|
28410
|
+
}
|
|
28411
|
+
else {
|
|
28412
|
+
console.error(`${this.loggerName ? `[${this.loggerName}] ` : ""}${message}`);
|
|
28413
|
+
}
|
|
28414
|
+
}
|
|
28415
|
+
fatal(message, meta) {
|
|
28416
|
+
if (meta) {
|
|
28417
|
+
console.error(`${this.loggerName ? `[${this.loggerName}] ` : ""}${message}`, meta);
|
|
28418
|
+
}
|
|
28419
|
+
else {
|
|
28420
|
+
console.error(`${this.loggerName ? `[${this.loggerName}] ` : ""}${message}`);
|
|
28421
|
+
}
|
|
28422
|
+
}
|
|
28423
|
+
exception(message, error, meta) {
|
|
28424
|
+
if (meta) {
|
|
28425
|
+
console.error(`${this.loggerName ? `[${this.loggerName}] ` : ""}${message}`, error, meta);
|
|
28426
|
+
}
|
|
28427
|
+
else {
|
|
28428
|
+
console.error(`${this.loggerName ? `[${this.loggerName}] ` : ""}${message}`, error);
|
|
28429
|
+
}
|
|
28430
|
+
}
|
|
28431
|
+
}
|
|
28432
|
+
|
|
28433
|
+
class InternalLogger {
|
|
28434
|
+
constructor(options, provider) {
|
|
28435
|
+
this.options = options;
|
|
28436
|
+
this.provider = provider;
|
|
28437
|
+
}
|
|
28438
|
+
debug(message, meta) {
|
|
28439
|
+
if (this.options.enabled && this.options.level === LogLevel.Debug) {
|
|
28440
|
+
this.provider.debug(message, this.serializeMeta(meta));
|
|
28441
|
+
}
|
|
28442
|
+
}
|
|
28443
|
+
info(message, meta) {
|
|
28444
|
+
if (this.options.enabled && this.options.level <= LogLevel.Info) {
|
|
28445
|
+
this.provider.info(message, this.serializeMeta(meta));
|
|
28446
|
+
}
|
|
28447
|
+
}
|
|
28448
|
+
warn(message, meta) {
|
|
28449
|
+
if (this.options.enabled && this.options.level <= LogLevel.Warn) {
|
|
28450
|
+
this.provider.warn(message, this.serializeMeta(meta));
|
|
28451
|
+
}
|
|
28452
|
+
}
|
|
28453
|
+
error(message, meta) {
|
|
28454
|
+
if (this.options.enabled && this.options.level <= LogLevel.Error) {
|
|
28455
|
+
this.provider.error(message, this.serializeMeta(meta));
|
|
28456
|
+
}
|
|
28457
|
+
}
|
|
28458
|
+
fatal(message, meta) {
|
|
28459
|
+
if (this.options.enabled && this.options.level <= LogLevel.Fatal) {
|
|
28460
|
+
this.provider.fatal(message, this.serializeMeta(meta));
|
|
28461
|
+
}
|
|
28462
|
+
}
|
|
28463
|
+
exception(message, error, meta) {
|
|
28464
|
+
if (this.options.enabled && this.options.level <= LogLevel.Error) {
|
|
28465
|
+
this.provider.exception(message, error, this.serializeMeta(meta));
|
|
28466
|
+
}
|
|
28467
|
+
}
|
|
28468
|
+
serializeMeta(meta) {
|
|
28469
|
+
const serializedMeta = jsonSerialize(meta, {
|
|
28470
|
+
prettify: true,
|
|
28471
|
+
stripBinaryData: true,
|
|
28472
|
+
});
|
|
28473
|
+
switch (this.options.serialization) {
|
|
28474
|
+
case MetaSerializationType.JSON:
|
|
28475
|
+
return serializedMeta;
|
|
28476
|
+
case MetaSerializationType.None:
|
|
28477
|
+
default:
|
|
28478
|
+
return JSON.parse(serializedMeta);
|
|
28479
|
+
}
|
|
28480
|
+
}
|
|
28481
|
+
}
|
|
28482
|
+
const getLogger = ({ options, loggerName, }) => {
|
|
28483
|
+
return new InternalLogger(options, new DefaultLogger(loggerName));
|
|
28484
|
+
};
|
|
28485
|
+
class Log {
|
|
28486
|
+
static setSerializationType(type) {
|
|
28487
|
+
this.options.serialization = type;
|
|
28488
|
+
}
|
|
28489
|
+
static setLevel(level) {
|
|
28490
|
+
this.options.level = level;
|
|
28491
|
+
this.options.level = level;
|
|
28492
|
+
this.options.enabled = true;
|
|
28493
|
+
}
|
|
28494
|
+
static enable() {
|
|
28495
|
+
this.options.enabled = true;
|
|
28496
|
+
}
|
|
28497
|
+
static disable() {
|
|
28498
|
+
this.options.enabled = false;
|
|
28499
|
+
}
|
|
28500
|
+
static getLogger(loggerName) {
|
|
28501
|
+
return getLogger({
|
|
28502
|
+
options: this.options,
|
|
28503
|
+
loggerName,
|
|
28504
|
+
});
|
|
28505
|
+
}
|
|
28506
|
+
}
|
|
28507
|
+
Log.options = {
|
|
28508
|
+
enabled: true,
|
|
28509
|
+
level: LogLevel.Debug,
|
|
28510
|
+
serialization: MetaSerializationType.None,
|
|
28511
|
+
};
|
|
28512
|
+
|
|
28513
|
+
const logMemoryUsage = () => {
|
|
28514
|
+
const usedMemory = process.memoryUsage();
|
|
28515
|
+
Log.getLogger("Diagnostics").debug(`Memory usage: \n${Object.keys(usedMemory)
|
|
28516
|
+
.map((x) => `${x} ${Math.round((usedMemory[x] / 1024 / 1024) * 100) / 100} MB`)
|
|
28517
|
+
.join("\n")}`);
|
|
28518
|
+
};
|
|
28519
|
+
|
|
28498
28520
|
const processArrayDifferences = ({ elements, elementIdSelector, desiredItems, desiredItemSelector, }) => {
|
|
28499
28521
|
const currentElementsIds = elements.map(elementIdSelector);
|
|
28500
28522
|
const desiredItemsIds = desiredItems.map(desiredItemSelector);
|
|
@@ -28527,5 +28549,5 @@ const processArrayItemMove = (items, input) => {
|
|
|
28527
28549
|
}));
|
|
28528
28550
|
};
|
|
28529
28551
|
|
|
28530
|
-
export { ExcelKeyTransform, Log, LogLevel, MetaSerializationType, addTime, buildObject, buildTree, byField, byFieldDesc, camelToKebabCase, camelToSnakeCase, csvBuild, csvParse, distinct, distinctElements, ensureDirectory, ensureStartSlash, ensureTailingSlash, excelBuild, excelParse, first, flatten, getDirectoryFilePaths, getDirectoryPath, groupBy, indexes, isNullOrUndefined, iterate, joinPath, jsonDistinct, last, logMemoryUsage, mapOrThrow, mergeDeep, newUuid, notNull, notUndefined, pluralize, processArrayDifferences, processArrayItemMove, range, removeUndefinedProps, selectMany, sleep, sort, splitPath, subArrays, subtractTime, toCamelCase, toDict, toItemsDict, toItemsMap, toMap, toTitleCase, trim$1 as trim, trimEnd, trimStart };
|
|
28552
|
+
export { ExcelKeyTransform, Log, LogLevel, MetaSerializationType, addTime, buildObject, buildTree, byField, byFieldDesc, camelToKebabCase, camelToSnakeCase, csvBuild, csvParse, distinct, distinctElements, ensureDirectory, ensureStartSlash, ensureTailingSlash, excelBuild, excelParse, first, flatten, getDirectoryFilePaths, getDirectoryPath, groupBy, indexes, isNullOrUndefined, iterate, joinPath, jsonDistinct, jsonSerialize, last, logMemoryUsage, mapOrThrow, mergeDeep, newUuid, notNull, notUndefined, pluralize, processArrayDifferences, processArrayItemMove, range, removeUndefinedProps, selectMany, sleep, sort, splitPath, subArrays, subtractTime, toCamelCase, toDict, toItemsDict, toItemsMap, toMap, toTitleCase, trim$1 as trim, trimEnd, trimStart };
|
|
28531
28553
|
//# sourceMappingURL=index.js.map
|