import { OAuthRestClientInterface, PaginationArgs } from '@/common'; import { AxiosRequestConfig, AxiosStatic } from 'axios'; import { Paginated } from '../../common/graphql'; export declare type GetPageResultCursor = { data: T[]; hasNext: boolean; nextCursor?: string; total?: number; }; declare type GetPageResult = { data: T[]; total: number; }; declare type PropMapper = (data: any) => T; declare type StringPropMapper = string | PropMapper; /** * Return a generator for a function that gets a page from an oauth endpoint with query parameters. * @param offsetQuery Query key to use for item offset * @param countQuery Query key to use for page size * @param totalProp Property to extract total assets from * @param resultProp Property to extract result items from * @returns A generator that takes a client, url and base params and generates a function that gets a page. */ export declare function getPageByQuery(offsetQuery: string, countQuery: string, totalProp: StringPropMapper, resultProp: StringPropMapper): (client: OAuthRestClientInterface, url: string, params?: any) => (page: number, pageSize: number) => Promise>; /** * Return a generator for a function that gets a page using an axios client with query parameters. * @param offsetQuery Query key to use for item offset * @param countQuery Query key to use for page size * @param totalProp Property to extract total assets from * @param resultProp Property to extract result items from * @param offsetFunc Function for getting the offset from the page number and size * @returns A generator that takes a client, url and base params and generates a function that gets a page. */ export declare function getPageByQueryAxios(offsetQuery: string, countQuery: string, totalProp: StringPropMapper, resultProp: StringPropMapper, offsetFunc?: (page: number, pageSize: number) => number): (axios: AxiosStatic, url: string, config: AxiosRequestConfig, params?: any) => (page: number, pageSize: number) => Promise>; /** * Iterate through fetching pages and build an array out of the results. * @param requestPage Method to use to request pages. Takes page number and size. Must return at least one page-size worth of items if the total allows it. * @param args Pagination arguments, new cursor and offset is written back into the object. * @param defaultPageSize Default page size if not provided by the arguments (default: 20) * @returns List of items fetched from the paginated endpoint */ export declare function paginateArgs(requestPage: (page: number, pageSize: number) => Promise>, args: PaginationArgs, defaultPageSize?: number): Promise; /** * Iterate through fetching pages and build an array out of the results. * @param requestPage Method to use to request pages. Takes page number and size. Must return at least one page-size worth of items if the total allows it. * @param pageSize Page size (default: 20) * @param pageNum Page number to start at (default: 0) * @param pageCount Number of pages to fetch (default: all) * @returns List of items fetched from the paginated endpoint */ export declare const paginate: (requestPage: (page: number, pageSize: number) => Promise>, pageSize?: number, pageNum?: number, pageCount?: number) => Promise<{ result: T[]; total: number; }>; /** * Iterate through fetching pages and build an array out of the results. * @param requestPage Method to use to request pages. Takes cursor and page size. * @param args Pagination arguments, new cursor and offset is written back into the object. * @param defaultPageSize Default page size if not provided by the arguments (default: 20) * @returns List of items fetched from the paginated endpoint */ export declare function paginateCursorArgs(requestPage: (cursor: string, pageSize: number) => Promise>, args: PaginationArgs, defaultPageSize?: number): Promise>; /** * Iterate through fetching pages and build an array out of the results. * @param requestPage Method to use to request pages. Takes cursor and page size. * @param pageSize Page size (default: 20) * @param cursor Start cursor (default: null) * @param pageCount Number of pages to fetch (default: all) * @returns List of items fetched from the paginated endpoint */ export declare const paginateCursor: (requestPage: (cursor: string, pageSize: number) => Promise>, pageSize?: number, cursor?: string, pageCount?: number) => Promise>; /** * Generate a method to paginate through a list of resources with the given arguments. * @param items List of items to paginate * @returns A method to paginate through a list of resources */ export declare function getListPage(list: T[]): (pageNum: number, pageSize: number) => Promise>; /** * Handle pagination as if the result list were empty. * @param args Pagination arguments, new cursor and offset is written back into the object. * @returns Empty list */ export declare function paginateBlankArgs(args: PaginationArgs): T[]; declare type GqlRequestMethod = (query: string, variables: any, isAdmin?: boolean) => Promise; /** * Generate a function that gets a page from a GraphQL API. * @param query The GraphQL query string * @param variables Variables to use with the GraphQL query * @param getPaginated Function that gets the Paginated type from the request type T * @param isAdmin Whether the admin credentials must be used or not * @returns A function that gets a page from a cursor and pageSize. */ export declare function getPageGql(gqlRequest: GqlRequestMethod, query: string, variables: any, getPaginated: (response: T) => Paginated, isAdmin?: boolean): (cursor: string | undefined, pageSize: number) => Promise>; export {};