@bool-ts/core 1.8.1 → 1.9.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/__test/controller.ts +1 -1
- package/__test/dispatcher.ts +2 -2
- package/__test/firstGuard.ts +3 -1
- package/__test/firstMiddleware.ts +3 -2
- package/__test/index.ts +1 -1
- package/__test/module.ts +1 -1
- package/__test/repository.ts +2 -3
- package/__test/secondGuard.ts +1 -1
- package/__test/secondMiddleware.ts +2 -2
- package/__test/service.ts +4 -7
- package/__test/tsconfig.json +6 -2
- package/__test/webSocket.ts +1 -1
- package/dist/index.js +17 -6
- package/package.json +5 -5
- package/dist/decorators/arguments.js +0 -123
- package/dist/decorators/controller.js +0 -9
- package/dist/decorators/dispatcher.js +0 -6
- package/dist/decorators/guard.js +0 -9
- package/dist/decorators/http.js +0 -60
- package/dist/decorators/index.js +0 -13
- package/dist/decorators/inject.js +0 -9
- package/dist/decorators/injectable.js +0 -3
- package/dist/decorators/middleware.js +0 -6
- package/dist/decorators/module.js +0 -48
- package/dist/decorators/webSocket.js +0 -40
- package/dist/decorators/webSocketArguments.js +0 -49
- package/dist/decorators/webSocketEvent.js +0 -24
- package/dist/decorators/zodSchema.js +0 -15
- package/dist/entities/httpRoute.js +0 -268
- package/dist/entities/httpRouter.js +0 -27
- package/dist/entities/httpRouterGroup.js +0 -24
- package/dist/entities/index.js +0 -6
- package/dist/entities/webSocketRoute.js +0 -22
- package/dist/entities/webSocketRouter.js +0 -54
- package/dist/entities/webSocketRouterGroup.js +0 -51
- package/dist/hooks/factory.js +0 -1072
- package/dist/hooks/index.js +0 -2
- package/dist/hooks/injector.js +0 -36
- package/dist/http/clientError.js +0 -42
- package/dist/http/index.js +0 -40
- package/dist/http/serverError.js +0 -24
- package/dist/interfaces/context.js +0 -1
- package/dist/interfaces/controller.js +0 -1
- package/dist/interfaces/dispatcher.js +0 -1
- package/dist/interfaces/guard.js +0 -1
- package/dist/interfaces/index.js +0 -1
- package/dist/interfaces/middleware.js +0 -1
- package/dist/interfaces/module.js +0 -1
- package/dist/interfaces/webSocket.js +0 -1
- package/dist/keys/index.js +0 -31
- package/dist/ultils/asyncFunction.js +0 -1
- package/dist/ultils/colors.js +0 -41
- package/dist/ultils/index.js +0 -3
- package/dist/ultils/socket.js +0 -7
package/dist/hooks/index.js
DELETED
package/dist/hooks/injector.js
DELETED
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
import "reflect-metadata";
|
|
2
|
-
import { controllerKey, dispatcherKey, guardKey, injectableKey, injectKey, middlewareKey, webSocketKey } from "../keys";
|
|
3
|
-
export class Injector {
|
|
4
|
-
_mapper = new Map();
|
|
5
|
-
/**
|
|
6
|
-
*
|
|
7
|
-
* @param constructor
|
|
8
|
-
*/
|
|
9
|
-
get(definition) {
|
|
10
|
-
if (this._mapper.has(definition)) {
|
|
11
|
-
return this._mapper.get(definition);
|
|
12
|
-
}
|
|
13
|
-
if (typeof definition !== "function") {
|
|
14
|
-
return undefined;
|
|
15
|
-
}
|
|
16
|
-
const ownMetadataKeys = Reflect.getMetadataKeys(definition);
|
|
17
|
-
if (![injectableKey, controllerKey, middlewareKey, guardKey, dispatcherKey, webSocketKey].some((value) => ownMetadataKeys.includes(value))) {
|
|
18
|
-
throw Error("Missing dependency declaration, please check @Injectable() used on dependency(ies).");
|
|
19
|
-
}
|
|
20
|
-
// Initialize dependencies injection
|
|
21
|
-
const dependencies = Reflect.getOwnMetadata(injectKey, definition) || [];
|
|
22
|
-
const injections = dependencies.map((dependency) => this.get(dependency));
|
|
23
|
-
const instance = new definition(...injections);
|
|
24
|
-
this._mapper.set(definition, instance);
|
|
25
|
-
return instance;
|
|
26
|
-
}
|
|
27
|
-
/**
|
|
28
|
-
*
|
|
29
|
-
* @param key
|
|
30
|
-
* @param value
|
|
31
|
-
*/
|
|
32
|
-
set(key, value) {
|
|
33
|
-
this._mapper.set(key, value);
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
export default Injector;
|
package/dist/http/clientError.js
DELETED
|
@@ -1,42 +0,0 @@
|
|
|
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
|
-
export class HttpClientError extends Error {
|
|
33
|
-
httpCode;
|
|
34
|
-
message;
|
|
35
|
-
data;
|
|
36
|
-
constructor({ httpCode, data, message }) {
|
|
37
|
-
super();
|
|
38
|
-
this.httpCode = httpCode;
|
|
39
|
-
this.message = !message?.trim() ? httpClientErrors[httpCode] : message.trim();
|
|
40
|
-
this.data = data;
|
|
41
|
-
}
|
|
42
|
-
}
|
package/dist/http/index.js
DELETED
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
import { HttpClientError } from "./clientError";
|
|
2
|
-
import { HttpServerError } from "./serverError";
|
|
3
|
-
export const jsonErrorInfer = (data, headers = new Headers()) => {
|
|
4
|
-
headers.set("Content-Type", "application/json");
|
|
5
|
-
if (data instanceof HttpClientError || data instanceof HttpServerError) {
|
|
6
|
-
return new Response(JSON.stringify(data), {
|
|
7
|
-
status: data.httpCode,
|
|
8
|
-
statusText: data.message,
|
|
9
|
-
headers: headers
|
|
10
|
-
});
|
|
11
|
-
}
|
|
12
|
-
return new Response(JSON.stringify((() => {
|
|
13
|
-
switch (typeof data) {
|
|
14
|
-
case "object":
|
|
15
|
-
return !(data instanceof Error)
|
|
16
|
-
? data
|
|
17
|
-
: {
|
|
18
|
-
message: data.message,
|
|
19
|
-
code: data.name,
|
|
20
|
-
cause: data.cause
|
|
21
|
-
};
|
|
22
|
-
case "string":
|
|
23
|
-
return {
|
|
24
|
-
message: data
|
|
25
|
-
};
|
|
26
|
-
case "number":
|
|
27
|
-
return {
|
|
28
|
-
code: data
|
|
29
|
-
};
|
|
30
|
-
default:
|
|
31
|
-
return undefined;
|
|
32
|
-
}
|
|
33
|
-
})()), {
|
|
34
|
-
status: 500,
|
|
35
|
-
statusText: "INTERNAL SERVER ERROR",
|
|
36
|
-
headers: headers
|
|
37
|
-
});
|
|
38
|
-
};
|
|
39
|
-
export * from "./clientError";
|
|
40
|
-
export * from "./serverError";
|
package/dist/http/serverError.js
DELETED
|
@@ -1,24 +0,0 @@
|
|
|
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
|
-
export class HttpServerError extends Error {
|
|
15
|
-
httpCode;
|
|
16
|
-
message;
|
|
17
|
-
data;
|
|
18
|
-
constructor({ httpCode, data, message }) {
|
|
19
|
-
super();
|
|
20
|
-
this.httpCode = httpCode;
|
|
21
|
-
this.message = !message?.trim() ? httpServerErrors[httpCode] : message.trim();
|
|
22
|
-
this.data = data;
|
|
23
|
-
}
|
|
24
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
package/dist/interfaces/guard.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
package/dist/interfaces/index.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
package/dist/keys/index.js
DELETED
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
export const argumentsKey = Symbol("__bool:arguments__");
|
|
2
|
-
export const webSocketEventArgumentsKey = Symbol("__bool:webSocketEventArguments__");
|
|
3
|
-
export const configKey = Symbol("__bool:config__");
|
|
4
|
-
export const controllerKey = Symbol("__bool:controller__");
|
|
5
|
-
export const dispatcherKey = Symbol("__bool:dispatcher__");
|
|
6
|
-
export const guardKey = Symbol("__bool:guard__");
|
|
7
|
-
export const controllerHttpKey = Symbol("__bool:controller.http__");
|
|
8
|
-
export const injectKey = Symbol("__bool:inject__");
|
|
9
|
-
export const injectableKey = Symbol("__bool:injectable__");
|
|
10
|
-
export const middlewareKey = Symbol("__bool:middleware__");
|
|
11
|
-
export const moduleKey = Symbol("__bool:module__");
|
|
12
|
-
export const zodSchemaKey = Symbol("__bool:zodSchema__");
|
|
13
|
-
export const webSocketKey = Symbol("__bool:webSocket__");
|
|
14
|
-
export const webSocketEventKey = Symbol("__bool:webSocket:event__");
|
|
15
|
-
export const webSocketServerArgsKey = Symbol("__bool:webSocketArguments:server__");
|
|
16
|
-
export const webSocketConnectionArgsKey = Symbol("__bool:webSocketArguments:connection__");
|
|
17
|
-
export const webSocketMessageArgsKey = Symbol("__bool:webSocketArguments:message__");
|
|
18
|
-
export const webSocketCloseCodeArgsKey = Symbol("__bool:webSocketArguments:closeCode__");
|
|
19
|
-
export const webSocketCloseReasonArgsKey = Symbol("__bool:webSocketArguments:closeReason__");
|
|
20
|
-
export const httpServerArgsKey = Symbol("__bool:httpArguments:server__");
|
|
21
|
-
export const requestHeadersArgsKey = Symbol("__bool:httpArguments:requestHeaders__");
|
|
22
|
-
export const requestHeaderArgsKey = Symbol("__bool:httpArguments:requestHeader__");
|
|
23
|
-
export const requestBodyArgsKey = Symbol("__bool:httpArguments:requestBody__");
|
|
24
|
-
export const paramsArgsKey = Symbol("__bool:httpArguments:params__");
|
|
25
|
-
export const paramArgsKey = Symbol("__bool:httpArguments:param__");
|
|
26
|
-
export const queryArgsKey = Symbol("__bool:httpArguments:query__");
|
|
27
|
-
export const requestArgsKey = Symbol("__bool:httpArguments:request__");
|
|
28
|
-
export const responseHeadersArgsKey = Symbol("__bool:httpArguments:responseHeaders__");
|
|
29
|
-
export const contextArgsKey = Symbol("__bool:httpArguments:context__");
|
|
30
|
-
export const routeModelArgsKey = Symbol("__bool:httpArguments:routeModel__");
|
|
31
|
-
export const responseBodyArgsKey = Symbol("__bool:httpArguments:responseBody__");
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export const AsyncFunction = async function () { }.constructor;
|
package/dist/ultils/colors.js
DELETED
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
const ansiColors = Object.freeze({
|
|
2
|
-
black: 30,
|
|
3
|
-
red: 31,
|
|
4
|
-
green: 32,
|
|
5
|
-
yellow: 33,
|
|
6
|
-
blue: 34,
|
|
7
|
-
magenta: 35,
|
|
8
|
-
cyan: 36,
|
|
9
|
-
white: 37,
|
|
10
|
-
gray: 90
|
|
11
|
-
});
|
|
12
|
-
const backgroundColors = Object.freeze({
|
|
13
|
-
black: 40,
|
|
14
|
-
red: 41,
|
|
15
|
-
green: 42,
|
|
16
|
-
yellow: 43,
|
|
17
|
-
blue: 44,
|
|
18
|
-
magenta: 45,
|
|
19
|
-
cyan: 46,
|
|
20
|
-
white: 47,
|
|
21
|
-
gray: 100
|
|
22
|
-
});
|
|
23
|
-
export const ansiText = (text, options = {}) => {
|
|
24
|
-
const { color, backgroundColor, bold, underline } = options;
|
|
25
|
-
let ansiCode = "";
|
|
26
|
-
if (bold) {
|
|
27
|
-
ansiCode += "\x1b[1m"; // Mã ANSI cho in đậm
|
|
28
|
-
}
|
|
29
|
-
if (underline) {
|
|
30
|
-
ansiCode += "\x1b[4m"; // Mã ANSI cho gạch chân
|
|
31
|
-
}
|
|
32
|
-
if (color && ansiColors[color]) {
|
|
33
|
-
ansiCode += `\x1b[${ansiColors[color]}m`;
|
|
34
|
-
}
|
|
35
|
-
// Màu nền
|
|
36
|
-
if (backgroundColor && backgroundColors[backgroundColor]) {
|
|
37
|
-
ansiCode += `\x1b[${backgroundColors[backgroundColor]}m`;
|
|
38
|
-
}
|
|
39
|
-
// Kết quả với reset
|
|
40
|
-
return `${ansiCode}${text}\x1b[0m`;
|
|
41
|
-
};
|
package/dist/ultils/index.js
DELETED
package/dist/ultils/socket.js
DELETED
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
export const isWebSocketUpgrade = (request) => {
|
|
2
|
-
const headers = request.headers;
|
|
3
|
-
const method = request.method;
|
|
4
|
-
const upgrade = headers.get("upgrade")?.toLowerCase() || "";
|
|
5
|
-
const connection = headers.get("connection")?.toLowerCase() || "";
|
|
6
|
-
return method === "GET" && upgrade?.toLowerCase() === "websocket" && connection?.toLowerCase().includes("upgrade");
|
|
7
|
-
};
|