UNPKG

@kaaiot/services

Version:

Type definitions for KaaIoT platform REST API service communication

40 lines (39 loc) 1.82 kB
import { AxiosError } from 'axios'; import { FetchResponse } from "../clients/service-requester"; export declare const isPromise: <T = any>(asyncContent: any | undefined) => asyncContent is Promise<T>; export declare const validateOrReject: (valueOrValues: any | any[], successValue: any, error: AxiosError) => any; interface ErrorOptions { message: string; responseMessage?: string; status?: number; } export declare const createError: (errorOptions: ErrorOptions) => AxiosError; export declare const extractAPIError: (error: AxiosError, defaultMessage?: string) => string; export declare const extractAPIValidationMessage: (error: AxiosError) => string | string[]; /** * Returns promise to be resolved in `timeout` ms. * * @param {number} milliseconds */ export declare const sleep: (milliseconds: number) => Promise<void>; export declare const microTask: (count?: number) => Promise<void>; export declare const computeInterval: (interval: number | undefined, defaultInterval?: number) => number; export declare const extractResourceName: (response: FetchResponse<any>) => string; /** * Rejects promise when `expectedPromise` doesn't resolve in `milliseconds` * * @param milliseconds * @param expectedPromise */ export declare const withTimeout: <InputPromise extends Promise<any>>(milliseconds: number, expectedPromise: InputPromise, failMessage?: string) => InputPromise; /** * Creates the object similar to Axios response to pass the typings when returns * default value instead of response * * @param data * @param status * @param statusText */ export declare const createFetchResponse: <T = any>(data: T, status?: number, statusText?: string) => FetchResponse<T>; export declare const wrapWithErrorMessage: <T>(fn: () => Promise<T>, errorMessage: string) => Promise<T>; export {};