@prisma/orm-family-sql 8.0.0-rc.16-dev.3 → 8.0.0-rc.16-dev.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.
Files changed (87) hide show
  1. package/dist/{ast-B_UPqRyb.mjs → ast-DUU5OVjo.mjs} +2 -2
  2. package/dist/{ast-B_UPqRyb.mjs.map → ast-DUU5OVjo.mjs.map} +1 -1
  3. package/dist/{authored-check-naming-BjIs43HD.mjs → authored-check-naming-BBdhHujS.mjs} +3 -3
  4. package/dist/{authored-check-naming-BjIs43HD.mjs.map → authored-check-naming-BBdhHujS.mjs.map} +1 -1
  5. package/dist/{authoring-type-constructors-dihiQslc-B5nYi7p2.mjs → authoring-type-constructors-dihiQslc-S4oVeeaO.mjs} +2 -2
  6. package/dist/{authoring-type-constructors-dihiQslc-B5nYi7p2.mjs.map → authoring-type-constructors-dihiQslc-S4oVeeaO.mjs.map} +1 -1
  7. package/dist/builder__runtime.mjs +2 -2
  8. package/dist/{codec-descriptor-registry-DoGFktu5.mjs → codec-descriptor-registry-D7bl9ayf.mjs} +2 -2
  9. package/dist/{codec-descriptor-registry-DoGFktu5.mjs.map → codec-descriptor-registry-D7bl9ayf.mjs.map} +1 -1
  10. package/dist/{config-types-BMRDvgSW.mjs → config-types-C-fKlHmB.mjs} +2 -2
  11. package/dist/{config-types-BMRDvgSW.mjs.map → config-types-C-fKlHmB.mjs.map} +1 -1
  12. package/dist/{contract-builder-83EIkQrg.mjs → contract-builder-BxkBHQir.mjs} +4 -4
  13. package/dist/{contract-builder-83EIkQrg.mjs.map → contract-builder-BxkBHQir.mjs.map} +1 -1
  14. package/dist/contract-emitter.mjs +1 -1
  15. package/dist/contract-prisma7__provider.d.mts +5 -0
  16. package/dist/contract-prisma7__provider.d.mts.map +1 -1
  17. package/dist/contract-prisma7__provider.mjs +206 -133
  18. package/dist/contract-prisma7__provider.mjs.map +1 -1
  19. package/dist/contract-psl.mjs +1 -1
  20. package/dist/contract-psl__attribute-specs.mjs +1 -1
  21. package/dist/contract-psl__provider.mjs +2 -2
  22. package/dist/contract-ts.mjs +3 -3
  23. package/dist/contract-ts__config-types.mjs +1 -1
  24. package/dist/contract-ts__contract-builder.mjs +2 -2
  25. package/dist/contract.mjs +9 -9
  26. package/dist/contract__authored-check-naming.mjs +1 -1
  27. package/dist/contract__entity-kinds.mjs +1 -1
  28. package/dist/contract__factories.mjs +1 -1
  29. package/dist/contract__foreign-key-materialization.mjs +1 -1
  30. package/dist/contract__index-naming.mjs +1 -1
  31. package/dist/contract__types.mjs +3 -3
  32. package/dist/contract__validators.mjs +2 -2
  33. package/dist/{control-ihau09EM.mjs → control-0kB6FkCn.mjs} +11 -11
  34. package/dist/{control-ihau09EM.mjs.map → control-0kB6FkCn.mjs.map} +1 -1
  35. package/dist/{derived-checks-DAbro9yn-BgBbql-q.mjs → derived-checks-DAbro9yn-BNuE2QEm.mjs} +10 -10
  36. package/dist/{derived-checks-DAbro9yn-BgBbql-q.mjs.map → derived-checks-DAbro9yn-BNuE2QEm.mjs.map} +1 -1
  37. package/dist/{dist-ljGeuCdK.mjs → dist-7hmkNQGd.mjs} +2 -2
  38. package/dist/{dist-ljGeuCdK.mjs.map → dist-7hmkNQGd.mjs.map} +1 -1
  39. package/dist/{entity-kinds-JlqzyFoo-BR7NtlZL.mjs → entity-kinds-JlqzyFoo-kIaAUFyK.mjs} +3 -3
  40. package/dist/{entity-kinds-JlqzyFoo-BR7NtlZL.mjs.map → entity-kinds-JlqzyFoo-kIaAUFyK.mjs.map} +1 -1
  41. package/dist/{factories-WPleYaty.mjs → factories-BsUyFxsk.mjs} +3 -3
  42. package/dist/{factories-WPleYaty.mjs.map → factories-BsUyFxsk.mjs.map} +1 -1
  43. package/dist/family.mjs +6 -6
  44. package/dist/family__control.mjs +3 -3
  45. package/dist/family__diff.mjs +1 -1
  46. package/dist/family__ir.mjs +1 -1
  47. package/dist/family__pack.mjs +2 -2
  48. package/dist/family__psl-build.mjs +1 -1
  49. package/dist/family__psl-infer.mjs +1 -1
  50. package/dist/{foreign-key-materialization-uN1uuv25.mjs → foreign-key-materialization-IGfTKmHV.mjs} +3 -3
  51. package/dist/{foreign-key-materialization-uN1uuv25.mjs.map → foreign-key-materialization-IGfTKmHV.mjs.map} +1 -1
  52. package/dist/{index-naming-Cj1Anq-T-DgO8vEIL.mjs → index-naming-Cj1Anq-T-NX841eiU.mjs} +2 -2
  53. package/dist/{index-naming-Cj1Anq-T-DgO8vEIL.mjs.map → index-naming-Cj1Anq-T-NX841eiU.mjs.map} +1 -1
  54. package/dist/{interpreter-BF5Xrf3W-DK928Clg.mjs → interpreter-BF5Xrf3W-DOTOXsEr.mjs} +5 -5
  55. package/dist/{interpreter-BF5Xrf3W-DK928Clg.mjs.map → interpreter-BF5Xrf3W-DOTOXsEr.mjs.map} +1 -1
  56. package/dist/{naming-BLraiRfc-DKPaCL0a.mjs → naming-DkG_OegU-DpENNdZX.mjs} +5 -18
  57. package/dist/naming-DkG_OegU-DpENNdZX.mjs.map +1 -0
  58. package/dist/orm-client.mjs +2 -2
  59. package/dist/{psl-build-B_fRV6lN.mjs → psl-build-Di-cBOCv.mjs} +2 -2
  60. package/dist/{psl-build-B_fRV6lN.mjs.map → psl-build-Di-cBOCv.mjs.map} +1 -1
  61. package/dist/{psl-field-resolution-DUCrDnuq-BXwISml1.mjs → psl-field-resolution-DUCrDnuq-BYapcETh.mjs} +3 -3
  62. package/dist/{psl-field-resolution-DUCrDnuq-BXwISml1.mjs.map → psl-field-resolution-DUCrDnuq-BYapcETh.mjs.map} +1 -1
  63. package/dist/{psl-infer-BokOY1hK.mjs → psl-infer-fU7LRjTx.mjs} +2 -2
  64. package/dist/{psl-infer-BokOY1hK.mjs.map → psl-infer-fU7LRjTx.mjs.map} +1 -1
  65. package/dist/relational-core.mjs +1 -1
  66. package/dist/relational-core__ast.mjs +1 -1
  67. package/dist/relational-core__codec-descriptor-registry.mjs +1 -1
  68. package/dist/runtime.mjs +1 -1
  69. package/dist/schema-ir.mjs +1 -1
  70. package/dist/schema-ir__naming.mjs +1 -1
  71. package/dist/schema-ir__types.mjs +1 -1
  72. package/dist/{schema-verify-DIfHSB4I-BK55V2WO.mjs → schema-verify-DIfHSB4I-CjYnmUuD.mjs} +2 -2
  73. package/dist/{schema-verify-DIfHSB4I-BK55V2WO.mjs.map → schema-verify-DIfHSB4I-CjYnmUuD.mjs.map} +1 -1
  74. package/dist/{serialized-index-QAYy0fjm-BW4shnLC.mjs → serialized-index-QAYy0fjm-zxvK3RBa.mjs} +3 -3
  75. package/dist/{serialized-index-QAYy0fjm-BW4shnLC.mjs.map → serialized-index-QAYy0fjm-zxvK3RBa.mjs.map} +1 -1
  76. package/dist/{sql-contract-serializer-DDaAVCQr-D40NltYi.mjs → sql-contract-serializer-DDaAVCQr-CLDkZLXO.mjs} +4 -4
  77. package/dist/{sql-contract-serializer-DDaAVCQr-D40NltYi.mjs.map → sql-contract-serializer-DDaAVCQr-CLDkZLXO.mjs.map} +1 -1
  78. package/dist/{storage-table-CyL4CNMi-zOQ-vTUd.mjs → storage-table-CyL4CNMi-ByGZXmzd.mjs} +2 -2
  79. package/dist/{storage-table-CyL4CNMi-zOQ-vTUd.mjs.map → storage-table-CyL4CNMi-ByGZXmzd.mjs.map} +1 -1
  80. package/dist/{types-D_7dH1ie-CN5Dgmgh.mjs → types-Cz_bcUWN-CC3lFQOi.mjs} +3 -3
  81. package/dist/{types-D_7dH1ie-CN5Dgmgh.mjs.map → types-Cz_bcUWN-CC3lFQOi.mjs.map} +1 -1
  82. package/dist/{types-BlcZJEoC.mjs → types-DDHgx581.mjs} +2 -2
  83. package/dist/{types-BlcZJEoC.mjs.map → types-DDHgx581.mjs.map} +1 -1
  84. package/dist/{validators-Ddcw8nHL.mjs → validators-Xx-TKcx3.mjs} +3 -3
  85. package/dist/{validators-Ddcw8nHL.mjs.map → validators-Xx-TKcx3.mjs.map} +1 -1
  86. package/package.json +18 -18
  87. package/dist/naming-BLraiRfc-DKPaCL0a.mjs.map +0 -1
@@ -62,6 +62,11 @@ interface Prisma7TargetBinding {
62
62
  readonly indexTypes: Readonly<Record<string, string>>;
63
63
  /** The longest identifier the database keeps, in bytes. Prisma 7 cuts the names it generates to fit. */
64
64
  readonly identifierMaxBytes: number;
65
+ /** The names the target's migration planner gives a primary key or foreign key the contract leaves unnamed. */
66
+ readonly defaultConstraintNames: {
67
+ readonly primaryKey: (tableName: string) => string;
68
+ readonly foreignKey: (tableName: string, columns: readonly string[]) => string;
69
+ };
65
70
  /**
66
71
  * The relation field names `contract infer` gives a junction table whose
67
72
  * columns `A` and `B` reference `tableA` and `tableB`, so the junction model
@@ -1 +1 @@
1
- {"version":3,"file":"contract-prisma7__provider.d.mts","names":[],"sources":["../../../../2-sql/2-authoring/contract-prisma7/dist/provider.d.mts"],"mappings":";;;;;;;;;;;;UAUU;WACC;WACA;;UAED;;WAEC,SAAS,SAAS,eAAe;;;;;WAKjC,aAAa,SAAS,eAAe;;;;UAItC;WACC;;WAEA;WACA,aAAa,SAAS;;;KAG5B;;;WAGM;;;;WAIA;;WAEA,UAAU;;WAEV,OAAO;;;UAGR;WACC,QAAQ;WACR,kBAAkB,OAAO,sBAAsB;;WAE/C;;WAEA,SAAS;;WAET;aACE;aACA;;;WAGF,YAAY,SAAS;;WAErB;;;;;;WAMA,6BAA6B,gBAAgB;;WAE7C,uBAAuB;;WAEvB,qBAAqB,QAAQ,sBAAsB;;;;UAIpD;WACC,SAAS;WACT;WACA,uBAAuB;;iBAEjB,gBAAgB,oBAAoB,SAAS,yBAAyB"}
1
+ {"version":3,"file":"contract-prisma7__provider.d.mts","names":[],"sources":["../../../../2-sql/2-authoring/contract-prisma7/dist/provider.d.mts"],"mappings":";;;;;;;;;;;;UAUU;WACC;WACA;;UAED;;WAEC,SAAS,SAAS,eAAe;;;;;WAKjC,aAAa,SAAS,eAAe;;;;UAItC;WACC;;WAEA;WACA,aAAa,SAAS;;;KAG5B;;;WAGM;;;;WAIA;;WAEA,UAAU;;WAEV,OAAO;;;UAGR;WACC,QAAQ;WACR,kBAAkB,OAAO,sBAAsB;;WAE/C;;WAEA,SAAS;;WAET;aACE;aACA;;;WAGF,YAAY,SAAS;;WAErB;;WAEA;aACE,aAAa;aACb,aAAa,mBAAmB;;;;;;;WAOlC,6BAA6B,gBAAgB;;WAE7C,uBAAuB;;WAEvB,qBAAqB,QAAQ,sBAAsB;;;;UAIpD;WACC,SAAS;WACT;WACA,uBAAuB;;iBAEjB,gBAAgB,oBAAoB,SAAS,yBAAyB"}
@@ -1,17 +1,18 @@
1
1
  import { d as unquotedSqlBaseNameOfCodec, l as sqlDataTypeOfCodec } from "./data-type-CAPmGXg9.mjs";
2
- import { d as validateSqlStorageConsistency, l as validateModelStorageReferences } from "./validators-Ddcw8nHL.mjs";
2
+ import { d as validateSqlStorageConsistency, l as validateModelStorageReferences } from "./validators-Xx-TKcx3.mjs";
3
3
  import { t as deriveValueSetFromEntity } from "./value-set-derivation-hook-Di9JZ0X7.mjs";
4
- import { n as buildSqlContractFromDefinition, t as applySqlSpecifierControlPolicy } from "./derived-checks-DAbro9yn-BgBbql-q.mjs";
5
- import { _ as readDataTypeDefault, u as instantiateFieldTypeConstructor } from "./psl-field-resolution-DUCrDnuq-BXwISml1.mjs";
6
- import { a as normalizeReferentialAction, n as buildEntityTypesByDiscriminator, r as indexFkRelations, t as applyBackrelationCandidates } from "./interpreter-BF5Xrf3W-DK928Clg.mjs";
4
+ import { n as buildSqlContractFromDefinition, t as applySqlSpecifierControlPolicy } from "./derived-checks-DAbro9yn-BNuE2QEm.mjs";
5
+ import { _ as readDataTypeDefault, u as instantiateFieldTypeConstructor } from "./psl-field-resolution-DUCrDnuq-BYapcETh.mjs";
6
+ import { a as normalizeReferentialAction, n as buildEntityTypesByDiscriminator, r as indexFkRelations, t as applyBackrelationCandidates } from "./interpreter-BF5Xrf3W-DOTOXsEr.mjs";
7
7
  import { isStructuredError } from "@prisma/orm-framework/utils/structured-error";
8
8
  import { entryForTag, getAuthoringTypeConstructor, instantiateAuthoringEntityType } from "@prisma/orm-framework/components/authoring";
9
+ import { clipToUtf8Bytes, utf8ByteLength } from "@prisma/orm-framework/utils/text";
9
10
  import { blindCast } from "@prisma/orm-framework/utils/casts";
10
11
  import { ifDefined } from "@prisma/orm-framework/utils/defined";
11
12
  import { InternalError } from "@prisma/orm-framework/utils/internal-error";
12
13
  import { validateContractDomain } from "@prisma/orm-framework/contract/validate-domain";
13
14
  import { readFile, readdir, stat } from "node:fs/promises";
14
- import { ArrayLiteralAst, BooleanLiteralExprAst, FunctionCallAst, IdentifierAst, NumberLiteralExprAst, PathExprAst, StringLiteralExprAst, dottedPathsIn, parse, printSyntax } from "@prisma/orm-framework/psl-parser/syntax";
15
+ import { ArrayLiteralAst, BooleanLiteralExprAst, FunctionCallAst, IdentifierAst, ModelAttributeAst, NumberLiteralExprAst, PathExprAst, StringLiteralExprAst, dottedPathsIn, parse, printSyntax } from "@prisma/orm-framework/psl-parser/syntax";
15
16
  import { notOk, ok } from "@prisma/orm-framework/utils/result";
16
17
  import { basename, dirname, extname, join, normalize } from "pathe";
17
18
  import { buildSymbolTable, createPslDiagnosticCollector, diagnosticSource, keywordPslSpan, nodePslSpan, readResolvedAttribute, readResolvedAttributes } from "@prisma/orm-framework/psl-parser";
@@ -38,6 +39,118 @@ function ignoredFieldReferenced(input) {
38
39
  const one = input.fieldNames.length === 1;
39
40
  return prisma7Diagnostic("PSL.PRISMA7_IGNORED_FIELD_REFERENCED", `${one ? "Field" : "Fields"} ${fields} ${one ? "is" : "are"} marked @ignore, but ${input.usedBy} uses ${one ? "it" : "them"}, and Prisma 7 still creates the ${input.constraint} that includes ${one ? "its column" : "their columns"}. Remove @ignore from ${fields}; Prisma 7's next migration is then empty, and ${one ? "the field appears" : "the fields appear"} in the Prisma 7 client again.`, input.sourceId, input.span);
40
41
  }
42
+ function parseIndexAttribute(attribute, owner, sourceId, indexTypes, diagnostics) {
43
+ const unsupported = (what, span) => {
44
+ diagnostics.push(prisma7Diagnostic("PSL.PRISMA7_INDEX_ARGUMENT_UNSUPPORTED", `"${owner}": @${attribute.name} ${what}`, sourceId, span));
45
+ };
46
+ let fields;
47
+ let map;
48
+ let type;
49
+ for (const arg of attribute.args) {
50
+ const key = arg.kind === "positional" ? "fields" : arg.name;
51
+ const expression = arg.expression;
52
+ switch (key) {
53
+ case "fields": {
54
+ const array = expression === void 0 ? void 0 : ArrayLiteralAst.cast(expression.syntax);
55
+ if (array === void 0) return unsupported("expects a list of field names.", arg.span);
56
+ const names = [];
57
+ for (const element of array.elements()) {
58
+ const path = PathExprAst.cast(element.syntax) ?? FunctionCallAst.cast(element.syntax)?.memberPath();
59
+ if (path !== void 0) return unsupported(`lists the dotted path "${path.path().join(".")}"; an index lists fields of its model by name, and Prisma 7 refuses the path as an unknown field.`, arg.span);
60
+ const name = IdentifierAst.cast(element.syntax)?.name();
61
+ if (name === void 0) return unsupported("field arguments such as sort or length are not supported; Prisma 8 indexes carry none.", arg.span);
62
+ names.push(name);
63
+ }
64
+ fields = names;
65
+ break;
66
+ }
67
+ case "map":
68
+ map = expression === void 0 ? void 0 : StringLiteralExprAst.cast(expression.syntax)?.value();
69
+ if (map === void 0) return unsupported("map must be a string.", arg.span);
70
+ break;
71
+ case "name": break;
72
+ case "type": {
73
+ const token = expression === void 0 ? void 0 : IdentifierAst.cast(expression.syntax)?.name();
74
+ type = token !== void 0 && Object.hasOwn(indexTypes, token) ? indexTypes[token] : void 0;
75
+ if (type === void 0) return unsupported(`type "${token ?? ""}" is not an index type Prisma 8 supports.`, arg.span);
76
+ break;
77
+ }
78
+ default: return unsupported(`argument "${key ?? ""}" is not supported.`, arg.span);
79
+ }
80
+ }
81
+ return {
82
+ fields,
83
+ map,
84
+ type,
85
+ span: attribute.span
86
+ };
87
+ }
88
+ /**
89
+ * A generated constraint name as Prisma 7 spells it: `base` cut so that
90
+ * `base + suffix` is at most `maxBytes` bytes, cut on a character boundary,
91
+ * with the suffix kept whole. Prisma 7.10.0 emits `..._aVeryLongCo_idx` for a
92
+ * long `@@index`, `..._AB_pkey` and `..._B_index` for a long implicit junction,
93
+ * and cuts a multi-byte name before the character that would cross the budget.
94
+ */
95
+ function prisma7ConstraintName(base, suffix, maxBytes) {
96
+ return `${clipToUtf8Bytes(base, maxBytes - utf8ByteLength(suffix))}${suffix}`;
97
+ }
98
+ /** Prisma 7's default index name: `{table}_{columns}_idx`, or `_key` for a unique index, cut to `maxBytes`. */
99
+ function defaultIndexName(tableName, columns, unique, maxBytes) {
100
+ return prisma7ConstraintName(`${tableName}_${columns.join("_")}`, unique ? "_key" : "_idx", maxBytes);
101
+ }
102
+ function indexNode(tableName, columns, attribute, unique, maxBytes) {
103
+ return {
104
+ columns,
105
+ ...attribute.type === void 0 ? {
106
+ type: void 0,
107
+ options: void 0
108
+ } : {
109
+ type: attribute.type,
110
+ options: {}
111
+ },
112
+ where: void 0,
113
+ unique: unique ? true : void 0,
114
+ map: attribute.map ?? defaultIndexName(tableName, columns, unique, maxBytes),
115
+ name: void 0
116
+ };
117
+ }
118
+ /** Prisma 7's primary key name: `map`, or `{table}_pkey` cut to `maxBytes`. */
119
+ function prisma7PrimaryKeyName(tableName, map, maxBytes) {
120
+ return map ?? prisma7ConstraintName(tableName, "_pkey", maxBytes);
121
+ }
122
+ /** Prisma 7's foreign key name: `map`, or `{table}_{columns}_fkey` cut to `maxBytes`. */
123
+ function prisma7ForeignKeyName(tableName, columns, map, maxBytes) {
124
+ return map ?? prisma7ConstraintName(`${tableName}_${columns.join("_")}`, "_fkey", maxBytes);
125
+ }
126
+ /** Prisma 7's primary key name for the junction table of an implicit many-to-many relation. */
127
+ function prisma7JunctionPrimaryKeyName(relationName, maxBytes) {
128
+ return prisma7ConstraintName(`_${relationName}`, "_AB_pkey", maxBytes);
129
+ }
130
+ /** Prisma 7's name for the junction foreign key on column `A` or `B`. */
131
+ function prisma7JunctionForeignKeyName(relationName, column, maxBytes) {
132
+ return prisma7ConstraintName(`_${relationName}`, `_${column}_fkey`, maxBytes);
133
+ }
134
+ /**
135
+ * The name a contract states for a constraint Prisma 7 named `prisma7Name`: the name itself where the target would derive a different one, and `undefined` where the two agree, so the contract stays unnamed there and a table rename keeps deriving it.
136
+ */
137
+ function statedConstraintName(prisma7Name, derivedName) {
138
+ return prisma7Name === derivedName ? void 0 : prisma7Name;
139
+ }
140
+ /**
141
+ * Refuses a `map` on `@id`, `@@id`, `@unique`, `@@unique`, `@@index` or `@relation` longer than the database keeps, as Prisma 7 does. The database would store the name cut short, so a contract holding it whole would rename or drop a constraint the database does not have.
142
+ */
143
+ function checkStatedConstraintNameLength(input) {
144
+ const { attribute, maxBytes } = input;
145
+ const mapArgument = attribute.args.find((arg) => arg.kind === "named" && arg.name === "map");
146
+ const expression = mapArgument?.expression;
147
+ const name = expression === void 0 ? void 0 : StringLiteralExprAst.cast(expression.syntax)?.value();
148
+ if (mapArgument === void 0 || name === void 0) return;
149
+ const bytes = utf8ByteLength(name);
150
+ if (bytes <= maxBytes) return;
151
+ const spelling = `${attribute.node instanceof ModelAttributeAst ? "@@" : "@"}${attribute.name}`;
152
+ input.diagnostics.push(prisma7Diagnostic("PSL.PRISMA7_CONSTRAINT_NAME_TOO_LONG", `${input.owner}: the name "${name}" in the map argument of ${spelling} is ${bytes} bytes, longer than the ${maxBytes} bytes the database keeps. Shorten the map to ${maxBytes} bytes or fewer; Prisma 7 refuses this name too.`, input.sourceId, mapArgument.span));
153
+ }
41
154
  const CLIENT_SIDE_GENERATORS = /* @__PURE__ */ new Set([
42
155
  "uuid",
43
156
  "cuid",
@@ -312,91 +425,6 @@ function dbgeneratedDefault(callArgs, unknown, span) {
312
425
  onCreate: void 0
313
426
  };
314
427
  }
315
- function parseIndexAttribute(attribute, owner, sourceId, indexTypes, diagnostics) {
316
- const unsupported = (what, span) => {
317
- diagnostics.push(prisma7Diagnostic("PSL.PRISMA7_INDEX_ARGUMENT_UNSUPPORTED", `"${owner}": @${attribute.name} ${what}`, sourceId, span));
318
- };
319
- let fields;
320
- let map;
321
- let type;
322
- for (const arg of attribute.args) {
323
- const key = arg.kind === "positional" ? "fields" : arg.name;
324
- const expression = arg.expression;
325
- switch (key) {
326
- case "fields": {
327
- const array = expression === void 0 ? void 0 : ArrayLiteralAst.cast(expression.syntax);
328
- if (array === void 0) return unsupported("expects a list of field names.", arg.span);
329
- const names = [];
330
- for (const element of array.elements()) {
331
- const path = PathExprAst.cast(element.syntax) ?? FunctionCallAst.cast(element.syntax)?.memberPath();
332
- if (path !== void 0) return unsupported(`lists the dotted path "${path.path().join(".")}"; an index lists fields of its model by name, and Prisma 7 refuses the path as an unknown field.`, arg.span);
333
- const name = IdentifierAst.cast(element.syntax)?.name();
334
- if (name === void 0) return unsupported("field arguments such as sort or length are not supported; Prisma 8 indexes carry none.", arg.span);
335
- names.push(name);
336
- }
337
- fields = names;
338
- break;
339
- }
340
- case "map":
341
- map = expression === void 0 ? void 0 : StringLiteralExprAst.cast(expression.syntax)?.value();
342
- if (map === void 0) return unsupported("map must be a string.", arg.span);
343
- break;
344
- case "name": break;
345
- case "type": {
346
- const token = expression === void 0 ? void 0 : IdentifierAst.cast(expression.syntax)?.name();
347
- type = token !== void 0 && Object.hasOwn(indexTypes, token) ? indexTypes[token] : void 0;
348
- if (type === void 0) return unsupported(`type "${token ?? ""}" is not an index type Prisma 8 supports.`, arg.span);
349
- break;
350
- }
351
- default: return unsupported(`argument "${key ?? ""}" is not supported.`, arg.span);
352
- }
353
- }
354
- return {
355
- fields,
356
- map,
357
- type,
358
- span: attribute.span
359
- };
360
- }
361
- const utf8 = new TextEncoder();
362
- /**
363
- * A generated constraint name as Prisma 7 spells it: `base` cut so that
364
- * `base + suffix` is at most `maxBytes` bytes, cut on a character boundary,
365
- * with the suffix kept whole. Prisma 7.10.0 emits `..._aVeryLongCo_idx` for a
366
- * long `@@index`, `..._AB_pkey` and `..._B_index` for a long implicit junction,
367
- * and cuts a multi-byte name before the character that would cross the budget.
368
- */
369
- function prisma7ConstraintName(base, suffix, maxBytes) {
370
- const budget = maxBytes - utf8.encode(suffix).length;
371
- let bytes = 0;
372
- let kept = "";
373
- for (const character of base) {
374
- bytes += utf8.encode(character).length;
375
- if (bytes > budget) break;
376
- kept += character;
377
- }
378
- return `${kept}${suffix}`;
379
- }
380
- /** Prisma 7's default index name: `{table}_{columns}_idx`, or `_key` for a unique index, cut to `maxBytes`. */
381
- function defaultIndexName(tableName, columns, unique, maxBytes) {
382
- return prisma7ConstraintName(`${tableName}_${columns.join("_")}`, unique ? "_key" : "_idx", maxBytes);
383
- }
384
- function indexNode(tableName, columns, attribute, unique, maxBytes) {
385
- return {
386
- columns,
387
- ...attribute.type === void 0 ? {
388
- type: void 0,
389
- options: void 0
390
- } : {
391
- type: attribute.type,
392
- options: {}
393
- },
394
- where: void 0,
395
- unique: unique ? true : void 0,
396
- map: attribute.map ?? defaultIndexName(tableName, columns, unique, maxBytes),
397
- name: void 0
398
- };
399
- }
400
428
  function prisma7ScalarMapping(typeMap, scalar) {
401
429
  return Object.hasOwn(typeMap.scalars, scalar) ? typeMap.scalars[scalar] : void 0;
402
430
  }
@@ -445,6 +473,7 @@ function actionValue(expression) {
445
473
  }
446
474
  function parseRelationAttribute(attribute, label, sourceId, diagnostics) {
447
475
  let name;
476
+ let map;
448
477
  let fields;
449
478
  let references;
450
479
  let onDelete;
@@ -480,12 +509,16 @@ function parseRelationAttribute(attribute, label, sourceId, diagnostics) {
480
509
  onUpdate = actionValue(arg.expression);
481
510
  if (onUpdate === void 0) return invalid("onUpdate must be a referential action", arg.span);
482
511
  break;
483
- case "map": break;
512
+ case "map":
513
+ map = stringValue(arg.expression);
514
+ if (map === void 0) return invalid("map must be a string", arg.span);
515
+ break;
484
516
  default: return invalid(`argument "${key ?? ""}" is not supported`, arg.span);
485
517
  }
486
518
  }
487
519
  return {
488
520
  name,
521
+ map,
489
522
  fields,
490
523
  references,
491
524
  onDelete,
@@ -656,7 +689,9 @@ function lowerRelations(models, naming, diagnostics) {
656
689
  rejectFkSide(model, relationField, ...actionRejections);
657
690
  continue;
658
691
  }
692
+ const foreignKeyName = statedConstraintName(prisma7ForeignKeyName(model.tableName, localColumns, attribute.map, naming.identifierMaxBytes), naming.defaultConstraintNames.foreignKey(model.tableName, localColumns));
659
693
  addForeignKey(model.modelName, {
694
+ ...ifDefined("name", foreignKeyName),
660
695
  columns: localColumns,
661
696
  references: {
662
697
  model: target.modelName,
@@ -866,7 +901,10 @@ function synthesizeJunction(requester, partner, naming, diagnostics) {
866
901
  const namespaceId = sideA.model.namespaceId;
867
902
  const key = junctionKey(namespaceId, name);
868
903
  const [relationFieldA, relationFieldB] = naming.junctionRelationFieldNames(sideA.model.tableName, sideB.model.tableName);
904
+ const foreignKeyName = (column) => statedConstraintName(prisma7JunctionForeignKeyName(name, column, naming.identifierMaxBytes), naming.defaultConstraintNames.foreignKey(tableName, [column]));
905
+ const primaryKeyName = statedConstraintName(prisma7JunctionPrimaryKeyName(name, naming.identifierMaxBytes), naming.defaultConstraintNames.primaryKey(tableName));
869
906
  const foreignKey = (column, side, id) => ({
907
+ ...ifDefined("name", foreignKeyName(column)),
870
908
  columns: [column],
871
909
  references: {
872
910
  model: side.model.modelName,
@@ -919,7 +957,10 @@ function synthesizeJunction(requester, partner, naming, diagnostics) {
919
957
  nullable: false,
920
958
  many: false
921
959
  }],
922
- id: { columns: ["A", "B"] },
960
+ id: {
961
+ columns: ["A", "B"],
962
+ ...ifDefined("name", primaryKeyName)
963
+ },
923
964
  indexes: [index],
924
965
  foreignKeys: [foreignKey("A", sideA, idA), foreignKey("B", sideB, idB)]
925
966
  },
@@ -1052,7 +1093,7 @@ function interpretPrisma7Documents(input) {
1052
1093
  for (const namedType of Object.values(symbolTable.topLevel.namedTypes)) unsupported("types", namedType.span);
1053
1094
  for (const symbol of Object.values(symbolTable.topLevel.models)) {
1054
1095
  if (!claimName("model", symbol.name, sourceId, symbol.span)) continue;
1055
- const declaration = readModelDeclaration(symbol, sourceId, sources, defaultNamespaceId, binding.indexTypes, diagnostics);
1096
+ const declaration = readModelDeclaration(symbol, sourceId, sources, defaultNamespaceId, binding, diagnostics);
1056
1097
  if (declaration === void 0) ignoredModels.add(symbol.name);
1057
1098
  else models.push(declaration);
1058
1099
  }
@@ -1076,6 +1117,7 @@ function interpretPrisma7Documents(input) {
1076
1117
  ignoredRelationFields: [],
1077
1118
  rejectedFields: /* @__PURE__ */ new Set(),
1078
1119
  idFields: declaration.id?.fields ?? [],
1120
+ idMap: declaration.id?.map,
1079
1121
  uniqueIndexes: [...declaration.uniqueIndexes],
1080
1122
  relationFields: []
1081
1123
  };
@@ -1158,12 +1200,16 @@ function interpretPrisma7Documents(input) {
1158
1200
  });
1159
1201
  const foreignKeys = lowered.foreignKeys.get(modelName);
1160
1202
  const relations = lowered.relations.get(modelName);
1203
+ const primaryKeyName = statedConstraintName(prisma7PrimaryKeyName(model.tableName, build.idMap, binding.identifierMaxBytes), binding.defaultConstraintNames.primaryKey(model.tableName));
1161
1204
  modelNodes.push({
1162
1205
  modelName,
1163
1206
  tableName: model.tableName,
1164
1207
  namespaceId: model.namespaceId,
1165
1208
  fields: [...build.columns.values()],
1166
- ...id !== void 0 && id.length > 0 ? { id: { columns: id } } : {},
1209
+ ...id !== void 0 && id.length > 0 ? { id: {
1210
+ columns: id,
1211
+ ...ifDefined("name", primaryKeyName)
1212
+ } } : {},
1167
1213
  ...indexes.length > 0 ? { indexes } : {},
1168
1214
  ...foreignKeys !== void 0 ? { foreignKeys } : {},
1169
1215
  ...relations !== void 0 ? { relations } : {}
@@ -1248,36 +1294,50 @@ function keyColumns(model, fieldNames) {
1248
1294
  }
1249
1295
  return columns;
1250
1296
  }
1251
- function readModelDeclaration(symbol, sourceId, sources, defaultNamespaceId, indexTypes, diagnostics) {
1297
+ function readModelDeclaration(symbol, sourceId, sources, defaultNamespaceId, binding, diagnostics) {
1298
+ const { indexTypes } = binding;
1252
1299
  if (symbol.attributes.some((attribute) => attribute.name === "ignore")) return void 0;
1253
1300
  let tableName = symbol.name;
1254
1301
  let namespaceId = defaultNamespaceId;
1255
1302
  let id;
1256
1303
  const uniqueIndexes = [];
1257
1304
  const indexes = [];
1258
- for (const attribute of symbol.attributes) switch (attribute.name) {
1259
- case "map":
1260
- tableName = requireStringArgument(attribute, symbol.name, sourceId, diagnostics) ?? tableName;
1261
- break;
1262
- case "schema":
1263
- namespaceId = requireStringArgument(attribute, symbol.name, sourceId, diagnostics) ?? namespaceId;
1264
- break;
1265
- case "id": {
1266
- const parsed = parseIndexAttribute(attribute, symbol.name, sourceId, indexTypes, diagnostics);
1267
- if (parsed?.fields !== void 0) id = parsed;
1268
- break;
1269
- }
1270
- case "unique": {
1271
- const parsed = parseIndexAttribute(attribute, symbol.name, sourceId, indexTypes, diagnostics);
1272
- if (parsed?.fields !== void 0) uniqueIndexes.push(parsed);
1273
- break;
1274
- }
1275
- case "index": {
1276
- const parsed = parseIndexAttribute(attribute, symbol.name, sourceId, indexTypes, diagnostics);
1277
- if (parsed?.fields !== void 0) indexes.push(parsed);
1278
- break;
1305
+ for (const attribute of symbol.attributes) {
1306
+ if ([
1307
+ "id",
1308
+ "unique",
1309
+ "index"
1310
+ ].includes(attribute.name)) checkStatedConstraintNameLength({
1311
+ attribute,
1312
+ owner: `Model "${symbol.name}"`,
1313
+ maxBytes: binding.identifierMaxBytes,
1314
+ sourceId,
1315
+ diagnostics
1316
+ });
1317
+ switch (attribute.name) {
1318
+ case "map":
1319
+ tableName = requireStringArgument(attribute, symbol.name, sourceId, diagnostics) ?? tableName;
1320
+ break;
1321
+ case "schema":
1322
+ namespaceId = requireStringArgument(attribute, symbol.name, sourceId, diagnostics) ?? namespaceId;
1323
+ break;
1324
+ case "id": {
1325
+ const parsed = parseIndexAttribute(attribute, symbol.name, sourceId, indexTypes, diagnostics);
1326
+ if (parsed?.fields !== void 0) id = parsed;
1327
+ break;
1328
+ }
1329
+ case "unique": {
1330
+ const parsed = parseIndexAttribute(attribute, symbol.name, sourceId, indexTypes, diagnostics);
1331
+ if (parsed?.fields !== void 0) uniqueIndexes.push(parsed);
1332
+ break;
1333
+ }
1334
+ case "index": {
1335
+ const parsed = parseIndexAttribute(attribute, symbol.name, sourceId, indexTypes, diagnostics);
1336
+ if (parsed?.fields !== void 0) indexes.push(parsed);
1337
+ break;
1338
+ }
1339
+ default: diagnostics.push(prisma7Diagnostic("PSL.PRISMA7_UNKNOWN_ATTRIBUTE", `Model "${symbol.name}": attribute "@@${attribute.name}" is not supported yet by the Prisma 7 contract source.`, sourceId, attribute.span));
1279
1340
  }
1280
- default: diagnostics.push(prisma7Diagnostic("PSL.PRISMA7_UNKNOWN_ATTRIBUTE", `Model "${symbol.name}": attribute "@@${attribute.name}" is not supported yet by the Prisma 7 contract source.`, sourceId, attribute.span));
1281
1341
  }
1282
1342
  return {
1283
1343
  symbol,
@@ -1491,23 +1551,36 @@ function readField(args) {
1491
1551
  let relation;
1492
1552
  let defaultAttribute;
1493
1553
  let updatedAt;
1494
- for (const attribute of field.attributes) if (attribute.name === "map" && !isRelationField) columnName = requireStringArgument(attribute, label, sourceId, diagnostics) ?? columnName;
1495
- else if (attribute.name.startsWith("db.") && !isRelationField) nativeType = {
1496
- name: attribute.name.slice(3),
1497
- attribute
1498
- };
1499
- else if (attribute.name === "id" && !isRelationField) {
1500
- if (parseIndexAttribute(attribute, label, sourceId, binding.indexTypes, diagnostics) !== void 0) build.idFields = [field.name];
1501
- } else if (attribute.name === "unique" && !isRelationField) {
1502
- const parsed = parseIndexAttribute(attribute, label, sourceId, binding.indexTypes, diagnostics);
1503
- if (parsed !== void 0) build.uniqueIndexes.push({
1504
- ...parsed,
1505
- fields: [field.name]
1554
+ for (const attribute of field.attributes) {
1555
+ if (isRelationField ? attribute.name === "relation" : ["id", "unique"].includes(attribute.name)) checkStatedConstraintNameLength({
1556
+ attribute,
1557
+ owner: label,
1558
+ maxBytes: binding.identifierMaxBytes,
1559
+ sourceId,
1560
+ diagnostics
1506
1561
  });
1507
- } else if (attribute.name === "default" && !isRelationField) defaultAttribute = attribute;
1508
- else if (attribute.name === "updatedAt" && !isRelationField) updatedAt = attribute;
1509
- else if (attribute.name === "relation" && isRelationField) relation = attribute;
1510
- else diagnostics.push(prisma7Diagnostic("PSL.PRISMA7_UNKNOWN_ATTRIBUTE", `${label}: attribute "@${attribute.name}" is not supported yet by the Prisma 7 contract source.`, sourceId, attribute.span));
1562
+ if (attribute.name === "map" && !isRelationField) columnName = requireStringArgument(attribute, label, sourceId, diagnostics) ?? columnName;
1563
+ else if (attribute.name.startsWith("db.") && !isRelationField) nativeType = {
1564
+ name: attribute.name.slice(3),
1565
+ attribute
1566
+ };
1567
+ else if (attribute.name === "id" && !isRelationField) {
1568
+ const parsed = parseIndexAttribute(attribute, label, sourceId, binding.indexTypes, diagnostics);
1569
+ if (parsed !== void 0) {
1570
+ build.idFields = [field.name];
1571
+ build.idMap = parsed.map;
1572
+ }
1573
+ } else if (attribute.name === "unique" && !isRelationField) {
1574
+ const parsed = parseIndexAttribute(attribute, label, sourceId, binding.indexTypes, diagnostics);
1575
+ if (parsed !== void 0) build.uniqueIndexes.push({
1576
+ ...parsed,
1577
+ fields: [field.name]
1578
+ });
1579
+ } else if (attribute.name === "default" && !isRelationField) defaultAttribute = attribute;
1580
+ else if (attribute.name === "updatedAt" && !isRelationField) updatedAt = attribute;
1581
+ else if (attribute.name === "relation" && isRelationField) relation = attribute;
1582
+ else diagnostics.push(prisma7Diagnostic("PSL.PRISMA7_UNKNOWN_ATTRIBUTE", `${label}: attribute "@${attribute.name}" is not supported yet by the Prisma 7 contract source.`, sourceId, attribute.span));
1583
+ }
1511
1584
  if (field.malformedType) return;
1512
1585
  if (field.typeConstructor !== void 0) {
1513
1586
  diagnostics.push(prisma7Diagnostic("PSL.PRISMA7_UNSUPPORTED_TYPE", `${label} has type "${field.typeConstructor.path.join(".")}(...)", which has no Prisma 8 codec, so model "${model.symbol.name}" cannot use this contract source while it has the field. Prisma 7 rejects @ignore on an Unsupported field, and removing the field drops its column on Prisma 7's next migration. Adding @@ignore to model "${model.symbol.name}" keeps the model out of the contract: Prisma 7's next migration is empty, but the model disappears from the Prisma 7 client too, and every relation field in another model that points to it needs @ignore, which removes that field from the Prisma 7 client as well.`, sourceId, field.typeConstructor.span));