1
- import { entries } from '@seedcompany/common' ;
1
+ import { entries , Nil } from '@seedcompany/common' ;
2
2
import {
3
3
comparisions ,
4
4
inArray ,
@@ -12,7 +12,7 @@ import { PatternCollection } from 'cypher-query-builder/dist/typings/clauses/pat
12
12
import { Comparator } from 'cypher-query-builder/dist/typings/clauses/where-comparators' ;
13
13
import { AndConditions } from 'cypher-query-builder/src/clauses/where-utils' ;
14
14
import { identity , isFunction } from 'lodash' ;
15
- import { ConditionalKeys } from 'type-fest' ;
15
+ import { AbstractClass , ConditionalKeys } from 'type-fest' ;
16
16
import { DateTimeFilter } from '~/common' ;
17
17
import { ACTIVE } from './matching' ;
18
18
import { path as pathPattern } from './where-path' ;
@@ -30,6 +30,19 @@ export type Builders<T> = {
30
30
[ K in keyof Required < T > ] : Builder < T , K > ;
31
31
} ;
32
32
33
+ /**
34
+ * A helper to define filters for the given filter class type.
35
+ * Functions can do nothing, adjust the query, return an object to add conditions to
36
+ * the where clause, or return a function which will be called after the where clause.
37
+ */
38
+ export const define =
39
+ < T extends Record < string , any > > (
40
+ filterClass : ( ) => AbstractClass < T > ,
41
+ builders : Builders < T > ,
42
+ ) =>
43
+ ( filters : T | Nil ) =>
44
+ builder ( filters ?? { } , builders ) ;
45
+
33
46
/**
34
47
* A helper to split filters given and call their respective functions.
35
48
* Functions can do nothing, adjust query, return an object to add conditions to
0 commit comments