rivetkit 0.0.0-skip-ready-wait-flatten-client-options.1cae221 → 0.0.0-sqlite-uds.4e59a38

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 (253) hide show
  1. package/dist/browser/client.d.ts +561 -89
  2. package/dist/browser/client.js +1063 -430
  3. package/dist/browser/client.js.map +1 -1
  4. package/dist/browser/inspector/client.d.ts +22 -2
  5. package/dist/browser/inspector/client.js +1036 -232
  6. package/dist/browser/inspector/client.js.map +1 -1
  7. package/dist/tsup/actor/errors.cjs +6 -2
  8. package/dist/tsup/actor/errors.cjs.map +1 -1
  9. package/dist/tsup/actor/errors.d.cts +1 -74
  10. package/dist/tsup/actor/errors.d.ts +1 -74
  11. package/dist/tsup/actor/errors.js +5 -1
  12. package/dist/tsup/agent-os/index.cjs +2218 -2082
  13. package/dist/tsup/agent-os/index.cjs.map +1 -1
  14. package/dist/tsup/agent-os/index.d.cts +556 -85
  15. package/dist/tsup/agent-os/index.d.ts +556 -85
  16. package/dist/tsup/agent-os/index.js +2220 -2084
  17. package/dist/tsup/agent-os/index.js.map +1 -1
  18. package/dist/tsup/{chunk-NFC5VU36.cjs → chunk-3GC3EP6D.cjs} +18 -10
  19. package/dist/tsup/chunk-3GC3EP6D.cjs.map +1 -0
  20. package/dist/tsup/{chunk-7MRGNVSR.js → chunk-3GLNEWGY.js} +78 -6
  21. package/dist/tsup/chunk-3GLNEWGY.js.map +1 -0
  22. package/dist/tsup/{chunk-V3QNBJ7N.cjs → chunk-4FC7TVS6.cjs} +35 -10
  23. package/dist/tsup/chunk-4FC7TVS6.cjs.map +1 -0
  24. package/dist/tsup/{chunk-POTPHU3P.cjs → chunk-62LSMTP2.cjs} +3 -3
  25. package/dist/tsup/{chunk-POTPHU3P.cjs.map → chunk-62LSMTP2.cjs.map} +1 -1
  26. package/dist/tsup/{chunk-OIKOPSXQ.js → chunk-7IVUT2JT.js} +12 -4
  27. package/dist/tsup/chunk-7IVUT2JT.js.map +1 -0
  28. package/dist/tsup/{chunk-22XU3BVY.cjs → chunk-GEYQLGXC.cjs} +925 -328
  29. package/dist/tsup/chunk-GEYQLGXC.cjs.map +1 -0
  30. package/dist/tsup/{chunk-D2TLG75Y.cjs → chunk-GMN45CQ6.cjs} +10 -10
  31. package/dist/tsup/chunk-GMN45CQ6.cjs.map +1 -0
  32. package/dist/tsup/{chunk-3BFYSYRU.js → chunk-HXUEHHJF.js} +3 -2
  33. package/dist/tsup/chunk-HXUEHHJF.js.map +1 -0
  34. package/dist/tsup/{chunk-IOYKCB6Y.cjs → chunk-I336PMWT.cjs} +44 -9
  35. package/dist/tsup/chunk-I336PMWT.cjs.map +1 -0
  36. package/dist/tsup/{chunk-RZEJJJKU.js → chunk-IB73AMGJ.js} +42 -7
  37. package/dist/tsup/chunk-IB73AMGJ.js.map +1 -0
  38. package/dist/tsup/{chunk-4ZIWB4CQ.js → chunk-ITWJ6Y7G.js} +2 -2
  39. package/dist/tsup/{chunk-PCBNKI2J.js → chunk-JZ7TWV65.js} +1 -1
  40. package/dist/tsup/chunk-JZ7TWV65.js.map +1 -0
  41. package/dist/tsup/{chunk-W54QCENI.js → chunk-KTNBYGRU.js} +134 -20
  42. package/dist/tsup/chunk-KTNBYGRU.js.map +1 -0
  43. package/dist/tsup/{chunk-AK57AL7S.cjs → chunk-OAPVVVTX.cjs} +79 -7
  44. package/dist/tsup/chunk-OAPVVVTX.cjs.map +1 -0
  45. package/dist/tsup/{chunk-TPBHXFB2.cjs → chunk-OUDV3ITX.cjs} +138 -24
  46. package/dist/tsup/chunk-OUDV3ITX.cjs.map +1 -0
  47. package/dist/tsup/{chunk-XNZR7UD2.cjs → chunk-PRXTIERO.cjs} +90 -65
  48. package/dist/tsup/chunk-PRXTIERO.cjs.map +1 -0
  49. package/dist/tsup/{chunk-LLD2D5LO.cjs → chunk-VE2X4KMG.cjs} +3 -2
  50. package/dist/tsup/chunk-VE2X4KMG.cjs.map +1 -0
  51. package/dist/tsup/{chunk-KSG2COSQ.js → chunk-WRZEVVLL.js} +6 -6
  52. package/dist/tsup/chunk-WRZEVVLL.js.map +1 -0
  53. package/dist/tsup/{chunk-LNMB25HW.js → chunk-XAIMHUPG.js} +780 -183
  54. package/dist/tsup/chunk-XAIMHUPG.js.map +1 -0
  55. package/dist/tsup/{chunk-D4TSTM6C.js → chunk-XZ62SWSC.js} +83 -58
  56. package/dist/tsup/chunk-XZ62SWSC.js.map +1 -0
  57. package/dist/tsup/{chunk-2NDZ7JCR.cjs → chunk-ZA7FLHKH.cjs} +1 -1
  58. package/dist/tsup/chunk-ZA7FLHKH.cjs.map +1 -0
  59. package/dist/tsup/{chunk-K34B3OVG.js → chunk-ZZ3WBRPD.js} +34 -9
  60. package/dist/tsup/chunk-ZZ3WBRPD.js.map +1 -0
  61. package/dist/tsup/client/mod.cjs +9 -9
  62. package/dist/tsup/client/mod.cjs.map +1 -1
  63. package/dist/tsup/client/mod.d.cts +8 -9
  64. package/dist/tsup/client/mod.d.ts +8 -9
  65. package/dist/tsup/client/mod.js +8 -8
  66. package/dist/tsup/common/log.cjs +5 -3
  67. package/dist/tsup/common/log.cjs.map +1 -1
  68. package/dist/tsup/common/log.d.cts +5 -1
  69. package/dist/tsup/common/log.d.ts +5 -1
  70. package/dist/tsup/common/log.js +6 -4
  71. package/dist/tsup/common/websocket.cjs +4 -4
  72. package/dist/tsup/common/websocket.js +3 -3
  73. package/dist/tsup/{config-CRdGwwbr.d.cts → config-CxG53eQo.d.cts} +577 -36
  74. package/dist/tsup/{config-kxXbtrJU.d.ts → config-DLOxy81E.d.cts} +5 -5
  75. package/dist/tsup/{config-kxXbtrJU.d.cts → config-DLOxy81E.d.ts} +5 -5
  76. package/dist/tsup/{config-DIpBWm5C.d.ts → config-Ds6DCRhV.d.ts} +577 -36
  77. package/dist/tsup/context-8KlcOYIs.d.cts +129 -0
  78. package/dist/tsup/context-Cfbm4QLr.d.ts +129 -0
  79. package/dist/tsup/db/drizzle.cjs +151 -79
  80. package/dist/tsup/db/drizzle.cjs.map +1 -1
  81. package/dist/tsup/db/drizzle.d.cts +2 -2
  82. package/dist/tsup/db/drizzle.d.ts +2 -2
  83. package/dist/tsup/db/drizzle.js +151 -79
  84. package/dist/tsup/db/drizzle.js.map +1 -1
  85. package/dist/tsup/db/mod.cjs +79 -24
  86. package/dist/tsup/db/mod.cjs.map +1 -1
  87. package/dist/tsup/db/mod.d.cts +2 -2
  88. package/dist/tsup/db/mod.d.ts +2 -2
  89. package/dist/tsup/db/mod.js +78 -23
  90. package/dist/tsup/db/mod.js.map +1 -1
  91. package/dist/tsup/dynamic/mod.cjs +24 -0
  92. package/dist/tsup/dynamic/mod.cjs.map +1 -0
  93. package/dist/tsup/dynamic/mod.d.cts +37 -0
  94. package/dist/tsup/dynamic/mod.d.ts +37 -0
  95. package/dist/tsup/dynamic/mod.js +24 -0
  96. package/dist/tsup/dynamic/mod.js.map +1 -0
  97. package/dist/tsup/inspector/mod.cjs +47 -12
  98. package/dist/tsup/inspector/mod.cjs.map +1 -1
  99. package/dist/tsup/inspector/mod.d.cts +37 -15
  100. package/dist/tsup/inspector/mod.d.ts +37 -15
  101. package/dist/tsup/inspector/mod.js +46 -11
  102. package/dist/tsup/inspector/mod.js.map +1 -1
  103. package/dist/tsup/inspector-tab/mod.cjs +162 -0
  104. package/dist/tsup/inspector-tab/mod.cjs.map +1 -0
  105. package/dist/tsup/inspector-tab/mod.d.cts +240 -0
  106. package/dist/tsup/inspector-tab/mod.d.ts +240 -0
  107. package/dist/tsup/inspector-tab/mod.js +162 -0
  108. package/dist/tsup/inspector-tab/mod.js.map +1 -0
  109. package/dist/tsup/mod.cjs +1078 -479
  110. package/dist/tsup/mod.cjs.map +1 -1
  111. package/dist/tsup/mod.d.cts +5 -6
  112. package/dist/tsup/mod.d.ts +5 -6
  113. package/dist/tsup/mod.js +996 -397
  114. package/dist/tsup/mod.js.map +1 -1
  115. package/dist/tsup/test/mod.cjs +21 -18
  116. package/dist/tsup/test/mod.cjs.map +1 -1
  117. package/dist/tsup/test/mod.d.cts +4 -5
  118. package/dist/tsup/test/mod.d.ts +4 -5
  119. package/dist/tsup/test/mod.js +18 -15
  120. package/dist/tsup/test/mod.js.map +1 -1
  121. package/dist/tsup/utils-CqDnC_PS.d.cts +104 -0
  122. package/dist/tsup/utils-CqDnC_PS.d.ts +104 -0
  123. package/dist/tsup/utils.cjs +3 -3
  124. package/dist/tsup/utils.d.cts +1 -1
  125. package/dist/tsup/utils.d.ts +1 -1
  126. package/dist/tsup/utils.js +2 -2
  127. package/dist/tsup/workflow/mod.cjs +386 -322
  128. package/dist/tsup/workflow/mod.cjs.map +1 -1
  129. package/dist/tsup/workflow/mod.d.cts +8 -9
  130. package/dist/tsup/workflow/mod.d.ts +8 -9
  131. package/dist/tsup/workflow/mod.js +363 -299
  132. package/dist/tsup/workflow/mod.js.map +1 -1
  133. package/package.json +35 -14
  134. package/src/actor/config.ts +188 -59
  135. package/src/actor/contexts/index.ts +7 -2
  136. package/src/actor/definition.ts +17 -19
  137. package/src/actor/driver.ts +3 -3
  138. package/src/actor/errors.ts +70 -7
  139. package/src/actor/instance/mod.ts +39 -56
  140. package/src/actor/keys.ts +2 -1
  141. package/src/actor/mod.ts +22 -20
  142. package/src/actor/schema.ts +2 -2
  143. package/src/agent-os/actor/index.ts +38 -18
  144. package/src/agent-os/actor/preview.ts +1 -2
  145. package/src/agent-os/actor/session.ts +2 -2
  146. package/src/agent-os/config.ts +1 -1
  147. package/src/agent-os/fs/database-vfs.ts +1 -1
  148. package/src/agent-os/index.ts +16 -15
  149. package/src/client/actor-common.ts +88 -62
  150. package/src/client/actor-conn.ts +58 -63
  151. package/src/client/actor-handle.ts +125 -71
  152. package/src/client/actor-query.ts +5 -5
  153. package/src/client/config.ts +3 -3
  154. package/src/client/errors.ts +2 -1
  155. package/src/client/lifecycle-errors.ts +2 -4
  156. package/src/client/query.ts +1 -1
  157. package/src/client/queue.ts +8 -3
  158. package/src/client/raw-utils.ts +10 -10
  159. package/src/client/resolve-gateway-target.ts +1 -1
  160. package/src/client/utils.ts +34 -10
  161. package/src/common/actor-router-consts.ts +7 -4
  162. package/src/common/actor-websocket.ts +3 -1
  163. package/src/common/bare/actor-persist/v1.ts +205 -163
  164. package/src/common/bare/actor-persist/v2.ts +265 -213
  165. package/src/common/bare/actor-persist/v3.ts +176 -172
  166. package/src/common/bare/actor-persist/v4.ts +254 -253
  167. package/src/common/bare/generated/client-protocol/v4.ts +599 -0
  168. package/src/common/bare/generated/inspector/v5.ts +1016 -0
  169. package/src/common/bare/transport/v1.ts +694 -542
  170. package/src/common/client-protocol-versioned.ts +176 -67
  171. package/src/common/client-protocol-zod.ts +7 -0
  172. package/src/common/client-protocol.ts +1 -1
  173. package/src/common/database/config.ts +16 -5
  174. package/src/common/database/mod.test.ts +83 -16
  175. package/src/common/database/mod.ts +86 -30
  176. package/src/common/database/native-database.test.ts +35 -22
  177. package/src/common/database/native-database.ts +26 -10
  178. package/src/common/database/shared.ts +1 -0
  179. package/src/common/encoding.ts +250 -16
  180. package/src/common/engine.ts +28 -1
  181. package/src/common/eventsource.ts +1 -1
  182. package/src/common/inline-websocket-adapter.ts +14 -13
  183. package/src/common/log.ts +15 -8
  184. package/src/common/router.ts +49 -23
  185. package/src/common/utils.ts +10 -202
  186. package/src/common/websocket-interface.ts +1 -1
  187. package/src/db/drizzle.ts +173 -96
  188. package/src/db/mod.ts +1 -1
  189. package/src/devtools-loader/index.ts +4 -7
  190. package/src/devtools-loader/serve-devtools.ts +26 -0
  191. package/src/drivers/engine/actor-driver.ts +76 -73
  192. package/src/dynamic/instance.ts +32 -0
  193. package/src/dynamic/internal.ts +50 -0
  194. package/src/dynamic/isolate-runtime.ts +66 -0
  195. package/src/dynamic/mod.ts +32 -0
  196. package/src/engine-client/actor-http-client.ts +6 -9
  197. package/src/engine-client/actor-websocket-client.ts +14 -13
  198. package/src/engine-client/api-endpoints.ts +51 -2
  199. package/src/engine-client/api-utils.ts +2 -2
  200. package/src/engine-client/driver.ts +3 -4
  201. package/src/engine-client/mod.ts +17 -10
  202. package/src/engine-client/ws-proxy.ts +9 -4
  203. package/src/inspector/client.browser.ts +66 -15
  204. package/src/inspector/mod.ts +2 -4
  205. package/src/inspector-tab/mod.ts +300 -0
  206. package/src/registry/config/envoy.ts +1 -2
  207. package/src/registry/config/index.ts +46 -20
  208. package/src/registry/index.ts +364 -87
  209. package/src/registry/napi-runtime.ts +97 -8
  210. package/src/registry/native-validation.ts +10 -12
  211. package/src/registry/native.ts +592 -343
  212. package/src/registry/process-metrics.ts +250 -0
  213. package/src/registry/runtime.ts +85 -6
  214. package/src/registry/wasm-runtime.ts +72 -3
  215. package/src/registry/write-through-proxy.ts +40 -0
  216. package/src/serde.ts +2 -2
  217. package/src/serverless/configure.ts +19 -8
  218. package/src/test/mod.ts +11 -8
  219. package/src/utils/crypto.ts +14 -0
  220. package/src/utils/endpoint-parser.ts +1 -1
  221. package/src/utils/env-vars.ts +37 -0
  222. package/src/utils/router.ts +1 -1
  223. package/src/utils.ts +1 -2
  224. package/src/workflow/context.ts +703 -240
  225. package/src/workflow/driver.ts +23 -12
  226. package/src/workflow/inspector.ts +12 -3
  227. package/src/workflow/mod.ts +37 -23
  228. package/dist/tsup/chunk-22XU3BVY.cjs.map +0 -1
  229. package/dist/tsup/chunk-2NDZ7JCR.cjs.map +0 -1
  230. package/dist/tsup/chunk-3BFYSYRU.js.map +0 -1
  231. package/dist/tsup/chunk-7MRGNVSR.js.map +0 -1
  232. package/dist/tsup/chunk-AK57AL7S.cjs.map +0 -1
  233. package/dist/tsup/chunk-D2TLG75Y.cjs.map +0 -1
  234. package/dist/tsup/chunk-D4TSTM6C.js.map +0 -1
  235. package/dist/tsup/chunk-IOYKCB6Y.cjs.map +0 -1
  236. package/dist/tsup/chunk-K34B3OVG.js.map +0 -1
  237. package/dist/tsup/chunk-KSG2COSQ.js.map +0 -1
  238. package/dist/tsup/chunk-LLD2D5LO.cjs.map +0 -1
  239. package/dist/tsup/chunk-LNMB25HW.js.map +0 -1
  240. package/dist/tsup/chunk-NFC5VU36.cjs.map +0 -1
  241. package/dist/tsup/chunk-OIKOPSXQ.js.map +0 -1
  242. package/dist/tsup/chunk-PCBNKI2J.js.map +0 -1
  243. package/dist/tsup/chunk-RZEJJJKU.js.map +0 -1
  244. package/dist/tsup/chunk-TPBHXFB2.cjs.map +0 -1
  245. package/dist/tsup/chunk-V3QNBJ7N.cjs.map +0 -1
  246. package/dist/tsup/chunk-W54QCENI.js.map +0 -1
  247. package/dist/tsup/chunk-XNZR7UD2.cjs.map +0 -1
  248. package/dist/tsup/context-B7G6sk7x.d.ts +0 -92
  249. package/dist/tsup/context-DzMRHkjC.d.cts +0 -92
  250. package/dist/tsup/utils-fwx3o3K9.d.cts +0 -18
  251. package/dist/tsup/utils-fwx3o3K9.d.ts +0 -18
  252. package/src/utils/serve.ts +0 -217
  253. /package/dist/tsup/{chunk-4ZIWB4CQ.js.map → chunk-ITWJ6Y7G.js.map} +0 -0
@@ -2,8 +2,9 @@ import { createVersionedDataHandler } from "vbare";
2
2
  import * as v1 from "./bare/generated/client-protocol/v1";
3
3
  import * as v2 from "./bare/generated/client-protocol/v2";
4
4
  import * as v3 from "./bare/generated/client-protocol/v3";
5
+ import * as v4 from "./bare/generated/client-protocol/v4";
5
6
 
6
- export const CURRENT_VERSION = 3;
7
+ export const CURRENT_VERSION = 4;
7
8
 
8
9
  // Converter from v1 to v2: Remove connectionToken from Init message
9
10
  const v1ToV2 = (v1Data: v1.ToClient): v2.ToClient => {
@@ -44,17 +45,45 @@ const v2ToV1 = (v2Data: v2.ToClient): v1.ToClient => {
44
45
  return v2Data as unknown as v1.ToClient;
45
46
  };
46
47
 
47
- // Converter from v2 to v3: No changes needed for ToClient
48
+ // Converter from v2 to v3: No changes needed for ToClient.
48
49
  const v2ToV3 = (v2Data: v2.ToClient): v3.ToClient => {
49
50
  return v2Data as unknown as v3.ToClient;
50
51
  };
51
52
 
52
- // Converter from v3 to v2: No changes needed for ToClient
53
+ const v3ToV4 = (v3Data: v3.ToClient): v4.ToClient => {
54
+ if (v3Data.body.tag === "Error") {
55
+ return {
56
+ body: {
57
+ tag: "Error",
58
+ val: {
59
+ ...v3Data.body.val,
60
+ actor: null,
61
+ },
62
+ },
63
+ };
64
+ }
65
+ return v3Data as unknown as v4.ToClient;
66
+ };
67
+
68
+ const v4ToV3 = (v4Data: v4.ToClient): v3.ToClient => {
69
+ if (v4Data.body.tag === "Error") {
70
+ const { actor: _, ...val } = v4Data.body.val;
71
+ return {
72
+ body: {
73
+ tag: "Error",
74
+ val,
75
+ },
76
+ };
77
+ }
78
+ return v4Data as unknown as v3.ToClient;
79
+ };
80
+
81
+ // Converter from v3 to v2: No changes needed for ToClient.
53
82
  const v3ToV2 = (v3Data: v3.ToClient): v2.ToClient => {
54
83
  return v3Data as unknown as v2.ToClient;
55
84
  };
56
85
 
57
- // ToServer identity converters (ToServer is identical across v1, v2, and v3)
86
+ // ToServer identity converters.
58
87
  const v1ToServerV2 = (v1Data: v1.ToServer): v2.ToServer => {
59
88
  return v1Data as unknown as v2.ToServer;
60
89
  };
@@ -63,6 +92,14 @@ const v2ToServerV3 = (v2Data: v2.ToServer): v3.ToServer => {
63
92
  return v2Data as unknown as v3.ToServer;
64
93
  };
65
94
 
95
+ const v3ToServerV4 = (v3Data: v3.ToServer): v4.ToServer => {
96
+ return v3Data as unknown as v4.ToServer;
97
+ };
98
+
99
+ const v4ToServerV3 = (v4Data: v4.ToServer): v3.ToServer => {
100
+ return v4Data as unknown as v3.ToServer;
101
+ };
102
+
66
103
  const v3ToServerV2 = (v3Data: v3.ToServer): v2.ToServer => {
67
104
  return v3Data as unknown as v2.ToServer;
68
105
  };
@@ -71,66 +108,90 @@ const v2ToServerV1 = (v2Data: v2.ToServer): v1.ToServer => {
71
108
  return v2Data as unknown as v1.ToServer;
72
109
  };
73
110
 
74
- export const CLIENT_PROTOCOL_TO_SERVER = createVersionedDataHandler<v3.ToServer>({
75
- deserializeVersion: (bytes, version) => {
76
- switch (version) {
77
- case 1:
78
- return v1.decodeToServer(bytes);
79
- case 2:
80
- return v2.decodeToServer(bytes);
81
- case 3:
82
- return v3.decodeToServer(bytes);
83
- default:
84
- throw new Error(`Unknown version ${version}`);
85
- }
86
- },
87
- serializeVersion: (data, version) => {
88
- switch (version) {
89
- case 1:
90
- return v1.encodeToServer(data as v1.ToServer);
91
- case 2:
92
- return v2.encodeToServer(data as v2.ToServer);
93
- case 3:
94
- return v3.encodeToServer(data as v3.ToServer);
95
- default:
96
- throw new Error(`Unknown version ${version}`);
97
- }
98
- },
99
- deserializeConverters: () => [v1ToServerV2, v2ToServerV3],
100
- serializeConverters: () => [v3ToServerV2, v2ToServerV1],
111
+ const v3HttpResponseErrorToV4 = (
112
+ v3Data: v3.HttpResponseError,
113
+ ): v4.HttpResponseError => ({
114
+ ...v3Data,
115
+ actor: null,
101
116
  });
102
117
 
103
- export const CLIENT_PROTOCOL_TO_CLIENT = createVersionedDataHandler<v3.ToClient>({
104
- deserializeVersion: (bytes, version) => {
105
- switch (version) {
106
- case 1:
107
- return v1.decodeToClient(bytes);
108
- case 2:
109
- return v2.decodeToClient(bytes);
110
- case 3:
111
- return v3.decodeToClient(bytes);
112
- default:
113
- throw new Error(`Unknown version ${version}`);
114
- }
115
- },
116
- serializeVersion: (data, version) => {
117
- switch (version) {
118
- case 1:
119
- return v1.encodeToClient(data as v1.ToClient);
120
- case 2:
121
- return v2.encodeToClient(data as v2.ToClient);
122
- case 3:
123
- return v3.encodeToClient(data as v3.ToClient);
124
- default:
125
- throw new Error(`Unknown version ${version}`);
126
- }
127
- },
128
- deserializeConverters: () => [v1ToV2, v2ToV3],
129
- serializeConverters: () => [v3ToV2, v2ToV1],
130
- });
118
+ const v4HttpResponseErrorToV3 = (
119
+ v4Data: v4.HttpResponseError,
120
+ ): v3.HttpResponseError => {
121
+ const { actor: _, ...rest } = v4Data;
122
+ return rest;
123
+ };
124
+
125
+ export const CLIENT_PROTOCOL_TO_SERVER =
126
+ createVersionedDataHandler<v4.ToServer>({
127
+ deserializeVersion: (bytes, version) => {
128
+ switch (version) {
129
+ case 1:
130
+ return v1.decodeToServer(bytes);
131
+ case 2:
132
+ return v2.decodeToServer(bytes);
133
+ case 3:
134
+ return v3.decodeToServer(bytes);
135
+ case 4:
136
+ return v4.decodeToServer(bytes);
137
+ default:
138
+ throw new Error(`Unknown version ${version}`);
139
+ }
140
+ },
141
+ serializeVersion: (data, version) => {
142
+ switch (version) {
143
+ case 1:
144
+ return v1.encodeToServer(data as v1.ToServer);
145
+ case 2:
146
+ return v2.encodeToServer(data as v2.ToServer);
147
+ case 3:
148
+ return v3.encodeToServer(data as v3.ToServer);
149
+ case 4:
150
+ return v4.encodeToServer(data as v4.ToServer);
151
+ default:
152
+ throw new Error(`Unknown version ${version}`);
153
+ }
154
+ },
155
+ deserializeConverters: () => [v1ToServerV2, v2ToServerV3, v3ToServerV4],
156
+ serializeConverters: () => [v4ToServerV3, v3ToServerV2, v2ToServerV1],
157
+ });
158
+
159
+ export const CLIENT_PROTOCOL_TO_CLIENT =
160
+ createVersionedDataHandler<v4.ToClient>({
161
+ deserializeVersion: (bytes, version) => {
162
+ switch (version) {
163
+ case 1:
164
+ return v1.decodeToClient(bytes);
165
+ case 2:
166
+ return v2.decodeToClient(bytes);
167
+ case 3:
168
+ return v3.decodeToClient(bytes);
169
+ case 4:
170
+ return v4.decodeToClient(bytes);
171
+ default:
172
+ throw new Error(`Unknown version ${version}`);
173
+ }
174
+ },
175
+ serializeVersion: (data, version) => {
176
+ switch (version) {
177
+ case 1:
178
+ return v1.encodeToClient(data as v1.ToClient);
179
+ case 2:
180
+ return v2.encodeToClient(data as v2.ToClient);
181
+ case 3:
182
+ return v3.encodeToClient(data as v3.ToClient);
183
+ case 4:
184
+ return v4.encodeToClient(data as v4.ToClient);
185
+ default:
186
+ throw new Error(`Unknown version ${version}`);
187
+ }
188
+ },
189
+ deserializeConverters: () => [v1ToV2, v2ToV3, v3ToV4],
190
+ serializeConverters: () => [v4ToV3, v3ToV2, v2ToV1],
191
+ });
131
192
 
132
193
  export const HTTP_ACTION_REQUEST_VERSIONED =
133
- createVersionedDataHandler<v3.HttpActionRequest>({
194
+ createVersionedDataHandler<v4.HttpActionRequest>({
134
195
  deserializeVersion: (bytes, version) => {
135
196
  switch (version) {
136
197
  case 1:
@@ -139,6 +200,8 @@ export const HTTP_ACTION_REQUEST_VERSIONED =
139
200
  return v2.decodeHttpActionRequest(bytes);
140
201
  case 3:
141
202
  return v3.decodeHttpActionRequest(bytes);
203
+ case 4:
204
+ return v4.decodeHttpActionRequest(bytes);
142
205
  default:
143
206
  throw new Error(`Unknown version ${version}`);
144
207
  }
@@ -157,6 +220,10 @@ export const HTTP_ACTION_REQUEST_VERSIONED =
157
220
  return v3.encodeHttpActionRequest(
158
221
  data as v3.HttpActionRequest,
159
222
  );
223
+ case 4:
224
+ return v4.encodeHttpActionRequest(
225
+ data as v4.HttpActionRequest,
226
+ );
160
227
  default:
161
228
  throw new Error(`Unknown version ${version}`);
162
229
  }
@@ -166,7 +233,7 @@ export const HTTP_ACTION_REQUEST_VERSIONED =
166
233
  });
167
234
 
168
235
  export const HTTP_ACTION_RESPONSE_VERSIONED =
169
- createVersionedDataHandler<v3.HttpActionResponse>({
236
+ createVersionedDataHandler<v4.HttpActionResponse>({
170
237
  deserializeVersion: (bytes, version) => {
171
238
  switch (version) {
172
239
  case 1:
@@ -175,6 +242,8 @@ export const HTTP_ACTION_RESPONSE_VERSIONED =
175
242
  return v2.decodeHttpActionResponse(bytes);
176
243
  case 3:
177
244
  return v3.decodeHttpActionResponse(bytes);
245
+ case 4:
246
+ return v4.decodeHttpActionResponse(bytes);
178
247
  default:
179
248
  throw new Error(`Unknown version ${version}`);
180
249
  }
@@ -193,6 +262,10 @@ export const HTTP_ACTION_RESPONSE_VERSIONED =
193
262
  return v3.encodeHttpActionResponse(
194
263
  data as v3.HttpActionResponse,
195
264
  );
265
+ case 4:
266
+ return v4.encodeHttpActionResponse(
267
+ data as v4.HttpActionResponse,
268
+ );
196
269
  default:
197
270
  throw new Error(`Unknown version ${version}`);
198
271
  }
@@ -202,11 +275,13 @@ export const HTTP_ACTION_RESPONSE_VERSIONED =
202
275
  });
203
276
 
204
277
  export const HTTP_QUEUE_SEND_REQUEST_VERSIONED =
205
- createVersionedDataHandler<v3.HttpQueueSendRequest>({
278
+ createVersionedDataHandler<v4.HttpQueueSendRequest>({
206
279
  deserializeVersion: (bytes, version) => {
207
280
  switch (version) {
208
281
  case 3:
209
282
  return v3.decodeHttpQueueSendRequest(bytes);
283
+ case 4:
284
+ return v4.decodeHttpQueueSendRequest(bytes);
210
285
  default:
211
286
  throw new Error(
212
287
  `HttpQueueSendRequest only exists in version 3+, got version ${version}`,
@@ -219,6 +294,10 @@ export const HTTP_QUEUE_SEND_REQUEST_VERSIONED =
219
294
  return v3.encodeHttpQueueSendRequest(
220
295
  data as v3.HttpQueueSendRequest,
221
296
  );
297
+ case 4:
298
+ return v4.encodeHttpQueueSendRequest(
299
+ data as v4.HttpQueueSendRequest,
300
+ );
222
301
  default:
223
302
  throw new Error(
224
303
  `HttpQueueSendRequest only exists in version 3+, got version ${version}`,
@@ -230,11 +309,13 @@ export const HTTP_QUEUE_SEND_REQUEST_VERSIONED =
230
309
  });
231
310
 
232
311
  export const HTTP_QUEUE_SEND_RESPONSE_VERSIONED =
233
- createVersionedDataHandler<v3.HttpQueueSendResponse>({
312
+ createVersionedDataHandler<v4.HttpQueueSendResponse>({
234
313
  deserializeVersion: (bytes, version) => {
235
314
  switch (version) {
236
315
  case 3:
237
316
  return v3.decodeHttpQueueSendResponse(bytes);
317
+ case 4:
318
+ return v4.decodeHttpQueueSendResponse(bytes);
238
319
  default:
239
320
  throw new Error(
240
321
  `HttpQueueSendResponse only exists in version 3+, got version ${version}`,
@@ -247,6 +328,10 @@ export const HTTP_QUEUE_SEND_RESPONSE_VERSIONED =
247
328
  return v3.encodeHttpQueueSendResponse(
248
329
  data as v3.HttpQueueSendResponse,
249
330
  );
331
+ case 4:
332
+ return v4.encodeHttpQueueSendResponse(
333
+ data as v4.HttpQueueSendResponse,
334
+ );
250
335
  default:
251
336
  throw new Error(
252
337
  `HttpQueueSendResponse only exists in version 3+, got version ${version}`,
@@ -258,7 +343,7 @@ export const HTTP_QUEUE_SEND_RESPONSE_VERSIONED =
258
343
  });
259
344
 
260
345
  export const HTTP_RESPONSE_ERROR_VERSIONED =
261
- createVersionedDataHandler<v3.HttpResponseError>({
346
+ createVersionedDataHandler<v4.HttpResponseError>({
262
347
  deserializeVersion: (bytes, version) => {
263
348
  switch (version) {
264
349
  case 1:
@@ -267,6 +352,8 @@ export const HTTP_RESPONSE_ERROR_VERSIONED =
267
352
  return v2.decodeHttpResponseError(bytes);
268
353
  case 3:
269
354
  return v3.decodeHttpResponseError(bytes);
355
+ case 4:
356
+ return v4.decodeHttpResponseError(bytes);
270
357
  default:
271
358
  throw new Error(`Unknown version ${version}`);
272
359
  }
@@ -285,16 +372,32 @@ export const HTTP_RESPONSE_ERROR_VERSIONED =
285
372
  return v3.encodeHttpResponseError(
286
373
  data as v3.HttpResponseError,
287
374
  );
375
+ case 4:
376
+ return v4.encodeHttpResponseError(
377
+ data as v4.HttpResponseError,
378
+ );
288
379
  default:
289
380
  throw new Error(`Unknown version ${version}`);
290
381
  }
291
382
  },
292
- deserializeConverters: () => [],
293
- serializeConverters: () => [],
383
+ deserializeConverters: () => [
384
+ (data: v1.HttpResponseError) =>
385
+ data as unknown as v2.HttpResponseError,
386
+ (data: v2.HttpResponseError) =>
387
+ data as unknown as v3.HttpResponseError,
388
+ v3HttpResponseErrorToV4,
389
+ ],
390
+ serializeConverters: () => [
391
+ v4HttpResponseErrorToV3,
392
+ (data: v3.HttpResponseError) =>
393
+ data as unknown as v2.HttpResponseError,
394
+ (data: v2.HttpResponseError) =>
395
+ data as unknown as v1.HttpResponseError,
396
+ ],
294
397
  });
295
398
 
296
399
  export const HTTP_RESOLVE_RESPONSE_VERSIONED =
297
- createVersionedDataHandler<v3.HttpResolveResponse>({
400
+ createVersionedDataHandler<v4.HttpResolveResponse>({
298
401
  deserializeVersion: (bytes, version) => {
299
402
  switch (version) {
300
403
  case 1:
@@ -303,6 +406,8 @@ export const HTTP_RESOLVE_RESPONSE_VERSIONED =
303
406
  return v2.decodeHttpResolveResponse(bytes);
304
407
  case 3:
305
408
  return v3.decodeHttpResolveResponse(bytes);
409
+ case 4:
410
+ return v4.decodeHttpResolveResponse(bytes);
306
411
  default:
307
412
  throw new Error(`Unknown version ${version}`);
308
413
  }
@@ -321,6 +426,10 @@ export const HTTP_RESOLVE_RESPONSE_VERSIONED =
321
426
  return v3.encodeHttpResolveResponse(
322
427
  data as v3.HttpResolveResponse,
323
428
  );
429
+ case 4:
430
+ return v4.encodeHttpResolveResponse(
431
+ data as v4.HttpResolveResponse,
432
+ );
324
433
  default:
325
434
  throw new Error(`Unknown version ${version}`);
326
435
  }
@@ -3,6 +3,11 @@ import { z } from "zod/v4";
3
3
  // Helper schemas
4
4
  const UintSchema = z.bigint();
5
5
  const OptionalUintSchema = UintSchema.nullable();
6
+ const ActorSpecifierSchema = z.object({
7
+ actorId: z.string(),
8
+ generation: z.union([z.number(), z.bigint()]),
9
+ key: z.string().optional(),
10
+ });
6
11
 
7
12
  // MARK: Message To Client
8
13
  export const InitSchema = z.object({
@@ -17,6 +22,7 @@ export const ErrorSchema = z.object({
17
22
  message: z.string(),
18
23
  metadata: z.unknown().optional(),
19
24
  actionId: OptionalUintSchema,
25
+ actor: ActorSpecifierSchema.optional(),
20
26
  });
21
27
  export type Error = z.infer<typeof ErrorSchema>;
22
28
 
@@ -105,6 +111,7 @@ export const HttpResponseErrorSchema = z.object({
105
111
  code: z.string(),
106
112
  message: z.string(),
107
113
  metadata: z.unknown().optional(),
114
+ actor: ActorSpecifierSchema.optional(),
108
115
  });
109
116
  export type HttpResponseError = z.infer<typeof HttpResponseErrorSchema>;
110
117
 
@@ -1 +1 @@
1
- export * from "./bare/generated/client-protocol/v3";
1
+ export * from "./bare/generated/client-protocol/v4";
@@ -37,18 +37,25 @@ export interface SqliteNativeMetrics {
37
37
  dbSizePages: number;
38
38
  }
39
39
 
40
+ /** @internal */
41
+ export interface SqliteLeaseOptions {
42
+ key: string;
43
+ timeoutMs?: number;
44
+ }
45
+
40
46
  export interface SqliteDatabase {
41
47
  exec(
42
48
  sql: string,
43
49
  callback?: (row: unknown[], columns: string[]) => void,
50
+ lease?: SqliteLeaseOptions,
44
51
  ): Promise<void>;
45
52
  execute(
46
53
  sql: string,
47
54
  params?: SqliteBindings,
55
+ lease?: SqliteLeaseOptions,
48
56
  ): Promise<SqliteExecuteResult>;
49
57
  run(sql: string, params?: SqliteBindings): Promise<void>;
50
58
  query(sql: string, params?: SqliteBindings): Promise<SqliteQueryResult>;
51
- writeMode<T>(callback: () => Promise<T>): Promise<T>;
52
59
  nativeMetrics?():
53
60
  | SqliteNativeMetrics
54
61
  | Promise<SqliteNativeMetrics | null>
@@ -133,10 +140,7 @@ export interface RawDatabaseClient {
133
140
  /**
134
141
  * Drizzle database client interface (will be extended by drizzle-orm types)
135
142
  */
136
- export interface DrizzleDatabaseClient {
137
- // This will be extended by BaseSQLiteDatabase from drizzle-orm
138
- // For now, just a marker interface
139
- }
143
+ export type DrizzleDatabaseClient = {};
140
144
 
141
145
  type ExecuteFunction = <
142
146
  TRow extends Record<string, unknown> = Record<string, unknown>,
@@ -150,6 +154,13 @@ export type RawAccess = {
150
154
  * Executes a raw SQL query.
151
155
  */
152
156
  execute: ExecuteFunction;
157
+ /** Runs a callback in an isolated native SQLite transaction. */
158
+ transaction: <T>(callback: (tx: RawAccess) => Promise<T> | T) => Promise<T>;
159
+ /** @internal */
160
+ __withSqliteLease: <T>(
161
+ timeoutMs: number,
162
+ callback: (leased: RawAccess) => Promise<T> | T,
163
+ ) => Promise<T>;
153
164
  /**
154
165
  * Returns native SQLite metrics when the active runtime supports them.
155
166
  */
@@ -4,15 +4,15 @@ import type {
4
4
  SqliteBindings,
5
5
  SqliteDatabase,
6
6
  SqliteExecuteResult,
7
+ SqliteLeaseOptions,
7
8
  } from "./config";
8
9
  import { db } from "./mod";
9
10
 
10
11
  class FakeSqliteDatabase implements SqliteDatabase {
11
- writeModeDepth = 0;
12
12
  executeCalls: {
13
13
  sql: string;
14
14
  params?: SqliteBindings;
15
- writeMode: boolean;
15
+ lease?: SqliteLeaseOptions;
16
16
  }[] = [];
17
17
 
18
18
  async exec(): Promise<void> {}
@@ -20,11 +20,12 @@ class FakeSqliteDatabase implements SqliteDatabase {
20
20
  async execute(
21
21
  sql: string,
22
22
  params?: SqliteBindings,
23
+ lease?: SqliteLeaseOptions,
23
24
  ): Promise<SqliteExecuteResult> {
24
25
  this.executeCalls.push({
25
26
  sql,
26
27
  params,
27
- writeMode: this.writeModeDepth > 0,
28
+ lease,
28
29
  });
29
30
  return {
30
31
  columns: [],
@@ -43,15 +44,6 @@ class FakeSqliteDatabase implements SqliteDatabase {
43
44
  return { columns, rows };
44
45
  }
45
46
 
46
- async writeMode<T>(callback: () => Promise<T>): Promise<T> {
47
- this.writeModeDepth++;
48
- try {
49
- return await callback();
50
- } finally {
51
- this.writeModeDepth--;
52
- }
53
- }
54
-
55
47
  async close(): Promise<void> {}
56
48
  }
57
49
 
@@ -73,7 +65,7 @@ function testProviderContext(
73
65
  }
74
66
 
75
67
  describe("db", () => {
76
- test("runs onMigrate through sqlite write mode", async () => {
68
+ test("runs onMigrate inside a sqlite savepoint", async () => {
77
69
  const nativeDb = new FakeSqliteDatabase();
78
70
  const provider = db({
79
71
  onMigrate: async (client) => {
@@ -89,17 +81,92 @@ describe("db", () => {
89
81
 
90
82
  await provider.onMigrate(client);
91
83
 
92
- expect(nativeDb.executeCalls).toEqual([
84
+ expect(
85
+ nativeDb.executeCalls.map(({ sql, params }) => ({ sql, params })),
86
+ ).toEqual([
87
+ {
88
+ sql: "SAVEPOINT __rivet_on_migrate",
89
+ params: undefined,
90
+ },
93
91
  {
94
92
  sql: "CREATE TABLE items(id INTEGER PRIMARY KEY, value TEXT)",
95
93
  params: undefined,
96
- writeMode: true,
97
94
  },
98
95
  {
99
96
  sql: "SELECT COUNT(*) AS count FROM items",
100
97
  params: undefined,
101
- writeMode: true,
98
+ },
99
+ {
100
+ sql: "RELEASE SAVEPOINT __rivet_on_migrate",
101
+ params: undefined,
102
102
  },
103
103
  ]);
104
+ const leases = nativeDb.executeCalls.map((call) => call.lease);
105
+ expect(leases.every((lease) => lease?.timeoutMs === 60_000)).toBe(true);
106
+ expect(new Set(leases.map((lease) => lease?.key)).size).toBe(1);
107
+ });
108
+
109
+ test("rolls back the migration savepoint when onMigrate fails", async () => {
110
+ const nativeDb = new FakeSqliteDatabase();
111
+ const provider = db({
112
+ onMigrate: async (client) => {
113
+ await client.execute(
114
+ "CREATE TABLE items(id INTEGER PRIMARY KEY, value TEXT)",
115
+ );
116
+ throw new Error("migration failed");
117
+ },
118
+ });
119
+ const client = await provider.createClient(
120
+ testProviderContext(nativeDb),
121
+ );
122
+
123
+ await expect(provider.onMigrate(client)).rejects.toThrow(
124
+ "migration failed",
125
+ );
126
+
127
+ expect(
128
+ nativeDb.executeCalls.map(({ sql, params }) => ({ sql, params })),
129
+ ).toEqual([
130
+ {
131
+ sql: "SAVEPOINT __rivet_on_migrate",
132
+ params: undefined,
133
+ },
134
+ {
135
+ sql: "CREATE TABLE items(id INTEGER PRIMARY KEY, value TEXT)",
136
+ params: undefined,
137
+ },
138
+ {
139
+ sql: "ROLLBACK TO SAVEPOINT __rivet_on_migrate",
140
+ params: undefined,
141
+ },
142
+ {
143
+ sql: "RELEASE SAVEPOINT __rivet_on_migrate",
144
+ params: undefined,
145
+ },
146
+ ]);
147
+ });
148
+
149
+ test("runs transaction work under one hidden lease", async () => {
150
+ const nativeDb = new FakeSqliteDatabase();
151
+ const provider = db();
152
+ const client = await provider.createClient(
153
+ testProviderContext(nativeDb),
154
+ );
155
+
156
+ const value = await client.transaction(async (tx) => {
157
+ await tx.execute("INSERT INTO items(value) VALUES (?)", "inside");
158
+ return 42;
159
+ });
160
+
161
+ expect(value).toBe(42);
162
+ expect(nativeDb.executeCalls.map((call) => call.sql)).toEqual([
163
+ "BEGIN",
164
+ "INSERT INTO items(value) VALUES (?)",
165
+ "COMMIT",
166
+ ]);
167
+ const keys = nativeDb.executeCalls.map((call) => call.lease?.key);
168
+ expect(keys.every((key) => key === keys[0] && key !== undefined)).toBe(
169
+ true,
170
+ );
104
171
  });
105
172
  });