UNPKG

1.33 kBTypeScriptView Raw
1import type { BasicCursorPaginationOptions, CollectionProp, CursorPaginatedCollectionProp, PaginationQueryOptions } from '../common-types';
2export type OffsetBasedParams = {
3 query?: PaginationQueryOptions;
4};
5export type CursorBasedParams = {
6 query?: BasicCursorPaginationOptions;
7};
8type ExpectedParams = OffsetBasedParams | CursorBasedParams;
9/**
10 * `sys.type` tends to cause type clashes downstream because it more commonly types less strict
11 * as 'string'. Because we don't rely on it for this functionality, we are fine with omitting it.
12 */
13type IterableCollection<T> = Omit<CollectionProp<T> | CursorPaginatedCollectionProp<T>, 'sys'>;
14export type FetchFn<P extends ExpectedParams, T = unknown> = (params: P) => Promise<IterableCollection<T>>;
15type ParamsType<P extends ExpectedParams, T extends FetchFn<P>> = T extends (params: infer P) => unknown ? P : never;
16/**
17 * Parameters for endpoint methods that can be paginated are inconsistent, `fetchAll` will only
18 * work with the more common version of supplying the limit, skip, and pageNext parameters via a distinct `query` property in the
19 * parameters.
20 */
21export declare function fetchAll<Params extends ExpectedParams, Entity, F extends FetchFn<Params, Entity>>(fetchFn: FetchFn<Params, Entity>, params: ParamsType<Params, F>): Promise<Entity[]>;
22export {};