import { DriveContext } from './context'; export type Next = () => Promise; export type ReadableValue = ReadableStreamReadValueResult>; export declare abstract class DriverHooks { abstract beforeInit?(ctx: DriveContext): Promise; abstract afterInit?(ctx: DriveContext): Promise; abstract beforeFetch?(ctx: DriveContext): Promise; abstract afterFetch?(ctx: DriveContext): Promise; abstract beforeParse?(ctx: DriveContext): Promise; abstract afterParse?(ctx: DriveContext): Promise; } export type Middleware = (context: T, next: Next) => Promise; export type MiddlewarePattern = string | ((ctx: ReturnType) => boolean); export type DriverMiddleware = Middleware>; export type UseDriverMiddleware = [ MiddlewarePattern, DriverMiddleware ]; export type DriverParams = UseDriverMiddleware[] | { use?: UseDriverMiddleware[]; hooks?: DriverHooks; randomId?: () => string; parser?: () => BodyParseFunc; stringify?: DataStringifyFunc; }; export type DriverRequest = { id: string; headers: Headers; } & Omit; export interface ReceiverFunc { (params: { size: number; done: boolean; percentage: number; context: DriveContext; reader: ReadableStreamDefaultReader; value?: Uint8Array; }): void; } export interface BodyParseFunc { (response: Response, context: DriveContext, extra?: { receiver?: ReceiverFunc; }): Promise; } export interface DataStringifyFunc { (value: any, replacer?: (this: any, key: string, value: any) => any, space?: string | number): string; (value: any, replacer?: (number | string)[] | null, space?: string | number): string; } export type ExtraOptions = { /** abort fetch before timeout */ timeout?: number; /** use extra middleware in current fetch */ use?: DriverMiddleware[]; /** progress callback */ receiver?: ReceiverFunc; /** body parse */ parse?: BodyParseFunc; /** data stringify */ stringify?: DataStringifyFunc; }; export type DriverOptions = RequestInit & ExtraOptions & { api: string; data?: object; }; export interface DriverMethodFunc { (api: string, data?: object, init?: Omit & ExtraOptions): Promise; } export type DriveFuncAttrs = Record, DriverMethodFunc>; export interface DriveFunc extends DriveFuncAttrs { (opts: DriverOptions): Promise; ( /** the fetch USVString */ api: string, /** the fetch body */ data?: object, /** the fetch request init */ init?: RequestInit & ExtraOptions): Promise; } export type FirstParam = string | DriverOptions; export type FetchContext = Required>; export type FetchMethod = "GET" | "PUT" | "POST" | "HEAD" | "TRACE" | "PATCH" | "DELETE" | "CONNECT" | "OPTIONS"; export declare const methods: readonly FetchMethod[];