Skip to content

Commit c1d4bc3

Browse files
committed
fix: don't pass unsupported options to clean
fixes #476
1 parent afbaa2b commit c1d4bc3

File tree

1 file changed

+6
-9
lines changed

1 file changed

+6
-9
lines changed

src/SimpleSchema.ts

+6-9
Original file line numberDiff line numberDiff line change
@@ -897,16 +897,13 @@ class SimpleSchema {
897897
// eslint-disable-next-line @typescript-eslint/no-invalid-void-type
898898
validator (options: ValidationOptions & { clean?: boolean, returnErrorsPromise?: boolean } = {}): (obj: Record<string, any>) => void | Promise<ValidationError[]> {
899899
return (obj: Record<string, any>) => {
900-
const optionsClone = { ...options }
901-
if (options.clean === true) {
902-
// Do this here and pass into both functions for better performance
903-
optionsClone.mongoObject = new MongoObject(obj, this.blackboxKeys())
904-
this.clean(obj, optionsClone)
900+
const { clean, returnErrorsPromise, ...validationOptions } = options
901+
// Do this here and pass into both functions for better performance
902+
const mongoObject = new MongoObject(obj, this.blackboxKeys())
903+
if (clean === true) {
904+
this.clean(obj, { mongoObject })
905905
}
906-
if (options.returnErrorsPromise === true) {
907-
return this.validateAndReturnErrorsPromise(obj, optionsClone)
908-
}
909-
return this.validate(obj, optionsClone)
906+
return returnErrorsPromise === true ? this.validateAndReturnErrorsPromise(obj, { ...validationOptions, mongoObject }) : this.validate(obj, { ...validationOptions, mongoObject })
910907
}
911908
}
912909

0 commit comments

Comments
 (0)