rivetkit 2.0.42 → 2.1.0-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 (322) hide show
  1. package/dist/{tsup/config-CLnylLYY.d.ts → browser/client.d.ts} +2127 -1910
  2. package/dist/browser/client.js +5182 -0
  3. package/dist/browser/client.js.map +1 -0
  4. package/dist/browser/inspector/client.d.ts +130 -0
  5. package/dist/browser/inspector/client.js +2854 -0
  6. package/dist/browser/inspector/client.js.map +1 -0
  7. package/dist/browser/v3-DnYObHH3.d.ts +279 -0
  8. package/dist/schemas/actor-inspector/v2.ts +796 -0
  9. package/dist/schemas/actor-inspector/v3.ts +899 -0
  10. package/dist/schemas/actor-persist/v4.ts +406 -0
  11. package/dist/schemas/client-protocol/v3.ts +554 -0
  12. package/dist/schemas/persist/v1.ts +781 -0
  13. package/dist/schemas/transport/v1.ts +697 -0
  14. package/dist/tsup/actor/errors.cjs +27 -3
  15. package/dist/tsup/actor/errors.cjs.map +1 -1
  16. package/dist/tsup/actor/errors.d.cts +37 -1
  17. package/dist/tsup/actor/errors.d.ts +37 -1
  18. package/dist/tsup/actor/errors.js +26 -1
  19. package/dist/tsup/{actor-router-consts-DzI2szci.d.cts → actor-router-consts-D29T1Z-K.d.cts} +1 -1
  20. package/dist/tsup/{actor-router-consts-DzI2szci.d.ts → actor-router-consts-D29T1Z-K.d.ts} +1 -1
  21. package/dist/tsup/chunk-424PT5DM.js +23 -0
  22. package/dist/tsup/chunk-424PT5DM.js.map +1 -0
  23. package/dist/tsup/{chunk-JDAD2YFA.js → chunk-5ESWDTHJ.js} +148 -273
  24. package/dist/tsup/chunk-5ESWDTHJ.js.map +1 -0
  25. package/dist/tsup/{chunk-FJ3KTN4V.js → chunk-6LIBPELE.js} +119 -11
  26. package/dist/tsup/chunk-6LIBPELE.js.map +1 -0
  27. package/dist/tsup/chunk-6LJAZ5R4.cjs +96 -0
  28. package/dist/tsup/chunk-6LJAZ5R4.cjs.map +1 -0
  29. package/dist/tsup/{chunk-LFVF5SCU.js → chunk-7HTNH26M.js} +126 -1
  30. package/dist/tsup/chunk-7HTNH26M.js.map +1 -0
  31. package/dist/tsup/chunk-7K4CYDGD.js +630 -0
  32. package/dist/tsup/chunk-7K4CYDGD.js.map +1 -0
  33. package/dist/tsup/{chunk-XXGJCOL6.js → chunk-A6YIZWTK.js} +2 -2
  34. package/dist/tsup/chunk-AIYEYMX5.cjs +630 -0
  35. package/dist/tsup/chunk-AIYEYMX5.cjs.map +1 -0
  36. package/dist/tsup/{chunk-Q6W7RJJP.js → chunk-DIGBC2VI.js} +211 -2316
  37. package/dist/tsup/chunk-DIGBC2VI.js.map +1 -0
  38. package/dist/tsup/{chunk-RZW2DNND.cjs → chunk-F6JYU5IK.cjs} +1957 -1039
  39. package/dist/tsup/chunk-F6JYU5IK.cjs.map +1 -0
  40. package/dist/tsup/chunk-HAZL2EPK.cjs +534 -0
  41. package/dist/tsup/chunk-HAZL2EPK.cjs.map +1 -0
  42. package/dist/tsup/chunk-HDQ2JUQT.cjs +23 -0
  43. package/dist/tsup/chunk-HDQ2JUQT.cjs.map +1 -0
  44. package/dist/tsup/chunk-HIDX4C5Y.cjs +1036 -0
  45. package/dist/tsup/chunk-HIDX4C5Y.cjs.map +1 -0
  46. package/dist/tsup/chunk-IVG73YCW.js +534 -0
  47. package/dist/tsup/chunk-IVG73YCW.js.map +1 -0
  48. package/dist/tsup/chunk-KJSYAUOM.js +96 -0
  49. package/dist/tsup/chunk-KJSYAUOM.js.map +1 -0
  50. package/dist/tsup/{chunk-2XQS746M.cjs → chunk-L47L3ZWJ.cjs} +127 -2
  51. package/dist/tsup/chunk-L47L3ZWJ.cjs.map +1 -0
  52. package/dist/tsup/{chunk-H4TB4X25.cjs → chunk-LW6KLR7A.cjs} +126 -18
  53. package/dist/tsup/chunk-LW6KLR7A.cjs.map +1 -0
  54. package/dist/tsup/chunk-LXUQ667X.js +2006 -0
  55. package/dist/tsup/chunk-LXUQ667X.js.map +1 -0
  56. package/dist/tsup/{chunk-GMAVRZSF.js → chunk-M2T62AZQ.js} +1790 -872
  57. package/dist/tsup/chunk-M2T62AZQ.js.map +1 -0
  58. package/dist/tsup/chunk-MZ37VV3P.js +5974 -0
  59. package/dist/tsup/chunk-MZ37VV3P.js.map +1 -0
  60. package/dist/tsup/chunk-N4KRDJ56.js +72 -0
  61. package/dist/tsup/chunk-N4KRDJ56.js.map +1 -0
  62. package/dist/tsup/chunk-NIYZDWMW.cjs +2006 -0
  63. package/dist/tsup/chunk-NIYZDWMW.cjs.map +1 -0
  64. package/dist/tsup/chunk-OMEPCQK2.js +649 -0
  65. package/dist/tsup/chunk-OMEPCQK2.js.map +1 -0
  66. package/dist/tsup/chunk-SR3KQE7Q.cjs +72 -0
  67. package/dist/tsup/chunk-SR3KQE7Q.cjs.map +1 -0
  68. package/dist/tsup/chunk-SSEP6DHP.cjs +2657 -0
  69. package/dist/tsup/chunk-SSEP6DHP.cjs.map +1 -0
  70. package/dist/tsup/chunk-T5YCUGVS.js +1036 -0
  71. package/dist/tsup/chunk-T5YCUGVS.js.map +1 -0
  72. package/dist/tsup/{chunk-EJVBH5VF.cjs → chunk-TPGXWFQT.cjs} +3 -3
  73. package/dist/tsup/{chunk-EJVBH5VF.cjs.map → chunk-TPGXWFQT.cjs.map} +1 -1
  74. package/dist/tsup/{chunk-X35U3YNX.cjs → chunk-TYLXNCA5.cjs} +214 -339
  75. package/dist/tsup/chunk-TYLXNCA5.cjs.map +1 -0
  76. package/dist/tsup/chunk-VKVNIQRQ.js +257 -0
  77. package/dist/tsup/chunk-VKVNIQRQ.js.map +1 -0
  78. package/dist/tsup/chunk-XWBAQO5H.cjs +649 -0
  79. package/dist/tsup/chunk-XWBAQO5H.cjs.map +1 -0
  80. package/dist/tsup/chunk-YQ4LDVD6.cjs +5974 -0
  81. package/dist/tsup/chunk-YQ4LDVD6.cjs.map +1 -0
  82. package/dist/tsup/chunk-ZFY5J2EP.cjs +257 -0
  83. package/dist/tsup/chunk-ZFY5J2EP.cjs.map +1 -0
  84. package/dist/tsup/client/mod.cjs +9 -10
  85. package/dist/tsup/client/mod.cjs.map +1 -1
  86. package/dist/tsup/client/mod.d.cts +11 -5
  87. package/dist/tsup/client/mod.d.ts +11 -5
  88. package/dist/tsup/client/mod.js +8 -8
  89. package/dist/tsup/common/log.cjs +4 -4
  90. package/dist/tsup/common/log.d.cts +2 -2
  91. package/dist/tsup/common/log.d.ts +2 -2
  92. package/dist/tsup/common/log.js +3 -2
  93. package/dist/tsup/common/websocket.cjs +5 -5
  94. package/dist/tsup/common/websocket.js +4 -3
  95. package/dist/tsup/config-BFqid9Gr.d.ts +2574 -0
  96. package/dist/tsup/config-BiNoIHRs.d.cts +80 -0
  97. package/dist/tsup/config-BiNoIHRs.d.ts +80 -0
  98. package/dist/tsup/{config-CZB2-W8x.d.cts → config-CAZphOS1.d.cts} +681 -355
  99. package/dist/tsup/db/drizzle/mod.cjs +49 -0
  100. package/dist/tsup/db/drizzle/mod.cjs.map +1 -0
  101. package/dist/tsup/db/drizzle/mod.d.cts +17 -0
  102. package/dist/tsup/db/drizzle/mod.d.ts +17 -0
  103. package/dist/tsup/db/drizzle/mod.js +49 -0
  104. package/dist/tsup/db/drizzle/mod.js.map +1 -0
  105. package/dist/tsup/db/mod.cjs +9 -0
  106. package/dist/tsup/db/mod.cjs.map +1 -0
  107. package/dist/tsup/db/mod.d.cts +9 -0
  108. package/dist/tsup/db/mod.d.ts +9 -0
  109. package/dist/tsup/db/mod.js +9 -0
  110. package/dist/tsup/db/mod.js.map +1 -0
  111. package/dist/tsup/{driver-D0QX9M11.d.ts → driver-Bxv62E2p.d.ts} +2 -2
  112. package/dist/tsup/{driver-q-zqG7fc.d.cts → driver-DYXwJR5D.d.cts} +2 -2
  113. package/dist/tsup/driver-helpers/mod.cjs +12 -6
  114. package/dist/tsup/driver-helpers/mod.cjs.map +1 -1
  115. package/dist/tsup/driver-helpers/mod.d.cts +12 -5
  116. package/dist/tsup/driver-helpers/mod.d.ts +12 -5
  117. package/dist/tsup/driver-helpers/mod.js +12 -5
  118. package/dist/tsup/driver-test-suite/mod.cjs +1370 -116
  119. package/dist/tsup/driver-test-suite/mod.cjs.map +1 -1
  120. package/dist/tsup/driver-test-suite/mod.d.cts +10 -4
  121. package/dist/tsup/driver-test-suite/mod.d.ts +10 -4
  122. package/dist/tsup/driver-test-suite/mod.js +2093 -838
  123. package/dist/tsup/driver-test-suite/mod.js.map +1 -1
  124. package/dist/tsup/inspector/mod.cjs +29 -3
  125. package/dist/tsup/inspector/mod.cjs.map +1 -1
  126. package/dist/tsup/inspector/mod.d.cts +124 -3
  127. package/dist/tsup/inspector/mod.d.ts +124 -3
  128. package/dist/tsup/inspector/mod.js +72 -45
  129. package/dist/tsup/keys-CydblqMh.d.cts +13 -0
  130. package/dist/tsup/keys-CydblqMh.d.ts +13 -0
  131. package/dist/tsup/mod.cjs +16 -10
  132. package/dist/tsup/mod.cjs.map +1 -1
  133. package/dist/tsup/mod.d.cts +26 -14
  134. package/dist/tsup/mod.d.ts +26 -14
  135. package/dist/tsup/mod.js +20 -13
  136. package/dist/tsup/serve-test-suite/mod.cjs +1165 -83
  137. package/dist/tsup/serve-test-suite/mod.cjs.map +1 -1
  138. package/dist/tsup/serve-test-suite/mod.js +1114 -29
  139. package/dist/tsup/serve-test-suite/mod.js.map +1 -1
  140. package/dist/tsup/test/mod.cjs +84 -11
  141. package/dist/tsup/test/mod.cjs.map +1 -1
  142. package/dist/tsup/test/mod.d.cts +10 -5
  143. package/dist/tsup/test/mod.d.ts +10 -5
  144. package/dist/tsup/test/mod.js +85 -11
  145. package/dist/tsup/test/mod.js.map +1 -1
  146. package/dist/tsup/utils.cjs +10 -4
  147. package/dist/tsup/utils.cjs.map +1 -1
  148. package/dist/tsup/utils.d.cts +72 -2
  149. package/dist/tsup/utils.d.ts +72 -2
  150. package/dist/tsup/utils.js +9 -2
  151. package/dist/tsup/v3-DnYObHH3.d.cts +279 -0
  152. package/dist/tsup/v3-DnYObHH3.d.ts +279 -0
  153. package/dist/tsup/workflow/mod.cjs +16 -0
  154. package/dist/tsup/workflow/mod.cjs.map +1 -0
  155. package/dist/tsup/workflow/mod.d.cts +83 -0
  156. package/dist/tsup/workflow/mod.d.ts +83 -0
  157. package/dist/tsup/workflow/mod.js +16 -0
  158. package/dist/tsup/workflow/mod.js.map +1 -0
  159. package/package.json +62 -5
  160. package/src/actor/config.ts +478 -68
  161. package/src/actor/conn/mod.ts +68 -16
  162. package/src/actor/conn/state-manager.ts +2 -2
  163. package/src/actor/contexts/action.ts +20 -12
  164. package/src/actor/contexts/base/actor.ts +137 -7
  165. package/src/actor/contexts/base/conn-init.ts +27 -7
  166. package/src/actor/contexts/base/conn.ts +27 -18
  167. package/src/actor/contexts/before-action-response.ts +9 -2
  168. package/src/actor/contexts/before-connect.ts +7 -2
  169. package/src/actor/contexts/connect.ts +9 -2
  170. package/src/actor/contexts/create-conn-state.ts +7 -2
  171. package/src/actor/contexts/create-vars.ts +16 -3
  172. package/src/actor/contexts/create.ts +16 -3
  173. package/src/actor/contexts/destroy.ts +9 -3
  174. package/src/actor/contexts/disconnect.ts +10 -4
  175. package/src/actor/contexts/index.ts +4 -3
  176. package/src/actor/contexts/request.ts +23 -6
  177. package/src/actor/contexts/run.ts +47 -0
  178. package/src/actor/contexts/sleep.ts +9 -3
  179. package/src/actor/contexts/state-change.ts +9 -3
  180. package/src/actor/contexts/wake.ts +9 -3
  181. package/src/actor/contexts/websocket.ts +23 -6
  182. package/src/actor/database.ts +8 -18
  183. package/src/actor/definition.ts +20 -6
  184. package/src/actor/driver.ts +32 -3
  185. package/src/actor/errors.ts +127 -0
  186. package/src/actor/instance/connection-manager.ts +183 -80
  187. package/src/actor/instance/event-manager.ts +26 -15
  188. package/src/actor/instance/keys.ts +117 -0
  189. package/src/actor/instance/mod.ts +784 -174
  190. package/src/actor/instance/queue-manager.ts +603 -0
  191. package/src/actor/instance/queue.ts +287 -0
  192. package/src/actor/instance/schedule-manager.ts +49 -7
  193. package/src/actor/instance/state-manager.ts +35 -11
  194. package/src/actor/instance/traces-driver.ts +128 -0
  195. package/src/actor/mod.ts +26 -2
  196. package/src/actor/protocol/old.ts +28 -13
  197. package/src/actor/protocol/serde.ts +1 -1
  198. package/src/actor/router-endpoints.ts +177 -21
  199. package/src/actor/router-websocket-endpoints.ts +18 -29
  200. package/src/actor/router.ts +177 -0
  201. package/src/actor/schema.ts +291 -0
  202. package/src/actor/utils.ts +40 -0
  203. package/src/client/actor-common.ts +1 -1
  204. package/src/client/actor-conn.ts +100 -33
  205. package/src/client/actor-handle.ts +61 -33
  206. package/src/client/client.ts +2 -4
  207. package/src/client/config.ts +1 -1
  208. package/src/client/mod.browser.ts +2 -0
  209. package/src/client/mod.ts +1 -4
  210. package/src/client/queue.ts +146 -0
  211. package/src/client/utils.ts +1 -1
  212. package/src/common/log.ts +1 -1
  213. package/src/common/utils.ts +3 -3
  214. package/src/db/config.ts +100 -0
  215. package/src/db/drizzle/mod.ts +226 -0
  216. package/src/db/drizzle/sqlite-core.ts +22 -0
  217. package/src/db/mod.ts +125 -0
  218. package/src/db/shared.ts +92 -0
  219. package/src/db/sqlite-vfs.ts +12 -0
  220. package/src/driver-helpers/mod.ts +1 -0
  221. package/src/driver-test-suite/mod.ts +69 -43
  222. package/src/driver-test-suite/tests/access-control.ts +218 -0
  223. package/src/driver-test-suite/tests/actor-db-raw.ts +73 -0
  224. package/src/driver-test-suite/tests/actor-db.ts +394 -0
  225. package/src/driver-test-suite/tests/actor-inspector.ts +259 -358
  226. package/src/driver-test-suite/tests/actor-kv.ts +41 -20
  227. package/src/driver-test-suite/tests/actor-queue.ts +324 -0
  228. package/src/driver-test-suite/tests/actor-run.ts +181 -0
  229. package/src/driver-test-suite/tests/actor-schedule.ts +5 -2
  230. package/src/driver-test-suite/tests/actor-sleep.ts +3 -3
  231. package/src/driver-test-suite/tests/actor-stateless.ts +70 -0
  232. package/src/driver-test-suite/tests/actor-workflow.ts +108 -0
  233. package/src/driver-test-suite/tests/manager-driver.ts +11 -0
  234. package/src/driver-test-suite/tests/raw-http-request-properties.ts +1 -1
  235. package/src/driver-test-suite/tests/raw-websocket.ts +12 -12
  236. package/src/drivers/default.ts +7 -2
  237. package/src/drivers/engine/actor-driver.ts +45 -37
  238. package/src/drivers/engine/config.ts +1 -1
  239. package/src/drivers/file-system/actor.ts +20 -2
  240. package/src/drivers/file-system/global-state.ts +569 -258
  241. package/src/drivers/file-system/kv-limits.ts +70 -0
  242. package/src/drivers/file-system/manager.ts +22 -6
  243. package/src/drivers/file-system/mod.ts +39 -16
  244. package/src/drivers/file-system/sqlite-runtime.ts +210 -0
  245. package/src/inspector/actor-inspector.ts +224 -102
  246. package/src/inspector/config.ts +1 -1
  247. package/src/inspector/handler.ts +102 -20
  248. package/src/inspector/mod.browser.ts +8 -0
  249. package/src/inspector/mod.ts +2 -0
  250. package/src/inspector/serve-ui.ts +40 -0
  251. package/src/inspector/transport.ts +18 -0
  252. package/src/inspector/utils.ts +5 -39
  253. package/src/manager/gateway.ts +1 -1
  254. package/src/manager/protocol/mod.ts +1 -1
  255. package/src/manager/protocol/query.ts +1 -1
  256. package/src/manager/router-schema.ts +1 -1
  257. package/src/manager/router.ts +38 -12
  258. package/src/manager-api/actors.ts +1 -1
  259. package/src/manager-api/common.ts +1 -1
  260. package/src/registry/config/driver.ts +1 -1
  261. package/src/registry/config/index.ts +212 -43
  262. package/src/registry/config/legacy-runner.ts +1 -1
  263. package/src/registry/config/runner.ts +1 -1
  264. package/src/registry/config/serverless.ts +1 -1
  265. package/src/registry/index.ts +7 -5
  266. package/src/remote-manager-driver/api-utils.ts +1 -1
  267. package/src/schemas/actor-inspector/mod.ts +1 -1
  268. package/src/schemas/actor-inspector/versioned.ts +195 -8
  269. package/src/schemas/actor-persist/versioned.ts +87 -7
  270. package/src/schemas/client-protocol/mod.ts +1 -1
  271. package/src/schemas/client-protocol/versioned.ts +127 -11
  272. package/src/schemas/client-protocol-zod/mod.ts +16 -1
  273. package/src/schemas/persist/mod.ts +1 -0
  274. package/src/schemas/transport/mod.ts +1 -0
  275. package/src/serde.ts +1 -1
  276. package/src/serve-test-suite/mod.ts +10 -9
  277. package/src/test/mod.ts +15 -56
  278. package/src/utils/endpoint-parser.test.ts +1 -1
  279. package/src/utils/endpoint-parser.ts +1 -1
  280. package/src/utils/env-vars.ts +12 -1
  281. package/src/utils/node.ts +15 -2
  282. package/src/utils.test.ts +34 -0
  283. package/src/utils.ts +140 -6
  284. package/src/workflow/constants.ts +2 -0
  285. package/src/workflow/context.ts +532 -0
  286. package/src/workflow/driver.ts +191 -0
  287. package/src/workflow/inspector.ts +268 -0
  288. package/src/workflow/mod.ts +122 -0
  289. package/dist/tsup/chunk-2IJTYN6K.cjs +0 -278
  290. package/dist/tsup/chunk-2IJTYN6K.cjs.map +0 -1
  291. package/dist/tsup/chunk-2XQS746M.cjs.map +0 -1
  292. package/dist/tsup/chunk-3VP5CSHV.cjs +0 -114
  293. package/dist/tsup/chunk-3VP5CSHV.cjs.map +0 -1
  294. package/dist/tsup/chunk-AQFSQMBG.js +0 -114
  295. package/dist/tsup/chunk-AQFSQMBG.js.map +0 -1
  296. package/dist/tsup/chunk-E6ZE2YEA.js +0 -664
  297. package/dist/tsup/chunk-E6ZE2YEA.js.map +0 -1
  298. package/dist/tsup/chunk-FJ3KTN4V.js.map +0 -1
  299. package/dist/tsup/chunk-GBENOENJ.cjs +0 -8
  300. package/dist/tsup/chunk-GBENOENJ.cjs.map +0 -1
  301. package/dist/tsup/chunk-GD7UXGOE.cjs +0 -4762
  302. package/dist/tsup/chunk-GD7UXGOE.cjs.map +0 -1
  303. package/dist/tsup/chunk-GMAVRZSF.js.map +0 -1
  304. package/dist/tsup/chunk-H4TB4X25.cjs.map +0 -1
  305. package/dist/tsup/chunk-JDAD2YFA.js.map +0 -1
  306. package/dist/tsup/chunk-KCOVZOPS.js +0 -1946
  307. package/dist/tsup/chunk-KCOVZOPS.js.map +0 -1
  308. package/dist/tsup/chunk-KDFWJKMJ.cjs +0 -664
  309. package/dist/tsup/chunk-KDFWJKMJ.cjs.map +0 -1
  310. package/dist/tsup/chunk-LFVF5SCU.js.map +0 -1
  311. package/dist/tsup/chunk-Q6W7RJJP.js.map +0 -1
  312. package/dist/tsup/chunk-RUW5CZ5Z.cjs +0 -1949
  313. package/dist/tsup/chunk-RUW5CZ5Z.cjs.map +0 -1
  314. package/dist/tsup/chunk-RZW2DNND.cjs.map +0 -1
  315. package/dist/tsup/chunk-TCOEBUUE.js +0 -278
  316. package/dist/tsup/chunk-TCOEBUUE.js.map +0 -1
  317. package/dist/tsup/chunk-X35U3YNX.cjs.map +0 -1
  318. package/dist/tsup/keys-Chhy4ylv.d.cts +0 -8
  319. package/dist/tsup/keys-Chhy4ylv.d.ts +0 -8
  320. package/dist/tsup/v1-Gq4avTK3.d.cts +0 -240
  321. package/dist/tsup/v1-Gq4avTK3.d.ts +0 -240
  322. /package/dist/tsup/{chunk-XXGJCOL6.js.map → chunk-A6YIZWTK.js.map} +0 -0
@@ -0,0 +1,406 @@
1
+ // @generated - post-processed by compile-bare.ts
2
+
3
+ import * as bare from "@rivetkit/bare-ts"
4
+
5
+ const config = /* @__PURE__ */ bare.Config({})
6
+
7
+ export type i64 = bigint
8
+ export type u16 = number
9
+ export type u32 = number
10
+ export type u64 = bigint
11
+
12
+ export type GatewayId = ArrayBuffer
13
+
14
+ export function readGatewayId(bc: bare.ByteCursor): GatewayId {
15
+ return bare.readFixedData(bc, 4)
16
+ }
17
+
18
+ export function writeGatewayId(bc: bare.ByteCursor, x: GatewayId): void {
19
+ assert(x.byteLength === 4)
20
+ bare.writeFixedData(bc, x)
21
+ }
22
+
23
+ export type RequestId = ArrayBuffer
24
+
25
+ export function readRequestId(bc: bare.ByteCursor): RequestId {
26
+ return bare.readFixedData(bc, 4)
27
+ }
28
+
29
+ export function writeRequestId(bc: bare.ByteCursor, x: RequestId): void {
30
+ assert(x.byteLength === 4)
31
+ bare.writeFixedData(bc, x)
32
+ }
33
+
34
+ export type MessageIndex = u16
35
+
36
+ export function readMessageIndex(bc: bare.ByteCursor): MessageIndex {
37
+ return bare.readU16(bc)
38
+ }
39
+
40
+ export function writeMessageIndex(bc: bare.ByteCursor, x: MessageIndex): void {
41
+ bare.writeU16(bc, x)
42
+ }
43
+
44
+ export function encodeMessageIndex(x: MessageIndex): Uint8Array {
45
+ const bc = new bare.ByteCursor(
46
+ new Uint8Array(config.initialBufferLength),
47
+ config
48
+ )
49
+ writeMessageIndex(bc, x)
50
+ return new Uint8Array(bc.view.buffer, bc.view.byteOffset, bc.offset)
51
+ }
52
+
53
+ export function decodeMessageIndex(bytes: Uint8Array): MessageIndex {
54
+ const bc = new bare.ByteCursor(bytes, config)
55
+ const result = readMessageIndex(bc)
56
+ if (bc.offset < bc.view.byteLength) {
57
+ throw new bare.BareError(bc.offset, "remaining bytes")
58
+ }
59
+ return result
60
+ }
61
+
62
+ export type Cbor = ArrayBuffer
63
+
64
+ export function readCbor(bc: bare.ByteCursor): Cbor {
65
+ return bare.readData(bc)
66
+ }
67
+
68
+ export function writeCbor(bc: bare.ByteCursor, x: Cbor): void {
69
+ bare.writeData(bc, x)
70
+ }
71
+
72
+ export type Subscription = {
73
+ readonly eventName: string,
74
+ }
75
+
76
+ export function readSubscription(bc: bare.ByteCursor): Subscription {
77
+ return {
78
+ eventName: bare.readString(bc),
79
+ }
80
+ }
81
+
82
+ export function writeSubscription(bc: bare.ByteCursor, x: Subscription): void {
83
+ bare.writeString(bc, x.eventName)
84
+ }
85
+
86
+ function read0(bc: bare.ByteCursor): readonly Subscription[] {
87
+ const len = bare.readUintSafe(bc)
88
+ if (len === 0) { return [] }
89
+ const result = [readSubscription(bc)]
90
+ for (let i = 1; i < len; i++) {
91
+ result[i] = readSubscription(bc)
92
+ }
93
+ return result
94
+ }
95
+
96
+ function write0(bc: bare.ByteCursor, x: readonly Subscription[]): void {
97
+ bare.writeUintSafe(bc, x.length)
98
+ for (let i = 0; i < x.length; i++) {
99
+ writeSubscription(bc, x[i])
100
+ }
101
+ }
102
+
103
+ function read1(bc: bare.ByteCursor): ReadonlyMap<string, string> {
104
+ const len = bare.readUintSafe(bc)
105
+ const result = new Map<string, string>()
106
+ for (let i = 0; i < len; i++) {
107
+ const offset = bc.offset
108
+ const key = bare.readString(bc)
109
+ if (result.has(key)) {
110
+ bc.offset = offset
111
+ throw new bare.BareError(offset, "duplicated key")
112
+ }
113
+ result.set(key, bare.readString(bc))
114
+ }
115
+ return result
116
+ }
117
+
118
+ function write1(bc: bare.ByteCursor, x: ReadonlyMap<string, string>): void {
119
+ bare.writeUintSafe(bc, x.size)
120
+ for(const kv of x) {
121
+ bare.writeString(bc, kv[0])
122
+ bare.writeString(bc, kv[1])
123
+ }
124
+ }
125
+
126
+ export type Conn = {
127
+ readonly id: string,
128
+ readonly parameters: Cbor,
129
+ readonly state: Cbor,
130
+ readonly subscriptions: readonly Subscription[],
131
+ readonly gatewayId: GatewayId,
132
+ readonly requestId: RequestId,
133
+ readonly serverMessageIndex: u16,
134
+ readonly clientMessageIndex: u16,
135
+ readonly requestPath: string,
136
+ readonly requestHeaders: ReadonlyMap<string, string>,
137
+ }
138
+
139
+ export function readConn(bc: bare.ByteCursor): Conn {
140
+ return {
141
+ id: bare.readString(bc),
142
+ parameters: readCbor(bc),
143
+ state: readCbor(bc),
144
+ subscriptions: read0(bc),
145
+ gatewayId: readGatewayId(bc),
146
+ requestId: readRequestId(bc),
147
+ serverMessageIndex: bare.readU16(bc),
148
+ clientMessageIndex: bare.readU16(bc),
149
+ requestPath: bare.readString(bc),
150
+ requestHeaders: read1(bc),
151
+ }
152
+ }
153
+
154
+ export function writeConn(bc: bare.ByteCursor, x: Conn): void {
155
+ bare.writeString(bc, x.id)
156
+ writeCbor(bc, x.parameters)
157
+ writeCbor(bc, x.state)
158
+ write0(bc, x.subscriptions)
159
+ writeGatewayId(bc, x.gatewayId)
160
+ writeRequestId(bc, x.requestId)
161
+ bare.writeU16(bc, x.serverMessageIndex)
162
+ bare.writeU16(bc, x.clientMessageIndex)
163
+ bare.writeString(bc, x.requestPath)
164
+ write1(bc, x.requestHeaders)
165
+ }
166
+
167
+ export function encodeConn(x: Conn): Uint8Array {
168
+ const bc = new bare.ByteCursor(
169
+ new Uint8Array(config.initialBufferLength),
170
+ config
171
+ )
172
+ writeConn(bc, x)
173
+ return new Uint8Array(bc.view.buffer, bc.view.byteOffset, bc.offset)
174
+ }
175
+
176
+ export function decodeConn(bytes: Uint8Array): Conn {
177
+ const bc = new bare.ByteCursor(bytes, config)
178
+ const result = readConn(bc)
179
+ if (bc.offset < bc.view.byteLength) {
180
+ throw new bare.BareError(bc.offset, "remaining bytes")
181
+ }
182
+ return result
183
+ }
184
+
185
+ function read2(bc: bare.ByteCursor): Cbor | null {
186
+ return bare.readBool(bc)
187
+ ? readCbor(bc)
188
+ : null
189
+ }
190
+
191
+ function write2(bc: bare.ByteCursor, x: Cbor | null): void {
192
+ bare.writeBool(bc, x !== null)
193
+ if (x !== null) {
194
+ writeCbor(bc, x)
195
+ }
196
+ }
197
+
198
+ export type ScheduleEvent = {
199
+ readonly eventId: string,
200
+ readonly timestamp: i64,
201
+ readonly action: string,
202
+ readonly args: Cbor | null,
203
+ }
204
+
205
+ export function readScheduleEvent(bc: bare.ByteCursor): ScheduleEvent {
206
+ return {
207
+ eventId: bare.readString(bc),
208
+ timestamp: bare.readI64(bc),
209
+ action: bare.readString(bc),
210
+ args: read2(bc),
211
+ }
212
+ }
213
+
214
+ export function writeScheduleEvent(bc: bare.ByteCursor, x: ScheduleEvent): void {
215
+ bare.writeString(bc, x.eventId)
216
+ bare.writeI64(bc, x.timestamp)
217
+ bare.writeString(bc, x.action)
218
+ write2(bc, x.args)
219
+ }
220
+
221
+ function read3(bc: bare.ByteCursor): readonly ScheduleEvent[] {
222
+ const len = bare.readUintSafe(bc)
223
+ if (len === 0) { return [] }
224
+ const result = [readScheduleEvent(bc)]
225
+ for (let i = 1; i < len; i++) {
226
+ result[i] = readScheduleEvent(bc)
227
+ }
228
+ return result
229
+ }
230
+
231
+ function write3(bc: bare.ByteCursor, x: readonly ScheduleEvent[]): void {
232
+ bare.writeUintSafe(bc, x.length)
233
+ for (let i = 0; i < x.length; i++) {
234
+ writeScheduleEvent(bc, x[i])
235
+ }
236
+ }
237
+
238
+ export type Actor = {
239
+ readonly input: Cbor | null,
240
+ readonly hasInitialized: boolean,
241
+ readonly state: Cbor,
242
+ readonly scheduledEvents: readonly ScheduleEvent[],
243
+ }
244
+
245
+ export function readActor(bc: bare.ByteCursor): Actor {
246
+ return {
247
+ input: read2(bc),
248
+ hasInitialized: bare.readBool(bc),
249
+ state: readCbor(bc),
250
+ scheduledEvents: read3(bc),
251
+ }
252
+ }
253
+
254
+ export function writeActor(bc: bare.ByteCursor, x: Actor): void {
255
+ write2(bc, x.input)
256
+ bare.writeBool(bc, x.hasInitialized)
257
+ writeCbor(bc, x.state)
258
+ write3(bc, x.scheduledEvents)
259
+ }
260
+
261
+ export function encodeActor(x: Actor): Uint8Array {
262
+ const bc = new bare.ByteCursor(
263
+ new Uint8Array(config.initialBufferLength),
264
+ config
265
+ )
266
+ writeActor(bc, x)
267
+ return new Uint8Array(bc.view.buffer, bc.view.byteOffset, bc.offset)
268
+ }
269
+
270
+ export function decodeActor(bytes: Uint8Array): Actor {
271
+ const bc = new bare.ByteCursor(bytes, config)
272
+ const result = readActor(bc)
273
+ if (bc.offset < bc.view.byteLength) {
274
+ throw new bare.BareError(bc.offset, "remaining bytes")
275
+ }
276
+ return result
277
+ }
278
+
279
+ export type QueueMetadata = {
280
+ readonly nextId: u64,
281
+ readonly size: u32,
282
+ }
283
+
284
+ export function readQueueMetadata(bc: bare.ByteCursor): QueueMetadata {
285
+ return {
286
+ nextId: bare.readU64(bc),
287
+ size: bare.readU32(bc),
288
+ }
289
+ }
290
+
291
+ export function writeQueueMetadata(bc: bare.ByteCursor, x: QueueMetadata): void {
292
+ bare.writeU64(bc, x.nextId)
293
+ bare.writeU32(bc, x.size)
294
+ }
295
+
296
+ export function encodeQueueMetadata(x: QueueMetadata): Uint8Array {
297
+ const bc = new bare.ByteCursor(
298
+ new Uint8Array(config.initialBufferLength),
299
+ config
300
+ )
301
+ writeQueueMetadata(bc, x)
302
+ return new Uint8Array(bc.view.buffer, bc.view.byteOffset, bc.offset)
303
+ }
304
+
305
+ export function decodeQueueMetadata(bytes: Uint8Array): QueueMetadata {
306
+ const bc = new bare.ByteCursor(bytes, config)
307
+ const result = readQueueMetadata(bc)
308
+ if (bc.offset < bc.view.byteLength) {
309
+ throw new bare.BareError(bc.offset, "remaining bytes")
310
+ }
311
+ return result
312
+ }
313
+
314
+ function read4(bc: bare.ByteCursor): u32 | null {
315
+ return bare.readBool(bc)
316
+ ? bare.readU32(bc)
317
+ : null
318
+ }
319
+
320
+ function write4(bc: bare.ByteCursor, x: u32 | null): void {
321
+ bare.writeBool(bc, x !== null)
322
+ if (x !== null) {
323
+ bare.writeU32(bc, x)
324
+ }
325
+ }
326
+
327
+ function read5(bc: bare.ByteCursor): i64 | null {
328
+ return bare.readBool(bc)
329
+ ? bare.readI64(bc)
330
+ : null
331
+ }
332
+
333
+ function write5(bc: bare.ByteCursor, x: i64 | null): void {
334
+ bare.writeBool(bc, x !== null)
335
+ if (x !== null) {
336
+ bare.writeI64(bc, x)
337
+ }
338
+ }
339
+
340
+ function read6(bc: bare.ByteCursor): boolean | null {
341
+ return bare.readBool(bc)
342
+ ? bare.readBool(bc)
343
+ : null
344
+ }
345
+
346
+ function write6(bc: bare.ByteCursor, x: boolean | null): void {
347
+ bare.writeBool(bc, x !== null)
348
+ if (x !== null) {
349
+ bare.writeBool(bc, x)
350
+ }
351
+ }
352
+
353
+ export type QueueMessage = {
354
+ readonly name: string,
355
+ readonly body: Cbor,
356
+ readonly createdAt: i64,
357
+ readonly failureCount: u32 | null,
358
+ readonly availableAt: i64 | null,
359
+ readonly inFlight: boolean | null,
360
+ readonly inFlightAt: i64 | null,
361
+ }
362
+
363
+ export function readQueueMessage(bc: bare.ByteCursor): QueueMessage {
364
+ return {
365
+ name: bare.readString(bc),
366
+ body: readCbor(bc),
367
+ createdAt: bare.readI64(bc),
368
+ failureCount: read4(bc),
369
+ availableAt: read5(bc),
370
+ inFlight: read6(bc),
371
+ inFlightAt: read5(bc),
372
+ }
373
+ }
374
+
375
+ export function writeQueueMessage(bc: bare.ByteCursor, x: QueueMessage): void {
376
+ bare.writeString(bc, x.name)
377
+ writeCbor(bc, x.body)
378
+ bare.writeI64(bc, x.createdAt)
379
+ write4(bc, x.failureCount)
380
+ write5(bc, x.availableAt)
381
+ write6(bc, x.inFlight)
382
+ write5(bc, x.inFlightAt)
383
+ }
384
+
385
+ export function encodeQueueMessage(x: QueueMessage): Uint8Array {
386
+ const bc = new bare.ByteCursor(
387
+ new Uint8Array(config.initialBufferLength),
388
+ config
389
+ )
390
+ writeQueueMessage(bc, x)
391
+ return new Uint8Array(bc.view.buffer, bc.view.byteOffset, bc.offset)
392
+ }
393
+
394
+ export function decodeQueueMessage(bytes: Uint8Array): QueueMessage {
395
+ const bc = new bare.ByteCursor(bytes, config)
396
+ const result = readQueueMessage(bc)
397
+ if (bc.offset < bc.view.byteLength) {
398
+ throw new bare.BareError(bc.offset, "remaining bytes")
399
+ }
400
+ return result
401
+ }
402
+
403
+
404
+ function assert(condition: boolean, message?: string): asserts condition {
405
+ if (!condition) throw new Error(message ?? "Assertion failed")
406
+ }