@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.
Files changed (52) hide show
  1. package/LICENSE +661 -661
  2. package/lib/database/validateDatabaseApplication.js +318 -318
  3. package/lib/raw/AutoBeCompilerCommonTemplate.js +5 -5
  4. package/lib/raw/AutoBeCompilerCommonTemplate.js.map +1 -1
  5. package/lib/raw/AutoBeCompilerInterfaceTemplate.js +4 -4
  6. package/lib/raw/AutoBeCompilerInterfaceTemplate.js.map +1 -1
  7. package/lib/raw/AutoBeCompilerRealizeTemplate.js +27 -27
  8. package/lib/raw/AutoBeCompilerRealizeTemplate.js.map +1 -1
  9. package/lib/raw/AutoBeCompilerRealizeTemplateOfPostgres.js +4 -4
  10. package/lib/raw/AutoBeCompilerRealizeTemplateOfPostgres.js.map +1 -1
  11. package/lib/raw/AutoBeCompilerRealizeTemplateOfSQLite.js +4 -4
  12. package/lib/raw/AutoBeCompilerRealizeTemplateOfSQLite.js.map +1 -1
  13. package/lib/raw/AutoBeCompilerTestTemplate.js +8 -8
  14. package/lib/raw/AutoBeCompilerTestTemplate.js.map +1 -1
  15. package/lib/raw/nestjs.json +1640 -1640
  16. package/lib/raw/test.json +130 -130
  17. package/package.json +4 -4
  18. package/src/AutoBeCompiler.ts +93 -93
  19. package/src/AutoBeTypeScriptCompiler.ts +136 -136
  20. package/src/database/AutoBeDatabaseCompiler.ts +48 -48
  21. package/src/database/validateDatabaseApplication.ts +873 -873
  22. package/src/index.ts +5 -5
  23. package/src/interface/AutoBeInterfaceCompiler.ts +79 -79
  24. package/src/raw/AutoBeCompilerCommonTemplate.ts +5 -5
  25. package/src/raw/AutoBeCompilerInterfaceTemplate.ts +4 -4
  26. package/src/raw/AutoBeCompilerRealizeTemplate.ts +27 -27
  27. package/src/raw/AutoBeCompilerRealizeTemplateOfPostgres.ts +4 -4
  28. package/src/raw/AutoBeCompilerRealizeTemplateOfSQLite.ts +4 -4
  29. package/src/raw/AutoBeCompilerTestTemplate.ts +8 -8
  30. package/src/raw/nestjs.json +1640 -1640
  31. package/src/raw/test.json +130 -130
  32. package/src/realize/AutoBeRealizeCompiler.ts +42 -42
  33. package/src/realize/testRealizeProject.ts +78 -78
  34. package/src/realize/writeRealizeControllers.ts +217 -217
  35. package/src/test/AutoBeTestCompiler.ts +112 -112
  36. package/src/test/programmers/AutoBeTestAccessorProgrammer.ts +42 -42
  37. package/src/test/programmers/AutoBeTestFunctionalProgrammer.ts +87 -87
  38. package/src/test/programmers/AutoBeTestLiteralProgrammer.ts +65 -65
  39. package/src/test/programmers/AutoBeTestOperatorProgrammer.ts +84 -84
  40. package/src/test/programmers/AutoBeTestPredicateProgrammer.ts +131 -131
  41. package/src/test/programmers/AutoBeTestRandomProgrammer.ts +304 -304
  42. package/src/test/programmers/AutoBeTestStatementProgrammer.ts +154 -154
  43. package/src/test/programmers/IAutoBeTestApiFunction.ts +6 -6
  44. package/src/test/programmers/IAutoBeTestProgrammerContext.ts +11 -11
  45. package/src/test/programmers/writeTestExpression.ts +29 -29
  46. package/src/test/programmers/writeTestFunction.ts +103 -103
  47. package/src/test/programmers/writeTestStatement.ts +19 -19
  48. package/src/utils/ArrayUtil.ts +21 -21
  49. package/src/utils/FilePrinter.ts +67 -67
  50. package/src/utils/ProcessUtil.ts +14 -14
  51. package/src/utils/shrinkCompileResult.ts +16 -16
  52. package/README.md +0 -261
@@ -1,154 +1,154 @@
1
- import { AutoBeTest } from "@autobe/interface";
2
- import ts from "typescript";
3
-
4
- import { FilePrinter } from "../../utils/FilePrinter";
5
- import { IAutoBeTestApiFunction } from "./IAutoBeTestApiFunction";
6
- import { IAutoBeTestProgrammerContext } from "./IAutoBeTestProgrammerContext";
7
- import { writeTestExpression } from "./writeTestExpression";
8
- import { writeTestStatement } from "./writeTestStatement";
9
-
10
- export namespace AutoBeTestStatementProgrammer {
11
- export const block = (
12
- ctx: IAutoBeTestProgrammerContext,
13
- stmt: AutoBeTest.IBlock,
14
- ): ts.Block =>
15
- ts.factory.createBlock(
16
- stmt.statements
17
- .map((child, i) => [
18
- ...writeTestStatement(ctx, child).filter((childStmt, j) =>
19
- j === 0
20
- ? ts.addSyntheticLeadingComment(
21
- childStmt,
22
- ts.SyntaxKind.SingleLineCommentTrivia,
23
- JSON.stringify(child),
24
- true,
25
- )
26
- : childStmt,
27
- ),
28
- ...(i !== 0 ? [FilePrinter.newLine()] : []),
29
- ])
30
- .flat(),
31
- true,
32
- );
33
-
34
- export const expressionStatement = (
35
- ctx: IAutoBeTestProgrammerContext,
36
- stmt: AutoBeTest.IExpressionStatement,
37
- ): ts.ExpressionStatement =>
38
- ts.factory.createExpressionStatement(
39
- writeTestExpression(ctx, stmt.expression),
40
- );
41
-
42
- // export const variableDeclaration = (
43
- // ctx: IAutoBeTestProgrammerContext,
44
- // stmt: AutoBeTest.IVariableDeclaration,
45
- // ): ts.VariableStatement => {
46
- // const typeNode: ts.TypeNode = NestiaMigrateSchemaProgrammer.write({
47
- // components: ctx.document.components,
48
- // importer: ctx.importer,
49
- // schema: OpenApiV3_1Emender.convertSchema(ctx.document.components)(
50
- // stmt.schema,
51
- // ),
52
- // });
53
- // return ts.factory.createVariableStatement(
54
- // undefined,
55
- // ts.factory.createVariableDeclarationList(
56
- // [
57
- // ts.factory.createVariableDeclaration(
58
- // stmt.name,
59
- // undefined,
60
- // typeNode,
61
- // undefined,
62
- // ),
63
- // ],
64
- // stmt.mutability === "const" ? ts.NodeFlags.Constant : ts.NodeFlags.Let,
65
- // ),
66
- // );
67
- // };
68
-
69
- export const ifStatement = (
70
- ctx: IAutoBeTestProgrammerContext,
71
- stmt: AutoBeTest.IIfStatement,
72
- ): ts.IfStatement =>
73
- ts.factory.createIfStatement(
74
- writeTestExpression(ctx, stmt.condition),
75
- block(ctx, stmt.thenStatement),
76
- stmt.elseStatement
77
- ? stmt.elseStatement.type === "ifStatement"
78
- ? ifStatement(ctx, stmt.elseStatement)
79
- : block(ctx, stmt.elseStatement)
80
- : undefined,
81
- );
82
-
83
- export const returnStatement = (
84
- ctx: IAutoBeTestProgrammerContext,
85
- stmt: AutoBeTest.IReturnStatement,
86
- ): ts.ReturnStatement =>
87
- ts.factory.createReturnStatement(writeTestExpression(ctx, stmt.expression));
88
-
89
- export const throwStatement = (
90
- ctx: IAutoBeTestProgrammerContext,
91
- stmt: AutoBeTest.IThrowStatement,
92
- ): ts.ThrowStatement =>
93
- ts.factory.createThrowStatement(writeTestExpression(ctx, stmt.expression));
94
-
95
- export const apiOperateStatement = (
96
- ctx: IAutoBeTestProgrammerContext,
97
- stmt: AutoBeTest.IApiOperateStatement,
98
- ): ts.Statement[] => {
99
- // find the function
100
- const func: IAutoBeTestApiFunction = ctx.endpoints.get(stmt.endpoint);
101
- if (!!stmt.variableName?.length && !!func.operation.responseBody)
102
- ctx.importer.dto(func.operation.responseBody.typeName);
103
-
104
- // make await function call expression
105
- const initializer: ts.AwaitExpression = ts.factory.createAwaitExpression(
106
- ts.factory.createCallExpression(
107
- ts.factory.createIdentifier(func.accessor),
108
- [],
109
- [
110
- ts.factory.createIdentifier("connection"),
111
- ...(stmt.argument ? [writeTestExpression(ctx, stmt.argument)] : []),
112
- ],
113
- ),
114
- );
115
- if (stmt.variableName === null || stmt.variableName === undefined)
116
- return [ts.factory.createExpressionStatement(initializer)];
117
-
118
- const variable: ts.VariableStatement = ts.factory.createVariableStatement(
119
- undefined,
120
- ts.factory.createVariableDeclarationList(
121
- [
122
- ts.factory.createVariableDeclaration(
123
- stmt.variableName,
124
- undefined,
125
- !!func.operation.responseBody
126
- ? ts.factory.createTypeReferenceNode(
127
- func.operation.responseBody.typeName,
128
- )
129
- : ts.factory.createKeywordTypeNode(
130
- ts.SyntaxKind.UndefinedKeyword,
131
- ),
132
- initializer,
133
- ),
134
- ],
135
- ts.NodeFlags.Const,
136
- ),
137
- );
138
- const assertion = ts.factory.createCallExpression(
139
- ts.factory.createPropertyAccessExpression(
140
- ts.factory.createIdentifier(
141
- ctx.importer.external({
142
- type: "default",
143
- library: "typia",
144
- name: "typia",
145
- }),
146
- ),
147
- "assert",
148
- ),
149
- undefined,
150
- [ts.factory.createIdentifier(stmt.variableName)],
151
- );
152
- return [variable, ts.factory.createExpressionStatement(assertion)];
153
- };
154
- }
1
+ import { AutoBeTest } from "@autobe/interface";
2
+ import ts from "typescript";
3
+
4
+ import { FilePrinter } from "../../utils/FilePrinter";
5
+ import { IAutoBeTestApiFunction } from "./IAutoBeTestApiFunction";
6
+ import { IAutoBeTestProgrammerContext } from "./IAutoBeTestProgrammerContext";
7
+ import { writeTestExpression } from "./writeTestExpression";
8
+ import { writeTestStatement } from "./writeTestStatement";
9
+
10
+ export namespace AutoBeTestStatementProgrammer {
11
+ export const block = (
12
+ ctx: IAutoBeTestProgrammerContext,
13
+ stmt: AutoBeTest.IBlock,
14
+ ): ts.Block =>
15
+ ts.factory.createBlock(
16
+ stmt.statements
17
+ .map((child, i) => [
18
+ ...writeTestStatement(ctx, child).filter((childStmt, j) =>
19
+ j === 0
20
+ ? ts.addSyntheticLeadingComment(
21
+ childStmt,
22
+ ts.SyntaxKind.SingleLineCommentTrivia,
23
+ JSON.stringify(child),
24
+ true,
25
+ )
26
+ : childStmt,
27
+ ),
28
+ ...(i !== 0 ? [FilePrinter.newLine()] : []),
29
+ ])
30
+ .flat(),
31
+ true,
32
+ );
33
+
34
+ export const expressionStatement = (
35
+ ctx: IAutoBeTestProgrammerContext,
36
+ stmt: AutoBeTest.IExpressionStatement,
37
+ ): ts.ExpressionStatement =>
38
+ ts.factory.createExpressionStatement(
39
+ writeTestExpression(ctx, stmt.expression),
40
+ );
41
+
42
+ // export const variableDeclaration = (
43
+ // ctx: IAutoBeTestProgrammerContext,
44
+ // stmt: AutoBeTest.IVariableDeclaration,
45
+ // ): ts.VariableStatement => {
46
+ // const typeNode: ts.TypeNode = NestiaMigrateSchemaProgrammer.write({
47
+ // components: ctx.document.components,
48
+ // importer: ctx.importer,
49
+ // schema: OpenApiV3_1Emender.convertSchema(ctx.document.components)(
50
+ // stmt.schema,
51
+ // ),
52
+ // });
53
+ // return ts.factory.createVariableStatement(
54
+ // undefined,
55
+ // ts.factory.createVariableDeclarationList(
56
+ // [
57
+ // ts.factory.createVariableDeclaration(
58
+ // stmt.name,
59
+ // undefined,
60
+ // typeNode,
61
+ // undefined,
62
+ // ),
63
+ // ],
64
+ // stmt.mutability === "const" ? ts.NodeFlags.Constant : ts.NodeFlags.Let,
65
+ // ),
66
+ // );
67
+ // };
68
+
69
+ export const ifStatement = (
70
+ ctx: IAutoBeTestProgrammerContext,
71
+ stmt: AutoBeTest.IIfStatement,
72
+ ): ts.IfStatement =>
73
+ ts.factory.createIfStatement(
74
+ writeTestExpression(ctx, stmt.condition),
75
+ block(ctx, stmt.thenStatement),
76
+ stmt.elseStatement
77
+ ? stmt.elseStatement.type === "ifStatement"
78
+ ? ifStatement(ctx, stmt.elseStatement)
79
+ : block(ctx, stmt.elseStatement)
80
+ : undefined,
81
+ );
82
+
83
+ export const returnStatement = (
84
+ ctx: IAutoBeTestProgrammerContext,
85
+ stmt: AutoBeTest.IReturnStatement,
86
+ ): ts.ReturnStatement =>
87
+ ts.factory.createReturnStatement(writeTestExpression(ctx, stmt.expression));
88
+
89
+ export const throwStatement = (
90
+ ctx: IAutoBeTestProgrammerContext,
91
+ stmt: AutoBeTest.IThrowStatement,
92
+ ): ts.ThrowStatement =>
93
+ ts.factory.createThrowStatement(writeTestExpression(ctx, stmt.expression));
94
+
95
+ export const apiOperateStatement = (
96
+ ctx: IAutoBeTestProgrammerContext,
97
+ stmt: AutoBeTest.IApiOperateStatement,
98
+ ): ts.Statement[] => {
99
+ // find the function
100
+ const func: IAutoBeTestApiFunction = ctx.endpoints.get(stmt.endpoint);
101
+ if (!!stmt.variableName?.length && !!func.operation.responseBody)
102
+ ctx.importer.dto(func.operation.responseBody.typeName);
103
+
104
+ // make await function call expression
105
+ const initializer: ts.AwaitExpression = ts.factory.createAwaitExpression(
106
+ ts.factory.createCallExpression(
107
+ ts.factory.createIdentifier(func.accessor),
108
+ [],
109
+ [
110
+ ts.factory.createIdentifier("connection"),
111
+ ...(stmt.argument ? [writeTestExpression(ctx, stmt.argument)] : []),
112
+ ],
113
+ ),
114
+ );
115
+ if (stmt.variableName === null || stmt.variableName === undefined)
116
+ return [ts.factory.createExpressionStatement(initializer)];
117
+
118
+ const variable: ts.VariableStatement = ts.factory.createVariableStatement(
119
+ undefined,
120
+ ts.factory.createVariableDeclarationList(
121
+ [
122
+ ts.factory.createVariableDeclaration(
123
+ stmt.variableName,
124
+ undefined,
125
+ !!func.operation.responseBody
126
+ ? ts.factory.createTypeReferenceNode(
127
+ func.operation.responseBody.typeName,
128
+ )
129
+ : ts.factory.createKeywordTypeNode(
130
+ ts.SyntaxKind.UndefinedKeyword,
131
+ ),
132
+ initializer,
133
+ ),
134
+ ],
135
+ ts.NodeFlags.Const,
136
+ ),
137
+ );
138
+ const assertion = ts.factory.createCallExpression(
139
+ ts.factory.createPropertyAccessExpression(
140
+ ts.factory.createIdentifier(
141
+ ctx.importer.external({
142
+ type: "default",
143
+ library: "typia",
144
+ name: "typia",
145
+ }),
146
+ ),
147
+ "assert",
148
+ ),
149
+ undefined,
150
+ [ts.factory.createIdentifier(stmt.variableName)],
151
+ );
152
+ return [variable, ts.factory.createExpressionStatement(assertion)];
153
+ };
154
+ }
@@ -1,6 +1,6 @@
1
- import { AutoBeOpenApi } from "@autobe/interface";
2
-
3
- export interface IAutoBeTestApiFunction {
4
- operation: AutoBeOpenApi.IOperation;
5
- accessor: string;
6
- }
1
+ import { AutoBeOpenApi } from "@autobe/interface";
2
+
3
+ export interface IAutoBeTestApiFunction {
4
+ operation: AutoBeOpenApi.IOperation;
5
+ accessor: string;
6
+ }
@@ -1,11 +1,11 @@
1
- import { AutoBeOpenApi } from "@autobe/interface";
2
- import { NestiaMigrateImportProgrammer } from "@nestia/migrate";
3
- import { HashMap } from "tstl";
4
-
5
- import { IAutoBeTestApiFunction } from "./IAutoBeTestApiFunction";
6
-
7
- export interface IAutoBeTestProgrammerContext {
8
- importer: NestiaMigrateImportProgrammer;
9
- document: AutoBeOpenApi.IDocument;
10
- endpoints: HashMap<AutoBeOpenApi.IEndpoint, IAutoBeTestApiFunction>;
11
- }
1
+ import { AutoBeOpenApi } from "@autobe/interface";
2
+ import { NestiaMigrateImportProgrammer } from "@nestia/migrate";
3
+ import { HashMap } from "tstl";
4
+
5
+ import { IAutoBeTestApiFunction } from "./IAutoBeTestApiFunction";
6
+
7
+ export interface IAutoBeTestProgrammerContext {
8
+ importer: NestiaMigrateImportProgrammer;
9
+ document: AutoBeOpenApi.IDocument;
10
+ endpoints: HashMap<AutoBeOpenApi.IEndpoint, IAutoBeTestApiFunction>;
11
+ }
@@ -1,29 +1,29 @@
1
- import { AutoBeTest } from "@autobe/interface";
2
- import ts from "typescript";
3
-
4
- import { AutoBeTestAccessorProgrammer } from "./AutoBeTestAccessorProgrammer";
5
- import { AutoBeTestFunctionalProgrammer } from "./AutoBeTestFunctionalProgrammer";
6
- import { AutoBeTestLiteralProgrammer } from "./AutoBeTestLiteralProgrammer";
7
- import { AutoBeTestOperatorProgrammer } from "./AutoBeTestOperatorProgrammer";
8
- import { AutoBeTestPredicateProgrammer } from "./AutoBeTestPredicateProgrammer";
9
- import { AutoBeTestRandomProgrammer } from "./AutoBeTestRandomProgrammer";
10
- import { IAutoBeTestProgrammerContext } from "./IAutoBeTestProgrammerContext";
11
-
12
- export const writeTestExpression = (
13
- ctx: IAutoBeTestProgrammerContext,
14
- expr: AutoBeTest.IExpression,
15
- ): ts.Expression =>
16
- factory[expr.type](
17
- ctx,
18
- // biome-ignore lint: intended
19
- expr as any,
20
- );
21
-
22
- const factory = {
23
- ...AutoBeTestLiteralProgrammer,
24
- ...AutoBeTestOperatorProgrammer,
25
- ...AutoBeTestAccessorProgrammer,
26
- ...AutoBeTestFunctionalProgrammer,
27
- ...AutoBeTestRandomProgrammer,
28
- ...AutoBeTestPredicateProgrammer,
29
- };
1
+ import { AutoBeTest } from "@autobe/interface";
2
+ import ts from "typescript";
3
+
4
+ import { AutoBeTestAccessorProgrammer } from "./AutoBeTestAccessorProgrammer";
5
+ import { AutoBeTestFunctionalProgrammer } from "./AutoBeTestFunctionalProgrammer";
6
+ import { AutoBeTestLiteralProgrammer } from "./AutoBeTestLiteralProgrammer";
7
+ import { AutoBeTestOperatorProgrammer } from "./AutoBeTestOperatorProgrammer";
8
+ import { AutoBeTestPredicateProgrammer } from "./AutoBeTestPredicateProgrammer";
9
+ import { AutoBeTestRandomProgrammer } from "./AutoBeTestRandomProgrammer";
10
+ import { IAutoBeTestProgrammerContext } from "./IAutoBeTestProgrammerContext";
11
+
12
+ export const writeTestExpression = (
13
+ ctx: IAutoBeTestProgrammerContext,
14
+ expr: AutoBeTest.IExpression,
15
+ ): ts.Expression =>
16
+ factory[expr.type](
17
+ ctx,
18
+ // biome-ignore lint: intended
19
+ expr as any,
20
+ );
21
+
22
+ const factory = {
23
+ ...AutoBeTestLiteralProgrammer,
24
+ ...AutoBeTestOperatorProgrammer,
25
+ ...AutoBeTestAccessorProgrammer,
26
+ ...AutoBeTestFunctionalProgrammer,
27
+ ...AutoBeTestRandomProgrammer,
28
+ ...AutoBeTestPredicateProgrammer,
29
+ };
@@ -1,103 +1,103 @@
1
- import { AutoBeOpenApi, IAutoBeTestWriteProps } from "@autobe/interface";
2
- import {
3
- AutoBeOpenApiEndpointComparator,
4
- transformOpenApiDocument,
5
- } from "@autobe/utils";
6
- import { NestiaMigrateImportProgrammer } from "@nestia/migrate";
7
- import { IHttpMigrateApplication } from "@typia/interface";
8
- import { HttpMigration } from "@typia/utils";
9
- import { HashMap, Pair } from "tstl";
10
- import ts, { FunctionDeclaration } from "typescript";
11
-
12
- import { FilePrinter } from "../../utils/FilePrinter";
13
- import { AutoBeTestStatementProgrammer } from "./AutoBeTestStatementProgrammer";
14
- import { IAutoBeTestApiFunction } from "./IAutoBeTestApiFunction";
15
- import { IAutoBeTestProgrammerContext } from "./IAutoBeTestProgrammerContext";
16
-
17
- export function writeTestFunction(props: IAutoBeTestWriteProps): string {
18
- const ctx: IAutoBeTestProgrammerContext = {
19
- importer: new NestiaMigrateImportProgrammer(),
20
- document: props.document,
21
- endpoints: associate(props.document),
22
- };
23
- const decla: FunctionDeclaration = ts.factory.createFunctionDeclaration(
24
- [
25
- ts.factory.createModifier(ts.SyntaxKind.ExportKeyword),
26
- ts.factory.createModifier(ts.SyntaxKind.AsyncKeyword),
27
- ],
28
- undefined,
29
- props.scenario.functionName,
30
- undefined,
31
- [
32
- ts.factory.createParameterDeclaration(
33
- undefined,
34
- undefined,
35
- "connection",
36
- undefined,
37
- ts.factory.createTypeReferenceNode(
38
- `${ctx.importer.external({
39
- type: "default",
40
- name: "api",
41
- library: `@ORGANIZATION/PROJECT-api`,
42
- })}.IConnection`,
43
- ),
44
- ),
45
- ],
46
- undefined,
47
- AutoBeTestStatementProgrammer.block(ctx, {
48
- type: "block",
49
- statements: props.function.statements,
50
- }),
51
- );
52
- return FilePrinter.write({
53
- statements: [
54
- ...ctx.importer.toStatements(
55
- (key) => `@ORGANIZATION/PROJECT-api/lib/structures/${key}`,
56
- ),
57
- FilePrinter.newLine(),
58
- FilePrinter.description(decla, props.scenario.draft),
59
- ],
60
- });
61
- }
62
-
63
- function associate(
64
- document: AutoBeOpenApi.IDocument,
65
- ): HashMap<AutoBeOpenApi.IEndpoint, IAutoBeTestApiFunction> {
66
- // associate operations and functions
67
- const operations: HashMap<AutoBeOpenApi.IEndpoint, AutoBeOpenApi.IOperation> =
68
- new HashMap(
69
- document.operations.map(
70
- (o) =>
71
- new Pair(
72
- {
73
- method: o.method,
74
- path: o.path,
75
- },
76
- o,
77
- ),
78
- ),
79
- AutoBeOpenApiEndpointComparator.hashCode,
80
- AutoBeOpenApiEndpointComparator.equals,
81
- );
82
- const functions: HashMap<AutoBeOpenApi.IEndpoint, IAutoBeTestApiFunction> =
83
- new HashMap(
84
- AutoBeOpenApiEndpointComparator.hashCode,
85
- AutoBeOpenApiEndpointComparator.equals,
86
- );
87
-
88
- // from migrate application
89
- const migrate: IHttpMigrateApplication = HttpMigration.application(
90
- transformOpenApiDocument(document),
91
- );
92
- for (const route of migrate.routes) {
93
- const endpoint: AutoBeOpenApi.IEndpoint = {
94
- path: route.path,
95
- method: route.method as "get",
96
- };
97
- functions.emplace(endpoint, {
98
- accessor: "api.functional." + route.accessor.join("."),
99
- operation: operations.get(endpoint),
100
- });
101
- }
102
- return functions;
103
- }
1
+ import { AutoBeOpenApi, IAutoBeTestWriteProps } from "@autobe/interface";
2
+ import {
3
+ AutoBeOpenApiEndpointComparator,
4
+ transformOpenApiDocument,
5
+ } from "@autobe/utils";
6
+ import { NestiaMigrateImportProgrammer } from "@nestia/migrate";
7
+ import { IHttpMigrateApplication } from "@typia/interface";
8
+ import { HttpMigration } from "@typia/utils";
9
+ import { HashMap, Pair } from "tstl";
10
+ import ts, { FunctionDeclaration } from "typescript";
11
+
12
+ import { FilePrinter } from "../../utils/FilePrinter";
13
+ import { AutoBeTestStatementProgrammer } from "./AutoBeTestStatementProgrammer";
14
+ import { IAutoBeTestApiFunction } from "./IAutoBeTestApiFunction";
15
+ import { IAutoBeTestProgrammerContext } from "./IAutoBeTestProgrammerContext";
16
+
17
+ export function writeTestFunction(props: IAutoBeTestWriteProps): string {
18
+ const ctx: IAutoBeTestProgrammerContext = {
19
+ importer: new NestiaMigrateImportProgrammer(),
20
+ document: props.document,
21
+ endpoints: associate(props.document),
22
+ };
23
+ const decla: FunctionDeclaration = ts.factory.createFunctionDeclaration(
24
+ [
25
+ ts.factory.createModifier(ts.SyntaxKind.ExportKeyword),
26
+ ts.factory.createModifier(ts.SyntaxKind.AsyncKeyword),
27
+ ],
28
+ undefined,
29
+ props.scenario.functionName,
30
+ undefined,
31
+ [
32
+ ts.factory.createParameterDeclaration(
33
+ undefined,
34
+ undefined,
35
+ "connection",
36
+ undefined,
37
+ ts.factory.createTypeReferenceNode(
38
+ `${ctx.importer.external({
39
+ type: "default",
40
+ name: "api",
41
+ library: `@ORGANIZATION/PROJECT-api`,
42
+ })}.IConnection`,
43
+ ),
44
+ ),
45
+ ],
46
+ undefined,
47
+ AutoBeTestStatementProgrammer.block(ctx, {
48
+ type: "block",
49
+ statements: props.function.statements,
50
+ }),
51
+ );
52
+ return FilePrinter.write({
53
+ statements: [
54
+ ...ctx.importer.toStatements(
55
+ (key) => `@ORGANIZATION/PROJECT-api/lib/structures/${key}`,
56
+ ),
57
+ FilePrinter.newLine(),
58
+ FilePrinter.description(decla, props.scenario.draft),
59
+ ],
60
+ });
61
+ }
62
+
63
+ function associate(
64
+ document: AutoBeOpenApi.IDocument,
65
+ ): HashMap<AutoBeOpenApi.IEndpoint, IAutoBeTestApiFunction> {
66
+ // associate operations and functions
67
+ const operations: HashMap<AutoBeOpenApi.IEndpoint, AutoBeOpenApi.IOperation> =
68
+ new HashMap(
69
+ document.operations.map(
70
+ (o) =>
71
+ new Pair(
72
+ {
73
+ method: o.method,
74
+ path: o.path,
75
+ },
76
+ o,
77
+ ),
78
+ ),
79
+ AutoBeOpenApiEndpointComparator.hashCode,
80
+ AutoBeOpenApiEndpointComparator.equals,
81
+ );
82
+ const functions: HashMap<AutoBeOpenApi.IEndpoint, IAutoBeTestApiFunction> =
83
+ new HashMap(
84
+ AutoBeOpenApiEndpointComparator.hashCode,
85
+ AutoBeOpenApiEndpointComparator.equals,
86
+ );
87
+
88
+ // from migrate application
89
+ const migrate: IHttpMigrateApplication = HttpMigration.application(
90
+ transformOpenApiDocument(document),
91
+ );
92
+ for (const route of migrate.routes) {
93
+ const endpoint: AutoBeOpenApi.IEndpoint = {
94
+ path: route.path,
95
+ method: route.method as "get",
96
+ };
97
+ functions.emplace(endpoint, {
98
+ accessor: "api.functional." + route.accessor.join("."),
99
+ operation: operations.get(endpoint),
100
+ });
101
+ }
102
+ return functions;
103
+ }
@@ -1,19 +1,19 @@
1
- import { AutoBeTest } from "@autobe/interface";
2
- import ts from "typescript";
3
-
4
- import { AutoBeTestStatementProgrammer } from "./AutoBeTestStatementProgrammer";
5
- import { IAutoBeTestProgrammerContext } from "./IAutoBeTestProgrammerContext";
6
-
7
- export const writeTestStatement = (
8
- ctx: IAutoBeTestProgrammerContext,
9
- stmt: AutoBeTest.IStatement,
10
- ): ts.Statement[] => {
11
- const next: ts.Statement | ts.Statement[] = AutoBeTestStatementProgrammer[
12
- stmt.type
13
- ](
14
- ctx,
15
- // biome-ignore lint: intended
16
- stmt as any,
17
- );
18
- return Array.isArray(next) ? next : [next];
19
- };
1
+ import { AutoBeTest } from "@autobe/interface";
2
+ import ts from "typescript";
3
+
4
+ import { AutoBeTestStatementProgrammer } from "./AutoBeTestStatementProgrammer";
5
+ import { IAutoBeTestProgrammerContext } from "./IAutoBeTestProgrammerContext";
6
+
7
+ export const writeTestStatement = (
8
+ ctx: IAutoBeTestProgrammerContext,
9
+ stmt: AutoBeTest.IStatement,
10
+ ): ts.Statement[] => {
11
+ const next: ts.Statement | ts.Statement[] = AutoBeTestStatementProgrammer[
12
+ stmt.type
13
+ ](
14
+ ctx,
15
+ // biome-ignore lint: intended
16
+ stmt as any,
17
+ );
18
+ return Array.isArray(next) ? next : [next];
19
+ };