@nestia/sdk 11.0.0-dev.20260316 → 11.0.1

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 (65) hide show
  1. package/LICENSE +21 -21
  2. package/README.md +93 -93
  3. package/assets/bundle/api/HttpError.ts +1 -1
  4. package/assets/bundle/api/IConnection.ts +1 -1
  5. package/assets/bundle/api/Primitive.ts +1 -1
  6. package/assets/bundle/api/Resolved.ts +1 -1
  7. package/assets/bundle/api/index.ts +4 -4
  8. package/assets/bundle/api/module.ts +6 -6
  9. package/assets/bundle/distribute/README.md +37 -37
  10. package/assets/bundle/distribute/package.json +28 -28
  11. package/assets/bundle/distribute/tsconfig.json +109 -109
  12. package/assets/bundle/e2e/index.ts +42 -42
  13. package/assets/config/nestia.config.ts +97 -97
  14. package/lib/executable/internal/NestiaConfigLoader.js +5 -5
  15. package/lib/executable/internal/NestiaConfigLoader.js.map +1 -1
  16. package/package.json +8 -8
  17. package/src/INestiaConfig.ts +267 -267
  18. package/src/NestiaSdkApplication.ts +307 -307
  19. package/src/NestiaSwaggerComposer.ts +143 -143
  20. package/src/analyses/AccessorAnalyzer.ts +67 -67
  21. package/src/analyses/DtoAnalyzer.ts +260 -260
  22. package/src/analyses/ImportAnalyzer.ts +126 -126
  23. package/src/analyses/ReflectHttpOperationAnalyzer.ts +183 -183
  24. package/src/analyses/ReflectHttpOperationExceptionAnalyzer.ts +72 -72
  25. package/src/analyses/ReflectHttpOperationParameterAnalyzer.ts +350 -350
  26. package/src/analyses/ReflectHttpOperationResponseAnalyzer.ts +126 -126
  27. package/src/analyses/TypedHttpRouteAnalyzer.ts +208 -208
  28. package/src/executable/internal/NestiaConfigLoader.ts +85 -85
  29. package/src/executable/internal/NestiaSdkCommand.ts +107 -107
  30. package/src/generates/SwaggerGenerator.ts +291 -291
  31. package/src/generates/internal/E2eFileProgrammer.ts +196 -196
  32. package/src/generates/internal/FilePrinter.ts +64 -64
  33. package/src/generates/internal/ImportDictionary.ts +192 -192
  34. package/src/generates/internal/SdkAliasCollection.ts +260 -260
  35. package/src/generates/internal/SdkFileProgrammer.ts +110 -110
  36. package/src/generates/internal/SdkHttpCloneProgrammer.ts +126 -126
  37. package/src/generates/internal/SdkHttpCloneReferencer.ts +77 -77
  38. package/src/generates/internal/SdkHttpFunctionProgrammer.ts +278 -278
  39. package/src/generates/internal/SdkHttpNamespaceProgrammer.ts +502 -502
  40. package/src/generates/internal/SdkHttpRouteProgrammer.ts +109 -109
  41. package/src/generates/internal/SdkHttpSimulationProgrammer.ts +312 -312
  42. package/src/generates/internal/SdkImportWizard.ts +62 -62
  43. package/src/generates/internal/SdkTypeProgrammer.ts +388 -388
  44. package/src/generates/internal/SdkTypeTagProgrammer.ts +114 -114
  45. package/src/generates/internal/SdkWebSocketNamespaceProgrammer.ts +379 -379
  46. package/src/generates/internal/SdkWebSocketRouteProgrammer.ts +302 -302
  47. package/src/generates/internal/SwaggerOperationComposer.ts +119 -119
  48. package/src/generates/internal/SwaggerOperationParameterComposer.ts +161 -161
  49. package/src/generates/internal/SwaggerOperationResponseComposer.ts +110 -110
  50. package/src/module.ts +4 -4
  51. package/src/structures/IReflectHttpOperationException.ts +18 -18
  52. package/src/structures/IReflectHttpOperationParameter.ts +79 -79
  53. package/src/structures/IReflectHttpOperationSuccess.ts +21 -21
  54. package/src/structures/ITypedApplication.ts +11 -11
  55. package/src/structures/ITypedHttpRouteException.ts +15 -15
  56. package/src/structures/ITypedHttpRouteParameter.ts +41 -41
  57. package/src/structures/ITypedHttpRouteSuccess.ts +22 -22
  58. package/src/transformers/IOperationMetadata.ts +46 -46
  59. package/src/transformers/ISdkOperationTransformerContext.ts +8 -8
  60. package/src/transformers/SdkOperationProgrammer.ts +240 -240
  61. package/src/transformers/SdkOperationTransformer.ts +248 -248
  62. package/src/transformers/TextPlainValidator.ts +17 -17
  63. package/src/utils/MetadataUtil.ts +26 -26
  64. package/src/validators/HttpHeadersValidator.ts +40 -40
  65. package/src/validators/HttpQueryValidator.ts +40 -40
@@ -1,196 +1,196 @@
1
- import { IdentifierFactory, LiteralFactory } from "@typia/core";
2
- import ts from "typescript";
3
-
4
- import { INestiaProject } from "../../structures/INestiaProject";
5
- import { ITypedHttpRoute } from "../../structures/ITypedHttpRoute";
6
- import { FilePrinter } from "./FilePrinter";
7
- import { ImportDictionary } from "./ImportDictionary";
8
- import { SdkAliasCollection } from "./SdkAliasCollection";
9
- import { SdkHttpParameterProgrammer } from "./SdkHttpParameterProgrammer";
10
- import { SdkImportWizard } from "./SdkImportWizard";
11
-
12
- export namespace E2eFileProgrammer {
13
- export const generate =
14
- (project: INestiaProject) =>
15
- (props: { api: string; current: string }) =>
16
- async (route: ITypedHttpRoute): Promise<void> => {
17
- const importer: ImportDictionary = new ImportDictionary(
18
- `${props.current}/${getFunctionName(route)}.ts`,
19
- );
20
- if (project.config.clone !== true) importer.declarations(route.imports);
21
- importer.internal({
22
- file: props.api,
23
- declaration: false,
24
- type: "default",
25
- name: "api",
26
- });
27
- const functor: ts.Statement = generateFunctor(project)(importer)(route);
28
- await FilePrinter.write({
29
- location: importer.file,
30
- statements: [
31
- ...importer.toStatements(props.current),
32
- FilePrinter.enter(),
33
- functor,
34
- ],
35
- });
36
- };
37
-
38
- const generateFunctor =
39
- (project: INestiaProject) =>
40
- (importer: ImportDictionary) =>
41
- (route: ITypedHttpRoute): ts.Statement =>
42
- ts.factory.createVariableStatement(
43
- [ts.factory.createModifier(ts.SyntaxKind.ExportKeyword)],
44
- ts.factory.createVariableDeclarationList(
45
- [
46
- ts.factory.createVariableDeclaration(
47
- ts.factory.createIdentifier(getFunctionName(route)),
48
- undefined,
49
- undefined,
50
- generateArrow(project)(importer)(route),
51
- ),
52
- ],
53
- ts.NodeFlags.Const,
54
- ),
55
- );
56
-
57
- const generateArrow =
58
- (project: INestiaProject) =>
59
- (importer: ImportDictionary) =>
60
- (route: ITypedHttpRoute) => {
61
- const random = IdentifierFactory.access(
62
- ts.factory.createIdentifier(SdkImportWizard.typia(importer)),
63
- "random",
64
- );
65
- const connection = route.headerObject
66
- ? ts.factory.createObjectLiteralExpression(
67
- [
68
- ts.factory.createSpreadAssignment(
69
- ts.factory.createIdentifier("connection"),
70
- ),
71
- ts.factory.createPropertyAssignment(
72
- "headers",
73
- ts.factory.createObjectLiteralExpression(
74
- [
75
- ts.factory.createSpreadAssignment(
76
- IdentifierFactory.access(
77
- ts.factory.createIdentifier("connection"),
78
- "headers",
79
- ),
80
- ),
81
- ts.factory.createSpreadAssignment(
82
- ts.factory.createCallExpression(
83
- random,
84
- [
85
- project.config.clone === true
86
- ? SdkAliasCollection.from(project)(importer)(
87
- route.headerObject.metadata,
88
- )
89
- : SdkAliasCollection.name(route.headerObject),
90
- ],
91
- undefined,
92
- ),
93
- ),
94
- ],
95
- true,
96
- ),
97
- ),
98
- ],
99
- true,
100
- )
101
- : ts.factory.createIdentifier("connection");
102
- const entries = SdkHttpParameterProgrammer.getEntries({
103
- project,
104
- importer,
105
- route,
106
- body: true,
107
- e2e: true,
108
- prefix: ["api", "functional", ...route.accessor].join(".") + ".",
109
- });
110
- const fetch = ts.factory.createCallExpression(
111
- ts.factory.createIdentifier(
112
- ["api", "functional", ...route.accessor].join("."),
113
- ),
114
- undefined,
115
- [
116
- connection,
117
- ...(project.config.keyword === true && entries.length !== 0
118
- ? [
119
- LiteralFactory.write(
120
- Object.fromEntries(
121
- entries.map((e) => [
122
- e.key,
123
- ts.factory.createCallExpression(
124
- IdentifierFactory.access(
125
- ts.factory.createIdentifier(
126
- SdkImportWizard.typia(importer),
127
- ),
128
- "random",
129
- ),
130
- [e.type],
131
- undefined,
132
- ),
133
- ]),
134
- ),
135
- ),
136
- ]
137
- : entries.map((e) =>
138
- ts.factory.createCallExpression(
139
- IdentifierFactory.access(
140
- ts.factory.createIdentifier(
141
- SdkImportWizard.typia(importer),
142
- ),
143
- "random",
144
- ),
145
- [e.type],
146
- undefined,
147
- ),
148
- )),
149
- ],
150
- );
151
- const assert = ts.factory.createCallExpression(
152
- IdentifierFactory.access(
153
- ts.factory.createIdentifier(SdkImportWizard.typia(importer)),
154
- "assert",
155
- ),
156
- undefined,
157
- [ts.factory.createIdentifier("output")],
158
- );
159
-
160
- return ts.factory.createArrowFunction(
161
- [ts.factory.createModifier(ts.SyntaxKind.AsyncKeyword)],
162
- undefined,
163
- [
164
- IdentifierFactory.parameter(
165
- "connection",
166
- ts.factory.createTypeReferenceNode("api.IConnection"),
167
- ),
168
- ],
169
- undefined,
170
- undefined,
171
- ts.factory.createBlock([
172
- ts.factory.createVariableStatement(
173
- [],
174
- ts.factory.createVariableDeclarationList(
175
- [
176
- ts.factory.createVariableDeclaration(
177
- "output",
178
- undefined,
179
- project.config.propagate !== true &&
180
- route.success.type.name === "void"
181
- ? undefined
182
- : SdkAliasCollection.response(project)(importer)(route),
183
- ts.factory.createAwaitExpression(fetch),
184
- ),
185
- ],
186
- ts.NodeFlags.Const,
187
- ),
188
- ),
189
- ts.factory.createExpressionStatement(assert),
190
- ]),
191
- );
192
- };
193
- }
194
-
195
- const getFunctionName = (route: ITypedHttpRoute): string =>
196
- ["test", "api", ...route.accessor].join("_");
1
+ import { IdentifierFactory, LiteralFactory } from "@typia/core";
2
+ import ts from "typescript";
3
+
4
+ import { INestiaProject } from "../../structures/INestiaProject";
5
+ import { ITypedHttpRoute } from "../../structures/ITypedHttpRoute";
6
+ import { FilePrinter } from "./FilePrinter";
7
+ import { ImportDictionary } from "./ImportDictionary";
8
+ import { SdkAliasCollection } from "./SdkAliasCollection";
9
+ import { SdkHttpParameterProgrammer } from "./SdkHttpParameterProgrammer";
10
+ import { SdkImportWizard } from "./SdkImportWizard";
11
+
12
+ export namespace E2eFileProgrammer {
13
+ export const generate =
14
+ (project: INestiaProject) =>
15
+ (props: { api: string; current: string }) =>
16
+ async (route: ITypedHttpRoute): Promise<void> => {
17
+ const importer: ImportDictionary = new ImportDictionary(
18
+ `${props.current}/${getFunctionName(route)}.ts`,
19
+ );
20
+ if (project.config.clone !== true) importer.declarations(route.imports);
21
+ importer.internal({
22
+ file: props.api,
23
+ declaration: false,
24
+ type: "default",
25
+ name: "api",
26
+ });
27
+ const functor: ts.Statement = generateFunctor(project)(importer)(route);
28
+ await FilePrinter.write({
29
+ location: importer.file,
30
+ statements: [
31
+ ...importer.toStatements(props.current),
32
+ FilePrinter.enter(),
33
+ functor,
34
+ ],
35
+ });
36
+ };
37
+
38
+ const generateFunctor =
39
+ (project: INestiaProject) =>
40
+ (importer: ImportDictionary) =>
41
+ (route: ITypedHttpRoute): ts.Statement =>
42
+ ts.factory.createVariableStatement(
43
+ [ts.factory.createModifier(ts.SyntaxKind.ExportKeyword)],
44
+ ts.factory.createVariableDeclarationList(
45
+ [
46
+ ts.factory.createVariableDeclaration(
47
+ ts.factory.createIdentifier(getFunctionName(route)),
48
+ undefined,
49
+ undefined,
50
+ generateArrow(project)(importer)(route),
51
+ ),
52
+ ],
53
+ ts.NodeFlags.Const,
54
+ ),
55
+ );
56
+
57
+ const generateArrow =
58
+ (project: INestiaProject) =>
59
+ (importer: ImportDictionary) =>
60
+ (route: ITypedHttpRoute) => {
61
+ const random = IdentifierFactory.access(
62
+ ts.factory.createIdentifier(SdkImportWizard.typia(importer)),
63
+ "random",
64
+ );
65
+ const connection = route.headerObject
66
+ ? ts.factory.createObjectLiteralExpression(
67
+ [
68
+ ts.factory.createSpreadAssignment(
69
+ ts.factory.createIdentifier("connection"),
70
+ ),
71
+ ts.factory.createPropertyAssignment(
72
+ "headers",
73
+ ts.factory.createObjectLiteralExpression(
74
+ [
75
+ ts.factory.createSpreadAssignment(
76
+ IdentifierFactory.access(
77
+ ts.factory.createIdentifier("connection"),
78
+ "headers",
79
+ ),
80
+ ),
81
+ ts.factory.createSpreadAssignment(
82
+ ts.factory.createCallExpression(
83
+ random,
84
+ [
85
+ project.config.clone === true
86
+ ? SdkAliasCollection.from(project)(importer)(
87
+ route.headerObject.metadata,
88
+ )
89
+ : SdkAliasCollection.name(route.headerObject),
90
+ ],
91
+ undefined,
92
+ ),
93
+ ),
94
+ ],
95
+ true,
96
+ ),
97
+ ),
98
+ ],
99
+ true,
100
+ )
101
+ : ts.factory.createIdentifier("connection");
102
+ const entries = SdkHttpParameterProgrammer.getEntries({
103
+ project,
104
+ importer,
105
+ route,
106
+ body: true,
107
+ e2e: true,
108
+ prefix: ["api", "functional", ...route.accessor].join(".") + ".",
109
+ });
110
+ const fetch = ts.factory.createCallExpression(
111
+ ts.factory.createIdentifier(
112
+ ["api", "functional", ...route.accessor].join("."),
113
+ ),
114
+ undefined,
115
+ [
116
+ connection,
117
+ ...(project.config.keyword === true && entries.length !== 0
118
+ ? [
119
+ LiteralFactory.write(
120
+ Object.fromEntries(
121
+ entries.map((e) => [
122
+ e.key,
123
+ ts.factory.createCallExpression(
124
+ IdentifierFactory.access(
125
+ ts.factory.createIdentifier(
126
+ SdkImportWizard.typia(importer),
127
+ ),
128
+ "random",
129
+ ),
130
+ [e.type],
131
+ undefined,
132
+ ),
133
+ ]),
134
+ ),
135
+ ),
136
+ ]
137
+ : entries.map((e) =>
138
+ ts.factory.createCallExpression(
139
+ IdentifierFactory.access(
140
+ ts.factory.createIdentifier(
141
+ SdkImportWizard.typia(importer),
142
+ ),
143
+ "random",
144
+ ),
145
+ [e.type],
146
+ undefined,
147
+ ),
148
+ )),
149
+ ],
150
+ );
151
+ const assert = ts.factory.createCallExpression(
152
+ IdentifierFactory.access(
153
+ ts.factory.createIdentifier(SdkImportWizard.typia(importer)),
154
+ "assert",
155
+ ),
156
+ undefined,
157
+ [ts.factory.createIdentifier("output")],
158
+ );
159
+
160
+ return ts.factory.createArrowFunction(
161
+ [ts.factory.createModifier(ts.SyntaxKind.AsyncKeyword)],
162
+ undefined,
163
+ [
164
+ IdentifierFactory.parameter(
165
+ "connection",
166
+ ts.factory.createTypeReferenceNode("api.IConnection"),
167
+ ),
168
+ ],
169
+ undefined,
170
+ undefined,
171
+ ts.factory.createBlock([
172
+ ts.factory.createVariableStatement(
173
+ [],
174
+ ts.factory.createVariableDeclarationList(
175
+ [
176
+ ts.factory.createVariableDeclaration(
177
+ "output",
178
+ undefined,
179
+ project.config.propagate !== true &&
180
+ route.success.type.name === "void"
181
+ ? undefined
182
+ : SdkAliasCollection.response(project)(importer)(route),
183
+ ts.factory.createAwaitExpression(fetch),
184
+ ),
185
+ ],
186
+ ts.NodeFlags.Const,
187
+ ),
188
+ ),
189
+ ts.factory.createExpressionStatement(assert),
190
+ ]),
191
+ );
192
+ };
193
+ }
194
+
195
+ const getFunctionName = (route: ITypedHttpRoute): string =>
196
+ ["test", "api", ...route.accessor].join("_");
@@ -1,64 +1,64 @@
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
- [
15
- "*",
16
- ...comment
17
- .split("\r\n")
18
- .join("\n")
19
- .split("\n")
20
- .map(
21
- (str) =>
22
- ` * ${str.split("*/").join("*\\\\/").split("*\\/").join("*\\\\/")}`,
23
- ),
24
- "",
25
- ].join("\n"),
26
- true,
27
- );
28
- return node;
29
- };
30
-
31
- export const enter = () =>
32
- ts.factory.createExpressionStatement(ts.factory.createIdentifier("\n"));
33
-
34
- export const write = async (props: {
35
- location: string;
36
- statements: ts.Statement[];
37
- top?: string;
38
- }): Promise<void> => {
39
- const script: string = ts
40
- .createPrinter()
41
- .printFile(
42
- ts.factory.createSourceFile(
43
- props.statements,
44
- ts.factory.createToken(ts.SyntaxKind.EndOfFileToken),
45
- ts.NodeFlags.None,
46
- ),
47
- );
48
- await fs.promises.writeFile(
49
- props.location,
50
- await beautify((props.top ?? "") + script),
51
- "utf8",
52
- );
53
- };
54
-
55
- const beautify = async (script: string): Promise<string> => {
56
- try {
57
- return await format(script, {
58
- parser: "typescript",
59
- });
60
- } catch {
61
- return script;
62
- }
63
- };
64
- }
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
+ [
15
+ "*",
16
+ ...comment
17
+ .split("\r\n")
18
+ .join("\n")
19
+ .split("\n")
20
+ .map(
21
+ (str) =>
22
+ ` * ${str.split("*/").join("*\\\\/").split("*\\/").join("*\\\\/")}`,
23
+ ),
24
+ "",
25
+ ].join("\n"),
26
+ true,
27
+ );
28
+ return node;
29
+ };
30
+
31
+ export const enter = () =>
32
+ ts.factory.createExpressionStatement(ts.factory.createIdentifier("\n"));
33
+
34
+ export const write = async (props: {
35
+ location: string;
36
+ statements: ts.Statement[];
37
+ top?: string;
38
+ }): Promise<void> => {
39
+ const script: string = ts
40
+ .createPrinter()
41
+ .printFile(
42
+ ts.factory.createSourceFile(
43
+ props.statements,
44
+ ts.factory.createToken(ts.SyntaxKind.EndOfFileToken),
45
+ ts.NodeFlags.None,
46
+ ),
47
+ );
48
+ await fs.promises.writeFile(
49
+ props.location,
50
+ await beautify((props.top ?? "") + script),
51
+ "utf8",
52
+ );
53
+ };
54
+
55
+ const beautify = async (script: string): Promise<string> => {
56
+ try {
57
+ return await format(script, {
58
+ parser: "typescript",
59
+ });
60
+ } catch {
61
+ return script;
62
+ }
63
+ };
64
+ }