diff --git a/packages/server/src/api/routes/tests/viewV2.spec.ts b/packages/server/src/api/routes/tests/viewV2.spec.ts index 1d47769fb8..ba2e93afbf 100644 --- a/packages/server/src/api/routes/tests/viewV2.spec.ts +++ b/packages/server/src/api/routes/tests/viewV2.spec.ts @@ -1653,7 +1653,7 @@ describe.each([ }) describe("search", () => { - it.only("returns empty rows from view when no schema is passed", async () => { + it("returns empty rows from view when no schema is passed", async () => { const rows = await Promise.all( Array.from({ length: 10 }, () => config.api.row.save(table._id!, {})) ) @@ -2197,28 +2197,6 @@ describe.each([ expect(response.rows).toHaveLength(0) }) - it("queries the row api passing the view fields only", async () => { - const searchSpy = jest.spyOn(sdk.rows, "search") - - const view = await config.api.viewV2.create({ - tableId: table._id!, - name: generator.guid(), - schema: { - id: { visible: true }, - one: { visible: false }, - }, - }) - - await config.api.viewV2.search(view.id, { query: {} }) - expect(searchSpy).toHaveBeenCalledTimes(1) - - expect(searchSpy).toHaveBeenCalledWith( - expect.objectContaining({ - fields: ["id"], - }) - ) - }) - describe("foreign relationship columns", () => { let envCleanup: () => void beforeAll(() => { diff --git a/packages/server/src/sdk/app/rows/search/internal/sqs.ts b/packages/server/src/sdk/app/rows/search/internal/sqs.ts index a01b1bc820..26e8f59303 100644 --- a/packages/server/src/sdk/app/rows/search/internal/sqs.ts +++ b/packages/server/src/sdk/app/rows/search/internal/sqs.ts @@ -463,11 +463,13 @@ export async function search( aggregations, }) - // check if we need to pick specific rows out - if (options.fields) { - const fields = [...options.fields, ...PROTECTED_INTERNAL_COLUMNS] - finalRows = finalRows.map((r: any) => pick(r, fields)) - } + const visibleFields = + options.fields || + Object.keys(source.schema || {}).filter( + key => source.schema?.[key].visible !== false + ) + const allowedFields = [...visibleFields, ...PROTECTED_INTERNAL_COLUMNS] + finalRows = finalRows.map((r: any) => pick(r, allowedFields)) const response: SearchResponse = { rows: finalRows,