|
| 1 | +import { Document, Keyword, KeywordType } from 'lib/types' |
| 2 | + |
| 3 | +export type RangeQueryOptions< |
| 4 | + TDocument extends Document, |
| 5 | + TKeyword extends Keyword<TDocument> = Keyword<TDocument> |
| 6 | +> = { |
| 7 | + gt?: KeywordType<TDocument, TKeyword> |
| 8 | + gte?: KeywordType<TDocument, TKeyword> |
| 9 | + lt?: KeywordType<TDocument, TKeyword> |
| 10 | + lte?: KeywordType<TDocument, TKeyword> |
| 11 | +} |
| 12 | + |
| 13 | +export type RangeQueryBody< |
| 14 | + TDocument extends Document, |
| 15 | + TKeyword extends Keyword<TDocument> = Keyword<TDocument> |
| 16 | +> = { |
| 17 | + [x in TKeyword]?: RangeQueryOptions<TDocument, TKeyword> |
| 18 | +} |
| 19 | + |
| 20 | +// eslint-disable-next-line @typescript-eslint/no-explicit-any |
| 21 | +export type RangeQuery< |
| 22 | + TDocument extends Document, |
| 23 | + TKeyword extends Keyword<TDocument> = Keyword<TDocument> |
| 24 | +> = { |
| 25 | + range: RangeQueryBody<TDocument, TKeyword> |
| 26 | +} |
| 27 | + |
| 28 | +// eslint-disable-next-line @typescript-eslint/no-explicit-any |
| 29 | +export const getRangeQuery = < |
| 30 | + TDocument extends Document, |
| 31 | + TKeyword extends Keyword<TDocument> = Keyword<TDocument> |
| 32 | +>(field: TKeyword, options: RangeQueryOptions<TDocument, TKeyword>): RangeQuery<TDocument, TKeyword> => ({ |
| 33 | + range: { [field]: options } as RangeQueryBody<TDocument, TKeyword> |
| 34 | +}) |
0 commit comments