@nestia/sdk 2.5.0-dev.20240129 → 2.5.0-dev.20240129-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/NestiaSdkApplication.js +1 -1
- package/lib/NestiaSdkApplication.js.map +1 -1
- package/lib/generates/CloneGenerator.d.ts +6 -0
- package/lib/generates/CloneGenerator.js +60 -0
- package/lib/generates/CloneGenerator.js.map +1 -0
- package/lib/generates/E2eGenerator.d.ts +2 -1
- package/lib/generates/E2eGenerator.js +2 -2
- package/lib/generates/E2eGenerator.js.map +1 -1
- package/lib/generates/SdkGenerator.js +3 -3
- package/lib/generates/SdkGenerator.js.map +1 -1
- package/lib/generates/internal/E2eFileProgrammer.d.ts +2 -1
- package/lib/generates/internal/E2eFileProgrammer.js +12 -16
- package/lib/generates/internal/E2eFileProgrammer.js.map +1 -1
- package/lib/generates/internal/SdkAliasCollection.d.ts +12 -0
- package/lib/generates/internal/SdkAliasCollection.js +89 -0
- package/lib/generates/internal/SdkAliasCollection.js.map +1 -0
- package/lib/generates/internal/SdkFileProgrammer.d.ts +2 -1
- package/lib/generates/internal/SdkFileProgrammer.js +5 -5
- package/lib/generates/internal/SdkFileProgrammer.js.map +1 -1
- package/lib/generates/internal/SdkFunctionProgrammer.js +6 -6
- package/lib/generates/internal/SdkFunctionProgrammer.js.map +1 -1
- package/lib/generates/internal/SdkInterfaceProgrammer.d.ts +12 -0
- package/lib/generates/internal/SdkInterfaceProgrammer.js +112 -0
- package/lib/generates/internal/SdkInterfaceProgrammer.js.map +1 -0
- package/lib/generates/internal/SdkNamespaceProgrammer.d.ts +1 -1
- package/lib/generates/internal/SdkNamespaceProgrammer.js +19 -18
- package/lib/generates/internal/SdkNamespaceProgrammer.js.map +1 -1
- package/lib/generates/internal/SdkRouteProgrammer.d.ts +1 -1
- package/lib/generates/internal/SdkRouteProgrammer.js +2 -2
- package/lib/generates/internal/SdkRouteProgrammer.js.map +1 -1
- package/lib/generates/internal/SdkSimulationProgrammer.d.ts +1 -1
- package/lib/generates/internal/SdkSimulationProgrammer.js +11 -12
- package/lib/generates/internal/SdkSimulationProgrammer.js.map +1 -1
- package/lib/generates/internal/{SdkDtoGenerator.d.ts → SdkTypeProgrammer.d.ts} +2 -4
- package/lib/generates/internal/SdkTypeProgrammer.js +160 -0
- package/lib/generates/internal/SdkTypeProgrammer.js.map +1 -0
- package/lib/utils/FormatUtil.js +3 -1
- package/lib/utils/FormatUtil.js.map +1 -1
- package/package.json +3 -3
- package/src/NestiaSdkApplication.ts +1 -1
- package/src/generates/CloneGenerator.ts +75 -0
- package/src/generates/E2eGenerator.ts +3 -1
- package/src/generates/SdkGenerator.ts +3 -3
- package/src/generates/internal/E2eFileProgrammer.ts +12 -19
- package/src/generates/internal/SdkAliasCollection.ts +145 -0
- package/src/generates/internal/SdkFileProgrammer.ts +5 -3
- package/src/generates/internal/SdkFunctionProgrammer.ts +9 -9
- package/src/generates/internal/SdkInterfaceProgrammer.ts +211 -0
- package/src/generates/internal/SdkNamespaceProgrammer.ts +31 -19
- package/src/generates/internal/SdkRouteProgrammer.ts +5 -1
- package/src/generates/internal/SdkSimulationProgrammer.ts +14 -16
- package/src/generates/internal/SdkTypeProgrammer.ts +252 -0
- package/src/utils/FormatUtil.ts +2 -1
- package/lib/generates/internal/SdkDtoGenerator.js +0 -295
- package/lib/generates/internal/SdkDtoGenerator.js.map +0 -1
- package/lib/generates/internal/SdkTypeDefiner.d.ts +0 -11
- package/lib/generates/internal/SdkTypeDefiner.js +0 -82
- package/lib/generates/internal/SdkTypeDefiner.js.map +0 -1
- package/src/generates/internal/SdkDtoGenerator.ts +0 -429
- package/src/generates/internal/SdkTypeDefiner.ts +0 -119
|
@@ -0,0 +1,160 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.SdkTypeProgrammer = void 0;
|
|
7
|
+
const typescript_1 = __importDefault(require("typescript"));
|
|
8
|
+
const ExpressionFactory_1 = require("typia/lib/factories/ExpressionFactory");
|
|
9
|
+
const TypeFactory_1 = require("typia/lib/factories/TypeFactory");
|
|
10
|
+
var SdkTypeProgrammer;
|
|
11
|
+
(function (SdkTypeProgrammer) {
|
|
12
|
+
SdkTypeProgrammer.decode = (config) => (importer) => (meta, parentEscaped = false) => {
|
|
13
|
+
const union = [];
|
|
14
|
+
// COALESCES
|
|
15
|
+
if (meta.any)
|
|
16
|
+
union.push(TypeFactory_1.TypeFactory.keyword("any"));
|
|
17
|
+
if (meta.nullable)
|
|
18
|
+
union.push(node("null"));
|
|
19
|
+
if (meta.isRequired() === false)
|
|
20
|
+
union.push(node("undefined"));
|
|
21
|
+
if (parentEscaped === false && meta.escaped)
|
|
22
|
+
union.push(decode_escaped(config)(importer)(meta.escaped));
|
|
23
|
+
// ATOMIC TYPES
|
|
24
|
+
for (const c of meta.constants)
|
|
25
|
+
for (const value of c.values)
|
|
26
|
+
union.push(decode_constant(value));
|
|
27
|
+
for (const tpl of meta.templates)
|
|
28
|
+
union.push(decode_template(config)(importer)(tpl));
|
|
29
|
+
for (const atom of meta.atomics)
|
|
30
|
+
union.push(decode_atomic(importer)(atom));
|
|
31
|
+
// OBJECT TYPES
|
|
32
|
+
for (const tuple of meta.tuples)
|
|
33
|
+
union.push(decode_tuple(config)(importer)(tuple));
|
|
34
|
+
for (const array of meta.arrays)
|
|
35
|
+
union.push(decode_array(config)(importer)(array));
|
|
36
|
+
for (const object of meta.objects)
|
|
37
|
+
union.push(decode_alias(config)(importer)(object));
|
|
38
|
+
for (const alias of meta.aliases)
|
|
39
|
+
union.push(decode_alias(config)(importer)(alias));
|
|
40
|
+
return union.length === 1
|
|
41
|
+
? union[0]
|
|
42
|
+
: typescript_1.default.factory.createUnionTypeNode(union);
|
|
43
|
+
};
|
|
44
|
+
const decode_escaped = (config) => (importer) => (meta) => {
|
|
45
|
+
if (meta.original.size() === 1 &&
|
|
46
|
+
meta.original.natives.length === 1 &&
|
|
47
|
+
meta.original.natives[0] === "Date")
|
|
48
|
+
return typescript_1.default.factory.createIntersectionTypeNode([
|
|
49
|
+
TypeFactory_1.TypeFactory.keyword("string"),
|
|
50
|
+
decodeTag(importer)({
|
|
51
|
+
name: "Format",
|
|
52
|
+
value: "date-time",
|
|
53
|
+
}),
|
|
54
|
+
]);
|
|
55
|
+
return SdkTypeProgrammer.decode(config)(importer)(meta.returns, true);
|
|
56
|
+
};
|
|
57
|
+
const decode_constant = (value) => {
|
|
58
|
+
if (typeof value === "boolean")
|
|
59
|
+
return typescript_1.default.factory.createLiteralTypeNode(value ? typescript_1.default.factory.createTrue() : typescript_1.default.factory.createFalse());
|
|
60
|
+
else if (typeof value === "bigint")
|
|
61
|
+
return typescript_1.default.factory.createLiteralTypeNode(value < BigInt(0)
|
|
62
|
+
? typescript_1.default.factory.createPrefixUnaryExpression(typescript_1.default.SyntaxKind.MinusToken, typescript_1.default.factory.createBigIntLiteral((-value).toString()))
|
|
63
|
+
: typescript_1.default.factory.createBigIntLiteral(value.toString()));
|
|
64
|
+
else if (typeof value === "number")
|
|
65
|
+
return typescript_1.default.factory.createLiteralTypeNode(ExpressionFactory_1.ExpressionFactory.number(value));
|
|
66
|
+
return typescript_1.default.factory.createLiteralTypeNode(typescript_1.default.factory.createStringLiteral(value));
|
|
67
|
+
};
|
|
68
|
+
const decode_template = (config) => (importer) => (meta) => {
|
|
69
|
+
var _a;
|
|
70
|
+
const head = meta[0].isSoleLiteral();
|
|
71
|
+
const spans = [];
|
|
72
|
+
for (const elem of meta.slice(head ? 1 : 0)) {
|
|
73
|
+
const last = (_a = spans.at(-1)) !== null && _a !== void 0 ? _a : (() => {
|
|
74
|
+
const tuple = [null, null];
|
|
75
|
+
spans.push(tuple);
|
|
76
|
+
return tuple;
|
|
77
|
+
})();
|
|
78
|
+
if (elem.isSoleLiteral())
|
|
79
|
+
if (last[1] === null)
|
|
80
|
+
last[1] = String(elem.constants[0].values[0]);
|
|
81
|
+
else
|
|
82
|
+
spans.push([
|
|
83
|
+
typescript_1.default.factory.createLiteralTypeNode(typescript_1.default.factory.createStringLiteral(String(elem.constants[0].values[0]))),
|
|
84
|
+
null,
|
|
85
|
+
]);
|
|
86
|
+
else if (last[0] === null)
|
|
87
|
+
last[0] = SdkTypeProgrammer.decode(config)(importer)(elem);
|
|
88
|
+
else
|
|
89
|
+
spans.push([SdkTypeProgrammer.decode(config)(importer)(elem), null]);
|
|
90
|
+
}
|
|
91
|
+
return typescript_1.default.factory.createTemplateLiteralType(typescript_1.default.factory.createTemplateHead(head ? meta[0].constants[0].values[0] : ""), spans
|
|
92
|
+
.filter(([node]) => node !== null)
|
|
93
|
+
.map(([node, str], i, array) => typescript_1.default.factory.createTemplateLiteralTypeSpan(node, (i !== array.length - 1
|
|
94
|
+
? typescript_1.default.factory.createTemplateMiddle
|
|
95
|
+
: typescript_1.default.factory.createTemplateTail)(str !== null && str !== void 0 ? str : ""))));
|
|
96
|
+
};
|
|
97
|
+
const decode_atomic = (importer) => (meta) => decode_type_tag_matrix(importer)(typescript_1.default.factory.createKeywordTypeNode(meta.type === "boolean"
|
|
98
|
+
? typescript_1.default.SyntaxKind.BooleanKeyword
|
|
99
|
+
: meta.type === "bigint"
|
|
100
|
+
? typescript_1.default.SyntaxKind.BigIntKeyword
|
|
101
|
+
: meta.type === "number"
|
|
102
|
+
? typescript_1.default.SyntaxKind.NumberKeyword
|
|
103
|
+
: typescript_1.default.SyntaxKind.StringKeyword), meta.tags);
|
|
104
|
+
const decode_array = (config) => (importer) => (meta) => decode_type_tag_matrix(importer)(typescript_1.default.factory.createArrayTypeNode(SdkTypeProgrammer.decode(config)(importer)(meta.type.value)), meta.tags);
|
|
105
|
+
const decode_tuple = (config) => (importer) => (meta) => typescript_1.default.factory.createTupleTypeNode(meta.type.elements.map((elem) => elem.rest
|
|
106
|
+
? typescript_1.default.factory.createRestTypeNode(typescript_1.default.factory.createArrayTypeNode(SdkTypeProgrammer.decode(config)(importer)(elem.rest)))
|
|
107
|
+
: SdkTypeProgrammer.decode(config)(importer)(elem)));
|
|
108
|
+
const decode_alias = (config) => (importer) => (meta) => {
|
|
109
|
+
importInternalFile(config)(importer)(meta.name);
|
|
110
|
+
return typescript_1.default.factory.createTypeReferenceNode(meta.name);
|
|
111
|
+
};
|
|
112
|
+
const decode_type_tag_matrix = (importer) => (base, matrix) => {
|
|
113
|
+
matrix = matrix.filter((row) => row.length !== 0);
|
|
114
|
+
if (matrix.length === 0)
|
|
115
|
+
return base;
|
|
116
|
+
else if (matrix.length === 1)
|
|
117
|
+
return typescript_1.default.factory.createIntersectionTypeNode([
|
|
118
|
+
base,
|
|
119
|
+
...matrix[0].map((tag) => decodeTag(importer)(tag)),
|
|
120
|
+
]);
|
|
121
|
+
return typescript_1.default.factory.createIntersectionTypeNode([
|
|
122
|
+
base,
|
|
123
|
+
typescript_1.default.factory.createUnionTypeNode(matrix.map((row) => row.length === 1
|
|
124
|
+
? decodeTag(importer)(row[0])
|
|
125
|
+
: typescript_1.default.factory.createIntersectionTypeNode(row.map((tag) => decodeTag(importer)(tag))))),
|
|
126
|
+
]);
|
|
127
|
+
};
|
|
128
|
+
})(SdkTypeProgrammer || (exports.SdkTypeProgrammer = SdkTypeProgrammer = {}));
|
|
129
|
+
const node = (text) => typescript_1.default.factory.createTypeReferenceNode(text);
|
|
130
|
+
const decodeTag = (importer) => (tag) => {
|
|
131
|
+
const instance = tag.name.split("<")[0];
|
|
132
|
+
return typescript_1.default.factory.createTypeReferenceNode(importer.external({
|
|
133
|
+
type: true,
|
|
134
|
+
library: `typia/lib/tags/${instance}`,
|
|
135
|
+
instance,
|
|
136
|
+
}), [
|
|
137
|
+
typescript_1.default.factory.createLiteralTypeNode(typeof tag.value === "boolean"
|
|
138
|
+
? tag.value
|
|
139
|
+
? typescript_1.default.factory.createTrue()
|
|
140
|
+
: typescript_1.default.factory.createFalse()
|
|
141
|
+
: typeof tag.value === "bigint"
|
|
142
|
+
? tag.value < BigInt(0)
|
|
143
|
+
? typescript_1.default.factory.createPrefixUnaryExpression(typescript_1.default.SyntaxKind.MinusToken, typescript_1.default.factory.createBigIntLiteral((-tag.value).toString()))
|
|
144
|
+
: typescript_1.default.factory.createBigIntLiteral(tag.value.toString())
|
|
145
|
+
: typeof tag.value === "number"
|
|
146
|
+
? ExpressionFactory_1.ExpressionFactory.number(tag.value)
|
|
147
|
+
: typescript_1.default.factory.createStringLiteral(tag.value)),
|
|
148
|
+
]);
|
|
149
|
+
};
|
|
150
|
+
const importInternalFile = (config) => (importer) => (name) => {
|
|
151
|
+
const top = name.split(".")[0];
|
|
152
|
+
if (importer.file === `${config.output}/structures/${top}.ts`)
|
|
153
|
+
return;
|
|
154
|
+
importer.internal({
|
|
155
|
+
type: true,
|
|
156
|
+
file: `${config.output}/structures/${name.split(".")[0]}`,
|
|
157
|
+
instance: top,
|
|
158
|
+
});
|
|
159
|
+
};
|
|
160
|
+
//# sourceMappingURL=SdkTypeProgrammer.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"SdkTypeProgrammer.js","sourceRoot":"","sources":["../../../src/generates/internal/SdkTypeProgrammer.ts"],"names":[],"mappings":";;;;;;AAAA,4DAA4B;AAC5B,6EAA0E;AAC1E,iEAA8D;AAa9D,IAAiB,iBAAiB,CAoMjC;AApMD,WAAiB,iBAAiB;IACnB,wBAAM,GACjB,CAAC,MAAqB,EAAE,EAAE,CAC1B,CAAC,QAA0B,EAAE,EAAE,CAC/B,CAAC,IAAc,EAAE,gBAAyB,KAAK,EAAe,EAAE;QAC9D,MAAM,KAAK,GAAkB,EAAE,CAAC;QAEhC,YAAY;QACZ,IAAI,IAAI,CAAC,GAAG;YAAE,KAAK,CAAC,IAAI,CAAC,yBAAW,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC;QACrD,IAAI,IAAI,CAA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AI,EAAE,IAAI;QACV,IAAI,EAAE,GAAG,MAAM,CAAC,MAAM,eAAe,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,EAAE;QACzD,QAAQ,EAAE,GAAG;KACd,CAAC,CAAC;AACL,CAAC,CAAC"}
|
package/lib/utils/FormatUtil.js
CHANGED
|
@@ -18,13 +18,15 @@ const typescript_1 = __importDefault(require("typescript"));
|
|
|
18
18
|
var FormatUtil;
|
|
19
19
|
(function (FormatUtil) {
|
|
20
20
|
FormatUtil.description = (node, comment) => {
|
|
21
|
+
if (comment.length === 0)
|
|
22
|
+
return node;
|
|
21
23
|
typescript_1.default.addSyntheticLeadingComment(node, typescript_1.default.SyntaxKind.MultiLineCommentTrivia, ["*", ...comment.split("\n").map((str) => ` * ${str}`), ""].join("\n"), true);
|
|
22
24
|
return node;
|
|
23
25
|
};
|
|
24
26
|
FormatUtil.enter = () => typescript_1.default.factory.createExpressionStatement(typescript_1.default.factory.createIdentifier("\n"));
|
|
25
27
|
FormatUtil.beautify = (script) => __awaiter(this, void 0, void 0, function* () {
|
|
26
28
|
try {
|
|
27
|
-
return (0, prettier_1.format)(script, {
|
|
29
|
+
return yield (0, prettier_1.format)(script, {
|
|
28
30
|
parser: "typescript",
|
|
29
31
|
});
|
|
30
32
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"FormatUtil.js","sourceRoot":"","sources":["../../src/utils/FormatUtil.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,uCAAkC;AAClC,4DAA4B;AAE5B,IAAiB,UAAU,
|
|
1
|
+
{"version":3,"file":"FormatUtil.js","sourceRoot":"","sources":["../../src/utils/FormatUtil.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,uCAAkC;AAClC,4DAA4B;AAE5B,IAAiB,UAAU,CA2B1B;AA3BD,WAAiB,UAAU;IACZ,sBAAW,GAAG,CACzB,IAAU,EACV,OAAe,EACT,EAAE;QACR,IAAI,OAAO,CAAC,MAAM,KAAK,CAAC;YAAE,OAAO,IAAI,CAAC;QACtC,oBAAE,CAAC,0BAA0B,CAC3B,IAAI,EACJ,oBAAE,CAAC,UAAU,CAAC,sBAAsB,EACpC,CAAC,GAAG,EAAE,GAAG,OAAO,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,GAAG,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,MAAM,GAAG,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,EACtE,IAAI,CACL,CAAC;QACF,OAAO,IAAI,CAAC;IACd,CAAC,CAAC;IAEW,gBAAK,GAAG,GAAG,EAAE,CACxB,oBAAE,CAAC,OAAO,CAAC,yBAAyB,CAAC,oBAAE,CAAC,OAAO,CAAC,gBAAgB,CAAC,IAAI,CAAC,CAAC,CAAC;IAE7D,mBAAQ,GAAG,CAAO,MAAc,EAAmB,EAAE;QAChE,IAAI,CAAC;YACH,OAAO,MAAM,IAAA,iBAAM,EAAC,MAAM,EAAE;gBAC1B,MAAM,EAAE,YAAY;aACrB,CAAC,CAAC;QACL,CAAC;QAAC,WAAM,CAAC;YACP,OAAO,MAAM,CAAC;QAChB,CAAC;IACH,CAAC,CAAA,CAAC;AACJ,CAAC,EA3BgB,UAAU,0BAAV,UAAU,QA2B1B"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nestia/sdk",
|
|
3
|
-
"version": "2.5.0-dev.20240129",
|
|
3
|
+
"version": "2.5.0-dev.20240129-2",
|
|
4
4
|
"description": "Nestia SDK and Swagger generator",
|
|
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.5.0-dev.20240129",
|
|
37
|
+
"@nestia/fetcher": "^2.5.0-dev.20240129-2",
|
|
38
38
|
"cli": "^1.0.1",
|
|
39
39
|
"get-function-location": "^2.0.0",
|
|
40
40
|
"glob": "^7.2.0",
|
|
@@ -46,7 +46,7 @@
|
|
|
46
46
|
"typia": "^5.4.1"
|
|
47
47
|
},
|
|
48
48
|
"peerDependencies": {
|
|
49
|
-
"@nestia/fetcher": ">=2.5.0-dev.20240129",
|
|
49
|
+
"@nestia/fetcher": ">=2.5.0-dev.20240129-2",
|
|
50
50
|
"@nestjs/common": ">=7.0.1",
|
|
51
51
|
"@nestjs/core": ">=7.0.1",
|
|
52
52
|
"prettier": ">=2.0.0",
|
|
@@ -51,7 +51,7 @@ export class NestiaSdkApplication {
|
|
|
51
51
|
(config) => config,
|
|
52
52
|
(checker) => (config) => async (routes) => {
|
|
53
53
|
await SdkGenerator.generate(checker)(config)(routes);
|
|
54
|
-
await E2eGenerator.generate(config)(routes);
|
|
54
|
+
await E2eGenerator.generate(checker)(config)(routes);
|
|
55
55
|
},
|
|
56
56
|
);
|
|
57
57
|
}
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import fs from "fs";
|
|
2
|
+
import ts from "typescript";
|
|
3
|
+
|
|
4
|
+
import { INestiaConfig } from "../INestiaConfig";
|
|
5
|
+
import { IRoute } from "../structures/IRoute";
|
|
6
|
+
import { FormatUtil } from "../utils/FormatUtil";
|
|
7
|
+
import { ImportDictionary } from "../utils/ImportDictionary";
|
|
8
|
+
import { SdkInterfaceProgrammer } from "./internal/SdkInterfaceProgrammer";
|
|
9
|
+
|
|
10
|
+
export namespace CloneGenerator {
|
|
11
|
+
export const generate =
|
|
12
|
+
(checker: ts.TypeChecker) =>
|
|
13
|
+
(config: INestiaConfig) =>
|
|
14
|
+
async (routes: IRoute[]): Promise<void> => {
|
|
15
|
+
const dict: Map<string, SdkInterfaceProgrammer.IModule> =
|
|
16
|
+
SdkInterfaceProgrammer.generate(checker)(config)(routes);
|
|
17
|
+
|
|
18
|
+
try {
|
|
19
|
+
await fs.promises.mkdir(`${config.output}/structures`);
|
|
20
|
+
} catch {}
|
|
21
|
+
for (const [key, value] of dict) await writeDtoFile(config)(key, value);
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
const writeDtoFile =
|
|
25
|
+
(config: INestiaConfig) =>
|
|
26
|
+
async (
|
|
27
|
+
key: string,
|
|
28
|
+
value: SdkInterfaceProgrammer.IModule,
|
|
29
|
+
): Promise<void> => {
|
|
30
|
+
const location: string = `${config.output}/structures/${key}.ts`;
|
|
31
|
+
const importer: ImportDictionary = new ImportDictionary(location);
|
|
32
|
+
const statements: ts.Statement[] = iterate(importer)(value);
|
|
33
|
+
if (statements.length === 0) return;
|
|
34
|
+
|
|
35
|
+
const script: string = ts
|
|
36
|
+
.createPrinter()
|
|
37
|
+
.printFile(
|
|
38
|
+
ts.factory.createSourceFile(
|
|
39
|
+
[
|
|
40
|
+
...importer.toStatements(`${config.output}/structures`),
|
|
41
|
+
...(importer.empty() ? [] : [FormatUtil.enter()]),
|
|
42
|
+
...statements,
|
|
43
|
+
],
|
|
44
|
+
ts.factory.createToken(ts.SyntaxKind.EndOfFileToken),
|
|
45
|
+
ts.NodeFlags.None,
|
|
46
|
+
),
|
|
47
|
+
);
|
|
48
|
+
await fs.promises.writeFile(
|
|
49
|
+
location,
|
|
50
|
+
await FormatUtil.beautify(script),
|
|
51
|
+
"utf8",
|
|
52
|
+
);
|
|
53
|
+
};
|
|
54
|
+
|
|
55
|
+
const iterate =
|
|
56
|
+
(importer: ImportDictionary) =>
|
|
57
|
+
(modulo: SdkInterfaceProgrammer.IModule): ts.Statement[] => {
|
|
58
|
+
const output: ts.Statement[] = [];
|
|
59
|
+
if (modulo.programmer !== null) output.push(modulo.programmer(importer));
|
|
60
|
+
if (modulo.children.size) {
|
|
61
|
+
const internal: ts.Statement[] = [];
|
|
62
|
+
for (const child of modulo.children.values())
|
|
63
|
+
internal.push(...iterate(importer)(child));
|
|
64
|
+
output.push(
|
|
65
|
+
ts.factory.createModuleDeclaration(
|
|
66
|
+
[ts.factory.createModifier(ts.SyntaxKind.ExportKeyword)],
|
|
67
|
+
ts.factory.createIdentifier(modulo.name),
|
|
68
|
+
ts.factory.createModuleBlock(internal),
|
|
69
|
+
ts.NodeFlags.Namespace,
|
|
70
|
+
),
|
|
71
|
+
);
|
|
72
|
+
}
|
|
73
|
+
return output;
|
|
74
|
+
};
|
|
75
|
+
}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import fs from "fs";
|
|
2
2
|
import path from "path";
|
|
3
|
+
import ts from "typescript";
|
|
3
4
|
|
|
4
5
|
import { INestiaConfig } from "../INestiaConfig";
|
|
5
6
|
import { ConfigAnalyzer } from "../analyses/ConfigAnalyzer";
|
|
@@ -8,6 +9,7 @@ import { E2eFileProgrammer } from "./internal/E2eFileProgrammer";
|
|
|
8
9
|
|
|
9
10
|
export namespace E2eGenerator {
|
|
10
11
|
export const generate =
|
|
12
|
+
(checker: ts.TypeChecker) =>
|
|
11
13
|
(config: INestiaConfig) =>
|
|
12
14
|
async (routeList: IRoute[]): Promise<void> => {
|
|
13
15
|
console.log("Generating E2E Test Functions");
|
|
@@ -24,7 +26,7 @@ export namespace E2eGenerator {
|
|
|
24
26
|
|
|
25
27
|
// GENERATE EACH TEST FILES
|
|
26
28
|
for (const route of routeList)
|
|
27
|
-
await E2eFileProgrammer.generate(config)({
|
|
29
|
+
await E2eFileProgrammer.generate(checker)(config)({
|
|
28
30
|
api: path.resolve(config.output!),
|
|
29
31
|
current: path.join(output, "features", "api", "automated"),
|
|
30
32
|
})(route);
|
|
@@ -5,8 +5,8 @@ import ts from "typescript";
|
|
|
5
5
|
|
|
6
6
|
import { INestiaConfig } from "../INestiaConfig";
|
|
7
7
|
import { IRoute } from "../structures/IRoute";
|
|
8
|
+
import { CloneGenerator } from "./CloneGenerator";
|
|
8
9
|
import { SdkDistributionComposer } from "./internal/SdkDistributionComposer";
|
|
9
|
-
import { SdkDtoGenerator } from "./internal/SdkDtoGenerator";
|
|
10
10
|
import { SdkFileProgrammer } from "./internal/SdkFileProgrammer";
|
|
11
11
|
|
|
12
12
|
export namespace SdkGenerator {
|
|
@@ -56,10 +56,10 @@ export namespace SdkGenerator {
|
|
|
56
56
|
}
|
|
57
57
|
|
|
58
58
|
// STRUCTURES
|
|
59
|
-
if (config.clone) await
|
|
59
|
+
if (config.clone) await CloneGenerator.generate(checker)(config)(routes);
|
|
60
60
|
|
|
61
61
|
// FUNCTIONAL
|
|
62
|
-
await SdkFileProgrammer.generate(config)(routes);
|
|
62
|
+
await SdkFileProgrammer.generate(checker)(config)(routes);
|
|
63
63
|
|
|
64
64
|
// DISTRIBUTION
|
|
65
65
|
if (config.distribute !== undefined)
|
|
@@ -6,12 +6,13 @@ import { INestiaConfig } from "../../INestiaConfig";
|
|
|
6
6
|
import { IRoute } from "../../structures/IRoute";
|
|
7
7
|
import { FormatUtil } from "../../utils/FormatUtil";
|
|
8
8
|
import { ImportDictionary } from "../../utils/ImportDictionary";
|
|
9
|
-
import {
|
|
9
|
+
import { SdkAliasCollection } from "./SdkAliasCollection";
|
|
10
10
|
import { SdkImportWizard } from "./SdkImportWizard";
|
|
11
|
-
import {
|
|
11
|
+
import { SdkTypeProgrammer } from "./SdkTypeProgrammer";
|
|
12
12
|
|
|
13
13
|
export namespace E2eFileProgrammer {
|
|
14
14
|
export const generate =
|
|
15
|
+
(checker: ts.TypeChecker) =>
|
|
15
16
|
(config: INestiaConfig) =>
|
|
16
17
|
(props: { api: string; current: string }) =>
|
|
17
18
|
async (route: IRoute): Promise<void> => {
|
|
@@ -33,7 +34,7 @@ export namespace E2eFileProgrammer {
|
|
|
33
34
|
name: "api",
|
|
34
35
|
});
|
|
35
36
|
|
|
36
|
-
const functor = generate_function(config)(importer)(route);
|
|
37
|
+
const functor = generate_function(checker)(config)(importer)(route);
|
|
37
38
|
|
|
38
39
|
await fs.promises.writeFile(
|
|
39
40
|
importer.file,
|
|
@@ -57,6 +58,7 @@ export namespace E2eFileProgrammer {
|
|
|
57
58
|
};
|
|
58
59
|
|
|
59
60
|
const generate_function =
|
|
61
|
+
(checker: ts.TypeChecker) =>
|
|
60
62
|
(config: INestiaConfig) =>
|
|
61
63
|
(importer: ImportDictionary) =>
|
|
62
64
|
(route: IRoute): ts.Statement =>
|
|
@@ -68,7 +70,7 @@ export namespace E2eFileProgrammer {
|
|
|
68
70
|
ts.factory.createIdentifier(getFunctionName(route)),
|
|
69
71
|
undefined,
|
|
70
72
|
undefined,
|
|
71
|
-
generate_arrow(config)(importer)(route),
|
|
73
|
+
generate_arrow(checker)(config)(importer)(route),
|
|
72
74
|
),
|
|
73
75
|
],
|
|
74
76
|
ts.NodeFlags.Const,
|
|
@@ -76,6 +78,7 @@ export namespace E2eFileProgrammer {
|
|
|
76
78
|
);
|
|
77
79
|
|
|
78
80
|
const generate_arrow =
|
|
81
|
+
(checker: ts.TypeChecker) =>
|
|
79
82
|
(config: INestiaConfig) =>
|
|
80
83
|
(importer: ImportDictionary) =>
|
|
81
84
|
(route: IRoute) => {
|
|
@@ -104,11 +107,7 @@ export namespace E2eFileProgrammer {
|
|
|
104
107
|
SdkImportWizard.typia(importer),
|
|
105
108
|
),
|
|
106
109
|
)("random"),
|
|
107
|
-
[
|
|
108
|
-
ts.factory.createTypeReferenceNode(
|
|
109
|
-
getTypeName(config)(importer)(headers),
|
|
110
|
-
),
|
|
111
|
-
],
|
|
110
|
+
[getTypeName(config)(importer)(headers)],
|
|
112
111
|
undefined,
|
|
113
112
|
),
|
|
114
113
|
),
|
|
@@ -134,11 +133,7 @@ export namespace E2eFileProgrammer {
|
|
|
134
133
|
IdentifierFactory.access(
|
|
135
134
|
ts.factory.createIdentifier(SdkImportWizard.typia(importer)),
|
|
136
135
|
)("random"),
|
|
137
|
-
[
|
|
138
|
-
ts.factory.createTypeReferenceNode(
|
|
139
|
-
getTypeName(config)(importer)(p),
|
|
140
|
-
),
|
|
141
|
-
],
|
|
136
|
+
[getTypeName(config)(importer)(p)],
|
|
142
137
|
undefined,
|
|
143
138
|
),
|
|
144
139
|
),
|
|
@@ -171,9 +166,7 @@ export namespace E2eFileProgrammer {
|
|
|
171
166
|
ts.factory.createVariableDeclaration(
|
|
172
167
|
"output",
|
|
173
168
|
undefined,
|
|
174
|
-
|
|
175
|
-
SdkTypeDefiner.output(config)(importer)(route),
|
|
176
|
-
),
|
|
169
|
+
SdkAliasCollection.output(checker)(config)(importer)(route),
|
|
177
170
|
ts.factory.createAwaitExpression(caller),
|
|
178
171
|
),
|
|
179
172
|
],
|
|
@@ -194,5 +187,5 @@ const getTypeName =
|
|
|
194
187
|
(importer: ImportDictionary) =>
|
|
195
188
|
(p: IRoute.IParameter | IRoute.IOutput) =>
|
|
196
189
|
p.metadata
|
|
197
|
-
?
|
|
198
|
-
: p.typeName;
|
|
190
|
+
? SdkTypeProgrammer.decode(config)(importer)(p.metadata)
|
|
191
|
+
: ts.factory.createTypeReferenceNode(p.typeName);
|
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
import ts from "typescript";
|
|
2
|
+
|
|
3
|
+
import { INestiaConfig } from "../../INestiaConfig";
|
|
4
|
+
import { IRoute } from "../../structures/IRoute";
|
|
5
|
+
import { ImportDictionary } from "../../utils/ImportDictionary";
|
|
6
|
+
import { SdkTypeProgrammer } from "./SdkTypeProgrammer";
|
|
7
|
+
|
|
8
|
+
export namespace SdkAliasCollection {
|
|
9
|
+
export const name =
|
|
10
|
+
(config: INestiaConfig) =>
|
|
11
|
+
(importer: ImportDictionary) =>
|
|
12
|
+
(p: IRoute.IParameter | IRoute.IOutput): ts.TypeNode =>
|
|
13
|
+
p.metadata
|
|
14
|
+
? SdkTypeProgrammer.decode(config)(importer)(p.metadata)
|
|
15
|
+
: ts.factory.createTypeReferenceNode(p.typeName);
|
|
16
|
+
|
|
17
|
+
export const headers =
|
|
18
|
+
(config: INestiaConfig) =>
|
|
19
|
+
(importer: ImportDictionary) =>
|
|
20
|
+
(param: IRoute.IParameter): ts.TypeNode => {
|
|
21
|
+
const type: ts.TypeNode = name(config)(importer)(param);
|
|
22
|
+
if (config.primitive === false) return type;
|
|
23
|
+
return ts.factory.createTypeReferenceNode(
|
|
24
|
+
importer.external({
|
|
25
|
+
type: true,
|
|
26
|
+
library: "@nestia/fetcher",
|
|
27
|
+
instance: "Resolved",
|
|
28
|
+
}),
|
|
29
|
+
[type],
|
|
30
|
+
);
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
export const query =
|
|
34
|
+
(config: INestiaConfig) =>
|
|
35
|
+
(importer: ImportDictionary) =>
|
|
36
|
+
(param: IRoute.IParameter): ts.TypeNode => {
|
|
37
|
+
const type: ts.TypeNode = name(config)(importer)(param);
|
|
38
|
+
if (config.primitive === false) return type;
|
|
39
|
+
return ts.factory.createTypeReferenceNode(
|
|
40
|
+
importer.external({
|
|
41
|
+
type: true,
|
|
42
|
+
library: "@nestia/fetcher",
|
|
43
|
+
instance: "Resolved",
|
|
44
|
+
}),
|
|
45
|
+
[type],
|
|
46
|
+
);
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
export const input =
|
|
50
|
+
(config: INestiaConfig) =>
|
|
51
|
+
(importer: ImportDictionary) =>
|
|
52
|
+
(param: IRoute.IParameter): ts.TypeNode => {
|
|
53
|
+
const type: ts.TypeNode = name(config)(importer)(param);
|
|
54
|
+
if (config.primitive === false) return type;
|
|
55
|
+
return ts.factory.createTypeReferenceNode(
|
|
56
|
+
importer.external({
|
|
57
|
+
type: true,
|
|
58
|
+
library: "@nestia/fetcher",
|
|
59
|
+
instance: "Primitive",
|
|
60
|
+
}),
|
|
61
|
+
[type],
|
|
62
|
+
);
|
|
63
|
+
};
|
|
64
|
+
|
|
65
|
+
export const output =
|
|
66
|
+
(checker: ts.TypeChecker) =>
|
|
67
|
+
(config: INestiaConfig) =>
|
|
68
|
+
(importer: ImportDictionary) =>
|
|
69
|
+
(route: IRoute): ts.TypeNode => {
|
|
70
|
+
if (config.propagate !== true) {
|
|
71
|
+
const node: ts.TypeNode = name(config)(importer)(route.output);
|
|
72
|
+
const type = checker.getTypeAtLocation(node);
|
|
73
|
+
const filter = (flag: ts.TypeFlags) => (type.getFlags() & flag) !== 0;
|
|
74
|
+
|
|
75
|
+
if (
|
|
76
|
+
filter(ts.TypeFlags.Undefined) ||
|
|
77
|
+
filter(ts.TypeFlags.Never) ||
|
|
78
|
+
filter(ts.TypeFlags.Void) ||
|
|
79
|
+
filter(ts.TypeFlags.VoidLike) ||
|
|
80
|
+
config.primitive === false
|
|
81
|
+
)
|
|
82
|
+
return node;
|
|
83
|
+
return ts.factory.createTypeReferenceNode(
|
|
84
|
+
importer.external({
|
|
85
|
+
type: true,
|
|
86
|
+
library: "@nestia/fetcher",
|
|
87
|
+
instance:
|
|
88
|
+
route.output.contentType === "application/x-www-form-urlencoded"
|
|
89
|
+
? "Resolved"
|
|
90
|
+
: "Primitive",
|
|
91
|
+
}),
|
|
92
|
+
[node],
|
|
93
|
+
);
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
const branches: IBranch[] = [
|
|
97
|
+
{
|
|
98
|
+
status: String(route.status ?? (route.method === "POST" ? 201 : 200)),
|
|
99
|
+
type: name(config)(importer)(route.output),
|
|
100
|
+
},
|
|
101
|
+
...Object.entries(route.exceptions).map(([status, value]) => ({
|
|
102
|
+
status,
|
|
103
|
+
type: name(config)(importer)(value),
|
|
104
|
+
})),
|
|
105
|
+
];
|
|
106
|
+
return ts.factory.createTypeReferenceNode(
|
|
107
|
+
importer.external({
|
|
108
|
+
type: true,
|
|
109
|
+
library: "@nestia/fetcher",
|
|
110
|
+
instance: "IPropagation",
|
|
111
|
+
}),
|
|
112
|
+
[
|
|
113
|
+
ts.factory.createTypeLiteralNode(
|
|
114
|
+
branches.map((b) =>
|
|
115
|
+
ts.factory.createPropertySignature(
|
|
116
|
+
undefined,
|
|
117
|
+
ts.factory.createNumericLiteral(b.status),
|
|
118
|
+
undefined,
|
|
119
|
+
b.type,
|
|
120
|
+
),
|
|
121
|
+
),
|
|
122
|
+
),
|
|
123
|
+
...(route.status
|
|
124
|
+
? [
|
|
125
|
+
ts.factory.createLiteralTypeNode(
|
|
126
|
+
ts.factory.createNumericLiteral(route.status),
|
|
127
|
+
),
|
|
128
|
+
]
|
|
129
|
+
: []),
|
|
130
|
+
],
|
|
131
|
+
);
|
|
132
|
+
};
|
|
133
|
+
|
|
134
|
+
export const responseBody =
|
|
135
|
+
(checker: ts.TypeChecker) =>
|
|
136
|
+
(config: INestiaConfig) =>
|
|
137
|
+
(importer: ImportDictionary) =>
|
|
138
|
+
(route: IRoute): ts.TypeNode =>
|
|
139
|
+
output(checker)({ ...config, propagate: false })(importer)(route);
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
interface IBranch {
|
|
143
|
+
status: string;
|
|
144
|
+
type: ts.TypeNode;
|
|
145
|
+
}
|
|
@@ -14,6 +14,7 @@ export namespace SdkFileProgrammer {
|
|
|
14
14
|
CONSTRUCTOR
|
|
15
15
|
--------------------------------------------------------- */
|
|
16
16
|
export const generate =
|
|
17
|
+
(checker: ts.TypeChecker) =>
|
|
17
18
|
(config: INestiaConfig) =>
|
|
18
19
|
async (routeList: IRoute[]): Promise<void> => {
|
|
19
20
|
// CONSTRUCT FOLDER TREE
|
|
@@ -21,7 +22,7 @@ export namespace SdkFileProgrammer {
|
|
|
21
22
|
for (const route of routeList) emplace(root)(route);
|
|
22
23
|
|
|
23
24
|
// ITERATE FILES
|
|
24
|
-
await iterate(config)(root)(config.output + "/functional");
|
|
25
|
+
await iterate(checker)(config)(root)(config.output + "/functional");
|
|
25
26
|
};
|
|
26
27
|
|
|
27
28
|
const emplace =
|
|
@@ -44,6 +45,7 @@ export namespace SdkFileProgrammer {
|
|
|
44
45
|
FILE ITERATOR
|
|
45
46
|
--------------------------------------------------------- */
|
|
46
47
|
const iterate =
|
|
48
|
+
(checker: ts.TypeChecker) =>
|
|
47
49
|
(config: INestiaConfig) =>
|
|
48
50
|
(directory: SdkRouteDirectory) =>
|
|
49
51
|
async (outDir: string): Promise<void> => {
|
|
@@ -55,7 +57,7 @@ export namespace SdkFileProgrammer {
|
|
|
55
57
|
// ITERATE CHILDREN
|
|
56
58
|
const statements: ts.Statement[] = [];
|
|
57
59
|
for (const [key, value] of directory.children) {
|
|
58
|
-
await iterate(config)(value)(`${outDir}/${key}`);
|
|
60
|
+
await iterate(checker)(config)(value)(`${outDir}/${key}`);
|
|
59
61
|
statements.push(
|
|
60
62
|
ts.factory.createExportDeclaration(
|
|
61
63
|
undefined,
|
|
@@ -92,7 +94,7 @@ export namespace SdkFileProgrammer {
|
|
|
92
94
|
type: true,
|
|
93
95
|
});
|
|
94
96
|
statements.push(
|
|
95
|
-
...SdkRouteProgrammer.generate(config)(importer)(route),
|
|
97
|
+
...SdkRouteProgrammer.generate(checker)(config)(importer)(route),
|
|
96
98
|
);
|
|
97
99
|
if (i !== directory.routes.length - 1)
|
|
98
100
|
statements.push(FormatUtil.enter());
|