-
Notifications
You must be signed in to change notification settings - Fork 367
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
7d85719
commit f96f40b
Showing
4 changed files
with
68 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import type { Filter, FilterConditionTypes } from '@linode/api-v4'; | ||
|
||
type OrderDirection = FilterConditionTypes['+order']; | ||
type XFilterableField = string; | ||
|
||
type FilterOperator = Exclude< | ||
keyof FilterConditionTypes, | ||
'+order' | '+order_by' | ||
>; | ||
|
||
type FieldFilter = { | ||
[K in FilterOperator]?: FilterConditionTypes[K]; | ||
}; | ||
|
||
interface XFilterDefaults { | ||
order: OrderDirection; | ||
orderBy: XFilterableField; | ||
} | ||
|
||
interface BuildXFilterParams<T extends XFilterableField> { | ||
additionalFilters?: Partial<Record<T, FieldFilter>>; | ||
defaults: XFilterDefaults; | ||
order?: OrderDirection; | ||
orderBy?: T; | ||
} | ||
|
||
export function buildXFilters<T extends XFilterableField>({ | ||
additionalFilters, | ||
defaults, | ||
order, | ||
orderBy, | ||
}: BuildXFilterParams<T>): Filter { | ||
return { | ||
'+order': order ?? defaults.order, | ||
'+order_by': orderBy ?? defaults.orderBy, | ||
...additionalFilters, | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters