import { IResponseAction, IBaseRequestAction, Types } from '../actions/BaseRequestAction'; import { METHOD } from '../utils/method'; import { ThrottleKeyOption } from './BaseHttpService'; interface Graphql { variables: object; query: string; } declare type Options = Partial, 'type'>> & { uri: string; instanceName: string; method: METHOD; }; export declare type ThrottleOptions = { /** * Millisecond * * `1000` means 1 second * `60000` means 1 minute */ duration: number; enable?: boolean; transfer?: ThrottleKeyOption['transfer']; }; export declare class HttpServiceBuilder { protected readonly config: Options; constructor(config: Options); /** * Query String on url. */ query(query: object): this; /** * The data you want to send. */ body(body: object): this; /** * Graphql template instead of body * * @see https://github.com/redux-model/graphql * * ```javascript * this.post('/graphql').graphql({ * query: `...template...`, * variables: { ... }, * }); * ``` */ graphql(tpl: ((args: object) => Graphql) | Graphql): this; /** * The message for successful request. * * ```typescript * const $api = new HttpService({ * onShowSuccess(message) { * alert(message); * } * }); * ``` */ successText(text: string): this; /** * The message for error request. * * ```typescript * const $api = new HttpService({ * onShowError(message) { * alert(message); * } * }); * ``` */ failText(text: string): this; requestOptions(options: RequestOption): this; /** * Don't show error message for this request. Default `false`, we will always show error message. */ hideError(is: boolean | ((response: IResponseAction) => boolean)): this; /** * Use cache data to interrupt request. Consider to use it only for get method. * * ```javascript * this.get('/user').throttle({ * // The cache expire after 10 seconds. * duration: 10000, * }); * ``` */ throttle(options: ThrottleOptions): this; /** * The payload for model.subscriptions() * * ```javascript * class AModel extends Model { * getUser = $api.action((id: number) => { * return this.get(`/users/${id}`).payload({ id }); * }); * } * * const aModel = new AModel(); * * --------- * * class BModel extends Model { * protected subscriptions(): Subscriptions { * return [ * aModel.getUser.onSuccess((state, action) => { * // action.payload.id * }). * ]; * } * } * ``` */ payload(payload: T): M extends true ? HttpServiceBuilderWithMeta : HttpServiceBuilderWithMetas; /** * Collect meta for each request * * ```javascript * class TestModel extends Model { * getUser = $api.action((id: number) => { * return this.get('/user').metas(id); * }); * } * * const testModel = new TestModel(); * * ------- * * testModel.getUser.metas.pick(1); * testModel.getUser.loadings.pick(1); * testModel.getUser.useMetas(1); * testModel.getUser.useMetas().pick(1); * testModel.getUser.useLoadings(1); * testModel.getUser.useLoadings().pick(1); * ``` */ metas(value: string): HttpServiceBuilderWithMetas; metas(value: number): HttpServiceBuilderWithMetas; metas(value: symbol): HttpServiceBuilderWithMetas; /** * Change state before send */ onPrepare(fn: NonNullable['onPrepare']>): this; /** * Dispatch more action before send */ afterPrepare(fn: NonNullable['afterPrepare']>, duration?: number): this; /** * Change state when request success */ onSuccess(fn: NonNullable['onSuccess']>): this; /** * Dispatch more action when request success */ afterSuccess(fn: NonNullable['afterSuccess']>, duration?: number): this; /** * Change state when request fail */ onFail(fn: NonNullable['onFail']>): this; /** * Dispatch more action when request fail */ afterFail(fn: NonNullable['afterFail']>, duration?: number): this; protected collect(actionName: string, types: Types): IBaseRequestAction; } export declare class HttpServiceBuilderWithMeta extends HttpServiceBuilder { private readonly _; } export declare class HttpServiceBuilderWithMetas extends HttpServiceBuilder { private readonly _; } export {};