rivetkit 0.0.0-sqlite-profiling-compat.87d61c0 → 0.0.0-sqlite-sync-3x-release.a00b07f

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 (277) hide show
  1. package/dist/browser/client.d.ts +1317 -765
  2. package/dist/browser/client.js +1457 -737
  3. package/dist/browser/client.js.map +1 -1
  4. package/dist/browser/inspector/client.d.ts +252 -129
  5. package/dist/browser/inspector/client.js +2042 -228
  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 -1
  10. package/dist/tsup/actor/errors.d.ts +1 -1
  11. package/dist/tsup/actor/errors.js +5 -1
  12. package/dist/tsup/agent-os/index.cjs +3 -2367
  13. package/dist/tsup/agent-os/index.cjs.map +1 -1
  14. package/dist/tsup/agent-os/index.d.cts +1 -2277
  15. package/dist/tsup/agent-os/index.d.ts +1 -2277
  16. package/dist/tsup/agent-os/index.js +3 -2367
  17. package/dist/tsup/agent-os/index.js.map +1 -1
  18. package/dist/tsup/{chunk-E4LNLI3W.cjs → chunk-2MOLY6AM.cjs} +444 -29
  19. package/dist/tsup/chunk-2MOLY6AM.cjs.map +1 -0
  20. package/dist/tsup/{chunk-OAUFXOG7.js → chunk-3DONDAMG.js} +2 -2
  21. package/dist/tsup/{chunk-XIX5DOZN.js → chunk-6FEYCVZC.js} +196 -20
  22. package/dist/tsup/chunk-6FEYCVZC.js.map +1 -0
  23. package/dist/tsup/chunk-6KXVLIXL.cjs +14 -0
  24. package/dist/tsup/chunk-6KXVLIXL.cjs.map +1 -0
  25. package/dist/tsup/chunk-73RNTXHB.cjs +243 -0
  26. package/dist/tsup/chunk-73RNTXHB.cjs.map +1 -0
  27. package/dist/tsup/{chunk-HXUEHHJF.js → chunk-A2CF6PFH.js} +19 -11
  28. package/dist/tsup/chunk-A2CF6PFH.js.map +1 -0
  29. package/dist/tsup/{chunk-EFU4JW3T.js → chunk-BRH4PQS5.js} +436 -21
  30. package/dist/tsup/chunk-BRH4PQS5.js.map +1 -0
  31. package/dist/tsup/{chunk-GM45LG7L.cjs → chunk-BTSDFFDC.cjs} +18 -11
  32. package/dist/tsup/chunk-BTSDFFDC.cjs.map +1 -0
  33. package/dist/tsup/{chunk-B3GLD4IN.js → chunk-D5WUPE47.js} +50 -3
  34. package/dist/tsup/chunk-D5WUPE47.js.map +1 -0
  35. package/dist/tsup/{chunk-O3ZUMAN7.js → chunk-DJUBJQEQ.js} +3 -3
  36. package/dist/tsup/chunk-DJUBJQEQ.js.map +1 -0
  37. package/dist/tsup/{chunk-3MHDOUD7.cjs → chunk-HDVZ6YZG.cjs} +197 -21
  38. package/dist/tsup/chunk-HDVZ6YZG.cjs.map +1 -0
  39. package/dist/tsup/{chunk-JZ7TWV65.js → chunk-JTHHCZCZ.js} +24 -1
  40. package/dist/tsup/chunk-JTHHCZCZ.js.map +1 -0
  41. package/dist/tsup/{chunk-D363DMNH.cjs → chunk-JUHXV3HF.cjs} +3 -3
  42. package/dist/tsup/chunk-JUHXV3HF.cjs.map +1 -0
  43. package/dist/tsup/chunk-JUWMP5O3.js +14 -0
  44. package/dist/tsup/chunk-JUWMP5O3.js.map +1 -0
  45. package/dist/tsup/{chunk-ZA7FLHKH.cjs → chunk-KVFIONKQ.cjs} +25 -2
  46. package/dist/tsup/chunk-KVFIONKQ.cjs.map +1 -0
  47. package/dist/tsup/{chunk-4FC7TVS6.cjs → chunk-MGI2VVF6.cjs} +39 -7
  48. package/dist/tsup/chunk-MGI2VVF6.cjs.map +1 -0
  49. package/dist/tsup/{chunk-BWERJMV6.cjs → chunk-OTVJYZ2L.cjs} +1139 -470
  50. package/dist/tsup/chunk-OTVJYZ2L.cjs.map +1 -0
  51. package/dist/tsup/{chunk-VE2X4KMG.cjs → chunk-RTWH3AX3.cjs} +18 -10
  52. package/dist/tsup/chunk-RTWH3AX3.cjs.map +1 -0
  53. package/dist/tsup/{chunk-DTRDGPHU.cjs → chunk-TM76Z7XT.cjs} +7 -7
  54. package/dist/tsup/chunk-TM76Z7XT.cjs.map +1 -0
  55. package/dist/tsup/{chunk-3GVMLSND.js → chunk-TRUHDXOU.js} +1023 -354
  56. package/dist/tsup/chunk-TRUHDXOU.js.map +1 -0
  57. package/dist/tsup/{chunk-PT7AC5PC.js → chunk-TSQTI6H6.js} +16 -9
  58. package/dist/tsup/chunk-TSQTI6H6.js.map +1 -0
  59. package/dist/tsup/{chunk-FNAXD5BQ.cjs → chunk-Z7E2G3JZ.cjs} +52 -5
  60. package/dist/tsup/chunk-Z7E2G3JZ.cjs.map +1 -0
  61. package/dist/tsup/{chunk-ZZ3WBRPD.js → chunk-ZOVJDAOW.js} +38 -6
  62. package/dist/tsup/chunk-ZOVJDAOW.js.map +1 -0
  63. package/dist/tsup/chunk-ZYK4B5WV.js +243 -0
  64. package/dist/tsup/chunk-ZYK4B5WV.js.map +1 -0
  65. package/dist/tsup/client/mod.cjs +8 -9
  66. package/dist/tsup/client/mod.cjs.map +1 -1
  67. package/dist/tsup/client/mod.d.cts +32 -6
  68. package/dist/tsup/client/mod.d.ts +32 -6
  69. package/dist/tsup/client/mod.js +7 -8
  70. package/dist/tsup/common/log.cjs +5 -3
  71. package/dist/tsup/common/log.cjs.map +1 -1
  72. package/dist/tsup/common/log.d.cts +5 -1
  73. package/dist/tsup/common/log.d.ts +5 -1
  74. package/dist/tsup/common/log.js +6 -4
  75. package/dist/tsup/common/websocket.cjs +4 -4
  76. package/dist/tsup/common/websocket.cjs.map +1 -1
  77. package/dist/tsup/common/websocket.js +3 -3
  78. package/dist/tsup/{config-BR1Nn0QQ.d.ts → config-B4erdavw.d.ts} +571 -65
  79. package/dist/tsup/{config-B0LNDrLY.d.cts → config-BfG1qpYz.d.cts} +80 -14
  80. package/dist/tsup/{config-B0LNDrLY.d.ts → config-BfG1qpYz.d.ts} +80 -14
  81. package/dist/tsup/{config-tCvkwzyN.d.cts → config-DK144OAw.d.cts} +571 -65
  82. package/dist/tsup/{context-D4WDwf9m.d.cts → context-Cvnf3BRe.d.cts} +3 -2
  83. package/dist/tsup/{context-oc9zhA3x.d.ts → context-Oxi6YWcG.d.ts} +3 -2
  84. package/dist/tsup/db/drizzle.cjs +127 -67
  85. package/dist/tsup/db/drizzle.cjs.map +1 -1
  86. package/dist/tsup/db/drizzle.d.cts +8 -4
  87. package/dist/tsup/db/drizzle.d.ts +8 -4
  88. package/dist/tsup/db/drizzle.js +127 -67
  89. package/dist/tsup/db/drizzle.js.map +1 -1
  90. package/dist/tsup/db/mod.cjs +6 -126
  91. package/dist/tsup/db/mod.cjs.map +1 -1
  92. package/dist/tsup/db/mod.d.cts +8 -4
  93. package/dist/tsup/db/mod.d.ts +8 -4
  94. package/dist/tsup/db/mod.js +5 -125
  95. package/dist/tsup/db/mod.js.map +1 -1
  96. package/dist/tsup/dynamic/mod.cjs +2 -2
  97. package/dist/tsup/dynamic/mod.cjs.map +1 -1
  98. package/dist/tsup/dynamic/mod.d.cts +6 -4
  99. package/dist/tsup/dynamic/mod.d.ts +6 -4
  100. package/dist/tsup/dynamic/mod.js +1 -1
  101. package/dist/tsup/inspector/mod.cjs +47 -12
  102. package/dist/tsup/inspector/mod.cjs.map +1 -1
  103. package/dist/tsup/inspector/mod.d.cts +26 -136
  104. package/dist/tsup/inspector/mod.d.ts +26 -136
  105. package/dist/tsup/inspector/mod.js +46 -11
  106. package/dist/tsup/inspector/mod.js.map +1 -1
  107. package/dist/tsup/inspector/workflow.cjs +21 -0
  108. package/dist/tsup/inspector/workflow.cjs.map +1 -0
  109. package/dist/tsup/inspector/workflow.d.cts +144 -0
  110. package/dist/tsup/inspector/workflow.d.ts +144 -0
  111. package/dist/tsup/inspector/workflow.js +21 -0
  112. package/dist/tsup/inspector/workflow.js.map +1 -0
  113. package/dist/tsup/inspector-tab/mod.cjs +2 -13
  114. package/dist/tsup/inspector-tab/mod.cjs.map +1 -1
  115. package/dist/tsup/inspector-tab/mod.d.cts +9 -17
  116. package/dist/tsup/inspector-tab/mod.d.ts +9 -17
  117. package/dist/tsup/inspector-tab/mod.js +1 -12
  118. package/dist/tsup/inspector-tab/mod.js.map +1 -1
  119. package/dist/tsup/mod.cjs +2724 -611
  120. package/dist/tsup/mod.cjs.map +1 -1
  121. package/dist/tsup/mod.d.cts +9 -7
  122. package/dist/tsup/mod.d.ts +9 -7
  123. package/dist/tsup/mod.js +2641 -528
  124. package/dist/tsup/mod.js.map +1 -1
  125. package/dist/tsup/test/mod.cjs +19 -17
  126. package/dist/tsup/test/mod.cjs.map +1 -1
  127. package/dist/tsup/test/mod.d.cts +6 -4
  128. package/dist/tsup/test/mod.d.ts +6 -4
  129. package/dist/tsup/test/mod.js +18 -16
  130. package/dist/tsup/test/mod.js.map +1 -1
  131. package/dist/tsup/unstable/migrations.cjs +101 -0
  132. package/dist/tsup/unstable/migrations.cjs.map +1 -0
  133. package/dist/tsup/unstable/migrations.d.cts +29 -0
  134. package/dist/tsup/unstable/migrations.d.ts +29 -0
  135. package/dist/tsup/unstable/migrations.js +101 -0
  136. package/dist/tsup/unstable/migrations.js.map +1 -0
  137. package/dist/tsup/{utils-CqDnC_PS.d.cts → utils-3rsE0JvI.d.cts} +25 -2
  138. package/dist/tsup/{utils-CqDnC_PS.d.ts → utils-3rsE0JvI.d.ts} +25 -2
  139. package/dist/tsup/utils-C1O-SklO.d.ts +162 -0
  140. package/dist/tsup/utils-C6b0aYUM.d.cts +162 -0
  141. package/dist/tsup/utils.cjs +7 -3
  142. package/dist/tsup/utils.cjs.map +1 -1
  143. package/dist/tsup/utils.d.cts +4 -147
  144. package/dist/tsup/utils.d.ts +4 -147
  145. package/dist/tsup/utils.js +6 -2
  146. package/dist/tsup/workflow/mod.cjs +260 -200
  147. package/dist/tsup/workflow/mod.cjs.map +1 -1
  148. package/dist/tsup/workflow/mod.d.cts +8 -6
  149. package/dist/tsup/workflow/mod.d.ts +8 -6
  150. package/dist/tsup/workflow/mod.js +249 -189
  151. package/dist/tsup/workflow/mod.js.map +1 -1
  152. package/package.json +34 -14
  153. package/src/actor/actions.ts +155 -0
  154. package/src/actor/config.ts +403 -43
  155. package/src/actor/definition.ts +26 -7
  156. package/src/actor/errors.ts +87 -5
  157. package/src/actor/keys.ts +86 -0
  158. package/src/actor/mod.ts +15 -1
  159. package/src/actor/tracing.ts +28 -0
  160. package/src/agent-os/index.ts +5 -65
  161. package/src/client/actor-common.ts +8 -15
  162. package/src/client/actor-conn.ts +135 -8
  163. package/src/client/actor-handle.ts +180 -42
  164. package/src/client/actor-query.ts +8 -1
  165. package/src/client/auth.ts +37 -0
  166. package/src/client/client.ts +89 -21
  167. package/src/client/config.ts +27 -2
  168. package/src/client/errors.ts +2 -1
  169. package/src/client/lifecycle-errors.ts +16 -1
  170. package/src/client/mod.ts +9 -0
  171. package/src/client/outbound-telemetry.ts +66 -0
  172. package/src/client/query.ts +2 -0
  173. package/src/client/queue.ts +3 -0
  174. package/src/client/raw-utils.ts +37 -8
  175. package/src/client/resolve-gateway-target.ts +2 -0
  176. package/src/client/retry-budget.ts +78 -0
  177. package/src/client/token-provider.ts +93 -0
  178. package/src/client/utils.ts +16 -2
  179. package/src/common/actor-router-consts.ts +5 -0
  180. package/src/common/actor-telemetry-context.ts +19 -0
  181. package/src/common/bare/generated/actor-runtime-socket-protocol/v1.ts +848 -0
  182. package/src/common/bare/generated/inspector/v5.ts +1016 -0
  183. package/src/common/bare/generated/inspector/v6.ts +1367 -0
  184. package/src/common/bare/transport/v1.ts +36 -0
  185. package/src/common/database/config.ts +108 -15
  186. package/src/common/database/mod.ts +247 -76
  187. package/src/common/database/native-database.ts +433 -23
  188. package/src/common/database/shared.ts +24 -0
  189. package/src/common/encoding.ts +31 -21
  190. package/src/common/fetch-like.ts +63 -0
  191. package/src/common/inspector-transport.ts +12 -2
  192. package/src/common/log.ts +14 -8
  193. package/src/common/otel-context.ts +99 -0
  194. package/src/common/router.ts +1 -1
  195. package/src/common/utils.ts +7 -19
  196. package/src/db/drizzle.ts +182 -80
  197. package/src/db/mod.ts +2 -0
  198. package/src/dynamic/isolate-runtime.ts +0 -2
  199. package/src/engine-api/actors.ts +3 -3
  200. package/src/engine-client/actor-http-client.ts +29 -20
  201. package/src/engine-client/actor-websocket-client.ts +6 -3
  202. package/src/engine-client/api-endpoints.ts +72 -14
  203. package/src/engine-client/driver.ts +8 -15
  204. package/src/engine-client/mod.ts +248 -112
  205. package/src/inspector/client.browser.ts +134 -16
  206. package/src/inspector/mod.ts +1 -1
  207. package/src/inspector/workflow.ts +61 -0
  208. package/src/inspector-tab/mod.ts +1 -15
  209. package/src/registry/config/envoy.ts +2 -18
  210. package/src/registry/config/index.ts +53 -61
  211. package/src/registry/index.ts +311 -21
  212. package/src/registry/napi-runtime.ts +583 -39
  213. package/src/registry/native-http.ts +225 -0
  214. package/src/registry/native.ts +1365 -414
  215. package/src/registry/run-handler-coordinator.ts +219 -0
  216. package/src/registry/runtime.ts +372 -7
  217. package/src/registry/wasm-runtime.ts +490 -21
  218. package/src/registry/write-through-proxy.ts +101 -0
  219. package/src/test/mod.ts +1 -19
  220. package/src/test/ready.ts +22 -0
  221. package/src/unstable/migrations.ts +141 -0
  222. package/src/utils/env-vars.ts +15 -6
  223. package/src/utils/node.ts +44 -28
  224. package/src/utils.ts +3 -0
  225. package/src/workflow/context.ts +9 -27
  226. package/src/workflow/driver.ts +253 -116
  227. package/src/workflow/inspector.ts +23 -24
  228. package/src/workflow/mod.ts +50 -72
  229. package/dist/tsup/chunk-3GVMLSND.js.map +0 -1
  230. package/dist/tsup/chunk-3MHDOUD7.cjs.map +0 -1
  231. package/dist/tsup/chunk-4FC7TVS6.cjs.map +0 -1
  232. package/dist/tsup/chunk-B3GLD4IN.js.map +0 -1
  233. package/dist/tsup/chunk-BWERJMV6.cjs.map +0 -1
  234. package/dist/tsup/chunk-D363DMNH.cjs.map +0 -1
  235. package/dist/tsup/chunk-DTRDGPHU.cjs.map +0 -1
  236. package/dist/tsup/chunk-E4LNLI3W.cjs.map +0 -1
  237. package/dist/tsup/chunk-EFU4JW3T.js.map +0 -1
  238. package/dist/tsup/chunk-FNAXD5BQ.cjs.map +0 -1
  239. package/dist/tsup/chunk-GM45LG7L.cjs.map +0 -1
  240. package/dist/tsup/chunk-HXUEHHJF.js.map +0 -1
  241. package/dist/tsup/chunk-JZ7TWV65.js.map +0 -1
  242. package/dist/tsup/chunk-O3ZUMAN7.js.map +0 -1
  243. package/dist/tsup/chunk-P6F5MEWX.cjs +0 -382
  244. package/dist/tsup/chunk-P6F5MEWX.cjs.map +0 -1
  245. package/dist/tsup/chunk-PT7AC5PC.js.map +0 -1
  246. package/dist/tsup/chunk-UV7INX3N.js +0 -382
  247. package/dist/tsup/chunk-UV7INX3N.js.map +0 -1
  248. package/dist/tsup/chunk-VE2X4KMG.cjs.map +0 -1
  249. package/dist/tsup/chunk-XIX5DOZN.js.map +0 -1
  250. package/dist/tsup/chunk-ZA7FLHKH.cjs.map +0 -1
  251. package/dist/tsup/chunk-ZZ3WBRPD.js.map +0 -1
  252. package/src/actor/driver.ts +0 -141
  253. package/src/actor/instance/mod.ts +0 -2484
  254. package/src/actor/keys.test.ts +0 -275
  255. package/src/actor/utils.test.ts +0 -48
  256. package/src/agent-os/actor/cron.ts +0 -84
  257. package/src/agent-os/actor/db.ts +0 -54
  258. package/src/agent-os/actor/filesystem.ts +0 -131
  259. package/src/agent-os/actor/index.ts +0 -285
  260. package/src/agent-os/actor/network.ts +0 -58
  261. package/src/agent-os/actor/preview.ts +0 -190
  262. package/src/agent-os/actor/process.ts +0 -177
  263. package/src/agent-os/actor/session.ts +0 -518
  264. package/src/agent-os/actor/shell.ts +0 -60
  265. package/src/agent-os/config.ts +0 -79
  266. package/src/agent-os/fs/database-vfs.ts +0 -624
  267. package/src/agent-os/types.ts +0 -148
  268. package/src/client/test.ts +0 -44
  269. package/src/common/database/mod.test.ts +0 -137
  270. package/src/common/database/native-database.test.ts +0 -211
  271. package/src/common/inline-websocket-adapter.test.ts +0 -51
  272. package/src/drivers/engine/actor-driver.ts +0 -2473
  273. package/src/registry/process-metrics.ts +0 -250
  274. package/src/registry/runtime.test.ts +0 -50
  275. package/src/utils/endpoint-parser.test.ts +0 -206
  276. package/src/utils.test.ts +0 -34
  277. /package/dist/tsup/{chunk-OAUFXOG7.js.map → chunk-3DONDAMG.js.map} +0 -0
@@ -521,6 +521,28 @@ export function writeWorkflowRemovedEntry(
521
521
  write1(bc, x.originalName);
522
522
  }
523
523
 
524
+ export type WorkflowVersionCheckEntry = {
525
+ readonly resolved: u32;
526
+ readonly latest: u32;
527
+ };
528
+
529
+ export function readWorkflowVersionCheckEntry(
530
+ bc: bare.ByteCursor,
531
+ ): WorkflowVersionCheckEntry {
532
+ return {
533
+ resolved: bare.readU32(bc),
534
+ latest: bare.readU32(bc),
535
+ };
536
+ }
537
+
538
+ export function writeWorkflowVersionCheckEntry(
539
+ bc: bare.ByteCursor,
540
+ x: WorkflowVersionCheckEntry,
541
+ ): void {
542
+ bare.writeU32(bc, x.resolved);
543
+ bare.writeU32(bc, x.latest);
544
+ }
545
+
524
546
  export type WorkflowEntryKind =
525
547
  | { readonly tag: "WorkflowStepEntry"; readonly val: WorkflowStepEntry }
526
548
  | { readonly tag: "WorkflowLoopEntry"; readonly val: WorkflowLoopEntry }
@@ -538,6 +560,10 @@ export type WorkflowEntryKind =
538
560
  | {
539
561
  readonly tag: "WorkflowRemovedEntry";
540
562
  readonly val: WorkflowRemovedEntry;
563
+ }
564
+ | {
565
+ readonly tag: "WorkflowVersionCheckEntry";
566
+ readonly val: WorkflowVersionCheckEntry;
541
567
  };
542
568
 
543
569
  export function readWorkflowEntryKind(bc: bare.ByteCursor): WorkflowEntryKind {
@@ -572,6 +598,11 @@ export function readWorkflowEntryKind(bc: bare.ByteCursor): WorkflowEntryKind {
572
598
  tag: "WorkflowRemovedEntry",
573
599
  val: readWorkflowRemovedEntry(bc),
574
600
  };
601
+ case 8:
602
+ return {
603
+ tag: "WorkflowVersionCheckEntry",
604
+ val: readWorkflowVersionCheckEntry(bc),
605
+ };
575
606
  default: {
576
607
  bc.offset = offset;
577
608
  throw new bare.BareError(offset, "invalid tag");
@@ -624,6 +655,11 @@ export function writeWorkflowEntryKind(
624
655
  writeWorkflowRemovedEntry(bc, x.val);
625
656
  break;
626
657
  }
658
+ case "WorkflowVersionCheckEntry": {
659
+ bare.writeU8(bc, 8);
660
+ writeWorkflowVersionCheckEntry(bc, x.val);
661
+ break;
662
+ }
627
663
  }
628
664
  }
629
665
 
@@ -9,17 +9,56 @@ export interface ActorMetricsLike {
9
9
  export type InferDatabaseClient<DBProvider extends AnyDatabaseProvider> =
10
10
  DBProvider extends DatabaseProvider<any>
11
11
  ? Awaited<ReturnType<DBProvider["createClient"]>>
12
- : never;
12
+ : RawAccess;
13
13
 
14
14
  export type SqliteBindings = unknown[] | Record<string, unknown>;
15
15
 
16
+ export interface SqliteQueryResult {
17
+ columns: string[];
18
+ rows: unknown[][];
19
+ }
20
+
21
+ export interface SqliteExecuteResult extends SqliteQueryResult {
22
+ changes: number;
23
+ lastInsertRowId?: number | null;
24
+ }
25
+
26
+ export interface SqliteBatchStatement {
27
+ sql: string;
28
+ params?: SqliteBindings;
29
+ }
30
+
31
+ export interface SqliteTransactionOptions {
32
+ /** Static operation name used to aggregate transaction performance. */
33
+ name?: string;
34
+ /** Deadlock-safety timeout in milliseconds. */
35
+ timeout?: number;
36
+ /** @experimental */
37
+ experimental?: {
38
+ /**
39
+ * Atomically includes actor and hibernatable connection state.
40
+ * Only single-statement `execute` calls are supported in the transaction.
41
+ * Concurrent actions that try to mutate state while the transaction is
42
+ * active fail with `actor.state_transaction_conflict`.
43
+ */
44
+ includeState?: boolean;
45
+ };
46
+ }
47
+
16
48
  /**
17
- * SQLite profiling controls.
49
+ * SQLite profiling configuration.
18
50
  *
19
- * @experimental This entire configuration surface is subject to change.
51
+ * @experimental This entire configuration surface is experimental and subject
52
+ * to change without notice.
20
53
  */
21
54
  export interface SqliteProfilingOptions {
22
- enabled?: boolean;
55
+ /** Exact SQL statements to give fingerprint labels. Profiling defaults to actor
56
+ * aggregates without fingerprint labels. Profile logs remain enabled.
57
+ * RIVETKIT_SQLITE_PROFILING overrides selection with a JSON object containing
58
+ * queries and/or fingerprints arrays. An empty object clears fingerprint selection. */
59
+ queries?: string[];
60
+ /** Exact query fingerprints to label separately, as reported in profile logs. */
61
+ fingerprints?: string[];
23
62
  maxTrackedStatementFingerprints?: number;
24
63
  maxTrackedTransactionFingerprints?: number;
25
64
  maxPrometheusSeries?: number;
@@ -32,16 +71,6 @@ export interface SqliteProfilingOptions {
32
71
  diagnosticEventQueueCapacity?: number;
33
72
  }
34
73
 
35
- export interface SqliteQueryResult {
36
- columns: string[];
37
- rows: unknown[][];
38
- }
39
-
40
- export interface SqliteExecuteResult extends SqliteQueryResult {
41
- changes: number;
42
- lastInsertRowId?: number | null;
43
- }
44
-
45
74
  export interface SqliteNativeMetrics {
46
75
  requestBuildNs: number;
47
76
  serializeNs: number;
@@ -61,16 +90,72 @@ export interface SqliteDatabase {
61
90
  sql: string,
62
91
  callback?: (row: unknown[], columns: string[]) => void,
63
92
  ): Promise<void>;
93
+ execSync?(
94
+ sql: string,
95
+ callback?: (row: unknown[], columns: string[]) => void,
96
+ ): void;
64
97
  execute(sql: string, params?: SqliteBindings): Promise<SqliteExecuteResult>;
98
+ executeSync?(sql: string, params?: SqliteBindings): SqliteExecuteResult;
99
+ executeBatch(
100
+ statements: SqliteBatchStatement[],
101
+ ): Promise<SqliteExecuteResult[]>;
102
+ beginTransaction(
103
+ timeoutMs?: number,
104
+ name?: string,
105
+ ): Promise<SqliteTransactionDatabase>;
106
+ beginTransactionSync?(
107
+ timeoutMs?: number,
108
+ name?: string,
109
+ ): SynchronousSqliteTransactionDatabase;
65
110
  run(sql: string, params?: SqliteBindings): Promise<void>;
66
111
  query(sql: string, params?: SqliteBindings): Promise<SqliteQueryResult>;
67
112
  nativeMetrics?():
68
113
  | SqliteNativeMetrics
69
114
  | Promise<SqliteNativeMetrics | null>
70
115
  | null;
116
+ /**
117
+ * Returns the ticket of the latest local commit. Synchronous writes return before they are
118
+ * durable; pass the ticket to `whenDurable` before releasing output that depends on them.
119
+ */
120
+ commitTicket?(): number;
121
+ /**
122
+ * Resolves once the commit `ticket` names and every earlier commit are durable. Rejects with
123
+ * `sqlite.durability_failed` once the database broke and the actor is restarting.
124
+ */
125
+ whenDurable?(ticket: number): Promise<void>;
126
+ /**
127
+ * Restarts the owning actor from durable state. Every later write fails, including the final
128
+ * state save. For native database providers whose in-memory state can no longer be trusted.
129
+ */
130
+ abortGeneration?(reason: string): void;
71
131
  close(): Promise<void>;
72
132
  }
73
133
 
134
+ export interface SqliteTransactionDatabase {
135
+ exec(
136
+ sql: string,
137
+ callback?: (row: unknown[], columns: string[]) => void,
138
+ ): Promise<void>;
139
+ execSync?(
140
+ sql: string,
141
+ callback?: (row: unknown[], columns: string[]) => void,
142
+ ): void;
143
+ execute(sql: string, params?: SqliteBindings): Promise<SqliteExecuteResult>;
144
+ executeSync?(sql: string, params?: SqliteBindings): SqliteExecuteResult;
145
+ commit(): Promise<void>;
146
+ rollback(): Promise<void>;
147
+ }
148
+
149
+ export type SynchronousSqliteTransactionDatabase = SqliteTransactionDatabase & {
150
+ execSync(
151
+ sql: string,
152
+ callback?: (row: unknown[], columns: string[]) => void,
153
+ ): void;
154
+ executeSync(sql: string, params?: SqliteBindings): SqliteExecuteResult;
155
+ commitSync(): void;
156
+ rollbackSync(): void;
157
+ };
158
+
74
159
  /**
75
160
  * Provider for opening native databases from the active runtime.
76
161
  */
@@ -122,7 +207,10 @@ export interface DatabaseProviderContext {
122
207
 
123
208
  export type DatabaseProvider<DB extends RawAccess> = {
124
209
  /**
125
- * @experimental This entire configuration surface is subject to change.
210
+ * Local SQLite profiling controls consumed by the actor runtime.
211
+ *
212
+ * @experimental This entire configuration surface is experimental and
213
+ * subject to change without notice.
126
214
  */
127
215
  sqliteProfiling?: SqliteProfilingOptions;
128
216
  /**
@@ -166,6 +254,11 @@ export type RawAccess = {
166
254
  * Executes a raw SQL query.
167
255
  */
168
256
  execute: ExecuteFunction;
257
+ /** Runs a callback in an isolated SQLite transaction. */
258
+ transaction: <T>(
259
+ callback: (tx: RawAccess) => Promise<T> | T,
260
+ options?: SqliteTransactionOptions,
261
+ ) => Promise<T>;
169
262
  /**
170
263
  * Returns native SQLite metrics when the active runtime supports them.
171
264
  */
@@ -1,20 +1,79 @@
1
+ import { getLogger } from "@/common/log";
1
2
  import type {
2
3
  DatabaseProvider,
4
+ NativeDatabaseProvider,
3
5
  RawAccess,
4
6
  SqliteDatabase,
5
7
  SqliteProfilingOptions,
8
+ SqliteTransactionDatabase,
9
+ SqliteTransactionOptions,
6
10
  } from "./config";
7
- import { isSqliteBindingObject, toSqliteBindings } from "./shared";
11
+ import {
12
+ isManualTransactionControl,
13
+ isSqliteBindingObject,
14
+ MIGRATION_TRANSACTION_TIMEOUT_MS,
15
+ toSqliteBindings,
16
+ validateTransactionName,
17
+ validateTransactionTimeout,
18
+ } from "./shared";
8
19
 
9
20
  export type { RawAccess } from "./config";
10
21
 
11
22
  export interface DatabaseFactoryConfig {
12
23
  onMigrate?: (db: RawAccess) => Promise<void> | void;
24
+ warnOnManualTransactions?: boolean;
13
25
  /**
14
- * @experimental This entire configuration surface is subject to change.
26
+ * SQLite profiling configuration.
27
+ *
28
+ * @experimental This entire configuration surface is experimental and
29
+ * subject to change without notice.
15
30
  */
16
31
  profiling?: SqliteProfilingOptions;
17
32
  }
33
+ const nativeStateTransactionOpeners = new WeakMap<
34
+ NativeDatabaseProvider,
35
+ (
36
+ timeoutMs?: number,
37
+ context?: unknown,
38
+ ) => Promise<SqliteTransactionDatabase>
39
+ >();
40
+ type NativeStateTransactionContext = {
41
+ enter(): Promise<unknown>;
42
+ exit(scope: unknown): void;
43
+ };
44
+ const nativeStateTransactionClientBinders = new WeakMap<
45
+ object,
46
+ (context: NativeStateTransactionContext) => object
47
+ >();
48
+
49
+ /** @internal */
50
+ export function registerNativeStateTransactionOpener<
51
+ T extends NativeDatabaseProvider,
52
+ >(
53
+ provider: T,
54
+ opener: (
55
+ timeoutMs?: number,
56
+ context?: unknown,
57
+ ) => Promise<SqliteTransactionDatabase>,
58
+ ): T {
59
+ nativeStateTransactionOpeners.set(provider, opener);
60
+ return provider;
61
+ }
62
+
63
+ /** @internal */
64
+ export function bindNativeStateTransactionContext<T>(
65
+ client: T,
66
+ context: NativeStateTransactionContext,
67
+ ): T {
68
+ if (
69
+ (typeof client !== "object" || client === null) &&
70
+ typeof client !== "function"
71
+ ) {
72
+ return client;
73
+ }
74
+ const bind = nativeStateTransactionClientBinders.get(client as object);
75
+ return (bind?.(context) ?? client) as T;
76
+ }
18
77
 
19
78
  function hasMultipleStatements(query: string): boolean {
20
79
  const trimmed = query.trim().replace(/;+$/, "").trimEnd();
@@ -23,9 +82,10 @@ function hasMultipleStatements(query: string): boolean {
23
82
 
24
83
  export function db({
25
84
  onMigrate,
85
+ warnOnManualTransactions = true,
26
86
  profiling,
27
87
  }: DatabaseFactoryConfig = {}): DatabaseProvider<RawAccess> {
28
- return {
88
+ const provider: DatabaseProvider<RawAccess> = {
29
89
  sqliteProfiling: profiling,
30
90
  createClient: async (ctx) => {
31
91
  const nativeDatabaseProvider = ctx.nativeDatabaseProvider;
@@ -37,6 +97,7 @@ export function db({
37
97
 
38
98
  const db = await nativeDatabaseProvider.open(ctx.actorId);
39
99
  let closed = false;
100
+ let manualTransactionWarned = false;
40
101
  const ensureOpen = () => {
41
102
  if (closed) {
42
103
  throw new Error(
@@ -45,80 +106,176 @@ export function db({
45
106
  }
46
107
  };
47
108
 
48
- const client: RawAccess = {
49
- execute: async <
50
- TRow extends Record<string, unknown> = Record<
51
- string,
52
- unknown
53
- >,
54
- >(
55
- query: string,
56
- ...args: unknown[]
57
- ): Promise<TRow[]> => {
58
- ensureOpen();
109
+ const createClient = (
110
+ target: SqliteDatabase | SqliteTransactionDatabase,
111
+ transactionScoped = false,
112
+ stateTransactionContext?: NativeStateTransactionContext,
113
+ ): RawAccess => {
114
+ const client: RawAccess = {
115
+ execute: async <
116
+ TRow extends Record<string, unknown> = Record<
117
+ string,
118
+ unknown
119
+ >,
120
+ >(
121
+ query: string,
122
+ ...args: unknown[]
123
+ ): Promise<TRow[]> => {
124
+ ensureOpen();
125
+ if (
126
+ !transactionScoped &&
127
+ warnOnManualTransactions &&
128
+ !manualTransactionWarned &&
129
+ !hasMultipleStatements(query) &&
130
+ isManualTransactionControl(query)
131
+ ) {
132
+ manualTransactionWarned = true;
133
+ getLogger("database").warn(
134
+ { actorId: ctx.actorId },
135
+ "Manual cross-call SQLite transactions can interleave with other actor work. Use db.transaction() for coordinated transactions. Set warnOnManualTransactions: false in your db(...) configuration to disable this warning.",
136
+ );
137
+ }
59
138
 
60
- const kvReadsBefore = ctx.metrics?.totalKvReads ?? 0;
61
- const kvWritesBefore = ctx.metrics?.totalKvWrites ?? 0;
62
- const start = performance.now();
139
+ const kvReadsBefore = ctx.metrics?.totalKvReads ?? 0;
140
+ const kvWritesBefore = ctx.metrics?.totalKvWrites ?? 0;
141
+ const start = performance.now();
63
142
 
64
- try {
65
- if (args.length > 0) {
66
- const bindings =
67
- args.length === 1 &&
68
- isSqliteBindingObject(args[0])
69
- ? toSqliteBindings(args[0])
70
- : toSqliteBindings(args);
71
- const { rows, columns } = await db.execute(
143
+ try {
144
+ if (args.length > 0) {
145
+ const bindings =
146
+ args.length === 1 &&
147
+ isSqliteBindingObject(args[0])
148
+ ? toSqliteBindings(args[0])
149
+ : toSqliteBindings(args);
150
+ const { rows, columns } = await target.execute(
151
+ query,
152
+ bindings,
153
+ );
154
+ return rows.map((row) =>
155
+ rowToObject<TRow>(row, columns),
156
+ );
157
+ }
158
+
159
+ if (!hasMultipleStatements(query)) {
160
+ const { rows, columns } = await target.execute(
161
+ query,
162
+ undefined,
163
+ );
164
+ return rows.map((row) =>
165
+ rowToObject<TRow>(row, columns),
166
+ );
167
+ }
168
+
169
+ return await execMultiStatement<TRow>(
170
+ target,
72
171
  query,
73
- bindings,
74
- );
75
- return rows.map((row) =>
76
- rowToObject<TRow>(row, columns),
77
172
  );
173
+ } finally {
174
+ const durationMs = performance.now() - start;
175
+ ctx.metrics?.trackSql(query, durationMs);
176
+ if (ctx.metrics) {
177
+ const kvReads =
178
+ ctx.metrics.totalKvReads - kvReadsBefore;
179
+ const kvWrites =
180
+ ctx.metrics.totalKvWrites - kvWritesBefore;
181
+ ctx.log?.debug({
182
+ msg: "sql query",
183
+ query: query.slice(0, 120),
184
+ durationMs,
185
+ kvReads,
186
+ kvWrites,
187
+ });
188
+ }
78
189
  }
79
-
80
- if (!hasMultipleStatements(query)) {
81
- const { rows, columns } = await db.execute(query);
82
- return rows.map((row) =>
83
- rowToObject<TRow>(row, columns),
190
+ },
191
+ transaction: async <T>(
192
+ callback: (tx: RawAccess) => Promise<T> | T,
193
+ options?: SqliteTransactionOptions,
194
+ ): Promise<T> => {
195
+ validateTransactionTimeout(options?.timeout);
196
+ validateTransactionName(options?.name);
197
+ if (
198
+ transactionScoped &&
199
+ options?.experimental?.includeState
200
+ ) {
201
+ throw new Error(
202
+ "experimental.includeState is not supported for nested transactions",
84
203
  );
85
204
  }
86
-
87
- return await execMultiStatement<TRow>(db, query);
88
- } finally {
89
- const durationMs = performance.now() - start;
90
- ctx.metrics?.trackSql(query, durationMs);
91
- if (ctx.metrics) {
92
- const kvReads =
93
- ctx.metrics.totalKvReads - kvReadsBefore;
94
- const kvWrites =
95
- ctx.metrics.totalKvWrites - kvWritesBefore;
96
- ctx.log?.debug({
97
- msg: "sql query",
98
- query: query.slice(0, 120),
99
- durationMs,
100
- kvReads,
101
- kvWrites,
102
- });
205
+ const includeState =
206
+ options?.experimental?.includeState === true;
207
+ const stateScope =
208
+ includeState && stateTransactionContext
209
+ ? await stateTransactionContext.enter()
210
+ : undefined;
211
+ try {
212
+ const transaction = includeState
213
+ ? await (() => {
214
+ const beginStateTransaction =
215
+ ctx.nativeDatabaseProvider &&
216
+ nativeStateTransactionOpeners.get(
217
+ ctx.nativeDatabaseProvider,
218
+ );
219
+ if (!beginStateTransaction) {
220
+ throw new Error(
221
+ "experimental.includeState is only supported by RivetKit's embedded database provider",
222
+ );
223
+ }
224
+ return beginStateTransaction(
225
+ options?.timeout,
226
+ stateScope,
227
+ );
228
+ })()
229
+ : await db.beginTransaction(
230
+ options?.timeout,
231
+ options?.name,
232
+ );
233
+ const tx = createClient(transaction, true);
234
+ try {
235
+ const result = await callback(tx);
236
+ await transaction.commit();
237
+ return result;
238
+ } catch (error) {
239
+ try {
240
+ await transaction.rollback();
241
+ } catch {
242
+ // Preserve the callback or commit error after expiry cleanup.
243
+ }
244
+ throw error;
245
+ }
246
+ } finally {
247
+ if (stateScope !== undefined) {
248
+ stateTransactionContext?.exit(stateScope);
249
+ }
250
+ }
251
+ },
252
+ close: async () => {
253
+ if (!closed) {
254
+ closed = true;
255
+ await db.close();
103
256
  }
104
- }
105
- },
106
- close: async () => {
107
- if (!closed) {
108
- closed = true;
109
- await db.close();
110
- }
111
- },
112
- nativeMetrics: () => db.nativeMetrics?.() ?? null,
257
+ },
258
+ nativeMetrics: () => db.nativeMetrics?.() ?? null,
259
+ };
260
+ if (!transactionScoped) {
261
+ nativeStateTransactionClientBinders.set(client, (context) =>
262
+ createClient(target, false, context),
263
+ );
264
+ }
265
+ return client;
113
266
  };
267
+ const client = createClient(db);
114
268
  return client;
115
269
  },
116
270
  onMigrate: async (client) => {
117
271
  if (onMigrate) {
118
- await withMigrationSavepoint(client, () => onMigrate(client));
272
+ await withMigrationSavepoint(client, (leased) =>
273
+ onMigrate(leased),
274
+ );
119
275
  }
120
276
  },
121
277
  };
278
+ return provider;
122
279
  }
123
280
 
124
281
  function rowToObject<TRow extends Record<string, unknown>>(
@@ -133,7 +290,7 @@ function rowToObject<TRow extends Record<string, unknown>>(
133
290
  }
134
291
 
135
292
  async function execMultiStatement<TRow extends Record<string, unknown>>(
136
- db: SqliteDatabase,
293
+ db: Pick<SqliteDatabase, "exec">,
137
294
  query: string,
138
295
  ): Promise<TRow[]> {
139
296
  const results: Record<string, unknown>[] = [];
@@ -149,19 +306,33 @@ async function execMultiStatement<TRow extends Record<string, unknown>>(
149
306
 
150
307
  async function withMigrationSavepoint<T>(
151
308
  client: RawAccess,
152
- callback: () => Promise<T> | T,
309
+ callback: (leased: RawAccess) => Promise<T> | T,
153
310
  ): Promise<T> {
154
- await client.execute("SAVEPOINT __rivet_on_migrate");
155
- try {
156
- const result = await callback();
157
- await client.execute("RELEASE SAVEPOINT __rivet_on_migrate");
158
- return result;
159
- } catch (error) {
160
- try {
161
- await client.execute("ROLLBACK TO SAVEPOINT __rivet_on_migrate");
162
- } finally {
163
- await client.execute("RELEASE SAVEPOINT __rivet_on_migrate");
164
- }
165
- throw error;
166
- }
311
+ return await client.transaction(
312
+ async (transaction) => {
313
+ await transaction.execute("SAVEPOINT __rivet_on_migrate");
314
+ try {
315
+ const result = await callback(transaction);
316
+ await transaction.execute(
317
+ "RELEASE SAVEPOINT __rivet_on_migrate",
318
+ );
319
+ return result;
320
+ } catch (error) {
321
+ try {
322
+ await transaction.execute(
323
+ "ROLLBACK TO SAVEPOINT __rivet_on_migrate",
324
+ );
325
+ } finally {
326
+ await transaction.execute(
327
+ "RELEASE SAVEPOINT __rivet_on_migrate",
328
+ );
329
+ }
330
+ throw error;
331
+ }
332
+ },
333
+ {
334
+ name: "rivetkit-migration",
335
+ timeout: MIGRATION_TRANSACTION_TIMEOUT_MS,
336
+ },
337
+ );
167
338
  }