Conversation
|
This is fantastic, much smaller than expected. Nicely done, James! |
nickva
left a comment
There was a problem hiding this comment.
I like the simple approach here, it turned out much simpler than expected implementation-wise at least!
If we're going to merge it, let's add some basic docs for it. Even if just API updates, but an example or two can be nice as well.
This counter is incremented whenever a VDU returns a value other than `1`, whereas `ok` and `true` are also treated as acceptable success values. This fixes the counter to only increment on actual failure responses.
|
I was going to give documenting this a short and when I looked where it would best fit in the docs, I realised that for Mango we have an API for adding indexes on top of the bare design doc mechanism. I am wondering if we want to do this here as well, something along the lines of:
I’m not sure I’m super a fan of this, but it would be mirroring the other Mango API. |
Yeah it makes sense from the Mango API pattern point of view, but selectors are sort of their own thing are used outside of Mango indexing already (filters), and VDU already exist (in JS form) and have their own "shape" so to speak and, at least to me, this seems more of an improvement/extension of the JS vdus. |
Overview
This PR implements "phase 1" of the functionality outlined in #5792, i.e. it adds the ability for
validate_doc_updateto be implemented as a Mango selector expression, rather than as a JavaScript function. The selector is evaluated against an ephemeral JSON structure containingnewDoc(the new doc version to be saved) andoldDoc(the one currently on disk). For example, saving the following to/db/_design/mango-vduwill cause all docs to be checked for atypefield which must be a string:{ "language": "query", "validate_doc_update": { "newDoc": { "type": { "$type": "string" } } } }This uses the existing infrastructure of
couch_query_serversandmango_native_proc, just adding appropriate message handlers to Mango processes for handling VDU requests.Testing recommendations
The added tests cover the basic functionality to check that Mango validators can be saved, and the in-memory cache is updated as appropriate. It assumes Mango works as it does in current releases and so does not re-test all the Mango functionality in detail.
Since there are now two different languages VDUs can be written in, I may have missed anything that assumes there's only one way to do it. I did however notice a counter being updated incorrectly, which is now fixed.
Related Issues or Pull Requests
Checklist
rel/overlay/etc/default.inisrc/docsfolder