gemi 0.116.0 → 0.117.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (331) hide show
  1. package/dist/ai/index.js +2 -2
  2. package/dist/ai/index.js.map +1 -1
  3. package/dist/app/index.js +2 -2
  4. package/dist/app/index.js.map +1 -1
  5. package/dist/auth/AuthServiceProvider.d.ts.map +1 -1
  6. package/dist/auth/config.d.ts +27 -0
  7. package/dist/auth/config.d.ts.map +1 -1
  8. package/dist/auth/connections/ConnectionManager.d.ts +133 -0
  9. package/dist/auth/connections/ConnectionManager.d.ts.map +1 -0
  10. package/dist/auth/connections/ConnectionStore.d.ts +146 -0
  11. package/dist/auth/connections/ConnectionStore.d.ts.map +1 -0
  12. package/dist/auth/connections/ConnectionsController.d.ts +23 -0
  13. package/dist/auth/connections/ConnectionsController.d.ts.map +1 -0
  14. package/dist/auth/connections/OAuthConnectionProvider.d.ts +105 -0
  15. package/dist/auth/connections/OAuthConnectionProvider.d.ts.map +1 -0
  16. package/dist/auth/connections/errors.d.ts +32 -0
  17. package/dist/auth/connections/errors.d.ts.map +1 -0
  18. package/dist/auth/oauth/oauthState.d.ts +15 -2
  19. package/dist/auth/oauth/oauthState.d.ts.map +1 -1
  20. package/dist/auth/routes.d.ts +13 -0
  21. package/dist/auth/routes.d.ts.map +1 -1
  22. package/dist/bin/orm/emit.d.ts.map +1 -1
  23. package/dist/bin/orm-generator.js +51 -4
  24. package/dist/bin/orm-generator.js.map +4 -4
  25. package/dist/bun/plugin.js +2 -2
  26. package/dist/bun/plugin.js.map +1 -1
  27. package/dist/bun/preload.js +2 -2
  28. package/dist/bun/preload.js.map +1 -1
  29. package/dist/chunk-00n3gwr8.js +71 -0
  30. package/dist/chunk-00n3gwr8.js.map +13 -0
  31. package/dist/{chunk-t4yh4nf9.js → chunk-076jezzg.js} +3 -3
  32. package/dist/{chunk-t4yh4nf9.js.map → chunk-076jezzg.js.map} +1 -1
  33. package/dist/{chunk-qjhw8nje.js → chunk-077rea02.js} +1 -1
  34. package/dist/{chunk-6cx8ncd4.js → chunk-1ckha5dt.js} +3 -3
  35. package/dist/{chunk-6cx8ncd4.js.map → chunk-1ckha5dt.js.map} +1 -1
  36. package/dist/{chunk-mschc94q.js → chunk-1zzd39qg.js} +2 -2
  37. package/dist/{chunk-mschc94q.js.map → chunk-1zzd39qg.js.map} +1 -1
  38. package/dist/{chunk-5stgtwqw.js → chunk-2bja99cq.js} +2 -2
  39. package/dist/{chunk-5stgtwqw.js.map → chunk-2bja99cq.js.map} +1 -1
  40. package/dist/chunk-2czfefn2.js +10 -0
  41. package/dist/{chunk-yf1njzd5.js.map → chunk-2czfefn2.js.map} +5 -4
  42. package/dist/{chunk-aazmrxj9.js → chunk-37pk2cjg.js} +2 -2
  43. package/dist/{chunk-aazmrxj9.js.map → chunk-37pk2cjg.js.map} +1 -1
  44. package/dist/{chunk-qsrcdzan.js → chunk-3w4hk6q2.js} +3 -3
  45. package/dist/{chunk-qsrcdzan.js.map → chunk-3w4hk6q2.js.map} +1 -1
  46. package/dist/chunk-51w202vr.js +5 -0
  47. package/dist/{chunk-whtzggn6.js.map → chunk-51w202vr.js.map} +3 -4
  48. package/dist/{chunk-4088szy9.js → chunk-5m8vvtvn.js} +3 -3
  49. package/dist/{chunk-4088szy9.js.map → chunk-5m8vvtvn.js.map} +1 -1
  50. package/dist/{chunk-6d8rvr1v.js → chunk-5p4z1fgc.js} +2 -2
  51. package/dist/{chunk-6d8rvr1v.js.map → chunk-5p4z1fgc.js.map} +1 -1
  52. package/dist/{chunk-kejwjerj.js → chunk-5w6kyxsj.js} +2 -2
  53. package/dist/{chunk-kejwjerj.js.map → chunk-5w6kyxsj.js.map} +1 -1
  54. package/dist/{chunk-pyk3gzvc.js → chunk-62jw0vsf.js} +2 -2
  55. package/dist/{chunk-pyk3gzvc.js.map → chunk-62jw0vsf.js.map} +1 -1
  56. package/dist/chunk-63ewmmhc.js +5 -0
  57. package/dist/{chunk-1q9kd20m.js.map → chunk-63ewmmhc.js.map} +1 -1
  58. package/dist/{chunk-p1aqq0ga.js → chunk-6ggmk2eg.js} +3 -3
  59. package/dist/{chunk-p1aqq0ga.js.map → chunk-6ggmk2eg.js.map} +1 -1
  60. package/dist/{chunk-2tzm58j3.js → chunk-6y4nk9f1.js} +2 -2
  61. package/dist/{chunk-2tzm58j3.js.map → chunk-6y4nk9f1.js.map} +1 -1
  62. package/dist/{chunk-1hr4xht1.js → chunk-8gtc3s1y.js} +2 -2
  63. package/dist/{chunk-1hr4xht1.js.map → chunk-8gtc3s1y.js.map} +1 -1
  64. package/dist/{chunk-frerzsxq.js → chunk-a22h5cby.js} +2 -2
  65. package/dist/{chunk-frerzsxq.js.map → chunk-a22h5cby.js.map} +1 -1
  66. package/dist/{chunk-zyt2w03d.js → chunk-a32wfzdq.js} +2 -2
  67. package/dist/{chunk-zyt2w03d.js.map → chunk-a32wfzdq.js.map} +1 -1
  68. package/dist/{chunk-t04f3akb.js → chunk-a77586gv.js} +2 -2
  69. package/dist/{chunk-t04f3akb.js.map → chunk-a77586gv.js.map} +1 -1
  70. package/dist/chunk-a7r39713.js +5 -0
  71. package/dist/chunk-a7r39713.js.map +10 -0
  72. package/dist/{chunk-vxm6yevm.js → chunk-arwmvgrz.js} +2 -2
  73. package/dist/{chunk-vxm6yevm.js.map → chunk-arwmvgrz.js.map} +1 -1
  74. package/dist/{chunk-41da9628.js → chunk-bvqae0px.js} +1 -1
  75. package/dist/{chunk-d9mar37g.js → chunk-c2n6zdyd.js} +2 -2
  76. package/dist/{chunk-d9mar37g.js.map → chunk-c2n6zdyd.js.map} +1 -1
  77. package/dist/{chunk-56jky6vf.js → chunk-cytss9mb.js} +2 -2
  78. package/dist/{chunk-56jky6vf.js.map → chunk-cytss9mb.js.map} +1 -1
  79. package/dist/{chunk-vw8849ys.js → chunk-dcgvq79a.js} +2 -2
  80. package/dist/{chunk-m54s6jpr.js.map → chunk-dcgvq79a.js.map} +1 -1
  81. package/dist/{chunk-6chz1ktz.js → chunk-de4t48j9.js} +3 -3
  82. package/dist/{chunk-6chz1ktz.js.map → chunk-de4t48j9.js.map} +1 -1
  83. package/dist/{chunk-cbqazg9k.js → chunk-dz99g58c.js} +2 -2
  84. package/dist/{chunk-cbqazg9k.js.map → chunk-dz99g58c.js.map} +1 -1
  85. package/dist/{chunk-e573yxpq.js → chunk-e7ezmag9.js} +3 -3
  86. package/dist/{chunk-e573yxpq.js.map → chunk-e7ezmag9.js.map} +1 -1
  87. package/dist/{chunk-yer1r3t3.js → chunk-epvpmakp.js} +2 -2
  88. package/dist/{chunk-yer1r3t3.js.map → chunk-epvpmakp.js.map} +1 -1
  89. package/dist/{chunk-yhrye9cm.js → chunk-f8vcwzgd.js} +2 -2
  90. package/dist/{chunk-yhrye9cm.js.map → chunk-f8vcwzgd.js.map} +1 -1
  91. package/dist/chunk-fa37qzm3.js +5 -0
  92. package/dist/chunk-fa37qzm3.js.map +12 -0
  93. package/dist/{chunk-fxgxf16k.js → chunk-ffgmqwzy.js} +2 -2
  94. package/dist/{chunk-fxgxf16k.js.map → chunk-ffgmqwzy.js.map} +1 -1
  95. package/dist/{chunk-er3wf6ng.js → chunk-fk6nxhxn.js} +2 -2
  96. package/dist/{chunk-er3wf6ng.js.map → chunk-fk6nxhxn.js.map} +1 -1
  97. package/dist/{chunk-3hrj5rwm.js → chunk-fnwbbmnk.js} +2 -2
  98. package/dist/{chunk-3hrj5rwm.js.map → chunk-fnwbbmnk.js.map} +1 -1
  99. package/dist/chunk-g2wncay4.js +9 -0
  100. package/dist/{chunk-hytt9qyj.js.map → chunk-g2wncay4.js.map} +3 -4
  101. package/dist/{chunk-gts5p6mw.js → chunk-ge9xjwgq.js} +4 -4
  102. package/dist/{chunk-gts5p6mw.js.map → chunk-ge9xjwgq.js.map} +1 -1
  103. package/dist/{chunk-tw5kwbx4.js → chunk-gjy2qjcr.js} +2 -2
  104. package/dist/{chunk-tw5kwbx4.js.map → chunk-gjy2qjcr.js.map} +1 -1
  105. package/dist/{chunk-15c2vgaf.js → chunk-gn7kne7r.js} +2 -2
  106. package/dist/{chunk-15c2vgaf.js.map → chunk-gn7kne7r.js.map} +1 -1
  107. package/dist/{chunk-9n1hx3mq.js → chunk-hr61ekcr.js} +3 -3
  108. package/dist/{chunk-9n1hx3mq.js.map → chunk-hr61ekcr.js.map} +1 -1
  109. package/dist/{chunk-m54s6jpr.js → chunk-hvgmqt6z.js} +2 -2
  110. package/dist/{chunk-vw8849ys.js.map → chunk-hvgmqt6z.js.map} +1 -1
  111. package/dist/{chunk-aeh67ynz.js → chunk-hvpn18bb.js} +3 -3
  112. package/dist/{chunk-aeh67ynz.js.map → chunk-hvpn18bb.js.map} +1 -1
  113. package/dist/{chunk-jdhdrr2k.js → chunk-j1453bn1.js} +2 -2
  114. package/dist/{chunk-jdhdrr2k.js.map → chunk-j1453bn1.js.map} +1 -1
  115. package/dist/{chunk-tn2bryy2.js → chunk-jpetnpzn.js} +2 -2
  116. package/dist/{chunk-tn2bryy2.js.map → chunk-jpetnpzn.js.map} +1 -1
  117. package/dist/{chunk-v1tfdgy1.js → chunk-jqrs16g2.js} +3 -3
  118. package/dist/{chunk-v1tfdgy1.js.map → chunk-jqrs16g2.js.map} +1 -1
  119. package/dist/{chunk-4mfrgd5m.js → chunk-kk77x2v4.js} +2 -2
  120. package/dist/{chunk-4mfrgd5m.js.map → chunk-kk77x2v4.js.map} +1 -1
  121. package/dist/chunk-kpn7f58a.js +14 -0
  122. package/dist/{chunk-pn8v6fj2.js.map → chunk-kpn7f58a.js.map} +11 -6
  123. package/dist/chunk-mhteg4yz.js +57 -0
  124. package/dist/{chunk-ms9k0rx6.js.map → chunk-mhteg4yz.js.map} +15 -11
  125. package/dist/{chunk-n672d4g8.js → chunk-n9jyjp4a.js} +2 -2
  126. package/dist/{chunk-n672d4g8.js.map → chunk-n9jyjp4a.js.map} +1 -1
  127. package/dist/{chunk-vbdty91k.js → chunk-nb2gggba.js} +3 -3
  128. package/dist/{chunk-vbdty91k.js.map → chunk-nb2gggba.js.map} +1 -1
  129. package/dist/chunk-ntxsdchf.js +50 -0
  130. package/dist/chunk-ntxsdchf.js.map +10 -0
  131. package/dist/{chunk-2z1981d0.js → chunk-pepzecrm.js} +2 -2
  132. package/dist/{chunk-2z1981d0.js.map → chunk-pepzecrm.js.map} +1 -1
  133. package/dist/{chunk-785b41h1.js → chunk-pgy3mfxw.js} +3 -3
  134. package/dist/{chunk-785b41h1.js.map → chunk-pgy3mfxw.js.map} +1 -1
  135. package/dist/{chunk-98m15b9x.js → chunk-qhw0hej0.js} +2 -2
  136. package/dist/{chunk-98m15b9x.js.map → chunk-qhw0hej0.js.map} +1 -1
  137. package/dist/{chunk-303mprnv.js → chunk-r3v2cnrj.js} +2 -2
  138. package/dist/{chunk-303mprnv.js.map → chunk-r3v2cnrj.js.map} +1 -1
  139. package/dist/{chunk-ktr3k768.js → chunk-rhmpphhc.js} +3 -3
  140. package/dist/{chunk-ktr3k768.js.map → chunk-rhmpphhc.js.map} +1 -1
  141. package/dist/{chunk-fre6f4nk.js → chunk-s4f56035.js} +2 -2
  142. package/dist/{chunk-fre6f4nk.js.map → chunk-s4f56035.js.map} +1 -1
  143. package/dist/{chunk-sr942vb1.js → chunk-sj4f7x4p.js} +2 -2
  144. package/dist/{chunk-sr942vb1.js.map → chunk-sj4f7x4p.js.map} +1 -1
  145. package/dist/{chunk-wyw6p3fg.js → chunk-sksmnjkn.js} +3 -3
  146. package/dist/{chunk-wyw6p3fg.js.map → chunk-sksmnjkn.js.map} +1 -1
  147. package/dist/{chunk-kqxdsv22.js → chunk-stnd9qht.js} +2 -2
  148. package/dist/{chunk-kqxdsv22.js.map → chunk-stnd9qht.js.map} +1 -1
  149. package/dist/{chunk-1myhm0g3.js → chunk-t65074mw.js} +3 -3
  150. package/dist/{chunk-1myhm0g3.js.map → chunk-t65074mw.js.map} +1 -1
  151. package/dist/chunk-t87w4h84.js +24 -0
  152. package/dist/{chunk-79xg42e7.js.map → chunk-t87w4h84.js.map} +2 -2
  153. package/dist/{chunk-z10cas5r.js → chunk-thz75w6e.js} +2 -2
  154. package/dist/{chunk-z10cas5r.js.map → chunk-thz75w6e.js.map} +1 -1
  155. package/dist/{chunk-xt9tv99x.js → chunk-v8vnxkvp.js} +2 -2
  156. package/dist/{chunk-xt9tv99x.js.map → chunk-v8vnxkvp.js.map} +1 -1
  157. package/dist/{chunk-x7cpth2f.js → chunk-veq07rp8.js} +1 -1
  158. package/dist/{chunk-agyfv3f8.js → chunk-vj5necm0.js} +1 -1
  159. package/dist/{chunk-p91b8zcn.js → chunk-vtc23xpk.js} +2 -2
  160. package/dist/{chunk-p91b8zcn.js.map → chunk-vtc23xpk.js.map} +1 -1
  161. package/dist/{chunk-jmpw6bqz.js → chunk-w4e480he.js} +2 -2
  162. package/dist/{chunk-jmpw6bqz.js.map → chunk-w4e480he.js.map} +1 -1
  163. package/dist/{chunk-8rv62v14.js → chunk-wgb79ysr.js} +2 -2
  164. package/dist/{chunk-8rv62v14.js.map → chunk-wgb79ysr.js.map} +1 -1
  165. package/dist/{chunk-1vzks22y.js → chunk-wk1tp1f1.js} +2 -2
  166. package/dist/{chunk-1vzks22y.js.map → chunk-wk1tp1f1.js.map} +1 -1
  167. package/dist/{chunk-bra1a1fq.js → chunk-wwdbgshx.js} +2 -2
  168. package/dist/{chunk-bra1a1fq.js.map → chunk-wwdbgshx.js.map} +1 -1
  169. package/dist/{chunk-eqse2m6n.js → chunk-wzzrz612.js} +2 -2
  170. package/dist/{chunk-eqse2m6n.js.map → chunk-wzzrz612.js.map} +1 -1
  171. package/dist/{chunk-hdps9n52.js → chunk-x7qwx07b.js} +3 -3
  172. package/dist/{chunk-hdps9n52.js.map → chunk-x7qwx07b.js.map} +1 -1
  173. package/dist/chunk-x84as3vy.js +5 -0
  174. package/dist/chunk-x84as3vy.js.map +12 -0
  175. package/dist/chunk-y0en07zh.js +302 -0
  176. package/dist/chunk-y0en07zh.js.map +17 -0
  177. package/dist/{chunk-d2gfcf85.js → chunk-yfwrbfnw.js} +2 -2
  178. package/dist/{chunk-d2gfcf85.js.map → chunk-yfwrbfnw.js.map} +1 -1
  179. package/dist/{chunk-mazznq15.js → chunk-yhp6bvhj.js} +3 -3
  180. package/dist/{chunk-mazznq15.js.map → chunk-yhp6bvhj.js.map} +1 -1
  181. package/dist/{chunk-tzm3c7n6.js → chunk-yvtmygrk.js} +4 -4
  182. package/dist/{chunk-tzm3c7n6.js.map → chunk-yvtmygrk.js.map} +1 -1
  183. package/dist/{chunk-mqfzdfnz.js → chunk-zkjs3m5m.js} +2 -2
  184. package/dist/{chunk-mqfzdfnz.js.map → chunk-zkjs3m5m.js.map} +1 -1
  185. package/dist/chunk-zw6843j3.js +5 -0
  186. package/dist/chunk-zw6843j3.js.map +12 -0
  187. package/dist/client/Head.d.ts.map +1 -1
  188. package/dist/client/fonts.d.ts +69 -0
  189. package/dist/client/fonts.d.ts.map +1 -0
  190. package/dist/client/index.d.ts +1 -0
  191. package/dist/client/index.d.ts.map +1 -1
  192. package/dist/client/index.js +75 -1
  193. package/dist/client/index.js.map +1 -1
  194. package/dist/config/index.js +1 -1
  195. package/dist/console/builtins.d.ts +13 -0
  196. package/dist/console/builtins.d.ts.map +1 -0
  197. package/dist/console/run.js +13 -11
  198. package/dist/console/run.js.map +6 -5
  199. package/dist/console/runner.d.ts.map +1 -1
  200. package/dist/console/usage.d.ts +2 -0
  201. package/dist/console/usage.d.ts.map +1 -1
  202. package/dist/container/index.js +2 -2
  203. package/dist/container/index.js.map +1 -1
  204. package/dist/database/index.js +2 -2
  205. package/dist/database/index.js.map +1 -1
  206. package/dist/email/index.js +2 -2
  207. package/dist/email/index.js.map +1 -1
  208. package/dist/facades/Connections.d.ts +36 -0
  209. package/dist/facades/Connections.d.ts.map +1 -0
  210. package/dist/facades/Crypt.d.ts +26 -0
  211. package/dist/facades/Crypt.d.ts.map +1 -0
  212. package/dist/facades/Meta.d.ts +7 -1
  213. package/dist/facades/Meta.d.ts.map +1 -1
  214. package/dist/facades/Storage.d.ts +29 -0
  215. package/dist/facades/Storage.d.ts.map +1 -1
  216. package/dist/facades/index.d.ts +2 -0
  217. package/dist/facades/index.d.ts.map +1 -1
  218. package/dist/facades/index.js +2 -2
  219. package/dist/facades/index.js.map +1 -1
  220. package/dist/foundation/index.js +2 -2
  221. package/dist/foundation/index.js.map +1 -1
  222. package/dist/http/HttpRequest.d.ts +1 -0
  223. package/dist/http/HttpRequest.d.ts.map +1 -1
  224. package/dist/http/Metadata.d.ts +5 -0
  225. package/dist/http/Metadata.d.ts.map +1 -1
  226. package/dist/http/index.d.ts +3 -1
  227. package/dist/http/index.d.ts.map +1 -1
  228. package/dist/http/index.js +2 -2
  229. package/dist/http/index.js.map +1 -1
  230. package/dist/http/requestContext.d.ts +1 -0
  231. package/dist/http/requestContext.d.ts.map +1 -1
  232. package/dist/http/safeFetch/errors.d.ts +10 -0
  233. package/dist/http/safeFetch/errors.d.ts.map +1 -1
  234. package/dist/http/safeFetch/index.d.ts +1 -1
  235. package/dist/http/safeFetch/index.d.ts.map +1 -1
  236. package/dist/http/sitemap/Robots.d.ts +95 -0
  237. package/dist/http/sitemap/Robots.d.ts.map +1 -0
  238. package/dist/http/sitemap/Sitemap.d.ts +145 -0
  239. package/dist/http/sitemap/Sitemap.d.ts.map +1 -0
  240. package/dist/http/sitemap/fetchText.d.ts +16 -0
  241. package/dist/http/sitemap/fetchText.d.ts.map +1 -0
  242. package/dist/http/sitemap/index.d.ts +3 -0
  243. package/dist/http/sitemap/index.d.ts.map +1 -0
  244. package/dist/http/sitemap/xml.d.ts +21 -0
  245. package/dist/http/sitemap/xml.d.ts.map +1 -0
  246. package/dist/i18n/Translator.d.ts.map +1 -1
  247. package/dist/i18n/dictionaryRuntime.js +2 -2
  248. package/dist/i18n/dictionaryRuntime.js.map +1 -1
  249. package/dist/i18n/index.d.ts +1 -1
  250. package/dist/i18n/index.d.ts.map +1 -1
  251. package/dist/i18n/index.js +2 -2
  252. package/dist/i18n/index.js.map +2 -2
  253. package/dist/i18n/resolveLocale.d.ts +18 -0
  254. package/dist/i18n/resolveLocale.d.ts.map +1 -1
  255. package/dist/kernel/index.js +3 -3
  256. package/dist/kernel/index.js.map +3 -3
  257. package/dist/kernel/providers.d.ts +2 -2
  258. package/dist/kernel/providers.d.ts.map +1 -1
  259. package/dist/orm/Model.d.ts.map +1 -1
  260. package/dist/orm/encryption-rotate.d.ts +44 -0
  261. package/dist/orm/encryption-rotate.d.ts.map +1 -0
  262. package/dist/orm/encryption.d.ts +54 -0
  263. package/dist/orm/encryption.d.ts.map +1 -0
  264. package/dist/orm/index.d.ts +2 -0
  265. package/dist/orm/index.d.ts.map +1 -1
  266. package/dist/orm/index.js +3 -3
  267. package/dist/orm/index.js.map +4 -4
  268. package/dist/orm/schema.d.ts +25 -1
  269. package/dist/orm/schema.d.ts.map +1 -1
  270. package/dist/server/index.js +2 -2
  271. package/dist/server/index.js.map +1 -1
  272. package/dist/services/encryption/Encrypter.d.ts +86 -0
  273. package/dist/services/encryption/Encrypter.d.ts.map +1 -0
  274. package/dist/services/encryption/EncryptionServiceProvider.d.ts +13 -0
  275. package/dist/services/encryption/EncryptionServiceProvider.d.ts.map +1 -0
  276. package/dist/services/encryption/config.d.ts +36 -0
  277. package/dist/services/encryption/config.d.ts.map +1 -0
  278. package/dist/services/file-storage/drivers/FileStorageDriver.d.ts +12 -1
  279. package/dist/services/file-storage/drivers/FileStorageDriver.d.ts.map +1 -1
  280. package/dist/services/file-storage/drivers/FileSystemDriver.d.ts +8 -1
  281. package/dist/services/file-storage/drivers/FileSystemDriver.d.ts.map +1 -1
  282. package/dist/services/file-storage/drivers/types.d.ts +17 -0
  283. package/dist/services/file-storage/drivers/types.d.ts.map +1 -1
  284. package/dist/services/file-storage/putFromUrl.d.ts +56 -0
  285. package/dist/services/file-storage/putFromUrl.d.ts.map +1 -0
  286. package/dist/services/file-storage/sniffContentType.d.ts +33 -0
  287. package/dist/services/file-storage/sniffContentType.d.ts.map +1 -0
  288. package/dist/services/index.d.ts +18 -4
  289. package/dist/services/index.d.ts.map +1 -1
  290. package/dist/services/index.js +10 -10
  291. package/dist/services/index.js.map +4 -3
  292. package/dist/services/queue/DatabaseQueueDriver.d.ts +96 -7
  293. package/dist/services/queue/DatabaseQueueDriver.d.ts.map +1 -1
  294. package/dist/services/queue/Job.d.ts +72 -0
  295. package/dist/services/queue/Job.d.ts.map +1 -1
  296. package/dist/services/queue/MemoryQueueDriver.d.ts +22 -2
  297. package/dist/services/queue/MemoryQueueDriver.d.ts.map +1 -1
  298. package/dist/services/queue/QueueDriver.d.ts +74 -1
  299. package/dist/services/queue/QueueDriver.d.ts.map +1 -1
  300. package/dist/services/queue/QueueManager.d.ts +47 -0
  301. package/dist/services/queue/QueueManager.d.ts.map +1 -1
  302. package/dist/services/queue/batch.d.ts +112 -0
  303. package/dist/services/queue/batch.d.ts.map +1 -0
  304. package/dist/services/queue/queueDriverContract.d.ts +5 -0
  305. package/dist/services/queue/queueDriverContract.d.ts.map +1 -1
  306. package/dist/services/queue/work.js +2 -2
  307. package/dist/services/queue/work.js.map +1 -1
  308. package/dist/services/router/ViewRouteDispatcher.d.ts.map +1 -1
  309. package/dist/stats/route-table.js +1 -1
  310. package/dist/support/index.js +2 -2
  311. package/dist/support/index.js.map +1 -1
  312. package/dist/vitest/index.js +2 -2
  313. package/dist/vitest/index.js.map +1 -1
  314. package/package.json +1 -1
  315. package/dist/chunk-1q9kd20m.js +0 -5
  316. package/dist/chunk-49nyyjfe.js +0 -5
  317. package/dist/chunk-49nyyjfe.js.map +0 -11
  318. package/dist/chunk-79xg42e7.js +0 -24
  319. package/dist/chunk-7vb4eey2.js +0 -217
  320. package/dist/chunk-7vb4eey2.js.map +0 -16
  321. package/dist/chunk-hytt9qyj.js +0 -54
  322. package/dist/chunk-jmg2zsaf.js +0 -5
  323. package/dist/chunk-jmg2zsaf.js.map +0 -12
  324. package/dist/chunk-ms9k0rx6.js +0 -46
  325. package/dist/chunk-pn8v6fj2.js +0 -14
  326. package/dist/chunk-whtzggn6.js +0 -5
  327. package/dist/chunk-yf1njzd5.js +0 -10
  328. /package/dist/{chunk-qjhw8nje.js.map → chunk-077rea02.js.map} +0 -0
  329. /package/dist/{chunk-41da9628.js.map → chunk-bvqae0px.js.map} +0 -0
  330. /package/dist/{chunk-x7cpth2f.js.map → chunk-veq07rp8.js.map} +0 -0
  331. /package/dist/{chunk-agyfv3f8.js.map → chunk-vj5necm0.js.map} +0 -0
@@ -0,0 +1,302 @@
1
+ // @bun
2
+ import{Bh as s,zh as L}from"./chunk-jpetnpzn.js";import{Ch as d}from"./chunk-dz99g58c.js";import{Eh as p,Fh as w,Gh as v,Ih as _,Kh as x,Th as k}from"./chunk-t65074mw.js";import{gi as f}from"./chunk-5w6kyxsj.js";import{Di as b,Gi as O}from"./chunk-076jezzg.js";import{Ji as l}from"./chunk-a32wfzdq.js";class D{entries=new Map;counters=new Map;async acquire(z,G,V){let Y=Date.now(),Z=this.entries.get(z);if(Z&&(Z.expiresAt>Y||Z.fences>0))return null;let $=(Z?.token??0)+1;return this.entries.set(z,{owner:G,token:$,expiresAt:Y+Math.max(0,V),fences:0}),$}async extend(z,G,V,Y){let Z=this.current(z,G,V);if(!Z)return!1;return Z.expiresAt=Date.now()+Math.max(0,Y),!0}async release(z,G,V){let Y=this.current(z,G,V);if(!Y)return!1;return Y.owner="",Y.expiresAt=0,!0}async holder(z){let G=this.entries.get(z);if(!G||G.expiresAt<=Date.now())return null;return{owner:G.owner,token:G.token}}async held(z,G,V){return this.current(z,G,V)!==void 0}async advance(z,G){if((this.counters.get(z)??-1/0)>=G)return!1;return this.counters.set(z,G),!0}async fence(z,G,V,Y){let Z=this.current(z,G,V);if(!Z)throw new L(z,V);Z.fences++;try{return await Y()}finally{Z.fences--}}windows=new Map;async hit(z,G,V){let Y=Date.now(),Z=this.windows.get(z);if(!Z||Z.endsAt<=Y)Z={count:0,endsAt:Y+Math.max(1,V)},this.windows.set(z,Z);if(Z.count>=G)return{allowed:!1,resetInMs:Z.endsAt-Y};return Z.count++,{allowed:!0,resetInMs:Z.endsAt-Y}}async refund(z){let G=this.windows.get(z);if(G&&G.endsAt>Date.now()&&G.count>0)G.count--}current(z,G,V){let Y=this.entries.get(z);if(!Y||Y.owner!==G||Y.expiresAt<=Date.now())return;if(V!==void 0&&Y.token!==V)return;return Y}}class N{table;sql;dialect;connection;busyTimeout;configured;constructor(z,G={}){let V=G.table??"gemi_locks";if(!/^[A-Za-z_][A-Za-z0-9_]*$/.test(V))throw Error(`The lock table name "${V}" is not a plain identifier. Use letters, digits and underscores.`);this.table=V,this.sql=z.sql,this.dialect=z.dialect,this.connection=z.name,this.busyTimeout=G.busyTimeout??1000}async createTable(){await this.configure();for(let z of n(this.dialect,this.table))await this.sql.unsafe(z)}async acquire(z,G,V){await this.configure();let Y=this.sql,Z=this.now(Y);if(await this.seed(Y,z),this.mysql){let X=await Y`
3
+ UPDATE ${this.name(Y)}
4
+ SET owner = ${G}, token = token + 1, expires_at = ${Z} + ${this.ms(Y,V)},
5
+ updated_at = ${Z}
6
+ WHERE name = ${z} AND expires_at <= ${Z}
7
+ `;if(W(X)===0)return null;let[F]=await Y`
8
+ SELECT token FROM ${this.name(Y)} WHERE name = ${z} AND owner = ${G}
9
+ `;return F?Number(F.token):null}let $=await Y`
10
+ UPDATE ${this.name(Y)}
11
+ SET owner = ${G}, token = token + 1, expires_at = ${Z} + ${this.ms(Y,V)},
12
+ updated_at = ${Z}
13
+ WHERE name = ${z} AND expires_at <= ${Z}
14
+ RETURNING token
15
+ `;return $[0]?Number($[0].token):null}async extend(z,G,V,Y){await this.configure();let Z=this.sql,$=this.now(Z),X=await Z`
16
+ UPDATE ${this.name(Z)}
17
+ SET expires_at = ${$} + ${this.ms(Z,Y)}, updated_at = ${$}
18
+ WHERE name = ${z} AND owner = ${G} AND token = ${V} AND expires_at > ${$}
19
+ `;if(W(X)>0)return!0;return this.mysql?this.held(z,G,V):!1}async release(z,G,V){await this.configure();let Y=this.sql,Z=this.now(Y),$=V===void 0?Y`1 = 1`:Y`token = ${V}`,X=await Y`
20
+ UPDATE ${this.name(Y)}
21
+ SET owner = '', expires_at = 0, updated_at = ${Z}
22
+ WHERE name = ${z} AND owner = ${G} AND ${$} AND expires_at > ${Z}
23
+ `;return W(X)>0}async holder(z){await this.configure();let G=this.sql,[V]=await G`
24
+ SELECT owner, token FROM ${this.name(G)}
25
+ WHERE name = ${z} AND expires_at > ${this.now(G)}
26
+ `;return V?{owner:String(V.owner),token:Number(V.token)}:null}async held(z,G,V){await this.configure();let Y=this.sql;return(await Y`
27
+ SELECT 1 AS held FROM ${this.name(Y)}
28
+ WHERE name = ${z} AND owner = ${G} AND token = ${V} AND expires_at > ${this.now(Y)}
29
+ `).length>0}async advance(z,G){await this.configure();let V=this.sql;await this.seed(V,z);let Y=await V`
30
+ UPDATE ${this.name(V)}
31
+ SET token = ${this.int(V,G)}, updated_at = ${this.now(V)}
32
+ WHERE name = ${z} AND token < ${this.int(V,G)}
33
+ `;return W(Y)>0}async fence(z,G,V,Y){await this.configure();let Z=async(X)=>{let F=this.now(X),H;if(this.dialect==="sqlite"){let K=await X`
34
+ UPDATE ${this.name(X)} SET updated_at = ${F}
35
+ WHERE name = ${z} AND owner = ${G} AND token = ${V} AND expires_at > ${F}
36
+ `;H=W(K)>0}else H=(await X`
37
+ SELECT 1 AS held FROM ${this.name(X)}
38
+ WHERE name = ${z} AND owner = ${G} AND token = ${V} AND expires_at > ${F}
39
+ FOR UPDATE
40
+ `).length>0;if(!H)throw new L(z,V);return Y()},$=this.connection;if($===void 0)return await this.sql.begin((X)=>Z(X));return k(this.sql,(X)=>v($,()=>Z(X)),{connection:$})}async hit(z,G,V){await this.configure();let Y=this.sql,Z=this.now(Y);await this.seed(Y,z);let $=this.ms(Y,Math.max(1,V)),X=await Y`
41
+ UPDATE ${this.name(Y)}
42
+ SET token = CASE WHEN expires_at <= ${Z} THEN 1 ELSE token + 1 END,
43
+ expires_at = CASE WHEN expires_at <= ${Z} THEN ${Z} + ${$} ELSE expires_at END,
44
+ updated_at = ${Z}
45
+ WHERE name = ${z} AND (expires_at <= ${Z} OR token < ${this.int(Y,G)})
46
+ `,F=W(X)>0,[H]=await Y`
47
+ SELECT expires_at - ${Z} AS reset FROM ${this.name(Y)} WHERE name = ${z}
48
+ `;return{allowed:F,resetInMs:Math.max(0,Number(H?.reset??0))}}async refund(z){await this.configure();let G=this.sql,V=this.now(G);await G`
49
+ UPDATE ${this.name(G)} SET token = token - 1, updated_at = ${V}
50
+ WHERE name = ${z} AND token > 0 AND expires_at > ${V}
51
+ `}async prune(z){await this.configure();let G=this.sql,V=this.now(G),Y=await G`
52
+ DELETE FROM ${this.name(G)}
53
+ WHERE expires_at <= ${V} AND updated_at <= ${V} - ${this.ms(G,z)}
54
+ `;return W(Y)}async seed(z,G){let V=this.now(z);if(this.mysql){await z`
55
+ INSERT IGNORE INTO ${this.name(z)} (name, owner, token, expires_at, updated_at)
56
+ VALUES (${G}, '', 0, 0, ${V})
57
+ `;return}await z`
58
+ INSERT INTO ${this.name(z)} (name, owner, token, expires_at, updated_at)
59
+ VALUES (${G}, '', 0, 0, ${V})
60
+ ON CONFLICT (name) DO NOTHING
61
+ `}get mysql(){return this.dialect==="mysql"||this.dialect==="mariadb"}configure(){if(this.dialect!=="sqlite"||this.busyTimeout===0)return Promise.resolve();return this.configured??=(async()=>{let[z]=await this.sql.unsafe("PRAGMA busy_timeout");if(Number(z?.timeout??0)!==0)return;await this.sql.unsafe(`PRAGMA busy_timeout = ${this.busyTimeout}`)})().catch((z)=>{throw this.configured=void 0,z}),this.configured}name(z){return z.unsafe(this.mysql?`\`${this.table}\``:`"${this.table}"`)}now(z){switch(this.dialect){case"postgres":return z`floor(extract(epoch from statement_timestamp()) * 1000)::bigint`;case"mysql":case"mariadb":return z`(TIMESTAMPDIFF(MICROSECOND, '1970-01-01 00:00:00', UTC_TIMESTAMP(6)) DIV 1000)`;case"sqlite":return z`CAST((julianday('now') - 2440587.5) * 86400000 AS INTEGER)`}}ms(z,G){return this.int(z,Math.max(0,Math.round(G)))}int(z,G){let V=Math.round(G);return this.mysql?z`CAST(${V} AS SIGNED)`:z`CAST(${V} AS BIGINT)`}}function W(z){let G=z;return Math.max(Number(G.count??0),Number(G.affectedRows??0))}function n(z,G){if(z==="mysql"||z==="mariadb")return[`CREATE TABLE IF NOT EXISTS \`${G}\` (
62
+ \`name\` VARCHAR(191) NOT NULL,
63
+ \`owner\` VARCHAR(191) NOT NULL,
64
+ \`token\` BIGINT NOT NULL DEFAULT 0,
65
+ \`expires_at\` BIGINT NOT NULL,
66
+ \`updated_at\` BIGINT NOT NULL,
67
+
68
+ PRIMARY KEY (\`name\`)
69
+ ) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci`];let V=z==="sqlite"?'"name" TEXT NOT NULL PRIMARY KEY,':'"name" TEXT NOT NULL,',Y=z==="sqlite"?"":`,
70
+
71
+ CONSTRAINT "${G}_pkey" PRIMARY KEY ("name")`;return[`CREATE TABLE IF NOT EXISTS "${G}" (
72
+ ${V}
73
+ "owner" TEXT NOT NULL,
74
+ "token" BIGINT NOT NULL DEFAULT 0,
75
+ "expires_at" BIGINT NOT NULL,
76
+ "updated_at" BIGINT NOT NULL${Y}
77
+ )`]}function C(z){return{id:z.id,name:z.name,total:z.total,pending:z.total,succeeded:0,failed:0,cancelled:0,failedJobIds:[],cancelledAt:null,finishedAt:null,createdAt:z.now,allowFailures:z.allowFailures,callbacks:z.callbacks}}function I(z,G,V){if(z.pending<=0)return z;let Y={...z,pending:z.pending-1};if(G==="succeeded")Y.succeeded++;else if(G==="cancelled")Y.cancelled++;else Y.failed++,Y.failedJobIds=[...z.failedJobIds,V];return Y}function S(z,G){return!G.allowFailures&&G.cancelledAt===null&&G.finishedAt===null&&G.failed>z.failed}function B(z,G,V){let Y=Math.min(Math.max(0,V),z.pending);return{...z,cancelledAt:z.cancelledAt??G,pending:z.pending-Y,cancelled:z.cancelled+Y}}function P(z,G,V){let Y=G,Z=[],$=G.callbacks,X=z.failed===0&&z.cancelledAt===null,F=G.failed===0&&G.cancelledAt===null;if(X&&!F&&$.catch)Z.push($.catch);if(G.pending===0&&G.finishedAt===null){if(Y={...G,finishedAt:V},G.cancelledAt===null&&(G.failed===0||G.allowFailures)&&$.then)Z.push($.then);if($.finally)Z.push($.finally)}let H=A(Y);return{record:Y,calls:Z.map((K)=>({name:K.name,args:JSON.stringify([...K.args,H])}))}}function A(z,G=0){let{allowFailures:V,callbacks:Y,...Z}=z,$=z.total-z.pending,X=z.total===0?1:Math.min(1,Math.max(0,($+Math.max(0,G))/z.total));return{...Z,failedJobIds:[...z.failedJobIds],progress:X}}function U(z){if(typeof z!=="number"||!Number.isFinite(z))throw TypeError(`A job's progress is a number from 0 to 1; got ${String(z)}.`);return Math.min(1,Math.max(0,z))}var h=200,a="Its batch was cancelled before it ran.";class y{table;batchTable;sql;dialect;connection;busyTimeout;configured;sqliteTail=Promise.resolve();constructor(z,G={}){let V=G.table??"gemi_jobs",Y=G.batchTable??(V==="gemi_jobs"?"gemi_job_batches":`${V}_batches`);for(let $ of[V,Y])if(!/^[A-Za-z_][A-Za-z0-9_]*$/.test($))throw Error(`The queue table name "${$}" is not a plain identifier. Use letters, digits and underscores.`);let Z=G.busyTimeout??1000;if(!Number.isInteger(Z)||Z<0)throw Error(`The queue's busyTimeout must be a whole number of milliseconds, 0 or more; got ${Z}.`);this.table=V,this.batchTable=Y,this.sql=z.sql,this.dialect=z.dialect,this.connection=z.name,this.busyTimeout=Z}configure(){if(this.dialect!=="sqlite"||this.busyTimeout===0)return Promise.resolve();return this.configured??=(async()=>{let[z]=await this.sql.unsafe("PRAGMA busy_timeout");if(Number(z?.timeout??0)!==0)return;await this.sql.unsafe(`PRAGMA busy_timeout = ${this.busyTimeout}`)})().catch((z)=>{throw this.configured=void 0,z}),this.configured}async createTable(){await this.configure();let[z,...G]=r(this.dialect,this.table);if(await this.sql.unsafe(z),!await this.hasBatchColumns())for(let V of t(this.dialect,this.table))await this.sql.unsafe(V);for(let V of G)await this.sql.unsafe(V);for(let V of o(this.dialect,this.batchTable))await this.sql.unsafe(V)}async hasBatchColumns(){try{return await this.sql.unsafe(`SELECT batch_id, progress FROM ${this.quoted(this.table)} WHERE 1 = 0`),!0}catch(z){if(u(z))return!1;throw z}}enqueue(z){let G=this.transaction(),V=this.insert(G??this.sql,z);if(G)x(V);return V}async insert(z,{name:G,args:V,delayMs:Y=0,id:Z=Bun.randomUUIDv7()}){await this.configure();let $=this.now(z);return await z`
78
+ INSERT INTO ${this.name(z)}
79
+ (id, name, payload, status, attempts, available_at, created_at, updated_at)
80
+ VALUES
81
+ (${Z}, ${G}, ${V}, 'pending', 0, ${$} + ${this.ms(z,Y)}, ${$}, ${$})
82
+ `,Z}lockStore(){return new N({sql:this.sql,dialect:this.dialect,name:this.connection},{busyTimeout:this.busyTimeout})}joinsTransaction(){return this.transaction()!==void 0}transaction(){if(this.dialect==="sqlite"||this.connection===void 0)return;let z=p();if(z===void 0||w()!==this.connection)return;return z}async claim(z,G){let V=Math.max(0,Math.floor(z));if(V===0)return[];return await this.configure(),(this.dialect==="mysql"||this.dialect==="mariadb"?await this.claimLocking(V,G):await this.claimUpdating(V,G)).map((Z)=>({order:Number(Z.available_at),job:{id:String(Z.id),name:String(Z.name),args:String(Z.payload),attempt:Number(Z.attempts),createdAt:Number(Z.created_at),...Z.batch_id==null?{}:{batchId:String(Z.batch_id)}}})).sort((Z,$)=>Z.order-$.order||(Z.job.id<$.job.id?-1:1)).map(({job:Z})=>Z)}async complete(z){if(z.batchId!==void 0)return this.endBatchJob(z,"succeeded");await this.configure();let G=this.sql;await G`
83
+ DELETE FROM ${this.name(G)}
84
+ WHERE id = ${z.id} AND status = 'claimed' AND attempts = ${z.attempt}
85
+ `}async fail(z,G){if(z.batchId!==void 0)return this.endBatchJob(z,"failed",G);await this.configure();let V=this.sql,Y=this.now(V);if(G.retryInMs===null){await V`
86
+ UPDATE ${this.name(V)}
87
+ SET status = 'dead', lease_expires_at = NULL, last_error = ${G.error},
88
+ updated_at = ${Y}
89
+ WHERE id = ${z.id} AND status = 'claimed' AND attempts = ${z.attempt}
90
+ `;return}await V`
91
+ UPDATE ${this.name(V)}
92
+ SET status = 'pending', available_at = ${Y} + ${this.ms(V,G.retryInMs)},
93
+ lease_expires_at = NULL, last_error = ${G.error}, updated_at = ${Y}
94
+ WHERE id = ${z.id} AND status = 'claimed' AND attempts = ${z.attempt}
95
+ `}async release(z,G){let V=this.sql,Y=this.now(V);await V`
96
+ UPDATE ${this.name(V)}
97
+ SET status = 'pending', attempts = attempts - 1,
98
+ available_at = ${Y} + ${this.ms(V,G.retryInMs)},
99
+ lease_expires_at = NULL, updated_at = ${Y}
100
+ WHERE id = ${z.id} AND status = 'claimed' AND attempts = ${z.attempt}
101
+ `}async heartbeat(z,G){await this.configure();let V=this.sql;await Promise.all(z.map((Y)=>{let Z=this.now(V);return V`
102
+ UPDATE ${this.name(V)}
103
+ SET lease_expires_at = ${Z} + ${this.ms(V,G.visibilityTimeoutMs)},
104
+ updated_at = ${Z}
105
+ WHERE id = ${Y.id} AND status = 'claimed' AND attempts = ${Y.attempt}
106
+ `}))}async retryDead(z){await this.configure();let G=this.sql,[V]=await G`
107
+ SELECT * FROM ${this.name(G)} WHERE id = ${z} AND status = 'dead'
108
+ `;if(!V||V.batch_id!=null)return!1;let Y=this.now(G),Z=await G`
109
+ UPDATE ${this.name(G)}
110
+ SET status = 'pending', attempts = 0, available_at = ${Y}, lease_expires_at = NULL,
111
+ updated_at = ${Y}
112
+ WHERE id = ${z} AND status = 'dead'
113
+ `;return Q(Z)>0}async prune(z){await this.configure();let G=this.sql,V=await G`
114
+ DELETE FROM ${this.name(G)}
115
+ WHERE status = 'dead' AND updated_at <= ${this.now(G)} - ${this.ms(G,z)}
116
+ `;return Q(V)}enqueueBatch(z){let G=this.transaction(),V=G?this.insertBatch(G,z):this.atomically((Y)=>this.insertBatch(Y,z));if(G)x(V);return V}async insertBatch(z,G){await this.configure();let V=await this.clock(z),Y=C({...G,total:G.args.length,now:V}),{record:Z,calls:$}=P(Y,Y,V);await M(z`
117
+ INSERT INTO ${this.batches(z)}
118
+ (id, name, total, pending, succeeded, failed, cancelled, failed_job_ids, options,
119
+ cancelled_at, finished_at, created_at, updated_at)
120
+ VALUES
121
+ (${Z.id}, ${Z.name}, ${Z.total}, ${Z.pending}, 0, 0, 0,
122
+ '[]', ${e(Z)}, NULL, ${this.timeOrNull(z,Z.finishedAt)},
123
+ ${this.ms(z,V)}, ${this.ms(z,V)})
124
+ `,this.batchTable);let X=this.ms(z,V);for(let F=0;F<G.args.length;F+=h){let H=G.args.slice(F,F+h).map((K)=>z`(${Bun.randomUUIDv7()}, ${G.job}, ${K}, 'pending', 0, ${X}, ${X}, ${X}, ${G.id}, 0)`).reduce((K,J)=>z`${K}, ${J}`);await M(z`
125
+ INSERT INTO ${this.name(z)}
126
+ (id, name, payload, status, attempts, available_at, created_at, updated_at, batch_id, progress)
127
+ VALUES ${H}
128
+ `,this.table)}for(let F of $)await this.insert(z,F)}async findBatch(z,G={}){await this.configure();let V=this.sql,[Y]=await M(V`SELECT * FROM ${this.batches(V)} WHERE id = ${z}`,this.batchTable);if(!Y)return null;let Z=j(Y);if(G.progress===!1||Z.pending===0)return A(Z);let[$]=await V`
129
+ SELECT COALESCE(SUM(progress), 0) AS running FROM ${this.name(V)}
130
+ WHERE batch_id = ${z} AND status IN ('pending', 'claimed')
131
+ `;return A(Z,Number($?.running??0))}async cancelBatch(z){return this.atomically(async(G)=>{let V=await this.lockBatch(G,z);if(!V||V.finishedAt!==null||V.cancelledAt!==null)return!1;let Y=await this.clock(G),Z=B(V,Y,await this.cancelWaiting(G,z));return await this.saveBatch(G,V,Z,Y),!0})}async reportProgress(z,G){let V=U(G);await this.configure();let Y=this.sql;await Y`
132
+ UPDATE ${this.name(Y)} SET progress = ${this.fraction(Y,V)}
133
+ WHERE id = ${z.id} AND status = 'claimed' AND attempts = ${z.attempt}
134
+ `}async pruneBatches(z){await this.configure();let G=this.sql,V=await G`
135
+ DELETE FROM ${this.batches(G)}
136
+ WHERE finished_at IS NOT NULL AND finished_at <= ${this.now(G)} - ${this.ms(G,z)}
137
+ `;return Q(V)}endBatchJob(z,G,V){let Y=z.batchId;return this.atomically(async(Z)=>{let $=await this.lockBatch(Z,Y),X=Z`id = ${z.id} AND status = 'claimed' AND attempts = ${z.attempt}`,F=this.now(Z);if(G==="succeeded"){let J=await Z`DELETE FROM ${this.name(Z)} WHERE ${X}`;if(Q(J)===0||!$)return;return this.count(Z,$,"succeeded",z.id)}let H=V.cancelled===!0||V.retryInMs!==null&&$!==void 0&&$.cancelledAt!==null;if(V.retryInMs!==null&&!H){await Z`
138
+ UPDATE ${this.name(Z)}
139
+ SET status = 'pending', available_at = ${F} + ${this.ms(Z,V.retryInMs)},
140
+ lease_expires_at = NULL, last_error = ${V.error}, progress = 0,
141
+ updated_at = ${F}
142
+ WHERE ${X}
143
+ `;return}let K=await Z`
144
+ UPDATE ${this.name(Z)}
145
+ SET status = 'dead', lease_expires_at = NULL, last_error = ${V.error},
146
+ updated_at = ${F}
147
+ WHERE ${X}
148
+ `;if(Q(K)===0||!$)return;return this.count(Z,$,H?"cancelled":"failed",z.id)})}async count(z,G,V,Y){let Z=await this.clock(z),$=I(G,V,Y);if(S(G,$))$=B($,Z,await this.cancelWaiting(z,G.id));await this.saveBatch(z,G,$,Z)}async cancelWaiting(z,G){let V=this.now(z),Y=await z`
149
+ UPDATE ${this.name(z)}
150
+ SET status = 'dead', last_error = ${a}, updated_at = ${V}
151
+ WHERE batch_id = ${G} AND status = 'pending'
152
+ `;return Q(Y)}async saveBatch(z,G,V,Y){let{record:Z,calls:$}=P(G,V,Y);await z`
153
+ UPDATE ${this.batches(z)}
154
+ SET pending = ${Z.pending}, succeeded = ${Z.succeeded}, failed = ${Z.failed},
155
+ cancelled = ${Z.cancelled}, failed_job_ids = ${JSON.stringify(Z.failedJobIds)},
156
+ cancelled_at = ${this.timeOrNull(z,Z.cancelledAt)},
157
+ finished_at = ${this.timeOrNull(z,Z.finishedAt)}, updated_at = ${this.ms(z,Y)}
158
+ WHERE id = ${Z.id}
159
+ `;for(let X of $)await this.insert(z,X)}async lockBatch(z,G){let V;if(this.dialect==="sqlite")await z`UPDATE ${this.batches(z)} SET updated_at = updated_at WHERE id = ${G}`,V=await z`SELECT * FROM ${this.batches(z)} WHERE id = ${G}`;else V=await z`SELECT * FROM ${this.batches(z)} WHERE id = ${G} FOR UPDATE`;return V[0]?j(V[0]):void 0}atomically(z){let G=async()=>{await this.configure();for(let Y=0;;Y++)try{return await this.sql.begin((Z)=>z(Z))}catch(Z){if(this.dialect!=="sqlite"||Y>=50||!/within a transaction/i.test(String(Z?.message??Z)))throw Z;await new Promise(($)=>setTimeout($,20))}};if(this.dialect!=="sqlite")return G();let V=this.sqliteTail.then(G,G);return this.sqliteTail=V.catch(()=>{}),V}async clock(z){let[G]=await z`SELECT ${this.now(z)} AS now`;return Number(G.now)}timeOrNull(z,G){return G===null?z`NULL`:this.ms(z,G)}fraction(z,G){return this.dialect==="postgres"?z`CAST(${G} AS DOUBLE PRECISION)`:z`${G}`}async claimUpdating(z,G){let V=this.sql,Y=this.now(V),Z=this.ms(V,G.visibilityTimeoutMs),$=this.name(V);if(this.dialect==="postgres")return await V`
160
+ WITH next AS (
161
+ SELECT id FROM ${$}
162
+ WHERE ${this.claimable(V,G)}
163
+ ORDER BY available_at, id
164
+ LIMIT ${z}
165
+ FOR UPDATE SKIP LOCKED
166
+ )
167
+ UPDATE ${$} AS job
168
+ SET status = 'claimed', attempts = job.attempts + 1, claimed_at = ${Y},
169
+ lease_expires_at = ${Y} + ${Z}, updated_at = ${Y}
170
+ FROM next
171
+ WHERE job.id = next.id
172
+ RETURNING job.*
173
+ `;return await V`
174
+ UPDATE ${$}
175
+ SET status = 'claimed', attempts = attempts + 1, claimed_at = ${Y},
176
+ lease_expires_at = ${Y} + ${Z}, updated_at = ${Y}
177
+ WHERE id IN (
178
+ SELECT id FROM ${$}
179
+ WHERE ${this.claimable(V,G)}
180
+ ORDER BY available_at, id
181
+ LIMIT ${z}
182
+ )
183
+ RETURNING *
184
+ `}async claimLocking(z,G){let V=await this.sql.reserve(),[Y]=await V`
185
+ SELECT @@transaction_isolation AS level
186
+ `;await V`SET SESSION TRANSACTION ISOLATION LEVEL READ COMMITTED`;try{return await this.claimLockingOn(V,z,G)}finally{let Z=Y?.level?.replaceAll("-"," ");if(Z&&/^[A-Z ]+$/.test(Z))await V.unsafe(`SET SESSION TRANSACTION ISOLATION LEVEL ${Z}`);V.release()}}async claimLockingOn(z,G,V){return await z.begin(async(Y)=>{let Z=this.name(Y),$=Y.unsafe("*"),X=await Y`
187
+ SELECT ${$} FROM ${Z}
188
+ WHERE status = 'pending' AND available_at <= ${this.now(Y)}
189
+ AND ${this.runnable(Y,V,"available_at")}
190
+ ORDER BY available_at, id
191
+ LIMIT ${G}
192
+ FOR UPDATE SKIP LOCKED
193
+ `;if(X.length<G){let F=await Y`
194
+ SELECT ${$} FROM ${Z}
195
+ WHERE status = 'claimed' AND lease_expires_at <= ${this.now(Y)}
196
+ AND ${this.runnable(Y,V,"lease_expires_at")}
197
+ ORDER BY lease_expires_at, id
198
+ LIMIT ${G-X.length}
199
+ FOR UPDATE SKIP LOCKED
200
+ `;X.push(...F)}for(let F of X){let H=this.now(Y);await Y`
201
+ UPDATE ${Z}
202
+ SET status = 'claimed', attempts = attempts + 1, claimed_at = ${H},
203
+ lease_expires_at = ${H} + ${this.ms(Y,V.visibilityTimeoutMs)},
204
+ updated_at = ${H}
205
+ WHERE id = ${F.id}
206
+ `}return X.map((F)=>({...F,attempts:Number(F.attempts)+1}))})}claimable(z,G){let V=this.now(z);return z`(
207
+ (status = 'pending' AND available_at <= ${V}
208
+ AND ${this.runnable(z,G,"available_at")})
209
+ OR (status = 'claimed' AND lease_expires_at <= ${V}
210
+ AND ${this.runnable(z,G,"lease_expires_at")})
211
+ )`}runnable(z,G,V){let Y=G.registered;if(!Y)return z`1 = 1`;let Z=Y.names.length?z`name IN (${Y.names.map((X)=>z`${X}`).reduce((X,F)=>z`${X}, ${F}`)})`:z`1 = 0`;if(!Number.isFinite(Y.graceMs))return Z;let $=z.unsafe(V);return z`(${Z} OR ${$} <= ${this.now(z)} - ${this.ms(z,Y.graceMs)})`}name(z){return z.unsafe(this.quoted(this.table))}batches(z){return z.unsafe(this.quoted(this.batchTable))}quoted(z){return this.dialect==="mysql"||this.dialect==="mariadb"?`\`${z}\``:`"${z}"`}now(z){switch(this.dialect){case"postgres":return z`floor(extract(epoch from statement_timestamp()) * 1000)::bigint`;case"mysql":case"mariadb":return z`(TIMESTAMPDIFF(MICROSECOND, '1970-01-01 00:00:00', UTC_TIMESTAMP(6)) DIV 1000)`;case"sqlite":return z`CAST((julianday('now') - 2440587.5) * 86400000 AS INTEGER)`}}ms(z,G){let V=Math.max(0,Math.round(G));return this.dialect==="mysql"||this.dialect==="mariadb"?z`CAST(${V} AS SIGNED)`:z`CAST(${V} AS BIGINT)`}}function Q(z){let G=z;return Math.max(Number(G.count??0),Number(G.affectedRows??0))}function r(z,G){if(z==="mysql"||z==="mariadb")return[`CREATE TABLE IF NOT EXISTS \`${G}\` (
212
+ \`id\` VARCHAR(191) NOT NULL,
213
+ \`name\` VARCHAR(191) NOT NULL,
214
+ \`payload\` LONGTEXT NOT NULL,
215
+ \`status\` VARCHAR(191) NOT NULL,
216
+ \`attempts\` INTEGER NOT NULL DEFAULT 0,
217
+ \`available_at\` BIGINT NOT NULL,
218
+ \`claimed_at\` BIGINT NULL,
219
+ \`lease_expires_at\` BIGINT NULL,
220
+ \`last_error\` LONGTEXT NULL,
221
+ \`created_at\` BIGINT NOT NULL,
222
+ \`updated_at\` BIGINT NOT NULL,
223
+ \`batch_id\` VARCHAR(191) NULL,
224
+ \`progress\` DOUBLE NULL,
225
+
226
+ INDEX \`${G}_status_available_at_idx\`(\`status\`, \`available_at\`),
227
+ INDEX \`${G}_status_lease_expires_at_idx\`(\`status\`, \`lease_expires_at\`),
228
+ INDEX \`${G}_batch_id_idx\`(\`batch_id\`),
229
+ PRIMARY KEY (\`id\`)
230
+ ) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci`];let V=z==="sqlite"?'"id" TEXT NOT NULL PRIMARY KEY,':'"id" TEXT NOT NULL,',Y=z==="sqlite"?"":`,
231
+
232
+ CONSTRAINT "${G}_pkey" PRIMARY KEY ("id")`;return[`CREATE TABLE IF NOT EXISTS "${G}" (
233
+ ${V}
234
+ "name" TEXT NOT NULL,
235
+ "payload" TEXT NOT NULL,
236
+ "status" TEXT NOT NULL,
237
+ "attempts" INTEGER NOT NULL DEFAULT 0,
238
+ "available_at" BIGINT NOT NULL,
239
+ "claimed_at" BIGINT,
240
+ "lease_expires_at" BIGINT,
241
+ "last_error" TEXT,
242
+ "created_at" BIGINT NOT NULL,
243
+ "updated_at" BIGINT NOT NULL,
244
+ "batch_id" TEXT,
245
+ "progress" ${z==="sqlite"?"REAL":"DOUBLE PRECISION"}${Y}
246
+ )`,`CREATE INDEX IF NOT EXISTS "${G}_status_available_at_idx" ON "${G}"("status", "available_at")`,`CREATE INDEX IF NOT EXISTS "${G}_status_lease_expires_at_idx" ON "${G}"("status", "lease_expires_at")`,`CREATE INDEX IF NOT EXISTS "${G}_batch_id_idx" ON "${G}"("batch_id")`]}function t(z,G){if(z==="mysql"||z==="mariadb")return[`ALTER TABLE \`${G}\` ADD COLUMN \`batch_id\` VARCHAR(191) NULL,
247
+ ADD COLUMN \`progress\` DOUBLE NULL,
248
+ ADD INDEX \`${G}_batch_id_idx\`(\`batch_id\`)`];let V=z==="sqlite"?"REAL":"DOUBLE PRECISION";if(z==="sqlite")return[`ALTER TABLE "${G}" ADD COLUMN "batch_id" TEXT`,`ALTER TABLE "${G}" ADD COLUMN "progress" ${V}`,`CREATE INDEX IF NOT EXISTS "${G}_batch_id_idx" ON "${G}"("batch_id")`];return[`ALTER TABLE "${G}" ADD COLUMN IF NOT EXISTS "batch_id" TEXT,
249
+ ADD COLUMN IF NOT EXISTS "progress" ${V}`,`CREATE INDEX IF NOT EXISTS "${G}_batch_id_idx" ON "${G}"("batch_id")`]}function o(z,G){if(z==="mysql"||z==="mariadb")return[`CREATE TABLE IF NOT EXISTS \`${G}\` (
250
+ \`id\` VARCHAR(191) NOT NULL,
251
+ \`name\` VARCHAR(191) NULL,
252
+ \`total\` INTEGER NOT NULL,
253
+ \`pending\` INTEGER NOT NULL,
254
+ \`succeeded\` INTEGER NOT NULL DEFAULT 0,
255
+ \`failed\` INTEGER NOT NULL DEFAULT 0,
256
+ \`cancelled\` INTEGER NOT NULL DEFAULT 0,
257
+ \`failed_job_ids\` LONGTEXT NOT NULL,
258
+ \`options\` LONGTEXT NOT NULL,
259
+ \`cancelled_at\` BIGINT NULL,
260
+ \`finished_at\` BIGINT NULL,
261
+ \`created_at\` BIGINT NOT NULL,
262
+ \`updated_at\` BIGINT NOT NULL,
263
+
264
+ PRIMARY KEY (\`id\`)
265
+ ) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci`];let V=z==="sqlite"?'"id" TEXT NOT NULL PRIMARY KEY,':'"id" TEXT NOT NULL,',Y=z==="sqlite"?"":`,
266
+
267
+ CONSTRAINT "${G}_pkey" PRIMARY KEY ("id")`;return[`CREATE TABLE IF NOT EXISTS "${G}" (
268
+ ${V}
269
+ "name" TEXT,
270
+ "total" INTEGER NOT NULL,
271
+ "pending" INTEGER NOT NULL,
272
+ "succeeded" INTEGER NOT NULL DEFAULT 0,
273
+ "failed" INTEGER NOT NULL DEFAULT 0,
274
+ "cancelled" INTEGER NOT NULL DEFAULT 0,
275
+ "failed_job_ids" TEXT NOT NULL,
276
+ "options" TEXT NOT NULL,
277
+ "cancelled_at" BIGINT,
278
+ "finished_at" BIGINT,
279
+ "created_at" BIGINT NOT NULL,
280
+ "updated_at" BIGINT NOT NULL${Y}
281
+ )`]}function j(z){let G=JSON.parse(z.options),V=(Y)=>Y==null?null:Number(Y);return{id:String(z.id),name:z.name==null?null:String(z.name),total:Number(z.total),pending:Number(z.pending),succeeded:Number(z.succeeded),failed:Number(z.failed),cancelled:Number(z.cancelled),failedJobIds:JSON.parse(z.failed_job_ids),cancelledAt:V(z.cancelled_at),finishedAt:V(z.finished_at),createdAt:Number(z.created_at),allowFailures:G.allowFailures===!0,callbacks:G.callbacks??{}}}function e(z){return JSON.stringify({allowFailures:z.allowFailures,callbacks:z.callbacks})}function u(z){let G=String(z?.message??z);return/does not exist|doesn't exist|unknown column|no such (table|column)|has no column/i.test(G)}async function M(z,G){try{return await z}catch(V){if(!u(V))throw V;throw Error(`Job batches need the "${G}" table and the batch_id and progress columns of the jobs table, and the database says one is missing. Add the GemiJobBatch model and the two GemiJob fields from the docs (docs/jobs-and-queues.md#batches) and migrate, or call the driver's createTable().`,{cause:V})}}import{AsyncResource as Gz}from"async_hooks";import{isMainThread as Vz}from"worker_threads";function Dz(z){return z}function q(){return{jobs:[],jobsDir:"app/jobs",concurrency:1,driver:"memory",visibilityTimeout:300000,pollInterval:1000,unknownJobGrace:3600000,locks:"auto"}}var zz=86400000;class T{entries=new Map;batches=new Map;listeners=new Set;timer;timerAt=1/0;seq=0;get waiting(){let z=0;for(let G of this.entries.values())if(!G.leased)z++;return z}get leased(){return this.entries.size-this.waiting}async enqueue(z){let G=this.add(z);return this.changed(),G}add({name:z,args:G,delayMs:V=0,id:Y=crypto.randomUUID()},Z){let $=Date.now();return this.entries.set(Y,{job:{id:Y,name:z,args:G,attempt:0,createdAt:$,...Z===void 0?{}:{batchId:Z}},until:$+Math.max(0,V),leased:!1,seq:this.seq++,progress:0}),Y}async enqueueBatch(z){let G=Date.now();this.forgetFinishedBatches(G);let V=C({...z,total:z.args.length,now:G});for(let $ of z.args)this.add({name:z.job,args:$},z.id);let{record:Y,calls:Z}=P(V,V,G);this.batches.set(z.id,Y);for(let $ of Z)this.add($);this.changed()}async findBatch(z,G={}){let V=this.batches.get(z);if(!V)return null;if(G.progress===!1||V.pending===0)return A(V);let Y=0;for(let Z of this.entries.values())if(Z.job.batchId===z)Y+=Z.progress;return A(V,Y)}async cancelBatch(z){let G=this.batches.get(z);if(!G||G.finishedAt!==null||G.cancelledAt!==null)return!1;let V=Date.now(),Y=B(G,V,this.cancelWaiting(z));return this.save(G,Y,V),this.changed(),!0}async reportProgress(z,G){let V=this.current(z);if(V)V.progress=U(G)}async claim(z,G){let V=Date.now(),Y=[...this.entries.values()].filter((Z)=>Z.until<=V).sort((Z,$)=>Z.until-$.until||Z.seq-$.seq).slice(0,Math.max(0,z));for(let Z of Y)Z.job={...Z.job,attempt:Z.job.attempt+1},Z.leased=!0,Z.until=V+G.visibilityTimeoutMs;if(Y.length>0)this.schedule();return Y.map((Z)=>({...Z.job}))}async complete(z){let G=this.current(z);if(!G)return;this.entries.delete(z.id),this.count(G,"succeeded"),this.schedule()}async fail(z,G){let V=this.current(z);if(!V)return;let Y=V.job.batchId===void 0?void 0:this.batches.get(V.job.batchId),Z=G.cancelled===!0||G.retryInMs!==null&&Y?.cancelledAt!=null;if(G.retryInMs===null||Z){this.entries.delete(z.id),this.count(V,Z?"cancelled":"failed"),this.schedule();return}V.leased=!1,V.until=Date.now()+Math.max(0,G.retryInMs),V.seq=this.seq++,V.progress=0,this.changed()}async release(z,G){let V=this.current(z);if(!V)return;V.job={...V.job,attempt:V.job.attempt-1},V.leased=!1,V.until=Date.now()+Math.max(0,G.retryInMs),V.seq=this.seq++,this.changed()}async heartbeat(z,G){let V=Date.now()+G.visibilityTimeoutMs;for(let Y of z){let Z=this.current(Y);if(Z)Z.until=V}this.schedule()}count(z,G){let V=z.job.batchId;if(V===void 0)return;let Y=this.batches.get(V);if(!Y)return;let Z=Date.now(),$=I(Y,G,z.job.id);if(S(Y,$))$=B($,Z,this.cancelWaiting(V));this.save(Y,$,Z),this.changed()}save(z,G,V){let{record:Y,calls:Z}=P(z,G,V);this.batches.set(Y.id,Y);for(let $ of Z)this.add($)}cancelWaiting(z){let G=0;for(let[V,Y]of this.entries)if(Y.job.batchId===z&&!Y.leased)this.entries.delete(V),G++;return G}forgetFinishedBatches(z){for(let[G,V]of this.batches)if(V.finishedAt!==null&&z-V.finishedAt>zz)this.batches.delete(G)}subscribe(z){return this.listeners.add(z),()=>void this.listeners.delete(z)}current(z){let G=this.entries.get(z.id);if(!G||!G.leased||G.job.attempt!==z.attempt)return;return G}changed(){this.schedule();let z=Date.now();for(let G of this.entries.values())if(G.until<=z){this.wake();return}}wake(){for(let z of[...this.listeners])z()}schedule(){let z=Date.now(),G=1/0;for(let V of this.entries.values())if(V.until>z&&V.until<G)G=V.until;if(G===this.timerAt)return;if(clearTimeout(this.timer),this.timer=void 0,this.timerAt=G,G===1/0)return;this.timer=setTimeout(()=>{this.timer=void 0,this.timerAt=1/0,this.changed()},G-z),this.timer.unref?.()}}function Yz(){let z=process.env.APP_DIR,G=process.env.ROOT_DIR,V=Bun.env.NODE_ENV==="production"?`${G}/dist/server/bootstrap.mjs`:`${z}/bootstrap.ts`,Y=new File([`
282
+ import { app } from "${V}"
283
+ self.onmessage = async (event) => {
284
+ const clone = app.clone()
285
+ let result = null;
286
+ let error = null;
287
+ try {
288
+ result = await clone.dispatchJob(event.data.jobName, event.data.args)
289
+ } catch (err) {
290
+ error = err
291
+ }
292
+ clone.destroy()
293
+ if(error) {
294
+ self.postMessage({error});
295
+ } else {
296
+ self.postMessage({result});
297
+ }
298
+ };
299
+ `],"worker.ts"),Z=URL.createObjectURL(Y);return new Worker(Z)}async function Zz(z,G){let V=Yz();return V.postMessage({jobName:z,args:G}),await new Promise((Y,Z)=>{V.onmessage=($)=>{let X=$.data;if("error"in X)Z(X.error);else Y(X.result)}})}var $z=new Gz("gemi.queue"),Xz=60000;class E{static token="queue";jobs={};config;driver;application;inFlight=new Map;state="idle";looping=!1;claiming;woken=!1;claimFailures=0;resume;unsubscribe;heartbeatTimer;releasedNames=new Set;lockManager;constructor(z={},G={}){this.config=d(q(),z),this.application=G.application,this.driver=Az(this.config.driver,this.application),this.useJobs(this.config.jobs)}useJobs(z){this.config.jobs=z,this.jobs={};for(let G of z)this.claim(G)}registerJob(z){this.config.jobs=[...this.config.jobs,z],this.claim(z)}claim(z){if(this.jobs[z.name]){console.error(`Two queued jobs are named "${z.name}" \u2014 the first is registered `+"and this one is not, so dispatching either would have run one of them. A class name is the queue's key, so only one job can hold it. Rename one.");return}this.jobs[z.name]=z}get registeredJobs(){return[...this.config.jobs]}dispatchJob(z,G){if(this.jobs[z])return new this.jobs[z]().run(JSON.parse(G))}push(z,G,V={}){let Y=this.uniqueKey(z,G);if(Y)return this.pushUnique(z,G,Y,V);let Z=this.driver.joinsTransaction?.()===!0;if(!Z){let $=Bun.randomUUIDv7();if(_(()=>this.record(z,G,{id:$,reportFailure:!0,committed:!0}).then(()=>{},()=>{})))return Promise.resolve($)}return this.record(z,G,{reportFailure:V.reportFailure,joins:Z})}pushBatch(z,G,V={}){if(!this.driver.enqueueBatch)throw Error("This queue's driver does not support batches. The memory and database drivers do.");if(new z().worker)throw Error(`${z.name} is a worker job, and a worker job cannot be dispatched in a batch: its thread has no way to report progress or reach the batch.`);if(z.prototype.uniqueId!==R.prototype.uniqueId)throw Error(`${z.name} is unique (it defines uniqueId), and a unique job cannot be dispatched in a batch: a duplicate would resolve to a job outside the batch, and the batch would wait for it forever.`);let Z={};for(let H of["then","catch","finally"]){let K=V[H];if(K===void 0)continue;if(typeof K?.name!=="string"||!Array.isArray(K.args))throw Error(`The batch's ${H} callback is not a job call. Build it with SomeJob.with(...args).`);Z[H]={name:K.name,args:K.args}}let $={id:Bun.randomUUIDv7(),name:V.name??null,job:z.name,args:G,allowFailures:V.allowFailures===!0,callbacks:Z},X={id:$.id,total:G.length},F=this.driver.joinsTransaction?.()===!0;if(!F){if(_(()=>this.recordBatch($,{committed:!0}).then(()=>{},()=>{})))return Promise.resolve(X)}return this.recordBatch($,{joins:F}).then(()=>X)}recordBatch(z,G){let V=this.driver.enqueueBatch(z);this.startIfIdle();let Y=()=>!this.driver.subscribe&&this.state==="running"&&this.wake(),Z=G.joins===!0&&_(Y);return V.then(()=>Z||Y(),($)=>{if(!G.committed)return;console.error(`[gemi] The queue driver could not record a batch of ${z.job}, which was held until its transaction committed. The transaction stays committed; the batch's jobs did not run and will not be retried.`,$)}),V}async findBatch(z){if(!this.driver.findBatch)throw Error("This queue's driver does not support batches.");return this.driver.findBatch(z)}async cancelBatch(z){if(!this.driver.cancelBatch)throw Error("This queue's driver does not support batches.");let G=await this.driver.cancelBatch(z);if(G)this.claimSoon();return G}get locks(){return this.lockManager??=new s(this.resolveLockStore()),this.lockManager}resolveLockStore(){let z=this.config.locks;if(z==="auto"){let G=this.driver.lockStore?.();if(G)return G;if(this.durable)console.warn('[gemi] The queue driver keeps no locks, so unique jobs, withoutOverlapping and onOneServer only hold within this process. Set the queue slice\'s `locks` to "database" or a LockStore.');return new D}if(z==="memory")return new D;if(z==="database"||typeof z==="function"){if(!this.application&&(z==="database"||z.length>0))throw Error("The queue's locks need the application they belong to, and this QueueManager was built without one. Pass { application }.");if(z==="database")return new N(this.application.make(f));return z(this.application)}if(typeof z==="string")throw Error(`Unknown queue locks "${z}". The queue slice's locks is "auto", "memory", "database", a LockStore, or a function returning one.`);return z}uniqueKey(z,G){if(z.prototype.uniqueId===R.prototype.uniqueId)return;let V=new z,Y=V.uniqueId(...JSON.parse(G));if(Y===void 0||Y===null||Y==="")return;return{key:m(z.name,Y),ttl:Math.max(1,V.uniqueFor)}}pushUnique(z,G,V,Y){let Z=Bun.randomUUIDv7();if(_(()=>this.recordUnique(z,G,V,Z,{report:!0,committed:!0}).then(()=>{},()=>{})))return Promise.resolve(Z);return this.recordUnique(z,G,V,Z,{report:Y.reportFailure!==!1,committed:!1})}recordUnique(z,G,V,Y,Z){let $=this.locks.store,X=(async()=>{for(let F=0;F<5;F++){if(await $.acquire(V.key,Y,V.ttl)!==null)try{return await this.record(z,G,{id:Y,reportFailure:!1})}catch(K){throw await $.release(V.key,Y).catch(()=>{}),K}let H=await $.holder(V.key);if(H)return H.owner}throw Error(`The unique key "${V.key}" kept changing hands, so ${z.name} was not queued.`)})();return X.catch((F)=>{if(!Z.report)return;console.error(`[gemi] The queue could not record the unique job ${z.name}`+(Z.committed?", which was held until its transaction committed. The transaction stays committed; the job did not run and will not be retried.":", so it did not run and will not be retried."),F)}),X}async releaseUnique(z,G,V){if(z.uniqueId===R.prototype.uniqueId)return;try{let Y=z.uniqueId(...G);if(Y===void 0||Y===null||Y==="")return;await this.locks.store.release(m(V.name,Y),V.id)}catch(Y){console.error(`[gemi] Could not free the unique key of ${V.name} (${V.id}); it frees itself after uniqueFor.`,Y)}}record(z,G,V){let Y=this.driver.enqueue({name:z.name,args:G,...V.id===void 0?{}:{id:V.id}});this.startIfIdle();let Z=()=>!this.driver.subscribe&&this.state==="running"&&this.wake(),$=V.joins===!0&&_(Z);return Y.then(()=>$||Z(),(X)=>{if(V.reportFailure===!1)return;console.error(`[gemi] The queue driver could not record ${z.name}`+(V.committed?", which was held until its transaction committed. The transaction stays committed; the job did not run and will not be retried.":", so it did not run and will not be retried."),X)}),Y}async retryDead(z){if(!this.driver.retryDead)throw Error("This queue's driver keeps nothing of a dead-lettered job, so there is nothing to retry. The database driver keeps them.");let G=await this.driver.retryDead(z);if(G)this.claimSoon();return G}startIfIdle(){if(this.state==="idle"&&(!this.durable||this.mayClaimHere()))this.start()}claimSoon(){if(this.startIfIdle(),!this.driver.subscribe&&this.state==="running")this.wake()}start(){if(this.state==="running")return;if(this.state="running",this.durable&&this.application&&this.mayClaimHere()&&!Fz())globalThis.__gemiDevQueue=this;if(this.unsubscribe=this.driver.subscribe?.(()=>this.wake()),this.looping)return this.wake();$z.runInAsyncScope(()=>void this.loop())}async drain(z=1/0){if(this.state="stopped",globalThis.__gemiDevQueue===this)globalThis.__gemiDevQueue=void 0;this.unsubscribe?.(),this.unsubscribe=void 0,this.wake();let G,V=new Promise((Z)=>{if(z!==1/0)G=setTimeout(Z,z)}),Y=(async()=>{await this.claiming?.catch(()=>{}),await Promise.allSettled([...this.inFlight.values()].map((Z)=>Z.done))})();return await Promise.race([Y,V]),clearTimeout(G),{unfinished:[...this.inFlight.values()].map((Z)=>({...Z.job}))}}stop(){return this.drain(0)}get running(){return this.inFlight.size}async loop(){this.looping=!0;try{await this.claimWhileRunning()}finally{this.looping=!1}}async claimWhileRunning(){while(this.state==="running"){let z=this.durable&&l()?0:this.config.concurrency-this.inFlight.size;if(z>0){this.woken=!1;let G=this.driver.claim(z,{...this.lease(),registered:{names:Object.keys(this.jobs),graceMs:this.config.unknownJobGrace}});this.claiming=G;let V=[];try{V=await G,this.claimFailures=0}catch(Y){this.claimFailures++,console.error(`The queue could not claim jobs from its driver; it will try again in ${this.retryDelay()}ms.`,Y)}finally{this.claiming=void 0}for(let Y of V)this.execute(Y);if(V.length===z)continue;if(this.woken&&this.inFlight.size<this.config.concurrency)continue}await this.sleep()}}sleep(){return new Promise((z)=>{let G,V=this.claimFailures>0?this.retryDelay():this.driver.subscribe?void 0:this.config.pollInterval;if(V!==void 0)G=setTimeout(()=>this.wake(),V),G.unref?.();this.resume=()=>{clearTimeout(G),z()}})}retryDelay(){let z=Math.min(Math.max(0,this.claimFailures-1),30);return Math.min(this.config.pollInterval*2**z,Xz)}wake(){this.woken=!0;let z=this.resume;this.resume=void 0,z?.()}get durable(){return!(this.driver instanceof T)}mayClaimHere(){return!this.application||Kz()}lease(){return{visibilityTimeoutMs:this.config.visibilityTimeout}}execute(z){let G=`${z.id}:${z.attempt}`,V=()=>this.run(z),Y=(this.application?b.run(this.application,V):V()).catch((Z)=>{console.error(`The queue could not record the outcome of ${z.name}.`,Z)}).finally(()=>{this.inFlight.delete(G),this.wake()});this.inFlight.set(G,{job:z,done:Y}),this.heartbeat()}heartbeat(){let z=this.driver;if(!z.heartbeat||this.heartbeatTimer)return;this.heartbeatTimer=setInterval(()=>{if(this.inFlight.size===0){clearInterval(this.heartbeatTimer),this.heartbeatTimer=void 0;return}let G=[...this.inFlight.values()].map((V)=>V.job);z.heartbeat(G,this.lease()).catch((V)=>{console.error("The queue could not extend its job leases.",V)})},Math.max(1,Math.floor(this.config.visibilityTimeout/3))),this.heartbeatTimer.unref?.()}async run(z){let G=this.jobs[z.name];if(!G){let K=Date.now()-z.createdAt;if(this.durable&&K<this.config.unknownJobGrace){if(!this.releasedNames.has(z.name))this.releasedNames.add(z.name),console.error(`Left a queued "${z.name}" for another replica: nothing is registered here under that name. It is dead-lettered if no replica has run it within unknownJobGrace (${this.config.unknownJobGrace}ms) of its dispatch.`);await this.driver.release(z,{retryInMs:Math.round(this.config.pollInterval*(1+Math.random()))});return}console.error(`Dropped a queued job: nothing is registered under the name "${z.name}". If the class exists, it was not `+"discovered \u2014 check that it is under the queue slice's jobsDir "+"(app/jobs by default), or list it in app/config/queue.ts."),await this.driver.fail(z,{error:`No job is registered under the name "${z.name}".`,retryInMs:null});return}let V;try{V=new G}catch(K){console.error(`Dropped a queued ${z.name}: it could not be constructed.`,K),await this.driver.fail(z,{error:`The job could not be constructed: ${String(K)}`,retryInMs:null});return}let Y;try{Y=JSON.parse(z.args)}catch(K){console.error(`Dropped a queued ${z.name}: its arguments are not JSON.`,K),await this.driver.fail(z,{error:`The arguments are not JSON: ${String(K)}`,retryInMs:null});return}if(z.attempt>Math.max(1,V.maxAttempts)){let K=Error(`${z.name} was claimed for attempt ${z.attempt} of ${V.maxAttempts}: an earlier attempt never finished, most likely because the process running it exited. Dead-lettered without running it again.`);g(`${z.name}.onDeadletter`,()=>V.onDeadletter(K,...Y)),await this.driver.fail(z,{error:K.message,retryInMs:null}),await this.releaseUnique(V,Y,z);return}if(z.batchId!==void 0){if((await this.driver.findBatch?.(z.batchId,{progress:!1}))?.cancelledAt!=null){await this.driver.fail(z,{error:"Its batch was cancelled before it ran.",retryInMs:null,cancelled:!0});return}let J=this.batchHandle(z);V.batch=J.batch,V.$progress=J.progress}let Z=await this.admit(V,Y,z);if(!Z)return;let $,X;try{X=await(V.worker?Zz(z.name,z.args):V.run(...Y))}catch(K){$=K}finally{await Z.done()}let F=V.$outcome;if($===void 0&&F?.kind==="release"){await this.driver.release(z,{retryInMs:Math.max(0,F.delayMs)});return}if($===void 0&&F?.kind==="fail")$=F.error;let H=F?.kind==="fail"?F.retry:!0;if($===void 0)try{V.onSuccess(X,...Y)}catch(K){$=K}if($!==void 0){let K=String($?.stack??$);if(g(`${z.name}.onFail`,()=>V.onFail($,...Y)),!H||z.attempt>=V.maxAttempts)g(`${z.name}.onDeadletter`,()=>V.onDeadletter($,...Y)),await this.driver.fail(z,{error:K,retryInMs:null}),await this.releaseUnique(V,Y,z);else await this.driver.fail(z,{error:K,retryInMs:Wz(V.backoff,z.attempt)});return}await this.driver.complete(z),await this.releaseUnique(V,Y,z)}batchHandle(z){let G=z.batchId,V=this.driver;return{batch:{id:G,cancelled:async()=>(await V.findBatch?.(G,{progress:!1}))?.cancelledAt!=null},progress:(Y)=>V.reportProgress?.(z,Y)??Promise.resolve()}}async admit(z,G,V){let Y=z.concurrency(...G),Z=[z.throttle(...G)??[]].flat();if(!Y&&Z.length===0)return{done:async()=>{}};let $=this.locks,X;if(Y&&Y.limit>0){let H=this.config.visibilityTimeout;for(let K=0;K<Y.limit&&!X;K++)X=await $.acquire(`gemi:concurrency:${Y.key}:${K}`,{ttl:H,renew:!0})??void 0;if(!X){await this.driver.release(V,{retryInMs:Math.round(this.config.pollInterval*(1+Math.random()))});return}}let F=[];for(let H of Z){let K=`gemi:throttle:${H.key}`,J=await $.store.hit(K,H.limit,H.window);if(!J.allowed){await Promise.all(F.map((i)=>$.store.refund(i))),await X?.release(),await this.driver.release(V,{retryInMs:Math.max(1,J.resetInMs)});return}F.push(K)}return{done:async()=>{await X?.release().catch((H)=>{console.error(`[gemi] Could not free a concurrency slot of ${V.name}.`,H)})}}}}function m(z,G){return`gemi:job:${z}:${String(G)}`}function g(z,G){try{G()}catch(V){console.error(`${z} threw; the job's claim was ended anyway.`,V)}}function Fz(){return Bun.env.NODE_ENV==="production"}function Kz(){if(!Vz)return!1;if(Jz())return!0;return process.env.ROOT_DIR!==void 0&&!Hz()}function Hz(z=process.env){return(z.GEMI_QUEUE_CLAIM??"").trim().toLowerCase()==="off"}var c=Symbol.for("gemi.queue.worker");function mz(z=!0){globalThis[c]=z}function Jz(){return globalThis[c]===!0}function Wz(z,G){let V=Array.isArray(z)?z[Math.min(G,z.length)-1]:z;return Math.max(0,V??0)}function Az(z,G){if(z==="memory")return new T;if(z==="database"||typeof z==="function"){if(!G&&(z==="database"||z.length>0))throw Error("The queue driver needs the application it belongs to, and this QueueManager was built without one. Pass { application }.");if(z==="database")return new y(G.make(f));return z(G)}if(typeof z==="string")throw Error(`Unknown queue driver "${z}". The queue slice's driver is "memory", "database", a QueueDriver, or a function returning one.`);return z}class R{static name="unset";worker=!1;maxAttempts=3;backoff=0;uniqueId(...z){return}uniqueFor=3600000;throttle(...z){return}concurrency(...z){return}release(z=0){this.$outcome={kind:"release",delayMs:z}}fail(z,G={}){this.$outcome={kind:"fail",error:z instanceof Error?z:Error(String(z)),retry:G.retry??!0}}batch=void 0;async progress(z){let G=U(z);await this.$progress?.(G)}$progress;$outcome;run(...z){}onFail(z,...G){}onSuccess(z,...G){}onDeadletter(z,...G){}static dispatch(...z){if(this.name==="unset")throw Error("Cannot dispatch a job with no name");return O(E).push(this,JSON.stringify(z))}static dispatchBatch(z,G={}){if(this.name==="unset")throw Error("Cannot dispatch a job with no name");return O(E).pushBatch(this,z.map((V)=>JSON.stringify(V)),G)}static with(...z){if(this.name==="unset")throw Error("Cannot use a job with no name as a callback");return JSON.stringify(z),{name:this.name,args:z}}static findBatch(z){return O(E).findBatch(z)}static cancelBatch(z){return O(E).cancelBatch(z)}}
300
+ export{D as zc,N as Ac,y as Bc,R as Cc,Dz as Dc,q as Ec,T as Fc,E as Gc,Kz as Hc,Hz as Ic,mz as Jc,Jz as Kc};
301
+
302
+ //# debugId=803B45721DCF33DC64756E2164756E21