type-r2
Version:
Serializable, validated, and observable data layer for modern JS applications
1 lines • 60.4 kB
JavaScript
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports):"function"==typeof define&&define.amd?define(["exports"],e):e((t="undefined"!=typeof globalThis?globalThis:t||self).Nested={})}(this,function(i){"use strict";function a(t,e){for(var n in e)e.hasOwnProperty(n)&&!t.hasOwnProperty(n)&&(t[n]=e[n]);if(2<arguments.length)for(var r=2;r<arguments.length;r++){var o=arguments[r];o&&a(t,o)}return t}function M(t){if(null===t)return!0;switch(typeof t){case"number":case"string":case"boolean":return!0;case"object":var e=Object.getPrototypeOf(t);if(e===Object.prototype||e===Array.prototype)return V(t,M)}return!1}function J(t){return Object.getPrototypeOf(t.prototype).constructor}function U(t){if(t)for(var e in t)if(t.hasOwnProperty(e))return!1;return!0}function B(t,e){if(Object.getPrototypeOf(t)===z){for(var n,r=t,o=e,i=0;i<r.length;i++)if(n=o(r[i],i))return n}else{var s,a,u=t,c=e;for(a in u)if(u.hasOwnProperty(a)&&(s=c(u[a],a)))return s}}function V(t,e){return!B(t,function(t){return!e(t)})}function H(t){for(var e,n={},r={},o=1;o<arguments.length;o++)r[arguments[o]]=!0;for(e in t)!r.hasOwnProperty(e)&&t.hasOwnProperty(e)&&(n[e]=t[e]);return n}function s(t,e,n){for(var r in e){var o;e.hasOwnProperty(r)&&void 0!==(o=n(e[r],r))&&(t[r]=o)}return t}function u(t,e){for(var n in e)e.hasOwnProperty(n)&&(t[n]=e[n]);if(2<arguments.length)for(var r=2;r<arguments.length;r++){var o=arguments[r];o&&u(t,o)}return t}function F(t){var e,n=!0;return function(){return n&&(n=!1,e=t.apply(this,arguments),t=null),e}}var z=Array.prototype,q=Date.prototype,W=Object.prototype;function K(t,e){if(t===e)return!1;if(t&&e&&"object"==typeof t&&"object"==typeof e){var n=Object.getPrototypeOf(t);if(n!==Object.getPrototypeOf(e))return!0;switch(n){case q:return+t!=+e;case z:var r=t,o=e;if(r.length!==o.length)return!0;for(var i=0;i<r.length;i++)if(K(r[i],o[i]))return!0;return!1;case W:case null:var s=t,a=e,u=Object.keys(s);if(u.length!==Object.keys(a).length)return!0;for(var c=0;c<u.length;c++){var l=u[c];if(!a.hasOwnProperty(l)||K(s[l],a[l]))return!0}return!1}}return!0}var L=Object.create(null);function c(t){var e=Object.create(L);return t?u(e,t):e}L.hasOwnProperty=W.hasOwnProperty;var Z=Object.freeze({__proto__:null,assign:u,assignToClassProto:function(t,e){for(var n=[],r=2;r<arguments.length;r++)n[r-2]=arguments[r];for(var o=0,i=n;o<i.length;o++){var s=i[o],a=e[s];void 0!==a&&(t.prototype[s]=a)}},defaults:a,every:V,fastAssign:function(t,e){for(var n in e)t[n]=e[n];return t},fastDefaults:function(t,e){for(var n in e)void 0===t[n]&&(t[n]=e[n]);return t},getBaseClass:J,getPropertyDescriptor:function(t,e){for(var n,r=t;!n&&r;r=Object.getPrototypeOf(r))n=Object.getOwnPropertyDescriptor(r,e);return n},hashMap:c,isEmpty:U,isValidJSON:M,keys:function(t){return t?Object.keys(t):[]},notEqual:K,omit:H,once:F,some:B,transform:s}),G=(e.prototype.merge=function(t){this.handlers=this.handlers.concat(t.handlers)},e.prototype.addEventsMap=function(t){for(var e in t)this.addEvent(e,t[e])},e.prototype.bubbleEvents=function(t){for(var e=0,n=t.split(rt);e<n.length;e++){var r=n[e];this.addEvent(r,X(r))}},e.prototype.addEvent=function(t,e){for(var n=this.handlers,r=0,o=t.split(rt);r<o.length;r++){var i=o[r];n.push(new $(i,e))}},e.prototype.subscribe=function(t,e){for(var n=0,r=this.handlers;n<r.length;n++){var o=r[n];l(e,o.name,o.callback,t)}},e.prototype.unsubscribe=function(t,e){for(var n=0,r=this.handlers;n<r.length;n++){var o=r[n];h(e,o.name,o.callback,t)}},e);function e(t){this.handlers=[],t&&(t instanceof e?this.handlers=t.handlers.slice():t&&this.addEventsMap(t))}var $=function(t,e){this.name=t,this.callback=!0===e?X(t):"string"==typeof e?function(){var t=this[e];t&&t.apply(this,arguments)}:e},Q={};function X(i){return Q[i]||(Q[i]=function(t,e,n,r,o){void 0===r&&void 0===o||st(this,i,t,e,n,r,o),void 0!==n?p(this,i,t,e,n):it(this,i,t,e)})}var Y=function(t,e,n){void 0===n&&(n=null),this.callback=t,this.context=e,this.next=n};function tt(t,e,n,r){for(var o,i,s=t[e],a=s;a;a=a.next)n&&n!==a.callback&&n!==a.callback._callback||r&&r!==a.context?(i=a,o=o||a):i&&(i.next=a.next);s!==o&&(t[e]=o)}function et(t,e,n,r){for(var o=t;o;o=o.next)o.callback.call(o.context,e,n,r)}function l(t,e,n,r){n&&((t=t._events||(t._events=Object.create(null)))[e]=new Y(n,r,t[e]))}function nt(t,e,n,r){var o;n&&((o=F(function(){h(t,e,o),n.apply(this,arguments)}))._callback=n,l(t,e,o,r))}function h(t,e,n,r){var o=t._events;if(o)if(n||r)if(e)tt(o,e,n,r);else for(var i in o)tt(o,i,n,r);else e?o[e]=void 0:t._events=void 0}var rt=/\s+/;function ot(t,e,n,r,o){if(rt.test(n))for(var i=0,s=n.split(rt);i<s.length;i++)t(e,s[i],r,o);else t(e,n,r,o)}function it(t,e,n,r){t=t._events;if(t){for(var o=t[e],t=t.all,i=n,s=r,a=o;a;a=a.next)a.callback.call(a.context,i,s);et(t,e,n,r)}}function p(t,e,n,r,o){t=t._events;if(t){var i=t[e],t=t.all;et(i,n,r,o);for(var s=e,a=n,u=r,c=o,l=t;l;l=l.next)l.callback.call(l.context,s,a,u,c)}}function st(t,e,n,r,o,i,s){t=t._events;if(t){for(var a=t[e],t=t.all,u=n,c=r,l=o,h=i,p=s,f=a;f;f=f.next)f.callback.call(f.context,u,c,l,h,p);for(var d=e,v=n,y=r,g=o,m=i,b=s,_=t;_;_=_.next)_.callback.call(_.context,d,v,y,g,m,b)}}var at=Object.freeze({__proto__:null,EventDescriptor:$,EventHandler:Y,EventMap:G,off:h,on:l,once:nt,strings:ot,trigger2:it,trigger3:p,trigger5:st}),ut=function(t,e){return(ut=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 f(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Class extends value "+String(e)+" is not a constructor or null");function n(){this.constructor=t}ut(t,e),t.prototype=null===e?Object.create(e):(n.prototype=e.prototype,new n)}var y=function(){return(y=Object.assign||function(t){for(var e,n=1,r=arguments.length;n<r;n++)for(var o in e=arguments[n])Object.prototype.hasOwnProperty.call(e,o)&&(t[o]=e[o]);return t}).apply(this,arguments)};function ct(t,e){var n={};for(o in t)Object.prototype.hasOwnProperty.call(t,o)&&e.indexOf(o)<0&&(n[o]=t[o]);if(null!=t&&"function"==typeof Object.getOwnPropertySymbols)for(var r=0,o=Object.getOwnPropertySymbols(t);r<o.length;r++)e.indexOf(o[r])<0&&Object.prototype.propertyIsEnumerable.call(t,o[r])&&(n[o[r]]=t[o[r]]);return n}function d(t,e,n,r){var o,i=arguments.length,s=i<3?e:null===r?r=Object.getOwnPropertyDescriptor(e,n):r;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)s=Reflect.decorate(t,e,n,r);else for(var a=t.length-1;0<=a;a--)(o=t[a])&&(s=(i<3?o(s):3<i?o(e,n,s):o(e,n))||s);return 3<i&&s&&Object.defineProperty(e,n,s),s}ht.define=function(t,e){void 0===t&&(t={});var n=J(this),e=(e&&u(this,e),t.mixins),t=ct(t,["mixins"]);return e&&this.mixins.merge(e),this.mixins.mergeObject(this.prototype,t,!0),this.mixins.mergeObject(this.prototype,this.mixins.getStaticDefinitions(n),!0),this.onDefine&&this.onDefine(this.mixins.definitions,n),this.mixins.mergeInheritedMembers(n),this},ht.extend=function(t,e){var n,r;function o(){return null!==r&&r.apply(this,arguments)||this}return t&&t.hasOwnProperty("constructor")?f(n=t.constructor,this):(f(o,r=this),n=o),pt(n),t&&n.define(t,e),n};var lt=ht;function ht(){}function pt(t){var e=J(t);t.__super__=e.prototype,t.define||v.get(lt).populate(t),v.get(t),t.onExtend&&t.onExtend(e)}function o(e){if("function"!=typeof e)return function(t){pt(t),t.define(e)};pt(e),e.define()}function ft(e){return function(t){t=v.get(t);t.definitionRules=a(c(),e,t.definitionRules)}}function dt(r,o){return function(t,e){var n;v.get(t.constructor).mergeObject(t,((t={})[r]=((n={})[e]=o,n),t))}}g.get=function(t){var e=t.mixins;return e&&t===e.Class?e:t.mixins=new g(t)},g.prototype.getStaticDefinitions=function(n){var t=c(),r=this.Class;return s(t,this.definitionRules,function(t,e){if(n[e]!==r[e])return r[e]})},g.prototype.merge=function(t){for(var e=this.Class.prototype,n=(this.mergeRules,this.appliedMixins=this.appliedMixins.slice()),r=0,o=t;r<o.length;r++){var i,s=o[r];Array.isArray(s)?this.merge(s):n.indexOf(s)<0&&(n.push(s),"function"==typeof s?(this.mergeObject(this.Class,s),(i=s.mixins)&&(this.mergeRules=a(c(),this.mergeRules,i.mergeRules),this.definitionRules=a(c(),this.definitionRules,i.definitionRules),this.appliedMixins=this.appliedMixins.concat(i.appliedMixins)),this.mergeObject(e,s.prototype)):this.mergeObject(e,s))}},g.prototype.populate=function(){for(var t=[],e=0;e<arguments.length;e++)t[e]=arguments[e];for(var n=0,r=t;n<r.length;n++)g.get(r[n]).merge([this.Class])},g.prototype.mergeObject=function(r,o,i){for(var s=this,t=o,e=function(t){var e,n=Object.getOwnPropertyDescriptor(o,t);(e=s.definitionRules[t])&>(s.definitions,t,n,e,i),e&&e!==m.protoValue||gt(r,t,n,s.mergeRules[t],i)},n=vt[typeof t],a=0,u=Object.getOwnPropertyNames(t);a<u.length;a++){var c=u[a];n[c]||e(c)}},g.prototype.mergeInheritedMembers=function(t){var e=this.mergeRules,n=this.Class;if(e){var r,o=n.prototype,i=t.prototype;for(r in e){var s=e[r];o.hasOwnProperty(r)&&r in i&&(o[r]=mt(o[r],i[r],s))}}};var v=g;function g(t){this.Class=t,this.definitions={};t=J(t).mixins;this.mergeRules=t&&t.mergeRules||c(),this.definitionRules=t&&t.definitionRules||c(),this.appliedMixins=t&&t.appliedMixins||[]}var vt={function:c({length:!0,prototype:!0,caller:!0,arguments:!0,name:!0,__super__:!0}),object:c({constructor:!0})};function yt(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];return function(t){return v.get(t).merge(e)}}var m=function(e){return function(t){t=v.get(t);t.mergeRules=a(e,t.mergeRules)}};function gt(t,e,n,r,o){var i;t.hasOwnProperty(e)?(i=Object.getOwnPropertyDescriptor(t,e)).configurable&&"value"in i&&(t[e]=o?mt(n.value,i.value,r):mt(i.value,n.value,r)):Object.defineProperty(t,e,n)}function mt(t,e,n){return void 0===t?e:n&&void 0!==e?n(t,e):t}m.value=function(t,e){return t},m.protoValue=function(t,e){return t},m.merge=function(t,e){return a({},t,e)},m.pipe=function(e,n){return function(t){return e.call(this,n.call(this,t))}},m.defaults=function(t,e){return function(){return a(t.apply(this,arguments),e.apply(this,arguments))}},m.classFirst=function(t,e){return function(){t.apply(this,arguments),e.apply(this,arguments)}},m.classLast=function(t,e){return function(){e.apply(this,arguments),t.apply(this,arguments)}},m.every=function(t,e){return function(){return t.apply(this,arguments)&&e.apply(this,arguments)}},m.some=function(t,e){return function(){return t.apply(this,arguments)||e.apply(this,arguments)}};var bt=ot,_t=l,wt=h,Ot=nt,Ct=st,Et=it,jt=p,At=0;function St(){return"l"+At++}t.onDefine=function(t,e){var n,r=t.localEvents,o=t._localEvents,t=t.properties;(r||o)&&(n=new G(this.prototype._localEvents),r&&n.addEventsMap(r),o&&n.merge(o),this.prototype._localEvents=n),t&&Object.defineProperties(this.prototype,s({},t,Nt))},t.prototype.initialize=function(){},t.prototype.on=function(t,e,n){if("string"==typeof t)bt(_t,this,t,e,n);else for(var r in t)bt(_t,this,r,t[r],n||e);return this},t.prototype.once=function(t,e,n){if("string"==typeof t)bt(Ot,this,t,e,n);else for(var r in t)bt(Ot,this,r,t[r],n||e);return this},t.prototype.off=function(t,e,n){if(t)if("string"==typeof t)bt(wt,this,t,e,n);else for(var r in t)bt(wt,this,r,t[r],n||e);else wt(this,void 0,e,n);return this},t.prototype.trigger=function(t,e,n,r,o,i){return void 0!==o||void 0!==i?Ct(this,t,e,n,r,o,i):void 0!==r?jt(this,t,e,n,r):Et(this,t,e,n),this},t.prototype.listenTo=function(t,e,n){return t&&(xt(this,t),t.on(e,n||"object"!=typeof e?n:this,this)),this},t.prototype.listenToOnce=function(t,e,n){return t&&(xt(this,t),t.once(e,n||"object"!=typeof e?n:this,this)),this},t.prototype.stopListening=function(t,e,n){var r=this._listeningTo;if(r){var o=!(e||n),i=n||"object"!=typeof e?n:this;if(t){n=r[t.cid];n&&(o&&delete r[t.cid],n.off(e,i,this))}else if(null==t){for(var s in r)r[s].off(e,i,this);o&&(this._listeningTo=void 0)}}return this},t.prototype.dispose=function(){this._disposed||(this.stopListening(),this.off(),this._disposed=!0)};var Pt=d([o,ft({properties:m.merge,localEvents:m.merge})],t);function t(){this._events=void 0,this._listeningTo=void 0,this.cid=St(),this.initialize.apply(this,arguments)}var n=H(Pt.prototype,"constructor","initialize");function Nt(t){if(t)return"function"==typeof t?{get:t,configurable:!0}:t}function xt(t,e){(t._listeningTo||(t._listeningTo=Object.create(null)))[e.cid||(e.cid=St())]=e}var Tt,Dt="undefined"!=typeof process&&process.env&&"production"===process.env.NODE_ENV,It=Dt?["error","info"]:["error","warn","debug","info","log"],Rt=(f(kt,Tt=Pt),kt.prototype.logToConsole=function(i,s){return this.on(i,function(t,e,n){if(!s||s.test(t)){var r,o=["[".concat(t,"] ").concat(e)];for(r in n)o.push("\n\t".concat(r,":"),Mt(n[r]));console[i].apply(console,o)}})},kt.prototype.throwOn=function(t,r){return this.on(t,function(t,e,n){if(!r||r.test(t))throw new Error("[".concat(t,"] ").concat(e))})},kt.prototype.count=function(r,o){var i=this;return this.on(r,function(t,e,n){o&&!o.test(t)||(i.counter[r]=(i.counter[r]||0)+1)})},kt.prototype.on=function(t,e){return Tt.prototype.on.call(this,t,e)},d([o],kt));function kt(){var t=null!==Tt&&Tt.apply(this,arguments)||this;return t.counter={},t}var Mt="undefined"==typeof window?function(t){var e;return t&&"object"==typeof t?(e=t.__inner_state__||t,e=Array.isArray(e)?"[ length = ".concat(e.length," ]"):"{ ".concat(Object.keys(e).join(", ")," }"),t.constructor.name+" "+e):JSON.stringify(t)}:function(t){return t},Jt=new Rt;if("undefined"!=typeof console)for(var Ut=0,Bt=It;Ut<Bt.length;Ut++)Jt.logToConsole(Bt[Ut]);var Vt=new Rt,Ht=(Vt.throwOn("error").throwOn("warn"),Jt.trigger.bind(Jt));function Ft(n,t,r,o){return zt(n),n._ioPromise=t.then(function(t){n._ioPromise=null;var e=o?o(t):t;return qt(n,"sync",n,t,r),e}).catch(function(t){throw n._ioPromise=null,qt(n,"error",n,t,r),t}),n._ioPromise.abort=t.abort,n._ioPromise}function zt(t){t._ioPromise&&t._ioPromise.abort&&(t._ioPromise.abort(),t._ioPromise=null)}function qt(t){for(var e=[],n=1;n<arguments.length;n++)e[n-1]=arguments[n];t.trigger.apply(t,e);t=t.collection;t&&t.trigger.apply(t,e)}var Wt=/\^|(store\.[^.]+)|([^.]+)/g,Kt=function(t,e){void 0===e&&(e=!1),t=t.match(Wt).map(function(t){return"^"===t||"owner"===t?"getOwner()":"~"===t[0]?'getStore().get("'.concat(t.substr(1),'")'):0===t.indexOf("store.")?'getStore().get("'.concat(t.substr(6),'")'):t}),this.tail=e&&t.pop(),this.local=!t.length,this.resolve=new Function("self","\n var v = self.".concat(t.shift(),";\n \n ").concat(t.map(function(t){return"\n v = v && v.".concat(t,";\n ")}).join(""),"\n\n return v;\n "))};function Lt(t,e,n){for(var r=e.match(Wt),o=r.length-1,i=t,s=0;s<o;s++){var a=r[s];switch(a){case"~":i=i.getStore();break;case"^":i=i.getOwner();break;default:i=i.get(a)}if(!i)return}return n(i,r[o])}Gt.prototype.each=function(t){var e,n=this.error,r=this.nested;for(e in n&&t(n,null),r)t(r[e],e)},Gt.prototype.eachError=function(n,r){this.each(function(t,e){t instanceof Gt?t.eachError(n,r.get(e)):n(t,e,r)})};var Zt=Gt;function Gt(t){this.length=t._validateNested(this.nested={}),(this.error=t.validate(t))&&this.length++}var $t,Qt=p,Xt=l,Yt=h,b=(i.ItemsBehavior=void 0,(w=i.ItemsBehavior||(i.ItemsBehavior={}))[w.share=1]="share",w[w.listen=2]="listen",w[w.persistent=4]="persistent",($t=r).onDefine=function(t,e){t.endpoint&&(this.prototype._endpoint=t.endpoint),Pt.onDefine.call(this,t,e)},r.onExtend=function(t){t.create===this.create&&(this.create=$t.create)},r.create=function(t,e){return new this(t,e)},Object.defineProperty(r.prototype,"__inner_state__",{get:function(){return null},enumerable:!1,configurable:!0}),r.prototype.dispose=function(){this._disposed||(zt(this),this._owner=void 0,this._ownerKey=void 0,this.off(),this.stopListening(),this._disposed=!0)},r.prototype.onChanges=function(t,e){Xt(this,this._changeEventName,t,e)},r.prototype.offChanges=function(t,e){Yt(this,this._changeEventName,t,e)},r.prototype.listenToChanges=function(t,e){this.listenTo(t,t._changeEventName,e)},r.prototype.transaction=function(t,e){var n=_.begin(this),t=t.call(this,this);t&&this.set(t),n&&_.commit(this)},r.prototype.assignFrom=function(e){var n=this;return this.transaction(function(){n.set(e.__inner_state__||e,{merge:!0});var t=e._changeToken;t&&(n._changeToken=t)}),this},r.from=function(t,e){var n=(e=void 0===e?{}:e).strict,e=ct(e,["strict"]),t=this.create(t,y(y({},e),{logger:n?Vt:void 0}));return n&&t.validationError&&t.eachValidationError(function(t,e,n){throw new Error("".concat(n.getClassName(),".").concat(e,": ").concat(t))}),t},r.prototype.parse=function(t,e){return t},r.prototype.deepGet=function(t){return Lt(this,t,function(t,e){return t.get?t.get(e):t[e]})},r.prototype.getOwner=function(){return this._owner},r.prototype.getStore=function(){var t=this._owner;return t?t.getStore():this._defaultStore},r.prototype.hasPendingIO=function(){return this._ioPromise},r.prototype.getEndpoint=function(){return function t(e){var n=e.collection;if(n)return t(n);if(e._owner)return(n=e._owner._endpoints)&&n[e._ownerKey]}(this)||this._endpoint},Object.defineProperty(r.prototype,"validationError",{get:function(){var t=this._validationError||(this._validationError=new Zt(this));return t.length?t:null},enumerable:!1,configurable:!0}),r.prototype.validate=function(t){},r.prototype.getValidationError=function(t){var e=this.validationError;return(t?e&&e.nested[t]:e)||null},r.prototype.deepValidationError=function(t){return Lt(this,t,function(t,e){return t.getValidationError(e)})},r.prototype.eachValidationError=function(t){var e=this.validationError;e&&e.eachError(t,this)},r.prototype.isValid=function(t){return!this.getValidationError(t)},r.prototype.valueOf=function(){return this.cid},r.prototype.toString=function(){return this.cid},r.prototype.getClassName=function(){var t=this.constructor.name;if("Subclass"!==t)return t},$t=d([o,ft({endpoint:m.value}),yt(Pt)],r));function r(t){this._changeToken={},this._transaction=!1,this._isDirty=null,this._owner=void 0,this._ownerKey=void 0,this._validationError=void 0,this.cid=this.cidPrefix+t}var _={begin:function(t){return!t._transaction&&(t._transaction=!0)},markAsDirty:function(t,e){var n=!e.silent;return n&&(t._isDirty=e),t._changeToken={},t._validationError=void 0,n},commit:function(t,e){var n=t._isDirty;if(n){for(;t._isDirty;){var r=t._isDirty;t._isDirty=null,Qt(t,t._changeEventName,t,r,e)}t._transaction=!1;var o=t._owner;o&&o!==e&&o._onChildrenChange(t,n)}else t._isDirty=null,t._transaction=!1},aquire:function(t,e,n){if(e._owner)throw new ReferenceError("Trying to aquire ownership for an object already having an owner");e._owner=t,e._ownerKey=n},free:function(t,e){t===e._owner&&(e._owner=void 0,e._ownerKey=void 0)}};var te=_.begin,ee=_.markAsDirty,ne=_.commit,re=p;function oe(t,e,n){var r=ie(t),o={};t._attributes[e].doUpdate(n,t,o)&&(se(t,o),re(t,"change:"+e,t,t.attributes[e],o)),r&&ne(t)}function ie(t){return!(!te(t)||(t._previousAttributes=new t.AttributesCopy(t.attributes),t._changedAttributes=null))}function se(t,e){return t._changedAttributes&&(t._changedAttributes=null),ee(t,e)}var w={transaction:function(t,e){var n=ie(this);t.call(this,this),n&&ne(this)},_onChildrenChange:function(t,e){var t=t._ownerKey,n=this._attributes[t];n&&!n.propagateChanges||this.forceAttributeChange(t,e)},forceAttributeChange:function(t,e){void 0===e&&(e={});var n=ie(this);se(this,e)&&re(this,"change:"+t,this,this.attributes[t],e),n&&ne(this)},_createTransaction:function(t,e){void 0===e&&(e={});var n,r=ie(this),o=[],i=[],s=this._attributes,a=e.parse?this.parse(t,e):t;if(ue(this,a,e)){for(var u in a){var c=s[u];c?c.doUpdate(a[u],this,e,i)&&o.push(u):(n=n||[]).push("'".concat(u,"'"))}n&&ae(this,n,{values:a},e)}if(o.length&&se(this,e))return new ce(this,r,i,o);for(var l=0,h=i;l<h.length;l++)h[l].commit(this);r&&ne(this)}};function ae(t,e,n,r){t._log("warn","Type-R:UnknownAttrs","undefined attributes ".concat(e.join(", ")," are ignored."),n,r.logger)}function ue(t,e,n){if(e&&e.constructor===Object)return 1;t._log("error","Type-R:InvalidObject","update with non-object is ignored!",{values:e},n.logger)}le.prototype.commit=function(t){for(var e=this.nested,n=this.object,r=this.changes,o=0,i=e;o<i.length;o++)i[o].commit(n);for(var s=n.attributes,a=n._isDirty,u=0,c=r;u<c.length;u++){var l=c[u];re(n,"change:"+l,n,s[l],a)}this.isRoot&&ne(n,t)};var ce=le;function le(t,e,n,r){this.object=t,this.isRoot=e,this.nested=n,this.changes=r}var he=K,pe={},O=(C.prototype.canBeUpdated=function(t,e,n){},C.prototype.transform=function(t,e,n,r){return t},C.prototype.convert=function(t,e,n,r){return t},C.prototype.isChanged=function(t,e){return he(t,e)},C.prototype.handleChange=function(t,e,n,r){},C.prototype.create=function(){},C.prototype.clone=function(t,e){return t},C.prototype.dispose=function(t,e){this.handleChange(void 0,e,t,pe)},C.prototype.validate=function(t,e,n){},C.prototype.toJSON=function(t,e,n){return t&&t.toJSON?t.toJSON(n):t},C.prototype.createPropertyDescriptor=function(){var e=this.name,t=this.getHook;if("id"!==e)return{set:function(t){oe(this,e,t)},get:t?function(){return t.call(this,this.attributes[e],e)}:function(){return this.attributes[e]},configurable:!0}},C.prototype.initialize=function(t,e){},C.prototype.doInit=function(t,e,n){t=void 0===t?this.defaultValue():t,t=this.transform(t,void 0,e,n);return this.handleChange(t,void 0,e,n),t},C.prototype.doUpdate=function(t,e,n,r){var o=this.name,i=e.attributes,s=i[o],t=this.transform(t,s,e,n);return i[o]=t,!!this.isChanged(t,s)&&(this.handleChange(t,s,e,n),!0)},C.prototype._log=function(t,e,n,r,o,i){o._log(t,e,"".concat(o.getClassName(),".").concat(this.name," ").concat(n),{"New value":r,"Prev. value":o.attributes[this.name]},i)},C.prototype.defaultValue=function(){return this.value},C);function C(t,e){this.name=t,this.getHook=null,this.options=e;var r,o,i,t=y({getHooks:[],transforms:[],changeHandlers:[]},e),e=(t.getHooks=t.getHooks.slice(),t.transforms=t.transforms.slice(),t.changeHandlers=t.changeHandlers.slice(),t.value),n=t.valueFn,s=t.type,a=t.parse,u=t.toJSON,c=t.changeEvents,l=t.validate,h=t.getHooks,p=t.transforms,f=t.changeHandlers,d=(this.value=e,this.type=s,n?this.defaultValue=n:!t.hasCustomDefault&&s?this.defaultValue=this.create:M(e)?(console.warn("any.ts creating new function with json",this,e),this.defaultValue=new Function("return ".concat(JSON.stringify(e),";"))):this.defaultValue=this.defaultValue,this.propagateChanges=!1!==c,this.toJSON=void 0===u?this.toJSON:u,this.validate=l||this.validate,t.isRequired&&(this.validate=(r=this.validate,function(t,e,n){return e?r.call(this,t,e,n):"Required"})),p.unshift(this.convert),this.get&&h.unshift(this.get),this.initialize.call(this,t),h.length&&(o=this.getHook=h.reduce(fe),i=this.validate,this.validate=function(t,e,n){return i.call(this,t,o.call(t,e,n),n)}),this.transform=p.length?p.reduce(de):this.transform,this.handleChange=f.length?f.reduce(ve):this.handleChange,this.doInit),v=this.doUpdate;this.doInit=a?function(t,e,n){return d.call(this,n.parse&&void 0!==t?a.call(e,t,this.name):t,e,n)}:d,this.doUpdate=a?function(t,e,n,r){return v.call(this,n.parse&&void 0!==t?a.call(e,t,this.name):t,e,n,r)}:v}function fe(n,r){return function(t,e){return r.call(this,n.call(this,t,e),e)}}function de(o,i){return function(t,e,n,r){return i.call(this,o.call(this,t,e,n,r),e,n,r)}}function ve(o,i){return function(t,e,n,r){o.call(this,t,e,n,r),i.call(this,t,e,n,r)}}f(E,ye=O),E.prototype.create=function(){return new this.type},E.prototype.convert=function(t){return null==t||t instanceof this.type?t:new this.type(t)},E.prototype.toJSON=function(t,e,n){return t&&t.toJSON?t.toJSON(n):t},E.prototype.clone=function(t){return new this.type(this.toJSON(t))},E.prototype.isChanged=function(t,e){return t!==e};var ye,ge=E;function E(){return null!==ye&&ye.apply(this,arguments)||this}f(j,me=O),j.prototype.dispose=function(){},j.prototype.create=function(){return this.type()},j.prototype.toJSON=function(t){return t},j.prototype.convert=function(t){return null==t?t:this.type(t)},j.prototype.isChanged=function(t,e){return t!==e},j.prototype.clone=function(t){return t},j.prototype.doInit=function(t,e,n){return this.transform(void 0===t?this.value:t,void 0,e,n)},j.prototype.doUpdate=function(t,e,n,r){var o=this.name,i=e.attributes,s=i[o];return s!==(i[o]=this.transform(t,s,e,n))},j.prototype.initialize=function(){this.options.hasCustomDefault||(this.value=this.type())};var me,be=j;function j(){return null!==me&&me.apply(this,arguments)||this}f(Oe,_e=be),Oe.prototype.create=function(){return 0},Oe.prototype.convert=function(t,e,n,r){var o=null==t?t:this.type(t);return o!=o&&this._log("error","Type-R:InvalidNumber","Number attribute is assigned with an invalid number",t,n,r.logger),o},Oe.prototype.validate=function(t,e,n){if(null!=e&&!isFinite(e))return n+" is not valid number"};var _e,we=Oe;function Oe(){return null!==_e&&_e.apply(this,arguments)||this}f(A,Ce=O),A.prototype.toJSON=function(t){return t},A.prototype.dispose=function(){},A.prototype.create=function(){return[]},A.prototype.convert=function(t,e,n,r){return null==t||Array.isArray(t)?t:(this._log("error","Type-R:InvalidArray","Array attribute assigned with non-array value",t,n,r.logger),[])},A.prototype.clone=function(t){return t&&t.slice()};var Ce,Ee=A;function A(){return null!==Ce&&Ce.apply(this,arguments)||this}f(Se,je=O),Se.prototype.create=function(){return{}},Se.prototype.convert=function(t,e,n,r){return null==t||"object"==typeof t?t:(this._log("error","Type-R:InvalidObject","Object attribute is assigned with non-object value",t,n,r.logger),{})};var je,Ae=Se;function Se(){return null!==je&&je.apply(this,arguments)||this}function Pe(){}f(Te,Ne=O),Te.prototype.toJSON=function(t){},Te.prototype.create=function(){return Pe},Te.prototype.dispose=function(){},Te.prototype.convert=function(t,e,n,r){return null==t||"function"==typeof t?t:(this._log("error","Type-R:InvalidFunction","Function attribute assigned with non-function value",t,n,r.logger),Pe)},Te.prototype.clone=function(t){return t};var Ne,xe=Te;function Te(){return null!==Ne&&Ne.apply(this,arguments)||this}f(S,De=O),S.prototype.create=function(){return new Date},S.prototype.convert=function(t,e,n,r){var o,i;return null==t||t instanceof Date?t:((i=(o=new Date(t)).getTime())!=i&&this._log("error","Type-R:InvalidDate","Date attribute assigned with invalid date",t,n,r.logger),o)},S.prototype.validate=function(t,e,n){if(null!=e){e=e.getTime();if(e!=e)return n+" is Invalid Date"}},S.prototype.toJSON=function(t){return t&&t.toISOString()},S.prototype.isChanged=function(t,e){return(t&&t.getTime())!==(e&&e.getTime())},S.prototype.doInit=function(t,e,n){return this.transform(void 0===t?this.defaultValue():t,void 0,e,n)},S.prototype.doUpdate=function(t,e,n,r){var o=this.name,i=e.attributes,s=i[o];return this.isChanged(s,i[o]=this.transform(t,s,e,n))},S.prototype.clone=function(t){return t&&new Date(t.getTime())},S.prototype.dispose=function(){};var De,Ie=S;function S(){return null!==De&&De.apply(this,arguments)||this}function Re(t){return!isNaN(new Date(t).getTime())}Re("2011-11-29T15:52:30.5")&&Re("2011-11-29T15:52:30.52")&&Re("2011-11-29T15:52:18.867")&&Re("2011-11-29T15:52:18.867Z")&&Re("2011-11-29T15:52:18.867-03:30")||(Ie.prototype.convert=function(t){return null==t||t instanceof Date?t:new Date(function(t){var e,n,r=0;if(n=Me.exec(t)){for(var o,i=0;o=ke[i];++i)n[o]=+n[o]||0;n[2]=(+n[2]||1)-1,n[3]=+n[3]||1,"Z"!==n[8]&&void 0!==n[9]&&(r=60*n[10]+n[11],"+"===n[9])&&(r=0-r),e=Date.UTC(n[1],n[2],n[3],n[4],n[5]+r,n[6],n[7])}else e=Date.parse(t);return e}(t))});var ke=[1,4,5,6,7,10,11],Me=/^(\d{4}|[+\-]\d{6})(?:-(\d{2})(?:-(\d{2}))?)?(?:T(\d{2}):(\d{2})(?::(\d{2})(?:\.(\d{3}))?)?(?:(Z)|([+\-])(\d{2})(?::(\d{2}))?)?)?$/;var Je,Ue=_.free,Be=_.aquire,Ve=(f(P,Je=O),P.prototype.clone=function(t){return t&&t.clone()},P.prototype.toJSON=function(t,e,n){return t&&t.toJSON(n)},P.prototype.doInit=function(t,e,n){t=n.clone?this.clone(t):void 0===t?this.defaultValue():t,t=this.transform(t,void 0,e,n);return this.handleChange(t,void 0,e,n),t},P.prototype.doUpdate=function(t,e,n,r){var o,i=this.name,s=e.attributes,a=s[i];return(o=this.canBeUpdated(a,t,n))?!(!(o=a._createTransaction(o,n))||(r?r.push(o):o.commit(e),!this.propagateChanges)):(r=this.transform(t,a,e,n),s[i]=r,!!this.isChanged(r,a)&&(this.handleChange(r,a,e,n),!0))},P.prototype.canBeUpdated=function(t,e,n){if(t&&null!=e)return e instanceof this.type?n.merge?e.__inner_state__:void 0:e},P.prototype.convert=function(t,e,n,r){return null==t?t:t instanceof this.type?(!t._shared||t._shared&i.ItemsBehavior.persistent||this._log("error","Type-R:InvalidCollection","aggregated collection attribute is assigned with shared collection type",t,n,r.logger),r.merge?t.clone():t._owner?(this._log("warn","Type-R:InvalidOwner","object alreay has an owner and was cloned. Use explicit object.clone() to dismiss this warning.",t,n,r.logger),t.clone()):t):this.type.create(t,r)},P.prototype.dispose=function(t,e){e&&this.handleChange(void 0,e,t,{})},P.prototype.validate=function(t,e){e=e&&e.validationError;if(e)return e},P.prototype.create=function(){return this.type.create()},P.prototype.initialize=function(t){t.changeHandlers.unshift(this._handleChange)},P.prototype._handleChange=function(t,e,n,r){e&&(Ue(n,e),r.unset||e.dispose()),t&&Be(n,t,this.name)},P);function P(){return null!==Je&&Je.apply(this,arguments)||this}var He,Fe=l,ze=h,qe=_.free,We=_.aquire,Ke=i.ItemsBehavior.listen|i.ItemsBehavior.share,Le=(f(N,He=O),N.prototype.doInit=function(t,e,n){t=n.clone?this.clone(t,e):void 0===t?this.defaultValue():t,t=this.transform(t,void 0,e,n);return this.handleChange(t,void 0,e,n),t},N.prototype.doUpdate=function(t,e,n,r){var o,i=this.name,s=e.attributes,a=s[i];return(o=this.canBeUpdated(a,t,n))?!(!(o=a._createTransaction(o,n))||(r?r.push(o):o.commit(e),!this.propagateChanges)):(r=this.transform(t,a,e,n),s[i]=r,!!this.isChanged(r,a)&&(this.handleChange(r,a,e,n),!0))},N.prototype.clone=function(t,e){var n;return t&&t._owner===e?(n=t.clone(),We(e,n,this.name),n):t},N.prototype.toJSON=function(){},N.prototype.canBeUpdated=function(t,e,n){if(t&&null!=e&&!(e instanceof this.type))return e},N.prototype.convert=function(t,e,n,r){return null==t||t instanceof this.type||(t=new this.type(t,r,Ke),We(n,t,this.name)),t},N.prototype.validate=function(t,e,n){},N.prototype.create=function(){return null},N.prototype._handleChange=function(t,e,n,r){e&&(e._owner===n?(qe(n,e),r.unset||e.dispose()):ze(e,e._changeEventName,this._onChange,n)),t&&t._owner!==n&&Fe(t,t._changeEventName,this._onChange,n)},N.prototype.dispose=function(t,e){e&&this.handleChange(void 0,e,t,{})},N.prototype.initialize=function(t){var r=this;this._onChange=this.propagateChanges?function(t,e,n){this!==n&&this.forceAttributeChange(r.name,e)}:Ze,t.changeHandlers.unshift(this._handleChange)},N);function N(){return null!==He&&He.apply(this,arguments)||this}function Ze(){}var Ge=[String,Number,Boolean,Date,Object,Array,Function],$e=[be,we,be,Ie,Ae,Ee,xe];function Qe(t){return t._metatype||function(t){t=Ge.indexOf(t);return t<0?ge:$e[t]}(t)}O.create=function(t,e){var n=t.type;return new(t._metatype||(n?Qe(n):O))(e,t)};var Xe=u,Ye=(x.prototype.check=function(r,o){function i(t,e,n){if(!r.call(t,e,n))return"function"==typeof(e=o||r.error||n+" is not valid")?e.call(t,n):e}var s=this.options.validate;return this.metadata({validate:s?function(t,e,n){return s(t,e,n)||i(t,e,n)}:i})},Object.defineProperty(x.prototype,"as",{get:function(){return dt("attributes",this)},enumerable:!1,configurable:!0}),Object.defineProperty(x.prototype,"isRequired",{get:function(){return this.required},enumerable:!1,configurable:!0}),Object.defineProperty(x.prototype,"required",{get:function(){return this.metadata({isRequired:!0})},enumerable:!1,configurable:!0}),x.prototype.endpoint=function(t){return this.metadata({endpoint:t})},x.prototype.watcher=function(t){return this.metadata({_onChange:t})},x.prototype.parse=function(t){return this.metadata({parse:t})},x.prototype.toJSON=function(t){return this.metadata({toJSON:"function"==typeof t?t:t?function(t,e,n){return t&&t.toJSON(n)}:tn})},x.prototype.get=function(t){return this.metadata({getHooks:this.options.getHooks.concat(t)})},x.prototype.set=function(o){return this.metadata({transforms:this.options.transforms.concat(function(t,e,n,r){return!this.isChanged(t,e)||void 0===(t=o.call(n,t,this.name))?e:this.convert(t,e,n,r)})})},x.prototype.changeEvents=function(t){return this.metadata({changeEvents:t})},x.prototype.events=function(t){var r=new G(t);return this.metadata({changeHandlers:this.options.changeHandlers.concat(function(t,e,n){e&&e.trigger&&r.unsubscribe(n,e),t&&t.trigger&&r.subscribe(n,t)})})},Object.defineProperty(x.prototype,"has",{get:function(){return this},enumerable:!1,configurable:!0}),x.prototype.metadata=function(t){var e=new x(this.options);return Xe(e.options,t),e},x.prototype.value=function(t){return"function"==typeof t?this.metadata({value:t(),hasCustomDefault:!0,valueFn:t}):this.metadata({value:t,hasCustomDefault:!0})},x.from=function(t){return t&&t instanceof x?t:("function"==typeof t?T:nn)(t)},x);function x(t){this.options={getHooks:[],transforms:[],changeHandlers:[]},t&&Xe(this.options,t)}function tn(){}function T(t,e){var n;return t instanceof Ye?t:(n=new Ye({type:t}),void 0===(t=t&&void 0===e?Qe(t).defaultValue:e)?n:n.value(t))}function en(t){return new Ye({value:null,type:t,_metatype:Le})}function nn(t){var e=function(t){switch(typeof t){case"number":return Number;case"string":return String;case"boolean":return Boolean;case"function":return Function;case"undefined":return;case"object":return t?t.constructor:void 0}}(t);return(e&&e.prototype instanceof b?en:T)(e).value(t)}function rn(t,e){return O.create(Ye.from(t).options,e)}function on(t,e,n){var r,t=s({},t,rn),o=a({},t,e),e=(e=o,n=n,e=Object.keys(e),(r=n.AttributesCopy||new Function("values","\n ".concat(e.map(function(t){return"\n this.".concat(t," = values.").concat(t,";\n ")}).join(""),"\n "))).prototype=Object.prototype,(n=n.Attributes||new Function("record","values","options","\n var _attrs = record._attributes;\n\n ".concat(e.map(function(t){return"\n this.".concat(t," = _attrs.").concat(t,".doInit( values.").concat(t,", record, options );\n ")}).join(""),"\n "))).prototype=Object.prototype,{Attributes:n,AttributesCopy:r});return y(y(y(y({},e),{_attributes:new e.AttributesCopy(o),_attributesArray:Object.keys(o).map(function(t){return o[t]}),properties:s({},t,function(t){return t.createPropertyDescriptor()})}),function(t){var e,n;for(n in t){var r=t[n].options._onChange;r&&(e=e||new G).addEvent("change:"+n,("string"==typeof r?function(t,n){var t=new Kt(t,!0),e=t.local,r=t.resolve,o=t.tail;return e?function(t,e){t[o](e,n)}:function(t,e){r(t)[o](e,n)}}:function(n,r){return function(t,e){n.call(t,e,r)}})(r,n))}return e?{_localEvents:e}:{}}(t)),{_endpoints:s({},o,function(t){return t.options.endpoint})})}var sn,an={save:function(e){var n=this,t=(void 0===e&&(e={}),this.getEndpoint()),r=this.toJSON(y({ioMethod:"save"},e));return Ft(this,this.isNew()?t.create(r,e,this):t.update(this.id,r,e,this),e,function(t){n.set(t,y({parse:!0,ioMethod:"save"},e))})},fetch:function(e){var n=this;return void 0===e&&(e={}),Ft(this,this.getEndpoint().read(this.id,e,this),e,function(t){return n.set(t,y({parse:!0,ioMethod:"fetch"},e))})},destroy:function(e){var n=this;return void 0===e&&(e={}),Ft(this,this.getEndpoint().destroy(this.id,e,this),e,function(){var t=n.collection;return t?t.remove(n,e):n.dispose(),n})}},un=u,cn=U,ln=0,D=(f(I,sn=b),I.onDefine=function(t,e){},Object.defineProperty(I,"ref",{get:function(){var n=this;return T(this).toJSON(function(t){return t?t.id:null}).parse(function(t){var e={};return e[n.prototype.idAttribute]=t,e})},enumerable:!1,configurable:!0}),I.extendAttrs=function(t){return this.defaults(t)},I.defaults=function(t){return this.extend({attributes:t})},I.prototype.previousAttributes=function(){return new this.AttributesCopy(this._previousAttributes)},Object.defineProperty(I.prototype,"__inner_state__",{get:function(){return this.attributes},enumerable:!1,configurable:!0}),Object.defineProperty(I.prototype,"changed",{get:function(){if(!(e=this._changedAttributes)){for(var t=this._previousAttributes,e={},n=this.attributes,r=0,o=this._attributesArray;r<o.length;r++){var i=o[r],s=i.name,a=n[s];i.isChanged(a,t[s])&&(e[s]=a)}this._changedAttributes=e}return e},enumerable:!1,configurable:!0}),I.prototype.changedAttributes=function(t){if(!t)return!!this.hasChanged()&&y({},this.changed);var e,n,r=!1,o=this._transaction?this._previousAttributes:this.attributes,i=this._attributes;for(n in t)i[n].isChanged(o[n],e=t[n])&&((r=r||{})[n]=e);return r},I.prototype.hasChanged=function(t){var e=this._previousAttributes;return!!e&&(t?this._attributes[t].isChanged(this.attributes[t],e[t]):!cn(this.changed))},I.prototype.previous=function(t){if(t){var e=this._previousAttributes;if(e)return e[t]}return null},I.prototype.isNew=function(){return null==this.id},I.prototype.has=function(t){return null!=this[t]},I.prototype.unset=function(t,e){var n,r=this[t];return this.set(((n={})[t]=void 0,n),y({unset:!0},e)),r},I.prototype.clear=function(t){var n=this,r=t&&t.nullify;return this.transaction(function(){n.forEach(function(t,e){return n[e]=r?null:void 0})},t),this},I.prototype.getOwner=function(){var t=this._owner;return this._ownerKey?t:t&&t._owner},Object.defineProperty(I.prototype,"id",{get:function(){return this.attributes[this.idAttribute]},set:function(t){oe(this,this.idAttribute,t)},enumerable:!1,configurable:!0}),I.prototype.defaults=function(t){void 0===t&&(t={});for(var e={},n=0,r=this._attributesArray;n<r.length;n++){var o=r[n],i=o.name,s=t[i];e[i]=void 0===s?o.defaultValue():s}return e},I.prototype.initialize=function(t,e){},I.prototype.clone=function(t){void 0===t&&(t={});var e=new this.constructor(this.attributes,{clone:!0});return t.pinStore&&(e._defaultStore=this.getStore()),e},I.prototype._validateNested=function(t){for(var e=0,n=this.attributes,r=0,o=this._attributesArray;r<o.length;r++){var i=o[r],s=i.name,i=i.validate(this,n[s],s);i&&(t[s]=i,e++)}return e},I.prototype.get=function(t){return this[t]},I.prototype.set=function(t,e){return t&&(t=this._createTransaction(t,e))&&t.commit(),this},I.prototype.toJSON=function(t){for(var e={},n=this.attributes,r=0,o=this._attributesArray;r<o.length;r++){var i=o[r],s=i.name,a=n[s];void 0!==a&&void 0!==(i=i.toJSON.call(this,a,s,t))&&(e[s]=i)}return e},I.prototype.parse=function(t,e){return t},I.prototype.deepSet=function(c,l,h){var p=this;return this.transaction(function(){for(var t,e=c.split("."),n=e.length-1,r=e[n],o=p,i=0;i<n;i++){var s=e[i],a=o.get?o.get(s):o[s];if(!a){var u=o._attributes;if(!u)return;u=u[s].create();h&&h.nullify&&u._attributes&&u.clear(h),o[s]=a=u}o=a}o.set?o.set(((t={})[r]=l,t),h):o[r]=l}),this},Object.defineProperty(I.prototype,"collection",{get:function(){return this._ownerKey?null:this._owner},enumerable:!1,configurable:!0}),I.prototype.dispose=function(){if(!this._disposed){for(var t=this.attributes,e=0,n=this._attributesArray;e<n.length;e++){var r=n[e];r.dispose(this,t[r.name])}sn.prototype.dispose.call(this)}},I.prototype._log=function(t,e,n,r,o){(o||Jt).trigger(t,e,this.getClassName()+" "+n,y(y({},r),{Record:this,"Attributes definition":this._attributes}))},I.prototype.getClassName=function(){return sn.prototype.getClassName.call(this)||"Record"},I.prototype._createTransaction=function(t,e){},I.prototype.forEach=function(n,r){var t,e=void 0!==r?function(t,e){return n.call(r,t,e)}:n,o=this.attributes;for(t in this.attributes){var i=o[t];void 0!==i&&e(i,t)}},I.prototype.mapObject=function(t,e){t=void 0===e?t:t.bind(e);return s({},this.attributes,t)},I.prototype[Symbol.iterator]=function(){return new pn(this)},I.prototype.entries=function(){return new pn(this)},I.prototype.keys=function(){var n=[];return this.forEach(function(t,e){return n.push(e)}),n},I._metatype=Ve,I.id=T(String).value(null),d([o({cidPrefix:"m",_changeEventName:"change",idAttribute:"id"}),ft({defaults:m.merge,attributes:m.merge,collection:m.merge,Collection:m.value,idAttribute:m.protoValue})],I));function I(t,e){var n=sn.call(this,ln++)||this,r=(n.attributes={},e||{}),o=(r.parse?n.parse(t,r):t)||{};if(!Dt){var i=n,s=o,a=r;if(ue(i,s,a)){var u,c=i._attributes,l=void 0;for(u in s)c[u]||(l=l||[]).push("'".concat(u,"'"));l&&ae(i,l,{values:s},a)}}return n._previousAttributes=n.attributes=new n.Attributes(n,o,r),n.initialize(t,e),n._localEvents&&n._localEvents.subscribe(n,n),n}un(D.prototype,w,an);function hn(t){this.id=t.id}D.prototype.Attributes=function(t,e,n){this.id=e.id};D.prototype.AttributesCopy=hn;un=O.create({value:void 0},"id");D.prototype._attributes={id:un},D.prototype._attributesArray=[un];fn.prototype.next=function(){var t=this.record,e=t._attributesArray[this.idx++];return{done:!e,value:e?[e.name,t[e.name]]:void 0}};var pn=fn;function fn(t){this.record=t,this.idx=0}var dn=u,vn=a;D.onExtend=function(t){b.onExtend.call(this,t);var e,n=this,r=(f(o,e=t.Collection),o.model=n,d([pt],o));function o(){return null!==e&&e.apply(this,arguments)||this}this.DefaultCollection=r,n.Collection===t.Collection&&(this.Collection=r)},D.onDefine=function(t,e){var n=e.prototype,n=on(this.attributes=function(t){var e=t.defaults,n=t.attributes,t=t.idAttribute,n=n||e||{};!t||t in n||(n[t]=void 0);return n}(t),n._attributes,this),r=n.properties,o=n._localEvents,n=ct(n,["properties","_localEvents"]);dn(this.prototype,n),t.properties=vn(t.properties||{},r),t._localEvents=o,b.onDefine.call(this,t,e),this.DefaultCollection.define(t.collection||{}),this.Collection=t.Collection,this.Collection.prototype.model=this,t.endpoint&&(this.Collection.prototype._endpoint=t.endpoint)};var yn=it,gn=p,mn=l,bn=h,_n=_.commit,wn=_.aquire,On=_.free;function Cn(t,e,n){var r,o=t.model,o=(t._shared?(r=e instanceof o?e:o.create(e,n),t._shared&i.ItemsBehavior.listen&&mn(r,r._changeEventName,t._onChildrenChange,t)):(r=e instanceof o?n.merge?e.clone():e:o.create(e,n))._owner?r._owner!==t&&(wn(t,r.clone()),(t._aggregationError||(t._aggregationError=[])).push(r)):wn(t,r),t._itemEvents);return o&&o.subscribe(t,r),r}function En(t,e,n){t._shared?t._shared&i.ItemsBehavior.listen&&bn(e,e._changeEventName,t._onChildrenChange,t):(On(t,e),n||e.dispose());n=t._itemEvents;n&&n.unsubscribe(t,e)}function jn(t,e){var n=t._comparator;return!(!n||!1===e.sort||(t.models.sort(n),0))}function An(t,e){var n=(t[e.cid]=e).id;!n&&0!==n||(t[n]=e)}function Sn(t,e){delete t[e.cid];e=e.id;!e&&0!==e||delete t[e]}function Pn(t,e){delete t[e.previous(e.idAttribute)];var n=e.id;null!=n&&(t[n]=e)}xn.prototype.commit=function(t){for(var e=this.nested,n=this.object,r=n._isDirty,o=0,i=e;o<i.length;o++)(u=i[o]).commit(n);n._aggregationError&&Tn(n,r);for(var s=0,a=e;s<a.length;s++){var u=a[s];yn(n,"change",u.object,r)}for(var e=this.added,c=this.removed,l=0,h=e;l<h.length;l++){var p=h[l];gn(p,"add",p,n,r),gn(n,"add",p,n,r)}for(var f=0,d=c;f<d.length;f++){p=d[f];gn(p,"remove",p,n,r),gn(n,"remove",p,n,r)}this.sorted&&yn(n,"sort",n,r),(e.length||c.length)&&yn(n,"update",n,r),this.isRoot&&_n(n,t)};var Nn=xn;function xn(t,e,n,r,o,i){this.object=t,this.isRoot=e,this.added=n,this.removed=r,this.nested=o,this.sorted=i}function Tn(t,e){t._log("warn","Type-R:InvalidOwner","added records already have an owner and were cloned. Use explicit record.clone() to dismiss this warning.",t._aggregationError,e.logger),t._aggregationError=void 0}var Dn=_.begin,In=_.commit,Rn=_.markAsDirty;function kn(t,e,n,r){var o=Dn(t),i=[],e=function(t,e,n,r,o){for(var i=t._byId,s=t.models,a=(o||r.merge)&&!t._shared,u=(r.parse,t.model.prototype.idAttribute),o=s.length,c=0,l=e;c<l.length;c++){var h,p=l[c],f=p?i[p[u]]||i[p.cid]:null;f?a&&p!==f&&(h=p.attributes||p,(h=f._createTransaction(h,r))&&n.push(h),f.hasChanged(u))&&Pn(i,f):(f=Cn(t,p,r),s.push(f),An(i,f))}return s.slice(o)}(t,e,i,n,r);if(e.length||i.length){r=function(t,e,n){var r=n.at;if(null==r)return jn(t,n);n=t.models.length-e.length;(r=Number(r))<0&&(r+=1+n);r<0&&(r=0);n<r&&(r=n);return function(t,e,n){for(var r=t.length-1,o=r-n.length;e<=o;o--,r--)t[r]=t[o];for(o=0,r=e;o<n.length;o++,r++)t[r]=n[o]}(t.models,r,e),!1}(t,e,n);if(Rn(t,n))return new Nn(t,o,e,[],i,r);t._aggregationError&&Tn(t,n)}o&&In(t)}var Mn=it,Jn=p,Un=_.markAsDirty,Bn=_.begin,Vn=_.commit;function Hn(t,e,n){e=function(t,e,n){for(var r=Array(e.length),o=t._byId,i=0,s=0;i<e.length;i++){var a=t.get(e[i]);a&&(r[s++]=a,Sn(o,a),En(t,a,n))}return r.length=s,r}(t,e,n.unset);if(e.length){for(var r=Bn(t),o=t,i=e.length,s=o.models,a=o.models=Array(s.length-i),u=o._byId,c=0,l=0;c<s.length;c++){var h=s[c];u[h.cid]&&(a[l++]=h)}a.length=l,Un(t,n)?new Nn(t,r,[],e,[],!1).commit():r&&Vn(t)}return e}var Fn=_.begin,zn=_.commit,qn=_.markAsDirty,Wn={silent:!0};function Kn(t,e,n,r){var o=Fn(t),e=function(t,e,n){for(var r=e?e.length:0,o=Array(r),i={},s=t.model.prototype.idAttribute,a=0,u=0;a<r;a++){var c=e[a];c&&(i[c[s]]||i[c.cid])||(c=Cn(t,c,n),o[u++]=c,An(i,c))}return o.length=u,t._byId=i,t.models=o}(t,e,n);if(e.length){var i=jn(t,n);if(qn(t,r?Wn:n))return new Nn(t,o,e.slice(),[],[],i);t._aggregationError&&Tn(t,n)}o&&zn(t)}function Ln(t,e,n){var r=Fn(t),o=[],i=t.models,e=function(t,e,n,r){for(var o=Array(e.length),i={},s=(null==r.merge||r.merge)&&!t._shared,a=t._byId,u=t.models,c=t.model.prototype.idAttribute,l=[],h=!0,p=0,f=0;p<e.length;p++){var d=e[p],v=null;if(d){var y=d[c],g=d.cid;if(i[y]||i[g])continue;v=a[y]||a[g]}v?s&&d!==v&&(h&&u[f]!==v&&(h=!1),y=d.attributes||d,g=v._createTransaction(y,r))&&n.push(g):(v=Cn(t,d,r),l.push(v)),o[f++]=v,An(i,v)}o.length=f,t.models=o,t._byId=i,h||(r.sorted=!0);return l}(t,e,o,n),s=t.models.length-e.length,s=s<i.length?(s?function(t,e){for(var n=t._byId,r=[],o=0,i=e;o<i.length;o++){var s=i[o];n[s.cid]||(r.push(s),En(t,s))}return r}:function(t,e){for(var n=0,r=e;n<r.length;n++)En(t,r[n]);return e})(t,i):[],i=o.length||e.length,a=jn(t,n)&&i||e.length||n.sorted;if(i||s.length||a){if(qn(t,n))return new Nn(t,r,e,s,o,a);t._aggregationError&&Tn(t,n)}r&&zn(t)}R.prototype.map=function(t,e){for(var n=this.models,r=n.length,o=Array(r),i=e?t.bind(e):t,s=0,a=0;s<r;s++){var u=i(n[s],s);void 0!==u&&(o[a++]=u)}return s!==a&&(o.length=a),o},R.prototype.each=function(t,e){for(var n=this.models,r=n.length,o=e?t.bind(e):t,i=0;i<r;i++)o(n[i],i)},R.prototype.firstMatch=function(t,e){for(var n=this.models,r=n.length,o=e?t.bind(e):t,i=0;i<r;i++){var s=o(n[i],i);if(void 0!==s)return s}},R.prototype.reduce=function(t,e){return void 0===e?this.models.reduce(t):this.models.reduce(t,e)},R.prototype.slice=function(t,e){return this.models.slice(t,e)},R.prototype.indexOf=function(t){return this.models.indexOf(this.get(t))},R.prototype.includes=function(t){return Boolean(this.get(t))},R.prototype.filter=function(t,e){var n=Gn(t);return this.map(function(t){return n(t)?t:void 0},e)},R.prototype.find=function(t,e){var n=Gn(t);return this.firstMatch(function(t){return n(t)?t:void 0},e)},R.prototype.some=function(t,e){return Boolean(this.find(t,e))},R.prototype.forEach=function(t,e){this.each(t,e)},R.prototype.values=function(){return this.models.values()},R.prototype.entries=function(){return this.models.entries()},R.prototype.every=function(t,e){var n=Gn(t);return void 0===this.firstMatch(function(t){return!!n(t)&&void 0},e)},R.prototype.pluck=function(e){return this.map(function(t){return t[e]})},R.prototype.first=function(){return this.models[0]},R.prototype.last=function(){return this.models[this.models.length-1]},R.prototype.at=function(t){t=t<0?t+this.models.length:t;return this.models[t]};w=R;function R(){}var Zn=function(t){return t};function Gn(o){if(null==o)return Zn;switch(typeof o){case"function":return o;case"object":var i=Object.keys(o);return function(t){for(var e=0,n=i;e<n.length;e++){var r=n[e];if(o[r]!==t[r])return!1}return!0};default:throw new Error("Invalid iteratee")}}var $n,Qn=it,Xn=_.begin,Yn=_.commit,tr=_.markAsDirty,er=0,nr=(f(rr,$n=Le),rr.defaultValue=[],rr);function rr(){return null!==$n&&$n.apply(this,arguments)||this}f(k,or=b),k.of=function(t){return t.Collection},k.ofRefs=function(t){return t.Collection.Refs},k.prototype.createSubset=function(t,e){throw new ReferenceError("Failed dependency injection")},k.onExtend=function(t){var r=this;function e(t,e,n){r.call(this,t,e,i.ItemsBehavior.share|(n?i.ItemsBehavior.listen:0))}this._SubsetOf=null,lt.mixins.populate(e),e.prototype=this.prototype,e._metatype=nr,this.Refs=this.Subset=e,b.onExtend.call(this,t)},k.onDefine=function(t,e){t.itemEvents&&((e=new G(e.prototype._itemEvents)).addEventsMap(t.itemEvents),this.prototype._itemEvents=e),void 0!==t.comparator&&(this.prototype.comparator=t.comparator),b.onDefine.call(this,t)},Object.defineProperty(k.prototype,"__inner_state__",{get:function(){return this.models},enumerable:!1,configurable:!0}),Object.defineProperty(k.prototype,"comparator",{get:function(){return this._comparator},set:function(n){var r=this;switch(typeof n){case"string":this._comparator=function(t,e){t=t[n],e=e[n];return t===e?0:t<e?-1:1};break;case"function":1===n.length?this._comparator=function(t,e){t=n.call(r,t),e=n.call(r,e);return t===e?0:t<e?-1:1}:this._comparator=function(t,e){return n.call(r,t,e)};break;default:this._comparator=null}},enumerable:!1,configurable:!0}),k.prototype.getStore=function(){return this._store||(this._store=this._owner?this._owner.getStore():this._defaultStore)},k.prototype._onChildrenChange=function(t,e,n){void 0===e&&(e={}),n!==this&&(n=this.idAttribute,t.hasChanged(n)&&Pn(this._byId,t),n=Xn(this),tr(this,e)&&Qn(this,"change",t,e),n)&&Yn(this)},k.prototype.get=function(t){var e;if(null!=t)return"object"==typeof t?void 0!==(e=t[this.idAttribute])&&this._byId[e]||this._byId[t.cid]:this._byId[t]},k.prototype[Symbol.iterator]=function(){return this.models[Symbol.iterator]()},k.prototype.updateEach=function(t){var e=_.begin