@nestia/sdk 3.11.0-dev.20240813-11 → 3.11.0-dev.20240814-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.
Files changed (80) hide show
  1. package/lib/NestiaSdkApplication.js +0 -13
  2. package/lib/NestiaSdkApplication.js.map +1 -1
  3. package/lib/analyses/ReflectControllerAnalyzer.js +2 -0
  4. package/lib/analyses/ReflectControllerAnalyzer.js.map +1 -1
  5. package/lib/analyses/ReflectHttpOperationAnalyzer.js +1 -0
  6. package/lib/analyses/ReflectHttpOperationAnalyzer.js.map +1 -1
  7. package/lib/analyses/ReflectHttpOperationParameterAnalyzer.js +14 -7
  8. package/lib/analyses/ReflectHttpOperationParameterAnalyzer.js.map +1 -1
  9. package/lib/analyses/ReflectHttpOperationResponseAnalyzer.js +2 -1
  10. package/lib/analyses/ReflectHttpOperationResponseAnalyzer.js.map +1 -1
  11. package/lib/analyses/TypedHttpRouteAnalyzer.js +3 -1
  12. package/lib/analyses/TypedHttpRouteAnalyzer.js.map +1 -1
  13. package/lib/generates/SwaggerGenerator.js +60 -8
  14. package/lib/generates/SwaggerGenerator.js.map +1 -1
  15. package/lib/generates/internal/E2eFileProgrammer.js +11 -10
  16. package/lib/generates/internal/E2eFileProgrammer.js.map +1 -1
  17. package/lib/generates/internal/SdkAliasCollection.d.ts +5 -1
  18. package/lib/generates/internal/SdkAliasCollection.js +31 -19
  19. package/lib/generates/internal/SdkAliasCollection.js.map +1 -1
  20. package/lib/generates/internal/SdkFileProgrammer.js +8 -7
  21. package/lib/generates/internal/SdkFileProgrammer.js.map +1 -1
  22. package/lib/generates/internal/SdkHttpCloneProgrammer.js +4 -0
  23. package/lib/generates/internal/SdkHttpCloneProgrammer.js.map +1 -1
  24. package/lib/generates/internal/SdkHttpCloneReferencer.js +6 -0
  25. package/lib/generates/internal/SdkHttpCloneReferencer.js.map +1 -1
  26. package/lib/generates/internal/SdkHttpFunctionProgrammer.js +20 -13
  27. package/lib/generates/internal/SdkHttpFunctionProgrammer.js.map +1 -1
  28. package/lib/generates/internal/SdkHttpNamespaceProgrammer.js +16 -8
  29. package/lib/generates/internal/SdkHttpNamespaceProgrammer.js.map +1 -1
  30. package/lib/generates/internal/SdkHttpRouteProgrammer.js +2 -2
  31. package/lib/generates/internal/SdkHttpRouteProgrammer.js.map +1 -1
  32. package/lib/generates/internal/SdkHttpSimulationProgrammer.js +6 -3
  33. package/lib/generates/internal/SdkHttpSimulationProgrammer.js.map +1 -1
  34. package/lib/generates/internal/SdkWebSocketNamespaceProgrammer.js +11 -5
  35. package/lib/generates/internal/SdkWebSocketNamespaceProgrammer.js.map +1 -1
  36. package/lib/generates/internal/SdkWebSocketRouteProgrammer.js +1 -1
  37. package/lib/generates/internal/SdkWebSocketRouteProgrammer.js.map +1 -1
  38. package/lib/generates/internal/SwaggerOperationComposer.js +19 -1
  39. package/lib/generates/internal/SwaggerOperationComposer.js.map +1 -1
  40. package/lib/generates/internal/SwaggerOperationParameterComposer.js +3 -3
  41. package/lib/generates/internal/SwaggerOperationParameterComposer.js.map +1 -1
  42. package/lib/transform.js +1 -1
  43. package/lib/transform.js.map +1 -1
  44. package/lib/transformers/SdkOperationProgrammer.js +17 -11
  45. package/lib/transformers/SdkOperationProgrammer.js.map +1 -1
  46. package/lib/transformers/SdkOperationTransformer.d.ts +1 -1
  47. package/lib/transformers/SdkOperationTransformer.js +12 -8
  48. package/lib/transformers/SdkOperationTransformer.js.map +1 -1
  49. package/lib/validators/HttpHeadersValidator.d.ts +5 -0
  50. package/lib/validators/HttpHeadersValidator.js +29 -0
  51. package/lib/validators/HttpHeadersValidator.js.map +1 -0
  52. package/lib/validators/HttpQueryValidator.d.ts +5 -0
  53. package/lib/validators/HttpQueryValidator.js +29 -0
  54. package/lib/validators/HttpQueryValidator.js.map +1 -0
  55. package/package.json +6 -6
  56. package/src/NestiaSdkApplication.ts +0 -14
  57. package/src/analyses/ReflectControllerAnalyzer.ts +2 -0
  58. package/src/analyses/ReflectHttpOperationAnalyzer.ts +1 -0
  59. package/src/analyses/ReflectHttpOperationParameterAnalyzer.ts +37 -5
  60. package/src/analyses/ReflectHttpOperationResponseAnalyzer.ts +8 -0
  61. package/src/analyses/TypedHttpRouteAnalyzer.ts +4 -1
  62. package/src/generates/SwaggerGenerator.ts +84 -10
  63. package/src/generates/internal/E2eFileProgrammer.ts +13 -10
  64. package/src/generates/internal/SdkAliasCollection.ts +42 -25
  65. package/src/generates/internal/SdkFileProgrammer.ts +8 -7
  66. package/src/generates/internal/SdkHttpCloneProgrammer.ts +4 -1
  67. package/src/generates/internal/SdkHttpCloneReferencer.ts +10 -0
  68. package/src/generates/internal/SdkHttpFunctionProgrammer.ts +25 -16
  69. package/src/generates/internal/SdkHttpNamespaceProgrammer.ts +256 -228
  70. package/src/generates/internal/SdkHttpRouteProgrammer.ts +2 -2
  71. package/src/generates/internal/SdkHttpSimulationProgrammer.ts +6 -3
  72. package/src/generates/internal/SdkWebSocketNamespaceProgrammer.ts +23 -10
  73. package/src/generates/internal/SdkWebSocketRouteProgrammer.ts +1 -1
  74. package/src/generates/internal/SwaggerOperationComposer.ts +25 -0
  75. package/src/generates/internal/SwaggerOperationParameterComposer.ts +3 -0
  76. package/src/transform.ts +1 -1
  77. package/src/transformers/SdkOperationProgrammer.ts +41 -36
  78. package/src/transformers/SdkOperationTransformer.ts +29 -8
  79. package/src/validators/HttpHeadersValidator.ts +34 -0
  80. package/src/validators/HttpQueryValidator.ts +34 -0
@@ -2,7 +2,6 @@ import ts from "typescript";
2
2
  import { IdentifierFactory } from "typia/lib/factories/IdentifierFactory";
3
3
  import { TypeFactory } from "typia/lib/factories/TypeFactory";
4
4
 
5
- import { INestiaConfig } from "../../INestiaConfig";
6
5
  import { INestiaProject } from "../../structures/INestiaProject";
7
6
  import { ITypedHttpRoute } from "../../structures/ITypedHttpRoute";
8
7
  import { ITypedHttpRouteParameter } from "../../structures/ITypedHttpRouteParameter";
@@ -56,21 +55,26 @@ export namespace SdkHttpFunctionProgrammer {
56
55
  ? ts.factory.createTypeReferenceNode(
57
56
  `${route.name}.${p === props.query ? "Query" : "Input"}`,
58
57
  )
59
- : SdkAliasCollection.name(p.type),
58
+ : project.config.clone === true
59
+ ? SdkAliasCollection.from(project)(importer)(p.metadata)
60
+ : SdkAliasCollection.name(p),
60
61
  ),
61
62
  ),
62
63
  ],
63
64
  ts.factory.createTypeReferenceNode("Promise", [
64
- SdkAliasCollection.output(project)(importer)(route),
65
+ project.config.propagate === true ||
66
+ route.success.metadata.size() !== 0
67
+ ? ts.factory.createTypeReferenceNode(`${route.name}.Output`)
68
+ : ts.factory.createTypeReferenceNode("void"),
65
69
  ]),
66
70
  ts.factory.createBlock(
67
- write_body(project.config)(importer)(route, props),
71
+ write_body(project)(importer)(route, props),
68
72
  true,
69
73
  ),
70
74
  );
71
75
 
72
76
  const write_body =
73
- (config: INestiaConfig) =>
77
+ (project: INestiaProject) =>
74
78
  (importer: ImportDictionary) =>
75
79
  (
76
80
  route: ITypedHttpRoute,
@@ -84,10 +88,12 @@ export namespace SdkHttpFunctionProgrammer {
84
88
  ts.factory.createCallExpression(
85
89
  IdentifierFactory.access(
86
90
  ts.factory.createIdentifier(
87
- SdkImportWizard.Fetcher(!!props.input?.encrypted)(importer),
91
+ SdkImportWizard.Fetcher(
92
+ !!props.input?.encrypted || route.success.encrypted,
93
+ )(importer),
88
94
  ),
89
- )(config.propagate ? "propagate" : "fetch"),
90
- config.propagate
95
+ )(project.config.propagate ? "propagate" : "fetch"),
96
+ project.config.propagate
91
97
  ? route.method.toLowerCase() === "get" ||
92
98
  route.method.toLowerCase() === "head"
93
99
  ? [TypeFactory.keyword("any")]
@@ -158,7 +164,7 @@ export namespace SdkHttpFunctionProgrammer {
158
164
  ...(props.input
159
165
  ? [ts.factory.createIdentifier(props.input.name)]
160
166
  : []),
161
- ...(config.json &&
167
+ ...(project.config.json &&
162
168
  props.input !== undefined &&
163
169
  (props.input.contentType === "application/json" ||
164
170
  props.input.encrypted === true)
@@ -167,7 +173,7 @@ export namespace SdkHttpFunctionProgrammer {
167
173
  ],
168
174
  );
169
175
  const output = (awaiter: boolean) =>
170
- config.simulate
176
+ project.config.simulate
171
177
  ? ts.factory.createConditionalExpression(
172
178
  ts.factory.createIdentifier("!!connection.simulate"),
173
179
  undefined,
@@ -188,7 +194,7 @@ export namespace SdkHttpFunctionProgrammer {
188
194
  ? ts.factory.createAwaitExpression(caller())
189
195
  : caller();
190
196
  return [
191
- ...(config.assert
197
+ ...(project.config.assert
192
198
  ? route.parameters
193
199
  .filter((p) => p.category !== "headers")
194
200
  .map((p) =>
@@ -211,12 +217,13 @@ export namespace SdkHttpFunctionProgrammer {
211
217
  : []),
212
218
  ...(route.success.setHeaders.length === 0
213
219
  ? [ts.factory.createReturnStatement(output(false))]
214
- : write_set_headers(config)(route)(output(true))),
220
+ : write_set_headers(project)(importer)(route)(output(true))),
215
221
  ];
216
222
  };
217
223
 
218
224
  const write_set_headers =
219
- (config: INestiaConfig) =>
225
+ (project: INestiaProject) =>
226
+ (importer: ImportDictionary) =>
220
227
  (route: ITypedHttpRoute) =>
221
228
  (condition: ts.Expression): ts.Statement[] => {
222
229
  const accessor = (x: string) => (y: string) =>
@@ -226,7 +233,9 @@ export namespace SdkHttpFunctionProgrammer {
226
233
  ...route.parameters.map((p) => p.name),
227
234
  ])("output");
228
235
  const headers: string = accessor("connection")("headers");
229
- const data: string = config.propagate ? accessor(output)("data") : output;
236
+ const data: string = project.config.propagate
237
+ ? accessor(output)("data")
238
+ : output;
230
239
 
231
240
  const assigners: ts.ExpressionStatement[] = [
232
241
  ts.factory.createBinaryExpression(
@@ -261,14 +270,14 @@ export namespace SdkHttpFunctionProgrammer {
261
270
  ts.factory.createVariableDeclaration(
262
271
  output,
263
272
  undefined,
264
- SdkAliasCollection.name(route.success.type),
273
+ SdkAliasCollection.output(project)(importer)(route),
265
274
  condition,
266
275
  ),
267
276
  ],
268
277
  ts.NodeFlags.Const,
269
278
  ),
270
279
  ),
271
- ...(config.propagate
280
+ ...(project.config.propagate
272
281
  ? [
273
282
  ts.factory.createIfStatement(
274
283
  ts.factory.createIdentifier(accessor(output)("success")),
@@ -33,9 +33,9 @@ export namespace SdkHttpNamespaceProgrammer {
33
33
  ts.factory.createModuleBlock([
34
34
  ...types,
35
35
  ...(types.length ? [FilePrinter.enter()] : []),
36
- write_metadata(importer)(route, props),
36
+ write_metadata(project)(importer)(route, props),
37
37
  FilePrinter.enter(),
38
- write_path(route, props.query),
38
+ write_path(project)(importer)(route, props.query),
39
39
  ...(project.config.simulate
40
40
  ? [
41
41
  SdkHttpSimulationProgrammer.random(project)(importer)(route),
@@ -101,6 +101,7 @@ export namespace SdkHttpNamespaceProgrammer {
101
101
  };
102
102
 
103
103
  const write_metadata =
104
+ (project: INestiaProject) =>
104
105
  (importer: ImportDictionary) =>
105
106
  (
106
107
  route: ITypedHttpRoute,
@@ -162,7 +163,13 @@ export namespace SdkHttpNamespaceProgrammer {
162
163
  ts.factory.createIdentifier(
163
164
  `${SdkImportWizard.typia(importer)}.http.createAssertQuery`,
164
165
  ),
165
- [SdkAliasCollection.name(route.success.type)],
166
+ [
167
+ project.config.clone === true
168
+ ? SdkAliasCollection.from(project)(importer)(
169
+ route.success.metadata,
170
+ )
171
+ : SdkAliasCollection.name(route.success),
172
+ ],
166
173
  undefined,
167
174
  ),
168
175
  ),
@@ -177,263 +184,284 @@ export namespace SdkHttpNamespaceProgrammer {
177
184
  ),
178
185
  );
179
186
 
180
- const write_path = (
181
- route: ITypedHttpRoute,
182
- query: ITypedHttpRouteParameter.IQuery | undefined,
183
- ): ts.VariableStatement => {
184
- const g = {
185
- total: [
186
- ...route.parameters.filter(
187
- (param) => param.category === "param" || param.category === "query",
188
- ),
189
- ],
190
- query: route.parameters
191
- .filter((param) => param.category === "query")
192
- .filter((param) => param.field !== null),
193
- path: route.parameters.filter((param) => param.category === "param"),
194
- };
195
- const out = (body: ts.ConciseBody) =>
196
- constant("path")(
197
- ts.factory.createArrowFunction(
198
- [],
199
- [],
200
- g.total.map((p) =>
201
- IdentifierFactory.parameter(
202
- p.name,
203
- p === query
204
- ? p.metadata.isRequired() === false
205
- ? ts.factory.createUnionTypeNode([
206
- ts.factory.createTypeReferenceNode(`${route.name}.Query`),
207
- ts.factory.createTypeReferenceNode("undefined"),
208
- ])
209
- : ts.factory.createTypeReferenceNode(`${route.name}.Query`)
210
- : SdkAliasCollection.name(p.type),
211
- ),
187
+ const write_path =
188
+ (project: INestiaProject) =>
189
+ (importer: ImportDictionary) =>
190
+ (
191
+ route: ITypedHttpRoute,
192
+ query: ITypedHttpRouteParameter.IQuery | undefined,
193
+ ): ts.VariableStatement => {
194
+ const g = {
195
+ total: [
196
+ ...route.parameters.filter(
197
+ (param) => param.category === "param" || param.category === "query",
212
198
  ),
213
- undefined,
214
- undefined,
215
- body,
216
- ),
217
- );
218
- if (g.total.length === 0)
219
- return out(ts.factory.createStringLiteral(route.path));
220
-
221
- const template = () => {
222
- const splitted: string[] = route.path.split(":");
223
- if (splitted.length === 1)
224
- return ts.factory.createStringLiteral(route.path);
225
- return ts.factory.createTemplateExpression(
226
- ts.factory.createTemplateHead(splitted[0]),
227
- splitted.slice(1).map((s, i, arr) => {
228
- const name: string = s.split("/")[0];
229
- return ts.factory.createTemplateSpan(
230
- ts.factory.createCallExpression(
231
- ts.factory.createIdentifier("encodeURIComponent"),
232
- undefined,
233
- [
234
- ts.factory.createBinaryExpression(
235
- ts.factory.createIdentifier(
236
- g.path.find((p) => p.field === name)!.name,
237
- ),
238
- ts.factory.createToken(ts.SyntaxKind.QuestionQuestionToken),
239
- ts.factory.createStringLiteral("null"),
240
- ),
241
- ],
242
- ),
243
- (i !== arr.length - 1
244
- ? ts.factory.createTemplateMiddle
245
- : ts.factory.createTemplateTail)(s.substring(name.length)),
246
- );
247
- }),
248
- );
249
- };
250
- if (query === undefined && g.query.length === 0) return out(template());
251
-
252
- const block = (expr: ts.Expression) => {
253
- const computeName = (str: string): string =>
254
- g.total.find((p) => p.name === str) !== undefined
255
- ? computeName("_" + str)
256
- : str;
257
- const variables: string = computeName("variables");
258
- return ts.factory.createBlock(
259
- [
260
- local(variables)("URLSearchParams")(
261
- ts.factory.createNewExpression(
262
- ts.factory.createIdentifier("URLSearchParams"),
263
- [],
264
- [],
199
+ ],
200
+ query: route.parameters
201
+ .filter((param) => param.category === "query")
202
+ .filter((param) => param.field !== null),
203
+ path: route.parameters.filter((param) => param.category === "param"),
204
+ };
205
+ const out = (body: ts.ConciseBody) =>
206
+ constant("path")(
207
+ ts.factory.createArrowFunction(
208
+ [],
209
+ [],
210
+ g.total.map((p) =>
211
+ IdentifierFactory.parameter(
212
+ p.name,
213
+ p === query
214
+ ? p.metadata.isRequired() === false
215
+ ? ts.factory.createUnionTypeNode([
216
+ ts.factory.createTypeReferenceNode(
217
+ `${route.name}.Query`,
218
+ ),
219
+ ts.factory.createTypeReferenceNode("undefined"),
220
+ ])
221
+ : ts.factory.createTypeReferenceNode(`${route.name}.Query`)
222
+ : project.config.clone === true
223
+ ? SdkAliasCollection.from(project)(importer)(p.metadata)
224
+ : SdkAliasCollection.name(p),
225
+ ),
265
226
  ),
266
- ),
267
- ts.factory.createForOfStatement(
268
227
  undefined,
269
- ts.factory.createVariableDeclarationList(
270
- [
271
- ts.factory.createVariableDeclaration(
272
- ts.factory.createArrayBindingPattern([
273
- ts.factory.createBindingElement(
274
- undefined,
275
- undefined,
276
- ts.factory.createIdentifier("key"),
277
- undefined,
278
- ),
279
- ts.factory.createBindingElement(
280
- undefined,
228
+ undefined,
229
+ body,
230
+ ),
231
+ );
232
+ if (g.total.length === 0)
233
+ return out(ts.factory.createStringLiteral(route.path));
234
+
235
+ const template = () => {
236
+ const splitted: string[] = route.path.split(":");
237
+ if (splitted.length === 1)
238
+ return ts.factory.createStringLiteral(route.path);
239
+ return ts.factory.createTemplateExpression(
240
+ ts.factory.createTemplateHead(splitted[0]),
241
+ splitted.slice(1).map((s, i, arr) => {
242
+ const name: string = s.split("/")[0];
243
+ return ts.factory.createTemplateSpan(
244
+ ts.factory.createCallExpression(
245
+ ts.factory.createIdentifier("encodeURIComponent"),
246
+ undefined,
247
+ [
248
+ ts.factory.createBinaryExpression(
249
+ ts.factory.createCallChain(
250
+ ts.factory.createPropertyAccessChain(
251
+ ts.factory.createIdentifier(
252
+ g.path.find((p) => p.field === name)!.name,
253
+ ),
254
+ ts.factory.createToken(ts.SyntaxKind.QuestionDotToken),
255
+ "toString",
256
+ ),
281
257
  undefined,
282
- ts.factory.createIdentifier("value"),
283
258
  undefined,
259
+ [],
284
260
  ),
285
- ]),
286
- undefined,
287
- undefined,
288
- undefined,
289
- ),
290
- ],
291
- ts.NodeFlags.Const,
261
+ ts.factory.createToken(ts.SyntaxKind.QuestionQuestionToken),
262
+ ts.factory.createStringLiteral("null"),
263
+ ),
264
+ ],
265
+ ),
266
+ (i !== arr.length - 1
267
+ ? ts.factory.createTemplateMiddle
268
+ : ts.factory.createTemplateTail)(s.substring(name.length)),
269
+ );
270
+ }),
271
+ );
272
+ };
273
+ if (query === undefined && g.query.length === 0) return out(template());
274
+
275
+ const block = (expr: ts.Expression) => {
276
+ const computeName = (str: string): string =>
277
+ g.total.find((p) => p.name === str) !== undefined
278
+ ? computeName("_" + str)
279
+ : str;
280
+ const variables: string = computeName("variables");
281
+ return ts.factory.createBlock(
282
+ [
283
+ local(variables)("URLSearchParams")(
284
+ ts.factory.createNewExpression(
285
+ ts.factory.createIdentifier("URLSearchParams"),
286
+ [],
287
+ [],
288
+ ),
292
289
  ),
293
- ts.factory.createCallExpression(
294
- ts.factory.createIdentifier("Object.entries"),
290
+ ts.factory.createForOfStatement(
295
291
  undefined,
296
- [ts.factory.createAsExpression(expr, TypeFactory.keyword("any"))],
297
- ),
298
- ts.factory.createIfStatement(
299
- ts.factory.createStrictEquality(
300
- ts.factory.createIdentifier("undefined"),
301
- ts.factory.createIdentifier("value"),
302
- ),
303
- ts.factory.createContinueStatement(),
304
- ts.factory.createIfStatement(
305
- ts.factory.createCallExpression(
306
- ts.factory.createIdentifier("Array.isArray"),
307
- undefined,
308
- [ts.factory.createIdentifier("value")],
309
- ),
310
- ts.factory.createExpressionStatement(
311
- ts.factory.createCallExpression(
312
- ts.factory.createPropertyAccessExpression(
313
- ts.factory.createIdentifier("value"),
314
- ts.factory.createIdentifier("forEach"),
315
- ),
316
- undefined,
317
- [
318
- ts.factory.createArrowFunction(
292
+ ts.factory.createVariableDeclarationList(
293
+ [
294
+ ts.factory.createVariableDeclaration(
295
+ ts.factory.createArrayBindingPattern([
296
+ ts.factory.createBindingElement(
319
297
  undefined,
320
298
  undefined,
321
- [IdentifierFactory.parameter("elem")],
299
+ ts.factory.createIdentifier("key"),
322
300
  undefined,
301
+ ),
302
+ ts.factory.createBindingElement(
303
+ undefined,
304
+ undefined,
305
+ ts.factory.createIdentifier("value"),
323
306
  undefined,
324
- ts.factory.createCallExpression(
325
- IdentifierFactory.access(
326
- ts.factory.createIdentifier(variables),
327
- )("append"),
328
- undefined,
329
- [
330
- ts.factory.createIdentifier("key"),
331
- ts.factory.createCallExpression(
332
- ts.factory.createIdentifier("String"),
333
- undefined,
334
- [ts.factory.createIdentifier("elem")],
335
- ),
336
- ],
337
- ),
338
307
  ),
339
- ],
308
+ ]),
309
+ undefined,
310
+ undefined,
311
+ undefined,
312
+ ),
313
+ ],
314
+ ts.NodeFlags.Const,
315
+ ),
316
+ ts.factory.createCallExpression(
317
+ ts.factory.createIdentifier("Object.entries"),
318
+ undefined,
319
+ [
320
+ ts.factory.createAsExpression(
321
+ expr,
322
+ TypeFactory.keyword("any"),
340
323
  ),
324
+ ],
325
+ ),
326
+ ts.factory.createIfStatement(
327
+ ts.factory.createStrictEquality(
328
+ ts.factory.createIdentifier("undefined"),
329
+ ts.factory.createIdentifier("value"),
341
330
  ),
342
- ts.factory.createExpressionStatement(
331
+ ts.factory.createContinueStatement(),
332
+ ts.factory.createIfStatement(
343
333
  ts.factory.createCallExpression(
344
- IdentifierFactory.access(
345
- ts.factory.createIdentifier(variables),
346
- )("set"),
334
+ ts.factory.createIdentifier("Array.isArray"),
347
335
  undefined,
348
- [
349
- ts.factory.createIdentifier("key"),
350
- ts.factory.createCallExpression(
351
- ts.factory.createIdentifier("String"),
352
- undefined,
353
- [ts.factory.createIdentifier("value")],
354
- ),
355
- ],
336
+ [ts.factory.createIdentifier("value")],
356
337
  ),
357
- ),
358
- ),
359
- ),
360
- ),
361
- local("location")("string")(template()),
362
- ts.factory.createReturnStatement(
363
- ts.factory.createConditionalExpression(
364
- ts.factory.createStrictEquality(
365
- ExpressionFactory.number(0),
366
- IdentifierFactory.access(
367
- ts.factory.createIdentifier(variables),
368
- )("size"),
369
- ),
370
- undefined,
371
- ts.factory.createIdentifier("location"),
372
- undefined,
373
- ts.factory.createTemplateExpression(
374
- ts.factory.createTemplateHead(""),
375
- [
376
- ts.factory.createTemplateSpan(
377
- ts.factory.createIdentifier("location"),
378
- ts.factory.createTemplateMiddle("?"),
338
+ ts.factory.createExpressionStatement(
339
+ ts.factory.createCallExpression(
340
+ ts.factory.createPropertyAccessExpression(
341
+ ts.factory.createIdentifier("value"),
342
+ ts.factory.createIdentifier("forEach"),
343
+ ),
344
+ undefined,
345
+ [
346
+ ts.factory.createArrowFunction(
347
+ undefined,
348
+ undefined,
349
+ [IdentifierFactory.parameter("elem")],
350
+ undefined,
351
+ undefined,
352
+ ts.factory.createCallExpression(
353
+ IdentifierFactory.access(
354
+ ts.factory.createIdentifier(variables),
355
+ )("append"),
356
+ undefined,
357
+ [
358
+ ts.factory.createIdentifier("key"),
359
+ ts.factory.createCallExpression(
360
+ ts.factory.createIdentifier("String"),
361
+ undefined,
362
+ [ts.factory.createIdentifier("elem")],
363
+ ),
364
+ ],
365
+ ),
366
+ ),
367
+ ],
368
+ ),
379
369
  ),
380
- ts.factory.createTemplateSpan(
370
+ ts.factory.createExpressionStatement(
381
371
  ts.factory.createCallExpression(
382
372
  IdentifierFactory.access(
383
373
  ts.factory.createIdentifier(variables),
384
- )("toString"),
385
- undefined,
374
+ )("set"),
386
375
  undefined,
376
+ [
377
+ ts.factory.createIdentifier("key"),
378
+ ts.factory.createCallExpression(
379
+ ts.factory.createIdentifier("String"),
380
+ undefined,
381
+ [ts.factory.createIdentifier("value")],
382
+ ),
383
+ ],
387
384
  ),
388
- ts.factory.createTemplateTail(""),
389
385
  ),
390
- ],
386
+ ),
391
387
  ),
392
388
  ),
389
+ local("location")("string")(template()),
390
+ ts.factory.createReturnStatement(
391
+ ts.factory.createConditionalExpression(
392
+ ts.factory.createStrictEquality(
393
+ ExpressionFactory.number(0),
394
+ IdentifierFactory.access(
395
+ ts.factory.createIdentifier(variables),
396
+ )("size"),
397
+ ),
398
+ undefined,
399
+ ts.factory.createIdentifier("location"),
400
+ undefined,
401
+ ts.factory.createTemplateExpression(
402
+ ts.factory.createTemplateHead(""),
403
+ [
404
+ ts.factory.createTemplateSpan(
405
+ ts.factory.createIdentifier("location"),
406
+ ts.factory.createTemplateMiddle("?"),
407
+ ),
408
+ ts.factory.createTemplateSpan(
409
+ ts.factory.createCallExpression(
410
+ IdentifierFactory.access(
411
+ ts.factory.createIdentifier(variables),
412
+ )("toString"),
413
+ undefined,
414
+ undefined,
415
+ ),
416
+ ts.factory.createTemplateTail(""),
417
+ ),
418
+ ],
419
+ ),
420
+ ),
421
+ ),
422
+ ],
423
+ true,
424
+ );
425
+ };
426
+ if (query !== undefined && g.query.length === 0)
427
+ return out(
428
+ block(
429
+ query.metadata.isRequired() === false
430
+ ? ts.factory.createBinaryExpression(
431
+ ts.factory.createIdentifier(query.name),
432
+ ts.factory.createToken(ts.SyntaxKind.QuestionQuestionToken),
433
+ ts.factory.createObjectLiteralExpression([], false),
434
+ )
435
+ : ts.factory.createIdentifier(query.name),
393
436
  ),
394
- ],
395
- true,
396
- );
397
- };
398
- if (query !== undefined && g.query.length === 0)
437
+ );
399
438
  return out(
400
439
  block(
401
- query.metadata.isRequired() === false
402
- ? ts.factory.createBinaryExpression(
403
- ts.factory.createIdentifier(query.name),
404
- ts.factory.createToken(ts.SyntaxKind.QuestionQuestionToken),
405
- ts.factory.createObjectLiteralExpression([], false),
406
- )
407
- : ts.factory.createIdentifier(query.name),
440
+ ts.factory.createObjectLiteralExpression(
441
+ [
442
+ ...(query
443
+ ? [
444
+ ts.factory.createSpreadAssignment(
445
+ ts.factory.createIdentifier(query.name),
446
+ ),
447
+ ]
448
+ : []),
449
+ ...g.query.map((q) =>
450
+ q.name === q.field
451
+ ? ts.factory.createShorthandPropertyAssignment(q.name)
452
+ : ts.factory.createPropertyAssignment(
453
+ Escaper.variable(q.field!)
454
+ ? q.field!
455
+ : ts.factory.createStringLiteral(q.field!),
456
+ ts.factory.createIdentifier(q.name),
457
+ ),
458
+ ),
459
+ ],
460
+ true,
461
+ ),
408
462
  ),
409
463
  );
410
- return out(
411
- block(
412
- ts.factory.createObjectLiteralExpression(
413
- [
414
- ...(query
415
- ? [
416
- ts.factory.createSpreadAssignment(
417
- ts.factory.createIdentifier(query.name),
418
- ),
419
- ]
420
- : []),
421
- ...g.query.map((q) =>
422
- q.name === q.field
423
- ? ts.factory.createShorthandPropertyAssignment(q.name)
424
- : ts.factory.createPropertyAssignment(
425
- Escaper.variable(q.field!)
426
- ? q.field!
427
- : ts.factory.createStringLiteral(q.field!),
428
- ts.factory.createIdentifier(q.name),
429
- ),
430
- ),
431
- ],
432
- true,
433
- ),
434
- ),
435
- );
436
- };
464
+ };
437
465
 
438
466
  const write_stringify =
439
467
  (project: INestiaProject) =>