Options
All
  • Public
  • Public/Protected
  • All
Menu

@21epub/epub-data-client

Index

Type aliases

Method

Method: "POST" | "GET" | "PUT" | "DELETE" | "OPTION" | "PATCH"

ParseFnForLoadMore

ParseFnForLoadMore: <T>(prevData: T[], currentData: T[]) => T[]

Type declaration

    • <T>(prevData: T[], currentData: T[]): T[]
    • Type parameters

      • T

      Parameters

      • prevData: T[]
      • currentData: T[]

      Returns T[]

ProParseDataFC

ProParseDataFC<D, T>: (rawData?: D) => T[] | [] | D | T | undefined

Type parameters

  • D

  • T

Type declaration

    • (rawData?: D): T[] | [] | D | T | undefined
    • Parameters

      • Optional rawData: D

      Returns T[] | [] | D | T | undefined

QueryOpt

QueryOpt: { page?: undefined | number; query?: undefined | string; size?: undefined | number }

Type declaration

  • [k: string]: string | number | undefined
  • Optional page?: undefined | number
  • Optional query?: undefined | string
  • Optional size?: undefined | number

RequestOpts

RequestOpts: { acceptMethods?: Array<Method>; addBackSlash?: undefined | false | true; ajaxRequestOptions?: AjaxRequest; catchError?: undefined | ((error: AjaxError) => void); catchMsg?: undefined | ((msg: string) => void); contentType?: "application/x-www-form-urlencoded" | "multipart/form-data" | "application/json" | "text/plain"; idAttribute?: undefined | string; size?: undefined | number }

Type declaration

  • Optional acceptMethods?: Array<Method>

    Methods allowed To use

  • Optional addBackSlash?: undefined | false | true

    Force to Add slash at the end of parsed url (default is false)

    example
      Turn `http://url.to/1234`  to `http://url.to/1234/`
  • Optional ajaxRequestOptions?: AjaxRequest
  • Optional catchError?: undefined | ((error: AjaxError) => void)

    catchError for both http response error and data.code!=200 error

  • Optional catchMsg?: undefined | ((msg: string) => void)

    catchMsg return by error response msg or default system msg

  • Optional contentType?: "application/x-www-form-urlencoded" | "multipart/form-data" | "application/json" | "text/plain"
  • Optional idAttribute?: undefined | string
  • Optional size?: undefined | number

    size for request per page

Variables

Const XHR2

XHR2: any = typeof XMLHttpRequest !== 'undefined' ? XMLHttpRequest : xhr2

Const xhr2

xhr2: any = require('xhr2')

Other Functions

Const catchError

  • catchError(error: AjaxError): void

Const catchMsg

  • catchMsg(msg: string): void

Const createDataHook

  • createDataHook<T>(data$: BehaviorSubject<T>, initialData: T): (Anonymous function)
  • Type parameters

    • T

    Parameters

    • data$: BehaviorSubject<T>
    • initialData: T

    Returns (Anonymous function)

Const generateInitData

  • generateInitData(): { facet: never[]; numpages: number; page: number; results: never[]; size: number; sum: number }
  • Returns { facet: never[]; numpages: number; page: number; results: never[]; size: number; sum: number }

    • facet: never[]
    • numpages: number
    • page: number
    • results: never[]
    • size: number
    • sum: number

Const generatePromiseRejectMock

  • generatePromiseRejectMock<T>(data: T): Observable<AjaxResponse>

Const generatePromiseResolveMock

  • generatePromiseResolveMock<T>(data: T): Observable<AjaxResponse>
  • For jest mock

    Type parameters

    • T

    Parameters

    • data: T

    Returns Observable<AjaxResponse>

Const getErrorMsg

  • getErrorMsg(error: AjaxError & { responseText?: undefined | string }): any

Const parseData

Const parseDataError

Const parseFnForLoadMore

  • parseFnForLoadMore(prevData: T[], currentData: T[]): T[]

Const parseRawResponse

  • parseRawResponse<T>(observer: Observable<AjaxFetcherResponse<T>>, catchErr?: undefined | ((error: AjaxError) => void), catchMsg?: undefined | ((msg: string) => void), loading$?: BehaviorSubject<boolean>): Promise<void | AjaxFetcherResponse<T>>
  • Type parameters

    • T

    Parameters

    • observer: Observable<AjaxFetcherResponse<T>>
    • Optional catchErr: undefined | ((error: AjaxError) => void)
    • Optional catchMsg: undefined | ((msg: string) => void)
    • Optional loading$: BehaviorSubject<boolean>

    Returns Promise<void | AjaxFetcherResponse<T>>

Const parseResponse

  • parseResponse<T>(observer: Observable<AjaxFetcherResponse<T>>, catchErr?: undefined | ((error: AjaxError) => void), catchMsg?: undefined | ((msg: string) => void), loading$?: BehaviorSubject<boolean>): Promise<void | T[] | undefined>
  • Type parameters

    • T

    Parameters

    • observer: Observable<AjaxFetcherResponse<T>>
    • Optional catchErr: undefined | ((error: AjaxError) => void)
    • Optional catchMsg: undefined | ((msg: string) => void)
    • Optional loading$: BehaviorSubject<boolean>

    Returns Promise<void | T[] | undefined>

Const parseResponsePro

  • parseResponsePro<D, T>(__namedParameters: { catchErr: undefined | ((error: AjaxError) => void); catchMsg: undefined | ((msg: string) => void); loading$: undefined | BehaviorSubject<boolean>; observer: Observable<AjaxResponsePro<D>>; parseData: undefined | ((rawData: D) => D | T[] | T | undefined) }): Promise<D | undefined>
  • Type parameters

    • D

    • T

    Parameters

    • __namedParameters: { catchErr: undefined | ((error: AjaxError) => void); catchMsg: undefined | ((msg: string) => void); loading$: undefined | BehaviorSubject<boolean>; observer: Observable<AjaxResponsePro<D>>; parseData: undefined | ((rawData: D) => D | T[] | T | undefined) }
      • catchErr: undefined | ((error: AjaxError) => void)
      • catchMsg: undefined | ((msg: string) => void)
      • loading$: undefined | BehaviorSubject<boolean>
      • observer: Observable<AjaxResponsePro<D>>
      • parseData: undefined | ((rawData: D) => D | T[] | T | undefined)

    Returns Promise<D | undefined>

Const parseUrl

  • parseUrl(prefix: string, suffix?: undefined | string): string
  • Parameters

    • prefix: string
    • Optional suffix: undefined | string

    Returns string

request

  • request(options: AjaxRequest): Observable<AjaxResponse>

Const urlJoin

  • urlJoin(__namedParameters: [string, Array], slash?: boolean): string
  • Parameters

    • __namedParameters: [string, Array]
    • Default value slash: boolean = true

    Returns string

Tools Functions

Const debounce

  • debounce<T>(fn: T, time: number): Function
  • Generate a debounced Function base on the actual function Debounced execute after time

    example
    const debouncePatch = debounce( async (body) => {
       await client.id('12345').patch(body);
    },200)
    
    ...
    debouncePatch(body)
    

    Type parameters

    • T: Function

    Parameters

    • fn: T
    • time: number

    Returns Function

Const throttle

  • throttle<T>(fn: T, time: number): Function
  • Throttle execution within time

    Type parameters

    • T: Function

    Parameters

    • fn: T
    • time: number

    Returns Function

Object literals

Const codeMessage

codeMessage: object

200

200: string = "服务器成功返回请求的数据。"

201

201: string = "新建或修改数据成功。"

202

202: string = "一个请求已经进入后台排队(异步任务)。"

204

204: string = "删除数据成功。"

400

400: string = "请求有错误,请重试!"

401

401: string = "用户没有权限(令牌、用户名、密码错误)。"

403

403: string = "用户得到授权,但是访问是被禁止的。"

404

404: string = "发出的请求针对的是不存在的记录,服务器没有进行操作。"

406

406: string = "请求的格式不可得。"

410

410: string = "请求的资源被永久删除,且不会再得到的。"

422

422: string = "当创建一个对象时,发生一个验证错误。"

500

500: string = "服务器发生错误,请检查服务器。"

502

502: string = "网关错误。"

503

503: string = "服务不可用,服务器暂时过载或维护。"

504

504: string = "网关超时。"

Generated using TypeDoc