@nestia/core 7.0.0-dev.20250607 → 7.0.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/LICENSE +21 -21
- package/README.md +92 -92
- package/package.json +3 -3
- package/src/adaptors/WebSocketAdaptor.ts +429 -429
- package/src/decorators/DynamicModule.ts +43 -43
- package/src/decorators/EncryptedBody.ts +101 -101
- package/src/decorators/EncryptedController.ts +38 -38
- package/src/decorators/EncryptedModule.ts +100 -100
- package/src/decorators/EncryptedRoute.ts +219 -219
- package/src/decorators/HumanRoute.ts +22 -22
- package/src/decorators/NoTransformConfigurationError.ts +32 -32
- package/src/decorators/PlainBody.ts +79 -79
- package/src/decorators/SwaggerCustomizer.ts +115 -115
- package/src/decorators/SwaggerExample.ts +100 -100
- package/src/decorators/TypedBody.ts +59 -59
- package/src/decorators/TypedException.ts +166 -166
- package/src/decorators/TypedFormData.ts +195 -195
- package/src/decorators/TypedHeaders.ts +64 -64
- package/src/decorators/TypedParam.ts +77 -77
- package/src/decorators/TypedQuery.ts +245 -245
- package/src/decorators/TypedRoute.ts +214 -214
- package/src/decorators/WebSocketRoute.ts +242 -242
- package/src/decorators/internal/EncryptedConstant.ts +4 -4
- package/src/decorators/internal/IWebSocketRouteReflect.ts +23 -23
- package/src/decorators/internal/NoTransformConfigureError.ts +2 -2
- package/src/decorators/internal/get_path_and_querify.ts +108 -108
- package/src/decorators/internal/get_path_and_stringify.ts +122 -122
- package/src/decorators/internal/get_text_body.ts +20 -20
- package/src/decorators/internal/headers_to_object.ts +13 -13
- package/src/decorators/internal/is_request_body_undefined.ts +14 -14
- package/src/decorators/internal/load_controller.ts +49 -49
- package/src/decorators/internal/route_error.ts +45 -45
- package/src/decorators/internal/validate_request_body.ts +74 -74
- package/src/decorators/internal/validate_request_form_data.ts +77 -77
- package/src/decorators/internal/validate_request_headers.ts +86 -86
- package/src/decorators/internal/validate_request_query.ts +74 -74
- package/src/index.ts +5 -5
- package/src/module.ts +22 -22
- package/src/options/INestiaTransformOptions.ts +38 -38
- package/src/options/INestiaTransformProject.ts +8 -8
- package/src/options/IRequestBodyValidator.ts +20 -20
- package/src/options/IRequestFormDataProps.ts +27 -27
- package/src/options/IRequestHeadersValidator.ts +22 -22
- package/src/options/IRequestQueryValidator.ts +20 -20
- package/src/options/IResponseBodyQuerifier.ts +25 -25
- package/src/options/IResponseBodyStringifier.ts +30 -30
- package/src/programmers/PlainBodyProgrammer.ts +70 -70
- package/src/programmers/TypedBodyProgrammer.ts +142 -142
- package/src/programmers/TypedFormDataBodyProgrammer.ts +118 -118
- package/src/programmers/TypedHeadersProgrammer.ts +63 -63
- package/src/programmers/TypedParamProgrammer.ts +33 -33
- package/src/programmers/TypedQueryBodyProgrammer.ts +112 -112
- package/src/programmers/TypedQueryProgrammer.ts +114 -114
- package/src/programmers/TypedQueryRouteProgrammer.ts +105 -105
- package/src/programmers/TypedRouteProgrammer.ts +94 -94
- package/src/programmers/http/HttpAssertQuerifyProgrammer.ts +72 -72
- package/src/programmers/http/HttpIsQuerifyProgrammer.ts +75 -75
- package/src/programmers/http/HttpQuerifyProgrammer.ts +108 -108
- package/src/programmers/http/HttpValidateQuerifyProgrammer.ts +76 -76
- package/src/programmers/internal/CoreMetadataUtil.ts +21 -21
- package/src/transform.ts +35 -35
- package/src/transformers/FileTransformer.ts +110 -110
- package/src/transformers/MethodTransformer.ts +103 -103
- package/src/transformers/NodeTransformer.ts +23 -23
- package/src/transformers/ParameterDecoratorTransformer.ts +143 -143
- package/src/transformers/ParameterTransformer.ts +57 -57
- package/src/transformers/TypedRouteTransformer.ts +85 -85
- package/src/transformers/WebSocketRouteTransformer.ts +120 -120
- package/src/typings/Creator.ts +3 -3
- package/src/typings/get-function-location.d.ts +7 -7
- package/src/utils/ArrayUtil.ts +7 -7
- package/src/utils/ExceptionManager.ts +112 -112
- package/src/utils/Singleton.ts +20 -20
- package/src/utils/SourceFinder.ts +57 -57
- package/src/utils/VersioningStrategy.ts +27 -27
|
@@ -1,242 +1,242 @@
|
|
|
1
|
-
import { IRequestBodyValidator } from "../options/IRequestBodyValidator";
|
|
2
|
-
import { IRequestQueryValidator } from "../options/IRequestQueryValidator";
|
|
3
|
-
import { NoTransformConfigurationError } from "./NoTransformConfigurationError";
|
|
4
|
-
import { IWebSocketRouteReflect } from "./internal/IWebSocketRouteReflect";
|
|
5
|
-
import { validate_request_body } from "./internal/validate_request_body";
|
|
6
|
-
import { validate_request_query } from "./internal/validate_request_query";
|
|
7
|
-
|
|
8
|
-
/**
|
|
9
|
-
* WebSocket route decorator.
|
|
10
|
-
*
|
|
11
|
-
* `@WebSocketRoute()` is a route decorator function for WebSocket routes.
|
|
12
|
-
* If you want to define a WebSocket route with this `@WebSocketRoute` decorator,
|
|
13
|
-
* please don't forget to call the {@link WebSocketAdaptor.upgrade} function
|
|
14
|
-
* to the {@link INestApplication} instance.
|
|
15
|
-
*
|
|
16
|
-
* Also, `WebSocketRoute` is a module containing parameter decorator
|
|
17
|
-
* functions of below for the `@WebSocketRoute` decorated method, at the same
|
|
18
|
-
* time. Note that, every parameters must be decorated by one of the parameter
|
|
19
|
-
* decorators in the `WebSocketRoute` module. One thing more important is,
|
|
20
|
-
* {@link WebSocketRoute.Acceptor} decorated parameter must be defined in the
|
|
21
|
-
* method. If not, it would be both compilation/runtime error.
|
|
22
|
-
*
|
|
23
|
-
* - {@link WebSocketRoute.Acceptor}
|
|
24
|
-
* - {@link WebSocketRoute.Driver}
|
|
25
|
-
* - {@link WebSocketRoute.Header}
|
|
26
|
-
* - {@link WebSocketRoute.Param}
|
|
27
|
-
* - {@link WebSocketRoute.Query}
|
|
28
|
-
*
|
|
29
|
-
* For reference, key difference between `@WebSocketGateway()` of NestJS and
|
|
30
|
-
* `@WebSocketRoute()` of Nestia is, `@WebSocketRoute()` can make multiple
|
|
31
|
-
* WebSocket routes by configuring *paths*, besides `@WebSocketGateway()`
|
|
32
|
-
* can't do it.
|
|
33
|
-
*
|
|
34
|
-
* Furthermore, if you build SDK (Software Development Kit) library through
|
|
35
|
-
* `@nestia/sdk`, you can make safe WebSocket client taking advantages of
|
|
36
|
-
* TypeScript type hints and checks.
|
|
37
|
-
*
|
|
38
|
-
* @param path Path(s) of the WebSocket request
|
|
39
|
-
* @returns Method decorator
|
|
40
|
-
* @author Jeongho Nam - https://github.com/samchon
|
|
41
|
-
*/
|
|
42
|
-
export function WebSocketRoute(
|
|
43
|
-
path?: undefined | string | string[],
|
|
44
|
-
): MethodDecorator {
|
|
45
|
-
return function WebSocketRoute(
|
|
46
|
-
_target: Object,
|
|
47
|
-
_propertyKey: string | symbol,
|
|
48
|
-
descriptor: TypedPropertyDescriptor<any>,
|
|
49
|
-
): TypedPropertyDescriptor<any> {
|
|
50
|
-
Reflect.defineMetadata(
|
|
51
|
-
"nestia/WebSocketRoute",
|
|
52
|
-
{
|
|
53
|
-
paths: path === undefined ? [] : Array.isArray(path) ? path : [path],
|
|
54
|
-
} satisfies IWebSocketRouteReflect,
|
|
55
|
-
descriptor.value,
|
|
56
|
-
);
|
|
57
|
-
return descriptor;
|
|
58
|
-
};
|
|
59
|
-
}
|
|
60
|
-
export namespace WebSocketRoute {
|
|
61
|
-
/**
|
|
62
|
-
* Acceptor parameter decorator.
|
|
63
|
-
*
|
|
64
|
-
* `@WebSocketRoute.Acceptor()` is a parameter decorator function for the
|
|
65
|
-
* `WebSocketAcceptor<Header, Provider, Listener>` (of `tgrid`) typed parameter.
|
|
66
|
-
*
|
|
67
|
-
* In the controller method decorated by `@WebSocketRoute()` and
|
|
68
|
-
* `@WebSocketRoute.Acceptor()`, call {@link WebSocketAcceptor.accept} function
|
|
69
|
-
* with `Provider` instance when you want to accept the WebSocket client
|
|
70
|
-
* connection. Otherwise you want to reject the connection, call
|
|
71
|
-
* {@link WebSocketAcceptor.rejcet} function instead.
|
|
72
|
-
*
|
|
73
|
-
* For reference, this `@WebSocketRoute.Acceptor()` parameter decorator is
|
|
74
|
-
* essential for the method decorated by `@WebSocketRoute()` decorator.
|
|
75
|
-
* If you forget it, it would be both compilation/runtime error.
|
|
76
|
-
*/
|
|
77
|
-
export function Acceptor(): ParameterDecorator {
|
|
78
|
-
return function WebSocketAcceptor(
|
|
79
|
-
target: Object,
|
|
80
|
-
propertyKey: string | symbol | undefined,
|
|
81
|
-
parameterIndex: number,
|
|
82
|
-
) {
|
|
83
|
-
emplace(target, propertyKey ?? "", {
|
|
84
|
-
category: "acceptor",
|
|
85
|
-
index: parameterIndex,
|
|
86
|
-
});
|
|
87
|
-
};
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
/**
|
|
91
|
-
* Driver parameter decorator.
|
|
92
|
-
*
|
|
93
|
-
* `@WebSocketRoute.Driver()` is a parameter decorator function for the
|
|
94
|
-
* `Driver<Listener>` (of `tgrid`) typed parameter.
|
|
95
|
-
*
|
|
96
|
-
* With the `@WebSocketRoute.Driver()` decorated parameter, you can call
|
|
97
|
-
* function of `Listener` typed instance provided by remote WebSocket client
|
|
98
|
-
* by calling the `Driver<Listener>` instance.
|
|
99
|
-
*
|
|
100
|
-
* For reference, this `@WebSocketRoute.Driver()` decorator is optional, and
|
|
101
|
-
* can be substituted by `@WebSocketRoute.Acceptor()` decorated parameter
|
|
102
|
-
* by calling the {@link WebSocketAcceptor.getDriver} function.
|
|
103
|
-
*/
|
|
104
|
-
export function Driver(): ParameterDecorator {
|
|
105
|
-
return function WebSocketDriver(
|
|
106
|
-
target: Object,
|
|
107
|
-
propertyKey: string | symbol | undefined,
|
|
108
|
-
parameterIndex: number,
|
|
109
|
-
) {
|
|
110
|
-
emplace(target, propertyKey ?? "", {
|
|
111
|
-
category: "driver",
|
|
112
|
-
index: parameterIndex,
|
|
113
|
-
});
|
|
114
|
-
};
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
/**
|
|
118
|
-
* Header decorator.
|
|
119
|
-
*
|
|
120
|
-
* `@WebSocketRoute.Header()` is a parameter decorator function for the
|
|
121
|
-
* WebSocket header with type casting and assertion.
|
|
122
|
-
*
|
|
123
|
-
* For reference, `@WebSocketRoute.Header()` is different with HTTP headers.
|
|
124
|
-
* It's for WebSocket protocol, especially for TGrid's {@link WebSocketConnector}
|
|
125
|
-
* and {@link WebSocketAcceptor}'s special header.
|
|
126
|
-
*
|
|
127
|
-
* Also, this `@WebSocketRoute.Header()` decorator is optional, and
|
|
128
|
-
* can be substituted by `@WebSocketRoute.Acceptor()` decorated parameter
|
|
129
|
-
* by accessting to the {@link WebSocketAcceptor.header} property.
|
|
130
|
-
*/
|
|
131
|
-
export function Header<T>(
|
|
132
|
-
validator?: IRequestBodyValidator<T>,
|
|
133
|
-
): ParameterDecorator {
|
|
134
|
-
const validate = validate_request_body("WebSocketRoute.Header")(validator);
|
|
135
|
-
return function WebSocketHeader(
|
|
136
|
-
target: Object,
|
|
137
|
-
propertyKey: string | symbol | undefined,
|
|
138
|
-
parameterIndex: number,
|
|
139
|
-
) {
|
|
140
|
-
emplace(target, propertyKey ?? "", {
|
|
141
|
-
category: "header",
|
|
142
|
-
index: parameterIndex,
|
|
143
|
-
validate,
|
|
144
|
-
});
|
|
145
|
-
};
|
|
146
|
-
}
|
|
147
|
-
|
|
148
|
-
/**
|
|
149
|
-
* URL parameter decorator.
|
|
150
|
-
*
|
|
151
|
-
* `@WebSocketRoute.Param()` is a parameter decorator function for the URL
|
|
152
|
-
* parameter with type casting and assertion.
|
|
153
|
-
*
|
|
154
|
-
* It's almost same with the {@link TypedParam}, but
|
|
155
|
-
* `@WebSocketRoute.Param()` is only for WebSocket protocol router function
|
|
156
|
-
* decorated by {@link WebSocketRoute}.
|
|
157
|
-
*
|
|
158
|
-
* @param field URL parameter field name
|
|
159
|
-
*/
|
|
160
|
-
export function Param<T extends boolean | bigint | number | string | null>(
|
|
161
|
-
field: string,
|
|
162
|
-
assert?: (value: string) => T,
|
|
163
|
-
): ParameterDecorator {
|
|
164
|
-
if (assert === undefined) {
|
|
165
|
-
NoTransformConfigurationError("WebSocketRoute.Param");
|
|
166
|
-
assert = (value) => value as T;
|
|
167
|
-
}
|
|
168
|
-
return function WebSocketParam(
|
|
169
|
-
target: Object,
|
|
170
|
-
propertyKey: string | symbol | undefined,
|
|
171
|
-
parameterIndex: number,
|
|
172
|
-
) {
|
|
173
|
-
emplace(target, propertyKey ?? "", {
|
|
174
|
-
category: "param",
|
|
175
|
-
index: parameterIndex,
|
|
176
|
-
field,
|
|
177
|
-
assert,
|
|
178
|
-
});
|
|
179
|
-
};
|
|
180
|
-
}
|
|
181
|
-
|
|
182
|
-
/**
|
|
183
|
-
* URL query decorator.
|
|
184
|
-
*
|
|
185
|
-
* `@WebSocketRoute.Query()` is a parameter decorator function for the URL
|
|
186
|
-
* query string with type casting and assertion.
|
|
187
|
-
*
|
|
188
|
-
* It is almost same with {@link TypedQuery}, but
|
|
189
|
-
* `@WebSocketRoute.Query()` is only for WebSocket protocol router function
|
|
190
|
-
* decorated by {@link WebSocketRoute}.
|
|
191
|
-
*
|
|
192
|
-
* For reference, as same with {@link TypedQuery}, `@WebSocketRoute.Query()`
|
|
193
|
-
* has same restriction for the target type `T`. If actual URL query
|
|
194
|
-
* parameter values are different with their promised type `T`,
|
|
195
|
-
* it would be runtime error.
|
|
196
|
-
*
|
|
197
|
-
* 1. Type `T` must be an object type
|
|
198
|
-
* 2. Do not allow dynamic property
|
|
199
|
-
* 3. Only `boolean`, `bigint`, `number`, `string` or their array types are allowed
|
|
200
|
-
* 4. By the way, union type never be not allowed
|
|
201
|
-
*/
|
|
202
|
-
export function Query<T extends object>(
|
|
203
|
-
validator?: IRequestQueryValidator<T>,
|
|
204
|
-
): ParameterDecorator {
|
|
205
|
-
const validate = validate_request_query("WebSocketRoute.Query")(validator);
|
|
206
|
-
return function WebSocketQuery(
|
|
207
|
-
target: Object,
|
|
208
|
-
propertyKey: string | symbol | undefined,
|
|
209
|
-
parameterIndex: number,
|
|
210
|
-
) {
|
|
211
|
-
emplace(target, propertyKey ?? "", {
|
|
212
|
-
category: "query",
|
|
213
|
-
index: parameterIndex,
|
|
214
|
-
validate,
|
|
215
|
-
});
|
|
216
|
-
};
|
|
217
|
-
}
|
|
218
|
-
|
|
219
|
-
/**
|
|
220
|
-
* @internal
|
|
221
|
-
*/
|
|
222
|
-
const emplace = (
|
|
223
|
-
target: Object,
|
|
224
|
-
propertyKey: string | symbol,
|
|
225
|
-
value: IWebSocketRouteReflect.IArgument,
|
|
226
|
-
) => {
|
|
227
|
-
const array: IWebSocketRouteReflect.IArgument[] | undefined =
|
|
228
|
-
Reflect.getMetadata(
|
|
229
|
-
"nestia/WebSocketRoute/Parameters",
|
|
230
|
-
target,
|
|
231
|
-
propertyKey,
|
|
232
|
-
);
|
|
233
|
-
if (array !== undefined) array.push(value);
|
|
234
|
-
else
|
|
235
|
-
Reflect.defineMetadata(
|
|
236
|
-
"nestia/WebSocketRoute/Parameters",
|
|
237
|
-
[value],
|
|
238
|
-
target,
|
|
239
|
-
propertyKey,
|
|
240
|
-
);
|
|
241
|
-
};
|
|
242
|
-
}
|
|
1
|
+
import { IRequestBodyValidator } from "../options/IRequestBodyValidator";
|
|
2
|
+
import { IRequestQueryValidator } from "../options/IRequestQueryValidator";
|
|
3
|
+
import { NoTransformConfigurationError } from "./NoTransformConfigurationError";
|
|
4
|
+
import { IWebSocketRouteReflect } from "./internal/IWebSocketRouteReflect";
|
|
5
|
+
import { validate_request_body } from "./internal/validate_request_body";
|
|
6
|
+
import { validate_request_query } from "./internal/validate_request_query";
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* WebSocket route decorator.
|
|
10
|
+
*
|
|
11
|
+
* `@WebSocketRoute()` is a route decorator function for WebSocket routes.
|
|
12
|
+
* If you want to define a WebSocket route with this `@WebSocketRoute` decorator,
|
|
13
|
+
* please don't forget to call the {@link WebSocketAdaptor.upgrade} function
|
|
14
|
+
* to the {@link INestApplication} instance.
|
|
15
|
+
*
|
|
16
|
+
* Also, `WebSocketRoute` is a module containing parameter decorator
|
|
17
|
+
* functions of below for the `@WebSocketRoute` decorated method, at the same
|
|
18
|
+
* time. Note that, every parameters must be decorated by one of the parameter
|
|
19
|
+
* decorators in the `WebSocketRoute` module. One thing more important is,
|
|
20
|
+
* {@link WebSocketRoute.Acceptor} decorated parameter must be defined in the
|
|
21
|
+
* method. If not, it would be both compilation/runtime error.
|
|
22
|
+
*
|
|
23
|
+
* - {@link WebSocketRoute.Acceptor}
|
|
24
|
+
* - {@link WebSocketRoute.Driver}
|
|
25
|
+
* - {@link WebSocketRoute.Header}
|
|
26
|
+
* - {@link WebSocketRoute.Param}
|
|
27
|
+
* - {@link WebSocketRoute.Query}
|
|
28
|
+
*
|
|
29
|
+
* For reference, key difference between `@WebSocketGateway()` of NestJS and
|
|
30
|
+
* `@WebSocketRoute()` of Nestia is, `@WebSocketRoute()` can make multiple
|
|
31
|
+
* WebSocket routes by configuring *paths*, besides `@WebSocketGateway()`
|
|
32
|
+
* can't do it.
|
|
33
|
+
*
|
|
34
|
+
* Furthermore, if you build SDK (Software Development Kit) library through
|
|
35
|
+
* `@nestia/sdk`, you can make safe WebSocket client taking advantages of
|
|
36
|
+
* TypeScript type hints and checks.
|
|
37
|
+
*
|
|
38
|
+
* @param path Path(s) of the WebSocket request
|
|
39
|
+
* @returns Method decorator
|
|
40
|
+
* @author Jeongho Nam - https://github.com/samchon
|
|
41
|
+
*/
|
|
42
|
+
export function WebSocketRoute(
|
|
43
|
+
path?: undefined | string | string[],
|
|
44
|
+
): MethodDecorator {
|
|
45
|
+
return function WebSocketRoute(
|
|
46
|
+
_target: Object,
|
|
47
|
+
_propertyKey: string | symbol,
|
|
48
|
+
descriptor: TypedPropertyDescriptor<any>,
|
|
49
|
+
): TypedPropertyDescriptor<any> {
|
|
50
|
+
Reflect.defineMetadata(
|
|
51
|
+
"nestia/WebSocketRoute",
|
|
52
|
+
{
|
|
53
|
+
paths: path === undefined ? [] : Array.isArray(path) ? path : [path],
|
|
54
|
+
} satisfies IWebSocketRouteReflect,
|
|
55
|
+
descriptor.value,
|
|
56
|
+
);
|
|
57
|
+
return descriptor;
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
export namespace WebSocketRoute {
|
|
61
|
+
/**
|
|
62
|
+
* Acceptor parameter decorator.
|
|
63
|
+
*
|
|
64
|
+
* `@WebSocketRoute.Acceptor()` is a parameter decorator function for the
|
|
65
|
+
* `WebSocketAcceptor<Header, Provider, Listener>` (of `tgrid`) typed parameter.
|
|
66
|
+
*
|
|
67
|
+
* In the controller method decorated by `@WebSocketRoute()` and
|
|
68
|
+
* `@WebSocketRoute.Acceptor()`, call {@link WebSocketAcceptor.accept} function
|
|
69
|
+
* with `Provider` instance when you want to accept the WebSocket client
|
|
70
|
+
* connection. Otherwise you want to reject the connection, call
|
|
71
|
+
* {@link WebSocketAcceptor.rejcet} function instead.
|
|
72
|
+
*
|
|
73
|
+
* For reference, this `@WebSocketRoute.Acceptor()` parameter decorator is
|
|
74
|
+
* essential for the method decorated by `@WebSocketRoute()` decorator.
|
|
75
|
+
* If you forget it, it would be both compilation/runtime error.
|
|
76
|
+
*/
|
|
77
|
+
export function Acceptor(): ParameterDecorator {
|
|
78
|
+
return function WebSocketAcceptor(
|
|
79
|
+
target: Object,
|
|
80
|
+
propertyKey: string | symbol | undefined,
|
|
81
|
+
parameterIndex: number,
|
|
82
|
+
) {
|
|
83
|
+
emplace(target, propertyKey ?? "", {
|
|
84
|
+
category: "acceptor",
|
|
85
|
+
index: parameterIndex,
|
|
86
|
+
});
|
|
87
|
+
};
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
/**
|
|
91
|
+
* Driver parameter decorator.
|
|
92
|
+
*
|
|
93
|
+
* `@WebSocketRoute.Driver()` is a parameter decorator function for the
|
|
94
|
+
* `Driver<Listener>` (of `tgrid`) typed parameter.
|
|
95
|
+
*
|
|
96
|
+
* With the `@WebSocketRoute.Driver()` decorated parameter, you can call
|
|
97
|
+
* function of `Listener` typed instance provided by remote WebSocket client
|
|
98
|
+
* by calling the `Driver<Listener>` instance.
|
|
99
|
+
*
|
|
100
|
+
* For reference, this `@WebSocketRoute.Driver()` decorator is optional, and
|
|
101
|
+
* can be substituted by `@WebSocketRoute.Acceptor()` decorated parameter
|
|
102
|
+
* by calling the {@link WebSocketAcceptor.getDriver} function.
|
|
103
|
+
*/
|
|
104
|
+
export function Driver(): ParameterDecorator {
|
|
105
|
+
return function WebSocketDriver(
|
|
106
|
+
target: Object,
|
|
107
|
+
propertyKey: string | symbol | undefined,
|
|
108
|
+
parameterIndex: number,
|
|
109
|
+
) {
|
|
110
|
+
emplace(target, propertyKey ?? "", {
|
|
111
|
+
category: "driver",
|
|
112
|
+
index: parameterIndex,
|
|
113
|
+
});
|
|
114
|
+
};
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
/**
|
|
118
|
+
* Header decorator.
|
|
119
|
+
*
|
|
120
|
+
* `@WebSocketRoute.Header()` is a parameter decorator function for the
|
|
121
|
+
* WebSocket header with type casting and assertion.
|
|
122
|
+
*
|
|
123
|
+
* For reference, `@WebSocketRoute.Header()` is different with HTTP headers.
|
|
124
|
+
* It's for WebSocket protocol, especially for TGrid's {@link WebSocketConnector}
|
|
125
|
+
* and {@link WebSocketAcceptor}'s special header.
|
|
126
|
+
*
|
|
127
|
+
* Also, this `@WebSocketRoute.Header()` decorator is optional, and
|
|
128
|
+
* can be substituted by `@WebSocketRoute.Acceptor()` decorated parameter
|
|
129
|
+
* by accessting to the {@link WebSocketAcceptor.header} property.
|
|
130
|
+
*/
|
|
131
|
+
export function Header<T>(
|
|
132
|
+
validator?: IRequestBodyValidator<T>,
|
|
133
|
+
): ParameterDecorator {
|
|
134
|
+
const validate = validate_request_body("WebSocketRoute.Header")(validator);
|
|
135
|
+
return function WebSocketHeader(
|
|
136
|
+
target: Object,
|
|
137
|
+
propertyKey: string | symbol | undefined,
|
|
138
|
+
parameterIndex: number,
|
|
139
|
+
) {
|
|
140
|
+
emplace(target, propertyKey ?? "", {
|
|
141
|
+
category: "header",
|
|
142
|
+
index: parameterIndex,
|
|
143
|
+
validate,
|
|
144
|
+
});
|
|
145
|
+
};
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
/**
|
|
149
|
+
* URL parameter decorator.
|
|
150
|
+
*
|
|
151
|
+
* `@WebSocketRoute.Param()` is a parameter decorator function for the URL
|
|
152
|
+
* parameter with type casting and assertion.
|
|
153
|
+
*
|
|
154
|
+
* It's almost same with the {@link TypedParam}, but
|
|
155
|
+
* `@WebSocketRoute.Param()` is only for WebSocket protocol router function
|
|
156
|
+
* decorated by {@link WebSocketRoute}.
|
|
157
|
+
*
|
|
158
|
+
* @param field URL parameter field name
|
|
159
|
+
*/
|
|
160
|
+
export function Param<T extends boolean | bigint | number | string | null>(
|
|
161
|
+
field: string,
|
|
162
|
+
assert?: (value: string) => T,
|
|
163
|
+
): ParameterDecorator {
|
|
164
|
+
if (assert === undefined) {
|
|
165
|
+
NoTransformConfigurationError("WebSocketRoute.Param");
|
|
166
|
+
assert = (value) => value as T;
|
|
167
|
+
}
|
|
168
|
+
return function WebSocketParam(
|
|
169
|
+
target: Object,
|
|
170
|
+
propertyKey: string | symbol | undefined,
|
|
171
|
+
parameterIndex: number,
|
|
172
|
+
) {
|
|
173
|
+
emplace(target, propertyKey ?? "", {
|
|
174
|
+
category: "param",
|
|
175
|
+
index: parameterIndex,
|
|
176
|
+
field,
|
|
177
|
+
assert,
|
|
178
|
+
});
|
|
179
|
+
};
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
/**
|
|
183
|
+
* URL query decorator.
|
|
184
|
+
*
|
|
185
|
+
* `@WebSocketRoute.Query()` is a parameter decorator function for the URL
|
|
186
|
+
* query string with type casting and assertion.
|
|
187
|
+
*
|
|
188
|
+
* It is almost same with {@link TypedQuery}, but
|
|
189
|
+
* `@WebSocketRoute.Query()` is only for WebSocket protocol router function
|
|
190
|
+
* decorated by {@link WebSocketRoute}.
|
|
191
|
+
*
|
|
192
|
+
* For reference, as same with {@link TypedQuery}, `@WebSocketRoute.Query()`
|
|
193
|
+
* has same restriction for the target type `T`. If actual URL query
|
|
194
|
+
* parameter values are different with their promised type `T`,
|
|
195
|
+
* it would be runtime error.
|
|
196
|
+
*
|
|
197
|
+
* 1. Type `T` must be an object type
|
|
198
|
+
* 2. Do not allow dynamic property
|
|
199
|
+
* 3. Only `boolean`, `bigint`, `number`, `string` or their array types are allowed
|
|
200
|
+
* 4. By the way, union type never be not allowed
|
|
201
|
+
*/
|
|
202
|
+
export function Query<T extends object>(
|
|
203
|
+
validator?: IRequestQueryValidator<T>,
|
|
204
|
+
): ParameterDecorator {
|
|
205
|
+
const validate = validate_request_query("WebSocketRoute.Query")(validator);
|
|
206
|
+
return function WebSocketQuery(
|
|
207
|
+
target: Object,
|
|
208
|
+
propertyKey: string | symbol | undefined,
|
|
209
|
+
parameterIndex: number,
|
|
210
|
+
) {
|
|
211
|
+
emplace(target, propertyKey ?? "", {
|
|
212
|
+
category: "query",
|
|
213
|
+
index: parameterIndex,
|
|
214
|
+
validate,
|
|
215
|
+
});
|
|
216
|
+
};
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
/**
|
|
220
|
+
* @internal
|
|
221
|
+
*/
|
|
222
|
+
const emplace = (
|
|
223
|
+
target: Object,
|
|
224
|
+
propertyKey: string | symbol,
|
|
225
|
+
value: IWebSocketRouteReflect.IArgument,
|
|
226
|
+
) => {
|
|
227
|
+
const array: IWebSocketRouteReflect.IArgument[] | undefined =
|
|
228
|
+
Reflect.getMetadata(
|
|
229
|
+
"nestia/WebSocketRoute/Parameters",
|
|
230
|
+
target,
|
|
231
|
+
propertyKey,
|
|
232
|
+
);
|
|
233
|
+
if (array !== undefined) array.push(value);
|
|
234
|
+
else
|
|
235
|
+
Reflect.defineMetadata(
|
|
236
|
+
"nestia/WebSocketRoute/Parameters",
|
|
237
|
+
[value],
|
|
238
|
+
target,
|
|
239
|
+
propertyKey,
|
|
240
|
+
);
|
|
241
|
+
};
|
|
242
|
+
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @internal
|
|
3
|
-
*/
|
|
4
|
-
export const ENCRYPTION_METADATA_KEY = "nestia:core:encryption:password";
|
|
1
|
+
/**
|
|
2
|
+
* @internal
|
|
3
|
+
*/
|
|
4
|
+
export const ENCRYPTION_METADATA_KEY = "nestia:core:encryption:password";
|
|
@@ -1,23 +1,23 @@
|
|
|
1
|
-
export interface IWebSocketRouteReflect {
|
|
2
|
-
paths: string[];
|
|
3
|
-
}
|
|
4
|
-
export namespace IWebSocketRouteReflect {
|
|
5
|
-
export type IArgument = IAcceptor | IDriver | IHeader | IParam | IQuery;
|
|
6
|
-
export interface IAcceptor extends IBase<"acceptor"> {}
|
|
7
|
-
export interface IDriver extends IBase<"driver"> {}
|
|
8
|
-
export interface IHeader extends IBase<"header"> {
|
|
9
|
-
validate: (input?: any) => Error | null;
|
|
10
|
-
}
|
|
11
|
-
export interface IParam extends IBase<"param"> {
|
|
12
|
-
field: string;
|
|
13
|
-
assert: (value: string) => any;
|
|
14
|
-
}
|
|
15
|
-
export interface IQuery extends IBase<"query"> {
|
|
16
|
-
validate: (input: URLSearchParams) => any | Error;
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
interface IBase<Category extends string> {
|
|
20
|
-
category: Category;
|
|
21
|
-
index: number;
|
|
22
|
-
}
|
|
23
|
-
}
|
|
1
|
+
export interface IWebSocketRouteReflect {
|
|
2
|
+
paths: string[];
|
|
3
|
+
}
|
|
4
|
+
export namespace IWebSocketRouteReflect {
|
|
5
|
+
export type IArgument = IAcceptor | IDriver | IHeader | IParam | IQuery;
|
|
6
|
+
export interface IAcceptor extends IBase<"acceptor"> {}
|
|
7
|
+
export interface IDriver extends IBase<"driver"> {}
|
|
8
|
+
export interface IHeader extends IBase<"header"> {
|
|
9
|
+
validate: (input?: any) => Error | null;
|
|
10
|
+
}
|
|
11
|
+
export interface IParam extends IBase<"param"> {
|
|
12
|
+
field: string;
|
|
13
|
+
assert: (value: string) => any;
|
|
14
|
+
}
|
|
15
|
+
export interface IQuery extends IBase<"query"> {
|
|
16
|
+
validate: (input: URLSearchParams) => any | Error;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
interface IBase<Category extends string> {
|
|
20
|
+
category: Category;
|
|
21
|
+
index: number;
|
|
22
|
+
}
|
|
23
|
+
}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
// For very old legay versions
|
|
2
|
-
export { NoTransformConfigurationError as NoTransformConfigureError } from "../NoTransformConfigurationError";
|
|
1
|
+
// For very old legay versions
|
|
2
|
+
export { NoTransformConfigurationError as NoTransformConfigureError } from "../NoTransformConfigurationError";
|