rivetkit 2.0.2 → 2.0.4-rc.1

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 (403) hide show
  1. package/README.md +3 -5
  2. package/dist/browser/client.d.ts +2485 -0
  3. package/dist/browser/client.js +5182 -0
  4. package/dist/browser/client.js.map +1 -0
  5. package/dist/browser/inspector/client.d.ts +130 -0
  6. package/dist/browser/inspector/client.js +2854 -0
  7. package/dist/browser/inspector/client.js.map +1 -0
  8. package/dist/browser/v3-DnYObHH3.d.ts +279 -0
  9. package/dist/inspector.tar.gz +0 -0
  10. package/dist/schemas/actor-inspector/v1.ts +784 -0
  11. package/dist/schemas/actor-inspector/v2.ts +796 -0
  12. package/dist/schemas/actor-inspector/v3.ts +899 -0
  13. package/dist/schemas/actor-persist/v1.ts +225 -0
  14. package/dist/schemas/actor-persist/v2.ts +268 -0
  15. package/dist/schemas/actor-persist/v3.ts +280 -0
  16. package/dist/schemas/actor-persist/v4.ts +406 -0
  17. package/dist/schemas/client-protocol/v1.ts +441 -0
  18. package/dist/schemas/client-protocol/v2.ts +438 -0
  19. package/dist/schemas/client-protocol/v3.ts +554 -0
  20. package/dist/schemas/file-system-driver/v1.ts +108 -0
  21. package/dist/schemas/file-system-driver/v2.ts +142 -0
  22. package/dist/schemas/file-system-driver/v3.ts +167 -0
  23. package/dist/schemas/persist/v1.ts +781 -0
  24. package/dist/schemas/transport/v1.ts +697 -0
  25. package/dist/tsup/actor/errors.cjs +106 -0
  26. package/dist/tsup/actor/errors.cjs.map +1 -0
  27. package/dist/tsup/actor/errors.d.cts +188 -0
  28. package/dist/tsup/actor/errors.d.ts +188 -0
  29. package/dist/tsup/actor/errors.js +106 -0
  30. package/dist/tsup/actor/errors.js.map +1 -0
  31. package/dist/tsup/actor-router-consts-D29T1Z-K.d.cts +24 -0
  32. package/dist/tsup/actor-router-consts-D29T1Z-K.d.ts +24 -0
  33. package/dist/tsup/chunk-325TLXJT.js +1060 -0
  34. package/dist/tsup/chunk-325TLXJT.js.map +1 -0
  35. package/dist/tsup/chunk-424PT5DM.js +23 -0
  36. package/dist/tsup/chunk-424PT5DM.js.map +1 -0
  37. package/dist/tsup/chunk-4JVIG3SS.cjs +6289 -0
  38. package/dist/tsup/chunk-4JVIG3SS.cjs.map +1 -0
  39. package/dist/tsup/chunk-6LJAZ5R4.cjs +96 -0
  40. package/dist/tsup/chunk-6LJAZ5R4.cjs.map +1 -0
  41. package/dist/tsup/chunk-6XU3FMCB.cjs +534 -0
  42. package/dist/tsup/chunk-6XU3FMCB.cjs.map +1 -0
  43. package/dist/tsup/chunk-7HTNH26M.js +509 -0
  44. package/dist/tsup/chunk-7HTNH26M.js.map +1 -0
  45. package/dist/tsup/chunk-AUVH72RE.cjs +5977 -0
  46. package/dist/tsup/chunk-AUVH72RE.cjs.map +1 -0
  47. package/dist/tsup/chunk-D4BYUPNQ.js +645 -0
  48. package/dist/tsup/chunk-D4BYUPNQ.js.map +1 -0
  49. package/dist/tsup/chunk-HDQ2JUQT.cjs +23 -0
  50. package/dist/tsup/chunk-HDQ2JUQT.cjs.map +1 -0
  51. package/dist/tsup/chunk-HHXX2VRM.js +6289 -0
  52. package/dist/tsup/chunk-HHXX2VRM.js.map +1 -0
  53. package/dist/tsup/chunk-JEAEA2PB.js +49 -0
  54. package/dist/tsup/chunk-JEAEA2PB.js.map +1 -0
  55. package/dist/tsup/chunk-JYSEG3VF.cjs +642 -0
  56. package/dist/tsup/chunk-JYSEG3VF.cjs.map +1 -0
  57. package/dist/tsup/chunk-K6DGYILQ.js +2657 -0
  58. package/dist/tsup/chunk-K6DGYILQ.js.map +1 -0
  59. package/dist/tsup/chunk-KJSYAUOM.js +96 -0
  60. package/dist/tsup/chunk-KJSYAUOM.js.map +1 -0
  61. package/dist/tsup/chunk-L47L3ZWJ.cjs +509 -0
  62. package/dist/tsup/chunk-L47L3ZWJ.cjs.map +1 -0
  63. package/dist/tsup/chunk-LXUQ667X.js +2006 -0
  64. package/dist/tsup/chunk-LXUQ667X.js.map +1 -0
  65. package/dist/tsup/chunk-MXNPAB5W.js +5977 -0
  66. package/dist/tsup/chunk-MXNPAB5W.js.map +1 -0
  67. package/dist/tsup/chunk-N4KRDJ56.js +72 -0
  68. package/dist/tsup/chunk-N4KRDJ56.js.map +1 -0
  69. package/dist/tsup/chunk-NIYZDWMW.cjs +2006 -0
  70. package/dist/tsup/chunk-NIYZDWMW.cjs.map +1 -0
  71. package/dist/tsup/chunk-PQZHDKRW.cjs +1060 -0
  72. package/dist/tsup/chunk-PQZHDKRW.cjs.map +1 -0
  73. package/dist/tsup/chunk-PVOE6BU7.cjs +1050 -0
  74. package/dist/tsup/chunk-PVOE6BU7.cjs.map +1 -0
  75. package/dist/tsup/chunk-Q4UD2GA4.cjs +1810 -0
  76. package/dist/tsup/chunk-Q4UD2GA4.cjs.map +1 -0
  77. package/dist/tsup/chunk-QUD664YZ.js +1810 -0
  78. package/dist/tsup/chunk-QUD664YZ.js.map +1 -0
  79. package/dist/tsup/chunk-RTOCTWME.js +1050 -0
  80. package/dist/tsup/chunk-RTOCTWME.js.map +1 -0
  81. package/dist/tsup/chunk-SAZZ4SB2.cjs +2657 -0
  82. package/dist/tsup/chunk-SAZZ4SB2.cjs.map +1 -0
  83. package/dist/tsup/chunk-SR3KQE7Q.cjs +72 -0
  84. package/dist/tsup/chunk-SR3KQE7Q.cjs.map +1 -0
  85. package/dist/tsup/chunk-V2GHLYC6.cjs +49 -0
  86. package/dist/tsup/chunk-V2GHLYC6.cjs.map +1 -0
  87. package/dist/tsup/chunk-V3WG7XTW.cjs +645 -0
  88. package/dist/tsup/chunk-V3WG7XTW.cjs.map +1 -0
  89. package/dist/tsup/chunk-VKVNIQRQ.js +257 -0
  90. package/dist/tsup/chunk-VKVNIQRQ.js.map +1 -0
  91. package/dist/tsup/chunk-WMPW7JYC.js +642 -0
  92. package/dist/tsup/chunk-WMPW7JYC.js.map +1 -0
  93. package/dist/tsup/chunk-Z7HNQ2WF.js +534 -0
  94. package/dist/tsup/chunk-Z7HNQ2WF.js.map +1 -0
  95. package/dist/tsup/chunk-ZFY5J2EP.cjs +257 -0
  96. package/dist/tsup/chunk-ZFY5J2EP.cjs.map +1 -0
  97. package/dist/tsup/client/mod.cjs +33 -0
  98. package/dist/tsup/client/mod.cjs.map +1 -0
  99. package/dist/tsup/client/mod.d.cts +64 -0
  100. package/dist/tsup/client/mod.d.ts +64 -0
  101. package/dist/tsup/client/mod.js +33 -0
  102. package/dist/tsup/client/mod.js.map +1 -0
  103. package/dist/tsup/common/log.cjs +21 -0
  104. package/dist/tsup/common/log.cjs.map +1 -0
  105. package/dist/tsup/common/log.d.cts +34 -0
  106. package/dist/tsup/common/log.d.ts +34 -0
  107. package/dist/tsup/common/log.js +21 -0
  108. package/dist/tsup/common/log.js.map +1 -0
  109. package/dist/tsup/common/websocket.cjs +10 -0
  110. package/dist/tsup/common/websocket.cjs.map +1 -0
  111. package/dist/tsup/common/websocket.d.cts +3 -0
  112. package/dist/tsup/common/websocket.d.ts +3 -0
  113. package/dist/tsup/common/websocket.js +10 -0
  114. package/dist/tsup/common/websocket.js.map +1 -0
  115. package/dist/tsup/config-BiNoIHRs.d.cts +80 -0
  116. package/dist/tsup/config-BiNoIHRs.d.ts +80 -0
  117. package/dist/tsup/config-P3XujgRr.d.ts +2594 -0
  118. package/dist/tsup/config-_gfywqqI.d.cts +2594 -0
  119. package/dist/tsup/context-Bxd8Cx4H.d.cts +75 -0
  120. package/dist/tsup/context-uNA4TRn3.d.ts +75 -0
  121. package/dist/tsup/db/drizzle/mod.cjs +49 -0
  122. package/dist/tsup/db/drizzle/mod.cjs.map +1 -0
  123. package/dist/tsup/db/drizzle/mod.d.cts +17 -0
  124. package/dist/tsup/db/drizzle/mod.d.ts +17 -0
  125. package/dist/tsup/db/drizzle/mod.js +49 -0
  126. package/dist/tsup/db/drizzle/mod.js.map +1 -0
  127. package/dist/tsup/db/mod.cjs +9 -0
  128. package/dist/tsup/db/mod.cjs.map +1 -0
  129. package/dist/tsup/db/mod.d.cts +9 -0
  130. package/dist/tsup/db/mod.d.ts +9 -0
  131. package/dist/tsup/db/mod.js +9 -0
  132. package/dist/tsup/db/mod.js.map +1 -0
  133. package/dist/tsup/driver-BcLvZcKl.d.cts +13 -0
  134. package/dist/tsup/driver-CPGHKXyh.d.ts +13 -0
  135. package/dist/tsup/driver-helpers/mod.cjs +53 -0
  136. package/dist/tsup/driver-helpers/mod.cjs.map +1 -0
  137. package/dist/tsup/driver-helpers/mod.d.cts +47 -0
  138. package/dist/tsup/driver-helpers/mod.d.ts +47 -0
  139. package/dist/tsup/driver-helpers/mod.js +53 -0
  140. package/dist/tsup/driver-helpers/mod.js.map +1 -0
  141. package/dist/tsup/driver-test-suite/mod.cjs +4974 -0
  142. package/dist/tsup/driver-test-suite/mod.cjs.map +1 -0
  143. package/dist/tsup/driver-test-suite/mod.d.cts +73 -0
  144. package/dist/tsup/driver-test-suite/mod.d.ts +73 -0
  145. package/dist/tsup/driver-test-suite/mod.js +4974 -0
  146. package/dist/tsup/driver-test-suite/mod.js.map +1 -0
  147. package/dist/tsup/inspector/mod.cjs +164 -0
  148. package/dist/tsup/inspector/mod.cjs.map +1 -0
  149. package/dist/tsup/inspector/mod.d.cts +130 -0
  150. package/dist/tsup/inspector/mod.d.ts +130 -0
  151. package/dist/tsup/inspector/mod.js +164 -0
  152. package/dist/tsup/inspector/mod.js.map +1 -0
  153. package/dist/tsup/keys-CydblqMh.d.cts +13 -0
  154. package/dist/tsup/keys-CydblqMh.d.ts +13 -0
  155. package/dist/tsup/mod.cjs +82 -0
  156. package/dist/tsup/mod.cjs.map +1 -0
  157. package/dist/tsup/mod.d.cts +126 -0
  158. package/dist/tsup/mod.d.ts +126 -0
  159. package/dist/tsup/mod.js +82 -0
  160. package/dist/tsup/mod.js.map +1 -0
  161. package/dist/tsup/serve-test-suite/mod.cjs +2601 -0
  162. package/dist/tsup/serve-test-suite/mod.cjs.map +1 -0
  163. package/dist/tsup/serve-test-suite/mod.d.cts +9 -0
  164. package/dist/tsup/serve-test-suite/mod.d.ts +9 -0
  165. package/dist/tsup/serve-test-suite/mod.js +2601 -0
  166. package/dist/tsup/serve-test-suite/mod.js.map +1 -0
  167. package/dist/tsup/test/mod.cjs +90 -0
  168. package/dist/tsup/test/mod.cjs.map +1 -0
  169. package/dist/tsup/test/mod.d.cts +26 -0
  170. package/dist/tsup/test/mod.d.ts +26 -0
  171. package/dist/tsup/test/mod.js +90 -0
  172. package/dist/tsup/test/mod.js.map +1 -0
  173. package/dist/tsup/utils-fwx3o3K9.d.cts +18 -0
  174. package/dist/tsup/utils-fwx3o3K9.d.ts +18 -0
  175. package/dist/tsup/utils.cjs +43 -0
  176. package/dist/tsup/utils.cjs.map +1 -0
  177. package/dist/tsup/utils.d.cts +148 -0
  178. package/dist/tsup/utils.d.ts +148 -0
  179. package/dist/tsup/utils.js +43 -0
  180. package/dist/tsup/utils.js.map +1 -0
  181. package/dist/tsup/v3-DnYObHH3.d.cts +279 -0
  182. package/dist/tsup/v3-DnYObHH3.d.ts +279 -0
  183. package/dist/tsup/workflow/mod.cjs +16 -0
  184. package/dist/tsup/workflow/mod.cjs.map +1 -0
  185. package/dist/tsup/workflow/mod.d.cts +25 -0
  186. package/dist/tsup/workflow/mod.d.ts +25 -0
  187. package/dist/tsup/workflow/mod.js +16 -0
  188. package/dist/tsup/workflow/mod.js.map +1 -0
  189. package/package.json +293 -5
  190. package/src/actor/config.ts +1221 -0
  191. package/src/actor/conn/driver.ts +61 -0
  192. package/src/actor/conn/drivers/http.ts +17 -0
  193. package/src/actor/conn/drivers/raw-request.ts +24 -0
  194. package/src/actor/conn/drivers/raw-websocket.ts +65 -0
  195. package/src/actor/conn/drivers/websocket.ts +144 -0
  196. package/src/actor/conn/mod.ts +288 -0
  197. package/src/actor/conn/persisted.ts +81 -0
  198. package/src/actor/conn/state-manager.ts +196 -0
  199. package/src/actor/contexts/action.ts +47 -0
  200. package/src/actor/contexts/base/actor.ts +347 -0
  201. package/src/actor/contexts/base/conn-init.ts +68 -0
  202. package/src/actor/contexts/base/conn.ts +73 -0
  203. package/src/actor/contexts/before-action-response.ts +42 -0
  204. package/src/actor/contexts/before-connect.ts +31 -0
  205. package/src/actor/contexts/connect.ts +42 -0
  206. package/src/actor/contexts/create-conn-state.ts +32 -0
  207. package/src/actor/contexts/create-vars.ts +39 -0
  208. package/src/actor/contexts/create.ts +39 -0
  209. package/src/actor/contexts/destroy.ts +42 -0
  210. package/src/actor/contexts/disconnect.ts +43 -0
  211. package/src/actor/contexts/index.ts +33 -0
  212. package/src/actor/contexts/request.ts +80 -0
  213. package/src/actor/contexts/run.ts +47 -0
  214. package/src/actor/contexts/sleep.ts +42 -0
  215. package/src/actor/contexts/state-change.ts +42 -0
  216. package/src/actor/contexts/wake.ts +42 -0
  217. package/src/actor/contexts/websocket.ts +80 -0
  218. package/src/actor/database.ts +13 -0
  219. package/src/actor/definition.ts +64 -0
  220. package/src/actor/driver.ts +114 -0
  221. package/src/actor/errors.ts +556 -0
  222. package/src/actor/instance/connection-manager.ts +574 -0
  223. package/src/actor/instance/event-manager.ts +314 -0
  224. package/src/actor/instance/keys.ts +146 -0
  225. package/src/actor/instance/kv.ts +241 -0
  226. package/src/actor/instance/mod.ts +1658 -0
  227. package/src/actor/instance/persisted.ts +67 -0
  228. package/src/actor/instance/queue-manager.ts +603 -0
  229. package/src/actor/instance/queue.ts +345 -0
  230. package/src/actor/instance/schedule-manager.ts +392 -0
  231. package/src/actor/instance/state-manager.ts +542 -0
  232. package/src/actor/instance/traces-driver.ts +128 -0
  233. package/src/actor/keys.test.ts +275 -0
  234. package/src/actor/keys.ts +89 -0
  235. package/src/actor/log.ts +6 -0
  236. package/src/actor/mod.ts +110 -0
  237. package/src/actor/protocol/old.ts +416 -0
  238. package/src/actor/protocol/serde.ts +222 -0
  239. package/src/actor/router-endpoints.ts +400 -0
  240. package/src/actor/router-websocket-endpoints.test.ts +54 -0
  241. package/src/actor/router-websocket-endpoints.ts +405 -0
  242. package/src/actor/router.ts +380 -0
  243. package/src/actor/schedule.ts +17 -0
  244. package/src/actor/schema.ts +291 -0
  245. package/src/actor/utils.test.ts +48 -0
  246. package/src/actor/utils.ts +158 -0
  247. package/src/client/actor-common.ts +32 -0
  248. package/src/client/actor-conn.ts +1262 -0
  249. package/src/client/actor-handle.ts +344 -0
  250. package/src/client/actor-query.ts +112 -0
  251. package/src/client/client.ts +558 -0
  252. package/src/client/config.ts +151 -0
  253. package/src/client/errors.ts +76 -0
  254. package/src/client/log.ts +5 -0
  255. package/src/client/mod.browser.ts +2 -0
  256. package/src/client/mod.ts +70 -0
  257. package/src/client/queue.ts +146 -0
  258. package/src/client/raw-utils.ts +149 -0
  259. package/src/client/test.ts +44 -0
  260. package/src/client/utils.ts +252 -0
  261. package/src/common/actor-router-consts.ts +59 -0
  262. package/src/common/cors.ts +57 -0
  263. package/src/common/eventsource-interface.ts +47 -0
  264. package/src/common/eventsource.ts +44 -0
  265. package/src/common/inline-websocket-adapter.ts +154 -0
  266. package/src/common/log-levels.ts +27 -0
  267. package/src/common/log.ts +229 -0
  268. package/src/common/logfmt.ts +221 -0
  269. package/src/common/network.ts +2 -0
  270. package/src/common/router.ts +174 -0
  271. package/src/common/utils.ts +339 -0
  272. package/src/common/websocket-interface.ts +7 -0
  273. package/src/common/websocket.ts +43 -0
  274. package/src/db/config.ts +100 -0
  275. package/src/db/drizzle/mod.ts +226 -0
  276. package/src/db/drizzle/sqlite-core.ts +22 -0
  277. package/src/db/mod.ts +125 -0
  278. package/src/db/shared.ts +92 -0
  279. package/src/db/sqlite-vfs.ts +12 -0
  280. package/src/devtools-loader/index.ts +33 -0
  281. package/src/devtools-loader/log.ts +5 -0
  282. package/src/driver-helpers/mod.ts +33 -0
  283. package/src/driver-helpers/utils.ts +54 -0
  284. package/src/driver-test-suite/log.ts +5 -0
  285. package/src/driver-test-suite/mod.ts +293 -0
  286. package/src/driver-test-suite/test-inline-client-driver.ts +307 -0
  287. package/src/driver-test-suite/tests/access-control.ts +218 -0
  288. package/src/driver-test-suite/tests/action-features.ts +203 -0
  289. package/src/driver-test-suite/tests/actor-conn-hibernation.ts +152 -0
  290. package/src/driver-test-suite/tests/actor-conn-state.ts +300 -0
  291. package/src/driver-test-suite/tests/actor-conn.ts +596 -0
  292. package/src/driver-test-suite/tests/actor-db-raw.ts +73 -0
  293. package/src/driver-test-suite/tests/actor-db.ts +477 -0
  294. package/src/driver-test-suite/tests/actor-destroy.ts +294 -0
  295. package/src/driver-test-suite/tests/actor-driver.ts +18 -0
  296. package/src/driver-test-suite/tests/actor-error-handling.ts +150 -0
  297. package/src/driver-test-suite/tests/actor-handle.ts +312 -0
  298. package/src/driver-test-suite/tests/actor-inline-client.ts +163 -0
  299. package/src/driver-test-suite/tests/actor-inspector.ts +264 -0
  300. package/src/driver-test-suite/tests/actor-kv.ts +65 -0
  301. package/src/driver-test-suite/tests/actor-metadata.ts +116 -0
  302. package/src/driver-test-suite/tests/actor-onstatechange.ts +95 -0
  303. package/src/driver-test-suite/tests/actor-queue.ts +325 -0
  304. package/src/driver-test-suite/tests/actor-run.ts +181 -0
  305. package/src/driver-test-suite/tests/actor-schedule.ts +97 -0
  306. package/src/driver-test-suite/tests/actor-sleep.ts +415 -0
  307. package/src/driver-test-suite/tests/actor-state.ts +54 -0
  308. package/src/driver-test-suite/tests/actor-stateless.ts +70 -0
  309. package/src/driver-test-suite/tests/actor-vars.ts +97 -0
  310. package/src/driver-test-suite/tests/actor-workflow.ts +118 -0
  311. package/src/driver-test-suite/tests/manager-driver.ts +388 -0
  312. package/src/driver-test-suite/tests/raw-http-direct-registry.ts +227 -0
  313. package/src/driver-test-suite/tests/raw-http-request-properties.ts +454 -0
  314. package/src/driver-test-suite/tests/raw-http.ts +359 -0
  315. package/src/driver-test-suite/tests/raw-websocket-direct-registry.ts +393 -0
  316. package/src/driver-test-suite/tests/raw-websocket.ts +513 -0
  317. package/src/driver-test-suite/tests/request-access.ts +240 -0
  318. package/src/driver-test-suite/utils.ts +80 -0
  319. package/src/drivers/default.ts +38 -0
  320. package/src/drivers/engine/actor-driver.ts +1027 -0
  321. package/src/drivers/engine/config.ts +43 -0
  322. package/src/drivers/engine/log.ts +5 -0
  323. package/src/drivers/engine/mod.ts +36 -0
  324. package/src/drivers/file-system/actor.ts +102 -0
  325. package/src/drivers/file-system/global-state.ts +1445 -0
  326. package/src/drivers/file-system/kv-limits.ts +70 -0
  327. package/src/drivers/file-system/log.ts +5 -0
  328. package/src/drivers/file-system/manager.ts +300 -0
  329. package/src/drivers/file-system/mod.ts +78 -0
  330. package/src/drivers/file-system/sqlite-runtime.ts +210 -0
  331. package/src/drivers/file-system/utils.ts +125 -0
  332. package/src/engine-process/constants.ts +2 -0
  333. package/src/engine-process/log.ts +5 -0
  334. package/src/engine-process/mod.ts +464 -0
  335. package/src/globals.d.ts +35 -0
  336. package/src/inspector/actor-inspector.ts +352 -0
  337. package/src/inspector/config.ts +49 -0
  338. package/src/inspector/handler.ts +273 -0
  339. package/src/inspector/log.ts +5 -0
  340. package/src/inspector/mod.browser.ts +8 -0
  341. package/src/inspector/mod.ts +4 -0
  342. package/src/inspector/serve-ui.ts +40 -0
  343. package/src/inspector/transport.ts +18 -0
  344. package/src/inspector/utils.ts +32 -0
  345. package/src/manager/driver.ts +106 -0
  346. package/src/manager/gateway.ts +668 -0
  347. package/src/manager/log.ts +5 -0
  348. package/src/manager/mod.ts +2 -0
  349. package/src/manager/protocol/mod.ts +22 -0
  350. package/src/manager/protocol/query.ts +85 -0
  351. package/src/manager/router-schema.ts +22 -0
  352. package/src/manager/router.ts +660 -0
  353. package/src/manager-api/actors.ts +83 -0
  354. package/src/manager-api/common.ts +4 -0
  355. package/src/mod.ts +24 -0
  356. package/src/registry/config/driver.ts +21 -0
  357. package/src/registry/config/index.ts +510 -0
  358. package/src/registry/config/legacy-runner.ts +157 -0
  359. package/src/registry/config/runner.ts +21 -0
  360. package/src/registry/config/serverless.ts +94 -0
  361. package/src/registry/index.ts +194 -0
  362. package/src/registry/log.ts +5 -0
  363. package/src/remote-manager-driver/actor-http-client.ts +84 -0
  364. package/src/remote-manager-driver/actor-websocket-client.ts +81 -0
  365. package/src/remote-manager-driver/api-endpoints.ts +159 -0
  366. package/src/remote-manager-driver/api-utils.ts +69 -0
  367. package/src/remote-manager-driver/log.ts +5 -0
  368. package/src/remote-manager-driver/metadata.ts +64 -0
  369. package/src/remote-manager-driver/mod.ts +414 -0
  370. package/src/remote-manager-driver/ws-proxy.ts +189 -0
  371. package/src/schemas/actor-inspector/mod.ts +1 -0
  372. package/src/schemas/actor-inspector/versioned.ts +233 -0
  373. package/src/schemas/actor-persist/mod.ts +1 -0
  374. package/src/schemas/actor-persist/versioned.ts +217 -0
  375. package/src/schemas/client-protocol/mod.ts +1 -0
  376. package/src/schemas/client-protocol/versioned.ts +330 -0
  377. package/src/schemas/client-protocol-zod/mod.ts +118 -0
  378. package/src/schemas/file-system-driver/mod.ts +1 -0
  379. package/src/schemas/file-system-driver/versioned.ts +135 -0
  380. package/src/schemas/persist/mod.ts +1 -0
  381. package/src/schemas/transport/mod.ts +1 -0
  382. package/src/serde.ts +138 -0
  383. package/src/serve-test-suite/mod.ts +148 -0
  384. package/src/serverless/configure.ts +82 -0
  385. package/src/serverless/log.ts +5 -0
  386. package/src/serverless/router.test.ts +299 -0
  387. package/src/serverless/router.ts +215 -0
  388. package/src/test/log.ts +5 -0
  389. package/src/test/mod.ts +99 -0
  390. package/src/utils/crypto.ts +24 -0
  391. package/src/utils/endpoint-parser.test.ts +202 -0
  392. package/src/utils/endpoint-parser.ts +124 -0
  393. package/src/utils/env-vars.ts +78 -0
  394. package/src/utils/node.ts +178 -0
  395. package/src/utils/router.ts +83 -0
  396. package/src/utils/serve.ts +212 -0
  397. package/src/utils.test.ts +34 -0
  398. package/src/utils.ts +437 -0
  399. package/src/workflow/constants.ts +2 -0
  400. package/src/workflow/context.ts +597 -0
  401. package/src/workflow/driver.ts +194 -0
  402. package/src/workflow/inspector.ts +268 -0
  403. package/src/workflow/mod.ts +128 -0
@@ -0,0 +1,1050 @@
1
+ "use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } }
2
+
3
+ var _chunkPQZHDKRWcjs = require('./chunk-PQZHDKRW.cjs');
4
+
5
+
6
+
7
+
8
+
9
+
10
+
11
+ var _chunkL47L3ZWJcjs = require('./chunk-L47L3ZWJ.cjs');
12
+
13
+ // src/actor/config.ts
14
+ var _v4 = require('zod/v4');
15
+ var zFunction = () => _v4.z.custom((val) => typeof val === "function");
16
+ var WorkflowInspectorConfigSchema = _v4.z.object({
17
+ getHistory: zFunction(),
18
+ onHistoryUpdated: zFunction().optional()
19
+ });
20
+ var RunInspectorConfigSchema = _v4.z.object({
21
+ workflow: WorkflowInspectorConfigSchema.optional()
22
+ }).optional();
23
+ var RunConfigSchema = _v4.z.object({
24
+ /** Display name for the actor in the Inspector UI. */
25
+ name: _v4.z.string().optional(),
26
+ /** Icon for the actor in the Inspector UI. Can be an emoji or FontAwesome icon name. */
27
+ icon: _v4.z.string().optional(),
28
+ /** The run handler function. */
29
+ run: zFunction(),
30
+ /** Inspector integration for long-running run handlers. */
31
+ inspector: RunInspectorConfigSchema.optional()
32
+ });
33
+ var RUN_FUNCTION_CONFIG_SYMBOL = /* @__PURE__ */ Symbol.for(
34
+ "rivetkit.run_function_config"
35
+ );
36
+ var zRunHandler = _v4.z.union([zFunction(), RunConfigSchema]).optional();
37
+ function getRunFunction(run) {
38
+ if (!run) return void 0;
39
+ if (typeof run === "function") return run;
40
+ return run.run;
41
+ }
42
+ function getRunMetadata(run) {
43
+ if (!run) return {};
44
+ if (typeof run === "function") {
45
+ const config = run[RUN_FUNCTION_CONFIG_SYMBOL];
46
+ if (!config) return {};
47
+ return { name: config.name, icon: config.icon };
48
+ }
49
+ return { name: run.name, icon: run.icon };
50
+ }
51
+ function getRunInspectorConfig(run) {
52
+ var _a;
53
+ if (!run) return void 0;
54
+ if (typeof run === "function") {
55
+ return (_a = run[RUN_FUNCTION_CONFIG_SYMBOL]) == null ? void 0 : _a.inspector;
56
+ }
57
+ return run.inspector;
58
+ }
59
+ var ActorConfigSchema = _v4.z.object({
60
+ onCreate: zFunction().optional(),
61
+ onDestroy: zFunction().optional(),
62
+ onWake: zFunction().optional(),
63
+ onSleep: zFunction().optional(),
64
+ run: zRunHandler,
65
+ onStateChange: zFunction().optional(),
66
+ onBeforeConnect: zFunction().optional(),
67
+ onConnect: zFunction().optional(),
68
+ onDisconnect: zFunction().optional(),
69
+ onBeforeActionResponse: zFunction().optional(),
70
+ onRequest: zFunction().optional(),
71
+ onWebSocket: zFunction().optional(),
72
+ actions: _v4.z.record(_v4.z.string(), zFunction()).default(() => ({})),
73
+ events: _v4.z.record(_v4.z.string(), _v4.z.any()).optional(),
74
+ queues: _v4.z.record(_v4.z.string(), _v4.z.any()).optional(),
75
+ state: _v4.z.any().optional(),
76
+ createState: zFunction().optional(),
77
+ connState: _v4.z.any().optional(),
78
+ createConnState: zFunction().optional(),
79
+ vars: _v4.z.any().optional(),
80
+ db: _v4.z.any().optional(),
81
+ createVars: zFunction().optional(),
82
+ options: _v4.z.object({
83
+ /** Display name for the actor in the Inspector UI. */
84
+ name: _v4.z.string().optional(),
85
+ /** Icon for the actor in the Inspector UI. Can be an emoji or FontAwesome icon name. */
86
+ icon: _v4.z.string().optional(),
87
+ createVarsTimeout: _v4.z.number().positive().default(5e3),
88
+ createConnStateTimeout: _v4.z.number().positive().default(5e3),
89
+ onConnectTimeout: _v4.z.number().positive().default(5e3),
90
+ // This must be less than engine config > pegboard.actor_stop_threshold
91
+ onSleepTimeout: _v4.z.number().positive().default(5e3),
92
+ // This must be less than engine config > pegboard.actor_stop_threshold
93
+ onDestroyTimeout: _v4.z.number().positive().default(5e3),
94
+ stateSaveInterval: _v4.z.number().positive().default(1e4),
95
+ actionTimeout: _v4.z.number().positive().default(6e4),
96
+ // Max time to wait for waitUntil background promises during shutdown
97
+ waitUntilTimeout: _v4.z.number().positive().default(15e3),
98
+ // Max time to wait for run handler to stop during shutdown
99
+ runStopTimeout: _v4.z.number().positive().default(15e3),
100
+ connectionLivenessTimeout: _v4.z.number().positive().default(2500),
101
+ connectionLivenessInterval: _v4.z.number().positive().default(5e3),
102
+ noSleep: _v4.z.boolean().default(false),
103
+ sleepTimeout: _v4.z.number().positive().default(3e4),
104
+ maxQueueSize: _v4.z.number().positive().default(1e3),
105
+ maxQueueMessageSize: _v4.z.number().positive().default(64 * 1024),
106
+ /**
107
+ * Can hibernate WebSockets for onWebSocket.
108
+ *
109
+ * WebSockets using actions/events are hibernatable by default.
110
+ *
111
+ * @experimental
112
+ **/
113
+ canHibernateWebSocket: _v4.z.union([
114
+ _v4.z.boolean(),
115
+ zFunction()
116
+ ]).default(false)
117
+ }).strict().prefault(() => ({}))
118
+ }).strict().refine(
119
+ (data) => !(data.state !== void 0 && data.createState !== void 0),
120
+ {
121
+ message: "Cannot define both 'state' and 'createState'",
122
+ path: ["state"]
123
+ }
124
+ ).refine(
125
+ (data) => !(data.connState !== void 0 && data.createConnState !== void 0),
126
+ {
127
+ message: "Cannot define both 'connState' and 'createConnState'",
128
+ path: ["connState"]
129
+ }
130
+ ).refine(
131
+ (data) => !(data.vars !== void 0 && data.createVars !== void 0),
132
+ {
133
+ message: "Cannot define both 'vars' and 'createVars'",
134
+ path: ["vars"]
135
+ }
136
+ );
137
+ var DocActorOptionsSchema = _v4.z.object({
138
+ name: _v4.z.string().optional().describe("Display name for the actor in the Inspector UI."),
139
+ icon: _v4.z.string().optional().describe(
140
+ "Icon for the actor in the Inspector UI. Can be an emoji (e.g., '\u{1F680}') or FontAwesome icon name (e.g., 'rocket')."
141
+ ),
142
+ createVarsTimeout: _v4.z.number().optional().describe("Timeout in ms for createVars handler. Default: 5000"),
143
+ createConnStateTimeout: _v4.z.number().optional().describe(
144
+ "Timeout in ms for createConnState handler. Default: 5000"
145
+ ),
146
+ onConnectTimeout: _v4.z.number().optional().describe("Timeout in ms for onConnect handler. Default: 5000"),
147
+ onSleepTimeout: _v4.z.number().optional().describe(
148
+ "Timeout in ms for onSleep handler. Must be less than ACTOR_STOP_THRESHOLD_MS. Default: 5000"
149
+ ),
150
+ onDestroyTimeout: _v4.z.number().optional().describe("Timeout in ms for onDestroy handler. Default: 5000"),
151
+ stateSaveInterval: _v4.z.number().optional().describe(
152
+ "Interval in ms between automatic state saves. Default: 10000"
153
+ ),
154
+ actionTimeout: _v4.z.number().optional().describe("Timeout in ms for action handlers. Default: 60000"),
155
+ waitUntilTimeout: _v4.z.number().optional().describe(
156
+ "Max time in ms to wait for waitUntil background promises during shutdown. Default: 15000"
157
+ ),
158
+ runStopTimeout: _v4.z.number().optional().describe(
159
+ "Max time in ms to wait for run handler to stop during shutdown. Default: 15000"
160
+ ),
161
+ connectionLivenessTimeout: _v4.z.number().optional().describe(
162
+ "Timeout in ms for connection liveness checks. Default: 2500"
163
+ ),
164
+ connectionLivenessInterval: _v4.z.number().optional().describe(
165
+ "Interval in ms between connection liveness checks. Default: 5000"
166
+ ),
167
+ noSleep: _v4.z.boolean().optional().describe("If true, the actor will never sleep. Default: false"),
168
+ sleepTimeout: _v4.z.number().optional().describe(
169
+ "Time in ms of inactivity before the actor sleeps. Default: 30000"
170
+ ),
171
+ maxQueueSize: _v4.z.number().optional().describe(
172
+ "Maximum number of queue messages before rejecting new messages. Default: 1000"
173
+ ),
174
+ maxQueueMessageSize: _v4.z.number().optional().describe(
175
+ "Maximum size of each queue message in bytes. Default: 65536"
176
+ ),
177
+ canHibernateWebSocket: _v4.z.boolean().optional().describe(
178
+ "Whether WebSockets using onWebSocket can be hibernated. WebSockets using actions/events are hibernatable by default. Default: false"
179
+ )
180
+ }).describe("Actor options for timeouts and behavior configuration.");
181
+ var DocActorConfigSchema = _v4.z.object({
182
+ state: _v4.z.unknown().optional().describe(
183
+ "Initial state value for the actor. Cannot be used with createState."
184
+ ),
185
+ createState: _v4.z.unknown().optional().describe(
186
+ "Function to create initial state. Receives context and input. Cannot be used with state."
187
+ ),
188
+ connState: _v4.z.unknown().optional().describe(
189
+ "Initial connection state value. Cannot be used with createConnState."
190
+ ),
191
+ createConnState: _v4.z.unknown().optional().describe(
192
+ "Function to create connection state. Receives context and connection params. Cannot be used with connState."
193
+ ),
194
+ vars: _v4.z.unknown().optional().describe(
195
+ "Initial ephemeral variables value. Cannot be used with createVars."
196
+ ),
197
+ createVars: _v4.z.unknown().optional().describe(
198
+ "Function to create ephemeral variables. Receives context and driver context. Cannot be used with vars."
199
+ ),
200
+ db: _v4.z.unknown().optional().describe("Database provider instance for the actor."),
201
+ onCreate: _v4.z.unknown().optional().describe(
202
+ "Called when the actor is first initialized. Use to initialize state."
203
+ ),
204
+ onDestroy: _v4.z.unknown().optional().describe("Called when the actor is destroyed."),
205
+ onWake: _v4.z.unknown().optional().describe(
206
+ "Called when the actor wakes up and is ready to receive connections and actions."
207
+ ),
208
+ onSleep: _v4.z.unknown().optional().describe(
209
+ "Called when the actor is stopping or sleeping. Use to clean up resources."
210
+ ),
211
+ run: _v4.z.unknown().optional().describe(
212
+ "Called after actor starts. Does not block startup. Use for background tasks like queue processing or tick loops. If it exits or throws, the actor crashes."
213
+ ),
214
+ onStateChange: _v4.z.unknown().optional().describe(
215
+ "Called when the actor's state changes. State changes within this hook won't trigger recursion."
216
+ ),
217
+ onBeforeConnect: _v4.z.unknown().optional().describe(
218
+ "Called before a client connects. Throw an error to reject the connection."
219
+ ),
220
+ onConnect: _v4.z.unknown().optional().describe("Called when a client successfully connects."),
221
+ onDisconnect: _v4.z.unknown().optional().describe("Called when a client disconnects."),
222
+ onBeforeActionResponse: _v4.z.unknown().optional().describe(
223
+ "Called before sending an action response. Use to transform output."
224
+ ),
225
+ onRequest: _v4.z.unknown().optional().describe(
226
+ "Called for raw HTTP requests to /actors/{name}/http/* endpoints."
227
+ ),
228
+ onWebSocket: _v4.z.unknown().optional().describe(
229
+ "Called for raw WebSocket connections to /actors/{name}/websocket/* endpoints."
230
+ ),
231
+ actions: _v4.z.record(_v4.z.string(), _v4.z.unknown()).optional().describe(
232
+ "Map of action name to handler function. Defaults to an empty object."
233
+ ),
234
+ events: _v4.z.record(_v4.z.string(), _v4.z.unknown()).optional().describe("Map of event names to schemas."),
235
+ queues: _v4.z.record(_v4.z.string(), _v4.z.unknown()).optional().describe("Map of queue names to schemas."),
236
+ options: DocActorOptionsSchema.optional()
237
+ }).describe("Actor configuration passed to the actor() function.");
238
+
239
+ // src/actor/instance/keys.ts
240
+ var KEYS = {
241
+ PERSIST_DATA: Uint8Array.from([1]),
242
+ CONN_PREFIX: Uint8Array.from([2]),
243
+ // Prefix for connection keys
244
+ INSPECTOR_TOKEN: Uint8Array.from([3]),
245
+ // Inspector token key
246
+ KV: Uint8Array.from([4]),
247
+ // Prefix for user-facing KV storage
248
+ QUEUE_PREFIX: Uint8Array.from([5]),
249
+ // Prefix for queue storage
250
+ WORKFLOW_PREFIX: Uint8Array.from([6]),
251
+ // Prefix for workflow storage
252
+ TRACES_PREFIX: Uint8Array.from([7]),
253
+ // Prefix for traces storage
254
+ SQLITE_PREFIX: Uint8Array.from([8])
255
+ // Prefix for SQLite VFS data
256
+ };
257
+ var STORAGE_VERSION = {
258
+ QUEUE: 1,
259
+ WORKFLOW: 1,
260
+ TRACES: 1,
261
+ SQLITE: 1
262
+ };
263
+ var STORAGE_VERSION_BYTES = {
264
+ QUEUE: Uint8Array.from([STORAGE_VERSION.QUEUE]),
265
+ WORKFLOW: Uint8Array.from([STORAGE_VERSION.WORKFLOW]),
266
+ TRACES: Uint8Array.from([STORAGE_VERSION.TRACES]),
267
+ SQLITE: Uint8Array.from([STORAGE_VERSION.SQLITE])
268
+ };
269
+ var QUEUE_NAMESPACE = {
270
+ METADATA: Uint8Array.from([1]),
271
+ MESSAGES: Uint8Array.from([2])
272
+ };
273
+ var QUEUE_ID_BYTES = 8;
274
+ function concatPrefix(prefix, suffix) {
275
+ const merged = new Uint8Array(prefix.length + suffix.length);
276
+ merged.set(prefix, 0);
277
+ merged.set(suffix, prefix.length);
278
+ return merged;
279
+ }
280
+ var QUEUE_STORAGE_PREFIX = concatPrefix(
281
+ KEYS.QUEUE_PREFIX,
282
+ STORAGE_VERSION_BYTES.QUEUE
283
+ );
284
+ var QUEUE_METADATA_KEY = concatPrefix(
285
+ QUEUE_STORAGE_PREFIX,
286
+ QUEUE_NAMESPACE.METADATA
287
+ );
288
+ var QUEUE_MESSAGES_PREFIX = concatPrefix(
289
+ QUEUE_STORAGE_PREFIX,
290
+ QUEUE_NAMESPACE.MESSAGES
291
+ );
292
+ var WORKFLOW_STORAGE_PREFIX = concatPrefix(
293
+ KEYS.WORKFLOW_PREFIX,
294
+ STORAGE_VERSION_BYTES.WORKFLOW
295
+ );
296
+ var TRACES_STORAGE_PREFIX = concatPrefix(
297
+ KEYS.TRACES_PREFIX,
298
+ STORAGE_VERSION_BYTES.TRACES
299
+ );
300
+ var SQLITE_STORAGE_PREFIX = concatPrefix(
301
+ KEYS.SQLITE_PREFIX,
302
+ STORAGE_VERSION_BYTES.SQLITE
303
+ );
304
+ function makePrefixedKey(key) {
305
+ const prefixed = new Uint8Array(KEYS.KV.length + key.length);
306
+ prefixed.set(KEYS.KV, 0);
307
+ prefixed.set(key, KEYS.KV.length);
308
+ return prefixed;
309
+ }
310
+ function removePrefixFromKey(prefixedKey) {
311
+ return prefixedKey.slice(KEYS.KV.length);
312
+ }
313
+ function makeWorkflowKey(key) {
314
+ return concatPrefix(WORKFLOW_STORAGE_PREFIX, key);
315
+ }
316
+ function workflowStoragePrefix() {
317
+ return Uint8Array.from(WORKFLOW_STORAGE_PREFIX);
318
+ }
319
+ function tracesStoragePrefix() {
320
+ return Uint8Array.from(TRACES_STORAGE_PREFIX);
321
+ }
322
+ function queueMetadataKey() {
323
+ return Uint8Array.from(QUEUE_METADATA_KEY);
324
+ }
325
+ function queueMessagesPrefix() {
326
+ return Uint8Array.from(QUEUE_MESSAGES_PREFIX);
327
+ }
328
+ function makeConnKey(connId) {
329
+ const encoder = new TextEncoder();
330
+ const connIdBytes = encoder.encode(connId);
331
+ const key = new Uint8Array(KEYS.CONN_PREFIX.length + connIdBytes.length);
332
+ key.set(KEYS.CONN_PREFIX, 0);
333
+ key.set(connIdBytes, KEYS.CONN_PREFIX.length);
334
+ return key;
335
+ }
336
+ function makeQueueMessageKey(id) {
337
+ const key = new Uint8Array(QUEUE_MESSAGES_PREFIX.length + QUEUE_ID_BYTES);
338
+ key.set(QUEUE_MESSAGES_PREFIX, 0);
339
+ const view = new DataView(key.buffer, key.byteOffset, key.byteLength);
340
+ view.setBigUint64(QUEUE_MESSAGES_PREFIX.length, id, false);
341
+ return key;
342
+ }
343
+ function decodeQueueMessageKey(key) {
344
+ const offset = QUEUE_MESSAGES_PREFIX.length;
345
+ if (key.length < offset + QUEUE_ID_BYTES) {
346
+ throw new Error("Queue key is too short");
347
+ }
348
+ for (let i = 0; i < QUEUE_MESSAGES_PREFIX.length; i++) {
349
+ if (key[i] !== QUEUE_MESSAGES_PREFIX[i]) {
350
+ throw new Error("Queue key has invalid prefix");
351
+ }
352
+ }
353
+ const view = new DataView(
354
+ key.buffer,
355
+ key.byteOffset + offset,
356
+ QUEUE_ID_BYTES
357
+ );
358
+ return view.getBigUint64(0, false);
359
+ }
360
+
361
+ // src/actor/instance/kv.ts
362
+ var textEncoder = new TextEncoder();
363
+ var textDecoder = new TextDecoder();
364
+ function encodeKey(key, keyType) {
365
+ if (key instanceof Uint8Array) {
366
+ return key;
367
+ }
368
+ const resolvedKeyType = _nullishCoalesce(keyType, () => ( "text"));
369
+ if (resolvedKeyType === "binary") {
370
+ throw new TypeError("Expected a Uint8Array when keyType is binary");
371
+ }
372
+ return textEncoder.encode(key);
373
+ }
374
+ function decodeKey(key, keyType) {
375
+ const resolvedKeyType = _nullishCoalesce(keyType, () => ( "text"));
376
+ switch (resolvedKeyType) {
377
+ case "text":
378
+ return textDecoder.decode(key);
379
+ case "binary":
380
+ return key;
381
+ default:
382
+ throw new TypeError("Invalid kv key type");
383
+ }
384
+ }
385
+ function resolveValueType(value) {
386
+ if (typeof value === "string") {
387
+ return "text";
388
+ }
389
+ if (value instanceof Uint8Array) {
390
+ return "binary";
391
+ }
392
+ if (value instanceof ArrayBuffer) {
393
+ return "arrayBuffer";
394
+ }
395
+ throw new TypeError("Invalid kv value");
396
+ }
397
+ function encodeValue(value, options) {
398
+ const type = _nullishCoalesce((options == null ? void 0 : options.type), () => ( resolveValueType(value)));
399
+ switch (type) {
400
+ case "text":
401
+ if (typeof value !== "string") {
402
+ throw new TypeError("Expected a string when type is text");
403
+ }
404
+ return textEncoder.encode(value);
405
+ case "arrayBuffer":
406
+ if (!(value instanceof ArrayBuffer)) {
407
+ throw new TypeError("Expected an ArrayBuffer when type is arrayBuffer");
408
+ }
409
+ return new Uint8Array(value);
410
+ case "binary":
411
+ if (!(value instanceof Uint8Array)) {
412
+ throw new TypeError("Expected a Uint8Array when type is binary");
413
+ }
414
+ return value;
415
+ default:
416
+ throw new TypeError("Invalid kv value type");
417
+ }
418
+ }
419
+ function decodeValue(value, options) {
420
+ const type = _nullishCoalesce((options == null ? void 0 : options.type), () => ( "text"));
421
+ switch (type) {
422
+ case "text":
423
+ return textDecoder.decode(value);
424
+ case "arrayBuffer": {
425
+ const copy = new Uint8Array(value.byteLength);
426
+ copy.set(value);
427
+ return copy.buffer;
428
+ }
429
+ case "binary":
430
+ return value;
431
+ default:
432
+ throw new TypeError("Invalid kv value type");
433
+ }
434
+ }
435
+ var ActorKv = class {
436
+ #driver;
437
+ #actorId;
438
+ constructor(driver, actorId) {
439
+ this.#driver = driver;
440
+ this.#actorId = actorId;
441
+ }
442
+ /**
443
+ * Get a single value by key.
444
+ */
445
+ async get(key, options) {
446
+ const results = await this.#driver.kvBatchGet(this.#actorId, [
447
+ makePrefixedKey(encodeKey(key))
448
+ ]);
449
+ const result = results[0];
450
+ if (!result) {
451
+ return null;
452
+ }
453
+ return decodeValue(result, options);
454
+ }
455
+ /**
456
+ * Get multiple values by keys.
457
+ */
458
+ async getBatch(keys, options) {
459
+ const prefixedKeys = keys.map(
460
+ (key) => makePrefixedKey(encodeKey(key))
461
+ );
462
+ const results = await this.#driver.kvBatchGet(
463
+ this.#actorId,
464
+ prefixedKeys
465
+ );
466
+ return results.map(
467
+ (result) => result ? decodeValue(result, options) : null
468
+ );
469
+ }
470
+ /**
471
+ * Put a single key-value pair.
472
+ */
473
+ async put(key, value, options) {
474
+ await this.#driver.kvBatchPut(this.#actorId, [
475
+ [makePrefixedKey(encodeKey(key)), encodeValue(value, options)]
476
+ ]);
477
+ }
478
+ /**
479
+ * Put multiple key-value pairs.
480
+ */
481
+ async putBatch(entries, options) {
482
+ const prefixedEntries = entries.map(
483
+ ([key, value]) => [
484
+ makePrefixedKey(encodeKey(key)),
485
+ encodeValue(value, options)
486
+ ]
487
+ );
488
+ await this.#driver.kvBatchPut(this.#actorId, prefixedEntries);
489
+ }
490
+ /**
491
+ * Delete a single key.
492
+ */
493
+ async delete(key) {
494
+ await this.#driver.kvBatchDelete(this.#actorId, [
495
+ makePrefixedKey(encodeKey(key))
496
+ ]);
497
+ }
498
+ /**
499
+ * Delete multiple keys.
500
+ */
501
+ async deleteBatch(keys) {
502
+ const prefixedKeys = keys.map(
503
+ (key) => makePrefixedKey(encodeKey(key))
504
+ );
505
+ await this.#driver.kvBatchDelete(this.#actorId, prefixedKeys);
506
+ }
507
+ /**
508
+ * List all keys with a given prefix.
509
+ * Returns key-value pairs where keys have the user prefix removed.
510
+ */
511
+ async list(prefix, options) {
512
+ const prefixedPrefix = makePrefixedKey(
513
+ encodeKey(prefix, options == null ? void 0 : options.keyType)
514
+ );
515
+ const results = await this.#driver.kvListPrefix(
516
+ this.#actorId,
517
+ prefixedPrefix
518
+ );
519
+ return results.map(([key, value]) => [
520
+ decodeKey(removePrefixFromKey(key), options == null ? void 0 : options.keyType),
521
+ decodeValue(value, options)
522
+ ]);
523
+ }
524
+ };
525
+
526
+ // src/actor/log.ts
527
+ function loggerWithoutContext() {
528
+ return _chunkPQZHDKRWcjs.getLogger.call(void 0, "actor-runtime");
529
+ }
530
+
531
+ // src/actor/utils.ts
532
+ function assertUnreachable(x) {
533
+ loggerWithoutContext().error({
534
+ msg: "unreachable",
535
+ value: `${x}`,
536
+ stack: new Error().stack
537
+ });
538
+ throw new (0, _chunkL47L3ZWJcjs.Unreachable)(x);
539
+ }
540
+ var DeadlineError = class extends Error {
541
+ constructor() {
542
+ super("Promise did not complete before deadline.");
543
+ }
544
+ };
545
+ function deadline(promise, timeout) {
546
+ const controller = new AbortController();
547
+ const signal = controller.signal;
548
+ const timeoutId = setTimeout(() => controller.abort(), timeout);
549
+ return Promise.race([
550
+ promise,
551
+ new Promise((_, reject) => {
552
+ signal.addEventListener("abort", () => reject(new DeadlineError()));
553
+ })
554
+ ]).finally(() => {
555
+ clearTimeout(timeoutId);
556
+ });
557
+ }
558
+ function joinAbortSignals(...signals) {
559
+ const activeSignals = signals.filter(
560
+ (signal) => signal !== void 0
561
+ );
562
+ if (activeSignals.length === 0) {
563
+ return { signal: void 0, cleanup: () => {
564
+ } };
565
+ }
566
+ if (activeSignals.length === 1) {
567
+ return { signal: activeSignals[0], cleanup: () => {
568
+ } };
569
+ }
570
+ const controller = new AbortController();
571
+ if (activeSignals.some((signal) => signal.aborted)) {
572
+ controller.abort();
573
+ return { signal: controller.signal, cleanup: () => {
574
+ } };
575
+ }
576
+ const cleanup = () => {
577
+ for (const signal of activeSignals) {
578
+ signal.removeEventListener("abort", onAbort);
579
+ }
580
+ };
581
+ const onAbort = () => {
582
+ controller.abort();
583
+ cleanup();
584
+ };
585
+ for (const signal of activeSignals) {
586
+ signal.addEventListener("abort", onAbort, { once: true });
587
+ }
588
+ return { signal: controller.signal, cleanup };
589
+ }
590
+ function generateSecureToken(length = 32) {
591
+ const array = new Uint8Array(length);
592
+ crypto.getRandomValues(array);
593
+ return btoa(String.fromCharCode(...array)).replace(/\+/g, "-").replace(/\//g, "_").replace(/=/g, "");
594
+ }
595
+ function isStatePath(path) {
596
+ return path === "state" || path.startsWith("state.");
597
+ }
598
+ function isConnStatePath(path) {
599
+ if (!path.startsWith("connections.")) {
600
+ return false;
601
+ }
602
+ const stateIndex = path.indexOf(".state", 12);
603
+ if (stateIndex === -1) {
604
+ return false;
605
+ }
606
+ const afterState = stateIndex + 6;
607
+ return path.length === afterState || path[afterState] === ".";
608
+ }
609
+
610
+ // src/actor/instance/queue.ts
611
+ var ActorQueue = class {
612
+ #queueManager;
613
+ #abortSignal;
614
+ #pendingCompletableMessageIds = /* @__PURE__ */ new Set();
615
+ constructor(queueManager, abortSignal) {
616
+ this.#queueManager = queueManager;
617
+ this.#abortSignal = abortSignal;
618
+ }
619
+ async next(opts) {
620
+ const resolvedOpts = _nullishCoalesce(opts, () => ( {}));
621
+ const messages = await this.nextBatch({
622
+ ...resolvedOpts,
623
+ count: 1
624
+ });
625
+ return messages[0];
626
+ }
627
+ async nextBatch(opts) {
628
+ const resolvedOpts = _nullishCoalesce(opts, () => ( {}));
629
+ const completable = resolvedOpts.completable === true;
630
+ if (this.#pendingCompletableMessageIds.size > 0) {
631
+ throw new (0, _chunkL47L3ZWJcjs.QueuePreviousMessageNotCompleted)();
632
+ }
633
+ const names = this.#normalizeNames(resolvedOpts.names);
634
+ const count = Math.max(1, _nullishCoalesce(resolvedOpts.count, () => ( 1)));
635
+ const { signal, cleanup } = joinAbortSignals(
636
+ this.#abortSignal,
637
+ resolvedOpts.signal
638
+ );
639
+ const messages = await this.#queueManager.receive(
640
+ names,
641
+ count,
642
+ resolvedOpts.timeout,
643
+ signal,
644
+ completable
645
+ ).finally(cleanup);
646
+ if (!completable) {
647
+ return messages;
648
+ }
649
+ return messages.map((message) => this.#makeCompletableMessage(message));
650
+ }
651
+ async tryNext(opts) {
652
+ const resolvedOpts = _nullishCoalesce(opts, () => ( {}));
653
+ const messages = await this.tryNextBatch({
654
+ ...resolvedOpts,
655
+ count: 1
656
+ });
657
+ return messages[0];
658
+ }
659
+ async tryNextBatch(opts) {
660
+ const resolvedOpts = _nullishCoalesce(opts, () => ( {}));
661
+ if (resolvedOpts.completable === true) {
662
+ return await this.nextBatch({
663
+ names: resolvedOpts.names,
664
+ count: resolvedOpts.count,
665
+ timeout: 0,
666
+ completable: true
667
+ });
668
+ }
669
+ return await this.nextBatch({
670
+ names: resolvedOpts.names,
671
+ count: resolvedOpts.count,
672
+ timeout: 0
673
+ });
674
+ }
675
+ async *iter(opts) {
676
+ const resolvedOpts = _nullishCoalesce(opts, () => ( {}));
677
+ while (!this.#abortSignal.aborted) {
678
+ try {
679
+ const message = resolvedOpts.completable === true ? await this.next({
680
+ names: resolvedOpts.names,
681
+ signal: resolvedOpts.signal,
682
+ completable: true
683
+ }) : await this.next({
684
+ names: resolvedOpts.names,
685
+ signal: resolvedOpts.signal
686
+ });
687
+ if (!message) {
688
+ continue;
689
+ }
690
+ yield message;
691
+ } catch (error) {
692
+ if (error instanceof _chunkL47L3ZWJcjs.ActorAborted) {
693
+ return;
694
+ }
695
+ throw error;
696
+ }
697
+ }
698
+ }
699
+ async send(name, body) {
700
+ return await this.#queueManager.enqueue(name, body);
701
+ }
702
+ #normalizeNames(names) {
703
+ if (!names || names.length === 0) {
704
+ return void 0;
705
+ }
706
+ return [...new Set(names)];
707
+ }
708
+ #makeCompletableMessage(message) {
709
+ const messageId = message.id.toString();
710
+ this.#pendingCompletableMessageIds.add(messageId);
711
+ let completed = false;
712
+ const completableMessage = {
713
+ ...message,
714
+ complete: async (response) => {
715
+ if (completed) {
716
+ throw new (0, _chunkL47L3ZWJcjs.QueueAlreadyCompleted)();
717
+ }
718
+ completed = true;
719
+ try {
720
+ await this.#queueManager.completeMessage(message, response);
721
+ this.#pendingCompletableMessageIds.delete(messageId);
722
+ } catch (error) {
723
+ completed = false;
724
+ throw error;
725
+ }
726
+ }
727
+ };
728
+ return completableMessage;
729
+ }
730
+ };
731
+
732
+ // src/actor/schema.ts
733
+ function event(options) {
734
+ return _nullishCoalesce(options, () => ( {}));
735
+ }
736
+ function queue(options) {
737
+ return _nullishCoalesce(options, () => ( {}));
738
+ }
739
+ function isStandardSchema(value) {
740
+ return typeof value === "object" && value !== null && "~standard" in value;
741
+ }
742
+ function isQueueSchemaDefinition(value) {
743
+ if (isEventSchemaDefinition(value)) {
744
+ return false;
745
+ }
746
+ return typeof value === "object" && value !== null && "message" in value && value.message !== void 0;
747
+ }
748
+ function isEventSchemaDefinition(value) {
749
+ return typeof value === "object" && value !== null && "schema" in value && value.schema !== void 0;
750
+ }
751
+ function hasSchemaConfigKey(schemas, key) {
752
+ if (!schemas) {
753
+ return false;
754
+ }
755
+ return Object.prototype.hasOwnProperty.call(schemas, key);
756
+ }
757
+ function getEventCanSubscribe(schemas, key) {
758
+ const schema = schemas == null ? void 0 : schemas[key];
759
+ if (!schema || isStandardSchema(schema)) {
760
+ return void 0;
761
+ }
762
+ const maybeCanSubscribe = schema.canSubscribe;
763
+ return typeof maybeCanSubscribe === "function" ? maybeCanSubscribe : void 0;
764
+ }
765
+ function getQueueCanPublish(schemas, key) {
766
+ const schema = schemas == null ? void 0 : schemas[key];
767
+ if (!schema || isStandardSchema(schema)) {
768
+ return void 0;
769
+ }
770
+ const maybeCanPublish = schema.canPublish;
771
+ return typeof maybeCanPublish === "function" ? maybeCanPublish : void 0;
772
+ }
773
+ function getValidationSchema(schema) {
774
+ if (!schema) {
775
+ return void 0;
776
+ }
777
+ if (isEventSchemaDefinition(schema)) {
778
+ return schema.schema;
779
+ }
780
+ if (isQueueSchemaDefinition(schema)) {
781
+ return schema.message;
782
+ }
783
+ if (typeof schema === "object" && schema !== null && "schema" in schema && schema.schema !== void 0) {
784
+ return schema.schema;
785
+ }
786
+ if (typeof schema === "object" && schema !== null && "message" in schema && schema.message !== void 0) {
787
+ return schema.message;
788
+ }
789
+ return schema;
790
+ }
791
+ function isPromiseLike(value) {
792
+ return typeof value === "object" && value !== null && "then" in value && typeof value.then === "function";
793
+ }
794
+ function validateSchemaSync(schemas, key, data) {
795
+ const schema = getValidationSchema(schemas == null ? void 0 : schemas[key]);
796
+ if (!schema) {
797
+ return { success: true, data };
798
+ }
799
+ if (isStandardSchema(schema)) {
800
+ const result = schema["~standard"].validate(data);
801
+ if (isPromiseLike(result)) {
802
+ throw new (0, _chunkL47L3ZWJcjs.Unsupported)("async schema validation");
803
+ }
804
+ if (result.issues) {
805
+ return { success: false, issues: [...result.issues] };
806
+ }
807
+ return {
808
+ success: true,
809
+ data: result.value
810
+ };
811
+ }
812
+ return { success: true, data };
813
+ }
814
+
815
+ // src/actor/contexts/base/actor.ts
816
+ var ACTOR_CONTEXT_INTERNAL_SYMBOL = /* @__PURE__ */ Symbol.for(
817
+ "rivetkit.actorContextInternal"
818
+ );
819
+ var ActorContext = class {
820
+
821
+ #actor;
822
+ #kv;
823
+ #queue;
824
+ constructor(actor) {
825
+ this.#actor = actor;
826
+ this[ACTOR_CONTEXT_INTERNAL_SYMBOL] = actor;
827
+ }
828
+ /**
829
+ * Gets the KV storage interface.
830
+ */
831
+ get kv() {
832
+ if (!this.#kv) {
833
+ this.#kv = new ActorKv(this.#actor.driver, this.#actor.id);
834
+ }
835
+ return this.#kv;
836
+ }
837
+ /**
838
+ * Get the actor state
839
+ *
840
+ * @remarks
841
+ * This property is not available in `createState` since the state hasn't been created yet.
842
+ */
843
+ get state() {
844
+ return this.#actor.state;
845
+ }
846
+ /**
847
+ * Get the actor variables
848
+ *
849
+ * @remarks
850
+ * This property is not available in `createVars` since the variables haven't been created yet.
851
+ * Variables are only available if you define `vars` or `createVars` in your actor config.
852
+ */
853
+ get vars() {
854
+ return this.#actor.vars;
855
+ }
856
+ broadcast(name, ...args) {
857
+ if (this.#actor.config.events !== void 0 && !hasSchemaConfigKey(this.#actor.config.events, name)) {
858
+ this.#actor.rLog.warn({
859
+ msg: "broadcasting event not defined in actor events config",
860
+ eventName: name
861
+ });
862
+ }
863
+ const payload = args.length === 1 ? args[0] : args;
864
+ const result = validateSchemaSync(
865
+ this.#actor.config.events,
866
+ name,
867
+ payload
868
+ );
869
+ if (!result.success) {
870
+ throw new (0, _chunkL47L3ZWJcjs.EventPayloadInvalid)(name, result.issues);
871
+ }
872
+ if (args.length === 1) {
873
+ this.#actor.eventManager.broadcast(name, result.data);
874
+ return;
875
+ }
876
+ if (Array.isArray(result.data)) {
877
+ this.#actor.eventManager.broadcast(
878
+ name,
879
+ ...result.data
880
+ );
881
+ return;
882
+ }
883
+ this.#actor.eventManager.broadcast(name, ...args);
884
+ }
885
+ /**
886
+ * Gets the logger instance.
887
+ */
888
+ get log() {
889
+ return this.#actor.log;
890
+ }
891
+ /**
892
+ * Access to queue receive helpers.
893
+ */
894
+ get queue() {
895
+ if (!this.#queue) {
896
+ this.#queue = exports.queue = new ActorQueue(
897
+ this.#actor.queueManager,
898
+ this.#actor.abortSignal
899
+ );
900
+ }
901
+ return this.#queue;
902
+ }
903
+ /**
904
+ * Gets actor ID.
905
+ */
906
+ get actorId() {
907
+ return this.#actor.id;
908
+ }
909
+ /**
910
+ * Gets the actor name.
911
+ */
912
+ get name() {
913
+ return this.#actor.name;
914
+ }
915
+ /**
916
+ * Gets the actor key.
917
+ */
918
+ get key() {
919
+ return this.#actor.key;
920
+ }
921
+ /**
922
+ * Gets the region.
923
+ */
924
+ get region() {
925
+ return this.#actor.region;
926
+ }
927
+ /**
928
+ * Gets the scheduler.
929
+ */
930
+ get schedule() {
931
+ return this.#actor.schedule;
932
+ }
933
+ /**
934
+ * Gets the map of connections.
935
+ */
936
+ get conns() {
937
+ return this.#actor.conns;
938
+ }
939
+ /**
940
+ * Returns the client for the given registry.
941
+ */
942
+ client() {
943
+ return this.#actor.inlineClient;
944
+ }
945
+ /**
946
+ * Gets the database.
947
+ *
948
+ * @experimental
949
+ * @remarks
950
+ * This property is only available if you define a `db` provider in your actor config.
951
+ * @throws {DatabaseNotEnabled} If the database is not enabled.
952
+ */
953
+ get db() {
954
+ return this.#actor.db;
955
+ }
956
+ /**
957
+ * Forces the state to get saved.
958
+ *
959
+ * @param opts - Options for saving the state.
960
+ */
961
+ async saveState(opts) {
962
+ return this.#actor.stateManager.saveState(opts);
963
+ }
964
+ /**
965
+ * Prevents the actor from sleeping until promise is complete.
966
+ */
967
+ waitUntil(promise) {
968
+ this.#actor.waitUntil(promise);
969
+ }
970
+ /**
971
+ * Prevents the actor from sleeping while the given promise is running.
972
+ *
973
+ * Use this when performing async operations in the `run` handler or other
974
+ * background contexts where you need to ensure the actor stays awake.
975
+ *
976
+ * Returns the resolved value and resets the sleep timer on completion.
977
+ * Errors are propagated to the caller.
978
+ */
979
+ keepAwake(promise) {
980
+ return this.#actor.keepAwake(promise);
981
+ }
982
+ /**
983
+ * AbortSignal that fires when the actor is stopping.
984
+ */
985
+ get abortSignal() {
986
+ return this.#actor.abortSignal;
987
+ }
988
+ /**
989
+ * True when the actor is stopping.
990
+ *
991
+ * Alias for `c.abortSignal.aborted`.
992
+ */
993
+ get aborted() {
994
+ return this.#actor.abortSignal.aborted;
995
+ }
996
+ /**
997
+ * Forces the actor to sleep.
998
+ *
999
+ * Not supported on all drivers.
1000
+ *
1001
+ * @experimental
1002
+ */
1003
+ sleep() {
1004
+ this.#actor.startSleep();
1005
+ }
1006
+ /**
1007
+ * Forces the actor to destroy.
1008
+ *
1009
+ * This will return immediately, then call `onStop` and `onDestroy`.
1010
+ *
1011
+ * @experimental
1012
+ */
1013
+ destroy() {
1014
+ this.#actor.startDestroy();
1015
+ }
1016
+ };
1017
+
1018
+
1019
+
1020
+
1021
+
1022
+
1023
+
1024
+
1025
+
1026
+
1027
+
1028
+
1029
+
1030
+
1031
+
1032
+
1033
+
1034
+
1035
+
1036
+
1037
+
1038
+
1039
+
1040
+
1041
+
1042
+
1043
+
1044
+
1045
+
1046
+
1047
+
1048
+
1049
+ exports.RUN_FUNCTION_CONFIG_SYMBOL = RUN_FUNCTION_CONFIG_SYMBOL; exports.getRunFunction = getRunFunction; exports.getRunMetadata = getRunMetadata; exports.getRunInspectorConfig = getRunInspectorConfig; exports.ActorConfigSchema = ActorConfigSchema; exports.loggerWithoutContext = loggerWithoutContext; exports.assertUnreachable = assertUnreachable; exports.DeadlineError = DeadlineError; exports.deadline = deadline; exports.generateSecureToken = generateSecureToken; exports.isStatePath = isStatePath; exports.isConnStatePath = isConnStatePath; exports.event = event; exports.queue = queue; exports.hasSchemaConfigKey = hasSchemaConfigKey; exports.getEventCanSubscribe = getEventCanSubscribe; exports.getQueueCanPublish = getQueueCanPublish; exports.validateSchemaSync = validateSchemaSync; exports.KEYS = KEYS; exports.makeWorkflowKey = makeWorkflowKey; exports.workflowStoragePrefix = workflowStoragePrefix; exports.tracesStoragePrefix = tracesStoragePrefix; exports.queueMetadataKey = queueMetadataKey; exports.queueMessagesPrefix = queueMessagesPrefix; exports.makeConnKey = makeConnKey; exports.makeQueueMessageKey = makeQueueMessageKey; exports.decodeQueueMessageKey = decodeQueueMessageKey; exports.ActorKv = ActorKv; exports.ACTOR_CONTEXT_INTERNAL_SYMBOL = ACTOR_CONTEXT_INTERNAL_SYMBOL; exports.ActorContext = ActorContext;
1050
+ //# sourceMappingURL=chunk-PVOE6BU7.cjs.map