UNPKG

@vuex-orm/core

Version:

The Vuex plugin to enable Object-Relational Mapping access to the Vuex Store.

1 lines 73.7 kB
var VuexORM=function(){"use strict";function t(t,e,n){return t(n={path:e,exports:{},require:function(t,e){return function(){throw new Error("Dynamic requires are not currently supported by @rollup/plugin-commonjs")}(null==e&&n.path)}},n.exports),n.exports}var e=t((function(t){var e=t.exports="undefined"!=typeof window&&window.Math==Math?window:"undefined"!=typeof self&&self.Math==Math?self:Function("return this")();"number"==typeof __g&&(__g=e)})),n=t((function(t){var e=t.exports={version:"2.6.12"};"number"==typeof __e&&(__e=e)})),r=function(t){return"object"==typeof t?null!==t:"function"==typeof t},i=function(t){if(!r(t))throw TypeError(t+" is not an object!");return t},o=function(t){try{return!!t()}catch(t){return!0}},u=!o((function(){return 7!=Object.defineProperty({},"a",{get:function(){return 7}}).a})),a=e.document,s=r(a)&&r(a.createElement),c=function(t){return s?a.createElement(t):{}},h=!u&&!o((function(){return 7!=Object.defineProperty(c("div"),"a",{get:function(){return 7}}).a})),f=Object.defineProperty,l={f:u?Object.defineProperty:function(t,e,n){if(i(t),e=function(t,e){if(!r(t))return t;var n,i;if(e&&"function"==typeof(n=t.toString)&&!r(i=n.call(t)))return i;if("function"==typeof(n=t.valueOf)&&!r(i=n.call(t)))return i;if(!e&&"function"==typeof(n=t.toString)&&!r(i=n.call(t)))return i;throw TypeError("Can't convert object to primitive value")}(e,!0),i(n),h)try{return f(t,e,n)}catch(t){}if("get"in n||"set"in n)throw TypeError("Accessors not supported!");return"value"in n&&(t[e]=n.value),t}},d=function(t,e){return{enumerable:!(1&t),configurable:!(2&t),writable:!(4&t),value:e}},p=u?function(t,e,n){return l.f(t,e,d(1,n))}:function(t,e,n){return t[e]=n,t},y={}.hasOwnProperty,v=function(t,e){return y.call(t,e)},m=0,g=Math.random(),b=function(t){return"Symbol(".concat(void 0===t?"":t,")_",(++m+g).toString(36))},w=t((function(t){var r="__core-js_shared__",i=e[r]||(e[r]={});(t.exports=function(t,e){return i[t]||(i[t]=void 0!==e?e:{})})("versions",[]).push({version:n.version,mode:"global",copyright:"© 2020 Denis Pushkarev (zloirock.ru)"})})),O=w("native-function-to-string",Function.toString),K=t((function(t){var r=b("src"),i="toString",o=(""+O).split(i);n.inspectSource=function(t){return O.call(t)},(t.exports=function(t,n,i,u){var a="function"==typeof i;a&&(v(i,"name")||p(i,"name",n)),t[n]!==i&&(a&&(v(i,r)||p(i,r,t[n]?""+t[n]:o.join(String(n)))),t===e?t[n]=i:u?t[n]?t[n]=i:p(t,n,i):(delete t[n],p(t,n,i)))})(Function.prototype,i,(function(){return"function"==typeof this&&this[r]||O.call(this)}))})),R=function(t,e,n){if(function(t){if("function"!=typeof t)throw TypeError(t+" is not a function!")}(t),void 0===e)return t;switch(n){case 1:return function(n){return t.call(e,n)};case 2:return function(n,r){return t.call(e,n,r)};case 3:return function(n,r,i){return t.call(e,n,r,i)}}return function(){return t.apply(e,arguments)}},k=function(t,r,i){var o,u,a,s,c=t&k.F,h=t&k.G,f=t&k.S,l=t&k.P,d=t&k.B,y=h?e:f?e[r]||(e[r]={}):(e[r]||{}).prototype,v=h?n:n[r]||(n[r]={}),m=v.prototype||(v.prototype={});for(o in h&&(i=r),i)a=((u=!c&&y&&void 0!==y[o])?y:i)[o],s=d&&u?R(a,e):l&&"function"==typeof a?R(Function.call,a):a,y&&K(y,o,a,t&k.U),v[o]!=a&&p(v,o,s),l&&m[o]!=a&&(m[o]=a)};e.core=n,k.F=1,k.G=2,k.S=4,k.P=8,k.B=16,k.W=32,k.U=64,k.R=128;var I=k,M={}.toString,$=function(t){return M.call(t).slice(8,-1)},F=Object("z").propertyIsEnumerable(0)?Object:function(t){return"String"==$(t)?t.split(""):Object(t)},S=function(t){if(null==t)throw TypeError("Can't call method on "+t);return t},A=function(t){return F(S(t))},E=Math.ceil,x=Math.floor,j=function(t){return isNaN(t=+t)?0:(t>0?x:E)(t)},P=Math.min,C=function(t){return t>0?P(j(t),9007199254740991):0},_=Math.max,B=Math.min,T=function(t){return function(e,n,r){var i,o=A(e),u=C(o.length),a=function(t,e){return(t=j(t))<0?_(t+e,0):B(t,e)}(r,u);if(t&&n!=n){for(;u>a;)if((i=o[a++])!=i)return!0}else for(;u>a;a++)if((t||a in o)&&o[a]===n)return t||a||0;return!t&&-1}},H=t((function(t){var n=w("wks"),r=e.Symbol,i="function"==typeof r;(t.exports=function(t){return n[t]||(n[t]=i&&r[t]||(i?r:b)("Symbol."+t))}).store=n})),z=H("unscopables"),U=Array.prototype;null==U[z]&&p(U,z,{});var N=function(t){U[z][t]=!0},V=T(!0);I(I.P,"Array",{includes:function(t){return V(this,t,arguments.length>1?arguments[1]:void 0)}}),N("includes"),n.Array.includes;var D=w("keys"),W=function(t){return D[t]||(D[t]=b(t))},L=T(!1),G=W("IE_PROTO"),q="constructor,hasOwnProperty,isPrototypeOf,propertyIsEnumerable,toLocaleString,toString,valueOf".split(","),Q=Object.keys||function(t){return function(t,e){var n,r=A(t),i=0,o=[];for(n in r)n!=G&&v(r,n)&&o.push(n);for(;e.length>i;)v(r,n=e[i++])&&(~L(o,n)||o.push(n));return o}(t,q)},J={f:Object.getOwnPropertySymbols},Y={f:{}.propertyIsEnumerable},X=function(t){return Object(S(t))},Z=Object.assign,tt=!Z||o((function(){var t={},e={},n=Symbol(),r="abcdefghijklmnopqrst";return t[n]=7,r.split("").forEach((function(t){e[t]=t})),7!=Z({},t)[n]||Object.keys(Z({},e)).join("")!=r}))?function(t,e){for(var n=X(t),r=arguments.length,i=1,o=J.f,a=Y.f;r>i;)for(var s,c=F(arguments[i++]),h=o?Q(c).concat(o(c)):Q(c),f=h.length,l=0;f>l;)s=h[l++],u&&!a.call(c,s)||(n[s]=c[s]);return n}:Z;I(I.S+I.F,"Object",{assign:tt}),n.Object.assign;var et=Y.f,nt=function(t){return function(e){for(var n,r=A(e),i=Q(r),o=i.length,a=0,s=[];o>a;)n=i[a++],u&&!et.call(r,n)||s.push(t?[n,r[n]]:r[n]);return s}},rt=nt(!0);I(I.S,"Object",{entries:function(t){return rt(t)}}),n.Object.entries;var it=nt(!1);I(I.S,"Object",{values:function(t){return it(t)}}),n.Object.values;var ot=H("match"),ut=function(t,e,n){if(r(i=e)&&(void 0!==(o=i[ot])?o:"RegExp"==$(i)))throw TypeError("String#"+n+" doesn't accept regex!");var i,o;return String(S(t))},at=H("match"),st="startsWith",ct="".startsWith;I(I.P+I.F*function(t){var e=/./;try{"/./"[t](e)}catch(n){try{return e[at]=!1,!"/./"[t](e)}catch(t){}}return!0}(st),"String",{startsWith:function(t){var e=ut(this,t,st),n=C(Math.min(arguments.length>1?arguments[1]:void 0,e.length)),r=String(t);return ct?ct.call(e,r,n):e.slice(n,n+r.length)===r}}),n.String.startsWith;var ht={},ft=u?Object.defineProperties:function(t,e){i(t);for(var n,r=Q(e),o=r.length,u=0;o>u;)l.f(t,n=r[u++],e[n]);return t},lt=e.document,dt=lt&&lt.documentElement,pt=W("IE_PROTO"),yt=function(){},vt=function(){var t,e=c("iframe"),n=q.length;for(e.style.display="none",dt.appendChild(e),e.src="javascript:",(t=e.contentWindow.document).open(),t.write("<script>document.F=Object<\/script>"),t.close(),vt=t.F;n--;)delete vt.prototype[q[n]];return vt()},mt=Object.create||function(t,e){var n;return null!==t?(yt.prototype=i(t),n=new yt,yt.prototype=null,n[pt]=t):n=vt(),void 0===e?n:ft(n,e)},gt=l.f,bt=H("toStringTag"),wt=function(t,e,n){t&&!v(t=n?t:t.prototype,bt)&&gt(t,bt,{configurable:!0,value:e})},Ot={};p(Ot,H("iterator"),(function(){return this}));var Kt,Rt=function(t,e,n){t.prototype=mt(Ot,{next:d(1,n)}),wt(t,e+" Iterator")},kt=W("IE_PROTO"),It=Object.prototype,Mt=Object.getPrototypeOf||function(t){return t=X(t),v(t,kt)?t[kt]:"function"==typeof t.constructor&&t instanceof t.constructor?t.constructor.prototype:t instanceof Object?It:null},$t=H("iterator"),Ft=!([].keys&&"next"in[].keys()),St="keys",At="values",Et=function(){return this},xt=(Kt=!0,function(t,e){var n,r,i=String(S(t)),o=j(e),u=i.length;return o<0||o>=u?Kt?"":void 0:(n=i.charCodeAt(o))<55296||n>56319||o+1===u||(r=i.charCodeAt(o+1))<56320||r>57343?Kt?i.charAt(o):n:Kt?i.slice(o,o+2):r-56320+(n-55296<<10)+65536});!function(t,e,n,r,i,o,u){Rt(n,e,r);var a,s,c,h=function(t){if(!Ft&&t in y)return y[t];switch(t){case St:case At:return function(){return new n(this,t)}}return function(){return new n(this,t)}},f=e+" Iterator",l=i==At,d=!1,y=t.prototype,v=y[$t]||y["@@iterator"]||i&&y[i],m=v||h(i),g=i?l?h("entries"):m:void 0,b="Array"==e&&y.entries||v;if(b&&(c=Mt(b.call(new t)))!==Object.prototype&&c.next&&(wt(c,f,!0),"function"!=typeof c[$t]&&p(c,$t,Et)),l&&v&&v.name!==At&&(d=!0,m=function(){return v.call(this)}),(Ft||d||!y[$t])&&p(y,$t,m),ht[e]=m,ht[f]=Et,i)if(a={values:l?m:h(At),keys:o?m:h(St),entries:g},u)for(s in a)s in y||K(y,s,a[s]);else I(I.P+I.F*(Ft||d),e,a)}(String,"String",(function(t){this._t=String(t),this._i=0}),(function(){var t,e=this._t,n=this._i;return n>=e.length?{value:void 0,done:!0}:(t=xt(e,n),this._i+=t.length,{value:t,done:!1})}));var jt=function(t,e,n,r){try{return r?e(i(n)[0],n[1]):e(n)}catch(e){var o=t.return;throw void 0!==o&&i(o.call(t)),e}},Pt=H("iterator"),Ct=Array.prototype,_t=function(t){return void 0!==t&&(ht.Array===t||Ct[Pt]===t)},Bt=function(t,e,n){e in t?l.f(t,e,d(0,n)):t[e]=n},Tt=H("toStringTag"),Ht="Arguments"==$(function(){return arguments}()),zt=H("iterator"),Ut=n.getIteratorMethod=function(t){if(null!=t)return t[zt]||t["@@iterator"]||ht[function(t){var e,n,r;return void 0===t?"Undefined":null===t?"Null":"string"==typeof(n=function(t,e){try{return t[e]}catch(t){}}(e=Object(t),Tt))?n:Ht?$(e):"Object"==(r=$(e))&&"function"==typeof e.callee?"Arguments":r}(t)]},Nt=H("iterator"),Vt=!1;try{var Dt=[7][Nt]();Dt.return=function(){Vt=!0},Array.from(Dt,(function(){throw 2}))}catch(t){}I(I.S+I.F*!function(t,e){if(!e&&!Vt)return!1;var n=!1;try{var r=[7],i=r[Nt]();i.next=function(){return{done:n=!0}},r[Nt]=function(){return i},t(r)}catch(t){}return n}((function(t){Array.from(t)})),"Array",{from:function(t){var e,n,r,i,o=X(t),u="function"==typeof this?this:Array,a=arguments.length,s=a>1?arguments[1]:void 0,c=void 0!==s,h=0,f=Ut(o);if(c&&(s=R(s,a>2?arguments[2]:void 0,2)),null==f||u==Array&&_t(f))for(n=new u(e=C(o.length));e>h;h++)Bt(n,h,c?s(o[h],h):o[h]);else for(i=f.call(o),n=new u;!(r=i.next()).done;h++)Bt(n,h,c?jt(i,s,[r.value,h],!0):r.value);return n.length=h,n}}),n.Array.from;var Wt=Array.isArray||function(t){return"Array"==$(t)},Lt=H("species"),Gt=function(t,e){return new(function(t){var e;return Wt(t)&&("function"!=typeof(e=t.constructor)||e!==Array&&!Wt(e.prototype)||(e=void 0),r(e)&&null===(e=e[Lt])&&(e=void 0)),void 0===e?Array:e}(t))(e)},qt=function(t,e){var n=1==t,r=2==t,i=3==t,o=4==t,u=6==t,a=5==t||u,s=e||Gt;return function(e,c,h){for(var f,l,d=X(e),p=F(d),y=R(c,h,3),v=C(p.length),m=0,g=n?s(e,v):r?s(e,0):void 0;v>m;m++)if((a||m in p)&&(l=y(f=p[m],m,d),t))if(n)g[m]=l;else if(l)switch(t){case 3:return!0;case 5:return f;case 6:return m;case 2:g.push(f)}else if(o)return!1;return u?-1:i||o?o:g}}(5),Qt="find",Jt=!0;Qt in[]&&Array(1).find((function(){Jt=!1})),I(I.P+I.F*Jt,"Array",{find:function(t){return qt(this,t,arguments.length>1?arguments[1]:void 0)}}),N(Qt),n.Array.find;var Yt=function(){function t(){}return t.register=function(t){this.store=t},t}(),Xt=function(t,e){return(Xt=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var n in e)Object.prototype.hasOwnProperty.call(e,n)&&(t[n]=e[n])})(t,e)};function Zt(t,e){function n(){this.constructor=t}Xt(t,e),t.prototype=null===e?Object.create(e):(n.prototype=e.prototype,new n)}var te=function(){return(te=Object.assign||function(t){for(var e,n=1,r=arguments.length;n<r;n++)for(var i in e=arguments[n])Object.prototype.hasOwnProperty.call(e,i)&&(t[i]=e[i]);return t}).apply(this,arguments)};function ee(t,e,n,r){return new(n||(n=Promise))((function(i,o){function u(t){try{s(r.next(t))}catch(t){o(t)}}function a(t){try{s(r.throw(t))}catch(t){o(t)}}function s(t){t.done?i(t.value):function(t){return t instanceof n?t:new n((function(e){e(t)}))}(t.value).then(u,a)}s((r=r.apply(t,e||[])).next())}))}function ne(t,e){var n,r,i,o,u={label:0,sent:function(){if(1&i[0])throw i[1];return i[1]},trys:[],ops:[]};return o={next:a(0),throw:a(1),return:a(2)},"function"==typeof Symbol&&(o[Symbol.iterator]=function(){return this}),o;function a(o){return function(a){return function(o){if(n)throw new TypeError("Generator is already executing.");for(;u;)try{if(n=1,r&&(i=2&o[0]?r.return:o[0]?r.throw||((i=r.return)&&i.call(r),0):r.next)&&!(i=i.call(r,o[1])).done)return i;switch(r=0,i&&(o=[2&o[0],i.value]),o[0]){case 0:case 1:i=o;break;case 4:return u.label++,{value:o[1],done:!1};case 5:u.label++,r=o[1],o=[0];continue;case 7:o=u.ops.pop(),u.trys.pop();continue;default:if(!(i=u.trys,(i=i.length>0&&i[i.length-1])||6!==o[0]&&2!==o[0])){u=0;continue}if(3===o[0]&&(!i||o[1]>i[0]&&o[1]<i[3])){u.label=o[1];break}if(6===o[0]&&u.label<i[1]){u.label=i[1],i=o;break}if(i&&u.label<i[2]){u.label=i[2],u.ops.push(o);break}i[2]&&u.ops.pop(),u.trys.pop();continue}o=e.call(t,u)}catch(t){o=[6,t],r=0}finally{n=i=0}if(5&o[0])throw o[1];return{value:o[0]?o[1]:void 0,done:!0}}([o,a])}}}function re(){for(var t=0,e=0,n=arguments.length;e<n;e++)t+=arguments[e].length;var r=Array(t),i=0;for(e=0;e<n;e++)for(var o=arguments[e],u=0,a=o.length;u<a;u++,i++)r[i]=o[u];return r}function ie(t){return Array.isArray(t)}function oe(t){return ie(t)?t.length:Object.keys(t).length}function ue(t,e){var n=Object.assign({},t);return Object.keys(t).reduce((function(n,r){return n[r]=e(t[r],r,t),n}),n)}function ae(t,e){if(t!==e){var n=void 0!==t,r=null===t,i=t==t,o=void 0!==e,u=null===e,a=e==e;if("number"==typeof t&&"number"==typeof e||(t=String(t),e=String(e)),!u&&t>e||r&&o&&a||!n&&a||!i)return 1;if(!r&&t<e||u&&n&&i||!o&&i||!a)return-1}return 0}var se={isArray:ie,size:oe,isEmpty:function(t){return 0===oe(t)},forOwn:function(t,e){Object.keys(t).forEach((function(n){return e(t[n],n,t)}))},map:function(t,e){var n=[];for(var r in t)n.push(e(t[r],r,t));return n},mapValues:ue,keyBy:function(t,e){var n={};return t.forEach((function(t){n[t[e]]=t})),n},orderBy:function(t,e,n){var r=-1;return function(t,e){var n=t.length;t.sort(e);var r=[];for(;n--;)r[n]=t[n].value;return r}(t.map((function(t){return{criteria:e.map((function(e){return"function"==typeof e?e(t):t[e]})),index:++r,value:t}})),(function(t,e){return function(t,e,n){var r=-1,i=t.criteria,o=e.criteria,u=i.length,a=n.length;for(;++r<u;){var s=ae(i[r],o[r]);if(s)return r>=a?s:s*("desc"===n[r]?-1:1)}return t.index-e.index}(t,e,n)}))},groupBy:function(t,e){return t.reduce((function(t,n){var r=e(n);return void 0===t[r]&&(t[r]=[]),t[r].push(n),t}),{})},cloneDeep:function t(e){if(null===e)return e;if(ie(e)){var n=[];return e.forEach((function(t){return n.push(t)})),n.map((function(e){return t(e)}))}if("object"==typeof e&&e!=={}){var r=te({},e);return Object.keys(r).forEach((function(e){return r[e]=t(r[e])})),r}return e}},ce=function(){function t(){}return t.make=function(){return this.count++,""+this.prefix+this.count},t.reset=function(){this.count=0},t.count=0,t.prefix="$uid",t}(),he=function(t){this.model=t},fe=function(t){function e(e,n,r){var i=t.call(this,e)||this;return i.isNullable=!1,i.value=n,i.mutator=r,i}return Zt(e,t),e.prototype.nullable=function(){return this.isNullable=!0,this},e.prototype.mutate=function(t,e){var n=this.mutator||this.model.mutators()[e];return n?n(t):t},e}(he),le=function(t){function e(e,n,r){return t.call(this,e,n,r)||this}return Zt(e,t),e.prototype.make=function(t,e,n){var r=t=void 0!==t?t:this.value;return"function"==typeof t&&(r=t()),this.mutate(r,n)},e}(fe),de=function(t){function e(e,n,r){return t.call(this,e,n,r)||this}return Zt(e,t),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||null===t&&this.isNullable?t:t+""},e}(fe),pe=function(t){function e(e,n,r){return t.call(this,e,n,r)||this}return Zt(e,t),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}(fe),ye=function(t){function e(e,n,r){return t.call(this,e,n,r)||this}return Zt(e,t),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}(fe),ve=function(t){function e(e,n){return t.call(this,e,n)||this}return Zt(e,t),e.prototype.make=function(t){return"number"==typeof t||"string"==typeof t?t:"function"==typeof this.value?this.value():ce.make()},e}(fe),me=function(t){function e(){return null!==t&&t.apply(this,arguments)||this}return Zt(e,t),e.prototype.getRelation=function(t,e,n){var r=t.newQuery(e);return n.forEach((function(t){t(r)})),r},e.prototype.getKeys=function(t,e){return t.reduce((function(t,n){return null===n[e]||void 0===n[e]||t.push(n[e]),t}),[])},e.prototype.mapSingleRelations=function(t,e){var n=new Map;return t.forEach((function(t){var r=t[e];!n.get(r)&&n.set(r,t)})),n},e.prototype.mapManyRelations=function(t,e){var n=new Map;return t.forEach((function(t){var r=t[e],i=n.get(r);i||(i=[],n.set(r,i)),i.push(t)})),n},e.prototype.mapRelationsByOrders=function(t,e,n,r){var i={};return e.forEach((function(e,o){t.filter((function(t){return t[r]===o})).forEach((function(t){var r=t[n];i[r]||(i[r]=[]),i[r]=i[r].concat(e)}))})),i},e.prototype.isOneRelation=function(t){return!ie(t)&&null!==t&&"object"==typeof t},e.prototype.isManyRelation=function(t){return!!ie(t)&&!(t.length<1)},e.prototype.makeOneRelation=function(t,e){return this.isOneRelation(t)?new(e.getModelFromRecord(t)||e)(t):null},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.getModelFromRecord(t)||e)(t)})):[]},e}(he),ge=function(t){function e(e,n,r,i){var o=t.call(this,e)||this;return o.related=o.model.relation(n),o.foreignKey=r,o.localKey=i,o}return Zt(e,t),e.prototype.define=function(t){return t.one(this.related)},e.prototype.attach=function(t,e,n){e[this.localKey]||(e[this.localKey]=this.model.getIndexIdFromRecord(e));var r=n[this.related.entity]&&n[this.related.entity][t];r&&(r[this.foreignKey]=e[this.localKey])},e.prototype.make=function(t,e,n){return this.makeOneRelation(t,this.related)},e.prototype.load=function(t,e,n,r){var i=this.getRelation(t,this.related.entity,r);this.addEagerConstraints(i,e),this.match(e,i.get(),n)},e.prototype.addEagerConstraints=function(t,e){t.whereFk(this.foreignKey,this.getKeys(e,this.localKey))},e.prototype.match=function(t,e,n){var r=this,i=this.buildDictionary(e);t.forEach((function(t){var e=t[r.localKey],o=i[e];t[n]=o||null}))},e.prototype.buildDictionary=function(t){var e=this;return t.reduce((function(t,n){return t[n[e.foreignKey]]=n,t}),{})},e}(me),be=function(t){function e(e,n,r,i){var o=t.call(this,e)||this;return o.parent=o.model.relation(n),o.foreignKey=r,o.ownerKey=i,o}return Zt(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]=n[this.parent.entity]&&n[this.parent.entity][t]?n[this.parent.entity][t][this.ownerKey]:t)},e.prototype.make=function(t,e,n){return this.makeOneRelation(t,this.parent)},e.prototype.load=function(t,e,n,r){var i=this.getRelation(t,this.parent.entity,r);this.addEagerConstraints(i,e),this.match(e,i.get(),n)},e.prototype.addEagerConstraints=function(t,e){t.whereFk(this.ownerKey,this.getKeys(e,this.foreignKey))},e.prototype.match=function(t,e,n){var r=this,i=this.buildDictionary(e);t.forEach((function(t){var e=t[r.foreignKey],o=null!==e?i[e]:null;t[n]=o||null}))},e.prototype.buildDictionary=function(t){var e=this;return t.reduce((function(t,n){return t[n[e.ownerKey]]=n,t}),{})},e}(me),we=function(t){function e(e,n,r,i){var o=t.call(this,e)||this;return o.related=o.model.relation(n),o.foreignKey=r,o.localKey=i,o}return Zt(e,t),e.prototype.define=function(t){return t.many(this.related)},e.prototype.attach=function(t,e,n){var r=this;t.forEach((function(t){var i=n[r.related.entity];i&&i[t]&&void 0===i[t][r.foreignKey]&&(i[t][r.foreignKey]=e[r.localKey])}))},e.prototype.make=function(t,e,n){return this.makeManyRelation(t,this.related)},e.prototype.load=function(t,e,n,r){var i=this.getRelation(t,this.related.entity,r);this.addEagerConstraints(i,e),this.match(e,i.get(),n)},e.prototype.addEagerConstraints=function(t,e){t.whereFk(this.foreignKey,this.getKeys(e,this.localKey))},e.prototype.match=function(t,e,n){var r=this,i=this.buildDictionary(e);t.forEach((function(t){var e=t[r.localKey],o=i[e];t[n]=o||[]}))},e.prototype.buildDictionary=function(t){var e=this;return t.reduce((function(t,n){var r=n[e.foreignKey];return t[r]||(t[r]=[]),t[r].push(n),t}),{})},e}(me),Oe=function(t){function e(e,n,r,i){var o=t.call(this,e)||this;return o.parent=o.model.relation(n),o.foreignKey=r,o.ownerKey=i,o}return Zt(e,t),e.prototype.define=function(t){return t.many(this.parent)},e.prototype.attach=function(t,e,n){var r=this;0!==t.length&&(e[this.foreignKey]=t.map((function(t){return r.parent.getIdFromRecord(n[r.parent.entity][t])})))},e.prototype.make=function(t,e,n){return this.makeManyRelation(t,this.parent)},e.prototype.load=function(t,e,n,r){var i=this,o=this.getRelation(t,this.parent.entity,r);this.addConstraintForHasManyBy(o,e);var u=this.mapSingleRelations(o.get(),this.ownerKey);e.forEach((function(t){var e=i.getRelatedRecords(u,t[i.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){var n=[];return t.forEach((function(t,r){-1!==e.indexOf(r)&&n.push(t)})),n},e}(me),Ke=function(t){function e(e,n,r,i,o,u,a){var s=t.call(this,e)||this;return s.related=s.model.relation(n),s.through=s.model.relation(r),s.firstKey=i,s.secondKey=o,s.localKey=u,s.secondLocalKey=a,s}return Zt(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,r){var i=this,o=this.getRelation(t,this.related.entity,r),u=t.newQuery(this.through.entity);this.addEagerConstraintForThrough(u,e);var a=u.get();this.addEagerConstraintForRelated(o,a);var s=this.mapThroughRelations(a,o);e.forEach((function(t){var e=s[t[i.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 i=e[n.firstKey];t[i]||(t[i]=[]);var o=r.get(e[n.secondLocalKey]);return void 0===o||(t[i]=t[i].concat(o)),t}),{})},e}(me),Re=function(t){function e(e,n,r,i,o,u,a){var s=t.call(this,e)||this;return s.pivotKey="pivot",s.related=s.model.relation(n),s.pivot=s.model.relation(r),s.foreignPivotKey=i,s.relatedPivotKey=o,s.parentKey=u,s.relatedKey=a,s}return Zt(e,t),e.prototype.as=function(t){return this.pivotKey=t,this},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,r){var i=this,o=this.getRelation(t,this.related.entity,r),u=t.newQuery(this.pivot.entity);this.addEagerConstraintForPivot(u,e);var a=u.get();this.addEagerConstraintForRelated(o,a);var s=this.mapPivotRelations(a,o);e.forEach((function(t){var e=s[t[i.parentKey]];t[n]=e||[]}))},e.prototype.addEagerConstraintForPivot=function(t,e){t.whereFk(this.foreignPivotKey,this.getKeys(e,this.parentKey))},e.prototype.addEagerConstraintForRelated=function(t,e){t.whereFk(this.relatedKey,this.getKeys(e,this.relatedPivotKey))},e.prototype.mapPivotRelations=function(t,e){var n=this,r=this.mapManyRelations(e.get(),this.relatedKey);return e.orders.length?this.mapRelationsByOrders(t,r,this.foreignPivotKey,this.relatedPivotKey):t.reduce((function(t,e){var i=e[n.foreignPivotKey];t[i]||(t[i]=[]);var o=r.get(e[n.relatedPivotKey]);return o&&(t[i]=t[i].concat(o.map((function(t){return t[n.pivotKey]=e,t})))),t}),{})},e.prototype.createPivots=function(t,e,n){var r=this;return se.isArray(this.pivot.primaryKey)?(se.forOwn(e[t.entity],(function(t){var i=t[n];void 0!==i&&0!==i.length&&r.createPivotRecord(e,t,i)})),e):e},e.prototype.createPivotRecord=function(t,e,n){var r=this;n.forEach((function(n){var i,o,u=e[r.parentKey],a=t[r.related.entity][n][r.relatedKey],s=JSON.stringify([r.pivot.primaryKey[0]===r.foreignPivotKey?u:a,r.pivot.primaryKey[1]===r.foreignPivotKey?u:a]),c=t[r.pivot.entity]?t[r.pivot.entity][s]:{},h=t[r.related.entity][n][r.pivotKey]||{};t[r.pivot.entity]=te(te({},t[r.pivot.entity]),((i={})[s]=te(te(te({},c),h),((o={$id:s})[r.foreignPivotKey]=u,o[r.relatedPivotKey]=a,o)),i))}))},e}(me),ke=function(t){function e(e,n,r){var i=t.call(this,e)||this;return i.id=n,i.type=r,i}return Zt(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){var r=e[this.type];try{var i=this.model.relation(r);return this.makeOneRelation(t,i)}catch(t){return null}},e.prototype.load=function(t,e,n,r){var i=this,o=this.getTypes(e).reduce((function(e,n){var o=i.getRelation(t,n,r);return e[n]=i.mapSingleRelations(o.get(),"$id"),e}),{});e.forEach((function(t){var e=t[i.id],r=t[i.type],u=o[r].get(String(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}(me),Ie=function(t){function e(e,n,r,i,o){var u=t.call(this,e)||this;return u.related=u.model.relation(n),u.id=r,u.type=i,u.localKey=o,u}return Zt(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][t];r[this.id]=r[this.id]||this.related.getIdFromRecord(e),r[this.type]=r[this.type]||this.model.entity},e.prototype.make=function(t,e,n){return this.makeOneRelation(t,this.related)},e.prototype.load=function(t,e,n,r){var i=this,o=this.getRelation(t,this.related.entity,r);this.addEagerConstraintForMorphOne(o,e,t.entity);var u=this.mapSingleRelations(o.get(),this.id);e.forEach((function(t){var e=u.get(t[i.localKey]);t[n]=e||null}))},e.prototype.addEagerConstraintForMorphOne=function(t,e,n){t.whereFk(this.type,n).whereFk(this.id,this.getKeys(e,this.localKey))},e}(me),Me=function(t){function e(e,n,r,i,o){var u=t.call(this,e)||this;return u.related=u.model.relation(n),u.id=r,u.type=i,u.localKey=o,u}return Zt(e,t),e.prototype.define=function(t){return t.many(this.related)},e.prototype.attach=function(t,e,n){var r=this,i=n[this.related.entity];t.forEach((function(t){var n=i[t];n[r.id]=n[r.id]||r.related.getIdFromRecord(e),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,r){var i=this,o=this.getRelation(t,this.related.entity,r);this.addEagerConstraintForMorphMany(o,e,t.entity);var u=this.mapManyRelations(o.get(),this.id);e.forEach((function(t){var e=u.get(t[i.localKey]);t[n]=e||[]}))},e.prototype.addEagerConstraintForMorphMany=function(t,e,n){t.whereFk(this.type,n).whereFk(this.id,this.getKeys(e,this.localKey))},e}(me),$e=function(t){function e(e,n,r,i,o,u,a,s){var c=t.call(this,e)||this;return c.pivotKey="pivot",c.related=c.model.relation(n),c.pivot=c.model.relation(r),c.relatedId=i,c.id=o,c.type=u,c.parentKey=a,c.relatedKey=s,c}return Zt(e,t),e.prototype.as=function(t){return this.pivotKey=t,this},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,r){var i=this,o=this.getRelation(t,this.related.entity,r),u=t.newQuery(this.pivot.entity);this.addEagerConstraintForPivot(u,e,t.entity);var a=u.get();this.addEagerConstraintForRelated(o,a);var s=this.mapPivotRelations(a,o);e.forEach((function(t){var e=s[t[i.parentKey]];t[n]=e||[]}))},e.prototype.addEagerConstraintForPivot=function(t,e,n){t.whereFk(this.type,n).whereFk(this.id,this.getKeys(e,this.parentKey))},e.prototype.addEagerConstraintForRelated=function(t,e){t.whereFk(this.relatedKey,this.getKeys(e,this.relatedId))},e.prototype.mapPivotRelations=function(t,e){var n=this,r=this.mapManyRelations(e.get(),this.relatedKey);return e.orders.length?this.mapRelationsByOrders(t,r,this.id,this.relatedId):t.reduce((function(t,e){var i=e[n.id];t[i]||(t[i]=[]);var o=r.get(e[n.relatedId]);return void 0===o||0===o.length||(t[i]=t[i].concat(o.map((function(t){return t[n.pivotKey]=e,t})))),t}),{})},e.prototype.createPivots=function(t,e,n){var r=this;return se.forOwn(e[t.entity],(function(i){var o=t.query().newQuery(r.pivot.entity).where(r.id,i[r.parentKey]).where(r.type,t.entity).get(),u=(i[n]||[]).filter((function(t){return!o.includes(t)}));se.isArray(u)&&0!==u.length&&r.createPivotRecord(t,e,i,u)})),e},e.prototype.createPivotRecord=function(t,e,n,r){var i=this;r.forEach((function(r){var o,u,a=n[i.parentKey],s=e[i.related.entity][r][i.relatedKey],c=a+"_"+r+"_"+t.entity,h=e[i.related.entity][r][i.pivotKey]||{};e[i.pivot.entity]=te(te({},e[i.pivot.entity]),((o={})[c]=te(te({},h),((u={$id:c})[i.relatedId]=s,u[i.id]=a,u[i.type]=t.entity,u)),o))}))},e}(me),Fe=function(t){function e(e,n,r,i,o,u,a,s){var c=t.call(this,e)||this;return c.pivotKey="pivot",c.related=c.model.relation(n),c.pivot=c.model.relation(r),c.relatedId=i,c.id=o,c.type=u,c.parentKey=a,c.relatedKey=s,c}return Zt(e,t),e.prototype.as=function(t){return this.pivotKey=t,this},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,r){var i=this,o=this.getRelation(t,this.related.entity,r),u=t.newQuery(this.pivot.entity);this.addEagerConstraintForPivot(u,e,this.related.entity);var a=u.get();this.addEagerConstraintForRelated(o,a);var s=this.mapPivotRelations(a,o);e.forEach((function(t){var e=s[t[i.parentKey]];t[n]=e||[]}))},e.prototype.addEagerConstraintForPivot=function(t,e,n){t.whereFk(this.type,n).whereFk(this.relatedId,this.getKeys(e,this.parentKey))},e.prototype.addEagerConstraintForRelated=function(t,e){t.whereFk(this.relatedKey,this.getKeys(e,this.id))},e.prototype.mapPivotRelations=function(t,e){var n=this,r=this.mapManyRelations(e.get(),this.relatedKey);return e.orders.length?this.mapRelationsByOrders(t,r,this.relatedId,this.id):t.reduce((function(t,e){var i=e[n.relatedId];t[i]||(t[i]=[]);var o=r.get(e[n.id]);return void 0===o||0===o.length||(t[i]=t[i].concat(o.map((function(t){return t[n.pivotKey]=e,t})))),t}),{})},e.prototype.createPivots=function(t,e,n){var r=this;return se.forOwn(e[t.entity],(function(t){var i=t[n];se.isArray(i)&&r.createPivotRecord(e,t,i)})),e},e.prototype.createPivotRecord=function(t,e,n){var r=this;n.forEach((function(n){var i,o,u=e[r.parentKey],a=n+"_"+u+"_"+r.related.entity,s=t[r.related.entity][n][r.pivotKey]||{};t[r.pivot.entity]=te(te({},t[r.pivot.entity]),((i={})[a]=te(te({},s),((o={$id:a})[r.relatedId]=u,o[r.id]=r.model.getIdFromRecord(t[r.related.entity][n]),o[r.type]=r.related.entity,o)),i))}))},e}(me),Se={relations:!0};function Ae(t,e){void 0===e&&(e={}),e=te(te({},Se),e);var n={},r=t.$fields();for(var i in r){var o=r[i],u=t[i];o instanceof me?n[i]=e.relations?xe(u):je(u):n[i]=Ee(t[i])}return n}function Ee(t){return null===t?null:ie(t)?t.map((function(t){return Ee(t)})):"object"==typeof t?function(t){var e={};for(var n in t)e[n]=Ee(t[n]);return e}(t):t}function xe(t){return null===t?null:ie(t)?t.map((function(t){return t.$toJson()})):t.$toJson()}function je(t){return ie(t)?[]:null}var Pe=function(){function t(t){this.$id=null,this.$fill(t)}return t.fields=function(){return{}},t.attr=function(t,e){return new le(this,t,e)},t.string=function(t,e){return new de(this,t,e)},t.number=function(t,e){return new pe(this,t,e)},t.boolean=function(t,e){return new ye(this,t,e)},t.uid=function(t){return new ve(this,t)},t.increment=function(){return this.uid()},t.hasOne=function(t,e,n){return new ge(this,t,e,this.localKey(n))},t.belongsTo=function(t,e,n){return new be(this,t,e,this.relation(t).localKey(n))},t.hasMany=function(t,e,n){return new we(this,t,e,this.localKey(n))},t.hasManyBy=function(t,e,n){return new Oe(this,t,e,this.relation(t).localKey(n))},t.hasManyThrough=function(t,e,n,r,i,o){return new Ke(this,t,e,n,r,this.localKey(i),this.relation(e).localKey(o))},t.belongsToMany=function(t,e,n,r,i,o){return new Re(this,t,e,n,r,this.localKey(i),this.relation(t).localKey(o))},t.morphTo=function(t,e){return new ke(this,t,e)},t.morphOne=function(t,e,n,r){return new Ie(this,t,e,n,this.localKey(r))},t.morphMany=function(t,e,n,r){return new Me(this,t,e,n,this.localKey(r))},t.morphToMany=function(t,e,n,r,i,o,u){return new $e(this,t,e,n,r,i,this.localKey(o),this.relation(t).localKey(u))},t.morphedByMany=function(t,e,n,r,i,o,u){return new Fe(this,t,e,n,r,i,this.localKey(o),this.relation(t).localKey(u))},t.mutators=function(){return{}},t.types=function(){return{}},t.store=function(){return Yt.store},t.database=function(){return this.store().$db()},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.getFields=function(){return this.cachedFields||(this.cachedFields={}),this.cachedFields[this.entity]||(this.cachedFields[this.entity]=this.fields()),this.cachedFields[this.entity]},t.all=function(){return this.getters("all")()},t.find=function(t){return this.getters("find")(t)},t.findIn=function(t){return this.getters("findIn")(t)},t.query=function(){return this.getters("query")()},t.exists=function(){return this.query().exists()},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.isPrimaryKey=function(t){return se.isArray(this.primaryKey)?this.primaryKey.includes(t):this.primaryKey===t},t.isCompositePrimaryKey=function(){return se.isArray(this.primaryKey)},t.getIdFromRecord=function(t){var e=this,n=this.primaryKey;if("string"==typeof n)return this.getIdFromValue(t[n]);var r=n.reduce((function(n,r){var i=e.getIdFromValue(t[r]);return null!==i&&n.push(i),n}),[]);return r.length===n.length?r:null},t.getIdFromValue=function(t){return"string"==typeof t&&""!==t||"number"==typeof t?t:null},t.getIndexIdFromRecord=function(t){var e=this.getIdFromRecord(t);return null===e?null:se.isArray(e)?JSON.stringify(e):String(e)},t.localKey=function(t){return t||("string"==typeof this.primaryKey?this.primaryKey:"id")},t.getModelFromRecord=function(t){return t instanceof this?t.$self():this.getTypeModel(t[this.typeKey])},t.relation=function(t){return"string"!=typeof t?t:this.database().model(t)},t.pivotFields=function(){var t=[];return se.forOwn(this.getFields(),(function(e,n){var r;(e instanceof Re||e instanceof $e||e instanceof Fe)&&t.push(((r={})[n]=e,r))})),t},t.hasPivotFields=function(){return this.pivotFields().length>0},t.hasTypes=function(){return Object.keys(this.types()).length>0},t.getTypeModel=function(t){var e=this.types()[t];return e||null},t.getTypeKeyValueFromModel=function(t){var e=t||this,n=this.types();for(var r in n)if(n[r].entity===e.entity)return r;return null},t.findRelationInSubTypes=function(t){var e=this.types();for(var n in e){var r=e[n].getFields();for(var i in r)if(i===t&&r[i]instanceof me)return r[i]}return null},t.hydrate=function(t){return new this(t).$getAttributes()},t.prototype.$self=function(){return this.constructor},t.prototype.$primaryKey=function(){return this.$self().primaryKey},t.prototype.$fields=function(){return this.$self().getFields()},t.prototype.$setIndexId=function(t){return this.$id=t,this},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 ee(this,void 0,void 0,(function(){return ne(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.$findIn=function(t){return this.$getters("findIn")(t)},t.prototype.$query=function(){return this.$getters("query")()},t.prototype.$create=function(t){return ee(this,void 0,void 0,(function(){return ne(this,(function(e){return[2,this.$dispatch("create",t)]}))}))},t.prototype.$insert=function(t){return ee(this,void 0,void 0,(function(){return ne(this,(function(e){return[2,this.$dispatch("insert",t)]}))}))},t.prototype.$update=function(t){return ee(this,void 0,void 0,(function(){return ne(this,(function(e){return se.isArray(t)||void 0!==t.where?[2,this.$dispatch("update",t)]:null===this.$self().getIndexIdFromRecord(t)?[2,this.$dispatch("update",{where:this.$self().getIdFromRecord(this),data:t})]:[2,this.$dispatch("update",t)]}))}))},t.prototype.$insertOrUpdate=function(t){return ee(this,void 0,void 0,(function(){return ne(this,(function(e){return[2,this.$dispatch("insertOrUpdate",t)]}))}))},t.prototype.$save=function(){return ee(this,void 0,void 0,(function(){var t,e,n,r=this;return ne(this,(function(i){switch(i.label){case 0:return t=this.$self().getFields(),e=Object.keys(t).reduce((function(e,n){return t[n]instanceof fe&&(e[n]=r[n]),e}),{}),[4,this.$dispatch("insertOrUpdate",{data:e})];case 1:return n=i.sent(),this.$fill(n[this.$self().entity][0]),[2,this]}}))}))},t.prototype.$delete=function(){return ee(this,void 0,void 0,(function(){var t,e=this;return ne(this,(function(n){return t=this.$primaryKey(),se.isArray(t)?[2,this.$dispatch("delete",(function(n){return t.every((function(t){return n[t]===e[t]}))}))]:[2,this.$dispatch("delete",this[t])]}))}))},t.prototype.$deleteAll=function(){return ee(this,void 0,void 0,(function(){return ne(this,(function(t){return[2,this.$dispatch("deleteAll")]}))}))},t.prototype.$fill=function(t){void 0===t&&(t={});var e=this.$fields();for(var n in e){var r=e[n],i=t[n];this[n]=r.make(i,t,n)}void 0!==t.$id&&this.$setIndexId(t.$id)},t.prototype.$generateId=function(){return this.$generatePrimaryId().$generateIndexId()},t.prototype.$generatePrimaryId=function(){var t=this,e=this.$self().primaryKey;return(se.isArray(e)?e:[e]).forEach((function(e){void 0!==t[e]&&null!==t[e]||(t[e]=ce.make())})),this},t.prototype.$generateIndexId=function(){return this.$setIndexId(this.$getIndexIdFromAttributes())},t.prototype.$getIndexIdFromAttributes=function(){return this.$self().getIndexIdFromRecord(this)},t.prototype.$getAttributes=function(){return(e=Ae(t=this,{relations:!1})).$id=t.$id,e;var t,e},t.prototype.$toJson=function(){return Ae(this)},t.primaryKey="id",t.typeKey="type",t.state={},t}(),Ce={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)}},findIn:function(t,e,n,r){return function(e){return r[t.$connection+"/findIn"](t.$name,e)}}};var _e={new:function(t){return ee(this,void 0,void 0,(function(){var e,n;return ne(this,(function(r){return e=t.state,n=e.$name,[2,t.dispatch(e.$connection+"/new",{entity:n},{root:!0})]}))}))},create:function(t,e){return ee(this,void 0,void 0,(function(){var n,r;return ne(this,(function(i){return n=t.state,r=n.$name,[2,t.dispatch(n.$connection+"/create",te(te({},e),{entity:r}),{root:!0})]}))}))},insert:function(t,e){return ee(this,void 0,void 0,(function(){var n,r;return ne(this,(function(i){return n=t.state,r=n.$name,[2,t.dispatch(n.$connection+"/insert",te(te({},e),{entity:r}),{root:!0})]}))}))},update:function(t,e){return ee(this,void 0,void 0,(function(){var n,r;return ne(this,(function(i){return n=t.state,r=n.$name,ie(e)||void 0===e.data?[2,t.dispatch(n.$connection+"/update",{entity:r,data:e},{root:!0})]:[2,t.dispatch(n.$connection+"/update",te({entity:r},e),{root:!0})]}))}))},insertOrUpdate:function(t,e){return ee(this,void 0,void 0,(function(){var n,r;return ne(this,(function(i){return n=t.state,r=n.$name,[2,t.dispatch(n.$connection+"/insertOrUpdate",te({entity:r},e),{root:!0})]}))}))},delete:function(t,e){return ee(this,void 0,void 0,(function(){var n,r,i;return ne(this,(function(o){return n=t.state,r=n.$name,i=e,[2,t.dispatch(n.$connection+"/delete",{entity:r,where:i},{root:!0})]}))}))},deleteAll:function(t){return ee(this,void 0,void 0,(function(){var e,n;return ne(this,(function(r){return e=t.state,n=e.$name,[2,t.dispatch(e.$connection+"/deleteAll",{entity:n},{root:!0})]}))}))}};function Be(t,e){for(var n=0;n<e.length;n++){var r=e[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(t,r.key,r)}}function Te(t,e,n){return e&&Be(t.prototype,e),n&&Be(t,n),t}function He(){return(He=Object.assign||function(t){for(var e=1;e<arguments.length;e++){var n=arguments[e];for(var r in n)Object.prototype.hasOwnProperty.call(n,r)&&(t[r]=n[r])}return t}).apply(this,arguments)}function ze(t,e){t.prototype=Object.create(e.prototype),t.prototype.constructor=t,t.__proto__=e}function Ue(t){return!(!t||"function"!=typeof t.hasOwnProperty||!(t.hasOwnProperty("__ownerID")||t._map&&t._map.hasOwnProperty("__ownerID")))}function Ne(t,e,n){return Object.keys(t).reduce((function(e,r){var i=""+r;return e.has(i)?e.set(i,n(e.get(i),t[i])):e}),e)}var Ve=function(){function t(t,e,n){if(void 0===e&&(e={}),void 0===n&&(n={}),!t||"string"!=typeof t)throw new Error("Expected a string key for Entity, but found "+t+".");var r=n,i=r.idAttribute,o=void 0===i?"id":i,u=r.mergeStrategy,a=void 0===u?function(t,e){return He({},t,e)}:u,s=r.processStrategy,c=void 0===s?function(t){return He({},t)}:s,h=r.fallbackStrategy,f=void 0===h?function(t,e){}:h;this._key=t,this._getId="function"==typeof o?o:function(t){return function(e){return Ue(e)?e.get(t):e[t]}}(o),this._idAttribute=o,this._mergeStrategy=a,this._processStrategy=c,this._fallbackStrategy=f,this.define(e)}var e=t.prototype;return e.define=function(t){this.schema=Object.keys(t).reduce((function(e,n){var r,i=t[n];return He({},e,((r={})[n]=i,r))}),this.schema||{})},e.getId=function(t,e,n){return this._getId(t,e,n)},e.merge=function(t,e){return this._mergeStrategy(t,e)},e.fallback=function(t,e){return this._fallbackStrategy(t,e)},e.normalize=function(t,e,n,r,i,o){var u=this,a=this.getId(t,e,n),s=this.key;if(s in o||(o[s]={}),a in o[s]||(o[s][a]=[]),o[s][a].some((function(e){return e===t})))return a;o[s][a].push(t);var c=this._processStrategy(t,e,n);return Object.keys(this.schema).forEach((function(e){if(c.hasOwnProperty(e)&&"object"==typeof c[e]){var n=u.schema[e],a="function"==typeof n?n(t):n;c[e]=r(c[e],c,e,a,i,o)}})),i(this,c,t,e,n),a},e.denormalize=function(t,e){var n=this;return Ue(t)?Ne(this.schema,t,e):(Object.keys(this.schema).forEach((function(r){if(t.hasOwnProperty(r)){var i=n.schema[r];t[r]=e(t[r],i)}})),t)},Te(t,[{key:"key",get:function(){return this._key}},{key:"idAttribute",get:function(){return this._idAttribute}}]),t}(),De=function(){function t(t,e){e&&(this._schemaAttribute="string"==typeof e?function(t){return t[e]}:e),this.define(t)}var e=t.prototype;return e.define=function(t){this.schema=t},e.getSchemaAttribute=function(t,e,n){return!this.isSingleSchema&&this._schemaAttribute(t,e,n)},e.inferSchema=function(t,e,n){if(this.isSingleSchema)return this.schema;var r=this.getSchemaAttribute(t,e,n);return this.schema[r]},e.normalizeValue=function(t,e,n,r,i,o){var u=this.inferSchema(t,e,n);if(!u)return t;var a=r(t,e,n,u,i,o);return this.isSingleSchema||null==a?a:{id:a,schema:this.getSchemaAttribute(t,e,n)}},e.denormalizeValue=function(t,e){var n=Ue(t)?t.get("schema"):t.schema;return this.isSingleSchema||n?e((this.isSingleSchema?void 0:Ue(t)?t.get("id"):t.id)||t,this.isSingleSchema?this.schema:this.schema[n]):t},Te(t,[{key:"isSingleSchema",get:function(){return!this._schemaAttribute}}]),t}(),We=function(t){function e(e,n){if(!n)throw new Error('Expected option "schemaAttribute" not found on UnionSchema.');return t.call(this,e,n)||this}ze(e,t);var n=e.prototype;return n.normalize=function(t,e,n,r,i,o){return this.normalizeValue(t,e,n,r,i,o)},n.denormalize=function(t,e){return this.denormalizeValue(t,e)},e}(De),Le=function(t){function e(){return t.apply(this,arguments)||this}ze(e,t);var n=e.prototype;return n.normalize=function(t,e,n,r,i,o){var u=this;return Object.keys(t).reduce((function(e,n,a){var s,c=t[n];return null!=c?He({},e,((s={})[n]=u.normalizeValue(c,t,n,r,i,o),s)):e}),{})},n.denormalize=function(t,e){var n=this;return Object.keys(t).reduce((function(r,i){var o,u=t[i];return He({},r,((o={})[i]=n.denormalizeValue(u,e),o))}),{})},e}(De),Ge=function(t){return Array.isArray(t)?t:Object.keys(t).map((function(e){return t[e]}))},qe=function(t,e,n,r,i,o,u){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),Ge(e).map((function(e,a){return i(e,n,r,t,o,u)}))},Qe=function(t){function e(){return t.apply(this,arguments)||this}ze(e,t);var n=e.prototype;return n.normalize=function(t,e,n,r,i,o){var u=this;return Ge(t).map((function(t,a){return u.normalizeValue(t,e,n,r,i,o)})).filter((function(t){return null!=t}))},n.denormalize=function(t,e){var n=this;return t&&t.map?t.map((function(t){return n.denormalizeValue(t,e)})):t},e}(De),Je=function(t,e,n,r,i,o,u){var a=He({},e);return Object.keys(t).forEach((function(n){var r=t[n],s="function"==typeof r?r(e):r,c=i(e[n],e,n,s,o,u);null==c?delete a[n]:a[n]=c})),a},Ye=function(t,e,n){if(Ue(e))return Ne(t,e,n);var r=He({},e);return Object.keys(t).forEach((function(e){null!=r[e]&&(r[e]=n(r[e],t[e]))})),r},Xe=function t(e,n,r,i,o,u){return"object"==typeof e&&e?"object"!=typeof i||i.normalize&&"function"==typeof i.normalize?i.normalize(e,n,r,t,o,u):(Array.isArray(i)?qe:Je)(i,e,n,r,t,o,u):e},Ze={Array:Qe,Entity:Ve,Object:function(){function t(t){this.define(t)}var e=t.prototype;return e.define=function(t){this.schema=Object.keys(t).reduce((function(e,n){var r,i=t[n];return He({},e,((r={})[n]=i,r))}),this.schema||{})},e.normalize=function(){for(var t=arguments.length,e=new Array(t),n=0;n<t;n++)e[n]=arguments[n];return Je.apply(void 0,[this.schema].concat(e))},e.denormalize=function(){for(var t=arguments.length,e=new Array(t),n=0;n<t;n++)e[n]=arguments[n];return Ye.apply(void 0,[this.schema].concat(e))},t}(),Union:We,Values:Le},tn=function(){function t(){}return t.process=function(t,e){if(se.isEmpty(e))return{};var n=t.database.schemas[t.model.entity];return function(t,e){if(!t||"object"!=typeof t)throw new Error('Unexpected input given to normalize. Expected type to be "object", found "'+(null===t?"null":typeof t)+'".');var n={},r=function(t){return function(e,n,r,i,o){var u=e.key,a=e.getId(r,i,o);u in t||(t[u]={});var s=t[u][a];t[u][a]=s?e.merge(s,n):n}}(n);return{entities:n,result:Xe(t,t,null,e,r,{})}}(e,se.isArray(e)?[n]:n).entities},t}(),en=function(){function t(){}return t.process=function(t,e){return Object.keys(e).forEach((function(n){var r=t.getModel(n);r.hasPivotFields()&&se.forOwn(r.pivotFields(),(function(t){se.forOwn(t,(function(t,n){t.createPivots(r,e,n)}))}))})),e},t}(),nn=function(){function t(){}return t.process=function(t,e){return se.forOwn(e,(function(n,r){var i=t.getModel(r).fields();se.forOwn(n,(function(t){se.forOwn(t,(function(n,r){var o=i[r];o instanceof me&&null!==n&&o.attach(n,t,e)}))}))})),e},t}(),rn=function(){function t(){}return t.normalize=function(t,e){var n=tn.process(t,e);return n=nn.process(t,n),n=en.process(t,n)},t}(),on=function(){function t(){}return t.filter=function(t,e){var n=this;return 0===t.wheres.length?e:e.filter((function(e){return n.check(t,e)}))},t.check=function(t,e){var n=se.groupBy(t.wheres,(function(t){return t.boolean})),r=this.getComparator(t,e),i=[];return n.and&&i.push(n.and.every(r)),n.or&&i.push(n.or.some(r)),-1!==i.indexOf(!0)},t.getComparator=function(t,e){var n=this;return function(r){if("function"==typeof r.field){var i=new fn(t.store,t.entity),o=n.executeWhereClosure(i,e,r.field);if("boolean"==typeof o)return o;var u=i.get();return!se.isEmpty(u.filter((function(t){return t.$id===e.$id})))}return"function"==typeof r.value?r.value(e[r.field]):se.isArray(r.value)?-1!==r.value.indexOf(e[r.field]):e[r.field]===r.value}},t.executeWhereClosure=function(t,e,n){if(3!==n.length)return n(e,t);var r=new t.model(e);return n(e,t,r)},t}(),un=function(){function t(){}return t.filter=function(t,e){if(0===t.orders.length)return e;var n=t.orders.map((function(t){return t.key})),r=t.orders.map((function(t){return t.direction}));return se.orderBy(e,n,r)},t}(),an=function(){function t(){}return t.filter=function(t,e){return e.slice(t.offsetNumber,t.offsetNumber+t.limitNumber)},t}(),sn=function(){function t(){}return t.where=function(t,e){return on.filter(t,e)},t.orderBy=function(t,e){return un.filter(t,e)},t.limit=function(t,e){return an.filter(t,e)},t}(),cn=function(){function t(){}return t.with=function(t,e,n){var r=this;"*"!==e?ie(e)?e.forEach((function(e){return r.with(t,e,n)})):this.parseWithRelations(t,e.split("."),n):this.withAll(t,n)},t.withAll=function(t,e){var n=t.model.getFields();for(var r in n)n[r]instanceof me&&this.with(t,r,e)},t.withAllRecursive=function(t,e){this.withAll(t,(function(t){e>0&&t.withAllRecursive(e-1)}))},t.setEagerLoad=function(t,e,n){void 0===n&&(n=null),t.load[e]||(t.load[e]=[]),n&&t.load[e].push(n)},t.parseWithRelations=function(t,e,n){var r=this,i=e[0];i.split("|").forEach((function(i){1!==e.length?