Options
All
  • Public
  • Public/Protected
  • All
Menu

Interface EntityBackendConfig<TEntity, TRawData, TId, TDataSet, T, TRawData, TInput>

Type parameters

Hierarchy

Index

Properties

Optional allItemsEndpoint

allItemsEndpoint: string

Normally, Paris follows the REST standard, and tries to fetch data for an Entity from the given endpoint + '/'. i.e: If endpoint === 'todo', querying the Entity would result in an HTTP GET from /api/todo/ However, if allItemsEndpoint is set to 'all', the HTTP GET would be from /api/todo/all.

Optional allItemsEndpointTrailingSlash

allItemsEndpointTrailingSlash: boolean

Normally, Paris follows the REST standard, and tries to fetch data for an Entity from the given endpoint + '/'. i.e: If endpoint === 'todo', querying the Entity would result in an HTTP GET from /api/todo/ However, if allItemsEndpointTrailingSlash is set to false, the trailing slash is removed and the HTTP GET would be from /api/todo.

default

true

Optional allItemsProperty

allItemsProperty: string

When fetching multiple items, Paris expects in the response either an array or an object with an 'items' property, that has an array value. allItemsProperty can be specified for changing the default 'items' property to whatever your response contains.

example

Without allItemsProperty, the data returned from querying your API would have to be either an array or: { "items": [...] }

However, if we set allItemsProperty like this: { "allItemsProperty": "results" }

Then Paris will expect the data to be:

{
        "results: [...]
}
default

'items'

Optional baseUrl

The domain to use for all calls for this Entity/ApiCall. Used as a prefix for all HTTP requests. Set to an empty string to avoid this altogether (in case the data arrives from an external URL, for example). If not set and not an empty string, Paris will use config.apiRoot instead.

Optional cache

cache: boolean | DataCacheSettings<T>

If cache is specified, entities will be cached according to the cache settings. Note: cache refers to individual items (such as received from getItemById or with an ApiCall), not queries.

Optional customHeaders

customHeaders: function | Record<string, string>

Custom headers for API call. It can be either a dictionary of string, with header names as the keys, or a function (which be applied by Paris) which receives data and config, and returns the headers for the API call.

param
param

Optional endpoint

The URL to use for HTTP requests.

Optional fixedData

fixedData: object

Query params to always send when requesting data.

Type declaration

  • [index: string]: any

Optional getRemoveData

getRemoveData: function

A function that returns data to send in the request body when DELETEing entities (by using repository.remove).

param

The entities that are removed.

Type declaration

    • (items: Array<TEntity>): any
    • Parameters

      • items: Array<TEntity>

      Returns any

Optional loadAll

loadAll: boolean

If true, all the Entity's items are fetched whenever any is needed, and then cached so subsequent requests are retrieved from cache rather than backend. This makes sense to use for Entities whose values are few and not expected to change, such as enums.

default

false

Optional parseData

parseData: function

A function that if specifies, parses whatever is received from the API call, before Paris starts handling it.

param
param
param

Type declaration

Optional parseDataQuery

parseDataQuery: function

When a query is performed, a DataQuery object can be specified with options for the query. parseDataQuery receives that DataQuery object and allows to modify it, so Paris can send to the API what it expects.

param

Type declaration

Optional parseDataSet

parseDataSet: function

For query results, Paris accepts either an array of items or an object. That object may contain properties such as 'count', 'next' and 'previous'. parseDataSet, if available, receives the object as it was returned from the API and parses it to a DataSet interface, so the original properties are available in the DataSet.

example

Parsing a DataSet from a raw object returned by the backend

    parseDataSet: (rawDataSet:TodoRawDataSet) => ({ items: rawDataSet.todoItems, next: rawDataSet.$nextPage, count: rawDataSet.total })
param

Type declaration

    • (dataSet: TDataSet): DataSet<TRawData>
    • Parameters

      • dataSet: TDataSet

      Returns DataSet<TRawData>

Optional parseItemQuery

parseItemQuery: function

When getting an Entity from backend (when calling repository.getItemById), Paris follows the REST standard and fetches it by GET from /{the Entity's endpoint}/{ID}. parseItemQuery allows to specify a different URL. This is useful if your API doesn't follow the REST standard.

example

Fetching an entity by specifying the ID in a query param rather than as a folder

parseItemQuery: itemId => `/todo?id=${itemId}`
param
param
param
param
returns

Type declaration

Optional parseRemoveQuery

parseRemoveQuery: function

Similar to parseDataQuery, but for a remove call, rather than getItemById. Use it to specify the URL to use when removing entities.

param
param
param
returns

Type declaration

Optional parseSaveQuery

parseSaveQuery: function

Similar to parseDataQuery, but for a save call, rather than getItemById. Use it to specify the URL to use when creating or updating an Entity.

param
param
param
param
returns

Type declaration

Optional saveMethod

saveMethod: function | SaveRequestMethod

Set the saveMethod of an Entity to determine the HTTP method to use in the request to the backend when saving an entity. Since this can be either a function or one of the RequestMethods, the method can be either hardcoded for all save calls of this Entity, or determined at runtime for each call. For example, you might want to use POST instead of Paris' default PUT when updating an existing entity, or you might want to use PATCH instead.

Optional separateArrayParams

separateArrayParams: boolean

If true, a value that's specified in DataQuery.params and is an array will result in multiple params in the HTTP request

example

Using separateArrayParams

@Entity({
    singularName: 'My entity',
    pluralName: 'My entities',
    endpoint: 'myentity',
    separateArrayParams: true
})
export class MyEntity extends EntityModelBase{}

paris.query(MyEntity, { where: { foo: ['bar', 'lish'] }})
    .subscribe((dataSet:DataSet<MyEntity>) => console.log(dataSet));

In this example, the API call will be to (config.apiRoot)/myentity?foo=bar&foo=lish. If separateArrayParams wasn't specified as true, the api call would have been to: (config.apiRoot)/myentity?foo=bar,lish

Optional timeout

timeout: number

If the HTTP request takes longer than this number (milliseconds), the request will fail with status 0.

default

60000

Generated using TypeDoc