@akanjs/common 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.
package/index.d.ts ADDED
@@ -0,0 +1,19 @@
1
+ export { FetchPolicy, SnakeCase, SnakeCaseObj, SnakeMsg } from './src/types.js';
2
+ export { splitVersion } from './src/splitVersion.js';
3
+ export { deepObjectify } from './src/deepObjectify.js';
4
+ export { pathGet } from './src/pathGet.js';
5
+ export { isQueryEqual } from './src/isQueryEqual.js';
6
+ export { isValidDate } from './src/isValidDate.js';
7
+ export { objectify } from './src/objectify.js';
8
+ export { randomPick } from './src/randomPick.js';
9
+ export { randomPicks } from './src/randomPicks.js';
10
+ export { pathSet } from './src/pathSet.js';
11
+ export { isDayjs } from 'dayjs';
12
+ export { mergeVersion } from './src/mergeVersion.js';
13
+ export { default as pluralize } from 'pluralize';
14
+ export { applyMixins } from './src/applyMixins.js';
15
+ export { capitalize } from './src/capitalize.js';
16
+ export { Logger } from './src/Logger.js';
17
+ export { lowerlize } from './src/lowerlize.js';
18
+ export { sleep } from './src/sleep.js';
19
+ import '@urql/core';
package/index.js CHANGED
@@ -1,344 +1,21 @@
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
- ));
31
-
32
- // pkgs/@akanjs/common/src/splitVersion.ts
33
- var splitVersion = (version) => {
34
- const [major, minor, patch] = version.split(".");
35
- return { major, minor, patch };
36
- };
37
-
38
- // pkgs/@akanjs/common/src/isDayjs.ts
39
- var import_dayjs = __require("dayjs");
40
-
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 {
65
- return obj;
66
- }
67
- };
68
-
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
- };
74
-
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)
82
- 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)
94
- 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
- };
102
-
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
- };
116
-
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
- };
126
-
127
- // pkgs/@akanjs/common/src/randomPick.ts
128
- var randomPick = (arr) => arr[Math.floor(Math.random() * arr.length)];
129
-
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
- };
144
-
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;
155
- return obj;
156
- };
157
-
158
- // pkgs/@akanjs/common/src/mergeVersion.ts
159
- var mergeVersion = (major, minor, patch) => `${major}.${minor}.${patch}`;
160
-
161
- // pkgs/@akanjs/common/src/pluralize.ts
162
- var import_pluralize = __toESM(__require("pluralize"));
163
-
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
- });
183
- });
184
- };
185
-
186
- // pkgs/@akanjs/common/src/capitalize.ts
187
- var capitalize = (str) => {
188
- return str.charAt(0).toUpperCase() + str.slice(1);
189
- };
190
-
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}
313
- `
314
- );
315
- else
316
- console.log(`${processMsg} ${timestampMsg} ${logLevelMsg} ${contextMsg} ${contentMsg} ${timeDiffMsg}
317
- `);
318
- }
319
- static rawLog(msg, method) {
320
- this.raw(`${msg}
321
- `, 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
- };
330
-
331
- // pkgs/@akanjs/common/src/lowerlize.ts
332
- var lowerlize = (str) => {
333
- return str.charAt(0).toLowerCase() + str.slice(1);
334
- };
335
-
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
- })();
1
+ var __defProp = Object.defineProperty;
2
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
+ var __getOwnPropNames = Object.getOwnPropertyNames;
4
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
5
+ var __copyProps = (to, from, except, desc) => {
6
+ if (from && typeof from === "object" || typeof from === "function") {
7
+ for (let key of __getOwnPropNames(from))
8
+ if (!__hasOwnProp.call(to, key) && key !== except)
9
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
10
+ }
11
+ return to;
12
+ };
13
+ var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
14
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
15
+ var index_exports = {};
16
+ module.exports = __toCommonJS(index_exports);
17
+ __reExport(index_exports, require("./src"), module.exports);
18
+ // Annotate the CommonJS export names for ESM import in node:
19
+ 0 && (module.exports = {
20
+ ...require("./src")
21
+ });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@akanjs/common",
3
- "version": "0.0.39",
3
+ "version": "0.0.40",
4
4
  "type": "commonjs",
5
5
  "publishConfig": {
6
6
  "access": "public"
@@ -14,8 +14,5 @@
14
14
  "engines": {
15
15
  "node": ">=22"
16
16
  },
17
- "dependencies": {
18
- "dayjs": "^1.11.13",
19
- "pluralize": "^8.0.0"
20
- }
17
+ "dependencies": {}
21
18
  }
@@ -0,0 +1,29 @@
1
+ declare const logLevels: readonly ["trace", "verbose", "debug", "log", "info", "warn", "error"];
2
+ type LogLevel = (typeof logLevels)[number];
3
+ declare class Logger {
4
+ #private;
5
+ static level: LogLevel;
6
+ static setLevel(level: LogLevel): void;
7
+ name?: string;
8
+ constructor(name?: string);
9
+ trace(msg: string, context?: string): void;
10
+ verbose(msg: string, context?: string): void;
11
+ debug(msg: string, context?: string): void;
12
+ log(msg: string, context?: string): void;
13
+ info(msg: string, context?: string): void;
14
+ warn(msg: string, context?: string): void;
15
+ error(msg: string, context?: string): void;
16
+ raw(msg: string, method?: "console" | "process"): void;
17
+ rawLog(msg: string, method?: "console" | "process"): void;
18
+ static trace(msg: string, context?: string): void;
19
+ static verbose(msg: string, context?: string): void;
20
+ static debug(msg: string, context?: string): void;
21
+ static log(msg: string, context?: string): void;
22
+ static info(msg: string, context?: string): void;
23
+ static warn(msg: string, context?: string): void;
24
+ static error(msg: string, context?: string): void;
25
+ static rawLog(msg: string, method?: "console" | "process"): void;
26
+ static raw(msg: string, method?: "console" | "process"): void;
27
+ }
28
+
29
+ export { Logger };
package/src/Logger.js ADDED
@@ -0,0 +1,162 @@
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 __name = (target, value) => __defProp(target, "name", { value, configurable: true });
8
+ var __export = (target, all) => {
9
+ for (var name in all)
10
+ __defProp(target, name, { get: all[name], enumerable: true });
11
+ };
12
+ var __copyProps = (to, from, except, desc) => {
13
+ if (from && typeof from === "object" || typeof from === "function") {
14
+ for (let key of __getOwnPropNames(from))
15
+ if (!__hasOwnProp.call(to, key) && key !== except)
16
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
+ }
18
+ return to;
19
+ };
20
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
+ // If the importer is in node compatibility mode or this is not an ESM
22
+ // file that has been converted to a CommonJS file using a Babel-
23
+ // compatible transform (i.e. "__esModule" has not been set), then set
24
+ // "default" to the CommonJS "module.exports" for node compatibility.
25
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
+ mod
27
+ ));
28
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
+ var Logger_exports = {};
30
+ __export(Logger_exports, {
31
+ Logger: () => Logger
32
+ });
33
+ module.exports = __toCommonJS(Logger_exports);
34
+ var import_dayjs = __toESM(require("dayjs"));
35
+ const logLevels = [
36
+ "trace",
37
+ "verbose",
38
+ "debug",
39
+ "log",
40
+ "info",
41
+ "warn",
42
+ "error"
43
+ ];
44
+ const clc = {
45
+ bold: /* @__PURE__ */ __name((text) => `\x1B[1m${text}\x1B[0m`, "bold"),
46
+ green: /* @__PURE__ */ __name((text) => `\x1B[32m${text}\x1B[39m`, "green"),
47
+ yellow: /* @__PURE__ */ __name((text) => `\x1B[33m${text}\x1B[39m`, "yellow"),
48
+ red: /* @__PURE__ */ __name((text) => `\x1B[31m${text}\x1B[39m`, "red"),
49
+ magentaBright: /* @__PURE__ */ __name((text) => `\x1B[95m${text}\x1B[39m`, "magentaBright"),
50
+ cyanBright: /* @__PURE__ */ __name((text) => `\x1B[96m${text}\x1B[39m`, "cyanBright")
51
+ };
52
+ const colorizeMap = {
53
+ trace: clc.bold,
54
+ verbose: clc.cyanBright,
55
+ debug: clc.magentaBright,
56
+ log: clc.green,
57
+ info: clc.green,
58
+ warn: clc.yellow,
59
+ error: clc.red
60
+ };
61
+ class Logger {
62
+ static {
63
+ __name(this, "Logger");
64
+ }
65
+ static #ignoreCtxSet = /* @__PURE__ */ new Set([
66
+ "InstanceLoader",
67
+ "RoutesResolver",
68
+ "RouterExplorer",
69
+ "NestFactory",
70
+ "WebSocketsController",
71
+ "GraphQLModule",
72
+ "NestApplication"
73
+ ]);
74
+ static level = process.env.NEXT_PUBLIC_LOG_LEVEL ?? "log";
75
+ static #levelIdx = logLevels.findIndex((l) => l === process.env.NEXT_PUBLIC_LOG_LEVEL);
76
+ static #startAt = (0, import_dayjs.default)();
77
+ static setLevel(level) {
78
+ this.level = level;
79
+ this.#levelIdx = logLevels.findIndex((l) => l === level);
80
+ }
81
+ name;
82
+ constructor(name) {
83
+ this.name = name;
84
+ }
85
+ trace(msg, context = "") {
86
+ if (Logger.#levelIdx <= 0) Logger.#printMessages(this.name ?? "App", msg, context, "trace");
87
+ }
88
+ verbose(msg, context = "") {
89
+ if (Logger.#levelIdx <= 1) Logger.#printMessages(this.name ?? "App", msg, context, "verbose");
90
+ }
91
+ debug(msg, context = "") {
92
+ if (Logger.#levelIdx <= 2) Logger.#printMessages(this.name ?? "App", msg, context, "debug");
93
+ }
94
+ log(msg, context = "") {
95
+ if (Logger.#levelIdx <= 3) Logger.#printMessages(this.name ?? "App", msg, context, "log");
96
+ }
97
+ info(msg, context = "") {
98
+ if (Logger.#levelIdx <= 4) Logger.#printMessages(this.name ?? "App", msg, context, "info");
99
+ }
100
+ warn(msg, context = "") {
101
+ if (Logger.#levelIdx <= 5) Logger.#printMessages(this.name ?? "App", msg, context, "warn");
102
+ }
103
+ error(msg, context = "") {
104
+ if (Logger.#levelIdx <= 6) Logger.#printMessages(this.name ?? "App", msg, context, "error");
105
+ }
106
+ raw(msg, method) {
107
+ Logger.rawLog(msg, method);
108
+ }
109
+ rawLog(msg, method) {
110
+ Logger.rawLog(msg, method);
111
+ }
112
+ static trace(msg, context = "") {
113
+ if (Logger.#levelIdx <= 0) Logger.#printMessages("App", msg, context, "trace");
114
+ }
115
+ static verbose(msg, context = "") {
116
+ if (Logger.#levelIdx <= 1) Logger.#printMessages("App", msg, context, "verbose");
117
+ }
118
+ static debug(msg, context = "") {
119
+ if (Logger.#levelIdx <= 2) Logger.#printMessages("App", msg, context, "debug");
120
+ }
121
+ static log(msg, context = "") {
122
+ if (Logger.#levelIdx <= 3) Logger.#printMessages("App", msg, context, "log");
123
+ }
124
+ static info(msg, context = "") {
125
+ if (Logger.#levelIdx <= 4) Logger.#printMessages("App", msg, context, "info");
126
+ }
127
+ static warn(msg, context = "") {
128
+ if (Logger.#levelIdx <= 5) Logger.#printMessages("App", msg, context, "warn");
129
+ }
130
+ static error(msg, context = "") {
131
+ if (Logger.#levelIdx <= 6) Logger.#printMessages("App", msg, context, "error");
132
+ }
133
+ static #colorize(msg, logLevel) {
134
+ return colorizeMap[logLevel](msg);
135
+ }
136
+ static #printMessages(name, content, context, logLevel, writeStreamType = logLevel === "error" ? "stderr" : "stdout") {
137
+ if (this.#ignoreCtxSet.has(context)) return;
138
+ const now = (0, import_dayjs.default)();
139
+ const processMsg = this.#colorize(`[${name ?? "App"}] ${global.process?.pid ?? "window"} -`, logLevel);
140
+ const timestampMsg = now.format("MM/DD/YYYY, HH:mm:ss A");
141
+ const logLevelMsg = this.#colorize(logLevel.toUpperCase().padStart(7, " "), logLevel);
142
+ const contextMsg = context ? clc.yellow(`[${context}] `) : "";
143
+ const contentMsg = this.#colorize(content, logLevel);
144
+ const timeDiffMsg = clc.yellow(`+${now.diff(Logger.#startAt, "ms")}ms`);
145
+ if (typeof window === "undefined") process[writeStreamType].write(`${processMsg} ${timestampMsg} ${logLevelMsg} ${contextMsg} ${contentMsg} ${timeDiffMsg}
146
+ `);
147
+ else console.log(`${processMsg} ${timestampMsg} ${logLevelMsg} ${contextMsg} ${contentMsg} ${timeDiffMsg}
148
+ `);
149
+ }
150
+ static rawLog(msg, method) {
151
+ this.raw(`${msg}
152
+ `, method);
153
+ }
154
+ static raw(msg, method) {
155
+ if (typeof window === "undefined" && method !== "console" && global.process) global.process.stdout.write(msg);
156
+ else console.log(msg);
157
+ }
158
+ }
159
+ // Annotate the CommonJS export names for ESM import in node:
160
+ 0 && (module.exports = {
161
+ Logger
162
+ });
@@ -0,0 +1,4 @@
1
+ type Type<T = any> = new (...args: any[]) => T;
2
+ declare const applyMixins: (derivedCtor: Type, constructors: (Type | undefined)[], avoidKeys?: Set<string>) => void;
3
+
4
+ export { applyMixins };
@@ -0,0 +1,49 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
+ var __getOwnPropNames = Object.getOwnPropertyNames;
4
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
5
+ var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+ var applyMixins_exports = {};
20
+ __export(applyMixins_exports, {
21
+ applyMixins: () => applyMixins
22
+ });
23
+ module.exports = __toCommonJS(applyMixins_exports);
24
+ const getAllPropertyDescriptors = /* @__PURE__ */ __name((objRef) => {
25
+ const descriptors = {};
26
+ let current = objRef.prototype;
27
+ while (current) {
28
+ Object.getOwnPropertyNames(current).forEach((name) => {
29
+ descriptors[name] ??= Object.getOwnPropertyDescriptor(current, name);
30
+ });
31
+ current = Object.getPrototypeOf(current);
32
+ }
33
+ return descriptors;
34
+ }, "getAllPropertyDescriptors");
35
+ const applyMixins = /* @__PURE__ */ __name((derivedCtor, constructors, avoidKeys) => {
36
+ constructors.forEach((baseCtor) => {
37
+ Object.entries(getAllPropertyDescriptors(baseCtor)).forEach(([name, descriptor]) => {
38
+ if (name === "constructor" || avoidKeys?.has(name)) return;
39
+ Object.defineProperty(derivedCtor.prototype, name, {
40
+ ...descriptor,
41
+ configurable: true
42
+ });
43
+ });
44
+ });
45
+ }, "applyMixins");
46
+ // Annotate the CommonJS export names for ESM import in node:
47
+ 0 && (module.exports = {
48
+ applyMixins
49
+ });
@@ -0,0 +1,3 @@
1
+ declare const capitalize: (str: string) => string;
2
+
3
+ export { capitalize };