@nestia/sdk 2.6.3-dev.20240328 → 2.6.4-dev.20240401

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.
Files changed (45) hide show
  1. package/lib/INestiaConfig.d.ts +14 -2
  2. package/lib/executable/internal/NestiaConfigLoader.js +31 -5
  3. package/lib/executable/internal/NestiaConfigLoader.js.map +1 -1
  4. package/lib/generates/SwaggerGenerator.d.ts +2 -0
  5. package/lib/generates/SwaggerGenerator.js +19 -3
  6. package/lib/generates/SwaggerGenerator.js.map +1 -1
  7. package/lib/structures/ISwagger.d.ts +5 -28
  8. package/lib/structures/ISwaggerServer.d.ts +15 -0
  9. package/lib/structures/ISwaggerServer.js +3 -0
  10. package/lib/structures/ISwaggerServer.js.map +1 -0
  11. package/lib/structures/ISwaggerTag.d.ts +9 -0
  12. package/lib/structures/ISwaggerTag.js +3 -0
  13. package/lib/structures/ISwaggerTag.js.map +1 -0
  14. package/package.json +3 -3
  15. package/src/INestiaConfig.ts +261 -248
  16. package/src/NestiaSdkApplication.ts +255 -255
  17. package/src/analyses/ExceptionAnalyzer.ts +148 -148
  18. package/src/analyses/ImportAnalyzer.ts +137 -137
  19. package/src/analyses/SecurityAnalyzer.ts +24 -24
  20. package/src/generates/CloneGenerator.ts +62 -62
  21. package/src/generates/E2eGenerator.ts +66 -66
  22. package/src/generates/SdkGenerator.ts +84 -84
  23. package/src/generates/SwaggerGenerator.ts +23 -3
  24. package/src/generates/internal/E2eFileProgrammer.ts +182 -182
  25. package/src/generates/internal/FilePrinter.ts +53 -53
  26. package/src/generates/internal/SdkAliasCollection.ts +152 -152
  27. package/src/generates/internal/SdkCloneProgrammer.ts +155 -155
  28. package/src/generates/internal/SdkFileProgrammer.ts +115 -115
  29. package/src/generates/internal/SdkFunctionProgrammer.ts +298 -298
  30. package/src/generates/internal/SdkImportWizard.ts +55 -55
  31. package/src/generates/internal/SdkNamespaceProgrammer.ts +510 -510
  32. package/src/generates/internal/SdkRouteProgrammer.ts +83 -83
  33. package/src/generates/internal/SdkSimulationProgrammer.ts +365 -365
  34. package/src/generates/internal/SdkTypeProgrammer.ts +385 -385
  35. package/src/generates/internal/SwaggerSchemaGenerator.ts +438 -438
  36. package/src/structures/IController.ts +94 -94
  37. package/src/structures/IRoute.ts +53 -53
  38. package/src/structures/ISwagger.ts +66 -91
  39. package/src/structures/ISwaggerRoute.ts +54 -54
  40. package/src/structures/ISwaggerSecurityScheme.ts +65 -65
  41. package/src/structures/ISwaggerServer.ts +16 -0
  42. package/src/structures/ISwaggerTag.ts +9 -0
  43. package/src/structures/ParamCategory.ts +1 -1
  44. package/src/structures/TypeEntry.ts +22 -22
  45. package/src/utils/StringUtil.ts +6 -6
@@ -1,182 +1,182 @@
1
- import ts from "typescript";
2
- import { IdentifierFactory } from "typia/lib/factories/IdentifierFactory";
3
-
4
- import { INestiaConfig } from "../../INestiaConfig";
5
- import { IRoute } from "../../structures/IRoute";
6
- import { FilePrinter } from "./FilePrinter";
7
- import { ImportDictionary } from "./ImportDictionary";
8
- import { SdkAliasCollection } from "./SdkAliasCollection";
9
- import { SdkImportWizard } from "./SdkImportWizard";
10
- import { SdkTypeProgrammer } from "./SdkTypeProgrammer";
11
-
12
- export namespace E2eFileProgrammer {
13
- export const generate =
14
- (checker: ts.TypeChecker) =>
15
- (config: INestiaConfig) =>
16
- (props: { api: string; current: string }) =>
17
- async (route: IRoute): Promise<void> => {
18
- const importer: ImportDictionary = new ImportDictionary(
19
- `${props.current}/${getFunctionName(route)}.ts`,
20
- );
21
- if (config.clone !== true)
22
- for (const tuple of route.imports)
23
- for (const instance of tuple[1])
24
- importer.internal({
25
- file: tuple[0],
26
- type: true,
27
- instance,
28
- });
29
- importer.internal({
30
- type: false,
31
- file: props.api,
32
- instance: null,
33
- name: "api",
34
- });
35
-
36
- const functor = generate_function(checker)(config)(importer)(route);
37
- await FilePrinter.write({
38
- location: importer.file,
39
- statements: [
40
- ...importer.toStatements(props.current),
41
- FilePrinter.enter(),
42
- functor,
43
- ],
44
- });
45
- };
46
-
47
- const generate_function =
48
- (checker: ts.TypeChecker) =>
49
- (config: INestiaConfig) =>
50
- (importer: ImportDictionary) =>
51
- (route: IRoute): ts.Statement =>
52
- ts.factory.createVariableStatement(
53
- [ts.factory.createModifier(ts.SyntaxKind.ExportKeyword)],
54
- ts.factory.createVariableDeclarationList(
55
- [
56
- ts.factory.createVariableDeclaration(
57
- ts.factory.createIdentifier(getFunctionName(route)),
58
- undefined,
59
- undefined,
60
- generate_arrow(checker)(config)(importer)(route),
61
- ),
62
- ],
63
- ts.NodeFlags.Const,
64
- ),
65
- );
66
-
67
- const generate_arrow =
68
- (checker: ts.TypeChecker) =>
69
- (config: INestiaConfig) =>
70
- (importer: ImportDictionary) =>
71
- (route: IRoute) => {
72
- const headers = route.parameters.find(
73
- (p) => p.category === "headers" && p.field === undefined,
74
- );
75
- const connection = headers
76
- ? ts.factory.createObjectLiteralExpression(
77
- [
78
- ts.factory.createSpreadAssignment(
79
- ts.factory.createIdentifier("connection"),
80
- ),
81
- ts.factory.createPropertyAssignment(
82
- "headers",
83
- ts.factory.createObjectLiteralExpression(
84
- [
85
- ts.factory.createSpreadAssignment(
86
- IdentifierFactory.access(
87
- ts.factory.createIdentifier("connection"),
88
- )("headers"),
89
- ),
90
- ts.factory.createSpreadAssignment(
91
- ts.factory.createCallExpression(
92
- IdentifierFactory.access(
93
- ts.factory.createIdentifier(
94
- SdkImportWizard.typia(importer),
95
- ),
96
- )("random"),
97
- [getTypeName(config)(importer)(headers)],
98
- undefined,
99
- ),
100
- ),
101
- ],
102
- true,
103
- ),
104
- ),
105
- ],
106
- true,
107
- )
108
- : ts.factory.createIdentifier("connection");
109
- const caller = ts.factory.createCallExpression(
110
- ts.factory.createIdentifier(
111
- ["api", "functional", ...route.accessors].join("."),
112
- ),
113
- undefined,
114
- [
115
- connection,
116
- ...route.parameters
117
- .filter((p) => p.category !== "headers")
118
- .map((p) =>
119
- ts.factory.createCallExpression(
120
- IdentifierFactory.access(
121
- ts.factory.createIdentifier(SdkImportWizard.typia(importer)),
122
- )("random"),
123
- [getTypeName(config)(importer)(p)],
124
- undefined,
125
- ),
126
- ),
127
- ],
128
- );
129
- const assert = ts.factory.createCallExpression(
130
- IdentifierFactory.access(
131
- ts.factory.createIdentifier(SdkImportWizard.typia(importer)),
132
- )("assert"),
133
- undefined,
134
- [ts.factory.createIdentifier("output")],
135
- );
136
-
137
- return ts.factory.createArrowFunction(
138
- [ts.factory.createModifier(ts.SyntaxKind.AsyncKeyword)],
139
- undefined,
140
- [
141
- IdentifierFactory.parameter(
142
- "connection",
143
- ts.factory.createTypeReferenceNode("api.IConnection"),
144
- ),
145
- ],
146
- undefined,
147
- undefined,
148
- ts.factory.createBlock([
149
- ts.factory.createVariableStatement(
150
- [],
151
- ts.factory.createVariableDeclarationList(
152
- [
153
- ts.factory.createVariableDeclaration(
154
- "output",
155
- undefined,
156
- config.propagate !== true && route.output.typeName === "void"
157
- ? undefined
158
- : SdkAliasCollection.output(checker)(config)(importer)(
159
- route,
160
- ),
161
- ts.factory.createAwaitExpression(caller),
162
- ),
163
- ],
164
- ts.NodeFlags.Const,
165
- ),
166
- ),
167
- ts.factory.createExpressionStatement(assert),
168
- ]),
169
- );
170
- };
171
- }
172
-
173
- const getFunctionName = (route: IRoute): string =>
174
- ["test", "api", ...route.accessors].join("_");
175
-
176
- const getTypeName =
177
- (config: INestiaConfig) =>
178
- (importer: ImportDictionary) =>
179
- (p: IRoute.IParameter | IRoute.IOutput) =>
180
- p.metadata
181
- ? SdkTypeProgrammer.write(config)(importer)(p.metadata)
182
- : ts.factory.createTypeReferenceNode(p.typeName);
1
+ import ts from "typescript";
2
+ import { IdentifierFactory } from "typia/lib/factories/IdentifierFactory";
3
+
4
+ import { INestiaConfig } from "../../INestiaConfig";
5
+ import { IRoute } from "../../structures/IRoute";
6
+ import { FilePrinter } from "./FilePrinter";
7
+ import { ImportDictionary } from "./ImportDictionary";
8
+ import { SdkAliasCollection } from "./SdkAliasCollection";
9
+ import { SdkImportWizard } from "./SdkImportWizard";
10
+ import { SdkTypeProgrammer } from "./SdkTypeProgrammer";
11
+
12
+ export namespace E2eFileProgrammer {
13
+ export const generate =
14
+ (checker: ts.TypeChecker) =>
15
+ (config: INestiaConfig) =>
16
+ (props: { api: string; current: string }) =>
17
+ async (route: IRoute): Promise<void> => {
18
+ const importer: ImportDictionary = new ImportDictionary(
19
+ `${props.current}/${getFunctionName(route)}.ts`,
20
+ );
21
+ if (config.clone !== true)
22
+ for (const tuple of route.imports)
23
+ for (const instance of tuple[1])
24
+ importer.internal({
25
+ file: tuple[0],
26
+ type: true,
27
+ instance,
28
+ });
29
+ importer.internal({
30
+ type: false,
31
+ file: props.api,
32
+ instance: null,
33
+ name: "api",
34
+ });
35
+
36
+ const functor = generate_function(checker)(config)(importer)(route);
37
+ await FilePrinter.write({
38
+ location: importer.file,
39
+ statements: [
40
+ ...importer.toStatements(props.current),
41
+ FilePrinter.enter(),
42
+ functor,
43
+ ],
44
+ });
45
+ };
46
+
47
+ const generate_function =
48
+ (checker: ts.TypeChecker) =>
49
+ (config: INestiaConfig) =>
50
+ (importer: ImportDictionary) =>
51
+ (route: IRoute): ts.Statement =>
52
+ ts.factory.createVariableStatement(
53
+ [ts.factory.createModifier(ts.SyntaxKind.ExportKeyword)],
54
+ ts.factory.createVariableDeclarationList(
55
+ [
56
+ ts.factory.createVariableDeclaration(
57
+ ts.factory.createIdentifier(getFunctionName(route)),
58
+ undefined,
59
+ undefined,
60
+ generate_arrow(checker)(config)(importer)(route),
61
+ ),
62
+ ],
63
+ ts.NodeFlags.Const,
64
+ ),
65
+ );
66
+
67
+ const generate_arrow =
68
+ (checker: ts.TypeChecker) =>
69
+ (config: INestiaConfig) =>
70
+ (importer: ImportDictionary) =>
71
+ (route: IRoute) => {
72
+ const headers = route.parameters.find(
73
+ (p) => p.category === "headers" && p.field === undefined,
74
+ );
75
+ const connection = headers
76
+ ? ts.factory.createObjectLiteralExpression(
77
+ [
78
+ ts.factory.createSpreadAssignment(
79
+ ts.factory.createIdentifier("connection"),
80
+ ),
81
+ ts.factory.createPropertyAssignment(
82
+ "headers",
83
+ ts.factory.createObjectLiteralExpression(
84
+ [
85
+ ts.factory.createSpreadAssignment(
86
+ IdentifierFactory.access(
87
+ ts.factory.createIdentifier("connection"),
88
+ )("headers"),
89
+ ),
90
+ ts.factory.createSpreadAssignment(
91
+ ts.factory.createCallExpression(
92
+ IdentifierFactory.access(
93
+ ts.factory.createIdentifier(
94
+ SdkImportWizard.typia(importer),
95
+ ),
96
+ )("random"),
97
+ [getTypeName(config)(importer)(headers)],
98
+ undefined,
99
+ ),
100
+ ),
101
+ ],
102
+ true,
103
+ ),
104
+ ),
105
+ ],
106
+ true,
107
+ )
108
+ : ts.factory.createIdentifier("connection");
109
+ const caller = ts.factory.createCallExpression(
110
+ ts.factory.createIdentifier(
111
+ ["api", "functional", ...route.accessors].join("."),
112
+ ),
113
+ undefined,
114
+ [
115
+ connection,
116
+ ...route.parameters
117
+ .filter((p) => p.category !== "headers")
118
+ .map((p) =>
119
+ ts.factory.createCallExpression(
120
+ IdentifierFactory.access(
121
+ ts.factory.createIdentifier(SdkImportWizard.typia(importer)),
122
+ )("random"),
123
+ [getTypeName(config)(importer)(p)],
124
+ undefined,
125
+ ),
126
+ ),
127
+ ],
128
+ );
129
+ const assert = ts.factory.createCallExpression(
130
+ IdentifierFactory.access(
131
+ ts.factory.createIdentifier(SdkImportWizard.typia(importer)),
132
+ )("assert"),
133
+ undefined,
134
+ [ts.factory.createIdentifier("output")],
135
+ );
136
+
137
+ return ts.factory.createArrowFunction(
138
+ [ts.factory.createModifier(ts.SyntaxKind.AsyncKeyword)],
139
+ undefined,
140
+ [
141
+ IdentifierFactory.parameter(
142
+ "connection",
143
+ ts.factory.createTypeReferenceNode("api.IConnection"),
144
+ ),
145
+ ],
146
+ undefined,
147
+ undefined,
148
+ ts.factory.createBlock([
149
+ ts.factory.createVariableStatement(
150
+ [],
151
+ ts.factory.createVariableDeclarationList(
152
+ [
153
+ ts.factory.createVariableDeclaration(
154
+ "output",
155
+ undefined,
156
+ config.propagate !== true && route.output.typeName === "void"
157
+ ? undefined
158
+ : SdkAliasCollection.output(checker)(config)(importer)(
159
+ route,
160
+ ),
161
+ ts.factory.createAwaitExpression(caller),
162
+ ),
163
+ ],
164
+ ts.NodeFlags.Const,
165
+ ),
166
+ ),
167
+ ts.factory.createExpressionStatement(assert),
168
+ ]),
169
+ );
170
+ };
171
+ }
172
+
173
+ const getFunctionName = (route: IRoute): string =>
174
+ ["test", "api", ...route.accessors].join("_");
175
+
176
+ const getTypeName =
177
+ (config: INestiaConfig) =>
178
+ (importer: ImportDictionary) =>
179
+ (p: IRoute.IParameter | IRoute.IOutput) =>
180
+ p.metadata
181
+ ? SdkTypeProgrammer.write(config)(importer)(p.metadata)
182
+ : ts.factory.createTypeReferenceNode(p.typeName);
@@ -1,53 +1,53 @@
1
- import fs from "fs";
2
- import { format } from "prettier";
3
- import ts from "typescript";
4
-
5
- export namespace FilePrinter {
6
- export const description = <Node extends ts.Node>(
7
- node: Node,
8
- comment: string,
9
- ): Node => {
10
- if (comment.length === 0) return node;
11
- ts.addSyntheticLeadingComment(
12
- node,
13
- ts.SyntaxKind.MultiLineCommentTrivia,
14
- ["*", ...comment.split("\n").map((str) => ` * ${str}`), ""].join("\n"),
15
- true,
16
- );
17
- return node;
18
- };
19
-
20
- export const enter = () =>
21
- ts.factory.createExpressionStatement(ts.factory.createIdentifier("\n"));
22
-
23
- export const write = async (props: {
24
- location: string;
25
- statements: ts.Statement[];
26
- top?: string;
27
- }): Promise<void> => {
28
- const script: string = ts
29
- .createPrinter()
30
- .printFile(
31
- ts.factory.createSourceFile(
32
- props.statements,
33
- ts.factory.createToken(ts.SyntaxKind.EndOfFileToken),
34
- ts.NodeFlags.None,
35
- ),
36
- );
37
- await fs.promises.writeFile(
38
- props.location,
39
- await beautify((props.top ?? "") + script),
40
- "utf8",
41
- );
42
- };
43
-
44
- const beautify = async (script: string): Promise<string> => {
45
- try {
46
- return await format(script, {
47
- parser: "typescript",
48
- });
49
- } catch {
50
- return script;
51
- }
52
- };
53
- }
1
+ import fs from "fs";
2
+ import { format } from "prettier";
3
+ import ts from "typescript";
4
+
5
+ export namespace FilePrinter {
6
+ export const description = <Node extends ts.Node>(
7
+ node: Node,
8
+ comment: string,
9
+ ): Node => {
10
+ if (comment.length === 0) return node;
11
+ ts.addSyntheticLeadingComment(
12
+ node,
13
+ ts.SyntaxKind.MultiLineCommentTrivia,
14
+ ["*", ...comment.split("\n").map((str) => ` * ${str}`), ""].join("\n"),
15
+ true,
16
+ );
17
+ return node;
18
+ };
19
+
20
+ export const enter = () =>
21
+ ts.factory.createExpressionStatement(ts.factory.createIdentifier("\n"));
22
+
23
+ export const write = async (props: {
24
+ location: string;
25
+ statements: ts.Statement[];
26
+ top?: string;
27
+ }): Promise<void> => {
28
+ const script: string = ts
29
+ .createPrinter()
30
+ .printFile(
31
+ ts.factory.createSourceFile(
32
+ props.statements,
33
+ ts.factory.createToken(ts.SyntaxKind.EndOfFileToken),
34
+ ts.NodeFlags.None,
35
+ ),
36
+ );
37
+ await fs.promises.writeFile(
38
+ props.location,
39
+ await beautify((props.top ?? "") + script),
40
+ "utf8",
41
+ );
42
+ };
43
+
44
+ const beautify = async (script: string): Promise<string> => {
45
+ try {
46
+ return await format(script, {
47
+ parser: "typescript",
48
+ });
49
+ } catch {
50
+ return script;
51
+ }
52
+ };
53
+ }