2024-05-09 12:28:44 +02:00
|
|
|
import {
|
|
|
|
BBReferenceFieldSubType,
|
2024-06-03 16:55:02 +02:00
|
|
|
FieldConstraints,
|
2024-05-09 12:28:44 +02:00
|
|
|
FieldSchema,
|
|
|
|
FieldType,
|
|
|
|
} from "@budibase/types"
|
|
|
|
|
2024-05-13 12:13:57 +02:00
|
|
|
export function isDeprecatedSingleUserColumn(
|
|
|
|
schema: Pick<FieldSchema, "type" | "subtype" | "constraints">
|
2024-05-14 17:43:42 +02:00
|
|
|
): schema is {
|
|
|
|
type: FieldType.BB_REFERENCE
|
|
|
|
subtype: BBReferenceFieldSubType.USER
|
|
|
|
} {
|
2024-05-09 12:28:44 +02:00
|
|
|
const result =
|
|
|
|
schema.type === FieldType.BB_REFERENCE &&
|
|
|
|
schema.subtype === BBReferenceFieldSubType.USER &&
|
|
|
|
schema.constraints?.type !== "array"
|
|
|
|
return result
|
|
|
|
}
|
2024-06-03 16:55:02 +02:00
|
|
|
|
|
|
|
export function isRequired(constraints: FieldConstraints | undefined) {
|
|
|
|
const isRequired =
|
|
|
|
!!constraints &&
|
|
|
|
((typeof constraints.presence !== "boolean" &&
|
|
|
|
constraints.presence?.allowEmpty === false) ||
|
|
|
|
constraints.presence === true)
|
|
|
|
return isRequired
|
|
|
|
}
|