Class BaseWriteableRestStore<ItemType, IDType>

Extends the Base Store implementation with write methods (put/add/delete).

Type Parameters

Hierarchy

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 BaseWriteableRestStore<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

    • Adds an object. This will trigger a POST request to the server if the object has no id. If it has an id a PUT request is executed. It is much the same as the put method. You can suppress the switching to put by marking the id as undefined in the options.

      Parameters

      Returns Promise<ItemType>

      Example

      const item = { id: 1, name : "hello"};
      // this will still execute a POST request
      store.add(item, {id: undefined});
    • 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.

    • Executes a PUT HTTP request if an id is provided in the item or the options. Executes a POST HTTP request if no id is provided.

      Parameters

      Returns Promise<ItemType>

      the result of the server, normally the new created/updated item.

    • Deletes an object by its identity. This will trigger a DELETE request to the server.

      Parameters

      Returns Promise<void>

    • 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.

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

      Parameters

      • invokedFromMethod: string
      • requestParameters: Record<string, any>
      • originalMethodParameters: MethodParameters<ItemType, IDType>

      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. 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