Skip to content
This repository was archived by the owner on Jun 22, 2021. It is now read-only.

Commit 35c8896

Browse files
committed
fix(Filter): Simplifies filter type.
1 parent 77b427a commit 35c8896

File tree

2 files changed

+18
-28
lines changed

2 files changed

+18
-28
lines changed

src/types/Filter.ts

Lines changed: 17 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,28 @@
1-
export type GreaterFilter<Prop> = { readonly $gt: Prop } | { readonly $gte: Prop };
2-
export type LesserFilter<Prop> = { readonly $lt: Prop } | { readonly $lte: Prop };
3-
export type InFilter<Prop> = { readonly $in: Prop[] } | { readonly $nin: Prop[] };
4-
export type EqualityFilter<Prop> = { readonly $eq: Prop } | { readonly $ne: Prop };
5-
export interface NotFilter<Prop> { readonly $not: PropFilter<Prop>; }
6-
7-
export type PropFilter<Prop> = (
8-
GreaterFilter<Prop> |
9-
LesserFilter<Prop> |
10-
InFilter<Prop> |
11-
EqualityFilter<Prop> |
12-
NotFilter<Prop>
13-
);
1+
export interface PropFilter<Prop> {
2+
readonly $gt?: Prop;
3+
readonly $gte?: Prop;
4+
readonly $lt?: Prop;
5+
readonly $lte?: Prop;
6+
readonly $in?: Prop[];
7+
readonly $nin?: Prop[];
8+
readonly $eq?: Prop;
9+
readonly $ne?: Prop;
10+
readonly $not?: PropFilter<Prop>;
11+
}
1412

1513
export type EntityFilter<Entity> = {
1614
readonly [P in keyof Entity]?: Entity[P] | PropFilter<Entity[P]>;
1715
};
1816

19-
export interface AndFilter<Entity> {
20-
readonly $and: Filter<Entity>[];
21-
}
22-
23-
export interface OrFilter<Entity> {
24-
readonly $or: Filter<Entity>[];
25-
}
26-
27-
export interface NorFilter<Entity> {
28-
readonly $nor: Filter<Entity>[];
17+
export interface ConditionFilter<Entity> {
18+
readonly $and?: Filter<Entity>[];
19+
readonly $or?: Filter<Entity>[];
20+
readonly $nor?: Filter<Entity>[];
2921
}
3022

3123
export type Filter<Entity> = (
32-
EntityFilter<Entity> |
33-
AndFilter<Entity> |
34-
OrFilter<Entity> |
35-
NorFilter<Entity>
24+
EntityFilter<Entity> &
25+
ConditionFilter<Entity>
3626
);
3727

3828
export default Filter;

src/utils/createPaginationFilter/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import * as atob from 'atob';
22
import { get, mapValues } from 'lodash';
33
// tslint:disable-next-line:no-unused
4-
import Filter, { AndFilter, NorFilter, NotFilter, OrFilter } from '../../types/Filter';
4+
import Filter, { ConditionFilter, EntityFilter } from '../../types/Filter';
55
import Pagination from '../../types/Pagination';
66
import Sort from '../../types/Sort';
77

0 commit comments

Comments
 (0)