import type { Todo } from "./types" import type { ExtensionDatabase } from "./database" export interface TodosRepo { getAll(): Promise getOne(id: string): Promise insert(input: Todo): Promise update(input: Todo): Promise delete(input: Todo): Promise } export function createTodosRepo(_db: Promise): TodosRepo { return { async getAll() { const db = await _db; return await db.getAll("todos"); }, async getOne(id) { const db = await _db; return await db.get("todos", id); }, async insert(input) { const db = await _db; await db.add("todos", input) }, async update(input) { const db = await _db; await db.put("todos", input) }, async delete(input) { const db = await _db; await db.delete("todos", input.id) } } }