@autobe/compiler 0.30.0-dev.20260315 → 0.30.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/LICENSE +661 -661
- package/lib/database/validateDatabaseApplication.js +318 -318
- package/lib/raw/AutoBeCompilerCommonTemplate.js +5 -5
- package/lib/raw/AutoBeCompilerCommonTemplate.js.map +1 -1
- package/lib/raw/AutoBeCompilerInterfaceTemplate.js +4 -4
- package/lib/raw/AutoBeCompilerInterfaceTemplate.js.map +1 -1
- package/lib/raw/AutoBeCompilerRealizeTemplate.js +27 -27
- package/lib/raw/AutoBeCompilerRealizeTemplate.js.map +1 -1
- package/lib/raw/AutoBeCompilerRealizeTemplateOfPostgres.js +4 -4
- package/lib/raw/AutoBeCompilerRealizeTemplateOfPostgres.js.map +1 -1
- package/lib/raw/AutoBeCompilerRealizeTemplateOfSQLite.js +4 -4
- package/lib/raw/AutoBeCompilerRealizeTemplateOfSQLite.js.map +1 -1
- package/lib/raw/AutoBeCompilerTestTemplate.js +8 -8
- package/lib/raw/AutoBeCompilerTestTemplate.js.map +1 -1
- package/lib/raw/nestjs.json +1640 -1640
- package/lib/raw/test.json +130 -130
- package/package.json +4 -4
- package/src/AutoBeCompiler.ts +93 -93
- package/src/AutoBeTypeScriptCompiler.ts +136 -136
- package/src/database/AutoBeDatabaseCompiler.ts +48 -48
- package/src/database/validateDatabaseApplication.ts +873 -873
- package/src/index.ts +5 -5
- package/src/interface/AutoBeInterfaceCompiler.ts +79 -79
- package/src/raw/AutoBeCompilerCommonTemplate.ts +5 -5
- package/src/raw/AutoBeCompilerInterfaceTemplate.ts +4 -4
- package/src/raw/AutoBeCompilerRealizeTemplate.ts +27 -27
- package/src/raw/AutoBeCompilerRealizeTemplateOfPostgres.ts +4 -4
- package/src/raw/AutoBeCompilerRealizeTemplateOfSQLite.ts +4 -4
- package/src/raw/AutoBeCompilerTestTemplate.ts +8 -8
- package/src/raw/nestjs.json +1640 -1640
- package/src/raw/test.json +130 -130
- package/src/realize/AutoBeRealizeCompiler.ts +42 -42
- package/src/realize/testRealizeProject.ts +78 -78
- package/src/realize/writeRealizeControllers.ts +217 -217
- package/src/test/AutoBeTestCompiler.ts +112 -112
- package/src/test/programmers/AutoBeTestAccessorProgrammer.ts +42 -42
- package/src/test/programmers/AutoBeTestFunctionalProgrammer.ts +87 -87
- package/src/test/programmers/AutoBeTestLiteralProgrammer.ts +65 -65
- package/src/test/programmers/AutoBeTestOperatorProgrammer.ts +84 -84
- package/src/test/programmers/AutoBeTestPredicateProgrammer.ts +131 -131
- package/src/test/programmers/AutoBeTestRandomProgrammer.ts +304 -304
- package/src/test/programmers/AutoBeTestStatementProgrammer.ts +154 -154
- package/src/test/programmers/IAutoBeTestApiFunction.ts +6 -6
- package/src/test/programmers/IAutoBeTestProgrammerContext.ts +11 -11
- package/src/test/programmers/writeTestExpression.ts +29 -29
- package/src/test/programmers/writeTestFunction.ts +103 -103
- package/src/test/programmers/writeTestStatement.ts +19 -19
- package/src/utils/ArrayUtil.ts +21 -21
- package/src/utils/FilePrinter.ts +67 -67
- package/src/utils/ProcessUtil.ts +14 -14
- package/src/utils/shrinkCompileResult.ts +16 -16
- package/README.md +0 -261
|
@@ -1,112 +1,112 @@
|
|
|
1
|
-
import {
|
|
2
|
-
AutoBeOpenApi,
|
|
3
|
-
IAutoBeTestCompiler,
|
|
4
|
-
IAutoBeTestValidateProps,
|
|
5
|
-
IAutoBeTestWriteProps,
|
|
6
|
-
IAutoBeTypeScriptCompileProps,
|
|
7
|
-
IAutoBeTypeScriptCompileResult,
|
|
8
|
-
} from "@autobe/interface";
|
|
9
|
-
import {
|
|
10
|
-
AutoBeOpenApiEndpointComparator,
|
|
11
|
-
validateTestFunction,
|
|
12
|
-
} from "@autobe/utils";
|
|
13
|
-
import { EmbedEsLint } from "embed-eslint";
|
|
14
|
-
import { HashMap, Pair } from "tstl";
|
|
15
|
-
import ts from "typescript";
|
|
16
|
-
import { IValidation } from "typia";
|
|
17
|
-
import typiaTransform from "typia/lib/transform";
|
|
18
|
-
|
|
19
|
-
import { AutoBeCompilerInterfaceTemplate } from "../raw/AutoBeCompilerInterfaceTemplate";
|
|
20
|
-
import TestExternal from "../raw/test.json";
|
|
21
|
-
import { FilePrinter } from "../utils/FilePrinter";
|
|
22
|
-
import { shrinkCompileResult } from "../utils/shrinkCompileResult";
|
|
23
|
-
import { writeTestFunction } from "./programmers/writeTestFunction";
|
|
24
|
-
|
|
25
|
-
export class AutoBeTestCompiler implements IAutoBeTestCompiler {
|
|
26
|
-
public async compile(
|
|
27
|
-
props: IAutoBeTypeScriptCompileProps,
|
|
28
|
-
): Promise<IAutoBeTypeScriptCompileResult> {
|
|
29
|
-
const alias: string = props.package ?? "@ORGANIZATION/PROJECT-api";
|
|
30
|
-
const compiler: EmbedEsLint = new EmbedEsLint({
|
|
31
|
-
external: TestExternal as Record<string, string>,
|
|
32
|
-
compilerOptions: {
|
|
33
|
-
target: ts.ScriptTarget.ESNext,
|
|
34
|
-
module: ts.ModuleKind.CommonJS,
|
|
35
|
-
downlevelIteration: true,
|
|
36
|
-
baseUrl: "./",
|
|
37
|
-
paths: {
|
|
38
|
-
[alias]: ["./src/api"],
|
|
39
|
-
[`${alias}/lib/*`]: ["./src/api/*"],
|
|
40
|
-
},
|
|
41
|
-
strict: true,
|
|
42
|
-
skipLibCheck: true,
|
|
43
|
-
esModuleInterop: true,
|
|
44
|
-
experimentalDecorators: true,
|
|
45
|
-
emitDecoratorMetadata: true,
|
|
46
|
-
noErrorTruncation: true,
|
|
47
|
-
},
|
|
48
|
-
transformers: (program, diagnostics) => ({
|
|
49
|
-
before: [
|
|
50
|
-
typiaTransform(
|
|
51
|
-
program,
|
|
52
|
-
{},
|
|
53
|
-
{
|
|
54
|
-
addDiagnostic: (input) => diagnostics.push(input),
|
|
55
|
-
},
|
|
56
|
-
),
|
|
57
|
-
],
|
|
58
|
-
}),
|
|
59
|
-
rules: {
|
|
60
|
-
"no-floating-promises": "error",
|
|
61
|
-
},
|
|
62
|
-
});
|
|
63
|
-
return shrinkCompileResult(compiler.compile(props.files));
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
public async validate(
|
|
67
|
-
props: IAutoBeTestValidateProps,
|
|
68
|
-
): Promise<IValidation.IError[] | null> {
|
|
69
|
-
const errors: IValidation.IError[] = [];
|
|
70
|
-
const endpoints: HashMap<
|
|
71
|
-
AutoBeOpenApi.IEndpoint,
|
|
72
|
-
AutoBeOpenApi.IOperation
|
|
73
|
-
> = new HashMap(
|
|
74
|
-
props.document.operations.map(
|
|
75
|
-
(op) =>
|
|
76
|
-
new Pair(
|
|
77
|
-
{
|
|
78
|
-
method: op.method,
|
|
79
|
-
path: op.path,
|
|
80
|
-
},
|
|
81
|
-
op,
|
|
82
|
-
),
|
|
83
|
-
),
|
|
84
|
-
AutoBeOpenApiEndpointComparator.hashCode,
|
|
85
|
-
AutoBeOpenApiEndpointComparator.equals,
|
|
86
|
-
);
|
|
87
|
-
validateTestFunction({
|
|
88
|
-
function: props.function,
|
|
89
|
-
document: props.document,
|
|
90
|
-
endpoints: endpoints,
|
|
91
|
-
errors,
|
|
92
|
-
});
|
|
93
|
-
return errors.length !== 0 ? errors : null;
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
public async write(props: IAutoBeTestWriteProps): Promise<string> {
|
|
97
|
-
const content: string = writeTestFunction(props);
|
|
98
|
-
return props.prettier === false ? content : FilePrinter.beautify(content);
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
public async getExternal(): Promise<Record<string, string>> {
|
|
102
|
-
return TestExternal as Record<string, string>;
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
public async getDefaultTypes(): Promise<Record<string, string>> {
|
|
106
|
-
return Object.fromEntries(
|
|
107
|
-
Object.entries(AutoBeCompilerInterfaceTemplate).filter(([key]) =>
|
|
108
|
-
key.startsWith("src/api/"),
|
|
109
|
-
),
|
|
110
|
-
);
|
|
111
|
-
}
|
|
112
|
-
}
|
|
1
|
+
import {
|
|
2
|
+
AutoBeOpenApi,
|
|
3
|
+
IAutoBeTestCompiler,
|
|
4
|
+
IAutoBeTestValidateProps,
|
|
5
|
+
IAutoBeTestWriteProps,
|
|
6
|
+
IAutoBeTypeScriptCompileProps,
|
|
7
|
+
IAutoBeTypeScriptCompileResult,
|
|
8
|
+
} from "@autobe/interface";
|
|
9
|
+
import {
|
|
10
|
+
AutoBeOpenApiEndpointComparator,
|
|
11
|
+
validateTestFunction,
|
|
12
|
+
} from "@autobe/utils";
|
|
13
|
+
import { EmbedEsLint } from "embed-eslint";
|
|
14
|
+
import { HashMap, Pair } from "tstl";
|
|
15
|
+
import ts from "typescript";
|
|
16
|
+
import { IValidation } from "typia";
|
|
17
|
+
import typiaTransform from "typia/lib/transform";
|
|
18
|
+
|
|
19
|
+
import { AutoBeCompilerInterfaceTemplate } from "../raw/AutoBeCompilerInterfaceTemplate";
|
|
20
|
+
import TestExternal from "../raw/test.json";
|
|
21
|
+
import { FilePrinter } from "../utils/FilePrinter";
|
|
22
|
+
import { shrinkCompileResult } from "../utils/shrinkCompileResult";
|
|
23
|
+
import { writeTestFunction } from "./programmers/writeTestFunction";
|
|
24
|
+
|
|
25
|
+
export class AutoBeTestCompiler implements IAutoBeTestCompiler {
|
|
26
|
+
public async compile(
|
|
27
|
+
props: IAutoBeTypeScriptCompileProps,
|
|
28
|
+
): Promise<IAutoBeTypeScriptCompileResult> {
|
|
29
|
+
const alias: string = props.package ?? "@ORGANIZATION/PROJECT-api";
|
|
30
|
+
const compiler: EmbedEsLint = new EmbedEsLint({
|
|
31
|
+
external: TestExternal as Record<string, string>,
|
|
32
|
+
compilerOptions: {
|
|
33
|
+
target: ts.ScriptTarget.ESNext,
|
|
34
|
+
module: ts.ModuleKind.CommonJS,
|
|
35
|
+
downlevelIteration: true,
|
|
36
|
+
baseUrl: "./",
|
|
37
|
+
paths: {
|
|
38
|
+
[alias]: ["./src/api"],
|
|
39
|
+
[`${alias}/lib/*`]: ["./src/api/*"],
|
|
40
|
+
},
|
|
41
|
+
strict: true,
|
|
42
|
+
skipLibCheck: true,
|
|
43
|
+
esModuleInterop: true,
|
|
44
|
+
experimentalDecorators: true,
|
|
45
|
+
emitDecoratorMetadata: true,
|
|
46
|
+
noErrorTruncation: true,
|
|
47
|
+
},
|
|
48
|
+
transformers: (program, diagnostics) => ({
|
|
49
|
+
before: [
|
|
50
|
+
typiaTransform(
|
|
51
|
+
program,
|
|
52
|
+
{},
|
|
53
|
+
{
|
|
54
|
+
addDiagnostic: (input) => diagnostics.push(input),
|
|
55
|
+
},
|
|
56
|
+
),
|
|
57
|
+
],
|
|
58
|
+
}),
|
|
59
|
+
rules: {
|
|
60
|
+
"no-floating-promises": "error",
|
|
61
|
+
},
|
|
62
|
+
});
|
|
63
|
+
return shrinkCompileResult(compiler.compile(props.files));
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
public async validate(
|
|
67
|
+
props: IAutoBeTestValidateProps,
|
|
68
|
+
): Promise<IValidation.IError[] | null> {
|
|
69
|
+
const errors: IValidation.IError[] = [];
|
|
70
|
+
const endpoints: HashMap<
|
|
71
|
+
AutoBeOpenApi.IEndpoint,
|
|
72
|
+
AutoBeOpenApi.IOperation
|
|
73
|
+
> = new HashMap(
|
|
74
|
+
props.document.operations.map(
|
|
75
|
+
(op) =>
|
|
76
|
+
new Pair(
|
|
77
|
+
{
|
|
78
|
+
method: op.method,
|
|
79
|
+
path: op.path,
|
|
80
|
+
},
|
|
81
|
+
op,
|
|
82
|
+
),
|
|
83
|
+
),
|
|
84
|
+
AutoBeOpenApiEndpointComparator.hashCode,
|
|
85
|
+
AutoBeOpenApiEndpointComparator.equals,
|
|
86
|
+
);
|
|
87
|
+
validateTestFunction({
|
|
88
|
+
function: props.function,
|
|
89
|
+
document: props.document,
|
|
90
|
+
endpoints: endpoints,
|
|
91
|
+
errors,
|
|
92
|
+
});
|
|
93
|
+
return errors.length !== 0 ? errors : null;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
public async write(props: IAutoBeTestWriteProps): Promise<string> {
|
|
97
|
+
const content: string = writeTestFunction(props);
|
|
98
|
+
return props.prettier === false ? content : FilePrinter.beautify(content);
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
public async getExternal(): Promise<Record<string, string>> {
|
|
102
|
+
return TestExternal as Record<string, string>;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
public async getDefaultTypes(): Promise<Record<string, string>> {
|
|
106
|
+
return Object.fromEntries(
|
|
107
|
+
Object.entries(AutoBeCompilerInterfaceTemplate).filter(([key]) =>
|
|
108
|
+
key.startsWith("src/api/"),
|
|
109
|
+
),
|
|
110
|
+
);
|
|
111
|
+
}
|
|
112
|
+
}
|
|
@@ -1,42 +1,42 @@
|
|
|
1
|
-
import { AutoBeTest } from "@autobe/interface";
|
|
2
|
-
import ts from "typescript";
|
|
3
|
-
|
|
4
|
-
import { IAutoBeTestProgrammerContext } from "./IAutoBeTestProgrammerContext";
|
|
5
|
-
import { writeTestExpression } from "./writeTestExpression";
|
|
6
|
-
|
|
7
|
-
export namespace AutoBeTestAccessorProgrammer {
|
|
8
|
-
export const identifier = (
|
|
9
|
-
_ctx: IAutoBeTestProgrammerContext,
|
|
10
|
-
expr: AutoBeTest.IIdentifier,
|
|
11
|
-
): ts.Identifier => ts.factory.createIdentifier(expr.text);
|
|
12
|
-
|
|
13
|
-
export const propertyAccessExpression = (
|
|
14
|
-
ctx: IAutoBeTestProgrammerContext,
|
|
15
|
-
expr: AutoBeTest.IPropertyAccessExpression,
|
|
16
|
-
): ts.PropertyAccessChain | ts.PropertyAccessExpression =>
|
|
17
|
-
expr.questionDot
|
|
18
|
-
? ts.factory.createPropertyAccessChain(
|
|
19
|
-
writeTestExpression(ctx, expr.expression),
|
|
20
|
-
ts.factory.createToken(ts.SyntaxKind.QuestionDotToken),
|
|
21
|
-
expr.name,
|
|
22
|
-
)
|
|
23
|
-
: ts.factory.createPropertyAccessExpression(
|
|
24
|
-
writeTestExpression(ctx, expr.expression),
|
|
25
|
-
expr.name,
|
|
26
|
-
);
|
|
27
|
-
|
|
28
|
-
export const elementAccessExpression = (
|
|
29
|
-
ctx: IAutoBeTestProgrammerContext,
|
|
30
|
-
expr: AutoBeTest.IElementAccessExpression,
|
|
31
|
-
): ts.ElementAccessChain | ts.ElementAccessExpression =>
|
|
32
|
-
expr.questionDot
|
|
33
|
-
? ts.factory.createElementAccessChain(
|
|
34
|
-
writeTestExpression(ctx, expr.expression),
|
|
35
|
-
ts.factory.createToken(ts.SyntaxKind.QuestionDotToken),
|
|
36
|
-
writeTestExpression(ctx, expr.argumentExpression),
|
|
37
|
-
)
|
|
38
|
-
: ts.factory.createElementAccessExpression(
|
|
39
|
-
writeTestExpression(ctx, expr.expression),
|
|
40
|
-
writeTestExpression(ctx, expr.argumentExpression),
|
|
41
|
-
);
|
|
42
|
-
}
|
|
1
|
+
import { AutoBeTest } from "@autobe/interface";
|
|
2
|
+
import ts from "typescript";
|
|
3
|
+
|
|
4
|
+
import { IAutoBeTestProgrammerContext } from "./IAutoBeTestProgrammerContext";
|
|
5
|
+
import { writeTestExpression } from "./writeTestExpression";
|
|
6
|
+
|
|
7
|
+
export namespace AutoBeTestAccessorProgrammer {
|
|
8
|
+
export const identifier = (
|
|
9
|
+
_ctx: IAutoBeTestProgrammerContext,
|
|
10
|
+
expr: AutoBeTest.IIdentifier,
|
|
11
|
+
): ts.Identifier => ts.factory.createIdentifier(expr.text);
|
|
12
|
+
|
|
13
|
+
export const propertyAccessExpression = (
|
|
14
|
+
ctx: IAutoBeTestProgrammerContext,
|
|
15
|
+
expr: AutoBeTest.IPropertyAccessExpression,
|
|
16
|
+
): ts.PropertyAccessChain | ts.PropertyAccessExpression =>
|
|
17
|
+
expr.questionDot
|
|
18
|
+
? ts.factory.createPropertyAccessChain(
|
|
19
|
+
writeTestExpression(ctx, expr.expression),
|
|
20
|
+
ts.factory.createToken(ts.SyntaxKind.QuestionDotToken),
|
|
21
|
+
expr.name,
|
|
22
|
+
)
|
|
23
|
+
: ts.factory.createPropertyAccessExpression(
|
|
24
|
+
writeTestExpression(ctx, expr.expression),
|
|
25
|
+
expr.name,
|
|
26
|
+
);
|
|
27
|
+
|
|
28
|
+
export const elementAccessExpression = (
|
|
29
|
+
ctx: IAutoBeTestProgrammerContext,
|
|
30
|
+
expr: AutoBeTest.IElementAccessExpression,
|
|
31
|
+
): ts.ElementAccessChain | ts.ElementAccessExpression =>
|
|
32
|
+
expr.questionDot
|
|
33
|
+
? ts.factory.createElementAccessChain(
|
|
34
|
+
writeTestExpression(ctx, expr.expression),
|
|
35
|
+
ts.factory.createToken(ts.SyntaxKind.QuestionDotToken),
|
|
36
|
+
writeTestExpression(ctx, expr.argumentExpression),
|
|
37
|
+
)
|
|
38
|
+
: ts.factory.createElementAccessExpression(
|
|
39
|
+
writeTestExpression(ctx, expr.expression),
|
|
40
|
+
writeTestExpression(ctx, expr.argumentExpression),
|
|
41
|
+
);
|
|
42
|
+
}
|
|
@@ -1,87 +1,87 @@
|
|
|
1
|
-
import { AutoBeTest } from "@autobe/interface";
|
|
2
|
-
import ts from "typescript";
|
|
3
|
-
|
|
4
|
-
import { AutoBeTestStatementProgrammer } from "./AutoBeTestStatementProgrammer";
|
|
5
|
-
import { IAutoBeTestProgrammerContext } from "./IAutoBeTestProgrammerContext";
|
|
6
|
-
import { writeTestExpression } from "./writeTestExpression";
|
|
7
|
-
|
|
8
|
-
export namespace AutoBeTestFunctionalProgrammer {
|
|
9
|
-
export const arrowFunction = (
|
|
10
|
-
ctx: IAutoBeTestProgrammerContext,
|
|
11
|
-
expr: AutoBeTest.IArrowFunction,
|
|
12
|
-
): ts.ArrowFunction =>
|
|
13
|
-
ts.factory.createArrowFunction(
|
|
14
|
-
[ts.factory.createModifier(ts.SyntaxKind.AsyncKeyword)],
|
|
15
|
-
undefined,
|
|
16
|
-
[],
|
|
17
|
-
undefined,
|
|
18
|
-
undefined,
|
|
19
|
-
AutoBeTestStatementProgrammer.block(ctx, expr.body),
|
|
20
|
-
);
|
|
21
|
-
|
|
22
|
-
export const callExpression = (
|
|
23
|
-
ctx: IAutoBeTestProgrammerContext,
|
|
24
|
-
expr: AutoBeTest.ICallExpression,
|
|
25
|
-
): ts.CallExpression =>
|
|
26
|
-
ts.factory.createCallExpression(
|
|
27
|
-
writeTestExpression(ctx, expr.expression),
|
|
28
|
-
undefined,
|
|
29
|
-
expr.arguments.map((arg) => writeTestExpression(ctx, arg)),
|
|
30
|
-
);
|
|
31
|
-
|
|
32
|
-
export const newExpression = (
|
|
33
|
-
ctx: IAutoBeTestProgrammerContext,
|
|
34
|
-
expr: AutoBeTest.INewExpression,
|
|
35
|
-
): ts.NewExpression =>
|
|
36
|
-
ts.factory.createNewExpression(
|
|
37
|
-
writeTestExpression(ctx, expr.expression),
|
|
38
|
-
undefined,
|
|
39
|
-
expr.arguments.map((arg) => writeTestExpression(ctx, arg)),
|
|
40
|
-
);
|
|
41
|
-
|
|
42
|
-
export const arrayFilterExpression = (
|
|
43
|
-
ctx: IAutoBeTestProgrammerContext,
|
|
44
|
-
expr: AutoBeTest.IArrayFilterExpression,
|
|
45
|
-
): ts.AwaitExpression =>
|
|
46
|
-
arrayExpression(ctx, "asyncFilter", [expr.array, expr.function]);
|
|
47
|
-
|
|
48
|
-
export const arrayForEachExpression = (
|
|
49
|
-
ctx: IAutoBeTestProgrammerContext,
|
|
50
|
-
expr: AutoBeTest.IArrayForEachExpression,
|
|
51
|
-
): ts.AwaitExpression =>
|
|
52
|
-
arrayExpression(ctx, "asyncForEach", [expr.array, expr.function]);
|
|
53
|
-
|
|
54
|
-
export const arrayMapExpression = (
|
|
55
|
-
ctx: IAutoBeTestProgrammerContext,
|
|
56
|
-
expr: AutoBeTest.IArrayMapExpression,
|
|
57
|
-
): ts.AwaitExpression =>
|
|
58
|
-
arrayExpression(ctx, "asyncMap", [expr.array, expr.function]);
|
|
59
|
-
|
|
60
|
-
export const arrayRepeatExpression = (
|
|
61
|
-
ctx: IAutoBeTestProgrammerContext,
|
|
62
|
-
expr: AutoBeTest.IArrayRepeatExpression,
|
|
63
|
-
): ts.AwaitExpression =>
|
|
64
|
-
arrayExpression(ctx, "asyncRepeat", [expr.count, expr.function]);
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
const arrayExpression = (
|
|
68
|
-
ctx: IAutoBeTestProgrammerContext,
|
|
69
|
-
name: string,
|
|
70
|
-
argList: AutoBeTest.IExpression[],
|
|
71
|
-
): ts.AwaitExpression =>
|
|
72
|
-
ts.factory.createAwaitExpression(
|
|
73
|
-
ts.factory.createCallExpression(
|
|
74
|
-
ts.factory.createPropertyAccessExpression(
|
|
75
|
-
ts.factory.createIdentifier(
|
|
76
|
-
ctx.importer.external({
|
|
77
|
-
type: "instance",
|
|
78
|
-
library: "@nestia/e2e",
|
|
79
|
-
name: "ArrayUtil",
|
|
80
|
-
}),
|
|
81
|
-
),
|
|
82
|
-
name,
|
|
83
|
-
),
|
|
84
|
-
undefined,
|
|
85
|
-
argList.map((a) => writeTestExpression(ctx, a)),
|
|
86
|
-
),
|
|
87
|
-
);
|
|
1
|
+
import { AutoBeTest } from "@autobe/interface";
|
|
2
|
+
import ts from "typescript";
|
|
3
|
+
|
|
4
|
+
import { AutoBeTestStatementProgrammer } from "./AutoBeTestStatementProgrammer";
|
|
5
|
+
import { IAutoBeTestProgrammerContext } from "./IAutoBeTestProgrammerContext";
|
|
6
|
+
import { writeTestExpression } from "./writeTestExpression";
|
|
7
|
+
|
|
8
|
+
export namespace AutoBeTestFunctionalProgrammer {
|
|
9
|
+
export const arrowFunction = (
|
|
10
|
+
ctx: IAutoBeTestProgrammerContext,
|
|
11
|
+
expr: AutoBeTest.IArrowFunction,
|
|
12
|
+
): ts.ArrowFunction =>
|
|
13
|
+
ts.factory.createArrowFunction(
|
|
14
|
+
[ts.factory.createModifier(ts.SyntaxKind.AsyncKeyword)],
|
|
15
|
+
undefined,
|
|
16
|
+
[],
|
|
17
|
+
undefined,
|
|
18
|
+
undefined,
|
|
19
|
+
AutoBeTestStatementProgrammer.block(ctx, expr.body),
|
|
20
|
+
);
|
|
21
|
+
|
|
22
|
+
export const callExpression = (
|
|
23
|
+
ctx: IAutoBeTestProgrammerContext,
|
|
24
|
+
expr: AutoBeTest.ICallExpression,
|
|
25
|
+
): ts.CallExpression =>
|
|
26
|
+
ts.factory.createCallExpression(
|
|
27
|
+
writeTestExpression(ctx, expr.expression),
|
|
28
|
+
undefined,
|
|
29
|
+
expr.arguments.map((arg) => writeTestExpression(ctx, arg)),
|
|
30
|
+
);
|
|
31
|
+
|
|
32
|
+
export const newExpression = (
|
|
33
|
+
ctx: IAutoBeTestProgrammerContext,
|
|
34
|
+
expr: AutoBeTest.INewExpression,
|
|
35
|
+
): ts.NewExpression =>
|
|
36
|
+
ts.factory.createNewExpression(
|
|
37
|
+
writeTestExpression(ctx, expr.expression),
|
|
38
|
+
undefined,
|
|
39
|
+
expr.arguments.map((arg) => writeTestExpression(ctx, arg)),
|
|
40
|
+
);
|
|
41
|
+
|
|
42
|
+
export const arrayFilterExpression = (
|
|
43
|
+
ctx: IAutoBeTestProgrammerContext,
|
|
44
|
+
expr: AutoBeTest.IArrayFilterExpression,
|
|
45
|
+
): ts.AwaitExpression =>
|
|
46
|
+
arrayExpression(ctx, "asyncFilter", [expr.array, expr.function]);
|
|
47
|
+
|
|
48
|
+
export const arrayForEachExpression = (
|
|
49
|
+
ctx: IAutoBeTestProgrammerContext,
|
|
50
|
+
expr: AutoBeTest.IArrayForEachExpression,
|
|
51
|
+
): ts.AwaitExpression =>
|
|
52
|
+
arrayExpression(ctx, "asyncForEach", [expr.array, expr.function]);
|
|
53
|
+
|
|
54
|
+
export const arrayMapExpression = (
|
|
55
|
+
ctx: IAutoBeTestProgrammerContext,
|
|
56
|
+
expr: AutoBeTest.IArrayMapExpression,
|
|
57
|
+
): ts.AwaitExpression =>
|
|
58
|
+
arrayExpression(ctx, "asyncMap", [expr.array, expr.function]);
|
|
59
|
+
|
|
60
|
+
export const arrayRepeatExpression = (
|
|
61
|
+
ctx: IAutoBeTestProgrammerContext,
|
|
62
|
+
expr: AutoBeTest.IArrayRepeatExpression,
|
|
63
|
+
): ts.AwaitExpression =>
|
|
64
|
+
arrayExpression(ctx, "asyncRepeat", [expr.count, expr.function]);
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
const arrayExpression = (
|
|
68
|
+
ctx: IAutoBeTestProgrammerContext,
|
|
69
|
+
name: string,
|
|
70
|
+
argList: AutoBeTest.IExpression[],
|
|
71
|
+
): ts.AwaitExpression =>
|
|
72
|
+
ts.factory.createAwaitExpression(
|
|
73
|
+
ts.factory.createCallExpression(
|
|
74
|
+
ts.factory.createPropertyAccessExpression(
|
|
75
|
+
ts.factory.createIdentifier(
|
|
76
|
+
ctx.importer.external({
|
|
77
|
+
type: "instance",
|
|
78
|
+
library: "@nestia/e2e",
|
|
79
|
+
name: "ArrayUtil",
|
|
80
|
+
}),
|
|
81
|
+
),
|
|
82
|
+
name,
|
|
83
|
+
),
|
|
84
|
+
undefined,
|
|
85
|
+
argList.map((a) => writeTestExpression(ctx, a)),
|
|
86
|
+
),
|
|
87
|
+
);
|
|
@@ -1,65 +1,65 @@
|
|
|
1
|
-
import { AutoBeTest } from "@autobe/interface";
|
|
2
|
-
import { NamingConvention } from "@typia/utils";
|
|
3
|
-
import ts from "typescript";
|
|
4
|
-
|
|
5
|
-
import { IAutoBeTestProgrammerContext } from "./IAutoBeTestProgrammerContext";
|
|
6
|
-
import { writeTestExpression } from "./writeTestExpression";
|
|
7
|
-
|
|
8
|
-
export namespace AutoBeTestLiteralProgrammer {
|
|
9
|
-
export const booleanLiteral = (
|
|
10
|
-
_ctx: IAutoBeTestProgrammerContext,
|
|
11
|
-
expr: AutoBeTest.IBooleanLiteral,
|
|
12
|
-
): ts.BooleanLiteral =>
|
|
13
|
-
expr.value ? ts.factory.createTrue() : ts.factory.createFalse();
|
|
14
|
-
|
|
15
|
-
export const numericLiteral = (
|
|
16
|
-
_ctx: IAutoBeTestProgrammerContext,
|
|
17
|
-
expr: AutoBeTest.INumericLiteral,
|
|
18
|
-
): ts.NumericLiteral | ts.PrefixUnaryExpression =>
|
|
19
|
-
expr.value < 0
|
|
20
|
-
? ts.factory.createPrefixUnaryExpression(
|
|
21
|
-
ts.SyntaxKind.MinusToken,
|
|
22
|
-
ts.factory.createNumericLiteral(-expr.value),
|
|
23
|
-
)
|
|
24
|
-
: ts.factory.createNumericLiteral(expr.value);
|
|
25
|
-
|
|
26
|
-
export const stringLiteral = (
|
|
27
|
-
_ctx: IAutoBeTestProgrammerContext,
|
|
28
|
-
expr: AutoBeTest.IStringLiteral,
|
|
29
|
-
): ts.StringLiteral => ts.factory.createStringLiteral(expr.value);
|
|
30
|
-
|
|
31
|
-
export const arrayLiteralExpression = (
|
|
32
|
-
ctx: IAutoBeTestProgrammerContext,
|
|
33
|
-
expr: AutoBeTest.IArrayLiteralExpression,
|
|
34
|
-
): ts.ArrayLiteralExpression =>
|
|
35
|
-
ts.factory.createArrayLiteralExpression(
|
|
36
|
-
expr.elements.map((elem) => writeTestExpression(ctx, elem)),
|
|
37
|
-
true,
|
|
38
|
-
);
|
|
39
|
-
|
|
40
|
-
export const objectLiteralExpression = (
|
|
41
|
-
ctx: IAutoBeTestProgrammerContext,
|
|
42
|
-
expr: AutoBeTest.IObjectLiteralExpression,
|
|
43
|
-
): ts.ObjectLiteralExpression =>
|
|
44
|
-
ts.factory.createObjectLiteralExpression(
|
|
45
|
-
expr.properties.map((e) =>
|
|
46
|
-
ts.factory.createPropertyAssignment(
|
|
47
|
-
NamingConvention.variable(e.name)
|
|
48
|
-
? ts.factory.createIdentifier(e.name)
|
|
49
|
-
: ts.factory.createStringLiteral(e.name),
|
|
50
|
-
writeTestExpression(ctx, e.value),
|
|
51
|
-
),
|
|
52
|
-
),
|
|
53
|
-
true,
|
|
54
|
-
);
|
|
55
|
-
|
|
56
|
-
export const nullLiteral = (
|
|
57
|
-
_ctx: IAutoBeTestProgrammerContext,
|
|
58
|
-
_expr: AutoBeTest.INullLiteral,
|
|
59
|
-
): ts.NullLiteral => ts.factory.createNull();
|
|
60
|
-
|
|
61
|
-
export const undefinedKeyword = (
|
|
62
|
-
_ctx: IAutoBeTestProgrammerContext,
|
|
63
|
-
_expr: AutoBeTest.IUndefinedKeyword,
|
|
64
|
-
): ts.Identifier => ts.factory.createIdentifier("undefined");
|
|
65
|
-
}
|
|
1
|
+
import { AutoBeTest } from "@autobe/interface";
|
|
2
|
+
import { NamingConvention } from "@typia/utils";
|
|
3
|
+
import ts from "typescript";
|
|
4
|
+
|
|
5
|
+
import { IAutoBeTestProgrammerContext } from "./IAutoBeTestProgrammerContext";
|
|
6
|
+
import { writeTestExpression } from "./writeTestExpression";
|
|
7
|
+
|
|
8
|
+
export namespace AutoBeTestLiteralProgrammer {
|
|
9
|
+
export const booleanLiteral = (
|
|
10
|
+
_ctx: IAutoBeTestProgrammerContext,
|
|
11
|
+
expr: AutoBeTest.IBooleanLiteral,
|
|
12
|
+
): ts.BooleanLiteral =>
|
|
13
|
+
expr.value ? ts.factory.createTrue() : ts.factory.createFalse();
|
|
14
|
+
|
|
15
|
+
export const numericLiteral = (
|
|
16
|
+
_ctx: IAutoBeTestProgrammerContext,
|
|
17
|
+
expr: AutoBeTest.INumericLiteral,
|
|
18
|
+
): ts.NumericLiteral | ts.PrefixUnaryExpression =>
|
|
19
|
+
expr.value < 0
|
|
20
|
+
? ts.factory.createPrefixUnaryExpression(
|
|
21
|
+
ts.SyntaxKind.MinusToken,
|
|
22
|
+
ts.factory.createNumericLiteral(-expr.value),
|
|
23
|
+
)
|
|
24
|
+
: ts.factory.createNumericLiteral(expr.value);
|
|
25
|
+
|
|
26
|
+
export const stringLiteral = (
|
|
27
|
+
_ctx: IAutoBeTestProgrammerContext,
|
|
28
|
+
expr: AutoBeTest.IStringLiteral,
|
|
29
|
+
): ts.StringLiteral => ts.factory.createStringLiteral(expr.value);
|
|
30
|
+
|
|
31
|
+
export const arrayLiteralExpression = (
|
|
32
|
+
ctx: IAutoBeTestProgrammerContext,
|
|
33
|
+
expr: AutoBeTest.IArrayLiteralExpression,
|
|
34
|
+
): ts.ArrayLiteralExpression =>
|
|
35
|
+
ts.factory.createArrayLiteralExpression(
|
|
36
|
+
expr.elements.map((elem) => writeTestExpression(ctx, elem)),
|
|
37
|
+
true,
|
|
38
|
+
);
|
|
39
|
+
|
|
40
|
+
export const objectLiteralExpression = (
|
|
41
|
+
ctx: IAutoBeTestProgrammerContext,
|
|
42
|
+
expr: AutoBeTest.IObjectLiteralExpression,
|
|
43
|
+
): ts.ObjectLiteralExpression =>
|
|
44
|
+
ts.factory.createObjectLiteralExpression(
|
|
45
|
+
expr.properties.map((e) =>
|
|
46
|
+
ts.factory.createPropertyAssignment(
|
|
47
|
+
NamingConvention.variable(e.name)
|
|
48
|
+
? ts.factory.createIdentifier(e.name)
|
|
49
|
+
: ts.factory.createStringLiteral(e.name),
|
|
50
|
+
writeTestExpression(ctx, e.value),
|
|
51
|
+
),
|
|
52
|
+
),
|
|
53
|
+
true,
|
|
54
|
+
);
|
|
55
|
+
|
|
56
|
+
export const nullLiteral = (
|
|
57
|
+
_ctx: IAutoBeTestProgrammerContext,
|
|
58
|
+
_expr: AutoBeTest.INullLiteral,
|
|
59
|
+
): ts.NullLiteral => ts.factory.createNull();
|
|
60
|
+
|
|
61
|
+
export const undefinedKeyword = (
|
|
62
|
+
_ctx: IAutoBeTestProgrammerContext,
|
|
63
|
+
_expr: AutoBeTest.IUndefinedKeyword,
|
|
64
|
+
): ts.Identifier => ts.factory.createIdentifier("undefined");
|
|
65
|
+
}
|