@madarco/agentbox 0.27.1 → 0.28.0-nightly.202607251721

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 (364) hide show
  1. package/CHANGELOG.md +87 -4
  2. package/README.md +7 -3
  3. package/dist/_cloud-attach-XZYF324R.js +26 -0
  4. package/dist/admin-client-NOZ5CCAH.js +15 -0
  5. package/dist/chunk-2VW37PW4.js +1694 -0
  6. package/dist/chunk-2VW37PW4.js.map +1 -0
  7. package/dist/{chunk-HR7NHH5J.js → chunk-3UMM4VJH.js} +808 -57
  8. package/dist/chunk-3UMM4VJH.js.map +1 -0
  9. package/dist/chunk-5U5QOFL5.js +20 -0
  10. package/dist/chunk-5U5QOFL5.js.map +1 -0
  11. package/dist/chunk-6P6D77QP.js +285 -0
  12. package/dist/chunk-6P6D77QP.js.map +1 -0
  13. package/dist/chunk-6V366IZC.js +2892 -0
  14. package/dist/chunk-6V366IZC.js.map +1 -0
  15. package/dist/{chunk-KWOEUFVA.js → chunk-7J6G526Q.js} +6 -14
  16. package/dist/{chunk-KWOEUFVA.js.map → chunk-7J6G526Q.js.map} +1 -1
  17. package/dist/{chunk-IDH5A4RR.js → chunk-AYPAYY5R.js} +17 -4
  18. package/dist/chunk-AYPAYY5R.js.map +1 -0
  19. package/dist/{chunk-JGZSA5ZI.js → chunk-BHJCMTHP.js} +58 -15
  20. package/dist/chunk-BHJCMTHP.js.map +1 -0
  21. package/dist/{chunk-26IKZRTT.js → chunk-BLWAWGFX.js} +297 -1217
  22. package/dist/chunk-BLWAWGFX.js.map +1 -0
  23. package/dist/chunk-CGPUFXET.js +95 -0
  24. package/dist/chunk-CGPUFXET.js.map +1 -0
  25. package/dist/{chunk-SJ75AIA2.js → chunk-D6AODRNA.js} +12 -9
  26. package/dist/{chunk-SJ75AIA2.js.map → chunk-D6AODRNA.js.map} +1 -1
  27. package/dist/chunk-DPJMEG7U.js +11 -0
  28. package/dist/chunk-DPJMEG7U.js.map +1 -0
  29. package/dist/chunk-E2ITEZAQ.js +148 -0
  30. package/dist/chunk-E2ITEZAQ.js.map +1 -0
  31. package/dist/{chunk-JE6UI5YR.js → chunk-NKVCIH6N.js} +89 -223
  32. package/dist/chunk-NKVCIH6N.js.map +1 -0
  33. package/dist/chunk-OEYAVBA6.js +120 -0
  34. package/dist/chunk-OEYAVBA6.js.map +1 -0
  35. package/dist/{chunk-UJEH2NJT.js → chunk-PXYPQ5BO.js} +64 -264
  36. package/dist/chunk-PXYPQ5BO.js.map +1 -0
  37. package/dist/chunk-QESXSSO6.js +670 -0
  38. package/dist/chunk-QESXSSO6.js.map +1 -0
  39. package/dist/{chunk-NEF6MDJO.js → chunk-QJCK2AFX.js} +128 -26
  40. package/dist/chunk-QJCK2AFX.js.map +1 -0
  41. package/dist/chunk-RUJJY23M.js +84 -0
  42. package/dist/chunk-RUJJY23M.js.map +1 -0
  43. package/dist/{chunk-LL7NCMUU.js → chunk-SKNJRYM5.js} +7 -13
  44. package/dist/chunk-SKNJRYM5.js.map +1 -0
  45. package/dist/chunk-WFGAMJ5Q.js +689 -0
  46. package/dist/chunk-WFGAMJ5Q.js.map +1 -0
  47. package/dist/chunk-ZJL56TJD.js +1444 -0
  48. package/dist/chunk-ZJL56TJD.js.map +1 -0
  49. package/dist/{chunk-V5XXJH63.js → chunk-ZXOP4LBG.js} +5 -8
  50. package/dist/chunk-ZXOP4LBG.js.map +1 -0
  51. package/dist/control-plane-2VEM2KCL.js +31 -0
  52. package/dist/custody-client-P6XIXHRG.js +16 -0
  53. package/dist/{dist-TSFVB7AI.js → dist-2SYQI5S2.js} +11 -7
  54. package/dist/dist-2SYQI5S2.js.map +1 -0
  55. package/dist/{dist-KQTMCVME.js → dist-6QZMZEL7.js} +18 -11
  56. package/dist/dist-6QZMZEL7.js.map +1 -0
  57. package/dist/{dist-FTKS2GI4.js → dist-JHMILJUT.js} +10 -6
  58. package/dist/{dist-OO52HARR.js → dist-JOFZOZCY.js} +41 -25
  59. package/dist/{dist-O3LKOIE7.js → dist-KZ2GEEEX.js} +11 -7
  60. package/dist/dist-KZ2GEEEX.js.map +1 -0
  61. package/dist/{dist-Z6L5MM5D.js → dist-Q5NY4CF6.js} +10 -6
  62. package/dist/{dist-U2SVLJUQ.js → dist-SKMNEDVW.js} +8 -2
  63. package/dist/dist-SKMNEDVW.js.map +1 -0
  64. package/dist/dist-SRCKO7ZV.js +197 -0
  65. package/dist/dist-SRCKO7ZV.js.map +1 -0
  66. package/dist/{dist-WVYAURMF.js → dist-UXZQWKY6.js} +10 -6
  67. package/dist/dist-UXZQWKY6.js.map +1 -0
  68. package/dist/env-file-UDUDQMP4.js +11 -0
  69. package/dist/env-file-UDUDQMP4.js.map +1 -0
  70. package/dist/hub-adopt-ZS5CREYF.js +21 -0
  71. package/dist/hub-adopt-ZS5CREYF.js.map +1 -0
  72. package/dist/index.js +2461 -1905
  73. package/dist/index.js.map +1 -1
  74. package/dist/node-postgres-6JUOVUN5.js +3584 -0
  75. package/dist/node-postgres-6JUOVUN5.js.map +1 -0
  76. package/dist/{prepared-state-75DIZ55S-TNJXWMXV.js → prepared-state-75DIZ55S-P6LE4N64.js} +3 -2
  77. package/dist/prepared-state-75DIZ55S-P6LE4N64.js.map +1 -0
  78. package/dist/remote-hub-SJ4XWBA5.js +9 -0
  79. package/dist/remote-hub-SJ4XWBA5.js.map +1 -0
  80. package/dist/sqlite-proxy-53E5D2VM.js +2882 -0
  81. package/dist/sqlite-proxy-53E5D2VM.js.map +1 -0
  82. package/package.json +1 -1
  83. package/runtime/_shared/ctl.cjs +29199 -16813
  84. package/runtime/digitalocean/ctl.cjs +29199 -16813
  85. package/runtime/docker/packages/ctl/dist/bin.cjs +29199 -16813
  86. package/runtime/e2b/ctl.cjs +29199 -16813
  87. package/runtime/hetzner/ctl.cjs +29199 -16813
  88. package/runtime/hub/apps/hub/.next/BUILD_ID +1 -1
  89. package/runtime/hub/apps/hub/.next/build-manifest.json +3 -3
  90. package/runtime/hub/apps/hub/.next/server/app/(auth)/api/auth/[...all]/route.js +5 -5
  91. package/runtime/hub/apps/hub/.next/server/app/(auth)/api/auth/[...all]/route.js.nft.json +1 -1
  92. package/runtime/hub/apps/hub/.next/server/app/(dashboard)/api/v1/approvals/[id]/answer/route.js +2 -2
  93. package/runtime/hub/apps/hub/.next/server/app/(dashboard)/api/v1/approvals/[id]/answer/route.js.nft.json +1 -1
  94. package/runtime/hub/apps/hub/.next/server/app/(dashboard)/api/v1/approvals/route.js +2 -2
  95. package/runtime/hub/apps/hub/.next/server/app/(dashboard)/api/v1/approvals/route.js.nft.json +1 -1
  96. package/runtime/hub/apps/hub/.next/server/app/(dashboard)/api/v1/boxes/[id]/[action]/route.js +2 -2
  97. package/runtime/hub/apps/hub/.next/server/app/(dashboard)/api/v1/boxes/[id]/[action]/route.js.nft.json +1 -1
  98. package/runtime/hub/apps/hub/.next/server/app/(dashboard)/api/v1/boxes/[id]/branches/route.js +2 -2
  99. package/runtime/hub/apps/hub/.next/server/app/(dashboard)/api/v1/boxes/[id]/branches/route.js.nft.json +1 -1
  100. package/runtime/hub/apps/hub/.next/server/app/(dashboard)/api/v1/boxes/[id]/git/[op]/route.js +2 -2
  101. package/runtime/hub/apps/hub/.next/server/app/(dashboard)/api/v1/boxes/[id]/git/[op]/route.js.nft.json +1 -1
  102. package/runtime/hub/apps/hub/.next/server/app/(dashboard)/api/v1/boxes/[id]/git/route.js +2 -2
  103. package/runtime/hub/apps/hub/.next/server/app/(dashboard)/api/v1/boxes/[id]/git/route.js.nft.json +1 -1
  104. package/runtime/hub/apps/hub/.next/server/app/(dashboard)/api/v1/boxes/[id]/open/route.js +2 -2
  105. package/runtime/hub/apps/hub/.next/server/app/(dashboard)/api/v1/boxes/[id]/open/route.js.nft.json +1 -1
  106. package/runtime/hub/apps/hub/.next/server/app/(dashboard)/api/v1/boxes/[id]/rename/route.js +2 -2
  107. package/runtime/hub/apps/hub/.next/server/app/(dashboard)/api/v1/boxes/[id]/rename/route.js.nft.json +1 -1
  108. package/runtime/hub/apps/hub/.next/server/app/(dashboard)/api/v1/boxes/[id]/route.js +2 -2
  109. package/runtime/hub/apps/hub/.next/server/app/(dashboard)/api/v1/boxes/[id]/route.js.nft.json +1 -1
  110. package/runtime/hub/apps/hub/.next/server/app/(dashboard)/api/v1/boxes/[id]/services/restart/route.js +2 -2
  111. package/runtime/hub/apps/hub/.next/server/app/(dashboard)/api/v1/boxes/[id]/services/restart/route.js.nft.json +1 -1
  112. package/runtime/hub/apps/hub/.next/server/app/(dashboard)/api/v1/boxes/[id]/services/route.js +4 -4
  113. package/runtime/hub/apps/hub/.next/server/app/(dashboard)/api/v1/boxes/[id]/services/route.js.nft.json +1 -1
  114. package/runtime/hub/apps/hub/.next/server/app/(dashboard)/api/v1/boxes/route.js +2 -2
  115. package/runtime/hub/apps/hub/.next/server/app/(dashboard)/api/v1/boxes/route.js.nft.json +1 -1
  116. package/runtime/hub/apps/hub/.next/server/app/(dashboard)/api/v1/health/route.js +2 -2
  117. package/runtime/hub/apps/hub/.next/server/app/(dashboard)/api/v1/health/route.js.nft.json +1 -1
  118. package/runtime/hub/apps/hub/.next/server/app/(dashboard)/api/v1/hosts/[alias]/bake/route.js +2 -2
  119. package/runtime/hub/apps/hub/.next/server/app/(dashboard)/api/v1/hosts/[alias]/bake/route.js.nft.json +1 -1
  120. package/runtime/hub/apps/hub/.next/server/app/(dashboard)/api/v1/hosts/[alias]/route.js +2 -2
  121. package/runtime/hub/apps/hub/.next/server/app/(dashboard)/api/v1/hosts/[alias]/route.js.nft.json +1 -1
  122. package/runtime/hub/apps/hub/.next/server/app/(dashboard)/api/v1/hosts/route.js +2 -2
  123. package/runtime/hub/apps/hub/.next/server/app/(dashboard)/api/v1/hosts/route.js.nft.json +1 -1
  124. package/runtime/hub/apps/hub/.next/server/app/(dashboard)/api/v1/jobs/[id]/login-code/route.js +2 -2
  125. package/runtime/hub/apps/hub/.next/server/app/(dashboard)/api/v1/jobs/[id]/login-code/route.js.nft.json +1 -1
  126. package/runtime/hub/apps/hub/.next/server/app/(dashboard)/api/v1/jobs/[id]/logs/route.js +2 -2
  127. package/runtime/hub/apps/hub/.next/server/app/(dashboard)/api/v1/jobs/[id]/logs/route.js.nft.json +1 -1
  128. package/runtime/hub/apps/hub/.next/server/app/(dashboard)/api/v1/jobs/[id]/route.js +2 -2
  129. package/runtime/hub/apps/hub/.next/server/app/(dashboard)/api/v1/jobs/[id]/route.js.nft.json +1 -1
  130. package/runtime/hub/apps/hub/.next/server/app/(dashboard)/api/v1/open-targets/route.js +2 -2
  131. package/runtime/hub/apps/hub/.next/server/app/(dashboard)/api/v1/open-targets/route.js.nft.json +1 -1
  132. package/runtime/hub/apps/hub/.next/server/app/(dashboard)/api/v1/projects/[id]/branches/route.js +2 -2
  133. package/runtime/hub/apps/hub/.next/server/app/(dashboard)/api/v1/projects/[id]/branches/route.js.nft.json +1 -1
  134. package/runtime/hub/apps/hub/.next/server/app/(dashboard)/api/v1/projects/[id]/route.js +2 -2
  135. package/runtime/hub/apps/hub/.next/server/app/(dashboard)/api/v1/projects/[id]/route.js.nft.json +1 -1
  136. package/runtime/hub/apps/hub/.next/server/app/(dashboard)/api/v1/projects/route.js +2 -2
  137. package/runtime/hub/apps/hub/.next/server/app/(dashboard)/api/v1/projects/route.js.nft.json +1 -1
  138. package/runtime/hub/apps/hub/.next/server/app/(dashboard)/api/v1/providers/[id]/credentials/route.js +2 -2
  139. package/runtime/hub/apps/hub/.next/server/app/(dashboard)/api/v1/providers/[id]/credentials/route.js.nft.json +1 -1
  140. package/runtime/hub/apps/hub/.next/server/app/(dashboard)/api/v1/providers/[id]/prepare/route.js +2 -2
  141. package/runtime/hub/apps/hub/.next/server/app/(dashboard)/api/v1/providers/[id]/prepare/route.js.nft.json +1 -1
  142. package/runtime/hub/apps/hub/.next/server/app/(dashboard)/api/v1/providers/route.js +2 -2
  143. package/runtime/hub/apps/hub/.next/server/app/(dashboard)/api/v1/providers/route.js.nft.json +1 -1
  144. package/runtime/hub/apps/hub/.next/server/app/(dashboard)/approvals/page.js +2 -2
  145. package/runtime/hub/apps/hub/.next/server/app/(dashboard)/approvals/page.js.nft.json +1 -1
  146. package/runtime/hub/apps/hub/.next/server/app/(dashboard)/approvals/page_client-reference-manifest.js +1 -1
  147. package/runtime/hub/apps/hub/.next/server/app/(dashboard)/boxes/[id]/page.js +2 -2
  148. package/runtime/hub/apps/hub/.next/server/app/(dashboard)/boxes/[id]/page.js.nft.json +1 -1
  149. package/runtime/hub/apps/hub/.next/server/app/(dashboard)/boxes/[id]/page_client-reference-manifest.js +1 -1
  150. package/runtime/hub/apps/hub/.next/server/app/(dashboard)/page.js +2 -2
  151. package/runtime/hub/apps/hub/.next/server/app/(dashboard)/page.js.nft.json +1 -1
  152. package/runtime/hub/apps/hub/.next/server/app/(dashboard)/page_client-reference-manifest.js +1 -1
  153. package/runtime/hub/apps/hub/.next/server/app/(dashboard)/projects/[id]/page.js +2 -2
  154. package/runtime/hub/apps/hub/.next/server/app/(dashboard)/projects/[id]/page.js.nft.json +1 -1
  155. package/runtime/hub/apps/hub/.next/server/app/(dashboard)/projects/[id]/page_client-reference-manifest.js +1 -1
  156. package/runtime/hub/apps/hub/.next/server/app/(dashboard)/settings/page.js +2 -2
  157. package/runtime/hub/apps/hub/.next/server/app/(dashboard)/settings/page.js.nft.json +1 -1
  158. package/runtime/hub/apps/hub/.next/server/app/(dashboard)/settings/page_client-reference-manifest.js +1 -1
  159. package/runtime/hub/apps/hub/.next/server/app/[...path]/route.js +4 -2
  160. package/runtime/hub/apps/hub/.next/server/app/[...path]/route.js.nft.json +1 -1
  161. package/runtime/hub/apps/hub/.next/server/app/_global-error.html +1 -1
  162. package/runtime/hub/apps/hub/.next/server/app/_global-error.rsc +1 -1
  163. package/runtime/hub/apps/hub/.next/server/app/_global-error.segments/__PAGE__.segment.rsc +1 -1
  164. package/runtime/hub/apps/hub/.next/server/app/_global-error.segments/_full.segment.rsc +1 -1
  165. package/runtime/hub/apps/hub/.next/server/app/_global-error.segments/_head.segment.rsc +1 -1
  166. package/runtime/hub/apps/hub/.next/server/app/_global-error.segments/_index.segment.rsc +1 -1
  167. package/runtime/hub/apps/hub/.next/server/app/_global-error.segments/_tree.segment.rsc +1 -1
  168. package/runtime/hub/apps/hub/.next/server/chunks/0-fj_better-auth_dist_adapters_kysely-adapter_index_mjs_0btft52._.js +3 -0
  169. package/runtime/hub/apps/hub/.next/server/chunks/1w4z_drizzle-orm_0gvv4ct._.js +4 -0
  170. package/runtime/hub/apps/hub/.next/server/chunks/1w4z_drizzle-orm_0pn9b49._.js +4 -0
  171. package/runtime/hub/apps/hub/.next/server/chunks/1w4z_drizzle-orm_145bz8z._.js +9 -0
  172. package/runtime/hub/apps/hub/.next/server/chunks/1w4z_drizzle-orm_14y990b._.js +3 -0
  173. package/runtime/hub/apps/hub/.next/server/chunks/1w4z_drizzle-orm_1nl4l3q._.js +3 -0
  174. package/runtime/hub/apps/hub/.next/server/chunks/1w4z_drizzle-orm_sqlite-proxy_index_05v_j5r.js +15 -0
  175. package/runtime/hub/apps/hub/.next/server/chunks/{[externals]__12m3qoa._.js → [externals]__0f3aqcx._.js} +2 -2
  176. package/runtime/hub/apps/hub/.next/server/chunks/[root-of-the-server]__0-9g1s8._.js +3 -0
  177. package/runtime/hub/apps/hub/.next/server/chunks/[root-of-the-server]__0-pvfxg._.js +3 -0
  178. package/runtime/hub/apps/hub/.next/server/chunks/[root-of-the-server]__01amzh6._.js +3 -0
  179. package/runtime/hub/apps/hub/.next/server/chunks/[root-of-the-server]__02q799_._.js +3 -0
  180. package/runtime/hub/apps/hub/.next/server/chunks/[root-of-the-server]__03k22rl._.js +3 -0
  181. package/runtime/hub/apps/hub/.next/server/chunks/[root-of-the-server]__04tqk-j._.js +3 -0
  182. package/runtime/hub/apps/hub/.next/server/chunks/[root-of-the-server]__05ovf1y._.js +3 -0
  183. package/runtime/hub/apps/hub/.next/server/chunks/[root-of-the-server]__05s-_x7._.js +3 -0
  184. package/runtime/hub/apps/hub/.next/server/chunks/[root-of-the-server]__07dnyfi._.js +3 -0
  185. package/runtime/hub/apps/hub/.next/server/chunks/[root-of-the-server]__07zk6qo._.js +3 -0
  186. package/runtime/hub/apps/hub/.next/server/chunks/[root-of-the-server]__0_59yi6._.js +3 -0
  187. package/runtime/hub/apps/hub/.next/server/chunks/[root-of-the-server]__0ajlo3d._.js +3 -0
  188. package/runtime/hub/apps/hub/.next/server/chunks/[root-of-the-server]__0b5s54n._.js +3 -0
  189. package/runtime/hub/apps/hub/.next/server/chunks/[root-of-the-server]__0c4fiez._.js +3 -0
  190. package/runtime/hub/apps/hub/.next/server/chunks/[root-of-the-server]__0c9iff1._.js +3 -0
  191. package/runtime/hub/apps/hub/.next/server/chunks/[root-of-the-server]__0d1lmiq._.js +5 -5
  192. package/runtime/hub/apps/hub/.next/server/chunks/[root-of-the-server]__0dh6lzr._.js +3 -0
  193. package/runtime/hub/apps/hub/.next/server/chunks/[root-of-the-server]__0ey83ai._.js +3 -0
  194. package/runtime/hub/apps/hub/.next/server/chunks/[root-of-the-server]__0h6vdvr._.js +3 -0
  195. package/runtime/hub/apps/hub/.next/server/chunks/[root-of-the-server]__0lup7p4._.js +3 -0
  196. package/runtime/hub/apps/hub/.next/server/chunks/[root-of-the-server]__0luxuu4._.js +3 -0
  197. package/runtime/hub/apps/hub/.next/server/chunks/[root-of-the-server]__0nl2u6u._.js +3 -0
  198. package/runtime/hub/apps/hub/.next/server/chunks/[root-of-the-server]__0nonp-6._.js +3 -0
  199. package/runtime/hub/apps/hub/.next/server/chunks/[root-of-the-server]__0oplozy._.js +3 -0
  200. package/runtime/hub/apps/hub/.next/server/chunks/[root-of-the-server]__0p-6wgd._.js +3 -0
  201. package/runtime/hub/apps/hub/.next/server/chunks/[root-of-the-server]__0rcnwbw._.js +3 -0
  202. package/runtime/hub/apps/hub/.next/server/chunks/[root-of-the-server]__0tuz1am._.js +3 -0
  203. package/runtime/hub/apps/hub/.next/server/chunks/[root-of-the-server]__1-9g0ae._.js +1 -1
  204. package/runtime/hub/apps/hub/.next/server/chunks/[root-of-the-server]__10ry4ss._.js +3 -0
  205. package/runtime/hub/apps/hub/.next/server/chunks/[root-of-the-server]__11hv164._.js +3 -0
  206. package/runtime/hub/apps/hub/.next/server/chunks/[root-of-the-server]__154_i13._.js +3 -0
  207. package/runtime/hub/apps/hub/.next/server/chunks/[root-of-the-server]__17676rc._.js +3 -0
  208. package/runtime/hub/apps/hub/.next/server/chunks/[root-of-the-server]__1bg1alc._.js +3 -0
  209. package/runtime/hub/apps/hub/.next/server/chunks/[root-of-the-server]__1cvqb1d._.js +3 -0
  210. package/runtime/hub/apps/hub/.next/server/chunks/[root-of-the-server]__1d60gbz._.js +3 -0
  211. package/runtime/hub/apps/hub/.next/server/chunks/[root-of-the-server]__1dm0jmw._.js +6 -0
  212. package/runtime/hub/apps/hub/.next/server/chunks/[root-of-the-server]__1dv_b1t._.js +3 -0
  213. package/runtime/hub/apps/hub/.next/server/chunks/[root-of-the-server]__1fzxip4._.js +3 -0
  214. package/runtime/hub/apps/hub/.next/server/chunks/[root-of-the-server]__1h4oj-e._.js +3 -0
  215. package/runtime/hub/apps/hub/.next/server/chunks/[root-of-the-server]__1i4gq_2._.js +3 -0
  216. package/runtime/hub/apps/hub/.next/server/chunks/[root-of-the-server]__1v1p7in._.js +3 -0
  217. package/runtime/hub/apps/hub/.next/server/chunks/[root-of-the-server]__1v9_her._.js +4 -0
  218. package/runtime/hub/apps/hub/.next/server/chunks/[root-of-the-server]__1x1jkpb._.js +3 -0
  219. package/runtime/hub/apps/hub/.next/server/chunks/[root-of-the-server]__1yd8n5l._.js +3 -0
  220. package/runtime/hub/apps/hub/.next/server/chunks/[root-of-the-server]__20t_rs8._.js +3 -0
  221. package/runtime/hub/apps/hub/.next/server/chunks/_033w048._.js +1 -1
  222. package/runtime/hub/apps/hub/.next/server/chunks/_06f2faq._.js +1 -1
  223. package/runtime/hub/apps/hub/.next/server/chunks/{_0760z6y._.js → _0907rw0._.js} +15 -15
  224. package/runtime/hub/apps/hub/.next/server/chunks/_0f3molr._.js +1 -1
  225. package/runtime/hub/apps/hub/.next/server/chunks/_0lgs9kd._.js +1 -1
  226. package/runtime/hub/apps/hub/.next/server/chunks/_0pyhcqe._.js +1 -1
  227. package/runtime/hub/apps/hub/.next/server/chunks/_1-42ili._.js +1 -1
  228. package/runtime/hub/apps/hub/.next/server/chunks/_11__3wi._.js +1 -1
  229. package/runtime/hub/apps/hub/.next/server/chunks/_12flzuh._.js +1 -1
  230. package/runtime/hub/apps/hub/.next/server/chunks/_1bng7w9._.js +1 -1
  231. package/runtime/hub/apps/hub/.next/server/chunks/_1rpkqst._.js +1 -1
  232. package/runtime/hub/apps/hub/.next/server/chunks/_1wt72m1._.js +1 -1
  233. package/runtime/hub/apps/hub/.next/server/chunks/_1x3l5t8._.js +1 -1
  234. package/runtime/hub/apps/hub/.next/server/chunks/packages_relay_dist_control-plane_03a-9aj.js +62 -31
  235. package/runtime/hub/apps/hub/.next/server/chunks/ssr/09xn_next_dist_0xy-j7z._.js +1 -1
  236. package/runtime/hub/apps/hub/.next/server/chunks/ssr/09xn_next_dist_1uccfbf._.js +1 -1
  237. package/runtime/hub/apps/hub/.next/server/chunks/ssr/09xn_next_dist_esm_build_templates_app-page_010858m.js +1 -1
  238. package/runtime/hub/apps/hub/.next/server/chunks/ssr/09xn_next_dist_esm_build_templates_app-page_04zwxnx.js +1 -1
  239. package/runtime/hub/apps/hub/.next/server/chunks/ssr/09xn_next_dist_esm_build_templates_app-page_06exuc7.js +1 -1
  240. package/runtime/hub/apps/hub/.next/server/chunks/ssr/09xn_next_dist_esm_build_templates_app-page_0f2ldrt.js +1 -1
  241. package/runtime/hub/apps/hub/.next/server/chunks/ssr/09xn_next_dist_esm_build_templates_app-page_0f2tzep.js +1 -1
  242. package/runtime/hub/apps/hub/.next/server/chunks/ssr/09xn_next_dist_esm_build_templates_app-page_116nh32.js +1 -1
  243. package/runtime/hub/apps/hub/.next/server/chunks/ssr/09xn_next_dist_esm_build_templates_app-page_11dyjcb.js +1 -1
  244. package/runtime/hub/apps/hub/.next/server/chunks/ssr/09xn_next_dist_esm_build_templates_app-page_1_4knli.js +1 -1
  245. package/runtime/hub/apps/hub/.next/server/chunks/ssr/1w4z_drizzle-orm_0ebuy19._.js +3 -0
  246. package/runtime/hub/apps/hub/.next/server/chunks/ssr/1w4z_drizzle-orm_0wxhi0-._.js +3 -0
  247. package/runtime/hub/apps/hub/.next/server/chunks/ssr/1w4z_drizzle-orm_0xe4ick._.js +9 -0
  248. package/runtime/hub/apps/hub/.next/server/chunks/ssr/1w4z_drizzle-orm_14oaveu._.js +4 -0
  249. package/runtime/hub/apps/hub/.next/server/chunks/ssr/1w4z_drizzle-orm_sqlite-proxy_index_1a6wfdg.js +15 -0
  250. package/runtime/hub/apps/hub/.next/server/chunks/ssr/[root-of-the-server]__0-pm2yl._.js +3 -0
  251. package/runtime/hub/apps/hub/.next/server/chunks/ssr/[root-of-the-server]__08-1wwu._.js +1 -1
  252. package/runtime/hub/apps/hub/.next/server/chunks/ssr/[root-of-the-server]__0c9mbcn._.js +1 -1
  253. package/runtime/hub/apps/hub/.next/server/chunks/ssr/[root-of-the-server]__0gdfxj4._.js +1 -1
  254. package/runtime/hub/apps/hub/.next/server/chunks/ssr/[root-of-the-server]__0kc-hwp._.js +1 -1
  255. package/runtime/hub/apps/hub/.next/server/chunks/ssr/[root-of-the-server]__0lu73p6._.js +1 -1
  256. package/runtime/hub/apps/hub/.next/server/chunks/ssr/[root-of-the-server]__0m1yf2b._.js +4 -0
  257. package/runtime/hub/apps/hub/.next/server/chunks/ssr/[root-of-the-server]__0wv-3zo._.js +3 -0
  258. package/runtime/hub/apps/hub/.next/server/chunks/ssr/[root-of-the-server]__10bfmwi._.js +1 -1
  259. package/runtime/hub/apps/hub/.next/server/chunks/ssr/[root-of-the-server]__18qvdzb._.js +2 -2
  260. package/runtime/hub/apps/hub/.next/server/chunks/ssr/[root-of-the-server]__1l2urlw._.js +1 -1
  261. package/runtime/hub/apps/hub/.next/server/chunks/ssr/{_0ro6vh6._.js → _0r2xlss._.js} +3 -3
  262. package/runtime/hub/apps/hub/.next/server/chunks/ssr/apps_hub_components_1z1p98f._.js +1 -1
  263. package/runtime/hub/apps/hub/.next/server/chunks/ssr/packages_relay_dist_control-plane_0ve-wz4.js +2 -25
  264. package/runtime/hub/apps/hub/.next/server/middleware-build-manifest.js +3 -3
  265. package/runtime/hub/apps/hub/.next/server/middleware.js +1 -1
  266. package/runtime/hub/apps/hub/.next/server/pages/500.html +1 -1
  267. package/runtime/hub/apps/hub/.next/static/chunks/{2xc1sm79a6tsb.js → 2gsrna76i1d80.js} +1 -1
  268. package/runtime/hub/apps/hub/attach-helper.cjs +191 -0
  269. package/runtime/hub/apps/hub/{auth-DC44GQZY.js → auth-IRNNO3IK.js} +2 -2
  270. package/runtime/hub/apps/hub/{auth-config-LALRDYDO.js → auth-config-WJHIMGUE.js} +4 -2
  271. package/runtime/hub/apps/hub/{chunk-YJ5MJOXK.js → chunk-4LYVBRBC.js} +2094 -220
  272. package/runtime/hub/apps/hub/chunk-6AVSKCZJ.js +669 -0
  273. package/runtime/hub/apps/hub/{chunk-QSMPSV5Z.js → chunk-A5Y7LJMU.js} +57 -14
  274. package/runtime/hub/apps/hub/chunk-EDRFXO2M.js +35 -0
  275. package/runtime/hub/apps/hub/chunk-F2JI4GMX.js +2891 -0
  276. package/runtime/hub/apps/hub/{chunk-EHBJKZCL.js → chunk-O3K3ZGFF.js} +500 -35
  277. package/runtime/hub/apps/hub/chunk-RII6IKNJ.js +688 -0
  278. package/runtime/hub/apps/hub/{chunk-RXYOWSSN.js → chunk-RMEUA6PA.js} +120 -14
  279. package/runtime/hub/apps/hub/{chunk-3FJNKSNZ.js → chunk-SCHQR5KR.js} +3 -1
  280. package/runtime/hub/apps/hub/{dist-6FPPUSWZ.js → dist-2GEAA7QA.js} +15 -3
  281. package/runtime/hub/apps/hub/{dist-JG45OFT2.js → dist-36O6F6M3.js} +39 -24
  282. package/runtime/hub/apps/hub/{dist-3I7KUI6W.js → dist-IWLEL2TO.js} +21 -24
  283. package/runtime/hub/apps/hub/{dist-G6TXUSPZ.js → dist-NYKIT5W5.js} +10 -11
  284. package/runtime/hub/apps/hub/{dist-EQV4L7KP.js → dist-QB2IJ7OD.js} +7 -1
  285. package/runtime/hub/apps/hub/{dist-LYDHYTP2.js → dist-RBBXXGLI.js} +129 -26
  286. package/runtime/hub/apps/hub/{dist-GTVVXCBP.js → dist-RRJN2U5P.js} +10 -14
  287. package/runtime/hub/apps/hub/{dist-DX6IYMAH.js → dist-UWXGDCK4.js} +14 -11
  288. package/runtime/hub/apps/hub/{hub-token-COBZGSLS.js → hub-token-6USIMBPQ.js} +2 -2
  289. package/runtime/hub/apps/hub/hub-worker-SOFWVTWU.js +215 -0
  290. package/runtime/hub/apps/hub/node-postgres-DIU2H5VP.js +3583 -0
  291. package/runtime/hub/apps/hub/package.json +5 -2
  292. package/runtime/hub/apps/hub/{prepared-state-75DIZ55S-2IFNUHHM.js → prepared-state-75DIZ55S-P5FHEORG.js} +1 -1
  293. package/runtime/hub/apps/hub/server.js +247 -66
  294. package/runtime/hub/apps/hub/sqlite-proxy-VJS3HIOV.js +2881 -0
  295. package/runtime/relay/bin.cjs +694 -13
  296. package/runtime/vercel/ctl.cjs +29199 -16813
  297. package/dist/_cloud-attach-WDGM6FL5.js +0 -19
  298. package/dist/chunk-26IKZRTT.js.map +0 -1
  299. package/dist/chunk-HR7NHH5J.js.map +0 -1
  300. package/dist/chunk-IDH5A4RR.js.map +0 -1
  301. package/dist/chunk-JE6UI5YR.js.map +0 -1
  302. package/dist/chunk-JGZSA5ZI.js.map +0 -1
  303. package/dist/chunk-LL7NCMUU.js.map +0 -1
  304. package/dist/chunk-NEF6MDJO.js.map +0 -1
  305. package/dist/chunk-UJEH2NJT.js.map +0 -1
  306. package/dist/chunk-V5XXJH63.js.map +0 -1
  307. package/dist/dist-KQTMCVME.js.map +0 -1
  308. package/dist/dist-O3LKOIE7.js.map +0 -1
  309. package/dist/dist-TSFVB7AI.js.map +0 -1
  310. package/runtime/hub/apps/hub/.next/server/chunks/0zhp_better-auth_dist_adapters_kysely-adapter_index_mjs_1rl4qnh._.js +0 -3
  311. package/runtime/hub/apps/hub/.next/server/chunks/[root-of-the-server]__04h15ml._.js +0 -3
  312. package/runtime/hub/apps/hub/.next/server/chunks/[root-of-the-server]__04jgk9x._.js +0 -3
  313. package/runtime/hub/apps/hub/.next/server/chunks/[root-of-the-server]__07ednlo._.js +0 -3
  314. package/runtime/hub/apps/hub/.next/server/chunks/[root-of-the-server]__0a7djvw._.js +0 -3
  315. package/runtime/hub/apps/hub/.next/server/chunks/[root-of-the-server]__0ig1bot._.js +0 -3
  316. package/runtime/hub/apps/hub/.next/server/chunks/[root-of-the-server]__0keu6we._.js +0 -3
  317. package/runtime/hub/apps/hub/.next/server/chunks/[root-of-the-server]__0ql4fjo._.js +0 -3
  318. package/runtime/hub/apps/hub/.next/server/chunks/[root-of-the-server]__0szd4sh._.js +0 -3
  319. package/runtime/hub/apps/hub/.next/server/chunks/[root-of-the-server]__0t7o5ed._.js +0 -3
  320. package/runtime/hub/apps/hub/.next/server/chunks/[root-of-the-server]__0vs8fma._.js +0 -3
  321. package/runtime/hub/apps/hub/.next/server/chunks/[root-of-the-server]__0w9ud8u._.js +0 -3
  322. package/runtime/hub/apps/hub/.next/server/chunks/[root-of-the-server]__0xh14bo._.js +0 -3
  323. package/runtime/hub/apps/hub/.next/server/chunks/[root-of-the-server]__0yhb0gc._.js +0 -3
  324. package/runtime/hub/apps/hub/.next/server/chunks/[root-of-the-server]__1-0flwc._.js +0 -3
  325. package/runtime/hub/apps/hub/.next/server/chunks/[root-of-the-server]__13ioh5z._.js +0 -3
  326. package/runtime/hub/apps/hub/.next/server/chunks/[root-of-the-server]__13jwk_k._.js +0 -3
  327. package/runtime/hub/apps/hub/.next/server/chunks/[root-of-the-server]__16_uteg._.js +0 -3
  328. package/runtime/hub/apps/hub/.next/server/chunks/[root-of-the-server]__16p2m-g._.js +0 -3
  329. package/runtime/hub/apps/hub/.next/server/chunks/[root-of-the-server]__19pc87s._.js +0 -3
  330. package/runtime/hub/apps/hub/.next/server/chunks/[root-of-the-server]__1_gu2yk._.js +0 -3
  331. package/runtime/hub/apps/hub/.next/server/chunks/[root-of-the-server]__1a50b07._.js +0 -3
  332. package/runtime/hub/apps/hub/.next/server/chunks/[root-of-the-server]__1ai-945._.js +0 -3
  333. package/runtime/hub/apps/hub/.next/server/chunks/[root-of-the-server]__1bu2zio._.js +0 -3
  334. package/runtime/hub/apps/hub/.next/server/chunks/[root-of-the-server]__1ctczev._.js +0 -3
  335. package/runtime/hub/apps/hub/.next/server/chunks/[root-of-the-server]__1d6mtlk._.js +0 -3
  336. package/runtime/hub/apps/hub/.next/server/chunks/[root-of-the-server]__1dn_3i1._.js +0 -3
  337. package/runtime/hub/apps/hub/.next/server/chunks/[root-of-the-server]__1e4z_-v._.js +0 -3
  338. package/runtime/hub/apps/hub/.next/server/chunks/[root-of-the-server]__1f2sueq._.js +0 -3
  339. package/runtime/hub/apps/hub/.next/server/chunks/[root-of-the-server]__1f9zctr._.js +0 -3
  340. package/runtime/hub/apps/hub/.next/server/chunks/[root-of-the-server]__1h4xycg._.js +0 -3
  341. package/runtime/hub/apps/hub/.next/server/chunks/[root-of-the-server]__1hqla7-._.js +0 -3
  342. package/runtime/hub/apps/hub/.next/server/chunks/[root-of-the-server]__1js2jdv._.js +0 -3
  343. package/runtime/hub/apps/hub/.next/server/chunks/[root-of-the-server]__1md9kdw._.js +0 -3
  344. package/runtime/hub/apps/hub/.next/server/chunks/[root-of-the-server]__1mttufy._.js +0 -3
  345. package/runtime/hub/apps/hub/.next/server/chunks/[root-of-the-server]__1nepkp-._.js +0 -6
  346. package/runtime/hub/apps/hub/.next/server/chunks/[root-of-the-server]__1pp5oib._.js +0 -3
  347. package/runtime/hub/apps/hub/.next/server/chunks/[root-of-the-server]__1q5bqse._.js +0 -3
  348. package/runtime/hub/apps/hub/.next/server/chunks/[root-of-the-server]__1qwhzmi._.js +0 -3
  349. package/runtime/hub/apps/hub/.next/server/chunks/[root-of-the-server]__1thipug._.js +0 -3
  350. package/runtime/hub/apps/hub/.next/server/chunks/[root-of-the-server]__1v9om6g._.js +0 -3
  351. package/runtime/hub/apps/hub/.next/server/chunks/[root-of-the-server]__1xeczo7._.js +0 -3
  352. package/runtime/hub/apps/hub/.next/server/chunks/[root-of-the-server]__20503l7._.js +0 -3
  353. package/runtime/hub/apps/hub/.next/server/chunks/ssr/[externals]_pg_20c820g._.js +0 -3
  354. package/runtime/hub/apps/hub/.next/server/chunks/ssr/[root-of-the-server]__0j0tjwn._.js +0 -3
  355. /package/dist/{_cloud-attach-WDGM6FL5.js.map → _cloud-attach-XZYF324R.js.map} +0 -0
  356. /package/dist/{dist-FTKS2GI4.js.map → admin-client-NOZ5CCAH.js.map} +0 -0
  357. /package/dist/{dist-OO52HARR.js.map → control-plane-2VEM2KCL.js.map} +0 -0
  358. /package/dist/{dist-U2SVLJUQ.js.map → custody-client-P6XIXHRG.js.map} +0 -0
  359. /package/dist/{dist-WVYAURMF.js.map → dist-JHMILJUT.js.map} +0 -0
  360. /package/dist/{dist-Z6L5MM5D.js.map → dist-JOFZOZCY.js.map} +0 -0
  361. /package/dist/{prepared-state-75DIZ55S-TNJXWMXV.js.map → dist-Q5NY4CF6.js.map} +0 -0
  362. /package/runtime/hub/apps/hub/.next/static/{PWF2iHQOg9-rRyfqVDLrh → B4bEtdig9I9joQFHDOjX3}/_buildManifest.js +0 -0
  363. /package/runtime/hub/apps/hub/.next/static/{PWF2iHQOg9-rRyfqVDLrh → B4bEtdig9I9joQFHDOjX3}/_clientMiddlewareManifest.js +0 -0
  364. /package/runtime/hub/apps/hub/.next/static/{PWF2iHQOg9-rRyfqVDLrh → B4bEtdig9I9joQFHDOjX3}/_ssgManifest.js +0 -0
@@ -0,0 +1,2882 @@
1
+ #!/usr/bin/env node
2
+ import {
3
+ CasingCache,
4
+ DefaultLogger,
5
+ DrizzleError,
6
+ DrizzleQueryError,
7
+ Many,
8
+ NoopCache,
9
+ NoopLogger,
10
+ One,
11
+ QueryPromise,
12
+ SelectionProxyHandler,
13
+ TransactionRollbackError,
14
+ TypedQueryBuilder,
15
+ aliasedTable,
16
+ aliasedTableColumn,
17
+ createTableRelationsHelpers,
18
+ extractTablesRelationalConfig,
19
+ getOperators,
20
+ getOrderByOperators,
21
+ hashQuery,
22
+ mapColumnsInAliasedSQLToAlias,
23
+ mapColumnsInSQLToAlias,
24
+ mapRelationalRow,
25
+ normalizeRelation
26
+ } from "./chunk-WFGAMJ5Q.js";
27
+ import {
28
+ SQLiteColumn,
29
+ SQLiteTable
30
+ } from "./chunk-QESXSSO6.js";
31
+ import {
32
+ Column,
33
+ Columns,
34
+ Param,
35
+ SQL,
36
+ Subquery,
37
+ Table,
38
+ View,
39
+ ViewBaseConfig,
40
+ WithSubquery,
41
+ and,
42
+ applyMixins,
43
+ entityKind,
44
+ eq,
45
+ fillPlaceholders,
46
+ getTableColumns,
47
+ getTableLikeName,
48
+ getTableName,
49
+ getTableUniqueName,
50
+ haveSameKeys,
51
+ is,
52
+ mapResultRow,
53
+ mapUpdateSet,
54
+ orderSelectedFields,
55
+ sql
56
+ } from "./chunk-6V366IZC.js";
57
+ import "./chunk-WJFZJZIM.js";
58
+
59
+ // ../../node_modules/.pnpm/drizzle-orm@0.45.2_@opentelemetry+api@1.9.1_@types+pg@8.20.0_kysely@0.29.2_pg@8.22.0/node_modules/drizzle-orm/sqlite-core/utils.js
60
+ function extractUsedTable(table) {
61
+ if (is(table, SQLiteTable)) {
62
+ return [`${table[Table.Symbol.BaseName]}`];
63
+ }
64
+ if (is(table, Subquery)) {
65
+ return table._.usedTables ?? [];
66
+ }
67
+ if (is(table, SQL)) {
68
+ return table.usedTables ?? [];
69
+ }
70
+ return [];
71
+ }
72
+
73
+ // ../../node_modules/.pnpm/drizzle-orm@0.45.2_@opentelemetry+api@1.9.1_@types+pg@8.20.0_kysely@0.29.2_pg@8.22.0/node_modules/drizzle-orm/sqlite-core/query-builders/delete.js
74
+ var SQLiteDeleteBase = class extends QueryPromise {
75
+ constructor(table, session, dialect, withList) {
76
+ super();
77
+ this.table = table;
78
+ this.session = session;
79
+ this.dialect = dialect;
80
+ this.config = { table, withList };
81
+ }
82
+ static [entityKind] = "SQLiteDelete";
83
+ /** @internal */
84
+ config;
85
+ /**
86
+ * Adds a `where` clause to the query.
87
+ *
88
+ * Calling this method will delete only those rows that fulfill a specified condition.
89
+ *
90
+ * See docs: {@link https://orm.drizzle.team/docs/delete}
91
+ *
92
+ * @param where the `where` clause.
93
+ *
94
+ * @example
95
+ * You can use conditional operators and `sql function` to filter the rows to be deleted.
96
+ *
97
+ * ```ts
98
+ * // Delete all cars with green color
99
+ * db.delete(cars).where(eq(cars.color, 'green'));
100
+ * // or
101
+ * db.delete(cars).where(sql`${cars.color} = 'green'`)
102
+ * ```
103
+ *
104
+ * You can logically combine conditional operators with `and()` and `or()` operators:
105
+ *
106
+ * ```ts
107
+ * // Delete all BMW cars with a green color
108
+ * db.delete(cars).where(and(eq(cars.color, 'green'), eq(cars.brand, 'BMW')));
109
+ *
110
+ * // Delete all cars with the green or blue color
111
+ * db.delete(cars).where(or(eq(cars.color, 'green'), eq(cars.color, 'blue')));
112
+ * ```
113
+ */
114
+ where(where) {
115
+ this.config.where = where;
116
+ return this;
117
+ }
118
+ orderBy(...columns) {
119
+ if (typeof columns[0] === "function") {
120
+ const orderBy = columns[0](
121
+ new Proxy(
122
+ this.config.table[Table.Symbol.Columns],
123
+ new SelectionProxyHandler({ sqlAliasedBehavior: "alias", sqlBehavior: "sql" })
124
+ )
125
+ );
126
+ const orderByArray = Array.isArray(orderBy) ? orderBy : [orderBy];
127
+ this.config.orderBy = orderByArray;
128
+ } else {
129
+ const orderByArray = columns;
130
+ this.config.orderBy = orderByArray;
131
+ }
132
+ return this;
133
+ }
134
+ limit(limit) {
135
+ this.config.limit = limit;
136
+ return this;
137
+ }
138
+ returning(fields = this.table[SQLiteTable.Symbol.Columns]) {
139
+ this.config.returning = orderSelectedFields(fields);
140
+ return this;
141
+ }
142
+ /** @internal */
143
+ getSQL() {
144
+ return this.dialect.buildDeleteQuery(this.config);
145
+ }
146
+ toSQL() {
147
+ const { typings: _typings, ...rest } = this.dialect.sqlToQuery(this.getSQL());
148
+ return rest;
149
+ }
150
+ /** @internal */
151
+ _prepare(isOneTimeQuery = true) {
152
+ return this.session[isOneTimeQuery ? "prepareOneTimeQuery" : "prepareQuery"](
153
+ this.dialect.sqlToQuery(this.getSQL()),
154
+ this.config.returning,
155
+ this.config.returning ? "all" : "run",
156
+ true,
157
+ void 0,
158
+ {
159
+ type: "delete",
160
+ tables: extractUsedTable(this.config.table)
161
+ }
162
+ );
163
+ }
164
+ prepare() {
165
+ return this._prepare(false);
166
+ }
167
+ run = (placeholderValues) => {
168
+ return this._prepare().run(placeholderValues);
169
+ };
170
+ all = (placeholderValues) => {
171
+ return this._prepare().all(placeholderValues);
172
+ };
173
+ get = (placeholderValues) => {
174
+ return this._prepare().get(placeholderValues);
175
+ };
176
+ values = (placeholderValues) => {
177
+ return this._prepare().values(placeholderValues);
178
+ };
179
+ async execute(placeholderValues) {
180
+ return this._prepare().execute(placeholderValues);
181
+ }
182
+ $dynamic() {
183
+ return this;
184
+ }
185
+ };
186
+
187
+ // ../../node_modules/.pnpm/drizzle-orm@0.45.2_@opentelemetry+api@1.9.1_@types+pg@8.20.0_kysely@0.29.2_pg@8.22.0/node_modules/drizzle-orm/sqlite-core/view-base.js
188
+ var SQLiteViewBase = class extends View {
189
+ static [entityKind] = "SQLiteViewBase";
190
+ };
191
+
192
+ // ../../node_modules/.pnpm/drizzle-orm@0.45.2_@opentelemetry+api@1.9.1_@types+pg@8.20.0_kysely@0.29.2_pg@8.22.0/node_modules/drizzle-orm/sqlite-core/dialect.js
193
+ var SQLiteDialect = class {
194
+ static [entityKind] = "SQLiteDialect";
195
+ /** @internal */
196
+ casing;
197
+ constructor(config) {
198
+ this.casing = new CasingCache(config?.casing);
199
+ }
200
+ escapeName(name) {
201
+ return `"${name.replace(/"/g, '""')}"`;
202
+ }
203
+ escapeParam(_num) {
204
+ return "?";
205
+ }
206
+ escapeString(str) {
207
+ return `'${str.replace(/'/g, "''")}'`;
208
+ }
209
+ buildWithCTE(queries) {
210
+ if (!queries?.length) return void 0;
211
+ const withSqlChunks = [sql`with `];
212
+ for (const [i, w] of queries.entries()) {
213
+ withSqlChunks.push(sql`${sql.identifier(w._.alias)} as (${w._.sql})`);
214
+ if (i < queries.length - 1) {
215
+ withSqlChunks.push(sql`, `);
216
+ }
217
+ }
218
+ withSqlChunks.push(sql` `);
219
+ return sql.join(withSqlChunks);
220
+ }
221
+ buildDeleteQuery({
222
+ table,
223
+ where,
224
+ returning,
225
+ withList,
226
+ limit,
227
+ orderBy
228
+ }) {
229
+ const withSql = this.buildWithCTE(withList);
230
+ const returningSql = returning ? sql` returning ${this.buildSelection(returning, { isSingleTable: true })}` : void 0;
231
+ const whereSql = where ? sql` where ${where}` : void 0;
232
+ const orderBySql = this.buildOrderBy(orderBy);
233
+ const limitSql = this.buildLimit(limit);
234
+ return sql`${withSql}delete from ${table}${whereSql}${returningSql}${orderBySql}${limitSql}`;
235
+ }
236
+ buildUpdateSet(table, set) {
237
+ const tableColumns = table[Table.Symbol.Columns];
238
+ const columnNames = Object.keys(tableColumns).filter(
239
+ (colName) => set[colName] !== void 0 || tableColumns[colName]?.onUpdateFn !== void 0
240
+ );
241
+ const setSize = columnNames.length;
242
+ return sql.join(
243
+ columnNames.flatMap((colName, i) => {
244
+ const col = tableColumns[colName];
245
+ const onUpdateFnResult = col.onUpdateFn?.();
246
+ const value = set[colName] ?? (is(onUpdateFnResult, SQL) ? onUpdateFnResult : sql.param(onUpdateFnResult, col));
247
+ const res = sql`${sql.identifier(this.casing.getColumnCasing(col))} = ${value}`;
248
+ if (i < setSize - 1) {
249
+ return [res, sql.raw(", ")];
250
+ }
251
+ return [res];
252
+ })
253
+ );
254
+ }
255
+ buildUpdateQuery({
256
+ table,
257
+ set,
258
+ where,
259
+ returning,
260
+ withList,
261
+ joins,
262
+ from,
263
+ limit,
264
+ orderBy
265
+ }) {
266
+ const withSql = this.buildWithCTE(withList);
267
+ const setSql = this.buildUpdateSet(table, set);
268
+ const fromSql = from && sql.join([sql.raw(" from "), this.buildFromTable(from)]);
269
+ const joinsSql = this.buildJoins(joins);
270
+ const returningSql = returning ? sql` returning ${this.buildSelection(returning, { isSingleTable: true })}` : void 0;
271
+ const whereSql = where ? sql` where ${where}` : void 0;
272
+ const orderBySql = this.buildOrderBy(orderBy);
273
+ const limitSql = this.buildLimit(limit);
274
+ return sql`${withSql}update ${table} set ${setSql}${fromSql}${joinsSql}${whereSql}${returningSql}${orderBySql}${limitSql}`;
275
+ }
276
+ /**
277
+ * Builds selection SQL with provided fields/expressions
278
+ *
279
+ * Examples:
280
+ *
281
+ * `select <selection> from`
282
+ *
283
+ * `insert ... returning <selection>`
284
+ *
285
+ * If `isSingleTable` is true, then columns won't be prefixed with table name
286
+ */
287
+ buildSelection(fields, { isSingleTable = false } = {}) {
288
+ const columnsLen = fields.length;
289
+ const chunks = fields.flatMap(({ field }, i) => {
290
+ const chunk = [];
291
+ if (is(field, SQL.Aliased) && field.isSelectionField) {
292
+ chunk.push(sql.identifier(field.fieldAlias));
293
+ } else if (is(field, SQL.Aliased) || is(field, SQL)) {
294
+ const query = is(field, SQL.Aliased) ? field.sql : field;
295
+ if (isSingleTable) {
296
+ chunk.push(
297
+ new SQL(
298
+ query.queryChunks.map((c) => {
299
+ if (is(c, Column)) {
300
+ return sql.identifier(this.casing.getColumnCasing(c));
301
+ }
302
+ return c;
303
+ })
304
+ )
305
+ );
306
+ } else {
307
+ chunk.push(query);
308
+ }
309
+ if (is(field, SQL.Aliased)) {
310
+ chunk.push(sql` as ${sql.identifier(field.fieldAlias)}`);
311
+ }
312
+ } else if (is(field, Column)) {
313
+ const tableName = field.table[Table.Symbol.Name];
314
+ if (field.columnType === "SQLiteNumericBigInt") {
315
+ if (isSingleTable) {
316
+ chunk.push(
317
+ sql`cast(${sql.identifier(this.casing.getColumnCasing(field))} as text)`
318
+ );
319
+ } else {
320
+ chunk.push(
321
+ sql`cast(${sql.identifier(tableName)}.${sql.identifier(this.casing.getColumnCasing(field))} as text)`
322
+ );
323
+ }
324
+ } else {
325
+ if (isSingleTable) {
326
+ chunk.push(sql.identifier(this.casing.getColumnCasing(field)));
327
+ } else {
328
+ chunk.push(
329
+ sql`${sql.identifier(tableName)}.${sql.identifier(this.casing.getColumnCasing(field))}`
330
+ );
331
+ }
332
+ }
333
+ } else if (is(field, Subquery)) {
334
+ const entries = Object.entries(field._.selectedFields);
335
+ if (entries.length === 1) {
336
+ const entry = entries[0][1];
337
+ const fieldDecoder = is(entry, SQL) ? entry.decoder : is(entry, Column) ? { mapFromDriverValue: (v) => entry.mapFromDriverValue(v) } : entry.sql.decoder;
338
+ if (fieldDecoder) field._.sql.decoder = fieldDecoder;
339
+ }
340
+ chunk.push(field);
341
+ }
342
+ if (i < columnsLen - 1) {
343
+ chunk.push(sql`, `);
344
+ }
345
+ return chunk;
346
+ });
347
+ return sql.join(chunks);
348
+ }
349
+ buildJoins(joins) {
350
+ if (!joins || joins.length === 0) {
351
+ return void 0;
352
+ }
353
+ const joinsArray = [];
354
+ if (joins) {
355
+ for (const [index, joinMeta] of joins.entries()) {
356
+ if (index === 0) {
357
+ joinsArray.push(sql` `);
358
+ }
359
+ const table = joinMeta.table;
360
+ const onSql = joinMeta.on ? sql` on ${joinMeta.on}` : void 0;
361
+ if (is(table, SQLiteTable)) {
362
+ const tableName = table[SQLiteTable.Symbol.Name];
363
+ const tableSchema = table[SQLiteTable.Symbol.Schema];
364
+ const origTableName = table[SQLiteTable.Symbol.OriginalName];
365
+ const alias = tableName === origTableName ? void 0 : joinMeta.alias;
366
+ joinsArray.push(
367
+ sql`${sql.raw(joinMeta.joinType)} join ${tableSchema ? sql`${sql.identifier(tableSchema)}.` : void 0}${sql.identifier(
368
+ origTableName
369
+ )}${alias && sql` ${sql.identifier(alias)}`}${onSql}`
370
+ );
371
+ } else {
372
+ joinsArray.push(
373
+ sql`${sql.raw(joinMeta.joinType)} join ${table}${onSql}`
374
+ );
375
+ }
376
+ if (index < joins.length - 1) {
377
+ joinsArray.push(sql` `);
378
+ }
379
+ }
380
+ }
381
+ return sql.join(joinsArray);
382
+ }
383
+ buildLimit(limit) {
384
+ return typeof limit === "object" || typeof limit === "number" && limit >= 0 ? sql` limit ${limit}` : void 0;
385
+ }
386
+ buildOrderBy(orderBy) {
387
+ const orderByList = [];
388
+ if (orderBy) {
389
+ for (const [index, orderByValue] of orderBy.entries()) {
390
+ orderByList.push(orderByValue);
391
+ if (index < orderBy.length - 1) {
392
+ orderByList.push(sql`, `);
393
+ }
394
+ }
395
+ }
396
+ return orderByList.length > 0 ? sql` order by ${sql.join(orderByList)}` : void 0;
397
+ }
398
+ buildFromTable(table) {
399
+ if (is(table, Table) && table[Table.Symbol.IsAlias]) {
400
+ return sql`${sql`${sql.identifier(table[Table.Symbol.Schema] ?? "")}.`.if(table[Table.Symbol.Schema])}${sql.identifier(
401
+ table[Table.Symbol.OriginalName]
402
+ )} ${sql.identifier(table[Table.Symbol.Name])}`;
403
+ }
404
+ return table;
405
+ }
406
+ buildSelectQuery({
407
+ withList,
408
+ fields,
409
+ fieldsFlat,
410
+ where,
411
+ having,
412
+ table,
413
+ joins,
414
+ orderBy,
415
+ groupBy,
416
+ limit,
417
+ offset,
418
+ distinct,
419
+ setOperators
420
+ }) {
421
+ const fieldsList = fieldsFlat ?? orderSelectedFields(fields);
422
+ for (const f of fieldsList) {
423
+ if (is(f.field, Column) && getTableName(f.field.table) !== (is(table, Subquery) ? table._.alias : is(table, SQLiteViewBase) ? table[ViewBaseConfig].name : is(table, SQL) ? void 0 : getTableName(table)) && !((table2) => joins?.some(
424
+ ({ alias }) => alias === (table2[Table.Symbol.IsAlias] ? getTableName(table2) : table2[Table.Symbol.BaseName])
425
+ ))(f.field.table)) {
426
+ const tableName = getTableName(f.field.table);
427
+ throw new Error(
428
+ `Your "${f.path.join(
429
+ "->"
430
+ )}" field references a column "${tableName}"."${f.field.name}", but the table "${tableName}" is not part of the query! Did you forget to join it?`
431
+ );
432
+ }
433
+ }
434
+ const isSingleTable = !joins || joins.length === 0;
435
+ const withSql = this.buildWithCTE(withList);
436
+ const distinctSql = distinct ? sql` distinct` : void 0;
437
+ const selection = this.buildSelection(fieldsList, { isSingleTable });
438
+ const tableSql = this.buildFromTable(table);
439
+ const joinsSql = this.buildJoins(joins);
440
+ const whereSql = where ? sql` where ${where}` : void 0;
441
+ const havingSql = having ? sql` having ${having}` : void 0;
442
+ const groupByList = [];
443
+ if (groupBy) {
444
+ for (const [index, groupByValue] of groupBy.entries()) {
445
+ groupByList.push(groupByValue);
446
+ if (index < groupBy.length - 1) {
447
+ groupByList.push(sql`, `);
448
+ }
449
+ }
450
+ }
451
+ const groupBySql = groupByList.length > 0 ? sql` group by ${sql.join(groupByList)}` : void 0;
452
+ const orderBySql = this.buildOrderBy(orderBy);
453
+ const limitSql = this.buildLimit(limit);
454
+ const offsetSql = offset ? sql` offset ${offset}` : void 0;
455
+ const finalQuery = sql`${withSql}select${distinctSql} ${selection} from ${tableSql}${joinsSql}${whereSql}${groupBySql}${havingSql}${orderBySql}${limitSql}${offsetSql}`;
456
+ if (setOperators.length > 0) {
457
+ return this.buildSetOperations(finalQuery, setOperators);
458
+ }
459
+ return finalQuery;
460
+ }
461
+ buildSetOperations(leftSelect, setOperators) {
462
+ const [setOperator, ...rest] = setOperators;
463
+ if (!setOperator) {
464
+ throw new Error("Cannot pass undefined values to any set operator");
465
+ }
466
+ if (rest.length === 0) {
467
+ return this.buildSetOperationQuery({ leftSelect, setOperator });
468
+ }
469
+ return this.buildSetOperations(
470
+ this.buildSetOperationQuery({ leftSelect, setOperator }),
471
+ rest
472
+ );
473
+ }
474
+ buildSetOperationQuery({
475
+ leftSelect,
476
+ setOperator: { type, isAll, rightSelect, limit, orderBy, offset }
477
+ }) {
478
+ const leftChunk = sql`${leftSelect.getSQL()} `;
479
+ const rightChunk = sql`${rightSelect.getSQL()}`;
480
+ let orderBySql;
481
+ if (orderBy && orderBy.length > 0) {
482
+ const orderByValues = [];
483
+ for (const singleOrderBy of orderBy) {
484
+ if (is(singleOrderBy, SQLiteColumn)) {
485
+ orderByValues.push(sql.identifier(singleOrderBy.name));
486
+ } else if (is(singleOrderBy, SQL)) {
487
+ for (let i = 0; i < singleOrderBy.queryChunks.length; i++) {
488
+ const chunk = singleOrderBy.queryChunks[i];
489
+ if (is(chunk, SQLiteColumn)) {
490
+ singleOrderBy.queryChunks[i] = sql.identifier(
491
+ this.casing.getColumnCasing(chunk)
492
+ );
493
+ }
494
+ }
495
+ orderByValues.push(sql`${singleOrderBy}`);
496
+ } else {
497
+ orderByValues.push(sql`${singleOrderBy}`);
498
+ }
499
+ }
500
+ orderBySql = sql` order by ${sql.join(orderByValues, sql`, `)}`;
501
+ }
502
+ const limitSql = typeof limit === "object" || typeof limit === "number" && limit >= 0 ? sql` limit ${limit}` : void 0;
503
+ const operatorChunk = sql.raw(`${type} ${isAll ? "all " : ""}`);
504
+ const offsetSql = offset ? sql` offset ${offset}` : void 0;
505
+ return sql`${leftChunk}${operatorChunk}${rightChunk}${orderBySql}${limitSql}${offsetSql}`;
506
+ }
507
+ buildInsertQuery({
508
+ table,
509
+ values: valuesOrSelect,
510
+ onConflict,
511
+ returning,
512
+ withList,
513
+ select
514
+ }) {
515
+ const valuesSqlList = [];
516
+ const columns = table[Table.Symbol.Columns];
517
+ const colEntries = Object.entries(columns).filter(
518
+ ([_, col]) => !col.shouldDisableInsert()
519
+ );
520
+ const insertOrder = colEntries.map(([, column]) => sql.identifier(this.casing.getColumnCasing(column)));
521
+ if (select) {
522
+ const select2 = valuesOrSelect;
523
+ if (is(select2, SQL)) {
524
+ valuesSqlList.push(select2);
525
+ } else {
526
+ valuesSqlList.push(select2.getSQL());
527
+ }
528
+ } else {
529
+ const values = valuesOrSelect;
530
+ valuesSqlList.push(sql.raw("values "));
531
+ for (const [valueIndex, value] of values.entries()) {
532
+ const valueList = [];
533
+ for (const [fieldName, col] of colEntries) {
534
+ const colValue = value[fieldName];
535
+ if (colValue === void 0 || is(colValue, Param) && colValue.value === void 0) {
536
+ let defaultValue;
537
+ if (col.default !== null && col.default !== void 0) {
538
+ defaultValue = is(col.default, SQL) ? col.default : sql.param(col.default, col);
539
+ } else if (col.defaultFn !== void 0) {
540
+ const defaultFnResult = col.defaultFn();
541
+ defaultValue = is(defaultFnResult, SQL) ? defaultFnResult : sql.param(defaultFnResult, col);
542
+ } else if (!col.default && col.onUpdateFn !== void 0) {
543
+ const onUpdateFnResult = col.onUpdateFn();
544
+ defaultValue = is(onUpdateFnResult, SQL) ? onUpdateFnResult : sql.param(onUpdateFnResult, col);
545
+ } else {
546
+ defaultValue = sql`null`;
547
+ }
548
+ valueList.push(defaultValue);
549
+ } else {
550
+ valueList.push(colValue);
551
+ }
552
+ }
553
+ valuesSqlList.push(valueList);
554
+ if (valueIndex < values.length - 1) {
555
+ valuesSqlList.push(sql`, `);
556
+ }
557
+ }
558
+ }
559
+ const withSql = this.buildWithCTE(withList);
560
+ const valuesSql = sql.join(valuesSqlList);
561
+ const returningSql = returning ? sql` returning ${this.buildSelection(returning, { isSingleTable: true })}` : void 0;
562
+ const onConflictSql = onConflict?.length ? sql.join(onConflict) : void 0;
563
+ return sql`${withSql}insert into ${table} ${insertOrder} ${valuesSql}${onConflictSql}${returningSql}`;
564
+ }
565
+ sqlToQuery(sql2, invokeSource) {
566
+ return sql2.toQuery({
567
+ casing: this.casing,
568
+ escapeName: this.escapeName,
569
+ escapeParam: this.escapeParam,
570
+ escapeString: this.escapeString,
571
+ invokeSource
572
+ });
573
+ }
574
+ buildRelationalQuery({
575
+ fullSchema,
576
+ schema,
577
+ tableNamesMap,
578
+ table,
579
+ tableConfig,
580
+ queryConfig: config,
581
+ tableAlias,
582
+ nestedQueryRelation,
583
+ joinOn
584
+ }) {
585
+ let selection = [];
586
+ let limit, offset, orderBy = [], where;
587
+ const joins = [];
588
+ if (config === true) {
589
+ const selectionEntries = Object.entries(tableConfig.columns);
590
+ selection = selectionEntries.map(([key, value]) => ({
591
+ dbKey: value.name,
592
+ tsKey: key,
593
+ field: aliasedTableColumn(value, tableAlias),
594
+ relationTableTsKey: void 0,
595
+ isJson: false,
596
+ selection: []
597
+ }));
598
+ } else {
599
+ const aliasedColumns = Object.fromEntries(
600
+ Object.entries(tableConfig.columns).map(([key, value]) => [
601
+ key,
602
+ aliasedTableColumn(value, tableAlias)
603
+ ])
604
+ );
605
+ if (config.where) {
606
+ const whereSql = typeof config.where === "function" ? config.where(aliasedColumns, getOperators()) : config.where;
607
+ where = whereSql && mapColumnsInSQLToAlias(whereSql, tableAlias);
608
+ }
609
+ const fieldsSelection = [];
610
+ let selectedColumns = [];
611
+ if (config.columns) {
612
+ let isIncludeMode = false;
613
+ for (const [field, value] of Object.entries(config.columns)) {
614
+ if (value === void 0) {
615
+ continue;
616
+ }
617
+ if (field in tableConfig.columns) {
618
+ if (!isIncludeMode && value === true) {
619
+ isIncludeMode = true;
620
+ }
621
+ selectedColumns.push(field);
622
+ }
623
+ }
624
+ if (selectedColumns.length > 0) {
625
+ selectedColumns = isIncludeMode ? selectedColumns.filter((c) => config.columns?.[c] === true) : Object.keys(tableConfig.columns).filter(
626
+ (key) => !selectedColumns.includes(key)
627
+ );
628
+ }
629
+ } else {
630
+ selectedColumns = Object.keys(tableConfig.columns);
631
+ }
632
+ for (const field of selectedColumns) {
633
+ const column = tableConfig.columns[field];
634
+ fieldsSelection.push({ tsKey: field, value: column });
635
+ }
636
+ let selectedRelations = [];
637
+ if (config.with) {
638
+ selectedRelations = Object.entries(config.with).filter(
639
+ (entry) => !!entry[1]
640
+ ).map(([tsKey, queryConfig]) => ({
641
+ tsKey,
642
+ queryConfig,
643
+ relation: tableConfig.relations[tsKey]
644
+ }));
645
+ }
646
+ let extras;
647
+ if (config.extras) {
648
+ extras = typeof config.extras === "function" ? config.extras(aliasedColumns, { sql }) : config.extras;
649
+ for (const [tsKey, value] of Object.entries(extras)) {
650
+ fieldsSelection.push({
651
+ tsKey,
652
+ value: mapColumnsInAliasedSQLToAlias(value, tableAlias)
653
+ });
654
+ }
655
+ }
656
+ for (const { tsKey, value } of fieldsSelection) {
657
+ selection.push({
658
+ dbKey: is(value, SQL.Aliased) ? value.fieldAlias : tableConfig.columns[tsKey].name,
659
+ tsKey,
660
+ field: is(value, Column) ? aliasedTableColumn(value, tableAlias) : value,
661
+ relationTableTsKey: void 0,
662
+ isJson: false,
663
+ selection: []
664
+ });
665
+ }
666
+ let orderByOrig = typeof config.orderBy === "function" ? config.orderBy(aliasedColumns, getOrderByOperators()) : config.orderBy ?? [];
667
+ if (!Array.isArray(orderByOrig)) {
668
+ orderByOrig = [orderByOrig];
669
+ }
670
+ orderBy = orderByOrig.map((orderByValue) => {
671
+ if (is(orderByValue, Column)) {
672
+ return aliasedTableColumn(orderByValue, tableAlias);
673
+ }
674
+ return mapColumnsInSQLToAlias(orderByValue, tableAlias);
675
+ });
676
+ limit = config.limit;
677
+ offset = config.offset;
678
+ for (const {
679
+ tsKey: selectedRelationTsKey,
680
+ queryConfig: selectedRelationConfigValue,
681
+ relation
682
+ } of selectedRelations) {
683
+ const normalizedRelation = normalizeRelation(
684
+ schema,
685
+ tableNamesMap,
686
+ relation
687
+ );
688
+ const relationTableName = getTableUniqueName(relation.referencedTable);
689
+ const relationTableTsName = tableNamesMap[relationTableName];
690
+ const relationTableAlias = `${tableAlias}_${selectedRelationTsKey}`;
691
+ const joinOn2 = and(
692
+ ...normalizedRelation.fields.map(
693
+ (field2, i) => eq(
694
+ aliasedTableColumn(
695
+ normalizedRelation.references[i],
696
+ relationTableAlias
697
+ ),
698
+ aliasedTableColumn(field2, tableAlias)
699
+ )
700
+ )
701
+ );
702
+ const builtRelation = this.buildRelationalQuery({
703
+ fullSchema,
704
+ schema,
705
+ tableNamesMap,
706
+ table: fullSchema[relationTableTsName],
707
+ tableConfig: schema[relationTableTsName],
708
+ queryConfig: is(relation, One) ? selectedRelationConfigValue === true ? { limit: 1 } : { ...selectedRelationConfigValue, limit: 1 } : selectedRelationConfigValue,
709
+ tableAlias: relationTableAlias,
710
+ joinOn: joinOn2,
711
+ nestedQueryRelation: relation
712
+ });
713
+ const field = sql`(${builtRelation.sql})`.as(selectedRelationTsKey);
714
+ selection.push({
715
+ dbKey: selectedRelationTsKey,
716
+ tsKey: selectedRelationTsKey,
717
+ field,
718
+ relationTableTsKey: relationTableTsName,
719
+ isJson: true,
720
+ selection: builtRelation.selection
721
+ });
722
+ }
723
+ }
724
+ if (selection.length === 0) {
725
+ throw new DrizzleError({
726
+ message: `No fields selected for table "${tableConfig.tsName}" ("${tableAlias}"). You need to have at least one item in "columns", "with" or "extras". If you need to select all columns, omit the "columns" key or set it to undefined.`
727
+ });
728
+ }
729
+ let result;
730
+ where = and(joinOn, where);
731
+ if (nestedQueryRelation) {
732
+ let field = sql`json_array(${sql.join(
733
+ selection.map(
734
+ ({ field: field2 }) => is(field2, SQLiteColumn) ? sql.identifier(this.casing.getColumnCasing(field2)) : is(field2, SQL.Aliased) ? field2.sql : field2
735
+ ),
736
+ sql`, `
737
+ )})`;
738
+ if (is(nestedQueryRelation, Many)) {
739
+ field = sql`coalesce(json_group_array(${field}), json_array())`;
740
+ }
741
+ const nestedSelection = [
742
+ {
743
+ dbKey: "data",
744
+ tsKey: "data",
745
+ field: field.as("data"),
746
+ isJson: true,
747
+ relationTableTsKey: tableConfig.tsName,
748
+ selection
749
+ }
750
+ ];
751
+ const needsSubquery = limit !== void 0 || offset !== void 0 || orderBy.length > 0;
752
+ if (needsSubquery) {
753
+ result = this.buildSelectQuery({
754
+ table: aliasedTable(table, tableAlias),
755
+ fields: {},
756
+ fieldsFlat: [
757
+ {
758
+ path: [],
759
+ field: sql.raw("*")
760
+ }
761
+ ],
762
+ where,
763
+ limit,
764
+ offset,
765
+ orderBy,
766
+ setOperators: []
767
+ });
768
+ where = void 0;
769
+ limit = void 0;
770
+ offset = void 0;
771
+ orderBy = void 0;
772
+ } else {
773
+ result = aliasedTable(table, tableAlias);
774
+ }
775
+ result = this.buildSelectQuery({
776
+ table: is(result, SQLiteTable) ? result : new Subquery(result, {}, tableAlias),
777
+ fields: {},
778
+ fieldsFlat: nestedSelection.map(({ field: field2 }) => ({
779
+ path: [],
780
+ field: is(field2, Column) ? aliasedTableColumn(field2, tableAlias) : field2
781
+ })),
782
+ joins,
783
+ where,
784
+ limit,
785
+ offset,
786
+ orderBy,
787
+ setOperators: []
788
+ });
789
+ } else {
790
+ result = this.buildSelectQuery({
791
+ table: aliasedTable(table, tableAlias),
792
+ fields: {},
793
+ fieldsFlat: selection.map(({ field }) => ({
794
+ path: [],
795
+ field: is(field, Column) ? aliasedTableColumn(field, tableAlias) : field
796
+ })),
797
+ joins,
798
+ where,
799
+ limit,
800
+ offset,
801
+ orderBy,
802
+ setOperators: []
803
+ });
804
+ }
805
+ return {
806
+ tableTsKey: tableConfig.tsName,
807
+ sql: result,
808
+ selection
809
+ };
810
+ }
811
+ };
812
+ var SQLiteSyncDialect = class extends SQLiteDialect {
813
+ static [entityKind] = "SQLiteSyncDialect";
814
+ migrate(migrations, session, config) {
815
+ const migrationsTable = config === void 0 ? "__drizzle_migrations" : typeof config === "string" ? "__drizzle_migrations" : config.migrationsTable ?? "__drizzle_migrations";
816
+ const migrationTableCreate = sql`
817
+ CREATE TABLE IF NOT EXISTS ${sql.identifier(migrationsTable)} (
818
+ id SERIAL PRIMARY KEY,
819
+ hash text NOT NULL,
820
+ created_at numeric
821
+ )
822
+ `;
823
+ session.run(migrationTableCreate);
824
+ const dbMigrations = session.values(
825
+ sql`SELECT id, hash, created_at FROM ${sql.identifier(migrationsTable)} ORDER BY created_at DESC LIMIT 1`
826
+ );
827
+ const lastDbMigration = dbMigrations[0] ?? void 0;
828
+ session.run(sql`BEGIN`);
829
+ try {
830
+ for (const migration of migrations) {
831
+ if (!lastDbMigration || Number(lastDbMigration[2]) < migration.folderMillis) {
832
+ for (const stmt of migration.sql) {
833
+ session.run(sql.raw(stmt));
834
+ }
835
+ session.run(
836
+ sql`INSERT INTO ${sql.identifier(
837
+ migrationsTable
838
+ )} ("hash", "created_at") VALUES(${migration.hash}, ${migration.folderMillis})`
839
+ );
840
+ }
841
+ }
842
+ session.run(sql`COMMIT`);
843
+ } catch (e) {
844
+ session.run(sql`ROLLBACK`);
845
+ throw e;
846
+ }
847
+ }
848
+ };
849
+ var SQLiteAsyncDialect = class extends SQLiteDialect {
850
+ static [entityKind] = "SQLiteAsyncDialect";
851
+ async migrate(migrations, session, config) {
852
+ const migrationsTable = config === void 0 ? "__drizzle_migrations" : typeof config === "string" ? "__drizzle_migrations" : config.migrationsTable ?? "__drizzle_migrations";
853
+ const migrationTableCreate = sql`
854
+ CREATE TABLE IF NOT EXISTS ${sql.identifier(migrationsTable)} (
855
+ id SERIAL PRIMARY KEY,
856
+ hash text NOT NULL,
857
+ created_at numeric
858
+ )
859
+ `;
860
+ await session.run(migrationTableCreate);
861
+ const dbMigrations = await session.values(
862
+ sql`SELECT id, hash, created_at FROM ${sql.identifier(migrationsTable)} ORDER BY created_at DESC LIMIT 1`
863
+ );
864
+ const lastDbMigration = dbMigrations[0] ?? void 0;
865
+ await session.transaction(async (tx) => {
866
+ for (const migration of migrations) {
867
+ if (!lastDbMigration || Number(lastDbMigration[2]) < migration.folderMillis) {
868
+ for (const stmt of migration.sql) {
869
+ await tx.run(sql.raw(stmt));
870
+ }
871
+ await tx.run(
872
+ sql`INSERT INTO ${sql.identifier(
873
+ migrationsTable
874
+ )} ("hash", "created_at") VALUES(${migration.hash}, ${migration.folderMillis})`
875
+ );
876
+ }
877
+ }
878
+ });
879
+ }
880
+ };
881
+
882
+ // ../../node_modules/.pnpm/drizzle-orm@0.45.2_@opentelemetry+api@1.9.1_@types+pg@8.20.0_kysely@0.29.2_pg@8.22.0/node_modules/drizzle-orm/sqlite-core/query-builders/select.js
883
+ var SQLiteSelectBuilder = class {
884
+ static [entityKind] = "SQLiteSelectBuilder";
885
+ fields;
886
+ session;
887
+ dialect;
888
+ withList;
889
+ distinct;
890
+ constructor(config) {
891
+ this.fields = config.fields;
892
+ this.session = config.session;
893
+ this.dialect = config.dialect;
894
+ this.withList = config.withList;
895
+ this.distinct = config.distinct;
896
+ }
897
+ from(source) {
898
+ const isPartialSelect = !!this.fields;
899
+ let fields;
900
+ if (this.fields) {
901
+ fields = this.fields;
902
+ } else if (is(source, Subquery)) {
903
+ fields = Object.fromEntries(
904
+ Object.keys(source._.selectedFields).map((key) => [key, source[key]])
905
+ );
906
+ } else if (is(source, SQLiteViewBase)) {
907
+ fields = source[ViewBaseConfig].selectedFields;
908
+ } else if (is(source, SQL)) {
909
+ fields = {};
910
+ } else {
911
+ fields = getTableColumns(source);
912
+ }
913
+ return new SQLiteSelectBase({
914
+ table: source,
915
+ fields,
916
+ isPartialSelect,
917
+ session: this.session,
918
+ dialect: this.dialect,
919
+ withList: this.withList,
920
+ distinct: this.distinct
921
+ });
922
+ }
923
+ };
924
+ var SQLiteSelectQueryBuilderBase = class extends TypedQueryBuilder {
925
+ static [entityKind] = "SQLiteSelectQueryBuilder";
926
+ _;
927
+ /** @internal */
928
+ config;
929
+ joinsNotNullableMap;
930
+ tableName;
931
+ isPartialSelect;
932
+ session;
933
+ dialect;
934
+ cacheConfig = void 0;
935
+ usedTables = /* @__PURE__ */ new Set();
936
+ constructor({ table, fields, isPartialSelect, session, dialect, withList, distinct }) {
937
+ super();
938
+ this.config = {
939
+ withList,
940
+ table,
941
+ fields: { ...fields },
942
+ distinct,
943
+ setOperators: []
944
+ };
945
+ this.isPartialSelect = isPartialSelect;
946
+ this.session = session;
947
+ this.dialect = dialect;
948
+ this._ = {
949
+ selectedFields: fields,
950
+ config: this.config
951
+ };
952
+ this.tableName = getTableLikeName(table);
953
+ this.joinsNotNullableMap = typeof this.tableName === "string" ? { [this.tableName]: true } : {};
954
+ for (const item of extractUsedTable(table)) this.usedTables.add(item);
955
+ }
956
+ /** @internal */
957
+ getUsedTables() {
958
+ return [...this.usedTables];
959
+ }
960
+ createJoin(joinType) {
961
+ return (table, on) => {
962
+ const baseTableName = this.tableName;
963
+ const tableName = getTableLikeName(table);
964
+ for (const item of extractUsedTable(table)) this.usedTables.add(item);
965
+ if (typeof tableName === "string" && this.config.joins?.some((join) => join.alias === tableName)) {
966
+ throw new Error(`Alias "${tableName}" is already used in this query`);
967
+ }
968
+ if (!this.isPartialSelect) {
969
+ if (Object.keys(this.joinsNotNullableMap).length === 1 && typeof baseTableName === "string") {
970
+ this.config.fields = {
971
+ [baseTableName]: this.config.fields
972
+ };
973
+ }
974
+ if (typeof tableName === "string" && !is(table, SQL)) {
975
+ const selection = is(table, Subquery) ? table._.selectedFields : is(table, View) ? table[ViewBaseConfig].selectedFields : table[Table.Symbol.Columns];
976
+ this.config.fields[tableName] = selection;
977
+ }
978
+ }
979
+ if (typeof on === "function") {
980
+ on = on(
981
+ new Proxy(
982
+ this.config.fields,
983
+ new SelectionProxyHandler({ sqlAliasedBehavior: "sql", sqlBehavior: "sql" })
984
+ )
985
+ );
986
+ }
987
+ if (!this.config.joins) {
988
+ this.config.joins = [];
989
+ }
990
+ this.config.joins.push({ on, table, joinType, alias: tableName });
991
+ if (typeof tableName === "string") {
992
+ switch (joinType) {
993
+ case "left": {
994
+ this.joinsNotNullableMap[tableName] = false;
995
+ break;
996
+ }
997
+ case "right": {
998
+ this.joinsNotNullableMap = Object.fromEntries(
999
+ Object.entries(this.joinsNotNullableMap).map(([key]) => [key, false])
1000
+ );
1001
+ this.joinsNotNullableMap[tableName] = true;
1002
+ break;
1003
+ }
1004
+ case "cross":
1005
+ case "inner": {
1006
+ this.joinsNotNullableMap[tableName] = true;
1007
+ break;
1008
+ }
1009
+ case "full": {
1010
+ this.joinsNotNullableMap = Object.fromEntries(
1011
+ Object.entries(this.joinsNotNullableMap).map(([key]) => [key, false])
1012
+ );
1013
+ this.joinsNotNullableMap[tableName] = false;
1014
+ break;
1015
+ }
1016
+ }
1017
+ }
1018
+ return this;
1019
+ };
1020
+ }
1021
+ /**
1022
+ * Executes a `left join` operation by adding another table to the current query.
1023
+ *
1024
+ * Calling this method associates each row of the table with the corresponding row from the joined table, if a match is found. If no matching row exists, it sets all columns of the joined table to null.
1025
+ *
1026
+ * See docs: {@link https://orm.drizzle.team/docs/joins#left-join}
1027
+ *
1028
+ * @param table the table to join.
1029
+ * @param on the `on` clause.
1030
+ *
1031
+ * @example
1032
+ *
1033
+ * ```ts
1034
+ * // Select all users and their pets
1035
+ * const usersWithPets: { user: User; pets: Pet | null; }[] = await db.select()
1036
+ * .from(users)
1037
+ * .leftJoin(pets, eq(users.id, pets.ownerId))
1038
+ *
1039
+ * // Select userId and petId
1040
+ * const usersIdsAndPetIds: { userId: number; petId: number | null; }[] = await db.select({
1041
+ * userId: users.id,
1042
+ * petId: pets.id,
1043
+ * })
1044
+ * .from(users)
1045
+ * .leftJoin(pets, eq(users.id, pets.ownerId))
1046
+ * ```
1047
+ */
1048
+ leftJoin = this.createJoin("left");
1049
+ /**
1050
+ * Executes a `right join` operation by adding another table to the current query.
1051
+ *
1052
+ * Calling this method associates each row of the joined table with the corresponding row from the main table, if a match is found. If no matching row exists, it sets all columns of the main table to null.
1053
+ *
1054
+ * See docs: {@link https://orm.drizzle.team/docs/joins#right-join}
1055
+ *
1056
+ * @param table the table to join.
1057
+ * @param on the `on` clause.
1058
+ *
1059
+ * @example
1060
+ *
1061
+ * ```ts
1062
+ * // Select all users and their pets
1063
+ * const usersWithPets: { user: User | null; pets: Pet; }[] = await db.select()
1064
+ * .from(users)
1065
+ * .rightJoin(pets, eq(users.id, pets.ownerId))
1066
+ *
1067
+ * // Select userId and petId
1068
+ * const usersIdsAndPetIds: { userId: number | null; petId: number; }[] = await db.select({
1069
+ * userId: users.id,
1070
+ * petId: pets.id,
1071
+ * })
1072
+ * .from(users)
1073
+ * .rightJoin(pets, eq(users.id, pets.ownerId))
1074
+ * ```
1075
+ */
1076
+ rightJoin = this.createJoin("right");
1077
+ /**
1078
+ * Executes an `inner join` operation, creating a new table by combining rows from two tables that have matching values.
1079
+ *
1080
+ * Calling this method retrieves rows that have corresponding entries in both joined tables. Rows without matching entries in either table are excluded, resulting in a table that includes only matching pairs.
1081
+ *
1082
+ * See docs: {@link https://orm.drizzle.team/docs/joins#inner-join}
1083
+ *
1084
+ * @param table the table to join.
1085
+ * @param on the `on` clause.
1086
+ *
1087
+ * @example
1088
+ *
1089
+ * ```ts
1090
+ * // Select all users and their pets
1091
+ * const usersWithPets: { user: User; pets: Pet; }[] = await db.select()
1092
+ * .from(users)
1093
+ * .innerJoin(pets, eq(users.id, pets.ownerId))
1094
+ *
1095
+ * // Select userId and petId
1096
+ * const usersIdsAndPetIds: { userId: number; petId: number; }[] = await db.select({
1097
+ * userId: users.id,
1098
+ * petId: pets.id,
1099
+ * })
1100
+ * .from(users)
1101
+ * .innerJoin(pets, eq(users.id, pets.ownerId))
1102
+ * ```
1103
+ */
1104
+ innerJoin = this.createJoin("inner");
1105
+ /**
1106
+ * Executes a `full join` operation by combining rows from two tables into a new table.
1107
+ *
1108
+ * Calling this method retrieves all rows from both main and joined tables, merging rows with matching values and filling in `null` for non-matching columns.
1109
+ *
1110
+ * See docs: {@link https://orm.drizzle.team/docs/joins#full-join}
1111
+ *
1112
+ * @param table the table to join.
1113
+ * @param on the `on` clause.
1114
+ *
1115
+ * @example
1116
+ *
1117
+ * ```ts
1118
+ * // Select all users and their pets
1119
+ * const usersWithPets: { user: User | null; pets: Pet | null; }[] = await db.select()
1120
+ * .from(users)
1121
+ * .fullJoin(pets, eq(users.id, pets.ownerId))
1122
+ *
1123
+ * // Select userId and petId
1124
+ * const usersIdsAndPetIds: { userId: number | null; petId: number | null; }[] = await db.select({
1125
+ * userId: users.id,
1126
+ * petId: pets.id,
1127
+ * })
1128
+ * .from(users)
1129
+ * .fullJoin(pets, eq(users.id, pets.ownerId))
1130
+ * ```
1131
+ */
1132
+ fullJoin = this.createJoin("full");
1133
+ /**
1134
+ * Executes a `cross join` operation by combining rows from two tables into a new table.
1135
+ *
1136
+ * Calling this method retrieves all rows from both main and joined tables, merging all rows from each table.
1137
+ *
1138
+ * See docs: {@link https://orm.drizzle.team/docs/joins#cross-join}
1139
+ *
1140
+ * @param table the table to join.
1141
+ *
1142
+ * @example
1143
+ *
1144
+ * ```ts
1145
+ * // Select all users, each user with every pet
1146
+ * const usersWithPets: { user: User; pets: Pet; }[] = await db.select()
1147
+ * .from(users)
1148
+ * .crossJoin(pets)
1149
+ *
1150
+ * // Select userId and petId
1151
+ * const usersIdsAndPetIds: { userId: number; petId: number; }[] = await db.select({
1152
+ * userId: users.id,
1153
+ * petId: pets.id,
1154
+ * })
1155
+ * .from(users)
1156
+ * .crossJoin(pets)
1157
+ * ```
1158
+ */
1159
+ crossJoin = this.createJoin("cross");
1160
+ createSetOperator(type, isAll) {
1161
+ return (rightSelection) => {
1162
+ const rightSelect = typeof rightSelection === "function" ? rightSelection(getSQLiteSetOperators()) : rightSelection;
1163
+ if (!haveSameKeys(this.getSelectedFields(), rightSelect.getSelectedFields())) {
1164
+ throw new Error(
1165
+ "Set operator error (union / intersect / except): selected fields are not the same or are in a different order"
1166
+ );
1167
+ }
1168
+ this.config.setOperators.push({ type, isAll, rightSelect });
1169
+ return this;
1170
+ };
1171
+ }
1172
+ /**
1173
+ * Adds `union` set operator to the query.
1174
+ *
1175
+ * Calling this method will combine the result sets of the `select` statements and remove any duplicate rows that appear across them.
1176
+ *
1177
+ * See docs: {@link https://orm.drizzle.team/docs/set-operations#union}
1178
+ *
1179
+ * @example
1180
+ *
1181
+ * ```ts
1182
+ * // Select all unique names from customers and users tables
1183
+ * await db.select({ name: users.name })
1184
+ * .from(users)
1185
+ * .union(
1186
+ * db.select({ name: customers.name }).from(customers)
1187
+ * );
1188
+ * // or
1189
+ * import { union } from 'drizzle-orm/sqlite-core'
1190
+ *
1191
+ * await union(
1192
+ * db.select({ name: users.name }).from(users),
1193
+ * db.select({ name: customers.name }).from(customers)
1194
+ * );
1195
+ * ```
1196
+ */
1197
+ union = this.createSetOperator("union", false);
1198
+ /**
1199
+ * Adds `union all` set operator to the query.
1200
+ *
1201
+ * Calling this method will combine the result-set of the `select` statements and keep all duplicate rows that appear across them.
1202
+ *
1203
+ * See docs: {@link https://orm.drizzle.team/docs/set-operations#union-all}
1204
+ *
1205
+ * @example
1206
+ *
1207
+ * ```ts
1208
+ * // Select all transaction ids from both online and in-store sales
1209
+ * await db.select({ transaction: onlineSales.transactionId })
1210
+ * .from(onlineSales)
1211
+ * .unionAll(
1212
+ * db.select({ transaction: inStoreSales.transactionId }).from(inStoreSales)
1213
+ * );
1214
+ * // or
1215
+ * import { unionAll } from 'drizzle-orm/sqlite-core'
1216
+ *
1217
+ * await unionAll(
1218
+ * db.select({ transaction: onlineSales.transactionId }).from(onlineSales),
1219
+ * db.select({ transaction: inStoreSales.transactionId }).from(inStoreSales)
1220
+ * );
1221
+ * ```
1222
+ */
1223
+ unionAll = this.createSetOperator("union", true);
1224
+ /**
1225
+ * Adds `intersect` set operator to the query.
1226
+ *
1227
+ * Calling this method will retain only the rows that are present in both result sets and eliminate duplicates.
1228
+ *
1229
+ * See docs: {@link https://orm.drizzle.team/docs/set-operations#intersect}
1230
+ *
1231
+ * @example
1232
+ *
1233
+ * ```ts
1234
+ * // Select course names that are offered in both departments A and B
1235
+ * await db.select({ courseName: depA.courseName })
1236
+ * .from(depA)
1237
+ * .intersect(
1238
+ * db.select({ courseName: depB.courseName }).from(depB)
1239
+ * );
1240
+ * // or
1241
+ * import { intersect } from 'drizzle-orm/sqlite-core'
1242
+ *
1243
+ * await intersect(
1244
+ * db.select({ courseName: depA.courseName }).from(depA),
1245
+ * db.select({ courseName: depB.courseName }).from(depB)
1246
+ * );
1247
+ * ```
1248
+ */
1249
+ intersect = this.createSetOperator("intersect", false);
1250
+ /**
1251
+ * Adds `except` set operator to the query.
1252
+ *
1253
+ * Calling this method will retrieve all unique rows from the left query, except for the rows that are present in the result set of the right query.
1254
+ *
1255
+ * See docs: {@link https://orm.drizzle.team/docs/set-operations#except}
1256
+ *
1257
+ * @example
1258
+ *
1259
+ * ```ts
1260
+ * // Select all courses offered in department A but not in department B
1261
+ * await db.select({ courseName: depA.courseName })
1262
+ * .from(depA)
1263
+ * .except(
1264
+ * db.select({ courseName: depB.courseName }).from(depB)
1265
+ * );
1266
+ * // or
1267
+ * import { except } from 'drizzle-orm/sqlite-core'
1268
+ *
1269
+ * await except(
1270
+ * db.select({ courseName: depA.courseName }).from(depA),
1271
+ * db.select({ courseName: depB.courseName }).from(depB)
1272
+ * );
1273
+ * ```
1274
+ */
1275
+ except = this.createSetOperator("except", false);
1276
+ /** @internal */
1277
+ addSetOperators(setOperators) {
1278
+ this.config.setOperators.push(...setOperators);
1279
+ return this;
1280
+ }
1281
+ /**
1282
+ * Adds a `where` clause to the query.
1283
+ *
1284
+ * Calling this method will select only those rows that fulfill a specified condition.
1285
+ *
1286
+ * See docs: {@link https://orm.drizzle.team/docs/select#filtering}
1287
+ *
1288
+ * @param where the `where` clause.
1289
+ *
1290
+ * @example
1291
+ * You can use conditional operators and `sql function` to filter the rows to be selected.
1292
+ *
1293
+ * ```ts
1294
+ * // Select all cars with green color
1295
+ * await db.select().from(cars).where(eq(cars.color, 'green'));
1296
+ * // or
1297
+ * await db.select().from(cars).where(sql`${cars.color} = 'green'`)
1298
+ * ```
1299
+ *
1300
+ * You can logically combine conditional operators with `and()` and `or()` operators:
1301
+ *
1302
+ * ```ts
1303
+ * // Select all BMW cars with a green color
1304
+ * await db.select().from(cars).where(and(eq(cars.color, 'green'), eq(cars.brand, 'BMW')));
1305
+ *
1306
+ * // Select all cars with the green or blue color
1307
+ * await db.select().from(cars).where(or(eq(cars.color, 'green'), eq(cars.color, 'blue')));
1308
+ * ```
1309
+ */
1310
+ where(where) {
1311
+ if (typeof where === "function") {
1312
+ where = where(
1313
+ new Proxy(
1314
+ this.config.fields,
1315
+ new SelectionProxyHandler({ sqlAliasedBehavior: "sql", sqlBehavior: "sql" })
1316
+ )
1317
+ );
1318
+ }
1319
+ this.config.where = where;
1320
+ return this;
1321
+ }
1322
+ /**
1323
+ * Adds a `having` clause to the query.
1324
+ *
1325
+ * Calling this method will select only those rows that fulfill a specified condition. It is typically used with aggregate functions to filter the aggregated data based on a specified condition.
1326
+ *
1327
+ * See docs: {@link https://orm.drizzle.team/docs/select#aggregations}
1328
+ *
1329
+ * @param having the `having` clause.
1330
+ *
1331
+ * @example
1332
+ *
1333
+ * ```ts
1334
+ * // Select all brands with more than one car
1335
+ * await db.select({
1336
+ * brand: cars.brand,
1337
+ * count: sql<number>`cast(count(${cars.id}) as int)`,
1338
+ * })
1339
+ * .from(cars)
1340
+ * .groupBy(cars.brand)
1341
+ * .having(({ count }) => gt(count, 1));
1342
+ * ```
1343
+ */
1344
+ having(having) {
1345
+ if (typeof having === "function") {
1346
+ having = having(
1347
+ new Proxy(
1348
+ this.config.fields,
1349
+ new SelectionProxyHandler({ sqlAliasedBehavior: "sql", sqlBehavior: "sql" })
1350
+ )
1351
+ );
1352
+ }
1353
+ this.config.having = having;
1354
+ return this;
1355
+ }
1356
+ groupBy(...columns) {
1357
+ if (typeof columns[0] === "function") {
1358
+ const groupBy = columns[0](
1359
+ new Proxy(
1360
+ this.config.fields,
1361
+ new SelectionProxyHandler({ sqlAliasedBehavior: "alias", sqlBehavior: "sql" })
1362
+ )
1363
+ );
1364
+ this.config.groupBy = Array.isArray(groupBy) ? groupBy : [groupBy];
1365
+ } else {
1366
+ this.config.groupBy = columns;
1367
+ }
1368
+ return this;
1369
+ }
1370
+ orderBy(...columns) {
1371
+ if (typeof columns[0] === "function") {
1372
+ const orderBy = columns[0](
1373
+ new Proxy(
1374
+ this.config.fields,
1375
+ new SelectionProxyHandler({ sqlAliasedBehavior: "alias", sqlBehavior: "sql" })
1376
+ )
1377
+ );
1378
+ const orderByArray = Array.isArray(orderBy) ? orderBy : [orderBy];
1379
+ if (this.config.setOperators.length > 0) {
1380
+ this.config.setOperators.at(-1).orderBy = orderByArray;
1381
+ } else {
1382
+ this.config.orderBy = orderByArray;
1383
+ }
1384
+ } else {
1385
+ const orderByArray = columns;
1386
+ if (this.config.setOperators.length > 0) {
1387
+ this.config.setOperators.at(-1).orderBy = orderByArray;
1388
+ } else {
1389
+ this.config.orderBy = orderByArray;
1390
+ }
1391
+ }
1392
+ return this;
1393
+ }
1394
+ /**
1395
+ * Adds a `limit` clause to the query.
1396
+ *
1397
+ * Calling this method will set the maximum number of rows that will be returned by this query.
1398
+ *
1399
+ * See docs: {@link https://orm.drizzle.team/docs/select#limit--offset}
1400
+ *
1401
+ * @param limit the `limit` clause.
1402
+ *
1403
+ * @example
1404
+ *
1405
+ * ```ts
1406
+ * // Get the first 10 people from this query.
1407
+ * await db.select().from(people).limit(10);
1408
+ * ```
1409
+ */
1410
+ limit(limit) {
1411
+ if (this.config.setOperators.length > 0) {
1412
+ this.config.setOperators.at(-1).limit = limit;
1413
+ } else {
1414
+ this.config.limit = limit;
1415
+ }
1416
+ return this;
1417
+ }
1418
+ /**
1419
+ * Adds an `offset` clause to the query.
1420
+ *
1421
+ * Calling this method will skip a number of rows when returning results from this query.
1422
+ *
1423
+ * See docs: {@link https://orm.drizzle.team/docs/select#limit--offset}
1424
+ *
1425
+ * @param offset the `offset` clause.
1426
+ *
1427
+ * @example
1428
+ *
1429
+ * ```ts
1430
+ * // Get the 10th-20th people from this query.
1431
+ * await db.select().from(people).offset(10).limit(10);
1432
+ * ```
1433
+ */
1434
+ offset(offset) {
1435
+ if (this.config.setOperators.length > 0) {
1436
+ this.config.setOperators.at(-1).offset = offset;
1437
+ } else {
1438
+ this.config.offset = offset;
1439
+ }
1440
+ return this;
1441
+ }
1442
+ /** @internal */
1443
+ getSQL() {
1444
+ return this.dialect.buildSelectQuery(this.config);
1445
+ }
1446
+ toSQL() {
1447
+ const { typings: _typings, ...rest } = this.dialect.sqlToQuery(this.getSQL());
1448
+ return rest;
1449
+ }
1450
+ as(alias) {
1451
+ const usedTables = [];
1452
+ usedTables.push(...extractUsedTable(this.config.table));
1453
+ if (this.config.joins) {
1454
+ for (const it of this.config.joins) usedTables.push(...extractUsedTable(it.table));
1455
+ }
1456
+ return new Proxy(
1457
+ new Subquery(this.getSQL(), this.config.fields, alias, false, [...new Set(usedTables)]),
1458
+ new SelectionProxyHandler({ alias, sqlAliasedBehavior: "alias", sqlBehavior: "error" })
1459
+ );
1460
+ }
1461
+ /** @internal */
1462
+ getSelectedFields() {
1463
+ return new Proxy(
1464
+ this.config.fields,
1465
+ new SelectionProxyHandler({ alias: this.tableName, sqlAliasedBehavior: "alias", sqlBehavior: "error" })
1466
+ );
1467
+ }
1468
+ $dynamic() {
1469
+ return this;
1470
+ }
1471
+ };
1472
+ var SQLiteSelectBase = class extends SQLiteSelectQueryBuilderBase {
1473
+ static [entityKind] = "SQLiteSelect";
1474
+ /** @internal */
1475
+ _prepare(isOneTimeQuery = true) {
1476
+ if (!this.session) {
1477
+ throw new Error("Cannot execute a query on a query builder. Please use a database instance instead.");
1478
+ }
1479
+ const fieldsList = orderSelectedFields(this.config.fields);
1480
+ const query = this.session[isOneTimeQuery ? "prepareOneTimeQuery" : "prepareQuery"](
1481
+ this.dialect.sqlToQuery(this.getSQL()),
1482
+ fieldsList,
1483
+ "all",
1484
+ true,
1485
+ void 0,
1486
+ {
1487
+ type: "select",
1488
+ tables: [...this.usedTables]
1489
+ },
1490
+ this.cacheConfig
1491
+ );
1492
+ query.joinsNotNullableMap = this.joinsNotNullableMap;
1493
+ return query;
1494
+ }
1495
+ $withCache(config) {
1496
+ this.cacheConfig = config === void 0 ? { config: {}, enable: true, autoInvalidate: true } : config === false ? { enable: false } : { enable: true, autoInvalidate: true, ...config };
1497
+ return this;
1498
+ }
1499
+ prepare() {
1500
+ return this._prepare(false);
1501
+ }
1502
+ run = (placeholderValues) => {
1503
+ return this._prepare().run(placeholderValues);
1504
+ };
1505
+ all = (placeholderValues) => {
1506
+ return this._prepare().all(placeholderValues);
1507
+ };
1508
+ get = (placeholderValues) => {
1509
+ return this._prepare().get(placeholderValues);
1510
+ };
1511
+ values = (placeholderValues) => {
1512
+ return this._prepare().values(placeholderValues);
1513
+ };
1514
+ async execute() {
1515
+ return this.all();
1516
+ }
1517
+ };
1518
+ applyMixins(SQLiteSelectBase, [QueryPromise]);
1519
+ function createSetOperator(type, isAll) {
1520
+ return (leftSelect, rightSelect, ...restSelects) => {
1521
+ const setOperators = [rightSelect, ...restSelects].map((select) => ({
1522
+ type,
1523
+ isAll,
1524
+ rightSelect: select
1525
+ }));
1526
+ for (const setOperator of setOperators) {
1527
+ if (!haveSameKeys(leftSelect.getSelectedFields(), setOperator.rightSelect.getSelectedFields())) {
1528
+ throw new Error(
1529
+ "Set operator error (union / intersect / except): selected fields are not the same or are in a different order"
1530
+ );
1531
+ }
1532
+ }
1533
+ return leftSelect.addSetOperators(setOperators);
1534
+ };
1535
+ }
1536
+ var getSQLiteSetOperators = () => ({
1537
+ union,
1538
+ unionAll,
1539
+ intersect,
1540
+ except
1541
+ });
1542
+ var union = createSetOperator("union", false);
1543
+ var unionAll = createSetOperator("union", true);
1544
+ var intersect = createSetOperator("intersect", false);
1545
+ var except = createSetOperator("except", false);
1546
+
1547
+ // ../../node_modules/.pnpm/drizzle-orm@0.45.2_@opentelemetry+api@1.9.1_@types+pg@8.20.0_kysely@0.29.2_pg@8.22.0/node_modules/drizzle-orm/sqlite-core/query-builders/query-builder.js
1548
+ var QueryBuilder = class {
1549
+ static [entityKind] = "SQLiteQueryBuilder";
1550
+ dialect;
1551
+ dialectConfig;
1552
+ constructor(dialect) {
1553
+ this.dialect = is(dialect, SQLiteDialect) ? dialect : void 0;
1554
+ this.dialectConfig = is(dialect, SQLiteDialect) ? void 0 : dialect;
1555
+ }
1556
+ $with = (alias, selection) => {
1557
+ const queryBuilder = this;
1558
+ const as = (qb) => {
1559
+ if (typeof qb === "function") {
1560
+ qb = qb(queryBuilder);
1561
+ }
1562
+ return new Proxy(
1563
+ new WithSubquery(
1564
+ qb.getSQL(),
1565
+ selection ?? ("getSelectedFields" in qb ? qb.getSelectedFields() ?? {} : {}),
1566
+ alias,
1567
+ true
1568
+ ),
1569
+ new SelectionProxyHandler({ alias, sqlAliasedBehavior: "alias", sqlBehavior: "error" })
1570
+ );
1571
+ };
1572
+ return { as };
1573
+ };
1574
+ with(...queries) {
1575
+ const self = this;
1576
+ function select(fields) {
1577
+ return new SQLiteSelectBuilder({
1578
+ fields: fields ?? void 0,
1579
+ session: void 0,
1580
+ dialect: self.getDialect(),
1581
+ withList: queries
1582
+ });
1583
+ }
1584
+ function selectDistinct(fields) {
1585
+ return new SQLiteSelectBuilder({
1586
+ fields: fields ?? void 0,
1587
+ session: void 0,
1588
+ dialect: self.getDialect(),
1589
+ withList: queries,
1590
+ distinct: true
1591
+ });
1592
+ }
1593
+ return { select, selectDistinct };
1594
+ }
1595
+ select(fields) {
1596
+ return new SQLiteSelectBuilder({ fields: fields ?? void 0, session: void 0, dialect: this.getDialect() });
1597
+ }
1598
+ selectDistinct(fields) {
1599
+ return new SQLiteSelectBuilder({
1600
+ fields: fields ?? void 0,
1601
+ session: void 0,
1602
+ dialect: this.getDialect(),
1603
+ distinct: true
1604
+ });
1605
+ }
1606
+ // Lazy load dialect to avoid circular dependency
1607
+ getDialect() {
1608
+ if (!this.dialect) {
1609
+ this.dialect = new SQLiteSyncDialect(this.dialectConfig);
1610
+ }
1611
+ return this.dialect;
1612
+ }
1613
+ };
1614
+
1615
+ // ../../node_modules/.pnpm/drizzle-orm@0.45.2_@opentelemetry+api@1.9.1_@types+pg@8.20.0_kysely@0.29.2_pg@8.22.0/node_modules/drizzle-orm/sqlite-core/query-builders/insert.js
1616
+ var SQLiteInsertBuilder = class {
1617
+ constructor(table, session, dialect, withList) {
1618
+ this.table = table;
1619
+ this.session = session;
1620
+ this.dialect = dialect;
1621
+ this.withList = withList;
1622
+ }
1623
+ static [entityKind] = "SQLiteInsertBuilder";
1624
+ values(values) {
1625
+ values = Array.isArray(values) ? values : [values];
1626
+ if (values.length === 0) {
1627
+ throw new Error("values() must be called with at least one value");
1628
+ }
1629
+ const mappedValues = values.map((entry) => {
1630
+ const result = {};
1631
+ const cols = this.table[Table.Symbol.Columns];
1632
+ for (const colKey of Object.keys(entry)) {
1633
+ const colValue = entry[colKey];
1634
+ result[colKey] = is(colValue, SQL) ? colValue : new Param(colValue, cols[colKey]);
1635
+ }
1636
+ return result;
1637
+ });
1638
+ return new SQLiteInsertBase(this.table, mappedValues, this.session, this.dialect, this.withList);
1639
+ }
1640
+ select(selectQuery) {
1641
+ const select = typeof selectQuery === "function" ? selectQuery(new QueryBuilder()) : selectQuery;
1642
+ if (!is(select, SQL) && !haveSameKeys(this.table[Columns], select._.selectedFields)) {
1643
+ throw new Error(
1644
+ "Insert select error: selected fields are not the same or are in a different order compared to the table definition"
1645
+ );
1646
+ }
1647
+ return new SQLiteInsertBase(this.table, select, this.session, this.dialect, this.withList, true);
1648
+ }
1649
+ };
1650
+ var SQLiteInsertBase = class extends QueryPromise {
1651
+ constructor(table, values, session, dialect, withList, select) {
1652
+ super();
1653
+ this.session = session;
1654
+ this.dialect = dialect;
1655
+ this.config = { table, values, withList, select };
1656
+ }
1657
+ static [entityKind] = "SQLiteInsert";
1658
+ /** @internal */
1659
+ config;
1660
+ returning(fields = this.config.table[SQLiteTable.Symbol.Columns]) {
1661
+ this.config.returning = orderSelectedFields(fields);
1662
+ return this;
1663
+ }
1664
+ /**
1665
+ * Adds an `on conflict do nothing` clause to the query.
1666
+ *
1667
+ * Calling this method simply avoids inserting a row as its alternative action.
1668
+ *
1669
+ * See docs: {@link https://orm.drizzle.team/docs/insert#on-conflict-do-nothing}
1670
+ *
1671
+ * @param config The `target` and `where` clauses.
1672
+ *
1673
+ * @example
1674
+ * ```ts
1675
+ * // Insert one row and cancel the insert if there's a conflict
1676
+ * await db.insert(cars)
1677
+ * .values({ id: 1, brand: 'BMW' })
1678
+ * .onConflictDoNothing();
1679
+ *
1680
+ * // Explicitly specify conflict target
1681
+ * await db.insert(cars)
1682
+ * .values({ id: 1, brand: 'BMW' })
1683
+ * .onConflictDoNothing({ target: cars.id });
1684
+ * ```
1685
+ */
1686
+ onConflictDoNothing(config = {}) {
1687
+ if (!this.config.onConflict) this.config.onConflict = [];
1688
+ if (config.target === void 0) {
1689
+ this.config.onConflict.push(sql` on conflict do nothing`);
1690
+ } else {
1691
+ const targetSql = Array.isArray(config.target) ? sql`${config.target}` : sql`${[config.target]}`;
1692
+ const whereSql = config.where ? sql` where ${config.where}` : sql``;
1693
+ this.config.onConflict.push(sql` on conflict ${targetSql} do nothing${whereSql}`);
1694
+ }
1695
+ return this;
1696
+ }
1697
+ /**
1698
+ * Adds an `on conflict do update` clause to the query.
1699
+ *
1700
+ * Calling this method will update the existing row that conflicts with the row proposed for insertion as its alternative action.
1701
+ *
1702
+ * See docs: {@link https://orm.drizzle.team/docs/insert#upserts-and-conflicts}
1703
+ *
1704
+ * @param config The `target`, `set` and `where` clauses.
1705
+ *
1706
+ * @example
1707
+ * ```ts
1708
+ * // Update the row if there's a conflict
1709
+ * await db.insert(cars)
1710
+ * .values({ id: 1, brand: 'BMW' })
1711
+ * .onConflictDoUpdate({
1712
+ * target: cars.id,
1713
+ * set: { brand: 'Porsche' }
1714
+ * });
1715
+ *
1716
+ * // Upsert with 'where' clause
1717
+ * await db.insert(cars)
1718
+ * .values({ id: 1, brand: 'BMW' })
1719
+ * .onConflictDoUpdate({
1720
+ * target: cars.id,
1721
+ * set: { brand: 'newBMW' },
1722
+ * where: sql`${cars.createdAt} > '2023-01-01'::date`,
1723
+ * });
1724
+ * ```
1725
+ */
1726
+ onConflictDoUpdate(config) {
1727
+ if (config.where && (config.targetWhere || config.setWhere)) {
1728
+ throw new Error(
1729
+ 'You cannot use both "where" and "targetWhere"/"setWhere" at the same time - "where" is deprecated, use "targetWhere" or "setWhere" instead.'
1730
+ );
1731
+ }
1732
+ if (!this.config.onConflict) this.config.onConflict = [];
1733
+ const whereSql = config.where ? sql` where ${config.where}` : void 0;
1734
+ const targetWhereSql = config.targetWhere ? sql` where ${config.targetWhere}` : void 0;
1735
+ const setWhereSql = config.setWhere ? sql` where ${config.setWhere}` : void 0;
1736
+ const targetSql = Array.isArray(config.target) ? sql`${config.target}` : sql`${[config.target]}`;
1737
+ const setSql = this.dialect.buildUpdateSet(this.config.table, mapUpdateSet(this.config.table, config.set));
1738
+ this.config.onConflict.push(
1739
+ sql` on conflict ${targetSql}${targetWhereSql} do update set ${setSql}${whereSql}${setWhereSql}`
1740
+ );
1741
+ return this;
1742
+ }
1743
+ /** @internal */
1744
+ getSQL() {
1745
+ return this.dialect.buildInsertQuery(this.config);
1746
+ }
1747
+ toSQL() {
1748
+ const { typings: _typings, ...rest } = this.dialect.sqlToQuery(this.getSQL());
1749
+ return rest;
1750
+ }
1751
+ /** @internal */
1752
+ _prepare(isOneTimeQuery = true) {
1753
+ return this.session[isOneTimeQuery ? "prepareOneTimeQuery" : "prepareQuery"](
1754
+ this.dialect.sqlToQuery(this.getSQL()),
1755
+ this.config.returning,
1756
+ this.config.returning ? "all" : "run",
1757
+ true,
1758
+ void 0,
1759
+ {
1760
+ type: "insert",
1761
+ tables: extractUsedTable(this.config.table)
1762
+ }
1763
+ );
1764
+ }
1765
+ prepare() {
1766
+ return this._prepare(false);
1767
+ }
1768
+ run = (placeholderValues) => {
1769
+ return this._prepare().run(placeholderValues);
1770
+ };
1771
+ all = (placeholderValues) => {
1772
+ return this._prepare().all(placeholderValues);
1773
+ };
1774
+ get = (placeholderValues) => {
1775
+ return this._prepare().get(placeholderValues);
1776
+ };
1777
+ values = (placeholderValues) => {
1778
+ return this._prepare().values(placeholderValues);
1779
+ };
1780
+ async execute() {
1781
+ return this.config.returning ? this.all() : this.run();
1782
+ }
1783
+ $dynamic() {
1784
+ return this;
1785
+ }
1786
+ };
1787
+
1788
+ // ../../node_modules/.pnpm/drizzle-orm@0.45.2_@opentelemetry+api@1.9.1_@types+pg@8.20.0_kysely@0.29.2_pg@8.22.0/node_modules/drizzle-orm/sqlite-core/query-builders/update.js
1789
+ var SQLiteUpdateBuilder = class {
1790
+ constructor(table, session, dialect, withList) {
1791
+ this.table = table;
1792
+ this.session = session;
1793
+ this.dialect = dialect;
1794
+ this.withList = withList;
1795
+ }
1796
+ static [entityKind] = "SQLiteUpdateBuilder";
1797
+ set(values) {
1798
+ return new SQLiteUpdateBase(
1799
+ this.table,
1800
+ mapUpdateSet(this.table, values),
1801
+ this.session,
1802
+ this.dialect,
1803
+ this.withList
1804
+ );
1805
+ }
1806
+ };
1807
+ var SQLiteUpdateBase = class extends QueryPromise {
1808
+ constructor(table, set, session, dialect, withList) {
1809
+ super();
1810
+ this.session = session;
1811
+ this.dialect = dialect;
1812
+ this.config = { set, table, withList, joins: [] };
1813
+ }
1814
+ static [entityKind] = "SQLiteUpdate";
1815
+ /** @internal */
1816
+ config;
1817
+ from(source) {
1818
+ this.config.from = source;
1819
+ return this;
1820
+ }
1821
+ createJoin(joinType) {
1822
+ return (table, on) => {
1823
+ const tableName = getTableLikeName(table);
1824
+ if (typeof tableName === "string" && this.config.joins.some((join) => join.alias === tableName)) {
1825
+ throw new Error(`Alias "${tableName}" is already used in this query`);
1826
+ }
1827
+ if (typeof on === "function") {
1828
+ const from = this.config.from ? is(table, SQLiteTable) ? table[Table.Symbol.Columns] : is(table, Subquery) ? table._.selectedFields : is(table, SQLiteViewBase) ? table[ViewBaseConfig].selectedFields : void 0 : void 0;
1829
+ on = on(
1830
+ new Proxy(
1831
+ this.config.table[Table.Symbol.Columns],
1832
+ new SelectionProxyHandler({ sqlAliasedBehavior: "sql", sqlBehavior: "sql" })
1833
+ ),
1834
+ from && new Proxy(
1835
+ from,
1836
+ new SelectionProxyHandler({ sqlAliasedBehavior: "sql", sqlBehavior: "sql" })
1837
+ )
1838
+ );
1839
+ }
1840
+ this.config.joins.push({ on, table, joinType, alias: tableName });
1841
+ return this;
1842
+ };
1843
+ }
1844
+ leftJoin = this.createJoin("left");
1845
+ rightJoin = this.createJoin("right");
1846
+ innerJoin = this.createJoin("inner");
1847
+ fullJoin = this.createJoin("full");
1848
+ /**
1849
+ * Adds a 'where' clause to the query.
1850
+ *
1851
+ * Calling this method will update only those rows that fulfill a specified condition.
1852
+ *
1853
+ * See docs: {@link https://orm.drizzle.team/docs/update}
1854
+ *
1855
+ * @param where the 'where' clause.
1856
+ *
1857
+ * @example
1858
+ * You can use conditional operators and `sql function` to filter the rows to be updated.
1859
+ *
1860
+ * ```ts
1861
+ * // Update all cars with green color
1862
+ * db.update(cars).set({ color: 'red' })
1863
+ * .where(eq(cars.color, 'green'));
1864
+ * // or
1865
+ * db.update(cars).set({ color: 'red' })
1866
+ * .where(sql`${cars.color} = 'green'`)
1867
+ * ```
1868
+ *
1869
+ * You can logically combine conditional operators with `and()` and `or()` operators:
1870
+ *
1871
+ * ```ts
1872
+ * // Update all BMW cars with a green color
1873
+ * db.update(cars).set({ color: 'red' })
1874
+ * .where(and(eq(cars.color, 'green'), eq(cars.brand, 'BMW')));
1875
+ *
1876
+ * // Update all cars with the green or blue color
1877
+ * db.update(cars).set({ color: 'red' })
1878
+ * .where(or(eq(cars.color, 'green'), eq(cars.color, 'blue')));
1879
+ * ```
1880
+ */
1881
+ where(where) {
1882
+ this.config.where = where;
1883
+ return this;
1884
+ }
1885
+ orderBy(...columns) {
1886
+ if (typeof columns[0] === "function") {
1887
+ const orderBy = columns[0](
1888
+ new Proxy(
1889
+ this.config.table[Table.Symbol.Columns],
1890
+ new SelectionProxyHandler({ sqlAliasedBehavior: "alias", sqlBehavior: "sql" })
1891
+ )
1892
+ );
1893
+ const orderByArray = Array.isArray(orderBy) ? orderBy : [orderBy];
1894
+ this.config.orderBy = orderByArray;
1895
+ } else {
1896
+ const orderByArray = columns;
1897
+ this.config.orderBy = orderByArray;
1898
+ }
1899
+ return this;
1900
+ }
1901
+ limit(limit) {
1902
+ this.config.limit = limit;
1903
+ return this;
1904
+ }
1905
+ returning(fields = this.config.table[SQLiteTable.Symbol.Columns]) {
1906
+ this.config.returning = orderSelectedFields(fields);
1907
+ return this;
1908
+ }
1909
+ /** @internal */
1910
+ getSQL() {
1911
+ return this.dialect.buildUpdateQuery(this.config);
1912
+ }
1913
+ toSQL() {
1914
+ const { typings: _typings, ...rest } = this.dialect.sqlToQuery(this.getSQL());
1915
+ return rest;
1916
+ }
1917
+ /** @internal */
1918
+ _prepare(isOneTimeQuery = true) {
1919
+ return this.session[isOneTimeQuery ? "prepareOneTimeQuery" : "prepareQuery"](
1920
+ this.dialect.sqlToQuery(this.getSQL()),
1921
+ this.config.returning,
1922
+ this.config.returning ? "all" : "run",
1923
+ true,
1924
+ void 0,
1925
+ {
1926
+ type: "insert",
1927
+ tables: extractUsedTable(this.config.table)
1928
+ }
1929
+ );
1930
+ }
1931
+ prepare() {
1932
+ return this._prepare(false);
1933
+ }
1934
+ run = (placeholderValues) => {
1935
+ return this._prepare().run(placeholderValues);
1936
+ };
1937
+ all = (placeholderValues) => {
1938
+ return this._prepare().all(placeholderValues);
1939
+ };
1940
+ get = (placeholderValues) => {
1941
+ return this._prepare().get(placeholderValues);
1942
+ };
1943
+ values = (placeholderValues) => {
1944
+ return this._prepare().values(placeholderValues);
1945
+ };
1946
+ async execute() {
1947
+ return this.config.returning ? this.all() : this.run();
1948
+ }
1949
+ $dynamic() {
1950
+ return this;
1951
+ }
1952
+ };
1953
+
1954
+ // ../../node_modules/.pnpm/drizzle-orm@0.45.2_@opentelemetry+api@1.9.1_@types+pg@8.20.0_kysely@0.29.2_pg@8.22.0/node_modules/drizzle-orm/sqlite-core/query-builders/count.js
1955
+ var SQLiteCountBuilder = class _SQLiteCountBuilder extends SQL {
1956
+ constructor(params) {
1957
+ super(_SQLiteCountBuilder.buildEmbeddedCount(params.source, params.filters).queryChunks);
1958
+ this.params = params;
1959
+ this.session = params.session;
1960
+ this.sql = _SQLiteCountBuilder.buildCount(
1961
+ params.source,
1962
+ params.filters
1963
+ );
1964
+ }
1965
+ sql;
1966
+ static [entityKind] = "SQLiteCountBuilderAsync";
1967
+ [Symbol.toStringTag] = "SQLiteCountBuilderAsync";
1968
+ session;
1969
+ static buildEmbeddedCount(source, filters) {
1970
+ return sql`(select count(*) from ${source}${sql.raw(" where ").if(filters)}${filters})`;
1971
+ }
1972
+ static buildCount(source, filters) {
1973
+ return sql`select count(*) from ${source}${sql.raw(" where ").if(filters)}${filters}`;
1974
+ }
1975
+ then(onfulfilled, onrejected) {
1976
+ return Promise.resolve(this.session.count(this.sql)).then(
1977
+ onfulfilled,
1978
+ onrejected
1979
+ );
1980
+ }
1981
+ catch(onRejected) {
1982
+ return this.then(void 0, onRejected);
1983
+ }
1984
+ finally(onFinally) {
1985
+ return this.then(
1986
+ (value) => {
1987
+ onFinally?.();
1988
+ return value;
1989
+ },
1990
+ (reason) => {
1991
+ onFinally?.();
1992
+ throw reason;
1993
+ }
1994
+ );
1995
+ }
1996
+ };
1997
+
1998
+ // ../../node_modules/.pnpm/drizzle-orm@0.45.2_@opentelemetry+api@1.9.1_@types+pg@8.20.0_kysely@0.29.2_pg@8.22.0/node_modules/drizzle-orm/sqlite-core/query-builders/query.js
1999
+ var RelationalQueryBuilder = class {
2000
+ constructor(mode, fullSchema, schema, tableNamesMap, table, tableConfig, dialect, session) {
2001
+ this.mode = mode;
2002
+ this.fullSchema = fullSchema;
2003
+ this.schema = schema;
2004
+ this.tableNamesMap = tableNamesMap;
2005
+ this.table = table;
2006
+ this.tableConfig = tableConfig;
2007
+ this.dialect = dialect;
2008
+ this.session = session;
2009
+ }
2010
+ static [entityKind] = "SQLiteAsyncRelationalQueryBuilder";
2011
+ findMany(config) {
2012
+ return this.mode === "sync" ? new SQLiteSyncRelationalQuery(
2013
+ this.fullSchema,
2014
+ this.schema,
2015
+ this.tableNamesMap,
2016
+ this.table,
2017
+ this.tableConfig,
2018
+ this.dialect,
2019
+ this.session,
2020
+ config ? config : {},
2021
+ "many"
2022
+ ) : new SQLiteRelationalQuery(
2023
+ this.fullSchema,
2024
+ this.schema,
2025
+ this.tableNamesMap,
2026
+ this.table,
2027
+ this.tableConfig,
2028
+ this.dialect,
2029
+ this.session,
2030
+ config ? config : {},
2031
+ "many"
2032
+ );
2033
+ }
2034
+ findFirst(config) {
2035
+ return this.mode === "sync" ? new SQLiteSyncRelationalQuery(
2036
+ this.fullSchema,
2037
+ this.schema,
2038
+ this.tableNamesMap,
2039
+ this.table,
2040
+ this.tableConfig,
2041
+ this.dialect,
2042
+ this.session,
2043
+ config ? { ...config, limit: 1 } : { limit: 1 },
2044
+ "first"
2045
+ ) : new SQLiteRelationalQuery(
2046
+ this.fullSchema,
2047
+ this.schema,
2048
+ this.tableNamesMap,
2049
+ this.table,
2050
+ this.tableConfig,
2051
+ this.dialect,
2052
+ this.session,
2053
+ config ? { ...config, limit: 1 } : { limit: 1 },
2054
+ "first"
2055
+ );
2056
+ }
2057
+ };
2058
+ var SQLiteRelationalQuery = class extends QueryPromise {
2059
+ constructor(fullSchema, schema, tableNamesMap, table, tableConfig, dialect, session, config, mode) {
2060
+ super();
2061
+ this.fullSchema = fullSchema;
2062
+ this.schema = schema;
2063
+ this.tableNamesMap = tableNamesMap;
2064
+ this.table = table;
2065
+ this.tableConfig = tableConfig;
2066
+ this.dialect = dialect;
2067
+ this.session = session;
2068
+ this.config = config;
2069
+ this.mode = mode;
2070
+ }
2071
+ static [entityKind] = "SQLiteAsyncRelationalQuery";
2072
+ /** @internal */
2073
+ mode;
2074
+ /** @internal */
2075
+ getSQL() {
2076
+ return this.dialect.buildRelationalQuery({
2077
+ fullSchema: this.fullSchema,
2078
+ schema: this.schema,
2079
+ tableNamesMap: this.tableNamesMap,
2080
+ table: this.table,
2081
+ tableConfig: this.tableConfig,
2082
+ queryConfig: this.config,
2083
+ tableAlias: this.tableConfig.tsName
2084
+ }).sql;
2085
+ }
2086
+ /** @internal */
2087
+ _prepare(isOneTimeQuery = false) {
2088
+ const { query, builtQuery } = this._toSQL();
2089
+ return this.session[isOneTimeQuery ? "prepareOneTimeQuery" : "prepareQuery"](
2090
+ builtQuery,
2091
+ void 0,
2092
+ this.mode === "first" ? "get" : "all",
2093
+ true,
2094
+ (rawRows, mapColumnValue) => {
2095
+ const rows = rawRows.map(
2096
+ (row) => mapRelationalRow(this.schema, this.tableConfig, row, query.selection, mapColumnValue)
2097
+ );
2098
+ if (this.mode === "first") {
2099
+ return rows[0];
2100
+ }
2101
+ return rows;
2102
+ }
2103
+ );
2104
+ }
2105
+ prepare() {
2106
+ return this._prepare(false);
2107
+ }
2108
+ _toSQL() {
2109
+ const query = this.dialect.buildRelationalQuery({
2110
+ fullSchema: this.fullSchema,
2111
+ schema: this.schema,
2112
+ tableNamesMap: this.tableNamesMap,
2113
+ table: this.table,
2114
+ tableConfig: this.tableConfig,
2115
+ queryConfig: this.config,
2116
+ tableAlias: this.tableConfig.tsName
2117
+ });
2118
+ const builtQuery = this.dialect.sqlToQuery(query.sql);
2119
+ return { query, builtQuery };
2120
+ }
2121
+ toSQL() {
2122
+ return this._toSQL().builtQuery;
2123
+ }
2124
+ /** @internal */
2125
+ executeRaw() {
2126
+ if (this.mode === "first") {
2127
+ return this._prepare(false).get();
2128
+ }
2129
+ return this._prepare(false).all();
2130
+ }
2131
+ async execute() {
2132
+ return this.executeRaw();
2133
+ }
2134
+ };
2135
+ var SQLiteSyncRelationalQuery = class extends SQLiteRelationalQuery {
2136
+ static [entityKind] = "SQLiteSyncRelationalQuery";
2137
+ sync() {
2138
+ return this.executeRaw();
2139
+ }
2140
+ };
2141
+
2142
+ // ../../node_modules/.pnpm/drizzle-orm@0.45.2_@opentelemetry+api@1.9.1_@types+pg@8.20.0_kysely@0.29.2_pg@8.22.0/node_modules/drizzle-orm/sqlite-core/query-builders/raw.js
2143
+ var SQLiteRaw = class extends QueryPromise {
2144
+ constructor(execute, getSQL, action, dialect, mapBatchResult) {
2145
+ super();
2146
+ this.execute = execute;
2147
+ this.getSQL = getSQL;
2148
+ this.dialect = dialect;
2149
+ this.mapBatchResult = mapBatchResult;
2150
+ this.config = { action };
2151
+ }
2152
+ static [entityKind] = "SQLiteRaw";
2153
+ /** @internal */
2154
+ config;
2155
+ getQuery() {
2156
+ return { ...this.dialect.sqlToQuery(this.getSQL()), method: this.config.action };
2157
+ }
2158
+ mapResult(result, isFromBatch) {
2159
+ return isFromBatch ? this.mapBatchResult(result) : result;
2160
+ }
2161
+ _prepare() {
2162
+ return this;
2163
+ }
2164
+ /** @internal */
2165
+ isResponseInArrayMode() {
2166
+ return false;
2167
+ }
2168
+ };
2169
+
2170
+ // ../../node_modules/.pnpm/drizzle-orm@0.45.2_@opentelemetry+api@1.9.1_@types+pg@8.20.0_kysely@0.29.2_pg@8.22.0/node_modules/drizzle-orm/sqlite-core/db.js
2171
+ var BaseSQLiteDatabase = class {
2172
+ constructor(resultKind, dialect, session, schema) {
2173
+ this.resultKind = resultKind;
2174
+ this.dialect = dialect;
2175
+ this.session = session;
2176
+ this._ = schema ? {
2177
+ schema: schema.schema,
2178
+ fullSchema: schema.fullSchema,
2179
+ tableNamesMap: schema.tableNamesMap
2180
+ } : {
2181
+ schema: void 0,
2182
+ fullSchema: {},
2183
+ tableNamesMap: {}
2184
+ };
2185
+ this.query = {};
2186
+ const query = this.query;
2187
+ if (this._.schema) {
2188
+ for (const [tableName, columns] of Object.entries(this._.schema)) {
2189
+ query[tableName] = new RelationalQueryBuilder(
2190
+ resultKind,
2191
+ schema.fullSchema,
2192
+ this._.schema,
2193
+ this._.tableNamesMap,
2194
+ schema.fullSchema[tableName],
2195
+ columns,
2196
+ dialect,
2197
+ session
2198
+ );
2199
+ }
2200
+ }
2201
+ this.$cache = { invalidate: async (_params) => {
2202
+ } };
2203
+ }
2204
+ static [entityKind] = "BaseSQLiteDatabase";
2205
+ query;
2206
+ /**
2207
+ * Creates a subquery that defines a temporary named result set as a CTE.
2208
+ *
2209
+ * It is useful for breaking down complex queries into simpler parts and for reusing the result set in subsequent parts of the query.
2210
+ *
2211
+ * See docs: {@link https://orm.drizzle.team/docs/select#with-clause}
2212
+ *
2213
+ * @param alias The alias for the subquery.
2214
+ *
2215
+ * Failure to provide an alias will result in a DrizzleTypeError, preventing the subquery from being referenced in other queries.
2216
+ *
2217
+ * @example
2218
+ *
2219
+ * ```ts
2220
+ * // Create a subquery with alias 'sq' and use it in the select query
2221
+ * const sq = db.$with('sq').as(db.select().from(users).where(eq(users.id, 42)));
2222
+ *
2223
+ * const result = await db.with(sq).select().from(sq);
2224
+ * ```
2225
+ *
2226
+ * To select arbitrary SQL values as fields in a CTE and reference them in other CTEs or in the main query, you need to add aliases to them:
2227
+ *
2228
+ * ```ts
2229
+ * // Select an arbitrary SQL value as a field in a CTE and reference it in the main query
2230
+ * const sq = db.$with('sq').as(db.select({
2231
+ * name: sql<string>`upper(${users.name})`.as('name'),
2232
+ * })
2233
+ * .from(users));
2234
+ *
2235
+ * const result = await db.with(sq).select({ name: sq.name }).from(sq);
2236
+ * ```
2237
+ */
2238
+ $with = (alias, selection) => {
2239
+ const self = this;
2240
+ const as = (qb) => {
2241
+ if (typeof qb === "function") {
2242
+ qb = qb(new QueryBuilder(self.dialect));
2243
+ }
2244
+ return new Proxy(
2245
+ new WithSubquery(
2246
+ qb.getSQL(),
2247
+ selection ?? ("getSelectedFields" in qb ? qb.getSelectedFields() ?? {} : {}),
2248
+ alias,
2249
+ true
2250
+ ),
2251
+ new SelectionProxyHandler({ alias, sqlAliasedBehavior: "alias", sqlBehavior: "error" })
2252
+ );
2253
+ };
2254
+ return { as };
2255
+ };
2256
+ $count(source, filters) {
2257
+ return new SQLiteCountBuilder({ source, filters, session: this.session });
2258
+ }
2259
+ /**
2260
+ * Incorporates a previously defined CTE (using `$with`) into the main query.
2261
+ *
2262
+ * This method allows the main query to reference a temporary named result set.
2263
+ *
2264
+ * See docs: {@link https://orm.drizzle.team/docs/select#with-clause}
2265
+ *
2266
+ * @param queries The CTEs to incorporate into the main query.
2267
+ *
2268
+ * @example
2269
+ *
2270
+ * ```ts
2271
+ * // Define a subquery 'sq' as a CTE using $with
2272
+ * const sq = db.$with('sq').as(db.select().from(users).where(eq(users.id, 42)));
2273
+ *
2274
+ * // Incorporate the CTE 'sq' into the main query and select from it
2275
+ * const result = await db.with(sq).select().from(sq);
2276
+ * ```
2277
+ */
2278
+ with(...queries) {
2279
+ const self = this;
2280
+ function select(fields) {
2281
+ return new SQLiteSelectBuilder({
2282
+ fields: fields ?? void 0,
2283
+ session: self.session,
2284
+ dialect: self.dialect,
2285
+ withList: queries
2286
+ });
2287
+ }
2288
+ function selectDistinct(fields) {
2289
+ return new SQLiteSelectBuilder({
2290
+ fields: fields ?? void 0,
2291
+ session: self.session,
2292
+ dialect: self.dialect,
2293
+ withList: queries,
2294
+ distinct: true
2295
+ });
2296
+ }
2297
+ function update(table) {
2298
+ return new SQLiteUpdateBuilder(table, self.session, self.dialect, queries);
2299
+ }
2300
+ function insert(into) {
2301
+ return new SQLiteInsertBuilder(into, self.session, self.dialect, queries);
2302
+ }
2303
+ function delete_(from) {
2304
+ return new SQLiteDeleteBase(from, self.session, self.dialect, queries);
2305
+ }
2306
+ return { select, selectDistinct, update, insert, delete: delete_ };
2307
+ }
2308
+ select(fields) {
2309
+ return new SQLiteSelectBuilder({ fields: fields ?? void 0, session: this.session, dialect: this.dialect });
2310
+ }
2311
+ selectDistinct(fields) {
2312
+ return new SQLiteSelectBuilder({
2313
+ fields: fields ?? void 0,
2314
+ session: this.session,
2315
+ dialect: this.dialect,
2316
+ distinct: true
2317
+ });
2318
+ }
2319
+ /**
2320
+ * Creates an update query.
2321
+ *
2322
+ * Calling this method without `.where()` clause will update all rows in a table. The `.where()` clause specifies which rows should be updated.
2323
+ *
2324
+ * Use `.set()` method to specify which values to update.
2325
+ *
2326
+ * See docs: {@link https://orm.drizzle.team/docs/update}
2327
+ *
2328
+ * @param table The table to update.
2329
+ *
2330
+ * @example
2331
+ *
2332
+ * ```ts
2333
+ * // Update all rows in the 'cars' table
2334
+ * await db.update(cars).set({ color: 'red' });
2335
+ *
2336
+ * // Update rows with filters and conditions
2337
+ * await db.update(cars).set({ color: 'red' }).where(eq(cars.brand, 'BMW'));
2338
+ *
2339
+ * // Update with returning clause
2340
+ * const updatedCar: Car[] = await db.update(cars)
2341
+ * .set({ color: 'red' })
2342
+ * .where(eq(cars.id, 1))
2343
+ * .returning();
2344
+ * ```
2345
+ */
2346
+ update(table) {
2347
+ return new SQLiteUpdateBuilder(table, this.session, this.dialect);
2348
+ }
2349
+ $cache;
2350
+ /**
2351
+ * Creates an insert query.
2352
+ *
2353
+ * Calling this method will create new rows in a table. Use `.values()` method to specify which values to insert.
2354
+ *
2355
+ * See docs: {@link https://orm.drizzle.team/docs/insert}
2356
+ *
2357
+ * @param table The table to insert into.
2358
+ *
2359
+ * @example
2360
+ *
2361
+ * ```ts
2362
+ * // Insert one row
2363
+ * await db.insert(cars).values({ brand: 'BMW' });
2364
+ *
2365
+ * // Insert multiple rows
2366
+ * await db.insert(cars).values([{ brand: 'BMW' }, { brand: 'Porsche' }]);
2367
+ *
2368
+ * // Insert with returning clause
2369
+ * const insertedCar: Car[] = await db.insert(cars)
2370
+ * .values({ brand: 'BMW' })
2371
+ * .returning();
2372
+ * ```
2373
+ */
2374
+ insert(into) {
2375
+ return new SQLiteInsertBuilder(into, this.session, this.dialect);
2376
+ }
2377
+ /**
2378
+ * Creates a delete query.
2379
+ *
2380
+ * Calling this method without `.where()` clause will delete all rows in a table. The `.where()` clause specifies which rows should be deleted.
2381
+ *
2382
+ * See docs: {@link https://orm.drizzle.team/docs/delete}
2383
+ *
2384
+ * @param table The table to delete from.
2385
+ *
2386
+ * @example
2387
+ *
2388
+ * ```ts
2389
+ * // Delete all rows in the 'cars' table
2390
+ * await db.delete(cars);
2391
+ *
2392
+ * // Delete rows with filters and conditions
2393
+ * await db.delete(cars).where(eq(cars.color, 'green'));
2394
+ *
2395
+ * // Delete with returning clause
2396
+ * const deletedCar: Car[] = await db.delete(cars)
2397
+ * .where(eq(cars.id, 1))
2398
+ * .returning();
2399
+ * ```
2400
+ */
2401
+ delete(from) {
2402
+ return new SQLiteDeleteBase(from, this.session, this.dialect);
2403
+ }
2404
+ run(query) {
2405
+ const sequel = typeof query === "string" ? sql.raw(query) : query.getSQL();
2406
+ if (this.resultKind === "async") {
2407
+ return new SQLiteRaw(
2408
+ async () => this.session.run(sequel),
2409
+ () => sequel,
2410
+ "run",
2411
+ this.dialect,
2412
+ this.session.extractRawRunValueFromBatchResult.bind(this.session)
2413
+ );
2414
+ }
2415
+ return this.session.run(sequel);
2416
+ }
2417
+ all(query) {
2418
+ const sequel = typeof query === "string" ? sql.raw(query) : query.getSQL();
2419
+ if (this.resultKind === "async") {
2420
+ return new SQLiteRaw(
2421
+ async () => this.session.all(sequel),
2422
+ () => sequel,
2423
+ "all",
2424
+ this.dialect,
2425
+ this.session.extractRawAllValueFromBatchResult.bind(this.session)
2426
+ );
2427
+ }
2428
+ return this.session.all(sequel);
2429
+ }
2430
+ get(query) {
2431
+ const sequel = typeof query === "string" ? sql.raw(query) : query.getSQL();
2432
+ if (this.resultKind === "async") {
2433
+ return new SQLiteRaw(
2434
+ async () => this.session.get(sequel),
2435
+ () => sequel,
2436
+ "get",
2437
+ this.dialect,
2438
+ this.session.extractRawGetValueFromBatchResult.bind(this.session)
2439
+ );
2440
+ }
2441
+ return this.session.get(sequel);
2442
+ }
2443
+ values(query) {
2444
+ const sequel = typeof query === "string" ? sql.raw(query) : query.getSQL();
2445
+ if (this.resultKind === "async") {
2446
+ return new SQLiteRaw(
2447
+ async () => this.session.values(sequel),
2448
+ () => sequel,
2449
+ "values",
2450
+ this.dialect,
2451
+ this.session.extractRawValuesValueFromBatchResult.bind(this.session)
2452
+ );
2453
+ }
2454
+ return this.session.values(sequel);
2455
+ }
2456
+ transaction(transaction, config) {
2457
+ return this.session.transaction(transaction, config);
2458
+ }
2459
+ };
2460
+
2461
+ // ../../node_modules/.pnpm/drizzle-orm@0.45.2_@opentelemetry+api@1.9.1_@types+pg@8.20.0_kysely@0.29.2_pg@8.22.0/node_modules/drizzle-orm/sqlite-core/session.js
2462
+ var ExecuteResultSync = class extends QueryPromise {
2463
+ constructor(resultCb) {
2464
+ super();
2465
+ this.resultCb = resultCb;
2466
+ }
2467
+ static [entityKind] = "ExecuteResultSync";
2468
+ async execute() {
2469
+ return this.resultCb();
2470
+ }
2471
+ sync() {
2472
+ return this.resultCb();
2473
+ }
2474
+ };
2475
+ var SQLitePreparedQuery = class {
2476
+ constructor(mode, executeMethod, query, cache, queryMetadata, cacheConfig) {
2477
+ this.mode = mode;
2478
+ this.executeMethod = executeMethod;
2479
+ this.query = query;
2480
+ this.cache = cache;
2481
+ this.queryMetadata = queryMetadata;
2482
+ this.cacheConfig = cacheConfig;
2483
+ if (cache && cache.strategy() === "all" && cacheConfig === void 0) {
2484
+ this.cacheConfig = { enable: true, autoInvalidate: true };
2485
+ }
2486
+ if (!this.cacheConfig?.enable) {
2487
+ this.cacheConfig = void 0;
2488
+ }
2489
+ }
2490
+ static [entityKind] = "PreparedQuery";
2491
+ /** @internal */
2492
+ joinsNotNullableMap;
2493
+ /** @internal */
2494
+ async queryWithCache(queryString, params, query) {
2495
+ if (this.cache === void 0 || is(this.cache, NoopCache) || this.queryMetadata === void 0) {
2496
+ try {
2497
+ return await query();
2498
+ } catch (e) {
2499
+ throw new DrizzleQueryError(queryString, params, e);
2500
+ }
2501
+ }
2502
+ if (this.cacheConfig && !this.cacheConfig.enable) {
2503
+ try {
2504
+ return await query();
2505
+ } catch (e) {
2506
+ throw new DrizzleQueryError(queryString, params, e);
2507
+ }
2508
+ }
2509
+ if ((this.queryMetadata.type === "insert" || this.queryMetadata.type === "update" || this.queryMetadata.type === "delete") && this.queryMetadata.tables.length > 0) {
2510
+ try {
2511
+ const [res] = await Promise.all([
2512
+ query(),
2513
+ this.cache.onMutate({ tables: this.queryMetadata.tables })
2514
+ ]);
2515
+ return res;
2516
+ } catch (e) {
2517
+ throw new DrizzleQueryError(queryString, params, e);
2518
+ }
2519
+ }
2520
+ if (!this.cacheConfig) {
2521
+ try {
2522
+ return await query();
2523
+ } catch (e) {
2524
+ throw new DrizzleQueryError(queryString, params, e);
2525
+ }
2526
+ }
2527
+ if (this.queryMetadata.type === "select") {
2528
+ const fromCache = await this.cache.get(
2529
+ this.cacheConfig.tag ?? await hashQuery(queryString, params),
2530
+ this.queryMetadata.tables,
2531
+ this.cacheConfig.tag !== void 0,
2532
+ this.cacheConfig.autoInvalidate
2533
+ );
2534
+ if (fromCache === void 0) {
2535
+ let result;
2536
+ try {
2537
+ result = await query();
2538
+ } catch (e) {
2539
+ throw new DrizzleQueryError(queryString, params, e);
2540
+ }
2541
+ await this.cache.put(
2542
+ this.cacheConfig.tag ?? await hashQuery(queryString, params),
2543
+ result,
2544
+ // make sure we send tables that were used in a query only if user wants to invalidate it on each write
2545
+ this.cacheConfig.autoInvalidate ? this.queryMetadata.tables : [],
2546
+ this.cacheConfig.tag !== void 0,
2547
+ this.cacheConfig.config
2548
+ );
2549
+ return result;
2550
+ }
2551
+ return fromCache;
2552
+ }
2553
+ try {
2554
+ return await query();
2555
+ } catch (e) {
2556
+ throw new DrizzleQueryError(queryString, params, e);
2557
+ }
2558
+ }
2559
+ getQuery() {
2560
+ return this.query;
2561
+ }
2562
+ mapRunResult(result, _isFromBatch) {
2563
+ return result;
2564
+ }
2565
+ mapAllResult(_result, _isFromBatch) {
2566
+ throw new Error("Not implemented");
2567
+ }
2568
+ mapGetResult(_result, _isFromBatch) {
2569
+ throw new Error("Not implemented");
2570
+ }
2571
+ execute(placeholderValues) {
2572
+ if (this.mode === "async") {
2573
+ return this[this.executeMethod](placeholderValues);
2574
+ }
2575
+ return new ExecuteResultSync(() => this[this.executeMethod](placeholderValues));
2576
+ }
2577
+ mapResult(response, isFromBatch) {
2578
+ switch (this.executeMethod) {
2579
+ case "run": {
2580
+ return this.mapRunResult(response, isFromBatch);
2581
+ }
2582
+ case "all": {
2583
+ return this.mapAllResult(response, isFromBatch);
2584
+ }
2585
+ case "get": {
2586
+ return this.mapGetResult(response, isFromBatch);
2587
+ }
2588
+ }
2589
+ }
2590
+ };
2591
+ var SQLiteSession = class {
2592
+ constructor(dialect) {
2593
+ this.dialect = dialect;
2594
+ }
2595
+ static [entityKind] = "SQLiteSession";
2596
+ prepareOneTimeQuery(query, fields, executeMethod, isResponseInArrayMode, customResultMapper, queryMetadata, cacheConfig) {
2597
+ return this.prepareQuery(
2598
+ query,
2599
+ fields,
2600
+ executeMethod,
2601
+ isResponseInArrayMode,
2602
+ customResultMapper,
2603
+ queryMetadata,
2604
+ cacheConfig
2605
+ );
2606
+ }
2607
+ run(query) {
2608
+ const staticQuery = this.dialect.sqlToQuery(query);
2609
+ try {
2610
+ return this.prepareOneTimeQuery(staticQuery, void 0, "run", false).run();
2611
+ } catch (err) {
2612
+ throw new DrizzleError({ cause: err, message: `Failed to run the query '${staticQuery.sql}'` });
2613
+ }
2614
+ }
2615
+ /** @internal */
2616
+ extractRawRunValueFromBatchResult(result) {
2617
+ return result;
2618
+ }
2619
+ all(query) {
2620
+ return this.prepareOneTimeQuery(this.dialect.sqlToQuery(query), void 0, "run", false).all();
2621
+ }
2622
+ /** @internal */
2623
+ extractRawAllValueFromBatchResult(_result) {
2624
+ throw new Error("Not implemented");
2625
+ }
2626
+ get(query) {
2627
+ return this.prepareOneTimeQuery(this.dialect.sqlToQuery(query), void 0, "run", false).get();
2628
+ }
2629
+ /** @internal */
2630
+ extractRawGetValueFromBatchResult(_result) {
2631
+ throw new Error("Not implemented");
2632
+ }
2633
+ values(query) {
2634
+ return this.prepareOneTimeQuery(this.dialect.sqlToQuery(query), void 0, "run", false).values();
2635
+ }
2636
+ async count(sql2) {
2637
+ const result = await this.values(sql2);
2638
+ return result[0][0];
2639
+ }
2640
+ /** @internal */
2641
+ extractRawValuesValueFromBatchResult(_result) {
2642
+ throw new Error("Not implemented");
2643
+ }
2644
+ };
2645
+ var SQLiteTransaction = class extends BaseSQLiteDatabase {
2646
+ constructor(resultType, dialect, session, schema, nestedIndex = 0) {
2647
+ super(resultType, dialect, session, schema);
2648
+ this.schema = schema;
2649
+ this.nestedIndex = nestedIndex;
2650
+ }
2651
+ static [entityKind] = "SQLiteTransaction";
2652
+ rollback() {
2653
+ throw new TransactionRollbackError();
2654
+ }
2655
+ };
2656
+
2657
+ // ../../node_modules/.pnpm/drizzle-orm@0.45.2_@opentelemetry+api@1.9.1_@types+pg@8.20.0_kysely@0.29.2_pg@8.22.0/node_modules/drizzle-orm/sqlite-proxy/session.js
2658
+ var SQLiteRemoteSession = class extends SQLiteSession {
2659
+ constructor(client, dialect, schema, batchCLient, options = {}) {
2660
+ super(dialect);
2661
+ this.client = client;
2662
+ this.schema = schema;
2663
+ this.batchCLient = batchCLient;
2664
+ this.logger = options.logger ?? new NoopLogger();
2665
+ this.cache = options.cache ?? new NoopCache();
2666
+ }
2667
+ static [entityKind] = "SQLiteRemoteSession";
2668
+ logger;
2669
+ cache;
2670
+ prepareQuery(query, fields, executeMethod, isResponseInArrayMode, customResultMapper, queryMetadata, cacheConfig) {
2671
+ return new RemotePreparedQuery(
2672
+ this.client,
2673
+ query,
2674
+ this.logger,
2675
+ this.cache,
2676
+ queryMetadata,
2677
+ cacheConfig,
2678
+ fields,
2679
+ executeMethod,
2680
+ isResponseInArrayMode,
2681
+ customResultMapper
2682
+ );
2683
+ }
2684
+ async batch(queries) {
2685
+ const preparedQueries = [];
2686
+ const builtQueries = [];
2687
+ for (const query of queries) {
2688
+ const preparedQuery = query._prepare();
2689
+ const builtQuery = preparedQuery.getQuery();
2690
+ preparedQueries.push(preparedQuery);
2691
+ builtQueries.push({ sql: builtQuery.sql, params: builtQuery.params, method: builtQuery.method });
2692
+ }
2693
+ const batchResults = await this.batchCLient(builtQueries);
2694
+ return batchResults.map((result, i) => preparedQueries[i].mapResult(result, true));
2695
+ }
2696
+ async transaction(transaction, config) {
2697
+ const tx = new SQLiteProxyTransaction("async", this.dialect, this, this.schema);
2698
+ await this.run(sql.raw(`begin${config?.behavior ? " " + config.behavior : ""}`));
2699
+ try {
2700
+ const result = await transaction(tx);
2701
+ await this.run(sql`commit`);
2702
+ return result;
2703
+ } catch (err) {
2704
+ await this.run(sql`rollback`);
2705
+ throw err;
2706
+ }
2707
+ }
2708
+ extractRawAllValueFromBatchResult(result) {
2709
+ return result.rows;
2710
+ }
2711
+ extractRawGetValueFromBatchResult(result) {
2712
+ return result.rows[0];
2713
+ }
2714
+ extractRawValuesValueFromBatchResult(result) {
2715
+ return result.rows;
2716
+ }
2717
+ };
2718
+ var SQLiteProxyTransaction = class _SQLiteProxyTransaction extends SQLiteTransaction {
2719
+ static [entityKind] = "SQLiteProxyTransaction";
2720
+ async transaction(transaction) {
2721
+ const savepointName = `sp${this.nestedIndex}`;
2722
+ const tx = new _SQLiteProxyTransaction("async", this.dialect, this.session, this.schema, this.nestedIndex + 1);
2723
+ await this.session.run(sql.raw(`savepoint ${savepointName}`));
2724
+ try {
2725
+ const result = await transaction(tx);
2726
+ await this.session.run(sql.raw(`release savepoint ${savepointName}`));
2727
+ return result;
2728
+ } catch (err) {
2729
+ await this.session.run(sql.raw(`rollback to savepoint ${savepointName}`));
2730
+ throw err;
2731
+ }
2732
+ }
2733
+ };
2734
+ var RemotePreparedQuery = class extends SQLitePreparedQuery {
2735
+ constructor(client, query, logger, cache, queryMetadata, cacheConfig, fields, executeMethod, _isResponseInArrayMode, customResultMapper) {
2736
+ super("async", executeMethod, query, cache, queryMetadata, cacheConfig);
2737
+ this.client = client;
2738
+ this.logger = logger;
2739
+ this.fields = fields;
2740
+ this._isResponseInArrayMode = _isResponseInArrayMode;
2741
+ this.customResultMapper = customResultMapper;
2742
+ this.customResultMapper = customResultMapper;
2743
+ this.method = executeMethod;
2744
+ }
2745
+ static [entityKind] = "SQLiteProxyPreparedQuery";
2746
+ method;
2747
+ getQuery() {
2748
+ return { ...this.query, method: this.method };
2749
+ }
2750
+ async run(placeholderValues) {
2751
+ const params = fillPlaceholders(this.query.params, placeholderValues ?? {});
2752
+ this.logger.logQuery(this.query.sql, params);
2753
+ return await this.queryWithCache(this.query.sql, params, async () => {
2754
+ return await this.client(this.query.sql, params, "run");
2755
+ });
2756
+ }
2757
+ mapAllResult(rows, isFromBatch) {
2758
+ if (isFromBatch) {
2759
+ rows = rows.rows;
2760
+ }
2761
+ if (!this.fields && !this.customResultMapper) {
2762
+ return rows;
2763
+ }
2764
+ if (this.customResultMapper) {
2765
+ return this.customResultMapper(rows);
2766
+ }
2767
+ return rows.map((row) => {
2768
+ return mapResultRow(
2769
+ this.fields,
2770
+ row,
2771
+ this.joinsNotNullableMap
2772
+ );
2773
+ });
2774
+ }
2775
+ async all(placeholderValues) {
2776
+ const { query, logger, client } = this;
2777
+ const params = fillPlaceholders(query.params, placeholderValues ?? {});
2778
+ logger.logQuery(query.sql, params);
2779
+ const { rows } = await this.queryWithCache(query.sql, params, async () => {
2780
+ return await client(query.sql, params, "all");
2781
+ });
2782
+ return this.mapAllResult(rows);
2783
+ }
2784
+ async get(placeholderValues) {
2785
+ const { query, logger, client } = this;
2786
+ const params = fillPlaceholders(query.params, placeholderValues ?? {});
2787
+ logger.logQuery(query.sql, params);
2788
+ const clientResult = await this.queryWithCache(query.sql, params, async () => {
2789
+ return await client(query.sql, params, "get");
2790
+ });
2791
+ return this.mapGetResult(clientResult.rows);
2792
+ }
2793
+ mapGetResult(rows, isFromBatch) {
2794
+ if (isFromBatch) {
2795
+ rows = rows.rows;
2796
+ }
2797
+ const row = rows;
2798
+ if (!this.fields && !this.customResultMapper) {
2799
+ return row;
2800
+ }
2801
+ if (!row) {
2802
+ return void 0;
2803
+ }
2804
+ if (this.customResultMapper) {
2805
+ return this.customResultMapper([rows]);
2806
+ }
2807
+ return mapResultRow(
2808
+ this.fields,
2809
+ row,
2810
+ this.joinsNotNullableMap
2811
+ );
2812
+ }
2813
+ async values(placeholderValues) {
2814
+ const params = fillPlaceholders(this.query.params, placeholderValues ?? {});
2815
+ this.logger.logQuery(this.query.sql, params);
2816
+ const clientResult = await this.queryWithCache(this.query.sql, params, async () => {
2817
+ return await this.client(this.query.sql, params, "values");
2818
+ });
2819
+ return clientResult.rows;
2820
+ }
2821
+ /** @internal */
2822
+ isResponseInArrayMode() {
2823
+ return this._isResponseInArrayMode;
2824
+ }
2825
+ };
2826
+
2827
+ // ../../node_modules/.pnpm/drizzle-orm@0.45.2_@opentelemetry+api@1.9.1_@types+pg@8.20.0_kysely@0.29.2_pg@8.22.0/node_modules/drizzle-orm/sqlite-proxy/driver.js
2828
+ var SqliteRemoteDatabase = class extends BaseSQLiteDatabase {
2829
+ static [entityKind] = "SqliteRemoteDatabase";
2830
+ async batch(batch) {
2831
+ return this.session.batch(batch);
2832
+ }
2833
+ };
2834
+ function drizzle(callback, batchCallback, config) {
2835
+ const dialect = new SQLiteAsyncDialect({ casing: config?.casing });
2836
+ let logger;
2837
+ let cache;
2838
+ let _batchCallback;
2839
+ let _config = {};
2840
+ if (batchCallback) {
2841
+ if (typeof batchCallback === "function") {
2842
+ _batchCallback = batchCallback;
2843
+ _config = config ?? {};
2844
+ } else {
2845
+ _batchCallback = void 0;
2846
+ _config = batchCallback;
2847
+ }
2848
+ if (_config.logger === true) {
2849
+ logger = new DefaultLogger();
2850
+ } else if (_config.logger !== false) {
2851
+ logger = _config.logger;
2852
+ cache = _config.cache;
2853
+ }
2854
+ }
2855
+ let schema;
2856
+ if (_config.schema) {
2857
+ const tablesConfig = extractTablesRelationalConfig(
2858
+ _config.schema,
2859
+ createTableRelationsHelpers
2860
+ );
2861
+ schema = {
2862
+ fullSchema: _config.schema,
2863
+ schema: tablesConfig.tables,
2864
+ tableNamesMap: tablesConfig.tableNamesMap
2865
+ };
2866
+ }
2867
+ const session = new SQLiteRemoteSession(callback, dialect, schema, _batchCallback, { logger, cache });
2868
+ const db = new SqliteRemoteDatabase("async", dialect, session, schema);
2869
+ db.$cache = cache;
2870
+ if (db.$cache) {
2871
+ db.$cache["invalidate"] = cache?.onMutate;
2872
+ }
2873
+ return db;
2874
+ }
2875
+ export {
2876
+ RemotePreparedQuery,
2877
+ SQLiteProxyTransaction,
2878
+ SQLiteRemoteSession,
2879
+ SqliteRemoteDatabase,
2880
+ drizzle
2881
+ };
2882
+ //# sourceMappingURL=sqlite-proxy-53E5D2VM.js.map