diff --git a/lerna.json b/lerna.json index 10e7b8cdee..a0de97dc7a 100644 --- a/lerna.json +++ b/lerna.json @@ -1,6 +1,6 @@ { "$schema": "node_modules/lerna/schemas/lerna-schema.json", - "version": "3.4.24", + "version": "3.5.0", "npmClient": "yarn", "concurrency": 20, "command": { diff --git a/packages/frontend-core/src/fetch/DataFetch.ts b/packages/frontend-core/src/fetch/DataFetch.ts index 298413b1e8..cbc9972484 100644 --- a/packages/frontend-core/src/fetch/DataFetch.ts +++ b/packages/frontend-core/src/fetch/DataFetch.ts @@ -8,7 +8,6 @@ import { Row, SearchFilters, SortOrder, - SortType, TableSchema, } from "@budibase/types" import { APIClient } from "../api/types" @@ -72,8 +71,6 @@ export default abstract class BaseDataFetch< options: DataFetchOptions & { datasource: TDatasource - sortType: SortType | null - // Client side feature customisation clientSideSearching: boolean clientSideSorting: boolean @@ -106,7 +103,6 @@ export default abstract class BaseDataFetch< // Sorting config sortColumn: null, sortOrder: SortOrder.ASCENDING, - sortType: null, // Pagination config paginate: true, @@ -227,31 +223,12 @@ export default abstract class BaseDataFetch< this.options.sortColumn = this.getDefaultSortColumn(definition, schema) } - // If we don't have a sort column specified then just ensure we don't set - // any sorting params - if (!this.options.sortColumn) { + // If no sort order, default to ascending + if (!this.options.sortOrder) { this.options.sortOrder = SortOrder.ASCENDING - this.options.sortType = null } else { - // Otherwise determine what sort type to use base on sort column - this.options.sortType = SortType.STRING - const fieldSchema = schema?.[this.options.sortColumn] - if ( - fieldSchema?.type === FieldType.NUMBER || - fieldSchema?.type === FieldType.BIGINT || - ("calculationType" in fieldSchema && fieldSchema?.calculationType) - ) { - this.options.sortType = SortType.NUMBER - } - - // If no sort order, default to ascending - if (!this.options.sortOrder) { - this.options.sortOrder = SortOrder.ASCENDING - } else { - // Ensure sortOrder matches the enum - this.options.sortOrder = - this.options.sortOrder.toLowerCase() as SortOrder - } + // Ensure sortOrder matches the enum + this.options.sortOrder = this.options.sortOrder.toLowerCase() as SortOrder } // Build the query @@ -294,7 +271,6 @@ export default abstract class BaseDataFetch< const { sortColumn, sortOrder, - sortType, limit, clientSideSearching, clientSideSorting, @@ -311,8 +287,8 @@ export default abstract class BaseDataFetch< } // If we don't support sorting, do a client-side sort - if (!this.features.supportsSort && clientSideSorting && sortType) { - rows = sort(rows, sortColumn as any, sortOrder, sortType) + if (!this.features.supportsSort && clientSideSorting && sortColumn) { + rows = sort(rows, sortColumn, sortOrder) } // If we don't support pagination, do a client-side limit diff --git a/packages/frontend-core/src/fetch/TableFetch.ts b/packages/frontend-core/src/fetch/TableFetch.ts index a6f92c0ab3..59bfc588f5 100644 --- a/packages/frontend-core/src/fetch/TableFetch.ts +++ b/packages/frontend-core/src/fetch/TableFetch.ts @@ -29,8 +29,7 @@ export default class TableFetch extends BaseDataFetch { } async getData() { - const { datasource, limit, sortColumn, sortOrder, sortType, paginate } = - this.options + const { datasource, limit, sortColumn, sortOrder, paginate } = this.options const { tableId } = datasource const { cursor, query } = get(this.store) @@ -41,7 +40,6 @@ export default class TableFetch extends BaseDataFetch { limit, sort: sortColumn, sortOrder: sortOrder ?? SortOrder.ASCENDING, - sortType, paginate, bookmark: cursor, }) diff --git a/packages/frontend-core/src/fetch/ViewV2Fetch.ts b/packages/frontend-core/src/fetch/ViewV2Fetch.ts index fd2eab2d53..4495450a23 100644 --- a/packages/frontend-core/src/fetch/ViewV2Fetch.ts +++ b/packages/frontend-core/src/fetch/ViewV2Fetch.ts @@ -1,4 +1,5 @@ import { + SearchViewRowRequest, SortOrder, ViewDatasource, ViewV2Enriched, @@ -40,8 +41,7 @@ export default class ViewV2Fetch extends BaseDataFetch< } async getData() { - const { datasource, limit, sortColumn, sortOrder, sortType, paginate } = - this.options + const { datasource, limit, sortColumn, sortOrder, paginate } = this.options const { cursor, query, definition } = get(this.store) // If this is a calculation view and we have no calculations, return nothing @@ -68,14 +68,13 @@ export default class ViewV2Fetch extends BaseDataFetch< } try { - const request = { + const request: SearchViewRowRequest = { query, paginate, limit, bookmark: cursor, sort: sortColumn, sortOrder: sortOrder, - sortType, } if (paginate) { const res = await this.API.viewV2.fetch(datasource.id, { diff --git a/packages/server/src/api/controllers/row/index.ts b/packages/server/src/api/controllers/row/index.ts index 8f4629a5b0..07ed4172ab 100644 --- a/packages/server/src/api/controllers/row/index.ts +++ b/packages/server/src/api/controllers/row/index.ts @@ -263,7 +263,6 @@ export async function search(ctx: Ctx) { limit: searchRequest.limit, sort: searchRequest.sort ?? undefined, sortOrder: searchRequest.sortOrder, - sortType: searchRequest.sortType ?? undefined, countRows: searchRequest.countRows, version: searchRequest.version, disableEscaping: searchRequest.disableEscaping, diff --git a/packages/server/src/api/controllers/row/views.ts b/packages/server/src/api/controllers/row/views.ts index 418aa462c4..78931c5d4d 100644 --- a/packages/server/src/api/controllers/row/views.ts +++ b/packages/server/src/api/controllers/row/views.ts @@ -63,14 +63,12 @@ function getSortOptions(request: SearchViewRowRequest, view: ViewV2) { return { sort: request.sort, sortOrder: request.sortOrder, - sortType: request.sortType ?? undefined, } } if (view.sort) { return { sort: view.sort.field, sortOrder: view.sort.order, - sortType: view.sort.type, } } diff --git a/packages/server/src/api/routes/tests/search.spec.ts b/packages/server/src/api/routes/tests/search.spec.ts index e115297ee9..cf7c7cf9fa 100644 --- a/packages/server/src/api/routes/tests/search.spec.ts +++ b/packages/server/src/api/routes/tests/search.spec.ts @@ -38,7 +38,7 @@ import { import _ from "lodash" import tk from "timekeeper" import { encodeJSBinding } from "@budibase/string-templates" -import { dataFilters } from "@budibase/shared-core" +import { dataFilters, InMemorySearchQuery } from "@budibase/shared-core" import { Knex } from "knex" import { generator, structures, mocks } from "@budibase/backend-core/tests" import { DEFAULT_EMPLOYEE_TABLE_SCHEMA } from "../../../db/defaultData/datasource_bb_default" @@ -200,31 +200,26 @@ if (descriptions.length) { const isView = sourceType === "view" class SearchAssertion { - constructor(private readonly query: SearchRowRequest) {} + constructor( + private readonly query: SearchRowRequest & { + sortType?: SortType + } + ) {} private async performSearch(): Promise> { if (isInMemory) { - const inMemoryQuery: RequiredKeys< - Omit - > = { + const inMemoryQuery: RequiredKeys = { sort: this.query.sort ?? undefined, query: { ...this.query.query }, - paginate: this.query.paginate, - bookmark: this.query.bookmark ?? undefined, limit: this.query.limit, sortOrder: this.query.sortOrder, sortType: this.query.sortType ?? undefined, - version: this.query.version, - disableEscaping: this.query.disableEscaping, countRows: this.query.countRows, - viewId: undefined, - fields: undefined, - indexer: undefined, - rows: undefined, } return dataFilters.search(_.cloneDeep(rows), inMemoryQuery) } else { - return config.api.row.search(tableOrViewId, this.query) + const { sortType, ...query } = this.query + return config.api.row.search(tableOrViewId, query) } } @@ -400,7 +395,9 @@ if (descriptions.length) { } } - function expectSearch(query: SearchRowRequest) { + function expectSearch( + query: SearchRowRequest & { sortType?: SortType } + ) { return new SearchAssertion(query) } @@ -1119,25 +1116,26 @@ if (descriptions.length) { }).toMatchExactly([{ name: "foo" }, { name: "bar" }]) }) - describe("sortType STRING", () => { - it("sorts ascending", async () => { - await expectSearch({ - query: {}, - sort: "name", - sortType: SortType.STRING, - sortOrder: SortOrder.ASCENDING, - }).toMatchExactly([{ name: "bar" }, { name: "foo" }]) - }) + isInMemory && + describe("sortType STRING", () => { + it("sorts ascending", async () => { + await expectSearch({ + query: {}, + sort: "name", + sortType: SortType.STRING, + sortOrder: SortOrder.ASCENDING, + }).toMatchExactly([{ name: "bar" }, { name: "foo" }]) + }) - it("sorts descending", async () => { - await expectSearch({ - query: {}, - sort: "name", - sortType: SortType.STRING, - sortOrder: SortOrder.DESCENDING, - }).toMatchExactly([{ name: "foo" }, { name: "bar" }]) + it("sorts descending", async () => { + await expectSearch({ + query: {}, + sort: "name", + sortType: SortType.STRING, + sortOrder: SortOrder.DESCENDING, + }).toMatchExactly([{ name: "foo" }, { name: "bar" }]) + }) }) - }) !isInternal && !isInMemory && @@ -1319,25 +1317,26 @@ if (descriptions.length) { }) }) - describe("sortType NUMBER", () => { - it("sorts ascending", async () => { - await expectSearch({ - query: {}, - sort: "age", - sortType: SortType.NUMBER, - sortOrder: SortOrder.ASCENDING, - }).toMatchExactly([{ age: 1 }, { age: 10 }]) - }) + isInMemory && + describe("sortType NUMBER", () => { + it("sorts ascending", async () => { + await expectSearch({ + query: {}, + sort: "age", + sortType: SortType.NUMBER, + sortOrder: SortOrder.ASCENDING, + }).toMatchExactly([{ age: 1 }, { age: 10 }]) + }) - it("sorts descending", async () => { - await expectSearch({ - query: {}, - sort: "age", - sortType: SortType.NUMBER, - sortOrder: SortOrder.DESCENDING, - }).toMatchExactly([{ age: 10 }, { age: 1 }]) + it("sorts descending", async () => { + await expectSearch({ + query: {}, + sort: "age", + sortType: SortType.NUMBER, + sortOrder: SortOrder.DESCENDING, + }).toMatchExactly([{ age: 10 }, { age: 1 }]) + }) }) - }) }) describe("dates", () => { @@ -1473,25 +1472,26 @@ if (descriptions.length) { }).toMatchExactly([{ dob: JAN_10TH }, { dob: JAN_1ST }]) }) - describe("sortType STRING", () => { - it("sorts ascending", async () => { - await expectSearch({ - query: {}, - sort: "dob", - sortType: SortType.STRING, - sortOrder: SortOrder.ASCENDING, - }).toMatchExactly([{ dob: JAN_1ST }, { dob: JAN_10TH }]) - }) + isInMemory && + describe("sortType STRING", () => { + it("sorts ascending", async () => { + await expectSearch({ + query: {}, + sort: "dob", + sortType: SortType.STRING, + sortOrder: SortOrder.ASCENDING, + }).toMatchExactly([{ dob: JAN_1ST }, { dob: JAN_10TH }]) + }) - it("sorts descending", async () => { - await expectSearch({ - query: {}, - sort: "dob", - sortType: SortType.STRING, - sortOrder: SortOrder.DESCENDING, - }).toMatchExactly([{ dob: JAN_10TH }, { dob: JAN_1ST }]) + it("sorts descending", async () => { + await expectSearch({ + query: {}, + sort: "dob", + sortType: SortType.STRING, + sortOrder: SortOrder.DESCENDING, + }).toMatchExactly([{ dob: JAN_10TH }, { dob: JAN_1ST }]) + }) }) - }) }) }) @@ -1639,220 +1639,196 @@ if (descriptions.length) { ]) }) - describe("sortType STRING", () => { - it("sorts ascending", async () => { - await expectSearch({ - query: {}, - sort: "time", - sortType: SortType.STRING, - sortOrder: SortOrder.ASCENDING, - }).toMatchExactly([ - { timeid: NULL_TIME__ID }, - { time: "00:00:00" }, - { time: "10:00:00" }, - { time: "10:45:00" }, - { time: "12:00:00" }, - { time: "15:30:00" }, - ]) - }) - - it("sorts descending", async () => { - await expectSearch({ - query: {}, - sort: "time", - sortType: SortType.STRING, - sortOrder: SortOrder.DESCENDING, - }).toMatchExactly([ - { time: "15:30:00" }, - { time: "12:00:00" }, - { time: "10:45:00" }, - { time: "10:00:00" }, - { time: "00:00:00" }, - { timeid: NULL_TIME__ID }, - ]) - }) - }) - }) - }) - - describe("datetime - date only", () => { - describe.each([true, false])( - "saved with timestamp: %s", - saveWithTimestamp => { - describe.each([true, false])( - "search with timestamp: %s", - searchWithTimestamp => { - const SAVE_SUFFIX = saveWithTimestamp - ? "T00:00:00.000Z" - : "" - const SEARCH_SUFFIX = searchWithTimestamp - ? "T00:00:00.000Z" - : "" - - const JAN_1ST = `2020-01-01` - const JAN_10TH = `2020-01-10` - const JAN_30TH = `2020-01-30` - const UNEXISTING_DATE = `2020-01-03` - const NULL_DATE__ID = `null_date__id` - - beforeAll(async () => { - tableOrViewId = await createTableOrView({ - dateid: { - name: "dateid", - type: FieldType.STRING, - }, - date: { - name: "date", - type: FieldType.DATETIME, - dateOnly: true, - }, - }) - - await createRows([ - { dateid: NULL_DATE__ID, date: null }, - { date: `${JAN_1ST}${SAVE_SUFFIX}` }, - { date: `${JAN_10TH}${SAVE_SUFFIX}` }, + isInMemory && + describe("sortType STRING", () => { + it("sorts ascending", async () => { + await expectSearch({ + query: {}, + sort: "time", + sortType: SortType.STRING, + sortOrder: SortOrder.ASCENDING, + }).toMatchExactly([ + { timeid: NULL_TIME__ID }, + { time: "00:00:00" }, + { time: "10:00:00" }, + { time: "10:45:00" }, + { time: "12:00:00" }, + { time: "15:30:00" }, ]) }) - describe("equal", () => { - it("successfully finds a row", async () => { - await expectQuery({ - equal: { date: `${JAN_1ST}${SEARCH_SUFFIX}` }, - }).toContainExactly([{ date: JAN_1ST }]) - }) - - it("successfully finds an ISO8601 row", async () => { - await expectQuery({ - equal: { date: `${JAN_10TH}${SEARCH_SUFFIX}` }, - }).toContainExactly([{ date: JAN_10TH }]) - }) - - it("finds a row with ISO8601 timestamp", async () => { - await expectQuery({ - equal: { date: `${JAN_1ST}${SEARCH_SUFFIX}` }, - }).toContainExactly([{ date: JAN_1ST }]) - }) - - it("fails to find nonexistent row", async () => { - await expectQuery({ - equal: { - date: `${UNEXISTING_DATE}${SEARCH_SUFFIX}`, - }, - }).toFindNothing() - }) + it("sorts descending", async () => { + await expectSearch({ + query: {}, + sort: "time", + sortType: SortType.STRING, + sortOrder: SortOrder.DESCENDING, + }).toMatchExactly([ + { time: "15:30:00" }, + { time: "12:00:00" }, + { time: "10:45:00" }, + { time: "10:00:00" }, + { time: "00:00:00" }, + { timeid: NULL_TIME__ID }, + ]) }) + }) + }) + }) - describe("notEqual", () => { - it("successfully finds a row", async () => { - await expectQuery({ - notEqual: { - date: `${JAN_1ST}${SEARCH_SUFFIX}`, + !isInMemory && + describe("datetime - date only", () => { + describe.each([true, false])( + "saved with timestamp: %s", + saveWithTimestamp => { + describe.each([true, false])( + "search with timestamp: %s", + searchWithTimestamp => { + const SAVE_SUFFIX = saveWithTimestamp + ? "T00:00:00.000Z" + : "" + const SEARCH_SUFFIX = searchWithTimestamp + ? "T00:00:00.000Z" + : "" + + const JAN_1ST = `2020-01-01` + const JAN_10TH = `2020-01-10` + const JAN_30TH = `2020-01-30` + const UNEXISTING_DATE = `2020-01-03` + const NULL_DATE__ID = `null_date__id` + + beforeAll(async () => { + tableOrViewId = await createTableOrView({ + dateid: { + name: "dateid", + type: FieldType.STRING, }, - }).toContainExactly([ - { date: JAN_10TH }, - { dateid: NULL_DATE__ID }, + date: { + name: "date", + type: FieldType.DATETIME, + dateOnly: true, + }, + }) + + await createRows([ + { dateid: NULL_DATE__ID, date: null }, + { date: `${JAN_1ST}${SAVE_SUFFIX}` }, + { date: `${JAN_10TH}${SAVE_SUFFIX}` }, ]) }) - it("fails to find nonexistent row", async () => { - await expectQuery({ - notEqual: { - date: `${JAN_30TH}${SEARCH_SUFFIX}`, - }, - }).toContainExactly([ - { date: JAN_1ST }, - { date: JAN_10TH }, - { dateid: NULL_DATE__ID }, - ]) - }) - }) + describe("equal", () => { + it("successfully finds a row", async () => { + await expectQuery({ + equal: { date: `${JAN_1ST}${SEARCH_SUFFIX}` }, + }).toContainExactly([{ date: JAN_1ST }]) + }) - describe("oneOf", () => { - it("successfully finds a row", async () => { - await expectQuery({ - oneOf: { date: [`${JAN_1ST}${SEARCH_SUFFIX}`] }, - }).toContainExactly([{ date: JAN_1ST }]) - }) + it("successfully finds an ISO8601 row", async () => { + await expectQuery({ + equal: { date: `${JAN_10TH}${SEARCH_SUFFIX}` }, + }).toContainExactly([{ date: JAN_10TH }]) + }) - it("fails to find nonexistent row", async () => { - await expectQuery({ - oneOf: { - date: [`${UNEXISTING_DATE}${SEARCH_SUFFIX}`], - }, - }).toFindNothing() - }) - }) + it("finds a row with ISO8601 timestamp", async () => { + await expectQuery({ + equal: { date: `${JAN_1ST}${SEARCH_SUFFIX}` }, + }).toContainExactly([{ date: JAN_1ST }]) + }) - describe("range", () => { - it("successfully finds a row", async () => { - await expectQuery({ - range: { - date: { - low: `${JAN_1ST}${SEARCH_SUFFIX}`, - high: `${JAN_1ST}${SEARCH_SUFFIX}`, + it("fails to find nonexistent row", async () => { + await expectQuery({ + equal: { + date: `${UNEXISTING_DATE}${SEARCH_SUFFIX}`, }, - }, - }).toContainExactly([{ date: JAN_1ST }]) + }).toFindNothing() + }) }) - it("successfully finds multiple rows", async () => { - await expectQuery({ - range: { - date: { - low: `${JAN_1ST}${SEARCH_SUFFIX}`, - high: `${JAN_10TH}${SEARCH_SUFFIX}`, + describe("notEqual", () => { + it("successfully finds a row", async () => { + await expectQuery({ + notEqual: { + date: `${JAN_1ST}${SEARCH_SUFFIX}`, }, - }, - }).toContainExactly([ - { date: JAN_1ST }, - { date: JAN_10TH }, - ]) - }) + }).toContainExactly([ + { date: JAN_10TH }, + { dateid: NULL_DATE__ID }, + ]) + }) - it("successfully finds no rows", async () => { - await expectQuery({ - range: { - date: { - low: `${JAN_30TH}${SEARCH_SUFFIX}`, - high: `${JAN_30TH}${SEARCH_SUFFIX}`, + it("fails to find nonexistent row", async () => { + await expectQuery({ + notEqual: { + date: `${JAN_30TH}${SEARCH_SUFFIX}`, }, - }, - }).toFindNothing() - }) - }) - - describe("sort", () => { - it("sorts ascending", async () => { - await expectSearch({ - query: {}, - sort: "date", - sortOrder: SortOrder.ASCENDING, - }).toMatchExactly([ - { dateid: NULL_DATE__ID }, - { date: JAN_1ST }, - { date: JAN_10TH }, - ]) + }).toContainExactly([ + { date: JAN_1ST }, + { date: JAN_10TH }, + { dateid: NULL_DATE__ID }, + ]) + }) }) - it("sorts descending", async () => { - await expectSearch({ - query: {}, - sort: "date", - sortOrder: SortOrder.DESCENDING, - }).toMatchExactly([ - { date: JAN_10TH }, - { date: JAN_1ST }, - { dateid: NULL_DATE__ID }, - ]) + describe("oneOf", () => { + it("successfully finds a row", async () => { + await expectQuery({ + oneOf: { date: [`${JAN_1ST}${SEARCH_SUFFIX}`] }, + }).toContainExactly([{ date: JAN_1ST }]) + }) + + it("fails to find nonexistent row", async () => { + await expectQuery({ + oneOf: { + date: [`${UNEXISTING_DATE}${SEARCH_SUFFIX}`], + }, + }).toFindNothing() + }) }) - describe("sortType STRING", () => { + describe("range", () => { + it("successfully finds a row", async () => { + await expectQuery({ + range: { + date: { + low: `${JAN_1ST}${SEARCH_SUFFIX}`, + high: `${JAN_1ST}${SEARCH_SUFFIX}`, + }, + }, + }).toContainExactly([{ date: JAN_1ST }]) + }) + + it("successfully finds multiple rows", async () => { + await expectQuery({ + range: { + date: { + low: `${JAN_1ST}${SEARCH_SUFFIX}`, + high: `${JAN_10TH}${SEARCH_SUFFIX}`, + }, + }, + }).toContainExactly([ + { date: JAN_1ST }, + { date: JAN_10TH }, + ]) + }) + + it("successfully finds no rows", async () => { + await expectQuery({ + range: { + date: { + low: `${JAN_30TH}${SEARCH_SUFFIX}`, + high: `${JAN_30TH}${SEARCH_SUFFIX}`, + }, + }, + }).toFindNothing() + }) + }) + + describe("sort", () => { it("sorts ascending", async () => { await expectSearch({ query: {}, sort: "date", - sortType: SortType.STRING, sortOrder: SortOrder.ASCENDING, }).toMatchExactly([ { dateid: NULL_DATE__ID }, @@ -1865,7 +1841,6 @@ if (descriptions.length) { await expectSearch({ query: {}, sort: "date", - sortType: SortType.STRING, sortOrder: SortOrder.DESCENDING, }).toMatchExactly([ { date: JAN_10TH }, @@ -1873,13 +1848,41 @@ if (descriptions.length) { { dateid: NULL_DATE__ID }, ]) }) + + isInMemory && + describe("sortType STRING", () => { + it("sorts ascending", async () => { + await expectSearch({ + query: {}, + sort: "date", + sortType: SortType.STRING, + sortOrder: SortOrder.ASCENDING, + }).toMatchExactly([ + { dateid: NULL_DATE__ID }, + { date: JAN_1ST }, + { date: JAN_10TH }, + ]) + }) + + it("sorts descending", async () => { + await expectSearch({ + query: {}, + sort: "date", + sortType: SortType.STRING, + sortOrder: SortOrder.DESCENDING, + }).toMatchExactly([ + { date: JAN_10TH }, + { date: JAN_1ST }, + { dateid: NULL_DATE__ID }, + ]) + }) + }) }) - }) - } - ) - } - ) - }) + } + ) + } + ) + }) isInternal && !isInMemory && diff --git a/packages/server/src/api/routes/tests/viewV2.spec.ts b/packages/server/src/api/routes/tests/viewV2.spec.ts index ad41aa618c..3f1bb43016 100644 --- a/packages/server/src/api/routes/tests/viewV2.spec.ts +++ b/packages/server/src/api/routes/tests/viewV2.spec.ts @@ -24,7 +24,6 @@ import { SearchResponse, SearchViewRowRequest, SortOrder, - SortType, StaticQuotaName, Table, TableSchema, @@ -154,7 +153,6 @@ if (descriptions.length) { sort: { field: "fieldToSort", order: SortOrder.DESCENDING, - type: SortType.STRING, }, schema: { id: { visible: true }, @@ -217,7 +215,6 @@ if (descriptions.length) { sort: { field: "fieldToSort", order: SortOrder.DESCENDING, - type: SortType.STRING, }, schema: { id: { visible: true }, @@ -1147,7 +1144,6 @@ if (descriptions.length) { sort: { field: generator.word(), order: SortOrder.DESCENDING, - type: SortType.STRING, }, schema: { id: { visible: true }, @@ -3153,7 +3149,6 @@ if (descriptions.length) { { field: string order?: SortOrder - type?: SortType }, string[] ][] = [ @@ -3161,7 +3156,6 @@ if (descriptions.length) { { field: "name", order: SortOrder.ASCENDING, - type: SortType.STRING, }, ["Alice", "Bob", "Charly", "Danny"], ], @@ -3178,22 +3172,6 @@ if (descriptions.length) { }, ["Danny", "Charly", "Bob", "Alice"], ], - [ - { - field: "name", - order: SortOrder.DESCENDING, - type: SortType.STRING, - }, - ["Danny", "Charly", "Bob", "Alice"], - ], - [ - { - field: "age", - order: SortOrder.ASCENDING, - type: SortType.NUMBER, - }, - ["Danny", "Alice", "Charly", "Bob"], - ], [ { field: "age", @@ -3204,15 +3182,13 @@ if (descriptions.length) { [ { field: "age", - order: SortOrder.DESCENDING, }, - ["Bob", "Charly", "Alice", "Danny"], + ["Danny", "Alice", "Charly", "Bob"], ], [ { field: "age", order: SortOrder.DESCENDING, - type: SortType.NUMBER, }, ["Bob", "Charly", "Alice", "Danny"], ], @@ -3299,7 +3275,6 @@ if (descriptions.length) { sort: { field: "name", order: SortOrder.ASCENDING, - type: SortType.STRING, }, schema: viewSchema, }) @@ -3307,7 +3282,6 @@ if (descriptions.length) { const response = await config.api.viewV2.search(view.id, { sort: sortParams.field, sortOrder: sortParams.order, - sortType: sortParams.type, query: {}, }) diff --git a/packages/server/src/integrations/s3.ts b/packages/server/src/integrations/s3.ts index 88d00724f1..32a44c838b 100644 --- a/packages/server/src/integrations/s3.ts +++ b/packages/server/src/integrations/s3.ts @@ -168,6 +168,7 @@ class S3Integration implements IntegrationBase { secretAccessKey: config.secretAccessKey, }, region: config.region, + endpoint: config.endpoint, } if (config.endpoint) { this.config.forcePathStyle = true diff --git a/packages/server/src/sdk/app/rows/search.ts b/packages/server/src/sdk/app/rows/search.ts index 3a582a46ea..8de46dc9fe 100644 --- a/packages/server/src/sdk/app/rows/search.ts +++ b/packages/server/src/sdk/app/rows/search.ts @@ -46,7 +46,6 @@ export async function search( query: options.query, sort: options.sort, sortOrder: options.sortOrder, - sortType: options.sortType, limit: options.limit, bookmark: options.bookmark, paginate: options.paginate, 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 84162a67af..76b496f92a 100644 --- a/packages/server/src/sdk/app/rows/search/internal/sqs.ts +++ b/packages/server/src/sdk/app/rows/search/internal/sqs.ts @@ -1,5 +1,6 @@ import { Aggregation, + AutoFieldSubType, CalculationType, DocumentType, EnrichedQueryJson, @@ -420,7 +421,11 @@ export async function search( } } else if (sortField) { const sortType = - sortField.type === FieldType.NUMBER ? SortType.NUMBER : SortType.STRING + sortField.type === FieldType.NUMBER || + (sortField.type === FieldType.AUTO && + sortField.subtype === AutoFieldSubType.AUTO_ID) + ? SortType.NUMBER + : SortType.STRING request.sort = { [mapToUserColumn(sortField.name)]: { direction: params.sortOrder || SortOrder.ASCENDING, diff --git a/packages/shared-core/src/filters.ts b/packages/shared-core/src/filters.ts index afe99d9565..5da5c34a4f 100644 --- a/packages/shared-core/src/filters.ts +++ b/packages/shared-core/src/filters.ts @@ -11,7 +11,6 @@ import { SortType, FieldConstraints, SortOrder, - RowSearchParams, EmptyFilterOption, SearchResponse, Table, @@ -25,6 +24,8 @@ import { isArraySearchOperator, isRangeSearchOperator, SearchFilter, + WithRequired, + SearchParams, } from "@budibase/types" import dayjs from "dayjs" import { OperatorOptions, SqlNumberTypeRangeMap } from "./constants" @@ -521,9 +522,19 @@ export function fixupFilterArrays(filters: SearchFilters) { return filters } +type SearchQuery = WithRequired< + Pick< + SearchParams, + "query" | "sort" | "sortOrder" | "sortType" | "limit" | "countRows" + >, + "query" +> + +export type InMemorySearchQuery = SearchQuery + export function search>( docs: T[], - query: Omit + query: SearchQuery ): SearchResponse { let result = runQuery(docs, query.query) if (query.sort) { diff --git a/packages/shared-core/src/index.ts b/packages/shared-core/src/index.ts index a4f4208f4a..daf4601c03 100644 --- a/packages/shared-core/src/index.ts +++ b/packages/shared-core/src/index.ts @@ -1,5 +1,6 @@ export * from "./constants" export * as dataFilters from "./filters" +export type * from "./filters" export * as helpers from "./helpers" export * as utils from "./utils" export * as sdk from "./sdk" diff --git a/packages/shared-core/src/tests/cron.test.ts b/packages/shared-core/src/tests/cron.spec.ts similarity index 100% rename from packages/shared-core/src/tests/cron.test.ts rename to packages/shared-core/src/tests/cron.spec.ts diff --git a/packages/shared-core/src/tests/themes.ts b/packages/shared-core/src/tests/themes.spec.ts similarity index 100% rename from packages/shared-core/src/tests/themes.ts rename to packages/shared-core/src/tests/themes.spec.ts diff --git a/packages/types/src/api/web/app/rows/search.ts b/packages/types/src/api/web/app/rows/search.ts index 7ba23bceca..4d903d44b6 100644 --- a/packages/types/src/api/web/app/rows/search.ts +++ b/packages/types/src/api/web/app/rows/search.ts @@ -8,11 +8,7 @@ import { SearchFilterKey, } from "../../../../sdk" import { Row } from "../../../../documents" -import { - PaginationResponse, - SortOrder, - SortType, -} from "../../../../api/web/pagination" +import { PaginationResponse, SortOrder } from "../../../../api/web/pagination" import { z } from "zod" const fieldKey = z @@ -70,7 +66,6 @@ const searchRowRequest = z.object({ limit: z.number().optional(), sort: z.string().nullish(), sortOrder: z.nativeEnum(SortOrder).optional(), - sortType: z.nativeEnum(SortType).nullish(), version: z.string().optional(), disableEscaping: z.boolean().optional(), countRows: z.boolean().optional(), @@ -83,7 +78,6 @@ export type SearchViewRowRequest = Pick< SearchRowRequest, | "sort" | "sortOrder" - | "sortType" | "limit" | "bookmark" | "paginate" diff --git a/packages/types/src/sdk/row.ts b/packages/types/src/sdk/row.ts index 6328a80ba1..da5eb0b041 100644 --- a/packages/types/src/sdk/row.ts +++ b/packages/types/src/sdk/row.ts @@ -50,7 +50,7 @@ export interface SearchParams { // when searching for rows we want a more extensive search type that requires certain properties export interface RowSearchParams - extends WithRequired {} + extends WithRequired, "tableId" | "query"> {} export interface SearchResponse { rows: T[]