mirror of
https://github.com/kennethnym/aris.git
synced 2026-04-17 07:11:18 +01:00
feat: wrap multi-step DB writes in transactions (#118)
- saveSourceConfig: upsert + credential update run atomically - updateSourceConfig: SELECT FOR UPDATE prevents lost updates - Widen Database type to accept transaction handles Co-authored-by: Ona <no-reply@ona.com>
This commit is contained in:
@@ -80,6 +80,9 @@ function createInMemoryStore() {
|
||||
async find(sourceId: string) {
|
||||
return rows.get(key(userId, sourceId))
|
||||
},
|
||||
async findForUpdate(sourceId: string) {
|
||||
return rows.get(key(userId, sourceId))
|
||||
},
|
||||
async updateConfig(sourceId: string, update: { enabled?: boolean; config?: unknown }) {
|
||||
const existing = rows.get(key(userId, sourceId))
|
||||
if (!existing) {
|
||||
@@ -125,7 +128,9 @@ mock.module("../sources/user-sources.ts", () => ({
|
||||
},
|
||||
}))
|
||||
|
||||
const fakeDb = {} as Database
|
||||
const fakeDb = {
|
||||
transaction: <T>(fn: (tx: unknown) => Promise<T>) => fn(fakeDb),
|
||||
} as unknown as Database
|
||||
|
||||
function createApp(providers: FeedSourceProvider[], userId?: string) {
|
||||
const sessionManager = new UserSessionManager({ providers, db: fakeDb })
|
||||
|
||||
Reference in New Issue
Block a user