diff --git a/hosting/couchdb/sqs/arm/sqs b/hosting/couchdb/sqs/arm/sqs index d251ce0e06..2bc31d5b93 100755 Binary files a/hosting/couchdb/sqs/arm/sqs and b/hosting/couchdb/sqs/arm/sqs differ diff --git a/hosting/couchdb/sqs/x86/sqs b/hosting/couchdb/sqs/x86/sqs index fb971be232..bb6323d316 100755 Binary files a/hosting/couchdb/sqs/x86/sqs and b/hosting/couchdb/sqs/x86/sqs differ diff --git a/lerna.json b/lerna.json index 0292b863e8..4a7cfc95cc 100644 --- a/lerna.json +++ b/lerna.json @@ -1,6 +1,6 @@ { "$schema": "node_modules/lerna/schemas/lerna-schema.json", - "version": "2.31.8", + "version": "2.32.0", "npmClient": "yarn", "packages": [ "packages/*", diff --git a/packages/account-portal b/packages/account-portal index 048c37ecd9..7899d07904 160000 --- a/packages/account-portal +++ b/packages/account-portal @@ -1 +1 @@ -Subproject commit 048c37ecd921340614bf61a76a774aaa46176569 +Subproject commit 7899d07904d89d48954dd500da7b5dec32b781dd diff --git a/packages/backend-core/src/events/index.ts b/packages/backend-core/src/events/index.ts index a238d72bac..ac5367b8d9 100644 --- a/packages/backend-core/src/events/index.ts +++ b/packages/backend-core/src/events/index.ts @@ -3,6 +3,7 @@ export * as processors from "./processors" export * as analytics from "./analytics" export { default as identification } from "./identification" export * as backfillCache from "./backfill" +export { publishEvent } from "./events" import { processors } from "./processors" diff --git a/packages/builder/src/pages/builder/portal/settings/ai/AISettings.spec.js b/packages/builder/src/pages/builder/portal/settings/ai/AISettings.spec.js index 805739957b..fafead1ebf 100644 --- a/packages/builder/src/pages/builder/portal/settings/ai/AISettings.spec.js +++ b/packages/builder/src/pages/builder/portal/settings/ai/AISettings.spec.js @@ -2,6 +2,7 @@ import { it, expect, describe, vi } from "vitest" import AISettings from "./index.svelte" import { render } from "@testing-library/svelte" import { admin, licensing } from "stores/portal" +import { notifications } from "@budibase/bbui" vi.spyOn(notifications, "error").mockImplementation(vi.fn) vi.spyOn(notifications, "success").mockImplementation(vi.fn) diff --git a/packages/server/src/api/routes/tests/search.spec.ts b/packages/server/src/api/routes/tests/search.spec.ts index 26bb1582dd..c9e7f4c3c5 100644 --- a/packages/server/src/api/routes/tests/search.spec.ts +++ b/packages/server/src/api/routes/tests/search.spec.ts @@ -2907,6 +2907,28 @@ describe.each([ 'Invalid body - "query.$and.conditions[1].$and.conditions" is required' ) }) + + it("returns no rows when onEmptyFilter set to none", async () => { + await expectSearch({ + query: { + onEmptyFilter: EmptyFilterOption.RETURN_NONE, + $and: { + conditions: [{ equal: { name: "" } }], + }, + }, + }).toFindNothing() + }) + + it("returns all rows when onEmptyFilter set to all", async () => { + await expectSearch({ + query: { + onEmptyFilter: EmptyFilterOption.RETURN_ALL, + $and: { + conditions: [{ equal: { name: "" } }], + }, + }, + }).toHaveLength(4) + }) }) !isLucene && @@ -3035,5 +3057,27 @@ describe.each([ }, }).toContainExactly([{ age: 1, name: "Jane" }]) }) + + it("returns no rows when onEmptyFilter set to none", async () => { + await expectSearch({ + query: { + onEmptyFilter: EmptyFilterOption.RETURN_NONE, + $or: { + conditions: [{ equal: { name: "" } }], + }, + }, + }).toFindNothing() + }) + + it("returns all rows when onEmptyFilter set to all", async () => { + await expectSearch({ + query: { + onEmptyFilter: EmptyFilterOption.RETURN_ALL, + $or: { + conditions: [{ equal: { name: "" } }], + }, + }, + }).toHaveLength(4) + }) }) }) diff --git a/packages/shared-core/src/filters.ts b/packages/shared-core/src/filters.ts index 4c263c48bd..45e9a7c6d0 100644 --- a/packages/shared-core/src/filters.ts +++ b/packages/shared-core/src/filters.ts @@ -27,6 +27,12 @@ import { isPlainObject, isEmpty } from "lodash" import { decodeNonAscii } from "./helpers/schema" const HBS_REGEX = /{{([^{].*?)}}/g +const LOGICAL_OPERATORS = Object.values(LogicalOperator) +const SEARCH_OPERATORS = [ + ...Object.values(BasicOperator), + ...Object.values(ArrayOperator), + ...Object.values(RangeOperator), +] /** * Returns the valid operator options for a certain data type @@ -117,7 +123,7 @@ export function recurseLogicalOperators( filters: SearchFilters, fn: (f: SearchFilters) => SearchFilters ) { - for (const logical of Object.values(LogicalOperator)) { + for (const logical of LOGICAL_OPERATORS) { if (filters[logical]) { filters[logical]!.conditions = filters[logical]!.conditions.map( condition => fn(condition) @@ -135,7 +141,7 @@ export function recurseSearchFilters( filters = processFn(filters) // Recurse through logical operators - for (const logical of Object.values(LogicalOperator)) { + for (const logical of LOGICAL_OPERATORS) { if (filters[logical]) { filters[logical]!.conditions = filters[logical]!.conditions.map( condition => recurseSearchFilters(condition, processFn) @@ -773,12 +779,16 @@ export function runQuery>( return filterFunctions[key as SearchFilterOperator]?.(doc) ?? false }) - if (query.allOr) { + // there are no filters - logical operators can cover this up + if (!hasFilters(query)) { + return true + } else if (query.allOr) { return results.some(result => result === true) } else { return results.every(result => result === true) } } + return docs.filter(docMatch) } @@ -841,14 +851,33 @@ export const hasFilters = (query?: SearchFilters) => { if (!query) { return false } - const skipped = ["allOr", "onEmptyFilter"] - for (let [key, value] of Object.entries(query)) { - if (skipped.includes(key) || typeof value !== "object") { - continue + const check = (filters: SearchFilters): boolean => { + for (const logical of LOGICAL_OPERATORS) { + if (filters[logical]) { + for (const condition of filters[logical]?.conditions || []) { + const result = check(condition) + if (result) { + return result + } + } + } } - if (Object.keys(value || {}).length !== 0) { - return true + for (const search of SEARCH_OPERATORS) { + const searchValue = filters[search] + if (!searchValue || typeof searchValue !== "object") { + continue + } + const filtered = Object.entries(searchValue).filter(entry => { + const valueDefined = + entry[1] !== undefined || entry[1] !== null || entry[1] !== "" + // not empty is an edge case, null is allowed for it - this is covered by test cases + return search === BasicOperator.NOT_EMPTY || valueDefined + }) + if (filtered.length !== 0) { + return true + } } + return false } - return false + return check(query) }