-
Notifications
You must be signed in to change notification settings - Fork 15
/
Copy pathbackbone-orm.min.js
12 lines (12 loc) · 138 KB
/
backbone-orm.min.js
1
2
3
4
5
6
7
8
9
10
11
12
/*
backbone-orm.js 0.7.13
Copyright (c) 2013-2016 Vidigami
License: MIT (http://www.opensource.org/licenses/mit-license.php)
Source: https://github.com/vidigami/backbone-orm
Dependencies: Backbone.js and Underscore.js.
*/
!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t(require("underscore"),require("backbone"),function(){try{return require("stream")}catch(e){}}()):"function"==typeof define&&define.amd?define(["underscore","backbone"],function(r,n){return t(r,n,e.stream)}):"object"==typeof exports?exports.BackboneORM=t(require("underscore"),require("backbone"),function(){try{return require("stream")}catch(e){}}()):e.BackboneORM=t(e._,e.Backbone,e.stream)}(this,function(e,t,r){return function(e){function t(n){if(r[n])return r[n].exports;var i=r[n]={exports:{},id:n,loaded:!1};return e[n].call(i.exports,i,i.exports,t),i.loaded=!0,i.exports}var r={};return t.m=e,t.c=r,t.p="",t(0)}([function(e,t,r){var n,i,o,s;o=r(1),n=r(2),e.exports=i=r(3),s={configure:r(4),sync:r(47),Utils:r(24),JSONUtils:r(33),DateUtils:r(40),TestUtils:r(48),Queue:r(11),DatabaseURL:r(32),Fabricator:r(49),MemoryStore:r(12),Cursor:r(42),Schema:r(43),ConnectionPool:r(50),BaseConvention:r(7),_:o,Backbone:n},o.extend(i,s),r(51),i.modules={underscore:o,backbone:n,url:r(25),querystring:r(27),"lru-cache":r(13),inflection:r(6)};try{i.modules.stream=r(37)}catch(a){}},function(t,r){t.exports=e},function(e,r){e.exports=t},function(e,t){e.exports={}},function(e,t,r){var n,i,o;o=r(1),i=r(3),n={"default":r(5),underscore:r(5),camelize:r(8),classify:r(9)},i.naming_conventions=n["default"],i.model_cache=new(r(10)),e.exports=function(e){var t,r,s,a;null==e&&(e={}),s=[];for(r in e)switch(a=e[r],r){case"model_cache":s.push(i.model_cache.configure(e.model_cache));break;case"naming_conventions":if(o.isString(a)){if(t=n[a]){i.naming_conventions=t;continue}s.push(console.log("BackboneORM configure: could not find naming_conventions: "+a+". Available: "+o.keys(n).join(", ")))}else s.push(i.naming_conventions=a);break;default:s.push(i[r]=a)}return s}},function(e,t,r){var n,i,o,s=function(e,t){function r(){this.constructor=e}for(var n in t)a.call(t,n)&&(e[n]=t[n]);return r.prototype=t.prototype,e.prototype=new r,e.__super__=t.prototype,e},a={}.hasOwnProperty;o=r(6),n=r(7),e.exports=i=function(e){function t(){return t.__super__.constructor.apply(this,arguments)}return s(t,e),t.attribute=function(e,t){return o[t?"pluralize":"singularize"](o.underscore(e))},t}(n)},function(e,t,r){var n,i,o;!function(r,s){i=[],n=s,o="function"==typeof n?n.apply(t,i):n,!(void 0!==o&&(e.exports=o))}(this,function(){var e=["accommodation","adulthood","advertising","advice","aggression","aid","air","aircraft","alcohol","anger","applause","arithmetic","assistance","athletics","bacon","baggage","beef","biology","blood","botany","bread","butter","carbon","cardboard","cash","chalk","chaos","chess","crossroads","countryside","dancing","deer","dignity","dirt","dust","economics","education","electricity","engineering","enjoyment","envy","equipment","ethics","evidence","evolution","fame","fiction","flour","flu","food","fuel","fun","furniture","gallows","garbage","garlic","genetics","gold","golf","gossip","grammar","gratitude","grief","guilt","gymnastics","happiness","hardware","harm","hate","hatred","health","heat","help","homework","honesty","honey","hospitality","housework","humour","hunger","hydrogen","ice","importance","inflation","information","innocence","iron","irony","jam","jewelry","judo","karate","knowledge","lack","laughter","lava","leather","leisure","lightning","linguine","linguini","linguistics","literature","litter","livestock","logic","loneliness","luck","luggage","macaroni","machinery","magic","management","mankind","marble","mathematics","mayonnaise","measles","methane","milk","money","mud","music","mumps","nature","news","nitrogen","nonsense","nurture","nutrition","obedience","obesity","oxygen","pasta","patience","physics","poetry","pollution","poverty","pride","psychology","publicity","punctuation","quartz","racism","relaxation","reliability","research","respect","revenge","rice","rubbish","rum","safety","scenery","seafood","seaside","series","shame","sheep","shopping","sleep","smoke","smoking","snow","soap","software","soil","spaghetti","species","steam","stuff","stupidity","sunshine","symmetry","tennis","thirst","thunder","timber","traffic","transportation","trust","underwear","unemployment","unity","validity","veal","vegetation","vegetarianism","vengeance","violence","vitality","warmth","wealth","weather","welfare","wheat","wildlife","wisdom","yoga","zinc","zoology"],t={plural:{men:new RegExp("^(m|wom)en$","gi"),people:new RegExp("(pe)ople$","gi"),children:new RegExp("(child)ren$","gi"),tia:new RegExp("([ti])a$","gi"),analyses:new RegExp("((a)naly|(b)a|(d)iagno|(p)arenthe|(p)rogno|(s)ynop|(t)he)ses$","gi"),hives:new RegExp("(hi|ti)ves$","gi"),curves:new RegExp("(curve)s$","gi"),lrves:new RegExp("([lr])ves$","gi"),foves:new RegExp("([^fo])ves$","gi"),movies:new RegExp("(m)ovies$","gi"),aeiouyies:new RegExp("([^aeiouy]|qu)ies$","gi"),series:new RegExp("(s)eries$","gi"),xes:new RegExp("(x|ch|ss|sh)es$","gi"),mice:new RegExp("([m|l])ice$","gi"),buses:new RegExp("(bus)es$","gi"),oes:new RegExp("(o)es$","gi"),shoes:new RegExp("(shoe)s$","gi"),crises:new RegExp("(cris|ax|test)es$","gi"),octopi:new RegExp("(octop|vir)i$","gi"),aliases:new RegExp("(alias|canvas|status)es$","gi"),summonses:new RegExp("^(summons)es$","gi"),oxen:new RegExp("^(ox)en","gi"),matrices:new RegExp("(matr)ices$","gi"),vertices:new RegExp("(vert|ind)ices$","gi"),feet:new RegExp("^feet$","gi"),teeth:new RegExp("^teeth$","gi"),geese:new RegExp("^geese$","gi"),quizzes:new RegExp("(quiz)zes$","gi"),whereases:new RegExp("^(whereas)es$","gi"),criteria:new RegExp("^(criteri)a$","gi"),ss:new RegExp("ss$","gi"),s:new RegExp("s$","gi")},singular:{man:new RegExp("^(m|wom)an$","gi"),person:new RegExp("(pe)rson$","gi"),child:new RegExp("(child)$","gi"),ox:new RegExp("^(ox)$","gi"),axis:new RegExp("(ax|test)is$","gi"),octopus:new RegExp("(octop|vir)us$","gi"),alias:new RegExp("(alias|status|canvas)$","gi"),summons:new RegExp("^(summons)$","gi"),bus:new RegExp("(bu)s$","gi"),buffalo:new RegExp("(buffal|tomat|potat)o$","gi"),tium:new RegExp("([ti])um$","gi"),sis:new RegExp("sis$","gi"),ffe:new RegExp("(?:([^f])fe|([lr])f)$","gi"),hive:new RegExp("(hi|ti)ve$","gi"),aeiouyy:new RegExp("([^aeiouy]|qu)y$","gi"),x:new RegExp("(x|ch|ss|sh)$","gi"),matrix:new RegExp("(matr)ix$","gi"),vertex:new RegExp("(vert|ind)ex$","gi"),mouse:new RegExp("([m|l])ouse$","gi"),foot:new RegExp("^foot$","gi"),tooth:new RegExp("^tooth$","gi"),goose:new RegExp("^goose$","gi"),quiz:new RegExp("(quiz)$","gi"),whereas:new RegExp("^(whereas)$","gi"),criterion:new RegExp("^(criteri)on$","gi"),s:new RegExp("s$","gi"),common:new RegExp("$","gi")}},r=[[t.plural.men],[t.plural.people],[t.plural.children],[t.plural.tia],[t.plural.analyses],[t.plural.hives],[t.plural.curves],[t.plural.lrves],[t.plural.foves],[t.plural.aeiouyies],[t.plural.series],[t.plural.movies],[t.plural.xes],[t.plural.mice],[t.plural.buses],[t.plural.oes],[t.plural.shoes],[t.plural.crises],[t.plural.octopi],[t.plural.aliases],[t.plural.summonses],[t.plural.oxen],[t.plural.matrices],[t.plural.feet],[t.plural.teeth],[t.plural.geese],[t.plural.quizzes],[t.plural.whereases],[t.plural.criteria],[t.singular.man,"$1en"],[t.singular.person,"$1ople"],[t.singular.child,"$1ren"],[t.singular.ox,"$1en"],[t.singular.axis,"$1es"],[t.singular.octopus,"$1i"],[t.singular.alias,"$1es"],[t.singular.summons,"$1es"],[t.singular.bus,"$1ses"],[t.singular.buffalo,"$1oes"],[t.singular.tium,"$1a"],[t.singular.sis,"ses"],[t.singular.ffe,"$1$2ves"],[t.singular.hive,"$1ves"],[t.singular.aeiouyy,"$1ies"],[t.singular.matrix,"$1ices"],[t.singular.vertex,"$1ices"],[t.singular.x,"$1es"],[t.singular.mouse,"$1ice"],[t.singular.foot,"feet"],[t.singular.tooth,"teeth"],[t.singular.goose,"geese"],[t.singular.quiz,"$1zes"],[t.singular.whereas,"$1es"],[t.singular.criterion,"$1a"],[t.singular.s,"s"],[t.singular.common,"s"]],n=[[t.singular.man],[t.singular.person],[t.singular.child],[t.singular.ox],[t.singular.axis],[t.singular.octopus],[t.singular.alias],[t.singular.summons],[t.singular.bus],[t.singular.buffalo],[t.singular.tium],[t.singular.sis],[t.singular.ffe],[t.singular.hive],[t.singular.aeiouyy],[t.singular.x],[t.singular.matrix],[t.singular.mouse],[t.singular.foot],[t.singular.tooth],[t.singular.goose],[t.singular.quiz],[t.singular.whereas],[t.singular.criterion],[t.plural.men,"$1an"],[t.plural.people,"$1rson"],[t.plural.children,"$1"],[t.plural.criteria,"$1on"],[t.plural.tia,"$1um"],[t.plural.analyses,"$1$2sis"],[t.plural.hives,"$1ve"],[t.plural.curves,"$1"],[t.plural.lrves,"$1f"],[t.plural.foves,"$1fe"],[t.plural.movies,"$1ovie"],[t.plural.aeiouyies,"$1y"],[t.plural.series,"$1eries"],[t.plural.xes,"$1"],[t.plural.mice,"$1ouse"],[t.plural.buses,"$1"],[t.plural.oes,"$1"],[t.plural.shoes,"$1"],[t.plural.crises,"$1is"],[t.plural.octopi,"$1us"],[t.plural.aliases,"$1"],[t.plural.summonses,"$1"],[t.plural.oxen,"$1"],[t.plural.matrices,"$1ix"],[t.plural.vertices,"$1ex"],[t.plural.feet,"foot"],[t.plural.teeth,"tooth"],[t.plural.geese,"goose"],[t.plural.quizzes,"$1"],[t.plural.whereases,"$1"],[t.plural.ss,"ss"],[t.plural.s,""]],i=["and","or","nor","a","an","the","so","but","to","of","at","by","from","into","on","onto","off","out","in","over","with","for"],o=new RegExp("(_ids|_id)$","g"),s=new RegExp("_","g"),a=new RegExp("[ _]","g"),u=new RegExp("([A-Z])","g"),l=new RegExp("^_"),c={_apply_rules:function(e,t,r,n){if(n)e=n;else{var i=c.indexOf(r,e.toLowerCase())>-1;if(!i)for(var o=0,s=t.length;s>o;o++)if(e.match(t[o][0])){void 0!==t[o][1]&&(e=e.replace(t[o][0],t[o][1]));break}}return e},indexOf:function(e,t,r,n){r||(r=-1);for(var i=-1,o=r,s=e.length;s>o;o++)if(e[o]===t||n&&n(e[o],t)){i=o;break}return i},pluralize:function(t,n){return c._apply_rules(t,r,e,n)},singularize:function(t,r){return c._apply_rules(t,n,e,r)},inflect:function(t,i,o,s){return i=parseInt(i,10),isNaN(i)?t:0===i||i>1?c._apply_rules(t,r,e,s):c._apply_rules(t,n,e,o)},camelize:function(e,t){for(var r,n,i,o,s=e.split("/"),a=0,u=s.length;u>a;a++){for(r=s[a].split("_"),n=0,i=r.length;i>n;n++)0!==n&&(r[n]=r[n].toLowerCase()),o=r[n].charAt(0),o=t&&0===a&&0===n?o.toLowerCase():o.toUpperCase(),r[n]=o+r[n].substring(1);s[a]=r.join("")}return s.join("::")},underscore:function(e,t){if(t&&e===e.toUpperCase())return e;for(var r=e.split("::"),n=0,i=r.length;i>n;n++)r[n]=r[n].replace(u,"_$1"),r[n]=r[n].replace(l,"");return r.join("/").toLowerCase()},humanize:function(e,t){return e=e.toLowerCase(),e=e.replace(o,""),e=e.replace(s," "),t||(e=c.capitalize(e)),e},capitalize:function(e){return e=e.toLowerCase(),e.substring(0,1).toUpperCase()+e.substring(1)},dasherize:function(e){return e.replace(a,"-")},titleize:function(e){e=e.toLowerCase().replace(s," ");for(var t,r,n,o=e.split(" "),a=0,u=o.length;u>a;a++){for(t=o[a].split("-"),r=0,n=t.length;n>r;r++)c.indexOf(i,t[r].toLowerCase())<0&&(t[r]=c.capitalize(t[r]));o[a]=t.join("-")}return e=o.join(" "),e=e.substring(0,1).toUpperCase()+e.substring(1)},demodulize:function(e){var t=e.split("::");return t[t.length-1]},tableize:function(e){return e=c.underscore(e),e=c.pluralize(e)},classify:function(e){return e=c.camelize(e),e=c.singularize(e)},foreign_key:function(e,t){return e=c.demodulize(e),e=c.underscore(e)+(t?"":"_")+"id"},ordinalize:function(e){for(var t=e.split(" "),r=0,n=t.length;n>r;r++){var i=parseInt(t[r],10);if(!isNaN(i)){var o=t[r].substring(t[r].length-2),s=t[r].substring(t[r].length-1),a="th";"11"!=o&&"12"!=o&&"13"!=o&&("1"===s?a="st":"2"===s?a="nd":"3"===s&&(a="rd")),t[r]+=a}}return t.join(" ")},transform:function(e,t){for(var r=0,n=t.length;n>r;r++){var i=t[r];this.hasOwnProperty(i)&&(e=this[i](e))}return e}};return c.version="1.8.0",c})},function(e,t,r){var n,i;i=r(6),e.exports=n=function(){function e(){}return e.modelName=function(e,t){return i[t?"pluralize":"singularize"](i.classify(e))},e.tableName=function(e){return i.pluralize(i.underscore(e))},e.foreignKey=function(e,t){return t?i.singularize(i.underscore(e))+"_ids":i.underscore(e)+"_id"},e.attribute=function(e,t){return i[t?"pluralize":"singularize"](i.underscore(e))},e}()},function(e,t,r){var n,i,o,s=function(e,t){function r(){this.constructor=e}for(var n in t)a.call(t,n)&&(e[n]=t[n]);return r.prototype=t.prototype,e.prototype=new r,e.__super__=t.prototype,e},a={}.hasOwnProperty;o=r(6),n=r(7),e.exports=i=function(e){function t(){return t.__super__.constructor.apply(this,arguments)}return s(t,e),t.attribute=function(e,t){return o[t?"pluralize":"singularize"](o.camelize(e,!0))},t}(n)},function(e,t,r){var n,i,o,s=function(e,t){function r(){this.constructor=e}for(var n in t)a.call(t,n)&&(e[n]=t[n]);return r.prototype=t.prototype,e.prototype=new r,e.__super__=t.prototype,e},a={}.hasOwnProperty;o=r(6),n=r(7),e.exports=i=function(e){function t(){return t.__super__.constructor.apply(this,arguments)}return s(t,e),t.attribute=function(e,t){return o[t?"pluralize":"singularize"](o.camelize(e,!1))},t}(n)},function(e,t,r){var n,i,o,s,a;n=r(2),a=r(1),s=r(11),i=r(12),e.exports=o=function(){function e(){this.enabled=!1,this.caches={},this.options={modelTypes:{}},this.verbose=!1}return e.prototype.configure=function(e){var t,r,n,i,o,s;null==e&&(e={}),this.enabled=e.enabled;for(r in e)if(n=e[r],a.isObject(n)){(t=this.options)[r]||(t[r]={}),s=this.options[r];for(i in n)o=n[i],s[i]=o}else this.options[r]=n;return this.reset()},e.prototype.configureSync=function(e,t){return e.prototype._orm_never_cache||!this.createCache(e)?t:r(21)(e,t)},e.prototype.reset=function(){var e,t,r,n;t=this.caches,r=[];for(e in t)n=t[e],r.push(this.createCache(n.model_type));return r},e.prototype.createCache=function(e){var t,r,n,o;if(!(n=null!=e?e.model_name:void 0))throw new Error("Missing model name for cache");if(r=e.cuid||(e.cuid=a.uniqueId("cuid")),(t=this.caches[r])&&(delete this.caches[r],t.cache.reset(),t.model_type.cache=null),!this.enabled)return null;if(!(o=this.options.modelTypes[n])){if(!(this.options.store||this.options.max||this.options.max_age))return null;o=this.options}return t=this.caches[r]={cache:("function"==typeof o.store?o.store():void 0)||new i(o),model_type:e},e.cache=t.cache},e}()},function(e,t){var r,n=function(e,t){return function(){return e.apply(t,arguments)}};e.exports=r=function(){function e(e){this.parallelism=e,this._doneTask=n(this._doneTask,this),this.parallelism||(this.parallelism=1/0),this.tasks=[],this.running_count=0,this.error=null,this.await_callback=null}return e.prototype.defer=function(e){return this.tasks.push(e),this._runTasks()},e.prototype.await=function(e){if(this.await_callback)throw new Error("Awaiting callback was added twice: "+e);return this.await_callback=e,!this.error&&this.tasks.length+this.running_count?void 0:this._callAwaiting()},e.prototype._doneTask=function(e){return this.running_count--,this.error||(this.error=e),this._runTasks()},e.prototype._runTasks=function(){var e;if(this.error||!(this.tasks.length+this.running_count))return this._callAwaiting();for(;this.running_count<this.parallelism;){if(!this.tasks.length)return;e=this.tasks.shift(),this.running_count++,e(this._doneTask)}},e.prototype._callAwaiting=function(){return!this.await_called&&this.await_callback?(this.await_called=!0,this.await_callback(this.error)):void 0},e}()},function(e,t,r){var n,i,o,s=function(e,t){return function(){return e.apply(t,arguments)}};o=r(1),n=r(13),e.exports=i=function(){function e(e){var t;null==e&&(e={}),this.forEach=s(this.forEach,this),this.reset=s(this.reset,this),this.destroy=s(this.destroy,this),this.get=s(this.get,this),this.set=s(this.set,this),(t=e.max_age)&&((e=o.omit(e,"max_age")).maxAge=t),this.cache=new n(e)}return e.prototype.set=function(e,t,r){return t._orm_never_cache?("function"==typeof r?r(null,t):void 0)||this:(this.cache.set(e,t),"function"==typeof r&&r(null,t),this)},e.prototype.get=function(e,t){var r;return r=this.cache.get(e),"function"==typeof t&&t(null,r),r},e.prototype.destroy=function(e,t){return this.cache.del(e),"function"==typeof t&&t(),this},e.prototype.del=e.prototype.destroy,e.prototype.reset=function(e){return this.cache.reset(),"function"==typeof e&&e(),this},e.prototype.forEach=function(e){return this.cache.forEach(e)},e}()},function(e,t,r){function n(e,t,r){var n;return g[t]?n=g[t]:(n=f(t),g[t]=n),2===arguments.length?e[n]:(e[n]=r,r)}function i(){return 1}function o(e){if(!(this instanceof o))return new o(e);"number"==typeof e&&(e={max:e}),e||(e={});var t=n(this,"max",e.max);(!t||"number"!=typeof t||0>=t)&&n(this,"max",1/0);var r=e.length||i;"function"!=typeof r&&(r=i),n(this,"lengthCalculator",r),n(this,"allowStale",e.stale||!1),n(this,"maxAge",e.maxAge||0),n(this,"dispose",e.dispose),this.reset()}function s(e,t,r,i){var o=r.value;u(e,o)&&(c(e,r),n(e,"allowStale")||(o=void 0)),o&&t.call(i,o.value,o.key,e)}function a(e,t,r){var i=n(e,"cache").get(t);if(i){var o=i.value;u(e,o)?(c(e,i),n(e,"allowStale")||(o=void 0)):r&&n(e,"lruList").unshiftNode(i),o&&(o=o.value)}return o}function u(e,t){if(!t||!t.maxAge&&!n(e,"maxAge"))return!1;var r=!1,i=Date.now()-t.now;return r=t.maxAge?i>t.maxAge:n(e,"maxAge")&&i>n(e,"maxAge")}function l(e){if(n(e,"length")>n(e,"max"))for(var t=n(e,"lruList").tail;n(e,"length")>n(e,"max")&&null!==t;){var r=t.prev;c(e,t),t=r}}function c(e,t){if(t){var r=t.value;n(e,"dispose")&&n(e,"dispose").call(this,r.key,r.value),n(e,"length",n(e,"length")-r.length),n(e,"cache")["delete"](r.key),n(e,"lruList").removeNode(t)}}function h(e,t,r,n,i){this.key=e,this.value=t,this.length=r,this.now=n,this.maxAge=i||0}e.exports=o;var f,p=r(14),d=r(17),y=r(20),g={},m="function"==typeof Symbol;f=m?function(e){return Symbol["for"](e)}:function(e){return"_"+e},Object.defineProperty(o.prototype,"max",{set:function(e){(!e||"number"!=typeof e||0>=e)&&(e=1/0),n(this,"max",e),l(this)},get:function(){return n(this,"max")},enumerable:!0}),Object.defineProperty(o.prototype,"allowStale",{set:function(e){n(this,"allowStale",!!e)},get:function(){return n(this,"allowStale")},enumerable:!0}),Object.defineProperty(o.prototype,"maxAge",{set:function(e){(!e||"number"!=typeof e||0>e)&&(e=0),n(this,"maxAge",e),l(this)},get:function(){return n(this,"maxAge")},enumerable:!0}),Object.defineProperty(o.prototype,"lengthCalculator",{set:function(e){"function"!=typeof e&&(e=i),e!==n(this,"lengthCalculator")&&(n(this,"lengthCalculator",e),n(this,"length",0),n(this,"lruList").forEach(function(e){e.length=n(this,"lengthCalculator").call(this,e.value,e.key),n(this,"length",n(this,"length")+e.length)},this)),l(this)},get:function(){return n(this,"lengthCalculator")},enumerable:!0}),Object.defineProperty(o.prototype,"length",{get:function(){return n(this,"length")},enumerable:!0}),Object.defineProperty(o.prototype,"itemCount",{get:function(){return n(this,"lruList").length},enumerable:!0}),o.prototype.rforEach=function(e,t){t=t||this;for(var r=n(this,"lruList").tail;null!==r;){var i=r.prev;s(this,e,r,t),r=i}},o.prototype.forEach=function(e,t){t=t||this;for(var r=n(this,"lruList").head;null!==r;){var i=r.next;s(this,e,r,t),r=i}},o.prototype.keys=function(){return n(this,"lruList").toArray().map(function(e){return e.key},this)},o.prototype.values=function(){return n(this,"lruList").toArray().map(function(e){return e.value},this)},o.prototype.reset=function(){n(this,"dispose")&&n(this,"lruList")&&n(this,"lruList").length&&n(this,"lruList").forEach(function(e){n(this,"dispose").call(this,e.key,e.value)},this),n(this,"cache",new p),n(this,"lruList",new y),n(this,"length",0)},o.prototype.dump=function(){return n(this,"lruList").map(function(e){return u(this,e)?void 0:{k:e.key,v:e.value,e:e.now+(e.maxAge||0)}},this).toArray().filter(function(e){return e})},o.prototype.dumpLru=function(){return n(this,"lruList")},o.prototype.inspect=function(e,t){var r="LRUCache {",o=!1,s=n(this,"allowStale");s&&(r+="\n allowStale: true",o=!0);var a=n(this,"max");a&&a!==1/0&&(o&&(r+=","),r+="\n max: "+d.inspect(a,t),o=!0);var l=n(this,"maxAge");l&&(o&&(r+=","),r+="\n maxAge: "+d.inspect(l,t),o=!0);var c=n(this,"lengthCalculator");c&&c!==i&&(o&&(r+=","),r+="\n length: "+d.inspect(n(this,"length"),t),o=!0);var h=!1;return n(this,"lruList").forEach(function(e){h?r+=",\n ":(o&&(r+=",\n"),h=!0,r+="\n ");var n=d.inspect(e.key).split("\n").join("\n "),s={value:e.value};e.maxAge!==l&&(s.maxAge=e.maxAge),c!==i&&(s.length=e.length),u(this,e)&&(s.stale=!0),s=d.inspect(s,t).split("\n").join("\n "),r+=n+" => "+s}),(h||o)&&(r+="\n"),r+="}"},o.prototype.set=function(e,t,r){r=r||n(this,"maxAge");var i=r?Date.now():0,o=n(this,"lengthCalculator").call(this,t,e);if(n(this,"cache").has(e)){if(o>n(this,"max"))return c(this,n(this,"cache").get(e)),!1;var s=n(this,"cache").get(e),a=s.value;return n(this,"dispose")&&n(this,"dispose").call(this,e,a.value),a.now=i,a.maxAge=r,a.value=t,n(this,"length",n(this,"length")+(o-a.length)),a.length=o,this.get(e),l(this),!0}var u=new h(e,t,o,i,r);return u.length>n(this,"max")?(n(this,"dispose")&&n(this,"dispose").call(this,e,t),!1):(n(this,"length",n(this,"length")+u.length),n(this,"lruList").unshift(u),n(this,"cache").set(e,n(this,"lruList").head),l(this),!0)},o.prototype.has=function(e){if(!n(this,"cache").has(e))return!1;var t=n(this,"cache").get(e).value;return u(this,t)?!1:!0},o.prototype.get=function(e){return a(this,e,!0)},o.prototype.peek=function(e){return a(this,e,!1)},o.prototype.pop=function(){var e=n(this,"lruList").tail;return e?(c(this,e),e.value):null},o.prototype.del=function(e){c(this,n(this,"cache").get(e))},o.prototype.load=function(e){this.reset();for(var t=Date.now(),r=e.length-1;r>=0;r--){var n=e[r],i=n.e||0;if(0===i)this.set(n.k,n.v);else{var o=i-t;o>0&&this.set(n.k,n.v,o)}}},o.prototype.prune=function(){var e=this;n(this,"cache").forEach(function(t,r){a(e,r,!1)})}},function(e,t,r){(function(t){"pseudomap"===t.env.npm_package_name&&"test"===t.env.npm_lifecycle_script&&(t.env.TEST_PSEUDOMAP="true"),"function"!=typeof Map||t.env.TEST_PSEUDOMAP?e.exports=r(16):e.exports=Map}).call(t,r(15))},function(e,t){function r(){l=!1,s.length?u=s.concat(u):c=-1,u.length&&n()}function n(){if(!l){var e=setTimeout(r);l=!0;for(var t=u.length;t;){for(s=u,u=[];++c<t;)s&&s[c].run();c=-1,t=u.length}s=null,l=!1,clearTimeout(e)}}function i(e,t){this.fun=e,this.array=t}function o(){}var s,a=e.exports={},u=[],l=!1,c=-1;a.nextTick=function(e){var t=new Array(arguments.length-1);if(arguments.length>1)for(var r=1;r<arguments.length;r++)t[r-1]=arguments[r];u.push(new i(e,t)),1!==u.length||l||setTimeout(n,0)},i.prototype.run=function(){this.fun.apply(null,this.array)},a.title="browser",a.browser=!0,a.env={},a.argv=[],a.version="",a.versions={},a.on=o,a.addListener=o,a.once=o,a.off=o,a.removeListener=o,a.removeAllListeners=o,a.emit=o,a.binding=function(e){throw new Error("process.binding is not supported")},a.cwd=function(){return"/"},a.chdir=function(e){throw new Error("process.chdir is not supported")},a.umask=function(){return 0}},function(e,t){function r(e){if(!(this instanceof r))throw new TypeError("Constructor PseudoMap requires 'new'");if(this.clear(),e)if(e instanceof r||"function"==typeof Map&&e instanceof Map)e.forEach(function(e,t){this.set(t,e)},this);else{if(!Array.isArray(e))throw new TypeError("invalid argument");e.forEach(function(e){this.set(e[0],e[1])},this)}}function n(e,t){return e===t||e!==e&&t!==t}function i(e,t,r){this.key=e,this.value=t,this._index=r}function o(e,t){for(var r=0,i="_"+t,o=i;a.call(e,o);o=i+r++)if(n(e[o].key,t))return e[o]}function s(e,t,r){for(var o=0,s="_"+t,u=s;a.call(e,u);u=s+o++)if(n(e[u].key,t))return void(e[u].value=r);e.size++,e[u]=new i(t,r,u)}var a=Object.prototype.hasOwnProperty;e.exports=r,r.prototype.forEach=function(e,t){t=t||this,Object.keys(this._data).forEach(function(r){"size"!==r&&e.call(t,this._data[r].value,this._data[r].key)},this)},r.prototype.has=function(e){return!!o(this._data,e)},r.prototype.get=function(e){var t=o(this._data,e);return t&&t.value},r.prototype.set=function(e,t){s(this._data,e,t)},r.prototype["delete"]=function(e){var t=o(this._data,e);t&&(delete this._data[t._index],this._data.size--)},r.prototype.clear=function(){var e=Object.create(null);e.size=0,Object.defineProperty(this,"_data",{value:e,enumerable:!1,configurable:!0,writable:!1})},Object.defineProperty(r.prototype,"size",{get:function(){return this._data.size},set:function(e){},enumerable:!0,configurable:!0}),r.prototype.values=r.prototype.keys=r.prototype.entries=function(){throw new Error("iterators are not implemented in this version")}},function(e,t,r){(function(e,n){function i(e,r){var n={seen:[],stylize:s};return arguments.length>=3&&(n.depth=arguments[2]),arguments.length>=4&&(n.colors=arguments[3]),y(r)?n.showHidden=r:r&&t._extend(n,r),b(n.showHidden)&&(n.showHidden=!1),b(n.depth)&&(n.depth=2),b(n.colors)&&(n.colors=!1),b(n.customInspect)&&(n.customInspect=!0),n.colors&&(n.stylize=o),u(n,e,n.depth)}function o(e,t){var r=i.styles[t];return r?"["+i.colors[r][0]+"m"+e+"["+i.colors[r][1]+"m":e}function s(e,t){return e}function a(e){var t={};return e.forEach(function(e,r){t[e]=!0}),t}function u(e,r,n){if(e.customInspect&&r&&$(r.inspect)&&r.inspect!==t.inspect&&(!r.constructor||r.constructor.prototype!==r)){var i=r.inspect(n,e);return _(i)||(i=u(e,i,n)),i}var o=l(e,r);if(o)return o;var s=Object.keys(r),y=a(s);if(e.showHidden&&(s=Object.getOwnPropertyNames(r)),O(r)&&(s.indexOf("message")>=0||s.indexOf("description")>=0))return c(r);if(0===s.length){if($(r)){var g=r.name?": "+r.name:"";return e.stylize("[Function"+g+"]","special")}if(E(r))return e.stylize(RegExp.prototype.toString.call(r),"regexp");if(x(r))return e.stylize(Date.prototype.toString.call(r),"date");if(O(r))return c(r)}var m="",v=!1,w=["{","}"];if(d(r)&&(v=!0,w=["[","]"]),$(r)){var b=r.name?": "+r.name:"";m=" [Function"+b+"]"}if(E(r)&&(m=" "+RegExp.prototype.toString.call(r)),x(r)&&(m=" "+Date.prototype.toUTCString.call(r)),O(r)&&(m=" "+c(r)),0===s.length&&(!v||0==r.length))return w[0]+m+w[1];if(0>n)return E(r)?e.stylize(RegExp.prototype.toString.call(r),"regexp"):e.stylize("[Object]","special");e.seen.push(r);var k;return k=v?h(e,r,n,y,s):s.map(function(t){return f(e,r,n,y,t,v)}),e.seen.pop(),p(k,m,w)}function l(e,t){if(b(t))return e.stylize("undefined","undefined");if(_(t)){var r="'"+JSON.stringify(t).replace(/^"|"$/g,"").replace(/'/g,"\\'").replace(/\\"/g,'"')+"'";return e.stylize(r,"string")}return v(t)?e.stylize(""+t,"number"):y(t)?e.stylize(""+t,"boolean"):g(t)?e.stylize("null","null"):void 0}function c(e){return"["+Error.prototype.toString.call(e)+"]"}function h(e,t,r,n,i){for(var o=[],s=0,a=t.length;a>s;++s)N(t,String(s))?o.push(f(e,t,r,n,String(s),!0)):o.push("");return i.forEach(function(i){i.match(/^\d+$/)||o.push(f(e,t,r,n,i,!0))}),o}function f(e,t,r,n,i,o){var s,a,l;if(l=Object.getOwnPropertyDescriptor(t,i)||{value:t[i]},l.get?a=l.set?e.stylize("[Getter/Setter]","special"):e.stylize("[Getter]","special"):l.set&&(a=e.stylize("[Setter]","special")),N(n,i)||(s="["+i+"]"),a||(e.seen.indexOf(l.value)<0?(a=g(r)?u(e,l.value,null):u(e,l.value,r-1),a.indexOf("\n")>-1&&(a=o?a.split("\n").map(function(e){return" "+e}).join("\n").substr(2):"\n"+a.split("\n").map(function(e){return" "+e}).join("\n"))):a=e.stylize("[Circular]","special")),b(s)){if(o&&i.match(/^\d+$/))return a;s=JSON.stringify(""+i),s.match(/^"([a-zA-Z_][a-zA-Z_0-9]*)"$/)?(s=s.substr(1,s.length-2),s=e.stylize(s,"name")):(s=s.replace(/'/g,"\\'").replace(/\\"/g,'"').replace(/(^"|"$)/g,"'"),s=e.stylize(s,"string"))}return s+": "+a}function p(e,t,r){var n=0,i=e.reduce(function(e,t){return n++,t.indexOf("\n")>=0&&n++,e+t.replace(/\u001b\[\d\d?m/g,"").length+1},0);return i>60?r[0]+(""===t?"":t+"\n ")+" "+e.join(",\n ")+" "+r[1]:r[0]+t+" "+e.join(", ")+" "+r[1]}function d(e){return Array.isArray(e)}function y(e){return"boolean"==typeof e}function g(e){return null===e}function m(e){return null==e}function v(e){return"number"==typeof e}function _(e){return"string"==typeof e}function w(e){return"symbol"==typeof e}function b(e){return void 0===e}function E(e){return k(e)&&"[object RegExp]"===S(e)}function k(e){return"object"==typeof e&&null!==e}function x(e){return k(e)&&"[object Date]"===S(e)}function O(e){return k(e)&&("[object Error]"===S(e)||e instanceof Error)}function $(e){return"function"==typeof e}function A(e){return null===e||"boolean"==typeof e||"number"==typeof e||"string"==typeof e||"symbol"==typeof e||"undefined"==typeof e}function S(e){return Object.prototype.toString.call(e)}function R(e){return 10>e?"0"+e.toString(10):e.toString(10)}function I(){var e=new Date,t=[R(e.getHours()),R(e.getMinutes()),R(e.getSeconds())].join(":");return[e.getDate(),M[e.getMonth()],t].join(" ")}function N(e,t){return Object.prototype.hasOwnProperty.call(e,t)}var C=/%[sdj%]/g;t.format=function(e){if(!_(e)){for(var t=[],r=0;r<arguments.length;r++)t.push(i(arguments[r]));return t.join(" ")}for(var r=1,n=arguments,o=n.length,s=String(e).replace(C,function(e){if("%%"===e)return"%";if(r>=o)return e;switch(e){case"%s":return String(n[r++]);case"%d":return Number(n[r++]);case"%j":try{return JSON.stringify(n[r++])}catch(t){return"[Circular]"}default:return e}}),a=n[r];o>r;a=n[++r])s+=g(a)||!k(a)?" "+a:" "+i(a);return s},t.deprecate=function(r,i){function o(){if(!s){if(n.throwDeprecation)throw new Error(i);n.traceDeprecation?console.trace(i):console.error(i),s=!0}return r.apply(this,arguments)}if(b(e.process))return function(){return t.deprecate(r,i).apply(this,arguments)};if(n.noDeprecation===!0)return r;var s=!1;return o};var T,j={};t.debuglog=function(e){if(b(T)&&(T=n.env.NODE_DEBUG||""),e=e.toUpperCase(),!j[e])if(new RegExp("\\b"+e+"\\b","i").test(T)){var r=n.pid;j[e]=function(){var n=t.format.apply(t,arguments);console.error("%s %d: %s",e,r,n)}}else j[e]=function(){};return j[e]},t.inspect=i,i.colors={bold:[1,22],italic:[3,23],underline:[4,24],inverse:[7,27],white:[37,39],grey:[90,39],black:[30,39],blue:[34,39],cyan:[36,39],green:[32,39],magenta:[35,39],red:[31,39],yellow:[33,39]},i.styles={special:"cyan",number:"yellow","boolean":"yellow",undefined:"grey","null":"bold",string:"green",date:"magenta",regexp:"red"},t.isArray=d,t.isBoolean=y,t.isNull=g,t.isNullOrUndefined=m,t.isNumber=v,t.isString=_,t.isSymbol=w,t.isUndefined=b,t.isRegExp=E,t.isObject=k,t.isDate=x,t.isError=O,t.isFunction=$,t.isPrimitive=A,t.isBuffer=r(18);var M=["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"];t.log=function(){console.log("%s - %s",I(),t.format.apply(t,arguments))},t.inherits=r(19),t._extend=function(e,t){if(!t||!k(t))return e;for(var r=Object.keys(t),n=r.length;n--;)e[r[n]]=t[r[n]];return e}}).call(t,function(){return this}(),r(15))},function(e,t){e.exports=function(e){return e&&"object"==typeof e&&"function"==typeof e.copy&&"function"==typeof e.fill&&"function"==typeof e.readUInt8}},function(e,t){"function"==typeof Object.create?e.exports=function(e,t){e.super_=t,e.prototype=Object.create(t.prototype,{constructor:{value:e,enumerable:!1,writable:!0,configurable:!0}})}:e.exports=function(e,t){e.super_=t;var r=function(){};r.prototype=t.prototype,e.prototype=new r,e.prototype.constructor=e}},function(e,t){function r(e){var t=this;if(t instanceof r||(t=new r),t.tail=null,t.head=null,t.length=0,e&&"function"==typeof e.forEach)e.forEach(function(e){t.push(e)});else if(arguments.length>0)for(var n=0,i=arguments.length;i>n;n++)t.push(arguments[n]);return t}function n(e,t){e.tail=new o(t,e.tail,null,e),e.head||(e.head=e.tail),e.length++}function i(e,t){e.head=new o(t,null,e.head,e),e.tail||(e.tail=e.head),e.length++}function o(e,t,r,n){return this instanceof o?(this.list=n,this.value=e,t?(t.next=this,this.prev=t):this.prev=null,void(r?(r.prev=this,this.next=r):this.next=null)):new o(e,t,r,n)}e.exports=r,r.Node=o,r.create=r,r.prototype.removeNode=function(e){if(e.list!==this)throw new Error("removing node which does not belong to this list");var t=e.next,r=e.prev;t&&(t.prev=r),r&&(r.next=t),e===this.head&&(this.head=t),e===this.tail&&(this.tail=r),e.list.length--,e.next=null,e.prev=null,e.list=null},r.prototype.unshiftNode=function(e){if(e!==this.head){e.list&&e.list.removeNode(e);var t=this.head;
e.list=this,e.next=t,t&&(t.prev=e),this.head=e,this.tail||(this.tail=e),this.length++}},r.prototype.pushNode=function(e){if(e!==this.tail){e.list&&e.list.removeNode(e);var t=this.tail;e.list=this,e.prev=t,t&&(t.next=e),this.tail=e,this.head||(this.head=e),this.length++}},r.prototype.push=function(){for(var e=0,t=arguments.length;t>e;e++)n(this,arguments[e]);return this.length},r.prototype.unshift=function(){for(var e=0,t=arguments.length;t>e;e++)i(this,arguments[e]);return this.length},r.prototype.pop=function(){if(this.tail){var e=this.tail.value;return this.tail=this.tail.prev,this.tail.next=null,this.length--,e}},r.prototype.shift=function(){if(this.head){var e=this.head.value;return this.head=this.head.next,this.head.prev=null,this.length--,e}},r.prototype.forEach=function(e,t){t=t||this;for(var r=this.head,n=0;null!==r;n++)e.call(t,r.value,n,this),r=r.next},r.prototype.forEachReverse=function(e,t){t=t||this;for(var r=this.tail,n=this.length-1;null!==r;n--)e.call(t,r.value,n,this),r=r.prev},r.prototype.get=function(e){for(var t=0,r=this.head;null!==r&&e>t;t++)r=r.next;return t===e&&null!==r?r.value:void 0},r.prototype.getReverse=function(e){for(var t=0,r=this.tail;null!==r&&e>t;t++)r=r.prev;return t===e&&null!==r?r.value:void 0},r.prototype.map=function(e,t){t=t||this;for(var n=new r,i=this.head;null!==i;)n.push(e.call(t,i.value,this)),i=i.next;return n},r.prototype.mapReverse=function(e,t){t=t||this;for(var n=new r,i=this.tail;null!==i;)n.push(e.call(t,i.value,this)),i=i.prev;return n},r.prototype.reduce=function(e,t){var r,n=this.head;if(arguments.length>1)r=t;else{if(!this.head)throw new TypeError("Reduce of empty list with no initial value");n=this.head.next,r=this.head.value}for(var i=0;null!==n;i++)r=e(r,n.value,i),n=n.next;return r},r.prototype.reduceReverse=function(e,t){var r,n=this.tail;if(arguments.length>1)r=t;else{if(!this.tail)throw new TypeError("Reduce of empty list with no initial value");n=this.tail.prev,r=this.tail.value}for(var i=this.length-1;null!==n;i--)r=e(r,n.value,i),n=n.prev;return r},r.prototype.toArray=function(){for(var e=new Array(this.length),t=0,r=this.head;null!==r;t++)e[t]=r.value,r=r.next;return e},r.prototype.toArrayReverse=function(){for(var e=new Array(this.length),t=0,r=this.tail;null!==r;t++)e[t]=r.value,r=r.prev;return e},r.prototype.slice=function(e,t){t=t||this.length,0>t&&(t+=this.length),e=e||0,0>e&&(e+=this.length);var n=new r;if(e>t||0>t)return n;0>e&&(e=0),t>this.length&&(t=this.length);for(var i=0,o=this.head;null!==o&&e>i;i++)o=o.next;for(;null!==o&&t>i;i++,o=o.next)n.push(o.value);return n},r.prototype.sliceReverse=function(e,t){t=t||this.length,0>t&&(t+=this.length),e=e||0,0>e&&(e+=this.length);var n=new r;if(e>t||0>t)return n;0>e&&(e=0),t>this.length&&(t=this.length);for(var i=this.length,o=this.tail;null!==o&&i>t;i--)o=o.prev;for(;null!==o&&i>e;i--,o=o.prev)n.push(o.value);return n},r.prototype.reverse=function(){for(var e=this.head,t=this.tail,r=e;null!==r;r=r.prev){var n=r.prev;r.prev=r.next,r.next=n}return this.head=t,this.tail=e,this}},function(e,t,r){var n,i,o,s,a,u,l,c;l=r(1),n=r(22),a=r(43),u=r(24),c=u.bbCallback,o=1e3,s=100,i=function(){function e(e,t){this.model_type=e,this.wrapped_sync_fn=t}return e.prototype.initialize=function(){if(!this.is_initialized&&(this.is_initialized=!0,this.wrapped_sync_fn("initialize"),!this.model_type.model_name))throw new Error("Missing model_name for model")},e.prototype.read=function(e,t){var r;return!t.force&&(r=this.model_type.cache.get(e.id))?t.success(r.toJSON()):this.wrapped_sync_fn("read",e,t)},e.prototype.create=function(e,t){return this.wrapped_sync_fn("create",e,{success:function(r){return function(n){var i,o;return(i={})[r.model_type.prototype.idAttribute]=n[r.model_type.prototype.idAttribute],e.set(i),(o=r.model_type.cache.get(e.id))?o!==e&&u.updateModel(o,e):r.model_type.cache.set(e.id,e),t.success(n)}}(this),error:function(e){return function(e){return"function"==typeof t.error?t.error(e):void 0}}(this)})},e.prototype.update=function(e,t){return this.wrapped_sync_fn("update",e,{success:function(r){return function(n){var i;return(i=r.model_type.cache.get(e.id))?i!==e&&u.updateModel(i,e):r.model_type.cache.set(e.id,e),t.success(n)}}(this),error:function(e){return function(e){return"function"==typeof t.error?t.error(e):void 0}}(this)})},e.prototype["delete"]=function(e,t){return this.model_type.cache.destroy(e.id),this.wrapped_sync_fn("delete",e,t)},e.prototype.resetSchema=function(e,t){return this.model_type.cache.reset(function(r){return function(n){return n?t(n):r.wrapped_sync_fn("resetSchema",e,t)}}(this))},e.prototype.cursor=function(e){return null==e&&(e={}),new n(e,l.pick(this,["model_type","wrapped_sync_fn"]))},e.prototype.destroy=function(e,t){return this.model_type.each(l.extend({$each:{limit:o,threads:s}},e),function(e){return function(e,t){return e.destroy(t)}}(this),t)},e.prototype.connect=function(e){return this.model_type.cache.reset(),this.wrapped_sync_fn("connect")},e}(),e.exports=function(e,t){var r,n;return r=new i(e,t),e.prototype.sync=n=function(e,n,i){return null==i&&(i={}),r.initialize(),"createSync"===e?t.apply(null,arguments):"sync"===e?r:r[e]?r[e].apply(r,Array.prototype.slice.call(arguments,1)):t.apply(t,Array.prototype.slice.call(arguments))},n}},function(e,t,r){var n,i,o=function(e,t){function r(){this.constructor=e}for(var n in t)s.call(t,n)&&(e[n]=t[n]);return r.prototype=t.prototype,e.prototype=new r,e.__super__=t.prototype,e},s={}.hasOwnProperty;i=r(1),e.exports=n=function(e){function t(){return t.__super__.constructor.apply(this,arguments)}return o(t,e),t.prototype.toJSON=function(e){return this.wrapped_sync_fn("cursor",i.extend({},this._find,this._cursor)).toJSON(e)},t}(r(23))},function(e,t,r){var n,i,o,s,a,u,l,c,h,f,p,d=function(e,t){function r(){this.constructor=e}for(var n in t)y.call(t,n)&&(e[n]=t[n]);return r.prototype=t.prototype,e.prototype=new r,e.__super__=t.prototype,e},y={}.hasOwnProperty,g=[].indexOf||function(e){for(var t=0,r=this.length;r>t;t++)if(t in this&&this[t]===e)return t;return-1};h=r(1),l=r(11),c=r(24),a=r(33),i=r(40),n=r(42),o={$ne:function(e,t){return!h.isEqual(e,t)},$lt:function(e,t){if(h.isNull(t))throw Error("Cannot compare to null");return h.isDate(t)?i.isBefore(e,t):t>e},$lte:function(e,t){if(h.isNull(t))throw Error("Cannot compare to null");return h.isDate(t)?!i.isAfter(e,t):t>=e},$gt:function(e,t){if(h.isNull(t))throw Error("Cannot compare to null");return h.isDate(t)?i.isAfter(e,t):e>t},$gte:function(e,t){if(h.isNull(t))throw Error("Cannot compare to null");return h.isDate(t)?!i.isBefore(e,t):e>=t},$exists:function(e,t){return t?!h.isUndefined(e):h.isUndefined(e)}},s=h.keys(o),p=function(e){return h.isArray(e)?e:h.isNull(e)?[]:e.$in?e.$in:[e]},f=function(e,t,r){return e[t]=e.hasOwnProperty(t)?{$in:h.intersection(p(e[t]),p(r))}:r},e.exports=u=function(e){function t(){return t.__super__.constructor.apply(this,arguments)}return d(t,e),t.prototype.queryToJSON=function(e){var r;return this.hasCursorQuery("$zero")?e(null,this.hasCursorQuery("$one")?null:[]):(r=this.hasCursorQuery("$exists"),this.buildFindQuery(function(n){return function(i,o){var s,u,f;return i?e(i):(s=[],u=null,f=new l(1),f.defer(function(e){var t,i,l,f,p,d,y,m,v,_,w,b,E;v=[{},{}],i=v[0],y=v[1];for(f in o)E=o[f],(null!=E?E.$in:void 0)&&(delete o[f],i[f]=E.$in),(null!=E?E.$nin:void 0)&&(delete o[f],y[f]=E.$nin);if(_=[a.isEmptyObject(i),a.isEmptyObject(y)],l=_[0],m=_[1],u=h.keys(o),!u.length&&l&&m)return s=n._cursor.$ids?function(){var e,t,r,n,i;for(r=this.store,i=[],e=0,t=r.length;t>e;e++)d=r[e],n=d.id,g.call(this._cursor.$ids,n)>=0&&i.push(a.deepClone(d));return i}.call(n):function(){var e,t,r,n;for(r=this.store,n=[],e=0,t=r.length;t>e;e++)d=r[e],n.push(a.deepClone(d));return n}.call(n),e();if(n._cursor.$ids){for(w=n.store,t=0,p=w.length;p>t;t++)d=w[t],b=d.id,g.call(n._cursor.$ids,b)>=0&&h.isEqual(h.pick(d,u),o)&&s.push(a.deepClone(d));return e()}return c.each(n.store,function(e,t){var h,p,d,v;if(r&&s.length)return t(null,!0);if(!l)for(f in i)if(v=i[f],p=e[f],g.call(v,p)<0)return t();if(!m)for(f in y)if(v=y[f],d=e[f],g.call(v,d)>=0)return t();return h=!0,c.eachDone(u,function(t,r){return n._valueIsMatch(o,t,e,function(e,t){return r(e,!(h=t))})},function(r){return r||!h||s.push(a.deepClone(e)),t(r)})},e)}),r||(f.defer(function(e){var t,r,i,o,a,u,l,f,p,d,y,g;if(n._cursor.$sort&&(t=h.isArray(n._cursor.$sort)?n._cursor.$sort:[n._cursor.$sort],s.sort(function(e,r){return c.jsonFieldCompare(e,r,t)})),n._cursor.$unique){for(y=[],g={},i=0,u=s.length;u>i;i++){for(f=s[i],a="",d=n._cursor.$unique,o=0,l=d.length;l>o;o++)r=d[o],f.hasOwnProperty(r)&&(a+=r+":"+JSON.stringify(f[r]));g[a]||(g[a]=!0,y.push(f))}s=y}return n._cursor.$offset&&(p=s.length-n._cursor.$offset,0>p&&(p=0),s=p?s.slice(n._cursor.$offset,n._cursor.$offset+p):[]),n._cursor.$one?s=s.slice(0,1):n._cursor.$limit&&(s=s.splice(0,Math.min(s.length,n._cursor.$limit))),e()}),f.defer(function(e){return n.fetchIncludes(s,e)})),void f.await(function(){var i;return n.hasCursorQuery("$count")?e(null,h.isArray(s)?s.length:s?1:0):r?e(null,h.isArray(s)?!!s.length:s):n.hasCursorQuery("$page")?(i=new t(h.extend(h.pick(n._cursor,"$unique"),n._find),h.pick(n,["model_type","store"])),i.count(function(t,r){return t?e(t):e(null,{offset:n._cursor.$offset||0,total_rows:r,rows:n.selectResults(s)})})):e(null,n.selectResults(s))}))}}(this)))},t.prototype.buildFindQuery=function(e){var t,r,n,i,o,s,u,c,h,p;i=new l,t={},o=this._find,r=function(e){return function(r,o,s){return i.defer(function(i){var a,u;return(u=e.model_type.relation(r))?u.join_table||"id"!==o?u.join_table||"belongsTo"===u.type?((a={$values:"id"})[o]=s,u.reverse_relation.model_type.cursor(a).toJSON(function(e,r){var n;return e?i(e):u.join_table?((n={})[u.reverse_relation.join_key]={$in:r},n.$values=u.foreign_key,u.join_table.cursor(n).toJSON(function(e,r){return e?i(e):(f(t,"id",{$in:r}),i())})):(f(t,u.foreign_key,{$in:r}),i())})):((a={})[o]=s,a.$values=u.foreign_key,u.reverse_model_type.cursor(a).toJSON(function(e,r){return e?i(e):(f(t,"id",{$in:r}),i())})):(f(t,u.foreign_key,s),i()):(f(t,n,s),i())})}}(this);for(n in o)if(h=o[n],n.indexOf(".")<0){if(!(c=this.model_type.reverseRelation(n))){f(t,n,h);continue}if(!c.embed&&!c.join_table){f(t,n,h);continue}!function(e){return function(r,n,o){return i.defer(function(i){var s;if(o.embed)throw Error("Embedded find is not yet supported. @_find: "+a.stringify(e._find));return(s={})[r]=n,s.$values=o.reverse_relation.join_key,o.join_table.cursor(s).toJSON(function(e,r){return e?i(e):(f(t,"id",{$in:r}),i())})})}}(this)(n,h,c)}else s=n.split("."),u=s[0],p=s[1],this.model_type.relationIsEmbedded(u)?f(t,n,h):r(u,p,h);return i.await(function(r){return function(r){return e(r,t)}}(this))},t.prototype.fetchIncludes=function(e,t){var r,n,i,o,s,a,u,c,f,p;if(!this._cursor.$include)return t();for(c=new l(1),i=h.isArray(this._cursor.$include)?this._cursor.$include:[this._cursor.$include],n=0,a=i.length;a>n;n++)if(s=i[n],!this.model_type.relationIsEmbedded(s)){if(!(p=this.model_type.relation(s)))return t(new Error("Included relation '"+s+"' is not a relation"));for(r=function(e){return function(e,t){return c.defer(function(r){return p.cursor(t,e).toJSON(function(n,i){return n?r(n):(delete t[p.foriegn_key],t[e]=i,r())})})}}(this),o=0,u=e.length;u>o;o++)f=e[o],r(s,f)}return c.await(t)},t.prototype._valueIsMatch=function(e,t,r,n){var i,a,u,l,c,f,p;return l=this.model_type,i=e[t],h.isObject(i)&&(p=function(){var e,t,r;for(r=[],e=0,t=s.length;t>e;e++)f=s[e],i.hasOwnProperty(f)&&r.push(f);return r}()),u=t.split("."),a=function(e,t){var r,n,s;if(s=e[t],p&&p.length){for(r=0,n=p.length;n>r;r++)if(f=p[r],!o[f](s,i[f]))return!1;return!0}return h.isEqual(s,i)},1===u.length?n(null,a(r,u[0])):(c=function(e){return function(t,r){var i,o,s,f,p;if(t)return n(t);if(s=u.shift(),"id"===s&&(s=e.model_type.prototype.idAttribute),u.length)return(p=l.relation(s))&&!p.embed?p.cursor(r,s).toJSON(c):c(null,r[s]);if(!h.isArray(r))return n(null,a(r,s));for(i=0,f=r.length;f>i;i++)if(o=r[i],a(o,s))return n(null,!0);return n(null,!1)}}(this))(null,r)},t}(n)},function(e,t,r){var n,i,o,s,a,u,l,c,h,f,p=function(e,t){function r(){this.constructor=e}for(var n in t)d.call(t,n)&&(e[n]=t[n]);return r.prototype=t.prototype,e.prototype=new r,e.__super__=t.prototype,e},d={}.hasOwnProperty;l=r(25),n=r(2),h=r(1),i=r(3),o=r(32),u=r(11),a=r(33),s=r(34),f=null,e.exports=c=function(){function e(){}return e.resetSchemas=function(t,r,n){var o,s,a,u,l;for(2===arguments.length&&(l=[{},r],r=l[0],n=l[1]),s=0,a=t.length;a>s;s++)u=t[s],u.schema();return o=[],e.each(t,function(e,t){return e.resetSchema(r,function(r){return r&&(o.push(e.model_name),console.log("Error when dropping schema for "+e.model_name+". "+r)),t()})},function(e){return r.verbose&&console.log(t.length-o.length+" schemas dropped."),i.model_cache.reset(),o.length?n(new Error("Failed to migrate schemas: "+o.join(", "))):n()})},e.bbCallback=function(e){return{success:function(t,r,n){return e(null,t,r,n)},error:function(t,r,n){return e(r||new Error("Backbone call failed"),t,r,n)}}},e.wrapOptions=function(t,r){return null==t&&(t={}),h.isFunction(t)&&(t=e.bbCallback(t)),h.defaults(e.bbCallback(function(e,n,i,o){return r(e,n,i,t)}),t)},e.isModel=function(e){return e&&e.attributes&&(e instanceof n.Model||e.parse&&e.fetch)},e.isCollection=function(e){return e&&e.models&&(e instanceof n.Collection||e.reset&&e.fetch)},e.get=function(e,t,r){return e._orm&&e._orm.hasOwnProperty(t)?e._orm[t]:r},e.set=function(e,t,r){return(e._orm||(e._orm={}))[t]=r},e.orSet=function(e,t,r){return(e._orm||(e._orm={})).hasOwnProperty(t)||(e._orm[t]=r),e._orm[t]},e.unset=function(e,t){return delete(e._orm||(e._orm={}))[t]},e.findOrGenerateModelName=function(e){var t,r;if(e.prototype.model_name)return e.prototype.model_name;if((r=h.result(new e,"url"))&&(t=new o(r).modelName()))return t;if(e.name)return e.name;throw"Could not find or generate model name for "+e},e.configureCollectionModelType=function(e,t){var r,i,o;return i=function(){var t,r;return t=h.result(this.collection||e.prototype,"url"),this.isNew()||(r=l.parse(t),r.pathname=r.pathname+"/encodeURIComponent(@id)",t=l.format(r)),t},o=e.prototype.model,o&&o!==n.Model?(o.prototype.sync===n.Model.prototype.sync&&(o.prototype.url=i,o.prototype.schema=e.prototype.schema,o.prototype.sync=t(o)),o):(r=function(r){function n(){return n.__super__.constructor.apply(this,arguments)}return p(n,r),n.prototype.url=i,n.prototype.schema=e.prototype.schema,n.prototype.sync=t(n),n}(n.Model),e.prototype.model=r)},e.configureModelType=function(e){return f||(f=r(35)),f(e)},e.patchRemove=function(e,t,r){var n,i,o,s,a,l;if(!(l=e.schema()))return r();o=new u(1),s=l.relations,n=function(e){return o.defer(function(r){return e.patchRemove(t,r)})};for(i in s)a=s[i],n(a);return o.await(r)},e.patchRemoveByJSON=function(t,r,n){return e.patchRemove(t,r,n)},e.presaveBelongsToRelationships=function(e,t){var r,n,i,o,s,a,l,c,h,f,p;if(!e.schema)return t();s=new u(1),f=e.schema(),a=f.relations;for(i in a)if(h=a[i],"belongsTo"===h.type&&!h.isVirtual()&&(p=e.get(i)))for(c=p.models?p.models:[p],r=function(e){return function(e){return s.defer(function(t){return e.save(t)})}}(this),n=0,o=c.length;o>n;n++)l=c[n],l.id||r(l);return s.await(t)},e.dataId=function(e){return h.isObject(e)?e.id:e},e.dataIsSameModel=function(t,r){return e.dataId(t)||e.dataId(r)?e.dataId(t)===e.dataId(r):h.isEqual(t,r)},e.dataToModel=function(t,r){var n,i,o;return t?h.isArray(t)?function(){var n,o,s;for(s=[],n=0,o=t.length;o>n;n++)i=t[n],s.push(e.dataToModel(i,r));return s}():(e.isModel(t)?o=t:e.dataId(t)!==t?o=new r(r.prototype.parse(t)):((n={})[r.prototype.idAttribute]=t,o=new r(n),o.setLoaded(!1)),o):null},e.updateModel=function(t,r){return!r||t===r||r._orm_needs_load?t:(e.isModel(r)&&(r=r.toJSON()),e.dataId(r)!==r&&(t.setLoaded(!0),t.set(r)),t)},e.updateOrNew=function(t,r){var n,i,o;return(n=r.cache)&&(i=e.dataId(t))&&(e.isModel(t)&&t.isLoaded()?o=t:(o=n.get(i))&&e.updateModel(o,t)),o||(o=e.isModel(t)?t:e.dataToModel(t,r),o&&n&&n.set(o.id,o)),o},e.modelJSONSave=function(t,r,i){var o,s;if(r._orm||(r._orm={}),!r._orm.model_type_json){try{s=h.result(new r,"url")}catch(a){}r._orm.model_type_json=o=function(e){function t(){return t.__super__.constructor.apply(this,arguments)}return p(t,e),t.prototype._orm_never_cache=!0,t.prototype.urlRoot=function(){return s},t}(n.Model)}return r.prototype.whitelist&&(t=h.pick(t,r.prototype.whitelist)),r.prototype.sync("update",new r._orm.model_type_json(t),e.bbCallback(i))},e.each=s.each,e.eachC=function(e,t,r){return s.each(e,r,t)},e.popEach=s.popEach,e.popEachC=function(e,t,r){return s.popEach(e,r,t)},e.eachDone=s.eachDone,e.eachDoneC=function(e,t,r){return s.eachDone(e,r,t)},e.isSorted=function(e,t){var r,n,i,o;for(t=h.uniq(t),r=0,i=e.length;i>r;r++){if(o=e[r],n&&1===this.fieldCompare(n,o,t))return!1;n=o}return!0},e.fieldCompare=function(e,t,r){var n,i;return i=r[0],h.isArray(i)&&(i=i[0]),"-"===i.charAt(0)&&(i=i.substr(1),n=!0),e.get(i)===t.get(i)?r.length>1?this.fieldCompare(e,t,r.splice(1)):0:n?e.get(i)<t.get(i)?1:-1:e.get(i)>t.get(i)?1:-1},e.jsonFieldCompare=function(e,t,r){var n,i;return i=r[0],h.isArray(i)&&(i=i[0]),"-"===i.charAt(0)&&(i=i.substr(1),n=!0),e[i]===t[i]?r.length>1?this.jsonFieldCompare(e,t,r.splice(1)):0:n?a.stringify(e[i])<a.stringify(t[i])?1:-1:a.stringify(e[i])>a.stringify(t[i])?1:-1},e}()},function(e,t,r){function n(){this.protocol=null,this.slashes=null,this.auth=null,this.host=null,this.port=null,this.hostname=null,this.hash=null,this.search=null,this.query=null,this.pathname=null,this.path=null,this.href=null}function i(e,t,r){if(e&&l.isObject(e)&&e instanceof n)return e;var i=new n;return i.parse(e,t,r),i}function o(e){return l.isString(e)&&(e=i(e)),e instanceof n?e.format():n.prototype.format.call(e)}function s(e,t){return i(e,!1,!0).resolve(t)}function a(e,t){return e?i(e,!1,!0).resolveObject(t):t}var u={encode:function(e){return e}},l=r(1);r(26);t.parse=i,t.resolve=s,t.resolveObject=a,t.format=o,t.Url=n;var c=/^([a-z0-9.+-]+:)/i,h=/:[0-9]*$/,f=["<",">",'"',"`"," ","\r","\n"," "],p=["{","}","|","\\","^","`"].concat(f),d=["'"].concat(p),y=["%","/","?",";","#"].concat(d),g=["/","?","#"],m=255,v=/^[a-z0-9A-Z_-]{0,63}$/,_=/^([a-z0-9A-Z_-]{0,63})(.*)$/,w={javascript:!0,"javascript:":!0},b={javascript:!0,"javascript:":!0},E={http:!0,https:!0,ftp:!0,gopher:!0,file:!0,"http:":!0,"https:":!0,"ftp:":!0,"gopher:":!0,"file:":!0},k=r(27);n.prototype.parse=function(e,t,r){if(!l.isString(e))throw new TypeError("Parameter 'url' must be a string, not "+typeof e);var n=e.split("#");n[0]=n[0].replace(/\\/g,"/"),e=n.join("#");var i=e;i=i.trim();var o=c.exec(i);if(o){o=o[0];var s=o.toLowerCase();this.protocol=s,i=i.substr(o.length)}if(r||o||i.match(/^\/\/[^@\/]+@[^@\/]+/)){var a="//"===i.substr(0,2);!a||o&&b[o]||(i=i.substr(2),this.slashes=!0)}if(!b[o]&&(a||o&&!E[o])){for(var h=-1,f=0;f<g.length;f++){var p=i.indexOf(g[f]);-1!==p&&(-1===h||h>p)&&(h=p)}var x,O;O=-1===h?i.lastIndexOf("@"):i.lastIndexOf("@",h),-1!==O&&(x=i.slice(0,O),i=i.slice(O+1),this.auth=decodeURIComponent(x)),h=-1;for(var f=0;f<y.length;f++){var p=i.indexOf(y[f]);-1!==p&&(-1===h||h>p)&&(h=p)}-1===h&&(h=i.length),this.host=i.slice(0,h),i=i.slice(h),this.parseHost(),this.hostname=this.hostname||"";var $="["===this.hostname[0]&&"]"===this.hostname[this.hostname.length-1];if(!$)for(var A=this.hostname.split(/\./),f=0,S=A.length;S>f;f++){var R=A[f];if(R&&!R.match(v)){for(var I="",N=0,C=R.length;C>N;N++)I+=R.charCodeAt(N)>127?"x":R[N];if(!I.match(v)){var T=A.slice(0,f),j=A.slice(f+1),M=R.match(_);M&&(T.push(M[1]),j.unshift(M[2])),j.length&&(i="/"+j.join(".")+i),this.hostname=T.join(".");break}}}if(this.hostname.length>m?this.hostname="":this.hostname=this.hostname.toLowerCase(),!$){for(var U=this.hostname.split("."),L=[],f=0;f<U.length;++f){var B=U[f];L.push(B.match(/[^A-Za-z0-9_-]/)?"xn--"+u.encode(B):B)}this.hostname=L.join(".")}var P=this.port?":"+this.port:"",z=this.hostname||"";this.host=z+P,this.href+=this.host,$&&(this.hostname=this.hostname.substr(1,this.hostname.length-2),"/"!==i[0]&&(i="/"+i))}if(!w[s])for(var f=0,S=d.length;S>f;f++){var J=d[f],D=encodeURIComponent(J);D===J&&(D=escape(J)),i=i.split(J).join(D)}var q=i.indexOf("#");-1!==q&&(this.hash=i.substr(q),i=i.slice(0,q));var F=i.indexOf("?");if(-1!==F?(this.search=i.substr(F),this.query=i.substr(F+1),t&&(this.query=k.parse(this.query)),i=i.slice(0,F)):t&&(this.search="",this.query={}),i&&(this.pathname=i),E[s]&&this.hostname&&!this.pathname&&(this.pathname="/"),this.pathname||this.search){var P=this.pathname||"",B=this.search||"";this.path=P+B}return this.href=this.format(),this},n.prototype.format=function(){var e=this.auth||"";e&&(e=encodeURIComponent(e),e=e.replace(/%3A/i,":"),e+="@");var t=this.protocol||"",r=this.pathname||"",n=this.hash||"",i=!1,o="";this.host?i=e+this.host:this.hostname&&(i=e+(-1===this.hostname.indexOf(":")?this.hostname:"["+this.hostname+"]"),this.port&&(i+=":"+this.port)),this.query&&l.isObject(this.query)&&Object.keys(this.query).length&&(o=k.stringify(this.query));var s=this.search||o&&"?"+o||"";return t&&":"!==t.substr(-1)&&(t+=":"),this.slashes||(!t||E[t])&&i!==!1?(i="//"+(i||""),r&&"/"!==r.charAt(0)&&(r="/"+r)):i||(i=""),n&&"#"!==n.charAt(0)&&(n="#"+n),s&&"?"!==s.charAt(0)&&(s="?"+s),r=r.replace(/[?#]/g,function(e){return encodeURIComponent(e)}),s=s.replace("#","%23"),t+i+r+s+n},n.prototype.resolve=function(e){return this.resolveObject(i(e,!1,!0)).format()},n.prototype.resolveObject=function(e){if(l.isString(e)){var t=new n;t.parse(e,!1,!0),e=t}var r=new n;if(Object.keys(this).forEach(function(e){r[e]=this[e]},this),r.hash=e.hash,""===e.href)return r.href=r.format(),r;if(e.slashes&&!e.protocol)return Object.keys(e).forEach(function(t){"protocol"!==t&&(r[t]=e[t])}),E[r.protocol]&&r.hostname&&!r.pathname&&(r.path=r.pathname="/"),r.href=r.format(),r;if(e.protocol&&e.protocol!==r.protocol){if(!E[e.protocol])return Object.keys(e).forEach(function(t){r[t]=e[t]}),r.href=r.format(),r;if(r.protocol=e.protocol,e.host||b[e.protocol])r.pathname=e.pathname;else{for(var i=(e.pathname||"").split("/");i.length&&!(e.host=i.shift()););e.host||(e.host=""),e.hostname||(e.hostname=""),""!==i[0]&&i.unshift(""),i.length<2&&i.unshift(""),r.pathname=i.join("/")}if(r.search=e.search,r.query=e.query,r.host=e.host||"",r.auth=e.auth,r.hostname=e.hostname||e.host,r.port=e.port,r.pathname||r.search){var o=r.pathname||"",s=r.search||"";r.path=o+s}return r.slashes=r.slashes||e.slashes,r.href=r.format(),r}var a=r.pathname&&"/"===r.pathname.charAt(0),u=e.host||e.pathname&&"/"===e.pathname.charAt(0),c=u||a||r.host&&e.pathname,h=c,f=r.pathname&&r.pathname.split("/")||[],i=e.pathname&&e.pathname.split("/")||[],p=r.protocol&&!E[r.protocol];if(p&&(r.hostname="",r.port=null,r.host&&(""===f[0]?f[0]=r.host:f.unshift(r.host)),r.host="",e.protocol&&(e.hostname=null,e.port=null,e.host&&(""===i[0]?i[0]=e.host:i.unshift(e.host)),e.host=null),c=c&&(""===i[0]||""===f[0])),u)r.host=e.host||""===e.host?e.host:r.host,r.hostname=e.hostname||""===e.hostname?e.hostname:r.hostname,r.search=e.search,r.query=e.query,f=i;else if(i.length)f||(f=[]),f.pop(),f=f.concat(i),r.search=e.search,r.query=e.query;else if(!l.isNull(e.search)&&!l.isUndefined(e.search)){if(p){r.hostname=r.host=f.shift();var d=r.host&&r.host.indexOf("@")>0?r.host.split("@"):!1;d&&(r.auth=d.shift(),r.host=r.hostname=d.shift())}return r.search=e.search,r.query=e.query,l.isNull(r.pathname)&&l.isNull(r.search)||(r.path=(r.pathname?r.pathname:"")+(r.search?r.search:"")),r.href=r.format(),r}if(!f.length)return r.pathname=null,r.search?r.path="/"+r.search:r.path=null,r.href=r.format(),r;for(var y=f.slice(-1)[0],g=(r.host||e.host)&&("."===y||".."===y)||""===y,m=0,v=f.length;v>=0;v--)y=f[v],"."===y?f.splice(v,1):".."===y?(f.splice(v,1),m++):m&&(f.splice(v,1),m--);if(!c&&!h)for(;m--;m)f.unshift("..");!c||""===f[0]||f[0]&&"/"===f[0].charAt(0)||f.unshift(""),g&&"/"!==f.join("/").substr(-1)&&f.push("");var _=""===f[0]||f[0]&&"/"===f[0].charAt(0);if(p){r.hostname=r.host=_?"":f.length?f.shift():"";var d=r.host&&r.host.indexOf("@")>0?r.host.split("@"):!1;d&&(r.auth=d.shift(),r.host=r.hostname=d.shift())}return c=c||r.host&&f.length,c&&!_&&f.unshift(""),f.length?r.pathname=f.join("/"):(r.pathname=null,r.path=null),l.isNull(r.pathname)&&l.isNull(r.search)||(r.path=(r.pathname?r.pathname:"")+(r.search?r.search:"")),r.auth=e.auth||r.auth,r.slashes=r.slashes||e.slashes,r.href=r.format(),r},n.prototype.parseHost=function(){var e=this.host,t=h.exec(e);t&&(t=t[0],":"!==t&&(this.port=t.substr(1)),e=e.substr(0,e.length-t.length)),e&&(this.hostname=e)}},function(e,t){t.forEach=function(e,t,r){if(e.forEach)return e.forEach(t,r);for(var n=0;n<e.length;n++)t.call(r,e[n],n,e)},"b"!=="ab".substr(-1)?t.substr=function(e,t,r){return 0>t&&(t=e.length+t),e.substr(t,r)}:t.substr=function(e,t,r){return e.substr(t,r)},t.trim=function(e){return e.trim?e.trim():e.replace(/^\s+|\s+$/g,"")}},function(e,t,r){(function(e){function n(e,t){return Object.prototype.hasOwnProperty.call(e,t)}function i(e){return e.charCodeAt(0)}var o=t,s=r(1);o.unescapeBuffer=function(t,r){for(var n,o,s,a=new e(t.length),u="CHAR",l=0,c=0;l<=t.length;l++){var h=t.charCodeAt(l);switch(u){case"CHAR":switch(h){case i("%"):n=0,o=0,u="HEX0";break;case i("+"):r&&(h=i(" "));default:a[c++]=h}break;case"HEX0":if(u="HEX1",s=h,i("0")<=h&&h<=i("9"))n=h-i("0");else if(i("a")<=h&&h<=i("f"))n=h-i("a")+10;else{if(!(i("A")<=h&&h<=i("F"))){a[c++]=i("%"),a[c++]=h,u="CHAR";break}n=h-i("A")+10}break;case"HEX1":if(u="CHAR",i("0")<=h&&h<=i("9"))o=h-i("0");else if(i("a")<=h&&h<=i("f"))o=h-i("a")+10;else{if(!(i("A")<=h&&h<=i("F"))){a[c++]=i("%"),a[c++]=s,a[c++]=h;break}o=h-i("A")+10}a[c++]=16*n+o}}return a.slice(0,c-1)},o.unescape=function(e,t){return o.unescapeBuffer(e,t).toString()},o.escape=function(e){return encodeURIComponent(e)};var a=function(e){return s.isString(e)?e:s.isBoolean(e)?e?"true":"false":s.isNumber(e)&&isFinite(e)?e:""};o.stringify=o.encode=function(e,t,r,n){t=t||"&",r=r||"=",s.isNull(e)&&(e=void 0);var i=o.escape;return n&&"function"==typeof n.encodeURIComponent&&(i=n.encodeURIComponent),s.isObject(e)?Object.keys(e).map(function(n){var o=i(a(n))+r;return s.isArray(e[n])?e[n].map(function(e){return o+i(a(e))}).join(t):o+i(a(e[n]))}).join(t):""},o.parse=o.decode=function(e,t,r,i){t=t||"&",r=r||"=";var a={};if(!s.isString(e)||0===e.length)return a;var u=/\+/g;e=e.split(t);var l=1e3;i&&s.isNumber(i.maxKeys)&&(l=i.maxKeys);var c=e.length;l>0&&c>l&&(c=l);var h=decodeURIComponent;i&&"function"==typeof i.decodeURIComponent&&(h=i.decodeURIComponent);for(var f=0;c>f;++f){var p,d,y,g,m=e[f].replace(u,"%20"),v=m.indexOf(r);v>=0?(p=m.substr(0,v),d=m.substr(v+1)):(p=m,d="");try{y=h(p),g=h(d)}catch(_){y=o.unescape(p,!0),g=o.unescape(d,!0)}n(a,y)?s.isArray(a[y])?a[y].push(g):a[y]=[a[y],g]:a[y]=g}return a}}).call(t,r(28).Buffer)},function(e,t,r){(function(e,n){"use strict";function i(){function e(){}try{var t=new Uint8Array(1);return t.foo=function(){return 42},t.constructor=e,42===t.foo()&&t.constructor===e&&"function"==typeof t.subarray&&0===t.subarray(1,1).byteLength}catch(r){return!1}}function o(){return e.TYPED_ARRAY_SUPPORT?2147483647:1073741823}function e(t){return this instanceof e?(e.TYPED_ARRAY_SUPPORT||(this.length=0,this.parent=void 0),"number"==typeof t?s(this,t):"string"==typeof t?a(this,t,arguments.length>1?arguments[1]:"utf8"):u(this,t)):arguments.length>1?new e(t,arguments[1]):new e(t)}function s(t,r){if(t=y(t,0>r?0:0|g(r)),!e.TYPED_ARRAY_SUPPORT)for(var n=0;r>n;n++)t[n]=0;return t}function a(e,t,r){("string"!=typeof r||""===r)&&(r="utf8");var n=0|v(t,r);return e=y(e,n),e.write(t,r),e}function u(t,r){if(e.isBuffer(r))return l(t,r);if(G(r))return c(t,r);if(null==r)throw new TypeError("must start with number, buffer, array or string");if("undefined"!=typeof ArrayBuffer){if(r.buffer instanceof ArrayBuffer)return h(t,r);if(r instanceof ArrayBuffer)return f(t,r)}return r.length?p(t,r):d(t,r)}function l(e,t){var r=0|g(t.length);return e=y(e,r),t.copy(e,0,0,r),e}function c(e,t){var r=0|g(t.length);e=y(e,r);for(var n=0;r>n;n+=1)e[n]=255&t[n];return e}function h(e,t){var r=0|g(t.length);e=y(e,r);for(var n=0;r>n;n+=1)e[n]=255&t[n];return e}function f(t,r){return e.TYPED_ARRAY_SUPPORT?(r.byteLength,t=e._augment(new Uint8Array(r))):t=h(t,new Uint8Array(r)),t}function p(e,t){var r=0|g(t.length);e=y(e,r);for(var n=0;r>n;n+=1)e[n]=255&t[n];return e}function d(e,t){var r,n=0;"Buffer"===t.type&&G(t.data)&&(r=t.data,n=0|g(r.length)),e=y(e,n);for(var i=0;n>i;i+=1)e[i]=255&r[i];return e}function y(t,r){e.TYPED_ARRAY_SUPPORT?(t=e._augment(new Uint8Array(r)),t.__proto__=e.prototype):(t.length=r,t._isBuffer=!0);var n=0!==r&&r<=e.poolSize>>>1;return n&&(t.parent=X),t}function g(e){if(e>=o())throw new RangeError("Attempt to allocate Buffer larger than maximum size: 0x"+o().toString(16)+" bytes");return 0|e}function m(t,r){if(!(this instanceof m))return new m(t,r);var n=new e(t,r);return delete n.parent,n}function v(e,t){"string"!=typeof e&&(e=""+e);var r=e.length;if(0===r)return 0;for(var n=!1;;)switch(t){case"ascii":case"binary":case"raw":case"raws":return r;case"utf8":case"utf-8":return q(e).length;case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return 2*r;case"hex":return r>>>1;case"base64":return Q(e).length;default:if(n)return q(e).length;t=(""+t).toLowerCase(),n=!0}}function _(e,t,r){var n=!1;if(t=0|t,r=void 0===r||r===1/0?this.length:0|r,e||(e="utf8"),0>t&&(t=0),r>this.length&&(r=this.length),t>=r)return"";for(;;)switch(e){case"hex":return N(this,t,r);case"utf8":case"utf-8":return A(this,t,r);case"ascii":return R(this,t,r);case"binary":return I(this,t,r);case"base64":return $(this,t,r);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return C(this,t,r);default:if(n)throw new TypeError("Unknown encoding: "+e);e=(e+"").toLowerCase(),n=!0}}function w(e,t,r,n){r=Number(r)||0;var i=e.length-r;n?(n=Number(n),n>i&&(n=i)):n=i;var o=t.length;if(o%2!==0)throw new Error("Invalid hex string");n>o/2&&(n=o/2);for(var s=0;n>s;s++){var a=parseInt(t.substr(2*s,2),16);if(isNaN(a))throw new Error("Invalid hex string");e[r+s]=a}return s}function b(e,t,r,n){return H(q(t,e.length-r),e,r,n)}function E(e,t,r,n){return H(F(t),e,r,n)}function k(e,t,r,n){return E(e,t,r,n)}function x(e,t,r,n){return H(Q(t),e,r,n)}function O(e,t,r,n){return H(Y(t,e.length-r),e,r,n)}function $(e,t,r){return 0===t&&r===e.length?K.fromByteArray(e):K.fromByteArray(e.slice(t,r))}function A(e,t,r){r=Math.min(e.length,r);for(var n=[],i=t;r>i;){var o=e[i],s=null,a=o>239?4:o>223?3:o>191?2:1;if(r>=i+a){var u,l,c,h;switch(a){case 1:128>o&&(s=o);break;case 2:u=e[i+1],128===(192&u)&&(h=(31&o)<<6|63&u,h>127&&(s=h));break;case 3:u=e[i+1],l=e[i+2],128===(192&u)&&128===(192&l)&&(h=(15&o)<<12|(63&u)<<6|63&l,h>2047&&(55296>h||h>57343)&&(s=h));break;case 4:u=e[i+1],l=e[i+2],c=e[i+3],128===(192&u)&&128===(192&l)&&128===(192&c)&&(h=(15&o)<<18|(63&u)<<12|(63&l)<<6|63&c,h>65535&&1114112>h&&(s=h))}}null===s?(s=65533,a=1):s>65535&&(s-=65536,n.push(s>>>10&1023|55296),s=56320|1023&s),n.push(s),i+=a}return S(n)}function S(e){var t=e.length;if(Z>=t)return String.fromCharCode.apply(String,e);for(var r="",n=0;t>n;)r+=String.fromCharCode.apply(String,e.slice(n,n+=Z));return r}function R(e,t,r){var n="";r=Math.min(e.length,r);for(var i=t;r>i;i++)n+=String.fromCharCode(127&e[i]);return n}function I(e,t,r){var n="";r=Math.min(e.length,r);for(var i=t;r>i;i++)n+=String.fromCharCode(e[i]);return n}function N(e,t,r){var n=e.length;(!t||0>t)&&(t=0),(!r||0>r||r>n)&&(r=n);for(var i="",o=t;r>o;o++)i+=D(e[o]);return i}function C(e,t,r){for(var n=e.slice(t,r),i="",o=0;o<n.length;o+=2)i+=String.fromCharCode(n[o]+256*n[o+1]);return i}function T(e,t,r){if(e%1!==0||0>e)throw new RangeError("offset is not uint");if(e+t>r)throw new RangeError("Trying to access beyond buffer length")}function j(t,r,n,i,o,s){if(!e.isBuffer(t))throw new TypeError("buffer must be a Buffer instance");if(r>o||s>r)throw new RangeError("value is out of bounds");
if(n+i>t.length)throw new RangeError("index out of range")}function M(e,t,r,n){0>t&&(t=65535+t+1);for(var i=0,o=Math.min(e.length-r,2);o>i;i++)e[r+i]=(t&255<<8*(n?i:1-i))>>>8*(n?i:1-i)}function U(e,t,r,n){0>t&&(t=4294967295+t+1);for(var i=0,o=Math.min(e.length-r,4);o>i;i++)e[r+i]=t>>>8*(n?i:3-i)&255}function L(e,t,r,n,i,o){if(t>i||o>t)throw new RangeError("value is out of bounds");if(r+n>e.length)throw new RangeError("index out of range");if(0>r)throw new RangeError("index out of range")}function B(e,t,r,n,i){return i||L(e,t,r,4,3.4028234663852886e38,-3.4028234663852886e38),V.write(e,t,r,n,23,4),r+4}function P(e,t,r,n,i){return i||L(e,t,r,8,1.7976931348623157e308,-1.7976931348623157e308),V.write(e,t,r,n,52,8),r+8}function z(e){if(e=J(e).replace(ee,""),e.length<2)return"";for(;e.length%4!==0;)e+="=";return e}function J(e){return e.trim?e.trim():e.replace(/^\s+|\s+$/g,"")}function D(e){return 16>e?"0"+e.toString(16):e.toString(16)}function q(e,t){t=t||1/0;for(var r,n=e.length,i=null,o=[],s=0;n>s;s++){if(r=e.charCodeAt(s),r>55295&&57344>r){if(!i){if(r>56319){(t-=3)>-1&&o.push(239,191,189);continue}if(s+1===n){(t-=3)>-1&&o.push(239,191,189);continue}i=r;continue}if(56320>r){(t-=3)>-1&&o.push(239,191,189),i=r;continue}r=(i-55296<<10|r-56320)+65536}else i&&(t-=3)>-1&&o.push(239,191,189);if(i=null,128>r){if((t-=1)<0)break;o.push(r)}else if(2048>r){if((t-=2)<0)break;o.push(r>>6|192,63&r|128)}else if(65536>r){if((t-=3)<0)break;o.push(r>>12|224,r>>6&63|128,63&r|128)}else{if(!(1114112>r))throw new Error("Invalid code point");if((t-=4)<0)break;o.push(r>>18|240,r>>12&63|128,r>>6&63|128,63&r|128)}}return o}function F(e){for(var t=[],r=0;r<e.length;r++)t.push(255&e.charCodeAt(r));return t}function Y(e,t){for(var r,n,i,o=[],s=0;s<e.length&&!((t-=2)<0);s++)r=e.charCodeAt(s),n=r>>8,i=r%256,o.push(i),o.push(n);return o}function Q(e){return K.toByteArray(z(e))}function H(e,t,r,n){for(var i=0;n>i&&!(i+r>=t.length||i>=e.length);i++)t[i+r]=e[i];return i}var K=r(29),V=r(30),G=r(31);t.Buffer=e,t.SlowBuffer=m,t.INSPECT_MAX_BYTES=50,e.poolSize=8192;var X={};e.TYPED_ARRAY_SUPPORT=void 0!==n.TYPED_ARRAY_SUPPORT?n.TYPED_ARRAY_SUPPORT:i(),e.TYPED_ARRAY_SUPPORT?(e.prototype.__proto__=Uint8Array.prototype,e.__proto__=Uint8Array):(e.prototype.length=void 0,e.prototype.parent=void 0),e.isBuffer=function(e){return!(null==e||!e._isBuffer)},e.compare=function(t,r){if(!e.isBuffer(t)||!e.isBuffer(r))throw new TypeError("Arguments must be Buffers");if(t===r)return 0;for(var n=t.length,i=r.length,o=0,s=Math.min(n,i);s>o&&t[o]===r[o];)++o;return o!==s&&(n=t[o],i=r[o]),i>n?-1:n>i?1:0},e.isEncoding=function(e){switch(String(e).toLowerCase()){case"hex":case"utf8":case"utf-8":case"ascii":case"binary":case"base64":case"raw":case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return!0;default:return!1}},e.concat=function(t,r){if(!G(t))throw new TypeError("list argument must be an Array of Buffers.");if(0===t.length)return new e(0);var n;if(void 0===r)for(r=0,n=0;n<t.length;n++)r+=t[n].length;var i=new e(r),o=0;for(n=0;n<t.length;n++){var s=t[n];s.copy(i,o),o+=s.length}return i},e.byteLength=v,e.prototype.toString=function(){var e=0|this.length;return 0===e?"":0===arguments.length?A(this,0,e):_.apply(this,arguments)},e.prototype.equals=function(t){if(!e.isBuffer(t))throw new TypeError("Argument must be a Buffer");return this===t?!0:0===e.compare(this,t)},e.prototype.inspect=function(){var e="",r=t.INSPECT_MAX_BYTES;return this.length>0&&(e=this.toString("hex",0,r).match(/.{2}/g).join(" "),this.length>r&&(e+=" ... ")),"<Buffer "+e+">"},e.prototype.compare=function(t){if(!e.isBuffer(t))throw new TypeError("Argument must be a Buffer");return this===t?0:e.compare(this,t)},e.prototype.indexOf=function(t,r){function n(e,t,r){for(var n=-1,i=0;r+i<e.length;i++)if(e[r+i]===t[-1===n?0:i-n]){if(-1===n&&(n=i),i-n+1===t.length)return r+n}else n=-1;return-1}if(r>2147483647?r=2147483647:-2147483648>r&&(r=-2147483648),r>>=0,0===this.length)return-1;if(r>=this.length)return-1;if(0>r&&(r=Math.max(this.length+r,0)),"string"==typeof t)return 0===t.length?-1:String.prototype.indexOf.call(this,t,r);if(e.isBuffer(t))return n(this,t,r);if("number"==typeof t)return e.TYPED_ARRAY_SUPPORT&&"function"===Uint8Array.prototype.indexOf?Uint8Array.prototype.indexOf.call(this,t,r):n(this,[t],r);throw new TypeError("val must be string, number or Buffer")},e.prototype.get=function(e){return console.log(".get() is deprecated. Access using array indexes instead."),this.readUInt8(e)},e.prototype.set=function(e,t){return console.log(".set() is deprecated. Access using array indexes instead."),this.writeUInt8(e,t)},e.prototype.write=function(e,t,r,n){if(void 0===t)n="utf8",r=this.length,t=0;else if(void 0===r&&"string"==typeof t)n=t,r=this.length,t=0;else if(isFinite(t))t=0|t,isFinite(r)?(r=0|r,void 0===n&&(n="utf8")):(n=r,r=void 0);else{var i=n;n=t,t=0|r,r=i}var o=this.length-t;if((void 0===r||r>o)&&(r=o),e.length>0&&(0>r||0>t)||t>this.length)throw new RangeError("attempt to write outside buffer bounds");n||(n="utf8");for(var s=!1;;)switch(n){case"hex":return w(this,e,t,r);case"utf8":case"utf-8":return b(this,e,t,r);case"ascii":return E(this,e,t,r);case"binary":return k(this,e,t,r);case"base64":return x(this,e,t,r);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return O(this,e,t,r);default:if(s)throw new TypeError("Unknown encoding: "+n);n=(""+n).toLowerCase(),s=!0}},e.prototype.toJSON=function(){return{type:"Buffer",data:Array.prototype.slice.call(this._arr||this,0)}};var Z=4096;e.prototype.slice=function(t,r){var n=this.length;t=~~t,r=void 0===r?n:~~r,0>t?(t+=n,0>t&&(t=0)):t>n&&(t=n),0>r?(r+=n,0>r&&(r=0)):r>n&&(r=n),t>r&&(r=t);var i;if(e.TYPED_ARRAY_SUPPORT)i=e._augment(this.subarray(t,r));else{var o=r-t;i=new e(o,void 0);for(var s=0;o>s;s++)i[s]=this[s+t]}return i.length&&(i.parent=this.parent||this),i},e.prototype.readUIntLE=function(e,t,r){e=0|e,t=0|t,r||T(e,t,this.length);for(var n=this[e],i=1,o=0;++o<t&&(i*=256);)n+=this[e+o]*i;return n},e.prototype.readUIntBE=function(e,t,r){e=0|e,t=0|t,r||T(e,t,this.length);for(var n=this[e+--t],i=1;t>0&&(i*=256);)n+=this[e+--t]*i;return n},e.prototype.readUInt8=function(e,t){return t||T(e,1,this.length),this[e]},e.prototype.readUInt16LE=function(e,t){return t||T(e,2,this.length),this[e]|this[e+1]<<8},e.prototype.readUInt16BE=function(e,t){return t||T(e,2,this.length),this[e]<<8|this[e+1]},e.prototype.readUInt32LE=function(e,t){return t||T(e,4,this.length),(this[e]|this[e+1]<<8|this[e+2]<<16)+16777216*this[e+3]},e.prototype.readUInt32BE=function(e,t){return t||T(e,4,this.length),16777216*this[e]+(this[e+1]<<16|this[e+2]<<8|this[e+3])},e.prototype.readIntLE=function(e,t,r){e=0|e,t=0|t,r||T(e,t,this.length);for(var n=this[e],i=1,o=0;++o<t&&(i*=256);)n+=this[e+o]*i;return i*=128,n>=i&&(n-=Math.pow(2,8*t)),n},e.prototype.readIntBE=function(e,t,r){e=0|e,t=0|t,r||T(e,t,this.length);for(var n=t,i=1,o=this[e+--n];n>0&&(i*=256);)o+=this[e+--n]*i;return i*=128,o>=i&&(o-=Math.pow(2,8*t)),o},e.prototype.readInt8=function(e,t){return t||T(e,1,this.length),128&this[e]?-1*(255-this[e]+1):this[e]},e.prototype.readInt16LE=function(e,t){t||T(e,2,this.length);var r=this[e]|this[e+1]<<8;return 32768&r?4294901760|r:r},e.prototype.readInt16BE=function(e,t){t||T(e,2,this.length);var r=this[e+1]|this[e]<<8;return 32768&r?4294901760|r:r},e.prototype.readInt32LE=function(e,t){return t||T(e,4,this.length),this[e]|this[e+1]<<8|this[e+2]<<16|this[e+3]<<24},e.prototype.readInt32BE=function(e,t){return t||T(e,4,this.length),this[e]<<24|this[e+1]<<16|this[e+2]<<8|this[e+3]},e.prototype.readFloatLE=function(e,t){return t||T(e,4,this.length),V.read(this,e,!0,23,4)},e.prototype.readFloatBE=function(e,t){return t||T(e,4,this.length),V.read(this,e,!1,23,4)},e.prototype.readDoubleLE=function(e,t){return t||T(e,8,this.length),V.read(this,e,!0,52,8)},e.prototype.readDoubleBE=function(e,t){return t||T(e,8,this.length),V.read(this,e,!1,52,8)},e.prototype.writeUIntLE=function(e,t,r,n){e=+e,t=0|t,r=0|r,n||j(this,e,t,r,Math.pow(2,8*r),0);var i=1,o=0;for(this[t]=255&e;++o<r&&(i*=256);)this[t+o]=e/i&255;return t+r},e.prototype.writeUIntBE=function(e,t,r,n){e=+e,t=0|t,r=0|r,n||j(this,e,t,r,Math.pow(2,8*r),0);var i=r-1,o=1;for(this[t+i]=255&e;--i>=0&&(o*=256);)this[t+i]=e/o&255;return t+r},e.prototype.writeUInt8=function(t,r,n){return t=+t,r=0|r,n||j(this,t,r,1,255,0),e.TYPED_ARRAY_SUPPORT||(t=Math.floor(t)),this[r]=255&t,r+1},e.prototype.writeUInt16LE=function(t,r,n){return t=+t,r=0|r,n||j(this,t,r,2,65535,0),e.TYPED_ARRAY_SUPPORT?(this[r]=255&t,this[r+1]=t>>>8):M(this,t,r,!0),r+2},e.prototype.writeUInt16BE=function(t,r,n){return t=+t,r=0|r,n||j(this,t,r,2,65535,0),e.TYPED_ARRAY_SUPPORT?(this[r]=t>>>8,this[r+1]=255&t):M(this,t,r,!1),r+2},e.prototype.writeUInt32LE=function(t,r,n){return t=+t,r=0|r,n||j(this,t,r,4,4294967295,0),e.TYPED_ARRAY_SUPPORT?(this[r+3]=t>>>24,this[r+2]=t>>>16,this[r+1]=t>>>8,this[r]=255&t):U(this,t,r,!0),r+4},e.prototype.writeUInt32BE=function(t,r,n){return t=+t,r=0|r,n||j(this,t,r,4,4294967295,0),e.TYPED_ARRAY_SUPPORT?(this[r]=t>>>24,this[r+1]=t>>>16,this[r+2]=t>>>8,this[r+3]=255&t):U(this,t,r,!1),r+4},e.prototype.writeIntLE=function(e,t,r,n){if(e=+e,t=0|t,!n){var i=Math.pow(2,8*r-1);j(this,e,t,r,i-1,-i)}var o=0,s=1,a=0>e?1:0;for(this[t]=255&e;++o<r&&(s*=256);)this[t+o]=(e/s>>0)-a&255;return t+r},e.prototype.writeIntBE=function(e,t,r,n){if(e=+e,t=0|t,!n){var i=Math.pow(2,8*r-1);j(this,e,t,r,i-1,-i)}var o=r-1,s=1,a=0>e?1:0;for(this[t+o]=255&e;--o>=0&&(s*=256);)this[t+o]=(e/s>>0)-a&255;return t+r},e.prototype.writeInt8=function(t,r,n){return t=+t,r=0|r,n||j(this,t,r,1,127,-128),e.TYPED_ARRAY_SUPPORT||(t=Math.floor(t)),0>t&&(t=255+t+1),this[r]=255&t,r+1},e.prototype.writeInt16LE=function(t,r,n){return t=+t,r=0|r,n||j(this,t,r,2,32767,-32768),e.TYPED_ARRAY_SUPPORT?(this[r]=255&t,this[r+1]=t>>>8):M(this,t,r,!0),r+2},e.prototype.writeInt16BE=function(t,r,n){return t=+t,r=0|r,n||j(this,t,r,2,32767,-32768),e.TYPED_ARRAY_SUPPORT?(this[r]=t>>>8,this[r+1]=255&t):M(this,t,r,!1),r+2},e.prototype.writeInt32LE=function(t,r,n){return t=+t,r=0|r,n||j(this,t,r,4,2147483647,-2147483648),e.TYPED_ARRAY_SUPPORT?(this[r]=255&t,this[r+1]=t>>>8,this[r+2]=t>>>16,this[r+3]=t>>>24):U(this,t,r,!0),r+4},e.prototype.writeInt32BE=function(t,r,n){return t=+t,r=0|r,n||j(this,t,r,4,2147483647,-2147483648),0>t&&(t=4294967295+t+1),e.TYPED_ARRAY_SUPPORT?(this[r]=t>>>24,this[r+1]=t>>>16,this[r+2]=t>>>8,this[r+3]=255&t):U(this,t,r,!1),r+4},e.prototype.writeFloatLE=function(e,t,r){return B(this,e,t,!0,r)},e.prototype.writeFloatBE=function(e,t,r){return B(this,e,t,!1,r)},e.prototype.writeDoubleLE=function(e,t,r){return P(this,e,t,!0,r)},e.prototype.writeDoubleBE=function(e,t,r){return P(this,e,t,!1,r)},e.prototype.copy=function(t,r,n,i){if(n||(n=0),i||0===i||(i=this.length),r>=t.length&&(r=t.length),r||(r=0),i>0&&n>i&&(i=n),i===n)return 0;if(0===t.length||0===this.length)return 0;if(0>r)throw new RangeError("targetStart out of bounds");if(0>n||n>=this.length)throw new RangeError("sourceStart out of bounds");if(0>i)throw new RangeError("sourceEnd out of bounds");i>this.length&&(i=this.length),t.length-r<i-n&&(i=t.length-r+n);var o,s=i-n;if(this===t&&r>n&&i>r)for(o=s-1;o>=0;o--)t[o+r]=this[o+n];else if(1e3>s||!e.TYPED_ARRAY_SUPPORT)for(o=0;s>o;o++)t[o+r]=this[o+n];else t._set(this.subarray(n,n+s),r);return s},e.prototype.fill=function(e,t,r){if(e||(e=0),t||(t=0),r||(r=this.length),t>r)throw new RangeError("end < start");if(r!==t&&0!==this.length){if(0>t||t>=this.length)throw new RangeError("start out of bounds");if(0>r||r>this.length)throw new RangeError("end out of bounds");var n;if("number"==typeof e)for(n=t;r>n;n++)this[n]=e;else{var i=q(e.toString()),o=i.length;for(n=t;r>n;n++)this[n]=i[n%o]}return this}},e.prototype.toArrayBuffer=function(){if("undefined"!=typeof Uint8Array){if(e.TYPED_ARRAY_SUPPORT)return new e(this).buffer;for(var t=new Uint8Array(this.length),r=0,n=t.length;n>r;r+=1)t[r]=this[r];return t.buffer}throw new TypeError("Buffer.toArrayBuffer not supported in this browser")};var W=e.prototype;e._augment=function(t){return t.constructor=e,t._isBuffer=!0,t._set=t.set,t.get=W.get,t.set=W.set,t.write=W.write,t.toString=W.toString,t.toLocaleString=W.toString,t.toJSON=W.toJSON,t.equals=W.equals,t.compare=W.compare,t.indexOf=W.indexOf,t.copy=W.copy,t.slice=W.slice,t.readUIntLE=W.readUIntLE,t.readUIntBE=W.readUIntBE,t.readUInt8=W.readUInt8,t.readUInt16LE=W.readUInt16LE,t.readUInt16BE=W.readUInt16BE,t.readUInt32LE=W.readUInt32LE,t.readUInt32BE=W.readUInt32BE,t.readIntLE=W.readIntLE,t.readIntBE=W.readIntBE,t.readInt8=W.readInt8,t.readInt16LE=W.readInt16LE,t.readInt16BE=W.readInt16BE,t.readInt32LE=W.readInt32LE,t.readInt32BE=W.readInt32BE,t.readFloatLE=W.readFloatLE,t.readFloatBE=W.readFloatBE,t.readDoubleLE=W.readDoubleLE,t.readDoubleBE=W.readDoubleBE,t.writeUInt8=W.writeUInt8,t.writeUIntLE=W.writeUIntLE,t.writeUIntBE=W.writeUIntBE,t.writeUInt16LE=W.writeUInt16LE,t.writeUInt16BE=W.writeUInt16BE,t.writeUInt32LE=W.writeUInt32LE,t.writeUInt32BE=W.writeUInt32BE,t.writeIntLE=W.writeIntLE,t.writeIntBE=W.writeIntBE,t.writeInt8=W.writeInt8,t.writeInt16LE=W.writeInt16LE,t.writeInt16BE=W.writeInt16BE,t.writeInt32LE=W.writeInt32LE,t.writeInt32BE=W.writeInt32BE,t.writeFloatLE=W.writeFloatLE,t.writeFloatBE=W.writeFloatBE,t.writeDoubleLE=W.writeDoubleLE,t.writeDoubleBE=W.writeDoubleBE,t.fill=W.fill,t.inspect=W.inspect,t.toArrayBuffer=W.toArrayBuffer,t};var ee=/[^+\/0-9A-Za-z-_]/g}).call(t,r(28).Buffer,function(){return this}())},function(e,t,r){var n="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";!function(e){"use strict";function t(e){var t=e.charCodeAt(0);return t===s||t===h?62:t===a||t===f?63:u>t?-1:u+10>t?t-u+26+26:c+26>t?t-c:l+26>t?t-l+26:void 0}function r(e){function r(e){l[h++]=e}var n,i,s,a,u,l;if(e.length%4>0)throw new Error("Invalid string. Length must be a multiple of 4");var c=e.length;u="="===e.charAt(c-2)?2:"="===e.charAt(c-1)?1:0,l=new o(3*e.length/4-u),s=u>0?e.length-4:e.length;var h=0;for(n=0,i=0;s>n;n+=4,i+=3)a=t(e.charAt(n))<<18|t(e.charAt(n+1))<<12|t(e.charAt(n+2))<<6|t(e.charAt(n+3)),r((16711680&a)>>16),r((65280&a)>>8),r(255&a);return 2===u?(a=t(e.charAt(n))<<2|t(e.charAt(n+1))>>4,r(255&a)):1===u&&(a=t(e.charAt(n))<<10|t(e.charAt(n+1))<<4|t(e.charAt(n+2))>>2,r(a>>8&255),r(255&a)),l}function i(e){function t(e){return n.charAt(e)}function r(e){return t(e>>18&63)+t(e>>12&63)+t(e>>6&63)+t(63&e)}var i,o,s,a=e.length%3,u="";for(i=0,s=e.length-a;s>i;i+=3)o=(e[i]<<16)+(e[i+1]<<8)+e[i+2],u+=r(o);switch(a){case 1:o=e[e.length-1],u+=t(o>>2),u+=t(o<<4&63),u+="==";break;case 2:o=(e[e.length-2]<<8)+e[e.length-1],u+=t(o>>10),u+=t(o>>4&63),u+=t(o<<2&63),u+="="}return u}var o="undefined"!=typeof Uint8Array?Uint8Array:Array,s="+".charCodeAt(0),a="/".charCodeAt(0),u="0".charCodeAt(0),l="a".charCodeAt(0),c="A".charCodeAt(0),h="-".charCodeAt(0),f="_".charCodeAt(0);e.toByteArray=r,e.fromByteArray=i}(t)},function(e,t){t.read=function(e,t,r,n,i){var o,s,a=8*i-n-1,u=(1<<a)-1,l=u>>1,c=-7,h=r?i-1:0,f=r?-1:1,p=e[t+h];for(h+=f,o=p&(1<<-c)-1,p>>=-c,c+=a;c>0;o=256*o+e[t+h],h+=f,c-=8);for(s=o&(1<<-c)-1,o>>=-c,c+=n;c>0;s=256*s+e[t+h],h+=f,c-=8);if(0===o)o=1-l;else{if(o===u)return s?NaN:(p?-1:1)*(1/0);s+=Math.pow(2,n),o-=l}return(p?-1:1)*s*Math.pow(2,o-n)},t.write=function(e,t,r,n,i,o){var s,a,u,l=8*o-i-1,c=(1<<l)-1,h=c>>1,f=23===i?Math.pow(2,-24)-Math.pow(2,-77):0,p=n?0:o-1,d=n?1:-1,y=0>t||0===t&&0>1/t?1:0;for(t=Math.abs(t),isNaN(t)||t===1/0?(a=isNaN(t)?1:0,s=c):(s=Math.floor(Math.log(t)/Math.LN2),t*(u=Math.pow(2,-s))<1&&(s--,u*=2),t+=s+h>=1?f/u:f*Math.pow(2,1-h),t*u>=2&&(s++,u/=2),s+h>=c?(a=0,s=c):s+h>=1?(a=(t*u-1)*Math.pow(2,i),s+=h):(a=t*Math.pow(2,h-1)*Math.pow(2,i),s=0));i>=8;e[r+p]=255&a,p+=d,a/=256,i-=8);for(s=s<<i|a,l+=i;l>0;e[r+p]=255&s,p+=d,s/=256,l-=8);e[r+p-d]|=128*y}},function(e,t){var r={}.toString;e.exports=Array.isArray||function(e){return"[object Array]"==r.call(e)}},function(e,t,r){var n,i,o,s,a;a=r(1),s=r(25),n=r(3),o=["protocol","slashes","auth","host","hostname","port","search","query","hash","href"],e.exports=i=function(){function e(e,t,r){var n,i,u,l,c,h,f,p,d,y,g,m,v,_,w,b,E,k;if(k=s.parse(e,t,r),v=k.pathname.split(","),v.length>1){for(b=a.pick(k,"protocol","auth","slashes"),b.host="{1}",b.pathname="{2}",E=s.format(b),E=E.replace("{1}/{2}",""),_=k.pathname.split("/"),k.pathname="/"+_[_.length-2]+"/"+_[_.length-1],l=e.replace(E,""),l=l.substring(0,l.indexOf(k.pathname)),u=l.split(","),w=["host","hostname","port"],h=0,y=w.length;y>h;h++)d=w[h],delete k[d];for(this.hosts=[],f=0,g=u.length;g>f;f++)n=u[f],c=n.split(":"),this.hosts.push(1===c.length?{host:c[0],hostname:c[0]}:{host:c[0],hostname:c[0]+":"+c[1],port:c[1]})}for(i=a.compact(k.pathname.split("/")),this.table=i.pop(),this.database=i.join("/"),p=0,m=o.length;m>p;p++)d=o[p],k.hasOwnProperty(d)&&(this[d]=k[d])}return e.prototype.format=function(e){var t,r,n;return null==e&&(e={}),n=a.pick(this,o),n.pathname="",this.hosts&&(t=a.map(this.hosts,function(e){return""+e.host+(e.port?":"+e.port:"")}),n.pathname+=t.join(","),n.host="{1}"),this.database&&(n.pathname+="/"+this.database),this.table&&!e.exclude_table&&(n.pathname+="/"+this.table),(e.exclude_search||e.exclude_query)&&(delete n.search,delete n.query),r=s.format(n),this.hosts&&(r=r.replace("{1}/"+n.pathname,n.pathname)),r},e.prototype.parseAuth=function(){var e,t;return this.auth?(e=this.auth.split(":"),t={user:e[0]},t.password=e.length>1?e[1]:null,t):null},e.prototype.modelName=function(){return this.table?n.naming_conventions.modelName(this.table,!1):null},e}()},function(e,t,r){var n,i,o,s;s=r(1),o=r(11),n=r(34),e.exports=i=function(){function e(){}return e.stringify=function(e){var t,r;try{return JSON.stringify(e)}catch(r){return t=r,"Failed to stringify"}},e.isEmptyObject=function(e){var t;for(t in e)return!1;return!0},e.parseDates=function(t){var r,n,i;if(s.isString(t)){if(t.length>=20&&"Z"===t[t.length-1]&&!s.isNaN((r=new Date(t)).getTime()))return r}else if(s.isObject(t)||s.isArray(t))for(n in t)i=t[n],t[n]=e.parseDates(i);return t},e.parseField=function(t,r,n){var i;return"Integer"!==(null!=r?r.schema().idType(n):void 0)?e.parseDates(t):s.isNaN(i=+t)?(console.log("Warning: failed to convert key: "+n+" value: "+t+" to integer. Model: "+r.model_name),t):i},e.parse=function(t,r){var n,i,o;if(!s.isObject(t))return e.parseDates(t);if(s.isArray(t))return function(){var n,i,s;for(s=[],n=0,i=t.length;i>n;n++)o=t[n],s.push(e.parse(o,r));return s}();i={};for(n in t)o=t[n],i[n]=e.parseField(o,r,n);return i},e.parseQuery=function(t){var r,n,i;r={};for(n in t)if(i=t[n],r[n]=i,s.isString(i)&&i.length){try{i=JSON.parse(i)}catch(o){}r[n]=e.parseDates(i)}return r},e.querify=function(e){var t,r,n;r={};for(t in e)n=e[t],r[t]=JSON.stringify(n);return r},e.toQuery=function(e){return console.log("JSONUtils.toQuery has been deprecated. Use JSONUtils.querify instead")},e.renderTemplate=function(t,r,i,o){var a;return 3===arguments.length&&(o=i,i={}),s.isArray(t)?(a=[],n.each(t,function(t){return function(t,n){return e.renderTemplate(t,r,i,function(e,t){return e||a.push(t),n(e)})}}(this),function(e){return e?o(e):o(null,a)})):t?s.isString(r)?e.renderKey(t,r,i,o):s.isArray(r)?e.renderKeys(t,r,i,o):s.isFunction(r)?r(t,i,o):e.renderDSL(t,r,i,o):o(null,null)},e.renderDSL=function(t,r,n,i){var a,u,l,c,h;3===arguments.length&&(i=n,n={}),c=new o,h={},u=function(r,i){return c.defer(function(o){var a,u,l,c,f;return a=i.key||r,(c=t.relation(a))?(i.query?(l=i.query,f=i.template):i.$count?(l=s.clone(i),delete l.key):s.isFunction(i)?f=i:i.template?s.isObject(i.template)&&!s.isFunction(i.template)?l=i.template:(f=i.template,l=s.clone(i),delete l.key,delete l.template,e.isEmptyObject(l)&&(l=null)):(f=s.clone(i),delete f.key),f?l?c.cursor(t,a,l).toModels(function(t,i){return t?o(t):e.renderTemplate(i,f,n,function(e,t){return h[r]=t,o(e)})}):t.get(a,function(t,i){return t?o(t):e.renderTemplate(i,f,n,function(e,t){return h[r]=t,o(e)})}):c.cursor(t,a,l).toJSON(function(e,t){return h[r]=t,o(e)})):(r.length>1&&"_"===r[r.length-1]&&(r=r.slice(0,+(r.length-2)+1||9e9)),"$select"===r?s.isString(i)?e.renderKey(t,i,n,function(e,t){return h[i]=t,o(e)}):e.renderKeys(t,i,n,function(e,t){return s.extend(h,t),o(e)}):s.isString(i)?e.renderKey(t,i,n,function(e,t){return h[r]=t,o(e)}):s.isFunction(i)?i(t,n,function(e,t){return h[r]=t,o(e)}):s.isString(i.method)?(u=s.isArray(i.args)?i.args.slice():i.args?[i.args]:[],u.push(function(e,t){return h[r]=t,o(e)}),t[i.method].apply(t,u)):(console.trace("Unknown DSL action: "+r+": ",i),o(new Error("Unknown DSL action: "+r+": ",i))))})};for(l in r)a=r[l],u(l,a);return c.await(function(e){return i(e,e?void 0:h)})},e.renderKeys=function(t,r,n,i){var s,a,u,l,c,h;for(3===arguments.length&&(i=n,n={}),h={},c=new o,s=function(r){return c.defer(function(i){return e.renderKey(t,r,n,function(e,t){return e?i(e):(h[r]=t,i())})})},a=0,l=r.length;l>a;a++)u=r[a],s(u);return c.await(function(e){return i(e,e?void 0:h)})},e.renderKey=function(e,t,r,n){return 3===arguments.length&&(n=r,r={}),e.get(t,function(r,i){var o;if(r)return n(r);if(e.relation(t)){if(s.isArray(i))return n(null,function(){var e,t,r;for(r=[],e=0,t=i.length;t>e;e++)o=i[e],r.push(o.toJSON());return r}());if(i&&i.toJSON)return n(null,i=i.toJSON())}return n(null,i)})},e.renderRelated=function(t,r,n,i,a){var u,l,c,h,f,p;if(4===arguments.length&&(a=i,i={}),s.isArray(t)){for(p=[],f=new o,u=function(t){return f.defer(function(o){return t.get(r,function(t,r){return t&&o(t),e.renderTemplate(r,n,i,function(e,t){return e?o(e):(p.push(t),o())})})})},l=0,c=t.length;c>l;l++)h=t[l],u(h);return f.await(function(e){return a(e,e?void 0:p)})}return t.get(r,function(t,r){return t&&a(t),e.renderTemplate(r,n,i,a)})},e.deepClone=function(t,r){var n,i;if(!t||"object"!=typeof t)return t;if(s.isString(t))return String.prototype.slice.call(t);if(s.isDate(t))return new Date(t.getTime());if(s.isFunction(t.clone))return t.clone();if(s.isArray(t))n=Array.prototype.slice.call(t);else{if(t.constructor!=={}.constructor)return t;n=s.extend({},t)}if(!s.isUndefined(r)&&r>0)for(i in n)n[i]=e.deepClone(n[i],r-1);return n},e}()},function(e,t,r){(function(t){var n,i;i=("undefined"!=typeof t&&null!==t?t.nextTick:void 0)||r(1).defer,e.exports=n=function(){function e(){}return e.MAX_ITERATION_COUNT=300,e.eachDone=function(t,r,n){var o,s,a;return(o=t.length)?(s=0,(a=function(){return r(t[s++],function(t,r){return t||s>=o||r?n(t):s&&s%e.MAX_ITERATION_COUNT===0?i(a):a()})})()):n()},e.each=function(t,r,n){var o,s,a;return(o=t.length)?(s=0,(a=function(){return r(t[s++],function(t){return t||s>=o?n(t):s&&s%e.MAX_ITERATION_COUNT===0?i(a):a()})})()):n()},e.popEach=function(t,r,n){var o,s,a;return(o=t.length)?(s=0,(a=function(){return s++,r(t.pop(),function(r){return r||s>=o||0===t.length?n(r):s&&s%e.MAX_ITERATION_COUNT===0?i(a):a()})})()):n()},e}()}).call(t,r(15))},function(e,t,r){var n,i,o,s,a,u,l,c,h;l=r(1),n=r(2),a=r(11),u=r(24),o=r(33),i=r(32),s=r(36),c=r(38),h=r(39),r(41),e.exports=function(e){var t,r,n,i,f,p;if(t=function(){function e(){}return e}(),e.createSync=function(t){return e.prototype.sync("createSync",t)},e.resetSchema=function(t,r){var n;return 1===arguments.length&&(n=[{},t],t=n[0],r=n[1]),e.prototype.sync("resetSchema",t,r)},e.cursor=function(t){return null==t&&(t={}),e.prototype.sync("cursor",t)},e.destroy=function(t,r){var n;return 1===arguments.length&&(n=[{},t],t=n[0],r=n[1]),l.isObject(t)||(t={id:t}),e.prototype.sync("destroy",t,r)},e.db=function(){return e.prototype.sync("db")},e.exists=function(t,r){var n;return 1===arguments.length&&(n=[{},t],t=n[0],r=n[1]),e.prototype.sync("cursor",t).exists(r)},e.count=function(t,r){var n;return 1===arguments.length&&(n=[{},t],t=n[0],r=n[1]),e.prototype.sync("cursor",t).count(r)},e.all=function(t){return e.prototype.sync("cursor",{}).toModels(t)},e.find=function(t,r){var n;return 1===arguments.length&&(n=[{},t],t=n[0],r=n[1]),e.prototype.sync("cursor",t).toModels(r)},e.findOne=function(t,r){var n;return 1===arguments.length&&(n=[{},t],t=n[0],r=n[1]),t=l.isObject(t)?l.extend({$one:!0},t):{id:t,$one:!0},e.prototype.sync("cursor",t).toModels(r)},e.findOrCreate=function(t,r){var n;if(!l.isObject(t)||u.isModel(t)||u.isCollection(t))throw"findOrCreate requires object data";return n=l.extend({$one:!0},t),e.prototype.sync("cursor",n).toModels(function(n,i){return n?r(n):i?r(null,i):new e(t).save(r)})},e.findOneNearestDate=function(t,r,n,i){var o,s,a,u;if(!(s=r.key))throw new Error("Missing options key");return 2===arguments.length?(a=[{},n],n=a[0],i=a[1]):3===arguments.length?(u=[new Date,{},n],r=u[0],n=u[1],i=u[2]):n=l.clone(n),n.$one=!0,o=[function(r){return function(r){return n[s]={$lte:t},e.cursor(n).sort("-"+s).toModels(r)}}(this),function(r){return function(r){return n[s]={$gte:t},e.cursor(n).sort(s).toModels(r)}}(this)],r.reverse&&(o=[o[1],o[0]]),o[0](function(e,t){return e?i(e):t?i(null,t):o[1](i)})},e.each=function(t,r,n){var i;return 2===arguments.length&&(i=[{},t,r],t=i[0],r=i[1],n=i[2]),c(e,t,r,n)},e.eachC=function(t,r,n){var i;return 2===arguments.length&&(i=[{},t,r],t=i[0],r=i[1],n=i[2]),c(e,t,n,r)},e.stream=function(t){if(null==t&&(t={}),!l.isFunction(s))throw new Error('Stream is a large dependency so you need to manually include "stream.js" in the browser.');return new s(e,t)},e.interval=function(t,r,n){return h(e,t,r,n)},e.intervalC=function(t,r,n){return h(e,t,n,r)},e.prototype.modelName=function(){return e.model_name},e.prototype.cache=function(){return e.cache},e.prototype.schema=e.schema=function(){return e.prototype.sync("schema")},e.prototype.tableName=e.tableName=function(){return e.prototype.sync("tableName")},e.prototype.relation=e.relation=function(t){var r;return(r=e.prototype.sync("schema"))?r.relation(t):void 0},e.prototype.relationIsEmbedded=e.relationIsEmbedded=function(t){var r;return(r=e.relation(t))?!!r.embed:!1},e.prototype.reverseRelation=e.reverseRelation=function(t){var r;return(r=e.prototype.sync("schema"))?r.reverseRelation(t):void 0},e.prototype.isLoaded=function(e){return 0===arguments.length&&(e="__model__"),!u.orSet(this,"needs_load",{})[e]},e.prototype.setLoaded=function(e,t){var r,n;return 1===arguments.length&&(n=["__model__",e],e=n[0],t=n[1]),r=u.orSet(this,"needs_load",{}),t&&u.get(this,"is_initialized")?void delete r[e]:r[e]=!t},e.prototype.isLoadedExists=function(e){return 0===arguments.length&&(e="__model__"),u.orSet(this,"needs_load",{}).hasOwnProperty(e)},e.prototype.isPartial=function(){return!!u.get(this,"partial")},e.prototype.setPartial=function(e){return e?u.set(this,"partial",!0):u.unset(this,"partial")},e.prototype.addUnset=function(e){var t;return t=u.orSet(this,"unsets",[]),t.indexOf(e)<0?t.push(e):void 0},e.prototype.removeUnset=function(e){var t,r;if(r=u.get(this,"unsets",null))return(t=r.indexOf(e))>=0?r.splice(t,1):void 0},e.prototype.fetchRelated=function(e,t){var r,n;return 1===arguments.length&&(n=[null,e],e=n[0],t=n[1]),r=new a(1),r.defer(function(e){return function(t){return e.isLoaded()?t():e.fetch(t)}}(this)),r.defer(function(t){return function(r){var n;return n=l.keys(u.orSet(t,"needs_load",{})),e&&!l.isArray(e)&&(e=[e]),l.isArray(e)&&(n=l.intersection(n,e)),u.each(n,function(e,r){return t.get(e,r)},r)}}(this)),r.await(t)},e.prototype.patchAdd=function(e,t,r){var n;return(n=this.relation(e))?t?n.patchAdd(this,t,r):r(new Error("patchAdd: missing relateds for '"+e+"'")):r(new Error("patchAdd: relation '"+e+"' unrecognized"))},e.prototype.patchRemove=function(t,r,n){var i,o,s,u,l;if(1===arguments.length){n=t,l=e.schema(),o=new a(1),s=l.relations,i=function(e){return function(t){return o.defer(function(r){return t.patchRemove(e,r)})}}(this);for(t in s)u=s[t],i(u);return o.await(n)}return(u=this.relation(t))?2===arguments.length?(n=r,u.patchRemove(this,n)):r?u.patchRemove(this,r,n):n(new Error("patchRemove: missing relateds for '"+t+"'")):n(new Error("patchRemove: relation '"+t+"' unrecognized"))},e.prototype.cursor=function(t,r){var n,i;if(null==r&&(r={}),e.schema&&(i=e.schema()),i&&(n=i.relation(t)))return n.cursor(this,t,r);throw new Error(i.model_name+"::cursor: Unexpected key: "+t+" is not a relation")},r=function(e,t){var r,n,i,o;return e.isNew()||!e.modelName?e.clone(t):(n=(r=t._cache)[o=e.modelName()]||(r[o]={}),(i=n[e.id])||(i=e.clone(t),e.isLoaded()&&(n[e.id]=i)),i)},f={initialize:function(t){var r,n,i,o,s,a;if(e.schema&&(s=e.schema())){i=s.relations;for(r in i)o=i[r],o.initializeModel(this);n=u.orSet(this,"needs_load",{});for(r in n)a=n[r],a||delete n[r];u.set(this,"is_initialized",!0)}return e.prototype._orm_original_fns.initialize.apply(this,arguments)},fetch:function(t){var r;if(l.isFunction(r=arguments[arguments.length-1]))switch(arguments.length){case 1:t=u.wrapOptions({},r);break;case 2:t=u.wrapOptions(t,r)}else t||(t={});return e.prototype._orm_original_fns.fetch.call(this,u.wrapOptions(t,function(e){return function(t,r,n,i){return t?"function"==typeof i.error?i.error(e,n,i):void 0:(e.setLoaded(!0),"function"==typeof i.success?i.success(e,n,i):void 0)}}(this)))},unset:function(t){var r;return this.addUnset(t),r=this.id,e.prototype._orm_original_fns.unset.apply(this,arguments),"id"===t&&e.cache&&r&&e.cache.get(r)===this?e.cache.destroy(r):void 0},set:function(t,r,n){var i,s,a,u,c;if(!e.schema||!(u=e.schema()))return e.prototype._orm_original_fns.set.apply(this,arguments);l.isString(t)?(i={})[t]=r:(i=t,n=r),c={},a={};for(t in i)r=i[t],(s=u.relation(t))?a[t]=s:c[t]=r;o.isEmptyObject(c)||e.prototype._orm_original_fns.set.call(this,c,n);for(t in a)s=a[t],s.set(this,t,i[t],n);return this},get:function(t,r){var n,i,o;return e.schema&&(i=e.schema()),i&&(n=i.relation(t))?n.get(this,t,r):(o=e.prototype._orm_original_fns.get.call(this,t),r&&r(null,o),o)},toJSON:function(t){var r,n,i,o,s,a,c,h,f;if(null==t&&(t={}),e.schema&&(h=e.schema()),this._orm||(this._orm={}),this._orm.json>0)return this.id;for((r=this._orm).json||(r.json=0),this._orm.json++,i={},s=t.keys||this.whitelist||l.keys(this.attributes),n=0,a=s.length;a>n;n++)o=s[n],f=this.attributes[o],h&&(c=h.relation(o))?c.appendJSON(i,this):u.isCollection(f)?i[o]=l.map(f.models,function(e){return e?e.toJSON(t):null}):u.isModel(f)?i[o]=f.toJSON(t):i[o]=f;return--this._orm.json,i},save:function(t,r,n){var i,o,s;if(l.isFunction(s=arguments[arguments.length-1]))switch(arguments.length){case 1:i={},n=u.wrapOptions({},s);break;case 2:i=t,n=u.wrapOptions({},s);break;case 3:i=t,n=u.wrapOptions(r,s);break;case 4:(i={})[t]=r,n=u.wrapOptions(n,s)}else 0===arguments.length?(i={},n={}):null===t||l.isObject(t)?(i=t,n=r):(i={})[t]=r;return this.isLoaded()?(this._orm||(this._orm={}),this._orm.save>0?this.id?"function"==typeof n.success?n.success(this,{},n):void 0:"function"==typeof n.error?n.error(this,new Error("Model is in a save loop: "+e.model_name)):void 0:((o=this._orm).save||(o.save=0),this._orm.save++,this.set(i,n),i={},u.presaveBelongsToRelationships(this,function(r){return function(o){return o?"function"==typeof n.error?n.error(r,o):void 0:e.prototype._orm_original_fns.save.call(r,i,u.wrapOptions(n,function(n,i,o,s){var l,c,h,f,p;if(u.unset(r,"unsets"),--r._orm.save,n)return"function"==typeof s.error?s.error(r,o,s):void 0;if(c=new a(1),e.schema){p=e.schema(),h=p.relations,l=function(e){return c.defer(function(t){return e.save(r,t)})};for(t in h)f=h[t],l(f)}return c.await(function(t){var n;return t?"function"==typeof s.error?s.error(r,Error("Failed to save relations. "+t,s)):void 0:((n=e.cache)&&n.set(r.id,r),"function"==typeof s.success?s.success(r,o,s):void 0)})}))}}(this)))):"function"==typeof n.error?n.error(this,new Error("An unloaded model is trying to be saved: "+e.model_name)):void 0},destroy:function(t){var r,n,i,o;if(l.isFunction(i=arguments[arguments.length-1]))switch(arguments.length){case 1:t=u.wrapOptions({},i);break;case 2:t=u.wrapOptions(t,i)}if((n=this.cache())&&n.destroy(this.id),!e.schema||!(o=e.schema()))return e.prototype._orm_original_fns.destroy.call(this,t);if(this._orm||(this._orm={}),this._orm.destroy>0)throw new Error("Model is in a destroy loop: "+e.model_name);return(r=this._orm).destroy||(r.destroy=0),
this._orm.destroy++,e.prototype._orm_original_fns.destroy.call(this,u.wrapOptions(t,function(e){return function(t,r,n,i){return--e._orm.destroy,t?"function"==typeof i.error?i.error(e,n,i):void 0:e.patchRemove(function(t){return t?"function"==typeof i.error?i.error(e,new Error("Failed to destroy relations. "+t,i)):void 0:"function"==typeof i.success?i.success(e,n,i):void 0})}}(this)))},clone:function(t){var n,i,o,s,a,c,h,f,p,d,y,g;if(!e.schema)return e.prototype._orm_original_fns.clone.apply(this,arguments);if(t||(t={}),t._cache||(t._cache={}),o=(n=t._cache)[d=this.modelName()]||(n[d]={}),this._orm||(this._orm={}),this._orm.clone>0)return this.id?o[this.id]:e.prototype._orm_original_fns.clone.apply(this,arguments);for((i=this._orm).clone||(i.clone=0),this._orm.clone++,this.id?(s=o[this.id])||(s=new this.constructor,this.isLoaded()&&(o[this.id]=s)):s=new this.constructor,this.attributes.id&&(s.id=this.attributes.id),h=t.keys||l.keys(this.attributes),a=0,f=h.length;f>a;a++)c=h[a],g=this.attributes[c],u.isCollection(g)?((null!=(y=s.attributes[c])?y.values:void 0)||(s.attributes[c]=new g.constructor),s.attributes[c].reset(function(){var e,n,i,o;for(i=g.models,o=[],e=0,n=i.length;n>e;e++)p=i[e],o.push(r(p,t));return o}())):u.isModel(g)?s.attributes[c]=r(g,t):s.attributes[c]=g;return--this._orm.clone,s}},!e.prototype._orm_original_fns){e.prototype._orm_original_fns={},p=[];for(i in f)n=f[i],e.prototype._orm_original_fns[i]=e.prototype[i],p.push(e.prototype[i]=n);return p}}},function(e,t,r){var n,i,o=function(e,t){function r(){this.constructor=e}for(var n in t)s.call(t,n)&&(e[n]=t[n]);return r.prototype=t.prototype,e.prototype=new r,e.__super__=t.prototype,e},s={}.hasOwnProperty;try{i=r(37)}catch(a){}(null!=i?i.Readable:void 0)&&(e.exports=n=function(e){function t(e,r){this.model_type=e,this.query=null!=r?r:{},t.__super__.constructor.call(this,{objectMode:!0})}return o(t,e),t.prototype._read=function(){var e;if(!this.ended&&!this.started)return this.started=!0,e=function(e){return function(t){return e.ended=!0,t&&e.emit("error",t),e.push(null)}}(this),this.model_type.each(this.query,function(e){return function(t,r){return e.push(t),r()}}(this),e)},t}(i.Readable))},function(e,t){if("undefined"==typeof r){var n=new Error('Cannot find module "stream"');throw n.code="MODULE_NOT_FOUND",n}e.exports=r},function(e,t,r){var n,i,o;o=r(1),i=r(11),n=null,e.exports=function(e,t,s,a){var u,l,c,h,f,p;return n||(n=r(23)),c=t.$each||{},u=c.json?"toJSON":"toModels",f=0,h=n.parseQuery(o.omit(t,"$each")),o.defaults(h.cursor,{$offset:0,$sort:"id"}),l=h.cursor.$limit||1/0,c.fetch&&(h.cursor.$limit=c.fetch),(p=function(){var t;return t=e.cursor(h),t[u].call(t,function(e,t){var r,n,o,u,d;if(e||!t)return a(new Error("Failed to get models. Error: "+e));if(!t.length)return a(null,f);for(d=new i(c.threads),r=function(e){return d.defer(function(t){return s(e,t)})},n=0,o=t.length;o>n&&(u=t[n],!(f++>=l));n++)r(u);return d.await(function(e){return e?a(e):f>=l||t.length<h.cursor.$limit||!h.cursor.$limit?a(null,f):(h.cursor.$offset+=h.cursor.$limit,p())})})})()}},function(e,t,r){var n,i,o,s,a,u;u=r(1),s=r(11),a=r(24),o=r(33),n=r(40),i=["milliseconds","seconds","minutes","hours","days","weeks","months","years"],e.exports=function(e,t,r,a){var l,c,h,f,p,d;if(f=t.$interval||{},!(c=f.key))throw new Error("missing option: key");if(!f.type)throw new Error("missing option: type");if(!u.contains(i,f.type))throw new Error("type is not recognized: "+f.type+", "+u.contains(i,f.type));return l=u.clone(f),l.range||(l.range={}),d=l.range,h=!1,p=new s(1),p.defer(function(r){var n;return(n=d.$gte||d.$gt)?(d.start=n,e.findOneNearestDate(n,{key:c,reverse:!0},t,function(e,t){return e?r(e):t?(l.first=t.get(c),r()):(h=!0,r())})):e.cursor(t).limit(1).sort(c).toModels(function(e,t){return e?r(e):t.length?(d.start=l.first=t[0].get(c),r()):(h=!0,r())})}),p.defer(function(r){var n;return h?r():(n=d.$lte||d.$lt)?(d.end=n,e.findOneNearestDate(n,{key:c},t,function(e,t){return e?r(e):t?(l.last=t.get(c),r()):(h=!0,r())})):e.cursor(t).limit(1).sort("-"+c).toModels(function(e,t){return e?r(e):t.length?(d.end=l.last=t[0].get(c),r()):(h=!0,r())})}),p.await(function(i){var s,p,y,g;if(i)return a(i);if(h)return a();if(g=d.start.getTime(),s=n.durationAsMilliseconds(u.isUndefined(f.length)?1:f.length,f.type),!s)throw Error("length_ms is invalid: "+s+" for range: "+o.stringify(d));return t=u.omit(t,"$interval"),t.$sort=[c],p=0,l.index=0,(y=function(i){return n.isAfter(i,d.end)?a():(t[c]={$gte:i,$lte:l.last},e.findOne(t,function(e,n){var o;return e?a(e):n?(o=n.get(c),l.index=Math.floor((o.getTime()-g)/s),i=new Date(d.start.getTime()+l.index*s),l.start=i,o=new Date(i.getTime()+s),l.end=o,t[c]={$gte:i,$lt:o},r(t,l,function(e){return e?a(e):y(o)})):a()}))})(d.start)})}},function(e,t,r){var n,i,o;o=r(1),i={milliseconds:{milliseconds:1},seconds:{milliseconds:1e3},minutes:{milliseconds:6e4},hours:{milliseconds:144e4},days:{days:1},weeks:{days:7},months:{months:1},years:{years:1}},e.exports=n=function(){function e(){}return e.durationAsMilliseconds=function(e,t){var r;if(!(r=i[t]))throw new Error("DateUtils.durationAsMilliseconds :Unrecognized units: "+t);return r.milliseconds?e*r.milliseconds:r.days?864e5*e*r.days:r.months?e*r.months*2592e6:r.years?e*r.years*31536e6:void 0},e.isBefore=function(e,t){return e.valueOf()<t.valueOf()},e.isAfter=function(e,t){return e.valueOf()>t.valueOf()},e.isEqual=function(e,t){return+e===+t},e}()},function(e,t,r){var n,i,o,s,a,u,l;if(o=r(1),n=r(2),i=r(24),s=n.Collection,l={fetch:function(e){var t;if(o.isFunction(t=arguments[arguments.length-1]))switch(arguments.length){case 1:e=i.wrapOptions({},t);break;case 2:e=i.wrapOptions(e,t)}return s.prototype._orm_original_fns.fetch.call(this,i.wrapOptions(e,function(e){return function(t,r,n,i){return t?"function"==typeof i.error?i.error(e,n,i):void 0:"function"==typeof i.success?i.success(r,n,i):void 0}}(this)))},_prepareModel:function(e,t){var r,n,o;return!i.isModel(e)&&(r=i.dataId(e))?(this.model.cache&&(n=!!this.model.cache.get(r)),o=i.updateOrNew(e,this.model),n&&!o._validate(e,t)?(this.trigger("invalid",this,e,t),!1):o):s.prototype._orm_original_fns._prepareModel.call(this,e,t)}},!s.prototype._orm_original_fns){s.prototype._orm_original_fns={};for(u in l)a=l[u],s.prototype._orm_original_fns[u]=s.prototype[u],s.prototype[u]=a}},function(e,t,r){var n,i,o,s,a,u=function(e,t){return function(){return e.apply(t,arguments)}};a=r(1),s=r(24),o=r(33),n=["$count","$exists","$zero","$one","$offset","$limit","$page","$sort","$unique","$whitelist","$select","$include","$values","$ids","$or"],e.exports=i=function(){function e(t,r){this.relatedModelTypesInQuery=u(this.relatedModelTypesInQuery,this);var n,i,o,s,l,c;for(i in r)c=r[i],this[i]=c;for(s=e.parseQuery(t,this.model_type),this._find=s.find,this._cursor=s.cursor,l=["$whitelist","$select","$values","$unique"],n=0,o=l.length;o>n;n++)i=l[n],this._cursor[i]&&!a.isArray(this._cursor[i])&&(this._cursor[i]=[this._cursor[i]])}return e.validateQuery=function(t,r,n){var i,o,s,u;s=[];for(o in t)if(u=t[o],a.isUndefined(u)||a.isObject(u)){if(i=r?r+"."+o:o,a.isUndefined(u))throw new Error("Unexpected undefined for query key '"+i+"' on "+(null!=n?n.model_name:void 0));a.isObject(u)?s.push(e.validateQuery(u,i,n)):s.push(void 0)}return s},e.parseQuery=function(t,r){var n,i,o,s,u;if(t){if(a.isObject(t)){if(t.find||t.cursor)return{find:t.find||{},cursor:t.cursor||{}};try{e.validateQuery(t,null,r)}catch(i){throw n=i,new Error("Error: "+n+". Query: ",t)}s={find:{},cursor:{}};for(o in t)u=t[o],"$"!==o[0]?s.find[o]=u:s.cursor[o]=u;return s}return{find:{id:t},cursor:{$one:!0}}}return{find:{},cursor:{}}},e.prototype.offset=function(e){return this._cursor.$offset=e,this},e.prototype.limit=function(e){return this._cursor.$limit=e,this},e.prototype.sort=function(e){return this._cursor.$sort=e,this},e.prototype.whiteList=function(e){var t;return t=a.flatten(arguments),this._cursor.$whitelist=this._cursor.$whitelist?a.intersection(this._cursor.$whitelist,t):t,this},e.prototype.select=function(e){var t;return t=a.flatten(arguments),this._cursor.$select=this._cursor.$select?a.intersection(this._cursor.$select,t):t,this},e.prototype.include=function(e){var t;return t=a.flatten(arguments),this._cursor.$include=this._cursor.$include?a.intersection(this._cursor.$include,t):t,this},e.prototype.values=function(e){var t;return t=a.flatten(arguments),this._cursor.$values=this._cursor.$values?a.intersection(this._cursor.$values,t):t,this},e.prototype.unique=function(e){var t;return t=a.flatten(arguments),this._cursor.$unique=this._cursor.$unique?a.intersection(this._cursor.$unique,t):t,this},e.prototype.ids=function(){return this._cursor.$values=["id"],this},e.prototype.count=function(e){return this.execWithCursorQuery("$count","toJSON",e)},e.prototype.exists=function(e){return this.execWithCursorQuery("$exists","toJSON",e)},e.prototype.toModel=function(e){return this.execWithCursorQuery("$one","toModels",e)},e.prototype.toModels=function(e){return this._cursor.$values?e(new Error("Cannot call toModels on cursor with values for model "+this.model_type.model_name+". Values: "+o.stringify(this._cursor.$values))):this.toJSON(function(t){return function(r,n){return r?e(r):t._cursor.$one&&!n?e(null,null):(a.isArray(n)||(n=[n]),t.prepareIncludes(n,function(r,n){var i,o,a,u;return u=(i=!(t._cursor.$select||t._cursor.$whitelist))?function(){var e,t,r;for(r=[],e=0,t=n.length;t>e;e++)o=n[e],r.push(s.updateOrNew(o,this.model_type));return r}.call(t):function(){var e,t,r;for(r=[],e=0,t=n.length;t>e;e++)o=n[e],r.push((a=new this.model_type(this.model_type.prototype.parse(o)),a.setPartial(!0),a));return r}.call(t),e(null,t._cursor.$one?u[0]:u)}))}}(this))},e.prototype.toJSON=function(e){return this.queryToJSON(e)},e.prototype.queryToJSON=function(e){throw new Error("queryToJSON must be implemented by a concrete cursor for a Backbone Sync type")},e.prototype.hasCursorQuery=function(e){return this._cursor[e]||""===this._cursor[e]},e.prototype.execWithCursorQuery=function(e,t,r){var n;return n=this._cursor[e],this._cursor[e]=!0,this[t](function(t){return function(i,o){return a.isUndefined(n)?delete t._cursor[e]:t._cursor[e]=n,r(i,o)}}(this))},e.prototype.relatedModelTypesInQuery=function(){var e,t,r,n,i,o,s,a,u,l,c,h;s=[],a=[],n=this._find;for(t in n)h=n[t],t.indexOf(".")>0?(i=t.split("."),l=i[0],t=i[1],s.push(l)):(c=this.model_type.reverseRelation(t))&&c.join_table&&(a.push(c.model_type),a.push(c.join_table));for((null!=(o=this._cursor)?o.$include:void 0)&&(s=s.concat(this._cursor.$include)),e=0,r=s.length;r>e;e++)l=s[e],(u=this.model_type.relation(l))&&(a.push(u.reverse_model_type),u.join_table&&a.push(u.join_table));return a},e.prototype.selectResults=function(e){var t,r,n,i;return this._cursor.$one&&(e=e.slice(0,1)),this._cursor.$values?(r=this._cursor.$whitelist?a.intersection(this._cursor.$values,this._cursor.$whitelist):this._cursor.$values,1===this._cursor.$values.length?(i=this._cursor.$values[0],e=r.length?function(){var t,r,o;for(o=[],t=0,r=e.length;r>t;t++)n=e[t],o.push(n.hasOwnProperty(i)?n[i]:null);return o}():a.map(e,function(){return null})):e=function(){var t,o,s;for(s=[],t=0,o=e.length;o>t;t++)n=e[t],s.push(function(){var e,t,o;for(o=[],e=0,t=r.length;t>e;e++)i=r[e],n.hasOwnProperty(i)&&o.push(n[i]);return o}());return s}()):this._cursor.$select?(t=this._cursor.$whitelist?a.intersection(this._cursor.$select,this._cursor.$whitelist):this._cursor.$select,e=function(){var r,i,o;for(o=[],r=0,i=e.length;i>r;r++)n=e[r],o.push(a.pick(n,t));return o}()):this._cursor.$whitelist&&(e=function(){var t,r,i;for(i=[],t=0,r=e.length;r>t;t++)n=e[t],i.push(a.pick(n,this._cursor.$whitelist));return i}.call(this)),this.hasCursorQuery("$page")?e:this._cursor.$one?e[0]||null:e},e.prototype.selectFromModels=function(e,t){var r,n,i;return this._cursor.$select?(r=this._cursor.$whitelist?a.intersection(this._cursor.$select,this._cursor.$whitelist):this._cursor.$select,e=function(){var t,o,s;for(i=new this.model_type(a.pick(i.attributes,r)),i.setPartial(!0),s=[],t=0,o=e.length;o>t;t++)n=e[t],s.push(i);return s}.call(this)):this._cursor.$whitelist&&(e=function(){var t,r,o;for(i=new this.model_type(a.pick(i.attributes,this._cursor.$whitelist)),i.setPartial(!0),o=[],t=0,r=e.length;r>t;t++)n=e[t],o.push(i);return o}.call(this)),e},e.prototype.prepareIncludes=function(e,t){var r,n,i,o,s,u,l,c,h,f,p,d,y;if(!a.isArray(this._cursor.$include)||a.isEmpty(this._cursor.$include))return t(null,e);for(d=this.model_type.schema(),y={},r=function(e){return function(e,t){var r;return r=e[t.prototype.idAttribute],y[r]||(t.cache?(y[r]=t.cache.get(r))||t.cache.set(r,y[r]=new t(e)):y[r]=new t(e)),y[r]}}(this),h=this._cursor.$include,n=0,u=h.length;u>n;n++)for(i=h[n],p=d.relation(i),y={},s=0,l=e.length;l>s;s++)c=e[s],a.isArray(f=c[i])?c[i]=function(){var e,t,n;for(n=[],e=0,t=f.length;t>e;e++)o=f[e],n.push(r(o,p.reverse_model_type));return n}():f&&(c[i]=r(f,p.reverse_model_type));return t(null,e)},e}()},function(e,t,r){var n,i,o,s,a,u,l,c,h,f,p=function(e,t){function r(){this.constructor=e}for(var n in t)d.call(t,n)&&(e[n]=t[n]);return r.prototype=t.prototype,e.prototype=new r,e.__super__=t.prototype,e},d={}.hasOwnProperty;f=r(1),n=r(2),i=r(3),u=r(44),a=r(46),o=r(32),h=r(24),s=r(33),l={hasOne:"hasOne",has_one:"hasOne",HasOne:"hasOne",belongsTo:"belongsTo",belongs_to:"belongsTo",BelongsTo:"belongsTo",hasMany:"hasMany",has_many:"hasMany",HasMany:"hasMany"},e.exports=c=function(){function e(e,t){this.model_type=e,this.type_overrides=null!=t?t:{},this.raw=f.clone(f.result(new this.model_type,"schema")||{}),this.fields={},this.relations={},this.virtual_accessors={},this.raw.id&&this._parseField("id",this.raw.id)}return e.prototype.initialize=function(){var e,t,r,n,i;if(!this.is_initialized){this.is_initialized=!0,r=this.raw;for(t in r)e=r[t],this._parseField(t,e);n=this.relations;for(t in n)i=n[t],i.initialize()}},e.prototype.type=function(e,t){var r,n,i,o,s,a,u;return 2===arguments.length?(((r=this.type_overrides)[e]||(r[e]={})).type=t,this):((n=e.indexOf("."))>=0&&(i=e.substr(n+1),e=e.substr(0,n)),(t=(null!=(o=this.type_overrides[e])?o.type:void 0)||(null!=(s=this.fields[e])?s.type:void 0)||(null!=(a=this.relation(e))?a.reverse_model_type:void 0)||(null!=(u=this.reverseRelation(e))?u.model_type:void 0))?this.virtual_accessors[e]?i?void console.log("Unexpected other for virtual id key: "+e+"."+i):("function"==typeof t.schema?t.schema().type("id"):void 0)||t:i?"function"==typeof t.schema?t.schema().type(i):void 0:t:void 0)},e.prototype.idType=function(e){var t;return e?(t=this.type(e))?("function"==typeof t.schema?t.schema().type("id"):void 0)||t:void 0:this.type("id")},e.prototype.field=function(e){return this.fields[e]||this.relation(e)},e.prototype.relation=function(e){return this.relations[e]||this.virtual_accessors[e]},e.prototype.reverseRelation=function(e){var t,r,n;r=this.relations;for(t in r)if(n=r[t],n.reverse_relation&&n.reverse_relation.join_key===e)return n.reverse_relation;return null},e.prototype.columns=function(){var e,t,r,n;e=f.keys(this.fields),f.find(e,function(e){return"id"===e})||e.push("id"),r=this.relations;for(t in r)n=r[t],"belongsTo"!==n.type||n.isVirtual()||n.isEmbedded()||e.push(n.foreign_key);return e},e.prototype.joinTables=function(){var e,t;return function(){var r,n;r=this.relations,n=[];for(e in r)t=r[e],!t.isVirtual()&&t.join_table&&n.push(t.join_table);return n}.call(this)},e.prototype.relatedModels=function(){var e,t,r,n;r=[],t=this.relations;for(e in t)n=t[e],r.push(n.reverse_model_type),n.join_table&&r.push(n.join_table);return r},e.prototype.allColumns=function(){return this.columns()},e.prototype.allRelations=function(){return this.relatedModels()},e.prototype.generateBelongsTo=function(e){var t,r;return t=i.naming_conventions.attribute(e.model_name),(r=this.relations[t])?r:this.raw[t]?(r=this._parseField(t,this.raw[t]),r.initialize(),r):(r=this._parseField(t,this.raw[t]=["belongsTo",e,{manual_fetch:!0}]),r.initialize(),r)},e.joinTableURL=function(e){var t,r;return t=i.naming_conventions.tableName(e.model_type.model_name),r=i.naming_conventions.tableName(e.reverse_relation.model_type.model_name),t.localeCompare(r)<0?t+"_"+r:r+"_"+t},e.prototype.generateJoinTable=function(t){var r,s,a,u,l,c;u={},u[t.join_key]=[l=t.model_type.schema().type("id"),{indexed:!0}],u[t.reverse_relation.join_key]=[(null!=(a=t.reverse_model_type)?a.schema().type("id"):void 0)||l,{indexed:!0}],c=e.joinTableURL(t),s=i.naming_conventions.modelName(c,!0);try{r=function(e){function r(){return r.__super__.constructor.apply(this,arguments)}return p(r,e),r.prototype.model_name=s,r.prototype.urlRoot=new o(f.result(new t.model_type,"url")).format({exclude_table:!0})+"/"+c,r.prototype.schema=u,r.prototype.sync=t.model_type.createSync(r),r}(n.Model)}catch(h){r=function(e){function r(){return r.__super__.constructor.apply(this,arguments)}return p(r,e),r.prototype.model_name=s,r.prototype.urlRoot="/"+c,r.prototype.schema=u,r.prototype.sync=t.model_type.createSync(r),r}(n.Model)}return r},e.prototype._parseField=function(e,t){var r,n,i;if(r=this._fieldInfoToOptions(f.isFunction(t)?t():t),!r.type)return this.fields[e]=r;if(!(i=l[r.type])){if(!f.isString(r.type))throw new Error("Unexpected type name is not a string: "+s.stringify(r));return this.fields[e]=r}return r.type=i,n=this.relations[e]="hasMany"===i?new a(this.model_type,e,r):new u(this.model_type,e,r),n.virtual_id_accessor&&(this.virtual_accessors[n.virtual_id_accessor]=n),"belongsTo"===i&&(this.virtual_accessors[n.foreign_key]=n),n},e.prototype._fieldInfoToOptions=function(e){var t;if(f.isString(e))return{type:e};if(!f.isArray(e))return e;if(t={},f.isString(e[0])&&(t.type=e[0],e=e.slice(1),0===e.length))return t;if(f.isFunction(e[0])&&(t.reverse_model_type=e[0],e=e.slice(1)),e.length>1)throw new Error("Unexpected field options array: "+s.stringify(e));return 1===e.length&&f.extend(t,e[0]),t},e}()},function(e,t,r){var n,i,o,s,a,u,l=function(e,t){function r(){this.constructor=e}for(var n in t)c.call(t,n)&&(e[n]=t[n]);return r.prototype=t.prototype,e.prototype=new r,e.__super__=t.prototype,e},c={}.hasOwnProperty;u=r(1),n=r(2),i=r(3),s=r(11),a=r(24),e.exports=o=function(e){function t(e,t,r){var n,o;this.model_type=e,this.key=t;for(n in r)o=r[n],this[n]=o;this.virtual_id_accessor||(this.virtual_id_accessor=i.naming_conventions.foreignKey(this.key)),this.join_key||(this.join_key=this.foreign_key||i.naming_conventions.foreignKey(this.model_type.model_name)),this.foreign_key||(this.foreign_key=i.naming_conventions.foreignKey("belongsTo"===this.type?this.key:this.as||this.model_type.model_name))}return l(t,e),t.prototype.initialize=function(){var e,t,r;if(this.reverse_relation=this._findOrGenerateReverseRelation(this),this.embed&&this.reverse_relation&&this.reverse_relation.embed)throw new Error("Both relationship directions cannot embed ("+this.model_type.model_name+" and "+this.reverse_model_type.model_name+"). Choose one or the other.");return this.embed&&this.model_type.schema().type("id",this.reverse_model_type.schema().type("id")),null!=(e=this.reverse_model_type)?e.schema().type(this.foreign_key,(null!=(t=this.model_type)&&null!=(r=t.schema())?r.type("id"):void 0)||this.model_type):void 0},t.prototype.initializeModel=function(e){return e.isLoadedExists(this.key)||e.setLoaded(this.key,this.isEmbedded()),this._bindBacklinks(e)},t.prototype.releaseModel=function(e){return this._unbindBacklinks(e),delete e._orm},t.prototype.set=function(e,t,r,i){var o,s,l,c,h;if(t!==this.key&&t!==this.virtual_id_accessor&&t!==this.foreign_key)throw new Error("One.set: Unexpected key "+t+". Expecting: "+this.key+" or "+this.virtual_id_accessor+" or "+this.foreign_key);if(u.isArray(r))throw new Error("One.set: cannot set an array for attribute "+this.key+" on "+this.model_type.model_name);return u.isUndefined(r)&&(r=null),r===(h=e.get(this.key))?this:(o=a.isModel(r),l=a.dataId(r),c=a.dataId(h),a.orSet(e,"rel_dirty",{})[this.key]=!0,c===l&&e.isLoaded(this.key)||(o&&r.isLoaded()&&l!==r?e.setLoaded(this.key,!0):e.setLoaded(this.key,u.isNull(r))),r&&!o&&((s=c===l)||(r=a.updateOrNew(r,this.reverse_model_type))),s||n.Model.prototype.set.call(e,this.key,r,i),s?a.updateModel(h,r):null!==r||!this.reverse_relation||"hasOne"!==this.reverse_relation.type&&"belongsTo"!==this.reverse_relation.type||this.embed||this.reverse_relation.embed||e.isLoaded(this.key)&&h&&h.get(this.reverse_relation.key)===e&&h.set(this.reverse_relation.key,null),this)},t.prototype.get=function(e,t,r){var n,i,o;if(t!==this.key&&t!==this.virtual_id_accessor&&t!==this.foreign_key)throw new Error("One.get: Unexpected key "+t+". Expecting: "+this.key+" or "+this.virtual_id_accessor+" or "+this.foreign_key);return o=function(r){return function(){var n;return(n=e.attributes[r.key])?t===r.virtual_id_accessor?n.id:n:null}}(this),!r||this.isVirtual()||this.manual_fetch||(n=e.isLoaded(this.key))||this.cursor(e,t).toJSON(function(n){return function(i,s){var u,l;return i?r(i):(t!==n.virtual_id_accessor&&e.setLoaded(n.key,!0),u=e.get(n.key),u&&u.id===(null!=s?s.id:void 0)?a.updateModel(u,s):(l=s?a.updateOrNew(s,n.reverse_model_type):null,e.set(n.key,l)),r(null,o()))}}(this)),i=o(),r&&(n||this.manual_fetch)&&r(null,i),i},t.prototype.save=function(e,t){var r;return this._hasChanged(e)?(delete a.orSet(e,"rel_dirty",{})[this.key],(r=e.attributes[this.key])?this._saveRelated(e,[r],t):t()):t()},t.prototype.patchAdd=function(e,t,r){var n,i;return e.id?t?u.isArray(t)?r(new Error("One.patchAdd: should be provided with one model only for key: "+this.key)):(i=a.dataId(t))?(this.reverse_model_type.cache&&!a.isModel(t)&&(n=this.reverse_model_type.cache.get(i))&&(a.updateModel(n,t),t=n),e.set(this.key,t),"belongsTo"===this.type?this.model_type.cursor({id:e.id,$one:!0}).toJSON(function(t){return function(n,o){return n?r(n):o?(o[t.foreign_key]=i,e.save(o,r)):r(new Error("Failed to fetch model with id: "+e.id))}}(this)):this.cursor(e,this.key).toJSON(function(n){return function(o,u){var l;return o?r(o):u&&i===u[n.reverse_model_type.prototype.idAttribute]?r():(l=new s(1),u&&l.defer(function(t){return n.patchRemove(e,u,t)}),l.defer(function(r){var o,s;return a.isModel(t)?t.isLoaded()&&(s=t.toJSON()):i!==t&&(s=t),s?(s[n.reverse_relation.foreign_key]=e.id,a.modelJSONSave(s,n.reverse_model_type,r)):(o={$one:!0},o.id=i,n.reverse_model_type.cursor(o).toJSON(function(t,i){return t?r(t):i?(i[n.reverse_relation.foreign_key]=e.id,a.modelJSONSave(i,n.reverse_model_type,r)):r()}))}),l.await(r))}}(this))):r(new Error("One.patchAdd: cannot add a new model. Please save first.")):r(new Error("One.patchAdd: missing model for: "+this.key)):r(new Error("One.patchAdd: model has null id for: "+this.key))},t.prototype.patchRemove=function(e,t,r){var n,i,o,s,l,c,h,f,p;if(2===arguments.length&&(l=[null,t],t=l[0],r=l[1]),!e.id)return r(new Error("One.patchRemove: model has null id for: "+this.key));if(2===arguments.length)return this.reverse_relation?(a.isModel(e)?(delete a.orSet(e,"rel_dirty",{})[this.key],p=e.get(this.key),e.set(this.key,null)):(o=e[this.key])&&(p=new this.reverse_model_type(o)),p&&((null!=(c=p.get(this.foreign_key))?c.id:void 0)===e.id&&p.set(this.foreign_key,null),(n=p.cache())&&n.set(p.id,p)),this.embed?r():void("belongsTo"===this.type?this.model_type.cursor({id:e.id,$one:!0}).toJSON(function(e){return function(t,n){return t?r(t):n?(n[e.foreign_key]=null,a.modelJSONSave(n,e.model_type,r)):r()}}(this)):this.cursor(e,this.key).toJSON(function(t){return function(n,i){return n?r(n):i?i[t.reverse_relation.foreign_key]!==e.id?r():(i[t.reverse_relation.foreign_key]=null,a.modelJSONSave(i,t.reverse_model_type,r)):r()}}(this)))):r();if(!t)return r(new Error("One.patchRemove: missing model for remove"));if(u.isArray(t)||(t=[t]),p=e.get(this.key))for(i=0,s=t.length;s>i;i++)if(h=t[i],a.dataIsSameModel(p,h)){e.set(this.key,null);break}return f=function(){var e,r,n;for(n=[],e=0,r=t.length;r>e;e++)h=t[e],n.push(a.dataId(h));return n}(),this.embed?r():"belongsTo"===this.type?this.model_type.cursor({id:e.id,$one:!0}).toJSON(function(e){return function(t,n){return t?r(t):n&&u.contains(f,n[e.foreign_key])?(n[e.foreign_key]=null,a.modelJSONSave(n,e.model_type,r)):r()}}(this)):this.cursor(e,this.key).toJSON(function(e){return function(t,n){return t?r(t):n&&u.contains(f,n[e.reverse_model_type.prototype.idAttribute])?(n[e.reverse_relation.foreign_key]=null,a.modelJSONSave(n,e.reverse_model_type,r)):r()}}(this))},t.prototype.appendJSON=function(e,t){var r,n;if(!this.isVirtual())return r=this.embed?this.key:this.foreign_key,(n=t.attributes[this.key])?this.embed?e[r]=n.toJSON():"belongsTo"===this.type?e[r]=n.id:void 0:void((this.embed||"belongsTo"===this.type)&&(e[r]=null))},t.prototype.cursor=function(e,t,r){var n;if(r=u.extend({$one:!0},r||{}),a.isModel(e))if("belongsTo"===this.type)(r.id=null!=(n=e.attributes[this.key])?n.id:void 0)||(r.$zero=!0,delete r.id);else{if(!e.id)throw new Error("Cannot create cursor for non-loaded model");r[this.reverse_relation.foreign_key]=e.id}else if("belongsTo"===this.type)(r.id=e[this.foreign_key])||(r.$zero=!0,delete r.id);else{if(!e.id)throw new Error("Cannot create cursor for non-loaded model");r[this.reverse_relation.foreign_key]=e.id}return t===this.virtual_id_accessor&&(r.$values=["id"]),this.reverse_model_type.cursor(r)},t.prototype._bindBacklinks=function(e){var t,r,n;if(this.reverse_relation)return t=a.set(e,"events",{}),n=function(t){return function(r){return t.reverse_relation.add?t.reverse_relation.add(r,e):r.set(t.reverse_relation.key,e)}}(this),t.change=function(e){return function(t){var r,i,o;return o=t.get(e.key),i=t.previous(e.key),a.dataId(o)!==a.dataId(i)?(a.orSet(t,"rel_dirty",{})[e.key]=!0,i&&e.reverse_relation&&"belongsTo"!==e.reverse_relation.type&&(e.reverse_relation.remove?e.isVirtual()&&o||e.reverse_relation.remove(i,t):(r=i.get(e.reverse_relation.key),a.dataId(r)===t.id&&i.set(e.reverse_relation.key,null))),o?n(o):void 0):void 0}}(this),e.on("change:"+this.key,t.change),(r=e.get(this.key))?n(r):e.attributes[this.key]=null,e},t.prototype._unbindBacklinks=function(e){var t;(t=a.get(e,"events"))&&(a.unset(e,"events"),e.attributes[this.key]=null,e.off("change:"+this.key,t.change),t.change=null)},t.prototype._hasChanged=function(e){return!!a.orSet(e,"rel_dirty",{})[this.key]||e.hasChanged(this.key)},t}(r(45))},function(e,t,r){var n,i,o,s,a,u;u=r(1),n=r(2),i=r(3),o=r(11),a=r(24),e.exports=s=function(){function e(){}return e.prototype.isEmbedded=function(){return!!(this.embed||this.reverse_relation&&this.reverse_relation.embed)},e.prototype.isVirtual=function(){return!!(this.virtual||this.reverse_relation&&this.reverse_relation.virtual)},e.prototype.findOrGenerateJoinTable=function(){var e;return(e=this.join_table||this.reverse_relation.join_table)?e:this.model_type.schema().generateJoinTable(this)},e.prototype._findOrGenerateReverseRelation=function(){var e,t,r;return e=this.model_type,t=this.reverse_model_type,u.isFunction(t.schema)||(t.sync=e.createSync(t)),r=t.relation(this.as),r||(r=t.relation(i.naming_conventions.attribute(e.model_name,!1))),r||(r=t.relation(i.naming_conventions.attribute(e.model_name,!0))),r||"belongsTo"===this.type||(r=t.schema().generateBelongsTo(e)),r&&!r.reverse_relation&&(r.reverse_relation=this),r},e.prototype._saveRelated=function(e,t,r){return this.embed||!this.reverse_relation||"belongsTo"===this.type?r():this.isVirtual()?r():this.cursor(e,this.key).toJSON(function(n){return function(i,s){var l,c,h,f,p;return i?r(i):(u.isArray(s)||(s=s?[s]:[]),h=new o(1),f=u.pluck(t,"id"),c=u.groupBy(s,function(e){return u.contains(f,e.id)?"kept":"removed"}),l=c.kept?u.difference(f,function(){var e,t,r,n;for(r=c.kept,n=[],e=0,t=r.length;t>e;e++)p=r[e],n.push(p.id);return n}()):f,c.removed&&(n.join_table?h.defer(function(t){var r,i;return r={},r[n.join_key]=e.id,r[n.reverse_relation.join_key]={$in:function(){var e,t,r,n;for(r=c.removed,n=[],e=0,t=r.length;t>e;e++)i=r[e],n.push(i[this.reverse_model_type.prototype.idAttribute]);return n}.call(n)},n.join_table.destroy(r,t)}):h.defer(function(e){return a.each(c.removed,function(e,t){return e[n.reverse_relation.foreign_key]=null,a.modelJSONSave(e,n.reverse_model_type,t)},e)})),l.length&&(n.join_table?h.defer(function(t){return a.each(l,function(t,r){var i,o;return i={},i[n.foreign_key]=e.id,i[n.reverse_relation.foreign_key]=t,o=new n.join_table(i),o.save(r)},t)}):h.defer(function(e){return a.each(l,function(e,r){var i;return i=u.find(t,function(t){return t.id===e}),n.reverse_relation._hasChanged(i)?i.save(function(e,t){var i;return!e&&(i=n.reverse_model_type.cache)&&i.set(t.id,t),r(e)}):r()},e)})),h.await(r))}}(this))},e}()},function(e,t,r){var n,i,o,s,a,u,l,c=function(e,t){function r(){this.constructor=e}for(var n in t)h.call(t,n)&&(e[n]=t[n]);return r.prototype=t.prototype,e.prototype=new r,e.__super__=t.prototype,e},h={}.hasOwnProperty;n=r(2),l=r(1),i=r(3),a=r(11),u=r(24),o=r(33),e.exports=s=function(e){function t(e,t,r){var o,s,a,u;this.model_type=e,this.key=t;for(s in r)u=r[s],this[s]=u;this.virtual_id_accessor||(this.virtual_id_accessor=i.naming_conventions.foreignKey(this.key,!0)),this.join_key||(this.join_key=this.foreign_key||i.naming_conventions.foreignKey(this.model_type.model_name)),this.foreign_key||(this.foreign_key=i.naming_conventions.foreignKey(this.as||this.model_type.model_name)),this._adding_ids={},this.collection_type||(a=this.reverse_model_type,o=function(e){function t(){return t.__super__.constructor.apply(this,arguments)}return c(t,e),t.prototype.model=a,t}(n.Collection),this.collection_type=o)}return c(t,e),t.prototype.initialize=function(){var e,t,r,n;if(this.reverse_relation=this._findOrGenerateReverseRelation(this),this.embed&&this.reverse_relation&&this.reverse_relation.embed)throw new Error("Both relationship directions cannot embed ("+this.model_type.model_name+" and "+this.reverse_model_type.model_name+"). Choose one or the other.");if("hasOne"===(null!=(e=this.reverse_relation)?e.type:void 0))throw new Error("The reverse of a hasMany relation should be `belongsTo`, not `hasOne` ("+this.model_type.model_name+" and "+this.reverse_model_type.model_name+").");return this.embed&&this.model_type.schema().type("id",this.reverse_model_type.schema().type("id")),null!=(t=this.reverse_model_type)&&t.schema().type(this.foreign_key,(null!=(r=this.model_type)&&null!=(n=r.schema())?n.type("id"):void 0)||this.model_type),"hasMany"===this.reverse_relation.type?this.join_table=this.findOrGenerateJoinTable(this):void 0},t.prototype.initializeModel=function(e){return e.isLoadedExists(this.key)||e.setLoaded(this.key,!1),this._bindBacklinks(e)},t.prototype.releaseModel=function(e){return this._unbindBacklinks(e),delete e._orm},t.prototype.set=function(e,t,r,n){var i,s,a,c,h,f,p,d;if(t!==this.key&&t!==this.virtual_id_accessor&&t!==this.foreign_key)throw new Error("Many.set: Unexpected key "+t+". Expecting: "+this.key+" or "+this.virtual_id_accessor+" or "+this.foreign_key);if(i=this._bindBacklinks(e),u.isCollection(r)&&(r=r.models),l.isUndefined(r)&&(r=[]),!l.isArray(r))throw new Error("HasMany.set: Unexpected type to set "+t+". Expecting array: "+o.stringify(r));if(u.orSet(e,"rel_dirty",{})[this.key]=!0,e.setLoaded(this.key,l.all(r,function(e){return u.dataId(e)!==e})),f=function(){var e,t,n;for(n=[],e=0,t=r.length;t>e;e++)a=r[e],n.push((d=i.get(u.dataId(a)))?u.updateModel(d,a):u.updateOrNew(a,this.reverse_model_type));return n}.call(this),e.setLoaded(this.key,l.all(f,function(e){return e.isLoaded()})),p=l.clone(i.models),i.reset(f),"belongsTo"===this.reverse_relation.type)for(h=l.pluck(f,"id"),s=0,c=p.length;c>s;s++)d=p[s],l.contains(h,d.id)||d.set(this.foreign_key,null);return this},t.prototype.get=function(e,t,r){var n,i,o,s;if(t!==this.key&&t!==this.virtual_id_accessor&&t!==this.foreign_key)throw new Error("Many.get: Unexpected key "+t+". Expecting: "+this.key+" or "+this.virtual_id_accessor+" or "+this.foreign_key);return n=this._ensureCollection(e),s=function(e){return function(){
var r,i,o,s,a;if(t===e.virtual_id_accessor){for(o=n.models,a=[],r=0,i=o.length;i>r;r++)s=o[r],a.push(s.id);return a}return n}}(this),!r||this.isVirtual()||this.manual_fetch||(i=e.isLoaded(this.key))||this.cursor(e,this.key).toJSON(function(t){return function(i,o){var a,l,c,h,f,p,d,y,g;if(i)return r(i);for(e.setLoaded(t.key,!0),l=0,h=o.length;h>l;l++)p=o[l],(y=n.get(p[t.reverse_model_type.prototype.idAttribute]))?y.set(p):n.add(y=u.updateOrNew(p,t.reverse_model_type));if(a=t.reverse_model_type.cache)for(d=n.models,c=0,f=d.length;f>c;c++)y=d[c],a.set(y.id,y);return g=s(),r(null,g.models?g.models:g)}}(this)),o=s(),r&&(i||this.manual_fetch)&&r(null,o.models?o.models:o),o},t.prototype.save=function(e,t){var r;return this._hasChanged(e)?(delete u.orSet(e,"rel_dirty",{})[this.key],r=this._ensureCollection(e),this._saveRelated(e,l.clone(r.models),t)):t()},t.prototype.appendJSON=function(e,t){var r,n;if(!this.isVirtual())return r=this._ensureCollection(t),n=this.embed?this.key:this.virtual_id_accessor,this.embed?e[n]=r.toJSON():void 0},t.prototype.add=function(e,t){var r,n,i,o;return t.id&&(r=this._adding_ids[t.id]=(this._adding_ids[t.id]||0)+1),n=this._ensureCollection(e),i=n.get(t.id),i!==t?(i&&n.remove(i),this.reverse_model_type.cache&&t.id&&this.reverse_model_type.cache.set(t.id,t),o=n.add(t,{silent:r>1}),t.id&&this._adding_ids[t.id]--,o):void 0},t.prototype.remove=function(e,t){var r,n;return r=this._ensureCollection(e),(n=r.get(t.id))?(u.orSet(e,"rel_dirty",{})[this.key]=!0,r.remove(n)):void 0},t.prototype.patchAdd=function(e,t,r){var n,i,o,s,a,c,h,f;if(!e.id)return r(new Error("Many.patchAdd: model has null id for: "+this.key));if(!t)return r(new Error("Many.patchAdd: missing model for: "+this.key));if(l.isArray(t)||(t=[t]),n=this._ensureCollection(e),t=function(){var e,r,i;for(i=[],e=0,r=t.length;r>e;e++)o=t[e],i.push((f=n.get(u.dataId(o)))?u.updateModel(f,o):u.updateOrNew(o,this.reverse_model_type));return i}.call(this),h=function(){var e,r,n;for(n=[],e=0,r=t.length;r>e;e++)c=t[e],n.push(u.dataId(c));return n}(),n.add(t),e.isLoaded(this.key))for(i=0,s=t.length;s>i;i++)if(c=t[i],!c.isLoaded()){e.setLoaded(this.key,!1);break}return this.join_table?u.each(h,function(t){return function(r,n){var i,o;return r?(i=function(n){var i;return(i={})[t.foreign_key]=e.id,i[t.reverse_relation.foreign_key]=r,t.join_table.exists(i,function(e,r){return e?n(e):r?n(new Error("Join already exists: "+JSON.stringify(i))):new t.join_table(i).save(n)})},"hasMany"===t.reverse_relation.type?i(n):((o={$one:!0})[t.reverse_relation.foreign_key]=r,t.join_table.cursor(o).toJSON(function(r,o){return r?n(r):o?o[t.foreign_key]===e.id?n():(o[t.foreign_key]=e.id,u.modelJSONSave(o,t.join_table,n)):i(n)}))):n(new Error("Many.patchAdd: cannot add an new model. Please save first."))}}(this),r):(a={id:{$in:h}},this.reverse_model_type.cursor(a).toJSON(function(t){return function(n,i){return u.each(i,function(r,n){return r[t.reverse_relation.foreign_key]=e.id,u.modelJSONSave(r,t.reverse_model_type,n)},r)}}(this)))},t.prototype.patchRemove=function(e,t,r){var n,i,o,s,a,c,h,f,p,d,y,g,m,v,_,w,b;if(2===arguments.length&&(y=[null,t],t=y[0],r=y[1]),!e.id)return r(new Error("Many.patchRemove: model has null id for: "+this.key));if(2===arguments.length){if(!this.reverse_relation)return r();for(u.isModel(e)?(delete u.orSet(e,"rel_dirty",{})[this.key],i=this._ensureCollection(e),b=l.clone(i.models)):b=function(){var t,r,n,i;for(n=e[this.key]||[],i=[],t=0,r=n.length;r>t;t++)a=n[t],i.push(new this.reverse_model_type(a));return i}.call(this),o=0,h=b.length;h>o;o++)w=b[o],(null!=(g=w.get(this.foreign_key))?g.id:void 0)===e.id&&w.set(this.foreign_key,null),(n=w.cache())&&n.set(w.id,w);return this.embed?r():this.join_table?((d={})[this.join_key]=e.id,this.join_table.destroy(d,r)):void("belongsTo"===this.type?this.model_type.cursor({id:e.id,$one:!0}).toJSON(function(e){return function(t,n){return t?r(t):n?(n[e.foreign_key]=null,u.modelJSONSave(n,e.model_type,r)):r()}}(this)):((d={})[this.reverse_relation.foreign_key]=e.id,this.reverse_model_type.cursor(d).toJSON(function(e){return function(t,n){return t?r(t):u.each(n,function(t,r){return t[e.reverse_relation.foreign_key]=null,u.modelJSONSave(t,e.reverse_model_type,r)},r)}}(this))))}if(!t)return r(new Error("Many.patchRemove: missing model for remove"));for(l.isArray(t)||(t=[t]),i=this._ensureCollection(e),s=0,f=t.length;f>s;s++)for(v=t[s],m=i.models,c=0,p=m.length;p>c;c++)if(w=m[c],u.dataIsSameModel(w,v)){i.remove(w);break}return _=function(){var e,r,n;for(n=[],e=0,r=t.length;r>e;e++)v=t[e],n.push(u.dataId(v));return n}(),this.embed?r():this.join_table?(d={},d[this.join_key]=e.id,d[this.reverse_relation.join_key]={$in:_},this.join_table.destroy(d,r)):"belongsTo"===this.type?this.model_type.cursor({id:e.id,$one:!0}).toJSON(function(e){return function(t,n){return t?r(t):n&&l.contains(_,n[e.foreign_key])?(n[e.foreign_key]=null,u.modelJSONSave(n,e.model_type,r)):r()}}(this)):(d={},d[this.reverse_relation.foreign_key]=e.id,d.id={$in:_},this.reverse_model_type.cursor(d).toJSON(function(t){return function(n,i){return n?r(n):u.each(i,function(r,n){return r[t.reverse_relation.foreign_key]!==e.id?n():(r[t.reverse_relation.foreign_key]=null,u.modelJSONSave(r,t.reverse_model_type,n))},r)}}(this)))},t.prototype.cursor=function(e,t,r){var n;return n=u.isModel(e)?e.attributes:e,(r=l.clone(r||{}))[this.join_table?this.join_key:this.reverse_relation.foreign_key]=n[this.model_type.prototype.idAttribute],t===this.virtual_id_accessor&&(r.$values||(r.$values=[])).push("id"),this.reverse_model_type.cursor(r)},t.prototype._bindBacklinks=function(e){var t,r,n,i,o,s;if((t=e.attributes[this.key])instanceof this.collection_type)return t;if(t=e.attributes[this.key]=new this.collection_type,!this.reverse_relation)return t;for(r=u.set(t,"events",{}),r.add=function(t){return function(r){var n,i;return t.reverse_relation.add?t.reverse_relation.add(r,e):(n=r.get(t.reverse_relation.key),i=e.id&&u.dataId(n)===e.id,!i||i&&!n.isLoaded()?r.set(t.reverse_relation.key,e):void 0)}}(this),r.remove=function(t){return function(r){var n;return u.orSet(e,"rel_dirty",{})[t.key]=!0,t.reverse_relation.remove?t.reverse_relation.remove(r,e):(n=r.get(t.reverse_relation.key),u.dataId(n)===e.id?r.set(t.reverse_relation.key,null):void 0)}}(this),r.reset=function(t){return function(n,i){var o,s,a,c,h,f,p,d,y,g;if(u.orSet(e,"rel_dirty",{})[t.key]=!0,a=n.models,d=i.previousModels||[],s=l.groupBy(d,function(e){return l.find(a,function(t){return t.id===e.id})?"kept":"removed"}),o=s.kept?l.select(a,function(e){return!l.find(s.kept,function(t){return t.id===e.id})}):a,s.removed)for(y=s.removed,c=0,f=y.length;f>c;c++)g=y[c],r.remove(g);for(h=0,p=o.length;p>h;h++)g=o[h],r.add(g)}}(this),s=["add","remove","reset"],n=0,i=s.length;i>n;n++)o=s[n],t.on(o,r[o]);return t},t.prototype._unbindBacklinks=function(e){var t,r,n,i,o,s;if(r=u.get(e,"events"))for(u.unset(e,"events"),t=e.attributes[this.key],t.models.splice(),s=["add","remove","reset"],n=0,i=s.length;i>n;n++)o=s[n],t.off(o,r[o]),r[o]=null},t.prototype._ensureCollection=function(e){return this._bindBacklinks(e)},t.prototype._hasChanged=function(e){return!!u.orSet(e,"rel_dirty",{})[this.key]||e.hasChanged(this.key)},t}(r(45))},function(e,t,r){var n,i,o,s,a,u,l,c,h,f,p=function(e,t){return function(){return e.apply(t,arguments)}};f=r(1),n=r(3),l=r(11),a=r(23),c=r(43),h=r(24),s=r(33),o=2e3,i={embed:!0,json:!0,unique:!0,manual_ids:!0,dynamic:!0,self_reference:!0},u=function(){function e(e){var t,r;this.model_type=e,this.deleteCB=p(this.deleteCB,this),this.model_type.model_name=h.findOrGenerateModelName(this.model_type),this.schema=new c(this.model_type),(null!=(r=this.schema.field("id"))?r.type:void 0)||this.schema.type("id","Integer"),this.store=(t=this.model_type).store||(t.store=[]),this.id=0,this.id_attribute=this.model_type.prototype.idAttribute}return e.prototype.initialize=function(){var e;if(!this.is_initialized)return this.is_initialized=!0,this.schema.initialize(),(null!=(e=this.schema.field("id"))?e.manual:void 0)&&(this.manual_id=!0),this.id_type=this.schema.idType()},e.prototype.read=function(e,t){var r;return e.models?t.success(function(){var e,t,n,i;for(n=this.store,i=[],e=0,t=n.length;t>e;e++)r=n[e],i.push(s.deepClone(r));return i}.call(this)):(r=this.get(e.id))?t.success(s.deepClone(r)):t.error(new Error("Model not found with id: "+e.id))},e.prototype.create=function(e,t){var r;return this.manual_id?t.error(new Error("Create should not be called for a manual id. Set an id before calling save. Model name: "+this.model_type.model_name+". Model: "+s.stringify(e.toJSON()))):(e.set(this.id_attribute,"String"===this.id_type?""+ ++this.id:++this.id),this.store.splice(this.insertIndexOf(e.id),0,r=e.toJSON()),t.success(s.deepClone(r)))},e.prototype.update=function(e,t){var r,n,i;return r=(n=this.insertIndexOf(e.id))>=this.store.length||this.store[n].id!==e.id,!this.manual_id&&r?t.error(new Error("Update cannot create a new model without manual option. Set an id before calling save. Model name: "+this.model_type.model_name+". Model: "+s.stringify(e.toJSON()))):(i=e.toJSON(),r?this.store.splice(n,0,i):this.store[n]=i,t.success(s.deepClone(i)))},e.prototype["delete"]=function(e,t){return this.deleteCB(e,function(e){return function(e){return e?t.error(e):t.success()}}(this))},e.prototype.deleteCB=function(e,t){var r,n;return(r=this.indexOf(e.id))<0?t(new Error("Model not found. Type: "+this.model_type.model_name+". Id: "+e.id)):(n=this.store.splice(r,1),h.patchRemove(this.model_type,e,t))},e.prototype.resetSchema=function(e,t){return this.destroy(t)},e.prototype.cursor=function(e){return null==e&&(e={}),new a(e,f.pick(this,["model_type","store"]))},e.prototype.destroy=function(e,t){var r,n,i,a;return 1===arguments.length&&(a=[{},e],e=a[0],t=a[1]),s.isEmptyObject(e)?h.popEach(this.store,function(e){return function(t,r){return h.patchRemove(e.model_type,t,r)}}(this),t):(n=!1,r=this.model_type.cursor(e).limit(o),(i=function(e){return function(){return r.toJSON(function(r,s){return r?t(r):0===s.length?t():(n=s.length<o,h.each(s,e.deleteCB,function(e){return e||n?t(e):i()}))})}}(this))())},e.prototype.get=function(e){var t,r;return(t=f.sortedIndex(this.store,{id:e},this.id_attribute))>=this.store.length||(r=this.store[t]).id!==e?null:r},e.prototype.indexOf=function(e){var t;return(t=f.sortedIndex(this.store,{id:e},this.id_attribute))>=this.store.length||this.store[t].id!==e?-1:t},e.prototype.insertIndexOf=function(e){return f.sortedIndex(this.store,{id:e},this.id_attribute)},e}(),e.exports=function(t){var r,i,o;return h.isCollection(new t)?(r=h.configureCollectionModelType(t,e.exports),t.prototype.sync=r.prototype.sync):(i=new u(t),t.prototype.sync=o=function(t,r,n){return null==n&&(n={}),i.initialize(),"createSync"===t?e.exports.apply(null,Array.prototype.slice.call(arguments,1)):"sync"===t?i:"isRemote"===t?!1:"schema"===t?i.schema:"tableName"!==t&&i[t]?i[t].apply(i,Array.prototype.slice.call(arguments,1)):void 0},h.configureModelType(t),n.model_cache.configureSync(t,o))},e.exports.Sync=u,e.exports.Cursor=a,e.exports.capabilities=function(e){return i}},function(e,t){var r;e.exports=r=function(){function e(){}return e.optionSets=function(){return[{cache:!1,embed:!1,$tags:"@no_cache @no_embed @quick"},{cache:!0,embed:!1,$tags:"@cache @no_embed"},{cache:!1,embed:!0,$tags:"@no_cache @embed"},{cache:!0,embed:!0,$tags:"@cache @embed"}]},e}()},function(e,t,r){var n,i,o;o=r(1),i=r(11),e.exports=n=function(){function e(){}return e["new"]=function(e,t,r){var n,i,s,a;for(s=[];t-- >0;){n={};for(i in r)a=r[i],n[i]=o.isFunction(a)?a():a;s.push(new e(n))}return s},e.create=function(t,r,n,o){var s,a,u,l,c,h;for(c=e["new"](t,r,n),h=new i,s=function(e){return h.defer(function(t){return e.save(t)})},a=0,u=c.length;u>a;a++)l=c[a],s(l);return h.await(function(e){return o(e,c)})},e.value=function(e){return 0!==arguments.length?function(){return e}:void 0},e.increment=function(e){return 0!==arguments.length?function(){return e++}:void 0},e.uniqueId=function(e){return 0===arguments.length?o.uniqueId():function(){return o.uniqueId(e)}},e.uniqueString=e.uniqueId,e.date=function(e,t){var r,n,i;return n=new Date,0===arguments.length?n:(1===arguments.length&&(i=[n,e],e=i[0],t=i[1]),r=e.getTime(),function(){var e;return e=new Date(r),r+=t,e})},e}()},function(e,t,r){var n;n=r(12),e.exports=new n({destroy:function(e,t){return t.destroy()}})},function(e,t,r){var n,i,o,s;n=r(3).Backbone,s=n.VERSION.split("."),i=s[0],o=s[1],+i>=1&&+o>=2&&(n.Collection.prototype._removeModels=function(e,t){for(var r=[],n=0;n<e.length;n++){var i=this.get(e[n]);if(i){var o=this.modelId(i.attributes);null!=o&&delete this._byId[o],delete this._byId[i.cid];var s=this.indexOf(i);this.models.splice(s,1),this.length--,t.silent||(t.index=s,i.trigger("remove",i,this,t)),r.push(i),this._removeReference(i,t)}}return r.length?r:!1})}])});