diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..6a5d09a --- /dev/null +++ b/.gitignore @@ -0,0 +1,4 @@ +bower_components +node_modules +deps +font \ No newline at end of file diff --git a/.npmignore b/.npmignore new file mode 100644 index 0000000..e69de29 diff --git a/Gulpfile.js b/Gulpfile.js new file mode 100644 index 0000000..87178a0 --- /dev/null +++ b/Gulpfile.js @@ -0,0 +1,45 @@ +'use strict'; + +var gulp = require('gulp'); +var sourcemaps = require('gulp-sourcemaps'); +var plugins = require('gulp-load-plugins')(); +var gutil = require('gulp-util'); +var shell = require('gulp-shell'); + +var build = { + filename: 'neurosync-pouchdb.js', + minified: 'neurosync-pouchdb.min.js', + output: './build/', + include: [ + './src/neurosync-pouchdb.js' + ] +}; + +var executeMinifiedBuild = function(props) +{ + return function() { + return gulp + .src( props.include ) + .pipe( sourcemaps.init() ) + .pipe( plugins.concat( props.minified ) ) + .pipe( plugins.uglify().on('error', gutil.log) ) + .pipe( sourcemaps.write('.') ) + .pipe( gulp.dest( props.output ) ) + ; + }; +}; + +var executeBuild = function(props) +{ + return function() { + return gulp + .src( props.include ) + .pipe( plugins.concat( props.filename ) ) + .pipe( gulp.dest( props.output ) ) + ; + }; +}; + +gulp.task( 'js:min', executeMinifiedBuild( build ) ); +gulp.task( 'js', executeBuild( build ) ); +gulp.task( 'default', ['js:min', 'js']); diff --git a/README.md b/README.md new file mode 100644 index 0000000..d422596 --- /dev/null +++ b/README.md @@ -0,0 +1,5 @@ +# neurosync-poucbdb + +A neurosync binding to poucbdb - implementing Neuro.rest, Neuro.live, & Neuro.store. + +The easiest way to install is by using bower via `bower install neurosync-poucbdb`. \ No newline at end of file diff --git a/bower.json b/bower.json new file mode 100644 index 0000000..ebb751c --- /dev/null +++ b/bower.json @@ -0,0 +1,29 @@ +{ + "name": "neurosync-pouchdb", + "version": "1.0.0", + "homepage": "https://github.com/ClickerMonkey/neurosync-pouchdb", + "authors": [ + "Philip Diffenderfer " + ], + "description": "A neurosync binding to pouchdb - implementing Neuro.rest, Neuro.live, & Neuro.store", + "main": "build/neurosync-pouchdb.js", + "keywords": [ + "javascript", + "orm", + "offline", + "realtime", + "neurosync", + "pouchdb" + ], + "license": "MIT", + "ignore": [ + "**/.*", + "node_modules", + "bower_components", + "test", + "tests" + ], + "dependencies": { + "pouchdb": "~5.1.0" + } +} diff --git a/build/neurosync-pouchdb.js b/build/neurosync-pouchdb.js new file mode 100644 index 0000000..d029505 --- /dev/null +++ b/build/neurosync-pouchdb.js @@ -0,0 +1,279 @@ +(function(PouchDB, Neuro, global, undefined) +{ + + Neuro.Debugs.POUCH_INIT = 2000; + Neuro.Debugs.POUCH_ALL = 2001; + Neuro.Debugs.POUCH_ALL_ERROR = 2002; + Neuro.Debugs.POUCH_GET = 2003; + Neuro.Debugs.POUCH_GET_ERROR = 2004; + Neuro.Debugs.POUCH_CREATE = 2005; + Neuro.Debugs.POUCH_CREATE_ERROR = 2006; + Neuro.Debugs.POUCH_UPDATE = 2007; + Neuro.Debugs.POUCH_UPDATE_ERROR = 2008; + Neuro.Debugs.POUCH_REMOVE = 2009; + Neuro.Debugs.POUCH_REMOVE_ERROR = 2010; + Neuro.Debugs.POUCH_LIVE_REMOVE = 2011; + Neuro.Debugs.POUCH_LIVE_SAVE = 2012; + Neuro.Debugs.POUCH_LIVE_SAVE_IGNORE = 2013; + + if ( Neuro.debugMap ) + { + Neuro.debugMap[ Neuro.Debugs.POUCH_INIT ] = 'PouchDB Initialized'; + Neuro.debugMap[ Neuro.Debugs.POUCH_ALL ] = 'PouchDB All'; + Neuro.debugMap[ Neuro.Debugs.POUCH_ALL_ERROR ] = 'PouchDB All Error'; + Neuro.debugMap[ Neuro.Debugs.POUCH_GET ] = 'PouchDB Get'; + Neuro.debugMap[ Neuro.Debugs.POUCH_GET_ERROR ] = 'PouchDB Get Error'; + Neuro.debugMap[ Neuro.Debugs.POUCH_CREATE ] = 'PouchDB Create'; + Neuro.debugMap[ Neuro.Debugs.POUCH_CREATE_ERROR ] = 'PouchDB Create Error'; + Neuro.debugMap[ Neuro.Debugs.POUCH_UPDATE ] = 'PouchDB Update'; + Neuro.debugMap[ Neuro.Debugs.POUCH_UPDATE_ERROR ] = 'PouchDB Update Error'; + Neuro.debugMap[ Neuro.Debugs.POUCH_REMOVE ] = 'PouchDB Remove'; + Neuro.debugMap[ Neuro.Debugs.POUCH_REMOVE_ERROR ] = 'PouchDB Remove Error'; + Neuro.debugMap[ Neuro.Debugs.POUCH_LIVE_REMOVE ] = 'PouchDB Live Remove'; + Neuro.debugMap[ Neuro.Debugs.POUCH_LIVE_SAVE ] = 'PouchDB Live Save'; + Neuro.debugMap[ Neuro.Debugs.POUCH_LIVE_SAVE_IGNORE ] = 'PouchDB Live Save Ignored'; + } + + var cache = {}; + + var Neuro_live = Neuro.live; + var Neuro_rest = Neuro.rest; + var Neuro_store = Neuro.store; + + Neuro.pouch = function(name, options) + { + return name in cache ? cache[ name ] : cache[ name ] = new PouchDB( name, options ); + }; + + if ( !Neuro.restSet ) + { + Neuro.rest = function(database) + { + if ( !database.api ) + { + return Neuro_rest.call( this, database ); + } + + database.fullSave = true; + database.cache = Neuro.Cache.None; + database.origin = Neuro.uuid(); + + var pouch = this.pouch( database.name, database.storeOptions ); + + var options = { + include_docs: true + }; + + PouchDB.replicate( database.name, database.api, { + live: true, + retry: true + }); + + Neuro.debug( Neuro.Debugs.POUCH_INIT, database, pouch ); + + return { + + pouchdb: pouch, + + all: function( success, failure ) + { + function onAll(response) + { + Neuro.debug( Neuro.Debugs.POUCH_ALL, database, response ); + + var values = []; + for (var i = 0; i < response.rows.length; i++) + { + values.push( response.rows[ i ].doc ); + } + + success( values ); + } + + function onAllError(err) + { + Neuro.debug( Neuro.Debugs.POUCH_ALL_ERROR, database, err ); + + failure( [], err.status ); + } + + pouch.allDocs( options ).then( onAll ).catch( onAllError ); + }, + + get: function( model, success, failure ) + { + var key = String( model.$key() ); + + function onGet(response) + { + Neuro.debug( Neuro.Debugs.POUCH_GET, database, model, key, response ); + + model._rev = response._rev; + success( response ); + } + + function onGetError(err) + { + Neuro.debug( Neuro.Debugs.POUCH_GET_ERROR, database, model, key, err ); + + failure( null, err.status ); + } + + pouch.get( key ).then( onGet ).catch( onGetError ); + }, + + create: function( model, encoded, success, failure ) + { + encoded._id = String( model.$key() ); + encoded.$origin = database.origin; + + function onCreate(response) + { + Neuro.debug( Neuro.Debugs.POUCH_CREATE, database, model, encoded, response ); + + if ( response.ok ) + { + model._rev = response.rev; + encoded._rev = response.rev; + success( {} ); + } + else + { + failure( null, response.status ); + } + } + + function onCreateError(err) + { + Neuro.debug( Neuro.Debugs.POUCH_CREATE_ERROR, database, model, encoded, err ); + + failure( null, err.status ); + } + + pouch.put( encoded ).then( onCreate ).catch( onCreateError ); + }, + + update: function( model, encoded, success, failure ) + { + encoded._id = String( model.$key() ); + encoded._rev = model._rev; + encoded.$origin = database.origin; + + function onUpdate(response) + { + Neuro.debug( Neuro.Debugs.POUCH_UPDATE, database, model, encoded, response ); + + if ( response.ok ) + { + model._rev = response.rev; + encoded._rev = response.rev; + success( {} ); + } + else + { + failure( null, response.status ); + } + } + + function onUpdateError(err) + { + Neuro.debug( Neuro.Debugs.POUCH_UPDATE_ERROR, database, model, encoded, err ); + + failure( null, err.status ); + } + + pouch.put( encoded ).then( onUpdate ).catch( onUpdateError ); + }, + + remove: function( model, success, failure ) + { + var key = String( model.$key() ); + + function onRemove(response) + { + Neuro.debug( Neuro.Debugs.POUCH_REMOVE, database, model, key, response ); + + if ( response.ok ) + { + success( {} ); + } + else + { + failure( {}, response.status ); + } + } + + function onRemoveError(err) + { + Neuro.debug( Neuro.Debugs.POUCH_REMOVE_ERROR, database, model, key, err ); + + failure( {}, err.status ); + } + + pouch.remove( key ).then( onRemove ).catch( onRemoveError ); + }, + + query: function( query, success, failure ) + { + success( [] ); + } + + }; + }; + + Neuro.restSet = true; + } + + if ( !Neuro.liveSet ) + { + Neuro.live = function(database) + { + if ( !database.api ) + { + return Neuro_live.call( this, database ); + } + + var pouch = this.pouch( database.name ); + var options = + { + since: 'now', + live: true, + include_docs: true + }; + + function onLiveChange(change) + { + if ( change.deleted ) + { + Neuro.debug( Neuro.Debugs.POUCH_LIVE_REMOVE, database, change ); + + database.liveRemove( change.id ); + } + else + { + if ( change.doc.$origin !== database.origin ) + { + Neuro.debug( Neuro.Debugs.POUCH_LIVE_SAVE, database, change ); + + database.liveSave( change.id, change.doc ); + } + else + { + Neuro.debug( Neuro.Debugs.POUCH_LIVE_SAVE_IGNORE, database, change ); + } + } + } + + pouch.changes( options ).on( 'change', onLiveChange ); + + return { + pouchdb: pouch, + save: Neuro.noop, + remove: Neuro.noop + }; + }; + + Neuro.liveSet = true; + } + +})( PouchDB, Neuro, this ); \ No newline at end of file diff --git a/build/neurosync-pouchdb.min.js b/build/neurosync-pouchdb.min.js new file mode 100644 index 0000000..6266ada --- /dev/null +++ b/build/neurosync-pouchdb.min.js @@ -0,0 +1,2 @@ +!function(e,u,t,g){u.Debugs.POUCH_INIT=2e3,u.Debugs.POUCH_ALL=2001,u.Debugs.POUCH_ALL_ERROR=2002,u.Debugs.POUCH_GET=2003,u.Debugs.POUCH_GET_ERROR=2004,u.Debugs.POUCH_CREATE=2005,u.Debugs.POUCH_CREATE_ERROR=2006,u.Debugs.POUCH_UPDATE=2007,u.Debugs.POUCH_UPDATE_ERROR=2008,u.Debugs.POUCH_REMOVE=2009,u.Debugs.POUCH_REMOVE_ERROR=2010,u.Debugs.POUCH_LIVE_REMOVE=2011,u.Debugs.POUCH_LIVE_SAVE=2012,u.Debugs.POUCH_LIVE_SAVE_IGNORE=2013,u.debugMap&&(u.debugMap[u.Debugs.POUCH_INIT]="PouchDB Initialized",u.debugMap[u.Debugs.POUCH_ALL]="PouchDB All",u.debugMap[u.Debugs.POUCH_ALL_ERROR]="PouchDB All Error",u.debugMap[u.Debugs.POUCH_GET]="PouchDB Get",u.debugMap[u.Debugs.POUCH_GET_ERROR]="PouchDB Get Error",u.debugMap[u.Debugs.POUCH_CREATE]="PouchDB Create",u.debugMap[u.Debugs.POUCH_CREATE_ERROR]="PouchDB Create Error",u.debugMap[u.Debugs.POUCH_UPDATE]="PouchDB Update",u.debugMap[u.Debugs.POUCH_UPDATE_ERROR]="PouchDB Update Error",u.debugMap[u.Debugs.POUCH_REMOVE]="PouchDB Remove",u.debugMap[u.Debugs.POUCH_REMOVE_ERROR]="PouchDB Remove Error",u.debugMap[u.Debugs.POUCH_LIVE_REMOVE]="PouchDB Live Remove",u.debugMap[u.Debugs.POUCH_LIVE_SAVE]="PouchDB Live Save",u.debugMap[u.Debugs.POUCH_LIVE_SAVE_IGNORE]="PouchDB Live Save Ignored");var n={},o=u.live,_=u.rest;u.store;u.pouch=function(u,t){return u in n?n[u]:n[u]=new e(u,t)},u.restSet||(u.rest=function(t){if(!t.api)return _.call(this,t);t.fullSave=!0,t.cache=u.Cache.None,t.origin=u.uuid();var g=this.pouch(t.name,t.storeOptions),n={include_docs:!0};return e.replicate(t.name,t.api,{live:!0,retry:!0}),u.debug(u.Debugs.POUCH_INIT,t,g),{pouchdb:g,all:function(e,o){function _(g){u.debug(u.Debugs.POUCH_ALL,t,g);for(var n=[],o=0;o + + + Neurosync Tasks Example + + + + + + +
+ +
+ + +
+ Go Online + Go Offline +
+ + +
+
+ + +
+
+ + + + +
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/examples/tasks/task.html b/examples/tasks/task.html new file mode 100644 index 0000000..ea0732f --- /dev/null +++ b/examples/tasks/task.html @@ -0,0 +1,16 @@ +
+ +
+
+ + + + + {{ model.finished_at | timeAgo }} + + Edit + Remove + +
\ No newline at end of file diff --git a/examples/tasks/taskList.html b/examples/tasks/taskList.html new file mode 100644 index 0000000..b319f25 --- /dev/null +++ b/examples/tasks/taskList.html @@ -0,0 +1,25 @@ +
+ +
+
+
{{ model.name }} + + Edit + Clear + Remove + +
+
+
+
    +
  • +
    + + +
    +
  • +
  • + +
  • +
+
\ No newline at end of file diff --git a/examples/tasks/tasks.css b/examples/tasks/tasks.css new file mode 100644 index 0000000..d6cd038 --- /dev/null +++ b/examples/tasks/tasks.css @@ -0,0 +1,102 @@ + +/* TaskList */ +.task-list { + margin-top: 15px; + margin-bottom: -5px; + padding: 5px 20px; +} +.task-list-name { + font-weight: bold; + font-size: 18px; +} +.task-list-actions { + float: right; + margin-top: -2px; +} +.task-list-actions a { + margin-left: 10px; + color: #666; + font-size: 14px; + text-decoration: none; + display: none; +} +.task-list-actions a:hover { + text-decoration: underline; +} +.task-list:hover { + background-color: #eee; +} +.task-list:hover .task-list-actions a { + display: inline-block; +} + +/* Tasks */ +.tasks .collection .collection-item { + padding: 5px 10px; +} +.tasks .collection .collection-item:hover { + background-color: #eee; +} +.tasks .collection .collection-item:hover .hide-on-hover { + display: none; +} +.tasks .collection .collection-item:hover .task-actions a { + display: inline-block; +} + +/* Task */ +.task { + padding: 3px; +} +.task-name.finished { + text-decoration: line-through; +} +.task-actions { + float: right; + margin-top: 4px; +} +.task-actions span { + color: #999; +} +.task-actions a { + padding-left: 10px; + color: #666; + font-size: 14px; + text-decoration: none; + display: none; +} +.task-actions a:hover { + text-decoration: underline; +} + +/* Animations */ +.animated.ng-enter, +.animated.ng-leave { + -webkit-transition: 400ms cubic-bezier(0.250, 0.250, 0.750, 0.750) all; + -moz-transition: 400ms cubic-bezier(0.250, 0.250, 0.750, 0.750) all; + -ms-transition: 400ms cubic-bezier(0.250, 0.250, 0.750, 0.750) all; + -o-transition: 400ms cubic-bezier(0.250, 0.250, 0.750, 0.750) all; + transition: 400ms cubic-bezier(0.250, 0.250, 0.750, 0.750) all; + position: relative; + display: block; +} + +.animated.ng-leave.ng-leave-active, +.animated.ng-enter { + -webkit-transform: translateX(10%); + -moz-transform: translateX(10%); + -ms-transform: translateX(10%); + -o-transform: translateX(10%); + transform: translateX(10%); + opacity: 0; +} + +.animated.ng-enter.ng-enter-active, +.animated.ng-leave { + -webkit-transform: translateX(0%); + -moz-transform: translateX(0%); + -ms-transform: translateX(0%); + -o-transform: translateX(0%); + transform: translateX(0%); + opacity: 1; +} \ No newline at end of file diff --git a/package.json b/package.json new file mode 100644 index 0000000..0ba6dea --- /dev/null +++ b/package.json @@ -0,0 +1,25 @@ +{ + "name": "neurosync-pouchdb", + "version": "0.2.0", + "description": "A neurosync binding to pouchdb - implementing Neuro.rest, Neuro.live, & Neuro.store", + "author": "Philip Diffenderfer", + "license": "MIT", + "repository": { + "type": "git", + "url": "git://github.com/ClickerMonkey/neurosync-pouchdb.git" + }, + "devDependencies": { + "gulp": "^3.8.10", + "gulp-concat": "^2.4.3", + "gulp-imagemin": "^2.1.0", + "gulp-less": "^2.0.1", + "gulp-load-plugins": "^0.8.0", + "gulp-minify-css": "^0.3.11", + "gulp-sass": "^1.2.4", + "gulp-shell": "^0.2.11", + "gulp-sourcemaps": "^1.3.0", + "gulp-uglify": "^1.0.2", + "gulp-util": "^3.0.4", + "gulp-watch": "^3.0.0" + } +} diff --git a/src/neurosync-pouchdb.js b/src/neurosync-pouchdb.js new file mode 100644 index 0000000..d029505 --- /dev/null +++ b/src/neurosync-pouchdb.js @@ -0,0 +1,279 @@ +(function(PouchDB, Neuro, global, undefined) +{ + + Neuro.Debugs.POUCH_INIT = 2000; + Neuro.Debugs.POUCH_ALL = 2001; + Neuro.Debugs.POUCH_ALL_ERROR = 2002; + Neuro.Debugs.POUCH_GET = 2003; + Neuro.Debugs.POUCH_GET_ERROR = 2004; + Neuro.Debugs.POUCH_CREATE = 2005; + Neuro.Debugs.POUCH_CREATE_ERROR = 2006; + Neuro.Debugs.POUCH_UPDATE = 2007; + Neuro.Debugs.POUCH_UPDATE_ERROR = 2008; + Neuro.Debugs.POUCH_REMOVE = 2009; + Neuro.Debugs.POUCH_REMOVE_ERROR = 2010; + Neuro.Debugs.POUCH_LIVE_REMOVE = 2011; + Neuro.Debugs.POUCH_LIVE_SAVE = 2012; + Neuro.Debugs.POUCH_LIVE_SAVE_IGNORE = 2013; + + if ( Neuro.debugMap ) + { + Neuro.debugMap[ Neuro.Debugs.POUCH_INIT ] = 'PouchDB Initialized'; + Neuro.debugMap[ Neuro.Debugs.POUCH_ALL ] = 'PouchDB All'; + Neuro.debugMap[ Neuro.Debugs.POUCH_ALL_ERROR ] = 'PouchDB All Error'; + Neuro.debugMap[ Neuro.Debugs.POUCH_GET ] = 'PouchDB Get'; + Neuro.debugMap[ Neuro.Debugs.POUCH_GET_ERROR ] = 'PouchDB Get Error'; + Neuro.debugMap[ Neuro.Debugs.POUCH_CREATE ] = 'PouchDB Create'; + Neuro.debugMap[ Neuro.Debugs.POUCH_CREATE_ERROR ] = 'PouchDB Create Error'; + Neuro.debugMap[ Neuro.Debugs.POUCH_UPDATE ] = 'PouchDB Update'; + Neuro.debugMap[ Neuro.Debugs.POUCH_UPDATE_ERROR ] = 'PouchDB Update Error'; + Neuro.debugMap[ Neuro.Debugs.POUCH_REMOVE ] = 'PouchDB Remove'; + Neuro.debugMap[ Neuro.Debugs.POUCH_REMOVE_ERROR ] = 'PouchDB Remove Error'; + Neuro.debugMap[ Neuro.Debugs.POUCH_LIVE_REMOVE ] = 'PouchDB Live Remove'; + Neuro.debugMap[ Neuro.Debugs.POUCH_LIVE_SAVE ] = 'PouchDB Live Save'; + Neuro.debugMap[ Neuro.Debugs.POUCH_LIVE_SAVE_IGNORE ] = 'PouchDB Live Save Ignored'; + } + + var cache = {}; + + var Neuro_live = Neuro.live; + var Neuro_rest = Neuro.rest; + var Neuro_store = Neuro.store; + + Neuro.pouch = function(name, options) + { + return name in cache ? cache[ name ] : cache[ name ] = new PouchDB( name, options ); + }; + + if ( !Neuro.restSet ) + { + Neuro.rest = function(database) + { + if ( !database.api ) + { + return Neuro_rest.call( this, database ); + } + + database.fullSave = true; + database.cache = Neuro.Cache.None; + database.origin = Neuro.uuid(); + + var pouch = this.pouch( database.name, database.storeOptions ); + + var options = { + include_docs: true + }; + + PouchDB.replicate( database.name, database.api, { + live: true, + retry: true + }); + + Neuro.debug( Neuro.Debugs.POUCH_INIT, database, pouch ); + + return { + + pouchdb: pouch, + + all: function( success, failure ) + { + function onAll(response) + { + Neuro.debug( Neuro.Debugs.POUCH_ALL, database, response ); + + var values = []; + for (var i = 0; i < response.rows.length; i++) + { + values.push( response.rows[ i ].doc ); + } + + success( values ); + } + + function onAllError(err) + { + Neuro.debug( Neuro.Debugs.POUCH_ALL_ERROR, database, err ); + + failure( [], err.status ); + } + + pouch.allDocs( options ).then( onAll ).catch( onAllError ); + }, + + get: function( model, success, failure ) + { + var key = String( model.$key() ); + + function onGet(response) + { + Neuro.debug( Neuro.Debugs.POUCH_GET, database, model, key, response ); + + model._rev = response._rev; + success( response ); + } + + function onGetError(err) + { + Neuro.debug( Neuro.Debugs.POUCH_GET_ERROR, database, model, key, err ); + + failure( null, err.status ); + } + + pouch.get( key ).then( onGet ).catch( onGetError ); + }, + + create: function( model, encoded, success, failure ) + { + encoded._id = String( model.$key() ); + encoded.$origin = database.origin; + + function onCreate(response) + { + Neuro.debug( Neuro.Debugs.POUCH_CREATE, database, model, encoded, response ); + + if ( response.ok ) + { + model._rev = response.rev; + encoded._rev = response.rev; + success( {} ); + } + else + { + failure( null, response.status ); + } + } + + function onCreateError(err) + { + Neuro.debug( Neuro.Debugs.POUCH_CREATE_ERROR, database, model, encoded, err ); + + failure( null, err.status ); + } + + pouch.put( encoded ).then( onCreate ).catch( onCreateError ); + }, + + update: function( model, encoded, success, failure ) + { + encoded._id = String( model.$key() ); + encoded._rev = model._rev; + encoded.$origin = database.origin; + + function onUpdate(response) + { + Neuro.debug( Neuro.Debugs.POUCH_UPDATE, database, model, encoded, response ); + + if ( response.ok ) + { + model._rev = response.rev; + encoded._rev = response.rev; + success( {} ); + } + else + { + failure( null, response.status ); + } + } + + function onUpdateError(err) + { + Neuro.debug( Neuro.Debugs.POUCH_UPDATE_ERROR, database, model, encoded, err ); + + failure( null, err.status ); + } + + pouch.put( encoded ).then( onUpdate ).catch( onUpdateError ); + }, + + remove: function( model, success, failure ) + { + var key = String( model.$key() ); + + function onRemove(response) + { + Neuro.debug( Neuro.Debugs.POUCH_REMOVE, database, model, key, response ); + + if ( response.ok ) + { + success( {} ); + } + else + { + failure( {}, response.status ); + } + } + + function onRemoveError(err) + { + Neuro.debug( Neuro.Debugs.POUCH_REMOVE_ERROR, database, model, key, err ); + + failure( {}, err.status ); + } + + pouch.remove( key ).then( onRemove ).catch( onRemoveError ); + }, + + query: function( query, success, failure ) + { + success( [] ); + } + + }; + }; + + Neuro.restSet = true; + } + + if ( !Neuro.liveSet ) + { + Neuro.live = function(database) + { + if ( !database.api ) + { + return Neuro_live.call( this, database ); + } + + var pouch = this.pouch( database.name ); + var options = + { + since: 'now', + live: true, + include_docs: true + }; + + function onLiveChange(change) + { + if ( change.deleted ) + { + Neuro.debug( Neuro.Debugs.POUCH_LIVE_REMOVE, database, change ); + + database.liveRemove( change.id ); + } + else + { + if ( change.doc.$origin !== database.origin ) + { + Neuro.debug( Neuro.Debugs.POUCH_LIVE_SAVE, database, change ); + + database.liveSave( change.id, change.doc ); + } + else + { + Neuro.debug( Neuro.Debugs.POUCH_LIVE_SAVE_IGNORE, database, change ); + } + } + } + + pouch.changes( options ).on( 'change', onLiveChange ); + + return { + pouchdb: pouch, + save: Neuro.noop, + remove: Neuro.noop + }; + }; + + Neuro.liveSet = true; + } + +})( PouchDB, Neuro, this ); \ No newline at end of file