You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@couchdb.apache.org by Marcello Nuccio <ma...@gmail.com> on 2011/10/04 10:35:41 UTC

Allowed contents of validate_doc_update field.

Is it supported to put anything other than an anonymous function in
the validate_doc_update field of a design document?

For example:

    var a = /bla/;
    function (doc, oldDoc, userCtx, secObj) {
        if (!a.test(doc._id)) ...
    }

is it supported or it can work only by coincidence.

Thanks,
  Marcello

Re: Allowed contents of validate_doc_update field.

Posted by Marcello Nuccio <ma...@gmail.com>.
2011/10/4 Jason Smith <jh...@iriscouch.com>:
> I would stick to a pure-function. What if you set `a = /not_bla/` in
> the function? But CouchDB might start many simultaneous Javascript
> processes, so you will not know the value of `a` later.
>
> I admit that sometimes I wish I could put constants and other things
> outside the function, for readability.

I'm not doing it for readability, or performance.
I'm trying to share common code between the client (browser), the
server (CouchDB), the backend, and support scripts (node.js).

Node and CouchDB have both CommonJS, but on the browser there's no
CommonJS, so I'm using RequireJS[1]. It works great, but I've not
managed to get it working with js-test-driver[2]. So, to get the job
done, in some places I'm doing file concatenation. And that is why
something is declared outside of validate_doc_update function.

[1]: http://requirejs.org/
[2]: http://code.google.com/p/js-test-driver/

> P.S. /regex/.test(str) does not work on some builds of CouchDB (or
> rather, some builds of Spidermonkey) which are still in use. It is
> safer to use str.match(/regex) which I also find less readable :)

Yes I know. I was about to submit a bug report a while ago, but
suddenly it started working an I forgot about it :-).

Thanks,
  Marcello


>
> On Tue, Oct 4, 2011 at 3:35 PM, Marcello Nuccio
> <ma...@gmail.com> wrote:
>> Is it supported to put anything other than an anonymous function in
>> the validate_doc_update field of a design document?
>>
>> For example:
>>
>>    var a = /bla/;
>>    function (doc, oldDoc, userCtx, secObj) {
>>        if (!a.test(doc._id)) ...
>>    }
>>
>> is it supported or it can work only by coincidence.
>>
>> Thanks,
>>  Marcello
>>
>
>
>
> --
> Iris Couch
>

Re: Allowed contents of validate_doc_update field.

Posted by Marcello Nuccio <ma...@gmail.com>.
With RequireJS I don't need a build step for the browser.
This is done only for production deployment using the RequireJS optimizer.

Marcello

2011/10/4 Sean Copenhaver <se...@gmail.com>:
> Ah, I have seen that in Kanso what they do is make you develop your couchapp
> in CommonJS modules then their push command packages it up into a design doc
> and an app.js for the browser.
>
> So you have node.js support right in the project directory (which could have
> a package.js with it) and a build step to get a couchdb and browser version.
> Not optimal sure but does give you what you want.
>
> On Tue, Oct 4, 2011 at 8:41 AM, Marcello Nuccio
> <ma...@gmail.com>wrote:
>
>> Yes, it works.
>> But I want to use the modules on the browser and I've managed to get
>> it working using RequireJS.
>> Unfortunately I have problems with js-test-driver, so right now I'm
>> doing file concatenation to get the job done.
>>
>> Marcello
>>
>> 2011/10/4 Sean Copenhaver <se...@gmail.com>:
>> > Do CommonJS modules work in validate_doc_update?
>> >
>> > On Tue, Oct 4, 2011 at 8:04 AM, Jason Smith <jh...@iriscouch.com> wrote:
>> >
>> >> I would stick to a pure-function. What if you set `a = /not_bla/` in
>> >> the function? But CouchDB might start many simultaneous Javascript
>> >> processes, so you will not know the value of `a` later.
>> >>
>> >> I admit that sometimes I wish I could put constants and other things
>> >> outside the function, for readability.
>> >>
>> >> P.S. /regex/.test(str) does not work on some builds of CouchDB (or
>> >> rather, some builds of Spidermonkey) which are still in use. It is
>> >> safer to use str.match(/regex) which I also find less readable :)
>> >>
>> >> On Tue, Oct 4, 2011 at 3:35 PM, Marcello Nuccio
>> >> <ma...@gmail.com> wrote:
>> >> > Is it supported to put anything other than an anonymous function in
>> >> > the validate_doc_update field of a design document?
>> >> >
>> >> > For example:
>> >> >
>> >> >    var a = /bla/;
>> >> >    function (doc, oldDoc, userCtx, secObj) {
>> >> >        if (!a.test(doc._id)) ...
>> >> >    }
>> >> >
>> >> > is it supported or it can work only by coincidence.
>> >> >
>> >> > Thanks,
>> >> >  Marcello
>> >> >
>> >>
>> >>
>> >>
>> >> --
>> >> Iris Couch
>> >>
>> >
>> >
>> >
>> > --
>> > “The limits of language are the limits of one's world. “ - Ludwig von
>> > Wittgenstein
>> >
>> > "Water is fluid, soft and yielding. But water will wear away rock, which
>> is
>> > rigid and cannot yield. As a rule, whatever is fluid, soft and yielding
>> will
>> > overcome whatever is rigid and hard. This is another paradox: what is
>> soft
>> > is strong." - Lao-Tzu
>> >
>>
>
>
>
> --
> “The limits of language are the limits of one's world. “ - Ludwig von
> Wittgenstein
>
> "Water is fluid, soft and yielding. But water will wear away rock, which is
> rigid and cannot yield. As a rule, whatever is fluid, soft and yielding will
> overcome whatever is rigid and hard. This is another paradox: what is soft
> is strong." - Lao-Tzu
>

Re: Allowed contents of validate_doc_update field.

Posted by Sean Copenhaver <se...@gmail.com>.
Ah, I have seen that in Kanso what they do is make you develop your couchapp
in CommonJS modules then their push command packages it up into a design doc
and an app.js for the browser.

So you have node.js support right in the project directory (which could have
a package.js with it) and a build step to get a couchdb and browser version.
Not optimal sure but does give you what you want.

On Tue, Oct 4, 2011 at 8:41 AM, Marcello Nuccio
<ma...@gmail.com>wrote:

> Yes, it works.
> But I want to use the modules on the browser and I've managed to get
> it working using RequireJS.
> Unfortunately I have problems with js-test-driver, so right now I'm
> doing file concatenation to get the job done.
>
> Marcello
>
> 2011/10/4 Sean Copenhaver <se...@gmail.com>:
> > Do CommonJS modules work in validate_doc_update?
> >
> > On Tue, Oct 4, 2011 at 8:04 AM, Jason Smith <jh...@iriscouch.com> wrote:
> >
> >> I would stick to a pure-function. What if you set `a = /not_bla/` in
> >> the function? But CouchDB might start many simultaneous Javascript
> >> processes, so you will not know the value of `a` later.
> >>
> >> I admit that sometimes I wish I could put constants and other things
> >> outside the function, for readability.
> >>
> >> P.S. /regex/.test(str) does not work on some builds of CouchDB (or
> >> rather, some builds of Spidermonkey) which are still in use. It is
> >> safer to use str.match(/regex) which I also find less readable :)
> >>
> >> On Tue, Oct 4, 2011 at 3:35 PM, Marcello Nuccio
> >> <ma...@gmail.com> wrote:
> >> > Is it supported to put anything other than an anonymous function in
> >> > the validate_doc_update field of a design document?
> >> >
> >> > For example:
> >> >
> >> >    var a = /bla/;
> >> >    function (doc, oldDoc, userCtx, secObj) {
> >> >        if (!a.test(doc._id)) ...
> >> >    }
> >> >
> >> > is it supported or it can work only by coincidence.
> >> >
> >> > Thanks,
> >> >  Marcello
> >> >
> >>
> >>
> >>
> >> --
> >> Iris Couch
> >>
> >
> >
> >
> > --
> > “The limits of language are the limits of one's world. “ - Ludwig von
> > Wittgenstein
> >
> > "Water is fluid, soft and yielding. But water will wear away rock, which
> is
> > rigid and cannot yield. As a rule, whatever is fluid, soft and yielding
> will
> > overcome whatever is rigid and hard. This is another paradox: what is
> soft
> > is strong." - Lao-Tzu
> >
>



-- 
“The limits of language are the limits of one's world. “ - Ludwig von
Wittgenstein

"Water is fluid, soft and yielding. But water will wear away rock, which is
rigid and cannot yield. As a rule, whatever is fluid, soft and yielding will
overcome whatever is rigid and hard. This is another paradox: what is soft
is strong." - Lao-Tzu

Re: Allowed contents of validate_doc_update field.

Posted by Marcello Nuccio <ma...@gmail.com>.
Yes, it works.
But I want to use the modules on the browser and I've managed to get
it working using RequireJS.
Unfortunately I have problems with js-test-driver, so right now I'm
doing file concatenation to get the job done.

Marcello

2011/10/4 Sean Copenhaver <se...@gmail.com>:
> Do CommonJS modules work in validate_doc_update?
>
> On Tue, Oct 4, 2011 at 8:04 AM, Jason Smith <jh...@iriscouch.com> wrote:
>
>> I would stick to a pure-function. What if you set `a = /not_bla/` in
>> the function? But CouchDB might start many simultaneous Javascript
>> processes, so you will not know the value of `a` later.
>>
>> I admit that sometimes I wish I could put constants and other things
>> outside the function, for readability.
>>
>> P.S. /regex/.test(str) does not work on some builds of CouchDB (or
>> rather, some builds of Spidermonkey) which are still in use. It is
>> safer to use str.match(/regex) which I also find less readable :)
>>
>> On Tue, Oct 4, 2011 at 3:35 PM, Marcello Nuccio
>> <ma...@gmail.com> wrote:
>> > Is it supported to put anything other than an anonymous function in
>> > the validate_doc_update field of a design document?
>> >
>> > For example:
>> >
>> >    var a = /bla/;
>> >    function (doc, oldDoc, userCtx, secObj) {
>> >        if (!a.test(doc._id)) ...
>> >    }
>> >
>> > is it supported or it can work only by coincidence.
>> >
>> > Thanks,
>> >  Marcello
>> >
>>
>>
>>
>> --
>> Iris Couch
>>
>
>
>
> --
> “The limits of language are the limits of one's world. “ - Ludwig von
> Wittgenstein
>
> "Water is fluid, soft and yielding. But water will wear away rock, which is
> rigid and cannot yield. As a rule, whatever is fluid, soft and yielding will
> overcome whatever is rigid and hard. This is another paradox: what is soft
> is strong." - Lao-Tzu
>

Re: Allowed contents of validate_doc_update field.

Posted by Sean Copenhaver <se...@gmail.com>.
Do CommonJS modules work in validate_doc_update?

On Tue, Oct 4, 2011 at 8:04 AM, Jason Smith <jh...@iriscouch.com> wrote:

> I would stick to a pure-function. What if you set `a = /not_bla/` in
> the function? But CouchDB might start many simultaneous Javascript
> processes, so you will not know the value of `a` later.
>
> I admit that sometimes I wish I could put constants and other things
> outside the function, for readability.
>
> P.S. /regex/.test(str) does not work on some builds of CouchDB (or
> rather, some builds of Spidermonkey) which are still in use. It is
> safer to use str.match(/regex) which I also find less readable :)
>
> On Tue, Oct 4, 2011 at 3:35 PM, Marcello Nuccio
> <ma...@gmail.com> wrote:
> > Is it supported to put anything other than an anonymous function in
> > the validate_doc_update field of a design document?
> >
> > For example:
> >
> >    var a = /bla/;
> >    function (doc, oldDoc, userCtx, secObj) {
> >        if (!a.test(doc._id)) ...
> >    }
> >
> > is it supported or it can work only by coincidence.
> >
> > Thanks,
> >  Marcello
> >
>
>
>
> --
> Iris Couch
>



-- 
“The limits of language are the limits of one's world. “ - Ludwig von
Wittgenstein

"Water is fluid, soft and yielding. But water will wear away rock, which is
rigid and cannot yield. As a rule, whatever is fluid, soft and yielding will
overcome whatever is rigid and hard. This is another paradox: what is soft
is strong." - Lao-Tzu

Re: Allowed contents of validate_doc_update field.

Posted by Jason Smith <jh...@iriscouch.com>.
I would stick to a pure-function. What if you set `a = /not_bla/` in
the function? But CouchDB might start many simultaneous Javascript
processes, so you will not know the value of `a` later.

I admit that sometimes I wish I could put constants and other things
outside the function, for readability.

P.S. /regex/.test(str) does not work on some builds of CouchDB (or
rather, some builds of Spidermonkey) which are still in use. It is
safer to use str.match(/regex) which I also find less readable :)

On Tue, Oct 4, 2011 at 3:35 PM, Marcello Nuccio
<ma...@gmail.com> wrote:
> Is it supported to put anything other than an anonymous function in
> the validate_doc_update field of a design document?
>
> For example:
>
>    var a = /bla/;
>    function (doc, oldDoc, userCtx, secObj) {
>        if (!a.test(doc._id)) ...
>    }
>
> is it supported or it can work only by coincidence.
>
> Thanks,
>  Marcello
>



-- 
Iris Couch