1
0
Fork 0
mirror of synced 2024-07-30 02:26:11 +12:00

Support nulls when optional

This commit is contained in:
Adria Navarro 2023-05-02 12:48:05 +01:00
parent 6e7c78362e
commit 1d041a3dd5

View file

@ -4,6 +4,9 @@ interface SchemaColumn {
readonly name: string
readonly type: FieldTypes
readonly autocolumn?: boolean
readonly constraints?: {
presence: boolean
}
}
interface Schema {
@ -76,6 +79,11 @@ export function validate(rows: Rows, schema: Schema): ValidationResults {
// If the columnType is not a string, then it's not present in the schema, and should be added to the invalid columns array
if (typeof columnType !== "string") {
results.invalidColumns.push(columnName)
} else if (
columnData == null &&
!schema[columnName].constraints?.presence
) {
results.schemaValidation[columnName] = true
} else if (
// If there's no data for this field don't bother with further checks
// If the field is already marked as invalid there's no need for further checks