couchdb-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Scott Weber <>
Subject Re: Design docs and javascript function unreadable...?
Date Thu, 20 Dec 2012 01:32:39 GMT
I am looking at the JSON string because FUTON is the only tool I have that gives 
me an interface.

I also took the JSON dos and put it in a file, and used curl to upload it.  It 
still rejects it.

In both cases, these are the only tools I am aware of. They are the only things 
described in the tutorial book.  They are the instructions I am following.

The online book functions all have newlines, tabs, comments, etc...  It is only 
natural that someone reading it would copy and paste them into the design doc in 
order to test.

My example design doc is below.  It only can be installed (using FUTON or curl) 
when all the whitespace is stripped out manually by me.

I cannot see how manually creating a slightly more complex function then these 
examples would not be begging for mistakes when forced to de-beautify it 
manually for loading in through FUTON or curl.

There is no way to just tell "validate_doc_update" to load a function from a 
whatever.js file?  So the function can remain readable?

   "_id": "_design/example",
   "_rev": "4-942673df70142b3c1d181628f93e1184",
"function(newDoc, oldDoc, userCtx) {
function require(field, message) { 
message = message ||  field; 
throw({forbidden : message});
if (!newDoc.session) { return;  } // if it's not a session document...
if (newdoc.BoxNumber && (newdoc.BoxNumber) != oldDoc.BoxNumber)) {
require('BoxNumber','Box Number cannot change');
   "views": {
       "foo": {
           "map": "function(doc){ emit(doc._id, doc._rev)}"

----- Original Message ----
From: Mark Hahn <>
To: user <>
Sent: Wed, December 19, 2012 6:29:54 PM
Subject: Re: Design docs and javascript function unreadable...?


It is stored as json and control chars aren't allowed in json strings.
All tools should handle the conversion in and out.  Futon handles it
fine.  My custom scripts handle it fine.  Why would you be looking at
the json string directly?

On Wed, Dec 19, 2012 at 4:08 PM, Scott Weber <> wrote:
> Clearly, this can't be the way it is supposed to behave.
> I must be missing something, somewhere...
> In a design doc, I put a function to validate.  I used to validate_doc_update
> key of the design JSON.  All taken from examples in the guide. Then I found
> out...
> The javascript in the design doc cannot have newlines..?  cannot have tabs..?
> Cannot be formatted so that it's readable..?  Seriously?
> There has to be a way to put readable code into this.  What am I missing?  All
> the code in the "The Definitive Guide' is loaded with comments, line breaks,
> etc...
> -Scott

View raw message