On Jan 29, 2009, at 12:50 PM, Chris Anderson wrote:
On Thu, Jan 29, 2009 at 1:03 AM, Brian Candler <[email protected]>
wrote:
can validate_doc_update also modify the data being stored?
No. Side effects in that function become would deeply confusing, as it
runs during replication as well as for client-updates.
Indeed.
My thinking to fill in the gap is we will provide something like a
server side stored procedure, that when given a newly updated document
can modify it and perform complex logic on it and then save it. Then
custom validation functions would refuse any documents that aren't
correctly processed, but allow through correctly process replicated
edits.
So you'd have a design doc that looks something like this
{
id:"_design/foo",
procs:{
update_article: "function(editDoc, userCtx) {var prevDoc =
load_prev_rev(editDoc); add_diffs(editDoc, prevDoc}; save(editDoc)}"
},
validate_doc_update: "function(newDoc, oldDoc, userCtx) {if !
validate_diffs(newDoc)) {throw {forbidden: 'Documents must be saved
via update_article'}",
...
}
And when saving a new doc:
PUT /db/_proc/foo/update_article
{
_id:"somedocid",
_rev:"somerev",
yadda:"yadda",
...
}
-Damien