From 3a095c507139c0470ad031818bda8e4c0c5de01a Mon Sep 17 00:00:00 2001 From: Adria Navarro Date: Fri, 26 Jul 2024 14:35:36 +0200 Subject: [PATCH 1/3] Renames --- packages/backend-core/tests/core/utilities/jestUtils.ts | 4 ++-- .../backend/DataTable/modals/CreateEditColumn.svelte | 4 ++-- packages/server/src/sdk/app/rows/search/internal.ts | 4 ++-- packages/server/src/sdk/app/views/index.ts | 4 ++-- packages/shared-core/src/constants/rows.ts | 4 ++-- packages/shared-core/src/table.ts | 4 ++-- 6 files changed, 12 insertions(+), 12 deletions(-) diff --git a/packages/backend-core/tests/core/utilities/jestUtils.ts b/packages/backend-core/tests/core/utilities/jestUtils.ts index a49c2a795e..7d2cfb41fa 100644 --- a/packages/backend-core/tests/core/utilities/jestUtils.ts +++ b/packages/backend-core/tests/core/utilities/jestUtils.ts @@ -1,6 +1,6 @@ import { CONSTANT_EXTERNAL_ROW_COLS, - CONSTANT_INTERNAL_ROW_COLS, + PROTECTED_INTERNAL_COLUMNS, } from "@budibase/shared-core" export function expectFunctionWasCalledTimesWith( @@ -14,7 +14,7 @@ export function expectFunctionWasCalledTimesWith( } export const expectAnyInternalColsAttributes: { - [K in (typeof CONSTANT_INTERNAL_ROW_COLS)[number]]: any + [K in (typeof PROTECTED_INTERNAL_COLUMNS)[number]]: any } = { tableId: expect.anything(), type: expect.anything(), diff --git a/packages/builder/src/components/backend/DataTable/modals/CreateEditColumn.svelte b/packages/builder/src/components/backend/DataTable/modals/CreateEditColumn.svelte index f982ef5333..6f96e77ca4 100644 --- a/packages/builder/src/components/backend/DataTable/modals/CreateEditColumn.svelte +++ b/packages/builder/src/components/backend/DataTable/modals/CreateEditColumn.svelte @@ -17,7 +17,7 @@ SWITCHABLE_TYPES, ValidColumnNameRegex, helpers, - CONSTANT_INTERNAL_ROW_COLS, + PROTECTED_INTERNAL_COLUMNS, CONSTANT_EXTERNAL_ROW_COLS, } from "@budibase/shared-core" import { createEventDispatcher, getContext, onMount } from "svelte" @@ -490,7 +490,7 @@ const newError = {} const prohibited = externalTable ? CONSTANT_EXTERNAL_ROW_COLS - : CONSTANT_INTERNAL_ROW_COLS + : PROTECTED_INTERNAL_COLUMNS if (!externalTable && fieldInfo.name?.startsWith("_")) { newError.name = `Column name cannot start with an underscore.` } else if (fieldInfo.name && !fieldInfo.name.match(ValidColumnNameRegex)) { diff --git a/packages/server/src/sdk/app/rows/search/internal.ts b/packages/server/src/sdk/app/rows/search/internal.ts index 097b16b104..46d2cd8c61 100644 --- a/packages/server/src/sdk/app/rows/search/internal.ts +++ b/packages/server/src/sdk/app/rows/search/internal.ts @@ -1,5 +1,5 @@ import { context, HTTPError } from "@budibase/backend-core" -import { CONSTANT_INTERNAL_ROW_COLS } from "@budibase/shared-core" +import { PROTECTED_INTERNAL_COLUMNS } from "@budibase/shared-core" import env from "../../../../environment" import { fullSearch, paginatedSearch } from "./utils" import { getRowParams, InternalTables } from "../../../../db/utils" @@ -75,7 +75,7 @@ export async function search( } if (options.fields) { - const fields = [...options.fields, ...CONSTANT_INTERNAL_ROW_COLS] + const fields = [...options.fields, ...PROTECTED_INTERNAL_COLUMNS] response.rows = response.rows.map((r: any) => pick(r, fields)) } diff --git a/packages/server/src/sdk/app/views/index.ts b/packages/server/src/sdk/app/views/index.ts index 3bdfec7448..2547788c64 100644 --- a/packages/server/src/sdk/app/views/index.ts +++ b/packages/server/src/sdk/app/views/index.ts @@ -11,7 +11,7 @@ import { features } from "@budibase/pro" import { helpers, CONSTANT_EXTERNAL_ROW_COLS, - CONSTANT_INTERNAL_ROW_COLS, + PROTECTED_INTERNAL_COLUMNS, } from "@budibase/shared-core" import { cloneDeep } from "lodash/fp" @@ -149,7 +149,7 @@ export function allowedFields(view: View | ViewV2) { return fieldSchema.visible && !fieldSchema.readonly }), ...CONSTANT_EXTERNAL_ROW_COLS, - ...CONSTANT_INTERNAL_ROW_COLS, + ...PROTECTED_INTERNAL_COLUMNS, ] } diff --git a/packages/shared-core/src/constants/rows.ts b/packages/shared-core/src/constants/rows.ts index bfa7595d62..47e05baae7 100644 --- a/packages/shared-core/src/constants/rows.ts +++ b/packages/shared-core/src/constants/rows.ts @@ -1,4 +1,4 @@ -export const CONSTANT_INTERNAL_ROW_COLS = [ +export const PROTECTED_INTERNAL_COLUMNS = [ "_id", "_rev", "type", @@ -10,5 +10,5 @@ export const CONSTANT_INTERNAL_ROW_COLS = [ export const CONSTANT_EXTERNAL_ROW_COLS = ["_id", "_rev", "tableId"] as const export function isInternalColumnName(name: string): boolean { - return (CONSTANT_INTERNAL_ROW_COLS as readonly string[]).includes(name) + return (PROTECTED_INTERNAL_COLUMNS as readonly string[]).includes(name) } diff --git a/packages/shared-core/src/table.ts b/packages/shared-core/src/table.ts index 8fd7909b18..615523f3eb 100644 --- a/packages/shared-core/src/table.ts +++ b/packages/shared-core/src/table.ts @@ -1,5 +1,5 @@ import { FieldType, Table } from "@budibase/types" -import { CONSTANT_INTERNAL_ROW_COLS } from "./constants" +import { PROTECTED_INTERNAL_COLUMNS } from "./constants" const allowDisplayColumnByType: Record = { [FieldType.STRING]: true, @@ -69,7 +69,7 @@ export function findDuplicateInternalColumns(table: Table): string[] { } } } - for (let internalColumn of CONSTANT_INTERNAL_ROW_COLS) { + for (let internalColumn of PROTECTED_INTERNAL_COLUMNS) { if (casedKeys.find(key => key === internalColumn)) { duplicates.push(internalColumn) } From ee74a84339bfc6cc61c6f8b4fe30c4c9c7c4a87e Mon Sep 17 00:00:00 2001 From: Adria Navarro Date: Fri, 26 Jul 2024 14:36:41 +0200 Subject: [PATCH 2/3] Remove duplicates --- .../server/src/api/controllers/row/utils/basic.ts | 5 ++--- packages/server/src/db/utils.ts | 8 -------- packages/server/src/sdk/app/rows/search/sqs.ts | 11 ++++------- packages/server/src/sdk/app/tables/internal/sqs.ts | 8 +++----- 4 files changed, 9 insertions(+), 23 deletions(-) diff --git a/packages/server/src/api/controllers/row/utils/basic.ts b/packages/server/src/api/controllers/row/utils/basic.ts index bca2494ac3..883ba5a806 100644 --- a/packages/server/src/api/controllers/row/utils/basic.ts +++ b/packages/server/src/api/controllers/row/utils/basic.ts @@ -1,8 +1,7 @@ // need to handle table name + field or just field, depending on if relationships used import { FieldType, Row, Table } from "@budibase/types" -import { helpers } from "@budibase/shared-core" +import { helpers, PROTECTED_INTERNAL_COLUMNS } from "@budibase/shared-core" import { generateRowIdField } from "../../../../integrations/utils" -import { CONSTANT_INTERNAL_ROW_COLS } from "../../../../db/utils" function extractFieldValue({ row, @@ -94,7 +93,7 @@ export function basicProcessing({ thisRow._rev = "rev" } else { const columns = Object.keys(table.schema) - for (let internalColumn of [...CONSTANT_INTERNAL_ROW_COLS, ...columns]) { + for (let internalColumn of [...PROTECTED_INTERNAL_COLUMNS, ...columns]) { thisRow[internalColumn] = extractFieldValue({ row, tableName: table._id!, diff --git a/packages/server/src/db/utils.ts b/packages/server/src/db/utils.ts index e3fe945863..043394e7a6 100644 --- a/packages/server/src/db/utils.ts +++ b/packages/server/src/db/utils.ts @@ -57,14 +57,6 @@ export const getUserMetadataParams = dbCore.getUserMetadataParams export const generateUserMetadataID = dbCore.generateUserMetadataID export const getGlobalIDFromUserMetadataID = dbCore.getGlobalIDFromUserMetadataID -export const CONSTANT_INTERNAL_ROW_COLS = [ - "_id", - "_rev", - "type", - "createdAt", - "updatedAt", - "tableId", -] /** * Gets parameters for retrieving tables, this is a utility function for the getDocParams function. diff --git a/packages/server/src/sdk/app/rows/search/sqs.ts b/packages/server/src/sdk/app/rows/search/sqs.ts index 44fd718871..c3da565c87 100644 --- a/packages/server/src/sdk/app/rows/search/sqs.ts +++ b/packages/server/src/sdk/app/rows/search/sqs.ts @@ -31,10 +31,7 @@ import { SQLITE_DESIGN_DOC_ID, SQS_DATASOURCE_INTERNAL, } from "@budibase/backend-core" -import { - CONSTANT_INTERNAL_ROW_COLS, - generateJunctionTableID, -} from "../../../../db/utils" +import { generateJunctionTableID } from "../../../../db/utils" import AliasTables from "../sqlAlias" import { outputProcessing } from "../../../../utilities/rowProcessor" import pick from "lodash/pick" @@ -44,7 +41,7 @@ import { getRelationshipColumns, getTableIDList, } from "./filters" -import { dataFilters } from "@budibase/shared-core" +import { dataFilters, PROTECTED_INTERNAL_COLUMNS } from "@budibase/shared-core" const builder = new sql.Sql(SqlClient.SQL_LITE) const MISSING_COLUMN_REGEX = new RegExp(`no such column: .+`) @@ -65,7 +62,7 @@ function buildInternalFieldList( }) } fieldList = fieldList.concat( - CONSTANT_INTERNAL_ROW_COLS.map(col => `${table._id}.${col}`) + PROTECTED_INTERNAL_COLUMNS.map(col => `${table._id}.${col}`) ) for (let col of Object.values(table.schema)) { const isRelationship = col.type === FieldType.LINK @@ -355,7 +352,7 @@ export async function search( // check if we need to pick specific rows out if (options.fields) { - const fields = [...options.fields, ...CONSTANT_INTERNAL_ROW_COLS] + const fields = [...options.fields, ...PROTECTED_INTERNAL_COLUMNS] finalRows = finalRows.map((r: any) => pick(r, fields)) } diff --git a/packages/server/src/sdk/app/tables/internal/sqs.ts b/packages/server/src/sdk/app/tables/internal/sqs.ts index 3c14e2fc67..9866a778d1 100644 --- a/packages/server/src/sdk/app/tables/internal/sqs.ts +++ b/packages/server/src/sdk/app/tables/internal/sqs.ts @@ -10,12 +10,10 @@ import { Table, } from "@budibase/types" import tablesSdk from "../" -import { - CONSTANT_INTERNAL_ROW_COLS, - generateJunctionTableID, -} from "../../../../db/utils" +import { generateJunctionTableID } from "../../../../db/utils" import { isEqual } from "lodash" import { DEFAULT_TABLES } from "../../../../db/defaultData/datasource_bb_default" +import { PROTECTED_INTERNAL_COLUMNS } from "@budibase/shared-core" const FieldTypeMap: Record = { [FieldType.BOOLEAN]: SQLiteType.NUMERIC, @@ -122,7 +120,7 @@ function mapTable(table: Table): SQLiteTables { } // there are some extra columns to map - add these in const constantMap: Record = {} - CONSTANT_INTERNAL_ROW_COLS.forEach(col => { + PROTECTED_INTERNAL_COLUMNS.forEach(col => { constantMap[col] = SQLiteType.TEXT }) const thisTable: SQLiteTable = { From f9bfe51c81a878a2dbbd67823dec1e3b36a88fa5 Mon Sep 17 00:00:00 2001 From: Adria Navarro Date: Fri, 26 Jul 2024 14:37:47 +0200 Subject: [PATCH 3/3] Rename external --- packages/backend-core/tests/core/utilities/jestUtils.ts | 4 ++-- .../backend/DataTable/modals/CreateEditColumn.svelte | 4 ++-- packages/server/src/sdk/app/rows/search/external.ts | 4 ++-- packages/server/src/sdk/app/views/index.ts | 4 ++-- packages/shared-core/src/constants/rows.ts | 2 +- 5 files changed, 9 insertions(+), 9 deletions(-) diff --git a/packages/backend-core/tests/core/utilities/jestUtils.ts b/packages/backend-core/tests/core/utilities/jestUtils.ts index 7d2cfb41fa..683a4e025b 100644 --- a/packages/backend-core/tests/core/utilities/jestUtils.ts +++ b/packages/backend-core/tests/core/utilities/jestUtils.ts @@ -1,5 +1,5 @@ import { - CONSTANT_EXTERNAL_ROW_COLS, + PROTECTED_EXTERNAL_COLUMNS, PROTECTED_INTERNAL_COLUMNS, } from "@budibase/shared-core" @@ -25,7 +25,7 @@ export const expectAnyInternalColsAttributes: { } export const expectAnyExternalColsAttributes: { - [K in (typeof CONSTANT_EXTERNAL_ROW_COLS)[number]]: any + [K in (typeof PROTECTED_EXTERNAL_COLUMNS)[number]]: any } = { tableId: expect.anything(), _id: expect.anything(), diff --git a/packages/builder/src/components/backend/DataTable/modals/CreateEditColumn.svelte b/packages/builder/src/components/backend/DataTable/modals/CreateEditColumn.svelte index 6f96e77ca4..a9ea90242a 100644 --- a/packages/builder/src/components/backend/DataTable/modals/CreateEditColumn.svelte +++ b/packages/builder/src/components/backend/DataTable/modals/CreateEditColumn.svelte @@ -18,7 +18,7 @@ ValidColumnNameRegex, helpers, PROTECTED_INTERNAL_COLUMNS, - CONSTANT_EXTERNAL_ROW_COLS, + PROTECTED_EXTERNAL_COLUMNS, } from "@budibase/shared-core" import { createEventDispatcher, getContext, onMount } from "svelte" import { cloneDeep } from "lodash/fp" @@ -489,7 +489,7 @@ } const newError = {} const prohibited = externalTable - ? CONSTANT_EXTERNAL_ROW_COLS + ? PROTECTED_EXTERNAL_COLUMNS : PROTECTED_INTERNAL_COLUMNS if (!externalTable && fieldInfo.name?.startsWith("_")) { newError.name = `Column name cannot start with an underscore.` diff --git a/packages/server/src/sdk/app/rows/search/external.ts b/packages/server/src/sdk/app/rows/search/external.ts index cd0650e4c4..c7a89bc0dd 100644 --- a/packages/server/src/sdk/app/rows/search/external.ts +++ b/packages/server/src/sdk/app/rows/search/external.ts @@ -16,7 +16,7 @@ import { breakExternalTableId, breakRowIdField, } from "../../../../integrations/utils" -import { utils, CONSTANT_EXTERNAL_ROW_COLS } from "@budibase/shared-core" +import { utils, PROTECTED_EXTERNAL_COLUMNS } from "@budibase/shared-core" import { ExportRowsParams, ExportRowsResult } from "./types" import { HTTPError } from "@budibase/backend-core" import pick from "lodash/pick" @@ -99,7 +99,7 @@ export async function search( } if (options.fields) { - const fields = [...options.fields, ...CONSTANT_EXTERNAL_ROW_COLS] + const fields = [...options.fields, ...PROTECTED_EXTERNAL_COLUMNS] rows = rows.map((r: any) => pick(r, fields)) } diff --git a/packages/server/src/sdk/app/views/index.ts b/packages/server/src/sdk/app/views/index.ts index 2547788c64..1c09f710d7 100644 --- a/packages/server/src/sdk/app/views/index.ts +++ b/packages/server/src/sdk/app/views/index.ts @@ -10,7 +10,7 @@ import { HTTPError } from "@budibase/backend-core" import { features } from "@budibase/pro" import { helpers, - CONSTANT_EXTERNAL_ROW_COLS, + PROTECTED_EXTERNAL_COLUMNS, PROTECTED_INTERNAL_COLUMNS, } from "@budibase/shared-core" import { cloneDeep } from "lodash/fp" @@ -148,7 +148,7 @@ export function allowedFields(view: View | ViewV2) { const fieldSchema = view.schema![key] return fieldSchema.visible && !fieldSchema.readonly }), - ...CONSTANT_EXTERNAL_ROW_COLS, + ...PROTECTED_EXTERNAL_COLUMNS, ...PROTECTED_INTERNAL_COLUMNS, ] } diff --git a/packages/shared-core/src/constants/rows.ts b/packages/shared-core/src/constants/rows.ts index 47e05baae7..03663a4014 100644 --- a/packages/shared-core/src/constants/rows.ts +++ b/packages/shared-core/src/constants/rows.ts @@ -7,7 +7,7 @@ export const PROTECTED_INTERNAL_COLUMNS = [ "tableId", ] as const -export const CONSTANT_EXTERNAL_ROW_COLS = ["_id", "_rev", "tableId"] as const +export const PROTECTED_EXTERNAL_COLUMNS = ["_id", "_rev", "tableId"] as const export function isInternalColumnName(name: string): boolean { return (PROTECTED_INTERNAL_COLUMNS as readonly string[]).includes(name)