import { assert } from "../test/type_testing.js"; import { test } from "vitest"; import { PaginationOptions, PaginationResult, paginationOptsValidator, paginationResultValidator, } from "./pagination.js"; import { Infer, v } from "../values/validator.js"; test("paginationOptsValidator matches the paginationOpts type", () => { type validatorType = Infer; assert(); // All optional fields exist and have the correct type. assert< Required extends Required ? true : false >(); }); test("paginationResultValidator with string items", () => { const _validator = paginationResultValidator(v.string()); type validatorType = Infer; type expectedType = PaginationResult; // Check that the inferred type matches PaginationResult assert(); assert(); }); test("paginationResultValidator with object items", () => { const itemValidator = v.object({ _id: v.id("users"), _creationTime: v.number(), name: v.string(), email: v.optional(v.string()), }); const _validator = paginationResultValidator(itemValidator); type validatorType = Infer; type itemType = Infer; type expectedType = PaginationResult; // Check that the inferred type matches PaginationResult with the correct item type assert(); assert(); // Verify the page array has the correct item type type pageType = validatorType["page"]; assert(); });