Improve types
This commit is contained in:
parent
bf62153b8b
commit
0e24df2ddf
|
@ -639,19 +639,19 @@ export function fixupFilterArrays(filters: SearchFilters) {
|
||||||
return filters
|
return filters
|
||||||
}
|
}
|
||||||
|
|
||||||
export function search<T>(
|
export function search<T extends Record<string, any>>(
|
||||||
docs: Record<string, T>[],
|
docs: T[],
|
||||||
query: RowSearchParams
|
query: Omit<RowSearchParams, "tableId">
|
||||||
): SearchResponse<Record<string, T>> {
|
): SearchResponse<T> {
|
||||||
let result = runQuery(docs, query.query)
|
let result = runQuery(docs, query.query)
|
||||||
if (query.sort) {
|
if (query.sort) {
|
||||||
result = sort(result, query.sort, query.sortOrder || SortOrder.ASCENDING)
|
result = sort(result, query.sort, query.sortOrder || SortOrder.ASCENDING)
|
||||||
}
|
}
|
||||||
let totalRows = result.length
|
const totalRows = result.length
|
||||||
if (query.limit) {
|
if (query.limit) {
|
||||||
result = limit(result, query.limit.toString())
|
result = limit(result, query.limit.toString())
|
||||||
}
|
}
|
||||||
const response: SearchResponse<Record<string, any>> = { rows: result }
|
const response: SearchResponse<T> = { rows: result }
|
||||||
if (query.countRows) {
|
if (query.countRows) {
|
||||||
response.totalRows = totalRows
|
response.totalRows = totalRows
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue