Track and save on groceries
1import z from "zod/v4";
2import { schemaTitle } from "../utils.js";
3
4export const DEFAULT_LIMIT = 50;
5export const Total = z.coerce.number().int().min(0);
6export const Limit = z.coerce.number().int().min(0);
7
8export const pageOptions = <T extends z.ZodType, C extends z.ZodType>(
9 schema: T,
10 cursor: C,
11) =>
12 z
13 .object({
14 limit: Limit.default(DEFAULT_LIMIT),
15 cursor: cursor.optional(),
16 })
17 .meta({
18 title: `${schemaTitle(schema)}PageOptions`,
19 });
20
21export const paginated = <T extends z.ZodTypeAny>(item: T) =>
22 z
23 .object({
24 total: Total,
25 limit: Limit,
26 items: z.array(item),
27 })
28 .meta({
29 title: `${schemaTitle(item)}s`,
30 });