diff --git a/packages/server/src/threads/automation.ts b/packages/server/src/threads/automation.ts index 2071115472..0e87b39f6a 100644 --- a/packages/server/src/threads/automation.ts +++ b/packages/server/src/threads/automation.ts @@ -8,7 +8,7 @@ import { import * as actions from "../automations/actions" import * as automationUtils from "../automations/automationUtils" import { replaceFakeBindings } from "../automations/loopUtils" -import { dataFilters, helpers } from "@budibase/shared-core" +import { dataFilters, helpers, utils } from "@budibase/shared-core" import { default as AutomationEmitter } from "../events/AutomationEmitter" import { generateAutomationMetadataID, isProdAppID } from "../db/utils" import { definitions as triggerDefs } from "../automations/triggerInfo" @@ -28,6 +28,7 @@ import { isLogicalSearchOperator, LoopStep, UserBindings, + isBasicSearchOperator, } from "@budibase/types" import { AutomationContext, TriggerOutput } from "../definitions/automations" import { WorkerCallback } from "./definitions" @@ -566,7 +567,7 @@ class Orchestrator { filters[filterKey].conditions = filters[filterKey].conditions.map( condition => recurseSearchFilters(condition) ) - } else { + } else if (isBasicSearchOperator(filterKey)) { for (const [field, value] of Object.entries(filters[filterKey])) { const fromContext = processStringSync( field, @@ -583,6 +584,9 @@ class Orchestrator { filters[filterKey][field] = processedVal } } + } else { + // We want to types to complain if we extend BranchSearchFilters, but not to throw if the request comes with some extra data. It will just be ignored + utils.unreachable(filterKey, { doNotThrow: true }) } } diff --git a/packages/shared-core/src/utils.ts b/packages/shared-core/src/utils.ts index 0e49db9c7c..e2c40a8849 100644 --- a/packages/shared-core/src/utils.ts +++ b/packages/shared-core/src/utils.ts @@ -26,9 +26,16 @@ const FILTER_ALLOWED_KEYS: (keyof SearchFilter)[] = [ export function unreachable( value: never, - message = `No such case in exhaustive switch: ${value}` + opts?: { + message?: string + doNotThrow?: boolean + } ) { - throw new Error(message) + const message = opts?.message || `No such case in exhaustive switch: ${value}` + const doNotThrow = !!opts?.doNotThrow + if (!doNotThrow) { + throw new Error(message) + } } export async function parallelForeach(