import { Dispatch, SetStateAction } from 'react'; export interface Meta { total: number; hasNext: boolean; hasPrev: boolean; } export interface RequestState { loading: boolean; called?: boolean; data: null | T; meta?: null | Meta; err: null | any; } export interface VoyagerGetResult { data: T; meta?: Meta; } export declare type Filter = ['eq' | 'ne' | 'regex' | 'in' | 'gt' | 'gte' | 'lt' | 'lte', string | number | null | Array]; export declare type Sort = [string, 'asc' | 'desc']; export interface QueryParameters { select: string[]; page_size: number; page_no: number; sort_by: Sort; filter: Record; } export interface RequestOptions { query: Partial; lazy: boolean; policy: 'cache-first' | 'cache-and-network' | 'network-first' | 'no-cache'; strictSoring: boolean; spawnFromCache: boolean; skipUntil: boolean; alias?: string; } export declare type Full = { [P in keyof T]: T[P]; }; export interface LoginHook { loading: boolean; error: string | null; login: (username: string, password: string) => Promise; } export interface RegisterHook { loading: boolean; error: string | null; register: (username: string, password: string) => Promise; } export interface AuthData { user: any; token: string; } export declare type AuthInjector = (headers: Record, body?: any) => Promise<[Record, any]> | [Record, any]; export declare namespace APIConnector { type BuildEndpoint = (url: string, resource: string, query: QueryParameters) => string; interface UnpackQueryResultReturn { data: any[]; meta: Meta; } type UnpackQueryResult = (res: Response) => Promise; type UnpackMutationResultReturn = { _voyager_api?: boolean; foo: Record; } | Record; type UnpackMutationResult = (res: Response) => Promise; interface Config { buildEndpoint: BuildEndpoint; unpackQueryResult: UnpackQueryResult; unpackMutationResult: UnpackMutationResult; } } export interface VoyagerClient { url: string; auth?: AuthInjector; connector?: Partial; } export interface VoyagerProviderProps { client: VoyagerClient; children: React.ReactNode; } export interface RequestCache { queryParams: QueryParameters; meta: Meta; alias?: string; } export interface ResourceCache { data: Array; requests: Record; } export declare type CacheValue = Record; export declare type CacheReducerAction = { type: 'GET'; payload: { resource: string; id: string; endpoint: string; data: any; queryParams: QueryParameters; }; } | { type: 'POST'; payload: { resource: string; data: any; }; } | { type: 'PUT'; payload: { resource: string; data: any; }; } | { type: 'DELETE'; payload: { resource: string; data: any; }; } | { type: 'MANUAL_EDIT'; payload: CacheValue; }; export interface CacheContext { dispatchCacheEvent?: Dispatch; cache: CacheValue; } export interface AuthFunctionParams { username: string; password: string; extra?: { [key: string]: any; }; } export declare type AuthFunction = (params: AuthFunctionParams) => Promise; export interface GetFunctionParams { silent?: boolean; policy?: 'cache-first' | 'cache-and-network' | 'network-first' | 'no-cache'; skipUntil?: boolean; } export declare type GetFunction = (params?: GetFunctionParams) => Promise; interface PaginationData { getNextPage: () => void; getPreviousPage: () => void; currentPage: number; pageSize: number; setCurrentPage: (page: number) => void; setPageSize: (size: number) => void; } export declare type PaginatedGet = [RequestState, GetFunction, PaginationData]; export declare type CacheObserver = (verb: 'get' | 'post' | 'put' | 'delete', data: any, resource: string) => void; export interface VoyagerContext_t { client: { url: string; connector: APIConnector.Config; auth?: AuthInjector; }; cacheObservers: CacheObserver[]; setCacheObservers: Dispatch>; } export {};