@nestia/core 1.1.0-dev.20230414 → 1.1.0-dev.20230420-2
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/TypedParam.d.ts +14 -8
- package/lib/decorators/TypedParam.js +13 -9
- package/lib/decorators/TypedParam.js.map +1 -1
- package/lib/programmers/TypedBodyProgrammer.js +4 -4
- package/lib/programmers/TypedBodyProgrammer.js.map +1 -1
- package/lib/programmers/TypedParamProgrammer.d.ts +5 -0
- package/lib/programmers/TypedParamProgrammer.js +108 -0
- package/lib/programmers/TypedParamProgrammer.js.map +1 -0
- package/lib/programmers/TypedQueryProgrammer.js +5 -5
- package/lib/programmers/TypedQueryProgrammer.js.map +1 -1
- package/lib/programmers/TypedRouteProgrammer.js +5 -5
- package/lib/programmers/TypedRouteProgrammer.js.map +1 -1
- package/lib/transformers/ParameterDecoratorTransformer.js +20 -8
- package/lib/transformers/ParameterDecoratorTransformer.js.map +1 -1
- package/package.json +6 -6
- package/src/decorators/TypedParam.ts +15 -9
- package/src/programmers/TypedBodyProgrammer.ts +12 -14
- package/src/programmers/TypedParamProgrammer.ts +96 -0
- package/src/programmers/TypedQueryProgrammer.ts +11 -20
- package/src/programmers/TypedRouteProgrammer.ts +9 -14
- package/src/transformers/ParameterDecoratorTransformer.ts +26 -12
|
@@ -3,23 +3,29 @@
|
|
|
3
3
|
*
|
|
4
4
|
* `TypedParam` is a decorator function getting specific typed parameter from the
|
|
5
5
|
* HTTP request URL. It's almost same with the {@link nest.Param}, but `TypedParam`
|
|
6
|
-
*
|
|
7
|
-
* parses all of the parameters as string type.
|
|
6
|
+
* automatically casts parameter value to be following its type. Beside, the
|
|
7
|
+
* {@link nest.Param} always parses all of the parameters as `string` type.
|
|
8
|
+
*
|
|
9
|
+
* Note that, if you just omit the `type` and `nullable` parameters, then
|
|
10
|
+
* `TypedParam` automatically determines the `type` and `nullable` values
|
|
11
|
+
* just by analyzing the parameter type. Only when you need to specify them
|
|
12
|
+
* are, you want to use the `uuid` type.
|
|
8
13
|
*
|
|
9
14
|
* ```typescript
|
|
10
|
-
* \@TypedRoute.Get("shopping/sales/:
|
|
15
|
+
* \@TypedRoute.Get("shopping/sales/:id/:no/:paused")
|
|
11
16
|
* public async pause
|
|
12
17
|
* (
|
|
13
|
-
* \@TypedParam("
|
|
14
|
-
* \@TypedParam("
|
|
15
|
-
* \@TypedParam("paused"
|
|
18
|
+
* \@TypedParam("id", "uuid"), id: string, // uuid specification
|
|
19
|
+
* \@TypedParam("no") id: number, // auto casting
|
|
20
|
+
* \@TypedParam("paused") paused: boolean | null // auto casting
|
|
16
21
|
* ): Promise<void>;
|
|
17
22
|
* ```
|
|
18
23
|
*
|
|
19
24
|
* @param name URL Parameter name
|
|
20
|
-
* @param type
|
|
25
|
+
* @param type If omit, automatically determined by the parameter type.
|
|
26
|
+
* @param nullable If omit, automatically determined by the parameter type.
|
|
21
27
|
* @returns Parameter decorator
|
|
22
28
|
*
|
|
23
29
|
* @author Jeongho Nam - https://github.com/samchon
|
|
24
30
|
*/
|
|
25
|
-
export declare function TypedParam(name: string, type?: "boolean" | "number" | "string" | "uuid", nullable?:
|
|
31
|
+
export declare function TypedParam(name: string, type?: "boolean" | "number" | "string" | "uuid", nullable?: false | true): ParameterDecorator;
|
|
@@ -7,28 +7,32 @@ var common_1 = require("@nestjs/common");
|
|
|
7
7
|
*
|
|
8
8
|
* `TypedParam` is a decorator function getting specific typed parameter from the
|
|
9
9
|
* HTTP request URL. It's almost same with the {@link nest.Param}, but `TypedParam`
|
|
10
|
-
*
|
|
11
|
-
* parses all of the parameters as string type.
|
|
10
|
+
* automatically casts parameter value to be following its type. Beside, the
|
|
11
|
+
* {@link nest.Param} always parses all of the parameters as `string` type.
|
|
12
|
+
*
|
|
13
|
+
* Note that, if you just omit the `type` and `nullable` parameters, then
|
|
14
|
+
* `TypedParam` automatically determines the `type` and `nullable` values
|
|
15
|
+
* just by analyzing the parameter type. Only when you need to specify them
|
|
16
|
+
* are, you want to use the `uuid` type.
|
|
12
17
|
*
|
|
13
18
|
* ```typescript
|
|
14
|
-
* \@TypedRoute.Get("shopping/sales/:
|
|
19
|
+
* \@TypedRoute.Get("shopping/sales/:id/:no/:paused")
|
|
15
20
|
* public async pause
|
|
16
21
|
* (
|
|
17
|
-
* \@TypedParam("
|
|
18
|
-
* \@TypedParam("
|
|
19
|
-
* \@TypedParam("paused"
|
|
22
|
+
* \@TypedParam("id", "uuid"), id: string, // uuid specification
|
|
23
|
+
* \@TypedParam("no") id: number, // auto casting
|
|
24
|
+
* \@TypedParam("paused") paused: boolean | null // auto casting
|
|
20
25
|
* ): Promise<void>;
|
|
21
26
|
* ```
|
|
22
27
|
*
|
|
23
28
|
* @param name URL Parameter name
|
|
24
|
-
* @param type
|
|
29
|
+
* @param type If omit, automatically determined by the parameter type.
|
|
30
|
+
* @param nullable If omit, automatically determined by the parameter type.
|
|
25
31
|
* @returns Parameter decorator
|
|
26
32
|
*
|
|
27
33
|
* @author Jeongho Nam - https://github.com/samchon
|
|
28
34
|
*/
|
|
29
35
|
function TypedParam(name, type, nullable) {
|
|
30
|
-
if (type === void 0) { type = "string"; }
|
|
31
|
-
if (nullable === void 0) { nullable = false; }
|
|
32
36
|
return (0, common_1.createParamDecorator)(function TypedParam(_a, ctx) {
|
|
33
37
|
var request = ctx.switchToHttp().getRequest();
|
|
34
38
|
var str = request.params[name];
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"TypedParam.js","sourceRoot":"","sources":["../../src/decorators/TypedParam.ts"],"names":[],"mappings":";;;AAAA,yCAIwB;AAGxB
|
|
1
|
+
{"version":3,"file":"TypedParam.js","sourceRoot":"","sources":["../../src/decorators/TypedParam.ts"],"names":[],"mappings":";;;AAAA,yCAIwB;AAGxB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6BG;AACH,SAAgB,UAAU,CACtB,IAAY,EACZ,IAA+C,EAC/C,QAAuB;IAEvB,OAAO,IAAA,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(modulo)(false)(type)),
|
|
35
35
|
]);
|
|
36
36
|
};
|
|
37
37
|
// RETURNS
|
|
38
38
|
if (project.options.validate === "is")
|
|
39
|
-
return parameter("is", IsProgrammer_1.IsProgrammer.
|
|
39
|
+
return parameter("is", IsProgrammer_1.IsProgrammer.write);
|
|
40
40
|
else if (project.options.validate === "validate")
|
|
41
|
-
return parameter("validate", ValidateProgrammer_1.ValidateProgrammer.
|
|
42
|
-
return parameter("assert", AssertProgrammer_1.AssertProgrammer.
|
|
41
|
+
return parameter("validate", ValidateProgrammer_1.ValidateProgrammer.write);
|
|
42
|
+
return parameter("assert", AssertProgrammer_1.AssertProgrammer.write);
|
|
43
43
|
};
|
|
44
44
|
};
|
|
45
45
|
})(TypedBodyProgrammer = exports.TypedBodyProgrammer || (exports.TypedBodyProgrammer = {}));
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"TypedBodyProgrammer.js","sourceRoot":"","sources":["../../src/programmers/TypedBodyProgrammer.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;AAAA,0DAA4B;AAE5B,2EAA0E;AAC1E,mEAAkE;AAClE,+EAA8E;AAK9E,IAAiB,mBAAmB,
|
|
1
|
+
{"version":3,"file":"TypedBodyProgrammer.js","sourceRoot":"","sources":["../../src/programmers/TypedBodyProgrammer.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;AAAA,0DAA4B;AAE5B,2EAA0E;AAC1E,mEAAkE;AAClE,+EAA8E;AAK9E,IAAiB,mBAAmB,CAsCnC;AAtCD,WAAiB,mBAAmB;IACnB,4BAAQ,GACjB,UAAC,OAAgC,EAAE,MAAiC;QACpE,OAAA,UAAC,IAAa;YACV,2BAA2B;YAC3B,IAAM,SAAS,GAAG,UACd,GAAW,EACX,UAI6D;gBAE7D,OAAA,oBAAE,CAAC,OAAO,CAAC,6BAA6B,CAAC;oBACrC,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;oBACD,oBAAE,CAAC,OAAO,CAAC,wBAAwB,CAC/B,oBAAE,CAAC,OAAO,CAAC,gBAAgB,CAAC,GAAG,CAAC,EAChC,UAAU,uBACH,OAAO,KACV,OAAO,EAAE;4BACL,OAAO,EAAE,KAAK;4BACd,MAAM,EAAE,KAAK;4BACb,UAAU,EAAE,KAAK;yBACpB,IACH,CAAC,MAAM,CAAC,CAAC,KAAK,CAAC,CAAC,IAAI,CAAC,CAC1B;iBACJ,CAAC;YAhBF,CAgBE,CAAC;YAEP,UAAU;YACV,IAAI,OAAO,CAAC,OAAO,CAAC,QAAQ,KAAK,IAAI;gBACjC,OAAO,SAAS,CAAC,IAAI,EAAE,2BAAY,CAAC,KAAK,CAAC,CAAC;iBAC1C,IAAI,OAAO,CAAC,OAAO,CAAC,QAAQ,KAAK,UAAU;gBAC5C,OAAO,SAAS,CAAC,UAAU,EAAE,uCAAkB,CAAC,KAAK,CAAC,CAAC;YAC3D,OAAO,SAAS,CAAC,QAAQ,EAAE,mCAAgB,CAAC,KAAK,CAAC,CAAC;QACvD,CAAC;IAlCD,CAkCC,CAAC;AACV,CAAC,EAtCgB,mBAAmB,GAAnB,2BAAmB,KAAnB,2BAAmB,QAsCnC"}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import ts from "typescript";
|
|
2
|
+
import { INestiaTransformProject } from "../options/INestiaTransformProject";
|
|
3
|
+
export declare namespace TypedParamProgrammer {
|
|
4
|
+
const generate: ({ checker }: INestiaTransformProject) => (parameters: readonly ts.Expression[]) => (type: ts.Type) => readonly ts.Expression[];
|
|
5
|
+
}
|
|
@@ -0,0 +1,108 @@
|
|
|
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 __importDefault = (this && this.__importDefault) || function (mod) {
|
|
28
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
29
|
+
};
|
|
30
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
31
|
+
exports.TypedParamProgrammer = void 0;
|
|
32
|
+
var typescript_1 = __importDefault(require("typescript"));
|
|
33
|
+
var MetadataCollection_1 = require("typia/lib/factories/MetadataCollection");
|
|
34
|
+
var MetadataFactory_1 = require("typia/lib/factories/MetadataFactory");
|
|
35
|
+
var TypedParamProgrammer;
|
|
36
|
+
(function (TypedParamProgrammer) {
|
|
37
|
+
TypedParamProgrammer.generate = function (_a) {
|
|
38
|
+
var checker = _a.checker;
|
|
39
|
+
return function (parameters) {
|
|
40
|
+
return function (type) {
|
|
41
|
+
var metadata = MetadataFactory_1.MetadataFactory.analyze(checker)({
|
|
42
|
+
resolve: false,
|
|
43
|
+
constant: true,
|
|
44
|
+
validate: validate,
|
|
45
|
+
})(new MetadataCollection_1.MetadataCollection())(type);
|
|
46
|
+
var _a = __read(get_atomic_types(metadata), 1), atomic = _a[0];
|
|
47
|
+
// AUTO TYPE SPECIFICATION
|
|
48
|
+
if (parameters.length === 1)
|
|
49
|
+
return [
|
|
50
|
+
parameters[0],
|
|
51
|
+
typescript_1.default.factory.createStringLiteral(atomic),
|
|
52
|
+
metadata.nullable
|
|
53
|
+
? typescript_1.default.factory.createTrue()
|
|
54
|
+
: typescript_1.default.factory.createFalse(),
|
|
55
|
+
];
|
|
56
|
+
// TYPE HAS BEEN SPECIFIED IN DECORATOR
|
|
57
|
+
var specified = MetadataFactory_1.MetadataFactory.analyze(checker)({
|
|
58
|
+
resolve: false,
|
|
59
|
+
constant: true,
|
|
60
|
+
})(new MetadataCollection_1.MetadataCollection())(checker.getTypeAtLocation(parameters[1]));
|
|
61
|
+
if (equals(atomic, specified) === false)
|
|
62
|
+
throw new Error(error("different type between parameter and variable"));
|
|
63
|
+
if (parameters.length === 2)
|
|
64
|
+
return [
|
|
65
|
+
parameters[0],
|
|
66
|
+
parameters[1],
|
|
67
|
+
metadata.nullable
|
|
68
|
+
? typescript_1.default.factory.createTrue()
|
|
69
|
+
: typescript_1.default.factory.createFalse(),
|
|
70
|
+
];
|
|
71
|
+
// NULLABLE HAS BEEN SPECIFIED
|
|
72
|
+
var nullable = MetadataFactory_1.MetadataFactory.analyze(checker)({
|
|
73
|
+
resolve: false,
|
|
74
|
+
constant: true,
|
|
75
|
+
})(new MetadataCollection_1.MetadataCollection())(checker.getTypeAtLocation(parameters[2]));
|
|
76
|
+
if (nullable.getName() !== "true" && nullable.getName() !== "false")
|
|
77
|
+
throw new Error(error("nullable value must be literal type"));
|
|
78
|
+
else if (metadata.nullable !== (nullable.getName() === "true"))
|
|
79
|
+
throw new Error(error("different type (nullable) between parameter and variable"));
|
|
80
|
+
return parameters;
|
|
81
|
+
};
|
|
82
|
+
};
|
|
83
|
+
};
|
|
84
|
+
})(TypedParamProgrammer = exports.TypedParamProgrammer || (exports.TypedParamProgrammer = {}));
|
|
85
|
+
var validate = function (meta) {
|
|
86
|
+
if (meta.any)
|
|
87
|
+
throw new Error(error("do not allow any type"));
|
|
88
|
+
else if (meta.required === false)
|
|
89
|
+
throw new Error(error("do not allow undefindable type"));
|
|
90
|
+
var atomics = get_atomic_types(meta);
|
|
91
|
+
var expected = meta.atomics.length +
|
|
92
|
+
meta.constants.map(function (c) { return c.values.length; }).reduce(function (a, b) { return a + b; }, 0);
|
|
93
|
+
if (meta.size() !== expected || atomics.length === 0)
|
|
94
|
+
throw new Error(error("only atomic or constant types is allowed"));
|
|
95
|
+
else if (atomics.length > 1)
|
|
96
|
+
throw new Error(error("do not allow union type"));
|
|
97
|
+
};
|
|
98
|
+
var get_atomic_types = function (meta) { return __spreadArray([], __read(new Set(__spreadArray(__spreadArray([], __read(meta.atomics), false), __read(meta.constants.map(function (c) { return c.type; })), false))), false); };
|
|
99
|
+
var error = function (message) {
|
|
100
|
+
return "Error on nestia.core.TypedParam(): ".concat(message, ".");
|
|
101
|
+
};
|
|
102
|
+
var equals = function (atomic, p) {
|
|
103
|
+
var name = p.getName();
|
|
104
|
+
if (atomic === "string")
|
|
105
|
+
return name === "\"string\"" || name === "\"uuid\"";
|
|
106
|
+
return "\"".concat(atomic, "\"") === name;
|
|
107
|
+
};
|
|
108
|
+
//# sourceMappingURL=TypedParamProgrammer.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"TypedParamProgrammer.js","sourceRoot":"","sources":["../../src/programmers/TypedParamProgrammer.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,0DAA4B;AAE5B,6EAA4E;AAC5E,uEAAsE;AAKtE,IAAiB,oBAAoB,CA2DpC;AA3DD,WAAiB,oBAAoB;IACpB,6BAAQ,GACjB,UAAC,EAAoC;YAAlC,OAAO,aAAA;QACV,OAAA,UAAC,UAAoC;YACrC,OAAA,UAAC,IAAa;gBACV,IAAM,QAAQ,GAAa,iCAAe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IAAK,OAAA,CAAC,GAAG,CAAC,EAAL,CAAK,EAAE,CAAC,CAAC,CAAC;IAC1E,IAAI,IAAI,CAAC,IAAI,EAAE,KAAK,QAAQ,IAAI,OAAO,CAAC,MAAM,KAAK,CAAC;QAChD,MAAM,IAAI,KAAK,CAAC,KAAK,CAAC,0CAA0C,CAAC,CAAC,CAAC;SAClE,IAAI,OAAO,CAAC,MAAM,GAAG,CAAC;QACvB,MAAM,IAAI,KAAK,CAAC,KAAK,CAAC,yBAAyB,CAAC,CAAC,CAAC;AAC1D,CAAC,CAAC;AAEF,IAAM,gBAAgB,GAAG,UAAC,IAAc,IAAe,gCAChD,IAAI,GAAG,wCAAK,IAAI,CAAC,OAAO,kBAAK,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,UAAC,CAAC,IAAK,OAAA,CAAC,CAAC,IAAI,EAAN,CAAM,CAAC,UAAE,WADhB,CAEtD,CAAC;AAEF,IAAM,KAAK,GAAG,UAAC,OAAe;IAC1B,OAAA,6CAAsC,OAAO,MAAG;AAAhD,CAAgD,CAAC;AAErD,IAAM,MAAM,GAAG,UAAC,MAAc,EAAE,CAAW;IACvC,IAAM,IAAI,GAAW,CAAC,CAAC,OAAO,EAAE,CAAC;IACjC,IAAI,MAAM,KAAK,QAAQ;QAAE,OAAO,IAAI,KAAK,YAAU,IAAI,IAAI,KAAK,UAAQ,CAAC;IACzE,OAAO,YAAI,MAAM,OAAG,KAAK,IAAI,CAAC;AAClC,CAAC,CAAC"}
|
|
@@ -70,10 +70,10 @@ var TypedQueryProgrammer;
|
|
|
70
70
|
return function (type) {
|
|
71
71
|
var e_1, _a;
|
|
72
72
|
var collection = new MetadataCollection_1.MetadataCollection();
|
|
73
|
-
var metadata = MetadataFactory_1.MetadataFactory.
|
|
73
|
+
var metadata = MetadataFactory_1.MetadataFactory.analyze(checker)({
|
|
74
74
|
resolve: false,
|
|
75
75
|
constant: true,
|
|
76
|
-
});
|
|
76
|
+
})(collection)(type);
|
|
77
77
|
if (metadata.objects.length !== 1 || metadata.bucket() !== 1)
|
|
78
78
|
throw new Error(ErrorMessages.object(metadata)("only one object type is allowed."));
|
|
79
79
|
else if (metadata.nullable === true)
|
|
@@ -198,9 +198,9 @@ var TypedQueryProgrammer;
|
|
|
198
198
|
};
|
|
199
199
|
var decode_object = function (project, modulo) {
|
|
200
200
|
return function (type, object) {
|
|
201
|
-
var assert = AssertProgrammer_1.AssertProgrammer.
|
|
201
|
+
var assert = AssertProgrammer_1.AssertProgrammer.write(__assign(__assign({}, project), { options: {
|
|
202
202
|
numeric: true,
|
|
203
|
-
} })
|
|
203
|
+
} }))(modulo)(false)(type);
|
|
204
204
|
var output = typescript_1.default.factory.createIdentifier("output");
|
|
205
205
|
var importer = new FunctionImporeter_1.FunctionImporter();
|
|
206
206
|
var statements = [
|
|
@@ -233,7 +233,7 @@ var TypedQueryProgrammer;
|
|
|
233
233
|
: [meta.constants[0].type, true];
|
|
234
234
|
})(), 2), type = _a[0], isArray = _a[1];
|
|
235
235
|
return typescript_1.default.factory.createPropertyAssignment(key, isArray
|
|
236
|
-
? typescript_1.default.factory.createCallExpression(IdentifierFactory_1.IdentifierFactory.
|
|
236
|
+
? 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, [
|
|
237
237
|
typescript_1.default.factory.createArrowFunction(undefined, undefined, [IdentifierFactory_1.IdentifierFactory.parameter("elem")], undefined, undefined, decode_value(importer)(type)(typescript_1.default.factory.createIdentifier("elem"))),
|
|
238
238
|
])
|
|
239
239
|
: decode_value(importer)(type)(typescript_1.default.factory.createCallExpression(typescript_1.default.factory.createIdentifier("input.get"), undefined, [typescript_1.default.factory.createStringLiteral(key)])));
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"TypedQueryProgrammer.js","sourceRoot":"","sources":["../../src/programmers/TypedQueryProgrammer.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,0DAA4B;AAE5B,2EAA0E;AAC1E,6EAA4E;AAC5E,uEAAsE;AACtE,yEAAwE;AAIxE,2EAA0E;AAC1E,qFAAmF;AAKnF,IAAiB,oBAAoB,
|
|
1
|
+
{"version":3,"file":"TypedQueryProgrammer.js","sourceRoot":"","sources":["../../src/programmers/TypedQueryProgrammer.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,0DAA4B;AAE5B,2EAA0E;AAC1E,6EAA4E;AAC5E,uEAAsE;AACtE,yEAAwE;AAIxE,2EAA0E;AAC1E,qFAAmF;AAKnF,IAAiB,oBAAoB,CAwNpC;AAxND,WAAiB,oBAAoB;IACpB,6BAAQ,GACjB,UAAC,OAAgC,EAAE,MAAiC;QACpE,OAAA,UAAC,IAAa;YACV,IAAM,MAAM,GAAmB,SAAS,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC,IAAI,CAAC,CAAC;YAChE,OAAO,MAAM,CAAC,OAAO,EAAE,MAAM,CAAC,CAAC,IAAI,EAAE,MAAM,CAAC,CAAC;QACjD,CAAC;IAHD,CAGC,CAAC;IAEN,IAAM,SAAS,GACX,UAAC,OAAuB;QACxB,OAAA,UAAC,IAAa;;YACV,IAAM,UAAU,GAAuB,IAAI,uCAAkB,EAAE,CAAC;YAChE,IAAM,QAAQ,GAAa,iCAAe,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC;gBACxD,OAAO,EAAE,KAAK;gBACd,QAAQ,EAAE,IAAI;aACjB,CAAC,CAAC,UAAU,CAAC,CAAC,IAAI,CAAC,CAAC;YACrB,IAAI,QAAQ,CAAC,OAAO,CAAC,MAAM,KAAK,CAAC,IAAI,QAAQ,CAAC,MAAM,EAAE,KAAK,CAAC;gBACxD,MAAM,IAAI,KAAK,CACX,aAAa,CA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
|
|
@@ -28,20 +28,20 @@ var TypedRouteProgrammer;
|
|
|
28
28
|
var parameter = function (key, programmer) {
|
|
29
29
|
return typescript_1.default.factory.createObjectLiteralExpression([
|
|
30
30
|
typescript_1.default.factory.createPropertyAssignment(typescript_1.default.factory.createIdentifier("type"), typescript_1.default.factory.createStringLiteral(key)),
|
|
31
|
-
typescript_1.default.factory.createPropertyAssignment(typescript_1.default.factory.createIdentifier(key), programmer(__assign(__assign({}, project), { options: {} })
|
|
31
|
+
typescript_1.default.factory.createPropertyAssignment(typescript_1.default.factory.createIdentifier(key), programmer(__assign(__assign({}, project), { options: {} }))(modulo)(type)),
|
|
32
32
|
]);
|
|
33
33
|
};
|
|
34
34
|
// RETURNS
|
|
35
35
|
if (project.options.stringify === "is")
|
|
36
|
-
return parameter("is", IsStringifyProgrammer_1.IsStringifyProgrammer.
|
|
36
|
+
return parameter("is", IsStringifyProgrammer_1.IsStringifyProgrammer.write);
|
|
37
37
|
else if (project.options.stringify === "validate")
|
|
38
|
-
return parameter("validate", ValidateStringifyProgrammer_1.ValidateStringifyProgrammer.
|
|
38
|
+
return parameter("validate", ValidateStringifyProgrammer_1.ValidateStringifyProgrammer.write);
|
|
39
39
|
else if (project.options.stringify === "stringify")
|
|
40
|
-
return parameter("stringify", StringifyProgrammer_1.StringifyProgrammer.
|
|
40
|
+
return parameter("stringify", StringifyProgrammer_1.StringifyProgrammer.write);
|
|
41
41
|
else if (project.options.stringify === null)
|
|
42
42
|
return typescript_1.default.factory.createNull();
|
|
43
43
|
// ASSERT IS DEFAULT
|
|
44
|
-
return parameter("assert", AssertStringifyProgrammer_1.AssertStringifyProgrammer.
|
|
44
|
+
return parameter("assert", AssertStringifyProgrammer_1.AssertStringifyProgrammer.write);
|
|
45
45
|
};
|
|
46
46
|
};
|
|
47
47
|
})(TypedRouteProgrammer = exports.TypedRouteProgrammer || (exports.TypedRouteProgrammer = {}));
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"TypedRouteProgrammer.js","sourceRoot":"","sources":["../../src/programmers/TypedRouteProgrammer.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;AAAA,0DAA4B;AAE5B,6FAA4F;AAC5F,qFAAoF;AACpF,iFAAgF;AAChF,iGAAgG;AAKhG,IAAiB,oBAAoB,
|
|
1
|
+
{"version":3,"file":"TypedRouteProgrammer.js","sourceRoot":"","sources":["../../src/programmers/TypedRouteProgrammer.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;AAAA,0DAA4B;AAE5B,6FAA4F;AAC5F,qFAAoF;AACpF,iFAAgF;AAChF,iGAAgG;AAKhG,IAAiB,oBAAoB,CAwCpC;AAxCD,WAAiB,oBAAoB;IACpB,6BAAQ,GACjB,UAAC,OAAgC,EAAE,MAAiC;QACpE,OAAA,UAAC,IAAa;YACV,0BAA0B;YAC1B,IAAM,SAAS,GAAG,UACd,GAAW,EACX,UAIwC;gBAExC,OAAA,oBAAE,CAAC,OAAO,CAAC,6BAA6B,CAAC;oBACrC,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;oBACD,oBAAE,CAAC,OAAO,CAAC,wBAAwB,CAC/B,oBAAE,CAAC,OAAO,CAAC,gBAAgB,CAAC,GAAG,CAAC,EAChC,UAAU,uBACH,OAAO,KACV,OAAO,EAAE,EAAE,IACb,CAAC,MAAM,CAAC,CAAC,IAAI,CAAC,CACnB;iBACJ,CAAC;YAZF,CAYE,CAAC;YAEP,UAAU;YACV,IAAI,OAAO,CAAC,OAAO,CAAC,SAAS,KAAK,IAAI;gBAClC,OAAO,SAAS,CAAC,IAAI,EAAE,6CAAqB,CAAC,KAAK,CAAC,CAAC;iBACnD,IAAI,OAAO,CAAC,OAAO,CAAC,SAAS,KAAK,UAAU;gBAC7C,OAAO,SAAS,CAAC,UAAU,EAAE,yDAA2B,CAAC,KAAK,CAAC,CAAC;iBAC/D,IAAI,OAAO,CAAC,OAAO,CAAC,SAAS,KAAK,WAAW;gBAC9C,OAAO,SAAS,CAAC,WAAW,EAAE,yCAAmB,CAAC,KAAK,CAAC,CAAC;iBACxD,IAAI,OAAO,CAAC,OAAO,CAAC,SAAS,KAAK,IAAI;gBACvC,OAAO,oBAAE,CAAC,OAAO,CAAC,UAAU,EAAE,CAAC;YAEnC,oBAAoB;YACpB,OAAO,SAAS,CAAC,QAAQ,EAAE,qDAAyB,CAAC,KAAK,CAAC,CAAC;QAChE,CAAC;IApCD,CAoCC,CAAC;AACV,CAAC,EAxCgB,oBAAoB,GAApB,4BAAoB,KAApB,4BAAoB,QAwCpC"}
|
|
@@ -7,19 +7,18 @@ exports.ParameterDecoratorTransformer = void 0;
|
|
|
7
7
|
var path_1 = __importDefault(require("path"));
|
|
8
8
|
var typescript_1 = __importDefault(require("typescript"));
|
|
9
9
|
var TypedBodyProgrammer_1 = require("../programmers/TypedBodyProgrammer");
|
|
10
|
+
var TypedParamProgrammer_1 = require("../programmers/TypedParamProgrammer");
|
|
10
11
|
var TypedQueryProgrammer_1 = require("../programmers/TypedQueryProgrammer");
|
|
11
12
|
var ParameterDecoratorTransformer;
|
|
12
13
|
(function (ParameterDecoratorTransformer) {
|
|
13
14
|
function transform(project, type, decorator) {
|
|
14
|
-
var _a
|
|
15
|
+
var _a;
|
|
15
16
|
//----
|
|
16
17
|
// VALIDATIONS
|
|
17
18
|
//----
|
|
18
19
|
// CHECK DECORATOR
|
|
19
20
|
if (!typescript_1.default.isCallExpression(decorator.expression))
|
|
20
21
|
return decorator;
|
|
21
|
-
else if (decorator.expression.arguments.length !== 0)
|
|
22
|
-
return decorator;
|
|
23
22
|
// SIGNATURE DECLARATION
|
|
24
23
|
var declaration = (_a = project.checker.getResolvedSignature(decorator.expression)) === null || _a === void 0 ? void 0 : _a.declaration;
|
|
25
24
|
if (declaration === undefined)
|
|
@@ -32,7 +31,7 @@ var ParameterDecoratorTransformer;
|
|
|
32
31
|
// TRANSFORMATION
|
|
33
32
|
//----
|
|
34
33
|
// FIND PROGRAMMER
|
|
35
|
-
var programmer =
|
|
34
|
+
var programmer = FUNCTORS[project.checker.getTypeAtLocation(declaration).symbol.name];
|
|
36
35
|
if (programmer === undefined)
|
|
37
36
|
return decorator;
|
|
38
37
|
// GET TYPE INFO
|
|
@@ -40,14 +39,27 @@ var ParameterDecoratorTransformer;
|
|
|
40
39
|
if (typeNode === undefined)
|
|
41
40
|
return decorator;
|
|
42
41
|
// DO TRANSFORM
|
|
43
|
-
return typescript_1.default.factory.createDecorator(typescript_1.default.factory.updateCallExpression(decorator.expression, decorator.expression.expression, decorator.expression.typeArguments,
|
|
42
|
+
return typescript_1.default.factory.createDecorator(typescript_1.default.factory.updateCallExpression(decorator.expression, decorator.expression.expression, decorator.expression.typeArguments, programmer(project, decorator.expression.expression)(decorator.expression.arguments)(type)));
|
|
44
43
|
}
|
|
45
44
|
ParameterDecoratorTransformer.transform = transform;
|
|
46
45
|
})(ParameterDecoratorTransformer = exports.ParameterDecoratorTransformer || (exports.ParameterDecoratorTransformer = {}));
|
|
47
46
|
var FUNCTORS = {
|
|
48
|
-
EncryptedBody: function () { return
|
|
49
|
-
|
|
50
|
-
|
|
47
|
+
EncryptedBody: function (project, modulo) { return function (parameters) { return function (type) {
|
|
48
|
+
return parameters.length
|
|
49
|
+
? parameters
|
|
50
|
+
: [TypedBodyProgrammer_1.TypedBodyProgrammer.generate(project, modulo)(type)];
|
|
51
|
+
}; }; },
|
|
52
|
+
TypedBody: function (project, modulo) { return function (parameters) { return function (type) {
|
|
53
|
+
return parameters.length
|
|
54
|
+
? parameters
|
|
55
|
+
: [TypedBodyProgrammer_1.TypedBodyProgrammer.generate(project, modulo)(type)];
|
|
56
|
+
}; }; },
|
|
57
|
+
TypedParam: TypedParamProgrammer_1.TypedParamProgrammer.generate,
|
|
58
|
+
TypedQuery: function (project, modulo) { return function (parameters) { return function (type) {
|
|
59
|
+
return parameters.length
|
|
60
|
+
? parameters
|
|
61
|
+
: [TypedQueryProgrammer_1.TypedQueryProgrammer.generate(project, modulo)(type)];
|
|
62
|
+
}; }; },
|
|
51
63
|
};
|
|
52
64
|
var LIB_PATH = path_1.default.join("node_modules", "@nestia", "core", "lib", "decorators");
|
|
53
65
|
var SRC_PATH = path_1.default.resolve(path_1.default.join(__dirname, "..", "decorators"));
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ParameterDecoratorTransformer.js","sourceRoot":"","sources":["../../src/transformers/ParameterDecoratorTransformer.ts"],"names":[],"mappings":";;;;;;AAAA,8CAAwB;AACxB,0DAA4B;AAG5B,0EAAyE;AACzE,4EAA2E;AAE3E,IAAiB,6BAA6B,
|
|
1
|
+
{"version":3,"file":"ParameterDecoratorTransformer.js","sourceRoot":"","sources":["../../src/transformers/ParameterDecoratorTransformer.ts"],"names":[],"mappings":";;;;;;AAAA,8CAAwB;AACxB,0DAA4B;AAG5B,0EAAyE;AACzE,4EAA2E;AAC3E,4EAA2E;AAE3E,IAAiB,6BAA6B,CAoD7C;AApDD,WAAiB,6BAA6B;IAC1C,SAAgB,SAAS,CACrB,OAAgC,EAChC,IAAa,EACb,SAAuB;;QAEvB,MAAM;QACN,cAAc;QACd,MAAM;QACN,kBAAkB;QAClB,IAAI,CAAC,oBAAE,CAAC,gBAAgB,CAAC,SAAS,CAAC,UAAU,CAAC;YAAE,OAAO,SAAS,CAAC;QAEjE,wBAAwB;QACxB,IAAM,WAAW,GACb,MAAA,OAAO,CAAC,OAAO,CAAC,oBAAoB,CAChC,SAAS,CAAC,UAAU,CACvB,0CAAE,WAAW,CAAC;QACnB,IAAI,WAAW,KAAK,SAAS;YAAE,OAAO,SAAS,CAAC;QAEhD,YAAY;QACZ,IAAM,IAAI,GAAW,cAAI,CAAC,OAAO,CAAC,WAAW,CAAC,aAAa,EAAE,CAAC,QAAQ,CAAC,CAAC;QACxE,IAAI,IAAI,CAAC,OAAO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C,CAAC;IAF3D,CAE2D,EAHX,CAGW,EAH3B,CAG2B;IAC/D,SAAS,EAAE,UAAC,OAAO,EAAE,MAAM,IAAK,OAAA,UAAC,UAAU,IAAK,OAAA,UAAC,IAAI;QACjD,OAAA,UAAU,CAAC,MAAM;YACb,CAAC,CAAC,UAAU;YACZ,CAAC,CAAC,CAAC,yCAAmB,CAAC,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC,CAAC,IAAI,CAAC,CAAC;IAF3D,CAE2D,EAHf,CAGe,EAH/B,CAG+B;IAC/D,UAAU,EAAE,2CAAoB,CAAC,QAAQ;IACzC,UAAU,EAAE,UAAC,OAAO,EAAE,MAAM,IAAK,OAAA,UAAC,UAAU,IAAK,OAAA,UAAC,IAAI;QAClD,OAAA,UAAU,CAAC,MAAM;YACb,CAAC,CAAC,UAAU;YACZ,CAAC,CAAC,CAAC,2CAAoB,CAAC,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC,CAAC,IAAI,CAAC,CAAC;IAF5D,CAE4D,EAHf,CAGe,EAH/B,CAG+B;CACnE,CAAC;AAEF,IAAM,QAAQ,GAAG,cAAI,CAAC,IAAI,CACtB,cAAc,EACd,SAAS,EACT,MAAM,EACN,KAAK,EACL,YAAY,CACf,CAAC;AACF,IAAM,QAAQ,GAAG,cAAI,CAAC,OAAO,CAAC,cAAI,CAAC,IAAI,CAAC,SAAS,EAAE,IAAI,EAAE,YAAY,CAAC,CAAC,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nestia/core",
|
|
3
|
-
"version": "1.1.0-dev.
|
|
3
|
+
"version": "1.1.0-dev.20230420-2",
|
|
4
4
|
"description": "Super-fast validation decorators of NestJS",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"typings": "lib/index.d.ts",
|
|
@@ -10,8 +10,8 @@
|
|
|
10
10
|
"dev": "npm run build -- --watch",
|
|
11
11
|
"eslint": "eslint ./**/*.ts",
|
|
12
12
|
"eslint:fix": "eslint ./**/*.ts --fix",
|
|
13
|
-
"package:latest": "npm publish --access public",
|
|
14
|
-
"package:next": "npm
|
|
13
|
+
"package:latest": "npm run build && npm run build:test && npm run test && npm publish --access public",
|
|
14
|
+
"package:next": "npm run package:latest -- --tag next",
|
|
15
15
|
"prepare": "ts-patch install",
|
|
16
16
|
"prettier": "prettier ./**/*.ts --write",
|
|
17
17
|
"test": "node bin/test"
|
|
@@ -36,7 +36,7 @@
|
|
|
36
36
|
},
|
|
37
37
|
"homepage": "https://github.com/samchon/nestia",
|
|
38
38
|
"dependencies": {
|
|
39
|
-
"@nestia/fetcher": "^1.1.0-dev.
|
|
39
|
+
"@nestia/fetcher": "^1.1.0-dev.20230420-2",
|
|
40
40
|
"@nestjs/common": ">= 7.0.1",
|
|
41
41
|
"@nestjs/core": ">= 7.0.1",
|
|
42
42
|
"@nestjs/platform-express": ">= 7.0.1",
|
|
@@ -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.0-dev.
|
|
47
|
+
"typia": "^3.8.0-dev.20230420-2"
|
|
48
48
|
},
|
|
49
49
|
"peerDependencies": {
|
|
50
50
|
"typescript": ">= 4.5.2"
|
|
@@ -63,7 +63,7 @@
|
|
|
63
63
|
"prettier": "^2.8.7",
|
|
64
64
|
"rimraf": "^3.0.2",
|
|
65
65
|
"ts-node": "^10.9.1",
|
|
66
|
-
"ts-patch": "
|
|
66
|
+
"ts-patch": "3.0.0-beta3",
|
|
67
67
|
"tstl": "^2.5.13",
|
|
68
68
|
"typescript": "^5.0.4",
|
|
69
69
|
"typescript-transform-paths": "^3.4.6"
|
|
@@ -10,29 +10,35 @@ import type express from "express";
|
|
|
10
10
|
*
|
|
11
11
|
* `TypedParam` is a decorator function getting specific typed parameter from the
|
|
12
12
|
* HTTP request URL. It's almost same with the {@link nest.Param}, but `TypedParam`
|
|
13
|
-
*
|
|
14
|
-
* parses all of the parameters as string type.
|
|
13
|
+
* automatically casts parameter value to be following its type. Beside, the
|
|
14
|
+
* {@link nest.Param} always parses all of the parameters as `string` type.
|
|
15
|
+
*
|
|
16
|
+
* Note that, if you just omit the `type` and `nullable` parameters, then
|
|
17
|
+
* `TypedParam` automatically determines the `type` and `nullable` values
|
|
18
|
+
* just by analyzing the parameter type. Only when you need to specify them
|
|
19
|
+
* are, you want to use the `uuid` type.
|
|
15
20
|
*
|
|
16
21
|
* ```typescript
|
|
17
|
-
* \@TypedRoute.Get("shopping/sales/:
|
|
22
|
+
* \@TypedRoute.Get("shopping/sales/:id/:no/:paused")
|
|
18
23
|
* public async pause
|
|
19
24
|
* (
|
|
20
|
-
* \@TypedParam("
|
|
21
|
-
* \@TypedParam("
|
|
22
|
-
* \@TypedParam("paused"
|
|
25
|
+
* \@TypedParam("id", "uuid"), id: string, // uuid specification
|
|
26
|
+
* \@TypedParam("no") id: number, // auto casting
|
|
27
|
+
* \@TypedParam("paused") paused: boolean | null // auto casting
|
|
23
28
|
* ): Promise<void>;
|
|
24
29
|
* ```
|
|
25
30
|
*
|
|
26
31
|
* @param name URL Parameter name
|
|
27
|
-
* @param type
|
|
32
|
+
* @param type If omit, automatically determined by the parameter type.
|
|
33
|
+
* @param nullable If omit, automatically determined by the parameter type.
|
|
28
34
|
* @returns Parameter decorator
|
|
29
35
|
*
|
|
30
36
|
* @author Jeongho Nam - https://github.com/samchon
|
|
31
37
|
*/
|
|
32
38
|
export function TypedParam(
|
|
33
39
|
name: string,
|
|
34
|
-
type
|
|
35
|
-
nullable
|
|
40
|
+
type?: "boolean" | "number" | "string" | "uuid",
|
|
41
|
+
nullable?: false | true,
|
|
36
42
|
): ParameterDecorator {
|
|
37
43
|
return createParamDecorator(function TypedParam(
|
|
38
44
|
{}: any,
|
|
@@ -16,8 +16,9 @@ export namespace TypedBodyProgrammer {
|
|
|
16
16
|
key: string,
|
|
17
17
|
programmer: (
|
|
18
18
|
project: IProject,
|
|
19
|
+
) => (
|
|
19
20
|
modulo: ts.LeftHandSideExpression,
|
|
20
|
-
) => (type: ts.Type) => ts.ArrowFunction,
|
|
21
|
+
) => (equals: boolean) => (type: ts.Type) => ts.ArrowFunction,
|
|
21
22
|
) =>
|
|
22
23
|
ts.factory.createObjectLiteralExpression([
|
|
23
24
|
ts.factory.createPropertyAssignment(
|
|
@@ -26,25 +27,22 @@ export namespace TypedBodyProgrammer {
|
|
|
26
27
|
),
|
|
27
28
|
ts.factory.createPropertyAssignment(
|
|
28
29
|
ts.factory.createIdentifier(key),
|
|
29
|
-
programmer(
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
functional: false,
|
|
36
|
-
},
|
|
30
|
+
programmer({
|
|
31
|
+
...project,
|
|
32
|
+
options: {
|
|
33
|
+
numeric: false,
|
|
34
|
+
finite: false,
|
|
35
|
+
functional: false,
|
|
37
36
|
},
|
|
38
|
-
|
|
39
|
-
)(type),
|
|
37
|
+
})(modulo)(false)(type),
|
|
40
38
|
),
|
|
41
39
|
]);
|
|
42
40
|
|
|
43
41
|
// RETURNS
|
|
44
42
|
if (project.options.validate === "is")
|
|
45
|
-
return parameter("is", IsProgrammer.
|
|
43
|
+
return parameter("is", IsProgrammer.write);
|
|
46
44
|
else if (project.options.validate === "validate")
|
|
47
|
-
return parameter("validate", ValidateProgrammer.
|
|
48
|
-
return parameter("assert", AssertProgrammer.
|
|
45
|
+
return parameter("validate", ValidateProgrammer.write);
|
|
46
|
+
return parameter("assert", AssertProgrammer.write);
|
|
49
47
|
};
|
|
50
48
|
}
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
import ts from "typescript";
|
|
2
|
+
|
|
3
|
+
import { MetadataCollection } from "typia/lib/factories/MetadataCollection";
|
|
4
|
+
import { MetadataFactory } from "typia/lib/factories/MetadataFactory";
|
|
5
|
+
import { Metadata } from "typia/lib/metadata/Metadata";
|
|
6
|
+
|
|
7
|
+
import { INestiaTransformProject } from "../options/INestiaTransformProject";
|
|
8
|
+
|
|
9
|
+
export namespace TypedParamProgrammer {
|
|
10
|
+
export const generate =
|
|
11
|
+
({ checker }: INestiaTransformProject) =>
|
|
12
|
+
(parameters: readonly ts.Expression[]) =>
|
|
13
|
+
(type: ts.Type): readonly ts.Expression[] => {
|
|
14
|
+
const metadata: Metadata = MetadataFactory.analyze(checker)({
|
|
15
|
+
resolve: false,
|
|
16
|
+
constant: true,
|
|
17
|
+
validate,
|
|
18
|
+
})(new MetadataCollection())(type);
|
|
19
|
+
const [atomic] = get_atomic_types(metadata);
|
|
20
|
+
|
|
21
|
+
// AUTO TYPE SPECIFICATION
|
|
22
|
+
if (parameters.length === 1)
|
|
23
|
+
return [
|
|
24
|
+
parameters[0],
|
|
25
|
+
ts.factory.createStringLiteral(atomic),
|
|
26
|
+
metadata.nullable
|
|
27
|
+
? ts.factory.createTrue()
|
|
28
|
+
: ts.factory.createFalse(),
|
|
29
|
+
];
|
|
30
|
+
|
|
31
|
+
// TYPE HAS BEEN SPECIFIED IN DECORATOR
|
|
32
|
+
const specified: Metadata = MetadataFactory.analyze(checker)({
|
|
33
|
+
resolve: false,
|
|
34
|
+
constant: true,
|
|
35
|
+
})(new MetadataCollection())(
|
|
36
|
+
checker.getTypeAtLocation(parameters[1]),
|
|
37
|
+
);
|
|
38
|
+
if (equals(atomic, specified) === false)
|
|
39
|
+
throw new Error(
|
|
40
|
+
error("different type between parameter and variable"),
|
|
41
|
+
);
|
|
42
|
+
if (parameters.length === 2)
|
|
43
|
+
return [
|
|
44
|
+
parameters[0],
|
|
45
|
+
parameters[1],
|
|
46
|
+
metadata.nullable
|
|
47
|
+
? ts.factory.createTrue()
|
|
48
|
+
: ts.factory.createFalse(),
|
|
49
|
+
];
|
|
50
|
+
|
|
51
|
+
// NULLABLE HAS BEEN SPECIFIED
|
|
52
|
+
const nullable: Metadata = MetadataFactory.analyze(checker)({
|
|
53
|
+
resolve: false,
|
|
54
|
+
constant: true,
|
|
55
|
+
})(new MetadataCollection())(
|
|
56
|
+
checker.getTypeAtLocation(parameters[2]),
|
|
57
|
+
);
|
|
58
|
+
if (nullable.getName() !== "true" && nullable.getName() !== "false")
|
|
59
|
+
throw new Error(error("nullable value must be literal type"));
|
|
60
|
+
else if (metadata.nullable !== (nullable.getName() === "true"))
|
|
61
|
+
throw new Error(
|
|
62
|
+
error(
|
|
63
|
+
"different type (nullable) between parameter and variable",
|
|
64
|
+
),
|
|
65
|
+
);
|
|
66
|
+
return parameters;
|
|
67
|
+
};
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
const validate = (meta: Metadata) => {
|
|
71
|
+
if (meta.any) throw new Error(error("do not allow any type"));
|
|
72
|
+
else if (meta.required === false)
|
|
73
|
+
throw new Error(error("do not allow undefindable type"));
|
|
74
|
+
|
|
75
|
+
const atomics: string[] = get_atomic_types(meta);
|
|
76
|
+
const expected: number =
|
|
77
|
+
meta.atomics.length +
|
|
78
|
+
meta.constants.map((c) => c.values.length).reduce((a, b) => a + b, 0);
|
|
79
|
+
if (meta.size() !== expected || atomics.length === 0)
|
|
80
|
+
throw new Error(error("only atomic or constant types is allowed"));
|
|
81
|
+
else if (atomics.length > 1)
|
|
82
|
+
throw new Error(error("do not allow union type"));
|
|
83
|
+
};
|
|
84
|
+
|
|
85
|
+
const get_atomic_types = (meta: Metadata): string[] => [
|
|
86
|
+
...new Set([...meta.atomics, ...meta.constants.map((c) => c.type)]),
|
|
87
|
+
];
|
|
88
|
+
|
|
89
|
+
const error = (message: string) =>
|
|
90
|
+
`Error on nestia.core.TypedParam(): ${message}.`;
|
|
91
|
+
|
|
92
|
+
const equals = (atomic: string, p: Metadata) => {
|
|
93
|
+
const name: string = p.getName();
|
|
94
|
+
if (atomic === "string") return name === `"string"` || name === `"uuid"`;
|
|
95
|
+
return `"${atomic}"` === name;
|
|
96
|
+
};
|
|
@@ -25,15 +25,10 @@ export namespace TypedQueryProgrammer {
|
|
|
25
25
|
(checker: ts.TypeChecker) =>
|
|
26
26
|
(type: ts.Type): MetadataObject => {
|
|
27
27
|
const collection: MetadataCollection = new MetadataCollection();
|
|
28
|
-
const metadata: Metadata = MetadataFactory.
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
{
|
|
33
|
-
resolve: false,
|
|
34
|
-
constant: true,
|
|
35
|
-
},
|
|
36
|
-
);
|
|
28
|
+
const metadata: Metadata = MetadataFactory.analyze(checker)({
|
|
29
|
+
resolve: false,
|
|
30
|
+
constant: true,
|
|
31
|
+
})(collection)(type);
|
|
37
32
|
if (metadata.objects.length !== 1 || metadata.bucket() !== 1)
|
|
38
33
|
throw new Error(
|
|
39
34
|
ErrorMessages.object(metadata)(
|
|
@@ -141,15 +136,12 @@ export namespace TypedQueryProgrammer {
|
|
|
141
136
|
const decode_object =
|
|
142
137
|
(project: INestiaTransformProject, modulo: ts.LeftHandSideExpression) =>
|
|
143
138
|
(type: ts.Type, object: MetadataObject): ts.ConciseBody => {
|
|
144
|
-
const assert: ts.ArrowFunction = AssertProgrammer.
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
numeric: true,
|
|
149
|
-
},
|
|
139
|
+
const assert: ts.ArrowFunction = AssertProgrammer.write({
|
|
140
|
+
...project,
|
|
141
|
+
options: {
|
|
142
|
+
numeric: true,
|
|
150
143
|
},
|
|
151
|
-
|
|
152
|
-
)(type);
|
|
144
|
+
})(modulo)(false)(type);
|
|
153
145
|
const output = ts.factory.createIdentifier("output");
|
|
154
146
|
|
|
155
147
|
const importer = new FunctionImporter();
|
|
@@ -199,14 +191,13 @@ export namespace TypedQueryProgrammer {
|
|
|
199
191
|
key,
|
|
200
192
|
isArray
|
|
201
193
|
? ts.factory.createCallExpression(
|
|
202
|
-
IdentifierFactory.
|
|
194
|
+
IdentifierFactory.access(
|
|
203
195
|
ts.factory.createCallExpression(
|
|
204
196
|
ts.factory.createIdentifier("input.getAll"),
|
|
205
197
|
undefined,
|
|
206
198
|
[ts.factory.createStringLiteral(key)],
|
|
207
199
|
),
|
|
208
|
-
|
|
209
|
-
),
|
|
200
|
+
)("map"),
|
|
210
201
|
undefined,
|
|
211
202
|
[
|
|
212
203
|
ts.factory.createArrowFunction(
|
|
@@ -17,6 +17,7 @@ export namespace TypedRouteProgrammer {
|
|
|
17
17
|
key: string,
|
|
18
18
|
programmer: (
|
|
19
19
|
project: IProject,
|
|
20
|
+
) => (
|
|
20
21
|
modulo: ts.LeftHandSideExpression,
|
|
21
22
|
) => (type: ts.Type) => ts.ArrowFunction,
|
|
22
23
|
) =>
|
|
@@ -27,30 +28,24 @@ export namespace TypedRouteProgrammer {
|
|
|
27
28
|
),
|
|
28
29
|
ts.factory.createPropertyAssignment(
|
|
29
30
|
ts.factory.createIdentifier(key),
|
|
30
|
-
programmer(
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
},
|
|
35
|
-
modulo,
|
|
36
|
-
)(type),
|
|
31
|
+
programmer({
|
|
32
|
+
...project,
|
|
33
|
+
options: {}, // use default option
|
|
34
|
+
})(modulo)(type),
|
|
37
35
|
),
|
|
38
36
|
]);
|
|
39
37
|
|
|
40
38
|
// RETURNS
|
|
41
39
|
if (project.options.stringify === "is")
|
|
42
|
-
return parameter("is", IsStringifyProgrammer.
|
|
40
|
+
return parameter("is", IsStringifyProgrammer.write);
|
|
43
41
|
else if (project.options.stringify === "validate")
|
|
44
|
-
return parameter(
|
|
45
|
-
"validate",
|
|
46
|
-
ValidateStringifyProgrammer.generate,
|
|
47
|
-
);
|
|
42
|
+
return parameter("validate", ValidateStringifyProgrammer.write);
|
|
48
43
|
else if (project.options.stringify === "stringify")
|
|
49
|
-
return parameter("stringify", StringifyProgrammer.
|
|
44
|
+
return parameter("stringify", StringifyProgrammer.write);
|
|
50
45
|
else if (project.options.stringify === null)
|
|
51
46
|
return ts.factory.createNull();
|
|
52
47
|
|
|
53
48
|
// ASSERT IS DEFAULT
|
|
54
|
-
return parameter("assert", AssertStringifyProgrammer.
|
|
49
|
+
return parameter("assert", AssertStringifyProgrammer.write);
|
|
55
50
|
};
|
|
56
51
|
}
|
|
@@ -3,6 +3,7 @@ import ts from "typescript";
|
|
|
3
3
|
|
|
4
4
|
import { INestiaTransformProject } from "../options/INestiaTransformProject";
|
|
5
5
|
import { TypedBodyProgrammer } from "../programmers/TypedBodyProgrammer";
|
|
6
|
+
import { TypedParamProgrammer } from "../programmers/TypedParamProgrammer";
|
|
6
7
|
import { TypedQueryProgrammer } from "../programmers/TypedQueryProgrammer";
|
|
7
8
|
|
|
8
9
|
export namespace ParameterDecoratorTransformer {
|
|
@@ -16,7 +17,6 @@ export namespace ParameterDecoratorTransformer {
|
|
|
16
17
|
//----
|
|
17
18
|
// CHECK DECORATOR
|
|
18
19
|
if (!ts.isCallExpression(decorator.expression)) return decorator;
|
|
19
|
-
else if (decorator.expression.arguments.length !== 0) return decorator;
|
|
20
20
|
|
|
21
21
|
// SIGNATURE DECLARATION
|
|
22
22
|
const declaration: ts.Declaration | undefined =
|
|
@@ -37,7 +37,7 @@ export namespace ParameterDecoratorTransformer {
|
|
|
37
37
|
const programmer: Programmer | undefined =
|
|
38
38
|
FUNCTORS[
|
|
39
39
|
project.checker.getTypeAtLocation(declaration).symbol.name
|
|
40
|
-
]
|
|
40
|
+
];
|
|
41
41
|
if (programmer === undefined) return decorator;
|
|
42
42
|
|
|
43
43
|
// GET TYPE INFO
|
|
@@ -51,22 +51,36 @@ export namespace ParameterDecoratorTransformer {
|
|
|
51
51
|
decorator.expression,
|
|
52
52
|
decorator.expression.expression,
|
|
53
53
|
decorator.expression.typeArguments,
|
|
54
|
-
|
|
54
|
+
programmer(
|
|
55
|
+
project,
|
|
56
|
+
decorator.expression.expression,
|
|
57
|
+
)(decorator.expression.arguments)(type),
|
|
55
58
|
),
|
|
56
59
|
);
|
|
57
60
|
}
|
|
58
61
|
}
|
|
59
62
|
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
63
|
+
type Programmer = (
|
|
64
|
+
project: INestiaTransformProject,
|
|
65
|
+
modulo: ts.LeftHandSideExpression,
|
|
66
|
+
) => (
|
|
67
|
+
parameters: readonly ts.Expression[],
|
|
68
|
+
) => (type: ts.Type) => readonly ts.Expression[];
|
|
65
69
|
|
|
66
|
-
const FUNCTORS: Record<string,
|
|
67
|
-
EncryptedBody: () =>
|
|
68
|
-
|
|
69
|
-
|
|
70
|
+
const FUNCTORS: Record<string, Programmer> = {
|
|
71
|
+
EncryptedBody: (project, modulo) => (parameters) => (type) =>
|
|
72
|
+
parameters.length
|
|
73
|
+
? parameters
|
|
74
|
+
: [TypedBodyProgrammer.generate(project, modulo)(type)],
|
|
75
|
+
TypedBody: (project, modulo) => (parameters) => (type) =>
|
|
76
|
+
parameters.length
|
|
77
|
+
? parameters
|
|
78
|
+
: [TypedBodyProgrammer.generate(project, modulo)(type)],
|
|
79
|
+
TypedParam: TypedParamProgrammer.generate,
|
|
80
|
+
TypedQuery: (project, modulo) => (parameters) => (type) =>
|
|
81
|
+
parameters.length
|
|
82
|
+
? parameters
|
|
83
|
+
: [TypedQueryProgrammer.generate(project, modulo)(type)],
|
|
70
84
|
};
|
|
71
85
|
|
|
72
86
|
const LIB_PATH = path.join(
|