feat: auth middleware, brain data layer, Valkey queue (P1-002/003/004) (#71)

Co-authored-by: Jason Woltje <jason@diversecanvas.com>
Co-committed-by: Jason Woltje <jason@diversecanvas.com>
This commit was merged in pull request #71.
This commit is contained in:
2026-03-13 02:37:56 +00:00
committed by jason.woltje
parent cbac5902db
commit 38897fe423
20 changed files with 2043 additions and 4290 deletions

View File

@@ -0,0 +1,49 @@
import { eq, type Db, conversations, messages } from '@mosaic/db';
export type Conversation = typeof conversations.$inferSelect;
export type NewConversation = typeof conversations.$inferInsert;
export type Message = typeof messages.$inferSelect;
export type NewMessage = typeof messages.$inferInsert;
export function createConversationsRepo(db: Db) {
return {
async findAll(userId: string): Promise<Conversation[]> {
return db.select().from(conversations).where(eq(conversations.userId, userId));
},
async findById(id: string): Promise<Conversation | undefined> {
const rows = await db.select().from(conversations).where(eq(conversations.id, id));
return rows[0];
},
async create(data: NewConversation): Promise<Conversation> {
const rows = await db.insert(conversations).values(data).returning();
return rows[0]!;
},
async update(id: string, data: Partial<NewConversation>): Promise<Conversation | undefined> {
const rows = await db
.update(conversations)
.set({ ...data, updatedAt: new Date() })
.where(eq(conversations.id, id))
.returning();
return rows[0];
},
async remove(id: string): Promise<boolean> {
const rows = await db.delete(conversations).where(eq(conversations.id, id)).returning();
return rows.length > 0;
},
async findMessages(conversationId: string): Promise<Message[]> {
return db.select().from(messages).where(eq(messages.conversationId, conversationId));
},
async addMessage(data: NewMessage): Promise<Message> {
const rows = await db.insert(messages).values(data).returning();
return rows[0]!;
},
};
}
export type ConversationsRepo = ReturnType<typeof createConversationsRepo>;