@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
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@autobe/compiler",
|
|
3
|
-
"version": "0.30.0
|
|
3
|
+
"version": "0.30.0",
|
|
4
4
|
"description": "AI backend server code generator",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"author": "Wrtn Technologies",
|
|
@@ -32,9 +32,9 @@
|
|
|
32
32
|
"tstl": "^3.0.0",
|
|
33
33
|
"typescript-transform-paths": "^3.5.5",
|
|
34
34
|
"typia": "^12.0.1",
|
|
35
|
-
"@autobe/
|
|
36
|
-
"@autobe/
|
|
37
|
-
"@autobe/
|
|
35
|
+
"@autobe/filesystem": "^0.30.0",
|
|
36
|
+
"@autobe/interface": "^0.30.0",
|
|
37
|
+
"@autobe/utils": "^0.30.0"
|
|
38
38
|
},
|
|
39
39
|
"devDependencies": {
|
|
40
40
|
"@types/node": "^22.15.3",
|
package/src/AutoBeCompiler.ts
CHANGED
|
@@ -1,93 +1,93 @@
|
|
|
1
|
-
import {
|
|
2
|
-
AutoBePhase,
|
|
3
|
-
IAutoBeCompiler,
|
|
4
|
-
IAutoBeCompilerListener,
|
|
5
|
-
IAutoBeDatabaseCompiler,
|
|
6
|
-
IAutoBeGetFilesOptions,
|
|
7
|
-
IAutoBeInterfaceCompiler,
|
|
8
|
-
IAutoBeRealizeCompiler,
|
|
9
|
-
IAutoBeTestCompiler,
|
|
10
|
-
IAutoBeTypeScriptCompiler,
|
|
11
|
-
} from "@autobe/interface";
|
|
12
|
-
|
|
13
|
-
import { AutoBeTypeScriptCompiler } from "./AutoBeTypeScriptCompiler";
|
|
14
|
-
import { AutoBeDatabaseCompiler } from "./database/AutoBeDatabaseCompiler";
|
|
15
|
-
import { AutoBeInterfaceCompiler } from "./interface/AutoBeInterfaceCompiler";
|
|
16
|
-
import { AutoBeCompilerCommonTemplate } from "./raw/AutoBeCompilerCommonTemplate";
|
|
17
|
-
import { AutoBeCompilerInterfaceTemplate } from "./raw/AutoBeCompilerInterfaceTemplate";
|
|
18
|
-
import { AutoBeCompilerRealizeTemplate } from "./raw/AutoBeCompilerRealizeTemplate";
|
|
19
|
-
import { AutoBeCompilerRealizeTemplateOfPostgres } from "./raw/AutoBeCompilerRealizeTemplateOfPostgres";
|
|
20
|
-
import { AutoBeCompilerRealizeTemplateOfSQLite } from "./raw/AutoBeCompilerRealizeTemplateOfSQLite";
|
|
21
|
-
import { AutoBeCompilerTestTemplate } from "./raw/AutoBeCompilerTestTemplate";
|
|
22
|
-
import { AutoBeRealizeCompiler } from "./realize/AutoBeRealizeCompiler";
|
|
23
|
-
import { AutoBeTestCompiler } from "./test/AutoBeTestCompiler";
|
|
24
|
-
|
|
25
|
-
/**
|
|
26
|
-
* Comprehensive compilation infrastructure for the vibe coding pipeline.
|
|
27
|
-
*
|
|
28
|
-
* This class provides the three-tier compiler system that transforms AST
|
|
29
|
-
* structures into production-ready code across all development phases. The
|
|
30
|
-
* AutoBeCompiler integrates the custom Prisma compiler, Interface compiler, and
|
|
31
|
-
* official TypeScript compiler into a unified compilation infrastructure.
|
|
32
|
-
*
|
|
33
|
-
* The compilation system ensures 100% syntactic correctness and semantic
|
|
34
|
-
* integrity throughout the automated development workflow by operating on
|
|
35
|
-
* validated AST data and providing continuous validation feedback loops. This
|
|
36
|
-
* enables the revolutionary "structure first, validate continuously, generate
|
|
37
|
-
* deterministically" approach that guarantees generated applications work
|
|
38
|
-
* correctly on the first attempt.
|
|
39
|
-
*
|
|
40
|
-
* For high-performance scenarios with multiple concurrent users, individual
|
|
41
|
-
* compiler components can be separated into dedicated worker processes to
|
|
42
|
-
* prevent blocking during computationally intensive compilation operations
|
|
43
|
-
* while maintaining the same interface compatibility.
|
|
44
|
-
*
|
|
45
|
-
* @author Samchon
|
|
46
|
-
*/
|
|
47
|
-
export class AutoBeCompiler implements IAutoBeCompiler {
|
|
48
|
-
public database: IAutoBeDatabaseCompiler;
|
|
49
|
-
public interface: IAutoBeInterfaceCompiler;
|
|
50
|
-
public typescript: IAutoBeTypeScriptCompiler;
|
|
51
|
-
public test: IAutoBeTestCompiler;
|
|
52
|
-
public realize: IAutoBeRealizeCompiler;
|
|
53
|
-
|
|
54
|
-
public constructor(private readonly listener: IAutoBeCompilerListener) {
|
|
55
|
-
this.database = new AutoBeDatabaseCompiler();
|
|
56
|
-
this.interface = new AutoBeInterfaceCompiler();
|
|
57
|
-
this.typescript = new AutoBeTypeScriptCompiler();
|
|
58
|
-
this.test = new AutoBeTestCompiler();
|
|
59
|
-
this.realize = new AutoBeRealizeCompiler(this.listener.realize);
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
public async getTemplate(
|
|
63
|
-
options: Required<IAutoBeGetFilesOptions>,
|
|
64
|
-
): Promise<Record<string, string>> {
|
|
65
|
-
const result: Record<string, string> = {
|
|
66
|
-
...AutoBeCompilerCommonTemplate,
|
|
67
|
-
};
|
|
68
|
-
const index: number = PHASES.indexOf(options.phase);
|
|
69
|
-
if (index >= OF_INTERFACE)
|
|
70
|
-
Object.assign(result, AutoBeCompilerInterfaceTemplate);
|
|
71
|
-
if (index >= OF_TEST) Object.assign(result, AutoBeCompilerTestTemplate);
|
|
72
|
-
if (index >= OF_REALIZE)
|
|
73
|
-
Object.assign(
|
|
74
|
-
result,
|
|
75
|
-
AutoBeCompilerRealizeTemplate,
|
|
76
|
-
options.dbms === "postgres"
|
|
77
|
-
? AutoBeCompilerRealizeTemplateOfPostgres
|
|
78
|
-
: AutoBeCompilerRealizeTemplateOfSQLite,
|
|
79
|
-
);
|
|
80
|
-
return result;
|
|
81
|
-
}
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
const PHASES: AutoBePhase[] = [
|
|
85
|
-
"analyze",
|
|
86
|
-
"database",
|
|
87
|
-
"interface",
|
|
88
|
-
"test",
|
|
89
|
-
"realize",
|
|
90
|
-
];
|
|
91
|
-
const OF_INTERFACE: number = PHASES.indexOf("interface");
|
|
92
|
-
const OF_TEST: number = PHASES.indexOf("test");
|
|
93
|
-
const OF_REALIZE: number = PHASES.indexOf("realize");
|
|
1
|
+
import {
|
|
2
|
+
AutoBePhase,
|
|
3
|
+
IAutoBeCompiler,
|
|
4
|
+
IAutoBeCompilerListener,
|
|
5
|
+
IAutoBeDatabaseCompiler,
|
|
6
|
+
IAutoBeGetFilesOptions,
|
|
7
|
+
IAutoBeInterfaceCompiler,
|
|
8
|
+
IAutoBeRealizeCompiler,
|
|
9
|
+
IAutoBeTestCompiler,
|
|
10
|
+
IAutoBeTypeScriptCompiler,
|
|
11
|
+
} from "@autobe/interface";
|
|
12
|
+
|
|
13
|
+
import { AutoBeTypeScriptCompiler } from "./AutoBeTypeScriptCompiler";
|
|
14
|
+
import { AutoBeDatabaseCompiler } from "./database/AutoBeDatabaseCompiler";
|
|
15
|
+
import { AutoBeInterfaceCompiler } from "./interface/AutoBeInterfaceCompiler";
|
|
16
|
+
import { AutoBeCompilerCommonTemplate } from "./raw/AutoBeCompilerCommonTemplate";
|
|
17
|
+
import { AutoBeCompilerInterfaceTemplate } from "./raw/AutoBeCompilerInterfaceTemplate";
|
|
18
|
+
import { AutoBeCompilerRealizeTemplate } from "./raw/AutoBeCompilerRealizeTemplate";
|
|
19
|
+
import { AutoBeCompilerRealizeTemplateOfPostgres } from "./raw/AutoBeCompilerRealizeTemplateOfPostgres";
|
|
20
|
+
import { AutoBeCompilerRealizeTemplateOfSQLite } from "./raw/AutoBeCompilerRealizeTemplateOfSQLite";
|
|
21
|
+
import { AutoBeCompilerTestTemplate } from "./raw/AutoBeCompilerTestTemplate";
|
|
22
|
+
import { AutoBeRealizeCompiler } from "./realize/AutoBeRealizeCompiler";
|
|
23
|
+
import { AutoBeTestCompiler } from "./test/AutoBeTestCompiler";
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* Comprehensive compilation infrastructure for the vibe coding pipeline.
|
|
27
|
+
*
|
|
28
|
+
* This class provides the three-tier compiler system that transforms AST
|
|
29
|
+
* structures into production-ready code across all development phases. The
|
|
30
|
+
* AutoBeCompiler integrates the custom Prisma compiler, Interface compiler, and
|
|
31
|
+
* official TypeScript compiler into a unified compilation infrastructure.
|
|
32
|
+
*
|
|
33
|
+
* The compilation system ensures 100% syntactic correctness and semantic
|
|
34
|
+
* integrity throughout the automated development workflow by operating on
|
|
35
|
+
* validated AST data and providing continuous validation feedback loops. This
|
|
36
|
+
* enables the revolutionary "structure first, validate continuously, generate
|
|
37
|
+
* deterministically" approach that guarantees generated applications work
|
|
38
|
+
* correctly on the first attempt.
|
|
39
|
+
*
|
|
40
|
+
* For high-performance scenarios with multiple concurrent users, individual
|
|
41
|
+
* compiler components can be separated into dedicated worker processes to
|
|
42
|
+
* prevent blocking during computationally intensive compilation operations
|
|
43
|
+
* while maintaining the same interface compatibility.
|
|
44
|
+
*
|
|
45
|
+
* @author Samchon
|
|
46
|
+
*/
|
|
47
|
+
export class AutoBeCompiler implements IAutoBeCompiler {
|
|
48
|
+
public database: IAutoBeDatabaseCompiler;
|
|
49
|
+
public interface: IAutoBeInterfaceCompiler;
|
|
50
|
+
public typescript: IAutoBeTypeScriptCompiler;
|
|
51
|
+
public test: IAutoBeTestCompiler;
|
|
52
|
+
public realize: IAutoBeRealizeCompiler;
|
|
53
|
+
|
|
54
|
+
public constructor(private readonly listener: IAutoBeCompilerListener) {
|
|
55
|
+
this.database = new AutoBeDatabaseCompiler();
|
|
56
|
+
this.interface = new AutoBeInterfaceCompiler();
|
|
57
|
+
this.typescript = new AutoBeTypeScriptCompiler();
|
|
58
|
+
this.test = new AutoBeTestCompiler();
|
|
59
|
+
this.realize = new AutoBeRealizeCompiler(this.listener.realize);
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
public async getTemplate(
|
|
63
|
+
options: Required<IAutoBeGetFilesOptions>,
|
|
64
|
+
): Promise<Record<string, string>> {
|
|
65
|
+
const result: Record<string, string> = {
|
|
66
|
+
...AutoBeCompilerCommonTemplate,
|
|
67
|
+
};
|
|
68
|
+
const index: number = PHASES.indexOf(options.phase);
|
|
69
|
+
if (index >= OF_INTERFACE)
|
|
70
|
+
Object.assign(result, AutoBeCompilerInterfaceTemplate);
|
|
71
|
+
if (index >= OF_TEST) Object.assign(result, AutoBeCompilerTestTemplate);
|
|
72
|
+
if (index >= OF_REALIZE)
|
|
73
|
+
Object.assign(
|
|
74
|
+
result,
|
|
75
|
+
AutoBeCompilerRealizeTemplate,
|
|
76
|
+
options.dbms === "postgres"
|
|
77
|
+
? AutoBeCompilerRealizeTemplateOfPostgres
|
|
78
|
+
: AutoBeCompilerRealizeTemplateOfSQLite,
|
|
79
|
+
);
|
|
80
|
+
return result;
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
const PHASES: AutoBePhase[] = [
|
|
85
|
+
"analyze",
|
|
86
|
+
"database",
|
|
87
|
+
"interface",
|
|
88
|
+
"test",
|
|
89
|
+
"realize",
|
|
90
|
+
];
|
|
91
|
+
const OF_INTERFACE: number = PHASES.indexOf("interface");
|
|
92
|
+
const OF_TEST: number = PHASES.indexOf("test");
|
|
93
|
+
const OF_REALIZE: number = PHASES.indexOf("realize");
|
|
@@ -1,136 +1,136 @@
|
|
|
1
|
-
import {
|
|
2
|
-
IAutoBeTypeScriptCompileProps,
|
|
3
|
-
IAutoBeTypeScriptCompileResult,
|
|
4
|
-
IAutoBeTypeScriptCompiler,
|
|
5
|
-
} from "@autobe/interface";
|
|
6
|
-
import nestiaCoreTransform from "@nestia/core/lib/transform";
|
|
7
|
-
import { EmbedEsLint } from "embed-eslint";
|
|
8
|
-
import { Pair } from "tstl";
|
|
9
|
-
// import { Pair } from "tstl";
|
|
10
|
-
import ts from "typescript";
|
|
11
|
-
import typiaTransform from "typia/lib/transform";
|
|
12
|
-
|
|
13
|
-
import NestJSExternal from "./raw/nestjs.json";
|
|
14
|
-
import { FilePrinter } from "./utils/FilePrinter";
|
|
15
|
-
import { shrinkCompileResult } from "./utils/shrinkCompileResult";
|
|
16
|
-
|
|
17
|
-
/**
|
|
18
|
-
* Official TypeScript compiler for final code validation and quality assurance.
|
|
19
|
-
*
|
|
20
|
-
* This compiler provides the ultimate validation layer that ensures all
|
|
21
|
-
* generated code meets production standards and integrates seamlessly with the
|
|
22
|
-
* TypeScript ecosystem. While the AST-based approach eliminates most potential
|
|
23
|
-
* errors before code generation, the AutoBeTypeScriptCompiler serves as the
|
|
24
|
-
* final quality gate for perfect integration verification throughout the vibe
|
|
25
|
-
* coding pipeline.
|
|
26
|
-
*
|
|
27
|
-
* The implementation validates framework integration with NestJS APIs, type
|
|
28
|
-
* system integrity for complex relationships, dependency resolution across
|
|
29
|
-
* modules, and build system compatibility with standard toolchains. It provides
|
|
30
|
-
* comprehensive IDE support including intelligent autocomplete, real-time error
|
|
31
|
-
* detection, sophisticated refactoring capabilities, and complete navigation
|
|
32
|
-
* features.
|
|
33
|
-
*
|
|
34
|
-
* The compiler enables critical feedback loops necessary for AI self-correction
|
|
35
|
-
* when implementation or test code contains compilation errors requiring
|
|
36
|
-
* iterative refinement. This ensures that generated applications are
|
|
37
|
-
* immediately deployable without manual debugging cycles while maintaining the
|
|
38
|
-
* reliability of the automated development process.
|
|
39
|
-
*
|
|
40
|
-
* @author Samchon
|
|
41
|
-
*/
|
|
42
|
-
export class AutoBeTypeScriptCompiler implements IAutoBeTypeScriptCompiler {
|
|
43
|
-
public async compile(
|
|
44
|
-
props: IAutoBeTypeScriptCompileProps,
|
|
45
|
-
): Promise<IAutoBeTypeScriptCompileResult> {
|
|
46
|
-
const alias: string = props.package ?? "@ORGANIZATION/PROJECT-api";
|
|
47
|
-
const compiler: EmbedEsLint = new EmbedEsLint({
|
|
48
|
-
external: NestJSExternal as Record<string, string>,
|
|
49
|
-
compilerOptions: {
|
|
50
|
-
target: ts.ScriptTarget.ESNext,
|
|
51
|
-
module: ts.ModuleKind.CommonJS,
|
|
52
|
-
downlevelIteration: true,
|
|
53
|
-
baseUrl: "./",
|
|
54
|
-
paths: {
|
|
55
|
-
[alias]: ["./src/api"],
|
|
56
|
-
[`${alias}/lib/*`]: ["./src/api/*"],
|
|
57
|
-
["@prisma/sdk"]: ["./src/prisma/client.ts"],
|
|
58
|
-
},
|
|
59
|
-
strict: true,
|
|
60
|
-
skipLibCheck: true,
|
|
61
|
-
esModuleInterop: true,
|
|
62
|
-
experimentalDecorators: true,
|
|
63
|
-
emitDecoratorMetadata: true,
|
|
64
|
-
noErrorTruncation: true,
|
|
65
|
-
},
|
|
66
|
-
transformers: (program, diagnostics) => ({
|
|
67
|
-
before: [
|
|
68
|
-
typiaTransform(
|
|
69
|
-
program,
|
|
70
|
-
{},
|
|
71
|
-
{
|
|
72
|
-
addDiagnostic: (input) => diagnostics.push(input),
|
|
73
|
-
},
|
|
74
|
-
),
|
|
75
|
-
nestiaCoreTransform(
|
|
76
|
-
program,
|
|
77
|
-
{},
|
|
78
|
-
{
|
|
79
|
-
addDiagnostic: (input) => diagnostics.push(input),
|
|
80
|
-
},
|
|
81
|
-
),
|
|
82
|
-
],
|
|
83
|
-
}),
|
|
84
|
-
rules: {
|
|
85
|
-
"no-floating-promises": "error",
|
|
86
|
-
},
|
|
87
|
-
});
|
|
88
|
-
return shrinkCompileResult(
|
|
89
|
-
compiler.compile({
|
|
90
|
-
...props.files,
|
|
91
|
-
...(props.prisma ?? {}),
|
|
92
|
-
}),
|
|
93
|
-
);
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
public async getExternal(location: string): Promise<string | undefined> {
|
|
97
|
-
return (NestJSExternal as Record<string, string>)[location] ?? undefined;
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
public beautify(script: string): Promise<string> {
|
|
101
|
-
return FilePrinter.beautify(script);
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
public async removeImportStatements(script: string): Promise<string> {
|
|
105
|
-
try {
|
|
106
|
-
const sourceFile: ts.SourceFile = ts.createSourceFile(
|
|
107
|
-
"module.ts",
|
|
108
|
-
script,
|
|
109
|
-
ts.ScriptTarget.ESNext,
|
|
110
|
-
true,
|
|
111
|
-
);
|
|
112
|
-
const statements: ts.Statement[] = sourceFile.statements.filter(
|
|
113
|
-
(stmt) => stmt.kind !== ts.SyntaxKind.ImportDeclaration,
|
|
114
|
-
);
|
|
115
|
-
const printer: ts.Printer = ts.createPrinter();
|
|
116
|
-
return statements
|
|
117
|
-
.map((stmt) =>
|
|
118
|
-
printer.printNode(ts.EmitHint.Unspecified, stmt, sourceFile),
|
|
119
|
-
)
|
|
120
|
-
.join("\n");
|
|
121
|
-
} catch {
|
|
122
|
-
script = await this.beautify(script);
|
|
123
|
-
const lines: string[] = script.replaceAll("\r\n", "\n").split("\n");
|
|
124
|
-
const indexes: Pair<number, number>[] = lines
|
|
125
|
-
.map((s, i) =>
|
|
126
|
-
s.startsWith("import ")
|
|
127
|
-
? new Pair(i, lines.slice(i).findIndex((s) => s.endsWith(";")) + i)
|
|
128
|
-
: null,
|
|
129
|
-
)
|
|
130
|
-
.filter((p) => p !== null);
|
|
131
|
-
for (const index of indexes.reverse())
|
|
132
|
-
lines.splice(index.first, index.second - index.first + 1);
|
|
133
|
-
return lines.join("\n");
|
|
134
|
-
}
|
|
135
|
-
}
|
|
136
|
-
}
|
|
1
|
+
import {
|
|
2
|
+
IAutoBeTypeScriptCompileProps,
|
|
3
|
+
IAutoBeTypeScriptCompileResult,
|
|
4
|
+
IAutoBeTypeScriptCompiler,
|
|
5
|
+
} from "@autobe/interface";
|
|
6
|
+
import nestiaCoreTransform from "@nestia/core/lib/transform";
|
|
7
|
+
import { EmbedEsLint } from "embed-eslint";
|
|
8
|
+
import { Pair } from "tstl";
|
|
9
|
+
// import { Pair } from "tstl";
|
|
10
|
+
import ts from "typescript";
|
|
11
|
+
import typiaTransform from "typia/lib/transform";
|
|
12
|
+
|
|
13
|
+
import NestJSExternal from "./raw/nestjs.json";
|
|
14
|
+
import { FilePrinter } from "./utils/FilePrinter";
|
|
15
|
+
import { shrinkCompileResult } from "./utils/shrinkCompileResult";
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Official TypeScript compiler for final code validation and quality assurance.
|
|
19
|
+
*
|
|
20
|
+
* This compiler provides the ultimate validation layer that ensures all
|
|
21
|
+
* generated code meets production standards and integrates seamlessly with the
|
|
22
|
+
* TypeScript ecosystem. While the AST-based approach eliminates most potential
|
|
23
|
+
* errors before code generation, the AutoBeTypeScriptCompiler serves as the
|
|
24
|
+
* final quality gate for perfect integration verification throughout the vibe
|
|
25
|
+
* coding pipeline.
|
|
26
|
+
*
|
|
27
|
+
* The implementation validates framework integration with NestJS APIs, type
|
|
28
|
+
* system integrity for complex relationships, dependency resolution across
|
|
29
|
+
* modules, and build system compatibility with standard toolchains. It provides
|
|
30
|
+
* comprehensive IDE support including intelligent autocomplete, real-time error
|
|
31
|
+
* detection, sophisticated refactoring capabilities, and complete navigation
|
|
32
|
+
* features.
|
|
33
|
+
*
|
|
34
|
+
* The compiler enables critical feedback loops necessary for AI self-correction
|
|
35
|
+
* when implementation or test code contains compilation errors requiring
|
|
36
|
+
* iterative refinement. This ensures that generated applications are
|
|
37
|
+
* immediately deployable without manual debugging cycles while maintaining the
|
|
38
|
+
* reliability of the automated development process.
|
|
39
|
+
*
|
|
40
|
+
* @author Samchon
|
|
41
|
+
*/
|
|
42
|
+
export class AutoBeTypeScriptCompiler implements IAutoBeTypeScriptCompiler {
|
|
43
|
+
public async compile(
|
|
44
|
+
props: IAutoBeTypeScriptCompileProps,
|
|
45
|
+
): Promise<IAutoBeTypeScriptCompileResult> {
|
|
46
|
+
const alias: string = props.package ?? "@ORGANIZATION/PROJECT-api";
|
|
47
|
+
const compiler: EmbedEsLint = new EmbedEsLint({
|
|
48
|
+
external: NestJSExternal as Record<string, string>,
|
|
49
|
+
compilerOptions: {
|
|
50
|
+
target: ts.ScriptTarget.ESNext,
|
|
51
|
+
module: ts.ModuleKind.CommonJS,
|
|
52
|
+
downlevelIteration: true,
|
|
53
|
+
baseUrl: "./",
|
|
54
|
+
paths: {
|
|
55
|
+
[alias]: ["./src/api"],
|
|
56
|
+
[`${alias}/lib/*`]: ["./src/api/*"],
|
|
57
|
+
["@prisma/sdk"]: ["./src/prisma/client.ts"],
|
|
58
|
+
},
|
|
59
|
+
strict: true,
|
|
60
|
+
skipLibCheck: true,
|
|
61
|
+
esModuleInterop: true,
|
|
62
|
+
experimentalDecorators: true,
|
|
63
|
+
emitDecoratorMetadata: true,
|
|
64
|
+
noErrorTruncation: true,
|
|
65
|
+
},
|
|
66
|
+
transformers: (program, diagnostics) => ({
|
|
67
|
+
before: [
|
|
68
|
+
typiaTransform(
|
|
69
|
+
program,
|
|
70
|
+
{},
|
|
71
|
+
{
|
|
72
|
+
addDiagnostic: (input) => diagnostics.push(input),
|
|
73
|
+
},
|
|
74
|
+
),
|
|
75
|
+
nestiaCoreTransform(
|
|
76
|
+
program,
|
|
77
|
+
{},
|
|
78
|
+
{
|
|
79
|
+
addDiagnostic: (input) => diagnostics.push(input),
|
|
80
|
+
},
|
|
81
|
+
),
|
|
82
|
+
],
|
|
83
|
+
}),
|
|
84
|
+
rules: {
|
|
85
|
+
"no-floating-promises": "error",
|
|
86
|
+
},
|
|
87
|
+
});
|
|
88
|
+
return shrinkCompileResult(
|
|
89
|
+
compiler.compile({
|
|
90
|
+
...props.files,
|
|
91
|
+
...(props.prisma ?? {}),
|
|
92
|
+
}),
|
|
93
|
+
);
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
public async getExternal(location: string): Promise<string | undefined> {
|
|
97
|
+
return (NestJSExternal as Record<string, string>)[location] ?? undefined;
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
public beautify(script: string): Promise<string> {
|
|
101
|
+
return FilePrinter.beautify(script);
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
public async removeImportStatements(script: string): Promise<string> {
|
|
105
|
+
try {
|
|
106
|
+
const sourceFile: ts.SourceFile = ts.createSourceFile(
|
|
107
|
+
"module.ts",
|
|
108
|
+
script,
|
|
109
|
+
ts.ScriptTarget.ESNext,
|
|
110
|
+
true,
|
|
111
|
+
);
|
|
112
|
+
const statements: ts.Statement[] = sourceFile.statements.filter(
|
|
113
|
+
(stmt) => stmt.kind !== ts.SyntaxKind.ImportDeclaration,
|
|
114
|
+
);
|
|
115
|
+
const printer: ts.Printer = ts.createPrinter();
|
|
116
|
+
return statements
|
|
117
|
+
.map((stmt) =>
|
|
118
|
+
printer.printNode(ts.EmitHint.Unspecified, stmt, sourceFile),
|
|
119
|
+
)
|
|
120
|
+
.join("\n");
|
|
121
|
+
} catch {
|
|
122
|
+
script = await this.beautify(script);
|
|
123
|
+
const lines: string[] = script.replaceAll("\r\n", "\n").split("\n");
|
|
124
|
+
const indexes: Pair<number, number>[] = lines
|
|
125
|
+
.map((s, i) =>
|
|
126
|
+
s.startsWith("import ")
|
|
127
|
+
? new Pair(i, lines.slice(i).findIndex((s) => s.endsWith(";")) + i)
|
|
128
|
+
: null,
|
|
129
|
+
)
|
|
130
|
+
.filter((p) => p !== null);
|
|
131
|
+
for (const index of indexes.reverse())
|
|
132
|
+
lines.splice(index.first, index.second - index.first + 1);
|
|
133
|
+
return lines.join("\n");
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
}
|
|
@@ -1,48 +1,48 @@
|
|
|
1
|
-
import {
|
|
2
|
-
AutoBeDatabase,
|
|
3
|
-
IAutoBeDatabaseCompiler,
|
|
4
|
-
IAutoBeDatabaseValidation,
|
|
5
|
-
IAutoBePrismaCompileResult,
|
|
6
|
-
IAutoBePrismaCompilerProps,
|
|
7
|
-
} from "@autobe/interface";
|
|
8
|
-
import { writePrismaApplication } from "@autobe/utils";
|
|
9
|
-
import { EmbedPrisma } from "embed-prisma";
|
|
10
|
-
|
|
11
|
-
import { validateDatabaseApplication } from "./validateDatabaseApplication";
|
|
12
|
-
|
|
13
|
-
export class AutoBeDatabaseCompiler implements IAutoBeDatabaseCompiler {
|
|
14
|
-
public async compilePrismaSchemas(
|
|
15
|
-
props: IAutoBePrismaCompilerProps,
|
|
16
|
-
): Promise<IAutoBePrismaCompileResult> {
|
|
17
|
-
const compiler: EmbedPrisma = new EmbedPrisma();
|
|
18
|
-
const result: IAutoBePrismaCompileResult = await compiler.compile(
|
|
19
|
-
props.files,
|
|
20
|
-
);
|
|
21
|
-
if (result.type !== "success") return result;
|
|
22
|
-
return {
|
|
23
|
-
...result,
|
|
24
|
-
client: Object.fromEntries(
|
|
25
|
-
Object.entries(result.client).map(([key, value]) => [
|
|
26
|
-
`src/prisma/${key}`,
|
|
27
|
-
value,
|
|
28
|
-
]),
|
|
29
|
-
),
|
|
30
|
-
};
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
public async writePrismaSchemas(
|
|
34
|
-
application: AutoBeDatabase.IApplication,
|
|
35
|
-
dbms: "postgres" | "sqlite" = "postgres",
|
|
36
|
-
): Promise<Record<string, string>> {
|
|
37
|
-
return writePrismaApplication({
|
|
38
|
-
application,
|
|
39
|
-
dbms,
|
|
40
|
-
});
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
public async validate(
|
|
44
|
-
application: AutoBeDatabase.IApplication,
|
|
45
|
-
): Promise<IAutoBeDatabaseValidation> {
|
|
46
|
-
return validateDatabaseApplication(application);
|
|
47
|
-
}
|
|
48
|
-
}
|
|
1
|
+
import {
|
|
2
|
+
AutoBeDatabase,
|
|
3
|
+
IAutoBeDatabaseCompiler,
|
|
4
|
+
IAutoBeDatabaseValidation,
|
|
5
|
+
IAutoBePrismaCompileResult,
|
|
6
|
+
IAutoBePrismaCompilerProps,
|
|
7
|
+
} from "@autobe/interface";
|
|
8
|
+
import { writePrismaApplication } from "@autobe/utils";
|
|
9
|
+
import { EmbedPrisma } from "embed-prisma";
|
|
10
|
+
|
|
11
|
+
import { validateDatabaseApplication } from "./validateDatabaseApplication";
|
|
12
|
+
|
|
13
|
+
export class AutoBeDatabaseCompiler implements IAutoBeDatabaseCompiler {
|
|
14
|
+
public async compilePrismaSchemas(
|
|
15
|
+
props: IAutoBePrismaCompilerProps,
|
|
16
|
+
): Promise<IAutoBePrismaCompileResult> {
|
|
17
|
+
const compiler: EmbedPrisma = new EmbedPrisma();
|
|
18
|
+
const result: IAutoBePrismaCompileResult = await compiler.compile(
|
|
19
|
+
props.files,
|
|
20
|
+
);
|
|
21
|
+
if (result.type !== "success") return result;
|
|
22
|
+
return {
|
|
23
|
+
...result,
|
|
24
|
+
client: Object.fromEntries(
|
|
25
|
+
Object.entries(result.client).map(([key, value]) => [
|
|
26
|
+
`src/prisma/${key}`,
|
|
27
|
+
value,
|
|
28
|
+
]),
|
|
29
|
+
),
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
public async writePrismaSchemas(
|
|
34
|
+
application: AutoBeDatabase.IApplication,
|
|
35
|
+
dbms: "postgres" | "sqlite" = "postgres",
|
|
36
|
+
): Promise<Record<string, string>> {
|
|
37
|
+
return writePrismaApplication({
|
|
38
|
+
application,
|
|
39
|
+
dbms,
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
public async validate(
|
|
44
|
+
application: AutoBeDatabase.IApplication,
|
|
45
|
+
): Promise<IAutoBeDatabaseValidation> {
|
|
46
|
+
return validateDatabaseApplication(application);
|
|
47
|
+
}
|
|
48
|
+
}
|