-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
WIP - (pouchdb/express-pouchdb#232) - Modernize pouchdb-update
- Loading branch information
1 parent
530f4d2
commit a92a18e
Showing
8 changed files
with
239 additions
and
37 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
node_modules | ||
dist | ||
coverage |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
sudo: false | ||
language: node_js | ||
|
||
cache: | ||
directories: | ||
- node_modules | ||
|
||
node_js: | ||
- "0.10" | ||
|
||
services: | ||
- couchdb | ||
|
||
before_install: | ||
- npm i -g npm@^2.0.0 | ||
|
||
before_script: | ||
- npm prune | ||
|
||
script: npm run $COMMAND | ||
|
||
env: | ||
matrix: | ||
- COMMAND='helper -- lint' | ||
- COMMAND='helper -- js-test' | ||
- COMMAND='build' | ||
|
||
#after_success: | ||
# - npm run helper -- semantic-release | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,43 @@ | ||
pouchdb-update | ||
============== | ||
|
||
[![Build Status](https://travis-ci.org/pouchdb/pouchdb-update.svg?branch=master)](https://travis-ci.org/pouchdb/pouchdb-update) | ||
[![Dependency Status](https://david-dm.org/pouchdb/pouchdb-update.svg)](https://david-dm.org/pouchdb/pouchdb-update) | ||
[![devDependency Status](https://david-dm.org/pouchdb/pouchdb-update/dev-status.svg)](https://david-dm.org/pouchdb/pouchdb-update#info=devDependencies) | ||
|
||
A PouchDB plug-in that allows you to re-use your CouchDB update | ||
functions on the client side. A browser version is available. | ||
|
||
See also [pouchdb-update's documentation](http://pythonhosted.org/Python-PouchDB/js-plugins.html#pouchdb-update-plug-in) | ||
TODO: convert the following to markdown + update + make nicer | ||
```rst | ||
.. _pouchdb-update-plug-in: | ||
PouchDB Update plug-in | ||
====================== | ||
+----------------------+-------------------+ | ||
| NodeJS package name: | `pouchdb-update`_ | | ||
+----------------------+-------------------+ | ||
| Browser object name: | ``window.Update`` | | ||
+----------------------+-------------------+ | ||
First, make sure you understand how update handlers work in CouchDB. A | ||
good start is `the wiki entry on update handlers`_. | ||
.. _pouchdb-update: https://www.npmjs.org/package/pouchdb-update | ||
.. _the wiki entry on update handlers: https://wiki.apache.org/couchdb/Document_Update_Handlers | ||
.. js:function:: Update.update(updatePath[, options[, callback]]) | ||
Runs the update function specified by ``updatePath``, saving part of | ||
its result in the database and returning the other part in the form | ||
of a CouchDB response object. | ||
[Website of this plug-in and a few others](http://python-pouchdb.marten-de-vries.nl/plugins.html) | ||
:param string updatePath: has the following form: | ||
``"designDocName/updateHandlerName[/docId]"``. The last being | ||
optional, like in CouchDB. | ||
:param object options: a request object stub. There's also | ||
``options.withValidation``, if true, this function saves the | ||
update handler result using the | ||
:js:func:`Validation.validatingPut` function instead of using the | ||
:js:func:`PouchDB.prototype.put` function. | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,37 +1,38 @@ | ||
{ | ||
"name": "pouchdb-update", | ||
"version": "1.0.7", | ||
"main": "index.js", | ||
"description": "A PouchDB plug-in that allows you to re-use your CouchDB update functions on the client side.", | ||
"repository": "pouchdb/pouchdb-update", | ||
"homepage": "http://python-pouchdb.marten-de-vries.nl/plugins.html", | ||
"keywords": [ | ||
"pouch", | ||
"pouchdb", | ||
"couch", | ||
"couchdb", | ||
"update", | ||
"design", | ||
"handler" | ||
], | ||
"license": "Apache-2.0", | ||
"author": "Marten de Vries", | ||
"dependencies": { | ||
"couchdb-objects": "^1.0.0", | ||
"couchdb-eval": "^1.0.0", | ||
"promise-nodify": "^1.0.0", | ||
"pouchdb-req-http-query": "^1.0.0", | ||
"couchdb-resp-completer": "^1.0.0", | ||
"pouchdb-promise": "^0.0.0", | ||
"pouchdb-plugin-error": "^1.0.0" | ||
}, | ||
"devDependencies": { | ||
"browserify": "^4.1.8", | ||
"uglify-js": "^2.4.13", | ||
"es3ify": "^0.1.3" | ||
}, | ||
"scripts": { | ||
"build-js": "mkdir -p dist && browserify index.js -s Update -g es3ify -o dist/pouchdb-update.js", | ||
"build": "npm run build-js; cd dist; uglifyjs pouchdb-update.js -mc > pouchdb-update.min.js" | ||
} | ||
"name": "pouchdb-update", | ||
"version": "1.0.7", | ||
"main": "index.js", | ||
"description": "A PouchDB plug-in that allows you to re-use your CouchDB update functions on the client side.", | ||
"repository": { | ||
"type": "git", | ||
"url": "https://github.com/pouchdb/pouchdb-update.git" | ||
}, | ||
"keywords": [ | ||
"pouch", | ||
"pouchdb", | ||
"couch", | ||
"couchdb", | ||
"update", | ||
"design", | ||
"handler" | ||
], | ||
"license": "Apache-2.0", | ||
"author": "Marten de Vries", | ||
"dependencies": { | ||
"couchdb-objects": "^1.0.0", | ||
"couchdb-eval": "^1.0.0", | ||
"promise-nodify": "^1.0.0", | ||
"pouchdb-req-http-query": "^1.0.3", | ||
"couchdb-resp-completer": "^1.0.0", | ||
"pouchdb-promise": "^0.0.0", | ||
"pouchdb-plugin-error": "^1.0.0" | ||
}, | ||
"devDependencies": { | ||
"pouchdb-plugin-helper": "^2.0.0" | ||
}, | ||
"scripts": { | ||
"helper": "./node_modules/.bin/pouchdb-plugin-helper", | ||
"test": "npm run helper -- test", | ||
"build": "npm run helper -- build Update" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
import {setup, setupWithDoc, teardown, updateDocument} from './utils'; | ||
|
||
let db; | ||
|
||
decribe('Sync update tests', () => { | ||
beforeEach(async () => { | ||
db = await setupWithDoc(); | ||
await db.put(updateDocument); | ||
}); | ||
afterEach(teardown); | ||
/* | ||
def testArgs(self): | ||
doc, req = json.loads(self._db.update("test/args/mytest", query={"a": 3}).body) | ||
self.assertTrue(doc["test"]) | ||
self.assertEqual(req["id"], "mytest") | ||
self.assertEqual(req["raw_path"], "/test/_design/test/_update/args/mytest?a=3") | ||
def testArgsWithoutDoc(self): | ||
resp = self._db.update("test/args", withValidation=True) | ||
doc, req = json.loads(resp.body) | ||
self.assertIsNone(doc) | ||
self.assertNotIn("withValidation", req) | ||
def testUnexistingFunction(self): | ||
with self.assertRaises(pouchdb.PouchDBError) as cm: | ||
self._db.update("test/unexisting/mytest") | ||
self.assertTrue(str(cm.exception)) | ||
self.assertEqual(cm.exception["name"], "not_found") | ||
self.assertEqual(cm.exception["message"], "missing update function unexisting on design doc _design/test") | ||
def testSaving(self): | ||
resp = self._db.update("test/save-adding-date", body=json.dumps({ | ||
"_id": "test", | ||
"name": "Today" | ||
})) | ||
self.assertEqual(resp.body, "Hello World!") | ||
doc = self._db.get("test") | ||
self.assertTrue(doc["updated"]) | ||
self.assertEqual(doc["name"], "Today") | ||
*/ | ||
}); | ||
|
||
describe('Async update tests', () => { | ||
beforeEach(done => { | ||
db = setup(); | ||
db.put(updateDocument, done); | ||
}); | ||
afterEach(teardown); | ||
/* | ||
def testException(self): | ||
def cb(err, resp): | ||
self.assertEqual(err["status"], 500) | ||
self.assertEqual(err["name"], "ReferenceError") | ||
self.assertIn("abc", err["message"]) | ||
self._db.update("test/exception", cb) | ||
self.waitUntilCalled(cb) | ||
*/ | ||
}); | ||
|
||
describe('Async update with empty design doc', () => { | ||
beforeEach(done => { | ||
db = setup(); | ||
db.put({_id: '_design/test'}, done); | ||
}); | ||
afterEach(teardown); | ||
|
||
/* | ||
def testBasic(self): | ||
def cb(err, resp): | ||
self.assertEqual(err["status"], 404) | ||
self.assertEqual(err["name"], "not_found") | ||
self.assertEqual(err["message"], "missing update function unexisting on design doc _design/test") | ||
self._db.update("test/unexisting", cb) | ||
self.waitUntilCalled(cb) | ||
*/ | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import {setupHTTP, teardown, updateDocument, should} from './utils'; | ||
|
||
let db; | ||
|
||
describe('http tests', () => { | ||
beforeEach(async () => { | ||
db = setupHTTP(); | ||
await db.put(updateDocument); | ||
}) | ||
afterEach(teardown); | ||
|
||
it('update', async () => { | ||
const [doc, req] = JSON.parse((await db.update('test/args/my-id')).body); | ||
should.not.exist(doc); | ||
req.id.should.equal('my-id'); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import {setup, teardown} from './utils'; | ||
|
||
describe('signature tests', () => { | ||
let db; | ||
beforeEach(() => { | ||
db = setup(); | ||
}); | ||
afterEach(teardown); | ||
|
||
it('update', () => { | ||
const promise = db.update('test/test/test', () => {}); | ||
promise.then.should.be.ok; | ||
promise.catch.should.be.ok; | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import stuff from 'pouchdb-plugin-helper/testutils'; | ||
import Update from '../'; | ||
|
||
stuff.PouchDB.plugin(Update); | ||
|
||
stuff.updateDocument = { | ||
_id: "_design/test", | ||
updates: { | ||
args: `function (doc, req) { | ||
return [null, toJSON([doc, req])]; | ||
}`, | ||
exception: `function (doc, req) { | ||
return abc; | ||
}`, | ||
'save-adding-date': `function (oldDoc, req) { | ||
var doc = JSON.parse(req.body); | ||
doc.updated = new Date(); | ||
return [doc, "Hello World!"]; | ||
}` | ||
} | ||
} | ||
|
||
module.exports = stuff; |