@nestia/sdk 1.6.7 → 2.0.0-dev.20230830
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/generates/E2eGenerator.js +2 -1
- package/lib/generates/E2eGenerator.js.map +1 -1
- package/lib/generates/internal/E2eFileProgrammer.d.ts +2 -1
- package/lib/generates/internal/E2eFileProgrammer.js +30 -19
- package/lib/generates/internal/E2eFileProgrammer.js.map +1 -1
- package/lib/generates/internal/SdkFileProgrammer.js +14 -30
- package/lib/generates/internal/SdkFileProgrammer.js.map +1 -1
- package/lib/generates/internal/SdkFunctionProgrammer.d.ts +2 -1
- package/lib/generates/internal/SdkFunctionProgrammer.js +72 -26
- package/lib/generates/internal/SdkFunctionProgrammer.js.map +1 -1
- package/lib/generates/internal/SdkSimulationProgrammer.d.ts +3 -1
- package/lib/generates/internal/SdkSimulationProgrammer.js +42 -24
- package/lib/generates/internal/SdkSimulationProgrammer.js.map +1 -1
- package/lib/utils/ImportDictionary.d.ts +16 -2
- package/lib/utils/ImportDictionary.js +66 -25
- package/lib/utils/ImportDictionary.js.map +1 -1
- package/package.json +3 -3
- package/src/generates/E2eGenerator.ts +4 -1
- package/src/generates/internal/E2eFileProgrammer.ts +36 -19
- package/src/generates/internal/SdkFileProgrammer.ts +20 -56
- package/src/generates/internal/SdkFunctionProgrammer.ts +85 -24
- package/src/generates/internal/SdkSimulationProgrammer.ts +107 -73
- package/src/utils/ImportDictionary.ts +97 -33
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SdkSimulationProgrammer.js","sourceRoot":"","sources":["../../../src/generates/internal/SdkSimulationProgrammer.ts"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"SdkSimulationProgrammer.js","sourceRoot":"","sources":["../../../src/generates/internal/SdkSimulationProgrammer.ts"],"names":[],"mappings":";;;AAIA,IAAiB,uBAAuB,CA4GvC;AA5GD,WAAiB,uBAAuB;IACvB,gCAAQ,GACjB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Dictionary {
|
|
2
|
-
private readonly
|
|
2
|
+
private readonly externals_;
|
|
3
|
+
private readonly internals_;
|
|
3
4
|
empty(): boolean;
|
|
4
|
-
|
|
5
|
+
external(props: ImportDictionary.IExternalProps): string;
|
|
6
|
+
internal(props: ImportDictionary.IInternalProps): string;
|
|
5
7
|
toScript(outDir: string): string;
|
|
6
8
|
}
|
|
9
|
+
export declare namespace ImportDictionary {
|
|
10
|
+
interface IInternalProps {
|
|
11
|
+
type: boolean;
|
|
12
|
+
file: string;
|
|
13
|
+
instance: string;
|
|
14
|
+
}
|
|
15
|
+
interface IExternalProps {
|
|
16
|
+
type: boolean;
|
|
17
|
+
library: string;
|
|
18
|
+
instance: string | null;
|
|
19
|
+
}
|
|
20
|
+
}
|
|
@@ -10,38 +10,79 @@ const HashSet_1 = require("tstl/container/HashSet");
|
|
|
10
10
|
const Pair_1 = require("tstl/utility/Pair");
|
|
11
11
|
class ImportDictionary {
|
|
12
12
|
constructor() {
|
|
13
|
-
this.
|
|
13
|
+
this.externals_ = new HashMap_1.HashMap();
|
|
14
|
+
this.internals_ = new HashMap_1.HashMap();
|
|
14
15
|
}
|
|
15
16
|
empty() {
|
|
16
|
-
return this.
|
|
17
|
+
return this.internals_.empty() && this.externals_.empty();
|
|
17
18
|
}
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
19
|
+
external(props) {
|
|
20
|
+
var _a;
|
|
21
|
+
const composition = this.externals_.take(new Pair_1.Pair(props.library, props.type), () => ({
|
|
22
|
+
location: props.library,
|
|
23
|
+
elements: new HashSet_1.HashSet(),
|
|
24
|
+
default: false,
|
|
25
|
+
type: props.type,
|
|
26
|
+
}));
|
|
27
|
+
if (props.instance === null)
|
|
28
|
+
composition.default = true;
|
|
23
29
|
else
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
30
|
+
composition.elements.insert(props.instance);
|
|
31
|
+
return (_a = props.instance) !== null && _a !== void 0 ? _a : props.library;
|
|
32
|
+
}
|
|
33
|
+
internal(props) {
|
|
34
|
+
var _a;
|
|
35
|
+
const file = (() => {
|
|
36
|
+
if (props.file.substring(props.file.length - 5) === ".d.ts")
|
|
37
|
+
return props.file.substring(0, props.file.length - 5);
|
|
38
|
+
else if (props.file.substring(0, props.file.length - 3) === ".ts")
|
|
39
|
+
return props.file.substring(0, props.file.length - 3);
|
|
40
|
+
throw new Error(`Error on ImportDictionary.emplace(): extension of the target file "${props.file}" is not "ts".`);
|
|
41
|
+
})();
|
|
42
|
+
const composition = this.internals_.take(new Pair_1.Pair(file, props.type), () => ({
|
|
43
|
+
location: file,
|
|
44
|
+
elements: new HashSet_1.HashSet(),
|
|
45
|
+
default: false,
|
|
46
|
+
type: props.type,
|
|
47
|
+
}));
|
|
48
|
+
if (props.instance === null)
|
|
49
|
+
composition.default = true;
|
|
50
|
+
else
|
|
51
|
+
composition.elements.insert(props.instance);
|
|
52
|
+
return (_a = props.instance) !== null && _a !== void 0 ? _a : file;
|
|
27
53
|
}
|
|
28
54
|
toScript(outDir) {
|
|
29
55
|
const statements = [];
|
|
30
|
-
|
|
31
|
-
const
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
const
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
56
|
+
const enroll = (locator) => (dict) => {
|
|
57
|
+
const compositions = dict
|
|
58
|
+
.toJSON()
|
|
59
|
+
.map((e) => (Object.assign(Object.assign({}, e.second), { location: locator(e.second.location) })))
|
|
60
|
+
.sort((a, b) => a.location.localeCompare(b.location));
|
|
61
|
+
for (const c of compositions) {
|
|
62
|
+
const brackets = [];
|
|
63
|
+
if (c.default)
|
|
64
|
+
brackets.push(c.location);
|
|
65
|
+
if (c.elements.empty() === false)
|
|
66
|
+
brackets.push(`{${c.elements
|
|
67
|
+
.toJSON()
|
|
68
|
+
.sort((a, b) => a.localeCompare(b))
|
|
69
|
+
.join(", ")}`);
|
|
70
|
+
statements.push(`import ${c.type ? "type " : ""} ${brackets.join(", ")} from "${c.location}";`);
|
|
71
|
+
}
|
|
72
|
+
};
|
|
73
|
+
enroll((str) => str)(this.externals_);
|
|
74
|
+
if (this.internals_.size())
|
|
75
|
+
statements.push("");
|
|
76
|
+
enroll((str) => {
|
|
77
|
+
const location = path_1.default
|
|
78
|
+
.relative(outDir, str)
|
|
79
|
+
.split("\\")
|
|
80
|
+
.join("/");
|
|
81
|
+
const index = location.lastIndexOf(NODE_MODULES);
|
|
82
|
+
return index === -1
|
|
83
|
+
? `./${location}`
|
|
84
|
+
: location.substring(index + NODE_MODULES.length);
|
|
85
|
+
})(this.internals_);
|
|
45
86
|
return statements.join("\n");
|
|
46
87
|
}
|
|
47
88
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ImportDictionary.js","sourceRoot":"","sources":["../../src/utils/ImportDictionary.ts"],"names":[],"mappings":";;;;;;AAAA,gDAAwB;AACxB,oDAAiD;AACjD,oDAAiD;AACjD,4CAAyC;AAEzC,MAAa,gBAAgB;IAA7B;QACqB,
|
|
1
|
+
{"version":3,"file":"ImportDictionary.js","sourceRoot":"","sources":["../../src/utils/ImportDictionary.ts"],"names":[],"mappings":";;;;;;AAAA,gDAAwB;AACxB,oDAAiD;AACjD,oDAAiD;AACjD,4CAAyC;AAEzC,MAAa,gBAAgB;IAA7B;QACqB,eAAU,GACvB,IAAI,iBAAO,EAAE,CAAC;QACD,eAAU,GACvB,IAAI,iBAAO,EAAE,CAAC;IAyFtB,CAAC;IAvFU,KAAK;QACR,OAAO,IAAI,CAAC,UAAU,CAAC,KAAK,EAAE,IAAI,IAAI,CAAC,UAAU,CAAC,KAAK,EAAE,CAAC;IAC9D,CAAC;IAEM,QAAQ,CAAC,KAAsC;;QAClD,MAAM,WAAW,GAAiB,IAAI,CAAC,UAAU,CAAC,IAAI,CAClD,IAAI,WAAI,CAAC,KAAK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-dev.20230830",
|
|
4
4
|
"description": "Nestia SDK and Swagger generator",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"typings": "lib/index.d.ts",
|
|
@@ -35,7 +35,7 @@
|
|
|
35
35
|
},
|
|
36
36
|
"homepage": "https://nestia.io",
|
|
37
37
|
"dependencies": {
|
|
38
|
-
"@nestia/fetcher": "^
|
|
38
|
+
"@nestia/fetcher": "^2.0.0-dev.20230830",
|
|
39
39
|
"cli": "^1.0.1",
|
|
40
40
|
"glob": "^7.2.0",
|
|
41
41
|
"path-to-regexp": "^6.2.1",
|
|
@@ -47,7 +47,7 @@
|
|
|
47
47
|
"typia": "^4.3.3"
|
|
48
48
|
},
|
|
49
49
|
"peerDependencies": {
|
|
50
|
-
"@nestia/fetcher": ">=
|
|
50
|
+
"@nestia/fetcher": ">=2.0.0-dev.20230830",
|
|
51
51
|
"@nestjs/common": ">=7.0.1",
|
|
52
52
|
"@nestjs/core": ">=7.0.1",
|
|
53
53
|
"reflect-metadata": ">=0.1.12",
|
|
@@ -3,6 +3,7 @@ import path from "path";
|
|
|
3
3
|
|
|
4
4
|
import { INestiaConfig } from "../INestiaConfig";
|
|
5
5
|
import { IRoute } from "../structures/IRoute";
|
|
6
|
+
import { ImportDictionary } from "../utils/ImportDictionary";
|
|
6
7
|
import { NestiaConfigUtil } from "../utils/NestiaConfigUtil";
|
|
7
8
|
import { E2eFileProgrammer } from "./internal/E2eFileProgrammer";
|
|
8
9
|
|
|
@@ -24,7 +25,9 @@ export namespace E2eGenerator {
|
|
|
24
25
|
|
|
25
26
|
// GENERATE EACH TEST FILES
|
|
26
27
|
for (const route of routeList)
|
|
27
|
-
await E2eFileProgrammer.generate(config)(
|
|
28
|
+
await E2eFileProgrammer.generate(config)(
|
|
29
|
+
new ImportDictionary(),
|
|
30
|
+
)({
|
|
28
31
|
api: path.resolve(config.output!),
|
|
29
32
|
current: path.join(output, "features", "api", "automated"),
|
|
30
33
|
})(route);
|
|
@@ -8,12 +8,17 @@ import { ImportDictionary } from "../../utils/ImportDictionary";
|
|
|
8
8
|
export namespace E2eFileProgrammer {
|
|
9
9
|
export const generate =
|
|
10
10
|
(config: INestiaConfig) =>
|
|
11
|
+
(importer: ImportDictionary) =>
|
|
11
12
|
(props: { api: string; current: string }) =>
|
|
12
13
|
async (route: IRoute): Promise<void> => {
|
|
13
14
|
const importDict: ImportDictionary = new ImportDictionary();
|
|
14
15
|
for (const tuple of route.imports)
|
|
15
16
|
for (const instance of tuple[1])
|
|
16
|
-
importDict.
|
|
17
|
+
importDict.internal({
|
|
18
|
+
file: tuple[0],
|
|
19
|
+
type: true,
|
|
20
|
+
instance,
|
|
21
|
+
});
|
|
17
22
|
|
|
18
23
|
const additional: string[] = [];
|
|
19
24
|
for (const param of route.parameters.filter(
|
|
@@ -25,17 +30,6 @@ export namespace E2eFileProgrammer {
|
|
|
25
30
|
}
|
|
26
31
|
|
|
27
32
|
const content: string = [
|
|
28
|
-
...(!!route.parameters.filter(
|
|
29
|
-
(p) =>
|
|
30
|
-
p.category !== "headers" && getAdditional(p) === null,
|
|
31
|
-
).length || route.output.name !== "void"
|
|
32
|
-
? [
|
|
33
|
-
config.primitive === false
|
|
34
|
-
? `import typia from "typia";`
|
|
35
|
-
: `import typia, { Primitive } from "typia";`,
|
|
36
|
-
"",
|
|
37
|
-
]
|
|
38
|
-
: []),
|
|
39
33
|
`import api from "./${path
|
|
40
34
|
.relative(props.current, props.api)
|
|
41
35
|
.split("\\")
|
|
@@ -44,7 +38,7 @@ export namespace E2eFileProgrammer {
|
|
|
44
38
|
? []
|
|
45
39
|
: [importDict.toScript(props.current)]),
|
|
46
40
|
"",
|
|
47
|
-
arrow(config)(route),
|
|
41
|
+
arrow(config)(importer)(route),
|
|
48
42
|
...(additional.length ? ["", ...additional] : []),
|
|
49
43
|
].join("\n");
|
|
50
44
|
|
|
@@ -57,11 +51,18 @@ export namespace E2eFileProgrammer {
|
|
|
57
51
|
|
|
58
52
|
const arrow =
|
|
59
53
|
(config: INestiaConfig) =>
|
|
54
|
+
(importer: ImportDictionary) =>
|
|
60
55
|
(route: IRoute): string => {
|
|
61
56
|
const tab: number = route.output.name === "void" ? 2 : 3;
|
|
62
57
|
const headers = route.parameters.find(
|
|
63
58
|
(p) => p.category === "headers" && p.field === undefined,
|
|
64
59
|
);
|
|
60
|
+
const typiaLib = () =>
|
|
61
|
+
importer.external({
|
|
62
|
+
type: false,
|
|
63
|
+
library: "typia",
|
|
64
|
+
instance: null,
|
|
65
|
+
});
|
|
65
66
|
const output = [
|
|
66
67
|
`await ${accessor(route)}(`,
|
|
67
68
|
headers !== undefined
|
|
@@ -70,7 +71,9 @@ export namespace E2eFileProgrammer {
|
|
|
70
71
|
" ...connection,",
|
|
71
72
|
" headers: {",
|
|
72
73
|
" ...(connection.headers ?? {}),",
|
|
73
|
-
`
|
|
74
|
+
` ...${typiaLib()}.random<${
|
|
75
|
+
headers.type.name
|
|
76
|
+
}>(),`,
|
|
74
77
|
" },",
|
|
75
78
|
"},",
|
|
76
79
|
]
|
|
@@ -79,7 +82,7 @@ export namespace E2eFileProgrammer {
|
|
|
79
82
|
: `${" ".repeat(tab * 4)}connection,`,
|
|
80
83
|
...route.parameters
|
|
81
84
|
.filter((param) => param.category !== "headers")
|
|
82
|
-
.map(parameter(config)(tab)),
|
|
85
|
+
.map(parameter(config)(importer)(tab)),
|
|
83
86
|
`${" ".repeat((tab - 1) * 4)});`,
|
|
84
87
|
].join("\n");
|
|
85
88
|
return [
|
|
@@ -89,11 +92,11 @@ export namespace E2eFileProgrammer {
|
|
|
89
92
|
...(route.output.name === "void"
|
|
90
93
|
? [` ${output}`]
|
|
91
94
|
: [
|
|
92
|
-
` const output: ${primitive(config)(
|
|
95
|
+
` const output: ${primitive(config)(importer)(
|
|
93
96
|
route.output.name,
|
|
94
97
|
)} = `,
|
|
95
98
|
` ${output}`,
|
|
96
|
-
`
|
|
99
|
+
` ${typiaLib()}.assert(output);`,
|
|
97
100
|
]),
|
|
98
101
|
`};`,
|
|
99
102
|
].join("\n");
|
|
@@ -101,6 +104,7 @@ export namespace E2eFileProgrammer {
|
|
|
101
104
|
|
|
102
105
|
const parameter =
|
|
103
106
|
(config: INestiaConfig) =>
|
|
107
|
+
(importer: ImportDictionary) =>
|
|
104
108
|
(tab: number) =>
|
|
105
109
|
(param: IRoute.IParameter): string => {
|
|
106
110
|
const middle: string =
|
|
@@ -110,7 +114,13 @@ export namespace E2eFileProgrammer {
|
|
|
110
114
|
? param.meta.nullable
|
|
111
115
|
? `Math.random() < .2 ? null : ${param.meta.type}()`
|
|
112
116
|
: `${param.meta.type}()`
|
|
113
|
-
:
|
|
117
|
+
: `${importer.external({
|
|
118
|
+
type: false,
|
|
119
|
+
library: "typia",
|
|
120
|
+
instance: null,
|
|
121
|
+
})}.random<${primitive(config)(importer)(
|
|
122
|
+
param.type.name,
|
|
123
|
+
)}>()`;
|
|
114
124
|
return `${" ".repeat(4 * tab)}${middle},`;
|
|
115
125
|
};
|
|
116
126
|
|
|
@@ -122,8 +132,15 @@ export namespace E2eFileProgrammer {
|
|
|
122
132
|
|
|
123
133
|
const primitive =
|
|
124
134
|
(config: INestiaConfig) =>
|
|
135
|
+
(importer: ImportDictionary) =>
|
|
125
136
|
(name: string): string =>
|
|
126
|
-
config.primitive !== false
|
|
137
|
+
config.primitive !== false
|
|
138
|
+
? `${importer.external({
|
|
139
|
+
type: true,
|
|
140
|
+
library: "@nestia/fetch",
|
|
141
|
+
instance: "Primitive",
|
|
142
|
+
})}<${name}>`
|
|
143
|
+
: name;
|
|
127
144
|
|
|
128
145
|
const getAdditional = (
|
|
129
146
|
param: IRoute.IParameter,
|
|
@@ -62,74 +62,38 @@ export namespace SdkFileProgrammer {
|
|
|
62
62
|
if (content.length && directory.routes.length) content.push("");
|
|
63
63
|
|
|
64
64
|
// ITERATE ROUTES
|
|
65
|
-
const
|
|
65
|
+
const importer: ImportDictionary = new ImportDictionary();
|
|
66
66
|
if (
|
|
67
67
|
config.simulate === true &&
|
|
68
68
|
directory.routes.some((r) => !!r.parameters.length)
|
|
69
69
|
)
|
|
70
|
-
|
|
71
|
-
`${config.output}/utils/NestiaSimulator.ts`,
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
);
|
|
75
|
-
|
|
70
|
+
importer.internal({
|
|
71
|
+
file: `${config.output}/utils/NestiaSimulator.ts`,
|
|
72
|
+
instance: "NestiaSimulator",
|
|
73
|
+
type: false,
|
|
74
|
+
});
|
|
76
75
|
directory.routes.forEach((route, i) => {
|
|
77
76
|
for (const tuple of route.imports)
|
|
78
77
|
for (const instance of tuple[1])
|
|
79
|
-
|
|
78
|
+
importer.internal({
|
|
79
|
+
file: tuple[0],
|
|
80
|
+
instance,
|
|
81
|
+
type: true,
|
|
82
|
+
});
|
|
80
83
|
|
|
81
|
-
content.push(
|
|
84
|
+
content.push(
|
|
85
|
+
SdkFunctionProgrammer.generate(config)(importer)(route),
|
|
86
|
+
);
|
|
82
87
|
if (i !== directory.routes.length - 1) content.push("");
|
|
83
88
|
});
|
|
84
89
|
|
|
85
90
|
// FINALIZE THE CONTENT
|
|
86
|
-
if (directory.routes.length !== 0)
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
route.parameters.some(
|
|
93
|
-
(param) => param.category !== "param",
|
|
94
|
-
),
|
|
95
|
-
);
|
|
96
|
-
const asserted: boolean =
|
|
97
|
-
config.assert === true &&
|
|
98
|
-
directory.routes.some(
|
|
99
|
-
(route) => route.parameters.length !== 0,
|
|
100
|
-
);
|
|
101
|
-
const json: boolean =
|
|
102
|
-
config.json === true &&
|
|
103
|
-
directory.routes.some(
|
|
104
|
-
(route) =>
|
|
105
|
-
route.method === "POST" ||
|
|
106
|
-
route.method === "PUT" ||
|
|
107
|
-
route.method === "PATCH",
|
|
108
|
-
);
|
|
109
|
-
const random: boolean =
|
|
110
|
-
config.simulate === true &&
|
|
111
|
-
directory.routes.some(
|
|
112
|
-
(s) =>
|
|
113
|
-
!!s.parameters.length || s.output.name !== "void",
|
|
114
|
-
);
|
|
115
|
-
|
|
116
|
-
const classes: string[] = ["Fetcher"];
|
|
117
|
-
const typings: string[] = ["IConnection"];
|
|
118
|
-
if (primitived) typings.push("Primitive");
|
|
119
|
-
|
|
120
|
-
const head: string[] = [
|
|
121
|
-
`import { ${classes.join(", ")} } from "@nestia/fetcher";`,
|
|
122
|
-
`import type { ${typings.join(
|
|
123
|
-
", ",
|
|
124
|
-
)} } from "@nestia/fetcher";`,
|
|
125
|
-
];
|
|
126
|
-
if (asserted || json || random)
|
|
127
|
-
head.push(`import typia from "typia";`);
|
|
128
|
-
if (!importDict.empty())
|
|
129
|
-
head.push("", importDict.toScript(outDir));
|
|
130
|
-
|
|
131
|
-
content.push(...head, "", ...content.splice(0, content.length));
|
|
132
|
-
}
|
|
91
|
+
if (directory.routes.length !== 0)
|
|
92
|
+
content.push(
|
|
93
|
+
importer.toScript(outDir),
|
|
94
|
+
"",
|
|
95
|
+
...content.splice(0, content.length),
|
|
96
|
+
);
|
|
133
97
|
|
|
134
98
|
const script: string =
|
|
135
99
|
"/**\n" +
|
|
@@ -6,14 +6,16 @@ import { Escaper } from "typia/lib/utils/Escaper";
|
|
|
6
6
|
import { INestiaConfig } from "../../INestiaConfig";
|
|
7
7
|
import { IController } from "../../structures/IController";
|
|
8
8
|
import { IRoute } from "../../structures/IRoute";
|
|
9
|
+
import { ImportDictionary } from "../../utils/ImportDictionary";
|
|
9
10
|
import { SdkSimulationProgrammer } from "./SdkSimulationProgrammer";
|
|
10
11
|
|
|
11
12
|
export namespace SdkFunctionProgrammer {
|
|
12
13
|
export const generate =
|
|
13
14
|
(config: INestiaConfig) =>
|
|
15
|
+
(importer: ImportDictionary) =>
|
|
14
16
|
(route: IRoute): string => {
|
|
15
17
|
const [x, y, z] = [head, body, tail].map((closure) =>
|
|
16
|
-
closure(config)(route)({
|
|
18
|
+
closure(config)(importer)(route)({
|
|
17
19
|
headers: route.parameters.find(
|
|
18
20
|
(param) =>
|
|
19
21
|
param.category === "headers" &&
|
|
@@ -37,11 +39,19 @@ export namespace SdkFunctionProgrammer {
|
|
|
37
39
|
--------------------------------------------------------- */
|
|
38
40
|
const body =
|
|
39
41
|
(config: INestiaConfig) =>
|
|
42
|
+
(importer: ImportDictionary) =>
|
|
40
43
|
(route: IRoute) =>
|
|
41
44
|
(props: {
|
|
42
45
|
query: IRoute.IParameter | undefined;
|
|
43
46
|
input: IRoute.IParameter | undefined;
|
|
44
47
|
}): string => {
|
|
48
|
+
const encrypted: boolean =
|
|
49
|
+
route.encrypted === true ||
|
|
50
|
+
(props.input !== undefined &&
|
|
51
|
+
props.input.custom === true &&
|
|
52
|
+
props.input.category === "body" &&
|
|
53
|
+
props.input.encrypted === true);
|
|
54
|
+
|
|
45
55
|
// FETCH ARGUMENTS WITH REQUST BODY
|
|
46
56
|
const parameters: IRoute.IParameter[] = filter_path_parameters(
|
|
47
57
|
route,
|
|
@@ -90,7 +100,13 @@ export namespace SdkFunctionProgrammer {
|
|
|
90
100
|
)
|
|
91
101
|
.map(
|
|
92
102
|
(param) =>
|
|
93
|
-
`
|
|
103
|
+
` ${importer.external({
|
|
104
|
+
library: "typia",
|
|
105
|
+
type: false,
|
|
106
|
+
instance: null,
|
|
107
|
+
})}.assert<typeof ${param.name}>(${
|
|
108
|
+
param.name
|
|
109
|
+
});`,
|
|
94
110
|
)
|
|
95
111
|
.join("\n") + "\n\n"
|
|
96
112
|
: "";
|
|
@@ -112,7 +128,13 @@ export namespace SdkFunctionProgrammer {
|
|
|
112
128
|
.join("\n");
|
|
113
129
|
const fetch = (tab: string) =>
|
|
114
130
|
[
|
|
115
|
-
`${awa ? "await " : ""}
|
|
131
|
+
`${awa ? "await " : ""}${importer.external({
|
|
132
|
+
type: false,
|
|
133
|
+
library: "@nestia/fetch",
|
|
134
|
+
instance: encrypted
|
|
135
|
+
? "EncryptedFetcher"
|
|
136
|
+
: "PlainFetcher",
|
|
137
|
+
})}.fetch(`,
|
|
116
138
|
fetchArguments
|
|
117
139
|
.map((param) =>
|
|
118
140
|
typeof param === "string"
|
|
@@ -186,6 +208,7 @@ export namespace SdkFunctionProgrammer {
|
|
|
186
208
|
--------------------------------------------------------- */
|
|
187
209
|
const head =
|
|
188
210
|
(config: INestiaConfig) =>
|
|
211
|
+
(importer: ImportDictionary) =>
|
|
189
212
|
(route: IRoute) =>
|
|
190
213
|
(props: {
|
|
191
214
|
query: IRoute.IParameter | undefined;
|
|
@@ -245,12 +268,17 @@ export namespace SdkFunctionProgrammer {
|
|
|
245
268
|
// FINALIZATION
|
|
246
269
|
//----
|
|
247
270
|
// REFORM PARAMETERS TEXT
|
|
271
|
+
const connectionType: string = importer.external({
|
|
272
|
+
library: "@nestia/fetch",
|
|
273
|
+
type: true,
|
|
274
|
+
instance: "IConnection",
|
|
275
|
+
});
|
|
248
276
|
const parameters: string[] = [
|
|
249
277
|
route.parameters.some(
|
|
250
278
|
(p) => p.category === "headers" && p.field === undefined,
|
|
251
279
|
)
|
|
252
|
-
? `connection:
|
|
253
|
-
:
|
|
280
|
+
? `connection: ${connectionType}<${`${route.name}.Headers`}>`
|
|
281
|
+
: `connection: ${connectionType}`,
|
|
254
282
|
...route.parameters
|
|
255
283
|
.filter((p) => p.category !== "headers")
|
|
256
284
|
.map((param) => {
|
|
@@ -286,6 +314,7 @@ export namespace SdkFunctionProgrammer {
|
|
|
286
314
|
|
|
287
315
|
const tail =
|
|
288
316
|
(config: INestiaConfig) =>
|
|
317
|
+
(importer: ImportDictionary) =>
|
|
289
318
|
(route: IRoute) =>
|
|
290
319
|
(props: {
|
|
291
320
|
query: IRoute.IParameter | undefined;
|
|
@@ -313,6 +342,12 @@ export namespace SdkFunctionProgrammer {
|
|
|
313
342
|
parameters,
|
|
314
343
|
});
|
|
315
344
|
|
|
345
|
+
const typiaLib = () =>
|
|
346
|
+
importer.external({
|
|
347
|
+
type: false,
|
|
348
|
+
library: "typia",
|
|
349
|
+
instance: null,
|
|
350
|
+
});
|
|
316
351
|
return (
|
|
317
352
|
`export namespace ${route.name} {\n` +
|
|
318
353
|
(types.length !== 0
|
|
@@ -321,27 +356,51 @@ export namespace SdkFunctionProgrammer {
|
|
|
321
356
|
(tuple) =>
|
|
322
357
|
` export type ${tuple.first} = ${
|
|
323
358
|
config.primitive !== false
|
|
324
|
-
?
|
|
359
|
+
? `${importer.external({
|
|
360
|
+
library: "@nestia/fetch",
|
|
361
|
+
type: true,
|
|
362
|
+
instance: "Primitive",
|
|
363
|
+
})}<${tuple.second}>`
|
|
325
364
|
: tuple.second
|
|
326
365
|
};`,
|
|
327
366
|
)
|
|
328
367
|
.join("\n") + "\n"
|
|
329
368
|
: "") +
|
|
330
369
|
"\n" +
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
props.input
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
370
|
+
[
|
|
371
|
+
"export const METADATA = {",
|
|
372
|
+
` method: "${route.method}",`,
|
|
373
|
+
` path: "${route.path}",`,
|
|
374
|
+
...(props.input
|
|
375
|
+
? [
|
|
376
|
+
`request: {`,
|
|
377
|
+
` type: "${
|
|
378
|
+
(props.input as IController.IBodyParameter)
|
|
379
|
+
.encrypted
|
|
380
|
+
? "text/plain"
|
|
381
|
+
: (
|
|
382
|
+
props.input as IController.IBodyParameter
|
|
383
|
+
).contentType ?? "application/json"
|
|
384
|
+
}",`,
|
|
385
|
+
` encrypted: ${
|
|
386
|
+
props.input.custom &&
|
|
387
|
+
props.input.category === "body" &&
|
|
388
|
+
props.input.encrypted
|
|
389
|
+
}`,
|
|
390
|
+
`},`,
|
|
391
|
+
].map((str) => ` ${str}`)
|
|
392
|
+
: []),
|
|
393
|
+
...(route.output
|
|
394
|
+
? [
|
|
395
|
+
`response: {`,
|
|
396
|
+
` type: "${route.output.type}",`,
|
|
397
|
+
` encrypted: ${route.encrypted},`,
|
|
398
|
+
`},`,
|
|
399
|
+
].map((str) => ` ${str}`)
|
|
400
|
+
: []),
|
|
401
|
+
...(route.status ? [` status: ${route.status},`] : []),
|
|
402
|
+
"}",
|
|
403
|
+
].join("\n") +
|
|
345
404
|
"\n" +
|
|
346
405
|
` export const path = (${parameters
|
|
347
406
|
.map(
|
|
@@ -357,16 +416,18 @@ export namespace SdkFunctionProgrammer {
|
|
|
357
416
|
`${path};\n` +
|
|
358
417
|
` }\n` +
|
|
359
418
|
(config.simulate === true && route.output.name !== "void"
|
|
360
|
-
? ` export const random = (g?: Partial
|
|
361
|
-
`
|
|
419
|
+
? ` export const random = (g?: Partial<${typiaLib()}.IRandomGenerator>): Output =>\n` +
|
|
420
|
+
` ${typiaLib()}.random<Output>(g);\n`
|
|
362
421
|
: "") +
|
|
363
422
|
(config.simulate === true
|
|
364
|
-
? SdkSimulationProgrammer.generate(
|
|
423
|
+
? SdkSimulationProgrammer.generate(config)(importer)(
|
|
424
|
+
route,
|
|
425
|
+
) + "\n"
|
|
365
426
|
: "") +
|
|
366
427
|
(config.json === true &&
|
|
367
428
|
route.parameters.find((param) => param.category === "body") !==
|
|
368
429
|
undefined
|
|
369
|
-
? ` export const stringify = (input: Input) =>
|
|
430
|
+
? ` export const stringify = (input: Input) => ${typiaLib()}.json.assertStringify(input);\n`
|
|
370
431
|
: "") +
|
|
371
432
|
"}"
|
|
372
433
|
);
|