@punks/backend-core 0.0.38 → 0.0.40

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.
@@ -0,0 +1 @@
1
+ export { logMemoryUsage } from "./resources";
@@ -0,0 +1 @@
1
+ export declare const logMemoryUsage: () => void;
@@ -6,5 +6,8 @@ export declare const processArrayDifferences: <TItem, TInputItem, TId>({ element
6
6
  }) => {
7
7
  missingElements: TInputItem[];
8
8
  exceedingElements: TItem[];
9
- unchangedElements: TItem[];
9
+ correspondingElements: {
10
+ current: TItem;
11
+ desired: TInputItem;
12
+ }[];
10
13
  };
@@ -1,4 +1,5 @@
1
1
  export * from "./abstractions";
2
+ export * from "./diagnostics";
2
3
  export * from "./functions";
3
4
  export * from "./logging";
4
5
  export * from "./models";
package/dist/esm/index.js CHANGED
@@ -16,6 +16,143 @@ 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
+
19
156
  const range = (start, end) => {
20
157
  return new Array(end - start + 1).fill(undefined).map((x, i) => i + start);
21
158
  };
@@ -28365,144 +28502,17 @@ const processArrayDifferences = ({ elements, elementIdSelector, desiredItems, de
28365
28502
  const missingElements = desiredItems.filter((x) => missingElementIds.includes(desiredItemSelector(x)));
28366
28503
  const exceedingElementIds = subArrays(currentElementsIds, desiredItemsIds, (a, b) => a === b);
28367
28504
  const exceedingElements = elements.filter((x) => exceedingElementIds.includes(elementIdSelector(x)));
28368
- const unchangedElementIds = subArrays(currentElementsIds, exceedingElementIds, (a, b) => a === b);
28369
- const unchangedElements = elements.filter((x) => unchangedElementIds.includes(elementIdSelector(x)));
28505
+ const correspondingElementIds = subArrays(currentElementsIds, exceedingElementIds, (a, b) => a === b);
28506
+ const correspondingElements = correspondingElementIds.map((id) => ({
28507
+ current: elements.find((x) => elementIdSelector(x) === id),
28508
+ desired: desiredItems.find((x) => desiredItemSelector(x) === id),
28509
+ }));
28370
28510
  return {
28371
28511
  missingElements,
28372
28512
  exceedingElements,
28373
- unchangedElements,
28513
+ correspondingElements,
28374
28514
  };
28375
28515
  };
28376
28516
 
28377
- class DefaultLogger {
28378
- constructor(loggerName) {
28379
- this.loggerName = loggerName;
28380
- }
28381
- debug(message, meta) {
28382
- if (meta) {
28383
- console.log(`${this.loggerName ? `[${this.loggerName}] ` : ""}${message}`, meta);
28384
- }
28385
- else {
28386
- console.log(`${this.loggerName ? `[${this.loggerName}] ` : ""}${message}`);
28387
- }
28388
- }
28389
- info(message, meta) {
28390
- if (meta) {
28391
- console.info(`${this.loggerName ? `[${this.loggerName}] ` : ""}${message}`, meta);
28392
- }
28393
- else {
28394
- console.info(`${this.loggerName ? `[${this.loggerName}] ` : ""}${message}`);
28395
- }
28396
- }
28397
- warn(message, meta) {
28398
- if (meta) {
28399
- console.warn(`${this.loggerName ? `[${this.loggerName}] ` : ""}${message}`, meta);
28400
- }
28401
- else {
28402
- console.warn(`${this.loggerName ? `[${this.loggerName}] ` : ""}${message}`);
28403
- }
28404
- }
28405
- error(message, meta) {
28406
- if (meta) {
28407
- console.error(`${this.loggerName ? `[${this.loggerName}] ` : ""}${message}`, meta);
28408
- }
28409
- else {
28410
- console.error(`${this.loggerName ? `[${this.loggerName}] ` : ""}${message}`);
28411
- }
28412
- }
28413
- fatal(message, meta) {
28414
- if (meta) {
28415
- console.error(`${this.loggerName ? `[${this.loggerName}] ` : ""}${message}`, meta);
28416
- }
28417
- else {
28418
- console.error(`${this.loggerName ? `[${this.loggerName}] ` : ""}${message}`);
28419
- }
28420
- }
28421
- exception(message, error, meta) {
28422
- if (meta) {
28423
- console.error(`${this.loggerName ? `[${this.loggerName}] ` : ""}${message}`, error, meta);
28424
- }
28425
- else {
28426
- console.error(`${this.loggerName ? `[${this.loggerName}] ` : ""}${message}`, error);
28427
- }
28428
- }
28429
- }
28430
-
28431
- class InternalLogger {
28432
- constructor(options, provider) {
28433
- this.options = options;
28434
- this.provider = provider;
28435
- }
28436
- debug(message, meta) {
28437
- if (this.options.enabled && this.options.level === LogLevel.Debug) {
28438
- this.provider.debug(message, this.serializeMeta(meta));
28439
- }
28440
- }
28441
- info(message, meta) {
28442
- if (this.options.enabled && this.options.level <= LogLevel.Info) {
28443
- this.provider.info(message, this.serializeMeta(meta));
28444
- }
28445
- }
28446
- warn(message, meta) {
28447
- if (this.options.enabled && this.options.level <= LogLevel.Warn) {
28448
- this.provider.warn(message, this.serializeMeta(meta));
28449
- }
28450
- }
28451
- error(message, meta) {
28452
- if (this.options.enabled && this.options.level <= LogLevel.Error) {
28453
- this.provider.error(message, this.serializeMeta(meta));
28454
- }
28455
- }
28456
- fatal(message, meta) {
28457
- if (this.options.enabled && this.options.level <= LogLevel.Fatal) {
28458
- this.provider.fatal(message, this.serializeMeta(meta));
28459
- }
28460
- }
28461
- exception(message, error, meta) {
28462
- if (this.options.enabled && this.options.level <= LogLevel.Error) {
28463
- this.provider.exception(message, error, this.serializeMeta(meta));
28464
- }
28465
- }
28466
- serializeMeta(meta) {
28467
- switch (this.options.serialization) {
28468
- case MetaSerializationType.JSON:
28469
- return JSON.stringify(meta, null, 2);
28470
- case MetaSerializationType.None:
28471
- default:
28472
- return meta;
28473
- }
28474
- }
28475
- }
28476
- const getLogger = ({ options, loggerName, }) => {
28477
- return new InternalLogger(options, new DefaultLogger(loggerName));
28478
- };
28479
- class Log {
28480
- static setSerializationType(type) {
28481
- this.options.serialization = type;
28482
- }
28483
- static setLevel(level) {
28484
- this.options.level = level;
28485
- this.options.level = level;
28486
- this.options.enabled = true;
28487
- }
28488
- static enable() {
28489
- this.options.enabled = true;
28490
- }
28491
- static disable() {
28492
- this.options.enabled = false;
28493
- }
28494
- static getLogger(loggerName) {
28495
- return getLogger({
28496
- options: this.options,
28497
- loggerName,
28498
- });
28499
- }
28500
- }
28501
- Log.options = {
28502
- enabled: true,
28503
- level: LogLevel.Debug,
28504
- serialization: MetaSerializationType.None,
28505
- };
28506
-
28507
- 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, mapOrThrow, mergeDeep, newUuid, notNull, notUndefined, pluralize, processArrayDifferences, range, removeUndefinedProps, selectMany, sleep, sort, splitPath, subArrays, subtractTime, toCamelCase, toDict, toItemsDict, toItemsMap, toMap, toTitleCase, trim$1 as trim, trimEnd, trimStart };
28517
+ 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, range, removeUndefinedProps, selectMany, sleep, sort, splitPath, subArrays, subtractTime, toCamelCase, toDict, toItemsDict, toItemsMap, toMap, toTitleCase, trim$1 as trim, trimEnd, trimStart };
28508
28518
  //# sourceMappingURL=index.js.map