@akanjs/common 0.0.33 → 0.0.35
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.js +344 -21
- package/package.json +8 -6
- package/README.md +0 -11
- package/index.d.ts +0 -1
- package/src/Logger.d.ts +0 -26
- package/src/Logger.js +0 -167
- package/src/applyMixins.d.ts +0 -3
- package/src/applyMixins.js +0 -48
- package/src/capitalize.d.ts +0 -1
- package/src/capitalize.js +0 -29
- package/src/deepObjectify.d.ts +0 -4
- package/src/deepObjectify.js +0 -53
- package/src/index.d.ts +0 -18
- package/src/index.js +0 -75
- package/src/isDayjs.d.ts +0 -2
- package/src/isDayjs.js +0 -27
- package/src/isQueryEqual.d.ts +0 -1
- package/src/isQueryEqual.js +0 -63
- package/src/isValidDate.d.ts +0 -2
- package/src/isValidDate.js +0 -49
- package/src/lowerlize.d.ts +0 -1
- package/src/lowerlize.js +0 -29
- package/src/mergeVersion.d.ts +0 -10
- package/src/mergeVersion.js +0 -27
- package/src/objectify.d.ts +0 -1
- package/src/objectify.js +0 -34
- package/src/pathGet.d.ts +0 -1
- package/src/pathGet.js +0 -30
- package/src/pathSet.d.ts +0 -1
- package/src/pathSet.js +0 -37
- package/src/pluralize.d.ts +0 -2
- package/src/pluralize.js +0 -37
- package/src/randomPick.d.ts +0 -1
- package/src/randomPick.js +0 -27
- package/src/randomPicks.d.ts +0 -1
- package/src/randomPicks.js +0 -39
- package/src/sleep.d.ts +0 -1
- package/src/sleep.js +0 -33
- package/src/splitVersion.d.ts +0 -11
- package/src/splitVersion.js +0 -30
- package/src/types.d.ts +0 -15
- package/src/types.js +0 -15
package/index.js
CHANGED
|
@@ -1,21 +1,344 @@
|
|
|
1
|
-
|
|
2
|
-
var
|
|
3
|
-
var
|
|
4
|
-
var
|
|
5
|
-
var
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
var
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
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
|
+
})();
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@akanjs/common",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.35",
|
|
4
4
|
"type": "commonjs",
|
|
5
5
|
"publishConfig": {
|
|
6
6
|
"access": "public"
|
|
@@ -10,10 +10,12 @@
|
|
|
10
10
|
"url": "https://github.com/akan-team/akanjs.git",
|
|
11
11
|
"directory": "pkgs/@akanjs/common"
|
|
12
12
|
},
|
|
13
|
-
"
|
|
14
|
-
|
|
15
|
-
"
|
|
16
|
-
"pluralize": "^8.0.0"
|
|
13
|
+
"main": "./index.js",
|
|
14
|
+
"engines": {
|
|
15
|
+
"node": ">=22"
|
|
17
16
|
},
|
|
18
|
-
"
|
|
17
|
+
"dependencies": {
|
|
18
|
+
"dayjs": "^^1.11.13",
|
|
19
|
+
"pluralize": "^^8.0.0"
|
|
20
|
+
}
|
|
19
21
|
}
|
package/README.md
DELETED
package/index.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from "./src";
|
package/src/Logger.d.ts
DELETED
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
declare const logLevels: readonly ["trace", "verbose", "debug", "log", "info", "warn", "error"];
|
|
2
|
-
type LogLevel = (typeof logLevels)[number];
|
|
3
|
-
export 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
|
-
rawLog(msg: string, method?: "console" | "process"): void;
|
|
17
|
-
static trace(msg: string, context?: string): void;
|
|
18
|
-
static verbose(msg: string, context?: string): void;
|
|
19
|
-
static debug(msg: string, context?: string): void;
|
|
20
|
-
static log(msg: string, context?: string): void;
|
|
21
|
-
static info(msg: string, context?: string): void;
|
|
22
|
-
static warn(msg: string, context?: string): void;
|
|
23
|
-
static error(msg: string, context?: string): void;
|
|
24
|
-
static rawLog(msg: string, method?: "console" | "process"): void;
|
|
25
|
-
}
|
|
26
|
-
export {};
|
package/src/Logger.js
DELETED
|
@@ -1,167 +0,0 @@
|
|
|
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
|
-
var Logger_exports = {};
|
|
29
|
-
__export(Logger_exports, {
|
|
30
|
-
Logger: () => Logger
|
|
31
|
-
});
|
|
32
|
-
module.exports = __toCommonJS(Logger_exports);
|
|
33
|
-
var import_dayjs = __toESM(require("dayjs"));
|
|
34
|
-
const logLevels = ["trace", "verbose", "debug", "log", "info", "warn", "error"];
|
|
35
|
-
const clc = {
|
|
36
|
-
bold: (text) => `\x1B[1m${text}\x1B[0m`,
|
|
37
|
-
green: (text) => `\x1B[32m${text}\x1B[39m`,
|
|
38
|
-
yellow: (text) => `\x1B[33m${text}\x1B[39m`,
|
|
39
|
-
red: (text) => `\x1B[31m${text}\x1B[39m`,
|
|
40
|
-
magentaBright: (text) => `\x1B[95m${text}\x1B[39m`,
|
|
41
|
-
cyanBright: (text) => `\x1B[96m${text}\x1B[39m`
|
|
42
|
-
};
|
|
43
|
-
const colorizeMap = {
|
|
44
|
-
trace: clc.bold,
|
|
45
|
-
verbose: clc.cyanBright,
|
|
46
|
-
debug: clc.magentaBright,
|
|
47
|
-
log: clc.green,
|
|
48
|
-
info: clc.green,
|
|
49
|
-
warn: clc.yellow,
|
|
50
|
-
error: clc.red
|
|
51
|
-
};
|
|
52
|
-
class Logger {
|
|
53
|
-
static #ignoreCtxSet = /* @__PURE__ */ new Set([
|
|
54
|
-
"InstanceLoader",
|
|
55
|
-
"RoutesResolver",
|
|
56
|
-
"RouterExplorer",
|
|
57
|
-
"NestFactory",
|
|
58
|
-
"WebSocketsController",
|
|
59
|
-
"GraphQLModule",
|
|
60
|
-
"NestApplication"
|
|
61
|
-
]);
|
|
62
|
-
static level = process.env.NEXT_PUBLIC_LOG_LEVEL ?? "log";
|
|
63
|
-
static #levelIdx = logLevels.findIndex((l) => l === process.env.NEXT_PUBLIC_LOG_LEVEL);
|
|
64
|
-
static #startAt = (0, import_dayjs.default)();
|
|
65
|
-
static setLevel(level) {
|
|
66
|
-
this.level = level;
|
|
67
|
-
this.#levelIdx = logLevels.findIndex((l) => l === level);
|
|
68
|
-
}
|
|
69
|
-
name;
|
|
70
|
-
constructor(name) {
|
|
71
|
-
this.name = name;
|
|
72
|
-
}
|
|
73
|
-
trace(msg, context = "") {
|
|
74
|
-
if (Logger.#levelIdx <= 0)
|
|
75
|
-
Logger.#printMessages(this.name ?? "App", msg, context, "trace");
|
|
76
|
-
}
|
|
77
|
-
verbose(msg, context = "") {
|
|
78
|
-
if (Logger.#levelIdx <= 1)
|
|
79
|
-
Logger.#printMessages(this.name ?? "App", msg, context, "verbose");
|
|
80
|
-
}
|
|
81
|
-
debug(msg, context = "") {
|
|
82
|
-
if (Logger.#levelIdx <= 2)
|
|
83
|
-
Logger.#printMessages(this.name ?? "App", msg, context, "debug");
|
|
84
|
-
}
|
|
85
|
-
log(msg, context = "") {
|
|
86
|
-
if (Logger.#levelIdx <= 3)
|
|
87
|
-
Logger.#printMessages(this.name ?? "App", msg, context, "log");
|
|
88
|
-
}
|
|
89
|
-
info(msg, context = "") {
|
|
90
|
-
if (Logger.#levelIdx <= 4)
|
|
91
|
-
Logger.#printMessages(this.name ?? "App", msg, context, "info");
|
|
92
|
-
}
|
|
93
|
-
warn(msg, context = "") {
|
|
94
|
-
if (Logger.#levelIdx <= 5)
|
|
95
|
-
Logger.#printMessages(this.name ?? "App", msg, context, "warn");
|
|
96
|
-
}
|
|
97
|
-
error(msg, context = "") {
|
|
98
|
-
if (Logger.#levelIdx <= 6)
|
|
99
|
-
Logger.#printMessages(this.name ?? "App", msg, context, "error");
|
|
100
|
-
}
|
|
101
|
-
rawLog(msg, method) {
|
|
102
|
-
Logger.rawLog(msg, method);
|
|
103
|
-
}
|
|
104
|
-
static trace(msg, context = "") {
|
|
105
|
-
if (Logger.#levelIdx <= 0)
|
|
106
|
-
Logger.#printMessages("App", msg, context, "trace");
|
|
107
|
-
}
|
|
108
|
-
static verbose(msg, context = "") {
|
|
109
|
-
if (Logger.#levelIdx <= 1)
|
|
110
|
-
Logger.#printMessages("App", msg, context, "verbose");
|
|
111
|
-
}
|
|
112
|
-
static debug(msg, context = "") {
|
|
113
|
-
if (Logger.#levelIdx <= 2)
|
|
114
|
-
Logger.#printMessages("App", msg, context, "debug");
|
|
115
|
-
}
|
|
116
|
-
static log(msg, context = "") {
|
|
117
|
-
if (Logger.#levelIdx <= 3)
|
|
118
|
-
Logger.#printMessages("App", msg, context, "log");
|
|
119
|
-
}
|
|
120
|
-
static info(msg, context = "") {
|
|
121
|
-
if (Logger.#levelIdx <= 4)
|
|
122
|
-
Logger.#printMessages("App", msg, context, "info");
|
|
123
|
-
}
|
|
124
|
-
static warn(msg, context = "") {
|
|
125
|
-
if (Logger.#levelIdx <= 5)
|
|
126
|
-
Logger.#printMessages("App", msg, context, "warn");
|
|
127
|
-
}
|
|
128
|
-
static error(msg, context = "") {
|
|
129
|
-
if (Logger.#levelIdx <= 6)
|
|
130
|
-
Logger.#printMessages("App", msg, context, "error");
|
|
131
|
-
}
|
|
132
|
-
static #colorize(msg, logLevel) {
|
|
133
|
-
return colorizeMap[logLevel](msg);
|
|
134
|
-
}
|
|
135
|
-
static #printMessages(name, content, context, logLevel, writeStreamType = logLevel === "error" ? "stderr" : "stdout") {
|
|
136
|
-
if (this.#ignoreCtxSet.has(context))
|
|
137
|
-
return;
|
|
138
|
-
const now = (0, import_dayjs.default)();
|
|
139
|
-
const processMsg = this.#colorize(
|
|
140
|
-
`[${name ?? "App"}] ${global.process?.pid ?? "window"} -`,
|
|
141
|
-
logLevel
|
|
142
|
-
);
|
|
143
|
-
const timestampMsg = now.format("MM/DD/YYYY, HH:mm:ss A");
|
|
144
|
-
const logLevelMsg = this.#colorize(logLevel.toUpperCase().padStart(7, " "), logLevel);
|
|
145
|
-
const contextMsg = context ? clc.yellow(`[${context}] `) : "";
|
|
146
|
-
const contentMsg = this.#colorize(content, logLevel);
|
|
147
|
-
const timeDiffMsg = clc.yellow(`+${now.diff(Logger.#startAt, "ms")}ms`);
|
|
148
|
-
if (typeof window === "undefined")
|
|
149
|
-
process[writeStreamType].write(
|
|
150
|
-
`${processMsg} ${timestampMsg} ${logLevelMsg} ${contextMsg} ${contentMsg} ${timeDiffMsg}
|
|
151
|
-
`
|
|
152
|
-
);
|
|
153
|
-
else
|
|
154
|
-
console.log(`${processMsg} ${timestampMsg} ${logLevelMsg} ${contextMsg} ${contentMsg} ${timeDiffMsg}
|
|
155
|
-
`);
|
|
156
|
-
}
|
|
157
|
-
static rawLog(msg, method) {
|
|
158
|
-
if (typeof window === "undefined" && method !== "console" && global.process)
|
|
159
|
-
global.process.stdout.write(msg);
|
|
160
|
-
else
|
|
161
|
-
console.log(msg);
|
|
162
|
-
}
|
|
163
|
-
}
|
|
164
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
165
|
-
0 && (module.exports = {
|
|
166
|
-
Logger
|
|
167
|
-
});
|
package/src/applyMixins.d.ts
DELETED
package/src/applyMixins.js
DELETED
|
@@ -1,48 +0,0 @@
|
|
|
1
|
-
var __defProp = Object.defineProperty;
|
|
2
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
-
var __export = (target, all) => {
|
|
6
|
-
for (var name in all)
|
|
7
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
8
|
-
};
|
|
9
|
-
var __copyProps = (to, from, except, desc) => {
|
|
10
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
11
|
-
for (let key of __getOwnPropNames(from))
|
|
12
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
13
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
14
|
-
}
|
|
15
|
-
return to;
|
|
16
|
-
};
|
|
17
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
18
|
-
var applyMixins_exports = {};
|
|
19
|
-
__export(applyMixins_exports, {
|
|
20
|
-
applyMixins: () => applyMixins
|
|
21
|
-
});
|
|
22
|
-
module.exports = __toCommonJS(applyMixins_exports);
|
|
23
|
-
const getAllPropertyDescriptors = (objRef) => {
|
|
24
|
-
const descriptors = {};
|
|
25
|
-
let current = objRef.prototype;
|
|
26
|
-
while (current) {
|
|
27
|
-
Object.getOwnPropertyNames(current).forEach((name) => {
|
|
28
|
-
if (!descriptors[name]) {
|
|
29
|
-
descriptors[name] = Object.getOwnPropertyDescriptor(current, name);
|
|
30
|
-
}
|
|
31
|
-
});
|
|
32
|
-
current = Object.getPrototypeOf(current);
|
|
33
|
-
}
|
|
34
|
-
return descriptors;
|
|
35
|
-
};
|
|
36
|
-
const applyMixins = (derivedCtor, constructors) => {
|
|
37
|
-
constructors.forEach((baseCtor) => {
|
|
38
|
-
Object.entries(getAllPropertyDescriptors(baseCtor)).forEach(([name, descriptor]) => {
|
|
39
|
-
if (name === "constructor")
|
|
40
|
-
return;
|
|
41
|
-
Object.defineProperty(derivedCtor.prototype, name, { ...descriptor, configurable: true });
|
|
42
|
-
});
|
|
43
|
-
});
|
|
44
|
-
};
|
|
45
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
46
|
-
0 && (module.exports = {
|
|
47
|
-
applyMixins
|
|
48
|
-
});
|
package/src/capitalize.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare const capitalize: (str: string) => string;
|