@nestia/sdk 3.11.0-dev.20240813-10 → 3.11.0-dev.20240814
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/assets/bundle/api/Resolved.ts +1 -0
- package/assets/bundle/api/module.ts +1 -0
- package/lib/NestiaSdkApplication.d.ts +1 -0
- package/lib/NestiaSdkApplication.js +24 -26
- package/lib/NestiaSdkApplication.js.map +1 -1
- package/lib/analyses/ReflectControllerAnalyzer.js +2 -0
- package/lib/analyses/ReflectControllerAnalyzer.js.map +1 -1
- package/lib/analyses/ReflectHttpOperationAnalyzer.js +10 -1
- package/lib/analyses/ReflectHttpOperationAnalyzer.js.map +1 -1
- package/lib/analyses/ReflectHttpOperationExceptionAnalyzer.d.ts +15 -0
- package/lib/analyses/ReflectHttpOperationExceptionAnalyzer.js +50 -0
- package/lib/analyses/ReflectHttpOperationExceptionAnalyzer.js.map +1 -0
- package/lib/analyses/ReflectHttpOperationParameterAnalyzer.js +14 -9
- package/lib/analyses/ReflectHttpOperationParameterAnalyzer.js.map +1 -1
- package/lib/analyses/ReflectHttpOperationResponseAnalyzer.js +2 -1
- package/lib/analyses/ReflectHttpOperationResponseAnalyzer.js.map +1 -1
- package/lib/analyses/ReflectWebSocketOperationAnalyzer.js +3 -2
- package/lib/analyses/ReflectWebSocketOperationAnalyzer.js.map +1 -1
- package/lib/analyses/TypedHttpRouteAnalyzer.js +3 -1
- package/lib/analyses/TypedHttpRouteAnalyzer.js.map +1 -1
- package/lib/executable/internal/NestiaSdkCommand.d.ts +1 -0
- package/lib/executable/internal/NestiaSdkCommand.js +3 -2
- package/lib/executable/internal/NestiaSdkCommand.js.map +1 -1
- package/lib/executable/sdk.js +3 -0
- package/lib/executable/sdk.js.map +1 -1
- package/lib/generates/CloneGenerator.d.ts +4 -0
- package/lib/generates/CloneGenerator.js +62 -60
- package/lib/generates/CloneGenerator.js.map +1 -1
- package/lib/generates/SdkGenerator.js +4 -3
- package/lib/generates/SdkGenerator.js.map +1 -1
- package/lib/generates/SwaggerGenerator.js +60 -8
- package/lib/generates/SwaggerGenerator.js.map +1 -1
- package/lib/generates/internal/E2eFileProgrammer.js +11 -3
- package/lib/generates/internal/E2eFileProgrammer.js.map +1 -1
- package/lib/generates/internal/ImportDictionary.js +1 -1
- package/lib/generates/internal/ImportDictionary.js.map +1 -1
- package/lib/generates/internal/SdkAliasCollection.d.ts +5 -1
- package/lib/generates/internal/SdkAliasCollection.js +24 -8
- package/lib/generates/internal/SdkAliasCollection.js.map +1 -1
- package/lib/generates/internal/SdkFileProgrammer.js +1 -1
- package/lib/generates/internal/SdkFileProgrammer.js.map +1 -1
- package/lib/generates/internal/SdkHttpCloneProgrammer.d.ts +11 -0
- package/lib/generates/internal/SdkHttpCloneProgrammer.js +75 -142
- package/lib/generates/internal/SdkHttpCloneProgrammer.js.map +1 -1
- package/lib/generates/internal/SdkHttpCloneReferencer.d.ts +4 -0
- package/lib/generates/internal/SdkHttpCloneReferencer.js +62 -0
- package/lib/generates/internal/SdkHttpCloneReferencer.js.map +1 -0
- package/lib/generates/internal/SdkHttpFunctionProgrammer.js +26 -13
- package/lib/generates/internal/SdkHttpFunctionProgrammer.js.map +1 -1
- package/lib/generates/internal/SdkHttpNamespaceProgrammer.js +17 -8
- package/lib/generates/internal/SdkHttpNamespaceProgrammer.js.map +1 -1
- package/lib/generates/internal/SdkHttpRouteProgrammer.js +2 -2
- package/lib/generates/internal/SdkHttpRouteProgrammer.js.map +1 -1
- package/lib/generates/internal/SdkHttpSimulationProgrammer.js +8 -5
- package/lib/generates/internal/SdkHttpSimulationProgrammer.js.map +1 -1
- package/lib/generates/internal/SdkWebSocketNamespaceProgrammer.js +12 -5
- package/lib/generates/internal/SdkWebSocketNamespaceProgrammer.js.map +1 -1
- package/lib/generates/internal/SdkWebSocketRouteProgrammer.js +3 -3
- package/lib/generates/internal/SdkWebSocketRouteProgrammer.js.map +1 -1
- package/lib/generates/internal/SwaggerOperationComposer.js +19 -1
- package/lib/generates/internal/SwaggerOperationComposer.js.map +1 -1
- package/lib/generates/internal/SwaggerOperationParameterComposer.js +3 -3
- package/lib/generates/internal/SwaggerOperationParameterComposer.js.map +1 -1
- package/lib/structures/IReflectHttpOperation.d.ts +1 -1
- package/lib/structures/IReflectHttpOperationException.d.ts +2 -2
- package/lib/structures/ITypedApplication.d.ts +2 -0
- package/lib/transform.js +2 -2
- package/lib/transform.js.map +1 -1
- package/lib/transformers/IOperationMetadata.d.ts +6 -1
- package/lib/transformers/{ISdkTransformerContext.d.ts → ISdkOperationTransformerContext.d.ts} +1 -1
- package/lib/transformers/{ISdkTransformerContext.js → ISdkOperationTransformerContext.js} +1 -1
- package/lib/transformers/ISdkOperationTransformerContext.js.map +1 -0
- package/lib/transformers/SdkOperationProgrammer.d.ts +13 -0
- package/lib/transformers/{SdkMetadataProgrammer.js → SdkOperationProgrammer.js} +36 -55
- package/lib/transformers/SdkOperationProgrammer.js.map +1 -0
- package/lib/transformers/SdkOperationTransformer.d.ts +4 -0
- package/lib/transformers/{SdkTransformer.js → SdkOperationTransformer.js} +56 -16
- package/lib/transformers/SdkOperationTransformer.js.map +1 -0
- package/lib/utils/MetadataUtil.d.ts +4 -0
- package/lib/utils/MetadataUtil.js +34 -0
- package/lib/utils/MetadataUtil.js.map +1 -0
- package/lib/utils/StringUtil.d.ts +1 -0
- package/lib/utils/StringUtil.js +6 -0
- package/lib/utils/StringUtil.js.map +1 -1
- package/lib/validators/HttpHeadersValidator.d.ts +5 -0
- package/lib/validators/HttpHeadersValidator.js +29 -0
- package/lib/validators/HttpHeadersValidator.js.map +1 -0
- package/lib/validators/HttpQueryValidator.d.ts +5 -0
- package/lib/validators/HttpQueryValidator.js +29 -0
- package/lib/validators/HttpQueryValidator.js.map +1 -0
- package/package.json +8 -8
- package/src/NestiaSdkApplication.ts +20 -30
- package/src/analyses/ReflectControllerAnalyzer.ts +2 -0
- package/src/analyses/ReflectHttpOperationAnalyzer.ts +10 -1
- package/src/analyses/ReflectHttpOperationExceptionAnalyzer.ts +71 -0
- package/src/analyses/ReflectHttpOperationParameterAnalyzer.ts +37 -8
- package/src/analyses/ReflectHttpOperationResponseAnalyzer.ts +8 -0
- package/src/analyses/ReflectWebSocketOperationAnalyzer.ts +10 -2
- package/src/analyses/TypedHttpRouteAnalyzer.ts +4 -1
- package/src/executable/internal/NestiaSdkCommand.ts +3 -2
- package/src/executable/sdk.ts +2 -0
- package/src/generates/CloneGenerator.ts +61 -60
- package/src/generates/SdkGenerator.ts +3 -3
- package/src/generates/SwaggerGenerator.ts +84 -10
- package/src/generates/internal/E2eFileProgrammer.ts +13 -3
- package/src/generates/internal/ImportDictionary.ts +1 -1
- package/src/generates/internal/SdkAliasCollection.ts +32 -10
- package/src/generates/internal/SdkFileProgrammer.ts +1 -1
- package/src/generates/internal/SdkHttpCloneProgrammer.ts +118 -144
- package/src/generates/internal/SdkHttpCloneReferencer.ts +71 -0
- package/src/generates/internal/SdkHttpFunctionProgrammer.ts +31 -16
- package/src/generates/internal/SdkHttpNamespaceProgrammer.ts +252 -230
- package/src/generates/internal/SdkHttpRouteProgrammer.ts +2 -2
- package/src/generates/internal/SdkHttpSimulationProgrammer.ts +30 -24
- package/src/generates/internal/SdkWebSocketNamespaceProgrammer.ts +14 -6
- package/src/generates/internal/SdkWebSocketRouteProgrammer.ts +6 -8
- package/src/generates/internal/SwaggerOperationComposer.ts +25 -0
- package/src/generates/internal/SwaggerOperationParameterComposer.ts +3 -0
- package/src/structures/IReflectHttpOperation.ts +1 -4
- package/src/structures/IReflectHttpOperationException.ts +2 -2
- package/src/structures/ITypedApplication.ts +3 -0
- package/src/transform.ts +2 -2
- package/src/transformers/IOperationMetadata.ts +7 -1
- package/src/transformers/{ISdkTransformerContext.ts → ISdkOperationTransformerContext.ts} +1 -1
- package/src/transformers/{SdkMetadataProgrammer.ts → SdkOperationProgrammer.ts} +40 -62
- package/src/transformers/{SdkTransformer.ts → SdkOperationTransformer.ts} +88 -16
- package/src/utils/MetadataUtil.ts +26 -0
- package/src/utils/StringUtil.ts +8 -0
- package/src/validators/HttpHeadersValidator.ts +34 -0
- package/src/validators/HttpQueryValidator.ts +34 -0
- package/lib/transformers/ISdkTransformerContext.js.map +0 -1
- package/lib/transformers/SdkMetadataProgrammer.d.ts +0 -11
- package/lib/transformers/SdkMetadataProgrammer.js.map +0 -1
- package/lib/transformers/SdkTransformer.d.ts +0 -4
- package/lib/transformers/SdkTransformer.js.map +0 -1
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import ts from "typescript";
|
|
2
2
|
import typia from "typia";
|
|
3
|
+
import { TypeFactory } from "typia/lib/factories/TypeFactory";
|
|
4
|
+
import { Metadata } from "typia/lib/schemas/metadata/Metadata";
|
|
3
5
|
|
|
4
6
|
import { INestiaProject } from "../../structures/INestiaProject";
|
|
5
7
|
import { IReflectHttpOperationParameter } from "../../structures/IReflectHttpOperationParameter";
|
|
@@ -7,18 +9,29 @@ import { IReflectType } from "../../structures/IReflectType";
|
|
|
7
9
|
import { ITypedHttpRoute } from "../../structures/ITypedHttpRoute";
|
|
8
10
|
import { ITypedHttpRouteParameter } from "../../structures/ITypedHttpRouteParameter";
|
|
9
11
|
import { ImportDictionary } from "./ImportDictionary";
|
|
12
|
+
import { SdkTypeProgrammer } from "./SdkTypeProgrammer";
|
|
10
13
|
|
|
11
14
|
export namespace SdkAliasCollection {
|
|
12
|
-
export const name = (type: IReflectType): ts.TypeNode =>
|
|
15
|
+
export const name = ({ type }: { type: IReflectType }): ts.TypeNode =>
|
|
13
16
|
ts.factory.createTypeReferenceNode(
|
|
14
17
|
type.name,
|
|
15
|
-
type.typeArguments
|
|
18
|
+
type.typeArguments
|
|
19
|
+
? type.typeArguments.map((a) => name({ type: a }))
|
|
20
|
+
: undefined,
|
|
16
21
|
);
|
|
17
22
|
|
|
23
|
+
export const from =
|
|
24
|
+
(project: INestiaProject) =>
|
|
25
|
+
(importer: ImportDictionary) =>
|
|
26
|
+
(metadata: Metadata) =>
|
|
27
|
+
SdkTypeProgrammer.write(project)(importer)(metadata);
|
|
28
|
+
|
|
18
29
|
export const headers =
|
|
19
30
|
(project: INestiaProject) =>
|
|
20
31
|
(importer: ImportDictionary) =>
|
|
21
32
|
(param: ITypedHttpRouteParameter.IHeaders): ts.TypeNode => {
|
|
33
|
+
if (project.config.clone === true)
|
|
34
|
+
return from(project)(importer)(param.metadata);
|
|
22
35
|
const type: ts.TypeNode = name(param);
|
|
23
36
|
if (project.config.primitive === false) return type;
|
|
24
37
|
return ts.factory.createTypeReferenceNode(
|
|
@@ -35,6 +48,8 @@ export namespace SdkAliasCollection {
|
|
|
35
48
|
(project: INestiaProject) =>
|
|
36
49
|
(importer: ImportDictionary) =>
|
|
37
50
|
(param: ITypedHttpRouteParameter.IQuery): ts.TypeNode => {
|
|
51
|
+
if (project.config.clone === true)
|
|
52
|
+
return from(project)(importer)(param.metadata);
|
|
38
53
|
const type: ts.TypeNode = name(param);
|
|
39
54
|
if (project.config.primitive === false) return type;
|
|
40
55
|
return ts.factory.createTypeReferenceNode(
|
|
@@ -51,9 +66,10 @@ export namespace SdkAliasCollection {
|
|
|
51
66
|
(project: INestiaProject) =>
|
|
52
67
|
(importer: ImportDictionary) =>
|
|
53
68
|
(param: ITypedHttpRouteParameter): ts.TypeNode => {
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
69
|
+
if (project.config.clone === true)
|
|
70
|
+
return from(project)(importer)(param.metadata);
|
|
71
|
+
const type: ts.TypeNode = name(param);
|
|
72
|
+
if (project.config.primitive === false) return type;
|
|
57
73
|
return ts.factory.createTypeReferenceNode(
|
|
58
74
|
importer.external({
|
|
59
75
|
type: true,
|
|
@@ -73,9 +89,15 @@ export namespace SdkAliasCollection {
|
|
|
73
89
|
(project: INestiaProject) =>
|
|
74
90
|
(importer: ImportDictionary) =>
|
|
75
91
|
(route: ITypedHttpRoute): ts.TypeNode => {
|
|
92
|
+
const schema = (p: { metadata: Metadata; type: IReflectType }) =>
|
|
93
|
+
project.config.clone === true
|
|
94
|
+
? from(project)(importer)(p.metadata)
|
|
95
|
+
: name(p);
|
|
76
96
|
if (project.config.propagate !== true) {
|
|
77
|
-
if (
|
|
78
|
-
return
|
|
97
|
+
if (route.success.metadata.size() === 0)
|
|
98
|
+
return TypeFactory.keyword("void");
|
|
99
|
+
else if (project.config.primitive === false)
|
|
100
|
+
return schema(route.success);
|
|
79
101
|
return ts.factory.createTypeReferenceNode(
|
|
80
102
|
importer.external({
|
|
81
103
|
type: true,
|
|
@@ -86,7 +108,7 @@ export namespace SdkAliasCollection {
|
|
|
86
108
|
? "Primitive"
|
|
87
109
|
: "Resolved",
|
|
88
110
|
}),
|
|
89
|
-
[
|
|
111
|
+
[schema(route.success)],
|
|
90
112
|
);
|
|
91
113
|
}
|
|
92
114
|
|
|
@@ -95,11 +117,11 @@ export namespace SdkAliasCollection {
|
|
|
95
117
|
status: String(
|
|
96
118
|
route.success.status ?? (route.method === "POST" ? 201 : 200),
|
|
97
119
|
),
|
|
98
|
-
type:
|
|
120
|
+
type: schema(route.success),
|
|
99
121
|
},
|
|
100
122
|
...Object.entries(route.exceptions).map(([status, value]) => ({
|
|
101
123
|
status,
|
|
102
|
-
type:
|
|
124
|
+
type: schema(value),
|
|
103
125
|
})),
|
|
104
126
|
];
|
|
105
127
|
return ts.factory.createTypeReferenceNode(
|
|
@@ -75,7 +75,7 @@ export namespace SdkFileProgrammer {
|
|
|
75
75
|
`${outDir}/index.ts`,
|
|
76
76
|
);
|
|
77
77
|
directory.routes.forEach((route, i) => {
|
|
78
|
-
if (project.config.clone
|
|
78
|
+
if (!(project.config.clone === true && route.protocol === "http"))
|
|
79
79
|
for (const tuple of route.imports)
|
|
80
80
|
for (const instance of tuple.instances)
|
|
81
81
|
importer.internal({
|
|
@@ -1,154 +1,128 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
// import { MetadataAtomic } from "typia/lib/schemas/metadata/MetadataAtomic";
|
|
8
|
-
// import { MetadataObject } from "typia/lib/schemas/metadata/MetadataObject";
|
|
1
|
+
import { IPointer } from "tstl";
|
|
2
|
+
import ts from "typescript";
|
|
3
|
+
import { IJsDocTagInfo } from "typia";
|
|
4
|
+
import { MetadataAlias } from "typia/lib/schemas/metadata/MetadataAlias";
|
|
5
|
+
import { MetadataAtomic } from "typia/lib/schemas/metadata/MetadataAtomic";
|
|
6
|
+
import { MetadataObject } from "typia/lib/schemas/metadata/MetadataObject";
|
|
9
7
|
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
8
|
+
import { INestiaProject } from "../../structures/INestiaProject";
|
|
9
|
+
import { ITypedApplication } from "../../structures/ITypedApplication";
|
|
10
|
+
import { MapUtil } from "../../utils/MapUtil";
|
|
11
|
+
import { StringUtil } from "../../utils/StringUtil";
|
|
12
|
+
import { FilePrinter } from "./FilePrinter";
|
|
13
|
+
import { ImportDictionary } from "./ImportDictionary";
|
|
14
|
+
import { SdkTypeProgrammer } from "./SdkTypeProgrammer";
|
|
16
15
|
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
16
|
+
export namespace SdkHttpCloneProgrammer {
|
|
17
|
+
export interface IModule {
|
|
18
|
+
name: string;
|
|
19
|
+
children: Map<string, IModule>;
|
|
20
|
+
programmer:
|
|
21
|
+
| null
|
|
22
|
+
| ((importer: ImportDictionary) => ts.TypeAliasDeclaration);
|
|
23
|
+
}
|
|
25
24
|
|
|
26
|
-
|
|
27
|
-
//
|
|
28
|
-
//
|
|
29
|
-
//
|
|
30
|
-
//
|
|
31
|
-
//
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
// const res = MetadataFactory.analyze(project.checker)({
|
|
50
|
-
// escape: true,
|
|
51
|
-
// constant: true,
|
|
52
|
-
// absorb: false,
|
|
53
|
-
// })(collection)(r.output.type);
|
|
54
|
-
// if (res.success) r.success.metadata = res.data;
|
|
55
|
-
// }
|
|
25
|
+
export const write = (app: ITypedApplication): Map<string, IModule> => {
|
|
26
|
+
// console.log({
|
|
27
|
+
// objects: Array.from(app.collection.objects.keys()).sort(),
|
|
28
|
+
// aliases: Array.from(app.collection.aliases.keys()).sort(),
|
|
29
|
+
// });
|
|
30
|
+
// COMPOSE THE DICTIONARY
|
|
31
|
+
const dict: Map<string, IModule> = new Map();
|
|
32
|
+
for (const [k, v] of app.collection.objects.entries())
|
|
33
|
+
if (StringUtil.isImplicit(k) === false)
|
|
34
|
+
prepare({
|
|
35
|
+
dict,
|
|
36
|
+
name: k,
|
|
37
|
+
programmer: (importer) => write_object(app.project)(importer)(v),
|
|
38
|
+
});
|
|
39
|
+
for (const [k, v] of app.collection.aliases.entries())
|
|
40
|
+
if (StringUtil.isImplicit(k) === false)
|
|
41
|
+
prepare({
|
|
42
|
+
dict,
|
|
43
|
+
name: k,
|
|
44
|
+
programmer: (importer) => write_alias(app.project)(importer)(v),
|
|
45
|
+
});
|
|
46
|
+
return dict;
|
|
47
|
+
};
|
|
56
48
|
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
// prepare(dict)(object.name)((importer) =>
|
|
66
|
-
// write_object(project)(importer)(object),
|
|
67
|
-
// );
|
|
68
|
-
// return dict;
|
|
69
|
-
// };
|
|
49
|
+
const prepare = (props: {
|
|
50
|
+
dict: Map<string, IModule>;
|
|
51
|
+
name: string;
|
|
52
|
+
programmer: (importer: ImportDictionary) => ts.TypeAliasDeclaration;
|
|
53
|
+
}) => {
|
|
54
|
+
let next: Map<string, IModule> = props.dict;
|
|
55
|
+
const accessors: string[] = props.name.split(".");
|
|
56
|
+
const modulo: IPointer<IModule> = { value: null! };
|
|
70
57
|
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
58
|
+
accessors.forEach((acc, i) => {
|
|
59
|
+
modulo.value = MapUtil.take(next, acc, () => ({
|
|
60
|
+
name: acc,
|
|
61
|
+
children: new Map(),
|
|
62
|
+
programmer: null,
|
|
63
|
+
}));
|
|
64
|
+
if (i === accessors.length - 1)
|
|
65
|
+
modulo.value.programmer = props.programmer;
|
|
66
|
+
next = modulo.value.children;
|
|
67
|
+
});
|
|
68
|
+
return modulo!;
|
|
69
|
+
};
|
|
77
70
|
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
71
|
+
const write_alias =
|
|
72
|
+
(project: INestiaProject) =>
|
|
73
|
+
(importer: ImportDictionary) =>
|
|
74
|
+
(alias: MetadataAlias): ts.TypeAliasDeclaration =>
|
|
75
|
+
FilePrinter.description(
|
|
76
|
+
ts.factory.createTypeAliasDeclaration(
|
|
77
|
+
[ts.factory.createToken(ts.SyntaxKind.ExportKeyword)],
|
|
78
|
+
alias.name.split(".").at(-1)!,
|
|
79
|
+
[],
|
|
80
|
+
SdkTypeProgrammer.write(project)(importer)(alias.value),
|
|
81
|
+
),
|
|
82
|
+
writeComment([])(alias.description, alias.jsDocTags),
|
|
83
|
+
);
|
|
89
84
|
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
85
|
+
const write_object =
|
|
86
|
+
(project: INestiaProject) =>
|
|
87
|
+
(importer: ImportDictionary) =>
|
|
88
|
+
(object: MetadataObject): ts.TypeAliasDeclaration => {
|
|
89
|
+
return FilePrinter.description(
|
|
90
|
+
ts.factory.createTypeAliasDeclaration(
|
|
91
|
+
[ts.factory.createToken(ts.SyntaxKind.ExportKeyword)],
|
|
92
|
+
object.name.split(".").at(-1)!,
|
|
93
|
+
[],
|
|
94
|
+
SdkTypeProgrammer.write_object(project)(importer)(object),
|
|
95
|
+
),
|
|
96
|
+
writeComment([])(object.description ?? null, object.jsDocTags),
|
|
97
|
+
);
|
|
98
|
+
};
|
|
99
|
+
}
|
|
103
100
|
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
// [ts.factory.createToken(ts.SyntaxKind.ExportKeyword)],
|
|
111
|
-
// object.name.split(".").at(-1)!,
|
|
112
|
-
// [],
|
|
113
|
-
// SdkTypeProgrammer.write_object(project)(importer)(object),
|
|
114
|
-
// ),
|
|
115
|
-
// writeComment([])(object.description ?? null, object.jsDocTags),
|
|
116
|
-
// );
|
|
117
|
-
// };
|
|
118
|
-
// }
|
|
101
|
+
const writeComment =
|
|
102
|
+
(atomics: MetadataAtomic[]) =>
|
|
103
|
+
(description: string | null, jsDocTags: IJsDocTagInfo[]): string => {
|
|
104
|
+
const lines: string[] = [];
|
|
105
|
+
if (description?.length)
|
|
106
|
+
lines.push(...description.split("\n").map((s) => `${s}`));
|
|
119
107
|
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
108
|
+
const filtered: IJsDocTagInfo[] =
|
|
109
|
+
!!atomics.length && !!jsDocTags?.length
|
|
110
|
+
? jsDocTags.filter(
|
|
111
|
+
(tag) =>
|
|
112
|
+
!atomics.some((a) =>
|
|
113
|
+
a.tags.some((r) => r.some((t) => t.kind === tag.name)),
|
|
114
|
+
),
|
|
115
|
+
)
|
|
116
|
+
: jsDocTags ?? [];
|
|
126
117
|
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
// !atomics.some((a) =>
|
|
139
|
-
// a.tags.some((r) => r.some((t) => t.kind === tag.name)),
|
|
140
|
-
// ),
|
|
141
|
-
// )
|
|
142
|
-
// : jsDocTags ?? [];
|
|
143
|
-
|
|
144
|
-
// if (description?.length && filtered.length) lines.push("");
|
|
145
|
-
// if (filtered.length)
|
|
146
|
-
// lines.push(
|
|
147
|
-
// ...filtered.map((t) =>
|
|
148
|
-
// t.text?.length
|
|
149
|
-
// ? `@${t.name} ${t.text.map((e) => e.text).join("")}`
|
|
150
|
-
// : `@${t.name}`,
|
|
151
|
-
// ),
|
|
152
|
-
// );
|
|
153
|
-
// return lines.join("\n");
|
|
154
|
-
// };
|
|
118
|
+
if (description?.length && filtered.length) lines.push("");
|
|
119
|
+
if (filtered.length)
|
|
120
|
+
lines.push(
|
|
121
|
+
...filtered.map((t) =>
|
|
122
|
+
t.text?.length
|
|
123
|
+
? `@${t.name} ${t.text.map((e) => e.text).join("")}`
|
|
124
|
+
: `@${t.name}`,
|
|
125
|
+
),
|
|
126
|
+
);
|
|
127
|
+
return lines.join("\n");
|
|
128
|
+
};
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import { Metadata } from "typia/lib/schemas/metadata/Metadata";
|
|
2
|
+
|
|
3
|
+
import { IReflectType } from "../../structures/IReflectType";
|
|
4
|
+
import { ITypedApplication } from "../../structures/ITypedApplication";
|
|
5
|
+
import { ITypedHttpRoute } from "../../structures/ITypedHttpRoute";
|
|
6
|
+
import { StringUtil } from "../../utils/StringUtil";
|
|
7
|
+
|
|
8
|
+
export namespace SdkHttpCloneReferencer {
|
|
9
|
+
export const replace = (app: ITypedApplication): void => {
|
|
10
|
+
const directory: string = `${app.project.config.output}/structures`;
|
|
11
|
+
for (const route of app.routes)
|
|
12
|
+
if (route.protocol === "http")
|
|
13
|
+
visitRoute({
|
|
14
|
+
directory,
|
|
15
|
+
route,
|
|
16
|
+
});
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
const visitRoute = (props: {
|
|
20
|
+
directory: string;
|
|
21
|
+
route: ITypedHttpRoute;
|
|
22
|
+
}): void => {
|
|
23
|
+
const unique: Set<string> = new Set();
|
|
24
|
+
for (const p of props.route.parameters)
|
|
25
|
+
visitType({
|
|
26
|
+
unique,
|
|
27
|
+
metadata: p.metadata,
|
|
28
|
+
type: p.type,
|
|
29
|
+
name: (name) => (p.type = { name }),
|
|
30
|
+
});
|
|
31
|
+
for (const v of Object.values(props.route.exceptions))
|
|
32
|
+
visitType({
|
|
33
|
+
unique,
|
|
34
|
+
metadata: v.metadata,
|
|
35
|
+
type: v.type,
|
|
36
|
+
name: (name) => (v.type = { name }),
|
|
37
|
+
});
|
|
38
|
+
visitType({
|
|
39
|
+
unique,
|
|
40
|
+
metadata: props.route.success.metadata,
|
|
41
|
+
type: props.route.success.type,
|
|
42
|
+
name: (name) => (props.route.success.type = { name }),
|
|
43
|
+
});
|
|
44
|
+
props.route.imports = Array.from(unique).map((str) => ({
|
|
45
|
+
file: `${props.directory}/${str}`,
|
|
46
|
+
instances: [str],
|
|
47
|
+
}));
|
|
48
|
+
};
|
|
49
|
+
|
|
50
|
+
const visitType = (p: {
|
|
51
|
+
unique: Set<string>;
|
|
52
|
+
metadata: Metadata;
|
|
53
|
+
type: IReflectType;
|
|
54
|
+
name: (key: string) => void;
|
|
55
|
+
}): void => {
|
|
56
|
+
const enroll = (key: string) => {
|
|
57
|
+
if (key.length && StringUtil.isImplicit(key) === false)
|
|
58
|
+
p.unique.add(key.split(".")[0]);
|
|
59
|
+
};
|
|
60
|
+
for (const alias of p.metadata.aliases) enroll(alias.name);
|
|
61
|
+
for (const array of p.metadata.arrays) enroll(array.type.name);
|
|
62
|
+
for (const tuple of p.metadata.tuples) enroll(tuple.type.name);
|
|
63
|
+
for (const object of p.metadata.objects) enroll(object.name);
|
|
64
|
+
p.name(p.metadata.getName());
|
|
65
|
+
};
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
const getFullText = (type: IReflectType): string =>
|
|
69
|
+
type.typeArguments === undefined
|
|
70
|
+
? type.name
|
|
71
|
+
: `${type.name}<${type.typeArguments.map(getFullText).join(", ")}>`;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import ts from "typescript";
|
|
2
2
|
import { IdentifierFactory } from "typia/lib/factories/IdentifierFactory";
|
|
3
|
+
import { TypeFactory } from "typia/lib/factories/TypeFactory";
|
|
3
4
|
|
|
4
|
-
import { INestiaConfig } from "../../INestiaConfig";
|
|
5
5
|
import { INestiaProject } from "../../structures/INestiaProject";
|
|
6
6
|
import { ITypedHttpRoute } from "../../structures/ITypedHttpRoute";
|
|
7
7
|
import { ITypedHttpRouteParameter } from "../../structures/ITypedHttpRouteParameter";
|
|
@@ -55,21 +55,26 @@ export namespace SdkHttpFunctionProgrammer {
|
|
|
55
55
|
? ts.factory.createTypeReferenceNode(
|
|
56
56
|
`${route.name}.${p === props.query ? "Query" : "Input"}`,
|
|
57
57
|
)
|
|
58
|
-
:
|
|
58
|
+
: project.config.clone === true
|
|
59
|
+
? SdkAliasCollection.from(project)(importer)(p.metadata)
|
|
60
|
+
: SdkAliasCollection.name(p),
|
|
59
61
|
),
|
|
60
62
|
),
|
|
61
63
|
],
|
|
62
64
|
ts.factory.createTypeReferenceNode("Promise", [
|
|
63
|
-
|
|
65
|
+
project.config.propagate === true ||
|
|
66
|
+
route.success.metadata.size() !== 0
|
|
67
|
+
? ts.factory.createTypeReferenceNode(`${route.name}.Output`)
|
|
68
|
+
: ts.factory.createTypeReferenceNode("void"),
|
|
64
69
|
]),
|
|
65
70
|
ts.factory.createBlock(
|
|
66
|
-
write_body(project
|
|
71
|
+
write_body(project)(importer)(route, props),
|
|
67
72
|
true,
|
|
68
73
|
),
|
|
69
74
|
);
|
|
70
75
|
|
|
71
76
|
const write_body =
|
|
72
|
-
(
|
|
77
|
+
(project: INestiaProject) =>
|
|
73
78
|
(importer: ImportDictionary) =>
|
|
74
79
|
(
|
|
75
80
|
route: ITypedHttpRoute,
|
|
@@ -83,10 +88,17 @@ export namespace SdkHttpFunctionProgrammer {
|
|
|
83
88
|
ts.factory.createCallExpression(
|
|
84
89
|
IdentifierFactory.access(
|
|
85
90
|
ts.factory.createIdentifier(
|
|
86
|
-
SdkImportWizard.Fetcher(
|
|
91
|
+
SdkImportWizard.Fetcher(
|
|
92
|
+
!!props.input?.encrypted || route.success.encrypted,
|
|
93
|
+
)(importer),
|
|
87
94
|
),
|
|
88
|
-
)(config.propagate ? "propagate" : "fetch"),
|
|
89
|
-
|
|
95
|
+
)(project.config.propagate ? "propagate" : "fetch"),
|
|
96
|
+
project.config.propagate
|
|
97
|
+
? route.method.toLowerCase() === "get" ||
|
|
98
|
+
route.method.toLowerCase() === "head"
|
|
99
|
+
? [TypeFactory.keyword("any")]
|
|
100
|
+
: [TypeFactory.keyword("any"), TypeFactory.keyword("any")]
|
|
101
|
+
: undefined,
|
|
90
102
|
[
|
|
91
103
|
props.input?.contentType !== "multipart/form-data"
|
|
92
104
|
? ts.factory.createObjectLiteralExpression(
|
|
@@ -152,7 +164,7 @@ export namespace SdkHttpFunctionProgrammer {
|
|
|
152
164
|
...(props.input
|
|
153
165
|
? [ts.factory.createIdentifier(props.input.name)]
|
|
154
166
|
: []),
|
|
155
|
-
...(config.json &&
|
|
167
|
+
...(project.config.json &&
|
|
156
168
|
props.input !== undefined &&
|
|
157
169
|
(props.input.contentType === "application/json" ||
|
|
158
170
|
props.input.encrypted === true)
|
|
@@ -161,7 +173,7 @@ export namespace SdkHttpFunctionProgrammer {
|
|
|
161
173
|
],
|
|
162
174
|
);
|
|
163
175
|
const output = (awaiter: boolean) =>
|
|
164
|
-
config.simulate
|
|
176
|
+
project.config.simulate
|
|
165
177
|
? ts.factory.createConditionalExpression(
|
|
166
178
|
ts.factory.createIdentifier("!!connection.simulate"),
|
|
167
179
|
undefined,
|
|
@@ -182,7 +194,7 @@ export namespace SdkHttpFunctionProgrammer {
|
|
|
182
194
|
? ts.factory.createAwaitExpression(caller())
|
|
183
195
|
: caller();
|
|
184
196
|
return [
|
|
185
|
-
...(config.assert
|
|
197
|
+
...(project.config.assert
|
|
186
198
|
? route.parameters
|
|
187
199
|
.filter((p) => p.category !== "headers")
|
|
188
200
|
.map((p) =>
|
|
@@ -205,12 +217,13 @@ export namespace SdkHttpFunctionProgrammer {
|
|
|
205
217
|
: []),
|
|
206
218
|
...(route.success.setHeaders.length === 0
|
|
207
219
|
? [ts.factory.createReturnStatement(output(false))]
|
|
208
|
-
: write_set_headers(
|
|
220
|
+
: write_set_headers(project)(importer)(route)(output(true))),
|
|
209
221
|
];
|
|
210
222
|
};
|
|
211
223
|
|
|
212
224
|
const write_set_headers =
|
|
213
|
-
(
|
|
225
|
+
(project: INestiaProject) =>
|
|
226
|
+
(importer: ImportDictionary) =>
|
|
214
227
|
(route: ITypedHttpRoute) =>
|
|
215
228
|
(condition: ts.Expression): ts.Statement[] => {
|
|
216
229
|
const accessor = (x: string) => (y: string) =>
|
|
@@ -220,7 +233,9 @@ export namespace SdkHttpFunctionProgrammer {
|
|
|
220
233
|
...route.parameters.map((p) => p.name),
|
|
221
234
|
])("output");
|
|
222
235
|
const headers: string = accessor("connection")("headers");
|
|
223
|
-
const data: string = config.propagate
|
|
236
|
+
const data: string = project.config.propagate
|
|
237
|
+
? accessor(output)("data")
|
|
238
|
+
: output;
|
|
224
239
|
|
|
225
240
|
const assigners: ts.ExpressionStatement[] = [
|
|
226
241
|
ts.factory.createBinaryExpression(
|
|
@@ -255,14 +270,14 @@ export namespace SdkHttpFunctionProgrammer {
|
|
|
255
270
|
ts.factory.createVariableDeclaration(
|
|
256
271
|
output,
|
|
257
272
|
undefined,
|
|
258
|
-
SdkAliasCollection.
|
|
273
|
+
SdkAliasCollection.output(project)(importer)(route),
|
|
259
274
|
condition,
|
|
260
275
|
),
|
|
261
276
|
],
|
|
262
277
|
ts.NodeFlags.Const,
|
|
263
278
|
),
|
|
264
279
|
),
|
|
265
|
-
...(config.propagate
|
|
280
|
+
...(project.config.propagate
|
|
266
281
|
? [
|
|
267
282
|
ts.factory.createIfStatement(
|
|
268
283
|
ts.factory.createIdentifier(accessor(output)("success")),
|