@prisma/orm-framework 8.0.0-rc.19-dev.7 → 8.0.0-rc.19-dev.9

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 (107) hide show
  1. package/dist/{authoring-BMkyimEq.mjs → authoring-CNUti739.mjs} +456 -247
  2. package/dist/authoring-CNUti739.mjs.map +1 -0
  3. package/dist/{authoring-CUZxY2RV.d.mts → authoring-CjwinhU5.d.mts} +79 -7
  4. package/dist/authoring-CjwinhU5.d.mts.map +1 -0
  5. package/dist/{binder-D_4RBHbt-56WrFUy3.d.mts → binder-D_4RBHbt-C-WTJ1K6.d.mts} +10 -10
  6. package/dist/{binder-D_4RBHbt-56WrFUy3.d.mts.map → binder-D_4RBHbt-C-WTJ1K6.d.mts.map} +1 -1
  7. package/dist/{codec-B_KV-HpC.d.mts → codec-B4ypaota.d.mts} +112 -3
  8. package/dist/codec-B4ypaota.d.mts.map +1 -0
  9. package/dist/codec-Do8tfXqk.mjs +457 -0
  10. package/dist/codec-Do8tfXqk.mjs.map +1 -0
  11. package/dist/{codec-descriptor-V2-N5Qmm-BR-5owl6.mjs → codec-descriptor-D0oY-hgs-C5e11ola.mjs} +19 -4
  12. package/dist/codec-descriptor-D0oY-hgs-C5e11ola.mjs.map +1 -0
  13. package/dist/{components-CJ5VhJT8.d.mts → components-B9ow7ca6.d.mts} +3 -3
  14. package/dist/{components-CJ5VhJT8.d.mts.map → components-B9ow7ca6.d.mts.map} +1 -1
  15. package/dist/{components-C83PWIWw.mjs → components-BaV9iCkq.mjs} +2 -2
  16. package/dist/{components-C83PWIWw.mjs.map → components-BaV9iCkq.mjs.map} +1 -1
  17. package/dist/components.d.mts +11 -11
  18. package/dist/components.mjs +8 -8
  19. package/dist/components__authoring.d.mts +4 -4
  20. package/dist/components__authoring.mjs +3 -3
  21. package/dist/components__codec.d.mts +2 -2
  22. package/dist/components__codec.mjs +4 -4
  23. package/dist/components__components.d.mts +3 -3
  24. package/dist/components__components.mjs +1 -1
  25. package/dist/components__control.d.mts +3 -3
  26. package/dist/components__control.mjs +2 -2
  27. package/dist/components__execution.d.mts +1 -1
  28. package/dist/components__psl-ast.d.mts +3 -3
  29. package/dist/{config-types-hb9Af32k.d.mts → config-types-Blog3oGn.d.mts} +6 -6
  30. package/dist/{config-types-hb9Af32k.d.mts.map → config-types-Blog3oGn.d.mts.map} +1 -1
  31. package/dist/config.d.mts +1 -1
  32. package/dist/config__config-types.d.mts +1 -1
  33. package/dist/contract-authoring.d.mts +3 -3
  34. package/dist/contract-authoring.mjs +3 -3
  35. package/dist/{control-B5ezUWD2-BdH2_lqS.d.mts → control-B5ezUWD2-Cy2_LDVU.d.mts} +2 -2
  36. package/dist/{control-B5ezUWD2-BdH2_lqS.d.mts.map → control-B5ezUWD2-Cy2_LDVU.d.mts.map} +1 -1
  37. package/dist/control-CvY9anXC.d.mts +1 -0
  38. package/dist/{control-BTteCOsf.mjs → control-DMJqhnwU.mjs} +3 -3
  39. package/dist/{control-BTteCOsf.mjs.map → control-DMJqhnwU.mjs.map} +1 -1
  40. package/dist/{control-D2drwCoH.d.mts → control-Dg8BDPmn.d.mts} +5 -5
  41. package/dist/{control-D2drwCoH.d.mts.map → control-Dg8BDPmn.d.mts.map} +1 -1
  42. package/dist/{control-KsXr4fYD-Csaj4sPO.mjs → control-KsXr4fYD-D2Ows0NI.mjs} +2 -2
  43. package/dist/{control-KsXr4fYD-Csaj4sPO.mjs.map → control-KsXr4fYD-D2Ows0NI.mjs.map} +1 -1
  44. package/dist/{data-type-CVNHtd6y-BFa_VnCb.mjs → data-type-V6mcDhcG-DVQAPOQT.mjs} +2 -2
  45. package/dist/{data-type-CVNHtd6y-BFa_VnCb.mjs.map → data-type-V6mcDhcG-DVQAPOQT.mjs.map} +1 -1
  46. package/dist/{declarations-BgUAq1RG-BOxzxoTR.mjs → declarations-BgUAq1RG-Dz_-EI1Q.mjs} +2 -2
  47. package/dist/{declarations-BgUAq1RG-BOxzxoTR.mjs.map → declarations-BgUAq1RG-Dz_-EI1Q.mjs.map} +1 -1
  48. package/dist/errors.d.mts +4 -4
  49. package/dist/errors.mjs +3 -3
  50. package/dist/errors__control.d.mts +2 -2
  51. package/dist/errors__control.mjs +1 -1
  52. package/dist/errors__execution.d.mts +1 -1
  53. package/dist/errors__execution.mjs +1 -1
  54. package/dist/errors__migration.d.mts +1 -1
  55. package/dist/errors__migration.mjs +1 -1
  56. package/dist/{execution-B_qZ4WLk.d.mts → execution-BsrZp2ks.d.mts} +2 -2
  57. package/dist/{execution-B_qZ4WLk.d.mts.map → execution-BsrZp2ks.d.mts.map} +1 -1
  58. package/dist/{execution-0Irooze3.d.mts → execution-DXqYartX.d.mts} +2 -2
  59. package/dist/{execution-0Irooze3.d.mts.map → execution-DXqYartX.d.mts.map} +1 -1
  60. package/dist/{execution-B7JGFd5C.mjs → execution-vfY4d-SZ.mjs} +2 -2
  61. package/dist/{execution-B7JGFd5C.mjs.map → execution-vfY4d-SZ.mjs.map} +1 -1
  62. package/dist/{expressions-CMQzbnHk-CrNw_vqf.mjs → expressions-CMQzbnHk-BL2zN0Iv.mjs} +2 -2
  63. package/dist/{expressions-CMQzbnHk-CrNw_vqf.mjs.map → expressions-CMQzbnHk-BL2zN0Iv.mjs.map} +1 -1
  64. package/dist/{framework-authoring-C78etPdT-CeiBIBJ-.d.mts → framework-authoring-DDxddXZm-uZYdhoE0.d.mts} +24 -27
  65. package/dist/framework-authoring-DDxddXZm-uZYdhoE0.d.mts.map +1 -0
  66. package/dist/{framework-components-BmRQfvNS-KSEiBXXc.d.mts → framework-components-Bo8VkHuI-CLxCdRvy.d.mts} +3 -3
  67. package/dist/{framework-components-BmRQfvNS-KSEiBXXc.d.mts.map → framework-components-Bo8VkHuI-CLxCdRvy.d.mts.map} +1 -1
  68. package/dist/ids.d.mts +1 -1
  69. package/dist/{migration-n7Y0_y4n.d.mts → migration-_8vByrkL.d.mts} +2 -2
  70. package/dist/{migration-n7Y0_y4n.d.mts.map → migration-_8vByrkL.d.mts.map} +1 -1
  71. package/dist/{migration-LrheHk4r.mjs → migration-uC-bSKA4.mjs} +2 -2
  72. package/dist/{migration-LrheHk4r.mjs.map → migration-uC-bSKA4.mjs.map} +1 -1
  73. package/dist/{parse-bZgfjovA-sINnImkq.mjs → parse-bZgfjovA-BNgYhylT.mjs} +3 -3
  74. package/dist/{parse-bZgfjovA-sINnImkq.mjs.map → parse-bZgfjovA-BNgYhylT.mjs.map} +1 -1
  75. package/dist/{parse-djL5wker-CYBtaUrK.d.mts → parse-djL5wker-DaT4W0gt.d.mts} +6 -6
  76. package/dist/{parse-djL5wker-CYBtaUrK.d.mts.map → parse-djL5wker-DaT4W0gt.d.mts.map} +1 -1
  77. package/dist/psl-ast-COcYtLlz.d.mts +2 -0
  78. package/dist/{psl-ast-54cA0pl_-DrzGrcMF.d.mts → psl-ast-rY25o3Ze-ClLY3CYt.d.mts} +3 -3
  79. package/dist/{psl-ast-54cA0pl_-DrzGrcMF.d.mts.map → psl-ast-rY25o3Ze-ClLY3CYt.d.mts.map} +1 -1
  80. package/dist/psl-parser.d.mts +20 -11
  81. package/dist/psl-parser.d.mts.map +1 -1
  82. package/dist/psl-parser.mjs +69 -45
  83. package/dist/psl-parser.mjs.map +1 -1
  84. package/dist/psl-parser__format.d.mts +1 -1
  85. package/dist/psl-parser__format.mjs +3 -3
  86. package/dist/psl-parser__interpret.d.mts +6 -6
  87. package/dist/psl-parser__interpret.mjs +3 -3
  88. package/dist/psl-parser__syntax.d.mts +1 -1
  89. package/dist/psl-parser__syntax.mjs +3 -3
  90. package/dist/psl-printer.d.mts +4 -4
  91. package/dist/psl-printer.mjs +1 -1
  92. package/dist/{temporal-presets-CIFczljn-BrjropV6.mjs → temporal-presets-5TK1pTYJ-DmhrnMP1.mjs} +3 -3
  93. package/dist/{temporal-presets-CIFczljn-BrjropV6.mjs.map → temporal-presets-5TK1pTYJ-DmhrnMP1.mjs.map} +1 -1
  94. package/dist/{temporal-presets-suGfXweJ-Cv2uijGj.d.mts → temporal-presets-BuMqk7h8-DZSuu4Z_.d.mts} +3 -3
  95. package/dist/{temporal-presets-suGfXweJ-Cv2uijGj.d.mts.map → temporal-presets-BuMqk7h8-DZSuu4Z_.d.mts.map} +1 -1
  96. package/dist/{type-constructor-calls-BLf-HsFy-Z9ApP-kL.mjs → type-constructor-calls-BLf-HsFy-D_jbIqj8.mjs} +4 -4
  97. package/dist/{type-constructor-calls-BLf-HsFy-Z9ApP-kL.mjs.map → type-constructor-calls-BLf-HsFy-D_jbIqj8.mjs.map} +1 -1
  98. package/package.json +15 -15
  99. package/dist/authoring-BMkyimEq.mjs.map +0 -1
  100. package/dist/authoring-CUZxY2RV.d.mts.map +0 -1
  101. package/dist/codec-B_KV-HpC.d.mts.map +0 -1
  102. package/dist/codec-DGRG8oEH.mjs +0 -56
  103. package/dist/codec-DGRG8oEH.mjs.map +0 -1
  104. package/dist/codec-descriptor-V2-N5Qmm-BR-5owl6.mjs.map +0 -1
  105. package/dist/control-BY0_FFTB.d.mts +0 -1
  106. package/dist/framework-authoring-C78etPdT-CeiBIBJ-.d.mts.map +0 -1
  107. package/dist/psl-ast-BubQebay.d.mts +0 -2
@@ -2,9 +2,10 @@ import { t as canonicalStringify } from "./canonical-stringify-DY4NaAJi.mjs";
2
2
  import { r as isInternalError, t as InternalError } from "./internal-error-ChGYPVpq-DhUD05u0.mjs";
3
3
  import { n as notOk, r as ok } from "./result-8OXF26MN.mjs";
4
4
  import { t as canonicalizeJson } from "./canonicalize-json-ZPawceQR-Dua1VNEB.mjs";
5
- import { u as dataTypeId } from "./data-type-CVNHtd6y-BFa_VnCb.mjs";
6
- import { A as isAuthoringTypeAliasDescriptor, E as isAuthoringFieldPresetDescriptor, F as printTaggedLiteral, I as printedTaggedLiteralReadsBack, S as instantiateAuthoringTypeConstructor, j as isAuthoringTypeConstructorDescriptor, w as isAuthoringArgRef } from "./temporal-presets-CIFczljn-BrjropV6.mjs";
7
- import { a as readContractValue, i as enumRefusalOf } from "./codec-descriptor-V2-N5Qmm-BR-5owl6.mjs";
5
+ import { d as dataTypeParams, u as dataTypeId } from "./data-type-V6mcDhcG-DVQAPOQT.mjs";
6
+ import { r as codecForRef } from "./resolve-codec-qqMjZrmn-Cok8elAo.mjs";
7
+ import { A as isAuthoringTypeAliasDescriptor, E as isAuthoringFieldPresetDescriptor, F as printTaggedLiteral, I as printedTaggedLiteralReadsBack, S as instantiateAuthoringTypeConstructor, j as isAuthoringTypeConstructorDescriptor, w as isAuthoringArgRef } from "./temporal-presets-5TK1pTYJ-DmhrnMP1.mjs";
8
+ import { a as numeralText, i as enumRefusalOf, o as readContractValue } from "./codec-descriptor-D0oY-hgs-C5e11ola.mjs";
8
9
  //#region ../../../1-framework/1-core/framework-components/dist/authoring.mjs
9
10
  /** Every type constructor of `namespace`, with its path, in namespace order. */
10
11
  function* authoringTypeConstructors(namespace, path = []) {
@@ -59,16 +60,22 @@ function findAuthoringTypeConstructorCall(namespace, output) {
59
60
  };
60
61
  }
61
62
  }
63
+ function storedFormOf(stored) {
64
+ return canonicalStringify(JSON.parse(JSON.stringify(stored)));
65
+ }
66
+ /** The key two stored values are equal by: the data type's `equalityKey` when it declares one, else the stored form as `contract.json` holds it, compared by `canonicalStringify`. */
67
+ function storedValueKey(stored, equalityKey) {
68
+ return equalityKey?.(stored) ?? storedFormOf(stored);
69
+ }
62
70
  /**
63
71
  * Each enum member whose stored form equals an earlier member's, paired with the first such member. Stored forms are compared as `contract.json` holds them, so negative zero is zero, and by `canonicalStringify`, so two objects with the same entries in a different order are equal; or, when the enum's data type declares an `equalityKey`, by that key, so `0.5` and `0.50` are one `numeric` value. Every enum authoring surface refuses the members this returns.
64
72
  */
65
73
  function duplicateStoredMembers(members, equalityKey) {
66
- const storedFormOf = (stored) => canonicalStringify(JSON.parse(JSON.stringify(stored)));
67
74
  const memberByKey = /* @__PURE__ */ new Map();
68
75
  const duplicates = [];
69
76
  for (const member of members) {
70
77
  const { name, stored } = member;
71
- const key = equalityKey?.(stored) ?? storedFormOf(stored);
78
+ const key = storedValueKey(stored, equalityKey);
72
79
  const earlier = memberByKey.get(key);
73
80
  if (earlier === void 0) memberByKey.set(key, member);
74
81
  else if (storedFormOf(earlier.stored) === storedFormOf(stored)) duplicates.push({
@@ -86,239 +93,6 @@ function duplicateStoredMembers(members, equalityKey) {
86
93
  return duplicates;
87
94
  }
88
95
  /**
89
- * A problem with an enum's members as a diagnostic at the member, or at the block when the problem is the enum's codec.
90
- */
91
- function enumMemberProblemDiagnostic(problem, site) {
92
- const { enumName, codecId, sourceId } = site;
93
- const at = (member) => ({
94
- sourceId,
95
- span: site.memberSpans[member] ?? site.span
96
- });
97
- switch (problem.kind) {
98
- case "codec-not-for-enums": return {
99
- code: "PSL_EXTENSION_INVALID_VALUE",
100
- message: `enum "${enumName}" cannot use the codec "${codecId}". ${problem.refusal}`,
101
- sourceId,
102
- span: site.span
103
- };
104
- case "codec-missing": return {
105
- code: "PSL_EXTENSION_INVALID_VALUE",
106
- message: `enum "${enumName}" uses codec "${codecId}", which no pack in the contract provides`,
107
- sourceId,
108
- span: site.span
109
- };
110
- case "codec-refused-member": return {
111
- code: "PSL_EXTENSION_INVALID_VALUE",
112
- message: `enum "${enumName}" member "${problem.member}" was rejected by codec "${codecId}": ${problem.reason}`,
113
- ...at(problem.member)
114
- };
115
- case "member-not-stored-as-written": return {
116
- code: "PSL_EXTENSION_INVALID_VALUE",
117
- message: `enum "${enumName}" member "${problem.member}" is written ${problem.written}, but its codec stores ${JSON.stringify(problem.stored)}. Write the member as ${problem.writeAs}.`,
118
- ...at(problem.member)
119
- };
120
- case "duplicate-member-value": return {
121
- code: "PSL_ENUM_DUPLICATE_MEMBER_VALUE",
122
- message: problem.earlierStored === void 0 ? `enum "${enumName}": members "${problem.earlier}" and "${problem.later}" both store ${JSON.stringify(problem.stored)}` : `enum "${enumName}": members "${problem.earlier}" and "${problem.later}" store ${JSON.stringify(problem.earlierStored)} and ${JSON.stringify(problem.stored)}, which the database holds equal`,
123
- ...at(problem.later)
124
- };
125
- }
126
- }
127
- /**
128
- * Reads the members of an `enum` block through its codec. When the family gives a reader for written values (`ctx.readWrittenValueForCodec`), each member is read as a column default is read: its syntax gives it a data type, the codec's data type takes it directly or through a cast, and the codec checks it, so a number keeps every digit and a quoted value is text. A bare member is read from its own name, as text. Without that reader, a member is read as JSON by the codec's data type and then the codec.
129
- * Pushes a diagnostic and returns `undefined` when a member is refused, when two members
130
- * store the same value, or when the block has no members. Shared by every family's enum factory.
131
- */
132
- function readEnumBlockMembers(block, codecId, codec, ctx) {
133
- const sourceId = ctx.sourceId ?? "unknown";
134
- const diagnostics = ctx.diagnostics;
135
- const site = {
136
- enumName: block.name,
137
- codecId,
138
- sourceId,
139
- span: block.span,
140
- memberSpans: block.parameterSpans
141
- };
142
- const members = [];
143
- const storedMembers = [];
144
- let memberError = false;
145
- for (const [memberName, memberValue] of Object.entries(block.values)) {
146
- const span = block.parameterSpans[memberName] ?? block.span;
147
- const bareMemberRefused = () => ({
148
- code: "PSL_ENUM_BARE_MEMBER_NON_STRING_CODEC",
149
- message: `enum "${block.name}" member "${memberName}" has no value and codec "${codecId}" does not accept a bare name as input`,
150
- sourceId,
151
- span
152
- });
153
- const written = block.writtenValues?.[memberName] ?? (memberValue === void 0 ? {
154
- kind: "string",
155
- text: memberName
156
- } : void 0);
157
- const reading = written === void 0 ? void 0 : ctx.readWrittenValueForCodec?.({
158
- written,
159
- codecId,
160
- subject: `enum "${block.name}" member "${memberName}"`
161
- });
162
- if (reading !== void 0 && !reading.ok) {
163
- diagnostics?.push(memberValue === void 0 ? bareMemberRefused() : {
164
- code: reading.code,
165
- message: reading.message,
166
- sourceId,
167
- span
168
- });
169
- memberError = true;
170
- continue;
171
- }
172
- const stored = reading?.ok ? reading.value : memberValue === void 0 ? memberName : memberValue;
173
- let read;
174
- try {
175
- read = readContractValue(codec, stored, void 0);
176
- } catch (err) {
177
- if (isInternalError(err)) throw err;
178
- diagnostics?.push(memberValue === void 0 ? bareMemberRefused() : {
179
- code: "PSL_EXTENSION_INVALID_VALUE",
180
- message: `enum "${block.name}" member "${memberName}" was rejected by codec "${codecId}": ${err instanceof Error ? err.message : String(err)}`,
181
- sourceId,
182
- span
183
- });
184
- memberError = true;
185
- continue;
186
- }
187
- members.push({
188
- name: memberName,
189
- value: read
190
- });
191
- storedMembers.push({
192
- name: memberName,
193
- stored: codec.dataType.toContract(codec.toDataTypeValue(read))
194
- });
195
- }
196
- for (const duplicate of duplicateStoredMembers(storedMembers, codec.dataType.equalityKey)) {
197
- diagnostics?.push(enumMemberProblemDiagnostic({
198
- kind: "duplicate-member-value",
199
- ...duplicate
200
- }, site));
201
- memberError = true;
202
- }
203
- if (memberError) return void 0;
204
- if (members.length === 0) {
205
- diagnostics?.push({
206
- code: "PSL_ENUM_MISSING_TYPE",
207
- message: `enum "${block.name}" must have at least one member`,
208
- sourceId,
209
- span: block.span
210
- });
211
- return;
212
- }
213
- return members;
214
- }
215
- /** Whether TypeScript gives the value a literal type: a primitive, or an array or plain object of them. */
216
- function hasLiteralType(value) {
217
- if ([
218
- "string",
219
- "number",
220
- "boolean",
221
- "bigint"
222
- ].includes(typeof value)) return true;
223
- if (Array.isArray(value)) return value.every(hasLiteralType);
224
- if (typeof value !== "object" || value === null) return false;
225
- const prototype = Object.getPrototypeOf(value);
226
- return (prototype === Object.prototype || prototype === null) && Object.values(value).every(hasLiteralType);
227
- }
228
- /**
229
- * A member's value in the form its codec stores it, and that form read back by the codec. A codec that throws on either is a refusal naming the member; an internal error is not the member's fault and propagates.
230
- */
231
- function encodeEnumMember(member, codec) {
232
- try {
233
- const stored = codec.dataType.toContract(codec.toDataTypeValue(member.value));
234
- return ok({
235
- stored,
236
- readBack: readContractValue(codec, stored, void 0)
237
- });
238
- } catch (cause) {
239
- if (isInternalError(cause)) throw cause;
240
- return notOk({
241
- kind: "codec-refused-member",
242
- member: member.name,
243
- reason: cause instanceof Error ? cause.message : String(cause),
244
- cause
245
- });
246
- }
247
- }
248
- /**
249
- * Refuses a member its codec reads back as a different value from the one written. A member with no literal type has nothing to compare.
250
- */
251
- function notStoredAsWritten(member, stored, readBack) {
252
- if (!hasLiteralType(member.value)) return void 0;
253
- if (hasLiteralType(readBack) && canonicalStringify(readBack) === canonicalStringify(member.value)) return void 0;
254
- return {
255
- kind: "member-not-stored-as-written",
256
- member: member.name,
257
- written: canonicalStringify(member.value),
258
- stored,
259
- writeAs: hasLiteralType(readBack) ? canonicalStringify(readBack) : JSON.stringify(stored)
260
- };
261
- }
262
- /**
263
- * Each member of an enum in the form its codec stores it. Refuses a codec an enum cannot use, a codec the lookup does not have, a member the codec refuses, a member the codec reads back as another value, and two members stored as the same value. Every family's contract build calls this, and reports the problems in its own terms.
264
- */
265
- function encodeEnumMembers(decodedEnum, codecLookup) {
266
- const descriptor = codecLookup.descriptorFor(decodedEnum.codecId);
267
- const refusal = descriptor === void 0 ? void 0 : enumRefusalOf(descriptor);
268
- if (refusal !== void 0) return notOk([{
269
- kind: "codec-not-for-enums",
270
- refusal
271
- }]);
272
- const codec = codecLookup.get(decodedEnum.codecId);
273
- if (codec === void 0) return notOk([{ kind: "codec-missing" }]);
274
- const problems = [];
275
- const members = [];
276
- for (const member of decodedEnum.enumMembers) {
277
- const encoded = encodeEnumMember(member, codec);
278
- if (!encoded.ok) {
279
- problems.push(encoded.failure);
280
- continue;
281
- }
282
- const { stored, readBack } = encoded.value;
283
- const mismatch = notStoredAsWritten(member, stored, readBack);
284
- if (mismatch !== void 0) problems.push(mismatch);
285
- members.push({
286
- name: member.name,
287
- value: stored
288
- });
289
- }
290
- for (const duplicate of duplicateStoredMembers(members.map(({ name, value }) => ({
291
- name,
292
- stored: value
293
- })), codec.dataType.equalityKey)) problems.push({
294
- kind: "duplicate-member-value",
295
- ...duplicate
296
- });
297
- return problems.length > 0 ? notOk(problems) : ok(members);
298
- }
299
- function presetSpellingsUnder(members, prefix) {
300
- return Object.entries(members).flatMap(([name, member]) => isAuthoringFieldPresetDescriptor(member) ? [`${prefix}.${name}(${(member.args ?? []).map((arg, index) => arg.name ?? `argument${index + 1}`).join(", ")})`] : presetSpellingsUnder(member, `${prefix}.${name}`));
301
- }
302
- /**
303
- * How each field preset registered under `namespace`, at any depth, is written, with the names of its arguments: `temporal.timestamp(onCreate, onUpdate)`.
304
- */
305
- function fieldPresetSpellings(contributions, namespace) {
306
- const members = contributions?.field?.[namespace];
307
- if (members === void 0 || isAuthoringFieldPresetDescriptor(members)) return [];
308
- return presetSpellingsUnder(members, namespace);
309
- }
310
- /**
311
- * Walks `authoringContributions.field` segment by segment and returns the field-preset descriptor at the path, or `undefined` when none is registered there.
312
- */
313
- function getAuthoringFieldPreset(contributions, path) {
314
- let current = contributions?.field;
315
- for (const segment of path) {
316
- if (typeof current !== "object" || current === null || "kind" in current) return;
317
- current = current[segment];
318
- }
319
- return current !== void 0 && isAuthoringFieldPresetDescriptor(current) ? current : void 0;
320
- }
321
- /**
322
96
  * Words a refusal of the cast rule. The message leads with what to write; the types are named only when the value has a form the position admits and its type is still refused, such as a number too large for the receiving type.
323
97
  */
324
98
  function describeRefusal(refusal, support, guidance) {
@@ -360,25 +134,44 @@ function isSameForm(a, b) {
360
134
  }
361
135
  /** Text a contract source reads as a number literal. */
362
136
  const NUMBER_TEXT = /^[+-]?(?:\d+(?:\.\d*)?|\.\d+)(?:[eE][+-]?\d+)?$|^[+-]?(?:NaN|Infinity)$/;
137
+ const DECIMAL_TEXT = /^([+-]?)0*(\d*?)(?:\.(\d*?))?0*$/;
138
+ /** A decimal numeral in one form: no plus sign, no leading or trailing zeros, the sign of zero kept. Other text is itself. */
139
+ function canonicalNumber(text) {
140
+ const match = text.includes(".") ? DECIMAL_TEXT.exec(text) : /^([+-]?)0*(\d*)$/.exec(text);
141
+ if (match === null) return text;
142
+ const [, sign = "", whole = "", fraction = ""] = match;
143
+ return `${sign === "-" ? "-" : ""}${whole === "" ? "0" : whole}${fraction === "" ? "" : `.${fraction}`}`;
144
+ }
145
+ /** Whether a stored value is the number `text` writes, digit for digit and with its sign, so writing the text unquoted stores what it says. */
146
+ function sameNumber(text, stored) {
147
+ const storedText = typeof stored === "number" ? Object.is(stored, -0) ? "-0" : numeralText(stored) : typeof stored === "string" ? stored : void 0;
148
+ return storedText !== void 0 && canonicalNumber(storedText) === canonicalNumber(text);
149
+ }
363
150
  /**
364
- * The literal to write in place of a quoted string that `receivingType` refuses under `receivingParams`: the string as a literal of the first tag the type admits, or else the string's text unquoted, as a number or a boolean. `undefined` when the value is not a quoted string, no such literal reads back as the same text, or the type would refuse each of them too.
151
+ * The literal to write in place of a quoted string that `receivingType` refuses under `receivingParams`: the string as a literal of the first tag the type admits, or else the string's text unquoted, as a number or a boolean. `undefined` when the value is not a quoted string, no such literal reads back as the same text, the type would refuse each of them too, or the number the text writes would be stored as another number, as `-0` is stored without its sign or `9007199254740993` as the nearest double.
365
152
  */
366
153
  function exactRewrite(support, receiving, written) {
367
154
  if (written.kind !== "string") return void 0;
368
- const admits = (candidate) => {
155
+ const castOf = (candidate) => {
369
156
  const read = readWrittenValue(support, candidate);
370
- return read.ok && castTypedValue(support, receiving.receivingType, receiving.receivingParams, read.value).ok;
157
+ if (!read.ok) return void 0;
158
+ const cast = castTypedValue(support, receiving.receivingType, receiving.receivingParams, read.value);
159
+ return cast.ok ? cast.value : void 0;
371
160
  };
161
+ const admits = (candidate) => castOf(candidate) !== void 0;
372
162
  const [tag] = admittedTags(support, receiving.receivingType);
373
163
  if (tag !== void 0 && printedTaggedLiteralReadsBack(written.text) && admits({
374
164
  kind: "tag",
375
165
  tag,
376
166
  text: written.text
377
167
  })) return printTaggedLiteral(tag, written.text);
378
- if (NUMBER_TEXT.test(written.text) && admits({
379
- kind: "number",
380
- text: written.text
381
- })) return written.text;
168
+ if (NUMBER_TEXT.test(written.text)) {
169
+ const stored = castOf({
170
+ kind: "number",
171
+ text: written.text
172
+ });
173
+ if (stored !== void 0 && sameNumber(written.text, stored.value)) return written.text;
174
+ }
382
175
  if ((written.text === "true" || written.text === "false") && admits({
383
176
  kind: "boolean",
384
177
  value: written.text === "true"
@@ -494,6 +287,91 @@ function readWrittenValueAs(support, receivingType, written) {
494
287
  rewrite
495
288
  }));
496
289
  }
290
+ /**
291
+ * Reads `written` into the codec `ref` names, built with `ref`'s type parameters: the authoring entry for its syntax reads it, the codec's data type takes it directly or through a cast, the data type constructs it under the type parameters, and the codec checks it. Returns the value as the data type stores it. A written list is read element by element into the element types of the data type's list cast, then through the list cast.
292
+ *
293
+ * A refusal is worded for a diagnostic, after `subject` and the element it is about, as in `enum "Ratio" member "Half" at element 2: Expected a number`: syntax no entry reads or a cast refuses is `PSL_INVALID_LITERAL`, a value of a type the data type neither is nor casts from is `PSL_VALUE_TYPE_INCOMPATIBLE`, and a value the data type under the type parameters or the codec refuses is `PSL_VALUE_REFUSED`. ADR 254.
294
+ */
295
+ function readWrittenValueIntoCodec(input) {
296
+ const { support, ref, written, subject } = input;
297
+ const codec = codecForRef(input.codecLookup, ref);
298
+ if (codec === void 0) throw new InternalError(`${subject}: no codec descriptor is registered for "${ref.codecId}", but the value was read for it.`);
299
+ const receivingType = codec.dataType.id;
300
+ const receivingParams = dataTypeParams(codec.dataType, ref.typeParams);
301
+ const refused = (elementIndex, { code, message }) => notOk({
302
+ code,
303
+ message: `${elementIndex === void 0 ? subject : `${subject} at element ${elementIndex + 1}`}: ${message}`
304
+ });
305
+ const stored = (json) => {
306
+ try {
307
+ const value = codec.dataType.valueFrom(json, receivingParams);
308
+ codec.fromDataTypeValue(value);
309
+ return ok(codec.dataType.toContract(value));
310
+ } catch (error) {
311
+ if (isInternalError(error)) throw error;
312
+ return refused(void 0, {
313
+ code: "PSL_VALUE_REFUSED",
314
+ message: messageOf(error)
315
+ });
316
+ }
317
+ };
318
+ const forms = admittedForms(support, [receivingType]);
319
+ if (written.kind === "list") {
320
+ const listCast = support.lookup.get(receivingType)?.listCast;
321
+ if (listCast === void 0) return refused(void 0, {
322
+ code: "PSL_VALUE_TYPE_INCOMPATIBLE",
323
+ message: `${describeExpected(forms)}; got a list`
324
+ });
325
+ const elementGuidance = {
326
+ forms: admittedForms(support, listCast.of),
327
+ rewrite: void 0
328
+ };
329
+ const elements = [];
330
+ for (const [index, element] of written.elements.entries()) {
331
+ if (element.kind === "list") return refused(index, {
332
+ code: "PSL_INVALID_LITERAL",
333
+ message: "a list holds values, not other lists"
334
+ });
335
+ const read = readWrittenValue(support, element);
336
+ if (!read.ok) return refused(index, describeRefusal(read.failure, support, elementGuidance));
337
+ if (!listCast.of.includes(read.value.type)) return refused(index, {
338
+ code: "PSL_VALUE_TYPE_INCOMPATIBLE",
339
+ message: describeRefusedValueType({
340
+ receivingType,
341
+ valueType: read.value.type
342
+ }, support, elementGuidance)
343
+ });
344
+ elements.push(read.value.value);
345
+ }
346
+ let json;
347
+ try {
348
+ json = listCast.cast(elements);
349
+ } catch (error) {
350
+ if (isInternalError(error)) throw error;
351
+ return refused(void 0, {
352
+ code: "PSL_INVALID_LITERAL",
353
+ message: messageOf(error)
354
+ });
355
+ }
356
+ return stored(json);
357
+ }
358
+ const read = readWrittenValue(support, written);
359
+ if (!read.ok) return refused(void 0, describeRefusal(read.failure, support, {
360
+ forms,
361
+ rewrite: void 0
362
+ }));
363
+ const cast = castTypedValue(support, receivingType, receivingParams, read.value);
364
+ if (cast.ok) return stored(cast.value.value);
365
+ const { failure } = cast;
366
+ if (failure.kind === "refused-by-type") return refused(void 0, {
367
+ code: "PSL_VALUE_REFUSED",
368
+ message: failure.message
369
+ });
370
+ return refused(void 0, describeRefusal(failure, support, {
371
+ forms,
372
+ rewrite: failure.kind === "no-cast" ? exactRewrite(support, failure, written) : void 0
373
+ }));
374
+ }
497
375
  /** The type itself, then each type it casts from, in key order. */
498
376
  function admittedTypes(support, dataType) {
499
377
  return [dataType, ...Object.keys(support.lookup.get(dataType)?.casts ?? {})];
@@ -549,7 +427,338 @@ function joinForms(forms) {
549
427
  function describeAdmittedForms(support, dataType) {
550
428
  return joinForms(admittedForms(support, [dataType]));
551
429
  }
430
+ /**
431
+ * The refusals of a discriminator: the field must be required, hold one value, and have one of the stack's text data types; and when an enum types it, each variant's value, as the field stores it, must be one of the enum's members, compared by the field's data type's equality. Returns no refusals for a discriminator that is valid.
432
+ */
433
+ function discriminatorRefusals(input) {
434
+ const { field } = input;
435
+ const textDataTypes = input.dataTypes.textDataTypes ?? [];
436
+ if (textDataTypes.length === 0) throw new InternalError("The stack names no text data types, so no field can be a discriminator; the target names its text types in its authoring contributions.");
437
+ const refusals = [];
438
+ if (field.nullable) refusals.push({ kind: "optional" });
439
+ if (field.many) refusals.push({ kind: "list" });
440
+ const dataType = field.ref === void 0 ? void 0 : input.codecLookup.descriptorFor(field.ref.codecId)?.dataType;
441
+ if (dataType === void 0 || !textDataTypes.includes(dataType)) refusals.push({
442
+ kind: "not-text",
443
+ dataType,
444
+ textDataTypes
445
+ });
446
+ const members = field.enumMembers;
447
+ if (members !== void 0) {
448
+ const equalityKey = dataType === void 0 ? void 0 : input.dataTypes.lookup.get(dataType)?.equalityKey;
449
+ const memberKeys = new Set(members.map((member) => storedValueKey(member, equalityKey)));
450
+ for (const { key, stored } of input.variantValues) if (!memberKeys.has(storedValueKey(stored, equalityKey))) refusals.push({
451
+ kind: "not-a-member",
452
+ key,
453
+ stored,
454
+ members
455
+ });
456
+ }
457
+ return refusals;
458
+ }
459
+ /**
460
+ * A discriminator refusal worded as a PSL diagnostic: a refusal of the field at its `@@discriminator`, and a value that is not a member at its `@@base`. The wording names PSL syntax, so PSL sources word the refusals with this; a TypeScript source words them in its own terms.
461
+ */
462
+ function describeDiscriminatorRefusal(refusal, subject) {
463
+ const field = `Discriminator field "${subject.fieldName}" on model "${subject.modelName}"`;
464
+ switch (refusal.kind) {
465
+ case "optional": return `${field} must be required, but it is optional. Remove the "?"`;
466
+ case "list": return `${field} must hold one value, but it is a list. Remove the "[]"`;
467
+ case "not-text": return `${field} must be text, such as String, but is "${subject.typeName}"`;
468
+ case "not-a-member": return `Model "${subject.variantName(refusal.key)}" declares @@base value ${JSON.stringify(refusal.stored)}, which is not a member of enum "${subject.enumName}", the type of discriminator field "${subject.modelName}.${subject.fieldName}". Write one of: ${refusal.members.map((member) => JSON.stringify(member)).join(", ")}`;
469
+ }
470
+ }
471
+ /**
472
+ * Applies the discriminator rule to one discriminator and its variants: reads each variant's written value into the field's codec with {@link readWrittenValueIntoCodec}, worded after `subject`, then decides with {@link discriminatorRefusals}. A refused field refuses the whole discriminator, so its variants' values are neither read nor refused. A discriminator is text, so a stored value that is not a string is a bug in a text data type.
473
+ */
474
+ function applyDiscriminatorRule(input) {
475
+ const { field, codecLookup, dataTypes } = input;
476
+ const fieldOnly = discriminatorRefusals({
477
+ field,
478
+ variantValues: [],
479
+ codecLookup,
480
+ dataTypes
481
+ }).filter(isFieldRefusal);
482
+ if (fieldOnly.length > 0) return {
483
+ fieldRefusals: fieldOnly,
484
+ variantRefusals: [],
485
+ values: /* @__PURE__ */ new Map()
486
+ };
487
+ const ref = field.ref;
488
+ if (ref === void 0) throw new InternalError("A discriminator field the rule accepts has a codec.");
489
+ const reads = input.variants.map(({ key, written }) => ({
490
+ key,
491
+ reading: readWrittenValueIntoCodec({
492
+ support: dataTypes,
493
+ codecLookup,
494
+ ref,
495
+ written,
496
+ subject: input.subject
497
+ })
498
+ }));
499
+ const notMembers = new Map(discriminatorRefusals({
500
+ field,
501
+ variantValues: reads.flatMap(({ key, reading }) => reading.ok ? [{
502
+ key,
503
+ stored: reading.value
504
+ }] : []),
505
+ codecLookup,
506
+ dataTypes
507
+ }).flatMap((refusal) => refusal.kind === "not-a-member" ? [[refusal.key, refusal]] : []));
508
+ const variantRefusals = [];
509
+ const values = /* @__PURE__ */ new Map();
510
+ for (const { key, reading } of reads) {
511
+ if (!reading.ok) {
512
+ variantRefusals.push({
513
+ kind: "unreadable",
514
+ key,
515
+ refusal: reading.failure
516
+ });
517
+ continue;
518
+ }
519
+ const notMember = notMembers.get(key);
520
+ if (notMember !== void 0) {
521
+ variantRefusals.push(notMember);
522
+ continue;
523
+ }
524
+ if (typeof reading.value !== "string") throw new InternalError(`Discriminator field codec "${ref.codecId}" stores a text value as ${typeof reading.value}.`);
525
+ values.set(key, reading.value);
526
+ }
527
+ return {
528
+ fieldRefusals: [],
529
+ variantRefusals,
530
+ values
531
+ };
532
+ }
533
+ function isFieldRefusal(refusal) {
534
+ return refusal.kind !== "not-a-member";
535
+ }
536
+ /**
537
+ * A problem with an enum's members as a diagnostic at the member, or at the block when the problem is the enum's codec.
538
+ */
539
+ function enumMemberProblemDiagnostic(problem, site) {
540
+ const { enumName, codecId, sourceId } = site;
541
+ const at = (member) => ({
542
+ sourceId,
543
+ span: site.memberSpans[member] ?? site.span
544
+ });
545
+ switch (problem.kind) {
546
+ case "codec-not-for-enums": return {
547
+ code: "PSL_EXTENSION_INVALID_VALUE",
548
+ message: `enum "${enumName}" cannot use the codec "${codecId}". ${problem.refusal}`,
549
+ sourceId,
550
+ span: site.span
551
+ };
552
+ case "codec-missing": return {
553
+ code: "PSL_EXTENSION_INVALID_VALUE",
554
+ message: `enum "${enumName}" uses codec "${codecId}", which no pack in the contract provides`,
555
+ sourceId,
556
+ span: site.span
557
+ };
558
+ case "codec-refused-member": return {
559
+ code: "PSL_EXTENSION_INVALID_VALUE",
560
+ message: `enum "${enumName}" member "${problem.member}" was rejected by codec "${codecId}": ${problem.reason}`,
561
+ ...at(problem.member)
562
+ };
563
+ case "member-not-stored-as-written": return {
564
+ code: "PSL_EXTENSION_INVALID_VALUE",
565
+ message: `enum "${enumName}" member "${problem.member}" is written ${problem.written}, but its codec stores ${JSON.stringify(problem.stored)}. Write the member as ${problem.writeAs}.`,
566
+ ...at(problem.member)
567
+ };
568
+ case "duplicate-member-value": return {
569
+ code: "PSL_ENUM_DUPLICATE_MEMBER_VALUE",
570
+ message: problem.earlierStored === void 0 ? `enum "${enumName}": members "${problem.earlier}" and "${problem.later}" both store ${JSON.stringify(problem.stored)}` : `enum "${enumName}": members "${problem.earlier}" and "${problem.later}" store ${JSON.stringify(problem.earlierStored)} and ${JSON.stringify(problem.stored)}, which the database holds equal`,
571
+ ...at(problem.later)
572
+ };
573
+ }
574
+ }
575
+ /** A member as it is written: its recorded written value, or a bare member's name, as text. */
576
+ function writtenMember(block, memberName, memberValue) {
577
+ const written = block.writtenValues?.[memberName];
578
+ if (written !== void 0) return written;
579
+ if (memberValue === void 0) return {
580
+ kind: "string",
581
+ text: memberName
582
+ };
583
+ throw new InternalError(`enum "${block.name}" member "${memberName}" has a value, but the block holds no written value for it.`);
584
+ }
585
+ /**
586
+ * Reads the members of an `enum` block through its codec with {@link readWrittenValueIntoCodec}: each member's syntax gives it a data type, the codec's data type takes it directly or through a cast, and the codec checks it, so a number keeps every digit and a quoted value is text. A bare member is read from its own name, as text.
587
+ * Pushes a diagnostic and returns `undefined` when a member is refused, when two members
588
+ * store the same value, or when the block has no members. Shared by every family's enum factory.
589
+ */
590
+ function readEnumBlockMembers(block, codecId, codec, ctx) {
591
+ const sourceId = ctx.sourceId ?? "unknown";
592
+ const diagnostics = ctx.diagnostics;
593
+ const site = {
594
+ enumName: block.name,
595
+ codecId,
596
+ sourceId,
597
+ span: block.span,
598
+ memberSpans: block.parameterSpans
599
+ };
600
+ const members = [];
601
+ const storedMembers = [];
602
+ let memberError = false;
603
+ for (const [memberName, memberValue] of Object.entries(block.values)) {
604
+ const span = block.parameterSpans[memberName] ?? block.span;
605
+ const reading = readWrittenValueIntoCodec({
606
+ support: ctx.dataTypes,
607
+ codecLookup: ctx.codecLookup,
608
+ ref: { codecId },
609
+ written: writtenMember(block, memberName, memberValue),
610
+ subject: `enum "${block.name}" member "${memberName}"`
611
+ });
612
+ if (!reading.ok) {
613
+ diagnostics?.push(memberValue === void 0 ? {
614
+ code: "PSL_ENUM_BARE_MEMBER_NON_STRING_CODEC",
615
+ message: `enum "${block.name}" member "${memberName}" has no value and codec "${codecId}" does not accept a bare name as input`,
616
+ sourceId,
617
+ span
618
+ } : {
619
+ ...reading.failure,
620
+ sourceId,
621
+ span
622
+ });
623
+ memberError = true;
624
+ continue;
625
+ }
626
+ const read = readContractValue(codec, reading.value, void 0);
627
+ members.push({
628
+ name: memberName,
629
+ value: read
630
+ });
631
+ storedMembers.push({
632
+ name: memberName,
633
+ stored: codec.dataType.toContract(codec.toDataTypeValue(read))
634
+ });
635
+ }
636
+ for (const duplicate of duplicateStoredMembers(storedMembers, codec.dataType.equalityKey)) {
637
+ diagnostics?.push(enumMemberProblemDiagnostic({
638
+ kind: "duplicate-member-value",
639
+ ...duplicate
640
+ }, site));
641
+ memberError = true;
642
+ }
643
+ if (memberError) return void 0;
644
+ if (members.length === 0) {
645
+ diagnostics?.push({
646
+ code: "PSL_ENUM_MISSING_TYPE",
647
+ message: `enum "${block.name}" must have at least one member`,
648
+ sourceId,
649
+ span: block.span
650
+ });
651
+ return;
652
+ }
653
+ return members;
654
+ }
655
+ /** Whether TypeScript gives the value a literal type: a primitive, or an array or plain object of them. */
656
+ function hasLiteralType(value) {
657
+ if ([
658
+ "string",
659
+ "number",
660
+ "boolean",
661
+ "bigint"
662
+ ].includes(typeof value)) return true;
663
+ if (Array.isArray(value)) return value.every(hasLiteralType);
664
+ if (typeof value !== "object" || value === null) return false;
665
+ const prototype = Object.getPrototypeOf(value);
666
+ return (prototype === Object.prototype || prototype === null) && Object.values(value).every(hasLiteralType);
667
+ }
668
+ /**
669
+ * A member's value in the form its codec stores it, and that form read back by the codec. A codec that throws on either is a refusal naming the member; an internal error is not the member's fault and propagates.
670
+ */
671
+ function encodeEnumMember(member, codec) {
672
+ try {
673
+ const stored = codec.dataType.toContract(codec.toDataTypeValue(member.value));
674
+ return ok({
675
+ stored,
676
+ readBack: readContractValue(codec, stored, void 0)
677
+ });
678
+ } catch (cause) {
679
+ if (isInternalError(cause)) throw cause;
680
+ return notOk({
681
+ kind: "codec-refused-member",
682
+ member: member.name,
683
+ reason: cause instanceof Error ? cause.message : String(cause),
684
+ cause
685
+ });
686
+ }
687
+ }
688
+ /**
689
+ * Refuses a member its codec reads back as a different value from the one written. A member with no literal type has nothing to compare.
690
+ */
691
+ function notStoredAsWritten(member, stored, readBack) {
692
+ if (!hasLiteralType(member.value)) return void 0;
693
+ if (hasLiteralType(readBack) && canonicalStringify(readBack) === canonicalStringify(member.value)) return void 0;
694
+ return {
695
+ kind: "member-not-stored-as-written",
696
+ member: member.name,
697
+ written: canonicalStringify(member.value),
698
+ stored,
699
+ writeAs: hasLiteralType(readBack) ? canonicalStringify(readBack) : JSON.stringify(stored)
700
+ };
701
+ }
702
+ /**
703
+ * Each member of an enum in the form its codec stores it. Refuses a codec an enum cannot use, a codec the lookup does not have, a member the codec refuses, a member the codec reads back as another value, and two members stored as the same value. Every family's contract build calls this, and reports the problems in its own terms.
704
+ */
705
+ function encodeEnumMembers(decodedEnum, codecLookup) {
706
+ const descriptor = codecLookup.descriptorFor(decodedEnum.codecId);
707
+ const refusal = descriptor === void 0 ? void 0 : enumRefusalOf(descriptor);
708
+ if (refusal !== void 0) return notOk([{
709
+ kind: "codec-not-for-enums",
710
+ refusal
711
+ }]);
712
+ const codec = codecLookup.get(decodedEnum.codecId);
713
+ if (codec === void 0) return notOk([{ kind: "codec-missing" }]);
714
+ const problems = [];
715
+ const members = [];
716
+ for (const member of decodedEnum.enumMembers) {
717
+ const encoded = encodeEnumMember(member, codec);
718
+ if (!encoded.ok) {
719
+ problems.push(encoded.failure);
720
+ continue;
721
+ }
722
+ const { stored, readBack } = encoded.value;
723
+ const mismatch = notStoredAsWritten(member, stored, readBack);
724
+ if (mismatch !== void 0) problems.push(mismatch);
725
+ members.push({
726
+ name: member.name,
727
+ value: stored
728
+ });
729
+ }
730
+ for (const duplicate of duplicateStoredMembers(members.map(({ name, value }) => ({
731
+ name,
732
+ stored: value
733
+ })), codec.dataType.equalityKey)) problems.push({
734
+ kind: "duplicate-member-value",
735
+ ...duplicate
736
+ });
737
+ return problems.length > 0 ? notOk(problems) : ok(members);
738
+ }
739
+ function presetSpellingsUnder(members, prefix) {
740
+ return Object.entries(members).flatMap(([name, member]) => isAuthoringFieldPresetDescriptor(member) ? [`${prefix}.${name}(${(member.args ?? []).map((arg, index) => arg.name ?? `argument${index + 1}`).join(", ")})`] : presetSpellingsUnder(member, `${prefix}.${name}`));
741
+ }
742
+ /**
743
+ * How each field preset registered under `namespace`, at any depth, is written, with the names of its arguments: `temporal.timestamp(onCreate, onUpdate)`.
744
+ */
745
+ function fieldPresetSpellings(contributions, namespace) {
746
+ const members = contributions?.field?.[namespace];
747
+ if (members === void 0 || isAuthoringFieldPresetDescriptor(members)) return [];
748
+ return presetSpellingsUnder(members, namespace);
749
+ }
750
+ /**
751
+ * Walks `authoringContributions.field` segment by segment and returns the field-preset descriptor at the path, or `undefined` when none is registered there.
752
+ */
753
+ function getAuthoringFieldPreset(contributions, path) {
754
+ let current = contributions?.field;
755
+ for (const segment of path) {
756
+ if (typeof current !== "object" || current === null || "kind" in current) return;
757
+ current = current[segment];
758
+ }
759
+ return current !== void 0 && isAuthoringFieldPresetDescriptor(current) ? current : void 0;
760
+ }
552
761
  //#endregion
553
- export { tagForm as C, readWrittenValueAs as S, findAuthoringTypeConstructorCall as _, castTypedValue as a, readEnumBlockMembers as b, describeRefusal as c, encodeEnumMembers as d, entryForPlain as f, fieldPresetSpellings as g, exactRewrite as h, authoringTypeConstructors as i, describeRefusedValueType as l, enumMemberProblemDiagnostic as m, admittedTags as n, describeAdmittedForms as o, entryForTag as p, authoringTypeConstructorArguments as r, describeExpected as s, admittedForms as t, duplicateStoredMembers as u, getAuthoringFieldPreset as v, readWrittenValue as x, knownTags as y };
762
+ export { readWrittenValue as C, tagForm as E, readEnumBlockMembers as S, readWrittenValueIntoCodec as T, exactRewrite as _, authoringTypeConstructors as a, getAuthoringFieldPreset as b, describeDiscriminatorRefusal as c, describeRefusedValueType as d, duplicateStoredMembers as f, enumMemberProblemDiagnostic as g, entryForTag as h, authoringTypeConstructorArguments as i, describeExpected as l, entryForPlain as m, admittedTags as n, castTypedValue as o, encodeEnumMembers as p, applyDiscriminatorRule as r, describeAdmittedForms as s, admittedForms as t, describeRefusal as u, fieldPresetSpellings as v, readWrittenValueAs as w, knownTags as x, findAuthoringTypeConstructorCall as y };
554
763
 
555
- //# sourceMappingURL=authoring-BMkyimEq.mjs.map
764
+ //# sourceMappingURL=authoring-CNUti739.mjs.map