Template
1
0

feat: checkpoint

This commit is contained in:
2025-11-23 22:57:43 +01:00
parent 7df57522d2
commit 5d45e273ee
160 changed files with 10160 additions and 1476 deletions

View File

@@ -0,0 +1,29 @@
import type z from "zod";
import type { ZodType } from "zod";
/**
* Takes a single record from a list of database rows.
*
* @param rows - List of rows to retrieve record from.
*/
export function takeOne<TSchema extends ZodType>(
schema: TSchema,
): (records: unknown[]) => z.output<TSchema> | undefined {
return (records: unknown[]) => {
if (records[0] === undefined) {
return undefined;
}
return schema.parse(records[0]);
};
}
/**
* Takes all records from a list of database rows and validates each one.
*
* @param schema - Zod schema to validate each record against.
*/
export function takeAll<TSchema extends ZodType>(schema: TSchema): (records: unknown[]) => z.output<TSchema>[] {
return (records: unknown[]) => {
return records.map((record) => schema.parse(record));
};
}