-
Notifications
You must be signed in to change notification settings - Fork 1
Description
Hello, I'm using Cabidela in a Cloudflare Pages worker project but I don't think it handles any string-format validation yet does it?
I see that pattern validation is implemented, but I want to register a named string format and supply a validator function for it similar to how you do it for TypeBox and Ajv. Just curious if you could tell me how you might expose that feature?
It looks like the correct place to add calls to a validator would be around here. Beyond that, I guess you would add a mapping of string-format validators in the CabidelaOptions, something like formats: Record<string, (value: string) => boolean | string>;?
My main question about any possible future format validators is the function signature. I suppose I would be safe just returning a boolean to Cabidela, but that would limit the resulting error messages to '${pathToString(needle.path)}' is not a valid '${format}'. and it would be nice, if the validator returned a string, to do something like '${pathToString(needle.path)}' is not a valid '${format}'. (${result}) where result would be the string returned from the validator.
For now I'll start by making my own validator functions just return booleans to be safe.
EDIT: The benefit of just returning a bool will be that I can use some code from ajv-formats, so I guess that should be the standard anyway.
This addition was pretty straightforward, but if you're taking pull requests let me know and I'll send one.