Move isRequired to shared-core
This commit is contained in:
parent
5c3973d7f9
commit
b937d95de2
|
@ -8,6 +8,7 @@ import {
|
||||||
} from "@budibase/types"
|
} from "@budibase/types"
|
||||||
import { HTTPError, db as dbCore } from "@budibase/backend-core"
|
import { HTTPError, db as dbCore } from "@budibase/backend-core"
|
||||||
import { features } from "@budibase/pro"
|
import { features } from "@budibase/pro"
|
||||||
|
import { helpers } from "@budibase/shared-core"
|
||||||
import { cloneDeep } from "lodash"
|
import { cloneDeep } from "lodash"
|
||||||
|
|
||||||
import * as utils from "../../../db/utils"
|
import * as utils from "../../../db/utils"
|
||||||
|
@ -16,7 +17,6 @@ import { isExternalTableID } from "../../../integrations/utils"
|
||||||
import * as internal from "./internal"
|
import * as internal from "./internal"
|
||||||
import * as external from "./external"
|
import * as external from "./external"
|
||||||
import sdk from "../../../sdk"
|
import sdk from "../../../sdk"
|
||||||
import { isRequired } from "../../../utilities/schema"
|
|
||||||
|
|
||||||
function pickApi(tableId: any) {
|
function pickApi(tableId: any) {
|
||||||
if (isExternalTableID(tableId)) {
|
if (isExternalTableID(tableId)) {
|
||||||
|
@ -58,7 +58,7 @@ async function guardViewSchema(
|
||||||
throw new HTTPError(`Readonly fields are not enabled`, 400)
|
throw new HTTPError(`Readonly fields are not enabled`, 400)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isRequired(tableSchemaField.constraints)) {
|
if (helpers.schema.isRequired(tableSchemaField.constraints)) {
|
||||||
throw new HTTPError(
|
throw new HTTPError(
|
||||||
`Field "${field}" cannot be readonly as it is a required field`,
|
`Field "${field}" cannot be readonly as it is a required field`,
|
||||||
400
|
400
|
||||||
|
|
|
@ -4,7 +4,6 @@ import {
|
||||||
TableSchema,
|
TableSchema,
|
||||||
FieldSchema,
|
FieldSchema,
|
||||||
Row,
|
Row,
|
||||||
FieldConstraints,
|
|
||||||
} from "@budibase/types"
|
} from "@budibase/types"
|
||||||
import { ValidColumnNameRegex, utils } from "@budibase/shared-core"
|
import { ValidColumnNameRegex, utils } from "@budibase/shared-core"
|
||||||
import { db } from "@budibase/backend-core"
|
import { db } from "@budibase/backend-core"
|
||||||
|
@ -41,15 +40,6 @@ export function isRows(rows: any): rows is Rows {
|
||||||
return Array.isArray(rows) && rows.every(row => typeof row === "object")
|
return Array.isArray(rows) && rows.every(row => typeof row === "object")
|
||||||
}
|
}
|
||||||
|
|
||||||
export function isRequired(constraints: FieldConstraints | undefined) {
|
|
||||||
const isRequired =
|
|
||||||
!!constraints &&
|
|
||||||
((typeof constraints.presence !== "boolean" &&
|
|
||||||
constraints.presence?.allowEmpty === false) ||
|
|
||||||
constraints.presence === true)
|
|
||||||
return isRequired
|
|
||||||
}
|
|
||||||
|
|
||||||
export function validate(rows: Rows, schema: TableSchema): ValidationResults {
|
export function validate(rows: Rows, schema: TableSchema): ValidationResults {
|
||||||
const results: ValidationResults = {
|
const results: ValidationResults = {
|
||||||
schemaValidation: {},
|
schemaValidation: {},
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
import {
|
import {
|
||||||
BBReferenceFieldSubType,
|
BBReferenceFieldSubType,
|
||||||
|
FieldConstraints,
|
||||||
FieldSchema,
|
FieldSchema,
|
||||||
FieldType,
|
FieldType,
|
||||||
} from "@budibase/types"
|
} from "@budibase/types"
|
||||||
|
@ -16,3 +17,12 @@ export function isDeprecatedSingleUserColumn(
|
||||||
schema.constraints?.type !== "array"
|
schema.constraints?.type !== "array"
|
||||||
return result
|
return result
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function isRequired(constraints: FieldConstraints | undefined) {
|
||||||
|
const isRequired =
|
||||||
|
!!constraints &&
|
||||||
|
((typeof constraints.presence !== "boolean" &&
|
||||||
|
constraints.presence?.allowEmpty === false) ||
|
||||||
|
constraints.presence === true)
|
||||||
|
return isRequired
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue