Skip to content

Commit

Permalink
fix: don't pass unsupported options to clean
Browse files Browse the repository at this point in the history
fixes #476
  • Loading branch information
aldeed committed Feb 19, 2024
1 parent afbaa2b commit c1d4bc3
Showing 1 changed file with 6 additions and 9 deletions.
15 changes: 6 additions & 9 deletions src/SimpleSchema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -897,16 +897,13 @@ class SimpleSchema {
// eslint-disable-next-line @typescript-eslint/no-invalid-void-type
validator (options: ValidationOptions & { clean?: boolean, returnErrorsPromise?: boolean } = {}): (obj: Record<string, any>) => void | Promise<ValidationError[]> {
return (obj: Record<string, any>) => {
const optionsClone = { ...options }
if (options.clean === true) {
// Do this here and pass into both functions for better performance
optionsClone.mongoObject = new MongoObject(obj, this.blackboxKeys())
this.clean(obj, optionsClone)
const { clean, returnErrorsPromise, ...validationOptions } = options
// Do this here and pass into both functions for better performance
const mongoObject = new MongoObject(obj, this.blackboxKeys())
if (clean === true) {
this.clean(obj, { mongoObject })
}
if (options.returnErrorsPromise === true) {
return this.validateAndReturnErrorsPromise(obj, optionsClone)
}
return this.validate(obj, optionsClone)
return returnErrorsPromise === true ? this.validateAndReturnErrorsPromise(obj, { ...validationOptions, mongoObject }) : this.validate(obj, { ...validationOptions, mongoObject })
}
}

Expand Down

0 comments on commit c1d4bc3

Please sign in to comment.