@nestia/core 2.2.0-dev.20231008 → 2.2.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/TypedQuery.d.ts +56 -0
- package/lib/decorators/TypedQuery.js +164 -0
- package/lib/decorators/TypedQuery.js.map +1 -1
- package/lib/decorators/internal/get_path_and_querify.d.ts +1 -0
- package/lib/decorators/internal/get_path_and_querify.js +164 -0
- package/lib/decorators/internal/get_path_and_querify.js.map +1 -0
- package/lib/options/IResponseBodyQuerifier.d.ts +20 -0
- package/lib/options/IResponseBodyQuerifier.js +3 -0
- package/lib/options/IResponseBodyQuerifier.js.map +1 -0
- package/lib/programmers/TypedQueryRouteProgrammer.d.ts +5 -0
- package/lib/programmers/TypedQueryRouteProgrammer.js +50 -0
- package/lib/programmers/TypedQueryRouteProgrammer.js.map +1 -0
- package/lib/programmers/http/HttpAssertQuerifyProgrammer.d.ts +5 -0
- package/lib/programmers/http/HttpAssertQuerifyProgrammer.js +39 -0
- package/lib/programmers/http/HttpAssertQuerifyProgrammer.js.map +1 -0
- package/lib/programmers/http/HttpIsQuerifyProgrammer.d.ts +5 -0
- package/lib/programmers/http/HttpIsQuerifyProgrammer.js +37 -0
- package/lib/programmers/http/HttpIsQuerifyProgrammer.js.map +1 -0
- package/lib/programmers/http/HttpQuerifyProgrammer.d.ts +5 -0
- package/lib/programmers/http/HttpQuerifyProgrammer.js +80 -0
- package/lib/programmers/http/HttpQuerifyProgrammer.js.map +1 -0
- package/lib/programmers/http/HttpValidateQuerifyProgrammer.d.ts +5 -0
- package/lib/programmers/http/HttpValidateQuerifyProgrammer.js +38 -0
- package/lib/programmers/http/HttpValidateQuerifyProgrammer.js.map +1 -0
- package/lib/transformers/TypedRouteTransformer.js +13 -6
- package/lib/transformers/TypedRouteTransformer.js.map +1 -1
- package/package.json +11 -11
- package/src/decorators/TypedQuery.ts +126 -0
- package/src/decorators/internal/get_path_and_querify.ts +104 -0
- package/src/options/IResponseBodyQuerifier.ts +25 -0
- package/src/programmers/TypedQueryRouteProgrammer.ts +55 -0
- package/src/programmers/http/HttpAssertQuerifyProgrammer.ts +59 -0
- package/src/programmers/http/HttpIsQuerifyProgrammer.ts +63 -0
- package/src/programmers/http/HttpQuerifyProgrammer.ts +105 -0
- package/src/programmers/http/HttpValidateQuerifyProgrammer.ts +64 -0
- package/src/transformers/TypedRouteTransformer.ts +15 -8
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"HttpIsQuerifyProgrammer.js","sourceRoot":"","sources":["../../../src/programmers/http/HttpIsQuerifyProgrammer.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;AAAA,0DAA4B;AAE5B,2EAA0E;AAC1E,yEAAwE;AACxE,mEAAkE;AAGlE,iEAAgE;AAEhE,IAAiB,uBAAuB,CAqDvC;AArDD,WAAiB,uBAAuB;IACvB,6BAAK,GACd,UAAC,OAAiB;QAClB,OAAA,UAAC,MAAiC;YAClC,OAAA,UAAC,IAAa;gBACV,OAAA,oBAAE,CAAC,OAAO,CAAC,mBAAmB,CAC1B,SAAS,EACT,SAAS,EACT,CAAC,qCAAiB,CAAC,SAAS,CAAC,OAAO,CAAC,CAAC,EACtC,SAAS,EACT,SAAS,EACT,oBAAE,CAAC,OAAO,CAAC,WAAW,CAAC;oBACnB,mCAAgB,CAAC,QAAQ,CACrB,IAAI,EACJ,2BAAY,CAAC,KAAK,uBACX,OAAO,KACV,OAAO,wBACA,OAAO,CAAC,OAAO,KAClB,UAAU,EAAE,KAAK,EACjB,OAAO,EAAE,KAAK,OAEpB,CAAC,MAAM,CAAC,CAAC,KAAK,CAAC,CAAC,IAAI,CAAC,CAC1B;oBACD,mCAAgB,CAAC,QAAQ,CACrB,WAAW,EACX,6CAAqB,CAAC,KAAK,uBACpB,OAAO,KACV,OAAO,wBACA,OAAO,CAAC,OAAO,KAClB,UAAU,EAAE,KAAK,EACjB,OAAO,EAAE,KAAK,OAEpB,CAAC,MAAM,CAAC,CAAC,IAAI,CAAC,CACnB;oBACD,oBAAE,CAAC,OAAO,CAAC,qBAAqB,CAC5B,oBAAE,CAAC,OAAO,CAAC,2BAA2B,CAClC,oBAAE,CAAC,OAAO,CAAC,oBAAoB,CAC3B,oBAAE,CAAC,OAAO,CAAC,gBAAgB,CAAC,IAAI,CAAC,EACjC,SAAS,EACT,CAAC,oBAAE,CAAC,OAAO,CAAC,gBAAgB,CAAC,OAAO,CAAC,CAAC,CACzC,EACD,SAAS,EACT,oBAAE,CAAC,OAAO,CAAC,oBAAoB,CAC3B,oBAAE,CAAC,OAAO,CAAC,gBAAgB,CAAC,WAAW,CAAC,EACxC,SAAS,EACT,CAAC,oBAAE,CAAC,OAAO,CAAC,gBAAgB,CAAC,OAAO,CAAC,CAAC,CACzC,EACD,SAAS,EACT,oBAAE,CAAC,OAAO,CAAC,UAAU,EAAE,CAC1B,CACJ;iBACJ,CAAC,CACL;YA/CD,CA+CC;QAhDL,CAgDK;IAjDL,CAiDK,CAAC;AACd,CAAC,EArDgB,uBAAuB,uCAAvB,uBAAuB,QAqDvC"}
|
|
@@ -0,0 +1,80 @@
|
|
|
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.HttpQuerifyProgrammer = void 0;
|
|
32
|
+
var typescript_1 = __importDefault(require("typescript"));
|
|
33
|
+
var IdentifierFactory_1 = require("typia/lib/factories/IdentifierFactory");
|
|
34
|
+
var MetadataCollection_1 = require("typia/lib/factories/MetadataCollection");
|
|
35
|
+
var MetadataFactory_1 = require("typia/lib/factories/MetadataFactory");
|
|
36
|
+
var StatementFactory_1 = require("typia/lib/factories/StatementFactory");
|
|
37
|
+
var FunctionImporeter_1 = require("typia/lib/programmers/helpers/FunctionImporeter");
|
|
38
|
+
var HttpQueryProgrammer_1 = require("typia/lib/programmers/http/HttpQueryProgrammer");
|
|
39
|
+
var TransformerError_1 = require("typia/lib/transformers/TransformerError");
|
|
40
|
+
var HttpQuerifyProgrammer;
|
|
41
|
+
(function (HttpQuerifyProgrammer) {
|
|
42
|
+
HttpQuerifyProgrammer.write = function (project) {
|
|
43
|
+
return function (modulo) {
|
|
44
|
+
return function (type) {
|
|
45
|
+
// GET OBJECT TYPE
|
|
46
|
+
var importer = new FunctionImporeter_1.FunctionImporter(modulo.getText());
|
|
47
|
+
var collection = new MetadataCollection_1.MetadataCollection();
|
|
48
|
+
var result = MetadataFactory_1.MetadataFactory.analyze(project.checker)({
|
|
49
|
+
escape: false,
|
|
50
|
+
constant: true,
|
|
51
|
+
absorb: true,
|
|
52
|
+
validate: HttpQueryProgrammer_1.HttpQueryProgrammer.validate,
|
|
53
|
+
})(collection)(type);
|
|
54
|
+
if (result.success === false)
|
|
55
|
+
throw TransformerError_1.TransformerError.from("@nestia.core.TypedQuery.".concat(importer.method))(result.errors);
|
|
56
|
+
var object = result.data.objects[0];
|
|
57
|
+
return typescript_1.default.factory.createArrowFunction(undefined, undefined, [IdentifierFactory_1.IdentifierFactory.parameter("input")], undefined, undefined, typescript_1.default.factory.createBlock(__spreadArray(__spreadArray(__spreadArray(__spreadArray([], __read(importer.declare(modulo)), false), [
|
|
58
|
+
StatementFactory_1.StatementFactory.constant("output", typescript_1.default.factory.createNewExpression(typescript_1.default.factory.createIdentifier("URLSearchParams"), undefined, []))
|
|
59
|
+
], false), __read(object.properties.map(function (p) {
|
|
60
|
+
return typescript_1.default.factory.createExpressionStatement(decode(p.key.constants[0].values[0])(p.value));
|
|
61
|
+
})), false), [
|
|
62
|
+
typescript_1.default.factory.createReturnStatement(typescript_1.default.factory.createIdentifier("output")),
|
|
63
|
+
], false), true));
|
|
64
|
+
};
|
|
65
|
+
};
|
|
66
|
+
};
|
|
67
|
+
var decode = function (key) {
|
|
68
|
+
return function (value) {
|
|
69
|
+
return !!value.arrays.length
|
|
70
|
+
? typescript_1.default.factory.createCallExpression(IdentifierFactory_1.IdentifierFactory.access(IdentifierFactory_1.IdentifierFactory.access(typescript_1.default.factory.createIdentifier("input"))(key))("forEach"), undefined, [
|
|
71
|
+
typescript_1.default.factory.createArrowFunction(undefined, undefined, [IdentifierFactory_1.IdentifierFactory.parameter("elem")], undefined, undefined, append(key)(typescript_1.default.factory.createIdentifier("elem"))),
|
|
72
|
+
])
|
|
73
|
+
: append(key)(IdentifierFactory_1.IdentifierFactory.access(typescript_1.default.factory.createIdentifier("input"))(key));
|
|
74
|
+
};
|
|
75
|
+
};
|
|
76
|
+
var append = function (key) { return function (elem) {
|
|
77
|
+
return typescript_1.default.factory.createCallExpression(IdentifierFactory_1.IdentifierFactory.access(typescript_1.default.factory.createIdentifier("output"))("append"), undefined, [typescript_1.default.factory.createStringLiteral(key), elem]);
|
|
78
|
+
}; };
|
|
79
|
+
})(HttpQuerifyProgrammer || (exports.HttpQuerifyProgrammer = HttpQuerifyProgrammer = {}));
|
|
80
|
+
//# sourceMappingURL=HttpQuerifyProgrammer.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"HttpQuerifyProgrammer.js","sourceRoot":"","sources":["../../../src/programmers/http/HttpQuerifyProgrammer.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,0DAA4B;AAE5B,2EAA0E;AAC1E,6EAA4E;AAC5E,uEAAsE;AACtE,yEAAwE;AACxE,qFAAmF;AACnF,sFAAqF;AAIrF,4EAA2E;AAE3E,IAAiB,qBAAqB,CA2FrC;AA3FD,WAAiB,qBAAqB;IACrB,2BAAK,GACd,UAAC,OAAiB;QAClB,OAAA,UAAC,MAAiC;YAClC,OAAA,UAAC,IAAa;gBACV,kBAAkB;gBAClB,IAAM,QAAQ,GAAqB,IAAI,oCAAgB,CACnD,MAAM,CAAC,OAAO,EAAE,CACnB,CAAC;gBACF,IAAM,UAAU,GAAuB,IAAI,uCAAkB,EAAE,CAAC;gBAChE,IAAM,MAAM,GAAG,iCAAe,CAAC,OAAO,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC;oBACpD,MAAM,EAAE,KAAK;oBACb,QAAQ,EAAE,IAAI;oBACd,MAAM,EAAE,IAAI;oBACZ,QAAQ,EAAE,yCAAmB,CAAC,QAAQ;iBACzC,CAAC,CAAC,UAAU,CAAC,CAAC,IAAI,CAAC,CAAC;gBACrB,IAAI,MAAM,CAAC,OAAO,KAAK,KAAK;oBACxB,MAAM,mCAAgB,CAAC,IAAI,CACvB,kCAA2B,QAAQ,CAAC,MAAM,CAAE,CAC/C,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC;gBAErB,IAAM,MAAM,GAAmB,MAAM,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC,CAAE,CAAC;gBACvD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AS,EACT,SAAS,EACT,CAAC,qCAAiB,CAAC,SAAS,CAAC,MAAM,CAAC,CAAC,EACrC,SAAS,EACT,SAAS,EACT,MAAM,CAAC,GAAG,CAAC,CAAC,oBAAE,CAAC,OAAO,CAAC,gBAAgB,CAAC,MAAM,CAAC,CAAC,CACnD;iBACJ,CACJ;gBACH,CAAC,CAAC,MAAM,CAAC,GAAG,CAAC,CACP,qCAAiB,CAAC,MAAM,CACpB,oBAAE,CAAC,OAAO,CAAC,gBAAgB,CAAC,OAAO,CAAC,CACvC,CAAC,GAAG,CAAC,CACT;QAvBP,CAuBO;IAxBX,CAwBW,CAAC;IAEhB,IAAM,MAAM,GAAG,UAAC,GAAW,IAAK,OAAA,UAAC,IAAmB;QAChD,OAAA,oBAAE,CAAC,OAAO,CAAC,oBAAoB,CAC3B,qCAAiB,CAAC,MAAM,CAAC,oBAAE,CAAC,OAAO,CAAC,gBAAgB,CAAC,QAAQ,CAAC,CAAC,CAC3D,QAAQ,CACX,EACD,SAAS,EACT,CAAC,oBAAE,CAAC,OAAO,CAAC,mBAAmB,CAAC,GAAG,CAAC,EAAE,IAAI,CAAC,CAC9C;IAND,CAMC,EAP2B,CAO3B,CAAC;AACV,CAAC,EA3FgB,qBAAqB,qCAArB,qBAAqB,QA2FrC"}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import ts from "typescript";
|
|
2
|
+
import { IProject } from "typia/lib/transformers/IProject";
|
|
3
|
+
export declare namespace HttpValidateQuerifyProgrammer {
|
|
4
|
+
const write: (project: IProject) => (modulo: ts.LeftHandSideExpression) => (type: ts.Type, name?: string) => ts.ArrowFunction;
|
|
5
|
+
}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __assign = (this && this.__assign) || function () {
|
|
3
|
+
__assign = Object.assign || function(t) {
|
|
4
|
+
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
5
|
+
s = arguments[i];
|
|
6
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
7
|
+
t[p] = s[p];
|
|
8
|
+
}
|
|
9
|
+
return t;
|
|
10
|
+
};
|
|
11
|
+
return __assign.apply(this, arguments);
|
|
12
|
+
};
|
|
13
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
14
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
exports.HttpValidateQuerifyProgrammer = void 0;
|
|
18
|
+
var typescript_1 = __importDefault(require("typescript"));
|
|
19
|
+
var IdentifierFactory_1 = require("typia/lib/factories/IdentifierFactory");
|
|
20
|
+
var StatementFactory_1 = require("typia/lib/factories/StatementFactory");
|
|
21
|
+
var ValidateProgrammer_1 = require("typia/lib/programmers/ValidateProgrammer");
|
|
22
|
+
var HttpQuerifyProgrammer_1 = require("./HttpQuerifyProgrammer");
|
|
23
|
+
var HttpValidateQuerifyProgrammer;
|
|
24
|
+
(function (HttpValidateQuerifyProgrammer) {
|
|
25
|
+
HttpValidateQuerifyProgrammer.write = function (project) {
|
|
26
|
+
return function (modulo) {
|
|
27
|
+
return function (type, name) {
|
|
28
|
+
return typescript_1.default.factory.createArrowFunction(undefined, undefined, [IdentifierFactory_1.IdentifierFactory.parameter("input")], undefined, undefined, typescript_1.default.factory.createBlock([
|
|
29
|
+
StatementFactory_1.StatementFactory.constant("validate", ValidateProgrammer_1.ValidateProgrammer.write(__assign(__assign({}, project), { options: __assign(__assign({}, project.options), { functional: false, numeric: true }) }))(modulo)(false)(type, name)),
|
|
30
|
+
StatementFactory_1.StatementFactory.constant("query", HttpQuerifyProgrammer_1.HttpQuerifyProgrammer.write(__assign(__assign({}, project), { options: __assign(__assign({}, project.options), { functional: false, numeric: false }) }))(modulo)(type)),
|
|
31
|
+
StatementFactory_1.StatementFactory.constant("output", typescript_1.default.factory.createCallExpression(typescript_1.default.factory.createIdentifier("query"), undefined, [typescript_1.default.factory.createIdentifier("input")])),
|
|
32
|
+
typescript_1.default.factory.createReturnStatement(typescript_1.default.factory.createAsExpression(typescript_1.default.factory.createCallExpression(typescript_1.default.factory.createIdentifier("validate"), undefined, [typescript_1.default.factory.createIdentifier("output")]), typescript_1.default.factory.createTypeReferenceNode("any"))),
|
|
33
|
+
]));
|
|
34
|
+
};
|
|
35
|
+
};
|
|
36
|
+
};
|
|
37
|
+
})(HttpValidateQuerifyProgrammer || (exports.HttpValidateQuerifyProgrammer = HttpValidateQuerifyProgrammer = {}));
|
|
38
|
+
//# sourceMappingURL=HttpValidateQuerifyProgrammer.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"HttpValidateQuerifyProgrammer.js","sourceRoot":"","sources":["../../../src/programmers/http/HttpValidateQuerifyProgrammer.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;AAAA,0DAA4B;AAE5B,2EAA0E;AAC1E,yEAAwE;AACxE,+EAA8E;AAG9E,iEAAgE;AAEhE,IAAiB,6BAA6B,CAsD7C;AAtDD,WAAiB,6BAA6B;IAC7B,mCAAK,GACd,UAAC,OAAiB;QAClB,OAAA,UAAC,MAAiC;YAClC,OAAA,UAAC,IAAa,EAAE,IAAa;gBACzB,OAAA,oBAAE,CAAC,OAAO,CAAC,mBAAmB,CAC1B,SAAS,EACT,SAAS,EACT,CAAC,qCAAiB,CAAC,SAAS,CAAC,OAAO,CAAC,CAAC,EACtC,SAAS,EACT,SAAS,EACT,oBAAE,CAAC,OAAO,CAAC,WAAW,CAAC;oBACnB,mCAAgB,CAAC,QAAQ,CACrB,UAAU,EACV,uCAAkB,CAAC,KAAK,uBACjB,OAAO,KACV,OAAO,wBACA,OAAO,CAAC,OAAO,KAClB,UAAU,EAAE,KAAK,EACjB,OAAO,EAAE,IAAI,OAEnB,CAAC,MAAM,CAAC,CAAC,KAAK,CAAC,CAAC,IAAI,EAAE,IAAI,CAAC,CAChC;oBACD,mCAAgB,CAAC,QAAQ,CACrB,OAAO,EACP,6CAAqB,CAAC,KAAK,uBACpB,OAAO,KACV,OAAO,wBACA,OAAO,CAAC,OAAO,KAClB,UAAU,EAAE,KAAK,EACjB,OAAO,EAAE,KAAK,OAEpB,CAAC,MAAM,CAAC,CAAC,IAAI,CAAC,CACnB;oBACD,mCAAgB,CAAC,QAAQ,CACrB,QAAQ,EACR,oBAAE,CAAC,OAAO,CAAC,oBAAoB,CAC3B,oBAAE,CAAC,OAAO,CAAC,gBAAgB,CAAC,OAAO,CAAC,EACpC,SAAS,EACT,CAAC,oBAAE,CAAC,OAAO,CAAC,gBAAgB,CAAC,OAAO,CAAC,CAAC,CACzC,CACJ;oBACD,oBAAE,CAAC,OAAO,CAAC,qBAAqB,CAC5B,oBAAE,CAAC,OAAO,CAAC,kBAAkB,CACzB,oBAAE,CAAC,OAAO,CAAC,oBAAoB,CAC3B,oBAAE,CAAC,OAAO,CAAC,gBAAgB,CAAC,UAAU,CAAC,EACvC,SAAS,EACT,CAAC,oBAAE,CAAC,OAAO,CAAC,gBAAgB,CAAC,QAAQ,CAAC,CAAC,CAC1C,EACD,oBAAE,CAAC,OAAO,CAAC,uBAAuB,CAAC,KAAK,CAAC,CAC5C,CACJ;iBACJ,CAAC,CACL;YAhDD,CAgDC;QAjDL,CAiDK;IAlDL,CAkDK,CAAC;AACd,CAAC,EAtDgB,6BAA6B,6CAA7B,6BAA6B,QAsD7C"}
|
|
@@ -31,6 +31,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
31
31
|
exports.TypedRouteTransformer = void 0;
|
|
32
32
|
var path_1 = __importDefault(require("path"));
|
|
33
33
|
var typescript_1 = __importDefault(require("typescript"));
|
|
34
|
+
var TypedQueryRouteProgrammer_1 = require("../programmers/TypedQueryRouteProgrammer");
|
|
34
35
|
var TypedRouteProgrammer_1 = require("../programmers/TypedRouteProgrammer");
|
|
35
36
|
var TypedRouteTransformer;
|
|
36
37
|
(function (TypedRouteTransformer) {
|
|
@@ -44,12 +45,13 @@ var TypedRouteTransformer;
|
|
|
44
45
|
if (!signature || !signature.declaration)
|
|
45
46
|
return decorator;
|
|
46
47
|
// CHECK TO BE TRANSFORMED
|
|
47
|
-
var
|
|
48
|
+
var modulo = (function () {
|
|
49
|
+
var _a;
|
|
48
50
|
// CHECK FILENAME
|
|
49
51
|
var location = path_1.default.resolve(signature.declaration.getSourceFile().fileName);
|
|
50
52
|
if (LIB_PATHS.every(function (str) { return location.indexOf(str) === -1; }) &&
|
|
51
53
|
SRC_PATHS.every(function (str) { return location !== str; }))
|
|
52
|
-
return
|
|
54
|
+
return null;
|
|
53
55
|
// CHECK DUPLICATE BOOSTER
|
|
54
56
|
if (decorator.expression.arguments.length >= 2)
|
|
55
57
|
return false;
|
|
@@ -59,9 +61,12 @@ var TypedRouteTransformer;
|
|
|
59
61
|
if (isObject(project.checker)(type_1))
|
|
60
62
|
return false;
|
|
61
63
|
}
|
|
62
|
-
return
|
|
64
|
+
return ((_a = location.split(path_1.default.sep).at(-1)) === null || _a === void 0 ? void 0 : _a.split(".")[0]) ===
|
|
65
|
+
"TypedQuery"
|
|
66
|
+
? "TypedQuery"
|
|
67
|
+
: "TypedRoute";
|
|
63
68
|
})();
|
|
64
|
-
if (
|
|
69
|
+
if (modulo === null)
|
|
65
70
|
return decorator;
|
|
66
71
|
// CHECK TYPE NODE
|
|
67
72
|
var typeNode = project.checker.typeToTypeNode(type, undefined, undefined);
|
|
@@ -69,7 +74,9 @@ var TypedRouteTransformer;
|
|
|
69
74
|
return decorator;
|
|
70
75
|
// DO TRANSFORM
|
|
71
76
|
return typescript_1.default.factory.createDecorator(typescript_1.default.factory.updateCallExpression(decorator.expression, decorator.expression.expression, decorator.expression.typeArguments, __spreadArray(__spreadArray([], __read(decorator.expression.arguments), false), [
|
|
72
|
-
|
|
77
|
+
(modulo === "TypedQuery"
|
|
78
|
+
? TypedQueryRouteProgrammer_1.TypedQueryRouteProgrammer
|
|
79
|
+
: TypedRouteProgrammer_1.TypedRouteProgrammer).generate(project)(decorator.expression.expression)(type),
|
|
73
80
|
], false)));
|
|
74
81
|
};
|
|
75
82
|
};
|
|
@@ -82,7 +89,7 @@ var TypedRouteTransformer;
|
|
|
82
89
|
!checker.isArrayLikeType(type);
|
|
83
90
|
};
|
|
84
91
|
};
|
|
85
|
-
var CLASSES = ["EncryptedRoute", "TypedRoute"];
|
|
92
|
+
var CLASSES = ["EncryptedRoute", "TypedRoute", "TypedQuery"];
|
|
86
93
|
var LIB_PATHS = CLASSES.map(function (cla) {
|
|
87
94
|
return path_1.default.join("node_modules", "@nestia", "core", "lib", "decorators", "".concat(cla, ".d.ts"));
|
|
88
95
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"TypedRouteTransformer.js","sourceRoot":"","sources":["../../src/transformers/TypedRouteTransformer.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,8CAAwB;AACxB,0DAA4B;AAG5B,4EAA2E;AAE3E,IAAiB,qBAAqB,
|
|
1
|
+
{"version":3,"file":"TypedRouteTransformer.js","sourceRoot":"","sources":["../../src/transformers/TypedRouteTransformer.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,8CAAwB;AACxB,0DAA4B;AAG5B,sFAAqF;AACrF,4EAA2E;AAE3E,IAAiB,qBAAqB,CAwFrC;AAxFD,WAAiB,qBAAqB;IACrB,+BAAS,GAClB,UAAC,OAAgC;QACjC,OAAA,UAAC,IAAa;YACd,OAAA,UAAC,SAAuB;gBACpB,IAAI,CAAC,oBAAE,CAAC,gBAAgB,CAAC,SAAS,CAAC,UAAU,CAAC;oBAAE,OAAO,SAAS,CAAC;gBAEjE,kBAAkB;gBAClB,IAAM,SAAS,GACX,OAAO,CAAC,OAAO,CAAC,oBAAoB,CAAC,SAAS,CAAC,UAAU,CAAC,CAAC;gBAC/D,IAAI,CAAC,SAAS,IAAI,CAAC,SAAS,CAAC,WAAW;oBAAE,OAAO,SAAS,CAAC;gBAE3D,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UAAG,GAAG,UAAO,CAChB;IAPD,CAOC,CACJ,CAAC;IACF,IAAM,SAAS,GAAG,OAAO,CAAC,GAAG,CAAC,UAAC,GAAG;QAC9B,OAAA,cAAI,CAAC,OAAO,CAAC,cAAI,CAAC,IAAI,CAAC,SAAS,EAAE,IAAI,EAAE,YAAY,EAAE,UAAG,GAAG,QAAK,CAAC,CAAC;IAAnE,CAAmE,CACtE,CAAC;AACN,CAAC,EAxFgB,qBAAqB,qCAArB,qBAAqB,QAwFrC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nestia/core",
|
|
3
|
-
"version": "2.2.0
|
|
3
|
+
"version": "2.2.0",
|
|
4
4
|
"description": "Super-fast validation decorators of NestJS",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"typings": "lib/index.d.ts",
|
|
@@ -34,20 +34,20 @@
|
|
|
34
34
|
},
|
|
35
35
|
"homepage": "https://nestia.io",
|
|
36
36
|
"dependencies": {
|
|
37
|
-
"@nestia/fetcher": "^2.2.0
|
|
38
|
-
"@nestjs/common": ">=
|
|
39
|
-
"@nestjs/core": ">=
|
|
40
|
-
"@nestjs/platform-express": ">=
|
|
41
|
-
"@nestjs/platform-fastify": ">=
|
|
37
|
+
"@nestia/fetcher": "^2.2.0",
|
|
38
|
+
"@nestjs/common": ">=7.0.1",
|
|
39
|
+
"@nestjs/core": ">=7.0.1",
|
|
40
|
+
"@nestjs/platform-express": ">=7.0.1",
|
|
41
|
+
"@nestjs/platform-fastify": ">=7.0.1",
|
|
42
42
|
"detect-ts-node": "^1.0.5",
|
|
43
43
|
"glob": "^7.2.0",
|
|
44
|
-
"raw-body": ">=
|
|
45
|
-
"reflect-metadata": ">=
|
|
46
|
-
"rxjs": ">=
|
|
47
|
-
"typia": "
|
|
44
|
+
"raw-body": ">=2.0.0",
|
|
45
|
+
"reflect-metadata": ">=0.1.12",
|
|
46
|
+
"rxjs": ">=6.0.0",
|
|
47
|
+
"typia": ">=5.2.0 <6.0.0"
|
|
48
48
|
},
|
|
49
49
|
"peerDependencies": {
|
|
50
|
-
"@nestia/fetcher": ">=2.2.0
|
|
50
|
+
"@nestia/fetcher": ">=2.2.0",
|
|
51
51
|
"@nestjs/common": ">=7.0.1",
|
|
52
52
|
"@nestjs/core": ">=7.0.1",
|
|
53
53
|
"@nestjs/platform-express": ">=7.0.1",
|
|
@@ -1,14 +1,28 @@
|
|
|
1
1
|
import {
|
|
2
2
|
BadRequestException,
|
|
3
|
+
CallHandler,
|
|
4
|
+
Delete,
|
|
3
5
|
ExecutionContext,
|
|
6
|
+
Get,
|
|
7
|
+
NestInterceptor,
|
|
8
|
+
Patch,
|
|
9
|
+
Post,
|
|
10
|
+
Put,
|
|
11
|
+
UseInterceptors,
|
|
12
|
+
applyDecorators,
|
|
4
13
|
createParamDecorator,
|
|
5
14
|
} from "@nestjs/common";
|
|
15
|
+
import { HttpArgumentsHost } from "@nestjs/common/interfaces";
|
|
6
16
|
import type express from "express";
|
|
7
17
|
import type { FastifyRequest } from "fastify";
|
|
18
|
+
import { catchError, map } from "rxjs";
|
|
8
19
|
|
|
9
20
|
import typia from "typia";
|
|
10
21
|
|
|
11
22
|
import { IRequestQueryValidator } from "../options/IRequestQueryValidator";
|
|
23
|
+
import { IResponseBodyQuerifier } from "../options/IResponseBodyQuerifier";
|
|
24
|
+
import { get_path_and_querify } from "./internal/get_path_and_querify";
|
|
25
|
+
import { route_error } from "./internal/route_error";
|
|
12
26
|
import { validate_request_query } from "./internal/validate_request_query";
|
|
13
27
|
|
|
14
28
|
/**
|
|
@@ -77,6 +91,81 @@ export namespace TypedQuery {
|
|
|
77
91
|
Object.assign(Body, typia.http.assertQuery);
|
|
78
92
|
Object.assign(Body, typia.http.isQuery);
|
|
79
93
|
Object.assign(Body, typia.http.validateQuery);
|
|
94
|
+
|
|
95
|
+
/**
|
|
96
|
+
* Router decorator function for the GET method.
|
|
97
|
+
*
|
|
98
|
+
* @param path Path of the HTTP request
|
|
99
|
+
* @returns Method decorator
|
|
100
|
+
*/
|
|
101
|
+
export const Get = Generator("Get");
|
|
102
|
+
|
|
103
|
+
/**
|
|
104
|
+
* Router decorator function for the POST method.
|
|
105
|
+
*
|
|
106
|
+
* @param path Path of the HTTP request
|
|
107
|
+
* @returns Method decorator
|
|
108
|
+
*/
|
|
109
|
+
export const Post = Generator("Post");
|
|
110
|
+
|
|
111
|
+
/**
|
|
112
|
+
* Router decorator function for the PATH method.
|
|
113
|
+
*
|
|
114
|
+
* @param path Path of the HTTP request
|
|
115
|
+
* @returns Method decorator
|
|
116
|
+
*/
|
|
117
|
+
export const Patch = Generator("Patch");
|
|
118
|
+
|
|
119
|
+
/**
|
|
120
|
+
* Router decorator function for the PUT method.
|
|
121
|
+
*
|
|
122
|
+
* @param path Path of the HTTP request
|
|
123
|
+
* @returns Method decorator
|
|
124
|
+
*/
|
|
125
|
+
export const Put = Generator("Put");
|
|
126
|
+
|
|
127
|
+
/**
|
|
128
|
+
* Router decorator function for the DELETE method.
|
|
129
|
+
*
|
|
130
|
+
* @param path Path of the HTTP request
|
|
131
|
+
* @returns Method decorator
|
|
132
|
+
*/
|
|
133
|
+
export const Delete = Generator("Delete");
|
|
134
|
+
|
|
135
|
+
/**
|
|
136
|
+
* @internal
|
|
137
|
+
*/
|
|
138
|
+
function Generator(method: "Get" | "Post" | "Put" | "Patch" | "Delete") {
|
|
139
|
+
function route(path?: string | string[]): MethodDecorator;
|
|
140
|
+
function route<T>(
|
|
141
|
+
stringify?: IResponseBodyQuerifier<T>,
|
|
142
|
+
): MethodDecorator;
|
|
143
|
+
function route<T>(
|
|
144
|
+
path: string | string[],
|
|
145
|
+
stringify?: IResponseBodyQuerifier<T>,
|
|
146
|
+
): MethodDecorator;
|
|
147
|
+
|
|
148
|
+
function route(...args: any[]): MethodDecorator {
|
|
149
|
+
const [path, stringify] = get_path_and_querify(
|
|
150
|
+
`TypedQuery.${method}`,
|
|
151
|
+
)(...args);
|
|
152
|
+
return applyDecorators(
|
|
153
|
+
ROUTERS[method](path),
|
|
154
|
+
UseInterceptors(new TypedQueryRouteInterceptor(stringify)),
|
|
155
|
+
);
|
|
156
|
+
}
|
|
157
|
+
return route;
|
|
158
|
+
}
|
|
159
|
+
for (const method of [typia.assert, typia.is, typia.validate])
|
|
160
|
+
for (const [key, value] of Object.entries(method))
|
|
161
|
+
for (const deco of [
|
|
162
|
+
TypedQuery.Get,
|
|
163
|
+
TypedQuery.Delete,
|
|
164
|
+
TypedQuery.Post,
|
|
165
|
+
TypedQuery.Put,
|
|
166
|
+
TypedQuery.Patch,
|
|
167
|
+
])
|
|
168
|
+
(deco as any)[key] = value;
|
|
80
169
|
}
|
|
81
170
|
Object.assign(TypedQuery, typia.http.assertQuery);
|
|
82
171
|
Object.assign(TypedQuery, typia.http.isQuery);
|
|
@@ -90,6 +179,9 @@ function tail(url: string): string {
|
|
|
90
179
|
return index === -1 ? "" : url.substring(index + 1);
|
|
91
180
|
}
|
|
92
181
|
|
|
182
|
+
/**
|
|
183
|
+
* @internal
|
|
184
|
+
*/
|
|
93
185
|
function isApplicationQuery(text?: string): boolean {
|
|
94
186
|
return (
|
|
95
187
|
text !== undefined &&
|
|
@@ -100,6 +192,9 @@ function isApplicationQuery(text?: string): boolean {
|
|
|
100
192
|
);
|
|
101
193
|
}
|
|
102
194
|
|
|
195
|
+
/**
|
|
196
|
+
* @internal
|
|
197
|
+
*/
|
|
103
198
|
class FakeURLSearchParams {
|
|
104
199
|
public constructor(private readonly target: Record<string, string[]>) {}
|
|
105
200
|
|
|
@@ -125,3 +220,34 @@ class FakeURLSearchParams {
|
|
|
125
220
|
: [value];
|
|
126
221
|
}
|
|
127
222
|
}
|
|
223
|
+
|
|
224
|
+
/**
|
|
225
|
+
* @internal
|
|
226
|
+
*/
|
|
227
|
+
class TypedQueryRouteInterceptor implements NestInterceptor {
|
|
228
|
+
public constructor(
|
|
229
|
+
private readonly toSearchParams: (input: any) => URLSearchParams,
|
|
230
|
+
) {}
|
|
231
|
+
|
|
232
|
+
public intercept(context: ExecutionContext, next: CallHandler) {
|
|
233
|
+
const http: HttpArgumentsHost = context.switchToHttp();
|
|
234
|
+
const response: express.Response = http.getResponse();
|
|
235
|
+
response.header("Content-Type", "application/x-www-form-urlencoded");
|
|
236
|
+
|
|
237
|
+
return next.handle().pipe(
|
|
238
|
+
map((value) => this.toSearchParams(value).toString()),
|
|
239
|
+
catchError((err) => route_error(http.getRequest(), err)),
|
|
240
|
+
);
|
|
241
|
+
}
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
/**
|
|
245
|
+
* @internal
|
|
246
|
+
*/
|
|
247
|
+
const ROUTERS = {
|
|
248
|
+
Get,
|
|
249
|
+
Post,
|
|
250
|
+
Patch,
|
|
251
|
+
Put,
|
|
252
|
+
Delete,
|
|
253
|
+
};
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
import { InternalServerErrorException } from "@nestjs/common";
|
|
2
|
+
|
|
3
|
+
import typia, { IValidation, TypeGuardError } from "typia";
|
|
4
|
+
|
|
5
|
+
import { IResponseBodyQuerifier } from "../../options/IResponseBodyQuerifier";
|
|
6
|
+
import { NoTransformConfigureError } from "./NoTransformConfigureError";
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* @internal
|
|
10
|
+
*/
|
|
11
|
+
export const get_path_and_querify =
|
|
12
|
+
(method: string) =>
|
|
13
|
+
(
|
|
14
|
+
...args: any[]
|
|
15
|
+
): [string | string[] | undefined, (input: any) => URLSearchParams] => {
|
|
16
|
+
const path: string | string[] | null | undefined =
|
|
17
|
+
args[0] === undefined ||
|
|
18
|
+
typeof args[0] === "string" ||
|
|
19
|
+
Array.isArray(args[0])
|
|
20
|
+
? args[0]
|
|
21
|
+
: null;
|
|
22
|
+
const functor: IResponseBodyQuerifier<any> | undefined =
|
|
23
|
+
path === null ? args[0] : args[1];
|
|
24
|
+
return [path ?? undefined, take(method)(functor)];
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* @internal
|
|
29
|
+
*/
|
|
30
|
+
const take =
|
|
31
|
+
(method: string) =>
|
|
32
|
+
<T>(functor?: IResponseBodyQuerifier<T> | null) => {
|
|
33
|
+
if (functor === undefined) throw NoTransformConfigureError(method);
|
|
34
|
+
else if (functor === null) return querify;
|
|
35
|
+
else if (functor.type === "stringify") return functor.stringify;
|
|
36
|
+
else if (functor.type === "assert") return assert(functor.assert);
|
|
37
|
+
else if (functor.type === "is") return is(functor.is);
|
|
38
|
+
else if (functor.type === "validate") return validate(functor.validate);
|
|
39
|
+
throw new Error(
|
|
40
|
+
`Error on nestia.core.${method}(): invalid typed stringify function.`,
|
|
41
|
+
);
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
const querify = (input: Record<string, any>): URLSearchParams => {
|
|
45
|
+
const output: URLSearchParams = new URLSearchParams();
|
|
46
|
+
for (const [key, value] of Object.entries(input))
|
|
47
|
+
if (key === undefined) continue;
|
|
48
|
+
else if (Array.isArray(value))
|
|
49
|
+
for (const elem of value) output.append(key, String(elem));
|
|
50
|
+
else output.append(key, String(value));
|
|
51
|
+
return output;
|
|
52
|
+
};
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* @internal
|
|
56
|
+
*/
|
|
57
|
+
const assert =
|
|
58
|
+
<T>(closure: (data: T) => URLSearchParams) =>
|
|
59
|
+
(data: T) => {
|
|
60
|
+
try {
|
|
61
|
+
return closure(data);
|
|
62
|
+
} catch (exp) {
|
|
63
|
+
if (typia.is<TypeGuardError>(exp))
|
|
64
|
+
throw new InternalServerErrorException({
|
|
65
|
+
path: exp.path,
|
|
66
|
+
reason: exp.message,
|
|
67
|
+
expected: exp.expected,
|
|
68
|
+
value: exp.value,
|
|
69
|
+
message: MESSAGE,
|
|
70
|
+
});
|
|
71
|
+
throw exp;
|
|
72
|
+
}
|
|
73
|
+
};
|
|
74
|
+
|
|
75
|
+
/**
|
|
76
|
+
* @internal
|
|
77
|
+
*/
|
|
78
|
+
const is =
|
|
79
|
+
<T>(closure: (data: T) => URLSearchParams | null) =>
|
|
80
|
+
(data: T) => {
|
|
81
|
+
const result: URLSearchParams | null = closure(data);
|
|
82
|
+
if (result === null) throw new InternalServerErrorException(MESSAGE);
|
|
83
|
+
return result;
|
|
84
|
+
};
|
|
85
|
+
|
|
86
|
+
/**
|
|
87
|
+
* @internal
|
|
88
|
+
*/
|
|
89
|
+
const validate =
|
|
90
|
+
<T>(closure: (data: T) => IValidation<URLSearchParams>) =>
|
|
91
|
+
(data: T) => {
|
|
92
|
+
const result: IValidation<URLSearchParams> = closure(data);
|
|
93
|
+
if (result.success === false)
|
|
94
|
+
throw new InternalServerErrorException({
|
|
95
|
+
errors: result.errors,
|
|
96
|
+
message: MESSAGE,
|
|
97
|
+
});
|
|
98
|
+
return result.data;
|
|
99
|
+
};
|
|
100
|
+
|
|
101
|
+
/**
|
|
102
|
+
* @internal
|
|
103
|
+
*/
|
|
104
|
+
const MESSAGE = "Response body data is not following the promised type.";
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { IValidation } from "typia";
|
|
2
|
+
|
|
3
|
+
export type IResponseBodyQuerifier<T> =
|
|
4
|
+
| IResponseBodyquerifier.IStringify<T>
|
|
5
|
+
| IResponseBodyquerifier.IIs<T>
|
|
6
|
+
| IResponseBodyquerifier.IAssert<T>
|
|
7
|
+
| IResponseBodyquerifier.IValidate<T>;
|
|
8
|
+
export namespace IResponseBodyquerifier {
|
|
9
|
+
export interface IStringify<T> {
|
|
10
|
+
type: "stringify";
|
|
11
|
+
stringify: (input: T) => URLSearchParams;
|
|
12
|
+
}
|
|
13
|
+
export interface IIs<T> {
|
|
14
|
+
type: "is";
|
|
15
|
+
is: (input: T) => URLSearchParams | null;
|
|
16
|
+
}
|
|
17
|
+
export interface IAssert<T> {
|
|
18
|
+
type: "assert";
|
|
19
|
+
assert: (input: T) => URLSearchParams;
|
|
20
|
+
}
|
|
21
|
+
export interface IValidate<T> {
|
|
22
|
+
type: "validate";
|
|
23
|
+
validate: (input: T) => IValidation<URLSearchParams>;
|
|
24
|
+
}
|
|
25
|
+
}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import ts from "typescript";
|
|
2
|
+
|
|
3
|
+
import { IProject } from "typia/lib/transformers/IProject";
|
|
4
|
+
|
|
5
|
+
import { INestiaTransformProject } from "../options/INestiaTransformProject";
|
|
6
|
+
import { HttpAssertQuerifyProgrammer } from "./http/HttpAssertQuerifyProgrammer";
|
|
7
|
+
import { HttpIsQuerifyProgrammer } from "./http/HttpIsQuerifyProgrammer";
|
|
8
|
+
import { HttpQuerifyProgrammer } from "./http/HttpQuerifyProgrammer";
|
|
9
|
+
import { HttpValidateQuerifyProgrammer } from "./http/HttpValidateQuerifyProgrammer";
|
|
10
|
+
|
|
11
|
+
export namespace TypedQueryRouteProgrammer {
|
|
12
|
+
export const generate =
|
|
13
|
+
(project: INestiaTransformProject) =>
|
|
14
|
+
(modulo: ts.LeftHandSideExpression) =>
|
|
15
|
+
(type: ts.Type): ts.Expression => {
|
|
16
|
+
// GENERATE STRINGIFY PLAN
|
|
17
|
+
const parameter = (
|
|
18
|
+
key: string,
|
|
19
|
+
programmer: (
|
|
20
|
+
project: IProject,
|
|
21
|
+
) => (
|
|
22
|
+
modulo: ts.LeftHandSideExpression,
|
|
23
|
+
) => (type: ts.Type) => ts.ArrowFunction,
|
|
24
|
+
) =>
|
|
25
|
+
ts.factory.createObjectLiteralExpression([
|
|
26
|
+
ts.factory.createPropertyAssignment(
|
|
27
|
+
ts.factory.createIdentifier("type"),
|
|
28
|
+
ts.factory.createStringLiteral(key),
|
|
29
|
+
),
|
|
30
|
+
ts.factory.createPropertyAssignment(
|
|
31
|
+
ts.factory.createIdentifier(key),
|
|
32
|
+
programmer({
|
|
33
|
+
...project,
|
|
34
|
+
options: {}, // use default option
|
|
35
|
+
})(modulo)(type),
|
|
36
|
+
),
|
|
37
|
+
]);
|
|
38
|
+
|
|
39
|
+
// RETURNS
|
|
40
|
+
if (project.options.stringify === "is")
|
|
41
|
+
return parameter("is", HttpIsQuerifyProgrammer.write);
|
|
42
|
+
else if (project.options.stringify === "validate")
|
|
43
|
+
return parameter(
|
|
44
|
+
"validate",
|
|
45
|
+
HttpValidateQuerifyProgrammer.write,
|
|
46
|
+
);
|
|
47
|
+
else if (project.options.stringify === "stringify")
|
|
48
|
+
return parameter("stringify", HttpQuerifyProgrammer.write);
|
|
49
|
+
else if (project.options.stringify === null)
|
|
50
|
+
return ts.factory.createNull();
|
|
51
|
+
|
|
52
|
+
// ASSERT IS DEFAULT
|
|
53
|
+
return parameter("assert", HttpAssertQuerifyProgrammer.write);
|
|
54
|
+
};
|
|
55
|
+
}
|