@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
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { type Node, factory } from "@ttsc/factory";
|
|
1
|
+
import { type Node, SyntaxKind, factory } from "@ttsc/factory";
|
|
2
2
|
import fs from "fs";
|
|
3
3
|
|
|
4
4
|
import { INestiaProject } from "../../structures/INestiaProject";
|
|
@@ -7,6 +7,7 @@ import { ITypedHttpRoute } from "../../structures/ITypedHttpRoute";
|
|
|
7
7
|
import { ITypedMcpRoute } from "../../structures/ITypedMcpRoute";
|
|
8
8
|
import { ITypedWebSocketRoute } from "../../structures/ITypedWebSocketRoute";
|
|
9
9
|
import { MapUtil } from "../../utils/MapUtil";
|
|
10
|
+
import { StringUtil } from "../../utils/StringUtil";
|
|
10
11
|
import { FilePrinter } from "./FilePrinter";
|
|
11
12
|
import { ImportDictionary } from "./ImportDictionary";
|
|
12
13
|
import { SdkHttpRouteProgrammer } from "./SdkHttpRouteProgrammer";
|
|
@@ -70,22 +71,75 @@ export namespace SdkFileProgrammer {
|
|
|
70
71
|
statements.push(FilePrinter.enter());
|
|
71
72
|
|
|
72
73
|
// ITERATE ROUTES
|
|
73
|
-
const
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
directory.routes.forEach((route, i) => {
|
|
77
|
-
if (!(project.config.clone === true && route.protocol === "http"))
|
|
78
|
-
importer.declarations(route.imports);
|
|
79
|
-
statements.push(
|
|
80
|
-
...(route.protocol === "http"
|
|
81
|
-
? SdkHttpRouteProgrammer.write(project)(importer)(route)
|
|
82
|
-
: route.protocol === "websocket"
|
|
83
|
-
? SdkWebSocketRouteProgrammer.write(project)(importer)(route)
|
|
84
|
-
: SdkMcpRouteProgrammer.write(project)(importer)(route)),
|
|
74
|
+
const write = (locals: Map<AnyRoute, string>) => {
|
|
75
|
+
const importer: ImportDictionary = new ImportDictionary(
|
|
76
|
+
`${outDir}/index.ts`,
|
|
85
77
|
);
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
78
|
+
const output: Node[] = [];
|
|
79
|
+
directory.routes.forEach((route, i) => {
|
|
80
|
+
if (!(project.config.clone === true && route.protocol === "http"))
|
|
81
|
+
importer.declarations(route.imports);
|
|
82
|
+
const local: string | undefined = locals.get(route);
|
|
83
|
+
const target: AnyRoute =
|
|
84
|
+
local === undefined ? route : { ...route, name: local };
|
|
85
|
+
const written: Node[] =
|
|
86
|
+
target.protocol === "http"
|
|
87
|
+
? SdkHttpRouteProgrammer.write(project)(importer)(target)
|
|
88
|
+
: target.protocol === "websocket"
|
|
89
|
+
? SdkWebSocketRouteProgrammer.write(project)(importer)(target)
|
|
90
|
+
: SdkMcpRouteProgrammer.write(project)(importer)(target);
|
|
91
|
+
if (local !== undefined) {
|
|
92
|
+
written.forEach(unexport);
|
|
93
|
+
written.push(
|
|
94
|
+
factory.createExportDeclaration(
|
|
95
|
+
undefined,
|
|
96
|
+
false,
|
|
97
|
+
factory.createNamedExports([
|
|
98
|
+
factory.createExportSpecifier(false, local, route.name),
|
|
99
|
+
]),
|
|
100
|
+
undefined,
|
|
101
|
+
),
|
|
102
|
+
);
|
|
103
|
+
}
|
|
104
|
+
output.push(...written);
|
|
105
|
+
if (i !== directory.routes.length - 1)
|
|
106
|
+
output.push(FilePrinter.enter());
|
|
107
|
+
});
|
|
108
|
+
return { importer, statements: output };
|
|
109
|
+
};
|
|
110
|
+
|
|
111
|
+
// A route's function and namespace are declared in the module scope,
|
|
112
|
+
// where the file's imports and the globals its bodies reference live
|
|
113
|
+
// too. A route named like one of them shadows it for the whole file, or
|
|
114
|
+
// conflicts with the import, so the SDK would not compile (#1647); a
|
|
115
|
+
// method named `tags` whose path parameter is typed with `tags.Format`
|
|
116
|
+
// is enough. Its public name cannot change, so it is declared under a
|
|
117
|
+
// local one and exported as itself.
|
|
118
|
+
let file = write(new Map());
|
|
119
|
+
const scope: Set<string> = new Set([
|
|
120
|
+
...file.importer.locals(),
|
|
121
|
+
...MODULE_GLOBALS,
|
|
122
|
+
]);
|
|
123
|
+
const shadowing: AnyRoute[] = directory.routes.filter((r) =>
|
|
124
|
+
scope.has(r.name),
|
|
125
|
+
);
|
|
126
|
+
if (shadowing.length !== 0) {
|
|
127
|
+
// each local name distinct from the scope, the routes, and the other
|
|
128
|
+
// locals
|
|
129
|
+
const taken: string[] = [
|
|
130
|
+
...scope,
|
|
131
|
+
...directory.routes.map((r) => r.name),
|
|
132
|
+
];
|
|
133
|
+
const locals: Map<AnyRoute, string> = new Map();
|
|
134
|
+
for (const route of shadowing) {
|
|
135
|
+
const local: string = StringUtil.escapeDuplicate(taken)(route.name);
|
|
136
|
+
taken.push(local);
|
|
137
|
+
locals.set(route, local);
|
|
138
|
+
}
|
|
139
|
+
file = write(locals);
|
|
140
|
+
}
|
|
141
|
+
const importer: ImportDictionary = file.importer;
|
|
142
|
+
statements.push(...file.statements);
|
|
89
143
|
|
|
90
144
|
// FINALIZE THE CONTENT
|
|
91
145
|
if (directory.routes.length !== 0)
|
|
@@ -109,3 +163,41 @@ export namespace SdkFileProgrammer {
|
|
|
109
163
|
});
|
|
110
164
|
};
|
|
111
165
|
}
|
|
166
|
+
|
|
167
|
+
type AnyRoute = ITypedHttpRoute | ITypedWebSocketRoute | ITypedMcpRoute;
|
|
168
|
+
|
|
169
|
+
/**
|
|
170
|
+
* Globals the generated route bodies reference, and names TypeScript reserves
|
|
171
|
+
* in a module's top-level scope: `Promise` in one with async functions, and
|
|
172
|
+
* `require` and `exports` in a CommonJS one.
|
|
173
|
+
*/
|
|
174
|
+
const MODULE_GLOBALS: string[] = [
|
|
175
|
+
"Array",
|
|
176
|
+
"Error",
|
|
177
|
+
"JSON",
|
|
178
|
+
"Object",
|
|
179
|
+
"Promise",
|
|
180
|
+
"ReadableStream",
|
|
181
|
+
"String",
|
|
182
|
+
"URLSearchParams",
|
|
183
|
+
"encodeURIComponent",
|
|
184
|
+
"exports",
|
|
185
|
+
"require",
|
|
186
|
+
"undefined",
|
|
187
|
+
];
|
|
188
|
+
|
|
189
|
+
/** Drops the `export` modifier of a route's function or namespace. */
|
|
190
|
+
const unexport = (node: Node): void => {
|
|
191
|
+
const declaration = node as {
|
|
192
|
+
kind: string;
|
|
193
|
+
modifiers?: Array<{ kind: string; token?: string }>;
|
|
194
|
+
};
|
|
195
|
+
if (
|
|
196
|
+
(declaration.kind === "FunctionDeclaration" ||
|
|
197
|
+
declaration.kind === "ModuleDeclaration") &&
|
|
198
|
+
declaration.modifiers !== undefined
|
|
199
|
+
)
|
|
200
|
+
declaration.modifiers = declaration.modifiers.filter(
|
|
201
|
+
(m) => m.token !== SyntaxKind.ExportKeyword,
|
|
202
|
+
);
|
|
203
|
+
};
|
|
@@ -15,7 +15,6 @@ import { TypeFactory } from "../../factories/TypeFactory";
|
|
|
15
15
|
import { sizeOf } from "../../internal/legacy";
|
|
16
16
|
import { INestiaProject } from "../../structures/INestiaProject";
|
|
17
17
|
import { ITypedHttpRoute } from "../../structures/ITypedHttpRoute";
|
|
18
|
-
import { StringUtil } from "../../utils/StringUtil";
|
|
19
18
|
import { ImportDictionary } from "./ImportDictionary";
|
|
20
19
|
import { SdkAliasCollection } from "./SdkAliasCollection";
|
|
21
20
|
import { SdkHttpParameterProgrammer } from "./SdkHttpParameterProgrammer";
|
|
@@ -26,6 +25,8 @@ export namespace SdkHttpFunctionProgrammer {
|
|
|
26
25
|
(project: INestiaProject) =>
|
|
27
26
|
(importer: ImportDictionary) =>
|
|
28
27
|
(route: ITypedHttpRoute): Node => {
|
|
28
|
+
const names: SdkHttpParameterProgrammer.INames =
|
|
29
|
+
SdkHttpParameterProgrammer.getNames({ project, route });
|
|
29
30
|
return factory.createFunctionDeclaration(
|
|
30
31
|
[
|
|
31
32
|
factory.createModifier(SyntaxKind.ExportKeyword),
|
|
@@ -36,7 +37,7 @@ export namespace SdkHttpFunctionProgrammer {
|
|
|
36
37
|
undefined,
|
|
37
38
|
[
|
|
38
39
|
IdentifierFactory.parameter(
|
|
39
|
-
|
|
40
|
+
names.connection,
|
|
40
41
|
factory.createTypeReferenceNode(
|
|
41
42
|
SdkImportWizard.IConnection(importer),
|
|
42
43
|
route.headerObject !== null
|
|
@@ -59,21 +60,15 @@ export namespace SdkHttpFunctionProgrammer {
|
|
|
59
60
|
? factory.createTypeReferenceNode(`${route.name}.Output`)
|
|
60
61
|
: factory.createTypeReferenceNode("void"),
|
|
61
62
|
]),
|
|
62
|
-
factory.createBlock(writeBody(project)(importer)(route), true),
|
|
63
|
+
factory.createBlock(writeBody(project)(importer)(route)(names), true),
|
|
63
64
|
);
|
|
64
65
|
};
|
|
65
66
|
|
|
66
67
|
const writeBody =
|
|
67
68
|
(project: INestiaProject) =>
|
|
68
69
|
(importer: ImportDictionary) =>
|
|
69
|
-
(route: ITypedHttpRoute)
|
|
70
|
-
|
|
71
|
-
project.config.keyword === true
|
|
72
|
-
? factory.createPropertyAccessExpression(
|
|
73
|
-
factory.createIdentifier("props"),
|
|
74
|
-
name,
|
|
75
|
-
)
|
|
76
|
-
: factory.createIdentifier(name);
|
|
70
|
+
(route: ITypedHttpRoute) =>
|
|
71
|
+
(names: SdkHttpParameterProgrammer.INames): Statement[] => {
|
|
77
72
|
const fetch = () =>
|
|
78
73
|
factory.createCallExpression(
|
|
79
74
|
IdentifierFactory.access(
|
|
@@ -95,7 +90,7 @@ export namespace SdkHttpFunctionProgrammer {
|
|
|
95
90
|
? factory.createObjectLiteralExpression(
|
|
96
91
|
[
|
|
97
92
|
factory.createSpreadAssignment(
|
|
98
|
-
factory.createIdentifier(
|
|
93
|
+
factory.createIdentifier(names.connection),
|
|
99
94
|
),
|
|
100
95
|
factory.createPropertyAssignment(
|
|
101
96
|
"headers",
|
|
@@ -103,7 +98,7 @@ export namespace SdkHttpFunctionProgrammer {
|
|
|
103
98
|
[
|
|
104
99
|
factory.createSpreadAssignment(
|
|
105
100
|
IdentifierFactory.access(
|
|
106
|
-
factory.createIdentifier(
|
|
101
|
+
factory.createIdentifier(names.connection),
|
|
107
102
|
"headers",
|
|
108
103
|
),
|
|
109
104
|
),
|
|
@@ -120,7 +115,7 @@ export namespace SdkHttpFunctionProgrammer {
|
|
|
120
115
|
],
|
|
121
116
|
true,
|
|
122
117
|
)
|
|
123
|
-
: factory.createIdentifier(
|
|
118
|
+
: factory.createIdentifier(names.connection),
|
|
124
119
|
factory.createObjectLiteralExpression(
|
|
125
120
|
[
|
|
126
121
|
factory.createSpreadAssignment(
|
|
@@ -157,7 +152,7 @@ export namespace SdkHttpFunctionProgrammer {
|
|
|
157
152
|
],
|
|
158
153
|
true,
|
|
159
154
|
),
|
|
160
|
-
...(route.body ? [access(route.body
|
|
155
|
+
...(route.body ? [names.access(route.body)] : []),
|
|
161
156
|
...(project.config.json &&
|
|
162
157
|
route.body !== null &&
|
|
163
158
|
(route.body.contentType === "application/json" ||
|
|
@@ -171,14 +166,17 @@ export namespace SdkHttpFunctionProgrammer {
|
|
|
171
166
|
? factory.createConditionalExpression(
|
|
172
167
|
factory.createStrictEquality(
|
|
173
168
|
factory.createTrue(),
|
|
174
|
-
|
|
169
|
+
IdentifierFactory.access(
|
|
170
|
+
factory.createIdentifier(names.connection),
|
|
171
|
+
"simulate",
|
|
172
|
+
),
|
|
175
173
|
),
|
|
176
174
|
undefined,
|
|
177
175
|
factory.createCallExpression(
|
|
178
176
|
factory.createIdentifier(`${route.name}.simulate`),
|
|
179
177
|
[],
|
|
180
178
|
[
|
|
181
|
-
factory.createIdentifier(
|
|
179
|
+
factory.createIdentifier(names.connection),
|
|
182
180
|
...(SdkHttpParameterProgrammer.getArguments({
|
|
183
181
|
project,
|
|
184
182
|
route,
|
|
@@ -201,15 +199,15 @@ export namespace SdkHttpFunctionProgrammer {
|
|
|
201
199
|
factory.createIdentifier(SdkImportWizard.typia(importer)),
|
|
202
200
|
"assert",
|
|
203
201
|
),
|
|
204
|
-
[factory.createTypeQueryNode(access(p
|
|
205
|
-
[access(p
|
|
202
|
+
[factory.createTypeQueryNode(names.access(p) as EntityName)],
|
|
203
|
+
[names.access(p)],
|
|
206
204
|
),
|
|
207
205
|
),
|
|
208
206
|
)
|
|
209
207
|
: []),
|
|
210
208
|
...(route.success.setHeaders.length === 0
|
|
211
209
|
? [factory.createReturnStatement(output(false))]
|
|
212
|
-
: writeSetHeaders(project)(importer)(route)(output(true))),
|
|
210
|
+
: writeSetHeaders(project)(importer)(route)(names)(output(true))),
|
|
213
211
|
];
|
|
214
212
|
};
|
|
215
213
|
|
|
@@ -217,16 +215,12 @@ export namespace SdkHttpFunctionProgrammer {
|
|
|
217
215
|
(project: INestiaProject) =>
|
|
218
216
|
(importer: ImportDictionary) =>
|
|
219
217
|
(route: ITypedHttpRoute) =>
|
|
218
|
+
(names: SdkHttpParameterProgrammer.INames) =>
|
|
220
219
|
(condition: Expression): Statement[] => {
|
|
221
220
|
const accessor = (x: string) => (y: string) =>
|
|
222
221
|
x[0] === "[" ? `${x}${y}` : `${x}.${y}`;
|
|
223
|
-
const output: string =
|
|
224
|
-
|
|
225
|
-
...SdkHttpParameterProgrammer.getSignificant(route, true).map(
|
|
226
|
-
(p) => p.name,
|
|
227
|
-
),
|
|
228
|
-
])("output");
|
|
229
|
-
const headers: string = accessor("connection")("headers");
|
|
222
|
+
const output: string = names.output;
|
|
223
|
+
const headers: string = accessor(names.connection)("headers");
|
|
230
224
|
const data: string = project.config.propagate
|
|
231
225
|
? accessor(output)("data")
|
|
232
226
|
: output;
|
|
@@ -248,9 +242,13 @@ export namespace SdkHttpFunctionProgrammer {
|
|
|
248
242
|
],
|
|
249
243
|
)
|
|
250
244
|
: factory.createBinaryExpression(
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
245
|
+
// a target is a header name, which usually is no identifier
|
|
246
|
+
tuple.target !== undefined
|
|
247
|
+
? IdentifierFactory.access(
|
|
248
|
+
factory.createIdentifier(headers),
|
|
249
|
+
tuple.target,
|
|
250
|
+
)
|
|
251
|
+
: factory.createIdentifier(accessor(headers)(tuple.source)),
|
|
254
252
|
factory.createToken(SyntaxKind.EqualsToken),
|
|
255
253
|
factory.createIdentifier(accessor(data)(tuple.source)),
|
|
256
254
|
),
|
|
@@ -24,6 +24,7 @@ import { SdkAliasCollection } from "./SdkAliasCollection";
|
|
|
24
24
|
import { SdkHttpParameterProgrammer } from "./SdkHttpParameterProgrammer";
|
|
25
25
|
import { SdkHttpSimulationProgrammer } from "./SdkHttpSimulationProgrammer";
|
|
26
26
|
import { SdkImportWizard } from "./SdkImportWizard";
|
|
27
|
+
import { SdkPathTemplate } from "./SdkPathTemplate";
|
|
27
28
|
|
|
28
29
|
export namespace SdkHttpNamespaceProgrammer {
|
|
29
30
|
export const write =
|
|
@@ -210,59 +211,28 @@ export namespace SdkHttpNamespaceProgrammer {
|
|
|
210
211
|
false,
|
|
211
212
|
);
|
|
212
213
|
if (parameters.length === 0)
|
|
213
|
-
return out(
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
const split: string[] = route.path.split(":");
|
|
219
|
-
if (split.length === 1) return factory.createStringLiteral(route.path);
|
|
220
|
-
return factory.createTemplateExpression(
|
|
221
|
-
factory.createTemplateHead(split[0]!),
|
|
222
|
-
split.slice(1).map((s, i, arr) => {
|
|
223
|
-
const name: string = s.split("/")[0]!;
|
|
224
|
-
return factory.createTemplateSpan(
|
|
225
|
-
factory.createCallExpression(
|
|
226
|
-
factory.createIdentifier("encodeURIComponent"),
|
|
227
|
-
undefined,
|
|
228
|
-
[
|
|
229
|
-
factory.createBinaryExpression(
|
|
230
|
-
factory.createCallChain(
|
|
231
|
-
factory.createPropertyAccessChain(
|
|
232
|
-
factory.createIdentifier(
|
|
233
|
-
access(
|
|
234
|
-
route.pathParameters.find((p) => p.field === name)!
|
|
235
|
-
.name,
|
|
236
|
-
),
|
|
237
|
-
),
|
|
238
|
-
factory.createToken(SyntaxKind.QuestionDotToken),
|
|
239
|
-
"toString",
|
|
240
|
-
),
|
|
241
|
-
undefined,
|
|
242
|
-
undefined,
|
|
243
|
-
[],
|
|
244
|
-
),
|
|
245
|
-
factory.createToken(SyntaxKind.QuestionQuestionToken),
|
|
246
|
-
factory.createStringLiteral("null"),
|
|
247
|
-
),
|
|
248
|
-
],
|
|
249
|
-
),
|
|
250
|
-
(i !== arr.length - 1
|
|
251
|
-
? factory.createTemplateMiddle
|
|
252
|
-
: factory.createTemplateTail)(s.substring(name.length)),
|
|
253
|
-
);
|
|
214
|
+
return out(
|
|
215
|
+
SdkPathTemplate.compose({
|
|
216
|
+
importer,
|
|
217
|
+
path: route.path,
|
|
218
|
+
argument: () => factory.createIdentifier("undefined"),
|
|
254
219
|
}),
|
|
255
220
|
);
|
|
256
|
-
|
|
221
|
+
|
|
222
|
+
const names: SdkHttpParameterProgrammer.INames =
|
|
223
|
+
SdkHttpParameterProgrammer.getNames({ project, route });
|
|
224
|
+
const template = () =>
|
|
225
|
+
SdkPathTemplate.compose({
|
|
226
|
+
importer,
|
|
227
|
+
path: route.path,
|
|
228
|
+
argument: (name) =>
|
|
229
|
+
names.access(route.pathParameters.find((p) => p.field === name)!),
|
|
230
|
+
});
|
|
257
231
|
if (route.queryObject === null && route.queryParameters.length === 0)
|
|
258
232
|
return out(template());
|
|
259
233
|
|
|
260
234
|
const block = (expr: Expression) => {
|
|
261
|
-
const
|
|
262
|
-
parameters.find((p) => p.name === str) !== undefined
|
|
263
|
-
? computeName("_" + str)
|
|
264
|
-
: str;
|
|
265
|
-
const variables: string = computeName("variables");
|
|
235
|
+
const variables: string = names.variables;
|
|
266
236
|
return factory.createBlock(
|
|
267
237
|
[
|
|
268
238
|
local(variables)("URLSearchParams")(
|
|
@@ -281,13 +251,13 @@ export namespace SdkHttpNamespaceProgrammer {
|
|
|
281
251
|
factory.createBindingElement(
|
|
282
252
|
undefined,
|
|
283
253
|
undefined,
|
|
284
|
-
factory.createIdentifier(
|
|
254
|
+
factory.createIdentifier(names.key),
|
|
285
255
|
undefined,
|
|
286
256
|
),
|
|
287
257
|
factory.createBindingElement(
|
|
288
258
|
undefined,
|
|
289
259
|
undefined,
|
|
290
|
-
factory.createIdentifier(
|
|
260
|
+
factory.createIdentifier(names.value),
|
|
291
261
|
undefined,
|
|
292
262
|
),
|
|
293
263
|
]),
|
|
@@ -306,19 +276,19 @@ export namespace SdkHttpNamespaceProgrammer {
|
|
|
306
276
|
factory.createIfStatement(
|
|
307
277
|
factory.createStrictEquality(
|
|
308
278
|
factory.createIdentifier("undefined"),
|
|
309
|
-
factory.createIdentifier(
|
|
279
|
+
factory.createIdentifier(names.value),
|
|
310
280
|
),
|
|
311
281
|
factory.createContinueStatement(),
|
|
312
282
|
factory.createIfStatement(
|
|
313
283
|
factory.createCallExpression(
|
|
314
284
|
factory.createIdentifier("Array.isArray"),
|
|
315
285
|
undefined,
|
|
316
|
-
[factory.createIdentifier(
|
|
286
|
+
[factory.createIdentifier(names.value)],
|
|
317
287
|
),
|
|
318
288
|
factory.createExpressionStatement(
|
|
319
289
|
factory.createCallExpression(
|
|
320
290
|
factory.createPropertyAccessExpression(
|
|
321
|
-
factory.createIdentifier(
|
|
291
|
+
factory.createIdentifier(names.value),
|
|
322
292
|
factory.createIdentifier("forEach"),
|
|
323
293
|
),
|
|
324
294
|
undefined,
|
|
@@ -326,7 +296,7 @@ export namespace SdkHttpNamespaceProgrammer {
|
|
|
326
296
|
factory.createArrowFunction(
|
|
327
297
|
undefined,
|
|
328
298
|
undefined,
|
|
329
|
-
[IdentifierFactory.parameter(
|
|
299
|
+
[IdentifierFactory.parameter(names.elem)],
|
|
330
300
|
undefined,
|
|
331
301
|
undefined,
|
|
332
302
|
factory.createCallExpression(
|
|
@@ -336,11 +306,11 @@ export namespace SdkHttpNamespaceProgrammer {
|
|
|
336
306
|
),
|
|
337
307
|
undefined,
|
|
338
308
|
[
|
|
339
|
-
factory.createIdentifier(
|
|
309
|
+
factory.createIdentifier(names.key),
|
|
340
310
|
factory.createCallExpression(
|
|
341
311
|
factory.createIdentifier("String"),
|
|
342
312
|
undefined,
|
|
343
|
-
[factory.createIdentifier(
|
|
313
|
+
[factory.createIdentifier(names.elem)],
|
|
344
314
|
),
|
|
345
315
|
],
|
|
346
316
|
),
|
|
@@ -356,11 +326,11 @@ export namespace SdkHttpNamespaceProgrammer {
|
|
|
356
326
|
),
|
|
357
327
|
undefined,
|
|
358
328
|
[
|
|
359
|
-
factory.createIdentifier(
|
|
329
|
+
factory.createIdentifier(names.key),
|
|
360
330
|
factory.createCallExpression(
|
|
361
331
|
factory.createIdentifier("String"),
|
|
362
332
|
undefined,
|
|
363
|
-
[factory.createIdentifier(
|
|
333
|
+
[factory.createIdentifier(names.value)],
|
|
364
334
|
),
|
|
365
335
|
],
|
|
366
336
|
),
|
|
@@ -368,7 +338,7 @@ export namespace SdkHttpNamespaceProgrammer {
|
|
|
368
338
|
),
|
|
369
339
|
),
|
|
370
340
|
),
|
|
371
|
-
local(
|
|
341
|
+
local(names.location)("string")(template()),
|
|
372
342
|
factory.createReturnStatement(
|
|
373
343
|
factory.createConditionalExpression(
|
|
374
344
|
factory.createStrictEquality(
|
|
@@ -379,13 +349,13 @@ export namespace SdkHttpNamespaceProgrammer {
|
|
|
379
349
|
),
|
|
380
350
|
),
|
|
381
351
|
undefined,
|
|
382
|
-
factory.createIdentifier(
|
|
352
|
+
factory.createIdentifier(names.location),
|
|
383
353
|
undefined,
|
|
384
354
|
factory.createTemplateExpression(
|
|
385
355
|
factory.createTemplateHead(""),
|
|
386
356
|
[
|
|
387
357
|
factory.createTemplateSpan(
|
|
388
|
-
factory.createIdentifier(
|
|
358
|
+
factory.createIdentifier(names.location),
|
|
389
359
|
factory.createTemplateMiddle("?"),
|
|
390
360
|
),
|
|
391
361
|
factory.createTemplateSpan(
|
|
@@ -412,11 +382,11 @@ export namespace SdkHttpNamespaceProgrammer {
|
|
|
412
382
|
block(
|
|
413
383
|
route.queryObject.metadata.required === false
|
|
414
384
|
? factory.createBinaryExpression(
|
|
415
|
-
|
|
385
|
+
names.access(route.queryObject),
|
|
416
386
|
factory.createToken(SyntaxKind.QuestionQuestionToken),
|
|
417
387
|
factory.createObjectLiteralExpression([], false),
|
|
418
388
|
)
|
|
419
|
-
:
|
|
389
|
+
: names.access(route.queryObject),
|
|
420
390
|
),
|
|
421
391
|
);
|
|
422
392
|
return out(
|
|
@@ -426,7 +396,7 @@ export namespace SdkHttpNamespaceProgrammer {
|
|
|
426
396
|
...(route.queryObject
|
|
427
397
|
? [
|
|
428
398
|
factory.createSpreadAssignment(
|
|
429
|
-
|
|
399
|
+
names.access(route.queryObject),
|
|
430
400
|
),
|
|
431
401
|
]
|
|
432
402
|
: []),
|
|
@@ -435,7 +405,7 @@ export namespace SdkHttpNamespaceProgrammer {
|
|
|
435
405
|
NamingConvention.variable(q.field!)
|
|
436
406
|
? q.field!
|
|
437
407
|
: factory.createStringLiteral(q.field!),
|
|
438
|
-
|
|
408
|
+
names.access(q),
|
|
439
409
|
),
|
|
440
410
|
),
|
|
441
411
|
],
|