Class BaseRestStore<ItemType, IDType>

Base Store implementation for simple rest services. Provides get and query methods.

Type Parameters

Hierarchy (view full)

Implements

Constructors

  • Create the store.

    Type Parameters

    • ItemType extends Readonly<Record<string, any>>
    • IDType extends string | number

    Parameters

    • options: Partial<Pick<BaseRestStore<ItemType, IDType>, keyof BaseRestStore<ItemType, IDType>>> = {}

      allows overwrite of any property

    • fetch: ((url, options) => Promise<any>) = apprt_request

      the fetch method to use. Provided to customize in the constructor to make tests easier.

        • (url, options): Promise<any>
        • Parameters

          • url: string
          • options: Record<string, any>

          Returns Promise<any>

    Returns BaseRestStore<ItemType, IDType>

Properties

accepts: string = "application/javascript, application/json"

Defines the Accept header to use on HTTP requests

callbackParam: string = "callback"

The jsonp request parameter

filterParam: string = "filter"

The filter param transporting the query.

headers: {} = {}

Additional headers to pass in all requests to the server. These can be overridden by passing additional headers to calls to the store.

Type declaration

    id: string = ""

    The id of this store.

    idProperty: string = "id"

    Indicates the property to use as the identity property. The values of this property should be unique.

    itemProperty: string = "items"

    Identifies the item array in query responses

    jsonp: boolean = false

    Shall jsonp used for get and query

    metadata: undefined | Partial<Metadata> = undefined

    Configuration option for getMetadata method.

    rangeParam: string = "range"

    Range parameter transporting item range definitions.

    sortParam: string = "sort"

    The query parameter to used for holding sort information. If this is omitted, than the sort information is included in a functional query token to avoid colliding with the set of name/value pairs.

    supportsPostSwitching: boolean = true

    Flag which indicates that an switching to POST is allowed when GET requests are to long. This is true by default for backwards compatibility.

    target: string = ""

    The target base URL to use for all requests to the server. This string will be prepended to the id to generate the URL (relative or absolute) for requests sent to the server

    totalProperty: string = "total"

    Identifies the total property in query responses

    _metadata: undefined | Partial<Metadata> = undefined

    Property for sub classes which provide static pre-configured metadata template.

    Methods

    • Gets identity of given item.

      Parameters

      • item: Partial<ItemType>

        an item of this store.

      Returns undefined | IDType

      id or undefined if no id is found.

    • Gets metadata of the store.

      Returns Promise<Metadata>

      metadata.

    • Hook for subclasses to convert ComplexQueryExpression into request parameters.

      Parameters

      Returns void

    • Converts the options.start and options.count values to request parameters. By default the headers "Range" and "X-Range" are calculated and the request parameter 'range' is added. A range is an string like '5..20' == ${start}-${start+count-1}.

      Parameters

      • requestParameters: Record<string, any>

        request parameters will be changed

      • options: QueryOptions

        the query options, with start + count.

      Returns void

    • Converts the options.sort to request parameters. By default the sort options are converted into 'sort' request parameter, like '-id,+name,+title'.

      Parameters

      • requestParameters: Record<string, any>

        request parameters to change.

      • options: QueryOptions

        the query options.

      Returns void

    • Helper method which checks the query options and delegates to fetch.

      Type Parameters

      • T

      Parameters

      • method: string

        http method to execute.

      • options: Record<string, any>

        the request options.

      Returns Promise<T>

      result of the request.

    • Overwrite this method to change the filter behavior.

      Parameters

      Returns Metadata

    • Hook for sub classes to add/change request parameters.

      Parameters

      Returns Record<string, any>

    • Overwrite this method to provide your own metadata! The method can return Promises! Here you can implement http requests to dynamically resolve metadata.

      Returns Partial<Metadata> | Promise<Partial<Metadata>>

    • Transforms server responses into ResultItems<T>. The default implementation expects a server response of this format:

       {
      total : <count>,
      items: [...]
      }

      Parameters

      • result: Record<string, any>

        json server response

      Returns ResultItems<ItemType>

      ResultItems.

    Generated using TypeDoc