viborm 1.3.2 → 1.4.0

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 (241) hide show
  1. package/dist/{adapter-internals-AGgQRu5t.mjs → adapter-internals-Cy2QEBnH.mjs} +1 -1
  2. package/dist/{adapter-internals-AGgQRu5t.mjs.map → adapter-internals-Cy2QEBnH.mjs.map} +1 -1
  3. package/dist/{adapter-namespace-B8XWzCev.mjs → adapter-namespace-BLejG8FA.mjs} +2 -2
  4. package/dist/{adapter-namespace-B8XWzCev.mjs.map → adapter-namespace-BLejG8FA.mjs.map} +1 -1
  5. package/dist/adapter-result-parser-D6lluSMi.mjs +2 -0
  6. package/dist/adapter-result-parser-D6lluSMi.mjs.map +1 -0
  7. package/dist/adapters.d.mts +1 -1
  8. package/dist/adapters.mjs +1 -1
  9. package/dist/{array-literal-BKdLfNzM.mjs → array-literal-BsbbSLw3.mjs} +1 -1
  10. package/dist/{array-literal-BKdLfNzM.mjs.map → array-literal-BsbbSLw3.mjs.map} +1 -1
  11. package/dist/{batch-refs-DoWlPD2h.mjs → batch-refs-BYCu1JnQ.mjs} +2 -2
  12. package/dist/{batch-refs-DoWlPD2h.mjs.map → batch-refs-BYCu1JnQ.mjs.map} +1 -1
  13. package/dist/bind-parameter-capacity-D6p9HrbB.mjs +2 -0
  14. package/dist/bind-parameter-capacity-D6p9HrbB.mjs.map +1 -0
  15. package/dist/builder-BS8EW4BQ.mjs +2 -0
  16. package/dist/builder-BS8EW4BQ.mjs.map +1 -0
  17. package/dist/bun-sql.d.mts +3 -1
  18. package/dist/bun-sql.mjs +1 -1
  19. package/dist/bun-sql.mjs.map +1 -1
  20. package/dist/bun-sqlite.d.mts +1 -1
  21. package/dist/bun-sqlite.mjs +1 -1
  22. package/dist/cache/cloudflare-kv.d.mts +1 -1
  23. package/dist/cache/cloudflare-kv.mjs +1 -1
  24. package/dist/cache/memory.d.mts +1 -1
  25. package/dist/cache/memory.mjs +1 -1
  26. package/dist/cache.d.mts +1 -1
  27. package/dist/cache.mjs +1 -1
  28. package/dist/{canonical-json-BReb5nFO.mjs → canonical-json-acY4dQNQ.mjs} +2 -2
  29. package/dist/canonical-json-acY4dQNQ.mjs.map +1 -0
  30. package/dist/chain-D5J9hIw-.mjs +2 -0
  31. package/dist/chain-D5J9hIw-.mjs.map +1 -0
  32. package/dist/cli.mjs +1 -1
  33. package/dist/client-Bhl2mWam.mjs +2 -0
  34. package/dist/client-Bhl2mWam.mjs.map +1 -0
  35. package/dist/{client-Df81J4oB.d.mts → client-BzgBm_86.d.mts} +4 -2
  36. package/dist/{client-q6ccRgdO.mjs → client-aU3YhZ6G.mjs} +16 -16
  37. package/dist/client-aU3YhZ6G.mjs.map +1 -0
  38. package/dist/client.d.mts +1 -1
  39. package/dist/client.mjs +1 -1
  40. package/dist/{clock-YTLtjLFS.mjs → clock-CJotKAxc.mjs} +1 -1
  41. package/dist/{clock-YTLtjLFS.mjs.map → clock-CJotKAxc.mjs.map} +1 -1
  42. package/dist/config.d.mts +1 -1
  43. package/dist/config.mjs +1 -1
  44. package/dist/d1.d.mts +1 -1
  45. package/dist/d1.mjs +1 -1
  46. package/dist/d1.mjs.map +1 -1
  47. package/dist/datetime-physical-codec-lX7IJBlz.mjs +2 -0
  48. package/dist/datetime-physical-codec-lX7IJBlz.mjs.map +1 -0
  49. package/dist/driver-CQQbCQh9.mjs +2 -0
  50. package/dist/{driver-Ddt147dK.mjs.map → driver-CQQbCQh9.mjs.map} +1 -1
  51. package/dist/{driver-D6_Ik58x.mjs → driver-u2qJicrE.mjs} +2 -2
  52. package/dist/{driver-D6_Ik58x.mjs.map → driver-u2qJicrE.mjs.map} +1 -1
  53. package/dist/driver.d.mts +1 -1
  54. package/dist/driver.mjs +1 -1
  55. package/dist/{error-mapping-C9WgitPi.mjs → error-mapping-6op318w6.mjs} +2 -2
  56. package/dist/error-mapping-6op318w6.mjs.map +1 -0
  57. package/dist/every-CzF00eDV.mjs +2 -0
  58. package/dist/{every-dpzVDwzu.mjs.map → every-CzF00eDV.mjs.map} +1 -1
  59. package/dist/{fs-estate-azK36i9V.mjs → fs-estate-N_F2YqYa.mjs} +2 -2
  60. package/dist/{fs-estate-azK36i9V.mjs.map → fs-estate-N_F2YqYa.mjs.map} +1 -1
  61. package/dist/{geo-area-codec-CbkmFArQ.mjs → geo-area-codec-BmMmWgU_.mjs} +2 -2
  62. package/dist/{geo-area-codec-CbkmFArQ.mjs.map → geo-area-codec-BmMmWgU_.mjs.map} +1 -1
  63. package/dist/{geo-point-codec-DyEHMdJg.mjs → geo-point-codec-D95uXgDF.mjs} +2 -2
  64. package/dist/{geo-point-codec-DyEHMdJg.mjs.map → geo-point-codec-D95uXgDF.mjs.map} +1 -1
  65. package/dist/{hydration-C2uXmJy6.mjs → hydration-BflrXEIQ.mjs} +2 -2
  66. package/dist/{hydration-C2uXmJy6.mjs.map → hydration-BflrXEIQ.mjs.map} +1 -1
  67. package/dist/{identifier-conversion-C2pwwFOS.mjs → identifier-conversion-Dc0Rf4Gi.mjs} +2 -2
  68. package/dist/{identifier-conversion-C2pwwFOS.mjs.map → identifier-conversion-Dc0Rf4Gi.mjs.map} +1 -1
  69. package/dist/identity-CmRos0Yf.mjs +2 -0
  70. package/dist/identity-CmRos0Yf.mjs.map +1 -0
  71. package/dist/{index-D4O0Twvs.d.mts → index-B4IWFJfv.d.mts} +1304 -1056
  72. package/dist/index.d.mts +2 -2
  73. package/dist/index.mjs +1 -1
  74. package/dist/instrumentation.d.mts +1 -1
  75. package/dist/instrumentation.mjs +1 -1
  76. package/dist/{invariant-D57gi_yW.mjs → invariant-D_fIjY_z.mjs} +1 -1
  77. package/dist/{invariant-D57gi_yW.mjs.map → invariant-D_fIjY_z.mjs.map} +1 -1
  78. package/dist/{json-number-DvmiNx0n.mjs → json-number-CGXpPu4D.mjs} +1 -1
  79. package/dist/{json-number-DvmiNx0n.mjs.map → json-number-CGXpPu4D.mjs.map} +1 -1
  80. package/dist/{key-B7vuAYPG.mjs → key-B89Z4vxn.mjs} +2 -2
  81. package/dist/{key-B7vuAYPG.mjs.map → key-B89Z4vxn.mjs.map} +1 -1
  82. package/dist/{libsql-DUO6vHad.mjs → libsql-CrDXsfpL.mjs} +2 -2
  83. package/dist/{libsql-DUO6vHad.mjs.map → libsql-CrDXsfpL.mjs.map} +1 -1
  84. package/dist/libsql.d.mts +1 -1
  85. package/dist/libsql.mjs +1 -1
  86. package/dist/libsql.mjs.map +1 -1
  87. package/dist/{memory-BApsTkt1.mjs → memory-TXO4KgBy.mjs} +2 -2
  88. package/dist/{memory-BApsTkt1.mjs.map → memory-TXO4KgBy.mjs.map} +1 -1
  89. package/dist/migrations/mysql.d.mts +4 -4
  90. package/dist/migrations/mysql.mjs +1 -1
  91. package/dist/migrations/postgres.d.mts +4 -4
  92. package/dist/migrations/postgres.mjs +1 -1
  93. package/dist/migrations/sqlite.d.mts +4 -4
  94. package/dist/migrations/sqlite.mjs +1 -1
  95. package/dist/migrations/storage/durable-object.mjs +1 -1
  96. package/dist/migrations/storage/fs.mjs +1 -1
  97. package/dist/migrations/storage/r2.mjs +1 -1
  98. package/dist/migrations/tenant.d.mts +2 -2
  99. package/dist/migrations/tenant.mjs +1 -1
  100. package/dist/migrations.d.mts +4 -4
  101. package/dist/migrations.mjs +1 -1
  102. package/dist/{mysql-D1GlcktG.mjs → mysql-C2vOPcuA.mjs} +2 -2
  103. package/dist/{mysql-D1GlcktG.mjs.map → mysql-C2vOPcuA.mjs.map} +1 -1
  104. package/dist/mysql-adapter-C5CMIYRS.mjs +2 -0
  105. package/dist/mysql-adapter-C5CMIYRS.mjs.map +1 -0
  106. package/dist/mysql2.d.mts +1 -1
  107. package/dist/mysql2.mjs +1 -1
  108. package/dist/mysql2.mjs.map +1 -1
  109. package/dist/neon-http.d.mts +3 -1
  110. package/dist/neon-http.mjs +1 -1
  111. package/dist/neon-http.mjs.map +1 -1
  112. package/dist/normalized-result-BF7gr4_b.mjs +2 -0
  113. package/dist/normalized-result-BF7gr4_b.mjs.map +1 -0
  114. package/dist/{object-store-CZADAv4c.mjs → object-store-WjVilDvN.mjs} +2 -2
  115. package/dist/{object-store-CZADAv4c.mjs.map → object-store-WjVilDvN.mjs.map} +1 -1
  116. package/dist/{object-store-BN64q8Zn.d.mts → object-store-uRqi0URP.d.mts} +3 -3
  117. package/dist/permissions.d.mts +1 -1
  118. package/dist/permissions.mjs +1 -1
  119. package/dist/permissions.mjs.map +1 -1
  120. package/dist/pg.d.mts +26 -1
  121. package/dist/pg.mjs +1 -1
  122. package/dist/pg.mjs.map +1 -1
  123. package/dist/pglite.d.mts +3 -1
  124. package/dist/pglite.mjs +1 -1
  125. package/dist/pglite.mjs.map +1 -1
  126. package/dist/{physical-CAOaNM4R.mjs → physical-uJfmo4-Z.mjs} +2 -2
  127. package/dist/{physical-CAOaNM4R.mjs.map → physical-uJfmo4-Z.mjs.map} +1 -1
  128. package/dist/{pinned-session-CjvR0Ge2.mjs → pinned-session-FYOFV_gB.mjs} +2 -2
  129. package/dist/{pinned-session-CjvR0Ge2.mjs.map → pinned-session-FYOFV_gB.mjs.map} +1 -1
  130. package/dist/planetscale.d.mts +1 -1
  131. package/dist/planetscale.mjs +1 -1
  132. package/dist/planetscale.mjs.map +1 -1
  133. package/dist/{planner-8smxUOt9.d.mts → planner-SzkGh-3T.d.mts} +1 -1
  134. package/dist/{postgres-Be0jMJWI.mjs → postgres-BSmy1PYR.mjs} +2 -2
  135. package/dist/{postgres-Be0jMJWI.mjs.map → postgres-BSmy1PYR.mjs.map} +1 -1
  136. package/dist/postgres-adapter-B1RyJlWL.mjs +2 -0
  137. package/dist/postgres-adapter-B1RyJlWL.mjs.map +1 -0
  138. package/dist/postgres-adapter-BAqRfWl1.mjs +2 -0
  139. package/dist/postgres-adapter-BAqRfWl1.mjs.map +1 -0
  140. package/dist/postgres-result-BCUQf8b_.mjs +2 -0
  141. package/dist/{postgres-result-CYu1dyI_.mjs.map → postgres-result-BCUQf8b_.mjs.map} +1 -1
  142. package/dist/postgres.d.mts +3 -1
  143. package/dist/postgres.mjs +1 -1
  144. package/dist/postgres.mjs.map +1 -1
  145. package/dist/{provider-limits-Da00ilvv.mjs → provider-limits-V09frtmK.mjs} +2 -2
  146. package/dist/{provider-limits-Da00ilvv.mjs.map → provider-limits-V09frtmK.mjs.map} +1 -1
  147. package/dist/relation-bound-BrZLsSke.mjs +2 -0
  148. package/dist/relation-bound-BrZLsSke.mjs.map +1 -0
  149. package/dist/{result-parsing-8wEK3GY1.mjs → result-parsing-CQf_eCl8.mjs} +1 -1
  150. package/dist/{result-parsing-8wEK3GY1.mjs.map → result-parsing-CQf_eCl8.mjs.map} +1 -1
  151. package/dist/result-shape-Fi1-Fvri.mjs +2 -0
  152. package/dist/result-shape-Fi1-Fvri.mjs.map +1 -0
  153. package/dist/{rows-JXjhWwyb.mjs → rows-BiaiswSV.mjs} +2 -2
  154. package/dist/{rows-JXjhWwyb.mjs.map → rows-BiaiswSV.mjs.map} +1 -1
  155. package/dist/{scalar-CqqZ6jWd.mjs → scalar-Cm7nMFmO.mjs} +2 -2
  156. package/dist/{scalar-CqqZ6jWd.mjs.map → scalar-Cm7nMFmO.mjs.map} +1 -1
  157. package/dist/schema/json.d.mts +1 -1
  158. package/dist/schema/json.mjs +1 -1
  159. package/dist/{schema-introspection-B2Rvqgut.mjs → schema-introspection-C1-XrQP4.mjs} +2 -2
  160. package/dist/{schema-introspection-B2Rvqgut.mjs.map → schema-introspection-C1-XrQP4.mjs.map} +1 -1
  161. package/dist/{schema-Cv-hhpl5.mjs → schema-tGtziyCJ.mjs} +2 -2
  162. package/dist/{schema-Cv-hhpl5.mjs.map → schema-tGtziyCJ.mjs.map} +1 -1
  163. package/dist/schema.d.mts +1 -1
  164. package/dist/schema.mjs +1 -1
  165. package/dist/select-assembly-BjT_fDbu.mjs +2 -0
  166. package/dist/select-assembly-BjT_fDbu.mjs.map +1 -0
  167. package/dist/{settle-etgtP1WM.mjs → settle-C4w1GfTU.mjs} +2 -2
  168. package/dist/{settle-etgtP1WM.mjs.map → settle-C4w1GfTU.mjs.map} +1 -1
  169. package/dist/{sha256-CEYo7k7R.mjs → sha256-_Nu4s32f.mjs} +1 -1
  170. package/dist/{sha256-CEYo7k7R.mjs.map → sha256-_Nu4s32f.mjs.map} +1 -1
  171. package/dist/soft-delete.d.mts +3 -3
  172. package/dist/sql-BvHwL73I.mjs +2 -0
  173. package/dist/sql-BvHwL73I.mjs.map +1 -0
  174. package/dist/{sql-EsoN_7Et.d.mts → sql-Q_twK-wW.d.mts} +5 -0
  175. package/dist/{sql-statement-tokens-BW7Q-rF-.mjs → sql-statement-tokens-4J5l5Lyt.mjs} +1 -1
  176. package/dist/{sql-statement-tokens-BW7Q-rF-.mjs.map → sql-statement-tokens-4J5l5Lyt.mjs.map} +1 -1
  177. package/dist/sql.d.mts +1 -1
  178. package/dist/sql.mjs +1 -1
  179. package/dist/sqlite-adapter-CoDeF2h2.mjs +2 -0
  180. package/dist/sqlite-adapter-CoDeF2h2.mjs.map +1 -0
  181. package/dist/{sqlite-utils-DIOll4P7.mjs → sqlite-utils-C0TyzOys.mjs} +2 -2
  182. package/dist/{sqlite-utils-DIOll4P7.mjs.map → sqlite-utils-C0TyzOys.mjs.map} +1 -1
  183. package/dist/sqlite3.d.mts +1 -1
  184. package/dist/sqlite3.mjs +1 -1
  185. package/dist/sqlite3.mjs.map +1 -1
  186. package/dist/{standard-sql-mJt0RHHE.mjs → standard-sql-DmKF8msN.mjs} +2 -2
  187. package/dist/standard-sql-DmKF8msN.mjs.map +1 -0
  188. package/dist/{to-many-BSipkSbK.mjs → to-many-Btc9X5Ga.mjs} +2 -2
  189. package/dist/{to-many-BSipkSbK.mjs.map → to-many-Btc9X5Ga.mjs.map} +1 -1
  190. package/dist/transaction-operation-CU1zlxiG.mjs.map +1 -1
  191. package/dist/{utils-DjXObbUK.mjs → utils-DkAxKcDD.mjs} +2 -2
  192. package/dist/{utils-DjXObbUK.mjs.map → utils-DkAxKcDD.mjs.map} +1 -1
  193. package/dist/{v-CrJYqdzu.mjs → v-514RME2X.mjs} +2 -2
  194. package/dist/{v-CrJYqdzu.mjs.map → v-514RME2X.mjs.map} +1 -1
  195. package/dist/{validation-BQtO6srU.mjs → validation-C7Z6wTJa.mjs} +2 -2
  196. package/dist/{validation-BQtO6srU.mjs.map → validation-C7Z6wTJa.mjs.map} +1 -1
  197. package/dist/validation-gwZYm3Yn.mjs +2 -0
  198. package/dist/validation-gwZYm3Yn.mjs.map +1 -0
  199. package/dist/validation.d.mts +1 -1
  200. package/dist/validation.mjs +1 -1
  201. package/dist/{validator-BqzpyNmt.mjs → validator-CQOw7G3q.mjs} +2 -2
  202. package/dist/{validator-BqzpyNmt.mjs.map → validator-CQOw7G3q.mjs.map} +1 -1
  203. package/dist/version-n393hhwM.mjs +2 -0
  204. package/dist/{version-Dus3if78.mjs.map → version-n393hhwM.mjs.map} +1 -1
  205. package/package.json +14 -14
  206. package/dist/bind-parameter-capacity-qfEejeOX.mjs +0 -2
  207. package/dist/bind-parameter-capacity-qfEejeOX.mjs.map +0 -1
  208. package/dist/builder-DhxaVYP2.mjs +0 -2
  209. package/dist/builder-DhxaVYP2.mjs.map +0 -1
  210. package/dist/canonical-json-BReb5nFO.mjs.map +0 -1
  211. package/dist/chain-BjJ_M7EE.mjs +0 -2
  212. package/dist/chain-BjJ_M7EE.mjs.map +0 -1
  213. package/dist/client-BCgMXn6N.mjs +0 -2
  214. package/dist/client-BCgMXn6N.mjs.map +0 -1
  215. package/dist/client-q6ccRgdO.mjs.map +0 -1
  216. package/dist/datetime-physical-codec-BEqQbIP_.mjs +0 -2
  217. package/dist/datetime-physical-codec-BEqQbIP_.mjs.map +0 -1
  218. package/dist/driver-Ddt147dK.mjs +0 -2
  219. package/dist/error-mapping-C9WgitPi.mjs.map +0 -1
  220. package/dist/every-dpzVDwzu.mjs +0 -2
  221. package/dist/identity-Bj2EN6Ss.mjs +0 -2
  222. package/dist/identity-Bj2EN6Ss.mjs.map +0 -1
  223. package/dist/mysql-adapter-ClOoHKpn.mjs +0 -2
  224. package/dist/mysql-adapter-ClOoHKpn.mjs.map +0 -1
  225. package/dist/postgres-adapter-BoQ4RRwr.mjs +0 -2
  226. package/dist/postgres-adapter-BoQ4RRwr.mjs.map +0 -1
  227. package/dist/postgres-adapter-C_Mt8lVC.mjs +0 -2
  228. package/dist/postgres-adapter-C_Mt8lVC.mjs.map +0 -1
  229. package/dist/postgres-result-CYu1dyI_.mjs +0 -2
  230. package/dist/result-shape-DQc-tDJ5.mjs +0 -2
  231. package/dist/result-shape-DQc-tDJ5.mjs.map +0 -1
  232. package/dist/select-assembly-BxtETbG9.mjs +0 -2
  233. package/dist/select-assembly-BxtETbG9.mjs.map +0 -1
  234. package/dist/sql-Bhxq9arK.mjs +0 -2
  235. package/dist/sql-Bhxq9arK.mjs.map +0 -1
  236. package/dist/sqlite-adapter-B_LNxPA0.mjs +0 -2
  237. package/dist/sqlite-adapter-B_LNxPA0.mjs.map +0 -1
  238. package/dist/standard-sql-mJt0RHHE.mjs.map +0 -1
  239. package/dist/validation-BamBwne9.mjs +0 -2
  240. package/dist/validation-BamBwne9.mjs.map +0 -1
  241. package/dist/version-Dus3if78.mjs +0 -2
@@ -1,4 +1,4 @@
1
- import { c as sqlTag, n as Sql } from "./sql-EsoN_7Et.mjs";
1
+ import { c as sqlTag, n as Sql } from "./sql-Q_twK-wW.mjs";
2
2
  import { StandardSchemaV1 } from "@standard-schema/spec";
3
3
 
4
4
  //#region src/schema/scalars/native-types.d.ts
@@ -625,6 +625,18 @@ interface DatabaseAdapterCapabilities {
625
625
  * clause, so a read taken only to lock rows is skipped there.
626
626
  */
627
627
  supportsRowLocks: boolean;
628
+ /**
629
+ * Whether a locking read whose exact match finds NOTHING still takes a lock.
630
+ * MySQL (InnoDB) does: a gap or next-key lock that two concurrent misses
631
+ * both hold and that each one's INSERT then waits on, a deadlock. So a read
632
+ * whose other arm inserts the key it looked for reads unlocked there and is
633
+ * confirmed under lock once it finds a row. PostgreSQL locks only the rows a
634
+ * read returns, so there that read locks what it finds and needs no
635
+ * confirmation. SQLite takes no row lock at all (`supportsRowLocks`), so
636
+ * its confirmation stays: it is the read that sees what changed. Absent:
637
+ * false.
638
+ */
639
+ locksMissingKeys?: boolean;
628
640
  /**
629
641
  * Whether a statement states each relation filter body it repeats ONCE, in
630
642
  * a `WITH`, as the key set every arm repeating it tests (a semijoin on the
@@ -634,6 +646,51 @@ interface DatabaseAdapterCapabilities {
634
646
  * a recursive walk stays where it is. Absent: false.
635
647
  */
636
648
  sharesRelationBodies?: boolean;
649
+ /**
650
+ * Whether a many-to-many relation filter reads its junction joined to the
651
+ * target, correlated in the filter's own `WHERE` (`EXISTS (SELECT 1 FROM
652
+ * junction j JOIN target t ON t.key = j.target WHERE j.source = parent.key
653
+ * AND …)`), rather than as the target's membership in a correlated junction
654
+ * subquery. `true` where the dialect plans the joined form at least as well
655
+ * everywhere measured (SQLite); `"unbounded"` where it does only in a
656
+ * statement whose root read is unbounded, a count, an aggregate, a
657
+ * `findMany` without `take` or a write: PostgreSQL turns the join into a
658
+ * hashed semijoin there (10–300× faster scans) but plans it about 0.2 ms
659
+ * more slowly, which a bounded read (a unique, first or existence read, a
660
+ * `take`) pays without the scan to win it back. Absent: false.
661
+ */
662
+ joinsJunctionFilters?: boolean | "unbounded";
663
+ /**
664
+ * Whether a recursive CTE fails once it runs a fixed number of iterations
665
+ * (MySQL's `cte_max_recursion_depth`, 1000 by default): a recursive filter
666
+ * then keeps its walk in place, whose anchor holds the first hop, rather
667
+ * than a reaching set, which spends one iteration per depth from its
668
+ * anchor. Absent: false.
669
+ */
670
+ boundsRecursionIterations?: boolean;
671
+ /**
672
+ * The most terms one compound `SELECT` may chain, where the transport
673
+ * bounds it below anything the engine writes: Cloudflare D1, 5. The engine
674
+ * nests a longer union in derived tables of at most that many. Absent:
675
+ * unbounded.
676
+ */
677
+ compoundSelectTerms?: number;
678
+ /**
679
+ * Whether the transport bounds expression depth below what nested relation
680
+ * filters reach unless each level reads from a derived table SQLite
681
+ * flattens (D1, depth 100; `SQLiteAdapter({ deepExpressions: false })`):
682
+ * a relation filter's own `EXISTS` then joins no flag member. Absent: false.
683
+ */
684
+ boundsExpressionDepth?: boolean;
685
+ /**
686
+ * Where relation bodies are shared, the relations (`FROM` items) a
687
+ * statement may reference before the engine trades plans for fewer:
688
+ * PlanetScale Neki refuses a statement over 256. Over it, a recursive
689
+ * filter's walk the statement repeats becomes one reaching set, then rows
690
+ * join the key sets they test, each as far as the statement needs. Absent:
691
+ * unbounded, so neither.
692
+ */
693
+ relationsPerStatement?: number;
637
694
  }
638
695
  //#endregion
639
696
  //#region src/adapters/adapter-core-types.d.ts
@@ -1150,8 +1207,15 @@ declare class ForbiddenError extends VibORMError {
1150
1207
  static readonly diagnosticName = "ForbiddenError";
1151
1208
  /** Literal discriminant: this class always carries `FORBIDDEN`. */
1152
1209
  readonly code: typeof VibORMErrorCode.FORBIDDEN;
1210
+ /**
1211
+ * `reason` names what refused the operation where the operation alone does
1212
+ * not say it, e.g. a field an update writes through a nested write;
1213
+ * `cause`, the failure it explains (an upsert's unique violation).
1214
+ */
1153
1215
  constructor(model: string, operation: string, options?: {
1154
1216
  meta?: VibORMErrorMeta;
1217
+ reason?: string;
1218
+ cause?: Error;
1155
1219
  });
1156
1220
  }
1157
1221
  /**
@@ -4758,1193 +4822,1266 @@ interface RawOperation<T$1> extends Promise<T$1> {
4758
4822
  readonly [RAW_OPERATION]: true;
4759
4823
  }
4760
4824
  //#endregion
4761
- //#region src/extensions/methods.d.ts
4762
- type NoMethods = Record<never, never>;
4763
- type ExtensionMethod = (this: void, ...args: never[]) => unknown;
4764
- type ExtensionMethodRecord = Readonly<Record<string, ExtensionMethod>>;
4765
- declare const extensionCacheState: unique symbol;
4766
- interface ExtensionCacheState {
4767
- readonly [extensionCacheState]: true;
4768
- }
4769
- declare const extensionResultConsumerState: unique symbol;
4770
- interface ExtensionResultConsumerState {
4771
- readonly [extensionResultConsumerState]: true;
4772
- }
4773
- /** The only static facts accumulated while extensions are chained. */
4774
- interface ClientExtensionState<ClientMethods extends object = NoMethods, ModelMethods extends object = NoMethods, CacheState extends ExtensionCacheState | undefined = undefined, ResultConsumerState extends ExtensionResultConsumerState | undefined = undefined, Controls$1 extends object = NoControls, RowModels extends string = never, Data$1 = never> {
4775
- readonly client: ClientMethods;
4776
- readonly models: ModelMethods;
4777
- readonly cache: CacheState;
4778
- readonly resultConsumer: ResultConsumerState;
4779
- /** The controls the chain declares: each one's values and placement. */
4780
- readonly controls: Controls$1;
4781
- /** The models the chain's `rows` can hide from a relation read. */
4782
- readonly rows: RowModels;
4783
- /** The fields the chain's `data` writes, which a caller no longer writes. */
4784
- readonly data: Data$1;
4785
- }
4786
- type EmptyClientExtensionState = ClientExtensionState;
4787
- /** Internal constraint for either the absent or enabled nominal cache bit. */
4788
- type ExtensionStateConstraint = ClientExtensionState<object, object, ExtensionCacheState | undefined, ExtensionResultConsumerState | undefined, object, string, unknown>;
4789
- /** Whether the current type-state includes the official cache capability. */
4790
- type HasExtensionCache<X$1 extends ExtensionStateConstraint> = [X$1["cache"]] extends [ExtensionCacheState] ? true : false;
4825
+ //#region src/client/result-types.d.ts
4791
4826
  /**
4792
- * Add the official cache capability without carrying its runtime config. Its
4793
- * one control, `cache` on every write, joins the chain's controls as its
4794
- * definition declares it.
4827
+ * Maps VibORM scalar types to their DATABASE RESULT types.
4828
+ * This is what the ORM returns after querying the database.
4829
+ *
4830
+ * Key difference from validation schema output:
4831
+ * - datetime/date/time: returns Date (not ISO string)
4832
+ * - json: inferred from custom schema if present, otherwise unknown
4833
+ * - enum: inferred from schema values
4795
4834
  */
4796
- type EnableExtensionCache<X$1 extends ExtensionStateConstraint> = ClientExtensionState<X$1["client"], X$1["models"], ExtensionCacheState, X$1["resultConsumer"], X$1["controls"] & DefinitionControls<{
4797
- readonly controls: OfficialCacheControls;
4798
- }>, X$1["rows"], X$1["data"]>;
4799
- /** Whether an earlier extension was typed against result-bearing delegates. */
4800
- type HasResultConsumingExtension<X$1 extends ExtensionStateConstraint> = [X$1["resultConsumer"]] extends [undefined] ? false : [X$1["resultConsumer"]] extends [ExtensionResultConsumerState] ? true : false;
4801
- type MethodsForModel<X$1 extends ExtensionStateConstraint, ModelName$1 extends PropertyKey> = ModelName$1 extends keyof X$1["models"] ? X$1["models"][ModelName$1] : NoMethods;
4835
+ type ScalarResultTypeMap = {
4836
+ string: string;
4837
+ int: number;
4838
+ number: number;
4839
+ decimal: Decimal;
4840
+ boolean: boolean;
4841
+ datetime: Date;
4842
+ date: Date;
4843
+ time: string;
4844
+ bigint: bigint;
4845
+ json: unknown;
4846
+ blob: Uint8Array;
4847
+ vector: number[];
4848
+ point: GeoPoint;
4849
+ enum: string;
4850
+ };
4802
4851
  /**
4803
- * One model's delegate after the chain's methods and controls. On a chain
4804
- * that declares create `data`, its writes may leave out the fields the chain
4805
- * writes on a create.
4852
+ * Extract the ScalarState from a Scalar using infer to preserve literal types.
4806
4853
  */
4807
- type ExtensionModelDelegate<C$1 extends VibORMConfig, X$1 extends ExtensionStateConstraint, ModelName$1 extends keyof ClientSchema<C$1>> = ([X$1["data"]] extends [never] ? Client<C$1, ClientRowsContext<C$1, X$1["rows"]>, X$1["controls"]>[ModelName$1] : Omit<Client<C$1, ClientRowsContext<C$1, X$1["rows"]>, X$1["controls"]>[ModelName$1], StampedOperation> & StampedOperations<C$1, ClientRowsContext<C$1, X$1["rows"]>, X$1["controls"], X$1["data"], ModelName$1>) & MethodsForModel<X$1, ModelName$1>;
4854
+ type ExtractScalarState<F$1> = F$1 extends {
4855
+ "~": {
4856
+ state: infer S;
4857
+ };
4858
+ } ? S extends ScalarState ? S : never : never;
4808
4859
  /**
4809
- * Model delegates after the methods contributed by the current chain. The
4810
- * always-true test is deliberate: for a client generic over its config it
4811
- * stays deferred, so the model map adds no index signature to that client and
4812
- * its `$` members stay reachable inside a body generic over `C`.
4860
+ * Get the base scalar type for a field, handling custom schemas.
4861
+ * For json/enum scalars with custom schemas, infer from the schema.
4862
+ * For datetime fields, always return Date (regardless of validation schema output).
4863
+ *
4864
+ * The enum arm reads the scalar's own `base` schema, so an enum's literal union
4865
+ * survives a relation read exactly as it does a direct one: this helper is
4866
+ * reached through the same `InferScalarOutput` on both paths.
4813
4867
  */
4814
- type ExtensionModelClient<C$1 extends VibORMConfig, X$1 extends ExtensionStateConstraint> = [keyof C$1["schema"]] extends [PropertyKey] ? { [ModelName in keyof ClientSchema<C$1>]: ExtensionModelDelegate<C$1, X$1, ModelName> } : unknown;
4815
- /** The surface given to one client-method factory. */
4816
- type ExtensionClientScope<C$1 extends VibORMConfig, X$1 extends ExtensionStateConstraint> = ExtensionModelClient<C$1, X$1> & RawSurface & X$1["client"] & {
4817
- readonly $schema: ClientSchema<C$1>;
4818
- readonly $transaction: TransactionClient<C$1, X$1>["$transaction"];
4819
- /**
4820
- * The client this scope's methods are called on, its calls admitting
4821
- * these values of this extension's own controls as if passed (a
4822
- * `bound: true` control only from here). Its type is that client's,
4823
- * which only the method knows: declare it with a `this` parameter,
4824
- * `$with<Self>(this: Self, value: Value): Self`, outside the returned
4825
- * literal (inside it, the factory's contextual type makes `Self` void).
4826
- */
4827
- readonly $bind: (values: Readonly<Record<string, unknown>>) => unknown;
4828
- };
4829
- type NonFunctionKeys<Methods$1 extends object> = { [Key in keyof Methods$1]: Methods$1[Key] extends CallableFunction ? never : Key }[keyof Methods$1];
4830
- type InvalidClientMethodKeys<Methods$1 extends object, C$1 extends VibORMConfig, X$1 extends ExtensionStateConstraint> = Exclude<keyof Methods$1, `$${string}`> | Extract<keyof Methods$1, keyof RawSurface | "$driver" | "$schema" | "$transaction" | "$connect" | "$disconnect" | "$withCache" | "$invalidate" | "$extends" | keyof X$1["client"]> | (string extends keyof C$1["schema"] ? never : Extract<keyof Methods$1, keyof C$1["schema"]>) | NonFunctionKeys<Methods$1>;
4831
- type GuardMethodFactory<Factory$1, Forbidden extends PropertyKey> = Factory$1 extends ((...args: infer Params) => infer Methods) ? Methods extends object ? (...args: Params) => Methods & Record<Forbidden, never> : (...args: Params) => never : never;
4832
- type ClientFactoryGuard<Definition$1, C$1 extends VibORMConfig, X$1 extends ExtensionStateConstraint> = Definition$1 extends {
4833
- readonly client: infer Factory;
4834
- } ? Factory extends ((...args: never[]) => infer Methods) ? Methods extends object ? {
4835
- readonly client: GuardMethodFactory<Factory, InvalidClientMethodKeys<Methods, C$1, X$1>>;
4836
- } : {
4837
- readonly client: never;
4838
- } : {
4839
- readonly client: never;
4840
- } : unknown;
4868
+ type GetScalarResultType<F$1 extends Scalar> = ExtractScalarState<F$1> extends infer S ? S extends ScalarState ? S["type"] extends "json" ? S["schema"] extends StandardSchemaV1<any, infer O> ? O : unknown : S["type"] extends "enum" ? EnumValues<S["base"]>[number] : ScalarResultTypeMap[S["type"]] : unknown : unknown;
4841
4869
  /**
4842
- * What every model factory may not return: a core operation or `then`. That
4843
- * each returned member is a function is the definition's own factory type
4844
- * (`ModelMethodFactory` returns an `ExtensionMethodRecord`), not this guard;
4845
- * `object` only keeps the all-optional key list from being a weak type, which
4846
- * would refuse every return that names none of those keys. Stated as a target
4847
- * shape, not a conditional over the factory, so a factory map generic over the
4848
- * client is checked rather than deferred. A method a prior extension put on
4849
- * the model cannot be named here for a client generic over its extension
4850
- * state: the runtime refuses that replacement when the extension is applied.
4870
+ * Apply nullable wrapper based on scalar state.
4871
+ * Uses non-distributive check to handle boolean literals correctly.
4851
4872
  */
4852
- type ModelFactoryGuard = (...args: never[]) => object & { readonly [Name in Operations | "then"]?: never };
4873
+ type ApplyNullable<T$1, Nullable> = [Nullable] extends [true] ? T$1 | null : T$1;
4853
4874
  /**
4854
- * Model keys outside the schema are refused by the definition's own `model`
4855
- * type (its per-schema factory table); this guard checks each factory's
4856
- * methods.
4875
+ * Apply array wrapper based on scalar state.
4876
+ * Uses non-distributive check to handle boolean literals correctly.
4857
4877
  */
4858
- type ModelFactoriesGuard<Definition$1> = Definition$1 extends {
4859
- readonly model: infer Factories;
4860
- } ? {
4861
- readonly model: { readonly [ModelName in keyof Factories]: ModelFactoryGuard };
4862
- } : unknown;
4863
- type ExtensionMethodDefinitionGuard<Definition$1, C$1 extends VibORMConfig, X$1 extends ExtensionStateConstraint> = ClientFactoryGuard<Definition$1, C$1, X$1> & ModelFactoriesGuard<Definition$1>;
4864
- type ClientMethodsOf<Definition$1> = Definition$1 extends {
4865
- readonly client: (...args: never[]) => infer Methods;
4866
- } ? Methods extends object ? Methods : NoMethods : NoMethods;
4867
- type ModelMethodsOf<Definition$1> = Definition$1 extends {
4868
- readonly model: infer Factories;
4869
- } ? Factories extends object ? { readonly [ModelName in keyof Factories]: Factories[ModelName] extends ((...args: never[]) => infer Methods) ? Methods extends object ? Methods : NoMethods : NoMethods } : NoMethods : NoMethods;
4870
- type MergeModelMethods<Left extends object, Right extends object> = { readonly [ModelName in keyof Left | keyof Right]: (ModelName extends keyof Left ? Left[ModelName] : NoMethods) & (ModelName extends keyof Right ? Right[ModelName] : NoMethods) };
4871
- type ResultConsumerContextOf<Definition$1> = Definition$1 extends {
4872
- readonly client: unknown;
4873
- } | {
4874
- readonly model: unknown;
4875
- } ? "result-consuming" : Definition$1 extends {
4876
- readonly query: infer Query;
4877
- } ? Query extends CallableFunction ? "result-independent" : "result-consuming" : "result-independent";
4878
- /** Incoming facts keep their nominal bit derivation inside this named state. */
4879
- interface ExtensionContributionState<ClientMethods extends object, ModelMethods extends object, Controls$1 extends object, RowModels extends string, Data$1, ConsumerContext extends string> extends ExtensionStateConstraint {
4880
- readonly client: ClientMethods;
4881
- readonly models: ModelMethods;
4882
- readonly cache: undefined;
4883
- readonly resultConsumer: ConsumerContext extends "result-consuming" ? ExtensionResultConsumerState : undefined;
4884
- readonly controls: Controls$1;
4885
- readonly rows: RowModels;
4886
- readonly data: Data$1;
4887
- }
4888
- /** Retain contribution facts, never the factory's contextual argument surface. */
4889
- type ExtensionStateContributionOf<Definition$1> = [Definition$1] extends [unknown] ? ExtensionContributionState<ClientMethodsOf<Definition$1>, ModelMethodsOf<Definition$1>, DefinitionControls<Definition$1>, RowsModels<Definition$1>, DefinitionData<Definition$1>, ResultConsumerContextOf<Definition$1>> : never;
4890
- /** Accumulate the same seven facts lazily, without retaining callback definitions. */
4891
- interface AccumulatedExtensionState<X$1 extends ExtensionStateConstraint, Contribution extends ExtensionStateConstraint> extends ExtensionStateConstraint {
4892
- readonly client: X$1["client"] & Contribution["client"];
4893
- readonly models: MergeModelMethods<X$1["models"], Contribution["models"]>;
4894
- readonly cache: X$1["cache"];
4895
- readonly resultConsumer: HasResultConsumingExtension<Contribution> extends true ? ExtensionResultConsumerState : X$1["resultConsumer"];
4896
- readonly controls: X$1["controls"] & Contribution["controls"];
4897
- readonly rows: X$1["rows"] | Contribution["rows"];
4898
- readonly data: X$1["data"] | Contribution["data"];
4899
- }
4900
- /** Public compatibility surface: the incoming argument remains a definition. */
4901
- type MergeExtensionState<X$1 extends ExtensionStateConstraint, Definition$1> = AccumulatedExtensionState<X$1, ExtensionStateContributionOf<Definition$1>>;
4902
- //#endregion
4903
- //#region src/extensions/request.d.ts
4878
+ type ApplyArray<T$1, IsArray> = [IsArray] extends [true] ? T$1[] : T$1;
4904
4879
  /**
4905
- * The single operation-specific owner of request properties that determine the
4906
- * public result type. A future projection spelling extends this table; runtime
4907
- * detachment and the handler input/patch types then change together.
4880
+ * Infer the DATABASE RESULT type for a scalar.
4881
+ *
4882
+ * This is the canonical helper for inferring output types from scalars.
4883
+ * It correctly handles:
4884
+ * - All scalar types with proper DB result mapping (datetime → Date)
4885
+ * - Custom schemas for json/enum scalars
4886
+ * - Nullable scalars
4887
+ * - Array scalars
4888
+ *
4889
+ * @example
4890
+ * // For s.dateTime().nullable() → Date | null
4891
+ * // For s.string().array() → string[]
4892
+ * // For s.json().schema(z.object({...})) → { ... }
4908
4893
  */
4909
- declare const RESULT_SHAPE_KEYS_BY_OPERATION: Readonly<{
4910
- findFirst: readonly ["select", "include", "omit"];
4911
- findMany: readonly ["select", "include", "omit"];
4912
- findUnique: readonly ["select", "include", "omit"];
4913
- findUniqueOrThrow: readonly ["select", "include", "omit"];
4914
- findFirstOrThrow: readonly ["select", "include", "omit"];
4915
- create: readonly ["select", "include", "omit"];
4916
- update: readonly ["select", "include", "omit"];
4917
- delete: readonly ["select", "include", "omit"];
4918
- upsert: readonly ["select", "include", "omit"];
4919
- createMany: readonly ["select", "omit"];
4920
- updateMany: readonly ["select", "omit"];
4921
- deleteMany: readonly ["select", "omit"];
4922
- count: readonly ["select"];
4923
- aggregate: readonly ["_count", "_avg", "_sum", "_min", "_max"];
4924
- groupBy: readonly ["by", "_count", "_avg", "_sum", "_min", "_max"];
4925
- exist: readonly [];
4926
- }>;
4927
- type ResultShapeKeyFor<Operation$2 extends Operations> = (typeof RESULT_SHAPE_KEYS_BY_OPERATION)[Operation$2][number];
4928
- /** The operation input visible to an ordinary request transform. */
4929
- type RequestTransformInput<Operation$2 extends Operations, Input$1 extends object> = Omit<Input$1, ResultShapeKeyFor<Operation$2>>;
4894
+ type InferScalarOutput<F$1 extends Scalar> = ExtractScalarState<F$1> extends infer S ? S extends ScalarState ? ApplyNullable<ApplyArray<GetScalarResultType<F$1>, S["array"]>, S["nullable"]> : never : never;
4930
4895
  /**
4931
- * A shallow patch over the non-projection input. The optional `never`
4932
- * properties make protected keys fail structurally, including held values.
4896
+ * Result for batch operations (createMany, updateMany, deleteMany)
4933
4897
  */
4934
- type RequestTransformPatch<Operation$2 extends Operations, Input$1 extends object> = Partial<RequestTransformInput<Operation$2, Input$1>> & { readonly [Key in ResultShapeKeyFor<Operation$2>]?: never };
4935
- interface GenericRequestContext {
4936
- readonly model: string;
4937
- readonly operation: Operations;
4938
- readonly input: Readonly<RequestTransformPatch<Operations, Record<string, unknown>>>;
4939
- /** The call's controls this handler's extension declares, and only those. */
4940
- readonly controls?: AdmittedControls;
4898
+ interface BatchPayload {
4899
+ count: number;
4941
4900
  }
4942
- type GenericRequestHandlerCall = (context: GenericRequestContext) => Readonly<RequestTransformPatch<Operations, Record<string, unknown>>>;
4943
- declare const officialRequestHandlerIdentity: unique symbol;
4944
- /** Public ordinary request handler; official identities cannot be erased into it. */
4945
- type GenericRequestHandler = GenericRequestHandlerCall & {
4946
- readonly [officialRequestHandlerIdentity]?: never;
4947
- };
4948
- /** Internal nominal call shape used by official request-based capabilities. */
4949
- type OfficialGenericRequestHandler = GenericRequestHandlerCall & {
4950
- readonly [officialRequestHandlerIdentity]: true;
4951
- };
4952
- type RequestOperationInput<S$1 extends Schema$1, ModelName$1 extends keyof S$1, OperationName$1 extends Operations> = Extract<Exclude<OperationPayload<OperationName$1, S$1[ModelName$1]>, undefined>, object>;
4953
- type RequestHandlerMap<S$1 extends Schema$1> = { readonly [ModelName in keyof S$1]?: { readonly [OperationName in Operations]?: (context: {
4954
- readonly model: ModelName;
4955
- readonly operation: OperationName;
4956
- readonly input: Readonly<RequestTransformInput<OperationName, RequestOperationInput<S$1, ModelName, OperationName>>>;
4957
- /** The call's controls this handler's extension declares, and only those. */
4958
- readonly controls?: AdmittedControls;
4959
- }) => RequestTransformPatch<OperationName, RequestOperationInput<S$1, ModelName, OperationName>> } };
4960
- //#endregion
4961
- //#region src/extensions/statement.d.ts
4962
- /** The trusted identity exposed to one low-level statement transform. */
4963
- interface StatementContext {
4964
- readonly statement: Sql;
4965
- readonly model: string | undefined;
4966
- readonly operation: Operations | keyof RawSurface;
4967
- }
4968
- type StatementHandler = (context: StatementContext) => Sql;
4969
- //#endregion
4970
- //#region src/extensions/definition.d.ts
4971
- type ExtensionConfig<S$1 extends Schema$1> = {
4972
- readonly schema: S$1;
4973
- readonly driver: AnyDriver;
4974
- };
4975
4901
  /**
4976
- * A model factory, declared as a method so a factory typed against the client
4977
- * it extends (`(delegate: M[K & keyof M]) => …`, generic over that client) is
4978
- * compared in either direction rather than only contravariantly.
4902
+ * Result type for count operations
4903
+ * Supports select for per-field counts like Prisma: count({ select: { _all: true, name: true } })
4979
4904
  */
4980
- type ModelMethodFactory<Delegate> = {
4981
- factory(delegate: Delegate): ExtensionMethodRecord;
4982
- }["factory"];
4905
+ /** Literal selections are required; runtime choices expose optional fields. */
4906
+ type SelectedFields<Selection$1, Fields$1> = { [K in keyof Selection$1 & keyof Fields$1 as Selection$1[K] extends true | object ? K : never]: Fields$1[K] } & { [K in keyof Selection$1 & keyof Fields$1 as Selection$1[K] extends true | object ? never : Extract<Selection$1[K], true | object> extends never ? never : K]?: Fields$1[K] };
4907
+ type SelectedCountResult<Selection$1> = Prettify<SelectedFields<Selection$1, { [K in keyof Selection$1]: number }>>;
4908
+ type CountResultType<Args, Selected = (Args extends {
4909
+ select: infer Selection;
4910
+ } ? SelectedCountResult<Selection> : never)> = Args extends {
4911
+ select: unknown;
4912
+ } ? keyof Selected extends never ? number : Selected : number;
4983
4913
  /**
4984
- * One factory per schema model. A definition's model key is looked up here by
4985
- * index, never by a conditional: a key outside the schema reads `never` (the
4986
- * factory is refused where it is written), and a key set generic over the
4987
- * client is substituted rather than deferred, so a plugin generic over `C`
4988
- * type-checks and meets the schema check when it is applied.
4914
+ * The non-recursive part of a model that result inference can compare safely.
4915
+ *
4916
+ * Full `Model` equality walks relation getters and collapses mutually-recursive
4917
+ * model consts. These two key sets identify the usual case without touching any
4918
+ * scalar implementation, external schema, or relation target. There are two,
4919
+ * not three, because a model now holds ONE relation map across both target
4920
+ * domains (§5.2).
4989
4921
  */
4990
- type ModelFactoryTable<C$1 extends VibORMConfig, X$1 extends ExtensionStateConstraint> = { readonly [ModelName in keyof ClientSchema<C$1>]: ModelMethodFactory<ExtensionModelDelegate<C$1, X$1, ModelName>> };
4991
- /** The model keys a definition's own `model` map names. */
4992
- type DefinitionModelKeys<Self> = Self extends {
4993
- readonly model?: infer Factories;
4994
- } ? keyof Factories : never;
4922
+ type ModelResultSurface<M$1 extends Model$1<any>> = M$1 extends Model$1<infer S> ? readonly [Extract<keyof S["scalars"], string>, Extract<keyof S["relations"], string>] : never;
4923
+ type SameKeySet<Left, Right> = [Exclude<Left, Right>] extends [never] ? [Exclude<Right, Left>] extends [never] ? true : false : false;
4924
+ type IsUsableModelResultSurface<Surface> = [Surface] extends [never] ? false : Surface extends readonly [infer Scalars, infer Relations] ? string extends Scalars ? false : string extends Relations ? false : true : false;
4925
+ /** Exact equality for the two shallow key sets above. */
4926
+ type SameModelResultSurface<Left, Right> = IsUsableModelResultSurface<Left> extends true ? IsUsableModelResultSurface<Right> extends true ? Left extends readonly [infer LS, infer LR] ? Right extends readonly [infer RS, infer RR] ? SameKeySet<LS, RS> extends true ? SameKeySet<LR, RR> : false : false : false : false : false;
4995
4927
  /**
4996
- * `Self` is the definition itself when `$extends` checks it (F-bounded), so
4997
- * its model keys come from the definition; otherwise every schema model.
4928
+ * The shallow surfaces of the models whose rows a client's `rows` can hide
4929
+ * from a relation read (`ClientRowsContext`, ./types.ts). It rides the same
4930
+ * result context as the omission defaults, as one more member of the union.
4998
4931
  */
4999
- type ContextualExtensionDefinition<C$1 extends VibORMConfig, X$1 extends ExtensionStateConstraint, Self = unknown> = ExtensionMembers<C$1, X$1> & {
5000
- readonly model?: unknown extends Self ? { readonly [ModelName in keyof ClientSchema<C$1>]?: ModelMethodFactory<ExtensionModelDelegate<C$1, X$1, ModelName>> } : { readonly [ModelName in DefinitionModelKeys<Self>]?: ModelFactoryTable<C$1, X$1>[ModelName & keyof ClientSchema<C$1>] };
5001
- };
5002
- type ExtensionMembers<C$1 extends VibORMConfig, X$1 extends ExtensionStateConstraint> = {
5003
- readonly name: string;
5004
- readonly request?: GenericRequestHandler | RequestHandlerMap<ClientSchema<C$1>>;
5005
- readonly query?: GenericQueryHandler | QueryHandlerMap<C$1, X$1["rows"]>;
5006
- readonly statement?: StatementHandler;
5007
- readonly observe?: ObserveHandler;
5008
- readonly controls?: ControlsContribution;
5009
- readonly rows?: RowsContribution;
5010
- readonly deletion?: DeletionContribution;
5011
- readonly data?: DataContribution;
5012
- readonly client?: (scope: ExtensionClientScope<C$1, X$1>) => ExtensionMethodRecord;
5013
- };
5014
- type SchemaGenericExtensionDefinition = Omit<ContextualExtensionDefinition<ExtensionConfig<Schema$1>, EmptyClientExtensionState>, "request" | "query"> & {
5015
- readonly request?: GenericRequestHandler;
5016
- readonly query?: GenericQueryHandler;
5017
- };
4932
+ interface ClientHiddenContext<Surfaces> {
4933
+ readonly hidden: Surfaces;
4934
+ }
5018
4935
  /**
5019
- * Public reusable extension definition.
4936
+ * `null` where a relation read can find this target hidden, and nothing
4937
+ * otherwise. Models are compared by their shallow surface, as the omission
4938
+ * defaults are: a target that shares its surface with a hidden model widens
4939
+ * with it, and a surface too wide to compare widens too, both on the `| null`
4940
+ * side. It distributes over the context, so a client without `rows` never
4941
+ * resolves a target, and TypeScript measures the context parameter of every
4942
+ * result type through it cheaply: the `[Hidden] extends [never]` form it
4943
+ * replaces cost the schema-only floor 33,535 types (measured, U7 repair).
4944
+ */
4945
+ type HiddenTargetNull<R$1 extends AnyRelation, Context> = Context extends ClientHiddenContext<infer Hidden> ? true extends HidesTarget<R$1, Hidden> ? null : never : never;
4946
+ type HidesTarget<R$1 extends AnyRelation, Hidden$1> = Hidden$1 extends unknown ? IsUsableModelResultSurface<Hidden$1> extends false ? true : MatchesSurface<TargetSurfaces<R$1>, Hidden$1> : never;
4947
+ type MatchesSurface<Surface, Hidden$1> = Surface extends unknown ? IsUsableModelResultSurface<Surface> extends false ? true : SameModelResultSurface<Surface, Hidden$1> : never;
4948
+ /** The shallow surface of each model a relation can target. */
4949
+ type TargetSurfaces<R$1 extends AnyRelation> = IsVariantTarget<R$1> extends true ? ModelResultSurface<GetPolymorphicTarget<R$1, PolymorphicPublicTypes<R$1>>> : ModelResultSurface<GetTargetModel<R$1>>;
4950
+ /** One configured model's compact, client-owned result default. */
4951
+ interface ClientResultOmitEntry<Surface, Omission, Unique> {
4952
+ readonly surface: Surface;
4953
+ readonly omission: Omission;
4954
+ readonly unique: Unique;
4955
+ }
4956
+ /** Named boundary so TypeScript can cache the carrier during result recursion. */
4957
+ interface ClientResultOmitContext<Entries$1> {
4958
+ readonly entries: Entries$1;
4959
+ }
4960
+ type EntrySurface<Entry> = Entry extends ClientResultOmitEntry<infer Surface, unknown, unknown> ? Surface : never;
4961
+ type MatchingClientOmitEntries<M$1 extends Model$1<any>, Context, Entries$1 = (Context extends ClientResultOmitContext<infer E> ? E : never)> = M$1 extends unknown ? Entries$1 extends unknown ? true extends SameModelResultSurface<ModelResultSurface<M$1>, EntrySurface<Entries$1>> ? Entries$1 : never : never : never;
4962
+ type IsUnion<T$1, Whole = T$1> = T$1 extends Whole ? [Whole] extends [T$1] ? false : true : never;
4963
+ type HasMultipleModelResultSurfaces<M$1 extends Model$1<any>, WholeSurface = ModelResultSurface<M$1>> = M$1 extends unknown ? SameModelResultSurface<ModelResultSurface<M$1>, WholeSurface> extends true ? false : true : never;
4964
+ type EntryOmission<Entry> = Entry extends ClientResultOmitEntry<unknown, infer Omission, unknown> ? Omission : never;
4965
+ type EntryUnique<Entry> = Entry extends ClientResultOmitEntry<unknown, unknown, infer Unique> ? Unique : never;
4966
+ type PossibleOmitKeys<Entry> = Entry extends unknown ? keyof Exclude<EntryOmission<Entry>, undefined> : never;
4967
+ type SoftenedResolvedOmit<Keys$1 extends PropertyKey> = [Keys$1] extends [never] ? undefined : { [K in Keys$1]: boolean };
4968
+ /**
4969
+ * Resolve a nested target's client default without comparing model graphs.
5020
4970
  *
5021
- * A schema with a string index has no exact model vocabulary, so its reusable
5022
- * request/query contributions must use the polymorphic all-operation form.
5023
- * Supplying a concrete schema retains its exact model and operation maps.
4971
+ * A unique shallow surface identifies the configured model exactly. When two
4972
+ * schema models have the same surface, the current public types contain no
4973
+ * nominal identity that can distinguish their runtime objects. In that case,
4974
+ * every possibly omitted field becomes a widened boolean; `ApplyOmit` renders
4975
+ * it optional, which is honest in both runtime worlds.
5024
4976
  */
5025
- type ClientExtension<S$1 extends Schema$1 = Schema$1> = string extends keyof S$1 ? SchemaGenericExtensionDefinition : ContextualExtensionDefinition<ExtensionConfig<S$1>, EmptyClientExtensionState>;
5026
- type DefinitionKeys = keyof ContextualExtensionDefinition<VibORMConfig, EmptyClientExtensionState>;
5027
- declare const schemaBoundExtensionContext: unique symbol;
5028
- type SchemaBoundExtension<Definition$1> = Definition$1 & {
5029
- readonly [schemaBoundExtensionContext]: ResultConsumerContextOf<Definition$1>;
5030
- };
5031
- type UnknownDefinitionKeys<Definition$1> = Record<Exclude<keyof Definition$1, DefinitionKeys | typeof schemaBoundExtensionContext>, never>;
5032
- type ConfigOmit$2<C$1 extends VibORMConfig> = "omit" extends keyof C$1 ? C$1[Extract<"omit", keyof C$1>] : undefined;
5033
- type HasNamedClientOmit<C$1 extends VibORMConfig> = string extends keyof NonNullable<ConfigOmit$2<C$1>> ? false : [Exclude<ConfigOmit$2<C$1>, undefined>] extends [never] ? false : true;
5034
- /** Refuse replaying a schema-bound result consumer into an omitted client. */
5035
- type SchemaBoundExtensionAdmission<Definition$1, C$1 extends VibORMConfig> = Definition$1 extends {
5036
- readonly [schemaBoundExtensionContext]: infer Context;
5037
- } ? Context extends "result-consuming" ? HasNamedClientOmit<C$1> extends true ? {
5038
- readonly [schemaBoundExtensionContext]: never;
5039
- } : unknown : unknown : unknown;
5040
- type OperationMapGuard<Map$1, S$1 extends Schema$1> = Map$1 extends CallableFunction ? unknown : Map$1 extends object ? Record<Exclude<keyof Map$1, keyof S$1>, never> & { readonly [ModelName in keyof Map$1]: ModelName extends keyof S$1 ? Map$1[ModelName] extends object ? Record<Exclude<keyof Map$1[ModelName], Operations>, never> : never : never } : never;
5041
- type ComponentMapGuard<Definition$1, Key$1 extends "request" | "query", S$1 extends Schema$1> = Definition$1 extends { readonly [K in Key$1]: infer Component } ? { readonly [K in Key$1]: OperationMapGuard<Component, S$1> } : unknown;
5042
- /** Policy model keys must be a subset of a concrete bound schema. */
5043
- type PolicyModelsGuard<Definition$1, S$1 extends Schema$1, Key$1 extends "data" | "rows" | "deletion"> = Definition$1 extends { readonly [K in Key$1]: {
5044
- readonly models: infer Models;
5045
- } } ? string extends keyof S$1 ? unknown : [keyof Models] extends [keyof S$1] ? unknown : { readonly [K in Key$1]: {
5046
- readonly models: Record<keyof Models, never>;
5047
- } } : unknown;
5048
- /** Structural refusal for non-fresh extension definitions and contributions. */
5049
- type ExactExtensionDefinition<Definition$1, C$1 extends VibORMConfig, X$1 extends ExtensionStateConstraint> = UnknownDefinitionKeys<Definition$1> & ComponentMapGuard<Definition$1, "request", C$1["schema"]> & ComponentMapGuard<Definition$1, "query", C$1["schema"]> & PolicyModelsGuard<Definition$1, C$1["schema"], "data"> & PolicyModelsGuard<Definition$1, C$1["schema"], "rows"> & PolicyModelsGuard<Definition$1, C$1["schema"], "deletion"> & ExtensionMethodDefinitionGuard<Definition$1, C$1, X$1>;
5050
- type DefineExtensionBinder<S$1 extends Schema$1> = <const Definition$1>(definition: Definition$1 & ContextualExtensionDefinition<ExtensionConfig<S$1>, EmptyClientExtensionState> & ExactExtensionDefinition<Definition$1, ExtensionConfig<S$1>, EmptyClientExtensionState>) => SchemaBoundExtension<NoInfer<Definition$1>>;
5051
- declare function defineExtension<const Definition$1 extends SchemaGenericExtensionDefinition>(definition: Definition$1 & ExactExtensionDefinition<Definition$1, ExtensionConfig<Schema$1>, EmptyClientExtensionState>): NoInfer<Definition$1>;
5052
- declare function defineExtension<S$1 extends Schema$1>(): DefineExtensionBinder<S$1>;
5053
- //#endregion
5054
- //#region src/extensions/controls.d.ts
5055
- /** The operations a declared control is accepted on. */
5056
- type ControlPlacement = "reads" | "writes" | "all" | readonly Operations[];
4977
+ type ResolveClientOmit<M$1 extends Model$1<any>, Context, Matches = MatchingClientOmitEntries<M$1, Context>, AmbiguousKeys extends PropertyKey = PossibleOmitKeys<Matches>> = [Context] extends [never] ? undefined : [Matches] extends [never] ? undefined : true extends HasMultipleModelResultSurfaces<M$1> ? SoftenedResolvedOmit<AmbiguousKeys> : true extends IsUnion<EntryOmission<Matches>> ? SoftenedResolvedOmit<AmbiguousKeys> : false extends EntryUnique<Matches> ? SoftenedResolvedOmit<AmbiguousKeys> : EntryOmission<Matches>;
4978
+ /** Get the target model itself without resolving its recursive state. */
4979
+ type GetTargetModel<R$1 extends AnyRelation> = TargetGetter<R$1> extends (() => infer Target) ? Target extends Model$1<any> ? Target : never : never;
5057
4980
  /**
5058
- * One argument an extension declares. Its values are a closed list or a
5059
- * Standard Schema; `on` names the operations that accept it (every operation
5060
- * when absent). With `required`, a call on one of those operations that does
5061
- * not pass it is refused, on the models the extension names in `rows`,
5062
- * `data` or `deletion` only; an extension that names no model asks for it on
5063
- * every model. With `bound`, it is accepted only from a binding (the client
5064
- * scope's `$bind`), never from a call's arguments: its placement reads no
5065
- * argument, so a call that passes it is refused as passing an unknown key.
5066
- * With `uncacheable`, a read that holds a value of it is never served from
5067
- * the cache: `$withCache` on that read is refused before any statement. A
5068
- * value held in a variable keeps its literal type only with `as const`, as a
5069
- * held enum clause does.
4981
+ * Get the target model's state from a relation
5070
4982
  */
5071
- type ControlDeclaration = ({
5072
- readonly oneOf: readonly (string | number | boolean)[];
5073
- } | {
5074
- readonly schema: StandardSchemaV1;
5075
- }) & {
5076
- readonly on?: ControlPlacement;
5077
- readonly required?: boolean;
5078
- readonly bound?: boolean;
5079
- readonly uncacheable?: boolean;
5080
- };
5081
- type ControlsContribution = {
5082
- readonly [name: string]: ControlDeclaration;
5083
- };
5084
- /** Constant scalar `where` or `data` fields of one model. */
5085
- type ScalarFields = {
5086
- readonly [field: string]: unknown;
5087
- };
4983
+ type GetTargetModelState<R$1 extends AnyRelation> = GetTargetModel<R$1> extends infer T ? T extends Model$1<infer S> ? S extends ModelState ? S : never : never : never;
5088
4984
  /**
5089
- * Which rows an operation sees. `control` names the call argument that picks
5090
- * a mode; every model entry declares the same mode names, `default` among
5091
- * them. `root` filters the call's own candidates, `related` rows reached
5092
- * through a relation; each is a model's `where`, admitted once when the
5093
- * extension is applied, or the name of one of its `verbs` predicates. Where a
5094
- * filter takes a value, `{ control: "<name>", path?: "a.b" }` takes the value
5095
- * the call passed for that control (or a field of it), `{ now: true }` the
5096
- * call's instant, and `{ $if: … }` tests a call value. An absent value
5097
- * (`null` included) matches nothing where its control is required, and drops
5098
- * its filter where it is not.
5099
- *
5100
- * `verbs` judges, per model, what a call may do to the rows it sees: a mode
5101
- * only narrows them (R8). A model's entry may be a function returning it:
5102
- * it is called when a call of the chain first needs that model, and its
5103
- * entry admitted then, so a refusal of it fails that call instead of
5104
- * `$extends`. A function returning deeply frozen plain data is called once
5105
- * per schema; one returning anything else, once per client.
4985
+ * Infer the output type for a model, respecting omit settings.
4986
+ * Uses InferScalarOutput for correct DB result types (e.g., Date for datetime).
5106
4987
  */
5107
- type RowsContribution = {
5108
- readonly control: string;
5109
- readonly default: string;
5110
- readonly models: {
5111
- readonly [model: string]: {
5112
- readonly [mode: string]: {
5113
- readonly root?: ScalarFields | string;
5114
- readonly related?: ScalarFields | string;
5115
- };
5116
- };
5117
- };
5118
- readonly verbs?: {
5119
- readonly [model: string]: RowsVerbs | (() => RowsVerbs);
5120
- };
5121
- };
4988
+ type InferModelOutput<S$1 extends ModelState> = S$1["omit"] extends Record<string, true> ? Omit<{ [K in keyof S$1["scalars"]]: S$1["scalars"][K] extends Scalar ? InferScalarOutput<S$1["scalars"][K]> : never }, keyof S$1["omit"]> : { [K in keyof S$1["scalars"]]: S$1["scalars"][K] extends Scalar ? InferScalarOutput<S$1["scalars"][K]> : never };
5122
4989
  /**
5123
- * One model's named predicates, each a `where` admitted once, and the verbs
5124
- * that take them. `read` ANDs with every mode's `root` and `related`; a write
5125
- * takes its verb's beside them: a delete `delete`'s, an update, for each
5126
- * field its data writes, that field's `writes` entry, else `update`'s, and
5127
- * `update`'s when its data writes only stamps. A join row's change is a write
5128
- * of the relation on both rows it links; a row only addressed to reach its
5129
- * children is read. A verb left out matches nothing.
4990
+ * `omit` at the TYPE level.
5130
4991
  *
5131
- * The row a write produces is judged too, as a value, against the rows as
5132
- * they stand before the write, inside the statement that writes it (R4): a
5133
- * created row at `place` (a model naming none is not judged on create); an
5134
- * updated row at the predicates that judged its old row, and, for each field
5135
- * its data writes, at that field's `moves` entry, and where it writes the
5136
- * key of an `acyclic` relation (a to-one relation of the model to itself),
5137
- * outside its own subtree. `acyclic` may be a function returning that list:
5138
- * it is called the first time an update writes the key of one of the
5139
- * model's self relations. A refused row is written by no statement.
4992
+ * Three cases, mirroring what the runtime can and cannot know:
4993
+ * - `true` — the key is gone;
4994
+ * - `false` (or absent) — the key stays;
4995
+ * - a widened `boolean` (a variable, a spread, `cond ? true : false`) — only
4996
+ * the runtime decides, so the key becomes OPTIONAL rather than being guessed
4997
+ * into one arm. Claiming it is present would be a lie exactly when the flag
4998
+ * is `true`, which is the case a caller writes this for.
5140
4999
  *
5141
- * `evidence` declares a projection key (`evidence.as`) a `select` or
5142
- * `include` may name at every depth, on reads and on the rows a write
5143
- * returns: per row, whether each of `names` holds there beside `read`, or,
5144
- * `ordered`, the last of them that holds (`null` on a row `read` does not
5145
- * hold). `reads` gates a field on a predicate: the row carries it only where
5146
- * `read` and that predicate hold, a `select` naming it fails on a row
5147
- * without them, and every operand a call writes over it (`where`, `orderBy`,
5148
- * aggregates, `distinct`, unique lookups, relation filters) reads it as
5149
- * absent there. A key or foreign-key field is never gated.
5000
+ * Model-level `.omit()` never appears here: those fields are absent from
5001
+ * `InferModelOutput` already, and the `omit` schema has no key to name them
5002
+ * with (see `src/validation/model/core/projection.ts`).
5150
5003
  */
5151
- type RowsVerbs = {
5152
- readonly predicates: {
5153
- readonly [name: string]: ScalarFields;
5154
- };
5155
- readonly read?: string;
5156
- readonly update?: string;
5157
- readonly delete?: string;
5158
- readonly writes?: {
5159
- readonly [field: string]: string;
5160
- };
5161
- readonly place?: string;
5162
- readonly moves?: {
5163
- readonly [field: string]: string;
5164
- };
5165
- readonly acyclic?: readonly string[] | (() => readonly string[]);
5166
- readonly evidence?: {
5167
- readonly as: string;
5168
- readonly names: readonly string[];
5169
- readonly ordered?: boolean;
5170
- };
5171
- readonly reads?: {
5172
- readonly [field: string]: string;
5173
- };
5174
- };
5004
+ type DefinitelyOmittedKeys<O$1> = { [K in keyof O$1]: [O$1[K]] extends [true] ? K : never }[keyof O$1];
5005
+ type MaybeOmittedKeys<O$1> = { [K in keyof O$1]: [O$1[K]] extends [true] ? never : [O$1[K]] extends [false] ? never : boolean extends O$1[K] ? K : never }[keyof O$1];
5006
+ type ReduceOmit<T$1, O$1> = Omit<T$1, Extract<DefinitelyOmittedKeys<O$1> | MaybeOmittedKeys<O$1>, keyof T$1>> & Partial<Pick<T$1, Extract<MaybeOmittedKeys<O$1>, keyof T$1>>>;
5175
5007
  /**
5176
- * What a delete does on the models named here: an update that stamps `at`
5177
- * with the call's time and writes `assign`, unless the call's controls match
5178
- * `removeWhen`.
5008
+ * An `omit` that MAY be absent decides nothing on its own, so every key it
5009
+ * names softens to a widened `boolean` — which {@link ReduceOmit} renders as an
5010
+ * OPTIONAL key, the same convention a widened flag already follows. It is the
5011
+ * spread idiom's other half: `{ ...(cond && { omit: { title: true } }) }` types
5012
+ * `omit` as optional, and promising `title` outright would be a lie exactly
5013
+ * when `cond` holds.
5179
5014
  */
5180
- type DeletionContribution = {
5181
- readonly removeWhen?: {
5182
- readonly [control: string]: string | number | boolean;
5183
- };
5184
- readonly models: {
5185
- readonly [model: string]: {
5186
- readonly at?: string;
5187
- readonly assign?: ScalarFields;
5188
- };
5189
- };
5190
- };
5015
+ type SoftenNodeOmit<O$1> = { [F in keyof O$1]: boolean };
5016
+ type ApplyOmit<T$1, O$1> = [O$1] extends [undefined] ? T$1 : undefined extends O$1 ? ReduceOmit<T$1, SoftenNodeOmit<Exclude<O$1, undefined>>> : ReduceOmit<T$1, O$1>;
5191
5017
  /**
5192
- * Fields an extension writes on the models named here: `create` on every
5193
- * create of the model, `update` on every update of it, a soft delete's
5194
- * included. A value is a constant, `{ control: "<name>", path?: "a.b" }` for
5195
- * the value the call passed for that control or a field of it (a call that
5196
- * passed none writes nothing there), `{ now: true }` for the call's instant,
5197
- * or, on `update`, one of the field's update operators (`{ increment: 1 }`). A field is written only where the caller left it
5198
- * out: a call that writes it itself, or writes the relation whose foreign key
5199
- * holds it, keeps its own value there. A create may leave out such a field
5200
- * even where the schema requires it: the call's data is checked with it
5201
- * counted as given. When the model names here are known to the types
5202
- * (written out, or kept by a `const` type parameter, not a plain
5203
- * `string[]`), the extended client's types agree, nested creates included:
5204
- * the field is optional on a create. When two extensions name a field, the
5205
- * later one writes it, and a value the caller writes wins over both.
5018
+ * Layer a query-local omission over a configured client default, per field.
5019
+ * A local `false` restores one configured field; an optional local omission
5020
+ * softens only the fields whose runtime value remains undecided.
5206
5021
  */
5207
- type DataContribution = {
5208
- readonly models: {
5209
- readonly [model: string]: {
5210
- readonly create?: ScalarFields;
5211
- readonly update?: ScalarFields;
5212
- };
5213
- };
5214
- };
5215
- /** Operations that select candidates: where a rows control is accepted. */
5216
- type CandidateOperations = Exclude<Operations, "create" | "createMany">;
5217
- /** One declared control as the delegates see it. */
5218
- interface PlacedControl<Value = unknown, Models$1 = PropertyKey, Placed = Operations> {
5219
- readonly value: Value;
5220
- readonly models: Models$1;
5221
- readonly operations: Placed;
5222
- }
5223
- type NoControls = Record<never, never>;
5224
- type ControlValue<Declaration> = Declaration extends {
5225
- readonly oneOf: readonly (infer Value)[];
5226
- } ? Value : Declaration extends {
5227
- readonly schema: StandardSchemaV1<infer Input>;
5228
- } ? Input : never;
5229
- type PlacementOperations<On> = On extends "reads" ? CacheableOperations : On extends "writes" ? MutationOperations : On extends readonly (infer Operation)[] ? Operation : Operations;
5022
+ type MergeClientOmit<Default, Local> = [Default] extends [undefined] ? Local : [Local] extends [undefined] ? Default : undefined extends Local ? Prettify<Omit<Default, keyof Exclude<Local, undefined>> & { [F in keyof Exclude<Local, undefined>]: boolean }> : Prettify<Omit<Default, keyof Local> & Local>;
5230
5023
  /**
5231
- * `deletion` places the control `removeWhen` names: on the deletes of the
5232
- * models it manages, whatever the declaration's `on` says.
5024
+ * The value a node STATES under one projection key, or `undefined` when it
5025
+ * states none.
5026
+ *
5027
+ * INDEXED ACCESS, not `Node extends { omit: infer O }`: a conditional matches a
5028
+ * REQUIRED property, so it reads an OPTIONAL one — the exact shape TypeScript
5029
+ * gives the spread idiom, `{ ...(cond && { select: sel }) }` -> `{ select?: Sel }`
5030
+ * — as "no such key", and the key would silently decide nothing. Indexed access
5031
+ * reports it as `Sel | undefined`, which is the truth: only the runtime knows.
5032
+ *
5033
+ * An object with a string INDEX SIGNATURE states nothing, for the same reason
5034
+ * `NoExtraClauseKeys` (./types.ts) refuses to police one: it declares no spelled
5035
+ * key, and reading `Record<string, unknown>["select"]` as a projection would
5036
+ * turn every dynamically-built payload into the ambiguous arm.
5233
5037
  */
5234
- type PlaceControl<Name$1, Declaration, Deletion> = Deletion extends {
5235
- readonly removeWhen: infer RemoveWhen;
5236
- readonly models: infer Managed;
5237
- } ? Name$1 extends keyof RemoveWhen ? PlacedControl<ControlValue<Declaration>, keyof Managed, "delete" | "deleteMany"> : PlaceFreeControl<Declaration> : PlaceFreeControl<Declaration>;
5238
- type PlaceFreeControl<Declaration> = PlacedControl<ControlValue<Declaration>, PropertyKey, PlacementOperations<Declaration extends {
5239
- readonly on: infer On;
5240
- } ? On : "all">>;
5241
- type DeclaredControls<Definition$1> = Definition$1 extends {
5242
- readonly controls: infer Controls extends ControlsContribution;
5243
- } ? { readonly [Name in keyof Controls as Controls[Name] extends {
5244
- readonly bound: true;
5245
- } ? never : Name]: PlaceControl<Name, Controls[Name], Definition$1 extends {
5246
- readonly deletion: infer Deletion;
5247
- } ? Deletion : unknown> } : NoControls;
5248
- /** Every model entry declares the same mode names: those are the values. */
5249
- type RowsModes<Rows$1 extends RowsContribution> = Rows$1["default"] | { [Model in keyof Rows$1["models"]]: keyof Rows$1["models"][Model] }[keyof Rows$1["models"]];
5250
- /** The rows control: every candidate-selecting operation of every model. */
5251
- type RowsControl<Definition$1> = Definition$1 extends {
5252
- readonly rows: infer Rows extends RowsContribution;
5253
- } ? { readonly [Name in Rows["control"]]: PlacedControl<RowsModes<Rows>, PropertyKey, CandidateOperations> } : NoControls;
5038
+ type NodeKey<Node, Key$1 extends string> = string extends keyof Node ? undefined : Key$1 extends keyof Node ? Node[Extract<Key$1, keyof Node>] : undefined;
5254
5039
  /**
5255
- * The models one definition's `rows` can hide from a relation read: its
5256
- * `models` and `verbs` keys. A to-one relation that targets one of them reads `null` when
5257
- * its target is hidden, so the result types widen it (`result-types.ts`).
5040
+ * Exported so the client layer can keep this query-local value distinct from
5041
+ * its configured default: selected worlds apply only this value, while
5042
+ * unselected worlds merge both before reducing the result.
5258
5043
  */
5259
- type RowsModels<Definition$1> = Definition$1 extends {
5260
- readonly rows: infer Rows extends RowsContribution;
5261
- } ? Extract<keyof Rows["models"] | (Rows extends {
5262
- readonly verbs: infer Verbs;
5263
- } ? keyof Verbs : never), string> : never;
5264
- /** The controls one definition places, keyed by control name. */
5265
- type DefinitionControls<Definition$1> = DeclaredControls<Definition$1> & RowsControl<Definition$1>;
5266
- /** The optional control arguments one (model, operation) accepts. */
5267
- type OperationControls<Controls$1, ModelName$1, Operation$2> = { readonly [Name in keyof Controls$1 as Controls$1[Name] extends PlacedControl<unknown, infer Models, infer Placed> ? ModelName$1 extends Models ? Operation$2 extends Placed ? Name : never : never : never]?: Controls$1[Name] extends PlacedControl<infer Value> ? Value : never };
5044
+ type NodeOmit<Node> = NodeKey<Node, "omit">;
5268
5045
  /**
5269
- * The fields one `data` entry writes on its models' creates: there they may
5270
- * be left out even where the schema requires them. An update's fields need
5271
- * nothing, as every field of an update is optional already.
5046
+ * The parse boundary treats an explicitly-`undefined` key as an ABSENT key
5047
+ * (`src/validation/primitives/object.ts`), which is what makes the
5048
+ * spread-an-optional idiom work; so `{ select: undefined }` and `{}` are the
5049
+ * same payload, and this helper reports them the same way.
5272
5050
  */
5273
- interface StampedFields<Models$1 = PropertyKey, Fields$1 = PropertyKey> {
5274
- readonly models: Models$1;
5275
- readonly fields: Fields$1;
5276
- }
5277
- type CreateStamps<Model$2, Entry> = "create" extends keyof Entry ? Entry extends {
5278
- readonly create?: infer Fields;
5279
- } ? StampedFields<Model$2, keyof NonNullable<Fields>> : never : never;
5051
+ type NodeSelect<Node> = NodeKey<Node, "select">;
5052
+ type NodeInclude<Node> = NodeKey<Node, "include">;
5053
+ /** The public recurrence request stated by one admitted relation node. */
5054
+ type NodeRecurse<Node> = NodeKey<Node, "recurse">;
5055
+ /** The two keys of a polymorphic COLLECTION projection envelope. */
5056
+ type NodeOnly<Projection> = NodeKey<Projection, "only">;
5057
+ type NodeVariants<Projection> = NodeKey<Projection, "variants">;
5280
5058
  /**
5281
- * What one definition's `data` writes on creates: one member per model. A
5282
- * definition whose model names are lost (`{ [model: string]: ... }`, as a
5283
- * recipe called with a plain `string[]` builds) writes nothing the types can
5284
- * name: its required fields stay required in the payloads.
5059
+ * The model that OWNS one asking slot, reconstructed from the state result
5060
+ * inference already carries.
5061
+ *
5062
+ * `Model<State>` is the identity `s.model(...)` returns for that exact state,
5063
+ * which is what the static membership projection compares getters against. It
5064
+ * is not a second model concept: it is the same type, spelled from the half of
5065
+ * it these mapped types thread.
5285
5066
  */
5286
- type DefinitionData<Definition$1> = Definition$1 extends {
5287
- readonly data: {
5288
- readonly models: infer Models;
5289
- };
5290
- } ? string extends keyof Models ? never : { [Model in keyof Models]: CreateStamps<Model, Models[Model]> }[keyof Models] : never;
5291
- /** The fields a chain writes on every create of one model. */
5292
- type StampedFieldNames<Data$1, ModelName$1> = Data$1 extends StampedFields<infer Models, infer Fields extends PropertyKey> ? ModelName$1 extends Models ? Fields : never : never;
5067
+ type SourceModelOf<S$1 extends ModelState> = Model$1<S$1>;
5068
+ /** Does this relation name variants rather than one model? */
5069
+ type IsVariantTarget<R$1 extends AnyRelation> = TargetKind<R$1> extends "variants" ? true : false;
5070
+ /** The configured target model at one public discriminator. */
5071
+ type GetPolymorphicTarget<R$1 extends AnyRelation, PublicType$1 extends PropertyKey> = PublicType$1 extends keyof VariantEntries<R$1> ? VariantEntries<R$1>[PublicType$1] extends {
5072
+ readonly getter: infer Getter;
5073
+ } ? Getter extends (() => infer Target) ? Target extends Model$1<any> ? Target : never : never : never : never;
5074
+ type PolymorphicPublicTypes<R$1 extends AnyRelation> = Extract<keyof VariantEntries<R$1>, string>;
5293
5075
  /**
5294
- * The controls one call admitted, by name. A `rows` control is resolved to its
5295
- * mode, so an absent one reads as its default; an absent plain control is not
5296
- * here.
5076
+ * Result for a relation when included
5077
+ * - To-many relations return arrays
5078
+ * - To-one relations return single objects (nullable if optional)
5297
5079
  */
5298
- type AdmittedControls = Readonly<Record<string, unknown>>;
5299
- //#endregion
5300
- //#region src/extensions/query.d.ts
5301
- type QueryInterceptionMode = "direct" | "transaction" | "array";
5302
- type RawQueryKind = "queryRaw" | "executeRaw" | "queryRawUnsafe" | "executeRawUnsafe";
5303
- type WriteOutcome = Readonly<{
5304
- certainty: "committed" | "may-have-committed";
5305
- }>;
5306
- type WriteOutcomeListener = (outcome: WriteOutcome) => unknown | Promise<unknown>;
5307
- type GenericQueryContextBase<Result> = {
5308
- readonly mode: QueryInterceptionMode;
5309
- readonly input: Readonly<Record<string, unknown>>;
5310
- readonly proceed: () => Promise<Result>;
5311
- readonly onWriteOutcome: (listener: WriteOutcomeListener) => void;
5312
- };
5313
- type GenericModelQueryContext<Result> = GenericQueryContextBase<Result> & {
5314
- readonly kind: "model";
5315
- readonly model: string;
5316
- readonly operation: Operations;
5317
- /** The call's controls this handler's extension declares, and only those. */
5318
- readonly controls?: AdmittedControls;
5319
- };
5320
- type GenericRawQueryContext<Result> = GenericQueryContextBase<Result> & { [Kind in RawQueryKind]: {
5321
- readonly kind: Kind;
5322
- readonly model: undefined;
5323
- readonly operation: `$${Kind}`;
5324
- } }[RawQueryKind];
5325
- type GenericQueryContext<Result> = GenericModelQueryContext<Result> | GenericRawQueryContext<Result>;
5326
- type GenericQueryHandlerCall = <Result>(context: GenericQueryContext<Result>) => Promise<Result>;
5327
- declare const officialQueryHandlerIdentity: unique symbol;
5328
- /** Public ordinary query handler; official identities cannot be erased into it. */
5329
- type GenericQueryHandler = GenericQueryHandlerCall & {
5330
- readonly [officialQueryHandlerIdentity]?: never;
5331
- };
5332
- /** Internal nominal call shape used by official query-based capabilities. */
5333
- type OfficialGenericQueryHandler = GenericQueryHandlerCall & {
5334
- readonly [officialQueryHandlerIdentity]: true;
5335
- };
5336
5080
  /**
5337
- * Per-model query handlers. Their results read the result context of the
5338
- * chain they are applied to: `Hidden` names the models its `rows` can hide
5339
- * (`rows` cannot follow a model-mapped handler, so a later extension adds
5340
- * none). A `rows` entry in the handler's OWN definition is not seen, as no
5341
- * definition types against its own contributions: declare it one step
5342
- * earlier.
5081
+ * The relation's cardinality wrapper, applied to an already-built element type
5082
+ * (plan §8.1's `RelationResult`): a to-many slot is an array, and a singular
5083
+ * slot is nullable unless the static membership projection PROVES it cannot be
5084
+ * empty. `SlotMayBeEmpty` answering a widened `boolean` therefore reads as
5085
+ * nullable, which is the safe direction — the promise "this is always present"
5086
+ * is the one that breaks callers.
5087
+ *
5088
+ * The asking key travels with the relation. Dropping it would let a self
5089
+ * relation select its own declaration as its inverse (§8.1 step 2).
5343
5090
  */
5344
- type QueryHandlerMap<C$1 extends VibORMConfig, Hidden$1 extends string = never> = { readonly [ModelName in keyof ClientSchema<C$1>]?: { readonly [OperationName in Operations]?: <Arg extends Exclude<OperationPayload<OperationName, ClientSchema<C$1>[ModelName]>, undefined>>(context: {
5345
- readonly mode: QueryInterceptionMode;
5346
- readonly kind: "model";
5347
- readonly model: ModelName;
5348
- readonly operation: OperationName;
5349
- readonly input: Readonly<Arg>;
5350
- /** The call's controls this handler's extension declares, and only those. */
5351
- readonly controls?: AdmittedControls;
5352
- readonly proceed: () => Promise<ContextualOperationResult<C$1, ModelName, OperationName, Arg, ClientRowsContext<C$1, Hidden$1>>>;
5353
- readonly onWriteOutcome: (listener: WriteOutcomeListener) => void;
5354
- }) => Promise<ContextualOperationResult<C$1, ModelName, OperationName, Arg, ClientRowsContext<C$1, Hidden$1>>> } };
5355
- //#endregion
5356
- //#region src/cache/capability.d.ts
5357
- declare const OFFICIAL_CACHE_NAME = "viborm.cache";
5358
- /** The exact official query contribution. It is recognized by identity. */
5359
- type OfficialCacheQueryContribution = OfficialGenericQueryHandler & {
5360
- bind(thisArg: unknown): GenericQueryHandler;
5361
- };
5091
+ type WrapRelation<S$1 extends ModelState, K$1, R$1 extends AnyRelation, T$1> = Cardinality<R$1> extends "many" ? T$1[] : SlotMayBeEmpty<SourceModelOf<S$1>, K$1, R$1> extends false ? T$1 : T$1 | null;
5092
+ type WrapRelationNode<S$1 extends ModelState, K$1, R$1 extends AnyRelation, T$1> = [T$1] extends [never] ? never : WrapRelation<S$1, K$1, R$1, T$1>;
5362
5093
  /**
5363
- * A mutation's `cache` argument is the cache's declared control (ruling 7):
5364
- * core removes and admits it before request handlers run, through the cache's
5365
- * own parser, so a malformed value is still a `CacheConfigurationError`.
5094
+ * A singular slot whose target the client's `rows` can hide reads `null` when
5095
+ * it is hidden, whatever the membership proves about the stored reference.
5096
+ * Applied beside {@link WrapRelation}, never inside it: a recursive slot is
5097
+ * always a self relation, which may be empty already (CM002), so only the
5098
+ * outer slot of a node ever needs it.
5366
5099
  */
5367
- type OfficialCacheControls = {
5368
- readonly cache: {
5369
- readonly schema: StandardSchemaV1<CacheInvalidationOptions>;
5370
- readonly on: "writes";
5371
- };
5372
- };
5373
- /** The official value accepted by the dedicated `$extends` overload. */
5374
- type OfficialCacheExtension = {
5375
- readonly name: typeof OFFICIAL_CACHE_NAME;
5376
- readonly query: OfficialCacheQueryContribution;
5377
- readonly controls: OfficialCacheControls;
5378
- };
5379
- //#endregion
5380
- //#region src/client/omit.d.ts
5381
- /** Fields a client hides by default, per model key of the schema. */
5382
- type ClientOmitConfig<S$1 extends Record<string, AnyModel>> = { [K in keyof S$1]?: ClientModelOmit<S$1[K]> };
5100
+ type OrHidden<T$1, R$1 extends AnyRelation, ClientDefaults> = [T$1] extends [never] ? never : Cardinality<R$1> extends "many" ? T$1 : T$1 | HiddenTargetNull<R$1, ClientDefaults>;
5383
5101
  /**
5384
- * The scalars of `M` a client may hide — every scalar except the ones the
5385
- * MODEL already hides for good (naming one of those has no `omit` key to name;
5386
- * see `@validation/model/core/projection`).
5387
- *
5388
- * The `any` arm is not decoration. A schema-generic extension sees
5389
- * `Model<any>`, whose `scalars` is `any` — and the subtraction above would then
5390
- * cancel to `never`, leaving `Partial<Record<never, true>>`, a config object
5391
- * with no known properties. Answering `string` preserves the contextual
5392
- * literal `true` until a concrete schema binds the official extension.
5102
+ * One finite named wrapper for an ordinary inferred node. The wrapper recurs
5103
+ * only through its relation property, so the ordinary projection is inferred
5104
+ * once rather than expanded once per requested depth. The repeated key is
5105
+ * wrapped by {@link WrapRelation}, the same cardinality and emptiness rule as
5106
+ * the outer slot, and its arguments are the same at every level.
5393
5107
  */
5394
- type ProjectableKeysOf<M$1 extends AnyModel> = 0 extends 1 & M$1["~"]["state"]["scalars"] ? string : Extract<Exclude<keyof M$1["~"]["state"]["scalars"], M$1["~"]["state"]["omit"] extends Record<string, true> ? keyof M$1["~"]["state"]["omit"] : never>, string>;
5108
+ type RecursiveRelationNode<Node, S$1 extends ModelState, K$1, R$1 extends AnyRelation, Exhaustive extends boolean> = Node & (Exhaustive extends true ? { [Field in Extract<K$1, PropertyKey>]: WrapRelation<S$1, K$1, R$1, RecursiveRelationNode<Node, S$1, K$1, R$1, Exhaustive>> } : { [Field in Extract<K$1, PropertyKey>]?: WrapRelation<S$1, K$1, R$1, RecursiveRelationNode<Node, S$1, K$1, R$1, Exhaustive>> });
5109
+ type IsExhaustiveRecurrence<Node> = [NodeRecurse<Node>] extends [{
5110
+ readonly depth: false;
5111
+ }] ? true : false;
5112
+ type ApplyRecurrence<S$1 extends ModelState, K$1, R$1 extends AnyRelation, Node, Inferred> = [NodeRecurse<Node>] extends [undefined] ? Inferred : RecursiveRelationNode<Inferred, S$1, K$1, R$1, IsExhaustiveRecurrence<Node>>;
5113
+ type InferRelationResult<S$1 extends ModelState, K$1, R$1 extends AnyRelation, ClientDefaults = never> = OrHidden<WrapRelation<S$1, K$1, R$1, ApplyOmit<InferModelOutput<GetTargetModelState<R$1>>, ResolveClientOmit<GetTargetModel<R$1>, ClientDefaults>>>, R$1, ClientDefaults>;
5114
+ type InferPolymorphicTargetVariant<Target$1 extends Model$1<any>, Override$1, ClientDefaults> = Target$1 extends Model$1<infer TargetState> ? TargetState extends ModelState ? Override$1 extends true ? ApplyOmit<InferModelOutput<TargetState>, ResolveClientOmit<Target$1, ClientDefaults>> : Override$1 extends object ? InferSelectInclude<TargetState, Override$1, NodeSelect<Override$1>, MergeClientOmit<ResolveClientOmit<Target$1, ClientDefaults>, NodeOmit<Override$1>>, ClientDefaults> : ApplyOmit<InferModelOutput<TargetState>, ResolveClientOmit<Target$1, ClientDefaults>> : never : never;
5395
5115
  /**
5396
- * The fields one model hides by default, each flagged `true`.
5397
- *
5398
- * `true` only — not `boolean`. Two reasons, and they are the same reason:
5399
- * - a `false` here would be a key that does nothing (the resolver only ever
5400
- * acts on `=== true`), and a config key that silently does nothing is the
5401
- * shape this codebase refuses; per-field re-inclusion belongs on the QUERY
5402
- * (`omit: { passwordHash: false }`), which is where it can be undone;
5403
- * - `boolean` as the contextual type widens the `true` a caller writes, and a
5404
- * widened flag is a flag the RESULT TYPE cannot resolve — it would render
5405
- * `passwordHash?: string` on a client that hides the column outright.
5116
+ * One configured polymorphic target. A missing projection key does not filter
5117
+ * that discriminator; it keeps the target model's default scalar output.
5406
5118
  */
5407
- type ClientModelOmit<M$1 extends AnyModel> = Partial<Record<ProjectableKeysOf<M$1>, true>>;
5408
- type ClientOmitKeys<Value> = Value extends unknown ? keyof Value : never;
5409
- type ClientOmitEntry<Given, ModelName$1 extends PropertyKey> = Given extends unknown ? ModelName$1 extends keyof Given ? Given[ModelName$1] : never : never;
5410
- /** Structural exactness for a direct client-default omit configuration. */
5411
- type ExactClientOmitConfig<Given, S$1 extends Record<string, AnyModel>> = Record<Exclude<ClientOmitKeys<Given>, keyof S$1>, never> & { [ModelName in Extract<ClientOmitKeys<Given>, keyof S$1>]?: Record<Exclude<ClientOmitKeys<ClientOmitEntry<Given, ModelName>>, keyof ClientModelOmit<S$1[ModelName]>>, never> };
5412
- //#endregion
5413
- //#region src/client/default-omit-extension.d.ts
5414
- declare const OFFICIAL_DEFAULT_OMIT_NAME = "viborm.defaultOmit";
5415
- declare const officialDefaultOmitConfig: unique symbol;
5416
- /** The authenticated request identity carrying one exact static omit witness. */
5417
- type OfficialDefaultOmitRequestContribution<Config> = OfficialGenericRequestHandler & {
5418
- readonly [officialDefaultOmitConfig]: Config;
5419
- bind(thisArg: unknown): GenericRequestHandler;
5420
- };
5421
- /** The official value accepted by the dedicated `$extends` admission branch. */
5422
- type OfficialDefaultOmitExtension<Config extends object = object> = {
5423
- readonly name: typeof OFFICIAL_DEFAULT_OMIT_NAME;
5424
- readonly request: OfficialDefaultOmitRequestContribution<Config>;
5425
- };
5426
- type DefaultOmitBinder<S$1 extends Schema$1> = <const Config extends ClientOmitConfig<S$1>>(config: Config & NoInfer<ExactClientOmitConfig<Config, S$1>>) => OfficialDefaultOmitExtension<Config & object>;
5427
- /** Create VibORM's fixed-name schema-bound default-omit extension. */
5428
- declare function defaultOmit<S$1 extends Schema$1>(): DefaultOmitBinder<S$1>;
5429
- //#endregion
5430
- //#region src/client/result-types.d.ts
5119
+ type InferPolymorphicVariant<R$1 extends AnyRelation, PublicType$1 extends PolymorphicPublicTypes<R$1>, Override$1, ClientDefaults> = GetPolymorphicTarget<R$1, PublicType$1> extends infer Target ? Target extends Model$1<any> ? InferPolymorphicTargetVariant<Target, Override$1, ClientDefaults> : never : never;
5120
+ type PolymorphicProjectionAt<Projection, PublicType$1 extends PropertyKey> = PublicType$1 extends keyof Projection ? Projection[PublicType$1] : undefined;
5431
5121
  /**
5432
- * Maps VibORM scalar types to their DATABASE RESULT types.
5433
- * This is what the ORM returns after querying the database.
5122
+ * One arm out of a collection's `variants` container.
5434
5123
  *
5435
- * Key difference from validation schema output:
5436
- * - datetime/date/time: returns Date (not ISO string)
5437
- * - json: inferred from custom schema if present, otherwise unknown
5438
- * - enum: inferred from schema values
5124
+ * The `Exclude` + re-added `undefined` is not decoration: `PolymorphicProjectionAt`
5125
+ * distributes over the KEY, not over the container, and `keyof (X | undefined)`
5126
+ * is `never` — so a container that MAY be undefined would answer `undefined`
5127
+ * for every arm, i.e. "no projection stated", i.e. the full default row. That
5128
+ * is the unsafe direction: the runtime may well apply the projection and return
5129
+ * fewer columns than the type promised.
5130
+ *
5131
+ * Splitting the container instead hands `InferPolymorphicTargetVariant` a
5132
+ * `Configured | undefined` override, which it already distributes into
5133
+ * `Selected | Default` — the honest union a caller in this position narrows.
5439
5134
  */
5440
- type ScalarResultTypeMap = {
5441
- string: string;
5442
- int: number;
5443
- number: number;
5444
- decimal: Decimal;
5445
- boolean: boolean;
5446
- datetime: Date;
5447
- date: Date;
5448
- time: string;
5449
- bigint: bigint;
5450
- json: unknown;
5451
- blob: Uint8Array;
5452
- vector: number[];
5453
- point: GeoPoint;
5454
- enum: string;
5455
- };
5135
+ type PolymorphicArmAt<Variants$1, PublicType$1 extends PropertyKey> = PolymorphicProjectionAt<Exclude<Variants$1, undefined>, PublicType$1> | (undefined extends Variants$1 ? undefined : never);
5456
5136
  /**
5457
- * Extract the ScalarState from a Scalar using infer to preserve literal types.
5137
+ * Exhaustive direct polymorphic result. Projection objects override individual
5138
+ * targets; omitted targets remain in the union with their default projection.
5458
5139
  */
5459
- type ExtractScalarState<F$1> = F$1 extends {
5460
- "~": {
5461
- state: infer S;
5462
- };
5463
- } ? S extends ScalarState ? S : never : never;
5140
+ type PolymorphicVariants<R$1 extends AnyRelation, Projection = undefined, ClientDefaults = never> = { [PublicType in PolymorphicPublicTypes<R$1>]: {
5141
+ readonly type: PublicType;
5142
+ readonly data: InferPolymorphicVariant<R$1, PublicType, PolymorphicProjectionAt<Projection, PublicType>, ClientDefaults>;
5143
+ } }[PolymorphicPublicTypes<R$1>];
5464
5144
  /**
5465
- * Get the base scalar type for a field, handling custom schemas.
5466
- * For json/enum scalars with custom schemas, infer from the schema.
5467
- * For datetime fields, always return Date (regardless of validation schema output).
5145
+ * The variants a COLLECTION projection can still produce, after `only`.
5468
5146
  *
5469
- * The enum arm reads the scalar's own `base` schema, so an enum's literal union
5470
- * survives a relation read exactly as it does a direct one: this helper is
5471
- * reached through the same `InferScalarOutput` on both paths.
5472
- */
5473
- type GetScalarResultType<F$1 extends Scalar> = ExtractScalarState<F$1> extends infer S ? S extends ScalarState ? S["type"] extends "json" ? S["schema"] extends StandardSchemaV1<any, infer O> ? O : unknown : S["type"] extends "enum" ? EnumValues<S["base"]>[number] : ScalarResultTypeMap[S["type"]] : unknown : unknown;
5474
- /**
5475
- * Apply nullable wrapper based on scalar state.
5476
- * Uses non-distributive check to handle boolean literals correctly.
5147
+ * The two `undefined` tests are ordered, and the order is the whole point:
5148
+ *
5149
+ * - `[Only] extends [undefined]` — the key is ABSENT (or the payload has an
5150
+ * index signature, which states nothing). Every variant survives.
5151
+ * - `undefined extends Only` — the key MAY be undefined, the shape real code
5152
+ * produces (`only: cond ? ["post"] : undefined`, or a forwarded optional
5153
+ * property). Only the runtime knows, so nothing is narrowed. This MUST be
5154
+ * tested BEFORE the element extraction: `readonly ["post"] | undefined`
5155
+ * matches `readonly (infer T)[]` on its defined member and would otherwise
5156
+ * narrow to `"post"` on a call that may not narrow at all.
5157
+ * - the tuple/array case narrows to the named members.
5158
+ * - anything else (a `string[]` built at runtime, an unresolvable generic)
5159
+ * narrows nothing, which is the honest answer.
5477
5160
  */
5478
- type ApplyNullable<T$1, Nullable> = [Nullable] extends [true] ? T$1 | null : T$1;
5161
+ type AllowedPublicTypes<R$1 extends AnyRelation, Only> = [Only] extends [undefined] ? PolymorphicPublicTypes<R$1> : undefined extends Only ? PolymorphicPublicTypes<R$1> : Only extends readonly (infer T)[] ? Extract<T, PolymorphicPublicTypes<R$1>> : PolymorphicPublicTypes<R$1>;
5479
5162
  /**
5480
- * Apply array wrapper based on scalar state.
5481
- * Uses non-distributive check to handle boolean literals correctly.
5163
+ * One element of a collection result: the same `{ type, data }` envelope the
5164
+ * to-one slot produces, but reached through `variants` rather than through the
5165
+ * projection's top level — which is what lets a public variant literally named
5166
+ * `only` or `variants` keep working.
5482
5167
  */
5483
- type ApplyArray<T$1, IsArray> = [IsArray] extends [true] ? T$1[] : T$1;
5168
+ type PolymorphicCollectionVariants<R$1 extends AnyRelation, Projection, ClientDefaults> = { [PublicType in AllowedPublicTypes<R$1, NodeOnly<Projection>>]: {
5169
+ readonly type: PublicType;
5170
+ readonly data: InferPolymorphicVariant<R$1, PublicType, PolymorphicArmAt<NodeVariants<Projection>, PublicType>, ClientDefaults>;
5171
+ } }[AllowedPublicTypes<R$1, NodeOnly<Projection>>];
5484
5172
  /**
5485
- * Infer the DATABASE RESULT type for a scalar.
5173
+ * CARDINALITY FIRST, through the same reader both target domains use — never by
5174
+ * testing `state.cardinality` inline, so one rule governs both levels.
5486
5175
  *
5487
- * This is the canonical helper for inferring output types from scalars.
5488
- * It correctly handles:
5489
- * - All scalar types with proper DB result mapping (datetime → Date)
5490
- * - Custom schemas for json/enum scalars
5491
- * - Nullable scalars
5492
- * - Array scalars
5176
+ * A collection is NEVER `| null`: an empty collection is `[]`, and `.optional()`
5177
+ * is unspellable on a collection state precisely so emptiness has one reading.
5178
+ * The singular arm asks the SAME `SlotMayBeEmpty` an ordinary slot asks; for a
5179
+ * variant target that projection is exactly the declared `.optional()` (§8.1).
5493
5180
  *
5494
- * @example
5495
- * // For s.dateTime().nullable() → Date | null
5496
- * // For s.string().array() → string[]
5497
- * // For s.json().schema(z.object({...})) → { ... }
5181
+ * The array wrapper is applied UNCONDITIONALLY, outside `WrapRelationNode`'s
5182
+ * never-collapse. `only: []` legitimately produces a `never` element union, and
5183
+ * collapsing that to `never` would type a call that returns a fresh empty array
5184
+ * as returning nothing at all; `readonly never[]` is the shape that matches.
5498
5185
  */
5499
- type InferScalarOutput<F$1 extends Scalar> = ExtractScalarState<F$1> extends infer S ? S extends ScalarState ? ApplyNullable<ApplyArray<GetScalarResultType<F$1>, S["array"]>, S["nullable"]> : never : never;
5186
+ type InferPolymorphicResult<S$1 extends ModelState, K$1, R$1 extends AnyRelation, Projection = undefined, ClientDefaults = never> = Cardinality<R$1> extends "many" ? readonly PolymorphicCollectionVariants<R$1, Projection, ClientDefaults>[] : SlotMayBeEmpty<SourceModelOf<S$1>, K$1, R$1> extends false ? PolymorphicVariants<R$1, Projection, ClientDefaults> | HiddenTargetNull<R$1, ClientDefaults> : PolymorphicVariants<R$1, Projection, ClientDefaults> | null;
5500
5187
  /**
5501
- * Result for batch operations (createMany, updateMany, deleteMany)
5188
+ * Infer result from select/include args
5189
+ * - select: ONLY returns selected fields
5190
+ * - include: returns base model + included relations
5191
+ * - neither: returns base model output
5192
+ *
5193
+ * The dispatch is on the select VALUE, not on key presence. `{ select: undefined }`
5194
+ * is the spread-an-optional idiom collapsed to a literal `undefined`, and the
5195
+ * parse boundary hands the engine a payload with no projection at all — so it
5196
+ * returns the full default row, exactly like `{}`. Reading it as "a selection of
5197
+ * nothing" typed that call `{}`, and `rows[0].id` stopped compiling on a call
5198
+ * that returns `id` at runtime.
5199
+ *
5200
+ * `select` + `include` is refused only when both keys carry values. `omit`
5201
+ * composes with either projection mode: in the selected world it subtracts
5202
+ * from the selected shape; in the unselected world it subtracts from the
5203
+ * default scalar shape.
5502
5204
  */
5503
- interface BatchPayload {
5504
- count: number;
5505
- }
5205
+ type InferSelectInclude<S$1 extends ModelState, Args, Selection$1 = NodeSelect<Args>, UnselectedOmit = NodeOmit<Args>, ClientDefaults = never> = [Selection$1] extends [undefined] ? InferUnselectedRow<S$1, Args, UnselectedOmit, ClientDefaults> : undefined extends Selection$1 ? InferUnselectedRow<S$1, Args, UnselectedOmit, ClientDefaults> | InferSelectedRow<S$1, Args, Exclude<Selection$1, undefined>, ClientDefaults> : InferSelectedRow<S$1, Args, Selection$1, ClientDefaults>;
5506
5206
  /**
5507
- * Result type for count operations
5508
- * Supports select for per-field counts like Prisma: count({ select: { _all: true, name: true } })
5207
+ * The row a node returns in the world where its `select` carries a value.
5208
+ *
5209
+ * `select` is exclusive with `include`, so a definite include makes this world
5210
+ * impossible. A local `omit` is different: it subtracts from the selected
5211
+ * result. Keys outside the selected shape have no effect.
5509
5212
  */
5510
- /** Literal selections are required; runtime choices expose optional fields. */
5511
- type SelectedFields<Selection$1, Fields$1> = { [K in keyof Selection$1 & keyof Fields$1 as Selection$1[K] extends true | object ? K : never]: Fields$1[K] } & { [K in keyof Selection$1 & keyof Fields$1 as Selection$1[K] extends true | object ? never : Extract<Selection$1[K], true | object> extends never ? never : K]?: Fields$1[K] };
5512
- type SelectedCountResult<Selection$1> = Prettify<SelectedFields<Selection$1, { [K in keyof Selection$1]: number }>>;
5513
- type CountResultType<Args, Selected = (Args extends {
5514
- select: infer Selection;
5515
- } ? SelectedCountResult<Selection> : never)> = Args extends {
5516
- select: unknown;
5517
- } ? keyof Selected extends never ? number : Selected : number;
5213
+ type InferSelectedRow<S$1 extends ModelState, Args, Selection$1, ClientDefaults> = undefined extends NodeInclude<Args> ? InferSelectResult<S$1, Selection$1, NodeOmit<Args>, ClientDefaults> : never;
5518
5214
  /**
5519
- * The non-recursive part of a model that result inference can compare safely.
5215
+ * The row a node returns when it states no `select`: the model's own output,
5216
+ * plus whatever `include` adds, reduced by the node's `omit`.
5520
5217
  *
5521
- * Full `Model` equality walks relation getters and collapses mutually-recursive
5522
- * model consts. These two key sets identify the usual case without touching any
5523
- * scalar implementation, external schema, or relation target. There are two,
5524
- * not three, because a model now holds ONE relation map across both target
5525
- * domains (§5.2).
5218
+ * An `include` that MAY be absent is read as ABSENT — the common ground of both
5219
+ * worlds — while a MAYBE `omit` softens instead (`ApplyOmit`). The asymmetry is
5220
+ * the direction of the lie: `include` only ADDS keys, so promising the smaller
5221
+ * row promises nothing that is missing at runtime, and the caller who wants the
5222
+ * relation spells the `include` definitely; `omit` REMOVES them, so reading a
5223
+ * maybe-omit as absent would promise a column the runtime may have dropped.
5526
5224
  */
5527
- type ModelResultSurface<M$1 extends Model$1<any>> = M$1 extends Model$1<infer S> ? readonly [Extract<keyof S["scalars"], string>, Extract<keyof S["relations"], string>] : never;
5528
- type SameKeySet<Left, Right> = [Exclude<Left, Right>] extends [never] ? [Exclude<Right, Left>] extends [never] ? true : false : false;
5529
- type IsUsableModelResultSurface<Surface> = [Surface] extends [never] ? false : Surface extends readonly [infer Scalars, infer Relations] ? string extends Scalars ? false : string extends Relations ? false : true : false;
5530
- /** Exact equality for the two shallow key sets above. */
5531
- type SameModelResultSurface<Left, Right> = IsUsableModelResultSurface<Left> extends true ? IsUsableModelResultSurface<Right> extends true ? Left extends readonly [infer LS, infer LR] ? Right extends readonly [infer RS, infer RR] ? SameKeySet<LS, RS> extends true ? SameKeySet<LR, RR> : false : false : false : false : false;
5225
+ type InferUnselectedRow<S$1 extends ModelState, Args, Omission = NodeOmit<Args>, ClientDefaults = never> = undefined extends NodeInclude<Args> ? ApplyOmit<InferModelOutput<S$1>, Omission> : ApplyOmit<InferIncludeResult<S$1, NodeInclude<Args>, ClientDefaults>, Omission>;
5532
5226
  /**
5533
- * The shallow surfaces of the models whose rows a client's `rows` can hide
5534
- * from a relation read (`ClientRowsContext`, ./types.ts). It rides the same
5535
- * result context as the omission defaults, as one more member of the union.
5227
+ * Result when select is provided - ONLY selected fields are returned
5536
5228
  */
5537
- interface ClientHiddenContext<Surfaces> {
5538
- readonly hidden: Surfaces;
5539
- }
5229
+ type InferSelectResult<S$1 extends ModelState, Selection$1, Omission = undefined, ClientDefaults = never> = Prettify<ApplyOmit<InferSelectedFields<S$1, Selection$1, ClientDefaults> & InferRelationCountSelection<S$1, Selection$1>, Omission> & InferDistanceSelection<S$1, Selection$1, Omission>>;
5540
5230
  /**
5541
- * `null` where a relation read can find this target hidden, and nothing
5542
- * otherwise. Models are compared by their shallow surface, as the omission
5543
- * defaults are: a target that shares its surface with a hidden model widens
5544
- * with it, and a surface too wide to compare widens too, both on the `| null`
5545
- * side. It distributes over the context, so a client without `rows` never
5546
- * resolves a target, and TypeScript measures the context parameter of every
5547
- * result type through it cheaply: the `[Hidden] extends [never]` form it
5548
- * replaces cost the schema-only floor 33,535 types (measured, U7 repair).
5231
+ * ONE mapped type over the model's shape, dispatching per member on TARGET KIND.
5232
+ *
5233
+ * There is no second polymorphic pass any more: both target domains live in the
5234
+ * one relation map (§5.2), and what still differs is only the ELEMENT shape a
5235
+ * variant slot produces — a discriminated `{ type, data }` union reached through
5236
+ * its own projection envelope. Splitting the map again here would put the same
5237
+ * key through two mapped types and let their guards drift apart.
5549
5238
  */
5550
- type HiddenTargetNull<R$1 extends AnyRelation, Context> = Context extends ClientHiddenContext<infer Hidden> ? true extends HidesTarget<R$1, Hidden> ? null : never : never;
5551
- type HidesTarget<R$1 extends AnyRelation, Hidden$1> = Hidden$1 extends unknown ? IsUsableModelResultSurface<Hidden$1> extends false ? true : MatchesSurface<TargetSurfaces<R$1>, Hidden$1> : never;
5552
- type MatchesSurface<Surface, Hidden$1> = Surface extends unknown ? IsUsableModelResultSurface<Surface> extends false ? true : SameModelResultSurface<Surface, Hidden$1> : never;
5553
- /** The shallow surface of each model a relation can target. */
5554
- type TargetSurfaces<R$1 extends AnyRelation> = IsVariantTarget<R$1> extends true ? ModelResultSurface<GetPolymorphicTarget<R$1, PolymorphicPublicTypes<R$1>>> : ModelResultSurface<GetTargetModel<R$1>>;
5555
- /** One configured model's compact, client-owned result default. */
5556
- interface ClientResultOmitEntry<Surface, Omission, Unique> {
5557
- readonly surface: Surface;
5558
- readonly omission: Omission;
5559
- readonly unique: Unique;
5560
- }
5561
- /** Named boundary so TypeScript can cache the carrier during result recursion. */
5562
- interface ClientResultOmitContext<Entries$1> {
5563
- readonly entries: Entries$1;
5564
- }
5565
- type EntrySurface<Entry> = Entry extends ClientResultOmitEntry<infer Surface, unknown, unknown> ? Surface : never;
5566
- type MatchingClientOmitEntries<M$1 extends Model$1<any>, Context, Entries$1 = (Context extends ClientResultOmitContext<infer E> ? E : never)> = M$1 extends unknown ? Entries$1 extends unknown ? true extends SameModelResultSurface<ModelResultSurface<M$1>, EntrySurface<Entries$1>> ? Entries$1 : never : never : never;
5567
- type IsUnion<T$1, Whole = T$1> = T$1 extends Whole ? [Whole] extends [T$1] ? false : true : never;
5568
- type HasMultipleModelResultSurfaces<M$1 extends Model$1<any>, WholeSurface = ModelResultSurface<M$1>> = M$1 extends unknown ? SameModelResultSurface<ModelResultSurface<M$1>, WholeSurface> extends true ? false : true : never;
5569
- type EntryOmission<Entry> = Entry extends ClientResultOmitEntry<unknown, infer Omission, unknown> ? Omission : never;
5570
- type EntryUnique<Entry> = Entry extends ClientResultOmitEntry<unknown, unknown, infer Unique> ? Unique : never;
5571
- type PossibleOmitKeys<Entry> = Entry extends unknown ? keyof Exclude<EntryOmission<Entry>, undefined> : never;
5572
- type SoftenedResolvedOmit<Keys$1 extends PropertyKey> = [Keys$1] extends [never] ? undefined : { [K in Keys$1]: boolean };
5239
+ type InferSelectedFields<S$1 extends ModelState, Selection$1, ClientDefaults> = SelectedFields<Selection$1, { [K in keyof Selection$1 & keyof S$1["shape"] as S$1["shape"][K] extends Scalar ? true extends Selection$1[K] ? K : never : K]: S$1["shape"][K] extends Scalar ? InferScalarOutput<S$1["shape"][K]> : S$1["shape"][K] extends AnyRelation ? InferSelectedRelation<S$1, K, S$1["shape"][K], Selection$1[K], ClientDefaults> : never }>;
5240
+ /** One selected relation member, per target kind then per projection value. */
5241
+ type InferSelectedRelation<S$1 extends ModelState, K$1, R$1 extends AnyRelation, Projection, ClientDefaults> = IsVariantTarget<R$1> extends true ? Projection extends true ? InferPolymorphicResult<S$1, K$1, R$1, undefined, ClientDefaults> : Projection extends object ? InferPolymorphicResult<S$1, K$1, R$1, Projection, ClientDefaults> : never : Projection extends true ? InferRelationResult<S$1, K$1, R$1, ClientDefaults> : Projection extends object ? InferRelationNodeResult<S$1, K$1, R$1, Projection, ClientDefaults> : never;
5242
+ type VectorScalarFieldKeys<S$1 extends ModelState> = { [K in keyof S$1["shape"]]: S$1["shape"][K] extends Scalar ? [ExtractScalarState<S$1["shape"][K]>] extends [ScalarState<"vector">] ? K : never : never }[keyof S$1["shape"]];
5243
+ type PointScalarFieldKeys<S$1 extends ModelState> = { [K in keyof S$1["shape"]]: S$1["shape"][K] extends Scalar ? [ExtractScalarState<S$1["shape"][K]>] extends [ScalarState<"point">] ? K : never : never }[keyof S$1["shape"]];
5244
+ type NullableDistanceScalarFieldKeys<S$1 extends ModelState> = { [K in DistanceScalarFieldKeys<S$1>]: S$1["shape"][K] extends Scalar ? ExtractScalarState<S$1["shape"][K]>["nullable"] extends true ? K : never : never }[DistanceScalarFieldKeys<S$1>];
5245
+ type DistanceScalarFieldKeys<S$1 extends ModelState> = VectorScalarFieldKeys<S$1> | PointScalarFieldKeys<S$1>;
5246
+ type SelectedDistanceKeys<S$1 extends ModelState, Selection$1> = { [K in keyof Selection$1 & DistanceScalarFieldKeys<S$1>]: Selection$1[K] extends {
5247
+ _distance: unknown;
5248
+ } ? K : never }[keyof Selection$1 & DistanceScalarFieldKeys<S$1>];
5249
+ type SelectedDistanceSources<S$1 extends ModelState, Selection$1> = { [K in SelectedDistanceKeys<S$1, Selection$1>]: true };
5250
+ type RemainingDistanceSources<S$1 extends ModelState, Selection$1, Omission> = ApplyOmit<SelectedDistanceSources<S$1, Selection$1>, Omission>;
5251
+ type RequiredKeys<T$1> = { [K in keyof T$1]-?: Record<never, never> extends Pick<T$1, K> ? never : K }[keyof T$1];
5252
+ type CosineDistanceKeys<S$1 extends ModelState, Selection$1> = { [K in keyof Selection$1 & VectorScalarFieldKeys<S$1>]: Selection$1[K] extends {
5253
+ _distance: {
5254
+ metric: infer Metric;
5255
+ };
5256
+ } ? "cosine" extends Metric ? K : never : never }[keyof Selection$1 & VectorScalarFieldKeys<S$1>];
5257
+ type DistanceValueForSources<S$1 extends ModelState, Sources, Selection$1> = Extract<keyof Sources, NullableDistanceScalarFieldKeys<S$1> | CosineDistanceKeys<S$1, Selection$1>> extends never ? number : number | null;
5258
+ type InferDistanceSelection<S$1 extends ModelState, Selection$1, Omission = undefined, Remaining = RemainingDistanceSources<S$1, Selection$1, Omission>> = [keyof Remaining] extends [never] ? Record<never, never> : [RequiredKeys<Remaining>] extends [never] ? {
5259
+ _distance?: DistanceValueForSources<S$1, Remaining, Selection$1>;
5260
+ } : {
5261
+ _distance: DistanceValueForSources<S$1, Remaining, Selection$1>;
5262
+ };
5573
5263
  /**
5574
- * Resolve a nested target's client default without comparing model graphs.
5264
+ * To-many (list) relation keys — the exact set Prisma's `_count: true`
5265
+ * shorthand expands to (`<Model>CountOutputType` holds only list relations).
5575
5266
  *
5576
- * A unique shallow surface identifies the configured model exactly. When two
5577
- * schema models have the same surface, the current public types contain no
5578
- * nominal identity that can distinguish their runtime objects. In that case,
5579
- * every possibly omitted field becomes a widened boolean; `ApplyOmit` renders
5580
- * it optional, which is honest in both runtime worlds.
5267
+ * ONE rule for both target domains: a variant collection is a list relation by
5268
+ * every reading that matters here — it holds many rows and it has a count.
5581
5269
  */
5582
- type ResolveClientOmit<M$1 extends Model$1<any>, Context, Matches = MatchingClientOmitEntries<M$1, Context>, AmbiguousKeys extends PropertyKey = PossibleOmitKeys<Matches>> = [Context] extends [never] ? undefined : [Matches] extends [never] ? undefined : true extends HasMultipleModelResultSurfaces<M$1> ? SoftenedResolvedOmit<AmbiguousKeys> : true extends IsUnion<EntryOmission<Matches>> ? SoftenedResolvedOmit<AmbiguousKeys> : false extends EntryUnique<Matches> ? SoftenedResolvedOmit<AmbiguousKeys> : EntryOmission<Matches>;
5583
- /** Get the target model itself without resolving its recursive state. */
5584
- type GetTargetModel<R$1 extends AnyRelation> = TargetGetter<R$1> extends (() => infer Target) ? Target extends Model$1<any> ? Target : never : never;
5270
+ type ToManyRelationKeys<S$1 extends ModelState> = { [K in keyof S$1["relations"]]: S$1["relations"][K] extends AnyRelation ? Cardinality<S$1["relations"][K]> extends "many" ? K : never : never }[keyof S$1["relations"]];
5585
5271
  /**
5586
- * Get the target model's state from a relation
5272
+ * The relation keys the EXPLICIT `_count: { select: … }` form may name.
5273
+ *
5274
+ * A deliberate superset of Prisma's, minus one cell: a variant SINGULAR slot's
5275
+ * `countFilter` family is a named refusal, so naming it must not compile either.
5276
+ * An ordinary singular relation stays nameable, as it is today.
5587
5277
  */
5588
- type GetTargetModelState<R$1 extends AnyRelation> = GetTargetModel<R$1> extends infer T ? T extends Model$1<infer S> ? S extends ModelState ? S : never : never : never;
5278
+ type CountableRelationKeys<S$1 extends ModelState> = { [K in keyof S$1["relations"]]: S$1["relations"][K] extends AnyRelation ? IsVariantTarget<S$1["relations"][K]> extends true ? Cardinality<S$1["relations"][K]> extends "many" ? K : never : K : never }[keyof S$1["relations"]];
5279
+ type InferRelationCountSelection<S$1 extends ModelState, Selection$1> = Selection$1 extends {
5280
+ _count: {
5281
+ select: infer CountSelection;
5282
+ };
5283
+ } ? {
5284
+ _count: { [K in keyof CountSelection & CountableRelationKeys<S$1> as CountSelection[K] extends true | object ? K : never]: number };
5285
+ } : Selection$1 extends {
5286
+ _count: true;
5287
+ } ? {
5288
+ _count: { [K in ToManyRelationKeys<S$1>]: number };
5289
+ } : Record<never, never>;
5589
5290
  /**
5590
- * Infer the output type for a model, respecting omit settings.
5591
- * Uses InferScalarOutput for correct DB result types (e.g., Date for datetime).
5291
+ * Result when include is provided - base result + included relations
5592
5292
  */
5593
- type InferModelOutput<S$1 extends ModelState> = S$1["omit"] extends Record<string, true> ? Omit<{ [K in keyof S$1["scalars"]]: S$1["scalars"][K] extends Scalar ? InferScalarOutput<S$1["scalars"][K]> : never }, keyof S$1["omit"]> : { [K in keyof S$1["scalars"]]: S$1["scalars"][K] extends Scalar ? InferScalarOutput<S$1["scalars"][K]> : never };
5293
+ type InferIncludeResult<S$1 extends ModelState, Include$1, ClientDefaults = never> = Prettify<InferModelOutput<S$1> & { [K in keyof Include$1 & keyof S$1["relations"] as Include$1[K] extends true | object ? K : never]: S$1["relations"][K] extends AnyRelation ? InferSelectedRelation<S$1, K, S$1["relations"][K], Include$1[K], ClientDefaults> : never } & InferRelationCountSelection<S$1, Include$1>>;
5594
5294
  /**
5595
- * `omit` at the TYPE level.
5596
- *
5597
- * Three cases, mirroring what the runtime can and cannot know:
5598
- * - `true` — the key is gone;
5599
- * - `false` (or absent) — the key stays;
5600
- * - a widened `boolean` (a variable, a spread, `cond ? true : false`) — only
5601
- * the runtime decides, so the key becomes OPTIONAL rather than being guessed
5602
- * into one arm. Claiming it is present would be a lie exactly when the flag
5603
- * is `true`, which is the case a caller writes this for.
5604
- *
5605
- * Model-level `.omit()` never appears here: those fields are absent from
5606
- * `InferModelOutput` already, and the `omit` schema has no key to name them
5607
- * with (see `src/validation/model/core/projection.ts`).
5295
+ * A relation node in `select`/`include` position: `{ select }`, `{ include }`,
5296
+ * `{ omit }`, pagination-only (`{ where, take, … }`), or any combination the
5297
+ * parse boundary accepts. A selected node applies its local omit after the
5298
+ * selection. An unselected node applies it to the default/include shape.
5299
+ * Pagination-only nodes fall through to the full relation payload.
5608
5300
  */
5609
- type DefinitelyOmittedKeys<O$1> = { [K in keyof O$1]: [O$1[K]] extends [true] ? K : never }[keyof O$1];
5610
- type MaybeOmittedKeys<O$1> = { [K in keyof O$1]: [O$1[K]] extends [true] ? never : [O$1[K]] extends [false] ? never : boolean extends O$1[K] ? K : never }[keyof O$1];
5611
- type ReduceOmit<T$1, O$1> = Omit<T$1, Extract<DefinitelyOmittedKeys<O$1> | MaybeOmittedKeys<O$1>, keyof T$1>> & Partial<Pick<T$1, Extract<MaybeOmittedKeys<O$1>, keyof T$1>>>;
5301
+ type InferRelationNodeResult<S$1 extends ModelState, K$1, R$1 extends AnyRelation, Node, ClientDefaults = never> = OrHidden<WrapRelationNode<S$1, K$1, R$1, ApplyRecurrence<S$1, K$1, R$1, Node, InferSelectInclude<GetTargetModelState<R$1>, Node, NodeSelect<Node>, MergeClientOmit<ResolveClientOmit<GetTargetModel<R$1>, ClientDefaults>, NodeOmit<Node>>, ClientDefaults>>>, R$1, ClientDefaults>;
5612
5302
  /**
5613
- * An `omit` that MAY be absent decides nothing on its own, so every key it
5614
- * names softens to a widened `boolean` — which {@link ReduceOmit} renders as an
5615
- * OPTIONAL key, the same convention a widened flag already follows. It is the
5616
- * spread idiom's other half: `{ ...(cond && { omit: { title: true } }) }` types
5617
- * `omit` as optional, and promising `title` outright would be a lie exactly
5618
- * when `cond` holds.
5303
+ * Extract scalar keys from a ModelShape
5619
5304
  */
5620
- type SoftenNodeOmit<O$1> = { [F in keyof O$1]: boolean };
5621
- type ApplyOmit<T$1, O$1> = [O$1] extends [undefined] ? T$1 : undefined extends O$1 ? ReduceOmit<T$1, SoftenNodeOmit<Exclude<O$1, undefined>>> : ReduceOmit<T$1, O$1>;
5305
+ type ScalarKeys$1<T$1 extends ModelShape> = { [K in keyof T$1]: T$1[K] extends Scalar ? K : never }[keyof T$1];
5622
5306
  /**
5623
- * Layer a query-local omission over a configured client default, per field.
5624
- * A local `false` restores one configured field; an optional local omission
5625
- * softens only the fields whose runtime value remains undecided.
5307
+ * Infer base type from a scalar for aggregates.
5308
+ * Uses InferScalarOutput for correct DB result types.
5626
5309
  */
5627
- type MergeClientOmit<Default, Local> = [Default] extends [undefined] ? Local : [Local] extends [undefined] ? Default : undefined extends Local ? Prettify<Omit<Default, keyof Exclude<Local, undefined>> & { [F in keyof Exclude<Local, undefined>]: boolean }> : Prettify<Omit<Default, keyof Local> & Local>;
5310
+ type InferScalarBase<F$1> = F$1 extends Scalar ? InferScalarOutput<F$1> : never;
5311
+ /** True when the scalar is a decimal, whose aggregates stay exact Decimals. */
5312
+ type IsDecimalScalar<F$1> = ExtractScalarState<F$1> extends {
5313
+ type: "decimal";
5314
+ } ? true : false;
5628
5315
  /**
5629
- * The value a node STATES under one projection key, or `undefined` when it
5630
- * states none.
5316
+ * Result type for aggregate operations
5317
+ * Dynamically typed based on which aggregates are requested
5631
5318
  *
5632
- * INDEXED ACCESS, not `Node extends { omit: infer O }`: a conditional matches a
5633
- * REQUIRED property, so it reads an OPTIONAL one — the exact shape TypeScript
5634
- * gives the spread idiom, `{ ...(cond && { select: sel }) }` -> `{ select?: Sel }`
5635
- * — as "no such key", and the key would silently decide nothing. Indexed access
5636
- * reports it as `Sel | undefined`, which is the truth: only the runtime knows.
5319
+ * THE RULE, and it is the RESULT PARSER's rule, not a guess:
5320
+ * `result-aggregate-parser.ts` marks `_sum` / `_min` / `_max` as `typed` and
5321
+ * decodes them through the FIELD'S OWN scalar decoder, so those three come back
5322
+ * spelled exactly like the column — `_sum` of an `s.bigInt()` is a `bigint`,
5323
+ * `_sum` of an `s.decimal({ precision, scale })` is an exact `Decimal`
5324
+ * (widened in precision, but still the field's scale). Only `_avg` takes the
5325
+ * widen-to-number path, and even it stays a `Decimal` for a decimal, because an
5326
+ * average of decimals is still a decimal — quantized to the field scale with
5327
+ * round-half-to-even.
5637
5328
  *
5638
- * An object with a string INDEX SIGNATURE states nothing, for the same reason
5639
- * `NoExtraClauseKeys` (./types.ts) refuses to police one: it declares no spelled
5640
- * key, and reading `Record<string, unknown>["select"]` as a projection would
5641
- * turn every dynamically-built payload into the ambiguous arm.
5329
+ * `_sum` used to be typed `number` for everything but a decimal, which made
5330
+ * `agg._sum.big * 2` type-check and then throw "Cannot mix BigInt and other
5331
+ * types" — and, worse, `agg._sum.big === 150` silently false. The decoder is the
5332
+ * half that is pinned behaviorally (tests/drivers/scalar-roundtrip-behavior.ts),
5333
+ * so the type follows it.
5642
5334
  */
5643
- type NodeKey<Node, Key$1 extends string> = string extends keyof Node ? undefined : Key$1 extends keyof Node ? Node[Extract<Key$1, keyof Node>] : undefined;
5335
+ type AggregateResultType<T$1 extends ModelShape, Args> = Prettify<SelectedFields<Args, { [K in keyof Args as K extends `_${string}` ? K : never]: K extends "_count" ? Args[K] extends boolean ? number : Args[K] extends object ? SelectedCountResult<Args[K]> : never : K extends "_sum" ? Args[K] extends object ? SelectedFields<Args[K], { [F in keyof Args[K]]: (F extends ScalarKeys$1<T$1> ? InferScalarBase<T$1[F]> : number) | null }> : never : K extends "_avg" ? Args[K] extends object ? SelectedFields<Args[K], { [F in keyof Args[K]]: (F extends ScalarKeys$1<T$1> ? IsDecimalScalar<T$1[F]> extends true ? Decimal : number : number) | null }> : never : K extends "_min" | "_max" ? Args[K] extends object ? SelectedFields<Args[K], { [F in keyof Args[K]]: F extends ScalarKeys$1<T$1> ? InferScalarBase<T$1[F]> | null : never }> : never : never }>>;
5644
5336
  /**
5645
- * Exported so the client layer can keep this query-local value distinct from
5646
- * its configured default: selected worlds apply only this value, while
5647
- * unselected worlds merge both before reducing the result.
5337
+ * Result type for groupBy operations
5338
+ * Includes the grouped-by fields plus any requested aggregates
5648
5339
  */
5649
- type NodeOmit<Node> = NodeKey<Node, "omit">;
5340
+ type GroupByResultType<T$1 extends ModelShape, Args> = Args extends {
5341
+ by: infer B;
5342
+ } ? Prettify<(B extends readonly (infer K)[] ? { [F in Extract<K, ScalarKeys$1<T$1> & keyof T$1>]: InferScalarBase<T$1[F]> } : B extends ScalarKeys$1<T$1> & keyof T$1 ? { [F in B]: InferScalarBase<T$1[F]> } : never) & AggregateResultType<T$1, Args>> : never;
5343
+ //#endregion
5344
+ //#region src/extensions/result-types.d.ts
5345
+ type AllModels = "$allModels";
5346
+ /** `Base` with `Over`'s members replacing its own. */
5347
+ type Override<Base$1, Over> = [keyof Over] extends [never] ? Base$1 : [keyof Base$1] extends [never] ? Over : Omit<Base$1, keyof Over> & Over;
5348
+ type FieldsAt<Result$1, Key$1> = Key$1 extends keyof Result$1 ? Result$1[Key$1] : unknown;
5349
+ /**
5350
+ * The fields one model gains, with their types: `$allModels` first, the
5351
+ * model's own after it, as the runtime orders them.
5352
+ */
5353
+ type ModelResultFields<Result$1, ModelName$1> = Override<FieldsAt<Result$1, AllModels> & {}, FieldsAt<Result$1, ModelName$1> & {}>;
5354
+ /**
5355
+ * Each declared field's type: what its `compute` returns. A definition
5356
+ * without `result` contributes `Record<never, never>`, spelled out rather
5357
+ * than through a local alias: a consumer's declaration emit prints this type
5358
+ * inside every extended client's state, and a name no public entry exports
5359
+ * would make that client unnameable there (TS2742).
5360
+ */
5361
+ type DefinitionResultFields<Definition$1> = Definition$1 extends {
5362
+ readonly result: infer Declared;
5363
+ } ? Declared extends object ? { readonly [ModelName in keyof Declared]: { -readonly [Field in keyof Declared[ModelName]]: Declared[ModelName][Field] extends {
5364
+ compute(...args: never[]): infer Value;
5365
+ } ? Value : never } } : Record<never, never> : Record<never, never>;
5366
+ /** The chain's fields with a later extension's: it wins a name. */
5367
+ type MergeResultFields<Previous extends object, Next$1 extends object> = [keyof Next$1] extends [never] ? Previous : [keyof Previous] extends [never] ? Next$1 : { readonly [ModelName in keyof Previous | keyof Next$1]: Override<FieldsAt<Previous, ModelName> & {}, FieldsAt<Next$1, ModelName> & {}> };
5368
+ /** The row a model's `compute` reads from: its scalars and earlier fields. */
5369
+ type ComputeRow<M$1, Earlier> = M$1 extends Model$1<infer State> ? Override<InferModelOutput<State>, Earlier> : never;
5370
+ /** The keys a `needs` map asks for. */
5371
+ type NeededKeys<Needs> = Needs extends object ? { [Key in keyof Needs]: Needs[Key] extends false ? never : Key }[keyof Needs] : never;
5372
+ /** The row one model's `compute` reads, before `needs` narrows it. */
5373
+ type ComputeRowOf<C$1 extends VibORMConfig, Earlier extends object, ModelName$1> = ModelName$1 extends keyof ClientSchema<C$1> ? ComputeRow<ClientSchema<C$1>[ModelName$1], ModelResultFields<Earlier, ModelName$1>> : never;
5374
+ /**
5375
+ * The `result` member as `$extends` and `defineExtension` type it. `Fields`
5376
+ * is its own type parameter, inferred from each field's `needs`, so that
5377
+ * each `compute` is given exactly the fields its `needs` names, typed from
5378
+ * the model: reading one it does not name is a compile error, as it would be
5379
+ * `undefined` at runtime, and a need the model lacks is refused. The
5380
+ * definition's own type parameter cannot carry this: a definition holding a
5381
+ * `compute` not yet typed is not inferred from at all. The shapes are
5382
+ * written inline, not through an interface, which TypeScript does not infer
5383
+ * through.
5384
+ */
5385
+ type ResultInference<C$1 extends VibORMConfig, Earlier extends object, Fields$1> = {
5386
+ readonly result?: { readonly [ModelName in keyof Fields$1]: ModelName extends "$allModels" ? { readonly [Field in keyof Fields$1[ModelName]]: {
5387
+ readonly needs?: Fields$1[ModelName][Field] & Readonly<Record<string, boolean>>;
5388
+ compute(row: { readonly [Key in NeededKeys<Fields$1[ModelName][Field]>]: unknown }): unknown;
5389
+ } } : { readonly [Field in keyof Fields$1[ModelName]]: {
5390
+ readonly needs?: Fields$1[ModelName][Field] & Readonly<Record<Exclude<keyof Fields$1[ModelName][Field], keyof ComputeRowOf<C$1, Earlier, ModelName>>, never>> & { readonly [Key in keyof ComputeRowOf<C$1, Earlier, ModelName>]?: boolean };
5391
+ compute(row: Pick<ComputeRowOf<C$1, Earlier, ModelName>, Extract<NeededKeys<Fields$1[ModelName][Field]>, keyof ComputeRowOf<C$1, Earlier, ModelName>>>): unknown;
5392
+ } } } & Readonly<Record<Exclude<keyof Fields$1, keyof ClientSchema<C$1> | "$allModels">, never>>;
5393
+ };
5650
5394
  /**
5651
- * The parse boundary treats an explicitly-`undefined` key as an ABSENT key
5652
- * (`src/validation/primitives/object.ts`), which is what makes the
5653
- * spread-an-optional idiom work; so `{ select: undefined }` and `{}` are the
5654
- * same payload, and this helper reports them the same way.
5395
+ * The `result` member of the definition envelope: which keys it holds. The
5396
+ * types of `needs` and `compute` are {@link ResultInference}'s.
5655
5397
  */
5656
- type NodeSelect<Node> = NodeKey<Node, "select">;
5657
- type NodeInclude<Node> = NodeKey<Node, "include">;
5658
- /** The public recurrence request stated by one admitted relation node. */
5659
- type NodeRecurse<Node> = NodeKey<Node, "recurse">;
5660
- /** The two keys of a polymorphic COLLECTION projection envelope. */
5661
- type NodeOnly<Projection> = NodeKey<Projection, "only">;
5662
- type NodeVariants<Projection> = NodeKey<Projection, "variants">;
5398
+ type ResultDefinition<C$1 extends VibORMConfig> = { readonly [ModelName in keyof ClientSchema<C$1> | "$allModels"]?: {
5399
+ readonly [field: string]: {
5400
+ readonly needs?: object;
5401
+ readonly compute: unknown;
5402
+ };
5403
+ } };
5404
+ //#endregion
5405
+ //#region src/extensions/methods.d.ts
5406
+ type NoMethods = Record<never, never>;
5407
+ type ExtensionMethod = (this: void, ...args: never[]) => unknown;
5408
+ type ExtensionMethodRecord = Readonly<Record<string, ExtensionMethod>>;
5409
+ declare const extensionCacheState: unique symbol;
5410
+ interface ExtensionCacheState {
5411
+ readonly [extensionCacheState]: true;
5412
+ }
5413
+ declare const extensionResultConsumerState: unique symbol;
5414
+ interface ExtensionResultConsumerState {
5415
+ readonly [extensionResultConsumerState]: true;
5416
+ }
5417
+ /** The only static facts accumulated while extensions are chained. */
5418
+ interface ClientExtensionState<ClientMethods extends object = NoMethods, ModelMethods extends object = NoMethods, CacheState extends ExtensionCacheState | undefined = undefined, ResultConsumerState extends ExtensionResultConsumerState | undefined = undefined, Controls$1 extends object = NoControls, RowModels extends string = never, Data$1 = never, Result$1 extends object = Record<never, never>> {
5419
+ readonly client: ClientMethods;
5420
+ readonly models: ModelMethods;
5421
+ readonly cache: CacheState;
5422
+ readonly resultConsumer: ResultConsumerState;
5423
+ /** The controls the chain declares: each one's values and placement. */
5424
+ readonly controls: Controls$1;
5425
+ /** The models the chain's `rows` can hide from a relation read. */
5426
+ readonly rows: RowModels;
5427
+ /** The fields the chain's `data` writes, which a caller no longer writes. */
5428
+ readonly data: Data$1;
5429
+ /** The fields the chain's `result` computes, per model key, and their types. */
5430
+ readonly result: Result$1;
5431
+ }
5432
+ type EmptyClientExtensionState = ClientExtensionState;
5433
+ /** Internal constraint for either the absent or enabled nominal cache bit. */
5434
+ type ExtensionStateConstraint = ClientExtensionState<object, object, ExtensionCacheState | undefined, ExtensionResultConsumerState | undefined, object, string, unknown, object>;
5435
+ /** Whether the current type-state includes the official cache capability. */
5436
+ type HasExtensionCache<X$1 extends ExtensionStateConstraint> = [X$1["cache"]] extends [ExtensionCacheState] ? true : false;
5663
5437
  /**
5664
- * The model that OWNS one asking slot, reconstructed from the state result
5665
- * inference already carries.
5666
- *
5667
- * `Model<State>` is the identity `s.model(...)` returns for that exact state,
5668
- * which is what the static membership projection compares getters against. It
5669
- * is not a second model concept: it is the same type, spelled from the half of
5670
- * it these mapped types thread.
5438
+ * Add the official cache capability without carrying its runtime config. Its
5439
+ * one control, `cache` on every write, joins the chain's controls as its
5440
+ * definition declares it.
5671
5441
  */
5672
- type SourceModelOf<S$1 extends ModelState> = Model$1<S$1>;
5673
- /** Does this relation name variants rather than one model? */
5674
- type IsVariantTarget<R$1 extends AnyRelation> = TargetKind<R$1> extends "variants" ? true : false;
5675
- /** The configured target model at one public discriminator. */
5676
- type GetPolymorphicTarget<R$1 extends AnyRelation, PublicType$1 extends PropertyKey> = PublicType$1 extends keyof VariantEntries<R$1> ? VariantEntries<R$1>[PublicType$1] extends {
5677
- readonly getter: infer Getter;
5678
- } ? Getter extends (() => infer Target) ? Target extends Model$1<any> ? Target : never : never : never : never;
5679
- type PolymorphicPublicTypes<R$1 extends AnyRelation> = Extract<keyof VariantEntries<R$1>, string>;
5442
+ type EnableExtensionCache<X$1 extends ExtensionStateConstraint> = ClientExtensionState<X$1["client"], X$1["models"], ExtensionCacheState, X$1["resultConsumer"], X$1["controls"] & DefinitionControls<{
5443
+ readonly controls: OfficialCacheControls;
5444
+ }>, X$1["rows"], X$1["data"], X$1["result"]>;
5445
+ /** Whether an earlier extension was typed against result-bearing delegates. */
5446
+ type HasResultConsumingExtension<X$1 extends ExtensionStateConstraint> = [X$1["resultConsumer"]] extends [undefined] ? false : [X$1["resultConsumer"]] extends [ExtensionResultConsumerState] ? true : false;
5447
+ type MethodsForModel<X$1 extends ExtensionStateConstraint, ModelName$1 extends PropertyKey> = ModelName$1 extends keyof X$1["models"] ? X$1["models"][ModelName$1] : NoMethods;
5680
5448
  /**
5681
- * Result for a relation when included
5682
- * - To-many relations return arrays
5683
- * - To-one relations return single objects (nullable if optional)
5684
- */
5685
- /**
5686
- * The relation's cardinality wrapper, applied to an already-built element type
5687
- * (plan §8.1's `RelationResult`): a to-many slot is an array, and a singular
5688
- * slot is nullable unless the static membership projection PROVES it cannot be
5689
- * empty. `SlotMayBeEmpty` answering a widened `boolean` therefore reads as
5690
- * nullable, which is the safe direction — the promise "this is always present"
5691
- * is the one that breaks callers.
5692
- *
5693
- * The asking key travels with the relation. Dropping it would let a self
5694
- * relation select its own declaration as its inverse (§8.1 step 2).
5449
+ * One model's delegate after the chain's methods and controls. On a chain
5450
+ * that declares create `data`, its writes may leave out the fields the chain
5451
+ * writes on a create.
5695
5452
  */
5696
- type WrapRelation<S$1 extends ModelState, K$1, R$1 extends AnyRelation, T$1> = Cardinality<R$1> extends "many" ? T$1[] : SlotMayBeEmpty<SourceModelOf<S$1>, K$1, R$1> extends false ? T$1 : T$1 | null;
5697
- type WrapRelationNode<S$1 extends ModelState, K$1, R$1 extends AnyRelation, T$1> = [T$1] extends [never] ? never : WrapRelation<S$1, K$1, R$1, T$1>;
5453
+ type ExtensionModelDelegate<C$1 extends VibORMConfig, X$1 extends ExtensionStateConstraint, ModelName$1 extends keyof ClientSchema<C$1>> = ([X$1["data"]] extends [never] ? Client<C$1, ClientRowsContext<C$1, X$1["rows"]>, X$1["controls"]>[ModelName$1] : Omit<Client<C$1, ClientRowsContext<C$1, X$1["rows"]>, X$1["controls"]>[ModelName$1], StampedOperation> & StampedOperations<C$1, ClientRowsContext<C$1, X$1["rows"]>, X$1["controls"], X$1["data"], ModelName$1>) & MethodsForModel<X$1, ModelName$1>;
5698
5454
  /**
5699
- * A singular slot whose target the client's `rows` can hide reads `null` when
5700
- * it is hidden, whatever the membership proves about the stored reference.
5701
- * Applied beside {@link WrapRelation}, never inside it: a recursive slot is
5702
- * always a self relation, which may be empty already (CM002), so only the
5703
- * outer slot of a node ever needs it.
5455
+ * One model's delegate on a chain that declares `result`: its projecting
5456
+ * operations rebuilt so `select` and `omit` name the computed fields and the
5457
+ * rows carry them. A chain without `result` never reaches this type.
5704
5458
  */
5705
- type OrHidden<T$1, R$1 extends AnyRelation, ClientDefaults> = [T$1] extends [never] ? never : Cardinality<R$1> extends "many" ? T$1 : T$1 | HiddenTargetNull<R$1, ClientDefaults>;
5459
+ type ComputedModelDelegate<C$1 extends VibORMConfig, X$1 extends ExtensionStateConstraint, ModelName$1 extends keyof ClientSchema<C$1>> = Omit<ExtensionModelDelegate<C$1, X$1, ModelName$1>, ComputedOperation> & ComputedOperations<C$1, ClientRowsContext<C$1, X$1["rows"]>, X$1["controls"], X$1["data"], ModelName$1, X$1["result"]>;
5706
5460
  /**
5707
- * One finite named wrapper for an ordinary inferred node. The wrapper recurs
5708
- * only through its relation property, so the ordinary projection is inferred
5709
- * once rather than expanded once per requested depth. The repeated key is
5710
- * wrapped by {@link WrapRelation}, the same cardinality and emptiness rule as
5711
- * the outer slot, and its arguments are the same at every level.
5461
+ * Model delegates after the methods contributed by the current chain. The
5462
+ * always-true test is deliberate: for a client generic over its config it
5463
+ * stays deferred, so the model map adds no index signature to that client and
5464
+ * its `$` members stay reachable inside a body generic over `C`. A chain
5465
+ * that declares `result` is told apart here, once per client.
5712
5466
  */
5713
- type RecursiveRelationNode<Node, S$1 extends ModelState, K$1, R$1 extends AnyRelation, Exhaustive extends boolean> = Node & (Exhaustive extends true ? { [Field in Extract<K$1, PropertyKey>]: WrapRelation<S$1, K$1, R$1, RecursiveRelationNode<Node, S$1, K$1, R$1, Exhaustive>> } : { [Field in Extract<K$1, PropertyKey>]?: WrapRelation<S$1, K$1, R$1, RecursiveRelationNode<Node, S$1, K$1, R$1, Exhaustive>> });
5714
- type IsExhaustiveRecurrence<Node> = [NodeRecurse<Node>] extends [{
5715
- readonly depth: false;
5716
- }] ? true : false;
5717
- type ApplyRecurrence<S$1 extends ModelState, K$1, R$1 extends AnyRelation, Node, Inferred> = [NodeRecurse<Node>] extends [undefined] ? Inferred : RecursiveRelationNode<Inferred, S$1, K$1, R$1, IsExhaustiveRecurrence<Node>>;
5718
- type InferRelationResult<S$1 extends ModelState, K$1, R$1 extends AnyRelation, ClientDefaults = never> = OrHidden<WrapRelation<S$1, K$1, R$1, ApplyOmit<InferModelOutput<GetTargetModelState<R$1>>, ResolveClientOmit<GetTargetModel<R$1>, ClientDefaults>>>, R$1, ClientDefaults>;
5719
- type InferPolymorphicTargetVariant<Target$1 extends Model$1<any>, Override, ClientDefaults> = Target$1 extends Model$1<infer TargetState> ? TargetState extends ModelState ? Override extends true ? ApplyOmit<InferModelOutput<TargetState>, ResolveClientOmit<Target$1, ClientDefaults>> : Override extends object ? InferSelectInclude<TargetState, Override, NodeSelect<Override>, MergeClientOmit<ResolveClientOmit<Target$1, ClientDefaults>, NodeOmit<Override>>, ClientDefaults> : ApplyOmit<InferModelOutput<TargetState>, ResolveClientOmit<Target$1, ClientDefaults>> : never : never;
5467
+ type ExtensionModelClient<C$1 extends VibORMConfig, X$1 extends ExtensionStateConstraint> = [keyof C$1["schema"]] extends [PropertyKey] ? [keyof X$1["result"]] extends [never] ? { [ModelName in keyof ClientSchema<C$1>]: ExtensionModelDelegate<C$1, X$1, ModelName> } : { [ModelName in keyof ClientSchema<C$1>]: ComputedModelDelegate<C$1, X$1, ModelName> } : unknown;
5468
+ /** The surface given to one client-method factory. */
5469
+ type ExtensionClientScope<C$1 extends VibORMConfig, X$1 extends ExtensionStateConstraint> = ExtensionModelClient<C$1, X$1> & RawSurface & X$1["client"] & {
5470
+ readonly $schema: ClientSchema<C$1>;
5471
+ readonly $transaction: TransactionClient<C$1, X$1>["$transaction"];
5472
+ /**
5473
+ * The client this scope's methods are called on, its calls admitting
5474
+ * these values of this extension's own controls as if passed (a
5475
+ * `bound: true` control only from here). Its type is that client's,
5476
+ * which only the method knows: declare it with a `this` parameter,
5477
+ * `$with<Self>(this: Self, value: Value): Self`, outside the returned
5478
+ * literal (inside it, the factory's contextual type makes `Self` void).
5479
+ */
5480
+ readonly $bind: (values: Readonly<Record<string, unknown>>) => unknown;
5481
+ };
5482
+ type NonFunctionKeys<Methods$1 extends object> = { [Key in keyof Methods$1]: Methods$1[Key] extends CallableFunction ? never : Key }[keyof Methods$1];
5483
+ type InvalidClientMethodKeys<Methods$1 extends object, C$1 extends VibORMConfig, X$1 extends ExtensionStateConstraint> = Exclude<keyof Methods$1, `$${string}`> | Extract<keyof Methods$1, keyof RawSurface | "$driver" | "$schema" | "$transaction" | "$connect" | "$disconnect" | "$withCache" | "$invalidate" | "$extends" | keyof X$1["client"]> | (string extends keyof C$1["schema"] ? never : Extract<keyof Methods$1, keyof C$1["schema"]>) | NonFunctionKeys<Methods$1>;
5484
+ type GuardMethodFactory<Factory$1, Forbidden extends PropertyKey> = Factory$1 extends ((...args: infer Params) => infer Methods) ? Methods extends object ? (...args: Params) => Methods & Record<Forbidden, never> : (...args: Params) => never : never;
5485
+ type ClientFactoryGuard<Definition$1, C$1 extends VibORMConfig, X$1 extends ExtensionStateConstraint> = Definition$1 extends {
5486
+ readonly client: infer Factory;
5487
+ } ? Factory extends ((...args: never[]) => infer Methods) ? Methods extends object ? {
5488
+ readonly client: GuardMethodFactory<Factory, InvalidClientMethodKeys<Methods, C$1, X$1>>;
5489
+ } : {
5490
+ readonly client: never;
5491
+ } : {
5492
+ readonly client: never;
5493
+ } : unknown;
5720
5494
  /**
5721
- * One configured polymorphic target. A missing projection key does not filter
5722
- * that discriminator; it keeps the target model's default scalar output.
5495
+ * What every model factory may not return: a core operation or `then`. That
5496
+ * each returned member is a function is the definition's own factory type
5497
+ * (`ModelMethodFactory` returns an `ExtensionMethodRecord`), not this guard;
5498
+ * `object` only keeps the all-optional key list from being a weak type, which
5499
+ * would refuse every return that names none of those keys. Stated as a target
5500
+ * shape, not a conditional over the factory, so a factory map generic over the
5501
+ * client is checked rather than deferred. A method a prior extension put on
5502
+ * the model cannot be named here for a client generic over its extension
5503
+ * state: the runtime refuses that replacement when the extension is applied.
5723
5504
  */
5724
- type InferPolymorphicVariant<R$1 extends AnyRelation, PublicType$1 extends PolymorphicPublicTypes<R$1>, Override, ClientDefaults> = GetPolymorphicTarget<R$1, PublicType$1> extends infer Target ? Target extends Model$1<any> ? InferPolymorphicTargetVariant<Target, Override, ClientDefaults> : never : never;
5725
- type PolymorphicProjectionAt<Projection, PublicType$1 extends PropertyKey> = PublicType$1 extends keyof Projection ? Projection[PublicType$1] : undefined;
5505
+ type ModelFactoryGuard = (...args: never[]) => object & { readonly [Name in Operations | "then"]?: never };
5726
5506
  /**
5727
- * One arm out of a collection's `variants` container.
5728
- *
5729
- * The `Exclude` + re-added `undefined` is not decoration: `PolymorphicProjectionAt`
5730
- * distributes over the KEY, not over the container, and `keyof (X | undefined)`
5731
- * is `never` — so a container that MAY be undefined would answer `undefined`
5732
- * for every arm, i.e. "no projection stated", i.e. the full default row. That
5733
- * is the unsafe direction: the runtime may well apply the projection and return
5734
- * fewer columns than the type promised.
5735
- *
5736
- * Splitting the container instead hands `InferPolymorphicTargetVariant` a
5737
- * `Configured | undefined` override, which it already distributes into
5738
- * `Selected | Default` — the honest union a caller in this position narrows.
5507
+ * Model keys outside the schema are refused by the definition's own `model`
5508
+ * type (its per-schema factory table); this guard checks each factory's
5509
+ * methods.
5739
5510
  */
5740
- type PolymorphicArmAt<Variants$1, PublicType$1 extends PropertyKey> = PolymorphicProjectionAt<Exclude<Variants$1, undefined>, PublicType$1> | (undefined extends Variants$1 ? undefined : never);
5511
+ type ModelFactoriesGuard<Definition$1> = Definition$1 extends {
5512
+ readonly model: infer Factories;
5513
+ } ? {
5514
+ readonly model: { readonly [ModelName in keyof Factories]: ModelFactoryGuard };
5515
+ } : unknown;
5516
+ type ExtensionMethodDefinitionGuard<Definition$1, C$1 extends VibORMConfig, X$1 extends ExtensionStateConstraint> = ClientFactoryGuard<Definition$1, C$1, X$1> & ModelFactoriesGuard<Definition$1>;
5517
+ type ClientMethodsOf<Definition$1> = Definition$1 extends {
5518
+ readonly client: (...args: never[]) => infer Methods;
5519
+ } ? Methods extends object ? Methods : NoMethods : NoMethods;
5520
+ type ModelMethodsOf<Definition$1> = Definition$1 extends {
5521
+ readonly model: infer Factories;
5522
+ } ? Factories extends object ? { readonly [ModelName in keyof Factories]: Factories[ModelName] extends ((...args: never[]) => infer Methods) ? Methods extends object ? Methods : NoMethods : NoMethods } : NoMethods : NoMethods;
5523
+ type MergeModelMethods<Left extends object, Right extends object> = { readonly [ModelName in keyof Left | keyof Right]: (ModelName extends keyof Left ? Left[ModelName] : NoMethods) & (ModelName extends keyof Right ? Right[ModelName] : NoMethods) };
5524
+ type ResultConsumerContextOf<Definition$1> = Definition$1 extends {
5525
+ readonly client: unknown;
5526
+ } | {
5527
+ readonly model: unknown;
5528
+ } ? "result-consuming" : Definition$1 extends {
5529
+ readonly query: infer Query;
5530
+ } ? Query extends CallableFunction ? "result-independent" : "result-consuming" : "result-independent";
5531
+ /** Incoming facts keep their nominal bit derivation inside this named state. */
5532
+ interface ExtensionContributionState<ClientMethods extends object, ModelMethods extends object, Controls$1 extends object, RowModels extends string, Data$1, ConsumerContext extends string, Result$1 extends object> extends ExtensionStateConstraint {
5533
+ readonly client: ClientMethods;
5534
+ readonly models: ModelMethods;
5535
+ readonly cache: undefined;
5536
+ readonly resultConsumer: ConsumerContext extends "result-consuming" ? ExtensionResultConsumerState : undefined;
5537
+ readonly controls: Controls$1;
5538
+ readonly rows: RowModels;
5539
+ readonly data: Data$1;
5540
+ readonly result: Result$1;
5541
+ }
5542
+ /** Retain contribution facts, never the factory's contextual argument surface. */
5543
+ type ExtensionStateContributionOf<Definition$1> = [Definition$1] extends [unknown] ? ExtensionContributionState<ClientMethodsOf<Definition$1>, ModelMethodsOf<Definition$1>, DefinitionControls<Definition$1>, RowsModels<Definition$1>, DefinitionData<Definition$1>, ResultConsumerContextOf<Definition$1>, DefinitionResultFields<Definition$1>> : never;
5544
+ /** Accumulate the same seven facts lazily, without retaining callback definitions. */
5545
+ interface AccumulatedExtensionState<X$1 extends ExtensionStateConstraint, Contribution extends ExtensionStateConstraint> extends ExtensionStateConstraint {
5546
+ readonly client: X$1["client"] & Contribution["client"];
5547
+ readonly models: MergeModelMethods<X$1["models"], Contribution["models"]>;
5548
+ readonly cache: X$1["cache"];
5549
+ readonly resultConsumer: HasResultConsumingExtension<Contribution> extends true ? ExtensionResultConsumerState : X$1["resultConsumer"];
5550
+ readonly controls: X$1["controls"] & Contribution["controls"];
5551
+ readonly rows: X$1["rows"] | Contribution["rows"];
5552
+ readonly data: X$1["data"] | Contribution["data"];
5553
+ readonly result: MergeResultFields<X$1["result"], Contribution["result"]>;
5554
+ }
5555
+ /** Public compatibility surface: the incoming argument remains a definition. */
5556
+ type MergeExtensionState<X$1 extends ExtensionStateConstraint, Definition$1> = AccumulatedExtensionState<X$1, ExtensionStateContributionOf<Definition$1>>;
5557
+ //#endregion
5558
+ //#region src/extensions/request.d.ts
5741
5559
  /**
5742
- * Exhaustive direct polymorphic result. Projection objects override individual
5743
- * targets; omitted targets remain in the union with their default projection.
5560
+ * The single operation-specific owner of request properties that determine the
5561
+ * public result type. A future projection spelling extends this table; runtime
5562
+ * detachment and the handler input/patch types then change together.
5744
5563
  */
5745
- type PolymorphicVariants<R$1 extends AnyRelation, Projection = undefined, ClientDefaults = never> = { [PublicType in PolymorphicPublicTypes<R$1>]: {
5746
- readonly type: PublicType;
5747
- readonly data: InferPolymorphicVariant<R$1, PublicType, PolymorphicProjectionAt<Projection, PublicType>, ClientDefaults>;
5748
- } }[PolymorphicPublicTypes<R$1>];
5564
+ declare const RESULT_SHAPE_KEYS_BY_OPERATION: Readonly<{
5565
+ findFirst: readonly ["select", "include", "omit"];
5566
+ findMany: readonly ["select", "include", "omit"];
5567
+ findUnique: readonly ["select", "include", "omit"];
5568
+ findUniqueOrThrow: readonly ["select", "include", "omit"];
5569
+ findFirstOrThrow: readonly ["select", "include", "omit"];
5570
+ create: readonly ["select", "include", "omit"];
5571
+ update: readonly ["select", "include", "omit"];
5572
+ delete: readonly ["select", "include", "omit"];
5573
+ upsert: readonly ["select", "include", "omit"];
5574
+ createMany: readonly ["select", "omit"];
5575
+ updateMany: readonly ["select", "omit"];
5576
+ deleteMany: readonly ["select", "omit"];
5577
+ count: readonly ["select"];
5578
+ aggregate: readonly ["_count", "_avg", "_sum", "_min", "_max"];
5579
+ groupBy: readonly ["by", "_count", "_avg", "_sum", "_min", "_max"];
5580
+ exist: readonly [];
5581
+ }>;
5582
+ type ResultShapeKeyFor<Operation$2 extends Operations> = (typeof RESULT_SHAPE_KEYS_BY_OPERATION)[Operation$2][number];
5583
+ /** The operation input visible to an ordinary request transform. */
5584
+ type RequestTransformInput<Operation$2 extends Operations, Input$1 extends object> = Omit<Input$1, ResultShapeKeyFor<Operation$2>>;
5749
5585
  /**
5750
- * The variants a COLLECTION projection can still produce, after `only`.
5751
- *
5752
- * The two `undefined` tests are ordered, and the order is the whole point:
5753
- *
5754
- * - `[Only] extends [undefined]` — the key is ABSENT (or the payload has an
5755
- * index signature, which states nothing). Every variant survives.
5756
- * - `undefined extends Only` — the key MAY be undefined, the shape real code
5757
- * produces (`only: cond ? ["post"] : undefined`, or a forwarded optional
5758
- * property). Only the runtime knows, so nothing is narrowed. This MUST be
5759
- * tested BEFORE the element extraction: `readonly ["post"] | undefined`
5760
- * matches `readonly (infer T)[]` on its defined member and would otherwise
5761
- * narrow to `"post"` on a call that may not narrow at all.
5762
- * - the tuple/array case narrows to the named members.
5763
- * - anything else (a `string[]` built at runtime, an unresolvable generic)
5764
- * narrows nothing, which is the honest answer.
5586
+ * A shallow patch over the non-projection input. The optional `never`
5587
+ * properties make protected keys fail structurally, including held values.
5765
5588
  */
5766
- type AllowedPublicTypes<R$1 extends AnyRelation, Only> = [Only] extends [undefined] ? PolymorphicPublicTypes<R$1> : undefined extends Only ? PolymorphicPublicTypes<R$1> : Only extends readonly (infer T)[] ? Extract<T, PolymorphicPublicTypes<R$1>> : PolymorphicPublicTypes<R$1>;
5589
+ type RequestTransformPatch<Operation$2 extends Operations, Input$1 extends object> = Partial<RequestTransformInput<Operation$2, Input$1>> & { readonly [Key in ResultShapeKeyFor<Operation$2>]?: never };
5590
+ interface GenericRequestContext {
5591
+ readonly model: string;
5592
+ readonly operation: Operations;
5593
+ readonly input: Readonly<RequestTransformPatch<Operations, Record<string, unknown>>>;
5594
+ /** The call's controls this handler's extension declares, and only those. */
5595
+ readonly controls?: AdmittedControls;
5596
+ }
5597
+ type GenericRequestHandlerCall = (context: GenericRequestContext) => Readonly<RequestTransformPatch<Operations, Record<string, unknown>>>;
5598
+ declare const officialRequestHandlerIdentity: unique symbol;
5599
+ /** Public ordinary request handler; official identities cannot be erased into it. */
5600
+ type GenericRequestHandler = GenericRequestHandlerCall & {
5601
+ readonly [officialRequestHandlerIdentity]?: never;
5602
+ };
5603
+ /** Internal nominal call shape used by official request-based capabilities. */
5604
+ type OfficialGenericRequestHandler = GenericRequestHandlerCall & {
5605
+ readonly [officialRequestHandlerIdentity]: true;
5606
+ };
5607
+ type RequestOperationInput<S$1 extends Schema$1, ModelName$1 extends keyof S$1, OperationName$1 extends Operations> = Extract<Exclude<OperationPayload<OperationName$1, S$1[ModelName$1]>, undefined>, object>;
5608
+ type RequestHandlerMap<S$1 extends Schema$1> = { readonly [ModelName in keyof S$1]?: { readonly [OperationName in Operations]?: (context: {
5609
+ readonly model: ModelName;
5610
+ readonly operation: OperationName;
5611
+ readonly input: Readonly<RequestTransformInput<OperationName, RequestOperationInput<S$1, ModelName, OperationName>>>;
5612
+ /** The call's controls this handler's extension declares, and only those. */
5613
+ readonly controls?: AdmittedControls;
5614
+ }) => RequestTransformPatch<OperationName, RequestOperationInput<S$1, ModelName, OperationName>> } };
5615
+ //#endregion
5616
+ //#region src/extensions/statement.d.ts
5617
+ /** The trusted identity exposed to one low-level statement transform. */
5618
+ interface StatementContext {
5619
+ readonly statement: Sql;
5620
+ readonly model: string | undefined;
5621
+ readonly operation: Operations | keyof RawSurface;
5622
+ }
5623
+ type StatementHandler = (context: StatementContext) => Sql;
5624
+ //#endregion
5625
+ //#region src/extensions/definition.d.ts
5626
+ type ExtensionConfig<S$1 extends Schema$1> = {
5627
+ readonly schema: S$1;
5628
+ readonly driver: AnyDriver;
5629
+ };
5767
5630
  /**
5768
- * One element of a collection result: the same `{ type, data }` envelope the
5769
- * to-one slot produces, but reached through `variants` rather than through the
5770
- * projection's top level — which is what lets a public variant literally named
5771
- * `only` or `variants` keep working.
5631
+ * A model factory, declared as a method so a factory typed against the client
5632
+ * it extends (`(delegate: M[K & keyof M]) => …`, generic over that client) is
5633
+ * compared in either direction rather than only contravariantly.
5772
5634
  */
5773
- type PolymorphicCollectionVariants<R$1 extends AnyRelation, Projection, ClientDefaults> = { [PublicType in AllowedPublicTypes<R$1, NodeOnly<Projection>>]: {
5774
- readonly type: PublicType;
5775
- readonly data: InferPolymorphicVariant<R$1, PublicType, PolymorphicArmAt<NodeVariants<Projection>, PublicType>, ClientDefaults>;
5776
- } }[AllowedPublicTypes<R$1, NodeOnly<Projection>>];
5635
+ type ModelMethodFactory<Delegate> = {
5636
+ factory(delegate: Delegate): ExtensionMethodRecord;
5637
+ }["factory"];
5777
5638
  /**
5778
- * CARDINALITY FIRST, through the same reader both target domains use — never by
5779
- * testing `state.cardinality` inline, so one rule governs both levels.
5780
- *
5781
- * A collection is NEVER `| null`: an empty collection is `[]`, and `.optional()`
5782
- * is unspellable on a collection state precisely so emptiness has one reading.
5783
- * The singular arm asks the SAME `SlotMayBeEmpty` an ordinary slot asks; for a
5784
- * variant target that projection is exactly the declared `.optional()` (§8.1).
5785
- *
5786
- * The array wrapper is applied UNCONDITIONALLY, outside `WrapRelationNode`'s
5787
- * never-collapse. `only: []` legitimately produces a `never` element union, and
5788
- * collapsing that to `never` would type a call that returns a fresh empty array
5789
- * as returning nothing at all; `readonly never[]` is the shape that matches.
5639
+ * One factory per schema model. A definition's model key is looked up here by
5640
+ * index, never by a conditional: a key outside the schema reads `never` (the
5641
+ * factory is refused where it is written), and a key set generic over the
5642
+ * client is substituted rather than deferred, so a plugin generic over `C`
5643
+ * type-checks and meets the schema check when it is applied.
5790
5644
  */
5791
- type InferPolymorphicResult<S$1 extends ModelState, K$1, R$1 extends AnyRelation, Projection = undefined, ClientDefaults = never> = Cardinality<R$1> extends "many" ? readonly PolymorphicCollectionVariants<R$1, Projection, ClientDefaults>[] : SlotMayBeEmpty<SourceModelOf<S$1>, K$1, R$1> extends false ? PolymorphicVariants<R$1, Projection, ClientDefaults> | HiddenTargetNull<R$1, ClientDefaults> : PolymorphicVariants<R$1, Projection, ClientDefaults> | null;
5645
+ type ModelFactoryTable<C$1 extends VibORMConfig, X$1 extends ExtensionStateConstraint> = { readonly [ModelName in keyof ClientSchema<C$1>]: ModelMethodFactory<ExtensionModelDelegate<C$1, X$1, ModelName>> };
5646
+ /** The model keys a definition's own `model` map names. */
5647
+ type DefinitionModelKeys<Self> = Self extends {
5648
+ readonly model?: infer Factories;
5649
+ } ? keyof Factories : never;
5792
5650
  /**
5793
- * Infer result from select/include args
5794
- * - select: ONLY returns selected fields
5795
- * - include: returns base model + included relations
5796
- * - neither: returns base model output
5797
- *
5798
- * The dispatch is on the select VALUE, not on key presence. `{ select: undefined }`
5799
- * is the spread-an-optional idiom collapsed to a literal `undefined`, and the
5800
- * parse boundary hands the engine a payload with no projection at all — so it
5801
- * returns the full default row, exactly like `{}`. Reading it as "a selection of
5802
- * nothing" typed that call `{}`, and `rows[0].id` stopped compiling on a call
5803
- * that returns `id` at runtime.
5651
+ * `Self` is the definition itself when `$extends` checks it (F-bounded), so
5652
+ * its model keys come from the definition; otherwise every schema model.
5653
+ */
5654
+ type ContextualExtensionDefinition<C$1 extends VibORMConfig, X$1 extends ExtensionStateConstraint, Self = unknown> = ExtensionMembers<C$1, X$1> & {
5655
+ readonly result?: ResultDefinition<C$1>;
5656
+ readonly model?: unknown extends Self ? { readonly [ModelName in keyof ClientSchema<C$1>]?: ModelMethodFactory<ExtensionModelDelegate<C$1, X$1, ModelName>> } : { readonly [ModelName in DefinitionModelKeys<Self>]?: ModelFactoryTable<C$1, X$1>[ModelName & keyof ClientSchema<C$1>] };
5657
+ };
5658
+ type ExtensionMembers<C$1 extends VibORMConfig, X$1 extends ExtensionStateConstraint> = {
5659
+ readonly name: string;
5660
+ readonly request?: GenericRequestHandler | RequestHandlerMap<ClientSchema<C$1>>;
5661
+ readonly query?: GenericQueryHandler | QueryHandlerMap<C$1, X$1["rows"]>;
5662
+ readonly statement?: StatementHandler;
5663
+ readonly observe?: ObserveHandler;
5664
+ readonly controls?: ControlsContribution;
5665
+ readonly rows?: RowsContribution;
5666
+ readonly deletion?: DeletionContribution;
5667
+ readonly data?: DataContribution;
5668
+ readonly client?: (scope: ExtensionClientScope<C$1, X$1>) => ExtensionMethodRecord;
5669
+ };
5670
+ type SchemaGenericExtensionDefinition = Omit<ContextualExtensionDefinition<ExtensionConfig<Schema$1>, EmptyClientExtensionState>, "request" | "query"> & {
5671
+ readonly request?: GenericRequestHandler;
5672
+ readonly query?: GenericQueryHandler;
5673
+ };
5674
+ /**
5675
+ * Public reusable extension definition.
5804
5676
  *
5805
- * `select` + `include` is refused only when both keys carry values. `omit`
5806
- * composes with either projection mode: in the selected world it subtracts
5807
- * from the selected shape; in the unselected world it subtracts from the
5808
- * default scalar shape.
5677
+ * A schema with a string index has no exact model vocabulary, so its reusable
5678
+ * request/query contributions must use the polymorphic all-operation form.
5679
+ * Supplying a concrete schema retains its exact model and operation maps.
5809
5680
  */
5810
- type InferSelectInclude<S$1 extends ModelState, Args, Selection$1 = NodeSelect<Args>, UnselectedOmit = NodeOmit<Args>, ClientDefaults = never> = [Selection$1] extends [undefined] ? InferUnselectedRow<S$1, Args, UnselectedOmit, ClientDefaults> : undefined extends Selection$1 ? InferUnselectedRow<S$1, Args, UnselectedOmit, ClientDefaults> | InferSelectedRow<S$1, Args, Exclude<Selection$1, undefined>, ClientDefaults> : InferSelectedRow<S$1, Args, Selection$1, ClientDefaults>;
5681
+ type ClientExtension<S$1 extends Schema$1 = Schema$1> = string extends keyof S$1 ? SchemaGenericExtensionDefinition : ContextualExtensionDefinition<ExtensionConfig<S$1>, EmptyClientExtensionState>;
5682
+ type DefinitionKeys = keyof ContextualExtensionDefinition<VibORMConfig, EmptyClientExtensionState>;
5683
+ declare const schemaBoundExtensionContext: unique symbol;
5684
+ type SchemaBoundExtension<Definition$1> = Definition$1 & {
5685
+ readonly [schemaBoundExtensionContext]: ResultConsumerContextOf<Definition$1>;
5686
+ };
5687
+ type UnknownDefinitionKeys<Definition$1> = Record<Exclude<keyof Definition$1, DefinitionKeys | typeof schemaBoundExtensionContext>, never>;
5688
+ type ConfigOmit$2<C$1 extends VibORMConfig> = "omit" extends keyof C$1 ? C$1[Extract<"omit", keyof C$1>] : undefined;
5689
+ type HasNamedClientOmit<C$1 extends VibORMConfig> = string extends keyof NonNullable<ConfigOmit$2<C$1>> ? false : [Exclude<ConfigOmit$2<C$1>, undefined>] extends [never] ? false : true;
5690
+ /** Refuse replaying a schema-bound result consumer into an omitted client. */
5691
+ type SchemaBoundExtensionAdmission<Definition$1, C$1 extends VibORMConfig> = Definition$1 extends {
5692
+ readonly [schemaBoundExtensionContext]: infer Context;
5693
+ } ? Context extends "result-consuming" ? HasNamedClientOmit<C$1> extends true ? {
5694
+ readonly [schemaBoundExtensionContext]: never;
5695
+ } : unknown : unknown : unknown;
5696
+ type OperationMapGuard<Map$1, S$1 extends Schema$1> = Map$1 extends CallableFunction ? unknown : Map$1 extends object ? Record<Exclude<keyof Map$1, keyof S$1>, never> & { readonly [ModelName in keyof Map$1]: ModelName extends keyof S$1 ? Map$1[ModelName] extends object ? Record<Exclude<keyof Map$1[ModelName], Operations>, never> : never : never } : never;
5697
+ type ComponentMapGuard<Definition$1, Key$1 extends "request" | "query", S$1 extends Schema$1> = Definition$1 extends { readonly [K in Key$1]: infer Component } ? { readonly [K in Key$1]: OperationMapGuard<Component, S$1> } : unknown;
5698
+ /** Policy model keys must be a subset of a concrete bound schema. */
5699
+ type PolicyModelsGuard<Definition$1, S$1 extends Schema$1, Key$1 extends "data" | "rows" | "deletion"> = Definition$1 extends { readonly [K in Key$1]: {
5700
+ readonly models: infer Models;
5701
+ } } ? string extends keyof S$1 ? unknown : [keyof Models] extends [keyof S$1] ? unknown : { readonly [K in Key$1]: {
5702
+ readonly models: Record<keyof Models, never>;
5703
+ } } : unknown;
5704
+ /** Structural refusal for non-fresh extension definitions and contributions. */
5705
+ type ExactExtensionDefinition<Definition$1, C$1 extends VibORMConfig, X$1 extends ExtensionStateConstraint> = UnknownDefinitionKeys<Definition$1> & ComponentMapGuard<Definition$1, "request", C$1["schema"]> & ComponentMapGuard<Definition$1, "query", C$1["schema"]> & PolicyModelsGuard<Definition$1, C$1["schema"], "data"> & PolicyModelsGuard<Definition$1, C$1["schema"], "rows"> & PolicyModelsGuard<Definition$1, C$1["schema"], "deletion"> & ExtensionMethodDefinitionGuard<Definition$1, C$1, X$1>;
5706
+ type DefineExtensionBinder<S$1 extends Schema$1> = <const Definition$1, Fields$1 = unknown>(definition: Definition$1 & ContextualExtensionDefinition<ExtensionConfig<S$1>, EmptyClientExtensionState> & ExactExtensionDefinition<Definition$1, ExtensionConfig<S$1>, EmptyClientExtensionState> & ResultInference<ExtensionConfig<S$1>, Record<never, never>, Fields$1>) => SchemaBoundExtension<NoInfer<Definition$1>>;
5707
+ declare function defineExtension<const Definition$1 extends SchemaGenericExtensionDefinition>(definition: Definition$1 & ExactExtensionDefinition<Definition$1, ExtensionConfig<Schema$1>, EmptyClientExtensionState>): NoInfer<Definition$1>;
5708
+ declare function defineExtension<S$1 extends Schema$1>(): DefineExtensionBinder<S$1>;
5709
+ //#endregion
5710
+ //#region src/extensions/controls.d.ts
5711
+ /** The operations a declared control is accepted on. */
5712
+ type ControlPlacement = "reads" | "writes" | "all" | readonly Operations[];
5811
5713
  /**
5812
- * The row a node returns in the world where its `select` carries a value.
5714
+ * One argument an extension declares. Its values are a closed list or a
5715
+ * Standard Schema; `on` names the operations that accept it (every operation
5716
+ * when absent). With `required`, a call on one of those operations that does
5717
+ * not pass it is refused, on the models the extension names in `rows`,
5718
+ * `data` or `deletion` only; an extension that names no model asks for it on
5719
+ * every model. With `bound`, it is accepted only from a binding (the client
5720
+ * scope's `$bind`), never from a call's arguments: its placement reads no
5721
+ * argument, so a call that passes it is refused as passing an unknown key.
5722
+ * With `uncacheable`, a read that holds a value of it is never served from
5723
+ * the cache: `$withCache` on that read is refused before any statement. A
5724
+ * value held in a variable keeps its literal type only with `as const`, as a
5725
+ * held enum clause does.
5726
+ */
5727
+ type ControlDeclaration = ({
5728
+ readonly oneOf: readonly (string | number | boolean)[];
5729
+ } | {
5730
+ readonly schema: StandardSchemaV1;
5731
+ }) & {
5732
+ readonly on?: ControlPlacement;
5733
+ readonly required?: boolean;
5734
+ readonly bound?: boolean;
5735
+ readonly uncacheable?: boolean;
5736
+ };
5737
+ type ControlsContribution = {
5738
+ readonly [name: string]: ControlDeclaration;
5739
+ };
5740
+ /** Constant scalar `where` or `data` fields of one model. */
5741
+ type ScalarFields = {
5742
+ readonly [field: string]: unknown;
5743
+ };
5744
+ /**
5745
+ * Which rows an operation sees. `control` names the call argument that picks
5746
+ * a mode; every model entry declares the same mode names, `default` among
5747
+ * them. `root` filters the call's own candidates, `related` rows reached
5748
+ * through a relation; each is a model's `where`, admitted once when the
5749
+ * extension is applied, or the name of one of its `verbs` predicates. Where a
5750
+ * filter takes a value, `{ control: "<name>", path?: "a.b" }` takes the value
5751
+ * the call passed for that control (or a field of it), `{ now: true }` the
5752
+ * call's instant, and `{ $if: … }` tests a call value. An absent value
5753
+ * (`null` included) matches nothing where its control is required, and drops
5754
+ * its filter where it is not.
5813
5755
  *
5814
- * `select` is exclusive with `include`, so a definite include makes this world
5815
- * impossible. A local `omit` is different: it subtracts from the selected
5816
- * result. Keys outside the selected shape have no effect.
5756
+ * `verbs` judges, per model, what a call may do to the rows it sees: a mode
5757
+ * only narrows them (R8). A model's entry may be a function returning it:
5758
+ * it is called when a call of the chain first needs that model, and its
5759
+ * entry admitted then, so a refusal of it fails that call instead of
5760
+ * `$extends`. A function returning deeply frozen plain data is called once
5761
+ * per schema; one returning anything else, once per client.
5817
5762
  */
5818
- type InferSelectedRow<S$1 extends ModelState, Args, Selection$1, ClientDefaults> = undefined extends NodeInclude<Args> ? InferSelectResult<S$1, Selection$1, NodeOmit<Args>, ClientDefaults> : never;
5763
+ type RowsContribution = {
5764
+ readonly control: string;
5765
+ readonly default: string;
5766
+ readonly models: {
5767
+ readonly [model: string]: {
5768
+ readonly [mode: string]: {
5769
+ readonly root?: ScalarFields | string;
5770
+ readonly related?: ScalarFields | string;
5771
+ };
5772
+ };
5773
+ };
5774
+ readonly verbs?: {
5775
+ readonly [model: string]: RowsVerbs | (() => RowsVerbs);
5776
+ };
5777
+ };
5819
5778
  /**
5820
- * The row a node returns when it states no `select`: the model's own output,
5821
- * plus whatever `include` adds, reduced by the node's `omit`.
5779
+ * One model's named predicates, each a `where` admitted once, and the verbs
5780
+ * that take them. `read` ANDs with every mode's `root` and `related`; a write
5781
+ * takes its verb's beside them: a delete `delete`'s, an update, for each
5782
+ * field its data writes, that field's `writes` entry, else `update`'s, and
5783
+ * `update`'s when its data writes only stamps. A join row's change is a write
5784
+ * of the relation on both rows it links; a row only addressed to reach its
5785
+ * children is read. A verb left out matches nothing.
5822
5786
  *
5823
- * An `include` that MAY be absent is read as ABSENT — the common ground of both
5824
- * worlds — while a MAYBE `omit` softens instead (`ApplyOmit`). The asymmetry is
5825
- * the direction of the lie: `include` only ADDS keys, so promising the smaller
5826
- * row promises nothing that is missing at runtime, and the caller who wants the
5827
- * relation spells the `include` definitely; `omit` REMOVES them, so reading a
5828
- * maybe-omit as absent would promise a column the runtime may have dropped.
5787
+ * The row a write produces is judged too, as a value, against the rows as
5788
+ * they stand before the write, inside the statement that writes it (R4): a
5789
+ * created row at `place` (a model naming none is not judged on create); an
5790
+ * updated row at the predicates that judged its old row, and, for each field
5791
+ * its data writes, at that field's `moves` entry, and where it writes the
5792
+ * key of an `acyclic` relation (a to-one relation of the model to itself),
5793
+ * outside its own subtree. `acyclic` may be a function returning that list:
5794
+ * it is called the first time an update writes the key of one of the
5795
+ * model's self relations. A refused row is written by no statement.
5796
+ *
5797
+ * `evidence` declares a projection key (`evidence.as`) a `select` or
5798
+ * `include` may name at every depth, on reads and on the rows a write
5799
+ * returns: per row, whether each of `names` holds there beside `read`, or,
5800
+ * `ordered`, the last of them that holds (`null` on a row `read` does not
5801
+ * hold). `reads` gates a field on a predicate: the row carries it only where
5802
+ * `read` and that predicate hold, a `select` naming it fails on a row
5803
+ * without them, and every operand a call writes over it (`where`, `orderBy`,
5804
+ * aggregates, `distinct`, unique lookups, relation filters) reads it as
5805
+ * absent there. A key or foreign-key field is never gated.
5829
5806
  */
5830
- type InferUnselectedRow<S$1 extends ModelState, Args, Omission = NodeOmit<Args>, ClientDefaults = never> = undefined extends NodeInclude<Args> ? ApplyOmit<InferModelOutput<S$1>, Omission> : ApplyOmit<InferIncludeResult<S$1, NodeInclude<Args>, ClientDefaults>, Omission>;
5807
+ type RowsVerbs = {
5808
+ readonly predicates: {
5809
+ readonly [name: string]: ScalarFields;
5810
+ };
5811
+ readonly read?: string;
5812
+ readonly update?: string;
5813
+ readonly delete?: string;
5814
+ readonly writes?: {
5815
+ readonly [field: string]: string;
5816
+ };
5817
+ readonly place?: string;
5818
+ readonly moves?: {
5819
+ readonly [field: string]: string;
5820
+ };
5821
+ readonly acyclic?: readonly string[] | (() => readonly string[]);
5822
+ readonly evidence?: {
5823
+ readonly as: string;
5824
+ readonly names: readonly string[];
5825
+ readonly ordered?: boolean;
5826
+ };
5827
+ readonly reads?: {
5828
+ readonly [field: string]: string;
5829
+ };
5830
+ };
5831
5831
  /**
5832
- * Result when select is provided - ONLY selected fields are returned
5832
+ * What a delete does on the models named here: an update that stamps `at`
5833
+ * with the call's time and writes `assign`, unless the call's controls match
5834
+ * `removeWhen`.
5833
5835
  */
5834
- type InferSelectResult<S$1 extends ModelState, Selection$1, Omission = undefined, ClientDefaults = never> = Prettify<ApplyOmit<InferSelectedFields<S$1, Selection$1, ClientDefaults> & InferRelationCountSelection<S$1, Selection$1>, Omission> & InferDistanceSelection<S$1, Selection$1, Omission>>;
5836
+ type DeletionContribution = {
5837
+ readonly removeWhen?: {
5838
+ readonly [control: string]: string | number | boolean;
5839
+ };
5840
+ readonly models: {
5841
+ readonly [model: string]: {
5842
+ readonly at?: string;
5843
+ readonly assign?: ScalarFields;
5844
+ };
5845
+ };
5846
+ };
5835
5847
  /**
5836
- * ONE mapped type over the model's shape, dispatching per member on TARGET KIND.
5837
- *
5838
- * There is no second polymorphic pass any more: both target domains live in the
5839
- * one relation map (§5.2), and what still differs is only the ELEMENT shape a
5840
- * variant slot produces — a discriminated `{ type, data }` union reached through
5841
- * its own projection envelope. Splitting the map again here would put the same
5842
- * key through two mapped types and let their guards drift apart.
5848
+ * Fields an extension writes on the models named here: `create` on every
5849
+ * create of the model, `update` on every update of it, a soft delete's
5850
+ * included. A value is a constant, `{ control: "<name>", path?: "a.b" }` for
5851
+ * the value the call passed for that control or a field of it (a call that
5852
+ * passed none writes nothing there), `{ now: true }` for the call's instant,
5853
+ * or, on `update`, one of the field's update operators (`{ increment: 1 }`). A field is written only where the caller left it
5854
+ * out: a call that writes it itself, or writes the relation whose foreign key
5855
+ * holds it, keeps its own value there. A create may leave out such a field
5856
+ * even where the schema requires it: the call's data is checked with it
5857
+ * counted as given. When the model names here are known to the types
5858
+ * (written out, or kept by a `const` type parameter, not a plain
5859
+ * `string[]`), the extended client's types agree, nested creates included:
5860
+ * the field is optional on a create. When two extensions name a field, the
5861
+ * later one writes it, and a value the caller writes wins over both.
5843
5862
  */
5844
- type InferSelectedFields<S$1 extends ModelState, Selection$1, ClientDefaults> = SelectedFields<Selection$1, { [K in keyof Selection$1 & keyof S$1["shape"] as S$1["shape"][K] extends Scalar ? true extends Selection$1[K] ? K : never : K]: S$1["shape"][K] extends Scalar ? InferScalarOutput<S$1["shape"][K]> : S$1["shape"][K] extends AnyRelation ? InferSelectedRelation<S$1, K, S$1["shape"][K], Selection$1[K], ClientDefaults> : never }>;
5845
- /** One selected relation member, per target kind then per projection value. */
5846
- type InferSelectedRelation<S$1 extends ModelState, K$1, R$1 extends AnyRelation, Projection, ClientDefaults> = IsVariantTarget<R$1> extends true ? Projection extends true ? InferPolymorphicResult<S$1, K$1, R$1, undefined, ClientDefaults> : Projection extends object ? InferPolymorphicResult<S$1, K$1, R$1, Projection, ClientDefaults> : never : Projection extends true ? InferRelationResult<S$1, K$1, R$1, ClientDefaults> : Projection extends object ? InferRelationNodeResult<S$1, K$1, R$1, Projection, ClientDefaults> : never;
5847
- type VectorScalarFieldKeys<S$1 extends ModelState> = { [K in keyof S$1["shape"]]: S$1["shape"][K] extends Scalar ? [ExtractScalarState<S$1["shape"][K]>] extends [ScalarState<"vector">] ? K : never : never }[keyof S$1["shape"]];
5848
- type PointScalarFieldKeys<S$1 extends ModelState> = { [K in keyof S$1["shape"]]: S$1["shape"][K] extends Scalar ? [ExtractScalarState<S$1["shape"][K]>] extends [ScalarState<"point">] ? K : never : never }[keyof S$1["shape"]];
5849
- type NullableDistanceScalarFieldKeys<S$1 extends ModelState> = { [K in DistanceScalarFieldKeys<S$1>]: S$1["shape"][K] extends Scalar ? ExtractScalarState<S$1["shape"][K]>["nullable"] extends true ? K : never : never }[DistanceScalarFieldKeys<S$1>];
5850
- type DistanceScalarFieldKeys<S$1 extends ModelState> = VectorScalarFieldKeys<S$1> | PointScalarFieldKeys<S$1>;
5851
- type SelectedDistanceKeys<S$1 extends ModelState, Selection$1> = { [K in keyof Selection$1 & DistanceScalarFieldKeys<S$1>]: Selection$1[K] extends {
5852
- _distance: unknown;
5853
- } ? K : never }[keyof Selection$1 & DistanceScalarFieldKeys<S$1>];
5854
- type SelectedDistanceSources<S$1 extends ModelState, Selection$1> = { [K in SelectedDistanceKeys<S$1, Selection$1>]: true };
5855
- type RemainingDistanceSources<S$1 extends ModelState, Selection$1, Omission> = ApplyOmit<SelectedDistanceSources<S$1, Selection$1>, Omission>;
5856
- type RequiredKeys<T$1> = { [K in keyof T$1]-?: Record<never, never> extends Pick<T$1, K> ? never : K }[keyof T$1];
5857
- type CosineDistanceKeys<S$1 extends ModelState, Selection$1> = { [K in keyof Selection$1 & VectorScalarFieldKeys<S$1>]: Selection$1[K] extends {
5858
- _distance: {
5859
- metric: infer Metric;
5863
+ type DataContribution = {
5864
+ readonly models: {
5865
+ readonly [model: string]: {
5866
+ readonly create?: ScalarFields;
5867
+ readonly update?: ScalarFields;
5868
+ };
5860
5869
  };
5861
- } ? "cosine" extends Metric ? K : never : never }[keyof Selection$1 & VectorScalarFieldKeys<S$1>];
5862
- type DistanceValueForSources<S$1 extends ModelState, Sources, Selection$1> = Extract<keyof Sources, NullableDistanceScalarFieldKeys<S$1> | CosineDistanceKeys<S$1, Selection$1>> extends never ? number : number | null;
5863
- type InferDistanceSelection<S$1 extends ModelState, Selection$1, Omission = undefined, Remaining = RemainingDistanceSources<S$1, Selection$1, Omission>> = [keyof Remaining] extends [never] ? Record<never, never> : [RequiredKeys<Remaining>] extends [never] ? {
5864
- _distance?: DistanceValueForSources<S$1, Remaining, Selection$1>;
5865
- } : {
5866
- _distance: DistanceValueForSources<S$1, Remaining, Selection$1>;
5867
5870
  };
5871
+ /** Operations that select candidates: where a rows control is accepted. */
5872
+ type CandidateOperations = Exclude<Operations, "create" | "createMany">;
5873
+ /** One declared control as the delegates see it. */
5874
+ interface PlacedControl<Value = unknown, Models$1 = PropertyKey, Placed = Operations> {
5875
+ readonly value: Value;
5876
+ readonly models: Models$1;
5877
+ readonly operations: Placed;
5878
+ }
5879
+ type NoControls = Record<never, never>;
5880
+ type ControlValue<Declaration> = Declaration extends {
5881
+ readonly oneOf: readonly (infer Value)[];
5882
+ } ? Value : Declaration extends {
5883
+ readonly schema: StandardSchemaV1<infer Input>;
5884
+ } ? Input : never;
5885
+ type PlacementOperations<On> = On extends "reads" ? CacheableOperations : On extends "writes" ? MutationOperations : On extends readonly (infer Operation)[] ? Operation : Operations;
5886
+ /**
5887
+ * `deletion` places the control `removeWhen` names: on the deletes of the
5888
+ * models it manages, whatever the declaration's `on` says.
5889
+ */
5890
+ type PlaceControl<Name$1, Declaration, Deletion> = Deletion extends {
5891
+ readonly removeWhen: infer RemoveWhen;
5892
+ readonly models: infer Managed;
5893
+ } ? Name$1 extends keyof RemoveWhen ? PlacedControl<ControlValue<Declaration>, keyof Managed, "delete" | "deleteMany"> : PlaceFreeControl<Declaration> : PlaceFreeControl<Declaration>;
5894
+ type PlaceFreeControl<Declaration> = PlacedControl<ControlValue<Declaration>, PropertyKey, PlacementOperations<Declaration extends {
5895
+ readonly on: infer On;
5896
+ } ? On : "all">>;
5897
+ type DeclaredControls<Definition$1> = Definition$1 extends {
5898
+ readonly controls: infer Controls extends ControlsContribution;
5899
+ } ? { readonly [Name in keyof Controls as Controls[Name] extends {
5900
+ readonly bound: true;
5901
+ } ? never : Name]: PlaceControl<Name, Controls[Name], Definition$1 extends {
5902
+ readonly deletion: infer Deletion;
5903
+ } ? Deletion : unknown> } : NoControls;
5904
+ /** Every model entry declares the same mode names: those are the values. */
5905
+ type RowsModes<Rows$1 extends RowsContribution> = Rows$1["default"] | { [Model in keyof Rows$1["models"]]: keyof Rows$1["models"][Model] }[keyof Rows$1["models"]];
5906
+ /** The rows control: every candidate-selecting operation of every model. */
5907
+ type RowsControl<Definition$1> = Definition$1 extends {
5908
+ readonly rows: infer Rows extends RowsContribution;
5909
+ } ? { readonly [Name in Rows["control"]]: PlacedControl<RowsModes<Rows>, PropertyKey, CandidateOperations> } : NoControls;
5868
5910
  /**
5869
- * To-many (list) relation keys — the exact set Prisma's `_count: true`
5870
- * shorthand expands to (`<Model>CountOutputType` holds only list relations).
5871
- *
5872
- * ONE rule for both target domains: a variant collection is a list relation by
5873
- * every reading that matters here — it holds many rows and it has a count.
5911
+ * The models one definition's `rows` can hide from a relation read: its
5912
+ * `models` and `verbs` keys. A to-one relation that targets one of them reads `null` when
5913
+ * its target is hidden, so the result types widen it (`result-types.ts`).
5874
5914
  */
5875
- type ToManyRelationKeys<S$1 extends ModelState> = { [K in keyof S$1["relations"]]: S$1["relations"][K] extends AnyRelation ? Cardinality<S$1["relations"][K]> extends "many" ? K : never : never }[keyof S$1["relations"]];
5915
+ type RowsModels<Definition$1> = Definition$1 extends {
5916
+ readonly rows: infer Rows extends RowsContribution;
5917
+ } ? Extract<keyof Rows["models"] | (Rows extends {
5918
+ readonly verbs: infer Verbs;
5919
+ } ? keyof Verbs : never), string> : never;
5920
+ /** The controls one definition places, keyed by control name. */
5921
+ type DefinitionControls<Definition$1> = DeclaredControls<Definition$1> & RowsControl<Definition$1>;
5922
+ /** The optional control arguments one (model, operation) accepts. */
5923
+ type OperationControls<Controls$1, ModelName$1, Operation$2> = { readonly [Name in keyof Controls$1 as Controls$1[Name] extends PlacedControl<unknown, infer Models, infer Placed> ? ModelName$1 extends Models ? Operation$2 extends Placed ? Name : never : never : never]?: Controls$1[Name] extends PlacedControl<infer Value> ? Value : never };
5876
5924
  /**
5877
- * The relation keys the EXPLICIT `_count: { select: … }` form may name.
5878
- *
5879
- * A deliberate superset of Prisma's, minus one cell: a variant SINGULAR slot's
5880
- * `countFilter` family is a named refusal, so naming it must not compile either.
5881
- * An ordinary singular relation stays nameable, as it is today.
5925
+ * The fields one `data` entry writes on its models' creates: there they may
5926
+ * be left out even where the schema requires them. An update's fields need
5927
+ * nothing, as every field of an update is optional already.
5882
5928
  */
5883
- type CountableRelationKeys<S$1 extends ModelState> = { [K in keyof S$1["relations"]]: S$1["relations"][K] extends AnyRelation ? IsVariantTarget<S$1["relations"][K]> extends true ? Cardinality<S$1["relations"][K]> extends "many" ? K : never : K : never }[keyof S$1["relations"]];
5884
- type InferRelationCountSelection<S$1 extends ModelState, Selection$1> = Selection$1 extends {
5885
- _count: {
5886
- select: infer CountSelection;
5887
- };
5888
- } ? {
5889
- _count: { [K in keyof CountSelection & CountableRelationKeys<S$1> as CountSelection[K] extends true | object ? K : never]: number };
5890
- } : Selection$1 extends {
5891
- _count: true;
5892
- } ? {
5893
- _count: { [K in ToManyRelationKeys<S$1>]: number };
5894
- } : Record<never, never>;
5929
+ interface StampedFields<Models$1 = PropertyKey, Fields$1 = PropertyKey> {
5930
+ readonly models: Models$1;
5931
+ readonly fields: Fields$1;
5932
+ }
5933
+ type CreateStamps<Model$2, Entry> = "create" extends keyof Entry ? Entry extends {
5934
+ readonly create?: infer Fields;
5935
+ } ? StampedFields<Model$2, keyof NonNullable<Fields>> : never : never;
5895
5936
  /**
5896
- * Result when include is provided - base result + included relations
5937
+ * What one definition's `data` writes on creates: one member per model. A
5938
+ * definition whose model names are lost (`{ [model: string]: ... }`, as a
5939
+ * recipe called with a plain `string[]` builds) writes nothing the types can
5940
+ * name: its required fields stay required in the payloads.
5897
5941
  */
5898
- type InferIncludeResult<S$1 extends ModelState, Include$1, ClientDefaults = never> = Prettify<InferModelOutput<S$1> & { [K in keyof Include$1 & keyof S$1["relations"] as Include$1[K] extends true | object ? K : never]: S$1["relations"][K] extends AnyRelation ? InferSelectedRelation<S$1, K, S$1["relations"][K], Include$1[K], ClientDefaults> : never } & InferRelationCountSelection<S$1, Include$1>>;
5942
+ type DefinitionData<Definition$1> = Definition$1 extends {
5943
+ readonly data: {
5944
+ readonly models: infer Models;
5945
+ };
5946
+ } ? string extends keyof Models ? never : { [Model in keyof Models]: CreateStamps<Model, Models[Model]> }[keyof Models] : never;
5947
+ /** The fields a chain writes on every create of one model. */
5948
+ type StampedFieldNames<Data$1, ModelName$1> = Data$1 extends StampedFields<infer Models, infer Fields extends PropertyKey> ? ModelName$1 extends Models ? Fields : never : never;
5899
5949
  /**
5900
- * A relation node in `select`/`include` position: `{ select }`, `{ include }`,
5901
- * `{ omit }`, pagination-only (`{ where, take, … }`), or any combination the
5902
- * parse boundary accepts. A selected node applies its local omit after the
5903
- * selection. An unselected node applies it to the default/include shape.
5904
- * Pagination-only nodes fall through to the full relation payload.
5950
+ * The controls one call admitted, by name. A `rows` control is resolved to its
5951
+ * mode, so an absent one reads as its default; an absent plain control is not
5952
+ * here.
5905
5953
  */
5906
- type InferRelationNodeResult<S$1 extends ModelState, K$1, R$1 extends AnyRelation, Node, ClientDefaults = never> = OrHidden<WrapRelationNode<S$1, K$1, R$1, ApplyRecurrence<S$1, K$1, R$1, Node, InferSelectInclude<GetTargetModelState<R$1>, Node, NodeSelect<Node>, MergeClientOmit<ResolveClientOmit<GetTargetModel<R$1>, ClientDefaults>, NodeOmit<Node>>, ClientDefaults>>>, R$1, ClientDefaults>;
5954
+ type AdmittedControls = Readonly<Record<string, unknown>>;
5955
+ //#endregion
5956
+ //#region src/extensions/query.d.ts
5957
+ type QueryInterceptionMode = "direct" | "transaction" | "array";
5958
+ type RawQueryKind = "queryRaw" | "executeRaw" | "queryRawUnsafe" | "executeRawUnsafe";
5959
+ type WriteOutcome = Readonly<{
5960
+ certainty: "committed" | "may-have-committed";
5961
+ }>;
5962
+ type WriteOutcomeListener = (outcome: WriteOutcome) => unknown | Promise<unknown>;
5963
+ type GenericQueryContextBase<Result$1> = {
5964
+ readonly mode: QueryInterceptionMode;
5965
+ readonly input: Readonly<Record<string, unknown>>;
5966
+ readonly proceed: () => Promise<Result$1>;
5967
+ readonly onWriteOutcome: (listener: WriteOutcomeListener) => void;
5968
+ };
5969
+ type GenericModelQueryContext<Result$1> = GenericQueryContextBase<Result$1> & {
5970
+ readonly kind: "model";
5971
+ readonly model: string;
5972
+ readonly operation: Operations;
5973
+ /** The call's controls this handler's extension declares, and only those. */
5974
+ readonly controls?: AdmittedControls;
5975
+ };
5976
+ type GenericRawQueryContext<Result$1> = GenericQueryContextBase<Result$1> & { [Kind in RawQueryKind]: {
5977
+ readonly kind: Kind;
5978
+ readonly model: undefined;
5979
+ readonly operation: `$${Kind}`;
5980
+ } }[RawQueryKind];
5981
+ type GenericQueryContext<Result$1> = GenericModelQueryContext<Result$1> | GenericRawQueryContext<Result$1>;
5982
+ type GenericQueryHandlerCall = <Result$1>(context: GenericQueryContext<Result$1>) => Promise<Result$1>;
5983
+ declare const officialQueryHandlerIdentity: unique symbol;
5984
+ /** Public ordinary query handler; official identities cannot be erased into it. */
5985
+ type GenericQueryHandler = GenericQueryHandlerCall & {
5986
+ readonly [officialQueryHandlerIdentity]?: never;
5987
+ };
5988
+ /** Internal nominal call shape used by official query-based capabilities. */
5989
+ type OfficialGenericQueryHandler = GenericQueryHandlerCall & {
5990
+ readonly [officialQueryHandlerIdentity]: true;
5991
+ };
5907
5992
  /**
5908
- * Extract scalar keys from a ModelShape
5993
+ * Per-model query handlers. Their results read the result context of the
5994
+ * chain they are applied to: `Hidden` names the models its `rows` can hide
5995
+ * (`rows` cannot follow a model-mapped handler, so a later extension adds
5996
+ * none). A `rows` entry in the handler's OWN definition is not seen, as no
5997
+ * definition types against its own contributions: declare it one step
5998
+ * earlier.
5909
5999
  */
5910
- type ScalarKeys$1<T$1 extends ModelShape> = { [K in keyof T$1]: T$1[K] extends Scalar ? K : never }[keyof T$1];
6000
+ type QueryHandlerMap<C$1 extends VibORMConfig, Hidden$1 extends string = never> = { readonly [ModelName in keyof ClientSchema<C$1>]?: { readonly [OperationName in Operations]?: <Arg extends Exclude<OperationPayload<OperationName, ClientSchema<C$1>[ModelName]>, undefined>>(context: {
6001
+ readonly mode: QueryInterceptionMode;
6002
+ readonly kind: "model";
6003
+ readonly model: ModelName;
6004
+ readonly operation: OperationName;
6005
+ readonly input: Readonly<Arg>;
6006
+ /** The call's controls this handler's extension declares, and only those. */
6007
+ readonly controls?: AdmittedControls;
6008
+ readonly proceed: () => Promise<ContextualOperationResult<C$1, ModelName, OperationName, Arg, ClientRowsContext<C$1, Hidden$1>>>;
6009
+ readonly onWriteOutcome: (listener: WriteOutcomeListener) => void;
6010
+ }) => Promise<ContextualOperationResult<C$1, ModelName, OperationName, Arg, ClientRowsContext<C$1, Hidden$1>>> } };
6011
+ //#endregion
6012
+ //#region src/cache/capability.d.ts
6013
+ declare const OFFICIAL_CACHE_NAME = "viborm.cache";
6014
+ /** The exact official query contribution. It is recognized by identity. */
6015
+ type OfficialCacheQueryContribution = OfficialGenericQueryHandler & {
6016
+ bind(thisArg: unknown): GenericQueryHandler;
6017
+ };
5911
6018
  /**
5912
- * Infer base type from a scalar for aggregates.
5913
- * Uses InferScalarOutput for correct DB result types.
6019
+ * A mutation's `cache` argument is the cache's declared control (ruling 7):
6020
+ * core removes and admits it before request handlers run, through the cache's
6021
+ * own parser, so a malformed value is still a `CacheConfigurationError`.
5914
6022
  */
5915
- type InferScalarBase<F$1> = F$1 extends Scalar ? InferScalarOutput<F$1> : never;
5916
- /** True when the scalar is a decimal, whose aggregates stay exact Decimals. */
5917
- type IsDecimalScalar<F$1> = ExtractScalarState<F$1> extends {
5918
- type: "decimal";
5919
- } ? true : false;
6023
+ type OfficialCacheControls = {
6024
+ readonly cache: {
6025
+ readonly schema: StandardSchemaV1<CacheInvalidationOptions>;
6026
+ readonly on: "writes";
6027
+ };
6028
+ };
6029
+ /** The official value accepted by the dedicated `$extends` overload. */
6030
+ type OfficialCacheExtension = {
6031
+ readonly name: typeof OFFICIAL_CACHE_NAME;
6032
+ readonly query: OfficialCacheQueryContribution;
6033
+ readonly controls: OfficialCacheControls;
6034
+ };
6035
+ //#endregion
6036
+ //#region src/client/omit.d.ts
6037
+ /** Fields a client hides by default, per model key of the schema. */
6038
+ type ClientOmitConfig<S$1 extends Record<string, AnyModel>> = { [K in keyof S$1]?: ClientModelOmit<S$1[K]> };
5920
6039
  /**
5921
- * Result type for aggregate operations
5922
- * Dynamically typed based on which aggregates are requested
5923
- *
5924
- * THE RULE, and it is the RESULT PARSER's rule, not a guess:
5925
- * `result-aggregate-parser.ts` marks `_sum` / `_min` / `_max` as `typed` and
5926
- * decodes them through the FIELD'S OWN scalar decoder, so those three come back
5927
- * spelled exactly like the column — `_sum` of an `s.bigInt()` is a `bigint`,
5928
- * `_sum` of an `s.decimal({ precision, scale })` is an exact `Decimal`
5929
- * (widened in precision, but still the field's scale). Only `_avg` takes the
5930
- * widen-to-number path, and even it stays a `Decimal` for a decimal, because an
5931
- * average of decimals is still a decimal — quantized to the field scale with
5932
- * round-half-to-even.
6040
+ * The scalars of `M` a client may hide — every scalar except the ones the
6041
+ * MODEL already hides for good (naming one of those has no `omit` key to name;
6042
+ * see `@validation/model/core/projection`).
5933
6043
  *
5934
- * `_sum` used to be typed `number` for everything but a decimal, which made
5935
- * `agg._sum.big * 2` type-check and then throw "Cannot mix BigInt and other
5936
- * types" — and, worse, `agg._sum.big === 150` silently false. The decoder is the
5937
- * half that is pinned behaviorally (tests/drivers/scalar-roundtrip-behavior.ts),
5938
- * so the type follows it.
6044
+ * The `any` arm is not decoration. A schema-generic extension sees
6045
+ * `Model<any>`, whose `scalars` is `any` — and the subtraction above would then
6046
+ * cancel to `never`, leaving `Partial<Record<never, true>>`, a config object
6047
+ * with no known properties. Answering `string` preserves the contextual
6048
+ * literal `true` until a concrete schema binds the official extension.
5939
6049
  */
5940
- type AggregateResultType<T$1 extends ModelShape, Args> = Prettify<SelectedFields<Args, { [K in keyof Args as K extends `_${string}` ? K : never]: K extends "_count" ? Args[K] extends boolean ? number : Args[K] extends object ? SelectedCountResult<Args[K]> : never : K extends "_sum" ? Args[K] extends object ? SelectedFields<Args[K], { [F in keyof Args[K]]: (F extends ScalarKeys$1<T$1> ? InferScalarBase<T$1[F]> : number) | null }> : never : K extends "_avg" ? Args[K] extends object ? SelectedFields<Args[K], { [F in keyof Args[K]]: (F extends ScalarKeys$1<T$1> ? IsDecimalScalar<T$1[F]> extends true ? Decimal : number : number) | null }> : never : K extends "_min" | "_max" ? Args[K] extends object ? SelectedFields<Args[K], { [F in keyof Args[K]]: F extends ScalarKeys$1<T$1> ? InferScalarBase<T$1[F]> | null : never }> : never : never }>>;
6050
+ type ProjectableKeysOf<M$1 extends AnyModel> = 0 extends 1 & M$1["~"]["state"]["scalars"] ? string : Extract<Exclude<keyof M$1["~"]["state"]["scalars"], M$1["~"]["state"]["omit"] extends Record<string, true> ? keyof M$1["~"]["state"]["omit"] : never>, string>;
5941
6051
  /**
5942
- * Result type for groupBy operations
5943
- * Includes the grouped-by fields plus any requested aggregates
6052
+ * The fields one model hides by default, each flagged `true`.
6053
+ *
6054
+ * `true` only — not `boolean`. Two reasons, and they are the same reason:
6055
+ * - a `false` here would be a key that does nothing (the resolver only ever
6056
+ * acts on `=== true`), and a config key that silently does nothing is the
6057
+ * shape this codebase refuses; per-field re-inclusion belongs on the QUERY
6058
+ * (`omit: { passwordHash: false }`), which is where it can be undone;
6059
+ * - `boolean` as the contextual type widens the `true` a caller writes, and a
6060
+ * widened flag is a flag the RESULT TYPE cannot resolve — it would render
6061
+ * `passwordHash?: string` on a client that hides the column outright.
5944
6062
  */
5945
- type GroupByResultType<T$1 extends ModelShape, Args> = Args extends {
5946
- by: infer B;
5947
- } ? Prettify<(B extends readonly (infer K)[] ? { [F in Extract<K, ScalarKeys$1<T$1> & keyof T$1>]: InferScalarBase<T$1[F]> } : B extends ScalarKeys$1<T$1> & keyof T$1 ? { [F in B]: InferScalarBase<T$1[F]> } : never) & AggregateResultType<T$1, Args>> : never;
6063
+ type ClientModelOmit<M$1 extends AnyModel> = Partial<Record<ProjectableKeysOf<M$1>, true>>;
6064
+ type ClientOmitKeys<Value> = Value extends unknown ? keyof Value : never;
6065
+ type ClientOmitEntry<Given, ModelName$1 extends PropertyKey> = Given extends unknown ? ModelName$1 extends keyof Given ? Given[ModelName$1] : never : never;
6066
+ /** Structural exactness for a direct client-default omit configuration. */
6067
+ type ExactClientOmitConfig<Given, S$1 extends Record<string, AnyModel>> = Record<Exclude<ClientOmitKeys<Given>, keyof S$1>, never> & { [ModelName in Extract<ClientOmitKeys<Given>, keyof S$1>]?: Record<Exclude<ClientOmitKeys<ClientOmitEntry<Given, ModelName>>, keyof ClientModelOmit<S$1[ModelName]>>, never> };
6068
+ //#endregion
6069
+ //#region src/client/default-omit-extension.d.ts
6070
+ declare const OFFICIAL_DEFAULT_OMIT_NAME = "viborm.defaultOmit";
6071
+ declare const officialDefaultOmitConfig: unique symbol;
6072
+ /** The authenticated request identity carrying one exact static omit witness. */
6073
+ type OfficialDefaultOmitRequestContribution<Config> = OfficialGenericRequestHandler & {
6074
+ readonly [officialDefaultOmitConfig]: Config;
6075
+ bind(thisArg: unknown): GenericRequestHandler;
6076
+ };
6077
+ /** The official value accepted by the dedicated `$extends` admission branch. */
6078
+ type OfficialDefaultOmitExtension<Config extends object = object> = {
6079
+ readonly name: typeof OFFICIAL_DEFAULT_OMIT_NAME;
6080
+ readonly request: OfficialDefaultOmitRequestContribution<Config>;
6081
+ };
6082
+ type DefaultOmitBinder<S$1 extends Schema$1> = <const Config extends ClientOmitConfig<S$1>>(config: Config & NoInfer<ExactClientOmitConfig<Config, S$1>>) => OfficialDefaultOmitExtension<Config & object>;
6083
+ /** Create VibORM's fixed-name schema-bound default-omit extension. */
6084
+ declare function defaultOmit<S$1 extends Schema$1>(): DefaultOmitBinder<S$1>;
5948
6085
  //#endregion
5949
6086
  //#region src/client/projected-types.d.ts
5950
6087
  /** The row operations a projection key reaches. */
@@ -6011,18 +6148,18 @@ type KeyResult<Entry, Asked> = Entry extends {
6011
6148
  type KeyMember<Node, Models$1 extends ProjectionModelsConstraint, Name$1 extends keyof Models$1, Key$1 extends string> = Key$1 extends keyof Spelled<Node> ? Spelled<Node>[Key$1] extends false | undefined ? unknown : { readonly [K in Key$1]: KeyResult<Models$1[Name$1]["evidence"], Spelled<Node>[Key$1]> } : unknown;
6012
6149
  type SpelledRelations<Node, Models$1 extends ProjectionModelsConstraint, Name$1 extends keyof Models$1> = Extract<keyof Spelled<Node>, keyof RelationsOf<Models$1, Name$1>>;
6013
6150
  /** Preserve a variant carrier and overlay its selected target document. */
6014
- type OverlayVariant<Result, Node, Models$1 extends ProjectionModelsConstraint, Links$2, Key$1 extends string> = Result extends readonly unknown[] ? { [Index in keyof Result]: OverlayVariant<Result[Index], Node extends {
6151
+ type OverlayVariant<Result$1, Node, Models$1 extends ProjectionModelsConstraint, Links$2, Key$1 extends string> = Result$1 extends readonly unknown[] ? { [Index in keyof Result$1]: OverlayVariant<Result$1[Index], Node extends {
6015
6152
  readonly variants?: infer Arms;
6016
- } ? Arms : undefined, Models$1, Links$2, Key$1> } : Result extends {
6153
+ } ? Arms : undefined, Models$1, Links$2, Key$1> } : Result$1 extends {
6017
6154
  readonly type: infer Variant;
6018
6155
  readonly data: unknown;
6019
- } ? { [P in keyof Result]: P extends "data" ? Variant extends keyof Node ? Overlay<Result[P], Node[Variant], Models$1, VariantName<Models$1, Links$2, Variant>, Key$1> : Result[P] : Result[P] } : Result;
6020
- type OverlayRelation<Result, Node, Models$1 extends ProjectionModelsConstraint, Name$1 extends keyof Models$1, Field$1, Key$1 extends string> = Field$1 extends keyof Models$1[Name$1]["relations"] ? Models$1[Name$1]["relations"][Field$1] extends infer Links ? [Links] extends [PropertyKey] ? Overlay<Result, Node, Models$1, Extract<Links, keyof Models$1>, Key$1> : OverlayVariant<Result, Node, Models$1, Links, Key$1> : never : Result;
6156
+ } ? { [P in keyof Result$1]: P extends "data" ? Variant extends keyof Node ? Overlay<Result$1[P], Node[Variant], Models$1, VariantName<Models$1, Links$2, Variant>, Key$1> : Result$1[P] : Result$1[P] } : Result$1;
6157
+ type OverlayRelation<Result$1, Node, Models$1 extends ProjectionModelsConstraint, Name$1 extends keyof Models$1, Field$1, Key$1 extends string> = Field$1 extends keyof Models$1[Name$1]["relations"] ? Models$1[Name$1]["relations"][Field$1] extends infer Links ? [Links] extends [PropertyKey] ? Overlay<Result$1, Node, Models$1, Extract<Links, keyof Models$1>, Key$1> : OverlayVariant<Result$1, Node, Models$1, Links, Key$1> : never : Result$1;
6021
6158
  type OverlayRow<Row$1, Node, Models$1 extends ProjectionModelsConstraint, Name$1 extends keyof Models$1, Key$1 extends string> = Prettify<{ [Field in keyof Row$1]: Field extends SpelledRelations<Node, Models$1, Name$1> ? Spelled<Node>[Field] extends object ? OverlayRelation<Row$1[Field], Spelled<Node>[Field], Models$1, Name$1, Field, Key$1> : Row$1[Field] : Row$1[Field] } & KeyMember<Node, Models$1, Name$1, Key$1>>;
6022
6159
  /** A result with the key's member added wherever the call spelled it. */
6023
- type Overlay<Result, Node, Models$1 extends ProjectionModelsConstraint, Name$1 extends keyof Models$1, Key$1 extends string> = Result extends readonly (infer Row)[] ? OverlayRow<Row, Node, Models$1, Name$1, Key$1>[] : Result extends object ? OverlayRow<Result, Node, Models$1, Name$1, Key$1> : Result;
6160
+ type Overlay<Result$1, Node, Models$1 extends ProjectionModelsConstraint, Name$1 extends keyof Models$1, Key$1 extends string> = Result$1 extends readonly (infer Row)[] ? OverlayRow<Row, Node, Models$1, Name$1, Key$1>[] : Result$1 extends object ? OverlayRow<Result$1, Node, Models$1, Name$1, Key$1> : Result$1;
6024
6161
  type ProjectedMethod<O$1 extends ProjectedOperation, C$1 extends VibORMConfig, ModelName$1 extends keyof ClientSchema<C$1>, ClientDefaults, Controls$1, Models$1 extends ProjectionModelsConstraint, Key$1 extends string, Pending extends boolean = true, M$1 extends Model$1<any> = ClientSchema<C$1>[ModelName$1], Payload = OperationPayload<O$1, M$1>, Placed = PlacedOperationControls<Controls$1, ModelName$1, O$1>> = <Arg extends ProjectedArgs<Exclude<Payload, undefined>, Models$1, ModelName$1, Key$1>>(args: Arg & WithControlArgs<NoExtraOperationKeys<O$1, WithoutKey<Arg, Key$1>, Exclude<Payload, undefined>, M$1, Placed>, Placed>) => ProjectedCarrier<Overlay<ContextualOperationResult<C$1, ModelName$1, O$1, WithoutKey<Arg, Key$1>, ClientDefaults>, Arg, Models$1, ModelName$1, Key$1>, Pending>;
6025
- type ProjectedCarrier<Result, Pending extends boolean> = Pending extends true ? PendingOperation<Result> : Promise<Result>;
6162
+ type ProjectedCarrier<Result$1, Pending extends boolean> = Pending extends true ? PendingOperation<Result$1> : Promise<Result$1>;
6026
6163
  /** Type-only projection facts retained when a cached view changes the carrier. */
6027
6164
  declare const projectedModelState: unique symbol;
6028
6165
  /**
@@ -6130,6 +6267,7 @@ interface ProjectedContribution<Contribution extends ExtensionStateConstraint, P
6130
6267
  readonly controls: Contribution["controls"];
6131
6268
  readonly rows: Contribution["rows"];
6132
6269
  readonly data: Contribution["data"];
6270
+ readonly result: Contribution["result"];
6133
6271
  }
6134
6272
  type ContributionOf<C$1 extends VibORMConfig, X$1 extends ExtensionStateConstraint, Definition$1, Contribution extends ExtensionStateConstraint = ExtensionStateContributionOf<Definition$1>> = DeclaresEvidence<C$1, Definition$1> extends false ? Contribution : ProjectedContribution<Contribution, ProjectedModelOperations<GatedConfig<C$1, Definition$1>, ClientRowsContext<GatedConfig<C$1, Definition$1>, X$1["rows"] | Contribution["rows"]>, X$1["controls"] & Contribution["controls"], Definition$1>>;
6135
6273
  type AppliedExtensionState<C$1 extends VibORMConfig, X$1 extends ExtensionStateConstraint, Definition$1> = Definition$1 extends OfficialCacheExtension ? EnableExtensionCache<X$1> : Definition$1 extends OfficialDefaultOmitExtension ? X$1 : AccumulatedExtensionState<X$1, ContributionOf<C$1, X$1, Definition$1>>;
@@ -6242,10 +6380,10 @@ interface VibORMClientMembers<C$1 extends VibORMConfig, X$1 extends ExtensionSta
6242
6380
  * Definitions append to the immutable chain; factories compose through the
6243
6381
  * same `$extends` method. Definition model keys are checked against this schema.
6244
6382
  */
6245
- $extends<Result = VibORMClient<C$1, X$1>>(factory: (client: NoInfer<VibORMClient<C$1, X$1>>) => Result & {
6383
+ $extends<Result$1 = VibORMClient<C$1, X$1>>(factory: (client: NoInfer<VibORMClient<C$1, X$1>>) => Result$1 & {
6246
6384
  readonly $schema: Schema$1;
6247
- }): Result;
6248
- $extends<const Definition$1 extends OfficialAwareDefinition<C$1, X$1, Definition$1>>(extension: Definition$1 & ExtensionAdmission<Definition$1, C$1, X$1> & (Definition$1 extends ((...args: never[]) => unknown) ? never : unknown)): VibORMClient<AppliedClientConfig<C$1, Definition$1>, AppliedExtensionState<C$1, X$1, Definition$1>>;
6385
+ }): Result$1;
6386
+ $extends<const Definition$1 extends OfficialAwareDefinition<C$1, X$1, Definition$1>, Fields$1 = unknown>(extension: Definition$1 & ExtensionAdmission<Definition$1, C$1, X$1> & (Definition$1 extends ((...args: never[]) => unknown) ? never : unknown) & ResultInference<C$1, X$1["result"], Fields$1>): VibORMClient<AppliedClientConfig<C$1, Definition$1>, AppliedExtensionState<C$1, X$1, Definition$1>>;
6249
6387
  }
6250
6388
  type ApplyClientExtensions<C$1 extends VibORMConfig, X$1 extends ExtensionStateConstraint, Definitions extends readonly unknown[]> = Definitions extends readonly [] ? VibORMClient<C$1, X$1> : Definitions extends readonly [infer Definition, ...infer RemainingDefinitions] ? Definition extends ((...args: never[]) => unknown) ? never : Definition extends OfficialAwareDefinition<C$1, X$1> ? Definition extends ExtensionAdmission<Definition, C$1, X$1> ? ApplyClientExtensions<AppliedClientConfig<C$1, Definition>, AppliedExtensionState<C$1, X$1, Definition>, RemainingDefinitions> : never : never : never;
6251
6389
  /**
@@ -11022,6 +11160,70 @@ type StampedOperation = "create" | "createMany" | "update" | "updateMany" | "ups
11022
11160
  * §7.5 and §7.1).
11023
11161
  */
11024
11162
  type StampedOperations<C$1 extends VibORMConfig, ClientDefaults, Controls$1, Data$1, K$1 extends keyof ClientSchema<C$1>> = { [O in StampedOperation]: Operation$1<O, ClientSchema<C$1>[K$1], ClientDefaultOmit<C$1, K$1>, ClientDefaults, PlacedOperationControls<Controls$1, K$1, O>, StampedPayload<O, OperationPayload<O, ClientSchema<C$1>[K$1]>, ClientSchema<C$1>[K$1], StampedFieldNames<Data$1, K$1>, Stamps<Data$1, ClientSchema<C$1>>>> };
11163
+ /**
11164
+ * The operations whose rows a chain's computed fields reach, and whose
11165
+ * `select` and `omit` name them.
11166
+ */
11167
+ type ComputedOperation = RowOperation | "createMany" | "updateMany" | "deleteMany";
11168
+ /** What a computed result type reads: the chain's fields and the schema. */
11169
+ interface ComputedResultContext<Result$1, S$1, ModelName$1> {
11170
+ readonly result: Result$1;
11171
+ readonly schema: S$1;
11172
+ readonly model: ModelName$1;
11173
+ }
11174
+ /**
11175
+ * One model's projecting operations on a client whose chain declares
11176
+ * `result`: `select` and `omit` also name the computed fields, and the rows
11177
+ * returned carry them, nested relation rows included. Only a chain with
11178
+ * `result` reaches this type, so every other client keeps its own
11179
+ * operation types untouched.
11180
+ */
11181
+ type ComputedOperations<C$1 extends VibORMConfig, ClientDefaults, Controls$1, Data$1, K$1 extends keyof ClientSchema<C$1>, Result$1> = { [O in ComputedOperation]: ComputedOperationMethod<O, ClientSchema<C$1>[K$1], ClientDefaultOmit<C$1, K$1>, ClientDefaults, PlacedOperationControls<Controls$1, K$1, O>, WithComputedKeys<O extends StampedOperation ? [Data$1] extends [never] ? OperationPayload<O, ClientSchema<C$1>[K$1]> : StampedPayload<O, OperationPayload<O, ClientSchema<C$1>[K$1]>, ClientSchema<C$1>[K$1], StampedFieldNames<Data$1, K$1>, Stamps<Data$1, ClientSchema<C$1>>> : OperationPayload<O, ClientSchema<C$1>[K$1]>, Extract<keyof ModelResultFields<Result$1, K$1>, string>>, ComputedResultContext<Result$1, ClientSchema<C$1>, K$1>> };
11182
+ type ComputedOperationMethod<O$1 extends Operations, M$1 extends Model$1<any>, DefaultOmit, ClientDefaults, Controls$1, Payload, Context> = undefined extends Payload ? <Arg extends Payload>(args?: WithControlArgs<NoExtraOperationKeys<O$1, Exclude<Arg, undefined>, Exclude<Payload, undefined>, M$1, Controls$1>, Controls$1>) => PendingOperation<WithComputedResult<OperationResultWithClientDefaults<O$1, M$1, Arg, DefaultOmit, ClientDefaults>, M$1, Arg, Context>> : <Arg extends Payload>(args: WithControlArgs<NoExtraOperationKeys<O$1, Arg, Payload, M$1, Controls$1>, Controls$1>) => PendingOperation<WithComputedResult<OperationResultWithClientDefaults<O$1, M$1, Arg, DefaultOmit, ClientDefaults>, M$1, Arg, Context>>;
11183
+ /** A payload whose `select` and `omit` also name the computed fields. */
11184
+ type WithComputedKeys<Payload, Names$1 extends string> = Payload extends object ? Omit<Payload, "select" | "omit"> & { [Key in Extract<keyof Payload, "select" | "omit">]?: (NonNullable<Payload[Key]> & { readonly [Name in Names$1]?: boolean }) | Extract<Payload[Key], undefined> } : Payload;
11185
+ /**
11186
+ * An operation's value with the computed fields added to each row: a list
11187
+ * item by item, `null` and `{ count }` as they are.
11188
+ */
11189
+ type WithComputedResult<Value, M$1, Args, Context> = Value extends readonly (infer Row)[] ? ComputedRow<Row, M$1, Args, Context>[] : Value extends null | BatchPayload ? Value : ComputedRow<Value, M$1, Args, Context>;
11190
+ /** The computed fields of one model: by name at the root, by surface below. */
11191
+ type ComputedFieldsFor<M$1, Context> = Context extends ComputedResultContext<infer Result, infer S, infer ModelName> ? [ModelName] extends [never] ? SurfaceNames<M$1, S> extends infer Names ? [Names] extends [never] ? Record<never, never> : OnlyName<Names> extends infer Name ? [Name] extends [never] ? AmbiguousReplacements<M$1, Result, Names> : ModelResultFields<Result, Name> : never : never : ModelResultFields<Result, ModelName> : never;
11192
+ /**
11193
+ * The fields of a row whose model shares its surface with another: only the
11194
+ * ones that replace a column, each typed as that column or any candidate's
11195
+ * computed value. A field that adds a key is left out, as the row may be of
11196
+ * a model without it.
11197
+ */
11198
+ type AmbiguousReplacements<M$1, Result$1, Names$1> = M$1 extends Model$1<infer State> ? { [Key in ReplacedColumns<Result$1, Names$1, State>]: (State["scalars"][Key] extends Scalar ? InferScalarOutput<State["scalars"][Key]> : never) | ComputedTypeAt<Result$1, Names$1, Key> } : never;
11199
+ type ReplacedColumns<Result$1, Names$1, State$1 extends ModelState> = Names$1 extends unknown ? Extract<keyof ModelResultFields<Result$1, Names$1>, keyof State$1["scalars"]> : never;
11200
+ type ComputedTypeAt<Result$1, Names$1, Key$1> = Names$1 extends unknown ? Key$1 extends keyof ModelResultFields<Result$1, Names$1> ? ModelResultFields<Result$1, Names$1>[Key$1] : never : never;
11201
+ /**
11202
+ * The schema's names whose model has `M`'s shallow surface. The public model
11203
+ * types carry no identity, so two models with the same scalar and relation
11204
+ * keys are indistinguishable here.
11205
+ */
11206
+ type SurfaceNames<M$1, S$1> = M$1 extends Model$1<any> ? { [K in keyof S$1]: S$1[K] extends Model$1<any> ? true extends SameModelResultSurface<ModelResultSurface<M$1>, ModelResultSurface<S$1[K]>> ? K : never : never }[keyof S$1] : never;
11207
+ /**
11208
+ * The one name, or `never` when none or several match: a nested row of a
11209
+ * model that shares its surface is typed with no added field rather than
11210
+ * with another model's (it carries its own at runtime).
11211
+ */
11212
+ type OnlyName<Names$1, All = Names$1> = [Names$1] extends [never] ? never : Names$1 extends unknown ? [All] extends [Names$1] ? Names$1 : never : never;
11213
+ /** The context one relation level down: the model is found by its surface. */
11214
+ type NestedComputedContext<Context> = Context extends ComputedResultContext<infer Result, infer S, unknown> ? ComputedResultContext<Result, S, never> : never;
11215
+ /** The computed fields one node's projection keeps; `omit` subtracts from both. */
11216
+ type KeptComputedFields<Fields$1, Args, Selection$1 = NodeSelect<Args>> = [Selection$1] extends [undefined] ? ApplyOmit<Fields$1, NodeOmit<Args>> : undefined extends Selection$1 ? Partial<Fields$1> : ApplyOmit<{ [K in keyof Selection$1 & keyof Fields$1 as Selection$1[K] extends true ? K : never]: Fields$1[K] } & { [K in keyof Selection$1 & keyof Fields$1 as Selection$1[K] extends true ? never : true extends Selection$1[K] ? K : never]?: Fields$1[K] }, NodeOmit<Args>>;
11217
+ /** The relations one node projects, with the node each one states. */
11218
+ type ProjectedRelations<Args> = [NodeSelect<Args>] extends [undefined] ? NodeInclude<Args> : NodeSelect<Args>;
11219
+ /**
11220
+ * One row of `M` with its computed fields, a field replacing a column it
11221
+ * shadows, and its projected relation rows rebuilt for their own models.
11222
+ * A recursive relation's deeper levels keep their columns' type only.
11223
+ */
11224
+ type ComputedRow<Row$1, M$1, Args, Context, Added = KeptComputedFields<ComputedFieldsFor<M$1, Context>, Args>, Relations = ProjectedRelations<Args>> = Row$1 extends unknown ? Prettify<Omit<Row$1, keyof Added | RebuiltRelationKeys<M$1, Relations>> & Added & { [Key in RebuiltRelationKeys<M$1, Relations> & keyof Row$1]: WithComputedResult<Row$1[Key], RelationTarget<M$1, Key>, Relations[Key & keyof Relations] extends true ? undefined : Relations[Key & keyof Relations], NestedComputedContext<Context>> }> : never;
11225
+ /** The relation keys of a projection whose rows are rebuilt. */
11226
+ type RebuiltRelationKeys<M$1, Relations> = Relations extends object ? { [Key in keyof Relations]: [RelationTarget<M$1, Key>] extends [never] ? never : Relations[Key] extends true | object ? Key : never }[keyof Relations] : never;
11025
11227
  /**
11026
11228
  * The call's own clauses, rebuilt: a create's rows, and an update's for the
11027
11229
  * creates they nest.
@@ -11535,7 +11737,7 @@ type NoExtraOperationKeys<O$1 extends Operations, Arg, Payload, M$1 extends Mode
11535
11737
  * not batchable.
11536
11738
  */
11537
11739
  type OperationMethod<O$1 extends Operations, M$1 extends Model$1<any>, DefaultOmit, ClientDefaults, Controls$1, Payload, Pending extends boolean> = undefined extends Payload ? <Arg extends Payload>(args?: WithControlArgs<NoExtraOperationKeys<O$1, Exclude<Arg, undefined>, Exclude<Payload, undefined>, M$1, Controls$1>, Controls$1>) => OperationCarrier<OperationResultWithClientDefaults<O$1, M$1, Arg, DefaultOmit, ClientDefaults>, Pending> : <Arg extends Payload>(args: WithControlArgs<NoExtraOperationKeys<O$1, Arg, Payload, M$1, Controls$1>, Controls$1>) => OperationCarrier<OperationResultWithClientDefaults<O$1, M$1, Arg, DefaultOmit, ClientDefaults>, Pending>;
11538
- type OperationCarrier<Result, Pending extends boolean> = Pending extends true ? PendingOperation<Result> : Promise<Result>;
11740
+ type OperationCarrier<Result$1, Pending extends boolean> = Pending extends true ? PendingOperation<Result$1> : Promise<Result$1>;
11539
11741
  type Operation$1<O$1 extends Operations, M$1 extends Model$1<any>, DefaultOmit = undefined, ClientDefaults = never, Controls$1 = NoControls, Payload = OperationPayload<O$1, M$1>> = OperationMethod<O$1, M$1, DefaultOmit, ClientDefaults, Controls$1, Payload, true>;
11540
11742
  type CachedOperation<O$1 extends Operations, M$1 extends Model$1<any>, DefaultOmit = undefined, ClientDefaults = never, Controls$1 = NoControls> = OperationMethod<O$1, M$1, DefaultOmit, ClientDefaults, Controls$1, OperationPayload<O$1, M$1>, false>;
11541
11743
  /**
@@ -11691,11 +11893,11 @@ interface DriverResultParser {
11691
11893
  * the trusted observer and starts the executor inside its span.
11692
11894
  */
11693
11895
  interface OfficialStatementExecutionGate {
11694
- execute<Result>(execution: StatementExecution, executor: () => Promise<Result>): Promise<Result>;
11896
+ execute<Result$1>(execution: StatementExecution, executor: () => Promise<Result$1>): Promise<Result$1>;
11695
11897
  }
11696
11898
  /** @internal One driver lifecycle dispatch, gated the same way. */
11697
11899
  interface OfficialDriverLifecycleExecutionGate {
11698
- execute<Result>(executor: () => Promise<Result>): Promise<Result>;
11900
+ execute<Result$1>(executor: () => Promise<Result$1>): Promise<Result$1>;
11699
11901
  }
11700
11902
  /**
11701
11903
  * Abstract base class for drivers with lazy client initialization.
@@ -11834,13 +12036,13 @@ declare abstract class DriverInstrumentationBase<TClient, TTransaction> {
11834
12036
  /** Whether trusted provenance carries at least one protected observer. */
11835
12037
  protected hasTrustedObservers(context: QueryExecutionContext | undefined): boolean;
11836
12038
  /** Observe one physical statement without exposing SQL or provider state. */
11837
- protected observeTrustedStatement<Result>(context: QueryExecutionContext, child: (gate: OfficialStatementExecutionGate | undefined) => Promise<Result>, readCompletionFacts?: ObservationCompletionFactsReader): Promise<Result>;
12039
+ protected observeTrustedStatement<Result$1>(context: QueryExecutionContext, child: (gate: OfficialStatementExecutionGate | undefined) => Promise<Result$1>, readCompletionFacts?: ObservationCompletionFactsReader): Promise<Result$1>;
11838
12040
  /** Observe one driver-owned lifecycle boundary without exposing its state. */
11839
- protected observeTrustedDriverLifecycle<Result>(kind: Extract<LifecycleUnitKind, "connection" | "savepoint" | "transaction">, context: QueryExecutionContext, boundary: LifecycleBoundary, child: (gate: OfficialDriverLifecycleExecutionGate | undefined) => Promise<Result>, readCompletionFacts?: ObservationCompletionFactsReader): Promise<Result>;
12041
+ protected observeTrustedDriverLifecycle<Result$1>(kind: Extract<LifecycleUnitKind, "connection" | "savepoint" | "transaction">, context: QueryExecutionContext, boundary: LifecycleBoundary, child: (gate: OfficialDriverLifecycleExecutionGate | undefined) => Promise<Result$1>, readCompletionFacts?: ObservationCompletionFactsReader): Promise<Result$1>;
11840
12042
  /** Apply a deferred transform to an internally prepared typed statement. */
11841
12043
  protected materializeTrustedBatchQuery(query: BatchQuery, context: QueryExecutionContext): BatchQuery;
11842
12044
  /** Form one protected statement onion around one native typed batch call. */
11843
- protected observeTrustedBatchStatements<Result>(queries: readonly BatchQuery[], context: QueryExecutionContext, child: (queries: readonly BatchQuery[], gate: OfficialStatementExecutionGate | undefined) => Promise<Result>, readCompletionFacts?: ObservationCompletionFactsReader): Promise<Result>;
12045
+ protected observeTrustedBatchStatements<Result$1>(queries: readonly BatchQuery[], context: QueryExecutionContext, child: (queries: readonly BatchQuery[], gate: OfficialStatementExecutionGate | undefined) => Promise<Result$1>, readCompletionFacts?: ObservationCompletionFactsReader): Promise<Result$1>;
11844
12046
  /** Build one private provider-dispatch gate for the official statement rail. */
11845
12047
  private createOfficialStatementExecutionGate;
11846
12048
  /** Build one late dispatch gate without moving the lifecycle across its queue. */
@@ -11928,7 +12130,7 @@ declare abstract class DriverTransactionBase<TClient, TTransaction> extends Driv
11928
12130
  /** One typed (or, for `_executeRaw`, raw) provider call, normalized. */
11929
12131
  private executeNormalizedProvider;
11930
12132
  /** The one typed statement lifecycle, shared by public and internal transport. */
11931
- protected executeTypedStatement<Result>(query: Sql, context: QueryExecutionContext | undefined, executeProvider: (client: TClient | TTransaction, sql: string, executionParams: unknown[], executionContext: QueryExecutionContext) => Promise<Result>): Promise<Result>;
12133
+ protected executeTypedStatement<Result$1>(query: Sql, context: QueryExecutionContext | undefined, executeProvider: (client: TClient | TTransaction, sql: string, executionParams: unknown[], executionContext: QueryExecutionContext) => Promise<Result$1>): Promise<Result$1>;
11932
12134
  /**
11933
12135
  * One statement's dispatch: observed when a trusted observer wants it, and
11934
12136
  * queued behind the connection's owner on a single-connection driver.
@@ -12798,7 +13000,10 @@ interface DatabaseAdapter {
12798
13000
  emptyArray: () => Sql;
12799
13001
  /**
12800
13002
  * Aggregate rows into a JSON array. An empty aggregate is the empty array,
12801
- * never SQL NULL, so no caller wraps it in its own COALESCE.
13003
+ * never SQL NULL, so no caller wraps it in its own COALESCE. `expr` is a
13004
+ * JSON value as built here (`object`, `array`): one read back through a
13005
+ * subquery column goes through `document` first, which SQLite needs to
13006
+ * keep it a JSON value rather than a quoted string.
12802
13007
  */
12803
13008
  agg: (expr: Sql) => Sql;
12804
13009
  /** Build JSON object from explicit column list (works on all databases) */
@@ -12881,6 +13086,14 @@ interface DatabaseAdapter {
12881
13086
  * element type to spell at all.
12882
13087
  */
12883
13088
  enumValue: (values: unknown[]) => Sql;
13089
+ /**
13090
+ * The values a one-column `query` answers, as one array, empty where it
13091
+ * answers none (PostgreSQL `ARRAY(…)`). A row tests a key set held this
13092
+ * way by {@link has} rather than by joining it: the array is computed once
13093
+ * per statement, where a joined set is read again for each row of a
13094
+ * correlated subquery. Absent where the dialect has no array value.
13095
+ */
13096
+ ofRows?: (query: Sql) => Sql;
12884
13097
  /** Check if array contains value */
12885
13098
  has: (column: Sql, value: Sql) => Sql;
12886
13099
  /** Check if array contains all values */
@@ -13035,10 +13248,21 @@ interface DatabaseAdapter {
13035
13248
  * Common Table Expressions
13036
13249
  */
13037
13250
  cte: {
13038
- /** Build WITH clause: WITH name AS (query), ... */
13251
+ /**
13252
+ * Build WITH clause: WITH name AS (query), ... A member `inlined` is read
13253
+ * correlated to each outer row through its own columns: PostgreSQL would
13254
+ * materialize a member read twice and scan it, without an index, once
13255
+ * per row, so it is written `NOT MATERIALIZED` there. A member
13256
+ * `inlined: false` is computed once: SQLite would inline it at every
13257
+ * use, so it is written `MATERIALIZED` there. Without `inlined`, the
13258
+ * database decides. A `recursive` member's query is its two terms,
13259
+ * `anchor UNION recursive`, and makes the clause `WITH RECURSIVE`.
13260
+ */
13039
13261
  with: (definitions: {
13040
13262
  name: string;
13041
13263
  query: Sql;
13264
+ inlined?: boolean;
13265
+ recursive?: boolean;
13042
13266
  }[]) => Sql;
13043
13267
  /**
13044
13268
  * Build recursive CTE: WITH RECURSIVE name AS (anchor UNION ALL recursive).
@@ -13391,6 +13615,8 @@ declare class MySQLAdapter implements DatabaseAdapter {
13391
13615
  with: (definitions: {
13392
13616
  name: string;
13393
13617
  query: Sql;
13618
+ inlined?: boolean;
13619
+ recursive?: boolean;
13394
13620
  }[]) => Sql;
13395
13621
  recursive: (name: string, anchor: Sql, recursive: Sql, union?: "all" | "distinct") => Sql;
13396
13622
  };
@@ -13448,6 +13674,8 @@ declare class MySQLAdapter implements DatabaseAdapter {
13448
13674
  supportsMutationTargetInSubquery: boolean;
13449
13675
  supportsMutationRowLimit: boolean;
13450
13676
  supportsRowLocks: boolean;
13677
+ locksMissingKeys: boolean;
13678
+ boundsRecursionIterations: boolean;
13451
13679
  };
13452
13680
  lastInsertId: () => Sql;
13453
13681
  vector: {
@@ -13575,6 +13803,7 @@ declare class PostgresAdapter implements DatabaseAdapter {
13575
13803
  literal: (items: Sql[]) => Sql;
13576
13804
  value: (values: unknown[], temporal?: "date" | "datetime") => Sql;
13577
13805
  enumValue: (values: unknown[]) => Sql;
13806
+ ofRows: (query: Sql) => Sql;
13578
13807
  has: (column: Sql, value: Sql) => Sql;
13579
13808
  hasEvery: (column: Sql, values: Sql) => Sql;
13580
13809
  hasSome: (column: Sql, values: Sql) => Sql;
@@ -13628,6 +13857,8 @@ declare class PostgresAdapter implements DatabaseAdapter {
13628
13857
  with: (definitions: {
13629
13858
  name: string;
13630
13859
  query: Sql;
13860
+ inlined?: boolean;
13861
+ recursive?: boolean;
13631
13862
  }[]) => Sql;
13632
13863
  recursive: (name: string, anchor: Sql, recursive: Sql, union?: "all" | "distinct") => Sql;
13633
13864
  };
@@ -13742,6 +13973,19 @@ interface SQLiteAdapterOptions {
13742
13973
  * to `false`.
13743
13974
  */
13744
13975
  readonly sharedRelationBodies?: boolean;
13976
+ /**
13977
+ * The most terms one compound `SELECT` may chain
13978
+ * (`capabilities.compoundSelectTerms`): Cloudflare D1 compiles SQLite with
13979
+ * 5 and refuses a sixth ("too many terms in compound SELECT"). Defaults to
13980
+ * SQLite's own bound, which the engine never reaches.
13981
+ */
13982
+ readonly compoundSelectTerms?: number;
13983
+ /**
13984
+ * Where bodies are shared, the relations a statement may reference before
13985
+ * its repeated walks become reaching sets and its rows join the key sets
13986
+ * they test (`capabilities.relationsPerStatement`). Absent: unbounded.
13987
+ */
13988
+ readonly relationsPerStatement?: number;
13745
13989
  }
13746
13990
  declare function sqliteJsonEquals(left: Sql, right: Sql): Sql;
13747
13991
  declare class SQLiteAdapter implements DatabaseAdapter {
@@ -13749,7 +13993,9 @@ declare class SQLiteAdapter implements DatabaseAdapter {
13749
13993
  constructor({
13750
13994
  temporaryObjects,
13751
13995
  deepExpressions,
13752
- sharedRelationBodies
13996
+ sharedRelationBodies,
13997
+ compoundSelectTerms,
13998
+ relationsPerStatement
13753
13999
  }?: SQLiteAdapterOptions);
13754
14000
  raw: (sqlString: string) => Sql;
13755
14001
  identifiers: {
@@ -13917,6 +14163,8 @@ declare class SQLiteAdapter implements DatabaseAdapter {
13917
14163
  with: (definitions: {
13918
14164
  name: string;
13919
14165
  query: Sql;
14166
+ inlined?: boolean;
14167
+ recursive?: boolean;
13920
14168
  }[]) => Sql;
13921
14169
  recursive: (name: string, anchor: Sql, recursive: Sql, union?: "all" | "distinct") => Sql;
13922
14170
  };
@@ -13979,4 +14227,4 @@ declare const mysqlAdapter: MySQLAdapter;
13979
14227
  declare const postgresAdapter: PostgresAdapter;
13980
14228
  declare const sqliteAdapter: SQLiteAdapter;
13981
14229
  //#endregion
13982
- export { ModelOperationInput as $, AutoGenerate as $n, ValidationErrorSource as $r, AccumulatedExtensionState as $t, Schema$1 as A, CacheConfigurationError as Ai, BatchQuery as An, BaseBlobSchema as Ar, DriverConfig as At, VariantToOneRelation as B, wrapError as Bi, ModelFieldRefs as Bn, JsonNull as Br, CountResultType as Bt, Client as C, UniqueConstraintError as Ci, WaitUntilFn as Cn, IsoDateSchema as Cr, s as Ct, OperationPayloadSchema as D, isNotNullConstraintError as Di, BatchTransactionOptions as Dn, EnumSchema as Dr, renderSchemaType as Dt, OperationPayload as E, isForeignKeyError as Ei, sqliteResultParser as En, BaseEnumSchema as Er, renderOperationResultType as Et, LinkedClientConfig as F, VibORMError as Fi, V$1 as Fn, toJsonSchema as Fr, VibORMClient as Ft, ParseResult as G, GeoPolygon as Gi, IndexOptions as Gn, inferred as Gr, DefinitionControls as Gt, BigIntScalar as H, GeoArea as Hi, isFieldRef as Hn, JsonNullSentinel as Hr, InferSelectInclude as Ht, Links$1 as I, VibORMErrorCode as Ii, v as In, createSchemaRegistry as Ir, VibORMConfig as It, SchemaRegistryOperation as J, MYSQL as Ji, Model$1 as Jn, JunctionReferentialAction as Jr, RowsVerbs as Jt, Prettify as K, DecimalDescriptor as Ki, IndexType as Kn, AnyRelation as Kr, NoControls as Kt, RelationLinks as L, isRetryableError as Li, StringSchema as Ln, AnyJsonNullSentinel as Lr, createClient as Lt, ClientSchema as M, CacheInvalidTTLError as Mi, Dialect as Mn, BaseBigIntSchema as Mr, ExtendedOperationResult as Mt, FlatSchema as N, CacheOperationNotCacheableError as Ni, QueryExecutionContext as Nn, BigIntSchema as Nr, ExtensionState as Nt, OperationResult as O, isUniqueConstraintError as Oi, DriverTransactionOptions as On, BaseBooleanSchema as Or, validateOperationPayload as Ot, Linked as P, PrismaErrorCode as Pi, QueryResult as Pn, createJsonSchemaConverter as Pr, NoExtraDriverConfigKeys as Pt, ModelCoreSchemas as Q, SQLITE as Qi, DecimalSchema as Qn, ValidationError as Qr, StatementHandler as Qt, ModelShape as R, isVibORMError as Ri, AnyFieldRef as Rn, AnyNull as Rr, AggregateResultType as Rt, CachedClient as S, NotNullConstraintError as Si, CacheSetOptions as Sn, BaseIsoTimestampSchema as Sr, ModelToManyRelation as St, MutationOperations as T, isCheckConstraintError as Ti, WithCacheOptions as Tn, IsoTimestampSchema as Tr, getOperationPayloadSchema as Tt, InferInput as U, GeoBounds as Ui, AnyModel as Un, isJsonNullSentinel as Ur, defaultOmit as Ut, type Scalar as V, DiagnosticDisclosure as Vi, createModelFieldRefs as Vn, JsonNullKind as Vr, GroupByResultType as Vt, InferOutput as W, GeoPoint as Wi, IndexDefinition as Wn, JsonSchema$1 as Wr, OfficialCacheExtension as Wt, ModelArgsSchemas as X, NativeTypeMap as Xi, ModelState as Xn, RelationCardinality as Xr, defineExtension as Xt, VibSchema as Y, NativeType as Yi, ModelInternal as Yn, ReferentialAction as Yr, ClientExtension as Yt, ModelCoreInput as Z, PG as Zi, UpdateState as Zn, RelationSlot as Zr, StatementContext as Zt, ObservationCompletion as _, isUnsupportedOperationError as _i, UnwrapPendingOperation as _n, InputJsonValue as _r, DateScalar as _t, PostgresAdapter as a, FeatureNotSupportedError as ai, MergeExtensionState as an, UpdateState$1 as ar, CoreSchemas as at, OFFICIAL_INSTRUMENTATION_NAME as b, CheckConstraintError as bi, CacheDriver as bn, BaseIsoDateSchema as br, ModelToOneRelation as bt, Operation as c, NestedWriteError as ci, validateSchemaOrThrow as cn, VectorSchema as cr, StringScalar as ct, MigrationSessionAttestation as d, QueryEngineError as di, SchemaValidationIssue as dn, ObjectSchema as dr, JsonScalar as dt, isValidationError as ei, ClientExtensionState as en, AutoGenerateType as er, ModelRelationNestedInput as et, SQLITE_MIGRATION_CAPABILITY as f, QueryError as fi, Severity as fn, BaseIntegerSchema as fr, IntScalar as ft, MigrationNamespaceAttestation as g, isPendingOperationError as gi, PendingOperation as gn, BaseJsonSchema as gr, DateTimeScalar as gt, DriverResultParser as h, isNotFoundError as hi, Schema$3 as hn, NumberSchema as hr, TimeScalar as ht, SQLiteAdapter as i, ConnectionError as ii, ExtensionResultConsumerState as in, ScalarType as ir, ArgsSchemas as it, ValidatedOperationPayload as j, CacheInvalidKeyError as ji, CommittedBatchNotification as jn, BlobSchema as jr, ExtendedClient as jt, Operations as k, isValueTooLongError as ki, TransactionOptionSupport as kn, BooleanSchema as kr, ClientTypeState as kt, AnyDriver as l, NotFoundError as li, SchemaValidationError as ln, BasePointSchema as lr, PointScalar as lt, PinnedSessionReservation as m, isClientInitializationError as mi, DateTimePhysicalForm as mn, IntegerSchema as mr, DecimalScalar as mt, postgresAdapter as n, TransactionError as ni, ExtensionCacheState as nn, InitialScalarState as nr, ModelStateSchemas as nt, MySQLAdapter as o, ForbiddenError as oi, RawOperation as on, parse as or, NumericScalar as ot, SqliteMigrationCapability as p, UnsupportedOperationError as pi, ValidationResult$1 as pn, BaseNumberSchema as pr, EnumScalar as pt, SchemaRegistryLookup as q, Decimal as qi, InitialModelState as qn, Getter as qr, PlacedControl as qt, sqliteAdapter as r, ClientInitializationError as ri, ExtensionContributionState as rn, ScalarState as rr, ScalarSchemas as rt, DatabaseAdapter as s, NestedWriteAssertionError as si, validateSchema as sn, BaseVectorSchema as sr, VectorScalar as st, mysqlAdapter as t, InvalidTransactionInputError as ti, EmptyClientExtensionState as tn, GeneratorDefaultBrand as tr, ModelSchemas as tt, Driver as u, PendingOperationError as ui, isSchemaValidationError as un, PointSchema as ur, NumberScalar as ut, ObservationUnit as v, MigrationError as vi, UnwrapPendingOperations as vn, JsonSchema as vr, BooleanScalar as vt, InferDatabase as w, ValueTooLongError as wi, CacheInvalidationOptions as wn, IsoTimeSchema as wr, getSchemas as wt, CacheableOperations as x, ForeignKeyError as xi, CacheEntry as xn, BaseIsoTimeSchema as xr, ReferencesStage as xt, ObserveHandler as y, isMigrationError as yi, isPendingOperation as yn, JsonValue as yr, BlobScalar as yt, VariantToManyRelation as z, toPrismaErrorCode as zi, FieldRef as zn, DbNull as zr, BatchPayload as zt };
14230
+ export { ModelOperationInput as $, AutoGenerate as $n, ValidationErrorSource as $r, ExtensionResultConsumerState as $t, Schema$1 as A, CacheConfigurationError as Ai, BatchQuery as An, BaseBlobSchema as Ar, DriverConfig as At, VariantToOneRelation as B, wrapError as Bi, ModelFieldRefs as Bn, JsonNull as Br, DefinitionControls as Bt, Client as C, UniqueConstraintError as Ci, WaitUntilFn as Cn, IsoDateSchema as Cr, s as Ct, OperationPayloadSchema as D, isNotNullConstraintError as Di, BatchTransactionOptions as Dn, EnumSchema as Dr, renderSchemaType as Dt, OperationPayload as E, isForeignKeyError as Ei, sqliteResultParser as En, BaseEnumSchema as Er, renderOperationResultType as Et, LinkedClientConfig as F, VibORMError as Fi, V$1 as Fn, toJsonSchema as Fr, VibORMClient as Ft, ParseResult as G, GeoPolygon as Gi, IndexOptions as Gn, inferred as Gr, defineExtension as Gt, BigIntScalar as H, GeoArea as Hi, isFieldRef as Hn, JsonNullSentinel as Hr, PlacedControl as Ht, Links$1 as I, VibORMErrorCode as Ii, v as In, createSchemaRegistry as Ir, VibORMConfig as It, SchemaRegistryOperation as J, MYSQL as Ji, Model$1 as Jn, JunctionReferentialAction as Jr, AccumulatedExtensionState as Jt, Prettify as K, DecimalDescriptor as Ki, IndexType as Kn, AnyRelation as Kr, StatementContext as Kt, RelationLinks as L, isRetryableError as Li, StringSchema as Ln, AnyJsonNullSentinel as Lr, createClient as Lt, ClientSchema as M, CacheInvalidTTLError as Mi, Dialect as Mn, BaseBigIntSchema as Mr, ExtendedOperationResult as Mt, FlatSchema as N, CacheOperationNotCacheableError as Ni, QueryExecutionContext as Nn, BigIntSchema as Nr, ExtensionState as Nt, OperationResult as O, isUniqueConstraintError as Oi, DriverTransactionOptions as On, BaseBooleanSchema as Or, validateOperationPayload as Ot, Linked as P, PrismaErrorCode as Pi, QueryResult as Pn, createJsonSchemaConverter as Pr, NoExtraDriverConfigKeys as Pt, ModelCoreSchemas as Q, SQLITE as Qi, DecimalSchema as Qn, ValidationError as Qr, ExtensionContributionState as Qt, ModelShape as R, isVibORMError as Ri, AnyFieldRef as Rn, AnyNull as Rr, defaultOmit as Rt, CachedClient as S, NotNullConstraintError as Si, CacheSetOptions as Sn, BaseIsoTimestampSchema as Sr, ModelToManyRelation as St, MutationOperations as T, isCheckConstraintError as Ti, WithCacheOptions as Tn, IsoTimestampSchema as Tr, getOperationPayloadSchema as Tt, InferInput as U, GeoBounds as Ui, AnyModel as Un, isJsonNullSentinel as Ur, RowsVerbs as Ut, type Scalar as V, DiagnosticDisclosure as Vi, createModelFieldRefs as Vn, JsonNullKind as Vr, NoControls as Vt, InferOutput as W, GeoPoint as Wi, IndexDefinition as Wn, JsonSchema$1 as Wr, ClientExtension as Wt, ModelArgsSchemas as X, NativeTypeMap as Xi, ModelState as Xn, RelationCardinality as Xr, EmptyClientExtensionState as Xt, VibSchema as Y, NativeType as Yi, ModelInternal as Yn, ReferentialAction as Yr, ClientExtensionState as Yt, ModelCoreInput as Z, PG as Zi, UpdateState as Zn, RelationSlot as Zr, ExtensionCacheState as Zt, ObservationCompletion as _, isUnsupportedOperationError as _i, UnwrapPendingOperation as _n, InputJsonValue as _r, DateScalar as _t, PostgresAdapter as a, FeatureNotSupportedError as ai, InferSelectInclude as an, UpdateState$1 as ar, CoreSchemas as at, OFFICIAL_INSTRUMENTATION_NAME as b, CheckConstraintError as bi, CacheDriver as bn, BaseIsoDateSchema as br, ModelToOneRelation as bt, Operation as c, NestedWriteError as ci, validateSchemaOrThrow as cn, VectorSchema as cr, StringScalar as ct, MigrationSessionAttestation as d, QueryEngineError as di, SchemaValidationIssue as dn, ObjectSchema as dr, JsonScalar as dt, isValidationError as ei, MergeExtensionState as en, AutoGenerateType as er, ModelRelationNestedInput as et, SQLITE_MIGRATION_CAPABILITY as f, QueryError as fi, Severity as fn, BaseIntegerSchema as fr, IntScalar as ft, MigrationNamespaceAttestation as g, isPendingOperationError as gi, PendingOperation as gn, BaseJsonSchema as gr, DateTimeScalar as gt, DriverResultParser as h, isNotFoundError as hi, Schema$3 as hn, NumberSchema as hr, TimeScalar as ht, SQLiteAdapter as i, ConnectionError as ii, GroupByResultType as in, ScalarType as ir, ArgsSchemas as it, ValidatedOperationPayload as j, CacheInvalidKeyError as ji, CommittedBatchNotification as jn, BlobSchema as jr, ExtendedClient as jt, Operations as k, isValueTooLongError as ki, TransactionOptionSupport as kn, BooleanSchema as kr, ClientTypeState as kt, AnyDriver as l, NotFoundError as li, SchemaValidationError as ln, BasePointSchema as lr, PointScalar as lt, PinnedSessionReservation as m, isClientInitializationError as mi, DateTimePhysicalForm as mn, IntegerSchema as mr, DecimalScalar as mt, postgresAdapter as n, TransactionError as ni, BatchPayload as nn, InitialScalarState as nr, ModelStateSchemas as nt, MySQLAdapter as o, ForbiddenError as oi, RawOperation as on, parse as or, NumericScalar as ot, SqliteMigrationCapability as p, UnsupportedOperationError as pi, ValidationResult$1 as pn, BaseNumberSchema as pr, EnumScalar as pt, SchemaRegistryLookup as q, Decimal as qi, InitialModelState as qn, Getter as qr, StatementHandler as qt, sqliteAdapter as r, ClientInitializationError as ri, CountResultType as rn, ScalarState as rr, ScalarSchemas as rt, DatabaseAdapter as s, NestedWriteAssertionError as si, validateSchema as sn, BaseVectorSchema as sr, VectorScalar as st, mysqlAdapter as t, InvalidTransactionInputError as ti, AggregateResultType as tn, GeneratorDefaultBrand as tr, ModelSchemas as tt, Driver as u, PendingOperationError as ui, isSchemaValidationError as un, PointSchema as ur, NumberScalar as ut, ObservationUnit as v, MigrationError as vi, UnwrapPendingOperations as vn, JsonSchema as vr, BooleanScalar as vt, InferDatabase as w, ValueTooLongError as wi, CacheInvalidationOptions as wn, IsoTimeSchema as wr, getSchemas as wt, CacheableOperations as x, ForeignKeyError as xi, CacheEntry as xn, BaseIsoTimeSchema as xr, ReferencesStage as xt, ObserveHandler as y, isMigrationError as yi, isPendingOperation as yn, JsonValue as yr, BlobScalar as yt, VariantToManyRelation as z, toPrismaErrorCode as zi, FieldRef as zn, DbNull as zr, OfficialCacheExtension as zt };