@bool-ts/core 1.8.0 → 1.8.2
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/entities/webSocketRoute.d.ts +2 -0
- package/dist/entities/webSocketRouter.d.ts +1 -1
- package/dist/index.js +4995 -6
- package/package.json +2 -2
- package/src/entities/webSocketRoute.ts +13 -5
- package/src/entities/webSocketRouter.ts +2 -2
- 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 -15
- 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/package.json
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@bool-ts/core",
|
|
3
|
-
"version": "1.8.
|
|
3
|
+
"version": "1.8.2",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"scripts": {
|
|
7
7
|
"test": "bun --hot run __test/index.ts",
|
|
8
|
-
"build": "tsc"
|
|
8
|
+
"build": "tsc --emitDeclarationOnly && bun build ./src/index.ts --outdir ./dist"
|
|
9
9
|
},
|
|
10
10
|
"repository": {
|
|
11
11
|
"type": "git",
|
|
@@ -3,6 +3,7 @@ import type { TWebSocketEventHandlerMetadata } from "../decorators";
|
|
|
3
3
|
export class WebSocketRoute {
|
|
4
4
|
public readonly eventName: string;
|
|
5
5
|
public readonly metadata: TWebSocketEventHandlerMetadata;
|
|
6
|
+
private _context: Object | undefined = undefined;
|
|
6
7
|
|
|
7
8
|
constructor({
|
|
8
9
|
eventName,
|
|
@@ -16,12 +17,19 @@ export class WebSocketRoute {
|
|
|
16
17
|
}
|
|
17
18
|
|
|
18
19
|
public bind(instance: Object): ThisType<WebSocketRoute> {
|
|
19
|
-
|
|
20
|
-
return this;
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
this.metadata.descriptor.value = this.metadata.descriptor.value.bind(instance);
|
|
20
|
+
this._context = instance;
|
|
24
21
|
|
|
25
22
|
return this;
|
|
26
23
|
}
|
|
24
|
+
|
|
25
|
+
public execute(): Readonly<TWebSocketEventHandlerMetadata> {
|
|
26
|
+
return Object.freeze({
|
|
27
|
+
methodName: this.metadata.methodName,
|
|
28
|
+
descriptor:
|
|
29
|
+
!this._context || typeof this.metadata.descriptor.value !== "function"
|
|
30
|
+
? this.metadata.descriptor
|
|
31
|
+
: this.metadata.descriptor.value.bind(this._context),
|
|
32
|
+
arguments: this.metadata.arguments
|
|
33
|
+
});
|
|
34
|
+
}
|
|
27
35
|
}
|
|
@@ -29,7 +29,7 @@ export class WebSocketRouter {
|
|
|
29
29
|
* @param instance
|
|
30
30
|
* @returns
|
|
31
31
|
*/
|
|
32
|
-
public bind(instance: Object) {
|
|
32
|
+
public bind(instance: Object): ThisType<WebSocketRouter> {
|
|
33
33
|
for (const route of this.routes) {
|
|
34
34
|
route.bind(instance);
|
|
35
35
|
}
|
|
@@ -45,7 +45,7 @@ export class WebSocketRouter {
|
|
|
45
45
|
const map = new Map<string, TWebSocketEventHandlerMetadata>();
|
|
46
46
|
|
|
47
47
|
for (const route of this.routes) {
|
|
48
|
-
map.set(`${this.alias}:::${route.eventName}`, route.
|
|
48
|
+
map.set(`${this.alias}:::${route.eventName}`, route.execute());
|
|
49
49
|
}
|
|
50
50
|
|
|
51
51
|
return map;
|
|
@@ -1,123 +0,0 @@
|
|
|
1
|
-
import * as Zod from "zod";
|
|
2
|
-
import { argumentsKey, contextArgsKey, paramArgsKey, paramsArgsKey, queryArgsKey, requestArgsKey, requestBodyArgsKey, requestHeaderArgsKey, requestHeadersArgsKey, responseHeadersArgsKey, routeModelArgsKey } from "../keys";
|
|
3
|
-
export const RequestHeaders = (schema) => (target, methodName, parameterIndex) => {
|
|
4
|
-
if (!methodName) {
|
|
5
|
-
return;
|
|
6
|
-
}
|
|
7
|
-
const requestHeadersMetadata = Reflect.getOwnMetadata(argumentsKey, target.constructor, methodName) || {};
|
|
8
|
-
requestHeadersMetadata[`argumentIndexes.${parameterIndex}`] = {
|
|
9
|
-
index: parameterIndex,
|
|
10
|
-
type: requestHeadersArgsKey,
|
|
11
|
-
zodSchema: schema
|
|
12
|
-
};
|
|
13
|
-
Reflect.defineMetadata(argumentsKey, requestHeadersMetadata, target.constructor, methodName);
|
|
14
|
-
};
|
|
15
|
-
export const RequestHeader = (key, schema) => (target, methodName, parameterIndex) => {
|
|
16
|
-
if (!methodName) {
|
|
17
|
-
return;
|
|
18
|
-
}
|
|
19
|
-
const requestHeaderMetadata = Reflect.getOwnMetadata(argumentsKey, target.constructor, methodName) || {};
|
|
20
|
-
requestHeaderMetadata[`argumentIndexes.${parameterIndex}`] = {
|
|
21
|
-
index: parameterIndex,
|
|
22
|
-
type: requestHeaderArgsKey,
|
|
23
|
-
key: key,
|
|
24
|
-
zodSchema: schema
|
|
25
|
-
};
|
|
26
|
-
Reflect.defineMetadata(argumentsKey, requestHeaderMetadata, target.constructor, methodName);
|
|
27
|
-
};
|
|
28
|
-
export const RequestBody = (schema, parser) => (target, methodName, parameterIndex) => {
|
|
29
|
-
if (!methodName) {
|
|
30
|
-
return;
|
|
31
|
-
}
|
|
32
|
-
const bodyMetadata = Reflect.getOwnMetadata(argumentsKey, target.constructor, methodName) || {};
|
|
33
|
-
bodyMetadata[`argumentIndexes.${parameterIndex}`] = {
|
|
34
|
-
index: parameterIndex,
|
|
35
|
-
type: requestBodyArgsKey,
|
|
36
|
-
zodSchema: schema,
|
|
37
|
-
parser: parser
|
|
38
|
-
};
|
|
39
|
-
Reflect.defineMetadata(argumentsKey, bodyMetadata, target.constructor, methodName);
|
|
40
|
-
};
|
|
41
|
-
export const Params = (schema) => (target, methodName, parameterIndex) => {
|
|
42
|
-
if (!methodName) {
|
|
43
|
-
return;
|
|
44
|
-
}
|
|
45
|
-
const paramsMetadata = Reflect.getOwnMetadata(argumentsKey, target.constructor, methodName) || {};
|
|
46
|
-
paramsMetadata[`argumentIndexes.${parameterIndex}`] = {
|
|
47
|
-
index: parameterIndex,
|
|
48
|
-
type: paramsArgsKey,
|
|
49
|
-
zodSchema: schema
|
|
50
|
-
};
|
|
51
|
-
Reflect.defineMetadata(argumentsKey, paramsMetadata, target.constructor, methodName);
|
|
52
|
-
};
|
|
53
|
-
export const Param = (key, schema) => (target, methodName, parameterIndex) => {
|
|
54
|
-
if (!methodName) {
|
|
55
|
-
return;
|
|
56
|
-
}
|
|
57
|
-
const paramMetadata = Reflect.getOwnMetadata(argumentsKey, target.constructor, methodName) || {};
|
|
58
|
-
paramMetadata[`argumentIndexes.${parameterIndex}`] = {
|
|
59
|
-
index: parameterIndex,
|
|
60
|
-
type: paramArgsKey,
|
|
61
|
-
key: key,
|
|
62
|
-
zodSchema: schema
|
|
63
|
-
};
|
|
64
|
-
Reflect.defineMetadata(argumentsKey, paramMetadata, target.constructor, methodName);
|
|
65
|
-
};
|
|
66
|
-
export const Query = (schema) => (target, methodName, parameterIndex) => {
|
|
67
|
-
if (!methodName) {
|
|
68
|
-
return;
|
|
69
|
-
}
|
|
70
|
-
const queryMetadata = Reflect.getOwnMetadata(argumentsKey, target.constructor, methodName) || {};
|
|
71
|
-
queryMetadata[`argumentIndexes.${parameterIndex}`] = {
|
|
72
|
-
index: parameterIndex,
|
|
73
|
-
type: queryArgsKey,
|
|
74
|
-
zodSchema: schema
|
|
75
|
-
};
|
|
76
|
-
Reflect.defineMetadata(argumentsKey, queryMetadata, target.constructor, methodName);
|
|
77
|
-
};
|
|
78
|
-
export const Request = (schema) => (target, methodName, parameterIndex) => {
|
|
79
|
-
if (!methodName) {
|
|
80
|
-
return;
|
|
81
|
-
}
|
|
82
|
-
const requestMetadata = Reflect.getOwnMetadata(argumentsKey, target.constructor, methodName) || {};
|
|
83
|
-
requestMetadata[`argumentIndexes.${parameterIndex}`] = {
|
|
84
|
-
index: parameterIndex,
|
|
85
|
-
type: requestArgsKey,
|
|
86
|
-
zodSchema: schema
|
|
87
|
-
};
|
|
88
|
-
Reflect.defineMetadata(argumentsKey, requestMetadata, target.constructor, methodName);
|
|
89
|
-
};
|
|
90
|
-
export const ResponseHeaders = () => (target, methodName, parameterIndex) => {
|
|
91
|
-
if (!methodName) {
|
|
92
|
-
return;
|
|
93
|
-
}
|
|
94
|
-
const responseHeadersMetadata = Reflect.getOwnMetadata(argumentsKey, target.constructor, methodName) || {};
|
|
95
|
-
responseHeadersMetadata[`argumentIndexes.${parameterIndex}`] = {
|
|
96
|
-
index: parameterIndex,
|
|
97
|
-
type: responseHeadersArgsKey
|
|
98
|
-
};
|
|
99
|
-
Reflect.defineMetadata(argumentsKey, responseHeadersMetadata, target.constructor, methodName);
|
|
100
|
-
};
|
|
101
|
-
export const Context = (key) => (target, methodName, parameterIndex) => {
|
|
102
|
-
if (!methodName) {
|
|
103
|
-
return;
|
|
104
|
-
}
|
|
105
|
-
const responseHeadersMetadata = Reflect.getOwnMetadata(argumentsKey, target.constructor, methodName) || {};
|
|
106
|
-
responseHeadersMetadata[`argumentIndexes.${parameterIndex}`] = {
|
|
107
|
-
index: parameterIndex,
|
|
108
|
-
type: contextArgsKey,
|
|
109
|
-
key: key
|
|
110
|
-
};
|
|
111
|
-
Reflect.defineMetadata(argumentsKey, responseHeadersMetadata, target.constructor, methodName);
|
|
112
|
-
};
|
|
113
|
-
export const RouteModel = () => (target, methodName, parameterIndex) => {
|
|
114
|
-
if (!methodName) {
|
|
115
|
-
return;
|
|
116
|
-
}
|
|
117
|
-
const responseHeadersMetadata = Reflect.getOwnMetadata(argumentsKey, target.constructor, methodName) || {};
|
|
118
|
-
responseHeadersMetadata[`argumentIndexes.${parameterIndex}`] = {
|
|
119
|
-
index: parameterIndex,
|
|
120
|
-
type: routeModelArgsKey
|
|
121
|
-
};
|
|
122
|
-
Reflect.defineMetadata(argumentsKey, responseHeadersMetadata, target.constructor, methodName);
|
|
123
|
-
};
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import { controllerHttpKey, controllerKey } from "../keys";
|
|
2
|
-
export const Controller = (prefix) => (target) => {
|
|
3
|
-
const metadata = {
|
|
4
|
-
prefix: !prefix?.startsWith("/") ? `/${prefix || ""}` : prefix,
|
|
5
|
-
httpMetadata: [...(Reflect.getOwnMetadata(controllerHttpKey, target.constructor) || [])]
|
|
6
|
-
};
|
|
7
|
-
Reflect.defineMetadata(controllerKey, metadata, target);
|
|
8
|
-
};
|
|
9
|
-
export default Controller;
|
package/dist/decorators/guard.js
DELETED
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import { guardKey } from "../keys";
|
|
2
|
-
export const Guard = () => (target) => {
|
|
3
|
-
if (!("enforce" in target.prototype) || typeof target.prototype.enforce !== "function") {
|
|
4
|
-
return;
|
|
5
|
-
}
|
|
6
|
-
const metadata = undefined;
|
|
7
|
-
Reflect.defineMetadata(guardKey, metadata, target);
|
|
8
|
-
};
|
|
9
|
-
export default Guard;
|
package/dist/decorators/http.js
DELETED
|
@@ -1,60 +0,0 @@
|
|
|
1
|
-
import { controllerHttpKey } from "../keys";
|
|
2
|
-
const defaultDecorator = (path, method) => (target, methodName, descriptor) => {
|
|
3
|
-
if (!(descriptor?.value instanceof Function)) {
|
|
4
|
-
throw Error(`${method} decorator only use for class method.`);
|
|
5
|
-
}
|
|
6
|
-
const metadata = [
|
|
7
|
-
...(Reflect.getOwnMetadata(controllerHttpKey, target.constructor) || []),
|
|
8
|
-
{
|
|
9
|
-
path: !path.startsWith("/") ? `/${path}` : path,
|
|
10
|
-
httpMethod: method.toUpperCase(),
|
|
11
|
-
methodName: methodName,
|
|
12
|
-
descriptor: descriptor
|
|
13
|
-
}
|
|
14
|
-
];
|
|
15
|
-
// Define controller metadata
|
|
16
|
-
Reflect.defineMetadata(controllerHttpKey, metadata, target.constructor);
|
|
17
|
-
};
|
|
18
|
-
/**
|
|
19
|
-
*
|
|
20
|
-
* @param path
|
|
21
|
-
* @returns
|
|
22
|
-
*/
|
|
23
|
-
export const Get = (path = "/") => defaultDecorator(path, "Get");
|
|
24
|
-
/**
|
|
25
|
-
*
|
|
26
|
-
* @param path
|
|
27
|
-
* @returns
|
|
28
|
-
*/
|
|
29
|
-
export const Post = (path = "/") => defaultDecorator(path, "Post");
|
|
30
|
-
/**
|
|
31
|
-
*
|
|
32
|
-
* @param path
|
|
33
|
-
* @returns
|
|
34
|
-
*/
|
|
35
|
-
export const Put = (path = "/") => defaultDecorator(path, "Put");
|
|
36
|
-
/**
|
|
37
|
-
*
|
|
38
|
-
* @param path
|
|
39
|
-
* @returns
|
|
40
|
-
*/
|
|
41
|
-
export const Patch = (path = "/") => defaultDecorator(path, "Patch");
|
|
42
|
-
/**
|
|
43
|
-
*
|
|
44
|
-
* @param path
|
|
45
|
-
* @returns
|
|
46
|
-
*/
|
|
47
|
-
export const Delete = (path = "/") => defaultDecorator(path, "Delete");
|
|
48
|
-
/**
|
|
49
|
-
*
|
|
50
|
-
* @param path
|
|
51
|
-
* @returns
|
|
52
|
-
*/
|
|
53
|
-
export const Options = (path = "/") => defaultDecorator(path, "Options");
|
|
54
|
-
export default {
|
|
55
|
-
Get,
|
|
56
|
-
Post,
|
|
57
|
-
Put,
|
|
58
|
-
Patch,
|
|
59
|
-
Delete
|
|
60
|
-
};
|
package/dist/decorators/index.js
DELETED
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
export { Context, Param, Params, Query, Request, RequestBody, RequestHeader, RequestHeaders, ResponseHeaders, RouteModel } from "./arguments";
|
|
2
|
-
export { Controller } from "./controller";
|
|
3
|
-
export { Dispatcher } from "./dispatcher";
|
|
4
|
-
export { Guard } from "./guard";
|
|
5
|
-
export { Delete, Get, Options, Patch, Post, Put } from "./http";
|
|
6
|
-
export { Inject } from "./inject";
|
|
7
|
-
export { Injectable } from "./injectable";
|
|
8
|
-
export { Middleware } from "./middleware";
|
|
9
|
-
export { Module } from "./module";
|
|
10
|
-
export { WebSocket } from "./webSocket";
|
|
11
|
-
export { WebSocketCloseCode, WebSocketCloseReason, WebSocketConnection, WebSocketServer } from "./webSocketArguments";
|
|
12
|
-
export { WebSocketEvent } from "./webSocketEvent";
|
|
13
|
-
export { ZodSchema } from "./zodSchema";
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import { injectKey } from "../keys";
|
|
2
|
-
export const Inject = (definition) => {
|
|
3
|
-
return (target, methodName, parameterIndex) => {
|
|
4
|
-
const designParameterTypes = Reflect.getMetadata(injectKey, target) || [];
|
|
5
|
-
designParameterTypes[parameterIndex] = definition;
|
|
6
|
-
Reflect.defineMetadata(injectKey, designParameterTypes, target);
|
|
7
|
-
};
|
|
8
|
-
};
|
|
9
|
-
export default Inject;
|
|
@@ -1,48 +0,0 @@
|
|
|
1
|
-
import { controllerKey, dispatcherKey, guardKey, injectableKey, middlewareKey, moduleKey, webSocketKey } from "../keys";
|
|
2
|
-
export const Module = (args) => (target) => {
|
|
3
|
-
const { middlewares, guards, dispatchers, controllers, dependencies, webSockets } = args || {};
|
|
4
|
-
if (middlewares) {
|
|
5
|
-
for (let i = 0; i < middlewares.length; i++) {
|
|
6
|
-
if (!Reflect.getOwnMetadataKeys(middlewares[i]).includes(middlewareKey)) {
|
|
7
|
-
throw Error(`${middlewares[i].name} is not a middleware.`);
|
|
8
|
-
}
|
|
9
|
-
}
|
|
10
|
-
}
|
|
11
|
-
if (guards) {
|
|
12
|
-
for (let i = 0; i < guards.length; i++) {
|
|
13
|
-
if (!Reflect.getOwnMetadataKeys(guards[i]).includes(guardKey)) {
|
|
14
|
-
throw Error(`${guards[i].name} is not a guard.`);
|
|
15
|
-
}
|
|
16
|
-
}
|
|
17
|
-
}
|
|
18
|
-
if (dispatchers) {
|
|
19
|
-
for (let i = 0; i < dispatchers.length; i++) {
|
|
20
|
-
if (!Reflect.getOwnMetadataKeys(dispatchers[i]).includes(dispatcherKey)) {
|
|
21
|
-
throw Error(`${dispatchers[i].name} is not a dispatcher.`);
|
|
22
|
-
}
|
|
23
|
-
}
|
|
24
|
-
}
|
|
25
|
-
if (controllers) {
|
|
26
|
-
for (let i = 0; i < controllers.length; i++) {
|
|
27
|
-
if (!Reflect.getOwnMetadataKeys(controllers[i]).includes(controllerKey)) {
|
|
28
|
-
throw Error(`${controllers[i].name} is not a controller.`);
|
|
29
|
-
}
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
|
-
if (dependencies) {
|
|
33
|
-
for (let i = 0; i < dependencies.length; i++) {
|
|
34
|
-
if (!Reflect.getOwnMetadataKeys(dependencies[i]).includes(injectableKey)) {
|
|
35
|
-
throw Error(`${dependencies[i].name} is not an injectable.`);
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
if (webSockets) {
|
|
40
|
-
for (let i = 0; i < webSockets.length; i++) {
|
|
41
|
-
if (!Reflect.getOwnMetadataKeys(webSockets[i]).includes(webSocketKey)) {
|
|
42
|
-
throw Error(`${webSockets[i].name} is not a websocket gateway.`);
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
Reflect.defineMetadata(moduleKey, args, target);
|
|
47
|
-
};
|
|
48
|
-
export default Module;
|
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
import { webSocketEventKey, webSocketKey } from "../keys";
|
|
2
|
-
const upgradeHandlerSymbol = Symbol("__bool:webSocket.upgrade__");
|
|
3
|
-
const upgradeHandler = (server, request, query) => {
|
|
4
|
-
const url = new URL(request.url);
|
|
5
|
-
return server.upgrade(request, {
|
|
6
|
-
data: {
|
|
7
|
-
method: request.method.toUpperCase(),
|
|
8
|
-
pathname: url.pathname,
|
|
9
|
-
query: query
|
|
10
|
-
}
|
|
11
|
-
});
|
|
12
|
-
};
|
|
13
|
-
export const WebSocket = (args) => (target) => {
|
|
14
|
-
const { prefix } = args || {};
|
|
15
|
-
target.prototype[upgradeHandlerSymbol] = upgradeHandler;
|
|
16
|
-
const descriptor = Object.getOwnPropertyDescriptor(target.prototype, upgradeHandlerSymbol);
|
|
17
|
-
const httpMetadata = !descriptor
|
|
18
|
-
? []
|
|
19
|
-
: [
|
|
20
|
-
{
|
|
21
|
-
path: "/",
|
|
22
|
-
httpMethod: "GET",
|
|
23
|
-
methodName: upgradeHandlerSymbol,
|
|
24
|
-
descriptor: descriptor
|
|
25
|
-
},
|
|
26
|
-
{
|
|
27
|
-
path: "/",
|
|
28
|
-
httpMethod: "POST",
|
|
29
|
-
methodName: upgradeHandlerSymbol,
|
|
30
|
-
descriptor: descriptor
|
|
31
|
-
}
|
|
32
|
-
];
|
|
33
|
-
const metadata = {
|
|
34
|
-
prefix: !prefix?.startsWith("/") ? `/${prefix || ""}` : prefix,
|
|
35
|
-
events: Reflect.getOwnMetadata(webSocketEventKey, target) || {},
|
|
36
|
-
http: httpMetadata
|
|
37
|
-
};
|
|
38
|
-
Reflect.defineMetadata(webSocketKey, metadata, target);
|
|
39
|
-
};
|
|
40
|
-
export default WebSocket;
|
|
@@ -1,49 +0,0 @@
|
|
|
1
|
-
import { webSocketCloseCodeArgsKey, webSocketCloseReasonArgsKey, webSocketConnectionArgsKey, webSocketEventArgumentsKey, webSocketMessageArgsKey, webSocketServerArgsKey } from "../keys";
|
|
2
|
-
export const WebSocketConnection = () => (target, methodName, parameterIndex) => {
|
|
3
|
-
if (!methodName) {
|
|
4
|
-
return;
|
|
5
|
-
}
|
|
6
|
-
const webSocketEventArgumentsMetadata = Reflect.getOwnMetadata(webSocketEventArgumentsKey, target.constructor, methodName) ||
|
|
7
|
-
{};
|
|
8
|
-
webSocketEventArgumentsMetadata[`argumentIndexes.${parameterIndex}`] = {
|
|
9
|
-
index: parameterIndex,
|
|
10
|
-
type: webSocketConnectionArgsKey
|
|
11
|
-
};
|
|
12
|
-
Reflect.defineMetadata(webSocketEventArgumentsKey, webSocketEventArgumentsMetadata, target.constructor, methodName);
|
|
13
|
-
};
|
|
14
|
-
export const WebSocketServer = () => (target, methodName, parameterIndex) => {
|
|
15
|
-
if (!methodName) {
|
|
16
|
-
return;
|
|
17
|
-
}
|
|
18
|
-
const webSocketEventArgumentsMetadata = Reflect.getOwnMetadata(webSocketEventArgumentsKey, target.constructor, methodName) ||
|
|
19
|
-
{};
|
|
20
|
-
webSocketEventArgumentsMetadata[`argumentIndexes.${parameterIndex}`] = {
|
|
21
|
-
index: parameterIndex,
|
|
22
|
-
type: webSocketServerArgsKey
|
|
23
|
-
};
|
|
24
|
-
Reflect.defineMetadata(webSocketEventArgumentsKey, webSocketEventArgumentsMetadata, target.constructor, methodName);
|
|
25
|
-
};
|
|
26
|
-
export const WebSocketCloseCode = () => (target, methodName, parameterIndex) => {
|
|
27
|
-
if (!methodName) {
|
|
28
|
-
return;
|
|
29
|
-
}
|
|
30
|
-
const webSocketEventArgumentsMetadata = Reflect.getOwnMetadata(webSocketEventArgumentsKey, target.constructor, methodName) ||
|
|
31
|
-
{};
|
|
32
|
-
webSocketEventArgumentsMetadata[`argumentIndexes.${parameterIndex}`] = {
|
|
33
|
-
index: parameterIndex,
|
|
34
|
-
type: webSocketCloseCodeArgsKey
|
|
35
|
-
};
|
|
36
|
-
Reflect.defineMetadata(webSocketEventArgumentsKey, webSocketEventArgumentsMetadata, target.constructor, methodName);
|
|
37
|
-
};
|
|
38
|
-
export const WebSocketCloseReason = () => (target, methodName, parameterIndex) => {
|
|
39
|
-
if (!methodName) {
|
|
40
|
-
return;
|
|
41
|
-
}
|
|
42
|
-
const webSocketEventArgumentsMetadata = Reflect.getOwnMetadata(webSocketEventArgumentsKey, target.constructor, methodName) ||
|
|
43
|
-
{};
|
|
44
|
-
webSocketEventArgumentsMetadata[`argumentIndexes.${parameterIndex}`] = {
|
|
45
|
-
index: parameterIndex,
|
|
46
|
-
type: webSocketCloseReasonArgsKey
|
|
47
|
-
};
|
|
48
|
-
Reflect.defineMetadata(webSocketEventArgumentsKey, webSocketEventArgumentsMetadata, target.constructor, methodName);
|
|
49
|
-
};
|
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
import { webSocketEventArgumentsKey, webSocketEventKey } from "../keys";
|
|
2
|
-
/**
|
|
3
|
-
*
|
|
4
|
-
* @param path
|
|
5
|
-
* @returns
|
|
6
|
-
*/
|
|
7
|
-
export const WebSocketEvent = (eventName) => (target, methodName, descriptor) => {
|
|
8
|
-
if (!(descriptor.value instanceof Function)) {
|
|
9
|
-
throw Error("WebSocketEvent decorator only use for class's method.");
|
|
10
|
-
}
|
|
11
|
-
const webSocketEventArgumentsMetadata = Reflect.getOwnMetadata(webSocketEventArgumentsKey, target.constructor, methodName);
|
|
12
|
-
const webSocketEventMetadata = Object.freeze({
|
|
13
|
-
methodName: methodName,
|
|
14
|
-
descriptor: descriptor,
|
|
15
|
-
arguments: webSocketEventArgumentsMetadata
|
|
16
|
-
});
|
|
17
|
-
const webSocketMetadata = {
|
|
18
|
-
...(Reflect.getOwnMetadata(webSocketEventKey, target.constructor) || undefined),
|
|
19
|
-
[eventName]: webSocketEventMetadata
|
|
20
|
-
};
|
|
21
|
-
Reflect.defineMetadata(webSocketEventKey, webSocketEventMetadata, target.constructor, methodName);
|
|
22
|
-
Reflect.defineMetadata(webSocketEventKey, webSocketMetadata, target.constructor);
|
|
23
|
-
};
|
|
24
|
-
export default WebSocket;
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import * as Zod from "zod";
|
|
2
|
-
import { zodSchemaKey } from "../keys";
|
|
3
|
-
export const ZodSchema = (schema) => {
|
|
4
|
-
return (target, methodName, parameterIndex) => {
|
|
5
|
-
if (!methodName) {
|
|
6
|
-
return;
|
|
7
|
-
}
|
|
8
|
-
const zodSchemasMetadata = Reflect.getOwnMetadata(zodSchemaKey, target.constructor, methodName) || {};
|
|
9
|
-
zodSchemasMetadata[`paramterIndexes.${parameterIndex}`] = {
|
|
10
|
-
index: parameterIndex,
|
|
11
|
-
schema: schema
|
|
12
|
-
};
|
|
13
|
-
Reflect.defineMetadata(zodSchemaKey, zodSchemasMetadata, target.constructor, methodName);
|
|
14
|
-
};
|
|
15
|
-
};
|