@prisma/orm-target-postgres 0.16.0-dev.36

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 (279) hide show
  1. package/LICENSE +201 -0
  2. package/README.md +23 -0
  3. package/dist/adapter-CWvVo0PV.d.mts +22 -0
  4. package/dist/adapter-CWvVo0PV.d.mts.map +1 -0
  5. package/dist/adapter-DhqcO3YO-jzwDVcCv.mjs +70 -0
  6. package/dist/adapter-DhqcO3YO-jzwDVcCv.mjs.map +1 -0
  7. package/dist/adapter.d.mts +12 -0
  8. package/dist/adapter.mjs +7 -0
  9. package/dist/adapter__adapter.d.mts +2 -0
  10. package/dist/adapter__adapter.mjs +2 -0
  11. package/dist/adapter__column-types.d.mts +2 -0
  12. package/dist/adapter__column-types.mjs +2 -0
  13. package/dist/adapter__control.d.mts +5 -0
  14. package/dist/adapter__control.mjs +441 -0
  15. package/dist/adapter__control.mjs.map +1 -0
  16. package/dist/adapter__operation-types.d.mts +2 -0
  17. package/dist/adapter__operation-types.mjs +1 -0
  18. package/dist/adapter__runtime.d.mts +2 -0
  19. package/dist/adapter__runtime.mjs +38 -0
  20. package/dist/adapter__runtime.mjs.map +1 -0
  21. package/dist/adapter__types.d.mts +4 -0
  22. package/dist/adapter__types.mjs +1 -0
  23. package/dist/authoring-03FwIL2k-kPjZAp3s.mjs +757 -0
  24. package/dist/authoring-03FwIL2k-kPjZAp3s.mjs.map +1 -0
  25. package/dist/canonicalize-CQlxSR4D-MnrT5gtW.d.mts +34 -0
  26. package/dist/canonicalize-CQlxSR4D-MnrT5gtW.d.mts.map +1 -0
  27. package/dist/canonicalize-CrN3u_xM-D4MrOqcB.mjs +59 -0
  28. package/dist/canonicalize-CrN3u_xM-D4MrOqcB.mjs.map +1 -0
  29. package/dist/codec-descriptor-Bec_zukr-BfvtUqhm.d.mts +37 -0
  30. package/dist/codec-descriptor-Bec_zukr-BfvtUqhm.d.mts.map +1 -0
  31. package/dist/codec-descriptor-Bg-_412t.d.mts +1 -0
  32. package/dist/codec-descriptor-CB6x0xEu-C-Zn2IEz.mjs +135 -0
  33. package/dist/codec-descriptor-CB6x0xEu-C-Zn2IEz.mjs.map +1 -0
  34. package/dist/codec-ids-CsOU3xDv-mPI0INiF.d.mts +33 -0
  35. package/dist/codec-ids-CsOU3xDv-mPI0INiF.d.mts.map +1 -0
  36. package/dist/codec-ids-fgafMLR7.d.mts +1 -0
  37. package/dist/codec-ids-tX7Svtz--BuOfRaVU.mjs +33 -0
  38. package/dist/codec-ids-tX7Svtz--BuOfRaVU.mjs.map +1 -0
  39. package/dist/codec-types-BHwY9Ff-.d.mts +2 -0
  40. package/dist/codec-types-mWhnDEAf-CAQzGFnF.d.mts +82 -0
  41. package/dist/codec-types-mWhnDEAf-CAQzGFnF.d.mts.map +1 -0
  42. package/dist/codecs-CBl0nD44-CaWPc1bd.mjs +1486 -0
  43. package/dist/codecs-CBl0nD44-CaWPc1bd.mjs.map +1 -0
  44. package/dist/codecs-CHIVTNZs.mjs +15 -0
  45. package/dist/codecs-CHIVTNZs.mjs.map +1 -0
  46. package/dist/codecs-Cvqvb9pV-Cdc51FKY.d.mts +589 -0
  47. package/dist/codecs-Cvqvb9pV-Cdc51FKY.d.mts.map +1 -0
  48. package/dist/codecs-DBn-uIv-.d.mts +15 -0
  49. package/dist/codecs-DBn-uIv-.d.mts.map +1 -0
  50. package/dist/column-types-BH-MU6uU.d.mts +108 -0
  51. package/dist/column-types-BH-MU6uU.d.mts.map +1 -0
  52. package/dist/column-types-CwAyCgp2.mjs +126 -0
  53. package/dist/column-types-CwAyCgp2.mjs.map +1 -0
  54. package/dist/contract-free-BZUS18FU.mjs +118 -0
  55. package/dist/contract-free-BZUS18FU.mjs.map +1 -0
  56. package/dist/contract-free-DzpGxLfb.d.mts +258 -0
  57. package/dist/contract-free-DzpGxLfb.d.mts.map +1 -0
  58. package/dist/control-2F195jJk.d.mts +11 -0
  59. package/dist/control-2F195jJk.d.mts.map +1 -0
  60. package/dist/control-6WFTtLAM.mjs +60 -0
  61. package/dist/control-6WFTtLAM.mjs.map +1 -0
  62. package/dist/control-B-FTbEnE.d.mts +22 -0
  63. package/dist/control-B-FTbEnE.d.mts.map +1 -0
  64. package/dist/control-D85zv_aY.d.mts +199 -0
  65. package/dist/control-D85zv_aY.d.mts.map +1 -0
  66. package/dist/control-DRMWptiJ.mjs +1355 -0
  67. package/dist/control-DRMWptiJ.mjs.map +1 -0
  68. package/dist/control-adapter-B9t0g7Pf-HrCxlM65.mjs +1901 -0
  69. package/dist/control-adapter-B9t0g7Pf-HrCxlM65.mjs.map +1 -0
  70. package/dist/control-policy-Cl3RRSPg-CT3QGpR3.mjs +1257 -0
  71. package/dist/control-policy-Cl3RRSPg-CT3QGpR3.mjs.map +1 -0
  72. package/dist/data-transform-BSM7TQpE.d.mts +1 -0
  73. package/dist/data-transform-ChZzy2dP-CxVCat_8.mjs +53 -0
  74. package/dist/data-transform-ChZzy2dP-CxVCat_8.mjs.map +1 -0
  75. package/dist/data-transform-Ck5FbyNO-BNE7QlAo.d.mts +38 -0
  76. package/dist/data-transform-Ck5FbyNO-BNE7QlAo.d.mts.map +1 -0
  77. package/dist/ddl-B4Rh8ntj.d.mts +1 -0
  78. package/dist/ddl-BdP4q3KY-Duef4uHw.mjs +395 -0
  79. package/dist/ddl-BdP4q3KY-Duef4uHw.mjs.map +1 -0
  80. package/dist/default-normalizer-B36TOul4.d.mts +31 -0
  81. package/dist/default-normalizer-B36TOul4.d.mts.map +1 -0
  82. package/dist/default-normalizer-Ba5ZebHM-isV86rjy.mjs +253 -0
  83. package/dist/default-normalizer-Ba5ZebHM-isV86rjy.mjs.map +1 -0
  84. package/dist/descriptor-meta-2IlVC6_d-DnV00Qd_.mjs +351 -0
  85. package/dist/descriptor-meta-2IlVC6_d-DnV00Qd_.mjs.map +1 -0
  86. package/dist/descriptor-meta-DnHabAS3-C53XXPQw.mjs +28 -0
  87. package/dist/descriptor-meta-DnHabAS3-C53XXPQw.mjs.map +1 -0
  88. package/dist/descriptor-meta-runtime-UwYdV8fD-B_m_Ha8r.mjs +13 -0
  89. package/dist/descriptor-meta-runtime-UwYdV8fD-B_m_Ha8r.mjs.map +1 -0
  90. package/dist/diff-database-schema-BfRs2vrG-D2o4KII0.mjs +390 -0
  91. package/dist/diff-database-schema-BfRs2vrG-D2o4KII0.mjs.map +1 -0
  92. package/dist/diff-database-schema-DsoNznGC.d.mts +38 -0
  93. package/dist/diff-database-schema-DsoNznGC.d.mts.map +1 -0
  94. package/dist/driver.d.mts +3 -0
  95. package/dist/driver.mjs +2 -0
  96. package/dist/driver__control.d.mts +2 -0
  97. package/dist/driver__control.mjs +2 -0
  98. package/dist/driver__runtime.d.mts +2 -0
  99. package/dist/driver__runtime.mjs +597 -0
  100. package/dist/driver__runtime.mjs.map +1 -0
  101. package/dist/errors-DCcVX4j1.d.mts +32 -0
  102. package/dist/errors-DCcVX4j1.d.mts.map +1 -0
  103. package/dist/errors-kYxOQjdD-D4T3rbVp.mjs +39 -0
  104. package/dist/errors-kYxOQjdD-D4T3rbVp.mjs.map +1 -0
  105. package/dist/issue-planner-jkY6p-Ca.d.mts +105 -0
  106. package/dist/issue-planner-jkY6p-Ca.d.mts.map +1 -0
  107. package/dist/migration-CBSAPE8S.d.mts +25 -0
  108. package/dist/migration-CBSAPE8S.d.mts.map +1 -0
  109. package/dist/migration-PTHAY9Cv.mjs +21 -0
  110. package/dist/migration-PTHAY9Cv.mjs.map +1 -0
  111. package/dist/namespace-ids-xtp_ZY86-Cpp8PTxD.mjs +7 -0
  112. package/dist/namespace-ids-xtp_ZY86-Cpp8PTxD.mjs.map +1 -0
  113. package/dist/native-type-normalizer-DqJlOTeX.d.mts +19 -0
  114. package/dist/native-type-normalizer-DqJlOTeX.d.mts.map +1 -0
  115. package/dist/native-type-normalizer-yvd3tqv-.mjs +38 -0
  116. package/dist/native-type-normalizer-yvd3tqv-.mjs.map +1 -0
  117. package/dist/nodes-BU-V-aZA-RqwPH68u.d.mts +235 -0
  118. package/dist/nodes-BU-V-aZA-RqwPH68u.d.mts.map +1 -0
  119. package/dist/nodes-DAvDJLvJ-BBdvFXNa.mjs +255 -0
  120. package/dist/nodes-DAvDJLvJ-BBdvFXNa.mjs.map +1 -0
  121. package/dist/normalize-error-CNjgVO71-CLlZ3CuJ.mjs +121 -0
  122. package/dist/normalize-error-CNjgVO71-CLlZ3CuJ.mjs.map +1 -0
  123. package/dist/op-factory-call-DifL68KT-Bo6pxs-R.mjs +2009 -0
  124. package/dist/op-factory-call-DifL68KT-Bo6pxs-R.mjs.map +1 -0
  125. package/dist/op-factory-call-FEA5mnWH.d.mts +1 -0
  126. package/dist/op-factory-call-jd4cgfjA-CyNT4YVn.d.mts +521 -0
  127. package/dist/op-factory-call-jd4cgfjA-CyNT4YVn.d.mts.map +1 -0
  128. package/dist/operation-types-BfRocNI8.d.mts +22 -0
  129. package/dist/operation-types-BfRocNI8.d.mts.map +1 -0
  130. package/dist/pack-DFM4tmob.d.mts +610 -0
  131. package/dist/pack-DFM4tmob.d.mts.map +1 -0
  132. package/dist/planner-Bmje9ii8-B99fEsNM.mjs +588 -0
  133. package/dist/planner-Bmje9ii8-B99fEsNM.mjs.map +1 -0
  134. package/dist/planner-DL4Bh5Nk.d.mts +163 -0
  135. package/dist/planner-DL4Bh5Nk.d.mts.map +1 -0
  136. package/dist/planner-ddl-builders-CbfICQfm-CxYiLrhX.mjs +102 -0
  137. package/dist/planner-ddl-builders-CbfICQfm-CxYiLrhX.mjs.map +1 -0
  138. package/dist/planner-ddl-builders-ijp60-JO.d.mts +19 -0
  139. package/dist/planner-ddl-builders-ijp60-JO.d.mts.map +1 -0
  140. package/dist/planner-identity-values-BmHn5C6U-BYBbUAyR.mjs +90 -0
  141. package/dist/planner-identity-values-BmHn5C6U-BYBbUAyR.mjs.map +1 -0
  142. package/dist/planner-identity-values-TfEhnoWa.d.mts +25 -0
  143. package/dist/planner-identity-values-TfEhnoWa.d.mts.map +1 -0
  144. package/dist/planner-produced-postgres-migration-B0PQLLUb-qsS6cQqX.d.mts +25 -0
  145. package/dist/planner-produced-postgres-migration-B0PQLLUb-qsS6cQqX.d.mts.map +1 -0
  146. package/dist/planner-produced-postgres-migration-C3GPZWeC.d.mts +1 -0
  147. package/dist/planner-produced-postgres-migration-Cicg2sXg-Ck9iDxGI.mjs +47 -0
  148. package/dist/planner-produced-postgres-migration-Cicg2sXg-Ck9iDxGI.mjs.map +1 -0
  149. package/dist/planner-schema-lookup-C4DHAddq.d.mts +21 -0
  150. package/dist/planner-schema-lookup-C4DHAddq.d.mts.map +1 -0
  151. package/dist/planner-schema-lookup-kMIVP2y--CdO4VlnF.mjs +57 -0
  152. package/dist/planner-schema-lookup-kMIVP2y--CdO4VlnF.mjs.map +1 -0
  153. package/dist/planner-sql-checks-CFgbRTJw.d.mts +20 -0
  154. package/dist/planner-sql-checks-CFgbRTJw.d.mts.map +1 -0
  155. package/dist/planner-sql-checks-DRc_78n8-C9nHOrvU.mjs +152 -0
  156. package/dist/planner-sql-checks-DRc_78n8-C9nHOrvU.mjs.map +1 -0
  157. package/dist/planner-target-details-HkP4RrRO-_xPQVPF0.d.mts +12 -0
  158. package/dist/planner-target-details-HkP4RrRO-_xPQVPF0.d.mts.map +1 -0
  159. package/dist/planner-type-resolution-Bt2f_q-F-C4T6YTae.mjs +15 -0
  160. package/dist/planner-type-resolution-Bt2f_q-F-C4T6YTae.mjs.map +1 -0
  161. package/dist/postgres-contract-view-2OP5JnXl-D2fpy4-8.d.mts +36 -0
  162. package/dist/postgres-contract-view-2OP5JnXl-D2fpy4-8.d.mts.map +1 -0
  163. package/dist/postgres-contract-view-FdLX7dV9-Cat1VKV9.mjs +144 -0
  164. package/dist/postgres-contract-view-FdLX7dV9-Cat1VKV9.mjs.map +1 -0
  165. package/dist/postgres-database-schema-node-CyfpHXDr-BqyozkQE.d.mts +285 -0
  166. package/dist/postgres-database-schema-node-CyfpHXDr-BqyozkQE.d.mts.map +1 -0
  167. package/dist/postgres-migration-CDJj7CvD-Bsqs_fVo.d.mts +260 -0
  168. package/dist/postgres-migration-CDJj7CvD-Bsqs_fVo.d.mts.map +1 -0
  169. package/dist/postgres-migration-CJshdIZn-DYYjgdD0.mjs +201 -0
  170. package/dist/postgres-migration-CJshdIZn-DYYjgdD0.mjs.map +1 -0
  171. package/dist/postgres-native-enum-CdP3b_-R-Cgz9KEKx.mjs +45 -0
  172. package/dist/postgres-native-enum-CdP3b_-R-Cgz9KEKx.mjs.map +1 -0
  173. package/dist/postgres-rls-policy-CnDxf3z9-C3LIHAIG.d.mts +61 -0
  174. package/dist/postgres-rls-policy-CnDxf3z9-C3LIHAIG.d.mts.map +1 -0
  175. package/dist/postgres-role-schema-node-B8Z5i5D--PObwlU2Z.mjs +204 -0
  176. package/dist/postgres-role-schema-node-B8Z5i5D--PObwlU2Z.mjs.map +1 -0
  177. package/dist/postgres-schema-KSzLDONj-CsXGoY8b.mjs +421 -0
  178. package/dist/postgres-schema-KSzLDONj-CsXGoY8b.mjs.map +1 -0
  179. package/dist/postgres-schema-Xsjt3RKO-Buv2X8ai.d.mts +269 -0
  180. package/dist/postgres-schema-Xsjt3RKO-Buv2X8ai.d.mts.map +1 -0
  181. package/dist/postgres-table-schema-node-BBkitBQh-DT1T5VWU.mjs +212 -0
  182. package/dist/postgres-table-schema-node-BBkitBQh-DT1T5VWU.mjs.map +1 -0
  183. package/dist/render-ops-DPwhZt2W.d.mts +11 -0
  184. package/dist/render-ops-DPwhZt2W.d.mts.map +1 -0
  185. package/dist/render-ops-DxzTxSsv-Bz85uUHk.mjs +34 -0
  186. package/dist/render-ops-DxzTxSsv-Bz85uUHk.mjs.map +1 -0
  187. package/dist/render-typescript-6sCFvMBh.d.mts +21 -0
  188. package/dist/render-typescript-6sCFvMBh.d.mts.map +1 -0
  189. package/dist/render-typescript-Cw3lFO28-Cx0lXWmv.mjs +117 -0
  190. package/dist/render-typescript-Cw3lFO28-Cx0lXWmv.mjs.map +1 -0
  191. package/dist/resolve-ddl-schema-CxqlLW47-0GiHRziS.mjs +22 -0
  192. package/dist/resolve-ddl-schema-CxqlLW47-0GiHRziS.mjs.map +1 -0
  193. package/dist/runtime-BbSRVwdd.d.mts +12 -0
  194. package/dist/runtime-BbSRVwdd.d.mts.map +1 -0
  195. package/dist/runtime-CDewySU9.d.mts +55 -0
  196. package/dist/runtime-CDewySU9.d.mts.map +1 -0
  197. package/dist/runtime-_TfO66h5.d.mts +32 -0
  198. package/dist/runtime-_TfO66h5.d.mts.map +1 -0
  199. package/dist/schema-ir-annotations-DuuYh0gl.d.mts +15 -0
  200. package/dist/schema-ir-annotations-DuuYh0gl.d.mts.map +1 -0
  201. package/dist/schema-node-kinds-qlnURWJy-Bo30pwTM.d.mts +30 -0
  202. package/dist/schema-node-kinds-qlnURWJy-Bo30pwTM.d.mts.map +1 -0
  203. package/dist/sql-utils-BnBlQxyh-DaX9Nb7Z.mjs +90 -0
  204. package/dist/sql-utils-BnBlQxyh-DaX9Nb7Z.mjs.map +1 -0
  205. package/dist/sql-utils-DW6fkczF.d.mts +62 -0
  206. package/dist/sql-utils-DW6fkczF.d.mts.map +1 -0
  207. package/dist/table-source-ikHOZmhD-DriY1Lcr.d.mts +15 -0
  208. package/dist/table-source-ikHOZmhD-DriY1Lcr.d.mts.map +1 -0
  209. package/dist/target.d.mts +47 -0
  210. package/dist/target.mjs +34 -0
  211. package/dist/target__codec-descriptor.d.mts +3 -0
  212. package/dist/target__codec-descriptor.mjs +2 -0
  213. package/dist/target__codec-ids.d.mts +3 -0
  214. package/dist/target__codec-ids.mjs +2 -0
  215. package/dist/target__codec-types.d.mts +4 -0
  216. package/dist/target__codec-types.mjs +1 -0
  217. package/dist/target__codecs.d.mts +3 -0
  218. package/dist/target__codecs.mjs +3 -0
  219. package/dist/target__contract-free.d.mts +3 -0
  220. package/dist/target__contract-free.mjs +4 -0
  221. package/dist/target__control.d.mts +2 -0
  222. package/dist/target__control.mjs +2 -0
  223. package/dist/target__data-transform.d.mts +3 -0
  224. package/dist/target__data-transform.mjs +2 -0
  225. package/dist/target__ddl.d.mts +4 -0
  226. package/dist/target__ddl.mjs +2 -0
  227. package/dist/target__default-normalizer.d.mts +2 -0
  228. package/dist/target__default-normalizer.mjs +2 -0
  229. package/dist/target__diff-database-schema.d.mts +2 -0
  230. package/dist/target__diff-database-schema.mjs +2 -0
  231. package/dist/target__errors.d.mts +2 -0
  232. package/dist/target__errors.mjs +2 -0
  233. package/dist/target__issue-planner.d.mts +2 -0
  234. package/dist/target__issue-planner.mjs +2 -0
  235. package/dist/target__migration.d.mts +4 -0
  236. package/dist/target__migration.mjs +5 -0
  237. package/dist/target__native-type-normalizer.d.mts +2 -0
  238. package/dist/target__native-type-normalizer.mjs +2 -0
  239. package/dist/target__op-factory-call.d.mts +3 -0
  240. package/dist/target__op-factory-call.mjs +2 -0
  241. package/dist/target__pack.d.mts +2 -0
  242. package/dist/target__pack.mjs +2 -0
  243. package/dist/target__planner-ddl-builders.d.mts +2 -0
  244. package/dist/target__planner-ddl-builders.mjs +2 -0
  245. package/dist/target__planner-identity-values.d.mts +2 -0
  246. package/dist/target__planner-identity-values.mjs +2 -0
  247. package/dist/target__planner-produced-postgres-migration.d.mts +3 -0
  248. package/dist/target__planner-produced-postgres-migration.mjs +2 -0
  249. package/dist/target__planner-schema-lookup.d.mts +2 -0
  250. package/dist/target__planner-schema-lookup.mjs +2 -0
  251. package/dist/target__planner-sql-checks.d.mts +2 -0
  252. package/dist/target__planner-sql-checks.mjs +2 -0
  253. package/dist/target__planner-target-details.d.mts +2 -0
  254. package/dist/target__planner-target-details.mjs +1 -0
  255. package/dist/target__planner.d.mts +2 -0
  256. package/dist/target__planner.mjs +3 -0
  257. package/dist/target__render-ops.d.mts +2 -0
  258. package/dist/target__render-ops.mjs +2 -0
  259. package/dist/target__render-typescript.d.mts +2 -0
  260. package/dist/target__render-typescript.mjs +2 -0
  261. package/dist/target__rls-canonicalize.d.mts +2 -0
  262. package/dist/target__rls-canonicalize.mjs +2 -0
  263. package/dist/target__runtime.d.mts +3 -0
  264. package/dist/target__runtime.mjs +23 -0
  265. package/dist/target__runtime.mjs.map +1 -0
  266. package/dist/target__schema-ir-annotations.d.mts +2 -0
  267. package/dist/target__schema-ir-annotations.mjs +2 -0
  268. package/dist/target__sql-utils.d.mts +2 -0
  269. package/dist/target__sql-utils.mjs +2 -0
  270. package/dist/target__types.d.mts +7 -0
  271. package/dist/target__types.mjs +5 -0
  272. package/dist/types-CkryN1AS-6MNZLjLY.d.mts +27 -0
  273. package/dist/types-CkryN1AS-6MNZLjLY.d.mts.map +1 -0
  274. package/dist/types-Cp_Jf2tk.d.mts +1 -0
  275. package/dist/types-ue6jkJyF-BQJzjx1P.d.mts +10 -0
  276. package/dist/types-ue6jkJyF-BQJzjx1P.d.mts.map +1 -0
  277. package/dist/types-xa86TkcV.d.mts +32 -0
  278. package/dist/types-xa86TkcV.d.mts.map +1 -0
  279. package/package.json +95 -0
@@ -0,0 +1,757 @@
1
+ import { o as PG_ENUM_CODEC_ID } from "./codec-ids-tX7Svtz--BuOfRaVU.mjs";
2
+ import { n as postgresError } from "./errors-kYxOQjdD-D4T3rbVp.mjs";
3
+ import { t as PostgresNativeEnum } from "./postgres-native-enum-CdP3b_-R-Cgz9KEKx.mjs";
4
+ import { a as PostgresRlsPolicySchema, i as PostgresRlsPolicy, n as PostgresRlsEnablement, o as PostgresRole, r as PostgresRlsEnablementSchema, s as PostgresRoleSchema, t as PostgresNativeEnumSchema } from "./postgres-schema-KSzLDONj-CsXGoY8b.mjs";
5
+ import { n as computeContentHash, t as POLICY_OPERATION_PREDICATES } from "./canonicalize-CrN3u_xM-D4MrOqcB.mjs";
6
+ import { blindCast } from "@prisma/orm-framework/utils/casts";
7
+ import { UNBOUND_NAMESPACE_ID } from "@prisma/orm-framework/components/ir";
8
+ import { ifDefined } from "@prisma/orm-framework/utils/defined";
9
+ import { assertWireNamePrefixLength, normalizeSqlBody } from "@prisma/orm-family-sql/schema-ir/naming";
10
+ import { assertDefined } from "@prisma/orm-framework/utils/assertions";
11
+ import { temporalAuthoringPresets, temporalCodecPresetWithPrecision } from "@prisma/orm-family-sql/family/control";
12
+ import { modelAttribute } from "@prisma/orm-framework/psl-parser";
13
+ import { exactNameBodyWarning } from "@prisma/orm-family-sql/contract/index-naming";
14
+ //#region ../../../3-targets/3-targets/postgres/dist/authoring-03FwIL2k.mjs
15
+ const PSL_RLS_PREDICATE_NOT_FOR_OPERATION = "PSL_RLS_PREDICATE_NOT_FOR_OPERATION";
16
+ const PSL_POLICY_INVALID_MAP = "PSL_POLICY_INVALID_MAP";
17
+ const PSL_NATIVE_ENUM_INVALID_MAP = "PSL_NATIVE_ENUM_INVALID_MAP";
18
+ const PSL_NATIVE_ENUM_BARE_MEMBER = "PSL_NATIVE_ENUM_BARE_MEMBER";
19
+ const PSL_EXTENSION_INVALID_VALUE = "PSL_EXTENSION_INVALID_VALUE";
20
+ const PSL_NATIVE_ENUM_DUPLICATE_MEMBER_VALUE = "PSL_NATIVE_ENUM_DUPLICATE_MEMBER_VALUE";
21
+ const PSL_NATIVE_ENUM_MISSING_MEMBERS = "PSL_NATIVE_ENUM_MISSING_MEMBERS";
22
+ const PSL_ROLE_BLOCK_OUTSIDE_UNBOUND_NAMESPACE = "PSL_ROLE_BLOCK_OUTSIDE_UNBOUND_NAMESPACE";
23
+ /**
24
+ * `pg.enum(<ref>)` registers as an ordinary type constructor whose sole
25
+ * positional argument names a `native_enum` entity instead of carrying a
26
+ * literal value. The interpreter resolves the ref to the `native_enum`
27
+ * entity generically (driven by `entityRefArg`); the `pg/enum@1` codec
28
+ * descriptor's `columnFromEntity` hook (see `codecs.ts`) converts that
29
+ * entity into the column's `typeParams` and native type.
30
+ */
31
+ const postgresAuthoringTypes = { pg: { enum: {
32
+ kind: "typeConstructor",
33
+ entityRefArg: {
34
+ index: 0,
35
+ entityKind: "native_enum"
36
+ },
37
+ output: { codecId: PG_ENUM_CODEC_ID }
38
+ } } };
39
+ /**
40
+ * Maps a `policy_<op>` keyword to the RLS operation it authors. The keyword
41
+ * IS the operation (per the project's rejection of a `policy { operation = … }`
42
+ * conditional block).
43
+ */
44
+ const POLICY_KEYWORD_OPERATION = {
45
+ policy_select: "select",
46
+ policy_insert: "insert",
47
+ policy_update: "update",
48
+ policy_delete: "delete",
49
+ policy_all: "all"
50
+ };
51
+ function readValueParam(block, key) {
52
+ const param = block.parameters[key];
53
+ return param?.kind === "value" ? param.raw : void 0;
54
+ }
55
+ function readListRefParams(block, key) {
56
+ const param = block.parameters[key];
57
+ if (param?.kind !== "list") return [];
58
+ return param.items.flatMap((item) => item.kind === "ref" ? [item.identifier] : []);
59
+ }
60
+ /**
61
+ * Unwraps a quoted PSL string argument, inverting the printer's
62
+ * `escapePslString` escapes (`\\`, `\"`, `\n`, `\r`). An unknown escape
63
+ * sequence is kept verbatim, matching the printer-side `unescapePslString`
64
+ * convention.
65
+ */
66
+ function unwrapQuotedString(raw) {
67
+ if (!(raw.startsWith("\"") && raw.endsWith("\"") && raw.length >= 2)) return raw;
68
+ const inner = raw.slice(1, -1);
69
+ let result = "";
70
+ for (let i = 0; i < inner.length; i++) {
71
+ if (inner[i] !== "\\" || i + 1 >= inner.length) {
72
+ result += inner[i];
73
+ continue;
74
+ }
75
+ const next = inner[i + 1];
76
+ if (next === "\\" || next === "\"") result += next;
77
+ else if (next === "n") result += "\n";
78
+ else if (next === "r") result += "\r";
79
+ else {
80
+ result += "\\";
81
+ result += next;
82
+ }
83
+ i++;
84
+ }
85
+ return result;
86
+ }
87
+ /**
88
+ * Assembles a {@link PostgresRlsPolicy} from lowered inputs: normalizes the
89
+ * predicates, computes the content-hash wire name, and constructs the frozen
90
+ * entity. The single hash-assembly body shared by the PSL block lowering
91
+ * ({@link lowerRlsPolicyFromBlock}) and the TS entity-handle lowering
92
+ * ({@link postgresLowerEntityHandles}) so the two surfaces cannot drift.
93
+ */
94
+ function buildRlsPolicyEntity(input) {
95
+ const permissive = input.permissive ?? true;
96
+ const wireHash = computeContentHash({
97
+ ...ifDefined("using", input.using !== void 0 ? normalizeSqlBody(input.using) : void 0),
98
+ ...ifDefined("withCheck", input.withCheck !== void 0 ? normalizeSqlBody(input.withCheck) : void 0),
99
+ roles: input.roles,
100
+ operation: input.operation,
101
+ permissive
102
+ });
103
+ return new PostgresRlsPolicy({
104
+ naming: {
105
+ kind: "wire",
106
+ prefix: input.prefix,
107
+ hash: wireHash
108
+ },
109
+ tableName: input.tableName,
110
+ namespaceId: input.namespaceId,
111
+ operation: input.operation,
112
+ roles: input.roles,
113
+ using: input.using,
114
+ withCheck: input.withCheck,
115
+ permissive
116
+ });
117
+ }
118
+ function lowerRlsPolicyFromBlock(block, ctx) {
119
+ const prefix = block.name;
120
+ const operation = POLICY_KEYWORD_OPERATION[block.keyword] ?? "select";
121
+ const tableName = block.resolvedModelRefs?.["target"]?.tableName;
122
+ assertDefined(tableName, `lowerRlsPolicyFromBlock: policy "${block.name}" reached the factory without a resolved \`target\` ref; the interpreter resolves same-namespace model refs before invoking entity factories.`);
123
+ const roles = [...readListRefParams(block, "roles")].sort();
124
+ const usingRaw = readValueParam(block, "using");
125
+ const withCheckRaw = readValueParam(block, "withCheck");
126
+ const support = POLICY_OPERATION_PREDICATES[operation];
127
+ const rejectPredicate = (predicate) => {
128
+ ctx.diagnostics?.push({
129
+ code: PSL_RLS_PREDICATE_NOT_FOR_OPERATION,
130
+ message: `\`${block.keyword}\` policy "${block.name}" does not take a \`${predicate}\` predicate; the ${operation.toUpperCase()} operation uses ${support.using ? "`using`" : "`withCheck`"}${support.using && support.withCheck ? " and `withCheck`" : " only"}.`,
131
+ sourceId: ctx.sourceId ?? "unknown",
132
+ span: block.parameters[predicate]?.span ?? block.span
133
+ });
134
+ };
135
+ if (usingRaw !== void 0 && !support.using) return rejectPredicate("using");
136
+ if (withCheckRaw !== void 0 && !support.withCheck) return rejectPredicate("withCheck");
137
+ const using = usingRaw !== void 0 ? unwrapQuotedString(usingRaw) : void 0;
138
+ const withCheck = withCheckRaw !== void 0 ? unwrapQuotedString(withCheckRaw) : void 0;
139
+ const permissiveRaw = readValueParam(block, "permissive");
140
+ if (permissiveRaw !== void 0 && permissiveRaw !== "true" && permissiveRaw !== "false") {
141
+ ctx.diagnostics?.push({
142
+ code: PSL_EXTENSION_INVALID_VALUE,
143
+ message: `\`${block.keyword}\` policy "${block.name}" \`permissive\` must be \`true\` or \`false\`, got ${permissiveRaw}.`,
144
+ sourceId: ctx.sourceId ?? "unknown",
145
+ span: block.parameters["permissive"]?.span ?? block.span
146
+ });
147
+ return;
148
+ }
149
+ const permissive = permissiveRaw !== "false";
150
+ const mapAttr = block.blockAttributes.find((a) => a.name === "map");
151
+ if (mapAttr) {
152
+ const rawArg = mapAttr.args[0]?.value;
153
+ const exactName = rawArg?.startsWith("\"") && rawArg.endsWith("\"") && rawArg.length >= 2 ? unwrapQuotedString(rawArg) : void 0;
154
+ if (exactName === void 0 || exactName === "") {
155
+ ctx.diagnostics?.push({
156
+ code: PSL_POLICY_INVALID_MAP,
157
+ message: `\`${block.keyword}\` policy "${block.name}" @@map attribute must have a quoted, non-empty policy-name argument`,
158
+ sourceId: ctx.sourceId ?? "unknown",
159
+ span: mapAttr.span
160
+ });
161
+ return;
162
+ }
163
+ ctx.warnings?.push(exactNameBodyWarning("policy", exactName));
164
+ return new PostgresRlsPolicy({
165
+ naming: {
166
+ kind: "exact",
167
+ name: exactName
168
+ },
169
+ tableName,
170
+ namespaceId: block.namespaceId,
171
+ operation,
172
+ roles,
173
+ using,
174
+ withCheck,
175
+ permissive
176
+ });
177
+ }
178
+ return buildRlsPolicyEntity({
179
+ prefix,
180
+ tableName,
181
+ namespaceId: block.namespaceId,
182
+ operation,
183
+ roles,
184
+ ...ifDefined("using", using),
185
+ ...ifDefined("withCheck", withCheck),
186
+ permissive
187
+ });
188
+ }
189
+ /**
190
+ * Lowers a `native_enum { memberName = "value" … @@map("type_name") }` block
191
+ * into a {@link PostgresNativeEnum}. Members must be authored as explicit
192
+ * `key = "value"` pairs — a bare (value-less) member is a diagnostic, not
193
+ * accepted (authoring-design.md §2.1). The parsed `memberName` is only used
194
+ * to duplicate-check and report diagnostics; the lowered entity carries just
195
+ * the member values (a native enum is value-only — the member "name" isn't
196
+ * a separate authoring concept from the value). `typeName` comes from
197
+ * `@@map` or defaults to the block name verbatim.
198
+ */
199
+ function lowerNativeEnumFromBlock(block, ctx) {
200
+ const sourceId = ctx.sourceId ?? "unknown";
201
+ const diagnostics = ctx.diagnostics;
202
+ const mapAttr = block.blockAttributes.find((a) => a.name === "map");
203
+ let typeName = block.name;
204
+ if (mapAttr) {
205
+ const rawArg = mapAttr.args[0]?.value;
206
+ const mapped = rawArg !== void 0 ? unwrapQuotedString(rawArg) : void 0;
207
+ if (mapped === void 0) {
208
+ diagnostics?.push({
209
+ code: PSL_NATIVE_ENUM_INVALID_MAP,
210
+ message: `native_enum "${block.name}" @@map attribute must have a quoted type-name argument`,
211
+ sourceId,
212
+ span: mapAttr.span
213
+ });
214
+ return;
215
+ }
216
+ typeName = mapped;
217
+ }
218
+ let memberError = false;
219
+ const seenValues = /* @__PURE__ */ new Set();
220
+ const members = [];
221
+ for (const [memberName, paramValue] of Object.entries(block.parameters)) {
222
+ if (paramValue.kind === "bare") {
223
+ diagnostics?.push({
224
+ code: PSL_NATIVE_ENUM_BARE_MEMBER,
225
+ message: `native_enum "${block.name}" member "${memberName}" has no value; members must be authored as "${memberName} = \\"value\\""`,
226
+ sourceId,
227
+ span: paramValue.span
228
+ });
229
+ memberError = true;
230
+ continue;
231
+ }
232
+ if (paramValue.kind !== "value") continue;
233
+ let jsonValue;
234
+ try {
235
+ jsonValue = JSON.parse(paramValue.raw);
236
+ } catch {
237
+ diagnostics?.push({
238
+ code: PSL_EXTENSION_INVALID_VALUE,
239
+ message: `native_enum "${block.name}" member "${memberName}" value "${paramValue.raw}" is not valid JSON`,
240
+ sourceId,
241
+ span: paramValue.span
242
+ });
243
+ memberError = true;
244
+ continue;
245
+ }
246
+ if (typeof jsonValue !== "string") {
247
+ diagnostics?.push({
248
+ code: PSL_EXTENSION_INVALID_VALUE,
249
+ message: `native_enum "${block.name}" member "${memberName}" value must be a string`,
250
+ sourceId,
251
+ span: paramValue.span
252
+ });
253
+ memberError = true;
254
+ continue;
255
+ }
256
+ if (seenValues.has(jsonValue)) {
257
+ diagnostics?.push({
258
+ code: PSL_NATIVE_ENUM_DUPLICATE_MEMBER_VALUE,
259
+ message: `native_enum "${block.name}": duplicate member value "${jsonValue}"`,
260
+ sourceId,
261
+ span: paramValue.span
262
+ });
263
+ memberError = true;
264
+ continue;
265
+ }
266
+ seenValues.add(jsonValue);
267
+ members.push(jsonValue);
268
+ }
269
+ if (memberError) return void 0;
270
+ if (members.length === 0) {
271
+ diagnostics?.push({
272
+ code: PSL_NATIVE_ENUM_MISSING_MEMBERS,
273
+ message: `native_enum "${block.name}" must have at least one member`,
274
+ sourceId,
275
+ span: block.span
276
+ });
277
+ return;
278
+ }
279
+ return new PostgresNativeEnum({
280
+ typeName,
281
+ members
282
+ });
283
+ }
284
+ /**
285
+ * `native_enum`'s entity-type factory output, checked separately from the assembled
286
+ * `postgresAuthoringEntityTypes` map below: `deriveValueSet` is SQL-family surface
287
+ * ({@link SqlValueSetDerivingEntityTypeOutput}), not part of the framework
288
+ * `AuthoringEntityTypeFactoryOutput` shape, so folding it directly into the map's single
289
+ * `satisfies AuthoringEntityTypeNamespace` check would trip an excess-property error. Checking it
290
+ * here against the intersection of both shapes keeps it structurally valid against each without
291
+ * widening the map's own check.
292
+ */
293
+ const nativeEnumEntityTypeOutput = {
294
+ factory: lowerNativeEnumFromBlock,
295
+ deriveValueSet: (entity) => ({
296
+ kind: "valueSet",
297
+ values: [...entity.members]
298
+ })
299
+ };
300
+ /**
301
+ * Lowers a `role <name> {}` block into a {@link PostgresRole}. Roles are
302
+ * cluster-scoped in Postgres, so the block must be declared inside
303
+ * `namespace unbound { … }` — any other lexical namespace (a named schema,
304
+ * or the default bucket top-level declarations resolve to) is a load-time
305
+ * diagnostic. The lowered entity carries the unbound coordinate.
306
+ */
307
+ function lowerRoleFromBlock(block, ctx) {
308
+ if (block.namespaceId !== UNBOUND_NAMESPACE_ID) {
309
+ ctx.diagnostics?.push({
310
+ code: PSL_ROLE_BLOCK_OUTSIDE_UNBOUND_NAMESPACE,
311
+ message: `\`role\` block "${block.name}" must be declared inside \`namespace unbound { }\`, not in namespace "${block.namespaceId}"`,
312
+ sourceId: ctx.sourceId ?? "unknown",
313
+ span: block.span
314
+ });
315
+ return;
316
+ }
317
+ return new PostgresRole({
318
+ name: block.name,
319
+ namespaceId: UNBOUND_NAMESPACE_ID
320
+ });
321
+ }
322
+ const postgresAuthoringEntityTypes = {
323
+ role: {
324
+ kind: "entity",
325
+ discriminator: "role",
326
+ validatorSchema: PostgresRoleSchema,
327
+ output: { factory: lowerRoleFromBlock }
328
+ },
329
+ rls: {
330
+ kind: "entity",
331
+ discriminator: "rls",
332
+ validatorSchema: PostgresRlsEnablementSchema,
333
+ output: { factory: (input) => new PostgresRlsEnablement(input) }
334
+ },
335
+ policy: {
336
+ kind: "entity",
337
+ discriminator: "policy",
338
+ validatorSchema: PostgresRlsPolicySchema,
339
+ output: { factory: lowerRlsPolicyFromBlock }
340
+ },
341
+ native_enum: {
342
+ kind: "entity",
343
+ discriminator: "native_enum",
344
+ validatorSchema: PostgresNativeEnumSchema,
345
+ output: nativeEnumEntityTypeOutput
346
+ }
347
+ };
348
+ /**
349
+ * Field presets contributed by the Postgres target pack.
350
+ *
351
+ * These mirror the PSL scalar-to-codec mapping used by the Postgres adapter
352
+ * (see `createPostgresPslScalarTypeDescriptors`), so that authoring a field
353
+ * via the TS callback surface (e.g. `field.int()`) and via the PSL scalar
354
+ * surface (e.g. `Int`) lowers to byte-identical contracts.
355
+ *
356
+ * The `uuidNative` / `id.uuidv4Native` / `id.uuidv7Native` presets use the
357
+ * native Postgres `uuid` type (codecId `pg/uuid@1`). For cross-target
358
+ * portability use `uuidString` / `id.uuidv4String` / `id.uuidv7String` from
359
+ * the family pack instead.
360
+ */
361
+ /**
362
+ * Shared parameter descriptors for the five `policy_<op>` PSL block
363
+ * keywords. All five share the `policy` discriminator — the parser
364
+ * dispatches by keyword (see the framework's PSL-block SPI), and every
365
+ * keyword's factory lowers to `PostgresRlsPolicy` via `lowerRlsPolicyFromBlock`.
366
+ *
367
+ * The `roles` list uses `scope:'cross-space'` because same-namespace
368
+ * role ref resolution requires PSL namespace entries keyed by `refKind`
369
+ * (i.e. `'role'`), which in turn requires the role block discriminator to
370
+ * equal `'role'`. Aligning discriminator with refKind is tracked for
371
+ * slice 4 (cross-space roles). Until then cross-space passes validation
372
+ * unconditionally and the authored role names flow through unchanged.
373
+ */
374
+ const policyTargetParam = {
375
+ kind: "ref",
376
+ refKind: "model",
377
+ scope: "same-namespace",
378
+ required: true
379
+ };
380
+ const policyRolesParam = {
381
+ kind: "list",
382
+ of: {
383
+ kind: "ref",
384
+ refKind: "role",
385
+ scope: "cross-space"
386
+ }
387
+ };
388
+ const policyPredicateParam = {
389
+ kind: "value",
390
+ codecId: "pg/text@1",
391
+ required: true
392
+ };
393
+ const policyPermissiveParam = {
394
+ kind: "value",
395
+ codecId: "pg/bool@1"
396
+ };
397
+ const policyRequiresRls = {
398
+ parameter: "target",
399
+ attribute: "rls"
400
+ };
401
+ const postgresAuthoringPslBlockDescriptors = {
402
+ policy_select: {
403
+ kind: "pslBlock",
404
+ keyword: "policy_select",
405
+ discriminator: "policy",
406
+ name: { required: true },
407
+ parameters: {
408
+ target: policyTargetParam,
409
+ roles: policyRolesParam,
410
+ using: policyPredicateParam,
411
+ permissive: policyPermissiveParam
412
+ },
413
+ requiresModelAttribute: policyRequiresRls
414
+ },
415
+ policy_delete: {
416
+ kind: "pslBlock",
417
+ keyword: "policy_delete",
418
+ discriminator: "policy",
419
+ name: { required: true },
420
+ parameters: {
421
+ target: policyTargetParam,
422
+ roles: policyRolesParam,
423
+ using: policyPredicateParam,
424
+ permissive: policyPermissiveParam
425
+ },
426
+ requiresModelAttribute: policyRequiresRls
427
+ },
428
+ policy_insert: {
429
+ kind: "pslBlock",
430
+ keyword: "policy_insert",
431
+ discriminator: "policy",
432
+ name: { required: true },
433
+ parameters: {
434
+ target: policyTargetParam,
435
+ roles: policyRolesParam,
436
+ withCheck: policyPredicateParam,
437
+ permissive: policyPermissiveParam
438
+ },
439
+ requiresModelAttribute: policyRequiresRls
440
+ },
441
+ policy_update: {
442
+ kind: "pslBlock",
443
+ keyword: "policy_update",
444
+ discriminator: "policy",
445
+ name: { required: true },
446
+ parameters: {
447
+ target: policyTargetParam,
448
+ roles: policyRolesParam,
449
+ using: policyPredicateParam,
450
+ withCheck: policyPredicateParam,
451
+ permissive: policyPermissiveParam
452
+ },
453
+ requiresModelAttribute: policyRequiresRls
454
+ },
455
+ policy_all: {
456
+ kind: "pslBlock",
457
+ keyword: "policy_all",
458
+ discriminator: "policy",
459
+ name: { required: true },
460
+ parameters: {
461
+ target: policyTargetParam,
462
+ roles: policyRolesParam,
463
+ using: policyPredicateParam,
464
+ withCheck: policyPredicateParam,
465
+ permissive: policyPermissiveParam
466
+ },
467
+ requiresModelAttribute: policyRequiresRls
468
+ },
469
+ /**
470
+ * PSL block descriptor for `native_enum`.
471
+ *
472
+ * Reuses the existing variadic-block mechanism (the same shape the SQL
473
+ * family's `enum` block ships): the body is an open `memberName = "value"`
474
+ * list. `variadicParameters: true` opens the block to arbitrary keys
475
+ * beyond the declared (empty) `parameters` set — the lowering factory
476
+ * (`lowerNativeEnumFromBlock`) turns the variadic entries into ordered
477
+ * members and rejects a bare (value-less) member.
478
+ */
479
+ native_enum: {
480
+ kind: "pslBlock",
481
+ keyword: "native_enum",
482
+ discriminator: "native_enum",
483
+ name: { required: true },
484
+ parameters: {},
485
+ variadicParameters: true
486
+ },
487
+ /**
488
+ * PSL block descriptor for `role` (e.g. `role anon {}`). Name-only, no
489
+ * parameters and no body content. Declared inside `namespace unbound { }`
490
+ * — see {@link lowerRoleFromBlock} for the placement check and the
491
+ * coordinate the lowered entity carries.
492
+ */
493
+ role: {
494
+ kind: "pslBlock",
495
+ keyword: "role",
496
+ discriminator: "role",
497
+ name: { required: true },
498
+ parameters: {}
499
+ }
500
+ };
501
+ /**
502
+ * `@@` model attributes contributed by the Postgres target pack.
503
+ *
504
+ * `@@rls` is argument-less: presence marks the model's table
505
+ * RLS-controlled. It lowers to a {@link PostgresRlsEnablement} marker in
506
+ * the namespace's `entries.rls`, keyed by the model's table name — the
507
+ * marker (never the policy set) is what drives
508
+ * `ENABLE`/`DISABLE ROW LEVEL SECURITY` planning.
509
+ */
510
+ const postgresAuthoringModelAttributes = { rls: {
511
+ kind: "modelAttribute",
512
+ attribute: "rls",
513
+ spec: modelAttribute("rls", {}),
514
+ lower: (_parsed, ctx) => ({
515
+ key: ctx.storageName,
516
+ entity: new PostgresRlsEnablement({
517
+ tableName: ctx.storageName,
518
+ namespaceId: ctx.namespaceId
519
+ })
520
+ })
521
+ } };
522
+ const postgresAuthoringFieldPresets = {
523
+ text: {
524
+ kind: "fieldPreset",
525
+ output: {
526
+ codecId: "pg/text@1",
527
+ nativeType: "text"
528
+ }
529
+ },
530
+ int: {
531
+ kind: "fieldPreset",
532
+ output: {
533
+ codecId: "pg/int4@1",
534
+ nativeType: "int4"
535
+ }
536
+ },
537
+ bigint: {
538
+ kind: "fieldPreset",
539
+ output: {
540
+ codecId: "pg/int8@1",
541
+ nativeType: "int8"
542
+ }
543
+ },
544
+ float: {
545
+ kind: "fieldPreset",
546
+ output: {
547
+ codecId: "pg/float8@1",
548
+ nativeType: "float8"
549
+ }
550
+ },
551
+ decimal: {
552
+ kind: "fieldPreset",
553
+ output: {
554
+ codecId: "pg/numeric@1",
555
+ nativeType: "numeric"
556
+ }
557
+ },
558
+ boolean: {
559
+ kind: "fieldPreset",
560
+ output: {
561
+ codecId: "pg/bool@1",
562
+ nativeType: "bool"
563
+ }
564
+ },
565
+ json: {
566
+ kind: "fieldPreset",
567
+ output: {
568
+ codecId: "pg/jsonb@1",
569
+ nativeType: "jsonb"
570
+ }
571
+ },
572
+ bytes: {
573
+ kind: "fieldPreset",
574
+ output: {
575
+ codecId: "pg/bytea@1",
576
+ nativeType: "bytea"
577
+ }
578
+ },
579
+ dateTime: {
580
+ kind: "fieldPreset",
581
+ output: {
582
+ codecId: "pg/timestamptz@1",
583
+ nativeType: "timestamptz"
584
+ }
585
+ },
586
+ temporal: {
587
+ .../* @__PURE__ */ temporalAuthoringPresets({
588
+ codecId: "pg/timestamptz@1",
589
+ nativeType: "timestamptz"
590
+ }),
591
+ timestamp: /* @__PURE__ */ temporalCodecPresetWithPrecision({
592
+ codecId: "pg/timestamp@1",
593
+ nativeType: "timestamp"
594
+ }),
595
+ timestamptz: /* @__PURE__ */ temporalCodecPresetWithPrecision({
596
+ codecId: "pg/timestamptz@1",
597
+ nativeType: "timestamptz"
598
+ })
599
+ },
600
+ uuidNative: {
601
+ kind: "fieldPreset",
602
+ output: {
603
+ codecId: "pg/uuid@1",
604
+ nativeType: "uuid"
605
+ }
606
+ },
607
+ id: {
608
+ uuidv4Native: {
609
+ kind: "fieldPreset",
610
+ output: {
611
+ codecId: "pg/uuid@1",
612
+ nativeType: "uuid",
613
+ executionDefaults: { onCreate: {
614
+ kind: "generator",
615
+ id: "uuidv4"
616
+ } },
617
+ id: true
618
+ }
619
+ },
620
+ uuidv7Native: {
621
+ kind: "fieldPreset",
622
+ output: {
623
+ codecId: "pg/uuid@1",
624
+ nativeType: "uuid",
625
+ executionDefaults: { onCreate: {
626
+ kind: "generator",
627
+ id: "uuidv7"
628
+ } },
629
+ id: true
630
+ }
631
+ }
632
+ }
633
+ };
634
+ /**
635
+ * Resolves an entity handle's `target` ref to a table coordinate of this
636
+ * contract, or throws the load-time diagnostic naming the handle: a
637
+ * cross-space target is rejected (you cannot CREATE POLICY on a table
638
+ * another space owns) and an unresolved target names the model.
639
+ */
640
+ function requireLocalTarget(refs, subject) {
641
+ const target = refs["target"];
642
+ if (target !== void 0 && target.kind === "resolved") return {
643
+ namespaceId: target.namespaceId,
644
+ tableName: target.tableName
645
+ };
646
+ if (target !== void 0 && target.kind === "cross-space") throw postgresError("CONTRACT.POLICY_INVALID", `defineContract: ${subject} targets model "${target.modelName ?? target.tableName}", which lives in another contract space. Policies and rlsEnabled entries must target a model declared in this contract.`, { meta: {
647
+ model: target.modelName ?? target.tableName,
648
+ reason: "cross-space-target"
649
+ } });
650
+ throw postgresError("CONTRACT.MODEL_UNKNOWN", `defineContract: ${subject} targets model "${target?.modelName ?? "<anonymous>"}", which is not in the contract's models. Add the model to \`models\`.`, { meta: { model: target?.modelName ?? "<anonymous>" } });
651
+ }
652
+ /**
653
+ * The SQL-family entity-handle batch lowering hook for the Postgres pack
654
+ * (`SqlEntityHandleLoweringContribution`). Receives every `entities` handle
655
+ * whose kind this pack registered — batch, so the cross-entity diagnostics
656
+ * (duplicate prefix, policy without rlsEnabled, duplicate role) can see
657
+ * sibling handles — and lowers them with the same keying and hash assembly
658
+ * as the PSL path: `policy` keyed by prefix (wire name via
659
+ * {@link buildRlsPolicyEntity}), `rls` keyed by table name, `role` keyed by
660
+ * name and filed under the default namespace (roles are declared
661
+ * contract-wide; PSL has no role block to set a precedent).
662
+ */
663
+ function postgresLowerEntityHandles(input) {
664
+ const enablements = /* @__PURE__ */ new Map();
665
+ const roles = /* @__PURE__ */ new Map();
666
+ const policies = [];
667
+ const coordinateKey = (coordinate) => `${coordinate.namespaceId} ${coordinate.tableName}`;
668
+ for (const { handle, refs } of input.handles) switch (handle.entityKind) {
669
+ case "rls": {
670
+ const coordinate = requireLocalTarget(refs, "an rlsEnabled entry");
671
+ const key = coordinateKey(coordinate);
672
+ if (!enablements.has(key)) enablements.set(key, {
673
+ coordinate,
674
+ entity: new PostgresRlsEnablement({
675
+ tableName: coordinate.tableName,
676
+ namespaceId: coordinate.namespaceId
677
+ })
678
+ });
679
+ break;
680
+ }
681
+ case "role": {
682
+ const roleHandle = blindCast(handle);
683
+ if (roles.has(roleHandle.name)) throw postgresError("CONTRACT.ROLE_INVALID", `defineContract: role "${roleHandle.name}" is declared more than once in the entities list.`, { meta: {
684
+ role: roleHandle.name,
685
+ reason: "duplicate"
686
+ } });
687
+ roles.set(roleHandle.name, new PostgresRole({
688
+ name: roleHandle.name,
689
+ namespaceId: UNBOUND_NAMESPACE_ID
690
+ }));
691
+ break;
692
+ }
693
+ case "policy": {
694
+ const policyHandle = blindCast(handle);
695
+ policies.push({
696
+ handle: policyHandle,
697
+ refs
698
+ });
699
+ break;
700
+ }
701
+ default: throw postgresError("CONTRACT.ENTITY_KIND_INVALID", `defineContract: the postgres pack does not lower "${handle.entityKind}" handles from the entities list.`, { meta: { entityKind: handle.entityKind } });
702
+ }
703
+ const rows = [];
704
+ const seenPrefixes = /* @__PURE__ */ new Set();
705
+ for (const { handle: policy, refs } of policies) {
706
+ const prefix = policy.name;
707
+ assertWireNamePrefixLength(prefix, "defineContract: policy prefix");
708
+ const coordinate = requireLocalTarget(refs, `policy "${prefix}"`);
709
+ if (!enablements.has(coordinateKey(coordinate))) {
710
+ const target = refs["target"];
711
+ throw postgresError("CONTRACT.POLICY_INVALID", `defineContract: policy "${prefix}" targets model "${target?.modelName ?? coordinate.tableName}", whose table is not RLS-enabled. Add rlsEnabled(<model>) to the entities list.`, { meta: {
712
+ prefix,
713
+ model: target?.modelName ?? coordinate.tableName,
714
+ reason: "target-not-rls-enabled"
715
+ } });
716
+ }
717
+ const prefixKey = `${coordinate.namespaceId} ${prefix}`;
718
+ if (seenPrefixes.has(prefixKey)) throw postgresError("CONTRACT.POLICY_INVALID", `defineContract: policy prefix "${prefix}" is declared more than once in namespace "${coordinate.namespaceId}". Policy prefixes must be unique per namespace.`, { meta: {
719
+ prefix,
720
+ namespaceId: coordinate.namespaceId,
721
+ reason: "duplicate-prefix"
722
+ } });
723
+ seenPrefixes.add(prefixKey);
724
+ const roleNames = [...new Set(policy.roles.map((roleHandle) => roleHandle.name))].sort();
725
+ rows.push({
726
+ namespaceId: coordinate.namespaceId,
727
+ entityKind: "policy",
728
+ key: prefix,
729
+ entity: buildRlsPolicyEntity({
730
+ prefix,
731
+ tableName: coordinate.tableName,
732
+ namespaceId: coordinate.namespaceId,
733
+ operation: policy.operation,
734
+ roles: roleNames,
735
+ ...ifDefined("using", policy.using),
736
+ ...ifDefined("withCheck", policy.withCheck)
737
+ })
738
+ });
739
+ }
740
+ for (const { coordinate, entity } of enablements.values()) rows.push({
741
+ namespaceId: coordinate.namespaceId,
742
+ entityKind: "rls",
743
+ key: coordinate.tableName,
744
+ entity
745
+ });
746
+ for (const [name, entity] of roles) rows.push({
747
+ namespaceId: UNBOUND_NAMESPACE_ID,
748
+ entityKind: "role",
749
+ key: name,
750
+ entity
751
+ });
752
+ return rows;
753
+ }
754
+ //#endregion
755
+ export { postgresAuthoringTypes as a, postgresAuthoringPslBlockDescriptors as i, postgresAuthoringFieldPresets as n, postgresLowerEntityHandles as o, postgresAuthoringModelAttributes as r, postgresAuthoringEntityTypes as t };
756
+
757
+ //# sourceMappingURL=authoring-03FwIL2k-kPjZAp3s.mjs.map