UNPKG

magner

Version:

Universal admin panel magnetic to any backend

34 lines (33 loc) 1.5 kB
import type { Router } from 'vue-router'; import type { ApiErrorType, ErrorParser, UrlToDataHelper, DataToUrlHelper } from '../../types/configs/development'; import type { ApiType } from '../../utils/api'; import type { LStorage } from '../../utils/core/local-storage'; import type { AppStoreType } from '../../types'; /** A proxy that accepts anything and returns something different */ export type ProxyFunc<ARGUMENT = any, PROXY = any> = (data: ARGUMENT) => PROXY; export type BaseResponse<RESULT = any> = { data: RESULT; error?: never; } | { error: ApiErrorType; data?: never; }; export type RequestWrap<RESULT = any, DATA = any> = (data: DATA) => Promise<BaseResponse<RESULT>>; /** Request function is used in different views. Users define it by themselves */ export type RequestCallback<RESULT = any, DATA = any> = (info: { data: DATA; api: ApiType; router: Router; lstorage: LStorage; parseError: ErrorParser<any>; urlToData?: UrlToDataHelper; dataToUrl?: DataToUrlHelper; appStore?: AppStoreType; }) => Promise<BaseResponse<RESULT>>; export type RequestFunc = <RESULT = any, DATA = any>(cb: RequestCallback<RESULT, DATA>) => RequestWrap<RESULT, DATA>; export interface CardRequestData<DATA = any> { id: string | number | Record<string, any>; isNew: boolean; data: DATA; } export type CardRequestFunc = <RESULT = any, DATA = any>(cb: RequestCallback<RESULT, CardRequestData<DATA>>) => RequestWrap<RESULT, CardRequestData<DATA>>;