rivetkit 0.0.0-sqlite-profiling-compat.4a9a623 → 0.0.0-sqlite-sync-3-0-0-release.14341d0

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 +1433 -692
  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-AGDY6TKH.js → chunk-2EQ2WCO7.js} +1054 -364
  19. package/dist/tsup/chunk-2EQ2WCO7.js.map +1 -0
  20. package/dist/tsup/{chunk-7QKCGUTJ.cjs → chunk-4H2LT2WB.cjs} +444 -29
  21. package/dist/tsup/chunk-4H2LT2WB.cjs.map +1 -0
  22. package/dist/tsup/{chunk-XIX5DOZN.js → chunk-6FEYCVZC.js} +196 -20
  23. package/dist/tsup/chunk-6FEYCVZC.js.map +1 -0
  24. package/dist/tsup/{chunk-QAVN4QNO.cjs → chunk-6WYQ3NJI.cjs} +7 -7
  25. package/dist/tsup/chunk-6WYQ3NJI.cjs.map +1 -0
  26. package/dist/tsup/{chunk-75UE45DE.js → chunk-6ZJX3KXW.js} +436 -21
  27. package/dist/tsup/chunk-6ZJX3KXW.js.map +1 -0
  28. package/dist/tsup/{chunk-HXUEHHJF.js → chunk-A2CF6PFH.js} +19 -11
  29. package/dist/tsup/chunk-A2CF6PFH.js.map +1 -0
  30. package/dist/tsup/{chunk-RIT7N3TX.js → chunk-AIGW2SKA.js} +50 -3
  31. package/dist/tsup/chunk-AIGW2SKA.js.map +1 -0
  32. package/dist/tsup/{chunk-3MHDOUD7.cjs → chunk-HDVZ6YZG.cjs} +197 -21
  33. package/dist/tsup/chunk-HDVZ6YZG.cjs.map +1 -0
  34. package/dist/tsup/{chunk-2CICCOBL.cjs → chunk-HU4F7H3F.cjs} +52 -5
  35. package/dist/tsup/chunk-HU4F7H3F.cjs.map +1 -0
  36. package/dist/tsup/{chunk-4PX3ZKJR.js → chunk-JNJEWQZL.js} +3 -3
  37. package/dist/tsup/chunk-JNJEWQZL.js.map +1 -0
  38. package/dist/tsup/{chunk-JZ7TWV65.js → chunk-JTHHCZCZ.js} +24 -1
  39. package/dist/tsup/chunk-JTHHCZCZ.js.map +1 -0
  40. package/dist/tsup/{chunk-ZA7FLHKH.cjs → chunk-KVFIONKQ.cjs} +25 -2
  41. package/dist/tsup/chunk-KVFIONKQ.cjs.map +1 -0
  42. package/dist/tsup/{chunk-4FC7TVS6.cjs → chunk-MGI2VVF6.cjs} +39 -7
  43. package/dist/tsup/chunk-MGI2VVF6.cjs.map +1 -0
  44. package/dist/tsup/{chunk-NHUTYWKU.cjs → chunk-NE5CUQRN.cjs} +1173 -483
  45. package/dist/tsup/chunk-NE5CUQRN.cjs.map +1 -0
  46. package/dist/tsup/{chunk-IICIOTML.js → chunk-OX5MX7TO.js} +2 -2
  47. package/dist/tsup/{chunk-ND567FR5.cjs → chunk-PSIBTOAR.cjs} +3 -3
  48. package/dist/tsup/chunk-PSIBTOAR.cjs.map +1 -0
  49. package/dist/tsup/chunk-PW6FYEIV.cjs +14 -0
  50. package/dist/tsup/chunk-PW6FYEIV.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-SLICBKAU.js +14 -0
  54. package/dist/tsup/chunk-SLICBKAU.js.map +1 -0
  55. package/dist/tsup/{chunk-XFYEVYHG.js → chunk-WCVYMFWJ.js} +16 -9
  56. package/dist/tsup/chunk-WCVYMFWJ.js.map +1 -0
  57. package/dist/tsup/chunk-WX3JS4XU.cjs +243 -0
  58. package/dist/tsup/chunk-WX3JS4XU.cjs.map +1 -0
  59. package/dist/tsup/chunk-X32L7FDD.js +243 -0
  60. package/dist/tsup/chunk-X32L7FDD.js.map +1 -0
  61. package/dist/tsup/{chunk-2WMYYG4R.cjs → chunk-XAY2HIZN.cjs} +18 -11
  62. package/dist/tsup/chunk-XAY2HIZN.cjs.map +1 -0
  63. package/dist/tsup/{chunk-ZZ3WBRPD.js → chunk-ZOVJDAOW.js} +38 -6
  64. package/dist/tsup/chunk-ZOVJDAOW.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.ts → config-BfG1qpYz.d.cts} +80 -14
  80. package/dist/tsup/{config-B0LNDrLY.d.cts → 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-oc9zhA3x.d.ts → context-Cvnf3BRe.d.cts} +3 -2
  83. package/dist/tsup/{context-D4WDwf9m.d.cts → 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 +2728 -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 +2645 -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 +178 -25
  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 +29 -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 +54 -61
  211. package/src/registry/index.ts +324 -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-2CICCOBL.cjs.map +0 -1
  230. package/dist/tsup/chunk-2WMYYG4R.cjs.map +0 -1
  231. package/dist/tsup/chunk-3MHDOUD7.cjs.map +0 -1
  232. package/dist/tsup/chunk-4FC7TVS6.cjs.map +0 -1
  233. package/dist/tsup/chunk-4PX3ZKJR.js.map +0 -1
  234. package/dist/tsup/chunk-75UE45DE.js.map +0 -1
  235. package/dist/tsup/chunk-7QKCGUTJ.cjs.map +0 -1
  236. package/dist/tsup/chunk-AGDY6TKH.js.map +0 -1
  237. package/dist/tsup/chunk-HXUEHHJF.js.map +0 -1
  238. package/dist/tsup/chunk-JZ7TWV65.js.map +0 -1
  239. package/dist/tsup/chunk-ND567FR5.cjs.map +0 -1
  240. package/dist/tsup/chunk-NHUTYWKU.cjs.map +0 -1
  241. package/dist/tsup/chunk-QAVN4QNO.cjs.map +0 -1
  242. package/dist/tsup/chunk-RIT7N3TX.js.map +0 -1
  243. package/dist/tsup/chunk-RV5MAFDT.cjs +0 -382
  244. package/dist/tsup/chunk-RV5MAFDT.cjs.map +0 -1
  245. package/dist/tsup/chunk-VE2X4KMG.cjs.map +0 -1
  246. package/dist/tsup/chunk-XFYEVYHG.js.map +0 -1
  247. package/dist/tsup/chunk-XHGDS3DZ.js +0 -382
  248. package/dist/tsup/chunk-XHGDS3DZ.js.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-IICIOTML.js.map → chunk-OX5MX7TO.js.map} +0 -0
@@ -1,250 +0,0 @@
1
- /**
2
- * Node.js runtime health metrics.
3
- *
4
- * Collects JS-internal data (event loop lag, GC, heap, libuv handles,
5
- * event loop utilization, CPU) using Node built-ins (`node:perf_hooks`,
6
- * `process`, `node:v8`, `PerformanceObserver`) and pushes them across NAPI
7
- * into Rust-side prometheus collectors registered with
8
- * `rivet_metrics::REGISTRY` so they appear on the existing `/metrics`
9
- * endpoint.
10
- *
11
- * All data collection happens here in TypeScript. The NAPI bridge is pure
12
- * type marshalling and the Rust side only registers + stores the metrics.
13
- */
14
- import {
15
- monitorEventLoopDelay,
16
- PerformanceObserver,
17
- performance,
18
- } from "node:perf_hooks";
19
- import { getHeapStatistics } from "node:v8";
20
- import * as napi from "@rivetkit/rivetkit-napi";
21
-
22
- type OptionalProcessMetricsNapi = typeof napi & {
23
- jsObserveGcDuration?: (kind: string, durationSeconds: number) => void;
24
- jsSetEventloopHeartbeatTsMs?: (timestampMs: number) => void;
25
- jsSetEventloopLagQuantile?: (
26
- quantile: string,
27
- valueSeconds: number,
28
- ) => void;
29
- jsSetEventloopUtilization?: (utilization: number) => void;
30
- jsAddProcessCpuSeconds?: (mode: string, valueSeconds: number) => void;
31
- jsSetProcessResidentMemoryBytes?: (bytes: number) => void;
32
- jsSetHeapBytes?: (kind: string, bytes: number) => void;
33
- jsSetActiveHandles?: (count: number) => void;
34
- jsSetActiveRequests?: (count: number) => void;
35
- };
36
-
37
- type GcPerformanceEntry = {
38
- duration: number;
39
- detail?: { kind?: number };
40
- kind?: number;
41
- };
42
-
43
- const processMetricsNapi = napi as OptionalProcessMetricsNapi;
44
-
45
- // Some napi process-metrics symbols may be missing on older native binaries
46
- // (the auto-generated index.js destructures them as `undefined` if the
47
- // underlying `.node` was built before they were added). Guard each call so
48
- // the metrics collection runs as a no-op instead of throwing
49
- // `TypeError: napi.jsXxx is not a function` on every interval tick.
50
- function callIfFn<T extends unknown[]>(
51
- fn: ((...args: T) => void) | undefined,
52
- ...args: T
53
- ): void {
54
- if (typeof fn === "function") {
55
- fn(...args);
56
- }
57
- }
58
-
59
- const SCRAPE_INTERVAL_MS = 5_000;
60
- const HEARTBEAT_INTERVAL_MS = 100;
61
- const EVENTLOOP_DELAY_RESOLUTION_MS = 20;
62
- const NS_PER_SECOND = 1e9;
63
- const US_PER_SECOND = 1e6;
64
-
65
- // V8 GC kind bitfield from Node's perf_hooks documentation. A `gc` performance
66
- // entry's `kind` field is one of these values.
67
- const GC_KIND_NAMES: Record<number, string> = {
68
- 1: "minor",
69
- 2: "major",
70
- 4: "incremental",
71
- 8: "weakcb",
72
- };
73
-
74
- interface ProcessMetricsState {
75
- scrapeInterval: NodeJS.Timeout;
76
- heartbeatInterval: NodeJS.Timeout;
77
- gcObserver: PerformanceObserver;
78
- eventLoopHistogram: ReturnType<typeof monitorEventLoopDelay>;
79
- lastCpuUsage: NodeJS.CpuUsage;
80
- lastEventLoopUtilization: ReturnType<
81
- typeof performance.eventLoopUtilization
82
- >;
83
- }
84
-
85
- let state: ProcessMetricsState | undefined;
86
-
87
- export function startProcessMetrics(): void {
88
- if (state) {
89
- return;
90
- }
91
-
92
- const eventLoopHistogram = monitorEventLoopDelay({
93
- resolution: EVENTLOOP_DELAY_RESOLUTION_MS,
94
- });
95
- eventLoopHistogram.enable();
96
-
97
- const gcObserver = new PerformanceObserver((list) => {
98
- for (const entry of list.getEntries()) {
99
- const gcEntry = entry as GcPerformanceEntry;
100
- const kind = gcEntry.detail?.kind ?? gcEntry.kind;
101
- if (typeof kind !== "number") continue;
102
- const kindName = GC_KIND_NAMES[kind];
103
- if (!kindName) continue;
104
- // `entry.duration` is in milliseconds; convert to seconds.
105
- callIfFn(
106
- processMetricsNapi.jsObserveGcDuration,
107
- kindName,
108
- gcEntry.duration / 1000,
109
- );
110
- }
111
- });
112
- gcObserver.observe({ entryTypes: ["gc"], buffered: false });
113
-
114
- const lastCpuUsage = process.cpuUsage();
115
- const lastEventLoopUtilization = performance.eventLoopUtilization();
116
-
117
- const heartbeatInterval = setInterval(() => {
118
- callIfFn(processMetricsNapi.jsSetEventloopHeartbeatTsMs, Date.now());
119
- }, HEARTBEAT_INTERVAL_MS);
120
- heartbeatInterval.unref();
121
-
122
- const scrapeInterval = setInterval(() => {
123
- try {
124
- collectAndPush();
125
- } catch {
126
- // Collection errors must never bring down the process; metrics
127
- // are best-effort.
128
- }
129
- }, SCRAPE_INTERVAL_MS);
130
- scrapeInterval.unref();
131
-
132
- state = {
133
- scrapeInterval,
134
- heartbeatInterval,
135
- gcObserver,
136
- eventLoopHistogram,
137
- lastCpuUsage,
138
- lastEventLoopUtilization,
139
- };
140
-
141
- // Emit one snapshot immediately so freshly-scraped instances have data.
142
- callIfFn(processMetricsNapi.jsSetEventloopHeartbeatTsMs, Date.now());
143
- try {
144
- collectAndPush();
145
- } catch {
146
- // As above; best-effort.
147
- }
148
- }
149
-
150
- export function stopProcessMetrics(): void {
151
- if (!state) {
152
- return;
153
- }
154
- clearInterval(state.scrapeInterval);
155
- clearInterval(state.heartbeatInterval);
156
- state.gcObserver.disconnect();
157
- state.eventLoopHistogram.disable();
158
- state = undefined;
159
- }
160
-
161
- function collectAndPush(): void {
162
- if (!state) return;
163
-
164
- // Event loop delay quantiles. `monitorEventLoopDelay()` reports values in
165
- // nanoseconds; convert to seconds. Reset after reading so the next window
166
- // reflects only the new interval.
167
- const hist = state.eventLoopHistogram;
168
- callIfFn(
169
- processMetricsNapi.jsSetEventloopLagQuantile,
170
- "p50",
171
- hist.percentile(50) / NS_PER_SECOND,
172
- );
173
- callIfFn(
174
- processMetricsNapi.jsSetEventloopLagQuantile,
175
- "p90",
176
- hist.percentile(90) / NS_PER_SECOND,
177
- );
178
- callIfFn(
179
- processMetricsNapi.jsSetEventloopLagQuantile,
180
- "p99",
181
- hist.percentile(99) / NS_PER_SECOND,
182
- );
183
- callIfFn(
184
- processMetricsNapi.jsSetEventloopLagQuantile,
185
- "max",
186
- hist.max / NS_PER_SECOND,
187
- );
188
- hist.reset();
189
-
190
- // Event loop utilization delta over the scrape window.
191
- const nextElu = performance.eventLoopUtilization();
192
- const eluDelta = performance.eventLoopUtilization(
193
- nextElu,
194
- state.lastEventLoopUtilization,
195
- );
196
- state.lastEventLoopUtilization = nextElu;
197
- callIfFn(
198
- processMetricsNapi.jsSetEventloopUtilization,
199
- eluDelta.utilization,
200
- );
201
-
202
- // CPU usage delta. `process.cpuUsage()` returns microseconds.
203
- const nextCpu = process.cpuUsage();
204
- const userDeltaUs = nextCpu.user - state.lastCpuUsage.user;
205
- const systemDeltaUs = nextCpu.system - state.lastCpuUsage.system;
206
- state.lastCpuUsage = nextCpu;
207
- if (userDeltaUs > 0) {
208
- callIfFn(
209
- processMetricsNapi.jsAddProcessCpuSeconds,
210
- "user",
211
- userDeltaUs / US_PER_SECOND,
212
- );
213
- }
214
- if (systemDeltaUs > 0) {
215
- callIfFn(
216
- processMetricsNapi.jsAddProcessCpuSeconds,
217
- "system",
218
- systemDeltaUs / US_PER_SECOND,
219
- );
220
- }
221
-
222
- // Memory + heap.
223
- const mem = process.memoryUsage();
224
- callIfFn(processMetricsNapi.jsSetProcessResidentMemoryBytes, mem.rss);
225
- callIfFn(processMetricsNapi.jsSetHeapBytes, "used", mem.heapUsed);
226
- callIfFn(processMetricsNapi.jsSetHeapBytes, "total", mem.heapTotal);
227
- const heapLimit = getHeapStatistics().heap_size_limit;
228
- callIfFn(processMetricsNapi.jsSetHeapBytes, "limit", heapLimit);
229
-
230
- // libuv active handles + requests. These are unstable Node internals
231
- // guarded behind underscore-prefixed names; if a future Node release
232
- // removes them the try/catch above keeps the rest of the collection
233
- // alive.
234
- const proc = process as unknown as {
235
- _getActiveHandles?: () => unknown[];
236
- _getActiveRequests?: () => unknown[];
237
- };
238
- if (typeof proc._getActiveHandles === "function") {
239
- callIfFn(
240
- processMetricsNapi.jsSetActiveHandles,
241
- proc._getActiveHandles().length,
242
- );
243
- }
244
- if (typeof proc._getActiveRequests === "function") {
245
- callIfFn(
246
- processMetricsNapi.jsSetActiveRequests,
247
- proc._getActiveRequests().length,
248
- );
249
- }
250
- }
@@ -1,50 +0,0 @@
1
- import { describe, expect, test } from "vitest";
2
- import {
3
- normalizeRuntimeSqlExecuteResult,
4
- type RuntimeSqlBindParam,
5
- type RuntimeSqlBindParams,
6
- } from "./runtime";
7
-
8
- describe("runtime SQL boundary", () => {
9
- test("accepts exact bind param variants", () => {
10
- const blob = new Uint8Array([1, 2, 3]);
11
- const params = [
12
- { kind: "null" },
13
- { kind: "int", intValue: 1 },
14
- { kind: "float", floatValue: 1.5 },
15
- { kind: "text", textValue: "text" },
16
- { kind: "blob", blobValue: blob },
17
- ] satisfies RuntimeSqlBindParams;
18
-
19
- expect(params).toEqual([
20
- { kind: "null" },
21
- { kind: "int", intValue: 1 },
22
- { kind: "float", floatValue: 1.5 },
23
- { kind: "text", textValue: "text" },
24
- { kind: "blob", blobValue: blob },
25
- ]);
26
- });
27
-
28
- test("rejects bind params with mismatched value fields at typecheck time", () => {
29
- const invalidIntParamCandidate = {
30
- kind: "int",
31
- intValue: 1,
32
- textValue: "extra",
33
- } as const;
34
- // @ts-expect-error Runtime SQL int params must only carry intValue.
35
- const invalidIntParam: RuntimeSqlBindParam = invalidIntParamCandidate;
36
-
37
- expect(invalidIntParam.kind).toBe("int");
38
- });
39
-
40
- test("normalizes execute result metadata", () => {
41
- const base = {
42
- columns: ["value"],
43
- rows: [[1]],
44
- changes: 1,
45
- lastInsertRowId: null,
46
- };
47
-
48
- expect(normalizeRuntimeSqlExecuteResult(base)).toEqual(base);
49
- });
50
- });
@@ -1,206 +0,0 @@
1
- import { describe, expect, test } from "vitest";
2
- import type { z } from "zod/v4";
3
- import { tryParseEndpoint } from "./endpoint-parser";
4
-
5
- // Helper to create a mock Zod refinement context for testing
6
- function createMockCtx(): { ctx: z.RefinementCtx; issues: z.ZodIssue[] } {
7
- const issues: z.ZodIssue[] = [];
8
- const ctx = {
9
- addIssue: (issue: z.IssueData) => {
10
- issues.push(issue as z.ZodIssue);
11
- },
12
- path: [],
13
- value: undefined,
14
- issues: [],
15
- } as unknown as z.RefinementCtx;
16
- return { ctx, issues };
17
- }
18
-
19
- describe("tryParseEndpoint", () => {
20
- describe("basic parsing", () => {
21
- test("parses endpoint with full auth", () => {
22
- const { ctx, issues } = createMockCtx();
23
- const result = tryParseEndpoint(ctx, {
24
- endpoint: "https://foo:bar@api.rivet.dev",
25
- });
26
- expect(issues).toHaveLength(0);
27
- expect(result).toEqual({
28
- endpoint: "https://api.rivet.dev/",
29
- namespace: "foo",
30
- token: "bar",
31
- });
32
- });
33
-
34
- test("parses endpoint with namespace only", () => {
35
- const { ctx, issues } = createMockCtx();
36
- const result = tryParseEndpoint(ctx, {
37
- endpoint: "https://foo@api.rivet.dev",
38
- });
39
- expect(issues).toHaveLength(0);
40
- expect(result).toEqual({
41
- endpoint: "https://api.rivet.dev/",
42
- namespace: "foo",
43
- token: undefined,
44
- });
45
- });
46
-
47
- test("parses endpoint without auth", () => {
48
- const { ctx, issues } = createMockCtx();
49
- const result = tryParseEndpoint(ctx, {
50
- endpoint: "https://api.rivet.dev",
51
- });
52
- expect(issues).toHaveLength(0);
53
- expect(result).toEqual({
54
- endpoint: "https://api.rivet.dev/",
55
- namespace: undefined,
56
- token: undefined,
57
- });
58
- });
59
-
60
- test("preserves path", () => {
61
- const { ctx, issues } = createMockCtx();
62
- const result = tryParseEndpoint(ctx, {
63
- endpoint: "https://foo:bar@api.rivet.dev/v1/actors",
64
- });
65
- expect(issues).toHaveLength(0);
66
- expect(result).toEqual({
67
- endpoint: "https://api.rivet.dev/v1/actors",
68
- namespace: "foo",
69
- token: "bar",
70
- });
71
- });
72
- });
73
-
74
- describe("validation errors", () => {
75
- test("adds issue for invalid URL", () => {
76
- const { ctx, issues } = createMockCtx();
77
- const result = tryParseEndpoint(ctx, { endpoint: "not-a-url" });
78
- expect(result).toBeUndefined();
79
- expect(issues).toHaveLength(1);
80
- expect(issues[0]?.message).toContain("invalid URL");
81
- });
82
-
83
- test("adds issue for query string", () => {
84
- const { ctx, issues } = createMockCtx();
85
- const result = tryParseEndpoint(ctx, {
86
- endpoint: "https://foo:bar@api.rivet.dev?region=us",
87
- });
88
- expect(result).toBeUndefined();
89
- expect(issues).toHaveLength(1);
90
- expect(issues[0]?.message).toBe(
91
- "endpoint cannot contain a query string",
92
- );
93
- });
94
-
95
- test("adds issue for fragment", () => {
96
- const { ctx, issues } = createMockCtx();
97
- const result = tryParseEndpoint(ctx, {
98
- endpoint: "https://foo:bar@api.rivet.dev#section",
99
- });
100
- expect(result).toBeUndefined();
101
- expect(issues).toHaveLength(1);
102
- expect(issues[0]?.message).toBe(
103
- "endpoint cannot contain a fragment",
104
- );
105
- });
106
-
107
- test("adds issue for token without namespace", () => {
108
- const { ctx, issues } = createMockCtx();
109
- const result = tryParseEndpoint(ctx, {
110
- endpoint: "https://:token@api.rivet.dev",
111
- });
112
- expect(result).toBeUndefined();
113
- expect(issues).toHaveLength(1);
114
- expect(issues[0]?.message).toBe(
115
- "endpoint cannot have a token without a namespace",
116
- );
117
- });
118
- });
119
-
120
- describe("duplicate credential checking", () => {
121
- test("adds issue when namespace in URL and config", () => {
122
- const { ctx, issues } = createMockCtx();
123
- const result = tryParseEndpoint(ctx, {
124
- endpoint: "https://url-ns@api.rivet.dev",
125
- path: ["endpoint"],
126
- namespace: "config-ns",
127
- });
128
- // Still returns result, but adds issue
129
- expect(result).toEqual({
130
- endpoint: "https://api.rivet.dev/",
131
- namespace: "url-ns",
132
- token: undefined,
133
- });
134
- expect(issues).toHaveLength(1);
135
- expect(issues[0]?.message).toContain(
136
- "cannot specify namespace both in endpoint URL and as a separate config option",
137
- );
138
- expect(issues[0]?.path).toEqual(["namespace"]);
139
- });
140
-
141
- test("adds issue when token in URL and config", () => {
142
- const { ctx, issues } = createMockCtx();
143
- const result = tryParseEndpoint(ctx, {
144
- endpoint: "https://ns:url-token@api.rivet.dev",
145
- path: ["endpoint"],
146
- token: "config-token",
147
- });
148
- // Still returns result, but adds issue
149
- expect(result).toEqual({
150
- endpoint: "https://api.rivet.dev/",
151
- namespace: "ns",
152
- token: "url-token",
153
- });
154
- expect(issues).toHaveLength(1);
155
- expect(issues[0]?.message).toContain(
156
- "cannot specify token both in endpoint URL and as a separate config option",
157
- );
158
- expect(issues[0]?.path).toEqual(["token"]);
159
- });
160
-
161
- test("adds issues for both namespace and token duplicates", () => {
162
- const { ctx, issues } = createMockCtx();
163
- const result = tryParseEndpoint(ctx, {
164
- endpoint: "https://url-ns:url-token@api.rivet.dev",
165
- path: ["endpoint"],
166
- namespace: "config-ns",
167
- token: "config-token",
168
- });
169
- expect(result).toBeDefined();
170
- expect(issues).toHaveLength(2);
171
- });
172
-
173
- test("no issue when namespace only in URL", () => {
174
- const { ctx, issues } = createMockCtx();
175
- const result = tryParseEndpoint(ctx, {
176
- endpoint: "https://url-ns@api.rivet.dev",
177
- path: ["endpoint"],
178
- token: "config-token",
179
- });
180
- expect(result).toBeDefined();
181
- expect(issues).toHaveLength(0);
182
- });
183
-
184
- test("no issue when namespace only in config", () => {
185
- const { ctx, issues } = createMockCtx();
186
- const result = tryParseEndpoint(ctx, {
187
- endpoint: "https://api.rivet.dev",
188
- path: ["endpoint"],
189
- namespace: "config-ns",
190
- });
191
- expect(result).toBeDefined();
192
- expect(issues).toHaveLength(0);
193
- });
194
- });
195
-
196
- describe("custom path", () => {
197
- test("uses custom path in error issues", () => {
198
- const { ctx, issues } = createMockCtx();
199
- tryParseEndpoint(ctx, {
200
- endpoint: "not-a-url",
201
- path: ["serverless", "publicEndpoint"],
202
- });
203
- expect(issues[0]?.path).toEqual(["serverless", "publicEndpoint"]);
204
- });
205
- });
206
- });
package/src/utils.test.ts DELETED
@@ -1,34 +0,0 @@
1
- import { describe, expect, test } from "vitest";
2
- import { joinSignals } from "./utils";
3
-
4
- describe("joinSignals", () => {
5
- test("returns a non-aborted signal when no inputs are provided", () => {
6
- const signal = joinSignals();
7
- expect(signal.aborted).toBe(false);
8
- });
9
-
10
- test("returns the same signal when only one input is provided", () => {
11
- const controller = new AbortController();
12
- const signal = joinSignals(controller.signal);
13
- expect(signal).toBe(controller.signal);
14
- });
15
-
16
- test("aborts immediately when any input signal is already aborted", () => {
17
- const controllerA = new AbortController();
18
- const controllerB = new AbortController();
19
- controllerA.abort("already-aborted");
20
-
21
- const signal = joinSignals(controllerA.signal, controllerB.signal);
22
- expect(signal.aborted).toBe(true);
23
- });
24
-
25
- test("aborts when one of the joined signals aborts", () => {
26
- const controllerA = new AbortController();
27
- const controllerB = new AbortController();
28
- const signal = joinSignals(controllerA.signal, controllerB.signal);
29
-
30
- expect(signal.aborted).toBe(false);
31
- controllerB.abort("stopped");
32
- expect(signal.aborted).toBe(true);
33
- });
34
- });