From 9c6347f7fd6345bce83bd924dc7df354f1fec9e9 Mon Sep 17 00:00:00 2001 From: Adria Navarro Date: Tue, 9 Jul 2024 12:24:59 +0200 Subject: [PATCH] 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