@prisma/orm-target-postgres 8.0.0-rc.2-dev.3 → 8.0.0-rc.20

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 (501) hide show
  1. package/README.md +4 -6
  2. package/dist/adapter-5qylEP__.d.mts +403 -0
  3. package/dist/adapter-5qylEP__.d.mts.map +1 -0
  4. package/dist/{adapter-B0xsc80z-sYcF0RVF.mjs → adapter-svGTIjA2-1p-Iw8D2.mjs} +24 -30
  5. package/dist/adapter-svGTIjA2-1p-Iw8D2.mjs.map +1 -0
  6. package/dist/adapter.d.mts +11 -13
  7. package/dist/adapter.mjs +7 -8
  8. package/dist/adapter__adapter.d.mts +2 -2
  9. package/dist/adapter__adapter.mjs +3 -2
  10. package/dist/adapter__column-types.d.mts +2 -2
  11. package/dist/adapter__column-types.mjs +2 -2
  12. package/dist/adapter__control.d.mts +4 -5
  13. package/dist/adapter__control.mjs +11 -423
  14. package/dist/adapter__control.mjs.map +1 -1
  15. package/dist/adapter__runtime.d.mts +1 -1
  16. package/dist/adapter__runtime.mjs +29 -19
  17. package/dist/adapter__runtime.mjs.map +1 -1
  18. package/dist/adapter__sql-renderer.d.mts +1 -1
  19. package/dist/adapter__sql-renderer.mjs +1 -1
  20. package/dist/adapter__types.d.mts +4 -3
  21. package/dist/aggregates-CEqqEg8k.d.mts +318 -0
  22. package/dist/aggregates-CEqqEg8k.d.mts.map +1 -0
  23. package/dist/{aggregates-Dh6HPdvC.mjs → aggregates-Dw-lAutX.mjs} +105 -40
  24. package/dist/aggregates-Dw-lAutX.mjs.map +1 -0
  25. package/dist/authoring-DWd5pnnV-BBX7P1wT.d.mts +52 -0
  26. package/dist/authoring-DWd5pnnV-BBX7P1wT.d.mts.map +1 -0
  27. package/dist/authoring-SbdvmVJh-nQ7YliD_.mjs +1342 -0
  28. package/dist/authoring-SbdvmVJh-nQ7YliD_.mjs.map +1 -0
  29. package/dist/autoincrement-widths-DonNJgfS-CCvZ4u1W.mjs +58 -0
  30. package/dist/autoincrement-widths-DonNJgfS-CCvZ4u1W.mjs.map +1 -0
  31. package/dist/{canonicalize-CQlxSR4D-MnrT5gtW.d.mts → canonicalize-B-xvDOdd-G3yUeKj4.d.mts} +7 -3
  32. package/dist/canonicalize-B-xvDOdd-G3yUeKj4.d.mts.map +1 -0
  33. package/dist/{canonicalize-CrN3u_xM-D4MrOqcB.mjs → canonicalize-RdxoUHao-FTTkizfe.mjs} +15 -3
  34. package/dist/canonicalize-RdxoUHao-FTTkizfe.mjs.map +1 -0
  35. package/dist/check-expressions-7uCCP01t-DtX2Vak9.mjs +48 -0
  36. package/dist/check-expressions-7uCCP01t-DtX2Vak9.mjs.map +1 -0
  37. package/dist/{check-expressions-DRgG8RN5-DiA-22aC.d.mts → check-expressions-CtTzM58x-LloO-5Vf.d.mts} +14 -13
  38. package/dist/check-expressions-CtTzM58x-LloO-5Vf.d.mts.map +1 -0
  39. package/dist/{codec-descriptor-LT7BpQta-BaDM8UQQ.mjs → codec-descriptor-DoR-cTFZ-BlG5Gj-X.mjs} +12 -21
  40. package/dist/codec-descriptor-DoR-cTFZ-BlG5Gj-X.mjs.map +1 -0
  41. package/dist/codec-descriptor-Fb3UoQGb.d.mts +1 -0
  42. package/dist/codec-descriptor-d1ByNBEk-DhrtS_5y.d.mts +47 -0
  43. package/dist/codec-descriptor-d1ByNBEk-DhrtS_5y.d.mts.map +1 -0
  44. package/dist/codec-ids-BMhEpFwv-B8Zh0s_Q.mjs +41 -0
  45. package/dist/codec-ids-BMhEpFwv-B8Zh0s_Q.mjs.map +1 -0
  46. package/dist/codec-ids-C6II64Wy-CPYTqDTT.d.mts +41 -0
  47. package/dist/codec-ids-C6II64Wy-CPYTqDTT.d.mts.map +1 -0
  48. package/dist/codec-ids-CcB5uBNf.d.mts +1 -0
  49. package/dist/codec-registry-D7XslgPe-DTZnVB8W.mjs +61 -0
  50. package/dist/codec-registry-D7XslgPe-DTZnVB8W.mjs.map +1 -0
  51. package/dist/codec-type-map-Fj5xCgwT-BeCXgfuR.d.mts +53 -0
  52. package/dist/codec-type-map-Fj5xCgwT-BeCXgfuR.d.mts.map +1 -0
  53. package/dist/codec-types-BBACckHa.d.mts +2 -0
  54. package/dist/codec-types-Ct_4iTVc-3tFJcIBo.d.mts +84 -0
  55. package/dist/codec-types-Ct_4iTVc-3tFJcIBo.d.mts.map +1 -0
  56. package/dist/codecs-CADK7dCR-C8WToYQb.d.mts +724 -0
  57. package/dist/codecs-CADK7dCR-C8WToYQb.d.mts.map +1 -0
  58. package/dist/codecs-CRl9-i_r-Co-bgYl3.mjs +1743 -0
  59. package/dist/codecs-CRl9-i_r-Co-bgYl3.mjs.map +1 -0
  60. package/dist/codecs-CoEpEqjM.d.mts +31 -0
  61. package/dist/codecs-CoEpEqjM.d.mts.map +1 -0
  62. package/dist/column-types-B4zsV-u3.mjs +106 -0
  63. package/dist/column-types-B4zsV-u3.mjs.map +1 -0
  64. package/dist/column-types-Bs2V0j8T.d.mts +164 -0
  65. package/dist/column-types-Bs2V0j8T.d.mts.map +1 -0
  66. package/dist/{control-adapter-DFr4gS-r-DM3KcZdQ.mjs → contract-contributions-Xz2FpyfI-CeQZqHKf.mjs} +489 -292
  67. package/dist/contract-contributions-Xz2FpyfI-CeQZqHKf.mjs.map +1 -0
  68. package/dist/{contract-free-DzpGxLfb.d.mts → contract-free-B6-wuc6M.d.mts} +36 -6
  69. package/dist/contract-free-B6-wuc6M.d.mts.map +1 -0
  70. package/dist/{contract-free-aQ4nT-_R.mjs → contract-free-o7olebm9.mjs} +13 -9
  71. package/dist/contract-free-o7olebm9.mjs.map +1 -0
  72. package/dist/control--HupSPoV.d.mts +847 -0
  73. package/dist/control--HupSPoV.d.mts.map +1 -0
  74. package/dist/{control-BaUpALVp.d.mts → control-CQEjh4P7.d.mts} +2 -2
  75. package/dist/control-CQEjh4P7.d.mts.map +1 -0
  76. package/dist/{control-DLTOAEHj.d.mts → control-D4cTcpcJ.d.mts} +22 -48
  77. package/dist/control-D4cTcpcJ.d.mts.map +1 -0
  78. package/dist/{control-Y6FxMu3o.mjs → control-DZQwENIP.mjs} +21 -9
  79. package/dist/control-DZQwENIP.mjs.map +1 -0
  80. package/dist/{control-policy-B53lnBCT-B9K9Cj1x.mjs → control-policy-DtU5u9Dm-44r_OF94.mjs} +444 -218
  81. package/dist/control-policy-DtU5u9Dm-44r_OF94.mjs.map +1 -0
  82. package/dist/{data-transform-ChZzy2dP-CxVCat_8.mjs → data-transform-h9agBu_c-RlC5A7aY.mjs} +12 -5
  83. package/dist/data-transform-h9agBu_c-RlC5A7aY.mjs.map +1 -0
  84. package/dist/{data-transform-Ck5FbyNO-BNE7QlAo.d.mts → data-transform-nGy9rz87-CE3DGlgn.d.mts} +15 -4
  85. package/dist/data-transform-nGy9rz87-CE3DGlgn.d.mts.map +1 -0
  86. package/dist/data-transform-nqkqNIb8.d.mts +1 -0
  87. package/dist/data-type-entries-gQW3-KSb-BIl8vgus.mjs +128 -0
  88. package/dist/data-type-entries-gQW3-KSb-BIl8vgus.mjs.map +1 -0
  89. package/dist/data-types--7V9yY1G.d.mts +99 -0
  90. package/dist/data-types--7V9yY1G.d.mts.map +1 -0
  91. package/dist/data-types-Chx0mjTP-DczU4S9b.mjs +950 -0
  92. package/dist/data-types-Chx0mjTP-DczU4S9b.mjs.map +1 -0
  93. package/dist/date-time-now-generators-CMkXVbMG-C-GjhReE.d.mts +45 -0
  94. package/dist/date-time-now-generators-CMkXVbMG-C-GjhReE.d.mts.map +1 -0
  95. package/dist/ddl-B7Rqlz6D-B7dRDgYb.mjs +647 -0
  96. package/dist/ddl-B7Rqlz6D-B7dRDgYb.mjs.map +1 -0
  97. package/dist/ddl-B8nQZTWN.d.mts +1 -0
  98. package/dist/default-constraint-names-Cz9Yoeim-sUzOGvIm.mjs +18 -0
  99. package/dist/default-constraint-names-Cz9Yoeim-sUzOGvIm.mjs.map +1 -0
  100. package/dist/default-normalizer-BqK6XxdC-2OUb2ybG.mjs +311 -0
  101. package/dist/default-normalizer-BqK6XxdC-2OUb2ybG.mjs.map +1 -0
  102. package/dist/default-normalizer-DO-cH75Q.d.mts +25 -0
  103. package/dist/default-normalizer-DO-cH75Q.d.mts.map +1 -0
  104. package/dist/descriptor-meta-BkD3nXF_-CZaNqC6r.mjs +36 -0
  105. package/dist/descriptor-meta-BkD3nXF_-CZaNqC6r.mjs.map +1 -0
  106. package/dist/descriptor-meta-DaFDNnHQ-QjiiAEtC.mjs +64 -0
  107. package/dist/descriptor-meta-DaFDNnHQ-QjiiAEtC.mjs.map +1 -0
  108. package/dist/descriptor-meta-runtime-Dft1L7eE-D8vpOz_Z.mjs +15 -0
  109. package/dist/descriptor-meta-runtime-Dft1L7eE-D8vpOz_Z.mjs.map +1 -0
  110. package/dist/{diff-database-schema-DsoNznGC.d.mts → diff-database-schema-BxzhZaVN.d.mts} +12 -7
  111. package/dist/diff-database-schema-BxzhZaVN.d.mts.map +1 -0
  112. package/dist/{diff-database-schema-DKq76rCk-uehceHYz.mjs → diff-database-schema-DAEzWtzU-DoyVgKqh.mjs} +38 -18
  113. package/dist/diff-database-schema-DAEzWtzU-DoyVgKqh.mjs.map +1 -0
  114. package/dist/driver.d.mts +3 -3
  115. package/dist/driver.mjs +3 -2
  116. package/dist/driver__control.d.mts +1 -1
  117. package/dist/driver__control.mjs +1 -1
  118. package/dist/driver__runtime.d.mts +2 -2
  119. package/dist/driver__runtime.mjs +2 -639
  120. package/dist/errors-BrhQYgdL-IvZHPjwL.mjs +103 -0
  121. package/dist/errors-BrhQYgdL-IvZHPjwL.mjs.map +1 -0
  122. package/dist/{errors-CU4xIwwk.d.mts → errors-D3Mj-x0o.d.mts} +3 -3
  123. package/dist/errors-D3Mj-x0o.d.mts.map +1 -0
  124. package/dist/full-text-BYg7EVX2.mjs +39 -0
  125. package/dist/full-text-BYg7EVX2.mjs.map +1 -0
  126. package/dist/full-text-SDbfxrE_.d.mts +26 -0
  127. package/dist/full-text-SDbfxrE_.d.mts.map +1 -0
  128. package/dist/full-text-collection-method-BFd2u2cs-Ba3OiWM3.d.mts +27 -0
  129. package/dist/full-text-collection-method-BFd2u2cs-Ba3OiWM3.d.mts.map +1 -0
  130. package/dist/full-text-index-authoring-CN1L9C1k.d.mts +7 -0
  131. package/dist/full-text-index-authoring-CN1L9C1k.d.mts.map +1 -0
  132. package/dist/full-text-index-definition-BPxQQBuC-VLyQ1kEL.mjs +195 -0
  133. package/dist/full-text-index-definition-BPxQQBuC-VLyQ1kEL.mjs.map +1 -0
  134. package/dist/full-text-index-definition-D5iBWLss-BEpqiucV.d.mts +71 -0
  135. package/dist/full-text-index-definition-D5iBWLss-BEpqiucV.d.mts.map +1 -0
  136. package/dist/full-text-parsers-CFFxiOrp-CrZ7VI1m.mjs +139 -0
  137. package/dist/full-text-parsers-CFFxiOrp-CrZ7VI1m.mjs.map +1 -0
  138. package/dist/full-text-search-document-Doy5TF7c-aMWM_1KB.mjs +54 -0
  139. package/dist/full-text-search-document-Doy5TF7c-aMWM_1KB.mjs.map +1 -0
  140. package/dist/index-types-BihjrAAq-C2VnfAyF.mjs +14 -0
  141. package/dist/index-types-BihjrAAq-C2VnfAyF.mjs.map +1 -0
  142. package/dist/indexes-BYf6nXVv-BXwLw7fO.d.mts +60 -0
  143. package/dist/indexes-BYf6nXVv-BXwLw7fO.d.mts.map +1 -0
  144. package/dist/infer-psl-contract-BSSHcuRi-ChdFSviw.mjs +1143 -0
  145. package/dist/infer-psl-contract-BSSHcuRi-ChdFSviw.mjs.map +1 -0
  146. package/dist/{issue-planner-Biq9Ls7e.d.mts → issue-planner-D-On52xP.d.mts} +39 -9
  147. package/dist/issue-planner-D-On52xP.d.mts.map +1 -0
  148. package/dist/list-decoder-BcrLExnx-DlCwavhu.d.mts +7 -0
  149. package/dist/list-decoder-BcrLExnx-DlCwavhu.d.mts.map +1 -0
  150. package/dist/marker-lock-BviIbusV.d.mts +11 -0
  151. package/dist/marker-lock-BviIbusV.d.mts.map +1 -0
  152. package/dist/marker-lock-DFc1Tfv5-BkBKBRE3.mjs +11 -0
  153. package/dist/marker-lock-DFc1Tfv5-BkBKBRE3.mjs.map +1 -0
  154. package/dist/{migration-PTHAY9Cv.mjs → migration-Be_iuIpn.mjs} +5 -4
  155. package/dist/migration-Be_iuIpn.mjs.map +1 -0
  156. package/dist/migration-D4lMmLVj.d.mts +26 -0
  157. package/dist/migration-D4lMmLVj.d.mts.map +1 -0
  158. package/dist/{namespace-ids-xtp_ZY86-Cpp8PTxD.mjs → namespace-ids-xtp_ZY86-Cxc0dBbO.mjs} +2 -2
  159. package/dist/namespace-ids-xtp_ZY86-Cxc0dBbO.mjs.map +1 -0
  160. package/dist/native-type-normalizer-BaGa9eeb.d.mts +30 -0
  161. package/dist/native-type-normalizer-BaGa9eeb.d.mts.map +1 -0
  162. package/dist/native-type-normalizer-Cn-RGt_E.mjs +24 -0
  163. package/dist/native-type-normalizer-Cn-RGt_E.mjs.map +1 -0
  164. package/dist/{nodes-DAvDJLvJ-BBdvFXNa.mjs → nodes-G8VTh4PM-DNvIhHag.mjs} +78 -7
  165. package/dist/nodes-G8VTh4PM-DNvIhHag.mjs.map +1 -0
  166. package/dist/{nodes-BU-V-aZA-RqwPH68u.d.mts → nodes-s0Oe37jT-Cw3BU2gL.d.mts} +82 -29
  167. package/dist/nodes-s0Oe37jT-Cw3BU2gL.d.mts.map +1 -0
  168. package/dist/op-factory-call-CRaVUOb_.d.mts +1 -0
  169. package/dist/{op-factory-call-H6zeDGLe-_1pAftJk.mjs → op-factory-call-gGX-mZu--0QUG5xH4.mjs} +1014 -258
  170. package/dist/op-factory-call-gGX-mZu--0QUG5xH4.mjs.map +1 -0
  171. package/dist/{op-factory-call-BAeyLFYf-BAgG1h1C.d.mts → op-factory-call-nLHvNx0O-BTBhGbOF.d.mts} +169 -111
  172. package/dist/op-factory-call-nLHvNx0O-BTBhGbOF.d.mts.map +1 -0
  173. package/dist/operation-types--Wa_cv45-RoRnL1Dn.d.mts +192 -0
  174. package/dist/operation-types--Wa_cv45-RoRnL1Dn.d.mts.map +1 -0
  175. package/dist/operation-types-OXILTAOX.d.mts +1 -0
  176. package/dist/pack-2CYw2w-b.d.mts +1573 -0
  177. package/dist/pack-2CYw2w-b.d.mts.map +1 -0
  178. package/dist/{planner-CT-7zSfk.d.mts → planner-AD3Dt57t.d.mts} +23 -51
  179. package/dist/planner-AD3Dt57t.d.mts.map +1 -0
  180. package/dist/planner-VuR6URu3-CCUT2Osx.mjs +954 -0
  181. package/dist/planner-VuR6URu3-CCUT2Osx.mjs.map +1 -0
  182. package/dist/planner-ddl-builders-CPM3y7cQ.d.mts +16 -0
  183. package/dist/planner-ddl-builders-CPM3y7cQ.d.mts.map +1 -0
  184. package/dist/planner-ddl-builders-cYnH52gC-BWifb_M6.mjs +28 -0
  185. package/dist/planner-ddl-builders-cYnH52gC-BWifb_M6.mjs.map +1 -0
  186. package/dist/planner-identity-values-Dsq989Lh.d.mts +26 -0
  187. package/dist/planner-identity-values-Dsq989Lh.d.mts.map +1 -0
  188. package/dist/planner-identity-values-QstrMJ2U-CcpaRVPY.mjs +70 -0
  189. package/dist/planner-identity-values-QstrMJ2U-CcpaRVPY.mjs.map +1 -0
  190. package/dist/planner-produced-postgres-migration-BBUwtjA_.d.mts +1 -0
  191. package/dist/{planner-produced-postgres-migration-D5m8nK6s-CbZ4hlbv.mjs → planner-produced-postgres-migration-BZclL_xO-uflxtYuP.mjs} +5 -5
  192. package/dist/planner-produced-postgres-migration-BZclL_xO-uflxtYuP.mjs.map +1 -0
  193. package/dist/{planner-produced-postgres-migration-BaviT8KK-Yo9kw6rs.d.mts → planner-produced-postgres-migration-DyIXJ3MR-DHO5wn_X.d.mts} +4 -4
  194. package/dist/planner-produced-postgres-migration-DyIXJ3MR-DHO5wn_X.d.mts.map +1 -0
  195. package/dist/{planner-schema-lookup-kMIVP2y--CdO4VlnF.mjs → planner-schema-lookup-BbUY9oVy.mjs} +2 -2
  196. package/dist/planner-schema-lookup-BbUY9oVy.mjs.map +1 -0
  197. package/dist/{planner-schema-lookup-C4DHAddq.d.mts → planner-schema-lookup-ceCNOGFf.d.mts} +2 -2
  198. package/dist/planner-schema-lookup-ceCNOGFf.d.mts.map +1 -0
  199. package/dist/planner-sql-checks-D-K44J19-CzvrqzNB.mjs +151 -0
  200. package/dist/planner-sql-checks-D-K44J19-CzvrqzNB.mjs.map +1 -0
  201. package/dist/planner-sql-checks-Ed-WGtge-D9ByMrW4.d.mts +37 -0
  202. package/dist/planner-sql-checks-Ed-WGtge-D9ByMrW4.d.mts.map +1 -0
  203. package/dist/planner-sql-checks-rEjFx_Jv.d.mts +1 -0
  204. package/dist/planner-target-details-CUEF0s90-6g-mOgTI.mjs +14 -0
  205. package/dist/planner-target-details-CUEF0s90-6g-mOgTI.mjs.map +1 -0
  206. package/dist/{planner-target-details-HkP4RrRO-_xPQVPF0.d.mts → planner-target-details-HkP4RrRO-D6VtK0jY.d.mts} +2 -2
  207. package/dist/planner-target-details-HkP4RrRO-D6VtK0jY.d.mts.map +1 -0
  208. package/dist/postgres-codec-traits-CnP5Bjxp-Dxdgv0TI.mjs +11 -0
  209. package/dist/postgres-codec-traits-CnP5Bjxp-Dxdgv0TI.mjs.map +1 -0
  210. package/dist/{postgres-contract-view-2OP5JnXl-D2fpy4-8.d.mts → postgres-contract-view-BFzIDwwN-hL3QLe_b.d.mts} +2 -2
  211. package/dist/postgres-contract-view-BFzIDwwN-hL3QLe_b.d.mts.map +1 -0
  212. package/dist/{postgres-contract-view-B8ykf2cO-T2LvWVFZ.mjs → postgres-contract-view-BO2elRMz-BqMBzJoJ.mjs} +27 -14
  213. package/dist/postgres-contract-view-BO2elRMz-BqMBzJoJ.mjs.map +1 -0
  214. package/dist/{postgres-database-schema-node-CyfpHXDr-BqyozkQE.d.mts → postgres-database-schema-node-Cv8usVNX-BmvGozi4.d.mts} +4 -4
  215. package/dist/postgres-database-schema-node-Cv8usVNX-BmvGozi4.d.mts.map +1 -0
  216. package/dist/postgres-migration-BSWmeRLo-CUfVTUf0.mjs +1312 -0
  217. package/dist/postgres-migration-BSWmeRLo-CUfVTUf0.mjs.map +1 -0
  218. package/dist/{postgres-migration-BNsrwlxh-CwI5BqAu.d.mts → postgres-migration-C5deJ3Ne-C4Jxu-e6.d.mts} +135 -15
  219. package/dist/postgres-migration-C5deJ3Ne-C4Jxu-e6.d.mts.map +1 -0
  220. package/dist/{postgres-native-enum-CdP3b_-R-Cgz9KEKx.mjs → postgres-native-enum-CdP3b_-R-DgG3pi5p.mjs} +2 -2
  221. package/dist/postgres-native-enum-CdP3b_-R-DgG3pi5p.mjs.map +1 -0
  222. package/dist/postgres-object-name-FPikIvOw-B8FfJI7z.mjs +23 -0
  223. package/dist/postgres-object-name-FPikIvOw-B8FfJI7z.mjs.map +1 -0
  224. package/dist/{postgres-rls-policy-CnDxf3z9-C3LIHAIG.d.mts → postgres-rls-policy-CnDxf3z9-BjpVyUnK.d.mts} +2 -2
  225. package/dist/postgres-rls-policy-CnDxf3z9-BjpVyUnK.d.mts.map +1 -0
  226. package/dist/{postgres-role-schema-node-B8Z5i5D--PObwlU2Z.mjs → postgres-role-schema-node-B8Z5i5D--BzOKm4N1.mjs} +3 -3
  227. package/dist/postgres-role-schema-node-B8Z5i5D--BzOKm4N1.mjs.map +1 -0
  228. package/dist/{postgres-schema-CF0yHESb-D7n2X21R.mjs → postgres-schema-C6w1rzOF-D1fdwqRx.mjs} +14 -12
  229. package/dist/postgres-schema-C6w1rzOF-D1fdwqRx.mjs.map +1 -0
  230. package/dist/{postgres-schema-Xsjt3RKO-Buv2X8ai.d.mts → postgres-schema-Xsjt3RKO-bis-SVSB.d.mts} +4 -4
  231. package/dist/postgres-schema-Xsjt3RKO-bis-SVSB.d.mts.map +1 -0
  232. package/dist/{postgres-table-schema-node-BBkitBQh-DT1T5VWU.mjs → postgres-table-schema-node-BBkitBQh-Dll8iaZT.mjs} +2 -2
  233. package/dist/postgres-table-schema-node-BBkitBQh-Dll8iaZT.mjs.map +1 -0
  234. package/dist/prisma7-binding-BjiLA9F7.mjs +307 -0
  235. package/dist/prisma7-binding-BjiLA9F7.mjs.map +1 -0
  236. package/dist/prisma7-binding-a56klfkc.d.mts +1651 -0
  237. package/dist/prisma7-binding-a56klfkc.d.mts.map +1 -0
  238. package/dist/{render-ops-DOsRP0Po-BKn_c_Ia.mjs → render-ops-BgqtCw9Z-T8BPTX85.mjs} +17 -10
  239. package/dist/render-ops-BgqtCw9Z-T8BPTX85.mjs.map +1 -0
  240. package/dist/{render-ops-DPwhZt2W.d.mts → render-ops-Bl84i7ut.d.mts} +3 -3
  241. package/dist/render-ops-Bl84i7ut.d.mts.map +1 -0
  242. package/dist/{render-typescript-6sCFvMBh.d.mts → render-typescript-BysdXYpH.d.mts} +2 -2
  243. package/dist/render-typescript-BysdXYpH.d.mts.map +1 -0
  244. package/dist/{render-typescript-Dqp1Spgn-B128r1qw.mjs → render-typescript-Dqp1Spgn-B4mJhuVr.mjs} +2 -2
  245. package/dist/render-typescript-Dqp1Spgn-B4mJhuVr.mjs.map +1 -0
  246. package/dist/resolve-ddl-schema-D3VNPMSm-BuB6NyOI.mjs +34 -0
  247. package/dist/resolve-ddl-schema-D3VNPMSm-BuB6NyOI.mjs.map +1 -0
  248. package/dist/{runtime-lHBKgjB9.d.mts → runtime-C0VXuM0b.d.mts} +4 -3
  249. package/dist/runtime-C0VXuM0b.d.mts.map +1 -0
  250. package/dist/runtime-CXfxy5ED.mjs +660 -0
  251. package/dist/runtime-CXfxy5ED.mjs.map +1 -0
  252. package/dist/{runtime-_TfO66h5.d.mts → runtime-Ci_toEDZ.d.mts} +12 -4
  253. package/dist/runtime-Ci_toEDZ.d.mts.map +1 -0
  254. package/dist/{runtime-DOXznQe0.d.mts → runtime-DtjW0GP_.d.mts} +4 -4
  255. package/dist/runtime-DtjW0GP_.d.mts.map +1 -0
  256. package/dist/{schema-ir-annotations-DuuYh0gl.d.mts → schema-ir-annotations-BygaWBiC.d.mts} +2 -2
  257. package/dist/schema-ir-annotations-BygaWBiC.d.mts.map +1 -0
  258. package/dist/{schema-node-kinds-qlnURWJy-Bo30pwTM.d.mts → schema-node-kinds-C52Bb1ve-DmxQRPPS.d.mts} +2 -2
  259. package/dist/schema-node-kinds-C52Bb1ve-DmxQRPPS.d.mts.map +1 -0
  260. package/dist/{normalize-error-CNjgVO71-CLlZ3CuJ.mjs → server-text-types-DeNPQpv5-DqX0h8WF.mjs} +45 -3
  261. package/dist/server-text-types-DeNPQpv5-DqX0h8WF.mjs.map +1 -0
  262. package/dist/{sql-renderer-ComgusFq-BBlqM1fw.mjs → sql-renderer-BdWJPa5F-Ct0CPlXc.mjs} +113 -123
  263. package/dist/sql-renderer-BdWJPa5F-Ct0CPlXc.mjs.map +1 -0
  264. package/dist/{sql-renderer-BgC0ZgLS.d.mts → sql-renderer-BiBhge7D.d.mts} +9 -7
  265. package/dist/sql-renderer-BiBhge7D.d.mts.map +1 -0
  266. package/dist/{sql-utils-DuzN3JZg-DiXy4Vah.mjs → sql-utils-Bnw3JbWf-BN0gcjZB.mjs} +31 -8
  267. package/dist/sql-utils-Bnw3JbWf-BN0gcjZB.mjs.map +1 -0
  268. package/dist/{sql-utils-DW6fkczF.d.mts → sql-utils-CnnGiZBc.d.mts} +12 -4
  269. package/dist/sql-utils-CnnGiZBc.d.mts.map +1 -0
  270. package/dist/{table-source-ikHOZmhD-DriY1Lcr.d.mts → table-source-ikHOZmhD-vYcblBYv.d.mts} +2 -2
  271. package/dist/table-source-ikHOZmhD-vYcblBYv.d.mts.map +1 -0
  272. package/dist/target.d.mts +61 -49
  273. package/dist/target.mjs +45 -36
  274. package/dist/target__aggregates.d.mts +1 -1
  275. package/dist/target__aggregates.mjs +1 -1
  276. package/dist/target__codec-descriptor.d.mts +2 -2
  277. package/dist/target__codec-descriptor.mjs +1 -1
  278. package/dist/target__codec-ids.d.mts +3 -3
  279. package/dist/target__codec-ids.mjs +2 -2
  280. package/dist/target__codec-types.d.mts +4 -4
  281. package/dist/target__codecs.d.mts +4 -3
  282. package/dist/target__codecs.mjs +3 -3
  283. package/dist/target__contract-free.d.mts +3 -3
  284. package/dist/target__contract-free.mjs +4 -4
  285. package/dist/target__control.d.mts +4 -2
  286. package/dist/target__control.mjs +2501 -2
  287. package/dist/target__control.mjs.map +1 -0
  288. package/dist/target__data-transform.d.mts +2 -2
  289. package/dist/target__data-transform.mjs +1 -1
  290. package/dist/target__data-types.d.mts +2 -0
  291. package/dist/target__data-types.mjs +3 -0
  292. package/dist/target__ddl.d.mts +4 -4
  293. package/dist/target__ddl.mjs +2 -2
  294. package/dist/target__default-normalizer.d.mts +2 -2
  295. package/dist/target__default-normalizer.mjs +2 -2
  296. package/dist/target__diff-database-schema.d.mts +1 -1
  297. package/dist/target__diff-database-schema.mjs +1 -1
  298. package/dist/target__errors.d.mts +1 -1
  299. package/dist/target__errors.mjs +1 -1
  300. package/dist/target__full-text-index-authoring.d.mts +3 -0
  301. package/dist/target__full-text-index-authoring.mjs +3 -0
  302. package/dist/target__full-text.d.mts +4 -0
  303. package/dist/target__full-text.mjs +3 -0
  304. package/dist/target__issue-planner.d.mts +1 -1
  305. package/dist/target__issue-planner.mjs +1 -1
  306. package/dist/target__marker-lock.d.mts +2 -0
  307. package/dist/target__marker-lock.mjs +2 -0
  308. package/dist/target__migration.d.mts +4 -4
  309. package/dist/target__migration.mjs +5 -5
  310. package/dist/target__native-type-normalizer.d.mts +2 -2
  311. package/dist/target__native-type-normalizer.mjs +2 -2
  312. package/dist/target__op-factory-call.d.mts +3 -3
  313. package/dist/target__op-factory-call.mjs +2 -2
  314. package/dist/target__operation-types.d.mts +4 -0
  315. package/dist/target__pack.d.mts +3 -2
  316. package/dist/target__pack.mjs +1 -1
  317. package/dist/target__planner-ddl-builders.d.mts +2 -2
  318. package/dist/target__planner-ddl-builders.mjs +2 -2
  319. package/dist/target__planner-identity-values.d.mts +1 -1
  320. package/dist/target__planner-identity-values.mjs +1 -1
  321. package/dist/target__planner-produced-postgres-migration.d.mts +2 -2
  322. package/dist/target__planner-produced-postgres-migration.mjs +1 -1
  323. package/dist/target__planner-schema-lookup.d.mts +1 -1
  324. package/dist/target__planner-schema-lookup.mjs +1 -1
  325. package/dist/target__planner-sql-checks.d.mts +3 -2
  326. package/dist/target__planner-sql-checks.mjs +2 -2
  327. package/dist/target__planner-target-details.d.mts +1 -1
  328. package/dist/target__planner.d.mts +1 -1
  329. package/dist/target__planner.mjs +2 -2
  330. package/dist/target__prisma7-binding.d.mts +2 -0
  331. package/dist/target__prisma7-binding.mjs +2 -0
  332. package/dist/target__render-ops.d.mts +1 -1
  333. package/dist/target__render-ops.mjs +1 -1
  334. package/dist/target__render-typescript.d.mts +1 -1
  335. package/dist/target__render-typescript.mjs +1 -1
  336. package/dist/target__rls-canonicalize.d.mts +2 -2
  337. package/dist/target__rls-canonicalize.mjs +2 -2
  338. package/dist/target__runtime.d.mts +6 -3
  339. package/dist/target__runtime.mjs +193 -4
  340. package/dist/target__runtime.mjs.map +1 -1
  341. package/dist/target__schema-ir-annotations.d.mts +1 -1
  342. package/dist/target__schema-ir-annotations.mjs +1 -1
  343. package/dist/target__sql-utils.d.mts +3 -2
  344. package/dist/target__sql-utils.mjs +4 -2
  345. package/dist/target__types.d.mts +7 -7
  346. package/dist/target__types.mjs +5 -5
  347. package/dist/types-AvjnIUna.d.mts +2 -0
  348. package/dist/types-D6lgKhE5-D1J9YJnd.d.mts +28 -0
  349. package/dist/types-D6lgKhE5-D1J9YJnd.d.mts.map +1 -0
  350. package/dist/{types-CjGjPLr5.d.mts → types-DOmgp_12.d.mts} +8 -8
  351. package/dist/types-DOmgp_12.d.mts.map +1 -0
  352. package/dist/{types-ue6jkJyF-BQJzjx1P.d.mts → types-ue6jkJyF-D79DmBTl.d.mts} +2 -2
  353. package/dist/types-ue6jkJyF-D79DmBTl.d.mts.map +1 -0
  354. package/package.json +22 -14
  355. package/dist/adapter-B0xsc80z-sYcF0RVF.mjs.map +0 -1
  356. package/dist/adapter-CPesdzv0.d.mts +0 -26
  357. package/dist/adapter-CPesdzv0.d.mts.map +0 -1
  358. package/dist/adapter__operation-types.d.mts +0 -2
  359. package/dist/aggregates-CgqNfj2O.d.mts +0 -10
  360. package/dist/aggregates-CgqNfj2O.d.mts.map +0 -1
  361. package/dist/aggregates-Dh6HPdvC.mjs.map +0 -1
  362. package/dist/authoring-BOpdZa2N-ClrLFiXw.mjs +0 -773
  363. package/dist/authoring-BOpdZa2N-ClrLFiXw.mjs.map +0 -1
  364. package/dist/canonicalize-CQlxSR4D-MnrT5gtW.d.mts.map +0 -1
  365. package/dist/canonicalize-CrN3u_xM-D4MrOqcB.mjs.map +0 -1
  366. package/dist/check-expressions-5vhxWaFy-CBcjFeur.mjs +0 -41
  367. package/dist/check-expressions-5vhxWaFy-CBcjFeur.mjs.map +0 -1
  368. package/dist/check-expressions-DRgG8RN5-DiA-22aC.d.mts.map +0 -1
  369. package/dist/codec-descriptor-Bec_zukr-BfvtUqhm.d.mts +0 -37
  370. package/dist/codec-descriptor-Bec_zukr-BfvtUqhm.d.mts.map +0 -1
  371. package/dist/codec-descriptor-Bg-_412t.d.mts +0 -1
  372. package/dist/codec-descriptor-LT7BpQta-BaDM8UQQ.mjs.map +0 -1
  373. package/dist/codec-ids-Bqu_IwO0-DKOdPizQ.d.mts +0 -35
  374. package/dist/codec-ids-Bqu_IwO0-DKOdPizQ.d.mts.map +0 -1
  375. package/dist/codec-ids-C5Rkltkw-DMf87l9s.mjs +0 -35
  376. package/dist/codec-ids-C5Rkltkw-DMf87l9s.mjs.map +0 -1
  377. package/dist/codec-ids-DJ6j6pZc.d.mts +0 -1
  378. package/dist/codec-types-BRU4F-7t-BaJbKF_i.d.mts +0 -84
  379. package/dist/codec-types-BRU4F-7t-BaJbKF_i.d.mts.map +0 -1
  380. package/dist/codec-types-bX63JRLf.d.mts +0 -2
  381. package/dist/codecs-B1HgsJZ2.mjs +0 -15
  382. package/dist/codecs-B1HgsJZ2.mjs.map +0 -1
  383. package/dist/codecs-BmPCJWqb-DveZGJvm.mjs +0 -1680
  384. package/dist/codecs-BmPCJWqb-DveZGJvm.mjs.map +0 -1
  385. package/dist/codecs-D8tLswBi-_nbo-Z8x.d.mts +0 -638
  386. package/dist/codecs-D8tLswBi-_nbo-Z8x.d.mts.map +0 -1
  387. package/dist/codecs-DmCKO7dg.d.mts +0 -15
  388. package/dist/codecs-DmCKO7dg.d.mts.map +0 -1
  389. package/dist/column-types-BH-MU6uU.d.mts +0 -108
  390. package/dist/column-types-BH-MU6uU.d.mts.map +0 -1
  391. package/dist/column-types-Bh92dNjD.mjs +0 -126
  392. package/dist/column-types-Bh92dNjD.mjs.map +0 -1
  393. package/dist/contract-free-DzpGxLfb.d.mts.map +0 -1
  394. package/dist/contract-free-aQ4nT-_R.mjs.map +0 -1
  395. package/dist/control-2F195jJk.d.mts +0 -11
  396. package/dist/control-2F195jJk.d.mts.map +0 -1
  397. package/dist/control-BaUpALVp.d.mts.map +0 -1
  398. package/dist/control-DLTOAEHj.d.mts.map +0 -1
  399. package/dist/control-V7OkAC55.mjs +0 -1459
  400. package/dist/control-V7OkAC55.mjs.map +0 -1
  401. package/dist/control-Y6FxMu3o.mjs.map +0 -1
  402. package/dist/control-adapter-DFr4gS-r-DM3KcZdQ.mjs.map +0 -1
  403. package/dist/control-policy-B53lnBCT-B9K9Cj1x.mjs.map +0 -1
  404. package/dist/data-transform-BSM7TQpE.d.mts +0 -1
  405. package/dist/data-transform-ChZzy2dP-CxVCat_8.mjs.map +0 -1
  406. package/dist/data-transform-Ck5FbyNO-BNE7QlAo.d.mts.map +0 -1
  407. package/dist/ddl-B4Rh8ntj.d.mts +0 -1
  408. package/dist/ddl-CNQJds-C-WfZ3y4y8.mjs +0 -395
  409. package/dist/ddl-CNQJds-C-WfZ3y4y8.mjs.map +0 -1
  410. package/dist/default-normalizer-B36TOul4.d.mts +0 -31
  411. package/dist/default-normalizer-B36TOul4.d.mts.map +0 -1
  412. package/dist/default-normalizer-Ba5ZebHM-isV86rjy.mjs +0 -253
  413. package/dist/default-normalizer-Ba5ZebHM-isV86rjy.mjs.map +0 -1
  414. package/dist/descriptor-meta-KVX21fsl-DBDoB4eg.mjs +0 -354
  415. package/dist/descriptor-meta-KVX21fsl-DBDoB4eg.mjs.map +0 -1
  416. package/dist/descriptor-meta-rilAH3ep-dAmiVLpe.mjs +0 -30
  417. package/dist/descriptor-meta-rilAH3ep-dAmiVLpe.mjs.map +0 -1
  418. package/dist/descriptor-meta-runtime-UwYdV8fD-B_m_Ha8r.mjs +0 -13
  419. package/dist/descriptor-meta-runtime-UwYdV8fD-B_m_Ha8r.mjs.map +0 -1
  420. package/dist/diff-database-schema-DKq76rCk-uehceHYz.mjs.map +0 -1
  421. package/dist/diff-database-schema-DsoNznGC.d.mts.map +0 -1
  422. package/dist/driver__runtime.mjs.map +0 -1
  423. package/dist/errors-CU4xIwwk.d.mts.map +0 -1
  424. package/dist/errors-DKjQzNaN-DFcF1thx.mjs +0 -39
  425. package/dist/errors-DKjQzNaN-DFcF1thx.mjs.map +0 -1
  426. package/dist/issue-planner-Biq9Ls7e.d.mts.map +0 -1
  427. package/dist/migration-PTHAY9Cv.mjs.map +0 -1
  428. package/dist/migration-aFeTWTOJ.d.mts +0 -25
  429. package/dist/migration-aFeTWTOJ.d.mts.map +0 -1
  430. package/dist/namespace-ids-xtp_ZY86-Cpp8PTxD.mjs.map +0 -1
  431. package/dist/native-type-normalizer-DqJlOTeX.d.mts +0 -19
  432. package/dist/native-type-normalizer-DqJlOTeX.d.mts.map +0 -1
  433. package/dist/native-type-normalizer-yvd3tqv-.mjs +0 -38
  434. package/dist/native-type-normalizer-yvd3tqv-.mjs.map +0 -1
  435. package/dist/nodes-BU-V-aZA-RqwPH68u.d.mts.map +0 -1
  436. package/dist/nodes-DAvDJLvJ-BBdvFXNa.mjs.map +0 -1
  437. package/dist/normalize-error-CNjgVO71-CLlZ3CuJ.mjs.map +0 -1
  438. package/dist/op-factory-call-BAeyLFYf-BAgG1h1C.d.mts.map +0 -1
  439. package/dist/op-factory-call-BTU8I_x0.d.mts +0 -1
  440. package/dist/op-factory-call-H6zeDGLe-_1pAftJk.mjs.map +0 -1
  441. package/dist/operation-types-BfRocNI8.d.mts +0 -22
  442. package/dist/operation-types-BfRocNI8.d.mts.map +0 -1
  443. package/dist/pack-CySS3DQU.d.mts +0 -626
  444. package/dist/pack-CySS3DQU.d.mts.map +0 -1
  445. package/dist/planner-CT-7zSfk.d.mts.map +0 -1
  446. package/dist/planner-D0uogzvT-1WyGIC5p.mjs +0 -671
  447. package/dist/planner-D0uogzvT-1WyGIC5p.mjs.map +0 -1
  448. package/dist/planner-ddl-builders-Chxh-LEQ-DXvwOeeA.mjs +0 -102
  449. package/dist/planner-ddl-builders-Chxh-LEQ-DXvwOeeA.mjs.map +0 -1
  450. package/dist/planner-ddl-builders-ijp60-JO.d.mts +0 -19
  451. package/dist/planner-ddl-builders-ijp60-JO.d.mts.map +0 -1
  452. package/dist/planner-identity-values-BmHn5C6U-BYBbUAyR.mjs +0 -90
  453. package/dist/planner-identity-values-BmHn5C6U-BYBbUAyR.mjs.map +0 -1
  454. package/dist/planner-identity-values-TfEhnoWa.d.mts +0 -25
  455. package/dist/planner-identity-values-TfEhnoWa.d.mts.map +0 -1
  456. package/dist/planner-produced-postgres-migration-BaviT8KK-Yo9kw6rs.d.mts.map +0 -1
  457. package/dist/planner-produced-postgres-migration-D5m8nK6s-CbZ4hlbv.mjs.map +0 -1
  458. package/dist/planner-produced-postgres-migration-D6C0T2xV.d.mts +0 -1
  459. package/dist/planner-schema-lookup-C4DHAddq.d.mts.map +0 -1
  460. package/dist/planner-schema-lookup-kMIVP2y--CdO4VlnF.mjs.map +0 -1
  461. package/dist/planner-sql-checks-CFgbRTJw.d.mts +0 -20
  462. package/dist/planner-sql-checks-CFgbRTJw.d.mts.map +0 -1
  463. package/dist/planner-sql-checks-ftgzvIO9-BTtBg2Vz.mjs +0 -152
  464. package/dist/planner-sql-checks-ftgzvIO9-BTtBg2Vz.mjs.map +0 -1
  465. package/dist/planner-target-details-HkP4RrRO-_xPQVPF0.d.mts.map +0 -1
  466. package/dist/planner-type-resolution-Bt2f_q-F-C4T6YTae.mjs +0 -15
  467. package/dist/planner-type-resolution-Bt2f_q-F-C4T6YTae.mjs.map +0 -1
  468. package/dist/postgres-contract-view-2OP5JnXl-D2fpy4-8.d.mts.map +0 -1
  469. package/dist/postgres-contract-view-B8ykf2cO-T2LvWVFZ.mjs.map +0 -1
  470. package/dist/postgres-database-schema-node-CyfpHXDr-BqyozkQE.d.mts.map +0 -1
  471. package/dist/postgres-migration-BNsrwlxh-CwI5BqAu.d.mts.map +0 -1
  472. package/dist/postgres-migration-Dbq3RGfZ-aMnwfEAb.mjs +0 -205
  473. package/dist/postgres-migration-Dbq3RGfZ-aMnwfEAb.mjs.map +0 -1
  474. package/dist/postgres-native-enum-CdP3b_-R-Cgz9KEKx.mjs.map +0 -1
  475. package/dist/postgres-rls-policy-CnDxf3z9-C3LIHAIG.d.mts.map +0 -1
  476. package/dist/postgres-role-schema-node-B8Z5i5D--PObwlU2Z.mjs.map +0 -1
  477. package/dist/postgres-schema-CF0yHESb-D7n2X21R.mjs.map +0 -1
  478. package/dist/postgres-schema-Xsjt3RKO-Buv2X8ai.d.mts.map +0 -1
  479. package/dist/postgres-table-schema-node-BBkitBQh-DT1T5VWU.mjs.map +0 -1
  480. package/dist/render-ops-DOsRP0Po-BKn_c_Ia.mjs.map +0 -1
  481. package/dist/render-ops-DPwhZt2W.d.mts.map +0 -1
  482. package/dist/render-typescript-6sCFvMBh.d.mts.map +0 -1
  483. package/dist/render-typescript-Dqp1Spgn-B128r1qw.mjs.map +0 -1
  484. package/dist/resolve-ddl-schema-CoaeNP35-C-UZldpj.mjs +0 -22
  485. package/dist/resolve-ddl-schema-CoaeNP35-C-UZldpj.mjs.map +0 -1
  486. package/dist/runtime-DOXznQe0.d.mts.map +0 -1
  487. package/dist/runtime-_TfO66h5.d.mts.map +0 -1
  488. package/dist/runtime-lHBKgjB9.d.mts.map +0 -1
  489. package/dist/schema-ir-annotations-DuuYh0gl.d.mts.map +0 -1
  490. package/dist/schema-node-kinds-qlnURWJy-Bo30pwTM.d.mts.map +0 -1
  491. package/dist/sql-renderer-BgC0ZgLS.d.mts.map +0 -1
  492. package/dist/sql-renderer-ComgusFq-BBlqM1fw.mjs.map +0 -1
  493. package/dist/sql-utils-DW6fkczF.d.mts.map +0 -1
  494. package/dist/sql-utils-DuzN3JZg-DiXy4Vah.mjs.map +0 -1
  495. package/dist/table-source-ikHOZmhD-DriY1Lcr.d.mts.map +0 -1
  496. package/dist/types-B-4d5_4a.d.mts +0 -1
  497. package/dist/types-CjGjPLr5.d.mts.map +0 -1
  498. package/dist/types-CkryN1AS-BcQRGsDn.d.mts +0 -27
  499. package/dist/types-CkryN1AS-BcQRGsDn.d.mts.map +0 -1
  500. package/dist/types-ue6jkJyF-BQJzjx1P.d.mts.map +0 -1
  501. /package/dist/{adapter__operation-types.mjs → target__operation-types.mjs} +0 -0
@@ -0,0 +1,1143 @@
1
+ import { S as PG_TEXT_CODEC_ID } from "./codec-ids-BMhEpFwv-B8Zh0s_Q.mjs";
2
+ import { c as postgresError } from "./errors-BrhQYgdL-IvZHPjwL.mjs";
3
+ import { A as pgJsonb, i as createPostgresBuiltinDataTypeLookup, k as pgJson } from "./data-types-Chx0mjTP-DczU4S9b.mjs";
4
+ import { r as createPostgresBuiltinCodecLookup } from "./codec-registry-D7XslgPe-DTZnVB8W.mjs";
5
+ import { t as POLICY_BLOCK_KEYWORDS } from "./authoring-SbdvmVJh-nQ7YliD_.mjs";
6
+ import { t as postgresRenderCheckExpressions } from "./check-expressions-7uCCP01t-DtX2Vak9.mjs";
7
+ import { t as postgresDataTypeEntries } from "./data-type-entries-gQW3-KSb-BIl8vgus.mjs";
8
+ import { n as readPostgresDefault } from "./default-normalizer-BqK6XxdC-2OUb2ybG.mjs";
9
+ import { codecForRef, readContractValue } from "@prisma/orm-framework/components/codec";
10
+ import { blindCast } from "@prisma/orm-framework/utils/casts";
11
+ import { isInternalError } from "@prisma/orm-framework/utils/internal-error";
12
+ import { coordinateKey, elementCoordinates } from "@prisma/orm-framework/components/ir";
13
+ import { assertDefined } from "@prisma/orm-framework/utils/assertions";
14
+ import { composeCheckWirePrefix, computeCheckContentHash, computeIndexContentHash, formatWireName, parseWireName } from "@prisma/orm-family-sql/schema-ir/naming";
15
+ import { ifDefined } from "@prisma/orm-framework/utils/defined";
16
+ import { getAuthoringTypeConstructor, instantiateAuthoringTypeConstructor, validateAuthoringHelperArguments } from "@prisma/orm-framework/components/authoring";
17
+ import { NAME_THE_PSL_SOURCE_LOSES, isPslIdentifier } from "@prisma/orm-framework/psl-parser";
18
+ import { printSqlExpressionLiteral, sqlTextsReadBack, storedSqlText } from "@prisma/orm-family-sql/contract/sql-expression";
19
+ import { SqlSchemaIR, SqlTableIR } from "@prisma/orm-family-sql/schema-ir/types";
20
+ import { readReportedDefault } from "@prisma/orm-family-sql/family/control";
21
+ import { isColumnDefault } from "@prisma/orm-framework/contract/types";
22
+ import { inferColumnTypes, inferredTypeConstructors, mapDefault, toEnumMemberName } from "@prisma/orm-family-sql/family/psl-build";
23
+ import { buildChildRelationField, deriveRelationFieldName, inferRelations, toEnumName, toFieldName, toModelName } from "@prisma/orm-family-sql/family/psl-infer";
24
+ import { UNSPECIFIED_PSL_NAMESPACE_ID, makePslNamespace, makePslNamespaceEntries } from "@prisma/orm-framework/components/psl-ast";
25
+ import { escapePslString } from "@prisma/orm-family-sql/contract/data-type-support";
26
+ //#region ../../../3-targets/postgres/1-target/dist/infer-psl-contract-BSSHcuRi.mjs
27
+ const SYNTHETIC_SPAN = {
28
+ start: {
29
+ offset: 0,
30
+ line: 1,
31
+ column: 1
32
+ },
33
+ end: {
34
+ offset: 0,
35
+ line: 1,
36
+ column: 1
37
+ }
38
+ };
39
+ function buildSimpleConstraintFieldAttribute(name, constraintName) {
40
+ if (constraintName === void 0) return buildAttribute("field", name, []);
41
+ return buildAttribute("field", name, [namedArg("map", `"${escapePslString(constraintName)}"`)]);
42
+ }
43
+ function parseDefaultAttributeString(attributeText) {
44
+ return buildAttribute("field", "default", [positionalArg(attributeText.replace(/^@default\(/, "").replace(/\)$/, ""))]);
45
+ }
46
+ function buildMapAttribute(target, mapName) {
47
+ return buildAttribute(target, "map", [positionalArg(`"${escapePslString(mapName)}"`)]);
48
+ }
49
+ function buildAttribute(target, name, args) {
50
+ return {
51
+ kind: "attribute",
52
+ target,
53
+ name,
54
+ args,
55
+ span: SYNTHETIC_SPAN
56
+ };
57
+ }
58
+ function positionalArg(value) {
59
+ return {
60
+ kind: "positional",
61
+ value,
62
+ span: SYNTHETIC_SPAN
63
+ };
64
+ }
65
+ function namedArg(name, value) {
66
+ return {
67
+ kind: "named",
68
+ name,
69
+ value,
70
+ span: SYNTHETIC_SPAN
71
+ };
72
+ }
73
+ /**
74
+ * The codec reference `contract emit` builds for a column of `pslType`: the codec its type constructor names, with the type parameters the values of the call's arguments give. Infer writes each argument only when its literal reads back as that value. An enum column's default is a member name, which is text either way, so it reads through the text codec.
75
+ */
76
+ function inferredCodecRef(context, pslType, isEnum) {
77
+ if (isEnum) return { codecId: PG_TEXT_CODEC_ID };
78
+ const descriptor = getAuthoringTypeConstructor(context.authoringContributions, pslType.path);
79
+ if (descriptor === void 0) return void 0;
80
+ const args = pslType.values ?? [];
81
+ validateAuthoringHelperArguments(pslType.path.join("."), descriptor.args, args);
82
+ const { codecId, typeParams } = instantiateAuthoringTypeConstructor(descriptor, args);
83
+ return {
84
+ codecId,
85
+ ...ifDefined("typeParams", typeParams === void 0 ? void 0 : blindCast(typeParams))
86
+ };
87
+ }
88
+ /**
89
+ * The default checks for `context`. A default the codec refuses has no PSL literal, so the raw
90
+ * expression prints instead of a schema `contract emit` would reject. A column whose codec cannot be
91
+ * built with its type parameters is treated the same way. An `InternalError` is a bug, not a
92
+ * refusal, so it passes through.
93
+ *
94
+ * A data type says which values its column takes, not that every codec of it accepts each one: the
95
+ * temporal codecs represent types that cast from text but refuse `infinity`, which PostgreSQL stores
96
+ * and reports verbatim.
97
+ */
98
+ function inferredColumnDefaults(context) {
99
+ return {
100
+ codecOf(pslType, isEnum) {
101
+ try {
102
+ const ref = inferredCodecRef(context, pslType, isEnum);
103
+ return ref === void 0 ? void 0 : context.codecLookup.descriptorFor(ref.codecId);
104
+ } catch (error) {
105
+ if (isInternalError(error)) throw error;
106
+ return;
107
+ }
108
+ },
109
+ typeParamsOf(pslType, isEnum) {
110
+ try {
111
+ return inferredCodecRef(context, pslType, isEnum)?.typeParams;
112
+ } catch (error) {
113
+ if (isInternalError(error)) throw error;
114
+ return;
115
+ }
116
+ },
117
+ readsBack(value, pslType, isEnum, isList) {
118
+ const values = isList && Array.isArray(value) ? value : [value];
119
+ try {
120
+ const ref = inferredCodecRef(context, pslType, isEnum);
121
+ if (ref === void 0) return false;
122
+ const codec = codecForRef(context.codecLookup, ref);
123
+ if (codec === void 0) return false;
124
+ for (const element of values) readContractValue(codec, blindCast(element), ref.typeParams);
125
+ return true;
126
+ } catch (error) {
127
+ if (isInternalError(error)) throw error;
128
+ return false;
129
+ }
130
+ }
131
+ };
132
+ }
133
+ /** For a table whose columns have no literal default, such as a many-to-many junction table. */
134
+ const noColumnDefaults = {
135
+ codecOf: () => void 0,
136
+ typeParamsOf: () => void 0,
137
+ readsBack: () => false
138
+ };
139
+ /** `desiredName`, or it with the lowest number from 2 up that makes it unused. */
140
+ function createUniqueFieldName(desiredName, usedFieldNames) {
141
+ if (!usedFieldNames.has(desiredName)) return desiredName;
142
+ let counter = 2;
143
+ while (usedFieldNames.has(`${desiredName}${counter}`)) counter++;
144
+ return `${desiredName}${counter}`;
145
+ }
146
+ /** One `native_enum <name> { … }` block, with `@@map` when the type name differs from the block name. */
147
+ function buildNativeEnumBlock(name, typeName, values) {
148
+ const usedMemberNames = /* @__PURE__ */ new Set([NAME_THE_PSL_SOURCE_LOSES]);
149
+ return {
150
+ kind: "native_enum",
151
+ keyword: "native_enum",
152
+ name,
153
+ parameters: Object.fromEntries(values.map((value) => {
154
+ const memberName = createUniqueFieldName(toEnumMemberName(value), usedMemberNames);
155
+ usedMemberNames.add(memberName);
156
+ return [memberName, {
157
+ expression: JSON.stringify(value),
158
+ span: SYNTHETIC_SPAN
159
+ }];
160
+ })),
161
+ blockAttributes: name === typeName ? [] : [{
162
+ name: "map",
163
+ args: [{
164
+ kind: "positional",
165
+ value: `"${escapePslString(typeName)}"`,
166
+ span: SYNTHETIC_SPAN
167
+ }],
168
+ span: SYNTHETIC_SPAN
169
+ }],
170
+ span: SYNTHETIC_SPAN
171
+ };
172
+ }
173
+ function buildFieldNamesByTable(tables) {
174
+ const fieldNamesByTable = /* @__PURE__ */ new Map();
175
+ for (const table of Object.values(tables)) {
176
+ const assignmentOrder = [...Object.values(table.columns).map((column, index) => {
177
+ const { name, map } = toFieldName(column.name);
178
+ return {
179
+ columnName: column.name,
180
+ desiredFieldName: name,
181
+ fieldMap: map,
182
+ index
183
+ };
184
+ })].sort((left, right) => {
185
+ const mapComparison = Number(left.fieldMap !== void 0) - Number(right.fieldMap !== void 0);
186
+ if (mapComparison !== 0) return mapComparison;
187
+ return left.index - right.index;
188
+ });
189
+ const usedFieldNames = /* @__PURE__ */ new Set();
190
+ const tableFieldNames = /* @__PURE__ */ new Map();
191
+ for (const column of assignmentOrder) {
192
+ const fieldName = createUniqueFieldName(column.desiredFieldName, usedFieldNames);
193
+ usedFieldNames.add(fieldName);
194
+ tableFieldNames.set(column.columnName, {
195
+ fieldName,
196
+ fieldMap: column.fieldMap
197
+ });
198
+ }
199
+ fieldNamesByTable.set(table.name, tableFieldNames);
200
+ }
201
+ return fieldNamesByTable;
202
+ }
203
+ function resolveColumnFieldName(fieldNamesByTable, tableName, columnName) {
204
+ return fieldNamesByTable.get(tableName)?.get(columnName)?.fieldName ?? toFieldName(columnName).name;
205
+ }
206
+ function buildTopLevelNameMap(sources, normalize, kind, sourceKind) {
207
+ const results = /* @__PURE__ */ new Map();
208
+ const normalizedToSources = /* @__PURE__ */ new Map();
209
+ for (const source of sources) {
210
+ const normalized = normalize(source);
211
+ results.set(source, normalized);
212
+ normalizedToSources.set(normalized.name, [...normalizedToSources.get(normalized.name) ?? [], source]);
213
+ }
214
+ const duplicates = [...normalizedToSources.entries()].filter(([, conflictingSources]) => conflictingSources.length > 1);
215
+ if (duplicates.length > 0) throw postgresError("CONTRACT.NAME_DUPLICATE", `PSL ${kind} name collisions detected:\n${duplicates.map(([normalizedName, conflictingSources]) => `- ${kind} "${normalizedName}" from ${sourceKind}s ${conflictingSources.map((source) => `"${source}"`).join(", ")}`).join("\n")}`, { meta: {
216
+ kind,
217
+ names: duplicates.map(([normalizedName]) => normalizedName)
218
+ } });
219
+ return results;
220
+ }
221
+ function topologicalSort(models, tables, modelNameMap) {
222
+ const modelByName = /* @__PURE__ */ new Map();
223
+ for (const model of models) modelByName.set(model.name, model);
224
+ const deps = /* @__PURE__ */ new Map();
225
+ const tableToModel = /* @__PURE__ */ new Map();
226
+ for (const tableName of Object.keys(tables)) {
227
+ const modelName = modelNameMap.get(tableName);
228
+ assertDefined(modelName, `topologicalSort: no model name mapped for table "${tableName}"`);
229
+ tableToModel.set(tableName, modelName);
230
+ deps.set(modelName, /* @__PURE__ */ new Set());
231
+ }
232
+ for (const [tableName, table] of Object.entries(tables)) {
233
+ const modelName = tableToModel.get(tableName);
234
+ assertDefined(modelName, `topologicalSort: no model name recorded for table "${tableName}"`);
235
+ const modelDeps = deps.get(modelName);
236
+ assertDefined(modelDeps, `topologicalSort: no dependency set recorded for model "${modelName}"`);
237
+ for (const fk of table.foreignKeys) {
238
+ const refModelName = tableToModel.get(fk.referencedTable);
239
+ if (refModelName && refModelName !== modelName) modelDeps.add(refModelName);
240
+ }
241
+ }
242
+ const result = [];
243
+ const visited = /* @__PURE__ */ new Set();
244
+ const visiting = /* @__PURE__ */ new Set();
245
+ const sortedNames = [...deps.keys()].sort();
246
+ function visit(name) {
247
+ if (visited.has(name)) return;
248
+ if (visiting.has(name)) return;
249
+ visiting.add(name);
250
+ const nameDeps = deps.get(name);
251
+ assertDefined(nameDeps, `topologicalSort: no dependency set recorded for model "${name}"`);
252
+ const sortedDeps = [...nameDeps].sort();
253
+ for (const dep of sortedDeps) visit(dep);
254
+ visiting.delete(name);
255
+ visited.add(name);
256
+ const model = modelByName.get(name);
257
+ assertDefined(model, `topologicalSort: no model block recorded for "${name}"`);
258
+ result.push(model);
259
+ }
260
+ for (const name of sortedNames) visit(name);
261
+ return result;
262
+ }
263
+ const PSL_SCALAR_TYPE_NAMES = /* @__PURE__ */ new Set([
264
+ "String",
265
+ "Boolean",
266
+ "Int",
267
+ "BigInt",
268
+ "Float",
269
+ "Decimal",
270
+ "DateTime",
271
+ "Json",
272
+ "Bytes"
273
+ ]);
274
+ /**
275
+ * Builds one `native_enum` extension-block AST node per introspected enum
276
+ * definition. Block names go through the shared top-level transform
277
+ * (`toEnumName`, intra-enum collisions throw like model collisions) and are
278
+ * then reserved against the model names — an enum whose PSL name a model
279
+ * already claims gets a numeric suffix, with `@@map` carrying the real type
280
+ * name. Members print as explicit `member = "value"` pairs: the member name
281
+ * is the sanitized value (deduplicated within the block), the JSON-encoded
282
+ * value carries the truth verbatim.
283
+ */
284
+ function buildNativeEnumBlocks(definitions, modelNames) {
285
+ const enumNames = buildTopLevelNameMap([...definitions.keys()].sort(), toEnumName, "enum", "enum type");
286
+ const usedTopLevelNames = new Set(PSL_SCALAR_TYPE_NAMES);
287
+ for (const result of modelNames.values()) usedTopLevelNames.add(result.name);
288
+ const enumNameMap = /* @__PURE__ */ new Map();
289
+ const enumBlocks = [];
290
+ for (const [typeName, result] of enumNames) {
291
+ const name = createUniqueFieldName(result.name, usedTopLevelNames);
292
+ usedTopLevelNames.add(name);
293
+ enumNameMap.set(typeName, name);
294
+ enumBlocks.push(buildNativeEnumBlock(name, typeName, definitions.get(typeName) ?? []));
295
+ }
296
+ return {
297
+ enumNameMap,
298
+ enumBlocks
299
+ };
300
+ }
301
+ /**
302
+ * The name of the adopted native enum `column` is typed by: the database reported its type as an
303
+ * enum named in `enumTypeNames`, in `schemaName` when the output is wrapped in that schema's
304
+ * namespace. Undefined for any other column.
305
+ */
306
+ function adoptedEnumTypeName(column, enumTypeNames, schemaName) {
307
+ const reported = column.reportedType;
308
+ if (reported?.kind !== "enum" || reported.name === void 0) return void 0;
309
+ if (schemaName !== void 0 && reported.schema !== schemaName) return void 0;
310
+ return enumTypeNames.has(reported.name) ? reported.name : void 0;
311
+ }
312
+ /**
313
+ * Coordinates every element a set of already-assembled contracts declare,
314
+ * mapped to the {@link SqlDescribedContractSpace} that owns it and keyed by
315
+ * the shared {@link coordinateKey} helper. `contract infer` uses this to omit
316
+ * database elements a stack extension pack's contract space already
317
+ * describes — reusing the same coordinate walk the contract-space aggregate
318
+ * and cross-space collision check use (`elementCoordinates`), rather than a
319
+ * bespoke per-entity-kind membership test — and, for a foreign key whose
320
+ * referenced table an entry owns, to resolve the qualified cross-space
321
+ * relation it describes.
322
+ */
323
+ function describedContractOwners(describedContracts) {
324
+ const owners = /* @__PURE__ */ new Map();
325
+ for (const entry of describedContracts) for (const coordinate of elementCoordinates(entry.contract.storage)) owners.set(coordinateKey(coordinate), entry);
326
+ return owners;
327
+ }
328
+ function resolveCrossSpaceTarget(owner, namespaceId, tableName) {
329
+ const domainNamespace = owner.contract.domain.namespaces[namespaceId];
330
+ if (domainNamespace === void 0) return;
331
+ for (const [modelName, model] of Object.entries(domainNamespace.models)) {
332
+ const storage = blindCast(model.storage);
333
+ if (storage.namespaceId !== namespaceId || storage.table !== tableName) continue;
334
+ const fieldNamesByColumn = /* @__PURE__ */ new Map();
335
+ for (const [fieldName, fieldStorage] of Object.entries(storage.fields)) fieldNamesByColumn.set(fieldStorage.column, { fieldName });
336
+ return {
337
+ spaceId: owner.spaceId,
338
+ namespaceId,
339
+ modelName,
340
+ fieldNamesByColumn
341
+ };
342
+ }
343
+ }
344
+ /**
345
+ * Classifies every foreign key on a surviving table into one of three cases.
346
+ * A foreign key that carries a `referencedSchema` is checked against the
347
+ * pack-owned coordinates first, so a pack-owned target wins even when a local
348
+ * table happens to share its bare name; only foreign keys with no owned
349
+ * coordinate fall through to the local/dangling distinction.
350
+ *
351
+ * - **Cross-space**: `referencedSchema` is set and a described contract owns
352
+ * the coordinate `(referencedSchema, 'table', referencedTable)`. The
353
+ * referenced table is absent from the tree (omitted because the pack
354
+ * describes it, or never introspected — `contract infer` walks a single
355
+ * namespace). Removed from `foreignKeys` (so `inferRelations` never falls
356
+ * back to a bare, unqualified table name for it) and replaced with a
357
+ * `RelationField` qualified with the owning pack's space id and namespace
358
+ * id. `owners` holds only pack-declared coordinates, so an app's own table
359
+ * (e.g. `public.users`) is never owned and cannot be captured here.
360
+ * - **Local**: not a pack-owned coordinate, and the referenced table survived
361
+ * introspection — left untouched, `inferRelations` handles it as before.
362
+ * - **Dangling**: not a pack-owned coordinate, and the referenced table is
363
+ * neither in the tree nor owned by any described contract. Removed from
364
+ * `foreignKeys`, keeping the scalar column, rather than emitting a relation
365
+ * to a model that was never defined.
366
+ *
367
+ * A pack that owns the referenced coordinate but declares no domain model
368
+ * mapped to it is malformed; that case throws rather than degrading to a
369
+ * silent drop, which would contradict the dangling definition above.
370
+ */
371
+ function resolveForeignKeys(tables, owners) {
372
+ const resultTables = {};
373
+ const extraRelationsByTable = /* @__PURE__ */ new Map();
374
+ const crossSpaceFieldNamesByTable = /* @__PURE__ */ new Map();
375
+ const danglingForeignKeysByTable = /* @__PURE__ */ new Map();
376
+ for (const [tableName, table] of Object.entries(tables)) {
377
+ const keptForeignKeys = [];
378
+ for (const fk of table.foreignKeys) {
379
+ if (fk.referencedSchema !== void 0) {
380
+ const owner = owners.get(coordinateKey({
381
+ namespaceId: fk.referencedSchema,
382
+ entityKind: "table",
383
+ entityName: fk.referencedTable
384
+ }));
385
+ if (owner !== void 0) {
386
+ const target = resolveCrossSpaceTarget(owner, fk.referencedSchema, fk.referencedTable);
387
+ if (target === void 0) throw postgresError("CONTRACT.PACK_CONTRIBUTION_INVALID", `contract infer: described contract space "${owner.spaceId}" owns storage coordinate "${fk.referencedSchema}.${fk.referencedTable}" but declares no domain model mapped to it. A pack that describes a table must also declare the domain model it maps to; this pack is malformed.`, { meta: {
388
+ spaceId: owner.spaceId,
389
+ tableName: fk.referencedTable
390
+ } });
391
+ if (!crossSpaceFieldNamesByTable.has(fk.referencedTable)) crossSpaceFieldNamesByTable.set(fk.referencedTable, target.fieldNamesByColumn);
392
+ const fieldName = deriveRelationFieldName(fk.columns, fk.referencedTable);
393
+ const optional = fk.columns.some((columnName) => table.columns[columnName]?.nullable ?? false);
394
+ const relationField = {
395
+ ...buildChildRelationField(fieldName, target.modelName, fk, optional, void 0, table),
396
+ typeNamespaceId: target.namespaceId,
397
+ typeContractSpaceId: target.spaceId
398
+ };
399
+ const existingRelations = extraRelationsByTable.get(tableName);
400
+ if (existingRelations) existingRelations.push(relationField);
401
+ else extraRelationsByTable.set(tableName, [relationField]);
402
+ continue;
403
+ }
404
+ }
405
+ if (tables[fk.referencedTable] !== void 0) keptForeignKeys.push(fk);
406
+ else {
407
+ const dangling = {
408
+ columns: fk.columns,
409
+ referencedSchema: fk.referencedSchema,
410
+ referencedTable: fk.referencedTable
411
+ };
412
+ const existingDangling = danglingForeignKeysByTable.get(tableName);
413
+ if (existingDangling) existingDangling.push(dangling);
414
+ else danglingForeignKeysByTable.set(tableName, [dangling]);
415
+ }
416
+ }
417
+ resultTables[tableName] = keptForeignKeys.length === table.foreignKeys.length ? table : new SqlTableIR({
418
+ ...table,
419
+ foreignKeys: keptForeignKeys
420
+ });
421
+ }
422
+ return {
423
+ tables: resultTables,
424
+ extraRelationsByTable,
425
+ crossSpaceFieldNamesByTable,
426
+ danglingForeignKeysByTable
427
+ };
428
+ }
429
+ /**
430
+ * Explains a foreign key `resolveForeignKeys` dropped as dangling: the
431
+ * database enforces it, but its target lives outside the introspected
432
+ * schema, so infer has no model to point a relation at. The suggested fix
433
+ * targets the common cause — an unconfigured extension pack's schema
434
+ * (e.g. Supabase's `auth`).
435
+ */
436
+ function buildDanglingForeignKeyWarning(danglingForeignKeys, fieldNamesByTable, tableName) {
437
+ return `Foreign key ${danglingForeignKeys.map((fk) => {
438
+ const fieldNames = fk.columns.map((columnName) => resolveColumnFieldName(fieldNamesByTable, tableName, columnName));
439
+ const target = fk.referencedSchema !== void 0 ? `${fk.referencedSchema}.${fk.referencedTable}` : fk.referencedTable;
440
+ return `"${fieldNames.join(", ")}" -> "${target}"`;
441
+ }).join(", ")} exists in the database, but its target schema is outside the introspected scope, so no relation field was generated. If the target schema is described by an extension pack, add it to extensions and re-run infer.`;
442
+ }
443
+ function buildModelConstraintAttribute(name, fields, constraintName) {
444
+ const args = [positionalArg(`[${fields.join(", ")}]`)];
445
+ if (constraintName !== void 0) args.push(namedArg("map", `"${escapePslString(constraintName)}"`));
446
+ return buildAttribute("model", name, args);
447
+ }
448
+ /**
449
+ * The naming of a live index, re-detected rather than trusted: wire when the
450
+ * live name parses as a wire name AND that hash recomputes from the
451
+ * introspected content; otherwise exact.
452
+ */
453
+ function detectIndexNaming(index) {
454
+ const parsed = parseWireName(index.name);
455
+ const recomputed = computeIndexContentHash({
456
+ ...index.columns !== void 0 ? { columns: index.columns } : {},
457
+ ...index.expression !== void 0 ? { expression: index.expression } : {},
458
+ ...index.where !== void 0 ? { where: index.where } : {},
459
+ unique: index.unique,
460
+ ...index.type !== void 0 ? { type: index.type } : {},
461
+ ...index.options !== void 0 ? { options: index.options } : {}
462
+ });
463
+ return parsed !== void 0 && parsed.hash === recomputed ? {
464
+ kind: "wire",
465
+ prefix: parsed.prefix
466
+ } : { kind: "exact" };
467
+ }
468
+ function namingArg(naming, exactName) {
469
+ return naming.kind === "wire" ? namedArg("name", `"${escapePslString(naming.prefix)}"`) : namedArg("map", `"${escapePslString(exactName)}"`);
470
+ }
471
+ /**
472
+ * Emits one `@@index` attribute at full fidelity, named as `naming` says;
473
+ * without it, the naming is re-detected from the live name and content.
474
+ */
475
+ function buildIndexAttribute(index, fieldNames, naming = detectIndexNaming(index)) {
476
+ const args = [];
477
+ if (fieldNames !== void 0) args.push(positionalArg(`[${fieldNames.join(", ")}]`));
478
+ else {
479
+ assertDefined(index.expression, `buildIndexAttribute: index "${index.name}" carries neither columns nor expression; SqlIndexIR enforces exactly one`);
480
+ args.push(namedArg("expression", printSqlExpressionLiteral(index.expression)));
481
+ }
482
+ args.push(namingArg(naming, index.name));
483
+ if (index.where !== void 0) args.push(namedArg("where", printSqlExpressionLiteral(index.where)));
484
+ if (index.unique) args.push(namedArg("unique", "true"));
485
+ if (index.type !== void 0 || index.options !== void 0) args.push(namedArg("type", `"${escapePslString(index.type ?? "btree")}"`));
486
+ if (index.options !== void 0) {
487
+ const entries = Object.entries(index.options ?? {}).sort(([a], [b]) => a < b ? -1 : a > b ? 1 : 0).map(([key, value]) => `${key}: "${escapePslString(String(value))}"`);
488
+ args.push(namedArg("options", `{ ${entries.join(", ")} }`));
489
+ }
490
+ return buildAttribute("model", "index", args);
491
+ }
492
+ /**
493
+ * Emits one `@@fullTextIndex` attribute. A weight group of one field is written as the bare field,
494
+ * a larger group as a list, and the language only when it is not the default.
495
+ */
496
+ function buildFullTextIndexAttribute(index, definition, fieldNameOf, naming) {
497
+ const args = [positionalArg(`[${definition.weightGroups.map((group) => {
498
+ const names = group.map(fieldNameOf);
499
+ return names.length === 1 ? names[0] ?? "" : `[${names.join(", ")}]`;
500
+ }).join(", ")}]`), namingArg(naming, index.name)];
501
+ if (definition.language !== "english") args.push(namedArg("language", `"${definition.language}"`));
502
+ if (index.where !== void 0) args.push(namedArg("where", printSqlExpressionLiteral(index.where)));
503
+ return buildAttribute("model", "fullTextIndex", args);
504
+ }
505
+ /**
506
+ * Emits one `@@check` attribute, named as `naming` says. Without it, a live,
507
+ * non-derived check is written in the `map:` form. Re-detecting `name:` is not
508
+ * attempted there: the live expression is Postgres's own reprint, but a
509
+ * wire-named check's hash was taken over the author's original text, so
510
+ * recomputing the hash from the reprint would essentially never match. `map:`
511
+ * plus the verbatim reprint is correct regardless — a reprint compared against
512
+ * a later reprint of the same expression is stable, so the emitted contract
513
+ * signs the live database with zero pending operations. `buildIntrospectedPolicyBlocks`
514
+ * makes the same call for `@@map` on adopted RLS policies, for the same reason.
515
+ */
516
+ function buildCheckAttribute(check, naming = { kind: "exact" }) {
517
+ return buildAttribute("model", "check", [namedArg("expression", printSqlExpressionLiteral(check.expression)), namingArg(naming, check.name)]);
518
+ }
519
+ /** Why `contract infer` skips an exact-named object whose SQL a `sql` literal would change. */
520
+ const SQL_DOES_NOT_READ_BACK = "its SQL cannot be written as a sql literal that reads back unchanged. It is not in this schema, so migration plan will drop it. A sql literal written by hand holds different text, so migration plan then stops with a conflict for an index or check, or drops and recreates a policy. Either change the SQL in the database to the text of the literal, or add the object without map: or @@map so Prisma names it.";
521
+ /** The note on a model whose column default `contract infer` printed as a `sql` literal that reads back as different text. */
522
+ function defaultDoesNotReadBackNote(column) {
523
+ return `// prisma: default of "${column}" holds text a sql literal cannot write back unchanged; check its string constants before applying a migration`;
524
+ }
525
+ /**
526
+ * The index as `contract infer` prints it, or `undefined` when it is skipped. An exact-named index
527
+ * is compared byte for byte, so its SQL must read back unchanged. A wire-named index is compared by
528
+ * name, and its canonical SQL hashes to the same name, so it is printed with that text.
529
+ */
530
+ function printableIndex(index) {
531
+ if (sqlTextsReadBack([index.expression, index.where])) return index;
532
+ const expression = index.expression === void 0 ? void 0 : storedSqlText(index.expression);
533
+ const where = index.where === void 0 ? void 0 : storedSqlText(index.where);
534
+ if (expression === void 0 && index.expression !== void 0) return void 0;
535
+ if (where === void 0 && index.where !== void 0) return void 0;
536
+ const canonical = {
537
+ ...index,
538
+ ...expression !== void 0 ? { expression } : {},
539
+ ...where !== void 0 ? { where } : {}
540
+ };
541
+ return detectIndexNaming(canonical).kind === "wire" ? canonical : void 0;
542
+ }
543
+ function buildModel(table, columnTypes, enumNameOf, fieldNamesByTable, defaultMapping, defaultOf, columnDefaults, relationFields, danglingForeignKeys, rlsEnabled = false, policySkipNotes = []) {
544
+ const { name: modelName, map: mapName } = toModelName(table.name);
545
+ const fieldNameMap = fieldNamesByTable.get(table.name);
546
+ const pkColumns = new Set(table.primaryKey?.columns ?? []);
547
+ const isSinglePk = pkColumns.size === 1;
548
+ const singlePkConstraintName = isSinglePk ? table.primaryKey?.name : void 0;
549
+ const uniqueColumns = /* @__PURE__ */ new Map();
550
+ for (const unique of table.uniques) if (unique.columns.length === 1) {
551
+ const [columnName = ""] = unique.columns;
552
+ const existingConstraintName = uniqueColumns.get(columnName);
553
+ if (!uniqueColumns.has(columnName) || existingConstraintName === void 0 && unique.name) uniqueColumns.set(columnName, unique.name);
554
+ }
555
+ const derivedCheckNames = computeDerivedCheckNames(table);
556
+ const defaultNotes = [];
557
+ const fields = [];
558
+ for (const column of Object.values(table.columns)) fields.push(buildScalarField(column, table, columnTypes, enumNameOf, fieldNameMap, defaultMapping, defaultOf, columnDefaults, pkColumns, isSinglePk, singlePkConstraintName, uniqueColumns, derivedCheckNames, () => defaultNotes.push(defaultDoesNotReadBackNote(column.name))));
559
+ const usedFieldNames = new Set(fields.map((field) => field.name));
560
+ for (const rel of relationFields) fields.push(buildRelationField(rel, table.name, fieldNamesByTable, usedFieldNames));
561
+ const modelAttributes = [];
562
+ if (table.primaryKey && table.primaryKey.columns.length > 1) {
563
+ const pkFieldNames = table.primaryKey.columns.map((columnName) => resolveColumnFieldName(fieldNamesByTable, table.name, columnName));
564
+ modelAttributes.push(buildModelConstraintAttribute("id", pkFieldNames, table.primaryKey.name));
565
+ }
566
+ for (const unique of table.uniques) if (unique.columns.length > 1) {
567
+ const uniqueFieldNames = unique.columns.map((columnName) => resolveColumnFieldName(fieldNamesByTable, table.name, columnName));
568
+ modelAttributes.push(buildModelConstraintAttribute("unique", uniqueFieldNames, unique.name));
569
+ }
570
+ const sqlSkipNotes = [];
571
+ const skipNote = (kind, name) => sqlSkipNotes.push(`// prisma: skipped ${kind} "${name}": ${SQL_DOES_NOT_READ_BACK}`);
572
+ for (const index of table.indexes) {
573
+ const printable = printableIndex(index);
574
+ if (printable === void 0) {
575
+ skipNote("index", index.name);
576
+ continue;
577
+ }
578
+ const indexFieldNames = printable.columns?.map((columnName) => resolveColumnFieldName(fieldNamesByTable, table.name, columnName));
579
+ modelAttributes.push(buildIndexAttribute(printable, indexFieldNames));
580
+ }
581
+ for (const check of table.checks ?? []) {
582
+ if (derivedCheckNames.has(check.name)) continue;
583
+ if (!sqlTextsReadBack([check.expression])) {
584
+ skipNote("check", check.name);
585
+ continue;
586
+ }
587
+ modelAttributes.push(buildCheckAttribute(check));
588
+ }
589
+ if (mapName) modelAttributes.push(buildMapAttribute("model", mapName));
590
+ if (rlsEnabled) modelAttributes.push(buildAttribute("model", "rls", []));
591
+ const warnings = [];
592
+ if (!table.primaryKey) warnings.push("This table has no primary key in the database");
593
+ if (danglingForeignKeys.length > 0) warnings.push(buildDanglingForeignKeyWarning(danglingForeignKeys, fieldNamesByTable, table.name));
594
+ const commentLines = [
595
+ ...warnings.length > 0 ? [`// WARNING: ${warnings.join(" ")}`] : [],
596
+ ...policySkipNotes,
597
+ ...sqlSkipNotes,
598
+ ...defaultNotes
599
+ ];
600
+ const comment = commentLines.length > 0 ? commentLines.join("\n") : void 0;
601
+ return {
602
+ kind: "model",
603
+ name: modelName,
604
+ fields,
605
+ attributes: modelAttributes,
606
+ span: SYNTHETIC_SPAN,
607
+ ...comment !== void 0 ? { comment } : {}
608
+ };
609
+ }
610
+ /**
611
+ * The live check names that are derived: a live check's name matches `formatWireName(composeCheckWirePrefix(table, column, kind), computeCheckContentHash(expression))` for some column of the table and some candidate `postgresRenderCheckExpressions` would render for that column. Never by comparing expressions — the live body is a Postgres reprint, never the authored text. One set serves both the element nullability of list fields and `@@check` exclusion in `buildModel`, so the two decisions cannot drift apart.
612
+ *
613
+ * `membership` is unreachable here today: infer never emits domain enums (`enumType()` is not inferred), so no inferred column has member values and no membership check is ever derived. Inferring domain enums would mean threading the column's member values through here.
614
+ */
615
+ function computeDerivedCheckNames(table) {
616
+ const liveCheckNames = new Set((table.checks ?? []).map((check) => check.name));
617
+ const derivedCheckNames = /* @__PURE__ */ new Set();
618
+ for (const column of Object.values(table.columns)) for (const candidate of postgresRenderCheckExpressions({
619
+ tableName: table.name,
620
+ columnName: column.name,
621
+ many: column.many === true,
622
+ memberValues: void 0
623
+ })) {
624
+ const derivedName = formatWireName(composeCheckWirePrefix(table.name, column.name, candidate.kind), computeCheckContentHash(candidate.expression));
625
+ if (liveCheckNames.has(derivedName)) derivedCheckNames.add(derivedName);
626
+ }
627
+ return derivedCheckNames;
628
+ }
629
+ function buildScalarField(column, table, columnTypes, enumNameOf, fieldNameMap, defaultMapping, defaultOf, columnDefaults, pkColumns, isSinglePk, singlePkConstraintName, uniqueColumns, derivedCheckNames, noteDefaultThatDoesNotReadBack) {
630
+ const resolvedField = fieldNameMap?.get(column.name);
631
+ const fieldName = resolvedField?.fieldName ?? toFieldName(column.name).name;
632
+ const fieldMap = resolvedField?.fieldMap;
633
+ const enumPslName = enumNameOf(column);
634
+ const pslType = enumPslName === void 0 ? columnTypes(table.name, column.name) : {
635
+ path: [enumPslName],
636
+ args: [],
637
+ values: []
638
+ };
639
+ const typeName = pslType.path.join(".");
640
+ const typeConstructor = enumPslName !== void 0 ? {
641
+ kind: "typeConstructor",
642
+ path: ["pg", "enum"],
643
+ args: [positionalArg(enumPslName)],
644
+ span: SYNTHETIC_SPAN
645
+ } : pslType.args.length > 0 || pslType.path.length > 1 ? {
646
+ kind: "typeConstructor",
647
+ path: pslType.path,
648
+ args: pslType.args.map(positionalArg),
649
+ span: SYNTHETIC_SPAN
650
+ } : void 0;
651
+ const attributes = [];
652
+ const isId = isSinglePk && pkColumns.has(column.name);
653
+ if (isId) attributes.push(buildSimpleConstraintFieldAttribute("id", singlePkConstraintName));
654
+ const isEnumColumn = enumPslName !== void 0;
655
+ const defaultAttribute = inferDefaultAttribute(column, defaultOf(table.name, column), {
656
+ ...defaultMapping,
657
+ ...ifDefined("columnCodec", columnDefaults.codecOf(pslType, isEnumColumn)),
658
+ ...ifDefined("typeParams", columnDefaults.typeParamsOf(pslType, isEnumColumn)),
659
+ list: column.many === true
660
+ }, (value) => columnDefaults.readsBack(value, pslType, isEnumColumn, column.many === true), noteDefaultThatDoesNotReadBack);
661
+ if (defaultAttribute !== void 0) attributes.push(parseDefaultAttributeString(defaultAttribute));
662
+ if (uniqueColumns.has(column.name) && !isId) {
663
+ const uniqueConstraintName = uniqueColumns.get(column.name);
664
+ attributes.push(buildSimpleConstraintFieldAttribute("unique", uniqueConstraintName));
665
+ }
666
+ if (fieldMap !== void 0) attributes.push(buildMapAttribute("field", fieldMap));
667
+ return {
668
+ kind: "field",
669
+ name: fieldName,
670
+ typeName,
671
+ ...ifDefined("typeConstructor", typeConstructor),
672
+ optional: column.nullable,
673
+ list: column.many === true,
674
+ ...ifDefined("elementOptional", column.many === true && !enforcesElementNotNull(table, column, derivedCheckNames) ? true : void 0),
675
+ attributes,
676
+ span: SYNTHETIC_SPAN
677
+ };
678
+ }
679
+ function enforcesElementNotNull(table, column, derivedCheckNames) {
680
+ return postgresRenderCheckExpressions({
681
+ tableName: table.name,
682
+ columnName: column.name,
683
+ many: true,
684
+ memberValues: void 0
685
+ }).some((candidate) => candidate.kind === "elementNotNull" && derivedCheckNames.has(formatWireName(composeCheckWirePrefix(table.name, column.name, candidate.kind), computeCheckContentHash(candidate.expression))));
686
+ }
687
+ /**
688
+ * A literal default prints as the PSL literal the column's data type takes. A literal that has no
689
+ * such PSL literal prints as a `sql` tagged literal holding the expression Postgres reported.
690
+ */
691
+ function inferDefaultAttribute(column, read, defaultMapping, readsBack, noteTextThatDoesNotReadBack) {
692
+ if (column.default === void 0 && column.resolvedDefault?.kind === "function" && column.resolvedDefault.expression === "autoincrement()") return "@default(autoincrement())";
693
+ if (read === void 0) return void 0;
694
+ if (read.kind === "function") return mappedAttribute(read, defaultMapping, noteTextThatDoesNotReadBack);
695
+ if (column.many === true && !Array.isArray(read.value)) return void 0;
696
+ return literalOrRawAttribute(read, column, defaultMapping, readsBack, noteTextThatDoesNotReadBack);
697
+ }
698
+ /**
699
+ * A literal no data type the column takes writes, or that the column's codec does not read back,
700
+ * has no PSL literal, so the raw database default prints instead.
701
+ */
702
+ function literalOrRawAttribute(columnDefault, column, defaultMapping, readsBack, noteTextThatDoesNotReadBack) {
703
+ const printed = columnDefault;
704
+ const result = printed.kind === "literal" && !readsBack(printed.value) ? void 0 : mapDefault(printed, defaultMapping);
705
+ if (result !== void 0) return result.attribute;
706
+ return typeof column.default === "string" ? mappedAttribute({
707
+ kind: "function",
708
+ expression: column.default
709
+ }, defaultMapping, noteTextThatDoesNotReadBack) : void 0;
710
+ }
711
+ /**
712
+ * A default expression prints even when its `sql` literal reads back as different text: dropping it
713
+ * would let the next plan drop the default. The caller notes it instead.
714
+ */
715
+ function mappedAttribute(columnDefault, defaultMapping, noteTextThatDoesNotReadBack) {
716
+ if (columnDefault.kind === "function" && !sqlTextsReadBack([columnDefault.expression])) noteTextThatDoesNotReadBack();
717
+ return mapDefault(columnDefault, defaultMapping)?.attribute;
718
+ }
719
+ function buildRelationField(rel, hostTableName, fieldNamesByTable, usedFieldNames) {
720
+ const fieldName = createUniqueFieldName(rel.fieldName, usedFieldNames);
721
+ usedFieldNames.add(fieldName);
722
+ const args = [];
723
+ if (rel.fields && rel.references) {
724
+ if (rel.relationName) args.push(namedArg("name", `"${escapePslString(rel.relationName)}"`));
725
+ args.push(namedArg("fields", `[${rel.fields.map((columnName) => resolveColumnFieldName(fieldNamesByTable, hostTableName, columnName)).join(", ")}]`));
726
+ args.push(namedArg("references", `[${rel.references.map((columnName) => resolveColumnFieldName(fieldNamesByTable, rel.referencedTableName ?? "", columnName)).join(", ")}]`));
727
+ if (rel.onDelete) args.push(namedArg("onDelete", rel.onDelete));
728
+ if (rel.onUpdate) args.push(namedArg("onUpdate", rel.onUpdate));
729
+ if (rel.fkName) args.push(namedArg("map", `"${escapePslString(rel.fkName)}"`));
730
+ if (rel.index === false) args.push(namedArg("index", "false"));
731
+ else if (rel.index !== void 0) args.push(namedArg("index", `"${escapePslString(rel.index)}"`));
732
+ } else if (rel.relationName) args.push(namedArg("name", `"${escapePslString(rel.relationName)}"`));
733
+ const attrs = args.length > 0 ? [buildAttribute("field", "relation", args)] : [];
734
+ return {
735
+ kind: "field",
736
+ name: fieldName,
737
+ typeName: rel.typeName,
738
+ ...ifDefined("typeNamespaceId", rel.typeNamespaceId),
739
+ ...ifDefined("typeContractSpaceId", rel.typeContractSpaceId),
740
+ optional: rel.optional,
741
+ list: rel.list,
742
+ attributes: attrs,
743
+ span: SYNTHETIC_SPAN
744
+ };
745
+ }
746
+ /** Replaces invalid character runs with `_`; prepends `_` when the first character is invalid. */
747
+ function sanitizePolicyHead(raw) {
748
+ let head = raw.replace(/[^\p{L}\p{N}_-]+/gu, "_");
749
+ if (!/^[\p{L}_]/u.test(head)) head = `_${head}`;
750
+ return head;
751
+ }
752
+ /**
753
+ * Builds one `policy_<operation>` block per introspected policy. Every
754
+ * adopted policy is exact-named: a reprinted body never reliably re-hashes to
755
+ * the live suffix, so `@@map` always carries the physical name and the head
756
+ * is only an identifier. A policy granting to a role whose name is not a
757
+ * legal identifier cannot be authored at all — role references have no
758
+ * `@@map` escape — so it is skipped with a note.
759
+ */
760
+ function buildIntrospectedPolicyBlocks(policiesByTable, modelNameMap, reservedHeads = /* @__PURE__ */ new Set()) {
761
+ const all = [];
762
+ for (const [tableName, policies] of policiesByTable) for (const policy of policies) all.push({
763
+ policy,
764
+ tableName
765
+ });
766
+ all.sort((a, b) => {
767
+ if (a.policy.name !== b.policy.name) return a.policy.name < b.policy.name ? -1 : 1;
768
+ if (a.tableName !== b.tableName) return a.tableName < b.tableName ? -1 : 1;
769
+ return a.policy.operation < b.policy.operation ? -1 : a.policy.operation > b.policy.operation ? 1 : 0;
770
+ });
771
+ const usedHeads = new Set(reservedHeads);
772
+ const blocks = [];
773
+ const skipNotesByTable = /* @__PURE__ */ new Map();
774
+ for (const { policy, tableName } of all) {
775
+ const modelName = modelNameMap.get(tableName);
776
+ assertDefined(modelName, `buildIntrospectedPolicyBlocks: policy "${policy.name}" targets table "${tableName}" with no emitted model; tables and policies come from the same introspection walk`);
777
+ const skipNote = (reason) => {
778
+ const notes = skipNotesByTable.get(tableName) ?? [];
779
+ notes.push(`// prisma: skipped policy "${policy.name}": ${reason}`);
780
+ skipNotesByTable.set(tableName, notes);
781
+ };
782
+ const badRole = policy.roles.find((role) => !isPslIdentifier(role));
783
+ if (badRole !== void 0) {
784
+ skipNote(`role "${badRole}" is not a valid PSL identifier and role references cannot be escaped`);
785
+ continue;
786
+ }
787
+ if (!sqlTextsReadBack([policy.using, policy.withCheck])) {
788
+ skipNote(SQL_DOES_NOT_READ_BACK);
789
+ continue;
790
+ }
791
+ let head = sanitizePolicyHead(parseWireName(policy.name)?.prefix ?? policy.name);
792
+ if (usedHeads.has(head)) {
793
+ let n = 2;
794
+ while (usedHeads.has(`${head}_${n}`)) n += 1;
795
+ head = `${head}_${n}`;
796
+ }
797
+ usedHeads.add(head);
798
+ blocks.push({
799
+ kind: "policy",
800
+ keyword: POLICY_BLOCK_KEYWORDS[policy.operation],
801
+ name: head,
802
+ parameters: {
803
+ target: {
804
+ expression: modelName,
805
+ span: SYNTHETIC_SPAN
806
+ },
807
+ roles: {
808
+ expression: `[${policy.roles.join(", ")}]`,
809
+ span: SYNTHETIC_SPAN
810
+ },
811
+ ...policy.using !== void 0 ? { using: {
812
+ expression: printSqlExpressionLiteral(policy.using),
813
+ span: SYNTHETIC_SPAN
814
+ } } : {},
815
+ ...policy.withCheck !== void 0 ? { withCheck: {
816
+ expression: printSqlExpressionLiteral(policy.withCheck),
817
+ span: SYNTHETIC_SPAN
818
+ } } : {},
819
+ ...policy.permissive ? {} : { permissive: {
820
+ expression: "false",
821
+ span: SYNTHETIC_SPAN
822
+ } }
823
+ },
824
+ blockAttributes: [{
825
+ name: "map",
826
+ args: [{
827
+ kind: "positional",
828
+ value: `"${escapePslString(policy.name)}"`,
829
+ span: SYNTHETIC_SPAN
830
+ }],
831
+ span: SYNTHETIC_SPAN
832
+ }],
833
+ span: SYNTHETIC_SPAN
834
+ });
835
+ }
836
+ return {
837
+ blocks,
838
+ skipNotesByTable
839
+ };
840
+ }
841
+ const DECIMAL_PARTS_PATTERN = /^(-?)(\d+)(?:\.(\d+))?(?:[eE]([+-]?\d+))?$/;
842
+ /** A numeral's value as `<sign><digits>e<exponent>`, with no leading or trailing zero digits. */
843
+ function decimalValue(numeral) {
844
+ const parts = DECIMAL_PARTS_PATTERN.exec(numeral);
845
+ if (parts === null) return void 0;
846
+ const [, sign = "", whole = "", fraction = "", exponent = "0"] = parts;
847
+ const digits = `${whole}${fraction}`.replace(/^0+/, "");
848
+ if (digits === "") return "0";
849
+ const significant = digits.replace(/0+$/, "");
850
+ return `${sign}${significant}e${Number(exponent) - fraction.length + digits.length - significant.length}`;
851
+ }
852
+ function keepsJsonNumber(value, source) {
853
+ if (!Number.isFinite(value) || source === void 0) return false;
854
+ const written = decimalValue(source);
855
+ return written !== void 0 && written === decimalValue(String(value));
856
+ }
857
+ /**
858
+ * Whether every number in the JSON text keeps its value once read into a JavaScript number. Postgres keeps every digit of a json number, and the JSON codecs read one into a JavaScript number, so a document holding `12345678901234567890` or `1e400` would print back as another document. `1.0` reads as `1`, the same value. Text that is not JSON is left to the codec.
859
+ */
860
+ function jsonKeepsEveryNumber(text) {
861
+ let exact = true;
862
+ const reviver = (_key, value, context) => {
863
+ if (typeof value === "number" && !keepsJsonNumber(value, context?.source)) exact = false;
864
+ return value;
865
+ };
866
+ try {
867
+ JSON.parse(text, reviver);
868
+ } catch {
869
+ return true;
870
+ }
871
+ return exact;
872
+ }
873
+ /**
874
+ * How `contract infer` reads the defaults the database reports: with the codec of the type constructor it prints for the column (`fromWire` of the literal's body, then `toDataTypeValue`), as `db verify` reads them with the contract column's codec. `contract infer` has no contract, so the constructor it prints stands in for one.
875
+ */
876
+ /** For tables whose columns carry no default to read, such as a many-to-many junction table. */
877
+ const noInferredDefaults = () => void 0;
878
+ function key(tableName, columnName) {
879
+ return JSON.stringify([tableName, columnName]);
880
+ }
881
+ /**
882
+ * Reads each column's reported default. A function default, SQL NULL and a literal the codec reads are the default; a literal the codec cannot read, or one on a column whose constructor names no codec, is the raw expression as reported.
883
+ */
884
+ async function readInferredDefaults(schema, columnTypes, isEnumColumn, context) {
885
+ const read = /* @__PURE__ */ new Map();
886
+ for (const table of Object.values(schema.tables)) for (const column of Object.values(table.columns)) {
887
+ const columnDefault = await readColumnDefault$1(column, () => columnTypes(table.name, column.name), isEnumColumn(column), context);
888
+ if (columnDefault !== void 0) read.set(key(table.name, column.name), columnDefault);
889
+ }
890
+ return (tableName, column) => read.get(key(tableName, column.name));
891
+ }
892
+ async function readColumnDefault$1(column, pslType, isEnum, context) {
893
+ const raw = column.default;
894
+ if (typeof raw !== "string") return isColumnDefault(raw) ? raw : void 0;
895
+ return readDefaultWithCodec(raw, column.many === true, codecOf(pslType, isEnum, context));
896
+ }
897
+ /**
898
+ * Reads one reported default, of a list column when `many`, with `codec`: a function default and SQL NULL as themselves, a literal the codec reads as its stored JSON, and anything else as the raw expression as reported.
899
+ */
900
+ async function readDefaultWithCodec(raw, many, codec) {
901
+ const reported = readPostgresDefault(raw, many);
902
+ if (reported.kind === "function") return reported;
903
+ if (reported.kind === "null") return {
904
+ kind: "literal",
905
+ value: null
906
+ };
907
+ const rawExpression = {
908
+ kind: "function",
909
+ expression: raw.trim()
910
+ };
911
+ if (codec === void 0) return rawExpression;
912
+ if (reported.literal.kind === "list" && reported.literal.elements.includes(null) && holdsNull(codec)) return rawExpression;
913
+ if (JSON_TYPES.has(codec.dataType.id) && !bodiesOf(reported.literal).every(jsonBodyIsExact)) return rawExpression;
914
+ const read = await readReportedDefault(codec, reported.literal, raw);
915
+ return "resolvedDefault" in read ? read.resolvedDefault : rawExpression;
916
+ }
917
+ const JSON_TYPES = /* @__PURE__ */ new Set([pgJson.id, pgJsonb.id]);
918
+ function bodiesOf(literal) {
919
+ return literal.kind === "value" ? [literal.body] : literal.elements;
920
+ }
921
+ function jsonBodyIsExact(body) {
922
+ return typeof body !== "string" || jsonKeepsEveryNumber(body);
923
+ }
924
+ /**
925
+ * Whether the codec's type has a value null, as a JSON type does. A list element that is SQL NULL would then print as that value, which reads back as something else, so such a list keeps its raw expression.
926
+ */
927
+ function holdsNull(codec) {
928
+ try {
929
+ codec.dataType.fromContract(null, {});
930
+ return true;
931
+ } catch (error) {
932
+ if (isInternalError(error)) throw error;
933
+ return false;
934
+ }
935
+ }
936
+ function codecOf(pslType, isEnum, context) {
937
+ try {
938
+ const ref = inferredCodecRef(context, isEnum ? { path: [] } : pslType(), isEnum);
939
+ return ref === void 0 ? void 0 : codecForRef(context.codecLookup, ref);
940
+ } catch (error) {
941
+ if (isInternalError(error)) throw error;
942
+ return;
943
+ }
944
+ }
945
+ function createPostgresDefaultMapping() {
946
+ const codecLookup = createPostgresBuiltinCodecLookup();
947
+ return { dataTypes: {
948
+ entries: postgresDataTypeEntries(),
949
+ lookup: createPostgresBuiltinDataTypeLookup(),
950
+ dataTypeOfCodec: (codecId) => codecLookup.descriptorFor(codecId)?.dataType
951
+ } };
952
+ }
953
+ /**
954
+ * Infers a PSL AST (for `printPsl`) from an introspected Postgres schema tree.
955
+ *
956
+ * Target-owned inference: it walks the `PostgresDatabaseSchemaNode` tree and
957
+ * owns the Postgres dialect knowledge — native enums and the default map.
958
+ * It reads each reported default with the codec of the type constructor it prints for the column (`readInferredDefaults`). A column's type is the SQL family's: the constructor marked
959
+ * `inferred` for the data type that claims the type the database reported.
960
+ * Relation inference, name transforms, and generic default mapping are
961
+ * shape-neutral utilities imported from the SQL family as well.
962
+ *
963
+ * The tree's tables (across its namespaces — `contract infer` introspects a
964
+ * single live namespace) are gathered into the model set and emitted in one
965
+ * bucket, alongside native-enum and RLS policy blocks. That bucket is named
966
+ * after the introspected schema when the content needs a `namespace { … }`
967
+ * wrap, and is the flat `UNSPECIFIED_PSL_NAMESPACE_ID` bucket otherwise. This
968
+ * entry point emits nothing else, so its output is always exactly one bucket
969
+ * and byte-identical to the prior flat inference. {@link buildPslDocumentAst}
970
+ * can emit a second, always-flat bucket for content that must stay top-level
971
+ * even under a wrap; no caller asks for one yet.
972
+ *
973
+ * `describedContracts` — the stack's extension packs' already-assembled
974
+ * contracts, each paired with its space id — is consulted while gathering
975
+ * tables: a table whose coordinate `(schemaName, 'table', tableName)` one of
976
+ * those contracts already declares is omitted, before the duplicate-name
977
+ * check below and before relation inference, so it cannot spuriously
978
+ * collide with an app table and never contributes a bare relation field. A
979
+ * surviving table's foreign key into an omitted, pack-owned table is not
980
+ * dropped: {@link resolveForeignKeys} rewrites it into a relation qualified
981
+ * with the pack's space id (`<spaceId>:<namespaceId>.<Model>`) instead.
982
+ */
983
+ async function inferPostgresPslContract(tree, context, describedContracts) {
984
+ const namespaces = Object.values(tree.namespaces);
985
+ const owners = describedContractOwners(describedContracts ?? []);
986
+ const enumDefinitions = /* @__PURE__ */ new Map();
987
+ const enumNamespaceNames = /* @__PURE__ */ new Set();
988
+ for (const namespace of namespaces) for (const { typeName, members } of namespace.nativeEnums) {
989
+ if (owners.get(coordinateKey({
990
+ namespaceId: namespace.schemaName,
991
+ entityKind: "native_enum",
992
+ entityName: typeName
993
+ })) !== void 0) continue;
994
+ enumDefinitions.set(typeName, members);
995
+ enumNamespaceNames.add(namespace.schemaName);
996
+ }
997
+ const tables = {};
998
+ const introspectedTables = [];
999
+ const tableNamespaceNames = /* @__PURE__ */ new Set();
1000
+ const rlsEnabledTables = /* @__PURE__ */ new Set();
1001
+ const policiesByTable = /* @__PURE__ */ new Map();
1002
+ for (const namespace of namespaces) for (const [tableName, table] of Object.entries(namespace.tables)) {
1003
+ if (owners.has(coordinateKey({
1004
+ namespaceId: namespace.schemaName,
1005
+ entityKind: "table",
1006
+ entityName: tableName
1007
+ }))) continue;
1008
+ if (tables[tableName] !== void 0) throw postgresError("CONTRACT.INFER_UNSUPPORTED", `contract infer: duplicate table name "${tableName}" across schemas is not yet supported (single-namespace PSL inference emits one flat bucket; multi-namespace \`namespace { … }\` output is a later slice).`, { meta: { tableName } });
1009
+ for (const column of Object.values(table.columns)) {
1010
+ const reported = column.reportedType;
1011
+ const owningSpaceId = reported?.kind === "enum" && reported.schema !== void 0 && reported.name !== void 0 ? owners.get(coordinateKey({
1012
+ namespaceId: reported.schema,
1013
+ entityKind: "native_enum",
1014
+ entityName: reported.name
1015
+ }))?.spaceId : void 0;
1016
+ if (owningSpaceId !== void 0) throw postgresError("CONTRACT.INFER_UNSUPPORTED", `contract infer: column "${tableName}"."${column.name}" is typed by native enum type "${column.typeText}", which extension pack space "${owningSpaceId}" already describes. A cross-space enum-typed column has no authorable PSL form yet; describe the table in that pack's contract or retype the column before re-running contract infer.`, { meta: {
1017
+ tableName,
1018
+ columnName: column.name
1019
+ } });
1020
+ }
1021
+ tables[tableName] = new SqlTableIR(table);
1022
+ introspectedTables.push({
1023
+ schemaName: namespace.schemaName,
1024
+ tableName,
1025
+ columns: Object.values(table.columns)
1026
+ });
1027
+ tableNamespaceNames.add(namespace.schemaName);
1028
+ if (table.rlsEnabled) rlsEnabledTables.add(tableName);
1029
+ if (table.policies.length > 0) policiesByTable.set(tableName, table.policies);
1030
+ }
1031
+ let wrapNamespaceName;
1032
+ if (enumDefinitions.size > 0 || policiesByTable.size > 0) {
1033
+ const contentNamespaces = /* @__PURE__ */ new Set([...enumNamespaceNames, ...tableNamespaceNames]);
1034
+ if (contentNamespaces.size > 1) throw postgresError("CONTRACT.INFER_UNSUPPORTED", `contract infer: adopting native enums or RLS policies with content across multiple schemas is not yet supported (single-namespace PSL inference emits one \`namespace { … }\` block; multi-namespace output is a later slice). Schemas: ${[...contentNamespaces].sort().join(", ")}.`, { meta: { schemas: [...contentNamespaces].sort() } });
1035
+ wrapNamespaceName = [...contentNamespaces][0];
1036
+ }
1037
+ const { tables: resolvedTables, extraRelationsByTable, crossSpaceFieldNamesByTable, danglingForeignKeysByTable } = resolveForeignKeys(tables, owners);
1038
+ const schemaIR = new SqlSchemaIR({ tables: resolvedTables });
1039
+ const enumInfo = { definitions: enumDefinitions };
1040
+ const isEnumColumn = (column) => adoptedEnumTypeName(column, enumInfo.definitions, wrapNamespaceName) !== void 0;
1041
+ const columnTypes = inferColumnTypes({
1042
+ tables: introspectedTables,
1043
+ constructors: inferredTypeConstructors({
1044
+ authoringTypes: context.authoringContributions.type,
1045
+ codecLookup: context.codecLookup,
1046
+ dataTypeLookup: context.dataTypes.lookup
1047
+ }),
1048
+ dataTypes: context.dataTypes,
1049
+ isEnumColumn
1050
+ });
1051
+ return buildPslDocumentAst(schemaIR, {
1052
+ columnTypes,
1053
+ defaultMapping: createPostgresDefaultMapping(),
1054
+ defaultOf: await readInferredDefaults(schemaIR, columnTypes, isEnumColumn, context),
1055
+ columnDefaults: inferredColumnDefaults(context),
1056
+ ...enumDefinitions.size > 0 ? { enumInfo } : {}
1057
+ }, {
1058
+ extraRelationsByTable,
1059
+ crossSpaceFieldNamesByTable,
1060
+ danglingForeignKeysByTable
1061
+ }, wrapNamespaceName, {
1062
+ rlsEnabledTables,
1063
+ policiesByTable
1064
+ });
1065
+ }
1066
+ /**
1067
+ * Builds the PSL document for one introspected schema.
1068
+ *
1069
+ * `namespaceName` wraps the output in `namespace <name> { … }`; omit it for
1070
+ * flat output. `topLevelExtensionBlocks` are declarations that must stay
1071
+ * top-level even when a wrap applies, such as a recovered domain enum — a
1072
+ * family `enum` inside a namespace is a hard diagnostic. They land in their
1073
+ * own always-flat bucket when a wrap applies, and in the single flat bucket
1074
+ * when none does; either way they print unwrapped.
1075
+ *
1076
+ * Their names are reserved before the policy blocks are built, so a policy
1077
+ * renames itself out of the way. Against the rest of the top-level scope — the
1078
+ * models, the native enums, PSL's scalar type names, and the other blocks in
1079
+ * the list — a clash throws instead: a block's name is its contract key
1080
+ * (`entries.valueSet[name]`, with no `@@map` escape), so it cannot be rewritten
1081
+ * here.
1082
+ */
1083
+ function buildPslDocumentAst(schemaIR, options, foreignKeyExtras, namespaceName, rlsExtras, topLevelExtensionBlocks = []) {
1084
+ const { columnTypes, defaultMapping, defaultOf } = options;
1085
+ const { extraRelationsByTable, crossSpaceFieldNamesByTable, danglingForeignKeysByTable } = foreignKeyExtras;
1086
+ const modelNames = buildTopLevelNameMap(Object.keys(schemaIR.tables), toModelName, "model", "table");
1087
+ const modelNameMap = new Map([...modelNames].map(([tableName, result]) => [tableName, result.name]));
1088
+ const { enumNameMap: bareEnumNameMap, enumBlocks } = buildNativeEnumBlocks(options.enumInfo?.definitions ?? /* @__PURE__ */ new Map(), modelNames);
1089
+ const enumNameOf = (column) => {
1090
+ const typeName = adoptedEnumTypeName(column, bareEnumNameMap, namespaceName);
1091
+ return typeName === void 0 ? void 0 : bareEnumNameMap.get(typeName);
1092
+ };
1093
+ const fieldNamesByTable = new Map([...crossSpaceFieldNamesByTable, ...buildFieldNamesByTable(schemaIR.tables)]);
1094
+ const { relationsByTable } = inferRelations(schemaIR.tables, modelNameMap);
1095
+ const policyEmission = buildIntrospectedPolicyBlocks(rlsExtras?.policiesByTable ?? /* @__PURE__ */ new Map(), modelNameMap, /* @__PURE__ */ new Set([
1096
+ ...modelNameMap.values(),
1097
+ ...bareEnumNameMap.values(),
1098
+ ...topLevelExtensionBlocks.map((block) => block.name)
1099
+ ]));
1100
+ const claimedTopLevelNames = /* @__PURE__ */ new Set([
1101
+ ...PSL_SCALAR_TYPE_NAMES,
1102
+ ...modelNameMap.values(),
1103
+ ...bareEnumNameMap.values()
1104
+ ]);
1105
+ for (const block of topLevelExtensionBlocks) {
1106
+ if (claimedTopLevelNames.has(block.name)) throw postgresError("CONTRACT.NAME_DUPLICATE", `contract infer: recovered ${block.keyword} "${block.name}" collides with a model, a native enum, a PSL scalar type, or another recovered declaration of the same name. Rename the recovered declaration, or exclude it.`, { meta: {
1107
+ kind: block.keyword,
1108
+ name: block.name
1109
+ } });
1110
+ claimedTopLevelNames.add(block.name);
1111
+ }
1112
+ const models = [];
1113
+ for (const table of Object.values(schemaIR.tables)) models.push(buildModel(table, columnTypes, enumNameOf, fieldNamesByTable, defaultMapping, defaultOf, options.columnDefaults, [...relationsByTable.get(table.name) ?? [], ...extraRelationsByTable.get(table.name) ?? []], danglingForeignKeysByTable.get(table.name) ?? [], rlsExtras?.rlsEnabledTables.has(table.name) ?? false, policyEmission.skipNotesByTable.get(table.name) ?? []));
1114
+ const sortedModels = topologicalSort(models, schemaIR.tables, modelNameMap);
1115
+ const separateTopLevelBucket = namespaceName !== void 0 && namespaceName !== UNSPECIFIED_PSL_NAMESPACE_ID && topLevelExtensionBlocks.length > 0;
1116
+ const namespaces = [];
1117
+ if (separateTopLevelBucket) namespaces.push(makePslNamespace({
1118
+ kind: "namespace",
1119
+ name: UNSPECIFIED_PSL_NAMESPACE_ID,
1120
+ entries: makePslNamespaceEntries([], [], topLevelExtensionBlocks),
1121
+ span: SYNTHETIC_SPAN
1122
+ }));
1123
+ namespaces.push(makePslNamespace({
1124
+ kind: "namespace",
1125
+ name: namespaceName ?? UNSPECIFIED_PSL_NAMESPACE_ID,
1126
+ entries: makePslNamespaceEntries(sortedModels, [], [
1127
+ ...separateTopLevelBucket ? [] : topLevelExtensionBlocks,
1128
+ ...enumBlocks,
1129
+ ...policyEmission.blocks
1130
+ ]),
1131
+ span: SYNTHETIC_SPAN
1132
+ }));
1133
+ return {
1134
+ kind: "document",
1135
+ sourceId: "<sql-schema-ir>",
1136
+ namespaces,
1137
+ span: SYNTHETIC_SPAN
1138
+ };
1139
+ }
1140
+ //#endregion
1141
+ export { buildIndexAttribute as a, buildNativeEnumBlock as c, inferPostgresPslContract as d, namedArg as f, positionalArg as g, parseDefaultAttributeString as h, buildFullTextIndexAttribute as i, buildPslDocumentAst as l, noInferredDefaults as m, buildAttribute as n, buildMapAttribute as o, noColumnDefaults as p, buildCheckAttribute as r, buildModelConstraintAttribute as s, SYNTHETIC_SPAN as t, createPostgresDefaultMapping as u };
1142
+
1143
+ //# sourceMappingURL=infer-psl-contract-BSSHcuRi-ChdFSviw.mjs.map