@nestia/core 3.0.5 → 3.1.0-dev.20240429
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/lib/adaptors/WebSocketAdaptor.d.ts +21 -0
- package/lib/adaptors/WebSocketAdaptor.js +275 -0
- package/lib/adaptors/WebSocketAdaptor.js.map +1 -0
- package/lib/decorators/DynamicModule.js +12 -59
- package/lib/decorators/DynamicModule.js.map +1 -1
- package/lib/decorators/EncryptedBody.js +36 -73
- package/lib/decorators/EncryptedBody.js.map +1 -1
- package/lib/decorators/EncryptedController.js +2 -2
- package/lib/decorators/EncryptedController.js.map +1 -1
- package/lib/decorators/EncryptedModule.js +24 -107
- package/lib/decorators/EncryptedModule.js.map +1 -1
- package/lib/decorators/EncryptedRoute.js +43 -119
- package/lib/decorators/EncryptedRoute.js.map +1 -1
- package/lib/decorators/PlainBody.js +24 -61
- package/lib/decorators/PlainBody.js.map +1 -1
- package/lib/decorators/SwaggerCustomizer.js +2 -2
- package/lib/decorators/SwaggerCustomizer.js.map +1 -1
- package/lib/decorators/TypedBody.js +12 -14
- package/lib/decorators/TypedBody.js.map +1 -1
- package/lib/decorators/TypedException.js +5 -5
- package/lib/decorators/TypedException.js.map +1 -1
- package/lib/decorators/TypedFormData.js +88 -291
- package/lib/decorators/TypedFormData.js.map +1 -1
- package/lib/decorators/TypedHeaders.js +6 -6
- package/lib/decorators/TypedHeaders.js.map +1 -1
- package/lib/decorators/TypedParam.d.ts +5 -6
- package/lib/decorators/TypedParam.js +14 -15
- package/lib/decorators/TypedParam.js.map +1 -1
- package/lib/decorators/TypedQuery.d.ts +2 -2
- package/lib/decorators/TypedQuery.js +52 -129
- package/lib/decorators/TypedQuery.js.map +1 -1
- package/lib/decorators/TypedRoute.js +31 -107
- package/lib/decorators/TypedRoute.js.map +1 -1
- package/lib/decorators/WebSocketRoute.d.ts +120 -0
- package/lib/decorators/WebSocketRoute.js +202 -0
- package/lib/decorators/WebSocketRoute.js.map +1 -0
- package/lib/decorators/internal/IWebSocketRouteReflect.d.ts +25 -0
- package/lib/decorators/internal/IWebSocketRouteReflect.js +3 -0
- package/lib/decorators/internal/IWebSocketRouteReflect.js.map +1 -0
- package/lib/decorators/internal/NoTransformConfigureError.js +1 -1
- package/lib/decorators/internal/NoTransformConfigureError.js.map +1 -1
- package/lib/decorators/internal/get_path_and_querify.js +67 -131
- package/lib/decorators/internal/get_path_and_querify.js.map +1 -1
- package/lib/decorators/internal/get_path_and_stringify.js +57 -71
- package/lib/decorators/internal/get_path_and_stringify.js.map +1 -1
- package/lib/decorators/internal/get_text_body.js +7 -46
- package/lib/decorators/internal/get_text_body.js.map +1 -1
- package/lib/decorators/internal/headers_to_object.js +3 -42
- package/lib/decorators/internal/headers_to_object.js.map +1 -1
- package/lib/decorators/internal/load_controller.js +29 -106
- package/lib/decorators/internal/load_controller.js.map +1 -1
- package/lib/decorators/internal/route_error.js +15 -65
- package/lib/decorators/internal/route_error.js.map +1 -1
- package/lib/decorators/internal/validate_request_body.js +44 -54
- package/lib/decorators/internal/validate_request_body.js.map +1 -1
- package/lib/decorators/internal/validate_request_form_data.js +36 -44
- package/lib/decorators/internal/validate_request_form_data.js.map +1 -1
- package/lib/decorators/internal/validate_request_headers.js +36 -44
- package/lib/decorators/internal/validate_request_headers.js.map +1 -1
- package/lib/decorators/internal/validate_request_query.js +36 -44
- package/lib/decorators/internal/validate_request_query.js.map +1 -1
- package/lib/index.js +1 -1
- package/lib/index.js.map +1 -1
- package/lib/module.d.ts +10 -9
- package/lib/module.js +10 -9
- package/lib/module.js.map +1 -1
- package/lib/programmers/PlainBodyProgrammer.js +29 -44
- package/lib/programmers/PlainBodyProgrammer.js.map +1 -1
- package/lib/programmers/TypedBodyProgrammer.js +57 -82
- package/lib/programmers/TypedBodyProgrammer.js.map +1 -1
- package/lib/programmers/TypedExceptionProgrammer.js +51 -54
- package/lib/programmers/TypedExceptionProgrammer.js.map +1 -1
- package/lib/programmers/TypedFormDataBodyProgrammer.js +50 -73
- package/lib/programmers/TypedFormDataBodyProgrammer.js.map +1 -1
- package/lib/programmers/TypedHeadersProgrammer.js +24 -43
- package/lib/programmers/TypedHeadersProgrammer.js.map +1 -1
- package/lib/programmers/TypedParamProgrammer.js +11 -28
- package/lib/programmers/TypedParamProgrammer.js.map +1 -1
- package/lib/programmers/TypedQueryBodyProgrammer.js +24 -43
- package/lib/programmers/TypedQueryBodyProgrammer.js.map +1 -1
- package/lib/programmers/TypedQueryProgrammer.js +24 -43
- package/lib/programmers/TypedQueryProgrammer.js.map +1 -1
- package/lib/programmers/TypedQueryRouteProgrammer.js +22 -39
- package/lib/programmers/TypedQueryRouteProgrammer.js.map +1 -1
- package/lib/programmers/TypedRouteProgrammer.js +22 -39
- package/lib/programmers/TypedRouteProgrammer.js.map +1 -1
- package/lib/programmers/http/HttpAssertQuerifyProgrammer.js +12 -29
- package/lib/programmers/http/HttpAssertQuerifyProgrammer.js.map +1 -1
- package/lib/programmers/http/HttpIsQuerifyProgrammer.js +10 -27
- package/lib/programmers/http/HttpIsQuerifyProgrammer.js.map +1 -1
- package/lib/programmers/http/HttpQuerifyProgrammer.js +33 -69
- package/lib/programmers/http/HttpQuerifyProgrammer.js.map +1 -1
- package/lib/programmers/http/HttpValidateQuerifyProgrammer.js +11 -28
- package/lib/programmers/http/HttpValidateQuerifyProgrammer.js.map +1 -1
- package/lib/programmers/internal/CoreMetadataUtil.js +12 -37
- package/lib/programmers/internal/CoreMetadataUtil.js.map +1 -1
- package/lib/transform.js +8 -8
- package/lib/transform.js.map +1 -1
- package/lib/transformers/FileTransformer.js +35 -66
- package/lib/transformers/FileTransformer.js.map +1 -1
- package/lib/transformers/MethodTransformer.js +39 -50
- package/lib/transformers/MethodTransformer.js.map +1 -1
- package/lib/transformers/NodeTransformer.js +8 -12
- package/lib/transformers/NodeTransformer.js.map +1 -1
- package/lib/transformers/ParameterDecoratorTransformer.js +75 -90
- package/lib/transformers/ParameterDecoratorTransformer.js.map +1 -1
- package/lib/transformers/ParameterTransformer.js +18 -24
- package/lib/transformers/ParameterTransformer.js.map +1 -1
- package/lib/transformers/TypedExceptionTransformer.js +24 -27
- package/lib/transformers/TypedExceptionTransformer.js.map +1 -1
- package/lib/transformers/TypedRouteTransformer.js +50 -88
- package/lib/transformers/TypedRouteTransformer.js.map +1 -1
- package/lib/transformers/WebSocketRouteTransformer.d.ts +6 -0
- package/lib/transformers/WebSocketRouteTransformer.js +72 -0
- package/lib/transformers/WebSocketRouteTransformer.js.map +1 -0
- package/lib/utils/ArrayUtil.d.ts +3 -0
- package/lib/utils/ArrayUtil.js +11 -0
- package/lib/utils/ArrayUtil.js.map +1 -0
- package/lib/utils/ExceptionManager.js +9 -31
- package/lib/utils/ExceptionManager.js.map +1 -1
- package/lib/utils/Singleton.js +6 -7
- package/lib/utils/Singleton.js.map +1 -1
- package/lib/utils/SourceFinder.js +38 -215
- package/lib/utils/SourceFinder.js.map +1 -1
- package/lib/utils/VersioningStrategy.d.ts +9 -0
- package/lib/utils/VersioningStrategy.js +17 -0
- package/lib/utils/VersioningStrategy.js.map +1 -0
- package/package.json +10 -6
- package/src/adaptors/WebSocketAdaptor.ts +416 -0
- package/src/decorators/TypedParam.ts +5 -6
- package/src/decorators/TypedQuery.ts +251 -251
- package/src/decorators/WebSocketRoute.ts +249 -0
- package/src/decorators/internal/IWebSocketRouteReflect.ts +23 -0
- package/src/decorators/internal/validate_request_body.ts +72 -72
- package/src/decorators/internal/validate_request_form_data.ts +75 -75
- package/src/decorators/internal/validate_request_headers.ts +83 -83
- package/src/decorators/internal/validate_request_query.ts +71 -71
- package/src/module.ts +20 -16
- package/src/transformers/MethodTransformer.ts +7 -4
- package/src/transformers/ParameterDecoratorTransformer.ts +129 -120
- package/src/transformers/TypedExceptionTransformer.ts +9 -13
- package/src/transformers/TypedRouteTransformer.ts +1 -8
- package/src/transformers/WebSocketRouteTransformer.ts +103 -0
- package/src/typings/get-function-location.d.ts +7 -0
- package/src/utils/ArrayUtil.ts +7 -0
- package/src/utils/VersioningStrategy.ts +27 -0
|
@@ -1,51 +1,15 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __read = (this && this.__read) || function (o, n) {
|
|
3
|
-
var m = typeof Symbol === "function" && o[Symbol.iterator];
|
|
4
|
-
if (!m) return o;
|
|
5
|
-
var i = m.call(o), r, ar = [], e;
|
|
6
|
-
try {
|
|
7
|
-
while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
|
|
8
|
-
}
|
|
9
|
-
catch (error) { e = { error: error }; }
|
|
10
|
-
finally {
|
|
11
|
-
try {
|
|
12
|
-
if (r && !r.done && (m = i["return"])) m.call(i);
|
|
13
|
-
}
|
|
14
|
-
finally { if (e) throw e.error; }
|
|
15
|
-
}
|
|
16
|
-
return ar;
|
|
17
|
-
};
|
|
18
|
-
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
19
|
-
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
|
|
20
|
-
if (ar || !(i in from)) {
|
|
21
|
-
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
|
|
22
|
-
ar[i] = from[i];
|
|
23
|
-
}
|
|
24
|
-
}
|
|
25
|
-
return to.concat(ar || Array.prototype.slice.call(from));
|
|
26
|
-
};
|
|
27
|
-
var __values = (this && this.__values) || function(o) {
|
|
28
|
-
var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
|
|
29
|
-
if (m) return m.call(o);
|
|
30
|
-
if (o && typeof o.length === "number") return {
|
|
31
|
-
next: function () {
|
|
32
|
-
if (o && i >= o.length) o = void 0;
|
|
33
|
-
return { value: o && o[i++], done: !o };
|
|
34
|
-
}
|
|
35
|
-
};
|
|
36
|
-
throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
|
|
37
|
-
};
|
|
38
2
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
39
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
40
4
|
};
|
|
41
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
42
6
|
exports.TypedQuery = void 0;
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
7
|
+
const common_1 = require("@nestjs/common");
|
|
8
|
+
const rxjs_1 = require("rxjs");
|
|
9
|
+
const typia_1 = __importDefault(require("typia"));
|
|
10
|
+
const get_path_and_querify_1 = require("./internal/get_path_and_querify");
|
|
11
|
+
const route_error_1 = require("./internal/route_error");
|
|
12
|
+
const validate_request_query_1 = require("./internal/validate_request_query");
|
|
49
13
|
/**
|
|
50
14
|
* Type safe URL query decorator.
|
|
51
15
|
*
|
|
@@ -53,8 +17,8 @@ var validate_request_query_1 = require("./internal/validate_request_query");
|
|
|
53
17
|
* same with {@link nest.Query}, but it can automatically cast property type following
|
|
54
18
|
* its DTO definition. Also, `TypedQuery` performs type validation.
|
|
55
19
|
*
|
|
56
|
-
* For reference, target type `T` must follow such restriction. Also, if
|
|
57
|
-
* query parameter values are different with their promised type `T`,
|
|
20
|
+
* For reference, target type `T` must follow such restriction. Also, if
|
|
21
|
+
* actual URL query parameter values are different with their promised type `T`,
|
|
58
22
|
* `BadRequestException` error (status code: 400) would be thrown.
|
|
59
23
|
*
|
|
60
24
|
* 1. Type `T` must be an object type
|
|
@@ -66,13 +30,13 @@ var validate_request_query_1 = require("./internal/validate_request_query");
|
|
|
66
30
|
* @author Jeongho Nam - https://github.com/samchon
|
|
67
31
|
*/
|
|
68
32
|
function TypedQuery(validator) {
|
|
69
|
-
|
|
33
|
+
const checker = (0, validate_request_query_1.validate_request_query)("TypedQuery")(validator);
|
|
70
34
|
return (0, common_1.createParamDecorator)(function TypedQuery(_unknown, context) {
|
|
71
|
-
|
|
35
|
+
const request = context
|
|
72
36
|
.switchToHttp()
|
|
73
37
|
.getRequest();
|
|
74
|
-
|
|
75
|
-
|
|
38
|
+
const params = new URLSearchParams(tail(request.url));
|
|
39
|
+
const output = checker(params);
|
|
76
40
|
if (output instanceof Error)
|
|
77
41
|
throw output;
|
|
78
42
|
return output;
|
|
@@ -80,24 +44,23 @@ function TypedQuery(validator) {
|
|
|
80
44
|
}
|
|
81
45
|
exports.TypedQuery = TypedQuery;
|
|
82
46
|
(function (TypedQuery) {
|
|
83
|
-
var e_1, _a, e_2, _b, e_3, _c;
|
|
84
47
|
/**
|
|
85
48
|
* Request body decorator.
|
|
86
49
|
*
|
|
87
50
|
* Request body decorator for the `application/x-www-form-urlencoded` type.
|
|
88
51
|
*/
|
|
89
52
|
function Body(validator) {
|
|
90
|
-
|
|
53
|
+
const checker = (0, validate_request_query_1.validate_request_query)("TypedQuery.Body")(validator);
|
|
91
54
|
return (0, common_1.createParamDecorator)(function TypedQueryBody(_unknown, context) {
|
|
92
|
-
|
|
55
|
+
const request = context
|
|
93
56
|
.switchToHttp()
|
|
94
57
|
.getRequest();
|
|
95
58
|
if (isApplicationQuery(request.headers["content-type"]) === false)
|
|
96
|
-
throw new common_1.BadRequestException(
|
|
97
|
-
|
|
59
|
+
throw new common_1.BadRequestException(`Request body type is not "application/x-www-form-urlencoded".`);
|
|
60
|
+
const params = request.body instanceof URLSearchParams
|
|
98
61
|
? request.body
|
|
99
62
|
: new FakeURLSearchParams(request.body);
|
|
100
|
-
|
|
63
|
+
const output = checker(params);
|
|
101
64
|
if (output instanceof Error)
|
|
102
65
|
throw output;
|
|
103
66
|
return output;
|
|
@@ -146,59 +109,22 @@ exports.TypedQuery = TypedQuery;
|
|
|
146
109
|
* @internal
|
|
147
110
|
*/
|
|
148
111
|
function Generator(method) {
|
|
149
|
-
function route() {
|
|
150
|
-
|
|
151
|
-
for (var _i = 0; _i < arguments.length; _i++) {
|
|
152
|
-
args[_i] = arguments[_i];
|
|
153
|
-
}
|
|
154
|
-
var _a = __read((0, get_path_and_querify_1.get_path_and_querify)("TypedQuery.".concat(method)).apply(void 0, __spreadArray([], __read(args), false)), 2), path = _a[0], stringify = _a[1];
|
|
112
|
+
function route(...args) {
|
|
113
|
+
const [path, stringify] = (0, get_path_and_querify_1.get_path_and_querify)(`TypedQuery.${method}`)(...args);
|
|
155
114
|
return (0, common_1.applyDecorators)(ROUTERS[method](path), (0, common_1.UseInterceptors)(new TypedQueryRouteInterceptor(stringify)));
|
|
156
115
|
}
|
|
157
116
|
return route;
|
|
158
117
|
}
|
|
159
|
-
|
|
160
|
-
for (
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
TypedQuery.Post,
|
|
170
|
-
TypedQuery.Put,
|
|
171
|
-
TypedQuery.Patch,
|
|
172
|
-
])), _k = _j.next(); !_k.done; _k = _j.next()) {
|
|
173
|
-
var deco = _k.value;
|
|
174
|
-
deco[key] = value;
|
|
175
|
-
}
|
|
176
|
-
}
|
|
177
|
-
catch (e_3_1) { e_3 = { error: e_3_1 }; }
|
|
178
|
-
finally {
|
|
179
|
-
try {
|
|
180
|
-
if (_k && !_k.done && (_c = _j.return)) _c.call(_j);
|
|
181
|
-
}
|
|
182
|
-
finally { if (e_3) throw e_3.error; }
|
|
183
|
-
}
|
|
184
|
-
}
|
|
185
|
-
}
|
|
186
|
-
catch (e_2_1) { e_2 = { error: e_2_1 }; }
|
|
187
|
-
finally {
|
|
188
|
-
try {
|
|
189
|
-
if (_g && !_g.done && (_b = _f.return)) _b.call(_f);
|
|
190
|
-
}
|
|
191
|
-
finally { if (e_2) throw e_2.error; }
|
|
192
|
-
}
|
|
193
|
-
}
|
|
194
|
-
}
|
|
195
|
-
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
196
|
-
finally {
|
|
197
|
-
try {
|
|
198
|
-
if (_e && !_e.done && (_a = _d.return)) _a.call(_d);
|
|
199
|
-
}
|
|
200
|
-
finally { if (e_1) throw e_1.error; }
|
|
201
|
-
}
|
|
118
|
+
for (const method of [typia_1.default.assert, typia_1.default.is, typia_1.default.validate])
|
|
119
|
+
for (const [key, value] of Object.entries(method))
|
|
120
|
+
for (const deco of [
|
|
121
|
+
TypedQuery.Get,
|
|
122
|
+
TypedQuery.Delete,
|
|
123
|
+
TypedQuery.Post,
|
|
124
|
+
TypedQuery.Put,
|
|
125
|
+
TypedQuery.Patch,
|
|
126
|
+
])
|
|
127
|
+
deco[key] = value;
|
|
202
128
|
})(TypedQuery || (exports.TypedQuery = TypedQuery = {}));
|
|
203
129
|
Object.assign(TypedQuery, typia_1.default.http.assertQuery);
|
|
204
130
|
Object.assign(TypedQuery, typia_1.default.http.isQuery);
|
|
@@ -207,7 +133,7 @@ Object.assign(TypedQuery, typia_1.default.http.validateQuery);
|
|
|
207
133
|
* @internal
|
|
208
134
|
*/
|
|
209
135
|
function tail(url) {
|
|
210
|
-
|
|
136
|
+
const index = url.indexOf("?");
|
|
211
137
|
return index === -1 ? "" : url.substring(index + 1);
|
|
212
138
|
}
|
|
213
139
|
/**
|
|
@@ -217,54 +143,51 @@ function isApplicationQuery(text) {
|
|
|
217
143
|
return (text !== undefined &&
|
|
218
144
|
text
|
|
219
145
|
.split(";")
|
|
220
|
-
.map(
|
|
221
|
-
.some(
|
|
146
|
+
.map((str) => str.trim())
|
|
147
|
+
.some((str) => str === "application/x-www-form-urlencoded"));
|
|
222
148
|
}
|
|
223
149
|
/**
|
|
224
150
|
* @internal
|
|
225
151
|
*/
|
|
226
|
-
|
|
227
|
-
|
|
152
|
+
class FakeURLSearchParams {
|
|
153
|
+
constructor(target) {
|
|
228
154
|
this.target = target;
|
|
229
155
|
}
|
|
230
|
-
|
|
156
|
+
has(key) {
|
|
231
157
|
return this.target[key] !== undefined;
|
|
232
|
-
}
|
|
233
|
-
|
|
158
|
+
}
|
|
159
|
+
get(key) {
|
|
234
160
|
var _a;
|
|
235
|
-
|
|
161
|
+
const value = this.target[key];
|
|
236
162
|
return value === undefined
|
|
237
163
|
? null
|
|
238
164
|
: Array.isArray(value)
|
|
239
165
|
? (_a = value[0]) !== null && _a !== void 0 ? _a : null
|
|
240
166
|
: value;
|
|
241
|
-
}
|
|
242
|
-
|
|
243
|
-
|
|
167
|
+
}
|
|
168
|
+
getAll(key) {
|
|
169
|
+
const value = this.target[key];
|
|
244
170
|
return value === undefined ? [] : Array.isArray(value) ? value : [value];
|
|
245
|
-
}
|
|
246
|
-
|
|
247
|
-
}());
|
|
171
|
+
}
|
|
172
|
+
}
|
|
248
173
|
/**
|
|
249
174
|
* @internal
|
|
250
175
|
*/
|
|
251
|
-
|
|
252
|
-
|
|
176
|
+
class TypedQueryRouteInterceptor {
|
|
177
|
+
constructor(toSearchParams) {
|
|
253
178
|
this.toSearchParams = toSearchParams;
|
|
254
179
|
}
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
var response = http.getResponse();
|
|
180
|
+
intercept(context, next) {
|
|
181
|
+
const http = context.switchToHttp();
|
|
182
|
+
const response = http.getResponse();
|
|
259
183
|
response.header("Content-Type", "application/x-www-form-urlencoded");
|
|
260
|
-
return next.handle().pipe((0, rxjs_1.map)(
|
|
261
|
-
}
|
|
262
|
-
|
|
263
|
-
}());
|
|
184
|
+
return next.handle().pipe((0, rxjs_1.map)((value) => this.toSearchParams(value).toString()), (0, rxjs_1.catchError)((err) => (0, route_error_1.route_error)(http.getRequest(), err)));
|
|
185
|
+
}
|
|
186
|
+
}
|
|
264
187
|
/**
|
|
265
188
|
* @internal
|
|
266
189
|
*/
|
|
267
|
-
|
|
190
|
+
const ROUTERS = {
|
|
268
191
|
Get: common_1.Get,
|
|
269
192
|
Post: common_1.Post,
|
|
270
193
|
Patch: common_1.Patch,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"TypedQuery.js","sourceRoot":"","sources":["../../src/decorators/TypedQuery.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"TypedQuery.js","sourceRoot":"","sources":["../../src/decorators/TypedQuery.ts"],"names":[],"mappings":";;;;;;AAAA,2CAawB;AAIxB,+BAAuC;AACvC,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,IAAA,iBAAU,EAAC,CAAC,GAAG,EAAE,EAAE,CAAC,IAAA,yBAAW,EAAC,IAAI,CAAC,UAAU,EAAE,EAAE,GAAG,CAAC,CAAC,CACzD,CAAC;IACJ,CAAC;CACF;AAED;;GAEG;AACH,MAAM,OAAO,GAAG;IACd,GAAG,EAAH,YAAG;IACH,IAAI,EAAJ,aAAI;IACJ,KAAK,EAAL,cAAK;IACL,GAAG,EAAH,YAAG;IACH,MAAM,EAAN,eAAM;CACP,CAAC"}
|
|
@@ -1,51 +1,14 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __read = (this && this.__read) || function (o, n) {
|
|
3
|
-
var m = typeof Symbol === "function" && o[Symbol.iterator];
|
|
4
|
-
if (!m) return o;
|
|
5
|
-
var i = m.call(o), r, ar = [], e;
|
|
6
|
-
try {
|
|
7
|
-
while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
|
|
8
|
-
}
|
|
9
|
-
catch (error) { e = { error: error }; }
|
|
10
|
-
finally {
|
|
11
|
-
try {
|
|
12
|
-
if (r && !r.done && (m = i["return"])) m.call(i);
|
|
13
|
-
}
|
|
14
|
-
finally { if (e) throw e.error; }
|
|
15
|
-
}
|
|
16
|
-
return ar;
|
|
17
|
-
};
|
|
18
|
-
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
19
|
-
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
|
|
20
|
-
if (ar || !(i in from)) {
|
|
21
|
-
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
|
|
22
|
-
ar[i] = from[i];
|
|
23
|
-
}
|
|
24
|
-
}
|
|
25
|
-
return to.concat(ar || Array.prototype.slice.call(from));
|
|
26
|
-
};
|
|
27
|
-
var __values = (this && this.__values) || function(o) {
|
|
28
|
-
var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
|
|
29
|
-
if (m) return m.call(o);
|
|
30
|
-
if (o && typeof o.length === "number") return {
|
|
31
|
-
next: function () {
|
|
32
|
-
if (o && i >= o.length) o = void 0;
|
|
33
|
-
return { value: o && o[i++], done: !o };
|
|
34
|
-
}
|
|
35
|
-
};
|
|
36
|
-
throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
|
|
37
|
-
};
|
|
38
2
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
39
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
40
4
|
};
|
|
41
|
-
var e_1, _a, e_2, _b, e_3, _c;
|
|
42
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
43
6
|
exports.TypedRoute = void 0;
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
7
|
+
const common_1 = require("@nestjs/common");
|
|
8
|
+
const operators_1 = require("rxjs/operators");
|
|
9
|
+
const typia_1 = __importDefault(require("typia"));
|
|
10
|
+
const get_path_and_stringify_1 = require("./internal/get_path_and_stringify");
|
|
11
|
+
const route_error_1 = require("./internal/route_error");
|
|
49
12
|
/**
|
|
50
13
|
* Type safe router decorator functions.
|
|
51
14
|
*
|
|
@@ -102,85 +65,46 @@ var TypedRoute;
|
|
|
102
65
|
* @internal
|
|
103
66
|
*/
|
|
104
67
|
function Generator(method) {
|
|
105
|
-
function route() {
|
|
106
|
-
|
|
107
|
-
for (var _i = 0; _i < arguments.length; _i++) {
|
|
108
|
-
args[_i] = arguments[_i];
|
|
109
|
-
}
|
|
110
|
-
var _a = __read((0, get_path_and_stringify_1.get_path_and_stringify)("TypedRoute.".concat(method)).apply(void 0, __spreadArray([], __read(args), false)), 2), path = _a[0], stringify = _a[1];
|
|
68
|
+
function route(...args) {
|
|
69
|
+
const [path, stringify] = (0, get_path_and_stringify_1.get_path_and_stringify)(`TypedRoute.${method}`)(...args);
|
|
111
70
|
return (0, common_1.applyDecorators)(ROUTERS[method](path), (0, common_1.UseInterceptors)(new TypedRouteInterceptor(stringify)));
|
|
112
71
|
}
|
|
113
72
|
return route;
|
|
114
73
|
}
|
|
115
74
|
})(TypedRoute || (exports.TypedRoute = TypedRoute = {}));
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
TypedRoute.Post,
|
|
132
|
-
TypedRoute.Put,
|
|
133
|
-
TypedRoute.Patch,
|
|
134
|
-
])), _k = _j.next(); !_k.done; _k = _j.next()) {
|
|
135
|
-
var deco = _k.value;
|
|
136
|
-
deco[key] = value;
|
|
137
|
-
}
|
|
138
|
-
}
|
|
139
|
-
catch (e_3_1) { e_3 = { error: e_3_1 }; }
|
|
140
|
-
finally {
|
|
141
|
-
try {
|
|
142
|
-
if (_k && !_k.done && (_c = _j.return)) _c.call(_j);
|
|
143
|
-
}
|
|
144
|
-
finally { if (e_3) throw e_3.error; }
|
|
145
|
-
}
|
|
146
|
-
}
|
|
147
|
-
}
|
|
148
|
-
catch (e_2_1) { e_2 = { error: e_2_1 }; }
|
|
149
|
-
finally {
|
|
150
|
-
try {
|
|
151
|
-
if (_g && !_g.done && (_b = _f.return)) _b.call(_f);
|
|
152
|
-
}
|
|
153
|
-
finally { if (e_2) throw e_2.error; }
|
|
154
|
-
}
|
|
155
|
-
}
|
|
156
|
-
}
|
|
157
|
-
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
158
|
-
finally {
|
|
159
|
-
try {
|
|
160
|
-
if (_e && !_e.done && (_a = _d.return)) _a.call(_d);
|
|
161
|
-
}
|
|
162
|
-
finally { if (e_1) throw e_1.error; }
|
|
163
|
-
}
|
|
75
|
+
for (const method of [
|
|
76
|
+
typia_1.default.json.stringify,
|
|
77
|
+
typia_1.default.json.isStringify,
|
|
78
|
+
typia_1.default.json.assertStringify,
|
|
79
|
+
typia_1.default.json.validateStringify,
|
|
80
|
+
])
|
|
81
|
+
for (const [key, value] of Object.entries(method))
|
|
82
|
+
for (const deco of [
|
|
83
|
+
TypedRoute.Get,
|
|
84
|
+
TypedRoute.Delete,
|
|
85
|
+
TypedRoute.Post,
|
|
86
|
+
TypedRoute.Put,
|
|
87
|
+
TypedRoute.Patch,
|
|
88
|
+
])
|
|
89
|
+
deco[key] = value;
|
|
164
90
|
/**
|
|
165
91
|
* @internal
|
|
166
92
|
*/
|
|
167
|
-
|
|
168
|
-
|
|
93
|
+
class TypedRouteInterceptor {
|
|
94
|
+
constructor(stringify) {
|
|
169
95
|
this.stringify = stringify;
|
|
170
96
|
}
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
var response = http.getResponse();
|
|
97
|
+
intercept(context, next) {
|
|
98
|
+
const http = context.switchToHttp();
|
|
99
|
+
const response = http.getResponse();
|
|
175
100
|
response.header("Content-Type", "application/json");
|
|
176
|
-
return next.handle().pipe((0, operators_1.map)(
|
|
177
|
-
}
|
|
178
|
-
|
|
179
|
-
}());
|
|
101
|
+
return next.handle().pipe((0, operators_1.map)((value) => this.stringify(value)), (0, operators_1.catchError)((err) => (0, route_error_1.route_error)(http.getRequest(), err)));
|
|
102
|
+
}
|
|
103
|
+
}
|
|
180
104
|
/**
|
|
181
105
|
* @internal
|
|
182
106
|
*/
|
|
183
|
-
|
|
107
|
+
const ROUTERS = {
|
|
184
108
|
Get: common_1.Get,
|
|
185
109
|
Post: common_1.Post,
|
|
186
110
|
Patch: common_1.Patch,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"TypedRoute.js","sourceRoot":"","sources":["../../src/decorators/TypedRoute.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"TypedRoute.js","sourceRoot":"","sources":["../../src/decorators/TypedRoute.ts"],"names":[],"mappings":";;;;;;AAAA,2CAWwB;AAGxB,8CAAiD;AACjD,kDAA0B;AAG1B,8EAA2E;AAC3E,wDAAqD;AAErD;;;;;;;;;;;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AAU,CAAC,KAAK;SACjB;YACE,IAAY,CAAC,GAAG,CAAC,GAAG,KAAK,CAAC;AAEjC;;GAEG;AACH,MAAM,qBAAqB;IACzB,YAAoC,SAAiC;QAAjC,cAAS,GAAT,SAAS,CAAwB;IAAG,CAAC;IAElE,SAAS,CAAC,OAAyB,EAAE,IAAiB;QAC3D,MAAM,IAAI,GAAsB,OAAO,CAAC,YAAY,EAAE,CAAC;QACvD,MAAM,QAAQ,GAAqB,IAAI,CAAC,WAAW,EAAE,CAAC;QACtD,QAAQ,CAAC,MAAM,CAAC,cAAc,EAAE,kBAAkB,CAAC,CAAC;QAEpD,OAAO,IAAI,CAAC,MAAM,EAAE,CAAC,IAAI,CACvB,IAAA,eAAG,EAAC,CAAC,KAAK,EAAE,EAAE,CAAC,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC,EACrC,IAAA,sBAAU,EAAC,CAAC,GAAG,EAAE,EAAE,CAAC,IAAA,yBAAW,EAAC,IAAI,CAAC,UAAU,EAAE,EAAE,GAAG,CAAC,CAAC,CACzD,CAAC;IACJ,CAAC;CACF;AAED;;GAEG;AACH,MAAM,OAAO,GAAG;IACd,GAAG,EAAH,YAAG;IACH,IAAI,EAAJ,aAAI;IACJ,KAAK,EAAL,cAAK;IACL,GAAG,EAAH,YAAG;IACH,MAAM,EAAN,eAAM;CACP,CAAC"}
|
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
import { IRequestBodyValidator } from "../options/IRequestBodyValidator";
|
|
2
|
+
import { IRequestQueryValidator } from "../options/IRequestQueryValidator";
|
|
3
|
+
/**
|
|
4
|
+
* WebSocket route decorator.
|
|
5
|
+
*
|
|
6
|
+
* `@WebSocketRoute` is a route decorator function for WebSocket routes.
|
|
7
|
+
* If you want to define a WebSocket route with this `@WebSocketRoute` decorator,
|
|
8
|
+
* please don't forget to call the {@link WebSocketAdaptor.upgrade} function
|
|
9
|
+
* to the {@link INestApplication} instance.
|
|
10
|
+
*
|
|
11
|
+
* Also, `WebSocketRoute` is a module containing parameter decorator
|
|
12
|
+
* functions of below for the `@WebSocketRoute` decorated method, at the same
|
|
13
|
+
* time. Note that, every parameters must be decorated by one of the parameter
|
|
14
|
+
* decorators in the `WebSocketRoute` module. One thing more important is,
|
|
15
|
+
* {@link WebSocketRoute.Acceptor} decorated parameter must be defined in the
|
|
16
|
+
* method. If not, it would be both compilation/runtime error.
|
|
17
|
+
*
|
|
18
|
+
* - {@link WebSocketRoute.Acceptor}
|
|
19
|
+
* - {@link WebSocketRoute.Driver}
|
|
20
|
+
* - {@link WebSocketRoute.Header}
|
|
21
|
+
* - {@link WebSocketRoute.Param}
|
|
22
|
+
* - {@link WebSocketRoute.Query}
|
|
23
|
+
*
|
|
24
|
+
* For reference, key difference between `@WebSocketGateway()` of NestJS and
|
|
25
|
+
* `@WebSocketRoute()` of Nestia is, `@WebSocketRoute()` can make multiple
|
|
26
|
+
* WebSocket routes by configuring *paths*, besides `@WebSocketGateway()`
|
|
27
|
+
* can't do it.
|
|
28
|
+
*
|
|
29
|
+
* Furthermore, if you build SDK (Software Development Kit) library through
|
|
30
|
+
* `@nestia/sdk`, you can make safe WebSocket client taking advantages of
|
|
31
|
+
* TypeScript type hints and checkings.
|
|
32
|
+
*
|
|
33
|
+
* @param path Path(s) of the WebSocket request
|
|
34
|
+
* @returns Method decorator
|
|
35
|
+
* @author Jeongho Nam - https://github.com/samchon
|
|
36
|
+
*/
|
|
37
|
+
export declare function WebSocketRoute(path?: undefined | string | string[]): MethodDecorator;
|
|
38
|
+
export declare namespace WebSocketRoute {
|
|
39
|
+
/**
|
|
40
|
+
* Acceptor parameter decorator.
|
|
41
|
+
*
|
|
42
|
+
* `@WebSocketRoute.Acceptor()` is a parameter decorator function for the
|
|
43
|
+
* `WebAcceptor<Header, Provider, Listener>` (of `tgrid`) typed parameter.
|
|
44
|
+
*
|
|
45
|
+
* In the controller method decorated by `@WebSocketRoute()` and
|
|
46
|
+
* `@WebSocketRoute.Acceptor()`, call {@link WebAcceptor.accept} function
|
|
47
|
+
* with `Provider` instance when you want to accept the WebSocket client
|
|
48
|
+
* connection. Otherwise you want to reject the connection, call
|
|
49
|
+
* {@link WebSocketAcceptor.rejcet} function instead.
|
|
50
|
+
*
|
|
51
|
+
* For reference, this `@WebSocketRoute.Acceptor()` parameter decorator is
|
|
52
|
+
* essential for the method decorated by `@WebSocketRoute()` decorator.
|
|
53
|
+
* If you forget it, it would be both compilation/runtime error.
|
|
54
|
+
*/
|
|
55
|
+
function Acceptor(): ParameterDecorator;
|
|
56
|
+
/**
|
|
57
|
+
* Driver parameter decorator.
|
|
58
|
+
*
|
|
59
|
+
* `@WebSocketRoute.Driver()` is a parameter decorator function for the
|
|
60
|
+
* `Driver<Listener>` (of `tgrid`) typed parameter.
|
|
61
|
+
*
|
|
62
|
+
* With the `@WebSocketRoute.Driver()` decorated parameter, you can call
|
|
63
|
+
* function of `Listener` typed instance provided by remote WebSocket client
|
|
64
|
+
* by calling the `Driver<Listener>` instance.
|
|
65
|
+
*
|
|
66
|
+
* For reference, this `@WebSocketRoute.Driver()` decorator is optional, and
|
|
67
|
+
* can be substituted by `@WebSocketRoute.Acceptor()` decorated parameter
|
|
68
|
+
* by calling the {@link WebAcceptor.getDriver} function.
|
|
69
|
+
*/
|
|
70
|
+
function Driver(): ParameterDecorator;
|
|
71
|
+
/**
|
|
72
|
+
* Header decorator.
|
|
73
|
+
*
|
|
74
|
+
* `@WebSocketRoute.Header()` is a parameter decorator function for the
|
|
75
|
+
* WebSocket header with type casting and assertion.
|
|
76
|
+
*
|
|
77
|
+
* For reference, `@WebSocketRoute.Header()` is different with HTTP headers.
|
|
78
|
+
* It's for WebSocket protocol, especially for TGrid's {@link WebConnector}
|
|
79
|
+
* and {@link WebAcceptor}'s special header.
|
|
80
|
+
*
|
|
81
|
+
* Also, this `@WebSocketRoute.Header()` decorator is optional, and
|
|
82
|
+
* can be substituted by `@WebSocketRoute.Acceptor()` decorated parameter
|
|
83
|
+
* by accessting to the {@link WebAcceptor.header} property.
|
|
84
|
+
*/
|
|
85
|
+
function Header<T>(validator?: IRequestBodyValidator<T>): ParameterDecorator;
|
|
86
|
+
/**
|
|
87
|
+
* URL parameter decorator.
|
|
88
|
+
*
|
|
89
|
+
* `@WebSocketRoute.Param()` is a parameter decorator function for the URL
|
|
90
|
+
* parameter with type casting and assertion.
|
|
91
|
+
*
|
|
92
|
+
* It's almost same with the {@link TypedParam}, but
|
|
93
|
+
* `@WebSocketRoute.Param()` is only for WebSocket protocol router function
|
|
94
|
+
* decorated by {@link WebSocketRoute}.
|
|
95
|
+
*
|
|
96
|
+
* @param field URL parameter field name
|
|
97
|
+
*/
|
|
98
|
+
function Param<T extends boolean | bigint | number | string | null>(field: string, assert?: (value: string) => T): ParameterDecorator;
|
|
99
|
+
/**
|
|
100
|
+
* URL query decorator.
|
|
101
|
+
*
|
|
102
|
+
* `@WebSocketRoute.Query()` is a parameter decorator function for the URL
|
|
103
|
+
* query string with type casting and assertion.
|
|
104
|
+
*
|
|
105
|
+
* It is almost same with {@link TypedQuery}, but
|
|
106
|
+
* `@WebSocketRoute.Query()` is only for WebSocket protocol router function
|
|
107
|
+
* decorated by {@link WebSocketRoute}.
|
|
108
|
+
*
|
|
109
|
+
* For reference, as same with {@link TypedQuery}, `@WebSocketRoute.Query()`
|
|
110
|
+
* has same restriction for the target type `T`. If actual URL query
|
|
111
|
+
* parameter values are different with their promised type `T`,
|
|
112
|
+
* it would be runtime error.
|
|
113
|
+
*
|
|
114
|
+
* 1. Type `T` must be an object type
|
|
115
|
+
* 2. Do not allow dynamic property
|
|
116
|
+
* 3. Only `boolean`, `bigint`, `number`, `string` or their array types are allowed
|
|
117
|
+
* 4. By the way, union type never be not allowed
|
|
118
|
+
*/
|
|
119
|
+
function Query<T extends object>(validator?: IRequestQueryValidator<T>): ParameterDecorator;
|
|
120
|
+
}
|