rivetkit 0.0.0-main.41efcce → 0.0.0-main.49693dc
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.
- package/dist/browser/client.d.ts +939 -104
- package/dist/browser/client.js +1867 -900
- package/dist/browser/client.js.map +1 -1
- package/dist/browser/inspector/client.d.ts +252 -129
- package/dist/browser/inspector/client.js +2079 -233
- package/dist/browser/inspector/client.js.map +1 -1
- package/dist/tsup/actor/errors.cjs +6 -2
- package/dist/tsup/actor/errors.cjs.map +1 -1
- package/dist/tsup/actor/errors.d.cts +1 -74
- package/dist/tsup/actor/errors.d.ts +1 -74
- package/dist/tsup/actor/errors.js +5 -1
- package/dist/tsup/agent-os/index.cjs +2408 -2029
- package/dist/tsup/agent-os/index.cjs.map +1 -1
- package/dist/tsup/agent-os/index.d.cts +932 -114
- package/dist/tsup/agent-os/index.d.ts +932 -114
- package/dist/tsup/agent-os/index.js +2412 -2033
- package/dist/tsup/agent-os/index.js.map +1 -1
- package/dist/tsup/{chunk-J27CEW6F.js → chunk-2OBVQZX6.js} +6 -6
- package/dist/tsup/chunk-2OBVQZX6.js.map +1 -0
- package/dist/tsup/chunk-3ZWHWMFJ.js +14 -0
- package/dist/tsup/chunk-3ZWHWMFJ.js.map +1 -0
- package/dist/tsup/{chunk-AK57AL7S.cjs → chunk-4KGXFC6M.cjs} +238 -22
- package/dist/tsup/chunk-4KGXFC6M.cjs.map +1 -0
- package/dist/tsup/{chunk-CVHUXINE.js → chunk-5IU3MI7X.js} +594 -72
- package/dist/tsup/chunk-5IU3MI7X.js.map +1 -0
- package/dist/tsup/{chunk-VD7AZIBR.js → chunk-6CXQMHZR.js} +1161 -361
- package/dist/tsup/chunk-6CXQMHZR.js.map +1 -0
- package/dist/tsup/{chunk-SBEFJ4IQ.js → chunk-6W2UIH3X.js} +70 -8
- package/dist/tsup/chunk-6W2UIH3X.js.map +1 -0
- package/dist/tsup/{chunk-7MRGNVSR.js → chunk-6W5VGLFT.js} +237 -21
- package/dist/tsup/chunk-6W5VGLFT.js.map +1 -0
- package/dist/tsup/{chunk-RF3MEJV6.cjs → chunk-B73TBMMG.cjs} +18 -11
- package/dist/tsup/chunk-B73TBMMG.cjs.map +1 -0
- package/dist/tsup/chunk-D6TORRA4.js +243 -0
- package/dist/tsup/chunk-D6TORRA4.js.map +1 -0
- package/dist/tsup/{chunk-PXLJOMJD.js → chunk-FXT3HN32.js} +2 -2
- package/dist/tsup/{chunk-ZGWSH7YV.js → chunk-IXBD7BXC.js} +48 -72
- package/dist/tsup/chunk-IXBD7BXC.js.map +1 -0
- package/dist/tsup/{chunk-3BFYSYRU.js → chunk-JI6GZ2C2.js} +4 -12
- package/dist/tsup/chunk-JI6GZ2C2.js.map +1 -0
- package/dist/tsup/{chunk-PCBNKI2J.js → chunk-JTHHCZCZ.js} +24 -1
- package/dist/tsup/chunk-JTHHCZCZ.js.map +1 -0
- package/dist/tsup/{chunk-2NDZ7JCR.cjs → chunk-KVFIONKQ.cjs} +25 -2
- package/dist/tsup/chunk-KVFIONKQ.cjs.map +1 -0
- package/dist/tsup/{chunk-SPMMF6TR.cjs → chunk-LGOWPZJ5.cjs} +3 -3
- package/dist/tsup/chunk-LGOWPZJ5.cjs.map +1 -0
- package/dist/tsup/chunk-LYNWTX6R.cjs +14 -0
- package/dist/tsup/chunk-LYNWTX6R.cjs.map +1 -0
- package/dist/tsup/{chunk-LLD2D5LO.cjs → chunk-MYWZCDML.cjs} +4 -12
- package/dist/tsup/chunk-MYWZCDML.cjs.map +1 -0
- package/dist/tsup/{chunk-XSC2WWXD.js → chunk-NYDZLWHZ.js} +16 -9
- package/dist/tsup/chunk-NYDZLWHZ.js.map +1 -0
- package/dist/tsup/{chunk-AV54CVAG.cjs → chunk-RB7WUDX6.cjs} +1290 -490
- package/dist/tsup/chunk-RB7WUDX6.cjs.map +1 -0
- package/dist/tsup/{chunk-JTL6Y2UN.cjs → chunk-SPJORZMM.cjs} +49 -73
- package/dist/tsup/chunk-SPJORZMM.cjs.map +1 -0
- package/dist/tsup/chunk-SSMKIYEX.cjs +243 -0
- package/dist/tsup/chunk-SSMKIYEX.cjs.map +1 -0
- package/dist/tsup/{chunk-TQSL4NJ3.cjs → chunk-TQ4HSX2U.cjs} +72 -10
- package/dist/tsup/chunk-TQ4HSX2U.cjs.map +1 -0
- package/dist/tsup/{chunk-EVADNK6Z.cjs → chunk-U6ZQELGJ.cjs} +10 -10
- package/dist/tsup/chunk-U6ZQELGJ.cjs.map +1 -0
- package/dist/tsup/chunk-XLBMKZD3.cjs +1257 -0
- package/dist/tsup/chunk-XLBMKZD3.cjs.map +1 -0
- package/dist/tsup/client/mod.cjs +8 -9
- package/dist/tsup/client/mod.cjs.map +1 -1
- package/dist/tsup/client/mod.d.cts +18 -7
- package/dist/tsup/client/mod.d.ts +18 -7
- package/dist/tsup/client/mod.js +7 -8
- package/dist/tsup/common/log.cjs +5 -3
- package/dist/tsup/common/log.cjs.map +1 -1
- package/dist/tsup/common/log.d.cts +5 -1
- package/dist/tsup/common/log.d.ts +5 -1
- package/dist/tsup/common/log.js +6 -4
- package/dist/tsup/common/websocket.cjs +4 -4
- package/dist/tsup/common/websocket.cjs.map +1 -1
- package/dist/tsup/common/websocket.js +3 -3
- package/dist/tsup/{config-B3RIidaJ.d.ts → config-BXSV17G7.d.cts} +987 -72
- package/dist/tsup/{config-D6WxBYjV.d.cts → config-Bi1r6gI7.d.ts} +987 -72
- package/dist/tsup/{config-B9qUIHX4.d.ts → config-ey2I2zz5.d.cts} +82 -15
- package/dist/tsup/{config-B9qUIHX4.d.cts → config-ey2I2zz5.d.ts} +82 -15
- package/dist/tsup/context-4fJemY0D.d.cts +129 -0
- package/dist/tsup/context-D4sNYboo.d.ts +129 -0
- package/dist/tsup/db/drizzle.cjs +168 -103
- package/dist/tsup/db/drizzle.cjs.map +1 -1
- package/dist/tsup/db/drizzle.d.cts +8 -4
- package/dist/tsup/db/drizzle.d.ts +8 -4
- package/dist/tsup/db/drizzle.js +170 -105
- package/dist/tsup/db/drizzle.js.map +1 -1
- package/dist/tsup/db/mod.cjs +6 -163
- package/dist/tsup/db/mod.cjs.map +1 -1
- package/dist/tsup/db/mod.d.cts +12 -4
- package/dist/tsup/db/mod.d.ts +12 -4
- package/dist/tsup/db/mod.js +5 -162
- package/dist/tsup/db/mod.js.map +1 -1
- package/dist/tsup/dynamic/mod.cjs +24 -0
- package/dist/tsup/dynamic/mod.cjs.map +1 -0
- package/dist/tsup/dynamic/mod.d.cts +38 -0
- package/dist/tsup/dynamic/mod.d.ts +38 -0
- package/dist/tsup/dynamic/mod.js +24 -0
- package/dist/tsup/dynamic/mod.js.map +1 -0
- package/dist/tsup/inspector/mod.cjs +47 -12
- package/dist/tsup/inspector/mod.cjs.map +1 -1
- package/dist/tsup/inspector/mod.d.cts +26 -136
- package/dist/tsup/inspector/mod.d.ts +26 -136
- package/dist/tsup/inspector/mod.js +46 -11
- package/dist/tsup/inspector/mod.js.map +1 -1
- package/dist/tsup/inspector/workflow.cjs +21 -0
- package/dist/tsup/inspector/workflow.cjs.map +1 -0
- package/dist/tsup/inspector/workflow.d.cts +144 -0
- package/dist/tsup/inspector/workflow.d.ts +144 -0
- package/dist/tsup/inspector/workflow.js +21 -0
- package/dist/tsup/inspector/workflow.js.map +1 -0
- package/dist/tsup/inspector-tab/mod.cjs +162 -0
- package/dist/tsup/inspector-tab/mod.cjs.map +1 -0
- package/dist/tsup/inspector-tab/mod.d.cts +241 -0
- package/dist/tsup/inspector-tab/mod.d.ts +241 -0
- package/dist/tsup/inspector-tab/mod.js +162 -0
- package/dist/tsup/inspector-tab/mod.js.map +1 -0
- package/dist/tsup/mod.cjs +4268 -944
- package/dist/tsup/mod.cjs.map +1 -1
- package/dist/tsup/mod.d.cts +9 -8
- package/dist/tsup/mod.d.ts +9 -8
- package/dist/tsup/mod.js +4229 -905
- package/dist/tsup/mod.js.map +1 -1
- package/dist/tsup/test/mod.cjs +26 -21
- package/dist/tsup/test/mod.cjs.map +1 -1
- package/dist/tsup/test/mod.d.cts +7 -6
- package/dist/tsup/test/mod.d.ts +7 -6
- package/dist/tsup/test/mod.js +25 -20
- package/dist/tsup/test/mod.js.map +1 -1
- package/dist/tsup/unstable/migrations.cjs +101 -0
- package/dist/tsup/unstable/migrations.cjs.map +1 -0
- package/dist/tsup/unstable/migrations.d.cts +29 -0
- package/dist/tsup/unstable/migrations.d.ts +29 -0
- package/dist/tsup/unstable/migrations.js +101 -0
- package/dist/tsup/unstable/migrations.js.map +1 -0
- package/dist/tsup/utils-Bbz-3411.d.cts +162 -0
- package/dist/tsup/utils-BqdWVlzm.d.ts +162 -0
- package/dist/tsup/utils-vvJQyygr.d.cts +109 -0
- package/dist/tsup/utils-vvJQyygr.d.ts +109 -0
- package/dist/tsup/utils.cjs +7 -3
- package/dist/tsup/utils.cjs.map +1 -1
- package/dist/tsup/utils.d.cts +4 -147
- package/dist/tsup/utils.d.ts +4 -147
- package/dist/tsup/utils.js +6 -2
- package/dist/tsup/workflow/mod.cjs +517 -412
- package/dist/tsup/workflow/mod.cjs.map +1 -1
- package/dist/tsup/workflow/mod.d.cts +11 -10
- package/dist/tsup/workflow/mod.d.ts +11 -10
- package/dist/tsup/workflow/mod.js +511 -406
- package/dist/tsup/workflow/mod.js.map +1 -1
- package/package.json +62 -14
- package/src/actor/actions.ts +119 -0
- package/src/actor/config.test.ts +78 -0
- package/src/actor/config.ts +518 -96
- package/src/actor/contexts/index.ts +7 -2
- package/src/actor/definition.ts +38 -26
- package/src/actor/errors.ts +101 -89
- package/src/actor/keys.ts +2 -1
- package/src/actor/mod.ts +32 -21
- package/src/actor/schema.ts +2 -2
- package/src/agent-os/actor/cron.ts +37 -2
- package/src/agent-os/actor/index.ts +39 -19
- package/src/agent-os/actor/preview.ts +1 -2
- package/src/agent-os/actor/session.ts +2 -2
- package/src/agent-os/config.ts +1 -1
- package/src/agent-os/fs/database-vfs.ts +1 -1
- package/src/agent-os/index.ts +16 -15
- package/src/agent-os/types.ts +11 -0
- package/src/client/actor-common.ts +106 -53
- package/src/client/actor-conn.ts +94 -45
- package/src/client/actor-handle.ts +198 -79
- package/src/client/actor-query.ts +13 -6
- package/src/client/client.ts +43 -15
- package/src/client/config.ts +8 -0
- package/src/client/errors.ts +4 -2
- package/src/client/lifecycle-errors.ts +28 -4
- package/src/client/mod.ts +9 -4
- package/src/client/query.ts +3 -1
- package/src/client/queue.ts +8 -3
- package/src/client/raw-utils.ts +24 -16
- package/src/client/resolve-gateway-target.ts +3 -1
- package/src/client/utils.ts +36 -10
- package/src/common/actor-router-consts.ts +7 -0
- package/src/common/actor-websocket.ts +3 -1
- package/src/common/bare/actor-persist/v1.ts +205 -163
- package/src/common/bare/actor-persist/v2.ts +265 -213
- package/src/common/bare/actor-persist/v3.ts +176 -172
- package/src/common/bare/actor-persist/v4.ts +254 -253
- package/src/common/bare/generated/actor-runtime-socket-protocol/v1.ts +848 -0
- package/src/common/bare/generated/client-protocol/v4.ts +599 -0
- package/src/common/bare/generated/inspector/v5.ts +1016 -0
- package/src/common/bare/generated/inspector/v6.ts +1367 -0
- package/src/common/bare/transport/v1.ts +694 -542
- package/src/common/client-protocol-versioned.ts +176 -67
- package/src/common/client-protocol-zod.ts +7 -0
- package/src/common/client-protocol.ts +1 -1
- package/src/common/database/config.ts +103 -10
- package/src/common/database/mod.test.ts +364 -0
- package/src/common/database/mod.ts +278 -149
- package/src/common/database/native-database.test.ts +220 -0
- package/src/common/database/native-database.ts +394 -58
- package/src/common/database/shared.ts +25 -0
- package/src/common/encoding.ts +302 -38
- package/src/common/engine.ts +28 -1
- package/src/common/eventsource.ts +1 -1
- package/src/common/fetch-like.ts +49 -0
- package/src/common/inline-websocket-adapter.ts +14 -13
- package/src/common/inspector-transport.ts +12 -2
- package/src/common/log.ts +117 -14
- package/src/common/router.ts +49 -23
- package/src/common/utils.ts +23 -203
- package/src/common/websocket-interface.ts +1 -1
- package/src/db/drizzle.test.ts +164 -0
- package/src/db/drizzle.ts +207 -121
- package/src/db/mod.ts +6 -1
- package/src/devtools-loader/index.ts +4 -7
- package/src/devtools-loader/serve-devtools.ts +26 -0
- package/src/dynamic/instance.ts +32 -0
- package/src/dynamic/internal.ts +50 -0
- package/src/dynamic/isolate-runtime.ts +64 -0
- package/src/dynamic/mod.ts +32 -0
- package/src/engine-client/actor-http-client.ts +23 -4
- package/src/engine-client/actor-websocket-client.ts +32 -5
- package/src/engine-client/api-endpoints.ts +52 -2
- package/src/engine-client/api-utils.ts +2 -2
- package/src/engine-client/driver.ts +21 -17
- package/src/engine-client/mod.ts +116 -64
- package/src/engine-client/ws-proxy.ts +9 -4
- package/src/globals.d.ts +4 -0
- package/src/inspector/client.browser.ts +127 -15
- package/src/inspector/mod.ts +2 -4
- package/src/inspector/workflow.ts +61 -0
- package/src/inspector-tab/mod.ts +301 -0
- package/src/registry/config/envoy.ts +1 -2
- package/src/registry/config/index.ts +160 -53
- package/src/registry/config/serverless.ts +7 -1
- package/src/registry/index.ts +659 -96
- package/src/registry/napi-runtime.ts +1154 -0
- package/src/registry/native-validation.ts +10 -12
- package/src/registry/native.ts +2005 -955
- package/src/registry/process-metrics.ts +250 -0
- package/src/registry/run-handler-coordinator.test.ts +252 -0
- package/src/registry/run-handler-coordinator.ts +219 -0
- package/src/registry/runtime.test.ts +50 -0
- package/src/registry/runtime.ts +839 -0
- package/src/registry/wasm-runtime.ts +1283 -0
- package/src/registry/write-through-proxy.ts +141 -0
- package/src/serde.ts +8 -2
- package/src/serverless/configure.ts +102 -49
- package/src/test/mod.ts +2 -17
- package/src/test/ready.ts +22 -0
- package/src/unstable/migrations.test.ts +170 -0
- package/src/unstable/migrations.ts +141 -0
- package/src/utils/crypto.ts +14 -0
- package/src/utils/endpoint-parser.ts +1 -1
- package/src/utils/env-vars.ts +39 -0
- package/src/utils/node.ts +44 -28
- package/src/utils/router.ts +1 -1
- package/src/utils.ts +4 -2
- package/src/workflow/context.ts +683 -242
- package/src/workflow/driver.test.ts +62 -0
- package/src/workflow/driver.ts +246 -119
- package/src/workflow/inspector.ts +24 -24
- package/src/workflow/mod.ts +76 -84
- package/dist/tsup/chunk-2NDZ7JCR.cjs.map +0 -1
- package/dist/tsup/chunk-3BFYSYRU.js.map +0 -1
- package/dist/tsup/chunk-6AVUJ52Q.cjs +0 -253
- package/dist/tsup/chunk-6AVUJ52Q.cjs.map +0 -1
- package/dist/tsup/chunk-7MRGNVSR.js.map +0 -1
- package/dist/tsup/chunk-7X7RVTFF.cjs +0 -735
- package/dist/tsup/chunk-7X7RVTFF.cjs.map +0 -1
- package/dist/tsup/chunk-AK57AL7S.cjs.map +0 -1
- package/dist/tsup/chunk-AV54CVAG.cjs.map +0 -1
- package/dist/tsup/chunk-CVHUXINE.js.map +0 -1
- package/dist/tsup/chunk-EVADNK6Z.cjs.map +0 -1
- package/dist/tsup/chunk-J27CEW6F.js.map +0 -1
- package/dist/tsup/chunk-JTL6Y2UN.cjs.map +0 -1
- package/dist/tsup/chunk-LLD2D5LO.cjs.map +0 -1
- package/dist/tsup/chunk-PCBNKI2J.js.map +0 -1
- package/dist/tsup/chunk-RF3MEJV6.cjs.map +0 -1
- package/dist/tsup/chunk-SB4MXRN2.js +0 -253
- package/dist/tsup/chunk-SB4MXRN2.js.map +0 -1
- package/dist/tsup/chunk-SBEFJ4IQ.js.map +0 -1
- package/dist/tsup/chunk-SPMMF6TR.cjs.map +0 -1
- package/dist/tsup/chunk-TQSL4NJ3.cjs.map +0 -1
- package/dist/tsup/chunk-VD7AZIBR.js.map +0 -1
- package/dist/tsup/chunk-XSC2WWXD.js.map +0 -1
- package/dist/tsup/chunk-ZGWSH7YV.js.map +0 -1
- package/dist/tsup/context-BxvHh9wi.d.cts +0 -92
- package/dist/tsup/context-CNIZBIKl.d.ts +0 -92
- package/dist/tsup/utils-fwx3o3K9.d.cts +0 -18
- package/dist/tsup/utils-fwx3o3K9.d.ts +0 -18
- package/src/actor/driver.ts +0 -141
- package/src/actor/instance/mod.ts +0 -2501
- package/src/drivers/engine/actor-driver.ts +0 -2470
- package/src/utils/serve.ts +0 -217
- /package/dist/tsup/{chunk-PXLJOMJD.js.map → chunk-FXT3HN32.js.map} +0 -0
|
@@ -1,14 +1,50 @@
|
|
|
1
1
|
import { decodeBridgeRivetError } from "@/actor/errors";
|
|
2
|
-
import {
|
|
3
|
-
|
|
2
|
+
import type {
|
|
3
|
+
SqliteBatchStatement,
|
|
4
|
+
SqliteBindings,
|
|
5
|
+
SqliteDatabase,
|
|
6
|
+
SqliteExecuteResult,
|
|
7
|
+
SqliteNativeMetrics,
|
|
8
|
+
SqliteTransactionDatabase,
|
|
9
|
+
} from "./config";
|
|
4
10
|
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
11
|
+
type NativeBindNoValues = {
|
|
12
|
+
intValue?: never;
|
|
13
|
+
floatValue?: never;
|
|
14
|
+
textValue?: never;
|
|
15
|
+
blobValue?: never;
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
type NativeBindParam =
|
|
19
|
+
| ({ kind: "null" } & NativeBindNoValues)
|
|
20
|
+
| {
|
|
21
|
+
kind: "int";
|
|
22
|
+
intValue: number;
|
|
23
|
+
floatValue?: never;
|
|
24
|
+
textValue?: never;
|
|
25
|
+
blobValue?: never;
|
|
26
|
+
}
|
|
27
|
+
| {
|
|
28
|
+
kind: "float";
|
|
29
|
+
intValue?: never;
|
|
30
|
+
floatValue: number;
|
|
31
|
+
textValue?: never;
|
|
32
|
+
blobValue?: never;
|
|
33
|
+
}
|
|
34
|
+
| {
|
|
35
|
+
kind: "text";
|
|
36
|
+
intValue?: never;
|
|
37
|
+
floatValue?: never;
|
|
38
|
+
textValue: string;
|
|
39
|
+
blobValue?: never;
|
|
40
|
+
}
|
|
41
|
+
| {
|
|
42
|
+
kind: "blob";
|
|
43
|
+
intValue?: never;
|
|
44
|
+
floatValue?: never;
|
|
45
|
+
textValue?: never;
|
|
46
|
+
blobValue: Buffer;
|
|
47
|
+
};
|
|
12
48
|
|
|
13
49
|
interface NativeExecResult {
|
|
14
50
|
columns: string[];
|
|
@@ -24,17 +60,35 @@ interface NativeRunResult {
|
|
|
24
60
|
changes: number;
|
|
25
61
|
}
|
|
26
62
|
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
63
|
+
interface NativeExecuteResult {
|
|
64
|
+
columns: string[];
|
|
65
|
+
rows: unknown[][];
|
|
66
|
+
changes: number;
|
|
67
|
+
lastInsertRowId?: number | null;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
interface NativeBatchStatement {
|
|
71
|
+
sql: string;
|
|
72
|
+
params?: NativeBindParam[] | null;
|
|
34
73
|
}
|
|
35
74
|
|
|
36
75
|
export interface JsNativeDatabaseLike {
|
|
37
76
|
exec(sql: string): Promise<NativeExecResult>;
|
|
77
|
+
execute(
|
|
78
|
+
sql: string,
|
|
79
|
+
params?: NativeBindParam[] | null,
|
|
80
|
+
): Promise<NativeExecuteResult>;
|
|
81
|
+
executeBatch?(
|
|
82
|
+
statements: NativeBatchStatement[],
|
|
83
|
+
): Promise<NativeExecuteResult[]>;
|
|
84
|
+
beginStateTransaction?(
|
|
85
|
+
timeoutMs?: number,
|
|
86
|
+
context?: unknown,
|
|
87
|
+
): Promise<JsNativeTransactionLike>;
|
|
88
|
+
beginTransaction(
|
|
89
|
+
timeoutMs?: number,
|
|
90
|
+
name?: string,
|
|
91
|
+
): Promise<JsNativeTransactionLike>;
|
|
38
92
|
query(
|
|
39
93
|
sql: string,
|
|
40
94
|
params?: NativeBindParam[] | null,
|
|
@@ -43,10 +97,26 @@ export interface JsNativeDatabaseLike {
|
|
|
43
97
|
sql: string,
|
|
44
98
|
params?: NativeBindParam[] | null,
|
|
45
99
|
): Promise<NativeRunResult>;
|
|
46
|
-
|
|
100
|
+
metrics?(): SqliteNativeMetrics | null;
|
|
47
101
|
takeLastKvError?(): string | null;
|
|
48
102
|
close(): Promise<void>;
|
|
49
103
|
}
|
|
104
|
+
export type StateAwareSqliteDatabase = SqliteDatabase & {
|
|
105
|
+
beginStateTransaction(
|
|
106
|
+
timeoutMs?: number,
|
|
107
|
+
context?: unknown,
|
|
108
|
+
): Promise<SqliteTransactionDatabase>;
|
|
109
|
+
};
|
|
110
|
+
|
|
111
|
+
export interface JsNativeTransactionLike {
|
|
112
|
+
exec(sql: string): Promise<NativeExecResult>;
|
|
113
|
+
execute(
|
|
114
|
+
sql: string,
|
|
115
|
+
params?: NativeBindParam[] | null,
|
|
116
|
+
): Promise<NativeExecuteResult>;
|
|
117
|
+
commit(): Promise<void>;
|
|
118
|
+
rollback(): Promise<void>;
|
|
119
|
+
}
|
|
50
120
|
|
|
51
121
|
function shouldAttachNativeKvError(message: string): boolean {
|
|
52
122
|
return /i\/o error|unable to open database file/i.test(message);
|
|
@@ -56,12 +126,16 @@ function enrichNativeDatabaseError(
|
|
|
56
126
|
database: JsNativeDatabaseLike,
|
|
57
127
|
error: unknown,
|
|
58
128
|
): never {
|
|
59
|
-
const
|
|
129
|
+
const bridgeReason =
|
|
60
130
|
typeof error === "string"
|
|
61
|
-
?
|
|
131
|
+
? error
|
|
62
132
|
: error instanceof Error
|
|
63
|
-
?
|
|
133
|
+
? error.message
|
|
64
134
|
: undefined;
|
|
135
|
+
const bridged =
|
|
136
|
+
bridgeReason === undefined
|
|
137
|
+
? undefined
|
|
138
|
+
: decodeBridgeRivetError(bridgeReason);
|
|
65
139
|
if (bridged) {
|
|
66
140
|
throw bridged;
|
|
67
141
|
}
|
|
@@ -167,18 +241,122 @@ function toNativeBindings(
|
|
|
167
241
|
});
|
|
168
242
|
}
|
|
169
243
|
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
):
|
|
173
|
-
|
|
174
|
-
|
|
244
|
+
function toNativeBatchStatement(
|
|
245
|
+
statement: SqliteBatchStatement,
|
|
246
|
+
): NativeBatchStatement {
|
|
247
|
+
return {
|
|
248
|
+
sql: statement.sql,
|
|
249
|
+
params: toNativeBindings(statement.sql, statement.params),
|
|
250
|
+
};
|
|
251
|
+
}
|
|
175
252
|
|
|
176
|
-
|
|
177
|
-
|
|
253
|
+
function normalizeNativeMetrics(
|
|
254
|
+
metrics: SqliteNativeMetrics | null | undefined,
|
|
255
|
+
): SqliteNativeMetrics | null {
|
|
256
|
+
if (!metrics) return null;
|
|
257
|
+
const raw = metrics as unknown as Record<string, unknown>;
|
|
258
|
+
const numberField = (camel: string, snake: string) =>
|
|
259
|
+
Number(raw[camel] ?? raw[snake] ?? 0);
|
|
260
|
+
|
|
261
|
+
return {
|
|
262
|
+
requestBuildNs: numberField("requestBuildNs", "request_build_ns"),
|
|
263
|
+
serializeNs: numberField("serializeNs", "serialize_ns"),
|
|
264
|
+
transportNs: numberField("transportNs", "transport_ns"),
|
|
265
|
+
stateUpdateNs: numberField("stateUpdateNs", "state_update_ns"),
|
|
266
|
+
totalNs: numberField("totalNs", "total_ns"),
|
|
267
|
+
commitCount: numberField("commitCount", "commit_count"),
|
|
268
|
+
pageCacheEntries: numberField("pageCacheEntries", "page_cache_entries"),
|
|
269
|
+
pageCacheWeightedSize: numberField(
|
|
270
|
+
"pageCacheWeightedSize",
|
|
271
|
+
"page_cache_weighted_size",
|
|
272
|
+
),
|
|
273
|
+
pageCacheCapacityPages: numberField(
|
|
274
|
+
"pageCacheCapacityPages",
|
|
275
|
+
"page_cache_capacity_pages",
|
|
276
|
+
),
|
|
277
|
+
writeBufferDirtyPages: numberField(
|
|
278
|
+
"writeBufferDirtyPages",
|
|
279
|
+
"write_buffer_dirty_pages",
|
|
280
|
+
),
|
|
281
|
+
dbSizePages: numberField("dbSizePages", "db_size_pages"),
|
|
282
|
+
};
|
|
283
|
+
}
|
|
284
|
+
|
|
285
|
+
class NativeCloseGate {
|
|
286
|
+
#active = 0;
|
|
287
|
+
#closed = false;
|
|
288
|
+
#waiters: (() => void)[] = [];
|
|
289
|
+
|
|
290
|
+
enter(): () => void {
|
|
291
|
+
if (this.#closed) {
|
|
178
292
|
throw new Error(
|
|
179
293
|
"Database is closed. This usually means a background timer (setInterval, setTimeout) or a stray promise is still running after the actor stopped. Use c.abortSignal to clean up timers before the actor shuts down.",
|
|
180
294
|
);
|
|
181
295
|
}
|
|
296
|
+
|
|
297
|
+
this.#active++;
|
|
298
|
+
let released = false;
|
|
299
|
+
return () => {
|
|
300
|
+
if (released) {
|
|
301
|
+
return;
|
|
302
|
+
}
|
|
303
|
+
released = true;
|
|
304
|
+
this.#active--;
|
|
305
|
+
if (this.#active === 0) {
|
|
306
|
+
const waiters = this.#waiters.splice(0);
|
|
307
|
+
for (const waiter of waiters) {
|
|
308
|
+
waiter();
|
|
309
|
+
}
|
|
310
|
+
}
|
|
311
|
+
};
|
|
312
|
+
}
|
|
313
|
+
|
|
314
|
+
async close(callback: () => Promise<void>): Promise<void> {
|
|
315
|
+
if (this.#closed) {
|
|
316
|
+
return;
|
|
317
|
+
}
|
|
318
|
+
this.#closed = true;
|
|
319
|
+
if (this.#active > 0) {
|
|
320
|
+
await new Promise<void>((resolve) => this.#waiters.push(resolve));
|
|
321
|
+
}
|
|
322
|
+
await callback();
|
|
323
|
+
}
|
|
324
|
+
}
|
|
325
|
+
|
|
326
|
+
export function wrapJsNativeDatabase(
|
|
327
|
+
database: JsNativeDatabaseLike,
|
|
328
|
+
): StateAwareSqliteDatabase {
|
|
329
|
+
const gate = new NativeCloseGate();
|
|
330
|
+
let closePromise: Promise<void> | undefined;
|
|
331
|
+
let lastInsertRowId: number | null = null;
|
|
332
|
+
|
|
333
|
+
const executeNative = async (
|
|
334
|
+
sql: string,
|
|
335
|
+
params?: SqliteBindings,
|
|
336
|
+
): Promise<SqliteExecuteResult> => {
|
|
337
|
+
const lastInsertRowIdColumn = lastInsertRowIdColumnName(sql);
|
|
338
|
+
if (lastInsertRowIdColumn) {
|
|
339
|
+
return {
|
|
340
|
+
columns: [lastInsertRowIdColumn],
|
|
341
|
+
rows: [[lastInsertRowId ?? 0]],
|
|
342
|
+
changes: 0,
|
|
343
|
+
lastInsertRowId,
|
|
344
|
+
};
|
|
345
|
+
}
|
|
346
|
+
|
|
347
|
+
const release = gate.enter();
|
|
348
|
+
try {
|
|
349
|
+
const nativeParams = toNativeBindings(sql, params);
|
|
350
|
+
const result = await database.execute(sql, nativeParams);
|
|
351
|
+
if (result.lastInsertRowId !== undefined) {
|
|
352
|
+
lastInsertRowId = result.lastInsertRowId;
|
|
353
|
+
}
|
|
354
|
+
return result;
|
|
355
|
+
} catch (error) {
|
|
356
|
+
enrichNativeDatabaseError(database, error);
|
|
357
|
+
} finally {
|
|
358
|
+
release();
|
|
359
|
+
}
|
|
182
360
|
};
|
|
183
361
|
|
|
184
362
|
return {
|
|
@@ -186,14 +364,15 @@ export function wrapJsNativeDatabase(
|
|
|
186
364
|
sql: string,
|
|
187
365
|
callback?: (row: unknown[], columns: string[]) => void,
|
|
188
366
|
): Promise<void> {
|
|
189
|
-
const
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
367
|
+
const release = gate.enter();
|
|
368
|
+
let result: NativeExecResult;
|
|
369
|
+
try {
|
|
370
|
+
result = await database.exec(sql);
|
|
371
|
+
} catch (error) {
|
|
372
|
+
enrichNativeDatabaseError(database, error);
|
|
373
|
+
} finally {
|
|
374
|
+
release();
|
|
375
|
+
}
|
|
197
376
|
if (!callback) {
|
|
198
377
|
return;
|
|
199
378
|
}
|
|
@@ -201,37 +380,194 @@ export function wrapJsNativeDatabase(
|
|
|
201
380
|
callback(row, result.columns);
|
|
202
381
|
}
|
|
203
382
|
},
|
|
204
|
-
async
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
383
|
+
async execute(
|
|
384
|
+
sql: string,
|
|
385
|
+
params?: SqliteBindings,
|
|
386
|
+
): Promise<SqliteExecuteResult> {
|
|
387
|
+
return await executeNative(sql, params);
|
|
388
|
+
},
|
|
389
|
+
async executeBatch(
|
|
390
|
+
statements: SqliteBatchStatement[],
|
|
391
|
+
): Promise<SqliteExecuteResult[]> {
|
|
392
|
+
const nativeStatements = statements.map(toNativeBatchStatement);
|
|
393
|
+
const release = gate.enter();
|
|
394
|
+
let transaction: JsNativeTransactionLike | undefined;
|
|
395
|
+
try {
|
|
396
|
+
const results = database.executeBatch
|
|
397
|
+
? await database.executeBatch(nativeStatements)
|
|
398
|
+
: await (async () => {
|
|
399
|
+
transaction = await database.beginTransaction();
|
|
400
|
+
const transactionResults: NativeExecuteResult[] =
|
|
401
|
+
[];
|
|
402
|
+
for (const statement of nativeStatements) {
|
|
403
|
+
transactionResults.push(
|
|
404
|
+
await transaction.execute(
|
|
405
|
+
statement.sql,
|
|
406
|
+
statement.params,
|
|
407
|
+
),
|
|
408
|
+
);
|
|
409
|
+
}
|
|
410
|
+
await transaction.commit();
|
|
411
|
+
transaction = undefined;
|
|
412
|
+
return transactionResults;
|
|
413
|
+
})();
|
|
414
|
+
for (const result of results) {
|
|
415
|
+
if (result.lastInsertRowId !== undefined) {
|
|
416
|
+
lastInsertRowId = result.lastInsertRowId;
|
|
417
|
+
}
|
|
418
|
+
}
|
|
419
|
+
return results;
|
|
420
|
+
} catch (error) {
|
|
421
|
+
if (transaction) {
|
|
422
|
+
try {
|
|
423
|
+
await transaction.rollback();
|
|
424
|
+
} catch {
|
|
425
|
+
// The original batch error is more actionable than cleanup failure.
|
|
426
|
+
}
|
|
427
|
+
}
|
|
428
|
+
enrichNativeDatabaseError(database, error);
|
|
429
|
+
} finally {
|
|
430
|
+
release();
|
|
431
|
+
}
|
|
432
|
+
},
|
|
433
|
+
async beginTransaction(
|
|
434
|
+
timeoutMs?: number,
|
|
435
|
+
name?: string,
|
|
436
|
+
): Promise<SqliteTransactionDatabase> {
|
|
437
|
+
const release = gate.enter();
|
|
438
|
+
let transaction: JsNativeTransactionLike;
|
|
439
|
+
try {
|
|
440
|
+
transaction = await database.beginTransaction(timeoutMs, name);
|
|
441
|
+
} catch (error) {
|
|
442
|
+
enrichNativeDatabaseError(database, error);
|
|
443
|
+
} finally {
|
|
444
|
+
release();
|
|
445
|
+
}
|
|
446
|
+
return wrapTransaction(database, transaction, gate, (result) => {
|
|
447
|
+
if (result.lastInsertRowId !== undefined) {
|
|
448
|
+
lastInsertRowId = result.lastInsertRowId;
|
|
211
449
|
}
|
|
212
450
|
});
|
|
213
451
|
},
|
|
214
|
-
async
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
452
|
+
async beginStateTransaction(
|
|
453
|
+
timeoutMs?: number,
|
|
454
|
+
context?: unknown,
|
|
455
|
+
): Promise<SqliteTransactionDatabase> {
|
|
456
|
+
if (!database.beginStateTransaction) {
|
|
457
|
+
throw new Error("actor state transactions are not configured");
|
|
458
|
+
}
|
|
459
|
+
const release = gate.enter();
|
|
460
|
+
let transaction: JsNativeTransactionLike;
|
|
461
|
+
try {
|
|
462
|
+
transaction = await database.beginStateTransaction(
|
|
463
|
+
timeoutMs,
|
|
464
|
+
context,
|
|
465
|
+
);
|
|
466
|
+
} catch (error) {
|
|
467
|
+
enrichNativeDatabaseError(database, error);
|
|
468
|
+
} finally {
|
|
469
|
+
release();
|
|
470
|
+
}
|
|
471
|
+
return wrapTransaction(database, transaction, gate, (result) => {
|
|
472
|
+
if (result.lastInsertRowId !== undefined) {
|
|
473
|
+
lastInsertRowId = result.lastInsertRowId;
|
|
221
474
|
}
|
|
222
475
|
});
|
|
223
476
|
},
|
|
224
|
-
|
|
225
|
-
|
|
477
|
+
async run(sql: string, params?: SqliteBindings): Promise<void> {
|
|
478
|
+
await executeNative(sql, params);
|
|
479
|
+
},
|
|
480
|
+
async query(sql: string, params?: SqliteBindings) {
|
|
481
|
+
const { columns, rows } = await executeNative(sql, params);
|
|
482
|
+
return { columns, rows };
|
|
483
|
+
},
|
|
484
|
+
nativeMetrics(): SqliteNativeMetrics | null {
|
|
485
|
+
return normalizeNativeMetrics(database.metrics?.());
|
|
226
486
|
},
|
|
227
487
|
async close(): Promise<void> {
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
return;
|
|
231
|
-
}
|
|
232
|
-
closed = true;
|
|
233
|
-
await database.close();
|
|
234
|
-
});
|
|
488
|
+
closePromise ??= gate.close(() => database.close());
|
|
489
|
+
await closePromise;
|
|
235
490
|
},
|
|
236
491
|
};
|
|
237
492
|
}
|
|
493
|
+
|
|
494
|
+
function wrapTransaction(
|
|
495
|
+
database: JsNativeDatabaseLike,
|
|
496
|
+
transaction: JsNativeTransactionLike,
|
|
497
|
+
gate: NativeCloseGate,
|
|
498
|
+
onExecute: (result: NativeExecuteResult) => void,
|
|
499
|
+
): SqliteTransactionDatabase {
|
|
500
|
+
return {
|
|
501
|
+
async exec(sql, callback) {
|
|
502
|
+
const release = gate.enter();
|
|
503
|
+
let result: NativeExecResult;
|
|
504
|
+
try {
|
|
505
|
+
result = await transaction.exec(sql);
|
|
506
|
+
} catch (error) {
|
|
507
|
+
enrichNativeDatabaseError(database, error);
|
|
508
|
+
} finally {
|
|
509
|
+
release();
|
|
510
|
+
}
|
|
511
|
+
if (callback) {
|
|
512
|
+
for (const row of result.rows) callback(row, result.columns);
|
|
513
|
+
}
|
|
514
|
+
},
|
|
515
|
+
async execute(sql, params) {
|
|
516
|
+
const release = gate.enter();
|
|
517
|
+
try {
|
|
518
|
+
const result = await transaction.execute(
|
|
519
|
+
sql,
|
|
520
|
+
toNativeBindings(sql, params),
|
|
521
|
+
);
|
|
522
|
+
onExecute(result);
|
|
523
|
+
return result;
|
|
524
|
+
} catch (error) {
|
|
525
|
+
enrichNativeDatabaseError(database, error);
|
|
526
|
+
} finally {
|
|
527
|
+
release();
|
|
528
|
+
}
|
|
529
|
+
},
|
|
530
|
+
async commit() {
|
|
531
|
+
const release = gate.enter();
|
|
532
|
+
try {
|
|
533
|
+
await transaction.commit();
|
|
534
|
+
} catch (error) {
|
|
535
|
+
enrichNativeDatabaseError(database, error);
|
|
536
|
+
} finally {
|
|
537
|
+
release();
|
|
538
|
+
}
|
|
539
|
+
},
|
|
540
|
+
async rollback() {
|
|
541
|
+
const release = gate.enter();
|
|
542
|
+
try {
|
|
543
|
+
await transaction.rollback();
|
|
544
|
+
} catch (error) {
|
|
545
|
+
enrichNativeDatabaseError(database, error);
|
|
546
|
+
} finally {
|
|
547
|
+
release();
|
|
548
|
+
}
|
|
549
|
+
},
|
|
550
|
+
};
|
|
551
|
+
}
|
|
552
|
+
|
|
553
|
+
function lastInsertRowIdColumnName(sql: string): string | undefined {
|
|
554
|
+
const match = sql.match(
|
|
555
|
+
/^\s*SELECT\s+last_insert_rowid\s*\(\s*\)\s*(?:AS\s+("[^"]+"|`[^`]+`|\[[^\]]+\]|\w+))?\s*;?\s*$/i,
|
|
556
|
+
);
|
|
557
|
+
if (!match) {
|
|
558
|
+
return undefined;
|
|
559
|
+
}
|
|
560
|
+
|
|
561
|
+
const alias = match[1];
|
|
562
|
+
if (!alias) {
|
|
563
|
+
return "last_insert_rowid()";
|
|
564
|
+
}
|
|
565
|
+
if (
|
|
566
|
+
(alias.startsWith('"') && alias.endsWith('"')) ||
|
|
567
|
+
(alias.startsWith("`") && alias.endsWith("`")) ||
|
|
568
|
+
(alias.startsWith("[") && alias.endsWith("]"))
|
|
569
|
+
) {
|
|
570
|
+
return alias.slice(1, -1);
|
|
571
|
+
}
|
|
572
|
+
return alias;
|
|
573
|
+
}
|
|
@@ -1,4 +1,29 @@
|
|
|
1
1
|
import type { SqliteBindings } from "./config";
|
|
2
|
+
|
|
3
|
+
/** Migrations may legitimately do substantially more work than request transactions. */
|
|
4
|
+
export const MIGRATION_TRANSACTION_TIMEOUT_MS = 5 * 60_000;
|
|
5
|
+
|
|
6
|
+
export function isManualTransactionControl(query: string): boolean {
|
|
7
|
+
return /^\s*(?:BEGIN|SAVEPOINT|COMMIT|END|ROLLBACK)\b/i.test(query);
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export function validateTransactionTimeout(timeout: number | undefined): void {
|
|
11
|
+
if (timeout !== undefined && (!Number.isFinite(timeout) || timeout <= 0)) {
|
|
12
|
+
throw new Error(
|
|
13
|
+
"db.transaction() timeout must be a positive finite number of milliseconds",
|
|
14
|
+
);
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export function validateTransactionName(name: string | undefined): void {
|
|
19
|
+
if (name === undefined) {
|
|
20
|
+
return;
|
|
21
|
+
}
|
|
22
|
+
if (name.length === 0) {
|
|
23
|
+
throw new Error("db.transaction() name must not be empty");
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
|
|
2
27
|
type SqliteBindingObject = Record<string, unknown>;
|
|
3
28
|
|
|
4
29
|
function isSqliteBindingValue(value: unknown): boolean {
|