@nestia/sdk 1.3.2 → 1.3.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/assets/config/nestia.config.ts +70 -70
- package/lib/INestiaConfig.d.ts +13 -0
- package/lib/executable/internal/NestiaSdkConfig.js +6 -2
- package/lib/executable/internal/NestiaSdkConfig.js.map +1 -1
- package/lib/executable/sdk.js +11 -11
- package/lib/generates/SwaggerGenerator.js +9 -9
- package/lib/generates/internal/DistributionComposer.js +1 -1
- package/lib/generates/internal/DistributionComposer.js.map +1 -1
- package/lib/generates/internal/E2eFileProgrammer.js +12 -12
- package/lib/generates/internal/SdkFileProgrammer.js +7 -5
- package/lib/generates/internal/SdkFileProgrammer.js.map +1 -1
- package/lib/generates/internal/SdkFunctionProgrammer.js +42 -49
- package/lib/generates/internal/SdkFunctionProgrammer.js.map +1 -1
- package/package.json +6 -4
- package/src/INestiaConfig.ts +204 -190
- package/src/NestiaSdkApplication.ts +262 -262
- package/src/analyses/ControllerAnalyzer.ts +261 -261
- package/src/analyses/GenericAnalyzer.ts +53 -53
- package/src/analyses/ImportAnalyzer.ts +164 -164
- package/src/analyses/PathAnalyzer.ts +58 -58
- package/src/analyses/ReflectAnalyzer.ts +321 -321
- package/src/executable/internal/CommandParser.ts +15 -15
- package/src/executable/internal/NestiaConfigCompilerOptions.ts +18 -18
- package/src/executable/internal/NestiaSdkCommand.ts +156 -156
- package/src/executable/internal/NestiaSdkConfig.ts +36 -36
- package/src/executable/internal/nestia.config.getter.ts +12 -12
- package/src/executable/sdk.ts +70 -70
- package/src/generates/E2eGenerator.ts +67 -67
- package/src/generates/SdkGenerator.ts +56 -56
- package/src/generates/SwaggerGenerator.ts +504 -504
- package/src/generates/internal/DistributionComposer.ts +98 -97
- package/src/generates/internal/E2eFileProgrammer.ts +135 -135
- package/src/generates/internal/SdkFileProgrammer.ts +150 -144
- package/src/generates/internal/SdkFunctionProgrammer.ts +51 -58
- package/src/generates/internal/SdkRouteDirectory.ts +21 -21
- package/src/index.ts +4 -4
- package/src/module.ts +2 -2
- package/src/structures/IController.ts +31 -31
- package/src/structures/IRoute.ts +39 -39
- package/src/structures/ISwaggerDocument.ts +120 -120
- package/src/structures/ITypeTuple.ts +6 -6
- package/src/structures/MethodType.ts +11 -11
- package/src/structures/ParamCategory.ts +1 -1
- package/src/structures/TypeEntry.ts +22 -22
- package/src/utils/ArrayUtil.ts +26 -26
- package/src/utils/FileRetriever.ts +22 -22
- package/src/utils/ImportDictionary.ts +56 -56
- package/src/utils/MapUtil.ts +14 -14
- package/src/utils/NestiaConfigUtil.ts +21 -21
- package/src/utils/SourceFinder.ts +60 -60
- package/src/utils/StripEnums.ts +10 -10
|
@@ -1,144 +1,150 @@
|
|
|
1
|
-
import fs from "fs";
|
|
2
|
-
|
|
3
|
-
import { INestiaConfig } from "../../INestiaConfig";
|
|
4
|
-
import { IRoute } from "../../structures/IRoute";
|
|
5
|
-
import { ImportDictionary } from "../../utils/ImportDictionary";
|
|
6
|
-
import { SdkFunctionProgrammer } from "./SdkFunctionProgrammer";
|
|
7
|
-
import { SdkRouteDirectory } from "./SdkRouteDirectory";
|
|
8
|
-
|
|
9
|
-
export namespace SdkFileProgrammer {
|
|
10
|
-
/* ---------------------------------------------------------
|
|
11
|
-
CONSTRUCTOR
|
|
12
|
-
--------------------------------------------------------- */
|
|
13
|
-
export const generate =
|
|
14
|
-
(config: INestiaConfig) =>
|
|
15
|
-
async (routeList: IRoute[]): Promise<void> => {
|
|
16
|
-
// CONSTRUCT FOLDER TREE
|
|
17
|
-
const root: SdkRouteDirectory = new SdkRouteDirectory(
|
|
18
|
-
null,
|
|
19
|
-
"functional",
|
|
20
|
-
);
|
|
21
|
-
for (const route of routeList) emplace(root)(route);
|
|
22
|
-
|
|
23
|
-
// RELOCATE FOR ONLY ONE CONTROLLER METHOD IN AN URL CASE
|
|
24
|
-
relocate(root);
|
|
25
|
-
|
|
26
|
-
// ITERATE FILES
|
|
27
|
-
await iterate(config)(root)(config.output + "/functional");
|
|
28
|
-
};
|
|
29
|
-
|
|
30
|
-
const emplace =
|
|
31
|
-
(directory: SdkRouteDirectory) =>
|
|
32
|
-
(route: IRoute): void => {
|
|
33
|
-
// SEPARATE IDENTIFIERS
|
|
34
|
-
const identifiers: string[] = route.path
|
|
35
|
-
.split("/")
|
|
36
|
-
.filter((str) => str.length && str[0] !== ":")
|
|
37
|
-
.map((str) => str.split("-").join("_").split(".").join("_"));
|
|
38
|
-
|
|
39
|
-
// OPEN DIRECTORIES
|
|
40
|
-
for (const key of identifiers) {
|
|
41
|
-
directory = directory.directories.take(
|
|
42
|
-
key,
|
|
43
|
-
() => new SdkRouteDirectory(directory, key),
|
|
44
|
-
);
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
// ADD ROUTE
|
|
48
|
-
directory.routes.push(route);
|
|
49
|
-
};
|
|
50
|
-
|
|
51
|
-
const relocate = (directory: SdkRouteDirectory): void => {
|
|
52
|
-
if (
|
|
53
|
-
directory.parent !== null &&
|
|
54
|
-
directory.directories.empty() &&
|
|
55
|
-
directory.routes.length === 1 &&
|
|
56
|
-
directory.name === directory.routes[0].name
|
|
57
|
-
) {
|
|
58
|
-
directory.parent.routes.push(directory.routes[0]);
|
|
59
|
-
directory.parent.directories.erase(directory.name);
|
|
60
|
-
} else if (directory.directories.empty() === false)
|
|
61
|
-
for (const it of directory.directories) relocate(it.second);
|
|
62
|
-
};
|
|
63
|
-
|
|
64
|
-
/* ---------------------------------------------------------
|
|
65
|
-
FILE ITERATOR
|
|
66
|
-
--------------------------------------------------------- */
|
|
67
|
-
const iterate =
|
|
68
|
-
(config: INestiaConfig) =>
|
|
69
|
-
(directory: SdkRouteDirectory) =>
|
|
70
|
-
async (outDir: string): Promise<void> => {
|
|
71
|
-
// CREATE A NEW DIRECTORY
|
|
72
|
-
try {
|
|
73
|
-
await fs.promises.mkdir(outDir);
|
|
74
|
-
} catch {}
|
|
75
|
-
|
|
76
|
-
// ITERATE CHILDREN
|
|
77
|
-
const content: string[] = [];
|
|
78
|
-
for (const it of directory.directories) {
|
|
79
|
-
await iterate(config)(it.second)(`${outDir}/${it.first}`);
|
|
80
|
-
content.push(`export * as ${it.first} from "./${it.first}";`);
|
|
81
|
-
}
|
|
82
|
-
if (content.length && directory.routes.length) content.push("");
|
|
83
|
-
|
|
84
|
-
// ITERATE ROUTES
|
|
85
|
-
const importDict: ImportDictionary = new ImportDictionary();
|
|
86
|
-
directory.routes.forEach((route, i) => {
|
|
87
|
-
for (const tuple of route.imports)
|
|
88
|
-
for (const instance of tuple[1])
|
|
89
|
-
importDict.emplace(tuple[0], false, instance);
|
|
90
|
-
|
|
91
|
-
content.push(SdkFunctionProgrammer.generate(config)(route));
|
|
92
|
-
if (i !== directory.routes.length - 1) content.push("");
|
|
93
|
-
});
|
|
94
|
-
|
|
95
|
-
// FINALIZE THE CONTENT
|
|
96
|
-
if (directory.routes.length !== 0) {
|
|
97
|
-
const primitived: boolean =
|
|
98
|
-
config.primitive !== false &&
|
|
99
|
-
directory.routes.some(
|
|
100
|
-
(route) =>
|
|
101
|
-
route.output.name !== "void" ||
|
|
102
|
-
route.parameters.some(
|
|
103
|
-
(param) => param.category !== "param",
|
|
104
|
-
),
|
|
105
|
-
);
|
|
106
|
-
const asserted: boolean =
|
|
107
|
-
config.assert === true &&
|
|
108
|
-
directory.routes.some(
|
|
109
|
-
(route) => route.parameters.length !== 0,
|
|
110
|
-
);
|
|
111
|
-
const json: boolean =
|
|
112
|
-
config.json === true &&
|
|
113
|
-
directory.routes.some(
|
|
114
|
-
(route) =>
|
|
115
|
-
route.method === "POST" ||
|
|
116
|
-
route.method === "PUT" ||
|
|
117
|
-
route.method === "PATCH",
|
|
118
|
-
);
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
const
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
]
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
1
|
+
import fs from "fs";
|
|
2
|
+
|
|
3
|
+
import { INestiaConfig } from "../../INestiaConfig";
|
|
4
|
+
import { IRoute } from "../../structures/IRoute";
|
|
5
|
+
import { ImportDictionary } from "../../utils/ImportDictionary";
|
|
6
|
+
import { SdkFunctionProgrammer } from "./SdkFunctionProgrammer";
|
|
7
|
+
import { SdkRouteDirectory } from "./SdkRouteDirectory";
|
|
8
|
+
|
|
9
|
+
export namespace SdkFileProgrammer {
|
|
10
|
+
/* ---------------------------------------------------------
|
|
11
|
+
CONSTRUCTOR
|
|
12
|
+
--------------------------------------------------------- */
|
|
13
|
+
export const generate =
|
|
14
|
+
(config: INestiaConfig) =>
|
|
15
|
+
async (routeList: IRoute[]): Promise<void> => {
|
|
16
|
+
// CONSTRUCT FOLDER TREE
|
|
17
|
+
const root: SdkRouteDirectory = new SdkRouteDirectory(
|
|
18
|
+
null,
|
|
19
|
+
"functional",
|
|
20
|
+
);
|
|
21
|
+
for (const route of routeList) emplace(root)(route);
|
|
22
|
+
|
|
23
|
+
// RELOCATE FOR ONLY ONE CONTROLLER METHOD IN AN URL CASE
|
|
24
|
+
relocate(root);
|
|
25
|
+
|
|
26
|
+
// ITERATE FILES
|
|
27
|
+
await iterate(config)(root)(config.output + "/functional");
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
const emplace =
|
|
31
|
+
(directory: SdkRouteDirectory) =>
|
|
32
|
+
(route: IRoute): void => {
|
|
33
|
+
// SEPARATE IDENTIFIERS
|
|
34
|
+
const identifiers: string[] = route.path
|
|
35
|
+
.split("/")
|
|
36
|
+
.filter((str) => str.length && str[0] !== ":")
|
|
37
|
+
.map((str) => str.split("-").join("_").split(".").join("_"));
|
|
38
|
+
|
|
39
|
+
// OPEN DIRECTORIES
|
|
40
|
+
for (const key of identifiers) {
|
|
41
|
+
directory = directory.directories.take(
|
|
42
|
+
key,
|
|
43
|
+
() => new SdkRouteDirectory(directory, key),
|
|
44
|
+
);
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
// ADD ROUTE
|
|
48
|
+
directory.routes.push(route);
|
|
49
|
+
};
|
|
50
|
+
|
|
51
|
+
const relocate = (directory: SdkRouteDirectory): void => {
|
|
52
|
+
if (
|
|
53
|
+
directory.parent !== null &&
|
|
54
|
+
directory.directories.empty() &&
|
|
55
|
+
directory.routes.length === 1 &&
|
|
56
|
+
directory.name === directory.routes[0].name
|
|
57
|
+
) {
|
|
58
|
+
directory.parent.routes.push(directory.routes[0]);
|
|
59
|
+
directory.parent.directories.erase(directory.name);
|
|
60
|
+
} else if (directory.directories.empty() === false)
|
|
61
|
+
for (const it of directory.directories) relocate(it.second);
|
|
62
|
+
};
|
|
63
|
+
|
|
64
|
+
/* ---------------------------------------------------------
|
|
65
|
+
FILE ITERATOR
|
|
66
|
+
--------------------------------------------------------- */
|
|
67
|
+
const iterate =
|
|
68
|
+
(config: INestiaConfig) =>
|
|
69
|
+
(directory: SdkRouteDirectory) =>
|
|
70
|
+
async (outDir: string): Promise<void> => {
|
|
71
|
+
// CREATE A NEW DIRECTORY
|
|
72
|
+
try {
|
|
73
|
+
await fs.promises.mkdir(outDir);
|
|
74
|
+
} catch {}
|
|
75
|
+
|
|
76
|
+
// ITERATE CHILDREN
|
|
77
|
+
const content: string[] = [];
|
|
78
|
+
for (const it of directory.directories) {
|
|
79
|
+
await iterate(config)(it.second)(`${outDir}/${it.first}`);
|
|
80
|
+
content.push(`export * as ${it.first} from "./${it.first}";`);
|
|
81
|
+
}
|
|
82
|
+
if (content.length && directory.routes.length) content.push("");
|
|
83
|
+
|
|
84
|
+
// ITERATE ROUTES
|
|
85
|
+
const importDict: ImportDictionary = new ImportDictionary();
|
|
86
|
+
directory.routes.forEach((route, i) => {
|
|
87
|
+
for (const tuple of route.imports)
|
|
88
|
+
for (const instance of tuple[1])
|
|
89
|
+
importDict.emplace(tuple[0], false, instance);
|
|
90
|
+
|
|
91
|
+
content.push(SdkFunctionProgrammer.generate(config)(route));
|
|
92
|
+
if (i !== directory.routes.length - 1) content.push("");
|
|
93
|
+
});
|
|
94
|
+
|
|
95
|
+
// FINALIZE THE CONTENT
|
|
96
|
+
if (directory.routes.length !== 0) {
|
|
97
|
+
const primitived: boolean =
|
|
98
|
+
config.primitive !== false &&
|
|
99
|
+
directory.routes.some(
|
|
100
|
+
(route) =>
|
|
101
|
+
route.output.name !== "void" ||
|
|
102
|
+
route.parameters.some(
|
|
103
|
+
(param) => param.category !== "param",
|
|
104
|
+
),
|
|
105
|
+
);
|
|
106
|
+
const asserted: boolean =
|
|
107
|
+
config.assert === true &&
|
|
108
|
+
directory.routes.some(
|
|
109
|
+
(route) => route.parameters.length !== 0,
|
|
110
|
+
);
|
|
111
|
+
const json: boolean =
|
|
112
|
+
config.json === true &&
|
|
113
|
+
directory.routes.some(
|
|
114
|
+
(route) =>
|
|
115
|
+
route.method === "POST" ||
|
|
116
|
+
route.method === "PUT" ||
|
|
117
|
+
route.method === "PATCH",
|
|
118
|
+
);
|
|
119
|
+
const random: boolean =
|
|
120
|
+
config.random === true &&
|
|
121
|
+
directory.routes.some((s) => s.output.name !== "void");
|
|
122
|
+
|
|
123
|
+
const typings: string[] = ["IConnection"];
|
|
124
|
+
if (primitived) typings.push("Primitive");
|
|
125
|
+
|
|
126
|
+
const head: string[] = [
|
|
127
|
+
`import { Fetcher } from "@nestia/fetcher";`,
|
|
128
|
+
`import type { ${typings.join(
|
|
129
|
+
", ",
|
|
130
|
+
)} } from "@nestia/fetcher";`,
|
|
131
|
+
];
|
|
132
|
+
if (asserted || json || random)
|
|
133
|
+
head.push(`import typia from "typia";`);
|
|
134
|
+
if (!importDict.empty())
|
|
135
|
+
head.push("", importDict.toScript(outDir));
|
|
136
|
+
|
|
137
|
+
content.push(...head, "", ...content.splice(0, content.length));
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
const script: string =
|
|
141
|
+
"/**\n" +
|
|
142
|
+
" * @packageDocumentation\n" +
|
|
143
|
+
` * @module ${directory.module}\n` +
|
|
144
|
+
" * @nestia Generated by Nestia - https://github.com/samchon/nestia \n" +
|
|
145
|
+
" */\n" +
|
|
146
|
+
"//================================================================\n" +
|
|
147
|
+
content.join("\n");
|
|
148
|
+
await fs.promises.writeFile(`${outDir}/index.ts`, script, "utf8");
|
|
149
|
+
};
|
|
150
|
+
}
|
|
@@ -1,6 +1,4 @@
|
|
|
1
|
-
import { Vector } from "tstl/container/Vector";
|
|
2
1
|
import { Pair } from "tstl/utility/Pair";
|
|
3
|
-
import ts from "typescript";
|
|
4
2
|
|
|
5
3
|
import { Escaper } from "typia/lib/utils/Escaper";
|
|
6
4
|
|
|
@@ -19,10 +17,10 @@ export namespace SdkFunctionProgrammer {
|
|
|
19
17
|
(param) => param.category === "body",
|
|
20
18
|
);
|
|
21
19
|
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
20
|
+
const [x, y, z] = [head, body, tail].map((closure) =>
|
|
21
|
+
closure(config)(route)({ query, input }),
|
|
22
|
+
);
|
|
23
|
+
return `${x} ${y}\n${z}`;
|
|
26
24
|
};
|
|
27
25
|
|
|
28
26
|
/* ---------------------------------------------------------
|
|
@@ -62,20 +60,43 @@ export namespace SdkFunctionProgrammer {
|
|
|
62
60
|
: "";
|
|
63
61
|
|
|
64
62
|
// FUNCTION CALL STATEMENT
|
|
65
|
-
const caller:
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
63
|
+
const caller = (awa: boolean) => {
|
|
64
|
+
const random = () =>
|
|
65
|
+
route.output.name === "void"
|
|
66
|
+
? "undefined"
|
|
67
|
+
: [
|
|
68
|
+
`${route.name}.random(`,
|
|
69
|
+
`${space(
|
|
70
|
+
14,
|
|
71
|
+
)}typeof connection.random === "object" &&`,
|
|
72
|
+
`${space(18)}connection.random !== null`,
|
|
73
|
+
`${space(18)}? connection.random`,
|
|
74
|
+
`${space(18)}: undefined`,
|
|
75
|
+
`${space(10)})`,
|
|
76
|
+
].join("\n");
|
|
77
|
+
const fetch = (tab: string) =>
|
|
78
|
+
[
|
|
79
|
+
`${awa ? "await " : ""}Fetcher.fetch(`,
|
|
80
|
+
fetchArguments
|
|
81
|
+
.map((param) => `${tab} ${param},`)
|
|
82
|
+
.join("\n"),
|
|
83
|
+
`${tab})`,
|
|
84
|
+
].join("\n");
|
|
85
|
+
if (!config.random) return fetch(space(4));
|
|
86
|
+
return (
|
|
87
|
+
`!!connection.random\n` +
|
|
88
|
+
` ? ${random()}\n` +
|
|
89
|
+
` : ${fetch(space(10))}`
|
|
90
|
+
);
|
|
91
|
+
};
|
|
71
92
|
if (route.setHeaders.length === 0)
|
|
72
|
-
return `{\n${assertions} return ${caller};\n}`;
|
|
93
|
+
return `{\n${assertions} return ${caller(false)};\n}`;
|
|
73
94
|
|
|
74
95
|
// SET HEADERS
|
|
75
96
|
const content: string[] = [
|
|
76
97
|
`{\n`,
|
|
77
98
|
assertions,
|
|
78
|
-
` const output: ${route.name}.Output =
|
|
99
|
+
` const output: ${route.name}.Output = ${caller(true)};\n`,
|
|
79
100
|
"\n",
|
|
80
101
|
` // configure header(s)\n`,
|
|
81
102
|
` connection.headers ??= {};\n`,
|
|
@@ -136,35 +157,6 @@ export namespace SdkFunctionProgrammer {
|
|
|
136
157
|
? route.description.split("\n")
|
|
137
158
|
: [];
|
|
138
159
|
|
|
139
|
-
// FILTER TAGS (VULNERABLE PARAMETERS WOULD BE REMOVED)
|
|
140
|
-
const tagList: ts.JSDocTagInfo[] = route.tags.slice();
|
|
141
|
-
if (tagList.length !== 0) {
|
|
142
|
-
const index: number = tagList.findIndex(
|
|
143
|
-
(t) => t.name === "param",
|
|
144
|
-
);
|
|
145
|
-
if (index !== -1) {
|
|
146
|
-
const capsule: Vector<ts.JSDocTagInfo> =
|
|
147
|
-
Vector.wrap(tagList);
|
|
148
|
-
capsule.insert(capsule.nth(index), {
|
|
149
|
-
name: "param",
|
|
150
|
-
text: [
|
|
151
|
-
{
|
|
152
|
-
kind: "parameterName",
|
|
153
|
-
text: "connection",
|
|
154
|
-
},
|
|
155
|
-
{
|
|
156
|
-
kind: "space",
|
|
157
|
-
text: " ",
|
|
158
|
-
},
|
|
159
|
-
{
|
|
160
|
-
kind: "text",
|
|
161
|
-
text: "connection Information of the remote HTTP(s) server with headers (+encryption password)",
|
|
162
|
-
},
|
|
163
|
-
],
|
|
164
|
-
});
|
|
165
|
-
}
|
|
166
|
-
}
|
|
167
|
-
|
|
168
160
|
// COMPLETE THE COMMENT
|
|
169
161
|
if (!!comments.length) comments.push("");
|
|
170
162
|
comments.push(
|
|
@@ -202,12 +194,9 @@ export namespace SdkFunctionProgrammer {
|
|
|
202
194
|
comments.map((str) => ` * ${str}`).join("\n") +
|
|
203
195
|
"\n" +
|
|
204
196
|
" */\n" +
|
|
205
|
-
`export
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
` (\n` +
|
|
209
|
-
`${parameters.map((str) => ` ${str}`).join(",\n")}\n` +
|
|
210
|
-
` ): Promise<${output}>`
|
|
197
|
+
`export async function ${route.name}(\n` +
|
|
198
|
+
parameters.map((str) => ` ${str},\n`).join("") +
|
|
199
|
+
`): Promise<${output}>`
|
|
211
200
|
);
|
|
212
201
|
};
|
|
213
202
|
|
|
@@ -217,7 +206,7 @@ export namespace SdkFunctionProgrammer {
|
|
|
217
206
|
(props: {
|
|
218
207
|
query: IRoute.IParameter | undefined;
|
|
219
208
|
input: IRoute.IParameter | undefined;
|
|
220
|
-
}): string
|
|
209
|
+
}): string => {
|
|
221
210
|
// LIST UP TYPES
|
|
222
211
|
const types: Pair<string, string>[] = [];
|
|
223
212
|
if (props.query !== undefined)
|
|
@@ -238,8 +227,7 @@ export namespace SdkFunctionProgrammer {
|
|
|
238
227
|
});
|
|
239
228
|
|
|
240
229
|
return (
|
|
241
|
-
`export namespace ${route.name}\n` +
|
|
242
|
-
"{\n" +
|
|
230
|
+
`export namespace ${route.name} {\n` +
|
|
243
231
|
(types.length !== 0
|
|
244
232
|
? types
|
|
245
233
|
.map(
|
|
@@ -265,12 +253,15 @@ export namespace SdkFunctionProgrammer {
|
|
|
265
253
|
: "") +
|
|
266
254
|
` };\n` +
|
|
267
255
|
"\n" +
|
|
268
|
-
` export
|
|
256
|
+
` export const path = (${parameters
|
|
269
257
|
.map((param) => `${param.name}: ${param.type.name}`)
|
|
270
|
-
.join(", ")}): string\n` +
|
|
271
|
-
` {\n` +
|
|
258
|
+
.join(", ")}): string => {\n` +
|
|
272
259
|
`${path};\n` +
|
|
273
260
|
` }\n` +
|
|
261
|
+
(config.random && route.output.name !== "void"
|
|
262
|
+
? ` export const random = (g?: Partial<typia.IRandomGenerator>): Output =>\n` +
|
|
263
|
+
` typia.random<Output>(g);\n`
|
|
264
|
+
: "") +
|
|
274
265
|
(config.json === true &&
|
|
275
266
|
route.parameters.find((param) => param.category === "body") !==
|
|
276
267
|
undefined
|
|
@@ -297,7 +288,7 @@ export namespace SdkFunctionProgrammer {
|
|
|
297
288
|
(param) => param.category === "query" && param.field !== undefined,
|
|
298
289
|
);
|
|
299
290
|
if (props.query === undefined && queryParams.length === 0)
|
|
300
|
-
return `${
|
|
291
|
+
return `${space(8)}return \`${props.path}\``;
|
|
301
292
|
|
|
302
293
|
const computeName = (str: string): string =>
|
|
303
294
|
props.parameters.find((p) => p.name === str) !== undefined
|
|
@@ -320,7 +311,7 @@ export namespace SdkFunctionProgrammer {
|
|
|
320
311
|
`const ${encoded}: string = ${search}.toString();`,
|
|
321
312
|
`return \`${props.path}\${${encoded}.length ? \`?\${${encoded}}\` : ""}\`;`,
|
|
322
313
|
]
|
|
323
|
-
.map((str) => `${
|
|
314
|
+
.map((str) => `${space(8)}${str}`)
|
|
324
315
|
.join("\n");
|
|
325
316
|
|
|
326
317
|
if (props.query !== undefined && queryParams.length === 0)
|
|
@@ -349,5 +340,7 @@ export namespace SdkFunctionProgrammer {
|
|
|
349
340
|
: JSON.stringify(param.field)
|
|
350
341
|
}: ${param.name}`,
|
|
351
342
|
)
|
|
352
|
-
.join(`,\n${
|
|
343
|
+
.join(`,\n${space(12)}`);
|
|
353
344
|
}
|
|
345
|
+
|
|
346
|
+
const space = (count: number) => " ".repeat(count);
|
|
@@ -1,21 +1,21 @@
|
|
|
1
|
-
import { HashMap } from "tstl";
|
|
2
|
-
|
|
3
|
-
import { IRoute } from "../../structures/IRoute";
|
|
4
|
-
|
|
5
|
-
export class SdkRouteDirectory {
|
|
6
|
-
public readonly module: string;
|
|
7
|
-
public readonly directories: HashMap<string, SdkRouteDirectory>;
|
|
8
|
-
public readonly routes: IRoute[];
|
|
9
|
-
|
|
10
|
-
public constructor(
|
|
11
|
-
readonly parent: SdkRouteDirectory | null,
|
|
12
|
-
readonly name: string,
|
|
13
|
-
) {
|
|
14
|
-
this.directories = new HashMap();
|
|
15
|
-
this.routes = [];
|
|
16
|
-
this.module =
|
|
17
|
-
this.parent !== null
|
|
18
|
-
? `${this.parent.module}.${name}`
|
|
19
|
-
: `api.${name}`;
|
|
20
|
-
}
|
|
21
|
-
}
|
|
1
|
+
import { HashMap } from "tstl";
|
|
2
|
+
|
|
3
|
+
import { IRoute } from "../../structures/IRoute";
|
|
4
|
+
|
|
5
|
+
export class SdkRouteDirectory {
|
|
6
|
+
public readonly module: string;
|
|
7
|
+
public readonly directories: HashMap<string, SdkRouteDirectory>;
|
|
8
|
+
public readonly routes: IRoute[];
|
|
9
|
+
|
|
10
|
+
public constructor(
|
|
11
|
+
readonly parent: SdkRouteDirectory | null,
|
|
12
|
+
readonly name: string,
|
|
13
|
+
) {
|
|
14
|
+
this.directories = new HashMap();
|
|
15
|
+
this.routes = [];
|
|
16
|
+
this.module =
|
|
17
|
+
this.parent !== null
|
|
18
|
+
? `${this.parent.module}.${name}`
|
|
19
|
+
: `api.${name}`;
|
|
20
|
+
}
|
|
21
|
+
}
|
package/src/index.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import * as nestia from "./module";
|
|
2
|
-
|
|
3
|
-
export * from "./module";
|
|
4
|
-
export default nestia;
|
|
1
|
+
import * as nestia from "./module";
|
|
2
|
+
|
|
3
|
+
export * from "./module";
|
|
4
|
+
export default nestia;
|
package/src/module.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export * from "./INestiaConfig";
|
|
2
|
-
export * from "./NestiaSdkApplication";
|
|
1
|
+
export * from "./INestiaConfig";
|
|
2
|
+
export * from "./NestiaSdkApplication";
|
|
@@ -1,31 +1,31 @@
|
|
|
1
|
-
import { ParamCategory } from "./ParamCategory";
|
|
2
|
-
|
|
3
|
-
export interface IController {
|
|
4
|
-
file: string;
|
|
5
|
-
name: string;
|
|
6
|
-
paths: string[];
|
|
7
|
-
functions: IController.IFunction[];
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
export namespace IController {
|
|
11
|
-
export interface IFunction {
|
|
12
|
-
name: string;
|
|
13
|
-
method: string;
|
|
14
|
-
paths: string[];
|
|
15
|
-
encrypted: boolean;
|
|
16
|
-
parameters: IParameter[];
|
|
17
|
-
status?: number;
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
export interface IParameter {
|
|
21
|
-
name: string;
|
|
22
|
-
index: number;
|
|
23
|
-
field: string | undefined;
|
|
24
|
-
category: ParamCategory;
|
|
25
|
-
encrypted: boolean;
|
|
26
|
-
meta?: {
|
|
27
|
-
type: string;
|
|
28
|
-
nullable: boolean;
|
|
29
|
-
};
|
|
30
|
-
}
|
|
31
|
-
}
|
|
1
|
+
import { ParamCategory } from "./ParamCategory";
|
|
2
|
+
|
|
3
|
+
export interface IController {
|
|
4
|
+
file: string;
|
|
5
|
+
name: string;
|
|
6
|
+
paths: string[];
|
|
7
|
+
functions: IController.IFunction[];
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export namespace IController {
|
|
11
|
+
export interface IFunction {
|
|
12
|
+
name: string;
|
|
13
|
+
method: string;
|
|
14
|
+
paths: string[];
|
|
15
|
+
encrypted: boolean;
|
|
16
|
+
parameters: IParameter[];
|
|
17
|
+
status?: number;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export interface IParameter {
|
|
21
|
+
name: string;
|
|
22
|
+
index: number;
|
|
23
|
+
field: string | undefined;
|
|
24
|
+
category: ParamCategory;
|
|
25
|
+
encrypted: boolean;
|
|
26
|
+
meta?: {
|
|
27
|
+
type: string;
|
|
28
|
+
nullable: boolean;
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
}
|