Multi-tenant platform (182 pages, 228 API routes, ~30 modules) built on a deterministic verification core: clinical-trial claims checked against ClinicalTrials.gov registered results and raw event counts (ARR/NNT/RR+CI recomputed in code, oracle-tested), code-enforced exact-span grounding, and multi-source cross-verification. Auth/RBAC/multi-tenancy, document processing at scale (unpdf + Docling), agentic workflows, Claude Science connector, compliance/audit, billing, public API, and more. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
47 lines
1.2 KiB
TypeScript
47 lines
1.2 KiB
TypeScript
// Shared, pure helpers for parsing/clamping pagination params from route handlers.
|
|
// Keeps clamp logic in one place so limit/offset semantics stay consistent.
|
|
|
|
export interface Pagination {
|
|
limit: number;
|
|
offset: number;
|
|
}
|
|
|
|
export interface ParsePaginationOptions {
|
|
defaultLimit: number;
|
|
maxLimit?: number;
|
|
minLimit?: number;
|
|
}
|
|
|
|
// Parse ?limit=&offset= from a URLSearchParams. Invalid/missing values fall back
|
|
// to the default; limit is clamped to [minLimit, maxLimit], offset to >= 0.
|
|
export function parsePagination(
|
|
params: URLSearchParams,
|
|
{ defaultLimit, maxLimit = 100, minLimit = 1 }: ParsePaginationOptions
|
|
): Pagination {
|
|
const limit = clampInt(params.get("limit"), defaultLimit, minLimit, maxLimit);
|
|
const offset = clampInt(params.get("offset"), 0, 0, Number.MAX_SAFE_INTEGER);
|
|
return { limit, offset };
|
|
}
|
|
|
|
function clampInt(
|
|
raw: string | null,
|
|
fallback: number,
|
|
min: number,
|
|
max: number
|
|
): number {
|
|
if (raw === null) {
|
|
return fallback;
|
|
}
|
|
const parsed = Number.parseInt(raw, 10);
|
|
if (Number.isNaN(parsed)) {
|
|
return fallback;
|
|
}
|
|
if (parsed < min) {
|
|
return min;
|
|
}
|
|
if (parsed > max) {
|
|
return max;
|
|
}
|
|
return parsed;
|
|
}
|