diff --git a/Gruntfile.js b/Gruntfile.js index 29f9d19..3a0a776 100644 --- a/Gruntfile.js +++ b/Gruntfile.js @@ -14,7 +14,7 @@ module.exports = function(grunt) { uglify: { options: { sourceMap: true, - banner: '/* <%= grunt.task.current.target %> v<%= pkg.version %> <%= grunt.template.today("dd-mm-yyyy") %> (C) 2015 Terikon Software */\n' + banner: '/* <%= grunt.task.current.target %> v<%= pkg.version %> <%= grunt.template.today("dd-mm-yyyy") %> (C) 2015 Terikon Apps */\n' }, 'kendo-pouchdb': { src: 'kendo-pouchdb.js', diff --git a/bower.json b/bower.json index 4c923aa..5d5ded7 100644 --- a/bower.json +++ b/bower.json @@ -1,7 +1,7 @@ { "name": "kendo-pouchdb", "main": "kendo-pouchdb.js", - "version": "0.1.4", + "version": "0.1.5", "description": "Kendo UI adapter for PouchDB", "homepage": "https://github.com/terikon/kendo-pouchdb", diff --git a/dist/kendo-pouchdb.amd.min.js b/dist/kendo-pouchdb.amd.min.js index 8fa9ce3..a0dea67 100644 --- a/dist/kendo-pouchdb.amd.min.js +++ b/dist/kendo-pouchdb.amd.min.js @@ -1,2 +1,2 @@ -/* kendo-pouchdb.amd v0.1.4 01-08-2015 (C) 2015 Terikon Software */ +/* kendo-pouchdb.amd v0.1.5 01-08-2015 (C) 2015 Terikon Apps */ define(["kendo","kendo-pouchdb"],function(a){"use strict";return a}); \ No newline at end of file diff --git a/dist/kendo-pouchdb.min.js b/dist/kendo-pouchdb.min.js index 7eca7c7..ba2ebca 100644 --- a/dist/kendo-pouchdb.min.js +++ b/dist/kendo-pouchdb.min.js @@ -1,4 +1,4 @@ -/* kendo-pouchdb v0.1.4 01-08-2015 (C) 2015 Terikon Software */ +/* kendo-pouchdb v0.1.5 01-08-2015 (C) 2015 Terikon Apps */ !function(a,b){b(["PouchDB","pouchCollate"],a)}(function(a,b){if(!a)throw new Error('Please include "pouchdb.js" before kendo-pouchdb');if(!b)throw new Error('Please include "pouchdb-collate.js" before kendo-pouchdb');return function(c){"use strict";var d={MAPREDUCE:"mapreduce",POUCHDBFIND:"pouchdb-find"},e=kendo.data.RemoteTransport.extend({init:function(b){var e=b&&b.pouchdb?b.pouchdb:{},f=e.db,g=e.idField,h=e.queryPlugin||d.MAPREDUCE,i=e.defaultView,j=e.fieldViews;if(!f)throw new Error('The "db" option must be set.');if(!(f instanceof a))throw new Error('The "db" option must be a PouchDB object.');if(!g)throw new Error('The "idField" option must be set.');var k=c.map(d,function(a){return a});if(k.indexOf(h)<0)throw new Error(kendo.format("{0} is not supported as queryPlugin",h));if(h===d.POUCHDBFIND&&i)throw new Error(kendo.format("defaultView cannot be used when queryPlugin is '{0}'",h));if(h===d.POUCHDBFIND&&j)throw new Error(kendo.format("fieldViews cannot be used when queryPlugin is '{0}'",h));this.db=f,this.idField=g,this.queryPlugin=h,this.defaultView=i,this.fieldViews=j||{},this.dataSource=b.data.dataSource,kendo.data.RemoteTransport.fn.init.call(this,b)},push:function(a){var b=this,d=this.db.changes({since:"now",live:!0,include_docs:!0,filter:b.defaultView?"_view":void 0,view:b.defaultView});d.on("change",function(d){var e,f=b._crudPromises.slice(),g=d.doc;c.when.apply(c,f).then(function(){if(d.deleted)a.pushDestroy(g);else if(e=b.dataSource.get(g._id),void 0!==e){if(g._rev===e._rev)return;a.pushUpdate(g)}else b.dataSource.pageSize()||a.pushCreate(g)})}),d.on("error",function(a){})},read:function(b){try{var e,f,g,h,i=this,j=b.data.filter,k=b.data.sort,l=i.queryPlugin===d.MAPREDUCE,m=i.queryPlugin===d.POUCHDBFIND,n=l?i._getFieldViewAndDirForSort(k):void 0,o=m?i._kendoFilterToFindSelector(j,k):void 0,p=m?i._kendoSortToFindSort(k):void 0,q=i._isEmptyFilter(j)||l&&i._isIdRangeFilter(j),r=i._isEmptySort(k)||i._isIdSort(k),s=q&&r&&!i.defaultView&&!o,t=function(){if(l){if(!i.db.query)throw new Error("db.query is needed to use mapreduce method, but it does not exists");return i.db.query.bind(i.db,n.fieldView)}if(m){if(!i.db.find)throw new Error("db.find is needed to use mapreduce method, but it does not exists");return i.db.find}throw new Error(kendo.format("queryPlugin {0} is not supported",i.queryPlugin))},u=s?i.db.allDocs:t(),v=b.data.pageSize,w=b.data.page,x=function(){return!s||e?a.utils.Promise.resolve(0):i.db.allDocs({startkey:"_design/",endkey:"_design￿"}).then(function(a){return a.rows.length})},y=function(a){var b=[];return c.each(a,function(a,c){void 0===c&&b.push(a)}),c.each(b,function(b,c){delete a[c]}),a};i._validateFilter(b.data.filter,b.data.sort),h=s||l?this._getFilterQueryOptions(b.data.filter):void 0,e=!!h,void 0!==v?(void 0===w&&(w=1),g=v*(w-1)):g=void 0,f=void 0!==g||void 0!==v;var z=n?n.descending:void 0,A=s||l?!0:void 0,B=y(c.extend({include_docs:A,descending:z,skip:g,limit:v,selector:o,sort:p},h)),C=function(a,b){if(s&&!e)return a.total_rows-=b,a;if(m)return a.total_rows=0,a;if(l&&!f)return a.total_rows=0,c.each(a.rows,function(){0!==this.doc._id.indexOf("_design/")&&(a.total_rows+=1)}),a;if(l){var d=c.extend({include_docs:!1,reduce:"_count"},h);return u.call(i.db,d).then(function(b){return s?(a.total_rows=b.rows.length,a):(a.total_rows=b.rows.length,a)})}throw new Error(kendo.format("Does not know how to calculate total for queryPlugin '{0}'",i.queryPlugin))};x().then(function(a){return u.call(i.db,B).then(function(b){return C(b,a)})}).then(function(a){b.success(a)})["catch"](function(a){b.error(a,a.status||a.message,a)})}catch(D){b.error(D,D.message,D)}},_crudPromises:[],_crud:function(a,b,d,e){var f=this,g=new c.Deferred,h=g.promise(),i=function(){g.resolve();var a=f._crudPromises.indexOf(h);f._crudPromises.splice(a,1)};this._crudPromises.push(h),e.call(this,b).then(function(a){b._rev=a.rev,d.success(b),i()})["catch"](function(b){409===b.status&&console.log(kendo.format("kendo-pouchdb: conflict occured for {0}: {1}",a,b)),d.error(b,b.status,b),i()})},create:function(a){var c=a.data;"_id"!==this.idField&&(c._id=b.toIndexableString(c[this.idField])),this._crud("create",c,a,function(a){return this.db.put(a)})},update:function(a){var b=a.data;this._crud("update",b,a,function(a){return this.db.put(a)})},destroy:function(a){var b=a.data;this._crud("destroy",b,a,function(a){return this.db.remove(a)})},_isEmptyFilter:function(a){return!a||!a.filters||0===a.filters.length},_isIdRangeFilter:function(a){if(!a||1!==a.filters.length)return!1;var b=a.filters[0].field,c=a.filters[0].operator;return"_id"!==b&&b!==this.idField?!1:["eq","neq","lt","lte","gt","gte"].indexOf(c)>=0},_isEmptySort:function(a){return!a||0===a.length},_isIdSort:function(a){if(!a||1!==a.length)return!1;var b=a[0].field;return"_id"===b||b===this.idField},_getFieldViewAndDirForSort:function(a){var b,c,d,e=this.defaultView;if(this._isEmptySort(a))return{fieldView:e,descending:!1};if(a.length>1)throw new Error("Sorting by multiple fields is not supported with views, use find");if(c=a[0].dir&&"desc"===a[0].dir,this._isIdSort(a))return{fieldView:e,descending:c};if(b=a[0].field,d=this.fieldViews[b],!d)throw new Error("No PouchDB view provided for sorting by '"+b+"'");return{fieldView:d,descending:c}},_validateFilter:function(a,b){if(a&&0!==a.filters.length){var c=a.filters;if(this.queryPlugin===d.MAPREDUCE){if(c.length>1)throw new Error("array of filters is currently not supported");var e=c[0].field,f=b&&b.length>0?b[0].field:this.idField;if(f!=e)throw new Error("filtering by field and then sorting by another field is not supported")}else this.queryPlugin===d.POUCHDBFIND}},_getFilterQueryOptions:function(a){if(this._isEmptyFilter(a))return void 0;if(1!==a.filters.length)throw new Error("_getFilterQueryOptions currently supports only one filter");var c=a.filters[0].field,d=a.filters[0].operator,e=c===this.idField||"_id"===c?b.toIndexableString(a.filters[0].value):a.filters[0].value;if(["neq","gt"].indexOf(d)>=0)throw new Error(kendo.format("{0} operator is currently not supported for field '{1}'",d,c));switch(d){case"eq":return{key:e};case"lt":return{endkey:e,inclusive_end:!1};case"lte":return{endkey:e,inclusive_end:!0};case"gte":return{startkey:e}}return void 0},_fieldToFindField:function(a){return a===this.idField?"_id":a},_valueToIndexable:function(a,c){return"_id"!==a&&a===this.idField?b.toIndexableString(c):c},_kendoFilterToFindSelector:function(a,b){var d=this;return this._isEmptyFilter(a)&&b&&b.length>0?{$and:c.map(b,function(a){var b=d._fieldToFindField(a.field),c={};return c[b]={$exists:!0},c})}:this._kendoFilterToFindSelectorInternal(a,b)},_kendoFilterToFindSelectorInternal:function(a,b){a=a||{};var d=this,e={},f=a.logic||"and",g=a.filters||[],h="and"===f?"$and":"$or",i=[],j=function(a){switch(a){case"eq":return"$eq";case"neq":return"$ne";case"lt":return"$lt";case"lte":return"$lte";case"gt":return"$gt";case"gte":return"$gte";default:throw new Error(kendo.format("Operator {0} is not supported by kendo-pouchdb",a))}};return c.each(g,function(a,c){var e,f,g,h=d._fieldToFindField(c.field),k=d._valueToIndexable(c.field,c.value);c.filters?f=d._kendoFilterToFindSelector(c,b):(f={},e=j(c.operator),g={},g[e]=k,f[h]=g),i.push(f)}),0===i.length?void 0:(e[h]=i,e)},_kendoSortToFindSort:function(a){var b=this;return this._isEmptySort(a)?void 0:c.map(a,function(a){var c={};return c[b._fieldToFindField(a.field)]="desc"===a.dir?"desc":"asc",c})}}),f={type:"json",data:function(a){if(a.rows){var b=c.map(a.rows,function(a){return 0!==a.doc._id.indexOf("_design/")?a.doc:void 0});return b}return a.docs?a.docs:a},total:function(a){return a.total_rows}};c.extend(!0,kendo.data,{schemas:{pouchdb:f},transports:{pouchdb:e}});var g=kendo.data.DataSource.extend({init:function(a){var b=a;if(b&&b.type&&"pouchdb"===b.type){var d;if(b=c.extend(!0,{},b),this._ispouchdb=!0,b.schema&&b.schema.model&&b.schema.model.fn&&b.schema.model.fn instanceof kendo.data.Model){if(d=b.schema.model,"_id"!==d.idField)throw new Error('The Model\'s id option should be "_id"')}else if(b=c.extend(!0,{schema:{model:{id:"_id"}}},b),"_id"!==b.schema.model.id)throw new Error('The model.id option should not be provided or should be "_id"');if(b.serverPaging=void 0===b.serverPaging?!0:b.serverPaging,b.serverFiltering=void 0===b.serverFiltering?!0:b.serverFiltering,b.serverSorting=void 0===b.serverSorting?!0:b.serverSorting,b.serverGrouping=void 0===b.serverGrouping?!0:b.serverGrouping,b.serverAggregates=void 0===b.serverAggregates?!0:b.serverAggregates,b.data)throw new Error("For DataSource of type pouchdb data option should not be provided");b.data={dataSource:this}}var e=Array.prototype.slice.call(arguments,1);e.unshift(b),kendo.data.DataSource.fn.init.apply(this,e)},getByModelId:function(a){return this._ispouchdb?kendo.data.DataSource.fn.get.call(this,b.toIndexableString(a)):kendo.data.DataSource.fn.get.apply(this,arguments)}});g.create=kendo.data.DataSource.create,kendo.data.PouchableDataSource=g}(window.kendo.jQuery),window.kendo},"function"==typeof define&&define.amd?define:function(a,b){b(window.PouchDB,window.pouchCollate)}); //# sourceMappingURL=kendo-pouchdb.min.js.map \ No newline at end of file diff --git a/package.json b/package.json index ad65d99..eb227ad 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "kendo-pouchdb", "title": "kendoPouchDB", - "version": "0.1.4", + "version": "0.1.5", "description": "Kendo UI adapter for PouchDB", "main": "kendo-pouchdb.js", "scripts": {