@nestia/sdk 13.0.4 → 14.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/assets/bundle/distribute/package.json +2 -2
- package/assets/bundle/distribute/tsconfig.json +15 -105
- package/lib/INestiaConfig.d.ts +19 -10
- package/lib/NestiaSdkApplication.js +58 -27
- package/lib/NestiaSdkApplication.js.map +1 -1
- package/lib/NestiaSwaggerComposer.js +11 -10
- package/lib/NestiaSwaggerComposer.js.map +1 -1
- package/lib/analyses/ConfigAnalyzer.js +4 -4
- package/lib/analyses/ConfigAnalyzer.js.map +1 -1
- package/lib/analyses/ParameterNameAnalyzer.d.ts +20 -0
- package/lib/analyses/ParameterNameAnalyzer.js +48 -0
- package/lib/analyses/ParameterNameAnalyzer.js.map +1 -0
- package/lib/analyses/PathAnalyzer.d.ts +30 -0
- package/lib/analyses/PathAnalyzer.js +108 -16
- package/lib/analyses/PathAnalyzer.js.map +1 -1
- package/lib/analyses/ReflectControllerAnalyzer.js +2 -1
- package/lib/analyses/ReflectControllerAnalyzer.js.map +1 -1
- package/lib/analyses/ReflectHttpOperationAnalyzer.js +7 -7
- package/lib/analyses/ReflectHttpOperationAnalyzer.js.map +1 -1
- package/lib/analyses/ReflectHttpOperationParameterAnalyzer.js +122 -23
- package/lib/analyses/ReflectHttpOperationParameterAnalyzer.js.map +1 -1
- package/lib/analyses/ReflectHttpOperationResponseAnalyzer.js +5 -2
- package/lib/analyses/ReflectHttpOperationResponseAnalyzer.js.map +1 -1
- package/lib/analyses/ReflectMcpOperationAnalyzer.js +5 -2
- package/lib/analyses/ReflectMcpOperationAnalyzer.js.map +1 -1
- package/lib/analyses/ReflectWebSocketOperationAnalyzer.js +6 -3
- package/lib/analyses/ReflectWebSocketOperationAnalyzer.js.map +1 -1
- package/lib/analyses/SecurityAnalyzer.d.ts +10 -0
- package/lib/analyses/SecurityAnalyzer.js +24 -19
- package/lib/analyses/SecurityAnalyzer.js.map +1 -1
- package/lib/analyses/SwaggerExampleAnalyzer.d.ts +15 -0
- package/lib/analyses/SwaggerExampleAnalyzer.js +20 -0
- package/lib/analyses/SwaggerExampleAnalyzer.js.map +1 -0
- package/lib/analyses/TypedHttpRouteAnalyzer.js +30 -21
- package/lib/analyses/TypedHttpRouteAnalyzer.js.map +1 -1
- package/lib/analyses/TypedWebSocketRouteAnalyzer.js +1 -1
- package/lib/analyses/TypedWebSocketRouteAnalyzer.js.map +1 -1
- package/lib/executable/internal/NestiaSdkWatcher.js +3 -3
- package/lib/executable/internal/NestiaSdkWatcher.js.map +1 -1
- package/lib/executable/sdk.js +16 -1
- package/lib/executable/sdk.js.map +1 -1
- package/lib/factories/ExpressionFactory.d.ts +3 -0
- package/lib/factories/ExpressionFactory.js +6 -2
- package/lib/factories/ExpressionFactory.js.map +1 -1
- package/lib/factories/LiteralFactory.js +3 -1
- package/lib/factories/LiteralFactory.js.map +1 -1
- package/lib/generates/SdkGenerator.js +3 -3
- package/lib/generates/SdkGenerator.js.map +1 -1
- package/lib/generates/SwaggerGenerator.js +135 -27
- package/lib/generates/SwaggerGenerator.js.map +1 -1
- package/lib/generates/internal/FilePrinter.d.ts +14 -0
- package/lib/generates/internal/FilePrinter.js +31 -0
- package/lib/generates/internal/FilePrinter.js.map +1 -1
- package/lib/generates/internal/ImportDictionary.d.ts +2 -0
- package/lib/generates/internal/ImportDictionary.js +13 -0
- package/lib/generates/internal/ImportDictionary.js.map +1 -1
- package/lib/generates/internal/SdkAliasCollection.d.ts +2 -1
- package/lib/generates/internal/SdkAliasCollection.js +8 -4
- package/lib/generates/internal/SdkAliasCollection.js.map +1 -1
- package/lib/generates/internal/SdkDistributionComposer.js +72 -14
- package/lib/generates/internal/SdkDistributionComposer.js.map +1 -1
- package/lib/generates/internal/SdkFileProgrammer.js +83 -12
- package/lib/generates/internal/SdkFileProgrammer.js.map +1 -1
- package/lib/generates/internal/SdkHttpFunctionProgrammer.js +21 -23
- package/lib/generates/internal/SdkHttpFunctionProgrammer.js.map +1 -1
- package/lib/generates/internal/SdkHttpNamespaceProgrammer.js +27 -34
- package/lib/generates/internal/SdkHttpNamespaceProgrammer.js.map +1 -1
- package/lib/generates/internal/SdkHttpParameterProgrammer.d.ts +40 -1
- package/lib/generates/internal/SdkHttpParameterProgrammer.js +105 -6
- package/lib/generates/internal/SdkHttpParameterProgrammer.js.map +1 -1
- package/lib/generates/internal/SdkHttpRouteProgrammer.js +16 -32
- package/lib/generates/internal/SdkHttpRouteProgrammer.js.map +1 -1
- package/lib/generates/internal/SdkHttpSimulationProgrammer.js +18 -14
- package/lib/generates/internal/SdkHttpSimulationProgrammer.js.map +1 -1
- package/lib/generates/internal/SdkMcpRouteProgrammer.js +39 -11
- package/lib/generates/internal/SdkMcpRouteProgrammer.js.map +1 -1
- package/lib/generates/internal/SdkPathTemplate.d.ts +21 -0
- package/lib/generates/internal/SdkPathTemplate.js +50 -0
- package/lib/generates/internal/SdkPathTemplate.js.map +1 -0
- package/lib/generates/internal/SdkTypeProgrammer.js +15 -15
- package/lib/generates/internal/SdkTypeProgrammer.js.map +1 -1
- package/lib/generates/internal/SdkTypeTagProgrammer.d.ts +20 -1
- package/lib/generates/internal/SdkTypeTagProgrammer.js +386 -67
- package/lib/generates/internal/SdkTypeTagProgrammer.js.map +1 -1
- package/lib/generates/internal/SdkWebSocketNamespaceProgrammer.js +27 -36
- package/lib/generates/internal/SdkWebSocketNamespaceProgrammer.js.map +1 -1
- package/lib/generates/internal/SdkWebSocketParameterProgrammer.d.ts +35 -1
- package/lib/generates/internal/SdkWebSocketParameterProgrammer.js +72 -5
- package/lib/generates/internal/SdkWebSocketParameterProgrammer.js.map +1 -1
- package/lib/generates/internal/SdkWebSocketRouteProgrammer.js +57 -33
- package/lib/generates/internal/SdkWebSocketRouteProgrammer.js.map +1 -1
- package/lib/generates/internal/SwaggerOperationComposer.js +19 -8
- package/lib/generates/internal/SwaggerOperationComposer.js.map +1 -1
- package/lib/generates/internal/SwaggerOperationParameterComposer.d.ts +1 -1
- package/lib/generates/internal/SwaggerOperationParameterComposer.js +201 -19
- package/lib/generates/internal/SwaggerOperationParameterComposer.js.map +1 -1
- package/lib/generates/internal/SwaggerOperationResponseComposer.d.ts +2 -0
- package/lib/generates/internal/SwaggerOperationResponseComposer.js +39 -7
- package/lib/generates/internal/SwaggerOperationResponseComposer.js.map +1 -1
- package/lib/internal/legacy.d.ts +49 -18
- package/lib/internal/legacy.js +84 -25
- package/lib/internal/legacy.js.map +1 -1
- package/lib/structures/IOperationMetadata.d.ts +22 -0
- package/lib/structures/IReflectHttpOperationException.d.ts +3 -2
- package/lib/structures/IReflectHttpOperationParameter.d.ts +8 -3
- package/lib/structures/IReflectHttpOperationSuccess.d.ts +4 -3
- package/lib/structures/ITypedHttpRoute.d.ts +8 -0
- package/lib/structures/ITypedHttpRouteException.d.ts +3 -1
- package/lib/structures/ITypedHttpRouteParameter.d.ts +3 -1
- package/lib/structures/ITypedHttpRouteSuccess.d.ts +3 -1
- package/lib/structures/ITypedWebSocketRoute.d.ts +8 -0
- package/lib/utils/SourceFinder.d.ts +10 -0
- package/lib/utils/SourceFinder.js +27 -4
- package/lib/utils/SourceFinder.js.map +1 -1
- package/lib/utils/VersioningStrategy.d.ts +13 -1
- package/lib/utils/VersioningStrategy.js +24 -12
- package/lib/utils/VersioningStrategy.js.map +1 -1
- package/native/go.mod +1 -1
- package/native/go.sum +2 -2
- package/native/sdk/sdk_http_rules.go +210 -0
- package/native/sdk/sdk_metadata_json.go +73 -3
- package/native/sdk/sdk_transform.go +801 -49
- package/package.json +8 -8
- package/src/INestiaConfig.ts +19 -10
- package/src/NestiaSdkApplication.ts +63 -34
- package/src/NestiaSwaggerComposer.ts +11 -8
- package/src/analyses/ConfigAnalyzer.ts +3 -3
- package/src/analyses/ParameterNameAnalyzer.ts +51 -0
- package/src/analyses/PathAnalyzer.ts +106 -14
- package/src/analyses/ReflectControllerAnalyzer.ts +2 -1
- package/src/analyses/ReflectHttpOperationAnalyzer.ts +4 -4
- package/src/analyses/ReflectHttpOperationParameterAnalyzer.ts +122 -39
- package/src/analyses/ReflectHttpOperationResponseAnalyzer.ts +6 -7
- package/src/analyses/ReflectMcpOperationAnalyzer.ts +6 -2
- package/src/analyses/ReflectWebSocketOperationAnalyzer.ts +7 -3
- package/src/analyses/SecurityAnalyzer.ts +30 -20
- package/src/analyses/SwaggerExampleAnalyzer.ts +23 -0
- package/src/analyses/TypedHttpRouteAnalyzer.ts +29 -20
- package/src/analyses/TypedWebSocketRouteAnalyzer.ts +1 -0
- package/src/executable/internal/NestiaSdkWatcher.ts +2 -2
- package/src/executable/sdk.ts +24 -1
- package/src/factories/ExpressionFactory.ts +8 -2
- package/src/factories/LiteralFactory.ts +7 -2
- package/src/generates/SdkGenerator.ts +3 -3
- package/src/generates/SwaggerGenerator.ts +173 -32
- package/src/generates/internal/FilePrinter.ts +28 -0
- package/src/generates/internal/ImportDictionary.ts +11 -0
- package/src/generates/internal/SdkAliasCollection.ts +11 -4
- package/src/generates/internal/SdkDistributionComposer.ts +89 -15
- package/src/generates/internal/SdkFileProgrammer.ts +108 -16
- package/src/generates/internal/SdkHttpFunctionProgrammer.ts +28 -30
- package/src/generates/internal/SdkHttpNamespaceProgrammer.ts +34 -64
- package/src/generates/internal/SdkHttpParameterProgrammer.ts +193 -13
- package/src/generates/internal/SdkHttpRouteProgrammer.ts +17 -31
- package/src/generates/internal/SdkHttpSimulationProgrammer.ts +51 -14
- package/src/generates/internal/SdkMcpRouteProgrammer.ts +112 -15
- package/src/generates/internal/SdkPathTemplate.ts +73 -0
- package/src/generates/internal/SdkTypeProgrammer.ts +19 -22
- package/src/generates/internal/SdkTypeTagProgrammer.ts +506 -78
- package/src/generates/internal/SdkWebSocketNamespaceProgrammer.ts +43 -68
- package/src/generates/internal/SdkWebSocketParameterProgrammer.ts +126 -5
- package/src/generates/internal/SdkWebSocketRouteProgrammer.ts +71 -48
- package/src/generates/internal/SwaggerOperationComposer.ts +20 -6
- package/src/generates/internal/SwaggerOperationParameterComposer.ts +279 -30
- package/src/generates/internal/SwaggerOperationResponseComposer.ts +55 -11
- package/src/internal/legacy.ts +114 -26
- package/src/structures/IOperationMetadata.ts +28 -0
- package/src/structures/IReflectHttpOperationException.ts +7 -2
- package/src/structures/IReflectHttpOperationParameter.ts +9 -2
- package/src/structures/IReflectHttpOperationSuccess.ts +8 -3
- package/src/structures/ITypedHttpRoute.ts +8 -0
- package/src/structures/ITypedHttpRouteException.ts +4 -1
- package/src/structures/ITypedHttpRouteParameter.ts +3 -1
- package/src/structures/ITypedHttpRouteSuccess.ts +4 -1
- package/src/structures/ITypedWebSocketRoute.ts +8 -0
- package/src/utils/SourceFinder.ts +25 -4
- package/src/utils/VersioningStrategy.ts +28 -13
- package/lib/validators/HttpHeadersValidator.d.ts +0 -11
- package/lib/validators/HttpHeadersValidator.js +0 -15
- package/lib/validators/HttpHeadersValidator.js.map +0 -1
- package/lib/validators/HttpQueryValidator.d.ts +0 -10
- package/lib/validators/HttpQueryValidator.js +0 -14
- package/lib/validators/HttpQueryValidator.js.map +0 -1
- package/src/validators/HttpHeadersValidator.ts +0 -12
- package/src/validators/HttpQueryValidator.ts +0 -11
|
@@ -12,6 +12,7 @@ import {
|
|
|
12
12
|
import { IdentifierFactory } from "../../factories/IdentifierFactory";
|
|
13
13
|
import { INestiaProject } from "../../structures/INestiaProject";
|
|
14
14
|
import { ITypedMcpRoute } from "../../structures/ITypedMcpRoute";
|
|
15
|
+
import { StringUtil } from "../../utils/StringUtil";
|
|
15
16
|
import { FilePrinter } from "./FilePrinter";
|
|
16
17
|
import { ImportDictionary } from "./ImportDictionary";
|
|
17
18
|
|
|
@@ -39,6 +40,16 @@ export namespace SdkMcpRouteProgrammer {
|
|
|
39
40
|
(_project: INestiaProject) =>
|
|
40
41
|
(importer: ImportDictionary) =>
|
|
41
42
|
(route: ITypedMcpRoute): Node => {
|
|
43
|
+
// The body reads `<route>.METADATA` next to these, so they yield to a
|
|
44
|
+
// tool of the same name, as the HTTP and WebSocket SDKs' own do.
|
|
45
|
+
const own = StringUtil.escapeDuplicate([route.name]);
|
|
46
|
+
const names = {
|
|
47
|
+
client: own("client"),
|
|
48
|
+
args: own("args"),
|
|
49
|
+
raw: own("raw"),
|
|
50
|
+
result: own("result"),
|
|
51
|
+
first: own("first"),
|
|
52
|
+
};
|
|
42
53
|
const clientType = factory.createTypeReferenceNode(
|
|
43
54
|
importer.external({
|
|
44
55
|
declaration: true,
|
|
@@ -75,7 +86,7 @@ export namespace SdkMcpRouteProgrammer {
|
|
|
75
86
|
factory.createParameterDeclaration(
|
|
76
87
|
undefined,
|
|
77
88
|
undefined,
|
|
78
|
-
|
|
89
|
+
names.client,
|
|
79
90
|
undefined,
|
|
80
91
|
clientType,
|
|
81
92
|
undefined,
|
|
@@ -86,7 +97,7 @@ export namespace SdkMcpRouteProgrammer {
|
|
|
86
97
|
factory.createParameterDeclaration(
|
|
87
98
|
undefined,
|
|
88
99
|
undefined,
|
|
89
|
-
|
|
100
|
+
names.args,
|
|
90
101
|
undefined,
|
|
91
102
|
inputRef,
|
|
92
103
|
undefined,
|
|
@@ -110,7 +121,7 @@ export namespace SdkMcpRouteProgrammer {
|
|
|
110
121
|
"arguments",
|
|
111
122
|
factory.createAsExpression(
|
|
112
123
|
factory.createAsExpression(
|
|
113
|
-
factory.createIdentifier(
|
|
124
|
+
factory.createIdentifier(names.args),
|
|
114
125
|
factory.createKeywordTypeNode(SyntaxKind.AnyKeyword),
|
|
115
126
|
),
|
|
116
127
|
factory.createTypeReferenceNode("Record", [
|
|
@@ -128,13 +139,13 @@ export namespace SdkMcpRouteProgrammer {
|
|
|
128
139
|
factory.createVariableDeclarationList(
|
|
129
140
|
[
|
|
130
141
|
factory.createVariableDeclaration(
|
|
131
|
-
|
|
142
|
+
names.raw,
|
|
132
143
|
undefined,
|
|
133
144
|
undefined,
|
|
134
145
|
factory.createAwaitExpression(
|
|
135
146
|
factory.createCallExpression(
|
|
136
147
|
factory.createPropertyAccessExpression(
|
|
137
|
-
factory.createIdentifier(
|
|
148
|
+
factory.createIdentifier(names.client),
|
|
138
149
|
"callTool",
|
|
139
150
|
),
|
|
140
151
|
undefined,
|
|
@@ -165,7 +176,7 @@ export namespace SdkMcpRouteProgrammer {
|
|
|
165
176
|
),
|
|
166
177
|
undefined,
|
|
167
178
|
[
|
|
168
|
-
factory.createIdentifier(
|
|
179
|
+
factory.createIdentifier(names.raw),
|
|
169
180
|
factory.createStringLiteral("toolResult"),
|
|
170
181
|
],
|
|
171
182
|
),
|
|
@@ -179,11 +190,11 @@ export namespace SdkMcpRouteProgrammer {
|
|
|
179
190
|
factory.createVariableDeclarationList(
|
|
180
191
|
[
|
|
181
192
|
factory.createVariableDeclaration(
|
|
182
|
-
|
|
193
|
+
names.result,
|
|
183
194
|
undefined,
|
|
184
195
|
factory.createTypeReferenceNode(callToolResultTypeName),
|
|
185
196
|
factory.createAsExpression(
|
|
186
|
-
factory.createIdentifier(
|
|
197
|
+
factory.createIdentifier(names.raw),
|
|
187
198
|
factory.createTypeReferenceNode(callToolResultTypeName),
|
|
188
199
|
),
|
|
189
200
|
),
|
|
@@ -194,13 +205,13 @@ export namespace SdkMcpRouteProgrammer {
|
|
|
194
205
|
factory.createIfStatement(
|
|
195
206
|
factory.createBinaryExpression(
|
|
196
207
|
factory.createPropertyAccessExpression(
|
|
197
|
-
factory.createIdentifier(
|
|
208
|
+
factory.createIdentifier(names.result),
|
|
198
209
|
"isError",
|
|
199
210
|
),
|
|
200
211
|
factory.createToken(SyntaxKind.EqualsEqualsEqualsToken),
|
|
201
212
|
factory.createTrue(),
|
|
202
213
|
),
|
|
203
|
-
|
|
214
|
+
throwToolErrorWithText(toolNameExpr, names.result),
|
|
204
215
|
),
|
|
205
216
|
...(isVoid
|
|
206
217
|
? [factory.createReturnStatement()]
|
|
@@ -210,13 +221,13 @@ export namespace SdkMcpRouteProgrammer {
|
|
|
210
221
|
factory.createVariableDeclarationList(
|
|
211
222
|
[
|
|
212
223
|
factory.createVariableDeclaration(
|
|
213
|
-
|
|
224
|
+
names.first,
|
|
214
225
|
undefined,
|
|
215
226
|
undefined,
|
|
216
227
|
factory.createCallExpression(
|
|
217
228
|
factory.createPropertyAccessExpression(
|
|
218
229
|
factory.createPropertyAccessExpression(
|
|
219
|
-
factory.createIdentifier(
|
|
230
|
+
factory.createIdentifier(names.result),
|
|
220
231
|
"content",
|
|
221
232
|
),
|
|
222
233
|
"find",
|
|
@@ -249,7 +260,7 @@ export namespace SdkMcpRouteProgrammer {
|
|
|
249
260
|
),
|
|
250
261
|
factory.createIfStatement(
|
|
251
262
|
factory.createBinaryExpression(
|
|
252
|
-
factory.createIdentifier(
|
|
263
|
+
factory.createIdentifier(names.first),
|
|
253
264
|
factory.createToken(SyntaxKind.EqualsEqualsEqualsToken),
|
|
254
265
|
factory.createIdentifier("undefined"),
|
|
255
266
|
),
|
|
@@ -258,7 +269,7 @@ export namespace SdkMcpRouteProgrammer {
|
|
|
258
269
|
factory.createIfStatement(
|
|
259
270
|
factory.createBinaryExpression(
|
|
260
271
|
factory.createPropertyAccessExpression(
|
|
261
|
-
factory.createIdentifier(
|
|
272
|
+
factory.createIdentifier(names.first),
|
|
262
273
|
"type",
|
|
263
274
|
),
|
|
264
275
|
factory.createToken(SyntaxKind.EqualsEqualsEqualsToken),
|
|
@@ -274,7 +285,7 @@ export namespace SdkMcpRouteProgrammer {
|
|
|
274
285
|
undefined,
|
|
275
286
|
[
|
|
276
287
|
factory.createPropertyAccessExpression(
|
|
277
|
-
factory.createIdentifier(
|
|
288
|
+
factory.createIdentifier(names.first),
|
|
278
289
|
"text",
|
|
279
290
|
),
|
|
280
291
|
],
|
|
@@ -423,6 +434,92 @@ export namespace SdkMcpRouteProgrammer {
|
|
|
423
434
|
const isVoidName = (name: string): boolean =>
|
|
424
435
|
name === "void" || name === "undefined";
|
|
425
436
|
|
|
437
|
+
/**
|
|
438
|
+
* The error of a tool that answered `isError`, carrying the text content the
|
|
439
|
+
* tool put its reason in, as `McpAdaptor` does an `HttpException`'s message.
|
|
440
|
+
*/
|
|
441
|
+
const throwToolErrorWithText = (
|
|
442
|
+
toolNameExpr: Expression,
|
|
443
|
+
result: string,
|
|
444
|
+
): Statement => {
|
|
445
|
+
const entry = (): Expression => factory.createIdentifier("entry");
|
|
446
|
+
return factory.createThrowStatement(
|
|
447
|
+
factory.createNewExpression(
|
|
448
|
+
factory.createIdentifier("Error"),
|
|
449
|
+
undefined,
|
|
450
|
+
[
|
|
451
|
+
factory.createTemplateExpression(
|
|
452
|
+
factory.createTemplateHead('MCP tool "'),
|
|
453
|
+
[
|
|
454
|
+
factory.createTemplateSpan(
|
|
455
|
+
toolNameExpr,
|
|
456
|
+
factory.createTemplateMiddle('" returned isError: '),
|
|
457
|
+
),
|
|
458
|
+
factory.createTemplateSpan(
|
|
459
|
+
factory.createCallExpression(
|
|
460
|
+
factory.createPropertyAccessExpression(
|
|
461
|
+
factory.createCallExpression(
|
|
462
|
+
factory.createPropertyAccessExpression(
|
|
463
|
+
factory.createCallExpression(
|
|
464
|
+
factory.createPropertyAccessExpression(
|
|
465
|
+
factory.createPropertyAccessExpression(
|
|
466
|
+
factory.createIdentifier(result),
|
|
467
|
+
"content",
|
|
468
|
+
),
|
|
469
|
+
"filter",
|
|
470
|
+
),
|
|
471
|
+
undefined,
|
|
472
|
+
[
|
|
473
|
+
factory.createArrowFunction(
|
|
474
|
+
undefined,
|
|
475
|
+
undefined,
|
|
476
|
+
[IdentifierFactory.parameter("entry")],
|
|
477
|
+
undefined,
|
|
478
|
+
undefined,
|
|
479
|
+
factory.createBinaryExpression(
|
|
480
|
+
factory.createPropertyAccessExpression(
|
|
481
|
+
entry(),
|
|
482
|
+
"type",
|
|
483
|
+
),
|
|
484
|
+
factory.createToken(
|
|
485
|
+
SyntaxKind.EqualsEqualsEqualsToken,
|
|
486
|
+
),
|
|
487
|
+
factory.createStringLiteral("text"),
|
|
488
|
+
),
|
|
489
|
+
),
|
|
490
|
+
],
|
|
491
|
+
),
|
|
492
|
+
"map",
|
|
493
|
+
),
|
|
494
|
+
undefined,
|
|
495
|
+
[
|
|
496
|
+
factory.createArrowFunction(
|
|
497
|
+
undefined,
|
|
498
|
+
undefined,
|
|
499
|
+
[IdentifierFactory.parameter("entry")],
|
|
500
|
+
undefined,
|
|
501
|
+
undefined,
|
|
502
|
+
factory.createPropertyAccessExpression(
|
|
503
|
+
entry(),
|
|
504
|
+
"text",
|
|
505
|
+
),
|
|
506
|
+
),
|
|
507
|
+
],
|
|
508
|
+
),
|
|
509
|
+
"join",
|
|
510
|
+
),
|
|
511
|
+
undefined,
|
|
512
|
+
[factory.createStringLiteral("\n")],
|
|
513
|
+
),
|
|
514
|
+
factory.createTemplateTail(""),
|
|
515
|
+
),
|
|
516
|
+
],
|
|
517
|
+
),
|
|
518
|
+
],
|
|
519
|
+
),
|
|
520
|
+
);
|
|
521
|
+
};
|
|
522
|
+
|
|
426
523
|
const throwToolError = (
|
|
427
524
|
toolNameExpr: Expression,
|
|
428
525
|
suffix: string,
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import { type Expression, factory } from "@ttsc/factory";
|
|
2
|
+
|
|
3
|
+
import { PathAnalyzer } from "../../analyses/PathAnalyzer";
|
|
4
|
+
import { IdentifierFactory } from "../../factories/IdentifierFactory";
|
|
5
|
+
import { ImportDictionary } from "./ImportDictionary";
|
|
6
|
+
|
|
7
|
+
export namespace SdkPathTemplate {
|
|
8
|
+
/**
|
|
9
|
+
* The expression an SDK function builds its route's path with: the literal
|
|
10
|
+
* text of the path, each parameter filled in by `PathParameter.encode()` of
|
|
11
|
+
* `@nestia/fetcher` with the value `argument` names for it: URI-encoded, or
|
|
12
|
+
* `"null"` when nullish, and refused when it is a dot segment (`.`, `..`) the
|
|
13
|
+
* URL would resolve away.
|
|
14
|
+
*
|
|
15
|
+
* The positions come from {@link PathAnalyzer.segments}, as the server's
|
|
16
|
+
* router reads the path, so a parameter with literal text beside it in its
|
|
17
|
+
* segment, such as `/files/:id.json` or `/range/:from-:to`, is filled in
|
|
18
|
+
* where it stands.
|
|
19
|
+
*/
|
|
20
|
+
export const compose = (props: {
|
|
21
|
+
importer: ImportDictionary;
|
|
22
|
+
path: string;
|
|
23
|
+
argument: (name: string) => Expression;
|
|
24
|
+
}): Expression => {
|
|
25
|
+
const segments: PathAnalyzer.ISegment[] | null = PathAnalyzer.segments(
|
|
26
|
+
props.path,
|
|
27
|
+
);
|
|
28
|
+
if (segments === null) return factory.createStringLiteral(props.path);
|
|
29
|
+
// the literal text as the router reads it, an escaped `\:` unescaped
|
|
30
|
+
else if (segments.every((segment) => segment.type === "literal"))
|
|
31
|
+
return factory.createStringLiteral(
|
|
32
|
+
segments
|
|
33
|
+
.map((segment) => (segment.type === "literal" ? segment.value : ""))
|
|
34
|
+
.join(""),
|
|
35
|
+
);
|
|
36
|
+
|
|
37
|
+
// a template holds a literal between every two expressions
|
|
38
|
+
const literals: string[] = [""];
|
|
39
|
+
const parameters: string[] = [];
|
|
40
|
+
for (const segment of segments)
|
|
41
|
+
if (segment.type === "literal")
|
|
42
|
+
literals[literals.length - 1] += segment.value;
|
|
43
|
+
else {
|
|
44
|
+
parameters.push(segment.name);
|
|
45
|
+
literals.push("");
|
|
46
|
+
}
|
|
47
|
+
return factory.createTemplateExpression(
|
|
48
|
+
factory.createTemplateHead(literals[0]!),
|
|
49
|
+
parameters.map((name, i) =>
|
|
50
|
+
factory.createTemplateSpan(
|
|
51
|
+
factory.createCallExpression(
|
|
52
|
+
IdentifierFactory.access(
|
|
53
|
+
factory.createIdentifier(
|
|
54
|
+
props.importer.external({
|
|
55
|
+
declaration: false,
|
|
56
|
+
file: "@nestia/fetcher",
|
|
57
|
+
type: "element",
|
|
58
|
+
name: "PathParameter",
|
|
59
|
+
}),
|
|
60
|
+
),
|
|
61
|
+
"encode",
|
|
62
|
+
),
|
|
63
|
+
undefined,
|
|
64
|
+
[factory.createStringLiteral(name), props.argument(name)],
|
|
65
|
+
),
|
|
66
|
+
(i !== parameters.length - 1
|
|
67
|
+
? factory.createTemplateMiddle
|
|
68
|
+
: factory.createTemplateTail)(literals[i + 1]!),
|
|
69
|
+
),
|
|
70
|
+
),
|
|
71
|
+
);
|
|
72
|
+
};
|
|
73
|
+
}
|
|
@@ -3,6 +3,7 @@ import { NamingConvention } from "@typia/utils";
|
|
|
3
3
|
import { IJsDocTagInfo, IMetadataTypeTag } from "typia";
|
|
4
4
|
|
|
5
5
|
import { ExpressionFactory } from "../../factories/ExpressionFactory";
|
|
6
|
+
import { LiteralFactory } from "../../factories/LiteralFactory";
|
|
6
7
|
import { TypeFactory } from "../../factories/TypeFactory";
|
|
7
8
|
import {
|
|
8
9
|
MetadataAliasType,
|
|
@@ -14,6 +15,7 @@ import {
|
|
|
14
15
|
MetadataProperty,
|
|
15
16
|
MetadataSchema,
|
|
16
17
|
MetadataTuple,
|
|
18
|
+
decodeMetadataValue,
|
|
17
19
|
isRequiredOf,
|
|
18
20
|
isSoleLiteralOf,
|
|
19
21
|
sizeOf,
|
|
@@ -43,7 +45,7 @@ export namespace SdkTypeProgrammer {
|
|
|
43
45
|
|
|
44
46
|
// ATOMIC TYPES
|
|
45
47
|
for (const c of meta.constants)
|
|
46
|
-
for (const value of c.values) union.push(write_constant(value));
|
|
48
|
+
for (const value of c.values) union.push(write_constant(c.type, value));
|
|
47
49
|
for (const tpl of meta.templates)
|
|
48
50
|
union.push(write_template(project)(importer)(tpl.row ?? tpl));
|
|
49
51
|
for (const atom of meta.atomics) union.push(write_atomic(importer)(atom));
|
|
@@ -106,10 +108,7 @@ export namespace SdkTypeProgrammer {
|
|
|
106
108
|
)
|
|
107
109
|
return factory.createIntersectionTypeNode([
|
|
108
110
|
TypeFactory.keyword("string"),
|
|
109
|
-
SdkTypeTagProgrammer.
|
|
110
|
-
name: "Format",
|
|
111
|
-
value: "date-time",
|
|
112
|
-
} as IMetadataTypeTag),
|
|
111
|
+
SdkTypeTagProgrammer.writePredefined(importer, "Format", "date-time"),
|
|
113
112
|
]);
|
|
114
113
|
return write(project)(importer)(meta.returns, true);
|
|
115
114
|
};
|
|
@@ -117,26 +116,24 @@ export namespace SdkTypeProgrammer {
|
|
|
117
116
|
/* -----------------------------------------------------------
|
|
118
117
|
ATOMICS
|
|
119
118
|
----------------------------------------------------------- */
|
|
120
|
-
const write_constant = (
|
|
121
|
-
|
|
119
|
+
const write_constant = (
|
|
120
|
+
type: string,
|
|
121
|
+
constant: MetadataConstantValue,
|
|
122
|
+
): TypeNode => {
|
|
123
|
+
const value: unknown = decodeMetadataValue(type, constant.value);
|
|
124
|
+
if (typeof value === "boolean")
|
|
122
125
|
return factory.createLiteralTypeNode(
|
|
123
|
-
value
|
|
124
|
-
);
|
|
125
|
-
else if (typeof value.value === "bigint")
|
|
126
|
-
return factory.createLiteralTypeNode(
|
|
127
|
-
value.value < BigInt(0)
|
|
128
|
-
? factory.createPrefixUnaryExpression(
|
|
129
|
-
SyntaxKind.MinusToken,
|
|
130
|
-
factory.createBigIntLiteral((-value.value).toString()),
|
|
131
|
-
)
|
|
132
|
-
: factory.createBigIntLiteral(value.value.toString()),
|
|
133
|
-
);
|
|
134
|
-
else if (typeof value.value === "number")
|
|
135
|
-
return factory.createLiteralTypeNode(
|
|
136
|
-
ExpressionFactory.number(value.value),
|
|
126
|
+
value ? factory.createTrue() : factory.createFalse(),
|
|
137
127
|
);
|
|
128
|
+
else if (typeof value === "bigint")
|
|
129
|
+
return factory.createLiteralTypeNode(LiteralFactory.write(value) as any);
|
|
130
|
+
else if (typeof value === "number")
|
|
131
|
+
// NaN is the one number with no literal type
|
|
132
|
+
return Number.isNaN(value)
|
|
133
|
+
? TypeFactory.keyword("number")
|
|
134
|
+
: factory.createLiteralTypeNode(ExpressionFactory.number(value));
|
|
138
135
|
return factory.createLiteralTypeNode(
|
|
139
|
-
factory.createStringLiteral(value
|
|
136
|
+
factory.createStringLiteral(value as string),
|
|
140
137
|
);
|
|
141
138
|
};
|
|
142
139
|
|