@nestia/sdk 1.4.3 → 1.4.4-dev.20230706
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +3 -3
- package/lib/generates/E2eGenerator.js +12 -1
- package/lib/generates/E2eGenerator.js.map +1 -1
- package/lib/generates/internal/E2eFileProgrammer.d.ts +1 -1
- package/lib/generates/internal/E2eFileProgrammer.js +13 -20
- package/lib/generates/internal/E2eFileProgrammer.js.map +1 -1
- package/lib/utils/StringUtil.d.ts +3 -0
- package/lib/utils/StringUtil.js +12 -0
- package/lib/utils/StringUtil.js.map +1 -0
- package/package.json +2 -2
- package/src/generates/E2eGenerator.ts +14 -1
- package/src/generates/internal/E2eFileProgrammer.ts +27 -25
- package/src/utils/StringUtil.ts +10 -0
package/README.md
CHANGED
|
@@ -14,7 +14,7 @@ Nestia is a set of helper libraries for NestJS, supporting below features:
|
|
|
14
14
|
- SDK generator for clients
|
|
15
15
|
- Swagger generator evolved than ever
|
|
16
16
|
- Automatic E2E test functions generator
|
|
17
|
-
-
|
|
17
|
+
- Mockup Simulator for client applications
|
|
18
18
|
- `nestia`: just CLI (command line interface) tool
|
|
19
19
|
|
|
20
20
|
> **Note**
|
|
@@ -25,7 +25,7 @@ Nestia is a set of helper libraries for NestJS, supporting below features:
|
|
|
25
25
|
> - JSON serialization is **200x faster** than `class-transformer`
|
|
26
26
|
> - Software Development Kit
|
|
27
27
|
> - SDK is similar with [tRPC](https://trpc.io), but much advanced
|
|
28
|
-
> -
|
|
28
|
+
> - Mockup simulator like [msw](https://mswjs.io/), but fully automated
|
|
29
29
|
|
|
30
30
|

|
|
31
31
|
|
|
@@ -62,4 +62,4 @@ Check out the document in the [website](https://nestia.io/docs/):
|
|
|
62
62
|
- [Swagger Documents](https://nestia.io/docs/sdk/swagger/)
|
|
63
63
|
- [SDK Library](https://nestia.io/docs/sdk/sdk/)
|
|
64
64
|
- [E2E Functions](https://nestia.io/docs/sdk/e2e/)
|
|
65
|
-
- [
|
|
65
|
+
- [Mockup Simulator](https://nestia.io/docs/sdk/simulator/)
|
|
@@ -16,11 +16,22 @@ exports.E2eGenerator = void 0;
|
|
|
16
16
|
const fs_1 = __importDefault(require("fs"));
|
|
17
17
|
const path_1 = __importDefault(require("path"));
|
|
18
18
|
const NestiaConfigUtil_1 = require("../utils/NestiaConfigUtil");
|
|
19
|
+
const StringUtil_1 = require("../utils/StringUtil");
|
|
19
20
|
const E2eFileProgrammer_1 = require("./internal/E2eFileProgrammer");
|
|
20
21
|
var E2eGenerator;
|
|
21
22
|
(function (E2eGenerator) {
|
|
22
23
|
E2eGenerator.generate = (config) => (routeList) => __awaiter(this, void 0, void 0, function* () {
|
|
24
|
+
var _a;
|
|
23
25
|
console.log("Generating E2E Test Functions");
|
|
26
|
+
const pathDict = new Map();
|
|
27
|
+
for (const route of routeList) {
|
|
28
|
+
const sequence = StringUtil_1.StringUtil.split(route.path).map((_str, i, entire) => entire.slice(0, i + 1).join("/"));
|
|
29
|
+
for (const s of sequence) {
|
|
30
|
+
const count = (_a = pathDict.get(s)) !== null && _a !== void 0 ? _a : 0;
|
|
31
|
+
pathDict.set(s, count + 1);
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
const counter = (path) => { var _a; return (_a = pathDict.get(path)) !== null && _a !== void 0 ? _a : 0; };
|
|
24
35
|
// PREPARE DIRECTORIES
|
|
25
36
|
const output = path_1.default.resolve(config.e2e);
|
|
26
37
|
yield mkdir(output);
|
|
@@ -31,7 +42,7 @@ var E2eGenerator;
|
|
|
31
42
|
yield index(config)(path_1.default.join(config.e2e, "index.ts"));
|
|
32
43
|
// GENERATE EACH TEST FILES
|
|
33
44
|
for (const route of routeList)
|
|
34
|
-
yield E2eFileProgrammer_1.E2eFileProgrammer.generate(config)({
|
|
45
|
+
yield E2eFileProgrammer_1.E2eFileProgrammer.generate(config)(counter)({
|
|
35
46
|
api: path_1.default.resolve(config.output),
|
|
36
47
|
current: path_1.default.join(output, "features", "api", "automated"),
|
|
37
48
|
})(route);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"E2eGenerator.js","sourceRoot":"","sources":["../../src/generates/E2eGenerator.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,4CAAoB;AACpB,gDAAwB;AAIxB,gEAA6D;AAC7D,oEAAiE;AAEjE,IAAiB,YAAY,
|
|
1
|
+
{"version":3,"file":"E2eGenerator.js","sourceRoot":"","sources":["../../src/generates/E2eGenerator.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,4CAAoB;AACpB,gDAAwB;AAIxB,gEAA6D;AAC7D,oDAAiD;AACjD,oEAAiE;AAEjE,IAAiB,YAAY,CAgE5B;AAhED,WAAiB,YAAY;IACZ,qBAAQ,GACjB,CAAC,MAAqB,EAAE,EAAE,CAC1B,CAAO,SAAmB,EAAiB,EAAE;;QACzC,OAAO,CAAC,GAAG,CAAC,+BAA+B,CAAC,CAAC;QAE7C,MAAM,QAAQ,GAAwB,IAAI,GAAG,EAAE,CAAC;QAChD,KAAK,MAAM,KAAK,IAAI,SAAS,EAAE;YAC3B,MAAM,QAAQ,GAAa,uBAAU,CAAC,KAAK,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,GAAG,CACvD,CAAC,IAAI,EAAE,CAAC,EAAE,MAAM,EAAE,EAAE,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,CACxD,CAAC;YACF,KAAK,MAAM,CAAC,IAAI,QAAQ,EAAE;gBACtB,MAAM,KAAK,GAAW,MAAA,QAAQ,CAAC,GAAG,CAAC,CAAC,CAAC,mCAAI,CAAC,CAAC;gBAC3C,QAAQ,CAAC,GAAG,CAAC,CAAC,EAAE,KAAK,GAAG,CAAC,CAAC,CAAC;aAC9B;SACJ;QACD,MAAM,OAAO,GAAG,CAAC,IAAY,EAAU,EAAE,WAAC,OAAA,MAAA,QAAQ,C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CACb,CAAC;QACF,MAAM,OAAO,GAAW,MAAM,YAAE,CAAC,QAAQ,CAAC,QAAQ,CAC9C,QAAQ,EACR,MAAM,CACT,CAAC;QAEF,MAAM,YAAE,CAAC,QAAQ,CAAC,SAAS,CACvB,MAAM,EACN,OAAO,CAAC,OAAO,CACX,UAAU,EACV,IAAI,CAAC,SAAS,CAAC,mCAAgB,CAAC,KAAK,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,CACvD,EACD,MAAM,CACT,CAAC;IACN,CAAC,CAAA,CAAC;AACV,CAAC,EAhEgB,YAAY,4BAAZ,YAAY,QAgE5B;AAED,MAAM,KAAK,GAAG,CAAO,QAAgB,EAAiB,EAAE;IACpD,IAAI;QACA,MAAM,YAAE,CAAC,QAAQ,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAC;KACrC;IAAC,WAAM,GAAE;AACd,CAAC,CAAA,CAAC"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { INestiaConfig } from "../../INestiaConfig";
|
|
2
2
|
import { IRoute } from "../../structures/IRoute";
|
|
3
3
|
export declare namespace E2eFileProgrammer {
|
|
4
|
-
const generate: (config: INestiaConfig) => (props: {
|
|
4
|
+
const generate: (config: INestiaConfig) => (counter: (path: string) => number) => (props: {
|
|
5
5
|
api: string;
|
|
6
6
|
current: string;
|
|
7
7
|
}) => (route: IRoute) => Promise<void>;
|
|
@@ -16,9 +16,10 @@ exports.E2eFileProgrammer = void 0;
|
|
|
16
16
|
const fs_1 = __importDefault(require("fs"));
|
|
17
17
|
const path_1 = __importDefault(require("path"));
|
|
18
18
|
const ImportDictionary_1 = require("../../utils/ImportDictionary");
|
|
19
|
+
const StringUtil_1 = require("../../utils/StringUtil");
|
|
19
20
|
var E2eFileProgrammer;
|
|
20
21
|
(function (E2eFileProgrammer) {
|
|
21
|
-
E2eFileProgrammer.generate = (config) => (props) => (route) => __awaiter(this, void 0, void 0, function* () {
|
|
22
|
+
E2eFileProgrammer.generate = (config) => (counter) => (props) => (route) => __awaiter(this, void 0, void 0, function* () {
|
|
22
23
|
var _a, _b;
|
|
23
24
|
const importDict = new ImportDictionary_1.ImportDictionary();
|
|
24
25
|
for (const tuple of route.imports)
|
|
@@ -48,21 +49,21 @@ var E2eFileProgrammer;
|
|
|
48
49
|
? []
|
|
49
50
|
: [importDict.toScript(props.current)]),
|
|
50
51
|
"",
|
|
51
|
-
arrow(config)(route),
|
|
52
|
+
arrow(config)(counter)(route),
|
|
52
53
|
...(additional.length ? ["", ...additional] : []),
|
|
53
54
|
].join("\n");
|
|
54
|
-
yield fs_1.default.promises.writeFile(`${props.current}/${name(route)}.ts`, content, "utf8");
|
|
55
|
+
yield fs_1.default.promises.writeFile(`${props.current}/${name(counter)(route)}.ts`, content, "utf8");
|
|
55
56
|
});
|
|
56
|
-
const arrow = (config) => (route) => {
|
|
57
|
+
const arrow = (config) => (counter) => (route) => {
|
|
57
58
|
const tab = route.output.name === "void" ? 2 : 3;
|
|
58
59
|
const output = [
|
|
59
|
-
`await ${accessor(route)}(`,
|
|
60
|
+
`await ${accessor(counter)(route)}(`,
|
|
60
61
|
`${" ".repeat(tab * 4)}connection,`,
|
|
61
62
|
...route.parameters.map(parameter(config)(tab)),
|
|
62
63
|
`${" ".repeat((tab - 1) * 4)});`,
|
|
63
64
|
].join("\n");
|
|
64
65
|
return [
|
|
65
|
-
`export const ${name(route)} = async (`,
|
|
66
|
+
`export const ${name(counter)(route)} = async (`,
|
|
66
67
|
` connection: api.IConnection`,
|
|
67
68
|
`): Promise<void> => {`,
|
|
68
69
|
...(route.output.name === "void"
|
|
@@ -85,22 +86,14 @@ var E2eFileProgrammer;
|
|
|
85
86
|
: `typia.random<${primitive(config)(param.type.name)}>()`;
|
|
86
87
|
return `${" ".repeat(4 * tab)}${middle},`;
|
|
87
88
|
};
|
|
88
|
-
const name = (route) => postfix([
|
|
89
|
-
|
|
90
|
-
...route.path
|
|
91
|
-
.split("/")
|
|
92
|
-
.filter((str) => str.length && str[0] !== ":")
|
|
93
|
-
.map(normalize),
|
|
94
|
-
])(route.name).join("_");
|
|
95
|
-
const accessor = (route) => postfix([
|
|
89
|
+
const name = (counter) => (route) => postfix(counter)(["test_api", ...StringUtil_1.StringUtil.split(route.path)])(route.name).join("_");
|
|
90
|
+
const accessor = (counter) => (route) => postfix(counter)([
|
|
96
91
|
"api.functional",
|
|
97
|
-
...route.path
|
|
98
|
-
.split("/")
|
|
99
|
-
.filter((str) => str.length && str[0] !== ":")
|
|
100
|
-
.map(normalize),
|
|
92
|
+
...StringUtil_1.StringUtil.split(route.path),
|
|
101
93
|
])(route.name).join(".");
|
|
102
|
-
const
|
|
103
|
-
|
|
94
|
+
const postfix = (counter) => (array) => (name) => array.at(-1) === name && counter([...array, name].join("/")) === 1
|
|
95
|
+
? array
|
|
96
|
+
: [...array, name];
|
|
104
97
|
const primitive = (config) => (name) => config.primitive !== false ? `Primitive<${name}>` : name;
|
|
105
98
|
})(E2eFileProgrammer || (exports.E2eFileProgrammer = E2eFileProgrammer = {}));
|
|
106
99
|
const UUID = `const uuid = (): string =>
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"E2eFileProgrammer.js","sourceRoot":"","sources":["../../../src/generates/internal/E2eFileProgrammer.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,4CAAoB;AACpB,gDAAwB;AAIxB,mEAAgE;
|
|
1
|
+
{"version":3,"file":"E2eFileProgrammer.js","sourceRoot":"","sources":["../../../src/generates/internal/E2eFileProgrammer.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,4CAAoB;AACpB,gDAAwB;AAIxB,mEAAgE;AAChE,uDAAoD;AAEpD,IAAiB,iBAAiB,CAiHjC;AAjHD,WAAiB,iBAAiB;IACjB,0BAAQ,GACjB,CAAC,MAAqB,EAAE,EAAE,CAC1B,CAAC,OAAiC,EAAE,EAAE,CACtC,CAAC,KAAuC,EAAE,EAAE,CAC5C,CAAO,KAAa,EAAiB,EAAE;;QACnC,MAAM,U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AAa,EAAU,EAAE,CACtB,OAAO,CAAC,OAAO,CAAC,CAAC;QACb,gBAAgB;QAChB,GAAG,uBAAU,CAAC,KAAK,CAAC,KAAK,CAAC,IAAI,CAAC;KAClC,CAAC,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;IAEjC,MAAM,OAAO,GACT,CAAC,OAAiC,EAAE,EAAE,CACtC,CAAC,KAAe,EAAE,EAAE,CACpB,CAAC,IAAY,EAAE,EAAE,CACb,KAAK,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,KAAK,IAAI,IAAI,OAAO,CAAC,CAAC,GAAG,KAAK,EAAE,IAAI,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,KAAK,CAAC;QAC9D,CAAC,CAAC,KAAK;QACP,CAAC,CAAC,CAAC,GAAG,KAAK,EAAE,IAAI,CAAC,CAAC;IAE/B,MAAM,SAAS,GACX,CAAC,MAAqB,EAAE,EAAE,CAC1B,CAAC,IAAY,EAAU,EAAE,CACrB,MAAM,CAAC,SAAS,KAAK,KAAK,CAAC,CAAC,CAAC,aAAa,IAAI,GAAG,CAAC,CAAC,CAAC,IAAI,CAAC;AACrE,CAAC,EAjHgB,iBAAiB,iCAAjB,iBAAiB,QAiHjC;AAED,MAAM,IAAI,GAAG;;;;;QAKL,CAAC;AACT,MAAM,IAAI,GAAG;;;;;;;EAOX,CAAC"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.StringUtil = void 0;
|
|
4
|
+
var StringUtil;
|
|
5
|
+
(function (StringUtil) {
|
|
6
|
+
StringUtil.split = (path) => path
|
|
7
|
+
.split("/")
|
|
8
|
+
.filter((str) => str.length && str[0] !== ":")
|
|
9
|
+
.map(normalize);
|
|
10
|
+
const normalize = (str) => str.split("-").join("_").split(".").join("_");
|
|
11
|
+
})(StringUtil || (exports.StringUtil = StringUtil = {}));
|
|
12
|
+
//# sourceMappingURL=StringUtil.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"StringUtil.js","sourceRoot":"","sources":["../../src/utils/StringUtil.ts"],"names":[],"mappings":";;;AAAA,IAAiB,UAAU,CAS1B;AATD,WAAiB,UAAU;IACV,gBAAK,GAAG,CAAC,IAAY,EAAE,EAAE,CAClC,IAAI;SACC,KAAK,CAAC,GAAG,CAAC;SACV,MAAM,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,GAAG,CAAC,MAAM,IAAI,GAAG,CAAC,CAAC,CAAC,KAAK,GAAG,CAAC;SAC7C,GAAG,CAAC,SAAS,CAAC,CAAC;IAExB,MAAM,SAAS,GAAG,CAAC,GAAW,EAAE,EAAE,CAC9B,GAAG,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;AACtD,CAAC,EATgB,UAAU,0BAAV,UAAU,QAS1B"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nestia/sdk",
|
|
3
|
-
"version": "1.4.
|
|
3
|
+
"version": "1.4.4-dev.20230706",
|
|
4
4
|
"description": "Nestia SDK and Swagger generator",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"typings": "lib/index.d.ts",
|
|
@@ -43,7 +43,7 @@
|
|
|
43
43
|
"tsconfck": "^2.0.1",
|
|
44
44
|
"tsconfig-paths": "^4.1.1",
|
|
45
45
|
"tstl": "^2.5.13",
|
|
46
|
-
"typia": "^4.1.
|
|
46
|
+
"typia": "^4.1.2"
|
|
47
47
|
},
|
|
48
48
|
"peerDependencies": {
|
|
49
49
|
"@nestia/fetcher": ">= 1.4.0",
|
|
@@ -4,6 +4,7 @@ import path from "path";
|
|
|
4
4
|
import { INestiaConfig } from "../INestiaConfig";
|
|
5
5
|
import { IRoute } from "../structures/IRoute";
|
|
6
6
|
import { NestiaConfigUtil } from "../utils/NestiaConfigUtil";
|
|
7
|
+
import { StringUtil } from "../utils/StringUtil";
|
|
7
8
|
import { E2eFileProgrammer } from "./internal/E2eFileProgrammer";
|
|
8
9
|
|
|
9
10
|
export namespace E2eGenerator {
|
|
@@ -12,6 +13,18 @@ export namespace E2eGenerator {
|
|
|
12
13
|
async (routeList: IRoute[]): Promise<void> => {
|
|
13
14
|
console.log("Generating E2E Test Functions");
|
|
14
15
|
|
|
16
|
+
const pathDict: Map<string, number> = new Map();
|
|
17
|
+
for (const route of routeList) {
|
|
18
|
+
const sequence: string[] = StringUtil.split(route.path).map(
|
|
19
|
+
(_str, i, entire) => entire.slice(0, i + 1).join("/"),
|
|
20
|
+
);
|
|
21
|
+
for (const s of sequence) {
|
|
22
|
+
const count: number = pathDict.get(s) ?? 0;
|
|
23
|
+
pathDict.set(s, count + 1);
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
const counter = (path: string): number => pathDict.get(path) ?? 0;
|
|
27
|
+
|
|
15
28
|
// PREPARE DIRECTORIES
|
|
16
29
|
const output: string = path.resolve(config.e2e!);
|
|
17
30
|
await mkdir(output);
|
|
@@ -24,7 +37,7 @@ export namespace E2eGenerator {
|
|
|
24
37
|
|
|
25
38
|
// GENERATE EACH TEST FILES
|
|
26
39
|
for (const route of routeList)
|
|
27
|
-
await E2eFileProgrammer.generate(config)({
|
|
40
|
+
await E2eFileProgrammer.generate(config)(counter)({
|
|
28
41
|
api: path.resolve(config.output!),
|
|
29
42
|
current: path.join(output, "features", "api", "automated"),
|
|
30
43
|
})(route);
|
|
@@ -4,10 +4,12 @@ import path from "path";
|
|
|
4
4
|
import { INestiaConfig } from "../../INestiaConfig";
|
|
5
5
|
import { IRoute } from "../../structures/IRoute";
|
|
6
6
|
import { ImportDictionary } from "../../utils/ImportDictionary";
|
|
7
|
+
import { StringUtil } from "../../utils/StringUtil";
|
|
7
8
|
|
|
8
9
|
export namespace E2eFileProgrammer {
|
|
9
10
|
export const generate =
|
|
10
11
|
(config: INestiaConfig) =>
|
|
12
|
+
(counter: (path: string) => number) =>
|
|
11
13
|
(props: { api: string; current: string }) =>
|
|
12
14
|
async (route: IRoute): Promise<void> => {
|
|
13
15
|
const importDict: ImportDictionary = new ImportDictionary();
|
|
@@ -37,12 +39,12 @@ export namespace E2eFileProgrammer {
|
|
|
37
39
|
? []
|
|
38
40
|
: [importDict.toScript(props.current)]),
|
|
39
41
|
"",
|
|
40
|
-
arrow(config)(route),
|
|
42
|
+
arrow(config)(counter)(route),
|
|
41
43
|
...(additional.length ? ["", ...additional] : []),
|
|
42
44
|
].join("\n");
|
|
43
45
|
|
|
44
46
|
await fs.promises.writeFile(
|
|
45
|
-
`${props.current}/${name(route)}.ts`,
|
|
47
|
+
`${props.current}/${name(counter)(route)}.ts`,
|
|
46
48
|
content,
|
|
47
49
|
"utf8",
|
|
48
50
|
);
|
|
@@ -50,16 +52,17 @@ export namespace E2eFileProgrammer {
|
|
|
50
52
|
|
|
51
53
|
const arrow =
|
|
52
54
|
(config: INestiaConfig) =>
|
|
55
|
+
(counter: (path: string) => number) =>
|
|
53
56
|
(route: IRoute): string => {
|
|
54
57
|
const tab: number = route.output.name === "void" ? 2 : 3;
|
|
55
58
|
const output = [
|
|
56
|
-
`await ${accessor(route)}(`,
|
|
59
|
+
`await ${accessor(counter)(route)}(`,
|
|
57
60
|
`${" ".repeat(tab * 4)}connection,`,
|
|
58
61
|
...route.parameters.map(parameter(config)(tab)),
|
|
59
62
|
`${" ".repeat((tab - 1) * 4)});`,
|
|
60
63
|
].join("\n");
|
|
61
64
|
return [
|
|
62
|
-
`export const ${name(route)} = async (`,
|
|
65
|
+
`export const ${name(counter)(route)} = async (`,
|
|
63
66
|
` connection: api.IConnection`,
|
|
64
67
|
`): Promise<void> => {`,
|
|
65
68
|
...(route.output.name === "void"
|
|
@@ -89,29 +92,28 @@ export namespace E2eFileProgrammer {
|
|
|
89
92
|
return `${" ".repeat(4 * tab)}${middle},`;
|
|
90
93
|
};
|
|
91
94
|
|
|
92
|
-
const name =
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
...route.path
|
|
96
|
-
.
|
|
97
|
-
|
|
98
|
-
.map(normalize),
|
|
99
|
-
])(route.name).join("_");
|
|
95
|
+
const name =
|
|
96
|
+
(counter: (path: string) => number) =>
|
|
97
|
+
(route: IRoute): string =>
|
|
98
|
+
postfix(counter)(["test_api", ...StringUtil.split(route.path)])(
|
|
99
|
+
route.name,
|
|
100
|
+
).join("_");
|
|
100
101
|
|
|
101
|
-
const accessor =
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
.
|
|
106
|
-
.
|
|
107
|
-
|
|
108
|
-
])(route.name).join(".");
|
|
102
|
+
const accessor =
|
|
103
|
+
(counter: (path: string) => number) =>
|
|
104
|
+
(route: IRoute): string =>
|
|
105
|
+
postfix(counter)([
|
|
106
|
+
"api.functional",
|
|
107
|
+
...StringUtil.split(route.path),
|
|
108
|
+
])(route.name).join(".");
|
|
109
109
|
|
|
110
|
-
const
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
110
|
+
const postfix =
|
|
111
|
+
(counter: (path: string) => number) =>
|
|
112
|
+
(array: string[]) =>
|
|
113
|
+
(name: string) =>
|
|
114
|
+
array.at(-1) === name && counter([...array, name].join("/")) === 1
|
|
115
|
+
? array
|
|
116
|
+
: [...array, name];
|
|
115
117
|
|
|
116
118
|
const primitive =
|
|
117
119
|
(config: INestiaConfig) =>
|