rivetkit 0.0.0-skip-ready-wait-flatten-client-options.1cae221 → 0.0.0-sqlite-uds.ea644f1
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 +561 -89
- package/dist/browser/client.js +1063 -430
- package/dist/browser/client.js.map +1 -1
- package/dist/browser/inspector/client.d.ts +22 -2
- package/dist/browser/inspector/client.js +1036 -232
- 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 +2232 -2082
- package/dist/tsup/agent-os/index.cjs.map +1 -1
- package/dist/tsup/agent-os/index.d.cts +556 -85
- package/dist/tsup/agent-os/index.d.ts +556 -85
- package/dist/tsup/agent-os/index.js +2234 -2084
- package/dist/tsup/agent-os/index.js.map +1 -1
- package/dist/tsup/{chunk-7MRGNVSR.js → chunk-3GLNEWGY.js} +78 -6
- package/dist/tsup/chunk-3GLNEWGY.js.map +1 -0
- package/dist/tsup/{chunk-V3QNBJ7N.cjs → chunk-4FC7TVS6.cjs} +35 -10
- package/dist/tsup/chunk-4FC7TVS6.cjs.map +1 -0
- package/dist/tsup/{chunk-XNZR7UD2.cjs → chunk-7DDQA6KN.cjs} +90 -65
- package/dist/tsup/chunk-7DDQA6KN.cjs.map +1 -0
- package/dist/tsup/{chunk-NFC5VU36.cjs → chunk-AESHILFV.cjs} +18 -10
- package/dist/tsup/chunk-AESHILFV.cjs.map +1 -0
- package/dist/tsup/{chunk-D4TSTM6C.js → chunk-EFQCNJ23.js} +83 -58
- package/dist/tsup/chunk-EFQCNJ23.js.map +1 -0
- package/dist/tsup/{chunk-OIKOPSXQ.js → chunk-FUS4OFX5.js} +12 -4
- package/dist/tsup/chunk-FUS4OFX5.js.map +1 -0
- package/dist/tsup/{chunk-IOYKCB6Y.cjs → chunk-GUCITCR3.cjs} +44 -9
- package/dist/tsup/chunk-GUCITCR3.cjs.map +1 -0
- package/dist/tsup/{chunk-3BFYSYRU.js → chunk-HXUEHHJF.js} +3 -2
- package/dist/tsup/chunk-HXUEHHJF.js.map +1 -0
- package/dist/tsup/{chunk-PCBNKI2J.js → chunk-JZ7TWV65.js} +1 -1
- package/dist/tsup/chunk-JZ7TWV65.js.map +1 -0
- package/dist/tsup/{chunk-KSG2COSQ.js → chunk-KYBAXJRA.js} +6 -6
- package/dist/tsup/chunk-KYBAXJRA.js.map +1 -0
- package/dist/tsup/{chunk-LNMB25HW.js → chunk-LMUEIJUM.js} +780 -183
- package/dist/tsup/chunk-LMUEIJUM.js.map +1 -0
- package/dist/tsup/{chunk-RZEJJJKU.js → chunk-LTMSYD2A.js} +42 -7
- package/dist/tsup/chunk-LTMSYD2A.js.map +1 -0
- package/dist/tsup/{chunk-AK57AL7S.cjs → chunk-OAPVVVTX.cjs} +79 -7
- package/dist/tsup/chunk-OAPVVVTX.cjs.map +1 -0
- package/dist/tsup/{chunk-D2TLG75Y.cjs → chunk-TIUL6FNF.cjs} +10 -10
- package/dist/tsup/chunk-TIUL6FNF.cjs.map +1 -0
- package/dist/tsup/{chunk-POTPHU3P.cjs → chunk-UYT2CIWO.cjs} +3 -3
- package/dist/tsup/{chunk-POTPHU3P.cjs.map → chunk-UYT2CIWO.cjs.map} +1 -1
- package/dist/tsup/{chunk-TPBHXFB2.cjs → chunk-VDTC257X.cjs} +138 -24
- package/dist/tsup/chunk-VDTC257X.cjs.map +1 -0
- package/dist/tsup/{chunk-LLD2D5LO.cjs → chunk-VE2X4KMG.cjs} +3 -2
- package/dist/tsup/chunk-VE2X4KMG.cjs.map +1 -0
- package/dist/tsup/{chunk-22XU3BVY.cjs → chunk-VWOA7DRK.cjs} +925 -328
- package/dist/tsup/chunk-VWOA7DRK.cjs.map +1 -0
- package/dist/tsup/{chunk-4ZIWB4CQ.js → chunk-VYQASICJ.js} +2 -2
- package/dist/tsup/{chunk-W54QCENI.js → chunk-X4BXYDTG.js} +134 -20
- package/dist/tsup/chunk-X4BXYDTG.js.map +1 -0
- package/dist/tsup/{chunk-2NDZ7JCR.cjs → chunk-ZA7FLHKH.cjs} +1 -1
- package/dist/tsup/chunk-ZA7FLHKH.cjs.map +1 -0
- package/dist/tsup/{chunk-K34B3OVG.js → chunk-ZZ3WBRPD.js} +34 -9
- package/dist/tsup/chunk-ZZ3WBRPD.js.map +1 -0
- package/dist/tsup/client/mod.cjs +9 -9
- package/dist/tsup/client/mod.cjs.map +1 -1
- package/dist/tsup/client/mod.d.cts +8 -9
- package/dist/tsup/client/mod.d.ts +8 -9
- package/dist/tsup/client/mod.js +8 -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.js +3 -3
- package/dist/tsup/{config-CRdGwwbr.d.cts → config-CxG53eQo.d.cts} +577 -36
- package/dist/tsup/{config-kxXbtrJU.d.ts → config-DLOxy81E.d.cts} +5 -5
- package/dist/tsup/{config-kxXbtrJU.d.cts → config-DLOxy81E.d.ts} +5 -5
- package/dist/tsup/{config-DIpBWm5C.d.ts → config-Ds6DCRhV.d.ts} +577 -36
- package/dist/tsup/context-8KlcOYIs.d.cts +129 -0
- package/dist/tsup/context-Cfbm4QLr.d.ts +129 -0
- package/dist/tsup/db/drizzle.cjs +164 -78
- package/dist/tsup/db/drizzle.cjs.map +1 -1
- package/dist/tsup/db/drizzle.d.cts +4 -2
- package/dist/tsup/db/drizzle.d.ts +4 -2
- package/dist/tsup/db/drizzle.js +164 -78
- package/dist/tsup/db/drizzle.js.map +1 -1
- package/dist/tsup/db/mod.cjs +93 -24
- package/dist/tsup/db/mod.cjs.map +1 -1
- package/dist/tsup/db/mod.d.cts +2 -2
- package/dist/tsup/db/mod.d.ts +2 -2
- package/dist/tsup/db/mod.js +92 -23
- 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 +37 -0
- package/dist/tsup/dynamic/mod.d.ts +37 -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 +37 -15
- package/dist/tsup/inspector/mod.d.ts +37 -15
- package/dist/tsup/inspector/mod.js +46 -11
- package/dist/tsup/inspector/mod.js.map +1 -1
- 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 +240 -0
- package/dist/tsup/inspector-tab/mod.d.ts +240 -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 +1078 -479
- package/dist/tsup/mod.cjs.map +1 -1
- package/dist/tsup/mod.d.cts +5 -6
- package/dist/tsup/mod.d.ts +5 -6
- package/dist/tsup/mod.js +996 -397
- package/dist/tsup/mod.js.map +1 -1
- package/dist/tsup/test/mod.cjs +21 -18
- package/dist/tsup/test/mod.cjs.map +1 -1
- package/dist/tsup/test/mod.d.cts +4 -5
- package/dist/tsup/test/mod.d.ts +4 -5
- package/dist/tsup/test/mod.js +18 -15
- package/dist/tsup/test/mod.js.map +1 -1
- package/dist/tsup/utils-CqDnC_PS.d.cts +104 -0
- package/dist/tsup/utils-CqDnC_PS.d.ts +104 -0
- package/dist/tsup/utils.cjs +3 -3
- package/dist/tsup/utils.d.cts +1 -1
- package/dist/tsup/utils.d.ts +1 -1
- package/dist/tsup/utils.js +2 -2
- package/dist/tsup/workflow/mod.cjs +386 -322
- package/dist/tsup/workflow/mod.cjs.map +1 -1
- package/dist/tsup/workflow/mod.d.cts +8 -9
- package/dist/tsup/workflow/mod.d.ts +8 -9
- package/dist/tsup/workflow/mod.js +363 -299
- package/dist/tsup/workflow/mod.js.map +1 -1
- package/package.json +35 -14
- package/src/actor/config.ts +188 -59
- package/src/actor/contexts/index.ts +7 -2
- package/src/actor/definition.ts +17 -19
- package/src/actor/driver.ts +3 -3
- package/src/actor/errors.ts +70 -7
- package/src/actor/instance/mod.ts +39 -56
- package/src/actor/keys.ts +2 -1
- package/src/actor/mod.ts +22 -20
- package/src/actor/schema.ts +2 -2
- package/src/agent-os/actor/index.ts +38 -18
- 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/client/actor-common.ts +88 -62
- package/src/client/actor-conn.ts +58 -63
- package/src/client/actor-handle.ts +125 -71
- package/src/client/actor-query.ts +5 -5
- package/src/client/config.ts +3 -3
- package/src/client/errors.ts +2 -1
- package/src/client/lifecycle-errors.ts +2 -4
- package/src/client/query.ts +1 -1
- package/src/client/queue.ts +8 -3
- package/src/client/raw-utils.ts +10 -10
- package/src/client/resolve-gateway-target.ts +1 -1
- package/src/client/utils.ts +34 -10
- package/src/common/actor-router-consts.ts +7 -4
- 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-uds-protocol/v1.ts +802 -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/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 +16 -5
- package/src/common/database/mod.test.ts +137 -16
- package/src/common/database/mod.ts +100 -30
- package/src/common/database/native-database.test.ts +35 -22
- package/src/common/database/native-database.ts +26 -10
- package/src/common/database/shared.ts +1 -0
- package/src/common/encoding.ts +250 -16
- package/src/common/engine.ts +28 -1
- package/src/common/eventsource.ts +1 -1
- package/src/common/inline-websocket-adapter.ts +14 -13
- package/src/common/log.ts +15 -8
- package/src/common/router.ts +49 -23
- package/src/common/utils.ts +10 -202
- package/src/common/websocket-interface.ts +1 -1
- package/src/db/drizzle.ts +194 -95
- package/src/db/mod.ts +1 -1
- package/src/devtools-loader/index.ts +4 -7
- package/src/devtools-loader/serve-devtools.ts +26 -0
- package/src/drivers/engine/actor-driver.ts +76 -73
- package/src/dynamic/instance.ts +32 -0
- package/src/dynamic/internal.ts +50 -0
- package/src/dynamic/isolate-runtime.ts +66 -0
- package/src/dynamic/mod.ts +32 -0
- package/src/engine-client/actor-http-client.ts +6 -9
- package/src/engine-client/actor-websocket-client.ts +14 -13
- package/src/engine-client/api-endpoints.ts +51 -2
- package/src/engine-client/api-utils.ts +2 -2
- package/src/engine-client/driver.ts +3 -4
- package/src/engine-client/mod.ts +17 -10
- package/src/engine-client/ws-proxy.ts +9 -4
- package/src/inspector/client.browser.ts +66 -15
- package/src/inspector/mod.ts +2 -4
- package/src/inspector-tab/mod.ts +300 -0
- package/src/registry/config/envoy.ts +1 -2
- package/src/registry/config/index.ts +46 -20
- package/src/registry/index.ts +364 -87
- package/src/registry/napi-runtime.ts +97 -8
- package/src/registry/native-validation.ts +10 -12
- package/src/registry/native.ts +592 -343
- package/src/registry/process-metrics.ts +250 -0
- package/src/registry/runtime.ts +85 -6
- package/src/registry/wasm-runtime.ts +72 -3
- package/src/registry/write-through-proxy.ts +40 -0
- package/src/serde.ts +2 -2
- package/src/serverless/configure.ts +19 -8
- package/src/test/mod.ts +11 -8
- package/src/utils/crypto.ts +14 -0
- package/src/utils/endpoint-parser.ts +1 -1
- package/src/utils/env-vars.ts +37 -0
- package/src/utils/router.ts +1 -1
- package/src/utils.ts +1 -2
- package/src/workflow/context.ts +703 -240
- package/src/workflow/driver.ts +23 -12
- package/src/workflow/inspector.ts +12 -3
- package/src/workflow/mod.ts +37 -23
- package/dist/tsup/chunk-22XU3BVY.cjs.map +0 -1
- package/dist/tsup/chunk-2NDZ7JCR.cjs.map +0 -1
- package/dist/tsup/chunk-3BFYSYRU.js.map +0 -1
- package/dist/tsup/chunk-7MRGNVSR.js.map +0 -1
- package/dist/tsup/chunk-AK57AL7S.cjs.map +0 -1
- package/dist/tsup/chunk-D2TLG75Y.cjs.map +0 -1
- package/dist/tsup/chunk-D4TSTM6C.js.map +0 -1
- package/dist/tsup/chunk-IOYKCB6Y.cjs.map +0 -1
- package/dist/tsup/chunk-K34B3OVG.js.map +0 -1
- package/dist/tsup/chunk-KSG2COSQ.js.map +0 -1
- package/dist/tsup/chunk-LLD2D5LO.cjs.map +0 -1
- package/dist/tsup/chunk-LNMB25HW.js.map +0 -1
- package/dist/tsup/chunk-NFC5VU36.cjs.map +0 -1
- package/dist/tsup/chunk-OIKOPSXQ.js.map +0 -1
- package/dist/tsup/chunk-PCBNKI2J.js.map +0 -1
- package/dist/tsup/chunk-RZEJJJKU.js.map +0 -1
- package/dist/tsup/chunk-TPBHXFB2.cjs.map +0 -1
- package/dist/tsup/chunk-V3QNBJ7N.cjs.map +0 -1
- package/dist/tsup/chunk-W54QCENI.js.map +0 -1
- package/dist/tsup/chunk-XNZR7UD2.cjs.map +0 -1
- package/dist/tsup/context-B7G6sk7x.d.ts +0 -92
- package/dist/tsup/context-DzMRHkjC.d.cts +0 -92
- package/dist/tsup/utils-fwx3o3K9.d.cts +0 -18
- package/dist/tsup/utils-fwx3o3K9.d.ts +0 -18
- package/src/utils/serve.ts +0 -217
- /package/dist/tsup/{chunk-4ZIWB4CQ.js.map → chunk-VYQASICJ.js.map} +0 -0
|
@@ -7,9 +7,7 @@ interface DatabaseFactoryConfig {
|
|
|
7
7
|
onMigrate?: (db: RawAccess) => Promise<void> | void;
|
|
8
8
|
}
|
|
9
9
|
|
|
10
|
-
|
|
11
|
-
__rivetWriteMode: <T>(callback: () => Promise<T> | T) => Promise<T>;
|
|
12
|
-
};
|
|
10
|
+
const MIGRATION_LEASE_TIMEOUT_MS = 60_000;
|
|
13
11
|
|
|
14
12
|
function hasMultipleStatements(query: string): boolean {
|
|
15
13
|
const trimmed = query.trim().replace(/;+$/, "").trimEnd();
|
|
@@ -30,6 +28,7 @@ export function db({
|
|
|
30
28
|
|
|
31
29
|
const db = await nativeDatabaseProvider.open(ctx.actorId);
|
|
32
30
|
let closed = false;
|
|
31
|
+
let transactionActive = false;
|
|
33
32
|
const ensureOpen = () => {
|
|
34
33
|
if (closed) {
|
|
35
34
|
throw new Error(
|
|
@@ -38,7 +37,10 @@ export function db({
|
|
|
38
37
|
}
|
|
39
38
|
};
|
|
40
39
|
|
|
41
|
-
const
|
|
40
|
+
const createClient = (lease?: {
|
|
41
|
+
key: string;
|
|
42
|
+
timeoutMs?: number;
|
|
43
|
+
}): RawAccess => ({
|
|
42
44
|
execute: async <
|
|
43
45
|
TRow extends Record<string, unknown> = Record<
|
|
44
46
|
string,
|
|
@@ -49,6 +51,11 @@ export function db({
|
|
|
49
51
|
...args: unknown[]
|
|
50
52
|
): Promise<TRow[]> => {
|
|
51
53
|
ensureOpen();
|
|
54
|
+
if (!lease && transactionActive) {
|
|
55
|
+
throw new Error(
|
|
56
|
+
"Use the tx argument inside db.transaction(); the outer database client cannot run work from the transaction callback.",
|
|
57
|
+
);
|
|
58
|
+
}
|
|
52
59
|
|
|
53
60
|
const kvReadsBefore = ctx.metrics?.totalKvReads ?? 0;
|
|
54
61
|
const kvWritesBefore = ctx.metrics?.totalKvWrites ?? 0;
|
|
@@ -64,6 +71,7 @@ export function db({
|
|
|
64
71
|
const { rows, columns } = await db.execute(
|
|
65
72
|
query,
|
|
66
73
|
bindings,
|
|
74
|
+
lease,
|
|
67
75
|
);
|
|
68
76
|
return rows.map((row) =>
|
|
69
77
|
rowToObject<TRow>(row, columns),
|
|
@@ -71,13 +79,17 @@ export function db({
|
|
|
71
79
|
}
|
|
72
80
|
|
|
73
81
|
if (!hasMultipleStatements(query)) {
|
|
74
|
-
const { rows, columns } = await db.execute(
|
|
82
|
+
const { rows, columns } = await db.execute(
|
|
83
|
+
query,
|
|
84
|
+
undefined,
|
|
85
|
+
lease,
|
|
86
|
+
);
|
|
75
87
|
return rows.map((row) =>
|
|
76
88
|
rowToObject<TRow>(row, columns),
|
|
77
89
|
);
|
|
78
90
|
}
|
|
79
91
|
|
|
80
|
-
return await execMultiStatement<TRow>(db, query);
|
|
92
|
+
return await execMultiStatement<TRow>(db, query, lease);
|
|
81
93
|
} finally {
|
|
82
94
|
const durationMs = performance.now() - start;
|
|
83
95
|
ctx.metrics?.trackSql(query, durationMs);
|
|
@@ -96,6 +108,48 @@ export function db({
|
|
|
96
108
|
}
|
|
97
109
|
}
|
|
98
110
|
},
|
|
111
|
+
transaction: async <T>(
|
|
112
|
+
callback: (tx: RawAccess) => Promise<T> | T,
|
|
113
|
+
): Promise<T> => {
|
|
114
|
+
if (lease || transactionActive) {
|
|
115
|
+
throw new Error(
|
|
116
|
+
"Nested or concurrent db.transaction() calls are not supported.",
|
|
117
|
+
);
|
|
118
|
+
}
|
|
119
|
+
const transactionLease = { key: crypto.randomUUID() };
|
|
120
|
+
const tx = createClient(transactionLease);
|
|
121
|
+
await db.execute("BEGIN", undefined, transactionLease);
|
|
122
|
+
transactionActive = true;
|
|
123
|
+
try {
|
|
124
|
+
const result = await callback(tx);
|
|
125
|
+
await db.execute("COMMIT", undefined, transactionLease);
|
|
126
|
+
return result;
|
|
127
|
+
} catch (error) {
|
|
128
|
+
try {
|
|
129
|
+
await db.execute(
|
|
130
|
+
"ROLLBACK",
|
|
131
|
+
undefined,
|
|
132
|
+
transactionLease,
|
|
133
|
+
);
|
|
134
|
+
} catch {
|
|
135
|
+
// A deadline poisons the lease key, so its cleanup rollback is
|
|
136
|
+
// expected to fail. Preserve the callback or commit error.
|
|
137
|
+
}
|
|
138
|
+
throw error;
|
|
139
|
+
} finally {
|
|
140
|
+
transactionActive = false;
|
|
141
|
+
}
|
|
142
|
+
},
|
|
143
|
+
__withSqliteLease: async <T>(
|
|
144
|
+
timeoutMs: number,
|
|
145
|
+
callback: (leased: RawAccess) => Promise<T> | T,
|
|
146
|
+
): Promise<T> => {
|
|
147
|
+
const internalLease = {
|
|
148
|
+
key: crypto.randomUUID(),
|
|
149
|
+
timeoutMs,
|
|
150
|
+
};
|
|
151
|
+
return await callback(createClient(internalLease));
|
|
152
|
+
},
|
|
99
153
|
close: async () => {
|
|
100
154
|
if (!closed) {
|
|
101
155
|
closed = true;
|
|
@@ -103,17 +157,15 @@ export function db({
|
|
|
103
157
|
}
|
|
104
158
|
},
|
|
105
159
|
nativeMetrics: () => db.nativeMetrics?.() ?? null,
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
): Promise<T> => {
|
|
109
|
-
return await db.writeMode(async () => await callback());
|
|
110
|
-
},
|
|
111
|
-
};
|
|
160
|
+
});
|
|
161
|
+
const client = createClient();
|
|
112
162
|
return client;
|
|
113
163
|
},
|
|
114
164
|
onMigrate: async (client) => {
|
|
115
165
|
if (onMigrate) {
|
|
116
|
-
await
|
|
166
|
+
await withMigrationSavepoint(client, (leased) =>
|
|
167
|
+
onMigrate(leased),
|
|
168
|
+
);
|
|
117
169
|
}
|
|
118
170
|
},
|
|
119
171
|
};
|
|
@@ -133,29 +185,47 @@ function rowToObject<TRow extends Record<string, unknown>>(
|
|
|
133
185
|
async function execMultiStatement<TRow extends Record<string, unknown>>(
|
|
134
186
|
db: SqliteDatabase,
|
|
135
187
|
query: string,
|
|
188
|
+
lease?: { key: string; timeoutMs?: number },
|
|
136
189
|
): Promise<TRow[]> {
|
|
137
190
|
const results: Record<string, unknown>[] = [];
|
|
138
191
|
let columnNames: string[] | null = null;
|
|
139
|
-
await db.exec(
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
192
|
+
await db.exec(
|
|
193
|
+
query,
|
|
194
|
+
(row: unknown[], columns: string[]) => {
|
|
195
|
+
if (!columnNames) {
|
|
196
|
+
columnNames = columns;
|
|
197
|
+
}
|
|
198
|
+
results.push(rowToObject(row, columnNames));
|
|
199
|
+
},
|
|
200
|
+
lease,
|
|
201
|
+
);
|
|
145
202
|
return results as TRow[];
|
|
146
203
|
}
|
|
147
204
|
|
|
148
|
-
async function
|
|
205
|
+
async function withMigrationSavepoint<T>(
|
|
149
206
|
client: RawAccess,
|
|
150
|
-
callback: () => Promise<T> | T,
|
|
207
|
+
callback: (leased: RawAccess) => Promise<T> | T,
|
|
151
208
|
): Promise<T> {
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
209
|
+
return await client.__withSqliteLease(
|
|
210
|
+
MIGRATION_LEASE_TIMEOUT_MS,
|
|
211
|
+
async (leased) => {
|
|
212
|
+
await leased.execute("SAVEPOINT __rivet_on_migrate");
|
|
213
|
+
try {
|
|
214
|
+
const result = await callback(leased);
|
|
215
|
+
await leased.execute("RELEASE SAVEPOINT __rivet_on_migrate");
|
|
216
|
+
return result;
|
|
217
|
+
} catch (error) {
|
|
218
|
+
try {
|
|
219
|
+
await leased.execute(
|
|
220
|
+
"ROLLBACK TO SAVEPOINT __rivet_on_migrate",
|
|
221
|
+
);
|
|
222
|
+
} finally {
|
|
223
|
+
await leased.execute(
|
|
224
|
+
"RELEASE SAVEPOINT __rivet_on_migrate",
|
|
225
|
+
);
|
|
226
|
+
}
|
|
227
|
+
throw error;
|
|
228
|
+
}
|
|
229
|
+
},
|
|
230
|
+
);
|
|
161
231
|
}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { describe, expect, test } from "vitest";
|
|
2
|
+
import { BRIDGE_RIVET_ERROR_PREFIX } from "@/actor/errors";
|
|
2
3
|
import {
|
|
3
4
|
type JsNativeDatabaseLike,
|
|
4
5
|
wrapJsNativeDatabase,
|
|
@@ -64,6 +65,14 @@ class FakeNativeDatabase implements JsNativeDatabaseLike {
|
|
|
64
65
|
});
|
|
65
66
|
}
|
|
66
67
|
|
|
68
|
+
rejectNext(error: unknown) {
|
|
69
|
+
const pending = this.#pending.shift();
|
|
70
|
+
if (!pending) {
|
|
71
|
+
throw new Error("no pending native execute call");
|
|
72
|
+
}
|
|
73
|
+
pending.reject(error);
|
|
74
|
+
}
|
|
75
|
+
|
|
67
76
|
async #startExecute(
|
|
68
77
|
sql: string,
|
|
69
78
|
params: NativeParams,
|
|
@@ -104,28 +113,6 @@ describe("wrapJsNativeDatabase", () => {
|
|
|
104
113
|
});
|
|
105
114
|
});
|
|
106
115
|
|
|
107
|
-
test("keeps write mode on the normal native execute lane", async () => {
|
|
108
|
-
const native = new FakeNativeDatabase();
|
|
109
|
-
const db = wrapJsNativeDatabase(native);
|
|
110
|
-
|
|
111
|
-
const query = db.writeMode(async () => {
|
|
112
|
-
const promise = db.query("SELECT 1");
|
|
113
|
-
expect(native.executeCalls).toMatchObject([
|
|
114
|
-
{ sql: "SELECT 1", write: false },
|
|
115
|
-
]);
|
|
116
|
-
native.resolveNext({
|
|
117
|
-
columns: ["value"],
|
|
118
|
-
rows: [[1]],
|
|
119
|
-
});
|
|
120
|
-
return await promise;
|
|
121
|
-
});
|
|
122
|
-
|
|
123
|
-
await expect(query).resolves.toEqual({
|
|
124
|
-
columns: ["value"],
|
|
125
|
-
rows: [[1]],
|
|
126
|
-
});
|
|
127
|
-
});
|
|
128
|
-
|
|
129
116
|
test("normalizes supported sqlite bind values", async () => {
|
|
130
117
|
const native = new FakeNativeDatabase();
|
|
131
118
|
const db = wrapJsNativeDatabase(native);
|
|
@@ -195,4 +182,30 @@ describe("wrapJsNativeDatabase", () => {
|
|
|
195
182
|
"Database is closed",
|
|
196
183
|
);
|
|
197
184
|
});
|
|
185
|
+
|
|
186
|
+
test("decodes sanitized native bridge errors without logging", async () => {
|
|
187
|
+
const native = new FakeNativeDatabase();
|
|
188
|
+
const db = wrapJsNativeDatabase(native);
|
|
189
|
+
const query = db.execute("SELECT broken", [1, "two"]);
|
|
190
|
+
const bridgeReason = `${BRIDGE_RIVET_ERROR_PREFIX}${JSON.stringify({
|
|
191
|
+
group: "rivetkit",
|
|
192
|
+
code: "internal_error",
|
|
193
|
+
message: "An internal error occurred",
|
|
194
|
+
statusCode: 500,
|
|
195
|
+
})}`;
|
|
196
|
+
|
|
197
|
+
native.rejectNext(new Error(bridgeReason));
|
|
198
|
+
|
|
199
|
+
await expect(query).rejects.toMatchObject({
|
|
200
|
+
name: "RivetError",
|
|
201
|
+
group: "rivetkit",
|
|
202
|
+
code: "internal_error",
|
|
203
|
+
message: "An internal error occurred",
|
|
204
|
+
});
|
|
205
|
+
|
|
206
|
+
await query.catch((error) => {
|
|
207
|
+
expect(error.stack).toContain("decodeBridgeRivetError");
|
|
208
|
+
expect(error.stack).toContain("enrichNativeDatabaseError");
|
|
209
|
+
});
|
|
210
|
+
});
|
|
198
211
|
});
|
|
@@ -3,6 +3,7 @@ import type {
|
|
|
3
3
|
SqliteBindings,
|
|
4
4
|
SqliteDatabase,
|
|
5
5
|
SqliteExecuteResult,
|
|
6
|
+
SqliteLeaseOptions,
|
|
6
7
|
SqliteNativeMetrics,
|
|
7
8
|
} from "./config";
|
|
8
9
|
|
|
@@ -66,10 +67,16 @@ interface NativeExecuteResult {
|
|
|
66
67
|
}
|
|
67
68
|
|
|
68
69
|
export interface JsNativeDatabaseLike {
|
|
69
|
-
exec(
|
|
70
|
+
exec(
|
|
71
|
+
sql: string,
|
|
72
|
+
leaseKey?: string,
|
|
73
|
+
leaseTimeoutMs?: number,
|
|
74
|
+
): Promise<NativeExecResult>;
|
|
70
75
|
execute(
|
|
71
76
|
sql: string,
|
|
72
77
|
params?: NativeBindParam[] | null,
|
|
78
|
+
leaseKey?: string,
|
|
79
|
+
leaseTimeoutMs?: number,
|
|
73
80
|
): Promise<NativeExecuteResult>;
|
|
74
81
|
query(
|
|
75
82
|
sql: string,
|
|
@@ -92,12 +99,16 @@ function enrichNativeDatabaseError(
|
|
|
92
99
|
database: JsNativeDatabaseLike,
|
|
93
100
|
error: unknown,
|
|
94
101
|
): never {
|
|
95
|
-
const
|
|
102
|
+
const bridgeReason =
|
|
96
103
|
typeof error === "string"
|
|
97
|
-
?
|
|
104
|
+
? error
|
|
98
105
|
: error instanceof Error
|
|
99
|
-
?
|
|
106
|
+
? error.message
|
|
100
107
|
: undefined;
|
|
108
|
+
const bridged =
|
|
109
|
+
bridgeReason === undefined
|
|
110
|
+
? undefined
|
|
111
|
+
: decodeBridgeRivetError(bridgeReason);
|
|
101
112
|
if (bridged) {
|
|
102
113
|
throw bridged;
|
|
103
114
|
}
|
|
@@ -286,6 +297,7 @@ export function wrapJsNativeDatabase(
|
|
|
286
297
|
const executeNative = async (
|
|
287
298
|
sql: string,
|
|
288
299
|
params?: SqliteBindings,
|
|
300
|
+
lease?: SqliteLeaseOptions,
|
|
289
301
|
): Promise<SqliteExecuteResult> => {
|
|
290
302
|
const lastInsertRowIdColumn = lastInsertRowIdColumnName(sql);
|
|
291
303
|
if (lastInsertRowIdColumn) {
|
|
@@ -300,7 +312,12 @@ export function wrapJsNativeDatabase(
|
|
|
300
312
|
const release = gate.enter();
|
|
301
313
|
try {
|
|
302
314
|
const nativeParams = toNativeBindings(sql, params);
|
|
303
|
-
const result = await database.execute(
|
|
315
|
+
const result = await database.execute(
|
|
316
|
+
sql,
|
|
317
|
+
nativeParams,
|
|
318
|
+
lease?.key,
|
|
319
|
+
lease?.timeoutMs,
|
|
320
|
+
);
|
|
304
321
|
if (result.lastInsertRowId !== undefined) {
|
|
305
322
|
lastInsertRowId = result.lastInsertRowId;
|
|
306
323
|
}
|
|
@@ -316,11 +333,12 @@ export function wrapJsNativeDatabase(
|
|
|
316
333
|
async exec(
|
|
317
334
|
sql: string,
|
|
318
335
|
callback?: (row: unknown[], columns: string[]) => void,
|
|
336
|
+
lease?: SqliteLeaseOptions,
|
|
319
337
|
): Promise<void> {
|
|
320
338
|
const release = gate.enter();
|
|
321
339
|
let result: NativeExecResult;
|
|
322
340
|
try {
|
|
323
|
-
result = await database.exec(sql);
|
|
341
|
+
result = await database.exec(sql, lease?.key, lease?.timeoutMs);
|
|
324
342
|
} catch (error) {
|
|
325
343
|
enrichNativeDatabaseError(database, error);
|
|
326
344
|
} finally {
|
|
@@ -336,8 +354,9 @@ export function wrapJsNativeDatabase(
|
|
|
336
354
|
async execute(
|
|
337
355
|
sql: string,
|
|
338
356
|
params?: SqliteBindings,
|
|
357
|
+
lease?: SqliteLeaseOptions,
|
|
339
358
|
): Promise<SqliteExecuteResult> {
|
|
340
|
-
return await executeNative(sql, params);
|
|
359
|
+
return await executeNative(sql, params, lease);
|
|
341
360
|
},
|
|
342
361
|
async run(sql: string, params?: SqliteBindings): Promise<void> {
|
|
343
362
|
await executeNative(sql, params);
|
|
@@ -346,9 +365,6 @@ export function wrapJsNativeDatabase(
|
|
|
346
365
|
const { columns, rows } = await executeNative(sql, params);
|
|
347
366
|
return { columns, rows };
|
|
348
367
|
},
|
|
349
|
-
async writeMode<T>(callback: () => Promise<T>): Promise<T> {
|
|
350
|
-
return await callback();
|
|
351
|
-
},
|
|
352
368
|
nativeMetrics(): SqliteNativeMetrics | null {
|
|
353
369
|
return normalizeNativeMetrics(database.metrics?.());
|
|
354
370
|
},
|