rivetkit 0.0.0-sqlite-uds.37f9e48 → 0.0.0-sqlite-profiling-compat.4a9a623
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 +28 -23
- package/dist/browser/client.js +6 -9
- package/dist/browser/client.js.map +1 -1
- package/dist/browser/inspector/client.d.ts +2 -22
- package/dist/browser/inspector/client.js +222 -996
- package/dist/browser/inspector/client.js.map +1 -1
- package/dist/tsup/actor/errors.cjs.map +1 -1
- package/dist/tsup/agent-os/index.cjs +34 -104
- package/dist/tsup/agent-os/index.cjs.map +1 -1
- package/dist/tsup/agent-os/index.d.cts +28 -23
- package/dist/tsup/agent-os/index.d.ts +28 -23
- package/dist/tsup/agent-os/index.js +36 -106
- package/dist/tsup/agent-os/index.js.map +1 -1
- package/dist/tsup/{chunk-UEDIZR2M.cjs → chunk-2CICCOBL.cjs} +4 -24
- package/dist/tsup/chunk-2CICCOBL.cjs.map +1 -0
- package/dist/tsup/{chunk-PVR4LVX2.cjs → chunk-2WMYYG4R.cjs} +10 -18
- package/dist/tsup/chunk-2WMYYG4R.cjs.map +1 -0
- package/dist/tsup/{chunk-HTREBONF.cjs → chunk-3MHDOUD7.cjs} +1 -6
- package/dist/tsup/chunk-3MHDOUD7.cjs.map +1 -0
- package/dist/tsup/chunk-4FC7TVS6.cjs.map +1 -1
- package/dist/tsup/{chunk-DB45WHMU.js → chunk-4PX3ZKJR.js} +3 -3
- package/dist/tsup/{chunk-FFJXFXEW.js → chunk-75UE45DE.js} +7 -11
- package/dist/tsup/chunk-75UE45DE.js.map +1 -0
- package/dist/tsup/{chunk-MFLAOS2S.cjs → chunk-7QKCGUTJ.cjs} +8 -12
- package/dist/tsup/chunk-7QKCGUTJ.cjs.map +1 -0
- package/dist/tsup/{chunk-2EYF7KY7.js → chunk-AGDY6TKH.js} +7 -7
- package/dist/tsup/{chunk-UEYBIN52.js → chunk-IICIOTML.js} +2 -2
- package/dist/tsup/{chunk-AGWIB6VG.cjs → chunk-ND567FR5.cjs} +3 -3
- package/dist/tsup/chunk-ND567FR5.cjs.map +1 -0
- package/dist/tsup/{chunk-OSQX3QN2.cjs → chunk-NHUTYWKU.cjs} +141 -141
- package/dist/tsup/chunk-NHUTYWKU.cjs.map +1 -0
- package/dist/tsup/{chunk-42H5OK5Z.cjs → chunk-QAVN4QNO.cjs} +7 -7
- package/dist/tsup/chunk-QAVN4QNO.cjs.map +1 -0
- package/dist/tsup/{chunk-Q3ODMSBE.js → chunk-RIT7N3TX.js} +2 -22
- package/dist/tsup/chunk-RIT7N3TX.js.map +1 -0
- package/dist/tsup/{chunk-LIEQDMZ6.cjs → chunk-RV5MAFDT.cjs} +5 -5
- package/dist/tsup/chunk-RV5MAFDT.cjs.map +1 -0
- package/dist/tsup/chunk-VE2X4KMG.cjs.map +1 -1
- package/dist/tsup/{chunk-E4X3JSN7.js → chunk-XFYEVYHG.js} +4 -12
- package/dist/tsup/chunk-XFYEVYHG.js.map +1 -0
- package/dist/tsup/{chunk-D2JJWLWM.js → chunk-XHGDS3DZ.js} +2 -2
- package/dist/tsup/{chunk-ARD7UMSN.js → chunk-XIX5DOZN.js} +1 -6
- package/dist/tsup/chunk-XIX5DOZN.js.map +1 -0
- package/dist/tsup/chunk-ZA7FLHKH.cjs.map +1 -1
- package/dist/tsup/client/mod.cjs +7 -7
- package/dist/tsup/client/mod.cjs.map +1 -1
- package/dist/tsup/client/mod.d.cts +3 -3
- package/dist/tsup/client/mod.d.ts +3 -3
- package/dist/tsup/client/mod.js +6 -6
- package/dist/tsup/common/log.cjs +2 -4
- package/dist/tsup/common/log.cjs.map +1 -1
- package/dist/tsup/common/log.d.cts +1 -5
- package/dist/tsup/common/log.d.ts +1 -5
- package/dist/tsup/common/log.js +3 -5
- package/dist/tsup/common/websocket.cjs +3 -3
- package/dist/tsup/common/websocket.cjs.map +1 -1
- package/dist/tsup/common/websocket.js +2 -2
- package/dist/tsup/{config-DLOxy81E.d.cts → config-B0LNDrLY.d.cts} +25 -5
- package/dist/tsup/{config-DLOxy81E.d.ts → config-B0LNDrLY.d.ts} +25 -5
- package/dist/tsup/{config-BkLXikR2.d.ts → config-BR1Nn0QQ.d.ts} +5 -24
- package/dist/tsup/{config-BARPNFvr.d.cts → config-tCvkwzyN.d.cts} +5 -24
- package/dist/tsup/{context-DntnH005.d.ts → context-D4WDwf9m.d.cts} +2 -3
- package/dist/tsup/{context-A16ymKhK.d.cts → context-oc9zhA3x.d.ts} +2 -3
- package/dist/tsup/db/drizzle.cjs +72 -144
- package/dist/tsup/db/drizzle.cjs.map +1 -1
- package/dist/tsup/db/drizzle.d.cts +2 -4
- package/dist/tsup/db/drizzle.d.ts +2 -4
- package/dist/tsup/db/drizzle.js +72 -144
- package/dist/tsup/db/drizzle.js.map +1 -1
- package/dist/tsup/db/mod.cjs +28 -90
- package/dist/tsup/db/mod.cjs.map +1 -1
- package/dist/tsup/db/mod.d.cts +8 -4
- package/dist/tsup/db/mod.d.ts +8 -4
- package/dist/tsup/db/mod.js +28 -90
- package/dist/tsup/db/mod.js.map +1 -1
- package/dist/tsup/dynamic/mod.cjs +2 -2
- package/dist/tsup/dynamic/mod.cjs.map +1 -1
- package/dist/tsup/dynamic/mod.d.cts +2 -2
- package/dist/tsup/dynamic/mod.d.ts +2 -2
- package/dist/tsup/dynamic/mod.js +1 -1
- package/dist/tsup/inspector/mod.cjs +11 -46
- package/dist/tsup/inspector/mod.cjs.map +1 -1
- package/dist/tsup/inspector/mod.d.cts +15 -37
- package/dist/tsup/inspector/mod.d.ts +15 -37
- package/dist/tsup/inspector/mod.js +10 -45
- package/dist/tsup/inspector/mod.js.map +1 -1
- package/dist/tsup/inspector-tab/mod.cjs +13 -2
- package/dist/tsup/inspector-tab/mod.cjs.map +1 -1
- package/dist/tsup/inspector-tab/mod.d.cts +14 -4
- package/dist/tsup/inspector-tab/mod.d.ts +14 -4
- package/dist/tsup/inspector-tab/mod.js +12 -1
- package/dist/tsup/inspector-tab/mod.js.map +1 -1
- package/dist/tsup/mod.cjs +91 -189
- package/dist/tsup/mod.cjs.map +1 -1
- package/dist/tsup/mod.d.cts +4 -4
- package/dist/tsup/mod.d.ts +4 -4
- package/dist/tsup/mod.js +25 -123
- package/dist/tsup/mod.js.map +1 -1
- package/dist/tsup/test/mod.cjs +10 -10
- package/dist/tsup/test/mod.cjs.map +1 -1
- package/dist/tsup/test/mod.d.cts +2 -2
- package/dist/tsup/test/mod.d.ts +2 -2
- package/dist/tsup/test/mod.js +6 -6
- package/dist/tsup/utils.cjs +2 -2
- package/dist/tsup/utils.cjs.map +1 -1
- package/dist/tsup/utils.js +1 -1
- package/dist/tsup/workflow/mod.cjs +11 -14
- package/dist/tsup/workflow/mod.cjs.map +1 -1
- package/dist/tsup/workflow/mod.d.cts +4 -4
- package/dist/tsup/workflow/mod.d.ts +4 -4
- package/dist/tsup/workflow/mod.js +5 -8
- package/dist/tsup/workflow/mod.js.map +1 -1
- package/package.json +14 -9
- package/src/actor/config.ts +0 -10
- package/src/common/bare/transport/v1.ts +0 -36
- package/src/common/database/config.ts +24 -19
- package/src/common/database/mod.test.ts +2 -96
- package/src/common/database/mod.ts +38 -102
- package/src/common/database/native-database.ts +4 -19
- package/src/common/log.ts +8 -14
- package/src/db/drizzle.ts +86 -187
- package/src/db/mod.ts +1 -0
- package/src/inspector/client.browser.ts +16 -73
- package/src/inspector/mod.ts +1 -1
- package/src/inspector-tab/mod.ts +15 -0
- package/src/registry/index.ts +0 -4
- package/src/registry/napi-runtime.ts +1 -25
- package/src/registry/native.ts +13 -95
- package/src/registry/runtime.ts +6 -18
- package/src/registry/wasm-runtime.ts +0 -22
- package/src/workflow/context.ts +0 -4
- package/src/workflow/inspector.ts +0 -8
- package/dist/tsup/chunk-42H5OK5Z.cjs.map +0 -1
- package/dist/tsup/chunk-AGWIB6VG.cjs.map +0 -1
- package/dist/tsup/chunk-ARD7UMSN.js.map +0 -1
- package/dist/tsup/chunk-E4X3JSN7.js.map +0 -1
- package/dist/tsup/chunk-FFJXFXEW.js.map +0 -1
- package/dist/tsup/chunk-HTREBONF.cjs.map +0 -1
- package/dist/tsup/chunk-LIEQDMZ6.cjs.map +0 -1
- package/dist/tsup/chunk-MFLAOS2S.cjs.map +0 -1
- package/dist/tsup/chunk-OSQX3QN2.cjs.map +0 -1
- package/dist/tsup/chunk-PVR4LVX2.cjs.map +0 -1
- package/dist/tsup/chunk-Q3ODMSBE.js.map +0 -1
- package/dist/tsup/chunk-UEDIZR2M.cjs.map +0 -1
- package/src/actor/config.test.ts +0 -11
- package/src/common/bare/generated/actor-uds-protocol/v1.ts +0 -802
- package/src/common/bare/generated/inspector/v5.ts +0 -1016
- /package/dist/tsup/{chunk-DB45WHMU.js.map → chunk-4PX3ZKJR.js.map} +0 -0
- /package/dist/tsup/{chunk-2EYF7KY7.js.map → chunk-AGDY6TKH.js.map} +0 -0
- /package/dist/tsup/{chunk-UEYBIN52.js.map → chunk-IICIOTML.js.map} +0 -0
- /package/dist/tsup/{chunk-D2JJWLWM.js.map → chunk-XHGDS3DZ.js.map} +0 -0
|
@@ -4,16 +4,13 @@ import type {
|
|
|
4
4
|
SqliteBindings,
|
|
5
5
|
SqliteDatabase,
|
|
6
6
|
SqliteExecuteResult,
|
|
7
|
-
SqliteLeaseOptions,
|
|
8
7
|
} from "./config";
|
|
9
8
|
import { db } from "./mod";
|
|
10
9
|
|
|
11
10
|
class FakeSqliteDatabase implements SqliteDatabase {
|
|
12
|
-
failSql = new Map<string, Error>();
|
|
13
11
|
executeCalls: {
|
|
14
12
|
sql: string;
|
|
15
13
|
params?: SqliteBindings;
|
|
16
|
-
lease?: SqliteLeaseOptions;
|
|
17
14
|
}[] = [];
|
|
18
15
|
|
|
19
16
|
async exec(): Promise<void> {}
|
|
@@ -21,17 +18,11 @@ class FakeSqliteDatabase implements SqliteDatabase {
|
|
|
21
18
|
async execute(
|
|
22
19
|
sql: string,
|
|
23
20
|
params?: SqliteBindings,
|
|
24
|
-
lease?: SqliteLeaseOptions,
|
|
25
21
|
): Promise<SqliteExecuteResult> {
|
|
26
22
|
this.executeCalls.push({
|
|
27
23
|
sql,
|
|
28
24
|
params,
|
|
29
|
-
lease,
|
|
30
25
|
});
|
|
31
|
-
const error = this.failSql.get(sql);
|
|
32
|
-
if (error) {
|
|
33
|
-
throw error;
|
|
34
|
-
}
|
|
35
26
|
return {
|
|
36
27
|
columns: [],
|
|
37
28
|
rows: [],
|
|
@@ -86,9 +77,7 @@ describe("db", () => {
|
|
|
86
77
|
|
|
87
78
|
await provider.onMigrate(client);
|
|
88
79
|
|
|
89
|
-
expect(
|
|
90
|
-
nativeDb.executeCalls.map(({ sql, params }) => ({ sql, params })),
|
|
91
|
-
).toEqual([
|
|
80
|
+
expect(nativeDb.executeCalls).toEqual([
|
|
92
81
|
{
|
|
93
82
|
sql: "SAVEPOINT __rivet_on_migrate",
|
|
94
83
|
params: undefined,
|
|
@@ -106,9 +95,6 @@ describe("db", () => {
|
|
|
106
95
|
params: undefined,
|
|
107
96
|
},
|
|
108
97
|
]);
|
|
109
|
-
const leases = nativeDb.executeCalls.map((call) => call.lease);
|
|
110
|
-
expect(leases.every((lease) => lease?.timeoutMs === 60_000)).toBe(true);
|
|
111
|
-
expect(new Set(leases.map((lease) => lease?.key)).size).toBe(1);
|
|
112
98
|
});
|
|
113
99
|
|
|
114
100
|
test("rolls back the migration savepoint when onMigrate fails", async () => {
|
|
@@ -129,9 +115,7 @@ describe("db", () => {
|
|
|
129
115
|
"migration failed",
|
|
130
116
|
);
|
|
131
117
|
|
|
132
|
-
expect(
|
|
133
|
-
nativeDb.executeCalls.map(({ sql, params }) => ({ sql, params })),
|
|
134
|
-
).toEqual([
|
|
118
|
+
expect(nativeDb.executeCalls).toEqual([
|
|
135
119
|
{
|
|
136
120
|
sql: "SAVEPOINT __rivet_on_migrate",
|
|
137
121
|
params: undefined,
|
|
@@ -150,82 +134,4 @@ describe("db", () => {
|
|
|
150
134
|
},
|
|
151
135
|
]);
|
|
152
136
|
});
|
|
153
|
-
|
|
154
|
-
test("runs transaction work under one hidden lease", async () => {
|
|
155
|
-
const nativeDb = new FakeSqliteDatabase();
|
|
156
|
-
const provider = db();
|
|
157
|
-
const client = await provider.createClient(
|
|
158
|
-
testProviderContext(nativeDb),
|
|
159
|
-
);
|
|
160
|
-
|
|
161
|
-
const value = await client.transaction(async (tx) => {
|
|
162
|
-
await tx.execute("INSERT INTO items(value) VALUES (?)", "inside");
|
|
163
|
-
return 42;
|
|
164
|
-
});
|
|
165
|
-
|
|
166
|
-
expect(value).toBe(42);
|
|
167
|
-
expect(nativeDb.executeCalls.map((call) => call.sql)).toEqual([
|
|
168
|
-
"BEGIN",
|
|
169
|
-
"INSERT INTO items(value) VALUES (?)",
|
|
170
|
-
"COMMIT",
|
|
171
|
-
]);
|
|
172
|
-
const keys = nativeDb.executeCalls.map((call) => call.lease?.key);
|
|
173
|
-
expect(keys.every((key) => key === keys[0] && key !== undefined)).toBe(
|
|
174
|
-
true,
|
|
175
|
-
);
|
|
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(
|
|
185
|
-
"INSERT INTO items(value) VALUES (?)",
|
|
186
|
-
"inside",
|
|
187
|
-
);
|
|
188
|
-
throw new Error("callback failed");
|
|
189
|
-
}),
|
|
190
|
-
).rejects.toThrow("callback failed");
|
|
191
|
-
|
|
192
|
-
expect(nativeDb.executeCalls.map((call) => call.sql)).toEqual([
|
|
193
|
-
"BEGIN",
|
|
194
|
-
"INSERT INTO items(value) VALUES (?)",
|
|
195
|
-
"ROLLBACK",
|
|
196
|
-
]);
|
|
197
|
-
});
|
|
198
|
-
|
|
199
|
-
test("rejects use of the outer client inside a transaction callback", async () => {
|
|
200
|
-
const nativeDb = new FakeSqliteDatabase();
|
|
201
|
-
const client = await db().createClient(testProviderContext(nativeDb));
|
|
202
|
-
|
|
203
|
-
await expect(
|
|
204
|
-
client.transaction(async () => {
|
|
205
|
-
await client.execute(
|
|
206
|
-
"INSERT INTO items(value) VALUES ('outside')",
|
|
207
|
-
);
|
|
208
|
-
}),
|
|
209
|
-
).rejects.toThrow("Use the tx argument");
|
|
210
|
-
|
|
211
|
-
expect(nativeDb.executeCalls.map((call) => call.sql)).toEqual([
|
|
212
|
-
"BEGIN",
|
|
213
|
-
"ROLLBACK",
|
|
214
|
-
]);
|
|
215
|
-
});
|
|
216
|
-
|
|
217
|
-
test("surfaces a lease-expired commit error", async () => {
|
|
218
|
-
const nativeDb = new FakeSqliteDatabase();
|
|
219
|
-
nativeDb.failSql.set("COMMIT", new Error("LeaseExpired"));
|
|
220
|
-
const client = await db().createClient(testProviderContext(nativeDb));
|
|
221
|
-
|
|
222
|
-
await expect(client.transaction(async () => 42)).rejects.toThrow(
|
|
223
|
-
"LeaseExpired",
|
|
224
|
-
);
|
|
225
|
-
expect(nativeDb.executeCalls.map((call) => call.sql)).toEqual([
|
|
226
|
-
"BEGIN",
|
|
227
|
-
"COMMIT",
|
|
228
|
-
"ROLLBACK",
|
|
229
|
-
]);
|
|
230
|
-
});
|
|
231
137
|
});
|
|
@@ -1,14 +1,21 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type {
|
|
2
|
+
DatabaseProvider,
|
|
3
|
+
RawAccess,
|
|
4
|
+
SqliteDatabase,
|
|
5
|
+
SqliteProfilingOptions,
|
|
6
|
+
} from "./config";
|
|
2
7
|
import { isSqliteBindingObject, toSqliteBindings } from "./shared";
|
|
3
8
|
|
|
4
9
|
export type { RawAccess } from "./config";
|
|
5
10
|
|
|
6
|
-
interface DatabaseFactoryConfig {
|
|
11
|
+
export interface DatabaseFactoryConfig {
|
|
7
12
|
onMigrate?: (db: RawAccess) => Promise<void> | void;
|
|
13
|
+
/**
|
|
14
|
+
* @experimental This entire configuration surface is subject to change.
|
|
15
|
+
*/
|
|
16
|
+
profiling?: SqliteProfilingOptions;
|
|
8
17
|
}
|
|
9
18
|
|
|
10
|
-
const MIGRATION_LEASE_TIMEOUT_MS = 60_000;
|
|
11
|
-
|
|
12
19
|
function hasMultipleStatements(query: string): boolean {
|
|
13
20
|
const trimmed = query.trim().replace(/;+$/, "").trimEnd();
|
|
14
21
|
return trimmed.includes(";");
|
|
@@ -16,8 +23,10 @@ function hasMultipleStatements(query: string): boolean {
|
|
|
16
23
|
|
|
17
24
|
export function db({
|
|
18
25
|
onMigrate,
|
|
26
|
+
profiling,
|
|
19
27
|
}: DatabaseFactoryConfig = {}): DatabaseProvider<RawAccess> {
|
|
20
28
|
return {
|
|
29
|
+
sqliteProfiling: profiling,
|
|
21
30
|
createClient: async (ctx) => {
|
|
22
31
|
const nativeDatabaseProvider = ctx.nativeDatabaseProvider;
|
|
23
32
|
if (!nativeDatabaseProvider) {
|
|
@@ -28,7 +37,6 @@ export function db({
|
|
|
28
37
|
|
|
29
38
|
const db = await nativeDatabaseProvider.open(ctx.actorId);
|
|
30
39
|
let closed = false;
|
|
31
|
-
let transactionActive = false;
|
|
32
40
|
const ensureOpen = () => {
|
|
33
41
|
if (closed) {
|
|
34
42
|
throw new Error(
|
|
@@ -37,10 +45,7 @@ export function db({
|
|
|
37
45
|
}
|
|
38
46
|
};
|
|
39
47
|
|
|
40
|
-
const
|
|
41
|
-
key: string;
|
|
42
|
-
timeoutMs?: number;
|
|
43
|
-
}): RawAccess => ({
|
|
48
|
+
const client: RawAccess = {
|
|
44
49
|
execute: async <
|
|
45
50
|
TRow extends Record<string, unknown> = Record<
|
|
46
51
|
string,
|
|
@@ -51,11 +56,6 @@ export function db({
|
|
|
51
56
|
...args: unknown[]
|
|
52
57
|
): Promise<TRow[]> => {
|
|
53
58
|
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
|
-
}
|
|
59
59
|
|
|
60
60
|
const kvReadsBefore = ctx.metrics?.totalKvReads ?? 0;
|
|
61
61
|
const kvWritesBefore = ctx.metrics?.totalKvWrites ?? 0;
|
|
@@ -71,7 +71,6 @@ export function db({
|
|
|
71
71
|
const { rows, columns } = await db.execute(
|
|
72
72
|
query,
|
|
73
73
|
bindings,
|
|
74
|
-
lease,
|
|
75
74
|
);
|
|
76
75
|
return rows.map((row) =>
|
|
77
76
|
rowToObject<TRow>(row, columns),
|
|
@@ -79,17 +78,13 @@ export function db({
|
|
|
79
78
|
}
|
|
80
79
|
|
|
81
80
|
if (!hasMultipleStatements(query)) {
|
|
82
|
-
const { rows, columns } = await db.execute(
|
|
83
|
-
query,
|
|
84
|
-
undefined,
|
|
85
|
-
lease,
|
|
86
|
-
);
|
|
81
|
+
const { rows, columns } = await db.execute(query);
|
|
87
82
|
return rows.map((row) =>
|
|
88
83
|
rowToObject<TRow>(row, columns),
|
|
89
84
|
);
|
|
90
85
|
}
|
|
91
86
|
|
|
92
|
-
return await execMultiStatement<TRow>(db, query
|
|
87
|
+
return await execMultiStatement<TRow>(db, query);
|
|
93
88
|
} finally {
|
|
94
89
|
const durationMs = performance.now() - start;
|
|
95
90
|
ctx.metrics?.trackSql(query, durationMs);
|
|
@@ -108,48 +103,6 @@ export function db({
|
|
|
108
103
|
}
|
|
109
104
|
}
|
|
110
105
|
},
|
|
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
|
-
},
|
|
153
106
|
close: async () => {
|
|
154
107
|
if (!closed) {
|
|
155
108
|
closed = true;
|
|
@@ -157,15 +110,12 @@ export function db({
|
|
|
157
110
|
}
|
|
158
111
|
},
|
|
159
112
|
nativeMetrics: () => db.nativeMetrics?.() ?? null,
|
|
160
|
-
}
|
|
161
|
-
const client = createClient();
|
|
113
|
+
};
|
|
162
114
|
return client;
|
|
163
115
|
},
|
|
164
116
|
onMigrate: async (client) => {
|
|
165
117
|
if (onMigrate) {
|
|
166
|
-
await withMigrationSavepoint(client, (
|
|
167
|
-
onMigrate(leased),
|
|
168
|
-
);
|
|
118
|
+
await withMigrationSavepoint(client, () => onMigrate(client));
|
|
169
119
|
}
|
|
170
120
|
},
|
|
171
121
|
};
|
|
@@ -185,47 +135,33 @@ function rowToObject<TRow extends Record<string, unknown>>(
|
|
|
185
135
|
async function execMultiStatement<TRow extends Record<string, unknown>>(
|
|
186
136
|
db: SqliteDatabase,
|
|
187
137
|
query: string,
|
|
188
|
-
lease?: { key: string; timeoutMs?: number },
|
|
189
138
|
): Promise<TRow[]> {
|
|
190
139
|
const results: Record<string, unknown>[] = [];
|
|
191
140
|
let columnNames: string[] | null = null;
|
|
192
|
-
await db.exec(
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
results.push(rowToObject(row, columnNames));
|
|
199
|
-
},
|
|
200
|
-
lease,
|
|
201
|
-
);
|
|
141
|
+
await db.exec(query, (row: unknown[], columns: string[]) => {
|
|
142
|
+
if (!columnNames) {
|
|
143
|
+
columnNames = columns;
|
|
144
|
+
}
|
|
145
|
+
results.push(rowToObject(row, columnNames));
|
|
146
|
+
});
|
|
202
147
|
return results as TRow[];
|
|
203
148
|
}
|
|
204
149
|
|
|
205
150
|
async function withMigrationSavepoint<T>(
|
|
206
151
|
client: RawAccess,
|
|
207
|
-
callback: (
|
|
152
|
+
callback: () => Promise<T> | T,
|
|
208
153
|
): Promise<T> {
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
} finally {
|
|
223
|
-
await leased.execute(
|
|
224
|
-
"RELEASE SAVEPOINT __rivet_on_migrate",
|
|
225
|
-
);
|
|
226
|
-
}
|
|
227
|
-
throw error;
|
|
228
|
-
}
|
|
229
|
-
},
|
|
230
|
-
);
|
|
154
|
+
await client.execute("SAVEPOINT __rivet_on_migrate");
|
|
155
|
+
try {
|
|
156
|
+
const result = await callback();
|
|
157
|
+
await client.execute("RELEASE SAVEPOINT __rivet_on_migrate");
|
|
158
|
+
return result;
|
|
159
|
+
} catch (error) {
|
|
160
|
+
try {
|
|
161
|
+
await client.execute("ROLLBACK TO SAVEPOINT __rivet_on_migrate");
|
|
162
|
+
} finally {
|
|
163
|
+
await client.execute("RELEASE SAVEPOINT __rivet_on_migrate");
|
|
164
|
+
}
|
|
165
|
+
throw error;
|
|
166
|
+
}
|
|
231
167
|
}
|
|
@@ -3,7 +3,6 @@ import type {
|
|
|
3
3
|
SqliteBindings,
|
|
4
4
|
SqliteDatabase,
|
|
5
5
|
SqliteExecuteResult,
|
|
6
|
-
SqliteLeaseOptions,
|
|
7
6
|
SqliteNativeMetrics,
|
|
8
7
|
} from "./config";
|
|
9
8
|
|
|
@@ -67,16 +66,10 @@ interface NativeExecuteResult {
|
|
|
67
66
|
}
|
|
68
67
|
|
|
69
68
|
export interface JsNativeDatabaseLike {
|
|
70
|
-
exec(
|
|
71
|
-
sql: string,
|
|
72
|
-
leaseKey?: string,
|
|
73
|
-
leaseTimeoutMs?: number,
|
|
74
|
-
): Promise<NativeExecResult>;
|
|
69
|
+
exec(sql: string): Promise<NativeExecResult>;
|
|
75
70
|
execute(
|
|
76
71
|
sql: string,
|
|
77
72
|
params?: NativeBindParam[] | null,
|
|
78
|
-
leaseKey?: string,
|
|
79
|
-
leaseTimeoutMs?: number,
|
|
80
73
|
): Promise<NativeExecuteResult>;
|
|
81
74
|
query(
|
|
82
75
|
sql: string,
|
|
@@ -297,7 +290,6 @@ export function wrapJsNativeDatabase(
|
|
|
297
290
|
const executeNative = async (
|
|
298
291
|
sql: string,
|
|
299
292
|
params?: SqliteBindings,
|
|
300
|
-
lease?: SqliteLeaseOptions,
|
|
301
293
|
): Promise<SqliteExecuteResult> => {
|
|
302
294
|
const lastInsertRowIdColumn = lastInsertRowIdColumnName(sql);
|
|
303
295
|
if (lastInsertRowIdColumn) {
|
|
@@ -312,12 +304,7 @@ export function wrapJsNativeDatabase(
|
|
|
312
304
|
const release = gate.enter();
|
|
313
305
|
try {
|
|
314
306
|
const nativeParams = toNativeBindings(sql, params);
|
|
315
|
-
const result = await database.execute(
|
|
316
|
-
sql,
|
|
317
|
-
nativeParams,
|
|
318
|
-
lease?.key,
|
|
319
|
-
lease?.timeoutMs,
|
|
320
|
-
);
|
|
307
|
+
const result = await database.execute(sql, nativeParams);
|
|
321
308
|
if (result.lastInsertRowId !== undefined) {
|
|
322
309
|
lastInsertRowId = result.lastInsertRowId;
|
|
323
310
|
}
|
|
@@ -333,12 +320,11 @@ export function wrapJsNativeDatabase(
|
|
|
333
320
|
async exec(
|
|
334
321
|
sql: string,
|
|
335
322
|
callback?: (row: unknown[], columns: string[]) => void,
|
|
336
|
-
lease?: SqliteLeaseOptions,
|
|
337
323
|
): Promise<void> {
|
|
338
324
|
const release = gate.enter();
|
|
339
325
|
let result: NativeExecResult;
|
|
340
326
|
try {
|
|
341
|
-
result = await database.exec(sql
|
|
327
|
+
result = await database.exec(sql);
|
|
342
328
|
} catch (error) {
|
|
343
329
|
enrichNativeDatabaseError(database, error);
|
|
344
330
|
} finally {
|
|
@@ -354,9 +340,8 @@ export function wrapJsNativeDatabase(
|
|
|
354
340
|
async execute(
|
|
355
341
|
sql: string,
|
|
356
342
|
params?: SqliteBindings,
|
|
357
|
-
lease?: SqliteLeaseOptions,
|
|
358
343
|
): Promise<SqliteExecuteResult> {
|
|
359
|
-
return await executeNative(sql, params
|
|
344
|
+
return await executeNative(sql, params);
|
|
360
345
|
},
|
|
361
346
|
async run(sql: string, params?: SqliteBindings): Promise<void> {
|
|
362
347
|
await executeNative(sql, params);
|
package/src/common/log.ts
CHANGED
|
@@ -62,10 +62,15 @@ export function configureBaseLogger(logger: Logger): void {
|
|
|
62
62
|
}
|
|
63
63
|
|
|
64
64
|
/**
|
|
65
|
-
*
|
|
65
|
+
* Configure the default logger with optional log level.
|
|
66
66
|
*/
|
|
67
|
-
export function
|
|
68
|
-
|
|
67
|
+
export function configureDefaultLogger(logLevel?: LogLevel) {
|
|
68
|
+
// Store the configured log level
|
|
69
|
+
if (logLevel) {
|
|
70
|
+
configuredLogLevel = logLevel;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
baseLogger = pino(
|
|
69
74
|
{
|
|
70
75
|
level: getPinoLevel(logLevel),
|
|
71
76
|
messageKey: "msg",
|
|
@@ -82,18 +87,7 @@ export function makeDefaultLogger(logLevel?: LogLevel): Logger {
|
|
|
82
87
|
},
|
|
83
88
|
createLogfmtDestination(),
|
|
84
89
|
);
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
/**
|
|
88
|
-
* Configure the default logger with optional log level.
|
|
89
|
-
*/
|
|
90
|
-
export function configureDefaultLogger(logLevel?: LogLevel) {
|
|
91
|
-
// Store the configured log level
|
|
92
|
-
if (logLevel) {
|
|
93
|
-
configuredLogLevel = logLevel;
|
|
94
|
-
}
|
|
95
90
|
|
|
96
|
-
baseLogger = makeDefaultLogger(logLevel);
|
|
97
91
|
loggerCache.clear();
|
|
98
92
|
}
|
|
99
93
|
|