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