@autobe/compiler 0.19.1 → 0.21.0
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/AutoBeTypeScriptCompiler.js +7 -8
- package/lib/AutoBeTypeScriptCompiler.js.map +1 -1
- package/lib/raw/AutoBeCompilerRealizeTemplate.js +2 -2
- package/lib/raw/AutoBeCompilerRealizeTemplate.js.map +1 -1
- package/lib/raw/AutoBeCompilerTestTemplate.js +1 -1
- package/lib/raw/nestjs.json +76 -75
- package/lib/raw/test.json +71 -70
- package/lib/realize/writeRealizeControllers.js +7 -1
- package/lib/realize/writeRealizeControllers.js.map +1 -1
- package/lib/test/AutoBeTestCompiler.js +7 -8
- package/lib/test/AutoBeTestCompiler.js.map +1 -1
- package/lib/test/programmers/AutoBeTestFunctionalProgrammer.js +5 -9
- package/lib/test/programmers/AutoBeTestFunctionalProgrammer.js.map +1 -1
- package/lib/test/programmers/AutoBeTestPredicateProgrammer.js +43 -55
- package/lib/test/programmers/AutoBeTestPredicateProgrammer.js.map +1 -1
- package/lib/test/programmers/AutoBeTestRandomProgrammer.js +13 -31
- package/lib/test/programmers/AutoBeTestRandomProgrammer.js.map +1 -1
- package/lib/utils/shrinkCompileResult.d.ts +3 -0
- package/lib/utils/shrinkCompileResult.js +17 -0
- package/lib/utils/shrinkCompileResult.js.map +1 -0
- package/package.json +12 -8
- package/src/AutoBeTypeScriptCompiler.ts +12 -13
- package/src/raw/AutoBeCompilerRealizeTemplate.ts +2 -2
- package/src/raw/AutoBeCompilerTestTemplate.ts +1 -1
- package/src/raw/nestjs.json +76 -75
- package/src/raw/test.json +71 -70
- package/src/realize/writeRealizeControllers.ts +35 -1
- package/src/test/AutoBeTestCompiler.ts +7 -8
- package/src/test/programmers/AutoBeTestFunctionalProgrammer.ts +5 -5
- package/src/test/programmers/AutoBeTestPredicateProgrammer.ts +25 -21
- package/src/test/programmers/AutoBeTestRandomProgrammer.ts +18 -28
- package/src/utils/shrinkCompileResult.ts +16 -0
|
@@ -73,6 +73,40 @@ export const writeRealizeControllers = async (
|
|
|
73
73
|
),
|
|
74
74
|
],
|
|
75
75
|
);
|
|
76
|
+
const tryCatch = ts.factory.createTryStatement(
|
|
77
|
+
ts.factory.createBlock(
|
|
78
|
+
[
|
|
79
|
+
ts.factory.createReturnStatement(
|
|
80
|
+
ts.factory.createAwaitExpression(call),
|
|
81
|
+
),
|
|
82
|
+
],
|
|
83
|
+
true,
|
|
84
|
+
),
|
|
85
|
+
ts.factory.createCatchClause(
|
|
86
|
+
ts.factory.createVariableDeclaration(
|
|
87
|
+
ts.factory.createIdentifier("error"),
|
|
88
|
+
undefined,
|
|
89
|
+
undefined,
|
|
90
|
+
undefined,
|
|
91
|
+
),
|
|
92
|
+
ts.factory.createBlock(
|
|
93
|
+
[
|
|
94
|
+
ts.factory.createExpressionStatement(
|
|
95
|
+
ts.factory.createCallExpression(
|
|
96
|
+
ts.factory.createIdentifier("console.log"),
|
|
97
|
+
undefined,
|
|
98
|
+
[ts.factory.createIdentifier("error")],
|
|
99
|
+
),
|
|
100
|
+
),
|
|
101
|
+
ts.factory.createThrowStatement(
|
|
102
|
+
ts.factory.createIdentifier("error"),
|
|
103
|
+
),
|
|
104
|
+
],
|
|
105
|
+
true,
|
|
106
|
+
),
|
|
107
|
+
),
|
|
108
|
+
undefined,
|
|
109
|
+
);
|
|
76
110
|
return ts.factory.updateMethodDeclaration(
|
|
77
111
|
method,
|
|
78
112
|
method.modifiers,
|
|
@@ -126,7 +160,7 @@ export const writeRealizeControllers = async (
|
|
|
126
160
|
]
|
|
127
161
|
: method.parameters,
|
|
128
162
|
method.type,
|
|
129
|
-
ts.factory.createBlock([
|
|
163
|
+
ts.factory.createBlock([tryCatch]),
|
|
130
164
|
);
|
|
131
165
|
},
|
|
132
166
|
},
|
|
@@ -7,7 +7,7 @@ import {
|
|
|
7
7
|
IAutoBeTypeScriptCompileResult,
|
|
8
8
|
} from "@autobe/interface";
|
|
9
9
|
import { AutoBeEndpointComparator, validateTestFunction } from "@autobe/utils";
|
|
10
|
-
import {
|
|
10
|
+
import { EmbedEsLint } from "embed-eslint";
|
|
11
11
|
import { HashMap, Pair } from "tstl";
|
|
12
12
|
import ts from "typescript";
|
|
13
13
|
import { IValidation } from "typia";
|
|
@@ -17,6 +17,7 @@ import { AutoBeCompilerInterfaceTemplate } from "../raw/AutoBeCompilerInterfaceT
|
|
|
17
17
|
import { AutoBeCompilerTestTemplate } from "../raw/AutoBeCompilerTestTemplate";
|
|
18
18
|
import TestExternal from "../raw/test.json";
|
|
19
19
|
import { FilePrinter } from "../utils/FilePrinter";
|
|
20
|
+
import { shrinkCompileResult } from "../utils/shrinkCompileResult";
|
|
20
21
|
import { writeTestFunction } from "./programmers/writeTestFunction";
|
|
21
22
|
|
|
22
23
|
export class AutoBeTestCompiler implements IAutoBeTestCompiler {
|
|
@@ -24,7 +25,7 @@ export class AutoBeTestCompiler implements IAutoBeTestCompiler {
|
|
|
24
25
|
props: IAutoBeTypeScriptCompileProps,
|
|
25
26
|
): Promise<IAutoBeTypeScriptCompileResult> {
|
|
26
27
|
const alias: string = props.package ?? "@ORGANIZATION/PROJECT-api";
|
|
27
|
-
const compiler:
|
|
28
|
+
const compiler: EmbedEsLint = new EmbedEsLint({
|
|
28
29
|
external: TestExternal as Record<string, string>,
|
|
29
30
|
compilerOptions: {
|
|
30
31
|
target: ts.ScriptTarget.ESNext,
|
|
@@ -53,13 +54,11 @@ export class AutoBeTestCompiler implements IAutoBeTestCompiler {
|
|
|
53
54
|
),
|
|
54
55
|
],
|
|
55
56
|
}),
|
|
57
|
+
rules: {
|
|
58
|
+
"no-floating-promises": "error",
|
|
59
|
+
},
|
|
56
60
|
});
|
|
57
|
-
|
|
58
|
-
return result.type === "success"
|
|
59
|
-
? { type: "success" }
|
|
60
|
-
: result.type === "failure"
|
|
61
|
-
? { type: "failure", diagnostics: result.diagnostics }
|
|
62
|
-
: { type: "exception", error: result.error };
|
|
61
|
+
return shrinkCompileResult(compiler.compile(props.files));
|
|
63
62
|
}
|
|
64
63
|
|
|
65
64
|
public async validate(
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { AutoBeTest } from "@autobe/interface";
|
|
2
2
|
import ts from "typescript";
|
|
3
|
-
import { ExpressionFactory } from "typia/lib/factories/ExpressionFactory";
|
|
4
3
|
|
|
5
4
|
import { AutoBeTestStatementProgrammer } from "./AutoBeTestStatementProgrammer";
|
|
6
5
|
import { IAutoBeTestProgrammerContext } from "./IAutoBeTestProgrammerContext";
|
|
@@ -71,8 +70,8 @@ const arrayExpression = (
|
|
|
71
70
|
argList: AutoBeTest.IExpression[],
|
|
72
71
|
): ts.AwaitExpression =>
|
|
73
72
|
ts.factory.createAwaitExpression(
|
|
74
|
-
|
|
75
|
-
|
|
73
|
+
ts.factory.createCallExpression(
|
|
74
|
+
ts.factory.createPropertyAccessExpression(
|
|
76
75
|
ts.factory.createIdentifier(
|
|
77
76
|
ctx.importer.external({
|
|
78
77
|
type: "instance",
|
|
@@ -82,6 +81,7 @@ const arrayExpression = (
|
|
|
82
81
|
),
|
|
83
82
|
name,
|
|
84
83
|
),
|
|
85
|
-
|
|
86
|
-
|
|
84
|
+
undefined,
|
|
85
|
+
argList.map((a) => writeTestExpression(ctx, a)),
|
|
86
|
+
),
|
|
87
87
|
);
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { AutoBeTest } from "@autobe/interface";
|
|
2
2
|
import ts from "typescript";
|
|
3
|
-
import { ExpressionFactory } from "typia/lib/factories/ExpressionFactory";
|
|
4
3
|
|
|
5
4
|
import { IAutoBeTestProgrammerContext } from "./IAutoBeTestProgrammerContext";
|
|
6
5
|
import { writeTestExpression } from "./writeTestExpression";
|
|
@@ -10,8 +9,8 @@ export namespace AutoBeTestPredicateProgrammer {
|
|
|
10
9
|
ctx: IAutoBeTestProgrammerContext,
|
|
11
10
|
expression: AutoBeTest.IEqualPredicate,
|
|
12
11
|
): ts.CallExpression =>
|
|
13
|
-
|
|
14
|
-
|
|
12
|
+
ts.factory.createCallExpression(
|
|
13
|
+
ts.factory.createPropertyAccessExpression(
|
|
15
14
|
ts.factory.createIdentifier(
|
|
16
15
|
ctx.importer.external({
|
|
17
16
|
type: "instance",
|
|
@@ -21,19 +20,20 @@ export namespace AutoBeTestPredicateProgrammer {
|
|
|
21
20
|
),
|
|
22
21
|
"equals",
|
|
23
22
|
),
|
|
24
|
-
|
|
23
|
+
undefined,
|
|
24
|
+
[
|
|
25
25
|
ts.factory.createStringLiteral(expression.title),
|
|
26
26
|
writeTestExpression(ctx, expression.x),
|
|
27
27
|
writeTestExpression(ctx, expression.y),
|
|
28
28
|
],
|
|
29
|
-
|
|
29
|
+
);
|
|
30
30
|
|
|
31
31
|
export const notEqualPredicate = (
|
|
32
32
|
ctx: IAutoBeTestProgrammerContext,
|
|
33
33
|
expression: AutoBeTest.INotEqualPredicate,
|
|
34
34
|
): ts.CallExpression =>
|
|
35
|
-
|
|
36
|
-
|
|
35
|
+
ts.factory.createCallExpression(
|
|
36
|
+
ts.factory.createPropertyAccessExpression(
|
|
37
37
|
ts.factory.createIdentifier(
|
|
38
38
|
ctx.importer.external({
|
|
39
39
|
type: "instance",
|
|
@@ -43,7 +43,8 @@ export namespace AutoBeTestPredicateProgrammer {
|
|
|
43
43
|
),
|
|
44
44
|
"error",
|
|
45
45
|
),
|
|
46
|
-
|
|
46
|
+
undefined,
|
|
47
|
+
[
|
|
47
48
|
ts.factory.createStringLiteral(expression.title),
|
|
48
49
|
ts.factory.createArrowFunction(
|
|
49
50
|
undefined,
|
|
@@ -59,14 +60,14 @@ export namespace AutoBeTestPredicateProgrammer {
|
|
|
59
60
|
}),
|
|
60
61
|
),
|
|
61
62
|
],
|
|
62
|
-
|
|
63
|
+
);
|
|
63
64
|
|
|
64
65
|
export const conditionalPredicate = (
|
|
65
66
|
ctx: IAutoBeTestProgrammerContext,
|
|
66
67
|
expression: AutoBeTest.IConditionalPredicate,
|
|
67
68
|
): ts.CallExpression =>
|
|
68
|
-
|
|
69
|
-
|
|
69
|
+
ts.factory.createCallExpression(
|
|
70
|
+
ts.factory.createPropertyAccessExpression(
|
|
70
71
|
ts.factory.createIdentifier(
|
|
71
72
|
ctx.importer.external({
|
|
72
73
|
type: "instance",
|
|
@@ -76,18 +77,19 @@ export namespace AutoBeTestPredicateProgrammer {
|
|
|
76
77
|
),
|
|
77
78
|
"predicate",
|
|
78
79
|
),
|
|
79
|
-
|
|
80
|
+
undefined,
|
|
81
|
+
[
|
|
80
82
|
ts.factory.createStringLiteral(expression.title),
|
|
81
83
|
writeTestExpression(ctx, expression.expression),
|
|
82
84
|
],
|
|
83
|
-
|
|
85
|
+
);
|
|
84
86
|
|
|
85
87
|
export const errorPredicate = (
|
|
86
88
|
ctx: IAutoBeTestProgrammerContext,
|
|
87
89
|
expression: AutoBeTest.IErrorPredicate,
|
|
88
90
|
): ts.CallExpression =>
|
|
89
|
-
|
|
90
|
-
|
|
91
|
+
ts.factory.createCallExpression(
|
|
92
|
+
ts.factory.createPropertyAccessExpression(
|
|
91
93
|
ts.factory.createIdentifier(
|
|
92
94
|
ctx.importer.external({
|
|
93
95
|
type: "instance",
|
|
@@ -97,18 +99,19 @@ export namespace AutoBeTestPredicateProgrammer {
|
|
|
97
99
|
),
|
|
98
100
|
"error",
|
|
99
101
|
),
|
|
100
|
-
|
|
102
|
+
undefined,
|
|
103
|
+
[
|
|
101
104
|
ts.factory.createStringLiteral(expression.title),
|
|
102
105
|
writeTestExpression(ctx, expression.function),
|
|
103
106
|
],
|
|
104
|
-
|
|
107
|
+
);
|
|
105
108
|
|
|
106
109
|
// export const httpErrorPredicate = (
|
|
107
110
|
// ctx: IAutoBeTestProgrammerContext,
|
|
108
111
|
// expression: AutoBeTest.IHttpErrorPredicate,
|
|
109
112
|
// ): ts.CallExpression =>
|
|
110
|
-
//
|
|
111
|
-
//
|
|
113
|
+
// ts.factory.createCallExpression(
|
|
114
|
+
// ts.factory.createPropertyAccessExpression(
|
|
112
115
|
// ts.factory.createIdentifier(
|
|
113
116
|
// ctx.importer.external({
|
|
114
117
|
// type: "instance",
|
|
@@ -118,10 +121,11 @@ export namespace AutoBeTestPredicateProgrammer {
|
|
|
118
121
|
// ),
|
|
119
122
|
// "httpError",
|
|
120
123
|
// ),
|
|
121
|
-
//
|
|
124
|
+
// undefined,
|
|
125
|
+
// [
|
|
122
126
|
// ts.factory.createStringLiteral(expression.title),
|
|
123
127
|
// ts.factory.createNumericLiteral(expression.status),
|
|
124
128
|
// writeTestExpression(ctx, expression.function),
|
|
125
129
|
// ],
|
|
126
|
-
//
|
|
130
|
+
// );
|
|
127
131
|
}
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { AutoBeTest } from "@autobe/interface";
|
|
2
2
|
import ts from "typescript";
|
|
3
|
-
import { ExpressionFactory } from "typia/lib/factories/ExpressionFactory";
|
|
4
3
|
|
|
5
4
|
import { IAutoBeTestProgrammerContext } from "./IAutoBeTestProgrammerContext";
|
|
6
5
|
import { writeTestExpression } from "./writeTestExpression";
|
|
@@ -29,8 +28,8 @@ export namespace AutoBeTestRandomProgrammer {
|
|
|
29
28
|
ctx: IAutoBeTestProgrammerContext,
|
|
30
29
|
expr: AutoBeTest.ISampleRandom,
|
|
31
30
|
): ts.CallExpression =>
|
|
32
|
-
|
|
33
|
-
|
|
31
|
+
ts.factory.createCallExpression(
|
|
32
|
+
ts.factory.createPropertyAccessExpression(
|
|
34
33
|
ts.factory.createIdentifier(
|
|
35
34
|
ctx.importer.external({
|
|
36
35
|
type: "instance",
|
|
@@ -40,11 +39,12 @@ export namespace AutoBeTestRandomProgrammer {
|
|
|
40
39
|
),
|
|
41
40
|
"sample",
|
|
42
41
|
),
|
|
43
|
-
|
|
42
|
+
undefined,
|
|
43
|
+
[
|
|
44
44
|
writeTestExpression(ctx, expr.array),
|
|
45
45
|
writeTestExpression(ctx, expr.count),
|
|
46
46
|
],
|
|
47
|
-
|
|
47
|
+
);
|
|
48
48
|
|
|
49
49
|
export const booleanRandom = (
|
|
50
50
|
_ctx: IAutoBeTestProgrammerContext,
|
|
@@ -244,22 +244,21 @@ export namespace AutoBeTestRandomProgrammer {
|
|
|
244
244
|
export const keywordRandom = (
|
|
245
245
|
ctx: IAutoBeTestProgrammerContext,
|
|
246
246
|
expr: AutoBeTest.IKeywordRandom,
|
|
247
|
-
): ts.Expression =>
|
|
248
|
-
|
|
249
|
-
ts.factory.
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
247
|
+
): ts.Expression =>
|
|
248
|
+
ts.factory.createCallExpression(
|
|
249
|
+
ts.factory.createPropertyAccessExpression(
|
|
250
|
+
ts.factory.createIdentifier(
|
|
251
|
+
ctx.importer.external({
|
|
252
|
+
type: "instance",
|
|
253
|
+
library: "@nestia/e2e",
|
|
254
|
+
name: "RandomGenerator",
|
|
255
|
+
}),
|
|
256
|
+
),
|
|
257
|
+
expr.keyword,
|
|
255
258
|
),
|
|
256
|
-
|
|
259
|
+
undefined,
|
|
260
|
+
undefined,
|
|
257
261
|
);
|
|
258
|
-
new Array(KEYWORD_CURRYING_COUNT[expr.keyword]).fill(0).forEach(() => {
|
|
259
|
-
value = ts.factory.createCallExpression(value, undefined, undefined);
|
|
260
|
-
});
|
|
261
|
-
return value;
|
|
262
|
-
};
|
|
263
262
|
}
|
|
264
263
|
|
|
265
264
|
const createTypiaTag = (
|
|
@@ -303,12 +302,3 @@ const createTypiaRandom = (
|
|
|
303
302
|
: [ts.factory.createIntersectionTypeNode(typeArguments)],
|
|
304
303
|
undefined,
|
|
305
304
|
);
|
|
306
|
-
|
|
307
|
-
const KEYWORD_CURRYING_COUNT = {
|
|
308
|
-
alphabets: 1,
|
|
309
|
-
alphaNumeric: 1,
|
|
310
|
-
mobile: 1,
|
|
311
|
-
name: 1,
|
|
312
|
-
paragraph: 2,
|
|
313
|
-
content: 3,
|
|
314
|
-
};
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { IAutoBeTypeScriptCompileResult } from "@autobe/interface";
|
|
2
|
+
import { IEmbedTypeScriptResult } from "embed-typescript";
|
|
3
|
+
|
|
4
|
+
export const shrinkCompileResult = (
|
|
5
|
+
result: IEmbedTypeScriptResult,
|
|
6
|
+
): IAutoBeTypeScriptCompileResult => {
|
|
7
|
+
if (result.type === "exception") return result;
|
|
8
|
+
else if (result.type === "success")
|
|
9
|
+
return {
|
|
10
|
+
type: "success",
|
|
11
|
+
};
|
|
12
|
+
return {
|
|
13
|
+
type: "failure",
|
|
14
|
+
diagnostics: result.diagnostics,
|
|
15
|
+
};
|
|
16
|
+
};
|