@akanjs/common 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.
Files changed (2) hide show
  1. package/index.js +338 -319
  2. package/package.json +1 -1
package/index.js CHANGED
@@ -1,344 +1,363 @@
1
- (() => {
2
- var __create = Object.create;
3
- var __defProp = Object.defineProperty;
4
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
- var __getOwnPropNames = Object.getOwnPropertyNames;
6
- var __getProtoOf = Object.getPrototypeOf;
7
- var __hasOwnProp = Object.prototype.hasOwnProperty;
8
- var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
9
- get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
10
- }) : x)(function(x) {
11
- if (typeof require !== "undefined")
12
- return require.apply(this, arguments);
13
- throw Error('Dynamic require of "' + x + '" is not supported');
14
- });
15
- var __copyProps = (to, from, except, desc) => {
16
- if (from && typeof from === "object" || typeof from === "function") {
17
- for (let key of __getOwnPropNames(from))
18
- if (!__hasOwnProp.call(to, key) && key !== except)
19
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
20
- }
21
- return to;
22
- };
23
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
24
- // If the importer is in node compatibility mode or this is not an ESM
25
- // file that has been converted to a CommonJS file using a Babel-
26
- // compatible transform (i.e. "__esModule" has not been set), then set
27
- // "default" to the CommonJS "module.exports" for node compatibility.
28
- isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
29
- mod
30
- ));
1
+ var __create = Object.create;
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __getProtoOf = Object.getPrototypeOf;
6
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
7
+ var __export = (target, all) => {
8
+ for (var name in all)
9
+ __defProp(target, name, { get: all[name], enumerable: true });
10
+ };
11
+ var __copyProps = (to, from, except, desc) => {
12
+ if (from && typeof from === "object" || typeof from === "function") {
13
+ for (let key of __getOwnPropNames(from))
14
+ if (!__hasOwnProp.call(to, key) && key !== except)
15
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
16
+ }
17
+ return to;
18
+ };
19
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
20
+ // If the importer is in node compatibility mode or this is not an ESM
21
+ // file that has been converted to a CommonJS file using a Babel-
22
+ // compatible transform (i.e. "__esModule" has not been set), then set
23
+ // "default" to the CommonJS "module.exports" for node compatibility.
24
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
25
+ mod
26
+ ));
27
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
28
+
29
+ // pkgs/@akanjs/common/index.ts
30
+ var common_exports = {};
31
+ __export(common_exports, {
32
+ Logger: () => Logger,
33
+ applyMixins: () => applyMixins,
34
+ capitalize: () => capitalize,
35
+ deepObjectify: () => deepObjectify,
36
+ isDayjs: () => import_dayjs.isDayjs,
37
+ isQueryEqual: () => isQueryEqual,
38
+ isValidDate: () => isValidDate,
39
+ lowerlize: () => lowerlize,
40
+ mergeVersion: () => mergeVersion,
41
+ objectify: () => objectify,
42
+ pathGet: () => pathGet,
43
+ pathSet: () => pathSet,
44
+ pluralize: () => import_pluralize.default,
45
+ randomPick: () => randomPick,
46
+ randomPicks: () => randomPicks,
47
+ sleep: () => sleep,
48
+ splitVersion: () => splitVersion
49
+ });
50
+ module.exports = __toCommonJS(common_exports);
31
51
 
32
- // pkgs/@akanjs/common/src/splitVersion.ts
33
- var splitVersion = (version) => {
34
- const [major, minor, patch] = version.split(".");
35
- return { major, minor, patch };
36
- };
52
+ // pkgs/@akanjs/common/src/splitVersion.ts
53
+ var splitVersion = (version) => {
54
+ const [major, minor, patch] = version.split(".");
55
+ return { major, minor, patch };
56
+ };
37
57
 
38
- // pkgs/@akanjs/common/src/isDayjs.ts
39
- var import_dayjs = __require("dayjs");
58
+ // pkgs/@akanjs/common/src/isDayjs.ts
59
+ var import_dayjs = require("dayjs");
40
60
 
41
- // pkgs/@akanjs/common/src/deepObjectify.ts
42
- var deepObjectify = (obj, option = {}) => {
43
- if ((0, import_dayjs.isDayjs)(obj) || obj?.constructor === Date) {
44
- if (!option.serializable && !option.convertDate)
45
- return obj;
46
- if (option.convertDate === "string")
47
- return obj.toISOString();
48
- else if (option.convertDate === "number")
49
- return (0, import_dayjs.isDayjs)(obj) ? obj.toDate().getTime() : obj.getTime();
50
- else
51
- return (0, import_dayjs.isDayjs)(obj) ? obj.toDate() : obj;
52
- } else if (Array.isArray(obj)) {
53
- return obj.map((o) => deepObjectify(o, option));
54
- } else if (obj && typeof obj === "object") {
55
- const val = {};
56
- Object.keys(obj).forEach((key) => {
57
- const fieldValue = obj[key];
58
- if (fieldValue?.__ModelType__ && !option.serializable)
59
- val[key] = fieldValue;
60
- else if (typeof obj[key] !== "function")
61
- val[key] = deepObjectify(fieldValue, option);
62
- });
63
- return val;
64
- } else {
61
+ // pkgs/@akanjs/common/src/deepObjectify.ts
62
+ var deepObjectify = (obj, option = {}) => {
63
+ if ((0, import_dayjs.isDayjs)(obj) || obj?.constructor === Date) {
64
+ if (!option.serializable && !option.convertDate)
65
65
  return obj;
66
- }
67
- };
66
+ if (option.convertDate === "string")
67
+ return obj.toISOString();
68
+ else if (option.convertDate === "number")
69
+ return (0, import_dayjs.isDayjs)(obj) ? obj.toDate().getTime() : obj.getTime();
70
+ else
71
+ return (0, import_dayjs.isDayjs)(obj) ? obj.toDate() : obj;
72
+ } else if (Array.isArray(obj)) {
73
+ return obj.map((o) => deepObjectify(o, option));
74
+ } else if (obj && typeof obj === "object") {
75
+ const val = {};
76
+ Object.keys(obj).forEach((key) => {
77
+ const fieldValue = obj[key];
78
+ if (fieldValue?.__ModelType__ && !option.serializable)
79
+ val[key] = fieldValue;
80
+ else if (typeof obj[key] !== "function")
81
+ val[key] = deepObjectify(fieldValue, option);
82
+ });
83
+ return val;
84
+ } else {
85
+ return obj;
86
+ }
87
+ };
68
88
 
69
- // pkgs/@akanjs/common/src/pathGet.ts
70
- var pathGet = (path, obj, separator = ".") => {
71
- const properties = Array.isArray(path) ? path : path.split(separator);
72
- return properties.reduce((prev, curr) => prev[curr], obj);
73
- };
89
+ // pkgs/@akanjs/common/src/pathGet.ts
90
+ var pathGet = (path, obj, separator = ".") => {
91
+ const properties = Array.isArray(path) ? path : path.split(separator);
92
+ return properties.reduce((prev, curr) => prev[curr], obj);
93
+ };
74
94
 
75
- // pkgs/@akanjs/common/src/isQueryEqual.ts
76
- var import_dayjs2 = __toESM(__require("dayjs"));
77
- var isQueryEqual = (value1, value2) => {
78
- if (value1 === value2)
79
- return true;
80
- if (Array.isArray(value1) && Array.isArray(value2)) {
81
- if (value1.length !== value2.length)
95
+ // pkgs/@akanjs/common/src/isQueryEqual.ts
96
+ var import_dayjs2 = __toESM(require("dayjs"));
97
+ var isQueryEqual = (value1, value2) => {
98
+ if (value1 === value2)
99
+ return true;
100
+ if (Array.isArray(value1) && Array.isArray(value2)) {
101
+ if (value1.length !== value2.length)
102
+ return false;
103
+ for (let i = 0; i < value1.length; i++)
104
+ if (!isQueryEqual(value1[i], value2[i]))
82
105
  return false;
83
- for (let i = 0; i < value1.length; i++)
84
- if (!isQueryEqual(value1[i], value2[i]))
85
- return false;
86
- return true;
87
- }
88
- if ([value1, value2].some((val) => val instanceof Date || (0, import_dayjs.isDayjs)(val)))
89
- return (0, import_dayjs2.default)(value1).isSame((0, import_dayjs2.default)(value2));
90
- if (typeof value1 === "object" && typeof value2 === "object") {
91
- if (value1 === null || value2 === null)
92
- return value1 === value2;
93
- if (Object.keys(value1).length !== Object.keys(value2).length)
106
+ return true;
107
+ }
108
+ if ([value1, value2].some((val) => val instanceof Date || (0, import_dayjs.isDayjs)(val)))
109
+ return (0, import_dayjs2.default)(value1).isSame((0, import_dayjs2.default)(value2));
110
+ if (typeof value1 === "object" && typeof value2 === "object") {
111
+ if (value1 === null || value2 === null)
112
+ return value1 === value2;
113
+ if (Object.keys(value1).length !== Object.keys(value2).length)
114
+ return false;
115
+ for (const key of Object.keys(value1))
116
+ if (!isQueryEqual(value1[key], value2[key]))
94
117
  return false;
95
- for (const key of Object.keys(value1))
96
- if (!isQueryEqual(value1[key], value2[key]))
97
- return false;
98
- return true;
99
- }
100
- return false;
101
- };
118
+ return true;
119
+ }
120
+ return false;
121
+ };
102
122
 
103
- // pkgs/@akanjs/common/src/isValidDate.ts
104
- var import_dayjs3 = __toESM(__require("dayjs"));
105
- var import_customParseFormat = __toESM(__require("dayjs/plugin/customParseFormat"));
106
- import_dayjs3.default.extend(import_customParseFormat.default);
107
- var isValidDate = (d) => {
108
- const format = "YYYY-MM-DD";
109
- if (typeof d === "string") {
110
- return (0, import_dayjs3.default)(d, format).isValid();
111
- } else if ((0, import_dayjs.isDayjs)(d))
112
- return d.isValid();
113
- else
114
- return d instanceof Date && !isNaN(d.getTime());
115
- };
123
+ // pkgs/@akanjs/common/src/isValidDate.ts
124
+ var import_dayjs3 = __toESM(require("dayjs"));
125
+ var import_customParseFormat = __toESM(require("dayjs/plugin/customParseFormat"));
126
+ import_dayjs3.default.extend(import_customParseFormat.default);
127
+ var isValidDate = (d) => {
128
+ const format = "YYYY-MM-DD";
129
+ if (typeof d === "string") {
130
+ return (0, import_dayjs3.default)(d, format).isValid();
131
+ } else if ((0, import_dayjs.isDayjs)(d))
132
+ return d.isValid();
133
+ else
134
+ return d instanceof Date && !isNaN(d.getTime());
135
+ };
116
136
 
117
- // pkgs/@akanjs/common/src/objectify.ts
118
- var objectify = (obj, keys = Object.keys(obj)) => {
119
- const val = {};
120
- keys.forEach((key) => {
121
- if (typeof obj[key] !== "function")
122
- val[key] = obj[key];
123
- });
124
- return val;
125
- };
137
+ // pkgs/@akanjs/common/src/objectify.ts
138
+ var objectify = (obj, keys = Object.keys(obj)) => {
139
+ const val = {};
140
+ keys.forEach((key) => {
141
+ if (typeof obj[key] !== "function")
142
+ val[key] = obj[key];
143
+ });
144
+ return val;
145
+ };
126
146
 
127
- // pkgs/@akanjs/common/src/randomPick.ts
128
- var randomPick = (arr) => arr[Math.floor(Math.random() * arr.length)];
147
+ // pkgs/@akanjs/common/src/randomPick.ts
148
+ var randomPick = (arr) => arr[Math.floor(Math.random() * arr.length)];
129
149
 
130
- // pkgs/@akanjs/common/src/randomPicks.ts
131
- var randomPicks = (arr, count = 1, allowDuplicate = false) => {
132
- if (!allowDuplicate && arr.length <= count)
133
- return arr;
134
- const idxs = [];
135
- let pickIdx;
136
- for (let i = 0; i < count; i++) {
137
- do {
138
- pickIdx = Math.floor(Math.random() * arr.length);
139
- } while (!allowDuplicate && idxs.includes(pickIdx));
140
- idxs.push(pickIdx);
141
- }
142
- return idxs.map((idx) => arr[idx]);
143
- };
150
+ // pkgs/@akanjs/common/src/randomPicks.ts
151
+ var randomPicks = (arr, count = 1, allowDuplicate = false) => {
152
+ if (!allowDuplicate && arr.length <= count)
153
+ return arr;
154
+ const idxs = [];
155
+ let pickIdx;
156
+ for (let i = 0; i < count; i++) {
157
+ do {
158
+ pickIdx = Math.floor(Math.random() * arr.length);
159
+ } while (!allowDuplicate && idxs.includes(pickIdx));
160
+ idxs.push(pickIdx);
161
+ }
162
+ return idxs.map((idx) => arr[idx]);
163
+ };
144
164
 
145
- // pkgs/@akanjs/common/src/pathSet.ts
146
- var pathSet = (obj, path, value) => {
147
- if (Object(obj) !== obj)
148
- return obj;
149
- if (!Array.isArray(path))
150
- path = path.toString().match(/[^.[\]]+/g) || [];
151
- path.slice(0, -1).reduce(
152
- (a, c, i) => Object(a[c]) === a[c] ? a[c] : a[c] = Math.abs(path[i + 1]) >> 0 === +path[i + 1] ? [] : {},
153
- obj
154
- )[path[path.length - 1]] = value;
165
+ // pkgs/@akanjs/common/src/pathSet.ts
166
+ var pathSet = (obj, path, value) => {
167
+ if (Object(obj) !== obj)
155
168
  return obj;
156
- };
169
+ if (!Array.isArray(path))
170
+ path = path.toString().match(/[^.[\]]+/g) || [];
171
+ path.slice(0, -1).reduce(
172
+ (a, c, i) => Object(a[c]) === a[c] ? a[c] : a[c] = Math.abs(path[i + 1]) >> 0 === +path[i + 1] ? [] : {},
173
+ obj
174
+ )[path[path.length - 1]] = value;
175
+ return obj;
176
+ };
157
177
 
158
- // pkgs/@akanjs/common/src/mergeVersion.ts
159
- var mergeVersion = (major, minor, patch) => `${major}.${minor}.${patch}`;
178
+ // pkgs/@akanjs/common/src/mergeVersion.ts
179
+ var mergeVersion = (major, minor, patch) => `${major}.${minor}.${patch}`;
160
180
 
161
- // pkgs/@akanjs/common/src/pluralize.ts
162
- var import_pluralize = __toESM(__require("pluralize"));
181
+ // pkgs/@akanjs/common/src/pluralize.ts
182
+ var import_pluralize = __toESM(require("pluralize"));
163
183
 
164
- // pkgs/@akanjs/common/src/applyMixins.ts
165
- var getAllPropertyDescriptors = (objRef) => {
166
- const descriptors = {};
167
- let current = objRef.prototype;
168
- while (current) {
169
- Object.getOwnPropertyNames(current).forEach((name) => {
170
- descriptors[name] ??= Object.getOwnPropertyDescriptor(current, name);
171
- });
172
- current = Object.getPrototypeOf(current);
173
- }
174
- return descriptors;
175
- };
176
- var applyMixins = (derivedCtor, constructors, avoidKeys) => {
177
- constructors.forEach((baseCtor) => {
178
- Object.entries(getAllPropertyDescriptors(baseCtor)).forEach(([name, descriptor]) => {
179
- if (name === "constructor" || avoidKeys?.has(name))
180
- return;
181
- Object.defineProperty(derivedCtor.prototype, name, { ...descriptor, configurable: true });
182
- });
184
+ // pkgs/@akanjs/common/src/applyMixins.ts
185
+ var getAllPropertyDescriptors = (objRef) => {
186
+ const descriptors = {};
187
+ let current = objRef.prototype;
188
+ while (current) {
189
+ Object.getOwnPropertyNames(current).forEach((name) => {
190
+ descriptors[name] ??= Object.getOwnPropertyDescriptor(current, name);
191
+ });
192
+ current = Object.getPrototypeOf(current);
193
+ }
194
+ return descriptors;
195
+ };
196
+ var applyMixins = (derivedCtor, constructors, avoidKeys) => {
197
+ constructors.forEach((baseCtor) => {
198
+ Object.entries(getAllPropertyDescriptors(baseCtor)).forEach(([name, descriptor]) => {
199
+ if (name === "constructor" || avoidKeys?.has(name))
200
+ return;
201
+ Object.defineProperty(derivedCtor.prototype, name, { ...descriptor, configurable: true });
183
202
  });
184
- };
203
+ });
204
+ };
185
205
 
186
- // pkgs/@akanjs/common/src/capitalize.ts
187
- var capitalize = (str) => {
188
- return str.charAt(0).toUpperCase() + str.slice(1);
189
- };
206
+ // pkgs/@akanjs/common/src/capitalize.ts
207
+ var capitalize = (str) => {
208
+ return str.charAt(0).toUpperCase() + str.slice(1);
209
+ };
190
210
 
191
- // pkgs/@akanjs/common/src/Logger.ts
192
- var import_dayjs4 = __toESM(__require("dayjs"));
193
- var logLevels = ["trace", "verbose", "debug", "log", "info", "warn", "error"];
194
- var clc = {
195
- bold: (text) => `\x1B[1m${text}\x1B[0m`,
196
- green: (text) => `\x1B[32m${text}\x1B[39m`,
197
- yellow: (text) => `\x1B[33m${text}\x1B[39m`,
198
- red: (text) => `\x1B[31m${text}\x1B[39m`,
199
- magentaBright: (text) => `\x1B[95m${text}\x1B[39m`,
200
- cyanBright: (text) => `\x1B[96m${text}\x1B[39m`
201
- };
202
- var colorizeMap = {
203
- trace: clc.bold,
204
- verbose: clc.cyanBright,
205
- debug: clc.magentaBright,
206
- log: clc.green,
207
- info: clc.green,
208
- warn: clc.yellow,
209
- error: clc.red
210
- };
211
- var Logger = class _Logger {
212
- static #ignoreCtxSet = /* @__PURE__ */ new Set([
213
- "InstanceLoader",
214
- "RoutesResolver",
215
- "RouterExplorer",
216
- "NestFactory",
217
- "WebSocketsController",
218
- "GraphQLModule",
219
- "NestApplication"
220
- ]);
221
- static level = process.env.NEXT_PUBLIC_LOG_LEVEL ?? "log";
222
- static #levelIdx = logLevels.findIndex((l) => l === process.env.NEXT_PUBLIC_LOG_LEVEL);
223
- static #startAt = (0, import_dayjs4.default)();
224
- static setLevel(level) {
225
- this.level = level;
226
- this.#levelIdx = logLevels.findIndex((l) => l === level);
227
- }
228
- name;
229
- constructor(name) {
230
- this.name = name;
231
- }
232
- trace(msg, context = "") {
233
- if (_Logger.#levelIdx <= 0)
234
- _Logger.#printMessages(this.name ?? "App", msg, context, "trace");
235
- }
236
- verbose(msg, context = "") {
237
- if (_Logger.#levelIdx <= 1)
238
- _Logger.#printMessages(this.name ?? "App", msg, context, "verbose");
239
- }
240
- debug(msg, context = "") {
241
- if (_Logger.#levelIdx <= 2)
242
- _Logger.#printMessages(this.name ?? "App", msg, context, "debug");
243
- }
244
- log(msg, context = "") {
245
- if (_Logger.#levelIdx <= 3)
246
- _Logger.#printMessages(this.name ?? "App", msg, context, "log");
247
- }
248
- info(msg, context = "") {
249
- if (_Logger.#levelIdx <= 4)
250
- _Logger.#printMessages(this.name ?? "App", msg, context, "info");
251
- }
252
- warn(msg, context = "") {
253
- if (_Logger.#levelIdx <= 5)
254
- _Logger.#printMessages(this.name ?? "App", msg, context, "warn");
255
- }
256
- error(msg, context = "") {
257
- if (_Logger.#levelIdx <= 6)
258
- _Logger.#printMessages(this.name ?? "App", msg, context, "error");
259
- }
260
- raw(msg, method) {
261
- _Logger.rawLog(msg, method);
262
- }
263
- rawLog(msg, method) {
264
- _Logger.rawLog(msg, method);
265
- }
266
- static trace(msg, context = "") {
267
- if (_Logger.#levelIdx <= 0)
268
- _Logger.#printMessages("App", msg, context, "trace");
269
- }
270
- static verbose(msg, context = "") {
271
- if (_Logger.#levelIdx <= 1)
272
- _Logger.#printMessages("App", msg, context, "verbose");
273
- }
274
- static debug(msg, context = "") {
275
- if (_Logger.#levelIdx <= 2)
276
- _Logger.#printMessages("App", msg, context, "debug");
277
- }
278
- static log(msg, context = "") {
279
- if (_Logger.#levelIdx <= 3)
280
- _Logger.#printMessages("App", msg, context, "log");
281
- }
282
- static info(msg, context = "") {
283
- if (_Logger.#levelIdx <= 4)
284
- _Logger.#printMessages("App", msg, context, "info");
285
- }
286
- static warn(msg, context = "") {
287
- if (_Logger.#levelIdx <= 5)
288
- _Logger.#printMessages("App", msg, context, "warn");
289
- }
290
- static error(msg, context = "") {
291
- if (_Logger.#levelIdx <= 6)
292
- _Logger.#printMessages("App", msg, context, "error");
293
- }
294
- static #colorize(msg, logLevel) {
295
- return colorizeMap[logLevel](msg);
296
- }
297
- static #printMessages(name, content, context, logLevel, writeStreamType = logLevel === "error" ? "stderr" : "stdout") {
298
- if (this.#ignoreCtxSet.has(context))
299
- return;
300
- const now = (0, import_dayjs4.default)();
301
- const processMsg = this.#colorize(
302
- `[${name ?? "App"}] ${global.process?.pid ?? "window"} -`,
303
- logLevel
304
- );
305
- const timestampMsg = now.format("MM/DD/YYYY, HH:mm:ss A");
306
- const logLevelMsg = this.#colorize(logLevel.toUpperCase().padStart(7, " "), logLevel);
307
- const contextMsg = context ? clc.yellow(`[${context}] `) : "";
308
- const contentMsg = this.#colorize(content, logLevel);
309
- const timeDiffMsg = clc.yellow(`+${now.diff(_Logger.#startAt, "ms")}ms`);
310
- if (typeof window === "undefined")
311
- process[writeStreamType].write(
312
- `${processMsg} ${timestampMsg} ${logLevelMsg} ${contextMsg} ${contentMsg} ${timeDiffMsg}
211
+ // pkgs/@akanjs/common/src/Logger.ts
212
+ var import_dayjs4 = __toESM(require("dayjs"));
213
+ var logLevels = ["trace", "verbose", "debug", "log", "info", "warn", "error"];
214
+ var clc = {
215
+ bold: (text) => `\x1B[1m${text}\x1B[0m`,
216
+ green: (text) => `\x1B[32m${text}\x1B[39m`,
217
+ yellow: (text) => `\x1B[33m${text}\x1B[39m`,
218
+ red: (text) => `\x1B[31m${text}\x1B[39m`,
219
+ magentaBright: (text) => `\x1B[95m${text}\x1B[39m`,
220
+ cyanBright: (text) => `\x1B[96m${text}\x1B[39m`
221
+ };
222
+ var colorizeMap = {
223
+ trace: clc.bold,
224
+ verbose: clc.cyanBright,
225
+ debug: clc.magentaBright,
226
+ log: clc.green,
227
+ info: clc.green,
228
+ warn: clc.yellow,
229
+ error: clc.red
230
+ };
231
+ var Logger = class _Logger {
232
+ static #ignoreCtxSet = /* @__PURE__ */ new Set([
233
+ "InstanceLoader",
234
+ "RoutesResolver",
235
+ "RouterExplorer",
236
+ "NestFactory",
237
+ "WebSocketsController",
238
+ "GraphQLModule",
239
+ "NestApplication"
240
+ ]);
241
+ static level = process.env.NEXT_PUBLIC_LOG_LEVEL ?? "log";
242
+ static #levelIdx = logLevels.findIndex((l) => l === process.env.NEXT_PUBLIC_LOG_LEVEL);
243
+ static #startAt = (0, import_dayjs4.default)();
244
+ static setLevel(level) {
245
+ this.level = level;
246
+ this.#levelIdx = logLevels.findIndex((l) => l === level);
247
+ }
248
+ name;
249
+ constructor(name) {
250
+ this.name = name;
251
+ }
252
+ trace(msg, context = "") {
253
+ if (_Logger.#levelIdx <= 0)
254
+ _Logger.#printMessages(this.name ?? "App", msg, context, "trace");
255
+ }
256
+ verbose(msg, context = "") {
257
+ if (_Logger.#levelIdx <= 1)
258
+ _Logger.#printMessages(this.name ?? "App", msg, context, "verbose");
259
+ }
260
+ debug(msg, context = "") {
261
+ if (_Logger.#levelIdx <= 2)
262
+ _Logger.#printMessages(this.name ?? "App", msg, context, "debug");
263
+ }
264
+ log(msg, context = "") {
265
+ if (_Logger.#levelIdx <= 3)
266
+ _Logger.#printMessages(this.name ?? "App", msg, context, "log");
267
+ }
268
+ info(msg, context = "") {
269
+ if (_Logger.#levelIdx <= 4)
270
+ _Logger.#printMessages(this.name ?? "App", msg, context, "info");
271
+ }
272
+ warn(msg, context = "") {
273
+ if (_Logger.#levelIdx <= 5)
274
+ _Logger.#printMessages(this.name ?? "App", msg, context, "warn");
275
+ }
276
+ error(msg, context = "") {
277
+ if (_Logger.#levelIdx <= 6)
278
+ _Logger.#printMessages(this.name ?? "App", msg, context, "error");
279
+ }
280
+ raw(msg, method) {
281
+ _Logger.rawLog(msg, method);
282
+ }
283
+ rawLog(msg, method) {
284
+ _Logger.rawLog(msg, method);
285
+ }
286
+ static trace(msg, context = "") {
287
+ if (_Logger.#levelIdx <= 0)
288
+ _Logger.#printMessages("App", msg, context, "trace");
289
+ }
290
+ static verbose(msg, context = "") {
291
+ if (_Logger.#levelIdx <= 1)
292
+ _Logger.#printMessages("App", msg, context, "verbose");
293
+ }
294
+ static debug(msg, context = "") {
295
+ if (_Logger.#levelIdx <= 2)
296
+ _Logger.#printMessages("App", msg, context, "debug");
297
+ }
298
+ static log(msg, context = "") {
299
+ if (_Logger.#levelIdx <= 3)
300
+ _Logger.#printMessages("App", msg, context, "log");
301
+ }
302
+ static info(msg, context = "") {
303
+ if (_Logger.#levelIdx <= 4)
304
+ _Logger.#printMessages("App", msg, context, "info");
305
+ }
306
+ static warn(msg, context = "") {
307
+ if (_Logger.#levelIdx <= 5)
308
+ _Logger.#printMessages("App", msg, context, "warn");
309
+ }
310
+ static error(msg, context = "") {
311
+ if (_Logger.#levelIdx <= 6)
312
+ _Logger.#printMessages("App", msg, context, "error");
313
+ }
314
+ static #colorize(msg, logLevel) {
315
+ return colorizeMap[logLevel](msg);
316
+ }
317
+ static #printMessages(name, content, context, logLevel, writeStreamType = logLevel === "error" ? "stderr" : "stdout") {
318
+ if (this.#ignoreCtxSet.has(context))
319
+ return;
320
+ const now = (0, import_dayjs4.default)();
321
+ const processMsg = this.#colorize(
322
+ `[${name ?? "App"}] ${global.process?.pid ?? "window"} -`,
323
+ logLevel
324
+ );
325
+ const timestampMsg = now.format("MM/DD/YYYY, HH:mm:ss A");
326
+ const logLevelMsg = this.#colorize(logLevel.toUpperCase().padStart(7, " "), logLevel);
327
+ const contextMsg = context ? clc.yellow(`[${context}] `) : "";
328
+ const contentMsg = this.#colorize(content, logLevel);
329
+ const timeDiffMsg = clc.yellow(`+${now.diff(_Logger.#startAt, "ms")}ms`);
330
+ if (typeof window === "undefined")
331
+ process[writeStreamType].write(
332
+ `${processMsg} ${timestampMsg} ${logLevelMsg} ${contextMsg} ${contentMsg} ${timeDiffMsg}
313
333
  `
314
- );
315
- else
316
- console.log(`${processMsg} ${timestampMsg} ${logLevelMsg} ${contextMsg} ${contentMsg} ${timeDiffMsg}
334
+ );
335
+ else
336
+ console.log(`${processMsg} ${timestampMsg} ${logLevelMsg} ${contextMsg} ${contentMsg} ${timeDiffMsg}
317
337
  `);
318
- }
319
- static rawLog(msg, method) {
320
- this.raw(`${msg}
338
+ }
339
+ static rawLog(msg, method) {
340
+ this.raw(`${msg}
321
341
  `, method);
322
- }
323
- static raw(msg, method) {
324
- if (typeof window === "undefined" && method !== "console" && global.process)
325
- global.process.stdout.write(msg);
326
- else
327
- console.log(msg);
328
- }
329
- };
342
+ }
343
+ static raw(msg, method) {
344
+ if (typeof window === "undefined" && method !== "console" && global.process)
345
+ global.process.stdout.write(msg);
346
+ else
347
+ console.log(msg);
348
+ }
349
+ };
330
350
 
331
- // pkgs/@akanjs/common/src/lowerlize.ts
332
- var lowerlize = (str) => {
333
- return str.charAt(0).toLowerCase() + str.slice(1);
334
- };
351
+ // pkgs/@akanjs/common/src/lowerlize.ts
352
+ var lowerlize = (str) => {
353
+ return str.charAt(0).toLowerCase() + str.slice(1);
354
+ };
335
355
 
336
- // pkgs/@akanjs/common/src/sleep.ts
337
- var sleep = async (ms) => {
338
- return new Promise((resolve) => {
339
- setTimeout(() => {
340
- resolve(true);
341
- }, ms);
342
- });
343
- };
344
- })();
356
+ // pkgs/@akanjs/common/src/sleep.ts
357
+ var sleep = async (ms) => {
358
+ return new Promise((resolve) => {
359
+ setTimeout(() => {
360
+ resolve(true);
361
+ }, ms);
362
+ });
363
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@akanjs/common",
3
- "version": "0.0.44",
3
+ "version": "0.0.46",
4
4
  "type": "commonjs",
5
5
  "publishConfig": {
6
6
  "access": "public"