/** * Importing npm packages */ /** * Importing user defined packages */ /** * Defining types */ export type SortOrder = 'asc' | 'desc'; export type PaginationMode = 'offset' | 'page' | 'cursor'; interface BasePagination { limit: number; sortBy: SortBy; sortOrder: SortOrder; } export interface OffsetPagination extends BasePagination { offset: number; } export interface PagePagination extends BasePagination { page: number; } export interface CursorPagination extends BasePagination { cursor: string | null; } export type NormalizedPagination = T extends 'offset' ? OffsetPagination : T extends 'page' ? PagePagination : T extends 'cursor' ? CursorPagination : never; export interface OffsetPaginationResult { total: number; limit: number; offset: number; items: T[]; } export interface PagePaginationResult { total: number; limit: number; page: number; totalPages: number; items: T[]; } export interface CursorPaginationResult { limit: number; nextCursor: string | null; items: T[]; } export type PaginationResult = U extends 'offset' ? OffsetPaginationResult : U extends 'page' ? PagePaginationResult : U extends 'cursor' ? CursorPaginationResult : never; export {};