@nestia/sdk 3.0.0-dev.20231209 → 3.0.0-dev.20240412

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 (168) hide show
  1. package/README.md +12 -9
  2. package/assets/config/nestia.config.ts +82 -79
  3. package/lib/INestiaConfig.d.ts +28 -6
  4. package/lib/NestiaSdkApplication.js +12 -10
  5. package/lib/NestiaSdkApplication.js.map +1 -1
  6. package/lib/analyses/ConfigAnalyzer.js +1 -1
  7. package/lib/analyses/ConfigAnalyzer.js.map +1 -1
  8. package/lib/analyses/ControllerAnalyzer.js +30 -15
  9. package/lib/analyses/ControllerAnalyzer.js.map +1 -1
  10. package/lib/analyses/ExceptionAnalyzer.js +35 -6
  11. package/lib/analyses/ExceptionAnalyzer.js.map +1 -1
  12. package/lib/analyses/ImportAnalyzer.d.ts +1 -2
  13. package/lib/analyses/ImportAnalyzer.js +2 -2
  14. package/lib/analyses/ImportAnalyzer.js.map +1 -1
  15. package/lib/analyses/PathAnalyzer.d.ts +2 -4
  16. package/lib/analyses/PathAnalyzer.js +27 -11
  17. package/lib/analyses/PathAnalyzer.js.map +1 -1
  18. package/lib/analyses/ReflectAnalyzer.js +34 -22
  19. package/lib/analyses/ReflectAnalyzer.js.map +1 -1
  20. package/lib/analyses/SecurityAnalyzer.js +13 -8
  21. package/lib/analyses/SecurityAnalyzer.js.map +1 -1
  22. package/lib/executable/internal/NestiaConfigLoader.js +300 -220
  23. package/lib/executable/internal/NestiaConfigLoader.js.map +1 -1
  24. package/lib/executable/sdk.js +11 -11
  25. package/lib/generates/CloneGenerator.d.ts +6 -0
  26. package/lib/generates/CloneGenerator.js +62 -0
  27. package/lib/generates/CloneGenerator.js.map +1 -0
  28. package/lib/generates/E2eGenerator.d.ts +2 -1
  29. package/lib/generates/E2eGenerator.js +2 -2
  30. package/lib/generates/E2eGenerator.js.map +1 -1
  31. package/lib/generates/SdkGenerator.js +3 -11
  32. package/lib/generates/SdkGenerator.js.map +1 -1
  33. package/lib/generates/SwaggerGenerator.d.ts +2 -0
  34. package/lib/generates/SwaggerGenerator.js +119 -62
  35. package/lib/generates/SwaggerGenerator.js.map +1 -1
  36. package/lib/generates/internal/E2eFileProgrammer.d.ts +2 -1
  37. package/lib/generates/internal/E2eFileProgrammer.js +49 -53
  38. package/lib/generates/internal/E2eFileProgrammer.js.map +1 -1
  39. package/lib/generates/internal/FilePrinter.d.ts +10 -0
  40. package/lib/generates/internal/FilePrinter.js +46 -0
  41. package/lib/generates/internal/FilePrinter.js.map +1 -0
  42. package/lib/{utils → generates/internal}/ImportDictionary.d.ts +2 -1
  43. package/lib/{utils → generates/internal}/ImportDictionary.js +20 -14
  44. package/lib/generates/internal/ImportDictionary.js.map +1 -0
  45. package/lib/generates/internal/SdkAliasCollection.d.ts +12 -0
  46. package/lib/generates/internal/SdkAliasCollection.js +97 -0
  47. package/lib/generates/internal/SdkAliasCollection.js.map +1 -0
  48. package/lib/generates/internal/SdkCloneProgrammer.d.ts +12 -0
  49. package/lib/generates/internal/SdkCloneProgrammer.js +99 -0
  50. package/lib/generates/internal/SdkCloneProgrammer.js.map +1 -0
  51. package/lib/generates/internal/SdkFileProgrammer.d.ts +2 -1
  52. package/lib/generates/internal/SdkFileProgrammer.js +27 -28
  53. package/lib/generates/internal/SdkFileProgrammer.js.map +1 -1
  54. package/lib/generates/internal/SdkFunctionProgrammer.d.ts +7 -2
  55. package/lib/generates/internal/SdkFunctionProgrammer.js +115 -322
  56. package/lib/generates/internal/SdkFunctionProgrammer.js.map +1 -1
  57. package/lib/generates/internal/SdkImportWizard.d.ts +1 -1
  58. package/lib/generates/internal/SdkNamespaceProgrammer.d.ts +11 -0
  59. package/lib/generates/internal/SdkNamespaceProgrammer.js +180 -0
  60. package/lib/generates/internal/SdkNamespaceProgrammer.js.map +1 -0
  61. package/lib/generates/internal/SdkRouteProgrammer.d.ts +7 -0
  62. package/lib/generates/internal/SdkRouteProgrammer.js +55 -0
  63. package/lib/generates/internal/SdkRouteProgrammer.js.map +1 -0
  64. package/lib/generates/internal/SdkSimulationProgrammer.d.ts +8 -2
  65. package/lib/generates/internal/SdkSimulationProgrammer.js +103 -89
  66. package/lib/generates/internal/SdkSimulationProgrammer.js.map +1 -1
  67. package/lib/generates/internal/SdkTypeProgrammer.d.ts +9 -0
  68. package/lib/generates/internal/SdkTypeProgrammer.js +228 -0
  69. package/lib/generates/internal/SdkTypeProgrammer.js.map +1 -0
  70. package/lib/generates/internal/SwaggerSchemaGenerator.d.ts +4 -4
  71. package/lib/generates/internal/SwaggerSchemaGenerator.js +30 -28
  72. package/lib/generates/internal/SwaggerSchemaGenerator.js.map +1 -1
  73. package/lib/structures/IController.d.ts +4 -2
  74. package/lib/structures/IRoute.d.ts +5 -4
  75. package/lib/structures/ISwaggerLazyProperty.d.ts +2 -2
  76. package/lib/structures/ISwaggerLazySchema.d.ts +2 -2
  77. package/lib/structures/ParamCategory.d.ts +1 -1
  78. package/lib/structures/TypeEntry.js +2 -2
  79. package/lib/structures/TypeEntry.js.map +1 -1
  80. package/lib/utils/StringUtil.d.ts +3 -0
  81. package/lib/utils/StringUtil.js +8 -0
  82. package/lib/utils/StringUtil.js.map +1 -0
  83. package/package.json +12 -16
  84. package/src/INestiaConfig.ts +30 -6
  85. package/src/NestiaSdkApplication.ts +255 -253
  86. package/src/analyses/AccessorAnalyzer.ts +60 -60
  87. package/src/analyses/ConfigAnalyzer.ts +147 -147
  88. package/src/analyses/ControllerAnalyzer.ts +42 -19
  89. package/src/analyses/ExceptionAnalyzer.ts +148 -115
  90. package/src/analyses/GenericAnalyzer.ts +51 -51
  91. package/src/analyses/ImportAnalyzer.ts +1 -2
  92. package/src/analyses/PathAnalyzer.ts +110 -98
  93. package/src/analyses/ReflectAnalyzer.ts +39 -35
  94. package/src/analyses/SecurityAnalyzer.ts +24 -20
  95. package/src/executable/internal/CommandParser.ts +15 -15
  96. package/src/executable/internal/NestiaConfigLoader.ts +67 -67
  97. package/src/executable/internal/NestiaSdkCommand.ts +60 -60
  98. package/src/executable/sdk.ts +73 -73
  99. package/src/generates/CloneGenerator.ts +62 -0
  100. package/src/generates/E2eGenerator.ts +66 -64
  101. package/src/generates/SdkGenerator.ts +84 -96
  102. package/src/generates/SwaggerGenerator.ts +145 -53
  103. package/src/generates/internal/E2eFileProgrammer.ts +182 -123
  104. package/src/generates/internal/FilePrinter.ts +53 -0
  105. package/src/{utils → generates/internal}/ImportDictionary.ts +35 -13
  106. package/src/generates/internal/SdkAliasCollection.ts +152 -0
  107. package/src/generates/internal/SdkCloneProgrammer.ts +155 -0
  108. package/src/generates/internal/SdkDistributionComposer.ts +91 -91
  109. package/src/generates/internal/SdkFileProgrammer.ts +115 -106
  110. package/src/generates/internal/SdkFunctionProgrammer.ts +298 -518
  111. package/src/generates/internal/SdkImportWizard.ts +55 -55
  112. package/src/generates/internal/SdkNamespaceProgrammer.ts +510 -0
  113. package/src/generates/internal/SdkRouteDirectory.ts +17 -17
  114. package/src/generates/internal/SdkRouteProgrammer.ts +83 -0
  115. package/src/generates/internal/SdkSimulationProgrammer.ts +365 -133
  116. package/src/generates/internal/SdkTypeProgrammer.ts +386 -0
  117. package/src/generates/internal/SwaggerSchemaGenerator.ts +437 -427
  118. package/src/generates/internal/SwaggerSchemaValidator.ts +198 -198
  119. package/src/index.ts +4 -4
  120. package/src/module.ts +2 -2
  121. package/src/structures/IController.ts +94 -95
  122. package/src/structures/IErrorReport.ts +6 -6
  123. package/src/structures/INestiaProject.ts +13 -13
  124. package/src/structures/INormalizedInput.ts +20 -20
  125. package/src/structures/IRoute.ts +53 -53
  126. package/src/structures/ISwaggerLazyProperty.ts +2 -2
  127. package/src/structures/ISwaggerLazySchema.ts +2 -2
  128. package/src/structures/ITypeTuple.ts +6 -6
  129. package/src/structures/MethodType.ts +5 -5
  130. package/src/structures/ParamCategory.ts +1 -1
  131. package/src/structures/TypeEntry.ts +1 -1
  132. package/src/utils/ArrayUtil.ts +26 -26
  133. package/src/utils/FileRetriever.ts +22 -22
  134. package/src/utils/MapUtil.ts +14 -14
  135. package/src/utils/PathUtil.ts +10 -10
  136. package/src/utils/SourceFinder.ts +66 -66
  137. package/src/utils/StringUtil.ts +6 -0
  138. package/src/utils/StripEnums.ts +5 -5
  139. package/assets/bundle/api/utils/NestiaSimulator.ts +0 -70
  140. package/lib/generates/internal/SdkDtoGenerator.d.ts +0 -9
  141. package/lib/generates/internal/SdkDtoGenerator.js +0 -294
  142. package/lib/generates/internal/SdkDtoGenerator.js.map +0 -1
  143. package/lib/generates/internal/SdkTypeDefiner.d.ts +0 -11
  144. package/lib/generates/internal/SdkTypeDefiner.js +0 -82
  145. package/lib/generates/internal/SdkTypeDefiner.js.map +0 -1
  146. package/lib/structures/ISwagger.d.ts +0 -72
  147. package/lib/structures/ISwagger.js +0 -3
  148. package/lib/structures/ISwagger.js.map +0 -1
  149. package/lib/structures/ISwaggerComponents.d.ts +0 -26
  150. package/lib/structures/ISwaggerComponents.js +0 -3
  151. package/lib/structures/ISwaggerComponents.js.map +0 -1
  152. package/lib/structures/ISwaggerInfo.d.ts +0 -71
  153. package/lib/structures/ISwaggerInfo.js +0 -3
  154. package/lib/structures/ISwaggerInfo.js.map +0 -1
  155. package/lib/structures/ISwaggerRoute.d.ts +0 -47
  156. package/lib/structures/ISwaggerRoute.js +0 -3
  157. package/lib/structures/ISwaggerRoute.js.map +0 -1
  158. package/lib/structures/ISwaggerSecurityScheme.d.ts +0 -56
  159. package/lib/structures/ISwaggerSecurityScheme.js +0 -3
  160. package/lib/structures/ISwaggerSecurityScheme.js.map +0 -1
  161. package/lib/utils/ImportDictionary.js.map +0 -1
  162. package/src/generates/internal/SdkDtoGenerator.ts +0 -424
  163. package/src/generates/internal/SdkTypeDefiner.ts +0 -119
  164. package/src/structures/ISwagger.ts +0 -91
  165. package/src/structures/ISwaggerComponents.ts +0 -29
  166. package/src/structures/ISwaggerInfo.ts +0 -80
  167. package/src/structures/ISwaggerRoute.ts +0 -51
  168. package/src/structures/ISwaggerSecurityScheme.ts +0 -65
@@ -1,55 +1,55 @@
1
- import { ImportDictionary } from "../../utils/ImportDictionary";
2
-
3
- export namespace SdkImportWizard {
4
- export const Fetcher = (encrypted: boolean) =>
5
- encrypted ? EncryptedFetcher : PlainFetcher;
6
-
7
- export const HttpError = (importer: ImportDictionary) =>
8
- importer.external({
9
- type: true,
10
- library: "@nestia/fetcher",
11
- instance: "HttpError",
12
- });
13
-
14
- export const IConnection = (importer: ImportDictionary) =>
15
- importer.external({
16
- type: true,
17
- library: "@nestia/fetcher",
18
- instance: "IConnection",
19
- });
20
-
21
- export const Primitive = (importer: ImportDictionary) =>
22
- importer.external({
23
- type: true,
24
- library: "@nestia/fetcher",
25
- instance: "Primitive",
26
- });
27
-
28
- export const Resolved = (importer: ImportDictionary) =>
29
- importer.external({
30
- type: true,
31
- library: "@nestia/fetcher",
32
- instance: "Resolved",
33
- });
34
-
35
- export const typia = (importer: ImportDictionary) =>
36
- importer.external({
37
- type: false,
38
- library: "typia",
39
- instance: null,
40
- });
41
- }
42
-
43
- const PlainFetcher = (importer: ImportDictionary) =>
44
- importer.external({
45
- type: false,
46
- library: "@nestia/fetcher/lib/PlainFetcher",
47
- instance: "PlainFetcher",
48
- });
49
-
50
- const EncryptedFetcher = (importer: ImportDictionary) =>
51
- importer.external({
52
- type: false,
53
- library: "@nestia/fetcher/lib/EncryptedFetcher",
54
- instance: "EncryptedFetcher",
55
- });
1
+ import { ImportDictionary } from "./ImportDictionary";
2
+
3
+ export namespace SdkImportWizard {
4
+ export const Fetcher = (encrypted: boolean) =>
5
+ encrypted ? EncryptedFetcher : PlainFetcher;
6
+
7
+ export const HttpError = (importer: ImportDictionary) =>
8
+ importer.external({
9
+ type: true,
10
+ library: "@nestia/fetcher",
11
+ instance: "HttpError",
12
+ });
13
+
14
+ export const IConnection = (importer: ImportDictionary) =>
15
+ importer.external({
16
+ type: true,
17
+ library: "@nestia/fetcher",
18
+ instance: "IConnection",
19
+ });
20
+
21
+ export const Primitive = (importer: ImportDictionary) =>
22
+ importer.external({
23
+ type: true,
24
+ library: "@nestia/fetcher",
25
+ instance: "Primitive",
26
+ });
27
+
28
+ export const Resolved = (importer: ImportDictionary) =>
29
+ importer.external({
30
+ type: true,
31
+ library: "@nestia/fetcher",
32
+ instance: "Resolved",
33
+ });
34
+
35
+ export const typia = (importer: ImportDictionary) =>
36
+ importer.external({
37
+ type: false,
38
+ library: "typia",
39
+ instance: null,
40
+ });
41
+ }
42
+
43
+ const PlainFetcher = (importer: ImportDictionary) =>
44
+ importer.external({
45
+ type: false,
46
+ library: "@nestia/fetcher/lib/PlainFetcher",
47
+ instance: "PlainFetcher",
48
+ });
49
+
50
+ const EncryptedFetcher = (importer: ImportDictionary) =>
51
+ importer.external({
52
+ type: false,
53
+ library: "@nestia/fetcher/lib/EncryptedFetcher",
54
+ instance: "EncryptedFetcher",
55
+ });
@@ -0,0 +1,510 @@
1
+ import ts from "typescript";
2
+ import typia from "typia";
3
+ import { ExpressionFactory } from "typia/lib/factories/ExpressionFactory";
4
+ import { IdentifierFactory } from "typia/lib/factories/IdentifierFactory";
5
+ import { LiteralFactory } from "typia/lib/factories/LiteralFactory";
6
+ import { TypeFactory } from "typia/lib/factories/TypeFactory";
7
+ import { Escaper } from "typia/lib/utils/Escaper";
8
+
9
+ import { INestiaConfig } from "../../INestiaConfig";
10
+ import { IController } from "../../structures/IController";
11
+ import { IRoute } from "../../structures/IRoute";
12
+ import { FilePrinter } from "./FilePrinter";
13
+ import { ImportDictionary } from "./ImportDictionary";
14
+ import { SdkAliasCollection } from "./SdkAliasCollection";
15
+ import { SdkImportWizard } from "./SdkImportWizard";
16
+ import { SdkSimulationProgrammer } from "./SdkSimulationProgrammer";
17
+ import { SdkTypeProgrammer } from "./SdkTypeProgrammer";
18
+
19
+ export namespace SdkNamespaceProgrammer {
20
+ export const write =
21
+ (checker: ts.TypeChecker) =>
22
+ (config: INestiaConfig) =>
23
+ (importer: ImportDictionary) =>
24
+ (
25
+ route: IRoute,
26
+ props: {
27
+ headers: IRoute.IParameter | undefined;
28
+ query: IRoute.IParameter | undefined;
29
+ input: IRoute.IParameter | undefined;
30
+ },
31
+ ): ts.ModuleDeclaration => {
32
+ const types = write_types(checker)(config)(importer)(route, props);
33
+ return ts.factory.createModuleDeclaration(
34
+ [ts.factory.createToken(ts.SyntaxKind.ExportKeyword)],
35
+ ts.factory.createIdentifier(route.name),
36
+ ts.factory.createModuleBlock([
37
+ ...types,
38
+ ...(types.length ? [FilePrinter.enter()] : []),
39
+ write_metadata(importer)(route, props),
40
+ FilePrinter.enter(),
41
+ write_path(config)(importer)(route, props),
42
+ ...(config.simulate
43
+ ? [
44
+ SdkSimulationProgrammer.random(checker)(config)(importer)(
45
+ route,
46
+ ),
47
+ SdkSimulationProgrammer.simulate(config)(importer)(
48
+ route,
49
+ props,
50
+ ),
51
+ ]
52
+ : []),
53
+ ...(config.json &&
54
+ typia.is<IController.IBodyParameter>(props.input) &&
55
+ (props.input.contentType === "application/json" ||
56
+ props.input.encrypted === true)
57
+ ? [write_stringify(config)(importer)]
58
+ : []),
59
+ ]),
60
+ ts.NodeFlags.Namespace,
61
+ );
62
+ };
63
+
64
+ const write_types =
65
+ (checker: ts.TypeChecker) =>
66
+ (config: INestiaConfig) =>
67
+ (importer: ImportDictionary) =>
68
+ (
69
+ route: IRoute,
70
+ props: {
71
+ headers: IRoute.IParameter | undefined;
72
+ query: IRoute.IParameter | undefined;
73
+ input: IRoute.IParameter | undefined;
74
+ },
75
+ ): ts.TypeAliasDeclaration[] => {
76
+ const array: ts.TypeAliasDeclaration[] = [];
77
+ const declare = (name: string, type: ts.TypeNode) =>
78
+ array.push(
79
+ ts.factory.createTypeAliasDeclaration(
80
+ [ts.factory.createModifier(ts.SyntaxKind.ExportKeyword)],
81
+ name,
82
+ undefined,
83
+ type,
84
+ ),
85
+ );
86
+ if (props.headers !== undefined)
87
+ declare(
88
+ "Headers",
89
+ SdkAliasCollection.headers(config)(importer)(props.headers),
90
+ );
91
+ if (props.query !== undefined)
92
+ declare(
93
+ "Query",
94
+ SdkAliasCollection.query(config)(importer)(props.query),
95
+ );
96
+ if (props.input !== undefined)
97
+ declare(
98
+ "Input",
99
+ SdkAliasCollection.input(config)(importer)(props.input),
100
+ );
101
+ if (config.propagate === true || route.output.typeName !== "void")
102
+ declare(
103
+ "Output",
104
+ SdkAliasCollection.output(checker)(config)(importer)(route),
105
+ );
106
+ return array;
107
+ };
108
+
109
+ const write_metadata =
110
+ (importer: ImportDictionary) =>
111
+ (
112
+ route: IRoute,
113
+ props: {
114
+ headers: IRoute.IParameter | undefined;
115
+ query: IRoute.IParameter | undefined;
116
+ input: IRoute.IParameter | undefined;
117
+ },
118
+ ): ts.VariableStatement =>
119
+ constant("METADATA")(
120
+ ts.factory.createAsExpression(
121
+ ts.factory.createObjectLiteralExpression(
122
+ [
123
+ ts.factory.createPropertyAssignment(
124
+ "method",
125
+ ts.factory.createStringLiteral(route.method),
126
+ ),
127
+ ts.factory.createPropertyAssignment(
128
+ "path",
129
+ ts.factory.createStringLiteral(route.path),
130
+ ),
131
+ ts.factory.createPropertyAssignment(
132
+ "request",
133
+ props.input
134
+ ? LiteralFactory.generate(
135
+ typia.is<IController.IBodyParameter>(props.input)
136
+ ? {
137
+ type: props.input.contentType,
138
+ encrypted: !!props.input.encrypted,
139
+ }
140
+ : {
141
+ type: "application/json",
142
+ encrypted: false,
143
+ },
144
+ )
145
+ : ts.factory.createNull(),
146
+ ),
147
+ ts.factory.createPropertyAssignment(
148
+ "response",
149
+ route.method !== "HEAD"
150
+ ? LiteralFactory.generate({
151
+ type: route.output.contentType,
152
+ encrypted: !!route.encrypted,
153
+ })
154
+ : ts.factory.createNull(),
155
+ ),
156
+ ts.factory.createPropertyAssignment(
157
+ "status",
158
+ route.status !== undefined
159
+ ? ExpressionFactory.number(route.status)
160
+ : ts.factory.createNull(),
161
+ ),
162
+ ...(route.output.contentType ===
163
+ "application/x-www-form-urlencoded"
164
+ ? [
165
+ ts.factory.createPropertyAssignment(
166
+ "parseQuery",
167
+ ts.factory.createCallExpression(
168
+ ts.factory.createIdentifier(
169
+ `${SdkImportWizard.typia(importer)}.http.createAssertQuery`,
170
+ ),
171
+ [
172
+ ts.factory.createTypeReferenceNode(
173
+ route.output.typeName,
174
+ ),
175
+ ],
176
+ undefined,
177
+ ),
178
+ ),
179
+ ]
180
+ : []),
181
+ ],
182
+ true,
183
+ ),
184
+ ts.factory.createTypeReferenceNode(
185
+ ts.factory.createIdentifier("const"),
186
+ ),
187
+ ),
188
+ );
189
+
190
+ const write_path =
191
+ (config: INestiaConfig) =>
192
+ (importer: ImportDictionary) =>
193
+ (
194
+ route: IRoute,
195
+ props: {
196
+ query: IRoute.IParameter | undefined;
197
+ },
198
+ ): ts.VariableStatement => {
199
+ const g = {
200
+ total: [
201
+ ...route.parameters.filter(
202
+ (param) => param.category === "param" || param.category === "query",
203
+ ),
204
+ ],
205
+ query: route.parameters.filter(
206
+ (param) => param.category === "query" && param.field !== undefined,
207
+ ),
208
+ path: route.parameters.filter((param) => param.category === "param"),
209
+ };
210
+ const out = (body: ts.ConciseBody) =>
211
+ constant("path")(
212
+ ts.factory.createArrowFunction(
213
+ [],
214
+ [],
215
+ g.total.map((p) =>
216
+ IdentifierFactory.parameter(
217
+ p.name,
218
+ p === props.query
219
+ ? ts.factory.createTypeReferenceNode(`${route.name}.Query`)
220
+ : getType(config)(importer)(p),
221
+ ),
222
+ ),
223
+ undefined,
224
+ undefined,
225
+ body,
226
+ ),
227
+ );
228
+ if (g.total.length === 0)
229
+ return out(ts.factory.createStringLiteral(route.path));
230
+
231
+ const template = () => {
232
+ const splitted: string[] = route.path.split(":");
233
+ if (splitted.length === 1)
234
+ return ts.factory.createStringLiteral(route.path);
235
+ return ts.factory.createTemplateExpression(
236
+ ts.factory.createTemplateHead(splitted[0]),
237
+ splitted.slice(1).map((s, i, arr) => {
238
+ const name: string = s.split("/")[0];
239
+ return ts.factory.createTemplateSpan(
240
+ ts.factory.createCallExpression(
241
+ ts.factory.createIdentifier("encodeURIComponent"),
242
+ undefined,
243
+ [
244
+ ts.factory.createBinaryExpression(
245
+ ts.factory.createIdentifier(
246
+ g.path.find((p) => p.field === name)!.name,
247
+ ),
248
+ ts.factory.createToken(ts.SyntaxKind.QuestionQuestionToken),
249
+ ts.factory.createStringLiteral("null"),
250
+ ),
251
+ ],
252
+ ),
253
+ (i !== arr.length - 1
254
+ ? ts.factory.createTemplateMiddle
255
+ : ts.factory.createTemplateTail)(s.substring(name.length)),
256
+ );
257
+ }),
258
+ );
259
+ };
260
+ if (props.query === undefined && g.query.length === 0)
261
+ return out(template());
262
+
263
+ const block = (expr: ts.Expression) => {
264
+ const computeName = (str: string): string =>
265
+ g.total
266
+ .filter((p) => p.category !== "headers")
267
+ .find((p) => p.name === str) !== undefined
268
+ ? computeName("_" + str)
269
+ : str;
270
+ const variables: string = computeName("variables");
271
+ return ts.factory.createBlock(
272
+ [
273
+ local(variables)("URLSearchParams")(
274
+ ts.factory.createNewExpression(
275
+ ts.factory.createIdentifier("URLSearchParams"),
276
+ [],
277
+ [],
278
+ ),
279
+ ),
280
+ ts.factory.createForOfStatement(
281
+ undefined,
282
+ ts.factory.createVariableDeclarationList(
283
+ [
284
+ ts.factory.createVariableDeclaration(
285
+ ts.factory.createArrayBindingPattern([
286
+ ts.factory.createBindingElement(
287
+ undefined,
288
+ undefined,
289
+ ts.factory.createIdentifier("key"),
290
+ undefined,
291
+ ),
292
+ ts.factory.createBindingElement(
293
+ undefined,
294
+ undefined,
295
+ ts.factory.createIdentifier("value"),
296
+ undefined,
297
+ ),
298
+ ]),
299
+ undefined,
300
+ undefined,
301
+ undefined,
302
+ ),
303
+ ],
304
+ ts.NodeFlags.Const,
305
+ ),
306
+ ts.factory.createCallExpression(
307
+ ts.factory.createIdentifier("Object.entries"),
308
+ undefined,
309
+ [
310
+ ts.factory.createAsExpression(
311
+ expr,
312
+ TypeFactory.keyword("any"),
313
+ ),
314
+ ],
315
+ ),
316
+ ts.factory.createIfStatement(
317
+ ts.factory.createStrictEquality(
318
+ ts.factory.createIdentifier("undefined"),
319
+ ts.factory.createIdentifier("value"),
320
+ ),
321
+ ts.factory.createContinueStatement(),
322
+ ts.factory.createIfStatement(
323
+ ts.factory.createCallExpression(
324
+ ts.factory.createIdentifier("Array.isArray"),
325
+ undefined,
326
+ [ts.factory.createIdentifier("value")],
327
+ ),
328
+ ts.factory.createExpressionStatement(
329
+ ts.factory.createCallExpression(
330
+ ts.factory.createPropertyAccessExpression(
331
+ ts.factory.createIdentifier("value"),
332
+ ts.factory.createIdentifier("forEach"),
333
+ ),
334
+ undefined,
335
+ [
336
+ ts.factory.createArrowFunction(
337
+ undefined,
338
+ undefined,
339
+ [IdentifierFactory.parameter("elem")],
340
+ undefined,
341
+ undefined,
342
+ ts.factory.createCallExpression(
343
+ IdentifierFactory.access(
344
+ ts.factory.createIdentifier(variables),
345
+ )("append"),
346
+ undefined,
347
+ [
348
+ ts.factory.createIdentifier("key"),
349
+ ts.factory.createCallExpression(
350
+ ts.factory.createIdentifier("String"),
351
+ undefined,
352
+ [ts.factory.createIdentifier("elem")],
353
+ ),
354
+ ],
355
+ ),
356
+ ),
357
+ ],
358
+ ),
359
+ ),
360
+ ts.factory.createExpressionStatement(
361
+ ts.factory.createCallExpression(
362
+ IdentifierFactory.access(
363
+ ts.factory.createIdentifier(variables),
364
+ )("set"),
365
+ undefined,
366
+ [
367
+ ts.factory.createIdentifier("key"),
368
+ ts.factory.createCallExpression(
369
+ ts.factory.createIdentifier("String"),
370
+ undefined,
371
+ [ts.factory.createIdentifier("value")],
372
+ ),
373
+ ],
374
+ ),
375
+ ),
376
+ ),
377
+ ),
378
+ ),
379
+ local("location")("string")(template()),
380
+ ts.factory.createReturnStatement(
381
+ ts.factory.createConditionalExpression(
382
+ ts.factory.createStrictEquality(
383
+ ExpressionFactory.number(0),
384
+ IdentifierFactory.access(
385
+ ts.factory.createIdentifier(variables),
386
+ )("size"),
387
+ ),
388
+ undefined,
389
+ ts.factory.createIdentifier("location"),
390
+ undefined,
391
+ ts.factory.createTemplateExpression(
392
+ ts.factory.createTemplateHead(""),
393
+ [
394
+ ts.factory.createTemplateSpan(
395
+ ts.factory.createIdentifier("location"),
396
+ ts.factory.createTemplateMiddle("?"),
397
+ ),
398
+ ts.factory.createTemplateSpan(
399
+ ts.factory.createCallExpression(
400
+ IdentifierFactory.access(
401
+ ts.factory.createIdentifier(variables),
402
+ )("toString"),
403
+ undefined,
404
+ undefined,
405
+ ),
406
+ ts.factory.createTemplateTail(""),
407
+ ),
408
+ ],
409
+ ),
410
+ ),
411
+ ),
412
+ ],
413
+ true,
414
+ );
415
+ };
416
+ if (props.query !== undefined && g.query.length === 0)
417
+ return out(block(ts.factory.createIdentifier(props.query.name)));
418
+ return out(
419
+ block(
420
+ ts.factory.createObjectLiteralExpression(
421
+ [
422
+ ...(props.query
423
+ ? [
424
+ ts.factory.createSpreadAssignment(
425
+ ts.factory.createIdentifier(props.query.name),
426
+ ),
427
+ ]
428
+ : []),
429
+ ...g.query.map((q) =>
430
+ q.name === q.field
431
+ ? ts.factory.createShorthandPropertyAssignment(q.name)
432
+ : ts.factory.createPropertyAssignment(
433
+ Escaper.variable(q.field!)
434
+ ? q.field!
435
+ : ts.factory.createStringLiteral(q.field!),
436
+ ts.factory.createIdentifier(q.name),
437
+ ),
438
+ ),
439
+ ],
440
+ true,
441
+ ),
442
+ ),
443
+ );
444
+ };
445
+
446
+ const write_stringify =
447
+ (config: INestiaConfig) =>
448
+ (importer: ImportDictionary): ts.VariableStatement =>
449
+ constant("stringify")(
450
+ ts.factory.createArrowFunction(
451
+ [],
452
+ undefined,
453
+ [
454
+ IdentifierFactory.parameter(
455
+ "input",
456
+ ts.factory.createTypeReferenceNode("Input"),
457
+ ),
458
+ ],
459
+ undefined,
460
+ undefined,
461
+ ts.factory.createCallExpression(
462
+ IdentifierFactory.access(
463
+ IdentifierFactory.access(
464
+ ts.factory.createIdentifier(SdkImportWizard.typia(importer)),
465
+ )("json"),
466
+ )(config.assert ? "stringify" : "assertStringify"),
467
+ undefined,
468
+ [ts.factory.createIdentifier("input")],
469
+ ),
470
+ ),
471
+ );
472
+ }
473
+
474
+ const local = (name: string) => (type: string) => (expression: ts.Expression) =>
475
+ ts.factory.createVariableStatement(
476
+ [],
477
+ ts.factory.createVariableDeclarationList(
478
+ [
479
+ ts.factory.createVariableDeclaration(
480
+ name,
481
+ undefined,
482
+ ts.factory.createTypeReferenceNode(type),
483
+ expression,
484
+ ),
485
+ ],
486
+ ts.NodeFlags.Const,
487
+ ),
488
+ );
489
+ const constant = (name: string) => (expression: ts.Expression) =>
490
+ ts.factory.createVariableStatement(
491
+ [ts.factory.createModifier(ts.SyntaxKind.ExportKeyword)],
492
+ ts.factory.createVariableDeclarationList(
493
+ [
494
+ ts.factory.createVariableDeclaration(
495
+ name,
496
+ undefined,
497
+ undefined,
498
+ expression,
499
+ ),
500
+ ],
501
+ ts.NodeFlags.Const,
502
+ ),
503
+ );
504
+ const getType =
505
+ (config: INestiaConfig) =>
506
+ (importer: ImportDictionary) =>
507
+ (p: IRoute.IParameter | IRoute.IOutput) =>
508
+ p.metadata
509
+ ? SdkTypeProgrammer.write(config)(importer)(p.metadata)
510
+ : ts.factory.createTypeReferenceNode(p.typeName);
@@ -1,17 +1,17 @@
1
- import { IRoute } from "../../structures/IRoute";
2
-
3
- export class SdkRouteDirectory {
4
- public readonly module: string;
5
- public readonly children: Map<string, SdkRouteDirectory>;
6
- public readonly routes: IRoute[];
7
-
8
- public constructor(
9
- readonly parent: SdkRouteDirectory | null,
10
- readonly name: string,
11
- ) {
12
- this.children = new Map();
13
- this.routes = [];
14
- this.module =
15
- this.parent !== null ? `${this.parent.module}.${name}` : `api.${name}`;
16
- }
17
- }
1
+ import { IRoute } from "../../structures/IRoute";
2
+
3
+ export class SdkRouteDirectory {
4
+ public readonly module: string;
5
+ public readonly children: Map<string, SdkRouteDirectory>;
6
+ public readonly routes: IRoute[];
7
+
8
+ public constructor(
9
+ readonly parent: SdkRouteDirectory | null,
10
+ readonly name: string,
11
+ ) {
12
+ this.children = new Map();
13
+ this.routes = [];
14
+ this.module =
15
+ this.parent !== null ? `${this.parent.module}.${name}` : `api.${name}`;
16
+ }
17
+ }