rivetkit 0.0.0-sqlite-uds.4e59a38 → 0.0.0-sqlite-uds.2015d80
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.js +1 -1
- package/dist/browser/client.js.map +1 -1
- package/dist/browser/inspector/client.js +1 -1
- package/dist/browser/inspector/client.js.map +1 -1
- package/dist/tsup/agent-os/index.cjs +15 -1
- package/dist/tsup/agent-os/index.cjs.map +1 -1
- package/dist/tsup/agent-os/index.js +15 -1
- package/dist/tsup/agent-os/index.js.map +1 -1
- package/dist/tsup/{chunk-KTNBYGRU.js → chunk-5NJB7EE2.js} +2 -2
- package/dist/tsup/{chunk-PRXTIERO.cjs → chunk-5RC3H5MH.cjs} +2 -2
- package/dist/tsup/{chunk-PRXTIERO.cjs.map → chunk-5RC3H5MH.cjs.map} +1 -1
- package/dist/tsup/{chunk-62LSMTP2.cjs → chunk-CKKFRK2T.cjs} +3 -3
- package/dist/tsup/{chunk-62LSMTP2.cjs.map → chunk-CKKFRK2T.cjs.map} +1 -1
- package/dist/tsup/{chunk-GMN45CQ6.cjs → chunk-COPUTOJF.cjs} +7 -7
- package/dist/tsup/{chunk-GMN45CQ6.cjs.map → chunk-COPUTOJF.cjs.map} +1 -1
- package/dist/tsup/{chunk-IB73AMGJ.js → chunk-D5TT3ZDY.js} +2 -2
- package/dist/tsup/{chunk-WRZEVVLL.js → chunk-DNGOGOHS.js} +3 -3
- package/dist/tsup/{chunk-GEYQLGXC.cjs → chunk-HV4FLJQR.cjs} +139 -139
- package/dist/tsup/{chunk-GEYQLGXC.cjs.map → chunk-HV4FLJQR.cjs.map} +1 -1
- package/dist/tsup/{chunk-I336PMWT.cjs → chunk-IVUL2OMZ.cjs} +4 -4
- package/dist/tsup/{chunk-I336PMWT.cjs.map → chunk-IVUL2OMZ.cjs.map} +1 -1
- package/dist/tsup/{chunk-XAIMHUPG.js → chunk-MUPT34DY.js} +4 -4
- package/dist/tsup/{chunk-ITWJ6Y7G.js → chunk-VBASTLLY.js} +2 -2
- package/dist/tsup/{chunk-7IVUT2JT.js → chunk-VL3UZ6XX.js} +4 -4
- package/dist/tsup/{chunk-OUDV3ITX.cjs → chunk-VP3RWGXE.cjs} +5 -5
- package/dist/tsup/{chunk-OUDV3ITX.cjs.map → chunk-VP3RWGXE.cjs.map} +1 -1
- package/dist/tsup/{chunk-XZ62SWSC.js → chunk-XPXLCL5I.js} +2 -2
- package/dist/tsup/{chunk-XZ62SWSC.js.map → chunk-XPXLCL5I.js.map} +1 -1
- package/dist/tsup/{chunk-3GC3EP6D.cjs → chunk-YPIVGZVX.cjs} +10 -10
- package/dist/tsup/{chunk-3GC3EP6D.cjs.map → chunk-YPIVGZVX.cjs.map} +1 -1
- package/dist/tsup/client/mod.cjs +6 -6
- package/dist/tsup/client/mod.js +5 -5
- package/dist/tsup/common/log.cjs +2 -2
- package/dist/tsup/common/log.js +1 -1
- package/dist/tsup/common/websocket.cjs +3 -3
- package/dist/tsup/common/websocket.js +2 -2
- package/dist/tsup/db/drizzle.cjs +14 -0
- package/dist/tsup/db/drizzle.cjs.map +1 -1
- package/dist/tsup/db/drizzle.d.cts +3 -1
- package/dist/tsup/db/drizzle.d.ts +3 -1
- package/dist/tsup/db/drizzle.js +14 -0
- package/dist/tsup/db/drizzle.js.map +1 -1
- package/dist/tsup/db/mod.cjs +14 -0
- package/dist/tsup/db/mod.cjs.map +1 -1
- package/dist/tsup/db/mod.js +14 -0
- package/dist/tsup/db/mod.js.map +1 -1
- package/dist/tsup/inspector/mod.cjs +5 -5
- package/dist/tsup/inspector/mod.js +4 -4
- package/dist/tsup/mod.cjs +62 -62
- package/dist/tsup/mod.js +5 -5
- package/dist/tsup/test/mod.cjs +9 -9
- package/dist/tsup/test/mod.js +5 -5
- package/dist/tsup/utils.cjs +2 -2
- package/dist/tsup/utils.js +1 -1
- package/dist/tsup/workflow/mod.cjs +7 -7
- package/dist/tsup/workflow/mod.js +4 -4
- package/package.json +8 -8
- package/src/common/bare/generated/actor-uds-protocol/v1.ts +802 -0
- package/src/common/database/mod.test.ts +54 -0
- package/src/common/database/mod.ts +14 -0
- package/src/db/drizzle.ts +24 -2
- /package/dist/tsup/{chunk-KTNBYGRU.js.map → chunk-5NJB7EE2.js.map} +0 -0
- /package/dist/tsup/{chunk-IB73AMGJ.js.map → chunk-D5TT3ZDY.js.map} +0 -0
- /package/dist/tsup/{chunk-WRZEVVLL.js.map → chunk-DNGOGOHS.js.map} +0 -0
- /package/dist/tsup/{chunk-XAIMHUPG.js.map → chunk-MUPT34DY.js.map} +0 -0
- /package/dist/tsup/{chunk-ITWJ6Y7G.js.map → chunk-VBASTLLY.js.map} +0 -0
- /package/dist/tsup/{chunk-7IVUT2JT.js.map → chunk-VL3UZ6XX.js.map} +0 -0
|
@@ -9,6 +9,7 @@ import type {
|
|
|
9
9
|
import { db } from "./mod";
|
|
10
10
|
|
|
11
11
|
class FakeSqliteDatabase implements SqliteDatabase {
|
|
12
|
+
failSql = new Map<string, Error>();
|
|
12
13
|
executeCalls: {
|
|
13
14
|
sql: string;
|
|
14
15
|
params?: SqliteBindings;
|
|
@@ -27,6 +28,10 @@ class FakeSqliteDatabase implements SqliteDatabase {
|
|
|
27
28
|
params,
|
|
28
29
|
lease,
|
|
29
30
|
});
|
|
31
|
+
const error = this.failSql.get(sql);
|
|
32
|
+
if (error) {
|
|
33
|
+
throw error;
|
|
34
|
+
}
|
|
30
35
|
return {
|
|
31
36
|
columns: [],
|
|
32
37
|
rows: [],
|
|
@@ -169,4 +174,53 @@ describe("db", () => {
|
|
|
169
174
|
true,
|
|
170
175
|
);
|
|
171
176
|
});
|
|
177
|
+
|
|
178
|
+
test("rolls back a transaction when the callback throws", async () => {
|
|
179
|
+
const nativeDb = new FakeSqliteDatabase();
|
|
180
|
+
const client = await db().createClient(testProviderContext(nativeDb));
|
|
181
|
+
|
|
182
|
+
await expect(
|
|
183
|
+
client.transaction(async (tx) => {
|
|
184
|
+
await tx.execute("INSERT INTO items(value) VALUES (?)", "inside");
|
|
185
|
+
throw new Error("callback failed");
|
|
186
|
+
}),
|
|
187
|
+
).rejects.toThrow("callback failed");
|
|
188
|
+
|
|
189
|
+
expect(nativeDb.executeCalls.map((call) => call.sql)).toEqual([
|
|
190
|
+
"BEGIN",
|
|
191
|
+
"INSERT INTO items(value) VALUES (?)",
|
|
192
|
+
"ROLLBACK",
|
|
193
|
+
]);
|
|
194
|
+
});
|
|
195
|
+
|
|
196
|
+
test("rejects use of the outer client inside a transaction callback", async () => {
|
|
197
|
+
const nativeDb = new FakeSqliteDatabase();
|
|
198
|
+
const client = await db().createClient(testProviderContext(nativeDb));
|
|
199
|
+
|
|
200
|
+
await expect(
|
|
201
|
+
client.transaction(async () => {
|
|
202
|
+
await client.execute("INSERT INTO items(value) VALUES ('outside')");
|
|
203
|
+
}),
|
|
204
|
+
).rejects.toThrow("Use the tx argument");
|
|
205
|
+
|
|
206
|
+
expect(nativeDb.executeCalls.map((call) => call.sql)).toEqual([
|
|
207
|
+
"BEGIN",
|
|
208
|
+
"ROLLBACK",
|
|
209
|
+
]);
|
|
210
|
+
});
|
|
211
|
+
|
|
212
|
+
test("surfaces a lease-expired commit error", async () => {
|
|
213
|
+
const nativeDb = new FakeSqliteDatabase();
|
|
214
|
+
nativeDb.failSql.set("COMMIT", new Error("LeaseExpired"));
|
|
215
|
+
const client = await db().createClient(testProviderContext(nativeDb));
|
|
216
|
+
|
|
217
|
+
await expect(client.transaction(async () => 42)).rejects.toThrow(
|
|
218
|
+
"LeaseExpired",
|
|
219
|
+
);
|
|
220
|
+
expect(nativeDb.executeCalls.map((call) => call.sql)).toEqual([
|
|
221
|
+
"BEGIN",
|
|
222
|
+
"COMMIT",
|
|
223
|
+
"ROLLBACK",
|
|
224
|
+
]);
|
|
225
|
+
});
|
|
172
226
|
});
|
|
@@ -28,6 +28,7 @@ export function db({
|
|
|
28
28
|
|
|
29
29
|
const db = await nativeDatabaseProvider.open(ctx.actorId);
|
|
30
30
|
let closed = false;
|
|
31
|
+
let transactionActive = false;
|
|
31
32
|
const ensureOpen = () => {
|
|
32
33
|
if (closed) {
|
|
33
34
|
throw new Error(
|
|
@@ -50,6 +51,11 @@ export function db({
|
|
|
50
51
|
...args: unknown[]
|
|
51
52
|
): Promise<TRow[]> => {
|
|
52
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
|
+
}
|
|
53
59
|
|
|
54
60
|
const kvReadsBefore = ctx.metrics?.totalKvReads ?? 0;
|
|
55
61
|
const kvWritesBefore = ctx.metrics?.totalKvWrites ?? 0;
|
|
@@ -105,9 +111,15 @@ export function db({
|
|
|
105
111
|
transaction: async <T>(
|
|
106
112
|
callback: (tx: RawAccess) => Promise<T> | T,
|
|
107
113
|
): Promise<T> => {
|
|
114
|
+
if (lease || transactionActive) {
|
|
115
|
+
throw new Error(
|
|
116
|
+
"Nested or concurrent db.transaction() calls are not supported.",
|
|
117
|
+
);
|
|
118
|
+
}
|
|
108
119
|
const transactionLease = { key: crypto.randomUUID() };
|
|
109
120
|
const tx = createClient(transactionLease);
|
|
110
121
|
await db.execute("BEGIN", undefined, transactionLease);
|
|
122
|
+
transactionActive = true;
|
|
111
123
|
try {
|
|
112
124
|
const result = await callback(tx);
|
|
113
125
|
await db.execute("COMMIT", undefined, transactionLease);
|
|
@@ -124,6 +136,8 @@ export function db({
|
|
|
124
136
|
// expected to fail. Preserve the callback or commit error.
|
|
125
137
|
}
|
|
126
138
|
throw error;
|
|
139
|
+
} finally {
|
|
140
|
+
transactionActive = false;
|
|
127
141
|
}
|
|
128
142
|
},
|
|
129
143
|
__withSqliteLease: async <T>(
|
package/src/db/drizzle.ts
CHANGED
|
@@ -32,7 +32,13 @@ type DrizzleDatabase<TSchema extends DrizzleSchema> = Omit<
|
|
|
32
32
|
SqliteRemoteDatabase<TSchema>,
|
|
33
33
|
"transaction"
|
|
34
34
|
> &
|
|
35
|
-
RawAccess
|
|
35
|
+
Omit<RawAccess, "transaction"> & {
|
|
36
|
+
transaction: <T>(
|
|
37
|
+
callback: (
|
|
38
|
+
tx: DrizzleDatabase<TSchema>,
|
|
39
|
+
) => Promise<T> | T,
|
|
40
|
+
) => Promise<T>;
|
|
41
|
+
};
|
|
36
42
|
|
|
37
43
|
const MIGRATION_LEASE_TIMEOUT_MS = 60_000;
|
|
38
44
|
|
|
@@ -95,6 +101,7 @@ export function db<TSchema extends DrizzleSchema = Record<string, never>>({
|
|
|
95
101
|
|
|
96
102
|
const nativeDb = await nativeDatabaseProvider.open(ctx.actorId);
|
|
97
103
|
let closed = false;
|
|
104
|
+
let transactionActive = false;
|
|
98
105
|
const ensureOpen = () => {
|
|
99
106
|
if (closed) {
|
|
100
107
|
throw new Error(
|
|
@@ -113,6 +120,11 @@ export function db<TSchema extends DrizzleSchema = Record<string, never>>({
|
|
|
113
120
|
method: "run" | "all" | "values" | "get",
|
|
114
121
|
) => {
|
|
115
122
|
ensureOpen();
|
|
123
|
+
if (!lease && transactionActive) {
|
|
124
|
+
throw new Error(
|
|
125
|
+
"Use the tx argument inside db.transaction(); the outer database client cannot run work from the transaction callback.",
|
|
126
|
+
);
|
|
127
|
+
}
|
|
116
128
|
|
|
117
129
|
const start = performance.now();
|
|
118
130
|
const kvReadsBefore = ctx.metrics?.totalKvReads ?? 0;
|
|
@@ -177,8 +189,15 @@ export function db<TSchema extends DrizzleSchema = Record<string, never>>({
|
|
|
177
189
|
);
|
|
178
190
|
};
|
|
179
191
|
drizzleDb.transaction = async <T>(
|
|
180
|
-
transactionCallback: (
|
|
192
|
+
transactionCallback: (
|
|
193
|
+
tx: DrizzleDatabase<TSchema>,
|
|
194
|
+
) => Promise<T> | T,
|
|
181
195
|
): Promise<T> => {
|
|
196
|
+
if (lease || transactionActive) {
|
|
197
|
+
throw new Error(
|
|
198
|
+
"Nested or concurrent db.transaction() calls are not supported.",
|
|
199
|
+
);
|
|
200
|
+
}
|
|
182
201
|
const transactionLease = { key: crypto.randomUUID() };
|
|
183
202
|
const tx = createDrizzleClient(transactionLease);
|
|
184
203
|
await nativeDb.execute(
|
|
@@ -186,6 +205,7 @@ export function db<TSchema extends DrizzleSchema = Record<string, never>>({
|
|
|
186
205
|
undefined,
|
|
187
206
|
transactionLease,
|
|
188
207
|
);
|
|
208
|
+
transactionActive = true;
|
|
189
209
|
try {
|
|
190
210
|
const result = await transactionCallback(tx);
|
|
191
211
|
await nativeDb.execute(
|
|
@@ -205,6 +225,8 @@ export function db<TSchema extends DrizzleSchema = Record<string, never>>({
|
|
|
205
225
|
// Preserve the callback or commit error after lease poisoning.
|
|
206
226
|
}
|
|
207
227
|
throw error;
|
|
228
|
+
} finally {
|
|
229
|
+
transactionActive = false;
|
|
208
230
|
}
|
|
209
231
|
};
|
|
210
232
|
drizzleDb.__withSqliteLease = async <T>(
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|