@better-auth/cli 1.3.5-beta.3 → 1.3.5-beta.5
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/dist/index.mjs +43 -21
- package/package.json +2 -2
package/dist/index.mjs
CHANGED
|
@@ -588,11 +588,17 @@ const generatePrismaSchema = async ({
|
|
|
588
588
|
for (const field in fields) {
|
|
589
589
|
const attr = fields[field];
|
|
590
590
|
if (attr.references) {
|
|
591
|
-
const
|
|
592
|
-
|
|
593
|
-
|
|
591
|
+
const referencedOriginalModel = attr.references.model;
|
|
592
|
+
const referencedCustomModel = tables[referencedOriginalModel]?.modelName || referencedOriginalModel;
|
|
593
|
+
const referencedModelNameCap = capitalizeFirstLetter(
|
|
594
|
+
referencedCustomModel
|
|
595
|
+
);
|
|
596
|
+
if (!manyToManyRelations.has(referencedModelNameCap)) {
|
|
597
|
+
manyToManyRelations.set(referencedModelNameCap, /* @__PURE__ */ new Set());
|
|
594
598
|
}
|
|
595
|
-
|
|
599
|
+
const currentCustomModel = tables[table]?.modelName || table;
|
|
600
|
+
const currentModelNameCap = capitalizeFirstLetter(currentCustomModel);
|
|
601
|
+
manyToManyRelations.get(referencedModelNameCap).add(currentModelNameCap);
|
|
596
602
|
}
|
|
597
603
|
}
|
|
598
604
|
}
|
|
@@ -625,9 +631,10 @@ const generatePrismaSchema = async ({
|
|
|
625
631
|
return isOptional ? "Int[]" : "Int[]";
|
|
626
632
|
}
|
|
627
633
|
};
|
|
634
|
+
const originalTableName = table;
|
|
635
|
+
const customModelName = tables[table]?.modelName || table;
|
|
636
|
+
const modelName = capitalizeFirstLetter(customModelName);
|
|
628
637
|
const fields = tables[table]?.fields;
|
|
629
|
-
const originalTable = tables[table]?.modelName;
|
|
630
|
-
const modelName = capitalizeFirstLetter(originalTable || "");
|
|
631
638
|
const prismaModel = builder.findByType("model", {
|
|
632
639
|
name: modelName
|
|
633
640
|
});
|
|
@@ -644,17 +651,18 @@ const generatePrismaSchema = async ({
|
|
|
644
651
|
}
|
|
645
652
|
for (const field in fields) {
|
|
646
653
|
const attr = fields[field];
|
|
654
|
+
const fieldName = attr.fieldName || field;
|
|
647
655
|
if (prismaModel) {
|
|
648
656
|
const isAlreadyExist = builder.findByType("field", {
|
|
649
|
-
name:
|
|
657
|
+
name: fieldName,
|
|
650
658
|
within: prismaModel.properties
|
|
651
659
|
});
|
|
652
660
|
if (isAlreadyExist) {
|
|
653
661
|
continue;
|
|
654
662
|
}
|
|
655
663
|
}
|
|
656
|
-
builder.model(modelName).field(
|
|
657
|
-
|
|
664
|
+
const fieldBuilder = builder.model(modelName).field(
|
|
665
|
+
fieldName,
|
|
658
666
|
field === "id" && options.advanced?.database?.useNumberId ? getType({
|
|
659
667
|
isBigint: false,
|
|
660
668
|
isOptional: false,
|
|
@@ -665,10 +673,20 @@ const generatePrismaSchema = async ({
|
|
|
665
673
|
type: attr.references?.field === "id" ? options.advanced?.database?.useNumberId ? "number" : "string" : attr.type
|
|
666
674
|
})
|
|
667
675
|
);
|
|
676
|
+
if (field === "id") {
|
|
677
|
+
fieldBuilder.attribute("id");
|
|
678
|
+
if (provider === "mongodb") {
|
|
679
|
+
fieldBuilder.attribute(`map("_id")`);
|
|
680
|
+
}
|
|
681
|
+
} else if (fieldName !== field) {
|
|
682
|
+
fieldBuilder.attribute(`map("${field}")`);
|
|
683
|
+
}
|
|
668
684
|
if (attr.unique) {
|
|
669
|
-
builder.model(modelName).blockAttribute(`unique([${
|
|
685
|
+
builder.model(modelName).blockAttribute(`unique([${fieldName}])`);
|
|
670
686
|
}
|
|
671
687
|
if (attr.references) {
|
|
688
|
+
const referencedOriginalModelName = attr.references.model;
|
|
689
|
+
const referencedCustomModelName = tables[referencedOriginalModelName]?.modelName || referencedOriginalModelName;
|
|
672
690
|
let action = "Cascade";
|
|
673
691
|
if (attr.references.onDelete === "no action") action = "NoAction";
|
|
674
692
|
else if (attr.references.onDelete === "set null") action = "SetNull";
|
|
@@ -676,14 +694,14 @@ const generatePrismaSchema = async ({
|
|
|
676
694
|
action = "SetDefault";
|
|
677
695
|
else if (attr.references.onDelete === "restrict") action = "Restrict";
|
|
678
696
|
builder.model(modelName).field(
|
|
679
|
-
`${
|
|
680
|
-
capitalizeFirstLetter(
|
|
697
|
+
`${referencedCustomModelName.toLowerCase()}`,
|
|
698
|
+
capitalizeFirstLetter(referencedCustomModelName)
|
|
681
699
|
).attribute(
|
|
682
|
-
`relation(fields: [${
|
|
700
|
+
`relation(fields: [${fieldName}], references: [${attr.references.field}], onDelete: ${action})`
|
|
683
701
|
);
|
|
684
702
|
}
|
|
685
703
|
if (!attr.unique && !attr.references && provider === "mysql" && attr.type === "string") {
|
|
686
|
-
builder.model(modelName).field(
|
|
704
|
+
builder.model(modelName).field(fieldName).attribute("db.Text");
|
|
687
705
|
}
|
|
688
706
|
}
|
|
689
707
|
if (manyToManyRelations.has(modelName)) {
|
|
@@ -702,15 +720,20 @@ const generatePrismaSchema = async ({
|
|
|
702
720
|
name: "map",
|
|
703
721
|
within: prismaModel?.properties
|
|
704
722
|
});
|
|
705
|
-
|
|
706
|
-
|
|
723
|
+
const hasChanged = customModelName !== originalTableName;
|
|
724
|
+
if (!hasAttribute) {
|
|
725
|
+
builder.model(modelName).blockAttribute(
|
|
726
|
+
"map",
|
|
727
|
+
`${hasChanged ? customModelName : originalTableName}`
|
|
728
|
+
);
|
|
707
729
|
}
|
|
708
730
|
}
|
|
709
731
|
});
|
|
732
|
+
const schemaChanged = schema.trim() !== schemaPrisma.trim();
|
|
710
733
|
return {
|
|
711
|
-
code:
|
|
734
|
+
code: schemaChanged ? schema : "",
|
|
712
735
|
fileName: filePath,
|
|
713
|
-
overwrite:
|
|
736
|
+
overwrite: schemaPrismaExist && schemaChanged
|
|
714
737
|
};
|
|
715
738
|
};
|
|
716
739
|
const getNewPrisma = (provider) => `generator client {
|
|
@@ -757,7 +780,6 @@ const generateSchema = (opts) => {
|
|
|
757
780
|
);
|
|
758
781
|
process.exit(1);
|
|
759
782
|
};
|
|
760
|
-
const getGenerator = generateSchema;
|
|
761
783
|
|
|
762
784
|
async function generateAction(opts) {
|
|
763
785
|
const options = z.object({
|
|
@@ -787,7 +809,7 @@ async function generateAction(opts) {
|
|
|
787
809
|
process.exit(1);
|
|
788
810
|
});
|
|
789
811
|
const spinner = yoctoSpinner({ text: "preparing schema..." }).start();
|
|
790
|
-
const schema = await
|
|
812
|
+
const schema = await generateSchema({
|
|
791
813
|
adapter,
|
|
792
814
|
file: options.output,
|
|
793
815
|
options: config
|
|
@@ -797,7 +819,7 @@ async function generateAction(opts) {
|
|
|
797
819
|
logger.info("Your schema is already up to date.");
|
|
798
820
|
process.exit(0);
|
|
799
821
|
}
|
|
800
|
-
if (schema.
|
|
822
|
+
if (schema.overwrite) {
|
|
801
823
|
let confirm2 = options.y || options.yes;
|
|
802
824
|
if (!confirm2) {
|
|
803
825
|
const response = await prompts({
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@better-auth/cli",
|
|
3
|
-
"version": "1.3.5-beta.
|
|
3
|
+
"version": "1.3.5-beta.5",
|
|
4
4
|
"description": "The CLI for Better Auth",
|
|
5
5
|
"module": "dist/index.mjs",
|
|
6
6
|
"repository": {
|
|
@@ -55,7 +55,7 @@
|
|
|
55
55
|
"semver": "^7.7.1",
|
|
56
56
|
"tinyexec": "^0.3.1",
|
|
57
57
|
"yocto-spinner": "^0.1.1",
|
|
58
|
-
"better-auth": "1.3.5-beta.
|
|
58
|
+
"better-auth": "1.3.5-beta.5"
|
|
59
59
|
},
|
|
60
60
|
"peerDependencies": {
|
|
61
61
|
"zod": "3.25.0 || ^4.0.0"
|