prisma-laravel-migrate 3.1.19 → 3.1.21
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/cli/cli.js +23 -16
- package/dist/cli/migrator.index.js +2 -3
- package/dist/cli/models.index.js +21 -14
- package/dist/cli/ts.index.js +15 -11
- package/dist/index.js +23 -16
- package/package.json +1 -1
package/dist/cli/cli.js
CHANGED
|
@@ -1102,11 +1102,10 @@ async function writeWithMerge(filePath, theirs, type, overwrite = true, currentP
|
|
|
1102
1102
|
const readPath = currentPath ?? filePath;
|
|
1103
1103
|
if (!overwrite && existsSync(filePath)) return;
|
|
1104
1104
|
const doFormat = (code) => {
|
|
1105
|
-
const
|
|
1106
|
-
const typeCfg = globalCfg ?? {};
|
|
1105
|
+
const typeCfg = getConfig(type);
|
|
1107
1106
|
const usePrettier = !!typeCfg.prettier;
|
|
1108
1107
|
if (!usePrettier || !code) return code;
|
|
1109
|
-
const parser =
|
|
1108
|
+
const parser = type == "typescript" ? "typescript" : "php";
|
|
1110
1109
|
return prettify(code, {
|
|
1111
1110
|
parser,
|
|
1112
1111
|
filepathHint: filePath
|
|
@@ -1691,6 +1690,11 @@ function deriveMethodName(modelName, kind) {
|
|
|
1691
1690
|
|
|
1692
1691
|
// src/generator/lib/relationship/index.ts
|
|
1693
1692
|
var pivotOtherEndpointFor = (thisModelName, candidate) => {
|
|
1693
|
+
if (candidate.documentation?.includes("@entity")) {
|
|
1694
|
+
const entities = listFrom(candidate.documentation ?? "", "@entity");
|
|
1695
|
+
if (entities.length > 0) return void 0;
|
|
1696
|
+
if (entities.includes(thisModelName)) return void 0;
|
|
1697
|
+
}
|
|
1694
1698
|
const rels = objRels(candidate).filter(
|
|
1695
1699
|
(r) => (r.relationFromFields?.length ?? 0) > 0
|
|
1696
1700
|
);
|
|
@@ -1810,7 +1814,7 @@ function buildRelationsForModel(dmmf, model) {
|
|
|
1810
1814
|
}
|
|
1811
1815
|
const rawChain = chainParts.length ? chainParts.join("->") : "";
|
|
1812
1816
|
defs.push({
|
|
1813
|
-
name: f.name.replace(/Id$/, ""),
|
|
1817
|
+
name: (f.dbName ?? f.name).replace(/Id$/, ""),
|
|
1814
1818
|
type: "belongsToMany",
|
|
1815
1819
|
mode: "explicit",
|
|
1816
1820
|
modelClass: `${keys.target}::class`,
|
|
@@ -1828,7 +1832,7 @@ function buildRelationsForModel(dmmf, model) {
|
|
|
1828
1832
|
});
|
|
1829
1833
|
} else if (keys.kind === "belongsToMany" && keys.mode === "implicit") {
|
|
1830
1834
|
defs.push({
|
|
1831
|
-
name: f.name.replace(/Id$/, ""),
|
|
1835
|
+
name: (f.dbName ?? f.name).replace(/Id$/, ""),
|
|
1832
1836
|
type: "belongsToMany",
|
|
1833
1837
|
mode: "implicit",
|
|
1834
1838
|
modelClass: `${keys.target}::class`,
|
|
@@ -1848,7 +1852,7 @@ function buildRelationsForModel(dmmf, model) {
|
|
|
1848
1852
|
const otherOwnsFK = (counterpart?.relationFromFields?.length ?? 0) > 0;
|
|
1849
1853
|
if (thisOwnsFK) {
|
|
1850
1854
|
defs.push({
|
|
1851
|
-
name: f.name.replace(/Id$/, ""),
|
|
1855
|
+
name: (f.dbName ?? f.name).replace(/Id$/, ""),
|
|
1852
1856
|
type: "belongsTo",
|
|
1853
1857
|
modelClass: `${f.type}::class`,
|
|
1854
1858
|
foreignKey: f.relationFromFields ?? [],
|
|
@@ -1861,7 +1865,7 @@ function buildRelationsForModel(dmmf, model) {
|
|
|
1861
1865
|
counterpart ? isUniqueOn(related, counterpart.relationFromFields ?? []) : false;
|
|
1862
1866
|
if (otherOwnsFK && counterpartIsSingle) {
|
|
1863
1867
|
defs.push({
|
|
1864
|
-
name: f.name.replace(/Id$/, ""),
|
|
1868
|
+
name: (f.dbName ?? f.name).replace(/Id$/, ""),
|
|
1865
1869
|
type: "hasOne",
|
|
1866
1870
|
modelClass: `${f.type}::class`,
|
|
1867
1871
|
foreignKey: counterpart.relationFromFields ?? [],
|
|
@@ -1872,7 +1876,7 @@ function buildRelationsForModel(dmmf, model) {
|
|
|
1872
1876
|
}
|
|
1873
1877
|
if (otherOwnsFK) {
|
|
1874
1878
|
defs.push({
|
|
1875
|
-
name: f.name.replace(/Id$/, ""),
|
|
1879
|
+
name: (f.dbName ?? f.name).replace(/Id$/, ""),
|
|
1876
1880
|
type: "hasMany",
|
|
1877
1881
|
modelClass: `${f.type}::class`,
|
|
1878
1882
|
foreignKey: counterpart.relationFromFields ?? [],
|
|
@@ -1946,9 +1950,10 @@ var PrismaToLaravelModelGenerator = class {
|
|
|
1946
1950
|
}
|
|
1947
1951
|
primitiveTypes = [PrismaTypes.BigInt, PrismaTypes.Int, PrismaTypes.String, PrismaTypes.Boolean, PrismaTypes.Bool];
|
|
1948
1952
|
generateAll() {
|
|
1953
|
+
const { namespace: baseNamespace, modelNamespace, enumNamespace } = getConfig("model") ?? {};
|
|
1949
1954
|
const enums = this.dmmf.datamodel.enums.map((e) => ({
|
|
1950
1955
|
name: e.name,
|
|
1951
|
-
namespace:
|
|
1956
|
+
namespace: enumNamespace ?? baseNamespace ?? "App",
|
|
1952
1957
|
// filled in by printer
|
|
1953
1958
|
values: e.values.map((v) => v.name)
|
|
1954
1959
|
}));
|
|
@@ -1986,7 +1991,7 @@ var PrismaToLaravelModelGenerator = class {
|
|
|
1986
1991
|
phpType = phpType.split("\\").pop();
|
|
1987
1992
|
}
|
|
1988
1993
|
return {
|
|
1989
|
-
name: field.name,
|
|
1994
|
+
name: field.dbName ?? field.name,
|
|
1990
1995
|
phpType,
|
|
1991
1996
|
fillable,
|
|
1992
1997
|
hidden,
|
|
@@ -2065,13 +2070,13 @@ var PrismaToLaravelModelGenerator = class {
|
|
|
2065
2070
|
const type = rel.type === "hasMany" || rel.type === "belongsToMany" ? `\\Illuminate\\Support\\Collection<int, ${rel.modelClass}>` : rel.modelClass;
|
|
2066
2071
|
docblockProps.push(`@property ${type} $${rel.name}`);
|
|
2067
2072
|
}
|
|
2073
|
+
const namespace = modelNamespace ?? baseNamespace ?? "App";
|
|
2068
2074
|
return {
|
|
2069
2075
|
className: model.name,
|
|
2070
2076
|
tableName: model.dbName ?? model.name,
|
|
2071
2077
|
guarded,
|
|
2072
2078
|
properties,
|
|
2073
|
-
namespace
|
|
2074
|
-
// filled in by printer
|
|
2079
|
+
namespace,
|
|
2075
2080
|
relations,
|
|
2076
2081
|
enums,
|
|
2077
2082
|
interfaces,
|
|
@@ -2288,7 +2293,9 @@ async function generateLaravelModels(options) {
|
|
|
2288
2293
|
modelStubPath: pick("modelStubPath"),
|
|
2289
2294
|
noEmit: pick("noEmit", false),
|
|
2290
2295
|
allowedPivotExtraFields: pick("allowedPivotExtraFields", []),
|
|
2291
|
-
namespace: pick("namespace", "App")
|
|
2296
|
+
namespace: pick("namespace", "App"),
|
|
2297
|
+
modelNamespace: pick("modelNamespace"),
|
|
2298
|
+
enumNamespace: pick("enumNamespace")
|
|
2292
2299
|
};
|
|
2293
2300
|
addToConfig("model", cfg);
|
|
2294
2301
|
const modelsDir = cfg.outputDir ? path13.resolve(process.cwd(), cfg.outputDir) : path13.resolve(process.cwd(), getOutDir2(generator));
|
|
@@ -3270,7 +3277,7 @@ async function generateTypesFromPrisma(options) {
|
|
|
3270
3277
|
await writeWithMerge(
|
|
3271
3278
|
enumsPath,
|
|
3272
3279
|
enumsCode,
|
|
3273
|
-
"
|
|
3280
|
+
"typescript",
|
|
3274
3281
|
cfg.overwriteExisting
|
|
3275
3282
|
);
|
|
3276
3283
|
}
|
|
@@ -3293,7 +3300,7 @@ async function generateTypesFromPrisma(options) {
|
|
|
3293
3300
|
await writeWithMerge(
|
|
3294
3301
|
mainPath,
|
|
3295
3302
|
mainFile,
|
|
3296
|
-
"
|
|
3303
|
+
"typescript",
|
|
3297
3304
|
cfg.overwriteExisting
|
|
3298
3305
|
);
|
|
3299
3306
|
}
|
|
@@ -3308,7 +3315,7 @@ async function generateTypesFromPrisma(options) {
|
|
|
3308
3315
|
await writeWithMerge(
|
|
3309
3316
|
filePath,
|
|
3310
3317
|
code,
|
|
3311
|
-
"
|
|
3318
|
+
"typescript",
|
|
3312
3319
|
cfg.overwriteExisting
|
|
3313
3320
|
);
|
|
3314
3321
|
});
|
|
@@ -1013,11 +1013,10 @@ async function writeWithMerge(filePath, theirs, type, overwrite = true, currentP
|
|
|
1013
1013
|
const readPath = currentPath ?? filePath;
|
|
1014
1014
|
if (!overwrite && existsSync(filePath)) return;
|
|
1015
1015
|
const doFormat = (code) => {
|
|
1016
|
-
const
|
|
1017
|
-
const typeCfg = globalCfg ?? {};
|
|
1016
|
+
const typeCfg = getConfig(type);
|
|
1018
1017
|
const usePrettier = !!typeCfg.prettier;
|
|
1019
1018
|
if (!usePrettier || !code) return code;
|
|
1020
|
-
const parser =
|
|
1019
|
+
const parser = "php";
|
|
1021
1020
|
return prettify(code, {
|
|
1022
1021
|
parser,
|
|
1023
1022
|
filepathHint: filePath
|
package/dist/cli/models.index.js
CHANGED
|
@@ -84,7 +84,7 @@ function addToConfig(key, value) {
|
|
|
84
84
|
function getConfig(key, property) {
|
|
85
85
|
const cfg = config;
|
|
86
86
|
const section = cfg[key];
|
|
87
|
-
return
|
|
87
|
+
return section;
|
|
88
88
|
}
|
|
89
89
|
var isForModel = (t) => (t & 1 /* Model */) !== 0;
|
|
90
90
|
function parseTargetDirective(tag, doc, defaultFlags = 1 /* Model */) {
|
|
@@ -531,6 +531,11 @@ function deriveMethodName(modelName, kind) {
|
|
|
531
531
|
|
|
532
532
|
// src/generator/lib/relationship/index.ts
|
|
533
533
|
var pivotOtherEndpointFor = (thisModelName, candidate) => {
|
|
534
|
+
if (candidate.documentation?.includes("@entity")) {
|
|
535
|
+
const entities = listFrom(candidate.documentation ?? "", "@entity");
|
|
536
|
+
if (entities.length > 0) return void 0;
|
|
537
|
+
if (entities.includes(thisModelName)) return void 0;
|
|
538
|
+
}
|
|
534
539
|
const rels = objRels(candidate).filter(
|
|
535
540
|
(r) => (r.relationFromFields?.length ?? 0) > 0
|
|
536
541
|
);
|
|
@@ -650,7 +655,7 @@ function buildRelationsForModel(dmmf, model) {
|
|
|
650
655
|
}
|
|
651
656
|
const rawChain = chainParts.length ? chainParts.join("->") : "";
|
|
652
657
|
defs.push({
|
|
653
|
-
name: f.name.replace(/Id$/, ""),
|
|
658
|
+
name: (f.dbName ?? f.name).replace(/Id$/, ""),
|
|
654
659
|
type: "belongsToMany",
|
|
655
660
|
mode: "explicit",
|
|
656
661
|
modelClass: `${keys.target}::class`,
|
|
@@ -668,7 +673,7 @@ function buildRelationsForModel(dmmf, model) {
|
|
|
668
673
|
});
|
|
669
674
|
} else if (keys.kind === "belongsToMany" && keys.mode === "implicit") {
|
|
670
675
|
defs.push({
|
|
671
|
-
name: f.name.replace(/Id$/, ""),
|
|
676
|
+
name: (f.dbName ?? f.name).replace(/Id$/, ""),
|
|
672
677
|
type: "belongsToMany",
|
|
673
678
|
mode: "implicit",
|
|
674
679
|
modelClass: `${keys.target}::class`,
|
|
@@ -688,7 +693,7 @@ function buildRelationsForModel(dmmf, model) {
|
|
|
688
693
|
const otherOwnsFK = (counterpart?.relationFromFields?.length ?? 0) > 0;
|
|
689
694
|
if (thisOwnsFK) {
|
|
690
695
|
defs.push({
|
|
691
|
-
name: f.name.replace(/Id$/, ""),
|
|
696
|
+
name: (f.dbName ?? f.name).replace(/Id$/, ""),
|
|
692
697
|
type: "belongsTo",
|
|
693
698
|
modelClass: `${f.type}::class`,
|
|
694
699
|
foreignKey: f.relationFromFields ?? [],
|
|
@@ -701,7 +706,7 @@ function buildRelationsForModel(dmmf, model) {
|
|
|
701
706
|
counterpart ? isUniqueOn(related, counterpart.relationFromFields ?? []) : false;
|
|
702
707
|
if (otherOwnsFK && counterpartIsSingle) {
|
|
703
708
|
defs.push({
|
|
704
|
-
name: f.name.replace(/Id$/, ""),
|
|
709
|
+
name: (f.dbName ?? f.name).replace(/Id$/, ""),
|
|
705
710
|
type: "hasOne",
|
|
706
711
|
modelClass: `${f.type}::class`,
|
|
707
712
|
foreignKey: counterpart.relationFromFields ?? [],
|
|
@@ -712,7 +717,7 @@ function buildRelationsForModel(dmmf, model) {
|
|
|
712
717
|
}
|
|
713
718
|
if (otherOwnsFK) {
|
|
714
719
|
defs.push({
|
|
715
|
-
name: f.name.replace(/Id$/, ""),
|
|
720
|
+
name: (f.dbName ?? f.name).replace(/Id$/, ""),
|
|
716
721
|
type: "hasMany",
|
|
717
722
|
modelClass: `${f.type}::class`,
|
|
718
723
|
foreignKey: counterpart.relationFromFields ?? [],
|
|
@@ -767,9 +772,10 @@ var PrismaToLaravelModelGenerator = class {
|
|
|
767
772
|
}
|
|
768
773
|
primitiveTypes = [PrismaTypes.BigInt, PrismaTypes.Int, PrismaTypes.String, PrismaTypes.Boolean, PrismaTypes.Bool];
|
|
769
774
|
generateAll() {
|
|
775
|
+
const { namespace: baseNamespace, modelNamespace, enumNamespace } = getConfig("model") ?? {};
|
|
770
776
|
const enums = this.dmmf.datamodel.enums.map((e) => ({
|
|
771
777
|
name: e.name,
|
|
772
|
-
namespace:
|
|
778
|
+
namespace: enumNamespace ?? baseNamespace ?? "App",
|
|
773
779
|
// filled in by printer
|
|
774
780
|
values: e.values.map((v) => v.name)
|
|
775
781
|
}));
|
|
@@ -807,7 +813,7 @@ var PrismaToLaravelModelGenerator = class {
|
|
|
807
813
|
phpType = phpType.split("\\").pop();
|
|
808
814
|
}
|
|
809
815
|
return {
|
|
810
|
-
name: field.name,
|
|
816
|
+
name: field.dbName ?? field.name,
|
|
811
817
|
phpType,
|
|
812
818
|
fillable,
|
|
813
819
|
hidden,
|
|
@@ -886,13 +892,13 @@ var PrismaToLaravelModelGenerator = class {
|
|
|
886
892
|
const type = rel.type === "hasMany" || rel.type === "belongsToMany" ? `\\Illuminate\\Support\\Collection<int, ${rel.modelClass}>` : rel.modelClass;
|
|
887
893
|
docblockProps.push(`@property ${type} $${rel.name}`);
|
|
888
894
|
}
|
|
895
|
+
const namespace = modelNamespace ?? baseNamespace ?? "App";
|
|
889
896
|
return {
|
|
890
897
|
className: model.name,
|
|
891
898
|
tableName: model.dbName ?? model.name,
|
|
892
899
|
guarded,
|
|
893
900
|
properties,
|
|
894
|
-
namespace
|
|
895
|
-
// filled in by printer
|
|
901
|
+
namespace,
|
|
896
902
|
relations,
|
|
897
903
|
enums,
|
|
898
904
|
interfaces,
|
|
@@ -1047,11 +1053,10 @@ async function writeWithMerge(filePath, theirs, type, overwrite = true, currentP
|
|
|
1047
1053
|
const readPath = filePath;
|
|
1048
1054
|
if (!overwrite && existsSync(filePath)) return;
|
|
1049
1055
|
const doFormat = (code) => {
|
|
1050
|
-
const
|
|
1051
|
-
const typeCfg = globalCfg ?? {};
|
|
1056
|
+
const typeCfg = getConfig(type);
|
|
1052
1057
|
const usePrettier = !!typeCfg.prettier;
|
|
1053
1058
|
if (!usePrettier || !code) return code;
|
|
1054
|
-
const parser =
|
|
1059
|
+
const parser = "php";
|
|
1055
1060
|
return prettify(code, {
|
|
1056
1061
|
parser,
|
|
1057
1062
|
filepathHint: filePath
|
|
@@ -1294,7 +1299,9 @@ async function generateLaravelModels(options) {
|
|
|
1294
1299
|
modelStubPath: pick("modelStubPath"),
|
|
1295
1300
|
noEmit: pick("noEmit", false),
|
|
1296
1301
|
allowedPivotExtraFields: pick("allowedPivotExtraFields", []),
|
|
1297
|
-
namespace: pick("namespace", "App")
|
|
1302
|
+
namespace: pick("namespace", "App"),
|
|
1303
|
+
modelNamespace: pick("modelNamespace"),
|
|
1304
|
+
enumNamespace: pick("enumNamespace")
|
|
1298
1305
|
};
|
|
1299
1306
|
addToConfig("model", cfg);
|
|
1300
1307
|
const modelsDir = cfg.outputDir ? path7.resolve(process.cwd(), cfg.outputDir) : path7.resolve(process.cwd(), getOutDir(generator));
|
package/dist/cli/ts.index.js
CHANGED
|
@@ -479,6 +479,11 @@ function deriveMethodName(modelName, kind) {
|
|
|
479
479
|
|
|
480
480
|
// src/generator/lib/relationship/index.ts
|
|
481
481
|
var pivotOtherEndpointFor = (thisModelName, candidate) => {
|
|
482
|
+
if (candidate.documentation?.includes("@entity")) {
|
|
483
|
+
const entities = listFrom(candidate.documentation ?? "", "@entity");
|
|
484
|
+
if (entities.length > 0) return void 0;
|
|
485
|
+
if (entities.includes(thisModelName)) return void 0;
|
|
486
|
+
}
|
|
482
487
|
const rels = objRels(candidate).filter(
|
|
483
488
|
(r) => (r.relationFromFields?.length ?? 0) > 0
|
|
484
489
|
);
|
|
@@ -598,7 +603,7 @@ function buildRelationsForModel(dmmf, model) {
|
|
|
598
603
|
}
|
|
599
604
|
const rawChain = chainParts.length ? chainParts.join("->") : "";
|
|
600
605
|
defs.push({
|
|
601
|
-
name: f.name.replace(/Id$/, ""),
|
|
606
|
+
name: (f.dbName ?? f.name).replace(/Id$/, ""),
|
|
602
607
|
type: "belongsToMany",
|
|
603
608
|
mode: "explicit",
|
|
604
609
|
modelClass: `${keys.target}::class`,
|
|
@@ -616,7 +621,7 @@ function buildRelationsForModel(dmmf, model) {
|
|
|
616
621
|
});
|
|
617
622
|
} else if (keys.kind === "belongsToMany" && keys.mode === "implicit") {
|
|
618
623
|
defs.push({
|
|
619
|
-
name: f.name.replace(/Id$/, ""),
|
|
624
|
+
name: (f.dbName ?? f.name).replace(/Id$/, ""),
|
|
620
625
|
type: "belongsToMany",
|
|
621
626
|
mode: "implicit",
|
|
622
627
|
modelClass: `${keys.target}::class`,
|
|
@@ -636,7 +641,7 @@ function buildRelationsForModel(dmmf, model) {
|
|
|
636
641
|
const otherOwnsFK = (counterpart?.relationFromFields?.length ?? 0) > 0;
|
|
637
642
|
if (thisOwnsFK) {
|
|
638
643
|
defs.push({
|
|
639
|
-
name: f.name.replace(/Id$/, ""),
|
|
644
|
+
name: (f.dbName ?? f.name).replace(/Id$/, ""),
|
|
640
645
|
type: "belongsTo",
|
|
641
646
|
modelClass: `${f.type}::class`,
|
|
642
647
|
foreignKey: f.relationFromFields ?? [],
|
|
@@ -649,7 +654,7 @@ function buildRelationsForModel(dmmf, model) {
|
|
|
649
654
|
counterpart ? isUniqueOn(related, counterpart.relationFromFields ?? []) : false;
|
|
650
655
|
if (otherOwnsFK && counterpartIsSingle) {
|
|
651
656
|
defs.push({
|
|
652
|
-
name: f.name.replace(/Id$/, ""),
|
|
657
|
+
name: (f.dbName ?? f.name).replace(/Id$/, ""),
|
|
653
658
|
type: "hasOne",
|
|
654
659
|
modelClass: `${f.type}::class`,
|
|
655
660
|
foreignKey: counterpart.relationFromFields ?? [],
|
|
@@ -660,7 +665,7 @@ function buildRelationsForModel(dmmf, model) {
|
|
|
660
665
|
}
|
|
661
666
|
if (otherOwnsFK) {
|
|
662
667
|
defs.push({
|
|
663
|
-
name: f.name.replace(/Id$/, ""),
|
|
668
|
+
name: (f.dbName ?? f.name).replace(/Id$/, ""),
|
|
664
669
|
type: "hasMany",
|
|
665
670
|
modelClass: `${f.type}::class`,
|
|
666
671
|
foreignKey: counterpart.relationFromFields ?? [],
|
|
@@ -1541,11 +1546,10 @@ async function writeWithMerge(filePath, theirs, type, overwrite = true, currentP
|
|
|
1541
1546
|
const readPath = filePath;
|
|
1542
1547
|
if (!overwrite && existsSync(filePath)) return;
|
|
1543
1548
|
const doFormat = (code) => {
|
|
1544
|
-
const
|
|
1545
|
-
const typeCfg = globalCfg ?? {};
|
|
1549
|
+
const typeCfg = getConfig(type);
|
|
1546
1550
|
const usePrettier = !!typeCfg.prettier;
|
|
1547
1551
|
if (!usePrettier || !code) return code;
|
|
1548
|
-
const parser =
|
|
1552
|
+
const parser = "typescript" ;
|
|
1549
1553
|
return prettify(code, {
|
|
1550
1554
|
parser,
|
|
1551
1555
|
filepathHint: filePath
|
|
@@ -1724,7 +1728,7 @@ async function generateTypesFromPrisma(options) {
|
|
|
1724
1728
|
await writeWithMerge(
|
|
1725
1729
|
enumsPath,
|
|
1726
1730
|
enumsCode,
|
|
1727
|
-
"
|
|
1731
|
+
"typescript",
|
|
1728
1732
|
cfg.overwriteExisting
|
|
1729
1733
|
);
|
|
1730
1734
|
}
|
|
@@ -1747,7 +1751,7 @@ async function generateTypesFromPrisma(options) {
|
|
|
1747
1751
|
await writeWithMerge(
|
|
1748
1752
|
mainPath,
|
|
1749
1753
|
mainFile,
|
|
1750
|
-
"
|
|
1754
|
+
"typescript",
|
|
1751
1755
|
cfg.overwriteExisting
|
|
1752
1756
|
);
|
|
1753
1757
|
}
|
|
@@ -1762,7 +1766,7 @@ async function generateTypesFromPrisma(options) {
|
|
|
1762
1766
|
await writeWithMerge(
|
|
1763
1767
|
filePath,
|
|
1764
1768
|
code,
|
|
1765
|
-
"
|
|
1769
|
+
"typescript",
|
|
1766
1770
|
cfg.overwriteExisting
|
|
1767
1771
|
);
|
|
1768
1772
|
});
|
package/dist/index.js
CHANGED
|
@@ -1166,11 +1166,10 @@ async function writeWithMerge(filePath, theirs, type, overwrite = true, currentP
|
|
|
1166
1166
|
const readPath = currentPath ?? filePath;
|
|
1167
1167
|
if (!overwrite && existsSync(filePath)) return;
|
|
1168
1168
|
const doFormat = (code) => {
|
|
1169
|
-
const
|
|
1170
|
-
const typeCfg = globalCfg ?? {};
|
|
1169
|
+
const typeCfg = getConfig(type);
|
|
1171
1170
|
const usePrettier = !!typeCfg.prettier;
|
|
1172
1171
|
if (!usePrettier || !code) return code;
|
|
1173
|
-
const parser =
|
|
1172
|
+
const parser = type == "typescript" ? "typescript" : "php";
|
|
1174
1173
|
return prettify(code, {
|
|
1175
1174
|
parser,
|
|
1176
1175
|
filepathHint: filePath
|
|
@@ -1751,6 +1750,11 @@ function deriveMethodName(modelName, kind) {
|
|
|
1751
1750
|
|
|
1752
1751
|
// src/generator/lib/relationship/index.ts
|
|
1753
1752
|
var pivotOtherEndpointFor = (thisModelName, candidate) => {
|
|
1753
|
+
if (candidate.documentation?.includes("@entity")) {
|
|
1754
|
+
const entities = listFrom(candidate.documentation ?? "", "@entity");
|
|
1755
|
+
if (entities.length > 0) return void 0;
|
|
1756
|
+
if (entities.includes(thisModelName)) return void 0;
|
|
1757
|
+
}
|
|
1754
1758
|
const rels = objRels(candidate).filter(
|
|
1755
1759
|
(r) => (r.relationFromFields?.length ?? 0) > 0
|
|
1756
1760
|
);
|
|
@@ -1870,7 +1874,7 @@ function buildRelationsForModel(dmmf, model) {
|
|
|
1870
1874
|
}
|
|
1871
1875
|
const rawChain = chainParts.length ? chainParts.join("->") : "";
|
|
1872
1876
|
defs.push({
|
|
1873
|
-
name: f.name.replace(/Id$/, ""),
|
|
1877
|
+
name: (f.dbName ?? f.name).replace(/Id$/, ""),
|
|
1874
1878
|
type: "belongsToMany",
|
|
1875
1879
|
mode: "explicit",
|
|
1876
1880
|
modelClass: `${keys.target}::class`,
|
|
@@ -1888,7 +1892,7 @@ function buildRelationsForModel(dmmf, model) {
|
|
|
1888
1892
|
});
|
|
1889
1893
|
} else if (keys.kind === "belongsToMany" && keys.mode === "implicit") {
|
|
1890
1894
|
defs.push({
|
|
1891
|
-
name: f.name.replace(/Id$/, ""),
|
|
1895
|
+
name: (f.dbName ?? f.name).replace(/Id$/, ""),
|
|
1892
1896
|
type: "belongsToMany",
|
|
1893
1897
|
mode: "implicit",
|
|
1894
1898
|
modelClass: `${keys.target}::class`,
|
|
@@ -1908,7 +1912,7 @@ function buildRelationsForModel(dmmf, model) {
|
|
|
1908
1912
|
const otherOwnsFK = (counterpart?.relationFromFields?.length ?? 0) > 0;
|
|
1909
1913
|
if (thisOwnsFK) {
|
|
1910
1914
|
defs.push({
|
|
1911
|
-
name: f.name.replace(/Id$/, ""),
|
|
1915
|
+
name: (f.dbName ?? f.name).replace(/Id$/, ""),
|
|
1912
1916
|
type: "belongsTo",
|
|
1913
1917
|
modelClass: `${f.type}::class`,
|
|
1914
1918
|
foreignKey: f.relationFromFields ?? [],
|
|
@@ -1921,7 +1925,7 @@ function buildRelationsForModel(dmmf, model) {
|
|
|
1921
1925
|
counterpart ? isUniqueOn(related, counterpart.relationFromFields ?? []) : false;
|
|
1922
1926
|
if (otherOwnsFK && counterpartIsSingle) {
|
|
1923
1927
|
defs.push({
|
|
1924
|
-
name: f.name.replace(/Id$/, ""),
|
|
1928
|
+
name: (f.dbName ?? f.name).replace(/Id$/, ""),
|
|
1925
1929
|
type: "hasOne",
|
|
1926
1930
|
modelClass: `${f.type}::class`,
|
|
1927
1931
|
foreignKey: counterpart.relationFromFields ?? [],
|
|
@@ -1932,7 +1936,7 @@ function buildRelationsForModel(dmmf, model) {
|
|
|
1932
1936
|
}
|
|
1933
1937
|
if (otherOwnsFK) {
|
|
1934
1938
|
defs.push({
|
|
1935
|
-
name: f.name.replace(/Id$/, ""),
|
|
1939
|
+
name: (f.dbName ?? f.name).replace(/Id$/, ""),
|
|
1936
1940
|
type: "hasMany",
|
|
1937
1941
|
modelClass: `${f.type}::class`,
|
|
1938
1942
|
foreignKey: counterpart.relationFromFields ?? [],
|
|
@@ -2006,9 +2010,10 @@ var PrismaToLaravelModelGenerator = class {
|
|
|
2006
2010
|
}
|
|
2007
2011
|
primitiveTypes = [PrismaTypes.BigInt, PrismaTypes.Int, PrismaTypes.String, PrismaTypes.Boolean, PrismaTypes.Bool];
|
|
2008
2012
|
generateAll() {
|
|
2013
|
+
const { namespace: baseNamespace, modelNamespace, enumNamespace } = getConfig("model") ?? {};
|
|
2009
2014
|
const enums = this.dmmf.datamodel.enums.map((e) => ({
|
|
2010
2015
|
name: e.name,
|
|
2011
|
-
namespace:
|
|
2016
|
+
namespace: enumNamespace ?? baseNamespace ?? "App",
|
|
2012
2017
|
// filled in by printer
|
|
2013
2018
|
values: e.values.map((v) => v.name)
|
|
2014
2019
|
}));
|
|
@@ -2046,7 +2051,7 @@ var PrismaToLaravelModelGenerator = class {
|
|
|
2046
2051
|
phpType = phpType.split("\\").pop();
|
|
2047
2052
|
}
|
|
2048
2053
|
return {
|
|
2049
|
-
name: field.name,
|
|
2054
|
+
name: field.dbName ?? field.name,
|
|
2050
2055
|
phpType,
|
|
2051
2056
|
fillable,
|
|
2052
2057
|
hidden,
|
|
@@ -2125,13 +2130,13 @@ var PrismaToLaravelModelGenerator = class {
|
|
|
2125
2130
|
const type = rel.type === "hasMany" || rel.type === "belongsToMany" ? `\\Illuminate\\Support\\Collection<int, ${rel.modelClass}>` : rel.modelClass;
|
|
2126
2131
|
docblockProps.push(`@property ${type} $${rel.name}`);
|
|
2127
2132
|
}
|
|
2133
|
+
const namespace = modelNamespace ?? baseNamespace ?? "App";
|
|
2128
2134
|
return {
|
|
2129
2135
|
className: model.name,
|
|
2130
2136
|
tableName: model.dbName ?? model.name,
|
|
2131
2137
|
guarded,
|
|
2132
2138
|
properties,
|
|
2133
|
-
namespace
|
|
2134
|
-
// filled in by printer
|
|
2139
|
+
namespace,
|
|
2135
2140
|
relations,
|
|
2136
2141
|
enums,
|
|
2137
2142
|
interfaces,
|
|
@@ -2283,7 +2288,9 @@ async function generateLaravelModels(options) {
|
|
|
2283
2288
|
modelStubPath: pick("modelStubPath"),
|
|
2284
2289
|
noEmit: pick("noEmit", false),
|
|
2285
2290
|
allowedPivotExtraFields: pick("allowedPivotExtraFields", []),
|
|
2286
|
-
namespace: pick("namespace", "App")
|
|
2291
|
+
namespace: pick("namespace", "App"),
|
|
2292
|
+
modelNamespace: pick("modelNamespace"),
|
|
2293
|
+
enumNamespace: pick("enumNamespace")
|
|
2287
2294
|
};
|
|
2288
2295
|
addToConfig("model", cfg);
|
|
2289
2296
|
const modelsDir = cfg.outputDir ? path9.resolve(process.cwd(), cfg.outputDir) : path9.resolve(process.cwd(), getOutDir2(generator));
|
|
@@ -3265,7 +3272,7 @@ async function generateTypesFromPrisma(options) {
|
|
|
3265
3272
|
await writeWithMerge(
|
|
3266
3273
|
enumsPath,
|
|
3267
3274
|
enumsCode,
|
|
3268
|
-
"
|
|
3275
|
+
"typescript",
|
|
3269
3276
|
cfg.overwriteExisting
|
|
3270
3277
|
);
|
|
3271
3278
|
}
|
|
@@ -3288,7 +3295,7 @@ async function generateTypesFromPrisma(options) {
|
|
|
3288
3295
|
await writeWithMerge(
|
|
3289
3296
|
mainPath,
|
|
3290
3297
|
mainFile,
|
|
3291
|
-
"
|
|
3298
|
+
"typescript",
|
|
3292
3299
|
cfg.overwriteExisting
|
|
3293
3300
|
);
|
|
3294
3301
|
}
|
|
@@ -3303,7 +3310,7 @@ async function generateTypesFromPrisma(options) {
|
|
|
3303
3310
|
await writeWithMerge(
|
|
3304
3311
|
filePath,
|
|
3305
3312
|
code,
|
|
3306
|
-
"
|
|
3313
|
+
"typescript",
|
|
3307
3314
|
cfg.overwriteExisting
|
|
3308
3315
|
);
|
|
3309
3316
|
});
|