@bool-ts/core 1.3.2 → 1.4.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/.prettierrc +11 -0
- package/LICENSE +21 -21
- package/__test/controller.ts +66 -79
- package/__test/index.ts +8 -11
- package/__test/interfaces.ts +7 -7
- package/__test/module.ts +16 -17
- package/__test/repository.ts +16 -16
- package/__test/service.ts +20 -20
- package/bun.lockb +0 -0
- package/dist/decorators/arguments.d.ts +31 -0
- package/dist/decorators/arguments.js +67 -0
- package/dist/decorators/controller.d.ts +2 -2
- package/dist/decorators/controller.js +6 -10
- package/dist/decorators/http.d.ts +1 -1
- package/dist/decorators/http.js +16 -103
- package/dist/decorators/index.d.ts +1 -0
- package/dist/decorators/index.js +7 -26
- package/dist/decorators/inject.js +5 -9
- package/dist/decorators/injectable.d.ts +2 -2
- package/dist/decorators/injectable.js +4 -8
- package/dist/decorators/module.d.ts +4 -2
- package/dist/decorators/module.js +4 -8
- package/dist/decorators/zodSchema.d.ts +1 -1
- package/dist/decorators/zodSchema.js +5 -8
- package/dist/entities/index.d.ts +3 -0
- package/dist/entities/index.js +3 -0
- package/dist/entities/route.d.ts +101 -0
- package/dist/entities/route.js +257 -0
- package/dist/entities/router.d.ts +10 -0
- package/dist/entities/router.js +25 -0
- package/dist/entities/routerGroup.d.ts +14 -0
- package/dist/entities/routerGroup.js +24 -0
- package/dist/hooks/factory.d.ts +12 -12
- package/dist/hooks/factory.js +180 -151
- package/dist/hooks/index.js +2 -7
- package/dist/hooks/injector.js +7 -10
- package/dist/http/clientError.d.ts +1 -1
- package/dist/http/clientError.js +3 -7
- package/dist/http/index.d.ts +12 -2
- package/dist/http/index.js +34 -73
- package/dist/http/serverError.js +3 -7
- package/dist/index.js +5 -21
- package/dist/interfaces/index.js +1 -3
- package/dist/ultils/asyncFunction.js +1 -4
- package/dist/ultils/index.js +1 -17
- package/package.json +30 -33
- package/src/decorators/arguments.ts +128 -0
- package/src/decorators/controller.ts +14 -18
- package/src/decorators/http.ts +81 -195
- package/src/decorators/index.ts +7 -6
- package/src/decorators/inject.ts +13 -19
- package/src/decorators/injectable.ts +11 -12
- package/src/decorators/module.ts +21 -22
- package/src/decorators/zodSchema.ts +20 -27
- package/src/entities/index.ts +3 -0
- package/src/entities/route.ts +328 -0
- package/src/entities/router.ts +35 -0
- package/src/entities/routerGroup.ts +34 -0
- package/src/hooks/factory.ts +285 -205
- package/src/hooks/index.ts +2 -2
- package/src/hooks/injector.ts +43 -43
- package/src/http/clientError.ts +45 -56
- package/src/http/index.ts +63 -72
- package/src/http/serverError.ts +38 -38
- package/src/index.ts +6 -6
- package/src/interfaces/index.ts +3 -3
- package/test.http +30 -28
- package/tsconfig.json +107 -109
package/src/http/clientError.ts
CHANGED
|
@@ -1,56 +1,45 @@
|
|
|
1
|
-
export const httpClientErrors = Object.freeze({
|
|
2
|
-
400: "BAD_REQUEST",
|
|
3
|
-
401: "UNAUTHORIZED",
|
|
4
|
-
402: "PAYMENT_REQUIRED",
|
|
5
|
-
403: "FORBIDDEN",
|
|
6
|
-
404: "NOT_FOUND",
|
|
7
|
-
405: "METHOD_NOT_ALLOWED",
|
|
8
|
-
406: "NOT_ACCEPTABLE",
|
|
9
|
-
407: "PROXY_AUTHENCATION_REQUIRED",
|
|
10
|
-
408: "REQUEST_TIMEOUT",
|
|
11
|
-
409: "CONFLICT",
|
|
12
|
-
410: "GONE",
|
|
13
|
-
411: "LENGTH_REQUIRED",
|
|
14
|
-
412: "PRECONDITION_FAILED",
|
|
15
|
-
413: "PAYLOAD_TOO_LARGE",
|
|
16
|
-
414: "URI_TOO_LONG",
|
|
17
|
-
415: "UNSUPPORTED_MEDIA_TYPE",
|
|
18
|
-
416: "RANGE_NOT_SATISFIABLE",
|
|
19
|
-
417: "EXPECTATION_FAILED",
|
|
20
|
-
418: "IM_A_TEAPOT",
|
|
21
|
-
421: "MISDIRECTED_REQUEST",
|
|
22
|
-
422: "UNPROCESSABLE_ENTITY",
|
|
23
|
-
423: "LOCKED",
|
|
24
|
-
424: "FAILED_DEPENDENCY",
|
|
25
|
-
425: "TOO_EARLY_",
|
|
26
|
-
426: "UPGRAGE_REQUIRED",
|
|
27
|
-
428: "PRECONDITION_REQUIRED",
|
|
28
|
-
429: "TOO_MANY_REQUESTS",
|
|
29
|
-
431: "REQUEST_HEADER_FIELDS_TOO_LARGE",
|
|
30
|
-
451: "UNAVAILABLE_FOR_LEGAL_REASONS"
|
|
31
|
-
});
|
|
32
|
-
|
|
33
|
-
export class HttpClientError<
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
httpCode
|
|
43
|
-
data
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
httpCode: T;
|
|
47
|
-
data: K;
|
|
48
|
-
message?: string;
|
|
49
|
-
}) {
|
|
50
|
-
super();
|
|
51
|
-
|
|
52
|
-
this.httpCode = httpCode;
|
|
53
|
-
this.message = !message?.trim() ? httpClientErrors[httpCode] : message.trim();
|
|
54
|
-
this.data = data;
|
|
55
|
-
}
|
|
56
|
-
}
|
|
1
|
+
export const httpClientErrors = Object.freeze({
|
|
2
|
+
400: "BAD_REQUEST",
|
|
3
|
+
401: "UNAUTHORIZED",
|
|
4
|
+
402: "PAYMENT_REQUIRED",
|
|
5
|
+
403: "FORBIDDEN",
|
|
6
|
+
404: "NOT_FOUND",
|
|
7
|
+
405: "METHOD_NOT_ALLOWED",
|
|
8
|
+
406: "NOT_ACCEPTABLE",
|
|
9
|
+
407: "PROXY_AUTHENCATION_REQUIRED",
|
|
10
|
+
408: "REQUEST_TIMEOUT",
|
|
11
|
+
409: "CONFLICT",
|
|
12
|
+
410: "GONE",
|
|
13
|
+
411: "LENGTH_REQUIRED",
|
|
14
|
+
412: "PRECONDITION_FAILED",
|
|
15
|
+
413: "PAYLOAD_TOO_LARGE",
|
|
16
|
+
414: "URI_TOO_LONG",
|
|
17
|
+
415: "UNSUPPORTED_MEDIA_TYPE",
|
|
18
|
+
416: "RANGE_NOT_SATISFIABLE",
|
|
19
|
+
417: "EXPECTATION_FAILED",
|
|
20
|
+
418: "IM_A_TEAPOT",
|
|
21
|
+
421: "MISDIRECTED_REQUEST",
|
|
22
|
+
422: "UNPROCESSABLE_ENTITY",
|
|
23
|
+
423: "LOCKED",
|
|
24
|
+
424: "FAILED_DEPENDENCY",
|
|
25
|
+
425: "TOO_EARLY_",
|
|
26
|
+
426: "UPGRAGE_REQUIRED",
|
|
27
|
+
428: "PRECONDITION_REQUIRED",
|
|
28
|
+
429: "TOO_MANY_REQUESTS",
|
|
29
|
+
431: "REQUEST_HEADER_FIELDS_TOO_LARGE",
|
|
30
|
+
451: "UNAVAILABLE_FOR_LEGAL_REASONS"
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
export class HttpClientError<T extends keyof typeof httpClientErrors = keyof typeof httpClientErrors, K = any> extends Error {
|
|
34
|
+
public readonly httpCode: T;
|
|
35
|
+
public readonly message: (typeof httpClientErrors)[T] | string;
|
|
36
|
+
public readonly data: K;
|
|
37
|
+
|
|
38
|
+
constructor({ httpCode, data, message }: { httpCode: T; data: K; message?: string }) {
|
|
39
|
+
super();
|
|
40
|
+
|
|
41
|
+
this.httpCode = httpCode;
|
|
42
|
+
this.message = !message?.trim() ? httpClientErrors[httpCode] : message.trim();
|
|
43
|
+
this.data = data;
|
|
44
|
+
}
|
|
45
|
+
}
|
package/src/http/index.ts
CHANGED
|
@@ -1,72 +1,63 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
}
|
|
65
|
-
catch (error) {
|
|
66
|
-
console.error(JSON.stringify(error));
|
|
67
|
-
res.end();
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
export * from "./clientError";
|
|
72
|
-
export * from "./serverError";
|
|
1
|
+
import { HttpClientError } from "./clientError";
|
|
2
|
+
import { HttpServerError } from "./serverError";
|
|
3
|
+
|
|
4
|
+
export type THttpMethods = {
|
|
5
|
+
GET: "GET";
|
|
6
|
+
HEAD: "HEAD";
|
|
7
|
+
POST: "POST";
|
|
8
|
+
PUT: "PUT";
|
|
9
|
+
DELETE: "DELETE";
|
|
10
|
+
CONNECT: "CONNECT";
|
|
11
|
+
OPTIONS: "OPTIONS";
|
|
12
|
+
TRACE: "TRACE";
|
|
13
|
+
PATCH: "PATCH";
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
export const jsonErrorInfer = (data: any) => {
|
|
17
|
+
const headers = new Headers();
|
|
18
|
+
|
|
19
|
+
headers.append("Content-Type", "application/json");
|
|
20
|
+
|
|
21
|
+
if (data instanceof HttpClientError || data instanceof HttpServerError) {
|
|
22
|
+
return new Response(JSON.stringify(data), {
|
|
23
|
+
status: data.httpCode,
|
|
24
|
+
statusText: data.message,
|
|
25
|
+
headers: headers
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
return new Response(
|
|
30
|
+
JSON.stringify(
|
|
31
|
+
(() => {
|
|
32
|
+
switch (typeof data) {
|
|
33
|
+
case "object":
|
|
34
|
+
return !(data instanceof Error)
|
|
35
|
+
? data
|
|
36
|
+
: {
|
|
37
|
+
message: data.message,
|
|
38
|
+
code: data.name,
|
|
39
|
+
cause: data.cause
|
|
40
|
+
};
|
|
41
|
+
case "string":
|
|
42
|
+
return {
|
|
43
|
+
message: data
|
|
44
|
+
};
|
|
45
|
+
case "number":
|
|
46
|
+
return {
|
|
47
|
+
code: data
|
|
48
|
+
};
|
|
49
|
+
default:
|
|
50
|
+
return undefined;
|
|
51
|
+
}
|
|
52
|
+
})()
|
|
53
|
+
),
|
|
54
|
+
{
|
|
55
|
+
status: 500,
|
|
56
|
+
statusText: "INTERNAL SERVER ERROR",
|
|
57
|
+
headers: headers
|
|
58
|
+
}
|
|
59
|
+
);
|
|
60
|
+
};
|
|
61
|
+
|
|
62
|
+
export * from "./clientError";
|
|
63
|
+
export * from "./serverError";
|
package/src/http/serverError.ts
CHANGED
|
@@ -1,38 +1,38 @@
|
|
|
1
|
-
export const httpServerErrors = Object.freeze({
|
|
2
|
-
500: "INTERNAL_SERVER_ERROR",
|
|
3
|
-
501: "NOT_IMPLEMENTED",
|
|
4
|
-
502: "BAD_GATEWAY",
|
|
5
|
-
503: "SERVICE_UNAVAILABLE",
|
|
6
|
-
504: "GATEWAY_TIMEOUT",
|
|
7
|
-
505: "HTTP_VERSION_NOT_SUPPORTED",
|
|
8
|
-
506: "VARIANT_ALSO_NEGOTIATES",
|
|
9
|
-
507: "INSUFFICIENT_STORAGE",
|
|
10
|
-
508: "LOOP_DETECTED",
|
|
11
|
-
510: "NOT_EXTENDED",
|
|
12
|
-
511: "NETWORK_AUTHENTICATION_REQUIRED"
|
|
13
|
-
});
|
|
14
|
-
|
|
15
|
-
export class HttpServerError<
|
|
16
|
-
T extends keyof typeof httpServerErrors = keyof typeof httpServerErrors,
|
|
17
|
-
K = any
|
|
18
|
-
> extends Error {
|
|
19
|
-
public readonly httpCode: T;
|
|
20
|
-
public readonly message: typeof httpServerErrors[T] | string;
|
|
21
|
-
public readonly data: K;
|
|
22
|
-
|
|
23
|
-
constructor({
|
|
24
|
-
httpCode,
|
|
25
|
-
data,
|
|
26
|
-
message
|
|
27
|
-
}: {
|
|
28
|
-
httpCode: T;
|
|
29
|
-
data: K;
|
|
30
|
-
message?: string;
|
|
31
|
-
}) {
|
|
32
|
-
super();
|
|
33
|
-
|
|
34
|
-
this.httpCode = httpCode;
|
|
35
|
-
this.message = !message?.trim() ? httpServerErrors[httpCode] : message.trim();
|
|
36
|
-
this.data = data;
|
|
37
|
-
}
|
|
38
|
-
}
|
|
1
|
+
export const httpServerErrors = Object.freeze({
|
|
2
|
+
500: "INTERNAL_SERVER_ERROR",
|
|
3
|
+
501: "NOT_IMPLEMENTED",
|
|
4
|
+
502: "BAD_GATEWAY",
|
|
5
|
+
503: "SERVICE_UNAVAILABLE",
|
|
6
|
+
504: "GATEWAY_TIMEOUT",
|
|
7
|
+
505: "HTTP_VERSION_NOT_SUPPORTED",
|
|
8
|
+
506: "VARIANT_ALSO_NEGOTIATES",
|
|
9
|
+
507: "INSUFFICIENT_STORAGE",
|
|
10
|
+
508: "LOOP_DETECTED",
|
|
11
|
+
510: "NOT_EXTENDED",
|
|
12
|
+
511: "NETWORK_AUTHENTICATION_REQUIRED"
|
|
13
|
+
});
|
|
14
|
+
|
|
15
|
+
export class HttpServerError<
|
|
16
|
+
T extends keyof typeof httpServerErrors = keyof typeof httpServerErrors,
|
|
17
|
+
K = any
|
|
18
|
+
> extends Error {
|
|
19
|
+
public readonly httpCode: T;
|
|
20
|
+
public readonly message: typeof httpServerErrors[T] | string;
|
|
21
|
+
public readonly data: K;
|
|
22
|
+
|
|
23
|
+
constructor({
|
|
24
|
+
httpCode,
|
|
25
|
+
data,
|
|
26
|
+
message
|
|
27
|
+
}: {
|
|
28
|
+
httpCode: T;
|
|
29
|
+
data: K;
|
|
30
|
+
message?: string;
|
|
31
|
+
}) {
|
|
32
|
+
super();
|
|
33
|
+
|
|
34
|
+
this.httpCode = httpCode;
|
|
35
|
+
this.message = !message?.trim() ? httpServerErrors[httpCode] : message.trim();
|
|
36
|
+
this.data = data;
|
|
37
|
+
}
|
|
38
|
+
}
|
package/src/index.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import "reflect-metadata";
|
|
2
|
-
|
|
3
|
-
export * from "./interfaces";
|
|
4
|
-
export * from "./hooks";
|
|
5
|
-
export * from "./decorators";
|
|
6
|
-
export * from "./http";
|
|
1
|
+
import "reflect-metadata";
|
|
2
|
+
|
|
3
|
+
export * from "./interfaces";
|
|
4
|
+
export * from "./hooks";
|
|
5
|
+
export * from "./decorators";
|
|
6
|
+
export * from "./http";
|
package/src/interfaces/index.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
export default {};
|
|
1
|
+
|
|
2
|
+
|
|
3
|
+
export default {};
|
package/test.http
CHANGED
|
@@ -1,28 +1,30 @@
|
|
|
1
|
-
@baseUrl = localhost:3000
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
### Send test GET method
|
|
5
|
-
GET http://{{baseUrl}}/test/abc
|
|
6
|
-
|
|
7
|
-
### Send test POST method
|
|
8
|
-
POST http://{{baseUrl}}/test/abc HTTP/1.1
|
|
9
|
-
content-type: application/json
|
|
10
|
-
|
|
11
|
-
{
|
|
12
|
-
"
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
1
|
+
@baseUrl = localhost:3000
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
### Send test GET method
|
|
5
|
+
GET http://{{baseUrl}}/test/abc/23234
|
|
6
|
+
|
|
7
|
+
### Send test POST method
|
|
8
|
+
POST http://{{baseUrl}}/test/abc/23234 HTTP/1.1
|
|
9
|
+
content-type: application/json
|
|
10
|
+
|
|
11
|
+
{
|
|
12
|
+
"data": {
|
|
13
|
+
"name": "sample",
|
|
14
|
+
"time": "Wed, 21 Oct 2015 18:27:50 GMT"
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
### Send test PUT method
|
|
19
|
+
PUT http://{{baseUrl}}/test
|
|
20
|
+
Content-Type: "application/json"
|
|
21
|
+
|
|
22
|
+
### Send test PATCH method
|
|
23
|
+
PATCH http://{{baseUrl}}/test/abc/23
|
|
24
|
+
Content-Type: "application/json"
|
|
25
|
+
|
|
26
|
+
### Send test DELETE method
|
|
27
|
+
DELETE http://{{baseUrl}}/test
|
|
28
|
+
|
|
29
|
+
### Send test OPTIONS method
|
|
30
|
+
OPTIONS http://{{baseUrl}}/test
|