You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@couchdb.apache.org by ja...@apache.org on 2013/10/03 17:50:51 UTC
[01/17] git commit: updated refs/heads/master to 532100c
Updated Branches:
refs/heads/master 3e19db216 -> 532100c10
add files to license.skip
Project: http://git-wip-us.apache.org/repos/asf/couchdb/repo
Commit: http://git-wip-us.apache.org/repos/asf/couchdb/commit/12763ee4
Tree: http://git-wip-us.apache.org/repos/asf/couchdb/tree/12763ee4
Diff: http://git-wip-us.apache.org/repos/asf/couchdb/diff/12763ee4
Branch: refs/heads/master
Commit: 12763ee4b51780f793ce213ca2ae7a99da055f2c
Parents: 0595c5e
Author: Jan Lehnardt <ja...@apache.org>
Authored: Sat Sep 21 16:24:20 2013 +0200
Committer: Jan Lehnardt <ja...@apache.org>
Committed: Thu Oct 3 17:21:29 2013 +0200
----------------------------------------------------------------------
license.skip | 2 ++
1 file changed, 2 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/couchdb/blob/12763ee4/license.skip
----------------------------------------------------------------------
diff --git a/license.skip b/license.skip
index 067fce3..d87cc6c 100644
--- a/license.skip
+++ b/license.skip
@@ -109,6 +109,8 @@
^src/couchdb/priv/couchjs
^src/couchdb/priv/couchspawnkillable
^src/couchdb/priv/stat_descriptions.cfg
+^src/couchjs-node/package.json
+^src/couchjs-node/README.md
^src/erlang-oauth/.*
^src/couch_dbupdates
^src/ejson/.*
[16/17] git commit: updated refs/heads/master to 532100c
Posted by ja...@apache.org.
move module exports past function decrarations
Project: http://git-wip-us.apache.org/repos/asf/couchdb/repo
Commit: http://git-wip-us.apache.org/repos/asf/couchdb/commit/447f101d
Tree: http://git-wip-us.apache.org/repos/asf/couchdb/tree/447f101d
Diff: http://git-wip-us.apache.org/repos/asf/couchdb/diff/447f101d
Branch: refs/heads/master
Commit: 447f101d3245e18384cddfedc10277ff7fe2647b
Parents: 0902e8c
Author: Sven Lito <me...@svenlito.com>
Authored: Thu Oct 3 16:33:11 2013 +0100
Committer: Jan Lehnardt <ja...@apache.org>
Committed: Thu Oct 3 17:45:40 2013 +0200
----------------------------------------------------------------------
src/couchjs-node/couchjs.js | 18 ++++++++++--------
1 file changed, 10 insertions(+), 8 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/couchdb/blob/447f101d/src/couchjs-node/couchjs.js
----------------------------------------------------------------------
diff --git a/src/couchjs-node/couchjs.js b/src/couchjs-node/couchjs.js
index 7b12dc3..84c21e0 100644
--- a/src/couchjs-node/couchjs.js
+++ b/src/couchjs-node/couchjs.js
@@ -10,14 +10,6 @@
// License for the specific language governing permissions and limitations under
// the License.
-module.exports = {
- 'print': print,
- 'readline': readline,
- 'stdin': stdin,
- 'evalcx': evalcx,
- 'quit': quit,
- 'gc': gc
-};
var vm = require('vm');
@@ -127,3 +119,13 @@ function toSource() {
return util.inspect(this);
}
+
+module.exports = {
+ 'print': print,
+ 'readline': readline,
+ 'stdin': stdin,
+ 'evalcx': evalcx,
+ 'quit': quit,
+ 'gc': gc
+};
+
[15/17] git commit: updated refs/heads/master to 532100c
Posted by ja...@apache.org.
applied formatting for constancy
Project: http://git-wip-us.apache.org/repos/asf/couchdb/repo
Commit: http://git-wip-us.apache.org/repos/asf/couchdb/commit/0902e8c5
Tree: http://git-wip-us.apache.org/repos/asf/couchdb/tree/0902e8c5
Diff: http://git-wip-us.apache.org/repos/asf/couchdb/diff/0902e8c5
Branch: refs/heads/master
Commit: 0902e8c5e8f7e66eecfacbdb266422d51f8cafc3
Parents: 2d7da55
Author: Sven Lito <me...@svenlito.com>
Authored: Thu Oct 3 09:23:07 2013 +0100
Committer: Jan Lehnardt <ja...@apache.org>
Committed: Thu Oct 3 17:45:38 2013 +0200
----------------------------------------------------------------------
src/couchjs-node/cli.js | 96 +++++++++++--------
src/couchjs-node/console.js | 73 +++++++-------
src/couchjs-node/couchdb.js | 20 ++--
src/couchjs-node/couchjs.js | 133 ++++++++++++++------------
src/couchjs-node/inspector.js | 111 +++++++++++----------
src/couchjs-node/package.json | 68 +++++++------
src/couchjs-node/sandbox.js | 23 +++--
src/couchjs-node/stream.js | 106 +++++++++++----------
src/couchjs-node/test/experiment.js | 159 ++++++++++++++++---------------
src/couchjs-node/xml.js | 9 +-
10 files changed, 441 insertions(+), 357 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/couchdb/blob/0902e8c5/src/couchjs-node/cli.js
----------------------------------------------------------------------
diff --git a/src/couchjs-node/cli.js b/src/couchjs-node/cli.js
index 8b7abef..065951f 100755
--- a/src/couchjs-node/cli.js
+++ b/src/couchjs-node/cli.js
@@ -12,64 +12,80 @@
// License for the specific language governing permissions and limitations under
// the License.
-var fs = require('fs')
-var util = require('util')
-var Fiber = require('fibers')
-var optimist = require('optimist')
-var child_process = require('child_process')
+var fs = require('fs');
+var util = require('util');
+var Fiber = require('fibers');
+var optimist = require('optimist');
+var child_process = require('child_process');
-var couchjs = require('./couchjs')
-var package_json = require('./package.json')
-var LineStream = require('./stream')
-var inspector = require('./inspector')
-var log = require('./console').log
+var couchjs = require('./couchjs');
+var package_json = require('./package.json');
+var LineStream = require('./stream');
+var inspector = require('./inspector');
+var log = require('./console').log;
var opts = optimist.boolean(['h', 'V', 'H'])
- .describe({ 'h': 'display a short help message and exit'
- , 'V': 'display version information and exit'
- , 'H': 'enable couchjs cURL bindings (not implemented)'
+ .describe({ 'h': 'display a short help message and exit',
+ 'V': 'display version information and exit',
+ 'H': 'enable couchjs cURL bindings (not implemented)'
})
- .usage('$0 <path to main.js>')
+ .usage('$0 <path to main.js>');
function main() {
- var main_js = opts.argv._[0]
- if(!main_js)
- return console.error(opts.help())
- log('couchjs/%s %s: %s', package_json.version, process.pid, main_js)
- if(process.env.COUCHJS_DEBUG_PORT)
- inspector(+process.env.COUCHJS_DEBUG_PORT)
+ 'use strict';
+
+ var main_js = opts.argv._[0];
+
+ if (!main_js) {
+ return console.error(opts.help());
+ }
+
+ log('couchjs/%s %s: %s', package_json.version, process.pid, main_js);
+
+ if (process.env.COUCHJS_DEBUG_PORT) {
+ inspector(+process.env.COUCHJS_DEBUG_PORT);
+ }
fs.readFile(main_js, 'utf8', function(er, body) {
- if(er)
- throw er
+ if (er) {
+ throw er;
+ }
+
+ var stdin = new LineStream.v2();
- var stdin = new LineStream.v2
stdin.on('readable', function() {
- var buf = stdin.read()
- if(buf)
- couchjs.stdin(buf)
- })
+ var buf = stdin.read();
+
+ if (buf) {
+ couchjs.stdin(buf);
+ }
+ });
+
stdin.on('end', function() {
- log('Terminate; connection to parent closed')
- process.exit(0)
- })
+ log('Terminate; connection to parent closed');
+ process.exit(0);
+ });
- process.stdin.setEncoding('utf8')
- process.stdin.pipe(stdin)
+ process.stdin.setEncoding('utf8');
+ process.stdin.pipe(stdin);
- var main_func = Function(['print', 'readline', 'evalcx', 'gc', 'quit'], body)
+ var main_func = Function(['print', 'readline', 'evalcx', 'gc', 'quit'], body);
- log('Call main')
- Fiber(function() { main_func(couchjs.print, couchjs.readline, couchjs.evalcx, couchjs.gc) }).run()
- })
+ log('Call main');
+
+ new Fiber(function() {
+ main_func(couchjs.print, couchjs.readline, couchjs.evalcx, couchjs.gc);
+ }).run();
+ });
process.on('uncaughtException', function(er) {
- log('Error:\n%s', er.stack)
- })
+ log('Error:\n%s', er.stack);
+ });
}
-if(require.main === module)
- main()
+if (require.main === module) {
+ main();
+}
http://git-wip-us.apache.org/repos/asf/couchdb/blob/0902e8c5/src/couchjs-node/console.js
----------------------------------------------------------------------
diff --git a/src/couchjs-node/console.js b/src/couchjs-node/console.js
index 67cc32d..0fda066 100644
--- a/src/couchjs-node/console.js
+++ b/src/couchjs-node/console.js
@@ -10,54 +10,57 @@
// License for the specific language governing permissions and limitations under
// the License.
-var fs = require('fs')
-var util = require('util')
+var fs = require('fs');
+var util = require('util');
+var noop = function() {};
-module.exports = {}
-module.exports.log = noop
-module.exports.debug = noop
-module.exports.info = noop
-module.exports.warn = noop
-module.exports.error = noop
+module.exports = {};
+module.exports.log = noop;
+module.exports.debug = noop;
+module.exports.info = noop;
+module.exports.warn = noop;
+module.exports.error = noop;
-var LOG_PATH = '/tmp/couchjs.log'
- , stat = null
- , LOG = null
+var LOG_PATH = '/tmp/couchjs.log';
+var stat = null;
+var LOG = null;
try {
- stat = fs.statSync(LOG_PATH)
+ stat = fs.statSync(LOG_PATH);
} catch(er) {}
-if(stat) {
- LOG = fs.createWriteStream(LOG_PATH, {'flags':'a'})
+if (stat) {
+ LOG = fs.createWriteStream(LOG_PATH, {
+ 'flags':'a'
+ });
- module.exports.log = log
- module.exports.debug = log
- module.exports.info = log
- module.exports.warn = log
- module.exports.error = log
+ var log = function () {
+ var str = util.format.apply(this, arguments);
+ LOG.write(str + '\n');
+ };
- process.on('exit', function() {
- module.exports.log('Exit %d', process.pid)
- })
+ var on_err = function (er) {
+ module.exports.error('Uncaught error:\n%s', er.stack || er.message || JSON.stringify(er))
- process.on('uncaughtException', on_err)
-}
+ if (er.stack) {
+ er = ['fatal', 'unknown_error', er.stack];
+ }
-function log() {
- var str = util.format.apply(this, arguments)
- LOG.write(str + '\n')
-}
+ process.stdout.write(JSON.stringify(er) + '\n');
+ process.exit(1);
+ };
-function on_err(er) {
- module.exports.error('Uncaught error:\n%s', er.stack || er.message || JSON.stringify(er))
+ module.exports.log = log;
+ module.exports.debug = log;
+ module.exports.info = log;
+ module.exports.warn = log;
+ module.exports.error = log;
- if(er.stack)
- er = ['fatal', 'unknown_error', er.stack]
+ process.on('exit', function() {
+ module.exports.log('Exit %d', process.pid);
+ });
- process.stdout.write(JSON.stringify(er) + '\n')
- process.exit(1)
+ process.on('uncaughtException', on_err);
}
-function noop() {}
http://git-wip-us.apache.org/repos/asf/couchdb/blob/0902e8c5/src/couchjs-node/couchdb.js
----------------------------------------------------------------------
diff --git a/src/couchjs-node/couchdb.js b/src/couchjs-node/couchdb.js
index 46b23b0..d420540 100755
--- a/src/couchjs-node/couchdb.js
+++ b/src/couchjs-node/couchdb.js
@@ -10,18 +10,20 @@
// License for the specific language governing permissions and limitations under
// the License.
-module.exports = handler
-var http = require('http')
+var http = require('http');
function handler(req, res) {
- res.writeHead(200)
- res.end('Hello: ' + req.url + '\n')
+ res.writeHead(200);
+ res.end('Hello: ' + req.url + '\n');
}
-if(require.main === module) {
- var http = require('http')
- var server = http.createServer(handler)
- server.listen(3000)
- console.log('Listening on :3000')
+if (require.main === module) {
+ var http = require('http');
+ var server = http.createServer(handler);
+
+ server.listen(3000);
+ console.log('Listening on :3000');
}
+
+module.exports = handler;
http://git-wip-us.apache.org/repos/asf/couchdb/blob/0902e8c5/src/couchjs-node/couchjs.js
----------------------------------------------------------------------
diff --git a/src/couchjs-node/couchjs.js b/src/couchjs-node/couchjs.js
index b633f6f..7b12dc3 100644
--- a/src/couchjs-node/couchjs.js
+++ b/src/couchjs-node/couchjs.js
@@ -10,105 +10,120 @@
// License for the specific language governing permissions and limitations under
// the License.
-module.exports = { 'print' : print
- , 'readline': readline
- , 'stdin' : stdin
- , 'evalcx' : evalcx
- , 'quit' : quit
- , 'gc' : gc
- }
+module.exports = {
+ 'print': print,
+ 'readline': readline,
+ 'stdin': stdin,
+ 'evalcx': evalcx,
+ 'quit': quit,
+ 'gc': gc
+};
-var vm = require('vm')
-var Fiber = require('fibers')
+var vm = require('vm');
+var Fiber = require('fibers');
-var XML = require('./xml')
-var log = require('./console').log
+var XML = require('./xml');
+var log = require('./console').log;
-var INPUT = {'queue':[], 'waiting':null}
+var INPUT = {
+ 'queue':[],
+ 'waiting':null
+};
-Error.prototype.toSource = Error.prototype.toSource || toSource
-Error.prototype.toString = Error.prototype.toString || toSource
-Function.prototype.toSource = Function.prototype.toSource || toSource
-Function.prototype.toString = Function.prototype.toString || toSource
+Error.prototype.toSource = Error.prototype.toSource || toSource;
+Error.prototype.toString = Error.prototype.toString || toSource;
+Function.prototype.toSource = Function.prototype.toSource || toSource;
+Function.prototype.toString = Function.prototype.toString || toSource;
function print(line) {
- log('STDOUT %s: %s', process.pid, line)
- process.stdout.write(line + '\n')
+ log('STDOUT %s: %s', process.pid, line);
+ process.stdout.write(line + '\n');
try {
- line = JSON.parse(line)
- } catch(er) { return }
+ line = JSON.parse(line);
+ } catch(er) {
+ return;
+ }
- if(line[0] == 'log')
- log('LOG: %s', line[1])
+ if (line[0] === 'log') {
+ log('LOG: %s', line[1]);
+ }
}
-function stdin(line) {
- log('STDIN %s: %s', process.pid, line.trim())
- if(INPUT.waiting)
- INPUT.waiting.run(line)
- else
- INPUT.queue.push(line)
+function stdin (line) {
+ log('STDIN %s: %s', process.pid, line.trim());
+
+ if (INPUT.waiting) {
+ INPUT.waiting.run(line);
+ } else {
+ INPUT.queue.push(line);
+ }
}
-function readline() {
- var line = INPUT.queue.shift()
- if(line)
- return line
+function readline () {
+ var line = INPUT.queue.shift();
+
+ if (line) {
+ return line;
+ }
- INPUT.waiting = Fiber.current
- line = Fiber.yield()
- INPUT.waiting = null
+ INPUT.waiting = Fiber.current;
+ line = Fiber.yield();
+ INPUT.waiting = null;
- return line
+ return line;
}
-function evalcx(source, sandbox) {
- sandbox = sandbox || {}
+function evalcx (source, sandbox) {
+ sandbox = sandbox || {};
//log('evalcx in %j: %j', Object.keys(sandbox), source)
- if(source == '')
- return sandbox
+ if (source == '') {
+ return sandbox;
+ }
// source might be "function(doc) { emit(doc._id, 1) }"
- source = source.replace(/;+$/, '')
+ source = source.replace(/;+$/, '');
- sandbox.XML = sandbox.XML || XML
- source = '(' + source + ')'
+ sandbox.XML = sandbox.XML || XML;
+ source = '(' + source + ')';
try {
- var id = Math.floor(Math.random() * 1000*1000)
- var filename = '_couchdb:' + id + '.js'
- var script = vm.createScript(source, filename)
- var func = script.runInNewContext(sandbox)
+ var id = Math.floor(Math.random() * 1000*1000);
+ var filename = '_couchdb:' + id + '.js';
+ var script = vm.createScript(source, filename);
+ var func = script.runInNewContext(sandbox);
} catch (er) {
- log('Error making code: %s', er.stack)
- return sandbox
+ log('Error making code: %s', er.stack);
+ return sandbox;
}
- return func
+ return func;
}
function quit(code) {
- code = code || 1
- if(code < 0)
- code = -code
+ code = code || 1;
+ if (code < 0) {
+ code = -code;
+ }
- process.exit(code)
+ process.exit(code);
}
function gc() { }
function toSource() {
- if(typeof this == 'function')
- return '' + this
+ if (typeof this == 'function') {
+ return '' + this;
+ }
- if(this instanceof Error)
- return this.stack
+ if (this instanceof Error) {
+ return this.stack;
+ }
- return util.inspect(this)
+ return util.inspect(this);
}
http://git-wip-us.apache.org/repos/asf/couchdb/blob/0902e8c5/src/couchjs-node/inspector.js
----------------------------------------------------------------------
diff --git a/src/couchjs-node/inspector.js b/src/couchjs-node/inspector.js
index 2b75c3b..343770f 100755
--- a/src/couchjs-node/inspector.js
+++ b/src/couchjs-node/inspector.js
@@ -12,77 +12,92 @@
// License for the specific language governing permissions and limitations under
// the License.
-module.exports = start
+module.exports = start;
-if(require.main === module)
- main()
+if (require.main === module) {
+ main();
+}
+
+
+var fs = require('fs');
+var util = require('util');
+var child_process = require('child_process');
+var log = require('./console').log;
+function start (debugPort) {
-var fs = require('fs')
-var util = require('util')
-var child_process = require('child_process')
+ if (!debugPort || typeof debugPort !== 'number') {
+ throw new Error('Need a listen debugPort');
+ }
-var log = require('./console').log
+ var webPort = debugPort + 1;
-function start(debugPort) {
- if(!debugPort || typeof debugPort != 'number')
- throw new Error('Need a listen debugPort')
- var webPort = debugPort + 1
+ var cmd = __filename;
+ var args = [debugPort, webPort];
+ var opts = {
+ 'cwd': __dirname,
+ 'stdio': 'pipe',
+ 'detached': false
+ };
- var cmd = __filename
- var args = [debugPort, webPort]
- var opts =
- { 'cwd': __dirname
- , 'stdio': 'pipe'
- , 'detached': false
- }
+ log('Start inspector: %s %j %j', cmd, args, opts);
- log('Start inspector: %s %j %j', cmd, args, opts)
- var inspector = child_process.spawn(cmd, args, opts)
- watch_inspector(inspector)
+ var inspector = child_process.spawn(cmd, args, opts);
- log('Enable remote debug pid=%d port=%d', process.pid, debugPort)
- process.debugPort = debugPort
- process.kill(process.pid, 'SIGUSR1')
+ watch_inspector(inspector);
+
+ log('Enable remote debug pid=%d port=%d', process.pid, debugPort);
+
+ process.debugPort = debugPort;
+ process.kill(process.pid, 'SIGUSR1');
}
function watch_inspector(child) {
+
child.stderr.on('data', function(body) {
- log('Inspector STDERR: %s', body)
- })
+ log('Inspector STDERR: %s', body);
+ });
+
child.stdout.on('data', function(body) {
- log('Inspector STDOUT: %s', body)
- })
+ log('Inspector STDOUT: %s', body);
+ });
child.on('exit', function(code, signal) {
- log('Inspector exited %d signal=%j', code, signal)
- process.exit(code)
- })
+ log('Inspector exited %d signal=%j', code, signal);
+ process.exit(code);
+ });
process.on('exit', function() {
- log('Kill inspector upon exit: %d', child.pid)
- process.kill(child.pid, 'SIGTERM')
- })
-}
+ log('Kill inspector upon exit: %d', child.pid);
+ process.kill(child.pid, 'SIGTERM');
+ });
+}
function main() {
- var debugPort = +process.argv[2]
- var webPort = +process.argv[3]
+ var debugPort = +process.argv[2];
+ var webPort = +process.argv[3];
- if(!debugPort || !webPort)
- throw new Error('Bad arguments: need debugPort and webPort')
+ if (!debugPort || !webPort) {
+ throw new Error('Bad arguments: need debugPort and webPort');
+ }
+
+ console.log('Start inspector debugPort=%j webPort=%j', debugPort, webPort);
+
+ var DebugServer = require('node-inspector/lib/debug-server');
+ var server = new DebugServer();
- console.log('Start inspector debugPort=%j webPort=%j', debugPort, webPort)
- var DebugServer = require('node-inspector/lib/debug-server')
- var server = new DebugServer
server.on('close', function() {
- console.log('Server closed')
- process.exit(0)
- })
+ console.log('Server closed');
+ process.exit(0);
+ });
+
+ server.start({
+ 'webPort':webPort,
+ 'debugPort':debugPort
+ });
- server.start({'webPort':webPort, 'debugPort':debugPort})
process.on('uncaughtException', function(er) {
- console.log('Error:\n%s', er.stack)
- })
+ console.log('Error:\n%s', er.stack);
+ });
}
http://git-wip-us.apache.org/repos/asf/couchdb/blob/0902e8c5/src/couchjs-node/package.json
----------------------------------------------------------------------
diff --git a/src/couchjs-node/package.json b/src/couchjs-node/package.json
index 5e8ade0..445f3b9 100644
--- a/src/couchjs-node/package.json
+++ b/src/couchjs-node/package.json
@@ -1,30 +1,40 @@
-{ "name": "couchjs"
-, "description": "Drop-in replacement for CouchDB JavaScript view server"
-, "keywords": [ "couchdb", "couchjs" ]
-, "version": "0.3.2"
-, "author": "Jason Smith <jh...@iriscouch.com> (http://www.iriscouch.com)"
-, "repository": { "type":"git", "url":"https://github.com/iriscouch/couchjs" }
-
-, "engines": { "node": ">= 0.8" }
-, "main": "./couchjs.js"
-, "bin": {"couchjs-node":"./cli.js"}
-
-, "couchdb": { "main":"./couchdb.js"
- , "vhosts": ["127.0.0.1.xip.io"]
- }
-
-, "bundledDependencies": ["node-inspector"]
-
-, "dependencies": { "optimist": "~0.3.4"
- , "async" : "~0.2.5"
- , "mkdirp" : "~0.3.4"
- , "fibers" : "~1.0.0"
- , "request" : "~2.9.203"
- , "pushover": "~1.2.1"
- , "defaultable": "~0.7.2"
- , "node-inspector": "git://github.com/iriscouch/node-inspector#couchjs"
- }
-
-, "devDependencies": { "tap": "~0.2.5"
- }
+{
+ "name": "couchjs",
+ "description": "Drop-in replacement for CouchDB JavaScript view server",
+ "keywords": [ "couchdb", "couchjs" ],
+ "version": "0.3.2",
+ "author": "Jason Smith <jh...@iriscouch.com> (http://www.iriscouch.com)",
+ "repository": {
+ "type":"git",
+ "url":"https://github.com/iriscouch/couchjs"
+ },
+ "engines": {
+ "node": ">= 0.8"
+ },
+ "main": "./couchjs.js",
+ "bin": {
+ "couchjs-node":"./cli.js"
+ },
+ "couchdb": {
+ "main":"./couchdb.js",
+ "vhosts": [
+ "127.0.0.1.xip.io"
+ ]
+ },
+ "bundledDependencies": [
+ "node-inspector"
+ ],
+ "dependencies": {
+ "optimist": "~0.3.4",
+ "async" : "~0.2.5",
+ "mkdirp" : "~0.3.4",
+ "fibers" : "~1.0.0",
+ "request" : "~2.9.203",
+ "pushover": "~1.2.1",
+ "defaultable": "~0.7.2",
+ "node-inspector": "git://github.com/iriscouch/node-inspector#couchjs"
+ },
+ "devDependencies": {
+ "tap": "~0.2.5"
+ }
}
http://git-wip-us.apache.org/repos/asf/couchdb/blob/0902e8c5/src/couchjs-node/sandbox.js
----------------------------------------------------------------------
diff --git a/src/couchjs-node/sandbox.js b/src/couchjs-node/sandbox.js
index cfdff18..5c18ef4 100644
--- a/src/couchjs-node/sandbox.js
+++ b/src/couchjs-node/sandbox.js
@@ -1,21 +1,28 @@
// from https://github.com/KlausTrainer/sandbox.js
exports.runInSandbox = function(src, ctx, whitelist) {
- var vm = require('vm'),
- sandbox;
+ var vm = require('vm');
+ var sandbox;
if (ctx && ctx.require) {
+
whitelist = whitelist || [];
- var insecureRequire = ctx.require,
- module = require("module"),
- oldModulePrototype = module.prototype;
+
+ var insecureRequire = ctx.require;
+ var module = require('module');
+ var oldModulePrototype = module.prototype;
var secureRequire = function(moduleName) {
- if (whitelist.indexOf(moduleName) == -1) {
+
+ if (whitelist.indexOf(moduleName) === -1) {
module.prototype = oldModulePrototype;
+
throw new Error("'" + moduleName + "' is not whitelisted");
+
} else {
var requiredModule = insecureRequire(moduleName);
+
module.prototype = oldModulePrototype;
+
return requiredModule;
}
};
@@ -31,10 +38,10 @@ exports.runInSandbox = function(src, ctx, whitelist) {
ctx.require = secureRequire;
sandbox = Object.freeze(vm.createContext(ctx));
ctx.require = insecureRequire;
+
} else {
sandbox = Object.freeze(vm.createContext(ctx || {}));
}
- return vm.createScript('(function() {"use strict"; return ('
- + src + ')()}())').runInContext(sandbox);
+ return vm.createScript('(function() {"use strict"; return (' + src + ')()}())').runInContext(sandbox);
};
http://git-wip-us.apache.org/repos/asf/couchdb/blob/0902e8c5/src/couchjs-node/stream.js
----------------------------------------------------------------------
diff --git a/src/couchjs-node/stream.js b/src/couchjs-node/stream.js
index ad6bcab..d0c192c 100644
--- a/src/couchjs-node/stream.js
+++ b/src/couchjs-node/stream.js
@@ -12,94 +12,100 @@
// Text line stream
-module.exports = LineStream
-module.exports.v2 = LineStream2
+module.exports = LineStream;
+module.exports.v2 = LineStream2;
-var stream = require('stream')
-var util = require('util')
+var stream = require('stream');
+var util = require('util');
-util.inherits(LineStream2, stream.Transform)
+util.inherits(LineStream2, stream.Transform);
+
function LineStream2 () {
- if(! (this instanceof LineStream2))
- return new LineStream2
- stream.Transform.call(this)
- this.setEncoding('utf8')
+ if (!(this instanceof LineStream2)) {
+ return new LineStream2();
+ }
+
+ stream.Transform.call(this);
+ this.setEncoding('utf8');
}
LineStream2.prototype._transform = function(message, encoding, done) {
- var self = this
+ var self = this;
- message = message.toString(encoding)
- var lines = message.split(/\n/)
+ message = message.toString(encoding);
+ var lines = message.split(/\n/);
// If the data ends in "\n" this will be ""; otherwise the final partial line.
- var remainder = lines.pop()
- if(remainder)
- this.unshift(remainder)
+ var remainder = lines.pop();
+ if (remainder) {
+ this.unshift(remainder);
+ }
lines.forEach(function(line) {
- self.push(line)
- })
+ self.push(line);
+ });
- done()
-}
+ done();
+};
+
+util.inherits(LineStream, stream);
-util.inherits(LineStream, stream)
function LineStream () {
- var self = this
- stream.call(self)
+ var self = this;
+ stream.call(self);
- self.readable = true
- self.writable = true
+ self.readable = true;
+ self.writable = true;
- self.buffer = ''
- self.downstream = null
+ self.buffer = '';
+ self.downstream = null;
self.on('pipe', function(upstream) {
upstream.on('end', function(data, encoding) {
- self.emit('end', data, encoding)
- })
- })
+ self.emit('end', data, encoding);
+ });
+ });
}
LineStream.prototype.write = function(data, encoding) {
- var self = this
+ var self = this;
- data = data || ''
- if(typeof data != 'string')
- return self.error(new Error('Data was not a string: ' + util.inspect(data)))
+ data = data || '';
+ if (typeof data !== 'string') {
+ return self.error(new Error('Data was not a string: ' + util.inspect(data)));
+ }
- self.buffer += data
- var lines = self.buffer.split(/\n/)
- self.buffer = lines.pop() // If the data ended in "\n" this will be ""; otherwise the final partial line.
+ self.buffer += data;
+ var lines = self.buffer.split(/\n/);
+ self.buffer = lines.pop(); // If the data ended in "\n" this will be ""; otherwise the final partial line.
lines.forEach(function(line) {
- self.emit('data', line)
- })
-}
+ self.emit('data', line);
+ });
+};
LineStream.prototype.end = function(data, encoding) {
- var self = this
+ var self = this;
- self.is_ending = true
- self.writable = false
+ self.is_ending = true;
+ self.writable = false;
// Always call write, even with no data, so it can fire the "end" event.
- self.write(data)
-}
+ self.write(data);
+};
LineStream.prototype.error = function(er) {
- var self = this
+ var self = this;
- self.readable = false
- self.writable = false
- self.emit('error', er)
+ self.readable = false;
+ self.writable = false;
+ self.emit('error', er);
// The write() method sometimes returns this value, so if there was an error, make write() return false.
- return false
-}
+ return false;
+};
http://git-wip-us.apache.org/repos/asf/couchdb/blob/0902e8c5/src/couchjs-node/test/experiment.js
----------------------------------------------------------------------
diff --git a/src/couchjs-node/test/experiment.js b/src/couchjs-node/test/experiment.js
index 094ac1d..fedf6d0 100644
--- a/src/couchjs-node/test/experiment.js
+++ b/src/couchjs-node/test/experiment.js
@@ -10,108 +10,117 @@
// License for the specific language governing permissions and limitations under
// the License.
-var vm = require('vm')
-var util = require('util')
+var vm = require('vm');
+var util = require('util');
-var STATE = 'wait'
- , v = 'vm'
+var STATE = 'wait';
+var v = 'vm';
function main() {
- process.debugPort = 5859
- process.kill(process.pid, 'SIGUSR1')
+ process.debugPort = 5859;
+ process.kill(process.pid, 'SIGUSR1');
- setTimeout(function() { stuff(0) }, 1000)
+ setTimeout(function() {
+ stuff(0);
+ }, 1000);
}
function stuff(count) {
- console.log('Doing stuff: %d', count)
- //debugger
- STATE = 'vm'
- console.log('More stuff: %d', count)
- if(STATE == 'done')
- console.log('Done')
- else if(STATE == 'code')
- setTimeout(code, 1000)
- else if(STATE == 'eval')
- test_eval()
- else if(STATE == 'vm')
- test_vm()
- else if(STATE == 'wait')
- setTimeout(function() { stuff(count+1) }, 1000)
- else
- throw new Error('Unknown state: ' + STATE)
+
+ console.log('Doing stuff: %d', count);
+ STATE = 'vm';
+ console.log('More stuff: %d', count);
+
+ if (STATE === 'done') {
+ console.log('Done');
+ } else if (STATE === 'code') {
+ setTimeout(code, 1000);
+ } else if(STATE === 'eval') {
+ test_eval();
+ } else if(STATE === 'vm') {
+ test_vm();
+ } else if(STATE === 'wait') {
+ setTimeout(function() {
+ stuff(count+1);
+ }, 1000);
+ } else {
+ throw new Error('Unknown state: ' + STATE);
+ }
}
function code() {
- var code =
- [ 'var foo = "in the code"'
- , 'console.log("This is some code")'
- , 'debugger'
- , 'console.log("foo = " + foo)'
- ].join('\n')
-
- var runner = Function([], code)
- console.log('Run runner in 1s')
+ var code = [
+ 'var foo = "in the code"',
+ 'console.log("This is some code")',
+ 'debugger',
+ 'console.log("foo = " + foo)'
+ ].join('\n');
+
+ var runner = Function([], code);
+
+ console.log('Run runner in 1s');
+
setTimeout(run_runner, 1000)
function run_runner() {
- console.log('About to run runner')
- debugger
- runner()
- console.log('Runner done')
+ console.log('About to run runner');
+ debugger;
+ runner();
+ console.log('Runner done');
}
}
function test_eval() {
- console.log('Test eval in 1s')
- setTimeout(run_eval, 1000)
+ console.log('Test eval in 1s');
+ setTimeout(run_eval, 1000);
- var code =
- [ 'var foo = "in eval"'
- , 'console.log("This is eval")'
- , 'debugger'
- , 'console.log("foo = " + foo)'
- ].join('\n')
+ var code = [
+ 'var foo = "in eval"',
+ 'console.log("This is eval")',
+ 'debugger',
+ 'console.log("foo = " + foo)'
+ ].join('\n');
function run_eval() {
- console.log('Run eval now')
- debugger
- eval(code)
+ console.log('Run eval now');
+ debugger;
+ eval(code);
}
}
function test_vm() {
- console.log('Test vm')
-
- var code =
- [ 'var i = 10'
- , 'setTimeout(hello, 1000)'
- , ''
- , 'function hello() {'
- , ' debugger'
- , ' console.log("Hello: " + i)'
- , ' if(--i)'
- , ' setTimeout(hello, 1000)'
- , '}'
- ].join('\n')
-
- console.log('Run vm now')
- var filename = '_couchdb:code.js'
-
- var sandbox = {}
- , ok = ['console', 'setTimeout']
+ console.log('Test vm');
+
+ var code = [
+ 'var i = 10',
+ 'setTimeout(hello, 1000)',
+ '',
+ 'function hello() {',
+ ' debugger',
+ ' console.log("Hello: " + i)',
+ ' if(--i)',
+ ' setTimeout(hello, 1000)',
+ '}'
+ ].join('\n');
+
+ console.log('Run vm now');
+ var filename = '_couchdb:code.js';
+
+ var sandbox = {};
+ var ok = ['console', 'setTimeout'];
ok.forEach(function(key) {
- sandbox[key] = global[key]
- })
+ sandbox[key] = global[key];
+ });
- var ctx = vm.createContext(sandbox)
- var script = vm.createScript(code, filename)
+ var ctx = vm.createContext(sandbox);
+ var script = vm.createScript(code, filename);
- var r = script.runInNewContext(sandbox)
- console.log('Result:\n%s', util.inspect(r, false, 10))
- return r
+ var r = script.runInNewContext(sandbox);
+ console.log('Result:\n%s', util.inspect(r, false, 10));
+ return r;
}
-if(require.main === module)
- main()
+if (require.main === module) {
+ main();
+}
http://git-wip-us.apache.org/repos/asf/couchdb/blob/0902e8c5/src/couchjs-node/xml.js
----------------------------------------------------------------------
diff --git a/src/couchjs-node/xml.js b/src/couchjs-node/xml.js
index efd3a8f..b64d221 100644
--- a/src/couchjs-node/xml.js
+++ b/src/couchjs-node/xml.js
@@ -10,12 +10,13 @@
// License for the specific language governing permissions and limitations under
// the License.
-module.exports = XML
function XML () {
- this.foo = 'bar'
+ this.foo = 'bar';
}
XML.prototype.toXMLString = function() {
- return '<xml>\n <title>test</title>\n</xml>'
-}
+ return '<xml>\n <title>test</title>\n</xml>';
+};
+
+module.exports = XML;
[08/17] git commit: updated refs/heads/master to 532100c
Posted by ja...@apache.org.
add differences notice
Project: http://git-wip-us.apache.org/repos/asf/couchdb/repo
Commit: http://git-wip-us.apache.org/repos/asf/couchdb/commit/ccf9309c
Tree: http://git-wip-us.apache.org/repos/asf/couchdb/tree/ccf9309c
Diff: http://git-wip-us.apache.org/repos/asf/couchdb/diff/ccf9309c
Branch: refs/heads/master
Commit: ccf9309c32ec06821babd94a3c5ecaaa279fed9f
Parents: 868c261
Author: Jan Lehnardt <ja...@apache.org>
Authored: Tue Sep 24 15:09:37 2013 +0200
Committer: Jan Lehnardt <ja...@apache.org>
Committed: Thu Oct 3 17:21:30 2013 +0200
----------------------------------------------------------------------
share/doc/src/experimental.rst | 6 ++++++
1 file changed, 6 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/couchdb/blob/ccf9309c/share/doc/src/experimental.rst
----------------------------------------------------------------------
diff --git a/share/doc/src/experimental.rst b/share/doc/src/experimental.rst
index 1e883bf..7d11ab3 100644
--- a/share/doc/src/experimental.rst
+++ b/share/doc/src/experimental.rst
@@ -71,3 +71,9 @@ be processed by the Node.JS query server.
Enjoy!
+Differences from the SpiderMonkey Query Server
+----------------------------------------------
+
+V8 and SpiderMonkey roughly behave similar, but there might be engine-
+specific differences that make or break a JavaScript function in one or
+the other server.
[13/17] git commit: updated refs/heads/master to 532100c
Posted by ja...@apache.org.
Add 'html/experimental.html' to 'Makefile.am'
Project: http://git-wip-us.apache.org/repos/asf/couchdb/repo
Commit: http://git-wip-us.apache.org/repos/asf/couchdb/commit/2d7da550
Tree: http://git-wip-us.apache.org/repos/asf/couchdb/tree/2d7da550
Diff: http://git-wip-us.apache.org/repos/asf/couchdb/diff/2d7da550
Branch: refs/heads/master
Commit: 2d7da550c90af5e9adb543ca43bcc32ad72d8c4d
Parents: c547a7c
Author: Klaus Trainer <kl...@posteo.de>
Authored: Wed Sep 25 16:40:16 2013 +0200
Committer: Jan Lehnardt <ja...@apache.org>
Committed: Thu Oct 3 17:21:30 2013 +0200
----------------------------------------------------------------------
share/doc/build/Makefile.am | 1 +
1 file changed, 1 insertion(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/couchdb/blob/2d7da550/share/doc/build/Makefile.am
----------------------------------------------------------------------
diff --git a/share/doc/build/Makefile.am b/share/doc/build/Makefile.am
index 1b69ef6..78558f4 100644
--- a/share/doc/build/Makefile.am
+++ b/share/doc/build/Makefile.am
@@ -264,6 +264,7 @@ html_files = \
html/config-ref.html \
html/contents.html \
html/externals.html \
+ html/experimental.html \
html/json-structure.html \
html/objects.inv \
html/http-api.html \
[03/17] git commit: updated refs/heads/master to 532100c
Posted by ja...@apache.org.
rm license file, we have one in hte top level
Project: http://git-wip-us.apache.org/repos/asf/couchdb/repo
Commit: http://git-wip-us.apache.org/repos/asf/couchdb/commit/93fd37bd
Tree: http://git-wip-us.apache.org/repos/asf/couchdb/tree/93fd37bd
Diff: http://git-wip-us.apache.org/repos/asf/couchdb/diff/93fd37bd
Branch: refs/heads/master
Commit: 93fd37bd4eb43d49e6b159620800e169b8399453
Parents: eebe8ae
Author: Jan Lehnardt <ja...@apache.org>
Authored: Sat Sep 21 16:15:13 2013 +0200
Committer: Jan Lehnardt <ja...@apache.org>
Committed: Thu Oct 3 17:21:29 2013 +0200
----------------------------------------------------------------------
src/couchjs-node/LICENSE | 202 ------------------------------------------
1 file changed, 202 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/couchdb/blob/93fd37bd/src/couchjs-node/LICENSE
----------------------------------------------------------------------
diff --git a/src/couchjs-node/LICENSE b/src/couchjs-node/LICENSE
deleted file mode 100644
index d645695..0000000
--- a/src/couchjs-node/LICENSE
+++ /dev/null
@@ -1,202 +0,0 @@
-
- Apache License
- Version 2.0, January 2004
- http://www.apache.org/licenses/
-
- TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
-
- 1. Definitions.
-
- "License" shall mean the terms and conditions for use, reproduction,
- and distribution as defined by Sections 1 through 9 of this document.
-
- "Licensor" shall mean the copyright owner or entity authorized by
- the copyright owner that is granting the License.
-
- "Legal Entity" shall mean the union of the acting entity and all
- other entities that control, are controlled by, or are under common
- control with that entity. For the purposes of this definition,
- "control" means (i) the power, direct or indirect, to cause the
- direction or management of such entity, whether by contract or
- otherwise, or (ii) ownership of fifty percent (50%) or more of the
- outstanding shares, or (iii) beneficial ownership of such entity.
-
- "You" (or "Your") shall mean an individual or Legal Entity
- exercising permissions granted by this License.
-
- "Source" form shall mean the preferred form for making modifications,
- including but not limited to software source code, documentation
- source, and configuration files.
-
- "Object" form shall mean any form resulting from mechanical
- transformation or translation of a Source form, including but
- not limited to compiled object code, generated documentation,
- and conversions to other media types.
-
- "Work" shall mean the work of authorship, whether in Source or
- Object form, made available under the License, as indicated by a
- copyright notice that is included in or attached to the work
- (an example is provided in the Appendix below).
-
- "Derivative Works" shall mean any work, whether in Source or Object
- form, that is based on (or derived from) the Work and for which the
- editorial revisions, annotations, elaborations, or other modifications
- represent, as a whole, an original work of authorship. For the purposes
- of this License, Derivative Works shall not include works that remain
- separable from, or merely link (or bind by name) to the interfaces of,
- the Work and Derivative Works thereof.
-
- "Contribution" shall mean any work of authorship, including
- the original version of the Work and any modifications or additions
- to that Work or Derivative Works thereof, that is intentionally
- submitted to Licensor for inclusion in the Work by the copyright owner
- or by an individual or Legal Entity authorized to submit on behalf of
- the copyright owner. For the purposes of this definition, "submitted"
- means any form of electronic, verbal, or written communication sent
- to the Licensor or its representatives, including but not limited to
- communication on electronic mailing lists, source code control systems,
- and issue tracking systems that are managed by, or on behalf of, the
- Licensor for the purpose of discussing and improving the Work, but
- excluding communication that is conspicuously marked or otherwise
- designated in writing by the copyright owner as "Not a Contribution."
-
- "Contributor" shall mean Licensor and any individual or Legal Entity
- on behalf of whom a Contribution has been received by Licensor and
- subsequently incorporated within the Work.
-
- 2. Grant of Copyright License. Subject to the terms and conditions of
- this License, each Contributor hereby grants to You a perpetual,
- worldwide, non-exclusive, no-charge, royalty-free, irrevocable
- copyright license to reproduce, prepare Derivative Works of,
- publicly display, publicly perform, sublicense, and distribute the
- Work and such Derivative Works in Source or Object form.
-
- 3. Grant of Patent License. Subject to the terms and conditions of
- this License, each Contributor hereby grants to You a perpetual,
- worldwide, non-exclusive, no-charge, royalty-free, irrevocable
- (except as stated in this section) patent license to make, have made,
- use, offer to sell, sell, import, and otherwise transfer the Work,
- where such license applies only to those patent claims licensable
- by such Contributor that are necessarily infringed by their
- Contribution(s) alone or by combination of their Contribution(s)
- with the Work to which such Contribution(s) was submitted. If You
- institute patent litigation against any entity (including a
- cross-claim or counterclaim in a lawsuit) alleging that the Work
- or a Contribution incorporated within the Work constitutes direct
- or contributory patent infringement, then any patent licenses
- granted to You under this License for that Work shall terminate
- as of the date such litigation is filed.
-
- 4. Redistribution. You may reproduce and distribute copies of the
- Work or Derivative Works thereof in any medium, with or without
- modifications, and in Source or Object form, provided that You
- meet the following conditions:
-
- (a) You must give any other recipients of the Work or
- Derivative Works a copy of this License; and
-
- (b) You must cause any modified files to carry prominent notices
- stating that You changed the files; and
-
- (c) You must retain, in the Source form of any Derivative Works
- that You distribute, all copyright, patent, trademark, and
- attribution notices from the Source form of the Work,
- excluding those notices that do not pertain to any part of
- the Derivative Works; and
-
- (d) If the Work includes a "NOTICE" text file as part of its
- distribution, then any Derivative Works that You distribute must
- include a readable copy of the attribution notices contained
- within such NOTICE file, excluding those notices that do not
- pertain to any part of the Derivative Works, in at least one
- of the following places: within a NOTICE text file distributed
- as part of the Derivative Works; within the Source form or
- documentation, if provided along with the Derivative Works; or,
- within a display generated by the Derivative Works, if and
- wherever such third-party notices normally appear. The contents
- of the NOTICE file are for informational purposes only and
- do not modify the License. You may add Your own attribution
- notices within Derivative Works that You distribute, alongside
- or as an addendum to the NOTICE text from the Work, provided
- that such additional attribution notices cannot be construed
- as modifying the License.
-
- You may add Your own copyright statement to Your modifications and
- may provide additional or different license terms and conditions
- for use, reproduction, or distribution of Your modifications, or
- for any such Derivative Works as a whole, provided Your use,
- reproduction, and distribution of the Work otherwise complies with
- the conditions stated in this License.
-
- 5. Submission of Contributions. Unless You explicitly state otherwise,
- any Contribution intentionally submitted for inclusion in the Work
- by You to the Licensor shall be under the terms and conditions of
- this License, without any additional terms or conditions.
- Notwithstanding the above, nothing herein shall supersede or modify
- the terms of any separate license agreement you may have executed
- with Licensor regarding such Contributions.
-
- 6. Trademarks. This License does not grant permission to use the trade
- names, trademarks, service marks, or product names of the Licensor,
- except as required for reasonable and customary use in describing the
- origin of the Work and reproducing the content of the NOTICE file.
-
- 7. Disclaimer of Warranty. Unless required by applicable law or
- agreed to in writing, Licensor provides the Work (and each
- Contributor provides its Contributions) on an "AS IS" BASIS,
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
- implied, including, without limitation, any warranties or conditions
- of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
- PARTICULAR PURPOSE. You are solely responsible for determining the
- appropriateness of using or redistributing the Work and assume any
- risks associated with Your exercise of permissions under this License.
-
- 8. Limitation of Liability. In no event and under no legal theory,
- whether in tort (including negligence), contract, or otherwise,
- unless required by applicable law (such as deliberate and grossly
- negligent acts) or agreed to in writing, shall any Contributor be
- liable to You for damages, including any direct, indirect, special,
- incidental, or consequential damages of any character arising as a
- result of this License or out of the use or inability to use the
- Work (including but not limited to damages for loss of goodwill,
- work stoppage, computer failure or malfunction, or any and all
- other commercial damages or losses), even if such Contributor
- has been advised of the possibility of such damages.
-
- 9. Accepting Warranty or Additional Liability. While redistributing
- the Work or Derivative Works thereof, You may choose to offer,
- and charge a fee for, acceptance of support, warranty, indemnity,
- or other liability obligations and/or rights consistent with this
- License. However, in accepting such obligations, You may act only
- on Your own behalf and on Your sole responsibility, not on behalf
- of any other Contributor, and only if You agree to indemnify,
- defend, and hold each Contributor harmless for any liability
- incurred by, or claims asserted against, such Contributor by reason
- of your accepting any such warranty or additional liability.
-
- END OF TERMS AND CONDITIONS
-
- APPENDIX: How to apply the Apache License to your work.
-
- To apply the Apache License to your work, attach the following
- boilerplate notice, with the fields enclosed by brackets "[]"
- replaced with your own identifying information. (Don't include
- the brackets!) The text should be enclosed in the appropriate
- comment syntax for the file format. We also recommend that a
- file or class name and description of purpose be included on the
- same "printed page" as the copyright notice for easier
- identification within third-party archives.
-
- Copyright [yyyy] [name of copyright owner]
-
- Licensed under the Apache License, Version 2.0 (the "License");
- you may not use this file except in compliance with the License.
- You may obtain a copy of the License at
-
- http://www.apache.org/licenses/LICENSE-2.0
-
- Unless required by applicable law or agreed to in writing, software
- distributed under the License is distributed on an "AS IS" BASIS,
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- See the License for the specific language governing permissions and
- limitations under the License.
[09/17] git commit: updated refs/heads/master to 532100c
Posted by ja...@apache.org.
move config to local.ini
Project: http://git-wip-us.apache.org/repos/asf/couchdb/repo
Commit: http://git-wip-us.apache.org/repos/asf/couchdb/commit/ea6fe188
Tree: http://git-wip-us.apache.org/repos/asf/couchdb/tree/ea6fe188
Diff: http://git-wip-us.apache.org/repos/asf/couchdb/diff/ea6fe188
Branch: refs/heads/master
Commit: ea6fe1886172562ad1d42d625c410bdaf9d14947
Parents: ccf9309
Author: Jan Lehnardt <ja...@apache.org>
Authored: Tue Sep 24 17:01:12 2013 +0200
Committer: Jan Lehnardt <ja...@apache.org>
Committed: Thu Oct 3 17:21:30 2013 +0200
----------------------------------------------------------------------
etc/couchdb/default.ini.tpl.in | 1 -
etc/couchdb/local.ini | 4 ++++
2 files changed, 4 insertions(+), 1 deletion(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/couchdb/blob/ea6fe188/etc/couchdb/default.ini.tpl.in
----------------------------------------------------------------------
diff --git a/etc/couchdb/default.ini.tpl.in b/etc/couchdb/default.ini.tpl.in
index 981bbb1..3267001 100644
--- a/etc/couchdb/default.ini.tpl.in
+++ b/etc/couchdb/default.ini.tpl.in
@@ -123,7 +123,6 @@ use_users_db = false
[query_servers]
javascript = %bindir%/%couchjs_command_name% %localbuilddatadir%/server/main.js
coffeescript = %bindir%/%couchjs_command_name% %localbuilddatadir%/server/main-coffee.js
-nodejs = /usr/local/bin/couchjs-node %localbuilddatadir%/server/main.js
; Changing reduce_limit to false will disable reduce_limit.
http://git-wip-us.apache.org/repos/asf/couchdb/blob/ea6fe188/etc/couchdb/local.ini
----------------------------------------------------------------------
diff --git a/etc/couchdb/local.ini b/etc/couchdb/local.ini
index a5db26f..8aae331 100644
--- a/etc/couchdb/local.ini
+++ b/etc/couchdb/local.ini
@@ -25,6 +25,10 @@
; the whitelist.
;config_whitelist = [{httpd,config_whitelist}, {log,level}, {etc,etc}]
+[query_servers]
+;nodejs = /usr/local/bin/couchjs-node /path/to/couchdb/share/server/main.js
+
+
[httpd_global_handlers]
;_google = {couch_httpd_proxy, handle_proxy_req, <<"http://www.google.com">>}
[10/17] git commit: updated refs/heads/master to 532100c
Posted by ja...@apache.org.
prefer install from source
Project: http://git-wip-us.apache.org/repos/asf/couchdb/repo
Commit: http://git-wip-us.apache.org/repos/asf/couchdb/commit/96d3847e
Tree: http://git-wip-us.apache.org/repos/asf/couchdb/tree/96d3847e
Diff: http://git-wip-us.apache.org/repos/asf/couchdb/diff/96d3847e
Branch: refs/heads/master
Commit: 96d3847e25deb331dd9ba4dae42e879d124d1100
Parents: ea6fe18
Author: Jan Lehnardt <ja...@apache.org>
Authored: Tue Sep 24 17:10:25 2013 +0200
Committer: Jan Lehnardt <ja...@apache.org>
Committed: Thu Oct 3 17:21:30 2013 +0200
----------------------------------------------------------------------
share/doc/src/experimental.rst | 10 +++++-----
1 file changed, 5 insertions(+), 5 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/couchdb/blob/96d3847e/share/doc/src/experimental.rst
----------------------------------------------------------------------
diff --git a/share/doc/src/experimental.rst b/share/doc/src/experimental.rst
index 7d11ab3..bca22a0 100644
--- a/share/doc/src/experimental.rst
+++ b/share/doc/src/experimental.rst
@@ -38,18 +38,18 @@ Setup
You will need to install Node.JS version 0.10.0 or later. See `Node.JS
Downloads <http://nodejs.org/download/>`_ for options.
-1. Install the `couchjs-node` binary. Either via NPM:
+1. Install the `couchjs-node` binary. Either from the CouchDB sources:
.. code-block:: shell
- npm install -g couchjs
+ cd src/couchjs-node
+ npm link
-Or from the CouchDB sources:
+Or via NPM:
.. code-block:: shell
- cd src/couchjs-node
- npm link
+ npm install -g couchjs
.. note:: **NPM in non-standard locations**
[06/17] git commit: updated refs/heads/master to 532100c
Posted by ja...@apache.org.
configure nodejs view server
Project: http://git-wip-us.apache.org/repos/asf/couchdb/repo
Commit: http://git-wip-us.apache.org/repos/asf/couchdb/commit/1c61f30b
Tree: http://git-wip-us.apache.org/repos/asf/couchdb/tree/1c61f30b
Diff: http://git-wip-us.apache.org/repos/asf/couchdb/diff/1c61f30b
Branch: refs/heads/master
Commit: 1c61f30b30e15397ee039d66991abbeb2c03e321
Parents: dc37570
Author: Jan Lehnardt <ja...@apache.org>
Authored: Sat Sep 21 15:43:59 2013 +0200
Committer: Jan Lehnardt <ja...@apache.org>
Committed: Thu Oct 3 17:21:29 2013 +0200
----------------------------------------------------------------------
etc/couchdb/default.ini.tpl.in | 1 +
1 file changed, 1 insertion(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/couchdb/blob/1c61f30b/etc/couchdb/default.ini.tpl.in
----------------------------------------------------------------------
diff --git a/etc/couchdb/default.ini.tpl.in b/etc/couchdb/default.ini.tpl.in
index 3267001..981bbb1 100644
--- a/etc/couchdb/default.ini.tpl.in
+++ b/etc/couchdb/default.ini.tpl.in
@@ -123,6 +123,7 @@ use_users_db = false
[query_servers]
javascript = %bindir%/%couchjs_command_name% %localbuilddatadir%/server/main.js
coffeescript = %bindir%/%couchjs_command_name% %localbuilddatadir%/server/main-coffee.js
+nodejs = /usr/local/bin/couchjs-node %localbuilddatadir%/server/main.js
; Changing reduce_limit to false will disable reduce_limit.
[17/17] git commit: updated refs/heads/master to 532100c
Posted by ja...@apache.org.
remove unused module imports and improved module structure
Project: http://git-wip-us.apache.org/repos/asf/couchdb/repo
Commit: http://git-wip-us.apache.org/repos/asf/couchdb/commit/532100c1
Tree: http://git-wip-us.apache.org/repos/asf/couchdb/tree/532100c1
Diff: http://git-wip-us.apache.org/repos/asf/couchdb/diff/532100c1
Branch: refs/heads/master
Commit: 532100c101387a3314a870264e58e7761c787c67
Parents: 447f101
Author: Sven Lito <me...@svenlito.com>
Authored: Thu Oct 3 16:34:06 2013 +0100
Committer: Jan Lehnardt <ja...@apache.org>
Committed: Thu Oct 3 17:45:43 2013 +0200
----------------------------------------------------------------------
src/couchjs-node/cli.js | 2 -
src/couchjs-node/console.js | 2 +-
src/couchjs-node/couchjs.js | 18 +++++----
src/couchjs-node/inspector.js | 64 ++++++++++++++++----------------
src/couchjs-node/stream.js | 50 +++++++++++++------------
src/couchjs-node/test/experiment.js | 1 -
6 files changed, 69 insertions(+), 68 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/couchdb/blob/532100c1/src/couchjs-node/cli.js
----------------------------------------------------------------------
diff --git a/src/couchjs-node/cli.js b/src/couchjs-node/cli.js
index 065951f..5447dd5 100755
--- a/src/couchjs-node/cli.js
+++ b/src/couchjs-node/cli.js
@@ -13,10 +13,8 @@
// the License.
var fs = require('fs');
-var util = require('util');
var Fiber = require('fibers');
var optimist = require('optimist');
-var child_process = require('child_process');
var couchjs = require('./couchjs');
var package_json = require('./package.json');
http://git-wip-us.apache.org/repos/asf/couchdb/blob/532100c1/src/couchjs-node/console.js
----------------------------------------------------------------------
diff --git a/src/couchjs-node/console.js b/src/couchjs-node/console.js
index 0fda066..18e7241 100644
--- a/src/couchjs-node/console.js
+++ b/src/couchjs-node/console.js
@@ -41,7 +41,7 @@ if (stat) {
};
var on_err = function (er) {
- module.exports.error('Uncaught error:\n%s', er.stack || er.message || JSON.stringify(er))
+ module.exports.error('Uncaught error:\n%s', er.stack || er.message || JSON.stringify(er));
if (er.stack) {
er = ['fatal', 'unknown_error', er.stack];
http://git-wip-us.apache.org/repos/asf/couchdb/blob/532100c1/src/couchjs-node/couchjs.js
----------------------------------------------------------------------
diff --git a/src/couchjs-node/couchjs.js b/src/couchjs-node/couchjs.js
index 84c21e0..ccc1aa9 100644
--- a/src/couchjs-node/couchjs.js
+++ b/src/couchjs-node/couchjs.js
@@ -14,6 +14,7 @@
var vm = require('vm');
var Fiber = require('fibers');
+var util = require('util');
var XML = require('./xml');
var log = require('./console').log;
@@ -23,11 +24,6 @@ var INPUT = {
'waiting':null
};
-Error.prototype.toSource = Error.prototype.toSource || toSource;
-Error.prototype.toString = Error.prototype.toString || toSource;
-Function.prototype.toSource = Function.prototype.toSource || toSource;
-Function.prototype.toString = Function.prototype.toString || toSource;
-
function print(line) {
log('STDOUT %s: %s', process.pid, line);
@@ -71,9 +67,10 @@ function readline () {
function evalcx (source, sandbox) {
sandbox = sandbox || {};
+ var func;
//log('evalcx in %j: %j', Object.keys(sandbox), source)
- if (source == '') {
+ if (source === '') {
return sandbox;
}
@@ -87,7 +84,7 @@ function evalcx (source, sandbox) {
var id = Math.floor(Math.random() * 1000*1000);
var filename = '_couchdb:' + id + '.js';
var script = vm.createScript(source, filename);
- var func = script.runInNewContext(sandbox);
+ func = script.runInNewContext(sandbox);
} catch (er) {
log('Error making code: %s', er.stack);
return sandbox;
@@ -109,7 +106,7 @@ function gc() { }
function toSource() {
- if (typeof this == 'function') {
+ if (typeof this === 'function') {
return '' + this;
}
@@ -120,6 +117,11 @@ function toSource() {
return util.inspect(this);
}
+Error.prototype.toSource = Error.prototype.toSource || toSource;
+Error.prototype.toString = Error.prototype.toString || toSource;
+Function.prototype.toSource = Function.prototype.toSource || toSource;
+Function.prototype.toString = Function.prototype.toString || toSource;
+
module.exports = {
'print': print,
'readline': readline,
http://git-wip-us.apache.org/repos/asf/couchdb/blob/532100c1/src/couchjs-node/inspector.js
----------------------------------------------------------------------
diff --git a/src/couchjs-node/inspector.js b/src/couchjs-node/inspector.js
index 343770f..48182e5 100755
--- a/src/couchjs-node/inspector.js
+++ b/src/couchjs-node/inspector.js
@@ -12,18 +12,33 @@
// License for the specific language governing permissions and limitations under
// the License.
-module.exports = start;
-if (require.main === module) {
- main();
-}
-
-var fs = require('fs');
-var util = require('util');
-var child_process = require('child_process');
+var cp = require('child_process');
var log = require('./console').log;
+function watchInspector(child) {
+
+ child.stderr.on('data', function(body) {
+ log('Inspector STDERR: %s', body);
+ });
+
+ child.stdout.on('data', function(body) {
+ log('Inspector STDOUT: %s', body);
+ });
+
+ child.on('exit', function(code, signal) {
+ log('Inspector exited %d signal=%j', code, signal);
+ process.exit(code);
+ });
+
+ process.on('exit', function() {
+ log('Kill inspector upon exit: %d', child.pid);
+ process.kill(child.pid, 'SIGTERM');
+ });
+
+}
+
function start (debugPort) {
if (!debugPort || typeof debugPort !== 'number') {
@@ -31,7 +46,6 @@ function start (debugPort) {
}
var webPort = debugPort + 1;
-
var cmd = __filename;
var args = [debugPort, webPort];
var opts = {
@@ -42,9 +56,9 @@ function start (debugPort) {
log('Start inspector: %s %j %j', cmd, args, opts);
- var inspector = child_process.spawn(cmd, args, opts);
+ var inspector = cp.spawn(cmd, args, opts);
- watch_inspector(inspector);
+ watchInspector(inspector);
log('Enable remote debug pid=%d port=%d', process.pid, debugPort);
@@ -52,28 +66,6 @@ function start (debugPort) {
process.kill(process.pid, 'SIGUSR1');
}
-function watch_inspector(child) {
-
- child.stderr.on('data', function(body) {
- log('Inspector STDERR: %s', body);
- });
-
- child.stdout.on('data', function(body) {
- log('Inspector STDOUT: %s', body);
- });
-
- child.on('exit', function(code, signal) {
- log('Inspector exited %d signal=%j', code, signal);
- process.exit(code);
- });
-
- process.on('exit', function() {
- log('Kill inspector upon exit: %d', child.pid);
- process.kill(child.pid, 'SIGTERM');
- });
-
-}
-
function main() {
var debugPort = +process.argv[2];
var webPort = +process.argv[3];
@@ -101,3 +93,9 @@ function main() {
console.log('Error:\n%s', er.stack);
});
}
+
+module.exports = start;
+
+if (require.main === module) {
+ main();
+}
http://git-wip-us.apache.org/repos/asf/couchdb/blob/532100c1/src/couchjs-node/stream.js
----------------------------------------------------------------------
diff --git a/src/couchjs-node/stream.js b/src/couchjs-node/stream.js
index d0c192c..ebffc30 100644
--- a/src/couchjs-node/stream.js
+++ b/src/couchjs-node/stream.js
@@ -12,16 +12,29 @@
// Text line stream
-module.exports = LineStream;
-module.exports.v2 = LineStream2;
-
var stream = require('stream');
var util = require('util');
-util.inherits(LineStream2, stream.Transform);
+function LineStream() {
-function LineStream2 () {
+ var self = this;
+ stream.call(self);
+
+ self.readable = true;
+ self.writable = true;
+
+ self.buffer = '';
+ self.downstream = null;
+
+ self.on('pipe', function(upstream) {
+ upstream.on('end', function(data, encoding) {
+ self.emit('end', data, encoding);
+ });
+ });
+}
+
+function LineStream2() {
if (!(this instanceof LineStream2)) {
return new LineStream2();
@@ -31,6 +44,8 @@ function LineStream2 () {
this.setEncoding('utf8');
}
+util.inherits(LineStream2, stream.Transform);
+
LineStream2.prototype._transform = function(message, encoding, done) {
var self = this;
@@ -52,25 +67,9 @@ LineStream2.prototype._transform = function(message, encoding, done) {
util.inherits(LineStream, stream);
-function LineStream () {
- var self = this;
- stream.call(self);
- self.readable = true;
- self.writable = true;
- self.buffer = '';
- self.downstream = null;
-
- self.on('pipe', function(upstream) {
- upstream.on('end', function(data, encoding) {
- self.emit('end', data, encoding);
- });
- });
-}
-
-
-LineStream.prototype.write = function(data, encoding) {
+LineStream.prototype.write = function(data) {
var self = this;
data = data || '';
@@ -88,7 +87,7 @@ LineStream.prototype.write = function(data, encoding) {
};
-LineStream.prototype.end = function(data, encoding) {
+LineStream.prototype.end = function(data) {
var self = this;
self.is_ending = true;
@@ -109,3 +108,8 @@ LineStream.prototype.error = function(er) {
// The write() method sometimes returns this value, so if there was an error, make write() return false.
return false;
};
+
+
+module.exports = LineStream;
+module.exports.v2 = LineStream2;
+
http://git-wip-us.apache.org/repos/asf/couchdb/blob/532100c1/src/couchjs-node/test/experiment.js
----------------------------------------------------------------------
diff --git a/src/couchjs-node/test/experiment.js b/src/couchjs-node/test/experiment.js
index fedf6d0..9197ec6 100644
--- a/src/couchjs-node/test/experiment.js
+++ b/src/couchjs-node/test/experiment.js
@@ -14,7 +14,6 @@ var vm = require('vm');
var util = require('util');
var STATE = 'wait';
-var v = 'vm';
function main() {
process.debugPort = 5859;
[12/17] git commit: updated refs/heads/master to 532100c
Posted by ja...@apache.org.
add sandbox.js
Project: http://git-wip-us.apache.org/repos/asf/couchdb/repo
Commit: http://git-wip-us.apache.org/repos/asf/couchdb/commit/ba6bdae4
Tree: http://git-wip-us.apache.org/repos/asf/couchdb/tree/ba6bdae4
Diff: http://git-wip-us.apache.org/repos/asf/couchdb/diff/ba6bdae4
Branch: refs/heads/master
Commit: ba6bdae4e3e941c8f815228d5937f35a33deddf7
Parents: 12763ee
Author: Jan Lehnardt <ja...@apache.org>
Authored: Sat Sep 21 16:28:47 2013 +0200
Committer: Jan Lehnardt <ja...@apache.org>
Committed: Thu Oct 3 17:21:30 2013 +0200
----------------------------------------------------------------------
NOTICE | 4 ++++
license.skip | 1 +
src/couchjs-node/sandbox.js | 40 ++++++++++++++++++++++++++++++++++++++++
3 files changed, 45 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/couchdb/blob/ba6bdae4/NOTICE
----------------------------------------------------------------------
diff --git a/NOTICE b/NOTICE
index 6a41c6c..5c95dd2 100644
--- a/NOTICE
+++ b/NOTICE
@@ -189,3 +189,7 @@ This product also includes the following third-party components:
* share/doc/src/templates/couchdb/domainindex.html
Copyright 2007-2011 by the Sphinx team
+
+ * sandbox.js https://github.com/KlausTrainer/sandbox.js
+
+ (c) 2013 Klaus Trainer
http://git-wip-us.apache.org/repos/asf/couchdb/blob/ba6bdae4/license.skip
----------------------------------------------------------------------
diff --git a/license.skip b/license.skip
index d87cc6c..4352011 100644
--- a/license.skip
+++ b/license.skip
@@ -110,6 +110,7 @@
^src/couchdb/priv/couchspawnkillable
^src/couchdb/priv/stat_descriptions.cfg
^src/couchjs-node/package.json
+^src/couchjs-node/sandbox.js
^src/couchjs-node/README.md
^src/erlang-oauth/.*
^src/couch_dbupdates
http://git-wip-us.apache.org/repos/asf/couchdb/blob/ba6bdae4/src/couchjs-node/sandbox.js
----------------------------------------------------------------------
diff --git a/src/couchjs-node/sandbox.js b/src/couchjs-node/sandbox.js
new file mode 100644
index 0000000..cfdff18
--- /dev/null
+++ b/src/couchjs-node/sandbox.js
@@ -0,0 +1,40 @@
+// from https://github.com/KlausTrainer/sandbox.js
+exports.runInSandbox = function(src, ctx, whitelist) {
+ var vm = require('vm'),
+ sandbox;
+
+ if (ctx && ctx.require) {
+ whitelist = whitelist || [];
+ var insecureRequire = ctx.require,
+ module = require("module"),
+ oldModulePrototype = module.prototype;
+
+ var secureRequire = function(moduleName) {
+ if (whitelist.indexOf(moduleName) == -1) {
+ module.prototype = oldModulePrototype;
+ throw new Error("'" + moduleName + "' is not whitelisted");
+ } else {
+ var requiredModule = insecureRequire(moduleName);
+ module.prototype = oldModulePrototype;
+ return requiredModule;
+ }
+ };
+
+ module.prototype = {
+ require: secureRequire,
+ load: module.prototype.load,
+ _compile: module.prototype._compile
+ };
+
+ module._cache = {};
+
+ ctx.require = secureRequire;
+ sandbox = Object.freeze(vm.createContext(ctx));
+ ctx.require = insecureRequire;
+ } else {
+ sandbox = Object.freeze(vm.createContext(ctx || {}));
+ }
+
+ return vm.createScript('(function() {"use strict"; return ('
+ + src + ')()}())').runInContext(sandbox);
+};
[11/17] git commit: updated refs/heads/master to 532100c
Posted by ja...@apache.org.
remove user-facing docs from in-src README, point to docs
Project: http://git-wip-us.apache.org/repos/asf/couchdb/repo
Commit: http://git-wip-us.apache.org/repos/asf/couchdb/commit/c547a7c3
Tree: http://git-wip-us.apache.org/repos/asf/couchdb/tree/c547a7c3
Diff: http://git-wip-us.apache.org/repos/asf/couchdb/diff/c547a7c3
Branch: refs/heads/master
Commit: c547a7c3d9e206e45438a282b47f815cd5843955
Parents: 96d3847
Author: Jan Lehnardt <ja...@apache.org>
Authored: Wed Sep 25 15:13:11 2013 +0200
Committer: Jan Lehnardt <ja...@apache.org>
Committed: Thu Oct 3 17:21:30 2013 +0200
----------------------------------------------------------------------
src/couchjs-node/README.md | 24 +-----------------------
1 file changed, 1 insertion(+), 23 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/couchdb/blob/c547a7c3/src/couchjs-node/README.md
----------------------------------------------------------------------
diff --git a/src/couchjs-node/README.md b/src/couchjs-node/README.md
index c686e80..551c3df 100644
--- a/src/couchjs-node/README.md
+++ b/src/couchjs-node/README.md
@@ -6,29 +6,7 @@ CouchJS is a command-line Node.js program. It is 100% compatible with Apache Cou
By using CouchJS, you will get 100% CouchDB compatibility (the test suite completely passes) but your JavaScript environment is V8, or Node.js.
-CouchJS is available as an npm module.
-
- $ npm install -g couchjs
-
-## Usage
-
-Install CouchDB. Install this package with npm. Confirm your `couchjs` install location.
-
- $ which couchjs # Note, your path will be different from mine.
- /home/jhs/node/bin/couchjs
-
-Look at the CouchDB config for the JavaScript query server.
-
- $ curl http://localhost:5984/_config/query_servers/javascript
- "/home/jhs/couchdb/bin/couchjs /home/jhs/couchdb/share/couchdb/server/main.js"
-
-Change that to this `couchjs`. **Leave the second argument the same.**
-
- $ curl -X PUT http://localhost:5984/_config/query_servers/javascript \
- -H content-type:application/json \
- -d "\"`which couchjs` /home/jhs/couchdb/share/couchdb/server/main.js\""
-
-Done!
+See share/doc/src/experimental.rst for installation instructions.
## Idea
[14/17] git commit: updated refs/heads/master to 532100c
Posted by ja...@apache.org.
remove last extra reference
Project: http://git-wip-us.apache.org/repos/asf/couchdb/repo
Commit: http://git-wip-us.apache.org/repos/asf/couchdb/commit/868c2614
Tree: http://git-wip-us.apache.org/repos/asf/couchdb/tree/868c2614
Diff: http://git-wip-us.apache.org/repos/asf/couchdb/diff/868c2614
Branch: refs/heads/master
Commit: 868c2614f56c88be155d83fc82a0698dee14ac0d
Parents: ba6bdae
Author: Jan Lehnardt <ja...@apache.org>
Authored: Sat Sep 21 16:35:08 2013 +0200
Committer: Jan Lehnardt <ja...@apache.org>
Committed: Thu Oct 3 17:21:30 2013 +0200
----------------------------------------------------------------------
src/couchjs-node/package.json | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/couchdb/blob/868c2614/src/couchjs-node/package.json
----------------------------------------------------------------------
diff --git a/src/couchjs-node/package.json b/src/couchjs-node/package.json
index 665888c..5e8ade0 100644
--- a/src/couchjs-node/package.json
+++ b/src/couchjs-node/package.json
@@ -7,7 +7,7 @@
, "engines": { "node": ">= 0.8" }
, "main": "./couchjs.js"
-, "bin": {"couchjs-node":"./cli.js", "couchjs-extra":"./extra.js"}
+, "bin": {"couchjs-node":"./cli.js"}
, "couchdb": { "main":"./couchdb.js"
, "vhosts": ["127.0.0.1.xip.io"]
[02/17] git commit: updated refs/heads/master to 532100c
Posted by ja...@apache.org.
add license headers
Project: http://git-wip-us.apache.org/repos/asf/couchdb/repo
Commit: http://git-wip-us.apache.org/repos/asf/couchdb/commit/0595c5e9
Tree: http://git-wip-us.apache.org/repos/asf/couchdb/tree/0595c5e9
Diff: http://git-wip-us.apache.org/repos/asf/couchdb/diff/0595c5e9
Branch: refs/heads/master
Commit: 0595c5e966a8f20a407683118263d6dc9d52a075
Parents: 8d0e749
Author: Jan Lehnardt <ja...@apache.org>
Authored: Sat Sep 21 16:22:47 2013 +0200
Committer: Jan Lehnardt <ja...@apache.org>
Committed: Thu Oct 3 17:21:29 2013 +0200
----------------------------------------------------------------------
src/couchjs-node/cli.js | 24 ++++++++++--------------
src/couchjs-node/console.js | 20 +++++++++-----------
src/couchjs-node/couchdb.js | 20 +++++++++-----------
src/couchjs-node/couchjs.js | 20 +++++++++-----------
src/couchjs-node/inspector.js | 24 ++++++++++--------------
src/couchjs-node/stream.js | 24 +++++++++++-------------
src/couchjs-node/test/experiment.js | 12 ++++++++++++
src/couchjs-node/xml.js | 20 +++++++++-----------
8 files changed, 79 insertions(+), 85 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/couchdb/blob/0595c5e9/src/couchjs-node/cli.js
----------------------------------------------------------------------
diff --git a/src/couchjs-node/cli.js b/src/couchjs-node/cli.js
index a835cab..8b7abef 100755
--- a/src/couchjs-node/cli.js
+++ b/src/couchjs-node/cli.js
@@ -1,20 +1,16 @@
#!/usr/bin/env node
+
+// Licensed under the Apache License, Version 2.0 (the "License"); you may not
+// use this file except in compliance with the License. You may obtain a copy of
+// the License at
//
-// couchjs replacement
-//
-// Copyright 2011 Iris Couch
-//
-// Licensed under the Apache License, Version 2.0 (the "License");
-// you may not use this file except in compliance with the License.
-// You may obtain a copy of the License at
-//
-// http://www.apache.org/licenses/LICENSE-2.0
+// http://www.apache.org/licenses/LICENSE-2.0
//
-// Unless required by applicable law or agreed to in writing, software
-// distributed under the License is distributed on an "AS IS" BASIS,
-// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-// See the License for the specific language governing permissions and
-// limitations under the License.
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+// License for the specific language governing permissions and limitations under
+// the License.
var fs = require('fs')
var util = require('util')
http://git-wip-us.apache.org/repos/asf/couchdb/blob/0595c5e9/src/couchjs-node/console.js
----------------------------------------------------------------------
diff --git a/src/couchjs-node/console.js b/src/couchjs-node/console.js
index 2a0a17a..67cc32d 100644
--- a/src/couchjs-node/console.js
+++ b/src/couchjs-node/console.js
@@ -1,16 +1,14 @@
-// Copyright 2011 Iris Couch
+// Licensed under the Apache License, Version 2.0 (the "License"); you may not
+// use this file except in compliance with the License. You may obtain a copy of
+// the License at
//
-// Licensed under the Apache License, Version 2.0 (the "License");
-// you may not use this file except in compliance with the License.
-// You may obtain a copy of the License at
+// http://www.apache.org/licenses/LICENSE-2.0
//
-// http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing, software
-// distributed under the License is distributed on an "AS IS" BASIS,
-// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-// See the License for the specific language governing permissions and
-// limitations under the License.
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+// License for the specific language governing permissions and limitations under
+// the License.
var fs = require('fs')
var util = require('util')
http://git-wip-us.apache.org/repos/asf/couchdb/blob/0595c5e9/src/couchjs-node/couchdb.js
----------------------------------------------------------------------
diff --git a/src/couchjs-node/couchdb.js b/src/couchjs-node/couchdb.js
index d297112..46b23b0 100755
--- a/src/couchjs-node/couchdb.js
+++ b/src/couchjs-node/couchdb.js
@@ -1,16 +1,14 @@
-// Copyright 2011 Iris Couch
+// Licensed under the Apache License, Version 2.0 (the "License"); you may not
+// use this file except in compliance with the License. You may obtain a copy of
+// the License at
//
-// Licensed under the Apache License, Version 2.0 (the "License");
-// you may not use this file except in compliance with the License.
-// You may obtain a copy of the License at
+// http://www.apache.org/licenses/LICENSE-2.0
//
-// http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing, software
-// distributed under the License is distributed on an "AS IS" BASIS,
-// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-// See the License for the specific language governing permissions and
-// limitations under the License.
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+// License for the specific language governing permissions and limitations under
+// the License.
module.exports = handler
http://git-wip-us.apache.org/repos/asf/couchdb/blob/0595c5e9/src/couchjs-node/couchjs.js
----------------------------------------------------------------------
diff --git a/src/couchjs-node/couchjs.js b/src/couchjs-node/couchjs.js
index d95341d..b633f6f 100644
--- a/src/couchjs-node/couchjs.js
+++ b/src/couchjs-node/couchjs.js
@@ -1,16 +1,14 @@
-// Copyright 2011 Iris Couch
+// Licensed under the Apache License, Version 2.0 (the "License"); you may not
+// use this file except in compliance with the License. You may obtain a copy of
+// the License at
//
-// Licensed under the Apache License, Version 2.0 (the "License");
-// you may not use this file except in compliance with the License.
-// You may obtain a copy of the License at
+// http://www.apache.org/licenses/LICENSE-2.0
//
-// http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing, software
-// distributed under the License is distributed on an "AS IS" BASIS,
-// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-// See the License for the specific language governing permissions and
-// limitations under the License.
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+// License for the specific language governing permissions and limitations under
+// the License.
module.exports = { 'print' : print
, 'readline': readline
http://git-wip-us.apache.org/repos/asf/couchdb/blob/0595c5e9/src/couchjs-node/inspector.js
----------------------------------------------------------------------
diff --git a/src/couchjs-node/inspector.js b/src/couchjs-node/inspector.js
index efa9856..2b75c3b 100755
--- a/src/couchjs-node/inspector.js
+++ b/src/couchjs-node/inspector.js
@@ -1,20 +1,16 @@
#!/usr/bin/env node
+
+// Licensed under the Apache License, Version 2.0 (the "License"); you may not
+// use this file except in compliance with the License. You may obtain a copy of
+// the License at
//
-// couchjs replacement
-//
-// Copyright 2011 Iris Couch
-//
-// Licensed under the Apache License, Version 2.0 (the "License");
-// you may not use this file except in compliance with the License.
-// You may obtain a copy of the License at
-//
-// http://www.apache.org/licenses/LICENSE-2.0
+// http://www.apache.org/licenses/LICENSE-2.0
//
-// Unless required by applicable law or agreed to in writing, software
-// distributed under the License is distributed on an "AS IS" BASIS,
-// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-// See the License for the specific language governing permissions and
-// limitations under the License.
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+// License for the specific language governing permissions and limitations under
+// the License.
module.exports = start
http://git-wip-us.apache.org/repos/asf/couchdb/blob/0595c5e9/src/couchjs-node/stream.js
----------------------------------------------------------------------
diff --git a/src/couchjs-node/stream.js b/src/couchjs-node/stream.js
index 90deda1..ad6bcab 100644
--- a/src/couchjs-node/stream.js
+++ b/src/couchjs-node/stream.js
@@ -1,18 +1,16 @@
-// Text line stream
-//
-// Copyright 2011 Iris Couch
-//
-// Licensed under the Apache License, Version 2.0 (the "License");
-// you may not use this file except in compliance with the License.
-// You may obtain a copy of the License at
+// Licensed under the Apache License, Version 2.0 (the "License"); you may not
+// use this file except in compliance with the License. You may obtain a copy of
+// the License at
//
-// http://www.apache.org/licenses/LICENSE-2.0
+// http://www.apache.org/licenses/LICENSE-2.0
//
-// Unless required by applicable law or agreed to in writing, software
-// distributed under the License is distributed on an "AS IS" BASIS,
-// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-// See the License for the specific language governing permissions and
-// limitations under the License.
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+// License for the specific language governing permissions and limitations under
+// the License.
+
+// Text line stream
module.exports = LineStream
module.exports.v2 = LineStream2
http://git-wip-us.apache.org/repos/asf/couchdb/blob/0595c5e9/src/couchjs-node/test/experiment.js
----------------------------------------------------------------------
diff --git a/src/couchjs-node/test/experiment.js b/src/couchjs-node/test/experiment.js
index 54a5ab4..094ac1d 100644
--- a/src/couchjs-node/test/experiment.js
+++ b/src/couchjs-node/test/experiment.js
@@ -1,3 +1,15 @@
+// Licensed under the Apache License, Version 2.0 (the "License"); you may not
+// use this file except in compliance with the License. You may obtain a copy of
+// the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+// License for the specific language governing permissions and limitations under
+// the License.
+
var vm = require('vm')
var util = require('util')
http://git-wip-us.apache.org/repos/asf/couchdb/blob/0595c5e9/src/couchjs-node/xml.js
----------------------------------------------------------------------
diff --git a/src/couchjs-node/xml.js b/src/couchjs-node/xml.js
index c81525b..efd3a8f 100644
--- a/src/couchjs-node/xml.js
+++ b/src/couchjs-node/xml.js
@@ -1,16 +1,14 @@
-// Copyright 2011 Iris Couch
+// Licensed under the Apache License, Version 2.0 (the "License"); you may not
+// use this file except in compliance with the License. You may obtain a copy of
+// the License at
//
-// Licensed under the Apache License, Version 2.0 (the "License");
-// you may not use this file except in compliance with the License.
-// You may obtain a copy of the License at
+// http://www.apache.org/licenses/LICENSE-2.0
//
-// http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing, software
-// distributed under the License is distributed on an "AS IS" BASIS,
-// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-// See the License for the specific language governing permissions and
-// limitations under the License.
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+// License for the specific language governing permissions and limitations under
+// the License.
module.exports = XML
[04/17] git commit: updated refs/heads/master to 532100c
Posted by ja...@apache.org.
add docs
Project: http://git-wip-us.apache.org/repos/asf/couchdb/repo
Commit: http://git-wip-us.apache.org/repos/asf/couchdb/commit/eebe8aee
Tree: http://git-wip-us.apache.org/repos/asf/couchdb/tree/eebe8aee
Diff: http://git-wip-us.apache.org/repos/asf/couchdb/diff/eebe8aee
Branch: refs/heads/master
Commit: eebe8aeee9bbf8b6d0dec745aa8552b68e477f82
Parents: 1c61f30
Author: Jan Lehnardt <ja...@apache.org>
Authored: Sat Sep 21 16:14:39 2013 +0200
Committer: Jan Lehnardt <ja...@apache.org>
Committed: Thu Oct 3 17:21:29 2013 +0200
----------------------------------------------------------------------
share/doc/build/Makefile.am | 2 +
share/doc/src/contents.rst | 1 +
share/doc/src/experimental.rst | 73 +++++++++++++++++++++++++++++++++++++
3 files changed, 76 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/couchdb/blob/eebe8aee/share/doc/build/Makefile.am
----------------------------------------------------------------------
diff --git a/share/doc/build/Makefile.am b/share/doc/build/Makefile.am
index 66819fa..1b69ef6 100644
--- a/share/doc/build/Makefile.am
+++ b/share/doc/build/Makefile.am
@@ -143,6 +143,7 @@ html_files = \
html/_sources/about.txt \
html/_sources/contents.txt \
html/_sources/contributing.txt \
+ html/_sources/experimental.txt \
html/_sources/externals.txt \
html/_sources/json-structure.txt \
html/_static/ajax-loader.gif \
@@ -403,6 +404,7 @@ src_files = \
../src/whatsnew/index.rst \
../src/about.rst \
../src/contents.rst \
+ ../src/experimental.rst \
../src/contributing.rst \
../src/externals.rst \
../src/json-structure.rst \
http://git-wip-us.apache.org/repos/asf/couchdb/blob/eebe8aee/share/doc/src/contents.rst
----------------------------------------------------------------------
diff --git a/share/doc/src/contents.rst b/share/doc/src/contents.rst
index 0b38b73..4395f92 100644
--- a/share/doc/src/contents.rst
+++ b/share/doc/src/contents.rst
@@ -29,6 +29,7 @@
fauxton/index
api/index
json-structure
+ experimental
contributing
whatsnew/index
cve/index
http://git-wip-us.apache.org/repos/asf/couchdb/blob/eebe8aee/share/doc/src/experimental.rst
----------------------------------------------------------------------
diff --git a/share/doc/src/experimental.rst b/share/doc/src/experimental.rst
new file mode 100644
index 0000000..1e883bf
--- /dev/null
+++ b/share/doc/src/experimental.rst
@@ -0,0 +1,73 @@
+.. Licensed under the Apache License, Version 2.0 (the "License"); you may not
+.. use this file except in compliance with the License. You may obtain a copy of
+.. the License at
+..
+.. http://www.apache.org/licenses/LICENSE-2.0
+..
+.. Unless required by applicable law or agreed to in writing, software
+.. distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+.. WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+.. License for the specific language governing permissions and limitations under
+.. the License.
+
+.. _experimental:
+
+=====================
+Experimental Features
+=====================
+
+This is a list of experimental features in CouchDB. They are included in
+a release because the development team is requesting feedback from the
+larger developer community. As such, please play around with these features
+and send us feedback, thanks!
+
+Use at your own risk! Do not rely on these features for critical
+applications.
+
+NodeJS Query Server
+===================
+
+The NodeJS Query Server is an alternative runtime environment for
+the default JavaScript Query Server that runs on top of Node.JS and
+not SpiderMonkey like the default Query Server.
+
+
+Setup
+-----
+
+You will need to install Node.JS version 0.10.0 or later. See `Node.JS
+Downloads <http://nodejs.org/download/>`_ for options.
+
+1. Install the `couchjs-node` binary. Either via NPM:
+
+.. code-block:: shell
+
+ npm install -g couchjs
+
+Or from the CouchDB sources:
+
+.. code-block:: shell
+
+ cd src/couchjs-node
+ npm link
+
+.. note:: **NPM in non-standard locations**
+
+ If your Node.JS installation doesn’t store binaries in `/usr/local/bin`
+ you will need to adjust CouchDB’s configuration. Add this to your `local.ini`
+ file:
+
+ .. code-block:: ini
+
+ [query_servers]
+ nodejs = /path/to/couchjs-node /path/to/couchdb/share/server/main.js
+
+ And then restart your CouchDB instance.
+
+2. Done. Now you can create design documents with the `language` parameter
+set to `nodejs` and all JavaScript functions in this design document will
+be processed by the Node.JS query server.
+
+Enjoy!
+
+
[07/17] git commit: updated refs/heads/master to 532100c
Posted by ja...@apache.org.
add couchjs-node from Jason
Project: http://git-wip-us.apache.org/repos/asf/couchdb/repo
Commit: http://git-wip-us.apache.org/repos/asf/couchdb/commit/dc375701
Tree: http://git-wip-us.apache.org/repos/asf/couchdb/tree/dc375701
Diff: http://git-wip-us.apache.org/repos/asf/couchdb/diff/dc375701
Branch: refs/heads/master
Commit: dc375701d02db659b6364f1d2aab4d6631c1e285
Parents: 3e19db2
Author: Jan Lehnardt <ja...@apache.org>
Authored: Sat Sep 21 15:42:47 2013 +0200
Committer: Jan Lehnardt <ja...@apache.org>
Committed: Thu Oct 3 17:21:29 2013 +0200
----------------------------------------------------------------------
src/couchjs-node/LICENSE | 202 ++++++++++++++++++
src/couchjs-node/README.md | 54 +++++
src/couchjs-node/checkout.sh | 36 ++++
src/couchjs-node/cli.js | 85 ++++++++
src/couchjs-node/console.js | 65 ++++++
src/couchjs-node/couchdb.js | 29 +++
src/couchjs-node/couchjs.js | 116 +++++++++++
src/couchjs-node/extra.js | 346 +++++++++++++++++++++++++++++++
src/couchjs-node/inspector.js | 92 ++++++++
src/couchjs-node/package.json | 30 +++
src/couchjs-node/stream.js | 107 ++++++++++
src/couchjs-node/test/experiment.js | 105 ++++++++++
src/couchjs-node/xml.js | 23 ++
13 files changed, 1290 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/couchdb/blob/dc375701/src/couchjs-node/LICENSE
----------------------------------------------------------------------
diff --git a/src/couchjs-node/LICENSE b/src/couchjs-node/LICENSE
new file mode 100644
index 0000000..d645695
--- /dev/null
+++ b/src/couchjs-node/LICENSE
@@ -0,0 +1,202 @@
+
+ Apache License
+ Version 2.0, January 2004
+ http://www.apache.org/licenses/
+
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
+
+ 1. Definitions.
+
+ "License" shall mean the terms and conditions for use, reproduction,
+ and distribution as defined by Sections 1 through 9 of this document.
+
+ "Licensor" shall mean the copyright owner or entity authorized by
+ the copyright owner that is granting the License.
+
+ "Legal Entity" shall mean the union of the acting entity and all
+ other entities that control, are controlled by, or are under common
+ control with that entity. For the purposes of this definition,
+ "control" means (i) the power, direct or indirect, to cause the
+ direction or management of such entity, whether by contract or
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
+ outstanding shares, or (iii) beneficial ownership of such entity.
+
+ "You" (or "Your") shall mean an individual or Legal Entity
+ exercising permissions granted by this License.
+
+ "Source" form shall mean the preferred form for making modifications,
+ including but not limited to software source code, documentation
+ source, and configuration files.
+
+ "Object" form shall mean any form resulting from mechanical
+ transformation or translation of a Source form, including but
+ not limited to compiled object code, generated documentation,
+ and conversions to other media types.
+
+ "Work" shall mean the work of authorship, whether in Source or
+ Object form, made available under the License, as indicated by a
+ copyright notice that is included in or attached to the work
+ (an example is provided in the Appendix below).
+
+ "Derivative Works" shall mean any work, whether in Source or Object
+ form, that is based on (or derived from) the Work and for which the
+ editorial revisions, annotations, elaborations, or other modifications
+ represent, as a whole, an original work of authorship. For the purposes
+ of this License, Derivative Works shall not include works that remain
+ separable from, or merely link (or bind by name) to the interfaces of,
+ the Work and Derivative Works thereof.
+
+ "Contribution" shall mean any work of authorship, including
+ the original version of the Work and any modifications or additions
+ to that Work or Derivative Works thereof, that is intentionally
+ submitted to Licensor for inclusion in the Work by the copyright owner
+ or by an individual or Legal Entity authorized to submit on behalf of
+ the copyright owner. For the purposes of this definition, "submitted"
+ means any form of electronic, verbal, or written communication sent
+ to the Licensor or its representatives, including but not limited to
+ communication on electronic mailing lists, source code control systems,
+ and issue tracking systems that are managed by, or on behalf of, the
+ Licensor for the purpose of discussing and improving the Work, but
+ excluding communication that is conspicuously marked or otherwise
+ designated in writing by the copyright owner as "Not a Contribution."
+
+ "Contributor" shall mean Licensor and any individual or Legal Entity
+ on behalf of whom a Contribution has been received by Licensor and
+ subsequently incorporated within the Work.
+
+ 2. Grant of Copyright License. Subject to the terms and conditions of
+ this License, each Contributor hereby grants to You a perpetual,
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+ copyright license to reproduce, prepare Derivative Works of,
+ publicly display, publicly perform, sublicense, and distribute the
+ Work and such Derivative Works in Source or Object form.
+
+ 3. Grant of Patent License. Subject to the terms and conditions of
+ this License, each Contributor hereby grants to You a perpetual,
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+ (except as stated in this section) patent license to make, have made,
+ use, offer to sell, sell, import, and otherwise transfer the Work,
+ where such license applies only to those patent claims licensable
+ by such Contributor that are necessarily infringed by their
+ Contribution(s) alone or by combination of their Contribution(s)
+ with the Work to which such Contribution(s) was submitted. If You
+ institute patent litigation against any entity (including a
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
+ or a Contribution incorporated within the Work constitutes direct
+ or contributory patent infringement, then any patent licenses
+ granted to You under this License for that Work shall terminate
+ as of the date such litigation is filed.
+
+ 4. Redistribution. You may reproduce and distribute copies of the
+ Work or Derivative Works thereof in any medium, with or without
+ modifications, and in Source or Object form, provided that You
+ meet the following conditions:
+
+ (a) You must give any other recipients of the Work or
+ Derivative Works a copy of this License; and
+
+ (b) You must cause any modified files to carry prominent notices
+ stating that You changed the files; and
+
+ (c) You must retain, in the Source form of any Derivative Works
+ that You distribute, all copyright, patent, trademark, and
+ attribution notices from the Source form of the Work,
+ excluding those notices that do not pertain to any part of
+ the Derivative Works; and
+
+ (d) If the Work includes a "NOTICE" text file as part of its
+ distribution, then any Derivative Works that You distribute must
+ include a readable copy of the attribution notices contained
+ within such NOTICE file, excluding those notices that do not
+ pertain to any part of the Derivative Works, in at least one
+ of the following places: within a NOTICE text file distributed
+ as part of the Derivative Works; within the Source form or
+ documentation, if provided along with the Derivative Works; or,
+ within a display generated by the Derivative Works, if and
+ wherever such third-party notices normally appear. The contents
+ of the NOTICE file are for informational purposes only and
+ do not modify the License. You may add Your own attribution
+ notices within Derivative Works that You distribute, alongside
+ or as an addendum to the NOTICE text from the Work, provided
+ that such additional attribution notices cannot be construed
+ as modifying the License.
+
+ You may add Your own copyright statement to Your modifications and
+ may provide additional or different license terms and conditions
+ for use, reproduction, or distribution of Your modifications, or
+ for any such Derivative Works as a whole, provided Your use,
+ reproduction, and distribution of the Work otherwise complies with
+ the conditions stated in this License.
+
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
+ any Contribution intentionally submitted for inclusion in the Work
+ by You to the Licensor shall be under the terms and conditions of
+ this License, without any additional terms or conditions.
+ Notwithstanding the above, nothing herein shall supersede or modify
+ the terms of any separate license agreement you may have executed
+ with Licensor regarding such Contributions.
+
+ 6. Trademarks. This License does not grant permission to use the trade
+ names, trademarks, service marks, or product names of the Licensor,
+ except as required for reasonable and customary use in describing the
+ origin of the Work and reproducing the content of the NOTICE file.
+
+ 7. Disclaimer of Warranty. Unless required by applicable law or
+ agreed to in writing, Licensor provides the Work (and each
+ Contributor provides its Contributions) on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+ implied, including, without limitation, any warranties or conditions
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
+ PARTICULAR PURPOSE. You are solely responsible for determining the
+ appropriateness of using or redistributing the Work and assume any
+ risks associated with Your exercise of permissions under this License.
+
+ 8. Limitation of Liability. In no event and under no legal theory,
+ whether in tort (including negligence), contract, or otherwise,
+ unless required by applicable law (such as deliberate and grossly
+ negligent acts) or agreed to in writing, shall any Contributor be
+ liable to You for damages, including any direct, indirect, special,
+ incidental, or consequential damages of any character arising as a
+ result of this License or out of the use or inability to use the
+ Work (including but not limited to damages for loss of goodwill,
+ work stoppage, computer failure or malfunction, or any and all
+ other commercial damages or losses), even if such Contributor
+ has been advised of the possibility of such damages.
+
+ 9. Accepting Warranty or Additional Liability. While redistributing
+ the Work or Derivative Works thereof, You may choose to offer,
+ and charge a fee for, acceptance of support, warranty, indemnity,
+ or other liability obligations and/or rights consistent with this
+ License. However, in accepting such obligations, You may act only
+ on Your own behalf and on Your sole responsibility, not on behalf
+ of any other Contributor, and only if You agree to indemnify,
+ defend, and hold each Contributor harmless for any liability
+ incurred by, or claims asserted against, such Contributor by reason
+ of your accepting any such warranty or additional liability.
+
+ END OF TERMS AND CONDITIONS
+
+ APPENDIX: How to apply the Apache License to your work.
+
+ To apply the Apache License to your work, attach the following
+ boilerplate notice, with the fields enclosed by brackets "[]"
+ replaced with your own identifying information. (Don't include
+ the brackets!) The text should be enclosed in the appropriate
+ comment syntax for the file format. We also recommend that a
+ file or class name and description of purpose be included on the
+ same "printed page" as the copyright notice for easier
+ identification within third-party archives.
+
+ Copyright [yyyy] [name of copyright owner]
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
http://git-wip-us.apache.org/repos/asf/couchdb/blob/dc375701/src/couchjs-node/README.md
----------------------------------------------------------------------
diff --git a/src/couchjs-node/README.md b/src/couchjs-node/README.md
new file mode 100644
index 0000000..c686e80
--- /dev/null
+++ b/src/couchjs-node/README.md
@@ -0,0 +1,54 @@
+# CouchJS
+
+## Drop-in replacement JavaScript engine for Apache CouchDB
+
+CouchJS is a command-line Node.js program. It is 100% compatible with Apache CouchDB's built-in JavaScript system.
+
+By using CouchJS, you will get 100% CouchDB compatibility (the test suite completely passes) but your JavaScript environment is V8, or Node.js.
+
+CouchJS is available as an npm module.
+
+ $ npm install -g couchjs
+
+## Usage
+
+Install CouchDB. Install this package with npm. Confirm your `couchjs` install location.
+
+ $ which couchjs # Note, your path will be different from mine.
+ /home/jhs/node/bin/couchjs
+
+Look at the CouchDB config for the JavaScript query server.
+
+ $ curl http://localhost:5984/_config/query_servers/javascript
+ "/home/jhs/couchdb/bin/couchjs /home/jhs/couchdb/share/couchdb/server/main.js"
+
+Change that to this `couchjs`. **Leave the second argument the same.**
+
+ $ curl -X PUT http://localhost:5984/_config/query_servers/javascript \
+ -H content-type:application/json \
+ -d "\"`which couchjs` /home/jhs/couchdb/share/couchdb/server/main.js\""
+
+Done!
+
+## Idea
+
+JavaScript is decoupled from the CouchDB core. To do JavaScript stuff, CouchDB runs a normal Unix subprocess, `couchjs`. This subprocess is just a read-eval-print loop on standard i/o. CouchDB passes `couchjs` a file name, and *that file* contains the view server implementation.
+
+This tool duplicates the "REPL" look and feel of `couchjs` and supports the exact same view server implementation.
+
+## Security
+
+I have no idea. I would not trust it for production use.
+
+## Log
+
+If you create a file, `/tmp/couchjs.log` then *couchjs* will output debugging messages there.
+
+## License
+
+Apache 2.0
+
+See the [Apache 2.0 license](named/blob/master/LICENSE).
+
+[tap]: https://github.com/isaacs/node-tap
+[def]: https://github.com/iriscouch/defaultable
http://git-wip-us.apache.org/repos/asf/couchdb/blob/dc375701/src/couchjs-node/checkout.sh
----------------------------------------------------------------------
diff --git a/src/couchjs-node/checkout.sh b/src/couchjs-node/checkout.sh
new file mode 100644
index 0000000..0076b51
--- /dev/null
+++ b/src/couchjs-node/checkout.sh
@@ -0,0 +1,36 @@
+# Copyright 2011 Iris Couch
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+repo="$1"
+commit="$2"
+
+if [ -z "$repo" -o ! -d "$repo" ]; then
+ echo "Not a valid repo: $repo" >&2
+ exit 1
+fi
+if [ -z "$commit" ]; then
+ echo "Not a valid commit: $commit" >&2
+ exit 1
+fi
+
+echo "Clone $repo:$commit to $(pwd)"
+
+set -e
+
+git clone "$repo" .
+git checkout "$commit"
+
+if [ -z "$skip_npm_install" ]; then
+ npm install --production
+fi
http://git-wip-us.apache.org/repos/asf/couchdb/blob/dc375701/src/couchjs-node/cli.js
----------------------------------------------------------------------
diff --git a/src/couchjs-node/cli.js b/src/couchjs-node/cli.js
new file mode 100755
index 0000000..14a6d97
--- /dev/null
+++ b/src/couchjs-node/cli.js
@@ -0,0 +1,85 @@
+#!/usr/bin/env node
+//
+// couchjs replacement
+//
+// Copyright 2011 Iris Couch
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+var fs = require('fs')
+var util = require('util')
+var Fiber = require('fibers')
+var optimist = require('optimist')
+var child_process = require('child_process')
+
+var couchjs = require('./couchjs')
+var package_json = require('./package.json')
+var couchdb_extra = require('./extra')
+var LineStream = require('./stream')
+var inspector = require('./inspector')
+var log = require('./console').log
+
+
+var opts = optimist.boolean(['h', 'V', 'H'])
+ .describe({ 'h': 'display a short help message and exit'
+ , 'V': 'display version information and exit'
+ , 'H': 'enable couchjs cURL bindings (not implemented)'
+ })
+ .boolean('extra')
+ .describe('extra', 'Extra features for CouchDB, for os_daemons')
+ .usage('$0 <path to main.js>')
+
+
+function main() {
+ if(opts.argv.extra)
+ return couchdb_extra()
+
+ var main_js = opts.argv._[0]
+ if(!main_js)
+ return console.error(opts.help())
+
+ log('couchjs/%s %s: %s', package_json.version, process.pid, main_js)
+ if(process.env.COUCHJS_DEBUG_PORT)
+ inspector(+process.env.COUCHJS_DEBUG_PORT)
+
+ fs.readFile(main_js, 'utf8', function(er, body) {
+ if(er)
+ throw er
+
+ var stdin = new LineStream.v2
+ stdin.on('readable', function() {
+ var buf = stdin.read()
+ if(buf)
+ couchjs.stdin(buf)
+ })
+ stdin.on('end', function() {
+ log('Terminate; connection to parent closed')
+ process.exit(0)
+ })
+
+ process.stdin.setEncoding('utf8')
+ process.stdin.pipe(stdin)
+
+ var main_func = Function(['print', 'readline', 'evalcx', 'gc', 'quit'], body)
+
+ log('Call main')
+ Fiber(function() { main_func(couchjs.print, couchjs.readline, couchjs.evalcx, couchjs.gc) }).run()
+ })
+
+ process.on('uncaughtException', function(er) {
+ log('Error:\n%s', er.stack)
+ })
+}
+
+if(require.main === module)
+ main()
http://git-wip-us.apache.org/repos/asf/couchdb/blob/dc375701/src/couchjs-node/console.js
----------------------------------------------------------------------
diff --git a/src/couchjs-node/console.js b/src/couchjs-node/console.js
new file mode 100644
index 0000000..2a0a17a
--- /dev/null
+++ b/src/couchjs-node/console.js
@@ -0,0 +1,65 @@
+// Copyright 2011 Iris Couch
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+var fs = require('fs')
+var util = require('util')
+
+
+module.exports = {}
+module.exports.log = noop
+module.exports.debug = noop
+module.exports.info = noop
+module.exports.warn = noop
+module.exports.error = noop
+
+var LOG_PATH = '/tmp/couchjs.log'
+ , stat = null
+ , LOG = null
+
+try {
+ stat = fs.statSync(LOG_PATH)
+} catch(er) {}
+
+if(stat) {
+ LOG = fs.createWriteStream(LOG_PATH, {'flags':'a'})
+
+ module.exports.log = log
+ module.exports.debug = log
+ module.exports.info = log
+ module.exports.warn = log
+ module.exports.error = log
+
+ process.on('exit', function() {
+ module.exports.log('Exit %d', process.pid)
+ })
+
+ process.on('uncaughtException', on_err)
+}
+
+function log() {
+ var str = util.format.apply(this, arguments)
+ LOG.write(str + '\n')
+}
+
+function on_err(er) {
+ module.exports.error('Uncaught error:\n%s', er.stack || er.message || JSON.stringify(er))
+
+ if(er.stack)
+ er = ['fatal', 'unknown_error', er.stack]
+
+ process.stdout.write(JSON.stringify(er) + '\n')
+ process.exit(1)
+}
+
+function noop() {}
http://git-wip-us.apache.org/repos/asf/couchdb/blob/dc375701/src/couchjs-node/couchdb.js
----------------------------------------------------------------------
diff --git a/src/couchjs-node/couchdb.js b/src/couchjs-node/couchdb.js
new file mode 100755
index 0000000..d297112
--- /dev/null
+++ b/src/couchjs-node/couchdb.js
@@ -0,0 +1,29 @@
+// Copyright 2011 Iris Couch
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+module.exports = handler
+
+var http = require('http')
+
+function handler(req, res) {
+ res.writeHead(200)
+ res.end('Hello: ' + req.url + '\n')
+}
+
+if(require.main === module) {
+ var http = require('http')
+ var server = http.createServer(handler)
+ server.listen(3000)
+ console.log('Listening on :3000')
+}
http://git-wip-us.apache.org/repos/asf/couchdb/blob/dc375701/src/couchjs-node/couchjs.js
----------------------------------------------------------------------
diff --git a/src/couchjs-node/couchjs.js b/src/couchjs-node/couchjs.js
new file mode 100644
index 0000000..d95341d
--- /dev/null
+++ b/src/couchjs-node/couchjs.js
@@ -0,0 +1,116 @@
+// Copyright 2011 Iris Couch
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+module.exports = { 'print' : print
+ , 'readline': readline
+ , 'stdin' : stdin
+ , 'evalcx' : evalcx
+ , 'quit' : quit
+ , 'gc' : gc
+ }
+
+
+var vm = require('vm')
+var Fiber = require('fibers')
+
+var XML = require('./xml')
+var log = require('./console').log
+
+var INPUT = {'queue':[], 'waiting':null}
+
+Error.prototype.toSource = Error.prototype.toSource || toSource
+Error.prototype.toString = Error.prototype.toString || toSource
+Function.prototype.toSource = Function.prototype.toSource || toSource
+Function.prototype.toString = Function.prototype.toString || toSource
+
+
+function print(line) {
+ log('STDOUT %s: %s', process.pid, line)
+ process.stdout.write(line + '\n')
+
+ try {
+ line = JSON.parse(line)
+ } catch(er) { return }
+
+ if(line[0] == 'log')
+ log('LOG: %s', line[1])
+}
+
+function stdin(line) {
+ log('STDIN %s: %s', process.pid, line.trim())
+ if(INPUT.waiting)
+ INPUT.waiting.run(line)
+ else
+ INPUT.queue.push(line)
+}
+
+function readline() {
+ var line = INPUT.queue.shift()
+ if(line)
+ return line
+
+ INPUT.waiting = Fiber.current
+ line = Fiber.yield()
+ INPUT.waiting = null
+
+ return line
+}
+
+
+function evalcx(source, sandbox) {
+ sandbox = sandbox || {}
+ //log('evalcx in %j: %j', Object.keys(sandbox), source)
+
+ if(source == '')
+ return sandbox
+
+ // source might be "function(doc) { emit(doc._id, 1) }"
+ source = source.replace(/;+$/, '')
+
+ sandbox.XML = sandbox.XML || XML
+ source = '(' + source + ')'
+
+ try {
+ var id = Math.floor(Math.random() * 1000*1000)
+ var filename = '_couchdb:' + id + '.js'
+ var script = vm.createScript(source, filename)
+ var func = script.runInNewContext(sandbox)
+ } catch (er) {
+ log('Error making code: %s', er.stack)
+ return sandbox
+ }
+
+ return func
+}
+
+function quit(code) {
+ code = code || 1
+ if(code < 0)
+ code = -code
+
+ process.exit(code)
+}
+
+function gc() { }
+
+
+function toSource() {
+ if(typeof this == 'function')
+ return '' + this
+
+ if(this instanceof Error)
+ return this.stack
+
+ return util.inspect(this)
+}
http://git-wip-us.apache.org/repos/asf/couchdb/blob/dc375701/src/couchjs-node/extra.js
----------------------------------------------------------------------
diff --git a/src/couchjs-node/extra.js b/src/couchjs-node/extra.js
new file mode 100755
index 0000000..2df0168
--- /dev/null
+++ b/src/couchjs-node/extra.js
@@ -0,0 +1,346 @@
+#!/usr/bin/env node
+// Copyright 2011 Iris Couch
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+module.exports = main
+
+var os = require('os')
+var fs = require('fs')
+var URL = require('url')
+var util = require('util')
+var http = require('http')
+var async = require('async')
+var mkdirp = require('mkdirp')
+var request = require('request')
+var optimist = require('optimist')
+var pushover = require('pushover')
+var child_process = require('child_process')
+
+var console = require('./console')
+var VER = require('./package.json').version
+
+var couch = { 'log': mk_couch_log('info')
+ , 'warn' : mk_couch_log('warn')
+ , 'error': mk_couch_log('error')
+ , 'debug': mk_couch_log('debug')
+ }
+
+
+var opts = optimist.usage('$0')
+
+var COUCH = null
+var GIT_DIR = null
+var COUCH_PASSWORD = null
+var GIT_PORT = null
+var APPLICATION = null
+
+function main() {
+ if(opts.argv.help)
+ return console.log(opts.help())
+
+ console.log('Extra CouchDB daemon: %s', process.pid)
+ couch.debug('CouchDB daemon %s: %s', VER, process.pid)
+
+ var env = {}
+ for (var k in process.env) {
+ var match = k.match(/^_couchdb_app_(.*)$/)
+ if(match)
+ env[match[1]] = process.env[k]
+ }
+
+ for (k in env)
+ couch.debug(' %s = %s', k, env[k])
+
+ if(env.port && env.password && env.couch && env.dir)
+ return git(env)
+
+ setInterval(function() {
+ console.log('Still here')
+ couch.log('Still in couch')
+ }, 60000)
+}
+
+function git(env) {
+ GIT_PORT = +env.port
+ COUCH = env.couch
+ COUCH_DIR = util.format('%s/couchjs-%s', env.dir, VER)
+ COUCH_PASSWORD = env.password
+
+ //var couch_url = util.format('http://_nodejs:%s@127.0.0.1:%d', password, couch_port)
+ //couch.log('couch url %j', couch_url)
+
+ auth('_nodejs', COUCH_PASSWORD, function(er, userCtx) {
+ if(er)
+ throw er
+
+ var roles = userCtx.roles || []
+ if(userCtx.name != '_nodejs' || !~roles.indexOf('_admin'))
+ throw new Error('Not admin: ' + JSON.stringify(res.body.userCtx))
+
+ var repos = pushover(COUCH_DIR)
+ repos.on('push', function(push) {
+ couch.log('Push %s/%s: %s', push.repo, push.commit, push.branch)
+ push.accept()
+ //couch.log('Response: %j', Object.keys(push.response))
+ push.response.on('finish', function() {
+ //couch.log('Finished!')
+ publish(push)
+ })
+ })
+
+ repos.on('fetch', function(fetch) {
+ couch.log('fetch %j', fetch.commit)
+ fetch.accept()
+ })
+
+ var server = http.createServer(function(req, res) {
+ if(! req.url.match(/^\/_nodejs\/_git(\/|$)/))
+ return handle_http(req, res)
+
+ req.pause()
+ auth_req(req, function(er, userCtx) {
+ if(er && er.statusCode) {
+ res.writeHead(er.statusCode, er.headers)
+ return res.end(er.body)
+ }
+
+ if(er) {
+ couch.log('Bad req %s: %s', req.url, er.message)
+ return res.end()
+ }
+
+ var roles = userCtx.roles || []
+ if(!~ roles.indexOf('_admin')) {
+ couch.log('Not admin: %s, %j', req.url, userCtx)
+ res.writeHead(401, 'Unauthorized', {'content-type':'application/json'})
+ return res.end('{"error":"not_authorized"}\n')
+ }
+
+ //couch.log('Handle Git: %j', req.url)
+ repos.handle(req, res)
+ req.resume()
+ })
+ })
+
+ server.listen(GIT_PORT)
+ })
+}
+
+function handle_http(req, res) {
+ if(! APPLICATION) {
+ var headers = { 'content-type': 'application/json'
+ , 'server': 'NodeJS-CouchDB/'+VER
+ }
+ res.writeHead(200, 'OK', headers)
+ var body = {'ok':true}
+ return res.end(JSON.stringify(body) + '\n')
+ }
+
+ // Clean up the vhost changes.
+ var vhost_path = req.headers['x-couchdb-vhost-path']
+ if(vhost_path) {
+ req.url = vhost_path
+ delete req.headers['x-couchdb-vhost-path']
+ }
+
+ APPLICATION(req, res)
+}
+
+function auth(user, pass, callback) {
+ if(!COUCH)
+ return process.nextTick(function() { callback(new Error('No _couchdb_port')) })
+
+ var url = COUCH + '/_session'
+ if(user || pass) {
+ url = URL.parse(url)
+ url.auth = util.format('%s:%s', user || '', pass || '')
+ url = URL.format(url)
+ }
+
+ //couch.log('auth: %j', url)
+ request({'url':url, 'json':true}, function(er, res) {
+ //couch.log('auth result: %j', res.body)
+ if(er)
+ return callback(er)
+
+ if(res.statusCode != 200) {
+ er = new Error('Bad status '+res.statusCode+' for auth: ' + res.body)
+ er.statusCode = res.statusCode
+ er.body = JSON.stringify(res.body) + '\n'
+ er.headers = res.headers
+ return callback(er)
+ }
+
+ return callback(null, res.body.userCtx)
+ })
+}
+
+function auth_req(req, callback) {
+ var headers = req.headers || {}
+ var auth_str = req.headers.authorization || ''
+
+ var match = auth_str.match(/^Basic (.+)$/)
+ if(!match)
+ return auth(null, null, callback)
+
+ try {
+ auth_str = new Buffer(match[1], 'base64').toString()
+ match = auth_str.match(/^([^:]+):(.+)$/)
+ } catch (er) {
+ return callback(er)
+ }
+
+ if(!match)
+ return callback(new Error('Bad auth string: ' + auth_str))
+
+ auth(match[1], match[2], callback)
+}
+
+
+function publish(push) {
+ var script = __dirname + '/checkout.sh'
+ var repo = COUCH_DIR + '/' + push.repo
+
+ var id = Math.floor(Math.random() * 1000 * 1000)
+ var work = util.format('%s/%s/%s', COUCH_DIR, push.commit, id)
+
+ mkdirp(work, function(er) {
+ if(er) {
+ couch.error('Failed to make working dir: %s', work)
+ throw er
+ }
+
+ checkout()
+ })
+
+ function checkout() {
+ var args = [script, repo, push.commit]
+ var opts = { 'cwd':work, 'stdio':'pipe' }
+
+ var child = child_process.spawn('bash', args, opts)
+
+ var output = []
+
+ child.stdout.on('data', function(x) {
+ var msg = util.format('OUT %s', x.toString().trim())
+ couch.debug(msg)
+ output.push(msg)
+ })
+ child.stderr.on('data', function(x) {
+ var msg = util.format('ERR %s', x.toString().trim())
+ couch.debug(msg)
+ output.push(msg)
+ })
+
+ child.on('exit', function(code) {
+ if(code !== 0) {
+ couch.error('Bad checkout: %d', code)
+ output.forEach(function(line) {
+ couch.error(line)
+ })
+
+ throw new Error('Bad checkout')
+ }
+
+ couch.log('Checked out push: %s', work)
+ fs.readFile(work+'/package.json', 'utf8', function(er, body) {
+ if(er)
+ throw er
+
+ body = JSON.parse(body)
+ if(!body.couchdb)
+ return couch.warn('No "couchdb" value in pushed package.json')
+
+ run_app(work, body)
+ })
+ })
+ }
+}
+
+
+function run_app(work_dir, pkg) {
+ var vhosts = []
+ , main = null
+
+ if(typeof pkg.couchdb == 'string')
+ main = pkg.couchdb
+ else {
+ vhosts = pkg.couchdb.vhosts || []
+ main = pkg.couchdb.main
+ }
+
+ couch.log('Run app %s: %j', main, vhosts)
+
+ var mod_path = util.format('%s/%s', work_dir, main)
+ try {
+ var ok = require.resolve(mod_path)
+ } catch (er) {
+ return couch.error('Bad module path: %s', mod_path)
+ }
+
+ couch_mod = require(mod_path)
+ APPLICATION = couch_mod
+ couch.log('Installed CouchDB application')
+
+ return async.forEach(vhosts, set_vhost, vhosts_set)
+
+ function set_vhost(vhost, to_async) {
+ var couch_url = URL.parse(COUCH)
+ couch_url.auth = '_nodejs:' + COUCH_PASSWORD
+ couch_url = URL.format(couch_url)
+ couch.log('couch_url: %j', couch_url)
+
+ var url = couch_url + '_config/vhosts/' + vhost
+ var body = '/_nodejs'
+ request.put({'url':url, 'json':body}, function(er, res) {
+ if(er)
+ return to_async(er)
+ if(res.statusCode != 200)
+ return to_async(new Error('Bad response '+res.statusCode+' to vhost: ' + vhost))
+
+ couch.log('Set vhost: %s', vhost)
+ return to_async()
+ })
+ }
+
+ function vhosts_set(er) {
+ if(er)
+ throw er
+
+ couch.log('Set %d vhosts for CouchDB application', vhosts.length)
+ }
+}
+
+
+//
+// Utilities
+//
+
+function mk_couch_log(level) {
+ if(level == 'warn')
+ level = 'error'
+
+ return logger
+
+ function logger() {
+ var str = util.format.apply(util, arguments)
+ var msg = ['log', str, {'level':level}]
+ msg = JSON.stringify(msg)
+ process.stdout.write(msg + '\n')
+ }
+}
+
+
+if(require.main === module)
+ main()
http://git-wip-us.apache.org/repos/asf/couchdb/blob/dc375701/src/couchjs-node/inspector.js
----------------------------------------------------------------------
diff --git a/src/couchjs-node/inspector.js b/src/couchjs-node/inspector.js
new file mode 100755
index 0000000..efa9856
--- /dev/null
+++ b/src/couchjs-node/inspector.js
@@ -0,0 +1,92 @@
+#!/usr/bin/env node
+//
+// couchjs replacement
+//
+// Copyright 2011 Iris Couch
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+module.exports = start
+
+if(require.main === module)
+ main()
+
+
+var fs = require('fs')
+var util = require('util')
+var child_process = require('child_process')
+
+var log = require('./console').log
+
+function start(debugPort) {
+ if(!debugPort || typeof debugPort != 'number')
+ throw new Error('Need a listen debugPort')
+ var webPort = debugPort + 1
+
+ var cmd = __filename
+ var args = [debugPort, webPort]
+ var opts =
+ { 'cwd': __dirname
+ , 'stdio': 'pipe'
+ , 'detached': false
+ }
+
+ log('Start inspector: %s %j %j', cmd, args, opts)
+ var inspector = child_process.spawn(cmd, args, opts)
+ watch_inspector(inspector)
+
+ log('Enable remote debug pid=%d port=%d', process.pid, debugPort)
+ process.debugPort = debugPort
+ process.kill(process.pid, 'SIGUSR1')
+}
+
+function watch_inspector(child) {
+ child.stderr.on('data', function(body) {
+ log('Inspector STDERR: %s', body)
+ })
+ child.stdout.on('data', function(body) {
+ log('Inspector STDOUT: %s', body)
+ })
+
+ child.on('exit', function(code, signal) {
+ log('Inspector exited %d signal=%j', code, signal)
+ process.exit(code)
+ })
+
+ process.on('exit', function() {
+ log('Kill inspector upon exit: %d', child.pid)
+ process.kill(child.pid, 'SIGTERM')
+ })
+}
+
+
+function main() {
+ var debugPort = +process.argv[2]
+ var webPort = +process.argv[3]
+
+ if(!debugPort || !webPort)
+ throw new Error('Bad arguments: need debugPort and webPort')
+
+ console.log('Start inspector debugPort=%j webPort=%j', debugPort, webPort)
+ var DebugServer = require('node-inspector/lib/debug-server')
+ var server = new DebugServer
+ server.on('close', function() {
+ console.log('Server closed')
+ process.exit(0)
+ })
+
+ server.start({'webPort':webPort, 'debugPort':debugPort})
+ process.on('uncaughtException', function(er) {
+ console.log('Error:\n%s', er.stack)
+ })
+}
http://git-wip-us.apache.org/repos/asf/couchdb/blob/dc375701/src/couchjs-node/package.json
----------------------------------------------------------------------
diff --git a/src/couchjs-node/package.json b/src/couchjs-node/package.json
new file mode 100644
index 0000000..665888c
--- /dev/null
+++ b/src/couchjs-node/package.json
@@ -0,0 +1,30 @@
+{ "name": "couchjs"
+, "description": "Drop-in replacement for CouchDB JavaScript view server"
+, "keywords": [ "couchdb", "couchjs" ]
+, "version": "0.3.2"
+, "author": "Jason Smith <jh...@iriscouch.com> (http://www.iriscouch.com)"
+, "repository": { "type":"git", "url":"https://github.com/iriscouch/couchjs" }
+
+, "engines": { "node": ">= 0.8" }
+, "main": "./couchjs.js"
+, "bin": {"couchjs-node":"./cli.js", "couchjs-extra":"./extra.js"}
+
+, "couchdb": { "main":"./couchdb.js"
+ , "vhosts": ["127.0.0.1.xip.io"]
+ }
+
+, "bundledDependencies": ["node-inspector"]
+
+, "dependencies": { "optimist": "~0.3.4"
+ , "async" : "~0.2.5"
+ , "mkdirp" : "~0.3.4"
+ , "fibers" : "~1.0.0"
+ , "request" : "~2.9.203"
+ , "pushover": "~1.2.1"
+ , "defaultable": "~0.7.2"
+ , "node-inspector": "git://github.com/iriscouch/node-inspector#couchjs"
+ }
+
+, "devDependencies": { "tap": "~0.2.5"
+ }
+}
http://git-wip-us.apache.org/repos/asf/couchdb/blob/dc375701/src/couchjs-node/stream.js
----------------------------------------------------------------------
diff --git a/src/couchjs-node/stream.js b/src/couchjs-node/stream.js
new file mode 100644
index 0000000..90deda1
--- /dev/null
+++ b/src/couchjs-node/stream.js
@@ -0,0 +1,107 @@
+// Text line stream
+//
+// Copyright 2011 Iris Couch
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+module.exports = LineStream
+module.exports.v2 = LineStream2
+
+var stream = require('stream')
+var util = require('util')
+
+
+util.inherits(LineStream2, stream.Transform)
+function LineStream2 () {
+ if(! (this instanceof LineStream2))
+ return new LineStream2
+
+ stream.Transform.call(this)
+ this.setEncoding('utf8')
+}
+
+LineStream2.prototype._transform = function(message, encoding, done) {
+ var self = this
+
+ message = message.toString(encoding)
+ var lines = message.split(/\n/)
+
+ // If the data ends in "\n" this will be ""; otherwise the final partial line.
+ var remainder = lines.pop()
+ if(remainder)
+ this.unshift(remainder)
+
+ lines.forEach(function(line) {
+ self.push(line)
+ })
+
+ done()
+}
+
+util.inherits(LineStream, stream)
+function LineStream () {
+ var self = this
+ stream.call(self)
+
+ self.readable = true
+ self.writable = true
+
+ self.buffer = ''
+ self.downstream = null
+
+ self.on('pipe', function(upstream) {
+ upstream.on('end', function(data, encoding) {
+ self.emit('end', data, encoding)
+ })
+ })
+}
+
+
+LineStream.prototype.write = function(data, encoding) {
+ var self = this
+
+ data = data || ''
+ if(typeof data != 'string')
+ return self.error(new Error('Data was not a string: ' + util.inspect(data)))
+
+ self.buffer += data
+ var lines = self.buffer.split(/\n/)
+ self.buffer = lines.pop() // If the data ended in "\n" this will be ""; otherwise the final partial line.
+
+ lines.forEach(function(line) {
+ self.emit('data', line)
+ })
+}
+
+
+LineStream.prototype.end = function(data, encoding) {
+ var self = this
+
+ self.is_ending = true
+ self.writable = false
+
+ // Always call write, even with no data, so it can fire the "end" event.
+ self.write(data)
+}
+
+
+LineStream.prototype.error = function(er) {
+ var self = this
+
+ self.readable = false
+ self.writable = false
+ self.emit('error', er)
+
+ // The write() method sometimes returns this value, so if there was an error, make write() return false.
+ return false
+}
http://git-wip-us.apache.org/repos/asf/couchdb/blob/dc375701/src/couchjs-node/test/experiment.js
----------------------------------------------------------------------
diff --git a/src/couchjs-node/test/experiment.js b/src/couchjs-node/test/experiment.js
new file mode 100644
index 0000000..54a5ab4
--- /dev/null
+++ b/src/couchjs-node/test/experiment.js
@@ -0,0 +1,105 @@
+var vm = require('vm')
+var util = require('util')
+
+var STATE = 'wait'
+ , v = 'vm'
+
+function main() {
+ process.debugPort = 5859
+ process.kill(process.pid, 'SIGUSR1')
+
+ setTimeout(function() { stuff(0) }, 1000)
+}
+
+function stuff(count) {
+ console.log('Doing stuff: %d', count)
+ //debugger
+ STATE = 'vm'
+ console.log('More stuff: %d', count)
+ if(STATE == 'done')
+ console.log('Done')
+ else if(STATE == 'code')
+ setTimeout(code, 1000)
+ else if(STATE == 'eval')
+ test_eval()
+ else if(STATE == 'vm')
+ test_vm()
+ else if(STATE == 'wait')
+ setTimeout(function() { stuff(count+1) }, 1000)
+ else
+ throw new Error('Unknown state: ' + STATE)
+}
+
+function code() {
+ var code =
+ [ 'var foo = "in the code"'
+ , 'console.log("This is some code")'
+ , 'debugger'
+ , 'console.log("foo = " + foo)'
+ ].join('\n')
+
+ var runner = Function([], code)
+ console.log('Run runner in 1s')
+ setTimeout(run_runner, 1000)
+
+ function run_runner() {
+ console.log('About to run runner')
+ debugger
+ runner()
+ console.log('Runner done')
+ }
+}
+
+function test_eval() {
+ console.log('Test eval in 1s')
+ setTimeout(run_eval, 1000)
+
+ var code =
+ [ 'var foo = "in eval"'
+ , 'console.log("This is eval")'
+ , 'debugger'
+ , 'console.log("foo = " + foo)'
+ ].join('\n')
+
+ function run_eval() {
+ console.log('Run eval now')
+ debugger
+ eval(code)
+ }
+}
+
+function test_vm() {
+ console.log('Test vm')
+
+ var code =
+ [ 'var i = 10'
+ , 'setTimeout(hello, 1000)'
+ , ''
+ , 'function hello() {'
+ , ' debugger'
+ , ' console.log("Hello: " + i)'
+ , ' if(--i)'
+ , ' setTimeout(hello, 1000)'
+ , '}'
+ ].join('\n')
+
+ console.log('Run vm now')
+ var filename = '_couchdb:code.js'
+
+ var sandbox = {}
+ , ok = ['console', 'setTimeout']
+
+ ok.forEach(function(key) {
+ sandbox[key] = global[key]
+ })
+
+ var ctx = vm.createContext(sandbox)
+ var script = vm.createScript(code, filename)
+
+ var r = script.runInNewContext(sandbox)
+ console.log('Result:\n%s', util.inspect(r, false, 10))
+ return r
+}
+
+if(require.main === module)
+ main()
http://git-wip-us.apache.org/repos/asf/couchdb/blob/dc375701/src/couchjs-node/xml.js
----------------------------------------------------------------------
diff --git a/src/couchjs-node/xml.js b/src/couchjs-node/xml.js
new file mode 100644
index 0000000..c81525b
--- /dev/null
+++ b/src/couchjs-node/xml.js
@@ -0,0 +1,23 @@
+// Copyright 2011 Iris Couch
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+module.exports = XML
+
+function XML () {
+ this.foo = 'bar'
+}
+
+XML.prototype.toXMLString = function() {
+ return '<xml>\n <title>test</title>\n</xml>'
+}
[05/17] git commit: updated refs/heads/master to 532100c
Posted by ja...@apache.org.
handle extras
Project: http://git-wip-us.apache.org/repos/asf/couchdb/repo
Commit: http://git-wip-us.apache.org/repos/asf/couchdb/commit/8d0e7491
Tree: http://git-wip-us.apache.org/repos/asf/couchdb/tree/8d0e7491
Diff: http://git-wip-us.apache.org/repos/asf/couchdb/diff/8d0e7491
Branch: refs/heads/master
Commit: 8d0e74915d07786c38a3c1bd8a13bdda67a4b028
Parents: 93fd37b
Author: Jan Lehnardt <ja...@apache.org>
Authored: Sat Sep 21 16:16:13 2013 +0200
Committer: Jan Lehnardt <ja...@apache.org>
Committed: Thu Oct 3 17:21:29 2013 +0200
----------------------------------------------------------------------
src/couchjs-node/checkout.sh | 36 ----
src/couchjs-node/cli.js | 6 -
src/couchjs-node/extra.js | 346 --------------------------------------
3 files changed, 388 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/couchdb/blob/8d0e7491/src/couchjs-node/checkout.sh
----------------------------------------------------------------------
diff --git a/src/couchjs-node/checkout.sh b/src/couchjs-node/checkout.sh
deleted file mode 100644
index 0076b51..0000000
--- a/src/couchjs-node/checkout.sh
+++ /dev/null
@@ -1,36 +0,0 @@
-# Copyright 2011 Iris Couch
-#
-# Licensed under the Apache License, Version 2.0 (the "License");
-# you may not use this file except in compliance with the License.
-# You may obtain a copy of the License at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-
-repo="$1"
-commit="$2"
-
-if [ -z "$repo" -o ! -d "$repo" ]; then
- echo "Not a valid repo: $repo" >&2
- exit 1
-fi
-if [ -z "$commit" ]; then
- echo "Not a valid commit: $commit" >&2
- exit 1
-fi
-
-echo "Clone $repo:$commit to $(pwd)"
-
-set -e
-
-git clone "$repo" .
-git checkout "$commit"
-
-if [ -z "$skip_npm_install" ]; then
- npm install --production
-fi
http://git-wip-us.apache.org/repos/asf/couchdb/blob/8d0e7491/src/couchjs-node/cli.js
----------------------------------------------------------------------
diff --git a/src/couchjs-node/cli.js b/src/couchjs-node/cli.js
index 14a6d97..a835cab 100755
--- a/src/couchjs-node/cli.js
+++ b/src/couchjs-node/cli.js
@@ -24,7 +24,6 @@ var child_process = require('child_process')
var couchjs = require('./couchjs')
var package_json = require('./package.json')
-var couchdb_extra = require('./extra')
var LineStream = require('./stream')
var inspector = require('./inspector')
var log = require('./console').log
@@ -35,15 +34,10 @@ var opts = optimist.boolean(['h', 'V', 'H'])
, 'V': 'display version information and exit'
, 'H': 'enable couchjs cURL bindings (not implemented)'
})
- .boolean('extra')
- .describe('extra', 'Extra features for CouchDB, for os_daemons')
.usage('$0 <path to main.js>')
function main() {
- if(opts.argv.extra)
- return couchdb_extra()
-
var main_js = opts.argv._[0]
if(!main_js)
return console.error(opts.help())
http://git-wip-us.apache.org/repos/asf/couchdb/blob/8d0e7491/src/couchjs-node/extra.js
----------------------------------------------------------------------
diff --git a/src/couchjs-node/extra.js b/src/couchjs-node/extra.js
deleted file mode 100755
index 2df0168..0000000
--- a/src/couchjs-node/extra.js
+++ /dev/null
@@ -1,346 +0,0 @@
-#!/usr/bin/env node
-// Copyright 2011 Iris Couch
-//
-// Licensed under the Apache License, Version 2.0 (the "License");
-// you may not use this file except in compliance with the License.
-// You may obtain a copy of the License at
-//
-// http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing, software
-// distributed under the License is distributed on an "AS IS" BASIS,
-// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-// See the License for the specific language governing permissions and
-// limitations under the License.
-
-module.exports = main
-
-var os = require('os')
-var fs = require('fs')
-var URL = require('url')
-var util = require('util')
-var http = require('http')
-var async = require('async')
-var mkdirp = require('mkdirp')
-var request = require('request')
-var optimist = require('optimist')
-var pushover = require('pushover')
-var child_process = require('child_process')
-
-var console = require('./console')
-var VER = require('./package.json').version
-
-var couch = { 'log': mk_couch_log('info')
- , 'warn' : mk_couch_log('warn')
- , 'error': mk_couch_log('error')
- , 'debug': mk_couch_log('debug')
- }
-
-
-var opts = optimist.usage('$0')
-
-var COUCH = null
-var GIT_DIR = null
-var COUCH_PASSWORD = null
-var GIT_PORT = null
-var APPLICATION = null
-
-function main() {
- if(opts.argv.help)
- return console.log(opts.help())
-
- console.log('Extra CouchDB daemon: %s', process.pid)
- couch.debug('CouchDB daemon %s: %s', VER, process.pid)
-
- var env = {}
- for (var k in process.env) {
- var match = k.match(/^_couchdb_app_(.*)$/)
- if(match)
- env[match[1]] = process.env[k]
- }
-
- for (k in env)
- couch.debug(' %s = %s', k, env[k])
-
- if(env.port && env.password && env.couch && env.dir)
- return git(env)
-
- setInterval(function() {
- console.log('Still here')
- couch.log('Still in couch')
- }, 60000)
-}
-
-function git(env) {
- GIT_PORT = +env.port
- COUCH = env.couch
- COUCH_DIR = util.format('%s/couchjs-%s', env.dir, VER)
- COUCH_PASSWORD = env.password
-
- //var couch_url = util.format('http://_nodejs:%s@127.0.0.1:%d', password, couch_port)
- //couch.log('couch url %j', couch_url)
-
- auth('_nodejs', COUCH_PASSWORD, function(er, userCtx) {
- if(er)
- throw er
-
- var roles = userCtx.roles || []
- if(userCtx.name != '_nodejs' || !~roles.indexOf('_admin'))
- throw new Error('Not admin: ' + JSON.stringify(res.body.userCtx))
-
- var repos = pushover(COUCH_DIR)
- repos.on('push', function(push) {
- couch.log('Push %s/%s: %s', push.repo, push.commit, push.branch)
- push.accept()
- //couch.log('Response: %j', Object.keys(push.response))
- push.response.on('finish', function() {
- //couch.log('Finished!')
- publish(push)
- })
- })
-
- repos.on('fetch', function(fetch) {
- couch.log('fetch %j', fetch.commit)
- fetch.accept()
- })
-
- var server = http.createServer(function(req, res) {
- if(! req.url.match(/^\/_nodejs\/_git(\/|$)/))
- return handle_http(req, res)
-
- req.pause()
- auth_req(req, function(er, userCtx) {
- if(er && er.statusCode) {
- res.writeHead(er.statusCode, er.headers)
- return res.end(er.body)
- }
-
- if(er) {
- couch.log('Bad req %s: %s', req.url, er.message)
- return res.end()
- }
-
- var roles = userCtx.roles || []
- if(!~ roles.indexOf('_admin')) {
- couch.log('Not admin: %s, %j', req.url, userCtx)
- res.writeHead(401, 'Unauthorized', {'content-type':'application/json'})
- return res.end('{"error":"not_authorized"}\n')
- }
-
- //couch.log('Handle Git: %j', req.url)
- repos.handle(req, res)
- req.resume()
- })
- })
-
- server.listen(GIT_PORT)
- })
-}
-
-function handle_http(req, res) {
- if(! APPLICATION) {
- var headers = { 'content-type': 'application/json'
- , 'server': 'NodeJS-CouchDB/'+VER
- }
- res.writeHead(200, 'OK', headers)
- var body = {'ok':true}
- return res.end(JSON.stringify(body) + '\n')
- }
-
- // Clean up the vhost changes.
- var vhost_path = req.headers['x-couchdb-vhost-path']
- if(vhost_path) {
- req.url = vhost_path
- delete req.headers['x-couchdb-vhost-path']
- }
-
- APPLICATION(req, res)
-}
-
-function auth(user, pass, callback) {
- if(!COUCH)
- return process.nextTick(function() { callback(new Error('No _couchdb_port')) })
-
- var url = COUCH + '/_session'
- if(user || pass) {
- url = URL.parse(url)
- url.auth = util.format('%s:%s', user || '', pass || '')
- url = URL.format(url)
- }
-
- //couch.log('auth: %j', url)
- request({'url':url, 'json':true}, function(er, res) {
- //couch.log('auth result: %j', res.body)
- if(er)
- return callback(er)
-
- if(res.statusCode != 200) {
- er = new Error('Bad status '+res.statusCode+' for auth: ' + res.body)
- er.statusCode = res.statusCode
- er.body = JSON.stringify(res.body) + '\n'
- er.headers = res.headers
- return callback(er)
- }
-
- return callback(null, res.body.userCtx)
- })
-}
-
-function auth_req(req, callback) {
- var headers = req.headers || {}
- var auth_str = req.headers.authorization || ''
-
- var match = auth_str.match(/^Basic (.+)$/)
- if(!match)
- return auth(null, null, callback)
-
- try {
- auth_str = new Buffer(match[1], 'base64').toString()
- match = auth_str.match(/^([^:]+):(.+)$/)
- } catch (er) {
- return callback(er)
- }
-
- if(!match)
- return callback(new Error('Bad auth string: ' + auth_str))
-
- auth(match[1], match[2], callback)
-}
-
-
-function publish(push) {
- var script = __dirname + '/checkout.sh'
- var repo = COUCH_DIR + '/' + push.repo
-
- var id = Math.floor(Math.random() * 1000 * 1000)
- var work = util.format('%s/%s/%s', COUCH_DIR, push.commit, id)
-
- mkdirp(work, function(er) {
- if(er) {
- couch.error('Failed to make working dir: %s', work)
- throw er
- }
-
- checkout()
- })
-
- function checkout() {
- var args = [script, repo, push.commit]
- var opts = { 'cwd':work, 'stdio':'pipe' }
-
- var child = child_process.spawn('bash', args, opts)
-
- var output = []
-
- child.stdout.on('data', function(x) {
- var msg = util.format('OUT %s', x.toString().trim())
- couch.debug(msg)
- output.push(msg)
- })
- child.stderr.on('data', function(x) {
- var msg = util.format('ERR %s', x.toString().trim())
- couch.debug(msg)
- output.push(msg)
- })
-
- child.on('exit', function(code) {
- if(code !== 0) {
- couch.error('Bad checkout: %d', code)
- output.forEach(function(line) {
- couch.error(line)
- })
-
- throw new Error('Bad checkout')
- }
-
- couch.log('Checked out push: %s', work)
- fs.readFile(work+'/package.json', 'utf8', function(er, body) {
- if(er)
- throw er
-
- body = JSON.parse(body)
- if(!body.couchdb)
- return couch.warn('No "couchdb" value in pushed package.json')
-
- run_app(work, body)
- })
- })
- }
-}
-
-
-function run_app(work_dir, pkg) {
- var vhosts = []
- , main = null
-
- if(typeof pkg.couchdb == 'string')
- main = pkg.couchdb
- else {
- vhosts = pkg.couchdb.vhosts || []
- main = pkg.couchdb.main
- }
-
- couch.log('Run app %s: %j', main, vhosts)
-
- var mod_path = util.format('%s/%s', work_dir, main)
- try {
- var ok = require.resolve(mod_path)
- } catch (er) {
- return couch.error('Bad module path: %s', mod_path)
- }
-
- couch_mod = require(mod_path)
- APPLICATION = couch_mod
- couch.log('Installed CouchDB application')
-
- return async.forEach(vhosts, set_vhost, vhosts_set)
-
- function set_vhost(vhost, to_async) {
- var couch_url = URL.parse(COUCH)
- couch_url.auth = '_nodejs:' + COUCH_PASSWORD
- couch_url = URL.format(couch_url)
- couch.log('couch_url: %j', couch_url)
-
- var url = couch_url + '_config/vhosts/' + vhost
- var body = '/_nodejs'
- request.put({'url':url, 'json':body}, function(er, res) {
- if(er)
- return to_async(er)
- if(res.statusCode != 200)
- return to_async(new Error('Bad response '+res.statusCode+' to vhost: ' + vhost))
-
- couch.log('Set vhost: %s', vhost)
- return to_async()
- })
- }
-
- function vhosts_set(er) {
- if(er)
- throw er
-
- couch.log('Set %d vhosts for CouchDB application', vhosts.length)
- }
-}
-
-
-//
-// Utilities
-//
-
-function mk_couch_log(level) {
- if(level == 'warn')
- level = 'error'
-
- return logger
-
- function logger() {
- var str = util.format.apply(util, arguments)
- var msg = ['log', str, {'level':level}]
- msg = JSON.stringify(msg)
- process.stdout.write(msg + '\n')
- }
-}
-
-
-if(require.main === module)
- main()