{"version":3,"file":"pagination.cjs","names":[],"sources":["../../src/query/pagination.ts"],"sourcesContent":["// Contracts mirroring the Tempest FastAPI SDK pagination envelopes, so a\n// React frontend consumes them with no manual mapping.\n//\n// Offset (fastapi-pagination `Page` / BasePaginationSchema):\n//   { items, total, page, size, pages }   (some configs name the size `page_size`)\n// Cursor (CursorPaginationSchema):\n//   { items, next_cursor, has_more, limit }\n\n/** Offset-paginated response envelope (fastapi-pagination `Page[T]`). */\nexport interface OffsetPage<T> {\n    /** The rows for the current page. */\n    items: T[];\n    /** Total number of matching rows across all pages. */\n    total: number;\n    /** Current 1-based page number. */\n    page: number;\n    /** Total number of pages. */\n    pages: number;\n    /** Page size — fastapi-pagination emits `size`. */\n    size?: number;\n    /** Page size — some backends name it `page_size` instead. */\n    page_size?: number;\n}\n\n/** Cursor-paginated response envelope (`CursorPaginationSchema[T]`). */\nexport interface CursorPage<T> {\n    /** The rows for this batch. */\n    items: T[];\n    /** Opaque cursor for the next batch, or null when exhausted. Pass it back verbatim. */\n    next_cursor: string | null;\n    /** Whether another batch exists. */\n    has_more: boolean;\n    /** Batch size used for this query. */\n    limit: number;\n}\n\n/** Offset filter query params (fastapi-pagination / `BasePaginationFilterSchema`). */\nexport interface OffsetParams {\n    page?: number;\n    /** Page size — fastapi-pagination convention. */\n    size?: number;\n    /** Page size — `page_size` convention. */\n    page_size?: number;\n    order_by?: string;\n    ascending?: boolean;\n}\n\n/** Cursor filter query params (`CursorPaginationFilterSchema`). */\nexport interface CursorParams {\n    cursor?: string | null;\n    limit?: number;\n    order_by?: string;\n    ascending?: boolean;\n}\n\n/**\n * Type guard for an {@link OffsetPage} envelope.\n *\n * @param value - The unknown value to test.\n * @returns Whether it carries `items` + `total` + `page` + `pages`.\n */\nexport function isOffsetPage<T = unknown>(value: unknown): value is OffsetPage<T> {\n    if (typeof value !== \"object\" || value === null) return false;\n    const v = value as Record<string, unknown>;\n    return Array.isArray(v.items) && typeof v.total === \"number\" && typeof v.pages === \"number\";\n}\n\n/**\n * Type guard for a {@link CursorPage} envelope.\n *\n * @param value - The unknown value to test.\n * @returns Whether it carries `items` + `has_more` + a `next_cursor` key.\n */\nexport function isCursorPage<T = unknown>(value: unknown): value is CursorPage<T> {\n    if (typeof value !== \"object\" || value === null) return false;\n    const v = value as Record<string, unknown>;\n    return Array.isArray(v.items) && typeof v.has_more === \"boolean\" && \"next_cursor\" in v;\n}\n\n/**\n * Build an empty {@link OffsetPage} — handy as `placeholderData`/`initialData`.\n *\n * @param pageSize - The page size to report (default 20).\n * @returns An empty offset page on page 1.\n */\nexport function emptyOffsetPage<T>(pageSize = 20): OffsetPage<T> {\n    return { items: [], total: 0, page: 1, size: pageSize, pages: 0 };\n}\n"],"mappings":"AA6DA,SAAgB,EAA0B,EAAwC,CAC9E,GAAI,OAAO,GAAU,WAAY,EAAgB,MAAO,GACxD,IAAM,EAAI,EACV,OAAO,MAAM,QAAQ,EAAE,KAAK,GAAK,OAAO,EAAE,OAAU,UAAY,OAAO,EAAE,OAAU,QACvF,CAQA,SAAgB,EAA0B,EAAwC,CAC9E,GAAI,OAAO,GAAU,WAAY,EAAgB,MAAO,GACxD,IAAM,EAAI,EACV,OAAO,MAAM,QAAQ,EAAE,KAAK,GAAK,OAAO,EAAE,UAAa,WAAa,gBAAiB,CACzF,CAQA,SAAgB,EAAmB,EAAW,GAAmB,CAC7D,MAAO,CAAE,MAAO,CAAC,EAAG,MAAO,EAAG,KAAM,EAAG,KAAM,EAAU,MAAO,CAAE,CACpE"}