-
Notifications
You must be signed in to change notification settings - Fork 46
/
Copy pathduration-field.ts
144 lines (133 loc) · 4.55 KB
/
duration-field.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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
/* Copyright (c) 2020 SAP SE or an SAP affiliate company. All rights reserved. */
/* eslint-disable max-classes-per-file */
import moment from 'moment';
import { EdmTypeShared } from '../edm-types';
import { EntityBase, ODataVersionOf, Constructable } from '../entity';
import { Filter } from '../filter';
import {
ComplexTypeField,
getEdmType,
getEntityConstructor
} from './complex-type-field';
import { ConstructorOrField } from './constructor-or-field';
import { EdmTypeField } from './edm-type-field';
/**
* Represents a property with a duration value.
*
* @typeparam EntityT - Type of the entity the field belongs to
*/
export class DurtionFieldBase<EntityT extends EntityBase> extends EdmTypeField<
EntityT,
moment.Duration
> {
/**
* Creates an instance of Filter for this field and the given value using the operator 'gt', i.e. `>`.
*
* @param value - Value to be used in the filter
* @returns The resulting filter
*/
greaterThan(value: moment.Duration): Filter<EntityT, moment.Duration> {
return new Filter(this.fieldPath(), 'gt', value, this.edmType);
}
/**
* Creates an instance of Filter for this field and the given value using the operator 'ge', i.e. `>=`.
*
* @param value - Value to be used in the filter
* @returns The resulting filter
*/
greaterOrEqual(value: moment.Duration): Filter<EntityT, moment.Duration> {
return new Filter(this.fieldPath(), 'ge', value, this.edmType);
}
/**
* Creates an instance of Filter for this field and the given value using the operator 'lt', i.e. `<`.
*
* @param value - Value to be used in the filter
* @returns The resulting filter
*/
lessThan(value: moment.Duration): Filter<EntityT, moment.Duration> {
return new Filter(this.fieldPath(), 'lt', value, this.edmType);
}
/**
* Creates an instance of Filter for this field and the given value using the operator 'le', i.e. `<=`.
*
* @param value - Value to be used in the filter
* @returns The resulting filter
*/
lessOrEqual(value: moment.Duration): Filter<EntityT, moment.Duration> {
return new Filter(this.fieldPath(), 'le', value, this.edmType);
}
}
/**
* Represents a selectable property with a duration value.
*
* @typeparam EntityT - Type of the entity the field belongs to
*/
export class DurationField<EntityT extends EntityBase> extends DurtionFieldBase<
EntityT
> {
readonly selectable: true;
}
/**
* Represents a complex type property with a duration value.
*
* @typeparam EntityT - Type of the entity the field belongs to
*/
export class ComplexTypeDurationPropertyField<
EntityT extends EntityBase,
ComplexT = any
> extends DurtionFieldBase<EntityT> {
/**
* The constructor of the entity or the complex type this field belongs to
*/
readonly fieldOf: ConstructorOrField<EntityT, ComplexT>;
/**
* Creates an instance of ComplexTypeDurationPropertyField.
*
* @param fieldName - Actual name of the field used in the OData request
* @param fieldOf - The constructor of the entity or the complex type this field belongs to
* @param edmType - Type of the field according to the metadata description
*/
constructor(
fieldName: string,
fieldOf: ConstructorOrField<EntityT, ComplexT>,
edmType: EdmTypeShared<ODataVersionOf<EntityT>>
);
/**
* @deprecated Since v1.19.0.
*
* Creates an instance of ComplexTypeDurationPropertyField.
*
* @param fieldName - Actual name of the field used in the OData request
* @param entityConstructor - Constructor type of the entity the field belongs to
* @param parentTypeName - Name of the parent complex type
* @param edmType - Type of the field according to the metadata description
*/
constructor(
fieldName: string,
entityConstructor: Constructable<EntityT>,
parentTypeName: string,
edmType: EdmTypeShared<ODataVersionOf<EntityT>>
);
/*
* Union of the two possible constructors.
*/
constructor(
fieldName: string,
fieldOf: ConstructorOrField<EntityT, ComplexT>,
arg3: string | EdmTypeShared<ODataVersionOf<EntityT>>,
arg4?: EdmTypeShared<ODataVersionOf<EntityT>>
) {
super(fieldName, getEntityConstructor(fieldOf), getEdmType(arg3, arg4));
this.fieldOf = fieldOf;
}
/**
* Path to the field to be used in filter and order by queries. Combines the parent complex type name with the field name.
*
* @returns Path to the field to be used in filter and order by queries.
*/
fieldPath(): string {
return this.fieldOf instanceof ComplexTypeField
? `${this.fieldOf.fieldPath()}/${this._fieldName}`
: this._fieldName;
}
}