@prisma/orm-target-postgres 8.0.0-rc.12-dev.14 → 8.0.0-rc.12-dev.16

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 (39) hide show
  1. package/dist/adapter__control.mjs +1 -1
  2. package/dist/adapter__runtime.mjs +1 -1
  3. package/dist/{authoring-gAs7Qz2A-BCHfYhEb.mjs → authoring-CSC0-DjI-CA5cgVmB.mjs} +55 -35
  4. package/dist/authoring-CSC0-DjI-CA5cgVmB.mjs.map +1 -0
  5. package/dist/control-CX9tMnuS.mjs +2350 -0
  6. package/dist/control-CX9tMnuS.mjs.map +1 -0
  7. package/dist/{descriptor-meta-BRzQLmGR-DZdNDAF6.mjs → descriptor-meta--zYVau3w-D-q8Cvf0.mjs} +3 -3
  8. package/dist/{descriptor-meta-BRzQLmGR-DZdNDAF6.mjs.map → descriptor-meta--zYVau3w-D-q8Cvf0.mjs.map} +1 -1
  9. package/dist/{errors-BcF1S3mV.d.mts → errors-1AjGQf6h.d.mts} +2 -2
  10. package/dist/{errors-BcF1S3mV.d.mts.map → errors-1AjGQf6h.d.mts.map} +1 -1
  11. package/dist/{infer-psl-contract-B9Hs0kKm-Cp7_uC0O.mjs → infer-psl-contract-DEHd6IMV-D1FmIxJC.mjs} +281 -277
  12. package/dist/infer-psl-contract-DEHd6IMV-D1FmIxJC.mjs.map +1 -0
  13. package/dist/migration-PTHAY9Cv.mjs.map +1 -1
  14. package/dist/{planner-CN7-lNRC-CN5OYpcD.mjs → planner-BAhxnFCn-0tAyr8zp.mjs} +3 -3
  15. package/dist/{planner-CN7-lNRC-CN5OYpcD.mjs.map → planner-BAhxnFCn-0tAyr8zp.mjs.map} +1 -1
  16. package/dist/{planner-produced-postgres-migration-Y5yqsSV--CyoG8l1n.mjs → planner-produced-postgres-migration-Ceuww3Cw-CMC3g395.mjs} +3 -3
  17. package/dist/{planner-produced-postgres-migration-Y5yqsSV--CyoG8l1n.mjs.map → planner-produced-postgres-migration-Ceuww3Cw-CMC3g395.mjs.map} +1 -1
  18. package/dist/{postgres-contract-view-CL1U38XC-CNK0yKEU.mjs → postgres-contract-view-BTNJukLn-QzZysnih.mjs} +3 -3
  19. package/dist/{postgres-contract-view-CL1U38XC-CNK0yKEU.mjs.map → postgres-contract-view-BTNJukLn-QzZysnih.mjs.map} +1 -1
  20. package/dist/{postgres-migration-C0CAQVCb-Blv2u1yN.mjs → postgres-migration-4s6yFwMP-lBYUEAjj.mjs} +3 -3
  21. package/dist/{postgres-migration-C0CAQVCb-Blv2u1yN.mjs.map → postgres-migration-4s6yFwMP-lBYUEAjj.mjs.map} +1 -1
  22. package/dist/{prisma7-binding-4hwKqLeu.mjs → prisma7-binding-aUk4pSUA.mjs} +4 -4
  23. package/dist/{prisma7-binding-4hwKqLeu.mjs.map → prisma7-binding-aUk4pSUA.mjs.map} +1 -1
  24. package/dist/target.d.mts +1 -1
  25. package/dist/target.mjs +7 -7
  26. package/dist/target__control.mjs +2 -2
  27. package/dist/target__errors.d.mts +1 -1
  28. package/dist/target__migration.mjs +1 -1
  29. package/dist/target__pack.mjs +1 -1
  30. package/dist/target__planner-produced-postgres-migration.mjs +1 -1
  31. package/dist/target__planner.mjs +1 -1
  32. package/dist/target__prisma7-binding.mjs +1 -1
  33. package/dist/target__runtime.mjs +2 -2
  34. package/dist/target__runtime.mjs.map +1 -1
  35. package/package.json +9 -9
  36. package/dist/authoring-gAs7Qz2A-BCHfYhEb.mjs.map +0 -1
  37. package/dist/control-DfIG6CQ9.mjs +0 -470
  38. package/dist/control-DfIG6CQ9.mjs.map +0 -1
  39. package/dist/infer-psl-contract-B9Hs0kKm-Cp7_uC0O.mjs.map +0 -1
@@ -3,6 +3,7 @@ import { D as postgresDataTypes } from "./data-types-BOMKl3ue-BZ8EARvV.mjs";
3
3
  import { s as postgresError } from "./errors-DYyzTYzE-39CV_aMo.mjs";
4
4
  import { t as postgresCodecDescriptorRegistry } from "./registry-Bf5BvREu-DJ7g3REJ.mjs";
5
5
  import { t as parsePostgresDefault } from "./default-normalizer-Coo-llj4-6YPzp_F9.mjs";
6
+ import { r as POLICY_BLOCK_KEYWORDS } from "./authoring-CSC0-DjI-CA5cgVmB.mjs";
6
7
  import { t as postgresRenderCheckExpressions } from "./check-expressions-DLCs-SXx-itMQrUsX.mjs";
7
8
  import { t as postgresDataTypeEntries } from "./data-type-entries-Fxm2HDZk-D4AAd63w.mjs";
8
9
  import { escapePslString } from "@prisma/orm-family-sql/relational-core/ast";
@@ -12,11 +13,197 @@ import { coordinateKey, elementCoordinates } from "@prisma/orm-framework/compone
12
13
  import { ifDefined } from "@prisma/orm-framework/utils/defined";
13
14
  import { composeCheckWirePrefix, computeCheckContentHash, computeIndexContentHash, formatWireName, parseWireName } from "@prisma/orm-family-sql/schema-ir/naming";
14
15
  import { assertDefined } from "@prisma/orm-framework/utils/assertions";
16
+ import { NAME_THE_PSL_SOURCE_LOSES, isPslIdentifier } from "@prisma/orm-framework/psl-parser";
15
17
  import { SqlSchemaIR, SqlTableIR } from "@prisma/orm-family-sql/schema-ir/types";
16
- import { buildChildRelationField, deriveRelationFieldName, inferRelations, mapDefault, toEnumMemberName, toEnumName, toFieldName, toModelName } from "@prisma/orm-family-sql/family/psl-infer";
18
+ import { buildChildRelationField, deriveRelationFieldName, inferRelations, toEnumName, toFieldName, toModelName } from "@prisma/orm-family-sql/family/psl-infer";
17
19
  import { UNSPECIFIED_PSL_NAMESPACE_ID, makePslNamespace, makePslNamespaceEntries } from "@prisma/orm-framework/components/psl-ast";
20
+ import { mapDefault, toEnumMemberName } from "@prisma/orm-family-sql/family/psl-build";
18
21
  import { isColumnDefault } from "@prisma/orm-framework/contract/types";
19
- //#region ../../../3-targets/3-targets/postgres/dist/infer-psl-contract-B9Hs0kKm.mjs
22
+ //#region ../../../3-targets/3-targets/postgres/dist/infer-psl-contract-DEHd6IMV.mjs
23
+ const POSTGRES_TO_PSL = {
24
+ text: "String",
25
+ bool: "Boolean",
26
+ boolean: "Boolean",
27
+ int4: "Int",
28
+ integer: "Int",
29
+ int8: "BigInt",
30
+ bigint: "BigInt",
31
+ float8: "Float",
32
+ "double precision": "Float",
33
+ jsonb: "Jsonb",
34
+ bytea: "Bytes"
35
+ };
36
+ const PRESERVED_NATIVE_TYPES = {
37
+ "character varying": "VarChar",
38
+ character: "Char",
39
+ char: "Char",
40
+ varchar: "VarChar",
41
+ uuid: "Uuid",
42
+ inet: "Inet",
43
+ int2: "SmallInt",
44
+ smallint: "SmallInt",
45
+ float4: "Real",
46
+ real: "Real",
47
+ numeric: "Numeric",
48
+ decimal: "Numeric",
49
+ timestamp: "Timestamp",
50
+ "timestamp without time zone": "Timestamp",
51
+ timestamptz: "Timestamptz",
52
+ "timestamp with time zone": "Timestamptz",
53
+ date: "Date",
54
+ time: "Time",
55
+ "time without time zone": "Time",
56
+ timetz: "Timetz",
57
+ "time with time zone": "Timetz",
58
+ json: "Json"
59
+ };
60
+ const PARAMETERIZED_NATIVE_TYPES = {
61
+ "character varying": "VarChar",
62
+ character: "Char",
63
+ char: "Char",
64
+ varchar: "VarChar",
65
+ numeric: "Numeric",
66
+ decimal: "Numeric",
67
+ timestamp: "Timestamp",
68
+ timestamptz: "Timestamptz",
69
+ time: "Time",
70
+ timetz: "Timetz"
71
+ };
72
+ [
73
+ ...Object.values(POSTGRES_TO_PSL),
74
+ ...Object.values(PRESERVED_NATIVE_TYPES),
75
+ ...Object.values(PARAMETERIZED_NATIVE_TYPES)
76
+ ];
77
+ const PARAMETERIZED_TYPE_PATTERN = /^(.+?)\((.+)\)$/;
78
+ function getOwnMappingValue(map, key) {
79
+ return Object.hasOwn(map, key) ? map[key] : void 0;
80
+ }
81
+ function splitTypeParameterList(params) {
82
+ return params.split(",").map((part) => part.trim()).filter((part) => part.length > 0);
83
+ }
84
+ function createPostgresTypeMap(enumTypeNames) {
85
+ return { resolve(nativeType) {
86
+ if (enumTypeNames?.has(nativeType)) return {
87
+ pslType: { name: nativeType },
88
+ nativeType
89
+ };
90
+ const paramMatch = nativeType.match(PARAMETERIZED_TYPE_PATTERN);
91
+ if (paramMatch) {
92
+ const [, baseType = nativeType, params = ""] = paramMatch;
93
+ const typeName = getOwnMappingValue(PARAMETERIZED_NATIVE_TYPES, baseType);
94
+ if (typeName) return {
95
+ pslType: {
96
+ name: typeName,
97
+ args: splitTypeParameterList(params)
98
+ },
99
+ nativeType,
100
+ typeParams: {
101
+ baseType,
102
+ params
103
+ }
104
+ };
105
+ }
106
+ const preservedType = getOwnMappingValue(PRESERVED_NATIVE_TYPES, nativeType);
107
+ if (preservedType) return {
108
+ pslType: { name: preservedType },
109
+ nativeType
110
+ };
111
+ const pslType = getOwnMappingValue(POSTGRES_TO_PSL, nativeType);
112
+ if (pslType) return {
113
+ pslType: { name: pslType },
114
+ nativeType
115
+ };
116
+ return {
117
+ unsupported: true,
118
+ nativeType
119
+ };
120
+ } };
121
+ }
122
+ const SYNTHETIC_SPAN = {
123
+ start: {
124
+ offset: 0,
125
+ line: 1,
126
+ column: 1
127
+ },
128
+ end: {
129
+ offset: 0,
130
+ line: 1,
131
+ column: 1
132
+ }
133
+ };
134
+ function buildSimpleConstraintFieldAttribute(name, constraintName) {
135
+ if (constraintName === void 0) return buildAttribute("field", name, []);
136
+ return buildAttribute("field", name, [namedArg("map", `"${escapePslString(constraintName)}"`)]);
137
+ }
138
+ function parseDefaultAttributeString(attributeText) {
139
+ return buildAttribute("field", "default", [positionalArg(attributeText.replace(/^@default\(/, "").replace(/\)$/, ""))]);
140
+ }
141
+ function buildMapAttribute(target, mapName) {
142
+ return buildAttribute(target, "map", [positionalArg(`"${escapePslString(mapName)}"`)]);
143
+ }
144
+ function buildAttribute(target, name, args) {
145
+ return {
146
+ kind: "attribute",
147
+ target,
148
+ name,
149
+ args,
150
+ span: SYNTHETIC_SPAN
151
+ };
152
+ }
153
+ function positionalArg(value) {
154
+ return {
155
+ kind: "positional",
156
+ value,
157
+ span: SYNTHETIC_SPAN
158
+ };
159
+ }
160
+ function namedArg(name, value) {
161
+ return {
162
+ kind: "named",
163
+ name,
164
+ value,
165
+ span: SYNTHETIC_SPAN
166
+ };
167
+ }
168
+ /** `desiredName`, or it with the lowest number from 2 up that makes it unused. */
169
+ function createUniqueFieldName(desiredName, usedFieldNames) {
170
+ if (!usedFieldNames.has(desiredName)) return desiredName;
171
+ let counter = 2;
172
+ while (usedFieldNames.has(`${desiredName}${counter}`)) counter++;
173
+ return `${desiredName}${counter}`;
174
+ }
175
+ /** One `native_enum <name> { … }` block, with `@@map` when the type name differs from the block name. */
176
+ function buildNativeEnumBlock(name, typeName, values) {
177
+ const usedMemberNames = /* @__PURE__ */ new Set([NAME_THE_PSL_SOURCE_LOSES]);
178
+ return {
179
+ kind: "native_enum",
180
+ keyword: "native_enum",
181
+ name,
182
+ parameters: Object.fromEntries(values.map((value) => {
183
+ const memberName = createUniqueFieldName(toEnumMemberName(value), usedMemberNames);
184
+ usedMemberNames.add(memberName);
185
+ return [memberName, {
186
+ kind: "value",
187
+ raw: JSON.stringify(value),
188
+ span: SYNTHETIC_SPAN
189
+ }];
190
+ })),
191
+ blockAttributes: name === typeName ? [] : [{
192
+ name: "map",
193
+ args: [{
194
+ kind: "positional",
195
+ value: `"${escapePslString(typeName)}"`,
196
+ span: SYNTHETIC_SPAN
197
+ }],
198
+ span: SYNTHETIC_SPAN
199
+ }],
200
+ attributes: name === typeName ? {} : { map: {
201
+ args: { name: typeName },
202
+ span: SYNTHETIC_SPAN
203
+ } },
204
+ span: SYNTHETIC_SPAN
205
+ };
206
+ }
20
207
  function buildFieldNamesByTable(tables) {
21
208
  const fieldNamesByTable = /* @__PURE__ */ new Map();
22
209
  for (const table of Object.values(tables)) {
@@ -50,12 +237,6 @@ function buildFieldNamesByTable(tables) {
50
237
  function resolveColumnFieldName(fieldNamesByTable, tableName, columnName) {
51
238
  return fieldNamesByTable.get(tableName)?.get(columnName)?.fieldName ?? toFieldName(columnName).name;
52
239
  }
53
- function createUniqueFieldName(desiredName, usedFieldNames) {
54
- if (!usedFieldNames.has(desiredName)) return desiredName;
55
- let counter = 2;
56
- while (usedFieldNames.has(`${desiredName}${counter}`)) counter++;
57
- return `${desiredName}${counter}`;
58
- }
59
240
  function buildTopLevelNameMap(sources, normalize, kind, sourceKind) {
60
241
  const results = /* @__PURE__ */ new Map();
61
242
  const normalizedToSources = /* @__PURE__ */ new Map();
@@ -113,64 +294,6 @@ function topologicalSort(models, tables, modelNameMap) {
113
294
  for (const name of sortedNames) visit(name);
114
295
  return result;
115
296
  }
116
- const SYNTHETIC_SPAN = {
117
- start: {
118
- offset: 0,
119
- line: 1,
120
- column: 1
121
- },
122
- end: {
123
- offset: 0,
124
- line: 1,
125
- column: 1
126
- }
127
- };
128
- function buildSimpleConstraintFieldAttribute(name, constraintName) {
129
- if (constraintName === void 0) return buildAttribute("field", name, []);
130
- return buildAttribute("field", name, [namedArg("map", `"${escapePslString(constraintName)}"`)]);
131
- }
132
- function parseDefaultAttributeString(attributeText) {
133
- return buildAttribute("field", "default", [positionalArg(attributeText.replace(/^@default\(/, "").replace(/\)$/, ""))]);
134
- }
135
- function buildMapAttribute(target, mapName) {
136
- return buildAttribute(target, "map", [positionalArg(`"${escapePslString(mapName)}"`)]);
137
- }
138
- function buildAttribute(target, name, args) {
139
- return {
140
- kind: "attribute",
141
- target,
142
- name,
143
- args,
144
- span: SYNTHETIC_SPAN
145
- };
146
- }
147
- function positionalArg(value) {
148
- return {
149
- kind: "positional",
150
- value,
151
- span: SYNTHETIC_SPAN
152
- };
153
- }
154
- function namedArg(name, value) {
155
- return {
156
- kind: "named",
157
- name,
158
- value,
159
- span: SYNTHETIC_SPAN
160
- };
161
- }
162
- /**
163
- * Resolves a `SqlColumnIR.default` value into a normalized {@link ColumnDefault}.
164
- *
165
- * `SqlSchemaIR` types the column default as `string` (a raw database default
166
- * expression). Some legacy fixtures and tests still pass already-normalized
167
- * `ColumnDefault` objects in the same slot, so we accept either shape
168
- * defensively at runtime.
169
- */
170
- function parseColumnDefault(value, nativeType, rawDefaultParser) {
171
- if (typeof value === "string") return rawDefaultParser ? rawDefaultParser(value, nativeType) : void 0;
172
- return isColumnDefault(value) ? value : void 0;
173
- }
174
297
  const PSL_SCALAR_TYPE_NAMES = /* @__PURE__ */ new Set([
175
298
  "String",
176
299
  "Boolean",
@@ -209,39 +332,6 @@ function buildNativeEnumBlocks(definitions, modelNames) {
209
332
  enumBlocks
210
333
  };
211
334
  }
212
- function buildNativeEnumBlock(name, typeName, values) {
213
- const usedMemberNames = /* @__PURE__ */ new Set();
214
- const parameters = {};
215
- for (const value of values) {
216
- const memberName = createUniqueFieldName(toEnumMemberName(value), usedMemberNames);
217
- usedMemberNames.add(memberName);
218
- parameters[memberName] = {
219
- kind: "value",
220
- raw: JSON.stringify(value),
221
- span: SYNTHETIC_SPAN
222
- };
223
- }
224
- return {
225
- kind: "native_enum",
226
- keyword: "native_enum",
227
- name,
228
- parameters,
229
- blockAttributes: name === typeName ? [] : [{
230
- name: "map",
231
- args: [{
232
- kind: "positional",
233
- value: `"${escapePslString(typeName)}"`,
234
- span: SYNTHETIC_SPAN
235
- }],
236
- span: SYNTHETIC_SPAN
237
- }],
238
- attributes: name === typeName ? {} : { map: {
239
- args: { name: typeName },
240
- span: SYNTHETIC_SPAN
241
- } },
242
- span: SYNTHETIC_SPAN
243
- };
244
- }
245
335
  /**
246
336
  * Coordinates every element a set of already-assembled contracts declare,
247
337
  * mapped to the {@link SqlDescribedContractSpace} that owns it and keyed by
@@ -373,8 +463,71 @@ function buildDanglingForeignKeyWarning(danglingForeignKeys, fieldNamesByTable,
373
463
  return `"${fieldNames.join(", ")}" -> "${target}"`;
374
464
  }).join(", ")} exists in the database, but its target schema is outside the introspected scope, so no relation field was generated. If the target schema is described by an extension pack, add it to extensions and re-run infer.`;
375
465
  }
376
- /** The codec `contract emit` binds to each PSL type name the type map prints. */
377
- const CODEC_ID_BY_PRINTED_TYPE = /* @__PURE__ */ new Map([
466
+ function buildModelConstraintAttribute(name, fields, constraintName) {
467
+ const args = [positionalArg(`[${fields.join(", ")}]`)];
468
+ if (constraintName !== void 0) args.push(namedArg("map", `"${escapePslString(constraintName)}"`));
469
+ return buildAttribute("model", name, args);
470
+ }
471
+ /**
472
+ * The naming of a live index, re-detected rather than trusted: wire when the
473
+ * live name parses as a wire name AND that hash recomputes from the
474
+ * introspected content; otherwise exact.
475
+ */
476
+ function detectIndexNaming(index) {
477
+ const parsed = parseWireName(index.name);
478
+ const recomputed = computeIndexContentHash({
479
+ ...index.columns !== void 0 ? { columns: index.columns } : {},
480
+ ...index.expression !== void 0 ? { expression: index.expression } : {},
481
+ ...index.where !== void 0 ? { where: index.where } : {},
482
+ unique: index.unique,
483
+ ...index.type !== void 0 ? { type: index.type } : {},
484
+ ...index.options !== void 0 ? { options: index.options } : {}
485
+ });
486
+ return parsed !== void 0 && parsed.hash === recomputed ? {
487
+ kind: "wire",
488
+ prefix: parsed.prefix
489
+ } : { kind: "exact" };
490
+ }
491
+ function namingArg(naming, exactName) {
492
+ return naming.kind === "wire" ? namedArg("name", `"${escapePslString(naming.prefix)}"`) : namedArg("map", `"${escapePslString(exactName)}"`);
493
+ }
494
+ /**
495
+ * Emits one `@@index` attribute at full fidelity, named as `naming` says;
496
+ * without it, the naming is re-detected from the live name and content.
497
+ */
498
+ function buildIndexAttribute(index, fieldNames, naming = detectIndexNaming(index)) {
499
+ const args = [];
500
+ if (fieldNames !== void 0) args.push(positionalArg(`[${fieldNames.join(", ")}]`));
501
+ else {
502
+ assertDefined(index.expression, `buildIndexAttribute: index "${index.name}" carries neither columns nor expression; SqlIndexIR enforces exactly one`);
503
+ args.push(namedArg("expression", `"${escapePslString(index.expression)}"`));
504
+ }
505
+ args.push(namingArg(naming, index.name));
506
+ if (index.where !== void 0) args.push(namedArg("where", `"${escapePslString(index.where)}"`));
507
+ if (index.unique) args.push(namedArg("unique", "true"));
508
+ if (index.type !== void 0 || index.options !== void 0) args.push(namedArg("type", `"${escapePslString(index.type ?? "btree")}"`));
509
+ if (index.options !== void 0) {
510
+ const entries = Object.entries(index.options ?? {}).sort(([a], [b]) => a < b ? -1 : a > b ? 1 : 0).map(([key, value]) => `${key}: "${escapePslString(String(value))}"`);
511
+ args.push(namedArg("options", `{ ${entries.join(", ")} }`));
512
+ }
513
+ return buildAttribute("model", "index", args);
514
+ }
515
+ /**
516
+ * Emits one `@@check` attribute, named as `naming` says. Without it, a live,
517
+ * non-derived check is written in the `map:` form. Re-detecting `name:` is not
518
+ * attempted there: the live expression is Postgres's own reprint, but a
519
+ * wire-named check's hash was taken over the author's original text, so
520
+ * recomputing the hash from the reprint would essentially never match. `map:`
521
+ * plus the verbatim reprint is correct regardless — a reprint compared against
522
+ * a later reprint of the same expression is stable, so the emitted contract
523
+ * signs the live database with zero pending operations. `buildIntrospectedPolicyBlocks`
524
+ * makes the same call for `@@map` on adopted RLS policies, for the same reason.
525
+ */
526
+ function buildCheckAttribute(check, naming = { kind: "exact" }) {
527
+ return buildAttribute("model", "check", [namedArg("expression", `"${escapePslString(check.expression)}"`), namingArg(naming, check.name)]);
528
+ }
529
+ /** The codec `contract emit` binds to each PSL type name the type map writes. */
530
+ const CODEC_ID_BY_INFERRED_TYPE = /* @__PURE__ */ new Map([
378
531
  ["String", "pg/text@1"],
379
532
  ["Boolean", "pg/bool@1"],
380
533
  ["Int", "pg/int4@1"],
@@ -401,15 +554,15 @@ const CODEC_ID_BY_PRINTED_TYPE = /* @__PURE__ */ new Map([
401
554
  * An enum column's default is a member name, which is text either way, so it reads through the text
402
555
  * codec.
403
556
  */
404
- function dataTypeForPrintedType(pslTypeName, isEnum) {
405
- const codecId = isEnum ? PG_TEXT_CODEC_ID : CODEC_ID_BY_PRINTED_TYPE.get(pslTypeName);
557
+ function dataTypeForInferredType(pslTypeName, isEnum) {
558
+ const codecId = isEnum ? PG_TEXT_CODEC_ID : CODEC_ID_BY_INFERRED_TYPE.get(pslTypeName);
406
559
  if (codecId === void 0) return void 0;
407
560
  return postgresCodecDescriptorRegistry.descriptorFor(codecId)?.dataType;
408
561
  }
409
562
  const codecs = /* @__PURE__ */ new Map();
410
563
  /** One instance per codec id: every codec in the table above decodes JSON the same way for any params. */
411
- function printedTypeCodec(pslTypeName, isEnum) {
412
- const codecId = isEnum ? PG_TEXT_CODEC_ID : CODEC_ID_BY_PRINTED_TYPE.get(pslTypeName);
564
+ function inferredTypeCodec(pslTypeName, isEnum) {
565
+ const codecId = isEnum ? PG_TEXT_CODEC_ID : CODEC_ID_BY_INFERRED_TYPE.get(pslTypeName);
413
566
  if (codecId === void 0) return void 0;
414
567
  const cached = codecs.get(codecId);
415
568
  if (cached !== void 0) return cached;
@@ -427,8 +580,8 @@ function printedTypeCodec(pslTypeName, isEnum) {
427
580
  * stores and reports verbatim. A default the codec refuses has no PSL literal, so the raw
428
581
  * expression prints instead of a schema `contract emit` would reject.
429
582
  */
430
- function printedDefaultReadsBack(value, pslTypeName, isEnum, isList) {
431
- const codec = printedTypeCodec(pslTypeName, isEnum);
583
+ function inferredDefaultReadsBack(value, pslTypeName, isEnum, isList) {
584
+ const codec = inferredTypeCodec(pslTypeName, isEnum);
432
585
  if (codec === void 0) return false;
433
586
  return (isList && Array.isArray(value) ? value : [value]).every((element) => {
434
587
  try {
@@ -439,59 +592,6 @@ function printedDefaultReadsBack(value, pslTypeName, isEnum, isList) {
439
592
  }
440
593
  });
441
594
  }
442
- function buildModelConstraintAttribute(name, fields, constraintName) {
443
- const args = [positionalArg(`[${fields.join(", ")}]`)];
444
- if (constraintName !== void 0) args.push(namedArg("map", `"${escapePslString(constraintName)}"`));
445
- return buildAttribute("model", name, args);
446
- }
447
- /**
448
- * Emits one `@@index` attribute at full fidelity. The index's identity is
449
- * re-detected rather than trusted: `name:` is emitted only when the live name
450
- * parses as a wire name AND that hash recomputes from the introspected
451
- * content; otherwise the live name is adopted verbatim with `map:`.
452
- */
453
- function buildIndexAttribute(index, fieldNames) {
454
- const args = [];
455
- if (fieldNames !== void 0) args.push(positionalArg(`[${fieldNames.join(", ")}]`));
456
- else {
457
- assertDefined(index.expression, `buildIndexAttribute: index "${index.name}" carries neither columns nor expression; SqlIndexIR enforces exactly one`);
458
- args.push(namedArg("expression", `"${escapePslString(index.expression)}"`));
459
- }
460
- const parsed = parseWireName(index.name);
461
- const recomputed = computeIndexContentHash({
462
- ...index.columns !== void 0 ? { columns: index.columns } : {},
463
- ...index.expression !== void 0 ? { expression: index.expression } : {},
464
- ...index.where !== void 0 ? { where: index.where } : {},
465
- unique: index.unique,
466
- ...index.type !== void 0 ? { type: index.type } : {},
467
- ...index.options !== void 0 ? { options: index.options } : {}
468
- });
469
- if (parsed !== void 0 && parsed.hash === recomputed) args.push(namedArg("name", `"${escapePslString(parsed.prefix)}"`));
470
- else args.push(namedArg("map", `"${escapePslString(index.name)}"`));
471
- if (index.where !== void 0) args.push(namedArg("where", `"${escapePslString(index.where)}"`));
472
- if (index.unique) args.push(namedArg("unique", "true"));
473
- const hasOptions = index.options !== void 0 && Object.keys(index.options).length > 0;
474
- if (index.type !== void 0 || hasOptions) args.push(namedArg("type", `"${escapePslString(index.type ?? "btree")}"`));
475
- if (hasOptions) {
476
- const entries = Object.entries(index.options ?? {}).sort(([a], [b]) => a < b ? -1 : a > b ? 1 : 0).map(([key, value]) => `${key}: "${escapePslString(String(value))}"`);
477
- args.push(namedArg("options", `{ ${entries.join(", ")} }`));
478
- }
479
- return buildAttribute("model", "index", args);
480
- }
481
- /**
482
- * Emits one `@@check` attribute for a live, non-derived check, always in the
483
- * `map:` form. Re-detecting `name:` is not attempted: the live expression is
484
- * Postgres's own reprint, but a wire-named check's hash was taken over the
485
- * author's original text, so recomputing the hash from the reprint would
486
- * essentially never match. `map:` plus the verbatim reprint is correct
487
- * regardless — a reprint compared against a later reprint of the same
488
- * expression is stable, so the emitted contract signs the live database with
489
- * zero pending operations. `buildPolicyBlocks` makes the same call for
490
- * `@@map` on adopted RLS policies, for the same reason.
491
- */
492
- function buildCheckAttribute(check) {
493
- return buildAttribute("model", "check", [namedArg("expression", `"${escapePslString(check.expression)}"`), namedArg("map", `"${escapePslString(check.name)}"`)]);
494
- }
495
595
  function buildModel(table, typeMap, enumNameMap, fieldNamesByTable, defaultMapping, rawDefaultParser, relationFields, danglingForeignKeys, rlsEnabled = false, policySkipNotes = []) {
496
596
  const { name: modelName, map: mapName } = toModelName(table.name);
497
597
  const fieldNameMap = fieldNamesByTable.get(table.name);
@@ -608,9 +708,9 @@ function buildScalarField(column, table, typeMap, enumNameMap, fieldNameMap, def
608
708
  const isEnumColumn = enumPslName !== void 0;
609
709
  const defaultAttribute = inferDefaultAttribute(column, rawDefaultParser, {
610
710
  ...defaultMapping,
611
- ...ifDefined("columnDataType", dataTypeForPrintedType(resolution.pslType.name, isEnumColumn)),
711
+ ...ifDefined("columnDataType", dataTypeForInferredType(resolution.pslType.name, isEnumColumn)),
612
712
  list: column.many === true
613
- }, (value) => printedDefaultReadsBack(value, resolution.pslType.name, isEnumColumn, column.many === true));
713
+ }, (value) => inferredDefaultReadsBack(value, resolution.pslType.name, isEnumColumn, column.many === true));
614
714
  if (defaultAttribute !== void 0) attributes.push(parseDefaultAttributeString(defaultAttribute));
615
715
  if (uniqueColumns.has(column.name) && !isId) {
616
716
  const uniqueConstraintName = uniqueColumns.get(column.name);
@@ -690,15 +790,18 @@ function buildRelationField(rel, hostTableName, fieldNamesByTable, usedFieldName
690
790
  span: SYNTHETIC_SPAN
691
791
  };
692
792
  }
693
- const POLICY_OPERATION_KEYWORD = {
694
- select: "policy_select",
695
- insert: "policy_insert",
696
- update: "policy_update",
697
- delete: "policy_delete",
698
- all: "policy_all"
699
- };
700
- /** The PSL tokenizer's identifier grammar: leading letter/underscore, then letters/digits/`_`/`-`. */
701
- const PSL_IDENTIFIER = /^[\p{L}_][\p{L}\p{N}_-]*$/u;
793
+ /**
794
+ * Resolves a `SqlColumnIR.default` value into a normalized {@link ColumnDefault}.
795
+ *
796
+ * `SqlSchemaIR` types the column default as `string` (a raw database default
797
+ * expression). Some legacy fixtures and tests still pass already-normalized
798
+ * `ColumnDefault` objects in the same slot, so we accept either shape
799
+ * defensively at runtime.
800
+ */
801
+ function parseColumnDefault(value, nativeType, rawDefaultParser) {
802
+ if (typeof value === "string") return rawDefaultParser ? rawDefaultParser(value, nativeType) : void 0;
803
+ return isColumnDefault(value) ? value : void 0;
804
+ }
702
805
  /** Replaces invalid character runs with `_`; prepends `_` when the first character is invalid. */
703
806
  function sanitizePolicyHead(raw) {
704
807
  let head = raw.replace(/[^\p{L}\p{N}_-]+/gu, "_");
@@ -713,7 +816,7 @@ function sanitizePolicyHead(raw) {
713
816
  * legal identifier cannot be authored at all — role references have no
714
817
  * `@@map` escape — so it is skipped with a note.
715
818
  */
716
- function buildPolicyBlocks(policiesByTable, modelNameMap, reservedHeads = /* @__PURE__ */ new Set()) {
819
+ function buildIntrospectedPolicyBlocks(policiesByTable, modelNameMap, reservedHeads = /* @__PURE__ */ new Set()) {
717
820
  const all = [];
718
821
  for (const [tableName, policies] of policiesByTable) for (const policy of policies) all.push({
719
822
  policy,
@@ -729,8 +832,8 @@ function buildPolicyBlocks(policiesByTable, modelNameMap, reservedHeads = /* @__
729
832
  const skipNotesByTable = /* @__PURE__ */ new Map();
730
833
  for (const { policy, tableName } of all) {
731
834
  const modelName = modelNameMap.get(tableName);
732
- assertDefined(modelName, `buildPolicyBlocks: policy "${policy.name}" targets table "${tableName}" with no emitted model; tables and policies come from the same introspection walk`);
733
- const badRole = policy.roles.find((role) => !PSL_IDENTIFIER.test(role));
835
+ assertDefined(modelName, `buildIntrospectedPolicyBlocks: policy "${policy.name}" targets table "${tableName}" with no emitted model; tables and policies come from the same introspection walk`);
836
+ const badRole = policy.roles.find((role) => !isPslIdentifier(role));
734
837
  if (badRole !== void 0) {
735
838
  const notes = skipNotesByTable.get(tableName) ?? [];
736
839
  notes.push(`// prisma: skipped policy "${policy.name}": role "${badRole}" is not a valid PSL identifier and role references cannot be escaped`);
@@ -746,7 +849,7 @@ function buildPolicyBlocks(policiesByTable, modelNameMap, reservedHeads = /* @__
746
849
  usedHeads.add(head);
747
850
  blocks.push({
748
851
  kind: "policy",
749
- keyword: POLICY_OPERATION_KEYWORD[policy.operation],
852
+ keyword: POLICY_BLOCK_KEYWORDS[policy.operation],
750
853
  name: head,
751
854
  parameters: {
752
855
  target: {
@@ -806,105 +909,6 @@ function createPostgresDefaultMapping() {
806
909
  dataTypes: createDataTypeLookup(postgresDataTypes)
807
910
  };
808
911
  }
809
- const POSTGRES_TO_PSL = {
810
- text: "String",
811
- bool: "Boolean",
812
- boolean: "Boolean",
813
- int4: "Int",
814
- integer: "Int",
815
- int8: "BigInt",
816
- bigint: "BigInt",
817
- float8: "Float",
818
- "double precision": "Float",
819
- jsonb: "Jsonb",
820
- bytea: "Bytes"
821
- };
822
- const PRESERVED_NATIVE_TYPES = {
823
- "character varying": "VarChar",
824
- character: "Char",
825
- char: "Char",
826
- varchar: "VarChar",
827
- uuid: "Uuid",
828
- inet: "Inet",
829
- int2: "SmallInt",
830
- smallint: "SmallInt",
831
- float4: "Real",
832
- real: "Real",
833
- numeric: "Numeric",
834
- decimal: "Numeric",
835
- timestamp: "Timestamp",
836
- "timestamp without time zone": "Timestamp",
837
- timestamptz: "Timestamptz",
838
- "timestamp with time zone": "Timestamptz",
839
- date: "Date",
840
- time: "Time",
841
- "time without time zone": "Time",
842
- timetz: "Timetz",
843
- "time with time zone": "Timetz",
844
- json: "Json"
845
- };
846
- const PARAMETERIZED_NATIVE_TYPES = {
847
- "character varying": "VarChar",
848
- character: "Char",
849
- char: "Char",
850
- varchar: "VarChar",
851
- numeric: "Numeric",
852
- decimal: "Numeric",
853
- timestamp: "Timestamp",
854
- timestamptz: "Timestamptz",
855
- time: "Time",
856
- timetz: "Timetz"
857
- };
858
- [
859
- ...Object.values(POSTGRES_TO_PSL),
860
- ...Object.values(PRESERVED_NATIVE_TYPES),
861
- ...Object.values(PARAMETERIZED_NATIVE_TYPES)
862
- ];
863
- const PARAMETERIZED_TYPE_PATTERN = /^(.+?)\((.+)\)$/;
864
- function getOwnMappingValue(map, key) {
865
- return Object.hasOwn(map, key) ? map[key] : void 0;
866
- }
867
- function splitTypeParameterList(params) {
868
- return params.split(",").map((part) => part.trim()).filter((part) => part.length > 0);
869
- }
870
- function createPostgresTypeMap(enumTypeNames) {
871
- return { resolve(nativeType) {
872
- if (enumTypeNames?.has(nativeType)) return {
873
- pslType: { name: nativeType },
874
- nativeType
875
- };
876
- const paramMatch = nativeType.match(PARAMETERIZED_TYPE_PATTERN);
877
- if (paramMatch) {
878
- const [, baseType = nativeType, params = ""] = paramMatch;
879
- const typeName = getOwnMappingValue(PARAMETERIZED_NATIVE_TYPES, baseType);
880
- if (typeName) return {
881
- pslType: {
882
- name: typeName,
883
- args: splitTypeParameterList(params)
884
- },
885
- nativeType,
886
- typeParams: {
887
- baseType,
888
- params
889
- }
890
- };
891
- }
892
- const preservedType = getOwnMappingValue(PRESERVED_NATIVE_TYPES, nativeType);
893
- if (preservedType) return {
894
- pslType: { name: preservedType },
895
- nativeType
896
- };
897
- const pslType = getOwnMappingValue(POSTGRES_TO_PSL, nativeType);
898
- if (pslType) return {
899
- pslType: { name: pslType },
900
- nativeType
901
- };
902
- return {
903
- unsupported: true,
904
- nativeType
905
- };
906
- } };
907
- }
908
912
  /**
909
913
  * Infers a PSL AST (for `printPsl`) from an introspected Postgres schema tree.
910
914
  *
@@ -1037,7 +1041,7 @@ function buildPslDocumentAst(schemaIR, options, foreignKeyExtras, namespaceName,
1037
1041
  if (namespaceName !== void 0) for (const [typeName, pslName] of bareEnumNameMap) enumNameMap.set(`${namespaceName}.${typeName}`, pslName);
1038
1042
  const fieldNamesByTable = new Map([...crossSpaceFieldNamesByTable, ...buildFieldNamesByTable(schemaIR.tables)]);
1039
1043
  const { relationsByTable } = inferRelations(schemaIR.tables, modelNameMap);
1040
- const policyEmission = buildPolicyBlocks(rlsExtras?.policiesByTable ?? /* @__PURE__ */ new Map(), modelNameMap, /* @__PURE__ */ new Set([
1044
+ const policyEmission = buildIntrospectedPolicyBlocks(rlsExtras?.policiesByTable ?? /* @__PURE__ */ new Map(), modelNameMap, /* @__PURE__ */ new Set([
1041
1045
  ...modelNameMap.values(),
1042
1046
  ...bareEnumNameMap.values(),
1043
1047
  ...topLevelExtensionBlocks.map((block) => block.name)
@@ -1083,6 +1087,6 @@ function buildPslDocumentAst(schemaIR, options, foreignKeyExtras, namespaceName,
1083
1087
  };
1084
1088
  }
1085
1089
  //#endregion
1086
- export { inferPostgresPslContract as i, createPostgresDefaultMapping as n, createPostgresTypeMap as r, buildPslDocumentAst as t };
1090
+ export { buildMapAttribute as a, buildPslDocumentAst as c, inferPostgresPslContract as d, namedArg as f, buildIndexAttribute as i, createPostgresDefaultMapping as l, positionalArg as m, buildAttribute as n, buildModelConstraintAttribute as o, parseDefaultAttributeString as p, buildCheckAttribute as r, buildNativeEnumBlock as s, SYNTHETIC_SPAN as t, createPostgresTypeMap as u };
1087
1091
 
1088
- //# sourceMappingURL=infer-psl-contract-B9Hs0kKm-Cp7_uC0O.mjs.map
1092
+ //# sourceMappingURL=infer-psl-contract-DEHd6IMV-D1FmIxJC.mjs.map