@nestia/sdk 12.0.0-rc.2 → 12.0.0-rc.4

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 (126) hide show
  1. package/LICENSE +21 -21
  2. package/assets/bundle/api/HttpError.ts +1 -1
  3. package/assets/bundle/api/IConnection.ts +1 -1
  4. package/assets/bundle/api/Primitive.ts +1 -1
  5. package/assets/bundle/api/Resolved.ts +1 -1
  6. package/assets/bundle/api/index.ts +4 -4
  7. package/assets/bundle/api/module.ts +6 -6
  8. package/assets/bundle/distribute/README.md +37 -37
  9. package/assets/bundle/distribute/package.json +28 -28
  10. package/assets/bundle/distribute/tsconfig.json +109 -109
  11. package/assets/bundle/e2e/index.ts +42 -42
  12. package/assets/config/nestia.config.ts +97 -97
  13. package/lib/executable/sdk.js +12 -12
  14. package/lib/generates/SdkGenerator.d.ts +9 -0
  15. package/lib/generates/SdkGenerator.js +23 -10
  16. package/lib/generates/SdkGenerator.js.map +1 -1
  17. package/lib/generates/internal/ImportDictionary.js +4 -4
  18. package/lib/generates/internal/ImportDictionary.js.map +1 -1
  19. package/lib/generates/internal/SwaggerReadonlyArrayEmender.js +9 -5
  20. package/lib/generates/internal/SwaggerReadonlyArrayEmender.js.map +1 -1
  21. package/native/go.mod +35 -52
  22. package/native/go.sum +54 -84
  23. package/native/sdk/register.go +322 -322
  24. package/native/sdk/sdk.go +17 -17
  25. package/native/sdk/sdk_metadata_json.go +327 -327
  26. package/native/sdk/sdk_transform.go +1879 -1879
  27. package/package.json +10 -10
  28. package/src/INestiaConfig.ts +267 -267
  29. package/src/NestiaSwaggerComposer.ts +152 -152
  30. package/src/analyses/AccessorAnalyzer.ts +93 -93
  31. package/src/analyses/ConfigAnalyzer.ts +344 -344
  32. package/src/analyses/ImportAnalyzer.ts +92 -92
  33. package/src/analyses/PathAnalyzer.ts +130 -130
  34. package/src/analyses/ReflectControllerAnalyzer.ts +112 -112
  35. package/src/analyses/ReflectHttpOperationAnalyzer.ts +183 -183
  36. package/src/analyses/ReflectHttpOperationExceptionAnalyzer.ts +90 -90
  37. package/src/analyses/ReflectHttpOperationParameterAnalyzer.ts +350 -350
  38. package/src/analyses/ReflectHttpOperationResponseAnalyzer.ts +163 -163
  39. package/src/analyses/ReflectMcpOperationAnalyzer.ts +124 -124
  40. package/src/analyses/ReflectMetadataAnalyzer.ts +44 -44
  41. package/src/analyses/SecurityAnalyzer.ts +25 -25
  42. package/src/analyses/TypedMcpRouteAnalyzer.ts +34 -34
  43. package/src/decorators/OperationMetadata.ts +29 -29
  44. package/src/executable/internal/CommandParser.ts +15 -15
  45. package/src/executable/internal/NestiaConfigLoader.ts +451 -451
  46. package/src/executable/internal/NestiaSdkCommand.ts +124 -124
  47. package/src/executable/internal/NestiaSdkWatcher.ts +342 -342
  48. package/src/executable/sdk.ts +90 -90
  49. package/src/factories/ExpressionFactory.ts +23 -23
  50. package/src/factories/IdentifierFactory.ts +84 -84
  51. package/src/factories/LiteralFactory.ts +54 -54
  52. package/src/factories/StatementFactory.ts +56 -56
  53. package/src/factories/TypeFactory.ts +27 -27
  54. package/src/generates/CloneGenerator.ts +74 -74
  55. package/src/generates/E2eGenerator.ts +32 -32
  56. package/src/generates/SdkGenerator.ts +188 -176
  57. package/src/generates/SwaggerGenerator.ts +342 -342
  58. package/src/generates/internal/E2eFileProgrammer.ts +246 -246
  59. package/src/generates/internal/FilePrinter.ts +57 -57
  60. package/src/generates/internal/ImportDictionary.ts +207 -207
  61. package/src/generates/internal/SdkAliasCollection.ts +280 -280
  62. package/src/generates/internal/SdkDistributionComposer.ts +123 -123
  63. package/src/generates/internal/SdkFileProgrammer.ts +113 -113
  64. package/src/generates/internal/SdkHttpCloneProgrammer.ts +124 -124
  65. package/src/generates/internal/SdkHttpCloneReferencer.ts +131 -131
  66. package/src/generates/internal/SdkHttpFunctionProgrammer.ts +290 -290
  67. package/src/generates/internal/SdkHttpNamespaceProgrammer.ts +507 -507
  68. package/src/generates/internal/SdkHttpParameterProgrammer.ts +163 -163
  69. package/src/generates/internal/SdkHttpRouteProgrammer.ts +109 -109
  70. package/src/generates/internal/SdkHttpSimulationProgrammer.ts +322 -322
  71. package/src/generates/internal/SdkImportWizard.ts +62 -62
  72. package/src/generates/internal/SdkMcpRouteProgrammer.ts +447 -447
  73. package/src/generates/internal/SdkRouteDirectory.ts +21 -21
  74. package/src/generates/internal/SdkTypeProgrammer.ts +389 -389
  75. package/src/generates/internal/SdkTypeTagProgrammer.ts +110 -110
  76. package/src/generates/internal/SdkWebSocketCloneProgrammer.ts +319 -319
  77. package/src/generates/internal/SdkWebSocketNamespaceProgrammer.ts +383 -383
  78. package/src/generates/internal/SdkWebSocketParameterProgrammer.ts +91 -91
  79. package/src/generates/internal/SdkWebSocketRouteProgrammer.ts +304 -304
  80. package/src/generates/internal/SwaggerDescriptionComposer.ts +64 -64
  81. package/src/generates/internal/SwaggerOperationComposer.ts +119 -119
  82. package/src/generates/internal/SwaggerOperationParameterComposer.ts +175 -175
  83. package/src/generates/internal/SwaggerOperationResponseComposer.ts +115 -115
  84. package/src/generates/internal/SwaggerReadonlyArrayEmender.ts +264 -262
  85. package/src/index.ts +4 -4
  86. package/src/internal/legacy.ts +492 -492
  87. package/src/module.ts +4 -4
  88. package/src/structures/INestiaProject.ts +10 -10
  89. package/src/structures/INestiaSdkInput.ts +27 -27
  90. package/src/structures/IOperationMetadata.ts +41 -41
  91. package/src/structures/IReflectController.ts +18 -18
  92. package/src/structures/IReflectHttpOperation.ts +26 -26
  93. package/src/structures/IReflectHttpOperationException.ts +18 -18
  94. package/src/structures/IReflectHttpOperationParameter.ts +79 -79
  95. package/src/structures/IReflectHttpOperationSuccess.ts +18 -18
  96. package/src/structures/IReflectImport.ts +6 -6
  97. package/src/structures/IReflectMcpOperation.ts +38 -38
  98. package/src/structures/IReflectMcpOperationParameter.ts +27 -27
  99. package/src/structures/IReflectOperationError.ts +26 -26
  100. package/src/structures/IReflectType.ts +4 -4
  101. package/src/structures/IReflectWebSocketOperation.ts +17 -17
  102. package/src/structures/ITypedApplication.ts +12 -12
  103. package/src/structures/ITypedHttpRoute.ts +41 -41
  104. package/src/structures/ITypedHttpRouteException.ts +15 -15
  105. package/src/structures/ITypedHttpRouteParameter.ts +41 -41
  106. package/src/structures/ITypedHttpRouteSuccess.ts +18 -18
  107. package/src/structures/ITypedMcpRoute.ts +33 -33
  108. package/src/structures/ITypedWebSocketRoute.ts +24 -24
  109. package/src/structures/ITypedWebSocketRouteParameter.ts +3 -3
  110. package/src/transform.ts +28 -28
  111. package/src/typings/get-function-location.d.ts +7 -7
  112. package/src/utils/ArrayUtil.ts +26 -26
  113. package/src/utils/EmittedJavaScriptPatcher.ts +88 -88
  114. package/src/utils/FileRetriever.ts +22 -22
  115. package/src/utils/HttpResponseContentTypeUtil.ts +30 -30
  116. package/src/utils/MapUtil.ts +14 -14
  117. package/src/utils/PathUtil.ts +10 -10
  118. package/src/utils/SourceFinder.ts +69 -69
  119. package/src/utils/StringUtil.ts +17 -17
  120. package/src/utils/TsConfigReader.ts +108 -108
  121. package/src/utils/TtscExecutor.ts +68 -68
  122. package/src/utils/VersioningStrategy.ts +28 -28
  123. package/src/validators/HttpHeadersValidator.ts +11 -11
  124. package/src/validators/HttpQueryValidator.ts +11 -11
  125. package/src/validators/TextPlainValidator.ts +17 -17
  126. package/README.md +0 -93
@@ -1,304 +1,304 @@
1
- import {
2
- type Expression,
3
- NodeFlags,
4
- type Statement,
5
- SyntaxKind,
6
- type TypeNode,
7
- factory,
8
- } from "@ttsc/factory";
9
- import { IJsDocTagInfo } from "typia";
10
-
11
- import { IdentifierFactory } from "../../factories/IdentifierFactory";
12
- import { INestiaProject } from "../../structures/INestiaProject";
13
- import { ITypedWebSocketRoute } from "../../structures/ITypedWebSocketRoute";
14
- import { StringUtil } from "../../utils/StringUtil";
15
- import { FilePrinter } from "./FilePrinter";
16
- import { ImportDictionary } from "./ImportDictionary";
17
- import { SdkImportWizard } from "./SdkImportWizard";
18
- import { SdkWebSocketNamespaceProgrammer } from "./SdkWebSocketNamespaceProgrammer";
19
- import { SdkWebSocketParameterProgrammer } from "./SdkWebSocketParameterProgrammer";
20
-
21
- export namespace SdkWebSocketRouteProgrammer {
22
- export const write =
23
- (project: INestiaProject) =>
24
- (importer: ImportDictionary) =>
25
- (route: ITypedWebSocketRoute): Statement[] => [
26
- FilePrinter.description(
27
- writeFunction(project)(importer)(route),
28
- writeDescription(route),
29
- ),
30
- SdkWebSocketNamespaceProgrammer.write(project)(importer)(route),
31
- ];
32
-
33
- const writeDescription = (route: ITypedWebSocketRoute): string => {
34
- // MAIN DESCRIPTION
35
- const comments: string[] = route.description
36
- ? route.description.split("\n")
37
- : [];
38
-
39
- // COMMENT TAGS
40
- const tags: IJsDocTagInfo[] = route.jsDocTags.filter(
41
- (tag) =>
42
- tag.name !== "param" ||
43
- [...route.pathParameters, ...(route.query ? [route.query] : [])]
44
- .filter((p) => p.category === "param" || p.category === "query")
45
- .some((p) => p.name === tag.text?.[0]?.text),
46
- );
47
- if (tags.length !== 0) {
48
- const content: string[] = tags.map((t) =>
49
- t.text?.length
50
- ? `@${t.name} ${t.text.map((e) => e.text).join("")}`
51
- : `@${t.name}`,
52
- );
53
- comments.push("", ...new Set(content));
54
- }
55
-
56
- // POSTFIX
57
- if (!!comments.length) comments.push("");
58
- comments.push(
59
- `@controller ${route.controller.class.name}.${route.name}`,
60
- `@path ${route.path}`,
61
- `@nestia Generated by Nestia - https://github.com/samchon/nestia`,
62
- );
63
- return comments.join("\n");
64
- };
65
-
66
- const writeFunction =
67
- (project: INestiaProject) =>
68
- (importer: ImportDictionary) =>
69
- (route: ITypedWebSocketRoute): Statement => {
70
- const connection: string = StringUtil.escapeDuplicate([route.name])(
71
- "connection",
72
- );
73
- return factory.createFunctionDeclaration(
74
- [
75
- factory.createModifier(SyntaxKind.ExportKeyword),
76
- factory.createModifier(SyntaxKind.AsyncKeyword),
77
- ],
78
- undefined,
79
- route.name,
80
- undefined,
81
- [
82
- IdentifierFactory.parameter(
83
- connection,
84
- factory.createTypeReferenceNode(
85
- SdkImportWizard.IConnection(importer),
86
- [factory.createTypeReferenceNode(`${route.name}.Header`)],
87
- ),
88
- ),
89
- ...SdkWebSocketParameterProgrammer.getParameterDeclarations({
90
- project,
91
- route,
92
- provider: true,
93
- prefix: true,
94
- }),
95
- ],
96
- factory.createTypeReferenceNode("Promise", [
97
- factory.createTypeReferenceNode(`${route.name}.Output`),
98
- ]),
99
- factory.createBlock(
100
- writeFunctionBody(project)(importer)(route)(connection),
101
- true,
102
- ),
103
- );
104
- };
105
-
106
- const writeFunctionBody =
107
- (project: INestiaProject) =>
108
- (importer: ImportDictionary) =>
109
- (route: ITypedWebSocketRoute) =>
110
- (connection: string): Statement[] => {
111
- const access = (key: string) =>
112
- project.config.keyword === true
113
- ? factory.createPropertyAccessExpression(
114
- factory.createIdentifier("props"),
115
- key,
116
- )
117
- : factory.createIdentifier(key);
118
- return [
119
- local("url")(factory.createTypeReferenceNode("string"))(
120
- joinPath(
121
- connection,
122
- factory.createCallExpression(
123
- factory.createPropertyAccessExpression(
124
- factory.createIdentifier(route.name),
125
- "path",
126
- ),
127
- [],
128
- project.config.keyword === true &&
129
- SdkWebSocketParameterProgrammer.isPathEmpty(route) === false
130
- ? [factory.createIdentifier("props")]
131
- : SdkWebSocketParameterProgrammer.getEntries({
132
- project,
133
- route,
134
- provider: false,
135
- prefix: true,
136
- }).map((p) => factory.createIdentifier(p.key)),
137
- ),
138
- ),
139
- ),
140
- local("connector")(
141
- factory.createTypeReferenceNode(
142
- importer.external({
143
- declaration: false,
144
- file: "tgrid",
145
- type: "element",
146
- name: "WebSocketConnector",
147
- }),
148
- [
149
- factory.createTypeReferenceNode(`${route.name}.Header`),
150
- factory.createTypeReferenceNode(`${route.name}.Provider`),
151
- factory.createTypeReferenceNode(`${route.name}.Listener`),
152
- ],
153
- ),
154
- )(
155
- factory.createNewExpression(
156
- factory.createIdentifier(
157
- importer.external({
158
- declaration: false,
159
- file: "tgrid",
160
- type: "element",
161
- name: "WebSocketConnector",
162
- }),
163
- ),
164
- undefined,
165
- [
166
- factory.createAsExpression(
167
- factory.createBinaryExpression(
168
- factory.createPropertyAccessExpression(
169
- factory.createIdentifier(connection),
170
- "headers",
171
- ),
172
- factory.createToken(SyntaxKind.QuestionQuestionToken),
173
- factory.createObjectLiteralExpression([], false),
174
- ),
175
- factory.createKeywordTypeNode(SyntaxKind.AnyKeyword),
176
- ),
177
- access("provider"),
178
- ],
179
- ),
180
- ),
181
- factory.createExpressionStatement(
182
- factory.createAwaitExpression(
183
- factory.createCallExpression(
184
- factory.createPropertyAccessExpression(
185
- factory.createIdentifier("connector"),
186
- "connect",
187
- ),
188
- undefined,
189
- [factory.createIdentifier("url")],
190
- ),
191
- ),
192
- ),
193
- local("driver")(
194
- factory.createTypeReferenceNode(
195
- importer.external({
196
- declaration: true,
197
- file: "tgrid",
198
- type: "element",
199
- name: "Driver",
200
- }),
201
- [factory.createTypeReferenceNode(`${route.name}.Listener`)],
202
- ),
203
- )(
204
- factory.createCallExpression(
205
- factory.createPropertyAccessExpression(
206
- factory.createIdentifier("connector"),
207
- "getDriver",
208
- ),
209
- undefined,
210
- undefined,
211
- ),
212
- ),
213
- factory.createReturnStatement(
214
- factory.createObjectLiteralExpression(
215
- [
216
- factory.createShorthandPropertyAssignment("connector"),
217
- factory.createShorthandPropertyAssignment("driver"),
218
- factory.createPropertyAssignment(
219
- factory.createIdentifier("reconnect"),
220
- factory.createArrowFunction(
221
- [factory.createToken(SyntaxKind.AsyncKeyword)],
222
- undefined,
223
- [],
224
- undefined,
225
- factory.createToken(SyntaxKind.EqualsGreaterThanToken),
226
- factory.createAwaitExpression(
227
- factory.createCallExpression(
228
- factory.createPropertyAccessExpression(
229
- factory.createIdentifier("connector"),
230
- factory.createIdentifier("connect"),
231
- ),
232
- undefined,
233
- [factory.createIdentifier("url")],
234
- ),
235
- ),
236
- ),
237
- ),
238
- ],
239
- true,
240
- ),
241
- ),
242
- ];
243
- };
244
- }
245
-
246
- const local = (name: string) => (type: TypeNode) => (expression: Expression) =>
247
- factory.createVariableStatement(
248
- [],
249
- factory.createVariableDeclarationList(
250
- [factory.createVariableDeclaration(name, undefined, type, expression)],
251
- NodeFlags.Const,
252
- ),
253
- );
254
-
255
- const joinPath = (connection: string, caller: Expression) =>
256
- factory.createTemplateExpression(factory.createTemplateHead("", ""), [
257
- factory.createTemplateSpan(
258
- factory.createConditionalExpression(
259
- factory.createCallExpression(
260
- factory.createPropertyAccessExpression(
261
- factory.createPropertyAccessExpression(
262
- factory.createIdentifier(connection),
263
- factory.createIdentifier("host"),
264
- ),
265
- factory.createIdentifier("endsWith"),
266
- ),
267
- undefined,
268
- [factory.createStringLiteral("/")],
269
- ),
270
- factory.createToken(SyntaxKind.QuestionToken),
271
- factory.createCallExpression(
272
- factory.createPropertyAccessExpression(
273
- factory.createPropertyAccessExpression(
274
- factory.createIdentifier(connection),
275
- factory.createIdentifier("host"),
276
- ),
277
- factory.createIdentifier("substring"),
278
- ),
279
- undefined,
280
- [
281
- factory.createNumericLiteral("0"),
282
- factory.createBinaryExpression(
283
- factory.createPropertyAccessExpression(
284
- factory.createPropertyAccessExpression(
285
- factory.createIdentifier(connection),
286
- factory.createIdentifier("host"),
287
- ),
288
- factory.createIdentifier("length"),
289
- ),
290
- factory.createToken(SyntaxKind.MinusToken),
291
- factory.createNumericLiteral("1"),
292
- ),
293
- ],
294
- ),
295
- factory.createToken(SyntaxKind.ColonToken),
296
- factory.createPropertyAccessExpression(
297
- factory.createIdentifier(connection),
298
- factory.createIdentifier("host"),
299
- ),
300
- ),
301
- factory.createTemplateMiddle(""),
302
- ),
303
- factory.createTemplateSpan(caller, factory.createTemplateTail("")),
304
- ]);
1
+ import {
2
+ type Expression,
3
+ NodeFlags,
4
+ type Statement,
5
+ SyntaxKind,
6
+ type TypeNode,
7
+ factory,
8
+ } from "@ttsc/factory";
9
+ import { IJsDocTagInfo } from "typia";
10
+
11
+ import { IdentifierFactory } from "../../factories/IdentifierFactory";
12
+ import { INestiaProject } from "../../structures/INestiaProject";
13
+ import { ITypedWebSocketRoute } from "../../structures/ITypedWebSocketRoute";
14
+ import { StringUtil } from "../../utils/StringUtil";
15
+ import { FilePrinter } from "./FilePrinter";
16
+ import { ImportDictionary } from "./ImportDictionary";
17
+ import { SdkImportWizard } from "./SdkImportWizard";
18
+ import { SdkWebSocketNamespaceProgrammer } from "./SdkWebSocketNamespaceProgrammer";
19
+ import { SdkWebSocketParameterProgrammer } from "./SdkWebSocketParameterProgrammer";
20
+
21
+ export namespace SdkWebSocketRouteProgrammer {
22
+ export const write =
23
+ (project: INestiaProject) =>
24
+ (importer: ImportDictionary) =>
25
+ (route: ITypedWebSocketRoute): Statement[] => [
26
+ FilePrinter.description(
27
+ writeFunction(project)(importer)(route),
28
+ writeDescription(route),
29
+ ),
30
+ SdkWebSocketNamespaceProgrammer.write(project)(importer)(route),
31
+ ];
32
+
33
+ const writeDescription = (route: ITypedWebSocketRoute): string => {
34
+ // MAIN DESCRIPTION
35
+ const comments: string[] = route.description
36
+ ? route.description.split("\n")
37
+ : [];
38
+
39
+ // COMMENT TAGS
40
+ const tags: IJsDocTagInfo[] = route.jsDocTags.filter(
41
+ (tag) =>
42
+ tag.name !== "param" ||
43
+ [...route.pathParameters, ...(route.query ? [route.query] : [])]
44
+ .filter((p) => p.category === "param" || p.category === "query")
45
+ .some((p) => p.name === tag.text?.[0]?.text),
46
+ );
47
+ if (tags.length !== 0) {
48
+ const content: string[] = tags.map((t) =>
49
+ t.text?.length
50
+ ? `@${t.name} ${t.text.map((e) => e.text).join("")}`
51
+ : `@${t.name}`,
52
+ );
53
+ comments.push("", ...new Set(content));
54
+ }
55
+
56
+ // POSTFIX
57
+ if (!!comments.length) comments.push("");
58
+ comments.push(
59
+ `@controller ${route.controller.class.name}.${route.name}`,
60
+ `@path ${route.path}`,
61
+ `@nestia Generated by Nestia - https://github.com/samchon/nestia`,
62
+ );
63
+ return comments.join("\n");
64
+ };
65
+
66
+ const writeFunction =
67
+ (project: INestiaProject) =>
68
+ (importer: ImportDictionary) =>
69
+ (route: ITypedWebSocketRoute): Statement => {
70
+ const connection: string = StringUtil.escapeDuplicate([route.name])(
71
+ "connection",
72
+ );
73
+ return factory.createFunctionDeclaration(
74
+ [
75
+ factory.createModifier(SyntaxKind.ExportKeyword),
76
+ factory.createModifier(SyntaxKind.AsyncKeyword),
77
+ ],
78
+ undefined,
79
+ route.name,
80
+ undefined,
81
+ [
82
+ IdentifierFactory.parameter(
83
+ connection,
84
+ factory.createTypeReferenceNode(
85
+ SdkImportWizard.IConnection(importer),
86
+ [factory.createTypeReferenceNode(`${route.name}.Header`)],
87
+ ),
88
+ ),
89
+ ...SdkWebSocketParameterProgrammer.getParameterDeclarations({
90
+ project,
91
+ route,
92
+ provider: true,
93
+ prefix: true,
94
+ }),
95
+ ],
96
+ factory.createTypeReferenceNode("Promise", [
97
+ factory.createTypeReferenceNode(`${route.name}.Output`),
98
+ ]),
99
+ factory.createBlock(
100
+ writeFunctionBody(project)(importer)(route)(connection),
101
+ true,
102
+ ),
103
+ );
104
+ };
105
+
106
+ const writeFunctionBody =
107
+ (project: INestiaProject) =>
108
+ (importer: ImportDictionary) =>
109
+ (route: ITypedWebSocketRoute) =>
110
+ (connection: string): Statement[] => {
111
+ const access = (key: string) =>
112
+ project.config.keyword === true
113
+ ? factory.createPropertyAccessExpression(
114
+ factory.createIdentifier("props"),
115
+ key,
116
+ )
117
+ : factory.createIdentifier(key);
118
+ return [
119
+ local("url")(factory.createTypeReferenceNode("string"))(
120
+ joinPath(
121
+ connection,
122
+ factory.createCallExpression(
123
+ factory.createPropertyAccessExpression(
124
+ factory.createIdentifier(route.name),
125
+ "path",
126
+ ),
127
+ [],
128
+ project.config.keyword === true &&
129
+ SdkWebSocketParameterProgrammer.isPathEmpty(route) === false
130
+ ? [factory.createIdentifier("props")]
131
+ : SdkWebSocketParameterProgrammer.getEntries({
132
+ project,
133
+ route,
134
+ provider: false,
135
+ prefix: true,
136
+ }).map((p) => factory.createIdentifier(p.key)),
137
+ ),
138
+ ),
139
+ ),
140
+ local("connector")(
141
+ factory.createTypeReferenceNode(
142
+ importer.external({
143
+ declaration: false,
144
+ file: "tgrid",
145
+ type: "element",
146
+ name: "WebSocketConnector",
147
+ }),
148
+ [
149
+ factory.createTypeReferenceNode(`${route.name}.Header`),
150
+ factory.createTypeReferenceNode(`${route.name}.Provider`),
151
+ factory.createTypeReferenceNode(`${route.name}.Listener`),
152
+ ],
153
+ ),
154
+ )(
155
+ factory.createNewExpression(
156
+ factory.createIdentifier(
157
+ importer.external({
158
+ declaration: false,
159
+ file: "tgrid",
160
+ type: "element",
161
+ name: "WebSocketConnector",
162
+ }),
163
+ ),
164
+ undefined,
165
+ [
166
+ factory.createAsExpression(
167
+ factory.createBinaryExpression(
168
+ factory.createPropertyAccessExpression(
169
+ factory.createIdentifier(connection),
170
+ "headers",
171
+ ),
172
+ factory.createToken(SyntaxKind.QuestionQuestionToken),
173
+ factory.createObjectLiteralExpression([], false),
174
+ ),
175
+ factory.createKeywordTypeNode(SyntaxKind.AnyKeyword),
176
+ ),
177
+ access("provider"),
178
+ ],
179
+ ),
180
+ ),
181
+ factory.createExpressionStatement(
182
+ factory.createAwaitExpression(
183
+ factory.createCallExpression(
184
+ factory.createPropertyAccessExpression(
185
+ factory.createIdentifier("connector"),
186
+ "connect",
187
+ ),
188
+ undefined,
189
+ [factory.createIdentifier("url")],
190
+ ),
191
+ ),
192
+ ),
193
+ local("driver")(
194
+ factory.createTypeReferenceNode(
195
+ importer.external({
196
+ declaration: true,
197
+ file: "tgrid",
198
+ type: "element",
199
+ name: "Driver",
200
+ }),
201
+ [factory.createTypeReferenceNode(`${route.name}.Listener`)],
202
+ ),
203
+ )(
204
+ factory.createCallExpression(
205
+ factory.createPropertyAccessExpression(
206
+ factory.createIdentifier("connector"),
207
+ "getDriver",
208
+ ),
209
+ undefined,
210
+ undefined,
211
+ ),
212
+ ),
213
+ factory.createReturnStatement(
214
+ factory.createObjectLiteralExpression(
215
+ [
216
+ factory.createShorthandPropertyAssignment("connector"),
217
+ factory.createShorthandPropertyAssignment("driver"),
218
+ factory.createPropertyAssignment(
219
+ factory.createIdentifier("reconnect"),
220
+ factory.createArrowFunction(
221
+ [factory.createToken(SyntaxKind.AsyncKeyword)],
222
+ undefined,
223
+ [],
224
+ undefined,
225
+ factory.createToken(SyntaxKind.EqualsGreaterThanToken),
226
+ factory.createAwaitExpression(
227
+ factory.createCallExpression(
228
+ factory.createPropertyAccessExpression(
229
+ factory.createIdentifier("connector"),
230
+ factory.createIdentifier("connect"),
231
+ ),
232
+ undefined,
233
+ [factory.createIdentifier("url")],
234
+ ),
235
+ ),
236
+ ),
237
+ ),
238
+ ],
239
+ true,
240
+ ),
241
+ ),
242
+ ];
243
+ };
244
+ }
245
+
246
+ const local = (name: string) => (type: TypeNode) => (expression: Expression) =>
247
+ factory.createVariableStatement(
248
+ [],
249
+ factory.createVariableDeclarationList(
250
+ [factory.createVariableDeclaration(name, undefined, type, expression)],
251
+ NodeFlags.Const,
252
+ ),
253
+ );
254
+
255
+ const joinPath = (connection: string, caller: Expression) =>
256
+ factory.createTemplateExpression(factory.createTemplateHead("", ""), [
257
+ factory.createTemplateSpan(
258
+ factory.createConditionalExpression(
259
+ factory.createCallExpression(
260
+ factory.createPropertyAccessExpression(
261
+ factory.createPropertyAccessExpression(
262
+ factory.createIdentifier(connection),
263
+ factory.createIdentifier("host"),
264
+ ),
265
+ factory.createIdentifier("endsWith"),
266
+ ),
267
+ undefined,
268
+ [factory.createStringLiteral("/")],
269
+ ),
270
+ factory.createToken(SyntaxKind.QuestionToken),
271
+ factory.createCallExpression(
272
+ factory.createPropertyAccessExpression(
273
+ factory.createPropertyAccessExpression(
274
+ factory.createIdentifier(connection),
275
+ factory.createIdentifier("host"),
276
+ ),
277
+ factory.createIdentifier("substring"),
278
+ ),
279
+ undefined,
280
+ [
281
+ factory.createNumericLiteral("0"),
282
+ factory.createBinaryExpression(
283
+ factory.createPropertyAccessExpression(
284
+ factory.createPropertyAccessExpression(
285
+ factory.createIdentifier(connection),
286
+ factory.createIdentifier("host"),
287
+ ),
288
+ factory.createIdentifier("length"),
289
+ ),
290
+ factory.createToken(SyntaxKind.MinusToken),
291
+ factory.createNumericLiteral("1"),
292
+ ),
293
+ ],
294
+ ),
295
+ factory.createToken(SyntaxKind.ColonToken),
296
+ factory.createPropertyAccessExpression(
297
+ factory.createIdentifier(connection),
298
+ factory.createIdentifier("host"),
299
+ ),
300
+ ),
301
+ factory.createTemplateMiddle(""),
302
+ ),
303
+ factory.createTemplateSpan(caller, factory.createTemplateTail("")),
304
+ ]);