Last active
August 29, 2015 14:06
-
-
Save alfonsodev/84b1d768e1d5678e2d19 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| { | |
| "_id": "_design/example", | |
| "views": { | |
| "foo": { | |
| "map": "function(doc){ emit(doc._id, doc._rev)}" | |
| } | |
| }, | |
| "updates": { | |
| "lib": { | |
| "libjsonpatch": "var jsonpatch;(function(e){function i(e,i){var s=false,o=0,u=i.length,a;while(o<u){a=i[o];var f=a.path.split(\"/\");var l=e;var c=1;var h=f.length;while(true){if(r(l)){var p=parseInt(f[c],10);c++;if(c>=h){s=n[a.op].call(a,l,p,e);break}l=l[p]}else{var d=f[c];if(d.indexOf(\"~\")!=-1)d=d.replace(/~1/g,\"/\").replace(/~0/g,\"~\");c++;if(c>=h){s=t[a.op].call(a,l,d,e);break}l=l[d]}}o++}return s}var t={add:function(e,t){e[t]=this.value;return true},remove:function(e,t){delete e[t];return true},replace:function(e,t){e[t]=this.value;return true},move:function(e,t,n){var r={op:\"_get\",path:this.from};i(n,[r]);i(n,[{op:\"remove\",path:this.from}]);i(n,[{op:\"add\",path:this.path,value:r.value}]);return true},copy:function(e,t,n){var r={op:\"_get\",path:this.from};i(n,[r]);i(n,[{op:\"add\",path:this.path,value:r.value}]);return true},test:function(e,t){return JSON.stringify(e[t])===JSON.stringify(this.value)},_get:function(e,t){this.value=e[t]}};var n={add:function(e,t){e.splice(t,0,this.value);return true},remove:function(e,t){e.splice(t,1);return true},replace:function(e,t){e[t]=this.value;return true},move:t.move,copy:t.copy,test:t.test,_get:t._get};var r;if(Array.isArray){r=Array.isArray}else{r=function(e){return e.push&&typeof e.length===\"number\"}}e.apply=i})(jsonpatch||(jsonpatch={}));if(typeof exports!==\"undefined\"){exports.apply=jsonpatch.apply}" | |
| }, | |
| "test": "function(doc,req) {var p = JSON.parse(req.body); require('updates/lib/libjsonpatch').apply( doc, p.patches );return [doc, 'OK! '];}" | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment