prisma-laravel-migrate 3.1.7 → 3.1.8
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/.idea/modules.xml +8 -0
- package/.idea/prisma-to-laravel-migration.iml +8 -0
- package/.idea/vcs.xml +6 -0
- package/dist/cli/cli.js +60 -14
- package/dist/cli/models.index.js +4 -5
- package/dist/cli/ts.index.js +527 -9
- package/dist/index.js +60 -14
- package/package.json +1 -1
- package/prodex/index-trace_251215-1156.md +1366 -0
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
|
2
|
+
<project version="4">
|
|
3
|
+
<component name="ProjectModuleManager">
|
|
4
|
+
<modules>
|
|
5
|
+
<module fileurl="file://$PROJECT_DIR$/.idea/prisma-to-laravel-migration.iml" filepath="$PROJECT_DIR$/.idea/prisma-to-laravel-migration.iml" />
|
|
6
|
+
</modules>
|
|
7
|
+
</component>
|
|
8
|
+
</project>
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
|
2
|
+
<module type="WEB_MODULE" version="4">
|
|
3
|
+
<component name="NewModuleRootManager">
|
|
4
|
+
<content url="file://$MODULE_DIR$" />
|
|
5
|
+
<orderEntry type="inheritedJdk" />
|
|
6
|
+
<orderEntry type="sourceFolder" forTests="false" />
|
|
7
|
+
</component>
|
|
8
|
+
</module>
|
package/.idea/vcs.xml
ADDED
package/dist/cli/cli.js
CHANGED
|
@@ -1301,7 +1301,7 @@ function formatLaravelTimestamp(date, seq, width) {
|
|
|
1301
1301
|
return base + suffix;
|
|
1302
1302
|
}
|
|
1303
1303
|
|
|
1304
|
-
// src/generator/
|
|
1304
|
+
// src/generator/lib/relationship/template-builder.ts
|
|
1305
1305
|
var asArrayPhp = (xs) => `[${xs.map((x) => `'${x}'`).join(", ")}]`;
|
|
1306
1306
|
var firstOrUndef = (xs) => xs && xs.length ? `'${xs[0]}'` : void 0;
|
|
1307
1307
|
function relationTemplate(def, opts = {}) {
|
|
@@ -1442,7 +1442,7 @@ var StubModelPrinter = class {
|
|
|
1442
1442
|
}
|
|
1443
1443
|
};
|
|
1444
1444
|
|
|
1445
|
-
// src/generator/
|
|
1445
|
+
// src/generator/lib/relationship/types.ts
|
|
1446
1446
|
var getModel = (dmmf, name) => dmmf.datamodel.models.find((m) => m.name === name);
|
|
1447
1447
|
var dbNameOf = (m) => m.dbName ?? m.name;
|
|
1448
1448
|
var conventionalPivotName = (a, b) => [a, b].map((s) => s.toLowerCase()).sort().join("_");
|
|
@@ -1479,7 +1479,7 @@ var isUniqueOn = (m, fields) => {
|
|
|
1479
1479
|
return uniques.some((set) => setsEqual(set.slice().sort(), sorted));
|
|
1480
1480
|
};
|
|
1481
1481
|
|
|
1482
|
-
// src/generator/
|
|
1482
|
+
// src/generator/lib/relationship/morph.ts
|
|
1483
1483
|
var MORPH_DEFAULTS = {
|
|
1484
1484
|
idSuffix: "_id",
|
|
1485
1485
|
typeSuffix: "_type"
|
|
@@ -1689,7 +1689,7 @@ function deriveMethodName(modelName, kind) {
|
|
|
1689
1689
|
return kind === "morphOne" ? base : base.endsWith("s") ? base : base + "s";
|
|
1690
1690
|
}
|
|
1691
1691
|
|
|
1692
|
-
// src/generator/
|
|
1692
|
+
// src/generator/lib/relationship/index.ts
|
|
1693
1693
|
var pivotOtherEndpointFor = (thisModelName, candidate) => {
|
|
1694
1694
|
const rels = objRels(candidate).filter(
|
|
1695
1695
|
(r) => (r.relationFromFields?.length ?? 0) > 0
|
|
@@ -1879,7 +1879,6 @@ function buildRelationsForModel(dmmf, model) {
|
|
|
1879
1879
|
localKey: counterpart.relationToFields ?? [],
|
|
1880
1880
|
targetModelName: f.type
|
|
1881
1881
|
});
|
|
1882
|
-
continue;
|
|
1883
1882
|
}
|
|
1884
1883
|
}
|
|
1885
1884
|
const detectedMorphTo = detectMorphToRelations(model);
|
|
@@ -2407,7 +2406,60 @@ var PrismaToTypesGenerator = class {
|
|
|
2407
2406
|
const hiddenFromModel = new Set(
|
|
2408
2407
|
listFrom(model.documentation ?? "", "hidden").map((n) => n.trim()).filter(Boolean)
|
|
2409
2408
|
);
|
|
2410
|
-
const
|
|
2409
|
+
const relationships = buildRelationsForModel(this.dmmf, model).map((rel) => {
|
|
2410
|
+
const isMany = rel.type === "hasMany" || rel.type === "belongsToMany" || rel.type === "morphMany" || rel.type === "morphToMany" || rel.type === "morphedByMany";
|
|
2411
|
+
const readonlyArrays = !!this.cfg.readonlyArrays;
|
|
2412
|
+
const wrapList = (base) => isMany ? readonlyArrays ? `ReadonlyArray<${base}>` : `${base}[]` : base;
|
|
2413
|
+
let tsType;
|
|
2414
|
+
if (rel.type === "morphTo") {
|
|
2415
|
+
tsType = "any";
|
|
2416
|
+
} else {
|
|
2417
|
+
const target = rel.targetModelName ?? "any";
|
|
2418
|
+
if (rel.pivotColumns) {
|
|
2419
|
+
const pivotCols = rel.pivotColumns;
|
|
2420
|
+
const pivotTable = rel.pivotTable;
|
|
2421
|
+
const pivotModel = pivotTable ? this.dmmf.datamodel.models.find(
|
|
2422
|
+
(m) => (m.dbName ?? m.name) === pivotTable
|
|
2423
|
+
) : void 0;
|
|
2424
|
+
const pivotProps = [];
|
|
2425
|
+
for (const col of pivotCols) {
|
|
2426
|
+
let colTs = "any";
|
|
2427
|
+
const f = pivotModel?.fields.find((pf) => pf.name === col);
|
|
2428
|
+
if (f && f.kind !== "object" && f.kind !== "enum") {
|
|
2429
|
+
colTs = this.mapPrismaTypeToTs(f);
|
|
2430
|
+
} else if (f && f.kind === "enum") {
|
|
2431
|
+
colTs = this.mapPrismaTypeToTs(f);
|
|
2432
|
+
enumNames.add(f.type);
|
|
2433
|
+
}
|
|
2434
|
+
const propName = /^[a-zA-Z_][a-zA-Z0-9_]*$/.test(col) ? col : JSON.stringify(col);
|
|
2435
|
+
pivotProps.push(`${propName}: ${colTs}`);
|
|
2436
|
+
}
|
|
2437
|
+
const pivotShape = pivotProps.length ? `{ ${pivotProps.join("; ")} }` : "{}";
|
|
2438
|
+
const elementType = `${target} & ${pivotShape}`;
|
|
2439
|
+
tsType = wrapList(elementType);
|
|
2440
|
+
} else {
|
|
2441
|
+
tsType = wrapList(target);
|
|
2442
|
+
}
|
|
2443
|
+
}
|
|
2444
|
+
let optional = true;
|
|
2445
|
+
if (containsWith(rel.name)) {
|
|
2446
|
+
optional = false;
|
|
2447
|
+
} else {
|
|
2448
|
+
const objField = model.fields.find(
|
|
2449
|
+
(f) => f.kind === "object" && (f.name === rel.name || f.name.replace(/Id$/, "") === rel.name)
|
|
2450
|
+
);
|
|
2451
|
+
if (objField && this.hasWithDirective(objField)) {
|
|
2452
|
+
optional = false;
|
|
2453
|
+
}
|
|
2454
|
+
}
|
|
2455
|
+
return {
|
|
2456
|
+
name: rel.name,
|
|
2457
|
+
type: tsType,
|
|
2458
|
+
optional,
|
|
2459
|
+
isList: isMany
|
|
2460
|
+
};
|
|
2461
|
+
});
|
|
2462
|
+
const fields = model.fields.filter((item) => item.kind !== "object").map((field) => {
|
|
2411
2463
|
const doc = field.documentation ?? "";
|
|
2412
2464
|
let tsType = this.mapPrismaTypeToTs(field);
|
|
2413
2465
|
const typeDirective = getFieldTypeDirective(field);
|
|
@@ -2423,8 +2475,6 @@ var PrismaToTypesGenerator = class {
|
|
|
2423
2475
|
enumNames.add(field.type);
|
|
2424
2476
|
}
|
|
2425
2477
|
}
|
|
2426
|
-
const isRelation = field.kind === "object";
|
|
2427
|
-
const hasWith = isRelation && (this.hasWithDirective(field) || containsWith(field.name));
|
|
2428
2478
|
const hiddenInline = /(^|\s)@hidden(\b|[{(])/m.test(doc) || listFrom(doc, "hidden").includes(field.name);
|
|
2429
2479
|
const hiddenByModel = hiddenFromModel.has(field.name);
|
|
2430
2480
|
const isHidden = hiddenInline || hiddenByModel;
|
|
@@ -2434,7 +2484,7 @@ var PrismaToTypesGenerator = class {
|
|
|
2434
2484
|
// Relations: optional by default (navigation props),
|
|
2435
2485
|
// unless @with says "this is always loaded".
|
|
2436
2486
|
// Non-relations: keep Prisma's required flag semantics.
|
|
2437
|
-
optional:
|
|
2487
|
+
optional: !field.isRequired,
|
|
2438
2488
|
isList: field.isList,
|
|
2439
2489
|
isId: field.isId,
|
|
2440
2490
|
isGenerated: !!field.isGenerated,
|
|
@@ -2487,7 +2537,7 @@ var PrismaToTypesGenerator = class {
|
|
|
2487
2537
|
);
|
|
2488
2538
|
return {
|
|
2489
2539
|
name: model.name,
|
|
2490
|
-
fields,
|
|
2540
|
+
fields: [...fields, ...relationships],
|
|
2491
2541
|
appends,
|
|
2492
2542
|
imports,
|
|
2493
2543
|
// strip directives from doc so TS header comment stays clean
|
|
@@ -2533,10 +2583,6 @@ var PrismaToTypesGenerator = class {
|
|
|
2533
2583
|
if (field.kind === "enum") {
|
|
2534
2584
|
return wrapList(field.type);
|
|
2535
2585
|
}
|
|
2536
|
-
if (field.kind === "object") {
|
|
2537
|
-
const base = field.type;
|
|
2538
|
-
return wrapList(base);
|
|
2539
|
-
}
|
|
2540
2586
|
return wrapList("any");
|
|
2541
2587
|
}
|
|
2542
2588
|
};
|
package/dist/cli/models.index.js
CHANGED
|
@@ -141,7 +141,7 @@ function getStubPath(pathString, folder) {
|
|
|
141
141
|
return path7.join(baseDir, "stubs", normalised);
|
|
142
142
|
}
|
|
143
143
|
|
|
144
|
-
// src/generator/
|
|
144
|
+
// src/generator/lib/relationship/template-builder.ts
|
|
145
145
|
var asArrayPhp = (xs) => `[${xs.map((x) => `'${x}'`).join(", ")}]`;
|
|
146
146
|
var firstOrUndef = (xs) => xs && xs.length ? `'${xs[0]}'` : void 0;
|
|
147
147
|
function relationTemplate(def, opts = {}) {
|
|
@@ -282,7 +282,7 @@ var StubModelPrinter = class {
|
|
|
282
282
|
}
|
|
283
283
|
};
|
|
284
284
|
|
|
285
|
-
// src/generator/
|
|
285
|
+
// src/generator/lib/relationship/types.ts
|
|
286
286
|
var getModel = (dmmf, name) => dmmf.datamodel.models.find((m) => m.name === name);
|
|
287
287
|
var dbNameOf = (m) => m.dbName ?? m.name;
|
|
288
288
|
var conventionalPivotName = (a, b) => [a, b].map((s) => s.toLowerCase()).sort().join("_");
|
|
@@ -319,7 +319,7 @@ var isUniqueOn = (m, fields) => {
|
|
|
319
319
|
return uniques.some((set) => setsEqual(set.slice().sort(), sorted));
|
|
320
320
|
};
|
|
321
321
|
|
|
322
|
-
// src/generator/
|
|
322
|
+
// src/generator/lib/relationship/morph.ts
|
|
323
323
|
var MORPH_DEFAULTS = {
|
|
324
324
|
idSuffix: "_id",
|
|
325
325
|
typeSuffix: "_type"
|
|
@@ -529,7 +529,7 @@ function deriveMethodName(modelName, kind) {
|
|
|
529
529
|
return kind === "morphOne" ? base : base.endsWith("s") ? base : base + "s";
|
|
530
530
|
}
|
|
531
531
|
|
|
532
|
-
// src/generator/
|
|
532
|
+
// src/generator/lib/relationship/index.ts
|
|
533
533
|
var pivotOtherEndpointFor = (thisModelName, candidate) => {
|
|
534
534
|
const rels = objRels(candidate).filter(
|
|
535
535
|
(r) => (r.relationFromFields?.length ?? 0) > 0
|
|
@@ -719,7 +719,6 @@ function buildRelationsForModel(dmmf, model) {
|
|
|
719
719
|
localKey: counterpart.relationToFields ?? [],
|
|
720
720
|
targetModelName: f.type
|
|
721
721
|
});
|
|
722
|
-
continue;
|
|
723
722
|
}
|
|
724
723
|
}
|
|
725
724
|
const detectedMorphTo = detectMorphToRelations(model);
|