diff --git a/packages/server/src/api/routes/tests/search.spec.ts b/packages/server/src/api/routes/tests/search.spec.ts index 037d8b3fe8..d6c149bf3f 100644 --- a/packages/server/src/api/routes/tests/search.spec.ts +++ b/packages/server/src/api/routes/tests/search.spec.ts @@ -34,7 +34,7 @@ import { Table, TableSchema, User, - ViewFieldMetadata, + ViewV2Schema, } from "@budibase/types" import _ from "lodash" import tk from "timekeeper" @@ -139,6 +139,15 @@ describe.each([ return table._id! } + async function createView(tableId: string, schema: ViewV2Schema) { + const view = await config.api.viewV2.create({ + tableId: tableId, + name: generator.guid(), + schema, + }) + return view + } + async function createRows(arr: Record[]) { // Shuffling to avoid false positives given a fixed order for (const row of _.shuffle(arr)) { @@ -153,21 +162,17 @@ describe.each([ "view", async (schema: TableSchema) => { const tableId = await createTable(schema) - const view = await config.api.viewV2.create({ - tableId: tableId, - name: generator.guid(), - schema: Object.keys(schema).reduce>( - (viewSchema, fieldName) => { - const field = schema[fieldName] - viewSchema[fieldName] = { - visible: field.visible ?? true, - readonly: false, - } - return viewSchema - }, - {} - ), - }) + const view = await createView( + tableId, + Object.keys(schema).reduce((viewSchema, fieldName) => { + const field = schema[fieldName] + viewSchema[fieldName] = { + visible: field.visible ?? true, + readonly: false, + } + return viewSchema + }, {}) + ) return view.id }, ], diff --git a/packages/server/src/api/routes/tests/viewV2.spec.ts b/packages/server/src/api/routes/tests/viewV2.spec.ts index 1d6c1d50cd..f63d8aeb85 100644 --- a/packages/server/src/api/routes/tests/viewV2.spec.ts +++ b/packages/server/src/api/routes/tests/viewV2.spec.ts @@ -22,9 +22,9 @@ import { RelationshipType, TableSchema, RenameColumn, - ViewFieldMetadata, FeatureFlag, BBReferenceFieldSubType, + ViewV2Schema, } from "@budibase/types" import { generator, mocks } from "@budibase/backend-core/tests" import { DatabaseName, getDatasource } from "../../../integrations/tests/utils" @@ -1152,10 +1152,7 @@ describe.each([ return table } - const createView = async ( - tableId: string, - schema: Record - ) => + const createView = async (tableId: string, schema: ViewV2Schema) => await config.api.viewV2.create({ name: generator.guid(), tableId, diff --git a/packages/server/src/db/linkedRows/index.ts b/packages/server/src/db/linkedRows/index.ts index 45f5ee6e5a..f359bcc2cf 100644 --- a/packages/server/src/db/linkedRows/index.ts +++ b/packages/server/src/db/linkedRows/index.ts @@ -23,8 +23,8 @@ import { Row, Table, TableSchema, - ViewFieldMetadata, ViewV2, + ViewV2Schema, } from "@budibase/types" import sdk from "../../sdk" import { helpers } from "@budibase/shared-core" @@ -262,7 +262,7 @@ export async function squashLinks( FeatureFlag.ENRICHED_RELATIONSHIPS ) - let viewSchema: Record = {} + let viewSchema: ViewV2Schema = {} if (sdk.views.isView(source)) { if (helpers.views.isCalculationView(source)) { return enriched diff --git a/packages/types/src/documents/app/view.ts b/packages/types/src/documents/app/view.ts index a957564039..271df45c65 100644 --- a/packages/types/src/documents/app/view.ts +++ b/packages/types/src/documents/app/view.ts @@ -71,9 +71,11 @@ export interface ViewV2 { order?: SortOrder type?: SortType } - schema?: Record + schema?: ViewV2Schema } +export type ViewV2Schema = Record + export type ViewSchema = ViewCountOrSumSchema | ViewStatisticsSchema export interface ViewCountOrSumSchema {