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

js-data

Package Overview
Dependencies
Maintainers
1
Versions
144
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

js-data - npm Package Compare versions

Comparing version 3.0.0-alpha.10 to 3.0.0-alpha.12

11

CHANGELOG.md

@@ -0,1 +1,12 @@

##### 3.0.0-alpha.12 - 04 February 2016
- Added back relation linking to DataStore and LinkedCollection
- Container and DataStore now proxy a number of Collection methods
- Container and DataStore now proxy Mapper#createRecord
- Container now proxies async Mapper methods, not just DataStore
##### 3.0.0-alpha.11 - 25 January 2016
- Refactored architecture into Record, Collection (and LinkedCollection), Mapper, Container, DataStore, and Schema
##### 3.0.0-alpha.10 - 09 January 2016

@@ -2,0 +13,0 @@

9

conf.json

@@ -17,7 +17,8 @@ {

"systemName": "js-data",
"copyright": "js-data Copyright © 2014-2016 Jason Dobry"
},
"source": {
"excludePattern": "(sync_methods|old_utils)"
"copyright": "js-data Copyright © 2014-2016 Jason Dobry",
"outputSourceFiles": true,
"syntaxTheme": "dark",
"linenums": true,
"footer": "<div style=\"text-align:center\">Back to <a href=\"http://js-data.io\">js-data.io</a></div>"
}
}
/*!
* js-data
* @version 3.0.0-alpha.10 - Homepage <http://www.js-data.io/>
* @version 3.0.0-alpha.12 - Homepage <http://www.js-data.io/>
* @author Jason Dobry <jason.dobry@gmail.com>

@@ -10,4 +10,4 @@ * @copyright (c) 2014-2015 Jason Dobry

*/
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t(e.JSData={})}(this,function(e){"use strict";function t(e){return Object.prototype.toString.call(e)}function n(e){return"[object Object]"===t(e)||!1}function r(e){return!!e&&"object"===("undefined"==typeof e?"undefined":ne.typeof(e))&&e.constructor===Object}function i(e){return"[object RegExp]"===t(e)||!1}function o(e){return"string"==typeof e||e&&"object"===("undefined"==typeof e?"undefined":ne.typeof(e))&&"[object String]"===t(e)||!1}function a(e){return e&&"object"===("undefined"==typeof e?"undefined":ne.typeof(e))&&"[object Date]"===t(e)||!1}function u(e){var n="undefined"==typeof e?"undefined":ne.typeof(e);return"number"===n||e&&"object"===n&&"[object Number]"===t(e)||!1}function s(e){return"[object Boolean]"===t(e)}function f(e){return"function"==typeof e||e&&"[object Function]"===t(e)||!1}function l(e){return o(e)||u(e)}function c(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]}}function d(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]}function h(e,t){if(!t)return e;var n=t.split(".");return n.forEach(function(t){e[t]||(e[t]={}),e=e[t]}),e}function p(e,t,r){if(n(t))v(t,function(t,n){p(e,n,t)});else{var i=ie.exec(t);i?h(e,i[1])[i[2]]=r:e[t]=r}}function v(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)}function g(e,t){return t&&v(t,function(e,t){var n=this[t];r(e)&&r(n)?g(n,e):this[t]=e},e),e}function m(e){return Promise.resolve(e)}function y(e){return Promise.reject(e)}function b(e,t){for(var n in e){var r=e[n];void 0===t[n]&&!f(r)&&n&&0!==n.indexOf("_")&&(t[n]=r)}}function A(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}function x(e,t){v(t,function(t,n){void 0===e[n]&&(e[n]=t)})}function _(e,n){if(!n||!n.length)return!1;for(var r=void 0,i=0;i<n.length;i++)if("[object RegExp]"===t(n[i])&&n[i].test(e)||n[i]===e)return r=e;return!!r}function w(e){return o(e)?JSON.parse(e):e}function O(e,t,r,o,u){if(t){if(e===t)throw new Error("Cannot copy! Source and destination are identical.");if(r=r||[],o=o||[],n(e)){var s=r.indexOf(e);if(-1!==s)return o[s];r.push(e),o.push(t)}var f=void 0;if(re(e)){var l=void 0;for(t.length=0,l=0;l<e.length;l++)f=O(e[l],null,r,o,u),n(e[l])&&(r.push(e[l]),o.push(f)),t.push(f)}else{re(t)?t.length=0:v(t,function(e,n){delete t[n]});for(var c in e)if(e.hasOwnProperty(c)){if(_(c,u))continue;f=O(e[c],null,r,o,u),n(e[c])&&(r.push(e[c]),o.push(f)),t[c]=f}}}else t=e,e&&(re(e)?t=O(e,[],r,o,u):a(e)?t=new Date(e.getTime()):i(e)?(t=new RegExp(e.source,e.toString().match(/[^\/]*$/)[0]),t.lastIndex=e.lastIndex):n(e)&&(t=O(e,Object.create(Object.getPrototypeOf(e)),r,o,u)));return t}function k(e,t,n){return""+t.toUpperCase()+n.toLowerCase()}function C(e){return e.replace(ue,"").replace(se,k)}function E(e){return e.split(ae).map(C).join("")}function I(e){return e=E(e),e?e.charAt(0).toLowerCase()+e.slice(1):e}function R(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)}}})}function j(e,t){for(t=e="";e++<36;t+=51*e&52?(15^e?8^Math.random()*(20^e?16:4):4).toString(16):"-");return t}function P(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function M(e,t){if(!e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return!t||"object"!==("undefined"==typeof t?"undefined":ne.typeof(t))&&"function"!=typeof t?e:t}function F(e,t){v(t,function(e,n){t[n]={value:e}}),Object.defineProperties(e,t)}function S(e,t){var n=this,r=void 0;return e||(e={}),t||(t={}),e.hasOwnProperty("constructor")?(r=e.constructor,delete e.constructor):r=function(){P(this,r);for(var e=arguments.length,t=Array(e),n=0;e>n;n++)t[n]=arguments[n];var i=M(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(n,function(e,t){r[t]=e}),Object.defineProperty(r,"__super__",{configurable:!0,value:n}),g(r.prototype,e),g(r,t),r}function N(e){P(this,N),this.collection=e,this.data=null}function L(e){return e.replace(ce,"\\$1")}function D(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 K(e,t,n){return e.splice(t,0,n),e}function U(e,t){return e.splice(t,1),e}function T(e,t,n){for(var r=0,i=e.length,o=void 0,a=void 0;i>r;){if(a=(r+i)/2|0,o=D(t,e[a],n),0===o)return{found:!0,index:a};0>o?i=a:r=a+1}return{found:!1,index:i}}function J(e,t){if(P(this,J),e||(e=[]),!re(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 q(e,t){var r=this;P(r,q),n(e)&&!re(e)&&(t=e,e=[]),e||(e=[]),t||(t={}),r.model=t.model,r.idAttribute=t.idAttribute,r.modelOpts=t.modelOpts||{},r._listeners={},this.onConflict=t.onConflict||"merge";var i=r.modelId();r.index=new J([i],{hashCode:function(e){return c(e,i)}}),r.indexes={},r.added={},r.autoPks={},r.createIndex("addedTimestamps",["$"],{fieldGetter:function(e){return r.added[c(e,i)]}}),e.forEach(function(e){r.index.insertRecord(e),e&&f(e.on)&&e.on("all",r._onModelEvent,r)})}function z(e,t,n){function r(){var n={name:t};return o(t)?f(e.getModel)?e.getModel(t)||n:n:t}function i(){return n.localField||I(r().name)}function a(){return n.foreignKey||n.localKey||I(r().name)+"Id"}n||(n={});var u={enumerable:void 0!==n.enumerable?!!n.enumerable:!1,get:function(){return this._get("links."+i())},set:function(e){return e?(this._set("links."+i(),e),p(this,a(),e[r().idAttribute]),c(this,i())):void 0}},s=u.get,l=u.set;return n.get&&(u.get=function(){var t=this;return n.get(e,r(),this,function(){return s.call(t)})},delete u.writable),n.set&&(u.set=function(t){var i=this;return n.set(e,r(),this,t,function(e){return l.call(i,void 0===e?t:e)})},delete u.writable),u.get&&(u.set||(u.set=function(){})),Object.defineProperty(e.prototype,i(),u),e.relationList||(e.relationList=[]),e.relationFields||(e.relationFields=[]),n.type="belongsTo",n.name=e.name,n.relation=t.name,n.Relation=t,n.getRelation=r,n.getLocalField=i,n.getForeignKey=a,e.relationList.push(n),e.relationFields.push(i()),e}function $(e,t){return function(n){return n.dbg(ve,e,t),z(n,e,t)}}function B(e){var t=arguments.length<=1||void 0===arguments[1]?!0:arguments[1];return e=e||{},function(n){return v(e,function(e,r){(void 0===n[r]||t)&&(n[r]=O(e))}),n}}function V(e,t,n){function r(){var n={name:t};return o(t)?f(e.getModel)?e.getModel(t)||n:n:t}function i(){return n.localField||I(r().name)+"Collection"}n||(n={});var a=n.foreignKey,u=n.localKeys,s=n.foreignKeys;a||u||s||(a=n.foreignKey=I(e.name)+"Id");var l={enumerable:void 0!==n.enumerable?!!n.enumerable:!1,get:function(){return this._get("links."+i())},set:function(t){var n=this;if(t)return this._set("links."+i(),t),t&&t.length&&!function(){var i=c(n,e.idAttribute);a?t.forEach(function(e){p(e,a,i)}):u?!function(){var e=[];t.forEach(function(t){e.push(c(t,r().idAttribute))}),p(n,u,e)}():s&&t.forEach(function(e){var t=c(e,s);t?-1===t.indexOf(i)&&t.push(i):p(e,s,[i])})}(),c(this,i())}},d=l.get,h=l.set;return n.get&&(l.get=function(){var t=this;return n.get(e,r(),this,function(){return d.call(t)})}),n.set&&(l.set=function(t){var i=this;return n.set(e,r(),this,t,function(e){return h.call(i,void 0===e?t:e)})}),Object.defineProperty(e.prototype,i(),l),e.relationList||(e.relationList=[]),e.relationFields||(e.relationFields=[]),n.type="hasMany",n.name=e.name,n.relation=r().name,n.Relation=r(),n.getRelation=r,n.getLocalField=i,e.relationList.push(n),e.relationFields.push(i()),e}function G(e,t){return function(n){return n.dbg(ge,e,t),V(n,e,t)}}function H(e,t,n){function r(){var n={name:t};return o(t)?f(e.getModel)?e.getModel(t)||n:n:t}function i(){return n.localField||I(r().name)}function a(){return n.foreignKey||n.localKey||I(e.name)+"Id"}n||(n={});var u={enumerable:void 0!==n.enumerable?!!n.enumerable:!1,get:function(){return this._get("links."+i())},set:function(t){return t?(this._set("links."+i(),t),p(t,a(),c(this,e.idAttribute)),c(this,i())):void 0}};return n.get&&!function(){var r=u.get;u.get=function(){var i=this;return n.get(e,t,this,r?function(){for(var e=arguments.length,t=Array(e),n=0;e>n;n++)t[n]=arguments[n];return r.apply(i,t)}:void 0)}}(),n.set&&!function(){var r=u.set;u.set=function(i){var o=this;return n.set(e,t,this,i,r?function(){for(var e=arguments.length,t=Array(e),n=0;e>n;n++)t[n]=arguments[n];return r.apply(o,t)}:void 0)}}(),Object.defineProperty(e.prototype,i(),u),e.relationList||(e.relationList=[]),e.relationFields||(e.relationFields=[]),n.type="hasOne",n.name=e.name,n.relation=t.name,n.Relation=t,n.getRelation=r,n.getLocalField=i,n.getForeignKey=a,e.relationList.push(n),e.relationFields.push(i()),e}function Q(e,t){return function(n){return n.dbg(me,"Model:",e,"opts:",t),H(n,e,t)}}function Z(e,t){var n=[];return v(e,function(e,r){var i=be[r];if(i){var o=i(e,t);o&&n.push(o)}}),n.length?n:void 0}function W(e,t,n){var r={enumerable:void 0!==n.enumerable?n.enumerable:!0};return r.get=function(){return this._get("props."+t)},r.set=function(e){var r=this,i=this._get,o=this._set,a=this._unset;if(!i("noValidate")){var u=Z(n,e);if(u)throw new Error(u.join(", "))}return n.track&&!i("creating")&&!function(){var n=i("changing"),u=i("previous."+t),s=i("props."+t),f=i("changed");n||(f=[]);var l=f.indexOf(t);s!==e&&-1===l&&f.push(t),u!==e?o("changes."+t,e):(a("changes."+t),l>=0&&f.splice(l,1)),f.length||(n=!1,a("changing"),a("changed"),i("eventId")&&(clearTimeout(i("eventId")),a("eventId"))),!n&&f.length&&(o("changed",f),o("changing",!0),o("eventId",setTimeout(function(){if(a("changed"),a("eventId"),a("changing"),!i("silent")){var e=void 0;for(e=0;e<f.length;e++)r.emit("change:"+f[e],r,c(r,f[e]));r.emit("change",r,i("changes"))}a("silent")},0)))}(),o("props."+t,e),e},n.get&&(r.get?!function(){var e=r.get;r.get=function(){return n.get.call(this,e)}}():r.get=n.get),n.set&&(r.set?!function(){var e=r.set;r.set=function(t){return n.set.call(this,t,e)}}():r.set=n.set),r}function X(e){return e||(e={}),function(t){return t.dbg(Ae,"opts:",e),t.schema||(t.schema={}),B(t.schema,e),v(e,function(e,n){var r=W(t,n,e);r.writable||Object.defineProperty(t.prototype,n,r)}),t}}function Y(e,t,n){return n||(n={}),n.op=xe,function(r){r.dbg(xe,"name:",e,"adapter:",t,"opts:",n),r.getAdapters()[e]=t,(n===!0||n.default)&&(r.defaultAdapter=e)}}function ee(e,t){var n=this;P(n,ee),e||(e={}),t||(t={});var r={};Object.defineProperties(n,{_get:{value:function(e){return c(r,e)}},_set:{value:function(e,t){return p(r,e,t)}},_unset:{value:function(e){return d(r,e)}}}),n._set("creating",!0),t.noValidate&&n._set("noValidate",!0),x(n,e),n._unset("creating"),n._set("changes",{}),n._unset("noValidate"),n._set("previous",O(e))}function te(e){var t=this;P(t,te),e||(e={}),t.defaults={};for(var n in e)t.defaults[n]=e[n];t.models={},t.collections={}}var ne={};ne.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},ne.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 re=Array.isArray,ie=/^(.+)\.(.+)$/,oe=JSON.stringify,ae=/\s+/,ue=/[^A-Za-z]/g,se=/(\w)(\w*)/g,fe=Object.freeze({isArray:re,isObject:n,isRegExp:i,isString:o,isDate:a,isNumber:u,isBoolean:s,isFunction:f,isSorN:l,get:c,unset:d,set:p,forOwn:v,deepMixIn:g,resolve:m,reject:y,_:b,intersection:A,fillIn:x,isBlacklisted:_,fromJson:w,toJson:oe,copy:O,pascalCase:E,camelCase:I,eventify:R,uuid:j,classCallCheck:P,possibleConstructorReturn:M,addHiddenPropsToTarget:F,extend:S}),le={skip:"",offset:"",where:"",limit:"",orderBy:"",sort:""},ce=/([.*+?^=!:${}()|[\]\/\\])/g,de=/%/g,he=/_/g;N.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!A(e||[],t||[]).length},isectNotEmpty:function(e,t){return A(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)}},F(N.prototype,{compare:function(e,t,n,r){var i=e[t],a=c(n,i[0]),u=c(r,i[0]);return a&&o(a)&&(a=a.toUpperCase()),u&&o(u)&&(u=u.toUpperCase()),n||(n=null),r||(r=null),"DESC"===i[1]?a>u?-1:u>a?1:t<e.length-1?this.compare(e,t+1,n,r):0:u>a?-1:a>u?1:t<e.length-1?this.compare(e,t+1,n,r):0},evaluate:function(e,t,n){return N.ops[t]?N.ops[t](e,n):0===t.indexOf("like")?null!==this.like(n,t.substr(4)).exec(e):0===t.indexOf("notLike")?null===this.like(n,t.substr(7)).exec(e):void 0},like:function(e,t){return new RegExp("^"+L(e).replace(de,".*").replace(he,".")+"$",t)},getData:function(){return this.data||(this.data=this.collection.index.getAll()),this.data},between:function(e,t,n){n||(n={});var r=this.collection,i=n.index?r.indexes[n.index]:r.index;if(this.data)throw new Error("Cannot access index after first operation!");return this.data=i.between(e,t,n),this},get:function(){var e=arguments.length<=0||void 0===arguments[0]?[]:arguments[0],t=arguments[1];if(t||(t={}),this.data)throw new Error("Cannot access index after first operation!");if(e&&!re(e)&&(e=[e]),!e.length)return this.getData(),this;var n=this.collection,r=t.index?n.indexes[t.index]:n.index;return this.data=r.get(e),this},getAll:function(){var e=this,t={};if(this.data)throw new Error("Cannot access index after first operation!");for(var r=arguments.length,i=Array(r),o=0;r>o;o++)i[o]=arguments[o];if(!i.length||1===i.length&&n(i[0]))return this.getData(),this;i.length&&n(i[i.length-1])&&(t=i[i.length-1],i.pop());var a=this.collection,u=t.index?a.indexes[t.index]:a.index;return this.data=[],i.forEach(function(t){e.data=e.data.concat(u.get(t))}),this},filter:function(e,t){var r=this;return e||(e={}),r.getData(),n(e)?!function(){var t={};n(e.where)&&(t=e.where),v(e,function(e,n){n in le||n in t||(t[n]={"==":e})});var i=[],a=[],s=[];v(t,function(e,t){n(e)||(e={"==":e}),v(e,function(e,n){i.push(t),a.push(n),s.push(e)})}),i.length&&!function(){var e=void 0,t=i.length;r.data=r.data.filter(function(n){var o=!0,u=!0;for(e=0;t>e;e++){var f=a[e],l="|"===f.charAt(0);f=l?f.substr(1):f;var d=r.evaluate(c(n,i[e]),f,s[e]);void 0!==d&&(u=o?d:l?u||d:u&&d),o=!1}return u})}();var f=e.orderBy||e.sort;o(f)&&(f=[[f,"ASC"]]),re(f)||(f=null),f&&!function(){var e=0;f.forEach(function(e,t){o(e)&&(f[t]=[e,"ASC"])}),r.data.sort(function(t,n){return r.compare(f,e,t,n)})}(),u(e.skip)?r.skip(e.skip):u(e.offset)&&r.skip(e.offset),u(e.limit)&&r.limit(e.limit)}():f(e)&&(r.data=r.data.filter(e,t)),r},skip:function(e){if(!u(e))throw new TypeError("skip: Expected number but found "+("undefined"==typeof e?"undefined":ne.typeof(e))+"!");var t=this.getData();return e<t.length?this.data=t.slice(e):this.data=[],this},limit:function(e){if(!u(e))throw new TypeError("limit: Expected number but found "+("undefined"==typeof e?"undefined":ne.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}});var pe={">":1,">=":1,"<":1,"<=":1};F(J.prototype,{set:function(e,t){re(e)||(e=[e]);var n=e.shift()||null,r=T(this.keys,n);if(0===e.length)if(r.found){var i=T(this.values[r.index],t,this.hashCode);i.found||K(this.values[r.index],i.index,t)}else K(this.keys,r.index,n),K(this.values,r.index,[t]);else if(r.found)this.values[r.index].set(e,t);else{K(this.keys,r.index,n);var o=new J([],{hashCode:this.hashCode});o.set(e,t),K(this.values,r.index,o)}},get:function(e){re(e)||(e=[e]);var t=e.shift()||null,n=T(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)})},query:function(e){var t=void 0,n=void 0;if(e[">"]?(t=e[">"],e.leftInclusive=!1):e[">="]&&(t=e[">="],e.leftInclusive=!0),e["<"]?(n=e["<"],e.rightInclusive=!1):e["<="]&&(n=e["<="],e.rightInclusive=!0),t.length!==n.length)throw new Error("Key arrays must be same length");var r={};return v(e,function(e,t){pe[t]||(r[t]=e)}),this.between(t,n,r)},between:function(e,t){var n=arguments.length<=2||void 0===arguments[2]?{}:arguments[2];re(e)||(e=[e]),re(t)||(t=[t]),x(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(),a=void 0;if(a=void 0!==i?T(this.keys,i):{found:!1,index:0},0===e.length){a.found&&n.leftInclusive===!1&&(a.index+=1);for(var u=a.index;u<this.keys.length;u+=1){if(void 0!==o)if(n.rightInclusive){if(this.keys[u]>o)break}else if(this.keys[u]>=o)break;if(r=this.values[u].isIndex?r.concat(this.values[u].getAll()):r.concat(this.values[u]),n.limit&&r.length>=n.limit+n.offset)break}}else for(var u=a.index;u<this.keys.length;u+=1){var s=this.keys[u];if(s>o)break;if(r=this.values[u].isIndex?s===i?r.concat(this.values[u]._between(O(e),t.map(function(){}),n)):s===o?r.concat(this.values[u]._between(e.map(function(){}),O(t),n)):r.concat(this.values[u].getAll()):r.concat(this.values[u]),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]:[]},remove:function(e,t){re(e)||(e=[e]);var n=e.shift(),r=T(this.keys,n);if(0===e.length){if(r.found){var i=T(this.values[r.index],t,this.hashCode);i.found&&(U(this.values[r.index],i.index),0===this.values[r.index].length&&(U(this.keys,r.index),U(this.values,r.index)))}}else r.found&&this.values[r.index].delete(e,t)},clear:function(){this.keys=[],this.values=[]},insertRecord:function(e){var t=this.fieldList.map(function(t){return f(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&&(U(t.keys,i),U(t.values,i)),n=!0,!1}else{var o=T(r,e,t.hashCode);if(o.found)return U(r,o.index),0===r.length&&(U(t.keys,i),U(t.values,i)),n=!0,!1}}),n?e:void 0},updateRecord:function(e){this.removeRecord(e),this.insertRecord(e)}}),F(q.prototype,{_onModelEvent:function(){this.emit.apply(this,arguments)},modelId:function(e){var t=this;return e?c(e,t.modelId()):t.model?t.model.idAttribute:t.idAttribute||"id"},createIndex:function(e,t,n){var r=this;o(e)&&void 0===t&&(t=[e]),n||(n={}),n.hashCode=n.hashCode||function(e){return r.modelId(e)};var i=r.indexes[e]=new J(t,n);return r.index.visitAll(i.insertRecord,i),r},getAutoPkItems:function(){var e=this;return e.getAll().filter(function(t){return e.autoPks[e.modelId(t)]})},query:function(){return new N(this)},between:function(e,t,n){return this.query().between(e,t,n).run()},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()},filter:function(e,t){return this.query().filter(e,t).run()},skip:function(e){return this.query().skip(e).run()},limit:function(e){return this.query().limit(e).run()},forEach:function(e,t){this.index.visitAll(e,t)},reduce:function(e,t){var n=this.getAll();return n.reduce(e,t)},map:function(e,t){var n=[];return this.index.visitAll(function(r){n.push(e.call(t,r))}),n},beforeAdd:function(){},add:function(e,t){var n=this;t||(t={}),b(n,t),e=n.beforeAdd(e,t)||e;var r=!1,i=n.modelId(),o=n.model?n.model.relationList||[]:[],a=(new Date).getTime();re(e)||(e=[e],r=!0),e=e.map(function(e){var r=n.modelId(e),u=!1;if(!l(r)){if(!t.autoPk)throw new TypeError(i+": Expected string or number, found "+("undefined"==typeof r?"undefined":ne.typeof(r))+"!");r=j(),p(e,i,r),u=!0}var s=n.get(r);if(e===s)return s;if(o.forEach(function(t){var i=t.getRelation();if(i.idAttribute){var o=i.idAttribute,a=t.foreignKey,u=c(e,t.getLocalField());if(f(t.add))t.add(n,t,e);else if(u&&t.add!==!1)if(re(u))u=u.map(function(e){if(!i.is(e))try{a&&p(e,a,r),e=i.createInstance(e)}catch(e){throw new Error("Failed to insert "+t.type+' relation: "'+t.relation+'"! '+e.message)}return e}),t.localKeys&&p(e,t.localKeys,u.map(function(e){return c(e,o)}));else if(!i.is(u))try{a&&p(u,t.foreignKey,r),u=i.createInstance(u)}catch(e){throw new Error("Failed to insert "+t.type+' relation: "'+t.relation+'"!')}p(e,t.localField,u)}}),s){var d=t.onConflict||n.onConflict;"merge"===d?g(s,e):"replace"===d&&(v(s,function(t,n){n===i||e.hasOwnProperty(n)||delete s[n]}),s.set(e)),e=s,n.updateIndexes(e)}else e=n.model?n.model.createInstance(e):e,n.index.insertRecord(e),v(n.indexes,function(t,n){t.insertRecord(e)}),e&&f(e.on)&&(e.on("all",n._onModelEvent,n),n.emit("add",e));return n.added[r]=a,u&&(n.autoPks[r]=e),e});var u=r?e.length?e[0]:void 0:e;return n.afterAdd(u,t),u},afterAdd:function(){},beforeRemove:function(){},remove:function(e,t){var n=this;t||(t={}),n.beforeRemove(e,t);var r=n.get(e);return r&&(delete n.added[e],delete n.autoPks[e],n.index.removeRecord(r),v(n.indexes,function(e,t){e.removeRecord(r)}),r&&f(r.off)&&(r.off("all",n._onModelEvent,n),n.emit("remove",r))),n.afterRemove(r,t),r},afterRemove:function(){},beforeRemoveAll:function(){},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.modelId(e))}),n.afterRemoveAll(r,e,t),r},afterRemoveAll:function(){},updateIndex:function(e,t){t||(t={});var n=t.index?this.indexes[t.index]:this.index;n.updateRecord(e)},updateIndexes:function(e){var t=this;t.index.updateRecord(e),v(t.indexes,function(t,n){t.updateRecord(e)})},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},toJSON:function(e){return this.mapCall("toJSON",e)},end:function(e,t){var n=this;return t.raw?(t.autoAdd&&(e.data=n.add(e.data,t)),e):(t.autoAdd&&(e=n.add(e,t)),e)},create:function(e,t){var n=this,r=n.modelId(e);return t||(t={}),x(t,n.modelOpts),n.model.create(e,t).then(function(e){return n.autoPks[r]&&n.remove(r),n.end(e,t)})},createMany:function(e,t){var n=this;return t||(t={}),x(t,n.modelOpts),n.model.createMany(e,t).then(function(r){return e.forEach(function(e){var t=n.modelId(e);n.autoPks[t]&&n.remove(t)}),n.end(r,t)})},find:function(e,t){var n=this;return t||(t={}),x(t,n.modelOpts),n.model.find(e,t).then(function(e){return n.end(e,t)})},findAll:function(e,t){var n=this;return t||(t={}),x(t,n.modelOpts),n.model.findAll(e,t).then(function(e){return n.end(e,t)})},update:function(e,t,n){var r=this;return n||(n={}),x(n,r.modelOpts),r.model.update(e,t,n).then(function(e){return r.end(e,n)})},updateMany:function(e,t){var n=this;return t||(t={}),x(t,n.modelOpts),n.model.updateMany(e,t).then(function(e){return n.end(e,t)})},updateAll:function(e,t,n){var r=this;return n||(n={}),x(n,r.modelOpts),r.model.updateAll(e,t,n).then(function(e){return r.end(e,n)})},destroy:function(e,t){var n=this;return t||(t={}),x(t,n.modelOpts),n.model.destroy(e,t).then(function(r){return t.raw?r.data=n.remove(e,t):r=n.remove(e,t),r})},destroyAll:function(e,t){var n=this;return t||(t={}),x(t,n.modelOpts),n.model.destroyAll(e,t).then(function(r){return t.raw?r.data=n.removeAll(e,t):r=n.removeAll(e,t),r})}}),R(q.prototype,function(){return this._listeners},function(e){this._listeners=e});var ve="belongsTo",ge="hasMany",me="hasOne",ye={array:re,boolean:s,integer:u,number:u,null:function(e){return null===e},object:n,string:o},be={type:function(e,t){if(void 0!==t){o(e)&&(e=[e]);var n=e.map(function(n){var r=ye[n];return r?r(t)?void 0:1:"type: Unknown type "+e});return-1!==n.indexOf(void 0)?void 0:"type: Expected: "+e.join(" or ")+". Actual: "+("undefined"==typeof t?"undefined":ne.typeof(t))}},anyOf:function(e,t){var n=!1,r=[];return e.forEach(function(e){var i=Z(e,t);i?r=r.concat(i):n=!0}),n?void 0:r},allOf:function(e,t){var n=[];return e.forEach(function(e){n=n.concat(Z(e,t)||[])}),n.length?void 0:n},oneOf:function(e,t){var n=!1,r=[];return e.forEach(function(e){var i=Z(e,t);if(i)r=r.concat(i);else{if(n)return r=["more than one schema validated"],n=!1,!1;n=!0}}),n?void 0:r}},Ae="setSchema",xe="registerAdapter",_e=m,we=function(){for(var e=arguments.length,t=Array(e),n=0;e>n;n++)t[n]=arguments[n];var r=this,i=t.pop();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))})};F(ee.prototype,{schema:function(e){var t=this.constructor.schema;return e?t[e]:t},validate:function(e,t){var n=[],r=this.schema();if(e)if(o(e)){var i=r[e];i&&(n=Z(i,t)||[])}else v(r,function(t,r){n=n.concat(Z(t,c(e,r))||[])});else e=this;return n.length?n:void 0},create:function(e){return this.constructor.create(this,e)},beforeSave:function(){},save:function(e){var t=void 0,n=void 0,r=this,i=r.constructor;return e||(e={}),b(r,e),n=e.adapter=r.getAdapterName(e),t=e.op="beforeSave",_e(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",_e(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.constructor,a=i.relationList||[];return e||(e=[]),t||(t={}),b(i,t),t.adapter=i.getAdapterName(t),n=t.op="beforeLoadRelations",_e(r[n](e,t)).then(function(){return o(e)&&(e=[e]),n=t.op="loadRelations",i.dbg(n,r,e,t),Promise.all(a.map(function(e){if(f(e.load))return e.load(i,e,r,t);var n=void 0;if("hasMany"===e.type&&e.foreignKey)n=e.Relation.findAll(ne.defineProperty({},e.foreignKey,c(r,i.idAttribute)),t);else if(e.foreignKey){var o=c(r,e.foreignKey);l(o)&&(n=e.Relation.find(o,t))}else e.localKeys?n=e.Relation.findAll(ne.defineProperty({},e.Relation.idAttribute,{in:c(r,e.localKeys)}),t):e.foreignKeys&&(n=e.Relation.findAll(ne.defineProperty({},e.Relation.idAttribute,{contains:c(r,i.idAttribute)}),t));return n&&(n=n.then(function(n){t.raw&&(n=n.data),p(r,e.localField,"hasOne"===e.type?n.length?n[0]:void 0:n)})),n}))}).then(function(){return n=t.op="afterLoadRelations",_e(r[n](e,t)).then(function(){return r})})},afterLoadRelations:function(){},destroy:function(e){var t=this.constructor;return t.destroy(c(this,t.idAttribute),e)},get:function(e){return c(this,e)},set:function(e,t,r){var i=this;n(e)&&(r=t),r||(r={}),r.silent&&i._set("silent",!0),p(i,e,t),i._get("eventId")||i._unset("silent")},unset:function(e,t){t||(t={}),t.silent&&this._set("silent",!0),d(this,e),this._get("eventId")||this._unset("silent")},hashCode:function(){return c(this,this.constructor.idAttribute)},changes:function(e){return e?this._get("changes."+e):this._get("changes")},hasChanges:function(){return!!(this._get("changed")||[]).length},commit:function(){return this._unset("changed"),this._set("changes",{}),this._set("previous",O(this)),this},previous:function(e){return e?this._get("previous."+e):this._get("previous")},revert:function(e){var t=this,n=this._get("previous")||{};return e||(e={}),e.preserve||(e.preserve=[]),v(this,function(r,i){i!==t.constructor.idAttribute&&!n.hasOwnProperty(i)&&t.hasOwnProperty(i)&&-1===e.preserve.indexOf(i)&&delete t[i]}),v(n,function(n,r){-1===e.preserve.indexOf(r)&&(t[r]=n)}),this.commit(),this},toJSON:function(e){return this.constructor.toJSON(this,e)}}),x(ee,{_adapters:null,_adaptersOwner:null,_listeners:null,_listenersOwner:null,csp:!1,defaultAdapter:"http",debug:!1,idAttribute:"id",notify:!0,pojo:!1,relationsEnumerable:!1,raw:!1,upsert:!0,_events:function(e){return e?this._listeners=e:this._listenersOwner!==this&&(this._listeners={},this._listenersOwner=this),this._listeners},end:function(e,t){var n=this;if(t.raw&&b(t,e),!t.pojo){var r=t.raw?e.data:e;r=re(r)?r.map(function(e){return n.createInstance(e)}):n.createInstance(r),t.raw?e.data=r:e=r}return t.notify&&setTimeout(function(){n.emit(t.op,e,t)}),e},createInstance:function(e,t){var n=this;return e instanceof n?e:new n(e,t)},is:function(e,t){var n=this;return n.instanceClass&&!t?e instanceof n.instanceClass:e instanceof n},toJSON:function(e,t){var n=this;t||(t={});var r=e;if(n.is(e)){r={};for(var i in e)r[i]=e[i];n&&n.relationList&&t.with&&(o(t.with)&&(t.with=[t.with]),n.relationList.forEach(function(n){var i=void 0;-1!==t.with.indexOf(n.relation)?i=n.relation:-1!==t.with.indexOf(n.localField)&&(i=n.localField),i&&!function(){var o={with:t.with.slice()};o.with.splice(o.with.indexOf(i),1),o.with.forEach(function(e,t){e&&0===e.indexOf(i)&&e.length>=i.length&&"."===e[i.length]?o.with[t]=e.substr(i.length+1):o.with[t]=""});var a=c(e,n.localField);a&&(re(a)?p(r,n.localField,a.map(function(e){return n.Relation.toJSON(e,o)})):p(r,n.localField,n.Relation.toJSON(a,o)))}()}))}return r},getAdapter:function(e){this.dbg("getAdapter","name:",e);var t=this.getAdapterName(e);if(!t)throw new ReferenceError(t+" not found!");return this.getAdapters()[t]},getAdapterName:function(e){return e||(e={}),o(e)&&(e={adapter:e}),e.adapter||e.defaultAdapter},getAdapters:function(){if(this._adaptersOwner!==this){var e=this._adapters;this._adapters={},e&&x(this._adapters,e),this._adaptersOwner=this}return this._adapters},beforeCreate:we,checkUpsertCreate:function(e,t){var n=this;return(t.upsert||void 0===t.upsert&&n.upsert)&&c(e,n.idAttribute)},create:function(e,t){var n=void 0,r=void 0,i=this;return e||(e={}),t||(t={}),i.checkUpsertCreate(e,t)?i.update(c(e,i.idAttribute),e,t):(b(i,t),r=t.adapter=i.getAdapterName(t),n=t.op="beforeCreate",_e(i[n](e,t)).then(function(o){e=o||e,n=t.op="create";var a=i.toJSON(e,t);return i.dbg(n,a,t),i.getAdapter(r)[n](i,a,t)}).then(function(e){return n=t.op="afterCreate",_e(i[n](e,t)).then(function(n){return e=n||e,i.end(e,t)})}))},afterCreate:we,beforeCreateMany:we,checkUpsertCreateMany:function(e,t){var n=this;return t.upsert||void 0===t.upsert&&n.upsert?e.reduce(function(e,t){return e&&c(t,n.idAttribute)},!0):void 0},createMany:function(e,t){var n=void 0,r=void 0,i=this;return e||(e=[]),t||(t={}),i.checkUpsertCreateMany(e,t)?i.updateMany(e,t):(b(i,t),r=t.adapter=i.getAdapterName(t),n=t.op="beforeCreateMany",_e(i[n](e,t)).then(function(o){e=o||e,n=t.op="createMany";var a=e.map(function(e){return i.toJSON(e,t)});return i.dbg(n,a,t),i.getAdapter(r)[n](i,a,t)}).then(function(e){return n=t.op="afterCreateMany",_e(i[n](e,t)).then(function(n){
return e=n||e,i.end(e,t)})}))},afterCreateMany:we,beforeFind:we,find:function(e,t){var n=void 0,r=void 0,i=this;return t||(t={}),b(i,t),r=t.adapter=i.getAdapterName(t),n=t.op="beforeFind",_e(i[n](e,t)).then(function(o){return e=void 0===o?e:o,n=t.op="find",i.dbg(n,e,t),i.getAdapter(r)[n](i,e,t)}).then(function(e){return n=t.op="afterFind",_e(i[n](e,t)).then(function(n){return e=n||e,i.end(e,t)})})},afterFind:we,beforeFindAll:we,findAll:function(e,t){var n=void 0,r=void 0,i=this;return e||(e={}),t||(t={}),b(i,t),r=t.adapter=i.getAdapterName(t),n=t.op="beforeFindAll",_e(i[n](e,t)).then(function(o){return e=o||e,n=t.op="findAll",i.dbg(n,e,t),i.getAdapter(r)[n](i,e,t)}).then(function(r){return n=t.op="afterFindAll",_e(i[n](r,e,t)).then(function(e){return r=e||r,i.end(r,t)})})},afterFindAll:we,beforeUpdate:we,update:function(e,t,n){var r=void 0,i=void 0,o=this;return t||(t={}),n||(n={}),b(o,n),i=n.adapter=o.getAdapterName(n),r=n.op="beforeUpdate",_e(o[r](e,t,n)).then(function(a){t=a||t,r=n.op="update";var u=o.toJSON(t,n);return o.dbg(r,e,u,n),o.getAdapter(i)[r](o,e,u,n)}).then(function(t){return r=n.op="afterUpdate",_e(o[r](e,t,n)).then(function(e){return t=e||t,o.end(t,n)})})},afterUpdate:we,beforeUpdateMany:we,updateMany:function(e,t){var n=void 0,r=void 0,i=this;return e||(e=[]),t||(t={}),b(i,t),r=t.adapter=i.getAdapterName(t),n=t.op="beforeUpdateMany",_e(i[n](e,t)).then(function(o){e=o||e,n=t.op="updateMany";var a=e.map(function(e){return i.toJSON(e,t)});return i.dbg(n,a,t),i.getAdapter(r)[n](i,a,t)}).then(function(e){return n=t.op="afterUpdateMany",_e(i[n](e,t)).then(function(n){return e=n||e,i.end(e,t)})})},afterUpdateMany:we,beforeUpdateAll:we,updateAll:function(e,t,n){var r=void 0,i=void 0,o=this;return e||(e={}),t||(t={}),n||(n={}),b(o,n),i=n.adapter=o.getAdapterName(n),r=n.op="beforeUpdateAll",_e(o[r](e,t,n)).then(function(a){t=a||t,r=n.op="updateAll";var u=o.toJSON(t,n);return o.dbg(r,e,u,n),o.getAdapter(i)[r](o,e,u,n)}).then(function(t){return r=n.op="afterUpdateAll",_e(o[r](e,t,n)).then(function(e){return t=e||t,o.end(t,n)})})},afterUpdateAll:we,beforeDestroy:we,destroy:function(e,t){var n=void 0,r=void 0,i=this;return t||(t={}),b(i,t),r=t.adapter=i.getAdapterName(t),n=t.op="beforeDestroy",_e(i[n](e,t)).then(function(o){return e=void 0===o?e:o,n=t.op="destroy",i.dbg(n,e,t),i.getAdapter(r)[n](i,e,t)}).then(function(e){return n=t.op="afterDestroy",_e(i[n](e,t)).then(function(n){return e=n||e,t.raw?(b(t,e),e):e})})},afterDestroy:we,beforeDestroyAll:we,destroyAll:function(e,t){var n=void 0,r=void 0,i=this;return e||(e={}),t||(t={}),b(i,t),r=t.adapter=i.getAdapterName(t),n=t.op="beforeDestroyAll",_e(i[n](e,t)).then(function(o){return e=o||e,n=t.op="destroyAll",i.dbg(n,e,t),i.getAdapter(r)[n](i,e,t)}).then(function(r){return n=t.op="afterDestroyAll",_e(i[n](r,e,t)).then(function(e){return r=e||r,t.raw?(b(t,r),r):r})})},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+")";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 $(e,t)(this)},hasMany:function(e,t){return G(e,t)(this)},hasOne:function(e,t){return Q(e,t)(this)},setSchema:function(e){return X(e)(this)},configure:function(e){return B(e)(this)},registerAdapter:function(e,t,n){return Y(e,t,n)(this)},extend:function(e,t){var n=this,r=void 0;n.dbg("extend","props:",e,"classProps:",t),e||(e={}),t||(t={});var i=e.initialize;if(delete e.initialize,e.hasOwnProperty("constructor"))r=e.constructor,delete e.constructor;else{if(!t.name)throw new TypeError("name: Expected string, found "+ne.typeof(t.name)+"!");if(t.csp)r=function(){P(this,r);for(var e=arguments.length,t=Array(e),n=0;e>n;n++)t[n]=arguments[n];var o=M(this,(r.__super__||Object.getPrototypeOf(r)).apply(this,t));return i&&i.apply(o,t),o};else{var o=E(t.name),a="return function "+o+"() {\n classCallCheck(this, "+o+")\n for (var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) {\n args[_key] = arguments[_key];\n }\n var _this = possibleConstructorReturn(this, ("+o+".__super__ || Object.getPrototypeOf("+o+")).apply(this, args));\n if (initialize) {\n initialize.apply(_this, arguments)\n }\n return _this\n }";r=new Function("classCallCheck","possibleConstructorReturn","Parent","initialize",a)(P,M,n,i)}}t.shortname=t.shortname||I(r.name||t.name),delete t.name;var u=t.schema;return delete t.schema,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(n,function(e,t){r[t]=e}),Object.defineProperty(r,"__super__",{configurable:!0,value:n}),B(e)(r.prototype),B(t)(r),u&&X(u)(r),r}}),R(ee,function(){return this._events()},function(e){this._events(e)},!0),R(ee.prototype,function(){return this._get("events")},function(e){this._set("events",e)}),F(te.prototype,{defineModel:function(e,t){var r=this;n(e)&&(t=e,e=t.name),t||(t={}),t.relations||(t.relations={}),x(t,r.defaults);var i=t.methods||{};delete t.methods;var o=r.models[t.extends],a=(o||ee).extend(i,t);return r.models[e]=a,a.getModel=function(e){return r.models[e]},v(t.relations,function(e,t){v(e,function(e,i){n(e)&&(e=[e]),e.forEach(function(e){var n=r.models[i]||i;return"belongsTo"===t?a.belongsTo(n,e):"hasOne"===t?a.hasOne(n,e):a.hasMany(n,e)})})}),a},defineCollection:function(e,t,n){var r=this;t||(t={}),o(t.model)&&(t.model=r.models[e]);var i=new(n||q)([],t);return r.collection[e]=i,i},model:function(e){return this.models[e]},collection:function(e){return this.collections[e]},registerAdapter:function(){for(var e=arguments.length,t=Array(e),n=0;e>n;n++)t[n]=arguments[n];v(this.models,function(e){e.registerAdapter.apply(e,t)})}}),te.prototype.defineResource=te.prototype.defineModel,Promise.prototype.spread||(Promise.prototype.spread=function(e){return this.then(function(t){return e.apply(this,t)})});var Oe=fe,ke={full:"<%= pkg.version %>",major:parseInt("<%= major %>",10),minor:parseInt("<%= minor %>",10),patch:parseInt("<%= patch %>",10),alpha:"<%= alpha %>",beta:"<%= beta %>"};e.utils=Oe,e.version=ke,e.Collection=q,e.Query=N,e.DS=te,e.belongsTo=$,e.configure=B,e.hasMany=G,e.hasOne=Q,e.setSchema=X,e.registerAdapter=Y,e.Model=ee,e.rules=be,e.validate=Z});
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t(e.JSData={})}(this,function(e){"use strict";function t(e){re(this,t),this.collection=e,this.data=null}function n(e){return e.replace(ce,"\\$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(re(this,u),e||(e=[]),!M(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;re(n,s),D(e)&&!M(e)&&(t=e,e=[]),K(t)&&(t={idAttribute:t}),e||(e=[]),t||(t={}),t.recordOpts||(t.recordOpts={}),X(n,t),X(n,pe),n._listeners={};var r=n.recordId();n.index=new u([r],{hashCode:function(e){return U(e,r)}}),n.indexes={},e.forEach(function(e){e=n.mapper?n.mapper.createRecord(e,n.recordOpts):e,n.index.insertRecord(e),e&&j(e.on)&&e.on("all",n._onRecordEvent,n)})}function f(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===he||t.type===ge))throw new Error("foreignKey is required");var o=t.localKeys,a=t.foreignKeys;if(!i&&!o&&!a&&t.type===ve)throw new Error("one of (foreignKey, localKeys, foreignKeys) is required");if(K(e)?t.relation=e:e&&(t.relation=e.name),!e||K(e)&&!j(t.getRelation))throw new Error("you must provide a reference to the related mapper!");X(n,t)}function c(e,t){var n=this;re(n,c),e||(e={}),t||(t={});var r={};Object.defineProperties(n,{_get:{value:function(e){return U(r,e)}},_set:{value:function(e,t){return B(r,e,t)}}}),n._set("creating",!0),t.noValidate&&n._set("noValidate",!0),X(n,e),n._set("creating"),n._set("changes",{}),n._set("noValidate"),n._set("previous",te(e))}function d(e){e||(e={}),X(this,e)}function l(e){var t=this;if(re(t,l),e||(e={}),X(t,e),X(t,te(Ue)),!t.name)throw new Error("mapper cannot function without a name!");t._adapters||(t._adapters={}),t._listeners||(t._listeners={}),t.schema instanceof d||(t.schema=new d(t.schema||{})),T(t.RecordClass)&&(t.RecordClass=c.extend()),t.RecordClass&&(t.RecordClass.Mapper=t)}function p(e){var t=this;re(t,p),e||(e={}),X(t,e),t.mapperDefaults=t.mapperDefaults||{},t.MapperClass=t.MapperClass||l,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=1/0,g=1.7976931348623157e308,m="[object Boolean]",y="[object Date]",b="[object Function]",x="[object Number]",A="[object Object]",w="[object RegExp]",_="[object String]",O=Object.prototype.toString,C=void 0;try{C=!!window}catch(e){C=!1}var R=function(e){return O.call(e)},E=function(e){if(!e)return 0===e?e:0;if(e=+e,e===v||e===-v){var t=0>e?-1:1;return t*g}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},M=Array.isArray,k=function(e){return e&&"object"===("undefined"==typeof e?"undefined":h.typeof(e))&&R(e)===y},j=function(e){return"function"==typeof e||e&&R(e)===b},S=function(e){return R(e)===x&&e==E(e)},N=function(e){return null===e},P=function(e){var t="undefined"==typeof e?"undefined":h.typeof(e);return"number"===t||e&&"object"===t&&R(e)===x},D=function(e){return R(e)===A},L=function(e){return R(e)===w},F=function(e){return K(e)||P(e)},K=function(e){return"string"==typeof e||e&&"object"===("undefined"==typeof e?"undefined":h.typeof(e))&&R(e)===_},T=function(e){return void 0===e},q=function(e){return R(e)===m},U=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]}},J=function(e,t){if(!t)return e;var n=t.split(".");return n.forEach(function(t){e[t]||(e[t]={}),e=e[t]}),e},$=/^(.+)\.(.+)$/,B=function e(t,n,r){if(D(n))G(n,function(n,r){e(t,r,n)});else{var i=$.exec(n);i?J(t,i[1])[i[2]]=r:t[n]=r}},G=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=function e(t,n){return n&&G(n,function(t,n){var r=this[n];I(t)&&I(r)?e(r,t):this[n]=t},t),t},z=function(e){return Promise.resolve(e)},H=function(e){return Promise.reject(e)},Q=function(e,t){for(var n in e){var r=e[n];void 0===t[n]&&!j(r)&&n&&0!==n.indexOf("_")&&(t[n]=r)}},W=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},X=function(e,t){G(t,function(t,n){e.hasOwnProperty(n)&&void 0!==e[n]||(e[n]=t)})},Y=function(e,t){if(!t||!t.length)return!1;for(var n=void 0,r=0;r<t.length;r++)if("[object RegExp]"===R(t[r])&&t[r].test(e)||t[r]===e)return n=e;return!!n},Z=function(e){return K(e)?JSON.parse(e):e},ee=JSON.stringify,te=function e(t,n,r,i,o){if(n){if(t===n)throw new Error("Cannot copy! Source and destination are identical.");if(r=r||[],i=i||[],D(t)){var a=r.indexOf(t);if(-1!==a)return i[a];r.push(t),i.push(n)}var u=void 0;if(M(t)){var s=void 0;for(n.length=0,s=0;s<t.length;s++)u=e(t[s],null,r,i,o),D(t[s])&&(r.push(t[s]),i.push(u)),n.push(u)}else{M(n)?n.length=0:G(n,function(e,t){delete n[t]});for(var f in t)if(t.hasOwnProperty(f)){if(Y(f,o))continue;u=e(t[f],null,r,i,o),D(t[f])&&(r.push(t[f]),i.push(u)),n[f]=u}}}else n=t,t&&(M(t)?n=e(t,[],r,i,o):k(t)?n=new Date(t.getTime()):L(t)?(n=new RegExp(t.source,t.toString().match(/[^\/]*$/)[0]),n.lastIndex=t.lastIndex):D(t)&&(n=e(t,Object.create(Object.getPrototypeOf(t)),r,i,o)));return n},ne=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)}}})},re=function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")},ie=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},oe=function(e,t){G(t,function(e,n){t[n]={writable:!0,value:e}}),Object.defineProperties(e,t)},ae=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(){re(this,r);for(var e=arguments.length,t=Array(e),n=0;e>n;n++)t[n]=arguments[n];var i=ie(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:G(n,function(e,t){r[t]=e}),Object.defineProperty(r,"__super__",{configurable:!0,value:n}),oe(r.prototype,e),X(r,t),r},ue=function(e,t){var n=t?e:e.constructor;return n.__super__||Object.getPrototypeOf(n)||n.__proto__},se=Object.freeze({get isBrowser(){return C},isArray:M,isDate:k,isFunction:j,isInteger:S,isNull:N,isNumber:P,isObject:D,isRegExp:L,isSorN:F,isString:K,isUndefined:T,isBoolean:q,get:U,set:B,forOwn:G,deepMixIn:V,resolve:z,reject:H,_:Q,intersection:W,fillIn:X,isBlacklisted:Y,fromJson:Z,toJson:ee,copy:te,eventify:ne,classCallCheck:re,possibleConstructorReturn:ie,addHiddenPropsToTarget:oe,extend:ae,getSuper:ue});t.extend=ae;var fe={skip:"",offset:"",where:"",limit:"",orderBy:"",sort:""},ce=/([.*+?^=!:${}()|[\]\/\\])/g,de=/%/g,le=/_/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!W(e||[],t||[]).length},isectNotEmpty:function(e,t){return W(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)}},oe(t.prototype,{compare:function(e,t,n,r){var i=e[t],o=U(n,i[0]),a=U(r,i[0]);return o&&K(o)&&(o=o.toUpperCase()),a&&K(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")?!N(this.like(r,n.substr(4)).exec(e)):0===n.indexOf("notLike")?N(this.like(r,n.substr(7)).exec(e)):void 0},like:function(e,t){return new RegExp("^"+n(e).replace(de,".*").replace(le,".")+"$",t)},getData:function(){return this.data||(this.data=this.collection.index.getAll()),this.data},between:function(e,t,n){n||(n={});var r=this.collection,i=n.index?r.indexes[n.index]:r.index;if(this.data)throw new Error("Cannot access index after first operation!");return this.data=i.between(e,t,n),this},get:function(){var e=arguments.length<=0||void 0===arguments[0]?[]:arguments[0],t=arguments[1];if(t||(t={}),this.data)throw new Error("Cannot access index after first operation!");if(e&&!M(e)&&(e=[e]),!e.length)return this.getData(),this;var n=this.collection,r=t.index?n.indexes[t.index]:n.index;return this.data=r.get(e),this},getAll:function(){var e=this,t={};if(this.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&&D(r[0]))return this.getData(),this;r.length&&D(r[r.length-1])&&(t=r[r.length-1],r.pop());var o=this.collection,a=t.index?o.indexes[t.index]:o.index;return this.data=[],r.forEach(function(t){e.data=e.data.concat(a.get(t))}),this},filter:function(e,t){var n=this;return e||(e={}),n.getData(),D(e)?!function(){var t={};D(e.where)&&(t=e.where),G(e,function(e,n){n in fe||n in t||(t[n]={"==":e})});var r=[],i=[],o=[];G(t,function(e,t){D(e)||(e={"==":e}),G(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 f=i[e],c="|"===f.charAt(0);f=c?f.substr(1):f;var d=n.evaluate(U(a,r[e]),f,o[e]);void 0!==d&&(s=u?d:c?s||d:s&&d),u=!1}return s})}();var a=e.orderBy||e.sort;K(a)&&(a=[[a,"ASC"]]),M(a)||(a=null),a&&!function(){var e=0;a.forEach(function(e,t){K(e)&&(a[t]=[e,"ASC"])}),n.data.sort(function(t,r){return n.compare(a,e,t,r)})}(),P(e.skip)?n.skip(e.skip):P(e.offset)&&n.skip(e.offset),P(e.limit)&&n.limit(e.limit)}():j(e)&&(n.data=n.data.filter(e,t)),n},skip:function(e){if(!P(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(!P(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}}),oe(u.prototype,{set:function(e,t){M(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){M(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];M(e)||(e=[e]),M(t)||(t=[t]),X(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 s=u.index;s<this.keys.length;s+=1){var f=this.keys[s];if(f>o)break;if(r=this.values[s].isIndex?f===i?r.concat(this.values[s]._between(te(e),t.map(function(){}),n)):f===o?r.concat(this.values[s]._between(e.map(function(){}),te(t),n)):r.concat(this.values[s].getAll()):r.concat(this.values[s]),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]:[]},remove:function(e,t){M(e)||(e=[e]);var n=e.shift(),r=a(this.keys,n);if(0===e.length){if(r.found){var i=a(this.values[r.index],t,this.hashCode);i.found&&(o(this.values[r.index],i.index),0===this.values[r.index].length&&(o(this.keys,r.index),o(this.values,r.index)))}}else r.found&&this.values[r.index].delete(e,t)},clear:function(){this.keys=[],this.values=[]},insertRecord:function(e){var t=this.fieldList.map(function(t){return j(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 pe={idAttribute:"id",mapper:null,onConflict:"merge",recordOpts:null};s.extend=ae,oe(s.prototype,{_onRecordEvent:function(){this.emit.apply(this,arguments)},add:function(e,t){var n=this;t||(t={}),Q(n,t),e=n.beforeAdd(e,t)||e;var r=!1,i=n.recordId();D(e)&&!M(e)&&(e=[e],r=!0),e=e.map(function(e){var r=n.recordId(e);if(!F(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?V(o,e):"replace"===a&&(G(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(n.indexes,function(t,n){t.insertRecord(e)}),e&&j(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;K(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()},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 U(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(n.indexes,function(e,t){e.removeRecord(r)}),r&&j(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={});var n=t.index?this.indexes[t.index]:this.index;n.updateRecord(e)},updateIndexes:function(e){var t=this;t.index.updateRecord(e),G(t.indexes,function(t,n){t.updateRecord(e)})}}),ne(s.prototype,function(){return this._listeners},function(e){this._listeners=e});var he="belongsTo",ve="hasMany",ge="hasOne",me=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 f(t,n);e.relationList||(e.relationList=[]),e.relationFields||(e.relationFields=[]),e.relationList.push(r),e.relationFields.push(r.localField)},ye=function(e,t){return t||(t={}),t.type=he,function(n){me(n,e,t)}},be=function(e,t){return t||(t={}),t.type=ve,function(n){me(n,e,t)}},xe=function(e,t){return t||(t={}),t.type=ge,function(n){me(n,e,t)}};c.extend=ae,oe(c.prototype,{_mapper:function(){if(!this.constructor.Mapper)throw new Error("This RecordClass has no Mapper!");return this.constructor.Mapper},get:function(e){return U(this,e)},set:function(e,t,n){var r=this;D(e)&&(n=t),n||(n={}),n.silent&&r._set("silent",!0),B(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 U(e,e._mapper().idAttribute)},changes:function(e){var t=this;return e?t._get("changes."+e):t._get("changes")},hasChanges:function(){return!!(this._get("changed")||[]).length},commit:function(){var e=this;return e._set("changed"),e._set("changes",{}),e._set("previous",te(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(t,function(r,i){i!==t._mapper().idAttribute&&!n.hasOwnProperty(i)&&t.hasOwnProperty(i)&&-1===e.preserve.indexOf(i)&&delete t[i]}),G(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={}),Q(r,e),n=e.adapter=r.getAdapterName(e),t=e.op="beforeSave",z(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",z(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={}),Q(i,t),t.adapter=i.getAdapterName(t),n=t.op="beforeLoadRelations",z(r[n](e,t)).then(function(){return K(e)&&(e=[e]),n=t.op="loadRelations",i.dbg(n,r,e,t),Promise.all(o.map(function(e){if(j(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,U(r,i.idAttribute)),t);else if(e.foreignKey){var o=U(r,e.foreignKey);F(o)&&(n=e.getRelation().find(o,t))}else e.localKeys?n=e.getRelation().findAll(h.defineProperty({},e.getRelation().idAttribute,{in:U(r,e.localKeys)}),t):e.foreignKeys&&(n=e.getRelation().findAll(h.defineProperty({},e.getRelation().idAttribute,{contains:U(r,i.idAttribute)}),t));return n&&(n=n.then(function(n){t.raw&&(n=n.data),B(r,e.localField,"hasOne"===e.type?n.length?n[0]:void 0:n)})),n}))}).then(function(){return n=t.op="afterLoadRelations",z(r[n](e,t)).then(function(){return r})})},afterLoadRelations:function(){},destroy:function(e){var t=this._mapper();return t.destroy(U(this,t.idAttribute),e)},toJSON:function(e){return this._mapper().toJSON(this,e)}}),ne(c.prototype,function(){return this._get("events")},function(e){this._set("events",e)}),d.extend=ae;var Ae={array:M,boolean:q,integer:S,null:N,number:P,object:D,string:K},we={},_e={},Oe=function(e,t){var n="";return e&&(n+=P(e)?"["+e+"]":t?"."+e:""+e),n},Ce=function(e){e||(e={});var t="",n=e.path||[];return n.forEach(function(e){t+=Oe(e,t)}),t+=Oe(e.prop,t)},Re=function(e,t,n){return{expected:t,actual:""+e,path:Ce(n)}},Ee=function(e,t,n,r){r.push(Re(e,t,n))},Ie=function(e,t,n,r){var i=n[e];return t.length>i?Re(t.length,"length no more than "+i,r):void 0},Me=function(e,t,n,r){var i=n[e];return t.length<i?Re(t.length,"length no less than "+i,r):void 0},ke=function(e,t,n,r){return!T(n[e])&&_e[e](t,n,r)},je=function(e,t,n,r){var i=[];return e.forEach(function(e){i=i.concat(ke(e,t,n,r)||[])}),i.length?i:void 0},Se=["enum","type","allOf","anyOf","oneOf","not"],Ne=["items","maxItems","minItems","uniqueItems"],Pe=["multipleOf","maximum","minimum"],De=["maxProperties","minProperties","required","properties","dependencies"],Le=["maxLength","minLength","pattern"],Fe=function(e,t,n){return je(Se,e,t,n)},Ke=function e(t,n,r){var i=[];r||(r={});var o=void 0,a=r.prop;if(!T(n)){if(!D(n))throw new Error('Invalid schema at path: "'+r.path+'"');return T(r.path)&&(r.path=[]),T(r.prop)||(o=!0,r.path.push(r.prop),r.prop=void 0),n.extends&&(i=j(n.extends.validate)?i.concat(n.extends.validate(t,r)||[]):i.concat(e(t,n.extends,r)||[])),T(t)?(n.required===!0&&Ee(t,"a value",r,i),o&&(r.path.pop(),r.prop=a),i.length?i:void 0):(i=i.concat(Fe(t,n,r)||[]),o&&(r.path.pop(),r.prop=a),i.length?i:void 0)}};d.types=Ae,d.typeGroupValidators=we,d.validationKeywords=_e,d.validate=Ke,d.prototype.validate=function(e,t){return d.validate(e,this,t)},X(_e,{allOf:function(e,t,n){var r=[];return t.allOf.forEach(function(t){r=r.concat(Ke(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=Ke(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)?Re(e,"one of ("+r.join(", ")+")",n):void 0},items:function e(t,n,r){r||(r={});for(var e=n.items,i=[],o=M(e),a=t.length,u=0;a>u;u++)o&&(e=n.items[u]),r.prop=u,i=i.concat(Ke(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)?Re(t,"no more than "+e,r):void 0},maxItems:function(e,t,n){return Ie("maxItems",e,t,n)},maxLength:function(e,t,n){return Ie("maxLength",e,t,n)},maxProperties:function e(t,n,r){var e=n.maxProperties,i=Object.keys(t).length;return i>e?Re(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)?Re(t,"no less than "+e,r):void 0},minItems:function(e,t,n){return Me("minItems",e,t,n)},minLength:function(e,t,n){return Me("minLength",e,t,n)},minProperties:function e(t,n,r){var e=n.minProperties,i=Object.keys(t).length;return e>i?Re(i,"no more than "+e+" properties",r):void 0},multipleOf:function(e,t,n){},not:function(e,t,n){return Ke(e,t.not,n)?void 0:Re("succeeded","should have failed",n)},oneOf:function(e,t,n){var r=!1,i=[];return t.oneOf.forEach(function(t){var o=Ke(e,t,n);if(o)i=i.concat(o);else{if(r)return i=[Re("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 K(t)&&!t.match(e)?Re(t,e,r):void 0},properties:function e(t,n,r){r||(r={});var i=T(n.additionalProperties)?!0:n.additionalProperties,o={},e=n.properties||{},a=n.patternProperties||{},u=[];G(t,function(e,t){o[t]=void 0}),G(e||{},function(e,n){T(t[n])&&!T(e.default)&&(t[n]=te(e.default)),r.prop=n,u=u.concat(Ke(t[n],e,r)||[]),delete o[n]}),G(a,function(e,n){G(o,function(i,a){a.match(n)&&(r.prop=a,u=u.concat(Ke(t[a],e,r)||[]),delete o[a])})});var s=Object.keys(o);return i===!1?s.length&&Ee("extra fields: "+s.join(", "),"no extra fields",r,u):D(i)&&s.forEach(function(e){r.prop=e,u=u.concat(Ke(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(T(U(t,e))){var n=r.prop;r.prop=e,Ee(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(K(e)&&(e=[e]),e.forEach(function(e){return Ae[e](t,n,r)?(i=e,!1):void 0}),!i)return Re(t?"undefined"==typeof t?"undefined":h.typeof(t):""+t,"one of ("+e.join(", ")+")",r);var o=we[i];return o?o(t,n,r):void 0},uniqueItems:function(e,t,n){if(e&&e.length&&t.uniqueItems){var r=e.length,i=void 0,o=void 0,a=void 0;for(o=r-1;o>0;o--)for(i=e[o],a=o-1;a>=0;a--)if(i===e[a])return Re(i,"no duplicates",n)}}}),X(we,{array:function(e,t,n){return je(Ne,e,t,n)},integer:function(e,t,n){return we.numeric(e,t,n)},number:function(e,t,n){return we.numeric(e,t,n)},numeric:function(e,t,n){return je(Pe,e,t,n)},object:function(e,t,n){return je(De,e,t,n)},string:function(e,t,n){return je(Le,e,t,n)}});var Te=z,qe=function(){for(var e=arguments.length,t=Array(e),n=0;e>n;n++)t[n]=arguments[n];var r=this,i=t.pop();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))})},Ue={_adapters:null,_listeners:null,defaultAdapter:"http",debug:!1,idAttribute:"id",name:null,notify:!0,raw:!1,RecordClass:void 0,schema:null,upsert:!0};oe(l.prototype,{end:function(e,t){var n=this;t.raw&&Q(t,e);var r=t.raw?e.data:e;return r=M(r)?r.map(function(e){return n.createRecord(e)}):n.createRecord(r),t.raw?e.data=r:e=r,t.notify&&setTimeout(function(){n.emit(t.op,e,t)}),e},createRecord:function(e,t){var n=this.RecordClass;return n?e instanceof n?e:new n(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=e;return n.is(e)&&(r=te(e),n&&n.relationList&&t.with&&(K(t.with)&&(t.with=[t.with]),n.relationList.forEach(function(n){var i=void 0;-1!==t.with.indexOf(n.relation)?i=n.relation:-1!==t.with.indexOf(n.localField)&&(i=n.localField),i&&!function(){var o={with:t.with.slice()};o.with.splice(o.with.indexOf(i),1),o.with.forEach(function(e,t){e&&0===e.indexOf(i)&&e.length>=i.length&&"."===e[i.length]?o.with[t]=e.substr(i.length+1):o.with[t]=""});var a=U(e,n.localField);a&&(M(a)?B(r,n.localField,a.map(function(e){return n.getRelation().toJSON(e,o)})):B(r,n.localField,n.getRelation().toJSON(a,o)))}()}))),r},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={}),K(e)&&(e={adapter:e}),e.adapter||e.defaultAdapter},getAdapters:function(){return this._adapters},getSchema:function(){return this.schema},beforeCreate:qe,checkUpsertCreate:function(e,t){var n=this;return(t.upsert||void 0===t.upsert&&n.upsert)&&U(e,n.idAttribute)},create:function(e,t){var n=void 0,r=void 0,i=this;return e||(e={}),t||(t={}),i.checkUpsertCreate(e,t)?i.update(U(e,i.idAttribute),e,t):(Q(i,t),r=t.adapter=i.getAdapterName(t),n=t.op="beforeCreate",Te(i[n](e,t)).then(function(o){e=o||e,n=t.op="create";var a=i.toJSON(e,t);return i.dbg(n,a,t),Te(i.getAdapter(r)[n](i,a,t))}).then(function(e){return n=t.op="afterCreate",Te(i[n](e,t)).then(function(n){return e=n||e,i.end(e,t)})}))},afterCreate:qe,beforeCreateMany:qe,checkUpsertCreateMany:function(e,t){var n=this;return t.upsert||void 0===t.upsert&&n.upsert?e.reduce(function(e,t){return e&&U(t,n.idAttribute)},!0):void 0},createMany:function(e,t){var n=void 0,r=void 0,i=this;return e||(e=[]),t||(t={}),i.checkUpsertCreateMany(e,t)?i.updateMany(e,t):(Q(i,t),r=t.adapter=i.getAdapterName(t),n=t.op="beforeCreateMany",Te(i[n](e,t)).then(function(o){e=o||e,n=t.op="createMany";var a=e.map(function(e){return i.toJSON(e,t)});return i.dbg(n,a,t),Te(i.getAdapter(r)[n](i,a,t))}).then(function(e){return n=t.op="afterCreateMany",Te(i[n](e,t)).then(function(n){return e=n||e,i.end(e,t)})}))},afterCreateMany:qe,beforeFind:qe,find:function(e,t){var n=void 0,r=void 0,i=this;return t||(t={}),Q(i,t),r=t.adapter=i.getAdapterName(t),n=t.op="beforeFind",Te(i[n](e,t)).then(function(o){return e=void 0===o?e:o,n=t.op="find",i.dbg(n,e,t),Te(i.getAdapter(r)[n](i,e,t))}).then(function(e){return n=t.op="afterFind",Te(i[n](e,t)).then(function(n){return e=n||e,i.end(e,t)})})},afterFind:qe,beforeFindAll:qe,findAll:function(e,t){var n=void 0,r=void 0,i=this;return e||(e={}),t||(t={}),Q(i,t),r=t.adapter=i.getAdapterName(t),n=t.op="beforeFindAll",Te(i[n](e,t)).then(function(o){return e=o||e,n=t.op="findAll",i.dbg(n,e,t),Te(i.getAdapter(r)[n](i,e,t))}).then(function(r){return n=t.op="afterFindAll",Te(i[n](r,e,t)).then(function(e){return r=e||r,i.end(r,t)})})},afterFindAll:qe,beforeUpdate:qe,update:function(e,t,n){var r=void 0,i=void 0,o=this;return t||(t={}),n||(n={}),Q(o,n),i=n.adapter=o.getAdapterName(n),r=n.op="beforeUpdate",Te(o[r](e,t,n)).then(function(a){t=a||t,r=n.op="update";var u=o.toJSON(t,n);return o.dbg(r,e,u,n),Te(o.getAdapter(i)[r](o,e,u,n))}).then(function(t){return r=n.op="afterUpdate",Te(o[r](e,t,n)).then(function(e){return t=e||t,o.end(t,n)})})},afterUpdate:qe,beforeUpdateMany:qe,updateMany:function(e,t){var n=void 0,r=void 0,i=this;return e||(e=[]),t||(t={}),Q(i,t),r=t.adapter=i.getAdapterName(t),n=t.op="beforeUpdateMany",Te(i[n](e,t)).then(function(o){e=o||e,n=t.op="updateMany";var a=e.map(function(e){return i.toJSON(e,t)});return i.dbg(n,a,t),Te(i.getAdapter(r)[n](i,a,t))}).then(function(e){return n=t.op="afterUpdateMany",Te(i[n](e,t)).then(function(n){return e=n||e,i.end(e,t)})})},afterUpdateMany:qe,beforeUpdateAll:qe,updateAll:function(e,t,n){var r=void 0,i=void 0,o=this;return e||(e={}),t||(t={}),n||(n={}),Q(o,n),i=n.adapter=o.getAdapterName(n),r=n.op="beforeUpdateAll",Te(o[r](e,t,n)).then(function(a){t=a||t,r=n.op="updateAll";var u=o.toJSON(t,n);return o.dbg(r,e,u,n),Te(o.getAdapter(i)[r](o,e,u,n))}).then(function(t){return r=n.op="afterUpdateAll",Te(o[r](e,t,n)).then(function(e){return t=e||t,o.end(t,n)})})},afterUpdateAll:qe,beforeDestroy:qe,destroy:function(e,t){var n=void 0,r=void 0,i=this;return t||(t={}),Q(i,t),r=t.adapter=i.getAdapterName(t),n=t.op="beforeDestroy",Te(i[n](e,t)).then(function(o){return e=void 0===o?e:o,n=t.op="destroy",i.dbg(n,e,t),Te(i.getAdapter(r)[n](i,e,t))}).then(function(e){return n=t.op="afterDestroy",Te(i[n](e,t)).then(function(n){return e=n||e,t.raw?(Q(t,e),e):e})})},afterDestroy:qe,beforeDestroyAll:qe,destroyAll:function(e,t){var n=void 0,r=void 0,i=this;return e||(e={}),
t||(t={}),Q(i,t),r=t.adapter=i.getAdapterName(t),n=t.op="beforeDestroyAll",Te(i[n](e,t)).then(function(o){return e=o||e,n=t.op="destroyAll",i.dbg(n,e,t),Te(i.getAdapter(r)[n](i,e,t))}).then(function(r){return n=t.op="afterDestroyAll",Te(i[n](r,e,t)).then(function(e){return r=e||r,t.raw?(Q(t,r),r):r})})},afterDestroyAll:qe,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 ye(e,t)(this)},hasMany:function(e,t){return be(e,t)(this)},hasOne:function(e,t){return xe(e,t)(this)},registerAdapter:function(e,t,n){var r=this;n||(n={}),r.getAdapters()[e]=t,(n===!0||n.default)&&(r.defaultAdapter=e)}}),l.extend=ae,ne(l.prototype,function(){return this._listeners},function(e){this._listeners=e}),p.extend=ae,oe(p.prototype,{create:function(e,t,n){var r=this;return n||(n={}),X(n,r.modelOpts),r.getMapper(e).create(t,n)},createMany:function(e,t,n){var r=this;return n||(n={}),X(n,r.modelOpts),r.getMapper(e).createMany(t,n)},createRecord:function(e,t,n){return this.getMapper(e).createRecord(t,n)},defineMapper:function(e,t){var n=this;if(D(e)){if(t=e,!t.name)throw new Error("name is required!");e=t.name}else if(!K(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,X(t,n.mapperDefaults);var i=n._mappers[e]=new r(t);return i.name=e,i._adapters=n.getAdapters(),G(i.relations,function(e,t){G(e,function(e,r){D(e)&&(e=[e]),e.forEach(function(e){e.getRelation=function(){return n.getMapper(r)};var o=n._mappers[r]||r;t===he?i.belongsTo(o,e):t===ge?i.hasOne(o,e):t===ve&&i.hasMany(o,e)})})}),i},destroy:function(e,t,n){var r=this;return n||(n={}),X(n,r.modelOpts),r.getMapper(e).destroy(t,n)},destroyAll:function(e,t,n){var r=this;return n||(n={}),X(n,r.modelOpts),r.getMapper(e).destroyAll(t,n)},find:function(e,t,n){var r=this;return n||(n={}),X(n,r.modelOpts),r.getMapper(e).find(t,n)},findAll:function(e,t,n){var r=this;return n||(n={}),X(n,r.modelOpts),r.getMapper(e).findAll(t,n)},getAdapterName:function(e){return e||(e={}),K(e)&&(e={adapter:e}),e.adapter||this.mapperDefaults.defaultAdapter},getAdapter:function(e){var t=this,n=t.getAdapterName(e);if(!n)throw new ReferenceError(n+" not found!");return t.getAdapters()[n]},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(r._mappers,function(t){t.defaultAdapter=e}))},update:function(e,t,n,r){var i=this;return r||(r={}),X(r,i.modelOpts),i.getMapper(e).update(t,n,r)},updateAll:function(e,t,n,r){var i=this;return r||(r={}),X(r,i.modelOpts),i.getMapper(e).updateAll(t,n,r)},updateMany:function(e,t,n){var r=this;return n||(n={}),X(n,r.modelOpts),r.getMapper(e).updateMany(t,n)}});var Je=s.extend({constructor:function(e,t){var n=this;if(re(n,Je),ue(n).call(n,e,t),n._added={},!n.datastore)throw new Error("This collection must have a datastore!");return n},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 D(e)&&!M(e)&&(s=!0,e=[e]),o.length&&e.length&&i.relationList.forEach(function(t){var n=t.relation,o=r.getMapper(n),a=o.idAttribute,u=t.foreignKey,s=t.localField,f=r.getCollection(n),c=t.type,d=c===he,l=c===ve,p=c===ge,h=i.idAttribute,v=T(t.add)?!0:!!t.add,g=void 0;e.forEach(function(e){g=U(e,s),j(t.add)?t.add(r,t,e):g&&!function(){var n=U(e,h);if(l)g=g.map(function(e){return e!==f.get(f.recordId(e))&&(u&&B(e,u,n),v&&(e=f.add(e))),e}),t.localKeys&&B(e,t.localKeys,g.map(function(e){return U(e,a)}));else{var r=U(g,a);g!==f.get(r)&&(d?B(e,u,r):p&&B(g,u,n),v&&(g=f.add(g)))}B(e,s,g)}()})}),e=ue(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=ue(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=ue(n).prototype.removeAll.call(n,e,t);return r.forEach(function(e){delete n._added[n.recordId(e)]}),r}});Je.extend=ae;var $e={linkRelations:C},Be=p.extend({constructor:function(e){var t=this;return re(t,Be),ue(t).call(t,e),t.CollectionClass=t.CollectionClass||Je,t._collections={},X(t,$e),t},_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={}),ue(r).create(e,t,n).then(function(t){return r._end(e,t,n)})},createMany:function(e,t,n){var r=this;return n||(n={}),ue(r).createMany(e,t,n).then(function(t){return r._end(e,t,n)})},defineMapper:function(e,t){var n=this,r=ue(n).prototype.defineMapper.call(n,e,t);r.relationList=r.relationList||[];var i=n._collections[e]=new n.CollectionClass(null,{_added:{},datastore:n,mapper:r});i.createIndex("addedTimestamps",["$"],{fieldGetter:function(e){return i._added[i.recordId(e)]}});var o=n.linkRelations;return o&&r.relationList.forEach(function(e){var a=e.relation,u=e.localField,s="links."+u,f=e.foreignKey,c=e.type,d=T(e.link)?o:e.link,l={index:f},p=void 0;c===he?(i.indexes[f]||i.createIndex(f),p={get:function(){var e=this;if(!e._get("$")||!d)return e._get(s);var t=U(e,f),r=T(t)?void 0:n.getCollection(a).get(t);return e._set(s,r),r},set:function(e){var t=this;return t._set(s,e),B(t,f,n.getCollection(a).recordId(e)),i.updateIndex(t,l),U(t,u)}}):c===ve?!function(){var t=e.localKeys,r=e.foreignKeys;n._collections[a]&&f&&!n.getCollection(a).indexes[f]&&n.getCollection(a).createIndex(f),p={get:function(){var e=this;if(!e._get("$")||!d)return e._get(s);var o=i.recordId(e),u=void 0,c=n.getCollection(a);if(f)u=c.getAll(o,{index:f});else if(t){var l=U(e,t)||[],p=M(l)?l:Object.keys(l);u=c.getAll.apply(c,p)}else if(r){var h={};B(h,"where."+r+".contains",o),u=c.filter(h)}return e._set(s,u),u},set:function(e){var o=this,c=i.recordId(o),d=n.getCollection(a);return o._set(s,e),f&&e.forEach(function(e){B(e,f,c),d.updateIndex(e,l)}),t?B(o,t,e.map(function(e){return d.recordId(e)})):r&&e.forEach(function(e){var t=U(e,r);t?-1===t.indexOf(c)&&t.push(c):B(e,r,[c])}),U(o,u)}}}():c===ge&&(p={get:function(){var e=this;if(!e._get("$")||!d)return e._get(s);var t=i.recordId(e),r=n.getCollection(a).getAll(t,{index:f}),o=r.length?r[0]:void 0;return e._set(s,o),o},set:function(e){var t=this,r=i.recordId(t);return t._set(s,e),B(e,f,r),n.getCollection(a).updateIndex(e,l),U(t,u)}}),p&&(p.enumerable=T(e.enumerable)?!0:e.enumerable,e.get&&!function(){var t=p.get;p.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)})}}(),t.set&&!function(){var t=p.set;p.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,u,p))}),r},destroy:function(e,t,n){var r=this;return n||(n={}),ue(r).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),i})},destroyAll:function(e,t,n){var r=this;return n||(n={}),ue(r).destroyAll(e,t,n).then(function(i){return n.raw?i.data=r.getCollection(e).removeAll(t,n):i=r.getCollection(e).removeAll(t,n),i})},find:function(e,t,n){var r=this;return n||(n={}),ue(r).find(e,t,n).then(function(t){return r._end(e,t,n)})},findAll:function(e,t,n){var r=this;return n||(n={}),ue(r).findAll(e,t,n).then(function(t){return r._end(e,t,n)})},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={}),ue(i).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={}),ue(i).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={}),ue(r).updateMany(t,n).then(function(t){return r._end(e,t,n)})}});Be.prototype.defineResource=Be.prototype.defineMapper,Be.extend=ae;var Ge=["add","between","createIndex","filter","get","getAll","query","remove","removeAll","toJson"],Ve={};Ge.forEach(function(e){Ve[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)}}),Ve.inject=function(){return console.warn("deprecated"),this.add.apply(this,arguments)},oe(Be.prototype,Ve);var ze={full:"<%= pkg.version %>",major:parseInt("<%= major %>",10),minor:parseInt("<%= minor %>",10),patch:parseInt("<%= patch %>",10),alpha:"<%= alpha %>",beta:"<%= beta %>"},He=Be;e.Collection=s,e.Container=p,e.DataStore=Be,e.DS=He,e.LinkedCollection=Je,e.Mapper=l,e.Query=t,e.Record=c,e.Schema=d,e.utils=se,e.version=ze,e.belongsToType=he,e.hasManyType=ve,e.hasOneType=ge,e.belongsTo=ye,e.hasMany=be,e.hasOne=xe});
//# sourceMappingURL=dist/js-data.min.map
{
"name": "js-data",
"description": "Robust, framework-agnostic in-memory data store.",
"version": "3.0.0-alpha.10",
"version": "3.0.0-alpha.12",
"homepage": "http://www.js-data.io",

@@ -29,7 +29,2 @@ "repository": {

"globals": [
"babelHelpers",
"__callCheck__",
"__get__",
"__inherits__",
"__possibleConstructorReturn__",
"describe",

@@ -47,3 +42,3 @@ "it",

"rollup-tests": "rollup -c rollup-tests.config.js",
"doc": "jsdoc -c conf.json src",
"doc": "jsdoc -c conf.json src && node scripts/cleanup.js",
"lint": "standard src/**/*.js test/**/*.js",

@@ -63,22 +58,22 @@ "helpers": "node scripts/helpers.js",

"test": "npm run build && npm run rollup-tests && npm run cover",
"ci": "npm test && cat coverage/lcov.info | coveralls || true && cat ./coverage/lcov.info | codacy-coverage || true"
"ci": "npm test && cat coverage/lcov.info | coveralls || true && cat ./coverage/lcov.info | codacy-coverage || true; npm run doc"
},
"devDependencies": {
"babel-core": "6.4.0",
"babel-eslint": "4.1.6",
"babel-core": "6.4.5",
"babel-eslint": "4.1.8",
"babel-plugin-syntax-async-functions": "6.3.13",
"babel-plugin-transform-regenerator": "6.3.26",
"babel-plugin-transform-regenerator": "6.4.4",
"babel-polyfill": "6.3.14",
"babel-preset-es2015-rollup": "1.0.0",
"babel-preset-es2015-rollup": "1.1.1",
"babel-preset-stage-0": "6.3.13",
"chai": "3.4.1",
"chai": "3.5.0",
"codacy-coverage": "1.1.3",
"coveralls": "2.11.6",
"ink-docstrap": "1.1.0",
"istanbul": "0.4.1",
"ink-docstrap": "1.1.1",
"istanbul": "0.4.2",
"jsdoc": "3.4.0",
"mocha": "2.3.4",
"rollup": "0.22.0",
"rollup-plugin-babel": "2.2.0",
"sinon": "1.17.2",
"mocha": "2.4.5",
"rollup": "0.25.2",
"rollup-plugin-babel": "2.3.9",
"sinon": "1.17.3",
"source-map-support": "0.4.0",

@@ -85,0 +80,0 @@ "standard": "5.4.1",

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

JSData is a datastore-agnostic ORM for Node.js and the Browser.
JSData is a framework-agnostic, datastore-agnostic ORM/ODM for Node.js and the
Browser.
Adapters allow JSData to connect to various datastores such as Firebase, MySql,
Adapters allow JSData to connect to various data sources such as Firebase, MySql,
RethinkDB, MongoDB, localStorage, Redis, a REST API, etc. With JSData you can

@@ -20,6 +21,5 @@ re-use your Models between environments, keep your data layer intact when

server and the client. JSData employs conventions for rapid development, but
allows for endless customization in order to meet your particular needs. Think
of it as the "Twitter Bootstrap" of JavaScript data layers.
allows for endless customization in order to meet your particular needs.
To get started, check out <http://js-data.io>!
For Getting Started guides, visit __[http://js-data.io](http://www.js-data.io)__!

@@ -31,4 +31,4 @@ ## Table of contents

* [Dependencies](#dependencies)
* [Documentation](#documentation)
* [API Reference](#api-reference)
* [Guides & Tutorials](#documentation)
* [API Reference Docs](#api-reference)
* [Support](#support)

@@ -41,86 +41,49 @@ * [Community](#community)

##### js-data + http adapter in the Browser
This example shows setting up JSData to use the Http adapter in the browser:
`npm install --save js-data js-data-http` or `bower install --save js-data js-data-http`.
```
npm i --save js-data js-data-http
```
(Substitute `js-data-http` for any one of the other client-side adapters.)
##### js-data + http adapter in Node.js
`npm install --save js-data axios js-data-http-node`
(Substitute `axios` and `js-data-http-node` for any one of the other server-side adapters.)
See [installation instructions][inst] for making JSData part of your
r.js/browserify/webpack build.
__ES2016:__
```javascript
import {Collection, Model, registerAdapter} from 'js-data'
import DSHttpAdapter from 'js-data-http'
import {DataStore} from 'js-data'
import HttpAdapter from 'js-data-http'
// "User" will use an http adapter by default
@registerAdapter('http', new DSHttpAdapter(), { default: true })
class User extends Model {}
const UserCollection = new Collection({ model: User })
// Create an empty data store
const store = new DataStore()
let user = await UserCollection.find(1)
// "store" will use an http adapter by default
store.registerAdapter('http', new HttpAdapter(), { 'default': true })
console.log(user) // { id: 1, name: 'John' }
console.log(user instanceof User) // true
// Define a new Mapper for a "user" resource
store.defineMapper('user')
// Get a reference to the store's "user" collection
const Users = store.getCollection('user')
// The user instance is now stored in UserCollection
console.log(UserCollection.get(user.id)) // { id: 1, name: 'John' }
console.log(user === UserCollection.get(user.id)) // true
async function showExample () {
let user = await store.find('user', 1)
user.name = 'Johnny'
console.log(user) // { id: 1, name: 'John' }
// PUT /user/1 {name:"Johnny"}
user = await user.save()
// The user record is now stored in Users
console.log(Users.get(user.id)) // { id: 1, name: 'John' }
console.log(user === Users.get(user.id)) // true
// The user instance has been updated
console.log(UserCollection.get(user.id)) // { id: 1, name: 'Johnny' }
console.log(user === UserCollection.get(user.id)) // true
user.name = 'Johnny'
await user.destroy()
// PUT /user/1 {name:"Johnny"}
user = await user.save()
// The user instance no longer stored in UserCollection
console.log(UserCollection.get(1)) // undefined
```
// The user record has been updated
console.log(Users.get(user.id)) // { id: 1, name: 'Johnny' }
console.log(user === Users.get(user.id)) // true
__ES2015:__
await user.destroy()
```javascript
import {Collection, Model, registerAdapter} from 'js-data'
import DSHttpAdapter from 'js-data-http'
class User extends Model {}
const UserCollection = new Collection({ model: User })
// "User" will use an http adapter by default
User.registerAdapter('http', new DSHttpAdapter(), { default: true })
let user = yield UserCollection.find(1)
console.log(user) // { id: 1, name: 'John' }
console.log(user instanceof User) // true
// The user instance is now stored in UserCollection
console.log(UserCollection.get(user.id)) // { id: 1, name: 'John' }
console.log(user === UserCollection.get(user.id)) // true
user.name = 'Johnny'
// PUT /user/1 {name:"Johnny"}
user = yield user.save()
// The user instance has been updated
console.log(UserCollection.get(user.id)) // { id: 1, name: 'Johnny' }
console.log(user === UserCollection.get(user.id)) // true
yield user.destroy()
// The user instance no longer stored in UserCollection
console.log(UserCollection.get(1)) // undefined
// The user instance no longer stored in Users
console.log(Users.get(1)) // undefined
}
```

@@ -131,16 +94,20 @@

```javascript
var User = JSData.Model.extend({}, { name: 'User' })
var UserCollection = new JSData.Collection({ model: User })
// register and use http by default for async operations
User.registerAdapter('http', new DSHttpAdapter(), { default: true });
// Create an empty data store
var store = new JSData.DataStore()
// Example CRUD operations with default configuration
UserCollection.find(1)
// "store" will use an http adapter by default
store.registerAdapter('http', new HttpAdapter(), { default: true })
// Define a new Mapper for a "user" resource
store.defineMapper('user')
// Get a reference to the store's "user" collection
var Users = store.getCollection('user')
store.find('user', 1)
.then(function (user) {
console.log(user) // { id: 1, name: 'John' }
console.log(user instanceof User) // true
// The user instance is now stored in UserCollection
console.log(UserCollection.get(user.id)) // { id: 1, name: 'John' }
console.log(user === UserCollection.get(user.id)) // true
// The user record is now stored in Users
console.log(Users.get(user.id)) // { id: 1, name: 'John' }
console.log(user === Users.get(user.id)) // true

@@ -153,12 +120,11 @@ user.name = 'Johnny'

.then(function (user) {
// The user instance has been updated
console.log(UserCollection.get(user.id)) // { id: 1, name: 'Johnny' }
console.log(user === UserCollection.get(user.id)) // true
// The user record has been updated
console.log(Users.get(user.id)) // { id: 1, name: 'Johnny' }
console.log(user === Users.get(user.id)) // true
// DELETE /user/1
return user.destroy()
})
.then(function () {
// The user instance no longer stored in UserCollection
console.log(UserCollection.get(1)) // undefined
// The user instance no longer stored in Users
console.log(Users.get(1)) // undefined
})

@@ -169,6 +135,6 @@ ```

Most ORMs only work with a single datastore. Even when written in JavaScript,
most ORMs only work in Node.js _or_ the Browser. Wouldn't it be nice if you
could use the same ORM on the client as you do on the backend? Wouldn't it be
nice if you could switch databases without having to switch ORMs? Enter
Most ORMs/ODMs only work with a single datastore, most JavaScript ORMs only work
in Node.js _or_ the Browser. Wouldn't it be nice if you could use the same
ORM/ODM on the client as you do on the backend? Wouldn't it be nice if you could
switch databases without having to switch out your data layer code? Enter
__JSData__.

@@ -185,6 +151,6 @@

connecting your frontend to your backend. [localStorage][3], [localForage][4],
[Firebase][5] and [other adapters][6] are already available. On the server you
could hook up to the [SQL adapter (Postgres/MySQL/MariaDB/SQLite3)][7] or the
[MongoDB][8] adapter. More adapters are coming, and you're free to implement
your own. See [Adapters][9].
[Firebase][5] and [other adapters][6] are available for the browser. On the
server you could hook up to the [SQL adapter (Postgres/MySQL/MariaDB/SQLite3)][7]
or the [MongoDB][8] adapter. More adapters are coming, and you're free to
implement your own. See [Adapters][9].

@@ -203,3 +169,4 @@ [![MtnWestJS Conf 2015 Presentation][mtn_b]][mtn_l]

## Documentation
## Guides & Tutorials
- [Main Site](http://www.js-data.io)
- [Getting Started with js-data](http://www.js-data.io/docs/home)

@@ -220,18 +187,8 @@ - [Resources/Models](http://www.js-data.io/docs/resources)

See an issue with the documentation? Have something to add? Click the "Suggest
Edits" at the top right of each page and make your suggested changes!
Edits" button at the top right of each page and make your suggested changes!
## API Reference
- [DS](http://www.js-data.io/docs/ds)
- [Configuration Options](http://www.js-data.io/docs/dsdefaults)
- [DSFirebaseAdapter](http://www.js-data.io/docs/dsfirebaseadapter)
- [DSHttpAdapter](http://www.js-data.io/docs/dshttpadapter)
- [DSLevelUpAdapter](http://www.js-data.io/docs/dslevelupadapter)
- [DSLocalForageAdapter](http://www.js-data.io/docs/dslocalforageadapter)
- [DSLocalStorageAdapter](http://www.js-data.io/docs/dslocalstorageadapter)
- [DSMongoDBAdapter](http://www.js-data.io/docs/dsmongodbadapter)
- [DSNeDBAdapter](http://www.js-data.io/docs/dsnedbadapter)
- [DSRedisAdapter](http://www.js-data.io/docs/dsredisadapter)
- [DSRethinkDBAdapter](http://www.js-data.io/docs/dsrethinkdbadapter)
- [DSSqlAdapter](http://www.js-data.io/docs/dssqladapter)
- [js-data-schema](http://www.js-data.io/docs/js-data-schema)
## API Reference Docs
- [all](http://api.js-data.io/)
- [js-data](http://api.js-data.io/js-data)
- [js-data-http](http://api.js-data.io/js-data-http)

@@ -270,3 +227,4 @@ ## Support

1. `git clone git@github.com:<you>/js-data.git`
1. `cd js-data; npm install;`
1. `cd js-data`
1. `npm install`
1. Write your code, including relevant documentation and tests

@@ -335,2 +293,2 @@ 1. Run `npm test` (build and test)

[ml]: https://groups.io/org/groupsio/jsdata
[so]: http://stackoverflow.com/questions/tagged/jsdata
[so]: http://stackoverflow.com/questions/tagged/jsdata

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

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

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

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc