@prisma/orm-family-sql 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 (325) hide show
  1. package/LICENSE +201 -0
  2. package/README.md +28 -0
  3. package/dist/ast-BstHjAoG.mjs +325 -0
  4. package/dist/ast-BstHjAoG.mjs.map +1 -0
  5. package/dist/ast-DSuzmsWn.d.mts +287 -0
  6. package/dist/ast-DSuzmsWn.d.mts.map +1 -0
  7. package/dist/authoring-type-constructors-Blqoa2Ua-DyCmD6mp.mjs +316 -0
  8. package/dist/authoring-type-constructors-Blqoa2Ua-DyCmD6mp.mjs.map +1 -0
  9. package/dist/build-contract-DBCz_YSs-DO0wMHai.mjs +778 -0
  10. package/dist/build-contract-DBCz_YSs-DO0wMHai.mjs.map +1 -0
  11. package/dist/builder.d.mts +3 -0
  12. package/dist/builder.mjs +1 -0
  13. package/dist/builder__runtime.d.mts +42 -0
  14. package/dist/builder__runtime.d.mts.map +1 -0
  15. package/dist/builder__runtime.mjs +955 -0
  16. package/dist/builder__runtime.mjs.map +1 -0
  17. package/dist/builder__types.d.mts +3 -0
  18. package/dist/builder__types.mjs +1 -0
  19. package/dist/canonicalization-hooks-CYnW_sGn.d.mts +10 -0
  20. package/dist/canonicalization-hooks-CYnW_sGn.d.mts.map +1 -0
  21. package/dist/canonicalization-hooks-DfIc_lOO.mjs +87 -0
  22. package/dist/canonicalization-hooks-DfIc_lOO.mjs.map +1 -0
  23. package/dist/codec-descriptor-registry-BJVJRftS.mjs +96 -0
  24. package/dist/codec-descriptor-registry-BJVJRftS.mjs.map +1 -0
  25. package/dist/codec-types-MOaceoPi-C5eL2sao.d.mts +116 -0
  26. package/dist/codec-types-MOaceoPi-C5eL2sao.d.mts.map +1 -0
  27. package/dist/config-types-47qB33rW.d.mts +21 -0
  28. package/dist/config-types-47qB33rW.d.mts.map +1 -0
  29. package/dist/config-types-N7PJc6VN.mjs +65 -0
  30. package/dist/config-types-N7PJc6VN.mjs.map +1 -0
  31. package/dist/contract-builder-MvJJrQ-5.d.mts +1306 -0
  32. package/dist/contract-builder-MvJJrQ-5.d.mts.map +1 -0
  33. package/dist/contract-builder-YjMQcvZ1.mjs +1615 -0
  34. package/dist/contract-builder-YjMQcvZ1.mjs.map +1 -0
  35. package/dist/contract-emitter.d.mts +25 -0
  36. package/dist/contract-emitter.d.mts.map +1 -0
  37. package/dist/contract-emitter.mjs +2 -0
  38. package/dist/contract-errors-BCN6RVI5-5IHBF_lg.mjs +9 -0
  39. package/dist/contract-errors-BCN6RVI5-5IHBF_lg.mjs.map +1 -0
  40. package/dist/contract-psl.d.mts +65 -0
  41. package/dist/contract-psl.d.mts.map +1 -0
  42. package/dist/contract-psl.mjs +2 -0
  43. package/dist/contract-psl__provider.d.mts +23 -0
  44. package/dist/contract-psl__provider.d.mts.map +1 -0
  45. package/dist/contract-psl__provider.mjs +105 -0
  46. package/dist/contract-psl__provider.mjs.map +1 -0
  47. package/dist/contract-ts.d.mts +3 -0
  48. package/dist/contract-ts.mjs +4 -0
  49. package/dist/contract-ts__config-types.d.mts +2 -0
  50. package/dist/contract-ts__config-types.mjs +2 -0
  51. package/dist/contract-ts__contract-builder.d.mts +2 -0
  52. package/dist/contract-ts__contract-builder.mjs +3 -0
  53. package/dist/contract-view-BMR5IWk4.mjs +39 -0
  54. package/dist/contract-view-BMR5IWk4.mjs.map +1 -0
  55. package/dist/contract-view-BbWQp6r4.d.mts +61 -0
  56. package/dist/contract-view-BbWQp6r4.d.mts.map +1 -0
  57. package/dist/contract.d.mts +26 -0
  58. package/dist/contract.mjs +17 -0
  59. package/dist/contract__canonicalization-hooks.d.mts +2 -0
  60. package/dist/contract__canonicalization-hooks.mjs +2 -0
  61. package/dist/contract__contract-view.d.mts +2 -0
  62. package/dist/contract__contract-view.mjs +2 -0
  63. package/dist/contract__entity-handle-lowering-hook.d.mts +2 -0
  64. package/dist/contract__entity-handle-lowering-hook.mjs +2 -0
  65. package/dist/contract__entity-kinds.d.mts +2 -0
  66. package/dist/contract__entity-kinds.mjs +2 -0
  67. package/dist/contract__factories.d.mts +2 -0
  68. package/dist/contract__factories.mjs +2 -0
  69. package/dist/contract__foreign-key-materialization.d.mts +2 -0
  70. package/dist/contract__foreign-key-materialization.mjs +2 -0
  71. package/dist/contract__index-naming.d.mts +2 -0
  72. package/dist/contract__index-naming.mjs +2 -0
  73. package/dist/contract__index-type-validation.d.mts +2 -0
  74. package/dist/contract__index-type-validation.mjs +2 -0
  75. package/dist/contract__index-types.d.mts +3 -0
  76. package/dist/contract__index-types.mjs +2 -0
  77. package/dist/contract__pack-types.d.mts +2 -0
  78. package/dist/contract__pack-types.mjs +1 -0
  79. package/dist/contract__referential-action-sql.d.mts +2 -0
  80. package/dist/contract__referential-action-sql.mjs +2 -0
  81. package/dist/contract__resolve-storage-table.d.mts +2 -0
  82. package/dist/contract__resolve-storage-table.mjs +2 -0
  83. package/dist/contract__types.d.mts +11 -0
  84. package/dist/contract__types.mjs +4 -0
  85. package/dist/contract__validators.d.mts +2 -0
  86. package/dist/contract__validators.mjs +3 -0
  87. package/dist/contract__value-set-derivation-hook.d.mts +2 -0
  88. package/dist/contract__value-set-derivation-hook.mjs +2 -0
  89. package/dist/control-B7iS4jv4.mjs +1326 -0
  90. package/dist/control-B7iS4jv4.mjs.map +1 -0
  91. package/dist/control-BHmsZudH.d.mts +948 -0
  92. package/dist/control-BHmsZudH.d.mts.map +1 -0
  93. package/dist/control-adapter-4y1O8Ps3.d.mts +1 -0
  94. package/dist/control-adapter-C99J7aEF-C-17lFY8.d.mts +191 -0
  95. package/dist/control-adapter-C99J7aEF-C-17lFY8.d.mts.map +1 -0
  96. package/dist/db-DhMsmBS--DKENDi3l.d.mts +365 -0
  97. package/dist/db-DhMsmBS--DKENDi3l.d.mts.map +1 -0
  98. package/dist/ddl-types-BMp2bWVS-D1waZJ4n.mjs +153 -0
  99. package/dist/ddl-types-BMp2bWVS-D1waZJ4n.mjs.map +1 -0
  100. package/dist/ddl-types-rrMsf77U-DGctYf-T.d.mts +149 -0
  101. package/dist/ddl-types-rrMsf77U-DGctYf-T.d.mts.map +1 -0
  102. package/dist/diff-B16bL_IR.mjs +13 -0
  103. package/dist/diff-B16bL_IR.mjs.map +1 -0
  104. package/dist/diff-DhlzHOMD.d.mts +104 -0
  105. package/dist/diff-DhlzHOMD.d.mts.map +1 -0
  106. package/dist/dist-C_q1_QR9.mjs +9 -0
  107. package/dist/dist-C_q1_QR9.mjs.map +1 -0
  108. package/dist/dist-DrScXbhq.mjs +414 -0
  109. package/dist/dist-DrScXbhq.mjs.map +1 -0
  110. package/dist/dist-x6jvtkKM.mjs +68 -0
  111. package/dist/dist-x6jvtkKM.mjs.map +1 -0
  112. package/dist/entity-handle-lowering-hook-CIvRKBfa.d.mts +92 -0
  113. package/dist/entity-handle-lowering-hook-CIvRKBfa.d.mts.map +1 -0
  114. package/dist/entity-handle-lowering-hook-DwLIKNiS.mjs +11 -0
  115. package/dist/entity-handle-lowering-hook-DwLIKNiS.mjs.map +1 -0
  116. package/dist/entity-kinds-DKxwKolf-CcsY-iYV.mjs +136 -0
  117. package/dist/entity-kinds-DKxwKolf-CcsY-iYV.mjs.map +1 -0
  118. package/dist/entity-kinds-Dh6VH4uK.d.mts +29 -0
  119. package/dist/entity-kinds-Dh6VH4uK.d.mts.map +1 -0
  120. package/dist/errors-B5g0xWro-mWH2C07F.mjs +9 -0
  121. package/dist/errors-B5g0xWro-mWH2C07F.mjs.map +1 -0
  122. package/dist/errors.d.mts +63 -0
  123. package/dist/errors.d.mts.map +1 -0
  124. package/dist/errors.mjs +2 -0
  125. package/dist/expression-DIf8F4Mc.d.mts +167 -0
  126. package/dist/expression-DIf8F4Mc.d.mts.map +1 -0
  127. package/dist/expression-RUO52bJB.mjs +109 -0
  128. package/dist/expression-RUO52bJB.mjs.map +1 -0
  129. package/dist/factories-B7tA4y9D.d.mts +39 -0
  130. package/dist/factories-B7tA4y9D.d.mts.map +1 -0
  131. package/dist/factories-CDG9zBxC.mjs +77 -0
  132. package/dist/factories-CDG9zBxC.mjs.map +1 -0
  133. package/dist/family.d.mts +13 -0
  134. package/dist/family.mjs +12 -0
  135. package/dist/family__control-adapter.d.mts +3 -0
  136. package/dist/family__control-adapter.mjs +1 -0
  137. package/dist/family__control.d.mts +4 -0
  138. package/dist/family__control.mjs +4 -0
  139. package/dist/family__diff.d.mts +3 -0
  140. package/dist/family__diff.mjs +3 -0
  141. package/dist/family__ir.d.mts +2 -0
  142. package/dist/family__ir.mjs +3 -0
  143. package/dist/family__migration.d.mts +2 -0
  144. package/dist/family__migration.mjs +2 -0
  145. package/dist/family__pack.d.mts +249 -0
  146. package/dist/family__pack.d.mts.map +1 -0
  147. package/dist/family__pack.mjs +18 -0
  148. package/dist/family__pack.mjs.map +1 -0
  149. package/dist/family__psl-infer.d.mts +2 -0
  150. package/dist/family__psl-infer.mjs +2 -0
  151. package/dist/family__runtime.d.mts +3 -0
  152. package/dist/family__runtime.mjs +3 -0
  153. package/dist/family__verify.d.mts +2 -0
  154. package/dist/family__verify.mjs +2 -0
  155. package/dist/foreign-key-BSy9u4O4-BnsOe5Nf.d.mts +85 -0
  156. package/dist/foreign-key-BSy9u4O4-BnsOe5Nf.d.mts.map +1 -0
  157. package/dist/foreign-key-materialization-Ca-wRbmj.d.mts +65 -0
  158. package/dist/foreign-key-materialization-Ca-wRbmj.d.mts.map +1 -0
  159. package/dist/foreign-key-materialization-HI7BIQrG.mjs +72 -0
  160. package/dist/foreign-key-materialization-HI7BIQrG.mjs.map +1 -0
  161. package/dist/index-Bb9U36N4.d.mts +511 -0
  162. package/dist/index-Bb9U36N4.d.mts.map +1 -0
  163. package/dist/index-BgaTJRxj.d.mts +25 -0
  164. package/dist/index-BgaTJRxj.d.mts.map +1 -0
  165. package/dist/index-naming-BZWoh45T.d.mts +62 -0
  166. package/dist/index-naming-BZWoh45T.d.mts.map +1 -0
  167. package/dist/index-naming-BoGBcMmI-DiJAr66H.mjs +108 -0
  168. package/dist/index-naming-BoGBcMmI-DiJAr66H.mjs.map +1 -0
  169. package/dist/index-type-validation-COH4d78M.mjs +17 -0
  170. package/dist/index-type-validation-COH4d78M.mjs.map +1 -0
  171. package/dist/index-type-validation-DN0L2mqm.d.mts +10 -0
  172. package/dist/index-type-validation-DN0L2mqm.d.mts.map +1 -0
  173. package/dist/index-types-CNhHgKHi.d.mts +1 -0
  174. package/dist/index-types-DJQ_xwaE.mjs +40 -0
  175. package/dist/index-types-DJQ_xwaE.mjs.map +1 -0
  176. package/dist/index-types-DPVhsW0v-D-BikM4h.d.mts +31 -0
  177. package/dist/index-types-DPVhsW0v-D-BikM4h.d.mts.map +1 -0
  178. package/dist/interpreter-5WgpL-ax-_nqHLUTr.mjs +3526 -0
  179. package/dist/interpreter-5WgpL-ax-_nqHLUTr.mjs.map +1 -0
  180. package/dist/ir-B3bKMnGQ.d.mts +123 -0
  181. package/dist/ir-B3bKMnGQ.d.mts.map +1 -0
  182. package/dist/ir-I-xciGUH.mjs +36 -0
  183. package/dist/ir-I-xciGUH.mjs.map +1 -0
  184. package/dist/lane-query-builder.d.mts +236 -0
  185. package/dist/lane-query-builder.d.mts.map +1 -0
  186. package/dist/lane-query-builder.mjs +67 -0
  187. package/dist/lane-query-builder.mjs.map +1 -0
  188. package/dist/middleware-B4XbF4d4-tfwBl6mX.d.mts +119 -0
  189. package/dist/middleware-B4XbF4d4-tfwBl6mX.d.mts.map +1 -0
  190. package/dist/middleware-ByRsXxxq.d.mts +1 -0
  191. package/dist/middleware-CMr4CHNz-DHIUdxlm.mjs +80 -0
  192. package/dist/middleware-CMr4CHNz-DHIUdxlm.mjs.map +1 -0
  193. package/dist/migration-CK4oePIo.mjs +44 -0
  194. package/dist/migration-CK4oePIo.mjs.map +1 -0
  195. package/dist/migration-CW0ZJLxP.d.mts +44 -0
  196. package/dist/migration-CW0ZJLxP.d.mts.map +1 -0
  197. package/dist/naming-BwqqVcZy-BgTObIQw.mjs +177 -0
  198. package/dist/naming-BwqqVcZy-BgTObIQw.mjs.map +1 -0
  199. package/dist/naming-jLgdauLi-C84G_UHi.d.mts +133 -0
  200. package/dist/naming-jLgdauLi-C84G_UHi.d.mts.map +1 -0
  201. package/dist/operations.d.mts +2 -0
  202. package/dist/operations.mjs +2 -0
  203. package/dist/orm-client.d.mts +1316 -0
  204. package/dist/orm-client.d.mts.map +1 -0
  205. package/dist/orm-client.mjs +4544 -0
  206. package/dist/orm-client.mjs.map +1 -0
  207. package/dist/pack-types-BcLTpwbv.d.mts +14 -0
  208. package/dist/pack-types-BcLTpwbv.d.mts.map +1 -0
  209. package/dist/plan-BTD8xFfa-Dd_K-A1R.d.mts +45 -0
  210. package/dist/plan-BTD8xFfa-Dd_K-A1R.d.mts.map +1 -0
  211. package/dist/plan-CkpcgUaM.mjs +34 -0
  212. package/dist/plan-CkpcgUaM.mjs.map +1 -0
  213. package/dist/plan-Cm4jaoNM.d.mts +2 -0
  214. package/dist/psl-infer-6je61Z6J.d.mts +119 -0
  215. package/dist/psl-infer-6je61Z6J.d.mts.map +1 -0
  216. package/dist/psl-infer-DGftl-HW.mjs +362 -0
  217. package/dist/psl-infer-DGftl-HW.mjs.map +1 -0
  218. package/dist/query-lane-context-Bz8XJZ45.d.mts +1 -0
  219. package/dist/query-lane-context-DtdVMqoz-C2Tj5QHA.d.mts +94 -0
  220. package/dist/query-lane-context-DtdVMqoz-C2Tj5QHA.d.mts.map +1 -0
  221. package/dist/referential-action-sql-Csd6dA8G.d.mts +12 -0
  222. package/dist/referential-action-sql-Csd6dA8G.d.mts.map +1 -0
  223. package/dist/referential-action-sql-DSqkrySN.mjs +17 -0
  224. package/dist/referential-action-sql-DSqkrySN.mjs.map +1 -0
  225. package/dist/relational-core.d.mts +13 -0
  226. package/dist/relational-core.mjs +8 -0
  227. package/dist/relational-core__ast.d.mts +5 -0
  228. package/dist/relational-core__ast.mjs +5 -0
  229. package/dist/relational-core__codec-descriptor-registry.d.mts +39 -0
  230. package/dist/relational-core__codec-descriptor-registry.d.mts.map +1 -0
  231. package/dist/relational-core__codec-descriptor-registry.mjs +2 -0
  232. package/dist/relational-core__contract-free.d.mts +220 -0
  233. package/dist/relational-core__contract-free.d.mts.map +1 -0
  234. package/dist/relational-core__contract-free.mjs +393 -0
  235. package/dist/relational-core__contract-free.mjs.map +1 -0
  236. package/dist/relational-core__expression.d.mts +2 -0
  237. package/dist/relational-core__expression.mjs +2 -0
  238. package/dist/relational-core__middleware.d.mts +3 -0
  239. package/dist/relational-core__middleware.mjs +2 -0
  240. package/dist/relational-core__plan.d.mts +4 -0
  241. package/dist/relational-core__plan.mjs +2 -0
  242. package/dist/relational-core__query-lane-context.d.mts +3 -0
  243. package/dist/relational-core__query-lane-context.mjs +1 -0
  244. package/dist/relational-core__types.d.mts +3 -0
  245. package/dist/relational-core__types.mjs +1 -0
  246. package/dist/resolve-storage-table-DUwyRJmP.d.mts +21 -0
  247. package/dist/resolve-storage-table-DUwyRJmP.d.mts.map +1 -0
  248. package/dist/resolve-storage-table-DZsfnzeW.mjs +46 -0
  249. package/dist/resolve-storage-table-DZsfnzeW.mjs.map +1 -0
  250. package/dist/runtime-DNewRuec.d.mts +46 -0
  251. package/dist/runtime-DNewRuec.d.mts.map +1 -0
  252. package/dist/runtime-tIHpGCcG.mjs +55 -0
  253. package/dist/runtime-tIHpGCcG.mjs.map +1 -0
  254. package/dist/runtime.d.mts +4 -0
  255. package/dist/runtime.mjs +1606 -0
  256. package/dist/runtime.mjs.map +1 -0
  257. package/dist/schema-differ-DpG_gnur-g5_iks8G.d.mts +47 -0
  258. package/dist/schema-differ-DpG_gnur-g5_iks8G.d.mts.map +1 -0
  259. package/dist/schema-ir.d.mts +2 -0
  260. package/dist/schema-ir.mjs +2 -0
  261. package/dist/schema-ir__naming.d.mts +2 -0
  262. package/dist/schema-ir__naming.mjs +2 -0
  263. package/dist/schema-ir__types.d.mts +3 -0
  264. package/dist/schema-ir__types.mjs +2 -0
  265. package/dist/schema-verify-vtFZbmGq-BNfTr6fU.mjs +222 -0
  266. package/dist/schema-verify-vtFZbmGq-BNfTr6fU.mjs.map +1 -0
  267. package/dist/serialized-index-B96AwqtU-DcqcB4q_.d.mts +26 -0
  268. package/dist/serialized-index-B96AwqtU-DcqcB4q_.d.mts.map +1 -0
  269. package/dist/serialized-index-Dp5_EjXD-DMsw8jf3.mjs +64 -0
  270. package/dist/serialized-index-Dp5_EjXD-DMsw8jf3.mjs.map +1 -0
  271. package/dist/sql-contract-serializer-2oBWuxTe-B9hzBBv1.mjs +171 -0
  272. package/dist/sql-contract-serializer-2oBWuxTe-B9hzBBv1.mjs.map +1 -0
  273. package/dist/sql-execution-plan-CJmsCP7n-DoEpNn7r.d.mts +32 -0
  274. package/dist/sql-execution-plan-CJmsCP7n-DoEpNn7r.d.mts.map +1 -0
  275. package/dist/sql-index-DsI8HAeK-BJsn-jvD.d.mts +72 -0
  276. package/dist/sql-index-DsI8HAeK-BJsn-jvD.d.mts.map +1 -0
  277. package/dist/sql-node-kEz6YFZo-v2F7delx.d.mts +42 -0
  278. package/dist/sql-node-kEz6YFZo-v2F7delx.d.mts.map +1 -0
  279. package/dist/sql-storage-B0QwiTg6-B8DVctJm.d.mts +171 -0
  280. package/dist/sql-storage-B0QwiTg6-B8DVctJm.d.mts.map +1 -0
  281. package/dist/storage-table-BBaAmanc-BwR37LMA.d.mts +130 -0
  282. package/dist/storage-table-BBaAmanc-BwR37LMA.d.mts.map +1 -0
  283. package/dist/storage-table-_LWDmPfv-DFhU2dML.mjs +277 -0
  284. package/dist/storage-table-_LWDmPfv-DFhU2dML.mjs.map +1 -0
  285. package/dist/storage-value-set-BGlj5Uus-CvZD--GG.d.mts +41 -0
  286. package/dist/storage-value-set-BGlj5Uus-CvZD--GG.d.mts.map +1 -0
  287. package/dist/timestamp-now-generator-DRXygu32-DN9Qb1uI.mjs +173 -0
  288. package/dist/timestamp-now-generator-DRXygu32-DN9Qb1uI.mjs.map +1 -0
  289. package/dist/types-BchwQpmO.d.mts +16 -0
  290. package/dist/types-BchwQpmO.d.mts.map +1 -0
  291. package/dist/types-BgkZru_1-H7yfikSQ.mjs +1444 -0
  292. package/dist/types-BgkZru_1-H7yfikSQ.mjs.map +1 -0
  293. package/dist/types-CMMQS6aG.mjs +111 -0
  294. package/dist/types-CMMQS6aG.mjs.map +1 -0
  295. package/dist/types-CuDrWc5v-ISVXBmBs.d.mts +134 -0
  296. package/dist/types-CuDrWc5v-ISVXBmBs.d.mts.map +1 -0
  297. package/dist/types-CvbBw1Jo-3KQdErJY.d.mts +688 -0
  298. package/dist/types-CvbBw1Jo-3KQdErJY.d.mts.map +1 -0
  299. package/dist/types-DIBA80mc-wf5wLmON.d.mts +723 -0
  300. package/dist/types-DIBA80mc-wf5wLmON.d.mts.map +1 -0
  301. package/dist/types-DMxc5KZa.d.mts +1 -0
  302. package/dist/types-Dl20lxky-DC_jdA0T.d.mts +247 -0
  303. package/dist/types-Dl20lxky-DC_jdA0T.d.mts.map +1 -0
  304. package/dist/types-DmhUVq4u-BpqqjPJx.mjs +719 -0
  305. package/dist/types-DmhUVq4u-BpqqjPJx.mjs.map +1 -0
  306. package/dist/types-IqZMLrFC-DtdJNICr.d.mts +426 -0
  307. package/dist/types-IqZMLrFC-DtdJNICr.d.mts.map +1 -0
  308. package/dist/types-TvBZ2Ne9.d.mts +1 -0
  309. package/dist/unique-constraint-jQWfH7dg-zLWtFp99.d.mts +32 -0
  310. package/dist/unique-constraint-jQWfH7dg-zLWtFp99.d.mts.map +1 -0
  311. package/dist/util-DQQgv2j1-D6INZaRG.mjs +34 -0
  312. package/dist/util-DQQgv2j1-D6INZaRG.mjs.map +1 -0
  313. package/dist/validators-C4PItWnf.mjs +0 -0
  314. package/dist/validators-C4PItWnf.mjs.map +1 -0
  315. package/dist/validators-CxeHhHrf.d.mts +206 -0
  316. package/dist/validators-CxeHhHrf.d.mts.map +1 -0
  317. package/dist/value-set-derivation-hook-BhgGVtw0.d.mts +35 -0
  318. package/dist/value-set-derivation-hook-BhgGVtw0.d.mts.map +1 -0
  319. package/dist/value-set-derivation-hook-Di9JZ0X7.mjs +22 -0
  320. package/dist/value-set-derivation-hook-Di9JZ0X7.mjs.map +1 -0
  321. package/dist/verify-E6Dd2vYp-gYwnlhLm.mjs +86 -0
  322. package/dist/verify-E6Dd2vYp-gYwnlhLm.mjs.map +1 -0
  323. package/dist/verify-zDRnw0Rn.d.mts +26 -0
  324. package/dist/verify-zDRnw0Rn.d.mts.map +1 -0
  325. package/package.json +112 -0
@@ -0,0 +1,1326 @@
1
+ import { t as sqlContractCanonicalizationHooks } from "./canonicalization-hooks-DfIc_lOO.mjs";
2
+ import { s as namingOf } from "./naming-BwqqVcZy-BgTObIQw.mjs";
3
+ import { c as StorageTable } from "./storage-table-_LWDmPfv-DFhU2dML.mjs";
4
+ import { l as isStorageTypeInstance } from "./types-CMMQS6aG.mjs";
5
+ import { c as SqlSchemaIR, n as RelationalSchemaNodeKind, u as SqlTableIR } from "./types-DmhUVq4u-BpqqjPJx.mjs";
6
+ import { t as sqlEmission } from "./dist-DrScXbhq.mjs";
7
+ import { i as sqlFamilyPslBlockDescriptors, n as sqlFamilyAuthoringTypes, r as sqlFamilyEntityTypes, t as sqlFamilyAuthoringFieldPresets } from "./authoring-type-constructors-Blqoa2Ua-DyCmD6mp.mjs";
8
+ import { n as classifyDiffSubjectGranularity, o as extractCodecControlHooks, s as verifySqlSchemaByDiff, t as classifyDiffEntityKind } from "./schema-verify-vtFZbmGq-BNfTr6fU.mjs";
9
+ import { t as sqlFamilyError } from "./errors-B5g0xWro-mWH2C07F.mjs";
10
+ import { t as SqlContractSerializer } from "./sql-contract-serializer-2oBWuxTe-B9hzBBv1.mjs";
11
+ import { t as collectSupportedCodecTypeIds } from "./verify-E6Dd2vYp-gYwnlhLm.mjs";
12
+ import { isPlainRecord } from "@prisma/orm-framework/components/ir";
13
+ import { InternalError } from "@prisma/orm-framework/utils/internal-error";
14
+ import { effectiveControlPolicy } from "@prisma/orm-framework/contract/types";
15
+ import { blindCast } from "@prisma/orm-framework/utils/casts";
16
+ import { ifDefined } from "@prisma/orm-framework/utils/defined";
17
+ import { notOk, ok } from "@prisma/orm-framework/utils/result";
18
+ import { APP_SPACE_ID, SchemaTreeNode, VERIFY_CODE_HASH_MISMATCH, VERIFY_CODE_MARKER_MISSING, VERIFY_CODE_TARGET_MISMATCH, assembleAuthoringContributions } from "@prisma/orm-framework/components/control";
19
+ import { assertDescriptorSelfConsistency } from "@prisma/orm-toolchain/migration-tools/spaces";
20
+ //#region ../../../2-sql/9-family/dist/control.mjs
21
+ function isDdlStatement(sqlStatement) {
22
+ const trimmed = sqlStatement.trim().toLowerCase();
23
+ return trimmed.startsWith("create ") || trimmed.startsWith("alter ") || trimmed.startsWith("drop ");
24
+ }
25
+ function hasExecuteSteps(operation) {
26
+ const candidate = operation;
27
+ if (!("execute" in candidate) || !Array.isArray(candidate["execute"])) return false;
28
+ return candidate["execute"].every((step) => typeof step === "object" && step !== null && "sql" in step);
29
+ }
30
+ /**
31
+ * Extracts a best-effort SQL DDL preview for CLI plan output.
32
+ * Presentation-only: never used to decide migration correctness.
33
+ */
34
+ function extractSqlDdl(operations) {
35
+ const statements = [];
36
+ for (const operation of operations) {
37
+ if (!hasExecuteSteps(operation)) continue;
38
+ for (const step of operation.execute) if (typeof step.sql === "string" && isDdlStatement(step.sql)) statements.push(step.sql.trim());
39
+ }
40
+ return statements;
41
+ }
42
+ /**
43
+ * Wraps `extractSqlDdl` into the family-agnostic `OperationPreview` shape.
44
+ * Each statement carries `language: 'sql'`.
45
+ */
46
+ function sqlOperationsToPreview(operations) {
47
+ return { statements: extractSqlDdl(operations).map((text) => ({
48
+ text,
49
+ language: "sql"
50
+ })) };
51
+ }
52
+ function missingDescriptorOperationError(targetId, operation) {
53
+ return sqlFamilyError("CONTRACT.PACK_CONTRIBUTION_INVALID", `SQL target "${targetId}" is missing the required ${operation} descriptor operation`, {
54
+ why: `The target descriptor does not contribute the ${operation} operation the SQL family requires for this call.`,
55
+ fix: `Use a target package whose control descriptor implements ${operation}.`,
56
+ meta: {
57
+ targetId,
58
+ operation
59
+ }
60
+ });
61
+ }
62
+ function extractCodecTypeIdsFromContract(contract) {
63
+ const typeIds = /* @__PURE__ */ new Set();
64
+ if (typeof contract === "object" && contract !== null && "storage" in contract && typeof contract.storage === "object" && contract.storage !== null && "namespaces" in contract.storage && typeof contract.storage.namespaces === "object" && contract.storage.namespaces !== null) {
65
+ const namespaces = contract.storage.namespaces;
66
+ for (const ns of Object.values(namespaces)) {
67
+ const tbls = ns.entries["table"];
68
+ if (typeof tbls !== "object" || tbls === null) continue;
69
+ for (const table of Object.values(tbls)) if (typeof table === "object" && table !== null && "columns" in table && typeof table.columns === "object" && table.columns !== null) {
70
+ const columns = table.columns;
71
+ for (const column of Object.values(columns)) if (column && typeof column === "object" && "codecId" in column && typeof column.codecId === "string") typeIds.add(column.codecId);
72
+ }
73
+ }
74
+ }
75
+ return Array.from(typeIds).sort();
76
+ }
77
+ function createVerifyResult(options) {
78
+ const contract = { storageHash: options.contractStorageHash };
79
+ if (options.contractProfileHash) contract.profileHash = options.contractProfileHash;
80
+ const target = { expected: options.expectedTargetId };
81
+ if (options.actualTargetId) target.actual = options.actualTargetId;
82
+ const meta = { contractPath: options.contractPath };
83
+ if (options.configPath) meta.configPath = options.configPath;
84
+ const result = {
85
+ ok: options.ok,
86
+ summary: options.summary,
87
+ contract,
88
+ target,
89
+ meta,
90
+ timings: { total: options.totalTime }
91
+ };
92
+ if (options.code) result.code = options.code;
93
+ if (options.marker) result.marker = {
94
+ storageHash: options.marker.storageHash,
95
+ profileHash: options.marker.profileHash
96
+ };
97
+ if (options.missingCodecs) result.missingCodecs = options.missingCodecs;
98
+ if (options.codecCoverageSkipped) result.codecCoverageSkipped = options.codecCoverageSkipped;
99
+ return result;
100
+ }
101
+ function buildSqlTypeMetadataRegistry(options) {
102
+ const { target, adapter, extensions } = options;
103
+ const registry = /* @__PURE__ */ new Map();
104
+ const targetId = adapter.targetId;
105
+ const descriptors = [
106
+ target,
107
+ adapter,
108
+ ...extensions
109
+ ];
110
+ for (const descriptor of descriptors) {
111
+ const storageTypes = descriptor.types?.storage;
112
+ if (!storageTypes) continue;
113
+ for (const storageType of storageTypes) if (storageType.familyId === "sql" && storageType.targetId === targetId) registry.set(storageType.typeId, {
114
+ typeId: storageType.typeId,
115
+ familyId: "sql",
116
+ targetId: storageType.targetId,
117
+ ...storageType.nativeType !== void 0 ? { nativeType: storageType.nativeType } : {}
118
+ });
119
+ }
120
+ return registry;
121
+ }
122
+ /**
123
+ * Builds a map from each extension id to the set of extension ids it
124
+ * transitively depends on. Uses the same declared-dependency data that
125
+ * `buildExtensionLoadOrder` in control-stack uses.
126
+ */
127
+ function buildTransitiveDependsOnMap(extensions) {
128
+ const directDeps = /* @__PURE__ */ new Map();
129
+ for (const ext of extensions) {
130
+ const packs = ext.contractSpace?.contractJson?.extensions;
131
+ const deps = packs !== null && typeof packs === "object" ? Object.keys(packs) : [];
132
+ directDeps.set(ext.id, deps);
133
+ }
134
+ const result = /* @__PURE__ */ new Map();
135
+ const resolve = (id, visiting) => {
136
+ const cached = result.get(id);
137
+ if (cached !== void 0) return cached;
138
+ const set = /* @__PURE__ */ new Set();
139
+ result.set(id, set);
140
+ for (const depId of directDeps.get(id) ?? []) {
141
+ set.add(depId);
142
+ if (!visiting.has(depId)) {
143
+ visiting.add(depId);
144
+ for (const transitive of resolve(depId, visiting)) set.add(transitive);
145
+ visiting.delete(depId);
146
+ }
147
+ }
148
+ return set;
149
+ };
150
+ for (const ext of extensions) resolve(ext.id, /* @__PURE__ */ new Set([ext.id]));
151
+ return result;
152
+ }
153
+ /**
154
+ * Asserts that no cross-space FK in any extension points against the
155
+ * dependency direction.
156
+ *
157
+ * A cross-space FK (target.spaceId present) from extension A pointing at
158
+ * space B is a violation when B depends on A (directly or transitively),
159
+ * because that means A is pointing "upward" against the dependency arrows
160
+ * established by the extension load order.
161
+ *
162
+ * Throws with a diagnostic naming the violating extension (source), the
163
+ * target space, and the direction violation.
164
+ */
165
+ function isObjectRecord(v) {
166
+ return typeof v === "object" && v !== null;
167
+ }
168
+ function assertNoCrossSpaceFkReverseReferences(extensions) {
169
+ const dependsOnMap = buildTransitiveDependsOnMap(extensions);
170
+ for (const ext of extensions) {
171
+ const namespaces = ext.contractSpace?.contractJson?.storage?.namespaces;
172
+ if (!isObjectRecord(namespaces)) continue;
173
+ for (const ns of Object.values(namespaces)) {
174
+ if (!isObjectRecord(ns)) continue;
175
+ const entries = ns["entries"];
176
+ if (!isObjectRecord(entries)) continue;
177
+ for (const slot of Object.values(entries)) {
178
+ if (!isObjectRecord(slot)) continue;
179
+ for (const table of Object.values(slot)) {
180
+ if (!isObjectRecord(table)) continue;
181
+ const foreignKeys = table["foreignKeys"];
182
+ if (!Array.isArray(foreignKeys)) continue;
183
+ for (const fk of foreignKeys) {
184
+ if (!isObjectRecord(fk)) continue;
185
+ const target = fk["target"];
186
+ if (!isObjectRecord(target)) continue;
187
+ if (target["spaceId"] === void 0) continue;
188
+ const targetSpaceId = target["spaceId"];
189
+ if (typeof targetSpaceId !== "string") continue;
190
+ if (dependsOnMap.get(targetSpaceId)?.has(ext.id)) throw sqlFamilyError("CONTRACT.FOREIGN_KEY_INVALID", `Cross-space FK reverse-reference detected: extension "${ext.id}" has a cross-space FK targeting space "${targetSpaceId}", but "${targetSpaceId}" depends on "${ext.id}". Cross-space FKs must follow the dependency direction (a space can only reference spaces it depends on, not spaces that depend on it).`, {
191
+ why: "The foreign key points against the contract-space dependency direction.",
192
+ fix: "Move the foreign key to the depending space, or restructure the extension dependencies so the referencing space depends on the referenced one.",
193
+ meta: {
194
+ extensionId: ext.id,
195
+ targetSpaceId
196
+ }
197
+ });
198
+ }
199
+ }
200
+ }
201
+ }
202
+ }
203
+ }
204
+ function createSqlFamilyInstance(stack) {
205
+ if (!stack.adapter) throw new InternalError("SQL family requires an adapter descriptor in ControlStack");
206
+ const target = stack.target;
207
+ const adapter = stack.adapter;
208
+ const extensions = stack.extensions;
209
+ for (const extension of extensions) if (extension.contractSpace) {
210
+ const { contractJson, headRef } = extension.contractSpace;
211
+ assertDescriptorSelfConsistency({
212
+ extensionId: extension.id,
213
+ target: contractJson.target,
214
+ targetFamily: contractJson.targetFamily,
215
+ storage: contractJson.storage,
216
+ headRefHash: headRef.hash,
217
+ ...sqlContractCanonicalizationHooks
218
+ });
219
+ }
220
+ assertNoCrossSpaceFkReverseReferences(extensions);
221
+ const { codecTypeImports, extensionIds } = stack;
222
+ const typeMetadataRegistry = buildSqlTypeMetadataRegistry({
223
+ target,
224
+ adapter,
225
+ extensions
226
+ });
227
+ let controlAdapter;
228
+ const getControlAdapter = () => controlAdapter ??= adapter.create(stack);
229
+ const targetSerializer = target.contractSerializer;
230
+ const targetInferPslContract = blindCast(target).inferPslContract;
231
+ const diffSchema = blindCast(target).diffSchema;
232
+ const targetGranularityOf = blindCast(target).classifySubjectGranularity;
233
+ const targetEntityKindOf = blindCast(target).classifyEntityKind;
234
+ const describedContracts = extensions.flatMap((extension) => extension.contractSpace ? [{
235
+ spaceId: extension.id,
236
+ contract: extension.contractSpace.contractJson
237
+ }] : []);
238
+ const deserializeWithTargetSerializer = (contractOrJson) => {
239
+ const serializer = targetSerializer ?? new SqlContractSerializer();
240
+ const json = targetSerializer !== void 0 && !isPlainRecord(contractOrJson) ? targetSerializer.serializeContract(blindCast(contractOrJson)) : contractOrJson;
241
+ return serializer.deserializeContract(json);
242
+ };
243
+ return {
244
+ familyId: "sql",
245
+ codecTypeImports,
246
+ extensionIds,
247
+ typeMetadataRegistry,
248
+ deserializeContract(contractJson) {
249
+ return deserializeWithTargetSerializer(contractJson);
250
+ },
251
+ async verify(verifyOptions) {
252
+ const { driver, contract: rawContract, expectedTargetId, contractPath, configPath } = verifyOptions;
253
+ const startTime = Date.now();
254
+ const contract = deserializeWithTargetSerializer(rawContract);
255
+ const contractStorageHash = contract.storage.storageHash;
256
+ const contractProfileHash = contract.profileHash;
257
+ const contractTarget = contract.target;
258
+ const marker = await getControlAdapter().readMarker(driver, APP_SPACE_ID);
259
+ let missingCodecs;
260
+ let codecCoverageSkipped = false;
261
+ const supportedTypeIds = collectSupportedCodecTypeIds([
262
+ adapter,
263
+ target,
264
+ ...extensions
265
+ ]);
266
+ if (supportedTypeIds.length === 0) codecCoverageSkipped = true;
267
+ else {
268
+ const supportedSet = new Set(supportedTypeIds);
269
+ const missing = extractCodecTypeIdsFromContract(contract).filter((id) => !supportedSet.has(id));
270
+ if (missing.length > 0) missingCodecs = missing;
271
+ }
272
+ if (!marker) return createVerifyResult({
273
+ ok: false,
274
+ code: VERIFY_CODE_MARKER_MISSING,
275
+ summary: "Marker missing",
276
+ contractStorageHash,
277
+ expectedTargetId,
278
+ contractPath,
279
+ totalTime: Date.now() - startTime,
280
+ ...contractProfileHash ? { contractProfileHash } : {},
281
+ ...missingCodecs ? { missingCodecs } : {},
282
+ ...codecCoverageSkipped ? { codecCoverageSkipped } : {},
283
+ ...configPath ? { configPath } : {}
284
+ });
285
+ if (contractTarget !== expectedTargetId) return createVerifyResult({
286
+ ok: false,
287
+ code: VERIFY_CODE_TARGET_MISMATCH,
288
+ summary: "Target mismatch",
289
+ contractStorageHash,
290
+ marker,
291
+ expectedTargetId,
292
+ actualTargetId: contractTarget,
293
+ contractPath,
294
+ totalTime: Date.now() - startTime,
295
+ ...contractProfileHash ? { contractProfileHash } : {},
296
+ ...missingCodecs ? { missingCodecs } : {},
297
+ ...codecCoverageSkipped ? { codecCoverageSkipped } : {},
298
+ ...configPath ? { configPath } : {}
299
+ });
300
+ if (marker.storageHash !== contractStorageHash) return createVerifyResult({
301
+ ok: false,
302
+ code: VERIFY_CODE_HASH_MISMATCH,
303
+ summary: "Hash mismatch",
304
+ contractStorageHash,
305
+ marker,
306
+ expectedTargetId,
307
+ contractPath,
308
+ totalTime: Date.now() - startTime,
309
+ ...contractProfileHash ? { contractProfileHash } : {},
310
+ ...missingCodecs ? { missingCodecs } : {},
311
+ ...codecCoverageSkipped ? { codecCoverageSkipped } : {},
312
+ ...configPath ? { configPath } : {}
313
+ });
314
+ if (contractProfileHash && marker.profileHash !== contractProfileHash) return createVerifyResult({
315
+ ok: false,
316
+ code: VERIFY_CODE_HASH_MISMATCH,
317
+ summary: "Hash mismatch",
318
+ contractStorageHash,
319
+ contractProfileHash,
320
+ marker,
321
+ expectedTargetId,
322
+ contractPath,
323
+ totalTime: Date.now() - startTime,
324
+ ...missingCodecs ? { missingCodecs } : {},
325
+ ...codecCoverageSkipped ? { codecCoverageSkipped } : {},
326
+ ...configPath ? { configPath } : {}
327
+ });
328
+ return createVerifyResult({
329
+ ok: true,
330
+ summary: "Database matches contract",
331
+ contractStorageHash,
332
+ marker,
333
+ expectedTargetId,
334
+ contractPath,
335
+ totalTime: Date.now() - startTime,
336
+ ...contractProfileHash ? { contractProfileHash } : {},
337
+ ...missingCodecs ? { missingCodecs } : {},
338
+ ...codecCoverageSkipped ? { codecCoverageSkipped } : {},
339
+ ...configPath ? { configPath } : {}
340
+ });
341
+ },
342
+ verifySchema(options) {
343
+ const contract = deserializeWithTargetSerializer(options.contract);
344
+ if (!diffSchema) throw missingDescriptorOperationError(target.targetId, "diffSchema");
345
+ if (!targetGranularityOf) throw missingDescriptorOperationError(target.targetId, "classifySubjectGranularity");
346
+ return verifySqlSchemaByDiff({
347
+ contract,
348
+ schema: options.schema,
349
+ strict: options.strict,
350
+ frameworkComponents: options.frameworkComponents,
351
+ diffSchema,
352
+ granularityOf: targetGranularityOf
353
+ });
354
+ },
355
+ /**
356
+ * Classifies a diff issue's subject granularity on demand, by resolving
357
+ * its node's `nodeKind` through the target's classifier — the
358
+ * {@link import('@internal/framework-components/control').SchemaSubjectClassifierCapable}
359
+ * capability. Framework consumers spanning contract spaces (the
360
+ * migration aggregate's unclaimed-elements sweep) detect and call this
361
+ * instead of reaching into the concrete schema-IR node, which they
362
+ * cannot read; nothing is stamped on the issue or the node.
363
+ */
364
+ classifySubjectGranularity(issue) {
365
+ if (!targetGranularityOf) throw missingDescriptorOperationError(target.targetId, "classifySubjectGranularity");
366
+ return classifyDiffSubjectGranularity(issue, targetGranularityOf);
367
+ },
368
+ /**
369
+ * Classifies a diff issue's subject storage `entityKind` on demand, by
370
+ * resolving its node's `nodeKind` through the target's classifier —
371
+ * the sibling of `classifySubjectGranularity` above, and part of the
372
+ * same {@link import('@internal/framework-components/control').SchemaSubjectClassifierCapable}
373
+ * capability.
374
+ */
375
+ classifyEntityKind(issue) {
376
+ if (!targetEntityKindOf) throw missingDescriptorOperationError(target.targetId, "classifyEntityKind");
377
+ return classifyDiffEntityKind(issue, targetEntityKindOf);
378
+ },
379
+ async sign(options) {
380
+ const { driver, contract: contractInput, contractPath, configPath } = options;
381
+ const startTime = Date.now();
382
+ const contract = deserializeWithTargetSerializer(contractInput);
383
+ const contractStorageHash = contract.storage.storageHash;
384
+ const contractProfileHash = "profileHash" in contract && typeof contract.profileHash === "string" ? contract.profileHash : contractStorageHash;
385
+ const contractTarget = contract.target;
386
+ const controlAdapter = getControlAdapter();
387
+ const lowererContext = { contract };
388
+ for (const query of controlAdapter.bootstrapSignMarkerQueries()) {
389
+ const lowered = await controlAdapter.lowerToExecuteRequest(query, lowererContext);
390
+ await driver.query(lowered.sql, lowered.params);
391
+ }
392
+ const existingMarker = await controlAdapter.readMarker(driver, APP_SPACE_ID);
393
+ let markerCreated = false;
394
+ let markerUpdated = false;
395
+ let previousHashes;
396
+ if (!existingMarker) {
397
+ await controlAdapter.insertMarker(driver, APP_SPACE_ID, {
398
+ storageHash: contractStorageHash,
399
+ profileHash: contractProfileHash
400
+ });
401
+ markerCreated = true;
402
+ } else {
403
+ const existingStorageHash = existingMarker.storageHash;
404
+ const existingProfileHash = existingMarker.profileHash;
405
+ if (!(existingStorageHash === contractStorageHash) || !(existingProfileHash === contractProfileHash)) {
406
+ previousHashes = {
407
+ storageHash: existingStorageHash,
408
+ profileHash: existingProfileHash
409
+ };
410
+ if (!await controlAdapter.updateMarker(driver, APP_SPACE_ID, existingStorageHash, {
411
+ storageHash: contractStorageHash,
412
+ profileHash: contractProfileHash
413
+ })) throw sqlFamilyError("MIGRATION.MARKER_CAS_FAILURE", "CAS conflict: marker was modified by another process during sign", {
414
+ why: "Another process updated the contract marker between the read and the compare-and-swap write.",
415
+ fix: "Re-run the sign command; if it keeps failing, make sure only one migration process runs at a time.",
416
+ meta: { space: APP_SPACE_ID }
417
+ });
418
+ markerUpdated = true;
419
+ }
420
+ }
421
+ let summary;
422
+ if (markerCreated) summary = "Database signed (marker created)";
423
+ else if (markerUpdated) summary = `Database signed (marker updated from ${previousHashes?.storageHash ?? "unknown"})`;
424
+ else summary = "Database already signed with this contract";
425
+ const totalTime = Date.now() - startTime;
426
+ return {
427
+ ok: true,
428
+ summary,
429
+ contract: {
430
+ storageHash: contractStorageHash,
431
+ profileHash: contractProfileHash
432
+ },
433
+ target: {
434
+ expected: contractTarget,
435
+ actual: contractTarget
436
+ },
437
+ marker: {
438
+ created: markerCreated,
439
+ updated: markerUpdated,
440
+ ...previousHashes ? { previous: previousHashes } : {}
441
+ },
442
+ meta: {
443
+ contractPath,
444
+ ...configPath ? { configPath } : {}
445
+ },
446
+ timings: { total: totalTime }
447
+ };
448
+ },
449
+ async readMarker(options) {
450
+ return getControlAdapter().readMarker(options.driver, options.space);
451
+ },
452
+ async readAllMarkers(options) {
453
+ return getControlAdapter().readAllMarkers(options.driver);
454
+ },
455
+ async readLedger(options) {
456
+ return getControlAdapter().readLedger(options.driver, options.space);
457
+ },
458
+ async initMarker(options) {
459
+ return getControlAdapter().initMarker(options.driver, options.space, options.destination);
460
+ },
461
+ async updateMarker(options) {
462
+ return getControlAdapter().updateMarker(options.driver, options.space, options.expectedFrom, options.destination);
463
+ },
464
+ async writeLedgerEntry(options) {
465
+ return getControlAdapter().writeLedgerEntry(options.driver, options.space, options.entry);
466
+ },
467
+ async introspect(options) {
468
+ return getControlAdapter().introspect(options.driver, options.contract);
469
+ },
470
+ inferPslContract(schemaIR) {
471
+ if (!targetInferPslContract) throw sqlFamilyError("CONTRACT.INFER_UNSUPPORTED", `Target "${target.targetId}" does not support contract infer (no inferPslContract on its descriptor).`, {
472
+ why: "The target descriptor does not provide the inferPslContract hook, so a PSL contract cannot be inferred from the database schema.",
473
+ fix: "Use a target package that supports contract infer, or author the contract instead of inferring it.",
474
+ meta: { targetId: target.targetId }
475
+ });
476
+ return targetInferPslContract(schemaIR, describedContracts);
477
+ },
478
+ lowerAst(ast, context) {
479
+ return getControlAdapter().lowerToExecuteRequest(ast, context);
480
+ },
481
+ bootstrapControlTableQueries() {
482
+ return getControlAdapter().bootstrapControlTableQueries();
483
+ },
484
+ toOperationPreview(operations) {
485
+ return sqlOperationsToPreview(operations);
486
+ },
487
+ toSchemaView(schema) {
488
+ const root = blindCast(schema);
489
+ const namespaceEntries = root.namespaces !== void 0 ? Object.entries(root.namespaces).map(([namespaceKey, namespace]) => [namespaceKey, namespace.tables]) : [[void 0, root.tables ?? {}]];
490
+ const qualify = namespaceEntries.length > 1;
491
+ const tableNodes = namespaceEntries.flatMap(([namespaceKey, tables]) => Object.entries(tables).map(([tableName, table]) => [
492
+ qualify && namespaceKey !== void 0 ? `${namespaceKey}.${tableName}` : tableName,
493
+ tableName,
494
+ table
495
+ ])).map(([displayName, tableName, table]) => {
496
+ const children = [];
497
+ const columnNodes = [];
498
+ for (const [columnName, column] of Object.entries(table.columns)) {
499
+ const label = `${columnName}: ${column.nativeType} (${column.nullable ? "nullable" : "not nullable"})`;
500
+ columnNodes.push(new SchemaTreeNode({
501
+ kind: "field",
502
+ id: `column-${displayName}-${columnName}`,
503
+ label,
504
+ meta: {
505
+ nativeType: column.nativeType,
506
+ nullable: column.nullable,
507
+ ...ifDefined("default", column.default)
508
+ }
509
+ }));
510
+ }
511
+ if (columnNodes.length > 0) children.push(new SchemaTreeNode({
512
+ kind: "collection",
513
+ id: `columns-${displayName}`,
514
+ label: "columns",
515
+ children: columnNodes
516
+ }));
517
+ if (table.primaryKey) {
518
+ const pkColumns = table.primaryKey.columns.join(", ");
519
+ children.push(new SchemaTreeNode({
520
+ kind: "index",
521
+ id: `primary-key-${displayName}`,
522
+ label: `primary key: ${pkColumns}`,
523
+ meta: {
524
+ columns: table.primaryKey.columns,
525
+ ...table.primaryKey.name ? { name: table.primaryKey.name } : {}
526
+ }
527
+ }));
528
+ }
529
+ for (const unique of table.uniques) {
530
+ const name = unique.name ?? `${tableName}_${unique.columns.join("_")}_unique`;
531
+ const label = `unique ${name}`;
532
+ children.push(new SchemaTreeNode({
533
+ kind: "index",
534
+ id: `unique-${displayName}-${name}`,
535
+ label,
536
+ meta: {
537
+ columns: unique.columns,
538
+ unique: true
539
+ }
540
+ }));
541
+ }
542
+ for (const index of table.indexes) {
543
+ const name = index.name;
544
+ const label = index.unique ? `unique index ${name}` : `index ${name}`;
545
+ children.push(new SchemaTreeNode({
546
+ kind: "index",
547
+ id: `index-${displayName}-${name}`,
548
+ label,
549
+ meta: {
550
+ columns: index.columns,
551
+ unique: index.unique
552
+ }
553
+ }));
554
+ }
555
+ const tableMeta = {};
556
+ if (table.primaryKey) {
557
+ tableMeta["primaryKey"] = table.primaryKey.columns;
558
+ if (table.primaryKey.name) tableMeta["primaryKeyName"] = table.primaryKey.name;
559
+ }
560
+ if (table.foreignKeys.length > 0) tableMeta["foreignKeys"] = table.foreignKeys.map((fk) => ({
561
+ columns: fk.columns,
562
+ referencedTable: fk.referencedTable,
563
+ referencedColumns: fk.referencedColumns,
564
+ ...fk.name ? { name: fk.name } : {}
565
+ }));
566
+ return new SchemaTreeNode({
567
+ kind: "entity",
568
+ id: `table-${displayName}`,
569
+ label: `table ${displayName}`,
570
+ ...Object.keys(tableMeta).length > 0 ? { meta: tableMeta } : {},
571
+ ...children.length > 0 ? { children } : {}
572
+ });
573
+ });
574
+ return { root: new SchemaTreeNode({
575
+ kind: "root",
576
+ id: "sql-schema",
577
+ label: "database",
578
+ ...tableNodes.length > 0 ? { children: tableNodes } : {}
579
+ }) };
580
+ }
581
+ };
582
+ }
583
+ var SqlFamilyDescriptor = class {
584
+ kind = "family";
585
+ id = "sql";
586
+ familyId = "sql";
587
+ version = "0.0.1";
588
+ emission = sqlEmission;
589
+ authoring = {
590
+ field: sqlFamilyAuthoringFieldPresets,
591
+ type: sqlFamilyAuthoringTypes,
592
+ entityTypes: sqlFamilyEntityTypes,
593
+ pslBlockDescriptors: sqlFamilyPslBlockDescriptors
594
+ };
595
+ create(stack) {
596
+ return createSqlFamilyInstance(stack);
597
+ }
598
+ };
599
+ function convertColumn(name, column, storageTypes, expandNativeType, renderDefault, resolveDefault) {
600
+ const resolved = resolveColumnTypeMetadata(column, storageTypes);
601
+ const baseNativeType = expandNativeType ? expandNativeType({
602
+ nativeType: resolved.nativeType,
603
+ codecId: resolved.codecId,
604
+ ...ifDefined("typeParams", resolved.typeParams)
605
+ }) : resolved.nativeType;
606
+ const nativeType = baseNativeType;
607
+ const resolvedNativeType = column.many ? `${baseNativeType}[]` : baseNativeType;
608
+ const rawColumnDefault = column.default ?? void 0;
609
+ const resolvedColumnDefault = rawColumnDefault !== void 0 && resolveDefault ? resolveDefault(rawColumnDefault, resolvedNativeType) : rawColumnDefault;
610
+ return {
611
+ name,
612
+ nativeType,
613
+ nullable: column.nullable,
614
+ ...ifDefined("many", column.many),
615
+ ...ifDefined("default", column.default != null && renderDefault ? renderDefault(column.default, column) : void 0),
616
+ resolvedNativeType,
617
+ ...ifDefined("resolvedDefault", resolvedColumnDefault),
618
+ codecRef: buildColumnCodecRef(resolved, column.many),
619
+ codecBaseNativeType: resolved.nativeType,
620
+ ...column.typeRef !== void 0 ? { codecNamedType: true } : {}
621
+ };
622
+ }
623
+ /**
624
+ * Builds the column's `CodecRef` from its resolved (post-`typeRef`) codec
625
+ * identity — the same construction the query AST and the migration DDL
626
+ * renderer already use (TML-2456, TML-2918).
627
+ */
628
+ function buildColumnCodecRef(resolved, many) {
629
+ return {
630
+ codecId: resolved.codecId,
631
+ ...ifDefined("typeParams", resolved.typeParams !== void 0 ? blindCast(resolved.typeParams) : void 0),
632
+ ...ifDefined("many", many)
633
+ };
634
+ }
635
+ function resolveColumnTypeMetadata(column, storageTypes) {
636
+ if (!column.typeRef) return column;
637
+ const referenced = storageTypes[column.typeRef];
638
+ if (!referenced) throw sqlFamilyError("CONTRACT.TYPE_UNKNOWN", `Column references storage type "${column.typeRef}" but it is not defined in storage.types.`, {
639
+ why: "The column typeRef does not resolve to any entry in the contract storage.types map.",
640
+ fix: "Regenerate the contract from its authoring source; do not hand-edit contract JSON.",
641
+ meta: { typeRef: column.typeRef }
642
+ });
643
+ if (isStorageTypeInstance(referenced)) return {
644
+ codecId: referenced.codecId,
645
+ nativeType: referenced.nativeType,
646
+ typeParams: referenced.typeParams
647
+ };
648
+ throw new InternalError(`Storage type "${column.typeRef}" has an unknown polymorphic kind; expected a codec-typed StorageTypeInstance.`);
649
+ }
650
+ /**
651
+ * Resolves a `ValueSetRef` to its permitted values from the contract storage.
652
+ *
653
+ * Throws when the referenced namespace or value-set is absent — this indicates
654
+ * the contract was built incorrectly (the check and the value-set must be
655
+ * co-emitted by the lowering step). Used by `convertCheck` (schema-IR
656
+ * projection), `verifyCheckConstraints` (verification), and
657
+ * `checkConstraintPlanCallStrategy` (migration planning) so all three agree on
658
+ * the resolved values and the error behavior on a missing reference.
659
+ */
660
+ function allStrings(values) {
661
+ return values.every((value) => typeof value === "string");
662
+ }
663
+ function resolveValueSetValues(ref, storage, contextLabel) {
664
+ const ns = storage.namespaces[ref.namespaceId];
665
+ if (!ns) throw sqlFamilyError("CONTRACT.NAMESPACE_UNKNOWN", `resolveValueSetValues: namespace "${ref.namespaceId}" not found in storage (${contextLabel})`, {
666
+ why: "A value-set reference names a namespace the contract storage does not declare.",
667
+ fix: "Regenerate the contract from its authoring source; do not hand-edit contract JSON.",
668
+ meta: {
669
+ namespaceId: ref.namespaceId,
670
+ context: contextLabel
671
+ }
672
+ });
673
+ const valueSet = ns.entries.valueSet?.[ref.entityName];
674
+ if (!valueSet) throw sqlFamilyError("CONTRACT.ENUM_UNKNOWN", `resolveValueSetValues: value-set "${ref.entityName}" not found in namespace "${ref.namespaceId}" (${contextLabel})`, {
675
+ why: "A value-set reference names an entry its namespace does not declare.",
676
+ fix: "Regenerate the contract from its authoring source; do not hand-edit contract JSON.",
677
+ meta: {
678
+ valueSet: ref.entityName,
679
+ namespaceId: ref.namespaceId,
680
+ context: contextLabel
681
+ }
682
+ });
683
+ const values = valueSet.values;
684
+ if (!allStrings(values)) throw sqlFamilyError("CONTRACT.ENUM_INVALID", `resolveValueSetValues: value-set "${ref.entityName}" in namespace "${ref.namespaceId}" has a non-string value; numeric-enum CHECK constraints are not yet supported (${contextLabel})`, {
685
+ why: "Only string value-sets can be rendered as CHECK constraints; this value-set carries a non-string value.",
686
+ fix: "Use string enum values, or drop the CHECK-constrained enum until numeric enums are supported.",
687
+ meta: {
688
+ valueSet: ref.entityName,
689
+ namespaceId: ref.namespaceId,
690
+ context: contextLabel
691
+ }
692
+ });
693
+ return values;
694
+ }
695
+ /**
696
+ * Projects a `CheckConstraint` IR into an `SqlCheckConstraintIRInput` by
697
+ * resolving the permitted values from the storage value-set it references.
698
+ *
699
+ * The `CheckConstraint.valueSet` ref points to
700
+ * `storage.namespaces[namespaceId].entries.valueSet[name]`. The resolved
701
+ * values are lifted directly from `StorageValueSet.values` so verification
702
+ * compares value sets, not SQL predicate strings.
703
+ *
704
+ * Throws if the referenced namespace or value-set is absent — this
705
+ * indicates the contract was built incorrectly (the check and the
706
+ * value-set must be co-emitted by the lowering step).
707
+ */
708
+ function convertCheck(check, storage) {
709
+ const permittedValues = resolveValueSetValues(check.valueSet, storage, `check "${check.name}"`);
710
+ return {
711
+ name: check.name,
712
+ column: check.column,
713
+ permittedValues
714
+ };
715
+ }
716
+ function convertUnique(unique, tableName) {
717
+ return {
718
+ columns: unique.columns,
719
+ ...ifDefined("name", unique.name),
720
+ dependsOn: flatColumnDependsOn(tableName, unique.columns)
721
+ };
722
+ }
723
+ function convertIndex(index, tableName, tableColumns) {
724
+ const base = {
725
+ naming: namingOf(index.name, index.prefix),
726
+ where: index.where,
727
+ unique: index.unique,
728
+ partial: index.where !== void 0,
729
+ type: index.type,
730
+ options: index.options,
731
+ annotations: void 0,
732
+ dependsOn: flatColumnDependsOn(tableName, index.columns ?? tableColumns)
733
+ };
734
+ return index.expression !== void 0 ? {
735
+ ...base,
736
+ expression: index.expression
737
+ } : {
738
+ ...base,
739
+ columns: index.columns ?? []
740
+ };
741
+ }
742
+ /**
743
+ * The referenced table's chain in the flat (single-schema) tree
744
+ * `contractToSchemaIR`/`contractNamespaceToSchemaIR` build: the root
745
+ * (`SqlSchemaIR`, fixed `'database'` id) followed by the table's own id.
746
+ * Postgres discards this when it re-derives the FK against its own
747
+ * multi-schema tree shape (`contractToPostgresDatabaseSchemaNode`); SQLite's
748
+ * flat tree uses it as-is.
749
+ */
750
+ function flatSchemaDependsOn(tableName) {
751
+ return [{
752
+ nodeKind: RelationalSchemaNodeKind.schema,
753
+ id: "database"
754
+ }, {
755
+ nodeKind: RelationalSchemaNodeKind.table,
756
+ id: tableName
757
+ }];
758
+ }
759
+ /**
760
+ * The chains from a table-child object (foreign key, index, unique, primary
761
+ * key) to each of the own columns it is built on, in the flat tree. Dropping
762
+ * a covered column auto-drops the object, so the object's drop must precede
763
+ * the column's; the graph derives that direction from these edges.
764
+ */
765
+ function flatColumnDependsOn(tableName, columns) {
766
+ return columns.map((column) => [
767
+ {
768
+ nodeKind: RelationalSchemaNodeKind.schema,
769
+ id: "database"
770
+ },
771
+ {
772
+ nodeKind: RelationalSchemaNodeKind.table,
773
+ id: tableName
774
+ },
775
+ {
776
+ nodeKind: RelationalSchemaNodeKind.column,
777
+ id: `column:${column}`
778
+ }
779
+ ]);
780
+ }
781
+ /**
782
+ * The FK's referenced-namespace identity comes from the target's namespace
783
+ * node, not the raw namespace-id string. An unbound target namespace stamps
784
+ * no `referencedSchema` at all — the FK node's id renders the absence as the
785
+ * empty segment, which is what flat (single-schema) introspection produces,
786
+ * so both diff sides' FK ids meet by construction. A bound namespace (or a
787
+ * cross-space target whose namespace lives in another contract's storage)
788
+ * stamps its coordinate verbatim; namespaced targets (Postgres) resolve the
789
+ * real DDL schema downstream.
790
+ *
791
+ * `dependsOn` carries the referenced table (created before the FK, dropped
792
+ * after it) plus the FK's own columns (dropped after the FK, since dropping a
793
+ * column auto-drops the FK built on it).
794
+ */
795
+ function convertForeignKey(fk, storage) {
796
+ const targetIsUnbound = storage.namespaces[fk.target.namespaceId]?.isUnbound === true;
797
+ return {
798
+ columns: fk.source.columns,
799
+ referencedTable: fk.target.tableName,
800
+ ...targetIsUnbound ? {} : { referencedSchema: fk.target.namespaceId },
801
+ referencedColumns: fk.target.columns,
802
+ ...ifDefined("name", fk.name),
803
+ ...ifDefined("onDelete", fk.onDelete),
804
+ ...ifDefined("onUpdate", fk.onUpdate),
805
+ dependsOn: [flatSchemaDependsOn(fk.target.tableName), ...flatColumnDependsOn(fk.source.tableName, fk.source.columns)]
806
+ };
807
+ }
808
+ function convertTable(name, table, storageTypes, expandNativeType, renderDefault, resolveDefault, storage) {
809
+ const columns = {};
810
+ for (const [colName, colDef] of Object.entries(table.columns)) columns[colName] = convertColumn(colName, colDef, storageTypes, expandNativeType, renderDefault, resolveDefault);
811
+ const checks = table.checks && table.checks.length > 0 ? table.checks.map((c) => convertCheck(c, storage)) : void 0;
812
+ return new SqlTableIR({
813
+ name,
814
+ columns,
815
+ ...ifDefined("primaryKey", table.primaryKey !== void 0 ? {
816
+ columns: table.primaryKey.columns,
817
+ ...ifDefined("name", table.primaryKey.name),
818
+ dependsOn: flatColumnDependsOn(name, table.primaryKey.columns)
819
+ } : void 0),
820
+ foreignKeys: table.foreignKeys.map((fk) => convertForeignKey(fk, storage)),
821
+ uniques: table.uniques.map((u) => convertUnique(u, name)),
822
+ indexes: table.indexes.map((i) => convertIndex(i, name, Object.keys(table.columns))),
823
+ ...ifDefined("checks", checks)
824
+ });
825
+ }
826
+ /**
827
+ * Detects destructive changes between two contract storages.
828
+ *
829
+ * The additive-only planner silently ignores removals (tables, columns).
830
+ * This function detects those removals so callers can report them as conflicts
831
+ * rather than silently producing an empty plan.
832
+ *
833
+ * Returns an empty array if no destructive changes are found.
834
+ */
835
+ function detectDestructiveChanges(from, to) {
836
+ if (!from) return [];
837
+ const hasOwn = (value, key) => Object.hasOwn(value, key);
838
+ const conflicts = [];
839
+ const namespaceIds = [.../* @__PURE__ */ new Set([...Object.keys(from.namespaces), ...Object.keys(to.namespaces)])].sort((a, b) => a < b ? -1 : a > b ? 1 : 0);
840
+ for (const namespaceId of namespaceIds) {
841
+ const fromNs = from.namespaces[namespaceId];
842
+ const toNs = to.namespaces[namespaceId];
843
+ const fromTables = fromNs?.entries.table;
844
+ if (!fromTables) continue;
845
+ for (const tableName of Object.keys(fromTables)) {
846
+ const toTableRaw = toNs?.entries.table?.[tableName];
847
+ if (!StorageTable.is(toTableRaw)) {
848
+ conflicts.push({
849
+ kind: "tableRemoved",
850
+ summary: `Table "${tableName}" was removed`
851
+ });
852
+ continue;
853
+ }
854
+ const toTable = toTableRaw;
855
+ const fromTableRaw = fromTables[tableName];
856
+ if (!StorageTable.is(fromTableRaw)) continue;
857
+ const fromTable = fromTableRaw;
858
+ for (const columnName of Object.keys(fromTable.columns)) if (!hasOwn(toTable.columns, columnName)) conflicts.push({
859
+ kind: "columnRemoved",
860
+ summary: `Column "${tableName}"."${columnName}" was removed`
861
+ });
862
+ }
863
+ }
864
+ return conflicts;
865
+ }
866
+ /**
867
+ * Converts a `Contract` to `SqlSchemaIR`.
868
+ *
869
+ * Reads `contract.storage` for tables and `contract.storage.types` for type
870
+ * annotations. Storage-type annotations are written under
871
+ * `options.annotationNamespace`.
872
+ *
873
+ * Drops codec metadata (`codecId`, `typeRef`) since the schema IR only represents
874
+ * structural information. When `expandNativeType` is provided, parameterized types
875
+ * are expanded (e.g. `character` + `{ length: 36 }` → `character(36)`) so the
876
+ * resulting IR compares correctly against the "to" contract during planning.
877
+ *
878
+ * Returns an empty schema IR when `contract` is `null` (new project).
879
+ */
880
+ /**
881
+ * Converts the tables of a single namespace into a `SqlSchemaIR`, keyed by
882
+ * table name within that namespace. Unlike {@link contractToSchemaIR}, which
883
+ * flattens every namespace's tables into one bare-keyed record (and throws on a
884
+ * cross-namespace name collision), this scopes the table iteration to one
885
+ * namespace so the same table name can exist in two schemas.
886
+ *
887
+ * The full `storage` is still passed to `convertTable`, so value-set / enum /
888
+ * type resolution that legitimately spans namespaces is unaffected. Foreign
889
+ * keys are built purely from the FK descriptor (`fk.target`), so cross-namespace
890
+ * FKs survive per-namespace conversion. The `annotations` block (storage-type
891
+ * derived) is omitted here — the per-namespace tree consumer reads only the
892
+ * per-table fields.
893
+ */
894
+ function contractNamespaceToSchemaIR(storage, namespaceId, options) {
895
+ if (options.annotationNamespace.length === 0) throw sqlFamilyError("CONTRACT.PACK_CONTRIBUTION_INVALID", "annotationNamespace must be a non-empty string", {
896
+ why: "The calling target pack passed an empty annotationNamespace to the contract-to-schema-IR projection.",
897
+ fix: "Fix the target pack to pass its non-empty annotation namespace (e.g. \"pg\").",
898
+ meta: { option: "annotationNamespace" }
899
+ });
900
+ const namespace = storage.namespaces[namespaceId];
901
+ if (!namespace) return new SqlSchemaIR({ tables: {} });
902
+ const storageTypes = { ...storage.types ?? {} };
903
+ const tables = {};
904
+ for (const [tableName, tableDefRaw] of Object.entries(namespace.entries.table ?? {})) {
905
+ StorageTable.assert(tableDefRaw, `namespaces.${namespaceId}.entries.table.${tableName}`);
906
+ tables[tableName] = convertTable(tableName, tableDefRaw, storageTypes, options.expandNativeType, options.renderDefault, options.resolveDefault, storage);
907
+ }
908
+ return new SqlSchemaIR({ tables });
909
+ }
910
+ function contractToSchemaIR(contract, options) {
911
+ if (options.annotationNamespace.length === 0) throw sqlFamilyError("CONTRACT.PACK_CONTRIBUTION_INVALID", "annotationNamespace must be a non-empty string", {
912
+ why: "The calling target pack passed an empty annotationNamespace to the contract-to-schema-IR projection.",
913
+ fix: "Fix the target pack to pass its non-empty annotation namespace (e.g. \"pg\").",
914
+ meta: { option: "annotationNamespace" }
915
+ });
916
+ if (!contract) return new SqlSchemaIR({ tables: {} });
917
+ const storage = contract.storage;
918
+ const storageTypes = { ...storage.types ?? {} };
919
+ const tables = {};
920
+ for (const ns of Object.values(storage.namespaces)) for (const [tableName, tableDefRaw] of Object.entries(ns.entries.table ?? {})) {
921
+ StorageTable.assert(tableDefRaw, `namespaces.${ns.id}.entries.table.${tableName}`);
922
+ const tableDef = tableDefRaw;
923
+ if (tables[tableName] !== void 0) throw sqlFamilyError("CONTRACT.TABLE_AMBIGUOUS", `contractToSchemaIR: duplicate SQL table name "${tableName}" across namespaces (ambiguous for flat SqlSchemaIR.tables).`, {
924
+ why: "Two namespaces declare a table with the same name, which is ambiguous for the flat schema-IR table map.",
925
+ fix: "Rename one of the tables so every table name is unique across namespaces.",
926
+ meta: { table: tableName }
927
+ });
928
+ tables[tableName] = convertTable(tableName, tableDef, storageTypes, options.expandNativeType, options.renderDefault, options.resolveDefault, storage);
929
+ }
930
+ return new SqlSchemaIR({
931
+ tables,
932
+ ...ifDefined("annotations", deriveAnnotations(storage, options.annotationNamespace, options.resolveEnumNamespaceSchema))
933
+ });
934
+ }
935
+ function deriveAnnotations(storage, annotationNamespace, _resolveEnumNamespaceSchema) {
936
+ const storageTypes = {};
937
+ for (const typeInstance of Object.values(storage.types ?? {})) if (isStorageTypeInstance(typeInstance)) storageTypes[typeInstance.nativeType] = typeInstance;
938
+ const envelope = { ...Object.keys(storageTypes).length > 0 ? { storageTypes } : {} };
939
+ if (Object.keys(envelope).length === 0) return void 0;
940
+ return { [annotationNamespace]: envelope };
941
+ }
942
+ /**
943
+ * The control policy that governs a single call. The `external` default is an
944
+ * un-overridable namespace floor: when the contract default is `external`, no
945
+ * per-object `managed` override can escalate DDL above the floor, so the
946
+ * policy is forced to `external` regardless of the node's own declaration.
947
+ * Every other default defers to the node's effective control policy.
948
+ */
949
+ function controlPolicyForCall(subject, defaultControlPolicy) {
950
+ if (defaultControlPolicy === "external") return "external";
951
+ return effectiveControlPolicy(subject?.explicitNodeControlPolicy, defaultControlPolicy);
952
+ }
953
+ /**
954
+ * Whether a call is allowed to emit under a given control policy.
955
+ *
956
+ * - `managed` — full lifecycle, every op allowed.
957
+ * - `tolerated` — create-if-absent only: allowed iff the call creates a whole
958
+ * new top-level object (and its subject was positively resolved). Anything
959
+ * that modifies an existing object, and anything whose subject could not be
960
+ * resolved, is suppressed.
961
+ * - `external` / `observed` — no DDL at all.
962
+ */
963
+ function callAllowedUnderControlPolicy(policy, subject) {
964
+ switch (policy) {
965
+ case "managed": return true;
966
+ case "tolerated": return subject?.createsNewObject === true;
967
+ case "external":
968
+ case "observed": return false;
969
+ }
970
+ }
971
+ /**
972
+ * Partition the calls produced for a single set of subjects into those the
973
+ * effective control policy permits (`kept`) and a list of
974
+ * {@link SuppressionRecord}s describing the suppressed calls.
975
+ *
976
+ * **Prefer {@link partitionIssuesByControlPolicy}** for the schema-issue
977
+ * pipeline: it filters subjects out of the planner's *input* so the planner
978
+ * never has to reason about un-modeled state on `external`/`observed`
979
+ * subjects. This call-level helper remains for paths that bypass the issue
980
+ * pipeline — currently the codec-emitted field-event ops, which originate
981
+ * from declared contract fields rather than from introspected schema state
982
+ * and therefore cannot trip the diff engine.
983
+ */
984
+ function partitionCallsByControlPolicy(options) {
985
+ const defaultControlPolicy = options.contract.defaultControlPolicy;
986
+ const kept = [];
987
+ const suppressions = [];
988
+ for (const call of options.calls) {
989
+ const subject = options.resolveControlPolicySubject(call);
990
+ const policy = controlPolicyForCall(subject, defaultControlPolicy);
991
+ if (callAllowedUnderControlPolicy(policy, subject)) kept.push(call);
992
+ else suppressions.push({
993
+ subject,
994
+ policy,
995
+ factoryName: options.resolveFactoryName(call),
996
+ createsNewObject: subject?.createsNewObject ?? false
997
+ });
998
+ }
999
+ return Object.freeze({
1000
+ kept: Object.freeze(kept),
1001
+ suppressions: Object.freeze(suppressions)
1002
+ });
1003
+ }
1004
+ /**
1005
+ * Partition a list of schema-issue-shaped inputs by the effective control
1006
+ * policy of each issue's subject *before* the planner is invoked.
1007
+ *
1008
+ * `plannable` is the list of issues whose subject's effective policy permits
1009
+ * the planner to act on them (`managed`, or `tolerated` for whole-object
1010
+ * creation issues only). Issues for `external`/`observed` subjects, and
1011
+ * non-creation issues for `tolerated` subjects, are dropped from the planner's
1012
+ * input entirely — they never enter introspection-driven planning, never feed
1013
+ * the diff engine, and never produce DDL calls that would have to be
1014
+ * post-filtered. This sidesteps a class of failure where the diff engine
1015
+ * cannot reason about the live shape of a subject the user marked as
1016
+ * out-of-scope (`external`).
1017
+ *
1018
+ * `suppressions` is one {@link SuppressionRecord} per suppressed subject (not
1019
+ * per suppressed issue). Its `factoryName` is the creation factory name when any
1020
+ * of the subject's issues is whole-object creation (e.g. `createTable`), else
1021
+ * `undefined` — the family never invents a modification verb for an op that
1022
+ * produced no call; the target renders the message.
1023
+ *
1024
+ * Unresolved-subject issues (`resolveControlPolicySubject` returns
1025
+ * `undefined`) emit one record each; they cannot be deduplicated because they
1026
+ * carry no subject coordinate.
1027
+ */
1028
+ function partitionIssuesByControlPolicy(options) {
1029
+ const defaultControlPolicy = options.contract.defaultControlPolicy;
1030
+ const plannable = [];
1031
+ const suppressedSubjects = /* @__PURE__ */ new Map();
1032
+ const unresolvedSuppressions = [];
1033
+ for (const issue of options.issues) {
1034
+ const subject = options.resolveControlPolicySubject(issue);
1035
+ const policy = controlPolicyForCall(subject, defaultControlPolicy);
1036
+ const creationFactoryName = options.resolveCreationFactoryName(issue);
1037
+ if (policy === "managed") {
1038
+ plannable.push(issue);
1039
+ continue;
1040
+ }
1041
+ if (policy === "tolerated" && subject !== void 0 && creationFactoryName !== void 0 && subject.createsNewObject) {
1042
+ plannable.push(issue);
1043
+ continue;
1044
+ }
1045
+ if (subject === void 0) {
1046
+ unresolvedSuppressions.push({
1047
+ subject: void 0,
1048
+ policy,
1049
+ factoryName: creationFactoryName,
1050
+ createsNewObject: false
1051
+ });
1052
+ continue;
1053
+ }
1054
+ const key = subjectKey(subject);
1055
+ const existing = suppressedSubjects.get(key);
1056
+ if (existing) {
1057
+ if (existing.creationFactoryName === void 0 && creationFactoryName !== void 0) existing.creationFactoryName = creationFactoryName;
1058
+ } else suppressedSubjects.set(key, {
1059
+ subject,
1060
+ policy,
1061
+ ...ifDefined("creationFactoryName", creationFactoryName)
1062
+ });
1063
+ }
1064
+ const suppressions = [...unresolvedSuppressions];
1065
+ for (const entry of suppressedSubjects.values()) suppressions.push({
1066
+ subject: entry.subject,
1067
+ policy: entry.policy,
1068
+ factoryName: entry.creationFactoryName,
1069
+ createsNewObject: entry.subject.createsNewObject
1070
+ });
1071
+ return Object.freeze({
1072
+ plannable: Object.freeze(plannable),
1073
+ suppressions: Object.freeze(suppressions)
1074
+ });
1075
+ }
1076
+ function subjectKey(subject) {
1077
+ return `${subject.namespaceId}\u0000${subject.entityKind ?? ""}\u0000${subject.entityName ?? ""}\u0000${subject.rlsPolicy ?? ""}`;
1078
+ }
1079
+ function planFieldEventOperations(options) {
1080
+ const priorContract = options.priorContract;
1081
+ const newContract = options.newContract;
1082
+ const added = [];
1083
+ const dropped = [];
1084
+ const altered = [];
1085
+ const namespaceIds = unionSorted(priorContract ? Object.keys(priorContract.storage.namespaces) : [], Object.keys(newContract.storage.namespaces));
1086
+ for (const namespaceId of namespaceIds) {
1087
+ const priorNs = priorContract?.storage.namespaces[namespaceId];
1088
+ const newNs = newContract.storage.namespaces[namespaceId];
1089
+ const priorTables = priorNs?.entries.table;
1090
+ const newTables = newNs?.entries.table;
1091
+ const tableNames = unionSorted(priorTables ? Object.keys(priorTables) : [], newTables ? Object.keys(newTables) : []);
1092
+ for (const tableName of tableNames) {
1093
+ const priorTableRaw = priorTables?.[tableName];
1094
+ const newTableRaw = newTables?.[tableName];
1095
+ const priorTable = StorageTable.is(priorTableRaw) ? priorTableRaw : void 0;
1096
+ const newTable = StorageTable.is(newTableRaw) ? newTableRaw : void 0;
1097
+ const fieldNames = unionSorted(priorTable ? Object.keys(priorTable.columns) : [], newTable ? Object.keys(newTable.columns) : []);
1098
+ for (const fieldName of fieldNames) {
1099
+ const priorField = priorTable?.columns[fieldName];
1100
+ const newField = newTable?.columns[fieldName];
1101
+ const entry = {
1102
+ namespaceId,
1103
+ tableName,
1104
+ fieldName,
1105
+ priorTable,
1106
+ newTable,
1107
+ priorField,
1108
+ newField
1109
+ };
1110
+ if (priorField === void 0 && newField !== void 0) added.push(entry);
1111
+ else if (priorField !== void 0 && newField === void 0) dropped.push(entry);
1112
+ else if (priorField !== void 0 && newField !== void 0) {
1113
+ if (isAlteration(priorField, newField)) altered.push(entry);
1114
+ }
1115
+ }
1116
+ }
1117
+ }
1118
+ const calls = [];
1119
+ appendCalls("added", added, options.codecHooks, calls, (e) => e.newField?.codecId);
1120
+ appendCalls("dropped", dropped, options.codecHooks, calls, (e) => e.priorField?.codecId);
1121
+ appendCalls("altered", altered, options.codecHooks, calls, (e) => e.newField?.codecId);
1122
+ return calls;
1123
+ }
1124
+ function appendCalls(event, entries, codecHooks, calls, pickCodecId) {
1125
+ for (const entry of entries) {
1126
+ const codecId = pickCodecId(entry);
1127
+ if (codecId === void 0) continue;
1128
+ const hook = codecHooks.get(codecId);
1129
+ if (!hook?.onFieldEvent) continue;
1130
+ const ctx = buildContext(event, entry);
1131
+ const emitted = hook.onFieldEvent(event, ctx);
1132
+ for (const call of emitted) calls.push(call);
1133
+ }
1134
+ }
1135
+ /**
1136
+ * The context's prior/new sides are scoped to the event:
1137
+ *
1138
+ * - `'added'` — only `newTable` / `newField` populated.
1139
+ * - `'dropped'` — only `priorTable` / `priorField` populated.
1140
+ * - `'altered'` — both sides populated.
1141
+ */
1142
+ function buildContext(event, entry) {
1143
+ const base = {
1144
+ namespaceId: entry.namespaceId,
1145
+ tableName: entry.tableName,
1146
+ fieldName: entry.fieldName
1147
+ };
1148
+ if (event === "added") return {
1149
+ ...base,
1150
+ ...entry.newTable !== void 0 ? { newTable: entry.newTable } : {},
1151
+ ...entry.newField !== void 0 ? { newField: entry.newField } : {}
1152
+ };
1153
+ if (event === "dropped") return {
1154
+ ...base,
1155
+ ...entry.priorTable !== void 0 ? { priorTable: entry.priorTable } : {},
1156
+ ...entry.priorField !== void 0 ? { priorField: entry.priorField } : {}
1157
+ };
1158
+ return {
1159
+ ...base,
1160
+ ...entry.priorTable !== void 0 ? { priorTable: entry.priorTable } : {},
1161
+ ...entry.newTable !== void 0 ? { newTable: entry.newTable } : {},
1162
+ ...entry.priorField !== void 0 ? { priorField: entry.priorField } : {},
1163
+ ...entry.newField !== void 0 ? { newField: entry.newField } : {}
1164
+ };
1165
+ }
1166
+ /**
1167
+ * `'altered'` predicate. Returns `false` whenever `codecId` differs —
1168
+ * any codec change suppresses the `altered` event entirely, including
1169
+ * cases where another property also differs in the same diff. Codec
1170
+ * rotation is a v1 non-goal; avoiding the mixed event keeps the
1171
+ * migration semantics for codec changes explicit rather than smuggling
1172
+ * them through as `altered`.
1173
+ *
1174
+ * For non-`codecId` diffs, returns `true` iff any other column property
1175
+ * differs.
1176
+ */
1177
+ function isAlteration(prior, current) {
1178
+ if (prior.codecId !== current.codecId) return false;
1179
+ return !sameStorageColumn(prior, current);
1180
+ }
1181
+ function sameStorageColumn(a, b) {
1182
+ if (a === b) return true;
1183
+ if (a.nativeType !== b.nativeType) return false;
1184
+ if (a.nullable !== b.nullable) return false;
1185
+ if (a.typeRef !== b.typeRef) return false;
1186
+ if (!sameJson(a.typeParams, b.typeParams)) return false;
1187
+ if (!sameJson(a.default, b.default)) return false;
1188
+ return true;
1189
+ }
1190
+ function sameJson(a, b) {
1191
+ if (a === b) return true;
1192
+ if (a === void 0 || b === void 0) return false;
1193
+ return JSON.stringify(a) === JSON.stringify(b);
1194
+ }
1195
+ function unionSorted(a, b) {
1196
+ const set = /* @__PURE__ */ new Set();
1197
+ for (const name of a) set.add(name);
1198
+ for (const name of b) set.add(name);
1199
+ return [...set].sort((x, y) => x < y ? -1 : x > y ? 1 : 0);
1200
+ }
1201
+ /**
1202
+ * Builds the codec-hook-composed `expandNativeType` callback the contract→IR
1203
+ * derivation uses to expand parameterized native types (e.g. `character` +
1204
+ * `{ length: 36 }` → `character(36)`). Returns `undefined` when no framework
1205
+ * components are supplied, so callers can omit the option entirely.
1206
+ */
1207
+ function buildNativeTypeExpander(frameworkComponents) {
1208
+ if (!frameworkComponents) return;
1209
+ const codecHooks = extractCodecControlHooks(frameworkComponents);
1210
+ return (input) => {
1211
+ if (!input.typeParams) return input.nativeType;
1212
+ if (!input.codecId) return input.nativeType;
1213
+ const hooks = codecHooks.get(input.codecId);
1214
+ if (!hooks?.expandNativeType) return input.nativeType;
1215
+ return hooks.expandNativeType(input);
1216
+ };
1217
+ }
1218
+ const readOnlyEmptyObject = Object.freeze({});
1219
+ function cloneRecord(value) {
1220
+ if (value === readOnlyEmptyObject) return value;
1221
+ return Object.freeze({ ...value });
1222
+ }
1223
+ function freezeSteps(steps) {
1224
+ if (steps.length === 0) return Object.freeze([]);
1225
+ return Object.freeze(steps.map((step) => Object.freeze({
1226
+ description: step.description,
1227
+ sql: step.sql,
1228
+ ...step.params ? { params: Object.freeze([...step.params]) } : {},
1229
+ ...step.meta ? { meta: cloneRecord(step.meta) } : {}
1230
+ })));
1231
+ }
1232
+ function freezeDetailsValue(value) {
1233
+ if (value === null || value === void 0) return value;
1234
+ if (typeof value !== "object") return value;
1235
+ if (Array.isArray(value)) return Object.freeze([...value]);
1236
+ return Object.freeze({ ...value });
1237
+ }
1238
+ function freezeTargetDetails(target) {
1239
+ return Object.freeze({
1240
+ id: target.id,
1241
+ ...target.details !== void 0 ? { details: freezeDetailsValue(target.details) } : {}
1242
+ });
1243
+ }
1244
+ function freezeOperation(operation) {
1245
+ return Object.freeze({
1246
+ id: operation.id,
1247
+ label: operation.label,
1248
+ ...operation.summary ? { summary: operation.summary } : {},
1249
+ operationClass: operation.operationClass,
1250
+ ...operation.invariantId ? { invariantId: operation.invariantId } : {},
1251
+ target: freezeTargetDetails(operation.target),
1252
+ precheck: freezeSteps(operation.precheck),
1253
+ execute: freezeSteps(operation.execute),
1254
+ postcheck: freezeSteps(operation.postcheck),
1255
+ ...operation.meta ? { meta: cloneRecord(operation.meta) } : {}
1256
+ });
1257
+ }
1258
+ function freezeOperations(operations) {
1259
+ if (operations.length === 0) return Object.freeze([]);
1260
+ return Object.freeze(operations.map((operation) => freezeOperation(operation)));
1261
+ }
1262
+ function createMigrationPlan(options) {
1263
+ return Object.freeze({
1264
+ targetId: options.targetId,
1265
+ spaceId: options.spaceId,
1266
+ ...options.origin !== void 0 ? { origin: options.origin ? Object.freeze({ ...options.origin }) : null } : {},
1267
+ destination: Object.freeze({ ...options.destination }),
1268
+ operations: freezeOperations(options.operations),
1269
+ providedInvariants: Object.freeze([...options.providedInvariants]),
1270
+ ...options.meta ? { meta: cloneRecord(options.meta) } : {}
1271
+ });
1272
+ }
1273
+ function plannerSuccess(plan, warnings) {
1274
+ return Object.freeze({
1275
+ kind: "success",
1276
+ plan,
1277
+ ...warnings && warnings.length > 0 ? { warnings: Object.freeze(warnings.map((conflict) => Object.freeze({
1278
+ kind: conflict.kind,
1279
+ summary: conflict.summary,
1280
+ ...conflict.why ? { why: conflict.why } : {},
1281
+ ...conflict.location ? { location: Object.freeze({ ...conflict.location }) } : {},
1282
+ ...conflict.meta ? { meta: cloneRecord(conflict.meta) } : {}
1283
+ }))) } : {}
1284
+ });
1285
+ }
1286
+ function plannerFailure(conflicts) {
1287
+ return Object.freeze({
1288
+ kind: "failure",
1289
+ conflicts: Object.freeze(conflicts.map((conflict) => Object.freeze({
1290
+ kind: conflict.kind,
1291
+ summary: conflict.summary,
1292
+ ...conflict.why ? { why: conflict.why } : {},
1293
+ ...conflict.location ? { location: Object.freeze({ ...conflict.location }) } : {},
1294
+ ...conflict.meta ? { meta: cloneRecord(conflict.meta) } : {}
1295
+ })))
1296
+ });
1297
+ }
1298
+ /**
1299
+ * Creates a successful migration runner result.
1300
+ */
1301
+ function runnerSuccess(value) {
1302
+ return ok(Object.freeze({
1303
+ operationsPlanned: value.operationsPlanned,
1304
+ operationsExecuted: value.operationsExecuted
1305
+ }));
1306
+ }
1307
+ /**
1308
+ * Creates a failed migration runner result.
1309
+ */
1310
+ function runnerFailure(code, summary, options) {
1311
+ return notOk(Object.freeze({
1312
+ code,
1313
+ summary,
1314
+ ...options?.why ? { why: options.why } : {},
1315
+ ...options?.meta ? { meta: cloneRecord(options.meta) } : {}
1316
+ }));
1317
+ }
1318
+ /**
1319
+ * Policy used by `db init`: additive-only operations, no widening/destructive steps.
1320
+ */
1321
+ const INIT_ADDITIVE_POLICY = Object.freeze({ allowedOperationClasses: Object.freeze(["additive"]) });
1322
+ var control_default = new SqlFamilyDescriptor();
1323
+ //#endregion
1324
+ export { runnerSuccess as _, contractToSchemaIR as a, createMigrationPlan as c, partitionIssuesByControlPolicy as d, planFieldEventOperations as f, runnerFailure as g, resolveValueSetValues as h, contractNamespaceToSchemaIR as i, detectDestructiveChanges as l, plannerSuccess as m, assembleAuthoringContributions as n, controlPolicyForCall as o, plannerFailure as p, buildNativeTypeExpander as r, control_default as s, INIT_ADDITIVE_POLICY as t, partitionCallsByControlPolicy as u };
1325
+
1326
+ //# sourceMappingURL=control-B7iS4jv4.mjs.map