1
0
Fork 0
mirror of synced 2024-09-20 11:27:56 +12:00

Checking the correct operation - also typeguarding the check.

This commit is contained in:
mike12345567 2024-08-09 14:35:13 +01:00
parent a9acc7f87b
commit 3e1a0a60b4
3 changed files with 15 additions and 5 deletions

View file

@ -70,7 +70,12 @@ function generateSchema(
case FieldType.LONGFORM:
case FieldType.BARCODEQR:
case FieldType.BB_REFERENCE_SINGLE:
schema.text(key)
// primary key strings have to have a length in some DBs
if (primaryKeys.includes(key)) {
schema.string(key, 255)
} else {
schema.text(key)
}
break
case FieldType.NUMBER:
// if meta is specified then this is a junction table entry

View file

@ -1,6 +1,5 @@
import dayjs from "dayjs"
import {
ArrayOperator,
AutoFieldSubType,
AutoReason,
Datasource,
@ -196,13 +195,13 @@ export class ExternalRequest<T extends Operation> {
if (filters) {
// need to map over the filters and make sure the _id field isn't present
let prefix = 1
for (const operator of Object.values(filters)) {
const isArrayOperator = Object.values(ArrayOperator).includes(operator)
for (const [operatorType, operator] of Object.entries(filters)) {
const isArrayOp = sdk.rows.utils.isArrayFilter(operatorType)
for (const field of Object.keys(operator || {})) {
if (dbCore.removeKeyNumbering(field) === "_id") {
if (primary) {
const parts = breakRowIdField(operator[field])
if (primary.length > 1 && isArrayOperator) {
if (primary.length > 1 && isArrayOp) {
operator[InternalSearchFilterOperator.COMPLEX_ID_OPERATOR] = {
id: primary,
values: parts[0],

View file

@ -12,6 +12,7 @@ import {
Table,
TableSchema,
SqlClient,
ArrayOperator,
} from "@budibase/types"
import { makeExternalQuery } from "../../../integrations/base/query"
import { Format } from "../../../api/controllers/view/exporters"
@ -311,3 +312,8 @@ function validateTimeOnlyField(
return res
}
// type-guard check
export function isArrayFilter(operator: any): operator is ArrayOperator {
return Object.values(ArrayOperator).includes(operator)
}