From d4f9822c748244152434608f236a41157e513837 Mon Sep 17 00:00:00 2001 From: Sam Rose Date: Fri, 15 Mar 2024 17:03:47 +0000 Subject: [PATCH 01/24] Move viewV2 tests out of row.spec.ts and into viewV2.spec.ts. --- .../server/src/api/routes/tests/row.spec.ts | 653 +----------------- .../src/api/routes/tests/viewV2.spec.ts | 491 ++++++++++++- 2 files changed, 507 insertions(+), 637 deletions(-) diff --git a/packages/server/src/api/routes/tests/row.spec.ts b/packages/server/src/api/routes/tests/row.spec.ts index 854410dcf6..64a156b15a 100644 --- a/packages/server/src/api/routes/tests/row.spec.ts +++ b/packages/server/src/api/routes/tests/row.spec.ts @@ -392,6 +392,23 @@ describe.each([ expect(row.arrayFieldArrayStrKnown).toEqual(["One"]) expect(row.optsFieldStrKnown).toEqual("Alpha") }) + + isInternal && + it("doesn't allow creating in user table", async () => { + const userTableId = InternalTable.USER_METADATA + const response = await config.api.row.save( + userTableId, + { + tableId: userTableId, + firstName: "Joe", + lastName: "Joe", + email: "joe@joe.com", + roles: {}, + }, + { status: 400 } + ) + expect(response.message).toBe("Cannot create new user entry.") + }) }) describe("get", () => { @@ -890,642 +907,6 @@ describe.each([ }) }) - describe("view 2.0", () => { - async function userTable(): Promise { - return saveTableRequest({ - name: `users_${uuid.v4()}`, - type: "table", - schema: { - name: { - type: FieldType.STRING, - name: "name", - }, - surname: { - type: FieldType.STRING, - name: "surname", - }, - age: { - type: FieldType.NUMBER, - name: "age", - }, - address: { - type: FieldType.STRING, - name: "address", - }, - jobTitle: { - type: FieldType.STRING, - name: "jobTitle", - }, - }, - }) - } - - const randomRowData = () => ({ - name: generator.first(), - surname: generator.last(), - age: generator.age(), - address: generator.address(), - jobTitle: generator.word(), - }) - - describe("create", () => { - it("should persist a new row with only the provided view fields", async () => { - const table = await config.api.table.save(await userTable()) - const view = await config.api.viewV2.create({ - tableId: table._id!, - name: generator.guid(), - schema: { - name: { visible: true }, - surname: { visible: true }, - address: { visible: true }, - }, - }) - - const data = randomRowData() - const newRow = await config.api.row.save(view.id, { - tableId: table!._id, - _viewId: view.id, - ...data, - }) - - const row = await config.api.row.get(table._id!, newRow._id!) - expect(row).toEqual({ - name: data.name, - surname: data.surname, - address: data.address, - tableId: table!._id, - _id: newRow._id, - _rev: newRow._rev, - id: newRow.id, - ...defaultRowFields, - }) - expect(row._viewId).toBeUndefined() - expect(row.age).toBeUndefined() - expect(row.jobTitle).toBeUndefined() - }) - }) - - describe("patch", () => { - it("should update only the view fields for a row", async () => { - const table = await config.api.table.save(await userTable()) - const tableId = table._id! - const view = await config.api.viewV2.create({ - tableId: tableId, - name: generator.guid(), - schema: { - name: { visible: true }, - address: { visible: true }, - }, - }) - - const newRow = await config.api.row.save(view.id, { - tableId, - _viewId: view.id, - ...randomRowData(), - }) - const newData = randomRowData() - await config.api.row.patch(view.id, { - tableId, - _viewId: view.id, - _id: newRow._id!, - _rev: newRow._rev!, - ...newData, - }) - - const row = await config.api.row.get(tableId, newRow._id!) - expect(row).toEqual({ - ...newRow, - name: newData.name, - address: newData.address, - _id: newRow._id, - _rev: expect.any(String), - id: newRow.id, - ...defaultRowFields, - }) - expect(row._viewId).toBeUndefined() - expect(row.age).toBeUndefined() - expect(row.jobTitle).toBeUndefined() - }) - }) - - describe("destroy", () => { - it("should be able to delete a row", async () => { - const table = await config.api.table.save(await userTable()) - const tableId = table._id! - const view = await config.api.viewV2.create({ - tableId: tableId, - name: generator.guid(), - schema: { - name: { visible: true }, - address: { visible: true }, - }, - }) - - const createdRow = await config.api.row.save(table._id!, {}) - const rowUsage = await getRowUsage() - - await config.api.row.bulkDelete(view.id, { rows: [createdRow] }) - - await assertRowUsage(rowUsage - 1) - - await config.api.row.get(tableId, createdRow._id!, { - status: 404, - }) - }) - - it("should be able to delete multiple rows", async () => { - const table = await config.api.table.save(await userTable()) - const tableId = table._id! - const view = await config.api.viewV2.create({ - tableId: tableId, - name: generator.guid(), - schema: { - name: { visible: true }, - address: { visible: true }, - }, - }) - - const rows = await Promise.all([ - config.api.row.save(table._id!, {}), - config.api.row.save(table._id!, {}), - config.api.row.save(table._id!, {}), - ]) - const rowUsage = await getRowUsage() - - await config.api.row.bulkDelete(view.id, { rows: [rows[0], rows[2]] }) - - await assertRowUsage(rowUsage - 2) - - await config.api.row.get(tableId, rows[0]._id!, { - status: 404, - }) - await config.api.row.get(tableId, rows[2]._id!, { - status: 404, - }) - await config.api.row.get(tableId, rows[1]._id!, { status: 200 }) - }) - }) - - describe("view search", () => { - let table: Table - const viewSchema = { age: { visible: true }, name: { visible: true } } - - beforeAll(async () => { - table = await config.api.table.save( - saveTableRequest({ - name: `users_${uuid.v4()}`, - schema: { - name: { - type: FieldType.STRING, - name: "name", - constraints: { type: "string" }, - }, - age: { - type: FieldType.NUMBER, - name: "age", - constraints: {}, - }, - }, - }) - ) - }) - - it("returns empty rows from view when no schema is passed", async () => { - const rows = await Promise.all( - Array.from({ length: 10 }, () => - config.api.row.save(table._id!, { tableId: table._id }) - ) - ) - - const createViewResponse = await config.api.viewV2.create({ - tableId: table._id!, - name: generator.guid(), - }) - const response = await config.api.viewV2.search(createViewResponse.id) - - expect(response.rows).toHaveLength(10) - expect(response).toEqual({ - rows: expect.arrayContaining( - rows.map(r => ({ - _viewId: createViewResponse.id, - tableId: table._id, - _id: r._id, - _rev: r._rev, - ...defaultRowFields, - })) - ), - ...(isInternal - ? {} - : { - hasNextPage: false, - bookmark: null, - }), - }) - }) - - it("searching respects the view filters", async () => { - await Promise.all( - Array.from({ length: 10 }, () => - config.api.row.save(table._id!, { - tableId: table._id, - name: generator.name(), - age: generator.integer({ min: 10, max: 30 }), - }) - ) - ) - - const expectedRows = await Promise.all( - Array.from({ length: 5 }, () => - config.api.row.save(table._id!, { - tableId: table._id, - name: generator.name(), - age: 40, - }) - ) - ) - - const createViewResponse = await config.api.viewV2.create({ - tableId: table._id!, - name: generator.guid(), - query: [ - { operator: SearchQueryOperators.EQUAL, field: "age", value: 40 }, - ], - schema: viewSchema, - }) - - const response = await config.api.viewV2.search(createViewResponse.id) - - expect(response.rows).toHaveLength(5) - expect(response).toEqual({ - rows: expect.arrayContaining( - expectedRows.map(r => ({ - _viewId: createViewResponse.id, - tableId: table._id, - name: r.name, - age: r.age, - _id: r._id, - _rev: r._rev, - ...defaultRowFields, - })) - ), - ...(isInternal - ? {} - : { - hasNextPage: false, - bookmark: null, - }), - }) - }) - - const sortTestOptions: [ - { - field: string - order?: SortOrder - type?: SortType - }, - string[] - ][] = [ - [ - { - field: "name", - order: SortOrder.ASCENDING, - type: SortType.STRING, - }, - ["Alice", "Bob", "Charly", "Danny"], - ], - [ - { - field: "name", - }, - ["Alice", "Bob", "Charly", "Danny"], - ], - [ - { - field: "name", - order: SortOrder.DESCENDING, - }, - ["Danny", "Charly", "Bob", "Alice"], - ], - [ - { - field: "name", - order: SortOrder.DESCENDING, - type: SortType.STRING, - }, - ["Danny", "Charly", "Bob", "Alice"], - ], - [ - { - field: "age", - order: SortOrder.ASCENDING, - type: SortType.number, - }, - ["Danny", "Alice", "Charly", "Bob"], - ], - [ - { - field: "age", - order: SortOrder.ASCENDING, - }, - ["Danny", "Alice", "Charly", "Bob"], - ], - [ - { - field: "age", - order: SortOrder.DESCENDING, - }, - ["Bob", "Charly", "Alice", "Danny"], - ], - [ - { - field: "age", - order: SortOrder.DESCENDING, - type: SortType.number, - }, - ["Bob", "Charly", "Alice", "Danny"], - ], - ] - - describe("sorting", () => { - let table: Table - beforeAll(async () => { - table = await config.api.table.save(await userTable()) - const users = [ - { name: "Alice", age: 25 }, - { name: "Bob", age: 30 }, - { name: "Charly", age: 27 }, - { name: "Danny", age: 15 }, - ] - await Promise.all( - users.map(u => - config.api.row.save(table._id!, { - tableId: table._id, - ...u, - }) - ) - ) - }) - - it.each(sortTestOptions)( - "allow sorting (%s)", - async (sortParams, expected) => { - const createViewResponse = await config.api.viewV2.create({ - tableId: table._id!, - name: generator.guid(), - sort: sortParams, - schema: viewSchema, - }) - - const response = await config.api.viewV2.search( - createViewResponse.id - ) - - expect(response.rows).toHaveLength(4) - expect(response.rows).toEqual( - expected.map(name => expect.objectContaining({ name })) - ) - } - ) - - it.each(sortTestOptions)( - "allow override the default view sorting (%s)", - async (sortParams, expected) => { - const createViewResponse = await config.api.viewV2.create({ - tableId: table._id!, - name: generator.guid(), - sort: { - field: "name", - order: SortOrder.ASCENDING, - type: SortType.STRING, - }, - schema: viewSchema, - }) - - const response = await config.api.viewV2.search( - createViewResponse.id, - { - sort: sortParams.field, - sortOrder: sortParams.order, - sortType: sortParams.type, - query: {}, - } - ) - - expect(response.rows).toHaveLength(4) - expect(response.rows).toEqual( - expected.map(name => expect.objectContaining({ name })) - ) - } - ) - }) - - it("when schema is defined, defined columns and row attributes are returned", async () => { - const table = await config.api.table.save(await userTable()) - const rows = await Promise.all( - Array.from({ length: 10 }, () => - config.api.row.save(table._id!, { - tableId: table._id, - name: generator.name(), - age: generator.age(), - }) - ) - ) - - const view = await config.api.viewV2.create({ - tableId: table._id!, - name: generator.guid(), - schema: { name: { visible: true } }, - }) - const response = await config.api.viewV2.search(view.id) - - expect(response.rows).toHaveLength(10) - expect(response.rows).toEqual( - expect.arrayContaining( - rows.map(r => ({ - ...(isInternal - ? expectAnyInternalColsAttributes - : expectAnyExternalColsAttributes), - _viewId: view.id, - name: r.name, - })) - ) - ) - }) - - it("views without data can be returned", async () => { - const table = await config.api.table.save(await userTable()) - const createViewResponse = await config.api.viewV2.create({ - tableId: table._id!, - name: generator.guid(), - }) - const response = await config.api.viewV2.search(createViewResponse.id) - expect(response.rows).toHaveLength(0) - }) - - it("respects the limit parameter", async () => { - const table = await config.api.table.save(await userTable()) - await Promise.all( - Array.from({ length: 10 }, () => config.api.row.save(table._id!, {})) - ) - - const limit = generator.integer({ min: 1, max: 8 }) - - const createViewResponse = await config.api.viewV2.create({ - tableId: table._id!, - name: generator.guid(), - }) - const response = await config.api.viewV2.search(createViewResponse.id, { - limit, - query: {}, - }) - - expect(response.rows).toHaveLength(limit) - }) - - it("can handle pagination", async () => { - const table = await config.api.table.save(await userTable()) - await Promise.all( - Array.from({ length: 10 }, () => config.api.row.save(table._id!, {})) - ) - const view = await config.api.viewV2.create({ - tableId: table._id!, - name: generator.guid(), - }) - const rows = (await config.api.viewV2.search(view.id)).rows - - const page1 = await config.api.viewV2.search(view.id, { - paginate: true, - limit: 4, - query: {}, - }) - expect(page1).toEqual({ - rows: expect.arrayContaining(rows.slice(0, 4)), - totalRows: isInternal ? 10 : undefined, - hasNextPage: true, - bookmark: expect.anything(), - }) - - const page2 = await config.api.viewV2.search(view.id, { - paginate: true, - limit: 4, - bookmark: page1.bookmark, - - query: {}, - }) - expect(page2).toEqual({ - rows: expect.arrayContaining(rows.slice(4, 8)), - totalRows: isInternal ? 10 : undefined, - hasNextPage: true, - bookmark: expect.anything(), - }) - - const page3 = await config.api.viewV2.search(view.id, { - paginate: true, - limit: 4, - bookmark: page2.bookmark, - query: {}, - }) - expect(page3).toEqual({ - rows: expect.arrayContaining(rows.slice(8)), - totalRows: isInternal ? 10 : undefined, - hasNextPage: false, - bookmark: expect.anything(), - }) - }) - - isInternal && - it("doesn't allow creating in user table", async () => { - const userTableId = InternalTable.USER_METADATA - const response = await config.api.row.save( - userTableId, - { - tableId: userTableId, - firstName: "Joe", - lastName: "Joe", - email: "joe@joe.com", - roles: {}, - }, - { status: 400 } - ) - expect(response.message).toBe("Cannot create new user entry.") - }) - - describe("permissions", () => { - let table: Table - let view: ViewV2 - - beforeAll(async () => { - table = await config.api.table.save(await userTable()) - await Promise.all( - Array.from({ length: 10 }, () => - config.api.row.save(table._id!, {}) - ) - ) - - view = await config.api.viewV2.create({ - tableId: table._id!, - name: generator.guid(), - }) - }) - - beforeEach(() => { - mocks.licenses.useViewPermissions() - }) - - it("does not allow public users to fetch by default", async () => { - await config.publish() - await config.api.viewV2.publicSearch(view.id, undefined, { - status: 403, - }) - }) - - it("allow public users to fetch when permissions are explicit", async () => { - await config.api.permission.add({ - roleId: roles.BUILTIN_ROLE_IDS.PUBLIC, - level: PermissionLevel.READ, - resourceId: view.id, - }) - await config.publish() - - const response = await config.api.viewV2.publicSearch(view.id) - - expect(response.rows).toHaveLength(10) - }) - - it("allow public users to fetch when permissions are inherited", async () => { - await config.api.permission.add({ - roleId: roles.BUILTIN_ROLE_IDS.PUBLIC, - level: PermissionLevel.READ, - resourceId: table._id!, - }) - await config.publish() - - const response = await config.api.viewV2.publicSearch(view.id) - - expect(response.rows).toHaveLength(10) - }) - - it("respects inherited permissions, not allowing not public views from public tables", async () => { - await config.api.permission.add({ - roleId: roles.BUILTIN_ROLE_IDS.PUBLIC, - level: PermissionLevel.READ, - resourceId: table._id!, - }) - await config.api.permission.add({ - roleId: roles.BUILTIN_ROLE_IDS.POWER, - level: PermissionLevel.READ, - resourceId: view.id, - }) - await config.publish() - - await config.api.viewV2.publicSearch(view.id, undefined, { - status: 403, - }) - }) - }) - }) - }) - let o2mTable: Table let m2mTable: Table beforeAll(async () => { diff --git a/packages/server/src/api/routes/tests/viewV2.spec.ts b/packages/server/src/api/routes/tests/viewV2.spec.ts index ded5e08d29..9c53ade52e 100644 --- a/packages/server/src/api/routes/tests/viewV2.spec.ts +++ b/packages/server/src/api/routes/tests/viewV2.spec.ts @@ -5,20 +5,25 @@ import { FieldSchema, FieldType, INTERNAL_TABLE_SOURCE_ID, + PermissionLevel, + QuotaUsageType, SaveTableRequest, SearchQueryOperators, SortOrder, SortType, + StaticQuotaName, Table, TableSourceType, UIFieldMetadata, UpdateViewRequest, ViewV2, } from "@budibase/types" -import { generator } from "@budibase/backend-core/tests" +import { generator, mocks } from "@budibase/backend-core/tests" import * as uuid from "uuid" import { databaseTestProviders } from "../../../integrations/tests/utils" import merge from "lodash/merge" +import { quotas } from "@budibase/pro" +import { roles } from "@budibase/backend-core" jest.unmock("mysql2") jest.unmock("mysql2/promise") @@ -33,6 +38,7 @@ describe.each([ ["mariadb", databaseTestProviders.mariadb], ])("/v2/views (%s)", (_, dsProvider) => { const config = setup.getConfig() + const isInternal = !dsProvider let table: Table let datasource: Datasource @@ -99,6 +105,18 @@ describe.each([ setup.afterAll() }) + const getRowUsage = async () => { + const { total } = await config.doInContext(undefined, () => + quotas.getCurrentUsageValues(QuotaUsageType.STATIC, StaticQuotaName.ROWS) + ) + return total + } + + const assertRowUsage = async (expected: number) => { + const usage = await getRowUsage() + expect(usage).toBe(expected) + } + describe("create", () => { it("persist the view when the view is successfully created", async () => { const newView: CreateViewRequest = { @@ -525,4 +543,475 @@ describe.each([ expect(row.Country).toEqual("Aussy") }) }) + + describe.only("row operations", () => { + let table: Table, view: ViewV2 + beforeEach(async () => { + table = await config.api.table.save( + saveTableRequest({ + schema: { + one: { type: FieldType.STRING, name: "one" }, + two: { type: FieldType.STRING, name: "two" }, + }, + }) + ) + view = await config.api.viewV2.create({ + tableId: table._id!, + name: generator.guid(), + schema: { + two: { visible: true }, + }, + }) + }) + + describe("create", () => { + it("should persist a new row with only the provided view fields", async () => { + const newRow = await config.api.row.save(view.id, { + tableId: table!._id, + _viewId: view.id, + one: "foo", + two: "bar", + }) + + const row = await config.api.row.get(table._id!, newRow._id!) + expect(row.one).toBeUndefined() + expect(row.two).toEqual("bar") + }) + }) + + describe("patch", () => { + it("should update only the view fields for a row", async () => { + const newRow = await config.api.row.save(table._id!, { + one: "foo", + two: "bar", + }) + await config.api.row.patch(view.id, { + tableId: table._id!, + _id: newRow._id!, + _rev: newRow._rev!, + one: "newFoo", + two: "newBar", + }) + + const row = await config.api.row.get(table._id!, newRow._id!) + expect(row.one).toEqual("foo") + expect(row.two).toEqual("newBar") + }) + }) + + describe("destroy", () => { + it("should be able to delete a row", async () => { + const createdRow = await config.api.row.save(table._id!, {}) + const rowUsage = await getRowUsage() + await config.api.row.bulkDelete(view.id, { rows: [createdRow] }) + await assertRowUsage(rowUsage - 1) + await config.api.row.get(table._id!, createdRow._id!, { + status: 404, + }) + }) + + it("should be able to delete multiple rows", async () => { + const rows = await Promise.all([ + config.api.row.save(table._id!, {}), + config.api.row.save(table._id!, {}), + config.api.row.save(table._id!, {}), + ]) + const rowUsage = await getRowUsage() + + await config.api.row.bulkDelete(view.id, { rows: [rows[0], rows[2]] }) + + await assertRowUsage(rowUsage - 2) + + await config.api.row.get(table._id!, rows[0]._id!, { + status: 404, + }) + await config.api.row.get(table._id!, rows[2]._id!, { + status: 404, + }) + await config.api.row.get(table._id!, rows[1]._id!, { status: 200 }) + }) + }) + + describe("search", () => { + it("returns empty rows from view when no schema is passed", async () => { + const rows = await Promise.all( + Array.from({ length: 10 }, () => config.api.row.save(table._id!, {})) + ) + const response = await config.api.viewV2.search(view.id) + expect(response.rows).toHaveLength(10) + expect(response).toEqual({ + rows: expect.arrayContaining( + rows.map(r => ({ + _viewId: view.id, + tableId: table._id, + _id: r._id, + _rev: r._rev, + ...(isInternal + ? { + type: "row", + updatedAt: expect.any(String), + createdAt: expect.any(String), + } + : {}), + })) + ), + ...(isInternal + ? {} + : { + hasNextPage: false, + bookmark: null, + }), + }) + }) + + it("searching respects the view filters", async () => { + await config.api.row.save(table._id!, { + one: "foo", + two: "bar", + }) + const two = await config.api.row.save(table._id!, { + one: "foo2", + two: "bar2", + }) + + const view = await config.api.viewV2.create({ + tableId: table._id!, + name: generator.guid(), + query: [ + { + operator: SearchQueryOperators.EQUAL, + field: "two", + value: "bar2", + }, + ], + schema: { + two: { visible: true }, + }, + }) + + const response = await config.api.viewV2.search(view.id) + expect(response.rows).toHaveLength(1) + expect(response).toEqual({ + rows: expect.arrayContaining([ + { + _viewId: view.id, + tableId: table._id, + two: two.two, + _id: two._id, + _rev: two._rev, + ...(isInternal + ? { + type: "row", + createdAt: expect.any(String), + updatedAt: expect.any(String), + } + : {}), + }, + ]), + ...(isInternal + ? {} + : { + hasNextPage: false, + bookmark: null, + }), + }) + }) + + it("views without data can be returned", async () => { + const response = await config.api.viewV2.search(view.id) + expect(response.rows).toHaveLength(0) + }) + + it("respects the limit parameter", async () => { + await Promise.all( + Array.from({ length: 10 }, () => config.api.row.save(table._id!, {})) + ) + const limit = generator.integer({ min: 1, max: 8 }) + const response = await config.api.viewV2.search(view.id, { + limit, + query: {}, + }) + expect(response.rows).toHaveLength(limit) + }) + + it("can handle pagination", async () => { + await Promise.all( + Array.from({ length: 10 }, () => config.api.row.save(table._id!, {})) + ) + const rows = (await config.api.viewV2.search(view.id)).rows + + const page1 = await config.api.viewV2.search(view.id, { + paginate: true, + limit: 4, + query: {}, + }) + expect(page1).toEqual({ + rows: expect.arrayContaining(rows.slice(0, 4)), + totalRows: isInternal ? 10 : undefined, + hasNextPage: true, + bookmark: expect.anything(), + }) + + const page2 = await config.api.viewV2.search(view.id, { + paginate: true, + limit: 4, + bookmark: page1.bookmark, + query: {}, + }) + expect(page2).toEqual({ + rows: expect.arrayContaining(rows.slice(4, 8)), + totalRows: isInternal ? 10 : undefined, + hasNextPage: true, + bookmark: expect.anything(), + }) + + const page3 = await config.api.viewV2.search(view.id, { + paginate: true, + limit: 4, + bookmark: page2.bookmark, + query: {}, + }) + expect(page3).toEqual({ + rows: expect.arrayContaining(rows.slice(8)), + totalRows: isInternal ? 10 : undefined, + hasNextPage: false, + bookmark: expect.anything(), + }) + }) + + const sortTestOptions: [ + { + field: string + order?: SortOrder + type?: SortType + }, + string[] + ][] = [ + [ + { + field: "name", + order: SortOrder.ASCENDING, + type: SortType.STRING, + }, + ["Alice", "Bob", "Charly", "Danny"], + ], + [ + { + field: "name", + }, + ["Alice", "Bob", "Charly", "Danny"], + ], + [ + { + field: "name", + order: SortOrder.DESCENDING, + }, + ["Danny", "Charly", "Bob", "Alice"], + ], + [ + { + field: "name", + order: SortOrder.DESCENDING, + type: SortType.STRING, + }, + ["Danny", "Charly", "Bob", "Alice"], + ], + [ + { + field: "age", + order: SortOrder.ASCENDING, + type: SortType.number, + }, + ["Danny", "Alice", "Charly", "Bob"], + ], + [ + { + field: "age", + order: SortOrder.ASCENDING, + }, + ["Danny", "Alice", "Charly", "Bob"], + ], + [ + { + field: "age", + order: SortOrder.DESCENDING, + }, + ["Bob", "Charly", "Alice", "Danny"], + ], + [ + { + field: "age", + order: SortOrder.DESCENDING, + type: SortType.number, + }, + ["Bob", "Charly", "Alice", "Danny"], + ], + ] + + describe("sorting", () => { + let table: Table + const viewSchema = { age: { visible: true }, name: { visible: true } } + + beforeAll(async () => { + table = await config.api.table.save( + saveTableRequest({ + name: `users_${uuid.v4()}`, + type: "table", + schema: { + name: { + type: FieldType.STRING, + name: "name", + }, + surname: { + type: FieldType.STRING, + name: "surname", + }, + age: { + type: FieldType.NUMBER, + name: "age", + }, + address: { + type: FieldType.STRING, + name: "address", + }, + jobTitle: { + type: FieldType.STRING, + name: "jobTitle", + }, + }, + }) + ) + + const users = [ + { name: "Alice", age: 25 }, + { name: "Bob", age: 30 }, + { name: "Charly", age: 27 }, + { name: "Danny", age: 15 }, + ] + await Promise.all( + users.map(u => + config.api.row.save(table._id!, { + tableId: table._id, + ...u, + }) + ) + ) + }) + + it.each(sortTestOptions)( + "allow sorting (%s)", + async (sortParams, expected) => { + const view = await config.api.viewV2.create({ + tableId: table._id!, + name: generator.guid(), + sort: sortParams, + schema: viewSchema, + }) + + const response = await config.api.viewV2.search(view.id) + + expect(response.rows).toHaveLength(4) + expect(response.rows).toEqual( + expected.map(name => expect.objectContaining({ name })) + ) + } + ) + + it.each(sortTestOptions)( + "allow override the default view sorting (%s)", + async (sortParams, expected) => { + const view = await config.api.viewV2.create({ + tableId: table._id!, + name: generator.guid(), + sort: { + field: "name", + order: SortOrder.ASCENDING, + type: SortType.STRING, + }, + schema: viewSchema, + }) + + const response = await config.api.viewV2.search(view.id, { + sort: sortParams.field, + sortOrder: sortParams.order, + sortType: sortParams.type, + query: {}, + }) + + expect(response.rows).toHaveLength(4) + expect(response.rows).toEqual( + expected.map(name => expect.objectContaining({ name })) + ) + } + ) + }) + }) + + describe("permissions", () => { + beforeEach(async () => { + mocks.licenses.useViewPermissions() + await Promise.all( + Array.from({ length: 10 }, () => config.api.row.save(table._id!, {})) + ) + }) + + it("does not allow public users to fetch by default", async () => { + await config.publish() + await config.api.viewV2.publicSearch(view.id, undefined, { + status: 403, + }) + }) + + it("does not allow public users to fetch by default", async () => { + await config.publish() + await config.api.viewV2.publicSearch(view.id, undefined, { + status: 403, + }) + }) + + it("allow public users to fetch when permissions are explicit", async () => { + await config.api.permission.add({ + roleId: roles.BUILTIN_ROLE_IDS.PUBLIC, + level: PermissionLevel.READ, + resourceId: view.id, + }) + await config.publish() + + const response = await config.api.viewV2.publicSearch(view.id) + + expect(response.rows).toHaveLength(10) + }) + + it("allow public users to fetch when permissions are inherited", async () => { + await config.api.permission.add({ + roleId: roles.BUILTIN_ROLE_IDS.PUBLIC, + level: PermissionLevel.READ, + resourceId: table._id!, + }) + await config.publish() + + const response = await config.api.viewV2.publicSearch(view.id) + + expect(response.rows).toHaveLength(10) + }) + + it("respects inherited permissions, not allowing not public views from public tables", async () => { + await config.api.permission.add({ + roleId: roles.BUILTIN_ROLE_IDS.PUBLIC, + level: PermissionLevel.READ, + resourceId: table._id!, + }) + await config.api.permission.add({ + roleId: roles.BUILTIN_ROLE_IDS.POWER, + level: PermissionLevel.READ, + resourceId: view.id, + }) + await config.publish() + + await config.api.viewV2.publicSearch(view.id, undefined, { + status: 403, + }) + }) + }) + }) }) From 6d7712fbdc15b74fa0387bd088eefb97a0bace0e Mon Sep 17 00:00:00 2001 From: Adria Navarro Date: Mon, 18 Mar 2024 10:18:45 +0100 Subject: [PATCH 02/24] Remove .only --- packages/server/src/api/routes/tests/viewV2.spec.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/server/src/api/routes/tests/viewV2.spec.ts b/packages/server/src/api/routes/tests/viewV2.spec.ts index 9c53ade52e..c0b8b33a9a 100644 --- a/packages/server/src/api/routes/tests/viewV2.spec.ts +++ b/packages/server/src/api/routes/tests/viewV2.spec.ts @@ -544,7 +544,7 @@ describe.each([ }) }) - describe.only("row operations", () => { + describe("row operations", () => { let table: Table, view: ViewV2 beforeEach(async () => { table = await config.api.table.save( From 362705793c6e3a63da7fe17729716dcf1fe6f627 Mon Sep 17 00:00:00 2001 From: Andrew Kingston Date: Tue, 19 Mar 2024 16:21:46 +0000 Subject: [PATCH 03/24] Add event context for live eval to table blocks --- .../components/app/blocks/TableBlock.svelte | 42 ++++++++++++------- 1 file changed, 27 insertions(+), 15 deletions(-) diff --git a/packages/client/src/components/app/blocks/TableBlock.svelte b/packages/client/src/components/app/blocks/TableBlock.svelte index 7c58f90508..45ef4e4d3d 100644 --- a/packages/client/src/components/app/blocks/TableBlock.svelte +++ b/packages/client/src/components/app/blocks/TableBlock.svelte @@ -1,5 +1,6 @@ -{#if allowDeletion} - -
- -
- {#if !externalTable} - Edit - {/if} - Delete -
-{/if} + +
+ +
+ {#if !externalTable} + Edit + {/if} + Delete +
Date: Wed, 20 Mar 2024 19:33:39 +0100 Subject: [PATCH 17/24] Type everywhere! --- .../server/src/integrations/base/sqlTable.ts | 2 +- .../server/src/sdk/app/rows/search/utils.ts | 2 +- .../rowProcessor/bbReferenceProcessor.ts | 4 +- .../src/utilities/rowProcessor/index.ts | 7 +-- packages/server/src/utilities/schema.ts | 50 +++++++------------ packages/types/src/documents/app/row.ts | 7 +-- .../types/src/documents/app/table/schema.ts | 39 ++++++++------- 7 files changed, 49 insertions(+), 62 deletions(-) diff --git a/packages/server/src/integrations/base/sqlTable.ts b/packages/server/src/integrations/base/sqlTable.ts index 06c2184549..0feecefb89 100644 --- a/packages/server/src/integrations/base/sqlTable.ts +++ b/packages/server/src/integrations/base/sqlTable.ts @@ -60,7 +60,7 @@ function generateSchema( schema.text(key) break case FieldType.BB_REFERENCE: { - const subtype = column.subtype as FieldSubtype + const subtype = column.subtype switch (subtype) { case FieldSubtype.USER: schema.text(key) diff --git a/packages/server/src/sdk/app/rows/search/utils.ts b/packages/server/src/sdk/app/rows/search/utils.ts index d300fdbef0..086599665b 100644 --- a/packages/server/src/sdk/app/rows/search/utils.ts +++ b/packages/server/src/sdk/app/rows/search/utils.ts @@ -67,7 +67,7 @@ export function searchInputMapping(table: Table, options: SearchParams) { for (let [key, column] of Object.entries(table.schema)) { switch (column.type) { case FieldType.BB_REFERENCE: { - const subtype = column.subtype as FieldSubtype + const subtype = column.subtype switch (subtype) { case FieldSubtype.USER: case FieldSubtype.USERS: diff --git a/packages/server/src/utilities/rowProcessor/bbReferenceProcessor.ts b/packages/server/src/utilities/rowProcessor/bbReferenceProcessor.ts index 31f1f5e575..a5fbfa981d 100644 --- a/packages/server/src/utilities/rowProcessor/bbReferenceProcessor.ts +++ b/packages/server/src/utilities/rowProcessor/bbReferenceProcessor.ts @@ -7,7 +7,7 @@ const ROW_PREFIX = DocumentType.ROW + SEPARATOR export async function processInputBBReferences( value: string | string[] | { _id: string } | { _id: string }[], - subtype: FieldSubtype + subtype: FieldSubtype.USER | FieldSubtype.USERS ): Promise { let referenceIds: string[] = [] @@ -61,7 +61,7 @@ export async function processInputBBReferences( export async function processOutputBBReferences( value: string | string[], - subtype: FieldSubtype + subtype: FieldSubtype.USER | FieldSubtype.USERS ) { if (value === null || value === undefined) { // Already processed or nothing to process diff --git a/packages/server/src/utilities/rowProcessor/index.ts b/packages/server/src/utilities/rowProcessor/index.ts index d956a94d0b..3ed4c5d903 100644 --- a/packages/server/src/utilities/rowProcessor/index.ts +++ b/packages/server/src/utilities/rowProcessor/index.ts @@ -159,10 +159,7 @@ export async function inputProcessing( } if (field.type === FieldType.BB_REFERENCE && value) { - clonedRow[key] = await processInputBBReferences( - value, - field.subtype as FieldSubtype - ) + clonedRow[key] = await processInputBBReferences(value, field.subtype) } } @@ -238,7 +235,7 @@ export async function outputProcessing( for (let row of enriched) { row[property] = await processOutputBBReferences( row[property], - column.subtype as FieldSubtype + column.subtype ) } } diff --git a/packages/server/src/utilities/schema.ts b/packages/server/src/utilities/schema.ts index 5c466ec510..85dfdd3506 100644 --- a/packages/server/src/utilities/schema.ts +++ b/packages/server/src/utilities/schema.ts @@ -1,26 +1,14 @@ -import { FieldType, FieldSubtype } from "@budibase/types" +import { + FieldType, + FieldSubtype, + TableSchema, + FieldSchema, + Row, +} from "@budibase/types" import { ValidColumnNameRegex, utils } from "@budibase/shared-core" import { db } from "@budibase/backend-core" import { parseCsvExport } from "../api/controllers/view/exporters" -interface SchemaColumn { - readonly name: string - readonly type: FieldType - readonly subtype: FieldSubtype - readonly autocolumn?: boolean - readonly constraints?: { - presence: boolean - } -} - -interface Schema { - readonly [index: string]: SchemaColumn -} - -interface Row { - [index: string]: any -} - type Rows = Array interface SchemaValidation { @@ -34,12 +22,10 @@ interface ValidationResults { errors: Record } -export function isSchema(schema: any): schema is Schema { +export function isSchema(schema: any): schema is TableSchema { return ( typeof schema === "object" && - Object.values(schema).every(rawColumn => { - const column = rawColumn as SchemaColumn - + Object.values(schema).every(column => { return ( column !== null && typeof column === "object" && @@ -54,7 +40,7 @@ export function isRows(rows: any): rows is Rows { return Array.isArray(rows) && rows.every(row => typeof row === "object") } -export function validate(rows: Rows, schema: Schema): ValidationResults { +export function validate(rows: Rows, schema: TableSchema): ValidationResults { const results: ValidationResults = { schemaValidation: {}, allValid: false, @@ -64,9 +50,11 @@ export function validate(rows: Rows, schema: Schema): ValidationResults { rows.forEach(row => { Object.entries(row).forEach(([columnName, columnData]) => { - const columnType = schema[columnName]?.type - const columnSubtype = schema[columnName]?.subtype - const isAutoColumn = schema[columnName]?.autocolumn + const { + type: columnType, + subtype: columnSubtype, + autocolumn: isAutoColumn, + } = schema[columnName] // If the column had an invalid value we don't want to override it if (results.schemaValidation[columnName] === false) { @@ -123,7 +111,7 @@ export function validate(rows: Rows, schema: Schema): ValidationResults { return results } -export function parse(rows: Rows, schema: Schema): Rows { +export function parse(rows: Rows, schema: TableSchema): Rows { return rows.map(row => { const parsedRow: Row = {} @@ -133,9 +121,7 @@ export function parse(rows: Rows, schema: Schema): Rows { return } - const columnType = schema[columnName].type - const columnSubtype = schema[columnName].subtype - + const { type: columnType, subtype: columnSubtype } = schema[columnName] if (columnType === FieldType.NUMBER) { // If provided must be a valid number parsedRow[columnName] = columnData ? Number(columnData) : columnData @@ -172,7 +158,7 @@ export function parse(rows: Rows, schema: Schema): Rows { function isValidBBReference( columnData: any, - columnSubtype: FieldSubtype + columnSubtype: FieldSubtype.USER | FieldSubtype.USERS ): boolean { switch (columnSubtype) { case FieldSubtype.USER: diff --git a/packages/types/src/documents/app/row.ts b/packages/types/src/documents/app/row.ts index 0b4c6cd295..aa8f50d4a8 100644 --- a/packages/types/src/documents/app/row.ts +++ b/packages/types/src/documents/app/row.ts @@ -41,12 +41,13 @@ export enum FieldSubtype { SINGLE = "single", } +// The 'as' are required for typescript not to type the outputs as generic FieldSubtype export const FieldTypeSubtypes = { BB_REFERENCE: { - USER: FieldSubtype.USER, - USERS: FieldSubtype.USERS, + USER: FieldSubtype.USER as FieldSubtype.USER, + USERS: FieldSubtype.USERS as FieldSubtype.USERS, }, ATTACHMENT: { - SINGLE: FieldSubtype.SINGLE, + SINGLE: FieldSubtype.SINGLE as FieldSubtype.SINGLE, }, } diff --git a/packages/types/src/documents/app/table/schema.ts b/packages/types/src/documents/app/table/schema.ts index 5da87883f4..3a74134ddd 100644 --- a/packages/types/src/documents/app/table/schema.ts +++ b/packages/types/src/documents/app/table/schema.ts @@ -17,13 +17,14 @@ export interface UIFieldMetadata { } interface BaseRelationshipFieldMetadata - extends Omit { + extends BaseFieldSchema< + AutoFieldSubType.CREATED_BY | AutoFieldSubType.UPDATED_BY | undefined + > { type: FieldType.LINK main?: boolean fieldName: string tableId: string tableRev?: string - subtype?: AutoFieldSubType.CREATED_BY | AutoFieldSubType.UPDATED_BY } // External tables use junction tables, internal tables don't require them @@ -60,18 +61,17 @@ export type RelationshipFieldMetadata = | ManyToOneRelationshipFieldMetadata export interface AutoColumnFieldMetadata - extends Omit { + extends BaseFieldSchema { type: FieldType.AUTO autocolumn: true - subtype?: AutoFieldSubType lastID?: number // if the column was turned to an auto-column for SQL, explains why (primary, foreign etc) autoReason?: AutoReason } -export interface NumberFieldMetadata extends Omit { +export interface NumberFieldMetadata + extends BaseFieldSchema { type: FieldType.NUMBER - subtype?: AutoFieldSubType.AUTO_ID lastID?: number autoReason?: AutoReason.FOREIGN_KEY // used specifically when Budibase generates external tables, this denotes if a number field @@ -82,16 +82,18 @@ export interface NumberFieldMetadata extends Omit { } } -export interface JsonFieldMetadata extends Omit { +export interface JsonFieldMetadata + extends BaseFieldSchema { type: FieldType.JSON - subtype?: JsonFieldSubType.ARRAY } -export interface DateFieldMetadata extends Omit { +export interface DateFieldMetadata + extends BaseFieldSchema< + AutoFieldSubType.CREATED_AT | AutoFieldSubType.UPDATED_AT | undefined + > { type: FieldType.DATETIME ignoreTimezones?: boolean timeOnly?: boolean - subtype?: AutoFieldSubType.CREATED_AT | AutoFieldSubType.UPDATED_AT } export interface LongFormFieldMetadata extends BaseFieldSchema { @@ -106,12 +108,17 @@ export interface FormulaFieldMetadata extends BaseFieldSchema { } export interface BBReferenceFieldMetadata - extends Omit { + extends BaseFieldSchema { type: FieldType.BB_REFERENCE - subtype: FieldSubtype.USER | FieldSubtype.USERS + relationshipType?: RelationshipType } +export interface AttachmentFieldMetadata + extends BaseFieldSchema { + type: FieldType.ATTACHMENT +} + export interface FieldConstraints { type?: string email?: boolean @@ -136,7 +143,7 @@ export interface FieldConstraints { } } -interface BaseFieldSchema extends UIFieldMetadata { +interface BaseFieldSchema extends UIFieldMetadata { type: FieldType name: string sortable?: boolean @@ -145,11 +152,7 @@ interface BaseFieldSchema extends UIFieldMetadata { constraints?: FieldConstraints autocolumn?: boolean autoReason?: AutoReason.FOREIGN_KEY - subtype?: never -} -interface AttachmentFieldMetadata extends Omit { - type: FieldType.ATTACHMENT - subtype?: FieldSubtype.SINGLE + subtype: TSubtype } interface OtherFieldMetadata extends BaseFieldSchema { From 4def299172347496cd4e35c8c7a4afe3e55542a9 Mon Sep 17 00:00:00 2001 From: Adria Navarro Date: Wed, 20 Mar 2024 23:16:41 +0100 Subject: [PATCH 18/24] Undo type changes --- .../types/src/documents/app/table/schema.ts | 42 +++++++++++-------- 1 file changed, 24 insertions(+), 18 deletions(-) diff --git a/packages/types/src/documents/app/table/schema.ts b/packages/types/src/documents/app/table/schema.ts index 3a74134ddd..45e39268ac 100644 --- a/packages/types/src/documents/app/table/schema.ts +++ b/packages/types/src/documents/app/table/schema.ts @@ -17,14 +17,13 @@ export interface UIFieldMetadata { } interface BaseRelationshipFieldMetadata - extends BaseFieldSchema< - AutoFieldSubType.CREATED_BY | AutoFieldSubType.UPDATED_BY | undefined - > { + extends Omit { type: FieldType.LINK main?: boolean fieldName: string tableId: string tableRev?: string + subtype?: AutoFieldSubType.CREATED_BY | AutoFieldSubType.UPDATED_BY } // External tables use junction tables, internal tables don't require them @@ -61,17 +60,18 @@ export type RelationshipFieldMetadata = | ManyToOneRelationshipFieldMetadata export interface AutoColumnFieldMetadata - extends BaseFieldSchema { + extends Omit { type: FieldType.AUTO autocolumn: true + subtype?: AutoFieldSubType lastID?: number // if the column was turned to an auto-column for SQL, explains why (primary, foreign etc) autoReason?: AutoReason } -export interface NumberFieldMetadata - extends BaseFieldSchema { +export interface NumberFieldMetadata extends Omit { type: FieldType.NUMBER + subtype?: AutoFieldSubType.AUTO_ID lastID?: number autoReason?: AutoReason.FOREIGN_KEY // used specifically when Budibase generates external tables, this denotes if a number field @@ -82,18 +82,16 @@ export interface NumberFieldMetadata } } -export interface JsonFieldMetadata - extends BaseFieldSchema { +export interface JsonFieldMetadata extends Omit { type: FieldType.JSON + subtype?: JsonFieldSubType.ARRAY } -export interface DateFieldMetadata - extends BaseFieldSchema< - AutoFieldSubType.CREATED_AT | AutoFieldSubType.UPDATED_AT | undefined - > { +export interface DateFieldMetadata extends Omit { type: FieldType.DATETIME ignoreTimezones?: boolean timeOnly?: boolean + subtype?: AutoFieldSubType.CREATED_AT | AutoFieldSubType.UPDATED_AT } export interface LongFormFieldMetadata extends BaseFieldSchema { @@ -108,15 +106,16 @@ export interface FormulaFieldMetadata extends BaseFieldSchema { } export interface BBReferenceFieldMetadata - extends BaseFieldSchema { + extends Omit { type: FieldType.BB_REFERENCE - + subtype: FieldSubtype.USER | FieldSubtype.USERS relationshipType?: RelationshipType } export interface AttachmentFieldMetadata - extends BaseFieldSchema { + extends Omit { type: FieldType.ATTACHMENT + subtype?: FieldSubtype.SINGLE } export interface FieldConstraints { @@ -143,7 +142,7 @@ export interface FieldConstraints { } } -interface BaseFieldSchema extends UIFieldMetadata { +interface BaseFieldSchema extends UIFieldMetadata { type: FieldType name: string sortable?: boolean @@ -152,7 +151,7 @@ interface BaseFieldSchema extends UIFieldMetadata { constraints?: FieldConstraints autocolumn?: boolean autoReason?: AutoReason.FOREIGN_KEY - subtype: TSubtype + subtype?: never } interface OtherFieldMetadata extends BaseFieldSchema { @@ -164,6 +163,7 @@ interface OtherFieldMetadata extends BaseFieldSchema { | FieldType.FORMULA | FieldType.NUMBER | FieldType.LONGFORM + | FieldType.BB_REFERENCE | FieldType.ATTACHMENT > } @@ -176,9 +176,9 @@ export type FieldSchema = | FormulaFieldMetadata | NumberFieldMetadata | LongFormFieldMetadata - | AttachmentFieldMetadata | BBReferenceFieldMetadata | JsonFieldMetadata + | AttachmentFieldMetadata export interface TableSchema { [key: string]: FieldSchema @@ -213,3 +213,9 @@ export function isBBReferenceField( ): field is BBReferenceFieldMetadata { return field.type === FieldType.BB_REFERENCE } + +export function isAttachmentField( + field: FieldSchema +): field is AttachmentFieldMetadata { + return field.type === FieldType.ATTACHMENT +} From 0859e79b1ed153870432104d4a4ff1bd8abd5a58 Mon Sep 17 00:00:00 2001 From: Adria Navarro Date: Wed, 20 Mar 2024 23:19:42 +0100 Subject: [PATCH 19/24] Lint --- packages/server/src/utilities/rowProcessor/index.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/packages/server/src/utilities/rowProcessor/index.ts b/packages/server/src/utilities/rowProcessor/index.ts index 3ed4c5d903..0015680e77 100644 --- a/packages/server/src/utilities/rowProcessor/index.ts +++ b/packages/server/src/utilities/rowProcessor/index.ts @@ -6,7 +6,6 @@ import { TYPE_TRANSFORM_MAP } from "./map" import { FieldType, AutoFieldSubType, - FieldSubtype, Row, RowAttachment, Table, From a6d38401414953a72ee42b0bd40826ea7a256cfa Mon Sep 17 00:00:00 2001 From: Adria Navarro Date: Thu, 21 Mar 2024 11:28:06 +0100 Subject: [PATCH 20/24] Fix bundling --- packages/string-templates/src/helpers/list.ts | 39 ++++++++++++------- 1 file changed, 26 insertions(+), 13 deletions(-) diff --git a/packages/string-templates/src/helpers/list.ts b/packages/string-templates/src/helpers/list.ts index 361558e04d..082d0e255b 100644 --- a/packages/string-templates/src/helpers/list.ts +++ b/packages/string-templates/src/helpers/list.ts @@ -1,17 +1,30 @@ import { date, duration } from "./date" +import { + math, + array, + number, + url, + string, + comparison, + object, + regex, + uuid, + // @ts-expect-error +} from "@budibase/handlebars-helpers" + // https://github.com/evanw/esbuild/issues/56 -const getExternalCollections = (): Record any> => ({ - math: require("@budibase/handlebars-helpers/lib/math"), - array: require("@budibase/handlebars-helpers/lib/array"), - number: require("@budibase/handlebars-helpers/lib/number"), - url: require("@budibase/handlebars-helpers/lib/url"), - string: require("@budibase/handlebars-helpers/lib/string"), - comparison: require("@budibase/handlebars-helpers/lib/comparison"), - object: require("@budibase/handlebars-helpers/lib/object"), - regex: require("@budibase/handlebars-helpers/lib/regex"), - uuid: require("@budibase/handlebars-helpers/lib/uuid"), -}) +const externalCollections = { + math, + array, + number, + url, + string, + comparison, + object, + regex, + uuid, +} export const helpersToRemoveForJs = ["sortBy"] @@ -28,8 +41,8 @@ export function getJsHelperList() { } helpers = {} - for (let collection of Object.values(getExternalCollections())) { - for (let [key, func] of Object.entries(collection)) { + for (let collection of Object.values(externalCollections)) { + for (let [key, func] of Object.entries(collection)) { // Handlebars injects the hbs options to the helpers by default. We are adding an empty {} as a last parameter to simulate it helpers[key] = (...props: any) => func(...props, {}) } From 1a8510358b80835809eea3529c0519c51cc28690 Mon Sep 17 00:00:00 2001 From: Adria Navarro Date: Thu, 21 Mar 2024 11:43:50 +0100 Subject: [PATCH 21/24] Fix test --- packages/string-templates/src/helpers/list.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/string-templates/src/helpers/list.ts b/packages/string-templates/src/helpers/list.ts index 082d0e255b..5852bc9127 100644 --- a/packages/string-templates/src/helpers/list.ts +++ b/packages/string-templates/src/helpers/list.ts @@ -42,7 +42,7 @@ export function getJsHelperList() { helpers = {} for (let collection of Object.values(externalCollections)) { - for (let [key, func] of Object.entries(collection)) { + for (let [key, func] of Object.entries(collection())) { // Handlebars injects the hbs options to the helpers by default. We are adding an empty {} as a last parameter to simulate it helpers[key] = (...props: any) => func(...props, {}) } From 08cf877565ee8f46a62b538af7a9340e93460049 Mon Sep 17 00:00:00 2001 From: Budibase Staging Release Bot <> Date: Thu, 21 Mar 2024 11:02:04 +0000 Subject: [PATCH 22/24] Bump version to 2.22.8 --- lerna.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lerna.json b/lerna.json index 3a92bc6d9a..ec64523dff 100644 --- a/lerna.json +++ b/lerna.json @@ -1,5 +1,5 @@ { - "version": "2.22.7", + "version": "2.22.8", "npmClient": "yarn", "packages": [ "packages/*", From a85d4460b1426629391159d41945057da8e842b0 Mon Sep 17 00:00:00 2001 From: Adria Navarro Date: Thu, 21 Mar 2024 14:18:45 +0100 Subject: [PATCH 23/24] Clean code --- packages/server/src/api/controllers/table/utils.ts | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/packages/server/src/api/controllers/table/utils.ts b/packages/server/src/api/controllers/table/utils.ts index ac13617869..0c9933a4cf 100644 --- a/packages/server/src/api/controllers/table/utils.ts +++ b/packages/server/src/api/controllers/table/utils.ts @@ -31,6 +31,7 @@ import { RelationshipFieldMetadata, FieldType, FieldTypeSubtypes, + AttachmentFieldMetadata, } from "@budibase/types" export async function clearColumns(table: Table, columnNames: string[]) { @@ -90,11 +91,14 @@ export async function checkForColumnUpdates( await checkForViewUpdates(updatedTable, deletedColumns, columnRename) } - for (const attachmentColumn of Object.values(updatedTable.schema).filter( - column => + const changedAttachmentSubtypeColumns = Object.values( + updatedTable.schema + ).filter( + (column): column is AttachmentFieldMetadata => column.type === FieldType.ATTACHMENT && column.subtype !== oldTable?.schema[column.name]?.subtype - )) { + ) + for (const attachmentColumn of changedAttachmentSubtypeColumns) { if (attachmentColumn.subtype === FieldTypeSubtypes.ATTACHMENT.SINGLE) { attachmentColumn.constraints ??= { length: {} } attachmentColumn.constraints.length ??= {} From ed94459fd8101d267729cf414c6b6eb829573cb3 Mon Sep 17 00:00:00 2001 From: Budibase Staging Release Bot <> Date: Thu, 21 Mar 2024 13:31:53 +0000 Subject: [PATCH 24/24] Bump version to 2.22.9 --- lerna.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lerna.json b/lerna.json index ec64523dff..5a561bec04 100644 --- a/lerna.json +++ b/lerna.json @@ -1,5 +1,5 @@ { - "version": "2.22.8", + "version": "2.22.9", "npmClient": "yarn", "packages": [ "packages/*",