├── .gitignore ├── .jscsrc ├── .jshintignore ├── .jshintrc ├── .npmignore ├── .rlxrc ├── .travis.yml ├── README.md ├── bin └── rlx ├── doc ├── cheatsheet.json ├── cheatsheet.md ├── man │ ├── rlx-admin.1 │ ├── rlx-alias.1 │ ├── rlx-application.1 │ ├── rlx-attach.1 │ ├── rlx-batch.1 │ ├── rlx-bulk.1 │ ├── rlx-config.1 │ ├── rlx-database.1 │ ├── rlx-document.1 │ ├── rlx-edit.1 │ ├── rlx-help.1 │ ├── rlx-http.1 │ ├── rlx-info.1 │ ├── rlx-interactive.1 │ ├── rlx-json.1 │ ├── rlx-level.1 │ ├── rlx-lint.1 │ ├── rlx-local.1 │ ├── rlx-log.1 │ ├── rlx-login.1 │ ├── rlx-logout.1 │ ├── rlx-replicate.1 │ ├── rlx-restart.1 │ ├── rlx-runconf.1 │ ├── rlx-security.1 │ ├── rlx-session.1 │ ├── rlx-stats.1 │ ├── rlx-system.1 │ ├── rlx-tasks.1 │ ├── rlx-tpl.1 │ ├── rlx-user.1 │ ├── rlx-uuids.1 │ ├── rlx-whoami.1 │ └── rlx.1 └── readme │ ├── developer.md │ ├── documentation.md │ ├── install.md │ ├── introduction.md │ ├── links.md │ └── quick-start.md ├── lib ├── before.js ├── boot.js ├── command │ ├── admin │ │ ├── add.js │ │ ├── get.js │ │ ├── index.js │ │ ├── ls.js │ │ └── rm.js │ ├── alias │ │ ├── add.js │ │ ├── edit.js │ │ ├── get.js │ │ ├── index.js │ │ ├── init.js │ │ ├── ls.js │ │ ├── parse.js │ │ ├── print.js │ │ └── rm.js │ ├── application │ │ ├── attach.js │ │ ├── cp.js │ │ ├── deploy.js │ │ ├── get.js │ │ ├── head.js │ │ ├── index.js │ │ ├── info.js │ │ ├── list.js │ │ ├── ls.js │ │ ├── push.js │ │ ├── rewrite.js │ │ ├── rm.js │ │ ├── show.js │ │ ├── update.js │ │ └── view.js │ ├── attach │ │ ├── dl.js │ │ ├── get.js │ │ ├── head.js │ │ ├── index.js │ │ ├── ls.js │ │ ├── rm.js │ │ └── up.js │ ├── batch │ │ ├── exec.js │ │ ├── index.js │ │ └── parse.js │ ├── bulk │ │ ├── index.js │ │ ├── ls.js │ │ ├── pull.js │ │ ├── push.js │ │ ├── revs.js │ │ └── rm.js │ ├── config │ │ ├── get.js │ │ ├── index.js │ │ ├── rm.js │ │ └── set.js │ ├── database │ │ ├── add.js │ │ ├── bulk.js │ │ ├── changes.js │ │ ├── cleanup.js │ │ ├── commit.js │ │ ├── compact.js │ │ ├── head.js │ │ ├── index.js │ │ ├── info.js │ │ ├── limit.js │ │ ├── ls.js │ │ ├── missing-revs.js │ │ ├── purge.js │ │ ├── revs-diff.js │ │ ├── rm.js │ │ ├── temp.js │ │ └── updates.js │ ├── document │ │ ├── add.js │ │ ├── conflicts.js │ │ ├── cp.js │ │ ├── dc.js │ │ ├── edit.js │ │ ├── get.js │ │ ├── head.js │ │ ├── index.js │ │ ├── ls.js │ │ ├── meta.js │ │ ├── rev.js │ │ ├── revs.js │ │ ├── revsinfo.js │ │ └── rm.js │ ├── edit.js │ ├── http │ │ ├── copy.js │ │ ├── del.js │ │ ├── get.js │ │ ├── head.js │ │ ├── index.js │ │ ├── post.js │ │ ├── put.js │ │ └── validate.js │ ├── info.js │ ├── interactive │ │ ├── cd.js │ │ ├── exit.js │ │ ├── index.js │ │ ├── open.js │ │ ├── pwd.js │ │ ├── shorthelp.js │ │ ├── su.js │ │ ├── welcome.js │ │ └── who.js │ ├── json │ │ ├── grep.js │ │ └── index.js │ ├── level │ │ ├── debug.js │ │ ├── error.js │ │ ├── get.js │ │ ├── index.js │ │ ├── info.js │ │ ├── none.js │ │ ├── set.js │ │ └── warn.js │ ├── lint.js │ ├── local │ │ ├── add.js │ │ ├── cp.js │ │ ├── get.js │ │ ├── index.js │ │ └── rm.js │ ├── log.js │ ├── login.js │ ├── logout.js │ ├── rc │ │ ├── dir.js │ │ ├── get.js │ │ ├── index.js │ │ ├── init.js │ │ ├── ls.js │ │ ├── print.js │ │ ├── rm.js │ │ └── set.js │ ├── replicate │ │ ├── add.js │ │ ├── index.js │ │ ├── ls.js │ │ └── rm.js │ ├── restart.js │ ├── security │ │ ├── edit.js │ │ ├── get.js │ │ ├── index.js │ │ ├── rm.js │ │ └── set.js │ ├── session │ │ ├── get.js │ │ ├── index.js │ │ ├── rm.js │ │ └── set.js │ ├── stats.js │ ├── system │ │ ├── auth.js │ │ ├── conf.js │ │ ├── dbh.js │ │ ├── dir.js │ │ ├── env.js │ │ ├── err.js │ │ ├── hist.js │ │ ├── index.js │ │ ├── jar.js │ │ ├── log.js │ │ ├── prg.js │ │ └── req.js │ ├── tasks.js │ ├── template │ │ ├── dir.js │ │ ├── dirs.js │ │ ├── index.js │ │ ├── init.js │ │ ├── ls.js │ │ ├── parse.js │ │ └── print.js │ ├── user │ │ ├── add.js │ │ ├── edit.js │ │ ├── get.js │ │ ├── index.js │ │ ├── ls.js │ │ ├── passwd.js │ │ ├── rm.js │ │ └── userdb.js │ ├── uuids.js │ └── whoami.js ├── error │ └── locales │ │ └── en.json ├── highlight │ ├── json.lang │ └── json.style ├── jar.js ├── prompt │ ├── colors.js │ ├── completer.js │ ├── history.js │ ├── index.js │ └── location.js ├── ready.js ├── request │ ├── auth.js │ ├── db.js │ ├── dirs.js │ ├── edit.js │ ├── error.js │ ├── index.js │ └── print.js ├── rlx.js ├── rlx.md ├── startup │ ├── index.js │ ├── load.js │ ├── validate.js │ └── validator │ │ └── db.js ├── template │ ├── db │ │ ├── bulk.js │ │ ├── replicate.js │ │ └── revmap.js │ ├── design │ │ ├── full │ │ │ ├── attachments │ │ │ │ └── .gitignore │ │ │ ├── filters │ │ │ │ └── .gitignore │ │ │ ├── index.json │ │ │ ├── lib │ │ │ │ └── .gitignore │ │ │ ├── lists │ │ │ │ └── .gitignore │ │ │ ├── rewrites.js │ │ │ ├── shows │ │ │ │ └── .gitignore │ │ │ ├── updates │ │ │ │ └── .gitignore │ │ │ ├── validate_doc_update.js │ │ │ └── views │ │ │ │ └── lib │ │ │ │ └── .gitignore │ │ ├── minimal │ │ │ └── index.json │ │ ├── validate │ │ │ ├── index.json │ │ │ └── validate_doc_update.js │ │ └── view │ │ │ ├── index.json │ │ │ └── views │ │ │ └── all.js │ ├── doc │ │ └── new.js │ ├── user │ │ └── new.js │ └── view │ │ └── temp.js └── util │ ├── alias │ ├── alias.json │ ├── build.js │ ├── expand.js │ ├── find.js │ ├── index.js │ ├── init.js │ ├── load.js │ ├── parse.js │ └── strip.js │ ├── attach │ ├── dl.js │ ├── index.js │ └── up.js │ ├── batch │ ├── exec.js │ ├── index.js │ ├── load.js │ ├── parse.js │ └── schema.js │ ├── chdir.js │ ├── copy.js │ ├── debug-log.js │ ├── design │ ├── collate.js │ ├── collator │ │ ├── collator.js │ │ ├── config.js │ │ ├── index.js │ │ └── javascript.js │ ├── directory.js │ ├── find.js │ ├── get.js │ ├── index.js │ └── list.js │ ├── direxists.js │ ├── docs │ ├── collate.js │ ├── collator │ │ ├── collator.js │ │ ├── index.js │ │ └── javascript.js │ ├── collect.js │ ├── deconstruct.js │ ├── fetch.js │ ├── get.js │ ├── index.js │ ├── revs.js │ ├── save.js │ └── write.js │ ├── editor │ ├── edit.js │ ├── index.js │ ├── info.js │ ├── request.js │ └── response.js │ ├── exec.js │ ├── expand.js │ ├── feed.js │ ├── file-object.js │ ├── files.js │ ├── json │ ├── files.js │ ├── finalize.js │ ├── grep.js │ ├── index.js │ ├── load.js │ └── patterns.js │ ├── lint.js │ ├── location.js │ ├── log │ └── prefix.js │ ├── match.js │ ├── mime.js │ ├── mkdirs.js │ ├── pp.js │ ├── progress.js │ ├── query │ ├── index.js │ └── parser.js │ ├── re.js │ ├── resolve.js │ ├── stringify.js │ ├── temp.js │ ├── template │ ├── fsref.js │ ├── index.js │ ├── list.js │ └── parse.js │ ├── types.js │ ├── validate.js │ └── write.js ├── package.json ├── sbin ├── cheatsheet └── timeout.sh ├── test ├── assert │ ├── admin.js │ ├── alias.js │ ├── app.js │ ├── attach.js │ ├── batch.js │ ├── bulk.js │ ├── conf.js │ ├── db.js │ ├── doc.js │ ├── error.js │ ├── generic.js │ ├── head.js │ ├── index.js │ ├── level.js │ ├── log.js │ ├── options.js │ ├── rc.js │ ├── replicate.js │ ├── security.js │ ├── server.js │ ├── template.js │ ├── user.js │ └── view.js ├── bin │ ├── editor │ └── qt ├── fixtures │ ├── alias.js │ ├── app │ │ ├── attachments │ │ │ ├── deep │ │ │ │ └── lorem.txt │ │ │ └── lipsum.txt │ │ ├── docs │ │ │ ├── mock-docs-alt-attachment │ │ │ │ ├── index.json │ │ │ │ └── mock-docs-alt-attachment.txt │ │ │ ├── mock-docs-attachment │ │ │ │ ├── deep │ │ │ │ │ └── mock-docs-deep-attachment.txt │ │ │ │ ├── index.json │ │ │ │ ├── mock-docs-attachment.txt │ │ │ │ └── mock-multiple-attachment.txt │ │ │ ├── mock-docs-document.json │ │ │ └── mock-docs-id-document.json │ │ ├── filters │ │ │ └── filter.js │ │ ├── index.json │ │ ├── lib │ │ │ └── shared.js │ │ ├── lists │ │ │ └── json.js │ │ ├── module.js │ │ ├── rewrites.js │ │ ├── shows │ │ │ └── json.js │ │ ├── updates │ │ │ └── push.js │ │ ├── validate_doc_update.js │ │ └── views │ │ │ ├── all │ │ │ ├── map.js │ │ │ └── reduce.js │ │ │ ├── inline.js │ │ │ └── lib │ │ │ └── view-shared.js │ ├── attachments │ │ └── mock-attachment.txt │ ├── batch.js │ ├── bulk.js │ ├── bulk │ │ ├── auto-id.js │ │ ├── id.js │ │ ├── list.js │ │ └── method.js │ ├── db.js │ ├── doc.js │ ├── files │ │ └── batch │ │ │ ├── 101-docs.js │ │ │ ├── db-add-rm.js │ │ │ ├── info-array.js │ │ │ ├── info-function.js │ │ │ ├── info-override.js │ │ │ ├── info-property.js │ │ │ ├── info-string.js │ │ │ └── info.js │ ├── http.js │ ├── local.js │ ├── params.js │ ├── qt.js │ ├── rc.js │ ├── sec.js │ ├── security.json │ ├── template.js │ ├── template │ │ ├── error │ │ │ ├── etemplate-export.js │ │ │ └── etemplate-return.js │ │ └── mock-template.js │ ├── updates │ │ └── mock-list-item.json │ ├── urls.js │ └── user.js ├── mocha.opts ├── spec │ ├── admin │ │ ├── error.js │ │ └── lifecycle.js │ ├── alias │ │ ├── error.js │ │ └── lifecycle.js │ ├── app │ │ ├── attach.js │ │ └── lifecycle.js │ ├── attach │ │ ├── error.js │ │ └── lifecycle.js │ ├── batch │ │ ├── lifecycle.js │ │ └── parse.js │ ├── bulk │ │ ├── error.js │ │ └── lifecycle.js │ ├── command │ │ ├── unknown-subcommand.js │ │ └── unknown.js │ ├── conf │ │ ├── error.js │ │ └── lifecycle.js │ ├── db │ │ ├── bulk.js │ │ ├── error.js │ │ ├── lifecycle.js │ │ ├── purge.js │ │ └── temp.js │ ├── doc │ │ ├── edit.js │ │ ├── error.js │ │ └── lifecycle.js │ ├── edit │ │ ├── error.js │ │ └── lifecycle.js │ ├── expand │ │ └── server.js │ ├── http │ │ ├── error.js │ │ └── lifecycle.js │ ├── level │ │ ├── error.js │ │ └── lifecycle.js │ ├── lint │ │ └── json.js │ ├── local │ │ └── lifecycle.js │ ├── options │ │ ├── force.js │ │ └── header.js │ ├── rc │ │ ├── error.js │ │ └── lifecycle.js │ ├── replicate │ │ └── lifecycle.js │ ├── security │ │ ├── edit.js │ │ ├── error.js │ │ └── lifecycle.js │ ├── server │ │ ├── error.js │ │ ├── info.js │ │ ├── restart.js │ │ ├── stats.js │ │ ├── tasks.js │ │ └── uuids.js │ ├── session │ │ ├── error.js │ │ ├── lifecycle.js │ │ ├── login.js │ │ ├── logout.js │ │ └── whoami.js │ ├── template │ │ ├── error.js │ │ └── lifecycle.js │ └── user │ │ ├── edit.js │ │ ├── error.js │ │ └── lifecycle.js └── util │ ├── config.js │ ├── fsutil.js │ ├── mock.js │ ├── setup │ ├── admin.js │ ├── alias.js │ ├── bulk.js │ ├── db.js │ ├── ddoc.js │ ├── doc.js │ ├── edit.js │ ├── home.js │ ├── index.js │ └── user.js │ └── teardown │ ├── admin.js │ ├── alias.js │ ├── db.js │ ├── ddoc.js │ ├── doc.js │ ├── edit.js │ ├── home.js │ ├── index.js │ └── user.js └── tmux.conf /.gitignore: -------------------------------------------------------------------------------- 1 | .DS_Store 2 | node_modules 3 | coverage 4 | target 5 | build 6 | package 7 | /lib/rlxc.js 8 | *.bak 9 | *.log 10 | *.pid 11 | *.dump 12 | -------------------------------------------------------------------------------- /.jscsrc: -------------------------------------------------------------------------------- 1 | { 2 | "fileExtensions": [".js", "jscs"], 3 | "requireSemicolons": false, 4 | "requireParenthesesAroundIIFE": true, 5 | "maximumLineLength": 80, 6 | "validateLineBreaks": "LF", 7 | "validateIndentation": 2, 8 | "requireMultipleVarDecl": false, 9 | "disallowTrailingComma": true, 10 | "disallowSpacesInConditionalExpression": false, 11 | "disallowSpaceAfterKeywords": false, 12 | "disallowSpaceBeforeBlockStatements": false, 13 | "disallowSpacesInsideObjectBrackets": null, 14 | "excludeFiles": [ 15 | "node_modules", 16 | "coverage", 17 | "target" 18 | ] 19 | } 20 | -------------------------------------------------------------------------------- /.jshintignore: -------------------------------------------------------------------------------- 1 | node_modules 2 | coverage 3 | target 4 | test/fixtures 5 | -------------------------------------------------------------------------------- /.jshintrc: -------------------------------------------------------------------------------- 1 | { 2 | "laxcomma" : true, 3 | "laxbreak" : true, 4 | "node" : true, 5 | "curly" : true, 6 | "bitwise" : false, 7 | "undef" : true, 8 | "eqeqeq" : true, 9 | "noarg" : true, 10 | "mocha" : true, 11 | "unused" : true, 12 | "asi" : true 13 | } 14 | -------------------------------------------------------------------------------- /.npmignore: -------------------------------------------------------------------------------- 1 | coverage 2 | target 3 | build 4 | package 5 | test 6 | /sbin 7 | /doc/readme 8 | /doc/cheatsheet.json 9 | /lib/rlxc.js 10 | *.bak 11 | *.log 12 | *.pid 13 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | services: 2 | - couchdb 3 | branches: 4 | except: 5 | - develop 6 | language: node_js 7 | before_script: 8 | - couchdb -V | grep 1.6.1 9 | - ./sbin/timeout.sh 10 | script: npm run cover 11 | node_js: 12 | - "4.1" 13 | - "4.0" 14 | - "0.12" 15 | - "stable" 16 | after_success: 17 | - npm run coveralls 18 | deploy: 19 | provider: npm 20 | email: freeformsystems@gmail.com 21 | api_key: 22 | secure: Rt5CcJgcO0J7uEJxCPCI867EEIhqTNxnViF/dhfC1HTYuWp4hUXvmf3LlP6BMQOmMRQEisT7PuxQqrSHZEYsz4Xt1Fcw65+9j5qU/pWKsP3b7A6y8CiuMkMyZnrnA2jOVTHzfdd++QRHgHjDyaYNcVZQQYwKgtXlcJ9OWqFF0ikThaHtqfrebXgO+Dsp3qNAL17Sdqv4Rqu4FMVB7Yv7Lr4OHffXLzhQhJIxLaAFKnBaQgTuHSikZ+Vw6Jy+I0eQW+zNfYidbGyEx/MdKtnyaA49Wdbaiu5eZWDDAUbhQqOO28YVxd0BEVstxLRdeDW3wlNDkpHOcEdZlASGvPuB9BSKQS6ssXKd93a9AKZwkTVQfadR3XeAAoHm19lElyVlbunPOkupkN4wYRiBUnKEGsk6rplP/UFUjSE8BQGe2eMSxSKTc79kbyG1TUcziOdqwHvbtBddjjmi7Akn/Y+4CF5/Y28Wx0z6EjFUyt8rzMxO5BwJix9fsnjT3Yws9Qx4+CHgP7b9EV6hRGV6ym1HfnRA+sF2nZBVHBcyMEKMSx3CWFjzQiihwzaSkl0PRFLdls/1EoO+8/QjL6dEPIOfZkg9hBaeLRe3p+bHdI+b5LfCr6iuD0Y9uzNUOBnxnMUUx0SgnOSmFbzLJ6EyeWdlkWN/Vp754mVTNURw/KaTmR4= 23 | on: 24 | tags: true 25 | repo: tmpfs/rlx 26 | node: '4.1' 27 | -------------------------------------------------------------------------------- /bin/rlx: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env node 2 | 3 | process.stdin.resume(); 4 | 5 | var program = require('../lib/rlx'); 6 | program(require('../package.json')).parse(); 7 | -------------------------------------------------------------------------------- /doc/cheatsheet.json: -------------------------------------------------------------------------------- 1 | { 2 | "pedantic": false, 3 | "include": "doc", 4 | "toc": "Table of Contents", 5 | "base": "https://github.com/freeformsystems/rlx", 6 | "partial": [ 7 | { 8 | "inc": [ 9 | "cheatsheet.md" 10 | ] 11 | } 12 | ] 13 | } 14 | -------------------------------------------------------------------------------- /doc/man/rlx-admin.1: -------------------------------------------------------------------------------- 1 | .TH "RLX-ADMIN" "1" "January 2016" "rlx-admin 0.2.0" "User Commands" 2 | .SH "NAME" 3 | rlx-admin -- Manage server administrators. 4 | .SH "USAGE" 5 | 6 | .SP 7 | rlx admin 8 | .br 9 | rlx admin ls 10 | .br 11 | rlx admin get 12 | .br 13 | rlx admin add 14 | .br 15 | rlx admin rm 16 | .SH "DESCRIPTION" 17 | .PP 18 | If no subcommand is specified \fBls\fR is invoked. 19 | .SH "COMMANDS" 20 | .BL 21 | .IP "\[ci]" 4 22 | \fBls\fR: List administrators. 23 | .IP "\[ci]" 4 24 | \fBget\fR: Get an administrator. 25 | .IP "\[ci]" 4 26 | \fBadd\fR: Create an administrator. 27 | .IP "\[ci]" 4 28 | \fBrm\fR: Delete an administrator. 29 | .EL 30 | .SH "BUGS" 31 | .PP 32 | Report bugs to https://github.com/tmpfs/rlx/issues. 33 | -------------------------------------------------------------------------------- /doc/man/rlx-config.1: -------------------------------------------------------------------------------- 1 | .TH "RLX-CONFIG" "1" "January 2016" "rlx-config 0.2.0" "User Commands" 2 | .SH "NAME" 3 | rlx-config -- Manage server configuration. 4 | .SH "USAGE" 5 | 6 | .SP 7 | rlx config 8 | .br 9 | rlx conf 10 | .br 11 | rlx conf get [section] [key] 12 | .br 13 | rlx conf set
14 | .br 15 | rlx conf rm
16 | .SH "DESCRIPTION" 17 | .PP 18 | If no subcommand is specified \fBget\fR is invoked. 19 | .SH "COMMANDS" 20 | .BL 21 | .IP "\[ci]" 4 22 | \fBget\fR: Get server configuration. 23 | .IP "\[ci]" 4 24 | \fBset\fR: Set server configuration. 25 | .IP "\[ci]" 4 26 | \fBrm\fR: Delete server configuration. 27 | .EL 28 | .SH "BUGS" 29 | .PP 30 | Report bugs to https://github.com/tmpfs/rlx/issues. 31 | -------------------------------------------------------------------------------- /doc/man/rlx-edit.1: -------------------------------------------------------------------------------- 1 | .TH "RLX-EDIT" "1" "January 2016" "rlx-edit 0.2.0" "User Commands" 2 | .SH "NAME" 3 | rlx-edit 4 | .SH "USAGE" 5 | 6 | rlx edit 7 | .SH "DESCRIPTION" 8 | .PP 9 | Edit a document. 10 | .SH "BUGS" 11 | .PP 12 | Report bugs to https://github.com/tmpfs/rlx/issues. 13 | -------------------------------------------------------------------------------- /doc/man/rlx-help.1: -------------------------------------------------------------------------------- 1 | .TH "RLX-HELP" "1" "January 2016" "rlx-help 0.2.0" "User Commands" 2 | .SH "NAME" 3 | rlx-help 4 | .SH "USAGE" 5 | 6 | rlx help 7 | .SH "DESCRIPTION" 8 | .PP 9 | Show help for commands. 10 | .SH "BUGS" 11 | .PP 12 | Report bugs to https://github.com/tmpfs/rlx/issues. 13 | -------------------------------------------------------------------------------- /doc/man/rlx-info.1: -------------------------------------------------------------------------------- 1 | .TH "RLX-INFO" "1" "January 2016" "rlx-info 0.2.0" "User Commands" 2 | .SH "NAME" 3 | rlx-info 4 | .SH "USAGE" 5 | 6 | rlx info 7 | .SH "DESCRIPTION" 8 | .PP 9 | Print server information. 10 | .SH "BUGS" 11 | .PP 12 | Report bugs to https://github.com/tmpfs/rlx/issues. 13 | -------------------------------------------------------------------------------- /doc/man/rlx-level.1: -------------------------------------------------------------------------------- 1 | .TH "RLX-LEVEL" "1" "January 2016" "rlx-level 0.2.0" "User Commands" 2 | .SH "NAME" 3 | rlx-level -- Get or set the server log level. 4 | .SH "USAGE" 5 | 6 | .SP 7 | rlx level 8 | .br 9 | rlx lvl 10 | .br 11 | rlx lvl get 12 | .br 13 | rlx lvl info 14 | .br 15 | rlx lvl debug 16 | .br 17 | rlx lvl error 18 | .br 19 | rlx lvl warn 20 | .br 21 | rlx lvl none 22 | .SH "DESCRIPTION" 23 | .PP 24 | If no subcommand is specified \fBget\fR is invoked. 25 | .SH "COMMANDS" 26 | .BL 27 | .IP "\[ci]" 4 28 | \fBget\fR: Get log level. 29 | .IP "\[ci]" 4 30 | \fBinfo\fR: Set log level to \fBinfo\fR. 31 | .IP "\[ci]" 4 32 | \fBdebug\fR: Set log level to \fBdebug\fR. 33 | .IP "\[ci]" 4 34 | \fBerror\fR: Set log level to \fBerror\fR. 35 | .IP "\[ci]" 4 36 | \fBwarn\fR: Set log level to \fBwarning\fR. 37 | .IP "\[ci]" 4 38 | \fBnone\fR: Set log level to \fBnone\fR. 39 | .EL 40 | .SH "BUGS" 41 | .PP 42 | Report bugs to https://github.com/tmpfs/rlx/issues. 43 | -------------------------------------------------------------------------------- /doc/man/rlx-lint.1: -------------------------------------------------------------------------------- 1 | .TH "RLX-LINT" "1" "January 2016" "rlx-lint 0.2.0" "User Commands" 2 | .SH "NAME" 3 | rlx-lint 4 | .SH "USAGE" 5 | 6 | rlx lint 7 | .SH "DESCRIPTION" 8 | .PP 9 | Lint javascript and json. 10 | .SH "BUGS" 11 | .PP 12 | Report bugs to https://github.com/tmpfs/rlx/issues. 13 | -------------------------------------------------------------------------------- /doc/man/rlx-local.1: -------------------------------------------------------------------------------- 1 | .TH "RLX-LOCAL" "1" "January 2016" "rlx-local 0.2.0" "User Commands" 2 | .SH "NAME" 3 | rlx-local -- Manage local documents. 4 | .SH "USAGE" 5 | 6 | .SP 7 | rlx local 8 | .br 9 | rlx lcl 10 | .br 11 | rlx lcl add 12 | .br 13 | rlx lcl get 14 | .br 15 | rlx lcl cp 16 | .br 17 | rlx lcl rm 18 | .SH "DESCRIPTION" 19 | .PP 20 | Commands for creating, deleting, retrieving and modifying \fBlocal\fR documents, it is not possible to list local documents, see the \fBcouchdb\fR documentation. 21 | .PP 22 | If no subcommand is specified an error is reported. 23 | .PP 24 | When using the \fBcp\fR command to copy a document if \fB\-\-destination\fR does not specify an absolute URL then the document is copied as a local document, ie, if you wish to copy a local document to a regular document you will need to use an absolute URL for the destination. 25 | .SH "COMMANDS" 26 | .BL 27 | .IP "\[ci]" 4 28 | \fBadd\fR: Create a local document. 29 | .IP "\[ci]" 4 30 | \fBget\fR: Get a local document. 31 | .IP "\[ci]" 4 32 | \fBcp\fR: Copy a local document. 33 | .IP "\[ci]" 4 34 | \fBrm\fR: Remove a local document. 35 | .EL 36 | .SH "BUGS" 37 | .PP 38 | Report bugs to https://github.com/tmpfs/rlx/issues. 39 | -------------------------------------------------------------------------------- /doc/man/rlx-log.1: -------------------------------------------------------------------------------- 1 | .TH "RLX-LOG" "1" "January 2016" "rlx-log 0.2.0" "User Commands" 2 | .SH "NAME" 3 | rlx-log -- Tail server log file. 4 | .SH "USAGE" 5 | 6 | rlx log [\-\-raw] [\-\-offset=] [\-\-bytes=] 7 | .SH "DESCRIPTION" 8 | .PP 9 | This command attempts to parse the raw response text into an array of JSON log records. If you wish to print the raw log text specify the \fB\-\-raw\fR option. 10 | .PP 11 | The server will often respond with partial log records (incomplete lines) depending upon the state of the log file and the \fB\-\-offset\fR and the \fB\-\-bytes\fR options. When parsing to JSON these incomplete log records are ignored, to view these partial log records use the \fB\-\-raw\fR option. 12 | .SH "OPTIONS" 13 | .BL 14 | .IP "\[ci]" 4 15 | \fB\-\-offset=[num]\fR: Offset in bytes for the log tail. 16 | .IP "\[ci]" 4 17 | \fB\-\-bytes=[num]\fR: Bytes to be returned, default is 1000. 18 | .IP "\[ci]" 4 19 | \fB\-\-raw\fR: Print log records as plain text. 20 | .EL 21 | .SH "BUGS" 22 | .PP 23 | Report bugs to https://github.com/tmpfs/rlx/issues. 24 | -------------------------------------------------------------------------------- /doc/man/rlx-login.1: -------------------------------------------------------------------------------- 1 | .TH "RLX-LOGIN" "1" "January 2016" "rlx-login 0.2.0" "User Commands" 2 | .SH "NAME" 3 | rlx-login -- Login to a server. 4 | .SH "USAGE" 5 | 6 | .SP 7 | rlx login 8 | .br 9 | rlx in 10 | .SH "DESCRIPTION" 11 | .PP 12 | Alias for the \fBsession set\fR command. 13 | .SH "BUGS" 14 | .PP 15 | Report bugs to https://github.com/tmpfs/rlx/issues. 16 | -------------------------------------------------------------------------------- /doc/man/rlx-logout.1: -------------------------------------------------------------------------------- 1 | .TH "RLX-LOGOUT" "1" "January 2016" "rlx-logout 0.2.0" "User Commands" 2 | .SH "NAME" 3 | rlx-logout -- Logout of current session. 4 | .SH "USAGE" 5 | 6 | .SP 7 | rlx logout 8 | .br 9 | rlx out 10 | .SH "DESCRIPTION" 11 | .PP 12 | Log out a user from the current authentication session. If no arguments are specified the current session is deleted, otherwise the stored cookie information for the user is removed. 13 | .PP 14 | Use the \fBwho\fR command to view currently available login sessions, to view current authentication information run \fBwhoami\fR. 15 | .PP 16 | Alias for the \fBsession rm\fR command. 17 | .SH "BUGS" 18 | .PP 19 | Report bugs to https://github.com/tmpfs/rlx/issues. 20 | -------------------------------------------------------------------------------- /doc/man/rlx-replicate.1: -------------------------------------------------------------------------------- 1 | .TH "RLX-REPLICATE" "1" "January 2016" "rlx-replicate 0.2.0" "User Commands" 2 | .SH "NAME" 3 | rlx-replicate -- Replicate a database. 4 | .SH "USAGE" 5 | 6 | .SP 7 | rlx replicate 8 | .br 9 | rlx repl 10 | .br 11 | rlx repl ls 12 | .br 13 | rlx repl add 14 | .br 15 | rlx repl rm 16 | .SH "DESCRIPTION" 17 | .PP 18 | Commands for starting, stopping and inspecting database replications. 19 | .PP 20 | If no subcommand is specified \fBls\fR is invoked. 21 | .SH "COMMANDS" 22 | .BL 23 | .IP "\[ci]" 4 24 | \fBls\fR: List active replications. 25 | .IP "\[ci]" 4 26 | \fBadd\fR: Start a replication. 27 | .IP "\[ci]" 4 28 | \fBrm\fR: Stop a replication. 29 | .EL 30 | .SH "BUGS" 31 | .PP 32 | Report bugs to https://github.com/tmpfs/rlx/issues. 33 | -------------------------------------------------------------------------------- /doc/man/rlx-restart.1: -------------------------------------------------------------------------------- 1 | .TH "RLX-RESTART" "1" "January 2016" "rlx-restart 0.2.0" "User Commands" 2 | .SH "NAME" 3 | rlx-restart -- Restart a server. 4 | .SH "USAGE" 5 | 6 | rlx restart 7 | .SH "DESCRIPTION" 8 | .PP 9 | Upon success (202 status code) by default this command will poll the server waiting for it to become available again. You can control this behaviour in the \fBrestart\fR section of an rc file. 10 | .BL 11 | .IP "\[ci]" 4 12 | \fBpoll\fR: Boolean indicating whether polling is enabled, default is \fBtrue\fR. 13 | .IP "\[ci]" 4 14 | \fBinterval\fR: Integer milliseconds between poll attempts, default is \fB2000\fR. 15 | .IP "\[ci]" 4 16 | \fBmax\fR: Integer indicating the maximum number of retry attempts, default is \fB10\fR. 17 | .EL 18 | .SH "BUGS" 19 | .PP 20 | Report bugs to https://github.com/tmpfs/rlx/issues. 21 | -------------------------------------------------------------------------------- /doc/man/rlx-security.1: -------------------------------------------------------------------------------- 1 | .TH "RLX-SECURITY" "1" "January 2016" "rlx-security 0.2.0" "User Commands" 2 | .SH "NAME" 3 | rlx-security -- Get or set database security. 4 | .SH "USAGE" 5 | 6 | .SP 7 | rlx security 8 | .br 9 | rlx sec 10 | .br 11 | rlx sec get 12 | .br 13 | rlx sec set 14 | .br 15 | rlx sec edit 16 | .br 17 | rlx sec rm 18 | .SH "DESCRIPTION" 19 | .PP 20 | If no subcommand is specified \fBget\fR is invoked. 21 | .PP 22 | The \fBsecurity\fR commands modify the security document for a database. The \fBrm\fR subcommand is a slight misnomer as the document is not actually removed, it is shorthand for setting the security document to the empty object (\fB{}\fR) which removes all database level security. 23 | .PP 24 | The \fBrm\fR subcommand name was chosen for consistency with other subcommands and is more concise than \fBreset\fR. 25 | .SH "COMMANDS" 26 | .BL 27 | .IP "\[ci]" 4 28 | \fBget\fR: Get the security document. 29 | .IP "\[ci]" 4 30 | \fBset\fR: Set the security document. 31 | .IP "\[ci]" 4 32 | \fBedit\fR: Edit the security document. 33 | .IP "\[ci]" 4 34 | \fBrm\fR: Reset the security document. 35 | .EL 36 | .SH "BUGS" 37 | .PP 38 | Report bugs to https://github.com/tmpfs/rlx/issues. 39 | -------------------------------------------------------------------------------- /doc/man/rlx-session.1: -------------------------------------------------------------------------------- 1 | .TH "RLX-SESSION" "1" "January 2016" "rlx-session 0.2.0" "User Commands" 2 | .SH "NAME" 3 | rlx-session -- Session authentication. 4 | .SH "USAGE" 5 | 6 | .SP 7 | rlx session 8 | .br 9 | rlx sess 10 | .br 11 | rlx sess get 12 | .br 13 | rlx sess set 14 | .br 15 | rlx sess rm 16 | .SH "DESCRIPTION" 17 | .PP 18 | If no subcommand is specified \fBget\fR is invoked. 19 | .SH "COMMANDS" 20 | .BL 21 | .IP "\[ci]" 4 22 | \fBget\fR: Get session authentication. 23 | .IP "\[ci]" 4 24 | \fBset\fR: Authenticate a session. 25 | .IP "\[ci]" 4 26 | \fBrm\fR: Logout a session. 27 | .EL 28 | .SH "BUGS" 29 | .PP 30 | Report bugs to https://github.com/tmpfs/rlx/issues. 31 | -------------------------------------------------------------------------------- /doc/man/rlx-stats.1: -------------------------------------------------------------------------------- 1 | .TH "RLX-STATS" "1" "January 2016" "rlx-stats 0.2.0" "User Commands" 2 | .SH "NAME" 3 | rlx-stats 4 | .SH "USAGE" 5 | 6 | rlx stats 7 | .SH "DESCRIPTION" 8 | .PP 9 | Print server statistics. 10 | .SH "BUGS" 11 | .PP 12 | Report bugs to https://github.com/tmpfs/rlx/issues. 13 | -------------------------------------------------------------------------------- /doc/man/rlx-tasks.1: -------------------------------------------------------------------------------- 1 | .TH "RLX-TASKS" "1" "January 2016" "rlx-tasks 0.2.0" "User Commands" 2 | .SH "NAME" 3 | rlx-tasks 4 | .SH "USAGE" 5 | 6 | rlx tasks 7 | .SH "DESCRIPTION" 8 | .PP 9 | Print active tasks. 10 | .SH "BUGS" 11 | .PP 12 | Report bugs to https://github.com/tmpfs/rlx/issues. 13 | -------------------------------------------------------------------------------- /doc/man/rlx-user.1: -------------------------------------------------------------------------------- 1 | .TH "RLX-USER" "1" "January 2016" "rlx-user 0.2.0" "User Commands" 2 | .SH "NAME" 3 | rlx-user -- Manage server users. 4 | .SH "USAGE" 5 | 6 | .SP 7 | rlx user 8 | .br 9 | rlx usr 10 | .br 11 | rlx usr ls 12 | .br 13 | rlx usr add <@vars...> 14 | .br 15 | rlx usr get 16 | .br 17 | rlx usr edit 18 | .br 19 | rlx usr rm 20 | .br 21 | rlx usr passwd 22 | .SH "DESCRIPTION" 23 | .PP 24 | If no subcommand is specified \fBls\fR is invoked. 25 | .SH "COMMANDS" 26 | .BL 27 | .IP "\[ci]" 4 28 | \fBls\fR: List users. 29 | .IP "\[ci]" 4 30 | \fBadd\fR: Create a user. 31 | .IP "\[ci]" 4 32 | \fBget\fR: Get a user document. 33 | .IP "\[ci]" 4 34 | \fBedit\fR: Edit a user document. 35 | .IP "\[ci]" 4 36 | \fBrm\fR: Remove a user document. 37 | .IP "\[ci]" 4 38 | \fBpasswd\fR: Set an existing user password. 39 | .EL 40 | .SH "BUGS" 41 | .PP 42 | Report bugs to https://github.com/tmpfs/rlx/issues. 43 | -------------------------------------------------------------------------------- /doc/man/rlx-uuids.1: -------------------------------------------------------------------------------- 1 | .TH "RLX-UUIDS" "1" "January 2016" "rlx-uuids 0.2.0" "User Commands" 2 | .SH "NAME" 3 | rlx-uuids 4 | .SH "USAGE" 5 | 6 | rlx uuids [\-\-count=] 7 | .SH "DESCRIPTION" 8 | .PP 9 | Print list of uuids. 10 | .SH "OPTIONS" 11 | .BL 12 | .IP "\[ci]" 4 13 | \fB\-\-count=[num]\fR: Number of uuids to fetch. 14 | .EL 15 | .SH "BUGS" 16 | .PP 17 | Report bugs to https://github.com/tmpfs/rlx/issues. 18 | -------------------------------------------------------------------------------- /doc/man/rlx-whoami.1: -------------------------------------------------------------------------------- 1 | .TH "RLX-WHOAMI" "1" "January 2016" "rlx-whoami 0.2.0" "User Commands" 2 | .SH "NAME" 3 | rlx-whoami -- Get current user information. 4 | .SH "USAGE" 5 | 6 | rlx whoami 7 | .SH "DESCRIPTION" 8 | .PP 9 | Alias for the \fBsession get\fR command. 10 | .SH "BUGS" 11 | .PP 12 | Report bugs to https://github.com/tmpfs/rlx/issues. 13 | -------------------------------------------------------------------------------- /doc/readme/documentation.md: -------------------------------------------------------------------------------- 1 | ## Documentation 2 | 3 | The documentation for the program is available via the `help` command, for those familiar with [couchdb][] the [cheatsheet](/doc/cheatsheet.md) is a good place to start. 4 | -------------------------------------------------------------------------------- /doc/readme/install.md: -------------------------------------------------------------------------------- 1 | ## Install 2 | 3 | ``` 4 | npm i -g rlx 5 | ``` 6 | -------------------------------------------------------------------------------- /doc/readme/introduction.md: -------------------------------------------------------------------------------- 1 | [![Build Status](https://travis-ci.org/tmpfs/rlx.svg)](https://travis-ci.org/tmpfs/rlx) 2 | [![npm version](http://img.shields.io/npm/v/rlx.svg)](https://npmjs.org/package/rlx) 3 | [![Coverage Status](https://coveralls.io/repos/tmpfs/rlx/badge.svg?branch=master&service=github&v=1)](https://coveralls.io/github/tmpfs/rlx?branch=master) 4 | 5 | Command line interface for [couchdb][] designed for POSIX systems. 6 | 7 | Requires [node][] and [npm][]. 8 | -------------------------------------------------------------------------------- /doc/readme/links.md: -------------------------------------------------------------------------------- 1 | [couchdb]: http://couchdb.apache.org 2 | [node]: http://nodejs.org 3 | [npm]: http://www.npmjs.org 4 | [man]: /doc/man 5 | [mdp]: https://github.com/tmpfs/mdp 6 | [manpage]: https://github.com/cli-kit/cli-manpage 7 | [jshint]: http://jshint.com 8 | [jscs]: http://jscs.info 9 | -------------------------------------------------------------------------------- /doc/readme/quick-start.md: -------------------------------------------------------------------------------- 1 | ## Quick Start 2 | 3 | Start [couchdb][] in it's default configuration, then run: 4 | 5 | ``` 6 | rlx i # Launch interactive console 7 | cd :lh # Use alias to `cd http://localhost:5984` 8 | db ls # List databases 9 | db add mydb # Create database 10 | cd mydb # Use new database 11 | doc add -i mydoc # Create a new document 12 | doc edit mydoc # Edit document with `vim` 13 | doc get mydoc # Print modified and saved document 14 | help # Learn more commands in the manual 15 | q # Quit interactive session 16 | ``` 17 | -------------------------------------------------------------------------------- /lib/command/admin/get.js: -------------------------------------------------------------------------------- 1 | var section = require('cdb').sections.admins; 2 | 3 | module.exports = function get(info, req, next) { 4 | var opts = req.db.options(req, {section: section, key: info.args[0]}); 5 | if(!opts.key) return req.error(this.errors.EUSERNAME_REQUIRED, req, next); 6 | var dbh = req.db(); 7 | dbh.config.get(opts, function(err, res, doc) { 8 | if(err) return req.error(err, req, next); 9 | var passwd = doc; 10 | doc = {}; 11 | doc[opts.key] = passwd; 12 | req.print(doc, req, next); 13 | }) 14 | } 15 | -------------------------------------------------------------------------------- /lib/command/admin/index.js: -------------------------------------------------------------------------------- 1 | var ls = require('./ls'); 2 | 3 | module.exports = function admin(info, req, next){ 4 | if(!info.args.length) { 5 | return ls.call(this, info, req, next); 6 | } 7 | info.validate(function response(err, parameters) { 8 | if(err) return req.error(err, req, next, parameters); 9 | next(info.cmd.commands()); 10 | }) 11 | } 12 | 13 | -------------------------------------------------------------------------------- /lib/command/admin/ls.js: -------------------------------------------------------------------------------- 1 | var section = require('cdb').sections.admins; 2 | 3 | module.exports = function ls(info, req, next) { 4 | var opts = req.db.options(req, {section: section}); 5 | var dbh = req.db(); 6 | dbh.config.get(opts, function(err, res, doc) { 7 | if(err) return req.error(err, req, next); 8 | req.print(doc, req, next); 9 | }) 10 | } 11 | -------------------------------------------------------------------------------- /lib/command/admin/rm.js: -------------------------------------------------------------------------------- 1 | var section = require('cdb').sections.admins; 2 | var prompt = require('../../prompt'); 3 | 4 | module.exports = function rm(info, req, next) { 5 | var errors = this.errors; 6 | var opts = req.db.options(req, {section: section, key: info.args[0]}); 7 | if(!opts.key) return req.error(errors.EUSERNAME_REQUIRED, req, next); 8 | var dbh = req.db(); 9 | prompt.rm.call(this, info, req, {id: opts.key}, function(err, res) { 10 | if(err) return req.error(err, req, next); 11 | if(res.accept !== true) return next(); 12 | dbh.config.rm(opts, function(err, res, doc) { 13 | if(res && res.statusCode === 404) { 14 | return req.error(errors.ENO_ADMIN, req, next, [opts.key]); 15 | } 16 | //console.log('rm complete...'); 17 | if(err) return req.error(err, req, next); 18 | var passwd = doc; 19 | doc = {}; 20 | doc[opts.key] = passwd; 21 | req.print(doc, req, next); 22 | }) 23 | }); 24 | } 25 | -------------------------------------------------------------------------------- /lib/command/alias/edit.js: -------------------------------------------------------------------------------- 1 | var alias = require('../../util/alias'); 2 | 3 | module.exports = function edit(info, req, next) { 4 | var log = this.log 5 | , conf = this.configure() 6 | , doc = conf.alias; 7 | 8 | if(doc === false) { 9 | return req.error( 10 | this.errors.EALIAS_FILE_REQUIRED, req, next, 11 | [req.dirs.user.alias, 'alias init']); 12 | } 13 | 14 | var opts = { 15 | file: req.dirs.user.alias, 16 | hash: req.rc.edit.hash, 17 | body: doc 18 | }; 19 | 20 | req.edit(info, req, next, opts, function(ereq, eres, edit) { 21 | var modified = eres.modified(); 22 | if(!modified) { 23 | log.warn('no changes detected'); 24 | 25 | // reload aliases in interactive mode 26 | }else if(conf.interactive) { 27 | return alias.load.call(this, req, function(err, aliases) { 28 | if(err) return req.error(err, req, next); 29 | next(); 30 | }) 31 | } 32 | next(); 33 | }); 34 | } 35 | -------------------------------------------------------------------------------- /lib/command/alias/get.js: -------------------------------------------------------------------------------- 1 | var alias = require('../../util/alias'); 2 | var chdir = require('../../util/chdir'); 3 | 4 | module.exports = function get(info, req, next){ 5 | if(!info.args.length) { 6 | return req.error( 7 | this.errors.ETOO_FEW_ARGUMENTS, req, next, [info.cmd.extra()]); 8 | } 9 | 10 | var aliases = this.configure().alias; 11 | if(aliases === false) { 12 | return req.error( 13 | this.errors.EALIAS_FILE_REQUIRED, req, next, 14 | [req.dirs.user.alias, 'alias init']); 15 | } 16 | var as = alias.strip(req, info.args[0]) 17 | , conf = this.configure(); 18 | var doc = alias.find.call(this, as, aliases); 19 | if(!doc) { 20 | return req.error(this.errors.EUNKNOWN_ALIAS, req, next, [as]); 21 | } 22 | 23 | // don't want to change location 24 | if(conf.interactive) { 25 | return req.print(doc, req, next); 26 | } 27 | 28 | var name = doc.name; 29 | 30 | // when running from the cli more useful to 31 | // print working directory information 32 | chdir.call(this, info.args[0], req, function(err, doc) { 33 | if(err) return req.error(err, req, next); 34 | doc.name = name; 35 | req.print(doc, req, next); 36 | }) 37 | } 38 | -------------------------------------------------------------------------------- /lib/command/alias/index.js: -------------------------------------------------------------------------------- 1 | module.exports = function alias(info, req, next){ 2 | if(!info.args.length) { 3 | return req.error(this.errors.ENO_SUBCOMMAND, req, next); 4 | } 5 | info.validate(function response(err, parameters) { 6 | if(err) return req.error(err, req, next, parameters); 7 | next(info.cmd.commands()); 8 | }) 9 | } 10 | -------------------------------------------------------------------------------- /lib/command/alias/init.js: -------------------------------------------------------------------------------- 1 | var alias = require('../../util/alias'); 2 | 3 | module.exports = function init(info, req, next){ 4 | alias.init.call(this, info, req, next); 5 | } 6 | -------------------------------------------------------------------------------- /lib/command/alias/ls.js: -------------------------------------------------------------------------------- 1 | var loc = require('../../util/location'); 2 | module.exports = function ls(info, req, next){ 3 | var doc = this.configure().alias; 4 | if(doc === false) { 5 | return req.error( 6 | this.errors.EALIAS_FILE_REQUIRED, req, next, 7 | [req.dirs.user.alias, 'alias init']); 8 | } 9 | var out = {}, k, v; 10 | for(k in doc) { 11 | v = doc[k]; 12 | out[k] = this.long ? v : loc.stringify.call(this, v); 13 | } 14 | req.print(out, req, next); 15 | } 16 | -------------------------------------------------------------------------------- /lib/command/alias/parse.js: -------------------------------------------------------------------------------- 1 | var alias = require('../../util/alias'); 2 | 3 | module.exports = function parse(info, req, next){ 4 | if(!info.args.length) { 5 | return req.error( 6 | this.errors.ETOO_FEW_ARGUMENTS, req, next, [info.cmd.extra()]); 7 | } 8 | var as = alias.strip(req, info.args[0]); 9 | var doc = alias.parse.call(this, as); 10 | req.print(doc, req, next); 11 | } 12 | -------------------------------------------------------------------------------- /lib/command/alias/print.js: -------------------------------------------------------------------------------- 1 | module.exports = function print(info, req, next){ 2 | var doc = this.configure().alias; 3 | if(doc === false) { 4 | return req.error( 5 | this.errors.EALIAS_FILE_REQUIRED, req, next, 6 | [req.dirs.user.alias, 'alias init']); 7 | } 8 | req.print(doc || {}, req, next); 9 | } 10 | -------------------------------------------------------------------------------- /lib/command/alias/rm.js: -------------------------------------------------------------------------------- 1 | var alias = require('../../util/alias'); 2 | var stringify = require('../../util/stringify'); 3 | var write = require('../../util/write'); 4 | var prompt = require('../../prompt'); 5 | 6 | module.exports = function rm(info, req, next){ 7 | if(!info.args.length) { 8 | return req.error( 9 | this.errors.ETOO_FEW_ARGUMENTS, req, next, [info.cmd.extra()]); 10 | } 11 | var aliases = this.configure().alias 12 | , file = req.dirs.user.alias; 13 | if(aliases === false) { 14 | return req.error( 15 | this.errors.EALIAS_FILE_REQUIRED, req, next, 16 | [file, 'alias init']); 17 | } 18 | var as = alias.strip(req, info.args[0]); 19 | var doc = alias.find.call(this, as, aliases); 20 | if(!doc) { 21 | return req.error(this.errors.EUNKNOWN_ALIAS, req, next, [as]); 22 | } 23 | 24 | doc = {alias: doc}; 25 | doc.file = file; 26 | delete aliases[as]; 27 | var opts = {output: file}; 28 | prompt.rm.call(this, info, req, {id: as}, function(err, res) { 29 | if(err) return req.error(err, req, next); 30 | if(res.accept !== true) return next(); 31 | var contents = stringify(aliases, null, req.rc.indent); 32 | write.call(this, contents, req, opts, function(err) { 33 | if(err) return req.error(err, req, next); 34 | doc.ok = true; 35 | req.print(doc, req, next); 36 | }) 37 | }); 38 | } 39 | -------------------------------------------------------------------------------- /lib/command/application/attach.js: -------------------------------------------------------------------------------- 1 | module.exports = function attach(info, req, next) { 2 | info.defer(this.commands().attach, info, req, next); 3 | } 4 | -------------------------------------------------------------------------------- /lib/command/application/cp.js: -------------------------------------------------------------------------------- 1 | var dcp = require('../document/cp'); 2 | 3 | module.exports = function cp(info, req, next) { 4 | dcp.call(this, info, req, next); 5 | } 6 | -------------------------------------------------------------------------------- /lib/command/application/deploy.js: -------------------------------------------------------------------------------- 1 | var push = require('./push'); 2 | 3 | module.exports = function deploy(info, req, next) { 4 | info.deploy = true; 5 | info.callback = true; 6 | push.call(this, info, req, function(err, res, doc) { 7 | var docs = doc.docs; 8 | var last = docs.pop(); 9 | if(last instanceof Error) return req.error(last, req, next); 10 | var result = {ok: doc.ok, rev: doc.rev}; 11 | req.print(result, req, next); 12 | }); 13 | } 14 | -------------------------------------------------------------------------------- /lib/command/application/get.js: -------------------------------------------------------------------------------- 1 | var dget = require('../document/get'); 2 | var design = require('../../util/design'); 3 | 4 | module.exports = function get(info, req, next) { 5 | dget.call(this, info, req, next, function(doc, sub) { 6 | var lang = doc.language || design.collators.default; 7 | if(sub) { 8 | if(typeof sub === 'string') { 9 | req.lang = lang; 10 | } 11 | req.print(sub, req, next); 12 | }else{ 13 | req.print(doc, req, next); 14 | } 15 | }); 16 | } 17 | -------------------------------------------------------------------------------- /lib/command/application/head.js: -------------------------------------------------------------------------------- 1 | var dhead = require('../document/head'); 2 | 3 | module.exports = function head(info, req, next) { 4 | dhead.call(this, info, req, next); 5 | } 6 | -------------------------------------------------------------------------------- /lib/command/application/index.js: -------------------------------------------------------------------------------- 1 | var ls = require('./ls'); 2 | 3 | module.exports = function app(info, req, next){ 4 | if(!info.args.length) { 5 | return ls.call(this, info, req, next); 6 | } 7 | // for these commands, --id and --ddoc are not interchangeable 8 | var ignore = ['show', 'list', 'update']; 9 | var cmd = info.args[0]; 10 | if(cmd && !~ignore.indexOf(cmd)) { 11 | // --id and --ddoc are interoperable 12 | if(this.id && !this.ddoc) { 13 | this.ddoc = this.id; 14 | }else if(this.ddoc && !this.id) { 15 | this.id = this.ddoc; 16 | } 17 | } 18 | info.validate(function response(err, parameters) { 19 | if(err) return req.error(err, req, next, parameters); 20 | next(info.cmd.commands()); 21 | }) 22 | } 23 | -------------------------------------------------------------------------------- /lib/command/application/info.js: -------------------------------------------------------------------------------- 1 | module.exports = function info(info, req, next) { 2 | if(!this.database) { 3 | return req.error(this.errors.EDATABASE_REQUIRED, req, next); 4 | } 5 | if(!this.id) { 6 | // TODO: use --id OR --ddoc error message 7 | return req.error(this.errors.EID_REQUIRED, req, next); 8 | } 9 | var opts = req.db.options( 10 | req, {db: this.database, id: this.id, ddoc: this.ddoc}); 11 | var dbh = req.db(); 12 | dbh.design.info(opts, function(err, res, doc) { 13 | if(err) return req.error(err, req, next); 14 | req.print(doc, req, next); 15 | }) 16 | } 17 | -------------------------------------------------------------------------------- /lib/command/application/list.js: -------------------------------------------------------------------------------- 1 | module.exports = function list(info, req, next) { 2 | if(!this.database) { 3 | return req.error(this.errors.EDATABASE_REQUIRED, req, next); 4 | } 5 | if(!this.ddoc) { 6 | return req.error(this.errors.EDDOC_REQUIRED, req, next); 7 | } 8 | if(!this.nm) { 9 | return req.error(this.errors.ENAME_REQUIRED, req, next); 10 | } 11 | 12 | var oddoc, view = info.args[0], ind = view.indexOf('/'); 13 | if(view && ind > -1) { 14 | oddoc = view.substr(0, ind); 15 | view = view.substr(ind + 1); 16 | } 17 | 18 | var opts = req.db.options( 19 | req, 20 | { 21 | db: this.database, 22 | id: this.id, 23 | ddoc: this.ddoc, 24 | name: this.nm, 25 | oddoc: oddoc, 26 | view: view 27 | } 28 | ); 29 | var dbh = req.db(); 30 | dbh.design.list(opts, function(err, res, doc) { 31 | req.print(doc, req, next); 32 | }) 33 | } 34 | -------------------------------------------------------------------------------- /lib/command/application/ls.js: -------------------------------------------------------------------------------- 1 | module.exports = function ls(info, req, next) { 2 | if(!this.database) { 3 | return req.error(this.errors.EDATABASE_REQUIRED, req, next); 4 | } 5 | var opts = req.db.options(req, {db: this.database}); 6 | var dbh = req.db(); 7 | dbh.design.ls(opts, function(err, res, doc) { 8 | if(err) return req.error(err, req, next); 9 | req.print(doc, req, next); 10 | }) 11 | } 12 | -------------------------------------------------------------------------------- /lib/command/application/rewrite.js: -------------------------------------------------------------------------------- 1 | var methods = require('cdb').methods 2 | , keys = Object.keys(methods); 3 | 4 | module.exports = function rewrite(info, req, next) { 5 | if(!this.database) { 6 | return req.error(this.errors.EDATABASE_REQUIRED, req, next); 7 | } 8 | if(!this.ddoc) { 9 | return req.error(this.errors.EDDOC_REQUIRED, req, next); 10 | } 11 | 12 | var path = info.args[0] || '', method = methods.get; 13 | if(~keys.indexOf(path.toLowerCase())) { 14 | method = methods[path.toLowerCase()]; 15 | path = info.args[1] || ''; 16 | } 17 | path = path.replace(/^\/+/, ''); 18 | 19 | // TODO: validate path is not empty 20 | //console.log(path); 21 | var opts = req.db.options( 22 | req, 23 | { 24 | db: this.database, 25 | ddoc: this.ddoc, 26 | path: path, 27 | method: method 28 | } 29 | ); 30 | var dbh = req.db(); 31 | dbh.design.rewrite(opts, function(err, res, doc) { 32 | req.print(doc, req, next); 33 | }) 34 | } 35 | -------------------------------------------------------------------------------- /lib/command/application/rm.js: -------------------------------------------------------------------------------- 1 | var drm = require('../document/rm'); 2 | 3 | module.exports = function rm(info, req, next) { 4 | drm.call(this, info, req, next); 5 | } 6 | -------------------------------------------------------------------------------- /lib/command/application/show.js: -------------------------------------------------------------------------------- 1 | module.exports = function show(info, req, next) { 2 | if(!this.database) { 3 | return req.error(this.errors.EDATABASE_REQUIRED, req, next); 4 | } 5 | if(!this.ddoc) { 6 | return req.error(this.errors.EDDOC_REQUIRED, req, next); 7 | } 8 | if(!this.nm) { 9 | return req.error(this.errors.ENAME_REQUIRED, req, next); 10 | } 11 | 12 | var opts = req.db.options( 13 | req, 14 | { 15 | db: this.database, 16 | id: this.id, 17 | ddoc: this.ddoc, 18 | name: this.nm 19 | } 20 | ); 21 | var dbh = req.db(); 22 | dbh.design.show(opts, function(err, res, doc) { 23 | req.print(doc, req, next); 24 | }) 25 | } 26 | -------------------------------------------------------------------------------- /lib/command/application/update.js: -------------------------------------------------------------------------------- 1 | module.exports = function update(info, req, next) { 2 | if(!this.database) { 3 | return req.error(this.errors.EDATABASE_REQUIRED, req, next); 4 | } 5 | if(!this.ddoc) { 6 | return req.error(this.errors.EDDOC_REQUIRED, req, next); 7 | } 8 | if(!this.nm) { 9 | return req.error(this.errors.ENAME_REQUIRED, req, next); 10 | } 11 | 12 | var opts = req.db.options( 13 | req, 14 | { 15 | db: this.database, 16 | id: this.id, 17 | ddoc: this.ddoc, 18 | name: this.nm, 19 | body: req.document.body 20 | } 21 | ); 22 | var dbh = req.db(); 23 | dbh.design.update(opts, function(err, res, doc) { 24 | req.print(doc, req, next); 25 | }) 26 | } 27 | -------------------------------------------------------------------------------- /lib/command/application/view.js: -------------------------------------------------------------------------------- 1 | module.exports = function view(info, req, next) { 2 | if(!this.database) { 3 | return req.error(this.errors.EDATABASE_REQUIRED, req, next); 4 | } 5 | if(!this.id) { 6 | return req.error(this.errors.EID_REQUIRED, req, next); 7 | } 8 | //console.dir(req.result); 9 | //console.dir(this.options().nm); 10 | if(!this.nm) { 11 | return req.error(this.errors.ENAME_REQUIRED, req, next); 12 | } 13 | //console.dir(this.name); 14 | var opts = req.db.options( 15 | req, 16 | { 17 | db: this.database, 18 | id: this.id, 19 | ddoc: this.ddoc, 20 | name: this.nm 21 | } 22 | ); 23 | var dbh = req.db(); 24 | dbh.design.view(opts, function(err, res, doc) { 25 | if(err) return req.error(err); 26 | req.print(doc, req, next); 27 | }) 28 | } 29 | -------------------------------------------------------------------------------- /lib/command/attach/get.js: -------------------------------------------------------------------------------- 1 | module.exports = function get(info, req, next) { 2 | 3 | if(!this.database) { 4 | return req.error(this.errors.EDATABASE_REQUIRED, req, next); 5 | } 6 | if(!this.id && !this.ddoc) { 7 | return req.error(this.errors.EID_REQUIRED, req, next); 8 | } 9 | if(!this.attachment) { 10 | return req.error(this.errors.EATTACHMENT_REQUIRED, req, next); 11 | } 12 | 13 | var opts = req.db.options( 14 | req, 15 | { 16 | db: this.database, 17 | id: this.id, 18 | ddoc: this.ddoc 19 | } 20 | ); 21 | var name = this.attachment; 22 | var dbh = req.db(); 23 | dbh.doc.get(opts, function(err, res, doc) { 24 | doc = doc._attachments || {}; 25 | if(doc[name]) { 26 | doc = doc[name] || {}; 27 | doc.name = name; 28 | }else{ 29 | doc = {}; 30 | } 31 | if(err) return req.error(err, req, next); 32 | req.print(doc, req, next); 33 | }) 34 | } 35 | -------------------------------------------------------------------------------- /lib/command/attach/head.js: -------------------------------------------------------------------------------- 1 | module.exports = function head(info, req, next) { 2 | 3 | if(!this.database) { 4 | return req.error(this.errors.EDATABASE_REQUIRED, req, next); 5 | } 6 | if(!this.id && !this.ddoc) { 7 | return req.error(this.errors.EID_REQUIRED, req, next); 8 | } 9 | if(!this.attachment) { 10 | return req.error(this.errors.EATTACHMENT_REQUIRED, req, next); 11 | } 12 | var opts = req.db.options( 13 | req, 14 | { 15 | db: this.database, 16 | id: this.id, 17 | attname: this.attachment, 18 | ddoc: this.ddoc 19 | } 20 | ); 21 | var dbh = req.db(); 22 | dbh.att.head(opts, function(err, res, doc) { 23 | //if(err) return req.error(err, req, next); 24 | if(err && !doc) return req.error(err, req, next); 25 | req.print(doc, req, next); 26 | }) 27 | } 28 | -------------------------------------------------------------------------------- /lib/command/attach/index.js: -------------------------------------------------------------------------------- 1 | var ls = require('./ls'); 2 | 3 | module.exports = function attach(info, req, next){ 4 | if(!info.args.length) { 5 | return ls.call(this, info, req, next); 6 | } 7 | //console.dir(info); 8 | info.validate(function response(err, parameters) { 9 | if(err) return req.error(err, req, next, parameters); 10 | next(info.cmd.commands()); 11 | }) 12 | } 13 | -------------------------------------------------------------------------------- /lib/command/attach/ls.js: -------------------------------------------------------------------------------- 1 | module.exports = function ls(info, req, next) { 2 | if(!this.database) { 3 | return req.error(this.errors.EDATABASE_REQUIRED, req, next); 4 | } 5 | if(!this.id && !this.ddoc) { 6 | return req.error(this.errors.EID_REQUIRED, req, next); 7 | } 8 | var opts = req.db.options( 9 | req, 10 | { 11 | db: this.database, 12 | id: this.id, 13 | ddoc: this.ddoc 14 | } 15 | ); 16 | var dbh = req.db(); 17 | dbh.doc.get(opts, function(err, res, doc) { 18 | doc = doc._attachments || {}; 19 | if(err) return req.error(err, req, next); 20 | req.print(doc, req, next); 21 | }) 22 | } 23 | -------------------------------------------------------------------------------- /lib/command/attach/rm.js: -------------------------------------------------------------------------------- 1 | module.exports = function rm(info, req, next) { 2 | if(!this.database) { 3 | return req.error(this.errors.EDATABASE_REQUIRED, req, next); 4 | } 5 | if(!this.id && !this.ddoc) { 6 | return req.error(this.errors.EID_REQUIRED, req, next); 7 | } 8 | if(!this.attachment) { 9 | return req.error(this.errors.EATTACHMENT_REQUIRED, req, next); 10 | } 11 | var opts = req.db.options( 12 | req, 13 | { 14 | db: this.database, 15 | id: this.id, 16 | attname: this.attachment, 17 | ddoc: this.ddoc 18 | } 19 | ); 20 | var dbh = req.db(); 21 | dbh.att.rm(opts, function(err, res, doc) { 22 | if(err) return req.error(err, req, next); 23 | req.print(doc, req, next); 24 | }) 25 | } 26 | -------------------------------------------------------------------------------- /lib/command/attach/up.js: -------------------------------------------------------------------------------- 1 | var path = require('path'); 2 | var progress = require('../../util/progress'); 3 | var upload = require('../../util/attach').up; 4 | 5 | module.exports = function up(info, req, next) { 6 | var errors = this.errors; 7 | var attname = this.attachment ? 8 | this.attachment : 9 | (this.file ? path.basename(this.file) : null); 10 | 11 | if(!this.database) { 12 | return req.error(this.errors.EDATABASE_REQUIRED, req, next); 13 | } 14 | 15 | if(!this.id && !this.ddoc) { 16 | return req.error(this.errors.EID_REQUIRED, req, next); 17 | } 18 | 19 | var files = info.args || []; 20 | if(this.file) { 21 | files.unshift(this.file); 22 | } 23 | 24 | if(!files.length) { 25 | return req.error( 26 | errors.ETOO_FEW_ARGUMENTS, req, next, [info.cmd.extra()]); 27 | //return req.error(this.errors.EFILES_REQUIRED, req, next); 28 | } 29 | 30 | var opts = { 31 | files: files, 32 | attname: attname, 33 | patterns: this.glob && this.glob.length ? this.glob : null 34 | } 35 | 36 | upload.call(this, opts, info, req, next, function(err, res, doc, list) { 37 | if(err) return req.error(err, req, next); 38 | if(!doc && list && !list.length) { 39 | return req.error(errors.ENO_FILES_FOUND, req, next); 40 | } 41 | req.print(doc, req, next); 42 | }) 43 | } 44 | -------------------------------------------------------------------------------- /lib/command/batch/exec.js: -------------------------------------------------------------------------------- 1 | var batch = require('../../util/batch').exec; 2 | 3 | module.exports = function exec(info, req, next) { 4 | var scope = this 5 | , errors = this.errors 6 | , long = this.long; 7 | 8 | if(!info.args.length) { 9 | return req.error( 10 | errors.ETOO_FEW_ARGUMENTS, req, next, [info.cmd.extra()]); 11 | } 12 | 13 | var opts = {cli: this, files: info.args.slice(0), include: long}; 14 | batch(opts, function(err, doc) { 15 | if(err) return req.error(err, req, next); 16 | req.print(doc, req, next); 17 | }) 18 | } 19 | -------------------------------------------------------------------------------- /lib/command/batch/index.js: -------------------------------------------------------------------------------- 1 | module.exports = function bulk(info, req, next){ 2 | if(!info.args.length) { 3 | return req.error(this.errors.ENO_SUBCOMMAND, req, next); 4 | } 5 | info.validate(function response(err, parameters) { 6 | if(err) return req.error(err, req, next, parameters); 7 | next(info.cmd.commands()); 8 | }) 9 | } 10 | -------------------------------------------------------------------------------- /lib/command/batch/parse.js: -------------------------------------------------------------------------------- 1 | var load = require('../../util/batch').load; 2 | 3 | module.exports = function parse(info, req, next) { 4 | var scope = this 5 | , errors = this.errors 6 | , long = this.long; 7 | 8 | if(!info.args.length) { 9 | return req.error( 10 | errors.ETOO_FEW_ARGUMENTS, req, next, [info.cmd.extra()]); 11 | } 12 | 13 | var opts = {cli: this, files: info.args.slice(0), include: long}; 14 | load(opts, function(err, doc) { 15 | if(err) return req.error(err, req, next); 16 | req.print(doc, req, next); 17 | }) 18 | } 19 | -------------------------------------------------------------------------------- /lib/command/bulk/index.js: -------------------------------------------------------------------------------- 1 | module.exports = function bulk(info, req, next){ 2 | if(!info.args.length) { 3 | return req.error(this.errors.ENO_SUBCOMMAND, req, next); 4 | } 5 | info.validate(function response(err, parameters) { 6 | if(err) return req.error(err, req, next, parameters); 7 | next(info.cmd.commands()); 8 | }) 9 | } 10 | -------------------------------------------------------------------------------- /lib/command/bulk/pull.js: -------------------------------------------------------------------------------- 1 | var docs = require('../../util/docs'); 2 | var direxists = require('../../util/direxists'); 3 | 4 | module.exports = function pull(info, req, next) { 5 | var scope = this 6 | , errors = this.errors 7 | , lenient = this.lenient 8 | , strict = this.strict 9 | , force = this.force 10 | , flat = this.flat; 11 | 12 | if(!this.database) { 13 | return req.error(errors.EDATABASE_REQUIRED, req, next); 14 | } 15 | 16 | if(info.args.length < 2) { 17 | return req.error(errors.ETOO_FEW_ARGUMENTS, req, next, [info.cmd.extra()]); 18 | } 19 | 20 | var target = info.args.pop(); 21 | var opts = { 22 | ids: info.args, 23 | lenient: lenient, 24 | strict: strict, 25 | flat: flat, 26 | long: true, 27 | force: force}; 28 | 29 | function fetch(dir) { 30 | opts.dir = dir; 31 | docs.fetch.call(scope, opts, info, req, function(err, doc) { 32 | if(err) return req.error(err, req, next); 33 | if(strict && doc.err.length) { 34 | return req.print(doc.err, req, next); 35 | } 36 | req.print(doc.files, req, next); 37 | }) 38 | } 39 | 40 | direxists.call(this, target, function(err, dir, stat) { 41 | if(err) return req.error(err, req, next); 42 | fetch.call(scope, dir); 43 | }) 44 | } 45 | -------------------------------------------------------------------------------- /lib/command/bulk/revs.js: -------------------------------------------------------------------------------- 1 | var docs = require('../../util/docs'); 2 | module.exports = function revs(info, req, next) { 3 | var errors = this.errors 4 | , raw = this.raw 5 | , long = this.long 6 | , strict = this.strict; 7 | 8 | if(!this.database) { 9 | return req.error(errors.EDATABASE_REQUIRED, req, next); 10 | } 11 | 12 | if(!info.args.length) { 13 | return req.error(errors.ETOO_FEW_ARGUMENTS, req, next, [info.cmd.extra()]); 14 | } 15 | 16 | var opts = {ids: info.args, lenient: this.lenient}; 17 | docs.revs(opts, info, req, function(err, doc) { 18 | if(err) return req.error(err, req, next); 19 | 20 | if(doc.err.length && strict) { 21 | return req.print(doc.err, req, next); 22 | } 23 | 24 | if(!raw) { 25 | if(!long) { 26 | return req.print(doc.map, req, next); 27 | }else{ 28 | return req.print(doc.list, req, next); 29 | } 30 | } 31 | req.print(doc.result, req, next); 32 | }) 33 | } 34 | -------------------------------------------------------------------------------- /lib/command/config/get.js: -------------------------------------------------------------------------------- 1 | module.exports = function get(info, req, next) { 2 | var opts = req.db.options(req, {section: info.args[0], key: info.args[1]}); 3 | var dbh = req.db(); 4 | dbh.config.get(opts, function(err, res, doc) { 5 | if(err) return req.error(err, req, next); 6 | req.print(doc, req, next); 7 | }) 8 | } 9 | -------------------------------------------------------------------------------- /lib/command/config/index.js: -------------------------------------------------------------------------------- 1 | var get = require('./get'); 2 | 3 | module.exports = function config(info, req, next){ 4 | if(!info.args.length) { 5 | return get.call(this, info, req, next); 6 | } 7 | info.validate(function response(err, parameters) { 8 | if(err) return req.error(err, req, next, parameters); 9 | next(info.cmd.commands()); 10 | }) 11 | } 12 | -------------------------------------------------------------------------------- /lib/command/config/rm.js: -------------------------------------------------------------------------------- 1 | module.exports = function rm(info, req, next) { 2 | var opts = req.db.options(req, {section: info.args[0], key: info.args[1]}); 3 | if(!opts.section) return req.error( 4 | this.errors.ECONFIG_SECTION_REQUIRED, req, next); 5 | if(!opts.key) return req.error( 6 | this.errors.ECONFIG_KEY_REQUIRED, req, next); 7 | var dbh = req.db(); 8 | dbh.config.rm(opts, function(err, res, doc) { 9 | if(err) return req.error(err, req, next); 10 | req.print(doc, req, next); 11 | }) 12 | } 13 | -------------------------------------------------------------------------------- /lib/command/config/set.js: -------------------------------------------------------------------------------- 1 | module.exports = function set(info, req, next) { 2 | var opts = req.db.options(req, 3 | {section: info.args[0], key: info.args[1], value: info.args[2]}); 4 | if(!opts.section) return req.error( 5 | this.errors.ECONFIG_SECTION_REQUIRED, req, next); 6 | if(!opts.key) return req.error( 7 | this.errors.ECONFIG_KEY_REQUIRED, req, next); 8 | if(!opts.value) return req.error( 9 | this.errors.ECONFIG_VALUE_REQUIRED, req, next); 10 | var dbh = req.db(); 11 | dbh.config.set(opts, function(err, res, doc) { 12 | if(err) return req.error(err, req, next); 13 | req.print(doc, req, next); 14 | }) 15 | } 16 | -------------------------------------------------------------------------------- /lib/command/database/add.js: -------------------------------------------------------------------------------- 1 | module.exports = function add(info, req, next) { 2 | var opts = req.db.options(req, {db: this.database || info.args[0]}); 3 | if(!opts.db) { 4 | return req.error(this.errors.EDATABASE_REQUIRED, req, next); 5 | } 6 | var dbh = req.db(); 7 | dbh.db.add(opts, function(err, res, doc) { 8 | if(err) return req.error(err, req, next); 9 | req.print(doc, req, next); 10 | }) 11 | } 12 | -------------------------------------------------------------------------------- /lib/command/database/changes.js: -------------------------------------------------------------------------------- 1 | module.exports = function commit(info, req, next) { 2 | var opts = req.db.options(req, {db: this.database}); 3 | if(!opts.db) { 4 | return req.error(this.errors.EDATABASE_REQUIRED, req, next); 5 | } 6 | // TODO: implement query parameters 7 | var dbh = req.db(); 8 | dbh.db.changes(opts, function(err, res, doc) { 9 | if(err) return req.error(err, req, next); 10 | req.print(doc, req, next); 11 | }) 12 | } 13 | -------------------------------------------------------------------------------- /lib/command/database/cleanup.js: -------------------------------------------------------------------------------- 1 | module.exports = function cleanup(info, req, next) { 2 | var opts = req.db.options(req, {db: this.database}); 3 | if(!opts.db) { 4 | return req.error(this.errors.EDATABASE_REQUIRED, req, next); 5 | } 6 | var dbh = req.db(); 7 | dbh.db.cleanup(opts, function(err, res, doc) { 8 | if(err) return req.error(err, req, next); 9 | req.print(doc, req, next); 10 | }) 11 | } 12 | -------------------------------------------------------------------------------- /lib/command/database/commit.js: -------------------------------------------------------------------------------- 1 | module.exports = function commit(info, req, next) { 2 | var opts = req.db.options(req, {db: this.database}); 3 | if(!opts.db) { 4 | return req.error(this.errors.EDATABASE_REQUIRED, req, next); 5 | } 6 | var dbh = req.db(); 7 | dbh.db.commit(opts, function(err, res, doc) { 8 | if(err) return req.error(err, req, next); 9 | req.print(doc, req, next); 10 | }) 11 | } 12 | -------------------------------------------------------------------------------- /lib/command/database/compact.js: -------------------------------------------------------------------------------- 1 | module.exports = function compact(info, req, next) { 2 | var opts = req.db.options(req, {db: this.database, ddoc: this.ddoc}); 3 | if(!opts.db) { 4 | return req.error(this.errors.EDATABASE_REQUIRED, req, next); 5 | } 6 | var dbh = req.db(); 7 | dbh.db.compact(opts, function(err, res, doc) { 8 | if(err) return req.error(err, req, next); 9 | req.print(doc, req, next); 10 | }) 11 | } 12 | -------------------------------------------------------------------------------- /lib/command/database/head.js: -------------------------------------------------------------------------------- 1 | function getErrorDocumentByStatusCode(code) { 2 | var doc = {code: code}; 3 | switch(code) { 4 | case 400: 5 | doc.error = 'bad_request'; 6 | break; 7 | case 404: 8 | doc.error = 'not_found'; 9 | break; 10 | } 11 | return doc; 12 | } 13 | 14 | module.exports = function head(info, req, next) { 15 | var opts = req.db.options(req, {db: this.database}); 16 | if(!opts.db) { 17 | return req.error(this.errors.EDATABASE_REQUIRED, req, next); 18 | } 19 | var dbh = req.db(); 20 | dbh.db.info(opts, function(err, res, doc) { 21 | var code = res && res.statusCode ? res.statusCode : 500; 22 | if(code !== 200 && code !== 404) { 23 | doc = getErrorDocumentByStatusCode(code); 24 | } 25 | if(err && code !== 200 && code !== 404) { 26 | return req.error(err, req, next); 27 | } 28 | doc = {ok: res.statusCode === 200}; 29 | req.print(doc, req, next); 30 | }) 31 | } 32 | -------------------------------------------------------------------------------- /lib/command/database/index.js: -------------------------------------------------------------------------------- 1 | var ls = require('./ls'); 2 | 3 | module.exports = function database(info, req, next){ 4 | if(!info.args.length) { 5 | return ls.call(this, info, req, next); 6 | } 7 | info.validate(function response(err, parameters) { 8 | if(err) return req.error(err, req, next, parameters); 9 | next(info.cmd.commands()); 10 | }) 11 | } 12 | -------------------------------------------------------------------------------- /lib/command/database/info.js: -------------------------------------------------------------------------------- 1 | module.exports = function info(info, req, next) { 2 | var opts = req.db.options(req, {db: this.database}); 3 | if(!opts.db) { 4 | return req.error(this.errors.EDATABASE_REQUIRED, req, next); 5 | } 6 | var dbh = req.db(); 7 | dbh.db.info(opts, function(err, res, doc) { 8 | if(err) return req.error(err, req, next); 9 | req.print(doc, req, next); 10 | }) 11 | } 12 | -------------------------------------------------------------------------------- /lib/command/database/limit.js: -------------------------------------------------------------------------------- 1 | var cli = require('cli-command'); 2 | 3 | module.exports = function limit(info, req, next) { 4 | var opts = req.db.options(req, {db: this.database}); 5 | if(!opts.db) { 6 | return req.error(this.errors.EDATABASE_REQUIRED, req, next); 7 | } 8 | if(info.args[0]) opts.limit = info.args[0]; 9 | if(opts.limit) { 10 | opts.limit = parseInt(opts.limit); 11 | if(isNaN(opts.limit)) { 12 | return next('invalid %s, must be an integer', ['limit']); 13 | } 14 | } 15 | var dbh = req.db(); 16 | dbh.db.limit(opts, function(err, res, doc) { 17 | if(err) return req.error(err, req, next); 18 | req.print(doc, req, next); 19 | }) 20 | } 21 | -------------------------------------------------------------------------------- /lib/command/database/ls.js: -------------------------------------------------------------------------------- 1 | module.exports = function ls(info, req, next) { 2 | var opts = req.db.options(req); 3 | var dbh = req.db(); 4 | req.db().ls(opts, function(err, res, doc) { 5 | if(err) return req.error(err, req, next); 6 | req.print(doc, req, next); 7 | }) 8 | } 9 | -------------------------------------------------------------------------------- /lib/command/database/missing-revs.js: -------------------------------------------------------------------------------- 1 | var template = require('../../util/template'); 2 | var stringify = require('../../util/stringify'); 3 | 4 | module.exports = function missingrevs(info, req, next) { 5 | if(!this.database) { 6 | return req.error(this.errors.EDATABASE_REQUIRED, req, next); 7 | } 8 | var errors = this.errors; 9 | var name = this.template || 'db/revmap'; 10 | var opts = req.db.options(req, {db: this.database}); 11 | var dbh = req.db(); 12 | template.list.call(this, req, function(err, list, unique) { 13 | if(err) return req.error(err, req, next); 14 | var tpl = template.find(name, unique); 15 | if(!tpl) { 16 | return req.error(errors.EUNKNOWN_TEMPLATE, req, next, [name]); 17 | } 18 | template.parse.call(this, tpl.file, req, function(err, doc) { 19 | if(err) return req.error(err); 20 | opts.body = stringify(doc, null, 0); 21 | dbh.db.missingrevs(opts, function(err, res, doc) { 22 | if(err) return req.error(err, req, next); 23 | req.print(doc, req, next); 24 | }) 25 | }) 26 | }) 27 | } 28 | -------------------------------------------------------------------------------- /lib/command/database/purge.js: -------------------------------------------------------------------------------- 1 | var template = require('../../util/template'); 2 | //var validate = require('../../util/validate'); 3 | var stringify = require('../../util/stringify'); 4 | 5 | module.exports = function purge(info, req, next) { 6 | if(!this.database) { 7 | return req.error(this.errors.EDATABASE_REQUIRED, req, next); 8 | } 9 | var errors = this.errors; 10 | var name = this.template || 'db/revmap'; 11 | var opts = req.db.options(req, {db: this.database}); 12 | var dbh = req.db(); 13 | template.list.call(this, req, function(err, list, unique) { 14 | if(err) return req.error(err, req, next); 15 | var tpl = template.find(name, unique); 16 | if(!tpl) { 17 | return req.error(errors.EUNKNOWN_TEMPLATE, req, next, [name]); 18 | } 19 | template.parse.call(this, tpl.file, req, function(err, doc) { 20 | if(err) return req.error(err); 21 | opts.body = stringify(doc, null, 0); 22 | dbh.db.purge(opts, function(err, res, doc) { 23 | if(err) return req.error(err, req, next); 24 | req.print(doc, req, next); 25 | }) 26 | }) 27 | }) 28 | } 29 | -------------------------------------------------------------------------------- /lib/command/database/revs-diff.js: -------------------------------------------------------------------------------- 1 | var template = require('../../util/template'); 2 | var stringify = require('../../util/stringify'); 3 | 4 | module.exports = function revsdiff(info, req, next) { 5 | if(!this.database) { 6 | return req.error(this.errors.EDATABASE_REQUIRED, req, next); 7 | } 8 | var errors = this.errors; 9 | var name = this.template || 'db/revmap'; 10 | var opts = req.db.options(req, {db: this.database}); 11 | var dbh = req.db(); 12 | template.list.call(this, req, function(err, list, unique) { 13 | if(err) return req.error(err, req, next); 14 | var tpl = template.find(name, unique); 15 | if(!tpl) { 16 | return req.error(errors.EUNKNOWN_TEMPLATE, req, next, [name]); 17 | } 18 | template.parse.call(this, tpl.file, req, function(err, doc) { 19 | if(err) return req.error(err); 20 | opts.body = stringify(doc, null, 0); 21 | dbh.db.revsdiff(opts, function(err, res, doc) { 22 | if(err) return req.error(err, req, next); 23 | req.print(doc, req, next); 24 | }) 25 | }) 26 | }) 27 | } 28 | -------------------------------------------------------------------------------- /lib/command/database/rm.js: -------------------------------------------------------------------------------- 1 | var prompt = require('../../prompt'); 2 | 3 | module.exports = function rm(info, req, next) { 4 | if(!info.args.length && !this.database) { 5 | return req.error( 6 | this.errors.ETOO_FEW_ARGUMENTS, req, next, [info.cmd.extra()]); 7 | } 8 | var opts = req.db.options(req, {db: info.args[0] || this.database}); 9 | var dbh = req.db(); 10 | prompt.rm.call(this, info, req, {id: opts.db}, function(err, res) { 11 | if(err) return req.error(err, req, next); 12 | if(res.accept !== true) return next(); 13 | dbh.db.rm(opts, function(err, res, doc) { 14 | if(err) return req.error(err, req, next); 15 | req.print(doc, req, next); 16 | }) 17 | }) 18 | } 19 | -------------------------------------------------------------------------------- /lib/command/database/updates.js: -------------------------------------------------------------------------------- 1 | var feed = require('../../util/feed'); 2 | var feeds = require('cdb').feeds; 3 | 4 | module.exports = function updates(info, req, next) { 5 | var log = this.log; 6 | var opts = req.db.options(req, {qs: {feed: this.feed}}); 7 | var dbh = req.db(); 8 | var conn = dbh.updates(opts, function(err, res, doc) { 9 | if(err) return req.error(err, req, next); 10 | log.info('feed connection closed %s', opts.server); 11 | next(); 12 | }) 13 | return feed.call(this, conn, opts, info, req, next); 14 | } 15 | -------------------------------------------------------------------------------- /lib/command/document/conflicts.js: -------------------------------------------------------------------------------- 1 | var get = require('./get'); 2 | module.exports = function conflicts(info, req, next) { 3 | req.query = req.query || {}; 4 | req.query.conflicts = true; 5 | get.call(this, info, req, next); 6 | } 7 | -------------------------------------------------------------------------------- /lib/command/document/cp.js: -------------------------------------------------------------------------------- 1 | module.exports = function cp(info, req, next) { 2 | if(!this.database) { 3 | return req.error(this.errors.EDATABASE_REQUIRED, req, next); 4 | }else if(!this.id) { 5 | return req.error(this.errors.EID_REQUIRED, req, next); 6 | }else if(!this.destination) { 7 | return req.error(this.errors.EDESTINATION_REQUIRED, req, next); 8 | } 9 | var opts = req.db.options( 10 | req, {db: this.database, id: this.id, ddoc: this.ddoc}); 11 | var dbh = req.db(); 12 | dbh.doc.cp(opts, function(err, res, doc) { 13 | if(err) return req.error(err, req, next); 14 | req.print(doc, req, next); 15 | }) 16 | } 17 | -------------------------------------------------------------------------------- /lib/command/document/dc.js: -------------------------------------------------------------------------------- 1 | var get = require('./get'); 2 | module.exports = function delconflicts(info, req, next) { 3 | req.query = req.query || {}; 4 | req.query.deleted_conflicts = true; 5 | get.call(this, info, req, next); 6 | } 7 | -------------------------------------------------------------------------------- /lib/command/document/get.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Lookup a document property to print. 3 | */ 4 | function find(doc, args) { 5 | var o = null, t = doc; 6 | for(var i = 0;i < args.length;i++) { 7 | if(t[args[i]]) { 8 | t = t[args[i]]; 9 | } 10 | if(i === args.length - 1) o = t; 11 | } 12 | return o; 13 | } 14 | 15 | module.exports = function get(info, req, next, cb) { 16 | var scope = this; 17 | if(!this.database) { 18 | return req.error(this.errors.EDATABASE_REQUIRED, req, next); 19 | } 20 | if(!this.id) { 21 | return req.error(this.errors.EID_REQUIRED, req, next); 22 | } 23 | var opts = req.db.options( 24 | req, {db: this.database, id: this.id, ddoc: this.ddoc}); 25 | var dbh = req.db(); 26 | var args = info.args.slice(0); 27 | dbh.doc.get(opts, function(err, res, doc) { 28 | var sub; 29 | if(err) return req.error(err, req, next); 30 | if(args.length) { 31 | sub = find(doc, args); 32 | } 33 | //console.log('got doc %j', doc); 34 | if(typeof cb === 'function') return cb.call(scope, doc, sub); 35 | req.print(sub ? sub : doc, req, next); 36 | }) 37 | } 38 | -------------------------------------------------------------------------------- /lib/command/document/head.js: -------------------------------------------------------------------------------- 1 | module.exports = function head(info, req, next) { 2 | if(!this.database) { 3 | return req.error(this.errors.EDATABASE_REQUIRED, req, next); 4 | } 5 | var opts = req.db.options( 6 | req, {db: this.database, id: this.id, ddoc: this.ddoc}); 7 | var dbh = req.db(); 8 | dbh.doc.head(opts, function(err, res, doc) { 9 | if(err && !doc) return req.error(err, req, next); 10 | req.print(doc, req, next); 11 | }) 12 | } 13 | -------------------------------------------------------------------------------- /lib/command/document/index.js: -------------------------------------------------------------------------------- 1 | var ls = require('./ls'); 2 | 3 | module.exports = function session(info, req, next){ 4 | if(!info.args.length) { 5 | return ls.call(this, info, req, next); 6 | } 7 | info.validate(function response(err, parameters) { 8 | if(err) return req.error(err, req, next, parameters); 9 | next(info.cmd.commands()); 10 | }) 11 | } 12 | -------------------------------------------------------------------------------- /lib/command/document/ls.js: -------------------------------------------------------------------------------- 1 | module.exports = function ls(info, req, next) { 2 | var opts = req.db.options(req, {db: this.database}); 3 | if(!opts.db) { 4 | return req.error(this.errors.EDATABASE_REQUIRED, req, next); 5 | } 6 | var dbh = req.db(); 7 | dbh.db.all(opts, function(err, res, doc) { 8 | if(err) return req.error(err, req, next); 9 | req.print(doc, req, next); 10 | }) 11 | } 12 | -------------------------------------------------------------------------------- /lib/command/document/meta.js: -------------------------------------------------------------------------------- 1 | var get = require('./get'); 2 | module.exports = function meta(info, req, next) { 3 | req.query = req.query || {}; 4 | req.query.meta = true; 5 | get.call(this, info, req, next); 6 | } 7 | -------------------------------------------------------------------------------- /lib/command/document/rev.js: -------------------------------------------------------------------------------- 1 | module.exports = function rev(info, req, next) { 2 | var opts = req.db.options(req, {db: this.database, id: this.id}); 3 | if(!opts.db) { 4 | return req.error(this.errors.EDATABASE_REQUIRED, req, next); 5 | } 6 | if(!opts.id) { 7 | return req.error(this.errors.EID_REQUIRED, req, next); 8 | } 9 | var dbh = req.db(); 10 | dbh.doc.head(opts, function(err, res, doc) { 11 | if(err) return req.error(err, req, next); 12 | req.print(doc, req, next); 13 | }) 14 | } 15 | -------------------------------------------------------------------------------- /lib/command/document/revs.js: -------------------------------------------------------------------------------- 1 | var get = require('./get'); 2 | module.exports = function revs(info, req, next) { 3 | req.query = req.query || {}; 4 | req.query.revs = true; 5 | get.call(this, info, req, next); 6 | } 7 | -------------------------------------------------------------------------------- /lib/command/document/revsinfo.js: -------------------------------------------------------------------------------- 1 | var get = require('./get'); 2 | module.exports = function revsinfo(info, req, next) { 3 | req.query = req.query || {}; 4 | req.query.revs_info = true; 5 | get.call(this, info, req, next); 6 | } 7 | -------------------------------------------------------------------------------- /lib/command/document/rm.js: -------------------------------------------------------------------------------- 1 | var prompt = require('../../prompt'); 2 | module.exports = function rm(info, req, next) { 3 | if(!this.database) { 4 | return req.error(this.errors.EDATABASE_REQUIRED, req, next); 5 | } 6 | if(!this.id) { 7 | return req.error(this.errors.EID_REQUIRED, req, next); 8 | } 9 | var opts = req.db.options( 10 | req, {db: this.database, id: this.id, ddoc: this.ddoc}); 11 | var dbh = req.db(); 12 | prompt.rm.call(this, info, req, {id: opts.id}, function(err, res) { 13 | if(err) return req.error(err, req, next); 14 | if(res.accept !== true) return next(); 15 | dbh.doc.rm(opts, function(err, res, doc) { 16 | if(err) return req.error(err, req, next); 17 | req.print(doc, req, next); 18 | }) 19 | }); 20 | } 21 | -------------------------------------------------------------------------------- /lib/command/http/copy.js: -------------------------------------------------------------------------------- 1 | var validate = require('./validate'); 2 | 3 | module.exports = function copy(info, req, next) { 4 | validate.call(this, info, req, function(err, uri) { 5 | if(err) return req.error(err, req, next); 6 | var dbh = req.db(); 7 | var opts = req.db.options(req, {url: uri}); 8 | dbh.copy(opts, function(err, res, doc) { 9 | if(err) return req.error(err, req, next); 10 | // TODO: negotiate mime type for printing 11 | req.print(doc, req, next); 12 | }); 13 | }); 14 | } 15 | -------------------------------------------------------------------------------- /lib/command/http/del.js: -------------------------------------------------------------------------------- 1 | var validate = require('./validate'); 2 | 3 | module.exports = function del(info, req, next) { 4 | validate.call(this, info, req, function(err, uri) { 5 | if(err) return req.error(err, req, next); 6 | var dbh = req.db(); 7 | var opts = req.db.options(req, {url: uri, body: req.document.body}); 8 | dbh.del(opts, function(err, res, doc) { 9 | if(err) return req.error(err, req, next); 10 | // TODO: negotiate mime type for printing 11 | req.print(doc, req, next); 12 | }); 13 | }); 14 | } 15 | -------------------------------------------------------------------------------- /lib/command/http/get.js: -------------------------------------------------------------------------------- 1 | var validate = require('./validate'); 2 | 3 | module.exports = function get(info, req, next){ 4 | validate.call(this, info, req, function(err, uri) { 5 | if(err) return req.error(err, req, next); 6 | var dbh = req.db(); 7 | var opts = req.db.options(req, {url: uri}); 8 | dbh.get(opts, function(err, res, doc) { 9 | if(err) return req.error(err, req, next); 10 | // TODO: negotiate mime type for printing 11 | req.print(doc, req, next); 12 | }); 13 | }); 14 | } 15 | -------------------------------------------------------------------------------- /lib/command/http/head.js: -------------------------------------------------------------------------------- 1 | var validate = require('./validate'); 2 | 3 | module.exports = function head(info, req, next) { 4 | validate.call(this, info, req, function(err, uri) { 5 | if(err) return req.error(err, req, next); 6 | var dbh = req.db(); 7 | var opts = req.db.options(req, {url: uri}); 8 | dbh.head(opts, function(err, res, doc) { 9 | if(err && !doc) return req.error(err, req, next); 10 | req.print(doc, req, next); 11 | }); 12 | }); 13 | } 14 | -------------------------------------------------------------------------------- /lib/command/http/index.js: -------------------------------------------------------------------------------- 1 | module.exports = function http(info, req, next){ 2 | if(!info.args.length) { 3 | return req.error(this.errors.ENO_SUBCOMMAND, req, next); 4 | } 5 | info.validate(function response(err, parameters) { 6 | if(err) return req.error(err, req, next, parameters); 7 | next(info.cmd.commands()); 8 | }) 9 | } 10 | -------------------------------------------------------------------------------- /lib/command/http/post.js: -------------------------------------------------------------------------------- 1 | var validate = require('./validate'); 2 | 3 | module.exports = function post(info, req, next) { 4 | validate.call(this, info, req, function(err, uri) { 5 | if(err) return req.error(err, req, next); 6 | var dbh = req.db(); 7 | var opts = req.db.options(req, {url: uri, body: req.document.body}); 8 | dbh.post(opts, function(err, res, doc) { 9 | if(err) return req.error(err, req, next); 10 | // TODO: negotiate mime type for printing 11 | req.print(doc, req, next); 12 | }); 13 | }); 14 | } 15 | -------------------------------------------------------------------------------- /lib/command/http/put.js: -------------------------------------------------------------------------------- 1 | var validate = require('./validate'); 2 | 3 | module.exports = function put(info, req, next) { 4 | validate.call(this, info, req, function(err, uri) { 5 | if(err) return req.error(err, req, next); 6 | var dbh = req.db(); 7 | var opts = req.db.options(req, {url: uri, body: req.document.body}); 8 | dbh.put(opts, function(err, res, doc) { 9 | if(err) return req.error(err, req, next); 10 | // TODO: negotiate mime type for printing 11 | req.print(doc, req, next); 12 | }); 13 | }); 14 | } 15 | -------------------------------------------------------------------------------- /lib/command/http/validate.js: -------------------------------------------------------------------------------- 1 | var url = require('url') 2 | , re = require('../../util/re') 3 | , alias = require('../../util/alias') 4 | , loc = require('../../util/location'); 5 | 6 | module.exports = function validate(info, req, next) { 7 | if(!info.args.length) { 8 | return next( 9 | this.wrap(this.errors.ETOO_FEW_ARGUMENTS, [info.cmd.extra()])); 10 | } 11 | 12 | var uri = info.args[0] 13 | , raw = '' + uri 14 | , as 15 | , conf = this.configure() 16 | , aliases = conf.alias; 17 | 18 | if(aliases && alias.test(req, uri)) { 19 | as = alias.strip(req, uri); 20 | as = alias.find(as, aliases); 21 | if(as) { 22 | uri = raw = loc.stringify.call(this, as); 23 | } 24 | } 25 | 26 | uri = url.parse(uri); 27 | 28 | if(!uri.protocol || !re.protocol().test(uri.protocol)) { 29 | return next( 30 | this.wrap(this.errors.EINVALID_PROTOCOL, [raw])); 31 | } 32 | 33 | uri = raw; 34 | 35 | next(null, uri); 36 | } 37 | -------------------------------------------------------------------------------- /lib/command/info.js: -------------------------------------------------------------------------------- 1 | module.exports = function info(info, req, next) { 2 | var opts = req.db.options(req); 3 | var dbh = req.db(); 4 | //console.log('info called %j', opts); 5 | dbh.info(opts, function(err, res, doc) { 6 | if(err) return req.error(err, req, next); 7 | req.print(doc, req, next); 8 | }) 9 | } 10 | -------------------------------------------------------------------------------- /lib/command/interactive/cd.js: -------------------------------------------------------------------------------- 1 | var chdir = require('../../util/chdir'); 2 | 3 | module.exports = function cd(info, req, next) { 4 | if(!info.args.length) { 5 | return req.error( 6 | this.errors.ETOO_FEW_ARGUMENTS, req, next, [info.cmd.extra()]); 7 | } 8 | 9 | chdir.call(this, info.args[0], req, function(err, doc) { 10 | if(err) return req.error(err, req, next); 11 | req.print(doc, req, next); 12 | }); 13 | } 14 | -------------------------------------------------------------------------------- /lib/command/interactive/exit.js: -------------------------------------------------------------------------------- 1 | module.exports = function exit(info, req, next) { 2 | var code = 0; 3 | var errs = this.configure().errors; 4 | if(errs && errs.length) { 5 | code = errs[errs.length - 1].code; 6 | } 7 | process.exit(code); 8 | } 9 | -------------------------------------------------------------------------------- /lib/command/interactive/pwd.js: -------------------------------------------------------------------------------- 1 | var loc = require('../../util/location'); 2 | 3 | module.exports = function pwd(info, req, next) { 4 | var doc = loc.cwd.call(this); 5 | req.print(doc, req, next); 6 | } 7 | -------------------------------------------------------------------------------- /lib/command/interactive/shorthelp.js: -------------------------------------------------------------------------------- 1 | var help = require('cli-help'); 2 | 3 | module.exports = function shorthelp(info, req, next) { 4 | // so we don't attempt to show help for a subcommand 5 | req.unparsed = []; 6 | // show the cmd style help 7 | help.call(this, 'cmd', req, next); 8 | } 9 | -------------------------------------------------------------------------------- /lib/command/interactive/su.js: -------------------------------------------------------------------------------- 1 | var jar = require('../../jar'); 2 | var login = require('../session/set'); 3 | 4 | module.exports = function su(info, req, next) { 5 | if(!info.args.length) { 6 | return req.error( 7 | this.errors.ETOO_FEW_ARGUMENTS, req, next, [info.cmd.extra()]); 8 | } 9 | var uname = info.args[0]; 10 | var server = info.args[1] || this.server; 11 | var exists = jar.cookie[server] 12 | && jar.cookie[server].list 13 | && jar.cookie[server].list[uname]; 14 | if(exists) { 15 | jar.cookie[server].user = uname; 16 | this.authuser = uname; 17 | return req.print({ok: true}, req, next); 18 | }else{ 19 | this.username = uname; 20 | this.server = server; 21 | login.call(this, info, req, next); 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /lib/command/interactive/welcome.js: -------------------------------------------------------------------------------- 1 | var async = require('async'); 2 | var ansi = require('ttycolor').ansi; 3 | var fs = require('fs'); 4 | var path = require('path'); 5 | 6 | function welcome(info, req, cb) { 7 | var scope = this 8 | , log = this.log 9 | , conf = this.configure(); 10 | 11 | var prefix = this.name() + ' |'; 12 | console.log( 13 | prefix 14 | + ' %s (interactive console), started on ' + conf.start.time, 15 | 'v' + this.version()); 16 | var names = this.commands().exit.names().slice(0); 17 | var last = names.pop(); 18 | console.log( 19 | prefix 20 | + ' run %s | %s | %s for documentation, leave with %s or %s', 21 | this.commands().help.getLongName() + ' ', '--help', '?', 22 | names.join(', '), last); 23 | 24 | var files = [ 25 | { 26 | message: 'rc init', 27 | file: path.join(req.dirs.user.home, req.runcontrol.name) 28 | }, 29 | { 30 | message: 'tpl init', 31 | file: req.dirs.user.template 32 | } 33 | ] 34 | 35 | async.eachSeries(files, function(item, callback) { 36 | fs.exists(item.file, function(exists) { 37 | if(!exists) { 38 | log.warn('%s does not exist, run %s', item.file, item.message); 39 | } 40 | callback(); 41 | }) 42 | }, function(err, result) { 43 | cb.call(scope, err, result); 44 | }) 45 | } 46 | 47 | module.exports = welcome; 48 | -------------------------------------------------------------------------------- /lib/command/interactive/who.js: -------------------------------------------------------------------------------- 1 | var jar = require('../../jar'); 2 | 3 | module.exports = function who(info, req, next) { 4 | var doc = {}, server, i; 5 | var servers = Object.keys(jar.cookie); 6 | for(i = 0;i < servers.length;i++) { 7 | server = servers[i]; 8 | doc[server] = Object.keys(jar.cookie[server].list); 9 | } 10 | req.print(doc, req, next); 11 | } 12 | -------------------------------------------------------------------------------- /lib/command/json/index.js: -------------------------------------------------------------------------------- 1 | module.exports = function json(info, req, next){ 2 | if(!info.args.length) { 3 | return req.error(this.errors.ENO_SUBCOMMAND, req, next); 4 | } 5 | info.validate(function response(err, parameters) { 6 | if(err) return req.error(err, req, next, parameters); 7 | next(info.cmd.commands()); 8 | }) 9 | } 10 | -------------------------------------------------------------------------------- /lib/command/level/debug.js: -------------------------------------------------------------------------------- 1 | var levels = require('cdb').log.levels; 2 | var set = require('./set'); 3 | 4 | module.exports = function debug(info, req, next){ 5 | info.cmd.level = levels.debug; 6 | set.call(this, info, req, next); 7 | } 8 | -------------------------------------------------------------------------------- /lib/command/level/error.js: -------------------------------------------------------------------------------- 1 | var levels = require('cdb').log.levels; 2 | var set = require('./set'); 3 | 4 | module.exports = function error(info, req, next){ 5 | info.cmd.level = levels.error; 6 | set.call(this, info, req, next); 7 | } 8 | -------------------------------------------------------------------------------- /lib/command/level/get.js: -------------------------------------------------------------------------------- 1 | var couch = require('cdb'); 2 | var section = couch.sections.log; 3 | var key = couch.sections.map.log.level; 4 | 5 | module.exports = function get(info, req, next){ 6 | var opts = req.db.options(req, {section: section, key: key}); 7 | var dbh = req.db(); 8 | dbh.config.get(opts, function(err, res, doc) { 9 | if(err) return req.error(err, req, next); 10 | var level = doc; 11 | doc = { 12 | level: level 13 | } 14 | req.print(doc, req, next); 15 | }) 16 | } 17 | -------------------------------------------------------------------------------- /lib/command/level/index.js: -------------------------------------------------------------------------------- 1 | var get = require('./get'); 2 | 3 | module.exports = function level(info, req, next){ 4 | if(!info.args.length) { 5 | return get.call(this, info, req, next); 6 | } 7 | info.validate(function response(err, parameters) { 8 | if(err) return req.error(err, req, next, parameters); 9 | next(info.cmd.commands()); 10 | }) 11 | } 12 | -------------------------------------------------------------------------------- /lib/command/level/info.js: -------------------------------------------------------------------------------- 1 | var levels = require('cdb').log.levels; 2 | var set = require('./set'); 3 | 4 | module.exports = function info(info, req, next){ 5 | info.cmd.level = levels.info; 6 | set.call(this, info, req, next); 7 | } 8 | -------------------------------------------------------------------------------- /lib/command/level/none.js: -------------------------------------------------------------------------------- 1 | var levels = require('cdb').log.levels; 2 | var set = require('./set'); 3 | 4 | module.exports = function none(info, req, next){ 5 | info.cmd.level = levels.none; 6 | set.call(this, info, req, next); 7 | 8 | } 9 | -------------------------------------------------------------------------------- /lib/command/level/set.js: -------------------------------------------------------------------------------- 1 | var couch = require('cdb'); 2 | var section = couch.sections.log; 3 | var key = couch.sections.map.log.level; 4 | 5 | module.exports = function set(info, req, next){ 6 | var opts = req.db.options(req, 7 | {section: section, key: key, value: info.cmd.level}); 8 | var dbh = req.db(); 9 | dbh.config.set(opts, function(err, res, doc) { 10 | if(err) return req.error(err, req, next); 11 | var old = doc; 12 | doc = { 13 | level: info.cmd.level, 14 | before: old 15 | } 16 | req.print(doc, req, next); 17 | }) 18 | } 19 | -------------------------------------------------------------------------------- /lib/command/level/warn.js: -------------------------------------------------------------------------------- 1 | var levels = require('cdb').log.levels; 2 | var set = require('./set'); 3 | 4 | module.exports = function warn(info, req, next){ 5 | info.cmd.level = levels.warn; 6 | set.call(this, info, req, next); 7 | } 8 | -------------------------------------------------------------------------------- /lib/command/lint.js: -------------------------------------------------------------------------------- 1 | var linter = require('../util/lint'); 2 | var types = require('../util/types'); 3 | var stringify = require('../util/stringify'); 4 | 5 | module.exports = function lint(info, req, next) { 6 | if(!req.document || !req.document.body) { 7 | return req.error(this.errors.EDOCUMENT_REQUIRED, req, next); 8 | } 9 | //console.dir(req.document.type); 10 | var method, opts, remote = (req.document && req.document.res); 11 | 12 | //console.dir(req.document); 13 | 14 | // TODO: check response headers for content-type 15 | // TODO: pass failing --json option through this test 16 | if(req.document.type === types.json) { 17 | var body = typeof req.document.body === 'string' ? 18 | req.document.body : stringify(req.document.body); 19 | method = linter.json; 20 | opts = body; 21 | }else if(/\.js$/.test(this.file)) { 22 | method = linter.js; 23 | opts = {file: this.file, body: req.document.body} 24 | } 25 | method(opts, function(err, doc) { 26 | if(err) return next(Array.isArray(err) ? err[0] : err); 27 | req.print(doc, req, next); 28 | }); 29 | } 30 | -------------------------------------------------------------------------------- /lib/command/local/add.js: -------------------------------------------------------------------------------- 1 | var add = require('../document/add'); 2 | module.exports = function ladd(info, req, next) { 3 | add.call(this, info, req, next); 4 | } 5 | -------------------------------------------------------------------------------- /lib/command/local/cp.js: -------------------------------------------------------------------------------- 1 | var cp = require('../document/cp'); 2 | module.exports = function lcp(info, req, next) { 3 | cp.call(this, info, req, next); 4 | } 5 | -------------------------------------------------------------------------------- /lib/command/local/get.js: -------------------------------------------------------------------------------- 1 | var get = require('../document/get'); 2 | module.exports = function lget(info, req, next) { 3 | get.call(this, info, req, next); 4 | } 5 | -------------------------------------------------------------------------------- /lib/command/local/index.js: -------------------------------------------------------------------------------- 1 | module.exports = function local(info, req, next){ 2 | if(!info.args.length) { 3 | return req.error(this.errors.ENO_SUBCOMMAND, req, next); 4 | } 5 | info.validate(function response(err, parameters) { 6 | if(err) return req.error(err, req, next, parameters); 7 | req.document.local = true; 8 | next(info.cmd.commands()); 9 | }) 10 | } 11 | -------------------------------------------------------------------------------- /lib/command/local/rm.js: -------------------------------------------------------------------------------- 1 | var rm = require('../document/rm'); 2 | module.exports = function lrm(info, req, next) { 3 | rm.call(this, info, req, next); 4 | } 5 | -------------------------------------------------------------------------------- /lib/command/log.js: -------------------------------------------------------------------------------- 1 | var LogParse = require('couchdb-log-parse') 2 | var parser = new LogParse() 3 | 4 | module.exports = function log(info, req, next) { 5 | var raw = this.raw, log = this.log; 6 | var opts = req.db.options(req, {qs: {}}); 7 | //console.log('log called'); 8 | if(this.offset) opts.qs.offset = this.offset; 9 | if(this.bytes) opts.qs.bytes = this.bytes; 10 | var dbh = req.db(); 11 | dbh.tail(opts, function(err, res, doc) { 12 | req.text = raw; 13 | if(err) return req.error(err, req, next); 14 | if(!raw) { 15 | var records = []; 16 | parser.on('message', function(msg) { 17 | // TODO: warn on invalid log record 18 | if(!msg.raw) { 19 | records.push(msg); 20 | } 21 | }) 22 | parser.once('end', function() { 23 | parser.removeAllListeners(); 24 | //console.log('got records %j', records); 25 | req.print(records, req, next); 26 | }) 27 | parser.end(new Buffer(doc)); 28 | }else{ 29 | req.print(doc, req, next); 30 | } 31 | }) 32 | } 33 | -------------------------------------------------------------------------------- /lib/command/login.js: -------------------------------------------------------------------------------- 1 | var set = require('./session/set'); 2 | 3 | module.exports = function login(info, req, next) { 4 | this.username = info.args[0] || this.username; 5 | set.call(this, info, req, next); 6 | } 7 | -------------------------------------------------------------------------------- /lib/command/logout.js: -------------------------------------------------------------------------------- 1 | var rm = require('./session/rm'); 2 | 3 | module.exports = function logout(info, req, next) { 4 | rm.call(this, info, req, next); 5 | } 6 | -------------------------------------------------------------------------------- /lib/command/rc/dir.js: -------------------------------------------------------------------------------- 1 | module.exports = function dir(info, req, next) { 2 | req.print(req.runcontrol.path, req, next); 3 | } 4 | -------------------------------------------------------------------------------- /lib/command/rc/get.js: -------------------------------------------------------------------------------- 1 | var property = require('cli-property') 2 | , find = property.find; 3 | 4 | module.exports = function get(info, req, next){ 5 | var target = req.rc; 6 | var key = info.args[0]; 7 | if(!key) { 8 | return req.error(this.errors.ERC_KEY_REQUIRED, req, next); 9 | } 10 | var result = find(key, target); 11 | req.print(result.value, req, next); 12 | } 13 | -------------------------------------------------------------------------------- /lib/command/rc/index.js: -------------------------------------------------------------------------------- 1 | var print = require('./print'); 2 | 3 | module.exports = function rc(info, req, next){ 4 | if(!info.args.length) { 5 | return print.call(this, info, req, next); 6 | } 7 | info.validate(function response(err, parameters) { 8 | if(err) return req.error(err, req, next, parameters); 9 | next(info.cmd.commands()); 10 | }) 11 | } 12 | -------------------------------------------------------------------------------- /lib/command/rc/init.js: -------------------------------------------------------------------------------- 1 | var fs = require('fs'); 2 | var path = require('path'); 3 | 4 | var copy = require('../../util/copy'); 5 | var direxists = require('../../util/direxists'); 6 | 7 | module.exports = function init(info, req, next){ 8 | var scope = this, errors = this.errors; 9 | var target = info.args[0]; 10 | var name = req.runcontrol.name; 11 | var src = path.join(req.dirs.base, name); 12 | var options = {ncp: {clobber: this.force}, source: src}; 13 | if(!target) { 14 | options.destination = path.join(req.dirs.user.home, name); 15 | copy.call(this, info, req, next, options); 16 | }else{ 17 | direxists.call(this, target, function(err, dir, stat) { 18 | if(err) return req.error(err, req, next); 19 | options.destination = path.join(dir, name); 20 | copy.call(scope, info, req, next, options); 21 | }) 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /lib/command/rc/ls.js: -------------------------------------------------------------------------------- 1 | module.exports = function ls(info, req, next) { 2 | req.print(this.long ? req.runcontrol.store : req.runcontrol.files, req, next); 3 | } 4 | -------------------------------------------------------------------------------- /lib/command/rc/print.js: -------------------------------------------------------------------------------- 1 | module.exports = function print(info, req, next){ 2 | req.print(req.rc, req, next); 3 | } 4 | -------------------------------------------------------------------------------- /lib/command/rc/rm.js: -------------------------------------------------------------------------------- 1 | var set = require('./set'); 2 | 3 | module.exports = function rm(info, req, next){ 4 | info.rm = true; 5 | if(info.args.length > 1) { 6 | info.args = info.args.slice(0, 1); 7 | } 8 | set.call(this, info, req, next); 9 | } 10 | -------------------------------------------------------------------------------- /lib/command/replicate/index.js: -------------------------------------------------------------------------------- 1 | var ls = require('./ls'); 2 | 3 | module.exports = function replicate(info, req, next){ 4 | if(!info.args.length) { 5 | return ls.call(this, info, req, next); 6 | } 7 | info.validate(function response(err, parameters) { 8 | if(err) return req.error(err, req, next, parameters); 9 | next(info.cmd.commands()); 10 | }) 11 | } 12 | -------------------------------------------------------------------------------- /lib/command/replicate/ls.js: -------------------------------------------------------------------------------- 1 | var tasktypes = require('cdb').tasktypes; 2 | 3 | module.exports = function ls(info, req, next) { 4 | var opts = req.db.options(req); 5 | var dbh = req.db(); 6 | dbh.tasks(opts, function(err, res, doc) { 7 | if(err) return req.error(err, req, next); 8 | if(Array.isArray(doc) && doc.length) { 9 | doc = doc.filter(function(value) { 10 | if(value && value.type === tasktypes.replication) { 11 | return value; 12 | } 13 | }) 14 | } 15 | req.print(doc, req, next); 16 | }) 17 | } 18 | -------------------------------------------------------------------------------- /lib/command/replicate/rm.js: -------------------------------------------------------------------------------- 1 | var add = require('./add'); 2 | 3 | module.exports = function rm(info, req, next) { 4 | req.vars.cancel = true; 5 | add.call(this, info, req, next); 6 | } 7 | -------------------------------------------------------------------------------- /lib/command/security/edit.js: -------------------------------------------------------------------------------- 1 | var editor = require('../../util/editor'); 2 | var temp = require('../../util/temp'); 3 | var types = require('../../util/types'); 4 | 5 | module.exports = function edit(info, req, next) { 6 | if(!this.database) { 7 | return req.error(this.errors.EDATABASE_REQUIRED, req, next); 8 | } 9 | var scope = this 10 | , log = this.log; 11 | var opts = req.db.options(req, {db: this.database}); 12 | var dbh = req.db(); 13 | dbh.sec.get(opts, function(err, res, doc) { 14 | if(err) return req.error(err, req, next); 15 | var topts = {body: doc, type: types.JSON}; 16 | temp.create.call(this, req, topts, function(err, file) { 17 | if(err) return req.error(err, req, next); 18 | var eopts = {file: file, hash: req.rc.edit.hash}; 19 | req.edit(info, req, next, eopts, function(ereq, eres, edit) { 20 | var modified = eres.modified(); 21 | if(!modified) { 22 | log.warn('no changes detected, aborting'); 23 | return next(); 24 | } 25 | // TODO: load document content when 26 | // TODO: not hashing files 27 | opts.body = eres.document ? '' + eres.document : doc; 28 | dbh.sec.set(opts, function(err, res, doc) { 29 | if(err) return req.error(err, req, next); 30 | req.print(doc, req, next); 31 | }) 32 | }) 33 | }) 34 | }) 35 | } 36 | -------------------------------------------------------------------------------- /lib/command/security/get.js: -------------------------------------------------------------------------------- 1 | module.exports = function get(info, req, next) { 2 | var opts = req.db.options(req, {db: this.database}); 3 | if(!opts.db) { 4 | return req.error(this.errors.EDATABASE_REQUIRED, req, next); 5 | } 6 | var dbh = req.db(); 7 | dbh.sec.get(opts, function(err, res, doc) { 8 | if(err) return req.error(err, req, next); 9 | req.print(doc, req, next); 10 | }) 11 | } 12 | -------------------------------------------------------------------------------- /lib/command/security/index.js: -------------------------------------------------------------------------------- 1 | var get = require('./get'); 2 | 3 | module.exports = function security(info, req, next){ 4 | if(!info.args.length) { 5 | return get.call(this, info, req, next); 6 | } 7 | info.validate(function response(err, parameters) { 8 | if(err) return req.error(err, req, next, parameters); 9 | next(info.cmd.commands()); 10 | }) 11 | } 12 | -------------------------------------------------------------------------------- /lib/command/security/rm.js: -------------------------------------------------------------------------------- 1 | module.exports = function rm(info, req, next) { 2 | var opts = req.db.options(req, {db: this.database}); 3 | if(!opts.db) { 4 | return req.error(this.errors.EDATABASE_REQUIRED, req, next); 5 | } 6 | opts.body = {}; 7 | var dbh = req.db(); 8 | dbh.sec.set(opts, function(err, res, doc) { 9 | if(err) return req.error(err, req, next); 10 | req.print(doc, req, next); 11 | }) 12 | } 13 | -------------------------------------------------------------------------------- /lib/command/security/set.js: -------------------------------------------------------------------------------- 1 | module.exports = function set(info, req, next) { 2 | var opts = req.db.options(req, {db: this.database}); 3 | if(!opts.db) { 4 | return req.error(this.errors.EDATABASE_REQUIRED, req, next); 5 | } 6 | if(req.document && req.document.body) { 7 | opts.body = req.document.body; 8 | } 9 | var dbh = req.db(); 10 | dbh.sec.set(opts, function(err, res, doc) { 11 | if(err) return req.error(err, req, next); 12 | req.print(doc, req, next); 13 | }) 14 | } 15 | -------------------------------------------------------------------------------- /lib/command/session/get.js: -------------------------------------------------------------------------------- 1 | module.exports = function get(info, req, next, cb) { 2 | var server = this.server; 3 | var opts = req.db.options(req); 4 | req.db().session.get(opts, function(err, res, doc) { 5 | if(cb) return cb(err, res, doc); 6 | if(err) return req.error(err, req, next); 7 | if(doc) { 8 | doc.server = server; 9 | } 10 | req.print(doc, req, next); 11 | }) 12 | } 13 | -------------------------------------------------------------------------------- /lib/command/session/index.js: -------------------------------------------------------------------------------- 1 | var get = require('./get'); 2 | 3 | module.exports = function session(info, req, next){ 4 | if(!info.args.length) { 5 | return get.call(this, info, req, next); 6 | } 7 | info.validate(function response(err, parameters) { 8 | if(err) return req.error(err, req, next, parameters); 9 | next(info.cmd.commands()); 10 | }) 11 | } 12 | -------------------------------------------------------------------------------- /lib/command/session/rm.js: -------------------------------------------------------------------------------- 1 | var jar = require('../../jar'); 2 | 3 | module.exports = function rm(info, req, next) { 4 | var scope = this; 5 | var username = info.args[0]; 6 | var server = info.args[1] || this.server; 7 | var opts = req.db.options(req, {username: username}); 8 | if(username && username !== this.authuser) { 9 | var item = jar.cookie[server], del = false; 10 | if(item && item.list) { 11 | del = item.list.hasOwnProperty(username); 12 | delete item.list[username]; 13 | } 14 | return req.print({ok: del}, req, next); 15 | } 16 | req.db().session.rm(opts, function(err, res, doc) { 17 | if(err) return req.error(err, req, next); 18 | delete scope.configure().authinfo; 19 | req.login.auth = null; 20 | req.login.credentials = {}; 21 | delete scope.username; 22 | delete scope.password; 23 | delete scope.authuser; 24 | req.print(doc, req, next); 25 | }) 26 | } 27 | -------------------------------------------------------------------------------- /lib/command/stats.js: -------------------------------------------------------------------------------- 1 | module.exports = function stats(info, req, next) { 2 | var opts = req.db.options(req); 3 | var dbh = req.db(); 4 | dbh.stats(opts, function(err, res, doc) { 5 | if(err) return req.error(err, req, next); 6 | req.print(doc, req, next); 7 | }) 8 | } 9 | -------------------------------------------------------------------------------- /lib/command/system/auth.js: -------------------------------------------------------------------------------- 1 | module.exports = function auth(info, req, next) { 2 | req.print(this.configure().authinfo || {}, req, next); 3 | } 4 | -------------------------------------------------------------------------------- /lib/command/system/conf.js: -------------------------------------------------------------------------------- 1 | module.exports = function conf(info, req, next) { 2 | req.print(this.configure(), req, next); 3 | } 4 | -------------------------------------------------------------------------------- /lib/command/system/dbh.js: -------------------------------------------------------------------------------- 1 | module.exports = function dbhandle(info, req, next) { 2 | req.print(req.db(), req, next); 3 | } 4 | -------------------------------------------------------------------------------- /lib/command/system/dir.js: -------------------------------------------------------------------------------- 1 | var loc = require('../../util/location'); 2 | 3 | module.exports = function cd(info, req, next) { 4 | var doc = loc.cwdir.call(this, info.args); 5 | req.print(doc, req, next); 6 | } 7 | -------------------------------------------------------------------------------- /lib/command/system/env.js: -------------------------------------------------------------------------------- 1 | module.exports = function env(info, req, next) { 2 | req.print(req.env, req, next); 3 | } 4 | -------------------------------------------------------------------------------- /lib/command/system/err.js: -------------------------------------------------------------------------------- 1 | var pp = require('../../util/pp'); 2 | 3 | module.exports = function err(info, req, next) { 4 | var errors = this.configure().errors || [] 5 | , log = this.log 6 | , raw = this.raw 7 | , scope = this 8 | , name = this.name(); 9 | 10 | if(!raw) { 11 | return req.print(errors, req, next); 12 | }else{ 13 | errors.forEach(function(err) { 14 | pp.conerr.call(scope, name, log, err); 15 | }) 16 | } 17 | next(); 18 | } 19 | -------------------------------------------------------------------------------- /lib/command/system/hist.js: -------------------------------------------------------------------------------- 1 | module.exports = function hist(info, req, next) { 2 | var hist = this.configure().history.store.history().slice(0); 3 | 4 | // this command has already been added to the history 5 | // which isn't really too convenient 6 | hist.shift(); 7 | 8 | // better to see more recent commands at the bottom 9 | hist.reverse(); 10 | 11 | req.print(hist, req, next); 12 | } 13 | -------------------------------------------------------------------------------- /lib/command/system/index.js: -------------------------------------------------------------------------------- 1 | module.exports = function system(info, req, next){ 2 | if(!info.args.length) { 3 | return req.error(this.errors.ENO_SUBCOMMAND, req, next); 4 | } 5 | info.validate(function response(err, parameters) { 6 | if(err) return req.error(err, req, next, parameters); 7 | next(info.cmd.commands()); 8 | }) 9 | } 10 | -------------------------------------------------------------------------------- /lib/command/system/jar.js: -------------------------------------------------------------------------------- 1 | var jar = require('../../jar'); 2 | 3 | module.exports = function sysjar(info, req, next) { 4 | req.print(jar, req, next); 5 | } 6 | -------------------------------------------------------------------------------- /lib/command/system/log.js: -------------------------------------------------------------------------------- 1 | var pp = require('../../util/pp'); 2 | 3 | module.exports = function log(info, req, next) { 4 | var scope = this 5 | , records = this.configure().logbuffer.records.slice(0) 6 | , log = this.log 7 | , raw = this.raw 8 | , name = this.name(); 9 | 10 | 11 | if(!raw) { 12 | return req.print(records, req, next); 13 | }else{ 14 | records.forEach(function(record) { 15 | pp.conrec.call(scope, name, log, record); 16 | }) 17 | } 18 | 19 | next(); 20 | } 21 | -------------------------------------------------------------------------------- /lib/command/system/prg.js: -------------------------------------------------------------------------------- 1 | module.exports = function program(info, req, next) { 2 | req.print(this, req, next); 3 | } 4 | -------------------------------------------------------------------------------- /lib/command/system/req.js: -------------------------------------------------------------------------------- 1 | module.exports = function request(info, req, next) { 2 | req.print({info: info, req: req}, req, next); 3 | } 4 | -------------------------------------------------------------------------------- /lib/command/tasks.js: -------------------------------------------------------------------------------- 1 | module.exports = function tasks(info, req, next) { 2 | var opts = req.db.options(req); 3 | var dbh = req.db(); 4 | dbh.tasks(opts, function(err, res, doc) { 5 | if(err) return req.error(err, req, next); 6 | req.print(doc, req, next); 7 | }) 8 | } 9 | -------------------------------------------------------------------------------- /lib/command/template/dir.js: -------------------------------------------------------------------------------- 1 | var dirs = require('./dirs'); 2 | 3 | module.exports = function dir(info, req, next) { 4 | var list = dirs.call(this, req) 5 | req.print(list, req, next); 6 | } 7 | -------------------------------------------------------------------------------- /lib/command/template/dirs.js: -------------------------------------------------------------------------------- 1 | var uniq = require('cli-util').uniq; 2 | 3 | /** 4 | * Work out which directories should be searched 5 | * for templates. 6 | */ 7 | function dirs(req) { 8 | var sd = req.dirs.tpl.system; 9 | var ud = req.dirs.user.template; 10 | var list = [ud, sd]; 11 | //if(this.user) list = [ud]; 12 | var custom = null; 13 | if(req.rc.search && req.rc.search.paths && req.rc.search.paths.template) { 14 | custom = req.rc.search.paths.template; 15 | } 16 | if(Array.isArray(custom) && custom.length) { 17 | list = custom.concat(list); 18 | } 19 | if(Array.isArray(this.searchPath) && this.searchPath.length) { 20 | list = this.searchPath.concat(list); 21 | } 22 | var ind = list.indexOf(sd); 23 | if(this.system === false && ~ind) { 24 | list.splice(ind, 1); 25 | } 26 | ind = list.indexOf(ud); 27 | if(this.user === false && ~ind) { 28 | //console.log(list); 29 | list.splice(ind, 1); 30 | } 31 | 32 | // when invoked with --no-system and --no-user 33 | // and there are no rc or cli search paths 34 | // default to system 35 | if(!list.length) { 36 | list.push(sd); 37 | } 38 | list = uniq(list); 39 | return list.reverse(); 40 | } 41 | 42 | module.exports = dirs; 43 | -------------------------------------------------------------------------------- /lib/command/template/index.js: -------------------------------------------------------------------------------- 1 | var ls = require('./ls'); 2 | 3 | module.exports = function template(info, req, next){ 4 | if(!info.args.length) { 5 | return ls.call(this, info, req, next); 6 | } 7 | info.validate(function response(err, parameters) { 8 | if(err) return req.error(err, req, next, parameters); 9 | next(info.cmd.commands()); 10 | }) 11 | } 12 | -------------------------------------------------------------------------------- /lib/command/template/ls.js: -------------------------------------------------------------------------------- 1 | var dirs = require('./dirs'); 2 | var template = require('../../util/template'); 3 | var treeify = template.treeify; 4 | 5 | module.exports = function ls(info, req, next) { 6 | var raw = this.raw; 7 | var opts = { 8 | patterns: this.glob.length ? this.glob : null, 9 | dirs: dirs.call(this, req) 10 | }; 11 | //console.log('listing templates'); 12 | template.list.call(this, req, opts, function(err, list, unique) { 13 | if(err) return req.error(err, req, next); 14 | var doc = !raw ? unique : treeify.call(this, unique, raw); 15 | req.text = raw; 16 | //console.dir(doc); 17 | req.print(doc, req, next); 18 | }) 19 | } 20 | -------------------------------------------------------------------------------- /lib/command/user/get.js: -------------------------------------------------------------------------------- 1 | var userdb = require('./userdb'); 2 | 3 | module.exports = function get(info, req, next) { 4 | var id = this.id || req.vars.name || info.args[0]; 5 | if(!id) { 6 | return req.error(this.errors.EID_REQUIRED, req, next); 7 | } 8 | var opts = req.db.options(req, 9 | {db: this.database || userdb.default, id: id}); 10 | opts.id = userdb.id(opts.id); 11 | 12 | req.vars.name = id; 13 | 14 | var dbh = req.db(); 15 | dbh.doc.get(opts, function(err, res, doc) { 16 | if(err) return req.error(err, req, next); 17 | req.print(doc, req, next); 18 | }) 19 | } 20 | -------------------------------------------------------------------------------- /lib/command/user/index.js: -------------------------------------------------------------------------------- 1 | var ls = require('./ls'); 2 | 3 | module.exports = function user(info, req, next){ 4 | if(!info.args.length) { 5 | return ls.call(this, info, req, next); 6 | } 7 | info.validate(function response(err, parameters) { 8 | if(err) return req.error(err, req, next, parameters); 9 | next(info.cmd.commands()); 10 | }) 11 | } 12 | -------------------------------------------------------------------------------- /lib/command/user/ls.js: -------------------------------------------------------------------------------- 1 | var userdb = require('./userdb'); 2 | 3 | module.exports = function ls(info, req, next) { 4 | //TODO: handle fetching authentication_db when necessary 5 | //TODO: allow POST to _all_docs 6 | var opts = req.db.options(req, {db: this.database || userdb.default}); 7 | opts.qs.startkey = userdb.prefix; 8 | var dbh = req.db(); 9 | dbh.db.all(opts, function(err, res, doc) { 10 | if(err) return req.error(err, req, next); 11 | req.print(doc, req, next); 12 | }) 13 | } 14 | -------------------------------------------------------------------------------- /lib/command/user/passwd.js: -------------------------------------------------------------------------------- 1 | var userdb = require('./userdb'); 2 | 3 | module.exports = function passwd(info, req, next) { 4 | var opts = req.db.options(req, 5 | {db: this.database || userdb.default, id: this.id || req.vars.name}); 6 | if(!opts.id) { 7 | return req.error(this.errors.EID_REQUIRED, req, next); 8 | } 9 | opts.id = userdb.id(opts.id); 10 | 11 | var password = req.vars.password || info.args[0]; 12 | if(!password) { 13 | return req.error(this.errors.EPASSWORD_REQUIRED, req, next); 14 | } 15 | 16 | var dbh = req.db(); 17 | dbh.doc.get(opts, function(err, res, doc) { 18 | if(err) return req.error(err, req, next); 19 | doc.password = password; 20 | opts.body = doc; 21 | dbh.doc.save(opts, function(err, res, doc) { 22 | if(err) return req.error(err, req, next); 23 | req.print(doc, req, next); 24 | }) 25 | }) 26 | } 27 | -------------------------------------------------------------------------------- /lib/command/user/rm.js: -------------------------------------------------------------------------------- 1 | var prompt = require('../../prompt'); 2 | var userdb = require('./userdb'); 3 | 4 | module.exports = function rm(info, req, next) { 5 | var id = this.id || req.vars.name || info.args[0]; 6 | if(!id) { 7 | return req.error(this.errors.EID_REQUIRED, req, next); 8 | } 9 | var opts = req.db.options(req, {db: this.database || userdb.default, id: id}); 10 | opts.id = userdb.id(opts.id); 11 | var dbh = req.db(); 12 | prompt.rm.call(this, info, req, {id: id}, function(err, res) { 13 | if(err) return req.error(err, req, next); 14 | if(res.accept !== true) return next(); 15 | dbh.doc.rm(opts, function(err, res, doc) { 16 | if(err) return req.error(err, req, next); 17 | req.print(doc, req, next); 18 | }) 19 | }) 20 | } 21 | -------------------------------------------------------------------------------- /lib/command/user/userdb.js: -------------------------------------------------------------------------------- 1 | var cdb = require('cdb'); 2 | var prefix = module.exports.prefix = cdb.user.prefix; 3 | module.exports.default = cdb.user.db; 4 | module.exports.id = function(id) { 5 | id = id || ''; 6 | if(id.indexOf(prefix) !== 0) { 7 | id = prefix + id; 8 | } 9 | return !id ? null : id; 10 | } 11 | module.exports.strip = function(id) { 12 | id = id || ''; 13 | if(id.indexOf(prefix) === 0) { 14 | id = id.replace(prefix, ''); 15 | } 16 | return !id ? null : id; 17 | } 18 | -------------------------------------------------------------------------------- /lib/command/uuids.js: -------------------------------------------------------------------------------- 1 | module.exports = function uuids(info, req, next) { 2 | var opts = req.db.options(req, {qs: {}}); 3 | if(this.count) opts.qs.count = this.count; 4 | var dbh = req.db(); 5 | dbh.uuids(opts, function(err, res, doc) { 6 | if(err) return req.error(err, req, next); 7 | req.print(doc, req, next); 8 | }) 9 | } 10 | -------------------------------------------------------------------------------- /lib/command/whoami.js: -------------------------------------------------------------------------------- 1 | var get = require('./session/get'); 2 | 3 | module.exports = function whoami(info, req, next) { 4 | get.call(this, info, req, next); 5 | } 6 | -------------------------------------------------------------------------------- /lib/highlight/json.lang: -------------------------------------------------------------------------------- 1 | # JSON lang definition file 2 | 3 | # for string types 4 | (keyquote,key,keyquote,colon,valquote,string,valquote) = `(")([^"]+)(")(\s*:)(\s*")((?:\\"|.)*?)(")` 5 | 6 | # for string primitives 7 | (valquote,string,valquote) = `(^")((?:\\"|.)*?)("$)` 8 | 9 | # for non-string types and string values (array of strings) 10 | (keyquote,key,keyquote,colon) = `(")([^"]+)(")(\s*:?\s*)` 11 | 12 | # duplicated from number.lang - can just include 13 | number = 14 | '\<[+-]?((0x[[:xdigit:]]+)|(([[:digit:]]*\.)? 15 | [[:digit:]]+([eE][+-]?[[:digit:]]+)?))u?((int(?:8|16|32|64))|L)?\>' 16 | 17 | symbol = ",","{","}","[","]" 18 | keyword = "true|false|null" 19 | -------------------------------------------------------------------------------- /lib/highlight/json.style: -------------------------------------------------------------------------------- 1 | string red b; 2 | keyword blue; 3 | number blue; 4 | type pink; 5 | normal black; 6 | symbol blue; 7 | 8 | // for JSON 9 | key bg:black; 10 | keyquote bg:black; 11 | valquote red; 12 | colon cyan; 13 | -------------------------------------------------------------------------------- /lib/jar.js: -------------------------------------------------------------------------------- 1 | module.exports = {}; 2 | -------------------------------------------------------------------------------- /lib/prompt/history.js: -------------------------------------------------------------------------------- 1 | var mkdirp = require('mkdirp') 2 | , input = require('cli-input') 3 | , history = input.history; 4 | 5 | function histload(info, req, cb) { 6 | var scope = this 7 | , opts = {} 8 | , k, i; 9 | req.history.file = req.dirs.user.history; 10 | for(k in req.rc.history) { 11 | opts[k] = req.rc.history[k]; 12 | } 13 | 14 | var conf = this.configure(); 15 | 16 | opts.file = req.history.file; 17 | opts.exit = true; 18 | mkdirp(req.dirs.user.home, function(err) { 19 | if(err) return cb.call(scope, err); 20 | req.history.manager = history(opts, function(err, store, hist) { 21 | if(err) return cb.call(scope, err); 22 | req.history.store = store; 23 | 24 | // store non-transient reference to history 25 | conf.history = req.history; 26 | 27 | cb.call(scope, null, store, hist); 28 | }); 29 | }) 30 | } 31 | 32 | module.exports = histload; 33 | -------------------------------------------------------------------------------- /lib/prompt/location.js: -------------------------------------------------------------------------------- 1 | var loc = require('../util/location') 2 | , url = require('url'); 3 | 4 | function location() { 5 | var scope = this; 6 | return function getLocation(key, options) { 7 | return loc.getPromptLocation.call(scope, key, options); 8 | } 9 | } 10 | 11 | function authenticate() { 12 | var scope = this; 13 | return function(key, options) { 14 | if(!scope.server) return ''; 15 | var u = url.parse(scope.server); 16 | u.auth = scope.username; 17 | u.protocol = ''; 18 | return url.format(u).replace(/^\/+/, '').replace(/\/+$/, ''); 19 | } 20 | } 21 | 22 | function health() { 23 | var scope = this; 24 | return function health(key, options) { 25 | if(!scope.server) return ''; 26 | //return '☯'; 27 | // u2600: ☀ ☁ ☂ ☃ ☄ ★ ☆ ☇ ☈ ☉ ☊ ☋ ☌ ☍ ☎ ☏ ☐ ☑ ☒ ☓ ☔ ☕ ☖ ☗ ☘ ☙ ☚ ☛ ☜ ☝ ☞ ☟ 28 | // u2620: ☠ ☡ ☢ ☣ ☤ ☥ ☦ ☧ ☨ ☩ ☪ ☫ ☬ ☭ ☮ ☯ ☰ ☱ ☲ ☳ ☴ ☵ ☶ ☷ ☸ ☹ ☺ ☻ ☼ ☽ ☾ ☿ 29 | //return '☆'; 30 | //return '⌛'; 31 | // 32 | //⩆ ⩇ 33 | // 34 | //return '☀'; 35 | //return '⊗'; 36 | //return '⁕'; 37 | return '⌘'; 38 | } 39 | } 40 | 41 | location.authenticate = authenticate; 42 | location.health = health; 43 | 44 | module.exports = location; 45 | -------------------------------------------------------------------------------- /lib/request/dirs.js: -------------------------------------------------------------------------------- 1 | var path = require('path'); 2 | var os = require('os'); 3 | var base = path.normalize(path.join(__dirname, '..', '..')); 4 | var lib = path.join(base, 'lib'); 5 | 6 | function dirs(req, home) { 7 | var name = '.' + this.name(); 8 | var rlx = module.exports.home = path.join(home, name); 9 | var des = 'design', tpl = 'template', his = '.history'; 10 | var alias = 'alias.json'; 11 | req.dirs = req.dirs || {}; 12 | req.files = req.files || {}; 13 | req.dirs.home = home; 14 | req.dirs.tmp = os.tmpdir(); 15 | req.dirs.base = base; 16 | req.dirs.lib = lib; 17 | req.dirs.design = [ 18 | path.join(rlx, tpl, des), 19 | path.join(lib, tpl, des) 20 | ]; 21 | req.dirs.tpl = { 22 | system: path.join(lib, tpl) 23 | } 24 | req.dirs.user = { 25 | template: path.join(rlx, tpl), 26 | home: rlx, 27 | history: path.join(rlx, his), 28 | alias: path.join(rlx, alias) 29 | } 30 | req.files.sh = { 31 | lang: path.join(lib, 'highlight', 'json.lang'), 32 | style: path.join(lib, 'highlight', 'json.style') 33 | } 34 | 35 | // default aliases file 36 | req.files.alias = path.join(lib,'util', 'alias', 'alias.json'); 37 | } 38 | 39 | module.exports = dirs; 40 | -------------------------------------------------------------------------------- /lib/request/edit.js: -------------------------------------------------------------------------------- 1 | var editor = require('../util/editor'); 2 | 3 | /** 4 | * Opens an editor. 5 | */ 6 | function edit(info, req, next, opts, cb) { 7 | var scope = this; 8 | new editor.EditorRequest(opts, function(err, ereq) { 9 | if(err) return req.error(err, req, next); 10 | new editor.Edit(ereq, function(err, ereq, eres, edit) { 11 | if(err) return req.error(err, req, next); 12 | cb.call(scope, ereq, eres, edit); 13 | }) 14 | }); 15 | } 16 | 17 | module.exports = edit; 18 | -------------------------------------------------------------------------------- /lib/request/index.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | auth: require('./auth'), 3 | db: require('./db'), 4 | dirs: require('./dirs'), 5 | error: require('./error'), 6 | edit: require('./edit'), 7 | print: require('./print'), 8 | } 9 | -------------------------------------------------------------------------------- /lib/startup/index.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | validate: require('./validate'), 3 | load: require('./load'), 4 | } 5 | -------------------------------------------------------------------------------- /lib/template/db/bulk.js: -------------------------------------------------------------------------------- 1 | module.exports = function template(req, cb) { 2 | var docs = [], doc; 3 | if(Array.isArray(this.docs) && this.docs.length) { 4 | docs = this.docs.map(function(value) { 5 | return {_id: value}; 6 | }); 7 | } 8 | if(this.files) { 9 | this.files.forEach(function(item) { 10 | doc = item.doc; 11 | if(doc) { 12 | if(Array.isArray(doc)) { 13 | doc = { 14 | list: doc 15 | } 16 | }else if(typeof doc === 'function') { 17 | doc = {map: '' + doc.toString()}; 18 | } 19 | //console.dir(doc); 20 | docs.push(doc); 21 | } 22 | }) 23 | } 24 | var doc = { 25 | all_or_nothing: false, 26 | new_edits: true, 27 | docs: docs 28 | }; 29 | cb(null, doc); 30 | } 31 | -------------------------------------------------------------------------------- /lib/template/db/replicate.js: -------------------------------------------------------------------------------- 1 | module.exports = function template(req, cb) { 2 | var doc = {}; 3 | doc.source = this.source; 4 | doc.target = this.target; 5 | doc.continuous = this.continuous; 6 | doc.cancel = this.cancel; 7 | doc.create_target = this.create_target; 8 | doc.proxy = this.proxy; 9 | doc.doc_ids = Array.isArray(this.doc_ids) ? this.doc_ids : undefined; 10 | cb(null, doc); 11 | } 12 | -------------------------------------------------------------------------------- /lib/template/db/revmap.js: -------------------------------------------------------------------------------- 1 | module.exports = function template(req, cb) { 2 | var doc = {}; 3 | for(var z in this) { 4 | doc[z] = Array.isArray(this[z]) ? this[z] : [this[z]]; 5 | } 6 | cb(null, doc); 7 | } 8 | -------------------------------------------------------------------------------- /lib/template/design/full/attachments/.gitignore: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tmpfs/rlx/545007d4de6e678d2ea8455622ac785493ee6c5a/lib/template/design/full/attachments/.gitignore -------------------------------------------------------------------------------- /lib/template/design/full/filters/.gitignore: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tmpfs/rlx/545007d4de6e678d2ea8455622ac785493ee6c5a/lib/template/design/full/filters/.gitignore -------------------------------------------------------------------------------- /lib/template/design/full/index.json: -------------------------------------------------------------------------------- 1 | { 2 | "language": "javascript", 3 | "options": { 4 | "local_seq": false, 5 | "include_design": false 6 | } 7 | } 8 | -------------------------------------------------------------------------------- /lib/template/design/full/lib/.gitignore: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tmpfs/rlx/545007d4de6e678d2ea8455622ac785493ee6c5a/lib/template/design/full/lib/.gitignore -------------------------------------------------------------------------------- /lib/template/design/full/lists/.gitignore: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tmpfs/rlx/545007d4de6e678d2ea8455622ac785493ee6c5a/lib/template/design/full/lists/.gitignore -------------------------------------------------------------------------------- /lib/template/design/full/rewrites.js: -------------------------------------------------------------------------------- 1 | module.exports = []; 2 | -------------------------------------------------------------------------------- /lib/template/design/full/shows/.gitignore: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tmpfs/rlx/545007d4de6e678d2ea8455622ac785493ee6c5a/lib/template/design/full/shows/.gitignore -------------------------------------------------------------------------------- /lib/template/design/full/updates/.gitignore: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tmpfs/rlx/545007d4de6e678d2ea8455622ac785493ee6c5a/lib/template/design/full/updates/.gitignore -------------------------------------------------------------------------------- /lib/template/design/full/validate_doc_update.js: -------------------------------------------------------------------------------- 1 | module.exports = function(newDoc, oldDoc, userCtx, secObj) {} 2 | -------------------------------------------------------------------------------- /lib/template/design/full/views/lib/.gitignore: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tmpfs/rlx/545007d4de6e678d2ea8455622ac785493ee6c5a/lib/template/design/full/views/lib/.gitignore -------------------------------------------------------------------------------- /lib/template/design/minimal/index.json: -------------------------------------------------------------------------------- 1 | { 2 | "language": "javascript", 3 | "options": { 4 | "local_seq": false, 5 | "include_design": false 6 | } 7 | } 8 | -------------------------------------------------------------------------------- /lib/template/design/validate/index.json: -------------------------------------------------------------------------------- 1 | { 2 | "language": "javascript", 3 | "options": { 4 | "local_seq": false, 5 | "include_design": false 6 | } 7 | } 8 | -------------------------------------------------------------------------------- /lib/template/design/validate/validate_doc_update.js: -------------------------------------------------------------------------------- 1 | module.exports = function(newDoc, oldDoc, userCtx, secObj) {} 2 | -------------------------------------------------------------------------------- /lib/template/design/view/index.json: -------------------------------------------------------------------------------- 1 | { 2 | "language": "javascript", 3 | "options": { 4 | "local_seq": false, 5 | "include_design": false 6 | } 7 | } 8 | -------------------------------------------------------------------------------- /lib/template/design/view/views/all.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | map: function(doc) { 3 | emit(doc._id, null); 4 | }, 5 | reduce: '_count' 6 | } 7 | -------------------------------------------------------------------------------- /lib/template/doc/new.js: -------------------------------------------------------------------------------- 1 | module.exports = function template(req, cb) { 2 | var doc = {}; 3 | if(this.id) { 4 | doc._id = this.id 5 | delete this.id; 6 | } 7 | for(var z in this) { 8 | doc[z] = this[z]; 9 | } 10 | cb(null, doc); 11 | } 12 | -------------------------------------------------------------------------------- /lib/template/user/new.js: -------------------------------------------------------------------------------- 1 | module.exports = function template(req, cb) { 2 | var doc = { 3 | _id: this.id, 4 | name: this.name, 5 | password: this.password, 6 | roles: Array.isArray(this.roles) 7 | ? this.roles : this.roles ? [this.roles] : [], 8 | type: 'user' 9 | } 10 | cb(null, doc); 11 | } 12 | -------------------------------------------------------------------------------- /lib/template/view/temp.js: -------------------------------------------------------------------------------- 1 | module.exports = function template(req, cb) { 2 | var doc = { 3 | map: function(doc) { 4 | emit(doc._id, null); 5 | }, 6 | reduce: '_count' 7 | } 8 | cb(null, doc); 9 | } 10 | -------------------------------------------------------------------------------- /lib/util/alias/alias.json: -------------------------------------------------------------------------------- 1 | { 2 | "lh": { 3 | "server": "http://localhost:5984" 4 | }, 5 | "lhs": { 6 | "server": "https://localhost:6984" 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /lib/util/alias/build.js: -------------------------------------------------------------------------------- 1 | function build(opts) { 2 | var o = {}; 3 | o.server = opts ? opts.server : this.server || undefined; 4 | o.database = opts ? opts.database : this.database || undefined; 5 | o.id = opts ? opts.id : this.id || undefined; 6 | o.rev = opts ? opts.rev : this.rev || undefined; 7 | 8 | // we want to be able to iterate on the keys cleanly 9 | if(!o.server) delete o.server; 10 | if(!o.database) delete o.database; 11 | if(!o.id) delete o.id; 12 | if(!o.rev) delete o.rev; 13 | 14 | return o; 15 | } 16 | 17 | module.exports = build; 18 | -------------------------------------------------------------------------------- /lib/util/alias/expand.js: -------------------------------------------------------------------------------- 1 | var loc = require('../location'); 2 | var find = require('./find'); 3 | 4 | 5 | var fields = [ 6 | 'server', 7 | 'database', 8 | 'id', 9 | 'rev', 10 | 'username', 11 | //'ddoc' 12 | ]; 13 | 14 | function expand(req, cb) { 15 | var match = req.rc.alias.match 16 | , aliases = this.configure().alias 17 | , i, v, a, k; 18 | 19 | // no aliases loaded cannot perform 20 | // alias expansion 21 | if(!aliases) return cb(); 22 | 23 | for(k in fields) { 24 | v = req.result.options[fields[k]]; 25 | if(v && match.test('' + v)) { 26 | //console.dir(v) 27 | a = find(v.replace(match, ''), aliases); 28 | if(!a) { 29 | return cb(this.wrap(this.errors.EUNKNOWN_ALIAS, [v])); 30 | } 31 | } 32 | } 33 | 34 | // no aliases specified/found 35 | if(!a) return cb(); 36 | 37 | // assign to the instance 38 | assign.call(this, a, match); 39 | 40 | cb(); 41 | } 42 | 43 | function assign(a, match) { 44 | var k, v; 45 | for(k in fields) { 46 | v = this[fields[k]]; 47 | //console.log('assign from alias %s', v); 48 | if(a[fields[k]] && (!v || match.test(v))) { 49 | //console.log('assigning %s', v); 50 | this[fields[k]] = a[fields[k]]; 51 | } 52 | } 53 | } 54 | 55 | expand.assign = assign; 56 | 57 | module.exports = expand; 58 | -------------------------------------------------------------------------------- /lib/util/alias/find.js: -------------------------------------------------------------------------------- 1 | var parse = require('./parse'); 2 | 3 | function find(alias, aliases) { 4 | if(typeof alias === 'string') { 5 | alias = parse(alias); 6 | } 7 | alias = alias || {}; 8 | aliases = aliases || {}; 9 | var keys = Object.keys(aliases) 10 | , nm = alias.name 11 | , as, k, o = alias; 12 | if(!nm || !~keys.indexOf(nm)) { 13 | return null; 14 | } 15 | as = aliases[nm]; 16 | for(k in as) { 17 | if(!o[k]) o[k] = as[k]; 18 | } 19 | return o; 20 | } 21 | 22 | module.exports = find; 23 | -------------------------------------------------------------------------------- /lib/util/alias/index.js: -------------------------------------------------------------------------------- 1 | function test(req, str) { 2 | return req.rc.alias.match.test(str || ''); 3 | } 4 | 5 | module.exports = { 6 | test: test, 7 | init: require('./init'), 8 | build: require('./build'), 9 | load: require('./load'), 10 | parse: require('./parse'), 11 | find: require('./find'), 12 | expand: require('./expand'), 13 | strip: require('./strip'), 14 | } 15 | -------------------------------------------------------------------------------- /lib/util/alias/init.js: -------------------------------------------------------------------------------- 1 | var copy = require('../copy'); 2 | 3 | function init(info, req, next){ 4 | var scope = this, errors = this.errors; 5 | var file = req.dirs.user.alias; 6 | var src = req.files.alias; 7 | var options = {ncp: {clobber: this.force}, source: src, destination: file}; 8 | copy.call(this, info, req, next, options); 9 | } 10 | 11 | module.exports = init; 12 | -------------------------------------------------------------------------------- /lib/util/alias/load.js: -------------------------------------------------------------------------------- 1 | var fs = require('fs'); 2 | 3 | /** 4 | * Load user alias file if it exists. 5 | */ 6 | function load(req, cb) { 7 | var file = req.dirs.user.alias 8 | , aliases = null 9 | , log = this.log 10 | , conf = this.configure(); 11 | 12 | // have to clear cache for reloads 13 | if(conf.interactive) { 14 | delete require.cache[file]; 15 | } 16 | 17 | fs.exists(file, function(exists) { 18 | // user has no aliases 19 | conf.alias = false; 20 | if(!exists) return cb(); 21 | try { 22 | aliases = require(file); 23 | }catch(e) { 24 | log.error('malformed file %s, aliases unavailable', file); 25 | } 26 | conf.alias = aliases; 27 | cb(null, aliases); 28 | }); 29 | } 30 | 31 | module.exports = load; 32 | -------------------------------------------------------------------------------- /lib/util/alias/parse.js: -------------------------------------------------------------------------------- 1 | var re = { 2 | user: /^([^@]+)@(.*)/, 3 | auth: /^([^:]+):(.+)/, 4 | protocol: /^https?:\/\//, 5 | } 6 | 7 | var url = require('url') 8 | , querystring = require('querystring'); 9 | 10 | function parse(alias) { 11 | alias = alias || ''; 12 | alias = alias.replace(re.protocol, ''); 13 | var o = {}, parts, u; 14 | if(re.user.test(alias)) { 15 | o.username = alias.replace(re.user, '$1'); 16 | if(re.auth.test(o.username)) { 17 | o.password = o.username.replace(re.auth, '$2'); 18 | o.username = alias.replace(re.auth, '$1'); 19 | } 20 | alias = alias.replace(re.user, '$2'); 21 | } 22 | function strip(s) { 23 | return s.replace(/^\/+/, '').replace(/\/+$/, ''); 24 | } 25 | if(~alias.indexOf('/') || ~alias.indexOf('?')) { 26 | alias = strip(alias); 27 | u = url.parse(alias, true, true); 28 | parts = strip(u.pathname).split('/'); 29 | 30 | //console.dir(u); 31 | //console.dir(parts); 32 | 33 | alias = parts.shift(); 34 | if(parts.length) o.database = querystring.unescape(parts.shift()); 35 | if(parts.length) o.id = parts.join('/'); 36 | if(u.query && u.query.rev) o.rev = u.query.rev; 37 | } 38 | o.name = alias; 39 | //console.dir(o); 40 | return o; 41 | } 42 | 43 | module.exports = parse; 44 | -------------------------------------------------------------------------------- /lib/util/alias/strip.js: -------------------------------------------------------------------------------- 1 | function strip(req, str) { 2 | return (str || '').replace(req.rc.alias.match, ''); 3 | } 4 | 5 | module.exports = strip; 6 | -------------------------------------------------------------------------------- /lib/util/attach/index.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | up: require('./up'), 3 | dl: require('./dl') 4 | } 5 | -------------------------------------------------------------------------------- /lib/util/batch/index.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | exec: require('./exec'), 3 | load: require('./load'), 4 | parse: require('./parse'), 5 | schema: require('./schema'), 6 | } 7 | -------------------------------------------------------------------------------- /lib/util/batch/load.js: -------------------------------------------------------------------------------- 1 | var async = require('async'); 2 | var parser = require('./parse'); 3 | var resolve = require('../resolve'); 4 | 5 | /** 6 | * Load a series of batch files. 7 | */ 8 | function load(opts, cb) { 9 | if(typeof opts === 'function') { 10 | cb = opts; 11 | opts = null; 12 | } 13 | opts = opts || {}; 14 | var files = opts.files || []; 15 | async.concatSeries(files, function(file, cb) { 16 | file = resolve(file); 17 | opts.file = file; 18 | parser(opts, function(err, res) { 19 | cb(err, res); 20 | }) 21 | }, function(err, result) { 22 | cb(err, result); 23 | }) 24 | } 25 | 26 | module.exports = load; 27 | 28 | -------------------------------------------------------------------------------- /lib/util/batch/schema.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | type: 'object', 3 | fields: { 4 | bail: {type: 'boolean'}, 5 | interactive: {type: 'boolean'}, 6 | server: {type: 'string'}, 7 | database: {type: 'string'}, 8 | exec: {type: 'array', required: true} 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /lib/util/design/collate.js: -------------------------------------------------------------------------------- 1 | var path = require('path'); 2 | var languages = { 3 | javascript: 'javascript' 4 | } 5 | var deflang = languages.javascript; 6 | 7 | var collators = require('./collator'); 8 | 9 | function collate(tpl, req, cb) { 10 | var doc = null, lang; 11 | try { 12 | doc = require(path.join(tpl.file, 'index.json')); 13 | }catch(e) { 14 | return cb.call(this, e); 15 | } 16 | lang = doc.language || deflang; 17 | var clazz = collators[lang]; 18 | if(!clazz) { 19 | return cb.call(this, 20 | this.wrap('unsupported design document language %s', [lang])); 21 | } 22 | 23 | var opts = {tpl: tpl, req: req, doc: doc, lang: lang}; 24 | var collator = new clazz(opts); 25 | collator.collate(this, cb); 26 | } 27 | 28 | module.exports = collate; 29 | module.exports.collators = collators; 30 | -------------------------------------------------------------------------------- /lib/util/design/collator/config.js: -------------------------------------------------------------------------------- 1 | var index = 'index.json'; 2 | var keys = { 3 | rewrites: 'rewrites', 4 | views: 'views', 5 | lib: 'lib', 6 | updates: 'updates', 7 | shows: 'shows', 8 | lists: 'lists', 9 | filters: 'filters', 10 | validate_doc_update: 'validate_doc_update', 11 | map: 'map', 12 | reduce: 'reduce' 13 | } 14 | var rules = { 15 | attachments: /^attachments\//, 16 | lib: /^lib\//, 17 | docs: /^docs\//, 18 | views: /^views\//, 19 | updates: /^updates\//, 20 | shows: /^shows\//, 21 | lists: /^lists\//, 22 | filters: /^filters\//, 23 | viewslib: /^views\/lib\//, 24 | viewsfile: /^views\/[^\.\/]+\./, 25 | rewrites: /^rewrites\./, 26 | map: /^map\./, 27 | reduce: /^reduce\./, 28 | validate_doc_update: /^validate_doc_update\./ 29 | } 30 | 31 | rules.modules = /^[^\/]+/; 32 | 33 | module.exports = { 34 | index: index, 35 | keys: keys, 36 | rules: rules 37 | } 38 | -------------------------------------------------------------------------------- /lib/util/design/collator/index.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | javascript: require('./javascript'), 3 | } 4 | 5 | module.exports.default = 'javascript'; 6 | -------------------------------------------------------------------------------- /lib/util/design/directory.js: -------------------------------------------------------------------------------- 1 | var fs = require('fs'); 2 | var path = require('path'); 3 | var resolve = require('../resolve'); 4 | var fileobject = require('../file-object'); 5 | var index = require('./collator/config').index; 6 | var direxists = require('../direxists'); 7 | 8 | function directory(dir, req, cb) { 9 | var scope = this, errors = this.errors, wrap = this.wrap; 10 | dir = resolve(dir); 11 | var file = fileobject(dir, path.dirname(dir)); 12 | //console.dir(file); 13 | fs.exists(file.file, function(exists) { 14 | if(!exists) return cb.call(scope, wrap(errors.ENO_INPUT, [file.file])); 15 | direxists.call(scope, file.file, function(err, dir, stat){ 16 | if(err) cb.call(scope, err); 17 | var indexfile = path.join(dir, index); 18 | fs.exists(indexfile, function(exists) { 19 | if(!exists) return cb.call(scope, wrap(errors.ENO_INPUT, [indexfile])); 20 | cb.call(scope, null, file); 21 | }); 22 | }); 23 | }); 24 | } 25 | 26 | module.exports = directory; 27 | -------------------------------------------------------------------------------- /lib/util/design/find.js: -------------------------------------------------------------------------------- 1 | function find(name, list) { 2 | return list[name]; 3 | } 4 | 5 | module.exports = find; 6 | -------------------------------------------------------------------------------- /lib/util/design/get.js: -------------------------------------------------------------------------------- 1 | var list = require('./list') 2 | , find = require('./find') 3 | , collate = require('./collate'); 4 | 5 | function get(name, info, req, cb) { 6 | var errors = this.errors, wrap = this.wrap; 7 | name = name.replace(/^design\//, ''); 8 | list.call(this, req, function(err, list, unique) { 9 | if(err) return cb(err); 10 | tpl = find(name, unique); 11 | if(!tpl) { 12 | return cb(wrap(errors.EUNKNOWN_TEMPLATE, [name])); 13 | } 14 | collate.call(this, tpl, req, function(err, result) { 15 | cb.call(this, err, result); 16 | }) 17 | }) 18 | } 19 | 20 | module.exports = get; 21 | -------------------------------------------------------------------------------- /lib/util/design/index.js: -------------------------------------------------------------------------------- 1 | var prefix = 'design/' ; 2 | 3 | function matches(name) { 4 | return name.indexOf(prefix) === 0; 5 | } 6 | 7 | function strip(name) { 8 | return name.replace(/^design\//, ''); 9 | } 10 | 11 | function prepend(name) { 12 | if(matches(name)) return name; 13 | return prefix + name.replace(/^\/+/, ''); 14 | } 15 | 16 | module.exports = { 17 | matches: matches, 18 | strip: strip, 19 | prepend: prepend, 20 | collate: require('./collate'), 21 | find: require('./find'), 22 | list: require('./list'), 23 | get: require('./get'), 24 | directory: require('./directory'), 25 | config: require('./collator/config'), 26 | glob: { 27 | wildcard: '/**', 28 | javascript: '*.js' 29 | } 30 | } 31 | module.exports.collators = module.exports.collate.collators; 32 | module.exports.index = module.exports.collate.collators; 33 | -------------------------------------------------------------------------------- /lib/util/direxists.js: -------------------------------------------------------------------------------- 1 | var fs = require('fs'); 2 | var resolve = require('./resolve'); 3 | 4 | function direxists(target, cb) { 5 | var scope = this, wrap = this.wrap, errors = this.errors; 6 | target = resolve(target); 7 | fs.stat(target, function(err, stats) { 8 | if(err || !stats || stats && !stats.isDirectory()) { 9 | return cb.call(scope, wrap(errors.EDIRECTORY_REQUIRED, [target])); 10 | } 11 | cb.call(scope, null, target, stats); 12 | }) 13 | } 14 | 15 | module.exports = direxists; 16 | -------------------------------------------------------------------------------- /lib/util/docs/collate.js: -------------------------------------------------------------------------------- 1 | var path = require('path'); 2 | var collators = require('./collator'); 3 | 4 | function collate(options, req, cb) { 5 | options = options || {}; 6 | options.lang = options.lang || 'javascript'; 7 | var rcauto = req.rc.docs && req.rc.docs.id ? req.rc.docs.id.auto : undefined; 8 | var rcflat = req.rc.docs ? req.rc.docs.flat : undefined; 9 | if(this.autoId !== undefined) rcauto = this.autoId; 10 | if(this.flat !== undefined) rcflat = this.flat; 11 | options.auto = rcauto !== undefined ? rcauto : true; 12 | options.flat = rcflat !== undefined ? rcflat : false; 13 | options.patterns = this.glob.length ? this.glob : null; 14 | var clazz = collators[options.lang]; 15 | if(!clazz) { 16 | return cb.call(this, 17 | this.wrap('unsupported document collation language %s', [lang])); 18 | } 19 | 20 | var collator = new clazz(options); 21 | if(typeof cb === 'function') collator.collate(this, cb); 22 | return collator; 23 | } 24 | 25 | module.exports = collate; 26 | module.exports.collators = collators; 27 | -------------------------------------------------------------------------------- /lib/util/docs/collator/collator.js: -------------------------------------------------------------------------------- 1 | var match = require('../../match'); 2 | 3 | var Collator = function(options) { 4 | options = options || {}; 5 | options.documents = options.documents || {}; 6 | 7 | // strip file extensions from ids 8 | options.strip = options.strip === undefined ? true : options.strip; 9 | 10 | // inject automatic identifier 11 | options.auto = options.auto === undefined ? true : options.auto; 12 | 13 | this.ignores = options.ignores; 14 | this.system = null; 15 | this.options = options; 16 | this.includes = ['**/*.json', '**/*.js']; 17 | } 18 | 19 | Collator.prototype.files = function(cb) { 20 | var files = this.options.documents, includes = this.includes; 21 | if(this.options.flat) { 22 | files = {}; 23 | this.options.files.forEach(function(fo) { 24 | if(match(fo, includes)) { 25 | delete fo.attachments; 26 | files[fo.path] = fo; 27 | } 28 | }); 29 | } 30 | 31 | if(this.options.patterns) { 32 | for(var k in files) { 33 | fo = files[k]; 34 | if(!match(fo, this.options.patterns)) { 35 | delete files[k]; 36 | } 37 | } 38 | } 39 | this.options.originals = this.options.documents; 40 | this.options.documents = files; 41 | cb.call(this, null, files); 42 | } 43 | 44 | module.exports = Collator; 45 | -------------------------------------------------------------------------------- /lib/util/docs/collator/index.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | javascript: require('./javascript'), 3 | } 4 | 5 | module.exports.default = 'javascript'; 6 | -------------------------------------------------------------------------------- /lib/util/docs/deconstruct.js: -------------------------------------------------------------------------------- 1 | var path = require('path'); 2 | var resolve = require('../resolve'); 3 | var fileobject = require('../file-object'); 4 | 5 | function deconstruct(options, info, req, cb) { 6 | var scope = this; 7 | options = options || {}; 8 | var index = 'index' 9 | , ext = '.json'; 10 | var docs = options.docs || []; 11 | var dir = options.dir || process.cwd(); 12 | var i, a, files = [], doc, nm, fo, ao, folder; 13 | for(i = 0;i < docs.length;i++) { 14 | doc = docs[i]; 15 | nm = doc._id; 16 | folder = doc._attachments && Object.keys(doc._attachments).length; 17 | if(!folder) { 18 | fo = fileobject(path.join(dir, nm) + ext, dir); 19 | }else{ 20 | fo = fileobject(path.join(dir, nm, index) + ext, dir); 21 | if(!options.flat) { 22 | fo.attachments = []; 23 | for(a in doc._attachments) { 24 | ao = fileobject(path.join(dir, nm, a), path.join(dir, nm)); 25 | ao.key = a; 26 | fo.attachments.push(ao); 27 | } 28 | } 29 | } 30 | if(options.long) { 31 | fo.id = doc._id; 32 | fo.document = doc; 33 | } 34 | files.push(fo); 35 | } 36 | cb(null, {docs: docs, files: files}); 37 | } 38 | 39 | module.exports = deconstruct; 40 | -------------------------------------------------------------------------------- /lib/util/docs/fetch.js: -------------------------------------------------------------------------------- 1 | var get = require('./get'); 2 | var write = require('./write'); 3 | var deconstruct = require('./deconstruct'); 4 | 5 | function fetch(options, info, req, cb) { 6 | var scope = this; 7 | options = options || {}; 8 | get.call(scope, options, info, req, function(err, doc) { 9 | if(err) return cb(err); 10 | options.docs = doc.docs; 11 | deconstruct.call(scope, options, info, req, function(err, doc) { 12 | if(err) return cb(err); 13 | options.files = doc.files; 14 | write.call(scope, options, info, req, function(err, doc) { 15 | if(err) return cb(err); 16 | cb(null, doc); 17 | }); 18 | }); 19 | }) 20 | } 21 | 22 | module.exports = fetch; 23 | -------------------------------------------------------------------------------- /lib/util/docs/get.js: -------------------------------------------------------------------------------- 1 | var revs = require('./revs'); 2 | 3 | function get(options, info, req, cb) { 4 | var scope = this; 5 | options = options || {}; 6 | options.qs = options.qs || {}; 7 | options.qs.include_docs = true; 8 | revs.call(scope, options, info, req, function(err, doc) { 9 | if(err) return cb(err); 10 | if(options.strict && doc.err.length) { 11 | return cb(null, doc); 12 | } 13 | var i, row, docs = []; 14 | if(doc.result && doc.result.rows) { 15 | for(i = 0;i < doc.result.rows.length;i++) { 16 | row = doc.result.rows[i]; 17 | if(row.id && row.doc) { 18 | docs.push(row.doc); 19 | } 20 | } 21 | } 22 | 23 | cb(null, {revs: doc, docs: docs}); 24 | }) 25 | } 26 | 27 | module.exports = get; 28 | -------------------------------------------------------------------------------- /lib/util/docs/index.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | collate: require('./collate'), 3 | collect: require('./collect'), 4 | save: require('./save'), 5 | get: require('./get'), 6 | deconstruct: require('./deconstruct'), 7 | write: require('./write'), 8 | fetch: require('./fetch'), 9 | revs: require('./revs'), 10 | } 11 | -------------------------------------------------------------------------------- /lib/util/docs/revs.js: -------------------------------------------------------------------------------- 1 | function revs(options, info, req, cb) { 2 | var scope = this, log = this.log; 3 | var dbh = req.db(); 4 | options = options || {}; 5 | var qs = options.qs || {}; 6 | qs.keys = options.ids || []; 7 | var opts = req.db.options(req, {qs: qs}); 8 | dbh.db.all(opts, function(err, res, doc) { 9 | if(err) return cb(err); 10 | var rows = doc.rows || [] 11 | , row, id, rev, item, list = [], map = {}, revs = [] 12 | , err = []; 13 | for(var i = 0;i < rows.length;i++) { 14 | row = rows[i]; 15 | id = row.id; 16 | if(id && row.value) { 17 | item = {id: id, rev: row.value.rev}; 18 | list.push(item); 19 | map[id] = item.rev; 20 | revs.push(item.rev); 21 | }else{ 22 | if(!options.lenient) { 23 | list.push(row); 24 | map[row.key] = row; 25 | } 26 | err.push(row); 27 | } 28 | } 29 | cb(null, {result: doc, list: list, map: map, revs: revs, err: err}); 30 | }) 31 | } 32 | 33 | module.exports = revs; 34 | -------------------------------------------------------------------------------- /lib/util/editor/edit.js: -------------------------------------------------------------------------------- 1 | var assert = require('assert'); 2 | var EditorRequest = require('./request'); 3 | var EditorResponse = require('./response'); 4 | 5 | function Edit(req, cb) { 6 | var scope = this; 7 | assert( 8 | req instanceof EditorRequest, 9 | 'edit requires an editor request') 10 | assert(typeof cb === 'function', 11 | 'edit callback must be a function'); 12 | 13 | process.stdin.pause(); 14 | var ps = req.spawn(function(err) { 15 | var res = new EditorResponse(req, err, function(err, res) { 16 | process.stdin.resume(); 17 | //console.dir(res); 18 | cb(err, req, res, scope); 19 | }); 20 | }); 21 | } 22 | 23 | module.exports = Edit; 24 | -------------------------------------------------------------------------------- /lib/util/editor/index.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | Edit: require('./edit'), 3 | EditorRequest: require('./request'), 4 | EditorResponse: require('./response') 5 | } 6 | -------------------------------------------------------------------------------- /lib/util/exec.js: -------------------------------------------------------------------------------- 1 | var cpexec = require('child_process').exec; 2 | 3 | function exec(opts, cb) { 4 | var cmd = opts.cmd; 5 | var cpopts = opts.options || {stdio: 'inherit'}; 6 | cpexec(cmd, cpopts, function(err, stdout, stderr) { 7 | var code = err && err.code ? err.code : 0; 8 | cb(err, {out: stdout, err: stderr, code: code}); 9 | }) 10 | } 11 | 12 | module.exports = exec; 13 | -------------------------------------------------------------------------------- /lib/util/feed.js: -------------------------------------------------------------------------------- 1 | var feeds = require('cdb').feeds; 2 | 3 | function feed(conn, opts, info, req, next) { 4 | var log = this.log, type = opts.qs.feed || feeds.continuous; 5 | conn.on('error', function(err) { 6 | req.error(err, req, next); 7 | }) 8 | conn.on('response', function() { 9 | log.info('feed connection open %s (%s)', opts.server, type); 10 | }) 11 | conn.on('data', function(data) { 12 | if(/^\r?\n$/.test('' + data)) return; 13 | var doc; 14 | try { 15 | if(type === feeds.eventsource) { 16 | data = ('' + data).trim().replace(/^data:\s+/, ''); 17 | } 18 | doc = JSON.parse('' + data); 19 | }catch(e){ 20 | //console.dir('"' + data + '"'); 21 | log.warn('failed to parse feed json \'%s\'', data); 22 | } 23 | if(doc) { 24 | req.print(doc, req, function() { 25 | // TODO 26 | }); 27 | } 28 | }) 29 | return conn; 30 | } 31 | 32 | module.exports = feed; 33 | -------------------------------------------------------------------------------- /lib/util/file-object.js: -------------------------------------------------------------------------------- 1 | var path = require('path'); 2 | 3 | function fileobject(file, dir) { 4 | //console.dir('file: ' + file); 5 | if(!file) return file; 6 | var name = path.basename(file); 7 | var rel = file.replace(dir, '').replace(/^\//, ''); 8 | return {file: file, name: name, path: rel}; 9 | } 10 | 11 | module.exports = fileobject; 12 | -------------------------------------------------------------------------------- /lib/util/json/files.js: -------------------------------------------------------------------------------- 1 | var regexp = require('cli-regexp'); 2 | 3 | module.exports = function files(info, req) { 4 | var list = [], arg, i, l = info.args.length; 5 | for(i = 0;i < l;i++) { 6 | arg = info.args[i]; 7 | if(/\.json$/.test(arg)) { 8 | list.push(arg); 9 | info.args.splice(i, 1); 10 | i--; l--; 11 | } 12 | } 13 | return list; 14 | } 15 | -------------------------------------------------------------------------------- /lib/util/json/finalize.js: -------------------------------------------------------------------------------- 1 | function finalize(results) { 2 | var long = this.long 3 | , flat = this.flat 4 | , map = {} 5 | , keys = [] 6 | , collides = false 7 | , result 8 | , value; 9 | 10 | function toKeyObject(k, v, o) { 11 | o = o || {}; 12 | o[k] = v; 13 | return o; 14 | } 15 | 16 | if(!long) { 17 | if(results.length === 1) { 18 | result = results[0]; 19 | return result.value; 20 | }else{ 21 | results = results.map(function(match) { 22 | collides = collides || ~keys.indexOf(match.key); 23 | keys.push(match.key); 24 | map[match.key] = match.value; 25 | return toKeyObject(match.key, match.value); 26 | }) 27 | } 28 | } 29 | 30 | return !collides && !long ? map : results; 31 | } 32 | 33 | module.exports = finalize; 34 | -------------------------------------------------------------------------------- /lib/util/json/index.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | load: require('./load'), 3 | grep: require('./grep'), 4 | patterns: require('./patterns'), 5 | files: require('./files'), 6 | finalize: require('./finalize'), 7 | } 8 | -------------------------------------------------------------------------------- /lib/util/json/load.js: -------------------------------------------------------------------------------- 1 | var async = require('async') 2 | , fs = require('fs'); 3 | 4 | var resolve = require('../resolve'); 5 | 6 | module.exports = function load(opts, cb) { 7 | opts = opts || {}; 8 | var list = [], files = opts.files || [], i; 9 | if(opts.body) list.push(opts.body); 10 | 11 | // don't use require(), we don't want them cached 12 | async.concatSeries(files, function(file, cb) { 13 | file = resolve(file); 14 | fs.readFile(file, function(err, data) { 15 | if(err) return cb(err); 16 | data = '' + data; 17 | var doc; 18 | try { 19 | doc = JSON.parse(data); 20 | }catch(e) { 21 | return cb(e); 22 | } 23 | cb(null, doc) 24 | }) 25 | }, function(err, results) { 26 | cb(null, list.concat(results)); 27 | }) 28 | } 29 | -------------------------------------------------------------------------------- /lib/util/json/patterns.js: -------------------------------------------------------------------------------- 1 | var regexp = require('cli-regexp'); 2 | 3 | module.exports = function patterns(info, req) { 4 | var list = [], arg, i, l = info.args.length; 5 | for(i = 0;i < l;i++) { 6 | arg = info.args[i]; 7 | if(regexp.seems(arg)) { 8 | list.push(arg); 9 | info.args.splice(i, 1); 10 | i--; l--; 11 | } 12 | } 13 | return list; 14 | } 15 | -------------------------------------------------------------------------------- /lib/util/lint.js: -------------------------------------------------------------------------------- 1 | function json(data, cb) { 2 | var jsonlint = require('jsonlint'); 3 | var result; 4 | try{ 5 | result = jsonlint.parse(data); 6 | }catch(e) { 7 | return cb(e); 8 | } 9 | cb(null, result); 10 | } 11 | 12 | function js(options, cb) { 13 | options = options || {}; 14 | var jslint = require('jslint'); 15 | var opts = options.lint || { 16 | edition: 'latest', 17 | length: 100 18 | } 19 | function toError(errors) { 20 | var err = errors[0]; 21 | var msg = err.reason 22 | + ' (' + options.file + ':' + err.line + ':' + err.character + ')'; 23 | var e = new Error(msg); 24 | return e; 25 | } 26 | var ls = new jslint.LintStream(opts); 27 | ls.write({file: options.file, body: options.body}); 28 | ls.on('data', function(chunk, encoding, callback) { 29 | var ok = chunk.linted.ok; 30 | if(!ok) cb(toError(chunk.linted.errors), options.body); 31 | cb(null, options.body); 32 | }) 33 | } 34 | 35 | module.exports = { 36 | json: json, 37 | js: js 38 | } 39 | -------------------------------------------------------------------------------- /lib/util/log/prefix.js: -------------------------------------------------------------------------------- 1 | var util = require('util') 2 | , ttycolor = require('ttycolor') 3 | , ansi = ttycolor.ansi 4 | , keys = ttycolor.map; 5 | 6 | function prefixer(conf) { 7 | var scope = this 8 | , nm = this.name(); 9 | 10 | return function prefix(record, tty) { 11 | var fmt = '%s |'; 12 | if(scope.color === false || !tty) { 13 | return util.format(fmt, nm); 14 | } 15 | var color = keys.normal; 16 | var id = this.names(record.level); 17 | switch(id) { 18 | case 'error': 19 | color = keys.red; 20 | break; 21 | case 'warn': 22 | color = keys.magenta; 23 | break; 24 | } 25 | var conf = scope.configure().log; 26 | return ansi(util.format(fmt, nm))[color]; 27 | } 28 | } 29 | 30 | module.exports = prefixer; 31 | -------------------------------------------------------------------------------- /lib/util/match.js: -------------------------------------------------------------------------------- 1 | var mm = require('minimatch'); 2 | 3 | function match(file, patterns) { 4 | var f = typeof(file) === 'object' ? file.path : file; 5 | for(var i = 0;i < patterns.length;i++) { 6 | //console.log('%s test: %s (%j)', 7 | //patterns[i], f, mm(f, patterns[i])); 8 | if(mm(f, patterns[i])) { 9 | return true; 10 | } 11 | } 12 | return false; 13 | } 14 | 15 | module.exports = match; 16 | -------------------------------------------------------------------------------- /lib/util/mime.js: -------------------------------------------------------------------------------- 1 | var types = { 2 | json: 'application/json', 3 | text: 'text/plain', 4 | javascript: [ 5 | 'application/javascript', 'text/javascript', 'application/x-javascript'] 6 | }, list = []; 7 | 8 | module.exports = types; 9 | Object.keys(types).forEach(function(key) { 10 | if(Array.isArray(types[key])) { 11 | list = list.concat(types[key]); 12 | }else{ 13 | list.push(types[key]); 14 | } 15 | module.exports[key.toUpperCase()] = 16 | Array.isArray(types[key]) ? types[key][0] : types[key]; 17 | }) 18 | module.exports.list = list; 19 | -------------------------------------------------------------------------------- /lib/util/mkdirs.js: -------------------------------------------------------------------------------- 1 | var fs = require('fs'); 2 | var path = require('path'); 3 | var mkdirp = require('mkdirp'); 4 | 5 | function mkdirs(target, file, cb) { 6 | var dir = path.dirname(file); 7 | if(dir === '.') return cb(); 8 | dir = path.join(target, dir); 9 | fs.stat(dir, function(err, stats) { 10 | if(stats && stats.isFile() || stats && stats.isDirectory()) { 11 | return cb(); 12 | } 13 | mkdirp(dir, cb); 14 | }); 15 | } 16 | 17 | module.exports = mkdirs; 18 | -------------------------------------------------------------------------------- /lib/util/re.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | protocol: function() { 3 | return /^https?:$/; 4 | } 5 | } 6 | -------------------------------------------------------------------------------- /lib/util/resolve.js: -------------------------------------------------------------------------------- 1 | var path = require('path'); 2 | 3 | function resolve(file) { 4 | if(file === '.') { 5 | return process.cwd(); 6 | } 7 | if(/^\//.test(file)) { 8 | return file; 9 | } 10 | return path.normalize(path.join(process.cwd(), file)).replace(/\/+$/, ''); 11 | } 12 | module.exports = resolve; 13 | -------------------------------------------------------------------------------- /lib/util/stringify.js: -------------------------------------------------------------------------------- 1 | var circular = require('circular'); 2 | 3 | function stringify(doc, replacer, indent) { 4 | return JSON.stringify(doc, replacer ? replacer : circular(null, true), 5 | typeof indent === 'number' ? indent : 2); 6 | } 7 | 8 | module.exports = stringify; 9 | -------------------------------------------------------------------------------- /lib/util/template/fsref.js: -------------------------------------------------------------------------------- 1 | var fs = require('fs'); 2 | var resolve = require('../resolve'); 3 | 4 | function fsref(options, cb) { 5 | options = options || {}; 6 | var name = resolve(options.name); 7 | fs.stat(resolve(name), function(err, stats) { 8 | var doc = {exists: !err, stat: stats, file: name, name: options.name}; 9 | cb(doc); 10 | }); 11 | } 12 | 13 | module.exports = fsref; 14 | -------------------------------------------------------------------------------- /lib/util/template/parse.js: -------------------------------------------------------------------------------- 1 | function parse(file, req, cb) { 2 | var scope = this, errors = this.errors, wrap = this.wrap; 3 | //console.dir(errors); 4 | var func, tplreq = {vars: req.vars, file: file}; 5 | try { 6 | func = require(file); 7 | }catch(e) { 8 | return cb.call(scope, e); 9 | } 10 | if(typeof func !== 'function') { 11 | return cb.call(scope, wrap(errors.ETEMPLATE_EXPORT, [file])); 12 | } 13 | func.call(req.vars, tplreq, function(err, doc) { 14 | if(err) return cb.call(scope, err); 15 | var isObject = doc && !Array.isArray(doc) && typeof doc === 'object'; 16 | if(!isObject) { 17 | return cb.call(scope, wrap(errors.ETEMPLATE_RETURN, [file])); 18 | } 19 | cb.call(scope, null, doc); 20 | }); 21 | } 22 | 23 | module.exports = parse; 24 | -------------------------------------------------------------------------------- /lib/util/types.js: -------------------------------------------------------------------------------- 1 | var types = { 2 | json: 'json', 3 | js: 'js', 4 | text: 'text', 5 | unknown: 'unknown' 6 | }, list = []; 7 | 8 | function getByExtension(file, unknown) { 9 | if(/\.json$/.test(file)) { 10 | return types.json; 11 | }else if(/\.js$/.test(file)) { 12 | return types.js; 13 | }else if(/\.txt$/.test(file)) { 14 | return types.text; 15 | } 16 | return unknown || types.unknown; 17 | } 18 | 19 | module.exports = types; 20 | Object.keys(types).forEach(function(key) { 21 | list.push(types[key]); 22 | module.exports[key.toUpperCase()] = types[key]; 23 | }) 24 | module.exports.list = list; 25 | module.exports.getByExtension = getByExtension; 26 | -------------------------------------------------------------------------------- /lib/util/validate.js: -------------------------------------------------------------------------------- 1 | var assert = require('assert'); 2 | var Schema = require('async-validate'); 3 | 4 | require('async-validate/plugin/all'); 5 | 6 | function validate(source, descriptor, options, cb) { 7 | var scope = this; 8 | if(typeof options === 'function') { 9 | cb = options; 10 | options = null; 11 | } 12 | assert(source, 'validation source must be an object'); 13 | assert(descriptor, 'validation descriptor must be an object'); 14 | assert(typeof cb === 'function', 'validation callback must be a function'); 15 | options = options || {bail: true}; 16 | //console.dir(descriptor); 17 | //if(!options.keys) options.keys = Object.keys(descriptor); 18 | var validator = new Schema(descriptor); 19 | validator.validate(source, options, function(err, res) { 20 | cb.call( 21 | scope, 22 | res ? res.errors : [], 23 | res ? res.fields : {}, source, descriptor, options); 24 | }); 25 | } 26 | 27 | module.exports = validate; 28 | -------------------------------------------------------------------------------- /lib/util/write.js: -------------------------------------------------------------------------------- 1 | var fs = require('fs'); 2 | var Readable = require('stream').Readable; 3 | 4 | function write(doc, req, options, next) { 5 | if(typeof options === 'function') { 6 | next = options; 7 | options = null; 8 | } 9 | options = options || {}; 10 | options.output = options.output || this.output; 11 | var isStream = (doc instanceof Readable); 12 | if(req.output.exists && !this.force) { 13 | return req.error(this.errors.EFS_FILE_EXISTS, req, next); 14 | } 15 | if(isStream) { 16 | doc.once('end', function() { 17 | next(); 18 | }) 19 | doc.pipe(fs.createWriteStream(options.output)); 20 | }else{ 21 | fs.writeFile(options.output, doc, function(err) { 22 | if(err) return req.error(err, req, next); 23 | next(); 24 | }) 25 | } 26 | } 27 | 28 | module.exports = write; 29 | -------------------------------------------------------------------------------- /sbin/timeout.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env sh 2 | 3 | curl -X PUT http://localhost:5984/_config/couchdb/os_process_timeout \ 4 | -H 'Content-Type: application/json' \ 5 | -d '"30000"' 6 | 7 | -------------------------------------------------------------------------------- /test/assert/admin.js: -------------------------------------------------------------------------------- 1 | var expect = require('chai').expect; 2 | 3 | function assert(doc, name, len, gt) { 4 | expect(doc).to.be.an('object'); 5 | var keys = Object.keys(doc); 6 | expect(keys).to.be.an('array'); 7 | if(!len || gt) { 8 | expect(keys.length).to.be.gt(gt ? len : 0); 9 | }else{ 10 | expect(keys.length).to.eql(len); 11 | } 12 | if(name) { 13 | expect(!!~keys.indexOf(name)).to.eql(true); 14 | } 15 | } 16 | 17 | module.exports = assert; 18 | -------------------------------------------------------------------------------- /test/assert/batch.js: -------------------------------------------------------------------------------- 1 | var expect = require('chai').expect; 2 | var mock = require('../util/mock'); 3 | var server = require('./server'); 4 | 5 | function exec(doc) { 6 | expect(doc).to.be.an('array'); 7 | expect(doc.length).to.eql(1); 8 | server.info(doc[0]); 9 | } 10 | 11 | function parse(doc) { 12 | expect(doc).to.be.an('array'); 13 | expect(doc.length).to.eql(1); 14 | doc = doc[0]; 15 | expect(doc).to.be.an('object') 16 | expect(doc.exec).to.be.an('array'); 17 | expect(doc.options.server).to.eql(mock.server.default); 18 | 19 | //console.dir(doc.exec[0]); 20 | 21 | var exec = doc.exec[0], cmd; 22 | expect(exec).to.be.an('object'); 23 | expect(exec.cmd).to.be.an('array'); 24 | cmd = exec.cmd; 25 | expect(cmd).to.be.an('array'); 26 | expect(cmd[0]).to.eql('info'); 27 | } 28 | 29 | module.exports = { 30 | parse: parse, 31 | exec: exec, 32 | } 33 | -------------------------------------------------------------------------------- /test/assert/conf.js: -------------------------------------------------------------------------------- 1 | var expect = require('chai').expect; 2 | var mock = require('../util/mock'); 3 | 4 | function all(doc) { 5 | var keys = Object.keys(doc); 6 | expect(doc).to.be.an('object'); 7 | expect(keys).to.be.an('array'); 8 | expect(keys.length).to.be.a('number').gt(0); 9 | } 10 | 11 | function set(doc) { 12 | expect(doc).to.be.a('string').to.eql(""); 13 | } 14 | 15 | function section(doc) { 16 | expect(doc).to.be.an('object'); 17 | expect(doc[mock.conf.key]).to.be.a('string') 18 | .to.eql(mock.conf.value); 19 | } 20 | 21 | function value(doc) { 22 | expect(doc).to.be.a('string') 23 | .to.eql(mock.conf.value); 24 | } 25 | 26 | function rm(doc) { 27 | expect(doc).to.be.a('string').to.eql(mock.conf.value); 28 | } 29 | 30 | module.exports = { 31 | all: all, 32 | set: set, 33 | section: section, 34 | value: value, 35 | rm: rm 36 | } 37 | -------------------------------------------------------------------------------- /test/assert/generic.js: -------------------------------------------------------------------------------- 1 | var expect = require('chai').expect; 2 | 3 | function ok(doc) { 4 | expect(doc).to.be.an('object'); 5 | expect(doc.ok).to.eql(true); 6 | } 7 | 8 | function object(doc) { 9 | expect(doc).to.be.an('object'); 10 | } 11 | 12 | function equal(doc, expected) { 13 | expect(doc).to.be.an('object').to.eql(expected); 14 | } 15 | 16 | function empty(doc) { 17 | equal(doc, {}); 18 | } 19 | 20 | function string(doc) { 21 | expect(doc).to.be.a('string'); 22 | } 23 | 24 | module.exports = { 25 | ok: ok, 26 | object: object, 27 | empty: empty, 28 | equal: equal, 29 | string: string, 30 | } 31 | -------------------------------------------------------------------------------- /test/assert/head.js: -------------------------------------------------------------------------------- 1 | var expect = require('chai').expect; 2 | 3 | function head(doc) { 4 | expect(doc).to.be.an('object'); 5 | expect(doc.size).to.be.a('number'); 6 | expect(doc.rev).to.be.a('string'); 7 | expect(doc.status).to.eql(200); 8 | expect(doc.headers).to.be.an('object'); 9 | } 10 | 11 | module.exports = head; 12 | -------------------------------------------------------------------------------- /test/assert/index.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | alias: require('./alias'), 3 | app: require('./app'), 4 | batch: require('./batch'), 5 | bulk: require('./bulk'), 6 | error: require('./error'), 7 | generic: require('./generic'), 8 | admin: require('./admin'), 9 | server: require('./server'), 10 | user: require('./user'), 11 | conf: require('./conf'), 12 | db: require('./db'), 13 | level: require('./level'), 14 | log: require('./log'), 15 | security: require('./security'), 16 | template: require('./template'), 17 | doc: require('./doc'), 18 | view: require('./view'), 19 | attach: require('./attach'), 20 | options: require('./options'), 21 | rc: require('./rc'), 22 | replicate: require('./replicate'), 23 | } 24 | -------------------------------------------------------------------------------- /test/assert/level.js: -------------------------------------------------------------------------------- 1 | var expect = require('chai').expect; 2 | 3 | function set(doc, level) { 4 | expect(doc).to.be.an('object'); 5 | expect(doc.level).to.be.a('string').to.eql(level); 6 | expect(doc.before).to.be.a('string'); 7 | } 8 | 9 | function get(doc) { 10 | expect(doc).to.be.an('object'); 11 | expect(doc.level).to.be.a('string'); 12 | } 13 | 14 | module.exports = { 15 | get: get, 16 | set: set, 17 | } 18 | -------------------------------------------------------------------------------- /test/assert/log.js: -------------------------------------------------------------------------------- 1 | var expect = require('chai').expect; 2 | 3 | function bytes(doc, amount) { 4 | expect(doc).to.be.a('string').to.have.length.of.at.least(amount); 5 | } 6 | 7 | module.exports = { 8 | bytes: bytes, 9 | } 10 | -------------------------------------------------------------------------------- /test/assert/options.js: -------------------------------------------------------------------------------- 1 | var expect = require('chai').expect; 2 | 3 | function headers(req) { 4 | expect(req.headers).to.be.an('object'); 5 | expect(req.headers['x-couch-full-commit']) 6 | .to.be.a('string').eql('true'); 7 | expect(req.headers['if-none-match']) 8 | .to.be.a('string').eql('"revision"'); 9 | } 10 | 11 | module.exports = { 12 | headers: headers, 13 | } 14 | -------------------------------------------------------------------------------- /test/assert/security.js: -------------------------------------------------------------------------------- 1 | var expect = require('chai').expect; 2 | 3 | function ctx(doc) { 4 | expect(doc).to.be.an('object'); 5 | expect(doc.ok).to.eql(true); 6 | expect(doc.userCtx).to.be.an('object'); 7 | expect(doc.info).to.be.an('object'); 8 | } 9 | 10 | function edit(doc) { 11 | expect(doc).to.be.an('object'); 12 | expect(doc.ok).to.eql(true); 13 | } 14 | 15 | module.exports = { 16 | ctx: ctx, 17 | edit: edit, 18 | } 19 | -------------------------------------------------------------------------------- /test/assert/server.js: -------------------------------------------------------------------------------- 1 | var expect = require('chai').expect; 2 | 3 | /** 4 | * Assert on server meta data. 5 | */ 6 | function info(doc) { 7 | expect(doc).to.be.an('object'); 8 | expect(doc.couchdb).to.be.a('string'); 9 | expect(doc.uuid).to.be.a('string'); 10 | expect(doc.version).to.be.a('string'); 11 | expect(doc.vendor).to.be.an('object'); 12 | expect(doc.vendor.version).to.be.a('string'); 13 | expect(doc.vendor.name).to.be.a('string'); 14 | } 15 | 16 | /** 17 | * Assert on server statistics. 18 | */ 19 | function stats(doc) { 20 | var keys = Object.keys(doc); 21 | expect(doc).to.be.an('object'); 22 | expect(keys).to.be.an('array'); 23 | expect(keys.length).to.be.gt(0); 24 | } 25 | 26 | /** 27 | * Assert on active tasks. 28 | */ 29 | function tasks(doc) { 30 | expect(doc).to.be.an('array').of.length(0); 31 | } 32 | 33 | function uuids(doc, count) { 34 | count = count === undefined ? 1 : count; 35 | expect(doc).to.be.an('object'); 36 | expect(doc.uuids).to.be.an('array').of.length(count); 37 | expect(doc.uuids[0]).to.be.a('string'); 38 | } 39 | 40 | module.exports = { 41 | info: info, 42 | stats: stats, 43 | tasks: tasks, 44 | uuids: uuids, 45 | } 46 | -------------------------------------------------------------------------------- /test/assert/view.js: -------------------------------------------------------------------------------- 1 | var expect = require('chai').expect; 2 | 3 | function result(doc) { 4 | expect(doc.total_rows).to.be.a('number'); 5 | expect(doc.offset).to.be.a('number'); 6 | expect(doc.rows).to.be.an('array'); 7 | expect(doc.rows.length).to.be.gt(0); 8 | } 9 | 10 | function temp(doc) { 11 | expect(doc).to.be.an('object'); 12 | expect(doc.rows).to.be.an('array'); 13 | } 14 | 15 | module.exports = { 16 | result: result, 17 | temp: temp, 18 | } 19 | -------------------------------------------------------------------------------- /test/bin/editor: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env node 2 | 3 | var fs = require('fs'); 4 | var file = process.argv[2]; 5 | var contents = fs.readFileSync(file); 6 | //console.dir('editor running with contents'); 7 | //console.dir('' + contents); 8 | if(/\.json/.test(file)) { 9 | contents = JSON.parse(contents); 10 | contents.random = Math.random(); 11 | contents = JSON.stringify(contents); 12 | } 13 | fs.writeFileSync(file, contents); 14 | -------------------------------------------------------------------------------- /test/fixtures/app/attachments/deep/lorem.txt: -------------------------------------------------------------------------------- 1 | Lorem ipsum dolor sit amet, consectetur adipiscing elit. Vestibulum et gravida dui, vel lobortis leo. Sed mauris enim, accumsan in iaculis a, consectetur ac elit. Etiam id laoreet dui, id molestie tellus. Cras quis tincidunt urna. Nulla sit amet nisi justo. Vestibulum interdum eu risus id lobortis. Nulla in convallis diam. Aliquam molestie luctus lacus, ut venenatis sem tempor sed. Mauris tristique nisi at ullamcorper malesuada. Ut massa magna, gravida non turpis feugiat, hendrerit feugiat orci. Sed ultricies dictum mauris et lobortis. Donec ut ultricies turpis, aliquet fringilla enim. In hendrerit arcu vitae enim vestibulum placerat. 2 | -------------------------------------------------------------------------------- /test/fixtures/app/attachments/lipsum.txt: -------------------------------------------------------------------------------- 1 | Lorem ipsum 2 | -------------------------------------------------------------------------------- /test/fixtures/app/docs/mock-docs-alt-attachment/index.json: -------------------------------------------------------------------------------- 1 | {} 2 | -------------------------------------------------------------------------------- /test/fixtures/app/docs/mock-docs-alt-attachment/mock-docs-alt-attachment.txt: -------------------------------------------------------------------------------- 1 | Lorem ipsum 2 | -------------------------------------------------------------------------------- /test/fixtures/app/docs/mock-docs-attachment/deep/mock-docs-deep-attachment.txt: -------------------------------------------------------------------------------- 1 | Lorem ipsum 2 | -------------------------------------------------------------------------------- /test/fixtures/app/docs/mock-docs-attachment/index.json: -------------------------------------------------------------------------------- 1 | {} 2 | -------------------------------------------------------------------------------- /test/fixtures/app/docs/mock-docs-attachment/mock-docs-attachment.txt: -------------------------------------------------------------------------------- 1 | Lorem ipsum 2 | -------------------------------------------------------------------------------- /test/fixtures/app/docs/mock-docs-attachment/mock-multiple-attachment.txt: -------------------------------------------------------------------------------- 1 | Lorem ipsum 2 | -------------------------------------------------------------------------------- /test/fixtures/app/docs/mock-docs-document.json: -------------------------------------------------------------------------------- 1 | {} 2 | -------------------------------------------------------------------------------- /test/fixtures/app/docs/mock-docs-id-document.json: -------------------------------------------------------------------------------- 1 | { 2 | "_id": "mock-docs-id-document-explicit" 3 | } 4 | -------------------------------------------------------------------------------- /test/fixtures/app/filters/filter.js: -------------------------------------------------------------------------------- 1 | module.exports = function(doc, req) { 2 | return true; 3 | } 4 | -------------------------------------------------------------------------------- /test/fixtures/app/index.json: -------------------------------------------------------------------------------- 1 | { 2 | "language": "javascript", 3 | "options": { 4 | "local_seq": false, 5 | "include_design": false 6 | } 7 | } 8 | -------------------------------------------------------------------------------- /test/fixtures/app/lib/shared.js: -------------------------------------------------------------------------------- 1 | module.exports = function shared(value){return value}; 2 | -------------------------------------------------------------------------------- /test/fixtures/app/lists/json.js: -------------------------------------------------------------------------------- 1 | module.exports = function(head, req) { 2 | start({ 3 | 'headers': { 4 | 'Content-Type': 'application/json' 5 | } 6 | }); 7 | var doc = [], row; 8 | while(row = getRow()){ 9 | doc.push(row); 10 | } 11 | send(toJSON(doc)); 12 | } 13 | -------------------------------------------------------------------------------- /test/fixtures/app/module.js: -------------------------------------------------------------------------------- 1 | module.exports = function(value){return value}; 2 | -------------------------------------------------------------------------------- /test/fixtures/app/rewrites.js: -------------------------------------------------------------------------------- 1 | module.exports = [ 2 | {from: '/foo', to: '../../bar'} 3 | ]; 4 | -------------------------------------------------------------------------------- /test/fixtures/app/shows/json.js: -------------------------------------------------------------------------------- 1 | module.exports = function(doc, req) { 2 | if (!doc) { 3 | return {json: {error: 'missing', reason: 'no document to show'}} 4 | } else { 5 | return {json: doc} 6 | } 7 | } 8 | -------------------------------------------------------------------------------- /test/fixtures/app/updates/push.js: -------------------------------------------------------------------------------- 1 | module.exports = function(doc, req) { 2 | if(!doc){ 3 | return [null, {code: 400, 4 | json: 5 | { 6 | error: 'missing', 7 | reason: 'no document to update' 8 | } 9 | }]; 10 | }else{ 11 | if(req.body) { 12 | // assuming json input 13 | req.body = JSON.parse(req.body); 14 | doc.list.push(req.body); 15 | } 16 | return [doc, {json: {ok: true}}]; 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /test/fixtures/app/validate_doc_update.js: -------------------------------------------------------------------------------- 1 | module.exports = function(newDoc, oldDoc, userCtx, secObj) {} 2 | -------------------------------------------------------------------------------- /test/fixtures/app/views/all/map.js: -------------------------------------------------------------------------------- 1 | module.exports = function(doc) { 2 | emit(doc._id, null); 3 | } 4 | -------------------------------------------------------------------------------- /test/fixtures/app/views/all/reduce.js: -------------------------------------------------------------------------------- 1 | module.exports = '_count'; 2 | -------------------------------------------------------------------------------- /test/fixtures/app/views/inline.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | map: function(doc) { 3 | emit(doc._id, null); 4 | }, 5 | reduce: '_count' 6 | } 7 | -------------------------------------------------------------------------------- /test/fixtures/app/views/lib/view-shared.js: -------------------------------------------------------------------------------- 1 | module.exports = function shared(value){return value}; 2 | -------------------------------------------------------------------------------- /test/fixtures/batch.js: -------------------------------------------------------------------------------- 1 | var mock = require('../util/mock'); 2 | var fsutil = require('../util/fsutil'); 3 | 4 | var fixtures = [ 5 | 6 | // BATCH 7 | { 8 | id: 'batch/parse', 9 | description: 'Parse a batch file', 10 | cmd: [ 11 | 'batch', 12 | 'parse', 13 | fsutil.batchfile('info.js') 14 | ] 15 | }, 16 | { 17 | id: 'batch/exec', 18 | description: 'Execute a batch file', 19 | cmd: [ 20 | 'batch', 21 | 'exec', 22 | fsutil.batchfile('info.js') 23 | ] 24 | }, 25 | ]; 26 | 27 | module.exports = fixtures; 28 | -------------------------------------------------------------------------------- /test/fixtures/bulk/auto-id.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | description: 'A mock bulk document with automatically assigned id' 3 | } 4 | -------------------------------------------------------------------------------- /test/fixtures/bulk/id.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | _id: 'mock/bulk/document/id', 3 | description: 'A mock bulk document with a particular id' 4 | } 5 | -------------------------------------------------------------------------------- /test/fixtures/bulk/list.js: -------------------------------------------------------------------------------- 1 | /** 2 | * An array is converted to a document with a *list* property. 3 | */ 4 | module.exports = [ 5 | 1, 2, 3 6 | ] 7 | -------------------------------------------------------------------------------- /test/fixtures/bulk/method.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Functions are assigned to a *map* property. 3 | */ 4 | module.exports = function(doc) { 5 | emit(doc._id, null); 6 | } 7 | -------------------------------------------------------------------------------- /test/fixtures/files/batch/101-docs.js: -------------------------------------------------------------------------------- 1 | var mock = require('../../../util/mock'); 2 | 3 | var batch = { 4 | bail: true, 5 | server: mock.server.default, 6 | database: mock.database.default, 7 | interactive: false, 8 | // comment this out and it will do it's thing 9 | noop: true, 10 | exec: [ 11 | 'db add' 12 | ] 13 | } 14 | 15 | for(var i = 0;i < 101;i++) { 16 | batch.exec.push( 17 | { 18 | cmd: ['doc', 'add', "@num=" + Math.random()], 19 | id: i, 20 | // you could achieve the same result 21 | // by declaring a json object too 22 | //json: { 23 | //num: Math.random() 24 | //} 25 | } 26 | ); 27 | } 28 | 29 | batch.exec.push('db rm'); 30 | 31 | module.exports = batch; 32 | -------------------------------------------------------------------------------- /test/fixtures/files/batch/db-add-rm.js: -------------------------------------------------------------------------------- 1 | var mock = require('../../../util/mock'); 2 | 3 | var batch = { 4 | bail: true, 5 | server: mock.server.default, 6 | database: mock.database.default, 7 | interactive: false, 8 | exec: [ 9 | ['db', 'add'], 10 | ['db', 'rm'] 11 | ] 12 | } 13 | 14 | module.exports = batch; 15 | -------------------------------------------------------------------------------- /test/fixtures/files/batch/info-array.js: -------------------------------------------------------------------------------- 1 | var mock = require('../../../util/mock'); 2 | 3 | var batch = { 4 | server: mock.server.default, 5 | exec: [ 6 | ['info'] 7 | ] 8 | } 9 | 10 | module.exports = batch; 11 | -------------------------------------------------------------------------------- /test/fixtures/files/batch/info-function.js: -------------------------------------------------------------------------------- 1 | var mock = require('../../../util/mock'); 2 | 3 | module.exports = function batch(cb) { 4 | var def = { 5 | server: mock.server.default, 6 | exec: [ 7 | { 8 | cmd: ['info'] 9 | } 10 | ] 11 | } 12 | cb(null, def); 13 | } 14 | -------------------------------------------------------------------------------- /test/fixtures/files/batch/info-override.js: -------------------------------------------------------------------------------- 1 | var mock = require('../../../util/mock'); 2 | 3 | var batch = { 4 | server: mock.server.default, 5 | exec: [ 6 | { 7 | cmd: ['info'], 8 | server: mock.server.secure, 9 | } 10 | ] 11 | } 12 | 13 | module.exports = batch; 14 | -------------------------------------------------------------------------------- /test/fixtures/files/batch/info-property.js: -------------------------------------------------------------------------------- 1 | var mock = require('../../../util/mock'); 2 | 3 | var batch = { 4 | exec: [ 5 | { 6 | cmd: ['info'], 7 | id: 'docid', 8 | error: true, 9 | color: false, 10 | json: { 11 | object: { 12 | field: [1,2,3] 13 | } 14 | }, 15 | header: ['X-Couch-Full-Commit: true', 'X-Forwarded-For: 127.0.0.1'], 16 | glob: ['*.txt', '*.md', '*.html'], 17 | query: 'rev=0-1' 18 | } 19 | ] 20 | } 21 | 22 | module.exports = batch; 23 | -------------------------------------------------------------------------------- /test/fixtures/files/batch/info-string.js: -------------------------------------------------------------------------------- 1 | var mock = require('../../../util/mock'); 2 | 3 | var batch = { 4 | server: mock.server.default, 5 | exec: [ 6 | 'info' 7 | ] 8 | } 9 | 10 | module.exports = batch; 11 | -------------------------------------------------------------------------------- /test/fixtures/files/batch/info.js: -------------------------------------------------------------------------------- 1 | var mock = require('../../../util/mock'); 2 | 3 | var batch = { 4 | server: mock.server.default, 5 | exec: [ 6 | { 7 | cmd: ['info'] 8 | } 9 | ] 10 | } 11 | 12 | module.exports = batch; 13 | -------------------------------------------------------------------------------- /test/fixtures/params.js: -------------------------------------------------------------------------------- 1 | var params = { 2 | server: '{server}', 3 | db: '{db}', 4 | ptn: '{ptn}', 5 | docid: '{docid}', 6 | attname: '{attname}', 7 | rev: '{rev}', 8 | view: '{view}', 9 | path: '{path}', 10 | ddoc: '{ddoc}', 11 | section: '{section}', 12 | key: '{key}', 13 | value: '{value}', 14 | func: '{func}', 15 | name: '{username}', 16 | pass: '{password}', 17 | file: '{file}', 18 | directory: '{dir}', 19 | template: '{template}' 20 | } 21 | 22 | module.exports = params; 23 | -------------------------------------------------------------------------------- /test/fixtures/security.json: -------------------------------------------------------------------------------- 1 | { 2 | "members": { 3 | "names": [], 4 | "roles": ["mock-role"] 5 | } 6 | } 7 | -------------------------------------------------------------------------------- /test/fixtures/template/error/etemplate-export.js: -------------------------------------------------------------------------------- 1 | module.exports = {}; 2 | -------------------------------------------------------------------------------- /test/fixtures/template/error/etemplate-return.js: -------------------------------------------------------------------------------- 1 | module.exports = function template(req, cb) { 2 | cb(null, []); 3 | } 4 | -------------------------------------------------------------------------------- /test/fixtures/template/mock-template.js: -------------------------------------------------------------------------------- 1 | module.exports = function template(req, cb) { 2 | var doc = {}; 3 | for(var z in this) { 4 | doc[z] = this[z]; 5 | } 6 | cb(null, doc); 7 | } 8 | -------------------------------------------------------------------------------- /test/fixtures/updates/mock-list-item.json: -------------------------------------------------------------------------------- 1 | { 2 | "type": "item" 3 | } 4 | -------------------------------------------------------------------------------- /test/fixtures/urls.js: -------------------------------------------------------------------------------- 1 | var api = 'http://docs.couchdb.org/en/latest/api'; 2 | var docs = { 3 | server: 'server/common.html', 4 | auth: 'server/authn.html', 5 | database: 'database/common.html', 6 | config: 'server/configuration.html', 7 | security: 'database/security.html', 8 | compact: 'database/compact.html', 9 | changes: 'database/changes.html', 10 | bulk: 'database/bulk-api.html', 11 | temp : 'database/temp-views.html', 12 | misc: 'database/misc.html', 13 | document: 'document/common.html', 14 | attachment: 'document/attachments.html', 15 | local: 'local.html', 16 | ddoc: 'ddoc/common.html', 17 | views: 'ddoc/views.html', 18 | render: 'ddoc/render.html', 19 | rewrites: 'ddoc/rewrites.html' 20 | } 21 | 22 | module.exports = { 23 | api: api, 24 | docs: docs 25 | } 26 | -------------------------------------------------------------------------------- /test/mocha.opts: -------------------------------------------------------------------------------- 1 | -u bdd 2 | --recursive 3 | --bail 4 | --check-leaks 5 | --reporter list 6 | --timeout 20000 7 | -A 8 | -------------------------------------------------------------------------------- /test/spec/batch/lifecycle.js: -------------------------------------------------------------------------------- 1 | var setup = require('../../util/setup'); 2 | var teardown = require('../../util/teardown'); 3 | 4 | var config = require('../../util/config'); 5 | var pkg = config.paths.pkg; 6 | var program = config.program; 7 | 8 | var qt = require('../../fixtures/qt'); 9 | 10 | describe('rlx:', function() { 11 | 12 | it('should parse batch file (command)', function(done){ 13 | var mock = config.file('batch-parse.json'); 14 | var args = qt.getArguments('batch/parse', {output: mock}); 15 | var def = program(require(pkg), config.name) 16 | def.program.on('complete', function(req) { 17 | var doc = config.json(mock); 18 | config.assert.batch.parse(doc); 19 | done(); 20 | }) 21 | def.parse(args); 22 | }); 23 | 24 | it('should execute batch file (command)', function(done){ 25 | var mock = config.file('batch-exec.json'); 26 | var args = qt.getArguments('batch/exec', {output: mock}); 27 | var def = program(require(pkg), config.name) 28 | def.program.on('complete', function(req) { 29 | var doc = config.json(mock); 30 | config.assert.batch.exec(doc, req); 31 | done(); 32 | }) 33 | def.parse(args); 34 | }); 35 | }) 36 | -------------------------------------------------------------------------------- /test/spec/command/unknown.js: -------------------------------------------------------------------------------- 1 | var config = require('../../util/config'); 2 | var pkg = config.paths.pkg; 3 | var program = config.program; 4 | 5 | describe('rlx:', function() { 6 | it('should error on unknown command', function(done){ 7 | var args = [ 8 | 'unknown', 9 | '-s=' + config.server.default, 10 | '--no-color' 11 | ]; 12 | var def = program(require(pkg), config.name); 13 | var errors = def.program.errors; 14 | def.program.on('error', function(err) { 15 | config.error.command(err, errors); 16 | done(); 17 | }) 18 | def.parse(args); 19 | }); 20 | }) 21 | -------------------------------------------------------------------------------- /test/spec/db/temp.js: -------------------------------------------------------------------------------- 1 | var setup = require('../../util/setup'); 2 | var teardown = require('../../util/teardown'); 3 | 4 | var config = require('../../util/config'); 5 | var pkg = config.paths.pkg; 6 | var program = config.program; 7 | var database = config.database.default; 8 | 9 | describe('rlx:', function() { 10 | before(function(done) { 11 | setup.edit.mock(function() { 12 | setup.db.add(done); 13 | }); 14 | }) 15 | after(function(done) { 16 | teardown.edit.restore(function() { 17 | teardown.db.rm(done); 18 | }); 19 | }) 20 | it('should execute temp view', function(done){ 21 | var mock = config.file('database-view-temp.json'); 22 | var args = [ 23 | 'db', 24 | 'temp', 25 | '-s', 26 | config.server.default, 27 | '-d', 28 | database, 29 | '--no-color', 30 | '-o', mock 31 | ]; 32 | var def = program(require(pkg), config.name) 33 | def.program.on('complete', function(req) { 34 | var doc = config.json(mock); 35 | config.assert.view.temp(doc); 36 | done(); 37 | }) 38 | def.parse(args); 39 | }); 40 | }); 41 | -------------------------------------------------------------------------------- /test/spec/doc/edit.js: -------------------------------------------------------------------------------- 1 | var setup = require('../../util/setup'); 2 | var teardown = require('../../util/teardown'); 3 | 4 | var config = require('../../util/config'); 5 | var pkg = config.paths.pkg; 6 | var program = config.program; 7 | 8 | describe('rlx:', function() { 9 | before(function(done) { 10 | setup.edit.mock(function() { 11 | setup.db.add(function() { 12 | setup.doc.add(done); 13 | }); 14 | }); 15 | }) 16 | after(function(done) { 17 | teardown.edit.restore(function() { 18 | teardown.db.rm(done); 19 | }); 20 | }) 21 | it('should edit document', function(done){ 22 | var mock = config.file('edit-mock-document.json'); 23 | var args = [ 24 | 'doc', 25 | 'edit', 26 | '-s', 27 | config.server.default, 28 | '-d', 29 | config.database.default, 30 | '--id', 31 | config.document.id, 32 | '--no-color', 33 | '-o', mock 34 | ]; 35 | var def = program(require(pkg), config.name) 36 | def.program.on('complete', function(req) { 37 | var doc = config.json(mock); 38 | config.assert.doc.edit(doc, config.document.id); 39 | done(); 40 | }) 41 | def.parse(args); 42 | }); 43 | }); 44 | -------------------------------------------------------------------------------- /test/spec/edit/error.js: -------------------------------------------------------------------------------- 1 | var config = require('../../util/config'); 2 | var pkg = config.paths.pkg; 3 | var program = config.program; 4 | var database = config.database.default; 5 | 6 | describe('rlx:', function() { 7 | it('should error on no document', function(done){ 8 | var args = [ 9 | 'edit', 10 | '--no-color' 11 | ]; 12 | var def = program(require(pkg), config.name) 13 | var errors = def.program.errors; 14 | def.program.on('error', function(err) { 15 | config.error.document(err, errors); 16 | done(); 17 | }) 18 | def.parse(args); 19 | }); 20 | }) 21 | -------------------------------------------------------------------------------- /test/spec/lint/json.js: -------------------------------------------------------------------------------- 1 | var config = require('../../util/config'); 2 | var pkg = config.paths.pkg; 3 | var program = config.program; 4 | 5 | describe('rlx:', function() { 6 | it('should lint remote file (json)', function(done){ 7 | var mock = config.file('lint-remote.json'); 8 | var args = [ 9 | 'lint', 10 | '-f=' + config.server.default, 11 | '--no-color', 12 | '-o', mock 13 | ]; 14 | var def = program(require(pkg), config.name) 15 | def.program.on('complete', function(req) { 16 | var doc = config.json(mock); 17 | config.assert.server.info(doc); 18 | done(); 19 | }) 20 | def.parse(args); 21 | }); 22 | it('should lint local file (json)', function(done){ 23 | var mock = config.file('lint-local.json'); 24 | var args = [ 25 | 'lint', 26 | '-f=' + pkg, 27 | '--no-color', 28 | '-o', mock 29 | ]; 30 | var def = program(require(pkg), config.name) 31 | def.program.on('complete', function(req) { 32 | var doc = config.json(mock); 33 | config.assert.generic.equal(doc, require(pkg)); 34 | done(); 35 | }) 36 | def.parse(args); 37 | }); 38 | }) 39 | -------------------------------------------------------------------------------- /test/spec/options/force.js: -------------------------------------------------------------------------------- 1 | var config = require('../../util/config'); 2 | var pkg = config.paths.pkg; 3 | var program = config.program; 4 | 5 | describe('rlx:', function() { 6 | var mock; 7 | before(function(done) { 8 | mock = config.file('force-option.json', '{}'); 9 | done(); 10 | }) 11 | after(function(done) { 12 | config.rmfile(mock); 13 | done(); 14 | }) 15 | it('should error on existing file', function(done){ 16 | var args = [ 17 | 'info', 18 | '-s=' + config.server.default, 19 | '--no-color', 20 | '-o=' + mock 21 | ]; 22 | var def = program(require(pkg), config.name); 23 | var errors = def.program.errors; 24 | def.program.on('error', function(err) { 25 | config.error.fsexists(err, errors); 26 | done(); 27 | }) 28 | def.parse(args); 29 | }); 30 | 31 | it('should overwrite existing file (--force)', function(done){ 32 | var args = [ 33 | 'info', 34 | '--force', 35 | '-s=' + config.server.default, 36 | '--no-color', 37 | '-o=' + mock 38 | ]; 39 | var def = program(require(pkg), config.name); 40 | var errors = def.program.errors; 41 | def.program.on('complete', function(req) { 42 | var doc = config.json(mock); 43 | config.assert.server.info(doc); 44 | done(); 45 | }) 46 | def.parse(args); 47 | }); 48 | }) 49 | -------------------------------------------------------------------------------- /test/spec/security/edit.js: -------------------------------------------------------------------------------- 1 | var setup = require('../../util/setup'); 2 | var teardown = require('../../util/teardown'); 3 | 4 | var config = require('../../util/config'); 5 | var pkg = config.paths.pkg; 6 | var program = config.program; 7 | 8 | describe('rlx:', function() { 9 | before(function(done) { 10 | setup.edit.mock(function() { 11 | setup.db.add(function() { 12 | setup.doc.add(done); 13 | }); 14 | }); 15 | }) 16 | after(function(done) { 17 | teardown.edit.restore(function() { 18 | teardown.db.rm(done); 19 | }); 20 | }) 21 | it('should edit document', function(done){ 22 | var mock = config.file('edit-mock-security.json'); 23 | var args = [ 24 | 'sec', 25 | 'edit', 26 | '-s', 27 | config.server.default, 28 | '-d', 29 | config.database.default, 30 | '--no-color', 31 | '-o', mock 32 | ]; 33 | var def = program(require(pkg), config.name) 34 | def.program.on('complete', function(req) { 35 | var doc = config.json(mock); 36 | config.assert.security.edit(doc, false); 37 | done(); 38 | }) 39 | def.parse(args); 40 | }); 41 | }); 42 | -------------------------------------------------------------------------------- /test/spec/server/info.js: -------------------------------------------------------------------------------- 1 | var qt = require('../../fixtures/qt'); 2 | var config = require('../../util/config'); 3 | var pkg = config.paths.pkg; 4 | var program = config.program; 5 | 6 | describe('rlx:', function() { 7 | it('should retrieve server information', function(done){ 8 | var mock = config.file('server-info.json'); 9 | var args = qt.getArguments('info', {output: mock}); 10 | var def = program(require(pkg), config.name) 11 | def.program.on('complete', function(req) { 12 | var doc = config.json(mock); 13 | config.assert.server.info(doc); 14 | done(); 15 | }) 16 | def.parse(args); 17 | }); 18 | }) 19 | -------------------------------------------------------------------------------- /test/spec/server/restart.js: -------------------------------------------------------------------------------- 1 | var qt = require('../../fixtures/qt'); 2 | var config = require('../../util/config'); 3 | var pkg = config.paths.pkg; 4 | var program = config.program; 5 | 6 | var assert = config.assert.generic.ok; 7 | 8 | describe('rlx:', function() { 9 | it('should restart server', function(done){ 10 | var mock = config.file('server-restart.json'); 11 | var args = qt.getArguments('restart', {output: mock}); 12 | var def = program(require(pkg), config.name) 13 | def.program.on('complete', function(req) { 14 | var doc = config.json(mock); 15 | assert(doc); 16 | done(); 17 | }) 18 | def.parse(args); 19 | }); 20 | }) 21 | -------------------------------------------------------------------------------- /test/spec/server/stats.js: -------------------------------------------------------------------------------- 1 | var qt = require('../../fixtures/qt'); 2 | var config = require('../../util/config'); 3 | var pkg = config.paths.pkg; 4 | var program = config.program; 5 | 6 | var assert = config.assert.server.stats; 7 | 8 | describe('rlx:', function() { 9 | it('should retrieve server statistics', function(done){ 10 | var mock = config.file('server-stats.json'); 11 | var args = qt.getArguments('stats', {output: mock}); 12 | var def = program(require(pkg), config.name) 13 | def.program.on('complete', function(req) { 14 | var doc = config.json(mock); 15 | assert(doc); 16 | done(); 17 | }) 18 | def.parse(args); 19 | }); 20 | }) 21 | -------------------------------------------------------------------------------- /test/spec/server/tasks.js: -------------------------------------------------------------------------------- 1 | var qt = require('../../fixtures/qt'); 2 | var config = require('../../util/config'); 3 | var pkg = config.paths.pkg; 4 | var program = config.program; 5 | 6 | var assert = config.assert.server.tasks; 7 | 8 | describe('rlx:', function() { 9 | it('should retrieve active tasks', function(done){ 10 | var mock = config.file('server-tasks.json'); 11 | var args = qt.getArguments('tasks', {output: mock}); 12 | var def = program(require(pkg), config.name) 13 | def.program.on('complete', function(req) { 14 | var doc = config.json(mock); 15 | assert(doc); 16 | done(); 17 | }) 18 | def.parse(args); 19 | }); 20 | }) 21 | -------------------------------------------------------------------------------- /test/spec/server/uuids.js: -------------------------------------------------------------------------------- 1 | var qt = require('../../fixtures/qt'); 2 | var config = require('../../util/config'); 3 | var pkg = config.paths.pkg; 4 | var program = config.program; 5 | 6 | var assert = config.assert.server.uuids; 7 | 8 | describe('rlx:', function() { 9 | it('should retrieve uuids', function(done){ 10 | var mock = config.file('server-uuids.json'); 11 | //var args = qt.getArguments('uuids', {output: mock}); 12 | var args = [ 13 | 'uuids', 14 | '--no-color', 15 | '-s=' + config.server.default, 16 | '-o', mock 17 | ]; 18 | var def = program(require(pkg), config.name) 19 | def.program.on('complete', function() { 20 | var doc = config.json(mock); 21 | assert(doc); 22 | done(); 23 | }) 24 | def.parse(args); 25 | }); 26 | it('should retrieve uuids using --count', function(done){ 27 | var mock = config.file('server-uuids-count.json'); 28 | var count = 10; 29 | var args = qt.getArguments('uuids', {output: mock, args: ['--count', count]}); 30 | var def = program(require(pkg), config.name) 31 | def.program.on('complete', function() { 32 | var doc = config.json(mock); 33 | assert(doc, count); 34 | done(); 35 | }) 36 | def.parse(args); 37 | }); 38 | }) 39 | -------------------------------------------------------------------------------- /test/spec/session/error.js: -------------------------------------------------------------------------------- 1 | var config = require('../../util/config'); 2 | var pkg = config.paths.pkg; 3 | var program = config.program; 4 | 5 | describe('rlx:', function() { 6 | it('should error on session/get (server required)', function(done){ 7 | var args = [ 8 | 'session', 9 | 'get', 10 | '--no-color' 11 | ]; 12 | var def = program(require(pkg), config.name); 13 | var errors = def.program.errors; 14 | def.program.on('error', function(err) { 15 | config.error.server(err, errors); 16 | done(); 17 | }) 18 | def.parse(args); 19 | }); 20 | it('should error on session/rm (server required)', function(done){ 21 | var args = [ 22 | 'session', 23 | 'rm', 24 | '--no-color' 25 | ]; 26 | var def = program(require(pkg), config.name); 27 | var errors = def.program.errors; 28 | def.program.on('error', function(err) { 29 | config.error.server(err, errors); 30 | done(); 31 | }) 32 | def.parse(args); 33 | }); 34 | }) 35 | -------------------------------------------------------------------------------- /test/spec/session/lifecycle.js: -------------------------------------------------------------------------------- 1 | var config = require('../../util/config'); 2 | var pkg = config.paths.pkg; 3 | var program = config.program; 4 | 5 | describe('rlx:', function() { 6 | it('should get session document', function(done){ 7 | var mock = config.file('session-get.json'); 8 | var args = [ 9 | 'session', 10 | 'get', 11 | '--no-color', 12 | '-s=' + config.server.default, 13 | '-o', mock 14 | ]; 15 | var def = program(require(pkg), config.name) 16 | def.program.on('complete', function(req) { 17 | var doc = config.json(mock); 18 | config.assert.security.ctx(doc); 19 | done(); 20 | }) 21 | def.parse(args); 22 | }); 23 | 24 | it('should delete session document', function(done){ 25 | var mock = config.file('session-rm.json'); 26 | var args = [ 27 | 'session', 28 | 'rm', 29 | '--no-color', 30 | '-s=' + config.server.default, 31 | '-o', mock 32 | ]; 33 | var def = program(require(pkg), config.name) 34 | def.program.on('complete', function(req) { 35 | var doc = config.json(mock); 36 | config.assert.generic.ok(doc); 37 | done(); 38 | }) 39 | def.parse(args); 40 | }); 41 | }) 42 | -------------------------------------------------------------------------------- /test/spec/session/login.js: -------------------------------------------------------------------------------- 1 | var setup = require('../../util/setup'); 2 | var teardown = require('../../util/teardown'); 3 | 4 | var config = require('../../util/config'); 5 | var pkg = config.paths.pkg; 6 | var program = config.program; 7 | 8 | describe('rlx:', function() { 9 | before(function(done) { 10 | setup.admin.add(done); 11 | }) 12 | after(function(done) { 13 | teardown.admin.rm(done); 14 | }) 15 | 16 | it('should set session document (login)', function(done){ 17 | var mock = config.file('login.json'); 18 | var args = [ 19 | 'login', 20 | '-u', 21 | config.admin.name, 22 | '-p', 23 | config.admin.pass, 24 | '--no-color', 25 | '-s=' + config.server.default, 26 | '-o', mock, 27 | '--no-interactive' 28 | ]; 29 | var def = program(require(pkg), config.name) 30 | def.program.on('complete', function() { 31 | var doc = config.json(mock); 32 | config.assert.security.ctx(doc); 33 | done(); 34 | }) 35 | def.parse(args); 36 | }); 37 | }) 38 | -------------------------------------------------------------------------------- /test/spec/session/logout.js: -------------------------------------------------------------------------------- 1 | var config = require('../../util/config'); 2 | var pkg = config.paths.pkg; 3 | var program = config.program; 4 | 5 | describe('rlx:', function() { 6 | it('should logout session', function(done){ 7 | var mock = config.file('session-logout.json'); 8 | var args = [ 9 | 'logout', 10 | '--no-color', 11 | '-s=' + config.server.default, 12 | '-o', mock 13 | ]; 14 | var def = program(require(pkg), config.name) 15 | def.program.on('complete', function() { 16 | var doc = config.json(mock); 17 | config.assert.generic.ok(doc); 18 | done(); 19 | }) 20 | def.parse(args); 21 | }); 22 | }) 23 | -------------------------------------------------------------------------------- /test/spec/session/whoami.js: -------------------------------------------------------------------------------- 1 | var config = require('../../util/config'); 2 | var pkg = config.paths.pkg; 3 | var program = config.program; 4 | 5 | describe('rlx:', function() { 6 | it('should get session document (whoami)', function(done){ 7 | var mock = config.file('whoami.json'); 8 | var args = [ 9 | 'whoami', 10 | '--no-color', 11 | '-s=' + config.server.default, 12 | '-o', mock 13 | ]; 14 | var def = program(require(pkg), config.name) 15 | def.program.on('complete', function() { 16 | var doc = config.json(mock); 17 | config.assert.security.ctx(doc); 18 | done(); 19 | }) 20 | def.parse(args); 21 | }); 22 | }) 23 | -------------------------------------------------------------------------------- /test/spec/user/edit.js: -------------------------------------------------------------------------------- 1 | var setup = require('../../util/setup'); 2 | var teardown = require('../../util/teardown'); 3 | 4 | var config = require('../../util/config'); 5 | var pkg = config.paths.pkg; 6 | var program = config.program; 7 | 8 | var assert = config.assert.user.edit; 9 | 10 | describe('rlx:', function() { 11 | before(function(done) { 12 | setup.edit.mock(function() { 13 | setup.db.add(function() { 14 | setup.user.add(done); 15 | }); 16 | }); 17 | }) 18 | after(function(done) { 19 | teardown.edit.restore(function() { 20 | teardown.db.rm(function() { 21 | teardown.user.rm(done); 22 | }); 23 | }); 24 | }) 25 | it('should edit user document', function(done){ 26 | var mock = config.file('edit-mock-user.json'); 27 | var args = [ 28 | 'user', 29 | 'edit', 30 | '-s=' + config.server.default, 31 | '--id=' + config.user.name, 32 | '--no-color', 33 | '-o', mock 34 | ]; 35 | var def = program(require(pkg), config.name) 36 | def.program.on('complete', function() { 37 | var doc = config.json(mock); 38 | assert(doc, config.user.id); 39 | done(); 40 | }) 41 | def.parse(args); 42 | }); 43 | }); 44 | -------------------------------------------------------------------------------- /test/util/config.js: -------------------------------------------------------------------------------- 1 | var fs = require('fs'); 2 | var path = require('path'); 3 | var mock = require('./mock'); 4 | var fsutil = require('./fsutil'); 5 | 6 | // mock data 7 | var config = mock; 8 | 9 | // file helpers 10 | for(var k in fsutil) { 11 | config[k] = fsutil[k]; 12 | } 13 | 14 | // assertion helpers 15 | var assert = require('../assert'); 16 | config.assert = require('../assert'); 17 | config.error = assert.error; 18 | 19 | /** 20 | * Load test fixtures. 21 | */ 22 | function fixtures() { 23 | var files = fs.readdirSync(config.paths.fixtures) 24 | , file, key, pth, item, contents; 25 | for(var i = 0;i < files.length;i++) { 26 | file = files[i]; 27 | contents = null; 28 | key = path.basename(file, '.json'); 29 | pth = path.join(config.paths.fixtures, file); 30 | config.paths[key] = pth; 31 | var stats = fs.statSync(pth); 32 | if(stats.isFile()) { 33 | contents = '' + fs.readFileSync(pth); 34 | } 35 | item = { 36 | name: file, 37 | path: pth, 38 | doc: contents, 39 | data: contents && /\.json$/.test(file) ? JSON.parse(contents) : contents 40 | } 41 | config.fixtures[key] = item; 42 | } 43 | } 44 | 45 | fixtures(); 46 | 47 | module.exports = config; 48 | -------------------------------------------------------------------------------- /test/util/fsutil.js: -------------------------------------------------------------------------------- 1 | var fs = require('fs') 2 | , path = require('path') 3 | , mock = require('./mock'); 4 | 5 | var fsutil = {}; 6 | fsutil.file = function(name, content) { 7 | var file = path.join(mock.paths.target, name); 8 | if(content) { 9 | fs.writeFileSync(file, content); 10 | } 11 | return file; 12 | } 13 | 14 | fsutil.batchfile = function(name) { 15 | return path.join(mock.paths.batch, name); 16 | } 17 | 18 | fsutil.rmfile = function(file) { 19 | fs.unlinkSync(file); 20 | } 21 | 22 | fsutil.json = function(file) { 23 | var contents = fsutil.text(file); 24 | //console.log('contents: %s', contents); 25 | return JSON.parse(contents); 26 | } 27 | 28 | fsutil.text = function(file) { 29 | return '' + fs.readFileSync(file); 30 | } 31 | 32 | fsutil.require = function(file) { 33 | return require(file); 34 | } 35 | 36 | module.exports = fsutil; 37 | -------------------------------------------------------------------------------- /test/util/setup/admin.js: -------------------------------------------------------------------------------- 1 | var cdb = require('cdb'); 2 | var jar = require('../../../lib/jar'); 3 | var dbh = new cdb({jar: jar}); 4 | var mock = require('../mock'); 5 | var admins = cdb.sections.admins; 6 | 7 | var admin = { 8 | add: function(opts, cb){ 9 | if(typeof opts === 'function') { 10 | cb = opts; 11 | opts = null; 12 | } 13 | opts = opts || {}; 14 | opts.server = opts.server || mock.server.default; 15 | opts.section = admins; 16 | opts.key = opts.key || mock.admin.name; 17 | opts.value = opts.value || mock.admin.pass; 18 | dbh.config.set(opts, cb); 19 | } 20 | } 21 | 22 | module.exports = admin; 23 | -------------------------------------------------------------------------------- /test/util/setup/alias.js: -------------------------------------------------------------------------------- 1 | var mock = require('../mock'); 2 | var pkg = mock.paths.pkg; 3 | var program = mock.program; 4 | 5 | var hs = require('./home'); 6 | var ht = require('../teardown/home'); 7 | 8 | var alias = { 9 | init: function(done) { 10 | hs.mock(function() { 11 | var file = mock.file('setup-alias-init.json'); 12 | var args = ['as', 'init', '-o', file, '--force', '--no-color']; 13 | var def = program(require(pkg), mock.name) 14 | def.program.on('complete', function(/*req*/) { 15 | ht.restore(done); 16 | }) 17 | def.parse(args); 18 | }); 19 | } 20 | } 21 | 22 | module.exports = alias; 23 | -------------------------------------------------------------------------------- /test/util/setup/bulk.js: -------------------------------------------------------------------------------- 1 | var cdb = require('cdb'); 2 | var jar = require('../../../lib/jar'); 3 | var dbh = new cdb({jar: jar}); 4 | var mock = require('../mock'); 5 | 6 | var doc = { 7 | docs: [ 8 | {_id: 'foo', list: []}, 9 | {_id: 'bar', list: []}, 10 | {_id: 'baz', list: []} 11 | ] 12 | }; 13 | 14 | var bulk = { 15 | add: function(opts, cb){ 16 | if(typeof opts === 'function') { 17 | cb = opts; 18 | opts = null; 19 | } 20 | opts = opts || {}; 21 | opts.server = opts.server || mock.server.default; 22 | opts.db = opts.db || mock.database.default; 23 | opts.body = opts.body || doc; 24 | dbh.db.bulk(opts, cb); 25 | } 26 | } 27 | 28 | module.exports = bulk; 29 | -------------------------------------------------------------------------------- /test/util/setup/db.js: -------------------------------------------------------------------------------- 1 | var cdb = require('cdb'); 2 | var jar = require('../../../lib/jar'); 3 | var dbh = new cdb({jar: jar}); 4 | var mock = require('../mock'); 5 | 6 | var db = { 7 | add: function(opts, cb){ 8 | if(typeof opts === 'function') { 9 | cb = opts; 10 | opts = null; 11 | } 12 | opts = opts || {}; 13 | opts.server = opts.server || mock.server.default; 14 | opts.db = opts.db || mock.database.default; 15 | dbh.db.add(opts, cb); 16 | } 17 | } 18 | 19 | module.exports = db; 20 | -------------------------------------------------------------------------------- /test/util/setup/ddoc.js: -------------------------------------------------------------------------------- 1 | var cdb = require('cdb'); 2 | var jar = require('../../../lib/jar'); 3 | var dbh = new cdb({jar: jar}); 4 | var mock = require('../mock'); 5 | 6 | var ddoc = { 7 | add: function(opts, cb){ 8 | if(typeof opts === 'function') { 9 | cb = opts; 10 | opts = null; 11 | } 12 | opts = opts || {}; 13 | opts.server = opts.server || mock.server.default; 14 | opts.db = opts.db || mock.database.default; 15 | opts.ddoc = opts.ddoc || mock.app.ddoc; 16 | opts.body = opts.body || {language: 'javascript'}; 17 | dbh.design.add(opts, cb); 18 | } 19 | } 20 | 21 | module.exports = ddoc; 22 | -------------------------------------------------------------------------------- /test/util/setup/doc.js: -------------------------------------------------------------------------------- 1 | var cdb = require('cdb'); 2 | var jar = require('../../../lib/jar'); 3 | var dbh = new cdb({jar: jar}); 4 | var mock = require('../mock'); 5 | 6 | var doc = { 7 | add: function(opts, cb){ 8 | if(typeof opts === 'function') { 9 | cb = opts; 10 | opts = null; 11 | } 12 | opts = opts || {}; 13 | opts.server = opts.server || mock.server.default; 14 | opts.db = opts.db || mock.database.default; 15 | opts.id = opts.id || mock.document.id; 16 | opts.body = opts.body || {_id: mock.document.id}; 17 | dbh.doc.add(opts, cb); 18 | } 19 | } 20 | 21 | module.exports = doc; 22 | -------------------------------------------------------------------------------- /test/util/setup/edit.js: -------------------------------------------------------------------------------- 1 | var mock = require('../mock'); 2 | 3 | var edit = { 4 | mock: function(cb){ 5 | module.exports.editor = process.env.EDITOR; 6 | module.exports.visual = process.env.VISUAL; 7 | process.env.VISUAL = process.env.EDITOR = mock.editor; 8 | cb(); 9 | } 10 | } 11 | 12 | module.exports = edit; 13 | -------------------------------------------------------------------------------- /test/util/setup/home.js: -------------------------------------------------------------------------------- 1 | var mock = require('../mock'); 2 | 3 | var home = { 4 | mock: function(cb){ 5 | module.exports.HOME = process.env.HOME; 6 | process.env.HOME = mock.usr.home; 7 | cb(); 8 | } 9 | } 10 | 11 | module.exports = home; 12 | -------------------------------------------------------------------------------- /test/util/setup/index.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | admin: require('./admin'), 3 | alias: require('./alias'), 4 | bulk: require('./bulk'), 5 | db: require('./db'), 6 | ddoc: require('./ddoc'), 7 | doc: require('./doc'), 8 | edit: require('./edit'), 9 | home: require('./home'), 10 | user: require('./user'), 11 | } 12 | -------------------------------------------------------------------------------- /test/util/setup/user.js: -------------------------------------------------------------------------------- 1 | var cdb = require('cdb'); 2 | var jar = require('../../../lib/jar'); 3 | var dbh = new cdb({jar: jar}); 4 | var mock = require('../mock'); 5 | 6 | var user = { 7 | add: function(opts, cb){ 8 | if(typeof opts === 'function') { 9 | cb = opts; 10 | opts = null; 11 | } 12 | opts = opts || {}; 13 | opts.server = opts.server || mock.server.default; 14 | opts.db = opts.db || mock.database.users; 15 | opts.id = opts.id || mock.user.id; 16 | opts.body = mock.user; 17 | opts.body.roles = opts.body.roles.split(','); 18 | dbh.doc.add(opts, cb); 19 | } 20 | } 21 | 22 | module.exports = user; 23 | -------------------------------------------------------------------------------- /test/util/teardown/admin.js: -------------------------------------------------------------------------------- 1 | var cdb = require('cdb'); 2 | var jar = require('../../../lib/jar'); 3 | var dbh = new cdb({jar: jar}); 4 | var mock = require('../mock'); 5 | var admins = cdb.sections.admins; 6 | 7 | var admin = { 8 | rm: function(opts, cb){ 9 | if(typeof opts === 'function') { 10 | cb = opts; 11 | opts = null; 12 | } 13 | opts = opts || {}; 14 | opts.jar = jar; 15 | opts.server = opts.server || mock.server.default; 16 | opts.section = admins; 17 | opts.key = opts.key || mock.admin.name; 18 | opts.value = opts.value || mock.admin.pass; 19 | dbh.config.rm(opts, cb); 20 | } 21 | } 22 | 23 | module.exports = admin; 24 | -------------------------------------------------------------------------------- /test/util/teardown/alias.js: -------------------------------------------------------------------------------- 1 | var mock = require('../mock') 2 | , fs = require('fs'); 3 | 4 | var alias = { 5 | unlink: function(cb) { 6 | fs.unlink(mock.usr.alias, function(err) { 7 | cb(err); 8 | }) 9 | } 10 | } 11 | 12 | module.exports = alias; 13 | -------------------------------------------------------------------------------- /test/util/teardown/db.js: -------------------------------------------------------------------------------- 1 | var cdb = require('cdb'); 2 | var jar = require('../../../lib/jar'); 3 | var dbh = new cdb({jar: jar}); 4 | var mock = require('../mock'); 5 | 6 | var db = { 7 | rm: function(opts, cb){ 8 | if(typeof opts === 'function') { 9 | cb = opts; 10 | opts = null; 11 | } 12 | opts = opts || {}; 13 | opts.server = opts.server || mock.server.default; 14 | opts.db = opts.db || mock.database.default; 15 | dbh.db.rm(opts, cb); 16 | } 17 | } 18 | 19 | module.exports = db; 20 | -------------------------------------------------------------------------------- /test/util/teardown/ddoc.js: -------------------------------------------------------------------------------- 1 | var cdb = require('cdb'); 2 | var jar = require('../../../lib/jar'); 3 | var dbh = new cdb({jar: jar}); 4 | var mock = require('../mock'); 5 | 6 | var ddoc = { 7 | rm: function(opts, cb){ 8 | if(typeof opts === 'function') { 9 | cb = opts; 10 | opts = null; 11 | } 12 | opts = opts || {}; 13 | opts.server = opts.server || mock.server.default; 14 | opts.db = opts.db || mock.database.default; 15 | opts.ddoc = opts.ddoc || mock.app.ddoc; 16 | dbh.design.rm(opts, cb); 17 | } 18 | } 19 | 20 | module.exports = ddoc; 21 | -------------------------------------------------------------------------------- /test/util/teardown/doc.js: -------------------------------------------------------------------------------- 1 | var cdb = require('cdb'); 2 | var jar = require('../../../lib/jar'); 3 | var dbh = new cdb({jar: jar}); 4 | var mock = require('../mock'); 5 | 6 | var doc = { 7 | rm: function(opts, cb){ 8 | if(typeof opts === 'function') { 9 | cb = opts; 10 | opts = null; 11 | } 12 | opts = opts || {}; 13 | opts.server = opts.server || mock.server.default; 14 | opts.db = opts.db || mock.database.default; 15 | opts.id = opts.id || mock.document.id; 16 | dbh.doc.rm(opts, cb); 17 | } 18 | } 19 | 20 | module.exports = doc; 21 | -------------------------------------------------------------------------------- /test/util/teardown/edit.js: -------------------------------------------------------------------------------- 1 | var setup = require('../setup/edit'); 2 | 3 | var edit = { 4 | restore: function(cb){ 5 | process.env.VISUAL = setup.visual; 6 | process.env.EDITOR = setup.editor; 7 | cb(); 8 | } 9 | } 10 | 11 | module.exports = edit; 12 | -------------------------------------------------------------------------------- /test/util/teardown/home.js: -------------------------------------------------------------------------------- 1 | var setup = require('../setup/home'); 2 | 3 | var home = { 4 | restore: function(cb){ 5 | process.env.HOME = setup.HOME; 6 | cb(); 7 | } 8 | } 9 | 10 | module.exports = home; 11 | -------------------------------------------------------------------------------- /test/util/teardown/index.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | admin: require('./admin'), 3 | alias: require('./alias'), 4 | db: require('./db'), 5 | ddoc: require('./ddoc'), 6 | doc: require('./doc'), 7 | edit: require('./edit'), 8 | home: require('./home'), 9 | user: require('./user'), 10 | } 11 | -------------------------------------------------------------------------------- /test/util/teardown/user.js: -------------------------------------------------------------------------------- 1 | var cdb = require('cdb'); 2 | var jar = require('../../../lib/jar'); 3 | var dbh = new cdb({jar: jar}); 4 | var mock = require('../mock'); 5 | 6 | var user = { 7 | rm: function(opts, cb){ 8 | if(typeof opts === 'function') { 9 | cb = opts; 10 | opts = null; 11 | } 12 | opts = opts || {}; 13 | opts.server = opts.server || mock.server.default; 14 | opts.db = opts.db || mock.database.users; 15 | opts.id = opts.id || mock.user.id; 16 | dbh.doc.rm(opts, cb); 17 | } 18 | } 19 | 20 | module.exports = user; 21 | -------------------------------------------------------------------------------- /tmux.conf: -------------------------------------------------------------------------------- 1 | # vim: set ft=conf: 2 | 3 | # kills window when not running with --session 4 | if-shell "test -z '${mxl_session}' && tmux find-window -N ${mxl_key}" \ 5 | "unlink-window -k -t ${mxl_key}" \ 6 | "select-pane"; 7 | 8 | # otherwise when a session is running this will replace 9 | # the first window by killing it 10 | new-window -k -n ${mxl_key} -t:${mxl_session} 11 | send-keys -t: 'vim .' C-m 12 | split-window -h -t: 13 | send-keys -t: 'git status -sb' C-m 14 | split-window -v -t: 15 | send-keys -t: 'couchdb' C-m 16 | split-window -v -t: 17 | send-keys -t: 'npm test' C-m 18 | select-pane -L 19 | --------------------------------------------------------------------------------