@prisma/orm-family-sql 8.0.0-rc.15-dev.2 → 8.0.0-rc.15-dev.3

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 (75) hide show
  1. package/dist/{authoring-type-constructors-dihiQslc-DqtjQyqj.mjs → authoring-type-constructors-dihiQslc-B5nYi7p2.mjs} +2 -2
  2. package/dist/{authoring-type-constructors-dihiQslc-DqtjQyqj.mjs.map → authoring-type-constructors-dihiQslc-B5nYi7p2.mjs.map} +1 -1
  3. package/dist/{config-types-CPTtyHK8.mjs → config-types-BMRDvgSW.mjs} +2 -2
  4. package/dist/{config-types-CPTtyHK8.mjs.map → config-types-BMRDvgSW.mjs.map} +1 -1
  5. package/dist/{contract-builder-Dy172HD2.mjs → contract-builder-83EIkQrg.mjs} +8 -8
  6. package/dist/{contract-builder-Dy172HD2.mjs.map → contract-builder-83EIkQrg.mjs.map} +1 -1
  7. package/dist/contract-prisma7__provider.mjs +23 -17
  8. package/dist/contract-prisma7__provider.mjs.map +1 -1
  9. package/dist/contract-psl.d.mts +6 -6
  10. package/dist/contract-psl.d.mts.map +1 -1
  11. package/dist/contract-psl.mjs +1 -1
  12. package/dist/contract-psl__attribute-specs.d.mts +2 -3
  13. package/dist/contract-psl__attribute-specs.d.mts.map +1 -1
  14. package/dist/contract-psl__attribute-specs.mjs +1 -1
  15. package/dist/contract-psl__provider.mjs +3 -3
  16. package/dist/contract-psl__provider.mjs.map +1 -1
  17. package/dist/contract-ts.mjs +3 -3
  18. package/dist/contract-ts__config-types.mjs +1 -1
  19. package/dist/contract-ts__contract-builder.mjs +2 -2
  20. package/dist/contract.d.mts +3 -3
  21. package/dist/contract.mjs +3 -3
  22. package/dist/contract__data-type-support.d.mts +2 -2
  23. package/dist/contract__data-type-support.mjs +2 -2
  24. package/dist/contract__validators.d.mts +2 -2
  25. package/dist/contract__validators.mjs +2 -2
  26. package/dist/{control-D18L8cFa.d.mts → control-Bi2JsNep.d.mts} +6 -6
  27. package/dist/control-Bi2JsNep.d.mts.map +1 -0
  28. package/dist/{control-CMe5ABYI.mjs → control-ihau09EM.mjs} +6 -6
  29. package/dist/control-ihau09EM.mjs.map +1 -0
  30. package/dist/{data-type-support-DoxtCfXq.d.mts → data-type-support-4TcZuD7d.d.mts} +6 -6
  31. package/dist/{data-type-support-DoxtCfXq.d.mts.map → data-type-support-4TcZuD7d.d.mts.map} +1 -1
  32. package/dist/{data-type-support-DeL6iJt8.mjs → data-type-support-Bu-VpT7z.mjs} +7 -7
  33. package/dist/data-type-support-Bu-VpT7z.mjs.map +1 -0
  34. package/dist/{derived-checks-DAbro9yn-DtEowq-J.mjs → derived-checks-DAbro9yn-BgBbql-q.mjs} +2 -2
  35. package/dist/{derived-checks-DAbro9yn-DtEowq-J.mjs.map → derived-checks-DAbro9yn-BgBbql-q.mjs.map} +1 -1
  36. package/dist/family.d.mts +6 -6
  37. package/dist/family.mjs +5 -5
  38. package/dist/family__control.d.mts +3 -3
  39. package/dist/family__control.mjs +3 -3
  40. package/dist/family__ir.mjs +1 -1
  41. package/dist/family__pack.mjs +2 -2
  42. package/dist/family__psl-build.d.mts +2 -2
  43. package/dist/family__psl-build.mjs +1 -1
  44. package/dist/family__psl-infer.d.mts +1 -1
  45. package/dist/{interpreter-D50jf6Dd-BW-Bj8Qr.mjs → interpreter-BF5Xrf3W-DK928Clg.mjs} +14 -20
  46. package/dist/interpreter-BF5Xrf3W-DK928Clg.mjs.map +1 -0
  47. package/dist/{psl-build-C1P-sV0c.mjs → psl-build-B_fRV6lN.mjs} +34 -33
  48. package/dist/psl-build-B_fRV6lN.mjs.map +1 -0
  49. package/dist/{psl-build-ClK2AyY1.d.mts → psl-build-C_n5uPZH.d.mts} +2 -2
  50. package/dist/psl-build-C_n5uPZH.d.mts.map +1 -0
  51. package/dist/{psl-column-resolution-BegCa1-t-1XiYCC7t.d.mts → psl-column-resolution-CNtNJ7g7-CR_auHUV.d.mts} +5 -7
  52. package/dist/psl-column-resolution-CNtNJ7g7-CR_auHUV.d.mts.map +1 -0
  53. package/dist/{psl-field-resolution-Bi-CSeoQ-Do_5hZ8Z.mjs → psl-field-resolution-DUCrDnuq-BXwISml1.mjs} +222 -279
  54. package/dist/psl-field-resolution-DUCrDnuq-BXwISml1.mjs.map +1 -0
  55. package/dist/{psl-infer-B91bSSdN.d.mts → psl-infer-Cm7eDSA-.d.mts} +2 -2
  56. package/dist/{psl-infer-B91bSSdN.d.mts.map → psl-infer-Cm7eDSA-.d.mts.map} +1 -1
  57. package/dist/{sql-contract-serializer-DDaAVCQr-h_U10PEJ.mjs → sql-contract-serializer-DDaAVCQr-D40NltYi.mjs} +2 -2
  58. package/dist/{sql-contract-serializer-DDaAVCQr-h_U10PEJ.mjs.map → sql-contract-serializer-DDaAVCQr-D40NltYi.mjs.map} +1 -1
  59. package/dist/{type-map-dnvRKl9o-avUb9OLv.d.mts → type-map-3w0ieDAb-DiMpKEc2.d.mts} +6 -8
  60. package/dist/type-map-3w0ieDAb-DiMpKEc2.d.mts.map +1 -0
  61. package/dist/{validators-BLkHaNpd.d.mts → validators-BAa0JKuB.d.mts} +7 -7
  62. package/dist/{validators-BLkHaNpd.d.mts.map → validators-BAa0JKuB.d.mts.map} +1 -1
  63. package/dist/{validators-BF_JSK38.mjs → validators-Ddcw8nHL.mjs} +9 -9
  64. package/dist/validators-Ddcw8nHL.mjs.map +1 -0
  65. package/package.json +18 -18
  66. package/dist/control-CMe5ABYI.mjs.map +0 -1
  67. package/dist/control-D18L8cFa.d.mts.map +0 -1
  68. package/dist/data-type-support-DeL6iJt8.mjs.map +0 -1
  69. package/dist/interpreter-D50jf6Dd-BW-Bj8Qr.mjs.map +0 -1
  70. package/dist/psl-build-C1P-sV0c.mjs.map +0 -1
  71. package/dist/psl-build-ClK2AyY1.d.mts.map +0 -1
  72. package/dist/psl-column-resolution-BegCa1-t-1XiYCC7t.d.mts.map +0 -1
  73. package/dist/psl-field-resolution-Bi-CSeoQ-Do_5hZ8Z.mjs.map +0 -1
  74. package/dist/type-map-dnvRKl9o-avUb9OLv.d.mts.map +0 -1
  75. package/dist/validators-BF_JSK38.mjs.map +0 -1
@@ -1,8 +1,8 @@
1
1
  import { s as sqlTextFromCanonical, t as SQL_EXPRESSION_DATA_TYPE_ID } from "./sql-expression-D7GsLgDM.mjs";
2
- import { n as checkSqlDefaultBody, o as reservedSqlDefaultBody } from "./validators-BF_JSK38.mjs";
3
- import { a as storedAsListColumn, i as isValueObjectMember } from "./derived-checks-DAbro9yn-DtEowq-J.mjs";
2
+ import { n as checkSqlDefaultText, o as reservedSqlDefaultText } from "./validators-Ddcw8nHL.mjs";
3
+ import { a as storedAsListColumn, i as isValueObjectMember } from "./derived-checks-DAbro9yn-BgBbql-q.mjs";
4
4
  import { structuredError } from "@prisma/orm-framework/utils/structured-error";
5
- import { authoringEntryType, instantiateAuthoringTypeConstructor, isAuthoringEntityTypeDescriptor, validateAuthoringHelperArguments, validateAuthoringTypeParams } from "@prisma/orm-framework/components/authoring";
5
+ import { admittedForms, castTypedValue, describeExpected, describeRefusal, describeRefusedValueType, exactRewrite, instantiateAuthoringTypeConstructor, isAuthoringEntityTypeDescriptor, readWrittenValue, tagForm, validateAuthoringHelperArguments, validateAuthoringTypeParams } from "@prisma/orm-framework/components/authoring";
6
6
  import { canonicalFormOf, codecForRef } from "@prisma/orm-framework/components/codec";
7
7
  import { blindCast } from "@prisma/orm-framework/utils/casts";
8
8
  import { ifDefined } from "@prisma/orm-framework/utils/defined";
@@ -13,7 +13,7 @@ import { describeTaggedLiteralFailure } from "@prisma/orm-framework/components/c
13
13
  import { notOk, ok } from "@prisma/orm-framework/utils/result";
14
14
  import { bool, diagnosticSource, entityRef, fieldAttribute, fieldRef, funcCall, identifier, interpretAttribute, leafDiagnostic, list, modelAttribute, nodePslSpan, numLiteral, oneOf, optional, record, referencedFieldRef, str, taggedLiteral, typeReferenceNode } from "@prisma/orm-framework/psl-parser";
15
15
  import { instantiatePslFieldPreset, isBareTypeConstructor, mapPslHelperArgs, reportPresetNotCalled, reportTypeConstructorNotCalled } from "@prisma/orm-framework/psl-parser/interpret";
16
- //#region ../../../2-sql/2-authoring/contract-psl/dist/psl-field-resolution-Bi-CSeoQ.mjs
16
+ //#region ../../../2-sql/2-authoring/contract-psl/dist/psl-field-resolution-DUCrDnuq.mjs
17
17
  function storageName(symbol, physicalNames) {
18
18
  const name = physicalNames.get(symbol);
19
19
  assertDefined(name, "Physical names are populated for every model and field before lowering");
@@ -58,124 +58,32 @@ const PSL_INVALID_DEFAULT_LITERAL = "PSL_INVALID_DEFAULT_LITERAL";
58
58
  const PSL_VALUE_TYPE_INCOMPATIBLE = "PSL_VALUE_TYPE_INCOMPATIBLE";
59
59
  /** A single value written as the default of a column that holds a list. */
60
60
  const PSL_DEFAULT_LIST_EXPECTED = "PSL_DEFAULT_LIST_EXPECTED";
61
- /** The entry a tag names, or `undefined` when no pack registered that tag. */
62
- function entryForTag(support, tag) {
63
- for (const [key, entry] of Object.entries(support.entries)) if (entry.written.kind === "tag" && entry.written.tag === tag) return {
64
- key,
65
- entry
66
- };
67
- }
68
- /** Every tag a stack registers, in the order the entries were merged, for a diagnostic. */
69
- function knownTags(support) {
70
- return Object.values(support.entries).flatMap((entry) => entry.written.kind === "tag" ? [entry.written.tag] : []);
71
- }
72
- function entryForPlain(support, syntax) {
73
- for (const [key, entry] of Object.entries(support.entries)) if (entry.written.kind === "plain" && entry.written.syntax === syntax) return {
74
- key,
75
- entry
76
- };
77
- }
78
- /** The text an entry reads: a tag's text, a string's value, or the word a boolean is written as. */
79
- function plainText(written) {
80
- switch (written.kind) {
81
- case "tag": return written.text;
82
- case "string": return written.text;
83
- case "boolean": return String(written.value);
84
- case "number": return written.text;
85
- }
86
- }
87
61
  function messageOf(error) {
88
62
  return error instanceof Error ? error.message : String(error);
89
63
  }
90
- /** Read one written value through the entry for its syntax. */
91
- function readValue(support, written, elementIndex) {
92
- const refuse = (refusal) => ({
64
+ function refused(refusal, suggestedTypes) {
65
+ return {
93
66
  ok: false,
94
- refusal: blindCast({
95
- ...refusal,
96
- elementIndex
97
- })
98
- });
99
- const found = written.kind === "tag" ? entryForTag(support, written.tag) : entryForPlain(support, written.kind);
100
- if (found === void 0) return written.kind === "tag" ? refuse({
101
- kind: "unknown-tag",
102
- tag: written.tag,
103
- known: knownTags(support)
104
- }) : refuse({
105
- kind: "unwritable",
106
- syntax: written.kind
107
- });
108
- const form = found.entry.written;
109
- if (form.kind === "plain" && form.syntax === "number") {
110
- const text = plainText(written);
111
- const classified = form.classify(text);
112
- if (classified === void 0) return refuse({
113
- kind: "unreadable",
114
- message: `no data type of this target holds the number ${text}`
115
- });
116
- return {
117
- ok: true,
118
- typed: classified
119
- };
120
- }
121
- const text = plainText(written);
122
- try {
123
- return {
124
- ok: true,
125
- typed: {
126
- type: blindCast(authoringEntryType(found.key, found.entry)),
127
- value: form.parse(text)
128
- }
129
- };
130
- } catch (error) {
131
- if (isInternalError(error)) throw error;
132
- return refuse({
133
- kind: "unreadable",
134
- message: messageOf(error)
135
- });
136
- }
67
+ refusal,
68
+ suggestedTypes
69
+ };
137
70
  }
138
- /** Convert a value of one data type into the form another stores, when that type takes it. */
139
- function castInto(support, columnType, typed, elementIndex) {
140
- if (typed.type === columnType) return {
71
+ function readOneValue(dataTypes, written, elementIndex, suggestedTypes) {
72
+ const read = readWrittenValue(dataTypes, written);
73
+ return read.ok ? {
141
74
  ok: true,
142
- value: typed.value
143
- };
144
- const declaration = support.lookup.get(columnType);
145
- const cast = declaration?.casts[typed.type];
146
- if (cast === void 0) return {
147
- ok: false,
148
- refusal: {
149
- kind: "no-cast",
150
- columnType,
151
- valueType: typed.type,
152
- casts: Object.keys(declaration?.casts ?? {}),
153
- elementIndex
154
- }
155
- };
156
- try {
157
- return {
158
- ok: true,
159
- value: cast(typed.value)
160
- };
161
- } catch (error) {
162
- if (isInternalError(error)) throw error;
163
- return {
164
- ok: false,
165
- refusal: {
166
- kind: "unreadable",
167
- message: messageOf(error),
168
- elementIndex
169
- }
170
- };
171
- }
75
+ typed: read.value
76
+ } : refused({
77
+ ...read.failure,
78
+ elementIndex
79
+ }, suggestedTypes);
172
80
  }
173
81
  /** The column's `typeParams` as the codec reference carries them, so `vector(3)` checks its length. */
174
82
  function codecRefTypeParams(typeParams) {
175
83
  return typeParams === void 0 ? void 0 : blindCast(typeParams);
176
84
  }
177
85
  /** A value in the canonical form of the column's values, when they have one. */
178
- function inCanonicalForm(toCanonicalForm, value, elementIndex) {
86
+ function inCanonicalForm(toCanonicalForm, value, elementIndex, suggestedTypes) {
179
87
  if (toCanonicalForm === void 0) return {
180
88
  ok: true,
181
89
  value
@@ -193,7 +101,8 @@ function inCanonicalForm(toCanonicalForm, value, elementIndex) {
193
101
  kind: "unreadable",
194
102
  message: messageOf(error),
195
103
  elementIndex
196
- }
104
+ },
105
+ suggestedTypes
197
106
  };
198
107
  }
199
108
  }
@@ -207,6 +116,7 @@ function storedValueReader(input) {
207
116
  ...ifDefined("typeParams", codecRefTypeParams(input.column.typeParams))
208
117
  });
209
118
  if (codec === void 0 || descriptor === void 0) throw new InternalError(`Field "${input.fieldPath}": no codec descriptor is registered for "${input.column.codecId}", but the column was resolved from one.`);
119
+ const suggestedTypes = [descriptor.dataType];
210
120
  const toCanonicalForm = canonicalFormOf(descriptor, input.dataTypeLookup);
211
121
  const read = (written, elementIndex) => {
212
122
  try {
@@ -220,10 +130,11 @@ function storedValueReader(input) {
220
130
  codecId: input.column.codecId,
221
131
  message: messageOf(error),
222
132
  elementIndex
223
- }
133
+ },
134
+ suggestedTypes
224
135
  };
225
136
  }
226
- return inCanonicalForm(toCanonicalForm, written, elementIndex);
137
+ return inCanonicalForm(toCanonicalForm, written, elementIndex, suggestedTypes);
227
138
  };
228
139
  return {
229
140
  descriptor,
@@ -231,11 +142,11 @@ function storedValueReader(input) {
231
142
  };
232
143
  }
233
144
  /**
234
- * Reads a value already in its stored JSON form, such as one member of a JSON document default, with the column's codec. Worded as {@link lowerDataTypeDefault} words a codec refusal.
145
+ * Reads a value already in its stored JSON form, such as one member of a JSON document default, with the column's codec, and gives it the canonical form of the column's values. Worded as {@link lowerDataTypeDefault} words the same refusals.
235
146
  */
236
147
  function readStoredValue(input) {
237
148
  const reading = storedValueReader(input).read(input.value, void 0);
238
- return reading.ok ? reading : refusalDiagnostic(reading.refusal, `Field "${input.fieldPath}"`);
149
+ return reading.ok ? reading : storedRefusalDiagnostic(reading.refusal, `Field "${input.fieldPath}"`);
239
150
  }
240
151
  /**
241
152
  * Read one `@default(...)` value for a column, refusing in parts so each contract source words its
@@ -246,37 +157,31 @@ function readStoredValue(input) {
246
157
  function readDataTypeDefault(input) {
247
158
  const { descriptor, read: readStored } = storedValueReader({
248
159
  ...input,
249
- dataTypeLookup: input.support.lookup
160
+ dataTypeLookup: input.dataTypes.lookup
250
161
  });
251
162
  const columnType = descriptor.dataType;
163
+ const suggestedTypes = [columnType];
252
164
  const readOne = (written, elementIndex) => {
253
- const read = readValue(input.support, written, elementIndex);
165
+ const read = readOneValue(input.dataTypes, written, elementIndex, suggestedTypes);
254
166
  if (!read.ok) return read;
255
- const cast = castInto(input.support, columnType, read.typed, elementIndex);
256
- if (!cast.ok) return cast;
257
- return readStored(cast.value, elementIndex);
167
+ const cast = castTypedValue(input.dataTypes, columnType, read.typed);
168
+ if (!cast.ok) return refused({
169
+ ...cast.failure,
170
+ elementIndex
171
+ }, suggestedTypes);
172
+ return readStored(cast.value.value, elementIndex);
258
173
  };
259
174
  if (input.written.kind !== "list") {
260
- if (input.isList) return {
261
- ok: false,
262
- refusal: {
263
- kind: "not-a-list",
264
- elementIndex: void 0
265
- }
266
- };
175
+ if (input.isList) return refused({
176
+ kind: "not-a-list",
177
+ elementIndex: void 0
178
+ }, suggestedTypes);
267
179
  return readOne(input.written, void 0);
268
180
  }
269
181
  if (input.isList) {
270
182
  const elements = [];
271
183
  for (const [elementIndex, written] of input.written.elements.entries()) {
272
- if (written.kind === "list") return {
273
- ok: false,
274
- refusal: {
275
- kind: "unreadable",
276
- message: "a list holds values, not other lists",
277
- elementIndex
278
- }
279
- };
184
+ if (written.kind === "list") return nestedList(elementIndex, suggestedTypes);
280
185
  const element = readOne(written, elementIndex);
281
186
  if (!element.ok) return element;
282
187
  elements.push(element.value);
@@ -293,122 +198,159 @@ function readDataTypeDefault(input) {
293
198
  readStored
294
199
  });
295
200
  }
201
+ function nestedList(elementIndex, suggestedTypes) {
202
+ return refused({
203
+ kind: "unreadable",
204
+ message: "a list holds values, not other lists",
205
+ elementIndex
206
+ }, suggestedTypes);
207
+ }
296
208
  /** A written list on a column that is not a list: the column's type takes it through its list cast. */
297
209
  function readListIntoScalar(input) {
298
- const listCast = input.support.lookup.get(input.columnType)?.listCast;
299
- if (listCast === void 0) return {
300
- ok: false,
301
- refusal: {
302
- kind: "no-cast",
303
- columnType: input.columnType,
304
- valueType: "a list",
305
- casts: Object.keys(input.support.lookup.get(input.columnType)?.casts ?? {}),
306
- elementIndex: void 0
307
- }
308
- };
210
+ const declaration = input.dataTypes.lookup.get(input.columnType);
211
+ const listCast = declaration?.listCast;
212
+ if (listCast === void 0) return refused({
213
+ kind: "no-list-cast",
214
+ receivingType: input.columnType,
215
+ casts: Object.keys(declaration?.casts ?? {}),
216
+ elementIndex: void 0
217
+ }, [input.columnType]);
309
218
  const elements = [];
310
219
  for (const [elementIndex, written] of input.written.elements.entries()) {
311
- if (written.kind === "list") return {
312
- ok: false,
313
- refusal: {
314
- kind: "unreadable",
315
- message: "a list holds values, not other lists",
316
- elementIndex
317
- }
318
- };
319
- const read = readValue(input.support, written, elementIndex);
220
+ if (written.kind === "list") return nestedList(elementIndex, listCast.of);
221
+ const read = readOneValue(input.dataTypes, written, elementIndex, listCast.of);
320
222
  if (!read.ok) return read;
321
- if (!listCast.of.includes(read.typed.type)) return {
322
- ok: false,
323
- refusal: {
324
- kind: "no-cast",
325
- columnType: input.columnType,
326
- valueType: read.typed.type,
327
- casts: [...listCast.of],
328
- elementIndex
329
- }
330
- };
223
+ if (!listCast.of.includes(read.typed.type)) return refused({
224
+ kind: "no-element-cast",
225
+ receivingType: input.columnType,
226
+ valueType: read.typed.type,
227
+ elementTypes: listCast.of,
228
+ elementIndex
229
+ }, listCast.of);
331
230
  elements.push(read.typed.value);
332
231
  }
333
232
  try {
334
233
  return input.readStored(listCast.cast(elements), void 0);
335
234
  } catch (error) {
336
235
  if (isInternalError(error)) throw error;
337
- return {
338
- ok: false,
339
- refusal: {
340
- kind: "unreadable",
341
- message: messageOf(error),
342
- elementIndex: void 0
343
- }
344
- };
236
+ return refused({
237
+ kind: "unreadable",
238
+ message: messageOf(error),
239
+ elementIndex: void 0
240
+ }, [input.columnType]);
345
241
  }
346
242
  }
347
- /** Where in a written list a diagnostic is about, for a message: ` at element 2`. */
348
- function at(elementIndex) {
349
- return elementIndex === void 0 ? "" : ` at element ${elementIndex + 1}`;
243
+ /** Where a diagnostic is about, for a message: `Field "N.count" at element 2`. */
244
+ function location(subject, elementIndex) {
245
+ return elementIndex === void 0 ? subject : `${subject} at element ${elementIndex + 1}`;
246
+ }
247
+ /**
248
+ * What may be written where every one of `types` is received, each form once: `a number`. A column
249
+ * whose type nothing writes still takes a `sql` literal, which `@default` stores as a SQL expression.
250
+ */
251
+ function formsOf(dataTypes, types) {
252
+ const forms = admittedForms(dataTypes, types);
253
+ return forms.length === 0 ? [tagForm("sql")] : forms;
254
+ }
255
+ /** The exact rewrite of the written value a `no-cast` refusal is about, before list elements are renumbered to the source list. */
256
+ function rewriteOf(refusal, written, dataTypes) {
257
+ if (refusal.kind !== "no-cast") return void 0;
258
+ const refused = refusal.elementIndex === void 0 || written.kind !== "list" ? written : written.elements[refusal.elementIndex];
259
+ return refused === void 0 || refused.kind === "list" ? void 0 : exactRewrite(dataTypes, refusal.receivingType, refused);
350
260
  }
351
261
  /** {@link readDataTypeDefault} worded as a PSL diagnostic's code and message. */
352
262
  function lowerDataTypeDefault(input) {
353
263
  const read = readDataTypeDefault(input);
354
- return read.ok ? read : refusalDiagnostic(read.refusal, `Field "${input.fieldPath}"`);
264
+ return read.ok ? read : refusalDiagnostic(atSourceElement(read.refusal, input.sourceElementIndexes), `Field "${input.fieldPath}"`, input.dataTypes, guidanceFor(read, input.written, input.dataTypes));
355
265
  }
356
266
  /**
357
267
  * Reads one number literal written in a contract source outside a default, such as an enum member's value, from its source text for a codec, as {@link lowerDataTypeDefault} reads a default: the number's entry gives it a data type, the codec's data type takes it directly or through a cast, and the codec checks it. A refusal is worded for `subject`.
358
268
  */
359
269
  function readWrittenNumberForCodec(input) {
270
+ const written = {
271
+ kind: "number",
272
+ text: input.text
273
+ };
360
274
  const read = readDataTypeDefault({
361
- written: {
362
- kind: "number",
363
- text: input.text
364
- },
275
+ written,
365
276
  isList: false,
366
277
  column: { codecId: input.codecId },
367
278
  codecLookup: input.codecLookup,
368
- support: input.support,
279
+ dataTypes: input.dataTypes,
369
280
  fieldPath: input.subject
370
281
  });
371
- return read.ok ? read : refusalDiagnostic(read.refusal, input.subject);
282
+ return read.ok ? read : refusalDiagnostic(read.refusal, input.subject, input.dataTypes, guidanceFor(read, written, input.dataTypes));
283
+ }
284
+ /** What a refusal of `written` tells the author to write instead. */
285
+ function guidanceFor(failure, written, dataTypes) {
286
+ return {
287
+ forms: formsOf(dataTypes, failure.suggestedTypes),
288
+ rewrite: rewriteOf(failure.refusal, written, dataTypes)
289
+ };
290
+ }
291
+ function atSourceElement(refusal, sourceElementIndexes) {
292
+ if (refusal.elementIndex === void 0) return refusal;
293
+ const elementIndex = sourceElementIndexes?.[refusal.elementIndex];
294
+ return elementIndex === void 0 ? refusal : {
295
+ ...refusal,
296
+ elementIndex
297
+ };
372
298
  }
373
- /** A refusal worded as a PSL diagnostic's code and message. */
374
- function refusalDiagnostic(refusal, subject) {
375
- const where = `${subject}${at(refusal.elementIndex)}`;
299
+ function codecRefusalDiagnostic(refusal, subject) {
300
+ return {
301
+ ok: false,
302
+ code: PSL_INVALID_DEFAULT_LITERAL,
303
+ message: `${location(subject, refusal.elementIndex)}: ${refusal.message}`,
304
+ place: { kind: "attribute" }
305
+ };
306
+ }
307
+ function storedRefusalDiagnostic(refusal, subject) {
308
+ if (refusal.kind === "refused-by-codec") return codecRefusalDiagnostic(refusal, subject);
309
+ return {
310
+ ok: false,
311
+ code: "PSL_INVALID_LITERAL",
312
+ message: `${location(subject, refusal.elementIndex)}: ${refusal.message}`,
313
+ place: { kind: "attribute" }
314
+ };
315
+ }
316
+ /** A refusal worded as a PSL diagnostic's code, message and place; `guidance` says what to write instead. */
317
+ function refusalDiagnostic(refusal, subject, dataTypes, guidance) {
318
+ const where = location(subject, refusal.elementIndex);
319
+ const atWrittenValue = {
320
+ kind: "written-value",
321
+ elementIndex: refusal.elementIndex
322
+ };
376
323
  switch (refusal.kind) {
377
- case "unreadable": return {
378
- ok: false,
379
- code: "PSL_INVALID_LITERAL",
380
- message: `${where}: ${refusal.message}`
381
- };
382
- case "unknown-tag": return {
383
- ok: false,
384
- code: "PSL_UNKNOWN_LITERAL_TAG",
385
- message: `Unknown literal tag "${refusal.tag}". Known tags: ${refusal.known.join(", ")}.`
386
- };
387
- case "unwritable": return {
388
- ok: false,
389
- code: PSL_VALUE_TYPE_INCOMPATIBLE,
390
- message: `${where}: this target has no data type for a ${refusal.syntax} value`
391
- };
392
324
  case "not-a-list": return {
393
325
  ok: false,
394
326
  code: PSL_DEFAULT_LIST_EXPECTED,
395
- message: `${where}: this column holds a list, so its default is a list literal, as in [1, 2]`
327
+ message: `${where}: this column holds a list, so its default is a list literal, as in [1, 2]`,
328
+ place: { kind: "attribute" }
396
329
  };
397
- case "no-cast": return {
330
+ case "refused-by-codec": return codecRefusalDiagnostic(refusal, subject);
331
+ case "no-list-cast": return {
398
332
  ok: false,
399
333
  code: PSL_VALUE_TYPE_INCOMPATIBLE,
400
- message: `${where}: ${refusal.columnType} has no cast from ${refusal.valueType}; ${describeCasts(refusal.casts)}`
334
+ message: `${where}: ${describeExpected(guidance.forms)}; got a list`,
335
+ place: atWrittenValue
401
336
  };
402
- case "refused-by-codec": return {
337
+ case "no-element-cast": return {
403
338
  ok: false,
404
- code: PSL_INVALID_DEFAULT_LITERAL,
405
- message: `${where}: ${refusal.message}`
339
+ code: PSL_VALUE_TYPE_INCOMPATIBLE,
340
+ message: `${where}: ${describeRefusedValueType(refusal, dataTypes, guidance)}`,
341
+ place: atWrittenValue
406
342
  };
343
+ default: {
344
+ const { code, message } = describeRefusal(refusal, dataTypes, guidance);
345
+ return {
346
+ ok: false,
347
+ code,
348
+ message: `${where}: ${message}`,
349
+ place: atWrittenValue
350
+ };
351
+ }
407
352
  }
408
353
  }
409
- function describeCasts(casts) {
410
- return casts.length === 0 ? "it casts from nothing" : `it casts from ${casts.join(", ")}`;
411
- }
412
354
  function formatSupportedFunctionList(registry) {
413
355
  const signatures = Array.from(registry.entries()).sort(([a], [b]) => a.localeCompare(b)).flatMap(([functionName, entry]) => {
414
356
  const usageSignatures = entry.usageSignatures?.filter((signature) => signature.length > 0);
@@ -524,29 +466,32 @@ function nullLiteral() {
524
466
  }
525
467
  };
526
468
  }
527
- function scalarDefaultArms(isList, registries) {
528
- const tagsByDocumentation = /* @__PURE__ */ new Map();
529
- for (const entry of Object.values(registries.dataTypeEntries)) {
530
- if (entry.written.kind !== "tag") continue;
531
- const tags = tagsByDocumentation.get(entry.documentation);
532
- if (tags === void 0) tagsByDocumentation.set(entry.documentation, [entry.written.tag]);
533
- else tags.push(entry.written.tag);
534
- }
535
- const tagArms = () => [...tagsByDocumentation].map(([documentation, tags]) => taggedLiteral(tags, { documentation }));
536
- const literal = () => oneOf(str(), numLiteral(), bool(), nullLiteral(), ...tagArms());
469
+ function scalarDefaultArms(isList, dataTypes, registries) {
470
+ const tagArms = (admits) => {
471
+ const tagsByDocumentation = /* @__PURE__ */ new Map();
472
+ for (const [dataType, entry] of Object.entries(dataTypes.entries)) {
473
+ if (entry.written.kind !== "tag" || !admits(dataType)) continue;
474
+ const tags = tagsByDocumentation.get(entry.documentation);
475
+ if (tags === void 0) tagsByDocumentation.set(entry.documentation, [entry.written.tag]);
476
+ else tags.push(entry.written.tag);
477
+ }
478
+ return [...tagsByDocumentation].map(([documentation, tags]) => taggedLiteral(tags, { documentation }));
479
+ };
480
+ const anyTag = () => tagArms(() => true);
481
+ const literal = () => oneOf(str(), numLiteral(), bool(), nullLiteral(), ...tagArms((dataType) => dataType !== SQL_EXPRESSION_DATA_TYPE_ID));
537
482
  const listArm = () => list(literal(), { label: `list of (${literal().label})` });
538
483
  const funcArms = [...registries.defaultFunctionRegistry.entries()].map(([name, entry]) => funcCall(name, blindCast(entry.signature)));
539
484
  return isList ? [
540
485
  listArm(),
541
486
  ...funcArms,
542
- ...tagArms()
487
+ ...anyTag()
543
488
  ] : [
544
489
  str(),
545
490
  numLiteral(),
546
491
  bool(),
547
492
  nullLiteral(),
548
493
  ...funcArms,
549
- ...tagArms(),
494
+ ...anyTag(),
550
495
  listArm()
551
496
  ];
552
497
  }
@@ -596,7 +541,7 @@ function defaultFieldSpec(ctx) {
596
541
  documentation: "Supplies a default value when this field is omitted from a mutation.",
597
542
  positional: [{
598
543
  key: "value",
599
- type: defaultValueArm(members === void 0 ? scalarDefaultArms(ctx.field.list, ctx.controlMutationDefaults) : enumDefaultArms(members, ctx.field.typeName, ctx.field.list), ctx.controlMutationDefaults.defaultFunctionRegistry),
544
+ type: defaultValueArm(members === void 0 ? scalarDefaultArms(ctx.field.list, ctx.dataTypes, ctx.controlMutationDefaults) : enumDefaultArms(members, ctx.field.typeName, ctx.field.list), ctx.controlMutationDefaults.defaultFunctionRegistry),
600
545
  documentation: "A literal, enum member, or registered default function compatible with this field."
601
546
  }]
602
547
  });
@@ -851,7 +796,8 @@ function fieldSpecContext(input) {
851
796
  model: input.model,
852
797
  field: input.field,
853
798
  typeResolution: node === void 0 ? void 0 : input.binder.symbolForNode(node),
854
- controlMutationDefaults: input.controlMutationDefaults
799
+ controlMutationDefaults: input.controlMutationDefaults,
800
+ dataTypes: input.dataTypes
855
801
  };
856
802
  }
857
803
  const sqlAttributeSpecs = {
@@ -1343,26 +1289,12 @@ const TAGGED_LITERAL_CANONICALIZATION_CODES = {
1343
1289
  nul: "PSL_TAGGED_LITERAL_NUL",
1344
1290
  "too-large": "PSL_TAGGED_LITERAL_TOO_LARGE"
1345
1291
  };
1346
- function readTaggedLiteral(literal, support, source) {
1347
- const reject = (code, message) => ({
1348
- ok: false,
1349
- diagnostic: {
1350
- code,
1351
- message,
1352
- ...source.at(literal.span)
1353
- }
1354
- });
1355
- if (entryForTag(support, literal.tag) === void 0) return reject("PSL_UNKNOWN_LITERAL_TAG", `Unknown literal tag "${literal.tag}". Known tags: ${knownTags(support).join(", ")}.`);
1356
- const { canonicalization } = literal;
1357
- if (!canonicalization.ok) return reject(TAGGED_LITERAL_CANONICALIZATION_CODES[canonicalization.reason], describeTaggedLiteralFailure(canonicalization.reason));
1358
- return {
1359
- ok: true,
1360
- written: {
1361
- kind: "tag",
1362
- tag: literal.tag,
1363
- text: canonicalization.body
1364
- }
1365
- };
1292
+ function defaultValueExpression(node) {
1293
+ return [...node.argList()?.args() ?? []].find((arg) => arg.colon() === void 0)?.value();
1294
+ }
1295
+ function listElements(expression) {
1296
+ const list = expression === void 0 ? void 0 : ArrayLiteralAst.cast(expression.syntax);
1297
+ return list === void 0 ? [] : [...list.elements()];
1366
1298
  }
1367
1299
  function rejectStrictListNullDefault(input) {
1368
1300
  if (input.field.elementOptional) return false;
@@ -1391,10 +1323,8 @@ function lowerDefaultForField(input) {
1391
1323
  model: input.model,
1392
1324
  field: input.field,
1393
1325
  binder: input.binder,
1394
- controlMutationDefaults: {
1395
- defaultFunctionRegistry: input.defaultFunctionRegistry,
1396
- dataTypeEntries: input.dataTypeSupport.entries
1397
- }
1326
+ controlMutationDefaults: { defaultFunctionRegistry: input.defaultFunctionRegistry },
1327
+ dataTypes: input.dataTypes
1398
1328
  }));
1399
1329
  const interpreted = interpretFieldAttribute({
1400
1330
  symbols: input.symbolTable,
@@ -1427,21 +1357,29 @@ function lowerDefaultForField(input) {
1427
1357
  canonical: true
1428
1358
  } };
1429
1359
  }
1360
+ const valueExpression = defaultValueExpression(node);
1361
+ const refusalLocation = (place) => {
1362
+ if (place.kind === "attribute") return source.at();
1363
+ const expression = place.elementIndex === void 0 ? valueExpression : listElements(valueExpression)[place.elementIndex];
1364
+ if (expression === void 0) throw new InternalError(`Field "${input.modelName}.${input.fieldName}": the refused @default value has no written expression.`);
1365
+ return diagnosticSource(input.sources, expression.syntax).at();
1366
+ };
1430
1367
  const readsListElements = (written) => input.isListColumn || input.field.list && written.kind === "list";
1431
- const readAsLiteral = (written) => {
1368
+ const readAsLiteral = (written, sourceElementIndexes) => {
1432
1369
  const lowered = lowerDataTypeDefault({
1433
1370
  written,
1371
+ sourceElementIndexes,
1434
1372
  isList: readsListElements(written),
1435
1373
  column: input.columnDescriptor,
1436
1374
  codecLookup: input.codecLookup,
1437
- support: input.dataTypeSupport,
1375
+ dataTypes: input.dataTypes,
1438
1376
  fieldPath: `${input.modelName}.${input.fieldName}`
1439
1377
  });
1440
1378
  if (!lowered.ok) {
1441
1379
  input.diagnostics.push({
1442
1380
  code: lowered.code,
1443
1381
  message: lowered.message,
1444
- ...source.at()
1382
+ ...refusalLocation(lowered.place)
1445
1383
  });
1446
1384
  return {};
1447
1385
  }
@@ -1466,7 +1404,7 @@ function lowerDefaultForField(input) {
1466
1404
  elementNullable: input.field.elementOptional,
1467
1405
  ...input.valueObjectDefault,
1468
1406
  codecLookup: input.codecLookup,
1469
- dataTypeLookup: input.dataTypeSupport.lookup
1407
+ dataTypeLookup: input.dataTypes.lookup
1470
1408
  });
1471
1409
  for (const { code, message } of mismatches) input.diagnostics.push({
1472
1410
  code,
@@ -1486,7 +1424,7 @@ function lowerDefaultForField(input) {
1486
1424
  canonical: true
1487
1425
  } };
1488
1426
  };
1489
- const writtenElement = (element) => {
1427
+ const writtenScalar = (element) => {
1490
1428
  if (typeof element === "string") return {
1491
1429
  kind: "string",
1492
1430
  text: element
@@ -1499,16 +1437,24 @@ function lowerDefaultForField(input) {
1499
1437
  kind: "number",
1500
1438
  text: element.text
1501
1439
  };
1502
- const literal = readTaggedLiteral(element, input.dataTypeSupport, source);
1503
- if (!literal.ok) {
1504
- input.diagnostics.push(literal.diagnostic);
1440
+ const { canonicalization } = element;
1441
+ if (!canonicalization.ok) {
1442
+ input.diagnostics.push({
1443
+ code: TAGGED_LITERAL_CANONICALIZATION_CODES[canonicalization.reason],
1444
+ message: describeTaggedLiteralFailure(canonicalization.reason),
1445
+ ...source.at(element.span)
1446
+ });
1505
1447
  return { ok: false };
1506
1448
  }
1507
- return literal.written;
1449
+ return {
1450
+ kind: "tag",
1451
+ tag: element.tag,
1452
+ text: canonicalization.text
1453
+ };
1508
1454
  };
1509
1455
  const sqlExpressionDefault = (text, span) => {
1510
- const reserved = reservedSqlDefaultBody(text);
1511
- const refusal = reserved === void 0 ? checkSqlDefaultBody(text) : `Write @default(${reserved}()) instead of sql\`${reserved}()\`; ${reserved}() is a Prisma default function, not raw SQL.`;
1456
+ const reserved = reservedSqlDefaultText(text);
1457
+ const refusal = reserved === void 0 ? checkSqlDefaultText(text) : `Write @default(${reserved}()) instead of sql\`${reserved}()\`; ${reserved}() is a Prisma default function, not raw SQL.`;
1512
1458
  if (refusal !== void 0) {
1513
1459
  input.diagnostics.push({
1514
1460
  code: PSL_INVALID_DEFAULT_SQL,
@@ -1537,16 +1483,18 @@ function lowerDefaultForField(input) {
1537
1483
  }
1538
1484
  if (Array.isArray(value)) {
1539
1485
  const elements = [];
1540
- for (const element of value) {
1486
+ const sourceElementIndexes = [];
1487
+ for (const [sourceIndex, element] of value.entries()) {
1541
1488
  if (element === null) continue;
1542
- const written = writtenElement(element);
1489
+ const written = writtenScalar(element);
1543
1490
  if ("ok" in written) return {};
1544
1491
  elements.push(written);
1492
+ sourceElementIndexes.push(sourceIndex);
1545
1493
  }
1546
1494
  return readAsLiteral({
1547
1495
  kind: "list",
1548
1496
  elements
1549
- });
1497
+ }, sourceElementIndexes);
1550
1498
  }
1551
1499
  if (typeof value === "string") return readAsLiteral({
1552
1500
  kind: "string",
@@ -1561,14 +1509,11 @@ function lowerDefaultForField(input) {
1561
1509
  text: value.text
1562
1510
  });
1563
1511
  if ("tag" in value) {
1564
- const literal = readTaggedLiteral(value, input.dataTypeSupport, source);
1565
- if (!literal.ok) {
1566
- input.diagnostics.push(literal.diagnostic);
1567
- return {};
1568
- }
1569
- const read = readValue(input.dataTypeSupport, literal.written, void 0);
1570
- if (read.ok && read.typed.type === SQL_EXPRESSION_DATA_TYPE_ID) return sqlExpressionDefault(sqlTextFromCanonical(read.typed.value), value.span);
1571
- return readAsLiteral(literal.written);
1512
+ const written = writtenScalar(value);
1513
+ if ("ok" in written) return {};
1514
+ const read = readWrittenValue(input.dataTypes, written);
1515
+ if (read.ok && read.value.type === SQL_EXPRESSION_DATA_TYPE_ID) return sqlExpressionDefault(sqlTextFromCanonical(read.value.value), value.span);
1516
+ return readAsLiteral(written);
1572
1517
  }
1573
1518
  if (typeof value === "object") {
1574
1519
  const context = {
@@ -1630,10 +1575,8 @@ function lowerEnumDefaultForField(input) {
1630
1575
  model,
1631
1576
  field,
1632
1577
  binder: input.binder,
1633
- controlMutationDefaults: {
1634
- defaultFunctionRegistry: input.defaultFunctionRegistry,
1635
- dataTypeEntries: input.dataTypeSupport.entries
1636
- }
1578
+ controlMutationDefaults: { defaultFunctionRegistry: input.defaultFunctionRegistry },
1579
+ dataTypes: input.dataTypes
1637
1580
  })),
1638
1581
  symbols: input.symbolTable,
1639
1582
  model,
@@ -1782,7 +1725,7 @@ function lowerNoCheckForField(input) {
1782
1725
  return [...authored].sort();
1783
1726
  }
1784
1727
  function collectResolvedFields(input) {
1785
- const { model, symbolTable, enumTypeDescriptors, namedTypeDescriptors, valueObjectTypes, authoringContributions, binder, targetId, defaultFunctionRegistry, dataTypeSupport, generatorDescriptorById, diagnostics, sources, scalarColumnDescriptors, enumHandles, capabilities, namespaceId, namespaceExtensionEntities, codecLookup } = input;
1728
+ const { model, symbolTable, enumTypeDescriptors, namedTypeDescriptors, valueObjectTypes, authoringContributions, binder, targetId, defaultFunctionRegistry, dataTypes, generatorDescriptorById, diagnostics, sources, scalarColumnDescriptors, enumHandles, capabilities, namespaceId, namespaceExtensionEntities, codecLookup } = input;
1786
1729
  const resolvedFields = [];
1787
1730
  const valueObjectStorageTypeName = authoringContributions?.valueObjectStorageType;
1788
1731
  const declaredControlPolicy = getAttribute(model.attributes, "control")?.args.find((arg) => arg.kind === "positional")?.value.trim();
@@ -1884,7 +1827,7 @@ function collectResolvedFields(input) {
1884
1827
  binder: input.binder,
1885
1828
  enumHandle,
1886
1829
  defaultFunctionRegistry,
1887
- dataTypeSupport,
1830
+ dataTypes,
1888
1831
  diagnostics
1889
1832
  }) : lowerDefaultForField({
1890
1833
  modelName: model.name,
@@ -1902,7 +1845,7 @@ function collectResolvedFields(input) {
1902
1845
  },
1903
1846
  generatorDescriptorById,
1904
1847
  defaultFunctionRegistry,
1905
- dataTypeSupport,
1848
+ dataTypes,
1906
1849
  codecLookup,
1907
1850
  diagnostics
1908
1851
  }) : {};
@@ -2001,6 +1944,6 @@ function collectResolvedFields(input) {
2001
1944
  return resolvedFields;
2002
1945
  }
2003
1946
  //#endregion
2004
- export { toNamedTypeFieldDescriptor as C, storageName as S, modelCoordinateKey as _, describeUnsupportedSqlAttribute as a, resolveFieldTypeDescriptor as b, getAttribute as c, instantiateFieldTypeConstructor as d, instantiatePslTypeConstructor as f, modelAttributeSpecsFrom as g, mapFieldNamesToColumns as h, contractError as i, getAuthoringEntity as l, interpretModelAttribute as m, bareTypeConstructorOf as n, entryForTag as o, interpretFieldAttribute as p, collectResolvedFields as r, formatDbAttributeMigrationMessage as s, PSL_CHECK_ON_STI_VARIANT as t, getNamedArgument as u, readDataTypeDefault as v, sqlAttributeSpecs as x, readWrittenNumberForCodec as y };
1947
+ export { toNamedTypeFieldDescriptor as S, readDataTypeDefault as _, describeUnsupportedSqlAttribute as a, sqlAttributeSpecs as b, getAuthoringEntity as c, instantiatePslTypeConstructor as d, interpretFieldAttribute as f, modelCoordinateKey as g, modelAttributeSpecsFrom as h, contractError as i, getNamedArgument as l, mapFieldNamesToColumns as m, bareTypeConstructorOf as n, formatDbAttributeMigrationMessage as o, interpretModelAttribute as p, collectResolvedFields as r, getAttribute as s, PSL_CHECK_ON_STI_VARIANT as t, instantiateFieldTypeConstructor as u, readWrittenNumberForCodec as v, storageName as x, resolveFieldTypeDescriptor as y };
2005
1948
 
2006
- //# sourceMappingURL=psl-field-resolution-Bi-CSeoQ-Do_5hZ8Z.mjs.map
1949
+ //# sourceMappingURL=psl-field-resolution-DUCrDnuq-BXwISml1.mjs.map