-
Notifications
You must be signed in to change notification settings - Fork 16
/
api-call-backend-config.interface.ts
68 lines (61 loc) · 2.53 KB
/
api-call-backend-config.interface.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
import {EntityConfigFunctionOrValue} from "./entity.config";
import {ParisConfig} from "./paris-config";
import {DataCacheSettings} from "../data_access/cache";
import {DataQuery} from "../data_access/data-query";
export interface ApiCallBackendConfigInterface<T = any, TRawData = any, TInput = any>{
/**
* The URL to use for HTTP requests.
*/
endpoint?:EntityConfigFunctionOrValue,
/**
* 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.
*/
cache?:boolean | DataCacheSettings<T>,
/**
* 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.
*/
baseUrl?:EntityConfigFunctionOrValue,
/**
* Query params to always send when requesting data.
*/
fixedData?: { [index:string]:any },
/**
* If `true`, a value that's specified in DataQuery.params and is an array will result in multiple params in the HTTP request
* @example <caption>Using separateArrayParams</caption>
* ```typescript
* @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
*/
separateArrayParams?:boolean,
/**
* A function that if specifies, parses whatever is received from the API call, before Paris starts handling it.
* @param {TRawData} data
* @param {ParisConfig} config
* @param {DataQuery} query
*/
parseData?:(data:TRawData, config?:ParisConfig, query?:DataQuery) => T
/**
* 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 {TInput} data
* @param {ParisConfig} config
*/
customHeaders?: ((data: TInput, config?:ParisConfig) => Record<string,string>) | Record<string,string>,
}