@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,778 @@
1
+ import { t as sqlContractCanonicalizationHooks } from "./canonicalization-hooks-DfIc_lOO.mjs";
2
+ import { i as Index } from "./storage-table-_LWDmPfv-DFhU2dML.mjs";
3
+ import { m as valueSetEntityKind, p as tableEntityKind } from "./entity-kinds-DKxwKolf-CcsY-iYV.mjs";
4
+ import { n as lowerAuthoredIndex } from "./index-naming-BoGBcMmI-DiJAr66H.mjs";
5
+ import { r as materializeForeignKeysAndIndexes } from "./foreign-key-materialization-HI7BIQrG.mjs";
6
+ import { t as validateIndexTypes } from "./index-type-validation-COH4d78M.mjs";
7
+ import { t as createIndexTypeRegistry } from "./index-types-DJQ_xwaE.mjs";
8
+ import { a as SqlStorage, o as applyFkDefaults, u as toStorageTypeInstance } from "./types-CMMQS6aG.mjs";
9
+ import { u as validateStorageSemantics } from "./validators-C4PItWnf.mjs";
10
+ import { t as deriveValueSetFromEntity } from "./value-set-derivation-hook-Di9JZ0X7.mjs";
11
+ import { UNBOUND_NAMESPACE_ID } from "@prisma/orm-framework/components/ir";
12
+ import { structuredError } from "@prisma/orm-framework/utils/structured-error";
13
+ import { InternalError } from "@prisma/orm-framework/utils/internal-error";
14
+ import { asNamespaceId, coreHash, crossRef } from "@prisma/orm-framework/contract/types";
15
+ import { flushAuthoringWarnings, isAuthoringEntityTypeDescriptor } from "@prisma/orm-framework/components/authoring";
16
+ import { blindCast } from "@prisma/orm-framework/utils/casts";
17
+ import { ifDefined } from "@prisma/orm-framework/utils/defined";
18
+ import { computeExecutionHash, computeProfileHash, computeStorageHash } from "@prisma/orm-framework/contract/hashing";
19
+ import { mergeCapabilityMatrices } from "@prisma/orm-framework/contract-authoring";
20
+ //#region ../../../2-sql/2-authoring/contract-ts/dist/build-contract-DBCz_YSs.mjs
21
+ function contractError(code, message, options) {
22
+ return structuredError(code, message, options);
23
+ }
24
+ function encodeViaCodec(value, codecId, codecLookup) {
25
+ const codec = codecLookup?.get(codecId);
26
+ if (codec) return codec.encodeJson(value);
27
+ return blindCast(value);
28
+ }
29
+ function encodeColumnDefault(defaultInput, codecId, codecLookup, many = false) {
30
+ if (defaultInput.kind === "function") return {
31
+ kind: "function",
32
+ expression: defaultInput.expression
33
+ };
34
+ if (many) {
35
+ if (!Array.isArray(defaultInput.value)) throw new InternalError(`Literal default on a list column must be an array; received ${typeof defaultInput.value}. A scalar default on a list field must be rejected at the authoring surface.`);
36
+ return {
37
+ kind: "literal",
38
+ value: defaultInput.value.map((element) => encodeViaCodec(element, codecId, codecLookup))
39
+ };
40
+ }
41
+ return {
42
+ kind: "literal",
43
+ value: encodeViaCodec(defaultInput.value, codecId, codecLookup)
44
+ };
45
+ }
46
+ function assertStorageSemantics(definition, contract) {
47
+ const semanticErrors = validateStorageSemantics(contract.storage);
48
+ if (semanticErrors.length > 0) throw contractError("CONTRACT.VALIDATION_FAILED", `Contract semantic validation failed: ${semanticErrors.join("; ")}`, { meta: { errors: semanticErrors } });
49
+ const indexTypeRegistry = createIndexTypeRegistry();
50
+ const packsToRegister = [definition.target, ...Object.values(definition.extensions ?? {})];
51
+ for (const pack of packsToRegister) {
52
+ const registration = pack.indexTypes;
53
+ if (registration === void 0) continue;
54
+ if (typeof registration !== "object" || registration === null || !Array.isArray(registration.entries)) throw contractError("CONTRACT.PACK_CONTRIBUTION_INVALID", `Pack "${pack.id ?? "<unknown>"}" declares "indexTypes" but its value is not an IndexTypeRegistration (expected an object with an "entries" array; got ${typeof registration}).`, { meta: {
55
+ packId: pack.id,
56
+ contribution: "indexTypes",
57
+ reason: "invalid-shape"
58
+ } });
59
+ for (const entry of registration.entries) indexTypeRegistry.register(entry);
60
+ }
61
+ validateIndexTypes(contract, indexTypeRegistry);
62
+ }
63
+ function assertKnownTargetModel(modelsByName, modelsByCoordinate, sourceModelName, targetModelName, targetNamespaceId, context) {
64
+ const targetModel = targetNamespaceId !== void 0 && targetNamespaceId.length > 0 ? modelsByCoordinate.get(`${targetNamespaceId}:${targetModelName}`) : modelsByName.get(targetModelName);
65
+ if (!targetModel) {
66
+ const qualified = targetNamespaceId !== void 0 && targetNamespaceId.length > 0 ? `${targetNamespaceId}.${targetModelName}` : targetModelName;
67
+ throw contractError("CONTRACT.MODEL_UNKNOWN", `${context} on model "${sourceModelName}" references unknown model "${qualified}"`, { meta: {
68
+ sourceModel: sourceModelName,
69
+ targetModel: qualified,
70
+ context
71
+ } });
72
+ }
73
+ return targetModel;
74
+ }
75
+ function assertTargetTableMatches(sourceModelName, targetModel, referencedTableName, context) {
76
+ if (targetModel.tableName !== referencedTableName) throw contractError("CONTRACT.TABLE_MISMATCH", `${context} on model "${sourceModelName}" references table "${referencedTableName}" but model "${targetModel.modelName}" maps to "${targetModel.tableName}"`, { meta: {
77
+ sourceModel: sourceModelName,
78
+ referencedTable: referencedTableName,
79
+ mappedTable: targetModel.tableName,
80
+ context
81
+ } });
82
+ }
83
+ function isValueObjectField(field) {
84
+ return "valueObjectName" in field;
85
+ }
86
+ /**
87
+ * Resolves a deferred entity-ref column descriptor (e.g. a `pg.enum(handle)`
88
+ * column) against the field's now-known owning namespace: attaches the
89
+ * storage `valueSet` ref the collected entity's derived value-set is stored
90
+ * under. `nativeType` / `typeParams.typeName` stay bare here — schema
91
+ * qualification (e.g. `auth.aal_level`) is a target concern applied in the
92
+ * next step, `qualifyColumnDescriptor`. A descriptor with no `entityRef` (the
93
+ * ordinary case) passes through unchanged.
94
+ */
95
+ function resolveEntityRefDescriptor(descriptor, namespaceId) {
96
+ const entityRef = descriptor.entityRef;
97
+ if (entityRef === void 0) return descriptor;
98
+ return {
99
+ ...descriptor,
100
+ valueSet: {
101
+ plane: "storage",
102
+ entityKind: "valueSet",
103
+ namespaceId,
104
+ entityName: entityRef.entityName
105
+ }
106
+ };
107
+ }
108
+ /**
109
+ * Structural check for a target that contributes a `qualifyColumnType` hook
110
+ * on its authoring contributions. Duck-typed (mirroring
111
+ * `contract-psl`'s `hasColumnFromEntityHook`) so the SQL family stays blind
112
+ * to the target's qualification logic and no framework/family interface has
113
+ * to name the hook.
114
+ */
115
+ function hasColumnTypeQualifier(authoring) {
116
+ return "qualifyColumnType" in authoring && typeof authoring.qualifyColumnType === "function";
117
+ }
118
+ function resolveColumnTypeQualifier(target) {
119
+ const authoring = target.authoring;
120
+ if (authoring === void 0) return void 0;
121
+ return hasColumnTypeQualifier(authoring) ? authoring.qualifyColumnType : void 0;
122
+ }
123
+ /**
124
+ * Applies the target's `qualifyColumnType` hook to a scalar column descriptor
125
+ * at construction, so the storage column and the domain field (which derives
126
+ * its `type.typeParams` from the storage column) are both built already
127
+ * qualified in a single pass. A descriptor whose codec the target leaves
128
+ * unchanged passes through untouched.
129
+ */
130
+ function qualifyColumnDescriptor(descriptor, namespaceId, qualify) {
131
+ if (qualify === void 0) return descriptor;
132
+ const qualified = qualify({
133
+ codecId: descriptor.codecId,
134
+ nativeType: descriptor.nativeType,
135
+ ...ifDefined("typeParams", descriptor.typeParams)
136
+ }, namespaceId);
137
+ if (qualified.nativeType === descriptor.nativeType && qualified.typeParams === descriptor.typeParams) return descriptor;
138
+ return {
139
+ ...descriptor,
140
+ nativeType: qualified.nativeType,
141
+ ...ifDefined("typeParams", qualified.typeParams)
142
+ };
143
+ }
144
+ /**
145
+ * Records a deferred column's entity-ref into the namespace-scoped collection
146
+ * accumulator (`namespaceId → entityKind → entityName`) — folded into the same
147
+ * namespace assembly `deriveEntityValueSets`/`entries.<kind>` step as the
148
+ * entities-channel attachments, so a column-collected entity gets its
149
+ * value-set the same way an entities-channel one does.
150
+ *
151
+ * The same handle reused by many columns in one namespace is normal (a native
152
+ * enum type backs any number of columns) and records the identical entity once.
153
+ * Two *different* entity instances sharing a name+kind in one namespace is a
154
+ * name collision — the emitted `entries.valueSet.<name>` could only reflect one
155
+ * of them, silently mismatching the other column's type/cast. PSL hard-errors
156
+ * on the equivalent (`PSL_DUPLICATE_DECLARATION`); the TS path rejects it too.
157
+ */
158
+ function collectEntityFromColumn(collected, namespaceId, entityRef) {
159
+ const forNs = collected[namespaceId] ?? {};
160
+ const forKind = forNs[entityRef.entityKind] ?? {};
161
+ const existing = forKind[entityRef.entityName];
162
+ if (existing !== void 0 && existing !== entityRef.entity) throw contractError("CONTRACT.NAME_DUPLICATE", `buildSqlContractFromDefinition: two different "${entityRef.entityKind}" entities named "${entityRef.entityName}" in namespace "${namespaceId}" — pack-entity names must be unique per namespace.`, { meta: {
163
+ kind: entityRef.entityKind,
164
+ name: entityRef.entityName,
165
+ namespaceId
166
+ } });
167
+ forKind[entityRef.entityName] = entityRef.entity;
168
+ forNs[entityRef.entityKind] = forKind;
169
+ collected[namespaceId] = forNs;
170
+ }
171
+ /**
172
+ * Merges a namespace's entities-channel attachments (lowered from the
173
+ * `entities` handle list, carried on `ContractDefinition.attachedEntities`)
174
+ * with the entities collected from that namespace's deferred entity-ref
175
+ * columns. A column-collected entity that shadows a *different* attached
176
+ * entity of the same kind+name (or vice-versa) is the same name-collision bug
177
+ * `collectEntityFromColumn` guards against across columns, so it is rejected
178
+ * the same way — by entity identity, so the same handle attached and used by
179
+ * a column does not throw.
180
+ */
181
+ function mergeColumnAndAttachedEntities(namespaceId, attached, columnCollected) {
182
+ if (attached === void 0) return columnCollected;
183
+ if (columnCollected === void 0) return attached;
184
+ const kinds = /* @__PURE__ */ new Set([...Object.keys(attached), ...Object.keys(columnCollected)]);
185
+ const result = {};
186
+ for (const kind of kinds) {
187
+ const attachedForKind = attached[kind];
188
+ const columnForKind = columnCollected[kind];
189
+ for (const [name, entity] of Object.entries(columnForKind ?? {})) {
190
+ const existing = attachedForKind?.[name];
191
+ if (existing !== void 0 && existing !== entity) throw contractError("CONTRACT.NAME_DUPLICATE", `buildSqlContractFromDefinition: two different "${kind}" entities named "${name}" in namespace "${namespaceId}" — a column-referenced entity conflicts with an attached one; pack-entity names must be unique per namespace.`, { meta: {
192
+ kind,
193
+ name,
194
+ namespaceId
195
+ } });
196
+ }
197
+ result[kind] = {
198
+ ...attachedForKind,
199
+ ...columnForKind
200
+ };
201
+ }
202
+ return result;
203
+ }
204
+ const JSONB_CODEC_ID = "pg/jsonb@1";
205
+ const JSONB_NATIVE_TYPE = "jsonb";
206
+ function resolveModelNamespaceId(model, modelNameToNamespaceId, defaultNamespaceId) {
207
+ if (model.namespaceId !== void 0 && model.namespaceId.length > 0) return model.namespaceId;
208
+ return modelNameToNamespaceId.get(model.modelName) ?? defaultNamespaceId;
209
+ }
210
+ function buildThroughDescriptor(through, tableNamespaceByName, targetModel, modelName, fieldName, defaultNamespaceId) {
211
+ if (!tableNamespaceByName.has(through.table)) throw contractError("CONTRACT.MODEL_UNKNOWN", `buildSqlContractFromDefinition: junction table "${through.table}" for relation "${modelName}.${fieldName}" is not a declared model.`, { meta: {
212
+ sourceModel: modelName,
213
+ relationName: fieldName,
214
+ junctionTable: through.table
215
+ } });
216
+ const namespaceId = through.namespaceId ?? defaultNamespaceId;
217
+ return {
218
+ table: through.table,
219
+ namespaceId,
220
+ parentColumns: through.parentColumns,
221
+ childColumns: through.childColumns,
222
+ targetColumns: targetColumnsForJunction(targetModel, fieldName)
223
+ };
224
+ }
225
+ function targetColumnsForJunction(targetModel, fieldName) {
226
+ const primaryKeyColumns = targetModel.id?.columns;
227
+ if (primaryKeyColumns && primaryKeyColumns.length > 0) return primaryKeyColumns;
228
+ const firstUnique = targetModel.uniques?.find((u) => u.columns.length > 0);
229
+ if (firstUnique) return firstUnique.columns;
230
+ throw contractError("CONTRACT.IDENTITY_INVALID", `M:N target model "${targetModel.modelName}" (relation field "${fieldName}") has no primary id or unique key to derive junction targetColumns.`, { meta: {
231
+ modelName: targetModel.modelName,
232
+ reason: "no-key-for-junction-target-columns"
233
+ } });
234
+ }
235
+ function buildStorageColumn(field, storageValueSetRef, codecLookup) {
236
+ if (isValueObjectField(field)) {
237
+ const encodedDefault = field.default !== void 0 ? encodeColumnDefault(field.default, JSONB_CODEC_ID, codecLookup) : void 0;
238
+ return {
239
+ nativeType: JSONB_NATIVE_TYPE,
240
+ codecId: JSONB_CODEC_ID,
241
+ nullable: field.nullable,
242
+ ...ifDefined("default", encodedDefault)
243
+ };
244
+ }
245
+ const codecId = field.descriptor.codecId;
246
+ const encodedDefault = field.default !== void 0 ? encodeColumnDefault(field.default, codecId, codecLookup, field.many === true) : void 0;
247
+ const valueSet = storageValueSetRef ?? field.descriptor.valueSet;
248
+ return {
249
+ nativeType: field.descriptor.nativeType,
250
+ codecId,
251
+ nullable: field.nullable,
252
+ ...field.many ? { many: true } : {},
253
+ ...ifDefined("typeParams", field.descriptor.typeParams),
254
+ ...ifDefined("default", encodedDefault),
255
+ ...ifDefined("typeRef", field.descriptor.typeRef),
256
+ ...ifDefined("valueSet", valueSet)
257
+ };
258
+ }
259
+ function buildDomainField(field, column, domainValueSetRef) {
260
+ if (isValueObjectField(field)) return {
261
+ type: {
262
+ kind: "valueObject",
263
+ name: field.valueObjectName
264
+ },
265
+ nullable: field.nullable,
266
+ ...field.many ? { many: true } : {}
267
+ };
268
+ return {
269
+ type: {
270
+ kind: "scalar",
271
+ codecId: column.codecId,
272
+ ...ifDefined("typeParams", column.typeParams)
273
+ },
274
+ nullable: column.nullable,
275
+ ...field.many ? { many: true } : {},
276
+ ...ifDefined("valueSet", domainValueSetRef)
277
+ };
278
+ }
279
+ function collectStorageNamespaceCoordinateIds(definition) {
280
+ const ids = /* @__PURE__ */ new Set();
281
+ ids.add(definition.target.defaultNamespaceId);
282
+ for (const id of definition.namespaces ?? []) if (id.length > 0) ids.add(id);
283
+ for (const model of definition.models) if (model.namespaceId !== void 0 && model.namespaceId.length > 0) ids.add(model.namespaceId);
284
+ for (const id of Object.keys(definition.attachedEntities ?? {})) if (id.length > 0) ids.add(id);
285
+ return ids;
286
+ }
287
+ /**
288
+ * Entry kinds the framework assembler itself manages (`table` from models,
289
+ * `valueSet` from `enums` and attached-entity value-set derivation). A
290
+ * pack-attached entity claiming one of these would silently clobber or be
291
+ * clobbered by the managed slot, so it is rejected outright.
292
+ */
293
+ const MANAGED_ENTRY_KINDS = /* @__PURE__ */ new Set([tableEntityKind.kind, valueSetEntityKind.kind]);
294
+ function assertNoManagedEntityKinds(namespaceId, entitiesForNs) {
295
+ if (entitiesForNs === void 0) return;
296
+ for (const kind of Object.keys(entitiesForNs)) if (MANAGED_ENTRY_KINDS.has(kind)) throw contractError("CONTRACT.ENTITY_KIND_INVALID", `buildSqlContractFromDefinition: attached entity in namespace "${namespaceId}" declares entry kind "${kind}", which is managed by the framework (table/valueSet) and cannot be attached.`, { meta: {
297
+ entityKind: kind,
298
+ namespaceId
299
+ } });
300
+ }
301
+ /**
302
+ * Walks the flat `entityTypes` namespace tree contributed by the target pack
303
+ * and every extension pack, indexing descriptors by their `discriminator` —
304
+ * the same string a pack entity's entries-map key (`entries.<kind>`) uses.
305
+ * Mirrors `contract-psl`'s `buildEntityTypesByDiscriminator`, recomposed here
306
+ * from the packs `ContractDefinition` already carries (`target` +
307
+ * `extensions`) since the TS assembler has no single pre-merged
308
+ * `AuthoringContributions` input to read the way the PSL interpreter does.
309
+ */
310
+ function collectEntityTypeDescriptorsByDiscriminator(definition) {
311
+ const result = /* @__PURE__ */ new Map();
312
+ const walk = (namespace) => {
313
+ for (const value of Object.values(namespace)) if (isAuthoringEntityTypeDescriptor(value)) result.set(value.discriminator, value);
314
+ else walk(value);
315
+ };
316
+ const components = [definition.target, ...Object.values(definition.extensions ?? {})];
317
+ for (const component of components) {
318
+ const entityTypes = component.authoring?.entityTypes;
319
+ if (entityTypes !== void 0) walk(entityTypes);
320
+ }
321
+ return result;
322
+ }
323
+ /**
324
+ * Derives value-sets for every pack entity declared in one namespace,
325
+ * reusing the same `SqlValueSetDerivingEntityTypeOutput.deriveValueSet` hook
326
+ * `contract-psl`'s `lowerExtensionBlocksForNamespace` folds into
327
+ * `entries.valueSet` on the PSL path — so a TS-attached entity (e.g. a
328
+ * native enum) gets its value-set the same way. Entity kinds with no
329
+ * registered descriptor, or whose descriptor output doesn't derive a
330
+ * value-set, contribute nothing.
331
+ */
332
+ function deriveEntityValueSets(entitiesForNs, entityTypesByDiscriminator) {
333
+ if (entitiesForNs === void 0) return void 0;
334
+ let result;
335
+ for (const [kind, entitiesByName] of Object.entries(entitiesForNs)) {
336
+ const descriptor = entityTypesByDiscriminator.get(kind);
337
+ if (descriptor === void 0) continue;
338
+ for (const [name, entity] of Object.entries(entitiesByName)) {
339
+ const derivedValueSet = deriveValueSetFromEntity(descriptor.output, entity);
340
+ if (derivedValueSet === void 0) continue;
341
+ result ??= {};
342
+ result[name] = derivedValueSet;
343
+ }
344
+ }
345
+ return result;
346
+ }
347
+ /**
348
+ * Merges a namespace's `enumType()`-derived value-sets with its pack-entity-
349
+ * derived value-sets. Both land in the same `entries.valueSet[name]` slot —
350
+ * which drives value-set → codec typing and the domain-enum CHECK — so a
351
+ * same-named entry in both would let one silently overwrite the other and
352
+ * corrupt whichever column resolves against it. The same collision class the
353
+ * `mergeColumnAndAttachedEntities` guard rejects; the PSL path already hard-errors
354
+ * on the equivalent (`interpretPslDocumentToSqlContract`). Reject it here too.
355
+ */
356
+ function mergeNamespaceValueSets(namespaceId, enumValueSets, packValueSets) {
357
+ if (enumValueSets !== void 0 && packValueSets !== void 0) {
358
+ for (const name of Object.keys(packValueSets)) if (Object.hasOwn(enumValueSets, name)) throw contractError("CONTRACT.NAME_DUPLICATE", `buildSqlContractFromDefinition: value-set "${name}" in namespace "${namespaceId}" is derived from both an enum and a pack entity — names must be unique per namespace.`, { meta: {
359
+ kind: "valueSet",
360
+ name,
361
+ namespaceId
362
+ } });
363
+ }
364
+ return {
365
+ ...enumValueSets,
366
+ ...packValueSets
367
+ };
368
+ }
369
+ function ensureUnboundNamespaceSlot(namespaces, createNamespace) {
370
+ if (Object.hasOwn(namespaces, UNBOUND_NAMESPACE_ID)) return namespaces;
371
+ const unbound = createNamespace({
372
+ id: UNBOUND_NAMESPACE_ID,
373
+ entries: { table: {} }
374
+ });
375
+ return {
376
+ [UNBOUND_NAMESPACE_ID]: unbound,
377
+ ...namespaces
378
+ };
379
+ }
380
+ function buildSqlContractFromDefinition(definition, codecLookup) {
381
+ const target = definition.target.targetId;
382
+ const defaultNamespaceId = definition.target.defaultNamespaceId;
383
+ const qualifyColumnType = resolveColumnTypeQualifier(definition.target);
384
+ const targetFamily = "sql";
385
+ const resolveNamespaceId = (m) => m.namespaceId !== void 0 && m.namespaceId.length > 0 ? m.namespaceId : defaultNamespaceId;
386
+ const modelsByName = new Map(definition.models.map((m) => [m.modelName, m]));
387
+ const tableNamespaceByName = new Map(definition.models.map((m) => [m.tableName, m.namespaceId !== void 0 && m.namespaceId.length > 0 ? m.namespaceId : defaultNamespaceId]));
388
+ const modelsByCoordinate = new Map(definition.models.map((m) => [`${resolveNamespaceId(m)}:${m.modelName}`, m]));
389
+ const tablesByNamespace = {};
390
+ const authoringWarnings = [...definition.warnings ?? []];
391
+ const modelNameToNamespaceId = /* @__PURE__ */ new Map();
392
+ const executionDefaults = [];
393
+ const modelsByNamespace = {};
394
+ const collectedColumnEntities = {};
395
+ const rootEntries = [];
396
+ for (const semanticModel of definition.models) {
397
+ const tableName = semanticModel.tableName;
398
+ const namespaceId = semanticModel.namespaceId !== void 0 && semanticModel.namespaceId.length > 0 ? semanticModel.namespaceId : defaultNamespaceId;
399
+ modelNameToNamespaceId.set(semanticModel.modelName, namespaceId);
400
+ if (!semanticModel.sharesBaseTable) rootEntries.push({
401
+ tableName,
402
+ namespaceId,
403
+ ref: crossRef(semanticModel.modelName, namespaceId)
404
+ });
405
+ const columns = {};
406
+ const fieldToColumn = {};
407
+ const domainFields = {};
408
+ const domainFieldRefs = {};
409
+ const checksForTable = [];
410
+ for (const field of semanticModel.fields) {
411
+ const executionDefaultPhases = field.executionDefaults?.onCreate || field.executionDefaults?.onUpdate ? field.executionDefaults : void 0;
412
+ if (executionDefaultPhases) {
413
+ if (field.default !== void 0) throw contractError("CONTRACT.DEFAULT_INVALID", `Field "${semanticModel.modelName}.${field.fieldName}" cannot define both default and executionDefaults.`, { meta: {
414
+ modelName: semanticModel.modelName,
415
+ fieldName: field.fieldName,
416
+ reason: "default-and-executionDefaults"
417
+ } });
418
+ if (field.nullable) throw contractError("CONTRACT.DEFAULT_INVALID", `Field "${semanticModel.modelName}.${field.fieldName}" cannot be nullable when executionDefaults are present.`, { meta: {
419
+ modelName: semanticModel.modelName,
420
+ fieldName: field.fieldName,
421
+ reason: "nullable-with-executionDefaults"
422
+ } });
423
+ }
424
+ const enumHandle = !isValueObjectField(field) ? field.enumTypeHandle : void 0;
425
+ const storageValueSetRef = enumHandle !== void 0 ? {
426
+ plane: "storage",
427
+ entityKind: "valueSet",
428
+ namespaceId: defaultNamespaceId,
429
+ entityName: enumHandle.enumName
430
+ } : void 0;
431
+ const domainValueSetRef = enumHandle !== void 0 ? {
432
+ plane: "domain",
433
+ entityKind: "enum",
434
+ namespaceId: defaultNamespaceId,
435
+ entityName: enumHandle.enumName
436
+ } : void 0;
437
+ let resolvedField = field;
438
+ if (!isValueObjectField(field)) {
439
+ let descriptor = field.descriptor;
440
+ const entityRef = descriptor.entityRef;
441
+ if (entityRef !== void 0) {
442
+ collectEntityFromColumn(collectedColumnEntities, namespaceId, entityRef);
443
+ descriptor = resolveEntityRefDescriptor(descriptor, namespaceId);
444
+ }
445
+ descriptor = qualifyColumnDescriptor(descriptor, namespaceId, qualifyColumnType);
446
+ if (descriptor !== field.descriptor) resolvedField = {
447
+ ...field,
448
+ descriptor
449
+ };
450
+ }
451
+ const column = buildStorageColumn(resolvedField, storageValueSetRef, codecLookup);
452
+ columns[field.columnName] = column;
453
+ fieldToColumn[field.fieldName] = field.columnName;
454
+ if (column.valueSet !== void 0 && storageValueSetRef !== void 0) checksForTable.push({
455
+ name: `${tableName}_${field.columnName}_check`,
456
+ column: field.columnName,
457
+ valueSet: column.valueSet
458
+ });
459
+ domainFields[field.fieldName] = buildDomainField(field, column, domainValueSetRef);
460
+ if (isValueObjectField(field)) domainFieldRefs[field.fieldName] = {
461
+ kind: "valueObject",
462
+ name: field.valueObjectName,
463
+ ...field.many ? { many: true } : {}
464
+ };
465
+ else if (field.many) domainFieldRefs[field.fieldName] = {
466
+ kind: "scalar",
467
+ many: true
468
+ };
469
+ if (executionDefaultPhases) executionDefaults.push({
470
+ ref: {
471
+ namespace: namespaceId,
472
+ table: tableName,
473
+ column: field.columnName
474
+ },
475
+ ...ifDefined("onCreate", executionDefaultPhases.onCreate),
476
+ ...ifDefined("onUpdate", executionDefaultPhases.onUpdate)
477
+ });
478
+ }
479
+ const authoringForeignKeys = (semanticModel.foreignKeys ?? []).map((fk) => {
480
+ if (fk.references.spaceId !== void 0) {
481
+ const targetNamespaceId = fk.references.namespaceId ?? defaultNamespaceId;
482
+ return {
483
+ source: {
484
+ namespaceId: asNamespaceId(namespaceId),
485
+ tableName,
486
+ columns: fk.columns
487
+ },
488
+ target: {
489
+ namespaceId: asNamespaceId(targetNamespaceId),
490
+ tableName: fk.references.table,
491
+ columns: fk.references.columns,
492
+ spaceId: fk.references.spaceId
493
+ },
494
+ ...applyFkDefaults({
495
+ ...ifDefined("constraint", fk.constraint),
496
+ ...ifDefined("index", fk.index)
497
+ }, definition.foreignKeyDefaults),
498
+ ...ifDefined("name", fk.name),
499
+ ...ifDefined("onDelete", fk.onDelete),
500
+ ...ifDefined("onUpdate", fk.onUpdate)
501
+ };
502
+ }
503
+ const targetModel = assertKnownTargetModel(modelsByName, modelsByCoordinate, semanticModel.modelName, fk.references.model, fk.references.namespaceId, "Foreign key");
504
+ assertTargetTableMatches(semanticModel.modelName, targetModel, fk.references.table, "Foreign key");
505
+ const targetNamespaceId = fk.references.namespaceId ?? (targetModel.namespaceId !== void 0 && targetModel.namespaceId.length > 0 ? targetModel.namespaceId : defaultNamespaceId);
506
+ return {
507
+ source: {
508
+ namespaceId: asNamespaceId(namespaceId),
509
+ tableName,
510
+ columns: fk.columns
511
+ },
512
+ target: {
513
+ namespaceId: asNamespaceId(targetNamespaceId),
514
+ tableName: fk.references.table,
515
+ columns: fk.references.columns
516
+ },
517
+ ...applyFkDefaults({
518
+ ...ifDefined("constraint", fk.constraint),
519
+ ...ifDefined("index", fk.index)
520
+ }, definition.foreignKeyDefaults),
521
+ ...ifDefined("name", fk.name),
522
+ ...ifDefined("onDelete", fk.onDelete),
523
+ ...ifDefined("onUpdate", fk.onUpdate)
524
+ };
525
+ });
526
+ if (!semanticModel.sharesBaseTable) {
527
+ const uniques = (semanticModel.uniques ?? []).map((u) => ({
528
+ columns: u.columns,
529
+ ...ifDefined("name", u.name)
530
+ }));
531
+ const declaredIndexes = (semanticModel.indexes ?? []).map((i) => lowerAuthoredIndex(tableName, blindCast({
532
+ ...ifDefined("columns", i.columns),
533
+ ...ifDefined("expression", i.expression),
534
+ where: i.where,
535
+ unique: i.unique,
536
+ map: i.map,
537
+ name: i.name,
538
+ type: i.type,
539
+ options: i.options
540
+ }), authoringWarnings));
541
+ const primaryKey = semanticModel.id ? {
542
+ columns: semanticModel.id.columns,
543
+ ...ifDefined("name", semanticModel.id.name)
544
+ } : void 0;
545
+ const { foreignKeys, indexes } = materializeForeignKeysAndIndexes(tableName, authoringForeignKeys, declaredIndexes, uniques, primaryKey);
546
+ const tableInput = {
547
+ columns,
548
+ ...ifDefined("control", semanticModel.control),
549
+ uniques,
550
+ indexes: indexes.map((i) => new Index(i)),
551
+ foreignKeys,
552
+ ...primaryKey ? { primaryKey } : {},
553
+ ...checksForTable.length > 0 ? { checks: checksForTable } : {}
554
+ };
555
+ let nsTables = tablesByNamespace[namespaceId];
556
+ if (nsTables === void 0) {
557
+ nsTables = {};
558
+ tablesByNamespace[namespaceId] = nsTables;
559
+ }
560
+ if (nsTables[tableName] !== void 0) throw contractError("CONTRACT.NAME_DUPLICATE", `buildSqlContractFromDefinition: duplicate table "${tableName}" in namespace "${namespaceId}".`, { meta: {
561
+ kind: "table",
562
+ name: tableName,
563
+ namespaceId
564
+ } });
565
+ nsTables[tableName] = tableInput;
566
+ }
567
+ const storageFields = {};
568
+ for (const [fieldName, columnName] of Object.entries(fieldToColumn)) storageFields[fieldName] = { column: columnName };
569
+ const columnToField = new Map(Object.entries(fieldToColumn).map(([field, col]) => [col, field]));
570
+ const modelRelations = {};
571
+ for (const relation of semanticModel.relations ?? []) {
572
+ if (relation.spaceId !== void 0) {
573
+ const targetNamespaceId = relation.namespaceId ?? defaultNamespaceId;
574
+ modelRelations[relation.fieldName] = {
575
+ to: crossRef(relation.toModel, targetNamespaceId, relation.spaceId),
576
+ cardinality: "N:1",
577
+ on: {
578
+ localFields: relation.on.parentColumns.map((col) => columnToField.get(col) ?? col),
579
+ targetFields: relation.on.childColumns
580
+ }
581
+ };
582
+ continue;
583
+ }
584
+ const targetModel = assertKnownTargetModel(modelsByName, modelsByCoordinate, semanticModel.modelName, relation.toModel, relation.toNamespaceId, "Relation");
585
+ assertTargetTableMatches(semanticModel.modelName, targetModel, relation.toTable, "Relation");
586
+ const targetColumnToField = new Map(targetModel.fields.map((f) => [f.columnName, f.fieldName]));
587
+ const to = crossRef(relation.toModel, relation.toNamespaceId !== void 0 && relation.toNamespaceId.length > 0 ? relation.toNamespaceId : resolveModelNamespaceId(targetModel, modelNameToNamespaceId, defaultNamespaceId));
588
+ const on = {
589
+ localFields: relation.on.parentColumns.map((col) => columnToField.get(col) ?? col),
590
+ targetFields: relation.on.childColumns.map((col) => targetColumnToField.get(col) ?? col)
591
+ };
592
+ if (relation.cardinality === "N:M") {
593
+ if (!relation.through) throw contractError("CONTRACT.RELATION_INVALID", `Relation "${semanticModel.modelName}.${relation.fieldName}" with cardinality "N:M" requires through metadata`, { meta: {
594
+ modelName: semanticModel.modelName,
595
+ relationName: relation.fieldName,
596
+ reason: "many-to-many-missing-through"
597
+ } });
598
+ modelRelations[relation.fieldName] = {
599
+ to,
600
+ cardinality: "N:M",
601
+ on,
602
+ through: buildThroughDescriptor(relation.through, tableNamespaceByName, targetModel, semanticModel.modelName, relation.fieldName, defaultNamespaceId)
603
+ };
604
+ } else modelRelations[relation.fieldName] = {
605
+ to,
606
+ cardinality: relation.cardinality,
607
+ on
608
+ };
609
+ }
610
+ let namespaceModels = modelsByNamespace[namespaceId];
611
+ if (namespaceModels === void 0) {
612
+ namespaceModels = {};
613
+ modelsByNamespace[namespaceId] = namespaceModels;
614
+ }
615
+ namespaceModels[semanticModel.modelName] = {
616
+ storage: {
617
+ table: tableName,
618
+ namespaceId,
619
+ fields: storageFields
620
+ },
621
+ fields: domainFields,
622
+ relations: modelRelations
623
+ };
624
+ }
625
+ const rootTableNameCounts = /* @__PURE__ */ new Map();
626
+ for (const entry of rootEntries) rootTableNameCounts.set(entry.tableName, (rootTableNameCounts.get(entry.tableName) ?? 0) + 1);
627
+ const roots = {};
628
+ for (const entry of rootEntries) {
629
+ const key = (rootTableNameCounts.get(entry.tableName) ?? 0) > 1 ? `${entry.namespaceId}.${entry.tableName}` : entry.tableName;
630
+ roots[key] = entry.ref;
631
+ }
632
+ const rawStorageTypes = definition.storageTypes ?? {};
633
+ const documentTypes = Object.fromEntries(Object.entries(rawStorageTypes).map(([name, entry]) => {
634
+ if (entry.kind === "codec-instance") return [name, entry];
635
+ return [name, toStorageTypeInstance({
636
+ codecId: entry.codecId,
637
+ nativeType: entry.nativeType,
638
+ typeParams: entry.typeParams ?? {}
639
+ })];
640
+ }));
641
+ const namespaceCoordinateIds = collectStorageNamespaceCoordinateIds(definition);
642
+ const domainEnumsByNs = {};
643
+ const storageValueSetsByNs = {};
644
+ for (const [enumName, handle] of Object.entries(definition.enums ?? {})) {
645
+ if (enumName !== handle.enumName) throw contractError("CONTRACT.ENUM_INVALID", `enum declaration key "${enumName}" must match enumType name "${handle.enumName}". Aliases are not supported.`, { meta: {
646
+ enumName: handle.enumName,
647
+ declarationKey: enumName,
648
+ reason: "key-name-mismatch"
649
+ } });
650
+ const nsId = defaultNamespaceId;
651
+ let domainSlot = domainEnumsByNs[nsId];
652
+ if (domainSlot === void 0) {
653
+ domainSlot = {};
654
+ domainEnumsByNs[nsId] = domainSlot;
655
+ }
656
+ domainSlot[enumName] = {
657
+ codecId: handle.codecId,
658
+ members: handle.enumMembers.map((m) => ({
659
+ name: m.name,
660
+ value: encodeViaCodec(m.value, handle.codecId, codecLookup)
661
+ }))
662
+ };
663
+ let storageSlot = storageValueSetsByNs[nsId];
664
+ if (storageSlot === void 0) {
665
+ storageSlot = {};
666
+ storageValueSetsByNs[nsId] = storageSlot;
667
+ }
668
+ storageSlot[enumName] = {
669
+ kind: "valueSet",
670
+ values: handle.values.map((v) => encodeViaCodec(v, handle.codecId, codecLookup))
671
+ };
672
+ }
673
+ const { createNamespace } = definition;
674
+ const entityTypesByDiscriminator = collectEntityTypeDescriptorsByDiscriminator(definition);
675
+ const namespaces = Object.fromEntries([...namespaceCoordinateIds].sort().map((id) => {
676
+ const entitiesForNs = mergeColumnAndAttachedEntities(id, definition.attachedEntities?.[id], collectedColumnEntities[id]);
677
+ assertNoManagedEntityKinds(id, entitiesForNs);
678
+ const enumValueSetEntries = storageValueSetsByNs[id];
679
+ const packValueSetEntries = deriveEntityValueSets(entitiesForNs, entityTypesByDiscriminator);
680
+ const valueSetEntries = enumValueSetEntries !== void 0 || packValueSetEntries !== void 0 ? mergeNamespaceValueSets(id, enumValueSetEntries, packValueSetEntries) : void 0;
681
+ const nsInput = {
682
+ id,
683
+ entries: {
684
+ table: tablesByNamespace[id] ?? {},
685
+ ...entitiesForNs,
686
+ ...valueSetEntries !== void 0 && Object.keys(valueSetEntries).length > 0 ? { valueSet: valueSetEntries } : {}
687
+ }
688
+ };
689
+ return [id, createNamespace(nsInput)];
690
+ }));
691
+ const storageWithoutHash = {
692
+ ...Object.keys(documentTypes).length > 0 ? { types: documentTypes } : {},
693
+ namespaces: defaultNamespaceId === UNBOUND_NAMESPACE_ID ? ensureUnboundNamespaceSlot(namespaces, createNamespace) : namespaces
694
+ };
695
+ const storageHash = definition.storageHash ? coreHash(definition.storageHash) : computeStorageHash({
696
+ target,
697
+ targetFamily,
698
+ storage: storageWithoutHash,
699
+ ...sqlContractCanonicalizationHooks
700
+ });
701
+ const storage = new SqlStorage({
702
+ ...storageWithoutHash,
703
+ storageHash
704
+ });
705
+ const executionSection = executionDefaults.length > 0 ? { mutations: { defaults: executionDefaults.sort((a, b) => {
706
+ const tableCompare = a.ref.table.localeCompare(b.ref.table);
707
+ if (tableCompare !== 0) return tableCompare;
708
+ return a.ref.column.localeCompare(b.ref.column);
709
+ }) } } : void 0;
710
+ const extensionNamespaces = definition.extensions ? Object.values(definition.extensions).map((pack) => pack.id) : void 0;
711
+ const extensions = { ...definition.extensions || {} };
712
+ if (extensionNamespaces) {
713
+ for (const namespace of extensionNamespaces) if (!Object.hasOwn(extensions, namespace)) extensions[namespace] = {};
714
+ }
715
+ const extensionPackCapabilitySources = definition.extensions ? Object.values(definition.extensions).map((pack) => pack.capabilities) : [];
716
+ const capabilities = mergeCapabilityMatrices(definition.target.capabilities, ...extensionPackCapabilitySources);
717
+ const profileHash = computeProfileHash({
718
+ target,
719
+ targetFamily,
720
+ capabilities: {}
721
+ });
722
+ const executionWithHash = executionSection ? {
723
+ ...executionSection,
724
+ executionHash: computeExecutionHash({
725
+ target,
726
+ targetFamily,
727
+ execution: executionSection
728
+ })
729
+ } : void 0;
730
+ const valueObjects = definition.valueObjects && definition.valueObjects.length > 0 ? Object.fromEntries(definition.valueObjects.map((vo) => [vo.name, { fields: Object.fromEntries(vo.fields.map((f) => [f.fieldName, isValueObjectField(f) ? {
731
+ type: {
732
+ kind: "valueObject",
733
+ name: f.valueObjectName
734
+ },
735
+ nullable: f.nullable,
736
+ ...f.many ? { many: true } : {}
737
+ } : {
738
+ type: {
739
+ kind: "scalar",
740
+ codecId: f.descriptor.codecId,
741
+ ...ifDefined("typeParams", f.descriptor.typeParams)
742
+ },
743
+ nullable: f.nullable
744
+ }])) }])) : void 0;
745
+ const domainNamespaceIds = new Set(Object.keys(modelsByNamespace));
746
+ if (domainNamespaceIds.size === 0) domainNamespaceIds.add(defaultNamespaceId);
747
+ if (valueObjects !== void 0) domainNamespaceIds.add(defaultNamespaceId);
748
+ for (const nsId of Object.keys(domainEnumsByNs)) domainNamespaceIds.add(nsId);
749
+ const domainNamespaces = Object.fromEntries([...domainNamespaceIds].sort().map((namespaceId) => {
750
+ const modelsInNs = modelsByNamespace[namespaceId] ?? {};
751
+ const enumsInNs = domainEnumsByNs[namespaceId];
752
+ return [namespaceId, {
753
+ models: modelsInNs,
754
+ ...namespaceId === defaultNamespaceId && valueObjects !== void 0 ? { valueObjects } : {},
755
+ ...enumsInNs !== void 0 && Object.keys(enumsInNs).length > 0 ? { enum: enumsInNs } : {}
756
+ }];
757
+ }));
758
+ const contract = {
759
+ target,
760
+ targetFamily,
761
+ ...ifDefined("defaultControlPolicy", definition.defaultControlPolicy),
762
+ domain: { namespaces: domainNamespaces },
763
+ roots,
764
+ storage,
765
+ ...executionWithHash ? { execution: executionWithHash } : {},
766
+ extensions,
767
+ capabilities,
768
+ profileHash,
769
+ meta: {}
770
+ };
771
+ assertStorageSemantics(definition, contract);
772
+ flushAuthoringWarnings(authoringWarnings);
773
+ return contract;
774
+ }
775
+ //#endregion
776
+ export { contractError as n, buildSqlContractFromDefinition as t };
777
+
778
+ //# sourceMappingURL=build-contract-DBCz_YSs-DO0wMHai.mjs.map