couchdb-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Samuel Williams <space.ship.travel...@gmail.com>
Subject Re: validate_doc_update response?
Date Sun, 22 Jul 2012 09:19:58 GMT
Just as an aside, I was thinking it would be nice to write something like
this:

ddoc = {
validates: {
{
match: function(document) { return document.type == 'user'; }
validate: function(new_doc, old_doc, user_context) {
if (!user_context.admin || old_doc.username == user_context.username)
throw 'forbidden', ...;
}
}
}
}

Not sure what others think, but putting all your validation logic in one
function seems pretty cumbersome. I'm probably going to wrap
validate_doc_update around this structure in my Ruby Query Server.

Does this seem like an interesting approach?

Kind regards,
Samuel

On 22 July 2012 21:14, Samuel Williams <space.ship.traveller@gmail.com>wrote:

> I see, so the specification for design doc was made before that patch, so
> the patch had to follow the specification of the design doc for
> consistency, yet the naming seems pretty horrible in contrast to all the
> other dispatch table verbs :(
>
> Oh well, thats the way it is then. Perhaps the ddoc API can be refactored
> for CouchDB v2.0 with better consistency and efficiency, personally I'd
> like to see a simplified design document API, from the POV of implementing
> a query server.
>
> Right now it feels like lots of different mechanisms all mixed up together
> (e.g. stateful add_fun vs non-stateful ddoc).
>
> I guess I'd need to come up with a good alternative with significant
> improvements to warrant the change right? Are any other people thinking
> about this?
>
> Kind regards,
> Samuel
>
> On 22 July 2012 21:06, Alexander Shorin <kxepal@gmail.com> wrote:
>
>> > I couldn't see any reason why the name was changed..?
>>
>> Because validate function stored at "validate_doc_update" field within
>> ddoc, not "validate", so ddoc subcommand have to be same named.
>> Leaving subcommand as "validate" would break backward compatibility in
>> this case.
>>
>> --
>> ,,,^..^,,,
>>
>>
>> On Sun, Jul 22, 2012 at 1:02 PM, Samuel Williams
>> <space.ship.traveller@gmail.com> wrote:
>> > I can't see why "validate" is a problem, I checked the patch which
>> changed
>> > the name:
>> >
>> >
>> https://github.com/apache/couchdb/commit/ea3b1153e52ac1513da4d634eedefb05c261039c
>> >
>> > I couldn't see any reason why the name was changed..?
>> >
>> > Kind regards,
>> > Samuel
>> >
>> > On 22 July 2012 20:52, Alexander Shorin <kxepal@gmail.com> wrote:
>> >
>> >> Hi again(: No problems.
>> >>
>> >> On Sun, Jul 22, 2012 at 12:48 PM, Samuel Williams
>> >> <space.ship.traveller@gmail.com> wrote:
>> >> > Regarding the "1" result, I'm surprised that it isn't 'true', since
>> that
>> >> > would seem far more logical and match the rest of the protocol, e.g.
>> >> > 'reset', and various other commands.
>> >>
>> >> I suppose main decision was about how to easily understand what
>> >> response received for what command, but I could be wrong there.
>> >>
>> >> > I'm not sure I understand the motivation behind going from
>> "validate" to
>> >> > "validate_doc_update" - was it renamed to avoid collisions with
>> something
>> >> > else?
>> >>
>> >> You just need once to take a look at how ddoc command been processed
>> >> to figure "why so"(:
>> >> https://github.com/apache/couchdb/blob/master/share/server/loop.js#L69
>> >>
>> >> --
>> >> ,,,^..^,,,
>> >>
>> >>
>> >> On Sun, Jul 22, 2012 at 12:48 PM, Samuel Williams
>> >> <space.ship.traveller@gmail.com> wrote:
>> >> > Thanks again Alex, you are always so helpful - and the references you
>> >> > provide are really great.
>> >> >
>> >> > Regarding the "1" result, I'm surprised that it isn't 'true', since
>> that
>> >> > would seem far more logical and match the rest of the protocol, e.g.
>> >> > 'reset', and various other commands.
>> >> >
>> >> > I'm not sure I understand the motivation behind going from
>> "validate" to
>> >> > "validate_doc_update" - was it renamed to avoid collisions with
>> something
>> >> > else?
>> >> >
>> >> > On 22 July 2012 20:40, Alexander Shorin <kxepal@gmail.com> wrote:
>> >> >
>> >> >> Hi Samuel!
>> >> >>
>> >> >> > 1/ I'm wondering what are valid responses to validate_doc_update?
>> The
>> >> >> query
>> >> >> > services I've seen return either a hash {forbidden: "message"}
or
>> 1
>> >> >> >
>> >> >> > Can I return true rather than 1? Seems more logical..
>> >> >>
>> >> >> You could, but this would be invalid output. See for details:
>> >> >>
>> >> >>
>> >>
>> https://github.com/apache/couchdb/blob/master/src/couchdb/couch_query_servers.erl#L230
>> >> >>
>> >> >>
>> >> >> > 2/ Why is the name "validate_doc_update" so verbose when compared
>> with
>> >> >> > "lists", "filters", etc? Why not just "validates"?
>> >> >>
>> >> >> Initially it was "validate" command, but since any ddoc subcommand
>> is
>> >> >> a ddoc field, it eventually renamed to validate_doc_update.
>> >> >> See first commit about it:
>> >> >>
>> >> >>
>> >>
>> https://github.com/apache/couchdb/commit/9044fc0234ed65056f087a86c7c117922f2a2c75
>> >> >>
>> >> >> --
>> >> >> ,,,^..^,,,
>> >> >>
>> >> >>
>> >> >> On Sun, Jul 22, 2012 at 12:07 PM, Samuel Williams
>> >> >> <space.ship.traveller@gmail.com> wrote:
>> >> >> > Hi,
>> >> >> >
>> >> >> > 1/ I'm wondering what are valid responses to validate_doc_update?
>> The
>> >> >> query
>> >> >> > services I've seen return either a hash {forbidden: "message"}
or
>> 1
>> >> >> >
>> >> >> > Can I return true rather than 1? Seems more logical..
>> >> >> >
>> >> >> > How do I report multiple failures? e.g. Title required, Author
>> >> required.
>> >> >> >
>> >> >> > 2/ Why is the name "validate_doc_update" so verbose when compared
>> with
>> >> >> > "lists", "filters", etc? Why not just "validates"?
>> >> >> >
>> >> >> > Thanks,
>> >> >> > Samuel
>> >> >>
>> >>
>>
>
>

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message