@nestia/core 0.1.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 -0
- package/lib/decorators/EncryptedBody.d.ts +22 -0
- package/lib/decorators/EncryptedBody.js +125 -0
- package/lib/decorators/EncryptedBody.js.map +1 -0
- package/lib/decorators/EncryptedController.d.ts +31 -0
- package/lib/decorators/EncryptedController.js +42 -0
- package/lib/decorators/EncryptedController.js.map +1 -0
- package/lib/decorators/EncryptedModule.d.ts +48 -0
- package/lib/decorators/EncryptedModule.js +270 -0
- package/lib/decorators/EncryptedModule.js.map +1 -0
- package/lib/decorators/EncryptedRoute.d.ts +78 -0
- package/lib/decorators/EncryptedRoute.js +191 -0
- package/lib/decorators/EncryptedRoute.js.map +1 -0
- package/lib/decorators/PlainBody.d.ts +22 -0
- package/lib/decorators/PlainBody.js +83 -0
- package/lib/decorators/PlainBody.js.map +1 -0
- package/lib/decorators/TypedBody.d.ts +14 -0
- package/lib/decorators/TypedBody.js +93 -0
- package/lib/decorators/TypedBody.js.map +1 -0
- package/lib/decorators/TypedParam.d.ts +25 -0
- package/lib/decorators/TypedParam.js +62 -0
- package/lib/decorators/TypedParam.js.map +1 -0
- package/lib/decorators/TypedRoute.d.ts +71 -0
- package/lib/decorators/TypedRoute.js +159 -0
- package/lib/decorators/TypedRoute.js.map +1 -0
- package/lib/decorators/internal/EncryptedConstant.d.ts +1 -0
- package/lib/decorators/internal/EncryptedConstant.js +8 -0
- package/lib/decorators/internal/EncryptedConstant.js.map +1 -0
- package/lib/decorators/internal/get_path_and_stringify.d.ts +1 -0
- package/lib/decorators/internal/get_path_and_stringify.js +75 -0
- package/lib/decorators/internal/get_path_and_stringify.js.map +1 -0
- package/lib/decorators/internal/headers_to_object.d.ts +1 -0
- package/lib/decorators/internal/headers_to_object.js +53 -0
- package/lib/decorators/internal/headers_to_object.js.map +1 -0
- package/lib/decorators/internal/route_error.d.ts +1 -0
- package/lib/decorators/internal/route_error.js +90 -0
- package/lib/decorators/internal/route_error.js.map +1 -0
- package/lib/decorators/internal/validate_request_body.d.ts +2 -0
- package/lib/decorators/internal/validate_request_body.js +56 -0
- package/lib/decorators/internal/validate_request_body.js.map +1 -0
- package/lib/index.d.ts +3 -0
- package/lib/index.js +32 -0
- package/lib/index.js.map +1 -0
- package/lib/module.d.ts +9 -0
- package/lib/module.js +26 -0
- package/lib/module.js.map +1 -0
- package/lib/options/INestiaTransformOptions.d.ts +5 -0
- package/lib/options/INestiaTransformOptions.js +3 -0
- package/lib/options/INestiaTransformOptions.js.map +1 -0
- package/lib/options/INestiaTransformProject.d.ts +5 -0
- package/lib/options/INestiaTransformProject.js +3 -0
- package/lib/options/INestiaTransformProject.js.map +1 -0
- package/lib/options/IRequestBodyValidator.d.ts +16 -0
- package/lib/options/IRequestBodyValidator.js +3 -0
- package/lib/options/IRequestBodyValidator.js.map +1 -0
- package/lib/options/IResponseBodyStringifier.d.ts +20 -0
- package/lib/options/IResponseBodyStringifier.js +3 -0
- package/lib/options/IResponseBodyStringifier.js.map +1 -0
- package/lib/transform.d.ts +3 -0
- package/lib/transform.js +21 -0
- package/lib/transform.js.map +1 -0
- package/lib/transformers/BodyTransformer.d.ts +5 -0
- package/lib/transformers/BodyTransformer.js +69 -0
- package/lib/transformers/BodyTransformer.js.map +1 -0
- package/lib/transformers/FileTransformer.d.ts +5 -0
- package/lib/transformers/FileTransformer.js +33 -0
- package/lib/transformers/FileTransformer.js.map +1 -0
- package/lib/transformers/MethodTransformer.d.ts +5 -0
- package/lib/transformers/MethodTransformer.js +55 -0
- package/lib/transformers/MethodTransformer.js.map +1 -0
- package/lib/transformers/NodeTransformer.d.ts +5 -0
- package/lib/transformers/NodeTransformer.js +21 -0
- package/lib/transformers/NodeTransformer.js.map +1 -0
- package/lib/transformers/ParameterTransformer.d.ts +5 -0
- package/lib/transformers/ParameterTransformer.js +31 -0
- package/lib/transformers/ParameterTransformer.js.map +1 -0
- package/lib/transformers/RouteTransformer.d.ts +5 -0
- package/lib/transformers/RouteTransformer.js +115 -0
- package/lib/transformers/RouteTransformer.js.map +1 -0
- package/lib/typings/Creator.d.ts +3 -0
- package/lib/typings/Creator.js +3 -0
- package/lib/typings/Creator.js.map +1 -0
- package/lib/utils/ExceptionManager.d.ts +64 -0
- package/lib/utils/ExceptionManager.js +113 -0
- package/lib/utils/ExceptionManager.js.map +1 -0
- package/lib/utils/Singleton.d.ts +1 -0
- package/lib/utils/Singleton.js +24 -0
- package/lib/utils/Singleton.js.map +1 -0
- package/package.json +66 -0
- package/src/decorators/EncryptedBody.ts +102 -0
- package/src/decorators/EncryptedController.ts +43 -0
- package/src/decorators/EncryptedModule.ts +127 -0
- package/src/decorators/EncryptedRoute.ts +200 -0
- package/src/decorators/PlainBody.ts +38 -0
- package/src/decorators/TypedBody.ts +49 -0
- package/src/decorators/TypedParam.ts +70 -0
- package/src/decorators/TypedRoute.ts +149 -0
- package/src/decorators/internal/EncryptedConstant.ts +4 -0
- package/src/decorators/internal/get_path_and_stringify.ts +76 -0
- package/src/decorators/internal/headers_to_object.ts +13 -0
- package/src/decorators/internal/route_error.ts +41 -0
- package/src/decorators/internal/validate_request_body.ts +58 -0
- package/src/index.ts +5 -0
- package/src/module.ts +9 -0
- package/src/options/INestiaTransformOptions.ts +6 -0
- package/src/options/INestiaTransformProject.ts +6 -0
- package/src/options/IRequestBodyValidator.ts +20 -0
- package/src/options/IResponseBodyStringifier.ts +25 -0
- package/src/transform.ts +20 -0
- package/src/transformers/BodyTransformer.ts +106 -0
- package/src/transformers/FileTransformer.ts +49 -0
- package/src/transformers/MethodTransformer.ts +91 -0
- package/src/transformers/NodeTransformer.ts +18 -0
- package/src/transformers/ParameterTransformer.ts +45 -0
- package/src/transformers/RouteTransformer.ts +134 -0
- package/src/typings/Creator.ts +3 -0
- package/src/utils/ExceptionManager.ts +126 -0
- package/src/utils/Singleton.ts +20 -0
|
@@ -0,0 +1,191 @@
|
|
|
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
|
+
var e_1, _a;
|
|
39
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
40
|
+
exports.EncryptedRoute = void 0;
|
|
41
|
+
var fetcher_1 = require("@nestia/fetcher");
|
|
42
|
+
var common_1 = require("@nestjs/common");
|
|
43
|
+
var rxjs_1 = require("rxjs");
|
|
44
|
+
var typia_1 = require("typia");
|
|
45
|
+
var Singleton_1 = require("../utils/Singleton");
|
|
46
|
+
var EncryptedConstant_1 = require("./internal/EncryptedConstant");
|
|
47
|
+
var get_path_and_stringify_1 = require("./internal/get_path_and_stringify");
|
|
48
|
+
var headers_to_object_1 = require("./internal/headers_to_object");
|
|
49
|
+
var route_error_1 = require("./internal/route_error");
|
|
50
|
+
/**
|
|
51
|
+
* Encrypted router decorator functions.
|
|
52
|
+
*
|
|
53
|
+
* `EncryptedRoute` is a module containing router decorator functions which encrypts
|
|
54
|
+
* response body data through AES-128/250 encryption. Also, those decorator functions
|
|
55
|
+
* can boost up JSON string conversion speed about 5x times faster, through
|
|
56
|
+
* [`typia.stringify()`](https://github.com/samchon/typia#fastest-json-string-conversion).
|
|
57
|
+
*
|
|
58
|
+
* For reference, `EncryptedRoute` encrypts response body usnig those options.
|
|
59
|
+
*
|
|
60
|
+
* - AES-128/256
|
|
61
|
+
* - CBC mode
|
|
62
|
+
* - PKCS #5 Padding
|
|
63
|
+
* - Base64 Encoding
|
|
64
|
+
*
|
|
65
|
+
* Also, router functions in `EncryptedRoute` can convert custom error classes to the
|
|
66
|
+
* regular {@link nest.HttpException} class automatically, through
|
|
67
|
+
* {@link ExceptionManager}.
|
|
68
|
+
*
|
|
69
|
+
* @author Jeongho Nam - https://github.com/samchon
|
|
70
|
+
*/
|
|
71
|
+
var EncryptedRoute;
|
|
72
|
+
(function (EncryptedRoute) {
|
|
73
|
+
/**
|
|
74
|
+
* Encrypted router decorator function for the GET method.
|
|
75
|
+
*
|
|
76
|
+
* @param paths Path(s) of the HTTP request
|
|
77
|
+
* @returns Method decorator
|
|
78
|
+
*/
|
|
79
|
+
EncryptedRoute.Get = Generator("Get");
|
|
80
|
+
/**
|
|
81
|
+
* Encrypted router decorator function for the GET method.
|
|
82
|
+
*
|
|
83
|
+
* @param paths Path(s) of the HTTP request
|
|
84
|
+
* @returns Method decorator
|
|
85
|
+
*/
|
|
86
|
+
EncryptedRoute.Post = Generator("Post");
|
|
87
|
+
/**
|
|
88
|
+
* Encrypted router decorator function for the PATCH method.
|
|
89
|
+
*
|
|
90
|
+
* @param path Path of the HTTP request
|
|
91
|
+
* @returns Method decorator
|
|
92
|
+
*/
|
|
93
|
+
EncryptedRoute.Patch = Generator("Patch");
|
|
94
|
+
/**
|
|
95
|
+
* Encrypted router decorator function for the PUT method.
|
|
96
|
+
*
|
|
97
|
+
* @param path Path of the HTTP request
|
|
98
|
+
* @returns Method decorator
|
|
99
|
+
*/
|
|
100
|
+
EncryptedRoute.Put = Generator("Put");
|
|
101
|
+
/**
|
|
102
|
+
* Encrypted router decorator function for the DELETE method.
|
|
103
|
+
*
|
|
104
|
+
* @param path Path of the HTTP request
|
|
105
|
+
* @returns Method decorator
|
|
106
|
+
*/
|
|
107
|
+
EncryptedRoute.Delete = Generator("Delete");
|
|
108
|
+
function Generator(method) {
|
|
109
|
+
function route() {
|
|
110
|
+
var args = [];
|
|
111
|
+
for (var _i = 0; _i < arguments.length; _i++) {
|
|
112
|
+
args[_i] = arguments[_i];
|
|
113
|
+
}
|
|
114
|
+
var _a = __read((0, get_path_and_stringify_1.get_path_and_stringify)("EncryptedRoute.".concat(method)).apply(void 0, __spreadArray([], __read(args), false)), 2), path = _a[0], stringify = _a[1];
|
|
115
|
+
return (0, common_1.applyDecorators)(ROUTERS[method](path), (0, common_1.UseInterceptors)(new EncryptedRouteInterceptor(method, stringify)));
|
|
116
|
+
}
|
|
117
|
+
return route;
|
|
118
|
+
}
|
|
119
|
+
})(EncryptedRoute = exports.EncryptedRoute || (exports.EncryptedRoute = {}));
|
|
120
|
+
try {
|
|
121
|
+
for (var _b = __values([
|
|
122
|
+
typia_1.assertStringify,
|
|
123
|
+
typia_1.isStringify,
|
|
124
|
+
typia_1.stringify,
|
|
125
|
+
typia_1.validateStringify,
|
|
126
|
+
]), _c = _b.next(); !_c.done; _c = _b.next()) {
|
|
127
|
+
var method = _c.value;
|
|
128
|
+
Object.assign(EncryptedRoute.Get, method);
|
|
129
|
+
Object.assign(EncryptedRoute.Delete, method);
|
|
130
|
+
Object.assign(EncryptedRoute.Post, method);
|
|
131
|
+
Object.assign(EncryptedRoute.Put, method);
|
|
132
|
+
Object.assign(EncryptedRoute.Patch, method);
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
136
|
+
finally {
|
|
137
|
+
try {
|
|
138
|
+
if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
|
|
139
|
+
}
|
|
140
|
+
finally { if (e_1) throw e_1.error; }
|
|
141
|
+
}
|
|
142
|
+
/**
|
|
143
|
+
* @internal
|
|
144
|
+
*/
|
|
145
|
+
var EncryptedRouteInterceptor = /** @class */ (function () {
|
|
146
|
+
function EncryptedRouteInterceptor(method, stringify) {
|
|
147
|
+
this.method = method;
|
|
148
|
+
this.stringify = stringify;
|
|
149
|
+
}
|
|
150
|
+
EncryptedRouteInterceptor.prototype.intercept = function (context, next) {
|
|
151
|
+
var _this = this;
|
|
152
|
+
var http = context.switchToHttp();
|
|
153
|
+
return next.handle().pipe((0, rxjs_1.map)(function (value) {
|
|
154
|
+
var param = Reflect.getMetadata(EncryptedConstant_1.ENCRYPTION_METADATA_KEY, context.getClass());
|
|
155
|
+
if (!param)
|
|
156
|
+
throw new Error("Error on EncryptedRoute.".concat(_this.method, "(): no encryption password is given."));
|
|
157
|
+
var headers = new Singleton_1.Singleton(function () {
|
|
158
|
+
var request = http.getRequest();
|
|
159
|
+
return (0, headers_to_object_1.headers_to_object)(request.headers);
|
|
160
|
+
});
|
|
161
|
+
var body = _this.stringify(value);
|
|
162
|
+
var password = typeof param === "function"
|
|
163
|
+
? param({ headers: headers.get(), body: body }, false)
|
|
164
|
+
: param;
|
|
165
|
+
var disabled = password.disabled === undefined
|
|
166
|
+
? false
|
|
167
|
+
: typeof password.disabled === "function"
|
|
168
|
+
? password.disabled({ headers: headers.get(), body: body }, false)
|
|
169
|
+
: password.disabled;
|
|
170
|
+
var response = http.getResponse();
|
|
171
|
+
response.header("Content-Type", disabled ? "application/json" : "text/plain");
|
|
172
|
+
if (disabled === true)
|
|
173
|
+
return body;
|
|
174
|
+
else if (body === undefined)
|
|
175
|
+
return body;
|
|
176
|
+
return fetcher_1.AesPkcs5.encrypt(body, password.key, password.iv);
|
|
177
|
+
}), (0, rxjs_1.catchError)(function (err) { return (0, route_error_1.route_error)(http.getRequest(), err); }));
|
|
178
|
+
};
|
|
179
|
+
return EncryptedRouteInterceptor;
|
|
180
|
+
}());
|
|
181
|
+
/**
|
|
182
|
+
* @internal
|
|
183
|
+
*/
|
|
184
|
+
var ROUTERS = {
|
|
185
|
+
Get: common_1.Get,
|
|
186
|
+
Post: common_1.Post,
|
|
187
|
+
Put: common_1.Put,
|
|
188
|
+
Patch: common_1.Patch,
|
|
189
|
+
Delete: common_1.Delete,
|
|
190
|
+
};
|
|
191
|
+
//# sourceMappingURL=EncryptedRoute.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"EncryptedRoute.js","sourceRoot":"","sources":["../../src/decorators/EncryptedRoute.ts"],"names":[],"mappings":"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"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Plain body decorator.
|
|
3
|
+
*
|
|
4
|
+
* `PlainBody` is a decorator function getting full body text from the HTTP request.
|
|
5
|
+
*
|
|
6
|
+
* If you adjust the regular {@link Body} decorator function to the body parameter,
|
|
7
|
+
* you can't get the full body text because the {@link Body} tries to convert the
|
|
8
|
+
* body text to JSON object. Therefore, `nestia-helper` provides this `PlainBody`
|
|
9
|
+
* decorator function to get the full body text.
|
|
10
|
+
*
|
|
11
|
+
* ```typescript
|
|
12
|
+
* \@TypedRoute.Post("memo")
|
|
13
|
+
* public store
|
|
14
|
+
* (
|
|
15
|
+
* \@PlainBody() body: string
|
|
16
|
+
* ): void;
|
|
17
|
+
* ```
|
|
18
|
+
*
|
|
19
|
+
* @return Parameter decorator
|
|
20
|
+
* @author Jeongho Nam - https://github.com/samchon
|
|
21
|
+
*/
|
|
22
|
+
export declare const PlainBody: () => ParameterDecorator;
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
12
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
13
|
+
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
14
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
15
|
+
function step(op) {
|
|
16
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
17
|
+
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
18
|
+
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
19
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
20
|
+
switch (op[0]) {
|
|
21
|
+
case 0: case 1: t = op; break;
|
|
22
|
+
case 4: _.label++; return { value: op[1], done: false };
|
|
23
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
24
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
25
|
+
default:
|
|
26
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
27
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
28
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
29
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
30
|
+
if (t[2]) _.ops.pop();
|
|
31
|
+
_.trys.pop(); continue;
|
|
32
|
+
}
|
|
33
|
+
op = body.call(thisArg, _);
|
|
34
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
35
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
36
|
+
}
|
|
37
|
+
};
|
|
38
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
39
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
40
|
+
};
|
|
41
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
42
|
+
exports.PlainBody = void 0;
|
|
43
|
+
var common_1 = require("@nestjs/common");
|
|
44
|
+
var raw_body_1 = __importDefault(require("raw-body"));
|
|
45
|
+
/**
|
|
46
|
+
* Plain body decorator.
|
|
47
|
+
*
|
|
48
|
+
* `PlainBody` is a decorator function getting full body text from the HTTP request.
|
|
49
|
+
*
|
|
50
|
+
* If you adjust the regular {@link Body} decorator function to the body parameter,
|
|
51
|
+
* you can't get the full body text because the {@link Body} tries to convert the
|
|
52
|
+
* body text to JSON object. Therefore, `nestia-helper` provides this `PlainBody`
|
|
53
|
+
* decorator function to get the full body text.
|
|
54
|
+
*
|
|
55
|
+
* ```typescript
|
|
56
|
+
* \@TypedRoute.Post("memo")
|
|
57
|
+
* public store
|
|
58
|
+
* (
|
|
59
|
+
* \@PlainBody() body: string
|
|
60
|
+
* ): void;
|
|
61
|
+
* ```
|
|
62
|
+
*
|
|
63
|
+
* @return Parameter decorator
|
|
64
|
+
* @author Jeongho Nam - https://github.com/samchon
|
|
65
|
+
*/
|
|
66
|
+
exports.PlainBody = (0, common_1.createParamDecorator)(function PlainBody(_data, context) {
|
|
67
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
68
|
+
var request, body;
|
|
69
|
+
return __generator(this, function (_a) {
|
|
70
|
+
switch (_a.label) {
|
|
71
|
+
case 0:
|
|
72
|
+
request = context.switchToHttp().getRequest();
|
|
73
|
+
if (!request.readable)
|
|
74
|
+
throw new common_1.BadRequestException("Invalid body");
|
|
75
|
+
return [4 /*yield*/, (0, raw_body_1.default)(request)];
|
|
76
|
+
case 1:
|
|
77
|
+
body = (_a.sent()).toString("utf8").trim();
|
|
78
|
+
return [2 /*return*/, body];
|
|
79
|
+
}
|
|
80
|
+
});
|
|
81
|
+
});
|
|
82
|
+
});
|
|
83
|
+
//# sourceMappingURL=PlainBody.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"PlainBody.js","sourceRoot":"","sources":["../../src/decorators/PlainBody.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,yCAIwB;AAExB,sDAA2B;AAE3B;;;;;;;;;;;;;;;;;;;;GAoBG;AACU,QAAA,SAAS,GAA6B,IAAA,6BAAoB,EACnE,SAAe,SAAS,CAAC,KAAU,EAAE,OAAyB;;;;;;oBACpD,OAAO,GAAoB,OAAO,CAAC,YAAY,EAAE,CAAC,UAAU,EAAE,CAAC;oBACrE,IAAI,CAAC,OAAO,CAAC,QAAQ;wBAAE,MAAM,IAAI,4BAAmB,CAAC,cAAc,CAAC,CAAC;oBAE/C,qBAAM,IAAA,kBAAG,EAAC,OAAO,CAAC,EAAA;;oBAAlC,IAAI,GAAW,CAAC,SAAkB,CAAC,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC,IAAI,EAAE;oBACjE,sBAAO,IAAI,EAAC;;;;CACf,CACJ,CAAC"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { IRequestBodyValidator } from "../options/IRequestBodyValidator";
|
|
2
|
+
/**
|
|
3
|
+
* Safe body decorator.
|
|
4
|
+
*
|
|
5
|
+
* `TypedBody` is a decorator function getting JSON data from HTTP request. Also,
|
|
6
|
+
* it validates the JSON data type through
|
|
7
|
+
* [`typia.assert()`](https://github.com/samchon/typia#runtime-type-checkers)
|
|
8
|
+
* function and throws `BadRequestException` error (status code: 400), if the JSON
|
|
9
|
+
* data is not following the promised type.
|
|
10
|
+
*
|
|
11
|
+
* @param validator Custom validator if required. Default is `typia.assert()`
|
|
12
|
+
* @author Jeongho Nam - https://github.com/samchon
|
|
13
|
+
*/
|
|
14
|
+
export declare function TypedBody<T>(validator?: IRequestBodyValidator<T>): ParameterDecorator;
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
12
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
13
|
+
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
14
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
15
|
+
function step(op) {
|
|
16
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
17
|
+
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
18
|
+
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
19
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
20
|
+
switch (op[0]) {
|
|
21
|
+
case 0: case 1: t = op; break;
|
|
22
|
+
case 4: _.label++; return { value: op[1], done: false };
|
|
23
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
24
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
25
|
+
default:
|
|
26
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
27
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
28
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
29
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
30
|
+
if (t[2]) _.ops.pop();
|
|
31
|
+
_.trys.pop(); continue;
|
|
32
|
+
}
|
|
33
|
+
op = body.call(thisArg, _);
|
|
34
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
35
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
36
|
+
}
|
|
37
|
+
};
|
|
38
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
39
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
40
|
+
};
|
|
41
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
42
|
+
exports.TypedBody = void 0;
|
|
43
|
+
var common_1 = require("@nestjs/common");
|
|
44
|
+
var raw_body_1 = __importDefault(require("raw-body"));
|
|
45
|
+
var typia_1 = require("typia");
|
|
46
|
+
var validate_request_body_1 = require("./internal/validate_request_body");
|
|
47
|
+
/**
|
|
48
|
+
* Safe body decorator.
|
|
49
|
+
*
|
|
50
|
+
* `TypedBody` is a decorator function getting JSON data from HTTP request. Also,
|
|
51
|
+
* it validates the JSON data type through
|
|
52
|
+
* [`typia.assert()`](https://github.com/samchon/typia#runtime-type-checkers)
|
|
53
|
+
* function and throws `BadRequestException` error (status code: 400), if the JSON
|
|
54
|
+
* data is not following the promised type.
|
|
55
|
+
*
|
|
56
|
+
* @param validator Custom validator if required. Default is `typia.assert()`
|
|
57
|
+
* @author Jeongho Nam - https://github.com/samchon
|
|
58
|
+
*/
|
|
59
|
+
function TypedBody(validator) {
|
|
60
|
+
var checker = (0, validate_request_body_1.validate_request_body)("TypedBody")(validator);
|
|
61
|
+
return (0, common_1.createParamDecorator)(function TypedBody(_unknown, context) {
|
|
62
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
63
|
+
var request, data, _a, _b, _c;
|
|
64
|
+
return __generator(this, function (_d) {
|
|
65
|
+
switch (_d.label) {
|
|
66
|
+
case 0:
|
|
67
|
+
request = context.switchToHttp().getRequest();
|
|
68
|
+
if (request.headers["content-type"] !== "application/json") {
|
|
69
|
+
throw new common_1.BadRequestException("Request body is not the application/json.");
|
|
70
|
+
}
|
|
71
|
+
if (!request.body) return [3 /*break*/, 1];
|
|
72
|
+
_a = request.body;
|
|
73
|
+
return [3 /*break*/, 3];
|
|
74
|
+
case 1:
|
|
75
|
+
_c = (_b = JSON).parse;
|
|
76
|
+
return [4 /*yield*/, (0, raw_body_1.default)(request, "utf8")];
|
|
77
|
+
case 2:
|
|
78
|
+
_a = _c.apply(_b, [(_d.sent()).trim()]);
|
|
79
|
+
_d.label = 3;
|
|
80
|
+
case 3:
|
|
81
|
+
data = _a;
|
|
82
|
+
checker(data);
|
|
83
|
+
return [2 /*return*/, data];
|
|
84
|
+
}
|
|
85
|
+
});
|
|
86
|
+
});
|
|
87
|
+
})();
|
|
88
|
+
}
|
|
89
|
+
exports.TypedBody = TypedBody;
|
|
90
|
+
Object.assign(TypedBody, typia_1.assert);
|
|
91
|
+
Object.assign(TypedBody, typia_1.is);
|
|
92
|
+
Object.assign(TypedBody, typia_1.validate);
|
|
93
|
+
//# sourceMappingURL=TypedBody.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"TypedBody.js","sourceRoot":"","sources":["../../src/decorators/TypedBody.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,yCAIwB;AAExB,sDAA2B;AAC3B,+BAA6C;AAG7C,0EAAyE;AAEzE;;;;;;;;;;;GAWG;AACH,SAAgB,SAAS,CACrB,SAAoC;IAEpC,IAAM,OAAO,GAAG,IAAA,6CAAqB,EAAC,WAAW,CAAC,CAAC,SAAS,CAAC,CAAC;IAC9D,OAAO,IAAA,6BAAoB,EAAC,SAAe,SAAS,CAChD,QAAa,EACb,OAAyB;;;;;;wBAEnB,OAAO,GAAoB,OAAO,CAAC,YAAY,EAAE,CAAC,UAAU,EAAE,CAAC;wBACrE,IAAI,OAAO,CAAC,OAAO,CAAC,cAAc,CAAC,KAAK,kBAAkB,EAAE;4BACxD,MAAM,IAAI,4BAAmB,CACzB,2CAA2C,CAC9C,CAAC;yBACL;6BACiB,OAAO,CAAC,IAAI,EAAZ,wBAAY;wBACxB,KAAA,OAAO,CAAC,IAAI,CAAA;;;wBACZ,KAAA,CAAA,KAAA,IAAI,CAAA,CAAC,KAAK,CAAA;wBAAE,qBAAM,IAAA,kBAAG,EAAC,OAAO,EAAE,MAAM,CAAC,EAAA;;wBAAtC,KAAA,cAAW,CAAC,SAA0B,CAAC,CAAC,IAAI,EAAE,EAAC,CAAA;;;wBAF/C,IAAI,KAE2C;wBACrD,OAAO,CAAC,IAAI,CAAC,CAAC;wBACd,sBAAO,IAAI,EAAC;;;;KACf,CAAC,EAAE,CAAC;AACT,CAAC;AApBD,8BAoBC;AAED,MAAM,CAAC,MAAM,CAAC,SAAS,EAAE,cAAM,CAAC,CAAC;AACjC,MAAM,CAAC,MAAM,CAAC,SAAS,EAAE,UAAE,CAAC,CAAC;AAC7B,MAAM,CAAC,MAAM,CAAC,SAAS,EAAE,gBAAQ,CAAC,CAAC"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* URL parameter decorator with type.
|
|
3
|
+
*
|
|
4
|
+
* `TypedParam` is a decorator function getting specific typed parameter from the HTTP
|
|
5
|
+
* request URL. It's almost same with the {@link nest.Param}, but `TypedParam` can specify
|
|
6
|
+
* the parameter type manually. Beside, the {@link nest.Param} always parses all of the
|
|
7
|
+
* parameters as string type.
|
|
8
|
+
*
|
|
9
|
+
* ```typescript
|
|
10
|
+
* \@TypedRoute.Get("shopping/sales/:section/:id/:paused")
|
|
11
|
+
* public async pause
|
|
12
|
+
* (
|
|
13
|
+
* \@TypedParam("section", "string") section: string,
|
|
14
|
+
* \@TypedParam("id", "number") id: number,
|
|
15
|
+
* \@TypedParam("paused", "boolean", true) paused: boolean | null
|
|
16
|
+
* ): Promise<void>;
|
|
17
|
+
* ```
|
|
18
|
+
*
|
|
19
|
+
* @param name URL Parameter name
|
|
20
|
+
* @param type Type of the URL parameter
|
|
21
|
+
* @returns Parameter decorator
|
|
22
|
+
*
|
|
23
|
+
* @author Jeongho Nam - https://github.com/samchon
|
|
24
|
+
*/
|
|
25
|
+
export declare function TypedParam(name: string, type?: "boolean" | "number" | "string" | "uuid", nullable?: boolean): ParameterDecorator;
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.TypedParam = void 0;
|
|
4
|
+
var common_1 = require("@nestjs/common");
|
|
5
|
+
/**
|
|
6
|
+
* URL parameter decorator with type.
|
|
7
|
+
*
|
|
8
|
+
* `TypedParam` is a decorator function getting specific typed parameter from the HTTP
|
|
9
|
+
* request URL. It's almost same with the {@link nest.Param}, but `TypedParam` can specify
|
|
10
|
+
* the parameter type manually. Beside, the {@link nest.Param} always parses all of the
|
|
11
|
+
* parameters as string type.
|
|
12
|
+
*
|
|
13
|
+
* ```typescript
|
|
14
|
+
* \@TypedRoute.Get("shopping/sales/:section/:id/:paused")
|
|
15
|
+
* public async pause
|
|
16
|
+
* (
|
|
17
|
+
* \@TypedParam("section", "string") section: string,
|
|
18
|
+
* \@TypedParam("id", "number") id: number,
|
|
19
|
+
* \@TypedParam("paused", "boolean", true) paused: boolean | null
|
|
20
|
+
* ): Promise<void>;
|
|
21
|
+
* ```
|
|
22
|
+
*
|
|
23
|
+
* @param name URL Parameter name
|
|
24
|
+
* @param type Type of the URL parameter
|
|
25
|
+
* @returns Parameter decorator
|
|
26
|
+
*
|
|
27
|
+
* @author Jeongho Nam - https://github.com/samchon
|
|
28
|
+
*/
|
|
29
|
+
function TypedParam(name, type, nullable) {
|
|
30
|
+
if (type === void 0) { type = "string"; }
|
|
31
|
+
if (nullable === void 0) { nullable = false; }
|
|
32
|
+
return (0, common_1.createParamDecorator)(function TypedParam(_a, ctx) {
|
|
33
|
+
var request = ctx.switchToHttp().getRequest();
|
|
34
|
+
var str = request.params[name];
|
|
35
|
+
if (nullable === true && str === "null")
|
|
36
|
+
return null;
|
|
37
|
+
else if (type === "boolean") {
|
|
38
|
+
if (str === "true" || str === "1")
|
|
39
|
+
return true;
|
|
40
|
+
else if (str === "false" || str === "0")
|
|
41
|
+
return false;
|
|
42
|
+
else
|
|
43
|
+
throw new common_1.BadRequestException("Value of the URL parameter '".concat(name, "' is not a boolean."));
|
|
44
|
+
}
|
|
45
|
+
else if (type === "number") {
|
|
46
|
+
var value = Number(str);
|
|
47
|
+
if (isNaN(value))
|
|
48
|
+
throw new common_1.BadRequestException("Value of the URL parameter \"".concat(name, "\" is not a number."));
|
|
49
|
+
return value;
|
|
50
|
+
}
|
|
51
|
+
else if (type === "uuid") {
|
|
52
|
+
if (UUID_PATTERN.test(str) === false)
|
|
53
|
+
throw new common_1.BadRequestException("Value of the URL parameter \"".concat(name, "\" is not a valid UUID."));
|
|
54
|
+
return str;
|
|
55
|
+
}
|
|
56
|
+
else
|
|
57
|
+
return str;
|
|
58
|
+
})(name);
|
|
59
|
+
}
|
|
60
|
+
exports.TypedParam = TypedParam;
|
|
61
|
+
var UUID_PATTERN = /^[0-9A-F]{8}-[0-9A-F]{4}-[0-9A-F]{4}-[0-9A-F]{4}-[0-9A-F]{12}$/i;
|
|
62
|
+
//# sourceMappingURL=TypedParam.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"TypedParam.js","sourceRoot":"","sources":["../../src/decorators/TypedParam.ts"],"names":[],"mappings":";;;AAAA,yCAIwB;AAGxB;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,SAAgB,UAAU,CACtB,IAAY,EACZ,IAAyD,EACzD,QAAyB;IADzB,qBAAA,EAAA,eAAyD;IACzD,yBAAA,EAAA,gBAAyB;IAEzB,OAAO,IAAA,6BAAoB,EAAC,SAAS,UAAU,CAC3C,EAAO,EACP,GAAqB;QAErB,IAAM,OAAO,GAAoB,GAAG,CAAC,YAAY,EAAE,CAAC,UAAU,EAAE,CAAC;QACjE,IAAM,GAAG,GAAW,OAAO,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;QAEzC,IAAI,QAAQ,KAAK,IAAI,IAAI,GAAG,KAAK,MAAM;YAAE,OAAO,IAAI,CAAC;aAChD,IAAI,IAAI,KAAK,SAAS,EAAE;YACzB,IAAI,GAAG,KAAK,MAAM,IAAI,GAAG,KAAK,GAAG;gBAAE,OAAO,IAAI,CAAC;iBAC1C,IAAI,GAAG,KAAK,OAAO,IAAI,GAAG,KAAK,GAAG;gBAAE,OAAO,KAAK,CAAC;;gBAElD,MAAM,IAAI,4BAAmB,CACzB,sCAA+B,IAAI,wBAAqB,CAC3D,CAAC;SACT;aAAM,IAAI,IAAI,KAAK,QAAQ,EAAE;YAC1B,IAAM,KAAK,GAAW,MAAM,CAAC,GAAG,CAAC,CAAC;YAClC,IAAI,KAAK,CAAC,KAAK,CAAC;gBACZ,MAAM,IAAI,4BAAmB,CACzB,uCAA+B,IAAI,wBAAoB,CAC1D,CAAC;YACN,OAAO,KAAK,CAAC;SAChB;aAAM,IAAI,IAAI,KAAK,MAAM,EAAE;YACxB,IAAI,YAAY,CAAC,IAAI,CAAC,GAAG,CAAC,KAAK,KAAK;gBAChC,MAAM,IAAI,4BAAmB,CACzB,uCAA+B,IAAI,4BAAwB,CAC9D,CAAC;YACN,OAAO,GAAG,CAAC;SACd;;YAAM,OAAO,GAAG,CAAC;IACtB,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC;AACb,CAAC;AAnCD,gCAmCC;AAED,IAAM,YAAY,GACd,iEAAiE,CAAC"}
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import { IResponseBodyStringifier } from "../options/IResponseBodyStringifier";
|
|
2
|
+
/**
|
|
3
|
+
* Safe router decorator functions.
|
|
4
|
+
*
|
|
5
|
+
* `TypedRoute` is a module containing router decorator functions which can boost up
|
|
6
|
+
* JSON string conversion speed about 5x times faster, through
|
|
7
|
+
* [`typia.stringify()`](https://github.com/samchon/typia#fastest-json-string-conversion).
|
|
8
|
+
*
|
|
9
|
+
* Also, router functions in `TypedRoute` can convert custom error classes to the
|
|
10
|
+
* regular {@link nest.HttpException} class automatically, through
|
|
11
|
+
* {@link ExceptionManager}.
|
|
12
|
+
*
|
|
13
|
+
* @author Jeongho Nam - https://github.com/samchon
|
|
14
|
+
*/
|
|
15
|
+
export declare namespace TypedRoute {
|
|
16
|
+
/**
|
|
17
|
+
* Router decorator function for the GET method.
|
|
18
|
+
*
|
|
19
|
+
* @param path Path of the HTTP request
|
|
20
|
+
* @returns Method decorator
|
|
21
|
+
*/
|
|
22
|
+
const Get: {
|
|
23
|
+
(path?: string | string[]): MethodDecorator;
|
|
24
|
+
<T>(stringify?: IResponseBodyStringifier<T> | undefined): MethodDecorator;
|
|
25
|
+
<T_1>(path: string | string[], stringify?: IResponseBodyStringifier<T_1> | undefined): MethodDecorator;
|
|
26
|
+
};
|
|
27
|
+
/**
|
|
28
|
+
* Router decorator function for the POST method.
|
|
29
|
+
*
|
|
30
|
+
* @param path Path of the HTTP request
|
|
31
|
+
* @returns Method decorator
|
|
32
|
+
*/
|
|
33
|
+
const Post: {
|
|
34
|
+
(path?: string | string[]): MethodDecorator;
|
|
35
|
+
<T>(stringify?: IResponseBodyStringifier<T> | undefined): MethodDecorator;
|
|
36
|
+
<T_1>(path: string | string[], stringify?: IResponseBodyStringifier<T_1> | undefined): MethodDecorator;
|
|
37
|
+
};
|
|
38
|
+
/**
|
|
39
|
+
* Router decorator function for the PATH method.
|
|
40
|
+
*
|
|
41
|
+
* @param path Path of the HTTP request
|
|
42
|
+
* @returns Method decorator
|
|
43
|
+
*/
|
|
44
|
+
const Patch: {
|
|
45
|
+
(path?: string | string[]): MethodDecorator;
|
|
46
|
+
<T>(stringify?: IResponseBodyStringifier<T> | undefined): MethodDecorator;
|
|
47
|
+
<T_1>(path: string | string[], stringify?: IResponseBodyStringifier<T_1> | undefined): MethodDecorator;
|
|
48
|
+
};
|
|
49
|
+
/**
|
|
50
|
+
* Router decorator function for the PUT method.
|
|
51
|
+
*
|
|
52
|
+
* @param path Path of the HTTP request
|
|
53
|
+
* @returns Method decorator
|
|
54
|
+
*/
|
|
55
|
+
const Put: {
|
|
56
|
+
(path?: string | string[]): MethodDecorator;
|
|
57
|
+
<T>(stringify?: IResponseBodyStringifier<T> | undefined): MethodDecorator;
|
|
58
|
+
<T_1>(path: string | string[], stringify?: IResponseBodyStringifier<T_1> | undefined): MethodDecorator;
|
|
59
|
+
};
|
|
60
|
+
/**
|
|
61
|
+
* Router decorator function for the DELETE method.
|
|
62
|
+
*
|
|
63
|
+
* @param path Path of the HTTP request
|
|
64
|
+
* @returns Method decorator
|
|
65
|
+
*/
|
|
66
|
+
const Delete: {
|
|
67
|
+
(path?: string | string[]): MethodDecorator;
|
|
68
|
+
<T>(stringify?: IResponseBodyStringifier<T> | undefined): MethodDecorator;
|
|
69
|
+
<T_1>(path: string | string[], stringify?: IResponseBodyStringifier<T_1> | undefined): MethodDecorator;
|
|
70
|
+
};
|
|
71
|
+
}
|