@bool-ts/core 2.1.2 → 2.2.0

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/README.md CHANGED
@@ -26,7 +26,7 @@ bun add @bool-ts/core
26
26
 
27
27
  ## Documentation
28
28
 
29
- For detailed documentation, please visit [https://boolts.dev](https://boolts.dev)
29
+ For detailed documentation, please visit [https://www.booljs.com](https://www.booljs.com)
30
30
 
31
31
  ## Quick Start
32
32
 
@@ -1,7 +1,7 @@
1
1
  import type { TConstructor } from "../ultils";
2
2
  type TLoaders<TConfig extends {} = {}> = Record<string | symbol, (args: {
3
3
  config: TConfig;
4
- }) => [string | symbol, any] | Promise<[string | symbol, any]>>;
4
+ }) => [string | symbol, unknown] | Promise<[string | symbol, unknown]>>;
5
5
  export type TContainerConfig<TConfig> = TConfig | (() => TConfig | Promise<TConfig>) | Readonly<{
6
6
  key: symbol;
7
7
  value: TConfig | (() => TConfig | Promise<TConfig>);
@@ -2,7 +2,7 @@ import type { TConstructor } from "../ultils";
2
2
  type TInstances = Array<new (...args: any[]) => any>;
3
3
  type TLoaders<TConfig extends {} = {}> = Record<string | symbol, (args: {
4
4
  config: TConfig;
5
- }) => [string | symbol, any] | Promise<[string | symbol, any]>>;
5
+ }) => [string | symbol, unknown] | Promise<[string | symbol, unknown]>>;
6
6
  export type TModuleConfig<TConfig> = TConfig | (() => TConfig | Promise<TConfig>) | Readonly<{
7
7
  key: symbol;
8
8
  value: TConfig | (() => TConfig | Promise<TConfig>);
@@ -1,16 +1,17 @@
1
1
  import type { TContainerMetadata, TWebSocketEventHandlerMetadata } from "../decorators";
2
+ import type { THttpMethods } from "../http";
3
+ import type { ICustomValidator } from "../interfaces/customValidator";
2
4
  import type { TConstructor } from "../ultils";
3
5
  import { parse as QsParse } from "qs";
4
- import type { ICustomValidator } from "../interfaces/customValidator";
5
6
  type TParamsType = Record<string, string>;
6
- type TApplicationOptions = Required<{
7
+ type TApplicationOptions<AllowedMethods extends Array<THttpMethods> = Array<THttpMethods>> = Required<{
7
8
  port: number;
8
9
  }> & Partial<{
9
10
  config: Record<string | symbol, any> | (() => Record<string | symbol, any>);
10
11
  prefix: string;
11
12
  debug: boolean;
12
13
  log: Partial<{
13
- methods: Array<"GET" | "POST" | "PUT" | "PATCH" | "DELETE" | "OPTIONS">;
14
+ methods: AllowedMethods;
14
15
  }>;
15
16
  queryParser: Parameters<typeof QsParse>[1];
16
17
  static: Required<{
@@ -22,7 +23,7 @@ type TApplicationOptions = Required<{
22
23
  cors: Partial<{
23
24
  credentials: boolean;
24
25
  origins: string | Array<string>;
25
- methods: Array<"GET" | "POST" | "PUT" | "PATCH" | "DELETE" | "OPTIONS">;
26
+ methods: Array<THttpMethods>;
26
27
  headers: Array<string>;
27
28
  }>;
28
29
  }>;
@@ -7,58 +7,69 @@ export type THttpRouteModel<T = unknown> = Readonly<{
7
7
  argumentsMetadata: TArgumentsMetadataCollection;
8
8
  }>;
9
9
  export declare class HttpRoute {
10
+ #private;
10
11
  static rootPattern: string;
11
12
  static innerRootPattern: string;
12
13
  readonly alias: string;
13
- private _map;
14
- constructor(alias: string);
14
+ constructor({ alias }: {
15
+ alias: string;
16
+ });
15
17
  /**
16
18
  *
17
19
  * @param pathname
18
20
  * @param method
19
21
  * @returns
20
22
  */
21
- test(pathname: string, method: keyof THttpMethods): Readonly<{
22
- parameters: Record<string, string>;
23
+ test({ pathname }: {
24
+ pathname: string;
25
+ }): boolean;
26
+ exec({ pathname, method }: {
27
+ pathname: string;
28
+ method: THttpMethods;
29
+ }): Readonly<{
30
+ parameters: Record<string, string | undefined>;
23
31
  model: THttpRouteModel;
24
- }> | false | undefined;
32
+ }> | null;
25
33
  /**
26
34
  *
27
- * @param pathname
28
- * @param method
35
+ * @param model
29
36
  * @returns
30
37
  */
31
- isMatch(pathname: string, method: keyof THttpMethods): boolean | undefined;
32
- /**
33
- *
34
- * @param handler
35
- * @returns
36
- */
37
- get(handler: THttpRouteModel): this;
38
+ get({ model }: {
39
+ model: THttpRouteModel;
40
+ }): this;
38
41
  /**
39
42
  *
40
- * @param handler
43
+ * @param model
41
44
  * @returns
42
45
  */
43
- post(handler: THttpRouteModel): this;
46
+ post({ model }: {
47
+ model: THttpRouteModel;
48
+ }): this;
44
49
  /**
45
50
  *
46
- * @param handler
51
+ * @param model
47
52
  * @returns
48
53
  */
49
- put(handler: THttpRouteModel): this;
54
+ put({ model }: {
55
+ model: THttpRouteModel;
56
+ }): this;
50
57
  /**
51
58
  *
52
- * @param handler
59
+ * @param model
53
60
  * @returns
54
61
  */
55
- delete(handler: THttpRouteModel): this;
62
+ delete({ model }: {
63
+ model: THttpRouteModel;
64
+ }): this;
56
65
  /**
57
66
  *
58
- * @param handler
67
+ * @param model
59
68
  * @returns
60
69
  */
61
- connect(handler: THttpRouteModel): this | Map<keyof THttpMethods, Readonly<{
70
+ connect({ model }: {
71
+ model: THttpRouteModel;
72
+ }): this | Map<THttpMethods, Readonly<{
62
73
  class: new (...args: Array<any>) => unknown;
63
74
  funcName: string | symbol;
64
75
  func: (...args: Array<any>) => unknown;
@@ -66,10 +77,12 @@ export declare class HttpRoute {
66
77
  }>>;
67
78
  /**
68
79
  *
69
- * @param handler
80
+ * @param model
70
81
  * @returns
71
82
  */
72
- options(handler: THttpRouteModel): this | Map<keyof THttpMethods, Readonly<{
83
+ options({ model }: {
84
+ model: THttpRouteModel;
85
+ }): this | Map<THttpMethods, Readonly<{
73
86
  class: new (...args: Array<any>) => unknown;
74
87
  funcName: string | symbol;
75
88
  func: (...args: Array<any>) => unknown;
@@ -77,10 +90,12 @@ export declare class HttpRoute {
77
90
  }>>;
78
91
  /**
79
92
  *
80
- * @param handler
93
+ * @param model
81
94
  * @returns
82
95
  */
83
- trace(handler: THttpRouteModel): this | Map<keyof THttpMethods, Readonly<{
96
+ trace({ model }: {
97
+ model: THttpRouteModel;
98
+ }): this | Map<THttpMethods, Readonly<{
84
99
  class: new (...args: Array<any>) => unknown;
85
100
  funcName: string | symbol;
86
101
  func: (...args: Array<any>) => unknown;
@@ -88,10 +103,12 @@ export declare class HttpRoute {
88
103
  }>>;
89
104
  /**
90
105
  *
91
- * @param handler
106
+ * @param model
92
107
  * @returns
93
108
  */
94
- patch(handler: THttpRouteModel): this | Map<keyof THttpMethods, Readonly<{
109
+ patch({ model }: {
110
+ model: THttpRouteModel;
111
+ }): this | Map<THttpMethods, Readonly<{
95
112
  class: new (...args: Array<any>) => unknown;
96
113
  funcName: string | symbol;
97
114
  func: (...args: Array<any>) => unknown;
@@ -99,7 +116,7 @@ export declare class HttpRoute {
99
116
  }>>;
100
117
  /**
101
118
  *
102
- * @param handler
119
+ * @param model
103
120
  * @returns
104
121
  */
105
122
  private _thinAlias;
@@ -2,7 +2,9 @@ import HttpRoute from "./httpRoute";
2
2
  export declare class HttpRouter {
3
3
  readonly alias: string;
4
4
  private _routes;
5
- constructor(alias: string);
5
+ constructor({ alias }: {
6
+ alias: string;
7
+ });
6
8
  /**
7
9
  *
8
10
  * @param alias
@@ -1,16 +1,20 @@
1
1
  import type { THttpMethods } from "../http";
2
+ import type { THttpRouteModel } from "./httpRoute";
2
3
  import type { HttpRouter } from "./httpRouter";
3
4
  export declare class HttpRouterGroup {
4
5
  private _routers;
5
6
  add(...routers: Array<HttpRouter>): this;
6
7
  /**
7
8
  *
8
- * @param pathame
9
+ * @param pathname
9
10
  * @param method
10
11
  * @returns
11
12
  */
12
- find(pathame: string, method: keyof THttpMethods): Readonly<{
13
- parameters: Record<string, string>;
14
- model: import("./httpRoute").THttpRouteModel;
15
- }> | undefined;
13
+ find({ pathname, method }: {
14
+ pathname: string;
15
+ method: THttpMethods;
16
+ }): Readonly<{
17
+ parameters: Record<string, string | undefined>;
18
+ model: THttpRouteModel;
19
+ }> | null;
16
20
  }
@@ -29,13 +29,13 @@ export declare const httpClientErrors: Readonly<{
29
29
  431: "REQUEST_HEADER_FIELDS_TOO_LARGE";
30
30
  451: "UNAVAILABLE_FOR_LEGAL_REASONS";
31
31
  }>;
32
- export declare class HttpClientError<T extends keyof typeof httpClientErrors = keyof typeof httpClientErrors, K = any> extends Error {
32
+ export declare class HttpClientError<T extends keyof typeof httpClientErrors = keyof typeof httpClientErrors, K = unknown> extends Error {
33
33
  readonly httpCode: T;
34
34
  readonly message: (typeof httpClientErrors)[T] | string;
35
- readonly data: K;
35
+ readonly data: K | undefined;
36
36
  constructor({ httpCode, data, message }: {
37
37
  httpCode: T;
38
- data: K;
38
+ data?: K;
39
39
  message?: string;
40
40
  });
41
41
  }
@@ -1,14 +1,6 @@
1
- export type THttpMethods = {
2
- GET: "GET";
3
- HEAD: "HEAD";
4
- POST: "POST";
5
- PUT: "PUT";
6
- DELETE: "DELETE";
7
- CONNECT: "CONNECT";
8
- OPTIONS: "OPTIONS";
9
- TRACE: "TRACE";
10
- PATCH: "PATCH";
11
- };
1
+ export type THttpMethods = "GET" | "HEAD" | "POST" | "PUT" | "DELETE" | "CONNECT" | "OPTIONS" | "TRACE" | "PATCH";
2
+ export declare const httpMethods: Array<THttpMethods>;
3
+ export declare const httpMethodsStandardization: (method: string) => method is THttpMethods;
12
4
  export declare const jsonErrorInfer: (data: any, headers?: Headers) => Response;
13
5
  export * from "./clientError";
14
6
  export * from "./serverError";
@@ -14,10 +14,10 @@ export declare const httpServerErrors: Readonly<{
14
14
  export declare class HttpServerError<T extends keyof typeof httpServerErrors = keyof typeof httpServerErrors, K = any> extends Error {
15
15
  readonly httpCode: T;
16
16
  readonly message: (typeof httpServerErrors)[T] | string;
17
- readonly data: K;
17
+ readonly data: K | undefined;
18
18
  constructor({ httpCode, data, message }: {
19
19
  httpCode: T;
20
- data: K;
20
+ data?: K;
21
21
  message?: string;
22
22
  });
23
23
  }