incubator-couchdb-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Stephen Bartell <snbart...@gmail.com>
Subject Re: commonjs in validation docs
Date Mon, 03 Jun 2013 00:00:37 GMT
So I can't seem to get a validate_update_doc nested in a view field to work.  Heres a test
ddoc straight from my database.

This one won't work
```
{
   "_id": "_design/val",
   "language": "javascript",
   "views": {
       "validate_doc_update": "function(newdoc, olddoc, ctx, sec) {throw {forbidden: 'You
shall not pass.'}}" // this one doesn't work
   }
}
```

This one works fine.
```
{
   "_id": "_design/val",
   "language": "javascript",
   "validate_doc_update": "function(newdoc, olddoc, ctx, sec) {throw {forbidden: 'You shall
not pass.'}}"  // this one works fine.
}
```

Are you able to spot what I am doing wrong here? If I can get this to work, then I can use
cjs, which would be awesome.

Best
sb

On Jun 1, 2013, at 2:19 AM, Johannes Jörg Schmidt <schmidt@netzmerk.com> wrote:

> Yes, you can use CommonJS modules inside validate_doc_update functions.
> The docs are a bit misleading in this case.
> 
> {
>  "lib": {
>    "validation": "exports.presence = ..."
>  },
>  "validate_doc_update": "function(doc) {
> require('lib/validation').presence(doc, 'title') }"
> }
> 
> g jo
> Am 01.06.2013 03:14 schrieb "Stephen Bartell" <snbartell@gmail.com>:
> 
>> Hi all!
>> 
>> Can I use cjs modules in validate_doc_update functions?
>> 
>> I had a look through the docs at
>> http://couchdb.readthedocs.org/en/latest/query-servers.html#commonjs-modulesand it
seems to suggest that I can have a validate_doc_update function
>> inside a view field.  I tried this and the validation doesn't seem to run.
>> Is this supposed to work?
>> 
>> Thanks!


Mime
View raw message