Khauri/firestore-plus

Separate validator from code

Khauri opened this issue · 0 comments

The schema validation has yup as a dependency and when creating, but it should be possible to enable a custom validator, such as joi, by creating an interface that has all the methods required. The advantage here is that then firestore-plus can list yup as an optional dependency.

I think this interface would suit all the needs

Validator {
  // Returns validated and/or transformed data
  // @throws Error if data is invalid
  validate : ( data : any ) => data : any
}

Some possible methods of changing the validator...

On initialization

new FirestorePlus(firebase, {
	validator : Validator
})

Lazily

firestorePlusInstance.validator = Validator