| 1 | import type { Bindings } from "../env"; |
| 2 | import { UserRepo } from "./users"; |
| 3 | import { SessionRepo } from "./sessions"; |
| 4 | import { EmailTokenRepo } from "./emailTokens"; |
| 5 | import { DeviceGrantRepo } from "./deviceGrants"; |
| 6 | |
| 7 | export interface Repos { |
| 8 | users: UserRepo; |
| 9 | sessions: SessionRepo; |
| 10 | emailTokens: EmailTokenRepo; |
| 11 | deviceGrants: DeviceGrantRepo; |
| 12 | } |
| 13 | |
| 14 | // Builds the repository layer from request bindings. The session pepper is a |
| 15 | // secret; absent (e.g. first local run) it degrades to an empty pepper. |
| 16 | export function repos(env: Bindings): Repos { |
| 17 | const pepper = env.SESSION_PEPPER ?? ""; |
| 18 | return { |
| 19 | users: new UserRepo(env.DB), |
| 20 | sessions: new SessionRepo(env.DB, pepper), |
| 21 | emailTokens: new EmailTokenRepo(env.DB, pepper), |
| 22 | deviceGrants: new DeviceGrantRepo(env.DB, pepper), |
| 23 | }; |
| 24 | } |
| 25 | |
| 26 | export { UserRepo, SessionRepo, EmailTokenRepo, DeviceGrantRepo }; |
| 27 |