Template
1
0

feat: initial boilerplate

This commit is contained in:
2025-08-11 20:45:41 +02:00
parent d98524254f
commit 1215a98afc
148 changed files with 6935 additions and 2060 deletions

View File

@@ -0,0 +1,11 @@
import { idIndex } from "~libraries/database/id.ts";
import { register } from "~libraries/database/registrar.ts";
import { db } from "../database.ts";
await register(db.db, [
{
name: "accounts",
indexes: [idIndex],
},
]);

View File

@@ -0,0 +1,6 @@
import { db, takeOne } from "../database.ts";
import { type AccountSchema, fromAccountDriver } from "./schema.ts";
export async function getAccountById(id: string): Promise<AccountSchema | undefined> {
return db.collection("accounts").find({ id }).toArray().then(fromAccountDriver).then(takeOne);
}

View File

@@ -0,0 +1,36 @@
import { z } from "zod";
const account = z.object({
id: z.uuid(),
name: z.object({
given: z.string(),
family: z.string(),
}),
email: z.email(),
});
/*
|--------------------------------------------------------------------------------
| Parsers
|--------------------------------------------------------------------------------
*/
const select = account;
const insert = account;
export function toAccountDriver(documents: unknown): AccountInsert {
return insert.parse(documents);
}
export function fromAccountDriver(documents: unknown[]): AccountSchema[] {
return documents.map((document) => select.parse(document));
}
/*
|--------------------------------------------------------------------------------
| Types
|--------------------------------------------------------------------------------
*/
export type AccountSchema = z.infer<typeof select>;
export type AccountInsert = z.infer<typeof insert>;

View File

@@ -0,0 +1,12 @@
import { config } from "~config";
import { getDatabaseAccessor } from "~libraries/database/accessor.ts";
import { AccountInsert } from "./account/schema.ts";
export const db = getDatabaseAccessor<{
accounts: AccountInsert;
}>(`${config.name}:read-store`);
export function takeOne<TDocument>(documents: TDocument[]): TDocument | undefined {
return documents[0];
}

View File

@@ -0,0 +1,3 @@
export * from "./account/methods.ts";
export * from "./account/schema.ts";
export * from "./database.ts";