Files
stack/packages/brain/src/projects.ts
Jason Woltje 4c5e4ae016 feat: auth middleware, brain data layer, Valkey queue (P1-002, P1-003, P1-004)
Auth middleware (P1-002):
- DatabaseModule provides Db instance with graceful shutdown
- AuthModule mounts BetterAuth at /api/auth/* via toNodeHandler
- AuthGuard validates sessions via BetterAuth API
- CurrentUser decorator extracts user from request

Brain data layer (P1-003):
- CRUD repositories for projects, missions, tasks, conversations
- createBrain(db) factory returns all repositories
- Re-exports drizzle-orm query helpers from @mosaic/db to avoid
  duplicate package resolution

Queue (P1-004):
- ioredis-based Valkey client with createQueue/createQueueClient
- Enqueue/dequeue, pub/sub, queue length operations

Closes #11, Closes #12, Closes #13

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-12 21:37:33 -05:00

39 lines
1.1 KiB
TypeScript

import { eq, type Db, projects } from '@mosaic/db';
export type Project = typeof projects.$inferSelect;
export type NewProject = typeof projects.$inferInsert;
export function createProjectsRepo(db: Db) {
return {
async findAll(): Promise<Project[]> {
return db.select().from(projects);
},
async findById(id: string): Promise<Project | undefined> {
const rows = await db.select().from(projects).where(eq(projects.id, id));
return rows[0];
},
async create(data: NewProject): Promise<Project> {
const rows = await db.insert(projects).values(data).returning();
return rows[0]!;
},
async update(id: string, data: Partial<NewProject>): Promise<Project | undefined> {
const rows = await db
.update(projects)
.set({ ...data, updatedAt: new Date() })
.where(eq(projects.id, id))
.returning();
return rows[0];
},
async remove(id: string): Promise<boolean> {
const rows = await db.delete(projects).where(eq(projects.id, id)).returning();
return rows.length > 0;
},
};
}
export type ProjectsRepo = ReturnType<typeof createProjectsRepo>;