@bool-ts/core 2.3.0 → 2.3.1
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/dist/index.js +4 -4
- package/dist/index.js.map +4 -4
- package/dist/utils/colors.d.ts +18 -18
- package/package.json +1 -1
- package/src/entities/application.ts +60 -11
- package/src/utils/colors.ts +26 -32
package/dist/utils/colors.d.ts
CHANGED
|
@@ -5,26 +5,26 @@ type AnsiOptions = {
|
|
|
5
5
|
underline?: boolean;
|
|
6
6
|
};
|
|
7
7
|
declare const ansiColors: Readonly<{
|
|
8
|
-
black:
|
|
9
|
-
red:
|
|
10
|
-
green:
|
|
11
|
-
yellow:
|
|
12
|
-
blue:
|
|
13
|
-
magenta:
|
|
14
|
-
cyan:
|
|
15
|
-
white:
|
|
16
|
-
gray:
|
|
8
|
+
black: "38;5;16";
|
|
9
|
+
red: "38;5;196";
|
|
10
|
+
green: "38;5;46";
|
|
11
|
+
yellow: "38;5;226";
|
|
12
|
+
blue: "38;5;21";
|
|
13
|
+
magenta: "38;5;201";
|
|
14
|
+
cyan: "38;5;51";
|
|
15
|
+
white: "38;5;231";
|
|
16
|
+
gray: "38;5;244";
|
|
17
17
|
}>;
|
|
18
18
|
declare const backgroundColors: Readonly<{
|
|
19
|
-
black:
|
|
20
|
-
red:
|
|
21
|
-
green:
|
|
22
|
-
yellow:
|
|
23
|
-
blue:
|
|
24
|
-
magenta:
|
|
25
|
-
cyan:
|
|
26
|
-
white:
|
|
27
|
-
gray:
|
|
19
|
+
black: "48;5;16";
|
|
20
|
+
red: "48;5;196";
|
|
21
|
+
green: "48;5;46";
|
|
22
|
+
yellow: "48;5;226";
|
|
23
|
+
blue: "48;5;21";
|
|
24
|
+
magenta: "48;5;201";
|
|
25
|
+
cyan: "48;5;51";
|
|
26
|
+
white: "48;5;231";
|
|
27
|
+
gray: "48;5;244";
|
|
28
28
|
}>;
|
|
29
29
|
export declare const ansiText: (text: string, options?: AnsiOptions) => string;
|
|
30
30
|
export {};
|
package/package.json
CHANGED
|
@@ -268,15 +268,15 @@ export class Application<TRootClass extends Object = Object> {
|
|
|
268
268
|
method = request.method.toUpperCase(),
|
|
269
269
|
responseHeaders = new Headers();
|
|
270
270
|
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
.set(queryArgsKey, query);
|
|
271
|
+
const context = new Context()
|
|
272
|
+
.setOptions({ isStatic: true })
|
|
273
|
+
.set(httpServerArgsKey, server)
|
|
274
|
+
.set(requestArgsKey, request)
|
|
275
|
+
.set(requestHeaderArgsKey, request.headers)
|
|
276
|
+
.set(responseHeadersArgsKey, responseHeaders)
|
|
277
|
+
.set(queryArgsKey, query);
|
|
279
278
|
|
|
279
|
+
try {
|
|
280
280
|
[
|
|
281
281
|
...(!allowCredentials
|
|
282
282
|
? []
|
|
@@ -369,9 +369,12 @@ export class Application<TRootClass extends Object = Object> {
|
|
|
369
369
|
} finally {
|
|
370
370
|
if (allowLogsMethods) {
|
|
371
371
|
const end = performance.now();
|
|
372
|
+
const responseStatus = context.get(responseStatusArgsKey, { isStatic: false });
|
|
373
|
+
const inferedResponseStatus =
|
|
374
|
+
typeof responseStatus !== "number" || !responseStatus ? 0 : responseStatus;
|
|
372
375
|
const pathname = ansiText(url.pathname, { color: "blue" });
|
|
373
376
|
const convertedPID = `${Bun.color("yellow", "ansi")}${process.pid}`;
|
|
374
|
-
const convertedMethod = ansiText(request.method
|
|
377
|
+
const convertedMethod = ansiText(` ${request.method} `, {
|
|
375
378
|
color: "yellow",
|
|
376
379
|
backgroundColor: "blue"
|
|
377
380
|
});
|
|
@@ -387,18 +390,64 @@ export class Application<TRootClass extends Object = Object> {
|
|
|
387
390
|
}
|
|
388
391
|
);
|
|
389
392
|
const convertedTime = ansiText(
|
|
390
|
-
|
|
393
|
+
` ${Math.round((end - start + Number.EPSILON) * 10 ** 2) / 10 ** 2}ms `,
|
|
391
394
|
{
|
|
392
395
|
color: "yellow",
|
|
393
396
|
backgroundColor: "blue"
|
|
394
397
|
}
|
|
395
398
|
);
|
|
399
|
+
const convertedResponseStatus = ansiText(
|
|
400
|
+
` ${inferedResponseStatus} (${inferStatusText(inferedResponseStatus)}) `,
|
|
401
|
+
(() => {
|
|
402
|
+
if (inferedResponseStatus >= 100 && inferedResponseStatus < 200)
|
|
403
|
+
return {
|
|
404
|
+
color: "white",
|
|
405
|
+
backgroundColor: "cyan"
|
|
406
|
+
};
|
|
407
|
+
else if (inferedResponseStatus >= 200 && inferedResponseStatus < 300)
|
|
408
|
+
return {
|
|
409
|
+
color: "white",
|
|
410
|
+
backgroundColor: "blue"
|
|
411
|
+
};
|
|
412
|
+
else if (inferedResponseStatus >= 300 && inferedResponseStatus < 400)
|
|
413
|
+
return {
|
|
414
|
+
color: "black",
|
|
415
|
+
backgroundColor: "magenta"
|
|
416
|
+
};
|
|
417
|
+
else if (inferedResponseStatus >= 400 && inferedResponseStatus < 500)
|
|
418
|
+
return {
|
|
419
|
+
color: "black",
|
|
420
|
+
backgroundColor: "yellow"
|
|
421
|
+
};
|
|
422
|
+
else if (inferedResponseStatus >= 500 && inferedResponseStatus < 600)
|
|
423
|
+
return {
|
|
424
|
+
color: "white",
|
|
425
|
+
backgroundColor: "red"
|
|
426
|
+
};
|
|
427
|
+
else
|
|
428
|
+
return {
|
|
429
|
+
color: "black",
|
|
430
|
+
backgroundColor: "gray"
|
|
431
|
+
};
|
|
432
|
+
})()
|
|
433
|
+
);
|
|
396
434
|
|
|
397
435
|
allowLogsMethods.includes(
|
|
398
436
|
request.method.toUpperCase() as (typeof allowLogsMethods)[number]
|
|
399
437
|
) &&
|
|
400
438
|
console.info(
|
|
401
|
-
|
|
439
|
+
[
|
|
440
|
+
`PID: ${convertedPID}`,
|
|
441
|
+
`Method: ${convertedMethod}`,
|
|
442
|
+
`IP: ${convertedReqIp}`,
|
|
443
|
+
pathname,
|
|
444
|
+
`Time: ${convertedTime}`,
|
|
445
|
+
typeof responseStatus !== "number" || !responseStatus
|
|
446
|
+
? undefined
|
|
447
|
+
: convertedResponseStatus
|
|
448
|
+
]
|
|
449
|
+
.filter((x) => !!x?.trim())
|
|
450
|
+
.join(" - ")
|
|
402
451
|
);
|
|
403
452
|
}
|
|
404
453
|
}
|
package/src/utils/colors.ts
CHANGED
|
@@ -6,51 +6,45 @@ type AnsiOptions = {
|
|
|
6
6
|
};
|
|
7
7
|
|
|
8
8
|
const ansiColors = Object.freeze({
|
|
9
|
-
black:
|
|
10
|
-
red:
|
|
11
|
-
green:
|
|
12
|
-
yellow:
|
|
13
|
-
blue:
|
|
14
|
-
magenta:
|
|
15
|
-
cyan:
|
|
16
|
-
white:
|
|
17
|
-
gray:
|
|
9
|
+
black: "38;5;16",
|
|
10
|
+
red: "38;5;196",
|
|
11
|
+
green: "38;5;46",
|
|
12
|
+
yellow: "38;5;226",
|
|
13
|
+
blue: "38;5;21",
|
|
14
|
+
magenta: "38;5;201",
|
|
15
|
+
cyan: "38;5;51",
|
|
16
|
+
white: "38;5;231",
|
|
17
|
+
gray: "38;5;244"
|
|
18
18
|
});
|
|
19
19
|
|
|
20
20
|
const backgroundColors = Object.freeze({
|
|
21
|
-
black:
|
|
22
|
-
red:
|
|
23
|
-
green:
|
|
24
|
-
yellow:
|
|
25
|
-
blue:
|
|
26
|
-
magenta:
|
|
27
|
-
cyan:
|
|
28
|
-
white:
|
|
29
|
-
gray:
|
|
21
|
+
black: "48;5;16",
|
|
22
|
+
red: "48;5;196",
|
|
23
|
+
green: "48;5;46",
|
|
24
|
+
yellow: "48;5;226",
|
|
25
|
+
blue: "48;5;21",
|
|
26
|
+
magenta: "48;5;201",
|
|
27
|
+
cyan: "48;5;51",
|
|
28
|
+
white: "48;5;231",
|
|
29
|
+
gray: "48;5;244"
|
|
30
30
|
});
|
|
31
31
|
|
|
32
32
|
export const ansiText = (text: string, options: AnsiOptions = {}) => {
|
|
33
33
|
const { color, backgroundColor, bold, underline } = options;
|
|
34
|
+
const codes: string[] = [];
|
|
34
35
|
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
if (bold) {
|
|
38
|
-
ansiCode += "\x1b[1m"; // Mã ANSI cho in đậm
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
if (underline) {
|
|
42
|
-
ansiCode += "\x1b[4m"; // Mã ANSI cho gạch chân
|
|
43
|
-
}
|
|
36
|
+
if (bold) codes.push("1");
|
|
37
|
+
if (underline) codes.push("4");
|
|
44
38
|
|
|
45
39
|
if (color && ansiColors[color]) {
|
|
46
|
-
|
|
40
|
+
codes.push(ansiColors[color]);
|
|
47
41
|
}
|
|
48
42
|
|
|
49
|
-
// Màu nền
|
|
50
43
|
if (backgroundColor && backgroundColors[backgroundColor]) {
|
|
51
|
-
|
|
44
|
+
codes.push(backgroundColors[backgroundColor]);
|
|
52
45
|
}
|
|
53
46
|
|
|
54
|
-
|
|
55
|
-
|
|
47
|
+
if (codes.length === 0) return text;
|
|
48
|
+
|
|
49
|
+
return `\x1b[${codes.join(";")}m${text}\x1b[0m`;
|
|
56
50
|
};
|