@punks/backend-core 0.0.39 → 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;
@@ -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
  };
@@ -28377,135 +28514,5 @@ const processArrayDifferences = ({ elements, elementIdSelector, desiredItems, de
28377
28514
  };
28378
28515
  };
28379
28516
 
28380
- class DefaultLogger {
28381
- constructor(loggerName) {
28382
- this.loggerName = loggerName;
28383
- }
28384
- debug(message, meta) {
28385
- if (meta) {
28386
- console.log(`${this.loggerName ? `[${this.loggerName}] ` : ""}${message}`, meta);
28387
- }
28388
- else {
28389
- console.log(`${this.loggerName ? `[${this.loggerName}] ` : ""}${message}`);
28390
- }
28391
- }
28392
- info(message, meta) {
28393
- if (meta) {
28394
- console.info(`${this.loggerName ? `[${this.loggerName}] ` : ""}${message}`, meta);
28395
- }
28396
- else {
28397
- console.info(`${this.loggerName ? `[${this.loggerName}] ` : ""}${message}`);
28398
- }
28399
- }
28400
- warn(message, meta) {
28401
- if (meta) {
28402
- console.warn(`${this.loggerName ? `[${this.loggerName}] ` : ""}${message}`, meta);
28403
- }
28404
- else {
28405
- console.warn(`${this.loggerName ? `[${this.loggerName}] ` : ""}${message}`);
28406
- }
28407
- }
28408
- error(message, meta) {
28409
- if (meta) {
28410
- console.error(`${this.loggerName ? `[${this.loggerName}] ` : ""}${message}`, meta);
28411
- }
28412
- else {
28413
- console.error(`${this.loggerName ? `[${this.loggerName}] ` : ""}${message}`);
28414
- }
28415
- }
28416
- fatal(message, meta) {
28417
- if (meta) {
28418
- console.error(`${this.loggerName ? `[${this.loggerName}] ` : ""}${message}`, meta);
28419
- }
28420
- else {
28421
- console.error(`${this.loggerName ? `[${this.loggerName}] ` : ""}${message}`);
28422
- }
28423
- }
28424
- exception(message, error, meta) {
28425
- if (meta) {
28426
- console.error(`${this.loggerName ? `[${this.loggerName}] ` : ""}${message}`, error, meta);
28427
- }
28428
- else {
28429
- console.error(`${this.loggerName ? `[${this.loggerName}] ` : ""}${message}`, error);
28430
- }
28431
- }
28432
- }
28433
-
28434
- class InternalLogger {
28435
- constructor(options, provider) {
28436
- this.options = options;
28437
- this.provider = provider;
28438
- }
28439
- debug(message, meta) {
28440
- if (this.options.enabled && this.options.level === LogLevel.Debug) {
28441
- this.provider.debug(message, this.serializeMeta(meta));
28442
- }
28443
- }
28444
- info(message, meta) {
28445
- if (this.options.enabled && this.options.level <= LogLevel.Info) {
28446
- this.provider.info(message, this.serializeMeta(meta));
28447
- }
28448
- }
28449
- warn(message, meta) {
28450
- if (this.options.enabled && this.options.level <= LogLevel.Warn) {
28451
- this.provider.warn(message, this.serializeMeta(meta));
28452
- }
28453
- }
28454
- error(message, meta) {
28455
- if (this.options.enabled && this.options.level <= LogLevel.Error) {
28456
- this.provider.error(message, this.serializeMeta(meta));
28457
- }
28458
- }
28459
- fatal(message, meta) {
28460
- if (this.options.enabled && this.options.level <= LogLevel.Fatal) {
28461
- this.provider.fatal(message, this.serializeMeta(meta));
28462
- }
28463
- }
28464
- exception(message, error, meta) {
28465
- if (this.options.enabled && this.options.level <= LogLevel.Error) {
28466
- this.provider.exception(message, error, this.serializeMeta(meta));
28467
- }
28468
- }
28469
- serializeMeta(meta) {
28470
- switch (this.options.serialization) {
28471
- case MetaSerializationType.JSON:
28472
- return JSON.stringify(meta, null, 2);
28473
- case MetaSerializationType.None:
28474
- default:
28475
- return meta;
28476
- }
28477
- }
28478
- }
28479
- const getLogger = ({ options, loggerName, }) => {
28480
- return new InternalLogger(options, new DefaultLogger(loggerName));
28481
- };
28482
- class Log {
28483
- static setSerializationType(type) {
28484
- this.options.serialization = type;
28485
- }
28486
- static setLevel(level) {
28487
- this.options.level = level;
28488
- this.options.level = level;
28489
- this.options.enabled = true;
28490
- }
28491
- static enable() {
28492
- this.options.enabled = true;
28493
- }
28494
- static disable() {
28495
- this.options.enabled = false;
28496
- }
28497
- static getLogger(loggerName) {
28498
- return getLogger({
28499
- options: this.options,
28500
- loggerName,
28501
- });
28502
- }
28503
- }
28504
- Log.options = {
28505
- enabled: true,
28506
- level: LogLevel.Debug,
28507
- serialization: MetaSerializationType.None,
28508
- };
28509
-
28510
- 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 };
28511
28518
  //# sourceMappingURL=index.js.map