@nestia/core 2.0.6 → 2.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/lib/decorators/TypedHeaders.d.ts +2 -1
- package/lib/decorators/TypedHeaders.js +13 -60
- package/lib/decorators/TypedHeaders.js.map +1 -1
- package/lib/decorators/TypedParam.d.ts +1 -8
- package/lib/decorators/TypedParam.js +24 -6
- package/lib/decorators/TypedParam.js.map +1 -1
- package/lib/decorators/TypedQuery.d.ts +2 -1
- package/lib/decorators/TypedQuery.js +13 -76
- package/lib/decorators/TypedQuery.js.map +1 -1
- package/lib/decorators/internal/get_path_and_stringify.d.ts +1 -1
- package/lib/decorators/internal/get_path_and_stringify.js +18 -0
- package/lib/decorators/internal/get_path_and_stringify.js.map +1 -1
- package/lib/decorators/internal/get_text_body.d.ts +1 -3
- package/lib/decorators/internal/get_text_body.js +6 -0
- package/lib/decorators/internal/get_text_body.js.map +1 -1
- package/lib/decorators/internal/headers_to_object.d.ts +1 -3
- package/lib/decorators/internal/headers_to_object.js +3 -0
- package/lib/decorators/internal/headers_to_object.js.map +1 -1
- package/lib/decorators/internal/load_controller.d.ts +1 -5
- package/lib/decorators/internal/load_controller.js +9 -0
- package/lib/decorators/internal/load_controller.js.map +1 -1
- package/lib/decorators/internal/route_error.d.ts +1 -3
- package/lib/decorators/internal/route_error.js +3 -0
- package/lib/decorators/internal/route_error.js.map +1 -1
- package/lib/decorators/internal/validate_request_body.d.ts +1 -1
- package/lib/decorators/internal/validate_request_body.js +6 -6
- package/lib/decorators/internal/validate_request_body.js.map +1 -1
- package/lib/decorators/internal/validate_request_headers.d.ts +3 -0
- package/lib/decorators/internal/validate_request_headers.js +64 -0
- package/lib/decorators/internal/validate_request_headers.js.map +1 -0
- package/lib/decorators/internal/validate_request_query.d.ts +3 -0
- package/lib/decorators/internal/validate_request_query.js +64 -0
- package/lib/decorators/internal/validate_request_query.js.map +1 -0
- package/lib/options/IRequestHeadersValidator.d.ts +16 -0
- package/lib/options/IRequestHeadersValidator.js +3 -0
- package/lib/options/IRequestHeadersValidator.js.map +1 -0
- package/lib/options/IRequestQueryValidator.d.ts +16 -0
- package/lib/options/IRequestQueryValidator.js +3 -0
- package/lib/options/IRequestQueryValidator.js.map +1 -0
- package/lib/programmers/TypedHeadersProgrammer.d.ts +0 -3
- package/lib/programmers/TypedHeadersProgrammer.js +21 -228
- package/lib/programmers/TypedHeadersProgrammer.js.map +1 -1
- package/lib/programmers/TypedParamProgrammer.d.ts +0 -2
- package/lib/programmers/TypedParamProgrammer.js +4 -92
- package/lib/programmers/TypedParamProgrammer.js.map +1 -1
- package/lib/programmers/TypedQueryProgrammer.d.ts +0 -3
- package/lib/programmers/TypedQueryProgrammer.js +22 -183
- package/lib/programmers/TypedQueryProgrammer.js.map +1 -1
- package/package.json +5 -5
- package/src/decorators/TypedHeaders.ts +13 -38
- package/src/decorators/TypedParam.ts +19 -18
- package/src/decorators/TypedQuery.ts +12 -50
- package/src/decorators/internal/get_path_and_stringify.ts +18 -0
- package/src/decorators/internal/get_text_body.ts +6 -0
- package/src/decorators/internal/headers_to_object.ts +3 -0
- package/src/decorators/internal/load_controller.ts +9 -0
- package/src/decorators/internal/route_error.ts +3 -0
- package/src/decorators/internal/validate_request_body.ts +6 -6
- package/src/decorators/internal/validate_request_headers.ts +73 -0
- package/src/decorators/internal/validate_request_query.ts +59 -0
- package/src/options/IRequestHeadersValidator.ts +22 -0
- package/src/options/IRequestQueryValidator.ts +20 -0
- package/src/programmers/TypedHeadersProgrammer.ts +40 -285
- package/src/programmers/TypedParamProgrammer.ts +7 -138
- package/src/programmers/TypedQueryProgrammer.ts +38 -251
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"TypedParamProgrammer.js","sourceRoot":"","sources":["../../src/programmers/TypedParamProgrammer.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"TypedParamProgrammer.js","sourceRoot":"","sources":["../../src/programmers/TypedParamProgrammer.ts"],"names":[],"mappings":";;;;;;;;;;;;;;AAEA,8FAA6F;AAI7F,IAAiB,oBAAoB,CAkBpC;AAlBD,WAAiB,oBAAoB;IACpB,6BAAQ,GACjB,UAAC,OAAgC;QACjC,OAAA,UAAC,MAAiC;YAClC,OAAA,UAAC,UAAoC;gBACrC,OAAA,UAAC,IAAa;oBACV,4BAA4B;oBAC5B,IAAI,UAAU,CAAC,MAAM,KAAK,CAAC;wBAAE,OAAO,UAAU,CAAC;oBAC/C,OAAO;wBACH,UAAU,CAAC,CAAC,CAAC;wBACb,iDAAuB,CAAC,KAAK,uBACtB,OAAO,KACV,OAAO,EAAE;gCACL,OAAO,EAAE,IAAI;6BAChB,IACH,CAAC,MAAM,CAAC,CAAC,IAAI,CAAC;qBACnB,CAAC;gBACN,CAAC;YAZD,CAYC;QAbD,CAaC;IAdD,CAcC,CAAC;AACV,CAAC,EAlBgB,oBAAoB,oCAApB,oBAAoB,QAkBpC"}
|
|
@@ -1,8 +1,5 @@
|
|
|
1
1
|
import ts from "typescript";
|
|
2
|
-
import { MetadataFactory } from "typia/lib/factories/MetadataFactory";
|
|
3
|
-
import { Metadata } from "typia/lib/schemas/metadata/Metadata";
|
|
4
2
|
import { INestiaTransformProject } from "../options/INestiaTransformProject";
|
|
5
3
|
export declare namespace TypedQueryProgrammer {
|
|
6
4
|
const generate: (project: INestiaTransformProject) => (modulo: ts.LeftHandSideExpression) => (type: ts.Type) => ts.Expression;
|
|
7
|
-
const validate: (meta: Metadata, explore: MetadataFactory.IExplore) => string[];
|
|
8
5
|
}
|
|
@@ -10,201 +10,40 @@ var __assign = (this && this.__assign) || function () {
|
|
|
10
10
|
};
|
|
11
11
|
return __assign.apply(this, arguments);
|
|
12
12
|
};
|
|
13
|
-
var __read = (this && this.__read) || function (o, n) {
|
|
14
|
-
var m = typeof Symbol === "function" && o[Symbol.iterator];
|
|
15
|
-
if (!m) return o;
|
|
16
|
-
var i = m.call(o), r, ar = [], e;
|
|
17
|
-
try {
|
|
18
|
-
while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
|
|
19
|
-
}
|
|
20
|
-
catch (error) { e = { error: error }; }
|
|
21
|
-
finally {
|
|
22
|
-
try {
|
|
23
|
-
if (r && !r.done && (m = i["return"])) m.call(i);
|
|
24
|
-
}
|
|
25
|
-
finally { if (e) throw e.error; }
|
|
26
|
-
}
|
|
27
|
-
return ar;
|
|
28
|
-
};
|
|
29
|
-
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
30
|
-
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
|
|
31
|
-
if (ar || !(i in from)) {
|
|
32
|
-
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
|
|
33
|
-
ar[i] = from[i];
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
return to.concat(ar || Array.prototype.slice.call(from));
|
|
37
|
-
};
|
|
38
13
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
39
14
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
40
15
|
};
|
|
41
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
42
17
|
exports.TypedQueryProgrammer = void 0;
|
|
43
18
|
var typescript_1 = __importDefault(require("typescript"));
|
|
44
|
-
var
|
|
45
|
-
var
|
|
46
|
-
var
|
|
47
|
-
var StatementFactory_1 = require("typia/lib/factories/StatementFactory");
|
|
48
|
-
var AssertProgrammer_1 = require("typia/lib/programmers/AssertProgrammer");
|
|
49
|
-
var FunctionImporeter_1 = require("typia/lib/programmers/helpers/FunctionImporeter");
|
|
50
|
-
var MetadataArray_1 = require("typia/lib/schemas/metadata/MetadataArray");
|
|
51
|
-
var TransformerError_1 = require("typia/lib/transformers/TransformerError");
|
|
52
|
-
var Escaper_1 = require("typia/lib/utils/Escaper");
|
|
53
|
-
var CoreMetadataUtil_1 = require("./internal/CoreMetadataUtil");
|
|
19
|
+
var HttpAssertQueryProgrammer_1 = require("typia/lib/programmers/http/HttpAssertQueryProgrammer");
|
|
20
|
+
var HttpIsQueryProgrammer_1 = require("typia/lib/programmers/http/HttpIsQueryProgrammer");
|
|
21
|
+
var HttpValidateQueryProgrammer_1 = require("typia/lib/programmers/http/HttpValidateQueryProgrammer");
|
|
54
22
|
var TypedQueryProgrammer;
|
|
55
23
|
(function (TypedQueryProgrammer) {
|
|
56
24
|
TypedQueryProgrammer.generate = function (project) {
|
|
57
25
|
return function (modulo) {
|
|
58
26
|
return function (type) {
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
if (meta.nullable === true)
|
|
72
|
-
insert("query parameters cannot be null.");
|
|
73
|
-
if (meta.isRequired() === false)
|
|
74
|
-
insert("query parameters cannot be undefined.");
|
|
75
|
-
}
|
|
76
|
-
else if (explore.nested !== null &&
|
|
77
|
-
explore.nested instanceof MetadataArray_1.MetadataArray) {
|
|
78
|
-
var atomics = CoreMetadataUtil_1.CoreMetadataUtil.atomics(meta);
|
|
79
|
-
var expected = meta.atomics.length +
|
|
80
|
-
meta.templates.length +
|
|
81
|
-
meta.constants
|
|
82
|
-
.map(function (c) { return c.values.length; })
|
|
83
|
-
.reduce(function (a, b) { return a + b; }, 0);
|
|
84
|
-
if (atomics.size > 1)
|
|
85
|
-
insert("union type is not allowed in array.");
|
|
86
|
-
if (meta.nullable)
|
|
87
|
-
insert("nullable type is not allowed in array.");
|
|
88
|
-
if (meta.isRequired() === false)
|
|
89
|
-
insert("optional type is not allowed in array.");
|
|
90
|
-
if (meta.size() !== expected)
|
|
91
|
-
insert("only atomic or constant types are allowed in array.");
|
|
92
|
-
}
|
|
93
|
-
else if (explore.object && explore.property !== null) {
|
|
94
|
-
//----
|
|
95
|
-
// COMMON
|
|
96
|
-
//----
|
|
97
|
-
// PROPERTY MUST BE SOLE
|
|
98
|
-
if (typeof explore.property === "object")
|
|
99
|
-
insert("dynamic property is not allowed.");
|
|
100
|
-
// DO NOT ALLOW TUPLE TYPE
|
|
101
|
-
if (meta.tuples.length)
|
|
102
|
-
insert("tuple type is not allowed.");
|
|
103
|
-
// DO NOT ALLOW UNION TYPE
|
|
104
|
-
if (CoreMetadataUtil_1.CoreMetadataUtil.isUnion(meta))
|
|
105
|
-
insert("union type is not allowed.");
|
|
106
|
-
// DO NOT ALLOW NESTED OBJECT
|
|
107
|
-
if (meta.objects.length ||
|
|
108
|
-
meta.sets.length ||
|
|
109
|
-
meta.maps.length ||
|
|
110
|
-
meta.natives.length)
|
|
111
|
-
insert("nested object type is not allowed.");
|
|
112
|
-
//----
|
|
113
|
-
// ARRAY CASES
|
|
114
|
-
//----
|
|
115
|
-
var isArray = meta.arrays.length > 1 || meta.tuples.length > 1;
|
|
116
|
-
// ARRAY TYPE MUST BE REQUIRED
|
|
117
|
-
if (isArray && meta.isRequired() === false)
|
|
118
|
-
insert("optional type is not allowed when array.");
|
|
119
|
-
// SET-COOKIE MUST BE ARRAY
|
|
120
|
-
if (explore.property === "set-cookie" && !isArray)
|
|
121
|
-
insert("set-cookie property must be array.");
|
|
122
|
-
}
|
|
123
|
-
return errors;
|
|
124
|
-
};
|
|
125
|
-
var getObject = function (checker) {
|
|
126
|
-
return function (type) {
|
|
127
|
-
var collection = new MetadataCollection_1.MetadataCollection();
|
|
128
|
-
var result = MetadataFactory_1.MetadataFactory.analyze(checker)({
|
|
129
|
-
escape: false,
|
|
130
|
-
constant: true,
|
|
131
|
-
absorb: true,
|
|
132
|
-
validate: TypedQueryProgrammer.validate,
|
|
133
|
-
})(collection)(type);
|
|
134
|
-
if (result.success === false)
|
|
135
|
-
throw TransformerError_1.TransformerError.from("@core.nestia.TypedHeaders")(result.errors);
|
|
136
|
-
return result.data.objects[0];
|
|
137
|
-
};
|
|
138
|
-
};
|
|
139
|
-
var decode = function (project, modulo) {
|
|
140
|
-
return function (type, object) {
|
|
141
|
-
return typescript_1.default.factory.createArrowFunction(undefined, undefined, [IdentifierFactory_1.IdentifierFactory.parameter("input")], undefined, undefined, decode_object(project, modulo)(type, object));
|
|
142
|
-
};
|
|
143
|
-
};
|
|
144
|
-
var decode_object = function (project, modulo) {
|
|
145
|
-
return function (type, object) {
|
|
146
|
-
var assert = AssertProgrammer_1.AssertProgrammer.write(__assign(__assign({}, project), { options: {
|
|
147
|
-
numeric: true,
|
|
148
|
-
finite: true,
|
|
149
|
-
} }))(modulo)(false)(type);
|
|
150
|
-
var output = typescript_1.default.factory.createIdentifier("output");
|
|
151
|
-
var importer = new FunctionImporeter_1.FunctionImporter("TypedQuery");
|
|
152
|
-
var optionalArrays = [];
|
|
153
|
-
var statements = __spreadArray(__spreadArray([
|
|
154
|
-
StatementFactory_1.StatementFactory.constant("output", typescript_1.default.factory.createObjectLiteralExpression(object.properties.map(function (prop) {
|
|
155
|
-
if (!prop.value.isRequired() &&
|
|
156
|
-
prop.value.arrays.length +
|
|
157
|
-
prop.value.tuples.length >
|
|
158
|
-
0)
|
|
159
|
-
optionalArrays.push(prop.key.constants[0].values[0]);
|
|
160
|
-
return decode_regular_property(importer)(prop);
|
|
161
|
-
}), true))
|
|
162
|
-
], __read(optionalArrays.map(function (key) {
|
|
163
|
-
var access = IdentifierFactory_1.IdentifierFactory.access(output)(key);
|
|
164
|
-
return typescript_1.default.factory.createIfStatement(typescript_1.default.factory.createStrictEquality(typescript_1.default.factory.createNumericLiteral(0), IdentifierFactory_1.IdentifierFactory.access(access)("length")), typescript_1.default.factory.createExpressionStatement(typescript_1.default.factory.createDeleteExpression(access)));
|
|
165
|
-
})), false), [
|
|
166
|
-
typescript_1.default.factory.createReturnStatement(typescript_1.default.factory.createCallExpression(assert, undefined, [
|
|
167
|
-
output,
|
|
168
|
-
])),
|
|
169
|
-
], false);
|
|
170
|
-
return typescript_1.default.factory.createBlock(__spreadArray(__spreadArray([], __read(importer.declare(modulo)), false), __read(statements), false), true);
|
|
171
|
-
};
|
|
172
|
-
};
|
|
173
|
-
var decode_regular_property = function (importer) {
|
|
174
|
-
return function (property) {
|
|
175
|
-
var key = property.key.constants[0].values[0];
|
|
176
|
-
var value = property.value;
|
|
177
|
-
var _a = __read(value.atomics
|
|
178
|
-
.length
|
|
179
|
-
? [value.atomics[0].type, false]
|
|
180
|
-
: value.constants.length
|
|
181
|
-
? [value.constants[0].type, false]
|
|
182
|
-
: (function () {
|
|
183
|
-
var _a, _b;
|
|
184
|
-
var meta = (_b = (_a = value.arrays[0]) === null || _a === void 0 ? void 0 : _a.type.value) !== null && _b !== void 0 ? _b : value.tuples[0].type.elements[0];
|
|
185
|
-
return meta.atomics.length
|
|
186
|
-
? [meta.atomics[0].type, true]
|
|
187
|
-
: [meta.constants[0].type, true];
|
|
188
|
-
})(), 2), type = _a[0], isArray = _a[1];
|
|
189
|
-
return typescript_1.default.factory.createPropertyAssignment(Escaper_1.Escaper.variable(key)
|
|
190
|
-
? key
|
|
191
|
-
: typescript_1.default.factory.createStringLiteral(key), isArray
|
|
192
|
-
? typescript_1.default.factory.createCallExpression(IdentifierFactory_1.IdentifierFactory.access(typescript_1.default.factory.createCallExpression(typescript_1.default.factory.createIdentifier("input.getAll"), undefined, [typescript_1.default.factory.createStringLiteral(key)]))("map"), undefined, [
|
|
193
|
-
typescript_1.default.factory.createArrowFunction(undefined, undefined, [IdentifierFactory_1.IdentifierFactory.parameter("elem")], undefined, undefined, decode_value(importer)(type)(false)(typescript_1.default.factory.createIdentifier("elem"))),
|
|
194
|
-
])
|
|
195
|
-
: decode_value(importer)(type)(value.nullable === false &&
|
|
196
|
-
value.isRequired() === false)(typescript_1.default.factory.createCallExpression(typescript_1.default.factory.createIdentifier("input.get"), undefined, [typescript_1.default.factory.createStringLiteral(key)])));
|
|
197
|
-
};
|
|
198
|
-
};
|
|
199
|
-
var decode_value = function (importer) {
|
|
200
|
-
return function (type) {
|
|
201
|
-
return function (onlyUndefindable) {
|
|
202
|
-
return function (value) {
|
|
203
|
-
var call = typescript_1.default.factory.createCallExpression(importer.use(type), undefined, [value]);
|
|
204
|
-
return onlyUndefindable
|
|
205
|
-
? typescript_1.default.factory.createBinaryExpression(call, typescript_1.default.factory.createToken(typescript_1.default.SyntaxKind.QuestionQuestionToken), typescript_1.default.factory.createIdentifier("undefined"))
|
|
206
|
-
: call;
|
|
27
|
+
// GENERATE VALIDATION PLAN
|
|
28
|
+
var parameter = function (key) {
|
|
29
|
+
return function (programmer) {
|
|
30
|
+
return typescript_1.default.factory.createObjectLiteralExpression([
|
|
31
|
+
typescript_1.default.factory.createPropertyAssignment(typescript_1.default.factory.createIdentifier("type"), typescript_1.default.factory.createStringLiteral(key)),
|
|
32
|
+
typescript_1.default.factory.createPropertyAssignment(typescript_1.default.factory.createIdentifier(key), programmer(__assign(__assign({}, project), { options: {
|
|
33
|
+
numeric: false,
|
|
34
|
+
finite: false,
|
|
35
|
+
functional: false,
|
|
36
|
+
} }))(modulo)(type)),
|
|
37
|
+
]);
|
|
38
|
+
};
|
|
207
39
|
};
|
|
40
|
+
// RETURNS
|
|
41
|
+
var category = project.options.validate;
|
|
42
|
+
if (category === "is" || category === "equals")
|
|
43
|
+
return parameter("is")(HttpIsQueryProgrammer_1.HttpIsQueryProgrammer.write);
|
|
44
|
+
else if (category === "validate" || category === "validateEquals")
|
|
45
|
+
return parameter("validate")(HttpValidateQueryProgrammer_1.HttpValidateQueryProgrammer.write);
|
|
46
|
+
return parameter("assert")(HttpAssertQueryProgrammer_1.HttpAssertQueryProgrammer.write);
|
|
208
47
|
};
|
|
209
48
|
};
|
|
210
49
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"TypedQueryProgrammer.js","sourceRoot":"","sources":["../../src/programmers/TypedQueryProgrammer.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"TypedQueryProgrammer.js","sourceRoot":"","sources":["../../src/programmers/TypedQueryProgrammer.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;AAAA,0DAA4B;AAE5B,kGAAiG;AACjG,0FAAyF;AACzF,sGAAqG;AAMrG,IAAiB,oBAAoB,CAyCpC;AAzCD,WAAiB,oBAAoB;IACpB,6BAAQ,GACjB,UAAC,OAAgC;QACjC,OAAA,UAAC,MAAiC;YAClC,OAAA,UAAC,IAAa;gBACV,2BAA2B;gBAC3B,IAAM,SAAS,GACX,UAAC,GAAwC;oBACzC,OAAA,UACI,UAIwC;wBAExC,OAAA,oBAAE,CAAC,OAAO,CAAC,6BAA6B,CAAC;4BACrC,oBAAE,CAAC,OAAO,CAAC,wBAAwB,CAC/B,oBAAE,CAAC,OAAO,CAAC,gBAAgB,CAAC,MAAM,CAAC,EACnC,oBAAE,CAAC,OAAO,CAAC,mBAAmB,CAAC,GAAG,CAAC,CACtC;4BACD,oBAAE,CAAC,OAAO,CAAC,wBAAwB,CAC/B,oBAAE,CAAC,OAAO,CAAC,gBAAgB,CAAC,GAAG,CAAC,EAChC,UAAU,uBACH,OAAO,KACV,OAAO,EAAE;oCACL,OAAO,EAAE,KAAK;oCACd,MAAM,EAAE,KAAK;oCACb,UAAU,EAAE,KAAK;iCACpB,IACH,CAAC,MAAM,CAAC,CAAC,IAAI,CAAC,CACnB;yBACJ,CAAC;oBAhBF,CAgBE;gBAvBN,CAuBM,CAAC;gBAEX,UAAU;gBACV,IAAM,QAAQ,GAAG,OAAO,CAAC,OAAO,CAAC,QAAQ,CAAC;gBAC1C,IAAI,QAAQ,KAAK,IAAI,IAAI,QAAQ,KAAK,QAAQ;oBAC1C,OAAO,SAAS,CAAC,IAAI,CAAC,CAAC,6CAAqB,CAAC,KAAK,CAAC,CAAC;qBACnD,IAAI,QAAQ,KAAK,UAAU,IAAI,QAAQ,KAAK,gBAAgB;oBAC7D,OAAO,SAAS,CAAC,UAAU,CAAC,CAAC,yDAA2B,CAAC,KAAK,CAAC,CAAC;gBACpE,OAAO,SAAS,CAAC,QAAQ,CAAC,CAAC,qDAAyB,CAAC,KAAK,CAAC,CAAC;YAChE,CAAC;QApCD,CAoCC;IArCD,CAqCC,CAAC;AACV,CAAC,EAzCgB,oBAAoB,oCAApB,oBAAoB,QAyCpC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nestia/core",
|
|
3
|
-
"version": "2.0
|
|
3
|
+
"version": "2.1.0",
|
|
4
4
|
"description": "Super-fast validation decorators of NestJS",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"typings": "lib/index.d.ts",
|
|
@@ -34,7 +34,7 @@
|
|
|
34
34
|
},
|
|
35
35
|
"homepage": "https://nestia.io",
|
|
36
36
|
"dependencies": {
|
|
37
|
-
"@nestia/fetcher": "^2.0
|
|
37
|
+
"@nestia/fetcher": "^2.1.0",
|
|
38
38
|
"@nestjs/common": ">= 7.0.1",
|
|
39
39
|
"@nestjs/core": ">= 7.0.1",
|
|
40
40
|
"@nestjs/platform-express": ">= 7.0.1",
|
|
@@ -44,10 +44,10 @@
|
|
|
44
44
|
"raw-body": ">= 2.0.0",
|
|
45
45
|
"reflect-metadata": ">= 0.1.12",
|
|
46
46
|
"rxjs": ">= 6.0.0",
|
|
47
|
-
"typia": "^5.
|
|
47
|
+
"typia": "^5.1.1"
|
|
48
48
|
},
|
|
49
49
|
"peerDependencies": {
|
|
50
|
-
"@nestia/fetcher": ">=2.0
|
|
50
|
+
"@nestia/fetcher": ">=2.1.0",
|
|
51
51
|
"@nestjs/common": ">=7.0.1",
|
|
52
52
|
"@nestjs/core": ">=7.0.1",
|
|
53
53
|
"@nestjs/platform-express": ">=7.0.1",
|
|
@@ -56,7 +56,7 @@
|
|
|
56
56
|
"reflect-metadata": ">=0.1.12",
|
|
57
57
|
"rxjs": ">=6.0.0",
|
|
58
58
|
"typescript": ">=4.8.0",
|
|
59
|
-
"typia": ">=5.
|
|
59
|
+
"typia": ">=5.1.1 <6.0.0"
|
|
60
60
|
},
|
|
61
61
|
"devDependencies": {
|
|
62
62
|
"@trivago/prettier-plugin-sort-imports": "^4.0.0",
|
|
@@ -1,14 +1,11 @@
|
|
|
1
|
-
import {
|
|
2
|
-
BadRequestException,
|
|
3
|
-
ExecutionContext,
|
|
4
|
-
createParamDecorator,
|
|
5
|
-
} from "@nestjs/common";
|
|
1
|
+
import { ExecutionContext, createParamDecorator } from "@nestjs/common";
|
|
6
2
|
import type express from "express";
|
|
7
3
|
import type { FastifyRequest } from "fastify";
|
|
8
4
|
|
|
9
|
-
import typia
|
|
5
|
+
import typia from "typia";
|
|
10
6
|
|
|
11
|
-
import {
|
|
7
|
+
import { IRequestHeadersValidator } from "../options/IRequestHeadersValidator";
|
|
8
|
+
import { validate_request_headers } from "./internal/validate_request_headers";
|
|
12
9
|
|
|
13
10
|
/**
|
|
14
11
|
* Type safe HTTP headers decorator.
|
|
@@ -52,10 +49,9 @@ import { NoTransformConfigureError } from "./internal/NoTransformConfigureError"
|
|
|
52
49
|
* @author Jeongho Nam - https://github.com/samchon
|
|
53
50
|
*/
|
|
54
51
|
export function TypedHeaders<T extends object>(
|
|
55
|
-
|
|
52
|
+
validator?: IRequestHeadersValidator<T>,
|
|
56
53
|
): ParameterDecorator {
|
|
57
|
-
|
|
58
|
-
|
|
54
|
+
const checker = validate_request_headers(validator);
|
|
59
55
|
return createParamDecorator(function TypedHeaders(
|
|
60
56
|
_unknown: any,
|
|
61
57
|
context: ExecutionContext,
|
|
@@ -63,33 +59,12 @@ export function TypedHeaders<T extends object>(
|
|
|
63
59
|
const request: express.Request | FastifyRequest = context
|
|
64
60
|
.switchToHttp()
|
|
65
61
|
.getRequest();
|
|
66
|
-
try {
|
|
67
|
-
return decoder(request.headers);
|
|
68
|
-
} catch (exp) {
|
|
69
|
-
if (typia.is<TypeGuardError>(exp))
|
|
70
|
-
throw new BadRequestException({
|
|
71
|
-
path: exp.path,
|
|
72
|
-
reason: exp.message,
|
|
73
|
-
expected: exp.expected,
|
|
74
|
-
value: exp.value,
|
|
75
|
-
message:
|
|
76
|
-
"Request query parameters are not following the promised type.",
|
|
77
|
-
});
|
|
78
|
-
throw exp;
|
|
79
|
-
}
|
|
80
|
-
})();
|
|
81
|
-
}
|
|
82
62
|
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
export const boolean = (value: string | undefined) =>
|
|
88
|
-
value !== undefined ? value === "true" : undefined;
|
|
89
|
-
export const bigint = (value: string | undefined) =>
|
|
90
|
-
value !== undefined ? BigInt(value) : undefined;
|
|
91
|
-
export const number = (value: string | undefined) =>
|
|
92
|
-
value !== undefined ? Number(value) : undefined;
|
|
93
|
-
export const string = (value: string | undefined) => value;
|
|
63
|
+
const output: T | Error = checker(request.headers);
|
|
64
|
+
if (output instanceof Error) throw output;
|
|
65
|
+
return output;
|
|
66
|
+
})();
|
|
94
67
|
}
|
|
95
|
-
Object.assign(TypedHeaders,
|
|
68
|
+
Object.assign(TypedHeaders, typia.http.assertHeaders);
|
|
69
|
+
Object.assign(TypedHeaders, typia.http.isHeaders);
|
|
70
|
+
Object.assign(TypedHeaders, typia.http.validateHeaders);
|
|
@@ -6,6 +6,8 @@ import {
|
|
|
6
6
|
import type express from "express";
|
|
7
7
|
import type { FastifyRequest } from "fastify";
|
|
8
8
|
|
|
9
|
+
import typia, { TypeGuardError } from "typia";
|
|
10
|
+
|
|
9
11
|
import { NoTransformConfigureError } from "./internal/NoTransformConfigureError";
|
|
10
12
|
|
|
11
13
|
/**
|
|
@@ -32,11 +34,11 @@ import { NoTransformConfigureError } from "./internal/NoTransformConfigureError"
|
|
|
32
34
|
*
|
|
33
35
|
* @author Jeongho Nam - https://github.com/samchon
|
|
34
36
|
*/
|
|
35
|
-
export function TypedParam<T>(
|
|
37
|
+
export function TypedParam<T extends boolean | bigint | number | string | null>(
|
|
36
38
|
name: string,
|
|
37
|
-
|
|
39
|
+
assert?: (value: string) => T,
|
|
38
40
|
): ParameterDecorator {
|
|
39
|
-
if (
|
|
41
|
+
if (assert === undefined) throw NoTransformConfigureError("TypedParam");
|
|
40
42
|
|
|
41
43
|
return createParamDecorator(function TypedParam(
|
|
42
44
|
{}: any,
|
|
@@ -46,20 +48,19 @@ export function TypedParam<T>(
|
|
|
46
48
|
.switchToHttp()
|
|
47
49
|
.getRequest();
|
|
48
50
|
const str: string = (request.params as any)[name];
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
51
|
+
try {
|
|
52
|
+
return assert(str);
|
|
53
|
+
} catch (exp) {
|
|
54
|
+
if (typia.is<TypeGuardError>(exp))
|
|
55
|
+
throw new BadRequestException({
|
|
56
|
+
path: exp.path,
|
|
57
|
+
reason: exp.message,
|
|
58
|
+
expected: exp.expected,
|
|
59
|
+
value: exp.value,
|
|
60
|
+
message: `Invalid URL parameter value on "${name}".`,
|
|
61
|
+
});
|
|
62
|
+
throw exp;
|
|
63
|
+
}
|
|
57
64
|
})(name);
|
|
58
65
|
}
|
|
59
|
-
|
|
60
|
-
export interface IProps<T> {
|
|
61
|
-
type: string;
|
|
62
|
-
cast: (value: string) => T;
|
|
63
|
-
is: (value: T) => boolean;
|
|
64
|
-
}
|
|
65
|
-
}
|
|
66
|
+
Object.assign(TypedParam, typia.http.parameter);
|
|
@@ -1,14 +1,11 @@
|
|
|
1
|
-
import {
|
|
2
|
-
BadRequestException,
|
|
3
|
-
ExecutionContext,
|
|
4
|
-
createParamDecorator,
|
|
5
|
-
} from "@nestjs/common";
|
|
1
|
+
import { ExecutionContext, createParamDecorator } from "@nestjs/common";
|
|
6
2
|
import type express from "express";
|
|
7
3
|
import type { FastifyRequest } from "fastify";
|
|
8
4
|
|
|
9
|
-
import typia
|
|
5
|
+
import typia from "typia";
|
|
10
6
|
|
|
11
|
-
import {
|
|
7
|
+
import { IRequestQueryValidator } from "../options/IRequestQueryValidator";
|
|
8
|
+
import { validate_request_query } from "./internal/validate_request_query";
|
|
12
9
|
|
|
13
10
|
/**
|
|
14
11
|
* Type safe URL query decorator.
|
|
@@ -30,10 +27,9 @@ import { NoTransformConfigureError } from "./internal/NoTransformConfigureError"
|
|
|
30
27
|
* @author Jeongho Nam - https://github.com/samchon
|
|
31
28
|
*/
|
|
32
29
|
export function TypedQuery<T extends object>(
|
|
33
|
-
|
|
30
|
+
validator?: IRequestQueryValidator<T>,
|
|
34
31
|
): ParameterDecorator {
|
|
35
|
-
|
|
36
|
-
|
|
32
|
+
const checker = validate_request_query(validator);
|
|
37
33
|
return createParamDecorator(function TypedQuery(
|
|
38
34
|
_unknown: any,
|
|
39
35
|
context: ExecutionContext,
|
|
@@ -43,48 +39,14 @@ export function TypedQuery<T extends object>(
|
|
|
43
39
|
.getRequest();
|
|
44
40
|
const params: URLSearchParams = new URLSearchParams(tail(request.url));
|
|
45
41
|
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
if (typia.is<TypeGuardError>(exp))
|
|
50
|
-
throw new BadRequestException({
|
|
51
|
-
path: exp.path,
|
|
52
|
-
reason: exp.message,
|
|
53
|
-
expected: exp.expected,
|
|
54
|
-
value: exp.value,
|
|
55
|
-
message:
|
|
56
|
-
"Request query parameters are not following the promised type.",
|
|
57
|
-
});
|
|
58
|
-
throw exp;
|
|
59
|
-
}
|
|
42
|
+
const output: T | Error = checker(params);
|
|
43
|
+
if (output instanceof Error) throw output;
|
|
44
|
+
return output;
|
|
60
45
|
})();
|
|
61
46
|
}
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
*/
|
|
66
|
-
export namespace TypedQuery {
|
|
67
|
-
export function boolean(str: string | null): boolean | null | undefined {
|
|
68
|
-
if (str === null) return undefined;
|
|
69
|
-
else if (str === "null") return null;
|
|
70
|
-
else if (str.length === 0) return true;
|
|
71
|
-
return str === "true" || str === "1"
|
|
72
|
-
? true
|
|
73
|
-
: str === "false" || str === "0"
|
|
74
|
-
? false
|
|
75
|
-
: (str as any); // wrong type
|
|
76
|
-
}
|
|
77
|
-
export function number(str: string | null): number | null | undefined {
|
|
78
|
-
return str?.length ? (str === "null" ? null : Number(str)) : undefined;
|
|
79
|
-
}
|
|
80
|
-
export function bigint(str: string | null): bigint | null | undefined {
|
|
81
|
-
return str?.length ? (str === "null" ? null : BigInt(str)) : undefined;
|
|
82
|
-
}
|
|
83
|
-
export function string(str: string | null): string | null | undefined {
|
|
84
|
-
return str === null ? undefined : str === "null" ? null : str;
|
|
85
|
-
}
|
|
86
|
-
}
|
|
87
|
-
Object.assign(TypedQuery, assert);
|
|
47
|
+
Object.assign(TypedQuery, typia.http.assertQuery);
|
|
48
|
+
Object.assign(TypedQuery, typia.http.isQuery);
|
|
49
|
+
Object.assign(TypedQuery, typia.http.validateQuery);
|
|
88
50
|
|
|
89
51
|
/**
|
|
90
52
|
* @internal
|
|
@@ -5,6 +5,9 @@ import typia, { IValidation, TypeGuardError } from "typia";
|
|
|
5
5
|
import { IResponseBodyStringifier } from "../../options/IResponseBodyStringifier";
|
|
6
6
|
import { NoTransformConfigureError } from "./NoTransformConfigureError";
|
|
7
7
|
|
|
8
|
+
/**
|
|
9
|
+
* @internal
|
|
10
|
+
*/
|
|
8
11
|
export const get_path_and_stringify =
|
|
9
12
|
(method: string) =>
|
|
10
13
|
(
|
|
@@ -21,6 +24,9 @@ export const get_path_and_stringify =
|
|
|
21
24
|
return [path ?? undefined, take(method)(functor)];
|
|
22
25
|
};
|
|
23
26
|
|
|
27
|
+
/**
|
|
28
|
+
* @internal
|
|
29
|
+
*/
|
|
24
30
|
const take =
|
|
25
31
|
(method: string) =>
|
|
26
32
|
<T>(functor?: IResponseBodyStringifier<T> | null) => {
|
|
@@ -35,6 +41,9 @@ const take =
|
|
|
35
41
|
);
|
|
36
42
|
};
|
|
37
43
|
|
|
44
|
+
/**
|
|
45
|
+
* @internal
|
|
46
|
+
*/
|
|
38
47
|
const assert =
|
|
39
48
|
<T>(closure: (data: T) => string) =>
|
|
40
49
|
(data: T) => {
|
|
@@ -53,6 +62,9 @@ const assert =
|
|
|
53
62
|
}
|
|
54
63
|
};
|
|
55
64
|
|
|
65
|
+
/**
|
|
66
|
+
* @internal
|
|
67
|
+
*/
|
|
56
68
|
const is =
|
|
57
69
|
<T>(closure: (data: T) => string | null) =>
|
|
58
70
|
(data: T) => {
|
|
@@ -61,6 +73,9 @@ const is =
|
|
|
61
73
|
return result;
|
|
62
74
|
};
|
|
63
75
|
|
|
76
|
+
/**
|
|
77
|
+
* @internal
|
|
78
|
+
*/
|
|
64
79
|
const validate =
|
|
65
80
|
<T>(closure: (data: T) => IValidation<string>) =>
|
|
66
81
|
(data: T) => {
|
|
@@ -73,4 +88,7 @@ const validate =
|
|
|
73
88
|
return result.data;
|
|
74
89
|
};
|
|
75
90
|
|
|
91
|
+
/**
|
|
92
|
+
* @internal
|
|
93
|
+
*/
|
|
76
94
|
const MESSAGE = "Response body data is not following the promised type.";
|
|
@@ -2,6 +2,9 @@ import type express from "express";
|
|
|
2
2
|
import type { FastifyRequest } from "fastify";
|
|
3
3
|
import raw from "raw-body";
|
|
4
4
|
|
|
5
|
+
/**
|
|
6
|
+
* @internal
|
|
7
|
+
*/
|
|
5
8
|
export const get_text_body = async (
|
|
6
9
|
request: express.Request | FastifyRequest,
|
|
7
10
|
): Promise<string> =>
|
|
@@ -9,6 +12,9 @@ export const get_text_body = async (
|
|
|
9
12
|
? (await raw(request)).toString("utf8")
|
|
10
13
|
: (request.body as string);
|
|
11
14
|
|
|
15
|
+
/**
|
|
16
|
+
* @internal
|
|
17
|
+
*/
|
|
12
18
|
const isExpressRequest = (
|
|
13
19
|
request: express.Request | FastifyRequest,
|
|
14
20
|
): request is express.Request => (request as express.Request).app !== undefined;
|
|
@@ -3,6 +3,9 @@ import is_ts_node from "detect-ts-node";
|
|
|
3
3
|
import { Creator } from "../../typings/Creator";
|
|
4
4
|
import { SourceFinder } from "../../utils/SourceFinder";
|
|
5
5
|
|
|
6
|
+
/**
|
|
7
|
+
* @internal
|
|
8
|
+
*/
|
|
6
9
|
export const load_controllers = async (
|
|
7
10
|
path: string | string[] | { include: string[]; exclude?: string[] },
|
|
8
11
|
): Promise<Creator<object>[]> => {
|
|
@@ -26,6 +29,9 @@ export const load_controllers = async (
|
|
|
26
29
|
return mount(sources);
|
|
27
30
|
};
|
|
28
31
|
|
|
32
|
+
/**
|
|
33
|
+
* @internal
|
|
34
|
+
*/
|
|
29
35
|
async function mount(sources: string[]): Promise<any[]> {
|
|
30
36
|
const controllers: any[] = [];
|
|
31
37
|
for (const file of sources) {
|
|
@@ -39,4 +45,7 @@ async function mount(sources: string[]): Promise<any[]> {
|
|
|
39
45
|
return controllers;
|
|
40
46
|
}
|
|
41
47
|
|
|
48
|
+
/**
|
|
49
|
+
* @internal
|
|
50
|
+
*/
|
|
42
51
|
const EXTENSION = is_ts_node ? "ts" : "js";
|