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

Commit 9d3d827

Browse files
committed
fix(filter): Fixes $not operator in filters.
Disallows top level $not to align with Mongo. BREAKING CHANGE: Disallows top level $not operator in filters.
1 parent b2e0110 commit 9d3d827

File tree

2 files changed

+7
-9
lines changed

2 files changed

+7
-9
lines changed

src/tests/utils/filterTest.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,6 @@ export default (opts: Opts) => {
7474

7575
it('should filter correctly when using $not operator', async () => {
7676
await createTestEntities();
77-
await opts.assertFirstEntityFilter({ $not: { stringProp: 'b' } });
77+
await opts.assertFirstEntityFilter({ stringProp: { $not: 'b' } });
7878
});
7979
};

src/types/Filter.ts

+6-8
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,19 @@ export type GreaterFilter<Prop> = { readonly $gt: Prop } | { readonly $gte: Prop
22
export type LesserFilter<Prop> = { readonly $lt: Prop } | { readonly $lte: Prop };
33
export type InFilter<Prop> = { readonly $in: Prop[] } | { readonly $nin: Prop[] };
44
export type EqualityFilter<Prop> = { readonly $eq: Prop } | { readonly $ne: Prop };
5+
export interface NotFilter<Prop> { readonly $not: PropFilter<Prop>; }
56

67
export type PropFilter<Prop> = (
78
GreaterFilter<Prop> |
89
LesserFilter<Prop> |
910
InFilter<Prop> |
10-
EqualityFilter<Prop>
11+
EqualityFilter<Prop> |
12+
NotFilter<Prop> |
13+
Prop
1114
);
1215

1316
export type EntityFilter<Entity> = {
14-
readonly [P in keyof Entity]?: Entity[P] | PropFilter<Entity[P]>;
17+
readonly [P in keyof Entity]?: PropFilter<Entity[P]>;
1518
};
1619

1720
export interface AndFilter<Entity> {
@@ -22,15 +25,10 @@ export interface OrFilter<Entity> {
2225
readonly $or: Filter<Entity>[];
2326
}
2427

25-
export interface NotFilter<Entity> {
26-
readonly $not: Filter<Entity>;
27-
}
28-
2928
export type Filter<Entity> = (
3029
EntityFilter<Entity> |
3130
AndFilter<Entity> |
32-
OrFilter<Entity> |
33-
NotFilter<Entity>
31+
OrFilter<Entity>
3432
);
3533

3634
export default Filter;

0 commit comments

Comments
 (0)