@datorama/akita
Version:
State Management Tailored-Made for JS Applications
2 lines • 51.3 kB
JavaScript
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports,require("rxjs"),require("rxjs/operators")):"function"==typeof define&&define.amd?define("@datorama/akita",["exports","rxjs","rxjs/operators"],e):e((t.datorama=t.datorama||{},t.datorama.akita={}),t.rxjs,t.rxjs.operators)}(this,function(i,s,O){"use strict";var n=function(t,e){return(n=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var i in e)e.hasOwnProperty(i)&&(t[i]=e[i])})(t,e)};function t(t,e){function i(){this.constructor=t}n(t,e),t.prototype=null===e?Object.create(e):(i.prototype=e.prototype,new i)}var w=function(){return(w=Object.assign||function(t){for(var e,i=1,n=arguments.length;i<n;i++)for(var r in e=arguments[i])Object.prototype.hasOwnProperty.call(e,r)&&(t[r]=e[r]);return t}).apply(this,arguments)};function e(t,e,i,n){var r,o=arguments.length,s=o<3?e:null===n?n=Object.getOwnPropertyDescriptor(e,i):n;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)s=Reflect.decorate(t,e,i,n);else for(var a=t.length-1;0<=a;a--)(r=t[a])&&(s=(o<3?r(s):3<o?r(e,i,s):r(e,i))||s);return 3<o&&s&&Object.defineProperty(e,i,s),s}function r(t,e){if("object"==typeof Reflect&&"function"==typeof Reflect.metadata)return Reflect.metadata(t,e)}function x(t){var e="function"==typeof Symbol&&t[Symbol.iterator],i=0;return e?e.call(t):{next:function(){return t&&i>=t.length&&(t=void 0),{value:t&&t[i++],done:!t}}}}function I(t,e){var i="function"==typeof Symbol&&t[Symbol.iterator];if(!i)return t;var n,r,o=i.call(t),s=[];try{for(;(void 0===e||0<e--)&&!(n=o.next()).done;)s.push(n.value)}catch(a){r={error:a}}finally{try{n&&!n.done&&(i=o["return"])&&i.call(o)}finally{if(r)throw r.error}}return s}function b(){for(var t=[],e=0;e<arguments.length;e++)t=t.concat(I(arguments[e]));return t}function p(t){return Array.isArray(t)}function f(t){return!!p(t)&&0===t.length}function h(t,e,i){var n,r,o={entities:{},ids:[]};try{for(var s=x(t),a=s.next();!a.done;a=s.next()){var u=i(a.value);o.entities[u[e]]=u,o.ids.push(u[e])}}catch(c){n={error:c}}finally{try{a&&!a.done&&(r=s["return"])&&r.call(s)}finally{if(n)throw n.error}}return o}function j(t,e){return t.hasOwnProperty(e)}function l(t){return t.hasOwnProperty("active")}function o(t){return p(t)}function y(t){var e=t.active,i=t.ids,n=t.entities;return o(e)?a(e,i):!1===j(n,e)?null:e}function a(t,e){var i=t.filter(function(t){return-1<e.indexOf(t)});return i.length===t.length?t:i}function d(t){return t.entities&&t.ids}function v(t,e){var i,n,r={};try{for(var o=x(Object.keys(t)),s=o.next();!s.done;s=o.next()){var a=s.value;r[a]=e(t[a])}}catch(u){i={error:u}}finally{try{s&&!s.done&&(n=o["return"])&&n.call(o)}finally{if(i)throw i.error}}return r}function u(t){var e,i,n=t.state,r=t.entities,o=t.idKey,s=t.preAddEntity,a=t.isNativePreAdd;if(p(r)){var u=h(r,o,s);e=u.entities,i=u.ids}else i=d(r)?(e=a?r.entities:v(r.entities,s),r.ids):(e=a?r:v(r,s),Object.keys(e).map(function(t){return isNaN(t)?t:Number(t)}));var c=w({},n,{entities:e,ids:i,loading:!1});return l(n)&&(c.active=y(c)),c}var c,C=(t(g,c=Error),g);function g(t){return c.call(this,t)||this}var m={type:null,entityIds:null,skip:!1},S=!1;function E(){S=!1}function P(t,e){k(t,e),S=!0}function k(t,e){!1===S&&(m.type=t,m.entityIds=e)}function _(t){void 0===t&&(t=!0),m.skip=t}function A(r,o){return function(t,e,i){var n=i.value;return i.value=function(){for(var t=[],e=0;e<arguments.length;e++)t[e]=arguments[e];return P(r,o),n.apply(this,t)},i}}var U=new s.Subject,F=new s.BehaviorSubject(!1),V={activeTransactions:0,batchTransaction:null};function N(){K()||(V.batchTransaction=new s.Subject),V.activeTransactions++,F.next(!0)}function D(){0==--V.activeTransactions&&(V.batchTransaction.next(!0),V.batchTransaction.complete(),F.next(!1),U.next(!0))}function K(){return 0<V.activeTransactions}function R(){return V.batchTransaction?V.batchTransaction.asObservable():s.of(!0)}function B(t,e){void 0===e&&(e=undefined),N();try{return t.apply(e)}finally{P("@Transaction"),D()}}function M(){return function(t,e,i){var n=i.value;return i.value=function(){for(var t=this,e=[],i=0;i<arguments.length;i++)e[i]=arguments[i];return B(function(){return n.apply(t,e)},this)},i}}function H(e){Object.freeze(e);var i="function"==typeof e,n=Object.prototype.hasOwnProperty;return Object.getOwnPropertyNames(e).forEach(function(t){!n.call(e,t)||i&&("caller"===t||"callee"===t||"arguments"===t)||null===e[t]||"object"!=typeof e[t]&&"function"!=typeof e[t]||Object.isFrozen(e[t])||H(e[t])}),e}var Q="akitaConfig";var q={resettable:!1};function $(){return q}function L(t){return null!=t&&""+t!="false"}function z(t){return L(t)&&"Object"===t.constructor.name}function J(t){return"function"==typeof t}var W=new s.Subject,X=new s.ReplaySubject(50,5e3),Y=new s.Subject;function G(t){W.next(t)}function Z(t){X.next(t)}function tt(t){Y.next(t)}function et(){return i.__DEV__}i.__DEV__=!0;var it="undefined"!=typeof window,nt="undefined"!=typeof global&&"undefined"!=typeof global.__runtimeVersion,rt=!it&&!nt,ot={},st={};it&&et()&&(window.$$stores=ot,window.$$queries=st);var at=(ut.prototype.setLoading=function(e){void 0===e&&(e=!1),e!==this._value().loading&&(et()&&k("Set Loading"),this._setState(function(t){return w({},t,{loading:e})}))},ut.prototype.setHasCache=function(t,e){var i=this;if(void 0===e&&(e={restartTTL:!1}),t!==this.cache.active.value&&this.cache.active.next(t),e.restartTTL){var n=this.cacheConfig&&this.cacheConfig.ttl;n&&(null!==this.cache.ttl&&clearTimeout(this.cache.ttl),this.cache.ttl=setTimeout(function(){return i.setHasCache(!1)},n))}},ut.prototype.setError=function(e){e!==this._value().error&&(et()&&k("Set Error"),this._setState(function(t){return w({},t,{error:e})}))},ut.prototype._select=function(t){return this.store.asObservable().pipe(O.map(t),O.distinctUntilChanged())},ut.prototype._value=function(){return this.storeValue},ut.prototype._cache=function(){return this.cache.active},Object.defineProperty(ut.prototype,"config",{get:function(){return this.constructor[Q]||{}},enumerable:!0,configurable:!0}),Object.defineProperty(ut.prototype,"storeName",{get:function(){return this.config.storeName||this.options.storeName||this.options.name},enumerable:!0,configurable:!0}),Object.defineProperty(ut.prototype,"deepFreeze",{get:function(){return this.config.deepFreezeFn||this.options.deepFreezeFn||H},enumerable:!0,configurable:!0}),Object.defineProperty(ut.prototype,"cacheConfig",{get:function(){return this.config.cache||this.options.cache},enumerable:!0,configurable:!0}),Object.defineProperty(ut.prototype,"resettable",{get:function(){return this.config.resettable||this.options.resettable},enumerable:!0,configurable:!0}),ut.prototype._setState=function(t,e){void 0===e&&(e=!0),this.storeValue=i.__DEV__?this.deepFreeze(t(this._value())):t(this._value()),this.store?K()?this.handleTransaction():this.dispatch(this.storeValue,e):this.store=new s.BehaviorSubject(this.storeValue)},ut.prototype.reset=function(){var t=this;this.isResettable()?(et()&&k("Reset"),this._setState(function(){return Object.assign({},t._initialState)}),this.setHasCache(!1)):et()&&console.warn("You need to enable the reset functionality")},ut.prototype.update=function(n){var r=this;et()&&k("Update"),this._setState(function(t){var e=J(n)?n(t):n,i=r.akitaPreUpdate(t,w({},t,e));return z(t)?i:new t.constructor(i)})},ut.prototype.updateStoreConfig=function(t){this.options=w({},this.options,t)},ut.prototype.akitaPreUpdate=function(t,e){return e},ut.prototype.ngOnDestroy=function(){this.destroy()},ut.prototype.destroy=function(){rt||window.hmrEnabled||this!==ot[this.storeName]||(delete ot[this.storeName],G(this.storeName),this.setHasCache(!1),this.cache.active.complete())},ut.prototype.onInit=function(t){(ot[this.storeName]=this)._setState(function(){return t}),Z(this.storeName),this.isResettable()&&(this._initialState=t),et()&&function i(t,e){t||console.error("@StoreConfig({ name }) is missing in "+e)}(this.storeName,this.constructor.name)},ut.prototype.dispatch=function(t,e){void 0===e&&(e=!0),this.store.next(t),e&&(tt(this.storeName),E())},ut.prototype.watchTransaction=function(){var t=this;R().subscribe(function(){t.inTransaction=!1,t.dispatch(t._value())})},ut.prototype.isResettable=function(){return!1!==this.resettable&&(this.resettable||$().resettable)},ut.prototype.handleTransaction=function(){this.inTransaction||(this.watchTransaction(),this.inTransaction=!0)},ut);function ut(t,e){void 0===e&&(e={}),this.options=e,this.inTransaction=!1,this.cache={active:new s.BehaviorSubject(!1),ttl:null},this.onInit(t)}function ct(t){return null===t||t===undefined}function pt(t){var e=typeof t;return null!=t&&("object"==e||"function"==e)}function ft(t,e,i){var n;if(p(t))n=t;else if(pt(t)){if(ct(i))return;t=Object.assign({wrap:!0},t);var r=e.indexOf(i);if(t.prev){var o=0===r;if(o&&!t.wrap)return;n=o?e[e.length-1]:e[r-1]}else if(t.next){var s=e.length===r+1;if(s&&!t.wrap)return;n=s?e[0]:e[r+1]}}else{if(t===i)return;n=t}return n}function ht(t){var e,i,n=t.state,r=t.entities,o=t.idKey,s=t.options,a=void 0===s?{}:s,u=t.preAddEntity,c={},p=[],f=!1;try{for(var h=x(r),l=h.next();!l.done;l=h.next()){var y=l.value;if(!1===j(n.entities,y[o])){var d=u(y),v=d[o];c[v]=d,a.prepend?p.unshift(v):p.push(v),f=!0}}}catch(g){e={error:g}}finally{try{l&&!l.done&&(i=h["return"])&&i.call(h)}finally{if(e)throw e.error}}return f?{newState:w({},n,{entities:w({},n.entities,c),ids:a.prepend?b(p,n.ids):b(n.ids,p)}),newIds:p}:null}function lt(t){return ct(t)?[]:Array.isArray(t)?t:[t]}function yt(t){var e,i,n=t.state,r=t.ids;if(ct(r))return dt(n);var o=n.entities,s={};try{for(var a=x(n.ids),u=a.next();!u.done;u=a.next()){var c=u.value;!1===r.includes(c)&&(s[c]=o[c])}}catch(f){e={error:f}}finally{try{u&&!u.done&&(i=a["return"])&&i.call(a)}finally{if(e)throw e.error}}var p=w({},n,{entities:s,ids:n.ids.filter(function(t){return!1===r.includes(t)})});return l(n)&&(p.active=y(p)),p}function dt(t){return w({},t,{entities:{},ids:[],active:o(t.active)?[]:null})}function vt(){return{entities:{},ids:[],loading:!0,error:null}}function gt(t){return!1===ct(t)}function mt(t){var e,i,n,r=t.state,o=t.ids,s=t.idKey,a=t.newStateOrFn,u=t.preUpdateEntity,c={},p=!1;try{for(var f=x(o),h=f.next();!h.done;h=f.next()){var l=h.value;if(!1!==j(r.entities,l)){var y=r.entities[l],d=J(a)?a(y):a,v=d.hasOwnProperty(s)&&d[s]!==y[s],g=void 0;n=l,v&&(p=!0,n=d[s]);var m=w({},y,d);g=z(y)?m:z(d)?new y.constructor(m):new d.constructor(m),c[n]=u(y,g)}}}catch(A){e={error:A}}finally{try{h&&!h.done&&(i=f["return"])&&i.call(f)}finally{if(e)throw e.error}}var b=r.ids,S=r.entities;if(p){var E=I(o,1)[0],P=r.entities,_=E;P[_];S=function O(t,e){var i={};for(var n in t)Object.prototype.hasOwnProperty.call(t,n)&&e.indexOf(n)<0&&(i[n]=t[n]);if(null!=t&&"function"==typeof Object.getOwnPropertySymbols){var r=0;for(n=Object.getOwnPropertySymbols(t);r<n.length;r++)e.indexOf(n[r])<0&&(i[n[r]]=t[n[r]])}return i}(P,["symbol"==typeof _?_:_+""]),b=r.ids.map(function(t){return t===E?n:t})}return w({},r,{entities:w({},S,c),ids:b})}function bt(t){return t===undefined}var St={Set:0,Add:1,Update:2,Remove:3};St[St.Set]="Set",St[St.Add]="Add",St[St.Update]="Update",St[St.Remove]="Remove";var Et,Pt,_t="id",At=(t(Ot,Et=at),Object.defineProperty(Ot.prototype,"selectEntityAction$",{get:function(){return this.entityActions.asObservable()},enumerable:!0,configurable:!0}),Object.defineProperty(Ot.prototype,"idKey",{get:function(){return this.config.idKey||this.options.idKey||_t},enumerable:!0,configurable:!0}),Ot.prototype.set=function(e){var i=this;if(!ct(e)){et()&&k("Set Entity");var n=this.akitaPreAddEntity===Ot.prototype.akitaPreAddEntity;this._setState(function(t){return u({state:t,entities:e,idKey:i.idKey,preAddEntity:i.akitaPreAddEntity,isNativePreAdd:n})}),this.setHasCache(!0,{restartTTL:!0}),this.hasInitialUIState()&&this.handleUICreation(),this.entityActions.next({type:St.Set,ids:this.ids})}},Ot.prototype.add=function(t,e){void 0===e&&(e={loading:!1});var i=lt(t);if(!f(i)){var n=ht({state:this._value(),preAddEntity:this.akitaPreAddEntity,entities:i,idKey:this.idKey,options:e});n&&(et()&&k("Add Entity"),n.newState.loading=e.loading,this._setState(function(){return n.newState}),this.hasInitialUIState()&&this.handleUICreation(!0),this.entityActions.next({type:St.Add,ids:n.newIds}))}},Ot.prototype.update=function(e,i){var n=this;if(bt(i))Et.prototype.update.call(this,e);else{var r=[];f(r=J(e)?this.ids.filter(function(t){return e(n.entities[t])}):ct(e)?this.ids:lt(e))||(et()&&k("Update Entity",r),this._setState(function(t){return mt({idKey:n.idKey,ids:r,preUpdateEntity:n.akitaPreUpdateEntity,state:t,newStateOrFn:i})}),this.entityActions.next({type:St.Update,ids:r}))}},Ot.prototype.upsert=function(t,r,o){var s=this;function e(e){return function(t){return j(s.entities,t)===e}}void 0===o&&(o={});var i=lt(t),a=J(o.baseClass),n=i.filter(e(!0)),u=i.filter(e(!1)).map(function(t){var e,i=J(r)?r({}):r,n=w({},i,((e={})[s.idKey]=t,e));return a?new o.baseClass(n):n});this.update(n,r),this.add(u),et()&&P("Upsert Entity")},Ot.prototype.upsertMany=function(t,e){var i,n;void 0===e&&(e={});var r=[],o=[],s={};try{for(var a=x(t),u=a.next();!u.done;u=a.next()){var c=u.value,p=this.akitaPreCheckEntity(c),f=p[this.idKey];if(j(this.entities,f)){var h=this._value().entities[f],l=w({},this._value().entities[f],p),y=e.baseClass?new e.baseClass(l):l,d=(v=this.akitaPreUpdateEntity(h,y))[this.idKey];s[d]=v,o.push(d)}else{var v,g=e.baseClass?new e.baseClass(p):p;d=(v=this.akitaPreAddEntity(g))[this.idKey],r.push(d),s[d]=v}}}catch(m){i={error:m}}finally{try{u&&!u.done&&(n=a["return"])&&n.call(a)}finally{if(i)throw i.error}}et()&&P("Upsert Many"),this._setState(function(t){return w({},t,{ids:r.length?b(t.ids,r):t.ids,entities:w({},t.entities,s),loading:!!e.loading})}),o.length&&this.entityActions.next({type:St.Update,ids:o}),r.length&&this.entityActions.next({type:St.Add,ids:r}),r.length&&this.hasUIStore()&&this.handleUICreation(!0)},Ot.prototype.replace=function(t,e){var i,n,r=lt(t);if(!f(r)){var o={};try{for(var s=x(r),a=s.next();!a.done;a=s.next()){var u=a.value;e[this.idKey]=u,o[u]=e}}catch(c){i={error:c}}finally{try{a&&!a.done&&(n=s["return"])&&n.call(s)}finally{if(i)throw i.error}}et()&&k("Replace Entity",t),this._setState(function(t){return w({},t,{entities:w({},t.entities,o)})})}},Ot.prototype.move=function(t,e){var i=this.ids.slice();i.splice(e<0?i.length+e:e,0,i.splice(t,1)[0]),et()&&k("Move Entity"),this._setState(function(t){return w({},t,{entities:w({},t.entities),ids:i})})},Ot.prototype.remove=function(e){var i=this;if(!f(this.ids)){var t=gt(e),n=[];f(n=J(e)?this.ids.filter(function(t){return e(i.entities[t])}):t?lt(e):null)||(et()&&k("Remove Entity",n),this._setState(function(t){return yt({state:t,ids:n})}),null===n&&this.setHasCache(!1),this.handleUIRemove(n),this.entityActions.next({type:St.Remove,ids:n}))}},Ot.prototype.updateActive=function(t){var e=lt(this.active);et()&&k("Update Active",e),this.update(e,t)},Ot.prototype.setActive=function(t){var e=ft(t,this.ids,this.active);e!==undefined&&(et()&&k("Set Active",e),this._setActive(e))},Ot.prototype.addActive=function(t){var e=this,i=lt(t);f(i)||i.every(function(t){return-1<e.active.indexOf(t)})||(et()&&k("Add Active",t),this._setState(function(t){var e=Array.from(new Set(b(t.active,i)));return w({},t,{active:e})}))},Ot.prototype.removeActive=function(t){var e=this,i=lt(t);f(i)||i.some(function(t){return-1<e.active.indexOf(t)})&&(et()&&k("Remove Active",t),this._setState(function(t){return w({},t,{active:Array.isArray(t.active)?t.active.filter(function(t){return-1===i.indexOf(t)}):null})}))},Ot.prototype.toggleActive=function(t){function e(e){return function(t){return i.active.includes(t)===e}}var i=this,n=lt(t),r=n.filter(e(!0)),o=n.filter(e(!1));this.removeActive(r),this.addActive(o),et()&&P("Toggle Active")},Ot.prototype.createUIStore=function(t,e){void 0===t&&(t={}),void 0===e&&(e={});var i={name:"UI/"+this.storeName,idKey:this.idKey};return this.ui=new xt(t,w({},i,e)),this.ui},Ot.prototype.destroy=function(){Et.prototype.destroy.call(this),this.ui instanceof Ot&&this.ui.destroy(),this.entityActions.complete()},Ot.prototype.akitaPreUpdateEntity=function(t,e){return e},Ot.prototype.akitaPreAddEntity=function(t){return t},Ot.prototype.akitaPreCheckEntity=function(t){return t},Object.defineProperty(Ot.prototype,"ids",{get:function(){return this._value().ids},enumerable:!0,configurable:!0}),Object.defineProperty(Ot.prototype,"entities",{get:function(){return this._value().entities},enumerable:!0,configurable:!0}),Object.defineProperty(Ot.prototype,"active",{get:function(){return this._value().active},enumerable:!0,configurable:!0}),Ot.prototype._setActive=function(e){this._setState(function(t){return w({},t,{active:e})})},Ot.prototype.handleUICreation=function(t){var r=this;function e(t){var e,i=r.entities[t],n=o?r.ui._akitaCreateEntityFn(i):r.ui._akitaCreateEntityFn;return w(((e={})[r.idKey]=i[r.idKey],e),n)}void 0===t&&(t=!1);var i,n=this.ids,o=J(this.ui._akitaCreateEntityFn);i=t?this.ids.filter(function(t){return bt(r.ui.entities[t])}).map(e):n.map(e),t?this.ui.add(i):this.ui.set(i)},Ot.prototype.hasInitialUIState=function(){return this.hasUIStore()&&!1===bt(this.ui._akitaCreateEntityFn)},Ot.prototype.handleUIRemove=function(t){this.hasUIStore()&&this.ui.remove(t)},Ot.prototype.hasUIStore=function(){return this.ui instanceof xt},e([M(),r("design:type",Function),r("design:paramtypes",[Object,Object,Object]),r("design:returntype",void 0)],Ot.prototype,"upsert",null),e([M(),r("design:type",Function),r("design:paramtypes",["function"==typeof(Pt="undefined"!=typeof T&&T)?Pt:Object]),r("design:returntype",void 0)],Ot.prototype,"toggleActive",null),Ot);function Ot(t,e){void 0===t&&(t={}),void 0===e&&(e={});var i=Et.call(this,w({},{entities:{},ids:[],loading:!0,error:null},t),e)||this;return i.options=e,i.entityActions=new s.Subject,i}var wt,xt=(t(It,wt=At),It.prototype.setInitialEntityState=function(t){this._akitaCreateEntityFn=t},It);function It(t,e){return void 0===t&&(t={}),void 0===e&&(e={}),wt.call(this,t,e)||this}var jt="akitaQueryConfig";function Ct(t){return"string"==typeof t}var kt=(Ut.prototype.select=function(e){var t;if(J(e))t=e;else if(Ct(e))t=function(t){return t[e]};else{if(Array.isArray(e))return this.store._select(function(t){return t}).pipe(O.distinctUntilChanged(function i(t){return function(e,i){var n=J(t[0]);return!1===t.some(function(t){return n?t(e)!==t(i):e[t]!==i[t]})}}(e)),O.map(function(i){return J(e[0])?e.map(function(t){return t(i)}):e.reduce(function(t,e){return t[e]=i[e],t},{})}));t=function(t){return t}}return this.store._select(t)},Ut.prototype.selectLoading=function(){return this.select(function(t){return t.loading})},Ut.prototype.selectError=function(){return this.select(function(t){return t.error})},Ut.prototype.getValue=function(){return this.store._value()},Ut.prototype.selectHasCache=function(){return this.store._cache().asObservable()},Ut.prototype.getHasCache=function(){return this.store._cache().value},Object.defineProperty(Ut.prototype,"config",{get:function(){return this.constructor[jt]},enumerable:!0,configurable:!0}),Ut);function Ut(t){this.store=t,this.__store__=t,et()&&(st[t.storeName]=this)}function Tt(t,e){t.sortBy=t.sortBy||e&&e.sortBy,t.sortByOrder=t.sortByOrder||e&&e.sortByOrder}var Ft={ASC:"asc",DESC:"desc"};function Vt(o,s){return void 0===s&&(s=Ft.ASC),function(t,e){if(!t.hasOwnProperty(o)||!e.hasOwnProperty(o))return 0;var i="string"==typeof t[o]?t[o].toUpperCase():t[o],n="string"==typeof e[o]?e[o].toUpperCase():e[o],r=0;return n<i?r=1:i<n&&(r=-1),s==Ft.DESC?-1*r:r}}function Nt(i,t){for(var n=[],r=i.ids,o=i.entities,s=t.filterBy,e=t.limitTo,a=t.sortBy,u=t.sortByOrder,c=function(e){var i=o[r[e]];if(!s)return n.push(i),"continue";lt(s).every(function(t){return t(i,e)})&&n.push(i)},p=0;p<r.length;p++)c(p);if(a){var f=J(a)?a:Vt(a,u);n=n.sort(function(t,e){return f(t,e,i)})}var h=Math.min(e||n.length,n.length);return h===n.length?n:n.slice(0,h)}function Dt(t,e){var r={},o=e.filterBy,s=e.limitTo,a=t.ids,u=t.entities;if(!o&&!s)return u;var i=!1===ct(s);if(o&&i)for(var c=0,n=function(e,t){if(c===s)return"break";var i=a[e],n=u[i];lt(o).every(function(t){return t(n,e)})&&(r[i]=n,c++)},p=0,f=a.length;p<f;p++){if("break"===n(p))break}else{var h=Math.min(s||a.length,a.length),l=function(e){var t=a[e],i=u[t];if(!o)return r[t]=i,"continue";lt(o).every(function(t){return t(i,e)})&&(r[t]=i)};for(p=0;p<h;p++)l(p)}return r}function Kt(i,n){return function(t){var e=t[i];return bt(e)?undefined:n?Ct(n)?e[n]:n(e):e}}function Rt(t,e,i){var n,r,o,s,a=[];if(J(e))try{for(var u=x(t),c=u.next();!c.done;c=u.next()){!0===e(l=c.value)&&a.push(l)}}catch(y){n={error:y}}finally{try{c&&!c.done&&(r=u["return"])&&r.call(u)}finally{if(n)throw n.error}}else{var p=lt(e).reduce(function(t,e){return t.add(e)},new Set);try{for(var f=x(t),h=f.next();!h.done;h=f.next()){var l=h.value;p.has(l[i])&&a.push(l)}}catch(d){o={error:d}}finally{try{h&&!h.done&&(s=f["return"])&&s.call(f)}finally{if(o)throw o.error}}}return a}function Bt(){return O.distinctUntilChanged(function(t,e){return t===e||!1!==p(t)&&!1!==p(e)&&(!(!f(t)||!f(e))||!Mt(e,t)&&!1===Mt(t,e))})}function Mt(t,e){return e.some(function(e){return t.find(function(t){return t===e})===undefined})}var Ht,Qt=(t(qt,Ht=kt),qt.prototype.selectAll=function(t){var e=this;return void 0===t&&(t={asObject:!1}),this.select(function(t){return t.entities}).pipe(O.map(function(){return e.getAll(t)}))},qt.prototype.getAll=function(t){return void 0===t&&(t={asObject:!1,filterBy:undefined,limitTo:undefined}),t.asObject?Dt(this.getValue(),t):(Tt(t,this.config||this.options),Nt(this.getValue(),t))},qt.prototype.selectMany=function(t,n){return t&&t.length?this.select(function(t){return t.entities}).pipe(O.map(function(e){return function i(t,o){return t.reduce(function(t,e,i,n){var r=o(e,i,n);return r!==undefined&&t.push(r),t},[])}(t,function(t){return Kt(t,n)(e)})}),Bt()):s.of([])},qt.prototype.selectEntity=function(t,e){var i=t;return J(t)&&(i=function u(t,e){var i,n;try{for(var r=x(Object.keys(e)),o=r.next();!o.done;o=r.next()){var s=o.value;if(!0===t(e[s]))return s}}catch(a){i={error:a}}finally{try{o&&!o.done&&(n=r["return"])&&n.call(r)}finally{if(i)throw i.error}}return undefined}(t,this.getValue().entities)),this.select(function(t){return t.entities}).pipe(O.map(Kt(i,e)),O.distinctUntilChanged())},qt.prototype.getEntity=function(t){return this.getValue().entities[t]},qt.prototype.selectActiveId=function(){return this.select(function(t){return t.active})},qt.prototype.getActiveId=function(){return this.getValue().active},qt.prototype.selectActive=function(e){var i=this;return p(this.getActive())?this.selectActiveId().pipe(O.switchMap(function(t){return i.selectMany(t,e)})):this.selectActiveId().pipe(O.switchMap(function(t){return i.selectEntity(t,e)}))},qt.prototype.getActive=function(){var e=this,t=this.getActiveId();return p(t)?t.map(function(t){return e.getValue().entities[t]}):L(t)?this.getEntity(t):undefined},qt.prototype.selectCount=function(t){var e=this;return this.select(function(t){return t.entities}).pipe(O.map(function(){return e.getCount(t)}))},qt.prototype.getCount=function(t){return J(t)?this.getAll().filter(t).length:this.getValue().ids.length},qt.prototype.selectLast=function(t){return this.selectAt(function(t){return t[t.length-1]},t)},qt.prototype.selectFirst=function(t){return this.selectAt(function(t){return t[0]},t)},qt.prototype.selectEntityAction=function(e){return bt(e)?this.store.selectEntityAction$:this.store.selectEntityAction$.pipe(O.filter(function(t){return t.type===e}),O.map(function(t){return t.ids}))},qt.prototype.hasEntity=function(t){var e=this;return ct(t)?0<this.getValue().ids.length:J(t)?this.getAll().some(t):p(t)?t.every(function(t){return t in e.getValue().entities}):t in this.getValue().entities},qt.prototype.hasActive=function(t){var e=this.getValue().active;return Array.isArray(e)?gt(t)?e.includes(t):0<e.length:gt(e)},qt.prototype.createUIQuery=function(){this.ui=new Lt(this.__store__.ui)},qt.prototype.selectAt=function(t,e){var i=this;return this.select(function(t){return t.ids}).pipe(O.map(t),O.distinctUntilChanged(),O.switchMap(function(t){return i.selectEntity(t,e)}))},qt);function qt(t,e){void 0===e&&(e={});var i=Ht.call(this,t)||this;return i.options=e,i.__store__=t,i}var $t,Lt=(t(zt,$t=Qt),zt);function zt(t){return $t.call(this,t)||this}function Jt(t){return t.pipe(O.filter(function(t){return null!=t}))}function Wt(t,e){return 1===e.split(".").length?t:e.split(".").slice(1).join(".").split(".").reduce(function(t,e){return t&&t[e]},t)}function Xt(t,e,n){var i=e.split(".");if(1===i.length)return n;t=w({},t);var r=i.length-2;return e.split(".").slice(1).reduce(function(t,e,i){return t[e]=i===r?n:w({},t[e]),t&&t[e]},t),t}var Yt=!1;function Gt(t){Yt=t}function Zt(){return Yt}function te(t){return function e(t){return t&&J(t.then)}(t)||s.isObservable(t)?s.from(t):s.of(t)}var ee=(ie.prototype.getStoresSnapshot=function(t){void 0===t&&(t=[]);for(var e={},i=0<t.length?t:Object.keys(ot),n=0;n<i.length;n++){var r=i[n];e[r]=ot[r]._value()}return e},ie.prototype.setStoresSnapshot=function(t,e){void 0===e&&(e={skipStorageUpdate:!1}),e.skipStorageUpdate&&Gt(!0);var n=t;Ct(t)&&(n=JSON.parse(n));for(var i=function(t,e){var i=e[t];ot[i]&&ot[i]._setState(function(){return n[i]})},r=0,o=Object.keys(n);r<o.length;r++)i(r,o);e.skipStorageUpdate&&Gt(!1)},ie);function ie(){}var ne=new ee,re=(oe.prototype.getQuery=function(){return this.query},oe.prototype.getStore=function(){return this.getQuery().__store__},oe.prototype.isEntityBased=function(t){return L(t)},oe.prototype.selectSource=function(t){return this.isEntityBased(t)?this.getQuery().selectEntity(t).pipe(Jt):this.getQuery().select(function(t){return t})},oe.prototype.getSource=function(t){return this.isEntityBased(t)?this.getQuery().getEntity(t):this.getQuery().getValue()},oe.prototype.updateStore=function(e,t){this.isEntityBased(t)?this.getStore().update(t,e):this.getStore()._setState(function(t){return w({},t,e)})},oe.prototype.onReset=function(i){var n=this,r=this.getStore().reset;this.getStore().reset=function(){for(var t=[],e=0;e<arguments.length;e++)t[e]=arguments[e];setTimeout(function(){r.apply(n.getStore(),t),i()})}},oe);function oe(t,e){this.query=t,e&&e.resetFn&&$().resettable&&this.onReset(e.resetFn)}var se,ae={pagesControls:!1,range:!1,startWith:1,cacheTimeout:undefined,clearStoreWithCache:!0},ue=(t(ce,se=re),Object.defineProperty(ce.prototype,"pageChanges",{get:function(){return this.page.asObservable()},enumerable:!0,configurable:!0}),Object.defineProperty(ce.prototype,"currentPage",{get:function(){return this.pagination.currentPage},enumerable:!0,configurable:!0}),Object.defineProperty(ce.prototype,"isFirst",{get:function(){return 1===this.currentPage},enumerable:!0,configurable:!0}),Object.defineProperty(ce.prototype,"isLast",{get:function(){return this.currentPage===this.pagination.lastPage},enumerable:!0,configurable:!0}),ce.prototype.withControls=function(){return this.config.pagesControls=!0,this},ce.prototype.withRange=function(){return this.config.range=!0,this},ce.prototype.setLoading=function(t){void 0===t&&(t=!0),this.getStore().setLoading(t)},ce.prototype.update=function(t){this.pagination=t,this.addPage(t.data)},ce.prototype.addPage=function(t){var e=this;this.pages.set(this.currentPage,{ids:t.map(function(t){return t[e.getStore().idKey]})}),this.getStore().add(t)},ce.prototype.clearCache=function(t){void 0===t&&(t={}),this.initial||(P("@Pagination - Clear Cache"),!1!==t.clearStore&&(this.config.clearStoreWithCache||t.clearStore)&&this.getStore().remove(),this.pages=new Map,this.metadata=new Map),this.initial=!1},ce.prototype.clearPage=function(t){this.pages["delete"](t)},ce.prototype.destroy=function(t){var e=void 0===t?{}:t,i=e.clearCache,n=e.currentPage;this.clearCacheSubscription&&this.clearCacheSubscription.unsubscribe(),i&&this.clearCache(),bt(n)||this.setPage(n),this.initial=!0},ce.prototype.isPageActive=function(t){return this.currentPage===t},ce.prototype.setPage=function(t){t===this.currentPage&&this.hasPage(t)||this.page.next(this.pagination.currentPage=t)},ce.prototype.nextPage=function(){this.currentPage!==this.pagination.lastPage&&this.setPage(this.pagination.currentPage+1)},ce.prototype.prevPage=function(){1<this.pagination.currentPage&&this.setPage(this.pagination.currentPage-1)},ce.prototype.setLastPage=function(){this.setPage(this.pagination.lastPage)},ce.prototype.setFirstPage=function(){this.setPage(1)},ce.prototype.hasPage=function(t){return this.pages.has(t)},ce.prototype.getPage=function(t){var e=this,i=this.pagination.currentPage;return this.hasPage(i)?this.selectPage(i):(this.setLoading(!0),s.from(t()).pipe(O.switchMap(function(t){return i=t.currentPage,B(function(){e.setLoading(!1),e.update(t)}),e.selectPage(i)})))},ce.prototype.getQuery=function(){return this.query},ce.prototype.refreshCurrentPage=function(){!1===ct(this.currentPage)&&(this.clearPage(this.currentPage),this.setPage(this.currentPage))},ce.prototype.getFrom=function(){return this.isFirst?1:(this.currentPage-1)*this.pagination.perPage+1},ce.prototype.getTo=function(){return this.isLast?this.pagination.total:this.currentPage*this.pagination.perPage},ce.prototype.selectPage=function(s){var a=this;return this.query.selectAll({asObject:!0}).pipe(O.take(1),O.map(function(e){var t=w({},a.pagination,{data:a.pages.get(s).ids.map(function(t){return e[t]})}),i=a.config,n=i.range,r=i.pagesControls;return isNaN(a.pagination.total)&&(1===t.lastPage?t.total=t.data?t.data.length:0:t.total=t.perPage*t.lastPage,a.pagination.total=t.total),n&&(t.from=a.getFrom(),t.to=a.getTo()),r&&(t.pageControls=function o(t,e){for(var i=Math.ceil(t/e),n=[],r=0;r<i;r++)n.push(r+1);return n}(a.pagination.total,a.pagination.perPage)),t}))},e([A("@Pagination - New Page"),r("design:type",Function),r("design:paramtypes",[Object]),r("design:returntype",void 0)],ce.prototype,"update",null),ce);function ce(t,e){void 0===e&&(e={});var i=se.call(this,t,{resetFn:function(){i.initial=!1,i.destroy({clearCache:!0,currentPage:1})}})||this;i.query=t,i.config=e,i.metadata=new Map,i.pages=new Map,i.pagination={currentPage:1,perPage:0,total:0,lastPage:0,data:[]},i.initial=!0,i.isLoading$=i.query.selectLoading().pipe(O.delay(0)),i.config=Object.assign(ae,e);var n=i.config,r=n.startWith,o=n.cacheTimeout;return i.page=new s.BehaviorSubject(r),s.isObservable(o)&&(i.clearCacheSubscription=o.subscribe(function(){return i.clearCache()})),i}var pe,fe=ue,he=(t(le,pe=re),le.prototype.setForm=function(t,e){return this.form=t,this.builder=e,this.activate(),this},le.prototype.reset=function(t){var e,i,n=this;i=t||(this.isKeyBased?this.initialValue:this.factoryFnOrPath()),this.isKeyBased&&Object.keys(this.initialValue).forEach(function(i){var t=n.initialValue[i];if(Array.isArray(t)&&n.builder){var e=n.form.controls[i];n.cleanArray(e),t.forEach(function(t,e){n.form.get(i).insert(e,n.params.arrControlFactory(t))})}}),this.form.patchValue(i,{emitEvent:this.params.emitEvent});var r=this.isKeyBased?Xt(this.getQuery().getValue(),this.getStore().storeName+"."+this.factoryFnOrPath,i):((e={})[this.params.formKey]=i,e);this.updateStore(r)},le.prototype.cleanArray=function(t){for(;0!==t.length;)t.removeAt(0)},le.prototype.resolveInitialValue=function(t,r){var o=this;if(t)return Object.keys(t).reduce(function(t,i){var e=r[i];if(Array.isArray(e)&&o.builder){var n=o.params.arrControlFactory;o.cleanArray(o.form.get(i)),e.forEach(function(t,e){o.form.get(i).insert(e,n(t))})}return t[i]=r[i],t},{})},le.prototype.activate=function(){var t,i,n=this;if(this.isKeyBased)if(this.isRootKeys)this.initialValue=this.resolveInitialValue(this.form.value,this.getQuery().getValue()),this.form.patchValue(this.initialValue,{emitEvent:this.params.emitEvent});else{i=this.getStore().storeName+"."+this.factoryFnOrPath;var e=Wt(this.getQuery().getValue(),i);this.initialValue=this.resolveInitialValue(e,e),this.form.patchValue(this.initialValue,{emitEvent:this.params.emitEvent})}else{this.getQuery().getValue()[this.params.formKey]||(P("@PersistNgFormPlugin activate"),this.updateStore(((t={})[this.params.formKey]=this.factoryFnOrPath(),t)));var r=this.getQuery().getValue()[this.params.formKey];this.form.patchValue(r)}this.formChanges=this.form.valueChanges.pipe(O.debounceTime(this.params.debounceTime)).subscribe(function(e){var t;P("@PersistForm - Update"),t=n.isKeyBased?n.isRootKeys?function(t){return w({},t,e)}:function(t){return Xt(t,i,e)}:function(){var t;return(t={})[n.params.formKey]=e,t},n.updateStore(t(n.getQuery().getValue()))})},le.prototype.destroy=function(){this.formChanges&&this.formChanges.unsubscribe(),this.form=null,this.builder=null},le);function le(t,e,i){void 0===i&&(i={});var n=pe.call(this,t)||this;return n.query=t,n.factoryFnOrPath=e,n.params=i,n.params=w({debounceTime:300,formKey:"akitaForm",emitEvent:!1,arrControlFactory:function(t){return n.builder.control(t)}},i),n.isRootKeys=!1===L(e),n.isKeyBased=Ct(e)||n.isRootKeys,n}function ye(t){return t&&t.charAt(0).toUpperCase()+t.slice(1)}var de=[];var ve=(ge.prototype.getEntity=function(t){return this.entities.get(t)},ge.prototype.hasEntity=function(t){return this.entities.has(t)},ge.prototype.removeEntity=function(t){return this.destroy(t),this.entities["delete"](t)},ge.prototype.createEntity=function(t,e){return this.entities.set(t,e)},ge.prototype.getIds=function(){return bt(this.entityIds)?this.query.getValue().ids:lt(this.entityIds)},ge.prototype.resolvedIds=function(t){return bt(t)?this.getIds():lt(t)},ge.prototype.rebase=function(i,n){var r=this;if(void 0===n&&(n={}),L(i))if(bt(this.entityIds)){for(var t=0,e=i.length;t<e;t++){var o=i[t];if(!1===this.hasEntity(o)){J(n.beforeAdd)&&n.beforeAdd(o);var s=this.instantiatePlugin(o);this.entities.set(o,s),J(n.afterAdd)&&n.afterAdd(s)}}this.entities.forEach(function(t,e){-1===i.indexOf(e)&&(J(n.beforeRemove)&&n.beforeRemove(t),r.removeEntity(e))})}else{var a=lt(this.entityIds);for(t=0,e=a.length;t<e;t++)o=a[t],-1<i.indexOf(o)&&!1===this.hasEntity(o)?(J(n.beforeAdd)&&n.beforeAdd(o),s=this.instantiatePlugin(o),this.entities.set(o,s),J(n.afterAdd)&&n.afterAdd(s)):this.entities.forEach(function(t,e){-1===i.indexOf(e)&&!0===r.hasEntity(e)&&(J(n.beforeRemove)&&n.beforeRemove(t),r.removeEntity(e))})}else this.getIds().forEach(function(t){r.hasEntity(t)||r.createEntity(t,r.instantiatePlugin(t))})},ge.prototype.selectIds=function(){return this.query.select(function(t){return t.ids})},ge.prototype.activate=function(t){this.rebase(t)},ge.prototype.forEachId=function(t,e){for(var i=this.resolvedIds(t),n=0,r=i.length;n<r;n++){var o=i[n];this.hasEntity(o)&&e(this.getEntity(o))}},ge);function ge(t,e){this.query=t,this.entityIds=e,this.entities=new Map}var me,be=(t(Se,me=re),Object.defineProperty(Se.prototype,"hasPast",{get:function(){return 0<this.history.past.length},enumerable:!0,configurable:!0}),Object.defineProperty(Se.prototype,"hasFuture",{get:function(){return 0<this.history.future.length},enumerable:!0,configurable:!0}),Se.prototype.activate=function(){var o=this;this.history.present=this.getSource(this._entityId),this.subscription=this.selectSource(this._entityId).pipe(O.pairwise()).subscribe(function(t){var e=I(t,2),i=e[0],n=e[1];if(o.skip)o.skip=!1;else{var r=o.params.comparator(i,n);!o.skipUpdate&&r&&(o.history.past.length===o.params.maxAge&&(o.history.past=o.history.past.slice(1)),o.history.past=b(o.history.past,[i]),o.history.present=n)}})},Se.prototype.undo=function(){if(0<this.history.past.length){var t=this.history,e=t.past,i=t.present,n=e[e.length-1];this.history.past=e.slice(0,e.length-1),this.history.present=n,this.history.future=b([i],this.history.future),this.update()}},Se.prototype.redo=function(){if(0<this.history.future.length){var t=this.history,e=t.past,i=t.present,n=this.history.future[0],r=this.history.future.slice(1);this.history.past=b(e,[i]),this.history.present=n,this.history.future=r,this.update("Redo")}},Se.prototype.jumpToPast=function(t){if(!(t<0||t>=this.history.past.length)){var e=this.history,i=e.past,n=e.future,r=i.slice(0,t),o=b(i.slice(t+1),n),s=i[t];this.history.past=r,this.history.present=s,this.history.future=o,this.update()}},Se.prototype.jumpToFuture=function(t){if(!(t<0||t>=this.history.future.length)){var e=this.history,i=e.past,n=e.future,r=b(i,n.slice(0,t)),o=n[t],s=n.slice(t+1);this.history.past=r,this.history.present=o,this.history.future=s,this.update("Redo")}},Se.prototype.clear=function(t){this.history=J(t)?t(this.history):{past:[],present:null,future:[]}},Se.prototype.destroy=function(t){void 0===t&&(t=!1),t&&this.clear(),this.subscription.unsubscribe()},Se.prototype.ignoreNext=function(){this.skip=!0},Se.prototype.update=function(t){void 0===t&&(t="Undo"),this.skipUpdate=!0,P("@StateHistory - "+t),this.updateStore(this.history.present,this._entityId),this.skipUpdate=!1},Se);function Se(t,e,i){void 0===e&&(e={});var n=me.call(this,t,{resetFn:function(){return n.clear()}})||this;return n.query=t,n.params=e,n._entityId=i,n.skip=!1,n.history={past:[],present:null,future:[]},n.skipUpdate=!1,e.maxAge=e.maxAge?e.maxAge:10,e.comparator=e.comparator||function(){return!0},n.activate(),n}var Ee,Pe=(t(_e,Ee=ve),_e.prototype.redo=function(t){this.forEachId(t,function(t){return t.redo()})},_e.prototype.undo=function(t){this.forEachId(t,function(t){return t.undo()})},_e.prototype.hasPast=function(t){if(this.hasEntity(t))return this.getEntity(t).hasPast},_e.prototype.hasFuture=function(t){if(this.hasEntity(t))return this.getEntity(t).hasFuture},_e.prototype.jumpToFuture=function(t,e){this.forEachId(t,function(t){return t.jumpToFuture(e)})},_e.prototype.jumpToPast=function(t,e){this.forEachId(t,function(t){return t.jumpToPast(e)})},_e.prototype.clear=function(t){this.forEachId(t,function(t){return t.clear()})},_e.prototype.destroy=function(t,e){void 0===e&&(e=!1),this.forEachId(t,function(t){return t.destroy(e)})},_e.prototype.ignoreNext=function(t){this.forEachId(t,function(t){return t.ignoreNext()})},_e.prototype.instantiatePlugin=function(t){return new be(this.query,this.params,t)},_e);function _e(t,e){void 0===e&&(e={});var i=Ee.call(this,t,e.entityIds)||this;return i.query=t,(i.params=e).maxAge=L(e.maxAge)?e.maxAge:10,i.activate(),i.selectIds().pipe(O.skip(1)).subscribe(function(t){return i.activate(t)}),i}var Ae={comparator:function(t,e){return JSON.stringify(t)!==JSON.stringify(e)}};function Oe(t,e){return e.split(".").reduce(function(t,e){return t&&"undefined"!==t[e]?t[e]:undefined},t)}var we,xe=(t(Ie,we=re),Ie.prototype.reset=function(t){void 0===t&&(t={});var e=this.head;J(t.updateFn)&&(e=this.isEntityBased(this._entityId)?t.updateFn(this.head,this.getQuery().getEntity(this._entityId)):t.updateFn(this.head,this.getQuery().getValue())),P("@DirtyCheck - Revert"),this.updateStore(e,this._entityId),this._reset.next()},Ie.prototype.setHead=function(){return this.active?this.head=this._getHead():(this.activate(),this.active=!0),this.updateDirtiness(!1),this},Ie.prototype.isDirty=function(){return!!this.dirty.value},Ie.prototype.hasHead=function(){return!!this.getHead()},Ie.prototype.destroy=function(){this.head=null,this.subscription&&this.subscription.unsubscribe(),this._reset&&this._reset.complete()},Ie.prototype.isPathDirty=function(t){var e=this.getHead(),i=Oe(this.getQuery().getValue(),t),n=Oe(e,t);return this.params.comparator(i,n)},Ie.prototype.getHead=function(){return this.head},Ie.prototype.activate=function(){var n=this;this.head=this._getHead();var t=this.params.watchProperty?this.params.watchProperty.map(function(e){return n.query.select(function(t){return t[e]}).pipe(O.map(function(t){return{val:t,__akitaKey:e}}))}):[this.selectSource(this._entityId)];this.subscription=s.combineLatest.apply(void 0,b(t)).pipe(O.skip(1)).subscribe(function(t){if(!bt(n.head)){var e=t.some(function(t){var e=t.__akitaKey?n.head[t.__akitaKey]:n.head,i=t.__akitaKey?t.val:t;return n.params.comparator(e,i)});n.updateDirtiness(e)}})},Ie.prototype.updateDirtiness=function(t){this.dirty.next(t)},Ie.prototype._getHead=function(){var t=this.getSource(this._entityId);return this.params.watchProperty&&(t=this.getWatchedValues(t)),t},Ie.prototype.getWatchedValues=function(i){return this.params.watchProperty.reduce(function(t,e){return t[e]=i[e],t},{})},Ie);function Ie(t,e,i){var n=we.call(this,t)||this;if(n.query=t,n.params=e,n._entityId=i,n.dirty=new s.BehaviorSubject(!1),n.active=!1,n._reset=new s.Subject,n.isDirty$=n.dirty.asObservable().pipe(O.distinctUntilChanged()),n.reset$=n._reset.asObservable(),n.params=w({},Ae,e),n.params.watchProperty){var r=lt(n.params.watchProperty);t instanceof Qt&&r.includes("entities")&&!r.includes("ids")&&r.push("ids"),n.params.watchProperty=r}return n}var je,Ce=(t(ke,je=ve),ke.prototype.setHead=function(t){if(this.params.entityIds&&t){var e=lt(t);if(!1===lt(this.params.entityIds).some(function(t){return-1<e.indexOf(t)}))return this}return this.forEachId(t,function(t){return t.setHead()}),this._someDirty.next(),this},ke.prototype.hasHead=function(t){return!!this.entities.has(t)&&this.getEntity(t).hasHead()},ke.prototype.reset=function(t,e){void 0===e&&(e={}),this.forEachId(t,function(t){return t.reset(e)})},ke.prototype.isDirty=function(t,e){if(void 0===e&&(e=!0),this.entities.has(t)){var i=this.getEntity(t);return e?i.isDirty$:i.isDirty()}return!1},ke.prototype.someDirty=function(){return this.checkSomeDirty()},ke.prototype.isPathDirty=function(t,e){if(this.entities.has(t)){var i=this.getEntity(t).getHead(),n=Oe(this.query.getEntity(t),e),r=Oe(i,e);return this.params.comparator(n,r)}return null},ke.prototype.destroy=function(t){this.forEachId(t,function(t){return t.destroy()}),t||this._someDirty.complete()},ke.prototype.instantiatePlugin=function(t){return new xe(this.query,this.params,t)},ke.prototype.checkSomeDirty=function(){var t,e,i=this.resolvedIds();try{for(var n=x(i),r=n.next();!r.done;r=n.next()){var o=r.value;if(this.getEntity(o).isDirty())return!0}}catch(s){t={error:s}}finally{try{r&&!r.done&&(e=n["return"])&&e.call(n)}finally{if(t)throw t.error}}return!1},ke);function ke(t,e){void 0===e&&(e={});var i=je.call(this,t,e.entityIds)||this;return i.query=t,i.params=e,i._someDirty=new s.Subject,i.someDirty$=s.merge(i.query.select(function(t){return t.entities}),i._someDirty.asObservable()).pipe(O.auditTime(0),O.map(function(){return i.checkSomeDirty()})),i.params=w({},Ae,e),i.activate(),i.selectIds().pipe(O.skip(1)).subscribe(function(t){je.prototype.rebase.call(i,t,{afterAdd:function(t){return t.setHead()}})}),i}var Ue={Update:0,AddEntities:1,SetEntities:2,UpdateEntities:3,RemoveEntities:4,UpsertEntities:5};function Te(i,t,e,n){var r;if(void 0===n&&(n=_t),J(t))r=t;else{var o=lt(t);r=function(t){return!0===o.includes(pt(t)?t[n]:t)}}function s(t){return t.map(function(t){return!0===r(t)?pt(t)?w({},t,e):e:t})}return p(i)?s(i):function(t){var e;return(e={})[i]=s(t[i]),e}}function Fe(i,t,e){void 0===e&&(e={});function n(t){return e.prepend?b(r,t||[]):b(t||[],r)}var r=lt(t);return p(i)?n(i):function(t){var e;return(e={})[i]=n(t[i]),e}}Ue[Ue.Update]="Update",Ue[Ue.AddEntities]="AddEntities",Ue[Ue.SetEntities]="SetEntities",Ue[Ue.UpdateEntities]="UpdateEntities",Ue[Ue.RemoveEntities]="RemoveEntities",Ue[Ue.UpsertEntities]="UpsertEntities";function Ve(){}i.EntityStore=At,i.EntityUIStore=xt,i.QueryEntity=Qt,i.EntityUIQuery=Lt,i.Query=kt,i.Store=at,i.applyTransaction=B,i.transaction=M,i.commit=R,i.endBatch=D,i.isTransactionInProcess=K,i.startBatch=N,i.transactionManager=V,i.withTransaction=function Ne(e){return function(t){return t.pipe(O.tap(function(t){return B(function(){return e(t)})}))}},i.filterNil=Jt,i.DEFAULT_ID_KEY=_t,i.action=A,i.setAction=k,i.setSkipAction=_,i.logAction=P,i.currentAction=m,i.resetCustomAction=E,i.SnapshotManager=ee,i.snapshotManager=ne,i.configKey=Q,i.StoreConfig=function De(r){return function(t){t[Q]={idKey:"id"};for(var e=0,i=Object.keys(r);e<i.length;e++){var n=i[e];"name"===n?t[Q].storeName=r[n]:t[Q][n]=r[n]}}},i.QueryConfig=function Ke(r){return function(t){t[jt]={};for(var e=0,i=Object.keys(r);e<i.length;e++){var n=i[e];t[jt][n]=r[n]}}},i.queryConfigKey=jt,i.akitaConfig=function Re(t){q=w({},q,t)},i.getAkitaConfig=$,i.compareValues=Vt,i.Order=Ft,i.AkitaPlugin=re,i.Paginator=fe,i.PaginatorPlugin=ue,i.PersistNgFormPlugin=he,i.persistState=function Be(t){if(!rt){var a,e={key:"AkitaStores",storage:"undefined"==typeof localStorage?t.storage:localStorage,deserialize:JSON.parse,serialize:JSON.stringify,include:[],exclude:[],persistOnDestroy:!1,preStorageUpdate:function(t,e){return e},preStoreUpdate:function(t,e){return e},skipStorageUpdate:Zt,preStorageUpdateOperator:function(){return function(t){return t}}},i=Object.assign({},e,t),u=i.storage,c=i.deserialize,p=i.serialize,n=i.include,f=i.exclude,h=i.key,l=i.preStorageUpdate,y=i.persistOnDestroy,d=i.preStorageUpdateOperator,v=i.preStoreUpdate,g=i.skipStorageUpdate,m=0<n.length,b=0<f.length;if(m&&b)throw new C("You can't use both include and exclude");m&&(a=n.reduce(function(t,e){J(e)?t.fns.push(e):t[e.split(".")[0]]=e;return t},{fns:[]}));var S={},E={},P=[],_=[],A="undefined"!=typeof localStorage&&(u===localStorage||u===sessionStorage);return te(u.getItem(h)).subscribe(function(t){var r=pt(t)?t:c(t||"{}");function n(t){r.$cache=w({},r.$cache||{},t);var e=Object.assign({},r,E);_.push(u.setItem(h,A?p(e):e)),function i(t){te(t).subscribe(function(){var t=_.shift();t&&i(t)})}(_.shift())}function o(e,i){S[e]=ot[e]._select(function(t){return Wt(t,i)}).pipe(O.skip(1),O.filter(function(){return!1===g()}),d()).subscribe(function(t){E[e]=l(e,t),Promise.resolve().then(function(){var t;return n(((t={})[e]=ot[e]._cache().getValue(),t))})})}function s(e,t,i){if(e in r){k("@PersistState"),t._setState(function(t){return Xt(t,i,v(e,r[e]))});var n=!!r.$cache&&r.$cache[e];ot[e].setHasCache(n)}}P.push(W.subscribe(function(t){S[t]&&(!1===y&&n(!1),S[t].unsubscribe(),delete S[t])})),P.push(X.subscribe(function(e){if(!b||!f.includes(e)){var t=ot[e];if(m){var i=a[e];if(!i){if(!a.fns.some(function(t){return t(e)}))return;i=e}s(e,t,i),o(e,i)}else s(e,t,e),o(e,e)}}))}),{destroy:function(){P.forEach(function(t){return t.unsubscribe()});for(var t=0,e=Object.keys(S);t<e.length;t++){var i=e[t];S[i].unsubscribe()}S={}},clear:function(){u.clear()},clearStore:function(i){ct(i)?te(u.setItem(h,"{}")).subscribe():te(u.getItem(h)).subscribe(function(t){var e=c(t||"{}");e[i]&&(delete e[i],te(u.setItem(h,p(e))).subscribe())})}}}},i.akitaDevtools=function Me(o,a){if(void 0===a&&(a={}),!rt&&window.__REDUX_DEVTOOLS_EXTENSION__){de.length&&de.forEach(function(t){t.unsubscribe?t.unsubscribe():t&&t()}),o&&o.run||((o=o||{}).run=function(t){return t()},a=o);var t=Object.assign({},{name:"Akita",shallow:!0},a),u=window.__REDUX_DEVTOOLS_EXTENSION__.connect(t),c={};de.push(X.subscribe(function(t){var e;c=w({},c,((e={})[t]=ot[t]._value(),e)),u.send({type:"["+ye(t)+"] - @@INIT"},c)})),de.push(W.subscribe(function(t){delete c[t],u.send({type:"["+t+"] - Delete Store"},c)})),de.push(Y.subscribe(function(t){var e,i=m.type,n=m.entityIds;if(m.skip)_(!1);else{var r=ot[t];if(r){if(!1===a.shallow&&c[t])if(JSON.stringify(r._value())===JSON.stringify(c[t]))return;c=w({},c,((e={})[t]=r._value(),e));var o=ye(t),s=gt(n)?"["+o+"] - "+i+" (ids: "+n+")":"["+o+"] - "+i;a.logTrace&&(console.group(s),console.trace(),console.groupEnd()),u.send({type:s},c)}}})),de.push(u.subscribe(function(t){if("DISPATCH"===t.type){if("COMMIT"===t.payload.type)return void u.init(c);if(t.state)for(var n=JSON.parse(t.state),e=function(t,e){var i=e[t];ot[i]&&o.run(function(){ot[i]._setState(function(){return n[i]},!1)})},i=0,r=Object.keys(n);i<r.length;i++)e(i,r)}}))}},i.EntityCollectionPlugin=ve,i.StateHistoryPlugin=be,i.EntityStateHistoryPlugin=Pe,i.dirtyCheckDefaultParams=Ae,i.DirtyCheckPlugin=xe,i.getNestedPath=Oe,i.EntityDirtyCheckPlugin=Ce,i.guid=function He(){return"xxxxxx4xyx".replace(/[xy]/g,function(t){var e=16*Math.random()|0;return("x"==t?e:3&e|8).toString(16)})},i.setEntities=u,i.isEntityState=d,i.toEntitiesIds=function Qe(t,e){var i,n;void 0===e&&(e=_t);var r=[];try{for(var o=x(t),s=o.next();!s.done;s=o.next()){var a=s.value;r.push(a[e])}}catch(u){i={error:u}}finally{try{s&&!s.done&&(n=o["return"])&&n.call(o)}finally{if(i)throw i.error}}return r},i.toEntitiesObject=h,i.hasEntity=j,i.hasActiveState=l,i.getExitingActives=a,i.isMultiActiveState=o,i.resolveActiveEntity=y,i.isEmpty=f,i.coerceArray=lt,i.updateEntities=mt,i.removeEntities=yt,i.removeAllEntities=dt,i.getInitialEntitiesState=vt,i.getActiveEntities=ft,i.addEntities=ht,i.resetStores=function qe(a){a=Object.assign({},{exclude:[]},a);var u=Object.keys(ot);B(function(){var t,e;try{for(var i=x(u),n=i.next();!n.done;n=i.next()){var r=n.value,o=ot[r];a.exclude?-1===a.exclude.indexOf(o.storeName)&&o.reset():o.reset()}}catch(s){t={error:s}}finally{try{n&&!n.done&&(e=i["return"])&&e.call(i)}finally{if(t)throw t.error}}})},i.isObject=pt,i.isPlainObject=z,i.isFunction=J,i.isArray=p,i.toBoolean=L,i.isUndefined=bt,i.isNil=ct,i.isString=Ct,i.isNumber=function $e(t){return!p(t)&&0<=t-parseFloat(t)+1},i.isDefined=gt,i.setValue=Xt,i.getValue=Wt,i.sortByOptions=Tt,i.entitiesToArray=Nt,i.entitiesToMap=Dt,i.__stores__=ot,i.isDev=et,i.enableAkitaProdMode=function Le(){i.__DEV__=!1},i.isNotBrowser=rt,i.runStoreAction=function ze(t,e,i){var n=ot[t];if(ct(n))throw new C(t+" doesn't exist");switch(e){case Ue.SetEntities:var r=i.payload;return void n.set(r.data);case Ue.AddEntities:r=i.payload;return void n.add(r.data,r.params);case Ue.UpdateEntities:r=i.payload;return void n.update(r.entityIds,r.data);case Ue.RemoveEntities:r=i.payload;return void n.remove(r.entityIds);case Ue.UpsertEntities:(r=i.payload).entityIds?n.upsert(r.entityIds,r.data):Array.isArray(r.data)?n.upsertMany(r.data):n.upsertMany([r.data]);case Ue.Update:r=i.payload;return void n.update(r.data)}},i.StoreActions=Ue,i.arrayUpdate=Te,i.arrayAdd=Fe,i.arrayUpsert=function Je(t,e,i,n){var r;void 0===n&&(n=_t);var o=pt(i);return t.some(function(t){return o?t[n]===e:t===e})?Te(t,e,i,n):Fe(t,o?w({},i,((r={})[n]=e,r)):i)},i.arrayFind=function We(e,i){return function(t){return t.pipe(O.map(function(t){return!1===p(t)?t:Rt(t,e,i||_t)}),Bt(),O.map(function(t){return!1===p(t)?t:p(e)||J(e)?t:t[0]}))}},i.distinctUntilArrayItemChanged=Bt,i.find=Rt,i.arrayRemove=function Xe(i,t,e){var n,r;return void 0===e&&(e=_t),r=J(t)?function o(i){return function(){for(var t=[],e=0;e<arguments.length;e++)t[e]=arguments[e];return!i.apply(void 0,b(t))}}(t):(n=lt(t),function(t){return!1===n.includes(pt(t)?t[e]:t)}),Array.isArray(i)?i.filter(r):function(t){var e;return(e={})[i]=t[i].filter(r),e}},i.createEntityQuery=function Ye(t,e){return new Qt(t,e)},i.createEntityStore=function Ge(t,e){return new At(t,e)},i.createQuery=function Ze(t){return new kt(t)},i.createStore=function ti(t,e){return new at(t,e)},i.cacheable=function ei(t,e){return t._cache().value?s.EMPTY:e},i.combineQueries=function ii(t){return s.combineLatest(t).pipe(O.auditTime(0))},i.EntityService=Ve,i.EntityActions=St,i.dispatchDeleted=G,i.dispatchAdded=Z,i.dispatchUpdate=tt,i.$$deleteStore=W,i.$$addStore=X,i.$$updateStore=Y,i.ɵa=it,i.ɵb=nt,Object.defineProperty(i,"__esModule",{value:!0})});
//# sourceMappingURL=datorama-akita.umd.min.js.map