@nestia/sdk 4.6.2 → 5.0.0-dev.20250301

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 (109) hide show
  1. package/LICENSE +21 -21
  2. package/README.md +91 -92
  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 +4 -4
  15. package/lib/executable/sdk.js +12 -12
  16. package/package.json +9 -10
  17. package/src/INestiaConfig.ts +271 -271
  18. package/src/NestiaSdkApplication.ts +307 -307
  19. package/src/NestiaSwaggerComposer.ts +138 -138
  20. package/src/analyses/AccessorAnalyzer.ts +67 -67
  21. package/src/analyses/ConfigAnalyzer.ts +155 -155
  22. package/src/analyses/ExceptionAnalyzer.ts +154 -154
  23. package/src/analyses/GenericAnalyzer.ts +49 -49
  24. package/src/analyses/ImportAnalyzer.ts +171 -171
  25. package/src/analyses/PathAnalyzer.ts +69 -69
  26. package/src/analyses/ReflectControllerAnalyzer.ts +105 -105
  27. package/src/analyses/ReflectHttpOperationAnalyzer.ts +183 -183
  28. package/src/analyses/ReflectHttpOperationExceptionAnalyzer.ts +71 -71
  29. package/src/analyses/ReflectHttpOperationParameterAnalyzer.ts +348 -348
  30. package/src/analyses/ReflectHttpOperationResponseAnalyzer.ts +127 -127
  31. package/src/analyses/ReflectMetadataAnalyzer.ts +44 -44
  32. package/src/analyses/ReflectWebSocketOperationAnalyzer.ts +172 -172
  33. package/src/analyses/SecurityAnalyzer.ts +25 -25
  34. package/src/analyses/TypedHttpRouteAnalyzer.ts +186 -186
  35. package/src/analyses/TypedWebSocketRouteAnalyzer.ts +18 -18
  36. package/src/decorators/OperationMetadata.ts +15 -15
  37. package/src/executable/internal/CommandParser.ts +15 -15
  38. package/src/executable/internal/NestiaConfigLoader.ts +78 -78
  39. package/src/executable/internal/NestiaSdkCommand.ts +103 -103
  40. package/src/executable/sdk.ts +75 -75
  41. package/src/generates/CloneGenerator.ts +66 -66
  42. package/src/generates/E2eGenerator.ts +32 -32
  43. package/src/generates/SdkGenerator.ts +159 -159
  44. package/src/generates/SwaggerGenerator.ts +292 -292
  45. package/src/generates/internal/E2eFileProgrammer.ts +183 -183
  46. package/src/generates/internal/FilePrinter.ts +53 -53
  47. package/src/generates/internal/ImportDictionary.ts +147 -147
  48. package/src/generates/internal/SdkAliasCollection.ts +185 -185
  49. package/src/generates/internal/SdkDistributionComposer.ts +103 -103
  50. package/src/generates/internal/SdkFileProgrammer.ts +116 -116
  51. package/src/generates/internal/SdkHttpCloneProgrammer.ts +124 -124
  52. package/src/generates/internal/SdkHttpCloneReferencer.ts +71 -71
  53. package/src/generates/internal/SdkHttpFunctionProgrammer.ts +301 -301
  54. package/src/generates/internal/SdkHttpNamespaceProgrammer.ts +529 -529
  55. package/src/generates/internal/SdkHttpRouteProgrammer.ts +117 -117
  56. package/src/generates/internal/SdkHttpSimulationProgrammer.ts +362 -362
  57. package/src/generates/internal/SdkImportWizard.ts +55 -55
  58. package/src/generates/internal/SdkRouteDirectory.ts +18 -18
  59. package/src/generates/internal/SdkTypeProgrammer.ts +377 -377
  60. package/src/generates/internal/SdkTypeTagProgrammer.ts +102 -102
  61. package/src/generates/internal/SdkWebSocketNamespaceProgrammer.ts +362 -362
  62. package/src/generates/internal/SdkWebSocketRouteProgrammer.ts +265 -265
  63. package/src/generates/internal/SwaggerDescriptionComposer.ts +64 -64
  64. package/src/generates/internal/SwaggerOperationComposer.ts +119 -119
  65. package/src/generates/internal/SwaggerOperationParameterComposer.ts +177 -177
  66. package/src/generates/internal/SwaggerOperationResponseComposer.ts +110 -110
  67. package/src/index.ts +4 -4
  68. package/src/module.ts +3 -3
  69. package/src/structures/INestiaProject.ts +13 -13
  70. package/src/structures/INestiaSdkInput.ts +20 -20
  71. package/src/structures/IReflectApplication.ts +8 -8
  72. package/src/structures/IReflectController.ts +15 -15
  73. package/src/structures/IReflectHttpOperation.ts +26 -26
  74. package/src/structures/IReflectHttpOperationException.ts +19 -19
  75. package/src/structures/IReflectHttpOperationParameter.ts +81 -81
  76. package/src/structures/IReflectHttpOperationSuccess.ts +22 -22
  77. package/src/structures/IReflectOperationError.ts +26 -26
  78. package/src/structures/IReflectType.ts +4 -4
  79. package/src/structures/IReflectTypeImport.ts +4 -4
  80. package/src/structures/IReflectWebSocketOperation.ts +17 -17
  81. package/src/structures/IReflectWebSocketOperationParameter.ts +38 -38
  82. package/src/structures/ITypedApplication.ts +11 -11
  83. package/src/structures/ITypedHttpRoute.ts +30 -30
  84. package/src/structures/ITypedHttpRouteException.ts +15 -15
  85. package/src/structures/ITypedHttpRouteParameter.ts +41 -41
  86. package/src/structures/ITypedHttpRouteSuccess.ts +22 -22
  87. package/src/structures/ITypedWebSocketRoute.ts +20 -20
  88. package/src/structures/ITypedWebSocketRouteParameter.ts +3 -3
  89. package/src/structures/MethodType.ts +5 -5
  90. package/src/structures/ParamCategory.ts +1 -1
  91. package/src/structures/TypeEntry.ts +22 -22
  92. package/src/transform.ts +9 -9
  93. package/src/transformers/IOperationMetadata.ts +44 -44
  94. package/src/transformers/ISdkOperationTransformerContext.ts +8 -8
  95. package/src/transformers/SdkOperationProgrammer.ts +209 -209
  96. package/src/transformers/SdkOperationTransformer.ts +253 -253
  97. package/src/transformers/TextPlainValidator.ts +17 -17
  98. package/src/typings/get-function-location.d.ts +7 -7
  99. package/src/utils/ArrayUtil.ts +26 -26
  100. package/src/utils/FileRetriever.ts +22 -22
  101. package/src/utils/MapUtil.ts +14 -14
  102. package/src/utils/MetadataUtil.ts +26 -26
  103. package/src/utils/PathUtil.ts +10 -10
  104. package/src/utils/SourceFinder.ts +66 -66
  105. package/src/utils/StringUtil.ts +17 -17
  106. package/src/utils/StripEnums.ts +5 -5
  107. package/src/utils/VersioningStrategy.ts +28 -28
  108. package/src/validators/HttpHeadersValidator.ts +34 -34
  109. package/src/validators/HttpQueryValidator.ts +34 -34
@@ -1,265 +1,265 @@
1
- import ts from "typescript";
2
- import { IJsDocTagInfo } from "typia";
3
- import { IdentifierFactory } from "typia/lib/factories/IdentifierFactory";
4
-
5
- import { ITypedWebSocketRoute } from "../../structures/ITypedWebSocketRoute";
6
- import { FilePrinter } from "./FilePrinter";
7
- import { ImportDictionary } from "./ImportDictionary";
8
- import { SdkAliasCollection } from "./SdkAliasCollection";
9
- import { SdkImportWizard } from "./SdkImportWizard";
10
- import { SdkWebSocketNamespaceProgrammer } from "./SdkWebSocketNamespaceProgrammer";
11
-
12
- export namespace SdkWebSocketRouteProgrammer {
13
- export const write =
14
- (importer: ImportDictionary) =>
15
- (route: ITypedWebSocketRoute): ts.Statement[] => [
16
- FilePrinter.description(
17
- writeFunction(importer)(route),
18
- writeDescription(route),
19
- ),
20
- SdkWebSocketNamespaceProgrammer.write(importer)(route),
21
- ];
22
-
23
- const writeDescription = (route: ITypedWebSocketRoute): string => {
24
- // MAIN DESCRIPTION
25
- const comments: string[] = route.description
26
- ? route.description.split("\n")
27
- : [];
28
-
29
- // COMMENT TAGS
30
- const tags: IJsDocTagInfo[] = route.jsDocTags.filter(
31
- (tag) =>
32
- tag.name !== "param" ||
33
- route.parameters
34
- .filter((p) => p.category === "param" || p.category === "query")
35
- .some((p) => p.name === tag.text?.[0]?.text),
36
- );
37
- if (tags.length !== 0) {
38
- const content: string[] = tags.map((t) =>
39
- t.text?.length
40
- ? `@${t.name} ${t.text.map((e) => e.text).join("")}`
41
- : `@${t.name}`,
42
- );
43
- comments.push("", ...new Set(content));
44
- }
45
-
46
- // POSTFIX
47
- if (!!comments.length) comments.push("");
48
- comments.push(
49
- `@controller ${route.controller.class.name}.${route.name}`,
50
- `@path ${route.path}`,
51
- `@nestia Generated by Nestia - https://github.com/samchon/nestia`,
52
- );
53
- return comments.join("\n");
54
- };
55
-
56
- const writeFunction =
57
- (importer: ImportDictionary) =>
58
- (route: ITypedWebSocketRoute): ts.FunctionDeclaration =>
59
- ts.factory.createFunctionDeclaration(
60
- [
61
- ts.factory.createModifier(ts.SyntaxKind.ExportKeyword),
62
- ts.factory.createModifier(ts.SyntaxKind.AsyncKeyword),
63
- ],
64
- undefined,
65
- route.name,
66
- undefined,
67
- [
68
- IdentifierFactory.parameter(
69
- "connection",
70
- ts.factory.createTypeReferenceNode(
71
- SdkImportWizard.IConnection(importer),
72
- [ts.factory.createTypeReferenceNode(`${route.name}.Header`)],
73
- ),
74
- ),
75
- ...route.parameters
76
- .filter((p) => p.category === "param" || p.category === "query")
77
- .map((p) =>
78
- IdentifierFactory.parameter(
79
- p.name,
80
- p.category === "param"
81
- ? SdkAliasCollection.name(p)
82
- : ts.factory.createTypeReferenceNode(`${route.name}.Query`),
83
- ),
84
- ),
85
- IdentifierFactory.parameter(
86
- "provider",
87
- ts.factory.createTypeReferenceNode(`${route.name}.Provider`),
88
- ),
89
- ],
90
- ts.factory.createTypeReferenceNode("Promise", [
91
- ts.factory.createTypeReferenceNode(`${route.name}.Output`),
92
- ]),
93
- ts.factory.createBlock(writeFunctionBody(importer)(route), true),
94
- );
95
-
96
- const writeFunctionBody =
97
- (importer: ImportDictionary) =>
98
- (route: ITypedWebSocketRoute): ts.Statement[] => [
99
- local("connector")(
100
- ts.factory.createTypeReferenceNode(
101
- importer.external({
102
- type: false,
103
- library: "tgrid",
104
- instance: "WebSocketConnector",
105
- }),
106
- [
107
- ts.factory.createTypeReferenceNode(`${route.name}.Header`),
108
- ts.factory.createTypeReferenceNode(`${route.name}.Provider`),
109
- ts.factory.createTypeReferenceNode(`${route.name}.Listener`),
110
- ],
111
- ),
112
- )(
113
- ts.factory.createNewExpression(
114
- ts.factory.createIdentifier(
115
- importer.external({
116
- type: false,
117
- library: "tgrid",
118
- instance: "WebSocketConnector",
119
- }),
120
- ),
121
- undefined,
122
- [
123
- ts.factory.createAsExpression(
124
- ts.factory.createBinaryExpression(
125
- ts.factory.createPropertyAccessExpression(
126
- ts.factory.createIdentifier("connection"),
127
- "headers",
128
- ),
129
- ts.factory.createToken(ts.SyntaxKind.QuestionQuestionToken),
130
- ts.factory.createObjectLiteralExpression([], false),
131
- ),
132
- ts.factory.createKeywordTypeNode(ts.SyntaxKind.AnyKeyword),
133
- ),
134
- ts.factory.createIdentifier("provider"),
135
- ],
136
- ),
137
- ),
138
- ts.factory.createExpressionStatement(
139
- ts.factory.createAwaitExpression(
140
- ts.factory.createCallExpression(
141
- ts.factory.createPropertyAccessExpression(
142
- ts.factory.createIdentifier("connector"),
143
- "connect",
144
- ),
145
- undefined,
146
- [
147
- joinPath(
148
- ts.factory.createCallExpression(
149
- ts.factory.createPropertyAccessExpression(
150
- ts.factory.createIdentifier(route.name),
151
- "path",
152
- ),
153
- [],
154
- route.parameters
155
- .filter(
156
- (p) => p.category === "param" || p.category === "query",
157
- )
158
- .map((x) => ts.factory.createIdentifier(x.name)),
159
- ),
160
- ),
161
- ],
162
- ),
163
- ),
164
- ),
165
- local("driver")(
166
- ts.factory.createTypeReferenceNode(
167
- importer.external({
168
- type: true,
169
- library: "tgrid",
170
- instance: "Driver",
171
- }),
172
- [ts.factory.createTypeReferenceNode(`${route.name}.Listener`)],
173
- ),
174
- )(
175
- ts.factory.createCallExpression(
176
- ts.factory.createPropertyAccessExpression(
177
- ts.factory.createIdentifier("connector"),
178
- "getDriver",
179
- ),
180
- undefined,
181
- undefined,
182
- ),
183
- ),
184
- ts.factory.createReturnStatement(
185
- ts.factory.createObjectLiteralExpression(
186
- [
187
- ts.factory.createShorthandPropertyAssignment("connector"),
188
- ts.factory.createShorthandPropertyAssignment("driver"),
189
- ],
190
- true,
191
- ),
192
- ),
193
- ];
194
- }
195
-
196
- const local =
197
- (name: string) => (type: ts.TypeNode) => (expression: ts.Expression) =>
198
- ts.factory.createVariableStatement(
199
- [],
200
- ts.factory.createVariableDeclarationList(
201
- [
202
- ts.factory.createVariableDeclaration(
203
- name,
204
- undefined,
205
- type,
206
- expression,
207
- ),
208
- ],
209
- ts.NodeFlags.Const,
210
- ),
211
- );
212
-
213
- const joinPath = (caller: ts.Expression) =>
214
- ts.factory.createTemplateExpression(ts.factory.createTemplateHead("", ""), [
215
- ts.factory.createTemplateSpan(
216
- ts.factory.createConditionalExpression(
217
- ts.factory.createCallExpression(
218
- ts.factory.createPropertyAccessExpression(
219
- ts.factory.createPropertyAccessExpression(
220
- ts.factory.createIdentifier("connection"),
221
- ts.factory.createIdentifier("host"),
222
- ),
223
- ts.factory.createIdentifier("endsWith"),
224
- ),
225
- undefined,
226
- [ts.factory.createStringLiteral("/")],
227
- ),
228
- ts.factory.createToken(ts.SyntaxKind.QuestionToken),
229
- ts.factory.createCallExpression(
230
- ts.factory.createPropertyAccessExpression(
231
- ts.factory.createPropertyAccessExpression(
232
- ts.factory.createIdentifier("connection"),
233
- ts.factory.createIdentifier("host"),
234
- ),
235
- ts.factory.createIdentifier("substring"),
236
- ),
237
- undefined,
238
- [
239
- ts.factory.createNumericLiteral("0"),
240
- ts.factory.createBinaryExpression(
241
- ts.factory.createPropertyAccessExpression(
242
- ts.factory.createPropertyAccessExpression(
243
- ts.factory.createIdentifier("connection"),
244
- ts.factory.createIdentifier("host"),
245
- ),
246
- ts.factory.createIdentifier("length"),
247
- ),
248
- ts.factory.createToken(ts.SyntaxKind.MinusToken),
249
- ts.factory.createNumericLiteral("1"),
250
- ),
251
- ],
252
- ),
253
- ts.factory.createToken(ts.SyntaxKind.ColonToken),
254
- ts.factory.createPropertyAccessExpression(
255
- ts.factory.createIdentifier("connection"),
256
- ts.factory.createIdentifier("host"),
257
- ),
258
- ),
259
- ts.factory.createTemplateMiddle("", ""),
260
- ),
261
- ts.factory.createTemplateSpan(
262
- caller,
263
- ts.factory.createTemplateTail("", ""),
264
- ),
265
- ]);
1
+ import ts from "typescript";
2
+ import { IJsDocTagInfo } from "typia";
3
+ import { IdentifierFactory } from "typia/lib/factories/IdentifierFactory";
4
+
5
+ import { ITypedWebSocketRoute } from "../../structures/ITypedWebSocketRoute";
6
+ import { FilePrinter } from "./FilePrinter";
7
+ import { ImportDictionary } from "./ImportDictionary";
8
+ import { SdkAliasCollection } from "./SdkAliasCollection";
9
+ import { SdkImportWizard } from "./SdkImportWizard";
10
+ import { SdkWebSocketNamespaceProgrammer } from "./SdkWebSocketNamespaceProgrammer";
11
+
12
+ export namespace SdkWebSocketRouteProgrammer {
13
+ export const write =
14
+ (importer: ImportDictionary) =>
15
+ (route: ITypedWebSocketRoute): ts.Statement[] => [
16
+ FilePrinter.description(
17
+ writeFunction(importer)(route),
18
+ writeDescription(route),
19
+ ),
20
+ SdkWebSocketNamespaceProgrammer.write(importer)(route),
21
+ ];
22
+
23
+ const writeDescription = (route: ITypedWebSocketRoute): string => {
24
+ // MAIN DESCRIPTION
25
+ const comments: string[] = route.description
26
+ ? route.description.split("\n")
27
+ : [];
28
+
29
+ // COMMENT TAGS
30
+ const tags: IJsDocTagInfo[] = route.jsDocTags.filter(
31
+ (tag) =>
32
+ tag.name !== "param" ||
33
+ route.parameters
34
+ .filter((p) => p.category === "param" || p.category === "query")
35
+ .some((p) => p.name === tag.text?.[0]?.text),
36
+ );
37
+ if (tags.length !== 0) {
38
+ const content: string[] = tags.map((t) =>
39
+ t.text?.length
40
+ ? `@${t.name} ${t.text.map((e) => e.text).join("")}`
41
+ : `@${t.name}`,
42
+ );
43
+ comments.push("", ...new Set(content));
44
+ }
45
+
46
+ // POSTFIX
47
+ if (!!comments.length) comments.push("");
48
+ comments.push(
49
+ `@controller ${route.controller.class.name}.${route.name}`,
50
+ `@path ${route.path}`,
51
+ `@nestia Generated by Nestia - https://github.com/samchon/nestia`,
52
+ );
53
+ return comments.join("\n");
54
+ };
55
+
56
+ const writeFunction =
57
+ (importer: ImportDictionary) =>
58
+ (route: ITypedWebSocketRoute): ts.FunctionDeclaration =>
59
+ ts.factory.createFunctionDeclaration(
60
+ [
61
+ ts.factory.createModifier(ts.SyntaxKind.ExportKeyword),
62
+ ts.factory.createModifier(ts.SyntaxKind.AsyncKeyword),
63
+ ],
64
+ undefined,
65
+ route.name,
66
+ undefined,
67
+ [
68
+ IdentifierFactory.parameter(
69
+ "connection",
70
+ ts.factory.createTypeReferenceNode(
71
+ SdkImportWizard.IConnection(importer),
72
+ [ts.factory.createTypeReferenceNode(`${route.name}.Header`)],
73
+ ),
74
+ ),
75
+ ...route.parameters
76
+ .filter((p) => p.category === "param" || p.category === "query")
77
+ .map((p) =>
78
+ IdentifierFactory.parameter(
79
+ p.name,
80
+ p.category === "param"
81
+ ? SdkAliasCollection.name(p)
82
+ : ts.factory.createTypeReferenceNode(`${route.name}.Query`),
83
+ ),
84
+ ),
85
+ IdentifierFactory.parameter(
86
+ "provider",
87
+ ts.factory.createTypeReferenceNode(`${route.name}.Provider`),
88
+ ),
89
+ ],
90
+ ts.factory.createTypeReferenceNode("Promise", [
91
+ ts.factory.createTypeReferenceNode(`${route.name}.Output`),
92
+ ]),
93
+ ts.factory.createBlock(writeFunctionBody(importer)(route), true),
94
+ );
95
+
96
+ const writeFunctionBody =
97
+ (importer: ImportDictionary) =>
98
+ (route: ITypedWebSocketRoute): ts.Statement[] => [
99
+ local("connector")(
100
+ ts.factory.createTypeReferenceNode(
101
+ importer.external({
102
+ type: false,
103
+ library: "tgrid",
104
+ instance: "WebSocketConnector",
105
+ }),
106
+ [
107
+ ts.factory.createTypeReferenceNode(`${route.name}.Header`),
108
+ ts.factory.createTypeReferenceNode(`${route.name}.Provider`),
109
+ ts.factory.createTypeReferenceNode(`${route.name}.Listener`),
110
+ ],
111
+ ),
112
+ )(
113
+ ts.factory.createNewExpression(
114
+ ts.factory.createIdentifier(
115
+ importer.external({
116
+ type: false,
117
+ library: "tgrid",
118
+ instance: "WebSocketConnector",
119
+ }),
120
+ ),
121
+ undefined,
122
+ [
123
+ ts.factory.createAsExpression(
124
+ ts.factory.createBinaryExpression(
125
+ ts.factory.createPropertyAccessExpression(
126
+ ts.factory.createIdentifier("connection"),
127
+ "headers",
128
+ ),
129
+ ts.factory.createToken(ts.SyntaxKind.QuestionQuestionToken),
130
+ ts.factory.createObjectLiteralExpression([], false),
131
+ ),
132
+ ts.factory.createKeywordTypeNode(ts.SyntaxKind.AnyKeyword),
133
+ ),
134
+ ts.factory.createIdentifier("provider"),
135
+ ],
136
+ ),
137
+ ),
138
+ ts.factory.createExpressionStatement(
139
+ ts.factory.createAwaitExpression(
140
+ ts.factory.createCallExpression(
141
+ ts.factory.createPropertyAccessExpression(
142
+ ts.factory.createIdentifier("connector"),
143
+ "connect",
144
+ ),
145
+ undefined,
146
+ [
147
+ joinPath(
148
+ ts.factory.createCallExpression(
149
+ ts.factory.createPropertyAccessExpression(
150
+ ts.factory.createIdentifier(route.name),
151
+ "path",
152
+ ),
153
+ [],
154
+ route.parameters
155
+ .filter(
156
+ (p) => p.category === "param" || p.category === "query",
157
+ )
158
+ .map((x) => ts.factory.createIdentifier(x.name)),
159
+ ),
160
+ ),
161
+ ],
162
+ ),
163
+ ),
164
+ ),
165
+ local("driver")(
166
+ ts.factory.createTypeReferenceNode(
167
+ importer.external({
168
+ type: true,
169
+ library: "tgrid",
170
+ instance: "Driver",
171
+ }),
172
+ [ts.factory.createTypeReferenceNode(`${route.name}.Listener`)],
173
+ ),
174
+ )(
175
+ ts.factory.createCallExpression(
176
+ ts.factory.createPropertyAccessExpression(
177
+ ts.factory.createIdentifier("connector"),
178
+ "getDriver",
179
+ ),
180
+ undefined,
181
+ undefined,
182
+ ),
183
+ ),
184
+ ts.factory.createReturnStatement(
185
+ ts.factory.createObjectLiteralExpression(
186
+ [
187
+ ts.factory.createShorthandPropertyAssignment("connector"),
188
+ ts.factory.createShorthandPropertyAssignment("driver"),
189
+ ],
190
+ true,
191
+ ),
192
+ ),
193
+ ];
194
+ }
195
+
196
+ const local =
197
+ (name: string) => (type: ts.TypeNode) => (expression: ts.Expression) =>
198
+ ts.factory.createVariableStatement(
199
+ [],
200
+ ts.factory.createVariableDeclarationList(
201
+ [
202
+ ts.factory.createVariableDeclaration(
203
+ name,
204
+ undefined,
205
+ type,
206
+ expression,
207
+ ),
208
+ ],
209
+ ts.NodeFlags.Const,
210
+ ),
211
+ );
212
+
213
+ const joinPath = (caller: ts.Expression) =>
214
+ ts.factory.createTemplateExpression(ts.factory.createTemplateHead("", ""), [
215
+ ts.factory.createTemplateSpan(
216
+ ts.factory.createConditionalExpression(
217
+ ts.factory.createCallExpression(
218
+ ts.factory.createPropertyAccessExpression(
219
+ ts.factory.createPropertyAccessExpression(
220
+ ts.factory.createIdentifier("connection"),
221
+ ts.factory.createIdentifier("host"),
222
+ ),
223
+ ts.factory.createIdentifier("endsWith"),
224
+ ),
225
+ undefined,
226
+ [ts.factory.createStringLiteral("/")],
227
+ ),
228
+ ts.factory.createToken(ts.SyntaxKind.QuestionToken),
229
+ ts.factory.createCallExpression(
230
+ ts.factory.createPropertyAccessExpression(
231
+ ts.factory.createPropertyAccessExpression(
232
+ ts.factory.createIdentifier("connection"),
233
+ ts.factory.createIdentifier("host"),
234
+ ),
235
+ ts.factory.createIdentifier("substring"),
236
+ ),
237
+ undefined,
238
+ [
239
+ ts.factory.createNumericLiteral("0"),
240
+ ts.factory.createBinaryExpression(
241
+ ts.factory.createPropertyAccessExpression(
242
+ ts.factory.createPropertyAccessExpression(
243
+ ts.factory.createIdentifier("connection"),
244
+ ts.factory.createIdentifier("host"),
245
+ ),
246
+ ts.factory.createIdentifier("length"),
247
+ ),
248
+ ts.factory.createToken(ts.SyntaxKind.MinusToken),
249
+ ts.factory.createNumericLiteral("1"),
250
+ ),
251
+ ],
252
+ ),
253
+ ts.factory.createToken(ts.SyntaxKind.ColonToken),
254
+ ts.factory.createPropertyAccessExpression(
255
+ ts.factory.createIdentifier("connection"),
256
+ ts.factory.createIdentifier("host"),
257
+ ),
258
+ ),
259
+ ts.factory.createTemplateMiddle("", ""),
260
+ ),
261
+ ts.factory.createTemplateSpan(
262
+ caller,
263
+ ts.factory.createTemplateTail("", ""),
264
+ ),
265
+ ]);
@@ -1,64 +1,64 @@
1
- import { IJsDocTagInfo } from "typia";
2
-
3
- export namespace SwaggerDescriptionComposer {
4
- export const compose = <Kind extends "summary" | "title">(props: {
5
- description: string | null;
6
- jsDocTags: IJsDocTagInfo[];
7
- kind: Kind;
8
- }): Kind extends "summary"
9
- ? { summary?: string; description?: string }
10
- : { title?: string; description?: string } => {
11
- const title: string | undefined = (() => {
12
- const [explicit] = getJsDocTexts({
13
- jsDocTags: props.jsDocTags,
14
- name: props.kind,
15
- });
16
- if (explicit?.length) return explicit;
17
- else if (!props.description?.length) return undefined;
18
-
19
- const index: number = props.description.indexOf("\n");
20
- const top: string = (
21
- index === -1 ? props.description : props.description.substring(0, index)
22
- ).trim();
23
- return top.endsWith(".") ? top.substring(0, top.length - 1) : undefined;
24
- })();
25
- return {
26
- [props.kind]: title,
27
- description: props.description?.length ? props.description : undefined,
28
- } as any;
29
- };
30
-
31
- export const descriptionFromJsDocTag = (props: {
32
- jsDocTags: IJsDocTagInfo[];
33
- tag: string;
34
- parameter?: string;
35
- }): string | undefined => {
36
- const parametric: (elem: IJsDocTagInfo) => boolean = props.parameter
37
- ? (tag) =>
38
- tag.text!.find(
39
- (elem) =>
40
- elem.kind === "parameterName" && elem.text === props.parameter,
41
- ) !== undefined
42
- : () => true;
43
- const tag: IJsDocTagInfo | undefined = props.jsDocTags.find(
44
- (tag) => tag.name === props.tag && tag.text && parametric(tag),
45
- );
46
- return tag && tag.text
47
- ? tag.text.find((elem) => elem.kind === "text")?.text
48
- : undefined;
49
- };
50
-
51
- export const getJsDocTexts = (props: {
52
- jsDocTags: IJsDocTagInfo[];
53
- name: string;
54
- }): string[] =>
55
- props.jsDocTags
56
- .filter(
57
- (tag) =>
58
- tag.name === props.name &&
59
- tag.text &&
60
- tag.text.find((elem) => elem.kind === "text" && elem.text.length) !==
61
- undefined,
62
- )
63
- .map((tag) => tag.text!.find((elem) => elem.kind === "text")!.text);
64
- }
1
+ import { IJsDocTagInfo } from "typia";
2
+
3
+ export namespace SwaggerDescriptionComposer {
4
+ export const compose = <Kind extends "summary" | "title">(props: {
5
+ description: string | null;
6
+ jsDocTags: IJsDocTagInfo[];
7
+ kind: Kind;
8
+ }): Kind extends "summary"
9
+ ? { summary?: string; description?: string }
10
+ : { title?: string; description?: string } => {
11
+ const title: string | undefined = (() => {
12
+ const [explicit] = getJsDocTexts({
13
+ jsDocTags: props.jsDocTags,
14
+ name: props.kind,
15
+ });
16
+ if (explicit?.length) return explicit;
17
+ else if (!props.description?.length) return undefined;
18
+
19
+ const index: number = props.description.indexOf("\n");
20
+ const top: string = (
21
+ index === -1 ? props.description : props.description.substring(0, index)
22
+ ).trim();
23
+ return top.endsWith(".") ? top.substring(0, top.length - 1) : undefined;
24
+ })();
25
+ return {
26
+ [props.kind]: title,
27
+ description: props.description?.length ? props.description : undefined,
28
+ } as any;
29
+ };
30
+
31
+ export const descriptionFromJsDocTag = (props: {
32
+ jsDocTags: IJsDocTagInfo[];
33
+ tag: string;
34
+ parameter?: string;
35
+ }): string | undefined => {
36
+ const parametric: (elem: IJsDocTagInfo) => boolean = props.parameter
37
+ ? (tag) =>
38
+ tag.text!.find(
39
+ (elem) =>
40
+ elem.kind === "parameterName" && elem.text === props.parameter,
41
+ ) !== undefined
42
+ : () => true;
43
+ const tag: IJsDocTagInfo | undefined = props.jsDocTags.find(
44
+ (tag) => tag.name === props.tag && tag.text && parametric(tag),
45
+ );
46
+ return tag && tag.text
47
+ ? tag.text.find((elem) => elem.kind === "text")?.text
48
+ : undefined;
49
+ };
50
+
51
+ export const getJsDocTexts = (props: {
52
+ jsDocTags: IJsDocTagInfo[];
53
+ name: string;
54
+ }): string[] =>
55
+ props.jsDocTags
56
+ .filter(
57
+ (tag) =>
58
+ tag.name === props.name &&
59
+ tag.text &&
60
+ tag.text.find((elem) => elem.kind === "text" && elem.text.length) !==
61
+ undefined,
62
+ )
63
+ .map((tag) => tag.text!.find((elem) => elem.kind === "text")!.text);
64
+ }