Skip to content

Commit d04ee71

Browse files
committed
New way to declare filters without current values
1 parent ed22b23 commit d04ee71

File tree

1 file changed

+15
-2
lines changed

1 file changed

+15
-2
lines changed

src/core/database/query/filters.ts

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { entries } from '@seedcompany/common';
1+
import { entries, Nil } from '@seedcompany/common';
22
import {
33
comparisions,
44
inArray,
@@ -12,7 +12,7 @@ import { PatternCollection } from 'cypher-query-builder/dist/typings/clauses/pat
1212
import { Comparator } from 'cypher-query-builder/dist/typings/clauses/where-comparators';
1313
import { AndConditions } from 'cypher-query-builder/src/clauses/where-utils';
1414
import { identity, isFunction } from 'lodash';
15-
import { ConditionalKeys } from 'type-fest';
15+
import { AbstractClass, ConditionalKeys } from 'type-fest';
1616
import { DateTimeFilter } from '~/common';
1717
import { ACTIVE } from './matching';
1818
import { path as pathPattern } from './where-path';
@@ -30,6 +30,19 @@ export type Builders<T> = {
3030
[K in keyof Required<T>]: Builder<T, K>;
3131
};
3232

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+
3346
/**
3447
* A helper to split filters given and call their respective functions.
3548
* Functions can do nothing, adjust query, return an object to add conditions to

0 commit comments

Comments
 (0)