Merge branch 'master' of github.com:budibase/budibase into js-stack-traces

This commit is contained in:
Sam Rose 2024-10-03 11:59:14 +01:00
commit 9bb6855967
No known key found for this signature in database
10 changed files with 2878 additions and 2759 deletions

View File

@ -1,6 +1,6 @@
{
"$schema": "node_modules/lerna/schemas/lerna-schema.json",
"version": "2.32.10",
"version": "2.32.11",
"npmClient": "yarn",
"packages": [
"packages/*",

View File

@ -124,9 +124,11 @@ export async function buildSqlFieldList(
([columnName, column]) =>
column.type !== FieldType.LINK &&
column.type !== FieldType.FORMULA &&
!existing.find((field: string) => field === columnName)
!existing.find(
(field: string) => field === `${table.name}.${columnName}`
)
)
.map(column => `${table.name}.${column[0]}`)
.map(([columnName]) => `${table.name}.${columnName}`)
}
let fields: string[] = []

File diff suppressed because it is too large Load Diff

View File

@ -22,9 +22,10 @@ import {
RelationshipType,
TableSchema,
RenameColumn,
ViewFieldMetadata,
FeatureFlag,
BBReferenceFieldSubType,
ViewV2Schema,
ViewCalculationFieldMetadata,
} from "@budibase/types"
import { generator, mocks } from "@budibase/backend-core/tests"
import { DatabaseName, getDatasource } from "../../../integrations/tests/utils"
@ -540,6 +541,33 @@ describe.each([
status: 201,
})
})
it("can create a view with calculation fields", async () => {
let view = await config.api.viewV2.create({
tableId: table._id!,
name: generator.guid(),
schema: {
sum: {
visible: true,
calculationType: CalculationType.SUM,
field: "Price",
},
},
})
expect(Object.keys(view.schema!)).toHaveLength(1)
let sum = view.schema!.sum as ViewCalculationFieldMetadata
expect(sum).toBeDefined()
expect(sum.calculationType).toEqual(CalculationType.SUM)
expect(sum.field).toEqual("Price")
view = await config.api.viewV2.get(view.id)
sum = view.schema!.sum as ViewCalculationFieldMetadata
expect(sum).toBeDefined()
expect(sum.calculationType).toEqual(CalculationType.SUM)
expect(sum.field).toEqual("Price")
})
})
describe("update", () => {
@ -1152,10 +1180,7 @@ describe.each([
return table
}
const createView = async (
tableId: string,
schema: Record<string, ViewFieldMetadata>
) =>
const createView = async (tableId: string, schema: ViewV2Schema) =>
await config.api.viewV2.create({
name: generator.guid(),
tableId,
@ -2546,6 +2571,51 @@ describe.each([
}
})
})
!isLucene &&
it("should not need required fields to be present", async () => {
const table = await config.api.table.save(
saveTableRequest({
schema: {
name: {
name: "name",
type: FieldType.STRING,
constraints: {
presence: true,
},
},
age: {
name: "age",
type: FieldType.NUMBER,
},
},
})
)
await Promise.all([
config.api.row.save(table._id!, { name: "Steve", age: 30 }),
config.api.row.save(table._id!, { name: "Jane", age: 31 }),
])
const view = await config.api.viewV2.create({
tableId: table._id!,
name: generator.guid(),
schema: {
sum: {
visible: true,
calculationType: CalculationType.SUM,
field: "age",
},
},
})
const response = await config.api.viewV2.search(view.id, {
query: {},
})
expect(response.rows).toHaveLength(1)
expect(response.rows[0].sum).toEqual(61)
})
})
describe("permissions", () => {

View File

@ -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<T = Row[] | Row>(
FeatureFlag.ENRICHED_RELATIONSHIPS
)
let viewSchema: Record<string, ViewFieldMetadata> = {}
let viewSchema: ViewV2Schema = {}
if (sdk.views.isView(source)) {
if (helpers.views.isCalculationView(source)) {
return enriched

View File

@ -93,6 +93,8 @@ export async function search(
// Lucene does not accept conditional filters, so we need to keep the old logic
const query: SearchFilters = viewQuery
delete options.query.onEmptyFilter
// Extract existing fields
const existingFields =
view.query
@ -115,6 +117,9 @@ export async function search(
conditions: [viewQuery, options.query],
},
}
if (viewQuery.onEmptyFilter) {
options.query.onEmptyFilter = viewQuery.onEmptyFilter
}
}
}

View File

@ -258,19 +258,12 @@ export async function enrichSchema(
view: ViewV2,
tableSchema: TableSchema
): Promise<ViewV2Enriched> {
const tableCache: Record<string, Table> = {}
async function populateRelTableSchema(
tableId: string,
viewFields: Record<string, RelationSchemaField>
) {
if (!tableCache[tableId]) {
tableCache[tableId] = await sdk.tables.getTable(tableId)
}
const relTable = tableCache[tableId]
const relTable = await sdk.tables.getTable(tableId)
const result: Record<string, ViewV2ColumnEnriched> = {}
for (const relTableFieldName of Object.keys(relTable.schema)) {
const relTableField = relTable.schema[relTableFieldName]
if ([FieldType.LINK, FieldType.FORMULA].includes(relTableField.type)) {
@ -299,15 +292,24 @@ export async function enrichSchema(
const viewSchema = view.schema || {}
const anyViewOrder = Object.values(viewSchema).some(ui => ui.order != null)
for (const key of Object.keys(tableSchema).filter(
k => tableSchema[k].visible !== false
)) {
const visibleSchemaFields = Object.keys(viewSchema).filter(key => {
if (helpers.views.isCalculationField(viewSchema[key])) {
return viewSchema[key].visible !== false
}
return key in tableSchema && tableSchema[key].visible !== false
})
const visibleTableFields = Object.keys(tableSchema).filter(
key => tableSchema[key].visible !== false
)
const visibleFields = new Set([...visibleSchemaFields, ...visibleTableFields])
for (const key of visibleFields) {
// if nothing specified in view, then it is not visible
const ui = viewSchema[key] || { visible: false }
schema[key] = {
...tableSchema[key],
...ui,
order: anyViewOrder ? ui?.order ?? undefined : tableSchema[key].order,
order: anyViewOrder ? ui?.order ?? undefined : tableSchema[key]?.order,
columns: undefined,
}
@ -319,10 +321,7 @@ export async function enrichSchema(
}
}
return {
...view,
schema: schema,
}
return { ...view, schema }
}
export function syncSchema(

View File

@ -7,11 +7,11 @@ import {
BulkImportRequest,
BulkImportResponse,
SearchRowResponse,
RowSearchParams,
DeleteRows,
DeleteRow,
PaginatedSearchRowResponse,
RowExportFormat,
SearchRowRequest,
} from "@budibase/types"
import { Expectations, TestAPI } from "./base"
@ -136,7 +136,7 @@ export class RowAPI extends TestAPI {
)
}
search = async <T extends RowSearchParams>(
search = async <T extends SearchRowRequest>(
sourceId: string,
params?: T,
expectations?: Expectations

View File

@ -71,9 +71,11 @@ export interface ViewV2 {
order?: SortOrder
type?: SortType
}
schema?: Record<string, ViewFieldMetadata>
schema?: ViewV2Schema
}
export type ViewV2Schema = Record<string, ViewFieldMetadata>
export type ViewSchema = ViewCountOrSumSchema | ViewStatisticsSchema
export interface ViewCountOrSumSchema {

View File

@ -2051,7 +2051,7 @@
resolved "https://registry.yarnpkg.com/@bcoe/v8-coverage/-/v8-coverage-0.2.3.tgz#75a2e8b51cb758a7553d6804a5932d7aace75c39"
integrity sha512-0hYQ8SB4Db5zvZB4axdMHGwEaQjkZzFjQiN9LVYvIFB2nSUHW9tYpxWriPrWDASIxiaXax83REcLxuSdnGPZtw==
"@budibase/backend-core@2.32.10":
"@budibase/backend-core@2.32.11":
version "0.0.0"
dependencies:
"@budibase/nano" "10.1.5"
@ -2132,15 +2132,15 @@
through2 "^2.0.0"
"@budibase/pro@npm:@budibase/pro@latest":
version "2.32.10"
resolved "https://registry.yarnpkg.com/@budibase/pro/-/pro-2.32.10.tgz#19fcbb3ced74791a7e96dfdc5a1270165792eea5"
integrity sha512-TbVp2bjmA0rHK+TKi9NVW06+O23fhDm7IJ/FlpWPHIBIZW7xDkCYu6LUOhSwSWMbOTcWzaJFuMbpN1HoTc/YjQ==
version "2.32.11"
resolved "https://registry.yarnpkg.com/@budibase/pro/-/pro-2.32.11.tgz#c94d534f829ca0ef252677757e157a7e58b87b4d"
integrity sha512-mOkqJpqHKWsfTWZwWcvBCYFUIluSUHltQNinc1ZRsg9rC3OKoHSDop6gzm744++H/GzGRN8V86kLhCgtNIlkpA==
dependencies:
"@anthropic-ai/sdk" "^0.27.3"
"@budibase/backend-core" "2.32.10"
"@budibase/shared-core" "2.32.10"
"@budibase/string-templates" "2.32.10"
"@budibase/types" "2.32.10"
"@budibase/backend-core" "2.32.11"
"@budibase/shared-core" "2.32.11"
"@budibase/string-templates" "2.32.11"
"@budibase/types" "2.32.11"
"@koa/router" "8.0.8"
bull "4.10.1"
dd-trace "5.2.0"
@ -2153,13 +2153,13 @@
scim-patch "^0.8.1"
scim2-parse-filter "^0.2.8"
"@budibase/shared-core@2.32.10":
"@budibase/shared-core@2.32.11":
version "0.0.0"
dependencies:
"@budibase/types" "0.0.0"
cron-validate "1.4.5"
"@budibase/string-templates@2.32.10":
"@budibase/string-templates@2.32.11":
version "0.0.0"
dependencies:
"@budibase/handlebars-helpers" "^0.13.2"
@ -2167,7 +2167,7 @@
handlebars "^4.7.8"
lodash.clonedeep "^4.5.0"
"@budibase/types@2.32.10":
"@budibase/types@2.32.11":
version "0.0.0"
dependencies:
scim-patch "^0.8.1"