Support outputSquash fields on searchs
This commit is contained in:
parent
73ec0bbf09
commit
1bc1db9b29
|
@ -1,6 +1,7 @@
|
|||
import {
|
||||
IncludeRelationship,
|
||||
Operation,
|
||||
OutputRowOptions,
|
||||
PaginationJson,
|
||||
Row,
|
||||
RowSearchParams,
|
||||
|
@ -60,7 +61,8 @@ function getPaginationAndLimitParameters(
|
|||
|
||||
export async function search(
|
||||
options: RowSearchParams,
|
||||
table: Table
|
||||
table: Table,
|
||||
outputRowOptions?: OutputRowOptions
|
||||
): Promise<SearchResponse<Row>> {
|
||||
const { tableId } = options
|
||||
const { countRows, paginate, query, ...params } = options
|
||||
|
@ -115,6 +117,7 @@ export async function search(
|
|||
let processed = await outputProcessing(table, rows, {
|
||||
preserveLinks: true,
|
||||
squash: true,
|
||||
squashNestedFields: outputRowOptions?.squashNestedFields,
|
||||
})
|
||||
|
||||
let hasNextPage = false
|
||||
|
|
|
@ -2,6 +2,7 @@ import { PROTECTED_INTERNAL_COLUMNS } from "@budibase/shared-core"
|
|||
import { fullSearch, paginatedSearch } from "../utils"
|
||||
import { InternalTables } from "../../../../../db/utils"
|
||||
import {
|
||||
OutputRowOptions,
|
||||
Row,
|
||||
RowSearchParams,
|
||||
SearchResponse,
|
||||
|
@ -15,7 +16,8 @@ import pick from "lodash/pick"
|
|||
|
||||
export async function search(
|
||||
options: RowSearchParams,
|
||||
table: Table
|
||||
table: Table,
|
||||
outputRowOptions?: OutputRowOptions
|
||||
): Promise<SearchResponse<Row>> {
|
||||
const { tableId } = options
|
||||
|
||||
|
@ -59,7 +61,9 @@ export async function search(
|
|||
response.rows = response.rows.map((r: any) => pick(r, fields))
|
||||
}
|
||||
|
||||
response.rows = await outputProcessing(table, response.rows)
|
||||
response.rows = await outputProcessing(table, response.rows, {
|
||||
squashNestedFields: outputRowOptions?.squashNestedFields,
|
||||
})
|
||||
}
|
||||
|
||||
return response
|
||||
|
|
|
@ -4,6 +4,7 @@ import {
|
|||
FieldType,
|
||||
isLogicalSearchOperator,
|
||||
Operation,
|
||||
OutputRowOptions,
|
||||
QueryJson,
|
||||
RelationshipFieldMetadata,
|
||||
RelationshipsJson,
|
||||
|
@ -283,7 +284,7 @@ function resyncDefinitionsRequired(status: number, message: string) {
|
|||
export async function search(
|
||||
options: RowSearchParams,
|
||||
table: Table,
|
||||
opts?: { retrying?: boolean }
|
||||
opts?: { retrying?: boolean; outputRowOptions?: OutputRowOptions }
|
||||
): Promise<SearchResponse<Row>> {
|
||||
let { paginate, query, ...params } = options
|
||||
|
||||
|
@ -382,6 +383,7 @@ export async function search(
|
|||
let finalRows = await outputProcessing(table, processed, {
|
||||
preserveLinks: true,
|
||||
squash: true,
|
||||
squashNestedFields: opts?.outputRowOptions?.squashNestedFields,
|
||||
})
|
||||
|
||||
// check if we need to pick specific rows out
|
||||
|
@ -409,7 +411,10 @@ export async function search(
|
|||
const msg = typeof err === "string" ? err : err.message
|
||||
if (!opts?.retrying && resyncDefinitionsRequired(err.status, msg)) {
|
||||
await sdk.tables.sqs.syncDefinition()
|
||||
return search(options, table, { retrying: true })
|
||||
return search(options, table, {
|
||||
retrying: true,
|
||||
outputRowOptions: opts?.outputRowOptions,
|
||||
})
|
||||
}
|
||||
// previously the internal table didn't error when a column didn't exist in search
|
||||
if (err.status === 400 && msg?.match(MISSING_COLUMN_REGEX)) {
|
||||
|
|
|
@ -16,6 +16,7 @@ import {
|
|||
IdentityType,
|
||||
Row,
|
||||
RowAttachment,
|
||||
SquashTableFields,
|
||||
Table,
|
||||
User,
|
||||
} from "@budibase/types"
|
||||
|
@ -247,6 +248,7 @@ export async function outputProcessing<T extends Row[] | Row>(
|
|||
preserveLinks?: boolean
|
||||
fromRow?: Row
|
||||
skipBBReferences?: boolean
|
||||
squashNestedFields?: SquashTableFields
|
||||
} = {
|
||||
squash: true,
|
||||
preserveLinks: false,
|
||||
|
@ -342,8 +344,12 @@ export async function outputProcessing<T extends Row[] | Row>(
|
|||
// process formulas after the complex types had been processed
|
||||
enriched = await processFormulas(table, enriched, { dynamic: true })
|
||||
|
||||
if (opts.squash) {
|
||||
enriched = await linkRows.squashLinks(table, enriched)
|
||||
if (opts.squash || opts.squashNestedFields) {
|
||||
enriched = await linkRows.squashLinks(
|
||||
table,
|
||||
enriched,
|
||||
opts.squashNestedFields
|
||||
)
|
||||
}
|
||||
// remove null properties to match internal API
|
||||
const isExternal = isExternalTableID(table._id!)
|
||||
|
|
|
@ -36,3 +36,9 @@ export enum RowExportFormat {
|
|||
JSON = "json",
|
||||
JSON_WITH_SCHEMA = "jsonWithSchema",
|
||||
}
|
||||
|
||||
export interface OutputRowOptions {
|
||||
squashNestedFields: SquashTableFields
|
||||
}
|
||||
|
||||
export type SquashTableFields = Record<string, { visibleFieldNames: string[] }>
|
||||
|
|
Loading…
Reference in New Issue