@prisma/orm-family-sql 8.0.0-rc.11-dev.42 → 8.0.0-rc.11-dev.44

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 (168) hide show
  1. package/dist/{ast-BHZ0g4iL.d.mts → ast-d2-iNoEs.d.mts} +72 -10
  2. package/dist/ast-d2-iNoEs.d.mts.map +1 -0
  3. package/dist/{ast-C8jX7HNs.mjs → ast-um6jG7BL.mjs} +129 -8
  4. package/dist/ast-um6jG7BL.mjs.map +1 -0
  5. package/dist/{authoring-type-constructors-C1ogrr_x-BeSS93gc.mjs → authoring-type-constructors-C1ogrr_x-VWDkCaSq.mjs} +2 -2
  6. package/dist/{authoring-type-constructors-C1ogrr_x-BeSS93gc.mjs.map → authoring-type-constructors-C1ogrr_x-VWDkCaSq.mjs.map} +1 -1
  7. package/dist/builder.d.mts +2 -2
  8. package/dist/builder__runtime.d.mts +8 -8
  9. package/dist/builder__types.d.mts +2 -2
  10. package/dist/{config-types-C-rrJ_8P.d.mts → config-types-Bd3ud-mX.d.mts} +3 -3
  11. package/dist/{config-types-C-rrJ_8P.d.mts.map → config-types-Bd3ud-mX.d.mts.map} +1 -1
  12. package/dist/{config-types-B98UYjF0.mjs → config-types-fwqTEhK6.mjs} +2 -2
  13. package/dist/{config-types-B98UYjF0.mjs.map → config-types-fwqTEhK6.mjs.map} +1 -1
  14. package/dist/{contract-builder-DV-DZX4h.d.mts → contract-builder-BHCjHphC.d.mts} +12 -5
  15. package/dist/{contract-builder-DV-DZX4h.d.mts.map → contract-builder-BHCjHphC.d.mts.map} +1 -1
  16. package/dist/{contract-builder-BCqPVNbs.mjs → contract-builder-BgWPuVYv.mjs} +2 -2
  17. package/dist/{contract-builder-BCqPVNbs.mjs.map → contract-builder-BgWPuVYv.mjs.map} +1 -1
  18. package/dist/contract-prisma7__provider.d.mts +1 -1
  19. package/dist/contract-prisma7__provider.mjs +118 -48
  20. package/dist/contract-prisma7__provider.mjs.map +1 -1
  21. package/dist/contract-psl.d.mts +10 -6
  22. package/dist/contract-psl.d.mts.map +1 -1
  23. package/dist/contract-psl.mjs +1 -1
  24. package/dist/contract-psl__attribute-specs.d.mts +9 -7
  25. package/dist/contract-psl__attribute-specs.d.mts.map +1 -1
  26. package/dist/contract-psl__attribute-specs.mjs +1 -1
  27. package/dist/contract-psl__provider.d.mts +1 -1
  28. package/dist/contract-psl__provider.mjs +3 -2
  29. package/dist/contract-psl__provider.mjs.map +1 -1
  30. package/dist/contract-ts.d.mts +3 -3
  31. package/dist/contract-ts.mjs +3 -3
  32. package/dist/contract-ts__config-types.d.mts +1 -1
  33. package/dist/contract-ts__config-types.mjs +1 -1
  34. package/dist/contract-ts__contract-builder.d.mts +2 -2
  35. package/dist/contract-ts__contract-builder.mjs +2 -2
  36. package/dist/contract.d.mts +5 -5
  37. package/dist/contract__factories.d.mts +1 -1
  38. package/dist/contract__index-type-validation.d.mts +1 -1
  39. package/dist/contract__types.d.mts +2 -2
  40. package/dist/contract__validators.d.mts +1 -1
  41. package/dist/{control-C9oCqe39.d.mts → control-D7O180pB.d.mts} +21 -18
  42. package/dist/control-D7O180pB.d.mts.map +1 -0
  43. package/dist/{control-Cijy1SHG.mjs → control-FOipY3kl.mjs} +11 -6
  44. package/dist/{control-Cijy1SHG.mjs.map → control-FOipY3kl.mjs.map} +1 -1
  45. package/dist/{control-adapter-C99J7aEF-B2G4GA5s.d.mts → control-adapter-C99J7aEF-DwFChl8n.d.mts} +8 -8
  46. package/dist/{control-adapter-C99J7aEF-B2G4GA5s.d.mts.map → control-adapter-C99J7aEF-DwFChl8n.d.mts.map} +1 -1
  47. package/dist/control-adapter-DPWKLNdH.d.mts +1 -0
  48. package/dist/{db-BhQdL6Za-Dod07quT.d.mts → db-BhQdL6Za-BBgu_awF.d.mts} +8 -8
  49. package/dist/{db-BhQdL6Za-Dod07quT.d.mts.map → db-BhQdL6Za-BBgu_awF.d.mts.map} +1 -1
  50. package/dist/{ddl-types-BGdnAbXo-DKPHPUGx.mjs → ddl-types-DOgOmDOh-Cs_MY05h.mjs} +2 -2
  51. package/dist/{ddl-types-BGdnAbXo-DKPHPUGx.mjs.map → ddl-types-DOgOmDOh-Cs_MY05h.mjs.map} +1 -1
  52. package/dist/{ddl-types-Biy7miT--CSyPnOHq.d.mts → ddl-types-DrK8E0jL-ClX_UkVh.d.mts} +4 -4
  53. package/dist/{ddl-types-Biy7miT--CSyPnOHq.d.mts.map → ddl-types-DrK8E0jL-ClX_UkVh.d.mts.map} +1 -1
  54. package/dist/{derived-checks-C4BPtrnO-B9MQRh6W.mjs → derived-checks-6WZKIUxH-B3Pd6QA5.mjs} +30 -12
  55. package/dist/derived-checks-6WZKIUxH-B3Pd6QA5.mjs.map +1 -0
  56. package/dist/{derived-checks-DPdD01O0-DCKdvxNK.d.mts → derived-checks-DPdD01O0-DNBs1ZDA.d.mts} +2 -2
  57. package/dist/{derived-checks-DPdD01O0-DCKdvxNK.d.mts.map → derived-checks-DPdD01O0-DNBs1ZDA.d.mts.map} +1 -1
  58. package/dist/{diff-CwozLSiO.d.mts → diff-C9tzE_nE.d.mts} +7 -7
  59. package/dist/{diff-CwozLSiO.d.mts.map → diff-C9tzE_nE.d.mts.map} +1 -1
  60. package/dist/{expression-CTADTPZW.d.mts → expression-CAJjmssr.d.mts} +6 -6
  61. package/dist/{expression-CTADTPZW.d.mts.map → expression-CAJjmssr.d.mts.map} +1 -1
  62. package/dist/{factories-B9PfKd5k.d.mts → factories-P3qBQhO-.d.mts} +2 -2
  63. package/dist/{factories-B9PfKd5k.d.mts.map → factories-P3qBQhO-.d.mts.map} +1 -1
  64. package/dist/family.d.mts +11 -11
  65. package/dist/family.mjs +2 -2
  66. package/dist/family__control-adapter.d.mts +2 -2
  67. package/dist/family__control.d.mts +4 -4
  68. package/dist/family__control.mjs +1 -1
  69. package/dist/family__diff.d.mts +2 -2
  70. package/dist/family__ir.d.mts +1 -1
  71. package/dist/family__migration.d.mts +1 -1
  72. package/dist/family__pack.d.mts +2 -2
  73. package/dist/family__pack.d.mts.map +1 -1
  74. package/dist/family__pack.mjs +2 -2
  75. package/dist/family__psl-infer.d.mts +1 -1
  76. package/dist/family__psl-infer.mjs +1 -1
  77. package/dist/family__runtime.d.mts +1 -1
  78. package/dist/{index-C6_--MKi.d.mts → index-CLAshwKN.d.mts} +3 -3
  79. package/dist/{index-C6_--MKi.d.mts.map → index-CLAshwKN.d.mts.map} +1 -1
  80. package/dist/{index-CA_WLNy1.d.mts → index-DI6YpxCw.d.mts} +10 -10
  81. package/dist/{index-CA_WLNy1.d.mts.map → index-DI6YpxCw.d.mts.map} +1 -1
  82. package/dist/{index-type-validation-BFiTwZub.d.mts → index-type-validation-CZ5L2lli.d.mts} +2 -2
  83. package/dist/{index-type-validation-BFiTwZub.d.mts.map → index-type-validation-CZ5L2lli.d.mts.map} +1 -1
  84. package/dist/{interpreter-Bf7Um__3-DC_thY44.mjs → interpreter-BIBwrA2w-DAiNN30m.mjs} +568 -181
  85. package/dist/interpreter-BIBwrA2w-DAiNN30m.mjs.map +1 -0
  86. package/dist/{ir-CodnAisu.d.mts → ir-BJ-dsbe-.d.mts} +2 -2
  87. package/dist/{ir-CodnAisu.d.mts.map → ir-BJ-dsbe-.d.mts.map} +1 -1
  88. package/dist/{middleware-0yjzaoBT-BqmCD6Dt.d.mts → middleware-CHg6zJkn-DJAKnDpd.d.mts} +3 -3
  89. package/dist/{middleware-0yjzaoBT-BqmCD6Dt.d.mts.map → middleware-CHg6zJkn-DJAKnDpd.d.mts.map} +1 -1
  90. package/dist/middleware-wyJe8dVq.d.mts +1 -0
  91. package/dist/{migration-CniGZoFt.d.mts → migration-BQWwBE8Q.d.mts} +3 -3
  92. package/dist/{migration-CniGZoFt.d.mts.map → migration-BQWwBE8Q.d.mts.map} +1 -1
  93. package/dist/operations.d.mts +1 -1
  94. package/dist/orm-client.d.mts +13 -13
  95. package/dist/orm-client.mjs +1 -1
  96. package/dist/{plan-Bs-Pdirc-BCy94--G.d.mts → plan-DVkrl9Pq-DOf_eQ84.d.mts} +4 -4
  97. package/dist/plan-DVkrl9Pq-DOf_eQ84.d.mts.map +1 -0
  98. package/dist/plan-Dzq6Nwb4.d.mts +2 -0
  99. package/dist/{prepared-statement-DZtymlzd-DFIuG_WK.d.mts → prepared-statement-DZtymlzd-DmbP44p0.d.mts} +15 -15
  100. package/dist/{prepared-statement-DZtymlzd-DFIuG_WK.d.mts.map → prepared-statement-DZtymlzd-DmbP44p0.d.mts.map} +1 -1
  101. package/dist/{psl-infer-6p4x9ebN.mjs → psl-infer-BAbdN_ZR.mjs} +195 -13
  102. package/dist/psl-infer-BAbdN_ZR.mjs.map +1 -0
  103. package/dist/{psl-infer-CLZsT2Hz.d.mts → psl-infer-DQCWvJtk.d.mts} +16 -3
  104. package/dist/psl-infer-DQCWvJtk.d.mts.map +1 -0
  105. package/dist/{query-lane-context-QIUURgPP-CvQ9jQRm.d.mts → query-lane-context-BUNC86DS-C_hIrqaW.d.mts} +6 -6
  106. package/dist/{query-lane-context-QIUURgPP-CvQ9jQRm.d.mts.map → query-lane-context-BUNC86DS-C_hIrqaW.d.mts.map} +1 -1
  107. package/dist/query-lane-context-CeOxBL6I.d.mts +1 -0
  108. package/dist/relational-core.d.mts +12 -12
  109. package/dist/relational-core.mjs +3 -3
  110. package/dist/relational-core__aggregate-descriptor-registry.d.mts +1 -1
  111. package/dist/relational-core__ast.d.mts +4 -4
  112. package/dist/relational-core__ast.mjs +3 -3
  113. package/dist/relational-core__codec-descriptor-registry.d.mts +3 -3
  114. package/dist/relational-core__contract-free.d.mts +3 -3
  115. package/dist/relational-core__contract-free.mjs +1 -1
  116. package/dist/relational-core__contract-free.mjs.map +1 -1
  117. package/dist/relational-core__expression.d.mts +1 -1
  118. package/dist/relational-core__middleware.d.mts +2 -2
  119. package/dist/relational-core__plan.d.mts +3 -3
  120. package/dist/relational-core__query-lane-context.d.mts +2 -2
  121. package/dist/relational-core__types.d.mts +2 -2
  122. package/dist/{runtime-gCSNgykk.d.mts → runtime-BqAUXvAl.d.mts} +3 -3
  123. package/dist/{runtime-gCSNgykk.d.mts.map → runtime-BqAUXvAl.d.mts.map} +1 -1
  124. package/dist/runtime.d.mts +4 -4
  125. package/dist/runtime.mjs +1 -1
  126. package/dist/runtime__internal__prepared-query.d.mts +1 -1
  127. package/dist/{schema-differ-DpG_gnur-DrAcUO68.d.mts → schema-differ-DpG_gnur-CXVM1Oed.d.mts} +4 -4
  128. package/dist/{schema-differ-DpG_gnur-DrAcUO68.d.mts.map → schema-differ-DpG_gnur-CXVM1Oed.d.mts.map} +1 -1
  129. package/dist/schema-ir.d.mts +1 -1
  130. package/dist/schema-ir__types.d.mts +2 -2
  131. package/dist/{sql-attribute-specs-DAEpjrWl-C0kmaUJt.mjs → sql-attribute-specs-BH0U6i1B-Ces5ZCvv.mjs} +37 -23
  132. package/dist/sql-attribute-specs-BH0U6i1B-Ces5ZCvv.mjs.map +1 -0
  133. package/dist/{sql-execution-plan-S3HvDKIP-8KF1nBHu.d.mts → sql-execution-plan-DBvAsaOB-LUMcfRpN.d.mts} +3 -3
  134. package/dist/sql-execution-plan-DBvAsaOB-LUMcfRpN.d.mts.map +1 -0
  135. package/dist/{types-BDUG29Df-DRoC4zw1.d.mts → types-BDUG29Df-LE85dIXP.d.mts} +2 -2
  136. package/dist/{types-BDUG29Df-DRoC4zw1.d.mts.map → types-BDUG29Df-LE85dIXP.d.mts.map} +1 -1
  137. package/dist/{types-BFPRCYGW-CvvVz-AC.d.mts → types-BFPRCYGW-CBv60DKI.d.mts} +7 -7
  138. package/dist/{types-BFPRCYGW-CvvVz-AC.d.mts.map → types-BFPRCYGW-CBv60DKI.d.mts.map} +1 -1
  139. package/dist/{types-CRU1CBUk-CR2_opbw.d.mts → types-BLVS175T-DmpY58Nx.d.mts} +9 -9
  140. package/dist/{types-CRU1CBUk-CR2_opbw.d.mts.map → types-BLVS175T-DmpY58Nx.d.mts.map} +1 -1
  141. package/dist/types-BijNazlM.d.mts +1 -0
  142. package/dist/{types-BmgtemBx.d.mts → types-C36_3E6_.d.mts} +2 -2
  143. package/dist/{types-BmgtemBx.d.mts.map → types-C36_3E6_.d.mts.map} +1 -1
  144. package/dist/{types-CHOgKgHg-DMlDrQz6.d.mts → types-CHOgKgHg-BxgkL3GS.d.mts} +2 -2
  145. package/dist/{types-CHOgKgHg-DMlDrQz6.d.mts.map → types-CHOgKgHg-BxgkL3GS.d.mts.map} +1 -1
  146. package/dist/types-CQ8FfvRk.d.mts +1 -0
  147. package/dist/{types-BXSw7th1-pL1Iggyd.d.mts → types-YGX78yVc-BBy1pp_1.d.mts} +7 -5
  148. package/dist/types-YGX78yVc-BBy1pp_1.d.mts.map +1 -0
  149. package/dist/{validators-DvtOcB04.d.mts → validators-CJSyNFS4.d.mts} +2 -2
  150. package/dist/{validators-DvtOcB04.d.mts.map → validators-CJSyNFS4.d.mts.map} +1 -1
  151. package/package.json +18 -18
  152. package/dist/ast-BHZ0g4iL.d.mts.map +0 -1
  153. package/dist/ast-C8jX7HNs.mjs.map +0 -1
  154. package/dist/control-C9oCqe39.d.mts.map +0 -1
  155. package/dist/control-adapter-Bx5ZQKj-.d.mts +0 -1
  156. package/dist/derived-checks-C4BPtrnO-B9MQRh6W.mjs.map +0 -1
  157. package/dist/interpreter-Bf7Um__3-DC_thY44.mjs.map +0 -1
  158. package/dist/middleware-Di3_d2T5.d.mts +0 -1
  159. package/dist/plan-BEJGOQ-l.d.mts +0 -2
  160. package/dist/plan-Bs-Pdirc-BCy94--G.d.mts.map +0 -1
  161. package/dist/psl-infer-6p4x9ebN.mjs.map +0 -1
  162. package/dist/psl-infer-CLZsT2Hz.d.mts.map +0 -1
  163. package/dist/query-lane-context-yy5kDAlG.d.mts +0 -1
  164. package/dist/sql-attribute-specs-DAEpjrWl-C0kmaUJt.mjs.map +0 -1
  165. package/dist/sql-execution-plan-S3HvDKIP-8KF1nBHu.d.mts.map +0 -1
  166. package/dist/types-BXSw7th1-pL1Iggyd.d.mts.map +0 -1
  167. package/dist/types-D3XRY_cO.d.mts +0 -1
  168. package/dist/types-RPn42d0t.d.mts +0 -1
@@ -1,22 +1,23 @@
1
1
  import { n as isAuthoredIndexInput } from "./index-naming-Cj1Anq-T-w1JL7-EM.mjs";
2
2
  import { t as deriveValueSetFromEntity } from "./value-set-derivation-hook-Di9JZ0X7.mjs";
3
- import { n as buildSqlContractFromDefinition } from "./derived-checks-C4BPtrnO-B9MQRh6W.mjs";
4
- import { a as interpretFieldAttribute, i as findModelAttributeNode, n as fieldSpecContext, o as interpretModelAttribute, r as findFieldAttributeNode, s as sqlAttributeSpecs, t as PSL_CHECK_ON_STI_VARIANT } from "./sql-attribute-specs-DAEpjrWl-C0kmaUJt.mjs";
3
+ import { n as buildSqlContractFromDefinition } from "./derived-checks-6WZKIUxH-B3Pd6QA5.mjs";
4
+ import { a as interpretFieldAttribute, i as findModelAttributeNode, n as fieldSpecContext, o as interpretModelAttribute, r as findFieldAttributeNode, s as sqlAttributeSpecs, t as PSL_CHECK_ON_STI_VARIANT } from "./sql-attribute-specs-BH0U6i1B-Ces5ZCvv.mjs";
5
5
  import { t as defaultTableName } from "./default-table-name-BfFY8qYR-lHNcVmY5.mjs";
6
- import { structuredError } from "@prisma/orm-framework/utils/structured-error";
7
- import { hasRegisteredFieldNamespace, instantiateAuthoringEntityType, instantiateAuthoringFieldPreset, instantiateAuthoringTypeConstructor, isAuthoringEntityTypeDescriptor, isAuthoringFieldPresetDescriptor, isAuthoringModelAttributeDescriptor, isAuthoringPslBlockDescriptor, isAuthoringTypeConstructorDescriptor, validateAuthoringHelperArguments } from "@prisma/orm-framework/components/authoring";
6
+ import { isStructuredError, structuredError } from "@prisma/orm-framework/utils/structured-error";
7
+ import { hasRegisteredFieldNamespace, instantiateAuthoringEntityType, instantiateAuthoringFieldPreset, instantiateAuthoringTypeConstructor, isAuthoringEntityTypeDescriptor, isAuthoringFieldPresetDescriptor, isAuthoringModelAttributeDescriptor, isAuthoringPslBlockDescriptor, isAuthoringTypeConstructorDescriptor, isDataTypeLoweringEntry, loweringEntryKey, validateAuthoringHelperArguments } from "@prisma/orm-framework/components/authoring";
8
8
  import { UNBOUND_NAMESPACE_ID } from "@prisma/orm-framework/components/ir";
9
9
  import { InternalError } from "@prisma/orm-framework/utils/internal-error";
10
10
  import { crossRef } from "@prisma/orm-framework/contract/types";
11
11
  import { ifDefined } from "@prisma/orm-framework/utils/defined";
12
12
  import { blindCast } from "@prisma/orm-framework/utils/casts";
13
13
  import { resolveToOneRelationNullable } from "@prisma/orm-framework/contract-authoring";
14
+ import { materializeCodec } from "@prisma/orm-framework/components/codec";
14
15
  import { assertDefined, invariant } from "@prisma/orm-framework/utils/assertions";
15
16
  import { describeTaggedLiteralFailure } from "@prisma/orm-framework/components/control";
16
17
  import { notOk, ok } from "@prisma/orm-framework/utils/result";
17
18
  import { createPslDiagnosticCollector, diagnosticSource, findBlockDescriptor, keywordPslSpan, nodePslSpan } from "@prisma/orm-framework/psl-parser";
18
19
  import { consumeInvalidFkPairing, fkRelationPairKey, requiredOneToOneBackrelationDiagnostic } from "@prisma/orm-framework/psl-parser/interpret";
19
- //#region ../../../2-sql/2-authoring/contract-psl/dist/interpreter-Bf7Um__3.mjs
20
+ //#region ../../../2-sql/2-authoring/contract-psl/dist/interpreter-BIBwrA2w.mjs
20
21
  function contractError(code, message, options) {
21
22
  return structuredError(code, message, options);
22
23
  }
@@ -56,6 +57,316 @@ function mapFieldNamesToColumns(input) {
56
57
  }
57
58
  return columns;
58
59
  }
60
+ /** A `` json`...` `` body that is not a JSON document. */
61
+ const PSL_INVALID_JSON_LITERAL = "PSL_INVALID_JSON_LITERAL";
62
+ /** A written value the entry, a cast, or the column's codec refuses. */
63
+ const PSL_INVALID_DEFAULT_LITERAL = "PSL_INVALID_DEFAULT_LITERAL";
64
+ /** A written value whose data type the column's type neither is nor casts from. */
65
+ const PSL_DEFAULT_TYPE_INCOMPATIBLE = "PSL_DEFAULT_TYPE_INCOMPATIBLE";
66
+ /** The code the JSON reader raises, so the PSL diagnostic for a bad document is its own. */
67
+ const INVALID_JSON_CODE = "CONTRACT.INVALID_JSON_LITERAL";
68
+ /** The value entries of a stack, by data type id. */
69
+ function valueEntries(support) {
70
+ return Object.entries(support.entries).flatMap(([key, entry]) => isDataTypeLoweringEntry(entry) ? [] : [[key, entry]]);
71
+ }
72
+ /** The entry a tag names, or `undefined` when no pack registered that tag. */
73
+ function entryForTag(support, tag) {
74
+ for (const [key, entry] of valueEntries(support)) if (entry.written.kind === "tag" && entry.written.tag === tag) return {
75
+ key,
76
+ entry
77
+ };
78
+ }
79
+ /** Every tag a stack registers, in the order the entries were merged, for a diagnostic. */
80
+ function knownTags(support) {
81
+ return Object.values(support.entries).flatMap((entry) => entry.written.kind === "tag" ? [entry.written.tag] : []);
82
+ }
83
+ function entryForPlain(support, syntax) {
84
+ for (const [key, entry] of valueEntries(support)) if (entry.written.kind === "plain" && entry.written.syntax === syntax) return {
85
+ key,
86
+ entry
87
+ };
88
+ }
89
+ /** The text an entry reads: a tag's body, a string's value, or the word a boolean is written as. */
90
+ function plainText(written) {
91
+ switch (written.kind) {
92
+ case "tag": return written.body;
93
+ case "string": return written.text;
94
+ case "boolean": return String(written.value);
95
+ case "number": return written.text;
96
+ }
97
+ }
98
+ function messageOf(error) {
99
+ return error instanceof Error ? error.message : String(error);
100
+ }
101
+ function isJsonRefusal(error) {
102
+ return isStructuredError(error) && error.code === INVALID_JSON_CODE;
103
+ }
104
+ /** Read one written value through the entry for its syntax. */
105
+ function readValue(support, written, elementIndex) {
106
+ const refuse = (refusal) => ({
107
+ ok: false,
108
+ refusal: blindCast({
109
+ ...refusal,
110
+ elementIndex
111
+ })
112
+ });
113
+ const found = written.kind === "tag" ? entryForTag(support, written.tag) : entryForPlain(support, written.kind);
114
+ if (found === void 0) return written.kind === "tag" ? refuse({
115
+ kind: "unknown-tag",
116
+ tag: written.tag,
117
+ known: knownTags(support)
118
+ }) : refuse({
119
+ kind: "unwritable",
120
+ syntax: written.kind
121
+ });
122
+ const form = found.entry.written;
123
+ if (form.kind === "plain" && form.syntax === "number") {
124
+ const text = plainText(written);
125
+ const classified = form.classify(text);
126
+ if (classified === void 0) return refuse({
127
+ kind: "unreadable",
128
+ json: false,
129
+ message: `no data type of this target holds the number ${text}`
130
+ });
131
+ return {
132
+ ok: true,
133
+ typed: classified
134
+ };
135
+ }
136
+ const text = plainText(written);
137
+ try {
138
+ return {
139
+ ok: true,
140
+ typed: {
141
+ type: blindCast(found.key),
142
+ value: form.parse(text)
143
+ }
144
+ };
145
+ } catch (error) {
146
+ return refuse({
147
+ kind: "unreadable",
148
+ json: isJsonRefusal(error),
149
+ message: messageOf(error)
150
+ });
151
+ }
152
+ }
153
+ /** Convert a value of one data type into the form another stores, when that type takes it. */
154
+ function castInto(support, columnType, typed, elementIndex) {
155
+ if (typed.type === columnType) return {
156
+ ok: true,
157
+ value: typed.value
158
+ };
159
+ const declaration = support.lookup.get(columnType);
160
+ const cast = declaration?.casts[typed.type];
161
+ if (cast === void 0) return {
162
+ ok: false,
163
+ refusal: {
164
+ kind: "no-cast",
165
+ columnType,
166
+ valueType: typed.type,
167
+ casts: Object.keys(declaration?.casts ?? {}),
168
+ elementIndex
169
+ }
170
+ };
171
+ try {
172
+ return {
173
+ ok: true,
174
+ value: cast(typed.value)
175
+ };
176
+ } catch (error) {
177
+ return {
178
+ ok: false,
179
+ refusal: {
180
+ kind: "unreadable",
181
+ json: isJsonRefusal(error),
182
+ message: messageOf(error),
183
+ elementIndex
184
+ }
185
+ };
186
+ }
187
+ }
188
+ /** The column's `typeParams` as the codec reference carries them, so `vector(3)` checks its length. */
189
+ function codecRefTypeParams(typeParams) {
190
+ return typeParams === void 0 ? void 0 : blindCast(typeParams);
191
+ }
192
+ /**
193
+ * Read one `@default(...)` value for a column, refusing in parts so each contract source words its
194
+ * own diagnostic. `isList` selects the check: a list column's elements are each read and cast
195
+ * against the element codec's data type, while a scalar column takes a written list only through
196
+ * its type's list cast — which is how `pgvector.Vector(3) @default([0.1, 0.2])` is read.
197
+ */
198
+ function readDataTypeDefault(input) {
199
+ const descriptorFor = input.codecLookup?.descriptorFor;
200
+ if (descriptorFor === void 0) throw new InternalError(`Field "${input.fieldPath}": the codec lookup resolving column codecs exposes no descriptorFor, but the column was resolved from a codec descriptor.`);
201
+ const descriptor = descriptorFor(input.column.codecId);
202
+ if (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.`);
203
+ const columnType = descriptor.dataType;
204
+ const codec = materializeCodec(descriptor, {
205
+ codecId: input.column.codecId,
206
+ ...ifDefined("typeParams", codecRefTypeParams(input.column.typeParams))
207
+ }, { name: input.fieldPath });
208
+ const validate = (value, elementIndex) => {
209
+ try {
210
+ codec.decodeJson(value);
211
+ return {
212
+ ok: true,
213
+ value
214
+ };
215
+ } catch (error) {
216
+ return {
217
+ ok: false,
218
+ refusal: {
219
+ kind: "undecodable",
220
+ codecId: input.column.codecId,
221
+ message: messageOf(error),
222
+ elementIndex
223
+ }
224
+ };
225
+ }
226
+ };
227
+ const readOne = (written, elementIndex) => {
228
+ const read = readValue(input.support, written, elementIndex);
229
+ if (!read.ok) return read;
230
+ const cast = castInto(input.support, columnType, read.typed, elementIndex);
231
+ if (!cast.ok) return cast;
232
+ return validate(cast.value, elementIndex);
233
+ };
234
+ if (input.written.kind !== "list") {
235
+ if (input.isList) return {
236
+ ok: false,
237
+ refusal: {
238
+ kind: "not-a-list",
239
+ elementIndex: void 0
240
+ }
241
+ };
242
+ return readOne(input.written, void 0);
243
+ }
244
+ if (input.isList) {
245
+ const elements = [];
246
+ for (const [elementIndex, written] of input.written.elements.entries()) {
247
+ if (written.kind === "list") return {
248
+ ok: false,
249
+ refusal: {
250
+ kind: "unreadable",
251
+ json: false,
252
+ message: "a list holds values, not other lists",
253
+ elementIndex
254
+ }
255
+ };
256
+ const element = readOne(written, elementIndex);
257
+ if (!element.ok) return element;
258
+ elements.push(element.value);
259
+ }
260
+ return {
261
+ ok: true,
262
+ value: elements
263
+ };
264
+ }
265
+ return readListIntoScalar({
266
+ ...input,
267
+ written: input.written,
268
+ columnType,
269
+ validate
270
+ });
271
+ }
272
+ /** A written list on a column that is not a list: the column's type takes it through its list cast. */
273
+ function readListIntoScalar(input) {
274
+ const listCast = input.support.lookup.get(input.columnType)?.listCast;
275
+ if (listCast === void 0) return {
276
+ ok: false,
277
+ refusal: {
278
+ kind: "no-cast",
279
+ columnType: input.columnType,
280
+ valueType: "a list",
281
+ casts: Object.keys(input.support.lookup.get(input.columnType)?.casts ?? {}),
282
+ elementIndex: void 0
283
+ }
284
+ };
285
+ const elements = [];
286
+ for (const [elementIndex, written] of input.written.elements.entries()) {
287
+ if (written.kind === "list") return {
288
+ ok: false,
289
+ refusal: {
290
+ kind: "unreadable",
291
+ json: false,
292
+ message: "a list holds values, not other lists",
293
+ elementIndex
294
+ }
295
+ };
296
+ const read = readValue(input.support, written, elementIndex);
297
+ if (!read.ok) return read;
298
+ if (!listCast.of.includes(read.typed.type)) return {
299
+ ok: false,
300
+ refusal: {
301
+ kind: "no-cast",
302
+ columnType: input.columnType,
303
+ valueType: read.typed.type,
304
+ casts: [...listCast.of],
305
+ elementIndex
306
+ }
307
+ };
308
+ elements.push(read.typed.value);
309
+ }
310
+ try {
311
+ return input.validate(listCast.cast(elements), void 0);
312
+ } catch (error) {
313
+ return {
314
+ ok: false,
315
+ refusal: {
316
+ kind: "unreadable",
317
+ json: isJsonRefusal(error),
318
+ message: messageOf(error),
319
+ elementIndex: void 0
320
+ }
321
+ };
322
+ }
323
+ }
324
+ /** Where in a written list a diagnostic is about, for a message: ` at element 2`. */
325
+ function at(elementIndex) {
326
+ return elementIndex === void 0 ? "" : ` at element ${elementIndex + 1}`;
327
+ }
328
+ /** {@link readDataTypeDefault} worded as a PSL diagnostic's code and message. */
329
+ function lowerDataTypeDefault(input) {
330
+ const read = readDataTypeDefault(input);
331
+ if (read.ok) return read;
332
+ const { refusal } = read;
333
+ const where = `Field "${input.fieldPath}"${at(refusal.elementIndex)}`;
334
+ switch (refusal.kind) {
335
+ case "unreadable": return {
336
+ ok: false,
337
+ code: refusal.json ? PSL_INVALID_JSON_LITERAL : PSL_INVALID_DEFAULT_LITERAL,
338
+ message: `${where}: ${refusal.message}`
339
+ };
340
+ case "unknown-tag": return {
341
+ ok: false,
342
+ code: "PSL_UNKNOWN_DEFAULT_LITERAL_TAG",
343
+ message: `Unknown literal tag "${refusal.tag}". Known tags: ${refusal.known.join(", ")}.`
344
+ };
345
+ case "unwritable": return {
346
+ ok: false,
347
+ code: PSL_DEFAULT_TYPE_INCOMPATIBLE,
348
+ message: `${where}: this target has no data type for a ${refusal.syntax} value`
349
+ };
350
+ case "not-a-list": return {
351
+ ok: false,
352
+ code: PSL_DEFAULT_TYPE_INCOMPATIBLE,
353
+ message: `${where}: this column holds a list, so its default is a list literal, as in [1, 2]`
354
+ };
355
+ case "no-cast": return {
356
+ ok: false,
357
+ code: PSL_DEFAULT_TYPE_INCOMPATIBLE,
358
+ message: `${where}: ${refusal.columnType} has no cast from ${refusal.valueType}; ${describeCasts(refusal.casts)}`
359
+ };
360
+ case "undecodable": return {
361
+ ok: false,
362
+ code: PSL_INVALID_DEFAULT_LITERAL,
363
+ message: `${where}: ${refusal.message}`
364
+ };
365
+ }
366
+ }
367
+ function describeCasts(casts) {
368
+ return casts.length === 0 ? "it casts from nothing" : `it casts from ${casts.join(", ")}`;
369
+ }
59
370
  function formatSupportedFunctionList(registry) {
60
371
  const signatures = Array.from(registry.entries()).sort(([a], [b]) => a.localeCompare(b)).flatMap(([functionName, entry]) => {
61
372
  const usageSignatures = entry.usageSignatures?.filter((signature) => signature.length > 0);
@@ -86,44 +397,6 @@ function lowerDefaultFunctionWithRegistry(input) {
86
397
  }
87
398
  };
88
399
  }
89
- /**
90
- * The default value a number literal gives a column whose codec holds numbers. Returns `undefined`
91
- * when the codec does not hold numbers, or reads the literal neither as a JSON number nor as
92
- * decimal text.
93
- */
94
- function numberLiteralDefault(text, codecId, codecLookup) {
95
- const codec = numberHoldingCodec(codecLookup, codecId);
96
- if (codec === void 0) return void 0;
97
- const number = Number(text);
98
- if (tryDecodeJson(codec, number) !== void 0) return number;
99
- const decoded = tryDecodeJson(codec, canonicalDecimalText(text));
100
- return decoded !== void 0 && isNumberValue(decoded.value) ? decoded.value : void 0;
101
- }
102
- function numberHoldingCodec(codecLookup, codecId) {
103
- return codecLookup?.descriptorFor?.(codecId)?.traits.includes("numeric") === true ? codecLookup?.get(codecId) : void 0;
104
- }
105
- const DECIMAL_NUMERAL = /^(-?)0*(\d+)(\.\d+)?$/;
106
- /**
107
- * Leading zeros and the sign of zero never change a decimal. Trailing zeros are kept, because a
108
- * column without a scale keeps them.
109
- */
110
- function canonicalDecimalText(text) {
111
- const numeral = DECIMAL_NUMERAL.exec(text);
112
- if (numeral === null) return text;
113
- const [, sign = "", whole = "", fraction = ""] = numeral;
114
- const digits = `${whole}${fraction}`;
115
- return /^[0.]+$/.test(digits) ? digits : `${sign}${digits}`;
116
- }
117
- function isNumberValue(value) {
118
- return typeof value === "string" || typeof value === "number" || typeof value === "bigint";
119
- }
120
- function tryDecodeJson(codec, json) {
121
- try {
122
- return { value: codec.decodeJson(json) };
123
- } catch {
124
- return;
125
- }
126
- }
127
400
  const INVALID_AUTHORING_ARGUMENT = Symbol("invalidAuthoringArgument");
128
401
  function isIdentifierStartCharacter(character) {
129
402
  return character !== void 0 && /[A-Za-z_$]/.test(character);
@@ -797,7 +1070,7 @@ const TAGGED_LITERAL_CANONICALIZATION_CODES = {
797
1070
  nul: "PSL_TAGGED_LITERAL_NUL",
798
1071
  "too-large": "PSL_TAGGED_LITERAL_TOO_LARGE"
799
1072
  };
800
- function lowerTaggedLiteral(literal, registry, context, source) {
1073
+ function lowerTaggedLiteral(literal, support, context, source) {
801
1074
  const reject = (code, message) => ({
802
1075
  ok: false,
803
1076
  kind: "owned",
@@ -807,10 +1080,18 @@ function lowerTaggedLiteral(literal, registry, context, source) {
807
1080
  ...source.at(literal.span)
808
1081
  }
809
1082
  });
810
- const entry = registry.get(literal.tag);
811
- if (entry === void 0) return reject("PSL_UNKNOWN_DEFAULT_LITERAL_TAG", `Unknown literal tag "${literal.tag}". Known tags: ${[...registry.keys()].join(", ")}.`);
1083
+ const entry = support.entries[loweringEntryKey(literal.tag)] ?? entryForTag(support, literal.tag)?.entry;
1084
+ if (entry === void 0) return reject("PSL_UNKNOWN_DEFAULT_LITERAL_TAG", `Unknown literal tag "${literal.tag}". Known tags: ${knownTags(support).join(", ")}.`);
812
1085
  const { canonicalization } = literal;
813
1086
  if (!canonicalization.ok) return reject(TAGGED_LITERAL_CANONICALIZATION_CODES[canonicalization.reason], describeTaggedLiteralFailure(canonicalization.reason));
1087
+ if (!isDataTypeLoweringEntry(entry)) return {
1088
+ ok: true,
1089
+ written: {
1090
+ kind: "tag",
1091
+ tag: literal.tag,
1092
+ body: canonicalization.body
1093
+ }
1094
+ };
814
1095
  const result = entry.lower({
815
1096
  literal: {
816
1097
  tag: literal.tag,
@@ -828,17 +1109,19 @@ function lowerDefaultForField(input) {
828
1109
  const node = findFieldAttributeNode(input.field, "default");
829
1110
  if (node === void 0) return {};
830
1111
  const source = diagnosticSource(input.sources, node.syntax);
1112
+ const spec = sqlAttributeSpecs.field.default(fieldSpecContext({
1113
+ symbols: input.symbolTable,
1114
+ model: input.model,
1115
+ field: input.field,
1116
+ controlMutationDefaults: {
1117
+ defaultFunctionRegistry: input.defaultFunctionRegistry,
1118
+ dataTypeEntries: input.dataTypeSupport.entries
1119
+ }
1120
+ }));
831
1121
  const interpreted = interpretFieldAttribute({
1122
+ symbols: input.symbolTable,
832
1123
  node,
833
- spec: sqlAttributeSpecs.field.default(fieldSpecContext({
834
- symbols: input.symbolTable,
835
- model: input.model,
836
- field: input.field,
837
- controlMutationDefaults: {
838
- defaultFunctionRegistry: input.defaultFunctionRegistry,
839
- defaultLiteralTagRegistry: input.defaultLiteralTagRegistry
840
- }
841
- })),
1124
+ spec,
842
1125
  model: input.model,
843
1126
  field: input.field,
844
1127
  sources: input.sources,
@@ -846,65 +1129,140 @@ function lowerDefaultForField(input) {
846
1129
  });
847
1130
  if (interpreted === void 0) return {};
848
1131
  const value = interpreted.value;
849
- const literalValue = (literal) => typeof literal === "object" ? numberLiteralDefault(literal.text, input.columnDescriptor.codecId, input.codecLookup) ?? Number(literal.text) : literal;
850
- if (Array.isArray(value)) return { defaultValue: {
851
- kind: "literal",
852
- value: value.map(literalValue)
853
- } };
854
- if (typeof value === "object" && "text" in value) return { defaultValue: {
855
- kind: "literal",
856
- value: literalValue(value)
857
- } };
858
- if (typeof value === "object") {
859
- const context = {
860
- sourceId: input.sources.sourceFileFor(node.syntax).filename,
861
- modelName: input.modelName,
862
- fieldName: input.fieldName,
863
- columnCodecId: input.columnDescriptor.codecId
864
- };
865
- const lowered = "tag" in value ? lowerTaggedLiteral(value, input.defaultLiteralTagRegistry, context, source) : lowerDefaultFunctionWithRegistry({
866
- call: value,
867
- registry: input.defaultFunctionRegistry,
868
- context,
869
- source
1132
+ const context = {
1133
+ sourceId: input.sources.sourceFileFor(node.syntax).filename,
1134
+ modelName: input.modelName,
1135
+ fieldName: input.fieldName,
1136
+ columnCodecId: input.columnDescriptor.codecId
1137
+ };
1138
+ const readAsLiteral = (written) => {
1139
+ const lowered = lowerDataTypeDefault({
1140
+ written,
1141
+ isList: input.field.list,
1142
+ column: input.columnDescriptor,
1143
+ codecLookup: input.codecLookup,
1144
+ support: input.dataTypeSupport,
1145
+ fieldPath: `${input.modelName}.${input.fieldName}`
870
1146
  });
871
1147
  if (!lowered.ok) {
872
- if (lowered.kind === "owned") input.diagnostics.push(lowered.diagnostic);
873
- else input.diagnostics.pushExternal(lowered.diagnostic);
874
- return {};
875
- }
876
- if (lowered.value.kind === "storage") return { defaultValue: lowered.value.defaultValue };
877
- const generatorDescriptor = input.generatorDescriptorById.get(lowered.value.generated.id);
878
- if (!generatorDescriptor) {
879
1148
  input.diagnostics.push({
880
- code: "PSL_INVALID_DEFAULT_APPLICABILITY",
881
- message: `Default generator "${lowered.value.generated.id}" is not available in the composed mutation default registry.`,
882
- ...source.at(value.span)
1149
+ code: lowered.code,
1150
+ message: lowered.message,
1151
+ ...source.at()
883
1152
  });
884
1153
  return {};
885
1154
  }
886
- if (generatorDescriptor.applicableCodecIds === void 0) {
887
- input.diagnostics.push({
888
- code: "PSL_INVALID_DEFAULT_APPLICABILITY",
889
- message: `Default generator "${generatorDescriptor.id}" is not applicable to "@default(...)" lowering. Use the corresponding field preset (e.g. \`temporal.${generatorDescriptor.id === "timestampNow" ? "updatedAt" : generatorDescriptor.id}()\`) instead.`,
890
- ...source.at(value.span)
891
- });
892
- return {};
1155
+ return { defaultValue: {
1156
+ kind: "literal",
1157
+ value: lowered.value,
1158
+ canonical: true
1159
+ } };
1160
+ };
1161
+ const writtenElement = (element) => {
1162
+ if (typeof element === "string") return {
1163
+ kind: "string",
1164
+ text: element
1165
+ };
1166
+ if (typeof element === "boolean") return {
1167
+ kind: "boolean",
1168
+ value: element
1169
+ };
1170
+ if ("text" in element) return {
1171
+ kind: "number",
1172
+ text: element.text
1173
+ };
1174
+ const lowered = lowerTaggedLiteral(element, input.dataTypeSupport, context, source);
1175
+ if (!lowered.ok) {
1176
+ if (lowered.kind === "owned") input.diagnostics.push(lowered.diagnostic);
1177
+ else input.diagnostics.pushExternal(lowered.diagnostic);
1178
+ return { ok: false };
893
1179
  }
894
- if (!generatorDescriptor.applicableCodecIds.includes(input.columnDescriptor.codecId)) {
1180
+ if (!("written" in lowered)) {
895
1181
  input.diagnostics.push({
896
- code: "PSL_INVALID_DEFAULT_APPLICABILITY",
897
- message: `Default generator "${generatorDescriptor.id}" is not applicable to "${input.modelName}.${input.fieldName}" with codecId "${input.columnDescriptor.codecId}".`,
898
- ...source.at(value.span)
1182
+ code: PSL_INVALID_DEFAULT_LITERAL,
1183
+ message: `Literal tag "${element.tag}" produces a default of its own and cannot be an element of a list literal.`,
1184
+ ...source.at(element.span)
899
1185
  });
900
- return {};
1186
+ return { ok: false };
901
1187
  }
902
- return { executionDefaults: { onCreate: lowered.value.generated } };
1188
+ return lowered.written;
1189
+ };
1190
+ if (input.columnDescriptor.valueSet !== void 0) {
1191
+ if (typeof value === "string") return { defaultValue: {
1192
+ kind: "literal",
1193
+ value
1194
+ } };
1195
+ if (Array.isArray(value)) {
1196
+ const members = value.filter((element) => typeof element === "string");
1197
+ if (members.length === value.length) return { defaultValue: {
1198
+ kind: "literal",
1199
+ value: members
1200
+ } };
1201
+ }
1202
+ }
1203
+ if (Array.isArray(value)) {
1204
+ const elements = [];
1205
+ for (const element of value) {
1206
+ const written = writtenElement(element);
1207
+ if ("ok" in written) return {};
1208
+ elements.push(written);
1209
+ }
1210
+ return readAsLiteral({
1211
+ kind: "list",
1212
+ elements
1213
+ });
903
1214
  }
904
- return { defaultValue: {
905
- kind: "literal",
1215
+ if (typeof value === "string") return readAsLiteral({
1216
+ kind: "string",
1217
+ text: value
1218
+ });
1219
+ if (typeof value === "boolean") return readAsLiteral({
1220
+ kind: "boolean",
906
1221
  value
907
- } };
1222
+ });
1223
+ if ("text" in value) return readAsLiteral({
1224
+ kind: "number",
1225
+ text: value.text
1226
+ });
1227
+ const lowered = "tag" in value ? lowerTaggedLiteral(value, input.dataTypeSupport, context, source) : lowerDefaultFunctionWithRegistry({
1228
+ call: value,
1229
+ registry: input.defaultFunctionRegistry,
1230
+ context,
1231
+ source
1232
+ });
1233
+ if (!lowered.ok) {
1234
+ if (lowered.kind === "owned") input.diagnostics.push(lowered.diagnostic);
1235
+ else input.diagnostics.pushExternal(lowered.diagnostic);
1236
+ return {};
1237
+ }
1238
+ if ("written" in lowered) return readAsLiteral(lowered.written);
1239
+ if (lowered.value.kind === "storage") return { defaultValue: lowered.value.defaultValue };
1240
+ const generatorDescriptor = input.generatorDescriptorById.get(lowered.value.generated.id);
1241
+ if (!generatorDescriptor) {
1242
+ input.diagnostics.push({
1243
+ code: "PSL_INVALID_DEFAULT_APPLICABILITY",
1244
+ message: `Default generator "${lowered.value.generated.id}" is not available in the composed mutation default registry.`,
1245
+ ...source.at(value.span)
1246
+ });
1247
+ return {};
1248
+ }
1249
+ if (generatorDescriptor.applicableCodecIds === void 0) {
1250
+ input.diagnostics.push({
1251
+ code: "PSL_INVALID_DEFAULT_APPLICABILITY",
1252
+ message: `Default generator "${generatorDescriptor.id}" is not applicable to "@default(...)" lowering. Use the corresponding field preset (e.g. \`temporal.${generatorDescriptor.id === "timestampNow" ? "updatedAt" : generatorDescriptor.id}()\`) instead.`,
1253
+ ...source.at(value.span)
1254
+ });
1255
+ return {};
1256
+ }
1257
+ if (!generatorDescriptor.applicableCodecIds.includes(input.columnDescriptor.codecId)) {
1258
+ input.diagnostics.push({
1259
+ code: "PSL_INVALID_DEFAULT_APPLICABILITY",
1260
+ message: `Default generator "${generatorDescriptor.id}" is not applicable to "${input.modelName}.${input.fieldName}" with codecId "${input.columnDescriptor.codecId}".`,
1261
+ ...source.at(value.span)
1262
+ });
1263
+ return {};
1264
+ }
1265
+ return { executionDefaults: { onCreate: lowered.value.generated } };
908
1266
  }
909
1267
  function resolveColumnDescriptor(field, enumTypeDescriptors, namedTypeDescriptors, scalarColumnDescriptors) {
910
1268
  if (namedTypeDescriptors.has(field.typeName)) return namedTypeDescriptors.get(field.typeName);
@@ -924,9 +1282,10 @@ function lowerEnumDefaultForField(input) {
924
1282
  field,
925
1283
  controlMutationDefaults: {
926
1284
  defaultFunctionRegistry: input.defaultFunctionRegistry,
927
- defaultLiteralTagRegistry: input.defaultLiteralTagRegistry
1285
+ dataTypeEntries: input.dataTypeSupport.entries
928
1286
  }
929
1287
  })),
1288
+ symbols: input.symbolTable,
930
1289
  model,
931
1290
  field,
932
1291
  sources: input.sources,
@@ -996,6 +1355,7 @@ function extractFieldConstraintNames(input) {
996
1355
  const idNode = findFieldAttributeNode(input.field, "id");
997
1356
  const idName = idNode === void 0 ? void 0 : interpretFieldAttribute({
998
1357
  node: idNode,
1358
+ symbols: input.symbolTable,
999
1359
  spec: sqlAttributeSpecs.field.id(),
1000
1360
  model: input.model,
1001
1361
  field: input.field,
@@ -1009,6 +1369,7 @@ function extractFieldConstraintNames(input) {
1009
1369
  idName,
1010
1370
  uniqueName: uniqueNode === void 0 ? void 0 : interpretFieldAttribute({
1011
1371
  node: uniqueNode,
1372
+ symbols: input.symbolTable,
1012
1373
  spec: sqlAttributeSpecs.field.unique(),
1013
1374
  model: input.model,
1014
1375
  field: input.field,
@@ -1030,6 +1391,7 @@ function lowerNoCheckForField(input) {
1030
1391
  const interpreted = interpretFieldAttribute({
1031
1392
  node,
1032
1393
  spec: sqlAttributeSpecs.field.noCheck(),
1394
+ symbols: input.symbolTable,
1033
1395
  model: input.model,
1034
1396
  field: input.field,
1035
1397
  sources: input.sources,
@@ -1065,7 +1427,7 @@ function lowerNoCheckForField(input) {
1065
1427
  return [...authored].sort();
1066
1428
  }
1067
1429
  function collectResolvedFields(input) {
1068
- const { model, symbolTable, mapping, enumTypeDescriptors, namedTypeDescriptors, modelNames, compositeTypeNames, composedExtensions, authoringContributions, familyId, targetId, defaultFunctionRegistry, defaultLiteralTagRegistry, generatorDescriptorById, diagnostics, sources, scalarColumnDescriptors, enumHandles, capabilities, namespaceId, namespaceExtensionEntities, codecLookup } = input;
1430
+ const { model, symbolTable, mapping, enumTypeDescriptors, namedTypeDescriptors, modelNames, compositeTypeNames, composedExtensions, authoringContributions, familyId, targetId, defaultFunctionRegistry, dataTypeSupport, generatorDescriptorById, diagnostics, sources, scalarColumnDescriptors, enumHandles, capabilities, namespaceId, namespaceExtensionEntities, codecLookup } = input;
1069
1431
  const resolvedFields = [];
1070
1432
  const valueObjectStorageTypeName = authoringContributions?.valueObjectStorageType;
1071
1433
  const declaredControlPolicy = getAttribute(model.attributes, "control")?.args.find((arg) => arg.kind === "positional")?.value.trim();
@@ -1179,7 +1541,7 @@ function collectResolvedFields(input) {
1179
1541
  sources: input.sources,
1180
1542
  enumHandle,
1181
1543
  defaultFunctionRegistry,
1182
- defaultLiteralTagRegistry,
1544
+ dataTypeSupport,
1183
1545
  diagnostics
1184
1546
  }) : lowerDefaultForField({
1185
1547
  modelName: model.name,
@@ -1191,7 +1553,7 @@ function collectResolvedFields(input) {
1191
1553
  columnDescriptor: descriptor,
1192
1554
  generatorDescriptorById,
1193
1555
  defaultFunctionRegistry,
1194
- defaultLiteralTagRegistry,
1556
+ dataTypeSupport,
1195
1557
  codecLookup,
1196
1558
  diagnostics
1197
1559
  }) : {};
@@ -1224,6 +1586,7 @@ function collectResolvedFields(input) {
1224
1586
  }
1225
1587
  const mappedColumnName = mapping.fieldColumns.get(field.name) ?? field.name;
1226
1588
  const { idAttribute, uniqueAttribute, idName, uniqueName } = extractFieldConstraintNames({
1589
+ symbolTable: input.symbolTable,
1227
1590
  model,
1228
1591
  field,
1229
1592
  sources: input.sources,
@@ -1257,6 +1620,7 @@ function collectResolvedFields(input) {
1257
1620
  const fieldExecutionDefaults = presetContributions?.executionDefaults ?? loweredDefault.executionDefaults;
1258
1621
  const fieldDefaultValue = presetContributions?.default ?? loweredDefault.defaultValue;
1259
1622
  const noCheckKinds = modelDerivesChecks ? lowerNoCheckForField({
1623
+ symbolTable: input.symbolTable,
1260
1624
  model,
1261
1625
  field,
1262
1626
  sources: input.sources,
@@ -1283,12 +1647,13 @@ function collectResolvedFields(input) {
1283
1647
  }
1284
1648
  return resolvedFields;
1285
1649
  }
1286
- function buildModelMappings(modelEntries, defaultNamespaceId, diagnostics, sources) {
1650
+ function buildModelMappings(symbols, modelEntries, defaultNamespaceId, diagnostics, sources) {
1287
1651
  const result = /* @__PURE__ */ new Map();
1288
1652
  for (const { model, namespaceId } of modelEntries) {
1289
1653
  const mapNode = findModelAttributeNode(model, "map");
1290
1654
  const tableName = mapNode === void 0 ? defaultTableName(model.name) : interpretModelAttribute({
1291
1655
  node: mapNode,
1656
+ symbols,
1292
1657
  spec: sqlAttributeSpecs.model.map(),
1293
1658
  model,
1294
1659
  sources,
@@ -1299,6 +1664,7 @@ function buildModelMappings(modelEntries, defaultNamespaceId, diagnostics, sourc
1299
1664
  const fieldMapNode = findFieldAttributeNode(field, "map");
1300
1665
  const columnName = fieldMapNode === void 0 ? field.name : interpretFieldAttribute({
1301
1666
  node: fieldMapNode,
1667
+ symbols,
1302
1668
  spec: sqlAttributeSpecs.field.map(),
1303
1669
  model,
1304
1670
  field,
@@ -1474,6 +1840,7 @@ function interpretRelationAttribute(input) {
1474
1840
  const node = findFieldAttributeNode(input.field, "relation");
1475
1841
  if (node === void 0) return void 0;
1476
1842
  return interpretFieldAttribute({
1843
+ symbols: input.symbols,
1477
1844
  node,
1478
1845
  spec: sqlAttributeSpecs.field.relation(),
1479
1846
  model: input.selfModel,
@@ -2150,7 +2517,7 @@ function buildModelNodeFromPsl(input) {
2150
2517
  familyId: input.familyId,
2151
2518
  targetId: input.targetId,
2152
2519
  defaultFunctionRegistry: input.defaultFunctionRegistry,
2153
- defaultLiteralTagRegistry: input.defaultLiteralTagRegistry,
2520
+ dataTypeSupport: input.dataTypeSupport,
2154
2521
  generatorDescriptorById: input.generatorDescriptorById,
2155
2522
  diagnostics,
2156
2523
  sources: input.sources,
@@ -2286,6 +2653,7 @@ function buildModelNodeFromPsl(input) {
2286
2653
  node,
2287
2654
  spec: sqlAttributeSpecs.model.control(),
2288
2655
  model,
2656
+ symbols: input.symbolTable,
2289
2657
  sources: input.sources,
2290
2658
  diagnostics
2291
2659
  });
@@ -2317,6 +2685,7 @@ function buildModelNodeFromPsl(input) {
2317
2685
  node,
2318
2686
  spec: sqlAttributeSpecs.model.id(),
2319
2687
  model,
2688
+ symbols: input.symbolTable,
2320
2689
  sources: input.sources,
2321
2690
  diagnostics
2322
2691
  });
@@ -2355,6 +2724,7 @@ function buildModelNodeFromPsl(input) {
2355
2724
  node,
2356
2725
  spec: sqlAttributeSpecs.model.unique(),
2357
2726
  model,
2727
+ symbols: input.symbolTable,
2358
2728
  sources: input.sources,
2359
2729
  diagnostics
2360
2730
  });
@@ -2382,6 +2752,7 @@ function buildModelNodeFromPsl(input) {
2382
2752
  node,
2383
2753
  spec: sqlAttributeSpecs.model.index(),
2384
2754
  model,
2755
+ symbols: input.symbolTable,
2385
2756
  sources: input.sources,
2386
2757
  diagnostics
2387
2758
  });
@@ -2427,6 +2798,7 @@ function buildModelNodeFromPsl(input) {
2427
2798
  node,
2428
2799
  spec: sqlAttributeSpecs.model.check(),
2429
2800
  model,
2801
+ symbols: input.symbolTable,
2430
2802
  sources: input.sources,
2431
2803
  diagnostics
2432
2804
  });
@@ -2459,10 +2831,11 @@ function buildModelNodeFromPsl(input) {
2459
2831
  model,
2460
2832
  controlMutationDefaults: {
2461
2833
  defaultFunctionRegistry: input.defaultFunctionRegistry,
2462
- defaultLiteralTagRegistry: input.defaultLiteralTagRegistry
2834
+ dataTypeEntries: input.dataTypeSupport.entries
2463
2835
  }
2464
2836
  }),
2465
2837
  model,
2838
+ symbols: input.symbolTable,
2466
2839
  sources: input.sources,
2467
2840
  diagnostics
2468
2841
  });
@@ -2852,15 +3225,16 @@ function patchModelDomainFields(models, modelResolvedFields) {
2852
3225
  }
2853
3226
  return patched;
2854
3227
  }
2855
- function collectPolymorphismDeclarations(models, sources, diagnostics) {
3228
+ function collectPolymorphismDeclarations(identities, symbols, sources, diagnostics) {
2856
3229
  const discriminatorDeclarations = /* @__PURE__ */ new Map();
2857
3230
  const baseDeclarations = /* @__PURE__ */ new Map();
2858
- for (const model of models) {
3231
+ for (const { model, key } of identities.values()) {
2859
3232
  const source = diagnosticSource(sources, model.node.syntax);
2860
3233
  const discriminatorNode = findModelAttributeNode(model, "discriminator");
2861
3234
  if (discriminatorNode !== void 0) {
2862
3235
  const parsed = interpretModelAttribute({
2863
3236
  node: discriminatorNode,
3237
+ symbols,
2864
3238
  spec: sqlAttributeSpecs.model.discriminator(),
2865
3239
  model,
2866
3240
  sources,
@@ -2874,7 +3248,7 @@ function collectPolymorphismDeclarations(models, sources, diagnostics) {
2874
3248
  message: `Discriminator field "${parsed.field}" on model "${model.name}" must be of type String, but is "${discField.typeName}"`,
2875
3249
  ...source.at(span)
2876
3250
  });
2877
- else discriminatorDeclarations.set(model.name, {
3251
+ else discriminatorDeclarations.set(key, {
2878
3252
  fieldName: parsed.field,
2879
3253
  span,
2880
3254
  source
@@ -2885,17 +3259,22 @@ function collectPolymorphismDeclarations(models, sources, diagnostics) {
2885
3259
  if (baseNode !== void 0) {
2886
3260
  const parsed = interpretModelAttribute({
2887
3261
  node: baseNode,
3262
+ symbols,
2888
3263
  spec: sqlAttributeSpecs.model.base(),
2889
3264
  model,
2890
3265
  sources,
2891
3266
  diagnostics
2892
3267
  });
2893
- if (parsed !== void 0) baseDeclarations.set(model.name, {
2894
- source,
2895
- baseName: parsed.base,
2896
- value: parsed.value,
2897
- span: nodePslSpan(baseNode.syntax, sources)
2898
- });
3268
+ if (parsed !== void 0) {
3269
+ const base = identities.get(parsed.base.declaration);
3270
+ invariant(base !== void 0, `Resolved base model "${parsed.base.declaration.name}" is missing from the collected model identities`);
3271
+ baseDeclarations.set(key, {
3272
+ source,
3273
+ base,
3274
+ value: parsed.value,
3275
+ span: nodePslSpan(baseNode.syntax, sources)
3276
+ });
3277
+ }
2899
3278
  }
2900
3279
  }
2901
3280
  return {
@@ -2903,11 +3282,9 @@ function collectPolymorphismDeclarations(models, sources, diagnostics) {
2903
3282
  baseDeclarations
2904
3283
  };
2905
3284
  }
2906
- function resolvePolymorphism(models, discriminatorDeclarations, baseDeclarations, modelNames, modelMappings, modelNamespaceIds, defaultNamespaceId, syntheticPkFieldsByVariant, stiBaseFieldsByBase, diagnostics) {
3285
+ function resolvePolymorphism(models, discriminatorDeclarations, baseDeclarations, modelMappings, syntheticPkFieldsByVariant, stiBaseFieldsByBase, diagnostics) {
2907
3286
  let patched = models;
2908
- const coordinateFor = (modelName) => modelCoordinateKey(modelNamespaceIds.get(modelName) ?? defaultNamespaceId, modelName);
2909
- for (const [baseName, fieldNames] of stiBaseFieldsByBase) {
2910
- const baseKey = coordinateFor(baseName);
3287
+ for (const [baseKey, fieldNames] of stiBaseFieldsByBase) {
2911
3288
  const baseModel = patched[baseKey];
2912
3289
  if (!baseModel || fieldNames.length === 0) continue;
2913
3290
  patched = {
@@ -2915,8 +3292,9 @@ function resolvePolymorphism(models, discriminatorDeclarations, baseDeclarations
2915
3292
  [baseKey]: stripStorageOnlyDomainFields(baseModel, fieldNames)
2916
3293
  };
2917
3294
  }
2918
- for (const [modelName, decl] of discriminatorDeclarations) {
2919
- if (baseDeclarations.has(modelName)) {
3295
+ for (const [modelKey, decl] of discriminatorDeclarations) {
3296
+ const modelName = modelMappings.get(modelKey)?.model.name;
3297
+ if (baseDeclarations.has(modelKey)) {
2920
3298
  diagnostics.push({
2921
3299
  code: "PSL_DISCRIMINATOR_AND_BASE",
2922
3300
  message: `Model "${modelName}" cannot have both @@discriminator and @@base`,
@@ -2924,12 +3302,14 @@ function resolvePolymorphism(models, discriminatorDeclarations, baseDeclarations
2924
3302
  });
2925
3303
  continue;
2926
3304
  }
2927
- const model = patched[coordinateFor(modelName)];
3305
+ const model = patched[modelKey];
2928
3306
  if (!model) continue;
2929
3307
  const variants = {};
2930
3308
  const seenValues = /* @__PURE__ */ new Map();
2931
- for (const [variantName, baseDecl] of baseDeclarations) {
2932
- if (baseDecl.baseName !== modelName) continue;
3309
+ for (const [variantKey, baseDecl] of baseDeclarations) {
3310
+ if (baseDecl.base.key !== modelKey) continue;
3311
+ const variantName = modelMappings.get(variantKey)?.model.name;
3312
+ invariant(variantName !== void 0, `Variant "${variantKey}" is missing from the model mappings`);
2933
3313
  const existingVariant = seenValues.get(baseDecl.value);
2934
3314
  if (existingVariant) {
2935
3315
  diagnostics.push({
@@ -2952,39 +3332,33 @@ function resolvePolymorphism(models, discriminatorDeclarations, baseDeclarations
2952
3332
  }
2953
3333
  patched = {
2954
3334
  ...patched,
2955
- [coordinateFor(modelName)]: {
3335
+ [modelKey]: {
2956
3336
  ...model,
2957
3337
  discriminator: { field: decl.fieldName },
2958
3338
  variants
2959
3339
  }
2960
3340
  };
2961
3341
  }
2962
- for (const [variantName, baseDecl] of baseDeclarations) {
2963
- if (!modelNames.has(baseDecl.baseName)) {
2964
- diagnostics.push({
2965
- code: "PSL_BASE_TARGET_NOT_FOUND",
2966
- message: `Model "${variantName}" @@base references non-existent model "${baseDecl.baseName}"`,
2967
- ...baseDecl.source.at(baseDecl.span)
2968
- });
2969
- continue;
2970
- }
2971
- if (!discriminatorDeclarations.has(baseDecl.baseName)) {
3342
+ for (const [variantKey, baseDecl] of baseDeclarations) {
3343
+ const variantMapping = modelMappings.get(variantKey);
3344
+ const variantName = variantMapping?.model.name;
3345
+ const baseName = baseDecl.base.model.name;
3346
+ if (!discriminatorDeclarations.has(baseDecl.base.key)) {
2972
3347
  diagnostics.push({
2973
3348
  code: "PSL_ORPHANED_BASE",
2974
- message: `Model "${variantName}" declares @@base(${baseDecl.baseName}, ...) but "${baseDecl.baseName}" has no @@discriminator`,
3349
+ message: `Model "${variantName}" declares @@base(${baseName}, ...) but "${baseName}" has no @@discriminator`,
2975
3350
  ...baseDecl.source.at(baseDecl.span)
2976
3351
  });
2977
3352
  continue;
2978
3353
  }
2979
- if (discriminatorDeclarations.has(variantName)) continue;
2980
- const variantModel = patched[coordinateFor(variantName)];
3354
+ if (discriminatorDeclarations.has(variantKey)) continue;
3355
+ const variantModel = patched[variantKey];
2981
3356
  if (!variantModel) continue;
2982
- const baseMapping = modelMappings.get(baseDecl.baseName);
2983
- const variantMapping = modelMappings.get(variantName);
3357
+ const baseMapping = modelMappings.get(baseDecl.base.key);
2984
3358
  const resolvedTable = variantMapping?.model.attributes.some((attr) => attr.name === "map") ?? false ? variantMapping?.tableName : baseMapping?.tableName;
2985
3359
  const patchedVariant = {
2986
3360
  ...variantModel,
2987
- base: crossRef(baseDecl.baseName, modelNamespaceIds.get(baseDecl.baseName) ?? defaultNamespaceId),
3361
+ base: crossRef(baseName, baseDecl.base.namespaceId),
2988
3362
  ...resolvedTable ? { storage: {
2989
3363
  ...variantModel.storage,
2990
3364
  table: resolvedTable
@@ -2992,7 +3366,7 @@ function resolvePolymorphism(models, discriminatorDeclarations, baseDeclarations
2992
3366
  };
2993
3367
  patched = {
2994
3368
  ...patched,
2995
- [coordinateFor(variantName)]: stripStorageOnlyDomainFields(patchedVariant, syntheticPkFieldsByVariant.get(variantName) ?? [])
3369
+ [variantKey]: stripStorageOnlyDomainFields(patchedVariant, syntheticPkFieldsByVariant.get(variantKey) ?? [])
2996
3370
  };
2997
3371
  }
2998
3372
  return patched;
@@ -3011,16 +3385,18 @@ function resolvePolymorphism(models, discriminatorDeclarations, baseDeclarations
3011
3385
  * storage table stays joinable. Single-table-inheritance variants (no own
3012
3386
  * table) are left untouched.
3013
3387
  */
3014
- function materializeMtiVariantStorageLinks(modelNodes, baseDeclarations, stiVariantNames) {
3015
- const nodeByModel = new Map(modelNodes.map((node) => [node.modelName, node]));
3388
+ function materializeMtiVariantStorageLinks(modelNodes, baseDeclarations, stiVariantKeys, defaultNamespaceId) {
3389
+ const keyOf = (node) => modelCoordinateKey(node.namespaceId ?? defaultNamespaceId, node.modelName);
3390
+ const nodeByModel = new Map(modelNodes.map((node) => [keyOf(node), node]));
3016
3391
  const syntheticPkFieldsByVariant = /* @__PURE__ */ new Map();
3017
3392
  return {
3018
3393
  modelNodes: modelNodes.map((node) => {
3019
- const baseDecl = baseDeclarations.get(node.modelName);
3394
+ const variantKey = keyOf(node);
3395
+ const baseDecl = baseDeclarations.get(variantKey);
3020
3396
  if (!baseDecl) return node;
3021
- const baseNode = nodeByModel.get(baseDecl.baseName);
3397
+ const baseNode = nodeByModel.get(baseDecl.base.key);
3022
3398
  if (!baseNode) return node;
3023
- if (stiVariantNames.has(node.modelName)) return node;
3399
+ if (stiVariantKeys.has(variantKey)) return node;
3024
3400
  const basePrimaryKey = baseNode.id;
3025
3401
  if (!basePrimaryKey || basePrimaryKey.columns.length === 0) return node;
3026
3402
  const existingColumns = new Set(node.fields.map((field) => field.columnName));
@@ -3037,7 +3413,7 @@ function materializeMtiVariantStorageLinks(modelNodes, baseDeclarations, stiVari
3037
3413
  });
3038
3414
  }
3039
3415
  if (linkFields.length === 0) return node;
3040
- syntheticPkFieldsByVariant.set(node.modelName, linkFields.map((field) => field.fieldName));
3416
+ syntheticPkFieldsByVariant.set(variantKey, linkFields.map((field) => field.fieldName));
3041
3417
  const foreignKey = {
3042
3418
  columns: basePrimaryKey.columns,
3043
3419
  references: {
@@ -3079,21 +3455,22 @@ function materializeMtiVariantStorageLinks(modelNodes, baseDeclarations, stiVari
3079
3455
  * MTI link guard; surfacing them as diagnostics is tracked separately
3080
3456
  * (TML-2827).
3081
3457
  */
3082
- function materializeStiVariantStorageColumns(modelNodes, baseDeclarations, stiVariantNames) {
3083
- if (stiVariantNames.size === 0) return {
3458
+ function materializeStiVariantStorageColumns(modelNodes, baseDeclarations, stiVariantKeys, defaultNamespaceId) {
3459
+ if (stiVariantKeys.size === 0) return {
3084
3460
  modelNodes: [...modelNodes],
3085
3461
  stiBaseFieldsByBase: /* @__PURE__ */ new Map()
3086
3462
  };
3087
- const nodeByModel = new Map(modelNodes.map((node) => [node.modelName, node]));
3463
+ const keyOf = (node) => modelCoordinateKey(node.namespaceId ?? defaultNamespaceId, node.modelName);
3464
+ const nodeByModel = new Map(modelNodes.map((node) => [keyOf(node), node]));
3088
3465
  const stiColumnsByBase = /* @__PURE__ */ new Map();
3089
- for (const variantName of stiVariantNames) {
3090
- const variantNode = nodeByModel.get(variantName);
3091
- const baseDecl = baseDeclarations.get(variantName);
3466
+ for (const variantKey of stiVariantKeys) {
3467
+ const variantNode = nodeByModel.get(variantKey);
3468
+ const baseDecl = baseDeclarations.get(variantKey);
3092
3469
  if (!variantNode || !baseDecl) continue;
3093
- const baseNode = nodeByModel.get(baseDecl.baseName);
3470
+ const baseNode = nodeByModel.get(baseDecl.base.key);
3094
3471
  if (!baseNode) continue;
3095
3472
  const baseColumns = new Set(baseNode.fields.map((field) => field.columnName));
3096
- const claimed = stiColumnsByBase.get(baseDecl.baseName) ?? [];
3473
+ const claimed = stiColumnsByBase.get(baseDecl.base.key) ?? [];
3097
3474
  const claimedColumns = new Set(claimed.map((field) => field.columnName));
3098
3475
  for (const field of variantNode.fields) {
3099
3476
  if (baseColumns.has(field.columnName) || claimedColumns.has(field.columnName)) continue;
@@ -3103,17 +3480,17 @@ function materializeStiVariantStorageColumns(modelNodes, baseDeclarations, stiVa
3103
3480
  nullable: true
3104
3481
  });
3105
3482
  }
3106
- stiColumnsByBase.set(baseDecl.baseName, claimed);
3483
+ stiColumnsByBase.set(baseDecl.base.key, claimed);
3107
3484
  }
3108
3485
  const stiBaseFieldsByBase = /* @__PURE__ */ new Map();
3109
3486
  for (const [baseName, columns] of stiColumnsByBase) stiBaseFieldsByBase.set(baseName, columns.map((field) => field.fieldName));
3110
3487
  return {
3111
3488
  modelNodes: modelNodes.map((node) => {
3112
- if (stiVariantNames.has(node.modelName)) return {
3489
+ if (stiVariantKeys.has(keyOf(node))) return {
3113
3490
  ...node,
3114
3491
  sharesBaseTable: true
3115
3492
  };
3116
- const stiColumns = stiColumnsByBase.get(node.modelName);
3493
+ const stiColumns = stiColumnsByBase.get(keyOf(node));
3117
3494
  if (!stiColumns || stiColumns.length === 0) return node;
3118
3495
  return {
3119
3496
  ...node,
@@ -3211,7 +3588,10 @@ function interpretPslDocumentToSqlContract(input) {
3211
3588
  const composedExtensions = new Set(input.composedExtensions ?? []);
3212
3589
  const composedExtensionContracts = input.composedExtensionContracts;
3213
3590
  const defaultFunctionRegistry = input.controlMutationDefaults?.defaultFunctionRegistry ?? /* @__PURE__ */ new Map();
3214
- const defaultLiteralTagRegistry = input.controlMutationDefaults?.defaultLiteralTagRegistry ?? /* @__PURE__ */ new Map();
3591
+ const dataTypeSupport = {
3592
+ entries: input.authoringContributions?.dataTypes ?? {},
3593
+ lookup: input.dataTypeLookup
3594
+ };
3215
3595
  const generatorDescriptors = input.controlMutationDefaults?.generatorDescriptors ?? [];
3216
3596
  const generatorDescriptorById = /* @__PURE__ */ new Map();
3217
3597
  for (const descriptor of generatorDescriptors) generatorDescriptorById.set(descriptor.id, descriptor);
@@ -3278,7 +3658,7 @@ function interpretPslDocumentToSqlContract(input) {
3278
3658
  } },
3279
3659
  warnings: authoringWarnings
3280
3660
  };
3281
- const earlyModelMappingsByCoordinate = buildModelMappings(modelEntries, defaultNamespaceId, createPslDiagnosticCollector(input.sources), input.sources);
3661
+ const earlyModelMappingsByCoordinate = buildModelMappings(input.symbolTable, modelEntries, defaultNamespaceId, createPslDiagnosticCollector(input.sources), input.sources);
3282
3662
  const composedPslBlockDescriptors = input.authoringContributions?.pslBlockDescriptors ?? {};
3283
3663
  const namespaceExtensionEntities = /* @__PURE__ */ new Map();
3284
3664
  const mergeNamespaceExtensionEntities = (nsId, entities, blocks) => {
@@ -3351,7 +3731,7 @@ function interpretPslDocumentToSqlContract(input) {
3351
3731
  diagnostics
3352
3732
  });
3353
3733
  const storageTypes = { ...namedTypeResult.storageTypes };
3354
- const modelMappingsByCoordinate = buildModelMappings(modelEntries, defaultNamespaceId, diagnostics, input.sources);
3734
+ const modelMappingsByCoordinate = buildModelMappings(input.symbolTable, modelEntries, defaultNamespaceId, diagnostics, input.sources);
3355
3735
  const modelMappings = /* @__PURE__ */ new Map();
3356
3736
  for (const mapping of modelMappingsByCoordinate.values()) modelMappings.set(mapping.model.name, mapping);
3357
3737
  const modelNodes = [];
@@ -3380,7 +3760,7 @@ function interpretPslDocumentToSqlContract(input) {
3380
3760
  targetId: input.target.targetId,
3381
3761
  authoringContributions: input.authoringContributions,
3382
3762
  defaultFunctionRegistry,
3383
- defaultLiteralTagRegistry,
3763
+ dataTypeSupport,
3384
3764
  generatorDescriptorById,
3385
3765
  scalarColumnDescriptors: input.scalarColumnDescriptors,
3386
3766
  sources: input.sources,
@@ -3442,25 +3822,33 @@ function interpretPslDocumentToSqlContract(input) {
3442
3822
  if (existing) existing.push(...relations);
3443
3823
  else modelRelations.set(modelName, [...relations]);
3444
3824
  }
3445
- const { discriminatorDeclarations, baseDeclarations } = collectPolymorphismDeclarations(models, input.sources, diagnostics);
3446
- const stiVariantNames = /* @__PURE__ */ new Set();
3447
- for (const variantName of baseDeclarations.keys()) if (!(modelMappings.get(variantName)?.model.attributes.some((attr) => attr.name === "map") ?? false)) stiVariantNames.add(variantName);
3448
- for (const variantName of stiVariantNames) {
3449
- const variantMapping = modelMappings.get(variantName);
3825
+ const { discriminatorDeclarations, baseDeclarations } = collectPolymorphismDeclarations(new Map(modelEntries.map(({ model, namespaceId }) => {
3826
+ const resolvedNamespaceId = namespaceId ?? defaultNamespaceId;
3827
+ return [model, {
3828
+ model,
3829
+ namespaceId: resolvedNamespaceId,
3830
+ key: modelCoordinateKey(resolvedNamespaceId, model.name)
3831
+ }];
3832
+ })), input.symbolTable, input.sources, diagnostics);
3833
+ const stiVariantKeys = /* @__PURE__ */ new Set();
3834
+ for (const variantKey of baseDeclarations.keys()) if (!(modelMappingsByCoordinate.get(variantKey)?.model.attributes.some((attr) => attr.name === "map") ?? false)) stiVariantKeys.add(variantKey);
3835
+ for (const variantKey of stiVariantKeys) {
3836
+ const variantMapping = modelMappingsByCoordinate.get(variantKey);
3450
3837
  if (variantMapping === void 0) continue;
3451
- const baseDecl = baseDeclarations.get(variantName);
3452
- invariant(baseDecl !== void 0, `stiVariantNames is derived from baseDeclarations.keys(), so "${variantName}" must have a base declaration`);
3838
+ const variantName = variantMapping.model.name;
3839
+ const baseDecl = baseDeclarations.get(variantKey);
3840
+ invariant(baseDecl !== void 0, `stiVariantKeys is derived from baseDeclarations.keys(), so "${variantName}" must have a base declaration`);
3453
3841
  for (const attribute of variantMapping.model.node.attributes()) {
3454
3842
  if (attribute.name()?.isSimpleName("check") !== true) continue;
3455
3843
  diagnostics.push({
3456
3844
  code: PSL_CHECK_ON_STI_VARIANT,
3457
- message: `Model "${variantName}" declares "@@check", but it shares its base model "${baseDecl.baseName}"'s storage table (single-table inheritance via @@base) and has no table of its own to declare a check constraint on. Declare the check on "${baseDecl.baseName}" instead.`,
3845
+ message: `Model "${variantName}" declares "@@check", but it shares its base model "${baseDecl.base.model.name}"'s storage table (single-table inheritance via @@base) and has no table of its own to declare a check constraint on. Declare the check on "${baseDecl.base.model.name}" instead.`,
3458
3846
  ...diagnosticSource(input.sources, attribute.syntax).at(nodePslSpan(attribute.syntax, input.sources))
3459
3847
  });
3460
3848
  }
3461
3849
  }
3462
- const { modelNodes: mtiLinkedModelNodes, syntheticPkFieldsByVariant } = materializeMtiVariantStorageLinks(modelNodes, baseDeclarations, stiVariantNames);
3463
- const { modelNodes: stiColumnModelNodes, stiBaseFieldsByBase } = materializeStiVariantStorageColumns(mtiLinkedModelNodes, baseDeclarations, stiVariantNames);
3850
+ const { modelNodes: mtiLinkedModelNodes, syntheticPkFieldsByVariant } = materializeMtiVariantStorageLinks(modelNodes, baseDeclarations, stiVariantKeys, defaultNamespaceId);
3851
+ const { modelNodes: stiColumnModelNodes, stiBaseFieldsByBase } = materializeStiVariantStorageColumns(mtiLinkedModelNodes, baseDeclarations, stiVariantKeys, defaultNamespaceId);
3464
3852
  const valueObjects = buildValueObjects({
3465
3853
  compositeTypes,
3466
3854
  enumTypeDescriptors: allEnumTypeDescriptors,
@@ -3524,13 +3912,12 @@ function interpretPslDocumentToSqlContract(input) {
3524
3912
  }
3525
3913
  let patchedModels = patchModelDomainFields(modelsForPatch, modelResolvedFields);
3526
3914
  const polyDiagnostics = createPslDiagnosticCollector(input.sources);
3527
- patchedModels = resolvePolymorphism(patchedModels, discriminatorDeclarations, baseDeclarations, modelNames, modelMappings, modelNamespaceIds, input.target.defaultNamespaceId, syntheticPkFieldsByVariant, stiBaseFieldsByBase, polyDiagnostics);
3915
+ patchedModels = resolvePolymorphism(patchedModels, discriminatorDeclarations, baseDeclarations, modelMappingsByCoordinate, syntheticPkFieldsByVariant, stiBaseFieldsByBase, polyDiagnostics);
3528
3916
  if (polyDiagnostics.length > 0) return notOk({
3529
3917
  summary: "PSL to SQL contract interpretation failed",
3530
3918
  diagnostics: polyDiagnostics.toExternal()
3531
3919
  });
3532
- const variantModelNames = new Set(baseDeclarations.keys());
3533
- const filteredRoots = Object.fromEntries(Object.entries(contract.roots).filter(([, crossReference]) => !variantModelNames.has(crossReference.model)));
3920
+ const filteredRoots = Object.fromEntries(Object.entries(contract.roots).filter(([, crossReference]) => !baseDeclarations.has(modelCoordinateKey(crossReference.namespace, crossReference.model))));
3534
3921
  return ok({
3535
3922
  ...contract,
3536
3923
  roots: filteredRoots,
@@ -3543,6 +3930,6 @@ function interpretPslDocumentToSqlContract(input) {
3543
3930
  });
3544
3931
  }
3545
3932
  //#endregion
3546
- export { normalizeReferentialAction as a, interpretPslDocumentToSqlContract as i, buildEntityTypesByDiscriminator as n, numberLiteralDefault as o, indexFkRelations as r, resolveFieldTypeDescriptor as s, applyBackrelationCandidates as t };
3933
+ export { interpretPslDocumentToSqlContract as a, resolveFieldTypeDescriptor as c, indexFkRelations as i, buildEntityTypesByDiscriminator as n, normalizeReferentialAction as o, entryForTag as r, readDataTypeDefault as s, applyBackrelationCandidates as t };
3547
3934
 
3548
- //# sourceMappingURL=interpreter-Bf7Um__3-DC_thY44.mjs.map
3935
+ //# sourceMappingURL=interpreter-BIBwrA2w-DAiNN30m.mjs.map