@nestia/sdk 2.5.0-dev.20240130 → 2.5.0-dev.20240130-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/INestiaConfig.d.ts +0 -6
- package/lib/executable/internal/NestiaConfigLoader.js +2 -6
- package/lib/executable/internal/NestiaConfigLoader.js.map +1 -1
- package/lib/generates/SwaggerGenerator.js +8 -11
- package/lib/generates/SwaggerGenerator.js.map +1 -1
- package/lib/generates/internal/SdkTypeProgrammer.js +8 -3
- package/lib/generates/internal/SdkTypeProgrammer.js.map +1 -1
- package/lib/structures/ISwagger.d.ts +1 -1
- package/package.json +3 -3
- package/src/INestiaConfig.ts +248 -255
- package/src/NestiaSdkApplication.ts +253 -253
- package/src/generates/E2eGenerator.ts +66 -66
- package/src/generates/SdkGenerator.ts +96 -96
- package/src/generates/SwaggerGenerator.ts +376 -378
- package/src/generates/internal/E2eFileProgrammer.ts +191 -191
- package/src/generates/internal/SdkAliasCollection.ts +145 -145
- package/src/generates/internal/SdkFileProgrammer.ts +135 -135
- package/src/generates/internal/SdkFunctionProgrammer.ts +219 -219
- package/src/generates/internal/SdkNamespaceProgrammer.ts +507 -507
- package/src/generates/internal/SdkRouteProgrammer.ts +86 -86
- package/src/generates/internal/SdkSimulationProgrammer.ts +357 -357
- package/src/generates/internal/SdkTypeProgrammer.ts +8 -7
- package/src/structures/ISwagger.ts +91 -91
- package/src/utils/FormatUtil.ts +31 -31
- package/src/utils/ImportDictionary.ts +197 -197
|
@@ -1,219 +1,219 @@
|
|
|
1
|
-
import ts from "typescript";
|
|
2
|
-
import typia from "typia";
|
|
3
|
-
import { IdentifierFactory } from "typia/lib/factories/IdentifierFactory";
|
|
4
|
-
|
|
5
|
-
import { INestiaConfig } from "../../INestiaConfig";
|
|
6
|
-
import { IController } from "../../structures/IController";
|
|
7
|
-
import { IRoute } from "../../structures/IRoute";
|
|
8
|
-
import { ImportDictionary } from "../../utils/ImportDictionary";
|
|
9
|
-
import { SdkImportWizard } from "./SdkImportWizard";
|
|
10
|
-
import { SdkTypeProgrammer } from "./SdkTypeProgrammer";
|
|
11
|
-
|
|
12
|
-
export namespace SdkFunctionProgrammer {
|
|
13
|
-
export const generate =
|
|
14
|
-
(config: INestiaConfig) =>
|
|
15
|
-
(importer: ImportDictionary) =>
|
|
16
|
-
(
|
|
17
|
-
route: IRoute,
|
|
18
|
-
props: {
|
|
19
|
-
headers: IRoute.IParameter | undefined;
|
|
20
|
-
query: IRoute.IParameter | undefined;
|
|
21
|
-
input: IRoute.IParameter | undefined;
|
|
22
|
-
},
|
|
23
|
-
): ts.FunctionDeclaration => {
|
|
24
|
-
return ts.factory.createFunctionDeclaration(
|
|
25
|
-
[
|
|
26
|
-
ts.factory.createModifier(ts.SyntaxKind.ExportKeyword),
|
|
27
|
-
ts.factory.createModifier(ts.SyntaxKind.AsyncKeyword),
|
|
28
|
-
],
|
|
29
|
-
undefined,
|
|
30
|
-
route.name,
|
|
31
|
-
undefined,
|
|
32
|
-
[
|
|
33
|
-
IdentifierFactory.parameter(
|
|
34
|
-
"connection",
|
|
35
|
-
ts.factory.createTypeReferenceNode(
|
|
36
|
-
SdkImportWizard.IConnection(importer),
|
|
37
|
-
props.headers
|
|
38
|
-
? [ts.factory.createTypeReferenceNode(`${route.name}.Headers`)]
|
|
39
|
-
: undefined,
|
|
40
|
-
),
|
|
41
|
-
),
|
|
42
|
-
...route.parameters
|
|
43
|
-
.filter((p) => p.category !== "headers")
|
|
44
|
-
.map((p) =>
|
|
45
|
-
ts.factory.createParameterDeclaration(
|
|
46
|
-
[],
|
|
47
|
-
undefined,
|
|
48
|
-
p.name,
|
|
49
|
-
p.optional
|
|
50
|
-
? ts.factory.createToken(ts.SyntaxKind.QuestionToken)
|
|
51
|
-
: undefined,
|
|
52
|
-
config.primitive !== false &&
|
|
53
|
-
(p === props.query || p === props.input)
|
|
54
|
-
? ts.factory.createTypeReferenceNode(
|
|
55
|
-
`${route.name}.${p === props.query ? "Query" : "Input"}`,
|
|
56
|
-
)
|
|
57
|
-
: getTypeName(config)(importer)(p),
|
|
58
|
-
),
|
|
59
|
-
),
|
|
60
|
-
],
|
|
61
|
-
ts.factory.createTypeReferenceNode("Promise", [
|
|
62
|
-
ts.factory.createTypeReferenceNode(
|
|
63
|
-
config.propagate !== true && route.output.typeName === "void"
|
|
64
|
-
? "void"
|
|
65
|
-
: `${route.name}.Output`,
|
|
66
|
-
),
|
|
67
|
-
]),
|
|
68
|
-
ts.factory.createBlock(
|
|
69
|
-
generate_body(config)(importer)(route, props),
|
|
70
|
-
true,
|
|
71
|
-
),
|
|
72
|
-
);
|
|
73
|
-
};
|
|
74
|
-
|
|
75
|
-
const generate_body =
|
|
76
|
-
(config: INestiaConfig) =>
|
|
77
|
-
(importer: ImportDictionary) =>
|
|
78
|
-
(
|
|
79
|
-
route: IRoute,
|
|
80
|
-
props: {
|
|
81
|
-
headers: IRoute.IParameter | undefined;
|
|
82
|
-
query: IRoute.IParameter | undefined;
|
|
83
|
-
input: IRoute.IParameter | undefined;
|
|
84
|
-
},
|
|
85
|
-
): ts.Statement[] => {
|
|
86
|
-
const encrypted: boolean =
|
|
87
|
-
route.encrypted === true ||
|
|
88
|
-
(props.input !== undefined &&
|
|
89
|
-
props.input.custom === true &&
|
|
90
|
-
props.input.category === "body" &&
|
|
91
|
-
props.input.encrypted === true);
|
|
92
|
-
const contentType: string | undefined =
|
|
93
|
-
props.input !== undefined
|
|
94
|
-
? typia.is<IController.IBodyParameter>(props.input)
|
|
95
|
-
? props.input.contentType
|
|
96
|
-
: "application/json"
|
|
97
|
-
: undefined;
|
|
98
|
-
|
|
99
|
-
const caller = () =>
|
|
100
|
-
ts.factory.createCallExpression(
|
|
101
|
-
IdentifierFactory.access(
|
|
102
|
-
ts.factory.createIdentifier(
|
|
103
|
-
SdkImportWizard.Fetcher(encrypted)(importer),
|
|
104
|
-
),
|
|
105
|
-
)(config.propagate ? "propagate" : "fetch"),
|
|
106
|
-
undefined,
|
|
107
|
-
[
|
|
108
|
-
contentType
|
|
109
|
-
? ts.factory.createObjectLiteralExpression(
|
|
110
|
-
[
|
|
111
|
-
ts.factory.createSpreadAssignment(
|
|
112
|
-
ts.factory.createIdentifier("connection"),
|
|
113
|
-
),
|
|
114
|
-
ts.factory.createPropertyAssignment(
|
|
115
|
-
"headers",
|
|
116
|
-
ts.factory.createObjectLiteralExpression(
|
|
117
|
-
[
|
|
118
|
-
ts.factory.createSpreadAssignment(
|
|
119
|
-
IdentifierFactory.access(
|
|
120
|
-
ts.factory.createIdentifier("connection"),
|
|
121
|
-
)("headers"),
|
|
122
|
-
),
|
|
123
|
-
ts.factory.createPropertyAssignment(
|
|
124
|
-
ts.factory.createStringLiteral("Content-Type"),
|
|
125
|
-
ts.factory.createStringLiteral(contentType),
|
|
126
|
-
),
|
|
127
|
-
],
|
|
128
|
-
true,
|
|
129
|
-
),
|
|
130
|
-
),
|
|
131
|
-
],
|
|
132
|
-
true,
|
|
133
|
-
)
|
|
134
|
-
: ts.factory.createIdentifier("connection"),
|
|
135
|
-
ts.factory.createObjectLiteralExpression(
|
|
136
|
-
[
|
|
137
|
-
ts.factory.createSpreadAssignment(
|
|
138
|
-
IdentifierFactory.access(
|
|
139
|
-
ts.factory.createIdentifier(route.name),
|
|
140
|
-
)("METADATA"),
|
|
141
|
-
),
|
|
142
|
-
ts.factory.createPropertyAssignment(
|
|
143
|
-
"path",
|
|
144
|
-
ts.factory.createCallExpression(
|
|
145
|
-
IdentifierFactory.access(
|
|
146
|
-
ts.factory.createIdentifier(route.name),
|
|
147
|
-
)("path"),
|
|
148
|
-
undefined,
|
|
149
|
-
route.parameters
|
|
150
|
-
.filter(
|
|
151
|
-
(p) => p.category === "param" || p.category === "query",
|
|
152
|
-
)
|
|
153
|
-
.map((p) => ts.factory.createIdentifier(p.name)),
|
|
154
|
-
),
|
|
155
|
-
),
|
|
156
|
-
],
|
|
157
|
-
true,
|
|
158
|
-
),
|
|
159
|
-
...(props.input
|
|
160
|
-
? [ts.factory.createIdentifier(props.input.name)]
|
|
161
|
-
: []),
|
|
162
|
-
...(config.json && props.input?.category === "body"
|
|
163
|
-
? [ts.factory.createIdentifier(`${route.name}.stringify`)]
|
|
164
|
-
: []),
|
|
165
|
-
],
|
|
166
|
-
);
|
|
167
|
-
return [
|
|
168
|
-
...(config.assert
|
|
169
|
-
? route.parameters
|
|
170
|
-
.filter((p) => p.category !== "headers")
|
|
171
|
-
.map((p) =>
|
|
172
|
-
ts.factory.createExpressionStatement(
|
|
173
|
-
ts.factory.createCallExpression(
|
|
174
|
-
IdentifierFactory.access(
|
|
175
|
-
ts.factory.createIdentifier(
|
|
176
|
-
SdkImportWizard.typia(importer),
|
|
177
|
-
),
|
|
178
|
-
)("assert"),
|
|
179
|
-
[
|
|
180
|
-
ts.factory.createTypeQueryNode(
|
|
181
|
-
ts.factory.createIdentifier(p.name),
|
|
182
|
-
),
|
|
183
|
-
],
|
|
184
|
-
[ts.factory.createIdentifier(p.name)],
|
|
185
|
-
),
|
|
186
|
-
),
|
|
187
|
-
)
|
|
188
|
-
: []),
|
|
189
|
-
ts.factory.createReturnStatement(
|
|
190
|
-
config.simulate
|
|
191
|
-
? ts.factory.createConditionalExpression(
|
|
192
|
-
ts.factory.createIdentifier("!!connection.simulate"),
|
|
193
|
-
undefined,
|
|
194
|
-
ts.factory.createCallExpression(
|
|
195
|
-
ts.factory.createIdentifier(`${route.name}.simulate`),
|
|
196
|
-
[],
|
|
197
|
-
[
|
|
198
|
-
ts.factory.createIdentifier("connection"),
|
|
199
|
-
...route.parameters
|
|
200
|
-
.filter((p) => p.category !== "headers")
|
|
201
|
-
.map((p) => ts.factory.createIdentifier(p.name)),
|
|
202
|
-
],
|
|
203
|
-
),
|
|
204
|
-
undefined,
|
|
205
|
-
caller(),
|
|
206
|
-
)
|
|
207
|
-
: caller(),
|
|
208
|
-
),
|
|
209
|
-
];
|
|
210
|
-
};
|
|
211
|
-
}
|
|
212
|
-
|
|
213
|
-
const getTypeName =
|
|
214
|
-
(config: INestiaConfig) =>
|
|
215
|
-
(importer: ImportDictionary) =>
|
|
216
|
-
(p: IRoute.IParameter | IRoute.IOutput) =>
|
|
217
|
-
p.metadata
|
|
218
|
-
? SdkTypeProgrammer.decode(config)(importer)(p.metadata)
|
|
219
|
-
: ts.factory.createTypeReferenceNode(p.typeName);
|
|
1
|
+
import ts from "typescript";
|
|
2
|
+
import typia from "typia";
|
|
3
|
+
import { IdentifierFactory } from "typia/lib/factories/IdentifierFactory";
|
|
4
|
+
|
|
5
|
+
import { INestiaConfig } from "../../INestiaConfig";
|
|
6
|
+
import { IController } from "../../structures/IController";
|
|
7
|
+
import { IRoute } from "../../structures/IRoute";
|
|
8
|
+
import { ImportDictionary } from "../../utils/ImportDictionary";
|
|
9
|
+
import { SdkImportWizard } from "./SdkImportWizard";
|
|
10
|
+
import { SdkTypeProgrammer } from "./SdkTypeProgrammer";
|
|
11
|
+
|
|
12
|
+
export namespace SdkFunctionProgrammer {
|
|
13
|
+
export const generate =
|
|
14
|
+
(config: INestiaConfig) =>
|
|
15
|
+
(importer: ImportDictionary) =>
|
|
16
|
+
(
|
|
17
|
+
route: IRoute,
|
|
18
|
+
props: {
|
|
19
|
+
headers: IRoute.IParameter | undefined;
|
|
20
|
+
query: IRoute.IParameter | undefined;
|
|
21
|
+
input: IRoute.IParameter | undefined;
|
|
22
|
+
},
|
|
23
|
+
): ts.FunctionDeclaration => {
|
|
24
|
+
return ts.factory.createFunctionDeclaration(
|
|
25
|
+
[
|
|
26
|
+
ts.factory.createModifier(ts.SyntaxKind.ExportKeyword),
|
|
27
|
+
ts.factory.createModifier(ts.SyntaxKind.AsyncKeyword),
|
|
28
|
+
],
|
|
29
|
+
undefined,
|
|
30
|
+
route.name,
|
|
31
|
+
undefined,
|
|
32
|
+
[
|
|
33
|
+
IdentifierFactory.parameter(
|
|
34
|
+
"connection",
|
|
35
|
+
ts.factory.createTypeReferenceNode(
|
|
36
|
+
SdkImportWizard.IConnection(importer),
|
|
37
|
+
props.headers
|
|
38
|
+
? [ts.factory.createTypeReferenceNode(`${route.name}.Headers`)]
|
|
39
|
+
: undefined,
|
|
40
|
+
),
|
|
41
|
+
),
|
|
42
|
+
...route.parameters
|
|
43
|
+
.filter((p) => p.category !== "headers")
|
|
44
|
+
.map((p) =>
|
|
45
|
+
ts.factory.createParameterDeclaration(
|
|
46
|
+
[],
|
|
47
|
+
undefined,
|
|
48
|
+
p.name,
|
|
49
|
+
p.optional
|
|
50
|
+
? ts.factory.createToken(ts.SyntaxKind.QuestionToken)
|
|
51
|
+
: undefined,
|
|
52
|
+
config.primitive !== false &&
|
|
53
|
+
(p === props.query || p === props.input)
|
|
54
|
+
? ts.factory.createTypeReferenceNode(
|
|
55
|
+
`${route.name}.${p === props.query ? "Query" : "Input"}`,
|
|
56
|
+
)
|
|
57
|
+
: getTypeName(config)(importer)(p),
|
|
58
|
+
),
|
|
59
|
+
),
|
|
60
|
+
],
|
|
61
|
+
ts.factory.createTypeReferenceNode("Promise", [
|
|
62
|
+
ts.factory.createTypeReferenceNode(
|
|
63
|
+
config.propagate !== true && route.output.typeName === "void"
|
|
64
|
+
? "void"
|
|
65
|
+
: `${route.name}.Output`,
|
|
66
|
+
),
|
|
67
|
+
]),
|
|
68
|
+
ts.factory.createBlock(
|
|
69
|
+
generate_body(config)(importer)(route, props),
|
|
70
|
+
true,
|
|
71
|
+
),
|
|
72
|
+
);
|
|
73
|
+
};
|
|
74
|
+
|
|
75
|
+
const generate_body =
|
|
76
|
+
(config: INestiaConfig) =>
|
|
77
|
+
(importer: ImportDictionary) =>
|
|
78
|
+
(
|
|
79
|
+
route: IRoute,
|
|
80
|
+
props: {
|
|
81
|
+
headers: IRoute.IParameter | undefined;
|
|
82
|
+
query: IRoute.IParameter | undefined;
|
|
83
|
+
input: IRoute.IParameter | undefined;
|
|
84
|
+
},
|
|
85
|
+
): ts.Statement[] => {
|
|
86
|
+
const encrypted: boolean =
|
|
87
|
+
route.encrypted === true ||
|
|
88
|
+
(props.input !== undefined &&
|
|
89
|
+
props.input.custom === true &&
|
|
90
|
+
props.input.category === "body" &&
|
|
91
|
+
props.input.encrypted === true);
|
|
92
|
+
const contentType: string | undefined =
|
|
93
|
+
props.input !== undefined
|
|
94
|
+
? typia.is<IController.IBodyParameter>(props.input)
|
|
95
|
+
? props.input.contentType
|
|
96
|
+
: "application/json"
|
|
97
|
+
: undefined;
|
|
98
|
+
|
|
99
|
+
const caller = () =>
|
|
100
|
+
ts.factory.createCallExpression(
|
|
101
|
+
IdentifierFactory.access(
|
|
102
|
+
ts.factory.createIdentifier(
|
|
103
|
+
SdkImportWizard.Fetcher(encrypted)(importer),
|
|
104
|
+
),
|
|
105
|
+
)(config.propagate ? "propagate" : "fetch"),
|
|
106
|
+
undefined,
|
|
107
|
+
[
|
|
108
|
+
contentType
|
|
109
|
+
? ts.factory.createObjectLiteralExpression(
|
|
110
|
+
[
|
|
111
|
+
ts.factory.createSpreadAssignment(
|
|
112
|
+
ts.factory.createIdentifier("connection"),
|
|
113
|
+
),
|
|
114
|
+
ts.factory.createPropertyAssignment(
|
|
115
|
+
"headers",
|
|
116
|
+
ts.factory.createObjectLiteralExpression(
|
|
117
|
+
[
|
|
118
|
+
ts.factory.createSpreadAssignment(
|
|
119
|
+
IdentifierFactory.access(
|
|
120
|
+
ts.factory.createIdentifier("connection"),
|
|
121
|
+
)("headers"),
|
|
122
|
+
),
|
|
123
|
+
ts.factory.createPropertyAssignment(
|
|
124
|
+
ts.factory.createStringLiteral("Content-Type"),
|
|
125
|
+
ts.factory.createStringLiteral(contentType),
|
|
126
|
+
),
|
|
127
|
+
],
|
|
128
|
+
true,
|
|
129
|
+
),
|
|
130
|
+
),
|
|
131
|
+
],
|
|
132
|
+
true,
|
|
133
|
+
)
|
|
134
|
+
: ts.factory.createIdentifier("connection"),
|
|
135
|
+
ts.factory.createObjectLiteralExpression(
|
|
136
|
+
[
|
|
137
|
+
ts.factory.createSpreadAssignment(
|
|
138
|
+
IdentifierFactory.access(
|
|
139
|
+
ts.factory.createIdentifier(route.name),
|
|
140
|
+
)("METADATA"),
|
|
141
|
+
),
|
|
142
|
+
ts.factory.createPropertyAssignment(
|
|
143
|
+
"path",
|
|
144
|
+
ts.factory.createCallExpression(
|
|
145
|
+
IdentifierFactory.access(
|
|
146
|
+
ts.factory.createIdentifier(route.name),
|
|
147
|
+
)("path"),
|
|
148
|
+
undefined,
|
|
149
|
+
route.parameters
|
|
150
|
+
.filter(
|
|
151
|
+
(p) => p.category === "param" || p.category === "query",
|
|
152
|
+
)
|
|
153
|
+
.map((p) => ts.factory.createIdentifier(p.name)),
|
|
154
|
+
),
|
|
155
|
+
),
|
|
156
|
+
],
|
|
157
|
+
true,
|
|
158
|
+
),
|
|
159
|
+
...(props.input
|
|
160
|
+
? [ts.factory.createIdentifier(props.input.name)]
|
|
161
|
+
: []),
|
|
162
|
+
...(config.json && props.input?.category === "body"
|
|
163
|
+
? [ts.factory.createIdentifier(`${route.name}.stringify`)]
|
|
164
|
+
: []),
|
|
165
|
+
],
|
|
166
|
+
);
|
|
167
|
+
return [
|
|
168
|
+
...(config.assert
|
|
169
|
+
? route.parameters
|
|
170
|
+
.filter((p) => p.category !== "headers")
|
|
171
|
+
.map((p) =>
|
|
172
|
+
ts.factory.createExpressionStatement(
|
|
173
|
+
ts.factory.createCallExpression(
|
|
174
|
+
IdentifierFactory.access(
|
|
175
|
+
ts.factory.createIdentifier(
|
|
176
|
+
SdkImportWizard.typia(importer),
|
|
177
|
+
),
|
|
178
|
+
)("assert"),
|
|
179
|
+
[
|
|
180
|
+
ts.factory.createTypeQueryNode(
|
|
181
|
+
ts.factory.createIdentifier(p.name),
|
|
182
|
+
),
|
|
183
|
+
],
|
|
184
|
+
[ts.factory.createIdentifier(p.name)],
|
|
185
|
+
),
|
|
186
|
+
),
|
|
187
|
+
)
|
|
188
|
+
: []),
|
|
189
|
+
ts.factory.createReturnStatement(
|
|
190
|
+
config.simulate
|
|
191
|
+
? ts.factory.createConditionalExpression(
|
|
192
|
+
ts.factory.createIdentifier("!!connection.simulate"),
|
|
193
|
+
undefined,
|
|
194
|
+
ts.factory.createCallExpression(
|
|
195
|
+
ts.factory.createIdentifier(`${route.name}.simulate`),
|
|
196
|
+
[],
|
|
197
|
+
[
|
|
198
|
+
ts.factory.createIdentifier("connection"),
|
|
199
|
+
...route.parameters
|
|
200
|
+
.filter((p) => p.category !== "headers")
|
|
201
|
+
.map((p) => ts.factory.createIdentifier(p.name)),
|
|
202
|
+
],
|
|
203
|
+
),
|
|
204
|
+
undefined,
|
|
205
|
+
caller(),
|
|
206
|
+
)
|
|
207
|
+
: caller(),
|
|
208
|
+
),
|
|
209
|
+
];
|
|
210
|
+
};
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
const getTypeName =
|
|
214
|
+
(config: INestiaConfig) =>
|
|
215
|
+
(importer: ImportDictionary) =>
|
|
216
|
+
(p: IRoute.IParameter | IRoute.IOutput) =>
|
|
217
|
+
p.metadata
|
|
218
|
+
? SdkTypeProgrammer.decode(config)(importer)(p.metadata)
|
|
219
|
+
: ts.factory.createTypeReferenceNode(p.typeName);
|