@nestia/sdk 2.6.2 → 2.6.3
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/lib/analyses/ControllerAnalyzer.js +3 -3
- package/lib/analyses/ControllerAnalyzer.js.map +1 -1
- package/lib/analyses/ImportAnalyzer.d.ts +1 -2
- package/lib/analyses/ImportAnalyzer.js +2 -2
- package/lib/analyses/ImportAnalyzer.js.map +1 -1
- package/lib/analyses/ReflectAnalyzer.js +2 -2
- package/lib/analyses/ReflectAnalyzer.js.map +1 -1
- package/lib/generates/SwaggerGenerator.js +4 -4
- package/lib/generates/SwaggerGenerator.js.map +1 -1
- package/lib/generates/internal/ImportDictionary.js +6 -8
- package/lib/generates/internal/ImportDictionary.js.map +1 -1
- package/lib/structures/TypeEntry.js +2 -2
- package/lib/structures/TypeEntry.js.map +1 -1
- package/package.json +4 -4
- package/src/INestiaConfig.ts +248 -248
- package/src/NestiaSdkApplication.ts +255 -255
- package/src/analyses/ControllerAnalyzer.ts +402 -402
- package/src/analyses/ExceptionAnalyzer.ts +148 -148
- package/src/analyses/ImportAnalyzer.ts +1 -2
- package/src/analyses/ReflectAnalyzer.ts +463 -463
- package/src/analyses/SecurityAnalyzer.ts +24 -24
- package/src/generates/CloneGenerator.ts +62 -62
- package/src/generates/E2eGenerator.ts +66 -66
- package/src/generates/SdkGenerator.ts +84 -84
- package/src/generates/SwaggerGenerator.ts +446 -446
- package/src/generates/internal/E2eFileProgrammer.ts +182 -182
- package/src/generates/internal/FilePrinter.ts +53 -53
- package/src/generates/internal/ImportDictionary.ts +147 -149
- package/src/generates/internal/SdkAliasCollection.ts +152 -152
- package/src/generates/internal/SdkCloneProgrammer.ts +155 -155
- package/src/generates/internal/SdkFileProgrammer.ts +115 -115
- package/src/generates/internal/SdkFunctionProgrammer.ts +298 -298
- package/src/generates/internal/SdkImportWizard.ts +55 -55
- package/src/generates/internal/SdkNamespaceProgrammer.ts +510 -510
- package/src/generates/internal/SdkRouteProgrammer.ts +83 -83
- package/src/generates/internal/SdkSimulationProgrammer.ts +365 -365
- package/src/generates/internal/SdkTypeProgrammer.ts +385 -385
- package/src/generates/internal/SwaggerSchemaGenerator.ts +438 -438
- package/src/structures/IController.ts +94 -94
- package/src/structures/IRoute.ts +53 -53
- package/src/structures/ISwagger.ts +91 -91
- package/src/structures/ISwaggerRoute.ts +54 -54
- package/src/structures/ISwaggerSecurityScheme.ts +65 -65
- package/src/structures/ParamCategory.ts +1 -1
- package/src/structures/TypeEntry.ts +1 -1
- package/src/utils/StringUtil.ts +6 -6
|
@@ -1,149 +1,147 @@
|
|
|
1
|
-
import path from "path";
|
|
2
|
-
import { HashMap } from "tstl
|
|
3
|
-
import
|
|
4
|
-
|
|
5
|
-
import
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
public
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
);
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
if (props.file.substring(props.file.length -
|
|
37
|
-
return props.file.substring(0, props.file.length -
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
const
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
.
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
.
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
...
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
const NODE_MODULES = "node_modules/";
|
|
1
|
+
import path from "path";
|
|
2
|
+
import { HashMap, HashSet, Pair } from "tstl";
|
|
3
|
+
import ts from "typescript";
|
|
4
|
+
|
|
5
|
+
import { FilePrinter } from "./FilePrinter";
|
|
6
|
+
|
|
7
|
+
export class ImportDictionary {
|
|
8
|
+
private readonly components_: HashMap<Pair<string, boolean>, IComposition> =
|
|
9
|
+
new HashMap();
|
|
10
|
+
|
|
11
|
+
public constructor(public readonly file: string) {}
|
|
12
|
+
|
|
13
|
+
public empty(): boolean {
|
|
14
|
+
return this.components_.empty();
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
public external(props: ImportDictionary.IExternalProps): string {
|
|
18
|
+
const composition: IComposition = this.components_.take(
|
|
19
|
+
new Pair(props.library, props.type),
|
|
20
|
+
() => ({
|
|
21
|
+
location: `node_modules/${props.library}`,
|
|
22
|
+
elements: new HashSet(),
|
|
23
|
+
default: false,
|
|
24
|
+
type: props.type,
|
|
25
|
+
}),
|
|
26
|
+
);
|
|
27
|
+
if (props.instance === null) composition.default = true;
|
|
28
|
+
else composition.elements.insert(props.instance);
|
|
29
|
+
return props.instance ?? props.library;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
public internal(props: ImportDictionary.IInternalProps): string {
|
|
33
|
+
const file: string = (() => {
|
|
34
|
+
if (props.file.substring(props.file.length - 5) === ".d.ts")
|
|
35
|
+
return props.file.substring(0, props.file.length - 5);
|
|
36
|
+
else if (props.file.substring(props.file.length - 3) === ".ts")
|
|
37
|
+
return props.file.substring(0, props.file.length - 3);
|
|
38
|
+
return props.file;
|
|
39
|
+
})();
|
|
40
|
+
const composition: IComposition = this.components_.take(
|
|
41
|
+
new Pair(file, props.type),
|
|
42
|
+
() => ({
|
|
43
|
+
location: file,
|
|
44
|
+
elements: new HashSet(),
|
|
45
|
+
default: false,
|
|
46
|
+
type: props.type,
|
|
47
|
+
}),
|
|
48
|
+
);
|
|
49
|
+
if (props.instance === null) {
|
|
50
|
+
composition.default = true;
|
|
51
|
+
if (props.name) composition.name = props.name;
|
|
52
|
+
} else composition.elements.insert(props.instance);
|
|
53
|
+
return props.instance ?? file;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
public toStatements(outDir: string): ts.Statement[] {
|
|
57
|
+
const external: ts.ImportDeclaration[] = [];
|
|
58
|
+
const internal: ts.ImportDeclaration[] = [];
|
|
59
|
+
|
|
60
|
+
const locator = (str: string) => {
|
|
61
|
+
const location: string = path.relative(outDir, str).split("\\").join("/");
|
|
62
|
+
const index: number = location.lastIndexOf(NODE_MODULES);
|
|
63
|
+
return index === -1
|
|
64
|
+
? location.startsWith("..")
|
|
65
|
+
? location
|
|
66
|
+
: `./${location}`
|
|
67
|
+
: location.substring(index + NODE_MODULES.length);
|
|
68
|
+
};
|
|
69
|
+
const enroll =
|
|
70
|
+
(filter: (str: string) => boolean) =>
|
|
71
|
+
(container: ts.ImportDeclaration[]) => {
|
|
72
|
+
const compositions: IComposition[] = this.components_
|
|
73
|
+
.toJSON()
|
|
74
|
+
.filter((c) => filter(c.second.location))
|
|
75
|
+
.map((e) => ({
|
|
76
|
+
...e.second,
|
|
77
|
+
location: locator(e.second.location),
|
|
78
|
+
}))
|
|
79
|
+
.sort((a, b) => a.location.localeCompare(b.location));
|
|
80
|
+
for (const c of compositions) {
|
|
81
|
+
const brackets: string[] = [];
|
|
82
|
+
if (c.default) brackets.push(c.name ?? c.location);
|
|
83
|
+
if (c.elements.empty() === false)
|
|
84
|
+
brackets.push(
|
|
85
|
+
`{ ${c.elements
|
|
86
|
+
.toJSON()
|
|
87
|
+
.sort((a, b) => a.localeCompare(b))
|
|
88
|
+
.join(", ")} }`,
|
|
89
|
+
);
|
|
90
|
+
container.push(
|
|
91
|
+
ts.factory.createImportDeclaration(
|
|
92
|
+
undefined,
|
|
93
|
+
ts.factory.createImportClause(
|
|
94
|
+
c.type,
|
|
95
|
+
c.default
|
|
96
|
+
? ts.factory.createIdentifier(c.name ?? c.location)
|
|
97
|
+
: undefined,
|
|
98
|
+
c.elements.empty() === false
|
|
99
|
+
? ts.factory.createNamedImports(
|
|
100
|
+
[...c.elements].map((elem) =>
|
|
101
|
+
ts.factory.createImportSpecifier(
|
|
102
|
+
false,
|
|
103
|
+
undefined,
|
|
104
|
+
ts.factory.createIdentifier(elem),
|
|
105
|
+
),
|
|
106
|
+
),
|
|
107
|
+
)
|
|
108
|
+
: undefined,
|
|
109
|
+
),
|
|
110
|
+
ts.factory.createStringLiteral(c.location),
|
|
111
|
+
),
|
|
112
|
+
);
|
|
113
|
+
}
|
|
114
|
+
};
|
|
115
|
+
|
|
116
|
+
enroll((str) => str.indexOf(NODE_MODULES) !== -1)(external);
|
|
117
|
+
enroll((str) => str.indexOf(NODE_MODULES) === -1)(internal);
|
|
118
|
+
return [
|
|
119
|
+
...external,
|
|
120
|
+
...(external.length && internal.length ? [FilePrinter.enter()] : []),
|
|
121
|
+
...internal,
|
|
122
|
+
];
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
export namespace ImportDictionary {
|
|
126
|
+
export interface IExternalProps {
|
|
127
|
+
type: boolean;
|
|
128
|
+
library: string;
|
|
129
|
+
instance: string | null;
|
|
130
|
+
}
|
|
131
|
+
export interface IInternalProps {
|
|
132
|
+
type: boolean;
|
|
133
|
+
file: string;
|
|
134
|
+
instance: string | null;
|
|
135
|
+
name?: string | null;
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
interface IComposition {
|
|
140
|
+
location: string;
|
|
141
|
+
type: boolean;
|
|
142
|
+
default: boolean;
|
|
143
|
+
name?: string;
|
|
144
|
+
elements: HashSet<string>;
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
const NODE_MODULES = "node_modules/";
|
|
@@ -1,152 +1,152 @@
|
|
|
1
|
-
import ts from "typescript";
|
|
2
|
-
import typia from "typia";
|
|
3
|
-
|
|
4
|
-
import { INestiaConfig } from "../../INestiaConfig";
|
|
5
|
-
import { IController } from "../../structures/IController";
|
|
6
|
-
import { IRoute } from "../../structures/IRoute";
|
|
7
|
-
import { ImportDictionary } from "./ImportDictionary";
|
|
8
|
-
import { SdkTypeProgrammer } from "./SdkTypeProgrammer";
|
|
9
|
-
|
|
10
|
-
export namespace SdkAliasCollection {
|
|
11
|
-
export const name =
|
|
12
|
-
(config: INestiaConfig) =>
|
|
13
|
-
(importer: ImportDictionary) =>
|
|
14
|
-
(p: IRoute.IParameter | IRoute.IOutput): ts.TypeNode =>
|
|
15
|
-
p.metadata
|
|
16
|
-
? SdkTypeProgrammer.write(config)(importer)(p.metadata)
|
|
17
|
-
: ts.factory.createTypeReferenceNode(p.typeName);
|
|
18
|
-
|
|
19
|
-
export const headers =
|
|
20
|
-
(config: INestiaConfig) =>
|
|
21
|
-
(importer: ImportDictionary) =>
|
|
22
|
-
(param: IRoute.IParameter): ts.TypeNode => {
|
|
23
|
-
const type: ts.TypeNode = name(config)(importer)(param);
|
|
24
|
-
if (config.primitive === false) return type;
|
|
25
|
-
return ts.factory.createTypeReferenceNode(
|
|
26
|
-
importer.external({
|
|
27
|
-
type: true,
|
|
28
|
-
library: "@nestia/fetcher",
|
|
29
|
-
instance: "Resolved",
|
|
30
|
-
}),
|
|
31
|
-
[type],
|
|
32
|
-
);
|
|
33
|
-
};
|
|
34
|
-
|
|
35
|
-
export const query =
|
|
36
|
-
(config: INestiaConfig) =>
|
|
37
|
-
(importer: ImportDictionary) =>
|
|
38
|
-
(param: IRoute.IParameter): ts.TypeNode => {
|
|
39
|
-
const type: ts.TypeNode = name(config)(importer)(param);
|
|
40
|
-
if (config.primitive === false) return type;
|
|
41
|
-
return ts.factory.createTypeReferenceNode(
|
|
42
|
-
importer.external({
|
|
43
|
-
type: true,
|
|
44
|
-
library: "@nestia/fetcher",
|
|
45
|
-
instance: "Resolved",
|
|
46
|
-
}),
|
|
47
|
-
[type],
|
|
48
|
-
);
|
|
49
|
-
};
|
|
50
|
-
|
|
51
|
-
export const input =
|
|
52
|
-
(config: INestiaConfig) =>
|
|
53
|
-
(importer: ImportDictionary) =>
|
|
54
|
-
(param: IRoute.IParameter): ts.TypeNode => {
|
|
55
|
-
const type: ts.TypeNode = name(config)(importer)(param);
|
|
56
|
-
if (config.clone === true || config.primitive === false) return type;
|
|
57
|
-
return ts.factory.createTypeReferenceNode(
|
|
58
|
-
importer.external({
|
|
59
|
-
type: true,
|
|
60
|
-
library: "@nestia/fetcher",
|
|
61
|
-
instance:
|
|
62
|
-
typia.is<IController.IBodyParameter>(param) &&
|
|
63
|
-
param.contentType === "multipart/form-data"
|
|
64
|
-
? "Resolved"
|
|
65
|
-
: "Primitive",
|
|
66
|
-
}),
|
|
67
|
-
[type],
|
|
68
|
-
);
|
|
69
|
-
};
|
|
70
|
-
|
|
71
|
-
export const output =
|
|
72
|
-
(checker: ts.TypeChecker) =>
|
|
73
|
-
(config: INestiaConfig) =>
|
|
74
|
-
(importer: ImportDictionary) =>
|
|
75
|
-
(route: IRoute): ts.TypeNode => {
|
|
76
|
-
if (config.propagate !== true) {
|
|
77
|
-
const node: ts.TypeNode = name(config)(importer)(route.output);
|
|
78
|
-
const type = checker.getTypeAtLocation(node);
|
|
79
|
-
const filter = (flag: ts.TypeFlags) => (type.getFlags() & flag) !== 0;
|
|
80
|
-
|
|
81
|
-
if (
|
|
82
|
-
config.clone === true ||
|
|
83
|
-
config.primitive === false ||
|
|
84
|
-
filter(ts.TypeFlags.Undefined) ||
|
|
85
|
-
filter(ts.TypeFlags.Never) ||
|
|
86
|
-
filter(ts.TypeFlags.Void) ||
|
|
87
|
-
filter(ts.TypeFlags.VoidLike)
|
|
88
|
-
)
|
|
89
|
-
return node;
|
|
90
|
-
return ts.factory.createTypeReferenceNode(
|
|
91
|
-
importer.external({
|
|
92
|
-
type: true,
|
|
93
|
-
library: "@nestia/fetcher",
|
|
94
|
-
instance:
|
|
95
|
-
route.output.contentType === "application/x-www-form-urlencoded"
|
|
96
|
-
? "Resolved"
|
|
97
|
-
: "Primitive",
|
|
98
|
-
}),
|
|
99
|
-
[node],
|
|
100
|
-
);
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
const branches: IBranch[] = [
|
|
104
|
-
{
|
|
105
|
-
status: String(route.status ?? (route.method === "POST" ? 201 : 200)),
|
|
106
|
-
type: name(config)(importer)(route.output),
|
|
107
|
-
},
|
|
108
|
-
...Object.entries(route.exceptions).map(([status, value]) => ({
|
|
109
|
-
status,
|
|
110
|
-
type: name(config)(importer)(value),
|
|
111
|
-
})),
|
|
112
|
-
];
|
|
113
|
-
return ts.factory.createTypeReferenceNode(
|
|
114
|
-
importer.external({
|
|
115
|
-
type: true,
|
|
116
|
-
library: "@nestia/fetcher",
|
|
117
|
-
instance: "IPropagation",
|
|
118
|
-
}),
|
|
119
|
-
[
|
|
120
|
-
ts.factory.createTypeLiteralNode(
|
|
121
|
-
branches.map((b) =>
|
|
122
|
-
ts.factory.createPropertySignature(
|
|
123
|
-
undefined,
|
|
124
|
-
ts.factory.createNumericLiteral(b.status),
|
|
125
|
-
undefined,
|
|
126
|
-
b.type,
|
|
127
|
-
),
|
|
128
|
-
),
|
|
129
|
-
),
|
|
130
|
-
...(route.status
|
|
131
|
-
? [
|
|
132
|
-
ts.factory.createLiteralTypeNode(
|
|
133
|
-
ts.factory.createNumericLiteral(route.status),
|
|
134
|
-
),
|
|
135
|
-
]
|
|
136
|
-
: []),
|
|
137
|
-
],
|
|
138
|
-
);
|
|
139
|
-
};
|
|
140
|
-
|
|
141
|
-
export const responseBody =
|
|
142
|
-
(checker: ts.TypeChecker) =>
|
|
143
|
-
(config: INestiaConfig) =>
|
|
144
|
-
(importer: ImportDictionary) =>
|
|
145
|
-
(route: IRoute): ts.TypeNode =>
|
|
146
|
-
output(checker)({ ...config, propagate: false })(importer)(route);
|
|
147
|
-
}
|
|
148
|
-
|
|
149
|
-
interface IBranch {
|
|
150
|
-
status: string;
|
|
151
|
-
type: ts.TypeNode;
|
|
152
|
-
}
|
|
1
|
+
import ts from "typescript";
|
|
2
|
+
import typia from "typia";
|
|
3
|
+
|
|
4
|
+
import { INestiaConfig } from "../../INestiaConfig";
|
|
5
|
+
import { IController } from "../../structures/IController";
|
|
6
|
+
import { IRoute } from "../../structures/IRoute";
|
|
7
|
+
import { ImportDictionary } from "./ImportDictionary";
|
|
8
|
+
import { SdkTypeProgrammer } from "./SdkTypeProgrammer";
|
|
9
|
+
|
|
10
|
+
export namespace SdkAliasCollection {
|
|
11
|
+
export const name =
|
|
12
|
+
(config: INestiaConfig) =>
|
|
13
|
+
(importer: ImportDictionary) =>
|
|
14
|
+
(p: IRoute.IParameter | IRoute.IOutput): ts.TypeNode =>
|
|
15
|
+
p.metadata
|
|
16
|
+
? SdkTypeProgrammer.write(config)(importer)(p.metadata)
|
|
17
|
+
: ts.factory.createTypeReferenceNode(p.typeName);
|
|
18
|
+
|
|
19
|
+
export const headers =
|
|
20
|
+
(config: INestiaConfig) =>
|
|
21
|
+
(importer: ImportDictionary) =>
|
|
22
|
+
(param: IRoute.IParameter): ts.TypeNode => {
|
|
23
|
+
const type: ts.TypeNode = name(config)(importer)(param);
|
|
24
|
+
if (config.primitive === false) return type;
|
|
25
|
+
return ts.factory.createTypeReferenceNode(
|
|
26
|
+
importer.external({
|
|
27
|
+
type: true,
|
|
28
|
+
library: "@nestia/fetcher",
|
|
29
|
+
instance: "Resolved",
|
|
30
|
+
}),
|
|
31
|
+
[type],
|
|
32
|
+
);
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
export const query =
|
|
36
|
+
(config: INestiaConfig) =>
|
|
37
|
+
(importer: ImportDictionary) =>
|
|
38
|
+
(param: IRoute.IParameter): ts.TypeNode => {
|
|
39
|
+
const type: ts.TypeNode = name(config)(importer)(param);
|
|
40
|
+
if (config.primitive === false) return type;
|
|
41
|
+
return ts.factory.createTypeReferenceNode(
|
|
42
|
+
importer.external({
|
|
43
|
+
type: true,
|
|
44
|
+
library: "@nestia/fetcher",
|
|
45
|
+
instance: "Resolved",
|
|
46
|
+
}),
|
|
47
|
+
[type],
|
|
48
|
+
);
|
|
49
|
+
};
|
|
50
|
+
|
|
51
|
+
export const input =
|
|
52
|
+
(config: INestiaConfig) =>
|
|
53
|
+
(importer: ImportDictionary) =>
|
|
54
|
+
(param: IRoute.IParameter): ts.TypeNode => {
|
|
55
|
+
const type: ts.TypeNode = name(config)(importer)(param);
|
|
56
|
+
if (config.clone === true || config.primitive === false) return type;
|
|
57
|
+
return ts.factory.createTypeReferenceNode(
|
|
58
|
+
importer.external({
|
|
59
|
+
type: true,
|
|
60
|
+
library: "@nestia/fetcher",
|
|
61
|
+
instance:
|
|
62
|
+
typia.is<IController.IBodyParameter>(param) &&
|
|
63
|
+
param.contentType === "multipart/form-data"
|
|
64
|
+
? "Resolved"
|
|
65
|
+
: "Primitive",
|
|
66
|
+
}),
|
|
67
|
+
[type],
|
|
68
|
+
);
|
|
69
|
+
};
|
|
70
|
+
|
|
71
|
+
export const output =
|
|
72
|
+
(checker: ts.TypeChecker) =>
|
|
73
|
+
(config: INestiaConfig) =>
|
|
74
|
+
(importer: ImportDictionary) =>
|
|
75
|
+
(route: IRoute): ts.TypeNode => {
|
|
76
|
+
if (config.propagate !== true) {
|
|
77
|
+
const node: ts.TypeNode = name(config)(importer)(route.output);
|
|
78
|
+
const type = checker.getTypeAtLocation(node);
|
|
79
|
+
const filter = (flag: ts.TypeFlags) => (type.getFlags() & flag) !== 0;
|
|
80
|
+
|
|
81
|
+
if (
|
|
82
|
+
config.clone === true ||
|
|
83
|
+
config.primitive === false ||
|
|
84
|
+
filter(ts.TypeFlags.Undefined) ||
|
|
85
|
+
filter(ts.TypeFlags.Never) ||
|
|
86
|
+
filter(ts.TypeFlags.Void) ||
|
|
87
|
+
filter(ts.TypeFlags.VoidLike)
|
|
88
|
+
)
|
|
89
|
+
return node;
|
|
90
|
+
return ts.factory.createTypeReferenceNode(
|
|
91
|
+
importer.external({
|
|
92
|
+
type: true,
|
|
93
|
+
library: "@nestia/fetcher",
|
|
94
|
+
instance:
|
|
95
|
+
route.output.contentType === "application/x-www-form-urlencoded"
|
|
96
|
+
? "Resolved"
|
|
97
|
+
: "Primitive",
|
|
98
|
+
}),
|
|
99
|
+
[node],
|
|
100
|
+
);
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
const branches: IBranch[] = [
|
|
104
|
+
{
|
|
105
|
+
status: String(route.status ?? (route.method === "POST" ? 201 : 200)),
|
|
106
|
+
type: name(config)(importer)(route.output),
|
|
107
|
+
},
|
|
108
|
+
...Object.entries(route.exceptions).map(([status, value]) => ({
|
|
109
|
+
status,
|
|
110
|
+
type: name(config)(importer)(value),
|
|
111
|
+
})),
|
|
112
|
+
];
|
|
113
|
+
return ts.factory.createTypeReferenceNode(
|
|
114
|
+
importer.external({
|
|
115
|
+
type: true,
|
|
116
|
+
library: "@nestia/fetcher",
|
|
117
|
+
instance: "IPropagation",
|
|
118
|
+
}),
|
|
119
|
+
[
|
|
120
|
+
ts.factory.createTypeLiteralNode(
|
|
121
|
+
branches.map((b) =>
|
|
122
|
+
ts.factory.createPropertySignature(
|
|
123
|
+
undefined,
|
|
124
|
+
ts.factory.createNumericLiteral(b.status),
|
|
125
|
+
undefined,
|
|
126
|
+
b.type,
|
|
127
|
+
),
|
|
128
|
+
),
|
|
129
|
+
),
|
|
130
|
+
...(route.status
|
|
131
|
+
? [
|
|
132
|
+
ts.factory.createLiteralTypeNode(
|
|
133
|
+
ts.factory.createNumericLiteral(route.status),
|
|
134
|
+
),
|
|
135
|
+
]
|
|
136
|
+
: []),
|
|
137
|
+
],
|
|
138
|
+
);
|
|
139
|
+
};
|
|
140
|
+
|
|
141
|
+
export const responseBody =
|
|
142
|
+
(checker: ts.TypeChecker) =>
|
|
143
|
+
(config: INestiaConfig) =>
|
|
144
|
+
(importer: ImportDictionary) =>
|
|
145
|
+
(route: IRoute): ts.TypeNode =>
|
|
146
|
+
output(checker)({ ...config, propagate: false })(importer)(route);
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
interface IBranch {
|
|
150
|
+
status: string;
|
|
151
|
+
type: ts.TypeNode;
|
|
152
|
+
}
|