From f26a8d410aef9e3994962843655f2a172f982273 Mon Sep 17 00:00:00 2001 From: Adria Navarro Date: Fri, 5 Jul 2024 11:19:01 +0200 Subject: [PATCH 01/14] Add export composite key --- .../server/src/api/routes/tests/row.spec.ts | 37 +++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/packages/server/src/api/routes/tests/row.spec.ts b/packages/server/src/api/routes/tests/row.spec.ts index b6e3edf5ff..d92438a310 100644 --- a/packages/server/src/api/routes/tests/row.spec.ts +++ b/packages/server/src/api/routes/tests/row.spec.ts @@ -1452,6 +1452,43 @@ describe.each([ { status: 404 } ) }) + + it("can export rows with composite primary keys", async () => { + const tableRequest = saveTableRequest({ + primary: ["number", "string"], + schema: { + string: { + type: FieldType.STRING, + name: "string", + }, + number: { + type: FieldType.NUMBER, + name: "number", + }, + }, + }) + delete tableRequest.schema.id + + const table = await config.api.table.save(tableRequest) + + const rows = await Promise.all( + generator + .unique( + () => ({ + string: generator.word({ length: 30 }), + number: generator.integer({ min: 0, max: 10000 }), + }), + 10 + ) + .map(d => config.api.row.save(table._id!, d)) + ) + + const res = await config.api.row.exportRows(table._id!, { + rows: _.sampleSize(rows, 3).map(r => r._id!), + }) + const results = JSON.parse(res) + expect(results.length).toEqual(3) + }) }) let o2mTable: Table From 85827bbf9309a3894b7ab215f8277bda5aaa0f5e Mon Sep 17 00:00:00 2001 From: Adria Navarro Date: Mon, 8 Jul 2024 13:27:30 +0200 Subject: [PATCH 02/14] Refactor breakRowIdField --- packages/backend-core/src/sql/sql.ts | 3 +-- packages/backend-core/src/sql/utils.ts | 3 +++ 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/packages/backend-core/src/sql/sql.ts b/packages/backend-core/src/sql/sql.ts index 615753efc3..c17cbae86f 100644 --- a/packages/backend-core/src/sql/sql.ts +++ b/packages/backend-core/src/sql/sql.ts @@ -217,8 +217,7 @@ class InternalBuilder { if (!opts.relationship && !isRelationshipField) { const alias = getTableAlias(tableName) fn(alias ? `${alias}.${updatedKey}` : updatedKey, value) - } - if (opts.relationship && isRelationshipField) { + } else if (opts.relationship && isRelationshipField) { const [filterTableName, property] = updatedKey.split(".") const alias = getTableAlias(filterTableName) fn(alias ? `${alias}.${property}` : property, value) diff --git a/packages/backend-core/src/sql/utils.ts b/packages/backend-core/src/sql/utils.ts index 45ab510948..4b0ac82ffe 100644 --- a/packages/backend-core/src/sql/utils.ts +++ b/packages/backend-core/src/sql/utils.ts @@ -116,6 +116,9 @@ export function breakRowIdField(_id: string | { _id: string }): any[] { return Array.isArray(parsed) ? parsed : [parsed] } catch (err) { // wasn't json - likely was handlebars for a many to many + if (Array.isArray(_id)) { + return _id + } return [_id] } } From 5be8882122fec80594a80bc1c63217c86e34a6a2 Mon Sep 17 00:00:00 2001 From: Adria Navarro Date: Tue, 9 Jul 2024 10:43:45 +0200 Subject: [PATCH 03/14] Handle composite keys on exports --- packages/backend-core/src/sql/sql.ts | 14 ++++++++++- .../api/controllers/row/ExternalRequest.ts | 25 +++++++++++++++---- .../server/src/api/routes/tests/row.spec.ts | 18 +------------ .../src/sdk/app/rows/search/external.ts | 5 +--- 4 files changed, 35 insertions(+), 27 deletions(-) diff --git a/packages/backend-core/src/sql/sql.ts b/packages/backend-core/src/sql/sql.ts index c17cbae86f..7410ca5dbf 100644 --- a/packages/backend-core/src/sql/sql.ts +++ b/packages/backend-core/src/sql/sql.ts @@ -172,6 +172,8 @@ function convertBooleans(query: SqlQuery | SqlQuery[]): SqlQuery | SqlQuery[] { return query } +const COMPLEX_ID_OPERATOR = "_complexIdOperator" + class InternalBuilder { private readonly client: string @@ -214,7 +216,14 @@ class InternalBuilder { for (let [key, value] of Object.entries(structure)) { const updatedKey = dbCore.removeKeyNumbering(key) const isRelationshipField = updatedKey.includes(".") - if (!opts.relationship && !isRelationshipField) { + + if (updatedKey === COMPLEX_ID_OPERATOR) { + const alias = getTableAlias(tableName) + fn( + value.id.map((x: string) => (alias ? `${alias}.${x}` : x)), + value.values + ) + } else if (!opts.relationship && !isRelationshipField) { const alias = getTableAlias(tableName) fn(alias ? `${alias}.${updatedKey}` : updatedKey, value) } else if (opts.relationship && isRelationshipField) { @@ -745,6 +754,9 @@ class InternalBuilder { class SqlQueryBuilder extends SqlTableQueryBuilder { private readonly limit: number + + public static COMPLEX_ID_OPERATOR = COMPLEX_ID_OPERATOR + // pass through client to get flavour of SQL constructor(client: string, limit: number = BASE_LIMIT) { super(client) diff --git a/packages/server/src/api/controllers/row/ExternalRequest.ts b/packages/server/src/api/controllers/row/ExternalRequest.ts index b51de46e99..a50297f7b0 100644 --- a/packages/server/src/api/controllers/row/ExternalRequest.ts +++ b/packages/server/src/api/controllers/row/ExternalRequest.ts @@ -40,7 +40,7 @@ import { } from "../../../sdk/app/rows/utils" import { processObjectSync } from "@budibase/string-templates" import { cloneDeep } from "lodash/fp" -import { db as dbCore } from "@budibase/backend-core" +import { db as dbCore, sql } from "@budibase/backend-core" import sdk from "../../../sdk" import env from "../../../environment" import { makeExternalQuery } from "../../../integrations/base/query" @@ -193,11 +193,26 @@ export class ExternalRequest { for (let field of Object.keys(operator || {})) { if (dbCore.removeKeyNumbering(field) === "_id") { if (primary) { - const parts = breakRowIdField(operator[field]) - for (let field of primary) { - operator[`${prefix}:${field}`] = parts.shift() + let idField = operator[field] + try { + // Make sure _id queries decode the Row IDs + idField = JSON.parse(idField) + } catch { + // It is not a JSON value + } + + const parts = breakRowIdField(idField) + if (primary.length > 1) { + operator[sql.Sql.COMPLEX_ID_OPERATOR] = { + id: primary, + values: parts, + } + } else { + for (let field of primary) { + operator[`${prefix}:${field}`] = parts.shift() + } + prefix++ } - prefix++ } // make sure this field doesn't exist on any filter delete operator[field] diff --git a/packages/server/src/api/routes/tests/row.spec.ts b/packages/server/src/api/routes/tests/row.spec.ts index d92438a310..9628757d16 100644 --- a/packages/server/src/api/routes/tests/row.spec.ts +++ b/packages/server/src/api/routes/tests/row.spec.ts @@ -1428,22 +1428,6 @@ describe.each([ expect(row._id).toEqual(existing._id) }) - it("should return an error on composite keys", async () => { - const existing = await config.api.row.save(table._id!, {}) - await config.api.row.exportRows( - table._id!, - { - rows: [`['${existing._id!}']`, "['d001', '10111']"], - }, - { - status: 400, - body: { - message: "Export data does not support composite keys.", - }, - } - ) - }) - it("should return an error if no table is found", async () => { const existing = await config.api.row.save(table._id!, {}) await config.api.row.exportRows( @@ -1453,7 +1437,7 @@ describe.each([ ) }) - it("can export rows with composite primary keys", async () => { + it("should handle filtering by composite primary keys", async () => { const tableRequest = saveTableRequest({ primary: ["number", "string"], schema: { diff --git a/packages/server/src/sdk/app/rows/search/external.ts b/packages/server/src/sdk/app/rows/search/external.ts index 93c46d8cc3..84306f572f 100644 --- a/packages/server/src/sdk/app/rows/search/external.ts +++ b/packages/server/src/sdk/app/rows/search/external.ts @@ -158,10 +158,7 @@ export async function exportRows( _id: rowIds.map((row: string) => { const ids = breakRowIdField(row) if (ids.length > 1) { - throw new HTTPError( - "Export data does not support composite keys.", - 400 - ) + return ids } return ids[0] }), From 0f1c8eb788eef9d4b35751b7b4385fd7777816e5 Mon Sep 17 00:00:00 2001 From: Adria Navarro Date: Mon, 8 Jul 2024 21:22:03 +0200 Subject: [PATCH 04/14] Disable mssql test --- .../server/src/api/routes/tests/row.spec.ts | 71 ++++++++++--------- 1 file changed, 37 insertions(+), 34 deletions(-) diff --git a/packages/server/src/api/routes/tests/row.spec.ts b/packages/server/src/api/routes/tests/row.spec.ts index 9628757d16..9fc7fb05c1 100644 --- a/packages/server/src/api/routes/tests/row.spec.ts +++ b/packages/server/src/api/routes/tests/row.spec.ts @@ -1437,42 +1437,45 @@ describe.each([ ) }) - it("should handle filtering by composite primary keys", async () => { - const tableRequest = saveTableRequest({ - primary: ["number", "string"], - schema: { - string: { - type: FieldType.STRING, - name: "string", + // MSSQL needs a setting called IDENTITY_INSERT to be set to ON to allow writing + // to identity columns. This is not something Budibase does currently. + providerType !== DatabaseName.SQL_SERVER && + it("should handle filtering by composite primary keys", async () => { + const tableRequest = saveTableRequest({ + primary: ["number", "string"], + schema: { + string: { + type: FieldType.STRING, + name: "string", + }, + number: { + type: FieldType.NUMBER, + name: "number", + }, }, - number: { - type: FieldType.NUMBER, - name: "number", - }, - }, + }) + delete tableRequest.schema.id + + const table = await config.api.table.save(tableRequest) + + const rows = await Promise.all( + generator + .unique( + () => ({ + string: generator.word({ length: 30 }), + number: generator.integer({ min: 0, max: 10000 }), + }), + 10 + ) + .map(d => config.api.row.save(table._id!, d)) + ) + + const res = await config.api.row.exportRows(table._id!, { + rows: _.sampleSize(rows, 3).map(r => r._id!), + }) + const results = JSON.parse(res) + expect(results.length).toEqual(3) }) - delete tableRequest.schema.id - - const table = await config.api.table.save(tableRequest) - - const rows = await Promise.all( - generator - .unique( - () => ({ - string: generator.word({ length: 30 }), - number: generator.integer({ min: 0, max: 10000 }), - }), - 10 - ) - .map(d => config.api.row.save(table._id!, d)) - ) - - const res = await config.api.row.exportRows(table._id!, { - rows: _.sampleSize(rows, 3).map(r => r._id!), - }) - const results = JSON.parse(res) - expect(results.length).toEqual(3) - }) }) let o2mTable: Table From 5387717183dd7c31bc78927c17600d102f91ee60 Mon Sep 17 00:00:00 2001 From: Adria Navarro Date: Tue, 9 Jul 2024 10:21:46 +0200 Subject: [PATCH 05/14] Fix --- packages/backend-core/src/sql/utils.ts | 3 --- 1 file changed, 3 deletions(-) diff --git a/packages/backend-core/src/sql/utils.ts b/packages/backend-core/src/sql/utils.ts index 4b0ac82ffe..45ab510948 100644 --- a/packages/backend-core/src/sql/utils.ts +++ b/packages/backend-core/src/sql/utils.ts @@ -116,9 +116,6 @@ export function breakRowIdField(_id: string | { _id: string }): any[] { return Array.isArray(parsed) ? parsed : [parsed] } catch (err) { // wasn't json - likely was handlebars for a many to many - if (Array.isArray(_id)) { - return _id - } return [_id] } } From 58bd346885a9114ba2baffe6ae78c4b4d76b9cf8 Mon Sep 17 00:00:00 2001 From: Adria Navarro Date: Tue, 9 Jul 2024 10:27:56 +0200 Subject: [PATCH 06/14] Fix --- packages/server/src/api/controllers/row/ExternalRequest.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/server/src/api/controllers/row/ExternalRequest.ts b/packages/server/src/api/controllers/row/ExternalRequest.ts index a50297f7b0..46de4ec350 100644 --- a/packages/server/src/api/controllers/row/ExternalRequest.ts +++ b/packages/server/src/api/controllers/row/ExternalRequest.ts @@ -205,7 +205,7 @@ export class ExternalRequest { if (primary.length > 1) { operator[sql.Sql.COMPLEX_ID_OPERATOR] = { id: primary, - values: parts, + values: parts[0], } } else { for (let field of primary) { From 62f5790a81465592fabd239ca52297b3148fd6f8 Mon Sep 17 00:00:00 2001 From: Adria Navarro Date: Tue, 9 Jul 2024 10:49:57 +0200 Subject: [PATCH 07/14] Remove unnecessary cast --- .../server/src/api/controllers/row/ExternalRequest.ts | 10 +--------- 1 file changed, 1 insertion(+), 9 deletions(-) diff --git a/packages/server/src/api/controllers/row/ExternalRequest.ts b/packages/server/src/api/controllers/row/ExternalRequest.ts index 46de4ec350..dfad5dcf58 100644 --- a/packages/server/src/api/controllers/row/ExternalRequest.ts +++ b/packages/server/src/api/controllers/row/ExternalRequest.ts @@ -193,15 +193,7 @@ export class ExternalRequest { for (let field of Object.keys(operator || {})) { if (dbCore.removeKeyNumbering(field) === "_id") { if (primary) { - let idField = operator[field] - try { - // Make sure _id queries decode the Row IDs - idField = JSON.parse(idField) - } catch { - // It is not a JSON value - } - - const parts = breakRowIdField(idField) + const parts = breakRowIdField(operator[field]) if (primary.length > 1) { operator[sql.Sql.COMPLEX_ID_OPERATOR] = { id: primary, From 9c6347f7fd6345bce83bd924dc7df354f1fec9e9 Mon Sep 17 00:00:00 2001 From: Adria Navarro Date: Tue, 9 Jul 2024 12:24:59 +0200 Subject: [PATCH 08/14] Move constants to types --- packages/backend-core/src/sql/sql.ts | 7 ++----- packages/server/src/api/controllers/row/ExternalRequest.ts | 5 +++-- packages/types/src/sdk/search.ts | 4 ++++ 3 files changed, 9 insertions(+), 7 deletions(-) diff --git a/packages/backend-core/src/sql/sql.ts b/packages/backend-core/src/sql/sql.ts index b274e40de7..76d73c42fe 100644 --- a/packages/backend-core/src/sql/sql.ts +++ b/packages/backend-core/src/sql/sql.ts @@ -15,6 +15,7 @@ import { FieldSchema, FieldType, INTERNAL_TABLE_SOURCE_ID, + InternalSearchFilterOperator, JsonFieldMetadata, JsonTypes, Operation, @@ -170,8 +171,6 @@ function convertBooleans(query: SqlQuery | SqlQuery[]): SqlQuery | SqlQuery[] { return query } -const COMPLEX_ID_OPERATOR = "_complexIdOperator" - class InternalBuilder { private readonly client: string @@ -215,7 +214,7 @@ class InternalBuilder { const updatedKey = dbCore.removeKeyNumbering(key) const isRelationshipField = updatedKey.includes(".") - if (updatedKey === COMPLEX_ID_OPERATOR) { + if (updatedKey === InternalSearchFilterOperator.COMPLEX_ID_OPERATOR) { const alias = getTableAlias(tableName) fn( value.id.map((x: string) => (alias ? `${alias}.${x}` : x)), @@ -753,8 +752,6 @@ class InternalBuilder { class SqlQueryBuilder extends SqlTableQueryBuilder { private readonly limit: number - public static COMPLEX_ID_OPERATOR = COMPLEX_ID_OPERATOR - // pass through client to get flavour of SQL constructor(client: string, limit: number = BASE_LIMIT) { super(client) diff --git a/packages/server/src/api/controllers/row/ExternalRequest.ts b/packages/server/src/api/controllers/row/ExternalRequest.ts index dfad5dcf58..87c9d27ee0 100644 --- a/packages/server/src/api/controllers/row/ExternalRequest.ts +++ b/packages/server/src/api/controllers/row/ExternalRequest.ts @@ -7,6 +7,7 @@ import { FieldType, FilterType, IncludeRelationship, + InternalSearchFilterOperator, isManyToOne, OneToManyRelationshipFieldMetadata, Operation, @@ -40,7 +41,7 @@ import { } from "../../../sdk/app/rows/utils" import { processObjectSync } from "@budibase/string-templates" import { cloneDeep } from "lodash/fp" -import { db as dbCore, sql } from "@budibase/backend-core" +import { db as dbCore } from "@budibase/backend-core" import sdk from "../../../sdk" import env from "../../../environment" import { makeExternalQuery } from "../../../integrations/base/query" @@ -195,7 +196,7 @@ export class ExternalRequest { if (primary) { const parts = breakRowIdField(operator[field]) if (primary.length > 1) { - operator[sql.Sql.COMPLEX_ID_OPERATOR] = { + operator[InternalSearchFilterOperator.COMPLEX_ID_OPERATOR] = { id: primary, values: parts[0], } diff --git a/packages/types/src/sdk/search.ts b/packages/types/src/sdk/search.ts index c40f1c3b84..5ea1f359f1 100644 --- a/packages/types/src/sdk/search.ts +++ b/packages/types/src/sdk/search.ts @@ -17,6 +17,10 @@ export enum SearchFilterOperator { CONTAINS_ANY = "containsAny", } +export enum InternalSearchFilterOperator { + COMPLEX_ID_OPERATOR = "_complexIdOperator", +} + export interface SearchFilters { allOr?: boolean // TODO: this is just around for now - we need a better way to do or/and From 63bd83457ede90eee5c18ed2957b5bbc4493f2b5 Mon Sep 17 00:00:00 2001 From: mike12345567 Date: Tue, 9 Jul 2024 11:26:54 +0100 Subject: [PATCH 09/14] Always allow creating views - don't limit it causing confusion. --- .../DataTable/buttons/grid/GridCreateViewButton.svelte | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/packages/builder/src/components/backend/DataTable/buttons/grid/GridCreateViewButton.svelte b/packages/builder/src/components/backend/DataTable/buttons/grid/GridCreateViewButton.svelte index 3441d8de17..d4f4bcd1b1 100644 --- a/packages/builder/src/components/backend/DataTable/buttons/grid/GridCreateViewButton.svelte +++ b/packages/builder/src/components/backend/DataTable/buttons/grid/GridCreateViewButton.svelte @@ -3,12 +3,11 @@ import { Modal, ActionButton, TooltipType, TempTooltip } from "@budibase/bbui" import GridCreateViewModal from "../../modals/grid/GridCreateViewModal.svelte" - const { rows, columns, filter } = getContext("grid") + const { filter } = getContext("grid") let modal let firstFilterUsage = false - $: disabled = !$columns.length || !$rows.length $: { if ($filter?.length && !firstFilterUsage) { firstFilterUsage = true @@ -21,7 +20,7 @@ type={TooltipType.Info} condition={firstFilterUsage} > - + Create view From 38f7b88735f20c9e580ea60523397f85e5b1bd4c Mon Sep 17 00:00:00 2001 From: Adria Navarro Date: Tue, 9 Jul 2024 14:01:44 +0200 Subject: [PATCH 10/14] Type filters --- packages/backend-core/src/sql/sql.ts | 48 ++++++++---- .../api/controllers/row/ExternalRequest.ts | 4 +- packages/types/src/sdk/search.ts | 75 +++++++++---------- 3 files changed, 70 insertions(+), 57 deletions(-) diff --git a/packages/backend-core/src/sql/sql.ts b/packages/backend-core/src/sql/sql.ts index 76d73c42fe..4936e4da68 100644 --- a/packages/backend-core/src/sql/sql.ts +++ b/packages/backend-core/src/sql/sql.ts @@ -11,6 +11,7 @@ import { import { SqlStatements } from "./sqlStatements" import SqlTableQueryBuilder from "./sqlTable" import { + AnySearchFilter, BBReferenceFieldMetadata, FieldSchema, FieldType, @@ -41,7 +42,7 @@ const envLimit = environment.SQL_MAX_ROWS : null const BASE_LIMIT = envLimit || 5000 -function likeKey(client: string, key: string): string { +function likeKey(client: string | string[], key: string): string { let start: string, end: string switch (client) { case SqlClient.MY_SQL: @@ -207,18 +208,27 @@ class InternalBuilder { return alias || name } function iterate( - structure: { [key: string]: any }, - fn: (key: string, value: any) => void + structure: AnySearchFilter, + fn: (key: string, value: any) => void, + complexKeyFn?: (key: string[], value: any) => void ) { - for (let [key, value] of Object.entries(structure)) { + for (const key in structure) { + const value = structure[key] const updatedKey = dbCore.removeKeyNumbering(key) const isRelationshipField = updatedKey.includes(".") - if (updatedKey === InternalSearchFilterOperator.COMPLEX_ID_OPERATOR) { + let castedTypeValue + if ( + key === InternalSearchFilterOperator.COMPLEX_ID_OPERATOR && + (castedTypeValue = structure[key]) && + complexKeyFn + ) { const alias = getTableAlias(tableName) - fn( - value.id.map((x: string) => (alias ? `${alias}.${x}` : x)), - value.values + complexKeyFn( + castedTypeValue.id.map((x: string) => + alias ? `${alias}.${x}` : x + ), + castedTypeValue.values ) } else if (!opts.relationship && !isRelationshipField) { const alias = getTableAlias(tableName) @@ -246,7 +256,7 @@ class InternalBuilder { } } - const contains = (mode: object, any: boolean = false) => { + const contains = (mode: AnySearchFilter, any: boolean = false) => { const rawFnc = allOr ? "orWhereRaw" : "whereRaw" const not = mode === filters?.notContains ? "NOT " : "" function stringifyArray(value: Array, quoteStyle = '"'): string { @@ -258,7 +268,7 @@ class InternalBuilder { return `[${value.join(",")}]` } if (this.client === SqlClient.POSTGRES) { - iterate(mode, (key: string, value: Array) => { + iterate(mode, (key, value) => { const wrap = any ? "" : "'" const op = any ? "\\?| array" : "@>" const fieldNames = key.split(/\./g) @@ -273,7 +283,7 @@ class InternalBuilder { }) } else if (this.client === SqlClient.MY_SQL) { const jsonFnc = any ? "JSON_OVERLAPS" : "JSON_CONTAINS" - iterate(mode, (key: string, value: Array) => { + iterate(mode, (key, value) => { query = query[rawFnc]( `${not}COALESCE(${jsonFnc}(${key}, '${stringifyArray( value @@ -282,7 +292,7 @@ class InternalBuilder { }) } else { const andOr = mode === filters?.containsAny ? " OR " : " AND " - iterate(mode, (key: string, value: Array) => { + iterate(mode, (key, value) => { let statement = "" for (let i in value) { if (typeof value[i] === "string") { @@ -306,10 +316,16 @@ class InternalBuilder { } if (filters.oneOf) { - iterate(filters.oneOf, (key, array) => { - const fnc = allOr ? "orWhereIn" : "whereIn" - query = query[fnc](key, Array.isArray(array) ? array : [array]) - }) + const fnc = allOr ? "orWhereIn" : "whereIn" + iterate( + filters.oneOf, + (key: string, array) => { + query = query[fnc](key, Array.isArray(array) ? array : [array]) + }, + (key: string[], array) => { + query = query[fnc](key, Array.isArray(array) ? array : [array]) + } + ) } if (filters.string) { iterate(filters.string, (key, value) => { diff --git a/packages/server/src/api/controllers/row/ExternalRequest.ts b/packages/server/src/api/controllers/row/ExternalRequest.ts index 87c9d27ee0..2ecdf9a4cb 100644 --- a/packages/server/src/api/controllers/row/ExternalRequest.ts +++ b/packages/server/src/api/controllers/row/ExternalRequest.ts @@ -190,8 +190,8 @@ export class ExternalRequest { if (filters) { // need to map over the filters and make sure the _id field isn't present let prefix = 1 - for (let operator of Object.values(filters)) { - for (let field of Object.keys(operator || {})) { + for (const operator of Object.values(filters)) { + for (const field of Object.keys(operator || {})) { if (dbCore.removeKeyNumbering(field) === "_id") { if (primary) { const parts = breakRowIdField(operator[field]) diff --git a/packages/types/src/sdk/search.ts b/packages/types/src/sdk/search.ts index 5ea1f359f1..856011284f 100644 --- a/packages/types/src/sdk/search.ts +++ b/packages/types/src/sdk/search.ts @@ -21,51 +21,48 @@ export enum InternalSearchFilterOperator { COMPLEX_ID_OPERATOR = "_complexIdOperator", } +type BasicFilter = Record & { + [InternalSearchFilterOperator.COMPLEX_ID_OPERATOR]?: never +} + +type ArrayFilter = Record & { + [InternalSearchFilterOperator.COMPLEX_ID_OPERATOR]?: { + id: string[] + values: string[] + } +} + +type RangeFilter = Record< + string, + | { + high: number | string + low: number | string + } + | { high: number | string } + | { low: number | string } +> & { + [InternalSearchFilterOperator.COMPLEX_ID_OPERATOR]?: never +} + +export type AnySearchFilter = BasicFilter | ArrayFilter | RangeFilter + export interface SearchFilters { allOr?: boolean // TODO: this is just around for now - we need a better way to do or/and // allows just fuzzy to be or - all the fuzzy/like parameters fuzzyOr?: boolean onEmptyFilter?: EmptyFilterOption - [SearchFilterOperator.STRING]?: { - [key: string]: string - } - [SearchFilterOperator.FUZZY]?: { - [key: string]: string - } - [SearchFilterOperator.RANGE]?: { - [key: string]: - | { - high: number | string - low: number | string - } - | { high: number | string } - | { low: number | string } - } - [SearchFilterOperator.EQUAL]?: { - [key: string]: any - } - [SearchFilterOperator.NOT_EQUAL]?: { - [key: string]: any - } - [SearchFilterOperator.EMPTY]?: { - [key: string]: any - } - [SearchFilterOperator.NOT_EMPTY]?: { - [key: string]: any - } - [SearchFilterOperator.ONE_OF]?: { - [key: string]: any[] - } - [SearchFilterOperator.CONTAINS]?: { - [key: string]: any[] - } - [SearchFilterOperator.NOT_CONTAINS]?: { - [key: string]: any[] - } - [SearchFilterOperator.CONTAINS_ANY]?: { - [key: string]: any[] - } + [SearchFilterOperator.STRING]?: BasicFilter + [SearchFilterOperator.FUZZY]?: BasicFilter + [SearchFilterOperator.RANGE]?: RangeFilter + [SearchFilterOperator.EQUAL]?: BasicFilter + [SearchFilterOperator.NOT_EQUAL]?: BasicFilter + [SearchFilterOperator.EMPTY]?: BasicFilter + [SearchFilterOperator.NOT_EMPTY]?: BasicFilter + [SearchFilterOperator.ONE_OF]?: ArrayFilter + [SearchFilterOperator.CONTAINS]?: ArrayFilter + [SearchFilterOperator.NOT_CONTAINS]?: ArrayFilter + [SearchFilterOperator.CONTAINS_ANY]?: ArrayFilter // specific to SQS/SQLite search on internal tables this can be used // to make sure the documents returned are always filtered down to a // specific document type (such as just rows) From 288d48c60df759d1204fd895b45b55abe9f9b957 Mon Sep 17 00:00:00 2001 From: Adria Navarro Date: Tue, 9 Jul 2024 15:04:41 +0200 Subject: [PATCH 11/14] Fix build --- packages/shared-core/src/filters.ts | 12 ++++-------- packages/types/src/sdk/search.ts | 6 +++--- 2 files changed, 7 insertions(+), 11 deletions(-) diff --git a/packages/shared-core/src/filters.ts b/packages/shared-core/src/filters.ts index 3c6901e195..28f0b28425 100644 --- a/packages/shared-core/src/filters.ts +++ b/packages/shared-core/src/filters.ts @@ -310,16 +310,12 @@ export const buildQuery = (filter: SearchFilter[]) => { query.equal = query.equal || {} query.equal[field] = true } else { - query[queryOperator] = { - ...query[queryOperator], - [field]: value, - } + query[queryOperator] ??= {} + query[queryOperator]![field] = value } } else { - query[queryOperator] = { - ...query[queryOperator], - [field]: value, - } + query[queryOperator] ??= {} + query[queryOperator]![field] = value } } }) diff --git a/packages/types/src/sdk/search.ts b/packages/types/src/sdk/search.ts index 856011284f..713b33ff54 100644 --- a/packages/types/src/sdk/search.ts +++ b/packages/types/src/sdk/search.ts @@ -21,7 +21,7 @@ export enum InternalSearchFilterOperator { COMPLEX_ID_OPERATOR = "_complexIdOperator", } -type BasicFilter = Record & { +type BasicFilter = Record & { [InternalSearchFilterOperator.COMPLEX_ID_OPERATOR]?: never } @@ -52,8 +52,8 @@ export interface SearchFilters { // allows just fuzzy to be or - all the fuzzy/like parameters fuzzyOr?: boolean onEmptyFilter?: EmptyFilterOption - [SearchFilterOperator.STRING]?: BasicFilter - [SearchFilterOperator.FUZZY]?: BasicFilter + [SearchFilterOperator.STRING]?: BasicFilter + [SearchFilterOperator.FUZZY]?: BasicFilter [SearchFilterOperator.RANGE]?: RangeFilter [SearchFilterOperator.EQUAL]?: BasicFilter [SearchFilterOperator.NOT_EQUAL]?: BasicFilter From a7b6004c1c24b34563ebd98c58541e2225a4de03 Mon Sep 17 00:00:00 2001 From: Adria Navarro Date: Tue, 9 Jul 2024 15:09:54 +0200 Subject: [PATCH 12/14] Fix more typings --- packages/types/src/sdk/search.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/types/src/sdk/search.ts b/packages/types/src/sdk/search.ts index 713b33ff54..ccb73a7fba 100644 --- a/packages/types/src/sdk/search.ts +++ b/packages/types/src/sdk/search.ts @@ -25,7 +25,7 @@ type BasicFilter = Record & { [InternalSearchFilterOperator.COMPLEX_ID_OPERATOR]?: never } -type ArrayFilter = Record & { +type ArrayFilter = Record & { [InternalSearchFilterOperator.COMPLEX_ID_OPERATOR]?: { id: string[] values: string[] From eae559d24959f57261abdcb60064a7f2ace2c372 Mon Sep 17 00:00:00 2001 From: Adria Navarro Date: Tue, 9 Jul 2024 15:14:37 +0200 Subject: [PATCH 13/14] Fix scim sync issues --- packages/pro | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/pro b/packages/pro index 11379517b7..7dbe323aec 160000 --- a/packages/pro +++ b/packages/pro @@ -1 +1 @@ -Subproject commit 11379517b76264a7f938c2d520bd259f586edada +Subproject commit 7dbe323aec724ae6336b13c06aaefa4a89837edf From 49fc362c340f2cba54536e3da9e2c8181e0b1ec2 Mon Sep 17 00:00:00 2001 From: Budibase Staging Release Bot <> Date: Tue, 9 Jul 2024 14:51:23 +0000 Subject: [PATCH 14/14] Bump version to 2.29.15 --- lerna.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lerna.json b/lerna.json index b3831d0886..4d2b5a6cf8 100644 --- a/lerna.json +++ b/lerna.json @@ -1,6 +1,6 @@ { "$schema": "node_modules/lerna/schemas/lerna-schema.json", - "version": "2.29.14", + "version": "2.29.15", "npmClient": "yarn", "packages": [ "packages/*",