Comparing version 3.0.0-alpha.20 to 3.0.0-alpha.21
@@ -0,1 +1,13 @@ | ||
##### 3.0.0-alpha.21 - 22 March 2016 | ||
###### Backwards compatible API changes | ||
- #195 - Add "with" to remove/removeAll (eject/ejectAll) to also remove relations | ||
- Added `Mapper#validate(record[, opts])`, `Record#validate([opts])` and `Record#isValid()` | ||
###### Backwards compatible bug fixes | ||
- #263 - orderBy with undefined values doesn't order (though null works) | ||
###### Other | ||
- Updated js-data.d.ts | ||
##### 3.0.0-alpha.20 - 18 March 2016 | ||
@@ -8,3 +20,7 @@ | ||
- Passive change detection now possible with changes to Record#changes() and Record#hasChanges(), see #313 | ||
- #283 - Added sum and count methods | ||
###### Backwards compatible big fixes | ||
- Container and DataStore now proxy all Mapper methods | ||
##### 3.0.0-alpha.19 - 14 March 2016 | ||
@@ -11,0 +27,0 @@ |
/*! | ||
* js-data | ||
* @version 3.0.0-alpha.20 - Homepage <http://www.js-data.io/> | ||
* @version 3.0.0-alpha.21 - 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(e){g.classCallCheck(this,t),this.collection=e,this.data=null}function n(e){return e.replace(L,"\\$1")}function r(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 i(e,t,n){return e.splice(t,0,n),e}function o(e,t){return e.splice(t,1),e}function a(e,t,n){for(var i=0,o=e.length,a=void 0,u=void 0;o>i;){if(u=(i+o)/2|0,a=r(t,e[u],n),0===a)return{found:!0,index:u};0>a?o=u:i=u+1}return{found:!1,index:o}}function u(e,t){if(g.classCallCheck(this,u),e||(e=[]),!g.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 s(e,t){var n=this;g.classCallCheck(n,s),g.isObject(e)&&!g.isArray(e)&&(t=e,e=[]),g.isString(t)&&(t={idAttribute:t}),e||(e=[]),t||(t={}),t.recordOpts||(t.recordOpts={}),g.fillIn(n,t),g.fillIn(n,T),n._listeners={};var r=n.recordId();n.index=new u([r],{hashCode:function(e){return g.get(e,r)}}),n.indexes={},e.forEach(function(e){e=n.mapper?n.mapper.createRecord(e,n.recordOpts):e,n.index.insertRecord(e),e&&g.isFunction(e.on)&&e.on("all",n._onRecordEvent,n)})}function c(e,t){var n=this;t||(t={});var r=t.localField;if(!r)throw new Error("localField is required");var i=t.foreignKey=t.foreignKey||t.localKey;if(!i&&(t.type===K||t.type===q))throw new Error("foreignKey is required");var o=t.localKeys,a=t.foreignKeys;if(!i&&!o&&!a&&t.type===D)throw new Error("one of (foreignKey, localKeys, foreignKeys) is required");if(g.isString(e)){if(t.relation=e,!g.isFunction(t.getRelation))throw new Error("you must provide a reference to the related mapper!")}else e&&(t.relation=e.name,Object.defineProperty(n,"relatedMapper",{value:e}));g.fillIn(n,t)}function f(e,t){var n=this;g.classCallCheck(n,f),e||(e={}),t||(t={});var r={};Object.defineProperties(n,{_get:{value:function(e){return g.get(r,e)}},_set:{value:function(e,t){return g.set(r,e,t)}},_unset:{value:function(e){return g.unset(r,e)}}});var i=n._set;i("creating",!0),t.noValidate&&i("noValidate",!0),g.fillIn(n,e),i("creating"),i("noValidate"),i("previous",g.copy(e))}function l(e){e||(e={}),g.fillIn(this,e),e.properties&&g.forOwn(e.properties,function(t,n){t instanceof l||(e.properties[n]=new l(t))})}function d(e){var t=this;if(g.classCallCheck(t,d),e||(e={}),Object.defineProperty(t,"_adapters",{value:void 0,writable:!0}),Object.defineProperty(t,"_listeners",{value:void 0,writable:!0}),Object.defineProperty(t,"RecordClass",{value:void 0,writable:!0}),g.fillIn(t,e),g.fillIn(t,g.copy(Ae)),!t.name)throw new Error("mapper cannot function without a name!");t._adapters||(t._adapters={}),t._listeners||(t._listeners={}),t.schema instanceof l||(t.schema=new l(t.schema||{})),g.isUndefined(t.RecordClass)&&(t.RecordClass=f.extend()),t.RecordClass&&(t.RecordClass.Mapper=t,g.getSuper(t.RecordClass,!0)===f&&t.applySchema&&me(t.schema,t.RecordClass.prototype))}function p(e){var t=this;g.classCallCheck(t,p),e||(e={}),g.fillIn(t,e),t.mapperDefaults=t.mapperDefaults||{},t.MapperClass=t.MapperClass||d,t._adapters={},t._mappers={}}var h={};h.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},h.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};var v={},g=v,y=1/0,m=1.7976931348623157e308,b="[object Boolean]",w="[object Date]",A="[object Function]",_="[object Number]",O="[object Object]",x="[object RegExp]",C="[object String]",R=Object.prototype.toString;try{v.isBrowser=!!window}catch(e){v.isBrowser=!1}v.Promise=Promise;var E=function(e){return R.call(e)},j=function(e){if(!e)return 0===e?e:0;if(e=+e,e===y||e===-y){var t=0>e?-1:1;return t*m}var n=e%1;return e===e?n?e-n:e:0},I=function(e){return!!e&&"object"===("undefined"==typeof e?"undefined":h.typeof(e))&&e.constructor===Object};v.isArray=Array.isArray,v.isDate=function(e){return e&&"object"===("undefined"==typeof e?"undefined":h.typeof(e))&&E(e)===w},v.isFunction=function(e){return"function"==typeof e||e&&E(e)===A},v.isInteger=function(e){return E(e)===_&&e==j(e)},v.isNull=function(e){return null===e},v.isNumber=function(e){var t="undefined"==typeof e?"undefined":h.typeof(e);return"number"===t||e&&"object"===t&&E(e)===_},v.isObject=function(e){return E(e)===O},v.isRegExp=function(e){return E(e)===x},v.isSorN=function(e){return v.isString(e)||v.isNumber(e)},v.isString=function(e){return"string"==typeof e||e&&"object"===("undefined"==typeof e?"undefined":h.typeof(e))&&E(e)===C},v.isUndefined=function(e){return void 0===e},v.isBoolean=function(e){return E(e)===b},v.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]}};var S=function(e,t){if(!t)return e;var n=t.split(".");return n.forEach(function(t){e[t]||(e[t]={}),e=e[t]}),e},F=/^(.+)\.(.+)$/;v.set=function(e,t,n){if(v.isObject(t))v.forOwn(t,function(t,n){v.set(e,n,t)});else{var r=F.exec(t);r?S(e,r[1])[r[2]]=n:e[t]=n}},v.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,delete e[r]},v.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)},v.deepMixIn=function(e,t){return t&&v.forOwn(t,function(e,t){var n=this[t];I(e)&&I(n)?v.deepMixIn(n,e):this[t]=e},e),e},v.deepFillIn=function(e,t){return t&&v.forOwn(t,function(e,t){var n=this[t];I(e)&&I(n)?v.deeputils.FillIn(n,e):this.hasOwnProperty(t)&&void 0!==this[t]||(this[t]=e)},e),e},v.resolve=function(e){return v.Promise.resolve(e)},v.reject=function(e){return v.Promise.reject(e)},v._=function(e,t){for(var n in e){var r=e[n];void 0===t[n]&&!v.isFunction(r)&&n&&0!==n.indexOf("_")&&(t[n]=r)}},v.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},v.fillIn=function(e,t){v.forOwn(t,function(t,n){e.hasOwnProperty(n)&&void 0!==e[n]||(e[n]=t)})},v.isBlacklisted=function(e,t){if(!t||!t.length)return!1;for(var n=void 0,r=0;r<t.length;r++)if(E(t[r])===x&&t[r].test(e)||t[r]===e)return n=e;return!!n},v.fromJson=function(e){return v.isString(e)?JSON.parse(e):e},v.toJson=JSON.stringify,v.copy=function(e,t,n,r,i,o){if(t){if(e===t)throw new Error("Cannot copy! Source and destination are identical.");if(n=n||[],r=r||[],v.isObject(e)){var a=n.indexOf(e);if(-1!==a)return r[a];n.push(e),r.push(t)}var u=void 0;if(v.isArray(e)){var s=void 0;for(t.length=0,s=0;s<e.length;s++)u=v.copy(e[s],null,n,r,i,o),v.isObject(e[s])&&(n.push(e[s]),r.push(u)),t.push(u)}else{v.isArray(t)?t.length=0:v.forOwn(t,function(e,n){delete t[n]});for(var c in e)if(e.hasOwnProperty(c)){if(v.isBlacklisted(c,i))continue;u=v.copy(e[c],null,n,r,i,o),v.isObject(e[c])&&(n.push(e[c]),r.push(u)),t[c]=u}}}else t=e,e&&(v.isArray(e)?t=v.copy(e,[],n,r,i,o):v.isDate(e)?t=new Date(e.getTime()):v.isRegExp(e)?(t=new RegExp(e.source,e.toString().match(/[^\/]*$/)[0]),t.lastIndex=e.lastIndex):v.isObject(e)&&(t=o?v.copy(e,{},n,r,i,o):v.copy(e,Object.create(Object.getPrototypeOf(e)),n,r,i,o)));return t},v.plainCopy=function(e){return v.copy(e,void 0,void 0,void 0,void 0,!0)},v.eventify=function(e,t,n,r){e=e||this;var i={};t||n||(t=function(){return i},n=function(e){i=e}),Object.defineProperties(e,{on:{enumerable:!!r,value:function(e,r,i){t.call(this)||n.call(this,{});var o=t.call(this);o[e]=o[e]||[],o[e].push({f:r,c:i})}},off:{enumerable:!!r,value:function(e,r){var i=t.call(this),o=i[e];if(o)if(r){for(var a=0;a<o.length;a++)if(o[a].f===r){o.splice(a,1);break}}else o.splice(0,o.length);else n.call(this,{})}},emit:{enumerable:!!r,value:function(){for(var e=t.call(this)||{},n=arguments.length,r=Array(n),i=0;n>i;i++)r[i]=arguments[i];var o=r.shift(),a=e[o]||[],u=void 0;for(u=0;u<a.length;u++)a[u].f.apply(a[u].c,r);for(a=e.all||[],r.unshift(o),u=0;u<a.length;u++)a[u].f.apply(a[u].c,r)}}})},v.classCallCheck=function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")},v.possibleConstructorReturn=function(e,t){if(!e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return!t||"object"!==("undefined"==typeof t?"undefined":h.typeof(t))&&"function"!=typeof t?e:t},v.addHiddenPropsToTarget=function(e,t){v.forOwn(t,function(e,n){t[n]={writable:!0,value:e}}),Object.defineProperties(e,t)},v.extend=function(e,t){var n=this,r=void 0;return e||(e={}),t||(t={}),e.hasOwnProperty("constructor")?(r=e.constructor,delete e.constructor):r=function(){v.classCallCheck(this,r);for(var e=arguments.length,t=Array(e),n=0;e>n;n++)t[n]=arguments[n];var i=v.possibleConstructorReturn(this,(r.__super__||Object.getPrototypeOf(r)).apply(this,t));return i},r.prototype=Object.create(n&&n.prototype,{constructor:{value:r,enumerable:!1,writable:!0,configurable:!0}}),Object.setPrototypeOf?Object.setPrototypeOf(r,n):t.strictEs6Class?r.__proto__=n:v.forOwn(n,function(e,t){r[t]=e}),Object.defineProperty(r,"__super__",{configurable:!0,value:n}),v.addHiddenPropsToTarget(r.prototype,e),v.fillIn(r,t),r},v.getSuper=function(e,t){var n=t?e:e.constructor;return n.__super__||Object.getPrototypeOf(n)||n.__proto__};var k=function(e,t){var n=-1;return e.forEach(function(e,r){return e===t?(n=r,!1):v.isObject(e)&&e.relation===t?(n=r,!1):void 0}),n},P=function(e,t,n,r){var i=t.relation,o=null,a=void 0;if(e||(e={}),e.with||(e.with=[]),(a=k(e.with,i))>=0?o=i:(a=k(e.with,t.localField))>=0&&(o=t.localField),e.withAll)return void n.call(r,t,{});if(o){var u={};v.fillIn(u,t.getRelation()),v.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)}};v.forEachRelation=function(e,t,n,r){var i=e.relationList||[];i.length&&i.forEach(function(e){P(t,e,n,r)})},v.omit=function(e,t){var n={};return v.forOwn(e,function(e,r){-1===t.indexOf(r)&&(n[r]=e)}),n},v.equal=function(e,t){return e==t},v.strictEqual=function(e,t){var n=e===t;return n||(v.isObject(e)&&v.isObject(t)?(v.forOwn(e,function(e,r){n=n&&v.strictEqual(e,t[r])}),v.forOwn(t,function(t,r){n=n&&v.strictEqual(t,e[r])})):v.isArray(e)&&v.isArray(t)&&e.forEach(function(e,r){n=n&&v.strictEqual(e,t[r])})),n},v.diffObjects=function(e,t,n){n||(n={});var r=n.equalsFn,i=n.ignore,o={added:{},removed:{},changed:{}};return v.isFunction(r)||(r=v.strictEqual),v.forOwn(t,function(t,n){var a=e[n];v.isBlacklisted(n,i)||r(a,t)||(v.isUndefined(a)?o.removed[n]=void 0:r(a,t)||(o.changed[n]=a))}),v.forOwn(e,function(e,n){v.isUndefined(t[n])&&!v.isBlacklisted(n,i)&&(o.added[n]=e)}),o},v.areDifferent=function(e,t,n){n||(n={});var r=v.diffObjects(e,t,n),i=Object.keys(r.added).length+Object.keys(r.removed).length+Object.keys(r.changed).length;return i>0},t.extend=g.extend;var M={skip:"",offset:"",where:"",limit:"",orderBy:"",sort:""},L=/([.*+?^=!:${}()|[\]\/\\])/g,N=/%/g,U=/_/g;t.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!g.intersection(e||[],t||[]).length},isectNotEmpty:function(e,t){return g.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)}},g.addHiddenPropsToTarget(t.prototype,{compare:function(e,t,n,r){var i=e[t],o=g.get(n,i[0]),a=g.get(r,i[0]);return o&&g.isString(o)&&(o=o.toUpperCase()),a&&g.isString(a)&&(a=a.toUpperCase()),n||(n=null),r||(r=null),"DESC"===i[1]?o>a?-1:a>o?1:t<e.length-1?this.compare(e,t+1,n,r):0:a>o?-1:o>a?1:t<e.length-1?this.compare(e,t+1,n,r):0},evaluate:function(e,n,r){return t.ops[n]?t.ops[n](e,r):0===n.indexOf("like")?!g.isNull(this.like(r,n.substr(4)).exec(e)):0===n.indexOf("notLike")?g.isNull(this.like(r,n.substr(7)).exec(e)):void 0},like:function(e,t){return new RegExp("^"+n(e).replace(N,".*").replace(U,".")+"$",t)},getData:function(){var e=this;return e.data||(e.data=e.collection.index.getAll()),e.data},between:function(e,t,n){var r=this;if(n||(n={}),r.data)throw new Error("Cannot access index after first operation!");return r.data=r.collection.getIndex(n.index).between(e,t,n),r},get:function(){var e=arguments.length<=0||void 0===arguments[0]?[]:arguments[0],t=arguments[1],n=this;if(t||(t={}),n.data)throw new Error("Cannot access index after first operation!");return e&&!g.isArray(e)&&(e=[e]),e.length?(n.data=n.collection.getIndex(t.index).get(e),n):(n.getData(),n)},getAll:function(){var e=this,t={};if(e.data)throw new Error("Cannot access index after first operation!");for(var n=arguments.length,r=Array(n),i=0;n>i;i++)r[i]=arguments[i];if(!r.length||1===r.length&&g.isObject(r[0]))return e.getData(),e;r.length&&g.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},filter:function(e,t){var n=this;return e||(e={}),n.getData(),g.isObject(e)?!function(){var t={};g.isObject(e.where)&&(t=e.where),g.forOwn(e,function(e,n){n in M||n in t||(t[n]={"==":e})});var r=[],i=[],o=[];g.forOwn(t,function(e,t){g.isObject(e)||(e={"==":e}),g.forOwn(e,function(e,n){r.push(t),i.push(n),o.push(e)})}),r.length&&!function(){var e=void 0,t=r.length;n.data=n.data.filter(function(a){var u=!0,s=!0;for(e=0;t>e;e++){var c=i[e],f="|"===c.charAt(0);c=f?c.substr(1):c;var l=n.evaluate(g.get(a,r[e]),c,o[e]);void 0!==l&&(s=u?l:f?s||l:s&&l),u=!1}return s})}();var a=e.orderBy||e.sort;g.isString(a)&&(a=[[a,"ASC"]]),g.isArray(a)||(a=null),a&&!function(){var e=0;a.forEach(function(e,t){g.isString(e)&&(a[t]=[e,"ASC"])}),n.data.sort(function(t,r){return n.compare(a,e,t,r)})}(),g.isNumber(e.skip)?n.skip(e.skip):g.isNumber(e.offset)&&n.skip(e.offset),g.isNumber(e.limit)&&n.limit(e.limit)}():g.isFunction(e)&&(n.data=n.data.filter(e,t)),n},skip:function(e){if(!g.isNumber(e))throw new TypeError("skip: Expected number but found "+("undefined"==typeof e?"undefined":h.typeof(e))+"!");var t=this.getData();return e<t.length?this.data=t.slice(e):this.data=[],this},limit:function(e){if(!g.isNumber(e))throw new TypeError("limit: Expected number but found "+("undefined"==typeof e?"undefined":h.typeof(e))+"!");var t=this.getData();return this.data=t.slice(0,Math.min(t.length,e)),this},forEach:function(e,t){return this.getData().forEach(e,t),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}}),g.addHiddenPropsToTarget(u.prototype,{set:function(e,t){g.isArray(e)||(e=[e]);var n=e.shift()||null,r=a(this.keys,n);if(0===e.length)if(r.found){var o=a(this.values[r.index],t,this.hashCode);o.found||i(this.values[r.index],o.index,t)}else i(this.keys,r.index,n),i(this.values,r.index,[t]);else if(r.found)this.values[r.index].set(e,t);else{i(this.keys,r.index,n);var s=new u([],{hashCode:this.hashCode});s.set(e,t),i(this.values,r.index,s)}},get:function(e){g.isArray(e)||(e=[e]);var t=e.shift()||null,n=a(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){var n=arguments.length<=2||void 0===arguments[2]?{}:arguments[2];g.isArray(e)||(e=[e]),g.isArray(t)||(t=[t]),g.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(),o=t.shift(),u=void 0;if(u=void 0!==i?a(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!==o)if(n.rightInclusive){if(this.keys[s]>o)break}else if(this.keys[s]>=o)break;if(r=this.values[s].isIndex?r.concat(this.values[s].getAll()):r.concat(this.values[s]),n.limit&&r.length>=n.limit+n.offset)break}}else for(var c=u.index;c<this.keys.length;c+=1){var f=this.keys[c];if(f>o)break;if(r=this.values[c].isIndex?f===i?r.concat(this.values[c]._between(copy(e),t.map(function(){}),n)):f===o?r.concat(this.values[c]._between(e.map(function(){}),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 g.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,i){if(r.isIndex){if(r.removeRecord(e))return 0===r.keys.length&&(o(t.keys,i),o(t.values,i)),n=!0,!1}else{var u=a(r,e,t.hashCode);if(u.found)return o(r,u.index),0===r.length&&(o(t.keys,i),o(t.values,i)),n=!0,!1}}),n?e:void 0},updateRecord:function(e){this.removeRecord(e),this.insertRecord(e)}});var T={idAttribute:"id",mapper:null,onConflict:"merge",recordOpts:null};s.extend=g.extend,g.addHiddenPropsToTarget(s.prototype,{_onRecordEvent:function(){this.emit.apply(this,arguments)},add:function(e,t){var n=this;t||(t={}),g._(n,t),e=n.beforeAdd(e,t)||e;var r=!1,i=n.recordId();g.isObject(e)&&!g.isArray(e)&&(e=[e],r=!0),e=e.map(function(e){var r=n.recordId(e);if(!g.isSorN(r))throw new TypeError(i+": Expected string or number, found "+("undefined"==typeof r?"undefined":h.typeof(r))+"!");var o=n.get(r);if(e===o)return o;if(o){var a=t.onConflict||n.onConflict;"merge"===a?g.deepMixIn(o,e):"replace"===a&&(g.forOwn(o,function(t,n){n===i||e.hasOwnProperty(n)||delete o[n]}),o.set(e)),e=o,n.updateIndexes(e)}else e=n.mapper?n.mapper.createRecord(e,n.recordOpts):e,n.index.insertRecord(e),g.forOwn(n.indexes,function(t,n){t.insertRecord(e)}),e&&g.isFunction(e.on)&&e.on("all",n._onRecordEvent,n);return e});var o=r?e.length?e[0]:void 0:e;return n.emit("add",o),n.afterAdd(e,t,o)||o},afterAdd:function(){},afterRemove:function(){},afterRemoveAll:function(){},beforeAdd:function(){},beforeRemove:function(){},beforeRemoveAll:function(){},between:function(e,t,n){return this.query().between(e,t,n).run()},createIndex:function(e,t,n){var r=this;g.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 u(t,n);return r.index.visitAll(i.insertRecord,i),r},filter:function(e,t){return this.query().filter(e,t).run()},forEach:function(e,t){this.index.visitAll(e,t)},get:function(e){var t=this.query().get(e).run();return t.length?t[0]:void 0},getAll:function(){var e;return(e=this.query()).getAll.apply(e,arguments).run()},getIndex:function(e){var t=e?this.indexes[e]:this.index;if(!t)throw new Error("Index "+e+" does not exist!");return t},limit:function(e){return this.query().limit(e).run()},map:function(e,t){var n=[];return this.index.visitAll(function(r){n.push(e.call(t,r))}),n},mapCall:function(e){for(var t=arguments.length,n=Array(t>1?t-1:0),r=1;t>r;r++)n[r-1]=arguments[r];var i=[];return this.index.visitAll(function(t){i.push(t[e].apply(t,n))}),i},recordId:function(e){if(e)return g.get(e,this.recordId());var t=this;return t.mapper?t.mapper.idAttribute:t.idAttribute||"id"},query:function(){return new t(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),g.forOwn(n.indexes,function(e,t){e.removeRecord(r)}),r&&g.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),g.forOwn(t.indexes,function(t,n){t.updateRecord(e)})}}),g.eventify(s.prototype,function(){return this._listeners},function(e){this._listeners=e});var K="belongsTo",D="hasMany",q="hasOne";g.addHiddenPropsToTarget(c.prototype,{getRelation:function(){return this.relatedMapper},getLocalKeys:function(e){},getForeignKey:function(e){return this.type===K?g.get(e,this.foreignKey):g.get(e,this.mapper.idAttribute)},setForeignKey:function(e,t){var n=this;e&&t&&(n.type===K?g.set(e,n.foreignKey,g.get(t,n.getRelation().idAttribute)):!function(){var r=n.mapper.idAttribute;g.isArray(t)?t.forEach(function(t){g.set(t,n.foreignKey,g.get(e,r))}):g.set(t,n.foreignKey,g.get(e,r))}())},getLocalField:function(e){return g.get(e,this.localField)},setLocalField:function(e,t){return g.set(e,this.localField,t)}});var Q=function(e,t,n){if(n||(n={}),!n.type)throw new Error("must specify relation type!");n.mapper=e,n.name=e.name;var r=new c(t,n);e.relationList||Object.defineProperty(e,"relationList",{value:[]}),e.relationFields||Object.defineProperty(e,"relationFields",{value:[]}),e.relationList.push(r),e.relationFields.push(r.localField)},J=function(e,t){return t||(t={}),t.type=K,function(n){Q(n,e,t)}},B=function(e,t){return t||(t={}),t.type=D,function(n){Q(n,e,t)}},H=function(e,t){return t||(t={}),t.type=q,function(n){Q(n,e,t)}};f.extend=g.extend,g.addHiddenPropsToTarget(f.prototype,{_mapper:function(){if(!this.constructor.Mapper)throw new Error("This RecordClass has no Mapper!");return this.constructor.Mapper},get:function(e){return g.get(this,e)},set:function(e,t,n){var r=this;g.isObject(e)&&(n=t),n||(n={}),n.silent&&r._set("silent",!0),g.set(r,e,t),r._get("eventId")||r._set("silent")},unset:function(e,t){this.set(e,void 0,t)},hashCode:function(){var e=this;return g.get(e,e._mapper().idAttribute)},changes:function(e){var t=this;return e||(e={}),g.diffObjects(t,t._get("previous"),e)},hasChanges:function(e){var t=this,n=!!(t._get("changed")||[]).length;return n||g.areDifferent(t,t._get("previous"),e)},commit:function(){var e=this;return e._set("changed"),e._set("previous",g.copy(e)),e},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=[]),g.forOwn(t,function(r,i){i!==t._mapper().idAttribute&&!n.hasOwnProperty(i)&&t.hasOwnProperty(i)&&-1===e.preserve.indexOf(i)&&delete t[i]}),g.forOwn(n,function(n,r){-1===e.preserve.indexOf(r)&&(t[r]=n)}),t.commit(),t},schema:function(e){var t=this._mapper().schema;return e?t[e]:t},create:function(e){return this._mapper().create(this,e)},beforeSave:function(){},save:function(e){var t=void 0,n=void 0,r=this,i=r._mapper();return e||(e={}),g._(r,e),n=e.adapter=r.getAdapterName(e),t=e.op="beforeSave",g.resolve(r[t](e)).then(function(){return t=e.op="save",i.dbg(t,r,e),r.getAdapter(n)[t](i,r,e)}).then(function(n){return t=e.op="afterSave",g.resolve(r[t](n,e)).then(function(t){return n=t||n,e.raw?(r.set(n.data),n.data=r):r.set(n),i.end(n,e)})})},afterSave:function(){},beforeLoadRelations:function(){},loadRelations:function(e,t){var n=void 0,r=this,i=r._mapper(),o=i.relationList||[];return e||(e=[]),t||(t={}),g._(i,t),t.adapter=i.getAdapterName(t),n=t.op="beforeLoadRelations",g.resolve(r[n](e,t)).then(function(){return g.isString(e)&&(e=[e]),n=t.op="loadRelations",i.dbg(n,r,e,t),Promise.all(o.map(function(e){if(g.isFunction(e.load))return e.load(i,e,r,t);var n=void 0;if("hasMany"===e.type&&e.foreignKey)n=e.getRelation().findAll(h.defineProperty({},e.foreignKey,g.get(r,i.idAttribute)),t);else if(e.foreignKey){var o=g.get(r,e.foreignKey);g.isSorN(o)&&(n=e.getRelation().find(o,t))}else e.localKeys?n=e.getRelation().findAll(h.defineProperty({},e.getRelation().idAttribute,{in:g.get(r,e.localKeys)}),t):e.foreignKeys&&(n=e.getRelation().findAll(h.defineProperty({},e.getRelation().idAttribute,{contains:g.get(r,i.idAttribute)}),t));return n&&(n=n.then(function(n){t.raw&&(n=n.data),g.set(r,e.localField,"hasOne"===e.type?n.length?n[0]:void 0:n)})),n}))}).then(function(){return n=t.op="afterLoadRelations",g.resolve(r[n](e,t)).then(function(){return r})})},afterLoadRelations:function(){},destroy:function(e){var t=this._mapper();return t.destroy(g.get(this,t.idAttribute),e)},toJSON:function(e){var t=this,n=this.constructor.Mapper;if(n)return n.toJSON(this,e);var r=function(){var e={};return g.forOwn(t,function(t,n){e[n]=g.copy(t)}),{v:e}}();return"object"===("undefined"==typeof r?"undefined":h.typeof(r))?r.v:void 0}}),g.eventify(f.prototype,function(){return this._get("events")},function(e){this._set("events",e)}),l.extend=g.extend;var $={array:g.isArray,boolean:g.isBoolean,integer:g.isInteger,null:g.isNull,number:g.isNumber,object:g.isObject,string:g.isString},V={},G={},W=function(e,t){var n="";return e&&(n+=g.isNumber(e)?"["+e+"]":t?"."+e:""+e),n},z=function(e){e||(e={});var t="",n=e.path||[];return n.forEach(function(e){t+=W(e,t)}),t+=W(e.prop,t)},X=function(e,t,n){return{expected:t,actual:""+e,path:z(n)}},Y=function(e,t,n,r){r.push(X(e,t,n))},Z=function(e,t,n,r){var i=n[e];return t.length>i?X(t.length,"length no more than "+i,r):void 0},ee=function(e,t,n,r){var i=n[e];return t.length<i?X(t.length,"length no less than "+i,r):void 0},te=function(e,t,n,r){return!g.isUndefined(n[e])&&G[e](t,n,r)},ne=function(e,t,n,r){var i=[];return e.forEach(function(e){i=i.concat(te(e,t,n,r)||[])}),i.length?i:void 0},re=["enum","type","allOf","anyOf","oneOf","not"],ie=["items","maxItems","minItems","uniqueItems"],oe=["multipleOf","maximum","minimum"],ae=["maxProperties","minProperties","required","properties","dependencies"],ue=["maxLength","minLength","pattern"],se=function(e,t,n){return ne(re,e,t,n)},ce=function e(t,n,r){var i=[];r||(r={});var o=void 0,a=r.prop;if(!g.isUndefined(n)){if(!g.isObject(n))throw new Error('Invalid schema at path: "'+r.path+'"');return g.isUndefined(r.path)&&(r.path=[]),g.isUndefined(r.prop)||(o=!0,r.path.push(r.prop),r.prop=void 0),n.extends&&(i=g.isFunction(n.extends.validate)?i.concat(n.extends.validate(t,r)||[]):i.concat(e(t,n.extends,r)||[])),g.isUndefined(t)?(n.required===!0&&Y(t,"a value",r,i),o&&(r.path.pop(),r.prop=a),i.length?i:void 0):(i=i.concat(se(t,n,r)||[]),o&&(r.path.pop(),r.prop=a),i.length?i:void 0)}};l.types=$,l.typeGroupValidators=V,l.validationKeywords=G,l.validate=ce,l.prototype.validate=function(e,t){return l.validate(e,this,t)},g.fillIn(G,{allOf:function(e,t,n){var r=[];return t.allOf.forEach(function(t){r=r.concat(ce(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=ce(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)?X(e,"one of ("+r.join(", ")+")",n):void 0},items:function e(t,n,r){r||(r={});for(var e=n.items,i=[],o=g.isArray(e),a=t.length,u=0;a>u;u++)o&&(e=n.items[u]),r.prop=u,i=i.concat(ce(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":h.typeof(t))===("undefined"==typeof e?"undefined":h.typeof(e))&&(i?t>e:t>=e)?X(t,"no more than "+e,r):void 0},maxItems:function(e,t,n){return Z("maxItems",e,t,n)},maxLength:function(e,t,n){return Z("maxLength",e,t,n)},maxProperties:function e(t,n,r){var e=n.maxProperties,i=Object.keys(t).length;return i>e?X(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":h.typeof(t))===("undefined"==typeof e?"undefined":h.typeof(e))&&(i?e>t:e>=t)?X(t,"no less than "+e,r):void 0},minItems:function(e,t,n){return ee("minItems",e,t,n)},minLength:function(e,t,n){return ee("minLength",e,t,n)},minProperties:function e(t,n,r){var e=n.minProperties,i=Object.keys(t).length;return e>i?X(i,"no more than "+e+" properties",r):void 0},multipleOf:function(e,t,n){},not:function(e,t,n){return ce(e,t.not,n)?void 0:X("succeeded","should have failed",n)},oneOf:function(e,t,n){var r=!1,i=[];return t.oneOf.forEach(function(t){var o=ce(e,t,n);if(o)i=i.concat(o);else{if(r)return i=[X("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 g.isString(t)&&!t.match(e)?X(t,e,r):void 0},properties:function e(t,n,r){r||(r={});var i=g.isUndefined(n.additionalProperties)?!0:n.additionalProperties,o={},e=n.properties||{},a=n.patternProperties||{},u=[];g.forOwn(t,function(e,t){o[t]=void 0}),g.forOwn(e||{},function(e,n){g.isUndefined(t[n])&&!g.isUndefined(e.default)&&(t[n]=g.copy(e.default)),r.prop=n,u=u.concat(ce(t[n],e,r)||[]),delete o[n]}),g.forOwn(a,function(e,n){g.forOwn(o,function(i,a){a.match(n)&&(r.prop=a,u=u.concat(ce(t[a],e,r)||[]),delete o[a])})});var s=Object.keys(o);return i===!1?s.length&&Y("extra fields: "+s.join(", "),"no extra fields",r,u):g.isObject(i)&&s.forEach(function(e){r.prop=e,u=u.concat(ce(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(g.isUndefined(g.get(t,e))){var n=r.prop;r.prop=e,Y(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(g.isString(e)&&(e=[e]),e.forEach(function(e){return $[e](t,n,r)?(i=e,!1):void 0}),!i)return X(t?"undefined"==typeof t?"undefined":h.typeof(t):""+t,"one of ("+e.join(", ")+")",r);var o=V[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 X(i,"no duplicates",n)}}}),g.fillIn(V,{array:function(e,t,n){return ne(ie,e,t,n)},integer:function(e,t,n){return V.numeric(e,t,n)},number:function(e,t,n){return V.numeric(e,t,n)},numeric:function(e,t,n){return ne(oe,e,t,n)},object:function(e,t,n){return ne(ae,e,t,n)},string:function(e,t,n){return ne(ue,e,t,n)}});var fe="changing",le="changed",de="creating",pe="eventId",he="noValidate",ve="silent",ge="validation failed",ye=function(e,t){var n={enumerable:g.isUndefined(t.enumerable)?!0:!!t.enumerable},r="props."+e,i="previous."+e;return n.get=function(){return this._get(r)},n.set=function(n){var o=this,a=o._get,u=o._set,s=o._unset;if(!a(he)){var c=t.validate(n);if(c){var f=new Error(ge);throw f.errors=c,f}}return t.track&&!a(de)&&!function(){var t=a(i),c=a(r),f=a(fe),l=a(le);f||(l=[]);var d=l.indexOf(e);c!==n&&-1===d&&l.push(e),t===n&&d>=0&&l.splice(d,1),l.length||(f=!1,s(fe),s(le),a(pe)&&(clearTimeout(a(pe)),s(pe))),!f&&l.length&&(u(le,l),u(fe,!0),u(pe,setTimeout(function(){if(s(le),s(pe),s(fe),!a(ve)){var e=void 0;for(e=0;e<l.length;e++)o.emit("change:"+l[e],o,g.get(o,l[e]));o.emit("change",o,o.changes())}s(ve)},0)))}(),u(r,n),n},n},me=function(e,t){var n=e.properties||{};g.forOwn(n,function(e,n){Object.defineProperty(t,n,ye(n,e))})},be=function(){for(var e=arguments.length,t=Array(e),n=0;e>n;n++)t[n]=arguments[n];var r=this,i=t[t.length-1];r.dbg.apply(r,[i.op].concat(t)),(i.notify||void 0===i.notify&&r.notify)&&setTimeout(function(){r.emit.apply(r,[i.op].concat(t))})},we=function(){for(var e=arguments.length,t=Array(e),n=0;e>n;n++)t[n]=arguments[n]; | ||
var r=this,i=t[t.length-2];r.dbg.apply(r,[i.op].concat(t)),(i.notify||void 0===i.notify&&r.notify)&&setTimeout(function(){r.emit.apply(r,[i.op].concat(t))})},Ae={applySchema:!0,defaultAdapter:"http",debug:!1,idAttribute:"id",name:null,notify:g.isBrowser,raw:!1,schema:null};g.addHiddenPropsToTarget(d.prototype,{_end:function(e,t){var n=this;t.raw&&g._(t,e);var r=t.raw?e.data:e;return g.isArray(r)&&r.length&&g.isObject(r[0])?r=r.map(function(e){return n.createRecord(e)}):g.isObject(r)&&(r=n.createRecord(r)),t.raw?e.data=r:e=r,e},createRecord:function(e,t){var n=this,r=n.RecordClass,i=n.relationList||[];return i.forEach(function(t){var n=t.getRelation(),r=t.getLocalField(e);g.isArray(r)&&r.length&&!n.is(r[0])?t.setLocalField(e,r.map(function(e){return t.getRelation().createRecord(e)})):g.isObject(r)&&!n.is(r)&&t.setLocalField(e,t.getRelation().createRecord(r))}),r?e instanceof r?e:new r(e,t):e},is:function(e){var t=this.RecordClass;return t?e instanceof t:!1},toJSON:function(e,t){var n=this;t||(t={});var r=(n?n.relationFields:[])||[],i={},o=void 0;return n&&n.schema&&(o=n.schema.properties||{},g.forOwn(o,function(t,n){i[n]=g.plainCopy(e[n])})),o||(o={}),t.strict||g.forOwn(e,function(e,t){o[t]||-1!==r.indexOf(t)||(i[t]=g.plainCopy(e))}),n&&t.withAll&&(t.with=r.slice()),n&&t.with&&(g.isString(t.with)&&(t.with=[t.with]),g.forEachRelation(n,t,function(t,n){var r=t.getLocalField(e);r&&(g.isArray(r)?t.setLocalField(i,r.map(function(e){return t.getRelation().toJSON(e,n)})):t.setLocalField(i,t.getRelation().toJSON(r,n)))})),i},getAdapter:function(e){var t=this;t.dbg("getAdapter","name:",e);var n=t.getAdapterName(e);if(!n)throw new ReferenceError(n+" not found!");return t.getAdapters()[n]},getAdapterName:function(e){return e||(e={}),g.isString(e)&&(e={adapter:e}),e.adapter||e.defaultAdapter},getAdapters:function(){return this._adapters},getSchema:function(){return this.schema},beforeCount:be,count:function(e,t){var n=void 0,r=void 0,i=this;return e||(e={}),t||(t={}),g._(i,t),r=t.adapter=i.getAdapterName(t),n=t.op="beforeCount",g.resolve(i[n](e,t)).then(function(){return n=t.op="count",i.dbg(n,e,t),g.resolve(i.getAdapter(r)[n](i,e,t))}).then(function(r){return t.raw&&g._(t,r),n=t.op="afterCount",g.resolve(i[n](e,t,r)).then(function(e){return g.isUndefined(e)?r:e})})},afterCount:we,beforeCreate:be,create:function(e,t){var n=void 0,r=void 0,i=this;return e||(e={}),t||(t={}),g._(i,t),r=t.adapter=i.getAdapterName(t),n=t.op="beforeCreate",g.resolve(i[n](e,t)).then(function(o){e=g.isUndefined(o)?e:o;var a={};t.with||(t.with=[]);var u=[];return g.forEachRelation(i,t,function(t,n){var r=t.getLocalField(e);t.type===K&&r&&u.push(t.getRelation().create(r,n).then(function(r){var i=n.raw?r.data:r;t.setLocalField(a,i),t.setForeignKey(e,i)}))}),Promise.all(u).then(function(){return n=t.op="create",i.dbg(n,e,t),g.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=[],g.forEachRelation(i,t,function(n,i){var o=n.getLocalField(e);if(o){var s=void 0;n.type===D?(n.setForeignKey(r,o),s=n.getRelation().createMany(o,i).then(function(e){n.setLocalField(r,t.raw?e.data:e)})):n.type===q?(n.setForeignKey(r,o),s=n.getRelation().create(o,i).then(function(e){n.setLocalField(r,t.raw?e.data:e)})):n.type===K&&n.getLocalField(a)&&n.setLocalField(r,n.getLocalField(a)),s&&u.push(s)}}),Promise.all(u).then(function(){return n})})}).then(function(r){return r=i._end(r,t),n=t.op="afterCreate",g.resolve(i[n](e,t,r)).then(function(e){return g.isUndefined(e)?r:e})})},afterCreate:we,beforeCreateMany:be,createMany:function(e,t){var n=void 0,r=void 0,i=this;return e||(e=[]),t||(t={}),g._(i,t),r=t.adapter=i.getAdapterName(t),n=t.op="beforeCreateMany",g.resolve(i[n](e,t)).then(function(o){e=g.isUndefined(o)?e:o;var a={};t.with||(t.with=[]);var u=[];return g.forEachRelation(i,t,function(t,n){var r=e.map(function(e){return t.getLocalField(e)}).filter(function(e){return e});t.type===K&&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])})}))}),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),g.resolve(i.getAdapter(r)[n](i,o,t))}).then(function(n){var r=t.raw?n.data:n;return u=[],g.forEachRelation(i,t,function(n,o){var s=e.map(function(e){return n.getLocalField(e)}).filter(function(e){return e});if(s.length===e.length){var c=n.getLocalField(a),f=void 0;n.type===D?i.log("warn","deep createMany of hasMany type not supported!"):n.type===q?(r.forEach(function(e,t){n.setForeignKey(e,s[t])}),f=n.getRelation().createMany(s,o).then(function(e){var i=t.raw?e.data:e;r.forEach(function(e,t){n.setLocalField(e,i[t])})})):n.type===K&&c&&c.length===r.length&&r.forEach(function(e,t){n.setLocalField(e,c[t])}),f&&u.push(f)}}),Promise.all(u).then(function(){return n})})}).then(function(r){return r=i._end(r,t),n=t.op="afterCreateMany",g.resolve(i[n](e,t,r)).then(function(e){return g.isUndefined(e)?r:e})})},afterCreateMany:we,beforeFind:be,find:function(e,t){var n=void 0,r=void 0,i=this;return t||(t={}),g._(i,t),r=t.adapter=i.getAdapterName(t),n=t.op="beforeFind",g.resolve(i[n](e,t)).then(function(){return n=t.op="find",i.dbg(n,e,t),g.resolve(i.getAdapter(r)[n](i,e,t))}).then(function(r){return r=i._end(r,t),n=t.op="afterFind",g.resolve(i[n](e,t,r)).then(function(e){return g.isUndefined(e)?r:e})})},afterFind:we,beforeFindAll:be,findAll:function(e,t){var n=void 0,r=void 0,i=this;return e||(e={}),t||(t={}),g._(i,t),r=t.adapter=i.getAdapterName(t),n=t.op="beforeFindAll",g.resolve(i[n](e,t)).then(function(){return n=t.op="findAll",i.dbg(n,e,t),g.resolve(i.getAdapter(r)[n](i,e,t))}).then(function(r){return r=i._end(r,t),n=t.op="afterFindAll",g.resolve(i[n](e,t,r)).then(function(e){return g.isUndefined(e)?r:e})})},afterFindAll:we,beforeSum:be,sum:function(e,t,n){var r=void 0,i=void 0,o=this;return t||(t={}),n||(n={}),g._(o,n),i=n.adapter=o.getAdapterName(n),r=n.op="beforeSum",g.resolve(o[r](e,t,n)).then(function(){return r=n.op="sum",o.dbg(r,t,n),g.resolve(o.getAdapter(i)[r](o,e,t,n))}).then(function(i){return n.raw&&g._(n,i),r=n.op="afterSum",g.resolve(o[r](e,t,n,i)).then(function(e){return g.isUndefined(e)?i:e})})},afterSum:we,beforeUpdate:be,update:function(e,t,n){var r=void 0,i=void 0,o=this;return t||(t={}),n||(n={}),g._(o,n),i=n.adapter=o.getAdapterName(n),r=n.op="beforeUpdate",g.resolve(o[r](e,t,n)).then(function(a){t=g.isUndefined(a)?t:a,r=n.op="update";var u=o.toJSON(t,n);return o.dbg(r,e,u,n),g.resolve(o.getAdapter(i)[r](o,e,u,n))}).then(function(i){return i=o._end(i,n),r=n.op="afterUpdate",g.resolve(o[r](e,t,n,i)).then(function(e){return g.isUndefined(e)?i:e})})},afterUpdate:we,beforeUpdateMany:be,updateMany:function(e,t){var n=void 0,r=void 0,i=this;return e||(e=[]),t||(t={}),g._(i,t),r=t.adapter=i.getAdapterName(t),n=t.op="beforeUpdateMany",g.resolve(i[n](e,t)).then(function(o){e=g.isUndefined(o)?e:o,n=t.op="updateMany";var a=e.map(function(e){return i.toJSON(e,t)});return i.dbg(n,a,t),g.resolve(i.getAdapter(r)[n](i,a,t))}).then(function(r){return r=i._end(r,t),n=t.op="afterUpdateMany",g.resolve(i[n](e,t,r)).then(function(e){return g.isUndefined(e)?r:e})})},afterUpdateMany:we,beforeUpdateAll:be,updateAll:function(e,t,n){var r=void 0,i=void 0,o=this;return e||(e={}),t||(t={}),n||(n={}),g._(o,n),i=n.adapter=o.getAdapterName(n),r=n.op="beforeUpdateAll",g.resolve(o[r](e,t,n)).then(function(a){e=g.isUndefined(a)?e:a,r=n.op="updateAll";var u=o.toJSON(e,n);return o.dbg(r,u,t,n),g.resolve(o.getAdapter(i)[r](o,u,t,n))}).then(function(i){return i=o._end(i,n),r=n.op="afterUpdateAll",g.resolve(o[r](e,t,n,i)).then(function(e){return g.isUndefined(e)?i:e})})},afterUpdateAll:we,beforeDestroy:be,destroy:function(e,t){var n=void 0,r=void 0,i=this;return t||(t={}),g._(i,t),r=t.adapter=i.getAdapterName(t),n=t.op="beforeDestroy",g.resolve(i[n](e,t)).then(function(){return n=t.op="destroy",i.dbg(n,e,t),g.resolve(i.getAdapter(r)[n](i,e,t))}).then(function(r){return t.raw&&g._(t,r),n=t.op="afterDestroy",g.resolve(i[n](e,t,r)).then(function(e){return g.isUndefined(e)?r:e})})},afterDestroy:we,beforeDestroyAll:be,destroyAll:function(e,t){var n=void 0,r=void 0,i=this;return e||(e={}),t||(t={}),g._(i,t),r=t.adapter=i.getAdapterName(t),n=t.op="beforeDestroyAll",g.resolve(i[n](e,t)).then(function(){return n=t.op="destroyAll",i.dbg(n,e,t),g.resolve(i.getAdapter(r)[n](i,e,t))}).then(function(r){return t.raw&&g._(t,r),n=t.op="afterDestroyAll",g.resolve(i[n](e,t,r)).then(function(e){return g.isUndefined(e)?r:e})})},afterDestroyAll:we,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||"mapper")+")";if(console[e]){var o;(o=console)[e].apply(o,[i].concat(n))}else{var a;(a=console).log.apply(a,[i].concat(n))}}},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))},belongsTo:function(e,t){return J(e,t)(this)},hasMany:function(e,t){return B(e,t)(this)},hasOne:function(e,t){return H(e,t)(this)},registerAdapter:function(e,t,n){var r=this;n||(n={}),r.getAdapters()[e]=t,(n===!0||n.default)&&(r.defaultAdapter=e)}}),d.extend=g.extend,g.eventify(d.prototype,function(){return this._listeners},function(e){this._listeners=e});var _e=["count","create","createMany","createRecord","dbg","destroy","destroyAll","emit","find","findAll","getSchema","is","log","off","on","sum","toJSON","update","updateAll","updateMany"];p.extend=g.extend,g.addHiddenPropsToTarget(p.prototype,{defineMapper:function(e,t){var n=this;if(g.isObject(e)){if(t=e,!t.name)throw new Error("name is required!");e=t.name}else if(!g.isString(e))throw new Error("name is required!");t||(t={}),t.name=e,t.relations||(t.relations={});var r=t.MapperClass||n.MapperClass;delete t.MapperClass,g.fillIn(t,n.mapperDefaults);var i=n._mappers[e]=new r(t);return i.name=e,i._adapters=n.getAdapters(),g.forOwn(i.relations,function(e,t){g.forOwn(e,function(e,r){g.isObject(e)&&(e=[e]),e.forEach(function(e){e.getRelation=function(){return n.getMapper(r)};var o=n._mappers[r]||r;t===K?i.belongsTo(o,e):t===q?i.hasOne(o,e):t===D&&i.hasMany(o,e)})})}),i},getAdapter:function(e){var t=this,n=t.getAdapterName(e);if(!n)throw new ReferenceError(n+" not found!");return t.getAdapters()[n]},getAdapterName:function(e){return e||(e={}),g.isString(e)&&(e={adapter:e}),e.adapter||this.mapperDefaults.defaultAdapter},getAdapters:function(){return this._adapters},getMapper:function(e){var t=this._mappers[e];if(!t)throw new ReferenceError(e+" is not a registered mapper!");return t},registerAdapter:function(e,t,n){var r=this;n||(n={}),r.getAdapters()[e]=t,(n===!0||n.default)&&(r.mapperDefaults.defaultAdapter=e,g.forOwn(r._mappers,function(t){t.defaultAdapter=e}))}});var Oe={};_e.forEach(function(e){Oe[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)}}),g.addHiddenPropsToTarget(p.prototype,Oe);var xe=s.extend({constructor:function(e,t){var n=this;if(g.classCallCheck(n,xe),g.getSuper(n).call(n,e,t),n._added={},!n.datastore)throw new Error("This collection must have a datastore!");return n},_onRecordEvent:function(){for(var e=this,t=arguments.length,n=Array(t),r=0;t>r;r++)n[r]=arguments[r];g.getSuper(e).prototype._onRecordEvent.apply(e,n);var i=n[0];g.isString(i)&&0===i.indexOf("change")&&e.updateIndexes(n[1])},add:function(e,t){var n=this,r=n.datastore,i=n.mapper,o=i.relationList||[],a=(new Date).getTime(),u=!!i.RecordClass,s=void 0;return g.isObject(e)&&!g.isArray(e)&&(s=!0,e=[e]),o.length&&e.length&&i.relationList.forEach(function(t){var n=t.relation,i=r.getMapper(n),o=i.idAttribute,a=t.foreignKey,u=r.getCollection(n),s=t.type,c=s===D,f=g.isUndefined(t.add)?!0:!!t.add,l=void 0;e.forEach(function(e){if(l=t.getLocalField(e),g.isFunction(t.add))t.add(r,t,e);else if(l){if(c)l=l.map(function(n){return n!==u.get(u.recordId(n))&&(a&&t.setForeignKey(e,n),f&&(n=u.add(n))),n}),t.localKeys&&g.set(e,t.localKeys,l.map(function(e){return g.get(e,o)}));else{var n=g.get(l,o);l!==u.get(n)&&(t.setForeignKey(e,l),f&&(l=u.add(l)))}t.setLocalField(e,l)}})}),e=g.getSuper(n).prototype.add.call(n,e,t),e.forEach(function(e){n._added[n.recordId(e)]=a,u&&e._set("$",a)}),s?e[0]:e},remove:function(e,t){var n=this;delete n._added[e];var r=g.getSuper(n).prototype.remove.call(n,e,t);if(r){var i=n.mapper;i.RecordClass&&r._set("$")}return r},removeAll:function(e,t){var n=this,r=g.getSuper(n).prototype.removeAll.call(n,e,t);return r.forEach(function(e){delete n._added[n.recordId(e)]}),r}});xe.extend=g.extend;var Ce={linkRelations:g.isBrowser},Re=p.extend({constructor:function(e){var t=this;return g.classCallCheck(t,Re),g.getSuper(t).call(t,e),t.CollectionClass=t.CollectionClass||xe,t._collections={},g.fillIn(t,Ce),t._pendingQueries={},t._completedQueries={},t},_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 g.getSuper(this).prototype[e].apply(this,n)},_end:function(e,t,n){return n.raw?(t.data=this.getCollection(e).add(t.data,n),t):t=this.getCollection(e).add(t,n)},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=g.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||{};g.forOwn(a,function(e,t){e.indexed&&i.createIndex(t)}),i.createIndex("addedTimestamps",["$"],{fieldGetter:function(e){return i._added[i.recordId(e)]}});var u=n.linkRelations;return u&&r.relationList.forEach(function(e){var t=e.relation,o=e.localField,a="links."+o,s=e.foreignKey,c=e.type,f=g.isUndefined(e.link)?u:e.link,l={index:s},d=void 0;c===K?(i.indexes[s]||i.createIndex(s),d={get:function(){var r=this;if(!r._get("$")||!f)return r._get(a);var i=e.getForeignKey(r),o=g.isUndefined(i)?void 0:n.getCollection(t).get(i);return r._set(a,o),o},set:function(t){var n=this;return n._set(a,t),e.setForeignKey(n,t),i.updateIndex(n,l),e.getLocalField(n)}}):c===D?!function(){var r=e.localKeys,o=e.foreignKeys;n._collections[t]&&s&&!n.getCollection(t).indexes[s]&&n.getCollection(t).createIndex(s),d={get:function(){var i=this;if(!i._get("$")||!f)return i._get(a);var u=e.getForeignKey(i),c=void 0,l=n.getCollection(t);if(s)c=l.getAll(u,{index:s});else if(r){var d=g.get(i,r)||[],p=g.isArray(d)?d:Object.keys(d);c=l.getAll.apply(l,p)}else if(o){var h={};g.set(h,"where."+o+".contains",u),c=l.filter(h)}return i._set(a,c),c},set:function(u){var c=this,f=i.recordId(c),d=n.getCollection(t);return c._set(a,u),s&&(e.setForeignKey(c,u),g.isArray(u)&&u.forEach(function(e){d.updateIndex(e,l)})),r?g.set(c,r,u.map(function(e){return d.recordId(e)})):o&&u.forEach(function(e){var t=g.get(e,o);t?-1===t.indexOf(f)&&t.push(f):g.set(e,o,[f])}),e.getLocalField(c)}}}():c===q&&(d={get:function(){var r=this;if(!r._get("$")||!f)return r._get(a);var i=e.getForeignKey(r),o=n.getCollection(t).getAll(i,{index:s}),u=o.length?o[0]:void 0;return r._set(a,u),u},set:function(r){var i=this;return i._set(a,r),e.setForeignKey(i,r),n.getCollection(t).updateIndex(r,l),e.getLocalField(i)}}),d&&(d.enumerable=g.isUndefined(e.enumerable)?!0:e.enumerable,e.get&&!function(){var t=d.get;d.get=function(){var n=this;return e.get(e,this,function(){for(var e=arguments.length,r=Array(e),i=0;e>i;i++)r[i]=arguments[i];return t.apply(n,r)})}}(),e.set&&!function(){var t=d.set;d.set=function(n){var r=this;return e.set(e,this,n,function(e){return t.call(r,void 0===e?n:e)})}}(),Object.defineProperty(r.RecordClass.prototype,o,d))}),r},destroy:function(e,t,n){var r=this;return n||(n={}),r._callSuper("destroy",e,t,n).then(function(i){return n.raw?i.data=r.getCollection(e).remove(t,n):i=r.getCollection(e).remove(t,n),delete r._pendingQueries[e][t],delete r._completedQueries[e][t],i})},destroyAll:function(e,t,n){var r=this;return n||(n={}),r._callSuper("destroyAll",e,t,n).then(function(i){n.raw?i.data=r.getCollection(e).removeAll(t,n):i=r.getCollection(e).removeAll(t,n);var o=r.hashQuery(e,t,n);return delete r._pendingQueries[e][o],delete r._completedQueries[e][o],i})},find:function(e,t,n){var r=this;n||(n={});var i=r._pendingQueries[e][t];if(g.fillIn(n,r.getMapper(e)),i)return i;var o=r.cachedFind(e,t,n),a=void 0;return a=n.force||!o?r._pendingQueries[e][t]=r._callSuper("find",e,t,n).then(function(i){return delete r._pendingQueries[e][t],r._end(e,i,n)},function(n){return delete r._pendingQueries[e][t],g.reject(n)}).then(function(n){return r._completedQueries[e][t]=(new Date).getTime(),n}):g.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(g.fillIn(n,r.getMapper(e)),o)return o;var a=r.cachedFindAll(e,t,n),u=void 0;return u=n.force||!a?r._pendingQueries[e][i]=r._callSuper("findAll",e,t,n).then(function(t){return delete r._pendingQueries[e][i],r._end(e,t,n)},function(t){return delete r._pendingQueries[e][i],g.reject(t)}).then(function(t){return r._completedQueries[e][i]=(new Date).getTime(),t}):g.resolve(a)},cachedFind:function(e,t,n){return this.get(e,t,n)},cachedFindAll:function(e,t,n){var r=this;return r._completedQueries[e][r.hashQuery(e,t,n)]?r.filter(e,t,n):void 0},hashQuery:function(e,t,n){return g.toJson(t)},getCollection:function(e){var t=this._collections[e];if(!t)throw new ReferenceError(e+" is not a registered collection!");return t},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,t,n,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)})}});Re.prototype.defineResource=Re.prototype.defineMapper,Re.extend=g.extend;var Ee=["add","between","createIndex","filter","get","getAll","query","remove","removeAll","toJson"],je={};Ee.forEach(function(e){je[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)}}),je.inject=function(){return console.warn("deprecated"),this.add.apply(this,arguments)},g.addHiddenPropsToTarget(Re.prototype,je);var Ie={full:"3.0.0-alpha.20",major:parseInt("3",10),minor:parseInt("0",10),patch:parseInt("0",10),alpha:"20",beta:"false"},Se=Re;e.Collection=s,e.Container=p,e.DataStore=Re,e.DS=Se,e.LinkedCollection=xe,e.Mapper=d,e.Query=t,e.Record=f,e.Schema=l,e.utils=g,e.version=Ie,e.belongsToType=K,e.hasManyType=D,e.hasOneType=q,e.belongsTo=J,e.hasMany=B,e.hasOne=H}); | ||
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define("js-data",["exports"],t):t(e.JSData=e.JSData||{})}(this,function(e){"use strict";function t(){this._listeners={}}function n(e,t,n){return e===t?0:(n&&(e=n(e),t=n(t)),null===e&&null===t?0:null===e?-1:null===t?1:t>e?-1:e>t?1:0)}function r(e,t,n){return e.splice(t,0,n),e}function i(e,t){return e.splice(t,1),e}function o(e,t,r){for(var i=0,o=e.length,a=void 0,u=void 0;o>i;){if(u=(i+o)/2|0,a=n(t,e[u],r),0===a)return{found:!0,index:u};0>a?o=u:i=u+1}return{found:!1,index:o}}function a(e,t){if(C.classCallCheck(this,a),e||(e=[]),!C.isArray(e))throw new Error("fieldList must be an array.");t||(t={}),this.fieldList=e,this.fieldGetter=t.fieldGetter,this.hashCode=t.hashCode,this.isIndex=!0,this.keys=[],this.values=[]}function u(e,t){var n=this;t||(t={});var r=t.localField;if(!r)throw new Error("localField is required");var i=t.foreignKey=t.foreignKey||t.localKey;if(!i&&(t.type===L||t.type===K))throw new Error("foreignKey is required");var o=t.localKeys,a=t.foreignKeys;if(!i&&!o&&!a&&t.type===M)throw new Error("one of (foreignKey, localKeys, foreignKeys) is required");if(C.isString(e)){if(t.relation=e,!C.isFunction(t.getRelation))throw new Error("you must provide a reference to the related mapper!")}else e&&(t.relation=e.name,Object.defineProperty(n,"relatedMapper",{value:e}));C.fillIn(n,t)}var s={};s.typeof="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol?"symbol":typeof e},s.defineProperty=function(e,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e},s.toConsumableArray=function(e){if(Array.isArray(e)){for(var t=0,n=Array(e.length);t<e.length;t++)n[t]=e[t];return n}return Array.from(e)};var c=1/0,f=1.7976931348623157e308,l="[object Boolean]",d="[object Date]",p="[object Function]",h="[object Number]",v="[object Object]",g="[object RegExp]",y="[object String]",m=Object.prototype.toString,b=/^(.+)\.(.+)$/,w=function(e){if(!e)return 0;if(e=+e,e===c||e===-c){var t=0>e?-1:1;return t*f}var n=e%1;return e===e?n?e-n:e:0},A=function(e){return m.call(e)},_=function(e){return!!e&&"object"===("undefined"==typeof e?"undefined":s.typeof(e))&&e.constructor===Object},O=function(e,t){if(!t)return e;var n=t.split(".");return n.forEach(function(t){e[t]||(e[t]={}),e=e[t]}),e},x={Promise:Promise,_:function(e,t){for(var n in e){var r=e[n];void 0===t[n]&&!x.isFunction(r)&&n&&0!==n.indexOf("_")&&(t[n]=r)}},_forRelation:function(e,t,n,r){var i=t.relation,o=null,a=void 0;if(e||(e={}),e.with||(e.with=[]),(a=x._getIndex(e.with,i))>=0?o=i:(a=x._getIndex(e.with,t.localField))>=0&&(o=t.localField),e.withAll)return void n.call(r,t,{});if(o){var u={};x.fillIn(u,t.getRelation()),x.fillIn(u,e),u.with=e.with.slice(),u._activeWith=u.with.splice(a,1)[0],u.with.forEach(function(e,t){e&&0===e.indexOf(o)&&e.length>=o.length&&"."===e[o.length]?u.with[t]=e.substr(o.length+1):u.with[t]=""}),n.call(r,t,u)}},_getIndex:function(e,t){var n=-1;return e.forEach(function(e,r){return e===t?(n=r,!1):x.isObject(e)&&e.relation===t?(n=r,!1):void 0}),n},addHiddenPropsToTarget:function(e,t){var n={};x.forOwn(t,function(e,t){n[t]={writable:!0,value:e}}),Object.defineProperties(e,n)},areDifferent:function(e,t,n){n||(n={});var r=x.diffObjects(e,t,n),i=Object.keys(r.added).length+Object.keys(r.removed).length+Object.keys(r.changed).length;return i>0},classCallCheck:function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")},copy:function(e,t,n,r,i,o){if(t){if(e===t)throw new Error("Cannot copy! Source and destination are identical.");if(n=n||[],r=r||[],x.isObject(e)){var a=n.indexOf(e);if(-1!==a)return r[a];n.push(e),r.push(t)}var u=void 0;if(x.isArray(e)){var s=void 0;for(t.length=0,s=0;s<e.length;s++)u=x.copy(e[s],null,n,r,i,o),x.isObject(e[s])&&(n.push(e[s]),r.push(u)),t.push(u)}else{x.isArray(t)?t.length=0:x.forOwn(t,function(e,n){delete t[n]});for(var c in e)if(e.hasOwnProperty(c)){if(x.isBlacklisted(c,i))continue;u=x.copy(e[c],null,n,r,i,o),x.isObject(e[c])&&(n.push(e[c]),r.push(u)),t[c]=u}}}else t=e,e&&(x.isArray(e)?t=x.copy(e,[],n,r,i,o):x.isDate(e)?t=new Date(e.getTime()):x.isRegExp(e)?(t=new RegExp(e.source,e.toString().match(/[^\/]*$/)[0]),t.lastIndex=e.lastIndex):x.isObject(e)&&(t=o?x.copy(e,{},n,r,i,o):x.copy(e,Object.create(Object.getPrototypeOf(e)),n,r,i,o)));return t},deepFillIn:function(e,t){return t&&x.forOwn(t,function(t,n){var r=e[n];_(t)&&_(r)?x.deepFillIn(r,t):e.hasOwnProperty(n)&&void 0!==e[n]||(e[n]=t)}),e},deepMixIn:function(e,t){return t&&x.forOwn(t,function(t,n){var r=e[n];_(t)&&_(r)?x.deepMixIn(r,t):e[n]=t}),e},diffObjects:function(e,t,n){n||(n={});var r=n.equalsFn,i=n.ignore,o={added:{},changed:{},removed:{}};return x.isFunction(r)||(r=x.strictEqual),x.forOwn(t,function(t,n){var a=e[n];x.isBlacklisted(n,i)||r(a,t)||(x.isUndefined(a)?o.removed[n]=void 0:r(a,t)||(o.changed[n]=a))}),x.forOwn(e,function(e,n){x.isUndefined(t[n])&&!x.isBlacklisted(n,i)&&(o.added[n]=e)}),o},equal:function(e,t){return e==t},eventify:function(e,t,n,r){e=e||this;var i={};t||n||(t=function(){return i},n=function(e){i=e}),Object.defineProperties(e,{emit:{enumerable:!!r,value:function(){for(var e=t.call(this)||{},n=arguments.length,r=Array(n),i=0;n>i;i++)r[i]=arguments[i];var o=r.shift(),a=e[o]||[],u=void 0;for(u=0;u<a.length;u++)a[u].f.apply(a[u].c,r);for(a=e.all||[],r.unshift(o),u=0;u<a.length;u++)a[u].f.apply(a[u].c,r)}},off:{enumerable:!!r,value:function(e,r){var i=t.call(this),o=i[e];if(o)if(r){for(var a=0;a<o.length;a++)if(o[a].f===r){o.splice(a,1);break}}else o.splice(0,o.length);else n.call(this,{})}},on:{enumerable:!!r,value:function(e,r,i){t.call(this)||n.call(this,{});var o=t.call(this);o[e]=o[e]||[],o[e].push({c:i,f:r})}}})},extend:function(e,t){var n=this,r=void 0;e||(e={}),t||(t={}),e.hasOwnProperty("constructor")?(r=e.constructor,delete e.constructor):r=function(){x.classCallCheck(this,r);for(var e=arguments.length,t=Array(e),n=0;e>n;n++)t[n]=arguments[n];var i=x.possibleConstructorReturn(this,(r.__super__||Object.getPrototypeOf(r)).apply(this,t));return i},r.prototype=Object.create(n&&n.prototype,{constructor:{configurable:!0,enumerable:!1,value:r,writable:!0}});var i=Object;return i.setPrototypeOf?i.setPrototypeOf(r,n):t.strictEs6Class?r.__proto__=n:x.forOwn(n,function(e,t){r[t]=e}),Object.defineProperty(r,"__super__",{configurable:!0,value:n}),x.addHiddenPropsToTarget(r.prototype,e),x.fillIn(r,t),r},fillIn:function(e,t){x.forOwn(t,function(t,n){e.hasOwnProperty(n)&&void 0!==e[n]||(e[n]=t)})},forEachRelation:function(e,t,n,r){var i=e.relationList||[];i.length&&i.forEach(function(e){x._forRelation(t,e,n,r)})},forOwn:function(e,t,n){var r=Object.keys(e),i=r.length,o=void 0;for(o=0;i>o;o++)t.call(n,e[r[o]],r[o],e)},fromJson:function(e){return x.isString(e)?JSON.parse(e):e},get:function(e,t){if(t){for(var n=t.split("."),r=n.pop();t=n.shift();)if(e=e[t],null==e)return;return e[r]}},getSuper:function(e,t){var n=t?e:e.constructor;return n.__super__||Object.getPrototypeOf(n)||n.__proto__},intersection:function(e,t){if(!e||!t)return[];var n=[],r=void 0,i=void 0,o=e.length;for(i=0;o>i;i++)r=e[i],-1===n.indexOf(r)&&-1!==t.indexOf(r)&&n.push(r);return n},isArray:Array.isArray,isBlacklisted:function(e,t){if(!t||!t.length)return!1;for(var n=void 0,r=0;r<t.length;r++)if(A(t[r])===g&&t[r].test(e)||t[r]===e)return n=e;return!!n},isBoolean:function(e){return A(e)===l},isBrowser:!1,isDate:function(e){return e&&"object"===("undefined"==typeof e?"undefined":s.typeof(e))&&A(e)===d},isFunction:function(e){return"function"==typeof e||e&&A(e)===p},isInteger:function(e){return A(e)===h&&e==w(e)},isNull:function(e){return null===e},isNumber:function(e){var t="undefined"==typeof e?"undefined":s.typeof(e);return"number"===t||e&&"object"===t&&A(e)===h},isObject:function(e){return A(e)===v},isRegExp:function(e){return A(e)===g},isSorN:function(e){return x.isString(e)||x.isNumber(e)},isString:function(e){return"string"==typeof e||e&&"object"===("undefined"==typeof e?"undefined":s.typeof(e))&&A(e)===y},isUndefined:function(e){return void 0===e},logify:function(e){x.addHiddenPropsToTarget(e,{dbg:function(){for(var e=arguments.length,t=Array(e),n=0;e>n;n++)t[n]=arguments[n];this.log.apply(this,["debug"].concat(t))},log:function(e){for(var t=arguments.length,n=Array(t>1?t-1:0),r=1;t>r;r++)n[r-1]=arguments[r];if(e&&!n.length&&(n.push(e),e="debug"),"debug"!==e||this.debug){var i=e.toUpperCase()+": ("+(this.name||this.constructor.name)+")";if(console[e]){var o;(o=console)[e].apply(o,[i].concat(n))}else{var a;(a=console).log.apply(a,[i].concat(n))}}}})},omit:function(e,t){var n={};return x.forOwn(e,function(e,r){-1===t.indexOf(r)&&(n[r]=e)}),n},plainCopy:function(e){return x.copy(e,void 0,void 0,void 0,void 0,!0)},possibleConstructorReturn:function(e,t){if(!e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return!t||"object"!==("undefined"==typeof t?"undefined":s.typeof(t))&&"function"!=typeof t?e:t},reject:function(e){return x.Promise.reject(e)},resolve:function(e){return x.Promise.resolve(e)},set:function(e,t,n){if(x.isObject(t))x.forOwn(t,function(t,n){x.set(e,n,t)});else{var r=b.exec(t);r?O(e,r[1])[r[2]]=n:e[t]=n}},strictEqual:function(e,t){var n=e===t;return n||(x.isObject(e)&&x.isObject(t)?(x.forOwn(e,function(e,r){n=n&&x.strictEqual(e,t[r])}),x.forOwn(t,function(t,r){n=n&&x.strictEqual(t,e[r])})):x.isArray(e)&&x.isArray(t)&&e.forEach(function(e,r){n=n&&x.strictEqual(e,t[r])})),n},toJson:JSON.stringify,unset:function(e,t){for(var n=t.split("."),r=n.pop();t=n.shift();)if(e=e[t],null==e)return;e[r]=void 0}};try{x.isBrowser=!!window}catch(e){x.isBrowser=!1}var C=x;t.extend=C.extend,C.logify(t.prototype),C.eventify(t.prototype,function(){return this._listeners},function(e){this._listeners=e});var E={limit:"",offset:"",orderBy:"",skip:"",sort:"",where:""},R=/([.*+?^=!:${}()|[\]\/\\])/g,j=/%/g,I=/_/g,F=function(e){return e.replace(R,"\\$1")},S=t.extend({constructor:function e(t){C.classCallCheck(this,e),this.collection=t,this.data=null},between:function(e,t,n){var r=this;if(n||(n={}),r.data)throw new Error("Cannot access index after first operation!");return r.data=r.collection.getIndex(n.index).between(e,t,n),r},compare:function(e,t,n,r){var i=e[t],o=C.get(n,i[0]),a=C.get(r,i[0]);return o&&C.isString(o)&&(o=o.toUpperCase()),a&&C.isString(a)&&(a=a.toUpperCase()),void 0===n&&(n=null),void 0===r&&(r=null),"DESC"===i[1]?o>a?-1:a>o?1:t<e.length-1?this.compare(e,t+1,n,r):0:a>o?-1:o>a?1:t<e.length-1?this.compare(e,t+1,n,r):0},evaluate:function(e,t,n){var r=this.constructor.ops;return r[t]?r[t](e,n):0===t.indexOf("like")?!C.isNull(this.like(n,t.substr(4)).exec(e)):0===t.indexOf("notLike")?C.isNull(this.like(n,t.substr(7)).exec(e)):void 0},filter:function(e,t){var n=this;return e||(e={}),n.getData(),C.isObject(e)?!function(){var t={};C.isObject(e.where)&&(t=e.where),C.forOwn(e,function(e,n){n in E||n in t||(t[n]={"==":e})});var r=[],i=[],o=[];C.forOwn(t,function(e,t){C.isObject(e)||(e={"==":e}),C.forOwn(e,function(e,n){r.push(t),i.push(n),o.push(e)})}),r.length&&!function(){var e=void 0,t=r.length;n.data=n.data.filter(function(a){var u=!0,s=!0;for(e=0;t>e;e++){var c=i[e],f="|"===c.charAt(0);c=f?c.substr(1):c;var l=n.evaluate(C.get(a,r[e]),c,o[e]);void 0!==l&&(s=u?l:f?s||l:s&&l),u=!1}return s})}();var a=e.orderBy||e.sort;C.isString(a)&&(a=[[a,"ASC"]]),C.isArray(a)||(a=null),a&&!function(){var e=0;a.forEach(function(e,t){C.isString(e)&&(a[t]=[e,"ASC"])}),n.data.sort(function(t,r){return n.compare(a,e,t,r)})}(),C.isNumber(e.skip)?n.skip(e.skip):C.isNumber(e.offset)&&n.skip(e.offset),C.isNumber(e.limit)&&n.limit(e.limit)}():C.isFunction(e)&&(n.data=n.data.filter(e,t)),n},forEach:function(e,t){return this.getData().forEach(e,t),this},get:function(e,t){var n=this;if(e||(e=[]),t||(t={}),n.data)throw new Error("Cannot access index after first operation!");return e&&!C.isArray(e)&&(e=[e]),e.length?(n.data=n.collection.getIndex(t.index).get(e),n):(n.getData(),n)},getAll:function(){var e=this,t={};if(e.data)throw new Error("Cannot access index after first operation!");for(var n=arguments.length,r=Array(n),i=0;n>i;i++)r[i]=arguments[i];if(!r.length||1===r.length&&C.isObject(r[0]))return e.getData(),e;r.length&&C.isObject(r[r.length-1])&&(t=r[r.length-1],r.pop());var o=e.collection,a=o.getIndex(t.index);return e.data=[],r.forEach(function(t){e.data=e.data.concat(a.get(t))}),e},getData:function(){var e=this;return e.data||(e.data=e.collection.index.getAll()),e.data},like:function(e,t){return new RegExp("^"+F(e).replace(j,".*").replace(I,".")+"$",t)},limit:function(e){if(!C.isNumber(e))throw new TypeError("limit: Expected number but found "+("undefined"==typeof e?"undefined":s.typeof(e))+"!");var t=this.getData();return this.data=t.slice(0,Math.min(t.length,e)),this},map:function(e,t){return this.data=this.getData().map(e,t),this},mapCall:function(e){for(var t=arguments.length,n=Array(t>1?t-1:0),r=1;t>r;r++)n[r-1]=arguments[r];return this.data=this.getData().map(function(t){return t[e].apply(t,n)}),this},run:function(){var e=this.data;return this.data=null,e},skip:function(e){if(!C.isNumber(e))throw new TypeError("skip: Expected number but found "+("undefined"==typeof e?"undefined":s.typeof(e))+"!");var t=this.getData();return e<t.length?this.data=t.slice(e):this.data=[],this}},{ops:{"==":function(e,t){return e==t},"===":function(e,t){return e===t},"!=":function(e,t){return e!=t},"!==":function(e,t){return e!==t},">":function(e,t){return e>t},">=":function(e,t){return e>=t},"<":function(e,t){return t>e},"<=":function(e,t){return t>=e},isectEmpty:function(e,t){return!C.intersection(e||[],t||[]).length},isectNotEmpty:function(e,t){return C.intersection(e||[],t||[]).length},in:function(e,t){return-1!==t.indexOf(e)},notIn:function(e,t){return-1===t.indexOf(e)},contains:function(e,t){return-1!==(e||[]).indexOf(t)},notContains:function(e,t){return-1===(e||[]).indexOf(t)}}});C.addHiddenPropsToTarget(a.prototype,{set:function(e,t){C.isArray(e)||(e=[e]);var n=e.shift()||null,i=o(this.keys,n);if(0===e.length)if(i.found){var u=o(this.values[i.index],t,this.hashCode);u.found||r(this.values[i.index],u.index,t)}else r(this.keys,i.index,n),r(this.values,i.index,[t]);else if(i.found)this.values[i.index].set(e,t);else{r(this.keys,i.index,n);var s=new a([],{hashCode:this.hashCode});s.set(e,t),r(this.values,i.index,s)}},get:function(e){C.isArray(e)||(e=[e]);var t=e.shift()||null,n=o(this.keys,t);return 0===e.length?n.found?this.values[n.index].isIndex?this.values[n.index].getAll():this.values[n.index]:[]:n.found?this.values[n.index].get(e):[]},getAll:function(){var e=[];return this.values.forEach(function(t){e=t.isIndex?e.concat(t.getAll()):e.concat(t)}),e},visitAll:function(e,t){this.values.forEach(function(n){n.isIndex?n.visitAll(e,t):n.forEach(e,t)})},between:function(e,t,n){n||(n={}),C.isArray(e)||(e=[e]),C.isArray(t)||(t=[t]),C.fillIn(n,{leftInclusive:!0,rightInclusive:!1,limit:void 0,offset:0});var r=this._between(e,t,n);return n.limit?r.slice(n.offset,n.limit+n.offset):r.slice(n.offset)},_between:function(e,t,n){var r=[],i=e.shift(),a=t.shift(),u=void 0;if(u=void 0!==i?o(this.keys,i):{found:!1,index:0},0===e.length){u.found&&n.leftInclusive===!1&&(u.index+=1);for(var s=u.index;s<this.keys.length;s+=1){if(void 0!==a)if(n.rightInclusive){if(this.keys[s]>a)break}else if(this.keys[s]>=a)break;if(r=this.values[s].isIndex?r.concat(this.values[s].getAll()):r.concat(this.values[s]),n.limit&&r.length>=n.limit+n.offset)break}}else for(var c=u.index;c<this.keys.length;c+=1){var f=this.keys[c];if(f>a)break;if(r=this.values[c].isIndex?f===i?r.concat(this.values[c]._between(C.copy(e),t.map(function(){}),n)):f===a?r.concat(this.values[c]._between(e.map(function(){}),C.copy(t),n)):r.concat(this.values[c].getAll()):r.concat(this.values[c]),n.limit&&r.length>=n.limit+n.offset)break}return n.limit?r.slice(0,n.limit+n.offset):r},peek:function(){return this.values.length?this.values[0].isIndex?this.values[0].peek():this.values[0]:[]},clear:function(){this.keys=[],this.values=[]},insertRecord:function(e){var t=this.fieldList.map(function(t){return C.isFunction(t)?t(e)||null:e[t]||null});this.set(t,e)},removeRecord:function(e){var t=this,n=void 0;return this.values.forEach(function(r,a){if(r.isIndex){if(r.removeRecord(e))return 0===r.keys.length&&(i(t.keys,a),i(t.values,a)),n=!0,!1}else{var u=o(r,e,t.hashCode);if(u.found)return i(r,u.index),0===r.length&&(i(t.keys,a),i(t.values,a)),n=!0,!1}}),n?e:void 0},updateRecord:function(e){this.removeRecord(e),this.insertRecord(e)}});var k={idAttribute:"id",mapper:null,onConflict:"merge",recordOpts:null},P=t.extend({constructor:function e(t,n){var r=this;C.classCallCheck(r,e),e.__super__.call(r),C.isObject(t)&&!C.isArray(t)&&(n=t,t=[]),C.isString(n)&&(n={idAttribute:n}),t||(t=[]),n||(n={}),n.recordOpts||(n.recordOpts={}),C.fillIn(r,n),C.fillIn(r,k);var i=r.recordId();r.index=new a([i],{hashCode:function(e){return C.get(e,i)}}),r.indexes={},t.forEach(function(e){e=r.mapper?r.mapper.createRecord(e,r.recordOpts):e,r.index.insertRecord(e),e&&C.isFunction(e.on)&&e.on("all",r._onRecordEvent,r)})},_onRecordEvent:function(){this.emit.apply(this,arguments)},add:function(e,t){var n=this;t||(t={}),C._(n,t),e=n.beforeAdd(e,t)||e;var r=!1,i=n.recordId();C.isObject(e)&&!C.isArray(e)&&(e=[e],r=!0),e=e.map(function(e){var r=n.recordId(e);if(!C.isSorN(r))throw new TypeError("Collection#add: Expected string or number for "+i+", found "+("undefined"==typeof r?"undefined":s.typeof(r))+"!");var o=n.get(r);if(e===o)return o;if(o){var a=t.onConflict||n.onConflict;"merge"===a?C.deepMixIn(o,e):"replace"===a&&(C.forOwn(o,function(t,n){n===i||e.hasOwnProperty(n)||delete o[n]}),o.set(e)),e=o,n.updateIndexes(e)}else e=n.mapper?n.mapper.createRecord(e,n.recordOpts):e,n.index.insertRecord(e),C.forOwn(n.indexes,function(t,n){t.insertRecord(e)}),e&&C.isFunction(e.on)&&e.on("all",n._onRecordEvent,n);return e});var o=r?e.length?e[0]:void 0:e;return n.emit("add",o),n.afterAdd(e,t,o)||o},afterAdd:function(){},afterRemove:function(){},afterRemoveAll:function(){},beforeAdd:function(){},beforeRemove:function(){},beforeRemoveAll:function(){},between:function(e,t,n){return this.query().between(e,t,n).run()},createIndex:function(e,t,n){var r=this;C.isString(e)&&void 0===t&&(t=[e]),n||(n={}),n.hashCode=n.hashCode||function(e){return r.recordId(e)};var i=r.indexes[e]=new a(t,n);return r.index.visitAll(i.insertRecord,i),r},filter:function(e,t){return this.query().filter(e,t).run()},forEach:function(e,t){this.index.visitAll(e,t)},get:function(e){var t=this.query().get(e).run();return t.length?t[0]:void 0},getAll:function(){var e;return(e=this.query()).getAll.apply(e,arguments).run()},getIndex:function(e){var t=e?this.indexes[e]:this.index;if(!t)throw new Error("Index "+e+" does not exist!");return t},limit:function(e){return this.query().limit(e).run()},map:function(e,t){var n=[];return this.index.visitAll(function(r){n.push(e.call(t,r))}),n},mapCall:function(e){for(var t=arguments.length,n=Array(t>1?t-1:0),r=1;t>r;r++)n[r-1]=arguments[r];var i=[];return this.index.visitAll(function(t){i.push(t[e].apply(t,n))}),i},recordId:function(e){if(e)return C.get(e,this.recordId());var t=this;return t.mapper?t.mapper.idAttribute:t.idAttribute||"id"},query:function(){return new S(this)},reduce:function(e,t){var n=this.getAll();return n.reduce(e,t)},remove:function(e,t){var n=this;t||(t={}),n.beforeRemove(e,t);var r=n.get(e);return r&&(n.index.removeRecord(r),C.forOwn(n.indexes,function(e,t){e.removeRecord(r)}),r&&C.isFunction(r.off)&&(r.off("all",n._onRecordEvent,n),n.emit("remove",r))),n.afterRemove(e,t,r)||r},removeAll:function(e,t){var n=this;t||(t={}),n.beforeRemoveAll(e,t);var r=n.filter(e);return r.forEach(function(e){n.remove(n.recordId(e),t)}),n.afterRemoveAll(e,t,r)||r},skip:function(e){return this.query().skip(e).run()},toJSON:function(e){return this.mapCall("toJSON",e)},updateIndex:function(e,t){t||(t={}),this.getIndex(t.index).updateRecord(e)},updateIndexes:function(e){var t=this;t.index.updateRecord(e),C.forOwn(t.indexes,function(t,n){t.updateRecord(e)})}}),L="belongsTo",M="hasMany",K="hasOne";C.addHiddenPropsToTarget(u.prototype,{getRelation:function(){return this.relatedMapper},getLocalKeys:function(e){},getForeignKey:function(e){return this.type===L?C.get(e,this.foreignKey):C.get(e,this.mapper.idAttribute)},setForeignKey:function(e,t){var n=this;e&&t&&(n.type===L?C.set(e,n.foreignKey,C.get(t,n.getRelation().idAttribute)):!function(){var r=n.mapper.idAttribute;C.isArray(t)?t.forEach(function(t){C.set(t,n.foreignKey,C.get(e,r))}):C.set(t,n.foreignKey,C.get(e,r))}())},getLocalField:function(e){return C.get(e,this.localField)},setLocalField:function(e,t){return C.set(e,this.localField,t)}});var N=function(e,t,n){if(n||(n={}),!n.type)throw new Error("must specify relation type!");n.mapper=e,n.name=e.name;var r=new u(t,n);e.relationList||Object.defineProperty(e,"relationList",{value:[]}),e.relationFields||Object.defineProperty(e,"relationFields",{value:[]}),e.relationList.push(r),e.relationFields.push(r.localField)},U=function(e,t){return t||(t={}),t.type=L,function(n){N(n,e,t)}},T=function(e,t){return t||(t={}),t.type=M,function(n){N(n,e,t)}},D=function(e,t){return t||(t={}),t.type=K,function(n){N(n,e,t)}},q=t.extend({constructor:function e(t,n){var r=this;C.classCallCheck(r,e),t||(t={}),n||(n={});var i={};Object.defineProperties(r,{_get:{enumerable:!1,value:function(e){return C.get(i,e)}},_set:{enumerable:!1,value:function(e,t){return C.set(i,e,t)}},_unset:{enumerable:!1,value:function(e){return C.unset(i,e)}}});var o=r._set;o("creating",!0),n.noValidate&&o("noValidate",!0),C.fillIn(r,t),o("creating",!1),o("noValidate",!1),o("previous",C.copy(t))},_mapper:function(){if(!this.constructor.mapper)throw new Error("This recordClass has no Mapper!");return this.constructor.mapper},afterLoadRelations:function(){},afterSave:function(){},beforeLoadRelations:function(){},beforeSave:function(){},changes:function(e){var t=this;return e||(e={}),C.diffObjects(t,t._get("previous"),e)},commit:function(){var e=this;return e._set("changed"),e._set("previous",C.copy(e)),e},create:function(e){return this._mapper().create(this,e)},destroy:function(e){var t=this._mapper();return t.destroy(C.get(this,t.idAttribute),e)},get:function(e){return C.get(this,e)},hasChanges:function(e){var t=this,n=!!(t._get("changed")||[]).length;return n||C.areDifferent(t,t._get("previous"),e)},hashCode:function(){var e=this;return C.get(e,e._mapper().idAttribute)},isValid:function(e){var t=this;return!!t._mapper().validate(t,e)},loadRelations:function(e,t){var n=void 0,r=this,i=r._mapper(),o=i.relationList||[];return e||(e=[]),t||(t={}),C._(i,t),t.adapter=i.getAdapterName(t),n=t.op="beforeLoadRelations",C.resolve(r[n](e,t)).then(function(){return C.isString(e)&&(e=[e]),n=t.op="loadRelations",i.dbg(n,r,e,t),Promise.all(o.map(function(e){if(C.isFunction(e.load))return e.load(i,e,r,t);var n=void 0;if("hasMany"===e.type&&e.foreignKey)n=e.getRelation().findAll(s.defineProperty({},e.foreignKey,C.get(r,i.idAttribute)),t);else if(e.foreignKey){var o=C.get(r,e.foreignKey);C.isSorN(o)&&(n=e.getRelation().find(o,t))}else e.localKeys?n=e.getRelation().findAll(s.defineProperty({},e.getRelation().idAttribute,{in:C.get(r,e.localKeys)}),t):e.foreignKeys&&(n=e.getRelation().findAll(s.defineProperty({},e.getRelation().idAttribute,{contains:C.get(r,i.idAttribute)}),t));return n&&(n=n.then(function(n){t.raw&&(n=n.data),C.set(r,e.localField,"hasOne"===e.type?n.length?n[0]:void 0:n)})),n}))}).then(function(){return n=t.op="afterLoadRelations",C.resolve(r[n](e,t)).then(function(){return r})})},previous:function(e){var t=this;return e?t._get("previous."+e):t._get("previous")},revert:function(e){var t=this,n=t._get("previous")||{};return e||(e={}),e.preserve||(e.preserve=[]),C.forOwn(t,function(r,i){i!==t._mapper().idAttribute&&!n.hasOwnProperty(i)&&t.hasOwnProperty(i)&&-1===e.preserve.indexOf(i)&&delete t[i]}),C.forOwn(n,function(n,r){-1===e.preserve.indexOf(r)&&(t[r]=n)}),t.commit(),t},save:function(e){var t=this,n=t._mapper();return n.update(C.get(t,n.idAttribute),t,e)},set:function(e,t,n){var r=this;C.isObject(e)&&(n=t),n||(n={}),n.silent&&r._set("silent",!0),C.set(r,e,t),r._get("eventId")||r._set("silent")},toJSON:function(e){var t=this,n=this.constructor.mapper;if(n)return n.toJSON(this,e);var r=function(){var e={};return C.forOwn(t,function(t,n){e[n]=C.copy(t)}),{v:e}}();return"object"===("undefined"==typeof r?"undefined":s.typeof(r))?r.v:void 0},unset:function(e,t){this.set(e,void 0,t)},validate:function(e){return this._mapper().validate(this,e)}});C.eventify(q.prototype,function(){return this._get("events")},function(e){this._set("events",e)});var Q={array:C.isArray,boolean:C.isBoolean,integer:C.isInteger,null:C.isNull,number:C.isNumber,object:C.isObject,string:C.isString},J=function(e,t){var n="";return e&&(n+=C.isNumber(e)?"["+e+"]":t?"."+e:""+e),n},B=function(e){e||(e={});var t="",n=e.path||[];return n.forEach(function(e){t+=J(e,t)}),t+=J(e.prop,t)},$=function(e,t,n){return{expected:t,actual:""+e,path:B(n)}},V=function(e,t,n,r){r.push($(e,t,n))},H=function(e,t,n,r){var i=n[e];return t.length>i?$(t.length,"length no more than "+i,r):void 0},G=function(e,t,n,r){var i=n[e];return t.length<i?$(t.length,"length no less than "+i,r):void 0},W={allOf:function(e,t,n){var r=[];return t.allOf.forEach(function(t){r=r.concat(ie(e,t,n)||[])}),r.length?void 0:r},anyOf:function(e,t,n){var r=!1,i=[];return t.anyOf.forEach(function(t){var o=ie(e,t,n);o?i=i.concat(o):r=!0}),r?void 0:i},dependencies:function(e,t,n){},enum:function(e,t,n){var r=t.enum;return-1===r.indexOf(e)?$(e,"one of ("+r.join(", ")+")",n):void 0},items:function e(t,n,r){r||(r={});for(var e=n.items,i=[],o=C.isArray(e),a=t.length,u=0;a>u;u++)o&&(e=n.items[u]),r.prop=u,i=i.concat(ie(t[u],e,r)||[]);return i.length?i:void 0},maximum:function e(t,n,r){var e=n.maximum,i=n.exclusiveMaximum;return("undefined"==typeof t?"undefined":s.typeof(t))===("undefined"==typeof e?"undefined":s.typeof(e))&&(i?t>e:t>=e)?$(t,"no more than "+e,r):void 0},maxItems:function(e,t,n){return H("maxItems",e,t,n)},maxLength:function(e,t,n){return H("maxLength",e,t,n)},maxProperties:function e(t,n,r){var e=n.maxProperties,i=Object.keys(t).length;return i>e?$(i,"no more than "+e+" properties",r):void 0},minimum:function e(t,n,r){var e=n.minimum,i=n.exclusiveMinimum;return("undefined"==typeof t?"undefined":s.typeof(t))===("undefined"==typeof e?"undefined":s.typeof(e))&&(i?e>t:e>=t)?$(t,"no less than "+e,r):void 0},minItems:function(e,t,n){return G("minItems",e,t,n)},minLength:function(e,t,n){return G("minLength",e,t,n)},minProperties:function e(t,n,r){var e=n.minProperties,i=Object.keys(t).length;return e>i?$(i,"no more than "+e+" properties",r):void 0},multipleOf:function(e,t,n){},not:function(e,t,n){return ie(e,t.not,n)?void 0:$("succeeded","should have failed",n)},oneOf:function(e,t,n){var r=!1,i=[];return t.oneOf.forEach(function(t){var o=ie(e,t,n);if(o)i=i.concat(o);else{if(r)return i=[$("valid against more than one","valid against only one",n)],r=!1,!1;r=!0}}),r?void 0:i},pattern:function e(t,n,r){var e=n.pattern;return C.isString(t)&&!t.match(e)?$(t,e,r):void 0},properties:function e(t,n,r){r||(r={});var i=C.isUndefined(n.additionalProperties)?!0:n.additionalProperties,o={},e=n.properties||{},a=n.patternProperties||{},u=[];C.forOwn(t,function(e,t){o[t]=void 0}),C.forOwn(e||{},function(e,n){C.isUndefined(t[n])&&!C.isUndefined(e.default)&&(t[n]=C.copy(e.default)),r.prop=n,u=u.concat(ie(t[n],e,r)||[]),delete o[n]}),C.forOwn(a,function(e,n){C.forOwn(o,function(i,a){a.match(n)&&(r.prop=a,u=u.concat(ie(t[a],e,r)||[]),delete o[a])})});var s=Object.keys(o);return i===!1?s.length&&V("extra fields: "+s.join(", "),"no extra fields",r,u):C.isObject(i)&&s.forEach(function(e){r.prop=e,u=u.concat(ie(t[e],i,r)||[])}),u.length?u:void 0},required:function e(t,n,r){var e=n.required,i=[];return r.existingOnly||e.forEach(function(e){if(C.isUndefined(C.get(t,e))){var n=r.prop;r.prop=e,V(void 0,"a value",r,i),r.prop=n}}),i.length?i:void 0},type:function e(t,n,r){var e=n.type,i=void 0;if(C.isString(e)&&(e=[e]),e.forEach(function(e){return Q[e](t,n,r)?(i=e,!1):void 0}),!i)return $(t?"undefined"==typeof t?"undefined":s.typeof(t):""+t,"one of ("+e.join(", ")+")",r);var o=pe[i];return o?o(t,n,r):void 0},uniqueItems:function(e,t,n){if(e&&e.length&&t.uniqueItems){var r=e.length,i=void 0,o=void 0,a=void 0;for(o=r-1;o>0;o--)for(i=e[o],a=o-1;a>=0;a--)if(i===e[a])return $(i,"no duplicates",n)}}},z=function(e,t,n,r){return!C.isUndefined(n[e])&&W[e](t,n,r)},X=function(e,t,n,r){var i=[];return e.forEach(function(e){i=i.concat(z(e,t,n,r)||[])}),i.length?i:void 0},Y=["enum","type","allOf","anyOf","oneOf","not"],Z=["items","maxItems","minItems","uniqueItems"],ee=["multipleOf","maximum","minimum"],te=["maxProperties","minProperties","required","properties","dependencies"],ne=["maxLength","minLength","pattern"],re=function(e,t,n){return X(Y,e,t,n)},ie=function e(t,n,r){var i=[];r||(r={});var o=void 0,a=r.prop;if(!C.isUndefined(n)){if(!C.isObject(n))throw new Error('Invalid schema at path: "'+r.path+'"');return C.isUndefined(r.path)&&(r.path=[]),C.isUndefined(r.prop)||(o=!0,r.path.push(r.prop),r.prop=void 0),n.extends&&(i=C.isFunction(n.extends.validate)?i.concat(n.extends.validate(t,r)||[]):i.concat(e(t,n.extends,r)||[])),C.isUndefined(t)?(n.required===!0&&V(t,"a value",r,i),o&&(r.path.pop(),r.prop=a),i.length?i:void 0):(i=i.concat(re(t,n,r)||[]),o&&(r.path.pop(),r.prop=a),i.length?i:void 0)}},oe="changing",ae="changed",ue="creating",se="eventId",ce="noValidate",fe="silent",le="validation failed",de=function(e,t,n){var r={enumerable:C.isUndefined(t.enumerable)?!0:!!t.enumerable},i="props."+e,o="previous."+e,a=n.getter,u=n.setter,s=n.unsetter;return r.get=function(){return this._get(i)},r.set=function(n){var r=this,c=r[a],f=r[u],l=r[s];if(!c(ce)){var d=t.validate(n);if(d){var p=new Error(le);throw p.errors=d,p}}return t.track&&!c(ue)&&!function(){var t=c(o),a=c(i),u=c(oe),s=c(ae);u||(s=[]);var d=s.indexOf(e);a!==n&&-1===d&&s.push(e),t===n&&d>=0&&s.splice(d,1),s.length||(u=!1,l(oe),l(ae),c(se)&&(clearTimeout(c(se)),l(se))),!u&&s.length&&(f(ae,s),f(oe,!0),f(se,setTimeout(function(){if(l(ae),l(se),l(oe),!c(fe)){var e=void 0;for(e=0;e<s.length;e++)r.emit("change:"+s[e],r,C.get(r,s[e]));r.emit("change",r,r.changes())}l(fe)},0)))}(),f(i,n),n},r},pe={array:function(e,t,n){return X(Z,e,t,n)},integer:function(e,t,n){return pe.numeric(e,t,n)},number:function(e,t,n){return pe.numeric(e,t,n)},numeric:function(e,t,n){return X(ee,e,t,n)},object:function(e,t,n){return X(te,e,t,n)},string:function(e,t,n){return X(ne,e,t,n)}},he=t.extend({constructor:function e(t){t||(t={}),C.fillIn(this,t),t.properties&&C.forOwn(t.properties,function(n,r){n instanceof e||(t.properties[r]=new e(n))})},apply:function(e,t){t||(t={}),t.getter=t.getter||"_get",t.setter=t.setter||"_set",t.unsetter=t.unsetter||"_unset";var n=this.properties||{};C.forOwn(n,function(n,r){Object.defineProperty(e,r,de(r,n,t))})},validate:function(e,t){return ie(e,this,t)}},{typeGroupValidators:pe,types:Q,validate:ie,validationKeywords:W}),ve=function(){for(var e=arguments.length,t=Array(e),n=0;e>n;n++)t[n]=arguments[n];var r=this,i=t[t.length-1];r.dbg.apply(r,[i.op].concat(t)),(i.notify||void 0===i.notify&&r.notify)&&setTimeout(function(){r.emit.apply(r,[i.op].concat(t))})},ge=function(){for(var e=arguments.length,t=Array(e),n=0;e>n;n++)t[n]=arguments[n];var r=this,i=t[t.length-2];r.dbg.apply(r,[i.op].concat(t)),(i.notify||void 0===i.notify&&r.notify)&&setTimeout(function(){r.emit.apply(r,[i.op].concat(t))})},ye={applySchema:!0,debug:!1,defaultAdapter:"http",idAttribute:"id",lifecycleMethods:{count:{defaults:[{},{}],skip:!0,types:[]},destroy:{defaults:[{},{}],skip:!0,types:[]},destroyAll:{defaults:[{},{}],skip:!0,types:[] | ||
},find:{defaults:[void 0,{}],types:[]},findAll:{defaults:[{},{}],types:[]},sum:{defaults:[void 0,{},{}],skip:!0,types:[]},update:{adapterArgs:function(e,t,n,r){return[t,e.toJSON(n,r),r]},beforeAssign:1,defaults:[void 0,{},{}],types:[]},updateAll:{adapterArgs:function(e,t,n,r){return[e.toJSON(t,r),n,r]},beforeAssign:0,defaults:[{},{},{}],types:[]},updateMany:{adapterArgs:function(e,t,n){return[t.map(function(t){return e.toJSON(t,n)}),n]},beforeAssign:0,defaults:[[],{}],types:[]}},name:null,notify:C.isBrowser,raw:!1,schema:null},me=t.extend({constructor:function e(t){var n=this;if(C.classCallCheck(n,e),e.__super__.call(n),t||(t={}),Object.defineProperty(n,"_adapters",{value:void 0,writable:!0}),Object.defineProperty(n,"_listeners",{value:{},writable:!0}),Object.defineProperty(n,"recordClass",{value:void 0,writable:!0}),C.fillIn(n,t),C.fillIn(n,C.copy(ye)),!n.name)throw new Error("mapper cannot function without a name!");n._adapters||(n._adapters={}),n.schema instanceof he||(n.schema=new he(n.schema||{})),C.isUndefined(n.recordClass)&&(n.recordClass=q.extend()),n.recordClass&&(n.recordClass.mapper=n,C.getSuper(n.recordClass,!0)===q&&n.schema&&n.schema.apply&&n.applySchema&&n.schema.apply(n.recordClass.prototype))},afterCount:ge,afterCreate:ge,afterCreateMany:ge,afterDestroy:ge,afterDestroyAll:ge,afterFind:ge,afterFindAll:ge,afterSum:ge,afterUpdate:ge,afterUpdateAll:ge,afterUpdateMany:ge,beforeCreate:ve,beforeCreateMany:ve,beforeCount:ve,beforeDestroy:ve,beforeDestroyAll:ve,beforeFind:ve,beforeFindAll:ve,beforeSum:ve,beforeUpdate:ve,beforeUpdateAll:ve,beforeUpdateMany:ve,_end:function(e,t,n){var r=this;if(t.raw&&C._(t,e),n)return e;var i=t.raw?e.data:e;return C.isArray(i)&&i.length&&C.isObject(i[0])?i=i.map(function(e){return r.createRecord(e)}):C.isObject(i)&&(i=r.createRecord(i)),t.raw?e.data=i:e=i,e},belongsTo:function(e,t){return U(e,t)(this)},count:function(e,t){return this.crud("count",e,t)},create:function(e,t){var n=void 0,r=void 0,i=this;return e||(e={}),t||(t={}),C._(i,t),r=t.adapter=i.getAdapterName(t),n=t.op="beforeCreate",C.resolve(i[n](e,t)).then(function(o){e=C.isUndefined(o)?e:o;var a={};t.with||(t.with=[]);var u=[];return C.forEachRelation(i,t,function(t,n){var r=t.getLocalField(e);t.type===L&&r&&u.push(t.getRelation().create(r,n).then(function(r){var i=n.raw?r.data:r;t.setLocalField(a,i),t.setForeignKey(e,i)}))}),C.Promise.all(u).then(function(){return n=t.op="create",i.dbg(n,e,t),C.resolve(i.getAdapter(r)[n](i,i.toJSON(e,{with:t.pass||[]}),t))}).then(function(n){var r=t.raw?n.data:n;return u=[],C.forEachRelation(i,t,function(n,i){var o=n.getLocalField(e);if(o){var s=void 0;n.type===M?(n.setForeignKey(r,o),s=n.getRelation().createMany(o,i).then(function(e){n.setLocalField(r,t.raw?e.data:e)})):n.type===K?(n.setForeignKey(r,o),s=n.getRelation().create(o,i).then(function(e){n.setLocalField(r,t.raw?e.data:e)})):n.type===L&&n.getLocalField(a)&&n.setLocalField(r,n.getLocalField(a)),s&&u.push(s)}}),C.Promise.all(u).then(function(){return n})})}).then(function(r){return r=i._end(r,t),n=t.op="afterCreate",C.resolve(i[n](e,t,r)).then(function(e){return C.isUndefined(e)?r:e})})},createInstance:function(e,t){return this.createRecord(e,t)},createMany:function(e,t){var n=void 0,r=void 0,i=this;return e||(e=[]),t||(t={}),C._(i,t),r=t.adapter=i.getAdapterName(t),n=t.op="beforeCreateMany",C.resolve(i[n](e,t)).then(function(o){e=C.isUndefined(o)?e:o;var a={};t.with||(t.with=[]);var u=[];return C.forEachRelation(i,t,function(t,n){var r=e.map(function(e){return t.getLocalField(e)}).filter(function(e){return e});t.type===L&&r.length===e.length&&u.push(t.getRelation().createMany(r,n).then(function(r){var i=n.raw?r.data:r;t.setLocalField(a,i),e.forEach(function(e,n){t.setForeignKey(e,i[n])})}))}),C.Promise.all(u).then(function(){n=t.op="createMany";var o=e.map(function(e){return i.toJSON(e,{with:t.pass||[]})});return i.dbg(n,e,t),C.resolve(i.getAdapter(r)[n](i,o,t))}).then(function(n){var r=t.raw?n.data:n;return u=[],C.forEachRelation(i,t,function(n,o){var s=e.map(function(e){return n.getLocalField(e)}).filter(function(e){return e});if(s.length===e.length){var c=n.getLocalField(a),f=void 0;n.type===M?i.log("warn","deep createMany of hasMany type not supported!"):n.type===K?(r.forEach(function(e,t){n.setForeignKey(e,s[t])}),f=n.getRelation().createMany(s,o).then(function(e){var i=t.raw?e.data:e;r.forEach(function(e,t){n.setLocalField(e,i[t])})})):n.type===L&&c&&c.length===r.length&&r.forEach(function(e,t){n.setLocalField(e,c[t])}),f&&u.push(f)}}),C.Promise.all(u).then(function(){return n})})}).then(function(r){return r=i._end(r,t),n=t.op="afterCreateMany",C.resolve(i[n](e,t,r)).then(function(e){return C.isUndefined(e)?r:e})})},createRecord:function(e,t){var n=this,r=n.recordClass,i=n.relationList||[];return i.forEach(function(t){var n=t.getRelation(),r=t.getLocalField(e);C.isArray(r)&&r.length&&!n.is(r[0])?t.setLocalField(e,r.map(function(e){return t.getRelation().createRecord(e)})):C.isObject(r)&&!n.is(r)&&t.setLocalField(e,t.getRelation().createRecord(r))}),r?e instanceof r?e:new r(e,t):e},crud:function(e){for(var t=arguments.length,n=Array(t>1?t-1:0),r=1;t>r;r++)n[r-1]=arguments[r];var i=this,o=i.lifecycleMethods[e];if(!o)throw new Error(e+": No such CRUD method!");var a=""+e.charAt(0).toUpperCase()+e.substr(1),u="before"+a,c="after"+a,f=void 0,l=void 0;o.defaults.forEach(function(e,t){C.isUndefined(n[t])&&(n[t]=C.copy(e))});var d=n[n.length-1];return C._(i,d),l=d.adapter=i.getAdapterName(d),f=d.op=u,C.resolve(i[f].apply(i,s.toConsumableArray(n))).then(function(t){var r;return C.isUndefined(o.beforeAssign)||(n[o.beforeAssign]=C.isUndefined(t)?n[o.beforeAssign]:t),f=d.op=e,n=o.adapterArgs?o.adapterArgs.apply(o,[i].concat(s.toConsumableArray(n))):n,i.dbg.apply(i,[f].concat(s.toConsumableArray(n))),C.resolve((r=i.getAdapter(l))[f].apply(r,[i].concat(s.toConsumableArray(n))))}).then(function(e){return e=i._end(e,d,!!o.skip),n.push(e),f=d.op=c,C.resolve(i[f].apply(i,s.toConsumableArray(n))).then(function(t){return C.isUndefined(t)?e:t})})},destroy:function(e,t){return this.crud("destroy",e,t)},destroyAll:function(e,t){return this.crud("destroyAll",e,t)},find:function(e,t){return this.crud("find",e,t)},findAll:function(e,t){return this.crud("findAll",e,t)},getAdapter:function(e){var t=this;t.dbg("getAdapter","name:",e);var n=t.getAdapterName(e);if(!n)throw new ReferenceError(n+" not found!");return t.getAdapters()[n]},getAdapterName:function(e){return e||(e={}),C.isString(e)&&(e={adapter:e}),e.adapter||e.defaultAdapter},getAdapters:function(){return this._adapters},getSchema:function(){return this.schema},hasMany:function(e,t){return T(e,t)(this)},hasOne:function(e,t){return D(e,t)(this)},is:function(e){var t=this.recordClass;return t?e instanceof t:!1},registerAdapter:function(e,t,n){var r=this;n||(n={}),r.getAdapters()[e]=t,(n===!0||n.default)&&(r.defaultAdapter=e)},sum:function(e,t,n){return this.crud("sum",e,t,n)},toJSON:function(e,t){var n=this;t||(t={});var r=(n?n.relationFields:[])||[],i={},o=void 0;return n&&n.schema&&(o=n.schema.properties||{},C.forOwn(o,function(t,n){i[n]=C.plainCopy(e[n])})),o||(o={}),t.strict||C.forOwn(e,function(e,t){o[t]||-1!==r.indexOf(t)||(i[t]=C.plainCopy(e))}),n&&t.withAll&&(t.with=r.slice()),n&&t.with&&(C.isString(t.with)&&(t.with=[t.with]),C.forEachRelation(n,t,function(t,n){var r=t.getLocalField(e);r&&(C.isArray(r)?t.setLocalField(i,r.map(function(e){return t.getRelation().toJSON(e,n)})):t.setLocalField(i,t.getRelation().toJSON(r,n)))})),i},update:function(e,t,n){return this.crud("update",e,t,n)},updateAll:function(e,t,n){return this.crud("updateAll",e,t,n)},updateMany:function(e,t){return this.crud("updateMany",e,t)},validate:function(e,t){var n=this;if(!n.getSchema())throw new Error("no schema!");if(C.isArray(e))return e.map(function(e){return n.schema.validate(e,t)});if(C.isObject(e))return n.schema.validate(e,t);throw new Error("not a record!")}}),be=["count","create","createMany","createRecord","dbg","destroy","destroyAll","emit","find","findAll","getSchema","is","log","off","on","sum","toJSON","update","updateAll","updateMany"],we={constructor:function e(t){var n=this;C.classCallCheck(n,e),e.__super__.call(n),t||(t={}),C.fillIn(n,t),n.mapperDefaults=n.mapperDefaults||{},n.mapperClass=n.mapperClass||me,n._adapters={},n._mappers={}},defineMapper:function(e,t){var n=this;if(C.isObject(e)){if(t=e,!t.name)throw new Error("name is required!");e=t.name}else if(!C.isString(e))throw new Error("name is required!");t||(t={}),t.name=e,t.relations||(t.relations={});var r=t.mapperClass||n.mapperClass;delete t.mapperClass,C.fillIn(t,n.mapperDefaults);var i=n._mappers[e]=new r(t);return i.name=e,i._adapters=n.getAdapters(),C.forOwn(i.relations,function(e,t){C.forOwn(e,function(e,r){C.isObject(e)&&(e=[e]),e.forEach(function(e){e.getRelation=function(){return n.getMapper(r)};var o=n._mappers[r]||r;t===L?i.belongsTo(o,e):t===K?i.hasOne(o,e):t===M&&i.hasMany(o,e)})})}),i},defineResource:function(e,t){return this.defineMapper(e,t)},getAdapter:function(e){var t=this,n=t.getAdapterName(e);if(!n)throw new ReferenceError(n+" not found!");return t.getAdapters()[n]},getAdapterName:function(e){return e||(e={}),C.isString(e)&&(e={adapter:e}),e.adapter||this.mapperDefaults.defaultAdapter},getAdapters:function(){return this._adapters},getMapper:function(e){var t=this._mappers[e];if(!t)throw new ReferenceError(e+" is not a registered mapper!");return t},registerAdapter:function(e,t,n){var r=this;n||(n={}),r.getAdapters()[e]=t,(n===!0||n.default)&&(r.mapperDefaults.defaultAdapter=e,C.forOwn(r._mappers,function(t){t.defaultAdapter=e}))}};be.forEach(function(e){we[e]=function(t){for(var n,r=arguments.length,i=Array(r>1?r-1:0),o=1;r>o;o++)i[o-1]=arguments[o];return(n=this.getMapper(t))[e].apply(n,i)}});var Ae=t.extend(we),_e=P.extend({constructor:function e(t,n){var r=this;if(C.classCallCheck(r,e),e.__super__.call(r,t,n),r._added={},!r.datastore)throw new Error("This collection must have a datastore!");return r},_onRecordEvent:function(){for(var e=this,t=arguments.length,n=Array(t),r=0;t>r;r++)n[r]=arguments[r];C.getSuper(e).prototype._onRecordEvent.apply(e,n);var i=n[0];C.isString(i)&&0===i.indexOf("change")&&e.updateIndexes(n[1])},add:function(e,t){var n=this,r=n.datastore,i=n.mapper,o=i.relationList||[],a=(new Date).getTime(),u=!!i.recordClass,s=void 0;return C.isObject(e)&&!C.isArray(e)&&(s=!0,e=[e]),o.length&&e.length&&i.relationList.forEach(function(t){var n=t.relation,i=r.getMapper(n),o=i.idAttribute,a=t.foreignKey,u=r.getCollection(n),s=t.type,c=s===M,f=C.isUndefined(t.add)?!0:!!t.add,l=void 0;e.forEach(function(e){if(l=t.getLocalField(e),C.isFunction(t.add))t.add(r,t,e);else if(l){if(c)l=l.map(function(n){return n!==u.get(u.recordId(n))&&(a&&t.setForeignKey(e,n),f&&(n=u.add(n))),n}),t.localKeys&&C.set(e,t.localKeys,l.map(function(e){return C.get(e,o)}));else{var n=C.get(l,o);l!==u.get(n)&&(t.setForeignKey(e,l),f&&(l=u.add(l)))}t.setLocalField(e,l)}})}),e=C.getSuper(n).prototype.add.call(n,e,t),e.forEach(function(e){n._added[n.recordId(e)]=a,u&&e._set("$",a)}),s?e[0]:e},remove:function(e,t){var n=this,r=n.mapper,i=C.getSuper(n).prototype.remove.call(n,e,t);return i&&(delete n._added[e],r.recordClass&&i._set("$")),i},removeAll:function(e,t){var n=this,r=n.mapper,i=C.getSuper(n).prototype.removeAll.call(n,e,t);return i.forEach(function(e){delete n._added[n.recordId(e)],r.recordClass&&e._set("$")}),i}}),Oe={linkRelations:C.isBrowser},xe={constructor:function e(t){var n=this;return C.classCallCheck(n,e),e.__super__.call(n,t),n.collectionClass=n.collectionClass||_e,n._collections={},C.fillIn(n,Oe),n._pendingQueries={},n._completedQueries={},n},_callSuper:function(e){for(var t=arguments.length,n=Array(t>1?t-1:0),r=1;t>r;r++)n[r-1]=arguments[r];return this.constructor.__super__.prototype[e].apply(this,n)},_end:function(e,t,n){return n.raw?(t.data=this.getCollection(e).add(t.data,n),t):t=this.getCollection(e).add(t,n)},cachedFind:function(e,t,n){return this.get(e,t,n)},cachedFindAll:function(e,t,n){var r=this;return r._completedQueries[e][r.hashQuery(e,t,n)]?r.filter(e,t,n):void 0},create:function(e,t,n){var r=this;return n||(n={}),r._callSuper("create",e,t,n).then(function(t){return r._end(e,t,n)})},createMany:function(e,t,n){var r=this;return n||(n={}),r._callSuper("createMany",e,t,n).then(function(t){return r._end(e,t,n)})},defineMapper:function(e,t){var n=this,r=C.getSuper(n).prototype.defineMapper.call(n,e,t);n._pendingQueries[e]={},n._completedQueries[e]={},r.relationList||Object.defineProperty(r,"relationList",{value:[]});var i=n._collections[e]=new n.collectionClass(null,{_added:{},datastore:n,mapper:r}),o=r.schema||{},a=o.properties||{};C.forOwn(a,function(e,t){e.indexed&&i.createIndex(t)}),i.createIndex("addedTimestamps",["$"],{fieldGetter:function(e){return i._added[i.recordId(e)]}});var u=n.linkRelations;return u&&r.relationList.forEach(function(e){var t=e.relation,o=e.localField,a="links."+o,s=e.foreignKey,c=e.type,f=C.isUndefined(e.link)?u:e.link,l={index:s},d=void 0;c===L?(i.indexes[s]||i.createIndex(s),d={get:function(){var r=this;if(!r._get("$")||!f)return r._get(a);var i=e.getForeignKey(r),o=C.isUndefined(i)?void 0:n.getCollection(t).get(i);return r._set(a,o),o},set:function(t){var n=this;return n._set(a,t),e.setForeignKey(n,t),i.updateIndex(n,l),e.getLocalField(n)}}):c===M?!function(){var r=e.localKeys,o=e.foreignKeys;n._collections[t]&&s&&!n.getCollection(t).indexes[s]&&n.getCollection(t).createIndex(s),d={get:function(){var i=this;if(!i._get("$")||!f)return i._get(a);var u=e.getForeignKey(i),c=void 0,l=n.getCollection(t);if(s)c=l.getAll(u,{index:s});else if(r){var d=C.get(i,r)||[],p=C.isArray(d)?d:Object.keys(d);c=l.getAll.apply(l,p)}else if(o){var h={};C.set(h,"where."+o+".contains",u),c=l.filter(h)}return i._set(a,c),c},set:function(u){var c=this,f=i.recordId(c),d=n.getCollection(t);return c._set(a,u),s&&(e.setForeignKey(c,u),C.isArray(u)&&u.forEach(function(e){d.updateIndex(e,l)})),r?C.set(c,r,u.map(function(e){return d.recordId(e)})):o&&u.forEach(function(e){var t=C.get(e,o);t?-1===t.indexOf(f)&&t.push(f):C.set(e,o,[f])}),e.getLocalField(c)}}}():c===K&&(d={get:function(){var r=this;if(!r._get("$")||!f)return r._get(a);var i=e.getForeignKey(r),o=n.getCollection(t).getAll(i,{index:s}),u=o.length?o[0]:void 0;return r._set(a,u),u},set:function(r){var i=this;return i._set(a,r),e.setForeignKey(i,r),n.getCollection(t).updateIndex(r,l),e.getLocalField(i)}}),d&&(d.enumerable=C.isUndefined(e.enumerable)?!0:e.enumerable,e.get&&!function(){var t=d.get;d.get=function(){var n=this;return e.get(e,this,function(){for(var e=arguments.length,r=Array(e),i=0;e>i;i++)r[i]=arguments[i];return t.apply(n,r)})}}(),e.set&&!function(){var t=d.set;d.set=function(n){var r=this;return e.set(e,this,n,function(e){return t.call(r,void 0===e?n:e)})}}(),Object.defineProperty(r.recordClass.prototype,o,d))}),r},destroy:function(e,t,n){var r=this;return n||(n={}),r._callSuper("destroy",e,t,n).then(function(i){return n.raw?i.data=r.getCollection(e).remove(t,n):i=r.getCollection(e).remove(t,n),delete r._pendingQueries[e][t],delete r._completedQueries[e][t],i})},destroyAll:function(e,t,n){var r=this;return n||(n={}),r._callSuper("destroyAll",e,t,n).then(function(i){n.raw?i.data=r.getCollection(e).removeAll(t,n):i=r.getCollection(e).removeAll(t,n);var o=r.hashQuery(e,t,n);return delete r._pendingQueries[e][o],delete r._completedQueries[e][o],i})},eject:function(e,t){return this.remove(e,t)},ejectAll:function(e,t){return this.removeAll(e,t)},find:function(e,t,n){var r=this;n||(n={});var i=r._pendingQueries[e][t];if(C.fillIn(n,r.getMapper(e)),i)return i;var o=r.cachedFind(e,t,n),a=void 0;return a=n.force||!o?r._pendingQueries[e][t]=r._callSuper("find",e,t,n).then(function(i){return delete r._pendingQueries[e][t],r._end(e,i,n)},function(n){return delete r._pendingQueries[e][t],C.reject(n)}).then(function(n){return r._completedQueries[e][t]=(new Date).getTime(),n}):C.resolve(o)},findAll:function(e,t,n){var r=this;n||(n={});var i=r.hashQuery(e,t,n),o=r._pendingQueries[e][i];if(C.fillIn(n,r.getMapper(e)),o)return o;var a=r.cachedFindAll(e,t,n),u=void 0;return u=n.force||!a?r._pendingQueries[e][i]=r._callSuper("findAll",e,t,n).then(function(t){return delete r._pendingQueries[e][i],r._end(e,t,n)},function(t){return delete r._pendingQueries[e][i],C.reject(t)}).then(function(t){return r._completedQueries[e][i]=(new Date).getTime(),t}):C.resolve(a)},getCollection:function(e){var t=this._collections[e];if(!t)throw new ReferenceError(e+" is not a registered collection!");return t},hashQuery:function(e,t,n){return C.toJson(t)},inject:function(e,t){return this.add(e,t)},remove:function(e,t,n){var r=this,i=r.getCollection(e).remove(t,n);return i&&r.removeRelated(e,[i],n),i},removeAll:function(e,t,n){var r=this,i=r.getCollection(e).removeAll(t,n);return i.length&&r.removeRelated(e,i,n),i},removeRelated:function(e,t,n){var r=this;C.forEachRelation(r.getMapper(e),n,function(e,n){t.forEach(function(t){var i=void 0,o=void 0;if(!e.foreignKey||"hasOne"!==e.type&&"hasMany"!==e.type?"hasMany"===e.type&&e.localKeys?o={where:s.defineProperty({},e.getRelation().idAttribute,{in:C.get(t,e.localKeys)})}:"hasMany"===e.type&&e.foreignKeys?o={where:s.defineProperty({},e.foreignKeys,{contains:e.getForeignKey(t)})}:"belongsTo"===e.type&&(i=r.remove(e.relation,e.getForeignKey(t),n)):o=s.defineProperty({},e.foreignKey,e.getForeignKey(t)),o&&(i=r.removeAll(e.relation,o,n)),i){if(C.isArray(i)&&!i.length)return;"hasOne"===e.type&&(i=i[0]),e.setLocalField(t,i)}})})},update:function(e,t,n,r){var i=this;return r||(r={}),i._callSuper("update",e,t,n,r).then(function(t){return i._end(e,t,r)})},updateAll:function(e,t,n,r){var i=this;return r||(r={}),i._callSuper("updateAll",e,n,t,r).then(function(t){return i._end(e,t,r)})},updateMany:function(e,t,n){var r=this;return n||(n={}),r._callSuper("updateMany",e,t,n).then(function(t){return r._end(e,t,n)})}},Ce=["add","between","createIndex","filter","get","getAll","query","toJson"];Ce.forEach(function(e){xe[e]=function(t){for(var n,r=arguments.length,i=Array(r>1?r-1:0),o=1;r>o;o++)i[o-1]=arguments[o];return(n=this.getCollection(t))[e].apply(n,i)}});var Ee=Ae.extend(xe),Re={alpha:"21",beta:"false",full:"3.0.0-alpha.21",major:parseInt("3",10),minor:parseInt("0",10),patch:parseInt("0",10)};e.version=Re,e.Collection=P,e.Component=t,e.Container=Ae,e.DataStore=Ee,e.LinkedCollection=_e,e.Mapper=me,e.Query=S,e.Record=q,e.Schema=he,e.utils=C,e.belongsToType=L,e.hasManyType=M,e.hasOneType=K,e.belongsTo=U,e.hasMany=T,e.hasOne=D}); | ||
//# sourceMappingURL=js-data.min.map |
926
js-data.d.ts
@@ -1,595 +0,365 @@ | ||
// Type definitions for JSData v3 | ||
// Project: https://github.com/js-data/js-data | ||
// Definitions by: Robert Porter <robertp.dev@gmail.com> | ||
declare module JSData { | ||
type ID = number | string; | ||
class Collection<R> { | ||
new(data?: R[], idAttribute?: string): this; | ||
/** | ||
* Create a new secondary index on the contents of the collection. | ||
*/ | ||
createIndex(name: string, keyList: string[]): Collection<R>; | ||
/** | ||
* Create a new query to be executed against the contents of the collection. | ||
* The result will be all or a subset of the contents of the collection. | ||
*/ | ||
query(): Query<R>; | ||
/** | ||
* Find all entities between two boundaries. | ||
*/ | ||
between(leftKeys: string[], rightKeys: string[], options: QueryOptions): R[]; | ||
/** | ||
* Find the entity or entities that match the provided key. | ||
*/ | ||
get(keyList: string[], options: QueryOptionsBase): R[]; | ||
/** | ||
* Find the entity or entities that match the provided keyLists. | ||
*/ | ||
getAll(keyList: string[], options: QueryOptionsBase): R[]; | ||
/** | ||
* Find the entity or entities that match the provided query or pass the | ||
* provided filter function. | ||
*/ | ||
filter(query: Object | Function): R[]; | ||
/** | ||
* Skip a number of results. | ||
*/ | ||
skip(number: Number): R[]; | ||
/** | ||
* Limit the result. | ||
*/ | ||
limit(number: Number): R[]; | ||
/** | ||
* Iterate over all entities. | ||
*/ | ||
forEach(fn: Function, thisArg?); | ||
/** | ||
* Reduce the data in the collection to a single value and return the result. | ||
*/ | ||
reduce<T>(callback: Function, initialValue: T): T; | ||
/** | ||
* Apply a mapping function to all entities. | ||
*/ | ||
map<T>(fn: (each: R) => T, thisArg?): T[]; | ||
/** | ||
* Instead a record into this collection, updating all indexes with the new | ||
* record. | ||
*/ | ||
insert(record: R); | ||
/** | ||
* Update the given record's position in all indexes of this collection. See | ||
* updateRecord() to update a record's in only one of the indexes. | ||
*/ | ||
update(record: R); | ||
/** | ||
* Remove the given record from all indexes in this collection. | ||
*/ | ||
remove(record: R); | ||
/** | ||
* Update a record's position in a single index of this collection. See | ||
* update() to update a record's position in all indexes at once. | ||
*/ | ||
updateRecord(record: R, options: QueryOptionsBase); | ||
export const version: { | ||
alpha: string|boolean | ||
beta: string|boolean | ||
full: string | ||
major: number | ||
minor: number | ||
patch: number | ||
} | ||
/** | ||
* A class used by the Collection class to build queries to be executed | ||
* against the collection's data. An instance of `Query` is returned by | ||
* Model.query() and Collection.query(). | ||
*/ | ||
class Query<R> { | ||
new(collection: Collection<R>): this; | ||
/** | ||
* Return the current data result of this query. | ||
*/ | ||
getData(): R[]; | ||
/** | ||
* Find all entities between two boundaries. | ||
*/ | ||
between(leftKeys: string[], rightKeys: string[], options: QueryOptions): Query<R>; | ||
/** | ||
* Find the entity or entities that match the provided key. | ||
*/ | ||
get(keyList: string[], options: QueryOptionsBase): Query<R>; | ||
/** | ||
* Find the entity or entities that match the provided keyLists. | ||
*/ | ||
getAll(keyList: string[], options: QueryOptionsBase): Query<R>; | ||
/** | ||
* Find the entity or entities that match the provided query or pass the | ||
* provided filter function. | ||
*/ | ||
filter(query: Object | Function, thisArg?): Query<R>; | ||
/** | ||
* Skip a number of results. | ||
*/ | ||
skip(number: Number): Query<R>; | ||
/** | ||
* Limit the result. | ||
*/ | ||
limit(number: Number): Query<R>; | ||
/** | ||
* Iterate over all entities. | ||
*/ | ||
forEach(fn: Function, thisArg?): Query<R>; | ||
/** | ||
* Apply a mapping function to the result data. | ||
*/ | ||
map(fn: Function, thisArg?): Query<R>; | ||
/** | ||
* Complete the execution of the query and return the resulting data. | ||
*/ | ||
run(): R[]; | ||
export interface Diff { | ||
added: any | ||
changed: any | ||
removed: any | ||
} | ||
interface QueryOptionsBase { | ||
/** | ||
* Name of the secondary index to use in the query. If no index is | ||
* specified, the main index is used. | ||
*/ | ||
index?: string; | ||
export const utils: { | ||
Promise: PromiseConstructor | ||
_(dest: any, src: any): void | ||
_forRelation(opts: any, def: any, fn: Function, ctx: Object): void | ||
_getIndex(list: any[], relation: any): number | ||
addHiddenPropsToTarget(target: Object, props: Object): void | ||
areDifferent(a: Object, b: Object, opts: any): boolean | ||
classCallCheck(instance: Object, ctor: Function): void | ||
copy(from: any, to?: any, stackFrom?: any, stackTo?: any, blacklist?: any[], plain?: boolean): any | ||
deepFillIn(dest: Object, source: Object): Object | ||
deepMixIn(dest: Object, source: Object): Object | ||
diffObjects(a: any, b: any, opts: any): Diff | ||
equal(a: any, b: any): boolean | ||
eventify(target: any, getter: Function, setter: Function, enumerable?: boolean): void | ||
extend(props?: any, classProps?: any): Function | ||
fillIn(dest: Object, src: Object): void | ||
forEachRelation(mapper: any, opts: any, fn: Function, ctx?: any): void | ||
forOwn(obj: any, fn: Function, thisArg?: Object): void | ||
fromJson(json: any): any | ||
'get'(object: Object, prop: string): any | ||
getSuper(instance: any, isCtor?: boolean): Function | ||
intersection(array1: any[], array2: any[]): any[] | ||
isArray(arg: any): boolean | ||
isBlacklisted(prop: string, bl: any[]): boolean | ||
isBoolean(value: any): boolean | ||
isBrowser: boolean | ||
isDate(value: any): boolean | ||
isFunction(value: any): boolean | ||
isInteger(value: any): boolean | ||
isNull(value: any): boolean | ||
isNumber(value: any): boolean | ||
isObject(value: any): boolean | ||
isRegExp(value: any): boolean | ||
isSorN(value: any): boolean | ||
isString(value: any): boolean | ||
isUndefined(value: any): boolean | ||
logify(target: any, defaultNamespace: any): void | ||
omit(props: Object, keys: string[]): Object | ||
plainCopy(from: any): any | ||
possibleConstructorReturn(self: Object, call: Object | Function): Object | ||
reject(value: any): Promise<any> | ||
resolve(value: any): Promise<any> | ||
set(object: Object, path: string, value?: any): void | ||
strictEqual(a: any, b: any): boolean | ||
toJson(value: any, replacer?: Function, space?: number): string | ||
unset(object: Object, path: string): void | ||
} | ||
interface QueryOptions extends QueryOptionsBase { | ||
/** | ||
* Whether to include entities on the left boundary. | ||
*/ | ||
leftInclusive?: boolean; | ||
/** | ||
* Whether to include entities on the left boundary. | ||
*/ | ||
rightInclusive?: boolean; | ||
/** | ||
* Limit the result to a certain number. | ||
*/ | ||
limit?: boolean; | ||
/** | ||
* The number of resulting entities to skip. | ||
*/ | ||
offset?: boolean; | ||
export class Component { | ||
static extend(instanceProps?: any, classProps?: any): any | ||
_listeners: Object | ||
dbg(...args: any[]): void | ||
emit(key?: string, ...args: any[]): void | ||
log(level: string, ...args: any[]): void | ||
off(key?: string, handler?: Function): void | ||
on(key?: string, handler?: Function): void | ||
} | ||
class DS { | ||
new(): this; | ||
clear(): Model<any>[]; | ||
defineModel<R>(options: ModelOptions): Model<R>; | ||
export class Record extends Component { | ||
static mapper: Mapper | ||
constructor(props?: any, opts?: any) | ||
_set(prop: any, value?: any): void | ||
_get(prop: string): any | ||
_unset(prop: any): void | ||
_mapper(): Mapper | ||
afterLoadRelations(): void | ||
afterSave(): void | ||
beforeSave(): void | ||
beforeLoadRelations(): void | ||
changes(opts?: any): Diff | ||
commit(): this | ||
create(opts?: any): Promise<Record> | ||
destroy(opts?: any): Promise<any> | ||
loadRelations(relations: any, opts?: any): Promise<this> | ||
'get'(key: string): any | ||
hasChanges(opts?: any): boolean | ||
hashCode(): string|number | ||
previous(key: any): any | ||
revert(opts?: any): this | ||
save(opts?: any): Promise<this> | ||
'set'(key: string, value?: any, opts?: any): void | ||
toJSON(opts?: any): any | ||
unset(key: string, opts?: any): void | ||
} | ||
interface ModelOptions { | ||
[key: string]: any; | ||
methods?: { [name: string]: Function }; | ||
noValidate?: boolean; | ||
export class Mapper extends Component { | ||
_adapters: Object | ||
applySchema: boolean | ||
name: string | ||
defaultAdapter: string | ||
debug: boolean | ||
idAttribute: string | ||
lifecycleMethods: any | ||
notify: boolean | ||
raw: boolean | ||
recordClass: any | ||
relationList: any[] | ||
relationFields: string[] | ||
schema: Schema | ||
constructor(opts?: any) | ||
afterCount(query: any, opts: any, result: any): any | ||
afterCreate(props: any, opts: any, result: any): any | ||
afterCreateMany(records: any[], opts: any, result: any): any | ||
afterDestroy(id: string|number, opts: any, result: any): any | ||
afterDestroyAll(query: any, opts: any, result: any): any | ||
afterFind(id: string|number, opts: any, result: any): any | ||
afterFindAll(query: any, opts: any, result: any): any | ||
afterSum(field: string, query:any, opts: any, result: any): any | ||
afterUpdate(id: string|number, opts: any, result: any): any | ||
afterUpdateAll(props: any, query: any, opts: any, result: any): any | ||
afterUpdateMany(records: any[], opts: any, result: any): any | ||
beforeCreate(props: any, opts: any): any | ||
beforeCreateMany(records: any[], opts: any): any | ||
beforeCount(query: any, opts: any): any | ||
beforeDestroy(id: string|number, opts: any): any | ||
beforeDestroyAll(query: any, opts: any): any | ||
beforeFind(id: string|number, opts: any): any | ||
beforeFindAll(query: any, opts: any): any | ||
beforeSum(field: string, query: any, opts: any): any | ||
beforeUpdate(id: string|number, opts: any): any | ||
beforeUpdateAll(query: any, opts: any): any | ||
beforeUpdateMany(records: any[], opts: any): any | ||
_end(result: any, opts: any, skip?: boolean): any | ||
belongsTo(relatedMapper: any, opts: any): void | ||
count(query: any, opts?: any): Promise<any> | ||
create(props: any, opts?: any): Promise<any> | ||
createInstance(props: any, opts?: any): any | ||
createMany(records: any[], opts?: any): Promise<any> | ||
createRecord(props?: any, opts?: any): any | ||
crud(method: any, ...args: any[]): Promise<any> | ||
destroy(id: string|number, opts?: any): Promise<any> | ||
destroyAll(query: any, opts?: any): Promise<any> | ||
find(id: string|number, opts?: any): Promise<any> | ||
findAll(query: any, opts?: any): Promise<any> | ||
getAdapter(name: any): any | ||
getAdapterName(opts?: any): any | ||
getAdapters(): any | ||
getSchema(): Schema | ||
hasMany(relatedMapper: any, opts: any): void | ||
hasOne(relatedMapper: any, opts: any): void | ||
is(record: any): boolean | ||
registerAdapter(name: string, adapter: any, opts?: any): void | ||
sum(field: string, query: any, opts?: any): Promise<any> | ||
toJSON(record: any, opts?: any): {} | ||
update(id: string|number, props: any, opts?: any): Promise<any> | ||
updateAll(props: any, query: any, opts?: any): Promise<any> | ||
updateMany(records: any[], opts?: any): Promise<any> | ||
} | ||
function belongsTo(model, opts?: RelationOptions): ClassDecorator; | ||
function configure(opts?: Object, overwrite?: boolean): ClassDecorator; | ||
function hasMany(model, opts?: RelationOptions): ClassDecorator; | ||
function hasOne(model, opts?: RelationOptions): ClassDecorator; | ||
function setSchema(opts?: Object): ClassDecorator; | ||
interface RelationOptions { | ||
localField?: string; | ||
foreignKey?: string; | ||
foreignKeys?: string[]; | ||
localKey?: string; | ||
localKeys?: string[]; | ||
get: (model, relation, instance?, originalGetter?: () => any) => any; | ||
set: (model, relation, instance, children?, originalSetter?: (children) => void) => any; | ||
export class Collection extends Component { | ||
idAttribute: string | ||
onConflict: string | ||
recordOpts: any | ||
index: Index | ||
indexes: any | ||
mapper: Mapper | ||
constructor(records?: any[], opts?: any) | ||
_onRecordEvent(...args: any[]): void | ||
add(records: any, opts?: any): any | ||
afterAdd(...args: any[]): void | ||
afterRemove(...args: any[]): void | ||
afterRemoveAll(...args: any[]): void | ||
beforeAdd(...args: any[]): void | ||
beforeRemove(...args: any[]): void | ||
beforeRemoveAll(...args: any[]): void | ||
between(leftKeys: any, rightKeys: any, opts?: any): any[] | ||
createIndex(name: any, fieldList: any, opts?: any): this | ||
filter(query: any, thisArg?: any): any[] | ||
forEach(cb: Function, thisArg?: any): void | ||
get(id: string|number): any | ||
getAll(...args: any[]): any[] | ||
getIndex(name: string): any | ||
limit(num: number): any[] | ||
map(cb: any, thisArg: any): any[] | ||
mapCall(funcName: string, ...args: any[]): any[] | ||
recordId(record?: any): any | ||
query(): Query | ||
reduce(cb: Function, initialValue: any): any | ||
remove(id: string|number, opts?: any): any | ||
removeAll(query: any, opts?: any): void | any[] | ||
skip(num: number): any[] | ||
toJSON(opts?: any): any[] | ||
updateIndex(record: any, opts?: any): void | ||
updateIndexes(record: any): void | ||
} | ||
/** | ||
* Add the provided adapter to the target's "adapters" property, registering it | ||
* with the specified. | ||
*/ | ||
function registerAdapter(name: string, adapter: Adapter, opts?: Object): ClassDecorator; | ||
/** | ||
* js-data's Model class. | ||
*/ | ||
class Model<R> { | ||
schema(key?: string): Object; | ||
validate(obj?: Object): string[] | void; | ||
create(opts?: Object): Promise<Model<R>>; | ||
save(opts?: Object): Promise<Model<R>>; | ||
destroy(opts?: Object): Promise<Model<R>>; | ||
/** | ||
* Return the value at the given path for this instance. | ||
*/ | ||
get(key: string): any; | ||
/** | ||
* Set the value for a given key, or the values for the given keys if "key" is | ||
* an object. | ||
*/ | ||
set(key: string, value): any; | ||
/** | ||
* Return a plain object representation of this instance. | ||
*/ | ||
toJSON(opts?: Object): string; | ||
/** | ||
* Extend this Model and return a new child Model. Static properties on this | ||
* Model will be shallow copied to the child Model. The child Model's | ||
* prototype will point to the parent Model. | ||
*/ | ||
static extend<R>(instanceProps?: Object, staticProps?: ModelOptions): ModelConstructor<R>; | ||
export class LinkedCollection extends Collection { | ||
_added: Object | ||
datastore: DataStore | ||
} | ||
interface ModelOptions { | ||
autoEject?: boolean; | ||
autoInject?: boolean; | ||
bypassCache?: boolean; | ||
csp?: boolean; | ||
defaultAdapter?: string; | ||
debug?: boolean; | ||
eagerEject?: boolean; | ||
endpoint?: string; | ||
idAttribute?: string; | ||
linkRelations?: boolean; | ||
name?: string; | ||
notify?: boolean; | ||
onConflict?: string; | ||
relationsEnumerable?: boolean; | ||
raw?: boolean; | ||
upsert?: boolean; | ||
export class Container extends Component { | ||
mapperDefaults: any | ||
mapperClass: typeof Mapper | ||
_adapters: Object | ||
_mappers: Object | ||
constructor(opts?: any) | ||
defineMapper(name: string, opts?: any): Mapper | ||
defineResource(name: string, opts?: any): Mapper | ||
getAdapter(name: any): any | ||
getAdapterName(opts?: any): string | ||
getAdapters(): any | ||
getMapper(name: string): Mapper | ||
registerAdapter(name: string, adapter: any, opts?: any): void | ||
} | ||
interface ModelConstructor<R> extends ModelOptions { | ||
new (properties: R, options: ModelOptions): Model<R>; | ||
/** | ||
* Create a new secondary index in the Collection instance of this Model. | ||
*/ | ||
createIndex(name: string, keyList: string[]); | ||
/** | ||
* Create a new instance of this Model from the provided properties. | ||
*/ | ||
createInstance(props: Object): Model<R>; | ||
/** | ||
* Check whether "instance" is actually an instance of this Model. | ||
*/ | ||
is(instance): boolean; | ||
/** | ||
* Insert the provided item or items into the Collection instance of this | ||
* Model. | ||
* | ||
* If an item is already in the collection then the provided item will either | ||
* merge with or replace the existing item based on the value of the | ||
* "onConflict" option. | ||
* | ||
* The collection's secondary indexes will be updated as each item is visited. | ||
*/ | ||
inject(items: Model<R> | Object, options?: Object): Model<R>; | ||
/** | ||
* Insert the provided item or items into the Collection instance of this | ||
* Model. | ||
* | ||
* If an item is already in the collection then the provided item will either | ||
* merge with or replace the existing item based on the value of the | ||
* "onConflict" option. | ||
* | ||
* The collection's secondary indexes will be updated as each item is visited. | ||
*/ | ||
inject(items: Model<R>[] | Object[], options?: Object): Model<R>[]; | ||
/** | ||
* Remove the instance with the given primary key from the Collection instance | ||
* of this Model. | ||
*/ | ||
eject(id: ID): Model<R> | void; | ||
/** | ||
* Remove the instances selected by "query" from the Collection instance of | ||
* this Model. | ||
*/ | ||
ejectAll(query: Object): Model<R>[]; | ||
/** | ||
* Return the instance in the Collection instance of this Model that has | ||
* the given primary key, if such an instance can be found. | ||
*/ | ||
get(id: ID): Model<R> | void; | ||
/** | ||
* Proxy for Collection.between() | ||
*/ | ||
getAll(keyList: string[], options: QueryOptionsBase): R[]; | ||
/** | ||
* Proxy for Collection.filter() | ||
*/ | ||
filter(query: Object | Function): R[]; | ||
/** | ||
* Proxy for `Collection.query()`. | ||
*/ | ||
query(): Query<R>; | ||
/** | ||
* Return the registered adapter with the given name or the default adapter if | ||
* no name is provided. | ||
*/ | ||
getAdapter(name?: string): Adapter; | ||
/** | ||
* Return the name of a registered adapter based on the given name or options, | ||
* or the name of the default adapter if no name provided | ||
*/ | ||
getAdapterName(options: Object): string; | ||
/** | ||
* Lifecycle hook. Called by `Model.create` after `Model.create` checks | ||
* whether it can do an upsert and before `Model.create` calls the `create` | ||
* method of an adapter. | ||
* | ||
* `Model.beforeCreate` will receive the same arguments that are passed to | ||
* `Model.create`. If `Model.beforeCreate` returns a promise, `Model.create` | ||
* will wait for the promise to resolve before continuing. If the promise | ||
* rejects, then the promise returned by `Model.create` will reject. If | ||
* `Model.beforeCreate` does not return a promise, `Model.create` will resume | ||
* execution immediately. | ||
*/ | ||
beforeCreate(props?: Object, opts?: Object): Promise<void> | void; | ||
/** | ||
* The "C" in "CRUD", `Model.create` creates a single entity using the | ||
* `create` method of an adapter. If the `props` passed to `Model.create` | ||
* contain a primary key as configured by `Model.idAttribute` and | ||
* `opts.upsert` is `true` of `Model.upsert` is `true` and `opts.upsert` is | ||
* not `false`, then `Model.update` will be called instead. | ||
* | ||
* 1. `Model.beforeCreate` is called and passed the same arguments passed to | ||
* `Model.create`. | ||
* 1. `props` and `opts` are passed to the `create` method of the adapter | ||
* specified by `opts.adapter` or `Model.defaultAdapter`. | ||
* 1. `Model.afterCreate` is called with the `data` argument returned by the | ||
* adapter's `create` method and the `opts` argument passed to `Model.create`. | ||
* 1. If `opts.raw` is `true` or `Model.raw` is `true` and `opts.raw` is not | ||
* `false`, then a result object is returned that contained the created entity | ||
* and some metadata about the operation and its result. Otherwise, the | ||
* promise returned by `Model.create` resolves with the created entity. | ||
*/ | ||
create(props?: Object, opts?: Object): Promise<R>; | ||
/** | ||
* Lifecycle hook. Called by `Model.create` after `Model.create` call the | ||
* `create` method of an adapter. | ||
* | ||
* `Model.afterCreate` will receive the `data` argument returned by the | ||
* adapter's `create` method and the `opts` argument passed to `Model.create`. | ||
* If `Model.afterCreate` returns a promise, `Model.create` will wait for the | ||
* promise to resolve before continuing. If the promise rejects, then the | ||
* promise returned by `Model.create` will reject. If `Model.afterCreate` does | ||
* not return a promise, `Model.create` will resume execution immediately. | ||
*/ | ||
afterCreate(data?: Object, opts?: Object): Promise<void> | void; | ||
beforeCreateMany(items?: Object[], opts?: Object): Promise<void> | void; | ||
createMany(items?: Object[], opts?: Object): Promise<R[]>; | ||
afterCreateMany(data?: Object[], opts?: Object): Promise<void> | void; | ||
beforeFind(id?: ID, opts?: Object): Promise<void> | void; | ||
find(id: ID, opts?: Object): Promise<R>; | ||
afterFind(data?: Object, opts?: Object): Promise<void> | void; | ||
beforeFindAll(query?: Object, opts?: Object): Promise<void> | void; | ||
findAll(query?: Object, opts?: Object): Promise<R[]>; | ||
afterFindAll(query?: Object, opts?: Object): Promise<void> | void; | ||
beforeUpdate(id?: ID, props?: Object, opts?: Object): Promise<void> | void; | ||
update(id: ID, props?: Object, opts?: Object): Promise<R>; | ||
afterUpdate(id?: ID, props?: Object, opts?: Object): Promise<void> | void; | ||
beforeUpdateMany(items?: Object[], opts?: Object): Promise<void> | void; | ||
updateMany(items?: Object[], opts?: Object): Promise<R[]>; | ||
afterUpdateMany(data?: Object[], opts?: Object): Promise<void> | void; | ||
beforeUpdateAll(query?: Object, props?: Object, opts?: Object): Promise<void> | void; | ||
updateAll(query?: Object, props?: Object, opts?: Object): Promise<R[]>; | ||
afterUpdateAll(query?: Object, data?: Object[], opts?: Object): Promise<void> | void; | ||
beforeDestroy(id?: ID, opts?: Object): Promise<void> | void; | ||
destroy(id: ID, opts?: Object): Promise<R>; | ||
afterDestroy(data?: Object, opts?: Object): Promise<void> | void; | ||
beforeDestroyAll(query?: Object, opts?: Object): Promise<void> | void; | ||
destroyAll(query?: Object, opts?: Object): Promise<R[]>; | ||
afterDestroyAll(query?: Object, opts?: Object): Promise<void> | void; | ||
belongsTo(model: Model<any>, opts?: RelationOptions): any; | ||
hasMany(model: Model<any>, opts?: RelationOptions): any; | ||
hasOne(model: Model<any>, opts?: RelationOptions): any; | ||
/** | ||
* Invoke the `setSchema` decorator on this Model. | ||
*/ | ||
setSchema(opts?: Object): any; | ||
/** | ||
* Invoke the `configure` decorator on this Model. | ||
*/ | ||
configure(opts?: Object): any; | ||
/** | ||
* Invoke the `registerAdapter` decorator on this Model. | ||
*/ | ||
registerAdapter(name: string, adapter: Adapter, opts?: Object): ModelConstructor<R>; | ||
/** | ||
* Extend this Model and return a new child Model. Static properties on this | ||
* Model will be shallow copied to the child Model. The child Model's | ||
* prototype will point to the parent Model. | ||
*/ | ||
extend<R>(instanceProps?: Object, staticProps?: ModelOptions): ModelConstructor<R>; | ||
export class DataStore extends Container { | ||
collectionClass: typeof LinkedCollection | ||
_collections: Object | ||
_pendingQueries: Object | ||
_completedQueries: Object | ||
linkRelations: boolean | ||
constructor(opts?: any) | ||
add(mapperName: string, records: any[]|any, opts?: any): any[]|any | ||
between(mapperName: string, leftKeys: any, rightKeys: any, opts?: any): any[] | ||
createIndex(mapperName: string, name: any, fieldList: any, opts?: any): LinkedCollection | ||
filter(mapperName: string, query: any, thisArg?: any): any[] | ||
get(mapperName: string, id: string|number): any | ||
getAll(mapperName: string, ...args: any[]): any[] | ||
query(mapperName: string): Query | ||
remove(mapperName: string, id: string|number, opts?: any): any | ||
removeAll(mapperName: string, query?: any, opts?: any): void | any[] | ||
toJson(mapperName: string, opts?: any): any[] | ||
_callSuper(method: string, ...args: any[]): any | ||
_end(mapperName: string, data: any, opts?: any): any | ||
create(mapperName: string, record: any, opts?: any): Promise<any> | ||
createMany(mapperName: string, records: any, opts?: any): Promise<any[]|any> | ||
defineMapper(mapperName: string, opts?: any): Mapper | ||
destroy(mapperName: string, id: any, opts?: any): Promise<any> | ||
destroyAll(mapperName: string, query?: any, opts?: any): Promise<any> | ||
find(mapperName: string, id: any, opts?: any): Promise<any> | ||
findAll(mapperName: string, query?: any, opts?: any): Promise<any> | ||
cachedFind(mapperName: string, id: any, opts?: any): any | ||
cachedFindAll(mapperName: string, query: any, opts?: any): any | ||
hashQuery(mapperName: string, query: any, opts?: any): string | ||
getCollection(mapperName: string): LinkedCollection | ||
update(mapperName: string, id: any, record: any, opts?: any): Promise<any> | ||
updateAll(mapperName: string, props: any, query?: any, opts?: any): Promise<any[]|any> | ||
updateMany(mapperName: string, records: any, opts?: any): Promise<any[]|any> | ||
} | ||
interface Adapter { } | ||
module rules { | ||
function type(predicate: string[], value): string | void; | ||
function anyOf(schemas: Array<Object>, value): string[] | void; | ||
function oneOf(schemas: Array<Object>, value): string[] | void; | ||
export class Query extends Component { | ||
static ops: { | ||
'=='(value: any, predicate: any): boolean | ||
'==='(value: any, predicate: any): boolean | ||
'!='(value: any, predicate: any): boolean | ||
'!=='(value: any, predicate: any): boolean | ||
'>'(value: any, predicate: any): boolean | ||
'>='(value: any, predicate: any): boolean | ||
'<'(value: any, predicate: any): boolean | ||
'<='(value: any, predicate: any): boolean | ||
'isectEmpty'(value: any, predicate: any): boolean | ||
'isectNotEmpty'(value: any, predicate: any): number | ||
'in'(value: any, predicate: any): boolean | ||
'notIn'(value: any, predicate: any): boolean | ||
'contains'(value: any, predicate: any): boolean | ||
'notContains'(value: any, predicate: any): boolean | ||
} | ||
collection: Collection|LinkedCollection | ||
data: any[] | ||
constructor(collection?: Collection) | ||
compare(orderBy: any, index: any, a: any, b: any): any | ||
evaluate(value: any, op: string, predicate: any): boolean | ||
like(pattern: any, flags: any): RegExp | ||
getData(): any[] | ||
between(leftKeys: any, rightKeys: any, opts?: any): this | ||
get(keyList?: any[], opts?: any): this | ||
getAll(...args: any[]): this | ||
filter(query: any, thisArg?: any): this | ||
skip(num: number): this | ||
limit(num: number): this | ||
forEach(forEachFn: Function, thisArg?: any): this | ||
map(mapFn: Function, thisArg?: any): this | ||
mapCall(funcName: string, ...args: any[]): this | ||
run(): any[] | ||
} | ||
function validate(schema: Object, value): string[] | void; | ||
module utils { | ||
/** | ||
* Return whether the provided value is an array. | ||
*/ | ||
function isArray(value): boolean; | ||
/** | ||
* Return whether the provided value is an object type. | ||
*/ | ||
function isObject(value): boolean; | ||
/** | ||
* Return whether the provided value is a regular expression type. | ||
*/ | ||
function isRegExp(value): boolean; | ||
/** | ||
* Return whether the provided value is a string type. | ||
*/ | ||
function isString(value): boolean; | ||
/** | ||
* Return whether the provided value is a date type. | ||
*/ | ||
function isDate(value): boolean; | ||
/** | ||
* Return whether the provided value is a number type. | ||
*/ | ||
function isNumber(value): boolean; | ||
/** | ||
* Return whether the provided value is a boolean type. | ||
*/ | ||
function isBoolean(value): boolean; | ||
/** | ||
* Return whether the provided value is a function. | ||
*/ | ||
function isFunction(value): boolean; | ||
/** | ||
* Return whether the provided value is a string or a number. | ||
*/ | ||
function isSorN(value): boolean; | ||
/** | ||
* Get the value at the provided key or path. | ||
*/ | ||
function get(object: Object, prop: string): any; | ||
/** | ||
* Unset the value at the provided key or path. | ||
*/ | ||
function unset(object: Object, prop: string): any; | ||
/** | ||
* Set the value at the provided key or path. | ||
*/ | ||
function set(object: Object, prop: string, value): any; | ||
/** | ||
* Iterate over an object's own enumerable properties. | ||
*/ | ||
function forOwn(object: Object, fn: Function, thisArg?); | ||
/** | ||
* Recursively shallow copy own enumberable properties from `src` to `dest`. | ||
*/ | ||
function deepMixIn(dest: Object, src: Object): Object; | ||
/** | ||
* Proxy for `Promise.resolve`. | ||
*/ | ||
function resolve(value): Promise<any>; | ||
/** | ||
* Proxy for `Promise.reject`. | ||
*/ | ||
function reject(value): Promise<any>; | ||
/** | ||
* Shallow copy own enumerable non-function properties from `src` to `dest`. | ||
*/ | ||
function _(src: Object, dest: Object); | ||
/** | ||
* Return the intersection of two arrays. | ||
*/ | ||
function intersection(first: Array<any>, second: Array<any>): Array<any>; | ||
/** | ||
* Shallow copy own enumerable properties from `src` to `dest` that are on `src` | ||
* but are missing from `dest. | ||
*/ | ||
function fillIn(dest: Object, src: Object); | ||
/** | ||
* Return whether `prop` is matched by any string or regular expression in `blacklist`. | ||
*/ | ||
function isBlacklisted(prop, blacklist: Array<any>): boolean; | ||
/** | ||
* Proxy for `JSON.parse`. | ||
*/ | ||
function fromJson(json: string | Object): Object; | ||
/** | ||
* Proxy for `JSON.stringify`. | ||
*/ | ||
function toJson(value: Object, replacer?: Function | Array<string | number>, space?: string | number): string; | ||
/** | ||
* Deep copy a value. | ||
*/ | ||
function copy(from, to?, stackFrom?, stackTo?, blacklist?): any; | ||
/** | ||
* Convert a string to pascalcase. | ||
*/ | ||
function pascalCase(str: string): string; | ||
/** | ||
* Convert a string to camelcase. | ||
*/ | ||
function camelCase(str: string): string; | ||
export interface SchemaValidationError { | ||
expected: any | ||
actual: string | ||
path: string | ||
} | ||
export class Schema extends Component { | ||
static types: { | ||
array(value: any): boolean | ||
boolean(value: any): boolean | ||
integer(value: any): boolean | ||
'null'(value: any): boolean | ||
number(value: any): boolean | ||
object(value: any): boolean | ||
string(value: any): boolean | ||
} | ||
static typeGroupValidators: { | ||
array(value: any, schema: any, opts: any): SchemaValidationError[] | ||
integer(value: any, schema: any, opts: any): SchemaValidationError[] | ||
number(value: any, schema: any, opts: any): SchemaValidationError[] | ||
numeric(value: any, schema: any, opts: any): SchemaValidationError[] | ||
object(value: any, schema: any, opts: any): SchemaValidationError[] | ||
string(value: any, schema: any, opts: any): SchemaValidationError[] | ||
} | ||
static validationKeywords: { | ||
allOf(value: any, schema: any, opts: any): SchemaValidationError[] | ||
anyOf(value: any, schema: any, opts: any): SchemaValidationError[] | ||
dependencies(value: any, schema: any, opts: any): void | ||
enum(value: any, schema: any, opts: any): SchemaValidationError | ||
items(value: any, schema: any, opts: any): SchemaValidationError[] | ||
maximum(value: any, schema: any, opts: any): SchemaValidationError | ||
maxItems(value: any, schema: any, opts: any): SchemaValidationError | ||
maxLength(value: any, schema: any, opts: any): SchemaValidationError | ||
maxProperties(value: any, schema: any, opts: any): SchemaValidationError | ||
minimum(value: any, schema: any, opts: any): SchemaValidationError | ||
minItems(value: any, schema: any, opts: any): SchemaValidationError | ||
minLength(value: any, schema: any, opts: any): SchemaValidationError | ||
minProperties(value: any, schema: any, opts: any): SchemaValidationError | ||
multipleOf(value: any, schema: any, opts: any): SchemaValidationError | ||
not(value: any, schema: any, opts: any): SchemaValidationError | ||
oneOf(value: any, schema: any, opts: any): SchemaValidationError[] | ||
pattern(value: any, schema: any, opts: any): SchemaValidationError | ||
properties(value: any, schema: any, opts: any): SchemaValidationError[] | ||
required(value: any, schema: any, opts: any): SchemaValidationError[] | ||
type(value: any, schema: any, opts: any): SchemaValidationError | ||
uniqueItems(value: any, schema: any, opts: any): SchemaValidationError | ||
} | ||
static validate(value: any, schema: any, opts: any): SchemaValidationError[] | ||
properties: any | ||
constructor(definition: any) | ||
apply(target: any, opts?: any): void | ||
validate(value: any, opts?: any): SchemaValidationError[] | ||
} | ||
export class Index { | ||
fieldList: string[] | ||
fieldGetter: Function | ||
hashCode: Function | ||
isIndex: boolean | ||
keys: any[] | ||
values: any[] | ||
constructor(fieldList: string[], opts?: any) | ||
'set'(keyList: any[], value: any): void | ||
'get'(keyList: any[]): any | ||
getAll(): any[] | ||
visitAll(cb: Function, thisArg?: any): void | ||
between(leftKeys: any, rightKeys: any, opts?: any): any[] | ||
_between(leftKeys: any, rightKeys: any, opts: any): any[] | ||
peek(): any | ||
clear(): void | ||
insertRecord(data: any): void | ||
removeRecord(data: any): any | ||
updateRecord(data: any): void | ||
} | ||
export const belongsToType: string | ||
export const hasManyType: string | ||
export const hasOneType: string | ||
export const belongsTo: (related: any, opts: any) => (target: any) => void | ||
export const hasMany: (related: any, opts: any) => (target: any) => void | ||
export const hasOne: (related: any, opts: any) => (target: any) => void | ||
} | ||
declare module 'js-data' { | ||
export = JSData; | ||
export = JSData | ||
} |
{ | ||
"name": "js-data", | ||
"description": "Robust, framework-agnostic in-memory data store.", | ||
"version": "3.0.0-alpha.20", | ||
"version": "3.0.0-alpha.21", | ||
"homepage": "http://www.js-data.io", | ||
@@ -13,2 +13,3 @@ "repository": { | ||
"main": "./dist/js-data.js", | ||
"jsnext:main": "dist/js-data.es2015.js", | ||
"keywords": [ | ||
@@ -40,7 +41,7 @@ "orm", | ||
"scripts": { | ||
"rollup": "rollup -c", | ||
"rollup-tests": "rollup -c rollup-tests.config.js", | ||
"doc": "jsdoc -c conf.json src && node scripts/cleanup.js", | ||
"lint": "repo-tools lint src/**/*.js test/**/*.js scripts/*.js", | ||
"helpers": "node scripts/helpers.js", | ||
"lint": "repo-tools lint src/**/*.js test/**/*.js scripts/*.js lib/**/*.js", | ||
"bundle": "rollup -c", | ||
"bundle2": "rollup -c rollup-es2015.config.js", | ||
"min": "uglifyjs dist/js-data.js -o dist/js-data.min.js --source-map dist/js-data.min.map --source-map-url js-data.min.map -v -m -c --screw-ie8", | ||
@@ -50,8 +51,8 @@ "version": "node scripts/version.js", | ||
"gzip": "echo gzipped size: $(cat dist/js-data.min.js | gzip -f9 | wc -c)kb", | ||
"build": "npm run lint && npm run rollup && npm run min && npm run version && npm run banner", | ||
"build": "npm run lint && npm run bundle && npm run bundle2 && npm run min && npm run version && npm run banner", | ||
"karma": "karma start", | ||
"mocha": "mocha -t 20000 -R spec -r source-map-support/register mocha.start.js", | ||
"r": "npm run rollup && npm run mocha", | ||
"r": "npm run bundle && npm run mocha", | ||
"t": "npm run rollup-tests && npm run mocha", | ||
"rt": "npm run rollup && npm run rollup-tests && npm run mocha", | ||
"rt": "npm run bundle && npm run rollup-tests && npm run mocha", | ||
"cover": "istanbul cover -x dist/js-data-tests.js --hook-run-in-context node_modules/mocha/bin/_mocha -- -t 20000 -R dot -r source-map-support/register mocha.start.js", | ||
@@ -64,6 +65,6 @@ "test": "npm run build && npm run rollup-tests && npm run cover", | ||
"devDependencies": { | ||
"babel-core": "6.7.2", | ||
"babel-core": "6.7.4", | ||
"babel-plugin-syntax-async-functions": "6.5.0", | ||
"babel-plugin-transform-regenerator": "6.6.5", | ||
"babel-polyfill": "6.7.2", | ||
"babel-polyfill": "6.7.4", | ||
"babel-preset-es2015-rollup": "1.1.1", | ||
@@ -78,3 +79,3 @@ "babel-preset-stage-0": "6.5.0", | ||
"mocha": "2.4.5", | ||
"rollup": "0.25.4", | ||
"rollup": "0.25.5", | ||
"rollup-plugin-babel": "2.4.0", | ||
@@ -81,0 +82,0 @@ "sinon": "1.17.3", |
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
1255390
20
13722