-
Notifications
You must be signed in to change notification settings - Fork 57
/
Copy pathodata-count-request-config.ts
53 lines (47 loc) · 1.66 KB
/
odata-count-request-config.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
import { createLogger, pick } from '@sap-cloud-sdk/util';
import { EntityBase } from '../entity';
import type { GetAllRequestBuilderBase } from '../request-builder/get-all-request-builder-base';
import { removeTrailingSlashes } from '../remove-slashes';
import { ODataRequestConfig } from './odata-request-config';
const logger = createLogger({
package: 'core',
messageContext: 'count-request-config'
});
/**
* OData count request configuration for an entity type.
*
* @typeparam EntityT - Type of the entity to setup a request for
*/
export class ODataCountRequestConfig<
EntityT extends EntityBase
> extends ODataRequestConfig {
/**
* Creates an instance of ODataGetAllRequestConfig.
*
* @param entityConstructor - Constructor type of the entity to create a configuration for
*/
constructor(readonly getAllRequest: GetAllRequestBuilderBase<EntityT>) {
super('get', getAllRequest._entityConstructor._defaultServicePath);
}
resourcePath(): string {
return `${removeTrailingSlashes(
this.getAllRequest._entityConstructor._entityName
)}/$count`;
}
queryParameters(): Record<string, any> {
const parametersAllowedInCount = ['$apply', '$search', '$filter'];
const defaultParameters = ['$format'];
const parameters = this.getAllRequest.requestConfig.queryParameters();
Object.keys(parameters).forEach(key => {
if (
!parametersAllowedInCount.includes(key) &&
!defaultParameters.includes(key)
) {
logger.warn(
`The query parameter ${key} must not be used in a count request and has been ignored.`
);
}
});
return pick(parametersAllowedInCount, parameters);
}
}