@looker/sdk-rtl
Version:
Looker SDK Runtime Library
65 lines (64 loc) • 2.87 kB
TypeScript
import type { IAPIMethods, IRawResponse, ITransportSettings, SDKResponse } from './transport';
export declare const LinkHeader = "Link";
export declare const TotalCountHeader = "X-Total-Count";
export type PageLinkRel = 'first' | 'last' | 'next' | 'prev';
interface ILength {
length: number;
}
export type PagingFunc<TSuccess, TError> = () => Promise<SDKResponse<TSuccess, TError>>;
export interface IPageLink {
name?: string;
rel: PageLinkRel;
mediaType?: string;
url: string;
}
export type PageLinks = Record<string, IPageLink>;
export interface IPager<TSuccess, TError> {
total: number;
offset: number;
limit: number;
links: PageLinks;
items: TSuccess;
options?: Partial<ITransportSettings>;
pages: number;
page: number;
hasRel(link: PageLinkRel): boolean;
getRel(name: PageLinkRel, limit?: number, offset?: number): Promise<SDKResponse<TSuccess, TError>>;
firstPage(): Promise<SDKResponse<TSuccess, TError>>;
lastPage(): Promise<SDKResponse<TSuccess, TError>>;
nextPage(): Promise<SDKResponse<TSuccess, TError>>;
prevPage(): Promise<SDKResponse<TSuccess, TError>>;
more(): boolean;
}
export declare const linkHeaderParser: (linkHeader: string) => PageLinks;
export type PageObserver<TSuccess> = (page: TSuccess) => TSuccess;
export declare function pager<TSuccess extends ILength, TError>(sdk: IAPIMethods, pageFunc: PagingFunc<TSuccess, TError>, options?: Partial<ITransportSettings>): Promise<IPager<TSuccess, TError>>;
export declare function pageAll<TSuccess extends ILength, TError>(sdk: IAPIMethods, pageFunc: PagingFunc<TSuccess, TError>, onPage?: PageObserver<TSuccess>, options?: Partial<ITransportSettings>): Promise<IPager<TSuccess, TError>>;
export declare class Paging<TSuccess extends ILength, TError> implements IPager<TSuccess, TError> {
sdk: IAPIMethods;
func: PagingFunc<TSuccess, TError>;
options?: Partial<ITransportSettings> | undefined;
items: TSuccess;
links: PageLinks;
total: number;
offset: number;
limit: number;
private transport;
constructor(sdk: IAPIMethods, func: PagingFunc<TSuccess, TError>, options?: Partial<ITransportSettings> | undefined);
private rawCatch;
get page(): number;
get pages(): number;
init(): Promise<this>;
hasRel(link: PageLinkRel): boolean;
more(): boolean;
private static paramDefault;
reset(): void;
getRel(name: PageLinkRel, limit?: number, offset?: number): Promise<SDKResponse<TSuccess, TError>>;
static findHeader(raw: IRawResponse, name: string): string;
parse(raw: IRawResponse): IPager<TSuccess, TError>;
firstPage(): Promise<SDKResponse<TSuccess, TError>>;
lastPage(): Promise<SDKResponse<TSuccess, TError>>;
nextPage(): Promise<SDKResponse<TSuccess, TError>>;
prevPage(): Promise<SDKResponse<TSuccess, TError>>;
}
export {};