Download packages/api/src/lib/pagination.ts from Atmint/cpns: direct link, hf CLI and curl.
- Browser
- Download file 544 Bytes
-
https://huggingface.co/spaces/Atmint/cpns/resolve/main/packages/api/src/lib/pagination.ts
- Command line
-
hf download hf://spaces/Atmint/cpns/packages/api/src/lib/pagination.ts
-
curl -L -o pagination.ts https://huggingface.co/spaces/Atmint/cpns/resolve/main/packages/api/src/lib/pagination.ts
544 Bytes
| import { z } from "zod"; | |
| import { sql } from "drizzle-orm"; | |
| export const paginationSchema = z.object({ | |
| limit: z.number().min(1).max(50).default(20), | |
| offset: z.number().min(0).default(0), | |
| }); | |
| export type PaginationInput = z.infer<typeof paginationSchema>; | |
| export interface PaginatedResult<T> { | |
| items: T[]; | |
| total: number; | |
| } | |
| export function paginateDefaults(input?: PaginationInput) { | |
| return { | |
| limit: input?.limit ?? 20, | |
| offset: input?.offset ?? 0, | |
| }; | |
| } | |
| export function countSql() { | |
| return sql<number>`count(*)::int`; | |
| } | |