rethinkdb / horizon

Horizon is a realtime, open-source backend for JavaScript apps.
MIT License
6.78k stars 351 forks source link

Date validator #795

Open deontologician opened 8 years ago

deontologician commented 8 years ago

Since we serialize dates to RethinkDB format in the wire protocol, which is what the validators check, we should probably add a convenience Date validator that takes similar arguments to the javascript Date constructor, but actually validates a date in reql format.

@Tryneus

nardeas commented 8 years ago

Great! Are there any other specific types we should add validators for that we can come up with?

nardeas commented 8 years ago

How about something like isArrayEqual or similar for comparing that arrays have exactly the same values? For example if I want to make sure that the user doesn't accidentally modify the default groups array in the users collection, but allow changing some other fields it would be easy to write a validator that checks isArrayEqual(newValue.groups, oldValue.groups). This is perhaps more like sugar because of course you could do newValue.groups.toString() == oldValue.groups.toString() but that isn't as clear.