Getting search input mapping up a level in the search SDK - avoids having to call it for every search type.
This commit is contained in:
parent
c40e965634
commit
bfb7750213
|
@ -13,6 +13,8 @@ import * as sqs from "./search/sqs"
|
|||
import env from "../../../environment"
|
||||
import { ExportRowsParams, ExportRowsResult } from "./search/types"
|
||||
import { dataFilters } from "@budibase/shared-core"
|
||||
import sdk from "../../index"
|
||||
import { searchInputMapping } from "./search/utils"
|
||||
|
||||
export { isValidFilter } from "../../../integrations/utils"
|
||||
|
||||
|
@ -72,12 +74,15 @@ export async function search(
|
|||
}
|
||||
}
|
||||
|
||||
const table = await sdk.tables.getTable(options.tableId)
|
||||
options = searchInputMapping(table, options)
|
||||
|
||||
if (isExternalTable) {
|
||||
return external.search(options)
|
||||
return external.search(options, table)
|
||||
} else if (env.SQS_SEARCH_ENABLE) {
|
||||
return sqs.search(options)
|
||||
return sqs.search(options, table)
|
||||
} else {
|
||||
return internal.search(options)
|
||||
return internal.search(options, table)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -8,6 +8,7 @@ import {
|
|||
SearchFilters,
|
||||
RowSearchParams,
|
||||
SearchResponse,
|
||||
Table,
|
||||
} from "@budibase/types"
|
||||
import * as exporters from "../../../../api/controllers/view/exporters"
|
||||
import { handleRequest } from "../../../../api/controllers/row/external"
|
||||
|
@ -18,13 +19,13 @@ import {
|
|||
import { utils } from "@budibase/shared-core"
|
||||
import { ExportRowsParams, ExportRowsResult } from "./types"
|
||||
import { HTTPError, db } from "@budibase/backend-core"
|
||||
import { searchInputMapping } from "./utils"
|
||||
import pick from "lodash/pick"
|
||||
import { outputProcessing } from "../../../../utilities/rowProcessor"
|
||||
import sdk from "../../../"
|
||||
|
||||
export async function search(
|
||||
options: RowSearchParams
|
||||
options: RowSearchParams,
|
||||
table: Table
|
||||
): Promise<SearchResponse<Row>> {
|
||||
const { tableId } = options
|
||||
const { paginate, query, ...params } = options
|
||||
|
@ -68,8 +69,6 @@ export async function search(
|
|||
}
|
||||
|
||||
try {
|
||||
const table = await sdk.tables.getTable(tableId)
|
||||
options = searchInputMapping(table, options)
|
||||
let rows = await handleRequest(Operation.READ, tableId, {
|
||||
filters: query,
|
||||
sort,
|
||||
|
@ -150,11 +149,15 @@ export async function exportRows(
|
|||
}
|
||||
|
||||
const datasource = await sdk.datasources.get(datasourceId!)
|
||||
const table = await sdk.tables.getTable(tableId)
|
||||
if (!datasource || !datasource.entities) {
|
||||
throw new HTTPError("Datasource has not been configured for plus API.", 400)
|
||||
}
|
||||
|
||||
let result = await search({ tableId, query: requestQuery, sort, sortOrder })
|
||||
let result = await search(
|
||||
{ tableId, query: requestQuery, sort, sortOrder },
|
||||
table
|
||||
)
|
||||
let rows: Row[] = []
|
||||
let headers
|
||||
|
||||
|
|
|
@ -33,7 +33,8 @@ import pick from "lodash/pick"
|
|||
import { breakRowIdField } from "../../../../integrations/utils"
|
||||
|
||||
export async function search(
|
||||
options: RowSearchParams
|
||||
options: RowSearchParams,
|
||||
table: Table
|
||||
): Promise<SearchResponse<Row>> {
|
||||
const { tableId } = options
|
||||
|
||||
|
@ -51,8 +52,6 @@ export async function search(
|
|||
query: {},
|
||||
}
|
||||
|
||||
let table = await sdk.tables.getTable(tableId)
|
||||
options = searchInputMapping(table, options)
|
||||
if (params.sort && !params.sortType) {
|
||||
const schema = table.schema
|
||||
const sortField = schema[params.sort]
|
||||
|
@ -122,12 +121,15 @@ export async function exportRows(
|
|||
|
||||
result = await outputProcessing<Row[]>(table, response)
|
||||
} else if (query) {
|
||||
let searchResponse = await search({
|
||||
tableId,
|
||||
query,
|
||||
sort,
|
||||
sortOrder,
|
||||
})
|
||||
let searchResponse = await search(
|
||||
{
|
||||
tableId,
|
||||
query,
|
||||
sort,
|
||||
sortOrder,
|
||||
},
|
||||
table
|
||||
)
|
||||
result = searchResponse.rows
|
||||
}
|
||||
|
||||
|
|
|
@ -112,7 +112,7 @@ describe("external search", () => {
|
|||
tableId,
|
||||
query: {},
|
||||
}
|
||||
const result = await search(searchParams)
|
||||
const result = await search(searchParams, config.table!)
|
||||
|
||||
expect(result.rows).toHaveLength(10)
|
||||
expect(result.rows).toEqual(
|
||||
|
@ -130,7 +130,7 @@ describe("external search", () => {
|
|||
query: {},
|
||||
fields: ["name", "age"],
|
||||
}
|
||||
const result = await search(searchParams)
|
||||
const result = await search(searchParams, config.table!)
|
||||
|
||||
expect(result.rows).toHaveLength(10)
|
||||
expect(result.rows).toEqual(
|
||||
|
@ -157,7 +157,7 @@ describe("external search", () => {
|
|||
},
|
||||
},
|
||||
}
|
||||
const result = await search(searchParams)
|
||||
const result = await search(searchParams, config.table!)
|
||||
|
||||
expect(result.rows).toHaveLength(3)
|
||||
expect(result.rows.map(row => row.id)).toEqual([1, 4, 8])
|
||||
|
|
|
@ -81,7 +81,7 @@ describe("internal", () => {
|
|||
tableId,
|
||||
query: {},
|
||||
}
|
||||
const result = await search(searchParams)
|
||||
const result = await search(searchParams, config.table!)
|
||||
|
||||
expect(result.rows).toHaveLength(10)
|
||||
expect(result.rows).toEqual(
|
||||
|
@ -99,7 +99,7 @@ describe("internal", () => {
|
|||
query: {},
|
||||
fields: ["name", "age"],
|
||||
}
|
||||
const result = await search(searchParams)
|
||||
const result = await search(searchParams, config.table!)
|
||||
|
||||
expect(result.rows).toHaveLength(10)
|
||||
expect(result.rows).toEqual(
|
||||
|
|
Loading…
Reference in New Issue