prisma-laravel-migrate 3.1.20 → 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 CHANGED
@@ -1690,6 +1690,11 @@ function deriveMethodName(modelName, kind) {
1690
1690
 
1691
1691
  // src/generator/lib/relationship/index.ts
1692
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
+ }
1693
1698
  const rels = objRels(candidate).filter(
1694
1699
  (r) => (r.relationFromFields?.length ?? 0) > 0
1695
1700
  );
@@ -1809,7 +1814,7 @@ function buildRelationsForModel(dmmf, model) {
1809
1814
  }
1810
1815
  const rawChain = chainParts.length ? chainParts.join("->") : "";
1811
1816
  defs.push({
1812
- name: f.name.replace(/Id$/, ""),
1817
+ name: (f.dbName ?? f.name).replace(/Id$/, ""),
1813
1818
  type: "belongsToMany",
1814
1819
  mode: "explicit",
1815
1820
  modelClass: `${keys.target}::class`,
@@ -1827,7 +1832,7 @@ function buildRelationsForModel(dmmf, model) {
1827
1832
  });
1828
1833
  } else if (keys.kind === "belongsToMany" && keys.mode === "implicit") {
1829
1834
  defs.push({
1830
- name: f.name.replace(/Id$/, ""),
1835
+ name: (f.dbName ?? f.name).replace(/Id$/, ""),
1831
1836
  type: "belongsToMany",
1832
1837
  mode: "implicit",
1833
1838
  modelClass: `${keys.target}::class`,
@@ -1847,7 +1852,7 @@ function buildRelationsForModel(dmmf, model) {
1847
1852
  const otherOwnsFK = (counterpart?.relationFromFields?.length ?? 0) > 0;
1848
1853
  if (thisOwnsFK) {
1849
1854
  defs.push({
1850
- name: f.name.replace(/Id$/, ""),
1855
+ name: (f.dbName ?? f.name).replace(/Id$/, ""),
1851
1856
  type: "belongsTo",
1852
1857
  modelClass: `${f.type}::class`,
1853
1858
  foreignKey: f.relationFromFields ?? [],
@@ -1860,7 +1865,7 @@ function buildRelationsForModel(dmmf, model) {
1860
1865
  counterpart ? isUniqueOn(related, counterpart.relationFromFields ?? []) : false;
1861
1866
  if (otherOwnsFK && counterpartIsSingle) {
1862
1867
  defs.push({
1863
- name: f.name.replace(/Id$/, ""),
1868
+ name: (f.dbName ?? f.name).replace(/Id$/, ""),
1864
1869
  type: "hasOne",
1865
1870
  modelClass: `${f.type}::class`,
1866
1871
  foreignKey: counterpart.relationFromFields ?? [],
@@ -1871,7 +1876,7 @@ function buildRelationsForModel(dmmf, model) {
1871
1876
  }
1872
1877
  if (otherOwnsFK) {
1873
1878
  defs.push({
1874
- name: f.name.replace(/Id$/, ""),
1879
+ name: (f.dbName ?? f.name).replace(/Id$/, ""),
1875
1880
  type: "hasMany",
1876
1881
  modelClass: `${f.type}::class`,
1877
1882
  foreignKey: counterpart.relationFromFields ?? [],
@@ -1945,9 +1950,10 @@ var PrismaToLaravelModelGenerator = class {
1945
1950
  }
1946
1951
  primitiveTypes = [PrismaTypes.BigInt, PrismaTypes.Int, PrismaTypes.String, PrismaTypes.Boolean, PrismaTypes.Bool];
1947
1952
  generateAll() {
1953
+ const { namespace: baseNamespace, modelNamespace, enumNamespace } = getConfig("model") ?? {};
1948
1954
  const enums = this.dmmf.datamodel.enums.map((e) => ({
1949
1955
  name: e.name,
1950
- namespace: getConfig("model")?.namespace ?? "App",
1956
+ namespace: enumNamespace ?? baseNamespace ?? "App",
1951
1957
  // filled in by printer
1952
1958
  values: e.values.map((v) => v.name)
1953
1959
  }));
@@ -1985,7 +1991,7 @@ var PrismaToLaravelModelGenerator = class {
1985
1991
  phpType = phpType.split("\\").pop();
1986
1992
  }
1987
1993
  return {
1988
- name: field.name,
1994
+ name: field.dbName ?? field.name,
1989
1995
  phpType,
1990
1996
  fillable,
1991
1997
  hidden,
@@ -2064,13 +2070,13 @@ var PrismaToLaravelModelGenerator = class {
2064
2070
  const type = rel.type === "hasMany" || rel.type === "belongsToMany" ? `\\Illuminate\\Support\\Collection<int, ${rel.modelClass}>` : rel.modelClass;
2065
2071
  docblockProps.push(`@property ${type} $${rel.name}`);
2066
2072
  }
2073
+ const namespace = modelNamespace ?? baseNamespace ?? "App";
2067
2074
  return {
2068
2075
  className: model.name,
2069
2076
  tableName: model.dbName ?? model.name,
2070
2077
  guarded,
2071
2078
  properties,
2072
- namespace: getConfig("model")?.namespace ?? "App",
2073
- // filled in by printer
2079
+ namespace,
2074
2080
  relations,
2075
2081
  enums,
2076
2082
  interfaces,
@@ -2287,7 +2293,9 @@ async function generateLaravelModels(options) {
2287
2293
  modelStubPath: pick("modelStubPath"),
2288
2294
  noEmit: pick("noEmit", false),
2289
2295
  allowedPivotExtraFields: pick("allowedPivotExtraFields", []),
2290
- namespace: pick("namespace", "App")
2296
+ namespace: pick("namespace", "App"),
2297
+ modelNamespace: pick("modelNamespace"),
2298
+ enumNamespace: pick("enumNamespace")
2291
2299
  };
2292
2300
  addToConfig("model", cfg);
2293
2301
  const modelsDir = cfg.outputDir ? path13.resolve(process.cwd(), cfg.outputDir) : path13.resolve(process.cwd(), getOutDir2(generator));
@@ -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 property ? section?.[property] : section;
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: getConfig("model")?.namespace ?? "App",
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: getConfig("model")?.namespace ?? "App",
895
- // filled in by printer
901
+ namespace,
896
902
  relations,
897
903
  enums,
898
904
  interfaces,
@@ -1293,7 +1299,9 @@ async function generateLaravelModels(options) {
1293
1299
  modelStubPath: pick("modelStubPath"),
1294
1300
  noEmit: pick("noEmit", false),
1295
1301
  allowedPivotExtraFields: pick("allowedPivotExtraFields", []),
1296
- namespace: pick("namespace", "App")
1302
+ namespace: pick("namespace", "App"),
1303
+ modelNamespace: pick("modelNamespace"),
1304
+ enumNamespace: pick("enumNamespace")
1297
1305
  };
1298
1306
  addToConfig("model", cfg);
1299
1307
  const modelsDir = cfg.outputDir ? path7.resolve(process.cwd(), cfg.outputDir) : path7.resolve(process.cwd(), getOutDir(generator));
@@ -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 ?? [],
package/dist/index.js CHANGED
@@ -1750,6 +1750,11 @@ function deriveMethodName(modelName, kind) {
1750
1750
 
1751
1751
  // src/generator/lib/relationship/index.ts
1752
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
+ }
1753
1758
  const rels = objRels(candidate).filter(
1754
1759
  (r) => (r.relationFromFields?.length ?? 0) > 0
1755
1760
  );
@@ -1869,7 +1874,7 @@ function buildRelationsForModel(dmmf, model) {
1869
1874
  }
1870
1875
  const rawChain = chainParts.length ? chainParts.join("->") : "";
1871
1876
  defs.push({
1872
- name: f.name.replace(/Id$/, ""),
1877
+ name: (f.dbName ?? f.name).replace(/Id$/, ""),
1873
1878
  type: "belongsToMany",
1874
1879
  mode: "explicit",
1875
1880
  modelClass: `${keys.target}::class`,
@@ -1887,7 +1892,7 @@ function buildRelationsForModel(dmmf, model) {
1887
1892
  });
1888
1893
  } else if (keys.kind === "belongsToMany" && keys.mode === "implicit") {
1889
1894
  defs.push({
1890
- name: f.name.replace(/Id$/, ""),
1895
+ name: (f.dbName ?? f.name).replace(/Id$/, ""),
1891
1896
  type: "belongsToMany",
1892
1897
  mode: "implicit",
1893
1898
  modelClass: `${keys.target}::class`,
@@ -1907,7 +1912,7 @@ function buildRelationsForModel(dmmf, model) {
1907
1912
  const otherOwnsFK = (counterpart?.relationFromFields?.length ?? 0) > 0;
1908
1913
  if (thisOwnsFK) {
1909
1914
  defs.push({
1910
- name: f.name.replace(/Id$/, ""),
1915
+ name: (f.dbName ?? f.name).replace(/Id$/, ""),
1911
1916
  type: "belongsTo",
1912
1917
  modelClass: `${f.type}::class`,
1913
1918
  foreignKey: f.relationFromFields ?? [],
@@ -1920,7 +1925,7 @@ function buildRelationsForModel(dmmf, model) {
1920
1925
  counterpart ? isUniqueOn(related, counterpart.relationFromFields ?? []) : false;
1921
1926
  if (otherOwnsFK && counterpartIsSingle) {
1922
1927
  defs.push({
1923
- name: f.name.replace(/Id$/, ""),
1928
+ name: (f.dbName ?? f.name).replace(/Id$/, ""),
1924
1929
  type: "hasOne",
1925
1930
  modelClass: `${f.type}::class`,
1926
1931
  foreignKey: counterpart.relationFromFields ?? [],
@@ -1931,7 +1936,7 @@ function buildRelationsForModel(dmmf, model) {
1931
1936
  }
1932
1937
  if (otherOwnsFK) {
1933
1938
  defs.push({
1934
- name: f.name.replace(/Id$/, ""),
1939
+ name: (f.dbName ?? f.name).replace(/Id$/, ""),
1935
1940
  type: "hasMany",
1936
1941
  modelClass: `${f.type}::class`,
1937
1942
  foreignKey: counterpart.relationFromFields ?? [],
@@ -2005,9 +2010,10 @@ var PrismaToLaravelModelGenerator = class {
2005
2010
  }
2006
2011
  primitiveTypes = [PrismaTypes.BigInt, PrismaTypes.Int, PrismaTypes.String, PrismaTypes.Boolean, PrismaTypes.Bool];
2007
2012
  generateAll() {
2013
+ const { namespace: baseNamespace, modelNamespace, enumNamespace } = getConfig("model") ?? {};
2008
2014
  const enums = this.dmmf.datamodel.enums.map((e) => ({
2009
2015
  name: e.name,
2010
- namespace: getConfig("model")?.namespace ?? "App",
2016
+ namespace: enumNamespace ?? baseNamespace ?? "App",
2011
2017
  // filled in by printer
2012
2018
  values: e.values.map((v) => v.name)
2013
2019
  }));
@@ -2045,7 +2051,7 @@ var PrismaToLaravelModelGenerator = class {
2045
2051
  phpType = phpType.split("\\").pop();
2046
2052
  }
2047
2053
  return {
2048
- name: field.name,
2054
+ name: field.dbName ?? field.name,
2049
2055
  phpType,
2050
2056
  fillable,
2051
2057
  hidden,
@@ -2124,13 +2130,13 @@ var PrismaToLaravelModelGenerator = class {
2124
2130
  const type = rel.type === "hasMany" || rel.type === "belongsToMany" ? `\\Illuminate\\Support\\Collection<int, ${rel.modelClass}>` : rel.modelClass;
2125
2131
  docblockProps.push(`@property ${type} $${rel.name}`);
2126
2132
  }
2133
+ const namespace = modelNamespace ?? baseNamespace ?? "App";
2127
2134
  return {
2128
2135
  className: model.name,
2129
2136
  tableName: model.dbName ?? model.name,
2130
2137
  guarded,
2131
2138
  properties,
2132
- namespace: getConfig("model")?.namespace ?? "App",
2133
- // filled in by printer
2139
+ namespace,
2134
2140
  relations,
2135
2141
  enums,
2136
2142
  interfaces,
@@ -2282,7 +2288,9 @@ async function generateLaravelModels(options) {
2282
2288
  modelStubPath: pick("modelStubPath"),
2283
2289
  noEmit: pick("noEmit", false),
2284
2290
  allowedPivotExtraFields: pick("allowedPivotExtraFields", []),
2285
- namespace: pick("namespace", "App")
2291
+ namespace: pick("namespace", "App"),
2292
+ modelNamespace: pick("modelNamespace"),
2293
+ enumNamespace: pick("enumNamespace")
2286
2294
  };
2287
2295
  addToConfig("model", cfg);
2288
2296
  const modelsDir = cfg.outputDir ? path9.resolve(process.cwd(), cfg.outputDir) : path9.resolve(process.cwd(), getOutDir2(generator));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "prisma-laravel-migrate",
3
- "version": "3.1.20",
3
+ "version": "3.1.21",
4
4
  "description": "Generate laravel migrations and/or models using prisma files",
5
5
  "bin": {
6
6
  "prisma-laravel-migrations": "./dist/cli/migrator.index.js",