Comparing version 3.0.0-beta.4 to 3.0.0-beta.5
@@ -0,1 +1,9 @@ | ||
##### 3.0.0-beta.5 - 07 May 2016 | ||
###### Backwards compatible changes | ||
- Pulled in mindex updates | ||
###### Bug fixes | ||
- #327 - Issues with inheritance using babel and ES6 classes | ||
##### 3.0.0-beta.4 - 06 May 2016 | ||
@@ -2,0 +10,0 @@ |
/*! | ||
* js-data | ||
* @version 3.0.0-beta.4 - Homepage <http://www.js-data.io/> | ||
* @version 3.0.0-beta.5 - 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(){Object.defineProperty(this,"_listeners",{value:{}})}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(j.classCallCheck(this,a),e||(e=[]),!j.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,r="new "+q;t||(t={});var i=t.localField;if(!i)throw j.err(r,"opts.localField")(400,"string",i);var o=t.foreignKey=t.foreignKey||t.localKey;if(!o&&(t.type===D||t.type===J))throw j.err(r,"opts.foreignKey")(400,"string",o);var a=t.localKeys,u=t.foreignKeys;if(!o&&!a&&!u&&t.type===T)throw j.err(r,"opts.<foreignKey|localKeys|foreignKeys>")(400,"string",o);if(j.isString(e)){if(t.relation=e,!j.isFunction(t.getRelation))throw j.err(r,"opts.getRelation")(400,"function",t.getRelation)}else{if(!e)throw j.err(r,"related")(400,"Mapper or string",e);t.relation=e.name,Object.defineProperty(n,"relatedMapper",{value:e})}Object.defineProperty(n,"inverse",{value:void 0,writable:!0}),j.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="utils",l=1/0,f=1.7976931348623157e308,d="[object Boolean]",p="[object Date]",h="[object Function]",v="[object Number]",g="[object Object]",y="[object RegExp]",m="[object String]",b=Object.prototype.toString,A=/^(.+)\.(.+)$/,_={400:function(){return"expected: "+arguments[0]+", found: "+(arguments[2]?arguments[1]:s.typeof(arguments[1]))},404:function(){return arguments[0]+" not found"}},w=function(e){if(!e)return 0;if(e=+e,e===l||e===-l){var t=0>e?-1:1;return t*f}var n=e%1;return e===e?n?e-n:e:0},O=function(e){return b.call(e)},x=function(e){return!!e&&"object"===("undefined"==typeof e?"undefined":s.typeof(e))&&e.constructor===Object},C=function(e,t){if(!t)return e;var n=t.split(".");return n.forEach(function(t){e[t]||(e[t]={}),e=e[t]}),e},I={Promise:Promise,_:function(e,t){I.forOwn(t,function(t,n){n&&I.isUndefined(e[n])&&!I.isFunction(t)&&0!==n.indexOf("_")&&(e[n]=t)})},_forRelation:function(e,t,n,r){var i=t.relation,o=null,a=void 0;if(e||(e={}),e.with||(e.with=[]),(a=I._getIndex(e.with,i))>=0?o=i:(a=I._getIndex(e.with,t.localField))>=0&&(o=t.localField),e.withAll)return void n.call(r,t,{});if(o){var u={};I.fillIn(u,t.getRelation()),I.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):I.isObject(e)&&e.relation===t?(n=r,!1):void 0}),n},addHiddenPropsToTarget:function(e,t){var n={};I.forOwn(t,function(e,t){n[t]={writable:!0,value:e}}),Object.defineProperties(e,n)},areDifferent:function(e,t,n){n||(n={});var r=I.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 I.err(""+t.name)(500,"Cannot call a class as a function")},copy:function(e,t,n,r,i,o){if(t){if(e===t)throw I.err(c+".copy")(500,"Cannot copy! Source and destination are identical.");if(n=n||[],r=r||[],I.isObject(e)){var a=n.indexOf(e);if(-1!==a)return r[a];n.push(e),r.push(t)}var u=void 0;if(I.isArray(e)){var s=void 0;for(t.length=0,s=0;s<e.length;s++)u=I.copy(e[s],null,n,r,i,o),I.isObject(e[s])&&(n.push(e[s]),r.push(u)),t.push(u)}else{I.isArray(t)?t.length=0:I.forOwn(t,function(e,n){delete t[n]});for(var l in e)if(e.hasOwnProperty(l)){if(I.isBlacklisted(l,i))continue;u=I.copy(e[l],null,n,r,i,o),I.isObject(e[l])&&(n.push(e[l]),r.push(u)),t[l]=u}}}else t=e,e&&(I.isArray(e)?t=I.copy(e,[],n,r,i,o):I.isDate(e)?t=new Date(e.getTime()):I.isRegExp(e)?(t=new RegExp(e.source,e.toString().match(/[^\/]*$/)[0]),t.lastIndex=e.lastIndex):I.isObject(e)&&(t=o?I.copy(e,{},n,r,i,o):I.copy(e,Object.create(Object.getPrototypeOf(e)),n,r,i,o)));return t},deepFillIn:function(e,t){return t&&I.forOwn(t,function(t,n){var r=e[n];x(t)&&x(r)?I.deepFillIn(r,t):e.hasOwnProperty(n)&&void 0!==e[n]||(e[n]=t)}),e},deepMixIn:function(e,t){return t&&I.forOwn(t,function(t,n){var r=e[n];x(t)&&x(r)?I.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 I.isFunction(r)||(r=I.strictEqual),I.forOwn(t,function(t,n){var a=e[n];I.isBlacklisted(n,i)||r(a,t)||(I.isUndefined(a)?o.removed[n]=void 0:r(a,t)||(o.changed[n]=a))}),I.forOwn(e,function(e,n){I.isUndefined(t[n])&&!I.isBlacklisted(n,i)&&(o.added[n]=e)}),o},equal:function(e,t){return e==t},err:function(e,t){return function(n){var r="["+e+":"+t+"] ",i=_[n].apply(null,Array.prototype.slice.call(arguments,1));return i=""+r+i+"\nhttp://www.js-data.io/v3.0/docs/errors#"+n,new Error(i)}},eventify:function(e,t,n){e=e||this;var r={};t||n||(t=function(){return r},n=function(e){r=e}),Object.defineProperties(e,{emit:{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:{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:{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(){I.classCallCheck(this,r);for(var e=arguments.length,t=Array(e),i=0;e>i;i++)t[i]=arguments[i];n.apply(this,t)},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:I.forOwn(n,function(e,t){r[t]=e}),Object.defineProperty(r,"__super__",{configurable:!0,value:n}),I.addHiddenPropsToTarget(r.prototype,e),I.fillIn(r,t),r},fillIn:function(e,t){return I.forOwn(t,function(t,n){e.hasOwnProperty(n)&&void 0!==e[n]||(e[n]=t)}),e},findIndex:function(e,t){var n=-1;return e?(e.forEach(function(e,r){return t(e)?(n=r,!1):void 0}),n):n},forEachRelation:function(e,t,n,r){var i=e.relationList||[];i.length&&i.forEach(function(e){I._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 I.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(O(t[r])===y&&t[r].test(e)||t[r]===e)return n=e;return!!n},isBoolean:function(e){return O(e)===d},isBrowser:!1,isDate:function(e){return e&&"object"===("undefined"==typeof e?"undefined":s.typeof(e))&&O(e)===p},isFunction:function(e){return"function"==typeof e||e&&O(e)===h},isInteger:function(e){return O(e)===v&&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&&O(e)===v},isObject:function(e){return O(e)===g},isRegExp:function(e){return O(e)===y},isSorN:function(e){return I.isString(e)||I.isNumber(e)},isString:function(e){return"string"==typeof e||e&&"object"===("undefined"==typeof e?"undefined":s.typeof(e))&&O(e)===m},isUndefined:function(e){return void 0===e},logify:function(e){I.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))}}}})},noDupeAdd:function(e,t,n){if(e){var r=this.findIndex(e,n);0>r&&e.push(t)}},omit:function(e,t){var n={};return I.forOwn(e,function(e,r){-1===t.indexOf(r)&&(n[r]=e)}),n},plainCopy:function(e){return I.copy(e,void 0,void 0,void 0,void 0,!0)},reject:function(e){return I.Promise.reject(e)},remove:function(e,t){if(e&&e.length){var n=this.findIndex(e,t);n>=0&&e.splice(n,1)}},resolve:function(e){return I.Promise.resolve(e)},set:function(e,t,n){if(I.isObject(t))I.forOwn(t,function(t,n){I.set(e,n,t)});else{var r=A.exec(t);r?C(e,r[1])[r[2]]=n:e[t]=n}},strictEqual:function(e,t){var n=e===t;return n||(I.isObject(e)&&I.isObject(t)?(I.forOwn(e,function(e,r){n=n&&I.strictEqual(e,t[r])}),I.forOwn(t,function(t,r){n=n&&I.strictEqual(t,e[r])})):I.isArray(e)&&I.isArray(t)&&e.forEach(function(e,r){n=n&&I.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{I.isBrowser=!!window}catch(e){I.isBrowser=!1}var j=I;t.extend=j.extend,j.logify(t.prototype),j.eventify(t.prototype,function(){return this._listeners},function(e){this._listeners=e});var F="Query",R="Index inaccessible after first operation",S={limit:"",offset:"",orderBy:"",skip:"",sort:"",where:""},E=/([.*+?^=!:${}()|[\]\/\\])/g,k=/%/g,P=/_/g,M=function(e){return e.replace(E,"\\$1")},K=t.extend({constructor:function e(t){var n=this;j.classCallCheck(n,e),n.collection=t,n.data=null},between:function(e,t,n){var r=this;if(n||(n={}),r.data)throw j.err(F+"#between")(500,"Cannot access index");return r.data=r.collection.getIndex(n.index).between(e,t,n),r},compare:function(e,t,n,r){var i=e[t],o=j.get(n,i[0]),a=j.get(r,i[0]);if(o&&j.isString(o)&&(o=o.toUpperCase()),a&&j.isString(a)&&(a=a.toUpperCase()),void 0===n&&(n=null),void 0===r&&(r=null),"DESC"===i[1].toUpperCase()){var u=a;a=o,o=u}return 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")?!j.isNull(this.like(n,t.substr(4)).exec(e)):0===t.indexOf("notLike")?j.isNull(this.like(n,t.substr(7)).exec(e)):void 0},filter:function(e,t){var n=this;return e||(e={}),n.getData(),j.isObject(e)?!function(){var t={};j.isObject(e.where)&&(t=e.where),j.forOwn(e,function(e,n){n in S||n in t||(t[n]={"==":e})});var r=[],i=[],o=[];j.forOwn(t,function(e,t){j.isObject(e)||(e={"==":e}),j.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(j.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;j.isString(a)&&(a=[[a,"ASC"]]),j.isArray(a)||(a=null),a&&!function(){var e=0;a.forEach(function(e,t){j.isString(e)&&(a[t]=[e,"ASC"])}),n.data.sort(function(t,r){return n.compare(a,e,t,r)})}(),j.isNumber(e.skip)?n.skip(e.skip):j.isNumber(e.offset)&&n.skip(e.offset),j.isNumber(e.limit)&&n.limit(e.limit)}():j.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 j.err(F+"#get")(500,R);return e&&!j.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 j.err(F+"#getAll")(500,R);for(var n=arguments.length,r=Array(n),i=0;n>i;i++)r[i]=arguments[i];if(!r.length||1===r.length&&j.isObject(r[0]))return e.getData(),e;r.length&&j.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("^"+M(e).replace(k,".*").replace(P,".")+"$",t)},limit:function(e){if(!j.isNumber(e))throw j.err(F+"#limit","num")(400,"number",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(!j.isNumber(e))throw j.err(F+"#skip","num")(400,"number",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!j.intersection(e||[],t||[]).length},isectNotEmpty:function(e,t){return j.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)}}});j.addHiddenPropsToTarget(a.prototype,{set:function(e,t){j.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){j.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={}),j.isArray(e)||(e=[e]),j.isArray(t)||(t=[t]),j.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(j.copy(e),t.map(function(){}),n)):l===a?r.concat(this.values[c]._between(e.map(function(){}),j.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 j.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 L="Collection",N={idAttribute:"id",onConflict:"merge"},U=t.extend({constructor:function e(t,n){var r=this;j.classCallCheck(r,e),e.__super__.call(r),t&&!j.isArray(t)&&(n=t,t=[]),j.isString(n)&&(n={idAttribute:n}),t||(t=[]),n||(n={}),Object.defineProperties(r,{mapper:{value:void 0,writable:!0},queryClass:{value:void 0,writable:!0}}),j.fillIn(r,n),j.fillIn(r,j.copy(N)),r.queryClass||(r.queryClass=K);var i=r.recordId();Object.defineProperties(r,{index:{value:new a([i],{hashCode:function(e){return j.get(e,i)}})},indexes:{value:{}}}),t&&r.add(t)},_onRecordEvent:function(){this.emit.apply(this,arguments)},add:function(e,t){var n=this;t||(t={}),j._(t,n),e=n.beforeAdd(e,t)||e;var r=!1,i=n.recordId();if(!j.isArray(e)){if(!j.isObject(e))throw j.err(L+"#add","records")(400,"object or array",e);e=[e],r=!0}e=e.map(function(e){var r=n.recordId(e);if(!j.isSorN(r))throw j.err(L+"#add","record."+i)(400,"string or number",r);var o=n.get(r);if(e===o)return o;if(o){var a=t.onConflict||n.onConflict;if("merge"===a)j.deepMixIn(o,e);else{if("replace"!==a)throw j.err(L+"#add","opts.onConflict")(400,"one of (merge, replace)",a,!0);j.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,t):e,n.index.insertRecord(e),j.forOwn(n.indexes,function(t,n){t.insertRecord(e)}),e&&j.isFunction(e.on)&&e.on("all",n._onRecordEvent,n);return e});var o=r?e[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;j.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 j.err(L+"#getIndex",e)(404,"index");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){var t=this;return e?j.get(e,t.recordId()):t.mapper?t.mapper.idAttribute:t.idAttribute},query:function(){var e=this.queryClass;return new e(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),j.forOwn(n.indexes,function(e,t){e.removeRecord(r)}),r&&j.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),j.forOwn(t.indexes,function(t,n){t.updateRecord(e)})}}),D="belongsTo",T="hasMany",J="hasOne",q="Relation";j.addHiddenPropsToTarget(u.prototype,{getRelation:function(){return this.relatedMapper},getForeignKey:function(e){return this.type===D?j.get(e,this.foreignKey):j.get(e,this.mapper.idAttribute)},setForeignKey:function(e,t){var n=this;e&&t&&(n.type===D?j.set(e,n.foreignKey,j.get(t,n.getRelation().idAttribute)):!function(){var r=n.mapper.idAttribute;j.isArray(t)?t.forEach(function(t){j.set(t,n.foreignKey,j.get(e,r))}):j.set(t,n.foreignKey,j.get(e,r))}())},getLocalField:function(e){return j.get(e,this.localField)},setLocalField:function(e,t){return j.set(e,this.localField,t)},getInverse:function(e){var t=this;return t.inverse?t.inverse:(t.getRelation().relationList.forEach(function(n){if(n.getRelation()===e){if(n.foreignKey&&n.foreignKey!==t.foreignKey)return;return t.inverse=n,!1}}),t.inverse)}});var Q=function(e,t,n){n.name=e.name;var r=new u(t,n);Object.defineProperty(r,"mapper",{value:e}),e.relationList||Object.defineProperty(e,"relationList",{value:[]}),e.relationFields||Object.defineProperty(e,"relationFields",{value:[]}),e.relationList.push(r),e.relationFields.push(r.localField)},B=function(e,t){return t||(t={}),t.type=D,function(n){Q(n,e,t)}},$=function(e,t){return t||(t={}),t.type=T,function(n){Q(n,e,t)}},V=function(e,t){return t||(t={}),t.type=J,function(n){Q(n,e,t)}},H="Record",G=function(e,t){var n=e.datastore;return n&&n[t]?function(){for(var r=arguments.length,i=Array(r),o=0;r>o;o++)i[o]=arguments[o];return n[t].apply(n,[e.name].concat(i))}:e[t].bind(e)},W=t.extend({constructor:function e(t,n){var r=this;j.classCallCheck(r,e),t||(t={}),n||(n={});var i={};Object.defineProperties(r,{_get:{value:function(e){return j.get(i,e)}},_set:{value:function(e,t){return j.set(i,e,t)}},_unset:{value:function(e){return j.unset(i,e)}}});var o=r._set;o("creating",!0),n.noValidate&&o("noValidate",!0),j.fillIn(r,t),o("creating",!1),o("noValidate",!1),o("previous",j.copy(t))},_mapper:function(){var e=this,t=e.constructor.mapper;if(!t)throw j.err(H+"#_mapper","")(404,"mapper");return t},afterLoadRelations:function(){},beforeLoadRelations:function(){},changes:function(e){var t=this;return e||(e={}),j.diffObjects("function"==typeof t.toJSON?t.toJSON(e):t,t._get("previous"),e)},commit:function(){var e=this;return e._set("changed"),e._set("previous",j.copy(e)),e},destroy:function(e){var t=this;e||(e={});var n=t._mapper();return G(n,"destroy")(j.get(t,n.idAttribute),e)},get:function(e){return j.get(this,e)},hasChanges:function(e){var t=this,n=!!(t._get("changed")||[]).length;return n||j.areDifferent("function"==typeof t.toJSON?t.toJSON(e):t,t._get("previous"),e)},hashCode:function(){var e=this;return j.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();return e||(e=[]),j.isString(e)&&(e=[e]),t||(t={}),t.with=e,j._(t,i),t.adapter=i.getAdapterName(t),n=t.op="beforeLoadRelations",j.resolve(r[n](e,t)).then(function(){n=t.op="loadRelations",i.dbg(n,r,e,t);var o=[],a=void 0;return j.forEachRelation(i,t,function(e,n){var u=e.getRelation();if(n.raw=!1,j.isFunction(e.load))a=e.load(i,e,r,t);else if("hasMany"===e.type||"hasOne"===e.type)e.foreignKey?a=G(u,"findAll")(s.defineProperty({},e.foreignKey,j.get(r,i.idAttribute)),n).then(function(t){return"hasOne"===e.type?t.length?t[0]:void 0:t}):e.localKeys?a=G(u,"findAll")({where:s.defineProperty({},u.idAttribute,{in:j.get(r,e.localKeys)})}):e.foreignKeys&&(a=G(u,"findAll")({where:s.defineProperty({},e.foreignKeys,{contains:j.get(r,i.idAttribute)})},t));else if("belongsTo"===e.type){var c=j.get(r,e.foreignKey);j.isSorN(c)&&(a=G(u,"find")(c,n))}a&&(a=a.then(function(t){e.setLocalField(r,t)}),o.push(a))}),Promise.all(o)}).then(function(){return n=t.op="afterLoadRelations",j.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=[]),j.forOwn(t,function(r,i){i!==t._mapper().idAttribute&&!n.hasOwnProperty(i)&&t.hasOwnProperty(i)&&-1===e.preserve.indexOf(i)&&delete t[i]}),j.forOwn(n,function(n,r){-1===e.preserve.indexOf(r)&&(t[r]=n)}),t.commit(),t},save:function(e){var t=this;e||(e={});var n=t._mapper(),r=j.get(t,n.idAttribute),i=t;if(j.isUndefined(r))return G(n,"create")(i,e);if(e.changesOnly){var o=t.changes(e);i={},j.fillIn(i,o.added),j.fillIn(i,o.changed)}return G(n,"update")(r,i,e)},set:function(e,t,n){var r=this;j.isObject(e)&&(n=t),n||(n={}),n.silent&&r._set("silent",!0),j.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 j.forOwn(t,function(t,n){e[n]=j.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)}});j.eventify(W.prototype,function(){return this._get("events")},function(e){this._set("events",e)});var z="Schema",X={array:j.isArray,boolean:j.isBoolean,integer:j.isInteger,null:j.isNull,number:j.isNumber,object:j.isObject,string:j.isString},Y=function(e,t){var n="";return e&&(n+=j.isNumber(e)?"["+e+"]":t?"."+e:""+e),n},Z=function(e){e||(e={});var t="",n=e.path||[];return n.forEach(function(e){t+=Y(e,t)}),t+=Y(e.prop,t)},ee=function(e,t,n){return{expected:t,actual:""+e,path:Z(n)}},te=function(e,t,n,r){r.push(ee(e,t,n))},ne=function(e,t,n,r){var i=n[e];return t.length>i?ee(t.length,"length no more than "+i,r):void 0},re=function(e,t,n,r){var i=n[e];return t.length<i?ee(t.length,"length no less than "+i,r):void 0},ie={allOf:function(e,t,n){var r=[];return t.allOf.forEach(function(t){r=r.concat(pe(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=pe(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)?ee(e,"one of ("+r.join(", ")+")",n):void 0},items:function e(t,n,r){r||(r={});for(var e=n.items,i=[],o=j.isArray(e),a=t.length,u=0;a>u;u++)o&&(e=n.items[u]),r.prop=u,i=i.concat(pe(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)?ee(t,"no more than "+e,r):void 0},maxItems:function(e,t,n){return ne("maxItems",e,t,n)},maxLength:function(e,t,n){return ne("maxLength",e,t,n)},maxProperties:function e(t,n,r){var e=n.maxProperties,i=Object.keys(t).length;return i>e?ee(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)?ee(t,"no less than "+e,r):void 0},minItems:function(e,t,n){return re("minItems",e,t,n)},minLength:function(e,t,n){return re("minLength",e,t,n)},minProperties:function e(t,n,r){var e=n.minProperties,i=Object.keys(t).length;return e>i?ee(i,"no more than "+e+" properties",r):void 0},multipleOf:function(e,t,n){},not:function(e,t,n){return pe(e,t.not,n)?void 0:ee("succeeded","should have failed",n)},oneOf:function(e,t,n){var r=!1,i=[];return t.oneOf.forEach(function(t){var o=pe(e,t,n);if(o)i=i.concat(o);else{if(r)return i=[ee("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 j.isString(t)&&!t.match(e)?ee(t,e,r):void 0},properties:function e(t,n,r){r||(r={});var i=j.isUndefined(n.additionalProperties)?!0:n.additionalProperties,o={},e=n.properties||{},a=n.patternProperties||{},u=[];j.forOwn(t,function(e,t){o[t]=void 0}),j.forOwn(e||{},function(e,n){j.isUndefined(t[n])&&!j.isUndefined(e.default)&&(t[n]=j.copy(e.default)),r.prop=n,u=u.concat(pe(t[n],e,r)||[]),delete o[n]}),j.forOwn(a,function(e,n){j.forOwn(o,function(i,a){a.match(n)&&(r.prop=a,u=u.concat(pe(t[a],e,r)||[]),delete o[a])})});var s=Object.keys(o);return i===!1?s.length&&te("extra fields: "+s.join(", "),"no extra fields",r,u):j.isObject(i)&&s.forEach(function(e){r.prop=e,u=u.concat(pe(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(j.isUndefined(j.get(t,e))){var n=r.prop;r.prop=e,te(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(j.isString(e)&&(e=[e]),e.forEach(function(e){return X[e](t,n,r)?(i=e,!1):void 0}),!i)return ee(t?"undefined"==typeof t?"undefined":s.typeof(t):""+t,"one of ("+e.join(", ")+")",r);var o=we[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 ee(i,"no duplicates",n)}}},oe=function(e,t,n,r){return!j.isUndefined(n[e])&&ie[e](t,n,r)},ae=function(e,t,n,r){var i=[];return e.forEach(function(e){i=i.concat(oe(e,t,n,r)||[])}),i.length?i:void 0},ue=["enum","type","allOf","anyOf","oneOf","not"],se=["items","maxItems","minItems","uniqueItems"],ce=["multipleOf","maximum","minimum"],le=["maxProperties","minProperties","required","properties","dependencies"],fe=["maxLength","minLength","pattern"],de=function(e,t,n){return ae(ue,e,t,n)},pe=function e(t,n,r){var i=[];r||(r={});var o=void 0,a=r.prop;if(!j.isUndefined(n)){if(!j.isObject(n))throw j.err(z+"#validate")(500,'Invalid schema at path: "'+r.path+'"');return j.isUndefined(r.path)&&(r.path=[]),j.isUndefined(r.prop)||(o=!0,r.path.push(r.prop),r.prop=void 0),n.extends&&(i=j.isFunction(n.extends.validate)?i.concat(n.extends.validate(t,r)||[]):i.concat(e(t,n.extends,r)||[])),j.isUndefined(t)?(n.required===!0&&te(t,"a value",r,i),o&&(r.path.pop(),r.prop=a),i.length?i:void 0):(i=i.concat(de(t,n,r)||[]),o&&(r.path.pop(),r.prop=a),i.length?i:void 0)}},he="changing",ve="changed",ge="creating",ye="eventId",me="noValidate",be="silent",Ae="validation failed",_e=function(e,t,n){var r={enumerable:j.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(me)){var d=t.validate(n);if(d){var p=new Error(Ae);throw p.errors=d,p}}return t.track&&!c(ge)&&!function(){var t=c(o),a=c(i),u=c(he),s=c(ve);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(he),f(ve),c(ye)&&(clearTimeout(c(ye)),f(ye))),!u&&s.length&&(l(ve,s),l(he,!0),l(ye,setTimeout(function(){if(f(ve),f(ye),f(he),!c(be)){var e=void 0;for(e=0;e<s.length;e++)r.emit("change:"+s[e],r,j.get(r,s[e]));r.emit("change",r,r.changes())}f(be)},0)))}(),l(i,n),n},r},we={array:function(e,t,n){return ae(se,e,t,n)},integer:function(e,t,n){return we.numeric(e,t,n)},number:function(e,t,n){return we.numeric(e,t,n)},numeric:function(e,t,n){return ae(ce,e,t,n)},object:function(e,t,n){return ae(le,e,t,n)},string:function(e,t,n){return ae(fe,e,t,n)}},Oe=t.extend({constructor:function e(t){t||(t={}),j.fillIn(this,t),t.properties&&j.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||{}; | ||
j.forOwn(n,function(n,r){Object.defineProperty(e,r,_e(r,n,t))})},validate:function(e,t){return pe(e,this,t)}},{typeGroupValidators:we,types:X,validate:pe,validationKeywords:ie}),xe="Mapper",Ce=function(e){return function(){for(var t=arguments.length,n=Array(t),r=0;t>r;r++)n[r]=arguments[r];var i=this,o=n[n.length-e];i.dbg.apply(i,[o.op].concat(n)),(o.notify||void 0===o.notify&&i.notify)&&setTimeout(function(){i.emit.apply(i,[o.op].concat(n))})}},Ie=Ce(1),je=Ce(2),Fe={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:[]}},Re={_adapters:{},applySchema:!0,debug:!1,defaultAdapter:"http",idAttribute:"id",notify:!0,raw:!1},Se=t.extend({constructor:function e(t){var n=this;if(j.classCallCheck(n,e),e.__super__.call(n),t||(t={}),Object.defineProperties(n,{_adapters:{value:void 0,writable:!0},recordClass:{value:void 0,writable:!0},lifecycleMethods:{value:Fe},schema:{value:void 0,writable:!0}}),j.fillIn(n,t),j.fillIn(n,j.copy(Re)),!n.name)throw j.err("new "+xe,"opts.name")(400,"string",n.name);n.schema instanceof Oe||(n.schema=new Oe(n.schema||{})),j.isUndefined(n.recordClass)&&!function(){var e=W;n.recordClass=e.extend({constructor:function(){var t=function(n,r){j.classCallCheck(this,t),e.call(this,n,r)};return t}()})}(),n.recordClass&&(n.recordClass.mapper=n,j.getSuper(n.recordClass,!0)===W&&n.schema&&n.schema.apply&&n.applySchema&&n.schema.apply(n.recordClass.prototype))},afterCount:je,afterCreate:je,afterCreateMany:je,afterDestroy:je,afterDestroyAll:je,afterFind:je,afterFindAll:je,afterSum:je,afterUpdate:je,afterUpdateAll:je,afterUpdateMany:je,beforeCreate:Ie,beforeCreateMany:Ie,beforeCount:Ie,beforeDestroy:Ie,beforeDestroyAll:Ie,beforeFind:Ie,beforeFindAll:Ie,beforeSum:Ie,beforeUpdate:Ie,beforeUpdateAll:Ie,beforeUpdateMany:Ie,_end:function(e,t,n){var r=this;if(t.raw&&j._(e,t),n)return e;var i=t.raw?e.data:e;return i&&j.isFunction(r.wrap)&&(i=r.wrap(i,t),t.raw?e.data=i:e=i),e},belongsTo:function(e,t){return B(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={}),j._(t,i),r=t.adapter=i.getAdapterName(t),n=t.op="beforeCreate",j.resolve(i[n](e,t)).then(function(o){e=j.isUndefined(o)?e:o;var a={};t.with||(t.with=[]);var u=[];return j.forEachRelation(i,t,function(t,n){var r=t.getLocalField(e),i=t.getRelation(),o=i.idAttribute;n.raw=!1,r&&(t.type===D?u.push(i.create(r,n).then(function(n){t.setLocalField(a,n),t.setForeignKey(e,n)})):t.type===T&&t.localKeys&&u.push(i.createMany(r,n).then(function(n){t.setLocalField(a,n),j.set(e,t.localKeys,n.map(function(e){return j.get(e,o)}))})))}),j.Promise.all(u).then(function(){return n=t.op="create",i.dbg(n,e,t),j.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=[],j.forEachRelation(i,t,function(t,n){var i=t.getLocalField(e);if(i){n.raw=!1;var o=void 0;t.type===T&&t.foreignKey?(t.setForeignKey(r,i),o=t.getRelation().createMany(i,n).then(function(e){t.setLocalField(r,e)})):t.type===J?(t.setForeignKey(r,i),o=t.getRelation().create(i,n).then(function(e){t.setLocalField(r,e)})):t.type===D&&t.getLocalField(a)?t.setLocalField(r,t.getLocalField(a)):t.type===T&&t.localKeys&&t.getLocalField(a)&&t.setLocalField(r,t.getLocalField(a)),o&&u.push(o)}}),j.Promise.all(u).then(function(){return n})})}).then(function(r){return r=i._end(r,t),n=t.op="afterCreate",j.resolve(i[n](e,t,r)).then(function(e){return j.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={}),j._(t,i),r=t.adapter=i.getAdapterName(t),n=t.op="beforeCreateMany",j.resolve(i[n](e,t)).then(function(o){e=j.isUndefined(o)?e:o;var a={};t.with||(t.with=[]);var u=[];return j.forEachRelation(i,t,function(t,n){var r=e.map(function(e){return t.getLocalField(e)}).filter(function(e){return e});t.type===D&&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])})}))}),j.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),j.resolve(i.getAdapter(r)[n](i,o,t))}).then(function(n){var r=t.raw?n.data:n;return u=[],j.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===T?i.log("warn","deep createMany of hasMany type not supported!"):n.type===J?(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===D&&c&&c.length===r.length&&r.forEach(function(e,t){n.setLocalField(e,c[t])}),l&&u.push(l)}}),j.Promise.all(u).then(function(){return n})})}).then(function(r){return r=i._end(r,t),n=t.op="afterCreateMany",j.resolve(i[n](e,t,r)).then(function(e){return j.isUndefined(e)?r:e})})},createRecord:function(e,t){e||(e={});var n=this;if(j.isArray(e))return e.map(function(e){return n.createRecord(e,t)});if(!j.isObject(e))throw j.err(xe+"#createRecord","props")(400,"array or object",e);var r=n.recordClass,i=n.relationList||[];return i.forEach(function(n){var r=n.getRelation(),i=n.getLocalField(e);if(i&&!r.is(i)){if(j.isArray(i)&&(!i.length||r.is(i[0])))return;j.set(e,n.localField,r.createRecord(i,t))}}),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 j.err(xe+"#crud",e)(404,"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){j.isUndefined(n[t])&&(n[t]=j.copy(e))});var d=n[n.length-1];return j._(d,i),f=d.adapter=i.getAdapterName(d),l=d.op=u,j.resolve(i[l].apply(i,s.toConsumableArray(n))).then(function(t){var r;return j.isUndefined(o.beforeAssign)||(n[o.beforeAssign]=j.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))),j.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,j.resolve(i[l].apply(i,s.toConsumableArray(n))).then(function(t){return j.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 j.err(xe+"#getAdapter","name")(400,"string",e);return t.getAdapters()[n]},getAdapterName:function(e){return e||(e={}),j.isString(e)&&(e={adapter:e}),e.adapter||e.defaultAdapter},getAdapters:function(){return this._adapters},getSchema:function(){return this.schema},hasMany:function(e,t){return $(e,t)(this)},hasOne:function(e,t){return V(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,r=void 0;if(t||(t={}),j.isArray(e))return e.map(function(e){return n.toJSON(e,t)});r=e;var i=(n?n.relationFields:[])||[],o={},a=void 0;if(n&&n.schema&&(a=n.schema.properties||{},j.forOwn(a,function(e,t){o[t]=j.plainCopy(r[t])})),a||(a={}),!t.strict)for(var u in r)a[u]||-1!==i.indexOf(u)||(o[u]=j.plainCopy(r[u]));return n&&t.withAll&&(t.with=i.slice()),n&&t.with&&(j.isString(t.with)&&(t.with=[t.with]),j.forEachRelation(n,t,function(e,t){var n=e.getLocalField(r);n&&(j.isArray(n)?e.setLocalField(o,n.map(function(n){return e.getRelation().toJSON(n,t)})):e.setLocalField(o,e.getRelation().toJSON(n,t)))})),o},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,r=n.getSchema();if(!j.isArray(e))return r.validate(e,t);var i=e.map(function(e){return r.validate(e,t)}),o=!1;return i.forEach(function(e){e&&(o=!0)}),o?i:void 0},wrap:function(e,t){return this.createRecord(e,t)}}),Ee="Container",ke=["count","create","createMany","createRecord","dbg","destroy","destroyAll","find","findAll","getSchema","is","log","sum","toJSON","update","updateAll","updateMany","validate"],Pe={constructor:function e(t){var n=this;j.classCallCheck(n,e),e.__super__.call(n),t||(t={}),j.fillIn(n,t),n.mapperDefaults=n.mapperDefaults||{},n.mapperClass=n.mapperClass||Se,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(j.isObject(e)&&(t=e,e=t.name),!j.isString(e))throw j.err(Ee+"#defineMapper","name")(400,"string",e);t||(t={}),t.name=e,t.relations||(t.relations={});var r=t.mapperClass||n.mapperClass;delete t.mapperClass,j.fillIn(t,n.mapperDefaults);var i=n._mappers[e]=new r(t);return i.relations||(i.relations={}),i.name=e,i._adapters=n.getAdapters(),i.datastore=n,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))}),j.forOwn(i.relations,function(e,t){j.forOwn(e,function(e,r){j.isObject(e)&&(e=[e]),e.forEach(function(e){e.getRelation=function(){return n.getMapper(r)};var o=n._mappers[r]||r;t===D?i.belongsTo(o,e):t===J?i.hasOne(o,e):t===T&&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 j.err(Ee+"#getAdapter","name")(400,"string",e);return t.getAdapters()[n]},getAdapterName:function(e){return e||(e={}),j.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 j.err(Ee+"#getMapper",e)(404,"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,j.forOwn(r._mappers,function(t){t.defaultAdapter=e}))}};ke.forEach(function(e){Pe[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 Me=t.extend(Pe),Ke="LinkedCollection",Le=U.extend({constructor:function e(t,n){var r=this;if(j.classCallCheck(r,e),e.__super__.call(r,t,n),Object.defineProperty(r,"_added",{value:{}}),!r.datastore)throw j.err("new "+Ke,"opts.datastore")(400,"DataStore",r.datastore);return r},_onRecordEvent:function(){for(var e=this,t=arguments.length,n=Array(t),r=0;t>r;r++)n[r]=arguments[r];j.getSuper(e).prototype._onRecordEvent.apply(e,n);var i=n[0];j.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,c=i.idAttribute,l=void 0;return j.isObject(e)&&!j.isArray(e)&&(l=!0,e=[e]),e=j.getSuper(n).prototype.add.call(n,e,t),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),l=t.type,f=l===T,d=j.isUndefined(t.add)?!0:!!t.add,p=void 0;e.forEach(function(e){p=t.getLocalField(e);var n=j.get(e,c);if(j.isFunction(t.add))p=t.add(r,t,e);else if(p)if(f)p=p.map(function(n){return n!==u.get(u.recordId(n))&&(a&&t.setForeignKey(e,n),d&&(n=u.add(n))),n});else{var i=j.get(p,o);p!==u.get(i)&&(t.setForeignKey(e,p),d&&(p=u.add(p)))}if(!p||j.isArray(p)&&!p.length)if(l===D){var h=j.get(e,a);j.isUndefined(h)||(p=u.get(h))}else if(l===J){var v=u.filter(s.defineProperty({},a,n));p=v.length?v[0]:void 0}else if(l===T)if(a){var g=u.filter(s.defineProperty({},a,n));p=g.length?g:void 0}else if(t.localKeys&&j.get(e,t.localKeys)){var y=u.filter({where:s.defineProperty({},o,{in:j.get(e,t.localKeys)})});p=y.length?y:void 0}else if(t.foreignKeys){var m=u.filter({where:s.defineProperty({},t.foreignKeys,{contains:n})});p=m.length?m:void 0}p&&t.setLocalField(e,p)})}),e.forEach(function(e){n._added[n.recordId(e)]=a,u&&e._set("$",a)}),l?e[0]:e},remove:function(e,t){var n=this,r=n.mapper,i=j.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=j.getSuper(n).prototype.removeAll.call(n,e,t);return i.forEach(function(e){delete n._added[n.recordId(e)],r.recordClass&&e._set("$")}),i}}),Ne="DataStore",Ue=function(e,t,n){e&&e._set?e._set(t,n):j.set(e,t,n)},De=function(e,t,n){var r=this,i=r._completedQueries[e][t];return j.isFunction(i)?i(e,t,n):i},Te={constructor:function e(t){var n=this;return j.classCallCheck(n,e),e.__super__.call(n,t),n.collectionClass=n.collectionClass||Le,n._collections={},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){var r=n.raw?t.data:t;return r&&j.isFunction(this.addToCache)&&(r=this.addToCache(e,r,n),n.raw?t.data=r:t=r),t},_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))},addToCache:function(e,t,n){return this.getCollection(e).add(t,n)},cachedFind:De,cachedFindAll:De,cacheFind:function(e,t,n,r){var i=this;i._completedQueries[e][n]=function(e,t,n){return i.get(e,t)}},cacheFindAll:function(e,t,n,r){var i=this;i._completedQueries[e][n]=function(e,t,n){return i.filter(e,j.fromJson(t))}},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=j.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||{};j.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=r.idAttribute;return r.relationList.forEach(function(e){var t=e.relation,o=e.localField,a="links."+o,s=e.foreignKey,c=e.type,l={index:s},f=void 0,d=function(){return this._get(a)};c===D?(i.indexes[s]||i.createIndex(s),f={get:d,set:function(o){var c=this,f=this._get(a);if(o===f)return f;var d=j.get(c,u),p=e.getInverse(r);if(o){var h=e.getRelation().idAttribute,v=j.get(o,h);if(j.isUndefined(v)||(o=n.get(t,v)||o),c._set(a,o),Ue(c,s,v),i.updateIndex(c,l),p.type===J)j.set(o,p.localField,c);else if(p.type===T){var g=j.get(o,p.localField);j.noDupeAdd(g,c,function(e){return d===j.get(e,u)})}}else c._set(a,void 0),Ue(c,s,void 0),i.updateIndex(c,l);if(f)if(p.type===J)j.set(f,p.localField,void 0);else if(p.type===T){var y=j.get(f,p.localField);j.remove(y,function(e){return d===j.get(e,u)})}return o}},r.recordClass.prototype.hasOwnProperty(s)&&!function(){var e=r.recordClass;r.recordClass=e.extend({constructor:function(){var t=function(n,r){j.classCallCheck(this,t),e.call(this,n,r)};return t}()})}(),Object.defineProperty(r.recordClass.prototype,s,{enumerable:!0,get:function(){return this._get(s)},set:function(e){var r=this;if(j.isUndefined(e))j.set(r,o,void 0);else{Ue(r,s,e);var i=n.get(t,e);i&&j.set(r,o,i)}}})):c===T?!function(){var i=e.localKeys,o=e.foreignKeys;n._collections[t]&&s&&!n.getCollection(t).indexes[s]&&n.getCollection(t).createIndex(s),f={get:function(){var e=this,t=d.call(e);return t||e._set(a,[]),d.call(e)},set:function(c){var f=this;c||(c=[]),c&&!j.isArray(c)&&(c=[c]);var d=j.get(f,u),p=e.getRelation().idAttribute,h=e.getInverse(r),v=h.localField,g=f._get(a);g||(g=[]);var y=g;g=[];var m={};return c.forEach(function(e){var r=j.get(e,p);j.isUndefined(r)||(e=n.get(t,r)||e,m[r]=e),g.push(e)}),s?(c.forEach(function(e){Ue(e,s,d),n.getCollection(t).updateIndex(e,l),j.set(e,v,f)}),y.forEach(function(e){var r=j.get(e,p);j.isUndefined(r)||m.hasOwnProperty(r)||(Ue(e,s,void 0),n.getCollection(t).updateIndex(e,l),j.set(e,v,void 0))})):i?!function(){var e=[];c.forEach(function(t){j.set(t,v,f),e.push(j.get(t,p))}),j.set(f,i,e),y.forEach(function(e){var t=j.get(e,p);j.isUndefined(t)||m.hasOwnProperty(t)||j.set(e,v,void 0)})}():o&&(y.forEach(function(e){var t=j.get(e,o)||[];j.remove(t,function(e){return d===e});var n=j.get(e,v)||[];j.remove(n,function(e){return d===j.get(e,u)})}),c.forEach(function(e){var t=j.get(e,o)||[];j.noDupeAdd(t,d,function(e){return d===e});var n=j.get(e,v)||[];j.noDupeAdd(n,f,function(e){return d===j.get(e,u)})})),f._set(a,g),g}}}():c===J&&(n._collections[t]&&s&&!n.getCollection(t).indexes[s]&&n.getCollection(t).createIndex(s),f={get:d,set:function(i){var o=this,c=this._get(a);if(i===c)return c;var f=j.get(i,e.getRelation().idAttribute),d=e.getInverse(r).localField;return c&&(Ue(c,s,void 0),n.getCollection(t).updateIndex(c,l),j.set(c,d,void 0)),i?(j.isUndefined(f)||(i=n.get(t,f)||i),o._set(a,i),Ue(i,s,j.get(o,u)),n.getCollection(t).updateIndex(i,l),j.set(i,d,o)):o._set(a,void 0),i}}),f&&(f.enumerable=j.isUndefined(e.enumerable)?!1:e.enumerable,e.get&&!function(){var t=f.get;f.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=f.set;f.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,f))}),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(j.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){delete r._pendingQueries[e][t];var o=r._end(e,i,n);return r.cacheFind(e,o,t,n),o},function(n){return delete r._pendingQueries[e][t],j.reject(n)}):j.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(j.fillIn(n,r.getMapper(e)),o)return o;var a=r.cachedFindAll(e,i,n),u=void 0;return u=n.force||!a?r._pendingQueries[e][i]=r._callSuper("findAll",e,t,n).then(function(t){delete r._pendingQueries[e][i];var o=r._end(e,t,n);return r.cacheFindAll(e,o,i,n),o},function(t){return delete r._pendingQueries[e][i],j.reject(t)}):j.resolve(a)},getCollection:function(e){var t=this._collections[e];if(!t)throw j.err(Ne+"#getCollection",e)(404,"collection");return t},hashQuery:function(e,t,n){return j.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;j.forEachRelation(r.getMapper(e),n,function(e,n){t.forEach(function(t){var i=void 0,o=void 0;if(!e.foreignKey||e.type!==J&&e.type!==T?e.type===T&&e.localKeys?o={where:s.defineProperty({},e.getRelation().idAttribute,{in:j.get(t,e.localKeys)})}:e.type===T&&e.foreignKeys?o={where:s.defineProperty({},e.foreignKeys,{contains:e.getForeignKey(t)})}:e.type===D&&(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(j.isArray(i)&&!i.length)return;e.type===J&&(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)})}},Je=["add","between","createIndex","filter","get","getAll","query","toJson"];Je.forEach(function(e){Te[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 qe=Me.extend(Te),Qe={beta:4,full:"3.0.0-beta.4",major:3,minor:0,patch:0};e.version=Qe,e.Collection=U,e.Component=t,e.Container=Me,e.DataStore=qe,e.Index=a,e.LinkedCollection=Le,e.Mapper=Se,e.Query=K,e.Record=W,e.Schema=Oe,e.utils=j,e.belongsToType=D,e.hasManyType=T,e.hasOneType=J,e.belongsTo=B,e.hasMany=$,e.hasOne=V}); | ||
!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(){Object.defineProperty(this,"_listeners",{value:{}})}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(j.classCallCheck(this,a),e||(e=[]),!j.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,r="new "+q;t||(t={});var i=t.localField;if(!i)throw j.err(r,"opts.localField")(400,"string",i);var o=t.foreignKey=t.foreignKey||t.localKey;if(!o&&(t.type===D||t.type===J))throw j.err(r,"opts.foreignKey")(400,"string",o);var a=t.localKeys,u=t.foreignKeys;if(!o&&!a&&!u&&t.type===T)throw j.err(r,"opts.<foreignKey|localKeys|foreignKeys>")(400,"string",o);if(j.isString(e)){if(t.relation=e,!j.isFunction(t.getRelation))throw j.err(r,"opts.getRelation")(400,"function",t.getRelation)}else{if(!e)throw j.err(r,"related")(400,"Mapper or string",e);t.relation=e.name,Object.defineProperty(n,"relatedMapper",{value:e})}Object.defineProperty(n,"inverse",{value:void 0,writable:!0}),j.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="utils",l=1/0,f=1.7976931348623157e308,d="[object Boolean]",p="[object Date]",h="[object Function]",v="[object Number]",g="[object Object]",y="[object RegExp]",m="[object String]",b=Object.prototype.toString,A=/^(.+)\.(.+)$/,_={400:function(){return"expected: "+arguments[0]+", found: "+(arguments[2]?arguments[1]:s.typeof(arguments[1]))},404:function(){return arguments[0]+" not found"}},w=function(e){if(!e)return 0;if(e=+e,e===l||e===-l){var t=0>e?-1:1;return t*f}var n=e%1;return e===e?n?e-n:e:0},O=function(e){return b.call(e)},x=function(e){return!!e&&"object"===("undefined"==typeof e?"undefined":s.typeof(e))&&e.constructor===Object},C=function(e,t){if(!t)return e;var n=t.split(".");return n.forEach(function(t){e[t]||(e[t]={}),e=e[t]}),e},I={Promise:Promise,_:function(e,t){I.forOwn(t,function(t,n){n&&I.isUndefined(e[n])&&!I.isFunction(t)&&0!==n.indexOf("_")&&(e[n]=t)})},_forRelation:function(e,t,n,r){var i=t.relation,o=null,a=void 0;if(e||(e={}),e.with||(e.with=[]),(a=I._getIndex(e.with,i))>=0?o=i:(a=I._getIndex(e.with,t.localField))>=0&&(o=t.localField),e.withAll)return void n.call(r,t,{});if(o){var u={};I.fillIn(u,t.getRelation()),I.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):I.isObject(e)&&e.relation===t?(n=r,!1):void 0}),n},addHiddenPropsToTarget:function(e,t){var n={};I.forOwn(t,function(e,t){n[t]={writable:!0,value:e}}),Object.defineProperties(e,n)},areDifferent:function(e,t,n){n||(n={});var r=I.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 I.err(""+t.name)(500,"Cannot call a class as a function")},copy:function(e,t,n,r,i,o){if(t){if(e===t)throw I.err(c+".copy")(500,"Cannot copy! Source and destination are identical.");if(n=n||[],r=r||[],I.isObject(e)){var a=n.indexOf(e);if(-1!==a)return r[a];n.push(e),r.push(t)}var u=void 0;if(I.isArray(e)){var s=void 0;for(t.length=0,s=0;s<e.length;s++)u=I.copy(e[s],null,n,r,i,o),I.isObject(e[s])&&(n.push(e[s]),r.push(u)),t.push(u)}else{I.isArray(t)?t.length=0:I.forOwn(t,function(e,n){delete t[n]});for(var l in e)if(e.hasOwnProperty(l)){if(I.isBlacklisted(l,i))continue;u=I.copy(e[l],null,n,r,i,o),I.isObject(e[l])&&(n.push(e[l]),r.push(u)),t[l]=u}}}else t=e,e&&(I.isArray(e)?t=I.copy(e,[],n,r,i,o):I.isDate(e)?t=new Date(e.getTime()):I.isRegExp(e)?(t=new RegExp(e.source,e.toString().match(/[^\/]*$/)[0]),t.lastIndex=e.lastIndex):I.isObject(e)&&(t=o?I.copy(e,{},n,r,i,o):I.copy(e,Object.create(Object.getPrototypeOf(e)),n,r,i,o)));return t},deepFillIn:function(e,t){return t&&I.forOwn(t,function(t,n){var r=e[n];x(t)&&x(r)?I.deepFillIn(r,t):e.hasOwnProperty(n)&&void 0!==e[n]||(e[n]=t)}),e},deepMixIn:function(e,t){return t&&I.forOwn(t,function(t,n){var r=e[n];x(t)&&x(r)?I.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 I.isFunction(r)||(r=I.strictEqual),I.forOwn(t,function(t,n){var a=e[n];I.isBlacklisted(n,i)||r(a,t)||(I.isUndefined(a)?o.removed[n]=void 0:r(a,t)||(o.changed[n]=a))}),I.forOwn(e,function(e,n){I.isUndefined(t[n])&&!I.isBlacklisted(n,i)&&(o.added[n]=e)}),o},equal:function(e,t){return e==t},err:function(e,t){return function(n){var r="["+e+":"+t+"] ",i=_[n].apply(null,Array.prototype.slice.call(arguments,1));return i=""+r+i+"\nhttp://www.js-data.io/v3.0/docs/errors#"+n,new Error(i)}},eventify:function(e,t,n){e=e||this;var r={};t||n||(t=function(){return r},n=function(e){r=e}),Object.defineProperties(e,{emit:{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:{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:{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(){I.classCallCheck(this,r);for(var e=arguments.length,t=Array(e),i=0;e>i;i++)t[i]=arguments[i];n.apply(this,t)},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:I.forOwn(n,function(e,t){r[t]=e}),Object.defineProperty(r,"__super__",{configurable:!0,value:n}),I.addHiddenPropsToTarget(r.prototype,e),I.fillIn(r,t),r},fillIn:function(e,t){return I.forOwn(t,function(t,n){e.hasOwnProperty(n)&&void 0!==e[n]||(e[n]=t)}),e},findIndex:function(e,t){var n=-1;return e?(e.forEach(function(e,r){return t(e)?(n=r,!1):void 0}),n):n},forEachRelation:function(e,t,n,r){var i=e.relationList||[];i.length&&i.forEach(function(e){I._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 I.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.hasOwnProperty("__super__")?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(O(t[r])===y&&t[r].test(e)||t[r]===e)return n=e;return!!n},isBoolean:function(e){return O(e)===d},isBrowser:!1,isDate:function(e){return e&&"object"===("undefined"==typeof e?"undefined":s.typeof(e))&&O(e)===p},isFunction:function(e){return"function"==typeof e||e&&O(e)===h},isInteger:function(e){return O(e)===v&&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&&O(e)===v},isObject:function(e){return O(e)===g},isRegExp:function(e){return O(e)===y},isSorN:function(e){return I.isString(e)||I.isNumber(e)},isString:function(e){return"string"==typeof e||e&&"object"===("undefined"==typeof e?"undefined":s.typeof(e))&&O(e)===m},isUndefined:function(e){return void 0===e},logify:function(e){I.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))}}}})},noDupeAdd:function(e,t,n){if(e){var r=this.findIndex(e,n);0>r&&e.push(t)}},omit:function(e,t){var n={};return I.forOwn(e,function(e,r){-1===t.indexOf(r)&&(n[r]=e)}),n},plainCopy:function(e){return I.copy(e,void 0,void 0,void 0,void 0,!0)},reject:function(e){return I.Promise.reject(e)},remove:function(e,t){if(e&&e.length){var n=this.findIndex(e,t);n>=0&&e.splice(n,1)}},resolve:function(e){return I.Promise.resolve(e)},set:function(e,t,n){if(I.isObject(t))I.forOwn(t,function(t,n){I.set(e,n,t)});else{var r=A.exec(t);r?C(e,r[1])[r[2]]=n:e[t]=n}},strictEqual:function(e,t){var n=e===t;return n||(I.isObject(e)&&I.isObject(t)?(I.forOwn(e,function(e,r){n=n&&I.strictEqual(e,t[r])}),I.forOwn(t,function(t,r){n=n&&I.strictEqual(t,e[r])})):I.isArray(e)&&I.isArray(t)&&e.forEach(function(e,r){n=n&&I.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{I.isBrowser=!!window}catch(e){I.isBrowser=!1}var j=I;t.extend=j.extend,j.logify(t.prototype),j.eventify(t.prototype,function(){return this._listeners},function(e){this._listeners=e});var F="Query",R="Index inaccessible after first operation",S={limit:"",offset:"",orderBy:"",skip:"",sort:"",where:""},E=/([.*+?^=!:${}()|[\]\/\\])/g,k=/%/g,P=/_/g,M=function(e){return e.replace(E,"\\$1")},K=t.extend({constructor:function e(t){var n=this;j.classCallCheck(n,e),n.collection=t,n.data=null},between:function(e,t,n){var r=this;if(n||(n={}),r.data)throw j.err(F+"#between")(500,"Cannot access index");return r.data=r.collection.getIndex(n.index).between(e,t,n),r},compare:function(e,t,n,r){var i=e[t],o=j.get(n,i[0]),a=j.get(r,i[0]);if(o&&j.isString(o)&&(o=o.toUpperCase()),a&&j.isString(a)&&(a=a.toUpperCase()),void 0===n&&(n=null),void 0===r&&(r=null),"DESC"===i[1].toUpperCase()){var u=a;a=o,o=u}return 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")?!j.isNull(this.like(n,t.substr(4)).exec(e)):0===t.indexOf("notLike")?j.isNull(this.like(n,t.substr(7)).exec(e)):void 0},filter:function(e,t){var n=this;return e||(e={}),n.getData(),j.isObject(e)?!function(){var t={};j.isObject(e.where)&&(t=e.where),j.forOwn(e,function(e,n){n in S||n in t||(t[n]={"==":e})});var r=[],i=[],o=[];j.forOwn(t,function(e,t){j.isObject(e)||(e={"==":e}),j.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(j.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;j.isString(a)&&(a=[[a,"ASC"]]),j.isArray(a)||(a=null),a&&!function(){var e=0;a.forEach(function(e,t){j.isString(e)&&(a[t]=[e,"ASC"])}),n.data.sort(function(t,r){return n.compare(a,e,t,r)})}(),j.isNumber(e.skip)?n.skip(e.skip):j.isNumber(e.offset)&&n.skip(e.offset),j.isNumber(e.limit)&&n.limit(e.limit)}():j.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 j.err(F+"#get")(500,R);return e&&!j.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 j.err(F+"#getAll")(500,R);for(var n=arguments.length,r=Array(n),i=0;n>i;i++)r[i]=arguments[i];if(!r.length||1===r.length&&j.isObject(r[0]))return e.getData(),e;r.length&&j.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("^"+M(e).replace(k,".*").replace(P,".")+"$",t)},limit:function(e){if(!j.isNumber(e))throw j.err(F+"#limit","num")(400,"number",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(!j.isNumber(e))throw j.err(F+"#skip","num")(400,"number",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!j.intersection(e||[],t||[]).length},isectNotEmpty:function(e,t){return j.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)}}});j.addHiddenPropsToTarget(a.prototype,{set:function(e,t){j.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){j.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(e){e||(e={});var t=[],n=this.values;if("desc"===e.order)for(var r=n.length-1;r>=0;r--){var i=n[r];t=i.isIndex?t.concat(i.getAll(e)):t.concat(i)}else for(var o=0;o<n.length;o++){var a=n[o];t=a.isIndex?t.concat(a.getAll(e)):t.concat(a)}return t},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={}),j.isArray(e)||(e=[e]),j.isArray(t)||(t=[t]),j.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(j.copy(e),t.map(function(){}),n)):l===a?r.concat(this.values[c]._between(e.map(function(){}),j.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 j.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 L="Collection",N={idAttribute:"id",onConflict:"merge"},U=t.extend({constructor:function e(t,n){var r=this;j.classCallCheck(r,e),e.__super__.call(r),t&&!j.isArray(t)&&(n=t,t=[]),j.isString(n)&&(n={idAttribute:n}),t||(t=[]),n||(n={}),Object.defineProperties(r,{mapper:{value:void 0,writable:!0},queryClass:{value:void 0,writable:!0}}),j.fillIn(r,n),j.fillIn(r,j.copy(N)),r.queryClass||(r.queryClass=K);var i=r.recordId();Object.defineProperties(r,{index:{value:new a([i],{hashCode:function(e){return j.get(e,i)}})},indexes:{value:{}}}),t&&r.add(t)},_onRecordEvent:function(){this.emit.apply(this,arguments)},add:function(e,t){var n=this;t||(t={}),j._(t,n),e=n.beforeAdd(e,t)||e;var r=!1,i=n.recordId();if(!j.isArray(e)){if(!j.isObject(e))throw j.err(L+"#add","records")(400,"object or array",e);e=[e],r=!0}e=e.map(function(e){var r=n.recordId(e);if(!j.isSorN(r))throw j.err(L+"#add","record."+i)(400,"string or number",r);var o=n.get(r);if(e===o)return o;if(o){var a=t.onConflict||n.onConflict;if("merge"===a)j.deepMixIn(o,e);else{if("replace"!==a)throw j.err(L+"#add","opts.onConflict")(400,"one of (merge, replace)",a,!0);j.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,t):e,n.index.insertRecord(e),j.forOwn(n.indexes,function(t,n){t.insertRecord(e)}),e&&j.isFunction(e.on)&&e.on("all",n._onRecordEvent,n);return e});var o=r?e[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;j.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 j.err(L+"#getIndex",e)(404,"index");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){var t=this;return e?j.get(e,t.recordId()):t.mapper?t.mapper.idAttribute:t.idAttribute},query:function(){var e=this.queryClass;return new e(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),j.forOwn(n.indexes,function(e,t){e.removeRecord(r)}),r&&j.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),j.forOwn(t.indexes,function(t,n){t.updateRecord(e)})}}),D="belongsTo",T="hasMany",J="hasOne",q="Relation";j.addHiddenPropsToTarget(u.prototype,{getRelation:function(){return this.relatedMapper},getForeignKey:function(e){return this.type===D?j.get(e,this.foreignKey):j.get(e,this.mapper.idAttribute)},setForeignKey:function(e,t){var n=this;e&&t&&(n.type===D?j.set(e,n.foreignKey,j.get(t,n.getRelation().idAttribute)):!function(){var r=n.mapper.idAttribute;j.isArray(t)?t.forEach(function(t){j.set(t,n.foreignKey,j.get(e,r))}):j.set(t,n.foreignKey,j.get(e,r))}())},getLocalField:function(e){return j.get(e,this.localField)},setLocalField:function(e,t){return j.set(e,this.localField,t)},getInverse:function(e){var t=this;return t.inverse?t.inverse:(t.getRelation().relationList.forEach(function(n){if(n.getRelation()===e){if(n.foreignKey&&n.foreignKey!==t.foreignKey)return;return t.inverse=n,!1}}),t.inverse)}});var Q=function(e,t,n){n.name=e.name;var r=new u(t,n);Object.defineProperty(r,"mapper",{value:e}),e.relationList||Object.defineProperty(e,"relationList",{value:[]}),e.relationFields||Object.defineProperty(e,"relationFields",{value:[]}),e.relationList.push(r),e.relationFields.push(r.localField)},B=function(e,t){return t||(t={}),t.type=D,function(n){Q(n,e,t)}},$=function(e,t){return t||(t={}),t.type=T,function(n){Q(n,e,t)}},V=function(e,t){return t||(t={}),t.type=J,function(n){Q(n,e,t)}},H="Record",G=function(e,t){var n=e.datastore;return n&&n[t]?function(){for(var r=arguments.length,i=Array(r),o=0;r>o;o++)i[o]=arguments[o];return n[t].apply(n,[e.name].concat(i))}:e[t].bind(e)},W=t.extend({constructor:function e(t,n){var r=this;j.classCallCheck(r,e),t||(t={}),n||(n={});var i={};Object.defineProperties(r,{_get:{value:function(e){return j.get(i,e)}},_set:{value:function(e,t){return j.set(i,e,t)}},_unset:{value:function(e){return j.unset(i,e)}}});var o=r._set;o("creating",!0),n.noValidate&&o("noValidate",!0),j.fillIn(r,t),o("creating",!1),o("noValidate",!1),o("previous",j.copy(t))},_mapper:function(){var e=this,t=e.constructor.mapper;if(!t)throw j.err(H+"#_mapper","")(404,"mapper");return t},afterLoadRelations:function(){},beforeLoadRelations:function(){},changes:function(e){var t=this;return e||(e={}),j.diffObjects("function"==typeof t.toJSON?t.toJSON(e):t,t._get("previous"),e)},commit:function(){var e=this;return e._set("changed"),e._set("previous",j.copy(e)),e},destroy:function(e){var t=this;e||(e={});var n=t._mapper();return G(n,"destroy")(j.get(t,n.idAttribute),e)},get:function(e){return j.get(this,e)},hasChanges:function(e){var t=this,n=!!(t._get("changed")||[]).length;return n||j.areDifferent("function"==typeof t.toJSON?t.toJSON(e):t,t._get("previous"),e)},hashCode:function(){var e=this;return j.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();return e||(e=[]),j.isString(e)&&(e=[e]),t||(t={}),t.with=e,j._(t,i),t.adapter=i.getAdapterName(t),n=t.op="beforeLoadRelations",j.resolve(r[n](e,t)).then(function(){n=t.op="loadRelations",i.dbg(n,r,e,t);var o=[],a=void 0;return j.forEachRelation(i,t,function(e,n){var u=e.getRelation();if(n.raw=!1,j.isFunction(e.load))a=e.load(i,e,r,t);else if("hasMany"===e.type||"hasOne"===e.type)e.foreignKey?a=G(u,"findAll")(s.defineProperty({},e.foreignKey,j.get(r,i.idAttribute)),n).then(function(t){return"hasOne"===e.type?t.length?t[0]:void 0:t}):e.localKeys?a=G(u,"findAll")({where:s.defineProperty({},u.idAttribute,{in:j.get(r,e.localKeys)})}):e.foreignKeys&&(a=G(u,"findAll")({where:s.defineProperty({},e.foreignKeys,{contains:j.get(r,i.idAttribute)})},t));else if("belongsTo"===e.type){var c=j.get(r,e.foreignKey);j.isSorN(c)&&(a=G(u,"find")(c,n))}a&&(a=a.then(function(t){e.setLocalField(r,t)}),o.push(a))}),Promise.all(o)}).then(function(){return n=t.op="afterLoadRelations",j.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=[]),j.forOwn(t,function(r,i){i!==t._mapper().idAttribute&&!n.hasOwnProperty(i)&&t.hasOwnProperty(i)&&-1===e.preserve.indexOf(i)&&delete t[i]}),j.forOwn(n,function(n,r){-1===e.preserve.indexOf(r)&&(t[r]=n)}),t.commit(),t},save:function(e){var t=this;e||(e={});var n=t._mapper(),r=j.get(t,n.idAttribute),i=t;if(j.isUndefined(r))return G(n,"create")(i,e);if(e.changesOnly){var o=t.changes(e);i={},j.fillIn(i,o.added),j.fillIn(i,o.changed)}return G(n,"update")(r,i,e)},set:function(e,t,n){var r=this;j.isObject(e)&&(n=t),n||(n={}),n.silent&&r._set("silent",!0),j.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 j.forOwn(t,function(t,n){e[n]=j.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)}});j.eventify(W.prototype,function(){return this._get("events")},function(e){this._set("events",e)});var z="Schema",X={array:j.isArray,boolean:j.isBoolean,integer:j.isInteger,null:j.isNull,number:j.isNumber,object:j.isObject,string:j.isString},Y=function(e,t){var n="";return e&&(n+=j.isNumber(e)?"["+e+"]":t?"."+e:""+e),n},Z=function(e){e||(e={});var t="",n=e.path||[];return n.forEach(function(e){t+=Y(e,t)}),t+=Y(e.prop,t)},ee=function(e,t,n){return{expected:t,actual:""+e,path:Z(n)}},te=function(e,t,n,r){r.push(ee(e,t,n))},ne=function(e,t,n,r){var i=n[e];return t.length>i?ee(t.length,"length no more than "+i,r):void 0},re=function(e,t,n,r){var i=n[e];return t.length<i?ee(t.length,"length no less than "+i,r):void 0},ie={allOf:function(e,t,n){var r=[];return t.allOf.forEach(function(t){r=r.concat(pe(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=pe(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)?ee(e,"one of ("+r.join(", ")+")",n):void 0},items:function e(t,n,r){r||(r={});for(var e=n.items,i=[],o=j.isArray(e),a=t.length,u=0;a>u;u++)o&&(e=n.items[u]),r.prop=u,i=i.concat(pe(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)?ee(t,"no more than "+e,r):void 0},maxItems:function(e,t,n){return ne("maxItems",e,t,n)},maxLength:function(e,t,n){return ne("maxLength",e,t,n)},maxProperties:function e(t,n,r){var e=n.maxProperties,i=Object.keys(t).length;return i>e?ee(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)?ee(t,"no less than "+e,r):void 0},minItems:function(e,t,n){return re("minItems",e,t,n)},minLength:function(e,t,n){return re("minLength",e,t,n)},minProperties:function e(t,n,r){var e=n.minProperties,i=Object.keys(t).length;return e>i?ee(i,"no more than "+e+" properties",r):void 0},multipleOf:function(e,t,n){},not:function(e,t,n){return pe(e,t.not,n)?void 0:ee("succeeded","should have failed",n)},oneOf:function(e,t,n){var r=!1,i=[];return t.oneOf.forEach(function(t){var o=pe(e,t,n);if(o)i=i.concat(o);else{if(r)return i=[ee("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 j.isString(t)&&!t.match(e)?ee(t,e,r):void 0},properties:function e(t,n,r){r||(r={});var i=j.isUndefined(n.additionalProperties)?!0:n.additionalProperties,o={},e=n.properties||{},a=n.patternProperties||{},u=[];j.forOwn(t,function(e,t){o[t]=void 0}),j.forOwn(e||{},function(e,n){j.isUndefined(t[n])&&!j.isUndefined(e.default)&&(t[n]=j.copy(e.default)),r.prop=n,u=u.concat(pe(t[n],e,r)||[]),delete o[n]}),j.forOwn(a,function(e,n){j.forOwn(o,function(i,a){a.match(n)&&(r.prop=a,u=u.concat(pe(t[a],e,r)||[]),delete o[a])})});var s=Object.keys(o);return i===!1?s.length&&te("extra fields: "+s.join(", "),"no extra fields",r,u):j.isObject(i)&&s.forEach(function(e){r.prop=e,u=u.concat(pe(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(j.isUndefined(j.get(t,e))){var n=r.prop;r.prop=e,te(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(j.isString(e)&&(e=[e]),e.forEach(function(e){return X[e](t,n,r)?(i=e,!1):void 0}),!i)return ee(t?"undefined"==typeof t?"undefined":s.typeof(t):""+t,"one of ("+e.join(", ")+")",r);var o=we[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 ee(i,"no duplicates",n)}}},oe=function(e,t,n,r){return!j.isUndefined(n[e])&&ie[e](t,n,r)},ae=function(e,t,n,r){var i=[];return e.forEach(function(e){i=i.concat(oe(e,t,n,r)||[])}),i.length?i:void 0},ue=["enum","type","allOf","anyOf","oneOf","not"],se=["items","maxItems","minItems","uniqueItems"],ce=["multipleOf","maximum","minimum"],le=["maxProperties","minProperties","required","properties","dependencies"],fe=["maxLength","minLength","pattern"],de=function(e,t,n){return ae(ue,e,t,n)},pe=function e(t,n,r){var i=[];r||(r={});var o=void 0,a=r.prop;if(!j.isUndefined(n)){if(!j.isObject(n))throw j.err(z+"#validate")(500,'Invalid schema at path: "'+r.path+'"');return j.isUndefined(r.path)&&(r.path=[]),j.isUndefined(r.prop)||(o=!0,r.path.push(r.prop),r.prop=void 0),n.extends&&(i=j.isFunction(n.extends.validate)?i.concat(n.extends.validate(t,r)||[]):i.concat(e(t,n.extends,r)||[])),j.isUndefined(t)?(n.required===!0&&te(t,"a value",r,i),o&&(r.path.pop(),r.prop=a),i.length?i:void 0):(i=i.concat(de(t,n,r)||[]),o&&(r.path.pop(),r.prop=a),i.length?i:void 0)}},he="changing",ve="changed",ge="creating",ye="eventId",me="noValidate",be="silent",Ae="validation failed",_e=function(e,t,n){var r={enumerable:j.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(me)){var d=t.validate(n);if(d){var p=new Error(Ae);throw p.errors=d,p}}return t.track&&!c(ge)&&!function(){var t=c(o),a=c(i),u=c(he),s=c(ve);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(he),f(ve),c(ye)&&(clearTimeout(c(ye)),f(ye))),!u&&s.length&&(l(ve,s),l(he,!0),l(ye,setTimeout(function(){if(f(ve),f(ye),f(he),!c(be)){var e=void 0;for(e=0;e<s.length;e++)r.emit("change:"+s[e],r,j.get(r,s[e]));r.emit("change",r,r.changes())}f(be)},0)))}(),l(i,n),n},r},we={array:function(e,t,n){return ae(se,e,t,n)},integer:function(e,t,n){return we.numeric(e,t,n)},number:function(e,t,n){return we.numeric(e,t,n)},numeric:function(e,t,n){return ae(ce,e,t,n)},object:function(e,t,n){return ae(le,e,t,n)},string:function(e,t,n){return ae(fe,e,t,n)}},Oe=t.extend({constructor:function e(t){t||(t={}),j.fillIn(this,t),t.properties&&j.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||{};j.forOwn(n,function(n,r){Object.defineProperty(e,r,_e(r,n,t))})},validate:function(e,t){return pe(e,this,t)}},{typeGroupValidators:we,types:X,validate:pe,validationKeywords:ie}),xe="Mapper",Ce=function(e){return function(){for(var t=arguments.length,n=Array(t),r=0;t>r;r++)n[r]=arguments[r];var i=this,o=n[n.length-e];i.dbg.apply(i,[o.op].concat(n)),(o.notify||void 0===o.notify&&i.notify)&&setTimeout(function(){i.emit.apply(i,[o.op].concat(n))})}},Ie=Ce(1),je=Ce(2),Fe={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:[]}},Re={_adapters:{},applySchema:!0,debug:!1,defaultAdapter:"http",idAttribute:"id",notify:!0,raw:!1},Se=t.extend({constructor:function e(t){var n=this;if(j.classCallCheck(n,e),e.__super__.call(n),t||(t={}),Object.defineProperties(n,{_adapters:{value:void 0,writable:!0},recordClass:{value:void 0,writable:!0},lifecycleMethods:{value:Fe},schema:{value:void 0,writable:!0}}),j.fillIn(n,t),j.fillIn(n,j.copy(Re)),!n.name)throw j.err("new "+xe,"opts.name")(400,"string",n.name);n.schema instanceof Oe||(n.schema=new Oe(n.schema||{})),j.isUndefined(n.recordClass)&&!function(){var e=W;n.recordClass=e.extend({constructor:function(){var t=function(n,r){j.classCallCheck(this,t),e.call(this,n,r)};return t}()})}(),n.recordClass&&(n.recordClass.mapper=n,j.getSuper(n.recordClass,!0)===W&&n.schema&&n.schema.apply&&n.applySchema&&n.schema.apply(n.recordClass.prototype))},afterCount:je,afterCreate:je,afterCreateMany:je,afterDestroy:je,afterDestroyAll:je,afterFind:je,afterFindAll:je,afterSum:je,afterUpdate:je,afterUpdateAll:je,afterUpdateMany:je,beforeCreate:Ie,beforeCreateMany:Ie,beforeCount:Ie,beforeDestroy:Ie,beforeDestroyAll:Ie,beforeFind:Ie,beforeFindAll:Ie,beforeSum:Ie,beforeUpdate:Ie,beforeUpdateAll:Ie,beforeUpdateMany:Ie,_end:function(e,t,n){var r=this;if(t.raw&&j._(e,t),n)return e;var i=t.raw?e.data:e;return i&&j.isFunction(r.wrap)&&(i=r.wrap(i,t),t.raw?e.data=i:e=i),e},belongsTo:function(e,t){return B(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={}),j._(t,i),r=t.adapter=i.getAdapterName(t),n=t.op="beforeCreate",j.resolve(i[n](e,t)).then(function(o){e=j.isUndefined(o)?e:o;var a={};t.with||(t.with=[]);var u=[];return j.forEachRelation(i,t,function(t,n){var r=t.getLocalField(e),i=t.getRelation(),o=i.idAttribute;n.raw=!1,r&&(t.type===D?u.push(i.create(r,n).then(function(n){t.setLocalField(a,n),t.setForeignKey(e,n)})):t.type===T&&t.localKeys&&u.push(i.createMany(r,n).then(function(n){t.setLocalField(a,n),j.set(e,t.localKeys,n.map(function(e){return j.get(e,o)}))})))}),j.Promise.all(u).then(function(){return n=t.op="create",i.dbg(n,e,t),j.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=[],j.forEachRelation(i,t,function(t,n){var i=t.getLocalField(e);if(i){n.raw=!1;var o=void 0;t.type===T&&t.foreignKey?(t.setForeignKey(r,i),o=t.getRelation().createMany(i,n).then(function(e){t.setLocalField(r,e)})):t.type===J?(t.setForeignKey(r,i),o=t.getRelation().create(i,n).then(function(e){t.setLocalField(r,e)})):t.type===D&&t.getLocalField(a)?t.setLocalField(r,t.getLocalField(a)):t.type===T&&t.localKeys&&t.getLocalField(a)&&t.setLocalField(r,t.getLocalField(a)),o&&u.push(o)}}),j.Promise.all(u).then(function(){return n})})}).then(function(r){return r=i._end(r,t),n=t.op="afterCreate",j.resolve(i[n](e,t,r)).then(function(e){return j.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={}),j._(t,i),r=t.adapter=i.getAdapterName(t),n=t.op="beforeCreateMany",j.resolve(i[n](e,t)).then(function(o){e=j.isUndefined(o)?e:o;var a={};t.with||(t.with=[]);var u=[];return j.forEachRelation(i,t,function(t,n){var r=e.map(function(e){return t.getLocalField(e)}).filter(function(e){return e});t.type===D&&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])})}))}),j.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),j.resolve(i.getAdapter(r)[n](i,o,t))}).then(function(n){var r=t.raw?n.data:n;return u=[],j.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===T?i.log("warn","deep createMany of hasMany type not supported!"):n.type===J?(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===D&&c&&c.length===r.length&&r.forEach(function(e,t){n.setLocalField(e,c[t])}),l&&u.push(l)}}),j.Promise.all(u).then(function(){return n})})}).then(function(r){return r=i._end(r,t),n=t.op="afterCreateMany",j.resolve(i[n](e,t,r)).then(function(e){return j.isUndefined(e)?r:e})})},createRecord:function(e,t){e||(e={});var n=this;if(j.isArray(e))return e.map(function(e){return n.createRecord(e,t)});if(!j.isObject(e))throw j.err(xe+"#createRecord","props")(400,"array or object",e);var r=n.recordClass,i=n.relationList||[];return i.forEach(function(n){var r=n.getRelation(),i=n.getLocalField(e);if(i&&!r.is(i)){if(j.isArray(i)&&(!i.length||r.is(i[0])))return;j.set(e,n.localField,r.createRecord(i,t))}}),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 j.err(xe+"#crud",e)(404,"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){j.isUndefined(n[t])&&(n[t]=j.copy(e))});var d=n[n.length-1];return j._(d,i),f=d.adapter=i.getAdapterName(d),l=d.op=u,j.resolve(i[l].apply(i,s.toConsumableArray(n))).then(function(t){var r;return j.isUndefined(o.beforeAssign)||(n[o.beforeAssign]=j.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))),j.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,j.resolve(i[l].apply(i,s.toConsumableArray(n))).then(function(t){return j.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 j.err(xe+"#getAdapter","name")(400,"string",e);return t.getAdapters()[n]},getAdapterName:function(e){return e||(e={}),j.isString(e)&&(e={adapter:e}),e.adapter||e.defaultAdapter},getAdapters:function(){return this._adapters},getSchema:function(){return this.schema},hasMany:function(e,t){return $(e,t)(this)},hasOne:function(e,t){return V(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,r=void 0;if(t||(t={}),j.isArray(e))return e.map(function(e){return n.toJSON(e,t)});r=e;var i=(n?n.relationFields:[])||[],o={},a=void 0;if(n&&n.schema&&(a=n.schema.properties||{},j.forOwn(a,function(e,t){o[t]=j.plainCopy(r[t])})),a||(a={}),!t.strict)for(var u in r)a[u]||-1!==i.indexOf(u)||(o[u]=j.plainCopy(r[u]));return n&&t.withAll&&(t.with=i.slice()),n&&t.with&&(j.isString(t.with)&&(t.with=[t.with]),j.forEachRelation(n,t,function(e,t){var n=e.getLocalField(r);n&&(j.isArray(n)?e.setLocalField(o,n.map(function(n){return e.getRelation().toJSON(n,t)})):e.setLocalField(o,e.getRelation().toJSON(n,t)))})),o},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,r=n.getSchema();if(!j.isArray(e))return r.validate(e,t);var i=e.map(function(e){return r.validate(e,t)}),o=!1;return i.forEach(function(e){e&&(o=!0)}),o?i:void 0},wrap:function(e,t){return this.createRecord(e,t)}}),Ee="Container",ke=["count","create","createMany","createRecord","dbg","destroy","destroyAll","find","findAll","getSchema","is","log","sum","toJSON","update","updateAll","updateMany","validate"],Pe={constructor:function e(t){var n=this;j.classCallCheck(n,e),e.__super__.call(n),t||(t={}),j.fillIn(n,t),n.mapperDefaults=n.mapperDefaults||{},n.mapperClass=n.mapperClass||Se,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(j.isObject(e)&&(t=e,e=t.name),!j.isString(e))throw j.err(Ee+"#defineMapper","name")(400,"string",e);t||(t={}),t.name=e,t.relations||(t.relations={});var r=t.mapperClass||n.mapperClass;delete t.mapperClass,j.fillIn(t,n.mapperDefaults);var i=n._mappers[e]=new r(t);return i.relations||(i.relations={}),i.name=e,i._adapters=n.getAdapters(),i.datastore=n,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))}),j.forOwn(i.relations,function(e,t){j.forOwn(e,function(e,r){j.isObject(e)&&(e=[e]),e.forEach(function(e){e.getRelation=function(){return n.getMapper(r)};var o=n._mappers[r]||r;t===D?i.belongsTo(o,e):t===J?i.hasOne(o,e):t===T&&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 j.err(Ee+"#getAdapter","name")(400,"string",e);return t.getAdapters()[n]},getAdapterName:function(e){return e||(e={}),j.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 j.err(Ee+"#getMapper",e)(404,"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,j.forOwn(r._mappers,function(t){t.defaultAdapter=e}))}};ke.forEach(function(e){Pe[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 Me=t.extend(Pe),Ke="LinkedCollection",Le=U.extend({constructor:function e(t,n){var r=this;if(j.classCallCheck(r,e),e.__super__.call(r,t,n),Object.defineProperty(r,"_added",{value:{}}),!r.datastore)throw j.err("new "+Ke,"opts.datastore")(400,"DataStore",r.datastore);return r},_onRecordEvent:function(){for(var e=this,t=arguments.length,n=Array(t),r=0;t>r;r++)n[r]=arguments[r];j.getSuper(e).prototype._onRecordEvent.apply(e,n);var i=n[0];j.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,c=i.idAttribute,l=void 0;return j.isObject(e)&&!j.isArray(e)&&(l=!0,e=[e]),e=j.getSuper(n).prototype.add.call(n,e,t),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),l=t.type,f=l===T,d=j.isUndefined(t.add)?!0:!!t.add,p=void 0;e.forEach(function(e){p=t.getLocalField(e);var n=j.get(e,c);if(j.isFunction(t.add))p=t.add(r,t,e);else if(p)if(f)p=p.map(function(n){return n!==u.get(u.recordId(n))&&(a&&t.setForeignKey(e,n),d&&(n=u.add(n))),n});else{var i=j.get(p,o);p!==u.get(i)&&(t.setForeignKey(e,p),d&&(p=u.add(p)))}if(!p||j.isArray(p)&&!p.length)if(l===D){var h=j.get(e,a);j.isUndefined(h)||(p=u.get(h))}else if(l===J){var v=u.filter(s.defineProperty({},a,n));p=v.length?v[0]:void 0}else if(l===T)if(a){var g=u.filter(s.defineProperty({},a,n));p=g.length?g:void 0}else if(t.localKeys&&j.get(e,t.localKeys)){var y=u.filter({where:s.defineProperty({},o,{in:j.get(e,t.localKeys)})});p=y.length?y:void 0}else if(t.foreignKeys){var m=u.filter({where:s.defineProperty({},t.foreignKeys,{contains:n})});p=m.length?m:void 0}p&&t.setLocalField(e,p)})}),e.forEach(function(e){n._added[n.recordId(e)]=a,u&&e._set("$",a)}),l?e[0]:e},remove:function(e,t){var n=this,r=n.mapper,i=j.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=j.getSuper(n).prototype.removeAll.call(n,e,t);return i.forEach(function(e){delete n._added[n.recordId(e)],r.recordClass&&e._set("$")}),i}}),Ne="DataStore",Ue=function(e,t,n){e&&e._set?e._set(t,n):j.set(e,t,n)},De=function(e,t,n){var r=this,i=r._completedQueries[e][t];return j.isFunction(i)?i(e,t,n):i},Te={constructor:function e(t){var n=this;return j.classCallCheck(n,e),e.__super__.call(n,t),n.collectionClass=n.collectionClass||Le,n._collections={},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){var r=n.raw?t.data:t;return r&&j.isFunction(this.addToCache)&&(r=this.addToCache(e,r,n),n.raw?t.data=r:t=r),t},_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))},addToCache:function(e,t,n){return this.getCollection(e).add(t,n)},cachedFind:De,cachedFindAll:De,cacheFind:function(e,t,n,r){var i=this;i._completedQueries[e][n]=function(e,t,n){return i.get(e,t)}},cacheFindAll:function(e,t,n,r){var i=this;i._completedQueries[e][n]=function(e,t,n){return i.filter(e,j.fromJson(t))}},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=j.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||{};j.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=r.idAttribute;return r.relationList.forEach(function(e){var t=e.relation,o=e.localField,a="links."+o,s=e.foreignKey,c=e.type,l={index:s},f=void 0,d=function(){return this._get(a)};c===D?(i.indexes[s]||i.createIndex(s),f={get:d,set:function(o){var c=this,f=this._get(a);if(o===f)return f;var d=j.get(c,u),p=e.getInverse(r);if(o){var h=e.getRelation().idAttribute,v=j.get(o,h);if(j.isUndefined(v)||(o=n.get(t,v)||o),c._set(a,o),Ue(c,s,v),i.updateIndex(c,l),p.type===J)j.set(o,p.localField,c);else if(p.type===T){var g=j.get(o,p.localField);j.noDupeAdd(g,c,function(e){return d===j.get(e,u)})}}else c._set(a,void 0),Ue(c,s,void 0),i.updateIndex(c,l);if(f)if(p.type===J)j.set(f,p.localField,void 0);else if(p.type===T){var y=j.get(f,p.localField);j.remove(y,function(e){return d===j.get(e,u)})}return o}},r.recordClass.prototype.hasOwnProperty(s)&&!function(){var e=r.recordClass;r.recordClass=e.extend({constructor:function(){var t=function(n,r){j.classCallCheck(this,t),e.call(this,n,r)};return t}()})}(),Object.defineProperty(r.recordClass.prototype,s,{enumerable:!0,get:function(){return this._get(s)},set:function(e){var r=this;if(j.isUndefined(e))j.set(r,o,void 0);else{Ue(r,s,e);var i=n.get(t,e);i&&j.set(r,o,i)}}})):c===T?!function(){var i=e.localKeys,o=e.foreignKeys;n._collections[t]&&s&&!n.getCollection(t).indexes[s]&&n.getCollection(t).createIndex(s),f={get:function(){var e=this,t=d.call(e);return t||e._set(a,[]),d.call(e)},set:function(c){var f=this;c||(c=[]),c&&!j.isArray(c)&&(c=[c]);var d=j.get(f,u),p=e.getRelation().idAttribute,h=e.getInverse(r),v=h.localField,g=f._get(a);g||(g=[]);var y=g;g=[];var m={};return c.forEach(function(e){var r=j.get(e,p);j.isUndefined(r)||(e=n.get(t,r)||e,m[r]=e),g.push(e)}),s?(c.forEach(function(e){Ue(e,s,d),n.getCollection(t).updateIndex(e,l),j.set(e,v,f)}),y.forEach(function(e){var r=j.get(e,p);j.isUndefined(r)||m.hasOwnProperty(r)||(Ue(e,s,void 0),n.getCollection(t).updateIndex(e,l),j.set(e,v,void 0))})):i?!function(){var e=[];c.forEach(function(t){j.set(t,v,f),e.push(j.get(t,p))}),j.set(f,i,e),y.forEach(function(e){var t=j.get(e,p);j.isUndefined(t)||m.hasOwnProperty(t)||j.set(e,v,void 0)})}():o&&(y.forEach(function(e){var t=j.get(e,o)||[];j.remove(t,function(e){return d===e});var n=j.get(e,v)||[];j.remove(n,function(e){return d===j.get(e,u)})}),c.forEach(function(e){var t=j.get(e,o)||[];j.noDupeAdd(t,d,function(e){return d===e});var n=j.get(e,v)||[];j.noDupeAdd(n,f,function(e){return d===j.get(e,u)})})),f._set(a,g),g}}}():c===J&&(n._collections[t]&&s&&!n.getCollection(t).indexes[s]&&n.getCollection(t).createIndex(s),f={get:d,set:function(i){var o=this,c=this._get(a);if(i===c)return c;var f=j.get(i,e.getRelation().idAttribute),d=e.getInverse(r).localField;return c&&(Ue(c,s,void 0),n.getCollection(t).updateIndex(c,l),j.set(c,d,void 0)),i?(j.isUndefined(f)||(i=n.get(t,f)||i),o._set(a,i),Ue(i,s,j.get(o,u)),n.getCollection(t).updateIndex(i,l),j.set(i,d,o)):o._set(a,void 0),i}}),f&&(f.enumerable=j.isUndefined(e.enumerable)?!1:e.enumerable,e.get&&!function(){var t=f.get;f.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=f.set;f.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,f))}),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(j.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){delete r._pendingQueries[e][t];var o=r._end(e,i,n);return r.cacheFind(e,o,t,n),o},function(n){return delete r._pendingQueries[e][t],j.reject(n)}):j.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(j.fillIn(n,r.getMapper(e)),o)return o;var a=r.cachedFindAll(e,i,n),u=void 0;return u=n.force||!a?r._pendingQueries[e][i]=r._callSuper("findAll",e,t,n).then(function(t){delete r._pendingQueries[e][i];var o=r._end(e,t,n);return r.cacheFindAll(e,o,i,n),o},function(t){return delete r._pendingQueries[e][i],j.reject(t)}):j.resolve(a)},getCollection:function(e){var t=this._collections[e];if(!t)throw j.err(Ne+"#getCollection",e)(404,"collection");return t},hashQuery:function(e,t,n){return j.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;j.forEachRelation(r.getMapper(e),n,function(e,n){t.forEach(function(t){var i=void 0,o=void 0;if(!e.foreignKey||e.type!==J&&e.type!==T?e.type===T&&e.localKeys?o={where:s.defineProperty({},e.getRelation().idAttribute,{in:j.get(t,e.localKeys)})}:e.type===T&&e.foreignKeys?o={where:s.defineProperty({},e.foreignKeys,{contains:e.getForeignKey(t)})}:e.type===D&&(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(j.isArray(i)&&!i.length)return;e.type===J&&(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)})}},Je=["add","between","createIndex","filter","get","getAll","query","toJson"];Je.forEach(function(e){Te[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 qe=Me.extend(Te),Qe={beta:5,full:"3.0.0-beta.5",major:3,minor:0,patch:0};e.version=Qe,e.Collection=U,e.Component=t,e.Container=Me,e.DataStore=qe,e.Index=a,e.LinkedCollection=Le,e.Mapper=Se,e.Query=K,e.Record=W,e.Schema=Oe,e.utils=j,e.belongsToType=D,e.hasManyType=T,e.hasOneType=J,e.belongsTo=B,e.hasMany=$,e.hasOne=V}); | ||
//# sourceMappingURL=js-data.min.map |
@@ -18,4 +18,4 @@ // Copyright (c) 2015, InternalFX. | ||
// Summary of modifications: | ||
// Converted to ES6 Class syntax | ||
// Reworked dependencies so as to re-use code already in js-data | ||
// Removed unused code | ||
import utils from '../../src/utils' | ||
@@ -99,11 +99,25 @@ import {binarySearch, insertAt, removeAt} from './_utils' | ||
getAll () { | ||
getAll (opts) { | ||
opts || (opts = {}) | ||
let results = [] | ||
this.values.forEach(function (value) { | ||
if (value.isIndex) { | ||
results = results.concat(value.getAll()) | ||
} else { | ||
results = results.concat(value) | ||
const values = this.values | ||
if (opts.order === 'desc') { | ||
for (let i = values.length - 1; i >= 0; i--) { | ||
const value = values[i] | ||
if (value.isIndex) { | ||
results = results.concat(value.getAll(opts)) | ||
} else { | ||
results = results.concat(value) | ||
} | ||
} | ||
}) | ||
} else { | ||
for (let i = 0; i < values.length; i++) { | ||
const value = values[i] | ||
if (value.isIndex) { | ||
results = results.concat(value.getAll(opts)) | ||
} else { | ||
results = results.concat(value) | ||
} | ||
} | ||
} | ||
return results | ||
@@ -110,0 +124,0 @@ }, |
{ | ||
"name": "js-data", | ||
"description": "Robust, framework-agnostic in-memory data store.", | ||
"version": "3.0.0-beta.4", | ||
"version": "3.0.0-beta.5", | ||
"homepage": "http://www.js-data.io", | ||
@@ -85,3 +85,3 @@ "repository": { | ||
"karma-sinon": "1.0.5", | ||
"nyc": "6.4.2", | ||
"nyc": "6.4.3", | ||
"phantomjs-prebuilt": "2.1.7", | ||
@@ -88,0 +88,0 @@ "rollup": "0.26.2", |
<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 v3 beta](http://www.js-data.io/) [![Slack Status][b1]][b2] [![npm version][b3]][b4] [![npm downloads][b5]][b6] | ||
# [js-data v3 beta](http://www.js-data.io/) [![Slack Status][b1]][b2] [![npm version][b3]][b4] [![npm downloads][b5]][b6] [![coverage][b15]][b16] | ||
@@ -5,0 +5,0 @@ | __Browser tests__ | __Node.js tests__ | |
@@ -629,3 +629,6 @@ /** | ||
const ctor = isCtor ? instance : instance.constructor | ||
return (ctor.__super__ || Object.getPrototypeOf(ctor) || ctor.__proto__) // eslint-disable-line | ||
if (ctor.hasOwnProperty('__super__')) { | ||
return ctor.__super__ | ||
} | ||
return Object.getPrototypeOf(ctor) || ctor.__proto__ // eslint-disable-line | ||
}, | ||
@@ -632,0 +635,0 @@ |
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
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
1765541
24369