@bool-ts/core 2.1.3 → 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 +1 -1
- package/dist/entities/application.d.ts +5 -4
- package/dist/entities/httpRoute.d.ts +46 -29
- package/dist/entities/httpRouter.d.ts +3 -1
- package/dist/entities/httpRouterGroup.d.ts +9 -5
- package/dist/http/clientError.d.ts +3 -3
- package/dist/http/index.d.ts +3 -11
- package/dist/http/serverError.d.ts +2 -2
- package/dist/index.js +6 -6
- package/dist/index.js.map +10 -10
- package/package.json +1 -1
- package/src/entities/application.ts +108 -70
- package/src/entities/httpRoute.ts +73 -166
- package/src/entities/httpRouter.ts +2 -4
- package/src/entities/httpRouterGroup.ts +16 -6
- package/src/http/clientError.ts +6 -3
- package/src/http/index.ts +26 -11
- package/src/http/serverError.ts +6 -3
package/README.md
CHANGED
|
@@ -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:
|
|
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<
|
|
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
|
-
|
|
14
|
-
|
|
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
|
|
22
|
-
|
|
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
|
-
}> |
|
|
32
|
+
}> | null;
|
|
25
33
|
/**
|
|
26
34
|
*
|
|
27
|
-
* @param
|
|
28
|
-
* @param method
|
|
35
|
+
* @param model
|
|
29
36
|
* @returns
|
|
30
37
|
*/
|
|
31
|
-
|
|
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
|
|
43
|
+
* @param model
|
|
41
44
|
* @returns
|
|
42
45
|
*/
|
|
43
|
-
post(
|
|
46
|
+
post({ model }: {
|
|
47
|
+
model: THttpRouteModel;
|
|
48
|
+
}): this;
|
|
44
49
|
/**
|
|
45
50
|
*
|
|
46
|
-
* @param
|
|
51
|
+
* @param model
|
|
47
52
|
* @returns
|
|
48
53
|
*/
|
|
49
|
-
put(
|
|
54
|
+
put({ model }: {
|
|
55
|
+
model: THttpRouteModel;
|
|
56
|
+
}): this;
|
|
50
57
|
/**
|
|
51
58
|
*
|
|
52
|
-
* @param
|
|
59
|
+
* @param model
|
|
53
60
|
* @returns
|
|
54
61
|
*/
|
|
55
|
-
delete(
|
|
62
|
+
delete({ model }: {
|
|
63
|
+
model: THttpRouteModel;
|
|
64
|
+
}): this;
|
|
56
65
|
/**
|
|
57
66
|
*
|
|
58
|
-
* @param
|
|
67
|
+
* @param model
|
|
59
68
|
* @returns
|
|
60
69
|
*/
|
|
61
|
-
connect(
|
|
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
|
|
80
|
+
* @param model
|
|
70
81
|
* @returns
|
|
71
82
|
*/
|
|
72
|
-
options(
|
|
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
|
|
93
|
+
* @param model
|
|
81
94
|
* @returns
|
|
82
95
|
*/
|
|
83
|
-
trace(
|
|
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
|
|
106
|
+
* @param model
|
|
92
107
|
* @returns
|
|
93
108
|
*/
|
|
94
|
-
patch(
|
|
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
|
|
119
|
+
* @param model
|
|
103
120
|
* @returns
|
|
104
121
|
*/
|
|
105
122
|
private _thinAlias;
|
|
@@ -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
|
|
9
|
+
* @param pathname
|
|
9
10
|
* @param method
|
|
10
11
|
* @returns
|
|
11
12
|
*/
|
|
12
|
-
find(
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
}
|
|
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 =
|
|
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
|
|
38
|
+
data?: K;
|
|
39
39
|
message?: string;
|
|
40
40
|
});
|
|
41
41
|
}
|
package/dist/http/index.d.ts
CHANGED
|
@@ -1,14 +1,6 @@
|
|
|
1
|
-
export type THttpMethods =
|
|
2
|
-
|
|
3
|
-
|
|
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
|
|
20
|
+
data?: K;
|
|
21
21
|
message?: string;
|
|
22
22
|
});
|
|
23
23
|
}
|