Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

js-data

Package Overview
Dependencies
Maintainers
1
Versions
144
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

js-data - npm Package Compare versions

Comparing version 3.0.0-alpha.21 to 3.0.0-alpha.22

9

CHANGELOG.md

@@ -0,1 +1,10 @@

##### 3.0.0-alpha.22 - 31 March 2016
###### Backwards compatible API changes
- Containers and DataStores now bubble up Mapper events
- DataStores now bubble up Collection events
###### Other
- Switched from mocha/istanbul to ava/nyc for parallel tests
##### 3.0.0-alpha.21 - 22 March 2016

@@ -2,0 +11,0 @@

6

dist/js-data.min.js
/*!
* js-data
* @version 3.0.0-alpha.21 - Homepage <http://www.js-data.io/>
* @version 3.0.0-alpha.22 - Homepage <http://www.js-data.io/>
* @author js-data project authors

@@ -10,4 +10,4 @@ * @copyright (c) 2014-2016 js-data project authors

*/
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define("js-data",["exports"],t):t(e.JSData=e.JSData||{})}(this,function(e){"use strict";function t(){this._listeners={}}function n(e,t,n){return e===t?0:(n&&(e=n(e),t=n(t)),null===e&&null===t?0:null===e?-1:null===t?1:t>e?-1:e>t?1:0)}function r(e,t,n){return e.splice(t,0,n),e}function i(e,t){return e.splice(t,1),e}function o(e,t,r){for(var i=0,o=e.length,a=void 0,u=void 0;o>i;){if(u=(i+o)/2|0,a=n(t,e[u],r),0===a)return{found:!0,index:u};0>a?o=u:i=u+1}return{found:!1,index:o}}function a(e,t){if(C.classCallCheck(this,a),e||(e=[]),!C.isArray(e))throw new Error("fieldList must be an array.");t||(t={}),this.fieldList=e,this.fieldGetter=t.fieldGetter,this.hashCode=t.hashCode,this.isIndex=!0,this.keys=[],this.values=[]}function u(e,t){var n=this;t||(t={});var r=t.localField;if(!r)throw new Error("localField is required");var i=t.foreignKey=t.foreignKey||t.localKey;if(!i&&(t.type===L||t.type===K))throw new Error("foreignKey is required");var o=t.localKeys,a=t.foreignKeys;if(!i&&!o&&!a&&t.type===M)throw new Error("one of (foreignKey, localKeys, foreignKeys) is required");if(C.isString(e)){if(t.relation=e,!C.isFunction(t.getRelation))throw new Error("you must provide a reference to the related mapper!")}else e&&(t.relation=e.name,Object.defineProperty(n,"relatedMapper",{value:e}));C.fillIn(n,t)}var s={};s.typeof="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol?"symbol":typeof e},s.defineProperty=function(e,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e},s.toConsumableArray=function(e){if(Array.isArray(e)){for(var t=0,n=Array(e.length);t<e.length;t++)n[t]=e[t];return n}return Array.from(e)};var c=1/0,f=1.7976931348623157e308,l="[object Boolean]",d="[object Date]",p="[object Function]",h="[object Number]",v="[object Object]",g="[object RegExp]",y="[object String]",m=Object.prototype.toString,b=/^(.+)\.(.+)$/,w=function(e){if(!e)return 0;if(e=+e,e===c||e===-c){var t=0>e?-1:1;return t*f}var n=e%1;return e===e?n?e-n:e:0},A=function(e){return m.call(e)},_=function(e){return!!e&&"object"===("undefined"==typeof e?"undefined":s.typeof(e))&&e.constructor===Object},O=function(e,t){if(!t)return e;var n=t.split(".");return n.forEach(function(t){e[t]||(e[t]={}),e=e[t]}),e},x={Promise:Promise,_:function(e,t){for(var n in e){var r=e[n];void 0===t[n]&&!x.isFunction(r)&&n&&0!==n.indexOf("_")&&(t[n]=r)}},_forRelation:function(e,t,n,r){var i=t.relation,o=null,a=void 0;if(e||(e={}),e.with||(e.with=[]),(a=x._getIndex(e.with,i))>=0?o=i:(a=x._getIndex(e.with,t.localField))>=0&&(o=t.localField),e.withAll)return void n.call(r,t,{});if(o){var u={};x.fillIn(u,t.getRelation()),x.fillIn(u,e),u.with=e.with.slice(),u._activeWith=u.with.splice(a,1)[0],u.with.forEach(function(e,t){e&&0===e.indexOf(o)&&e.length>=o.length&&"."===e[o.length]?u.with[t]=e.substr(o.length+1):u.with[t]=""}),n.call(r,t,u)}},_getIndex:function(e,t){var n=-1;return e.forEach(function(e,r){return e===t?(n=r,!1):x.isObject(e)&&e.relation===t?(n=r,!1):void 0}),n},addHiddenPropsToTarget:function(e,t){var n={};x.forOwn(t,function(e,t){n[t]={writable:!0,value:e}}),Object.defineProperties(e,n)},areDifferent:function(e,t,n){n||(n={});var r=x.diffObjects(e,t,n),i=Object.keys(r.added).length+Object.keys(r.removed).length+Object.keys(r.changed).length;return i>0},classCallCheck:function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")},copy:function(e,t,n,r,i,o){if(t){if(e===t)throw new Error("Cannot copy! Source and destination are identical.");if(n=n||[],r=r||[],x.isObject(e)){var a=n.indexOf(e);if(-1!==a)return r[a];n.push(e),r.push(t)}var u=void 0;if(x.isArray(e)){var s=void 0;for(t.length=0,s=0;s<e.length;s++)u=x.copy(e[s],null,n,r,i,o),x.isObject(e[s])&&(n.push(e[s]),r.push(u)),t.push(u)}else{x.isArray(t)?t.length=0:x.forOwn(t,function(e,n){delete t[n]});for(var c in e)if(e.hasOwnProperty(c)){if(x.isBlacklisted(c,i))continue;u=x.copy(e[c],null,n,r,i,o),x.isObject(e[c])&&(n.push(e[c]),r.push(u)),t[c]=u}}}else t=e,e&&(x.isArray(e)?t=x.copy(e,[],n,r,i,o):x.isDate(e)?t=new Date(e.getTime()):x.isRegExp(e)?(t=new RegExp(e.source,e.toString().match(/[^\/]*$/)[0]),t.lastIndex=e.lastIndex):x.isObject(e)&&(t=o?x.copy(e,{},n,r,i,o):x.copy(e,Object.create(Object.getPrototypeOf(e)),n,r,i,o)));return t},deepFillIn:function(e,t){return t&&x.forOwn(t,function(t,n){var r=e[n];_(t)&&_(r)?x.deepFillIn(r,t):e.hasOwnProperty(n)&&void 0!==e[n]||(e[n]=t)}),e},deepMixIn:function(e,t){return t&&x.forOwn(t,function(t,n){var r=e[n];_(t)&&_(r)?x.deepMixIn(r,t):e[n]=t}),e},diffObjects:function(e,t,n){n||(n={});var r=n.equalsFn,i=n.ignore,o={added:{},changed:{},removed:{}};return x.isFunction(r)||(r=x.strictEqual),x.forOwn(t,function(t,n){var a=e[n];x.isBlacklisted(n,i)||r(a,t)||(x.isUndefined(a)?o.removed[n]=void 0:r(a,t)||(o.changed[n]=a))}),x.forOwn(e,function(e,n){x.isUndefined(t[n])&&!x.isBlacklisted(n,i)&&(o.added[n]=e)}),o},equal:function(e,t){return e==t},eventify:function(e,t,n,r){e=e||this;var i={};t||n||(t=function(){return i},n=function(e){i=e}),Object.defineProperties(e,{emit:{enumerable:!!r,value:function(){for(var e=t.call(this)||{},n=arguments.length,r=Array(n),i=0;n>i;i++)r[i]=arguments[i];var o=r.shift(),a=e[o]||[],u=void 0;for(u=0;u<a.length;u++)a[u].f.apply(a[u].c,r);for(a=e.all||[],r.unshift(o),u=0;u<a.length;u++)a[u].f.apply(a[u].c,r)}},off:{enumerable:!!r,value:function(e,r){var i=t.call(this),o=i[e];if(o)if(r){for(var a=0;a<o.length;a++)if(o[a].f===r){o.splice(a,1);break}}else o.splice(0,o.length);else n.call(this,{})}},on:{enumerable:!!r,value:function(e,r,i){t.call(this)||n.call(this,{});var o=t.call(this);o[e]=o[e]||[],o[e].push({c:i,f:r})}}})},extend:function(e,t){var n=this,r=void 0;e||(e={}),t||(t={}),e.hasOwnProperty("constructor")?(r=e.constructor,delete e.constructor):r=function(){x.classCallCheck(this,r);for(var e=arguments.length,t=Array(e),n=0;e>n;n++)t[n]=arguments[n];var i=x.possibleConstructorReturn(this,(r.__super__||Object.getPrototypeOf(r)).apply(this,t));return i},r.prototype=Object.create(n&&n.prototype,{constructor:{configurable:!0,enumerable:!1,value:r,writable:!0}});var i=Object;return i.setPrototypeOf?i.setPrototypeOf(r,n):t.strictEs6Class?r.__proto__=n:x.forOwn(n,function(e,t){r[t]=e}),Object.defineProperty(r,"__super__",{configurable:!0,value:n}),x.addHiddenPropsToTarget(r.prototype,e),x.fillIn(r,t),r},fillIn:function(e,t){x.forOwn(t,function(t,n){e.hasOwnProperty(n)&&void 0!==e[n]||(e[n]=t)})},forEachRelation:function(e,t,n,r){var i=e.relationList||[];i.length&&i.forEach(function(e){x._forRelation(t,e,n,r)})},forOwn:function(e,t,n){var r=Object.keys(e),i=r.length,o=void 0;for(o=0;i>o;o++)t.call(n,e[r[o]],r[o],e)},fromJson:function(e){return x.isString(e)?JSON.parse(e):e},get:function(e,t){if(t){for(var n=t.split("."),r=n.pop();t=n.shift();)if(e=e[t],null==e)return;return e[r]}},getSuper:function(e,t){var n=t?e:e.constructor;return n.__super__||Object.getPrototypeOf(n)||n.__proto__},intersection:function(e,t){if(!e||!t)return[];var n=[],r=void 0,i=void 0,o=e.length;for(i=0;o>i;i++)r=e[i],-1===n.indexOf(r)&&-1!==t.indexOf(r)&&n.push(r);return n},isArray:Array.isArray,isBlacklisted:function(e,t){if(!t||!t.length)return!1;for(var n=void 0,r=0;r<t.length;r++)if(A(t[r])===g&&t[r].test(e)||t[r]===e)return n=e;return!!n},isBoolean:function(e){return A(e)===l},isBrowser:!1,isDate:function(e){return e&&"object"===("undefined"==typeof e?"undefined":s.typeof(e))&&A(e)===d},isFunction:function(e){return"function"==typeof e||e&&A(e)===p},isInteger:function(e){return A(e)===h&&e==w(e)},isNull:function(e){return null===e},isNumber:function(e){var t="undefined"==typeof e?"undefined":s.typeof(e);return"number"===t||e&&"object"===t&&A(e)===h},isObject:function(e){return A(e)===v},isRegExp:function(e){return A(e)===g},isSorN:function(e){return x.isString(e)||x.isNumber(e)},isString:function(e){return"string"==typeof e||e&&"object"===("undefined"==typeof e?"undefined":s.typeof(e))&&A(e)===y},isUndefined:function(e){return void 0===e},logify:function(e){x.addHiddenPropsToTarget(e,{dbg:function(){for(var e=arguments.length,t=Array(e),n=0;e>n;n++)t[n]=arguments[n];this.log.apply(this,["debug"].concat(t))},log:function(e){for(var t=arguments.length,n=Array(t>1?t-1:0),r=1;t>r;r++)n[r-1]=arguments[r];if(e&&!n.length&&(n.push(e),e="debug"),"debug"!==e||this.debug){var i=e.toUpperCase()+": ("+(this.name||this.constructor.name)+")";if(console[e]){var o;(o=console)[e].apply(o,[i].concat(n))}else{var a;(a=console).log.apply(a,[i].concat(n))}}}})},omit:function(e,t){var n={};return x.forOwn(e,function(e,r){-1===t.indexOf(r)&&(n[r]=e)}),n},plainCopy:function(e){return x.copy(e,void 0,void 0,void 0,void 0,!0)},possibleConstructorReturn:function(e,t){if(!e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return!t||"object"!==("undefined"==typeof t?"undefined":s.typeof(t))&&"function"!=typeof t?e:t},reject:function(e){return x.Promise.reject(e)},resolve:function(e){return x.Promise.resolve(e)},set:function(e,t,n){if(x.isObject(t))x.forOwn(t,function(t,n){x.set(e,n,t)});else{var r=b.exec(t);r?O(e,r[1])[r[2]]=n:e[t]=n}},strictEqual:function(e,t){var n=e===t;return n||(x.isObject(e)&&x.isObject(t)?(x.forOwn(e,function(e,r){n=n&&x.strictEqual(e,t[r])}),x.forOwn(t,function(t,r){n=n&&x.strictEqual(t,e[r])})):x.isArray(e)&&x.isArray(t)&&e.forEach(function(e,r){n=n&&x.strictEqual(e,t[r])})),n},toJson:JSON.stringify,unset:function(e,t){for(var n=t.split("."),r=n.pop();t=n.shift();)if(e=e[t],null==e)return;e[r]=void 0}};try{x.isBrowser=!!window}catch(e){x.isBrowser=!1}var C=x;t.extend=C.extend,C.logify(t.prototype),C.eventify(t.prototype,function(){return this._listeners},function(e){this._listeners=e});var E={limit:"",offset:"",orderBy:"",skip:"",sort:"",where:""},R=/([.*+?^=!:${}()|[\]\/\\])/g,j=/%/g,I=/_/g,F=function(e){return e.replace(R,"\\$1")},S=t.extend({constructor:function e(t){C.classCallCheck(this,e),this.collection=t,this.data=null},between:function(e,t,n){var r=this;if(n||(n={}),r.data)throw new Error("Cannot access index after first operation!");return r.data=r.collection.getIndex(n.index).between(e,t,n),r},compare:function(e,t,n,r){var i=e[t],o=C.get(n,i[0]),a=C.get(r,i[0]);return o&&C.isString(o)&&(o=o.toUpperCase()),a&&C.isString(a)&&(a=a.toUpperCase()),void 0===n&&(n=null),void 0===r&&(r=null),"DESC"===i[1]?o>a?-1:a>o?1:t<e.length-1?this.compare(e,t+1,n,r):0:a>o?-1:o>a?1:t<e.length-1?this.compare(e,t+1,n,r):0},evaluate:function(e,t,n){var r=this.constructor.ops;return r[t]?r[t](e,n):0===t.indexOf("like")?!C.isNull(this.like(n,t.substr(4)).exec(e)):0===t.indexOf("notLike")?C.isNull(this.like(n,t.substr(7)).exec(e)):void 0},filter:function(e,t){var n=this;return e||(e={}),n.getData(),C.isObject(e)?!function(){var t={};C.isObject(e.where)&&(t=e.where),C.forOwn(e,function(e,n){n in E||n in t||(t[n]={"==":e})});var r=[],i=[],o=[];C.forOwn(t,function(e,t){C.isObject(e)||(e={"==":e}),C.forOwn(e,function(e,n){r.push(t),i.push(n),o.push(e)})}),r.length&&!function(){var e=void 0,t=r.length;n.data=n.data.filter(function(a){var u=!0,s=!0;for(e=0;t>e;e++){var c=i[e],f="|"===c.charAt(0);c=f?c.substr(1):c;var l=n.evaluate(C.get(a,r[e]),c,o[e]);void 0!==l&&(s=u?l:f?s||l:s&&l),u=!1}return s})}();var a=e.orderBy||e.sort;C.isString(a)&&(a=[[a,"ASC"]]),C.isArray(a)||(a=null),a&&!function(){var e=0;a.forEach(function(e,t){C.isString(e)&&(a[t]=[e,"ASC"])}),n.data.sort(function(t,r){return n.compare(a,e,t,r)})}(),C.isNumber(e.skip)?n.skip(e.skip):C.isNumber(e.offset)&&n.skip(e.offset),C.isNumber(e.limit)&&n.limit(e.limit)}():C.isFunction(e)&&(n.data=n.data.filter(e,t)),n},forEach:function(e,t){return this.getData().forEach(e,t),this},get:function(e,t){var n=this;if(e||(e=[]),t||(t={}),n.data)throw new Error("Cannot access index after first operation!");return e&&!C.isArray(e)&&(e=[e]),e.length?(n.data=n.collection.getIndex(t.index).get(e),n):(n.getData(),n)},getAll:function(){var e=this,t={};if(e.data)throw new Error("Cannot access index after first operation!");for(var n=arguments.length,r=Array(n),i=0;n>i;i++)r[i]=arguments[i];if(!r.length||1===r.length&&C.isObject(r[0]))return e.getData(),e;r.length&&C.isObject(r[r.length-1])&&(t=r[r.length-1],r.pop());var o=e.collection,a=o.getIndex(t.index);return e.data=[],r.forEach(function(t){e.data=e.data.concat(a.get(t))}),e},getData:function(){var e=this;return e.data||(e.data=e.collection.index.getAll()),e.data},like:function(e,t){return new RegExp("^"+F(e).replace(j,".*").replace(I,".")+"$",t)},limit:function(e){if(!C.isNumber(e))throw new TypeError("limit: Expected number but found "+("undefined"==typeof e?"undefined":s.typeof(e))+"!");var t=this.getData();return this.data=t.slice(0,Math.min(t.length,e)),this},map:function(e,t){return this.data=this.getData().map(e,t),this},mapCall:function(e){for(var t=arguments.length,n=Array(t>1?t-1:0),r=1;t>r;r++)n[r-1]=arguments[r];return this.data=this.getData().map(function(t){return t[e].apply(t,n)}),this},run:function(){var e=this.data;return this.data=null,e},skip:function(e){if(!C.isNumber(e))throw new TypeError("skip: Expected number but found "+("undefined"==typeof e?"undefined":s.typeof(e))+"!");var t=this.getData();return e<t.length?this.data=t.slice(e):this.data=[],this}},{ops:{"==":function(e,t){return e==t},"===":function(e,t){return e===t},"!=":function(e,t){return e!=t},"!==":function(e,t){return e!==t},">":function(e,t){return e>t},">=":function(e,t){return e>=t},"<":function(e,t){return t>e},"<=":function(e,t){return t>=e},isectEmpty:function(e,t){return!C.intersection(e||[],t||[]).length},isectNotEmpty:function(e,t){return C.intersection(e||[],t||[]).length},in:function(e,t){return-1!==t.indexOf(e)},notIn:function(e,t){return-1===t.indexOf(e)},contains:function(e,t){return-1!==(e||[]).indexOf(t)},notContains:function(e,t){return-1===(e||[]).indexOf(t)}}});C.addHiddenPropsToTarget(a.prototype,{set:function(e,t){C.isArray(e)||(e=[e]);var n=e.shift()||null,i=o(this.keys,n);if(0===e.length)if(i.found){var u=o(this.values[i.index],t,this.hashCode);u.found||r(this.values[i.index],u.index,t)}else r(this.keys,i.index,n),r(this.values,i.index,[t]);else if(i.found)this.values[i.index].set(e,t);else{r(this.keys,i.index,n);var s=new a([],{hashCode:this.hashCode});s.set(e,t),r(this.values,i.index,s)}},get:function(e){C.isArray(e)||(e=[e]);var t=e.shift()||null,n=o(this.keys,t);return 0===e.length?n.found?this.values[n.index].isIndex?this.values[n.index].getAll():this.values[n.index]:[]:n.found?this.values[n.index].get(e):[]},getAll:function(){var e=[];return this.values.forEach(function(t){e=t.isIndex?e.concat(t.getAll()):e.concat(t)}),e},visitAll:function(e,t){this.values.forEach(function(n){n.isIndex?n.visitAll(e,t):n.forEach(e,t)})},between:function(e,t,n){n||(n={}),C.isArray(e)||(e=[e]),C.isArray(t)||(t=[t]),C.fillIn(n,{leftInclusive:!0,rightInclusive:!1,limit:void 0,offset:0});var r=this._between(e,t,n);return n.limit?r.slice(n.offset,n.limit+n.offset):r.slice(n.offset)},_between:function(e,t,n){var r=[],i=e.shift(),a=t.shift(),u=void 0;if(u=void 0!==i?o(this.keys,i):{found:!1,index:0},0===e.length){u.found&&n.leftInclusive===!1&&(u.index+=1);for(var s=u.index;s<this.keys.length;s+=1){if(void 0!==a)if(n.rightInclusive){if(this.keys[s]>a)break}else if(this.keys[s]>=a)break;if(r=this.values[s].isIndex?r.concat(this.values[s].getAll()):r.concat(this.values[s]),n.limit&&r.length>=n.limit+n.offset)break}}else for(var c=u.index;c<this.keys.length;c+=1){var f=this.keys[c];if(f>a)break;if(r=this.values[c].isIndex?f===i?r.concat(this.values[c]._between(C.copy(e),t.map(function(){}),n)):f===a?r.concat(this.values[c]._between(e.map(function(){}),C.copy(t),n)):r.concat(this.values[c].getAll()):r.concat(this.values[c]),n.limit&&r.length>=n.limit+n.offset)break}return n.limit?r.slice(0,n.limit+n.offset):r},peek:function(){return this.values.length?this.values[0].isIndex?this.values[0].peek():this.values[0]:[]},clear:function(){this.keys=[],this.values=[]},insertRecord:function(e){var t=this.fieldList.map(function(t){return C.isFunction(t)?t(e)||null:e[t]||null});this.set(t,e)},removeRecord:function(e){var t=this,n=void 0;return this.values.forEach(function(r,a){if(r.isIndex){if(r.removeRecord(e))return 0===r.keys.length&&(i(t.keys,a),i(t.values,a)),n=!0,!1}else{var u=o(r,e,t.hashCode);if(u.found)return i(r,u.index),0===r.length&&(i(t.keys,a),i(t.values,a)),n=!0,!1}}),n?e:void 0},updateRecord:function(e){this.removeRecord(e),this.insertRecord(e)}});var k={idAttribute:"id",mapper:null,onConflict:"merge",recordOpts:null},P=t.extend({constructor:function e(t,n){var r=this;C.classCallCheck(r,e),e.__super__.call(r),C.isObject(t)&&!C.isArray(t)&&(n=t,t=[]),C.isString(n)&&(n={idAttribute:n}),t||(t=[]),n||(n={}),n.recordOpts||(n.recordOpts={}),C.fillIn(r,n),C.fillIn(r,k);var i=r.recordId();r.index=new a([i],{hashCode:function(e){return C.get(e,i)}}),r.indexes={},t.forEach(function(e){e=r.mapper?r.mapper.createRecord(e,r.recordOpts):e,r.index.insertRecord(e),e&&C.isFunction(e.on)&&e.on("all",r._onRecordEvent,r)})},_onRecordEvent:function(){this.emit.apply(this,arguments)},add:function(e,t){var n=this;t||(t={}),C._(n,t),e=n.beforeAdd(e,t)||e;var r=!1,i=n.recordId();C.isObject(e)&&!C.isArray(e)&&(e=[e],r=!0),e=e.map(function(e){var r=n.recordId(e);if(!C.isSorN(r))throw new TypeError("Collection#add: Expected string or number for "+i+", found "+("undefined"==typeof r?"undefined":s.typeof(r))+"!");var o=n.get(r);if(e===o)return o;if(o){var a=t.onConflict||n.onConflict;"merge"===a?C.deepMixIn(o,e):"replace"===a&&(C.forOwn(o,function(t,n){n===i||e.hasOwnProperty(n)||delete o[n]}),o.set(e)),e=o,n.updateIndexes(e)}else e=n.mapper?n.mapper.createRecord(e,n.recordOpts):e,n.index.insertRecord(e),C.forOwn(n.indexes,function(t,n){t.insertRecord(e)}),e&&C.isFunction(e.on)&&e.on("all",n._onRecordEvent,n);return e});var o=r?e.length?e[0]:void 0:e;return n.emit("add",o),n.afterAdd(e,t,o)||o},afterAdd:function(){},afterRemove:function(){},afterRemoveAll:function(){},beforeAdd:function(){},beforeRemove:function(){},beforeRemoveAll:function(){},between:function(e,t,n){return this.query().between(e,t,n).run()},createIndex:function(e,t,n){var r=this;C.isString(e)&&void 0===t&&(t=[e]),n||(n={}),n.hashCode=n.hashCode||function(e){return r.recordId(e)};var i=r.indexes[e]=new a(t,n);return r.index.visitAll(i.insertRecord,i),r},filter:function(e,t){return this.query().filter(e,t).run()},forEach:function(e,t){this.index.visitAll(e,t)},get:function(e){var t=this.query().get(e).run();return t.length?t[0]:void 0},getAll:function(){var e;return(e=this.query()).getAll.apply(e,arguments).run()},getIndex:function(e){var t=e?this.indexes[e]:this.index;if(!t)throw new Error("Index "+e+" does not exist!");return t},limit:function(e){return this.query().limit(e).run()},map:function(e,t){var n=[];return this.index.visitAll(function(r){n.push(e.call(t,r))}),n},mapCall:function(e){for(var t=arguments.length,n=Array(t>1?t-1:0),r=1;t>r;r++)n[r-1]=arguments[r];var i=[];return this.index.visitAll(function(t){i.push(t[e].apply(t,n))}),i},recordId:function(e){if(e)return C.get(e,this.recordId());var t=this;return t.mapper?t.mapper.idAttribute:t.idAttribute||"id"},query:function(){return new S(this)},reduce:function(e,t){var n=this.getAll();return n.reduce(e,t)},remove:function(e,t){var n=this;t||(t={}),n.beforeRemove(e,t);var r=n.get(e);return r&&(n.index.removeRecord(r),C.forOwn(n.indexes,function(e,t){e.removeRecord(r)}),r&&C.isFunction(r.off)&&(r.off("all",n._onRecordEvent,n),n.emit("remove",r))),n.afterRemove(e,t,r)||r},removeAll:function(e,t){var n=this;t||(t={}),n.beforeRemoveAll(e,t);var r=n.filter(e);return r.forEach(function(e){n.remove(n.recordId(e),t)}),n.afterRemoveAll(e,t,r)||r},skip:function(e){return this.query().skip(e).run()},toJSON:function(e){return this.mapCall("toJSON",e)},updateIndex:function(e,t){t||(t={}),this.getIndex(t.index).updateRecord(e)},updateIndexes:function(e){var t=this;t.index.updateRecord(e),C.forOwn(t.indexes,function(t,n){t.updateRecord(e)})}}),L="belongsTo",M="hasMany",K="hasOne";C.addHiddenPropsToTarget(u.prototype,{getRelation:function(){return this.relatedMapper},getLocalKeys:function(e){},getForeignKey:function(e){return this.type===L?C.get(e,this.foreignKey):C.get(e,this.mapper.idAttribute)},setForeignKey:function(e,t){var n=this;e&&t&&(n.type===L?C.set(e,n.foreignKey,C.get(t,n.getRelation().idAttribute)):!function(){var r=n.mapper.idAttribute;C.isArray(t)?t.forEach(function(t){C.set(t,n.foreignKey,C.get(e,r))}):C.set(t,n.foreignKey,C.get(e,r))}())},getLocalField:function(e){return C.get(e,this.localField)},setLocalField:function(e,t){return C.set(e,this.localField,t)}});var N=function(e,t,n){if(n||(n={}),!n.type)throw new Error("must specify relation type!");n.mapper=e,n.name=e.name;var r=new u(t,n);e.relationList||Object.defineProperty(e,"relationList",{value:[]}),e.relationFields||Object.defineProperty(e,"relationFields",{value:[]}),e.relationList.push(r),e.relationFields.push(r.localField)},U=function(e,t){return t||(t={}),t.type=L,function(n){N(n,e,t)}},T=function(e,t){return t||(t={}),t.type=M,function(n){N(n,e,t)}},D=function(e,t){return t||(t={}),t.type=K,function(n){N(n,e,t)}},q=t.extend({constructor:function e(t,n){var r=this;C.classCallCheck(r,e),t||(t={}),n||(n={});var i={};Object.defineProperties(r,{_get:{enumerable:!1,value:function(e){return C.get(i,e)}},_set:{enumerable:!1,value:function(e,t){return C.set(i,e,t)}},_unset:{enumerable:!1,value:function(e){return C.unset(i,e)}}});var o=r._set;o("creating",!0),n.noValidate&&o("noValidate",!0),C.fillIn(r,t),o("creating",!1),o("noValidate",!1),o("previous",C.copy(t))},_mapper:function(){if(!this.constructor.mapper)throw new Error("This recordClass has no Mapper!");return this.constructor.mapper},afterLoadRelations:function(){},afterSave:function(){},beforeLoadRelations:function(){},beforeSave:function(){},changes:function(e){var t=this;return e||(e={}),C.diffObjects(t,t._get("previous"),e)},commit:function(){var e=this;return e._set("changed"),e._set("previous",C.copy(e)),e},create:function(e){return this._mapper().create(this,e)},destroy:function(e){var t=this._mapper();return t.destroy(C.get(this,t.idAttribute),e)},get:function(e){return C.get(this,e)},hasChanges:function(e){var t=this,n=!!(t._get("changed")||[]).length;return n||C.areDifferent(t,t._get("previous"),e)},hashCode:function(){var e=this;return C.get(e,e._mapper().idAttribute)},isValid:function(e){var t=this;return!!t._mapper().validate(t,e)},loadRelations:function(e,t){var n=void 0,r=this,i=r._mapper(),o=i.relationList||[];return e||(e=[]),t||(t={}),C._(i,t),t.adapter=i.getAdapterName(t),n=t.op="beforeLoadRelations",C.resolve(r[n](e,t)).then(function(){return C.isString(e)&&(e=[e]),n=t.op="loadRelations",i.dbg(n,r,e,t),Promise.all(o.map(function(e){if(C.isFunction(e.load))return e.load(i,e,r,t);var n=void 0;if("hasMany"===e.type&&e.foreignKey)n=e.getRelation().findAll(s.defineProperty({},e.foreignKey,C.get(r,i.idAttribute)),t);else if(e.foreignKey){var o=C.get(r,e.foreignKey);C.isSorN(o)&&(n=e.getRelation().find(o,t))}else e.localKeys?n=e.getRelation().findAll(s.defineProperty({},e.getRelation().idAttribute,{in:C.get(r,e.localKeys)}),t):e.foreignKeys&&(n=e.getRelation().findAll(s.defineProperty({},e.getRelation().idAttribute,{contains:C.get(r,i.idAttribute)}),t));return n&&(n=n.then(function(n){t.raw&&(n=n.data),C.set(r,e.localField,"hasOne"===e.type?n.length?n[0]:void 0:n)})),n}))}).then(function(){return n=t.op="afterLoadRelations",C.resolve(r[n](e,t)).then(function(){return r})})},previous:function(e){var t=this;return e?t._get("previous."+e):t._get("previous")},revert:function(e){var t=this,n=t._get("previous")||{};return e||(e={}),e.preserve||(e.preserve=[]),C.forOwn(t,function(r,i){i!==t._mapper().idAttribute&&!n.hasOwnProperty(i)&&t.hasOwnProperty(i)&&-1===e.preserve.indexOf(i)&&delete t[i]}),C.forOwn(n,function(n,r){-1===e.preserve.indexOf(r)&&(t[r]=n)}),t.commit(),t},save:function(e){var t=this,n=t._mapper();return n.update(C.get(t,n.idAttribute),t,e)},set:function(e,t,n){var r=this;C.isObject(e)&&(n=t),n||(n={}),n.silent&&r._set("silent",!0),C.set(r,e,t),r._get("eventId")||r._set("silent")},toJSON:function(e){var t=this,n=this.constructor.mapper;if(n)return n.toJSON(this,e);var r=function(){var e={};return C.forOwn(t,function(t,n){e[n]=C.copy(t)}),{v:e}}();return"object"===("undefined"==typeof r?"undefined":s.typeof(r))?r.v:void 0},unset:function(e,t){this.set(e,void 0,t)},validate:function(e){return this._mapper().validate(this,e)}});C.eventify(q.prototype,function(){return this._get("events")},function(e){this._set("events",e)});var Q={array:C.isArray,boolean:C.isBoolean,integer:C.isInteger,null:C.isNull,number:C.isNumber,object:C.isObject,string:C.isString},J=function(e,t){var n="";return e&&(n+=C.isNumber(e)?"["+e+"]":t?"."+e:""+e),n},B=function(e){e||(e={});var t="",n=e.path||[];return n.forEach(function(e){t+=J(e,t)}),t+=J(e.prop,t)},$=function(e,t,n){return{expected:t,actual:""+e,path:B(n)}},V=function(e,t,n,r){r.push($(e,t,n))},H=function(e,t,n,r){var i=n[e];return t.length>i?$(t.length,"length no more than "+i,r):void 0},G=function(e,t,n,r){var i=n[e];return t.length<i?$(t.length,"length no less than "+i,r):void 0},W={allOf:function(e,t,n){var r=[];return t.allOf.forEach(function(t){r=r.concat(ie(e,t,n)||[])}),r.length?void 0:r},anyOf:function(e,t,n){var r=!1,i=[];return t.anyOf.forEach(function(t){var o=ie(e,t,n);o?i=i.concat(o):r=!0}),r?void 0:i},dependencies:function(e,t,n){},enum:function(e,t,n){var r=t.enum;return-1===r.indexOf(e)?$(e,"one of ("+r.join(", ")+")",n):void 0},items:function e(t,n,r){r||(r={});for(var e=n.items,i=[],o=C.isArray(e),a=t.length,u=0;a>u;u++)o&&(e=n.items[u]),r.prop=u,i=i.concat(ie(t[u],e,r)||[]);return i.length?i:void 0},maximum:function e(t,n,r){var e=n.maximum,i=n.exclusiveMaximum;return("undefined"==typeof t?"undefined":s.typeof(t))===("undefined"==typeof e?"undefined":s.typeof(e))&&(i?t>e:t>=e)?$(t,"no more than "+e,r):void 0},maxItems:function(e,t,n){return H("maxItems",e,t,n)},maxLength:function(e,t,n){return H("maxLength",e,t,n)},maxProperties:function e(t,n,r){var e=n.maxProperties,i=Object.keys(t).length;return i>e?$(i,"no more than "+e+" properties",r):void 0},minimum:function e(t,n,r){var e=n.minimum,i=n.exclusiveMinimum;return("undefined"==typeof t?"undefined":s.typeof(t))===("undefined"==typeof e?"undefined":s.typeof(e))&&(i?e>t:e>=t)?$(t,"no less than "+e,r):void 0},minItems:function(e,t,n){return G("minItems",e,t,n)},minLength:function(e,t,n){return G("minLength",e,t,n)},minProperties:function e(t,n,r){var e=n.minProperties,i=Object.keys(t).length;return e>i?$(i,"no more than "+e+" properties",r):void 0},multipleOf:function(e,t,n){},not:function(e,t,n){return ie(e,t.not,n)?void 0:$("succeeded","should have failed",n)},oneOf:function(e,t,n){var r=!1,i=[];return t.oneOf.forEach(function(t){var o=ie(e,t,n);if(o)i=i.concat(o);else{if(r)return i=[$("valid against more than one","valid against only one",n)],r=!1,!1;r=!0}}),r?void 0:i},pattern:function e(t,n,r){var e=n.pattern;return C.isString(t)&&!t.match(e)?$(t,e,r):void 0},properties:function e(t,n,r){r||(r={});var i=C.isUndefined(n.additionalProperties)?!0:n.additionalProperties,o={},e=n.properties||{},a=n.patternProperties||{},u=[];C.forOwn(t,function(e,t){o[t]=void 0}),C.forOwn(e||{},function(e,n){C.isUndefined(t[n])&&!C.isUndefined(e.default)&&(t[n]=C.copy(e.default)),r.prop=n,u=u.concat(ie(t[n],e,r)||[]),delete o[n]}),C.forOwn(a,function(e,n){C.forOwn(o,function(i,a){a.match(n)&&(r.prop=a,u=u.concat(ie(t[a],e,r)||[]),delete o[a])})});var s=Object.keys(o);return i===!1?s.length&&V("extra fields: "+s.join(", "),"no extra fields",r,u):C.isObject(i)&&s.forEach(function(e){r.prop=e,u=u.concat(ie(t[e],i,r)||[])}),u.length?u:void 0},required:function e(t,n,r){var e=n.required,i=[];return r.existingOnly||e.forEach(function(e){if(C.isUndefined(C.get(t,e))){var n=r.prop;r.prop=e,V(void 0,"a value",r,i),r.prop=n}}),i.length?i:void 0},type:function e(t,n,r){var e=n.type,i=void 0;if(C.isString(e)&&(e=[e]),e.forEach(function(e){return Q[e](t,n,r)?(i=e,!1):void 0}),!i)return $(t?"undefined"==typeof t?"undefined":s.typeof(t):""+t,"one of ("+e.join(", ")+")",r);var o=pe[i];return o?o(t,n,r):void 0},uniqueItems:function(e,t,n){if(e&&e.length&&t.uniqueItems){var r=e.length,i=void 0,o=void 0,a=void 0;for(o=r-1;o>0;o--)for(i=e[o],a=o-1;a>=0;a--)if(i===e[a])return $(i,"no duplicates",n)}}},z=function(e,t,n,r){return!C.isUndefined(n[e])&&W[e](t,n,r)},X=function(e,t,n,r){var i=[];return e.forEach(function(e){i=i.concat(z(e,t,n,r)||[])}),i.length?i:void 0},Y=["enum","type","allOf","anyOf","oneOf","not"],Z=["items","maxItems","minItems","uniqueItems"],ee=["multipleOf","maximum","minimum"],te=["maxProperties","minProperties","required","properties","dependencies"],ne=["maxLength","minLength","pattern"],re=function(e,t,n){return X(Y,e,t,n)},ie=function e(t,n,r){var i=[];r||(r={});var o=void 0,a=r.prop;if(!C.isUndefined(n)){if(!C.isObject(n))throw new Error('Invalid schema at path: "'+r.path+'"');return C.isUndefined(r.path)&&(r.path=[]),C.isUndefined(r.prop)||(o=!0,r.path.push(r.prop),r.prop=void 0),n.extends&&(i=C.isFunction(n.extends.validate)?i.concat(n.extends.validate(t,r)||[]):i.concat(e(t,n.extends,r)||[])),C.isUndefined(t)?(n.required===!0&&V(t,"a value",r,i),o&&(r.path.pop(),r.prop=a),i.length?i:void 0):(i=i.concat(re(t,n,r)||[]),o&&(r.path.pop(),r.prop=a),i.length?i:void 0)}},oe="changing",ae="changed",ue="creating",se="eventId",ce="noValidate",fe="silent",le="validation failed",de=function(e,t,n){var r={enumerable:C.isUndefined(t.enumerable)?!0:!!t.enumerable},i="props."+e,o="previous."+e,a=n.getter,u=n.setter,s=n.unsetter;return r.get=function(){return this._get(i)},r.set=function(n){var r=this,c=r[a],f=r[u],l=r[s];if(!c(ce)){var d=t.validate(n);if(d){var p=new Error(le);throw p.errors=d,p}}return t.track&&!c(ue)&&!function(){var t=c(o),a=c(i),u=c(oe),s=c(ae);u||(s=[]);var d=s.indexOf(e);a!==n&&-1===d&&s.push(e),t===n&&d>=0&&s.splice(d,1),s.length||(u=!1,l(oe),l(ae),c(se)&&(clearTimeout(c(se)),l(se))),!u&&s.length&&(f(ae,s),f(oe,!0),f(se,setTimeout(function(){if(l(ae),l(se),l(oe),!c(fe)){var e=void 0;for(e=0;e<s.length;e++)r.emit("change:"+s[e],r,C.get(r,s[e]));r.emit("change",r,r.changes())}l(fe)},0)))}(),f(i,n),n},r},pe={array:function(e,t,n){return X(Z,e,t,n)},integer:function(e,t,n){return pe.numeric(e,t,n)},number:function(e,t,n){return pe.numeric(e,t,n)},numeric:function(e,t,n){return X(ee,e,t,n)},object:function(e,t,n){return X(te,e,t,n)},string:function(e,t,n){return X(ne,e,t,n)}},he=t.extend({constructor:function e(t){t||(t={}),C.fillIn(this,t),t.properties&&C.forOwn(t.properties,function(n,r){n instanceof e||(t.properties[r]=new e(n))})},apply:function(e,t){t||(t={}),t.getter=t.getter||"_get",t.setter=t.setter||"_set",t.unsetter=t.unsetter||"_unset";var n=this.properties||{};C.forOwn(n,function(n,r){Object.defineProperty(e,r,de(r,n,t))})},validate:function(e,t){return ie(e,this,t)}},{typeGroupValidators:pe,types:Q,validate:ie,validationKeywords:W}),ve=function(){for(var e=arguments.length,t=Array(e),n=0;e>n;n++)t[n]=arguments[n];var r=this,i=t[t.length-1];r.dbg.apply(r,[i.op].concat(t)),(i.notify||void 0===i.notify&&r.notify)&&setTimeout(function(){r.emit.apply(r,[i.op].concat(t))})},ge=function(){for(var e=arguments.length,t=Array(e),n=0;e>n;n++)t[n]=arguments[n];var r=this,i=t[t.length-2];r.dbg.apply(r,[i.op].concat(t)),(i.notify||void 0===i.notify&&r.notify)&&setTimeout(function(){r.emit.apply(r,[i.op].concat(t))})},ye={applySchema:!0,debug:!1,defaultAdapter:"http",idAttribute:"id",lifecycleMethods:{count:{defaults:[{},{}],skip:!0,types:[]},destroy:{defaults:[{},{}],skip:!0,types:[]},destroyAll:{defaults:[{},{}],skip:!0,types:[]
},find:{defaults:[void 0,{}],types:[]},findAll:{defaults:[{},{}],types:[]},sum:{defaults:[void 0,{},{}],skip:!0,types:[]},update:{adapterArgs:function(e,t,n,r){return[t,e.toJSON(n,r),r]},beforeAssign:1,defaults:[void 0,{},{}],types:[]},updateAll:{adapterArgs:function(e,t,n,r){return[e.toJSON(t,r),n,r]},beforeAssign:0,defaults:[{},{},{}],types:[]},updateMany:{adapterArgs:function(e,t,n){return[t.map(function(t){return e.toJSON(t,n)}),n]},beforeAssign:0,defaults:[[],{}],types:[]}},name:null,notify:C.isBrowser,raw:!1,schema:null},me=t.extend({constructor:function e(t){var n=this;if(C.classCallCheck(n,e),e.__super__.call(n),t||(t={}),Object.defineProperty(n,"_adapters",{value:void 0,writable:!0}),Object.defineProperty(n,"_listeners",{value:{},writable:!0}),Object.defineProperty(n,"recordClass",{value:void 0,writable:!0}),C.fillIn(n,t),C.fillIn(n,C.copy(ye)),!n.name)throw new Error("mapper cannot function without a name!");n._adapters||(n._adapters={}),n.schema instanceof he||(n.schema=new he(n.schema||{})),C.isUndefined(n.recordClass)&&(n.recordClass=q.extend()),n.recordClass&&(n.recordClass.mapper=n,C.getSuper(n.recordClass,!0)===q&&n.schema&&n.schema.apply&&n.applySchema&&n.schema.apply(n.recordClass.prototype))},afterCount:ge,afterCreate:ge,afterCreateMany:ge,afterDestroy:ge,afterDestroyAll:ge,afterFind:ge,afterFindAll:ge,afterSum:ge,afterUpdate:ge,afterUpdateAll:ge,afterUpdateMany:ge,beforeCreate:ve,beforeCreateMany:ve,beforeCount:ve,beforeDestroy:ve,beforeDestroyAll:ve,beforeFind:ve,beforeFindAll:ve,beforeSum:ve,beforeUpdate:ve,beforeUpdateAll:ve,beforeUpdateMany:ve,_end:function(e,t,n){var r=this;if(t.raw&&C._(t,e),n)return e;var i=t.raw?e.data:e;return C.isArray(i)&&i.length&&C.isObject(i[0])?i=i.map(function(e){return r.createRecord(e)}):C.isObject(i)&&(i=r.createRecord(i)),t.raw?e.data=i:e=i,e},belongsTo:function(e,t){return U(e,t)(this)},count:function(e,t){return this.crud("count",e,t)},create:function(e,t){var n=void 0,r=void 0,i=this;return e||(e={}),t||(t={}),C._(i,t),r=t.adapter=i.getAdapterName(t),n=t.op="beforeCreate",C.resolve(i[n](e,t)).then(function(o){e=C.isUndefined(o)?e:o;var a={};t.with||(t.with=[]);var u=[];return C.forEachRelation(i,t,function(t,n){var r=t.getLocalField(e);t.type===L&&r&&u.push(t.getRelation().create(r,n).then(function(r){var i=n.raw?r.data:r;t.setLocalField(a,i),t.setForeignKey(e,i)}))}),C.Promise.all(u).then(function(){return n=t.op="create",i.dbg(n,e,t),C.resolve(i.getAdapter(r)[n](i,i.toJSON(e,{with:t.pass||[]}),t))}).then(function(n){var r=t.raw?n.data:n;return u=[],C.forEachRelation(i,t,function(n,i){var o=n.getLocalField(e);if(o){var s=void 0;n.type===M?(n.setForeignKey(r,o),s=n.getRelation().createMany(o,i).then(function(e){n.setLocalField(r,t.raw?e.data:e)})):n.type===K?(n.setForeignKey(r,o),s=n.getRelation().create(o,i).then(function(e){n.setLocalField(r,t.raw?e.data:e)})):n.type===L&&n.getLocalField(a)&&n.setLocalField(r,n.getLocalField(a)),s&&u.push(s)}}),C.Promise.all(u).then(function(){return n})})}).then(function(r){return r=i._end(r,t),n=t.op="afterCreate",C.resolve(i[n](e,t,r)).then(function(e){return C.isUndefined(e)?r:e})})},createInstance:function(e,t){return this.createRecord(e,t)},createMany:function(e,t){var n=void 0,r=void 0,i=this;return e||(e=[]),t||(t={}),C._(i,t),r=t.adapter=i.getAdapterName(t),n=t.op="beforeCreateMany",C.resolve(i[n](e,t)).then(function(o){e=C.isUndefined(o)?e:o;var a={};t.with||(t.with=[]);var u=[];return C.forEachRelation(i,t,function(t,n){var r=e.map(function(e){return t.getLocalField(e)}).filter(function(e){return e});t.type===L&&r.length===e.length&&u.push(t.getRelation().createMany(r,n).then(function(r){var i=n.raw?r.data:r;t.setLocalField(a,i),e.forEach(function(e,n){t.setForeignKey(e,i[n])})}))}),C.Promise.all(u).then(function(){n=t.op="createMany";var o=e.map(function(e){return i.toJSON(e,{with:t.pass||[]})});return i.dbg(n,e,t),C.resolve(i.getAdapter(r)[n](i,o,t))}).then(function(n){var r=t.raw?n.data:n;return u=[],C.forEachRelation(i,t,function(n,o){var s=e.map(function(e){return n.getLocalField(e)}).filter(function(e){return e});if(s.length===e.length){var c=n.getLocalField(a),f=void 0;n.type===M?i.log("warn","deep createMany of hasMany type not supported!"):n.type===K?(r.forEach(function(e,t){n.setForeignKey(e,s[t])}),f=n.getRelation().createMany(s,o).then(function(e){var i=t.raw?e.data:e;r.forEach(function(e,t){n.setLocalField(e,i[t])})})):n.type===L&&c&&c.length===r.length&&r.forEach(function(e,t){n.setLocalField(e,c[t])}),f&&u.push(f)}}),C.Promise.all(u).then(function(){return n})})}).then(function(r){return r=i._end(r,t),n=t.op="afterCreateMany",C.resolve(i[n](e,t,r)).then(function(e){return C.isUndefined(e)?r:e})})},createRecord:function(e,t){var n=this,r=n.recordClass,i=n.relationList||[];return i.forEach(function(t){var n=t.getRelation(),r=t.getLocalField(e);C.isArray(r)&&r.length&&!n.is(r[0])?t.setLocalField(e,r.map(function(e){return t.getRelation().createRecord(e)})):C.isObject(r)&&!n.is(r)&&t.setLocalField(e,t.getRelation().createRecord(r))}),r?e instanceof r?e:new r(e,t):e},crud:function(e){for(var t=arguments.length,n=Array(t>1?t-1:0),r=1;t>r;r++)n[r-1]=arguments[r];var i=this,o=i.lifecycleMethods[e];if(!o)throw new Error(e+": No such CRUD method!");var a=""+e.charAt(0).toUpperCase()+e.substr(1),u="before"+a,c="after"+a,f=void 0,l=void 0;o.defaults.forEach(function(e,t){C.isUndefined(n[t])&&(n[t]=C.copy(e))});var d=n[n.length-1];return C._(i,d),l=d.adapter=i.getAdapterName(d),f=d.op=u,C.resolve(i[f].apply(i,s.toConsumableArray(n))).then(function(t){var r;return C.isUndefined(o.beforeAssign)||(n[o.beforeAssign]=C.isUndefined(t)?n[o.beforeAssign]:t),f=d.op=e,n=o.adapterArgs?o.adapterArgs.apply(o,[i].concat(s.toConsumableArray(n))):n,i.dbg.apply(i,[f].concat(s.toConsumableArray(n))),C.resolve((r=i.getAdapter(l))[f].apply(r,[i].concat(s.toConsumableArray(n))))}).then(function(e){return e=i._end(e,d,!!o.skip),n.push(e),f=d.op=c,C.resolve(i[f].apply(i,s.toConsumableArray(n))).then(function(t){return C.isUndefined(t)?e:t})})},destroy:function(e,t){return this.crud("destroy",e,t)},destroyAll:function(e,t){return this.crud("destroyAll",e,t)},find:function(e,t){return this.crud("find",e,t)},findAll:function(e,t){return this.crud("findAll",e,t)},getAdapter:function(e){var t=this;t.dbg("getAdapter","name:",e);var n=t.getAdapterName(e);if(!n)throw new ReferenceError(n+" not found!");return t.getAdapters()[n]},getAdapterName:function(e){return e||(e={}),C.isString(e)&&(e={adapter:e}),e.adapter||e.defaultAdapter},getAdapters:function(){return this._adapters},getSchema:function(){return this.schema},hasMany:function(e,t){return T(e,t)(this)},hasOne:function(e,t){return D(e,t)(this)},is:function(e){var t=this.recordClass;return t?e instanceof t:!1},registerAdapter:function(e,t,n){var r=this;n||(n={}),r.getAdapters()[e]=t,(n===!0||n.default)&&(r.defaultAdapter=e)},sum:function(e,t,n){return this.crud("sum",e,t,n)},toJSON:function(e,t){var n=this;t||(t={});var r=(n?n.relationFields:[])||[],i={},o=void 0;return n&&n.schema&&(o=n.schema.properties||{},C.forOwn(o,function(t,n){i[n]=C.plainCopy(e[n])})),o||(o={}),t.strict||C.forOwn(e,function(e,t){o[t]||-1!==r.indexOf(t)||(i[t]=C.plainCopy(e))}),n&&t.withAll&&(t.with=r.slice()),n&&t.with&&(C.isString(t.with)&&(t.with=[t.with]),C.forEachRelation(n,t,function(t,n){var r=t.getLocalField(e);r&&(C.isArray(r)?t.setLocalField(i,r.map(function(e){return t.getRelation().toJSON(e,n)})):t.setLocalField(i,t.getRelation().toJSON(r,n)))})),i},update:function(e,t,n){return this.crud("update",e,t,n)},updateAll:function(e,t,n){return this.crud("updateAll",e,t,n)},updateMany:function(e,t){return this.crud("updateMany",e,t)},validate:function(e,t){var n=this;if(!n.getSchema())throw new Error("no schema!");if(C.isArray(e))return e.map(function(e){return n.schema.validate(e,t)});if(C.isObject(e))return n.schema.validate(e,t);throw new Error("not a record!")}}),be=["count","create","createMany","createRecord","dbg","destroy","destroyAll","emit","find","findAll","getSchema","is","log","off","on","sum","toJSON","update","updateAll","updateMany"],we={constructor:function e(t){var n=this;C.classCallCheck(n,e),e.__super__.call(n),t||(t={}),C.fillIn(n,t),n.mapperDefaults=n.mapperDefaults||{},n.mapperClass=n.mapperClass||me,n._adapters={},n._mappers={}},defineMapper:function(e,t){var n=this;if(C.isObject(e)){if(t=e,!t.name)throw new Error("name is required!");e=t.name}else if(!C.isString(e))throw new Error("name is required!");t||(t={}),t.name=e,t.relations||(t.relations={});var r=t.mapperClass||n.mapperClass;delete t.mapperClass,C.fillIn(t,n.mapperDefaults);var i=n._mappers[e]=new r(t);return i.name=e,i._adapters=n.getAdapters(),C.forOwn(i.relations,function(e,t){C.forOwn(e,function(e,r){C.isObject(e)&&(e=[e]),e.forEach(function(e){e.getRelation=function(){return n.getMapper(r)};var o=n._mappers[r]||r;t===L?i.belongsTo(o,e):t===K?i.hasOne(o,e):t===M&&i.hasMany(o,e)})})}),i},defineResource:function(e,t){return this.defineMapper(e,t)},getAdapter:function(e){var t=this,n=t.getAdapterName(e);if(!n)throw new ReferenceError(n+" not found!");return t.getAdapters()[n]},getAdapterName:function(e){return e||(e={}),C.isString(e)&&(e={adapter:e}),e.adapter||this.mapperDefaults.defaultAdapter},getAdapters:function(){return this._adapters},getMapper:function(e){var t=this._mappers[e];if(!t)throw new ReferenceError(e+" is not a registered mapper!");return t},registerAdapter:function(e,t,n){var r=this;n||(n={}),r.getAdapters()[e]=t,(n===!0||n.default)&&(r.mapperDefaults.defaultAdapter=e,C.forOwn(r._mappers,function(t){t.defaultAdapter=e}))}};be.forEach(function(e){we[e]=function(t){for(var n,r=arguments.length,i=Array(r>1?r-1:0),o=1;r>o;o++)i[o-1]=arguments[o];return(n=this.getMapper(t))[e].apply(n,i)}});var Ae=t.extend(we),_e=P.extend({constructor:function e(t,n){var r=this;if(C.classCallCheck(r,e),e.__super__.call(r,t,n),r._added={},!r.datastore)throw new Error("This collection must have a datastore!");return r},_onRecordEvent:function(){for(var e=this,t=arguments.length,n=Array(t),r=0;t>r;r++)n[r]=arguments[r];C.getSuper(e).prototype._onRecordEvent.apply(e,n);var i=n[0];C.isString(i)&&0===i.indexOf("change")&&e.updateIndexes(n[1])},add:function(e,t){var n=this,r=n.datastore,i=n.mapper,o=i.relationList||[],a=(new Date).getTime(),u=!!i.recordClass,s=void 0;return C.isObject(e)&&!C.isArray(e)&&(s=!0,e=[e]),o.length&&e.length&&i.relationList.forEach(function(t){var n=t.relation,i=r.getMapper(n),o=i.idAttribute,a=t.foreignKey,u=r.getCollection(n),s=t.type,c=s===M,f=C.isUndefined(t.add)?!0:!!t.add,l=void 0;e.forEach(function(e){if(l=t.getLocalField(e),C.isFunction(t.add))t.add(r,t,e);else if(l){if(c)l=l.map(function(n){return n!==u.get(u.recordId(n))&&(a&&t.setForeignKey(e,n),f&&(n=u.add(n))),n}),t.localKeys&&C.set(e,t.localKeys,l.map(function(e){return C.get(e,o)}));else{var n=C.get(l,o);l!==u.get(n)&&(t.setForeignKey(e,l),f&&(l=u.add(l)))}t.setLocalField(e,l)}})}),e=C.getSuper(n).prototype.add.call(n,e,t),e.forEach(function(e){n._added[n.recordId(e)]=a,u&&e._set("$",a)}),s?e[0]:e},remove:function(e,t){var n=this,r=n.mapper,i=C.getSuper(n).prototype.remove.call(n,e,t);return i&&(delete n._added[e],r.recordClass&&i._set("$")),i},removeAll:function(e,t){var n=this,r=n.mapper,i=C.getSuper(n).prototype.removeAll.call(n,e,t);return i.forEach(function(e){delete n._added[n.recordId(e)],r.recordClass&&e._set("$")}),i}}),Oe={linkRelations:C.isBrowser},xe={constructor:function e(t){var n=this;return C.classCallCheck(n,e),e.__super__.call(n,t),n.collectionClass=n.collectionClass||_e,n._collections={},C.fillIn(n,Oe),n._pendingQueries={},n._completedQueries={},n},_callSuper:function(e){for(var t=arguments.length,n=Array(t>1?t-1:0),r=1;t>r;r++)n[r-1]=arguments[r];return this.constructor.__super__.prototype[e].apply(this,n)},_end:function(e,t,n){return n.raw?(t.data=this.getCollection(e).add(t.data,n),t):t=this.getCollection(e).add(t,n)},cachedFind:function(e,t,n){return this.get(e,t,n)},cachedFindAll:function(e,t,n){var r=this;return r._completedQueries[e][r.hashQuery(e,t,n)]?r.filter(e,t,n):void 0},create:function(e,t,n){var r=this;return n||(n={}),r._callSuper("create",e,t,n).then(function(t){return r._end(e,t,n)})},createMany:function(e,t,n){var r=this;return n||(n={}),r._callSuper("createMany",e,t,n).then(function(t){return r._end(e,t,n)})},defineMapper:function(e,t){var n=this,r=C.getSuper(n).prototype.defineMapper.call(n,e,t);n._pendingQueries[e]={},n._completedQueries[e]={},r.relationList||Object.defineProperty(r,"relationList",{value:[]});var i=n._collections[e]=new n.collectionClass(null,{_added:{},datastore:n,mapper:r}),o=r.schema||{},a=o.properties||{};C.forOwn(a,function(e,t){e.indexed&&i.createIndex(t)}),i.createIndex("addedTimestamps",["$"],{fieldGetter:function(e){return i._added[i.recordId(e)]}});var u=n.linkRelations;return u&&r.relationList.forEach(function(e){var t=e.relation,o=e.localField,a="links."+o,s=e.foreignKey,c=e.type,f=C.isUndefined(e.link)?u:e.link,l={index:s},d=void 0;c===L?(i.indexes[s]||i.createIndex(s),d={get:function(){var r=this;if(!r._get("$")||!f)return r._get(a);var i=e.getForeignKey(r),o=C.isUndefined(i)?void 0:n.getCollection(t).get(i);return r._set(a,o),o},set:function(t){var n=this;return n._set(a,t),e.setForeignKey(n,t),i.updateIndex(n,l),e.getLocalField(n)}}):c===M?!function(){var r=e.localKeys,o=e.foreignKeys;n._collections[t]&&s&&!n.getCollection(t).indexes[s]&&n.getCollection(t).createIndex(s),d={get:function(){var i=this;if(!i._get("$")||!f)return i._get(a);var u=e.getForeignKey(i),c=void 0,l=n.getCollection(t);if(s)c=l.getAll(u,{index:s});else if(r){var d=C.get(i,r)||[],p=C.isArray(d)?d:Object.keys(d);c=l.getAll.apply(l,p)}else if(o){var h={};C.set(h,"where."+o+".contains",u),c=l.filter(h)}return i._set(a,c),c},set:function(u){var c=this,f=i.recordId(c),d=n.getCollection(t);return c._set(a,u),s&&(e.setForeignKey(c,u),C.isArray(u)&&u.forEach(function(e){d.updateIndex(e,l)})),r?C.set(c,r,u.map(function(e){return d.recordId(e)})):o&&u.forEach(function(e){var t=C.get(e,o);t?-1===t.indexOf(f)&&t.push(f):C.set(e,o,[f])}),e.getLocalField(c)}}}():c===K&&(d={get:function(){var r=this;if(!r._get("$")||!f)return r._get(a);var i=e.getForeignKey(r),o=n.getCollection(t).getAll(i,{index:s}),u=o.length?o[0]:void 0;return r._set(a,u),u},set:function(r){var i=this;return i._set(a,r),e.setForeignKey(i,r),n.getCollection(t).updateIndex(r,l),e.getLocalField(i)}}),d&&(d.enumerable=C.isUndefined(e.enumerable)?!0:e.enumerable,e.get&&!function(){var t=d.get;d.get=function(){var n=this;return e.get(e,this,function(){for(var e=arguments.length,r=Array(e),i=0;e>i;i++)r[i]=arguments[i];return t.apply(n,r)})}}(),e.set&&!function(){var t=d.set;d.set=function(n){var r=this;return e.set(e,this,n,function(e){return t.call(r,void 0===e?n:e)})}}(),Object.defineProperty(r.recordClass.prototype,o,d))}),r},destroy:function(e,t,n){var r=this;return n||(n={}),r._callSuper("destroy",e,t,n).then(function(i){return n.raw?i.data=r.getCollection(e).remove(t,n):i=r.getCollection(e).remove(t,n),delete r._pendingQueries[e][t],delete r._completedQueries[e][t],i})},destroyAll:function(e,t,n){var r=this;return n||(n={}),r._callSuper("destroyAll",e,t,n).then(function(i){n.raw?i.data=r.getCollection(e).removeAll(t,n):i=r.getCollection(e).removeAll(t,n);var o=r.hashQuery(e,t,n);return delete r._pendingQueries[e][o],delete r._completedQueries[e][o],i})},eject:function(e,t){return this.remove(e,t)},ejectAll:function(e,t){return this.removeAll(e,t)},find:function(e,t,n){var r=this;n||(n={});var i=r._pendingQueries[e][t];if(C.fillIn(n,r.getMapper(e)),i)return i;var o=r.cachedFind(e,t,n),a=void 0;return a=n.force||!o?r._pendingQueries[e][t]=r._callSuper("find",e,t,n).then(function(i){return delete r._pendingQueries[e][t],r._end(e,i,n)},function(n){return delete r._pendingQueries[e][t],C.reject(n)}).then(function(n){return r._completedQueries[e][t]=(new Date).getTime(),n}):C.resolve(o)},findAll:function(e,t,n){var r=this;n||(n={});var i=r.hashQuery(e,t,n),o=r._pendingQueries[e][i];if(C.fillIn(n,r.getMapper(e)),o)return o;var a=r.cachedFindAll(e,t,n),u=void 0;return u=n.force||!a?r._pendingQueries[e][i]=r._callSuper("findAll",e,t,n).then(function(t){return delete r._pendingQueries[e][i],r._end(e,t,n)},function(t){return delete r._pendingQueries[e][i],C.reject(t)}).then(function(t){return r._completedQueries[e][i]=(new Date).getTime(),t}):C.resolve(a)},getCollection:function(e){var t=this._collections[e];if(!t)throw new ReferenceError(e+" is not a registered collection!");return t},hashQuery:function(e,t,n){return C.toJson(t)},inject:function(e,t){return this.add(e,t)},remove:function(e,t,n){var r=this,i=r.getCollection(e).remove(t,n);return i&&r.removeRelated(e,[i],n),i},removeAll:function(e,t,n){var r=this,i=r.getCollection(e).removeAll(t,n);return i.length&&r.removeRelated(e,i,n),i},removeRelated:function(e,t,n){var r=this;C.forEachRelation(r.getMapper(e),n,function(e,n){t.forEach(function(t){var i=void 0,o=void 0;if(!e.foreignKey||"hasOne"!==e.type&&"hasMany"!==e.type?"hasMany"===e.type&&e.localKeys?o={where:s.defineProperty({},e.getRelation().idAttribute,{in:C.get(t,e.localKeys)})}:"hasMany"===e.type&&e.foreignKeys?o={where:s.defineProperty({},e.foreignKeys,{contains:e.getForeignKey(t)})}:"belongsTo"===e.type&&(i=r.remove(e.relation,e.getForeignKey(t),n)):o=s.defineProperty({},e.foreignKey,e.getForeignKey(t)),o&&(i=r.removeAll(e.relation,o,n)),i){if(C.isArray(i)&&!i.length)return;"hasOne"===e.type&&(i=i[0]),e.setLocalField(t,i)}})})},update:function(e,t,n,r){var i=this;return r||(r={}),i._callSuper("update",e,t,n,r).then(function(t){return i._end(e,t,r)})},updateAll:function(e,t,n,r){var i=this;return r||(r={}),i._callSuper("updateAll",e,n,t,r).then(function(t){return i._end(e,t,r)})},updateMany:function(e,t,n){var r=this;return n||(n={}),r._callSuper("updateMany",e,t,n).then(function(t){return r._end(e,t,n)})}},Ce=["add","between","createIndex","filter","get","getAll","query","toJson"];Ce.forEach(function(e){xe[e]=function(t){for(var n,r=arguments.length,i=Array(r>1?r-1:0),o=1;r>o;o++)i[o-1]=arguments[o];return(n=this.getCollection(t))[e].apply(n,i)}});var Ee=Ae.extend(xe),Re={alpha:"21",beta:"false",full:"3.0.0-alpha.21",major:parseInt("3",10),minor:parseInt("0",10),patch:parseInt("0",10)};e.version=Re,e.Collection=P,e.Component=t,e.Container=Ae,e.DataStore=Ee,e.LinkedCollection=_e,e.Mapper=me,e.Query=S,e.Record=q,e.Schema=he,e.utils=C,e.belongsToType=L,e.hasManyType=M,e.hasOneType=K,e.belongsTo=U,e.hasMany=T,e.hasOne=D});
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define("js-data",["exports"],t):t(e.JSData=e.JSData||{})}(this,function(e){"use strict";function t(){this._listeners={}}function n(e,t,n){return e===t?0:(n&&(e=n(e),t=n(t)),null===e&&null===t?0:null===e?-1:null===t?1:t>e?-1:e>t?1:0)}function r(e,t,n){return e.splice(t,0,n),e}function i(e,t){return e.splice(t,1),e}function o(e,t,r){for(var i=0,o=e.length,a=void 0,u=void 0;o>i;){if(u=(i+o)/2|0,a=n(t,e[u],r),0===a)return{found:!0,index:u};0>a?o=u:i=u+1}return{found:!1,index:o}}function a(e,t){if(C.classCallCheck(this,a),e||(e=[]),!C.isArray(e))throw new Error("fieldList must be an array.");t||(t={}),this.fieldList=e,this.fieldGetter=t.fieldGetter,this.hashCode=t.hashCode,this.isIndex=!0,this.keys=[],this.values=[]}function u(e,t){var n=this;t||(t={});var r=t.localField;if(!r)throw new Error("localField is required");var i=t.foreignKey=t.foreignKey||t.localKey;if(!i&&(t.type===P||t.type===K))throw new Error("foreignKey is required");var o=t.localKeys,a=t.foreignKeys;if(!i&&!o&&!a&&t.type===L)throw new Error("one of (foreignKey, localKeys, foreignKeys) is required");if(C.isString(e)){if(t.relation=e,!C.isFunction(t.getRelation))throw new Error("you must provide a reference to the related mapper!")}else e&&(t.relation=e.name,Object.defineProperty(n,"relatedMapper",{value:e}));C.fillIn(n,t)}var s={};s.typeof="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol?"symbol":typeof e},s.defineProperty=function(e,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e},s.toConsumableArray=function(e){if(Array.isArray(e)){for(var t=0,n=Array(e.length);t<e.length;t++)n[t]=e[t];return n}return Array.from(e)};var c=1/0,l=1.7976931348623157e308,f="[object Boolean]",d="[object Date]",p="[object Function]",h="[object Number]",v="[object Object]",g="[object RegExp]",y="[object String]",m=Object.prototype.toString,b=/^(.+)\.(.+)$/,w=function(e){if(!e)return 0;if(e=+e,e===c||e===-c){var t=0>e?-1:1;return t*l}var n=e%1;return e===e?n?e-n:e:0},A=function(e){return m.call(e)},_=function(e){return!!e&&"object"===("undefined"==typeof e?"undefined":s.typeof(e))&&e.constructor===Object},O=function(e,t){if(!t)return e;var n=t.split(".");return n.forEach(function(t){e[t]||(e[t]={}),e=e[t]}),e},x={Promise:Promise,_:function(e,t){for(var n in e){var r=e[n];void 0===t[n]&&!x.isFunction(r)&&n&&0!==n.indexOf("_")&&(t[n]=r)}},_forRelation:function(e,t,n,r){var i=t.relation,o=null,a=void 0;if(e||(e={}),e.with||(e.with=[]),(a=x._getIndex(e.with,i))>=0?o=i:(a=x._getIndex(e.with,t.localField))>=0&&(o=t.localField),e.withAll)return void n.call(r,t,{});if(o){var u={};x.fillIn(u,t.getRelation()),x.fillIn(u,e),u.with=e.with.slice(),u._activeWith=u.with.splice(a,1)[0],u.with.forEach(function(e,t){e&&0===e.indexOf(o)&&e.length>=o.length&&"."===e[o.length]?u.with[t]=e.substr(o.length+1):u.with[t]=""}),n.call(r,t,u)}},_getIndex:function(e,t){var n=-1;return e.forEach(function(e,r){return e===t?(n=r,!1):x.isObject(e)&&e.relation===t?(n=r,!1):void 0}),n},addHiddenPropsToTarget:function(e,t){var n={};x.forOwn(t,function(e,t){n[t]={writable:!0,value:e}}),Object.defineProperties(e,n)},areDifferent:function(e,t,n){n||(n={});var r=x.diffObjects(e,t,n),i=Object.keys(r.added).length+Object.keys(r.removed).length+Object.keys(r.changed).length;return i>0},classCallCheck:function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")},copy:function(e,t,n,r,i,o){if(t){if(e===t)throw new Error("Cannot copy! Source and destination are identical.");if(n=n||[],r=r||[],x.isObject(e)){var a=n.indexOf(e);if(-1!==a)return r[a];n.push(e),r.push(t)}var u=void 0;if(x.isArray(e)){var s=void 0;for(t.length=0,s=0;s<e.length;s++)u=x.copy(e[s],null,n,r,i,o),x.isObject(e[s])&&(n.push(e[s]),r.push(u)),t.push(u)}else{x.isArray(t)?t.length=0:x.forOwn(t,function(e,n){delete t[n]});for(var c in e)if(e.hasOwnProperty(c)){if(x.isBlacklisted(c,i))continue;u=x.copy(e[c],null,n,r,i,o),x.isObject(e[c])&&(n.push(e[c]),r.push(u)),t[c]=u}}}else t=e,e&&(x.isArray(e)?t=x.copy(e,[],n,r,i,o):x.isDate(e)?t=new Date(e.getTime()):x.isRegExp(e)?(t=new RegExp(e.source,e.toString().match(/[^\/]*$/)[0]),t.lastIndex=e.lastIndex):x.isObject(e)&&(t=o?x.copy(e,{},n,r,i,o):x.copy(e,Object.create(Object.getPrototypeOf(e)),n,r,i,o)));return t},deepFillIn:function(e,t){return t&&x.forOwn(t,function(t,n){var r=e[n];_(t)&&_(r)?x.deepFillIn(r,t):e.hasOwnProperty(n)&&void 0!==e[n]||(e[n]=t)}),e},deepMixIn:function(e,t){return t&&x.forOwn(t,function(t,n){var r=e[n];_(t)&&_(r)?x.deepMixIn(r,t):e[n]=t}),e},diffObjects:function(e,t,n){n||(n={});var r=n.equalsFn,i=n.ignore,o={added:{},changed:{},removed:{}};return x.isFunction(r)||(r=x.strictEqual),x.forOwn(t,function(t,n){var a=e[n];x.isBlacklisted(n,i)||r(a,t)||(x.isUndefined(a)?o.removed[n]=void 0:r(a,t)||(o.changed[n]=a))}),x.forOwn(e,function(e,n){x.isUndefined(t[n])&&!x.isBlacklisted(n,i)&&(o.added[n]=e)}),o},equal:function(e,t){return e==t},eventify:function(e,t,n,r){e=e||this;var i={};t||n||(t=function(){return i},n=function(e){i=e}),Object.defineProperties(e,{emit:{enumerable:!!r,value:function(){for(var e=t.call(this)||{},n=arguments.length,r=Array(n),i=0;n>i;i++)r[i]=arguments[i];var o=r.shift(),a=e[o]||[],u=void 0;for(u=0;u<a.length;u++)a[u].f.apply(a[u].c,r);for(a=e.all||[],r.unshift(o),u=0;u<a.length;u++)a[u].f.apply(a[u].c,r)}},off:{enumerable:!!r,value:function(e,r){var i=t.call(this),o=i[e];if(o)if(r){for(var a=0;a<o.length;a++)if(o[a].f===r){o.splice(a,1);break}}else o.splice(0,o.length);else n.call(this,{})}},on:{enumerable:!!r,value:function(e,r,i){t.call(this)||n.call(this,{});var o=t.call(this);o[e]=o[e]||[],o[e].push({c:i,f:r})}}})},extend:function(e,t){var n=this,r=void 0;e||(e={}),t||(t={}),e.hasOwnProperty("constructor")?(r=e.constructor,delete e.constructor):r=function(){x.classCallCheck(this,r);for(var e=arguments.length,t=Array(e),n=0;e>n;n++)t[n]=arguments[n];var i=x.possibleConstructorReturn(this,(r.__super__||Object.getPrototypeOf(r)).apply(this,t));return i},r.prototype=Object.create(n&&n.prototype,{constructor:{configurable:!0,enumerable:!1,value:r,writable:!0}});var i=Object;return i.setPrototypeOf?i.setPrototypeOf(r,n):t.strictEs6Class?r.__proto__=n:x.forOwn(n,function(e,t){r[t]=e}),Object.defineProperty(r,"__super__",{configurable:!0,value:n}),x.addHiddenPropsToTarget(r.prototype,e),x.fillIn(r,t),r},fillIn:function(e,t){x.forOwn(t,function(t,n){e.hasOwnProperty(n)&&void 0!==e[n]||(e[n]=t)})},forEachRelation:function(e,t,n,r){var i=e.relationList||[];i.length&&i.forEach(function(e){x._forRelation(t,e,n,r)})},forOwn:function(e,t,n){var r=Object.keys(e),i=r.length,o=void 0;for(o=0;i>o;o++)t.call(n,e[r[o]],r[o],e)},fromJson:function(e){return x.isString(e)?JSON.parse(e):e},get:function(e,t){if(t){for(var n=t.split("."),r=n.pop();t=n.shift();)if(e=e[t],null==e)return;return e[r]}},getSuper:function(e,t){var n=t?e:e.constructor;return n.__super__||Object.getPrototypeOf(n)||n.__proto__},intersection:function(e,t){if(!e||!t)return[];var n=[],r=void 0,i=void 0,o=e.length;for(i=0;o>i;i++)r=e[i],-1===n.indexOf(r)&&-1!==t.indexOf(r)&&n.push(r);return n},isArray:Array.isArray,isBlacklisted:function(e,t){if(!t||!t.length)return!1;for(var n=void 0,r=0;r<t.length;r++)if(A(t[r])===g&&t[r].test(e)||t[r]===e)return n=e;return!!n},isBoolean:function(e){return A(e)===f},isBrowser:!1,isDate:function(e){return e&&"object"===("undefined"==typeof e?"undefined":s.typeof(e))&&A(e)===d},isFunction:function(e){return"function"==typeof e||e&&A(e)===p},isInteger:function(e){return A(e)===h&&e==w(e)},isNull:function(e){return null===e},isNumber:function(e){var t="undefined"==typeof e?"undefined":s.typeof(e);return"number"===t||e&&"object"===t&&A(e)===h},isObject:function(e){return A(e)===v},isRegExp:function(e){return A(e)===g},isSorN:function(e){return x.isString(e)||x.isNumber(e)},isString:function(e){return"string"==typeof e||e&&"object"===("undefined"==typeof e?"undefined":s.typeof(e))&&A(e)===y},isUndefined:function(e){return void 0===e},logify:function(e){x.addHiddenPropsToTarget(e,{dbg:function(){for(var e=arguments.length,t=Array(e),n=0;e>n;n++)t[n]=arguments[n];this.log.apply(this,["debug"].concat(t))},log:function(e){for(var t=arguments.length,n=Array(t>1?t-1:0),r=1;t>r;r++)n[r-1]=arguments[r];if(e&&!n.length&&(n.push(e),e="debug"),"debug"!==e||this.debug){var i=e.toUpperCase()+": ("+(this.name||this.constructor.name)+")";if(console[e]){var o;(o=console)[e].apply(o,[i].concat(n))}else{var a;(a=console).log.apply(a,[i].concat(n))}}}})},omit:function(e,t){var n={};return x.forOwn(e,function(e,r){-1===t.indexOf(r)&&(n[r]=e)}),n},plainCopy:function(e){return x.copy(e,void 0,void 0,void 0,void 0,!0)},possibleConstructorReturn:function(e,t){if(!e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return!t||"object"!==("undefined"==typeof t?"undefined":s.typeof(t))&&"function"!=typeof t?e:t},reject:function(e){return x.Promise.reject(e)},resolve:function(e){return x.Promise.resolve(e)},set:function(e,t,n){if(x.isObject(t))x.forOwn(t,function(t,n){x.set(e,n,t)});else{var r=b.exec(t);r?O(e,r[1])[r[2]]=n:e[t]=n}},strictEqual:function(e,t){var n=e===t;return n||(x.isObject(e)&&x.isObject(t)?(x.forOwn(e,function(e,r){n=n&&x.strictEqual(e,t[r])}),x.forOwn(t,function(t,r){n=n&&x.strictEqual(t,e[r])})):x.isArray(e)&&x.isArray(t)&&e.forEach(function(e,r){n=n&&x.strictEqual(e,t[r])})),n},toJson:JSON.stringify,unset:function(e,t){for(var n=t.split("."),r=n.pop();t=n.shift();)if(e=e[t],null==e)return;e[r]=void 0}};try{x.isBrowser=!!window}catch(e){x.isBrowser=!1}var C=x;t.extend=C.extend,C.logify(t.prototype),C.eventify(t.prototype,function(){return this._listeners},function(e){this._listeners=e});var E={limit:"",offset:"",orderBy:"",skip:"",sort:"",where:""},R=/([.*+?^=!:${}()|[\]\/\\])/g,j=/%/g,I=/_/g,F=function(e){return e.replace(R,"\\$1")},S=t.extend({constructor:function e(t){C.classCallCheck(this,e),this.collection=t,this.data=null},between:function(e,t,n){var r=this;if(n||(n={}),r.data)throw new Error("Cannot access index after first operation!");return r.data=r.collection.getIndex(n.index).between(e,t,n),r},compare:function(e,t,n,r){var i=e[t],o=C.get(n,i[0]),a=C.get(r,i[0]);return o&&C.isString(o)&&(o=o.toUpperCase()),a&&C.isString(a)&&(a=a.toUpperCase()),void 0===n&&(n=null),void 0===r&&(r=null),"DESC"===i[1]?o>a?-1:a>o?1:t<e.length-1?this.compare(e,t+1,n,r):0:a>o?-1:o>a?1:t<e.length-1?this.compare(e,t+1,n,r):0},evaluate:function(e,t,n){var r=this.constructor.ops;return r[t]?r[t](e,n):0===t.indexOf("like")?!C.isNull(this.like(n,t.substr(4)).exec(e)):0===t.indexOf("notLike")?C.isNull(this.like(n,t.substr(7)).exec(e)):void 0},filter:function(e,t){var n=this;return e||(e={}),n.getData(),C.isObject(e)?!function(){var t={};C.isObject(e.where)&&(t=e.where),C.forOwn(e,function(e,n){n in E||n in t||(t[n]={"==":e})});var r=[],i=[],o=[];C.forOwn(t,function(e,t){C.isObject(e)||(e={"==":e}),C.forOwn(e,function(e,n){r.push(t),i.push(n),o.push(e)})}),r.length&&!function(){var e=void 0,t=r.length;n.data=n.data.filter(function(a){var u=!0,s=!0;for(e=0;t>e;e++){var c=i[e],l="|"===c.charAt(0);c=l?c.substr(1):c;var f=n.evaluate(C.get(a,r[e]),c,o[e]);void 0!==f&&(s=u?f:l?s||f:s&&f),u=!1}return s})}();var a=e.orderBy||e.sort;C.isString(a)&&(a=[[a,"ASC"]]),C.isArray(a)||(a=null),a&&!function(){var e=0;a.forEach(function(e,t){C.isString(e)&&(a[t]=[e,"ASC"])}),n.data.sort(function(t,r){return n.compare(a,e,t,r)})}(),C.isNumber(e.skip)?n.skip(e.skip):C.isNumber(e.offset)&&n.skip(e.offset),C.isNumber(e.limit)&&n.limit(e.limit)}():C.isFunction(e)&&(n.data=n.data.filter(e,t)),n},forEach:function(e,t){return this.getData().forEach(e,t),this},get:function(e,t){var n=this;if(e||(e=[]),t||(t={}),n.data)throw new Error("Cannot access index after first operation!");return e&&!C.isArray(e)&&(e=[e]),e.length?(n.data=n.collection.getIndex(t.index).get(e),n):(n.getData(),n)},getAll:function(){var e=this,t={};if(e.data)throw new Error("Cannot access index after first operation!");for(var n=arguments.length,r=Array(n),i=0;n>i;i++)r[i]=arguments[i];if(!r.length||1===r.length&&C.isObject(r[0]))return e.getData(),e;r.length&&C.isObject(r[r.length-1])&&(t=r[r.length-1],r.pop());var o=e.collection,a=o.getIndex(t.index);return e.data=[],r.forEach(function(t){e.data=e.data.concat(a.get(t))}),e},getData:function(){var e=this;return e.data||(e.data=e.collection.index.getAll()),e.data},like:function(e,t){return new RegExp("^"+F(e).replace(j,".*").replace(I,".")+"$",t)},limit:function(e){if(!C.isNumber(e))throw new TypeError("limit: Expected number but found "+("undefined"==typeof e?"undefined":s.typeof(e))+"!");var t=this.getData();return this.data=t.slice(0,Math.min(t.length,e)),this},map:function(e,t){return this.data=this.getData().map(e,t),this},mapCall:function(e){for(var t=arguments.length,n=Array(t>1?t-1:0),r=1;t>r;r++)n[r-1]=arguments[r];return this.data=this.getData().map(function(t){return t[e].apply(t,n)}),this},run:function(){var e=this.data;return this.data=null,e},skip:function(e){if(!C.isNumber(e))throw new TypeError("skip: Expected number but found "+("undefined"==typeof e?"undefined":s.typeof(e))+"!");var t=this.getData();return e<t.length?this.data=t.slice(e):this.data=[],this}},{ops:{"==":function(e,t){return e==t},"===":function(e,t){return e===t},"!=":function(e,t){return e!=t},"!==":function(e,t){return e!==t},">":function(e,t){return e>t},">=":function(e,t){return e>=t},"<":function(e,t){return t>e},"<=":function(e,t){return t>=e},isectEmpty:function(e,t){return!C.intersection(e||[],t||[]).length},isectNotEmpty:function(e,t){return C.intersection(e||[],t||[]).length},in:function(e,t){return-1!==t.indexOf(e)},notIn:function(e,t){return-1===t.indexOf(e)},contains:function(e,t){return-1!==(e||[]).indexOf(t)},notContains:function(e,t){return-1===(e||[]).indexOf(t)}}});C.addHiddenPropsToTarget(a.prototype,{set:function(e,t){C.isArray(e)||(e=[e]);var n=e.shift()||null,i=o(this.keys,n);if(0===e.length)if(i.found){var u=o(this.values[i.index],t,this.hashCode);u.found||r(this.values[i.index],u.index,t)}else r(this.keys,i.index,n),r(this.values,i.index,[t]);else if(i.found)this.values[i.index].set(e,t);else{r(this.keys,i.index,n);var s=new a([],{hashCode:this.hashCode});s.set(e,t),r(this.values,i.index,s)}},get:function(e){C.isArray(e)||(e=[e]);var t=e.shift()||null,n=o(this.keys,t);return 0===e.length?n.found?this.values[n.index].isIndex?this.values[n.index].getAll():this.values[n.index]:[]:n.found?this.values[n.index].get(e):[]},getAll:function(){var e=[];return this.values.forEach(function(t){e=t.isIndex?e.concat(t.getAll()):e.concat(t)}),e},visitAll:function(e,t){this.values.forEach(function(n){n.isIndex?n.visitAll(e,t):n.forEach(e,t)})},between:function(e,t,n){n||(n={}),C.isArray(e)||(e=[e]),C.isArray(t)||(t=[t]),C.fillIn(n,{leftInclusive:!0,rightInclusive:!1,limit:void 0,offset:0});var r=this._between(e,t,n);return n.limit?r.slice(n.offset,n.limit+n.offset):r.slice(n.offset)},_between:function(e,t,n){var r=[],i=e.shift(),a=t.shift(),u=void 0;if(u=void 0!==i?o(this.keys,i):{found:!1,index:0},0===e.length){u.found&&n.leftInclusive===!1&&(u.index+=1);for(var s=u.index;s<this.keys.length;s+=1){if(void 0!==a)if(n.rightInclusive){if(this.keys[s]>a)break}else if(this.keys[s]>=a)break;if(r=this.values[s].isIndex?r.concat(this.values[s].getAll()):r.concat(this.values[s]),n.limit&&r.length>=n.limit+n.offset)break}}else for(var c=u.index;c<this.keys.length;c+=1){var l=this.keys[c];if(l>a)break;if(r=this.values[c].isIndex?l===i?r.concat(this.values[c]._between(C.copy(e),t.map(function(){}),n)):l===a?r.concat(this.values[c]._between(e.map(function(){}),C.copy(t),n)):r.concat(this.values[c].getAll()):r.concat(this.values[c]),n.limit&&r.length>=n.limit+n.offset)break}return n.limit?r.slice(0,n.limit+n.offset):r},peek:function(){return this.values.length?this.values[0].isIndex?this.values[0].peek():this.values[0]:[]},clear:function(){this.keys=[],this.values=[]},insertRecord:function(e){var t=this.fieldList.map(function(t){return C.isFunction(t)?t(e)||null:e[t]||null});this.set(t,e)},removeRecord:function(e){var t=this,n=void 0;return this.values.forEach(function(r,a){if(r.isIndex){if(r.removeRecord(e))return 0===r.keys.length&&(i(t.keys,a),i(t.values,a)),n=!0,!1}else{var u=o(r,e,t.hashCode);if(u.found)return i(r,u.index),0===r.length&&(i(t.keys,a),i(t.values,a)),n=!0,!1}}),n?e:void 0},updateRecord:function(e){this.removeRecord(e),this.insertRecord(e)}});var k={idAttribute:"id",mapper:null,onConflict:"merge",recordOpts:null},M=t.extend({constructor:function e(t,n){var r=this;C.classCallCheck(r,e),e.__super__.call(r),C.isObject(t)&&!C.isArray(t)&&(n=t,t=[]),C.isString(n)&&(n={idAttribute:n}),t||(t=[]),n||(n={}),n.recordOpts||(n.recordOpts={}),C.fillIn(r,n),C.fillIn(r,k);var i=r.recordId();r.index=new a([i],{hashCode:function(e){return C.get(e,i)}}),r.indexes={},t.forEach(function(e){e=r.mapper?r.mapper.createRecord(e,r.recordOpts):e,r.index.insertRecord(e),e&&C.isFunction(e.on)&&e.on("all",r._onRecordEvent,r)})},_onRecordEvent:function(){this.emit.apply(this,arguments)},add:function(e,t){var n=this;t||(t={}),C._(n,t),e=n.beforeAdd(e,t)||e;var r=!1,i=n.recordId();C.isObject(e)&&!C.isArray(e)&&(e=[e],r=!0),e=e.map(function(e){var r=n.recordId(e);if(!C.isSorN(r))throw new TypeError("Collection#add: Expected string or number for "+i+", found "+("undefined"==typeof r?"undefined":s.typeof(r))+"!");var o=n.get(r);if(e===o)return o;if(o){var a=t.onConflict||n.onConflict;"merge"===a?C.deepMixIn(o,e):"replace"===a&&(C.forOwn(o,function(t,n){n===i||e.hasOwnProperty(n)||delete o[n]}),o.set(e)),e=o,n.updateIndexes(e)}else e=n.mapper?n.mapper.createRecord(e,n.recordOpts):e,n.index.insertRecord(e),C.forOwn(n.indexes,function(t,n){t.insertRecord(e)}),e&&C.isFunction(e.on)&&e.on("all",n._onRecordEvent,n);return e});var o=r?e.length?e[0]:void 0:e;return n.emit("add",o),n.afterAdd(e,t,o)||o},afterAdd:function(){},afterRemove:function(){},afterRemoveAll:function(){},beforeAdd:function(){},beforeRemove:function(){},beforeRemoveAll:function(){},between:function(e,t,n){return this.query().between(e,t,n).run()},createIndex:function(e,t,n){var r=this;C.isString(e)&&void 0===t&&(t=[e]),n||(n={}),n.hashCode=n.hashCode||function(e){return r.recordId(e)};var i=r.indexes[e]=new a(t,n);return r.index.visitAll(i.insertRecord,i),r},filter:function(e,t){return this.query().filter(e,t).run()},forEach:function(e,t){this.index.visitAll(e,t)},get:function(e){var t=this.query().get(e).run();return t.length?t[0]:void 0},getAll:function(){var e;return(e=this.query()).getAll.apply(e,arguments).run()},getIndex:function(e){var t=e?this.indexes[e]:this.index;if(!t)throw new Error("Index "+e+" does not exist!");return t},limit:function(e){return this.query().limit(e).run()},map:function(e,t){var n=[];return this.index.visitAll(function(r){n.push(e.call(t,r))}),n},mapCall:function(e){for(var t=arguments.length,n=Array(t>1?t-1:0),r=1;t>r;r++)n[r-1]=arguments[r];var i=[];return this.index.visitAll(function(t){i.push(t[e].apply(t,n))}),i},recordId:function(e){if(e)return C.get(e,this.recordId());var t=this;return t.mapper?t.mapper.idAttribute:t.idAttribute||"id"},query:function(){return new S(this)},reduce:function(e,t){var n=this.getAll();return n.reduce(e,t)},remove:function(e,t){var n=this;t||(t={}),n.beforeRemove(e,t);var r=n.get(e);return r&&(n.index.removeRecord(r),C.forOwn(n.indexes,function(e,t){e.removeRecord(r)}),r&&C.isFunction(r.off)&&(r.off("all",n._onRecordEvent,n),n.emit("remove",r))),n.afterRemove(e,t,r)||r},removeAll:function(e,t){var n=this;t||(t={}),n.beforeRemoveAll(e,t);var r=n.filter(e);return r.forEach(function(e){n.remove(n.recordId(e),t)}),n.afterRemoveAll(e,t,r)||r},skip:function(e){return this.query().skip(e).run()},toJSON:function(e){return this.mapCall("toJSON",e)},updateIndex:function(e,t){t||(t={}),this.getIndex(t.index).updateRecord(e)},updateIndexes:function(e){var t=this;t.index.updateRecord(e),C.forOwn(t.indexes,function(t,n){t.updateRecord(e)})}}),P="belongsTo",L="hasMany",K="hasOne";C.addHiddenPropsToTarget(u.prototype,{getRelation:function(){return this.relatedMapper},getLocalKeys:function(e){},getForeignKey:function(e){return this.type===P?C.get(e,this.foreignKey):C.get(e,this.mapper.idAttribute)},setForeignKey:function(e,t){var n=this;e&&t&&(n.type===P?C.set(e,n.foreignKey,C.get(t,n.getRelation().idAttribute)):!function(){var r=n.mapper.idAttribute;C.isArray(t)?t.forEach(function(t){C.set(t,n.foreignKey,C.get(e,r))}):C.set(t,n.foreignKey,C.get(e,r))}())},getLocalField:function(e){return C.get(e,this.localField)},setLocalField:function(e,t){return C.set(e,this.localField,t)}});var N=function(e,t,n){if(n||(n={}),!n.type)throw new Error("must specify relation type!");n.mapper=e,n.name=e.name;var r=new u(t,n);e.relationList||Object.defineProperty(e,"relationList",{value:[]}),e.relationFields||Object.defineProperty(e,"relationFields",{value:[]}),e.relationList.push(r),e.relationFields.push(r.localField)},U=function(e,t){return t||(t={}),t.type=P,function(n){N(n,e,t)}},T=function(e,t){return t||(t={}),t.type=L,function(n){N(n,e,t)}},D=function(e,t){return t||(t={}),t.type=K,function(n){N(n,e,t)}},q=t.extend({constructor:function e(t,n){var r=this;C.classCallCheck(r,e),t||(t={}),n||(n={});var i={};Object.defineProperties(r,{_get:{enumerable:!1,value:function(e){return C.get(i,e)}},_set:{enumerable:!1,value:function(e,t){return C.set(i,e,t)}},_unset:{enumerable:!1,value:function(e){return C.unset(i,e)}}});var o=r._set;o("creating",!0),n.noValidate&&o("noValidate",!0),C.fillIn(r,t),o("creating",!1),o("noValidate",!1),o("previous",C.copy(t))},_mapper:function(){if(!this.constructor.mapper)throw new Error("This recordClass has no Mapper!");return this.constructor.mapper},afterLoadRelations:function(){},afterSave:function(){},beforeLoadRelations:function(){},beforeSave:function(){},changes:function(e){var t=this;return e||(e={}),C.diffObjects(t,t._get("previous"),e)},commit:function(){var e=this;return e._set("changed"),e._set("previous",C.copy(e)),e},create:function(e){return this._mapper().create(this,e)},destroy:function(e){var t=this._mapper();return t.destroy(C.get(this,t.idAttribute),e)},get:function(e){return C.get(this,e)},hasChanges:function(e){var t=this,n=!!(t._get("changed")||[]).length;return n||C.areDifferent(t,t._get("previous"),e)},hashCode:function(){var e=this;return C.get(e,e._mapper().idAttribute)},isValid:function(e){var t=this;return!!t._mapper().validate(t,e)},loadRelations:function(e,t){var n=void 0,r=this,i=r._mapper(),o=i.relationList||[];return e||(e=[]),t||(t={}),C._(i,t),t.adapter=i.getAdapterName(t),n=t.op="beforeLoadRelations",C.resolve(r[n](e,t)).then(function(){return C.isString(e)&&(e=[e]),n=t.op="loadRelations",i.dbg(n,r,e,t),Promise.all(o.map(function(e){if(C.isFunction(e.load))return e.load(i,e,r,t);var n=void 0;if("hasMany"===e.type&&e.foreignKey)n=e.getRelation().findAll(s.defineProperty({},e.foreignKey,C.get(r,i.idAttribute)),t);else if(e.foreignKey){var o=C.get(r,e.foreignKey);C.isSorN(o)&&(n=e.getRelation().find(o,t))}else e.localKeys?n=e.getRelation().findAll(s.defineProperty({},e.getRelation().idAttribute,{in:C.get(r,e.localKeys)}),t):e.foreignKeys&&(n=e.getRelation().findAll(s.defineProperty({},e.getRelation().idAttribute,{contains:C.get(r,i.idAttribute)}),t));return n&&(n=n.then(function(n){t.raw&&(n=n.data),C.set(r,e.localField,"hasOne"===e.type?n.length?n[0]:void 0:n)})),n}))}).then(function(){return n=t.op="afterLoadRelations",C.resolve(r[n](e,t)).then(function(){return r})})},previous:function(e){var t=this;return e?t._get("previous."+e):t._get("previous")},revert:function(e){var t=this,n=t._get("previous")||{};return e||(e={}),e.preserve||(e.preserve=[]),C.forOwn(t,function(r,i){i!==t._mapper().idAttribute&&!n.hasOwnProperty(i)&&t.hasOwnProperty(i)&&-1===e.preserve.indexOf(i)&&delete t[i]}),C.forOwn(n,function(n,r){-1===e.preserve.indexOf(r)&&(t[r]=n)}),t.commit(),t},save:function(e){var t=this,n=t._mapper();return n.update(C.get(t,n.idAttribute),t,e)},set:function(e,t,n){var r=this;C.isObject(e)&&(n=t),n||(n={}),n.silent&&r._set("silent",!0),C.set(r,e,t),r._get("eventId")||r._set("silent")},toJSON:function(e){var t=this,n=this.constructor.mapper;if(n)return n.toJSON(this,e);var r=function(){var e={};return C.forOwn(t,function(t,n){e[n]=C.copy(t)}),{v:e}}();return"object"===("undefined"==typeof r?"undefined":s.typeof(r))?r.v:void 0},unset:function(e,t){this.set(e,void 0,t)},validate:function(e){return this._mapper().validate(this,e)}});C.eventify(q.prototype,function(){return this._get("events")},function(e){this._set("events",e)});var Q={array:C.isArray,boolean:C.isBoolean,integer:C.isInteger,null:C.isNull,number:C.isNumber,object:C.isObject,string:C.isString},J=function(e,t){var n="";return e&&(n+=C.isNumber(e)?"["+e+"]":t?"."+e:""+e),n},B=function(e){e||(e={});var t="",n=e.path||[];return n.forEach(function(e){t+=J(e,t)}),t+=J(e.prop,t)},$=function(e,t,n){return{expected:t,actual:""+e,path:B(n)}},V=function(e,t,n,r){r.push($(e,t,n))},H=function(e,t,n,r){var i=n[e];return t.length>i?$(t.length,"length no more than "+i,r):void 0},G=function(e,t,n,r){var i=n[e];return t.length<i?$(t.length,"length no less than "+i,r):void 0},W={allOf:function(e,t,n){var r=[];return t.allOf.forEach(function(t){r=r.concat(ie(e,t,n)||[])}),r.length?void 0:r},anyOf:function(e,t,n){var r=!1,i=[];return t.anyOf.forEach(function(t){var o=ie(e,t,n);o?i=i.concat(o):r=!0}),r?void 0:i},dependencies:function(e,t,n){},enum:function(e,t,n){var r=t.enum;return-1===r.indexOf(e)?$(e,"one of ("+r.join(", ")+")",n):void 0},items:function e(t,n,r){r||(r={});for(var e=n.items,i=[],o=C.isArray(e),a=t.length,u=0;a>u;u++)o&&(e=n.items[u]),r.prop=u,i=i.concat(ie(t[u],e,r)||[]);return i.length?i:void 0},maximum:function e(t,n,r){var e=n.maximum,i=n.exclusiveMaximum;return("undefined"==typeof t?"undefined":s.typeof(t))===("undefined"==typeof e?"undefined":s.typeof(e))&&(i?t>e:t>=e)?$(t,"no more than "+e,r):void 0},maxItems:function(e,t,n){return H("maxItems",e,t,n)},maxLength:function(e,t,n){return H("maxLength",e,t,n)},maxProperties:function e(t,n,r){var e=n.maxProperties,i=Object.keys(t).length;return i>e?$(i,"no more than "+e+" properties",r):void 0},minimum:function e(t,n,r){var e=n.minimum,i=n.exclusiveMinimum;return("undefined"==typeof t?"undefined":s.typeof(t))===("undefined"==typeof e?"undefined":s.typeof(e))&&(i?e>t:e>=t)?$(t,"no less than "+e,r):void 0},minItems:function(e,t,n){return G("minItems",e,t,n)},minLength:function(e,t,n){return G("minLength",e,t,n)},minProperties:function e(t,n,r){var e=n.minProperties,i=Object.keys(t).length;return e>i?$(i,"no more than "+e+" properties",r):void 0},multipleOf:function(e,t,n){},not:function(e,t,n){return ie(e,t.not,n)?void 0:$("succeeded","should have failed",n)},oneOf:function(e,t,n){var r=!1,i=[];return t.oneOf.forEach(function(t){var o=ie(e,t,n);if(o)i=i.concat(o);else{if(r)return i=[$("valid against more than one","valid against only one",n)],r=!1,!1;r=!0}}),r?void 0:i},pattern:function e(t,n,r){var e=n.pattern;return C.isString(t)&&!t.match(e)?$(t,e,r):void 0},properties:function e(t,n,r){r||(r={});var i=C.isUndefined(n.additionalProperties)?!0:n.additionalProperties,o={},e=n.properties||{},a=n.patternProperties||{},u=[];C.forOwn(t,function(e,t){o[t]=void 0}),C.forOwn(e||{},function(e,n){C.isUndefined(t[n])&&!C.isUndefined(e.default)&&(t[n]=C.copy(e.default)),r.prop=n,u=u.concat(ie(t[n],e,r)||[]),delete o[n]}),C.forOwn(a,function(e,n){C.forOwn(o,function(i,a){a.match(n)&&(r.prop=a,u=u.concat(ie(t[a],e,r)||[]),delete o[a])})});var s=Object.keys(o);return i===!1?s.length&&V("extra fields: "+s.join(", "),"no extra fields",r,u):C.isObject(i)&&s.forEach(function(e){r.prop=e,u=u.concat(ie(t[e],i,r)||[])}),u.length?u:void 0},required:function e(t,n,r){var e=n.required,i=[];return r.existingOnly||e.forEach(function(e){if(C.isUndefined(C.get(t,e))){var n=r.prop;r.prop=e,V(void 0,"a value",r,i),r.prop=n}}),i.length?i:void 0},type:function e(t,n,r){var e=n.type,i=void 0;if(C.isString(e)&&(e=[e]),e.forEach(function(e){return Q[e](t,n,r)?(i=e,!1):void 0}),!i)return $(t?"undefined"==typeof t?"undefined":s.typeof(t):""+t,"one of ("+e.join(", ")+")",r);var o=pe[i];return o?o(t,n,r):void 0},uniqueItems:function(e,t,n){if(e&&e.length&&t.uniqueItems){var r=e.length,i=void 0,o=void 0,a=void 0;for(o=r-1;o>0;o--)for(i=e[o],a=o-1;a>=0;a--)if(i===e[a])return $(i,"no duplicates",n)}}},z=function(e,t,n,r){return!C.isUndefined(n[e])&&W[e](t,n,r)},X=function(e,t,n,r){var i=[];return e.forEach(function(e){i=i.concat(z(e,t,n,r)||[])}),i.length?i:void 0},Y=["enum","type","allOf","anyOf","oneOf","not"],Z=["items","maxItems","minItems","uniqueItems"],ee=["multipleOf","maximum","minimum"],te=["maxProperties","minProperties","required","properties","dependencies"],ne=["maxLength","minLength","pattern"],re=function(e,t,n){return X(Y,e,t,n)},ie=function e(t,n,r){var i=[];r||(r={});var o=void 0,a=r.prop;if(!C.isUndefined(n)){if(!C.isObject(n))throw new Error('Invalid schema at path: "'+r.path+'"');return C.isUndefined(r.path)&&(r.path=[]),C.isUndefined(r.prop)||(o=!0,r.path.push(r.prop),r.prop=void 0),n.extends&&(i=C.isFunction(n.extends.validate)?i.concat(n.extends.validate(t,r)||[]):i.concat(e(t,n.extends,r)||[])),C.isUndefined(t)?(n.required===!0&&V(t,"a value",r,i),o&&(r.path.pop(),r.prop=a),i.length?i:void 0):(i=i.concat(re(t,n,r)||[]),o&&(r.path.pop(),r.prop=a),i.length?i:void 0)}},oe="changing",ae="changed",ue="creating",se="eventId",ce="noValidate",le="silent",fe="validation failed",de=function(e,t,n){var r={enumerable:C.isUndefined(t.enumerable)?!0:!!t.enumerable},i="props."+e,o="previous."+e,a=n.getter,u=n.setter,s=n.unsetter;return r.get=function(){return this._get(i)},r.set=function(n){var r=this,c=r[a],l=r[u],f=r[s];if(!c(ce)){var d=t.validate(n);if(d){var p=new Error(fe);throw p.errors=d,p}}return t.track&&!c(ue)&&!function(){var t=c(o),a=c(i),u=c(oe),s=c(ae);u||(s=[]);var d=s.indexOf(e);a!==n&&-1===d&&s.push(e),t===n&&d>=0&&s.splice(d,1),s.length||(u=!1,f(oe),f(ae),c(se)&&(clearTimeout(c(se)),f(se))),!u&&s.length&&(l(ae,s),l(oe,!0),l(se,setTimeout(function(){if(f(ae),f(se),f(oe),!c(le)){var e=void 0;for(e=0;e<s.length;e++)r.emit("change:"+s[e],r,C.get(r,s[e]));r.emit("change",r,r.changes())}f(le)},0)))}(),l(i,n),n},r},pe={array:function(e,t,n){return X(Z,e,t,n)},integer:function(e,t,n){return pe.numeric(e,t,n)},number:function(e,t,n){return pe.numeric(e,t,n)},numeric:function(e,t,n){return X(ee,e,t,n)},object:function(e,t,n){return X(te,e,t,n)},string:function(e,t,n){return X(ne,e,t,n)}},he=t.extend({constructor:function e(t){t||(t={}),C.fillIn(this,t),t.properties&&C.forOwn(t.properties,function(n,r){n instanceof e||(t.properties[r]=new e(n))})},apply:function(e,t){t||(t={}),t.getter=t.getter||"_get",t.setter=t.setter||"_set",t.unsetter=t.unsetter||"_unset";var n=this.properties||{};C.forOwn(n,function(n,r){Object.defineProperty(e,r,de(r,n,t))})},validate:function(e,t){return ie(e,this,t)}},{typeGroupValidators:pe,types:Q,validate:ie,validationKeywords:W}),ve=function(){for(var e=arguments.length,t=Array(e),n=0;e>n;n++)t[n]=arguments[n];var r=this,i=t[t.length-1];r.dbg.apply(r,[i.op].concat(t)),(i.notify||void 0===i.notify&&r.notify)&&setTimeout(function(){r.emit.apply(r,[i.op].concat(t))})},ge=function(){for(var e=arguments.length,t=Array(e),n=0;e>n;n++)t[n]=arguments[n];var r=this,i=t[t.length-2];r.dbg.apply(r,[i.op].concat(t)),(i.notify||void 0===i.notify&&r.notify)&&setTimeout(function(){r.emit.apply(r,[i.op].concat(t))})},ye={applySchema:!0,debug:!1,defaultAdapter:"http",idAttribute:"id",lifecycleMethods:{count:{defaults:[{},{}],skip:!0,types:[]},destroy:{defaults:[{},{}],skip:!0,types:[]},destroyAll:{defaults:[{},{}],skip:!0,types:[]
},find:{defaults:[void 0,{}],types:[]},findAll:{defaults:[{},{}],types:[]},sum:{defaults:[void 0,{},{}],skip:!0,types:[]},update:{adapterArgs:function(e,t,n,r){return[t,e.toJSON(n,r),r]},beforeAssign:1,defaults:[void 0,{},{}],types:[]},updateAll:{adapterArgs:function(e,t,n,r){return[e.toJSON(t,r),n,r]},beforeAssign:0,defaults:[{},{},{}],types:[]},updateMany:{adapterArgs:function(e,t,n){return[t.map(function(t){return e.toJSON(t,n)}),n]},beforeAssign:0,defaults:[[],{}],types:[]}},name:null,notify:C.isBrowser,raw:!1,schema:null},me=t.extend({constructor:function e(t){var n=this;if(C.classCallCheck(n,e),e.__super__.call(n),t||(t={}),Object.defineProperty(n,"_adapters",{value:void 0,writable:!0}),Object.defineProperty(n,"_listeners",{value:{},writable:!0}),Object.defineProperty(n,"recordClass",{value:void 0,writable:!0}),C.fillIn(n,t),C.fillIn(n,C.copy(ye)),!n.name)throw new Error("mapper cannot function without a name!");n._adapters||(n._adapters={}),n.schema instanceof he||(n.schema=new he(n.schema||{})),C.isUndefined(n.recordClass)&&(n.recordClass=q.extend()),n.recordClass&&(n.recordClass.mapper=n,C.getSuper(n.recordClass,!0)===q&&n.schema&&n.schema.apply&&n.applySchema&&n.schema.apply(n.recordClass.prototype))},afterCount:ge,afterCreate:ge,afterCreateMany:ge,afterDestroy:ge,afterDestroyAll:ge,afterFind:ge,afterFindAll:ge,afterSum:ge,afterUpdate:ge,afterUpdateAll:ge,afterUpdateMany:ge,beforeCreate:ve,beforeCreateMany:ve,beforeCount:ve,beforeDestroy:ve,beforeDestroyAll:ve,beforeFind:ve,beforeFindAll:ve,beforeSum:ve,beforeUpdate:ve,beforeUpdateAll:ve,beforeUpdateMany:ve,_end:function(e,t,n){var r=this;if(t.raw&&C._(t,e),n)return e;var i=t.raw?e.data:e;return C.isArray(i)&&i.length&&C.isObject(i[0])?i=i.map(function(e){return r.createRecord(e)}):C.isObject(i)&&(i=r.createRecord(i)),t.raw?e.data=i:e=i,e},belongsTo:function(e,t){return U(e,t)(this)},count:function(e,t){return this.crud("count",e,t)},create:function(e,t){var n=void 0,r=void 0,i=this;return e||(e={}),t||(t={}),C._(i,t),r=t.adapter=i.getAdapterName(t),n=t.op="beforeCreate",C.resolve(i[n](e,t)).then(function(o){e=C.isUndefined(o)?e:o;var a={};t.with||(t.with=[]);var u=[];return C.forEachRelation(i,t,function(t,n){var r=t.getLocalField(e);t.type===P&&r&&u.push(t.getRelation().create(r,n).then(function(r){var i=n.raw?r.data:r;t.setLocalField(a,i),t.setForeignKey(e,i)}))}),C.Promise.all(u).then(function(){return n=t.op="create",i.dbg(n,e,t),C.resolve(i.getAdapter(r)[n](i,i.toJSON(e,{with:t.pass||[]}),t))}).then(function(n){var r=t.raw?n.data:n;return u=[],C.forEachRelation(i,t,function(n,i){var o=n.getLocalField(e);if(o){var s=void 0;n.type===L?(n.setForeignKey(r,o),s=n.getRelation().createMany(o,i).then(function(e){n.setLocalField(r,t.raw?e.data:e)})):n.type===K?(n.setForeignKey(r,o),s=n.getRelation().create(o,i).then(function(e){n.setLocalField(r,t.raw?e.data:e)})):n.type===P&&n.getLocalField(a)&&n.setLocalField(r,n.getLocalField(a)),s&&u.push(s)}}),C.Promise.all(u).then(function(){return n})})}).then(function(r){return r=i._end(r,t),n=t.op="afterCreate",C.resolve(i[n](e,t,r)).then(function(e){return C.isUndefined(e)?r:e})})},createInstance:function(e,t){return this.createRecord(e,t)},createMany:function(e,t){var n=void 0,r=void 0,i=this;return e||(e=[]),t||(t={}),C._(i,t),r=t.adapter=i.getAdapterName(t),n=t.op="beforeCreateMany",C.resolve(i[n](e,t)).then(function(o){e=C.isUndefined(o)?e:o;var a={};t.with||(t.with=[]);var u=[];return C.forEachRelation(i,t,function(t,n){var r=e.map(function(e){return t.getLocalField(e)}).filter(function(e){return e});t.type===P&&r.length===e.length&&u.push(t.getRelation().createMany(r,n).then(function(r){var i=n.raw?r.data:r;t.setLocalField(a,i),e.forEach(function(e,n){t.setForeignKey(e,i[n])})}))}),C.Promise.all(u).then(function(){n=t.op="createMany";var o=e.map(function(e){return i.toJSON(e,{with:t.pass||[]})});return i.dbg(n,e,t),C.resolve(i.getAdapter(r)[n](i,o,t))}).then(function(n){var r=t.raw?n.data:n;return u=[],C.forEachRelation(i,t,function(n,o){var s=e.map(function(e){return n.getLocalField(e)}).filter(function(e){return e});if(s.length===e.length){var c=n.getLocalField(a),l=void 0;n.type===L?i.log("warn","deep createMany of hasMany type not supported!"):n.type===K?(r.forEach(function(e,t){n.setForeignKey(e,s[t])}),l=n.getRelation().createMany(s,o).then(function(e){var i=t.raw?e.data:e;r.forEach(function(e,t){n.setLocalField(e,i[t])})})):n.type===P&&c&&c.length===r.length&&r.forEach(function(e,t){n.setLocalField(e,c[t])}),l&&u.push(l)}}),C.Promise.all(u).then(function(){return n})})}).then(function(r){return r=i._end(r,t),n=t.op="afterCreateMany",C.resolve(i[n](e,t,r)).then(function(e){return C.isUndefined(e)?r:e})})},createRecord:function(e,t){var n=this,r=n.recordClass,i=n.relationList||[];return i.forEach(function(t){var n=t.getRelation(),r=t.getLocalField(e);C.isArray(r)&&r.length&&!n.is(r[0])?t.setLocalField(e,r.map(function(e){return t.getRelation().createRecord(e)})):C.isObject(r)&&!n.is(r)&&t.setLocalField(e,t.getRelation().createRecord(r))}),r?e instanceof r?e:new r(e,t):e},crud:function(e){for(var t=arguments.length,n=Array(t>1?t-1:0),r=1;t>r;r++)n[r-1]=arguments[r];var i=this,o=i.lifecycleMethods[e];if(!o)throw new Error(e+": No such CRUD method!");var a=""+e.charAt(0).toUpperCase()+e.substr(1),u="before"+a,c="after"+a,l=void 0,f=void 0;o.defaults.forEach(function(e,t){C.isUndefined(n[t])&&(n[t]=C.copy(e))});var d=n[n.length-1];return C._(i,d),f=d.adapter=i.getAdapterName(d),l=d.op=u,C.resolve(i[l].apply(i,s.toConsumableArray(n))).then(function(t){var r;return C.isUndefined(o.beforeAssign)||(n[o.beforeAssign]=C.isUndefined(t)?n[o.beforeAssign]:t),l=d.op=e,n=o.adapterArgs?o.adapterArgs.apply(o,[i].concat(s.toConsumableArray(n))):n,i.dbg.apply(i,[l].concat(s.toConsumableArray(n))),C.resolve((r=i.getAdapter(f))[l].apply(r,[i].concat(s.toConsumableArray(n))))}).then(function(e){return e=i._end(e,d,!!o.skip),n.push(e),l=d.op=c,C.resolve(i[l].apply(i,s.toConsumableArray(n))).then(function(t){return C.isUndefined(t)?e:t})})},destroy:function(e,t){return this.crud("destroy",e,t)},destroyAll:function(e,t){return this.crud("destroyAll",e,t)},find:function(e,t){return this.crud("find",e,t)},findAll:function(e,t){return this.crud("findAll",e,t)},getAdapter:function(e){var t=this;t.dbg("getAdapter","name:",e);var n=t.getAdapterName(e);if(!n)throw new ReferenceError(n+" not found!");return t.getAdapters()[n]},getAdapterName:function(e){return e||(e={}),C.isString(e)&&(e={adapter:e}),e.adapter||e.defaultAdapter},getAdapters:function(){return this._adapters},getSchema:function(){return this.schema},hasMany:function(e,t){return T(e,t)(this)},hasOne:function(e,t){return D(e,t)(this)},is:function(e){var t=this.recordClass;return t?e instanceof t:!1},registerAdapter:function(e,t,n){var r=this;n||(n={}),r.getAdapters()[e]=t,(n===!0||n.default)&&(r.defaultAdapter=e)},sum:function(e,t,n){return this.crud("sum",e,t,n)},toJSON:function(e,t){var n=this;t||(t={});var r=(n?n.relationFields:[])||[],i={},o=void 0;return n&&n.schema&&(o=n.schema.properties||{},C.forOwn(o,function(t,n){i[n]=C.plainCopy(e[n])})),o||(o={}),t.strict||C.forOwn(e,function(e,t){o[t]||-1!==r.indexOf(t)||(i[t]=C.plainCopy(e))}),n&&t.withAll&&(t.with=r.slice()),n&&t.with&&(C.isString(t.with)&&(t.with=[t.with]),C.forEachRelation(n,t,function(t,n){var r=t.getLocalField(e);r&&(C.isArray(r)?t.setLocalField(i,r.map(function(e){return t.getRelation().toJSON(e,n)})):t.setLocalField(i,t.getRelation().toJSON(r,n)))})),i},update:function(e,t,n){return this.crud("update",e,t,n)},updateAll:function(e,t,n){return this.crud("updateAll",e,t,n)},updateMany:function(e,t){return this.crud("updateMany",e,t)},validate:function(e,t){var n=this;if(!n.getSchema())throw new Error("no schema!");if(C.isArray(e))return e.map(function(e){return n.schema.validate(e,t)});if(C.isObject(e))return n.schema.validate(e,t);throw new Error("not a record!")}}),be=["count","create","createMany","createRecord","dbg","destroy","destroyAll","find","findAll","getSchema","is","log","sum","toJSON","update","updateAll","updateMany"],we={constructor:function e(t){var n=this;C.classCallCheck(n,e),e.__super__.call(n),t||(t={}),C.fillIn(n,t),n.mapperDefaults=n.mapperDefaults||{},n.mapperClass=n.mapperClass||me,n._adapters={},n._mappers={}},_onMapperEvent:function(e){for(var t=arguments.length,n=Array(t>1?t-1:0),r=1;t>r;r++)n[r-1]=arguments[r];var i=n.shift();this.emit.apply(this,[i,e].concat(n))},defineMapper:function(e,t){var n=this;if(C.isObject(e)){if(t=e,!t.name)throw new Error("name is required!");e=t.name}else if(!C.isString(e))throw new Error("name is required!");t||(t={}),t.name=e,t.relations||(t.relations={});var r=t.mapperClass||n.mapperClass;delete t.mapperClass,C.fillIn(t,n.mapperDefaults);var i=n._mappers[e]=new r(t);return i.name=e,i._adapters=n.getAdapters(),i.on("all",function(){for(var t=arguments.length,r=Array(t),i=0;t>i;i++)r[i]=arguments[i];n._onMapperEvent.apply(n,[e].concat(r))}),C.forOwn(i.relations,function(e,t){C.forOwn(e,function(e,r){C.isObject(e)&&(e=[e]),e.forEach(function(e){e.getRelation=function(){return n.getMapper(r)};var o=n._mappers[r]||r;t===P?i.belongsTo(o,e):t===K?i.hasOne(o,e):t===L&&i.hasMany(o,e)})})}),i},defineResource:function(e,t){return this.defineMapper(e,t)},getAdapter:function(e){var t=this,n=t.getAdapterName(e);if(!n)throw new ReferenceError(n+" not found!");return t.getAdapters()[n]},getAdapterName:function(e){return e||(e={}),C.isString(e)&&(e={adapter:e}),e.adapter||this.mapperDefaults.defaultAdapter},getAdapters:function(){return this._adapters},getMapper:function(e){var t=this._mappers[e];if(!t)throw new ReferenceError(e+" is not a registered mapper!");return t},registerAdapter:function(e,t,n){var r=this;n||(n={}),r.getAdapters()[e]=t,(n===!0||n.default)&&(r.mapperDefaults.defaultAdapter=e,C.forOwn(r._mappers,function(t){t.defaultAdapter=e}))}};be.forEach(function(e){we[e]=function(t){for(var n,r=arguments.length,i=Array(r>1?r-1:0),o=1;r>o;o++)i[o-1]=arguments[o];return(n=this.getMapper(t))[e].apply(n,i)}});var Ae=t.extend(we),_e=M.extend({constructor:function e(t,n){var r=this;if(C.classCallCheck(r,e),e.__super__.call(r,t,n),r._added={},!r.datastore)throw new Error("This collection must have a datastore!");return r},_onRecordEvent:function(){for(var e=this,t=arguments.length,n=Array(t),r=0;t>r;r++)n[r]=arguments[r];C.getSuper(e).prototype._onRecordEvent.apply(e,n);var i=n[0];C.isString(i)&&0===i.indexOf("change")&&e.updateIndexes(n[1])},add:function(e,t){var n=this,r=n.datastore,i=n.mapper,o=i.relationList||[],a=(new Date).getTime(),u=!!i.recordClass,s=void 0;return C.isObject(e)&&!C.isArray(e)&&(s=!0,e=[e]),o.length&&e.length&&i.relationList.forEach(function(t){var n=t.relation,i=r.getMapper(n),o=i.idAttribute,a=t.foreignKey,u=r.getCollection(n),s=t.type,c=s===L,l=C.isUndefined(t.add)?!0:!!t.add,f=void 0;e.forEach(function(e){if(f=t.getLocalField(e),C.isFunction(t.add))t.add(r,t,e);else if(f){if(c)f=f.map(function(n){return n!==u.get(u.recordId(n))&&(a&&t.setForeignKey(e,n),l&&(n=u.add(n))),n}),t.localKeys&&C.set(e,t.localKeys,f.map(function(e){return C.get(e,o)}));else{var n=C.get(f,o);f!==u.get(n)&&(t.setForeignKey(e,f),l&&(f=u.add(f)))}t.setLocalField(e,f)}})}),e=C.getSuper(n).prototype.add.call(n,e,t),e.forEach(function(e){n._added[n.recordId(e)]=a,u&&e._set("$",a)}),s?e[0]:e},remove:function(e,t){var n=this,r=n.mapper,i=C.getSuper(n).prototype.remove.call(n,e,t);return i&&(delete n._added[e],r.recordClass&&i._set("$")),i},removeAll:function(e,t){var n=this,r=n.mapper,i=C.getSuper(n).prototype.removeAll.call(n,e,t);return i.forEach(function(e){delete n._added[n.recordId(e)],r.recordClass&&e._set("$")}),i}}),Oe={linkRelations:C.isBrowser},xe={constructor:function e(t){var n=this;return C.classCallCheck(n,e),e.__super__.call(n,t),n.collectionClass=n.collectionClass||_e,n._collections={},C.fillIn(n,Oe),n._pendingQueries={},n._completedQueries={},n},_callSuper:function(e){for(var t=arguments.length,n=Array(t>1?t-1:0),r=1;t>r;r++)n[r-1]=arguments[r];return this.constructor.__super__.prototype[e].apply(this,n)},_end:function(e,t,n){return n.raw?(t.data=this.getCollection(e).add(t.data,n),t):t=this.getCollection(e).add(t,n)},_onCollectionEvent:function(e){for(var t=arguments.length,n=Array(t>1?t-1:0),r=1;t>r;r++)n[r-1]=arguments[r];var i=n.shift();this.emit.apply(this,[i,e].concat(n))},cachedFind:function(e,t,n){return this.get(e,t,n)},cachedFindAll:function(e,t,n){var r=this;return r._completedQueries[e][r.hashQuery(e,t,n)]?r.filter(e,t,n):void 0},create:function(e,t,n){var r=this;return n||(n={}),r._callSuper("create",e,t,n).then(function(t){return r._end(e,t,n)})},createMany:function(e,t,n){var r=this;return n||(n={}),r._callSuper("createMany",e,t,n).then(function(t){return r._end(e,t,n)})},defineMapper:function(e,t){var n=this,r=C.getSuper(n).prototype.defineMapper.call(n,e,t);n._pendingQueries[e]={},n._completedQueries[e]={},r.relationList||Object.defineProperty(r,"relationList",{value:[]});var i=n._collections[e]=new n.collectionClass(null,{_added:{},datastore:n,mapper:r}),o=r.schema||{},a=o.properties||{};C.forOwn(a,function(e,t){e.indexed&&i.createIndex(t)}),i.createIndex("addedTimestamps",["$"],{fieldGetter:function(e){return i._added[i.recordId(e)]}}),i.on("all",function(){for(var t=arguments.length,r=Array(t),i=0;t>i;i++)r[i]=arguments[i];n._onCollectionEvent.apply(n,[e].concat(r))});var u=n.linkRelations;return u&&r.relationList.forEach(function(e){var t=e.relation,o=e.localField,a="links."+o,s=e.foreignKey,c=e.type,l=C.isUndefined(e.link)?u:e.link,f={index:s},d=void 0;c===P?(i.indexes[s]||i.createIndex(s),d={get:function(){var r=this;if(!r._get("$")||!l)return r._get(a);var i=e.getForeignKey(r),o=C.isUndefined(i)?void 0:n.getCollection(t).get(i);return r._set(a,o),o},set:function(t){var n=this;return n._set(a,t),e.setForeignKey(n,t),i.updateIndex(n,f),e.getLocalField(n)}}):c===L?!function(){var r=e.localKeys,o=e.foreignKeys;n._collections[t]&&s&&!n.getCollection(t).indexes[s]&&n.getCollection(t).createIndex(s),d={get:function(){var i=this;if(!i._get("$")||!l)return i._get(a);var u=e.getForeignKey(i),c=void 0,f=n.getCollection(t);if(s)c=f.getAll(u,{index:s});else if(r){var d=C.get(i,r)||[],p=C.isArray(d)?d:Object.keys(d);c=f.getAll.apply(f,p)}else if(o){var h={};C.set(h,"where."+o+".contains",u),c=f.filter(h)}return i._set(a,c),c},set:function(u){var c=this,l=i.recordId(c),d=n.getCollection(t);return c._set(a,u),s&&(e.setForeignKey(c,u),C.isArray(u)&&u.forEach(function(e){d.updateIndex(e,f)})),r?C.set(c,r,u.map(function(e){return d.recordId(e)})):o&&u.forEach(function(e){var t=C.get(e,o);t?-1===t.indexOf(l)&&t.push(l):C.set(e,o,[l])}),e.getLocalField(c)}}}():c===K&&(d={get:function(){var r=this;if(!r._get("$")||!l)return r._get(a);var i=e.getForeignKey(r),o=n.getCollection(t).getAll(i,{index:s}),u=o.length?o[0]:void 0;return r._set(a,u),u},set:function(r){var i=this;return i._set(a,r),e.setForeignKey(i,r),n.getCollection(t).updateIndex(r,f),e.getLocalField(i)}}),d&&(d.enumerable=C.isUndefined(e.enumerable)?!0:e.enumerable,e.get&&!function(){var t=d.get;d.get=function(){var n=this;return e.get(e,this,function(){for(var e=arguments.length,r=Array(e),i=0;e>i;i++)r[i]=arguments[i];return t.apply(n,r)})}}(),e.set&&!function(){var t=d.set;d.set=function(n){var r=this;return e.set(e,this,n,function(e){return t.call(r,void 0===e?n:e)})}}(),Object.defineProperty(r.recordClass.prototype,o,d))}),r},destroy:function(e,t,n){var r=this;return n||(n={}),r._callSuper("destroy",e,t,n).then(function(i){return n.raw?i.data=r.getCollection(e).remove(t,n):i=r.getCollection(e).remove(t,n),delete r._pendingQueries[e][t],delete r._completedQueries[e][t],i})},destroyAll:function(e,t,n){var r=this;return n||(n={}),r._callSuper("destroyAll",e,t,n).then(function(i){n.raw?i.data=r.getCollection(e).removeAll(t,n):i=r.getCollection(e).removeAll(t,n);var o=r.hashQuery(e,t,n);return delete r._pendingQueries[e][o],delete r._completedQueries[e][o],i})},eject:function(e,t){return this.remove(e,t)},ejectAll:function(e,t){return this.removeAll(e,t)},find:function(e,t,n){var r=this;n||(n={});var i=r._pendingQueries[e][t];if(C.fillIn(n,r.getMapper(e)),i)return i;var o=r.cachedFind(e,t,n),a=void 0;return a=n.force||!o?r._pendingQueries[e][t]=r._callSuper("find",e,t,n).then(function(i){return delete r._pendingQueries[e][t],r._end(e,i,n)},function(n){return delete r._pendingQueries[e][t],C.reject(n)}).then(function(n){return r._completedQueries[e][t]=(new Date).getTime(),n}):C.resolve(o)},findAll:function(e,t,n){var r=this;n||(n={});var i=r.hashQuery(e,t,n),o=r._pendingQueries[e][i];if(C.fillIn(n,r.getMapper(e)),o)return o;var a=r.cachedFindAll(e,t,n),u=void 0;return u=n.force||!a?r._pendingQueries[e][i]=r._callSuper("findAll",e,t,n).then(function(t){return delete r._pendingQueries[e][i],r._end(e,t,n)},function(t){return delete r._pendingQueries[e][i],C.reject(t)}).then(function(t){return r._completedQueries[e][i]=(new Date).getTime(),t}):C.resolve(a)},getCollection:function(e){var t=this._collections[e];if(!t)throw new ReferenceError(e+" is not a registered collection!");return t},hashQuery:function(e,t,n){return C.toJson(t)},inject:function(e,t){return this.add(e,t)},remove:function(e,t,n){var r=this,i=r.getCollection(e).remove(t,n);return i&&r.removeRelated(e,[i],n),i},removeAll:function(e,t,n){var r=this,i=r.getCollection(e).removeAll(t,n);return i.length&&r.removeRelated(e,i,n),i},removeRelated:function(e,t,n){var r=this;C.forEachRelation(r.getMapper(e),n,function(e,n){t.forEach(function(t){var i=void 0,o=void 0;if(!e.foreignKey||"hasOne"!==e.type&&"hasMany"!==e.type?"hasMany"===e.type&&e.localKeys?o={where:s.defineProperty({},e.getRelation().idAttribute,{in:C.get(t,e.localKeys)})}:"hasMany"===e.type&&e.foreignKeys?o={where:s.defineProperty({},e.foreignKeys,{contains:e.getForeignKey(t)})}:"belongsTo"===e.type&&(i=r.remove(e.relation,e.getForeignKey(t),n)):o=s.defineProperty({},e.foreignKey,e.getForeignKey(t)),o&&(i=r.removeAll(e.relation,o,n)),i){if(C.isArray(i)&&!i.length)return;"hasOne"===e.type&&(i=i[0]),e.setLocalField(t,i)}})})},update:function(e,t,n,r){var i=this;return r||(r={}),i._callSuper("update",e,t,n,r).then(function(t){return i._end(e,t,r)})},updateAll:function(e,t,n,r){var i=this;return r||(r={}),i._callSuper("updateAll",e,n,t,r).then(function(t){return i._end(e,t,r)})},updateMany:function(e,t,n){var r=this;return n||(n={}),r._callSuper("updateMany",e,t,n).then(function(t){return r._end(e,t,n)})}},Ce=["add","between","createIndex","filter","get","getAll","query","toJson"];Ce.forEach(function(e){xe[e]=function(t){for(var n,r=arguments.length,i=Array(r>1?r-1:0),o=1;r>o;o++)i[o-1]=arguments[o];return(n=this.getCollection(t))[e].apply(n,i)}});var Ee=Ae.extend(xe),Re={alpha:"22",beta:"false",full:"3.0.0-alpha.22",major:parseInt("3",10),minor:parseInt("0",10),patch:parseInt("0",10)};e.version=Re,e.Collection=M,e.Component=t,e.Container=Ae,e.DataStore=Ee,e.LinkedCollection=_e,e.Mapper=me,e.Query=S,e.Record=q,e.Schema=he,e.utils=C,e.belongsToType=P,e.hasManyType=L,e.hasOneType=K,e.belongsTo=U,e.hasMany=T,e.hasOne=D});
//# sourceMappingURL=js-data.min.map
{
"name": "js-data",
"description": "Robust, framework-agnostic in-memory data store.",
"version": "3.0.0-alpha.21",
"version": "3.0.0-alpha.22",
"homepage": "http://www.js-data.io",

@@ -27,20 +27,10 @@ "repository": {

],
"standard": {
"parser": "babel-eslint",
"globals": [
"describe",
"it",
"sinon",
"before",
"after",
"beforeEach",
"afterEach"
]
},
"standard": { "parser": "babel-eslint" },
"babel": { "presets": ["es2015-rollup"] },
"ava": { "files": ["test/**/*.test.js"] },
"scripts": {
"rollup-tests": "rollup -c rollup-tests.config.js",
"doc": "jsdoc -c conf.json src && node scripts/cleanup.js",
"lint": "repo-tools lint src/**/*.js test/**/*.js scripts/*.js lib/**/*.js",
"bundle": "rollup -c",
"bundle2": "rollup -c rollup-es2015.config.js",
"bundle": "rollup -c -o dist/js-data.js -m dist/js-data.js.map -f umd",
"bundle:next": "rollup -c -o dist/js-data.es2015.js -m dist/js-data.es2015.js.map -f es6",
"min": "uglifyjs dist/js-data.js -o dist/js-data.min.js --source-map dist/js-data.min.map --source-map-url js-data.min.map -v -m -c --screw-ie8",

@@ -50,34 +40,26 @@ "version": "node scripts/version.js",

"gzip": "echo gzipped size: $(cat dist/js-data.min.js | gzip -f9 | wc -c)kb",
"build": "npm run lint && npm run bundle && npm run bundle2 && npm run min && npm run version && npm run banner",
"karma": "karma start",
"mocha": "mocha -t 20000 -R spec -r source-map-support/register mocha.start.js",
"r": "npm run bundle && npm run mocha",
"t": "npm run rollup-tests && npm run mocha",
"rt": "npm run bundle && npm run rollup-tests && npm run mocha",
"cover": "istanbul cover -x dist/js-data-tests.js --hook-run-in-context node_modules/mocha/bin/_mocha -- -t 20000 -R dot -r source-map-support/register mocha.start.js",
"test": "npm run build && npm run rollup-tests && npm run cover",
"build": "npm run bundle && npm run min && npm run version && npm run banner",
"ava": "ava",
"r": "npm run bundle && ava",
"cover": "nyc ava",
"report-html": "nyc report --reporter=html",
"test": "npm run lint && npm run build && npm run cover",
"repo-tools": "repo-tools updates && repo-tools changelog && repo-tools authors",
"release": "npm test && npm run doc && npm run repo-tools",
"ci": "npm test && cat coverage/lcov.info | coveralls || true"
"release": "npm test && npm run bundle:next && npm run doc && npm run repo-tools",
"ci": "npm test && nyc report --reporter=text-lcov | ./node_modules/.bin/coveralls || true"
},
"devDependencies": {
"ava": "0.13.0",
"babel-core": "6.7.4",
"babel-plugin-syntax-async-functions": "6.5.0",
"babel-plugin-transform-regenerator": "6.6.5",
"babel-polyfill": "6.7.4",
"babel-preset-es2015-rollup": "1.1.1",
"babel-preset-stage-0": "6.5.0",
"chai": "3.5.0",
"coveralls": "2.11.8",
"coveralls": "2.11.9",
"ink-docstrap": "1.1.4",
"istanbul": "0.4.2",
"js-data-repo-tools": "0.2.0",
"jsdoc": "3.4.0",
"mocha": "2.4.5",
"rollup": "0.25.5",
"nyc": "6.1.1",
"rollup": "0.25.7",
"rollup-plugin-babel": "2.4.0",
"sinon": "1.17.3",
"source-map-support": "0.4.0",
"uglify-js": "2.6.2"
}
}

@@ -25,179 +25,26 @@ <img src="https://raw.githubusercontent.com/js-data/js-data/master/js-data.png" alt="js-data logo" title="js-data" align="right" width="96" height="96" />

js-data is a framework-agnostic, datastore-agnostic ORM/ODM for Node.js and the
JSData is a framework-agnostic, datastore-agnostic ORM/ODM for Node.js and the
Browser.
Adapters allow js-data to connect to various data sources such as Firebase,
MySql, RethinkDB, MongoDB, localStorage, Redis, a REST API, etc. With js-data
Adapters allow JSData to connect to various data sources such as Firebase,
MySql, RethinkDB, MongoDB, localStorage, Redis, a REST API, etc. With JSData
you can re-use your data modeling code between environments, keep your data
layer intact when transitioning between app frameworks, and work with a unified
data API on the server and the client. js-data employs conventions for rapid
data API on the server and the client. JSData employs conventions for rapid
development, but allows for endless customization in order to meet your
particular needs.
To get started, visit __[http://js-data.io](http://www.js-data.io)__.
To get started, visit the main website at __[http://js-data.io](http://www.js-data.io/v3.0/docs/home)__.
## Table of contents
## Links
* [Quick start](#quick-start)
* [Background](#background)
* [Dependencies](#dependencies)
* [Guides and Tutorials](#guides-and-tutorials)
* [API Reference Docs](#api-reference-docs)
* [Community](#community)
* [Support](#support)
* [Contributing](#contributing)
* [License](#license)
* [Quick start](http://www.js-data.io/v3.0/docs/home#quick-start)
* [Background](http://www.js-data.io/v3.0/docs/home#background)
* [Dependencies](http://www.js-data.io/v3.0/docs/home#dependencies)
* [Guides and Tutorials](http://www.js-data.io/v3.0/docs/home)
* [API Reference Docs](http://api.js-data.io)
* [Community](http://js-data.io/docs/community)
* [Support](http://js-data.io/docs/support)
* [Contributing](http://js-data.io/docs/contributing)
## Quick Start
This example shows setting up js-data to use the Http adapter in the browser:
```
npm i --save js-data js-data-http
```
See [installation instructions](http://js-data.io/docs/installation) for more
information.
```javascript
import {DataStore} from 'js-data'
import HttpAdapter from 'js-data-http'
// Create an empty data store
const store = new DataStore()
// "store" will use an http adapter by default
store.registerAdapter('http', new HttpAdapter(), { 'default': true })
// Define a Mapper for a "user" resource
store.defineMapper('user')
```
```js
// GET /user/1
let user = await store.find('user', 1)
console.log(user) // { id: 1, name: 'John' }
// The user record is now stored in Users
console.log(store.get('user', user.id)) // { id: 1, name: 'John' }
console.log(user === store.get('user', user.id)) // true
// PUT /user/1 {name:"Johnny"}
user = await store.update('user', user.id, { name: 'Johnny' })
// The user record has been updated, and the change synced to the store
console.log(store.get('user', user.id)) // { id: 1, name: 'Johnny' }
console.log(user === store.get('user', user.id)) // true
// DELETE /user/1
await store.destroy('user', user.id)
// The user instance no longer in the store
console.log(store.get('user', 1)) // undefined
```
__ES5:__
```javascript
// Create an empty data store
var store = new JSData.DataStore()
// "store" will use an http adapter by default
store.registerAdapter('http', new HttpAdapter(), { default: true })
// Define a Mapper for a "user" resource
store.defineMapper('user')
// GET /user/1
store.find('user', 1)
.then(function (user) {
console.log(user) // { id: 1, name: 'John' }
// The user record is now stored in Users
console.log(store.get('user', user.id)) // { id: 1, name: 'John' }
console.log(user === store.get('user', user.id)) // true
// PUT /user/1 {name:"Johnny"}
return await store.update('user', user.id, { name: 'Johnny' })
})
.then(function (user) {
// The user record has been updated, and the change synced to the store
console.log(store.get('user', user.id)) // { id: 1, name: 'Johnny' }
console.log(user === store.get('user', user.id)) // true
// DELETE /user/1
return store.destroy('user', user.id)
})
.then(function () {
// The user instance no longer in the store
console.log(store.get('user', 1)) // undefined
})
```
## Background
Most ORMs/ODMs only work with a single datastore, and most JavaScript ORMs only
work in Node.js _or_ the Browser. Wouldn't it be nice if you could use the same
ORM/ODM on the client as you do on the backend? Wouldn't it be nice if you could
switch databases without having to switch out your data layer code? Enter
__js-data__.
Originally inspired by the desire to have something like [Ember Data][1] that
worked in Angular.js and other frameworks, js-data was created. Turns out,
js-data works in Node.js, so server-side adapters were written. js-data is the
Model layer you've been craving. It consists of a convenient
__framework-agnostic__, __datastore-agnostic__ ORM for managing your data, which
uses __adapters__ to connect to various __persistence layers__.
The most commonly used adapter is the [http adapter][2], which is perfect for
connecting your frontend to your backend. [localStorage][3], [localForage][4],
[Firebase][5] and [other adapters][6] are available for the browser. On the
server you could hook up to the [SQL adapter (Postgres/MySQL/MariaDB/SQLite3)][7]
or the [MongoDB][8] adapter. More adapters are coming, and you're free to
implement your own. See [Adapters][6].
[![MtnWestJS Conf 2015 Presentation][9]][10]
[1]: https://github.com/emberjs/data
[2]: https://github.com/js-data/js-data-http
[3]: https://github.com/js-data/js-data-localstorage
[4]: https://github.com/js-data/js-data-localforage
[5]: https://github.com/js-data/js-data-firebase
[6]: http://js-data.io/docs/adapters
[7]: https://github.com/js-data/js-data-sql
[8]: https://github.com/js-data/js-data-mongodb
[9]: http://img.youtube.com/vi/8wxnnJA9FKw/0.jpg
[10]: https://www.youtube.com/watch?v=8wxnnJA9FKw
## Dependencies
js-data and its adapters depend on a global ES2015 `Promise` constructor. In
the browser, `window.Promise` must be available. In Node.js, `global.Promise`
must be available. Here is a handy [ES2015 Promise polyfill](https://github.com/jakearchibald/es6-promise)
if you need it.
js-data and its adapters require full ES5 support from the runtime. Here is a
handy [ES5 polyfill](https://github.com/afarkas/html5shiv) if you need it.
## Guides and Tutorials
[Get started at http://js-data.io](http://js-data.io)
## API Reference Docs
[Visit http://api.js-data.io](http://api.js-data.io).
## Community
[Explore the Community](http://js-data.io/docs/community).
## Support
[Find out how to Get Support](http://js-data.io/docs/support).
## Contributing
[Read the Contributing Guide](http://js-data.io/docs/contributing).
## License

@@ -204,0 +51,0 @@

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc