@bool-ts/core 1.6.12 → 1.6.14

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.
@@ -1,9 +1,9 @@
1
1
  import type { THttpMethods } from "../http";
2
- export type TRouteModel<T = unknown> = Readonly<Required<{
2
+ export type TRouteModel<T = unknown> = Readonly<{
3
3
  class: new (...args: Array<any>) => T;
4
4
  funcName: string | symbol;
5
5
  func: (...args: Array<any>) => unknown;
6
- }>>;
6
+ }>;
7
7
  export declare class Route {
8
8
  static rootPattern: string;
9
9
  readonly alias: string;
@@ -46,41 +46,41 @@ export declare class Route {
46
46
  * @param handlers
47
47
  * @returns
48
48
  */
49
- connect(handler: TRouteModel): this | Map<keyof THttpMethods, Readonly<Required<{
49
+ connect(handler: TRouteModel): this | Map<keyof THttpMethods, Readonly<{
50
50
  class: new (...args: Array<any>) => unknown;
51
51
  funcName: string | symbol;
52
52
  func: (...args: Array<any>) => unknown;
53
- }>>>;
53
+ }>>;
54
54
  /**
55
55
  *
56
56
  * @param handlers
57
57
  * @returns
58
58
  */
59
- options(handler: TRouteModel): this | Map<keyof THttpMethods, Readonly<Required<{
59
+ options(handler: TRouteModel): this | Map<keyof THttpMethods, Readonly<{
60
60
  class: new (...args: Array<any>) => unknown;
61
61
  funcName: string | symbol;
62
62
  func: (...args: Array<any>) => unknown;
63
- }>>>;
63
+ }>>;
64
64
  /**
65
65
  *
66
66
  * @param handlers
67
67
  * @returns
68
68
  */
69
- trace(handler: TRouteModel): this | Map<keyof THttpMethods, Readonly<Required<{
69
+ trace(handler: TRouteModel): this | Map<keyof THttpMethods, Readonly<{
70
70
  class: new (...args: Array<any>) => unknown;
71
71
  funcName: string | symbol;
72
72
  func: (...args: Array<any>) => unknown;
73
- }>>>;
73
+ }>>;
74
74
  /**
75
75
  *
76
76
  * @param handlers
77
77
  * @returns
78
78
  */
79
- patch(handler: TRouteModel): this | Map<keyof THttpMethods, Readonly<Required<{
79
+ patch(handler: TRouteModel): this | Map<keyof THttpMethods, Readonly<{
80
80
  class: new (...args: Array<any>) => unknown;
81
81
  funcName: string | symbol;
82
82
  func: (...args: Array<any>) => unknown;
83
- }>>>;
83
+ }>>;
84
84
  /**
85
85
  *
86
86
  * @param handlers
@@ -180,7 +180,7 @@ export const BoolFactory = async (target, options) => {
180
180
  });
181
181
  Bun.serve({
182
182
  port: options.port,
183
- fetch: async (request) => {
183
+ fetch: async (request, server) => {
184
184
  const { headers } = request;
185
185
  const start = performance.now();
186
186
  const url = new URL(request.url);
@@ -320,7 +320,7 @@ export const BoolFactory = async (target, options) => {
320
320
  });
321
321
  }
322
322
  context[paramsArgsKey] = result.parameters;
323
- context[routeModelArgsKey] = result;
323
+ context[routeModelArgsKey] = result.model;
324
324
  let responseBody = undefined;
325
325
  // Execute before dispatcher(s)
326
326
  for (let i = 0; i < beforeDispatcherGroup.length; i++) {
@@ -509,7 +509,10 @@ export const BoolFactory = async (target, options) => {
509
509
  const end = performance.now();
510
510
  const convertedPID = `${process.pid}`.yellow;
511
511
  const convertedMethod = `${request.method.yellow}`.bgBlue;
512
- const convertedReqIp = `${request.headers.get("x-forwarded-for") || request.headers.get("x-real-ip") || "<Unknown>"}`.yellow;
512
+ const convertedReqIp = `${request.headers.get("x-forwarded-for") ||
513
+ request.headers.get("x-real-ip") ||
514
+ server.requestIP(request)?.address ||
515
+ "<Unknown>"}`.yellow;
513
516
  const convertedTime = `${Math.round((end - start + Number.EPSILON) * 10 ** 2) / 10 ** 2}ms`.yellow;
514
517
  allowLogsMethods.includes(request.method.toUpperCase()) &&
515
518
  console.info(`PID: ${convertedPID} - Method: ${convertedMethod} - IP: ${convertedReqIp} - ${url.pathname.blue} - Time: ${convertedTime}`);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bool-ts/core",
3
- "version": "1.6.12",
3
+ "version": "1.6.14",
4
4
  "description": "",
5
5
  "main": "dist/index.js",
6
6
  "scripts": {
@@ -2,13 +2,11 @@
2
2
 
3
3
  import type { THttpMethods } from "../http";
4
4
 
5
- export type TRouteModel<T = unknown> = Readonly<
6
- Required<{
7
- class: new (...args: Array<any>) => T;
8
- funcName: string | symbol;
9
- func: (...args: Array<any>) => unknown;
10
- }>
11
- >;
5
+ export type TRouteModel<T = unknown> = Readonly<{
6
+ class: new (...args: Array<any>) => T;
7
+ funcName: string | symbol;
8
+ func: (...args: Array<any>) => unknown;
9
+ }>;
12
10
 
13
11
  export class Route {
14
12
  public static rootPattern = ":([a-z0-9A-Z_.-]{1,})";
@@ -268,7 +268,7 @@ export const BoolFactory = async (target: new (...args: any[]) => unknown, optio
268
268
 
269
269
  Bun.serve({
270
270
  port: options.port,
271
- fetch: async (request) => {
271
+ fetch: async (request, server) => {
272
272
  const { headers } = request;
273
273
  const start = performance.now();
274
274
  const url = new URL(request.url);
@@ -475,7 +475,7 @@ export const BoolFactory = async (target: new (...args: any[]) => unknown, optio
475
475
  }
476
476
 
477
477
  context[paramsArgsKey] = result.parameters;
478
- context[routeModelArgsKey] = result;
478
+ context[routeModelArgsKey] = result.model;
479
479
 
480
480
  let responseBody = undefined;
481
481
 
@@ -785,7 +785,10 @@ export const BoolFactory = async (target: new (...args: any[]) => unknown, optio
785
785
  const convertedPID = `${process.pid}`.yellow;
786
786
  const convertedMethod = `${request.method.yellow}`.bgBlue;
787
787
  const convertedReqIp = `${
788
- request.headers.get("x-forwarded-for") || request.headers.get("x-real-ip") || "<Unknown>"
788
+ request.headers.get("x-forwarded-for") ||
789
+ request.headers.get("x-real-ip") ||
790
+ server.requestIP(request)?.address ||
791
+ "<Unknown>"
789
792
  }`.yellow;
790
793
  const convertedTime = `${Math.round((end - start + Number.EPSILON) * 10 ** 2) / 10 ** 2}ms`.yellow;
791
794