/
SearchPropertyType.ts
61 lines (53 loc) · 1.71 KB
/
SearchPropertyType.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
import {OnmsEnum, forId, forLabel} from '../internal/OnmsEnum';
import {Comparator, Comparators} from './Comparator';
/**
* Represents a search property type.
* @category Rest
*/
export class SearchPropertyType extends OnmsEnum<string> {
/** @inheritdoc */
public static forId(id?: string) {
return forId(SearchPropertyTypes, id);
}
/** @inheritdoc */
public static forLabel(label?: string) {
return forLabel(SearchPropertyTypes, label);
}
/** supported comparators. */
private readonly comparators: Comparator[];
constructor(id: string, label: string, someComparators: Comparator[]) {
super(id, label);
this.comparators = someComparators;
}
/**
* Returns the comparators supported by this type.
*
* @returns {Comparator[]} the supported comparators.
*/
public getComparators() {
return this.comparators;
}
}
/** @hidden */
const StringComparators = [
Comparators.EQ, Comparators.NE,
];
/** @hidden */
const NumberComparators = [
Comparators.EQ, Comparators.NE,
Comparators.GE, Comparators.GT,
Comparators.LE, Comparators.LT,
];
/**
* Constant references to all search property types.
* @category Model
*/
export const SearchPropertyTypes = {
FLOAT: new SearchPropertyType('FLOAT', 'floating-point number', NumberComparators),
INTEGER: new SearchPropertyType('INTEGER', 'integer', NumberComparators),
IP_ADDRESS: new SearchPropertyType('IP_ADDRESS', 'IP address', StringComparators),
LONG: new SearchPropertyType('LONG', 'long integer', NumberComparators),
STRING: new SearchPropertyType('STRING', 'string', StringComparators),
TIMESTAMP: new SearchPropertyType('TIMESTAMP', 'date and time', NumberComparators),
};
Object.freeze(SearchPropertyTypes);