-
Notifications
You must be signed in to change notification settings - Fork 78
Description
Hi,
I just employed a hack to use a validation library other than class-validator. Since validateModels: true will import class-validator dynamically, I just fed it a fake package of the same name. It simply exports a validate function act as a stand-in replacement for class-validator.
The validation interface is quite trivial:
interface IEntityValidator {
(entity: IEntity, validateOptions?: Record<string, unknown>): Array<any>
}So changing initialize to accept
interface IFireormInitOptions {
validateModels?: boolean
validate?: IEntityValidator
}would allow for trivially wrapping every validation library under the sun in an IEntityValidator and returning an array containing arbitrary validation errors, whether that's simple strings or elaborate objects.
It would still support the current behavior of passing in validateModels and default to using class-validator. There is an easy deprecation path for phasing out the class-validator-only method, if desired. Eventually, if one chooses to use class-validator it's merely
import { getFirestore } from 'my-firestore-setup';
import { validate } from 'class-validator';
import { initialize } from 'fireorm';
initialize(getFirestore(), { validate })which in my estimation is acceptable boilerplate for being able to use arbitrary validation methods.
I'd be happy to submit a PR in case this proposal is to your liking.