@nestia/core 1.2.3 → 1.2.4
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/decorators/EncryptedBody.js +2 -6
- package/lib/decorators/EncryptedBody.js.map +1 -1
- package/lib/decorators/PlainBody.js +3 -4
- package/lib/decorators/PlainBody.js.map +1 -1
- package/lib/decorators/TypedBody.js +2 -6
- package/lib/decorators/TypedBody.js.map +1 -1
- package/lib/decorators/TypedParam.js +7 -6
- package/lib/decorators/TypedParam.js.map +1 -1
- package/lib/decorators/TypedQuery.js +2 -3
- package/lib/decorators/TypedQuery.js.map +1 -1
- package/lib/decorators/internal/route_error.d.ts +2 -1
- package/lib/decorators/internal/route_error.js +4 -2
- package/lib/decorators/internal/route_error.js.map +1 -1
- package/package.json +2 -2
- package/src/decorators/EncryptedBody.ts +3 -10
- package/src/decorators/PlainBody.ts +5 -8
- package/src/decorators/TypedBody.ts +3 -10
- package/src/decorators/TypedParam.ts +15 -23
- package/src/decorators/TypedQuery.ts +8 -11
- package/src/decorators/internal/route_error.ts +8 -2
- package/lib/decorators/internal/send_bad_request.d.ts +0 -2
- package/lib/decorators/internal/send_bad_request.js +0 -13
- package/lib/decorators/internal/send_bad_request.js.map +0 -1
- package/src/decorators/internal/send_bad_request.ts +0 -12
|
@@ -44,7 +44,6 @@ var Singleton_1 = require("../utils/Singleton");
|
|
|
44
44
|
var EncryptedConstant_1 = require("./internal/EncryptedConstant");
|
|
45
45
|
var get_text_body_1 = require("./internal/get_text_body");
|
|
46
46
|
var headers_to_object_1 = require("./internal/headers_to_object");
|
|
47
|
-
var send_bad_request_1 = require("./internal/send_bad_request");
|
|
48
47
|
var validate_request_body_1 = require("./internal/validate_request_body");
|
|
49
48
|
/**
|
|
50
49
|
* Encrypted body decorator.
|
|
@@ -79,7 +78,7 @@ function EncryptedBody(validator) {
|
|
|
79
78
|
.switchToHttp()
|
|
80
79
|
.getRequest();
|
|
81
80
|
if (isTextPlain(request.headers["content-type"]) === false)
|
|
82
|
-
|
|
81
|
+
throw new common_1.BadRequestException("Request body type is not \"text/plain\".");
|
|
83
82
|
param = Reflect.getMetadata(EncryptedConstant_1.ENCRYPTION_METADATA_KEY, context.getClass());
|
|
84
83
|
if (!param)
|
|
85
84
|
throw new Error("Error on nestia.core.EncryptedBody(): no encryption password is given.");
|
|
@@ -95,10 +94,7 @@ function EncryptedBody(validator) {
|
|
|
95
94
|
data = JSON.parse(decrypt(body, password.key, password.iv));
|
|
96
95
|
error = checker(data);
|
|
97
96
|
if (error !== null)
|
|
98
|
-
|
|
99
|
-
return [2 /*return*/, (0, send_bad_request_1.send_bad_request)(context)(error)];
|
|
100
|
-
else
|
|
101
|
-
throw error;
|
|
97
|
+
throw error;
|
|
102
98
|
return [2 /*return*/, data];
|
|
103
99
|
}
|
|
104
100
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"EncryptedBody.js","sourceRoot":"","sources":["../../src/decorators/EncryptedBody.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,2CAAgE;AAChE,
|
|
1
|
+
{"version":3,"file":"EncryptedBody.js","sourceRoot":"","sources":["../../src/decorators/EncryptedBody.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,2CAAgE;AAChE,yCAIwB;AAIxB,+BAA6C;AAG7C,gDAA+C;AAC/C,kEAAuE;AACvE,0DAAyD;AACzD,kEAAiE;AACjE,0EAAyE;AAEzE;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,SAAgB,aAAa,CACzB,SAAoC;IAEpC,IAAM,OAAO,GAAG,IAAA,6CAAqB,EAAC,eAAe,CAAC,CAAC,SAAS,CAAC,CAAC;IAClE,OAAO,IAAA,6BAAoB,EAAC,SAAe,aAAa,CACpD,QAAa,EACb,OAAyB;;;;;;wBAEnB,OAAO,GAAqC,OAAO;6BACpD,YAAY,EAAE;6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;;GAEG;AACH,IAAM,OAAO,GAAG,UAAC,IAAY,EAAE,GAAW,EAAE,EAAU;IAClD,IAAI;QACA,OAAO,kBAAQ,CAAC,OAAO,CAAC,IAAI,EAAE,GAAG,EAAE,EAAE,CAAC,CAAC;KAC1C;IAAC,OAAO,GAAG,EAAE;QACV,IAAI,GAAG,YAAY,KAAK;YACpB,MAAM,IAAI,4BAAmB,CACzB,qFAAqF,CACxF,CAAC;;YACD,MAAM,GAAG,CAAC;KAClB;AACL,CAAC,CAAC;AAEF,IAAM,WAAW,GAAG,UAAC,IAAa;IAC9B,OAAA,IAAI,KAAK,SAAS;QAClB,IAAI;aACC,KAAK,CAAC,GAAG,CAAC;aACV,GAAG,CAAC,UAAC,GAAG,IAAK,OAAA,GAAG,CAAC,IAAI,EAAE,EAAV,CAAU,CAAC;aACxB,IAAI,CAAC,UAAC,GAAG,IAAK,OAAA,GAAG,KAAK,YAAY,EAApB,CAAoB,CAAC;AAJxC,CAIwC,CAAC"}
|
|
@@ -39,7 +39,6 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
39
39
|
exports.PlainBody = void 0;
|
|
40
40
|
var common_1 = require("@nestjs/common");
|
|
41
41
|
var get_text_body_1 = require("./internal/get_text_body");
|
|
42
|
-
var send_bad_request_1 = require("./internal/send_bad_request");
|
|
43
42
|
/**
|
|
44
43
|
* Plain body decorator.
|
|
45
44
|
*
|
|
@@ -68,9 +67,9 @@ exports.PlainBody = (0, common_1.createParamDecorator)(function PlainBody(_data,
|
|
|
68
67
|
request = context
|
|
69
68
|
.switchToHttp()
|
|
70
69
|
.getRequest();
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
70
|
+
if (!isTextPlain(request.headers["content-type"]))
|
|
71
|
+
throw new common_1.BadRequestException("Request body type is not \"text/plain\".");
|
|
72
|
+
return [2 /*return*/, (0, get_text_body_1.get_text_body)(request)];
|
|
74
73
|
});
|
|
75
74
|
});
|
|
76
75
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"PlainBody.js","sourceRoot":"","sources":["../../src/decorators/PlainBody.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,yCAIwB;AAIxB,0DAAyD;
|
|
1
|
+
{"version":3,"file":"PlainBody.js","sourceRoot":"","sources":["../../src/decorators/PlainBody.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,yCAIwB;AAIxB,0DAAyD;AAEzD;;;;;;;;;;;;;;;;;;;;GAoBG;AACU,QAAA,SAAS,GAA6B,IAAA,6BAAoB,EACnE,SAAe,SAAS,CAAC,KAAU,EAAE,OAAyB;;;;YACpD,OAAO,GAAqC,OAAO;iBACpD,YAAY,EAAE;iBACd,UAAU,EAAE,CAAC;YAClB,IAAI,CAAC,WAAW,CAAC,OAAO,CAAC,OAAO,CAAC,cAAc,CAAC,CAAC;gBAC7C,MAAM,IAAI,4BAAmB,CACzB,0CAAwC,CAC3C,CAAC;YACN,sBAAO,IAAA,6BAAa,EAAC,OAAO,CAAC,EAAC;;;CACjC,CACJ,CAAC;AAEF,IAAM,WAAW,GAAG,UAAC,IAAa;IAC9B,OAAA,IAAI,KAAK,SAAS;QAClB,IAAI;aACC,KAAK,CAAC,GAAG,CAAC;aACV,GAAG,CAAC,UAAC,GAAG,IAAK,OAAA,GAAG,CAAC,IAAI,EAAE,EAAV,CAAU,CAAC;aACxB,IAAI,CAAC,UAAC,GAAG,IAAK,OAAA,GAAG,KAAK,YAAY,EAApB,CAAoB,CAAC;AAJxC,CAIwC,CAAC"}
|
|
@@ -3,7 +3,6 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.TypedBody = void 0;
|
|
4
4
|
var common_1 = require("@nestjs/common");
|
|
5
5
|
var typia_1 = require("typia");
|
|
6
|
-
var send_bad_request_1 = require("./internal/send_bad_request");
|
|
7
6
|
var validate_request_body_1 = require("./internal/validate_request_body");
|
|
8
7
|
/**
|
|
9
8
|
* Type safe body decorator.
|
|
@@ -26,13 +25,10 @@ function TypedBody(validator) {
|
|
|
26
25
|
.switchToHttp()
|
|
27
26
|
.getRequest();
|
|
28
27
|
if (isApplicationJson(request.headers["content-type"]) === false)
|
|
29
|
-
|
|
28
|
+
throw new common_1.BadRequestException("Request body type is not \"application/json\".");
|
|
30
29
|
var error = checker(request.body);
|
|
31
30
|
if (error !== null)
|
|
32
|
-
|
|
33
|
-
return (0, send_bad_request_1.send_bad_request)(context)(error);
|
|
34
|
-
else
|
|
35
|
-
throw error;
|
|
31
|
+
throw error;
|
|
36
32
|
return request.body;
|
|
37
33
|
})();
|
|
38
34
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"TypedBody.js","sourceRoot":"","sources":["../../src/decorators/TypedBody.ts"],"names":[],"mappings":";;;AAAA,
|
|
1
|
+
{"version":3,"file":"TypedBody.js","sourceRoot":"","sources":["../../src/decorators/TypedBody.ts"],"names":[],"mappings":";;;AAAA,yCAIwB;AAIxB,+BAA6C;AAG7C,0EAAyE;AAEzE;;;;;;;;;;;;;GAaG;AACH,SAAgB,SAAS,CACrB,SAAoC;IAEpC,IAAM,OAAO,GAAG,IAAA,6CAAqB,EAAC,WAAW,CAAC,CAAC,SAAS,CAAC,CAAC;IAC9D,OAAO,IAAA,6BAAoB,EAAC,SAAS,SAAS,CAC1C,QAAa,EACb,OAAyB;QAEzB,IAAM,OAAO,GAAqC,OAAO;aACpD,YAAY,EAAE;aACd,UAAU,EAAE,CAAC;QAClB,IAAI,iBAAiB,CAAC,OAAO,CAAC,OAAO,CAAC,cAAc,CAAC,CAAC,KAAK,KAAK;YAC5D,MAAM,IAAI,4BAAmB,CACzB,gDAA8C,CACjD,CAAC;QAEN,IAAM,KAAK,GAAiB,OAAO,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;QAClD,IAAI,KAAK,KAAK,IAAI;YAAE,MAAM,KAAK,CAAC;QAChC,OAAO,OAAO,CAAC,IAAI,CAAC;IACxB,CAAC,CAAC,EAAE,CAAC;AACT,CAAC;AApBD,8BAoBC;AAED,MAAM,CAAC,MAAM,CAAC,SAAS,EAAE,UAAE,CAAC,CAAC;AAC7B,MAAM,CAAC,MAAM,CAAC,SAAS,EAAE,cAAM,CAAC,CAAC;AACjC,MAAM,CAAC,MAAM,CAAC,SAAS,EAAE,gBAAQ,CAAC,CAAC;AAEnC,IAAM,iBAAiB,GAAG,UAAC,IAAa;IACpC,OAAA,IAAI,KAAK,SAAS;QAClB,IAAI;aACC,KAAK,CAAC,GAAG,CAAC;aACV,GAAG,CAAC,UAAC,GAAG,IAAK,OAAA,GAAG,CAAC,IAAI,EAAE,EAAV,CAAU,CAAC;aACxB,IAAI,CAAC,UAAC,GAAG,IAAK,OAAA,GAAG,KAAK,kBAAkB,EAA1B,CAA0B,CAAC;AAJ9C,CAI8C,CAAC"}
|
|
@@ -2,7 +2,6 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.TypedParam = void 0;
|
|
4
4
|
var common_1 = require("@nestjs/common");
|
|
5
|
-
var send_bad_request_1 = require("./internal/send_bad_request");
|
|
6
5
|
/**
|
|
7
6
|
* Type safe URL parameter decorator.
|
|
8
7
|
*
|
|
@@ -35,7 +34,9 @@ var send_bad_request_1 = require("./internal/send_bad_request");
|
|
|
35
34
|
*/
|
|
36
35
|
function TypedParam(name, type, nullable) {
|
|
37
36
|
function TypedParam(_a, context) {
|
|
38
|
-
var request = context
|
|
37
|
+
var request = context
|
|
38
|
+
.switchToHttp()
|
|
39
|
+
.getRequest();
|
|
39
40
|
var str = request.params[name];
|
|
40
41
|
if (nullable === true && str === "null")
|
|
41
42
|
return null;
|
|
@@ -45,22 +46,22 @@ function TypedParam(name, type, nullable) {
|
|
|
45
46
|
else if (str === "false" || str === "0")
|
|
46
47
|
return false;
|
|
47
48
|
else
|
|
48
|
-
|
|
49
|
+
throw new common_1.BadRequestException("Value of the URL parameter '".concat(name, "' is not a boolean."));
|
|
49
50
|
}
|
|
50
51
|
else if (type === "number") {
|
|
51
52
|
var value = Number(str);
|
|
52
53
|
if (isNaN(value))
|
|
53
|
-
|
|
54
|
+
throw new common_1.BadRequestException("Value of the URL parameter \"".concat(name, "\" is not a number."));
|
|
54
55
|
return value;
|
|
55
56
|
}
|
|
56
57
|
else if (type === "uuid") {
|
|
57
58
|
if (UUID_PATTERN.test(str) === false)
|
|
58
|
-
|
|
59
|
+
throw new common_1.BadRequestException("Value of the URL parameter \"".concat(name, "\" is not a valid UUID."));
|
|
59
60
|
return str;
|
|
60
61
|
}
|
|
61
62
|
else if (type === "date") {
|
|
62
63
|
if (DATE_PATTERN.test(str) === false)
|
|
63
|
-
|
|
64
|
+
throw new common_1.BadRequestException("Value of the URL parameter \"".concat(name, "\" is not a valid date."));
|
|
64
65
|
return str;
|
|
65
66
|
}
|
|
66
67
|
else
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"TypedParam.js","sourceRoot":"","sources":["../../src/decorators/TypedParam.ts"],"names":[],"mappings":";;;AAAA,yCAIwB;
|
|
1
|
+
{"version":3,"file":"TypedParam.js","sourceRoot":"","sources":["../../src/decorators/TypedParam.ts"],"names":[],"mappings":";;;AAAA,yCAIwB;AAIxB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6BG;AACH,SAAgB,UAAU,CACtB,IAAY,EACZ,IAAwD,EACxD,QAAuB;IAEvB,SAAS,UAAU,CAAC,EAAO,EAAE,OAAyB;QAClD,IAAM,OAAO,GAAqC,OAAO;aACpD,YAAY,EAAE;aACd,UAAU,EAAE,CAAC;QAClB,IAAM,GAAG,GAAY,OAAO,CAAC,MAAc,CAAC,IAAI,CAAC,CAAC;QAElD,IAAI,QAAQ,KAAK,IAAI,IAAI,GAAG,KAAK,MAAM;YAAE,OAAO,IAAI,CAAC;aAChD,IAAI,IAAI,KAAK,SAAS,EAAE;YACzB,IAAI,GAAG,KAAK,MAAM,IA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ar(require("typia"));
|
|
29
29
|
var TransformError_1 = require("./internal/TransformError");
|
|
30
|
-
var send_bad_request_1 = require("./internal/send_bad_request");
|
|
31
30
|
/**
|
|
32
31
|
* Type safe URL query decorator.
|
|
33
32
|
*
|
|
@@ -57,13 +56,13 @@ function TypedQuery(decoder) {
|
|
|
57
56
|
var $io0 = function (input) { return "string" === typeof input.method && (undefined === input.path || "string" === typeof input.path) && "string" === typeof input.expected && true && "string" === typeof input.name && "string" === typeof input.message && (undefined === input.stack || "string" === typeof input.stack); };
|
|
58
57
|
return "object" === typeof input && null !== input && $io0(input);
|
|
59
58
|
})(exp))
|
|
60
|
-
|
|
59
|
+
throw new common_1.BadRequestException({
|
|
61
60
|
path: exp.path,
|
|
62
61
|
reason: exp.message,
|
|
63
62
|
expected: exp.expected,
|
|
64
63
|
value: exp.value,
|
|
65
64
|
message: "Request query parameters are not following the promised type.",
|
|
66
|
-
})
|
|
65
|
+
});
|
|
67
66
|
throw exp;
|
|
68
67
|
}
|
|
69
68
|
})();
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"TypedQuery.js","sourceRoot":"","sources":["../../src/decorators/TypedQuery.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,yCAIwB;AAIxB,6CAAsD;AAEtD,4DAA2D;
|
|
1
|
+
{"version":3,"file":"TypedQuery.js","sourceRoot":"","sources":["../../src/decorators/TypedQuery.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,yCAIwB;AAIxB,6CAAsD;AAEtD,4DAA2D;AAE3D;;;;;;;;;;;;GAYG;AACH,SAAgB,UAAU,CACtB,OAAwC;IAExC,IAAI,OAAO,KAAK,SAAS;QAAE,MAAM,IAAA,+BAAc,EAAC,YAAY,CAAC,CAAC;IAE9D,OAAO,IAAA,6BAAoB,EAAC,SAAS,UAAU,CAC3C,QAAa,EACb,OAAyB;QAEzB,IAAM,OAAO,GAAqC,OAAO;aACpD,YAAY,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,CAAC,CAAC,SAAS,CAAC;IAC3E,CAAC;IAFe,iBAAM,SAErB,CAAA;IACD,SAAgB,MAAM,CAAC,GAAkB;QACrC,OAAO,CAAA,GAAG,aAAH,GAAG,uBAAH,GAAG,CAAE,MAAM,EAAC,CAAC,CAAC,CAAC,GAAG,KAAK,MAAM,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC;IAC3E,CAAC;IAFe,iBAAM,SAErB,CAAA;IACD,SAAgB,MAAM,CAAC,GAAkB;QACrC,OAAO,GAAG,KAAK,IAAI,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,GAAG,KAAK,MAAM,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,GAAG,CAAC;IAClE,CAAC;IAFe,iBAAM,SAErB,CAAA;AACL,CAAC,EApBgB,UAAU,GAAV,kBAAU,KAAV,kBAAU,QAoB1B;AACD,MAAM,CAAC,MAAM,CAAC,UAAU,EAAE,cAAM,CAAC,CAAC;AAElC;;GAEG;AACH,SAAS,IAAI,CAAC,GAAW;IACrB,IAAM,KAAK,GAAW,GAAG,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC;IACvC,OAAO,KAAK,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,GAAG,CAAC,SAAS,CAAC,KAAK,GAAG,CAAC,CAAC,CAAC;AACxD,CAAC"}
|
|
@@ -1,2 +1,3 @@
|
|
|
1
1
|
import express from "express";
|
|
2
|
-
|
|
2
|
+
import type { FastifyRequest } from "fastify";
|
|
3
|
+
export declare function route_error(request: express.Request | FastifyRequest, error: any): import("rxjs").Observable<never>;
|
|
@@ -32,6 +32,7 @@ var common_1 = require("@nestjs/common");
|
|
|
32
32
|
var rxjs_1 = require("rxjs");
|
|
33
33
|
var ExceptionManager_1 = require("../../utils/ExceptionManager");
|
|
34
34
|
function route_error(request, error) {
|
|
35
|
+
var _a;
|
|
35
36
|
error = (function () {
|
|
36
37
|
var e_1, _a;
|
|
37
38
|
// HTTP-ERROR
|
|
@@ -57,9 +58,10 @@ function route_error(request, error) {
|
|
|
57
58
|
})();
|
|
58
59
|
try {
|
|
59
60
|
error.method = request.method;
|
|
60
|
-
error.path =
|
|
61
|
+
error.path =
|
|
62
|
+
(_a = request.path) !== null && _a !== void 0 ? _a : request.routerPath;
|
|
61
63
|
}
|
|
62
|
-
catch (
|
|
64
|
+
catch (_b) { }
|
|
63
65
|
setTimeout(function () {
|
|
64
66
|
var e_2, _a;
|
|
65
67
|
try {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"route_error.js","sourceRoot":"","sources":["../../../src/decorators/internal/route_error.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,yCAA+C;
|
|
1
|
+
{"version":3,"file":"route_error.js","sourceRoot":"","sources":["../../../src/decorators/internal/route_error.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,yCAA+C;AAG/C,6BAAkC;AAElC,iEAAgE;AAEhE,SAAgB,WAAW,CACvB,OAAyC,EACzC,KAAU;;IAEV,KAAK,GAAG,CAAC;;QACL,aAAa;QACb,IAAI,KAAK,YAAY,sBAAa;YAAE,OAAO,KAAK,CAAC;;YAEjD,0BAA0B;YAC1B,KAAiC,IAAA,KAAA,SAAA,mCAAgB,CAAC,MAAM,CAAA,gBAAA;gBAA7C,IAAA,KAAA,mBAAkB,EAAjB,OAAO,QAAA,EAAE,OAAO,QAAA;gBACxB,IAAI,KAAK,YAAY,OAAO;oBAAE,OAAO,OAAO,CAAC,KAAK,CAAC,CAAC;aAAA;;;;;;;;;QAExD,uBAAuB;QACvB,OAAO,KAAK,CAAC;IACjB,CAAC,CAAC,EAAE,CAAC;IAEL,IAAI;QACA,KAAK,CAAC,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;QAC9B,KAAK,CAAC,IAAI;YACN,MAAC,OAA2B,CAAC,IAAI,mCAChC,OAA0B,CAAC,UAAU,CAAC;KAC9C;IAAC,WAAM,GAAE;IAEV,UAAU,CAAC;;;YACP,KAAuB,IAAA,KAAA,SAAA,mCAAgB,CAAC,SAAS,CAAA,gBAAA,4BAAE;gBAA9C,IAAM,QAAQ,WAAA;gBACf,IAAI;oBACA,IAAM,GAAG,GAAuB,QAAQ,CAAC,KAAK,CAAC,CAAC;oBAChD,IAAI,OAAO,GAAG,KAAK,QAAQ,IAAI,OAAO,GAAG,CAAC,KAAK,KAAK,UAAU;wBAC1D,GAAG,CAAC,KAAK,CAAC,cAAO,CAAC,CAAC,CAAC;iBAC3B;gBAAC,WAAM,GAAE;aACb;;;;;;;;;IACL,CAAC,EAAE,CAAC,CAAC,CAAC;IACN,OAAO,IAAA,iBAAU,EAAC,cAAM,OAAA,KAAK,EAAL,CAAK,CAAC,CAAC;AACnC,CAAC;AAjCD,kCAiCC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nestia/core",
|
|
3
|
-
"version": "1.2.
|
|
3
|
+
"version": "1.2.4",
|
|
4
4
|
"description": "Super-fast validation decorators of NestJS",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"typings": "lib/index.d.ts",
|
|
@@ -44,7 +44,7 @@
|
|
|
44
44
|
"raw-body": ">= 2.0.0",
|
|
45
45
|
"reflect-metadata": ">= 0.1.12",
|
|
46
46
|
"rxjs": ">= 6.0.0",
|
|
47
|
-
"typia": "^3.8.
|
|
47
|
+
"typia": "^3.8.9"
|
|
48
48
|
},
|
|
49
49
|
"peerDependencies": {
|
|
50
50
|
"typescript": ">= 4.5.2"
|
|
@@ -2,7 +2,6 @@ import { AesPkcs5, IEncryptionPassword } from "@nestia/fetcher";
|
|
|
2
2
|
import {
|
|
3
3
|
BadRequestException,
|
|
4
4
|
ExecutionContext,
|
|
5
|
-
HttpException,
|
|
6
5
|
createParamDecorator,
|
|
7
6
|
} from "@nestjs/common";
|
|
8
7
|
import type express from "express";
|
|
@@ -15,7 +14,6 @@ import { Singleton } from "../utils/Singleton";
|
|
|
15
14
|
import { ENCRYPTION_METADATA_KEY } from "./internal/EncryptedConstant";
|
|
16
15
|
import { get_text_body } from "./internal/get_text_body";
|
|
17
16
|
import { headers_to_object } from "./internal/headers_to_object";
|
|
18
|
-
import { send_bad_request } from "./internal/send_bad_request";
|
|
19
17
|
import { validate_request_body } from "./internal/validate_request_body";
|
|
20
18
|
|
|
21
19
|
/**
|
|
@@ -51,10 +49,8 @@ export function EncryptedBody<T>(
|
|
|
51
49
|
.switchToHttp()
|
|
52
50
|
.getRequest();
|
|
53
51
|
if (isTextPlain(request.headers["content-type"]) === false)
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
`Request body type is not "text/plain".`,
|
|
57
|
-
),
|
|
52
|
+
throw new BadRequestException(
|
|
53
|
+
`Request body type is not "text/plain".`,
|
|
58
54
|
);
|
|
59
55
|
|
|
60
56
|
const param:
|
|
@@ -82,10 +78,7 @@ export function EncryptedBody<T>(
|
|
|
82
78
|
// PARSE AND VALIDATE DATA
|
|
83
79
|
const data: any = JSON.parse(decrypt(body, password.key, password.iv));
|
|
84
80
|
const error: Error | null = checker(data);
|
|
85
|
-
if (error !== null)
|
|
86
|
-
if (error instanceof HttpException)
|
|
87
|
-
return send_bad_request(context)(error);
|
|
88
|
-
else throw error;
|
|
81
|
+
if (error !== null) throw error;
|
|
89
82
|
return data;
|
|
90
83
|
})();
|
|
91
84
|
}
|
|
@@ -7,7 +7,6 @@ import type express from "express";
|
|
|
7
7
|
import type { FastifyRequest } from "fastify";
|
|
8
8
|
|
|
9
9
|
import { get_text_body } from "./internal/get_text_body";
|
|
10
|
-
import { send_bad_request } from "./internal/send_bad_request";
|
|
11
10
|
|
|
12
11
|
/**
|
|
13
12
|
* Plain body decorator.
|
|
@@ -35,13 +34,11 @@ export const PlainBody: () => ParameterDecorator = createParamDecorator(
|
|
|
35
34
|
const request: express.Request | FastifyRequest = context
|
|
36
35
|
.switchToHttp()
|
|
37
36
|
.getRequest();
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
),
|
|
44
|
-
);
|
|
37
|
+
if (!isTextPlain(request.headers["content-type"]))
|
|
38
|
+
throw new BadRequestException(
|
|
39
|
+
`Request body type is not "text/plain".`,
|
|
40
|
+
);
|
|
41
|
+
return get_text_body(request);
|
|
45
42
|
},
|
|
46
43
|
);
|
|
47
44
|
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import {
|
|
2
2
|
BadRequestException,
|
|
3
3
|
ExecutionContext,
|
|
4
|
-
HttpException,
|
|
5
4
|
createParamDecorator,
|
|
6
5
|
} from "@nestjs/common";
|
|
7
6
|
import type express from "express";
|
|
@@ -10,7 +9,6 @@ import type { FastifyRequest } from "fastify";
|
|
|
10
9
|
import { assert, is, validate } from "typia";
|
|
11
10
|
|
|
12
11
|
import { IRequestBodyValidator } from "../options/IRequestBodyValidator";
|
|
13
|
-
import { send_bad_request } from "./internal/send_bad_request";
|
|
14
12
|
import { validate_request_body } from "./internal/validate_request_body";
|
|
15
13
|
|
|
16
14
|
/**
|
|
@@ -39,17 +37,12 @@ export function TypedBody<T>(
|
|
|
39
37
|
.switchToHttp()
|
|
40
38
|
.getRequest();
|
|
41
39
|
if (isApplicationJson(request.headers["content-type"]) === false)
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
`Request body type is not "application/json".`,
|
|
45
|
-
),
|
|
40
|
+
throw new BadRequestException(
|
|
41
|
+
`Request body type is not "application/json".`,
|
|
46
42
|
);
|
|
47
43
|
|
|
48
44
|
const error: Error | null = checker(request.body);
|
|
49
|
-
if (error !== null)
|
|
50
|
-
if (error instanceof HttpException)
|
|
51
|
-
return send_bad_request(context)(error);
|
|
52
|
-
else throw error;
|
|
45
|
+
if (error !== null) throw error;
|
|
53
46
|
return request.body;
|
|
54
47
|
})();
|
|
55
48
|
}
|
|
@@ -4,8 +4,7 @@ import {
|
|
|
4
4
|
createParamDecorator,
|
|
5
5
|
} from "@nestjs/common";
|
|
6
6
|
import type express from "express";
|
|
7
|
-
|
|
8
|
-
import { send_bad_request } from "./internal/send_bad_request";
|
|
7
|
+
import type { FastifyRequest } from "fastify";
|
|
9
8
|
|
|
10
9
|
/**
|
|
11
10
|
* Type safe URL parameter decorator.
|
|
@@ -43,46 +42,39 @@ export function TypedParam(
|
|
|
43
42
|
nullable?: false | true,
|
|
44
43
|
): ParameterDecorator {
|
|
45
44
|
function TypedParam({}: any, context: ExecutionContext) {
|
|
46
|
-
const request: express.Request = context
|
|
47
|
-
|
|
45
|
+
const request: express.Request | FastifyRequest = context
|
|
46
|
+
.switchToHttp()
|
|
47
|
+
.getRequest();
|
|
48
|
+
const str: string = (request.params as any)[name];
|
|
48
49
|
|
|
49
50
|
if (nullable === true && str === "null") return null;
|
|
50
51
|
else if (type === "boolean") {
|
|
51
52
|
if (str === "true" || str === "1") return true;
|
|
52
53
|
else if (str === "false" || str === "0") return false;
|
|
53
54
|
else
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
`Value of the URL parameter '${name}' is not a boolean.`,
|
|
57
|
-
),
|
|
55
|
+
throw new BadRequestException(
|
|
56
|
+
`Value of the URL parameter '${name}' is not a boolean.`,
|
|
58
57
|
);
|
|
59
58
|
} else if (type === "number") {
|
|
60
59
|
const value: number = Number(str);
|
|
61
60
|
if (isNaN(value))
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
`Value of the URL parameter "${name}" is not a number.`,
|
|
65
|
-
),
|
|
61
|
+
throw new BadRequestException(
|
|
62
|
+
`Value of the URL parameter "${name}" is not a number.`,
|
|
66
63
|
);
|
|
67
64
|
return value;
|
|
68
65
|
} else if (type === "uuid") {
|
|
69
66
|
if (UUID_PATTERN.test(str) === false)
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
`Value of the URL parameter "${name}" is not a valid UUID.`,
|
|
73
|
-
),
|
|
67
|
+
throw new BadRequestException(
|
|
68
|
+
`Value of the URL parameter "${name}" is not a valid UUID.`,
|
|
74
69
|
);
|
|
75
70
|
return str;
|
|
76
71
|
} else if (type === "date") {
|
|
77
72
|
if (DATE_PATTERN.test(str) === false)
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
`Value of the URL parameter "${name}" is not a valid date.`,
|
|
81
|
-
),
|
|
73
|
+
throw new BadRequestException(
|
|
74
|
+
`Value of the URL parameter "${name}" is not a valid date.`,
|
|
82
75
|
);
|
|
83
76
|
return str;
|
|
84
|
-
}
|
|
85
|
-
else return str;
|
|
77
|
+
} else return str;
|
|
86
78
|
}
|
|
87
79
|
(TypedParam as any).nullable = !!nullable;
|
|
88
80
|
(TypedParam as any).type = type;
|
|
@@ -91,4 +83,4 @@ export function TypedParam(
|
|
|
91
83
|
|
|
92
84
|
const UUID_PATTERN =
|
|
93
85
|
/^(?:[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}|00000000-0000-0000-0000-000000000000)$/i;
|
|
94
|
-
const DATE_PATTERN = /^\d{4}-\d{2}-\d{2}$/;
|
|
86
|
+
const DATE_PATTERN = /^\d{4}-\d{2}-\d{2}$/;
|
|
@@ -9,7 +9,6 @@ import type { FastifyRequest } from "fastify";
|
|
|
9
9
|
import typia, { TypeGuardError, assert } from "typia";
|
|
10
10
|
|
|
11
11
|
import { TransformError } from "./internal/TransformError";
|
|
12
|
-
import { send_bad_request } from "./internal/send_bad_request";
|
|
13
12
|
|
|
14
13
|
/**
|
|
15
14
|
* Type safe URL query decorator.
|
|
@@ -42,16 +41,14 @@ export function TypedQuery<T>(
|
|
|
42
41
|
return decoder(params);
|
|
43
42
|
} catch (exp) {
|
|
44
43
|
if (typia.is<TypeGuardError>(exp))
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
}),
|
|
54
|
-
);
|
|
44
|
+
throw new BadRequestException({
|
|
45
|
+
path: exp.path,
|
|
46
|
+
reason: exp.message,
|
|
47
|
+
expected: exp.expected,
|
|
48
|
+
value: exp.value,
|
|
49
|
+
message:
|
|
50
|
+
"Request query parameters are not following the promised type.",
|
|
51
|
+
});
|
|
55
52
|
throw exp;
|
|
56
53
|
}
|
|
57
54
|
})();
|
|
@@ -1,10 +1,14 @@
|
|
|
1
1
|
import { HttpException } from "@nestjs/common";
|
|
2
2
|
import express from "express";
|
|
3
|
+
import type { FastifyRequest } from "fastify";
|
|
3
4
|
import { throwError } from "rxjs";
|
|
4
5
|
|
|
5
6
|
import { ExceptionManager } from "../../utils/ExceptionManager";
|
|
6
7
|
|
|
7
|
-
export function route_error(
|
|
8
|
+
export function route_error(
|
|
9
|
+
request: express.Request | FastifyRequest,
|
|
10
|
+
error: any,
|
|
11
|
+
) {
|
|
8
12
|
error = (() => {
|
|
9
13
|
// HTTP-ERROR
|
|
10
14
|
if (error instanceof HttpException) return error;
|
|
@@ -19,7 +23,9 @@ export function route_error(request: express.Request, error: any) {
|
|
|
19
23
|
|
|
20
24
|
try {
|
|
21
25
|
error.method = request.method;
|
|
22
|
-
error.path =
|
|
26
|
+
error.path =
|
|
27
|
+
(request as express.Request).path ??
|
|
28
|
+
(request as FastifyRequest).routerPath;
|
|
23
29
|
} catch {}
|
|
24
30
|
|
|
25
31
|
setTimeout(() => {
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.send_bad_request = void 0;
|
|
4
|
-
var send_bad_request = function (context) {
|
|
5
|
-
return function (error) {
|
|
6
|
-
var response = context
|
|
7
|
-
.switchToHttp()
|
|
8
|
-
.getResponse();
|
|
9
|
-
response.status(error.getStatus()).send(error.getResponse());
|
|
10
|
-
};
|
|
11
|
-
};
|
|
12
|
-
exports.send_bad_request = send_bad_request;
|
|
13
|
-
//# sourceMappingURL=send_bad_request.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"send_bad_request.js","sourceRoot":"","sources":["../../../src/decorators/internal/send_bad_request.ts"],"names":[],"mappings":";;;AAIO,IAAM,gBAAgB,GACzB,UAAC,OAAyB;IAC1B,OAAA,UAAC,KAA0B;QACvB,IAAM,QAAQ,GAAoC,OAAO;aACpD,YAAY,EAAE;aACd,WAAW,EAAE,CAAC;QACnB,QAAQ,CAAC,MAAM,CAAC,KAAK,CAAC,SAAS,EAAE,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,WAAW,EAAE,CAAC,CAAC;IACjE,CAAC;AALD,CAKC,CAAC;AAPO,QAAA,gBAAgB,oBAOvB"}
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import { BadRequestException, ExecutionContext } from "@nestjs/common";
|
|
2
|
-
import type express from "express";
|
|
3
|
-
import type { FastifyReply } from "fastify";
|
|
4
|
-
|
|
5
|
-
export const send_bad_request =
|
|
6
|
-
(context: ExecutionContext) =>
|
|
7
|
-
(error: BadRequestException): void => {
|
|
8
|
-
const response: express.Response | FastifyReply = context
|
|
9
|
-
.switchToHttp()
|
|
10
|
-
.getResponse();
|
|
11
|
-
response.status(error.getStatus()).send(error.getResponse());
|
|
12
|
-
};
|