@autobe/compiler 0.8.0 → 0.9.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/AutoBeCompiler.d.ts +25 -5
- package/lib/AutoBeCompiler.js +24 -8
- package/lib/AutoBeCompiler.js.map +1 -1
- package/lib/AutoBeInterfaceCompiler.d.ts +26 -0
- package/lib/AutoBeInterfaceCompiler.js +81 -2
- package/lib/AutoBeInterfaceCompiler.js.map +1 -1
- package/lib/AutoBePrismaCompiler.d.ts +27 -2
- package/lib/AutoBePrismaCompiler.js +33 -5
- package/lib/AutoBePrismaCompiler.js.map +1 -1
- package/lib/AutoBeTypeScriptCompiler.d.ts +25 -0
- package/lib/AutoBeTypeScriptCompiler.js +26 -1
- package/lib/AutoBeTypeScriptCompiler.js.map +1 -1
- package/lib/prisma/writePrismaApplication.d.ts +4 -1
- package/lib/prisma/writePrismaApplication.js +93 -52
- package/lib/prisma/writePrismaApplication.js.map +1 -1
- package/package.json +2 -2
- package/src/AutoBeCompiler.ts +24 -17
- package/src/AutoBeInterfaceCompiler.ts +98 -5
- package/src/AutoBePrismaCompiler.ts +33 -4
- package/src/AutoBeTypeScriptCompiler.ts +26 -1
- package/src/prisma/writePrismaApplication.ts +133 -69
|
@@ -3,27 +3,33 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.writePrismaApplication = writePrismaApplication;
|
|
4
4
|
const ArrayUtil_1 = require("../utils/ArrayUtil");
|
|
5
5
|
const MapUtil_1 = require("../utils/MapUtil");
|
|
6
|
-
|
|
7
|
-
|
|
6
|
+
const StringUtil_1 = require("../utils/StringUtil");
|
|
7
|
+
function writePrismaApplication(props) {
|
|
8
|
+
for (const file of props.application.files)
|
|
8
9
|
for (const model of file.models)
|
|
9
10
|
fillMappingName(model);
|
|
10
|
-
return Object.assign(Object.assign({}, Object.fromEntries(
|
|
11
|
+
return Object.assign(Object.assign({}, Object.fromEntries(props.application.files
|
|
11
12
|
.filter((file) => file.filename !== "main.prisma")
|
|
12
|
-
.map((file) => [
|
|
13
|
+
.map((file) => [
|
|
14
|
+
file.filename,
|
|
15
|
+
writeFile(Object.assign(Object.assign({}, props), { file })),
|
|
16
|
+
]))), { "main.prisma": props.dbms === "postgres" ? POSTGRES_MAIN_FILE : SQLITE_MAIN_FILE });
|
|
13
17
|
}
|
|
14
|
-
function writeFile(
|
|
15
|
-
return file.models
|
|
18
|
+
function writeFile(props) {
|
|
19
|
+
return props.file.models
|
|
20
|
+
.map((model) => writeModel(Object.assign(Object.assign({}, props), { model })))
|
|
21
|
+
.join("\n\n");
|
|
16
22
|
}
|
|
17
|
-
function writeModel(
|
|
23
|
+
function writeModel(props) {
|
|
18
24
|
return [
|
|
19
25
|
writeComment([
|
|
20
|
-
model.description,
|
|
26
|
+
props.model.description,
|
|
21
27
|
"",
|
|
22
|
-
...(model.material ? [] : [`@namespace ${file.namespace}`]),
|
|
28
|
+
...(props.model.material ? [] : [`@namespace ${props.file.namespace}`]),
|
|
23
29
|
"@author AutoBE - https://github.com/wrtnlabs/autobe",
|
|
24
30
|
].join("\n")),
|
|
25
|
-
`model ${model.name} {`,
|
|
26
|
-
indent(ArrayUtil_1.ArrayUtil.paddle([writeColumns(
|
|
31
|
+
`model ${props.model.name} {`,
|
|
32
|
+
indent(ArrayUtil_1.ArrayUtil.paddle([writeColumns(props), writeRelations(props)]).join("\n")),
|
|
27
33
|
"}",
|
|
28
34
|
].join("\n");
|
|
29
35
|
}
|
|
@@ -43,30 +49,52 @@ function fillMappingName(model) {
|
|
|
43
49
|
/* -----------------------------------------------------------
|
|
44
50
|
COLUMNS
|
|
45
51
|
----------------------------------------------------------- */
|
|
46
|
-
function writeColumns(
|
|
52
|
+
function writeColumns(props) {
|
|
47
53
|
return [
|
|
48
54
|
"//----",
|
|
49
55
|
"// COLUMNS",
|
|
50
56
|
"//----",
|
|
51
|
-
writePrimary(
|
|
52
|
-
|
|
53
|
-
|
|
57
|
+
writePrimary({
|
|
58
|
+
dbms: props.dbms,
|
|
59
|
+
field: props.model.primaryField,
|
|
60
|
+
}),
|
|
61
|
+
...props.model.foreignFields
|
|
62
|
+
.map((x) => [
|
|
63
|
+
"",
|
|
64
|
+
writeField({
|
|
65
|
+
dbms: props.dbms,
|
|
66
|
+
field: x,
|
|
67
|
+
}),
|
|
68
|
+
])
|
|
69
|
+
.flat(),
|
|
70
|
+
...props.model.plainFields
|
|
71
|
+
.map((x) => [
|
|
72
|
+
"",
|
|
73
|
+
writeField({
|
|
74
|
+
dbms: props.dbms,
|
|
75
|
+
field: x,
|
|
76
|
+
}),
|
|
77
|
+
])
|
|
78
|
+
.flat(),
|
|
54
79
|
];
|
|
55
80
|
}
|
|
56
|
-
function writePrimary(
|
|
81
|
+
function writePrimary(props) {
|
|
82
|
+
const type = props.dbms === "postgres" ? POSTGRES_PHYSICAL_TYPES.uuid : undefined;
|
|
57
83
|
return [
|
|
58
|
-
writeComment(field.description),
|
|
59
|
-
`${field.name} String @id
|
|
84
|
+
writeComment(props.field.description),
|
|
85
|
+
`${props.field.name} String @id${type ? ` ${type}` : ""}`,
|
|
60
86
|
].join("\n");
|
|
61
87
|
}
|
|
62
|
-
function writeField(
|
|
63
|
-
const logical = LOGICAL_TYPES[field.type];
|
|
64
|
-
const physical =
|
|
88
|
+
function writeField(props) {
|
|
89
|
+
const logical = LOGICAL_TYPES[props.field.type];
|
|
90
|
+
const physical = props.dbms === "postgres"
|
|
91
|
+
? POSTGRES_PHYSICAL_TYPES[props.field.type]
|
|
92
|
+
: undefined;
|
|
65
93
|
return [
|
|
66
|
-
writeComment(field.description),
|
|
94
|
+
writeComment(props.field.description),
|
|
67
95
|
[
|
|
68
|
-
field.name,
|
|
69
|
-
`${logical}${field.nullable ? "?" : ""}`,
|
|
96
|
+
props.field.name,
|
|
97
|
+
`${logical}${props.field.nullable ? "?" : ""}`,
|
|
70
98
|
...(physical ? [physical] : []),
|
|
71
99
|
].join(" "),
|
|
72
100
|
].join("\n");
|
|
@@ -74,21 +102,21 @@ function writeField(field) {
|
|
|
74
102
|
/* -----------------------------------------------------------
|
|
75
103
|
RELATIONS
|
|
76
104
|
----------------------------------------------------------- */
|
|
77
|
-
function writeRelations(
|
|
78
|
-
const hasRelationships =
|
|
105
|
+
function writeRelations(props) {
|
|
106
|
+
const hasRelationships = props.application.files
|
|
79
107
|
.map((otherFile) => otherFile.models.map((otherModel) => otherModel.foreignFields
|
|
80
|
-
.filter((otherForeign) => otherForeign.relation.targetModel === model.name)
|
|
108
|
+
.filter((otherForeign) => otherForeign.relation.targetModel === props.model.name)
|
|
81
109
|
.map((otherForeign) => ({
|
|
82
110
|
modelName: otherModel.name,
|
|
83
111
|
unique: otherForeign.unique,
|
|
84
112
|
mappingName: otherForeign.relation.mappingName,
|
|
85
113
|
}))))
|
|
86
114
|
.flat(2);
|
|
87
|
-
const foreignIndexes = model.foreignFields.filter((f) => model.uniqueIndexes.every((u) => u.fieldNames[0] !== f.name) &&
|
|
115
|
+
const foreignIndexes = props.model.foreignFields.filter((f) => props.model.uniqueIndexes.every((u) => u.fieldNames[0] !== f.name) &&
|
|
88
116
|
(f.unique === true ||
|
|
89
|
-
model.plainIndexes.every((p) => p.fieldNames[0] !== f.name)));
|
|
117
|
+
props.model.plainIndexes.every((p) => p.fieldNames[0] !== f.name)));
|
|
90
118
|
const contents = [
|
|
91
|
-
model.foreignFields.map(writeConstraint),
|
|
119
|
+
props.model.foreignFields.map(writeConstraint),
|
|
92
120
|
hasRelationships.map((r) => {
|
|
93
121
|
var _a;
|
|
94
122
|
return [
|
|
@@ -99,9 +127,11 @@ function writeRelations(app, model) {
|
|
|
99
127
|
}),
|
|
100
128
|
foreignIndexes.map(writeForeignIndex),
|
|
101
129
|
[
|
|
102
|
-
...model.uniqueIndexes.map(writeUniqueIndex),
|
|
103
|
-
...model.plainIndexes.map(writePlainIndex),
|
|
104
|
-
...
|
|
130
|
+
...props.model.uniqueIndexes.map(writeUniqueIndex),
|
|
131
|
+
...props.model.plainIndexes.map(writePlainIndex),
|
|
132
|
+
...(props.dbms === "postgres"
|
|
133
|
+
? props.model.ginIndexes.map(writeGinIndex)
|
|
134
|
+
: []),
|
|
105
135
|
],
|
|
106
136
|
];
|
|
107
137
|
if (contents.every((c) => c.length === 0))
|
|
@@ -171,29 +201,40 @@ const LOGICAL_TYPES = {
|
|
|
171
201
|
uuid: "String",
|
|
172
202
|
uri: "String",
|
|
173
203
|
};
|
|
174
|
-
const
|
|
204
|
+
const POSTGRES_PHYSICAL_TYPES = {
|
|
175
205
|
int: "@db.Integer",
|
|
176
206
|
double: "@db.DoublePrecision",
|
|
177
207
|
uuid: "@db.Uuid",
|
|
178
208
|
datetime: "@db.Timestamptz",
|
|
179
209
|
uri: "@db.VarChar(80000)",
|
|
180
210
|
};
|
|
181
|
-
const
|
|
182
|
-
generator client {
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
}
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
211
|
+
const POSTGRES_MAIN_FILE = StringUtil_1.StringUtil.trim `
|
|
212
|
+
generator client {
|
|
213
|
+
provider = "prisma-client-js"
|
|
214
|
+
previewFeatures = ["postgresqlExtensions", "views"]
|
|
215
|
+
binaryTargets = ["native"]
|
|
216
|
+
}
|
|
217
|
+
datasource db {
|
|
218
|
+
provider = "postgresql"
|
|
219
|
+
url = env("DATABASE_URL")
|
|
220
|
+
extensions = []
|
|
221
|
+
}
|
|
222
|
+
generator markdown {
|
|
223
|
+
provider = "prisma-markdown"
|
|
224
|
+
output = "../docs/ERD.md"
|
|
225
|
+
}
|
|
226
|
+
`;
|
|
227
|
+
const SQLITE_MAIN_FILE = StringUtil_1.StringUtil.trim `
|
|
228
|
+
generator client {
|
|
229
|
+
provider = "prisma-client-js"
|
|
230
|
+
}
|
|
231
|
+
datasource db {
|
|
232
|
+
provider = "sqlite"
|
|
233
|
+
url = "file:./prisma.db"
|
|
234
|
+
}
|
|
235
|
+
generator markdown {
|
|
236
|
+
provider = "prisma-markdown"
|
|
237
|
+
output = "../docs/ERD.md"
|
|
238
|
+
}
|
|
239
|
+
`;
|
|
199
240
|
//# sourceMappingURL=writePrismaApplication.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"writePrismaApplication.js","sourceRoot":"","sources":["../../src/prisma/writePrismaApplication.ts"],"names":[],"mappings":";;
|
|
1
|
+
{"version":3,"file":"writePrismaApplication.js","sourceRoot":"","sources":["../../src/prisma/writePrismaApplication.ts"],"names":[],"mappings":";;AAMA,wDAqBC;AAzBD,kDAA+C;AAC/C,8CAA2C;AAC3C,oDAAiD;AAEjD,SAAgB,sBAAsB,CAAC,KAGtC;IACC,KAAK,MAAM,IAAI,IAAI,KAAK,CAAC,WAAW,CAAC,KAAK;QACxC,KAAK,MAAM,KAAK,IAAI,IAAI,CAAC,MAAM;YAAE,eAAe,CAAC,KAAK,CAAC,CAAC;IAC1D,uCACK,MAAM,CAAC,WAAW,CACnB,KAAK,CAAC,WAAW,CAAC,KAAK;SACpB,MAAM,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,QAAQ,KAAK,aAAa,CAAC;SACjD,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC;QACb,IAAI,CAAC,QAAQ;QACb,SAAS,iCACJ,KAAK,KACR,IAAI,IACJ;KACH,CAAC,CACL,KACD,aAAa,EACX,KAAK,CAAC,IAAI,KAAK,UAAU,CAAC,CAAC,CAAC,kBAAkB,CAAC,CAAC,CAAC,gBAAgB,IACnE;AACJ,CAAC;AAED,SAAS,SAAS,CAAC,KAIlB;IACC,OAAO,KAAK,CAAC,IAAI,CAAC,MAAM;SACrB,GAAG,CAAC,CAAC,KAAK,EAAE,EAAE,CACb,UAAU,iCACL,KAAK,KACR,KAAK,IACL,CACH;SACA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AC,IAAI,CAAA;;;;;;;;;;;;CAYvC,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@autobe/compiler",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.9.0",
|
|
4
4
|
"description": "AI backend server code generator",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"author": "Wrtn Technologies",
|
|
@@ -25,7 +25,7 @@
|
|
|
25
25
|
"prisma-markdown": "^3.0.0",
|
|
26
26
|
"tstl": "^3.0.0",
|
|
27
27
|
"typia": "^9.3.1",
|
|
28
|
-
"@autobe/interface": "^0.
|
|
28
|
+
"@autobe/interface": "^0.9.0"
|
|
29
29
|
},
|
|
30
30
|
"devDependencies": {
|
|
31
31
|
"@types/node": "^22.15.3",
|
package/src/AutoBeCompiler.ts
CHANGED
|
@@ -1,35 +1,42 @@
|
|
|
1
1
|
import {
|
|
2
|
-
AutoBeOpenApi,
|
|
3
2
|
IAutoBeCompiler,
|
|
4
3
|
IAutoBeInterfaceCompiler,
|
|
5
4
|
IAutoBePrismaCompiler,
|
|
6
5
|
IAutoBeTypeScriptCompiler,
|
|
7
|
-
IAutoBeTypeScriptCompilerProps,
|
|
8
|
-
IAutoBeTypeScriptCompilerResult,
|
|
9
6
|
} from "@autobe/interface";
|
|
10
7
|
|
|
11
8
|
import { AutoBeInterfaceCompiler } from "./AutoBeInterfaceCompiler";
|
|
12
9
|
import { AutoBePrismaCompiler } from "./AutoBePrismaCompiler";
|
|
13
10
|
import { AutoBeTypeScriptCompiler } from "./AutoBeTypeScriptCompiler";
|
|
14
11
|
|
|
12
|
+
/**
|
|
13
|
+
* Comprehensive compilation infrastructure for the vibe coding pipeline.
|
|
14
|
+
*
|
|
15
|
+
* This class provides the three-tier compiler system that transforms AST
|
|
16
|
+
* structures into production-ready code across all development phases. The
|
|
17
|
+
* AutoBeCompiler integrates the custom Prisma compiler, Interface compiler, and
|
|
18
|
+
* official TypeScript compiler into a unified compilation infrastructure.
|
|
19
|
+
*
|
|
20
|
+
* The compilation system ensures 100% syntactic correctness and semantic
|
|
21
|
+
* integrity throughout the automated development workflow by operating on
|
|
22
|
+
* validated AST data and providing continuous validation feedback loops. This
|
|
23
|
+
* enables the revolutionary "structure first, validate continuously, generate
|
|
24
|
+
* deterministically" approach that guarantees generated applications work
|
|
25
|
+
* correctly on the first attempt.
|
|
26
|
+
*
|
|
27
|
+
* For high-performance scenarios with multiple concurrent users, individual
|
|
28
|
+
* compiler components can be separated into dedicated worker processes to
|
|
29
|
+
* prevent blocking during computationally intensive compilation operations
|
|
30
|
+
* while maintaining the same interface compatibility.
|
|
31
|
+
*
|
|
32
|
+
* @author Samchon
|
|
33
|
+
*/
|
|
15
34
|
export class AutoBeCompiler implements IAutoBeCompiler {
|
|
16
35
|
public readonly prisma: IAutoBePrismaCompiler = new AutoBePrismaCompiler();
|
|
17
36
|
|
|
18
|
-
public interface
|
|
19
|
-
document: AutoBeOpenApi.IDocument,
|
|
20
|
-
): Promise<Record<string, string>> {
|
|
21
|
-
return this.interface_compiler_.compile(document);
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
public typescript(
|
|
25
|
-
props: IAutoBeTypeScriptCompilerProps,
|
|
26
|
-
): Promise<IAutoBeTypeScriptCompilerResult> {
|
|
27
|
-
return this.typescript_compiler_.compile(props);
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
private readonly interface_compiler_: IAutoBeInterfaceCompiler =
|
|
37
|
+
public readonly interface: IAutoBeInterfaceCompiler =
|
|
31
38
|
new AutoBeInterfaceCompiler();
|
|
32
39
|
|
|
33
|
-
|
|
40
|
+
public readonly typescript: IAutoBeTypeScriptCompiler =
|
|
34
41
|
new AutoBeTypeScriptCompiler();
|
|
35
42
|
}
|
|
@@ -1,6 +1,12 @@
|
|
|
1
1
|
import { AutoBeOpenApi, IAutoBeInterfaceCompiler } from "@autobe/interface";
|
|
2
2
|
import { NestiaMigrateApplication } from "@nestia/migrate";
|
|
3
|
-
import {
|
|
3
|
+
import {
|
|
4
|
+
HttpMigration,
|
|
5
|
+
IHttpMigrateApplication,
|
|
6
|
+
OpenApi,
|
|
7
|
+
OpenApiTypeChecker,
|
|
8
|
+
OpenApiV3_1,
|
|
9
|
+
} from "@samchon/openapi";
|
|
4
10
|
import sortImport from "@trivago/prettier-plugin-sort-imports";
|
|
5
11
|
import import2 from "import2";
|
|
6
12
|
import { format } from "prettier";
|
|
@@ -8,11 +14,34 @@ import { format } from "prettier";
|
|
|
8
14
|
import { AutoBeCompilerConstants } from "./raw/AutoBeCompilerConstants";
|
|
9
15
|
import { ArrayUtil } from "./utils/ArrayUtil";
|
|
10
16
|
|
|
17
|
+
/**
|
|
18
|
+
* Custom Interface compiler that handles API specification and NestJS
|
|
19
|
+
* application generation.
|
|
20
|
+
*
|
|
21
|
+
* This compiler transforms validated {@link AutoBeOpenApi.IDocument} AST
|
|
22
|
+
* structures into comprehensive NestJS projects through a sophisticated
|
|
23
|
+
* multi-stage transformation pipeline. The Interface compiler bridges the gap
|
|
24
|
+
* between database design and application implementation, ensuring perfect
|
|
25
|
+
* alignment with business requirements and database schemas.
|
|
26
|
+
*
|
|
27
|
+
* The compiler leverages NestiaMigrateApplication for robust NestJS project
|
|
28
|
+
* generation and HttpMigration for bidirectional conversion between AutoBE AST
|
|
29
|
+
* and standard OpenAPI formats. All generated TypeScript code is automatically
|
|
30
|
+
* formatted with Prettier and organized with proper import sorting for
|
|
31
|
+
* production-ready quality.
|
|
32
|
+
*
|
|
33
|
+
* Key capabilities include generating complete NestJS applications with
|
|
34
|
+
* controllers, DTOs, client SDKs, and E2E test scaffolds, all enhanced with
|
|
35
|
+
* keyworded parameter optimization for AI consumption and comprehensive
|
|
36
|
+
* documentation derived from AST descriptions.
|
|
37
|
+
*
|
|
38
|
+
* @author Samchon
|
|
39
|
+
*/
|
|
11
40
|
export class AutoBeInterfaceCompiler implements IAutoBeInterfaceCompiler {
|
|
12
41
|
public async compile(
|
|
13
42
|
document: AutoBeOpenApi.IDocument,
|
|
14
43
|
): Promise<Record<string, string>> {
|
|
15
|
-
const swagger: OpenApi.IDocument =
|
|
44
|
+
const swagger: OpenApi.IDocument = transformDocument(document);
|
|
16
45
|
const migrate: NestiaMigrateApplication = new NestiaMigrateApplication(
|
|
17
46
|
swagger,
|
|
18
47
|
);
|
|
@@ -41,6 +70,18 @@ export class AutoBeInterfaceCompiler implements IAutoBeInterfaceCompiler {
|
|
|
41
70
|
"README.md": AutoBeCompilerConstants.README,
|
|
42
71
|
};
|
|
43
72
|
}
|
|
73
|
+
|
|
74
|
+
public async transform(
|
|
75
|
+
document: AutoBeOpenApi.IDocument,
|
|
76
|
+
): Promise<OpenApi.IDocument> {
|
|
77
|
+
return transformDocument(document);
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
public async invert(
|
|
81
|
+
document: OpenApi.IDocument,
|
|
82
|
+
): Promise<AutoBeOpenApi.IDocument> {
|
|
83
|
+
return invertDocument(document);
|
|
84
|
+
}
|
|
44
85
|
}
|
|
45
86
|
|
|
46
87
|
async function beautify(script: string) {
|
|
@@ -58,9 +99,7 @@ async function beautify(script: string) {
|
|
|
58
99
|
}
|
|
59
100
|
}
|
|
60
101
|
|
|
61
|
-
function
|
|
62
|
-
route: AutoBeOpenApi.IDocument,
|
|
63
|
-
): OpenApi.IDocument {
|
|
102
|
+
function transformDocument(route: AutoBeOpenApi.IDocument): OpenApi.IDocument {
|
|
64
103
|
const paths: Record<string, OpenApi.IPath> = {};
|
|
65
104
|
for (const op of route.operations) {
|
|
66
105
|
paths[op.path] ??= {};
|
|
@@ -109,3 +148,57 @@ function createOpenApiDocument(
|
|
|
109
148
|
components: route.components,
|
|
110
149
|
} as OpenApiV3_1.IDocument);
|
|
111
150
|
}
|
|
151
|
+
|
|
152
|
+
function invertDocument(document: OpenApi.IDocument): AutoBeOpenApi.IDocument {
|
|
153
|
+
const app: IHttpMigrateApplication = HttpMigration.application(document);
|
|
154
|
+
return {
|
|
155
|
+
operations: app.routes
|
|
156
|
+
.filter((r) => r.query === null)
|
|
157
|
+
.map(
|
|
158
|
+
(r) =>
|
|
159
|
+
({
|
|
160
|
+
specification: empty("specification"),
|
|
161
|
+
method: r.method as "post",
|
|
162
|
+
path: r.path,
|
|
163
|
+
summary: r.operation().summary ?? empty("summary"),
|
|
164
|
+
description: r.operation().description ?? empty("description"),
|
|
165
|
+
parameters: r.parameters.map(
|
|
166
|
+
(p) =>
|
|
167
|
+
({
|
|
168
|
+
name: p.name,
|
|
169
|
+
description:
|
|
170
|
+
p.parameter().description ?? empty("description"),
|
|
171
|
+
schema: p.schema as any,
|
|
172
|
+
}) satisfies AutoBeOpenApi.IParameter,
|
|
173
|
+
),
|
|
174
|
+
requestBody:
|
|
175
|
+
r.body?.type === "application/json" &&
|
|
176
|
+
OpenApiTypeChecker.isReference(r.body.schema)
|
|
177
|
+
? {
|
|
178
|
+
description: r.body.description() ?? empty("description"),
|
|
179
|
+
typeName: r.body.schema.$ref.split("/").pop()!,
|
|
180
|
+
}
|
|
181
|
+
: null,
|
|
182
|
+
responseBody:
|
|
183
|
+
r.success?.type === "application/json" &&
|
|
184
|
+
OpenApiTypeChecker.isReference(r.success.schema)
|
|
185
|
+
? {
|
|
186
|
+
description:
|
|
187
|
+
r.success.description() ?? empty("description"),
|
|
188
|
+
typeName: r.success.schema.$ref.split("/").pop()!,
|
|
189
|
+
}
|
|
190
|
+
: null,
|
|
191
|
+
}) satisfies AutoBeOpenApi.IOperation,
|
|
192
|
+
),
|
|
193
|
+
components: {
|
|
194
|
+
schemas: (document.components?.schemas ?? {}) as Record<
|
|
195
|
+
string,
|
|
196
|
+
AutoBeOpenApi.IJsonSchemaDescriptive
|
|
197
|
+
>,
|
|
198
|
+
},
|
|
199
|
+
};
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
function empty(key: string): string {
|
|
203
|
+
return `Describe ${key} as much as possible with clear and concise words.`;
|
|
204
|
+
}
|
|
@@ -10,6 +10,31 @@ import { EmbedPrisma } from "embed-prisma";
|
|
|
10
10
|
import { validatePrismaApplication } from "./prisma/validatePrismaApplication";
|
|
11
11
|
import { writePrismaApplication } from "./prisma/writePrismaApplication";
|
|
12
12
|
|
|
13
|
+
/**
|
|
14
|
+
* Custom Prisma compiler that handles database schema validation and
|
|
15
|
+
* generation.
|
|
16
|
+
*
|
|
17
|
+
* This compiler provides the foundational compilation layer that transforms
|
|
18
|
+
* business requirements into validated database architectures through
|
|
19
|
+
* sophisticated AST manipulation. The AutoBePrismaCompiler operates exclusively
|
|
20
|
+
* on {@link AutoBePrisma.IApplication} structures, eliminating error-prone
|
|
21
|
+
* text-based schema authoring while ensuring perfect consistency between
|
|
22
|
+
* business logic and data storage design.
|
|
23
|
+
*
|
|
24
|
+
* The implementation leverages EmbedPrisma for robust schema compilation,
|
|
25
|
+
* custom validation logic for comprehensive AST analysis, and specialized
|
|
26
|
+
* writing utilities for deterministic code generation. The compiler ensures
|
|
27
|
+
* 100% syntactic correctness and semantic integrity through multi-layered
|
|
28
|
+
* validation including relationship graph analysis, business logic validation,
|
|
29
|
+
* and performance optimization.
|
|
30
|
+
*
|
|
31
|
+
* The compilation process produces comprehensive documentation, optimal
|
|
32
|
+
* indexes, proper constraints, and ERD diagrams ready for production deployment
|
|
33
|
+
* while maintaining perfect alignment with business requirements throughout the
|
|
34
|
+
* automated development pipeline.
|
|
35
|
+
*
|
|
36
|
+
* @author Samchon
|
|
37
|
+
*/
|
|
13
38
|
export class AutoBePrismaCompiler implements IAutoBePrismaCompiler {
|
|
14
39
|
public async compile(
|
|
15
40
|
props: IAutoBePrismaCompilerProps,
|
|
@@ -19,14 +44,18 @@ export class AutoBePrismaCompiler implements IAutoBePrismaCompiler {
|
|
|
19
44
|
}
|
|
20
45
|
|
|
21
46
|
public async validate(
|
|
22
|
-
|
|
47
|
+
application: AutoBePrisma.IApplication,
|
|
23
48
|
): Promise<IAutoBePrismaValidation> {
|
|
24
|
-
return validatePrismaApplication(
|
|
49
|
+
return validatePrismaApplication(application);
|
|
25
50
|
}
|
|
26
51
|
|
|
27
52
|
public async write(
|
|
28
|
-
|
|
53
|
+
application: AutoBePrisma.IApplication,
|
|
54
|
+
dbms: "postgres" | "sqlite" = "postgres",
|
|
29
55
|
): Promise<Record<string, string>> {
|
|
30
|
-
return writePrismaApplication(
|
|
56
|
+
return writePrismaApplication({
|
|
57
|
+
application,
|
|
58
|
+
dbms,
|
|
59
|
+
});
|
|
31
60
|
}
|
|
32
61
|
}
|
|
@@ -10,6 +10,31 @@ import typiaTransform from "typia/lib/transform";
|
|
|
10
10
|
|
|
11
11
|
import EXTERNAL from "./raw/external.json";
|
|
12
12
|
|
|
13
|
+
/**
|
|
14
|
+
* Official TypeScript compiler for final code validation and quality assurance.
|
|
15
|
+
*
|
|
16
|
+
* This compiler provides the ultimate validation layer that ensures all
|
|
17
|
+
* generated code meets production standards and integrates seamlessly with the
|
|
18
|
+
* TypeScript ecosystem. While the AST-based approach eliminates most potential
|
|
19
|
+
* errors before code generation, the AutoBeTypeScriptCompiler serves as the
|
|
20
|
+
* final quality gate for perfect integration verification throughout the vibe
|
|
21
|
+
* coding pipeline.
|
|
22
|
+
*
|
|
23
|
+
* The implementation validates framework integration with NestJS APIs, type
|
|
24
|
+
* system integrity for complex relationships, dependency resolution across
|
|
25
|
+
* modules, and build system compatibility with standard toolchains. It provides
|
|
26
|
+
* comprehensive IDE support including intelligent autocomplete, real-time error
|
|
27
|
+
* detection, sophisticated refactoring capabilities, and complete navigation
|
|
28
|
+
* features.
|
|
29
|
+
*
|
|
30
|
+
* The compiler enables critical feedback loops necessary for AI self-correction
|
|
31
|
+
* when implementation or test code contains compilation errors requiring
|
|
32
|
+
* iterative refinement. This ensures that generated applications are
|
|
33
|
+
* immediately deployable without manual debugging cycles while maintaining the
|
|
34
|
+
* reliability of the automated development process.
|
|
35
|
+
*
|
|
36
|
+
* @author Samchon
|
|
37
|
+
*/
|
|
13
38
|
export class AutoBeTypeScriptCompiler implements IAutoBeTypeScriptCompiler {
|
|
14
39
|
public async compile(
|
|
15
40
|
props: IAutoBeTypeScriptCompilerProps,
|
|
@@ -21,9 +46,9 @@ export class AutoBeTypeScriptCompiler implements IAutoBeTypeScriptCompiler {
|
|
|
21
46
|
target: ts.ScriptTarget.ESNext,
|
|
22
47
|
module: ts.ModuleKind.CommonJS,
|
|
23
48
|
downlevelIteration: true,
|
|
49
|
+
baseUrl: "./",
|
|
24
50
|
paths: {
|
|
25
51
|
[alias]: ["./src/api"],
|
|
26
|
-
[`${alias}/lib/`]: ["./src/api"],
|
|
27
52
|
[`${alias}/lib/*`]: ["./src/api/*"],
|
|
28
53
|
},
|
|
29
54
|
strict: true,
|