-
Notifications
You must be signed in to change notification settings - Fork 8
/
query-filter.ts
100 lines (90 loc) · 2.98 KB
/
query-filter.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
export type FilterBuilder<T> = {
[P in keyof T]-?: FilterBuilderProp<T[P]>
}
export type FilterBuilderProp<T> = null extends T
? FilterBuilderType<T> & FilterNullable
: FilterBuilderType<T>
export type FilterBuilderType<T> = T extends Array<infer R>
? FilterCollection<R>
: T extends string
? FilterString
: T extends number
? FilterNumber
: T extends boolean
? FilterBoolean
: T extends Date
? FilterDate
: T extends Object
? FilterBuilder<T>
: never
export interface StringOptions {
/** Applies `tolower` method to the property */
caseInsensitive?: boolean
/** Ignores Guid type casting */
ignoreGuid?: boolean
}
export interface FilterExpression {
not(): FilterExpression
and(exp: FilterExpression): FilterExpression
or(exp: FilterExpression): FilterExpression
}
export interface FilterDate {
inTimeSpan(
y: number,
m?: number,
d?: number,
h?: number,
mm?: number
): FilterExpression
isSame(d: string | Date | FilterDate): FilterExpression
isSame(
d: number | Date | FilterDate,
g: 'year' | 'month' | 'day' | 'hour' | 'minute' | 'second'
): FilterExpression
isAfter(d: string | Date | FilterDate): FilterExpression
isAfterOrEqual(d: string | Date | FilterDate): FilterExpression
isBefore(d: string | Date | FilterDate): FilterExpression
isBeforeOrEqual(d: string | Date | FilterDate): FilterExpression
}
export interface FilterString {
contains(s: string | FilterString, options?: StringOptions): FilterExpression
equals(s: string | FilterString, options?: StringOptions): FilterExpression
notEquals(s: string | FilterString, options?: StringOptions): FilterExpression
startsWith(
s: string | FilterString,
options?: StringOptions
): FilterExpression
endsWith(s: string | FilterString, options?: StringOptions): FilterExpression
in(list: string[]): FilterExpression
length(): FilterNumber
tolower(): FilterString
toupper(): FilterString
trim(): FilterString
indexof(s: string): FilterNumber
substring(n: number): FilterString
append(s: string): FilterString
prepend(s: string): FilterString
}
export interface FilterNumber {
equals(n: number | FilterNumber): FilterExpression
notEquals(n: number | FilterNumber): FilterExpression
biggerThan(n: number | FilterNumber): FilterExpression
biggerThanOrEqual(n: number | FilterNumber): FilterExpression
lessThan(n: number | FilterNumber): FilterExpression
lessThanOrEqual(n: number | FilterNumber): FilterExpression
in(list: number[]): FilterExpression
}
export interface FilterBoolean {
equals(b: boolean | FilterBoolean): FilterExpression
notEquals(b: boolean | FilterBoolean): FilterExpression
}
export interface FilterNullable {
isNull(): FilterExpression
notNull(): FilterExpression
}
export interface FilterCollection<T> {
empty(): FilterExpression
notEmpty(): FilterExpression
any(c: (arg: FilterBuilderProp<T>) => FilterExpression): FilterExpression
all(c: (arg: FilterBuilderProp<T>) => FilterExpression): FilterExpression
}