diff --git a/dist/index.js b/dist/index.js index 8e5c3b8..b75b8c8 100644 --- a/dist/index.js +++ b/dist/index.js @@ -13,4 +13,4 @@ * @author Feross Aboukhadijeh * @license MIT */ -t.exports=function(t){return null!=t&&(n(t)||function(t){return"function"==typeof t.readFloatLE&&"function"==typeof t.slice&&n(t.slice(0,0))}(t)||!!t._isBuffer)}},function(t,e,n){"use strict";var r=n(2),o=n(0),i=n(40),u=n(41);function a(t){this.defaults=t,this.interceptors={request:new i,response:new i}}a.prototype.request=function(t){"string"==typeof t&&(t=o.merge({url:arguments[0]},arguments[1])),(t=o.merge(r,{method:"get"},this.defaults,t)).method=t.method.toLowerCase();var e=[u,void 0],n=Promise.resolve(t);for(this.interceptors.request.forEach(function(t){e.unshift(t.fulfilled,t.rejected)}),this.interceptors.response.forEach(function(t){e.push(t.fulfilled,t.rejected)});e.length;)n=n.then(e.shift(),e.shift());return n},o.forEach(["delete","get","head","options"],function(t){a.prototype[t]=function(e,n){return this.request(o.merge(n||{},{method:t,url:e}))}}),o.forEach(["post","put","patch"],function(t){a.prototype[t]=function(e,n,r){return this.request(o.merge(r||{},{method:t,url:e,data:n}))}}),t.exports=a},function(t,e,n){"use strict";var r=n(0);t.exports=function(t,e){r.forEach(t,function(n,r){r!==e&&r.toUpperCase()===e.toUpperCase()&&(t[e]=n,delete t[r])})}},function(t,e,n){"use strict";var r=n(0),o=n(5),i=n(7),u=n(22),a=n(23),s=n(3),c="undefined"!=typeof window&&window.btoa&&window.btoa.bind(window)||n(24);t.exports=function(t){return new Promise(function(e,f){var l=t.data,h=t.headers;r.isFormData(l)&&delete h["Content-Type"];var p=new XMLHttpRequest,d="onreadystatechange",y=!1;if("undefined"==typeof window||!window.XDomainRequest||"withCredentials"in p||a(t.url)||(p=new window.XDomainRequest,d="onload",y=!0,p.onprogress=function(){},p.ontimeout=function(){}),t.auth){var v=t.auth.username||"",g=t.auth.password||"";h.Authorization="Basic "+c(v+":"+g)}if(p.open(t.method.toUpperCase(),i(t.url,t.params,t.paramsSerializer),!0),p.timeout=t.timeout,p[d]=function(){if(p&&(4===p.readyState||y)&&(0!==p.status||p.responseURL&&0===p.responseURL.indexOf("file:"))){var n="getAllResponseHeaders"in p?u(p.getAllResponseHeaders()):null,r={data:t.responseType&&"text"!==t.responseType?p.response:p.responseText,status:1223===p.status?204:p.status,statusText:1223===p.status?"No Content":p.statusText,headers:n,config:t,request:p};o(e,f,r),p=null}},p.onerror=function(){f(s("Network Error",t,null,p)),p=null},p.ontimeout=function(){f(s("timeout of "+t.timeout+"ms exceeded",t,"ECONNABORTED",p)),p=null},r.isStandardBrowserEnv()){var m=n(25),_=(t.withCredentials||a(t.url))&&t.xsrfCookieName?m.read(t.xsrfCookieName):void 0;_&&(h[t.xsrfHeaderName]=_)}if("setRequestHeader"in p&&r.forEach(h,function(t,e){void 0===l&&"content-type"===e.toLowerCase()?delete h[e]:p.setRequestHeader(e,t)}),t.withCredentials&&(p.withCredentials=!0),t.responseType)try{p.responseType=t.responseType}catch(e){if("json"!==t.responseType)throw e}"function"==typeof t.onDownloadProgress&&p.addEventListener("progress",t.onDownloadProgress),"function"==typeof t.onUploadProgress&&p.upload&&p.upload.addEventListener("progress",t.onUploadProgress),t.cancelToken&&t.cancelToken.promise.then(function(t){p&&(p.abort(),f(t),p=null)}),void 0===l&&(l=null),p.send(l)})}},function(t,e,n){"use strict";var r=n(0),o=["age","authorization","content-length","content-type","etag","expires","from","host","if-modified-since","if-unmodified-since","last-modified","location","max-forwards","proxy-authorization","referer","retry-after","user-agent"];t.exports=function(t){var e,n,i,u={};return t?(r.forEach(t.split("\n"),function(t){if(i=t.indexOf(":"),e=r.trim(t.substr(0,i)).toLowerCase(),n=r.trim(t.substr(i+1)),e){if(u[e]&&o.indexOf(e)>=0)return;u[e]="set-cookie"===e?(u[e]?u[e]:[]).concat([n]):u[e]?u[e]+", "+n:n}}),u):u}},function(t,e,n){"use strict";var r=n(0);t.exports=r.isStandardBrowserEnv()?function(){var t,e=/(msie|trident)/i.test(navigator.userAgent),n=document.createElement("a");function o(t){var r=t;return e&&(n.setAttribute("href",r),r=n.href),n.setAttribute("href",r),{href:n.href,protocol:n.protocol?n.protocol.replace(/:$/,""):"",host:n.host,search:n.search?n.search.replace(/^\?/,""):"",hash:n.hash?n.hash.replace(/^#/,""):"",hostname:n.hostname,port:n.port,pathname:"/"===n.pathname.charAt(0)?n.pathname:"/"+n.pathname}}return t=o(window.location.href),function(e){var n=r.isString(e)?o(e):e;return n.protocol===t.protocol&&n.host===t.host}}():function(){return!0}},function(t,e,n){"use strict";var r="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";function o(){this.message="String contains an invalid character"}o.prototype=new Error,o.prototype.code=5,o.prototype.name="InvalidCharacterError",t.exports=function(t){for(var e,n,i=String(t),u="",a=0,s=r;i.charAt(0|a)||(s="=",a%1);u+=s.charAt(63&e>>8-a%1*8)){if((n=i.charCodeAt(a+=.75))>255)throw new o;e=e<<8|n}return u}},function(t,e,n){"use strict";var r=n(0);t.exports=r.isStandardBrowserEnv()?{write:function(t,e,n,o,i,u){var a=[];a.push(t+"="+encodeURIComponent(e)),r.isNumber(n)&&a.push("expires="+new Date(n).toGMTString()),r.isString(o)&&a.push("path="+o),r.isString(i)&&a.push("domain="+i),!0===u&&a.push("secure"),document.cookie=a.join("; ")},read:function(t){var e=document.cookie.match(new RegExp("(^|;\\s*)("+t+")=([^;]*)"));return e?decodeURIComponent(e[3]):null},remove:function(t){this.write(t,"",Date.now()-864e5)}}:{write:function(){},read:function(){return null},remove:function(){}}},function(t,e,n){"use strict";var r=n(0),o=n(5),i=n(7),u=n(8),a=n(9),s=n(10).http,c=n(10).https,f=n(11),l=n(38),h=n(39),p=n(3),d=n(6);t.exports=function(t){return new Promise(function(e,n){var y,v=t.data,g=t.headers;if(g["User-Agent"]||g["user-agent"]||(g["User-Agent"]="axios/"+h.version),v&&!r.isStream(v)){if(Buffer.isBuffer(v));else if(r.isArrayBuffer(v))v=new Buffer(new Uint8Array(v));else{if(!r.isString(v))return n(p("Data after transformation must be a string, an ArrayBuffer, a Buffer, or a Stream",t));v=new Buffer(v,"utf-8")}g["Content-Length"]=v.length}var m=void 0;t.auth&&(m=(t.auth.username||"")+":"+(t.auth.password||""));var _=f.parse(t.url),b=_.protocol||"http:";if(!m&&_.auth){var w=_.auth.split(":");m=(w[0]||"")+":"+(w[1]||"")}m&&delete g.Authorization;var x="https:"===b,C=x?t.httpsAgent:t.httpAgent,R={path:i(_.path,t.params,t.paramsSerializer).replace(/^\?/,""),method:t.method,headers:g,agent:C,auth:m};t.socketPath?R.socketPath=t.socketPath:(R.hostname=_.hostname,R.port=_.port);var O,E=t.proxy;if(!E&&!1!==E){var k=b.slice(0,-1)+"_proxy",A=process.env[k]||process.env[k.toUpperCase()];if(A){var j=f.parse(A);if(E={host:j.hostname,port:j.port},j.auth){var S=j.auth.split(":");E.auth={username:S[0],password:S[1]}}}}if(E&&(R.hostname=E.host,R.host=E.host,R.headers.host=_.hostname+(_.port?":"+_.port:""),R.port=E.port,R.path=b+"//"+_.hostname+(_.port?":"+_.port:"")+R.path,E.auth)){var $=new Buffer(E.auth.username+":"+E.auth.password,"utf8").toString("base64");R.headers["Proxy-Authorization"]="Basic "+$}t.transport?O=t.transport:0===t.maxRedirects?O=x?a:u:(t.maxRedirects&&(R.maxRedirects=t.maxRedirects),O=x?c:s),t.maxContentLength&&t.maxContentLength>-1&&(R.maxBodyLength=t.maxContentLength);var F=O.request(R,function(r){if(!F.aborted){clearTimeout(y),y=null;var i=r;switch(r.headers["content-encoding"]){case"gzip":case"compress":case"deflate":i=i.pipe(l.createUnzip()),delete r.headers["content-encoding"]}var u=r.req||F,a={status:r.statusCode,statusText:r.statusMessage,headers:r.headers,config:t,request:u};if("stream"===t.responseType)a.data=i,o(e,n,a);else{var s=[];i.on("data",function(e){s.push(e),t.maxContentLength>-1&&Buffer.concat(s).length>t.maxContentLength&&n(p("maxContentLength size of "+t.maxContentLength+" exceeded",t,null,u))}),i.on("error",function(e){F.aborted||n(d(e,t,null,u))}),i.on("end",function(){var r=Buffer.concat(s);"arraybuffer"!==t.responseType&&(r=r.toString("utf8")),a.data=r,o(e,n,a)})}}});F.on("error",function(e){F.aborted||n(d(e,t,null,F))}),t.timeout&&!y&&(y=setTimeout(function(){F.abort(),n(p("timeout of "+t.timeout+"ms exceeded",t,"ECONNABORTED",F))},t.timeout)),t.cancelToken&&t.cancelToken.promise.then(function(t){F.aborted||(F.abort(),n(t))}),r.isStream(v)?v.pipe(F):F.end(v)})}},function(t,e){t.exports=require("assert")},function(t,e){t.exports=require("stream")},function(t,e,n){"undefined"==typeof process||"renderer"===process.type?t.exports=n(30):t.exports=n(32)},function(t,e,n){function r(){var t;try{t=e.storage.debug}catch(t){}return!t&&"undefined"!=typeof process&&"env"in process&&(t=process.env.DEBUG),t}(e=t.exports=n(12)).log=function(){return"object"==typeof console&&console.log&&Function.prototype.apply.call(console.log,console,arguments)},e.formatArgs=function(t){var n=this.useColors;if(t[0]=(n?"%c":"")+this.namespace+(n?" %c":" ")+t[0]+(n?"%c ":" ")+"+"+e.humanize(this.diff),!n)return;var r="color: "+this.color;t.splice(1,0,r,"color: inherit");var o=0,i=0;t[0].replace(/%[a-zA-Z%]/g,function(t){"%%"!==t&&"%c"===t&&(i=++o)}),t.splice(i,0,r)},e.save=function(t){try{null==t?e.storage.removeItem("debug"):e.storage.debug=t}catch(t){}},e.load=r,e.useColors=function(){if("undefined"!=typeof window&&window.process&&"renderer"===window.process.type)return!0;if("undefined"!=typeof navigator&&navigator.userAgent&&navigator.userAgent.toLowerCase().match(/(edge|trident)\/(\d+)/))return!1;return"undefined"!=typeof document&&document.documentElement&&document.documentElement.style&&document.documentElement.style.WebkitAppearance||"undefined"!=typeof window&&window.console&&(window.console.firebug||window.console.exception&&window.console.table)||"undefined"!=typeof navigator&&navigator.userAgent&&navigator.userAgent.toLowerCase().match(/firefox\/(\d+)/)&&parseInt(RegExp.$1,10)>=31||"undefined"!=typeof navigator&&navigator.userAgent&&navigator.userAgent.toLowerCase().match(/applewebkit\/(\d+)/)},e.storage="undefined"!=typeof chrome&&void 0!==chrome.storage?chrome.storage.local:function(){try{return window.localStorage}catch(t){}}(),e.colors=["#0000CC","#0000FF","#0033CC","#0033FF","#0066CC","#0066FF","#0099CC","#0099FF","#00CC00","#00CC33","#00CC66","#00CC99","#00CCCC","#00CCFF","#3300CC","#3300FF","#3333CC","#3333FF","#3366CC","#3366FF","#3399CC","#3399FF","#33CC00","#33CC33","#33CC66","#33CC99","#33CCCC","#33CCFF","#6600CC","#6600FF","#6633CC","#6633FF","#66CC00","#66CC33","#9900CC","#9900FF","#9933CC","#9933FF","#99CC00","#99CC33","#CC0000","#CC0033","#CC0066","#CC0099","#CC00CC","#CC00FF","#CC3300","#CC3333","#CC3366","#CC3399","#CC33CC","#CC33FF","#CC6600","#CC6633","#CC9900","#CC9933","#CCCC00","#CCCC33","#FF0000","#FF0033","#FF0066","#FF0099","#FF00CC","#FF00FF","#FF3300","#FF3333","#FF3366","#FF3399","#FF33CC","#FF33FF","#FF6600","#FF6633","#FF9900","#FF9933","#FFCC00","#FFCC33"],e.formatters.j=function(t){try{return JSON.stringify(t)}catch(t){return"[UnexpectedJSONParseError]: "+t.message}},e.enable(r())},function(t,e){var n=1e3,r=60*n,o=60*r,i=24*o,u=365.25*i;function a(t,e,n){if(!(t0)return function(t){if((t=String(t)).length>100)return;var e=/^((?:\d+)?\.?\d+) *(milliseconds?|msecs?|ms|seconds?|secs?|s|minutes?|mins?|m|hours?|hrs?|h|days?|d|years?|yrs?|y)?$/i.exec(t);if(!e)return;var a=parseFloat(e[1]);switch((e[2]||"ms").toLowerCase()){case"years":case"year":case"yrs":case"yr":case"y":return a*u;case"days":case"day":case"d":return a*i;case"hours":case"hour":case"hrs":case"hr":case"h":return a*o;case"minutes":case"minute":case"mins":case"min":case"m":return a*r;case"seconds":case"second":case"secs":case"sec":case"s":return a*n;case"milliseconds":case"millisecond":case"msecs":case"msec":case"ms":return a;default:return}}(t);if("number"===s&&!1===isNaN(t))return e.long?function(t){return a(t,i,"day")||a(t,o,"hour")||a(t,r,"minute")||a(t,n,"second")||t+" ms"}(t):function(t){if(t>=i)return Math.round(t/i)+"d";if(t>=o)return Math.round(t/o)+"h";if(t>=r)return Math.round(t/r)+"m";if(t>=n)return Math.round(t/n)+"s";return t+"ms"}(t);throw new Error("val is not a non-empty string or a valid number. val="+JSON.stringify(t))}},function(t,e,n){var r=n(33),o=n(34);(e=t.exports=n(12)).init=function(t){t.inspectOpts={};for(var n=Object.keys(e.inspectOpts),r=0;r=2&&(e.colors=[20,21,26,27,32,33,38,39,40,41,42,43,44,45,56,57,62,63,68,69,74,75,76,77,78,79,80,81,92,93,98,99,112,113,128,129,134,135,148,149,160,161,162,163,164,165,166,167,168,169,170,171,172,173,178,179,184,185,196,197,198,199,200,201,202,203,204,205,206,207,208,209,214,215,220,221])}catch(t){}function u(){return process.env.DEBUG}e.inspectOpts=Object.keys(process.env).filter(function(t){return/^debug_/i.test(t)}).reduce(function(t,e){var n=e.substring(6).toLowerCase().replace(/_([a-z])/g,function(t,e){return e.toUpperCase()}),r=process.env[e];return r=!!/^(yes|on|true|enabled)$/i.test(r)||!/^(no|off|false|disabled)$/i.test(r)&&("null"===r?null:Number(r)),t[n]=r,t},{}),e.formatters.o=function(t){return this.inspectOpts.colors=this.useColors,o.inspect(t,this.inspectOpts).split("\n").map(function(t){return t.trim()}).join(" ")},e.formatters.O=function(t){return this.inspectOpts.colors=this.useColors,o.inspect(t,this.inspectOpts)},e.enable(u())},function(t,e){t.exports=require("tty")},function(t,e){t.exports=require("util")},function(t,e,n){"use strict";const r=n(36),o=n(37),i=process.env;let u;function a(t){return function(t){return 0!==t&&{level:t,hasBasic:!0,has256:t>=2,has16m:t>=3}}(function(t){if(!1===u)return 0;if(o("color=16m")||o("color=full")||o("color=truecolor"))return 3;if(o("color=256"))return 2;if(t&&!t.isTTY&&!0!==u)return 0;const e=u?1:0;if("win32"===process.platform){const t=r.release().split(".");return Number(process.versions.node.split(".")[0])>=8&&Number(t[0])>=10&&Number(t[2])>=10586?Number(t[2])>=14931?3:2:1}if("CI"in i)return["TRAVIS","CIRCLECI","APPVEYOR","GITLAB_CI"].some(t=>t in i)||"codeship"===i.CI_NAME?1:e;if("TEAMCITY_VERSION"in i)return/^(9\.(0*[1-9]\d*)\.|\d{2,}\.)/.test(i.TEAMCITY_VERSION)?1:0;if("truecolor"===i.COLORTERM)return 3;if("TERM_PROGRAM"in i){const t=parseInt((i.TERM_PROGRAM_VERSION||"").split(".")[0],10);switch(i.TERM_PROGRAM){case"iTerm.app":return t>=3?3:2;case"Apple_Terminal":return 2}}return/-256(color)?$/i.test(i.TERM)?2:/^screen|^xterm|^vt100|^vt220|^rxvt|color|ansi|cygwin|linux/i.test(i.TERM)?1:"COLORTERM"in i?1:(i.TERM,e)}(t))}o("no-color")||o("no-colors")||o("color=false")?u=!1:(o("color")||o("colors")||o("color=true")||o("color=always"))&&(u=!0),"FORCE_COLOR"in i&&(u=0===i.FORCE_COLOR.length||0!==parseInt(i.FORCE_COLOR,10)),t.exports={supportsColor:a,stdout:a(process.stdout),stderr:a(process.stderr)}},function(t,e){t.exports=require("os")},function(t,e,n){"use strict";t.exports=((t,e)=>{e=e||process.argv;const n=t.startsWith("-")?"":1===t.length?"-":"--",r=e.indexOf(n+t),o=e.indexOf("--");return-1!==r&&(-1===o||r=0?i=a:(i=o+a)<0&&(i=0);i0&&o[o.length-1])&&(6===i[0]||2===i[0])){u=0;continue}if(3===i[0]&&(!o||i[1]>o[0]&&i[1]e)return 1;if(t=u)return s;var c=n[a];return s*("desc"===c?-1:1)}}return t.index-e.index}(t,e,n)})},pickBy:function(t,e){return Object.keys(t).reduce(function(n,r){var o=t[r];return e(o,r)&&(n[r]=o),n},{})}},p=function(){return function(t){this.model=t}}(),d=function(t){function e(e,n){var r=t.call(this,e)||this;return r.mutator=n,r}return a(e,t),e.prototype.mutate=function(t,e){var n=this.mutator||this.model.mutators()[e];return n?n(t):t},e}(p),y=function(t){function e(e,n,r){var o=t.call(this,e,r)||this;return o.value=n,o}return a(e,t),e.prototype.make=function(t,e,n){return t=void 0!==t?t:this.value,this.mutate(t,n)},e}(d),v=function(t){function e(e){var n=t.call(this,e)||this;return n.value=1,n}return a(e,t),e.prototype.make=function(t,e,n){return"number"==typeof t?t:null},e}(d),g=function(t){function e(e,n,r){var o=t.call(this,e,r)||this;return o.isNullable=!1,o.value=n,o}return a(e,t),e.prototype.nullable=function(){return this.isNullable=!0,this},e.prototype.make=function(t,e,n){return this.mutate(this.fix(t),n)},e.prototype.fix=function(t){return void 0===t?this.value:"string"==typeof t?t:null===t&&this.isNullable?t:t+""},e}(d),m=function(t){function e(e,n,r){var o=t.call(this,e,r)||this;return o.isNullable=!1,o.value=n,o}return a(e,t),e.prototype.nullable=function(){return this.isNullable=!0,this},e.prototype.make=function(t,e,n){return this.mutate(this.fix(t),n)},e.prototype.fix=function(t){return void 0===t?this.value:"number"==typeof t?t:"string"==typeof t?parseFloat(t):"boolean"==typeof t?t?1:0:null===t&&this.isNullable?t:0},e}(d),b=function(t){function e(e,n,r){var o=t.call(this,e,r)||this;return o.isNullable=!1,o.value=n,o}return a(e,t),e.prototype.nullable=function(){return this.isNullable=!0,this},e.prototype.make=function(t,e,n){return this.mutate(this.fix(t),n)},e.prototype.fix=function(t){if(void 0===t)return this.value;if("boolean"==typeof t)return t;if("string"==typeof t){if(0===t.length)return!1;var e=parseInt(t,0);return!!isNaN(e)||!!e}return"number"==typeof t?!!t:!(null!==t||!this.isNullable)&&t},e}(d),w=function(t){function e(){return null!==t&&t.apply(this,arguments)||this}return a(e,t),e.prototype.getRelation=function(t,e){var n=t.newQuery(e);return this.addEagerConstraint(t,n),n},e.prototype.getKeys=function(t,e){return t.map(function(t){return t[e]})},e.prototype.addEagerConstraint=function(t,e){for(var n in t.load)t.load[n].forEach(function(t){t(e)})},e.prototype.mapSingleRelations=function(t,e){return t.reduce(function(t,n){return t[n[e]]=n,t},{})},e.prototype.mapManyRelations=function(t,e){return t.reduce(function(t,n){var r=n[e];return t[r]||(t[r]=[]),t[r].push(n),t},{})},e.prototype.isOneRelation=function(t){return!Array.isArray(t)&&null!==t&&"object"==typeof t},e.prototype.isManyRelation=function(t){return!!Array.isArray(t)&&!(t.length<1)},e.prototype.makeManyRelation=function(t,e){var n=this;return this.isManyRelation(t)?t.filter(function(t){return n.isOneRelation(t)}).map(function(t){return new e(t)}):[]},e}(p),x=function(t){function e(e,n,r,o){var i=t.call(this,e)||this;return i.related=i.model.relation(n),i.foreignKey=r,i.localKey=o,i}return a(e,t),e.prototype.define=function(t){return t.one(this.related)},e.prototype.attach=function(t,e,n){var r=n[this.related.entity];r&&r[t]&&void 0===r[t][this.foreignKey]&&(e[this.localKey]||(e[this.localKey]=e.$id),r[t][this.foreignKey]=e[this.localKey])},e.prototype.make=function(t,e,n){return this.isOneRelation(t)?new this.related(t):null},e.prototype.load=function(t,e,n){var r=this,o=this.getRelation(t,this.related.entity);o.where(this.foreignKey,this.getKeys(e,this.localKey));var i=this.mapSingleRelations(o.get(),this.foreignKey);e.forEach(function(t){var e=i[t[r.localKey]];t[n]=e||null})},e}(w),C=function(t){function e(e,n,r,o){var i=t.call(this,e)||this;return i.parent=i.model.relation(n),i.foreignKey=r,i.ownerKey=o,i}return a(e,t),e.prototype.define=function(t){return t.one(this.parent)},e.prototype.attach=function(t,e,n){void 0===e[this.foreignKey]&&(e[this.foreignKey]=t)},e.prototype.make=function(t,e,n){return this.isOneRelation(t)?new this.parent(t):null},e.prototype.load=function(t,e,n){var r=this,o=this.getRelation(t,this.parent.entity);o.where(this.ownerKey,this.getKeys(e,this.foreignKey));var i=this.mapSingleRelations(o.get(),this.ownerKey);e.forEach(function(t){var e=i[t[r.foreignKey]];t[n]=e||null})},e}(w),R=function(t){function e(e,n,r,o){var i=t.call(this,e)||this;return i.related=i.model.relation(n),i.foreignKey=r,i.localKey=o,i}return a(e,t),e.prototype.define=function(t){return t.many(this.related)},e.prototype.attach=function(t,e,n){var r=this;Array.isArray(t)&&t.forEach(function(t){var o=n[r.related.entity];o&&o[t]&&void 0===o[t][r.foreignKey]&&(o[t][r.foreignKey]=e.$id)})},e.prototype.make=function(t,e,n){return this.makeManyRelation(t,this.related)},e.prototype.load=function(t,e,n){var r=this,o=this.getRelation(t,this.related.entity);o.where(this.foreignKey,this.getKeys(e,this.localKey));var i=this.mapManyRelations(o.get(),this.foreignKey);e.forEach(function(t){var e=i[t[r.localKey]];t[n]=e||[]})},e}(w),O=function(t){function e(e,n,r,o){var i=t.call(this,e)||this;return i.parent=i.model.relation(n),i.foreignKey=r,i.ownerKey=o,i}return a(e,t),e.prototype.define=function(t){return t.many(this.parent)},e.prototype.attach=function(t,e,n){0!==t.length&&void 0===e[this.foreignKey]&&(e[this.foreignKey]=t)},e.prototype.make=function(t,e,n){return this.makeManyRelation(t,this.parent)},e.prototype.load=function(t,e,n){var r=this,o=this.getRelation(t,this.parent.entity);this.addConstraintForHasManyBy(o,e);var i=this.mapSingleRelations(o.get(),this.ownerKey);e.forEach(function(t){var e=r.getRelatedRecords(i,t[r.foreignKey]);t[n]=e})},e.prototype.addConstraintForHasManyBy=function(t,e){var n=this,r=e.reduce(function(t,e){return t.concat(e[n.foreignKey])},[]);t.where(this.ownerKey,r)},e.prototype.getRelatedRecords=function(t,e){return e.reduce(function(e,n){var r=t[n];return r&&e.push(r),e},[])},e}(w),E=function(t){function e(e,n,r,o,i,u,a){var s=t.call(this,e)||this;return s.related=s.model.relation(n),s.through=s.model.relation(r),s.firstKey=o,s.secondKey=i,s.localKey=u,s.secondLocalKey=a,s}return a(e,t),e.prototype.define=function(t){return t.many(this.related)},e.prototype.attach=function(t,e,n){},e.prototype.make=function(t,e,n){return this.makeManyRelation(t,this.related)},e.prototype.load=function(t,e,n){var r=this,o=this.getRelation(t,this.related.entity),i=t.newQuery(this.through.entity);this.addEagerConstraintForThrough(i,e);var u=i.get();this.addEagerConstraintForRelated(o,u);var a=this.mapThroughRelations(u,o);e.forEach(function(t){var e=a[t[r.localKey]];t[n]=e||[]})},e.prototype.addEagerConstraintForThrough=function(t,e){t.where(this.firstKey,this.getKeys(e,this.localKey))},e.prototype.addEagerConstraintForRelated=function(t,e){t.where(this.secondKey,this.getKeys(e,this.secondLocalKey))},e.prototype.mapThroughRelations=function(t,e){var n=this,r=this.mapManyRelations(e.get(),this.secondKey);return t.reduce(function(t,e){var o=e[n.firstKey];t[o]||(t[o]=[]);var i=r[e[n.secondLocalKey]];return t[o]=t[o].concat(i),t},{})},e}(w),k=function(t){function e(e,n,r,o,i,u,a){var s=t.call(this,e)||this;return s.related=s.model.relation(n),s.pivot=s.model.relation(r),s.foreignPivotKey=o,s.relatedPivotKey=i,s.parentKey=u,s.relatedKey=a,s}return a(e,t),e.prototype.define=function(t){return t.many(this.related)},e.prototype.attach=function(t,e,n){},e.prototype.make=function(t,e,n){return this.makeManyRelation(t,this.related)},e.prototype.load=function(t,e,n){var r=this,o=this.getRelation(t,this.related.entity),i=t.newQuery(this.pivot.entity);this.addEagerConstraintForPivot(i,e);var u=i.get();this.addEagerConstraintForRelated(o,u);var a=this.mapPivotRelations(u,o);e.forEach(function(t){var e=a[t[r.parentKey]];t[n]=e})},e.prototype.addEagerConstraintForPivot=function(t,e){t.where(this.foreignPivotKey,this.getKeys(e,this.parentKey))},e.prototype.addEagerConstraintForRelated=function(t,e){t.where(this.relatedKey,this.getKeys(e,this.relatedPivotKey))},e.prototype.mapPivotRelations=function(t,e){var n=this,r=this.mapManyRelations(e.get(),this.relatedKey);return t.reduce(function(t,e){var o=e[n.foreignPivotKey];t[o]||(t[o]=[]);var i=r[e[n.relatedPivotKey]];return i&&(t[o]=t[o].concat(i)),t},{})},e.prototype.createPivots=function(t,e,n){var r=this;return this.pivot.primaryKey instanceof Array==!1?e:(h.forOwn(e[t.entity],function(t){var o=t[n];void 0!==o&&0!==o.length&&r.createPivotRecord(e,t,o)}),e)},e.prototype.createPivotRecord=function(t,e,n){var r=this;n.forEach(function(n){var o,i,u=e[r.parentKey]+"_"+n;t[r.pivot.entity]=s({},t[r.pivot.entity],((o={})[u]=((i={$id:u})[r.foreignPivotKey]=e[r.parentKey],i[r.relatedPivotKey]=n,i),o))})},e}(w),A=function(t){function e(e,n,r){var o=t.call(this,e)||this;return o.id=n,o.type=r,o}return a(e,t),e.prototype.define=function(t){var e=this;return t.union(function(t,n){return n[e.type]})},e.prototype.attach=function(t,e,n){},e.prototype.make=function(t,e,n){if(!this.isOneRelation(t))return null;var r=e[this.type],o=this.model.relation(r);return o?new o(t):null},e.prototype.load=function(t,e,n){var r=this,o=this.getTypes(e).reduce(function(e,n){var o=r.getRelation(t,n);return e[n]=r.mapSingleRelations(o.get(),"$id"),e},{});e.forEach(function(t){var e=t[r.id],i=t[r.type],u=o[i][e];t[n]=u||null})},e.prototype.getTypes=function(t){var e=this;return t.reduce(function(t,n){var r=n[e.type];return!t.includes(r)&&t.push(r),t},[])},e}(w),j=function(t){function e(e,n,r,o,i){var u=t.call(this,e)||this;return u.related=u.model.relation(n),u.id=r,u.type=o,u.localKey=i,u}return a(e,t),e.prototype.define=function(t){return t.one(this.related)},e.prototype.attach=function(t,e,n){var r=n[this.related.entity]&&n[this.related.entity][t];r&&(r[this.id]=r[this.id]||e.$id,r[this.type]=r[this.type]||this.model.entity)},e.prototype.make=function(t,e,n){return this.isOneRelation(t)?new this.related(t):null},e.prototype.load=function(t,e,n){var r=this,o=this.getRelation(t,this.related.entity);this.addEagerConstraintForMorphOne(o,e,t.entity);var i=this.mapSingleRelations(o.get(),this.id);e.forEach(function(t){var e=i[t[r.localKey]];t[n]=e||null})},e.prototype.addEagerConstraintForMorphOne=function(t,e,n){t.where(this.type,n).where(this.id,this.getKeys(e,this.localKey))},e}(w),S=function(t){function e(e,n,r,o,i){var u=t.call(this,e)||this;return u.related=u.model.relation(n),u.id=r,u.type=o,u.localKey=i,u}return a(e,t),e.prototype.define=function(t){return t.many(this.related)},e.prototype.attach=function(t,e,n){var r=this;if(Array.isArray(t)){var o=n[this.related.entity];t.forEach(function(t){var n=o[t];n[r.id]=n[r.id]||e.$id,n[r.type]=n[r.type]||r.model.entity})}},e.prototype.make=function(t,e,n){return this.makeManyRelation(t,this.related)},e.prototype.load=function(t,e,n){var r=this,o=this.getRelation(t,this.related.entity);this.addEagerConstraintForMorphMany(o,e,t.entity);var i=this.mapManyRelations(o.get(),this.id);e.forEach(function(t){var e=i[t[r.localKey]];t[n]=e})},e.prototype.addEagerConstraintForMorphMany=function(t,e,n){t.where(this.type,n).where(this.id,this.getKeys(e,this.localKey))},e}(w),$=function(t){function e(e,n,r,o,i,u,a,s){var c=t.call(this,e)||this;return c.related=c.model.relation(n),c.pivot=c.model.relation(r),c.relatedId=o,c.id=i,c.type=u,c.parentKey=a,c.relatedKey=s,c}return a(e,t),e.prototype.define=function(t){return t.many(this.related)},e.prototype.attach=function(t,e,n){},e.prototype.make=function(t,e,n){return this.makeManyRelation(t,this.related)},e.prototype.load=function(t,e,n){var r=this,o=this.getRelation(t,this.related.entity),i=t.newQuery(this.pivot.entity);this.addEagerConstraintForPivot(i,e,t.entity);var u=i.get();this.addEagerConstraintForRelated(o,u);var a=this.mapPivotRelations(u,o);e.forEach(function(t){var e=a[t[r.parentKey]];t[n]=e})},e.prototype.addEagerConstraintForPivot=function(t,e,n){t.where(this.type,n).where(this.id,this.getKeys(e,this.parentKey))},e.prototype.addEagerConstraintForRelated=function(t,e){t.where(this.relatedKey,this.getKeys(e,this.relatedId))},e.prototype.mapPivotRelations=function(t,e){var n=this,r=this.mapManyRelations(e.get(),this.relatedKey);return t.reduce(function(t,e){var o=e[n.id];t[o]||(t[o]=[]);var i=r[e[n.relatedId]];return t[o]=t[o].concat(i),t},{})},e.prototype.createPivots=function(t,e,n){var r=this;return h.forOwn(e[t.entity],function(o){var i=o[n];Array.isArray(i)&&0!==i.length&&r.createPivotRecord(t,e,o,i)}),e},e.prototype.createPivotRecord=function(t,e,n,r){var o=this;r.forEach(function(r){var i,u,a=n[o.parentKey],c=a+"_"+r+"_"+t.entity;e[o.pivot.entity]=s({},e[o.pivot.entity],((i={})[c]=((u={$id:c})[o.relatedId]=r,u[o.id]=a,u[o.type]=t.entity,u),i))})},e}(w),F=function(t){function e(e,n,r,o,i,u,a,s){var c=t.call(this,e)||this;return c.related=c.model.relation(n),c.pivot=c.model.relation(r),c.relatedId=o,c.id=i,c.type=u,c.parentKey=a,c.relatedKey=s,c}return a(e,t),e.prototype.define=function(t){return t.many(this.related)},e.prototype.attach=function(t,e,n){},e.prototype.make=function(t,e,n){return this.makeManyRelation(t,this.related)},e.prototype.load=function(t,e,n){var r=this,o=this.getRelation(t,this.related.entity),i=t.newQuery(this.pivot.entity);this.addEagerConstraintForPivot(i,e,this.related.entity);var u=i.get();this.addEagerConstraintForRelated(o,u);var a=this.mapPivotRelations(u,o);e.forEach(function(t){var e=a[t[r.parentKey]];t[n]=e})},e.prototype.addEagerConstraintForPivot=function(t,e,n){t.where(this.type,n).where(this.relatedId,this.getKeys(e,this.parentKey))},e.prototype.addEagerConstraintForRelated=function(t,e){t.where(this.relatedKey,this.getKeys(e,this.id))},e.prototype.mapPivotRelations=function(t,e){var n=this,r=this.mapManyRelations(e.get(),this.relatedKey);return t.reduce(function(t,e){var o=e[n.relatedId];t[o]||(t[o]=[]);var i=r[e[n.id]];return t[o]=t[o].concat(i),t},{})},e.prototype.createPivots=function(t,e,n){var r=this;return h.forOwn(e[t.entity],function(t){var o=t[n];Array.isArray(o)&&r.createPivotRecord(e,t,o)}),e},e.prototype.createPivotRecord=function(t,e,n){var r=this;n.forEach(function(n){var o,i,u=e[r.parentKey],a=n+"_"+u+"_"+r.related.entity;t[r.pivot.entity]=s({},t[r.pivot.entity],((o={})[a]=((i={$id:a})[r.relatedId]=u,i[r.id]=n,i[r.type]=r.related.entity,i),o))})},e}(w),M=function(){function t(t){this.$id=null,this.$fill(t)}return t.fields=function(){return{}},t.getFields=function(){return this.cachedFields?this.cachedFields:(this.cachedFields=this.fields(),this.cachedFields)},t.attr=function(t,e){return new y(this,t,e)},t.string=function(t,e){return new g(this,t,e)},t.number=function(t,e){return new m(this,t,e)},t.boolean=function(t,e){return new b(this,t,e)},t.increment=function(){return new v(this)},t.hasOne=function(t,e,n){return new x(this,t,e,this.localKey(n))},t.belongsTo=function(t,e,n){return new C(this,t,e,this.relation(t).localKey(n))},t.hasMany=function(t,e,n){return new R(this,t,e,this.localKey(n))},t.hasManyBy=function(t,e,n){return new O(this,t,e,this.relation(t).localKey(n))},t.hasManyThrough=function(t,e,n,r,o,i){return new E(this,t,e,n,r,this.localKey(o),this.relation(e).localKey(i))},t.belongsToMany=function(t,e,n,r,o,i){return new k(this,t,e,n,r,this.localKey(o),this.relation(t).localKey(i))},t.morphTo=function(t,e){return new A(this,t,e)},t.morphOne=function(t,e,n,r){return new j(this,t,e,n,this.localKey(r))},t.morphMany=function(t,e,n,r){return new S(this,t,e,n,this.localKey(r))},t.morphToMany=function(t,e,n,r,o,i,u){return new $(this,t,e,n,r,o,this.localKey(i),this.relation(t).localKey(u))},t.morphedByMany=function(t,e,n,r,o,i,u){return new F(this,t,e,n,r,o,this.localKey(i),this.relation(t).localKey(u))},t.mutators=function(){return{}},t.database=function(){return i.database},t.store=function(){return this.database().store},t.namespace=function(t){return this.database().namespace+"/"+this.entity+"/"+t},t.getters=function(t){return this.store().getters[this.namespace(t)]},t.dispatch=function(t,e){return this.store().dispatch(this.namespace(t),e)},t.commit=function(t){this.store().commit(this.database().namespace+"/$mutate",{entity:this.entity,callback:t})},t.all=function(){return this.getters("all")()},t.find=function(t){return this.getters("find")(t)},t.query=function(){return this.getters("query")()},t.new=function(){return this.dispatch("new")},t.create=function(t){return this.dispatch("create",t)},t.insert=function(t){return this.dispatch("insert",t)},t.update=function(t){return this.dispatch("update",t)},t.insertOrUpdate=function(t){return this.dispatch("insertOrUpdate",t)},t.delete=function(t){return this.dispatch("delete",t)},t.deleteAll=function(){return this.dispatch("deleteAll")},t.id=function(t){var e=this.primaryKey;return"string"==typeof e?t[e]:e.map(function(e){return t[e]}).join("_")},t.localKey=function(t){return t||("string"==typeof this.primaryKey?this.primaryKey:"id")},t.relation=function(t){return"string"!=typeof t?t:this.database().model(t)},t.getAttributeClass=function(t){switch(t){case"increment":return v;default:throw Error('The attribute name "'+t+"\" doesn't exists.")}},t.getFieldsByAttribute=function(t){var e=this.getAttributeClass(t),n=this.fields();return Object.keys(n).reduce(function(t,r){var o=n[r];return o instanceof e&&(t[r]=o),t},{})},t.getIncrementFields=function(){return this.getFieldsByAttribute("increment")},t.hasIncrementFields=function(){return Object.keys(this.getIncrementFields()).length>0},t.pivotFields=function(){var t=[];return h.forOwn(this.fields(),function(e,n){var r;(e instanceof k||e instanceof $||e instanceof F)&&t.push(((r={})[n]=e,r))}),t},t.hasPivotFields=function(){return this.pivotFields().length>0},t.hydrate=function(t){return new this(t).$toJson()},t.prototype.$self=function(){return this.constructor},t.prototype.$fields=function(){return this.$self().getFields()},t.prototype.$store=function(){return this.$self().store()},t.prototype.$namespace=function(t){return this.$self().namespace(t)},t.prototype.$getters=function(t){return this.$self().getters(t)},t.prototype.$dispatch=function(t,e){return c(this,void 0,void 0,function(){return f(this,function(n){return[2,this.$self().dispatch(t,e)]})})},t.prototype.$all=function(){return this.$getters("all")()},t.prototype.$find=function(t){return this.$getters("find")(t)},t.prototype.$query=function(){return this.$getters("query")()},t.prototype.$create=function(t){return c(this,void 0,void 0,function(){return f(this,function(e){return[2,this.$dispatch("create",t)]})})},t.prototype.$insert=function(t){return c(this,void 0,void 0,function(){return f(this,function(e){return[2,this.$dispatch("insert",t)]})})},t.prototype.$update=function(t){return c(this,void 0,void 0,function(){return f(this,function(e){return Array.isArray(t)?[2,this.$dispatch("update",t)]:void 0!==t.where?[2,this.$dispatch("update",t)]:void 0===this.$self().id(t)?[2,this.$dispatch("update",{where:this.$id,data:t})]:[2,this.$dispatch("update",t)]})})},t.prototype.$insertOrUpdate=function(t){return c(this,void 0,void 0,function(){return f(this,function(e){return[2,this.$dispatch("insertOrUpdate",t)]})})},t.prototype.$delete=function(t){return c(this,void 0,void 0,function(){return f(this,function(e){return t?[2,this.$dispatch("delete",t)]:null===this.$id?[2,null]:[2,this.$dispatch("delete",this.$id)]})})},t.prototype.$deleteAll=function(){return c(this,void 0,void 0,function(){return f(this,function(t){return[2,this.$dispatch("deleteAll")]})})},t.prototype.$fill=function(t){var e=this,n=t||{},r=this.$fields();Object.keys(r).forEach(function(t){var o=r[t],i=n[t];e[t]=o.make(i,n,t)}),void 0!==n.$id&&(this.$id=n.$id)},t.prototype.$toJson=function(){var e=this,n=this.$fields();return Object.keys(n).reduce(function(n,r){var o=e[r];return o instanceof t?(n[r]=e.serializeItem(o),n):Array.isArray(o)?(n[r]=e.serializeCollection(o),n):(n[r]=o,n)},{})},t.prototype.$save=function(){return c(this,void 0,void 0,function(){var t,e,n,r=this;return f(this,function(o){switch(o.label){case 0:return t=this.$self().getFields(),e=Object.keys(t).reduce(function(e,n){return t[n]instanceof d&&(e[n]=r[n]),e},{}),[4,this.$dispatch("insertOrUpdate",{data:e})];case 1:return n=o.sent(),this.$fill(n[this.$self().entity][0]),[2,this]}})})},t.prototype.serializeItem=function(t){return t.$toJson()},t.prototype.serializeCollection=function(e){return e.map(function(e){return e instanceof t?e.$toJson():e})},t.primaryKey="id",t.state={},t}();function K(t){return!(!t||"function"!=typeof t.hasOwnProperty||!(t.hasOwnProperty("__ownerID")||t._map&&t._map.hasOwnProperty("__ownerID")))}function B(t,e,n){return Object.keys(t).reduce(function(e,r){var o=""+r;return e.has(o)?e.set(o,n(e.get(o),t[o])):e},e)}var I="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},P=function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")},T=function(){function t(t,e){for(var n=0;n1&&void 0!==arguments[1]?arguments[1]:{},r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{};if(P(this,t),!e||"string"!=typeof e)throw new Error("Expected a string key for Entity, but found "+e+".");var o=r.idAttribute,i=void 0===o?"id":o,u=r.mergeStrategy,a=void 0===u?function(t,e){return U({},t,e)}:u,s=r.processStrategy,c=void 0===s?function(t){return U({},t)}:s;this._key=e,this._getId="function"==typeof i?i:z(i),this._idAttribute=i,this._mergeStrategy=a,this._processStrategy=c,this.define(n)}return t.prototype.define=function(t){this.schema=Object.keys(t).reduce(function(e,n){var r,o=t[n];return U({},e,((r={})[n]=o,r))},this.schema||{})},t.prototype.getId=function(t,e,n){return this._getId(t,e,n)},t.prototype.merge=function(t,e){return this._mergeStrategy(t,e)},t.prototype.normalize=function(t,e,n,r,o){var i=this,u=this._processStrategy(t,e,n);return Object.keys(this.schema).forEach(function(t){if(u.hasOwnProperty(t)&&"object"===I(u[t])){var e=i.schema[t];u[t]=r(u[t],u,t,e,o)}}),o(this,u,t,e,n),this.getId(t,e,n)},t.prototype.denormalize=function(t,e){var n=this;return K(t)?B(this.schema,t,e):(Object.keys(this.schema).forEach(function(r){if(t.hasOwnProperty(r)){var o=n.schema[r];t[r]=e(t[r],o)}}),t)},T(t,[{key:"key",get:function(){return this._key}},{key:"idAttribute",get:function(){return this._idAttribute}}]),t}(),D=function(){function t(e,n){P(this,t),n&&(this._schemaAttribute="string"==typeof n?function(t){return t[n]}:n),this.define(e)}return t.prototype.define=function(t){this.schema=t},t.prototype.getSchemaAttribute=function(t,e,n){return!this.isSingleSchema&&this._schemaAttribute(t,e,n)},t.prototype.inferSchema=function(t,e,n){if(this.isSingleSchema)return this.schema;var r=this.getSchemaAttribute(t,e,n);return this.schema[r]},t.prototype.normalizeValue=function(t,e,n,r,o){var i=this.inferSchema(t,e,n);if(!i)return t;var u=r(t,e,n,i,o);return this.isSingleSchema||void 0===u||null===u?u:{id:u,schema:this.getSchemaAttribute(t,e,n)}},t.prototype.denormalizeValue=function(t,e){var n=K(t)?t.get("schema"):t.schema;if(!this.isSingleSchema&&!n)return t;var r=K(t)?t.get("id"):t.id,o=this.isSingleSchema?this.schema:this.schema[n];return e(r||t,o)},T(t,[{key:"isSingleSchema",get:function(){return!this._schemaAttribute}}]),t}(),H=function(t){function e(n,r){if(P(this,e),!r)throw new Error('Expected option "schemaAttribute" not found on UnionSchema.');return q(this,t.call(this,n,r))}return L(e,t),e.prototype.normalize=function(t,e,n,r,o){return this.normalizeValue(t,e,n,r,o)},e.prototype.denormalize=function(t,e){return this.denormalizeValue(t,e)},e}(D),W=function(t){function e(){return P(this,e),q(this,t.apply(this,arguments))}return L(e,t),e.prototype.normalize=function(t,e,n,r,o){var i=this;return Object.keys(t).reduce(function(e,n,u){var a,s=t[n];return void 0!==s&&null!==s?U({},e,((a={})[n]=i.normalizeValue(s,t,n,r,o),a)):e},{})},e.prototype.denormalize=function(t,e){var n=this;return Object.keys(t).reduce(function(r,o){var i,u=t[o];return U({},r,((i={})[o]=n.denormalizeValue(u,e),i))},{})},e}(D),G=function(t){return Array.isArray(t)?t:Object.keys(t).map(function(e){return t[e]})},V=function(t,e,n,r,o,i){return t=function(t){if(Array.isArray(t)&&t.length>1)throw new Error("Expected schema definition to be a single schema, but found "+t.length+".");return t[0]}(t),G(e).map(function(e,u){return o(e,n,r,t,i)})},J=function(t){function e(){return P(this,e),q(this,t.apply(this,arguments))}return L(e,t),e.prototype.normalize=function(t,e,n,r,o){var i=this;return G(t).map(function(t,u){return i.normalizeValue(t,e,n,r,o)}).filter(function(t){return void 0!==t&&null!==t})},e.prototype.denormalize=function(t,e){var n=this;return t&&t.map?t.map(function(t){return n.denormalizeValue(t,e)}):t},e}(D),Z=function(t,e,n,r,o,i){var u=U({},e);return Object.keys(t).forEach(function(n){var r=t[n],a=o(e[n],e,n,r,i);void 0===a||null===a?delete u[n]:u[n]=a}),u},Q={Array:J,Entity:N,Object:function(){function t(e){P(this,t),this.define(e)}return t.prototype.define=function(t){this.schema=Object.keys(t).reduce(function(e,n){var r,o=t[n];return U({},e,((r={})[n]=o,r))},this.schema||{})},t.prototype.normalize=function(){for(var t=arguments.length,e=Array(t),n=0;n0&&t.withAllRecursive(e-1)})},t.parseWithRelations=function(t,e,n){var r=this,o=e[0];o.split("|").forEach(function(e){r.setEagerLoad(t,e)}),1!==e.length?(e.shift(),this.addNestedWiths(t,e,n)):this.setEagerLoad(t,o,n)},t.addNestedWiths=function(t,e,n){var r=e.join(".");this.setEagerLoad(t,r,function(t){t.with(r,n)})},t.eagerLoadRelations=function(t,e){var n=t.model.getFields();for(var r in t.load){var o=n[r];o instanceof w&&o.load(t,e,r)}},t}(),ft=function(){function t(t){this.indexToBeDeleted=[],this.query=t}return t.on=function(t,e,n){void 0===n&&(n=!1);var r=this.lastHookId+1;return this.lastHookId=r,this.hooks[t]||(this.hooks[t]=[]),this.hooks[t].push({callback:e,once:n,uid:r}),r},t.off=function(t){var e=this,n=!1;return Object.keys(this.hooks).some(function(r){var o=e.hooks[r],i=o.findIndex(function(e){return e.uid===t});return-1!==i&&(o.splice(i,1),n=!0),n}),n},t.prototype.self=function(){return this.constructor},t.prototype.getHook=function(t){return this.query.model[t]||null},t.prototype.getGlobalHook=function(t){return this.self().hooks[t]||null},t.prototype.has=function(t){return!!this.getHook(t)||!!this.getGlobalHook(t)},t.prototype.executeSelectHook=function(t,e){return this.has(t)?(e=this.executeLocalSelectHook(t,e),e=this.executeGlobalSelectHook(t,e)):e},t.prototype.executeLocalSelectHook=function(t,e){var n=this.getHook(t);return n?n(e,this.query.entity):e},t.prototype.executeGlobalSelectHook=function(t,e){var n=this,r=this.getGlobalHook(t);if(!r)return e;var o=[];return r.forEach(function(t,r){var i=t.callback,u=t.once;e=i.call(n.query,e,n.query.entity),u&&o.push(r)}),o.reverse().forEach(function(t){r.splice(t,1)}),e},t.prototype.executeMutationHookOnRecords=function(t,e){var n=this;this.has(t)&&(Object.keys(e).forEach(function(r){!1===n.executeMutationHook(t,e[r])&&delete e[r]}),this.removeGlobalHook(t))},t.prototype.executeMutationHook=function(t,e){return!1!==this.executeLocalMutationHook(t,e)&&(!1!==this.executeGlobalMutationHook(t,e)&&void 0)},t.prototype.executeLocalMutationHook=function(t,e){var n=this.getHook(t);if(n)return n(e,this.query.entity)},t.prototype.executeGlobalMutationHook=function(t,e){var n=this,r=this.getGlobalHook(t);if(r){var o=[];return r.forEach(function(t,r){o.push(t.callback.call(n.query,e,n.query.entity)),t.once&&n.indexToBeDeleted.push(r)}),!o.includes(!1)&&void 0}},t.prototype.removeGlobalHook=function(t){var e=this.getGlobalHook(t);e&&this.indexToBeDeleted.reverse().forEach(function(t){e.splice(t,1)})},t.hooks={},t.lastHookId=0,t}(),lt=function(){function t(t,e){this.wheres=[],this.orders=[],this._offset=0,this._limit=Math.pow(2,53)-1,this.load={},this.result={data:null},this.rootState=t,this.state=t[e],this.entity=e,this.model=this.getModel(e),this.module=this.getModule(e),this.hook=new ft(this)}return t.database=function(){return i.database},t.getModel=function(t){return this.database().model(t)},t.getModels=function(){return this.database().models()},t.getModule=function(t){return this.database().module(t)},t.getModules=function(){return this.database().modules()},t.deleteAll=function(t){var e=this,n=this.getModels();h.forOwn(n,function(n,r){t[r]&&new e(t,r).deleteAll()})},t.on=function(t,e,n){return ft.on(t,e,n)},t.off=function(t){return ft.off(t)},t.prototype.self=function(){return this.constructor},t.prototype.newQuery=function(e){return e=e||this.entity,new t(this.rootState,e)},t.prototype.database=function(){return this.self().database()},t.prototype.getModel=function(t){var e=t||this.entity;return this.self().getModel(e)},t.prototype.getModels=function(){return this.self().getModels()},t.prototype.getModule=function(t){var e=t||this.entity;return this.self().getModule(e)},t.prototype.getModules=function(){return this.self().getModules()},t.prototype.setResult=function(t){return this.result=t,this},t.prototype.all=function(){return this.get()},t.prototype.find=function(t){return this.item(this.state.data[t])},t.prototype.get=function(){var t=this.select();return this.collect(t)},t.prototype.first=function(){var t=this.select();return this.item(t[0])},t.prototype.last=function(){var t=this.select();return this.item(t[t.length-1])},t.prototype.records=function(){var t=this;return Object.keys(this.state.data).map(function(e){var n=t.state.data[e];return n instanceof M?n:t.hydrate(n)})},t.prototype.where=function(t,e){return this.wheres.push({field:t,value:e,boolean:"and"}),this},t.prototype.orWhere=function(t,e){return this.wheres.push({field:t,value:e,boolean:"or"}),this},t.prototype.orderBy=function(t,e){return void 0===e&&(e="asc"),this.orders.push({field:t,direction:e}),this},t.prototype.offset=function(t){return this._offset=t,this},t.prototype.limit=function(t){return this._limit=t,this},t.prototype.with=function(t,e){return void 0===e&&(e=null),ct.with(this,t,e),this},t.prototype.withAll=function(){return ct.withAll(this),this},t.prototype.withAllRecursive=function(t){return void 0===t&&(t=3),ct.withAllRecursive(this,t),this},t.prototype.has=function(t,e,n){return this.addHasConstraint(t,e,n)},t.prototype.hasNot=function(t,e,n){return this.addHasConstraint(t,e,n,!1)},t.prototype.addHasConstraint=function(t,e,n,r){var o=this.matchesHasRelation(t,e,n,r);return this.where("$id",function(t){return o.includes(t)}),this},t.prototype.whereHas=function(t,e){return this.addWhereHasConstraint(t,e)},t.prototype.whereHasNot=function(t,e){return this.addWhereHasConstraint(t,e,!1)},t.prototype.addWhereHasConstraint=function(t,e,n){var r=this.matchesWhereHasRelation(t,e,n);return this.where("$id",function(t){return r.includes(t)}),this},t.prototype.select=function(){var t=this.records();return t=this.hook.executeSelectHook("beforeSelect",t),t=this.filterWhere(t),t=this.hook.executeSelectHook("afterWhere",t),t=this.filterOrderBy(t),t=this.hook.executeSelectHook("afterOrderBy",t),t=this.filterLimit(t),t=this.hook.executeSelectHook("afterLimit",t)},t.prototype.filterWhere=function(t){return st.where(this,t)},t.prototype.filterOrderBy=function(t){return st.orderBy(this,t)},t.prototype.filterLimit=function(t){return st.limit(this,t)},t.prototype.count=function(){return this.get().length},t.prototype.max=function(t){var e=this.get().reduce(function(e,n){return"number"==typeof n[t]&&e.push(n[t]),e},[]);return 0===e.length?0:Math.max.apply(Math,e)},t.prototype.min=function(t){var e=this.get().reduce(function(e,n){return"number"==typeof n[t]&&e.push(n[t]),e},[]);return 0===e.length?0:Math.min.apply(Math,e)},t.prototype.sum=function(t){return this.get().reduce(function(e,n){return"number"==typeof n[t]&&(e+=n[t]),e},0)},t.prototype.item=function(t){return t?(Object.keys(this.load).length>0&&(t=new this.model(t),ct.eagerLoadRelations(this,[t])),t):null},t.prototype.collect=function(t){var e=this;return t.length<1?[]:(Object.keys(this.load).length>0&&(t=t.map(function(t){return new e.model(t)}),ct.eagerLoadRelations(this,t)),t)},t.prototype.matchesHasRelation=function(t,e,n,r){var o;void 0===r&&(r=!0),o=void 0===e?function(t){return t.length>=1}:"number"==typeof e?function(t){return t.length>=e}:"="===e&&"number"==typeof n?function(t){return t.length===n}:">"===e&&"number"==typeof n?function(t){return t.length>n}:">="===e&&"number"==typeof n?function(t){return t.length>=n}:"<"===e&&"number"==typeof n?function(t){return t.length=1};var i=[];return this.newQuery().with(t).get().forEach(function(e){var n=e[t],u=!1;Array.isArray(n)&&n.length<1?u=!1:Array.isArray(n)?u=o(n):n&&(u=o([n])),u===r&&i.push(e.$id)}),i},t.prototype.matchesWhereHasRelation=function(t,e,n){void 0===n&&(n=!0);var r=[];return this.newQuery().with(t,e).get().forEach(function(e){var o=e[t];(Array.isArray(o)?!!o.length:!!o)===n&&r.push(e.$id)}),r},t.prototype.new=function(){var t=(new this.model).$toJson(),e=this.insert(t,{});return this.result.data=e[this.entity][0],this.result.data},t.prototype.create=function(t,e){return this.persist(t,"create",e)},t.prototype.createMany=function(t){var e=this,n=this.hydrateMany(t);return this.commit("create",n,function(){e.state.data=n}),this.map(n)},t.prototype.insert=function(t,e){return this.persist(t,"insert",e)},t.prototype.insertMany=function(t){var e=this,n=this.hydrateMany(t);return this.commit("create",n,function(){e.state.data=s({},e.state.data,n)}),this.map(n)},t.prototype.update=function(t,e,n){if(Array.isArray(t))return this.persist(t,"update",n);if("function"==typeof t){if(!e)throw new Error("You must specify `where` to update records by specifying `data` as a closure.");return"function"==typeof e?this.updateByCondition(t,e):this.updateById(t,e)}if("function"==typeof e)return this.updateByCondition(t,e);if(!e)return this.persist(t,"update",n);if(Array.isArray(this.model.primaryKey))throw new Error("\n You can't specify `where` value as `string` or `number` when you\n have a composite key defined in your model. Please include composite\n keys to the `data` fields.\n ");return t[this.model.primaryKey]=e,this.persist(t,"update",n)},t.prototype.updateMany=function(t){var e=this.combine(t);return this.commitUpdate(e)},t.prototype.updateById=function(t,e){var n;e="number"==typeof e?e.toString():e;var r=this.state.data[e];if(!r)return null;var o=((n={})[e]=this.processUpdate(t,r),n);return this.commitUpdate(o),o[e]},t.prototype.updateByCondition=function(t,e){var n=this,r=Object.keys(this.state.data).reduce(function(r,o){var i=n.state.data[o];return e(i)?(r[o]=n.processUpdate(t,i),r):r},{});return this.commitUpdate(r)},t.prototype.processUpdate=function(t,e){return"function"==typeof t?(t(e),e):this.hydrate(s({},e,t))},t.prototype.commitUpdate=function(t){var e=this;return this.commit("update",t,function(){e.state.data=s({},e.state.data,t)}),this.map(t)},t.prototype.insertOrUpdate=function(t,e){return this.persist(t,"insertOrUpdate",e)},t.prototype.insertOrUpdateMany=function(t){var e=this,n={},r={};return Object.keys(t).forEach(function(o){var i=t[o];e.state.data[o]?r[o]=i:n[o]=i}),this.insertMany(n).concat(this.updateMany(r))},t.prototype.persist=function(t,e,n){var r=this;return t=this.normalize(t),h.isEmpty(t)?("create"===e&&(this.state.data={}),{}):(this.result.data=Object.keys(t).reduce(function(o,i){var u=r.newQuery(i)[r.getPersistMethod(i,e,n)+"Many"](t[i]);return u.length>0&&(o[i]=u),o},{}),this.result.data)},t.prototype.getPersistMethod=function(t,e,n){return n.create&&n.create.includes(t)?"create":n.insert&&n.insert.includes(t)?"insert":n.update&&n.update.includes(t)?"update":n.insertOrUpdate&&n.insertOrUpdate.includes(t)?"insertOrUpdate":e},t.prototype.delete=function(t){return"function"==typeof t?(this.result.data=this.deleteByCondition(t),this.result.data):(this.result.data=this.deleteById(t),this.result.data)},t.prototype.deleteById=function(t){var e;t="number"==typeof t?t.toString():t;var n=this.state.data[t];if(!n)return null;var r=((e={})[t]=n,e);return this.commitDelete(r)[0]},t.prototype.deleteByCondition=function(t){var e=this,n=Object.keys(this.state.data).reduce(function(n,r){var o=e.state.data[r];return t(o)?(n[r]=o,n):n},{});return this.commitDelete(n)},t.prototype.deleteAll=function(){var t=this.state.data;this.commitDelete(t)},t.prototype.commitDelete=function(t){var e=this;return this.commit("delete",t,function(){var n=Object.keys(t);e.state.data=Object.keys(e.state.data).reduce(function(t,r){return n.includes(r)||(t[r]=e.state.data[r]),t},{})}),this.map(t)},t.prototype.normalize=function(t){return ot.normalize(this,t)},t.prototype.hydrate=function(t){return new(0,this.model)(t)},t.prototype.hydrateMany=function(t){var e=this;return Object.keys(t).reduce(function(n,r){var o=t[r];return n[r]=e.hydrate(o),n},{})},t.prototype.combine=function(t){var e=this;return Object.keys(t).reduce(function(n,r){var o=e.state.data[r];if(!o)return n;var i=t[r];return n[r]=e.hydrate(s({},o,i)),n},{})},t.prototype.map=function(t){return Object.keys(t).map(function(e){return t[e]})},t.prototype.commit=function(t,e,n){var r=""+t.charAt(0).toUpperCase()+t.slice(1);this.hook.executeMutationHookOnRecords("before"+r,e),n(),this.hook.executeMutationHookOnRecords("after"+r,e)},t}(),ht={query:function(t,e,n,r){return function(){return r[t.$connection+"/query"](t.$name)}},all:function(t,e,n,r){return function(){return r[t.$connection+"/all"](t.$name)}},find:function(t,e,n,r){return function(e){return r[t.$connection+"/find"](t.$name,e)}}},pt={new:function(t){var e=t.state,n=e.$name;return t.dispatch(e.$connection+"/new",{entity:n},{root:!0})},create:function(t,e){var n=t.state,r=n.$name;return t.dispatch(n.$connection+"/create",s({},e,{entity:r}),{root:!0})},insert:function(t,e){var n=t.state,r=n.$name;return t.dispatch(n.$connection+"/insert",s({},e,{entity:r}),{root:!0})},update:function(t,e){var n=t.state,r=n.$name;return Array.isArray(e)?t.dispatch(n.$connection+"/update",{entity:r,data:e},{root:!0}):void 0===e.data?t.dispatch(n.$connection+"/update",{entity:r,data:e},{root:!0}):t.dispatch(n.$connection+"/update",s({entity:r},e),{root:!0})},insertOrUpdate:function(t,e){var n=t.state,r=n.$name;return t.dispatch(n.$connection+"/insertOrUpdate",s({entity:r},e),{root:!0})},delete:function(t,e){var n=t.state,r=n.$name,o="object"==typeof e?e.where:e;return t.dispatch(n.$connection+"/delete",{entity:r,where:o},{root:!0})},deleteAll:function(t){var e=t.state,n=e.$name;return t.dispatch(e.$connection+"/deleteAll",{entity:n},{root:!0})}},dt={query:function(t){return function(e){return new lt(t,e)}},all:function(t){return function(e){return new lt(t,e).all()}},find:function(t){return function(e,n){return new lt(t,e).find(n)}}},yt={new:function(t,e){var n={data:{}};return t.commit("new",s({},e,{result:n})),n.data},create:function(t,e){return c(this,void 0,void 0,function(){var n;return f(this,function(r){return n={data:{}},t.commit("create",s({},e,{result:n})),[2,n.data]})})},insert:function(t,e){return c(this,void 0,void 0,function(){var n;return f(this,function(r){return n={data:{}},t.commit("insert",s({},e,{result:n})),[2,n.data]})})},update:function(t,e){return c(this,void 0,void 0,function(){var n;return f(this,function(r){return n={data:{}},t.commit("update",s({},e,{result:n})),[2,n.data]})})},insertOrUpdate:function(t,e){return c(this,void 0,void 0,function(){var n;return f(this,function(r){return n={data:{}},t.commit("insertOrUpdate",s({},e,{result:n})),[2,n.data]})})},delete:function(t,e){return c(this,void 0,void 0,function(){var n;return f(this,function(r){return n={data:{}},t.commit("delete",s({},e,{result:n})),[2,n.data]})})},deleteAll:function(t,e){return c(this,void 0,void 0,function(){return f(this,function(n){return e&&e.entity?(t.commit("deleteAll",{entity:e.entity}),[2]):(t.commit("deleteAll"),[2])})})}},vt=function(){function t(){}return t.createPersistOptions=function(t){return{create:t.create,insert:t.insert,update:t.update,insertOrUpdate:t.insertOrUpdate}},t}(),gt={$mutate:function(t,e){e.callback(t[e.entity])},new:function(t,e){var n=e.entity,r=e.result;new lt(t,n).setResult(r).new()},create:function(t,e){var n=e.entity,r=e.data,o=e.result,i=vt.createPersistOptions(e);new lt(t,n).setResult(o).create(r,i)},insert:function(t,e){var n=e.entity,r=e.data,o=e.result,i=vt.createPersistOptions(e);new lt(t,n).setResult(o).insert(r,i)},update:function(t,e){var n=e.entity,r=e.data,o=e.where||null,i=e.result,u=vt.createPersistOptions(e);new lt(t,n).setResult(i).update(r,o,u)},insertOrUpdate:function(t,e){var n=e.entity,r=e.data,o=e.result,i=vt.createPersistOptions(e);new lt(t,n).setResult(o).insertOrUpdate(r,i)},delete:function(t,e){var n=e.entity,r=e.where,o=e.result;new lt(t,n).setResult(o).delete(r)},deleteAll:function(t,e){e&&e.entity?new lt(t,e.entity).deleteAll():lt.deleteAll(t)}};var mt=function(){function t(){}return t.set=function(){this.value=""+this.prefix+this.count},t.get=function(){return this.value},t.increment=function(){return this.count++,this.set(),this.get()},t.count=0,t.prefix="_no_key_",t.value="",t}(),_t=function(){function t(){}return t.create=function(t){return function(e,n,r){var o=t.id(e);return void 0===o||null===o||""===o?mt.get():o}},t}(),bt=function(){function t(){}return t.create=function(t){var e=this;return function(n,r,o){var i=e.getId(t,n);return s({},n,{$id:i})}},t.getId=function(t,e){var n=t.id(e);return void 0===n||null===n||""===n?mt.increment():n},t}(),wt=function(){function t(t){var e=this;this.schemas={},this.model=t;var n=t.database().models();Object.keys(n).forEach(function(t){e.one(n[t])})}return t.create=function(t){return new this(t).one()},t.prototype.one=function(t){if(t=t||this.model,this.schemas[t.entity])return this.schemas[t.entity];var e=new Q.Entity(t.entity,{},{idAttribute:_t.create(t),processStrategy:bt.create(t)});this.schemas[t.entity]=e;var n=this.definition(t);return e.define(n),e},t.prototype.many=function(t){return new Q.Array(this.one(t))},t.prototype.union=function(t){return new Q.Union(this.schemas,t)},t.prototype.definition=function(t){var e=this,n=t.fields();return Object.keys(n).reduce(function(t,r){var o=n[r];return o instanceof w&&(t[r]=o.define(e)),t},{})},t}(),xt=function(){function t(){}return t.create=function(t,e,n){var r={namespaced:!0,state:{$name:t},getters:dt,actions:yt,mutations:gt,modules:{}};return this.createModules(r,t,e,n)},t.createModules=function(t,e,n,r){var o=this;return Object.keys(r).forEach(function(i){var u=n[i],a=r[i];t.modules[i]={namespaced:!0},t.modules[i].state=o.createState(e,i,u,a),t.getters[i]=function(t,e,n,r){return function(){return e.query(i)}},t.modules[i].getters=s({},ht,a.getters),t.modules[i].actions=s({},pt,a.actions),t.modules[i].mutations=a.mutations||{}}),t},t.createState=function(t,e,n,r){var o="function"==typeof n.state?n.state():n.state,i="function"==typeof r.state?r.state():r.state;return s({},o,i,{$connection:t,$name:e,data:{}})},t}(),Ct=function(){function t(){this.entities=[],this.schemas={}}return t.prototype.start=function(t,e){this.store=t,this.namespace=e,this.registerModules(),this.createSchema()},t.prototype.register=function(t,e){void 0===e&&(e={}),this.entities.push({name:t.entity,model:t,module:e})},t.prototype.model=function(t){return this.models()[t]},t.prototype.models=function(){return this.entities.reduce(function(t,e){return t[e.name]=e.model,t},{})},t.prototype.module=function(t){return this.modules()[t]},t.prototype.modules=function(){return this.entities.reduce(function(t,e){return t[e.name]=e.module,t},{})},t.prototype.registerModules=function(){var t=xt.create(this.namespace,this.models(),this.modules());this.store.registerModule(this.namespace,t)},t.prototype.createSchema=function(){var t=this;this.entities.forEach(function(e){t.schemas[e.name]=wt.create(e.model)})},t}();const Rt={baseURL:"http://localhost:3000",url:"/",method:"get",access_token:"",headers:{"Content-Type":"application/json",Accept:"application/json"},data:{},timeout:0,withCredentials:!1,responseType:"json",responseEncoding:"utf8",validateStatus:t=>t>=200&&t<300,maxRedirects:5,socketPath:null,proxy:{},onResponse:t=>t.data,onUnauthorised(t){},onNotFound(t){},onServerError(t){},onGenericError(t){},onValidationError(t){},onError(t){const{response:e}=t,n={401:this.onUnauthorised,404:this.onNotFound,422:this.onValidationError,500:this.onServerError};return e&&e.status in n?n[e.status](t):this.onGenericError(t),Promise.reject(t)}},Ot={database:new Ct,http:Rt},Et={getters:{loading:t=>t.loading,errors:t=>t.errors},mutations:{onRequest(t){t.loading=!0,t.errors=[]},onError(t,e){t.loading=!1,t.errors=e.data},onSuccess(t){t.loading=!1,t.errors=[]}},state:{loading:!1,errors:[]}},kt={http:Rt,methods:{$fetch:{name:"fetch",http:{url:"",method:"get"}},$get:{name:"get",http:{url:"/:id",method:"get"}},$create:{name:"create",alias:["insert"],http:{url:"",method:"post"}},$update:{name:"update",http:{url:"/:id",method:"put"}},$delete:{name:"delete",http:{url:"/:id",method:"delete"}}}};class At{constructor(t,e){if(this.components=t,this.options=o.a.merge({},Ot,e),this.database=e.database,!e.database)throw new Error("database option is required to initialise!")}static setup(t,e){return this.instance=new At(t,e),this.instance}static getInstance(){return this.instance}getModelFromState(t){return o.a.find(this.database.entities,{name:t.$name}).model}}class jt{static transformModule(t){return o.a.merge({},Et,t)}static transformModel(t){const e=At.getInstance();return kt.http=o.a.merge({},kt.http,e.options.http),t.methodConf=o.a.merge({},kt,t.methodConf),t.methodConf.http.url="/"===t.methodConf.http.url?`/${t.entity}`:t.methodConf.http.url,t.getFields=(()=>(t.cachedFields||(t.cachedFields=o.a.merge({},{$id:t.attr(void 0),$isUpdating:t.boolean(!1),$updateErrors:t.attr([]),$isDeleting:t.boolean(!1),$deleteErrors:t.attr([])},t.fields())),t.cachedFields)),t}static transformParams(t,e,n={}){let r=`${e.methodConf.http.url}${e.methodConf.methods[t].http.url}`,i=o.a.map(r.match(/(\/?)(\:)([A-z]*)/gm),t=>t.replace("/",""));return o.a.forEach(i,t=>{const e=o.a.has(n.params,t.replace(":",""))?n.params[t.replace(":","")]:"";r=r.replace(t,e).replace("//","/")}),n.query&&(r+=`?${Object.keys(n.query).map(t=>`${encodeURIComponent(t)}=${encodeURIComponent(n.query[t])}`).join("&")}`),r}}var St=n(15),$t=n.n(St);class Ft{constructor(t){return this.instance=$t.a.create(t),this.setAuthentication(t.access_token),this.instance.interceptors.response.use(e=>t.onResponse(e),e=>t.onError(e)),this.instance}setAuthentication(t){if(!t)return;const e="function"==typeof t?t():t;this.instance.defaults.headers.common.Authorization=`Bearer ${e}`}async head(t,e={}){return this.instance.head(t,e)}async get(t,e={}){return this.instance.get(t,e)}async post(t,e={},n={}){return this.instance.post(t,e,n)}async patch(t,e={},n={}){return this.instance.patch(t,e,n)}async put(t,e={},n={}){return this.instance.put(t,e,n)}async delete(t,e={}){return this.instance.delete(t,e)}}class Mt extends jt{static async call({state:t,commit:e},n={}){const r=At.getInstance().getModelFromState(t),o=jt.transformParams("$fetch",r,n),i=new Ft(r.methodConf.http).get(o);return this.onRequest(e),i.then(t=>this.onSuccess(e,r,t)).catch(t=>this.onError(e,t)),i}static onRequest(t){t("onRequest")}static onSuccess(t,e,n){t("onSuccess"),e.insertOrUpdate({data:n})}static onError(t,e){t("onError",e)}}class Kt extends jt{static async call({state:t,commit:e},n={}){const r=At.getInstance().getModelFromState(t),o=jt.transformParams("$get",r,n),i=new Ft(r.methodConf.http).get(o);return this.onRequest(e),i.then(t=>this.onSuccess(e,r,t)).catch(t=>this.onError(e,t)),i}static onRequest(t){t("onRequest")}static onSuccess(t,e,n){t("onSuccess"),e.insertOrUpdate({data:n})}static onError(t,e){t("onError",e)}}class Bt extends jt{static async call({state:t,commit:e},n={}){if(!n.data||"object"!=typeof n)throw new TypeError("You must include a data object in the params to send a POST request",n);const r=At.getInstance().getModelFromState(t),o=jt.transformParams("$create",r,n),i=new Ft(r.methodConf.http).post(o,n.data);return this.onRequest(e),i.then(t=>this.onSuccess(e,r,t)).catch(t=>this.onError(e,t)),i}static onRequest(t){t("onRequest")}static onSuccess(t,e,n){t("onSuccess"),e.insertOrUpdate({data:n})}static onError(t,e){t("onError",e)}}class It extends jt{static async call({state:t,commit:e},n={}){if(!n.data||"object"!=typeof n)throw new TypeError("You must include a data object in the params to send a POST request",n);const r=At.getInstance().getModelFromState(t),o=jt.transformParams("$update",r,n),i=new Ft(r.methodConf.http).put(o,n.data);return this.onRequest(r,n),i.then(t=>this.onSuccess(r,n,t)).catch(t=>this.onError(r,n,t)),i}static onRequest(t,e){t.update({where:e.params.id,data:{$isUpdating:!0,$updateErrors:[]}})}static onSuccess(t,e,n){t.update({where:e.params.id||n.id,data:o.a.merge({},n,{$isUpdating:!1,$updateErrors:[]})})}static onError(t,e,n){t.update({where:e.params.id,data:{$isUpdating:!1,$updateErrors:n}})}}class Pt extends jt{static async call({state:t,commit:e},n={}){const r=At.getInstance().getModelFromState(t),o=jt.transformParams("$delete",r,n),i=new Ft(r.methodConf.http).delete(o);return this.onRequest(r,n),i.then(t=>this.onSuccess(r,n,t)).catch(t=>this.onError(r,n,t)),i}static onRequest(t,e){t.update({where:e.params.id,data:{$isDeleting:!0,$deleteErrors:[]}})}static onSuccess(t,e,n){t.delete({where:e.params.id||n.id})}static onError(t,e,n){t.update({where:e.params.id,data:{$isDeleting:!1,$deleteErrors:n}})}}class Tt{constructor(t,e){At.setup(t,e),this.setupActions(),this.setupModels()}setupActions(){const t=At.getInstance();t.components.Actions.$fetch=Mt.call.bind(Mt),t.components.Actions.$get=Kt.call.bind(Kt),t.components.Actions.$create=Bt.call.bind(Bt),t.components.Actions.$update=It.call.bind(It),t.components.Actions.$delete=Pt.call.bind(Pt)}setupModels(){const t=At.getInstance();_.map(t.database.entities,t=>(t.module=jt.transformModule(t.module),t.model=jt.transformModel(t.model),t)),t.components.Model.$fetch=function(t={}){return this.dispatch("$fetch",t)},t.components.Model.$get=function(t={}){return this.dispatch("$get",t)},t.components.Model.$create=function(t={}){return this.dispatch("$create",t)},t.components.Model.$update=function(t={}){return this.dispatch("$update",t)},t.components.Model.$delete=function(t={}){return this.dispatch("$delete",t)}}}n.d(e,"default",function(){return Ut});class Ut{static install(t,e){return new Tt(t,e)}}}])}); \ No newline at end of file +t.exports=function(t){return null!=t&&(n(t)||function(t){return"function"==typeof t.readFloatLE&&"function"==typeof t.slice&&n(t.slice(0,0))}(t)||!!t._isBuffer)}},function(t,e,n){"use strict";var r=n(2),o=n(0),i=n(40),u=n(41);function a(t){this.defaults=t,this.interceptors={request:new i,response:new i}}a.prototype.request=function(t){"string"==typeof t&&(t=o.merge({url:arguments[0]},arguments[1])),(t=o.merge(r,{method:"get"},this.defaults,t)).method=t.method.toLowerCase();var e=[u,void 0],n=Promise.resolve(t);for(this.interceptors.request.forEach(function(t){e.unshift(t.fulfilled,t.rejected)}),this.interceptors.response.forEach(function(t){e.push(t.fulfilled,t.rejected)});e.length;)n=n.then(e.shift(),e.shift());return n},o.forEach(["delete","get","head","options"],function(t){a.prototype[t]=function(e,n){return this.request(o.merge(n||{},{method:t,url:e}))}}),o.forEach(["post","put","patch"],function(t){a.prototype[t]=function(e,n,r){return this.request(o.merge(r||{},{method:t,url:e,data:n}))}}),t.exports=a},function(t,e,n){"use strict";var r=n(0);t.exports=function(t,e){r.forEach(t,function(n,r){r!==e&&r.toUpperCase()===e.toUpperCase()&&(t[e]=n,delete t[r])})}},function(t,e,n){"use strict";var r=n(0),o=n(5),i=n(7),u=n(22),a=n(23),s=n(3),c="undefined"!=typeof window&&window.btoa&&window.btoa.bind(window)||n(24);t.exports=function(t){return new Promise(function(e,f){var l=t.data,h=t.headers;r.isFormData(l)&&delete h["Content-Type"];var p=new XMLHttpRequest,d="onreadystatechange",y=!1;if("undefined"==typeof window||!window.XDomainRequest||"withCredentials"in p||a(t.url)||(p=new window.XDomainRequest,d="onload",y=!0,p.onprogress=function(){},p.ontimeout=function(){}),t.auth){var v=t.auth.username||"",g=t.auth.password||"";h.Authorization="Basic "+c(v+":"+g)}if(p.open(t.method.toUpperCase(),i(t.url,t.params,t.paramsSerializer),!0),p.timeout=t.timeout,p[d]=function(){if(p&&(4===p.readyState||y)&&(0!==p.status||p.responseURL&&0===p.responseURL.indexOf("file:"))){var n="getAllResponseHeaders"in p?u(p.getAllResponseHeaders()):null,r={data:t.responseType&&"text"!==t.responseType?p.response:p.responseText,status:1223===p.status?204:p.status,statusText:1223===p.status?"No Content":p.statusText,headers:n,config:t,request:p};o(e,f,r),p=null}},p.onerror=function(){f(s("Network Error",t,null,p)),p=null},p.ontimeout=function(){f(s("timeout of "+t.timeout+"ms exceeded",t,"ECONNABORTED",p)),p=null},r.isStandardBrowserEnv()){var m=n(25),_=(t.withCredentials||a(t.url))&&t.xsrfCookieName?m.read(t.xsrfCookieName):void 0;_&&(h[t.xsrfHeaderName]=_)}if("setRequestHeader"in p&&r.forEach(h,function(t,e){void 0===l&&"content-type"===e.toLowerCase()?delete h[e]:p.setRequestHeader(e,t)}),t.withCredentials&&(p.withCredentials=!0),t.responseType)try{p.responseType=t.responseType}catch(e){if("json"!==t.responseType)throw e}"function"==typeof t.onDownloadProgress&&p.addEventListener("progress",t.onDownloadProgress),"function"==typeof t.onUploadProgress&&p.upload&&p.upload.addEventListener("progress",t.onUploadProgress),t.cancelToken&&t.cancelToken.promise.then(function(t){p&&(p.abort(),f(t),p=null)}),void 0===l&&(l=null),p.send(l)})}},function(t,e,n){"use strict";var r=n(0),o=["age","authorization","content-length","content-type","etag","expires","from","host","if-modified-since","if-unmodified-since","last-modified","location","max-forwards","proxy-authorization","referer","retry-after","user-agent"];t.exports=function(t){var e,n,i,u={};return t?(r.forEach(t.split("\n"),function(t){if(i=t.indexOf(":"),e=r.trim(t.substr(0,i)).toLowerCase(),n=r.trim(t.substr(i+1)),e){if(u[e]&&o.indexOf(e)>=0)return;u[e]="set-cookie"===e?(u[e]?u[e]:[]).concat([n]):u[e]?u[e]+", "+n:n}}),u):u}},function(t,e,n){"use strict";var r=n(0);t.exports=r.isStandardBrowserEnv()?function(){var t,e=/(msie|trident)/i.test(navigator.userAgent),n=document.createElement("a");function o(t){var r=t;return e&&(n.setAttribute("href",r),r=n.href),n.setAttribute("href",r),{href:n.href,protocol:n.protocol?n.protocol.replace(/:$/,""):"",host:n.host,search:n.search?n.search.replace(/^\?/,""):"",hash:n.hash?n.hash.replace(/^#/,""):"",hostname:n.hostname,port:n.port,pathname:"/"===n.pathname.charAt(0)?n.pathname:"/"+n.pathname}}return t=o(window.location.href),function(e){var n=r.isString(e)?o(e):e;return n.protocol===t.protocol&&n.host===t.host}}():function(){return!0}},function(t,e,n){"use strict";var r="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";function o(){this.message="String contains an invalid character"}o.prototype=new Error,o.prototype.code=5,o.prototype.name="InvalidCharacterError",t.exports=function(t){for(var e,n,i=String(t),u="",a=0,s=r;i.charAt(0|a)||(s="=",a%1);u+=s.charAt(63&e>>8-a%1*8)){if((n=i.charCodeAt(a+=.75))>255)throw new o;e=e<<8|n}return u}},function(t,e,n){"use strict";var r=n(0);t.exports=r.isStandardBrowserEnv()?{write:function(t,e,n,o,i,u){var a=[];a.push(t+"="+encodeURIComponent(e)),r.isNumber(n)&&a.push("expires="+new Date(n).toGMTString()),r.isString(o)&&a.push("path="+o),r.isString(i)&&a.push("domain="+i),!0===u&&a.push("secure"),document.cookie=a.join("; ")},read:function(t){var e=document.cookie.match(new RegExp("(^|;\\s*)("+t+")=([^;]*)"));return e?decodeURIComponent(e[3]):null},remove:function(t){this.write(t,"",Date.now()-864e5)}}:{write:function(){},read:function(){return null},remove:function(){}}},function(t,e,n){"use strict";var r=n(0),o=n(5),i=n(7),u=n(8),a=n(9),s=n(10).http,c=n(10).https,f=n(11),l=n(38),h=n(39),p=n(3),d=n(6);t.exports=function(t){return new Promise(function(e,n){var y,v=t.data,g=t.headers;if(g["User-Agent"]||g["user-agent"]||(g["User-Agent"]="axios/"+h.version),v&&!r.isStream(v)){if(Buffer.isBuffer(v));else if(r.isArrayBuffer(v))v=new Buffer(new Uint8Array(v));else{if(!r.isString(v))return n(p("Data after transformation must be a string, an ArrayBuffer, a Buffer, or a Stream",t));v=new Buffer(v,"utf-8")}g["Content-Length"]=v.length}var m=void 0;t.auth&&(m=(t.auth.username||"")+":"+(t.auth.password||""));var _=f.parse(t.url),b=_.protocol||"http:";if(!m&&_.auth){var w=_.auth.split(":");m=(w[0]||"")+":"+(w[1]||"")}m&&delete g.Authorization;var x="https:"===b,C=x?t.httpsAgent:t.httpAgent,R={path:i(_.path,t.params,t.paramsSerializer).replace(/^\?/,""),method:t.method,headers:g,agent:C,auth:m};t.socketPath?R.socketPath=t.socketPath:(R.hostname=_.hostname,R.port=_.port);var O,E=t.proxy;if(!E&&!1!==E){var k=b.slice(0,-1)+"_proxy",A=process.env[k]||process.env[k.toUpperCase()];if(A){var j=f.parse(A);if(E={host:j.hostname,port:j.port},j.auth){var S=j.auth.split(":");E.auth={username:S[0],password:S[1]}}}}if(E&&(R.hostname=E.host,R.host=E.host,R.headers.host=_.hostname+(_.port?":"+_.port:""),R.port=E.port,R.path=b+"//"+_.hostname+(_.port?":"+_.port:"")+R.path,E.auth)){var $=new Buffer(E.auth.username+":"+E.auth.password,"utf8").toString("base64");R.headers["Proxy-Authorization"]="Basic "+$}t.transport?O=t.transport:0===t.maxRedirects?O=x?a:u:(t.maxRedirects&&(R.maxRedirects=t.maxRedirects),O=x?c:s),t.maxContentLength&&t.maxContentLength>-1&&(R.maxBodyLength=t.maxContentLength);var F=O.request(R,function(r){if(!F.aborted){clearTimeout(y),y=null;var i=r;switch(r.headers["content-encoding"]){case"gzip":case"compress":case"deflate":i=i.pipe(l.createUnzip()),delete r.headers["content-encoding"]}var u=r.req||F,a={status:r.statusCode,statusText:r.statusMessage,headers:r.headers,config:t,request:u};if("stream"===t.responseType)a.data=i,o(e,n,a);else{var s=[];i.on("data",function(e){s.push(e),t.maxContentLength>-1&&Buffer.concat(s).length>t.maxContentLength&&n(p("maxContentLength size of "+t.maxContentLength+" exceeded",t,null,u))}),i.on("error",function(e){F.aborted||n(d(e,t,null,u))}),i.on("end",function(){var r=Buffer.concat(s);"arraybuffer"!==t.responseType&&(r=r.toString("utf8")),a.data=r,o(e,n,a)})}}});F.on("error",function(e){F.aborted||n(d(e,t,null,F))}),t.timeout&&!y&&(y=setTimeout(function(){F.abort(),n(p("timeout of "+t.timeout+"ms exceeded",t,"ECONNABORTED",F))},t.timeout)),t.cancelToken&&t.cancelToken.promise.then(function(t){F.aborted||(F.abort(),n(t))}),r.isStream(v)?v.pipe(F):F.end(v)})}},function(t,e){t.exports=require("assert")},function(t,e){t.exports=require("stream")},function(t,e,n){"undefined"==typeof process||"renderer"===process.type?t.exports=n(30):t.exports=n(32)},function(t,e,n){function r(){var t;try{t=e.storage.debug}catch(t){}return!t&&"undefined"!=typeof process&&"env"in process&&(t=process.env.DEBUG),t}(e=t.exports=n(12)).log=function(){return"object"==typeof console&&console.log&&Function.prototype.apply.call(console.log,console,arguments)},e.formatArgs=function(t){var n=this.useColors;if(t[0]=(n?"%c":"")+this.namespace+(n?" %c":" ")+t[0]+(n?"%c ":" ")+"+"+e.humanize(this.diff),!n)return;var r="color: "+this.color;t.splice(1,0,r,"color: inherit");var o=0,i=0;t[0].replace(/%[a-zA-Z%]/g,function(t){"%%"!==t&&"%c"===t&&(i=++o)}),t.splice(i,0,r)},e.save=function(t){try{null==t?e.storage.removeItem("debug"):e.storage.debug=t}catch(t){}},e.load=r,e.useColors=function(){if("undefined"!=typeof window&&window.process&&"renderer"===window.process.type)return!0;if("undefined"!=typeof navigator&&navigator.userAgent&&navigator.userAgent.toLowerCase().match(/(edge|trident)\/(\d+)/))return!1;return"undefined"!=typeof document&&document.documentElement&&document.documentElement.style&&document.documentElement.style.WebkitAppearance||"undefined"!=typeof window&&window.console&&(window.console.firebug||window.console.exception&&window.console.table)||"undefined"!=typeof navigator&&navigator.userAgent&&navigator.userAgent.toLowerCase().match(/firefox\/(\d+)/)&&parseInt(RegExp.$1,10)>=31||"undefined"!=typeof navigator&&navigator.userAgent&&navigator.userAgent.toLowerCase().match(/applewebkit\/(\d+)/)},e.storage="undefined"!=typeof chrome&&void 0!==chrome.storage?chrome.storage.local:function(){try{return window.localStorage}catch(t){}}(),e.colors=["#0000CC","#0000FF","#0033CC","#0033FF","#0066CC","#0066FF","#0099CC","#0099FF","#00CC00","#00CC33","#00CC66","#00CC99","#00CCCC","#00CCFF","#3300CC","#3300FF","#3333CC","#3333FF","#3366CC","#3366FF","#3399CC","#3399FF","#33CC00","#33CC33","#33CC66","#33CC99","#33CCCC","#33CCFF","#6600CC","#6600FF","#6633CC","#6633FF","#66CC00","#66CC33","#9900CC","#9900FF","#9933CC","#9933FF","#99CC00","#99CC33","#CC0000","#CC0033","#CC0066","#CC0099","#CC00CC","#CC00FF","#CC3300","#CC3333","#CC3366","#CC3399","#CC33CC","#CC33FF","#CC6600","#CC6633","#CC9900","#CC9933","#CCCC00","#CCCC33","#FF0000","#FF0033","#FF0066","#FF0099","#FF00CC","#FF00FF","#FF3300","#FF3333","#FF3366","#FF3399","#FF33CC","#FF33FF","#FF6600","#FF6633","#FF9900","#FF9933","#FFCC00","#FFCC33"],e.formatters.j=function(t){try{return JSON.stringify(t)}catch(t){return"[UnexpectedJSONParseError]: "+t.message}},e.enable(r())},function(t,e){var n=1e3,r=60*n,o=60*r,i=24*o,u=365.25*i;function a(t,e,n){if(!(t0)return function(t){if((t=String(t)).length>100)return;var e=/^((?:\d+)?\.?\d+) *(milliseconds?|msecs?|ms|seconds?|secs?|s|minutes?|mins?|m|hours?|hrs?|h|days?|d|years?|yrs?|y)?$/i.exec(t);if(!e)return;var a=parseFloat(e[1]);switch((e[2]||"ms").toLowerCase()){case"years":case"year":case"yrs":case"yr":case"y":return a*u;case"days":case"day":case"d":return a*i;case"hours":case"hour":case"hrs":case"hr":case"h":return a*o;case"minutes":case"minute":case"mins":case"min":case"m":return a*r;case"seconds":case"second":case"secs":case"sec":case"s":return a*n;case"milliseconds":case"millisecond":case"msecs":case"msec":case"ms":return a;default:return}}(t);if("number"===s&&!1===isNaN(t))return e.long?function(t){return a(t,i,"day")||a(t,o,"hour")||a(t,r,"minute")||a(t,n,"second")||t+" ms"}(t):function(t){if(t>=i)return Math.round(t/i)+"d";if(t>=o)return Math.round(t/o)+"h";if(t>=r)return Math.round(t/r)+"m";if(t>=n)return Math.round(t/n)+"s";return t+"ms"}(t);throw new Error("val is not a non-empty string or a valid number. val="+JSON.stringify(t))}},function(t,e,n){var r=n(33),o=n(34);(e=t.exports=n(12)).init=function(t){t.inspectOpts={};for(var n=Object.keys(e.inspectOpts),r=0;r=2&&(e.colors=[20,21,26,27,32,33,38,39,40,41,42,43,44,45,56,57,62,63,68,69,74,75,76,77,78,79,80,81,92,93,98,99,112,113,128,129,134,135,148,149,160,161,162,163,164,165,166,167,168,169,170,171,172,173,178,179,184,185,196,197,198,199,200,201,202,203,204,205,206,207,208,209,214,215,220,221])}catch(t){}function u(){return process.env.DEBUG}e.inspectOpts=Object.keys(process.env).filter(function(t){return/^debug_/i.test(t)}).reduce(function(t,e){var n=e.substring(6).toLowerCase().replace(/_([a-z])/g,function(t,e){return e.toUpperCase()}),r=process.env[e];return r=!!/^(yes|on|true|enabled)$/i.test(r)||!/^(no|off|false|disabled)$/i.test(r)&&("null"===r?null:Number(r)),t[n]=r,t},{}),e.formatters.o=function(t){return this.inspectOpts.colors=this.useColors,o.inspect(t,this.inspectOpts).split("\n").map(function(t){return t.trim()}).join(" ")},e.formatters.O=function(t){return this.inspectOpts.colors=this.useColors,o.inspect(t,this.inspectOpts)},e.enable(u())},function(t,e){t.exports=require("tty")},function(t,e){t.exports=require("util")},function(t,e,n){"use strict";const r=n(36),o=n(37),i=process.env;let u;function a(t){return function(t){return 0!==t&&{level:t,hasBasic:!0,has256:t>=2,has16m:t>=3}}(function(t){if(!1===u)return 0;if(o("color=16m")||o("color=full")||o("color=truecolor"))return 3;if(o("color=256"))return 2;if(t&&!t.isTTY&&!0!==u)return 0;const e=u?1:0;if("win32"===process.platform){const t=r.release().split(".");return Number(process.versions.node.split(".")[0])>=8&&Number(t[0])>=10&&Number(t[2])>=10586?Number(t[2])>=14931?3:2:1}if("CI"in i)return["TRAVIS","CIRCLECI","APPVEYOR","GITLAB_CI"].some(t=>t in i)||"codeship"===i.CI_NAME?1:e;if("TEAMCITY_VERSION"in i)return/^(9\.(0*[1-9]\d*)\.|\d{2,}\.)/.test(i.TEAMCITY_VERSION)?1:0;if("truecolor"===i.COLORTERM)return 3;if("TERM_PROGRAM"in i){const t=parseInt((i.TERM_PROGRAM_VERSION||"").split(".")[0],10);switch(i.TERM_PROGRAM){case"iTerm.app":return t>=3?3:2;case"Apple_Terminal":return 2}}return/-256(color)?$/i.test(i.TERM)?2:/^screen|^xterm|^vt100|^vt220|^rxvt|color|ansi|cygwin|linux/i.test(i.TERM)?1:"COLORTERM"in i?1:(i.TERM,e)}(t))}o("no-color")||o("no-colors")||o("color=false")?u=!1:(o("color")||o("colors")||o("color=true")||o("color=always"))&&(u=!0),"FORCE_COLOR"in i&&(u=0===i.FORCE_COLOR.length||0!==parseInt(i.FORCE_COLOR,10)),t.exports={supportsColor:a,stdout:a(process.stdout),stderr:a(process.stderr)}},function(t,e){t.exports=require("os")},function(t,e,n){"use strict";t.exports=((t,e)=>{e=e||process.argv;const n=t.startsWith("-")?"":1===t.length?"-":"--",r=e.indexOf(n+t),o=e.indexOf("--");return-1!==r&&(-1===o||r=0?i=a:(i=o+a)<0&&(i=0);i0&&o[o.length-1])&&(6===i[0]||2===i[0])){u=0;continue}if(3===i[0]&&(!o||i[1]>o[0]&&i[1]e)return 1;if(t=u)return s;var c=n[a];return s*("desc"===c?-1:1)}}return t.index-e.index}(t,e,n)})},pickBy:function(t,e){return Object.keys(t).reduce(function(n,r){var o=t[r];return e(o,r)&&(n[r]=o),n},{})}},p=function(){return function(t){this.model=t}}(),d=function(t){function e(e,n){var r=t.call(this,e)||this;return r.mutator=n,r}return a(e,t),e.prototype.mutate=function(t,e){var n=this.mutator||this.model.mutators()[e];return n?n(t):t},e}(p),y=function(t){function e(e,n,r){var o=t.call(this,e,r)||this;return o.value=n,o}return a(e,t),e.prototype.make=function(t,e,n){return t=void 0!==t?t:this.value,this.mutate(t,n)},e}(d),v=function(t){function e(e){var n=t.call(this,e)||this;return n.value=1,n}return a(e,t),e.prototype.make=function(t,e,n){return"number"==typeof t?t:null},e}(d),g=function(t){function e(e,n,r){var o=t.call(this,e,r)||this;return o.isNullable=!1,o.value=n,o}return a(e,t),e.prototype.nullable=function(){return this.isNullable=!0,this},e.prototype.make=function(t,e,n){return this.mutate(this.fix(t),n)},e.prototype.fix=function(t){return void 0===t?this.value:"string"==typeof t?t:null===t&&this.isNullable?t:t+""},e}(d),m=function(t){function e(e,n,r){var o=t.call(this,e,r)||this;return o.isNullable=!1,o.value=n,o}return a(e,t),e.prototype.nullable=function(){return this.isNullable=!0,this},e.prototype.make=function(t,e,n){return this.mutate(this.fix(t),n)},e.prototype.fix=function(t){return void 0===t?this.value:"number"==typeof t?t:"string"==typeof t?parseFloat(t):"boolean"==typeof t?t?1:0:null===t&&this.isNullable?t:0},e}(d),b=function(t){function e(e,n,r){var o=t.call(this,e,r)||this;return o.isNullable=!1,o.value=n,o}return a(e,t),e.prototype.nullable=function(){return this.isNullable=!0,this},e.prototype.make=function(t,e,n){return this.mutate(this.fix(t),n)},e.prototype.fix=function(t){if(void 0===t)return this.value;if("boolean"==typeof t)return t;if("string"==typeof t){if(0===t.length)return!1;var e=parseInt(t,0);return!!isNaN(e)||!!e}return"number"==typeof t?!!t:!(null!==t||!this.isNullable)&&t},e}(d),w=function(t){function e(){return null!==t&&t.apply(this,arguments)||this}return a(e,t),e.prototype.getRelation=function(t,e){var n=t.newQuery(e);return this.addEagerConstraint(t,n),n},e.prototype.getKeys=function(t,e){return t.map(function(t){return t[e]})},e.prototype.addEagerConstraint=function(t,e){for(var n in t.load)t.load[n].forEach(function(t){t(e)})},e.prototype.mapSingleRelations=function(t,e){return t.reduce(function(t,n){return t[n[e]]=n,t},{})},e.prototype.mapManyRelations=function(t,e){return t.reduce(function(t,n){var r=n[e];return t[r]||(t[r]=[]),t[r].push(n),t},{})},e.prototype.isOneRelation=function(t){return!Array.isArray(t)&&null!==t&&"object"==typeof t},e.prototype.isManyRelation=function(t){return!!Array.isArray(t)&&!(t.length<1)},e.prototype.makeManyRelation=function(t,e){var n=this;return this.isManyRelation(t)?t.filter(function(t){return n.isOneRelation(t)}).map(function(t){return new e(t)}):[]},e}(p),x=function(t){function e(e,n,r,o){var i=t.call(this,e)||this;return i.related=i.model.relation(n),i.foreignKey=r,i.localKey=o,i}return a(e,t),e.prototype.define=function(t){return t.one(this.related)},e.prototype.attach=function(t,e,n){var r=n[this.related.entity];r&&r[t]&&void 0===r[t][this.foreignKey]&&(e[this.localKey]||(e[this.localKey]=e.$id),r[t][this.foreignKey]=e[this.localKey])},e.prototype.make=function(t,e,n){return this.isOneRelation(t)?new this.related(t):null},e.prototype.load=function(t,e,n){var r=this,o=this.getRelation(t,this.related.entity);o.where(this.foreignKey,this.getKeys(e,this.localKey));var i=this.mapSingleRelations(o.get(),this.foreignKey);e.forEach(function(t){var e=i[t[r.localKey]];t[n]=e||null})},e}(w),C=function(t){function e(e,n,r,o){var i=t.call(this,e)||this;return i.parent=i.model.relation(n),i.foreignKey=r,i.ownerKey=o,i}return a(e,t),e.prototype.define=function(t){return t.one(this.parent)},e.prototype.attach=function(t,e,n){void 0===e[this.foreignKey]&&(e[this.foreignKey]=t)},e.prototype.make=function(t,e,n){return this.isOneRelation(t)?new this.parent(t):null},e.prototype.load=function(t,e,n){var r=this,o=this.getRelation(t,this.parent.entity);o.where(this.ownerKey,this.getKeys(e,this.foreignKey));var i=this.mapSingleRelations(o.get(),this.ownerKey);e.forEach(function(t){var e=i[t[r.foreignKey]];t[n]=e||null})},e}(w),R=function(t){function e(e,n,r,o){var i=t.call(this,e)||this;return i.related=i.model.relation(n),i.foreignKey=r,i.localKey=o,i}return a(e,t),e.prototype.define=function(t){return t.many(this.related)},e.prototype.attach=function(t,e,n){var r=this;Array.isArray(t)&&t.forEach(function(t){var o=n[r.related.entity];o&&o[t]&&void 0===o[t][r.foreignKey]&&(o[t][r.foreignKey]=e.$id)})},e.prototype.make=function(t,e,n){return this.makeManyRelation(t,this.related)},e.prototype.load=function(t,e,n){var r=this,o=this.getRelation(t,this.related.entity);o.where(this.foreignKey,this.getKeys(e,this.localKey));var i=this.mapManyRelations(o.get(),this.foreignKey);e.forEach(function(t){var e=i[t[r.localKey]];t[n]=e||[]})},e}(w),O=function(t){function e(e,n,r,o){var i=t.call(this,e)||this;return i.parent=i.model.relation(n),i.foreignKey=r,i.ownerKey=o,i}return a(e,t),e.prototype.define=function(t){return t.many(this.parent)},e.prototype.attach=function(t,e,n){0!==t.length&&void 0===e[this.foreignKey]&&(e[this.foreignKey]=t)},e.prototype.make=function(t,e,n){return this.makeManyRelation(t,this.parent)},e.prototype.load=function(t,e,n){var r=this,o=this.getRelation(t,this.parent.entity);this.addConstraintForHasManyBy(o,e);var i=this.mapSingleRelations(o.get(),this.ownerKey);e.forEach(function(t){var e=r.getRelatedRecords(i,t[r.foreignKey]);t[n]=e})},e.prototype.addConstraintForHasManyBy=function(t,e){var n=this,r=e.reduce(function(t,e){return t.concat(e[n.foreignKey])},[]);t.where(this.ownerKey,r)},e.prototype.getRelatedRecords=function(t,e){return e.reduce(function(e,n){var r=t[n];return r&&e.push(r),e},[])},e}(w),E=function(t){function e(e,n,r,o,i,u,a){var s=t.call(this,e)||this;return s.related=s.model.relation(n),s.through=s.model.relation(r),s.firstKey=o,s.secondKey=i,s.localKey=u,s.secondLocalKey=a,s}return a(e,t),e.prototype.define=function(t){return t.many(this.related)},e.prototype.attach=function(t,e,n){},e.prototype.make=function(t,e,n){return this.makeManyRelation(t,this.related)},e.prototype.load=function(t,e,n){var r=this,o=this.getRelation(t,this.related.entity),i=t.newQuery(this.through.entity);this.addEagerConstraintForThrough(i,e);var u=i.get();this.addEagerConstraintForRelated(o,u);var a=this.mapThroughRelations(u,o);e.forEach(function(t){var e=a[t[r.localKey]];t[n]=e||[]})},e.prototype.addEagerConstraintForThrough=function(t,e){t.where(this.firstKey,this.getKeys(e,this.localKey))},e.prototype.addEagerConstraintForRelated=function(t,e){t.where(this.secondKey,this.getKeys(e,this.secondLocalKey))},e.prototype.mapThroughRelations=function(t,e){var n=this,r=this.mapManyRelations(e.get(),this.secondKey);return t.reduce(function(t,e){var o=e[n.firstKey];t[o]||(t[o]=[]);var i=r[e[n.secondLocalKey]];return t[o]=t[o].concat(i),t},{})},e}(w),k=function(t){function e(e,n,r,o,i,u,a){var s=t.call(this,e)||this;return s.related=s.model.relation(n),s.pivot=s.model.relation(r),s.foreignPivotKey=o,s.relatedPivotKey=i,s.parentKey=u,s.relatedKey=a,s}return a(e,t),e.prototype.define=function(t){return t.many(this.related)},e.prototype.attach=function(t,e,n){},e.prototype.make=function(t,e,n){return this.makeManyRelation(t,this.related)},e.prototype.load=function(t,e,n){var r=this,o=this.getRelation(t,this.related.entity),i=t.newQuery(this.pivot.entity);this.addEagerConstraintForPivot(i,e);var u=i.get();this.addEagerConstraintForRelated(o,u);var a=this.mapPivotRelations(u,o);e.forEach(function(t){var e=a[t[r.parentKey]];t[n]=e})},e.prototype.addEagerConstraintForPivot=function(t,e){t.where(this.foreignPivotKey,this.getKeys(e,this.parentKey))},e.prototype.addEagerConstraintForRelated=function(t,e){t.where(this.relatedKey,this.getKeys(e,this.relatedPivotKey))},e.prototype.mapPivotRelations=function(t,e){var n=this,r=this.mapManyRelations(e.get(),this.relatedKey);return t.reduce(function(t,e){var o=e[n.foreignPivotKey];t[o]||(t[o]=[]);var i=r[e[n.relatedPivotKey]];return i&&(t[o]=t[o].concat(i)),t},{})},e.prototype.createPivots=function(t,e,n){var r=this;return this.pivot.primaryKey instanceof Array==!1?e:(h.forOwn(e[t.entity],function(t){var o=t[n];void 0!==o&&0!==o.length&&r.createPivotRecord(e,t,o)}),e)},e.prototype.createPivotRecord=function(t,e,n){var r=this;n.forEach(function(n){var o,i,u=e[r.parentKey]+"_"+n;t[r.pivot.entity]=s({},t[r.pivot.entity],((o={})[u]=((i={$id:u})[r.foreignPivotKey]=e[r.parentKey],i[r.relatedPivotKey]=n,i),o))})},e}(w),A=function(t){function e(e,n,r){var o=t.call(this,e)||this;return o.id=n,o.type=r,o}return a(e,t),e.prototype.define=function(t){var e=this;return t.union(function(t,n){return n[e.type]})},e.prototype.attach=function(t,e,n){},e.prototype.make=function(t,e,n){if(!this.isOneRelation(t))return null;var r=e[this.type],o=this.model.relation(r);return o?new o(t):null},e.prototype.load=function(t,e,n){var r=this,o=this.getTypes(e).reduce(function(e,n){var o=r.getRelation(t,n);return e[n]=r.mapSingleRelations(o.get(),"$id"),e},{});e.forEach(function(t){var e=t[r.id],i=t[r.type],u=o[i][e];t[n]=u||null})},e.prototype.getTypes=function(t){var e=this;return t.reduce(function(t,n){var r=n[e.type];return!t.includes(r)&&t.push(r),t},[])},e}(w),j=function(t){function e(e,n,r,o,i){var u=t.call(this,e)||this;return u.related=u.model.relation(n),u.id=r,u.type=o,u.localKey=i,u}return a(e,t),e.prototype.define=function(t){return t.one(this.related)},e.prototype.attach=function(t,e,n){var r=n[this.related.entity]&&n[this.related.entity][t];r&&(r[this.id]=r[this.id]||e.$id,r[this.type]=r[this.type]||this.model.entity)},e.prototype.make=function(t,e,n){return this.isOneRelation(t)?new this.related(t):null},e.prototype.load=function(t,e,n){var r=this,o=this.getRelation(t,this.related.entity);this.addEagerConstraintForMorphOne(o,e,t.entity);var i=this.mapSingleRelations(o.get(),this.id);e.forEach(function(t){var e=i[t[r.localKey]];t[n]=e||null})},e.prototype.addEagerConstraintForMorphOne=function(t,e,n){t.where(this.type,n).where(this.id,this.getKeys(e,this.localKey))},e}(w),S=function(t){function e(e,n,r,o,i){var u=t.call(this,e)||this;return u.related=u.model.relation(n),u.id=r,u.type=o,u.localKey=i,u}return a(e,t),e.prototype.define=function(t){return t.many(this.related)},e.prototype.attach=function(t,e,n){var r=this;if(Array.isArray(t)){var o=n[this.related.entity];t.forEach(function(t){var n=o[t];n[r.id]=n[r.id]||e.$id,n[r.type]=n[r.type]||r.model.entity})}},e.prototype.make=function(t,e,n){return this.makeManyRelation(t,this.related)},e.prototype.load=function(t,e,n){var r=this,o=this.getRelation(t,this.related.entity);this.addEagerConstraintForMorphMany(o,e,t.entity);var i=this.mapManyRelations(o.get(),this.id);e.forEach(function(t){var e=i[t[r.localKey]];t[n]=e})},e.prototype.addEagerConstraintForMorphMany=function(t,e,n){t.where(this.type,n).where(this.id,this.getKeys(e,this.localKey))},e}(w),$=function(t){function e(e,n,r,o,i,u,a,s){var c=t.call(this,e)||this;return c.related=c.model.relation(n),c.pivot=c.model.relation(r),c.relatedId=o,c.id=i,c.type=u,c.parentKey=a,c.relatedKey=s,c}return a(e,t),e.prototype.define=function(t){return t.many(this.related)},e.prototype.attach=function(t,e,n){},e.prototype.make=function(t,e,n){return this.makeManyRelation(t,this.related)},e.prototype.load=function(t,e,n){var r=this,o=this.getRelation(t,this.related.entity),i=t.newQuery(this.pivot.entity);this.addEagerConstraintForPivot(i,e,t.entity);var u=i.get();this.addEagerConstraintForRelated(o,u);var a=this.mapPivotRelations(u,o);e.forEach(function(t){var e=a[t[r.parentKey]];t[n]=e})},e.prototype.addEagerConstraintForPivot=function(t,e,n){t.where(this.type,n).where(this.id,this.getKeys(e,this.parentKey))},e.prototype.addEagerConstraintForRelated=function(t,e){t.where(this.relatedKey,this.getKeys(e,this.relatedId))},e.prototype.mapPivotRelations=function(t,e){var n=this,r=this.mapManyRelations(e.get(),this.relatedKey);return t.reduce(function(t,e){var o=e[n.id];t[o]||(t[o]=[]);var i=r[e[n.relatedId]];return t[o]=t[o].concat(i),t},{})},e.prototype.createPivots=function(t,e,n){var r=this;return h.forOwn(e[t.entity],function(o){var i=o[n];Array.isArray(i)&&0!==i.length&&r.createPivotRecord(t,e,o,i)}),e},e.prototype.createPivotRecord=function(t,e,n,r){var o=this;r.forEach(function(r){var i,u,a=n[o.parentKey],c=a+"_"+r+"_"+t.entity;e[o.pivot.entity]=s({},e[o.pivot.entity],((i={})[c]=((u={$id:c})[o.relatedId]=r,u[o.id]=a,u[o.type]=t.entity,u),i))})},e}(w),F=function(t){function e(e,n,r,o,i,u,a,s){var c=t.call(this,e)||this;return c.related=c.model.relation(n),c.pivot=c.model.relation(r),c.relatedId=o,c.id=i,c.type=u,c.parentKey=a,c.relatedKey=s,c}return a(e,t),e.prototype.define=function(t){return t.many(this.related)},e.prototype.attach=function(t,e,n){},e.prototype.make=function(t,e,n){return this.makeManyRelation(t,this.related)},e.prototype.load=function(t,e,n){var r=this,o=this.getRelation(t,this.related.entity),i=t.newQuery(this.pivot.entity);this.addEagerConstraintForPivot(i,e,this.related.entity);var u=i.get();this.addEagerConstraintForRelated(o,u);var a=this.mapPivotRelations(u,o);e.forEach(function(t){var e=a[t[r.parentKey]];t[n]=e})},e.prototype.addEagerConstraintForPivot=function(t,e,n){t.where(this.type,n).where(this.relatedId,this.getKeys(e,this.parentKey))},e.prototype.addEagerConstraintForRelated=function(t,e){t.where(this.relatedKey,this.getKeys(e,this.id))},e.prototype.mapPivotRelations=function(t,e){var n=this,r=this.mapManyRelations(e.get(),this.relatedKey);return t.reduce(function(t,e){var o=e[n.relatedId];t[o]||(t[o]=[]);var i=r[e[n.id]];return t[o]=t[o].concat(i),t},{})},e.prototype.createPivots=function(t,e,n){var r=this;return h.forOwn(e[t.entity],function(t){var o=t[n];Array.isArray(o)&&r.createPivotRecord(e,t,o)}),e},e.prototype.createPivotRecord=function(t,e,n){var r=this;n.forEach(function(n){var o,i,u=e[r.parentKey],a=n+"_"+u+"_"+r.related.entity;t[r.pivot.entity]=s({},t[r.pivot.entity],((o={})[a]=((i={$id:a})[r.relatedId]=u,i[r.id]=n,i[r.type]=r.related.entity,i),o))})},e}(w),M=function(){function t(t){this.$id=null,this.$fill(t)}return t.fields=function(){return{}},t.getFields=function(){return this.cachedFields?this.cachedFields:(this.cachedFields=this.fields(),this.cachedFields)},t.attr=function(t,e){return new y(this,t,e)},t.string=function(t,e){return new g(this,t,e)},t.number=function(t,e){return new m(this,t,e)},t.boolean=function(t,e){return new b(this,t,e)},t.increment=function(){return new v(this)},t.hasOne=function(t,e,n){return new x(this,t,e,this.localKey(n))},t.belongsTo=function(t,e,n){return new C(this,t,e,this.relation(t).localKey(n))},t.hasMany=function(t,e,n){return new R(this,t,e,this.localKey(n))},t.hasManyBy=function(t,e,n){return new O(this,t,e,this.relation(t).localKey(n))},t.hasManyThrough=function(t,e,n,r,o,i){return new E(this,t,e,n,r,this.localKey(o),this.relation(e).localKey(i))},t.belongsToMany=function(t,e,n,r,o,i){return new k(this,t,e,n,r,this.localKey(o),this.relation(t).localKey(i))},t.morphTo=function(t,e){return new A(this,t,e)},t.morphOne=function(t,e,n,r){return new j(this,t,e,n,this.localKey(r))},t.morphMany=function(t,e,n,r){return new S(this,t,e,n,this.localKey(r))},t.morphToMany=function(t,e,n,r,o,i,u){return new $(this,t,e,n,r,o,this.localKey(i),this.relation(t).localKey(u))},t.morphedByMany=function(t,e,n,r,o,i,u){return new F(this,t,e,n,r,o,this.localKey(i),this.relation(t).localKey(u))},t.mutators=function(){return{}},t.database=function(){return i.database},t.store=function(){return this.database().store},t.namespace=function(t){return this.database().namespace+"/"+this.entity+"/"+t},t.getters=function(t){return this.store().getters[this.namespace(t)]},t.dispatch=function(t,e){return this.store().dispatch(this.namespace(t),e)},t.commit=function(t){this.store().commit(this.database().namespace+"/$mutate",{entity:this.entity,callback:t})},t.all=function(){return this.getters("all")()},t.find=function(t){return this.getters("find")(t)},t.query=function(){return this.getters("query")()},t.new=function(){return this.dispatch("new")},t.create=function(t){return this.dispatch("create",t)},t.insert=function(t){return this.dispatch("insert",t)},t.update=function(t){return this.dispatch("update",t)},t.insertOrUpdate=function(t){return this.dispatch("insertOrUpdate",t)},t.delete=function(t){return this.dispatch("delete",t)},t.deleteAll=function(){return this.dispatch("deleteAll")},t.id=function(t){var e=this.primaryKey;return"string"==typeof e?t[e]:e.map(function(e){return t[e]}).join("_")},t.localKey=function(t){return t||("string"==typeof this.primaryKey?this.primaryKey:"id")},t.relation=function(t){return"string"!=typeof t?t:this.database().model(t)},t.getAttributeClass=function(t){switch(t){case"increment":return v;default:throw Error('The attribute name "'+t+"\" doesn't exists.")}},t.getFieldsByAttribute=function(t){var e=this.getAttributeClass(t),n=this.fields();return Object.keys(n).reduce(function(t,r){var o=n[r];return o instanceof e&&(t[r]=o),t},{})},t.getIncrementFields=function(){return this.getFieldsByAttribute("increment")},t.hasIncrementFields=function(){return Object.keys(this.getIncrementFields()).length>0},t.pivotFields=function(){var t=[];return h.forOwn(this.fields(),function(e,n){var r;(e instanceof k||e instanceof $||e instanceof F)&&t.push(((r={})[n]=e,r))}),t},t.hasPivotFields=function(){return this.pivotFields().length>0},t.hydrate=function(t){return new this(t).$toJson()},t.prototype.$self=function(){return this.constructor},t.prototype.$fields=function(){return this.$self().getFields()},t.prototype.$store=function(){return this.$self().store()},t.prototype.$namespace=function(t){return this.$self().namespace(t)},t.prototype.$getters=function(t){return this.$self().getters(t)},t.prototype.$dispatch=function(t,e){return c(this,void 0,void 0,function(){return f(this,function(n){return[2,this.$self().dispatch(t,e)]})})},t.prototype.$all=function(){return this.$getters("all")()},t.prototype.$find=function(t){return this.$getters("find")(t)},t.prototype.$query=function(){return this.$getters("query")()},t.prototype.$create=function(t){return c(this,void 0,void 0,function(){return f(this,function(e){return[2,this.$dispatch("create",t)]})})},t.prototype.$insert=function(t){return c(this,void 0,void 0,function(){return f(this,function(e){return[2,this.$dispatch("insert",t)]})})},t.prototype.$update=function(t){return c(this,void 0,void 0,function(){return f(this,function(e){return Array.isArray(t)?[2,this.$dispatch("update",t)]:void 0!==t.where?[2,this.$dispatch("update",t)]:void 0===this.$self().id(t)?[2,this.$dispatch("update",{where:this.$id,data:t})]:[2,this.$dispatch("update",t)]})})},t.prototype.$insertOrUpdate=function(t){return c(this,void 0,void 0,function(){return f(this,function(e){return[2,this.$dispatch("insertOrUpdate",t)]})})},t.prototype.$delete=function(t){return c(this,void 0,void 0,function(){return f(this,function(e){return t?[2,this.$dispatch("delete",t)]:null===this.$id?[2,null]:[2,this.$dispatch("delete",this.$id)]})})},t.prototype.$deleteAll=function(){return c(this,void 0,void 0,function(){return f(this,function(t){return[2,this.$dispatch("deleteAll")]})})},t.prototype.$fill=function(t){var e=this,n=t||{},r=this.$fields();Object.keys(r).forEach(function(t){var o=r[t],i=n[t];e[t]=o.make(i,n,t)}),void 0!==n.$id&&(this.$id=n.$id)},t.prototype.$toJson=function(){var e=this,n=this.$fields();return Object.keys(n).reduce(function(n,r){var o=e[r];return o instanceof t?(n[r]=e.serializeItem(o),n):Array.isArray(o)?(n[r]=e.serializeCollection(o),n):(n[r]=o,n)},{})},t.prototype.$save=function(){return c(this,void 0,void 0,function(){var t,e,n,r=this;return f(this,function(o){switch(o.label){case 0:return t=this.$self().getFields(),e=Object.keys(t).reduce(function(e,n){return t[n]instanceof d&&(e[n]=r[n]),e},{}),[4,this.$dispatch("insertOrUpdate",{data:e})];case 1:return n=o.sent(),this.$fill(n[this.$self().entity][0]),[2,this]}})})},t.prototype.serializeItem=function(t){return t.$toJson()},t.prototype.serializeCollection=function(e){return e.map(function(e){return e instanceof t?e.$toJson():e})},t.primaryKey="id",t.state={},t}();function K(t){return!(!t||"function"!=typeof t.hasOwnProperty||!(t.hasOwnProperty("__ownerID")||t._map&&t._map.hasOwnProperty("__ownerID")))}function B(t,e,n){return Object.keys(t).reduce(function(e,r){var o=""+r;return e.has(o)?e.set(o,n(e.get(o),t[o])):e},e)}var I="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},P=function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")},T=function(){function t(t,e){for(var n=0;n1&&void 0!==arguments[1]?arguments[1]:{},r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{};if(P(this,t),!e||"string"!=typeof e)throw new Error("Expected a string key for Entity, but found "+e+".");var o=r.idAttribute,i=void 0===o?"id":o,u=r.mergeStrategy,a=void 0===u?function(t,e){return U({},t,e)}:u,s=r.processStrategy,c=void 0===s?function(t){return U({},t)}:s;this._key=e,this._getId="function"==typeof i?i:z(i),this._idAttribute=i,this._mergeStrategy=a,this._processStrategy=c,this.define(n)}return t.prototype.define=function(t){this.schema=Object.keys(t).reduce(function(e,n){var r,o=t[n];return U({},e,((r={})[n]=o,r))},this.schema||{})},t.prototype.getId=function(t,e,n){return this._getId(t,e,n)},t.prototype.merge=function(t,e){return this._mergeStrategy(t,e)},t.prototype.normalize=function(t,e,n,r,o){var i=this,u=this._processStrategy(t,e,n);return Object.keys(this.schema).forEach(function(t){if(u.hasOwnProperty(t)&&"object"===I(u[t])){var e=i.schema[t];u[t]=r(u[t],u,t,e,o)}}),o(this,u,t,e,n),this.getId(t,e,n)},t.prototype.denormalize=function(t,e){var n=this;return K(t)?B(this.schema,t,e):(Object.keys(this.schema).forEach(function(r){if(t.hasOwnProperty(r)){var o=n.schema[r];t[r]=e(t[r],o)}}),t)},T(t,[{key:"key",get:function(){return this._key}},{key:"idAttribute",get:function(){return this._idAttribute}}]),t}(),D=function(){function t(e,n){P(this,t),n&&(this._schemaAttribute="string"==typeof n?function(t){return t[n]}:n),this.define(e)}return t.prototype.define=function(t){this.schema=t},t.prototype.getSchemaAttribute=function(t,e,n){return!this.isSingleSchema&&this._schemaAttribute(t,e,n)},t.prototype.inferSchema=function(t,e,n){if(this.isSingleSchema)return this.schema;var r=this.getSchemaAttribute(t,e,n);return this.schema[r]},t.prototype.normalizeValue=function(t,e,n,r,o){var i=this.inferSchema(t,e,n);if(!i)return t;var u=r(t,e,n,i,o);return this.isSingleSchema||void 0===u||null===u?u:{id:u,schema:this.getSchemaAttribute(t,e,n)}},t.prototype.denormalizeValue=function(t,e){var n=K(t)?t.get("schema"):t.schema;if(!this.isSingleSchema&&!n)return t;var r=K(t)?t.get("id"):t.id,o=this.isSingleSchema?this.schema:this.schema[n];return e(r||t,o)},T(t,[{key:"isSingleSchema",get:function(){return!this._schemaAttribute}}]),t}(),H=function(t){function e(n,r){if(P(this,e),!r)throw new Error('Expected option "schemaAttribute" not found on UnionSchema.');return q(this,t.call(this,n,r))}return L(e,t),e.prototype.normalize=function(t,e,n,r,o){return this.normalizeValue(t,e,n,r,o)},e.prototype.denormalize=function(t,e){return this.denormalizeValue(t,e)},e}(D),W=function(t){function e(){return P(this,e),q(this,t.apply(this,arguments))}return L(e,t),e.prototype.normalize=function(t,e,n,r,o){var i=this;return Object.keys(t).reduce(function(e,n,u){var a,s=t[n];return void 0!==s&&null!==s?U({},e,((a={})[n]=i.normalizeValue(s,t,n,r,o),a)):e},{})},e.prototype.denormalize=function(t,e){var n=this;return Object.keys(t).reduce(function(r,o){var i,u=t[o];return U({},r,((i={})[o]=n.denormalizeValue(u,e),i))},{})},e}(D),G=function(t){return Array.isArray(t)?t:Object.keys(t).map(function(e){return t[e]})},V=function(t,e,n,r,o,i){return t=function(t){if(Array.isArray(t)&&t.length>1)throw new Error("Expected schema definition to be a single schema, but found "+t.length+".");return t[0]}(t),G(e).map(function(e,u){return o(e,n,r,t,i)})},J=function(t){function e(){return P(this,e),q(this,t.apply(this,arguments))}return L(e,t),e.prototype.normalize=function(t,e,n,r,o){var i=this;return G(t).map(function(t,u){return i.normalizeValue(t,e,n,r,o)}).filter(function(t){return void 0!==t&&null!==t})},e.prototype.denormalize=function(t,e){var n=this;return t&&t.map?t.map(function(t){return n.denormalizeValue(t,e)}):t},e}(D),Z=function(t,e,n,r,o,i){var u=U({},e);return Object.keys(t).forEach(function(n){var r=t[n],a=o(e[n],e,n,r,i);void 0===a||null===a?delete u[n]:u[n]=a}),u},Q={Array:J,Entity:N,Object:function(){function t(e){P(this,t),this.define(e)}return t.prototype.define=function(t){this.schema=Object.keys(t).reduce(function(e,n){var r,o=t[n];return U({},e,((r={})[n]=o,r))},this.schema||{})},t.prototype.normalize=function(){for(var t=arguments.length,e=Array(t),n=0;n0&&t.withAllRecursive(e-1)})},t.parseWithRelations=function(t,e,n){var r=this,o=e[0];o.split("|").forEach(function(e){r.setEagerLoad(t,e)}),1!==e.length?(e.shift(),this.addNestedWiths(t,e,n)):this.setEagerLoad(t,o,n)},t.addNestedWiths=function(t,e,n){var r=e.join(".");this.setEagerLoad(t,r,function(t){t.with(r,n)})},t.eagerLoadRelations=function(t,e){var n=t.model.getFields();for(var r in t.load){var o=n[r];o instanceof w&&o.load(t,e,r)}},t}(),ft=function(){function t(t){this.indexToBeDeleted=[],this.query=t}return t.on=function(t,e,n){void 0===n&&(n=!1);var r=this.lastHookId+1;return this.lastHookId=r,this.hooks[t]||(this.hooks[t]=[]),this.hooks[t].push({callback:e,once:n,uid:r}),r},t.off=function(t){var e=this,n=!1;return Object.keys(this.hooks).some(function(r){var o=e.hooks[r],i=o.findIndex(function(e){return e.uid===t});return-1!==i&&(o.splice(i,1),n=!0),n}),n},t.prototype.self=function(){return this.constructor},t.prototype.getHook=function(t){return this.query.model[t]||null},t.prototype.getGlobalHook=function(t){return this.self().hooks[t]||null},t.prototype.has=function(t){return!!this.getHook(t)||!!this.getGlobalHook(t)},t.prototype.executeSelectHook=function(t,e){return this.has(t)?(e=this.executeLocalSelectHook(t,e),e=this.executeGlobalSelectHook(t,e)):e},t.prototype.executeLocalSelectHook=function(t,e){var n=this.getHook(t);return n?n(e,this.query.entity):e},t.prototype.executeGlobalSelectHook=function(t,e){var n=this,r=this.getGlobalHook(t);if(!r)return e;var o=[];return r.forEach(function(t,r){var i=t.callback,u=t.once;e=i.call(n.query,e,n.query.entity),u&&o.push(r)}),o.reverse().forEach(function(t){r.splice(t,1)}),e},t.prototype.executeMutationHookOnRecords=function(t,e){var n=this;this.has(t)&&(Object.keys(e).forEach(function(r){!1===n.executeMutationHook(t,e[r])&&delete e[r]}),this.removeGlobalHook(t))},t.prototype.executeMutationHook=function(t,e){return!1!==this.executeLocalMutationHook(t,e)&&(!1!==this.executeGlobalMutationHook(t,e)&&void 0)},t.prototype.executeLocalMutationHook=function(t,e){var n=this.getHook(t);if(n)return n(e,this.query.entity)},t.prototype.executeGlobalMutationHook=function(t,e){var n=this,r=this.getGlobalHook(t);if(r){var o=[];return r.forEach(function(t,r){o.push(t.callback.call(n.query,e,n.query.entity)),t.once&&n.indexToBeDeleted.push(r)}),!o.includes(!1)&&void 0}},t.prototype.removeGlobalHook=function(t){var e=this.getGlobalHook(t);e&&this.indexToBeDeleted.reverse().forEach(function(t){e.splice(t,1)})},t.hooks={},t.lastHookId=0,t}(),lt=function(){function t(t,e){this.wheres=[],this.orders=[],this._offset=0,this._limit=Math.pow(2,53)-1,this.load={},this.result={data:null},this.rootState=t,this.state=t[e],this.entity=e,this.model=this.getModel(e),this.module=this.getModule(e),this.hook=new ft(this)}return t.database=function(){return i.database},t.getModel=function(t){return this.database().model(t)},t.getModels=function(){return this.database().models()},t.getModule=function(t){return this.database().module(t)},t.getModules=function(){return this.database().modules()},t.deleteAll=function(t){var e=this,n=this.getModels();h.forOwn(n,function(n,r){t[r]&&new e(t,r).deleteAll()})},t.on=function(t,e,n){return ft.on(t,e,n)},t.off=function(t){return ft.off(t)},t.prototype.self=function(){return this.constructor},t.prototype.newQuery=function(e){return e=e||this.entity,new t(this.rootState,e)},t.prototype.database=function(){return this.self().database()},t.prototype.getModel=function(t){var e=t||this.entity;return this.self().getModel(e)},t.prototype.getModels=function(){return this.self().getModels()},t.prototype.getModule=function(t){var e=t||this.entity;return this.self().getModule(e)},t.prototype.getModules=function(){return this.self().getModules()},t.prototype.setResult=function(t){return this.result=t,this},t.prototype.all=function(){return this.get()},t.prototype.find=function(t){return this.item(this.state.data[t])},t.prototype.get=function(){var t=this.select();return this.collect(t)},t.prototype.first=function(){var t=this.select();return this.item(t[0])},t.prototype.last=function(){var t=this.select();return this.item(t[t.length-1])},t.prototype.records=function(){var t=this;return Object.keys(this.state.data).map(function(e){var n=t.state.data[e];return n instanceof M?n:t.hydrate(n)})},t.prototype.where=function(t,e){return this.wheres.push({field:t,value:e,boolean:"and"}),this},t.prototype.orWhere=function(t,e){return this.wheres.push({field:t,value:e,boolean:"or"}),this},t.prototype.orderBy=function(t,e){return void 0===e&&(e="asc"),this.orders.push({field:t,direction:e}),this},t.prototype.offset=function(t){return this._offset=t,this},t.prototype.limit=function(t){return this._limit=t,this},t.prototype.with=function(t,e){return void 0===e&&(e=null),ct.with(this,t,e),this},t.prototype.withAll=function(){return ct.withAll(this),this},t.prototype.withAllRecursive=function(t){return void 0===t&&(t=3),ct.withAllRecursive(this,t),this},t.prototype.has=function(t,e,n){return this.addHasConstraint(t,e,n)},t.prototype.hasNot=function(t,e,n){return this.addHasConstraint(t,e,n,!1)},t.prototype.addHasConstraint=function(t,e,n,r){var o=this.matchesHasRelation(t,e,n,r);return this.where("$id",function(t){return o.includes(t)}),this},t.prototype.whereHas=function(t,e){return this.addWhereHasConstraint(t,e)},t.prototype.whereHasNot=function(t,e){return this.addWhereHasConstraint(t,e,!1)},t.prototype.addWhereHasConstraint=function(t,e,n){var r=this.matchesWhereHasRelation(t,e,n);return this.where("$id",function(t){return r.includes(t)}),this},t.prototype.select=function(){var t=this.records();return t=this.hook.executeSelectHook("beforeSelect",t),t=this.filterWhere(t),t=this.hook.executeSelectHook("afterWhere",t),t=this.filterOrderBy(t),t=this.hook.executeSelectHook("afterOrderBy",t),t=this.filterLimit(t),t=this.hook.executeSelectHook("afterLimit",t)},t.prototype.filterWhere=function(t){return st.where(this,t)},t.prototype.filterOrderBy=function(t){return st.orderBy(this,t)},t.prototype.filterLimit=function(t){return st.limit(this,t)},t.prototype.count=function(){return this.get().length},t.prototype.max=function(t){var e=this.get().reduce(function(e,n){return"number"==typeof n[t]&&e.push(n[t]),e},[]);return 0===e.length?0:Math.max.apply(Math,e)},t.prototype.min=function(t){var e=this.get().reduce(function(e,n){return"number"==typeof n[t]&&e.push(n[t]),e},[]);return 0===e.length?0:Math.min.apply(Math,e)},t.prototype.sum=function(t){return this.get().reduce(function(e,n){return"number"==typeof n[t]&&(e+=n[t]),e},0)},t.prototype.item=function(t){return t?(Object.keys(this.load).length>0&&(t=new this.model(t),ct.eagerLoadRelations(this,[t])),t):null},t.prototype.collect=function(t){var e=this;return t.length<1?[]:(Object.keys(this.load).length>0&&(t=t.map(function(t){return new e.model(t)}),ct.eagerLoadRelations(this,t)),t)},t.prototype.matchesHasRelation=function(t,e,n,r){var o;void 0===r&&(r=!0),o=void 0===e?function(t){return t.length>=1}:"number"==typeof e?function(t){return t.length>=e}:"="===e&&"number"==typeof n?function(t){return t.length===n}:">"===e&&"number"==typeof n?function(t){return t.length>n}:">="===e&&"number"==typeof n?function(t){return t.length>=n}:"<"===e&&"number"==typeof n?function(t){return t.length=1};var i=[];return this.newQuery().with(t).get().forEach(function(e){var n=e[t],u=!1;Array.isArray(n)&&n.length<1?u=!1:Array.isArray(n)?u=o(n):n&&(u=o([n])),u===r&&i.push(e.$id)}),i},t.prototype.matchesWhereHasRelation=function(t,e,n){void 0===n&&(n=!0);var r=[];return this.newQuery().with(t,e).get().forEach(function(e){var o=e[t];(Array.isArray(o)?!!o.length:!!o)===n&&r.push(e.$id)}),r},t.prototype.new=function(){var t=(new this.model).$toJson(),e=this.insert(t,{});return this.result.data=e[this.entity][0],this.result.data},t.prototype.create=function(t,e){return this.persist(t,"create",e)},t.prototype.createMany=function(t){var e=this,n=this.hydrateMany(t);return this.commit("create",n,function(){e.state.data=n}),this.map(n)},t.prototype.insert=function(t,e){return this.persist(t,"insert",e)},t.prototype.insertMany=function(t){var e=this,n=this.hydrateMany(t);return this.commit("create",n,function(){e.state.data=s({},e.state.data,n)}),this.map(n)},t.prototype.update=function(t,e,n){if(Array.isArray(t))return this.persist(t,"update",n);if("function"==typeof t){if(!e)throw new Error("You must specify `where` to update records by specifying `data` as a closure.");return"function"==typeof e?this.updateByCondition(t,e):this.updateById(t,e)}if("function"==typeof e)return this.updateByCondition(t,e);if(!e)return this.persist(t,"update",n);if(Array.isArray(this.model.primaryKey))throw new Error("\n You can't specify `where` value as `string` or `number` when you\n have a composite key defined in your model. Please include composite\n keys to the `data` fields.\n ");return t[this.model.primaryKey]=e,this.persist(t,"update",n)},t.prototype.updateMany=function(t){var e=this.combine(t);return this.commitUpdate(e)},t.prototype.updateById=function(t,e){var n;e="number"==typeof e?e.toString():e;var r=this.state.data[e];if(!r)return null;var o=((n={})[e]=this.processUpdate(t,r),n);return this.commitUpdate(o),o[e]},t.prototype.updateByCondition=function(t,e){var n=this,r=Object.keys(this.state.data).reduce(function(r,o){var i=n.state.data[o];return e(i)?(r[o]=n.processUpdate(t,i),r):r},{});return this.commitUpdate(r)},t.prototype.processUpdate=function(t,e){return"function"==typeof t?(t(e),e):this.hydrate(s({},e,t))},t.prototype.commitUpdate=function(t){var e=this;return this.commit("update",t,function(){e.state.data=s({},e.state.data,t)}),this.map(t)},t.prototype.insertOrUpdate=function(t,e){return this.persist(t,"insertOrUpdate",e)},t.prototype.insertOrUpdateMany=function(t){var e=this,n={},r={};return Object.keys(t).forEach(function(o){var i=t[o];e.state.data[o]?r[o]=i:n[o]=i}),this.insertMany(n).concat(this.updateMany(r))},t.prototype.persist=function(t,e,n){var r=this;return t=this.normalize(t),h.isEmpty(t)?("create"===e&&(this.state.data={}),{}):(this.result.data=Object.keys(t).reduce(function(o,i){var u=r.newQuery(i)[r.getPersistMethod(i,e,n)+"Many"](t[i]);return u.length>0&&(o[i]=u),o},{}),this.result.data)},t.prototype.getPersistMethod=function(t,e,n){return n.create&&n.create.includes(t)?"create":n.insert&&n.insert.includes(t)?"insert":n.update&&n.update.includes(t)?"update":n.insertOrUpdate&&n.insertOrUpdate.includes(t)?"insertOrUpdate":e},t.prototype.delete=function(t){return"function"==typeof t?(this.result.data=this.deleteByCondition(t),this.result.data):(this.result.data=this.deleteById(t),this.result.data)},t.prototype.deleteById=function(t){var e;t="number"==typeof t?t.toString():t;var n=this.state.data[t];if(!n)return null;var r=((e={})[t]=n,e);return this.commitDelete(r)[0]},t.prototype.deleteByCondition=function(t){var e=this,n=Object.keys(this.state.data).reduce(function(n,r){var o=e.state.data[r];return t(o)?(n[r]=o,n):n},{});return this.commitDelete(n)},t.prototype.deleteAll=function(){var t=this.state.data;this.commitDelete(t)},t.prototype.commitDelete=function(t){var e=this;return this.commit("delete",t,function(){var n=Object.keys(t);e.state.data=Object.keys(e.state.data).reduce(function(t,r){return n.includes(r)||(t[r]=e.state.data[r]),t},{})}),this.map(t)},t.prototype.normalize=function(t){return ot.normalize(this,t)},t.prototype.hydrate=function(t){return new(0,this.model)(t)},t.prototype.hydrateMany=function(t){var e=this;return Object.keys(t).reduce(function(n,r){var o=t[r];return n[r]=e.hydrate(o),n},{})},t.prototype.combine=function(t){var e=this;return Object.keys(t).reduce(function(n,r){var o=e.state.data[r];if(!o)return n;var i=t[r];return n[r]=e.hydrate(s({},o,i)),n},{})},t.prototype.map=function(t){return Object.keys(t).map(function(e){return t[e]})},t.prototype.commit=function(t,e,n){var r=""+t.charAt(0).toUpperCase()+t.slice(1);this.hook.executeMutationHookOnRecords("before"+r,e),n(),this.hook.executeMutationHookOnRecords("after"+r,e)},t}(),ht={query:function(t,e,n,r){return function(){return r[t.$connection+"/query"](t.$name)}},all:function(t,e,n,r){return function(){return r[t.$connection+"/all"](t.$name)}},find:function(t,e,n,r){return function(e){return r[t.$connection+"/find"](t.$name,e)}}},pt={new:function(t){var e=t.state,n=e.$name;return t.dispatch(e.$connection+"/new",{entity:n},{root:!0})},create:function(t,e){var n=t.state,r=n.$name;return t.dispatch(n.$connection+"/create",s({},e,{entity:r}),{root:!0})},insert:function(t,e){var n=t.state,r=n.$name;return t.dispatch(n.$connection+"/insert",s({},e,{entity:r}),{root:!0})},update:function(t,e){var n=t.state,r=n.$name;return Array.isArray(e)?t.dispatch(n.$connection+"/update",{entity:r,data:e},{root:!0}):void 0===e.data?t.dispatch(n.$connection+"/update",{entity:r,data:e},{root:!0}):t.dispatch(n.$connection+"/update",s({entity:r},e),{root:!0})},insertOrUpdate:function(t,e){var n=t.state,r=n.$name;return t.dispatch(n.$connection+"/insertOrUpdate",s({entity:r},e),{root:!0})},delete:function(t,e){var n=t.state,r=n.$name,o="object"==typeof e?e.where:e;return t.dispatch(n.$connection+"/delete",{entity:r,where:o},{root:!0})},deleteAll:function(t){var e=t.state,n=e.$name;return t.dispatch(e.$connection+"/deleteAll",{entity:n},{root:!0})}},dt={query:function(t){return function(e){return new lt(t,e)}},all:function(t){return function(e){return new lt(t,e).all()}},find:function(t){return function(e,n){return new lt(t,e).find(n)}}},yt={new:function(t,e){var n={data:{}};return t.commit("new",s({},e,{result:n})),n.data},create:function(t,e){return c(this,void 0,void 0,function(){var n;return f(this,function(r){return n={data:{}},t.commit("create",s({},e,{result:n})),[2,n.data]})})},insert:function(t,e){return c(this,void 0,void 0,function(){var n;return f(this,function(r){return n={data:{}},t.commit("insert",s({},e,{result:n})),[2,n.data]})})},update:function(t,e){return c(this,void 0,void 0,function(){var n;return f(this,function(r){return n={data:{}},t.commit("update",s({},e,{result:n})),[2,n.data]})})},insertOrUpdate:function(t,e){return c(this,void 0,void 0,function(){var n;return f(this,function(r){return n={data:{}},t.commit("insertOrUpdate",s({},e,{result:n})),[2,n.data]})})},delete:function(t,e){return c(this,void 0,void 0,function(){var n;return f(this,function(r){return n={data:{}},t.commit("delete",s({},e,{result:n})),[2,n.data]})})},deleteAll:function(t,e){return c(this,void 0,void 0,function(){return f(this,function(n){return e&&e.entity?(t.commit("deleteAll",{entity:e.entity}),[2]):(t.commit("deleteAll"),[2])})})}},vt=function(){function t(){}return t.createPersistOptions=function(t){return{create:t.create,insert:t.insert,update:t.update,insertOrUpdate:t.insertOrUpdate}},t}(),gt={$mutate:function(t,e){e.callback(t[e.entity])},new:function(t,e){var n=e.entity,r=e.result;new lt(t,n).setResult(r).new()},create:function(t,e){var n=e.entity,r=e.data,o=e.result,i=vt.createPersistOptions(e);new lt(t,n).setResult(o).create(r,i)},insert:function(t,e){var n=e.entity,r=e.data,o=e.result,i=vt.createPersistOptions(e);new lt(t,n).setResult(o).insert(r,i)},update:function(t,e){var n=e.entity,r=e.data,o=e.where||null,i=e.result,u=vt.createPersistOptions(e);new lt(t,n).setResult(i).update(r,o,u)},insertOrUpdate:function(t,e){var n=e.entity,r=e.data,o=e.result,i=vt.createPersistOptions(e);new lt(t,n).setResult(o).insertOrUpdate(r,i)},delete:function(t,e){var n=e.entity,r=e.where,o=e.result;new lt(t,n).setResult(o).delete(r)},deleteAll:function(t,e){e&&e.entity?new lt(t,e.entity).deleteAll():lt.deleteAll(t)}};var mt=function(){function t(){}return t.set=function(){this.value=""+this.prefix+this.count},t.get=function(){return this.value},t.increment=function(){return this.count++,this.set(),this.get()},t.count=0,t.prefix="_no_key_",t.value="",t}(),_t=function(){function t(){}return t.create=function(t){return function(e,n,r){var o=t.id(e);return void 0===o||null===o||""===o?mt.get():o}},t}(),bt=function(){function t(){}return t.create=function(t){var e=this;return function(n,r,o){var i=e.getId(t,n);return s({},n,{$id:i})}},t.getId=function(t,e){var n=t.id(e);return void 0===n||null===n||""===n?mt.increment():n},t}(),wt=function(){function t(t){var e=this;this.schemas={},this.model=t;var n=t.database().models();Object.keys(n).forEach(function(t){e.one(n[t])})}return t.create=function(t){return new this(t).one()},t.prototype.one=function(t){if(t=t||this.model,this.schemas[t.entity])return this.schemas[t.entity];var e=new Q.Entity(t.entity,{},{idAttribute:_t.create(t),processStrategy:bt.create(t)});this.schemas[t.entity]=e;var n=this.definition(t);return e.define(n),e},t.prototype.many=function(t){return new Q.Array(this.one(t))},t.prototype.union=function(t){return new Q.Union(this.schemas,t)},t.prototype.definition=function(t){var e=this,n=t.fields();return Object.keys(n).reduce(function(t,r){var o=n[r];return o instanceof w&&(t[r]=o.define(e)),t},{})},t}(),xt=function(){function t(){}return t.create=function(t,e,n){var r={namespaced:!0,state:{$name:t},getters:dt,actions:yt,mutations:gt,modules:{}};return this.createModules(r,t,e,n)},t.createModules=function(t,e,n,r){var o=this;return Object.keys(r).forEach(function(i){var u=n[i],a=r[i];t.modules[i]={namespaced:!0},t.modules[i].state=o.createState(e,i,u,a),t.getters[i]=function(t,e,n,r){return function(){return e.query(i)}},t.modules[i].getters=s({},ht,a.getters),t.modules[i].actions=s({},pt,a.actions),t.modules[i].mutations=a.mutations||{}}),t},t.createState=function(t,e,n,r){var o="function"==typeof n.state?n.state():n.state,i="function"==typeof r.state?r.state():r.state;return s({},o,i,{$connection:t,$name:e,data:{}})},t}(),Ct=function(){function t(){this.entities=[],this.schemas={}}return t.prototype.start=function(t,e){this.store=t,this.namespace=e,this.registerModules(),this.createSchema()},t.prototype.register=function(t,e){void 0===e&&(e={}),this.entities.push({name:t.entity,model:t,module:e})},t.prototype.model=function(t){return this.models()[t]},t.prototype.models=function(){return this.entities.reduce(function(t,e){return t[e.name]=e.model,t},{})},t.prototype.module=function(t){return this.modules()[t]},t.prototype.modules=function(){return this.entities.reduce(function(t,e){return t[e.name]=e.module,t},{})},t.prototype.registerModules=function(){var t=xt.create(this.namespace,this.models(),this.modules());this.store.registerModule(this.namespace,t)},t.prototype.createSchema=function(){var t=this;this.entities.forEach(function(e){t.schemas[e.name]=wt.create(e.model)})},t}();const Rt={baseURL:"http://localhost:3000",url:"/",method:"get",access_token:"",headers:{"Content-Type":"application/json",Accept:"application/json"},data:{},timeout:0,withCredentials:!1,responseType:"json",responseEncoding:"utf8",validateStatus:t=>t>=200&&t<300,maxRedirects:5,socketPath:null,proxy:{},onResponse:t=>t.data,onUnauthorised(t){},onNotFound(t){},onServerError(t){},onGenericError(t){},onValidationError(t){},onError(t){const{response:e}=t,n={401:this.onUnauthorised,404:this.onNotFound,422:this.onValidationError,500:this.onServerError};return e&&e.status in n?n[e.status](t):this.onGenericError(t),Promise.reject(t)}},Ot={database:new Ct,http:Rt},Et={getters:{loading:t=>t.loading,errors:t=>t.errors},mutations:{onRequest(t){t.loading=!0,t.errors=[]},onError(t,e){t.loading=!1,t.errors=e.data},onSuccess(t){t.loading=!1,t.errors=[]}},state:{loading:!1,errors:[]}},kt={http:Rt,methods:{$fetch:{name:"fetch",http:{url:"",method:"get"}},$get:{name:"get",http:{url:"/:id",method:"get"}},$create:{name:"create",alias:["insert"],http:{url:"",method:"post"}},$update:{name:"update",http:{url:"/:id",method:"put"}},$delete:{name:"delete",http:{url:"/:id",method:"delete"}}}};class At{constructor(t,e){if(this.components=t,this.options=o.a.merge({},Ot,e),this.database=e.database,!e.database)throw new Error("database option is required to initialise!")}static setup(t,e){return this.instance=new At(t,e),this.instance}static getInstance(){return this.instance}getModelFromState(t){return o.a.find(this.database.entities,{name:t.$name}).model}}class jt{static transformModule(t){return o.a.merge({},Et,t)}static transformModel(t){const e=At.getInstance();return kt.http=o.a.merge({},kt.http,e.options.http),t.methodConf=o.a.merge({},kt,t.methodConf),t.methodConf.http.url="/"===t.methodConf.http.url?`/${t.entity}`:t.methodConf.http.url,t.getFields=(()=>(t.cachedFields||(t.cachedFields=o.a.merge({},{$id:t.attr(void 0),$isUpdating:t.boolean(!1),$updateErrors:t.attr([]),$isDeleting:t.boolean(!1),$deleteErrors:t.attr([])},t.fields())),t.cachedFields)),t}static transformParams(t,e,n={}){let r=`${e.methodConf.http.url}${e.methodConf.methods[t].http.url}`,i=o.a.map(r.match(/(\/?)(\:)([A-z]*)/gm),t=>t.replace("/",""));return o.a.forEach(i,t=>{const e=o.a.has(n.params,t.replace(":",""))?n.params[t.replace(":","")]:"";r=r.replace(t,e).replace("//","/")}),n.query&&(r+=`?${Object.keys(n.query).map(t=>`${encodeURIComponent(t)}=${encodeURIComponent(n.query[t])}`).join("&")}`),r}static getMethod(t,e,n){const r=e.methodConf.methods[t].http.method;return r||n}}var St=n(15),$t=n.n(St);class Ft{constructor(t){return this.instance=$t.a.create(t),this.setAuthentication(t.access_token),this.instance.interceptors.response.use(e=>t.onResponse(e),e=>t.onError(e)),this.instance}setAuthentication(t){if(!t)return;const e="function"==typeof t?t():t;this.instance.defaults.headers.common.Authorization=`Bearer ${e}`}async head(t,e={}){return this.instance.head(t,e)}async get(t,e={}){return this.instance.get(t,e)}async post(t,e={},n={}){return this.instance.post(t,e,n)}async patch(t,e={},n={}){return this.instance.patch(t,e,n)}async put(t,e={},n={}){return this.instance.put(t,e,n)}async delete(t,e={}){return this.instance.delete(t,e)}}class Mt extends jt{static async call({state:t,commit:e},n={}){const r=At.getInstance().getModelFromState(t),o=jt.transformParams("$fetch",r,n),i=new Ft(r.methodConf.http)[jt.getMethod("$fetch",r,"get")](o);return this.onRequest(e),i.then(t=>this.onSuccess(e,r,t)).catch(t=>this.onError(e,t)),i}static onRequest(t){t("onRequest")}static onSuccess(t,e,n){t("onSuccess"),e.insertOrUpdate({data:n})}static onError(t,e){t("onError",e)}}class Kt extends jt{static async call({state:t,commit:e},n={}){const r=At.getInstance().getModelFromState(t),o=jt.transformParams("$get",r,n),i=new Ft(r.methodConf.http)[jt.getMethod("$get",r,"get")](o);return this.onRequest(e),i.then(t=>this.onSuccess(e,r,t)).catch(t=>this.onError(e,t)),i}static onRequest(t){t("onRequest")}static onSuccess(t,e,n){t("onSuccess"),e.insertOrUpdate({data:n})}static onError(t,e){t("onError",e)}}class Bt extends jt{static async call({state:t,commit:e},n={}){if(!n.data||"object"!=typeof n)throw new TypeError("You must include a data object in the params to send a POST request",n);const r=At.getInstance().getModelFromState(t),o=jt.transformParams("$create",r,n),i=new Ft(r.methodConf.http)[jt.getMethod("$create",r,"post")](o,n.data);return this.onRequest(e),i.then(t=>this.onSuccess(e,r,t)).catch(t=>this.onError(e,t)),i}static onRequest(t){t("onRequest")}static onSuccess(t,e,n){t("onSuccess"),e.insertOrUpdate({data:n})}static onError(t,e){t("onError",e)}}class It extends jt{static async call({state:t,commit:e},n={}){if(!n.data||"object"!=typeof n)throw new TypeError("You must include a data object in the params to send a POST request",n);const r=At.getInstance().getModelFromState(t),o=jt.transformParams("$update",r,n),i=new Ft(r.methodConf.http)[jt.getMethod("$update",r,"put")](o,n.data);return this.onRequest(r,n),i.then(t=>this.onSuccess(r,n,t)).catch(t=>this.onError(r,n,t)),i}static onRequest(t,e){t.update({where:e.params.id,data:{$isUpdating:!0,$updateErrors:[]}})}static onSuccess(t,e,n){t.update({where:e.params.id||n.id,data:o.a.merge({},n,{$isUpdating:!1,$updateErrors:[]})})}static onError(t,e,n){t.update({where:e.params.id,data:{$isUpdating:!1,$updateErrors:n}})}}class Pt extends jt{static async call({state:t,commit:e},n={}){const r=At.getInstance().getModelFromState(t),o=jt.transformParams("$delete",r,n),i=new Ft(r.methodConf.http)[jt.getMethod("$delete",r,"delete")](o);return this.onRequest(r,n),i.then(t=>this.onSuccess(r,n,t)).catch(t=>this.onError(r,n,t)),i}static onRequest(t,e){t.update({where:e.params.id,data:{$isDeleting:!0,$deleteErrors:[]}})}static onSuccess(t,e,n){t.delete({where:e.params.id||n.id})}static onError(t,e,n){t.update({where:e.params.id,data:{$isDeleting:!1,$deleteErrors:n}})}}class Tt{constructor(t,e){At.setup(t,e),this.setupActions(),this.setupModels()}setupActions(){const t=At.getInstance();t.components.Actions.$fetch=Mt.call.bind(Mt),t.components.Actions.$get=Kt.call.bind(Kt),t.components.Actions.$create=Bt.call.bind(Bt),t.components.Actions.$update=It.call.bind(It),t.components.Actions.$delete=Pt.call.bind(Pt)}setupModels(){const t=At.getInstance();_.map(t.database.entities,t=>(t.module=jt.transformModule(t.module),t.model=jt.transformModel(t.model),t)),t.components.Model.$fetch=function(t={}){return this.dispatch("$fetch",t)},t.components.Model.$get=function(t={}){return this.dispatch("$get",t)},t.components.Model.$create=function(t={}){return this.dispatch("$create",t)},t.components.Model.$update=function(t={}){return this.dispatch("$update",t)},t.components.Model.$delete=function(t={}){return this.dispatch("$delete",t)}}}n.d(e,"default",function(){return Ut});class Ut{static install(t,e){return new Tt(t,e)}}}])}); \ No newline at end of file diff --git a/package.json b/package.json index 661f58c..fb1bbd8 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@vuex-orm/plugin-axios", - "version": "0.3.0", + "version": "0.4.0", "description": "Vuex-ORM Plugin to sync the data against a RESTful API.", "main": "dist/index.js", "scripts": {