@autobe/compiler 0.29.2 → 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/lib/AutoBeCompiler.d.ts +2 -2
- package/lib/AutoBeCompiler.js +3 -3
- package/lib/AutoBeCompiler.js.map +1 -1
- package/lib/AutoBeTypeScriptCompiler.d.ts +1 -0
- package/lib/AutoBeTypeScriptCompiler.js +27 -0
- package/lib/AutoBeTypeScriptCompiler.js.map +1 -1
- package/lib/database/AutoBeDatabaseCompiler.d.ts +6 -0
- package/lib/{prisma/AutoBePrismaCompiler.js → database/AutoBeDatabaseCompiler.js} +19 -13
- package/lib/database/AutoBeDatabaseCompiler.js.map +1 -0
- package/lib/database/validateDatabaseApplication.d.ts +2 -0
- package/lib/{prisma/validatePrismaApplication.js → database/validateDatabaseApplication.js} +178 -4
- package/lib/database/validateDatabaseApplication.js.map +1 -0
- package/lib/index.d.ts +1 -1
- package/lib/index.js +1 -1
- package/lib/index.js.map +1 -1
- package/lib/interface/AutoBeInterfaceCompiler.d.ts +1 -1
- package/lib/raw/AutoBeCompilerCommonTemplate.js +2 -2
- package/lib/raw/AutoBeCompilerCommonTemplate.js.map +1 -1
- package/lib/raw/AutoBeCompilerInterfaceTemplate.js +4 -2
- package/lib/raw/AutoBeCompilerInterfaceTemplate.js.map +1 -1
- package/lib/raw/AutoBeCompilerRealizeTemplate.js +16 -3
- package/lib/raw/AutoBeCompilerRealizeTemplate.js.map +1 -1
- package/lib/raw/AutoBeCompilerRealizeTemplateOfPostgres.js +3 -2
- package/lib/raw/AutoBeCompilerRealizeTemplateOfPostgres.js.map +1 -1
- package/lib/raw/AutoBeCompilerRealizeTemplateOfSQLite.js +2 -1
- package/lib/raw/AutoBeCompilerRealizeTemplateOfSQLite.js.map +1 -1
- package/lib/raw/AutoBeCompilerTestTemplate.js +1 -1
- package/lib/raw/AutoBeCompilerTestTemplate.js.map +1 -1
- package/lib/raw/nestjs.json +1777 -656
- package/lib/raw/test.json +748 -520
- package/lib/realize/writeRealizeControllers.js +16 -10
- package/lib/realize/writeRealizeControllers.js.map +1 -1
- package/lib/test/AutoBeTestCompiler.d.ts +1 -0
- package/lib/test/AutoBeTestCompiler.js +6 -0
- package/lib/test/AutoBeTestCompiler.js.map +1 -1
- package/lib/test/programmers/AutoBeTestLiteralProgrammer.js +2 -2
- package/lib/test/programmers/AutoBeTestLiteralProgrammer.js.map +1 -1
- package/lib/test/programmers/IAutoBeTestProgrammerContext.d.ts +1 -1
- package/lib/test/programmers/writeTestExpression.js +3 -1
- package/lib/test/programmers/writeTestExpression.js.map +1 -1
- package/lib/test/programmers/writeTestFunction.js +4 -4
- package/lib/test/programmers/writeTestFunction.js.map +1 -1
- package/lib/test/programmers/writeTestStatement.js +3 -1
- package/lib/test/programmers/writeTestStatement.js.map +1 -1
- package/lib/utils/FilePrinter.js +1 -1
- package/lib/utils/FilePrinter.js.map +1 -1
- package/package.json +13 -12
- package/src/AutoBeCompiler.ts +5 -5
- package/src/AutoBeTypeScriptCompiler.ts +36 -0
- package/src/database/AutoBeDatabaseCompiler.ts +48 -0
- package/src/{prisma/validatePrismaApplication.ts → database/validateDatabaseApplication.ts} +228 -28
- package/src/index.ts +1 -1
- package/src/interface/AutoBeInterfaceCompiler.ts +1 -1
- package/src/raw/AutoBeCompilerCommonTemplate.ts +2 -2
- package/src/raw/AutoBeCompilerInterfaceTemplate.ts +4 -2
- package/src/raw/AutoBeCompilerRealizeTemplate.ts +16 -3
- package/src/raw/AutoBeCompilerRealizeTemplateOfPostgres.ts +3 -2
- package/src/raw/AutoBeCompilerRealizeTemplateOfSQLite.ts +2 -1
- package/src/raw/AutoBeCompilerTestTemplate.ts +1 -1
- package/src/raw/nestjs.json +1777 -656
- package/src/raw/test.json +748 -520
- package/src/realize/writeRealizeControllers.ts +26 -16
- package/src/test/AutoBeTestCompiler.ts +9 -0
- package/src/test/programmers/AutoBeTestLiteralProgrammer.ts +2 -2
- package/src/test/programmers/IAutoBeTestProgrammerContext.ts +1 -1
- package/src/test/programmers/writeTestExpression.ts +6 -1
- package/src/test/programmers/writeTestFunction.ts +3 -2
- package/src/test/programmers/writeTestStatement.ts +5 -1
- package/src/utils/FilePrinter.ts +1 -1
- package/lib/prisma/AutoBePrismaCompiler.d.ts +0 -6
- package/lib/prisma/AutoBePrismaCompiler.js.map +0 -1
- package/lib/prisma/validatePrismaApplication.d.ts +0 -2
- package/lib/prisma/validatePrismaApplication.js.map +0 -1
- package/src/prisma/AutoBePrismaCompiler.ts +0 -36
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { MapUtil, StringUtil } from "@autobe/utils";
|
|
1
|
+
import { AutoBeDatabase, IAutoBeDatabaseValidation } from "@autobe/interface";
|
|
2
|
+
import { AutoBeEscaper, MapUtil, StringUtil } from "@autobe/utils";
|
|
3
3
|
import { HashMap, hash } from "tstl";
|
|
4
4
|
|
|
5
|
-
export function
|
|
6
|
-
application:
|
|
7
|
-
):
|
|
5
|
+
export function validateDatabaseApplication(
|
|
6
|
+
application: AutoBeDatabase.IApplication,
|
|
7
|
+
): IAutoBeDatabaseValidation {
|
|
8
8
|
const dict: Map<string, IModelContainer> = new Map(
|
|
9
9
|
application.files
|
|
10
10
|
.map((file, fi) =>
|
|
@@ -23,7 +23,7 @@ export function validatePrismaApplication(
|
|
|
23
23
|
)
|
|
24
24
|
.flat(),
|
|
25
25
|
);
|
|
26
|
-
const errors:
|
|
26
|
+
const errors: IAutoBeDatabaseValidation.IError[] = [
|
|
27
27
|
...validateDuplicatedFiles(application),
|
|
28
28
|
...validateDuplicatedModels(application),
|
|
29
29
|
...application.files
|
|
@@ -33,8 +33,10 @@ export function validatePrismaApplication(
|
|
|
33
33
|
return [
|
|
34
34
|
...validateDuplicatedFields(dict, model, accessor),
|
|
35
35
|
...validateDuplicatedIndexes(model, accessor),
|
|
36
|
+
...validateValidNames(model, accessor),
|
|
36
37
|
...validateIndexes(model, accessor),
|
|
37
38
|
...validateReferences(model, accessor, dict),
|
|
39
|
+
...validateDuplicatedRelationOppositeNames(dict, model),
|
|
38
40
|
];
|
|
39
41
|
}),
|
|
40
42
|
)
|
|
@@ -53,8 +55,8 @@ export function validatePrismaApplication(
|
|
|
53
55
|
}
|
|
54
56
|
|
|
55
57
|
interface IModelContainer {
|
|
56
|
-
file:
|
|
57
|
-
model:
|
|
58
|
+
file: AutoBeDatabase.IFile;
|
|
59
|
+
model: AutoBeDatabase.IModel;
|
|
58
60
|
fileIndex: number;
|
|
59
61
|
modelIndex: number;
|
|
60
62
|
}
|
|
@@ -63,10 +65,10 @@ interface IModelContainer {
|
|
|
63
65
|
DUPLICATES
|
|
64
66
|
----------------------------------------------------------- */
|
|
65
67
|
function validateDuplicatedFiles(
|
|
66
|
-
app:
|
|
67
|
-
):
|
|
68
|
+
app: AutoBeDatabase.IApplication,
|
|
69
|
+
): IAutoBeDatabaseValidation.IError[] {
|
|
68
70
|
interface IFileContainer {
|
|
69
|
-
file:
|
|
71
|
+
file: AutoBeDatabase.IFile;
|
|
70
72
|
index: number;
|
|
71
73
|
}
|
|
72
74
|
const group: Map<string, IFileContainer[]> = new Map();
|
|
@@ -75,7 +77,7 @@ function validateDuplicatedFiles(
|
|
|
75
77
|
MapUtil.take(group, file.filename, () => []).push(container);
|
|
76
78
|
});
|
|
77
79
|
|
|
78
|
-
const errors:
|
|
80
|
+
const errors: IAutoBeDatabaseValidation.IError[] = [];
|
|
79
81
|
for (const array of group.values())
|
|
80
82
|
if (array.length !== 1)
|
|
81
83
|
array.forEach((container, i) => {
|
|
@@ -99,8 +101,8 @@ function validateDuplicatedFiles(
|
|
|
99
101
|
}
|
|
100
102
|
|
|
101
103
|
function validateDuplicatedModels(
|
|
102
|
-
app:
|
|
103
|
-
):
|
|
104
|
+
app: AutoBeDatabase.IApplication,
|
|
105
|
+
): IAutoBeDatabaseValidation.IError[] {
|
|
104
106
|
const modelContainers: Map<string, IModelContainer[]> = new Map();
|
|
105
107
|
app.files.forEach((file, fileIndex) => {
|
|
106
108
|
file.models.forEach((model, modelIndex) => {
|
|
@@ -114,7 +116,7 @@ function validateDuplicatedModels(
|
|
|
114
116
|
});
|
|
115
117
|
});
|
|
116
118
|
|
|
117
|
-
const errors:
|
|
119
|
+
const errors: IAutoBeDatabaseValidation.IError[] = [];
|
|
118
120
|
for (const array of modelContainers.values())
|
|
119
121
|
if (array.length !== 1)
|
|
120
122
|
array.forEach((container, i) => {
|
|
@@ -142,10 +144,10 @@ function validateDuplicatedModels(
|
|
|
142
144
|
|
|
143
145
|
function validateDuplicatedFields(
|
|
144
146
|
dict: Map<string, IModelContainer>,
|
|
145
|
-
model:
|
|
147
|
+
model: AutoBeDatabase.IModel,
|
|
146
148
|
accessor: string,
|
|
147
|
-
):
|
|
148
|
-
const errors:
|
|
149
|
+
): IAutoBeDatabaseValidation.IError[] {
|
|
150
|
+
const errors: IAutoBeDatabaseValidation.IError[] = [];
|
|
149
151
|
|
|
150
152
|
// FIND DUPLICATED FIELDS
|
|
151
153
|
const group: Map<string, string[]> = new Map();
|
|
@@ -231,10 +233,10 @@ function validateDuplicatedFields(
|
|
|
231
233
|
}
|
|
232
234
|
|
|
233
235
|
function validateDuplicatedIndexes(
|
|
234
|
-
model:
|
|
236
|
+
model: AutoBeDatabase.IModel,
|
|
235
237
|
accessor: string,
|
|
236
|
-
):
|
|
237
|
-
const errors:
|
|
238
|
+
): IAutoBeDatabaseValidation.IError[] {
|
|
239
|
+
const errors: IAutoBeDatabaseValidation.IError[] = [];
|
|
238
240
|
|
|
239
241
|
// FIND DUPLICATED INDEXES
|
|
240
242
|
const group: HashMap<string[], string[]> = new HashMap(
|
|
@@ -415,7 +417,7 @@ function validateDuplicatedIndexes(
|
|
|
415
417
|
new Set(model.ginIndexes.map((g) => g.fieldName)).size
|
|
416
418
|
)
|
|
417
419
|
errors.push({
|
|
418
|
-
path: `${accessor}.ginIndexes
|
|
420
|
+
path: `${accessor}.ginIndexes`,
|
|
419
421
|
table: model.name,
|
|
420
422
|
field: null,
|
|
421
423
|
message: StringUtil.trim`
|
|
@@ -430,13 +432,211 @@ function validateDuplicatedIndexes(
|
|
|
430
432
|
return errors;
|
|
431
433
|
}
|
|
432
434
|
|
|
435
|
+
function validateDuplicatedRelationOppositeNames(
|
|
436
|
+
dict: Map<string, IModelContainer>,
|
|
437
|
+
model: AutoBeDatabase.IModel,
|
|
438
|
+
): IAutoBeDatabaseValidation.IError[] {
|
|
439
|
+
interface IOppositeNameContainer {
|
|
440
|
+
container: IModelContainer;
|
|
441
|
+
foreignField: AutoBeDatabase.IForeignField;
|
|
442
|
+
foreignFieldIndex: number;
|
|
443
|
+
}
|
|
444
|
+
const errors: IAutoBeDatabaseValidation.IError[] = [];
|
|
445
|
+
const group: Map<string, IOppositeNameContainer[]> = new Map();
|
|
446
|
+
|
|
447
|
+
// Collect all field/relation names in the target model
|
|
448
|
+
const targetFieldNames = new Set<string>([
|
|
449
|
+
model.primaryField.name,
|
|
450
|
+
...model.foreignFields.map((f) => f.name),
|
|
451
|
+
...model.foreignFields.map((f) => f.relation.name),
|
|
452
|
+
...model.plainFields.map((f) => f.name),
|
|
453
|
+
]);
|
|
454
|
+
|
|
455
|
+
for (const c of dict.values()) {
|
|
456
|
+
c.model.foreignFields.forEach((ff, i) => {
|
|
457
|
+
if (ff.relation.targetModel !== model.name) return;
|
|
458
|
+
MapUtil.take(group, ff.relation.oppositeName, () => []).push({
|
|
459
|
+
container: c,
|
|
460
|
+
foreignField: ff,
|
|
461
|
+
foreignFieldIndex: i,
|
|
462
|
+
});
|
|
463
|
+
});
|
|
464
|
+
}
|
|
465
|
+
|
|
466
|
+
// Check oppositeName conflicts with target model's existing fields
|
|
467
|
+
for (const [oppositeName, array] of group) {
|
|
468
|
+
if (targetFieldNames.has(oppositeName)) {
|
|
469
|
+
array.forEach((item) => {
|
|
470
|
+
const c = item.container;
|
|
471
|
+
const ff = item.foreignField;
|
|
472
|
+
errors.push({
|
|
473
|
+
path: `application.files[${c.fileIndex}].models[${c.modelIndex}].foreignFields[${item.foreignFieldIndex}].relation.oppositeName`,
|
|
474
|
+
table: c.model.name,
|
|
475
|
+
field: ff.name,
|
|
476
|
+
message: StringUtil.trim`
|
|
477
|
+
oppositeName "${oppositeName}" conflicts with existing field in target model "${model.name}".
|
|
478
|
+
|
|
479
|
+
**What happened?**
|
|
480
|
+
The oppositeName "${oppositeName}" would create a reverse relation property in "${model.name}",
|
|
481
|
+
but "${model.name}" already has a field or relation with that name.
|
|
482
|
+
|
|
483
|
+
**Why is this a problem?**
|
|
484
|
+
- Prisma cannot have two properties with the same name in a model
|
|
485
|
+
- This will cause Prisma schema compilation errors
|
|
486
|
+
- The reverse relation would overwrite or conflict with the existing field
|
|
487
|
+
|
|
488
|
+
**How to fix:**
|
|
489
|
+
Choose a different oppositeName that doesn't conflict with existing fields in "${model.name}".
|
|
490
|
+
|
|
491
|
+
**Naming suggestions:**
|
|
492
|
+
- Add a descriptive prefix/suffix: "${oppositeName}List", "${oppositeName}Items", "related${oppositeName.charAt(0).toUpperCase() + oppositeName.slice(1)}"
|
|
493
|
+
- Use the source model name: "${c.model.name.replace(/_/g, "").toLowerCase()}s"
|
|
494
|
+
`,
|
|
495
|
+
});
|
|
496
|
+
});
|
|
497
|
+
}
|
|
498
|
+
}
|
|
499
|
+
|
|
500
|
+
// Check duplicate oppositeNames among relations targeting the same model
|
|
501
|
+
for (const [oppositeName, array] of group) {
|
|
502
|
+
if (array.length === 1) continue;
|
|
503
|
+
array.forEach((item, i) => {
|
|
504
|
+
const c = item.container;
|
|
505
|
+
const ff = item.foreignField;
|
|
506
|
+
errors.push({
|
|
507
|
+
path: `application.files[${c.fileIndex}].models[${c.modelIndex}].foreignFields[${item.foreignFieldIndex}].relation.oppositeName`,
|
|
508
|
+
table: c.model.name,
|
|
509
|
+
field: ff.name,
|
|
510
|
+
message: StringUtil.trim`
|
|
511
|
+
Duplicated relation oppositeName "${oppositeName}" detected on target model "${model.name}".
|
|
512
|
+
|
|
513
|
+
**What is oppositeName?**
|
|
514
|
+
In Prisma relations, oppositeName defines the name of the reverse relation field
|
|
515
|
+
on the target model. It allows the target model to access related records through
|
|
516
|
+
this named property.
|
|
517
|
+
|
|
518
|
+
**Current situation:**
|
|
519
|
+
Multiple foreign key fields from different models are trying to create reverse
|
|
520
|
+
relations on "${model.name}" with the same oppositeName "${oppositeName}".
|
|
521
|
+
|
|
522
|
+
**Conflicting relations:**
|
|
523
|
+
${array
|
|
524
|
+
.filter((_, j) => i !== j)
|
|
525
|
+
.map(
|
|
526
|
+
(oppo) =>
|
|
527
|
+
`- Model "${oppo.container.model.name}", field "${oppo.foreignField.name}" (accessor: application.files[${oppo.container.fileIndex}].models[${oppo.container.modelIndex}].foreignFields[${oppo.foreignFieldIndex}].relation.oppositeName)`,
|
|
528
|
+
)
|
|
529
|
+
.join("\n")}
|
|
530
|
+
|
|
531
|
+
**Why is this a problem?**
|
|
532
|
+
- Prisma requires unique relation names within a model
|
|
533
|
+
- When "${model.name}" tries to access related records, it won't know which relation to use
|
|
534
|
+
- This will cause Prisma schema compilation errors
|
|
535
|
+
|
|
536
|
+
**How to fix:**
|
|
537
|
+
Each relation pointing to "${model.name}" must have a unique oppositeName.
|
|
538
|
+
|
|
539
|
+
**Naming suggestions:**
|
|
540
|
+
- Use descriptive names that indicate the relationship's purpose
|
|
541
|
+
- Include the source model name for clarity
|
|
542
|
+
- Examples:
|
|
543
|
+
- Instead of both using "orders", use "customerOrders" and "sellerOrders"
|
|
544
|
+
- Instead of both using "users", use "createdByUser" and "assignedToUser"
|
|
545
|
+
- For "${c.model.name}" → "${model.name}": consider "${c.model.name.charAt(0).toLowerCase() + c.model.name.slice(1)}s" or a more descriptive name
|
|
546
|
+
|
|
547
|
+
Please rename the oppositeName to be unique across all relations targeting "${model.name}".
|
|
548
|
+
`,
|
|
549
|
+
});
|
|
550
|
+
});
|
|
551
|
+
}
|
|
552
|
+
return errors;
|
|
553
|
+
}
|
|
554
|
+
|
|
433
555
|
/* -----------------------------------------------------------
|
|
434
556
|
VALIDATIONS
|
|
435
557
|
----------------------------------------------------------- */
|
|
558
|
+
function validateValidNames(
|
|
559
|
+
model: AutoBeDatabase.IModel,
|
|
560
|
+
accessor: string,
|
|
561
|
+
): IAutoBeDatabaseValidation.IError[] {
|
|
562
|
+
const errors: IAutoBeDatabaseValidation.IError[] = [];
|
|
563
|
+
const validate = (props: {
|
|
564
|
+
value: string;
|
|
565
|
+
accessor: string;
|
|
566
|
+
field: string | null;
|
|
567
|
+
}): void => {
|
|
568
|
+
if (AutoBeEscaper.reserved(props.value))
|
|
569
|
+
errors.push({
|
|
570
|
+
path: props.accessor,
|
|
571
|
+
table: model.name,
|
|
572
|
+
field: props.field,
|
|
573
|
+
message: StringUtil.trim`
|
|
574
|
+
The name "${props.value}" is a system reserved keyword and cannot be used.
|
|
575
|
+
`,
|
|
576
|
+
});
|
|
577
|
+
else if (AutoBeEscaper.variable(props.value) === false)
|
|
578
|
+
errors.push({
|
|
579
|
+
path: props.accessor,
|
|
580
|
+
table: model.name,
|
|
581
|
+
field: props.field,
|
|
582
|
+
message: StringUtil.trim`
|
|
583
|
+
The name "${props.value}" is not a valid identifier.
|
|
584
|
+
|
|
585
|
+
Change to a valid identifier which can be a variable name in programming languages.
|
|
586
|
+
`,
|
|
587
|
+
});
|
|
588
|
+
};
|
|
589
|
+
|
|
590
|
+
// TABLE NAME
|
|
591
|
+
validate({
|
|
592
|
+
value: model.name,
|
|
593
|
+
accessor: `${accessor}.name`,
|
|
594
|
+
field: null,
|
|
595
|
+
});
|
|
596
|
+
|
|
597
|
+
// FIELDS
|
|
598
|
+
validate({
|
|
599
|
+
value: model.primaryField.name,
|
|
600
|
+
accessor: `${accessor}.primaryField.name`,
|
|
601
|
+
field: model.primaryField.name,
|
|
602
|
+
});
|
|
603
|
+
model.foreignFields.forEach((ff, i) => {
|
|
604
|
+
validate({
|
|
605
|
+
value: ff.name,
|
|
606
|
+
accessor: `${accessor}.foreignFields[${i}].name`,
|
|
607
|
+
field: ff.name,
|
|
608
|
+
});
|
|
609
|
+
validate({
|
|
610
|
+
value: ff.relation.name,
|
|
611
|
+
accessor: `${accessor}.foreignFields[${i}].relation.name`,
|
|
612
|
+
field: ff.name,
|
|
613
|
+
});
|
|
614
|
+
validate({
|
|
615
|
+
value: ff.relation.oppositeName,
|
|
616
|
+
accessor: `${accessor}.foreignFields[${i}].relation.oppositeName`,
|
|
617
|
+
field: ff.name,
|
|
618
|
+
});
|
|
619
|
+
if (ff.relation.mappingName)
|
|
620
|
+
validate({
|
|
621
|
+
value: ff.relation.mappingName,
|
|
622
|
+
accessor: `${accessor}.foreignFields[${i}].relation.mappingName`,
|
|
623
|
+
field: ff.name,
|
|
624
|
+
});
|
|
625
|
+
});
|
|
626
|
+
model.plainFields.forEach((pf, i) =>
|
|
627
|
+
validate({
|
|
628
|
+
value: pf.name,
|
|
629
|
+
accessor: `${accessor}.plainFields[${i}].name`,
|
|
630
|
+
field: pf.name,
|
|
631
|
+
}),
|
|
632
|
+
);
|
|
633
|
+
return errors;
|
|
634
|
+
}
|
|
635
|
+
|
|
436
636
|
function validateIndexes(
|
|
437
|
-
model:
|
|
637
|
+
model: AutoBeDatabase.IModel,
|
|
438
638
|
accessor: string,
|
|
439
|
-
):
|
|
639
|
+
): IAutoBeDatabaseValidation.IError[] {
|
|
440
640
|
// EMENSION
|
|
441
641
|
model.uniqueIndexes = model.uniqueIndexes.filter(
|
|
442
642
|
(unique) =>
|
|
@@ -449,7 +649,7 @@ function validateIndexes(
|
|
|
449
649
|
plain.fieldNames[0] !== model.primaryField.name,
|
|
450
650
|
);
|
|
451
651
|
|
|
452
|
-
const errors:
|
|
652
|
+
const errors: IAutoBeDatabaseValidation.IError[] = [];
|
|
453
653
|
const columnNames: Set<string> = new Set([
|
|
454
654
|
model.primaryField.name,
|
|
455
655
|
...model.foreignFields.map((field) => field.name),
|
|
@@ -589,11 +789,11 @@ function validateIndexes(
|
|
|
589
789
|
}
|
|
590
790
|
|
|
591
791
|
function validateReferences(
|
|
592
|
-
model:
|
|
792
|
+
model: AutoBeDatabase.IModel,
|
|
593
793
|
accessor: string,
|
|
594
794
|
dict: Map<string, IModelContainer>,
|
|
595
|
-
):
|
|
596
|
-
const errors:
|
|
795
|
+
): IAutoBeDatabaseValidation.IError[] {
|
|
796
|
+
const errors: IAutoBeDatabaseValidation.IError[] = [];
|
|
597
797
|
|
|
598
798
|
model.foreignFields.forEach((field, i) => {
|
|
599
799
|
// DUPLICATED NAME
|
package/src/index.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
export * from "./AutoBeCompiler";
|
|
2
|
-
export * from "./
|
|
2
|
+
export * from "./database/AutoBeDatabaseCompiler";
|
|
3
3
|
export * from "./interface/AutoBeInterfaceCompiler";
|
|
4
4
|
export * from "./test/AutoBeTestCompiler";
|
|
5
5
|
export * from "./AutoBeTypeScriptCompiler";
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { AutoBeOpenApi, IAutoBeInterfaceCompiler } from "@autobe/interface";
|
|
2
2
|
import { invertOpenApiDocument, transformOpenApiDocument } from "@autobe/utils";
|
|
3
3
|
import { NestiaMigrateApplication } from "@nestia/migrate";
|
|
4
|
-
import { OpenApi } from "
|
|
4
|
+
import { OpenApi } from "typia";
|
|
5
5
|
|
|
6
6
|
import { ArrayUtil } from "../utils/ArrayUtil";
|
|
7
7
|
import { FilePrinter } from "../utils/FilePrinter";
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
export const AutoBeCompilerCommonTemplate: Record<string, string> = {
|
|
2
2
|
".eslintrc.cjs": "module.exports = {\n root: true,\n plugins: [\"@typescript-eslint\", \"deprecation\"],\n extends: [\"plugin:@typescript-eslint/recommended\"],\n parser: \"@typescript-eslint/parser\",\n parserOptions: {\n project: [\"tsconfig.json\", \"test/tsconfig.json\"],\n },\n overrides: [\n {\n files: [\"src/**/*.ts\", \"test/**/*.ts\"],\n rules: {\n \"@typescript-eslint/consistent-type-definitions\": \"off\",\n \"@typescript-eslint/no-empty-function\": \"off\",\n \"@typescript-eslint/no-empty-interface\": \"off\",\n \"@typescript-eslint/no-explicit-any\": \"off\",\n \"@typescript-eslint/no-inferrable-types\": \"off\",\n \"@typescript-eslint/no-namespace\": \"off\",\n \"@typescript-eslint/no-non-null-assertion\": \"off\",\n \"@typescript-eslint/no-unused-expressions\": \"off\",\n \"@typescript-eslint/no-unused-vars\": \"off\",\n \"@typescript-eslint/no-var-requires\": \"off\",\n \"@typescript-eslint/no-floating-promises\": \"error\",\n \"@typescript-eslint/no-require-imports\": \"off\",\n \"@typescript-eslint/no-empty-object-type\": \"off\",\n \"@typescript-eslint/prefer-as-const\": \"off\",\n \"prefer-as-const\": \"off\",\n },\n },\n ],\n};\n",
|
|
3
|
-
".gitignore": "./autobe/\nbin/\ndist/\nlib/\nnode_modules/\n\nprisma/migrations\nprisma/schema/migrations\nprisma/bbs.db\n\n*.DS_Store\n.env\n.npmrc\npackage-lock.json\npnpm-lock.yaml",
|
|
3
|
+
".gitignore": "./autobe/\nbin/\ndist/\nlib/\nnode_modules/\n\nprisma/migrations\nprisma/schema/migrations\nprisma/bbs.db\nsrc/prisma\n\n*.DS_Store\n.env\n.npmrc\npackage-lock.json\npnpm-lock.yaml",
|
|
4
4
|
"LICENSE": "MIT License\n\nCopyright (c) 2025 Wrtn Technologies\n\nPermission is hereby granted, free of charge, to any person obtaining a copy\nof this software and associated documentation files (the \"Software\"), to deal\nin the Software without restriction, including without limitation the rights\nto use, copy, modify, merge, publish, distribute, sublicense, and/or sell\ncopies of the Software, and to permit persons to whom the Software is\nfurnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in all\ncopies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\nIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\nFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\nAUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\nLIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\nOUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\nSOFTWARE.",
|
|
5
|
-
"README.md": "# AutoBE Generated Backend Server\n\n\n\nA backend repository generated by [`@autobe`](https://github.com/wrtnlabs/autobe).\n\nThis backend program was automatically generated using [`@autobe`](https://github.com/wrtnlabs/autobe), the AI vibe coding agent for backend servers of below stack.\n\n- TypeScript\n- NestJS / Nestia\n- Prisma\n- Postgres\n\n```mermaid\nflowchart\nsubgraph \"Backend Coding Agent\"\n coder(\"Facade Controller\")\nend\nsubgraph \"Functional Agents\"\n coder --\"Requirements Analysis\"--> analyze(\"{{ANALYSIS_EMOJI}} Analyze\")\n coder --\"ERD\"-->
|
|
5
|
+
"README.md": "# AutoBE Generated Backend Server\n\n\n\nA backend repository generated by [`@autobe`](https://github.com/wrtnlabs/autobe).\n\nThis backend program was automatically generated using [`@autobe`](https://github.com/wrtnlabs/autobe), the AI vibe coding agent for backend servers of below stack.\n\n- TypeScript\n- NestJS / Nestia\n- Prisma\n- Postgres\n\n```mermaid\nflowchart\nsubgraph \"Backend Coding Agent\"\n coder(\"Facade Controller\")\nend\nsubgraph \"Functional Agents\"\n coder --\"Requirements Analysis\"--> analyze(\"{{ANALYSIS_EMOJI}} Analyze\")\n coder --\"ERD\"--> database(\"{{DATABASE_EMOJI}} Database\")\n coder --\"API Design\"--> interface(\"{{INTERFACE_EMOJI}} Interface\")\n coder --\"Test Codes\" --> test(\"{{TEST_EMOJI}} Test\")\n coder --\"Main Program\" --> realize(\"{{REALIZE_EMOJI}} Realize\")\nend\nsubgraph \"Compiler Feedback\"\n database --\"validates\" --> prismaCompiler(\"Prisma Compiler\")\n interface --\"validates\" --> openapiValidator(\"OpenAPI Validator\")\n interface --\"generates\" --> tsCompiler(\"TypeScript Compiler\")\n test --\"validates\" --> tsCompiler(\"TypeScript Compiler\")\n realize --\"validates\" --> tsCompiler(\"TypeScript Compiler\")\nend\n```\n\nAlso, this backend application was built following [`@autobe`](https://github.com/wrtnlabs/autobe)'s waterfall development model, where each specialized AI agent handles a specific phase of development. The process ensures 100% working code through continuous compiler feedback and validation at every stage.\n\nEach agent receives input from previous phases and produces validated output that becomes the foundation for the next development stage. The **Facade Controller** orchestrates the entire process, while **Functional Agents** handle specialized tasks with built-in **Compiler Feedback** ensuring code quality and correctness.\n\nBelow table shows the mapping between waterfall phases, corresponding [`@autobe`](https://github.com/wrtnlabs/autobe) agents, and the actual deliverables you can find in this repository:\n\nWaterfall Model | AutoBe Agent | Result\n----------------|--------------|----------------------------------------------\nRequirements | ✅ Facade | Conversation History\nAnalysis | {{ANALYSIS_EMOJI}} Analyze | [Requirement Analysis Report](docs/analysis)\nDesign | {{DATABASE_EMOJI}} Prisma | [Entity Relationship Diagram](docs/ERD.md) / [Prisma Schema](prisma/schema)\nDesign | {{INTERFACE_EMOJI}} Interface | [API Controllers](src/controllers) / [DTO Structures](src/api/structures)\nDevelopment | {{REALIZE_EMOJI}} Realize | [API Provider Functions](src/providers)\nTesting | {{TEST_EMOJI}} Test | [E2E Test Functions](test/features/api)\nMaintenance | - | Use Claude Code like AI coding tool please\n\n## Project Structure\n\nThis template project has categorized directories like below.\n\nAs you can see from the below, all of the Backend source files are placed into the [src](src/) directory. When you build the TypeScript source files, compiled files would be placed into the `lib` directory following the [`tsconfig.json`](tsconfig.json) configuration. Otherwise you build client [SDK library](https://nestia.io/docs/sdk/) for npm publishing and their compiled files would be placed into the [`packages`](packages) directory.\n\n - [`packages/api/`](packages/api): SDK module built by `npm run build:api`\n - [`docs/`](docs/): Documentation directory\n - [`docs/analysis`](docs/analysis/): Requirement Analysis report\n - [`docs/ERD.md`](docs/ERD.md): Entity Relationship Diagram and detailed descriptions\n - [`prisma/schema`](prisma/schema): Prisma ORM schema files\n - [`src/`](src): Backend source directory\n - [`src/api/`](src/api/): Client SDK that would be published to the `@ORGANIZATION/PROJECT-api`\n - [`src/api/functional/`](src/api/functional/): API functions generated by the [`nestia`](https://github.com/samchon/nestia)\n - [`src/api/structures/`](src/api/structures/): DTO structures\n - [`src/controllers/`](src/controllers/): Controller classes of the Main Program\n - [`src/providers/`](src/providers/): Implementations of the API functions\n - [`test/`](test): Test Automation Program\n - [`test/features`](test/features): List of test functions\n - [`nestia.config.ts`](nestia.config.ts): Configuration file of [`nestia`](https://github.com/samchon/nestia)\n - [`package.json`](package.json): NPM configuration\n - [`tsconfig.json`](tsconfig.json): TypeScript configuration for the main program\n\n## NPM Run Commands\n\nList of the run commands defined in the [package.json](package.json) are like below:\n\n - Test\n - **`test`**: Run test automation program\n - `benchmark`: Run performance benchmark program\n - Build\n - `build`: Build everything\n - `build:main`: Build main program (`src` directory)\n - `build:test` Build test automation program (`test` directory)\n - `build:sdk`: Build SDK into main program only\n - `build:swagger`: Build Swagger Documents\n - **`dev`**: Incremental build for development (test program)\n - Deploy\n - `package:api`: Build and deploy the SDK library to the NPM\n - `start`: Start the backend server\n - `start:dev`: Start the backend server with incremental build and reload\n - Webpack\n - `webpack`: Run webpack bundler\n - `webpack:start`: Start the backend server built by webpack\n - `webpack:test`: Run test program to the webpack built\n\n## Specialization\n\nTransform this template project to be yours.\n\nWhen you've created a new backend project through this template project, you can specialize it to be suitable for you by changing some words. Replace below words through IDE specific function like `Edit > Replace in Files` (*Ctrl + Shift + H*), who've been supported by the VSCode.\n\n| Before | After\n|--------------|----------------------------------------\n| ORGANIZATION | Your account or corporation name\n| PROJECT | Your own project name\n| AUTHOR | Author name\n| https://github.com/samchon/nestia-start | Your repository URL\n\n## Benchmark\n\n### Aggregate\n\nPhase | Generated | FCSR | Token Consumption | Elapsed Time\n------|-----------|------|-------------------|--------------\n{{BENCHMARK_AGGREGATE}}\n\nThis table shows the comprehensive metrics for each phase of the AutoBE generation pipeline. For each phase (Analyze, Database, Interface, Test, Realize), it tracks:\n\n- **Phase**: The pipeline phase with success (✅) or failure (❌) indicator\n- **Generated**: Count of artifacts produced (e.g., actors, documents, namespaces, models, operations, schemas, functions)\n- **FCSR**: Function calling success rate\n- **Token Consumption**: Total number of LLM tokens consumed during the phase\n- **Elapsed Time**: Wall-clock time taken to complete the phase, including all AI agent operations and compiler feedback loops\n\nThese aggregate metrics provide visibility into the computational cost and time requirements of the entire generation process, helping identify resource-intensive phases and overall pipeline efficiency.\n\n### Function Calling\n\nType | Trial | Validation Failure | JSON Parse Error | Success | Success Rate\n:----|------:|-------------------:|-----------------:|---------:|-------------:\n{{BENCHMARK_FUNCTION_CALLING}}\n\nThis table shows the reliability and quality metrics for AI agent function calling operations across all phases. Each row represents a specific operation type (e.g., `analyzeScenario`, `prismaSchema`, `realizeWrite`), tracking:\n\n- **Type**: The AI agent operation name\n- **Trial**: Total number of function calling attempts made by the agent\n- **Validation Failure**: Calls that produced valid JSON but failed type validation\n- **JSON Parse Error**: Calls that produced malformed JSON that couldn't be parsed\n- **Success**: Calls that completed successfully with valid, validated responses\n- **Success Rate**: Percentage of successful calls out of total attempts\n\nThese metrics reveal the effectiveness of AutoBE's validation feedback strategy powered by [`typia.llm.application<Class, Model>()`](https://typia.io/docs/llm/application/). When function calls fail type validation, detailed error messages are fed back to the AI agent, enabling iterative correction through self-healing spiral loops.\n\nSuccess rates vary based on model size and capability - smaller models may have lower initial success rates. However, validation feedback enables even weaker models to achieve high success rates through automatic correction cycles, demonstrating the power of compiler-driven development.\n\n## License\n\nAutoBE is licensed under the [GNU Affero General Public License v3.0 (AGPL-3.0)](https://github.com/wrtnlabs/autobe/?tab=AGPL-3.0-1-ov-file#readme). If you modify AutoBE itself or offer it as a network service, you must make your source code available under the same license.\n\nHowever, backend applications generated by AutoBE can be relicensed under any license you choose, such as MIT. This means you can freely use AutoBE-generated code in commercial projects without open source obligations, similar to how other code generation tools work.\n",
|
|
6
6
|
"typos.toml": "[default]\nlocale = 'en-us'\nextend-ignore-re = [\n \"(?Rm)^.*(<!--|#|//)\\\\s*spellchecker:disable-line(-->|\\n)?$\",\n \".*(?:spellchecker|typos):\\\\s?ignore-next-line[^\\\\n]*\\\\n[^\\\\n]*\",\n \"(?s)(<!--|#|//)\\\\s*spellchecker:off\\\\s*(-->|\\n).*?(<!--|#|//)\\\\s*spellchecker:on\",\n]\n\n[default.extend-words]\nJeongho = \"Jeongho\"\nNam = \"Nam\"\ntypia = \"typia\"\n\n[files]\nextend-exclude = [\"*.json\"]"
|
|
7
7
|
};
|
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
export const AutoBeCompilerInterfaceTemplate: Record<string, string> = {
|
|
2
|
-
".github/workflows/build.yml": "name: build\non:\n pull_request:\n paths:\n - 'src/**'\n - 'test/**'\n - 'package.json'\njobs:\n Ubuntu:\n runs-on: ubuntu-latest\n steps:\n - uses: actions/checkout@v4\n - uses: actions/setup-node@v4\n with:\n node-version: 20.x\n - uses: pnpm/action-setup@v4\n with:\n version: 8\n \n - name: Install Backend-Server\n run: pnpm install\n\n - name: Build Swagger\n run: pnpm run build:swagger\n\n - name: Build SDK\n run: pnpm run build:sdk\n\n - name: Compile Backend-Server\n run: pnpm run build\n\n
|
|
3
|
-
"
|
|
2
|
+
".github/workflows/build.yml": "name: build\non:\n pull_request:\n paths:\n - 'src/**'\n - 'test/**'\n - 'package.json'\njobs:\n Ubuntu:\n runs-on: ubuntu-latest\n steps:\n - uses: actions/checkout@v4\n - uses: actions/setup-node@v4\n with:\n node-version: 20.x\n - uses: pnpm/action-setup@v4\n with:\n version: 8\n \n - name: Install Backend-Server\n run: pnpm install\n\n - name: Build Swagger\n run: pnpm run build:swagger\n\n - name: Build SDK\n run: pnpm run build:sdk\n\n - name: Compile Backend-Server\n run: pnpm run build\n\n - name: Run Test Program\n run: pnpm run test -- --reset true --simultaneous 16\n\n - name: EsLint\n run: pnpm run eslint\n",
|
|
3
|
+
"src/api/structures/IEntity.ts": "import { tags } from \"typia\";\n\n/** Just a base entity interface for referencing. */\nexport interface IEntity {\n /** Primary Key. */\n id: string & tags.Format<\"uuid\">;\n}\n",
|
|
4
|
+
"src/api/typings/DeepPartial.ts": "export type DeepPartial<T> = T extends\n | string\n | number\n | boolean\n | bigint\n | symbol\n | null\n | undefined\n ? T\n : T extends (...args: unknown[]) => unknown\n ? T\n : T extends Array<infer U>\n ? Array<DeepPartial<U>>\n : T extends object\n ? { [P in keyof T]?: DeepPartial<T[P]> }\n : T;\n",
|
|
5
|
+
"test/tsconfig.json": "{\n \"extends\": \"../tsconfig.json\",\n \"compilerOptions\": {\n \"baseUrl\": \"../\",\n \"outDir\": \"../bin\",\n \"noUnusedLocals\": false,\n \"noUnusedParameters\": false,\n },\n \"include\": [\".\", \"../src\"]\n}"
|
|
4
6
|
};
|