-
Notifications
You must be signed in to change notification settings - Fork 3
/
breeze.base.min.js
5 lines (5 loc) · 141 KB
/
breeze.base.min.js
1
2
3
4
5
!function(a){"object"==typeof exports&&"object"==typeof module?module.exports=a():"function"==typeof define&&define.amd?define(a):breeze=a()}(function(){function a(a,b){for(var c in a)T(a,c)&&b(c,a[c])}function b(a,b){for(var c in a)if(T(a,c)){var d=a[c];if(b(c,d))return{key:c,value:d}}return null}function c(a,b){var c=[];for(var d in a)if(T(a,d)){var e=b?b(d,a[d]):a[d];void 0!==e&&c.push(e)}return c}function d(a,b){return function(c){return c[a]===b}}function e(a){return function(b){return b[a]}}function f(a){var b=[];for(var c in a)T(a,c)&&b.push(a[c]);return b}function g(a,b,c){if(!b)return a;if(c)c.forEach(function(c){a[c]=b[c]});else for(var d in b)T(b,d)&&(a[d]=b[d]);return a}function h(a,b){for(var c in b)void 0===a[c]&&(a[c]=b[c]);return a}function i(a,b){return b.defaultInstance=h(new b(a),b.defaultInstance),a}function j(a,b){var c={};for(var d in b)if(d in a){var e=a[d],f=b[d];e!=f&&(Array.isArray(e)&&0===e.length||("function"==typeof f?e=f(e):"object"==typeof e&&e&&e.parentEnum&&(e=e.name),void 0!==e&&(c[d]=e)))}return c}function k(a,b){if(a!==Object(a))return a;if(a._$visited)return void 0;if(a.toJSON){var c=a.toJSON();if(c!==Object(c))return c;if(c!==a)return k(c);a=c}a._$visited=!0;var d;if(a instanceof Array)d=a.map(function(a){return k(a,b)});else if("function"==typeof a)d=void 0;else{var d={};for(var e in a)if("_$visited"!==e){var f=a[e];if(!b||(f=b(e,f),void 0!==f)){var f=k(f);void 0!==f&&(d[e]=f)}}}return delete a._$visited,d}function l(a,b){var c={},d=a.length;return b.forEach(function(b){for(var e=0;d>e;e++){var f=a[e];if(f){var g=f[b];if(void 0!==g){c[b]=g;break}}}}),c}function m(a){return null==a?[]:Array.isArray(a)?a:[a]}function n(a,b){if(null==a)return a;var c;return Array.isArray(a)?(c=[],a.map(function(a,d){c[d]=b(a,d)})):c=b(a),c}function o(a,b){for(var c=0,d=a.length;d>c;c++)if(b(a[c]))return a[c];return null}function p(a,b){for(var c=0,d=a.length;d>c;c++)if(b(a[c]))return c;return-1}function q(a,b,c){for(var d=D(b)?b:void 0,e=a.length-1,f=!1,g=e;g>=0;g--)if((d?d(a[g]):a[g]===b)&&(a.splice(g,1),f=!0,!c))return f;return f}function r(a,b,c){for(var d=[],e=Math.min(a.length,b.length),f=0;e>f;++f)d.push(c(a[f],b[f]));return d}function s(a,b,c){if(!a||!b)return!1;if(a.length!==b.length)return!1;for(var d=0;d<a.length;d++)if(Array.isArray(a[d])){if(!s(a[d],b[d]))return!1}else if(c){if(!c(a[d],b[d]))return!1}else if(a[d]!==b[d])return!1;return!0}function t(a,b){var c=a[b];return c||(c=[],a[b]=c),c}function u(a,b){for(var c=a.split(";"),d=0,e=c.length;e>d;d++){var f=v(c[d]);if(f)return f}if(b)throw new Error("Unable to initialize "+a+". "+b||"")}function v(a){var b=this.window;if(b){var c=b[a];if(c)return c;var d=b.require;if(d){if(d.defined)return d.defined(a)?d(a):void 0;try{return d(a)}catch(e){return}}}}function w(a,b,c,d){var e=a[b];if(c===e)return d();a[b]=c;try{return d()}finally{void 0===e?delete a[b]:a[b]=e}}function x(a,b,c){var d;try{return d=a(),c()}catch(e){throw"object"==typeof d&&(d.error=e),e}finally{b(d)}}function y(a){return function(){for(var b=U(arguments),c="",d=b.length,e=null;d--;)e=b[d],c+=e===Object(e)?JSON.stringify(e):e,a.memoize||(a.memoize={});return c in a.memoize?a.memoize[c]:a.memoize[c]=a.apply(this,b)}}function z(){return"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,function(a){var b=16*Math.random()|0,c="x"==a?b:3&b|8;return c.toString(16)})}function A(a){if("string"!=typeof a)throw new Error("Invalid ISO8601 duration '"+a+"'");var b=/^P((\d+Y)?(\d+M)?(\d+D)?)?(T(\d+H)?(\d+M)?(\d+S)?)?$/.exec(a);if(!b)throw new Error("Invalid ISO8601 duration '"+a+"'");for(var c=[2,3,4,6,7,8],d=[31104e3,2592e3,86400,3600,60,1],e=0,f=0;6>f;f++){var g=b[c[f]];g=g?+g.replace(/[A-Za-z]+/g,""):0,e+=g*d[f]}return e}function B(a){return null===a?"null":void 0===a?"undefined":Object.prototype.toString.call(a).slice(8,-1).toLowerCase()}function C(a){return"date"===B(a)&&!isNaN(a.getTime())}function D(a){return"function"===B(a)}function E(a){return"string"==typeof a&&/[a-fA-F\d]{8}-(?:[a-fA-F\d]{4}-){3}[a-fA-F\d]{12}/.test(a)}function F(a){return"string"==typeof a&&/^(-|)?P[T]?[\d\.,\-]+[YMDTHS]/.test(a)}function G(a){if(null===a||void 0===a)return!0;for(var b in a)if(T(a,b))return!1;return!0}function H(a){return!isNaN(parseFloat(a))&&isFinite(a)}function I(a,b){return a&&b?0===a.indexOf(b,0):!1}function J(a,b){return a&&b?-1!==a.indexOf(b,a.length-b.length):!1}function K(a){var b=arguments,c=RegExp("%([1-"+(arguments.length-1)+"])","g");return a.replace(c,function(a,c){return b[c]})}function L(a){var b=Function.call;return function(){return b.apply(a,arguments)}}function M(a,b,c){void 0===b&&(b=null);var d=c(),e=a.dataType;if(e&&e.parse&&(b=Array.isArray(b)&&!a.isScalar?b.map(function(a){return e.parse(a,typeof a)}):e.parse(b,typeof b)),!(b===d||e&&e.isDate&&b&&d&&b.valueOf()===d.valueOf())){var f,g,h,i=this,j=a.name,k=this.entityAspect;if(k)f=k;else{if(f=this.complexAspect,!f)return c(b),void 0;k=f.getEntityAspect()}var l=f.getPropertyPath(j),m=k._inProcess;if(m){if(m.indexOf(a)>=0)return;m.push(a)}else m=[a],k._inProcess=m;var n=k.entity;try{var o=k.entityManager;if(k.entityState.isUnchangedOrModified()&&void 0===f.originalValues[j]&&a.isDataProperty&&!a.isComplexProperty&&(f.originalValues[j]=void 0!==d?d:a.defaultValue),a.isComplexProperty){if(!a.isScalar)throw new Error(K("You cannot set the non-scalar complex property: '%1' on the type: '%2'.Instead get the property and use array functions like 'push' or 'splice' to change its contents.",a.name,a.parentType.name));if(!b)throw new Error(K("You cannot set the '%1' property to null because it's datatype is the ComplexType: '%2'",a.name,a.dataType.name));if(!d){var p=e.getCtor();d=new p,c(d)}e.dataProperties.forEach(function(a){var c=a.name,e=b.getProperty(c);d.setProperty(c,e)})}else if(a.isDataProperty){if(!a.isScalar)throw new Error("Nonscalar data properties are readonly - items may be added or removed but the collection may not be changed.");if(a.isPartOfKey&&!this.complexAspect&&o&&!o.isLoading){var q=this.entityType.keyProperties,r=q.map(function(c){return c===a?b:this.getProperty(c.name)},this),s=new jb(this.entityType,r);if(o.findEntityByKey(s))throw new Error("An entity with this key is already in the cache: "+s.toString());var t=this.entityAspect.getKey(),u=o._findEntityGroup(this.entityType);u._replaceKey(t,s)}var v=a.relatedNavigationProperty;if(v&&o)null!=b?(g=new jb(v.entityType,[b]),h=o.findEntityByKey(g),h?this.setProperty(v.name,h):o._unattachedChildrenMap.addChild(g,v,this)):this.setProperty(v.name,null);else if(a.inverseNavigationProperty&&o&&!o._inKeyFixup){var w=a.inverseNavigationProperty;if(null!=d&&(g=new jb(w.parentType,[d]),h=o.findEntityByKey(g)))if(w.isScalar)h.setProperty(w.name,null);else{var x=h.getProperty(w.name);x.splice(x.indexOf(this),1)}null!=b&&(g=new jb(w.parentType,[b]),h=o.findEntityByKey(g),h?w.isScalar?h.setProperty(w.name,this):h.getProperty(w.name).push(this):o._unattachedChildrenMap.addChild(g,w,this))}if(c(b),o&&!o.isLoading&&(k.entityState.isUnchanged()&&!a.isUnmapped&&k.setModified(),o.validationOptions.validateOnPropertyChange&&k._validateProperty(b,{entity:n,property:a,propertyName:l,oldValue:d})),a.isPartOfKey&&!this.complexAspect){var y=this.entityType.keyProperties.indexOf(a);this.entityType.navigationProperties.forEach(function(a){var c=a.inverse,d=c?c.foreignKeyNames:a.invForeignKeyNames;if(0!==d.length){var e=i.getProperty(a.name),f=d[y];if(a.isScalar){if(!e)return;e.setProperty(f,b)}else e.forEach(function(a){a.setProperty(f,b)})}}),o&&this.entityType.inverseForeignKeyProperties.forEach(function(a){null==a.relatedNavigationProperty.inverse&&o._updateFkVal(a,d,b)}),k.getKey(!0)}}else{if(!a.isScalar)throw new Error("Nonscalar navigation properties are readonly - entities can be added or removed but the collection may not be changed.");var z=a.inverse;if(null!=b){var A=b.entityAspect;if(o){if(A.entityState.isDetached())o.isLoading||o.attachEntity(b,kb.Added);else if(A.entityManager!==o)throw new Error("An Entity cannot be attached to an entity in another EntityManager. One of the two entities must be detached first.")}else A&&A.entityManager&&(o=A.entityManager,o.isLoading||o.attachEntity(k.entity,kb.Added))}if(z)if(z.isScalar)null!=d&&d.setProperty(z.name,null),null!=b&&b.setProperty(z.name,this);else{if(null!=d){var B=d.getProperty(z.name),C=B.indexOf(this);-1!==C&&B.splice(C,1)}if(null!=b){var D=b.getProperty(z.name);D.push(this)}}else if(a.invForeignKeyNames&&o&&!o._inKeyFixup){var E=a.invForeignKeyNames;if(null!=b){var F=this.entityAspect.getKey().values;E.forEach(function(a,c){b.setProperty(a,F[c])})}else null!=d&&E.forEach(function(a){var b=d.entityType.getProperty(a);b.isPartOfKey||d.setProperty(a,null)})}if(c(b),o&&!o.isLoading&&(k.entityState.isUnchanged()&&!a.isUnmapped&&k.setModified(),o.validationOptions.validateOnPropertyChange&&k._validateProperty(b,{entity:this,property:a,propertyName:l,oldValue:d})),a.relatedDataProperties&&!k.entityState.isDeleted()){var G=a.entityType.keyProperties;G.forEach(function(c,d){var e=a.relatedDataProperties[d];if(b||!e.isPartOfKey){var f=b?b.getProperty(c.name):e.defaultValue;i.setProperty(e.name,f)}})}}var H={entity:n,parent:this,property:a,propertyName:l,oldValue:d,newValue:b};o?o.isLoading||o.isRejectingChanges||(k.propertyChanged.publish(H),o.entityChanged.publish({entityAction:gb.PropertyChange,entity:n,args:H})):k.propertyChanged.publish(H)}finally{m.pop()}}}function N(a){return a.indexOf(":#")>=0}function O(a,b){return a+":#"+b}function P(a,b,c){if(b)if(Array.isArray(b))b.forEach(a.addProperty.bind(a));else{if("object"!=typeof b)throw new Error("The 'dataProperties' or 'navigationProperties' values must be either an array of data/nav properties or an object where each property defines a data/nav property");for(var d in b)if(T(b,d)){var e=b[d];e.name=d;var f=new c(e);a.addProperty(f)}}}function Q(a,b){var c;if(c=Array.isArray(b)?b:b.split("."),1===c.length)return a.getProperty(b);for(var d=a,e=0;e<c.length&&(d=d.getProperty(c[e]),null!=d);e++);return d}function R(a){return a&&a.isDate?function(a){return a&&a.getTime()}:a===lb.Time?function(a){return a&&A(a)}:function(a){return a}}var S={version:"1.4.11",metadataVersion:"1.0.5"},T=L(Object.prototype.hasOwnProperty),U=L(Array.prototype.slice);Object.create||(Object.create=function(a){var b=function(){};return b.prototype=a,new b});var V={};V.objectForEach=a,V.extend=g,V.propEq=d,V.pluck=e,V.arrayEquals=s,V.arrayFirst=o,V.arrayIndexOf=p,V.arrayRemoveItem=q,V.arrayZip=r,V.requireLib=u,V.using=w,V.memoize=y,V.getUuid=z,V.durationToSeconds=A,V.isDate=C,V.isGuid=E,V.isDuration=F,V.isFunction=D,V.isEmpty=G,V.isNumeric=H,V.stringStartsWith=I,V.stringEndsWith=J,V.formatString=K,V.toJSONSafe=k,V.parent=S,S.core=V;var W=function(){function a(a,b){return null==b?!1:"string"==typeof b&&b.length>0}function b(a,b){return null==b?!1:typeof b===a.typeName?!0:!1}function c(a,b){return null==b?!1:b instanceof a.type}function d(a,b){return null==b?!1:void 0!==b[a.propertyName]}function e(a,b){return null==b?!1:a.enumType.contains(b)}function f(a,b){return a.allowNull?void 0!==b:null!=b}function h(a,b){if(null==b)return!0;var c=a.prevContext;return c?c.fn(c,b):!0}function i(a,b){var c=a.prevContext,d=c?" or it "+l(c,b):"";return"is optional"+d}function j(a,b){if(!Array.isArray(b))return!1;if(a.mustNotBeEmpty&&0===b.length)return!1;var c=a.prevContext;return c?b.every(function(a){return c.fn(c,a)}):!0}function k(a,b){var c=a.mustNotBeEmpty?"a nonEmpty array":"an array",d=a.prevContext,e=d?" where each element "+l(d,b):"";return" must be "+c+e}function l(a,b){var c=a.msg;return"function"==typeof c&&(c=c(a,b)),c}function m(a,b){if(a._context){for(var c=a._context;null!=c.prevContext;)c=c.prevContext;if(null===c.prevContext)return c.prevContext=b,a;if(null!=b.prevContext)throw new Error("Illegal construction - use 'or' to combine checks");b.prevContext=a._context}return n(a,b)}function n(a,b){return a._contexts[a._contexts.length-1]=b,a._context=b,a}function o(a){var b=a._contexts;return null==b[b.length-1]&&b.pop(),0===b.length?void 0:b.some(function(b){return b.fn(b,a.v)})}function p(a,b){throw new Error(K("Error configuring an instance of '%1'. %2",a&&a._$typeName||"object",b))}var q=function(a,b){this.v=a,this.name=b,this._contexts=[null]},r=q.prototype;return r.isObject=function(){return this.isTypeOf("object")},r.isBoolean=function(){return this.isTypeOf("boolean")},r.isString=function(){return this.isTypeOf("string")},r.isNonEmptyString=function(){return m(this,{fn:a,msg:"must be a nonEmpty string"})},r.isNumber=function(){return this.isTypeOf("number")},r.isFunction=function(){return this.isTypeOf("function")},r.isTypeOf=function(a){return m(this,{fn:b,typeName:a,msg:K("must be a '%1'",a)})},r.isInstanceOf=function(a,b){return b=b||a.prototype._$typeName,m(this,{fn:c,type:a,typeName:b,msg:K("must be an instance of '%1'",b)})},r.hasProperty=function(a){return m(this,{fn:d,propertyName:a,msg:K("must have a '%1' property ",a)})},r.isEnumOf=function(a){return m(this,{fn:e,enumType:a,msg:K("must be an instance of the '%1' enumeration",a.name)})},r.isRequired=function(a){return m(this,{fn:f,allowNull:a,msg:"is required"})},r.isOptional=function(){var a={fn:h,prevContext:null,msg:i};return m(this,a)},r.isNonEmptyArray=function(){return this.isArray(!0)},r.isArray=function(a){var b={fn:j,mustNotBeEmpty:a,prevContext:null,msg:k};return m(this,b)},r.or=function(){return this._contexts.push(null),this._context=null,this},r.check=function(a){var b=o(this);if(void 0!==b){if(!b)throw new Error(this.getMessage());return void 0!==this.v?this.v:a}},r._addContext=function(a){return m(this,a)},r.getMessage=function(){var a=this,b=this._contexts.map(function(b){return l(b,a.v)}).join(", or it ");return K(this.MESSAGE_PREFIX,this.name)+" "+b},r.withDefault=function(a){return this.defaultValue=a,this},r.whereParam=function(a){return this.parent.whereParam(a)},r.applyAll=function(a,b,c){var d=a._$typeName;c=c||d&&this.parent.config._$typeName===d;var e=g({},this.parent.config);if(this.parent.params.forEach(function(d){c||delete e[d.name];try{d.check()}catch(f){p(a,f.message)}!b&&d._applyOne(a)}),!c)for(var f in e)void 0!==e[f]&&p(a,K("Unknown property: '%1'.",f))},r._applyOne=function(a){void 0!==this.v?a[this.name]=this.v:void 0!==this.defaultValue&&(a[this.name]=this.defaultValue)},r.MESSAGE_PREFIX="The '%1' parameter ",q}(),X=function(a,b){return new W(a,b)},Y=function(){var a=function(a){if("object"!=typeof a)throw new Error("Configuration parameter should be an object, instead it is a: "+typeof a);this.config=a,this.params=[]},b=a.prototype;return b.whereParam=function(a){var b=new W(this.config[a],a);return b.parent=this,this.params.push(b),b},a}(),Z=function(a){return new Y(a)};V.Param=W,V.assertParam=X,V.assertConfig=Z;var $=function(){function a(){}var b=function(b,c){this.name=b;var d=new a(c);d.parentEnum=this,this._symbolPrototype=d,c&&Object.keys(c).forEach(function(a){d[a]=c[a]})},c=b.prototype;return b.isSymbol=function(b){return b instanceof a},c.fromName=function(a){return this[a]},c.addSymbol=function(a){var b=Object.create(this._symbolPrototype);return a&&Object.keys(a).forEach(function(c){b[c]=a[c]}),setTimeout(function(){b.getName()},0),b},c.seal=function(){this.getSymbols().forEach(function(a){return a.getName()})},c.getSymbols=function(){return this.getNames().map(function(a){return this[a]},this)},c.getNames=function(){var a=[];for(var b in this)this.hasOwnProperty(b)&&("name"===b||"_"===b.substr(0,1)||D(this[b])||a.push(b));return a},c.contains=function(b){return b instanceof a?this[b.getName()]===b:!1},a.prototype.getName=function(){if(!this.name){var a=this;this.name=o(this.parentEnum.getNames(),function(b){return a.parentEnum[b]===a})}return this.name},a.prototype.toString=function(){return this.getName()},a.prototype.toJSON=function(){return{_$typeName:this.parentEnum.name,name:this.name}},b}();V.Enum=$;var _=function(){function a(a,c,d){var e=a._subscribers;return e?(e.forEach(function(e){try{e.callback(c)}catch(f){f.context="unable to publish on topic: "+a.name,d?d(f):a._defaultErrorCallback?a._defaultErrorCallback(f):b(f)}}),void 0):!0}function b(){}var c={},d=1,e=function(a,b,d){X(a,"eventName").isNonEmptyString().check(),X(b,"publisher").isObject().check(),this.name=a,c[a]=!0,this.publisher=b,d&&(this._defaultErrorCallback=d)},f=e.prototype;return f.publish=function(b,c,d){return e._isEnabled(this.name,this.publisher)?(c===!0?setTimeout(a,0,this,b,d):a(this,b,d),!0):!1},f.publishAsync=function(a,b){this.publish(a,!0,b)},f.subscribe=function(a){this._subscribers||(this._subscribers=[]);var b=d;return this._subscribers.push({unsubKey:b,callback:a}),++d,b},f.unsubscribe=function(a){if(!this._subscribers)return!1;var b=this._subscribers,c=p(b,function(b){return b.unsubKey===a});return-1!==c?(b.splice(c,1),0===b.length&&(this._subscribers=null),!0):!1},f.clear=function(){this._subscribers=null},e.bubbleEvent=function(a,b){a._getEventParent=b},e.enable=function(a,b,c){X(a,"eventName").isNonEmptyString().check(),X(b,"obj").isObject().check(),X(c,"isEnabled").isBoolean().isOptional().or().isFunction().check(),b._$eventMap||(b._$eventMap={}),b._$eventMap[a]=c},e.isEnabled=function(a,b){if(X(a,"eventName").isNonEmptyString().check(),X(b,"obj").isObject().check(),!b._getEventParent)throw new Error("This object does not support event enabling/disabling");return e._isEnabled(b,a)},e._isEnabled=function(a,b){var c=null,d=b._$eventMap;if(d&&(c=d[a]),null!=c)return"function"==typeof c?c(b):!!c;var f=b._getEventParent&&b._getEventParent();return f?e._isEnabled(a,f):!0},e}();V.Event=_;var ab=function(){function a(a,b,c){var d=b.defaultInstance;return d||(d=new b.ctor,b.defaultInstance=d,d._$impl=b),d.initialize(),c&&(a.defaultInstance=d),e.interfaceInitialized.publish({interfaceName:a.name,instance:d,isDefault:!0}),d.checkForRecomposition&&e.interfaceInitialized.subscribe(function(a){d.checkForRecomposition(a)}),d}function d(a){var c=a.toLowerCase(),d=b(e.interfaceRegistry||{},function(a){return a.toLowerCase()===c});if(!d)throw new Error("Unknown interface name: "+a);return d.value}var e={};e.functionRegistry={},e.typeRegistry={},e.objectRegistry={},e.interfaceInitialized=new _("interfaceInitialized",e);var f=function(a){this.name=a,this.defaultInstance=null,this._implMap={}};return f.prototype.registerCtor=function(a,b){this._implMap[a.toLowerCase()]={ctor:b,defaultInstance:null}},f.prototype.getImpl=function(a){return this._implMap[a.toLowerCase()]},f.prototype.getFirstImpl=function(){var a=b(this._implMap,function(){return!0});return a?a.value:null},e.interfaceRegistry={ajax:new f("ajax"),modelLibrary:new f("modelLibrary"),dataService:new f("dataService")},e.interfaceRegistry.modelLibrary.getDefaultInstance=function(){if(!this.defaultInstance)throw new Error("Unable to locate the default implementation of the '"+this.name+"' interface. Possible options are 'ko', 'backingStore' or 'backbone'. See the breeze.config.initializeAdapterInstances method.");return this.defaultInstance},e.setProperties=function(a){Z(a).whereParam("remoteAccessImplementation").isOptional().whereParam("trackingImplementation").isOptional().whereParam("ajaxImplementation").isOptional().applyAll(a),a.remoteAccessImplementation&&e.initializeAdapterInstance("dataService",a.remoteAccessImplementation),a.trackingImplementation&&e.initializeAdapterInstance("modelLibrary",a.trackingImplementation),a.ajaxImplementation&&e.initializeAdapterInstance("ajax",a.ajaxImplementation)},e.registerAdapter=function(a,b){X(a,"interfaceName").isNonEmptyString().check(),X(b,"adapterCtor").isFunction().check();var c=new b,e=c.name;if(!e)throw new Error("Unable to locate a 'name' property on the constructor passed into the 'registerAdapter' call.");var f=d(a);f.registerCtor(e,b)},e.getAdapter=function(a,b){var c=d(a);if(b){var e=c.getImpl(b);return e?e.ctor:null}return c.defaultInstance?c.defaultInstance._$impl.ctor:null},e.initializeAdapterInstances=function(a){return Z(a).whereParam("dataService").isOptional().whereParam("modelLibrary").isOptional().whereParam("ajax").isOptional().applyAll(this,!1),c(a,e.initializeAdapterInstance)},e.initializeAdapterInstance=function(b,c,e){e=void 0===e?!0:e,X(b,"interfaceName").isNonEmptyString().check(),X(c,"adapterName").isNonEmptyString().check(),X(e,"isDefault").isBoolean().check();var f=d(b),g=f.getImpl(c);if(!g)throw new Error("Unregistered adapter. Interface: "+b+" AdapterName: "+c);return a(f,g,e)},e.getAdapterInstance=function(b,c){var e,f=d(b);return c&&""!==c?(e=f.getImpl(c),e?e.defaultInstance:null):f.defaultInstance?f.defaultInstance:(e=f.getFirstImpl(),e.defaultInstance?e.defaultInstance:a(f,e,!0))},e.registerFunction=function(a,b){X(a,"fn").isFunction().check(),X(b,"fnName").isString().check(),a.prototype._$fnName=b,e.functionRegistry[b]=a},e._storeObject=function(a,b,c){var d=("string"==typeof b?b:b.prototype._$typeName)+"."+c;e.objectRegistry[d]=a},e._fetchObject=function(a,b){if(!b)return void 0;var c=("string"==typeof a?a:a.prototype._$typeName)+"."+b,d=e.objectRegistry[c];if(!d)throw new Error("Unable to locate a registered object by the name: "+c);return d},e.registerType=function(a,b){X(a,"ctor").isFunction().check(),X(b,"typeName").isString().check(),a.prototype._$typeName=b,e.typeRegistry[b]=a},e.stringifyPad="",e}(),bb=ab.interfaceRegistry.modelLibrary;V.config=ab,S.config=ab;var cb=function(){function a(a){var b=a.getEntityAspect();b.entityState.isUnchanged()&&b.setModified(),b.entityState.isModified()&&!a._origValues&&(a._origValues=a.slice(0))}function b(a,b){a._processAdds(b),d(a,"arrayChanged",{array:a,added:b})}function c(a,b){a._processRemoves(b),d(a,"arrayChanged",{array:a,removed:b})}function d(a,b,c){var d=a._getPendingPubs();d?a._pendingArgs?e(a._pendingArgs,c):(a._pendingArgs=c,d.push(function(){a[b].publish(a._pendingArgs),a._pendingArgs=null})):a[b].publish(c)}function e(a,b){for(var c in b)if("array"!==c&&a.hasOwnProperty(c)){var d=b[c],e=a[c];if(e){if(!Array.isArray(e))throw new Error("Cannot combine non array args");Array.prototype.push.apply(e,d)}else a[c]=d}}function f(a,b,c){a.parent=b,a.parentProperty=c}var g={};return g.push=function(){if(this._inProgress)return-1;var a=this._getGoodAdds(U(arguments));if(!a.length)return this.length;this._beforeChange();var c=Array.prototype.push.apply(this,a);return b(this,a),c},g._push=function(){if(this._inProgress)return-1;var a=U(arguments);this._beforeChange();var c=Array.prototype.push.apply(this,a);return b(this,a),c},g.unshift=function(){var a=this._getGoodAdds(U(arguments));if(!a.length)return this.length;this._beforeChange();var c=Array.prototype.unshift.apply(this,a);return b(this,U(a)),c},g.pop=function(){this._beforeChange();var a=Array.prototype.pop.apply(this);return c(this,[a]),a},g.shift=function(){this._beforeChange();var a=Array.prototype.shift.apply(this);return c(this,[a]),a},g.splice=function(){var a=this._getGoodAdds(U(arguments,2)),d=U(arguments,0,2).concat(a);this._beforeChange();var e=Array.prototype.splice.apply(this,d);return c(this,e),a.length&&b(this,a),e},g.getEntityAspect=function(){return this.parent.entityAspect||this.parent.complexAspect.getEntityAspect()},g._getEventParent=function(){return this.getEntityAspect()},g._getPendingPubs=function(){var a=this.getEntityAspect().entityManager;return a&&a._pendingPubs},g._beforeChange=function(){},{mixin:g,publish:d,updateEntityState:a,initializeParent:f}}(),db=function(){function b(a,b,c,d,e){for(d=+a[b=a.length-1],e=0;b--;)c=+a[b],d+=++e%2?2*c%10+(c>4):c;return!(d%10)}function c(a,b,c,d){c&&(n.messageTemplates[a]=c);var e="string"==typeof b?new RegExp(b):b,f=function(a){return null==a||""===a?!0:"string"!=typeof a?!1:e.test(a)};return new n(a,f,d)}function d(a,b,c){return b?a.replace(/%([^%]+)%/g,function(a,d){var e;return e=c?b.hasOwnProperty(d)?b[d]:"":b[d],e?D(e)?e(b):e:""}):a}function e(a,b,c,d){return n.messageTemplates[a]=K("'%displayName%' must be an integer between the values of %1 and %2",b,c),function(){var e=function(a,d){return null==a?!0:("string"==typeof a&&d&&d.allowString&&(a=parseInt(a,0)),"number"!=typeof a||isNaN(a)||Math.floor(a)!==a?!1:null!=b&&b>a?!1:null!=c&&a>c?!1:!0)};return new n(a,e,d)}}var f=-32768,h=32767,i=-2147483648,j=2147483647,k=0,l=255,m={displayName:function(a){return a.property?a.property.displayName||a.propertyName||a.property.name:"Value"}},n=function(a,b,c){this._baseContext=c||{},this._baseContext.name=a,c=g(Object.create(m),this._baseContext),c.messageTemplate=c.messageTemplate||n.messageTemplates[a],this.name=a,this.valFn=b,this.context=c},o=n.prototype;return o._$typeName="Validator",o.validate=function(a,b){var c;c=b?g(Object.create(this.context),b):this.context,this.currentContext=c;try{return this.valFn(a,c)?null:(c.value=a,new eb(this,c,this.getMessage()))}catch(d){return new eb(this,c,"Exception occured while executing this validator: "+this.name)}},o.getMessage=function(){try{var a=this.currentContext,b=a.message;return b?"function"==typeof b?b(a):b:a.messageTemplate?d(a.messageTemplate,a):"invalid value: "+this.name||"{unnamed validator}"}catch(c){return"Unable to format error message"+c.toString()}},o.toJSON=function(){return this._baseContext},n.fromJSON=function(a){var b="Validator."+a.name,c=ab.functionRegistry[b];if(!c)throw new Error("Unable to locate a validator named:"+a.name);return c(a)},n.register=function(a){ab.registerFunction(function(){return a},"Validator."+a.name)},n.registerFactory=function(a,b){ab.registerFunction(a,"Validator."+b)},n.messageTemplates={bool:"'%displayName%' must be a 'true' or 'false' value",creditCard:"The %displayName% is not a valid credit card number",date:"'%displayName%' must be a date",duration:"'%displayName%' must be a ISO8601 duration string, such as 'P3H24M60S'",emailAddress:"The %displayName% '%value%' is not a valid email address",guid:"'%displayName%' must be a GUID",integer:"'%displayName%' must be an integer",integerRange:"'%displayName%' must be an integer between the values of %minValue% and %maxValue%",maxLength:"'%displayName%' must be a string with %maxLength% characters or less",number:"'%displayName%' must be a number",phone:"The %displayName% '%value%' is not a valid phone number",regularExpression:"The %displayName% '%value%' does not match '%expression%'",required:"'%displayName%' is required",string:"'%displayName%' must be a string",stringLength:"'%displayName%' must be a string with between %minLength% and %maxLength% characters",url:"The %displayName% '%value%' is not a valid url"},n.required=function(a){var b=function(a,b){return"string"==typeof a?b&&b.allowEmptyStrings?!0:a.length>0:null!=a};return new n("required",b,a)},n.maxLength=function(a){var b=function(a,b){return null==a?!0:"string"!=typeof a?!1:a.length<=b.maxLength};return new n("maxLength",b,a)},n.stringLength=function(a){var b=function(a,b){return null==a?!0:"string"!=typeof a?!1:null!=b.minLength&&a.length<b.minLength?!1:null!=b.maxLength&&a.length>b.maxLength?!1:!0};return new n("stringLength",b,a)},n.string=function(){var a=function(a){return null==a?!0:"string"==typeof a};return new n("string",a)},n.guid=function(){var a=function(a){return null==a?!0:E(a)};return new n("guid",a)},n.duration=function(){var a=function(a){return null==a?!0:F(a)};return new n("duration",a)},n.number=n.double=n.single=function(a){var b=function(a,b){return null==a?!0:("string"==typeof a&&b&&b.allowString&&(a=parseInt(a,10)),"number"==typeof a&&!isNaN(a))};return new n("number",b,a)},n.integer=n.int64=function(a){var b=function(a,b){return null==a?!0:("string"==typeof a&&b&&b.allowString&&(a=parseInt(a,10)),"number"==typeof a&&!isNaN(a)&&Math.floor(a)===a)};return new n("integer",b,a)},n.int32=function(a){return e("int32",i,j,a)()},n.int16=function(a){return e("int16",f,h,a)()},n.byte=function(a){return e("byte",k,l,a)()},n.bool=function(){var a=function(a){return null==a?!0:a===!0||a===!1};return new n("bool",a)},n.none=function(){var a=function(){return!0};return new n("none",a)},n.date=function(){var a=function(a){if(null==a)return!0;if("string"!=typeof a)return C(a);try{return!isNaN(Date.parse(a))}catch(b){return!1}};return new n("date",a)},n.creditCard=function(a){function c(a){return null==a||""===a?!0:"string"!=typeof a?!1:(a=a.replace(/(\-|\s)/g,""),!a||/\D/.test(a)?!1:b(a))}return new n("creditCard",c,a)},n.regularExpression=function(a){function b(a,b){if(null==a||""===a)return!0;if("string"!=typeof a)return!1;try{var c=new RegExp(b.expression)}catch(d){throw new Error("Missing or invalid expression parameter to regExp validator")}return c.test(a)}return new n("regularExpression",b,a)},n.emailAddress=function(a){var b=/^((([a-z]|\d|[!#\$%&'\*\+\-\/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+(\.([a-z]|\d|[!#\$%&'\*\+\-\/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+)*)|((\x22)((((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(([\x01-\x08\x0b\x0c\x0e-\x1f\x7f]|\x21|[\x23-\x5b]|[\x5d-\x7e]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(\\([\x01-\x09\x0b\x0c\x0d-\x7f]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]))))*(((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(\x22)))@((([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.)+(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.?$/;return c("emailAddress",b,null,a)},n.phone=function(a){var b=/^((\+|(0(\d+)?[-/.\s]?))[1-9]\d{0,2}[-/.\s]?)?((\(\d{1,6}\)|\d{1,6})[-/.\s]?)?(\d+[-/.\s]?)+\d+$/;return c("phone",b,null,a)},n.url=function(a){var b=/^(https?|ftp):\/\/(((([a-zA-Z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-fA-F]{2})|[!\$&'\(\)\*\+,;=]|:)*@)?(((\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5])\.(\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5])\.(\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5])\.(\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5]))|([a-zA-Z][\-a-zA-Z0-9]*)|((([a-zA-Z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-zA-Z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-zA-Z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-zA-Z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.)+(([a-zA-Z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-zA-Z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-zA-Z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-zA-Z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.?)(:\d*)?)(\/((([a-zA-Z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-fA-F]{2})|[!\$&'\(\)\*\+,;=]|:|@)+(\/(([a-zA-Z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-fA-F]{2})|[!\$&'\(\)\*\+,;=]|:|@)*)*)?)?(\?((([a-zA-Z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-fA-F]{2})|[!\$&'\(\)\*\+,;=]|:|@)|[\uE000-\uF8FF]|\/|\?)*)?(\#((([a-zA-Z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-fA-F]{2})|[!\$&'\(\)\*\+,;=]|:|@)|\/|\?)*)?$/;return c("url",b,null,a)},n.makeRegExpValidator=c,a(n,function(a,b){"function"==typeof b&&"fromJSON"!==a&&"register"!==a&&"registerFactory"!==a&&"makeRegExpValidator"!==a&&ab.registerFunction(b,"Validator."+a)}),n}(),eb=function(){var a=function(a,b,c,d){X(a,"validator").isOptional().isInstanceOf(db).check(),X(c,"errorMessage").isNonEmptyString().check(),X(d,"key").isOptional().isNonEmptyString().check(),this.validator=a;var b=b||{};this.context=b,this.errorMessage=c,this.property=b.property,this.propertyName=b.propertyName||b.property&&b.property.name,this.key=d?d:eb.getKey(a||c,this.propertyName),this.isServerError=!1};return a.getKey=function(a,b){return(a.name||a)+(b?":"+b:"")},a}();S.Validator=db,S.ValidationError=eb;var fb=function(){function a(a,b){return b&&Z(b).whereParam("validateOnAttach").isBoolean().isOptional().whereParam("validateOnSave").isBoolean().isOptional().whereParam("validateOnQuery").isBoolean().isOptional().whereParam("validateOnPropertyChange").isBoolean().isOptional().applyAll(a),a
}var b=function(b){a(this,b)},c=b.prototype;return c._$typeName="ValidationOptions",c.using=function(b){if(!b)return this;var c=new fb(this);return a(c,b),c},c.setAsDefault=function(){return i(this,b)},b.defaultInstance=new b({validateOnAttach:!0,validateOnSave:!0,validateOnQuery:!1,validateOnPropertyChange:!0}),b}();S.ValidationOptions=fb,S.makeComplexArray=function(){function a(a,b){return b.filter(function(b){return b.parent!==a.parent})}function b(a,b){b.forEach(function(b){if(null!=b.parent)throw new Error("The complexObject is already attached. Either clone it or remove it from its current owner");e(b,a)})}function c(a,b){b.forEach(function(b){d(b,a)})}function d(a,b){var c=a.complexAspect;return c.parent!==b.parent?null:(c.parent=null,c.parentProperty=null,c)}function e(a,b){var c=a.complexAspect;return c.parent===b.parent?null:(c.parent=b.parent,c.parentProperty=b.parentProperty,c)}function f(a,b,c){return cb.initializeParent(a,b,c),a.arrayChanged=new _("arrayChanged",a),g(a,cb.mixin),g(a,h)}var h={};return h._getGoodAdds=function(b){return a(this,b)},h._beforeChange=function(){cb.updateEntityState(this)},h._processAdds=function(a){b(this,a)},h._processRemoves=function(a){c(this,a)},h._rejectChanges=function(){if(this._origValues){var a=this;this.forEach(function(b){d(b,a)}),this.length=0,this._origValues.forEach(function(b){a.push(b)}),Array.prototype.push.apply(this,this._origValues)}},h._acceptChanges=function(){this._origValues=null},f}();var gb=function(){var a={isAttach:function(){return!!this.isAttach},isDetach:function(){return!!this.isDetach},isModification:function(){return!!this.isModification}},b=new $("EntityAction",a);return b.Attach=b.addSymbol({isAttach:!0}),b.AttachOnQuery=b.addSymbol({isAttach:!0}),b.AttachOnImport=b.addSymbol({isAttach:!0}),b.Detach=b.addSymbol({isDetach:!0}),b.MergeOnQuery=b.addSymbol({isModification:!0}),b.MergeOnImport=b.addSymbol({isModification:!0}),b.MergeOnSave=b.addSymbol({isModification:!0}),b.PropertyChange=b.addSymbol({isModification:!0}),b.EntityStateChange=b.addSymbol(),b.AcceptChanges=b.addSymbol(),b.RejectChanges=b.addSymbol({isModification:!0}),b.Clear=b.addSymbol({isDetach:!0}),b.seal(),b}();S.EntityAction=gb;var hb=function(){function b(a){var c=a.entityAspect||a.complexAspect,d=a.entityType||a.complexType,e=c.originalValues;for(var f in e)a.setProperty(f,e[f]);d.complexProperties.forEach(function(c){var d=a.getProperty(c.name);c.isScalar?b(d):(d._rejectChanges(),d.forEach(function(a){b(a)}))})}function c(a){var b=a.entityAspect||a.complexAspect;b.originalValues={};var d=a.entityType||a.complexType;d.complexProperties.forEach(function(b){var d=a.getProperty(b.name);b.isScalar?c(d):(d._acceptChanges(),d.forEach(function(a){c(a)}))})}function d(a){var b=!0,c=a.entityType||a.complexType,e=a.entityAspect||a.complexAspect,f=a.entityAspect||a.complexAspect.getEntityAspect();return c.getProperties().forEach(function(c){var g=a.getProperty(c.name),h=e.getPropertyPath(c.name);if(c.validators.length>0){var i={entity:f.entity,property:c,propertyName:h};b=f._validateProperty(g,i)&&b}c.isComplexProperty&&c.isScalar&&(b=d(g)&&b)}),c.validators.forEach(function(a){b=i(f,a,e.entity)&&b}),b}function e(a,b){var c=b.isDeleted();c?g(a,!0):w(a.entityAspect.entityManager,"isLoading",!0,function(){g(a,!1)})}function g(a,b){a.entityType.navigationProperties.forEach(function(c){var d=c.inverse,e=a.getProperty(c.name);if(c.isScalar){if(e){if(d)if(d.isScalar)h(e,d,b);else{var f=e.getProperty(d.name);f.length&&q(f,a)}a.setProperty(c.name,null)}}else d&&e.slice(0).forEach(function(a){d.isScalar&&h(a,d,b)}),e.length=0})}function h(a,b,c){if(c)a.setProperty(b.name,null);else{var d=(a.entityAspect.entityManager,b.foreignKeyNames);if(d)var e=d.map(function(b){return a.getProperty(b)});a.setProperty(b.name,null),d&&d.forEach(function(b,c){a.setProperty(b,e[c])})}}function i(a,b,c,d){var e=b.validate(c,d);if(e)return a._addValidationError(e),!1;var f=eb.getKey(b,d?d.propertyName:null);return a._removeValidationError(f),!0}var j=function(a){if(null===a){var b=hb._nullInstance;if(b)return b;hb._nullInstance=this}else{if(void 0===a)throw new Error("The EntityAspect ctor requires an entity as its only argument.");if(a.entityAspect)return a.entityAspect}if(!(this instanceof hb))return new hb(a);if(this.entity=a,this.entityGroup=null,this.entityManager=null,this.entityState=kb.Detached,this.isBeingSaved=!1,this.originalValues={},this.hasValidationErrors=!1,this._validationErrors={},this.validationErrorsChanged=new _("validationErrorsChanged",this),this.propertyChanged=new _("propertyChanged",this),null!=a){a.entityAspect=this;var c=a.entityType||a._$entityType;if(!c){var d=a.prototype._$typeName;throw d?new Error("Metadata for this entityType has not yet been resolved: "+d):new Error("This entity is not registered as a valid EntityType")}var e=c.getEntityCtor();bb.getDefaultInstance().startTracking(a,e.prototype)}},k=j.prototype;return _.bubbleEvent(k,function(){return this.entityManager}),k.getKey=function(a){if(a=X(a,"forceRefresh").isBoolean().isOptional().check(!1),a||!this._entityKey){var b=this.entity.entityType,c=b.keyProperties,d=c.map(function(a){return this.entity.getProperty(a.name)},this);this._entityKey=new jb(b,d)}return this._entityKey},k.acceptChanges=function(){var a=this.entityManager;this.entityState.isDeleted()?a.detachEntity(this.entity):this.setUnchanged(),a.entityChanged.publish({entityAction:gb.AcceptChanges,entity:this.entity})},k.rejectChanges=function(){var a=this.entity,c=this.entityManager;w(c,"isRejectingChanges",!0,function(){b(a)}),this.entityState.isAdded()?(c.detachEntity(a),c._notifyStateChange(a,!1)):(this.entityState.isDeleted()&&this.entityManager._linkRelatedEntities(a),this.setUnchanged(),this.propertyChanged.publish({entity:a,propertyName:null}),this.entityManager.entityChanged.publish({entityAction:gb.RejectChanges,entity:a}))},k.getPropertyPath=function(a){return a},k.setUnchanged=function(){c(this.entity),delete this.hasTempKey,this.entityState=kb.Unchanged,this.entityManager._notifyStateChange(this.entity,!1)},k.setModified=function(){this.entityState=kb.Modified,this.entityManager._notifyStateChange(this.entity,!0)},k.setDeleted=function(){var a=this.entityManager,b=this.entity;this.entityState.isAdded()?(a.detachEntity(b),a._notifyStateChange(b,!1)):(this.entityState=kb.Deleted,e(b,kb.Deleted),a._notifyStateChange(b,!0))},k.setDetached=function(){var a=this.entityGroup;if(!a)return!1;var b=this.entity;return a.detachEntity(b),e(b,kb.Detached),this.entityManager.entityChanged.publish({entityAction:gb.Detach,entity:b}),this._detach(),!0},k.loadNavigationProperty=function(a,b,c){var d=this.entity,e=d.entityType._checkNavProperty(a),f=zb.fromEntityNavigation(d,e);return d.entityAspect.entityManager.executeQuery(f,b,c)},k.validateEntity=function(){var a=!0;return this._processValidationOpAndPublish(function(b){a=d(b.entity)}),a},k.validateProperty=function(a,b){var c=this.getPropertyValue(a);return c&&c.complexAspect?d(c):(b=b||{},b.entity=this.entity,"string"==typeof a?(b.property=this.entity.entityType.getProperty(a,!0),b.propertyName=a):(b.property=a,b.propertyName=a.name),this._validateProperty(c,b))},k.getValidationErrors=function(a){X(a,"property").isOptional().isEntityProperty().or().isString().check();var b=f(this._validationErrors);if(a){var c="string"==typeof a?a:a.name;b=b.filter(function(a){return a.property&&(a.property.name===c||-1!=c.indexOf(".")&&a.propertyName==c)})}return b},k.addValidationError=function(a){X(a,"validationError").isInstanceOf(eb).check(),this._processValidationOpAndPublish(function(b){b._addValidationError(a)})},k.removeValidationError=function(a){X(a,"validationErrorOrKey").isString().or().isInstanceOf(eb).or().isInstanceOf(db).check();var b="string"==typeof a?a:a.key;this._processValidationOpAndPublish(function(a){a._removeValidationError(b)})},k.clearValidationErrors=function(){this._processValidationOpAndPublish(function(b){a(b._validationErrors,function(a,c){c&&(delete b._validationErrors[a],b._pendingValidationResult.removed.push(c))}),b.hasValidationErrors=!G(this._validationErrors)})},k.getParentKey=function(a){var b=a.foreignKeyNames;if(0===b.length)return null;var c=this,d=b.map(function(a){return c.entity.getProperty(a)});return new jb(a.entityType,d)},k.getPropertyValue=function(a){X(a,"property").isString().or().isEntityProperty().check();var b;if("string"==typeof a){var c=a.trim().split("."),d=c.shift();for(b=this.entity,b=b.getProperty(d);c.length>0;)d=c.shift(),b=b.getProperty(d)}else{if(!(a.parentType instanceof rb))throw new Error("The validateProperty method does not accept a 'property' parameter whose parentType is a ComplexType; Pass a 'property path' string as the 'property' parameter instead ");b=this.entity.getProperty(a.name)}return b},k._detach=function(){this.entityGroup=null,this.entityManager=null,this.entityState=kb.Detached,this.originalValues={},this._validationErrors={},this.hasValidationErrors=!1,this.validationErrorsChanged.clear(),this.propertyChanged.clear()},k._validateProperty=function(a,b){var c=!0;return this._processValidationOpAndPublish(function(d){b.property.validators.forEach(function(e){c=i(d,e,a,b)&&c})}),c},k._processValidationOpAndPublish=function(a){if(this._pendingValidationResult)a(this);else try{this._pendingValidationResult={entity:this.entity,added:[],removed:[]},a(this),(this._pendingValidationResult.added.length>0||this._pendingValidationResult.removed.length>0)&&(this.validationErrorsChanged.publish(this._pendingValidationResult),this.entityManager&&this.entityManager.validationErrorsChanged.publish(this._pendingValidationResult))}finally{this._pendingValidationResult=void 0}},k._addValidationError=function(a){this._validationErrors[a.key]=a,this.hasValidationErrors=!0,this._pendingValidationResult.added.push(a)},k._removeValidationError=function(a){var b=this._validationErrors[a];b&&(delete this._validationErrors[a],this.hasValidationErrors=!G(this._validationErrors),this._pendingValidationResult.removed.push(b))},j}(),ib=function(){var a=function(a,b,c){if(!a)throw new Error("The ComplexAspect ctor requires an entity as its only argument.");if(a.complexAspect)return a.complexAspect;if(!(this instanceof ib))return new ib(a,b,c);this.complexObject=a,a.complexAspect=this,this.originalValues={},null!=b&&(this.parent=b,this.parentProperty=c);var d=a.complexType;if(!d){var e=a.prototype._$typeName;throw e?new Error("Metadata for this complexType has not yet been resolved: "+e):new Error("This entity is not registered as a valid ComplexType")}var f=d.getCtor();bb.getDefaultInstance().startTracking(a,f.prototype)},b=a.prototype;return b.getEntityAspect=function(){var a=this.parent;if(!a)return new hb(null);for(var b=a.entityAspect;a&&!b;)a=a.complexAspect&&a.complexAspect.parent,b=a&&a.entityAspect;return b||new hb(null)},b.getPropertyPath=function(a){var b=this.parent;if(!b)return null;var c=b.complexAspect||b.entityAspect;return c.getPropertyPath(this.parentProperty.name+"."+a)},a}();S.EntityAspect=hb,S.ComplexAspect=ib;var jb=function(){function a(a){return a.join(b)}var b=":::",c=function(b,c){X(b,"entityType").isInstanceOf(rb).check();var d=b.getSelfAndSubtypes();d.length>1&&(this._subtypes=d.filter(function(a){return a.isAbstract===!1})),Array.isArray(c)||(c=U(arguments,1)),this.entityType=b,b.keyProperties.forEach(function(a,b){a.dataType===lb.Guid&&(c[b]=c[b]&&c[b].toLowerCase())}),this.values=c,this._keyInGroup=a(c)};c._$typeName="EntityKey";var d=c.prototype;return d.toJSON=function(){return{entityType:this.entityType.name,values:this.values}},c.fromJSON=function(a,b){var c=b._getEntityType(a.entityType,!0);return new jb(c,a.values)},d.equals=function(a){return a instanceof jb?this.entityType===a.entityType&&s(this.values,a.values):!1},d.toString=function(){return this.entityType.name+"-"+this._keyInGroup},c.equals=function(a,b){return a instanceof jb?a.equals(b):!1},d._isEmpty=function(){return 0===this.values.join("").length},c.createKeyString=a,c}();S.EntityKey=jb;var kb=function(){var a={isUnchanged:function(){return this===b.Unchanged},isAdded:function(){return this===b.Added},isModified:function(){return this===b.Modified},isDeleted:function(){return this===b.Deleted},isDetached:function(){return this===b.Detached},isUnchangedOrModified:function(){return this===b.Unchanged||this===b.Modified},isAddedModifiedOrDeleted:function(){return this===b.Added||this===b.Modified||this===b.Deleted}},b=new $("EntityState",a);return b.Unchanged=b.addSymbol(),b.Added=b.addSymbol(),b.Modified=b.addSymbol(),b.Deleted=b.addSymbol(),b.Detached=b.addSymbol(),b.seal(),b}();S.EntityState=kb,S.makePrimitiveArray=function(){function a(a,c,d){return cb.initializeParent(a,c,d),a.arrayChanged=new _("arrayChanged",a),g(a,cb.mixin),g(a,b)}var b={};return b._getGoodAdds=function(a){return a},b._beforeChange=function(){var a=this.getEntityAspect();a.entityState.isUnchanged()&&a.setModified(),a.entityState.isModified()&&!this._origValues&&(this._origValues=this.slice(0))},b._processAdds=function(){},b._processRemoves=function(){},b._rejectChanges=function(){this._origValues&&(this.length=0,Array.prototype.push.apply(this,this._origValues))},b._acceptChanges=function(){this._origValues=null},a}(),S.makeRelationArray=function(){function a(a,b){var c=d(a,b);if(!c.length)return c;var e=a.parentEntity,f=e.entityAspect.entityManager;return f&&!f.isLoading&&c.forEach(function(b){if(b.entityAspect.entityState.isDetached()){a._inProgress=!0;try{f.attachEntity(b,kb.Added)}finally{a._inProgress=!1}}}),c}function b(a,b){var c=a.parentEntity,d=a.navigationProperty,e=a._addsInProcess,f=d.inverse,g=e.length;try{b.forEach(function(a){if(e.push(a),f)a.setProperty(f.name,c);else{var b=c.entityType.keyProperties;d.invForeignKeyNames.forEach(function(d,e){a.setProperty(d,c.getProperty(b[e].name))})}})}finally{e.splice(g,b.length)}}function c(a,b){var c=a.navigationProperty.inverse;c&&b.forEach(function(a){a.setProperty(c.name,null)})}function d(a,b){var c,d=a.parentEntity,e=a.navigationProperty,f=e.inverse;if(f)c=b.filter(function(b){if(a._addsInProcess.indexOf(b)>=0)return!1;var c=b.getProperty(f.name);return c!==d});else{var g=e.invForeignKeyNames,h=d.entityType.keyProperties;c=b.filter(function(b){return a._addsInProcess.indexOf(b)>=0?!1:g.some(function(a,c){var e=h[c].name,f=d.getProperty(e),g=b.getProperty(a);return f!==g})})}return c}function e(a,b,c){return a.parentEntity=b,a.navigationProperty=c,a.arrayChanged=new _("arrayChanged",a),a._addsInProcess=[],g(a,cb.mixin),g(a,f)}var f={};return f.load=function(a,b){var c=this.parentEntity,d=zb.fromEntityNavigation(this.parentEntity,this.navigationProperty),e=c.entityAspect.entityManager;return e.executeQuery(d,a,b)},f._getEventParent=function(){return this.parentEntity.entityAspect},f._getPendingPubs=function(){var a=this.parentEntity.entityAspect.entityManager;return a&&a._pendingPubs},f._getGoodAdds=function(b){return a(this,b)},f._processAdds=function(a){b(this,a)},f._processRemoves=function(a){c(this,a)},e}();var lb=function(){function a(a,b){throw a=K(a,b),new Error(a)}function b(a){switch(a){case x.String:return db.string;case x.Int64:return db.int64;case x.Int32:return db.int32;case x.Int16:return db.int16;case x.Decimal:return db.number;case x.Double:return db.number;case x.Single:return db.number;case x.DateTime:return db.date;case x.DateTimeOffset:return db.date;case x.Boolean:return db.bool;case x.Guid:return db.guid;case x.Byte:return db.byte;case x.Binary:return db.none;case x.Time:return db.duration;case x.Undefined:return db.none}}var c={},d={stringPrefix:"K_",nextNumber:-1,nextNumberIncrement:-1},e=function(){return d.stringPrefix+f().toString()},f=function(){var a=d.nextNumber;return d.nextNumber+=d.nextNumberIncrement,a},g=function(){return z()},h=function(){return new Date},i=function(a){return null==a?a:a.toString()},j=function(a,b){if("string"===b){var c=a.trim();if(""===c)return null;var d=parseInt(c,10);return isNaN(d)?a:d}return"number"===b?Math.round(a):a},k=function(a,b){if("string"===b){var c=a.trim();if(""===c)return null;var d=parseFloat(c);return isNaN(d)?a:d}return a},l=function(a,b){var c;if("string"===b){var d=a.trim();return""===d?null:(c=new Date(Date.parse(d)),C(c)?c:a)}return"number"===b?(c=new Date(a),C(c)?c:a):a},m=function(a,b){if("string"===b){var c=a.trim().toLowerCase();return"false"===c||""===c?!1:"true"===c?!0:a}return a},n=function(a){return null==a?null:"'"+a.replace(/'/g,"''")+"'"},o=function(a){return null==a?null:"string"==typeof a?parseInt(a,10):a},p=function(a){return function(b){return null==b?null:("string"==typeof b&&(b=parseFloat(b)),b+a)}},q=function(b){if(null==b)return null;try{return"datetime'"+b.toISOString()+"'"}catch(c){a("'%1' is not a valid dateTime",b)}},r=function(b){if(null==b)return null;try{return"datetimeoffset'"+b.toISOString()+"'"}catch(c){a("'%1' is not a valid dateTime",b)}},s=function(b){return null==b?null:(F(b)||a("'%1' is not a valid ISO 8601 duration",b),"time'"+b+"'")},t=function(b){return null==b?null:(E(b)||a("'%1' is not a valid guid",b),"guid'"+b+"'")},u=function(a){return null==a?null:"string"==typeof a?"true"===a.trim().toLowerCase():!!a},v=function(a){return null==a?a:"binary'"+a+"'"},w=function(a){return a},x=new $("DataType",c);x.String=x.addSymbol({defaultValue:"",parse:i,fmtOData:n,getNext:e}),x.Int64=x.addSymbol({defaultValue:0,isNumeric:!0,isInteger:!0,quoteJsonOData:!0,parse:j,fmtOData:p("L"),getNext:f}),x.Int32=x.addSymbol({defaultValue:0,isNumeric:!0,isInteger:!0,parse:j,fmtOData:o,getNext:f}),x.Int16=x.addSymbol({defaultValue:0,isNumeric:!0,isInteger:!0,parse:j,fmtOData:o,getNext:f}),x.Byte=x.addSymbol({defaultValue:0,isNumeric:!0,isInteger:!0,parse:j,fmtOData:o}),x.Decimal=x.addSymbol({defaultValue:0,isNumeric:!0,quoteJsonOData:!0,parse:k,fmtOData:p("m"),getNext:f}),x.Double=x.addSymbol({defaultValue:0,isNumeric:!0,parse:k,fmtOData:p("d"),getNext:f}),x.Single=x.addSymbol({defaultValue:0,isNumeric:!0,parse:k,fmtOData:p("f"),getNext:f}),x.DateTime=x.addSymbol({defaultValue:new Date(1900,0,1),isDate:!0,parse:l,fmtOData:q,getNext:h}),x.DateTimeOffset=x.addSymbol({defaultValue:new Date(1900,0,1),isDate:!0,parse:l,fmtOData:r,getNext:h}),x.Time=x.addSymbol({defaultValue:"PT0S",fmtOData:s}),x.Boolean=x.addSymbol({defaultValue:!1,parse:m,fmtOData:u}),x.Guid=x.addSymbol({defaultValue:"00000000-0000-0000-0000-000000000000",fmtOData:t,getNext:g}),x.Binary=x.addSymbol({defaultValue:null,fmtOData:v}),x.Undefined=x.addSymbol({defaultValue:void 0,fmtOData:w}),x.seal(),x.fromEdmDataType=function(a){var b=null,c=a.split(".");if(c.length>1){var d=c[1];b="image"===d?x.Byte:2===c.length?x.fromName(d)||x.Undefined:x.String}return b},x.fromValue=function(a){if(C(a))return x.DateTime;switch(typeof a){case"string":return E(a)?x.Guid:F(a)&&a.length>3?x.Time:x.String;case"boolean":return x.Boolean;case"number":return x.Int32}return x.Undefined};var y=/.\d{3}$/;return x.parseTimeFromServer=function(a){if("string"==typeof a)return a;if(a&&"Edm.Time"===a.__edmType){var b=Math.floor(a.ms/1e3);return"PT"+b+"S"}return a},x.parseDateAsUTC=function(a){if("string"==typeof a){var b=y.test(a);a=b?a+"Z":a}return a=new Date(Date.parse(a))},x.parseDateFromServer=x.parseDateAsUTC,x.parseRawValue=function(a,b){return void 0===a?void 0:(b.isDate&&a?C(a)||(a=x.parseDateFromServer(a)):b===x.Binary?a&&void 0!==a.$value&&(a=a.$value):b===x.Time&&(a=x.parseTimeFromServer(a)),a)},x.constants=d,x.getSymbols().forEach(function(a){a.validatorCtor=b(a)}),x}();S.DataType=lb;var mb=function(){function a(a,b){return b&&(Z(b).whereParam("serviceName").isOptional().whereParam("adapterName").isString().isOptional().whereParam("hasServerMetadata").isBoolean().isOptional().whereParam("jsonResultsAdapter").isInstanceOf(nb).isOptional().whereParam("useJsonp").isBoolean().isOptional().applyAll(a),a.serviceName=a.serviceName&&mb._normalizeServiceName(a.serviceName),a.adapterInstance=a.adapterName&&ab.getAdapterInstance("dataService",a.adapterName)),a}var b=function(b){a(this,b)},c=b.prototype;return c._$typeName="DataService",c.using=function(b){if(!b)return this;var c=new mb(this);return a(c,b)},b.resolve=function(a){a.push({hasServerMetadata:!0,useJsonp:!1});var b=new mb(l(a,["serviceName","adapterName","hasServerMetadata","jsonResultsAdapter","useJsonp"]));if(!b.serviceName)throw new Error("Unable to resolve a 'serviceName' for this dataService");return b.adapterInstance=b.adapterInstance||ab.getAdapterInstance("dataService",b.adapterName),b.jsonResultsAdapter=b.jsonResultsAdapter||b.adapterInstance.jsonResultsAdapter,b},b._normalizeServiceName=function(a){return a=a.trim(),"/"!==a.substr(-1)?a+"/":a},c.toJSON=function(){return j(this,{serviceName:null,adapterName:null,hasServerMetadata:null,jsonResultsAdapter:function(a){return a&&a.name},useJsonp:null})},b.fromJSON=function(a){return a.jsonResultsAdapter=ab._fetchObject(nb,a.jsonResultsAdapter),new mb(a)},c.makeUrl=function(a){var b=this.serviceName;return V.stringEndsWith(b,"/")&&(b=b.substr(0,b.length-1)),a="/"+a,V.stringEndsWith(b,a)||(b+=a),b},b}(),nb=function(){function a(a){return a.results}var b=function(b){if(1!==arguments.length)throw new Error("The JsonResultsAdapter ctor should be called with a single argument that is a configuration object.");Z(b).whereParam("name").isNonEmptyString().whereParam("extractResults").isFunction().isOptional().withDefault(a).whereParam("visitNode").isFunction().applyAll(this),ab._storeObject(this,c._$typeName,this.name)},c=b.prototype;return c._$typeName="JsonResultsAdapter",b}();S.DataService=mb,S.JsonResultsAdapter=nb;var ob=v("Q");ob||(ob=function(){var a="Q is undefined. Are you missing Q.js? See https://github.com/kriskowal/q";throw new Error(a)},ob.defer=ob.resolve=ob.reject=ob),S.config.setQ=function(a){ob=a};var pb=function(){function a(a){var b=[];for(var c in a){var d=a[c];c===d.name&&b.push(a[c])}return b}function b(a,b,c){var e=O(b.shortName,b.namespace),g=a._getEntityType(e,!0);if(g)return c?d(g,b):g;var h={shortName:b.shortName,namespace:b.namespace,isAbstract:b.isAbstract,autoGeneratedKeyType:vb.fromName(b.autoGeneratedKeyType),defaultResourceName:b.defaultResourceName,custom:b.custom};if(g=b.isComplexType?new sb(h):new rb(h),b.baseTypeName){g.baseTypeName=b.baseTypeName;var i=a._getEntityType(b.baseTypeName,!0);i?f(a,b,g,i):t(a._deferredTypes,b.baseTypeName).push({json:b,stype:g})}else f(a,b,g,null);return g}function d(a,b){return b.custom&&(a.custom=b.custom),e(a,b.dataProperties),e(a,b.navigationProperties),a}function e(a,b){b&&b.forEach(function(b){var c=b.name;if(!c){if(!b.nameOnServer)throw new Error("Unable to complete 'importMetadata' - cannot locate a 'name' or 'nameOnServer' for one of the imported property nodes");c=a.metadataStore.namingConvention.serverPropertyNameToClient(b.nameOnServer,{})}if(b.custom){var d=a.getProperty(c,!0);d.custom=b.custom}})}function f(a,b,c,d){b.validators&&(c.validators=b.validators.map(db.fromJSON)),d&&(c.baseEntityType=d,d.dataProperties.forEach(function(a){var b=new tb(a);b.isInherited=!0,c.addProperty(b)}),d.navigationProperties.forEach(function(a){var b=new ub(a);b.isInherited=!0,c.addProperty(b)})),b.dataProperties.forEach(function(a){c.addProperty(tb.fromJSON(a))});var e=!b.isComplexType;e&&b.navigationProperties&&b.navigationProperties.forEach(function(a){c.addProperty(ub.fromJSON(a))}),a.addEntityType(c);var g=a._deferredTypes,h=g[c.name];h&&(h.forEach(function(b){f(a,b.json,b.stype,c)}),delete g[c.name])}function h(a,b,c){if(N(b))return b;var d=a._shortNameMap[b];if(!d&&c)throw new Error("Unable to locate 'entityTypeName' of: "+b);return d}var i=0,j=function(a){a=a||{},Z(a).whereParam("namingConvention").isOptional().isInstanceOf(yb).withDefault(yb.defaultInstance).whereParam("localQueryComparisonOptions").isOptional().isInstanceOf(xb).withDefault(xb.defaultInstance).whereParam("serializerFn").isOptional().isFunction().applyAll(this),this.dataServices=[],this._resourceEntityTypeMap={},this._structuralTypeMap={},this._shortNameMap={},this._ctorRegistry={},this._incompleteTypeMap={},this._incompleteComplexTypeMap={},this._id=i++},k=j.prototype;return k._$typeName="MetadataStore",j.ANONTYPE_PREFIX="_IB_",k.setProperties=function(a){Z(a).whereParam("name").isString().isOptional().whereParam("serializerFn").isFunction().isOptional().applyAll(this)},k.addDataService=function(a,b){X(a,"dataService").isInstanceOf(mb).check(),X(b,"shouldOverwrite").isBoolean().isOptional().check();var c=this._getDataServiceIndex(a.serviceName);if(c>=0){if(!b)throw new Error("A dataService with this name '"+a.serviceName+"' already exists in this MetadataStore");this.dataServices[c]=a}else this.dataServices.push(a)},k._getDataServiceIndex=function(a){return p(this.dataServices,function(b){return b.serviceName===a})},k.addEntityType=function(a){if(a instanceof rb||a instanceof sb||(a=a.isComplexType?new sb(a):new rb(a)),!a.isComplexType&&0===a.keyProperties.length&&!a.isAbstract)throw new Error("Unable to add "+a.name+" to this MetadataStore. An EntityType must have at least one property designated as a key property - See the 'DataProperty.isPartOfKey' property.");if(a.metadataStore=this,!a.isAnonymous){if(this._structuralTypeMap[a.name])throw new Error("Type "+a.name+" already exists in this MetadataStore.");this._structuralTypeMap[a.name]=a,this._shortNameMap[a.shortName]=a.name}if(a.getProperties().forEach(function(b){a._updateNames(b),b.isUnmapped||a._mappedPropertiesCount++}),a._updateCps(),!a.isComplexType){a._updateNps();var b=a.defaultResourceName||a.baseEntityType&&a.baseEntityType.defaultResourceName;b&&!this.getEntityTypeNameForResourceName(b)&&this.setEntityTypeForResourceName(b,a.name),a.defaultResourceName=b,a.getEntityCtor()}a.baseEntityType&&a.baseEntityType.subtypes.push(a)},k.exportMetadata=function(){var a=JSON.stringify({metadataVersion:S.metadataVersion,name:this.name,namingConvention:this.namingConvention.name,localQueryComparisonOptions:this.localQueryComparisonOptions.name,dataServices:this.dataServices,structuralTypes:c(this._structuralTypeMap),resourceEntityTypeMap:this._resourceEntityTypeMap},null,ab.stringifyPad);return a},k.importMetadata=function(a,c){X(c,"allowMerge").isOptional().isBoolean().check(),this._deferredTypes={};var d="string"==typeof a?JSON.parse(a):a;if(d.schema)return qb.parse(this,d.schema,d.altMetadata);if(d.metadataVersion&&d.metadataVersion!==S.metadataVersion){var e=K("Cannot import metadata with a different 'metadataVersion' (%1) than the current 'breeze.metadataVersion' (%2) ",d.metadataVersion,S.metadataVersion);throw new Error(e)}var f=d.namingConvention,h=d.localQueryComparisonOptions;if(this.isEmpty())this.namingConvention=ab._fetchObject(yb,f)||this.namingConvention,this.localQueryComparisonOptions=ab._fetchObject(xb,h)||this.localQueryComparisonOptions;else{if(f&&this.namingConvention.name!==f)throw new Error("Cannot import metadata with a different 'namingConvention' from the current MetadataStore");if(h&&this.localQueryComparisonOptions.name!==h)throw new Error("Cannot import metadata with different 'localQueryComparisonOptions' from the current MetadataStore")}var i=this;d.dataServices&&d.dataServices.forEach(function(a){a=mb.fromJSON(a),i.addDataService(a,!0)});this._structuralTypeMap;return d.structuralTypes&&d.structuralTypes.forEach(function(a){b(i,a,c)}),g(this._resourceEntityTypeMap,d.resourceEntityTypeMap),g(this._incompleteTypeMap,d.incompleteTypeMap),this},j.importMetadata=function(a){var b=new pb;return b.importMetadata(a),b},k.hasMetadataFor=function(a){return!!this.getDataService(a)},k.getDataService=function(a){return X(a,"serviceName").isString().check(),a=mb._normalizeServiceName(a),o(this.dataServices,function(b){return b.serviceName===a})},k.fetchMetadata=function(a,b,c){if(X(a,"dataService").isString().or().isInstanceOf(mb).check(),X(b,"callback").isFunction().isOptional().check(),X(c,"errorCallback").isFunction().isOptional().check(),"string"==typeof a&&(a=this.getDataService(a)||new mb({serviceName:a})),a=mb.resolve([a]),this.hasMetadataFor(a.serviceName))throw new Error("Metadata for a specific serviceName may only be fetched once per MetadataStore. ServiceName: "+a.serviceName);return a.adapterInstance.fetchMetadata(this,a).then(function(a){return b&&b(a),ob.resolve(a)},function(a){return c&&c(a),ob.reject(a)})},k.trackUnmappedType=function(a,b){X(a,"entityCtor").isFunction().check(),X(b,"interceptor").isFunction().isOptional().check();var c=new rb(this);c._setCtor(a,b)},k.registerEntityTypeCtor=function(a,b,c,d){X(a,"structuralTypeName").isString().check(),X(b,"aCtor").isFunction().isOptional().check(),X(c,"initFn").isOptional().isFunction().or().isString().check(),X(d,"noTrackingFn").isOptional().isFunction().check();var e=h(this,a,!1),f=e||a;if(this._ctorRegistry[f]={ctor:b,initFn:c,noTrackingFn:d},e){var g=this._structuralTypeMap[e];g&&g.getCtor(!0)}},k.toQueryString=function(a){if(!a)throw new Error("query cannot be empty");if("string"==typeof a)return a;if(a instanceof zb)return a._toUri(this);throw new Error("unable to recognize query parameter as either a string or an EntityQuery")},k.isEmpty=function(){return G(this._structuralTypeMap)},k.getEntityType=function(a,b){return X(a,"structuralTypeName").isString().check(),X(b,"okIfNotFound").isBoolean().isOptional().check(!1),this._getEntityType(a,b)},k._getEntityType=function(a,b){var c=h(this,a,!1),d=this._structuralTypeMap[c];if(!d){if(b)return null;var e=K("Unable to locate a 'Type' by the name: '%1'. Be sure to execute a query or call fetchMetadata first.",a);throw new Error(e)}if(d.length){var f=d.join(",");throw new Error("There are multiple types with this 'shortName': "+f)}return d},k.getEntityTypes=function(){return a(this._structuralTypeMap)},k.getIncompleteNavigationProperties=function(){return c(this._incompleteTypeMap,function(a,b){return b})},k.getEntityTypeNameForResourceName=function(a){return X(a,"resourceName").isString().check(),this._resourceEntityTypeMap[a]},k.setEntityTypeForResourceName=function(a,b){X(a,"resourceName").isString().check(),X(b,"entityTypeOrName").isInstanceOf(rb).or().isString().check();var c;c=b instanceof rb?b.name:h(this,b,!0),this._resourceEntityTypeMap[a]=c;var d=this._getEntityType(c,!0);d&&!d.defaultResourceName&&(d.defaultResourceName=a)},k._checkEntityType=function(a){if(!a.entityType){var b=a.prototype._$typeName;if(!b)throw new Error("This entity has not been registered. See the MetadataStore.registerEntityTypeCtor method");var c=this._getEntityType(b);c&&(a.entityType=c)}},j}(),qb=function(){function a(a,c,e){a._entityTypeResourceMap={},m(c).forEach(function(c){if(c.cSpaceOSpaceMapping){var e=JSON.parse(c.cSpaceOSpaceMapping),f={};e.forEach(function(a){f[a[0]]=a[1]}),c.cSpaceOSpaceMapping=f}c.entityContainer&&m(c.entityContainer).forEach(function(b){m(b.entitySet).forEach(function(b){var d=p(b.entityType,c).typeName;a.setEntityTypeForResourceName(b.name,d),a._entityTypeResourceMap[d]=b.name})}),c.complexType&&m(c.complexType).forEach(function(b){d(b,c,a)}),c.entityType&&m(c.entityType).forEach(function(d){b(d,c,a)})});var f=a.getIncompleteNavigationProperties();if(f.length>0)throw new Error("Bad nav properties");return e&&a.importMetadata(e,!0),a}function b(a,b,d){var e=a.name,f=q(e,b),g=new rb({shortName:e,namespace:f,isAbstract:a.abstract&&"true"===a.abstract});if(a.baseType){var h=p(a.baseType,b).typeName;g.baseTypeName=h;var i=d._getEntityType(h,!0);if(i)c(g,a,b,d,i);else{var j=d._deferredTypes[h];j||(j=[],d._deferredTypes[h]=j),j.push({entityType:g,csdlEntityType:a})}}else c(g,a,b,d,null);return g}function c(a,b,d,g,h){var j=[];h&&(a.baseEntityType=h,a.autoGeneratedKeyType=h.autoGeneratedKeyType,j=h.keyProperties.map(e("name")),h.dataProperties.forEach(function(b){var c=new tb(b);c.isInherited=!0,a.addProperty(c)}),h.navigationProperties.forEach(function(b){var c=new ub(b);c.isInherited=!0,a.addProperty(c)}));var k=b.key?m(b.key.propertyRef).map(e("name")):[];
k=j.concat(k),m(b.property).forEach(function(b){f(a,b,d,k)}),m(b.navigationProperty).forEach(function(b){i(a,b,d)}),g.addEntityType(a),a.defaultResourceName=g._entityTypeResourceMap[a.name];var l=g._deferredTypes,n=l[a.name];n&&(n.forEach(function(b){c(b.entityType,b.csdlEntityType,d,g,a)}),delete l[a.name])}function d(a,b,c){var d=a.name,e=q(d,b),g=new sb({shortName:d,namespace:e});return m(a.property).forEach(function(a){f(g,a,b)}),c.addEntityType(g),g}function f(a,b,c,d){var e,f=b.type.split(".");return 2===f.length?e=g(a,b,d):j(b,c)?(e=g(a,b,d),e&&(e.enumType=b.type)):e=h(a,b,c),e&&(a.addProperty(e),k(e)),e}function g(a,b,c){var d=lb.fromEdmDataType(b.type);if(null==d)return a.warnings.push("Unable to recognize DataType for property: "+b.name+" DateType: "+b.type),null;var e="true"===b.nullable||null==b.nullable,f=null!=c&&c.indexOf(b.name)>=0;f&&a.autoGeneratedKeyType===vb.None&&l(b)&&(a.autoGeneratedKeyType=vb.Identity);var g=b.maxLength;g=null==g||"Max"===g?null:parseInt(g,10);var h=new tb({nameOnServer:b.name,dataType:d,isNullable:e,isPartOfKey:f,maxLength:g,defaultValue:b.defaultValue,concurrencyMode:b.concurrencyMode});return d===lb.Undefined&&(h.rawTypeName=b.type),h}function h(a,b,c){var d=p(b.type,c).typeName,e=new tb({nameOnServer:b.name,complexTypeName:d,isNullable:!1});return e}function i(a,b,c){var d=n(b,c),f=o(d.end,function(a){return a.role===b.toRole}),g="*"!==f.multiplicity,h=p(f.type,c).typeName,i=d.referentialConstraint;if(i){var j={nameOnServer:b.name,entityTypeName:h,isScalar:g,associationName:d.name},k=i.principal,l=i.dependent,q=m(l.propertyRef),r=q.map(e("name"));b.fromRole===k.role?j.invForeignKeyNamesOnServer=r:j.foreignKeyNamesOnServer=r;var s=new ub(j);return a.addProperty(s),s}}function j(a,b){if(!b.enumType)return!1;var c=m(b.enumType),d=a.type.split("."),e=d[d.length-1];return c.some(function(a){return a.name===e})}function k(a){var b;if(a.isNullable||a.validators.push(db.required()),!a.isComplexProperty){if(a.dataType===lb.String)if(a.maxLength){var c={maxLength:a.maxLength};b=db.maxLength(c)}else b=db.string();else b=a.dataType.validatorCtor();a.validators.push(b)}}function l(a){var b=o(Object.keys(a),function(a){return a.indexOf("StoreGeneratedPattern")>=0});if(b)return"Identity"===a[b];var c=a.extensions;if(!c)return!1;var d=o(c,function(a){return"StoreGeneratedPattern"===a.name&&"Identity"===a.value});return!!d}function n(a,b){var c=p(a.relationship,b).shortTypeName,d=b.association;if(!d)return null;Array.isArray(d)||(d=[d]);var e=o(d,function(a){return a.name===c});return e}function p(a,b){if(!a)return null;if(I(a,pb.ANONTYPE_PREFIX))return{shortTypeName:a,namespace:"",typeName:a,isAnonymous:!0};var c=a.split(",")[0],d=c.split(".");if(d.length>1){var e,f=d[d.length-1];if(b)e=q(f,b);else{var g=d.slice(0,d.length-1);e=g.join(".")}return{shortTypeName:f,namespace:e,typeName:O(f,e)}}return{shortTypeName:a,namespace:"",typeName:a}}function q(a,b){var c,d=b.cSpaceOSpaceMapping;if(d){var e=d[b.namespace+"."+a];c=e&&e.substr(0,e.length-(a.length+1))}return c||b.namespace}var r=y(function(a){return a&&p(a).typeName});return{parse:a,normalizeTypeName:r}}(),rb=function(){function a(a,b){return a.entityAspect||a.complexAspect?a.getProperty(b.name):a[b.name]}function b(){return function(){}}function c(a){return a.filter(function(a){return!a.isInherited})}function f(a,b,c){var d=c+"OnServer",e=b[c];if(e&&e.length){if(b.isUnmapped)return;var f=m(e).map(function(c){var d=a.clientPropertyNameToServer(c,b),e=a.serverPropertyNameToClient(d,b);if(c!==e)throw new Error("NamingConvention for this client property name does not roundtrip properly:"+c+"-->"+e);return d});b[d]=Array.isArray(e)?f:f[0]}else{var g=b[d];if(!g||0===g.length)return;var h=m(g).map(function(c){var d=a.serverPropertyNameToClient(c,b),e=a.clientPropertyNameToServer(d,b);if(c!==e)throw new Error("NamingConvention for this server property name does not roundtrip properly:"+c+"-->"+e);return d});b[c]=Array.isArray(g)?h:h[0]}}function g(a,b){var c=b._getEntityType(a.complexTypeName,!0);if(!c)return!1;if(!(c instanceof sb))throw new Error("Unable to resolve ComplexType with the name: "+a.complexTypeName+" for the property: "+property.name);return a.dataType=c,a.defaultValue=null,!0}function h(a,b){var c=b._getEntityType(a.entityTypeName,!0);if(!c)return!1;a.entityType=c;var d=o(c.navigationProperties,function(b){return b.associationName===a.associationName&&(b.name!==a.name||b.entityTypeName!==a.entityTypeName)});return a.inverse=d,d||a.invForeignKeyNames.forEach(function(b){var d=c.getDataProperty(b),e=a.parentType;d.inverseNavigationProperty=o(e.navigationProperties,function(a){return a.invForeignKeyNames&&a.invForeignKeyNames.indexOf(d.name)>=0&&a.entityType===d.parentType}),i(c.foreignKeyProperties,d)}),k(a),!0}function i(a,b){var c=a.indexOf(b);-1===c&&a.push(b)}function k(a){var b=a.foreignKeyNames;if(0!==b.length){var c=a.parentType,d=b.map(function(a){return c.getDataProperty(a)}),e=c.foreignKeyProperties;d.forEach(function(b){i(e,b),b.relatedNavigationProperty=a,a.entityType.inverseForeignKeyProperties.push(b),a.relatedDataProperties?a.relatedDataProperties.push(b):a.relatedDataProperties=[b]})}}function l(a,b){var c=a.getPropertyNames(),d=bb.getDefaultInstance().getTrackablePropertyNames(b);d.forEach(function(b){if(-1===c.indexOf(b)){var d=new tb({name:b,dataType:lb.Undefined,isNullable:!0,isUnmapped:!0});a.subtypes?a.getSelfAndSubtypes().forEach(function(a){a.addProperty(new tb(d))}):a.addProperty(d)}})}var n=0,p=function(a){if(arguments.length>1)throw new Error("The EntityType ctor has a single argument that is either a 'MetadataStore' or a configuration object.");"MetadataStore"===a._$typeName?(this.metadataStore=a,this.shortName="Anon_"+ ++n,this.namespace="",this.isAnonymous=!0):Z(a).whereParam("shortName").isNonEmptyString().whereParam("namespace").isString().isOptional().withDefault("").whereParam("baseTypeName").isString().isOptional().whereParam("isAbstract").isBoolean().isOptional().withDefault(!1).whereParam("autoGeneratedKeyType").isEnumOf(vb).isOptional().withDefault(vb.None).whereParam("defaultResourceName").isNonEmptyString().isOptional().withDefault(null).whereParam("dataProperties").isOptional().whereParam("navigationProperties").isOptional().whereParam("serializerFn").isOptional().isFunction().whereParam("custom").isOptional().applyAll(this),this.name=O(this.shortName,this.namespace),this.dataProperties=[],this.navigationProperties=[],this.complexProperties=[],this.keyProperties=[],this.foreignKeyProperties=[],this.inverseForeignKeyProperties=[],this.concurrencyProperties=[],this.unmappedProperties=[],this.validators=[],this.warnings=[],this._mappedPropertiesCount=0,this.subtypes=[],P(this,a.dataProperties,tb),P(this,a.navigationProperties,ub)},q=p.prototype,r=lb.parseRawValue;return q._$typeName="EntityType",q.setProperties=function(a){Z(a).whereParam("autoGeneratedKeyType").isEnumOf(vb).isOptional().whereParam("defaultResourceName").isString().isOptional().whereParam("serializerFn").isFunction().isOptional().whereParam("custom").isOptional().applyAll(this),a.defaultResourceName&&(this.defaultResourceName=a.defaultResourceName)},q.isSubtypeOf=function(a){X(a,"entityType").isInstanceOf(rb).check();var b=this;do{if(b===a)return!0;b=b.baseEntityType}while(b);return!1},q.getSelfAndSubtypes=function(){var a=[this];return this.subtypes.forEach(function(b){var c=b.getSelfAndSubtypes();a.push.apply(a,c)}),a},q.addProperty=function(a){if(X(a,"dataProperty").isInstanceOf(tb).or().isInstanceOf(ub).check(),this.metadataStore&&!a.isUnmapped)throw new Error("The '"+this.name+"' EntityType has already been added to a MetadataStore and therefore no additional properties may be added to it.");if(a.parentType){if(a.parentType!==this)throw new Error("This dataProperty has already been added to "+a.parentType.name);return this}return a.parentType=this,a.isDataProperty?this._addDataProperty(a):this._addNavigationProperty(a),this},q.createEntity=function(b){if(b&&b._$eref&&!b._$eref.entityAspect.entityManager)return b._$eref;var c=this._createInstanceCore();return b&&(this.keyProperties.every(function(a){return null!=b[a.name]})&&(b._$eref=c),this._updateTargetFromRaw(c,b,a),this.navigationProperties.forEach(function(a){var d,e=b[a.name];if(void 0!=e){var f=a.entityType;if(a.isScalar)d=e.entityAspect?e:f.createEntity(e),c.setProperty(a.name,d);else{var g=c.getProperty(a.name);e.forEach(function(a){d=a.entityAspect?a:f.createEntity(a),g.push(d)})}}})),this._initializeInstance(c),c},q._createInstanceCore=function(){var a=this.getEntityCtor(),b=new a;return new hb(b),b},q._initializeInstance=function(a){this.baseEntityType&&this.baseEntityType._initializeInstance(a);var b=this.initFn;b&&("string"==typeof b&&(b=a[b]),b(a)),this.complexProperties&&this.complexProperties.forEach(function(b){var c=a.getProperty(b.name);Array.isArray(c)?c.forEach(function(a){b.dataType._initializeInstance(a)}):b.dataType._initializeInstance(c)}),a.entityAspect&&(a.entityAspect._initialized=!0)},q.getCtor=q.getEntityCtor=function(a){if(this._ctor&&!a)return this._ctor;var c=this.metadataStore._ctorRegistry,d=c[this.name]||c[this.shortName]||{},e=d.ctor||this._ctor;if(e&&e.prototype.entityType&&e.prototype.entityType.metadataStore!==this.metadataStore)throw new Error("Cannot register the same constructor for "+this.name+" in different metadata stores. Please define a separate constructor for each metadata store.");if(d.ctor&&a&&(this._extra=void 0),!e){var f=bb.getDefaultInstance().createCtor;e=f?f(this):b()}return this.initFn=d.initFn,this.noTrackingFn=d.noTrackingFn,e.prototype._$typeName=this.name,this._setCtor(e),e},q._setCtor=function(a,b){var c=a.prototype;this._extra=this._extra||{};var d=new a;l(this,d),"EntityType"===this._$typeName?c.entityType=this:c.complexType=this,c._$interceptor=b||M,bb.getDefaultInstance().initializeEntityPrototype(c),this._ctor=a},q.addValidator=function(a,b){X(a,"validator").isInstanceOf(db).check(),X(b,"property").isOptional().isString().or().isEntityProperty().check(),b?("string"==typeof b&&(b=this.getProperty(b,!0)),b.validators.push(a)):this.validators.push(a)},q.getProperties=function(){return this.dataProperties.concat(this.navigationProperties)},q.getPropertyNames=function(){return this.getProperties().map(e("name"))},q.getDataProperty=function(a,b){var c=b?"nameOnServer":"name";return o(this.dataProperties,d(c,a))},q.getNavigationProperty=function(a,b){var c=b?"nameOnServer":"name";return o(this.navigationProperties,d(c,a))},q.getProperty=function(a,b){b=b||!1;var c=Array.isArray(a)?a:a.trim().split("."),e=c[0],f=o(this.getProperties(),d("name",e));if(1===c.length){if(f)return f;if(b)throw new Error("unable to locate property: "+e+" on entityType: "+this.name);return null}if(f){c.shift();var g=f.isNavigationProperty?f.entityType:f.dataType;if(g)return g.getProperty(c,b);throw new Error("should not get here - unknown property type for: "+f.name)}if(b)throw new Error("unable to locate property: "+e+" on type: "+this.name);return null},q.getEntityKeyFromRawEntity=function(a,b){var c=this.keyProperties.map(function(c){var d=b(a,c);return r(d,c.dataType)});return new jb(this,c)},q._updateTargetFromRaw=function(a,b,c){this.dataProperties.forEach(function(d){var e=c(b,d);if(void 0!==e){var f,g=d.dataType;if(d.isComplexProperty){if(null===e)return;f=a.getProperty(d.name),d.isScalar?g._updateTargetFromRaw(f,e,c):(f.length=0,Array.isArray(e)&&e.forEach(function(b){var e=g._createInstanceCore(a,d);g._updateTargetFromRaw(e,b,c),g._initializeInstance(e),f.push(e)}))}else{var h;d.isScalar?(h=r(e,g),a.setProperty(d.name,h)):(f=a.getProperty(d.name),f.length=0,Array.isArray(e)&&e.forEach(function(a){h=r(a,g),f.push(h)}))}}});var d=b.entityAspect||b.complexAspect;d&&d.originalValuesMap&&(targetAspect=a.entityAspect||a.complexAspect,targetAspect.originalValues=d.originalValuesMap)},q.toString=function(){return this.name},q.toJSON=function(){return j(this,{shortName:null,namespace:null,baseTypeName:null,isAbstract:!1,autoGeneratedKeyType:null,defaultResourceName:null,dataProperties:c,navigationProperties:c,validators:null,custom:null})},q._clientPropertyPathToServer=function(a){var b=this.metadataStore.namingConvention.clientPropertyNameToServer,c=this,d=a.split(".").map(function(a){var d=c.getProperty(a);return b(a,d)}).join("/");return d},q._updateNames=function(a){var b=this.metadataStore.namingConvention;f(b,a,"name"),a.isNavigationProperty&&(f(b,a,"foreignKeyNames"),f(b,a,"invForeignKeyNames"))},q._checkNavProperty=function(a){if(a.isNavigationProperty){if(a.parentType!==this)throw new Error(K("The navigationProperty '%1' is not a property of entity type '%2'",a.name,this.name));return a}if("string"==typeof a){var b=this.getProperty(a);if(b&&b.isNavigationProperty)return b}throw new Error("The 'navigationProperty' parameter must either be a NavigationProperty or the name of a NavigationProperty")},q._addDataProperty=function(a){this.dataProperties.push(a),a.isPartOfKey&&this.keyProperties.push(a),a.isComplexProperty&&this.complexProperties.push(a),a.concurrencyMode&&"None"!==a.concurrencyMode&&this.concurrencyProperties.push(a),a.isUnmapped&&this.unmappedProperties.push(a)},q._addNavigationProperty=function(a){this.navigationProperties.push(a),N(a.entityTypeName)||(a.entityTypeName=O(a.entityTypeName,this.namespace))},q._updateCps=function(){var a=this.metadataStore,b=a._incompleteComplexTypeMap;this.complexProperties.forEach(function(c){c.complexType||g(c,a)||t(b,c.complexTypeName).push(c)}),this.isComplexType&&((b[this.name]||[]).forEach(function(b){g(b,a)}),delete b[this.name])},q._updateNps=function(){var a=this.metadataStore,b=a._incompleteTypeMap;this.navigationProperties.forEach(function(c){c.entityType||h(c,a)||t(b,c.entityTypeName).push(c)}),(b[this.name]||[]).forEach(function(b){h(b,a)}),delete b[this.name]},p}(),sb=function(){var a=function(a){if(arguments.length>1)throw new Error("The ComplexType ctor has a single argument that is a configuration object.");Z(a).whereParam("shortName").isNonEmptyString().whereParam("namespace").isString().isOptional().withDefault("").whereParam("dataProperties").isOptional().whereParam("isComplexType").isOptional().isBoolean().whereParam("custom").isOptional().isBoolean().applyAll(this),this.name=O(this.shortName,this.namespace),this.isComplexType=!0,this.dataProperties=[],this.complexProperties=[],this.validators=[],this.concurrencyProperties=[],this.unmappedProperties=[],this.navigationProperties=[],this.keyProperties=[],P(this,a.dataProperties,tb)},b=a.prototype;return b.setProperties=function(a){Z(a).whereParam("custom").isOptional().applyAll(this)},b._createInstanceCore=function(a,b){var c=this.getCtor(),d=new c;return new ib(d,a,b),d},b.addProperty=function(a){if(X(a,"dataProperty").isInstanceOf(tb).check(),this.metadataStore&&!a.isUnmapped)throw new Error("The '"+this.name+"' ComplexType has already been added to a MetadataStore and therefore no additional properties may be added to it.");if(a.parentType){if(a.parentType!==this)throw new Error("This dataProperty has already been added to "+property.parentType.name);return this}return this._addDataProperty(a),this},b.getProperties=function(){return this.dataProperties},b=g(b,rb.prototype,["addValidator","getProperty","getPropertyNames","_addDataProperty","_updateNames","_updateCps","_initializeInstance","_updateTargetFromRaw","_clientPropertyPathToServer","_setCtor"]),b.createInstance=rb.prototype.createEntity,b.getCtor=rb.prototype.getEntityCtor,b.toJSON=function(){return j(this,{shortName:null,namespace:null,isComplexType:null,dataProperties:null,validators:null,custom:null})},b._$typeName="ComplexType",a}(),tb=function(){var a=function(a){Z(a).whereParam("name").isString().isOptional().whereParam("nameOnServer").isString().isOptional().whereParam("dataType").isEnumOf(lb).isOptional().or().isString().or().isInstanceOf(sb).whereParam("complexTypeName").isOptional().whereParam("isNullable").isBoolean().isOptional().withDefault(!0).whereParam("isScalar").isOptional().withDefault(!0).whereParam("defaultValue").isOptional().whereParam("isPartOfKey").isBoolean().isOptional().whereParam("isUnmapped").isBoolean().isOptional().whereParam("concurrencyMode").isString().isOptional().whereParam("maxLength").isNumber().isOptional().whereParam("validators").isInstanceOf(db).isArray().isOptional().withDefault([]).whereParam("enumType").isOptional().whereParam("rawTypeName").isOptional().whereParam("custom").isOptional().applyAll(this);var b=!(!this.name&&!this.nameOnServer);if(!b)throw new Error("A DataProperty must be instantiated with either a 'name' or a 'nameOnServer' property");if(this.complexTypeName)this.isComplexProperty=!0,this.dataType=null;else if("string"==typeof this.dataType){var c=lb.fromName(this.dataType);if(!c)throw new Error("Unable to find a DataType enumeration by the name of: "+this.dataType);this.dataType=c}else this.dataType||(this.dataType=lb.String);if(null==this.defaultValue)if(this.isNullable)this.defaultValue=null;else if(this.isComplexProperty);else if(this.dataType===lb.Binary)this.defaultValue="AAAAAAAAJ3U=";else if(this.defaultValue=this.dataType.defaultValue,null==this.defaultValue)throw new Error("A nonnullable DataProperty cannot have a null defaultValue. Name: "+(this.name||this.nameOnServer));this.isComplexProperty&&(this.isScalar=null==this.isScalar||this.isScalar===!0)},b=a.prototype;return b._$typeName="DataProperty",a.getRawValueFromServer=function(a,b){if(b.isUnmapped)return a[b.nameOnServer||b.name];var c=a[b.nameOnServer];return void 0!==c?c:b.defaultValue},a.getRawValueFromClient=function(a,b){var c=a[b.name];return void 0!==c?c:b.defaultValue},b.isDataProperty=!0,b.isNavigationProperty=!1,b.setProperties=function(a){Z(a).whereParam("custom").isOptional().applyAll(this)},b.toJSON=function(){return j(this,{name:null,dataType:function(a){return a&&a.parentEnum?a.name:void 0},complexTypeName:null,isNullable:!0,defaultValue:null,isPartOfKey:!1,isUnmapped:!1,concurrencyMode:null,maxLength:null,validators:null,enumType:null,rawTypeName:null,isScalar:!0,custom:null})},a.fromJSON=function(a){return a.dataType=lb.fromName(a.dataType),a.defaultValue&&a.dataType&&a.dataType.isDate&&(a.defaultValue=new Date(Date.parse(a.defaultValue))),a.validators&&(a.validators=a.validators.map(db.fromJSON)),new tb(a)},a}(),ub=function(){var a=function(a){Z(a).whereParam("name").isString().isOptional().whereParam("nameOnServer").isString().isOptional().whereParam("entityTypeName").isString().whereParam("isScalar").isBoolean().isOptional().withDefault(!0).whereParam("associationName").isString().isOptional().whereParam("foreignKeyNames").isArray().isString().isOptional().withDefault([]).whereParam("foreignKeyNamesOnServer").isArray().isString().isOptional().withDefault([]).whereParam("invForeignKeyNames").isArray().isString().isOptional().withDefault([]).whereParam("invForeignKeyNamesOnServer").isArray().isString().isOptional().withDefault([]).whereParam("validators").isInstanceOf(db).isArray().isOptional().withDefault([]).whereParam("custom").isOptional().applyAll(this);var b=!(!this.name&&!this.nameOnServer);if(!b)throw new Error("A Navigation property must be instantiated with either a 'name' or a 'nameOnServer' property")},b=a.prototype;return b._$typeName="NavigationProperty",b.isDataProperty=!1,b.isNavigationProperty=!0,b.setProperties=function(a){Z(a).whereParam("custom").isOptional().applyAll(this)},b.toJSON=function(){return j(this,{name:null,entityTypeName:null,isScalar:null,associationName:null,validators:null,foreignKeyNames:null,invForeignKeyNames:null,custom:null})},a.fromJSON=function(a){return a.validators&&(a.validators=a.validators.map(db.fromJSON)),new ub(a)},a}(),vb=function(){var a=new $("AutoGeneratedKeyType");return a.None=a.addSymbol(),a.Identity=a.addSymbol(),a.KeyGenerator=a.addSymbol(),a.seal(),a}();!function(){function a(a,b){return null==b?!1:void 0!==b.entityType}function b(a,b){return null==b?!1:b.isDataProperty||b.isNavigationProperty}var c=W.prototype;c.isEntity=function(){return this._addContext({fn:a,msg:" must be an entity"})},c.isEntityProperty=function(){return this._addContext({fn:b,msg:" must be either a DataProperty or a NavigationProperty"})}}(),S.MetadataStore=pb,S.EntityType=rb,S.ComplexType=sb,S.DataProperty=tb,S.NavigationProperty=ub,S.AutoGeneratedKeyType=vb,pb.normalizeTypeName=qb.normalizeTypeName;var wb=function(){function a(a,b,c){var d=b.name+".."+b.parentType.name,e=a._tempIdMap[d];return e||c&&(e={entityType:b.parentType,propertyName:b.name,keyMap:{}},a._tempIdMap[d]=e),e}var b=function(){this._tempIdMap={}},c=b.prototype;return c.generateTempKeyValue=function(b,c){var d=b.keyProperties;if(d.length>1)throw new Error("Ids can not be autogenerated for entities with multipart keys");var e,f=d[0],g=a(this,f,!0);if(null!=c&&(g.keyMap[c.toString()]||(e=c)),void 0===e){var h=f.dataType;if(!h.getNext)throw new Error("Cannot use a property with a dataType of: "+h.toString()+" for id generation");for(e=h.getNext(this);null!=g.keyMap[e.toString()];)e=h.getNext(this)}return g.keyMap[e.toString()]=!0,e},c.getTempKeys=function(){var a=[];for(var b in this._tempIdMap){var c=this._tempIdMap[b],d=c.entityType;for(var e in c.keyMap)a.push(new jb(d,[e]))}return a},c.isTempKey=function(b){var c=b.entityType.keyProperties;if(c.length>1)return!1;var d=c[0],e=a(this,d);return e?void 0!==e.keyMap[b.values[0].toString()]:!1},ab.registerType(b,"KeyGenerator"),b}();S.KeyGenerator=wb;var xb=function(){var a=function(a){Z(a||{}).whereParam("name").isOptional().isString().whereParam("isCaseSensitive").isOptional().isBoolean().whereParam("usesSql92CompliantStringComparison").isBoolean().applyAll(this),this.name||(this.name=z()),ab._storeObject(this,b._$typeName,this.name)},b=a.prototype;return b._$typeName="LocalQueryComparisonOptions",a.caseInsensitiveSQL=new a({name:"caseInsensitiveSQL",isCaseSensitive:!1,usesSql92CompliantStringComparison:!0}),a.defaultInstance=new a(a.caseInsensitiveSQL),b.setAsDefault=function(){return i(this,a)},a}();S.LocalQueryComparisonOptions=xb;var yb=function(){var a=function(a){Z(a||{}).whereParam("name").isOptional().isString().whereParam("serverPropertyNameToClient").isFunction().whereParam("clientPropertyNameToServer").isFunction().applyAll(this),this.name||(this.name=z()),ab._storeObject(this,b._$typeName,this.name)},b=a.prototype;return b._$typeName="NamingConvention",a.none=new a({name:"noChange",serverPropertyNameToClient:function(a){return a},clientPropertyNameToServer:function(a){return a}}),a.camelCase=new a({name:"camelCase",serverPropertyNameToClient:function(a){return a.substr(0,1).toLowerCase()+a.substr(1)},clientPropertyNameToServer:function(a){return a.substr(0,1).toUpperCase()+a.substr(1)}}),a.defaultInstance=new a(a.none),b.setAsDefault=function(){return i(this,a)},a}();S.NamingConvention=yb;var zb=function(){function b(c,d,e,f){var g=e._$typeName||e.parentEnum&&e.parentEnum.name,h=g&&g.substr(0,1).toLowerCase()+g.substr(1);if(f&&h!=f)throw new Error("Invalid value for property: "+f);if(h){var i=d[h];if(void 0===i)throw new Error("Invalid config property: "+h);null===i?c[h]=e:i(c,e)}else a(e,function(a,e){b(c,d,e,a)})}function c(a,b,c){return b&&a[b]===c?a:(copy=g(new zb,a,["resourceName","entityType","wherePredicate","orderByClause","selectClause","skipCount","takeCount","expandClause","inlineCountEnabled","noTrackingEnabled","queryOptions","entityManager","dataService","resultEntityType"]),copy.parameters=g({},a.parameters),b&&(copy[b]=c),copy)}function d(a){return X(a,"propertyPaths").isOptional().isString().or().isArray().isString().check(),"string"==typeof a&&(a=a.split(",")),a=a.map(function(a){return a.trim()})}function e(a){var b=a.entityType,c=b.keyProperties.map(function(b){return Eb.create(b.name,Cb.Equals,a.getProperty(b.name))}),d=Eb.and(c);return d}function f(a,b,e){var f;return null==b?f=null:(b=d(b),f=Hb.create(b,e),a.orderByClause&&(f=a.orderByClause.addClause(f))),c(a,"orderByClause",f)}function h(a){var b=a.entityType.keyProperties,c=r(b,a.values,function(a,b){return Eb.create(a.name,Cb.Equals,b)}),d=Eb.and(c);return d}function i(a,b){if(b.isScalar){if(0===b.foreignKeyNames.length)return null;var c=b.foreignKeyNames.map(function(b){return a.getProperty(b)}),d=new jb(b.entityType,c);return h(d)}var e=b.inverse,f=e?e.foreignKeyNames:b.invForeignKeyNames;if(0===f.length)return null;var g=a.entityAspect.getKey().values,i=r(f,g,function(a,b){return Eb.create(a,Cb.Equals,b)});return Eb.and(i)}var j=function(a){X(a,"resourceName").isOptional().isString().check(),this.resourceName=a,this.entityType=null,this.wherePredicate=null,this.orderByClause=null,this.selectClause=null,this.skipCount=null,this.takeCount=null,this.expandClause=null,this.parameters={},this.inlineCountEnabled=!1,this.noTrackingEnabled=!1,this.entityManager=null},k=j.prototype;return k._$typeName="EntityQuery",k.from=function(a){return X(a,"resourceName").isString().check(),c(this,"resourceName",a)},j.from=function(a){return X(a,"resourceName").isString().check(),new zb(a)},k.toType=function(a){return X(a,"entityType").isString().or().isInstanceOf(rb).check(),c(this,"resultEntityType",a)},k.where=function(a){var b;if(null==a)b=null;else{b=a instanceof Eb?a:Eb.create(U(arguments)),this.entityType&&b.validate(this.entityType),this.wherePredicate&&(b=new Gb("and",[this.wherePredicate,b]))}return c(this,"wherePredicate",b)},k.orderBy=function(a){return f(this,a)},k.orderByDesc=function(a){return f(this,a,!0)},k.select=function(a){var b=null==a?null:new Kb(d(a));return c(this,"selectClause",b)},k.skip=function(a){return X(a,"count").isOptional().isNumber().check(),c(this,"skipCount",null==a?null:a)},k.top=function(a){return this.take(a)},k.take=function(a){return X(a,"count").isOptional().isNumber().check(),c(this,"takeCount",null==a?null:a)},k.expand=function(a){var b=null==a?null:new Lb(d(a));return c(this,"expandClause",b)},k.withParameters=function(a){return X(a,"parameters").isObject().check(),c(this,"parameters",a)},k.inlineCount=function(a){return X(a,"enabled").isBoolean().isOptional().check(),a=void 0===a?!0:!!a,c(this,"inlineCountEnabled",a)},k.noTracking=function(a){return X(a,"enabled").isBoolean().isOptional().check(),a=void 0===a?!0:!!a,c(this,"noTrackingEnabled",a)},k.using=function(a){if(!a)return this;var d=c(this);return b(d,{entityManager:null,dataService:null,queryOptions:null,fetchStrategy:function(a,b){a.queryOptions=(a.queryOptions||new Ob).using(b)},mergeStrategy:function(a,b){a.queryOptions=(a.queryOptions||new Ob).using(b)},jsonResultsAdapter:function(a,b){a.dataService=(a.dataService||new mb).using({jsonResultsAdapter:b})}},a),d},k.execute=function(a,b){if(!this.entityManager)throw new Error("An EntityQuery must have its EntityManager property set before calling 'execute'");return this.entityManager.executeQuery(this,a,b)},k.executeLocally=function(){if(!this.entityManager)throw new Error("An EntityQuery must have its EntityManager property set before calling 'executeLocally'");return this.entityManager.executeQueryLocally(this)},j.fromEntities=function(a){X(a,"entities").isEntity().or().isNonEmptyArray().isEntity().check(),Array.isArray(a)||(a=U(arguments));var b=a[0],c=new zb(b.entityType.defaultResourceName),d=a.map(function(a){return e(a)}),f=Eb.or(d);c=c.where(f);var g=b.entityAspect.entityManager;return g&&(c=c.using(g)),c},j.fromEntityKey=function(a){X(a,"entityKey").isInstanceOf(jb).check();var b=new zb(a.entityType.defaultResourceName),c=h(a);return b=b.where(c).toType(a.entityType)},j.fromEntityNavigation=function(a,b){X(a,"entity").isEntity().check();var c=a.entityType._checkNavProperty(b),d=new zb(c.entityType.defaultResourceName),e=i(a,c);d=d.where(e);var f=a.entityAspect.entityManager;return f&&(d=d.using(f)),d},k._getFromEntityType=function(a,b){var c=this.entityType;if(c)return c;var d=this.resourceName;if(!d)throw new Error("There is no resourceName for this query");if(a.isEmpty()){if(b)throw new Error("There is no metadata available for this query. Are you querying the local cache before you've fetched metadata?");return null}var e=a.getEntityTypeNameForResourceName(d);if(c=e?a._getEntityType(e):this._getToEntityType(a,!0),!c){if(b)throw new Error(K("Cannot find an entityType for resourceName: '%1'. Consider adding an 'EntityQuery.toType' call to your query or calling the MetadataStore.setEntityTypeForResourceName method to register an entityType for this resourceName.",d));return null}return this.entityType=c,c},k._getToEntityType=function(a,b){return this.resultEntityType instanceof rb?this.resultEntityType:this.resultEntityType?(this.resultEntityType=a._getEntityType(this.resultEntityType,!1),this.resultEntityType):b?null:!this.selectClause&&this._getFromEntityType(a,!1)},k._toUri=function(a){function b(){var a=k.wherePredicate;if(a)return k.entityType&&a.validate(k.entityType),Eb._next=0,a.toODataFragment(j)}function c(){return k.inlineCountEnabled?k.inlineCountEnabled?"allpages":"none":void 0}function d(){var a=k.orderByClause;if(a)return k.entityType&&a.validate(k.entityType),a.toODataFragment(j)}function e(){var a=k.selectClause;if(a)return k.entityType&&a.validate(k.entityType),a.toODataFragment(j)}function f(){var a=k.expandClause;if(a)return a.toODataFragment(j)}function g(){var a=k.skipCount;if(a)return a.toString()}function h(){var a=k.takeCount;if(null!=a)return a.toString()}function i(a){var b=[];for(var c in a){var d=a[c];void 0!==d&&(d instanceof Array?d.forEach(function(a){b.push(c+"="+encodeURIComponent(a))}):b.push(c+"="+encodeURIComponent(d)))}return b.length>0?"?"+b.join("&"):""}var j=this._getFromEntityType(a,!1);j||(j=new rb(a));var k=this,l={};l.$filter=b(),l.$orderby=d(),l.$skip=g(),l.$top=h(),l.$expand=f(),l.$select=e(),l.$inlinecount=c();var m=i(l);return this.resourceName+m},k._toFilterFunction=function(a){var b=this.wherePredicate;return b?(b.validate(a),b.toFunction(a)):null},k._toOrderByComparer=function(a){var b=this.orderByClause;return b?b.getComparer(a):null},j}(),Ab=function(){var a={toupper:{fn:function(a){return a.toUpperCase()},dataType:lb.String},tolower:{fn:function(a){return a.toLowerCase()},dataType:lb.String},substring:{fn:function(a,b,c){return a.substring(b,c)},dataType:lb.String},substringof:{fn:function(a,b){return b.indexOf(a)>=0},dataType:lb.Boolean},length:{fn:function(a){return a.length},dataType:lb.Int32},trim:{fn:function(a){return a.trim()},dataType:lb.String},concat:{fn:function(a,b){return a.concat(b)},dataType:lb.String},replace:{fn:function(a,b,c){return a.replace(b,c)},dataType:lb.String},startswith:{fn:function(a,b){return I(a,b)},dataType:lb.Boolean},endswith:{fn:function(a,b){return J(a,b)},dataType:lb.Boolean},indexof:{fn:function(a,b){return a.indexOf(b)},dataType:lb.Int32},round:{fn:function(a){return Math.round(a)},dataType:lb.Int32},ceiling:{fn:function(a){return Math.ceil(a)},dataType:lb.Int32},floor:{fn:function(a){return Math.floor(a)},dataType:lb.Int32},second:{fn:function(a){return a.getSeconds()},dataType:lb.Int32},minute:{fn:function(a){return a.getMinutes()},dataType:lb.Int32},day:{fn:function(a){return a.getDate()},dataType:lb.Int32},month:{fn:function(a){return a.getMonth()+1},dataType:lb.Int32},year:{fn:function(a){return a.getFullYear()},dataType:lb.Int32}};return a}(),Bb=function(){function a(a){var b=a.split(".");return 1===b.length?function(b){return b.getProperty(a)}:function(a){return Q(a,b)}}var b=/^[a-z_][\w.$]*$/i,c=/('[^']*'|[^,]+)/g,d=/("[^"]*"|[^,]+)/g,e=function(e,f,g){var h=e.split(":");if(this.isRealNode=!0,1===h.length){var i=h[0].trim();this.value=i;var j=i.substr(0,1),k=("'"===j||'"'===j)&&i.length>1&&i.substr(i.length-1)===j;if(k){var l=i.substr(1,i.length-2);this.fn=function(){return l},this.dataType=lb.String}else{var m=b.test(i);if(m){if(g&&null==g.getProperty(i,!1))return this.isRealNode=!1,void 0;this.propertyPath=i,this.fn=a(i)}else{if(g)return this.isRealNode=!1,void 0;this.fn=function(){return i
},this.dataType=lb.fromValue(i)}}}else try{this.fnName=h[0].trim().toLowerCase();var n=Ab[this.fnName];this.localFn=n.fn,this.dataType=n.dataType;var o=this;this.fn=function(a){var b=o.fnNodes.map(function(b){var c=b.fn(a);return c}),c=o.localFn.apply(null,b);return c};var p=f[h[1]].trim();"("===p.substr(0,1)&&(p=p.substr(1,p.length-2));var q=e.indexOf("'")>=0?c:d,r=p.match(q);this.fnNodes=r.map(function(a){return new Bb(a,f)})}catch(s){this.isRealNode=!1}},f=e.prototype;return e.create=function(a,b,c){if("string"!=typeof a)return null;for(var d,e=/\([^()]*\)/,f=[],g=0;d=e.exec(a);){var h=d[0];f.push(h);var i=":"+g++;a=a.replace(h,i)}var j=new Bb(a,f,c?null:b);return j.isRealNode?(!j.dataType&&c&&c.isStringFn&&(j.dataType=lb.String),j._validate(b),j):null},f.toString=function(){if(this.fnName){var a=this.fnNodes.map(function(a){return a.toString()}),b=this.fnName+"("+a.join(",")+")";return b}return this.value},f.toODataFragment=function(a){if(this._validate(a),this.fnName){var b=this.fnNodes.map(function(b){return b.toODataFragment(a)}),c=this.fnName+"("+b.join(",")+")";return c}var d=this.value.substr(0,1);return"'"===d||'"'===d?this.value:this.value==this.propertyPath?a._clientPropertyPathToServer(this.propertyPath):this.value},f._validate=function(a){if(!this.isValidated)if(this.isValidated=!0,this.propertyPath){if(a.isAnonymous)return;var b=a.getProperty(this.propertyPath,!0);if(!b){var c=K("Unable to resolve propertyPath. EntityType: '%1' PropertyPath: '%2'",a.name,this.propertyPath);throw new Error(c)}this.dataType=b.isDataProperty?b.dataType:b.entityType}else this.fnNodes&&this.fnNodes.forEach(function(b){b._validate(a)})},e}(),Cb=function(){var a=new $("FilterQueryOp");return a.Equals=a.addSymbol({operator:"eq",aliases:["=="]}),a.NotEquals=a.addSymbol({operator:"ne",aliases:["!="]}),a.GreaterThan=a.addSymbol({operator:"gt",aliases:[">"]}),a.LessThan=a.addSymbol({operator:"lt",aliases:["<"]}),a.GreaterThanOrEqual=a.addSymbol({operator:"ge",aliases:[">="]}),a.LessThanOrEqual=a.addSymbol({operator:"le",aliases:["<="]}),a.Contains=a.addSymbol({operator:"substringof",aliases:["contains"],isFunction:!0,isStringFn:!0}),a.StartsWith=a.addSymbol({operator:"startswith",isFunction:!0,isStringFn:!0}),a.EndsWith=a.addSymbol({operator:"endswith",isFunction:!0,isStringFn:!0}),a.Any=a.addSymbol({operator:"any",isAnyAll:!0,aliases:["some"]}),a.All=a.addSymbol({operator:"all",isAnyAll:!0,aliases:["every"]}),a.IsTypeOf=a.addSymbol({operator:"isof",isFunction:!0,aliases:["isTypeOf"]}),a.seal(),a._map=function(){var b={};return a.getSymbols().forEach(function(a){b[a.name.toLowerCase()]=a,b[a.operator.toLowerCase()]=a,a.aliases&&a.aliases.forEach(function(c){b[c.toLowerCase()]=a})}),b}(),a.from=function(b){return a.contains(b)?b:a._map[b.toLowerCase()]},a}(),Db=function(){var a=new $("BooleanQueryOp");return a.And=a.addSymbol({operator:"and",aliases:["&&"]}),a.Or=a.addSymbol({operator:"or",aliases:["||"]}),a.Not=a.addSymbol({operator:"not",aliases:["~","!"]}),a.seal(),a._map=function(){var b={};return a.getSymbols().forEach(function(a){b[a.name.toLowerCase()]=a,b[a.operator.toLowerCase()]=a,a.aliases&&a.aliases.forEach(function(c){b[c.toLowerCase()]=a})}),b}(),a.from=function(b){return a.contains(b)?b:a._map[b.toLowerCase()]},a}(),Eb=function(){function a(a){var b;if(1===a.length&&Array.isArray(a[0]))b=a[0];else{var b=U(a);b[0]instanceof Eb||(b=[Eb.create(b)])}return b.filter(function(a){return null!=a})}var b=function(){return arguments[0].prototype===!0?this:new Fb(U(arguments))},c=b.prototype;return b.create=function(a){var b=Array.isArray(a)&&1===arguments.length?a:U(arguments);return new Fb(b)},b.and=function(b){return b=a(arguments),0===b.length?null:1===b.length?b[0]:new Gb("and",b)},b.or=function(b){return b=a(arguments),0===b.length?null:1===b.length?b[0]:new Gb("or",b)},b.not=function(a){return new Gb("not",[a])},c.and=function(c){return c=a(arguments),c.unshift(this),b.and(c)},c.or=function(c){return c=a(arguments),c.unshift(this),b.or(c)},c.not=function(){return new Gb("not",[this])},b}(),Fb=function(){function a(a,f,g){var h,i=a.metadataStore.localQueryComparisonOptions,j=R(g);switch(f){case Cb.Equals:h=function(a,c){return a&&"string"==typeof a?b(a,c,i):j(a)==j(c)};break;case Cb.NotEquals:h=function(a,c){return a&&"string"==typeof a?!b(a,c,i):j(a)!=j(c)};break;case Cb.GreaterThan:h=function(a,b){return j(a)>j(b)};break;case Cb.GreaterThanOrEqual:h=function(a,b){return j(a)>=j(b)};break;case Cb.LessThan:h=function(a,b){return j(a)<j(b)};break;case Cb.LessThanOrEqual:h=function(a,b){return j(a)<=j(b)};break;case Cb.StartsWith:h=function(a,b){return c(a,b,i)};break;case Cb.EndsWith:h=function(a,b){return d(a,b,i)};break;case Cb.Contains:h=function(a,b){return e(a,b,i)};break;case Cb.Any:h=function(a,b){return a.some(function(a){return b(a)})};break;case Cb.All:h=function(a,b){return a.every(function(a){return b(a)})};break;default:throw new Error("Unknown FilterQueryOp: "+f)}return h}function b(a,b,c){return null==b?!1:("string"!=typeof b&&(b=b.toString()),c.usesSql92CompliantStringComparison&&(a=(a||"").trim(),b=(b||"").trim()),c.isCaseSensitive||(a=(a||"").toLowerCase(),b=(b||"").toLowerCase()),a===b)}function c(a,b,c){return c.isCaseSensitive||(a=(a||"").toLowerCase(),b=(b||"").toLowerCase()),I(a,b)}function d(a,b,c){return c.isCaseSensitive||(a=(a||"").toLowerCase(),b=(b||"").toLowerCase()),J(a,b)}function e(a,b,c){return c.isCaseSensitive||(a=(a||"").toLowerCase(),b=(b||"").toLowerCase()),a.indexOf(b)>=0}var f=function(a){if(1===a.length)return this._odataExpr=a[0],void 0;var b=a[0];X(b,"propertyOrExpr").isString().isOptional().check();var c=a[1];X(c,"operator").isEnumOf(Cb).or().isString().check();var d=Cb.from(c);if(!d)throw new Error("Unknown query operation: "+c);if(this._filterQueryOp=d,b)this._propertyOrExpr=b;else if(d!==Cb.IsTypeOf)throw new Error("propertyOrExpr cannot be null except when using the 'IsTypeOf' operator");var e=a[2];return d&&d.isAnyAll?(this._value=e instanceof Eb?e:new Fb(a.slice(2)),this._isLiteral=void 0,void 0):(X(e,"value").isRequired(!0).check(),null!=e&&"object"==typeof e&&void 0!==e.value?(this._dataType=e.dataType||lb.fromValue(e.value),this._value=e.value,this._isLiteral=e.isLiteral):(this._dataType=lb.fromValue(e),this._value=e,this._isLiteral=void 0),void 0)},g=new Eb({prototype:!0});return f.prototype=g,g.toODataFragment=function(a,b){if(this._odataExpr)return this._odataExpr;var c=this._filterQueryOp,d=this._value;if(c==Cb.IsTypeOf){var e=a.metadataStore.getEntityType(d),f=e.namespace+"."+e.shortName;return c.operator+"("+lb.String.fmtOData(f)+")"}this.validate(a);var g=this._fnNode1&&this._fnNode1.toODataFragment(a);if(b&&(g=b+"/"+g),Eb._next+=1,b="x"+Eb._next,c.isAnyAll)return g+"/"+c.operator+"("+b+": "+d.toODataFragment(this.dataType,b)+")";var h;if(this._fnNode2)h=this._fnNode2.toODataFragment(a);else{var i=this._fnNode1.dataType||this._dataType;h=i.fmtOData(d)}return c.isFunction?c==Cb.Contains?c.operator+"("+h+","+g+") eq true":c.operator+"("+g+","+h+") eq true":g+" "+c.operator+" "+h},g.toFunction=function(b){if(this._odataExpr)throw new Exception("OData predicateexpressions cannot be interpreted locally");this.validate(b);var c=this._fnNode1.dataType||this._dataType,d=a(b,this._filterQueryOp,c),e=this._fnNode1.fn;if(this._fnNode2){var f=this._fnNode2.fn;return function(a){return d(e(a),f(a))}}if(this._filterQueryOp&&this._filterQueryOp.isAnyAll){var g=this._value.toFunction(c);return function(a){return d(e(a),g)}}var h=this._value;return function(a){return d(e(a),h)}},g.toString=function(){return K("{%1} %2 {%3}",this._propertyOrExpr,this._filterQueryOp.operator,this._value)},g.validate=function(a){var b=this._filterQueryOp;return void 0===this._fnNode1&&this._propertyOrExpr&&(this._fnNode1=Bb.create(this._propertyOrExpr,a,b),this.dataType=this._fnNode1.dataType),b&&b.isAnyAll?(this._value.validate(this.dataType),void 0):(void 0!==this._fnNode2||this._isLiteral||(this._fnNode2=Bb.create(this._value,a)),void 0)},f}(),Gb=function(){function a(a,b,c){var d,e;switch(b){case Db.Not:return d=c[0].toFunction(a),function(a){return!d(a)};case Db.And:return e=c.map(function(b){return b.toFunction(a)}),function(a){var b=e.reduce(function(b,c){return b&&c(a)},!0);return b};case Db.Or:return e=c.map(function(b){return b.toFunction(a)}),function(a){var b=e.reduce(function(b,c){return b||c(a)},!1);return b};default:throw new Error("Invalid boolean operator:"+b)}}var b=function(a,b){if(!Array.isArray(b))throw new Error("predicates parameter must be an array");if(this._booleanQueryOp=Db.from(a),!this._booleanQueryOp)throw new Error("Unknown query operation: "+a);if(this._booleanQueryOp===Db.Not&&1!==b.length)throw new Error("Only a single predicate can be passed in with the 'Not' operator");this._predicates=b},c=new Eb({prototype:!0});return b.prototype=c,c.toODataFragment=function(a,b){if(1==this._predicates.length)return this._booleanQueryOp.operator+" ("+this._predicates[0].toODataFragment(a,b)+")";var c=this._predicates.map(function(c){return"("+c.toODataFragment(a,b)+")"}).join(" "+this._booleanQueryOp.operator+" ");return c},c.toFunction=function(b){return a(b,this._booleanQueryOp,this._predicates)},c.toString=function(){if(1==this._predicates.length)return this._booleanQueryOp.operator+" ("+this._predicates[0]+")";var a=this._predicates.map(function(a){return"("+a.toString()+")"}).join(" "+this._booleanQueryOp.operator+" ");return a},c.validate=function(a){this._isValidated||(this._predicates.every(function(b){b.validate(a)}),this._isValidated=!0)},b}(),Hb=function(){var a=function(b,c){return b.prototype===!0?this:a.create(b,c)},b=a.prototype;return a.create=function(a,b){if(a.length>1){var c=a.map(function(a){return new Ib(a,b)});return new Jb(c)}return new Ib(a[0],b)},a.combine=function(a){return new Jb(a)},a.isOrderByClause=function(a){return a instanceof Hb},b.addClause=function(a){return new Jb([this,a])},a}(),Ib=function(){var a=function(a,b){if("string"!=typeof a)throw new Error("propertyPath is not a string");a=a.trim();var c=a.split(" ");if(c.length>1&&b!==!0&&b!==!1&&(b=I(c[1].toLowerCase(),"desc"),!b)){var d=I(c[1].toLowerCase(),"asc");if(!d)throw new Error("the second word in the propertyPath must begin with 'desc' or 'asc'")}this.propertyPath=c[0],this.isDesc=b},b=new Hb({prototype:!0});return a.prototype=b,b.validate=function(a){a&&(this.lastProperty=a.getProperty(this.propertyPath,!0))},b.toODataFragment=function(a){return a._clientPropertyPathToServer(this.propertyPath)+(this.isDesc?" desc":"")},b.getComparer=function(a){if(this.lastProperty||this.validate(a),this.lastProperty)var b=this.lastProperty.dataType,c=this.lastProperty.parentType.metadataStore.localQueryComparisonOptions.isCaseSensitive;var d=this.propertyPath,e=this.isDesc;return function(a,f){var g=Q(a,d),h=Q(f,d),i=b||g&&lb.fromValue(g)||lb.fromValue(h);if(i===lb.String)c?(g=g||"",h=h||""):(g=(g||"").toLowerCase(),h=(h||"").toLowerCase());else{var j=R(i);g=j(g),h=j(h)}return g===h?0:g>h||void 0===h?e?-1:1:e?1:-1}},a}(),Jb=function(){var a=function(a){var b=[];a.forEach(function(a){if(a instanceof Jb)b=b.concat(a.orderByClauses);else{if(!(a instanceof Ib))throw new Error("Invalid argument to CompositeOrderByClause ctor.");b.push(a)}}),this._orderByClauses=b},b=new Hb({prototype:!0});return a.prototype=b,b.validate=function(a){this._orderByClauses.forEach(function(b){b.validate(a)})},b.toODataFragment=function(a){var b=this._orderByClauses.map(function(b){return b.toODataFragment(a)});return b.join(",")},b.getComparer=function(a){var b=this._orderByClauses.map(function(b){return b.getComparer(a)});return function(a,c){for(var d=0;d<b.length;d++){var e=b[d](a,c);if(0!==e)return e}return 0}},a}(),Kb=function(){var a=function(a){this.propertyPaths=a,this._pathNames=a.map(function(a){return a.replace(".","_")})},b=a.prototype;return b.validate=function(a){a&&this.propertyPaths.forEach(function(b){a.getProperty(b,!0)})},b.toODataFragment=function(a){var b=this.propertyPaths.map(function(b){return a._clientPropertyPathToServer(b)}).join(",");return b},b.toFunction=function(){var a=this;return function(b){var c={};return a.propertyPaths.forEach(function(d,e){c[a._pathNames[e]]=Q(b,d)}),c}},a}(),Lb=function(){var a=function(a){this.propertyPaths=a},b=a.prototype;return b.toODataFragment=function(a){var b=this.propertyPaths.map(function(b){return a._clientPropertyPathToServer(b)}).join(",");return b},a}();S.FilterQueryOp=Cb,S.Predicate=Eb,S.EntityQuery=zb,S.FnNode=Bb,S.OrderByClause=Hb;var Mb=function(){var a=new $("MergeStrategy");return a.PreserveChanges=a.addSymbol(),a.OverwriteChanges=a.addSymbol(),a.SkipMerge=a.addSymbol(),a.Disallowed=a.addSymbol(),a.seal(),a}(),Nb=function(){var a=new $("FetchStrategy");return a.FromServer=a.addSymbol(),a.FromLocalCache=a.addSymbol(),a.seal(),a}(),Ob=function(){function a(a,b){return b&&Z(b).whereParam("fetchStrategy").isEnumOf(Nb).isOptional().whereParam("mergeStrategy").isEnumOf(Mb).isOptional().applyAll(a),a}var b=function(b){a(this,b)},c=b.prototype;return c._$typeName="QueryOptions",b.resolve=function(a){return new Ob(l(a,["fetchStrategy","mergeStrategy"]))},b.defaultInstance=new b({fetchStrategy:Nb.FromServer,mergeStrategy:Mb.PreserveChanges}),c.using=function(b){if(!b)return this;var c=new Ob(this);return Mb.contains(b)?b={mergeStrategy:b}:Nb.contains(b)&&(b={fetchStrategy:b}),a(c,b)},c.setAsDefault=function(){return i(this,b)},c.toJSON=function(){return j(this,{fetchStrategy:null,mergeStrategy:null})},b.fromJSON=function(a){return new Ob({fetchStrategy:Nb.fromName(a.fetchStrategy),mergeStrategy:Mb.fromName(a.mergeStrategy)})},b}();S.QueryOptions=Ob,S.FetchStrategy=Nb,S.MergeStrategy=Mb;var Pb=function(){function a(a){if(a){if(1===a.length){var b=a[0];return function(a){return a?a.entityAspect.entityState===b:!1}}return function(b){return b?a.some(function(a){return b.entityAspect.entityState===a}):!1}}return function(a){return!!a}}var b=a([kb.Added,kb.Modified,kb.Deleted]),c=function(a,b){this.entityManager=a,this.entityType=b,this._indexMap={},this._entities=[],this._emptyIndexes=[]},d=c.prototype;return d.attachEntity=function(a,b,c){var d=a.entityAspect;d._initialized||this.entityType._initializeInstance(a),delete d._initialized;var e=d.getKey()._keyInGroup,f=this._indexMap[e];if(f>=0){var g=this._entities[f],h=g.entityAspect.entityState.isUnchanged();if(g===a)d.entityState=b;else{if(c===Mb.Disallowed)throw new Error("A MergeStrategy of 'Disallowed' does not allow you to attach an entity when an entity with the same key is already attached: "+d.getKey());(c===Mb.OverwriteChanges||c===Mb.PreserveChanges&&h)&&(this.entityType._updateTargetFromRaw(g,a,tb.getRawValueFromClient),this.entityManager._checkStateChange(g,h,b.isUnchanged()))}return g}return 0===this._emptyIndexes.length?f=this._entities.push(a)-1:(f=this._emptyIndexes.pop(),this._entities[f]=a),this._indexMap[e]=f,d.entityState=b,d.entityGroup=this,d.entityManager=this.entityManager,a},d.detachEntity=function(a){var b=a.entityAspect,c=b.getKey()._keyInGroup,d=this._indexMap[c];if(void 0===d)throw new Error("internal error - entity cannot be found in group");return delete this._indexMap[c],this._emptyIndexes.push(d),this._entities[d]=null,a},d.findEntityByKey=function(a){var b;b=a instanceof jb?a._keyInGroup:jb.createKeyString(a);var c=this._indexMap[b];return void 0!==c?this._entities[c]:null},d.hasChanges=function(){return this._entities.some(b)},d.getEntities=function(b){var c=a(b);return this._entities.filter(c)},d._clear=function(){this._entities.forEach(function(a){null!=a&&a.entityAspect._detach()}),this._entities=null,this._indexMap=null,this._emptyIndexes=null},d._updateFkVal=function(a,b,c){var d=a.name;this._entities.forEach(function(a){null!=a&&a.getProperty(d)==b&&a.setProperty(d,c)})},d._fixupKey=function(a,b){var c=this._indexMap[a];if(void 0===c)throw new Error("Internal Error in key fixup - unable to locate entity");var d=this._entities[c],e=d.entityType.keyProperties[0].name;d.setProperty(e,b),delete d.entityAspect.hasTempKey,delete this._indexMap[a],this._indexMap[b]=c},d._replaceKey=function(a,b){var c=this._indexMap[a._keyInGroup];delete this._indexMap[a._keyInGroup],this._indexMap[b._keyInGroup]=c},c}(),Qb=function(){function b(a,b,c){var d=c?Ob.defaultInstance:a.queryOptions,e=c?Sb.defaultInstance:a.saveOptions,f=c?fb.defaultInstance:a.validationOptions,g=Z(b).whereParam("serviceName").isOptional().isString().whereParam("dataService").isOptional().isInstanceOf(mb).whereParam("queryOptions").isInstanceOf(Ob).isOptional().withDefault(d).whereParam("saveOptions").isInstanceOf(Sb).isOptional().withDefault(e).whereParam("validationOptions").isInstanceOf(fb).isOptional().withDefault(f).whereParam("keyGeneratorCtor").isFunction().isOptional();c&&(g=g.whereParam("metadataStore").isInstanceOf(pb).isOptional().withDefault(new pb)),g.applyAll(a),h(a.queryOptions,d),h(a.saveOptions,e),h(a.validationOptions,f),b.serviceName&&(a.dataService=new mb({serviceName:a.serviceName})),a.serviceName=a.dataService&&a.dataService.serviceName,a.keyGeneratorCtor=a.keyGeneratorCtor||wb,(c||b.keyGeneratorCtor)&&(a.keyGenerator=new a.keyGeneratorCtor)}function c(b){b.forEach(function(b){var c=[],d=b.entityAspect._validationErrors;a(d,function(a,b){b.isServerError&&c.push(a)}),0!==c.length&&(c.forEach(function(a){delete d[a]}),b.hasValidationErrors=!G(d))})}function d(b){var c=[];return b.forEach(function(b){a(b.entityAspect._validationErrors,function(a,d){var e=g({entity:b,errorName:d.validator.name},d,["errorMessage","propertyName","isServerError"]);c.push(e)})}),c}function e(a,b){var c=b.entityErrors;if(c){var d=a.entityManager,e=d.metadataStore;b.entityErrors=c.map(function(a){var b=null;if(a.keyValues){var c=e._getEntityType(a.entityTypeName),f=new jb(c,a.keyValues);b=d.findEntityByKey(f)}if(b){var h=a.propertyName?{propertyName:a.propertyName,property:c.getProperty(a.propertyName)}:{},i=eb.getKey(a.errorName||a.errorMessage,a.propertyName),j=new eb(null,h,a.errorMessage,i);j.isServerError=!0,b.entityAspect.addValidationError(j)}var k=g({entity:b,isServerError:!0},a,["errorName","errorMessage","propertyName"]);return k})}}function i(a,b){if(a.length!==b.length)return!1;for(var c=0,d=a.length;d>c;c++)if(a[c]!==b[c])return!1;return!0}function j(a,b){var c,d=s(a,b),e=d.entityKey,f=0===d.remainingArgs.length?!1:!!d.remainingArgs[0],g=!1;return f&&(c=a.getEntityByKey(e),g=c&&c.entityAspect.entityState.isDeleted(),g&&(c=null,a.queryOptions.mergeStrategy===Mb.OverwriteChanges&&(g=!1))),c||g?ob.resolve({entity:c,entityKey:e,fromCache:!0}):zb.fromEntityKey(e).using(a).execute().then(function(a){return c=0===a.results.length?null:a.results[0],ob.resolve({entity:c,entityKey:e,fromCache:!1})})}function l(a,b){return X(b,"entityTypes").isString().isOptional().or().isNonEmptyArray().isString().or().isInstanceOf(rb).or().isNonEmptyArray().isInstanceOf(rb).check(),"string"==typeof b?b=a.metadataStore._getEntityType(b,!1):Array.isArray(b)&&"string"==typeof b[0]&&(b=b.map(function(b){return a.metadataStore._getEntityType(b,!1)})),b}function p(a,b,c){var d,e=H(a,b);return e.forEach(function(a){if(a){var b=a.getEntities(c);d?d.push.apply(d,b):d=b}}),d||[]}function s(a,b){try{if(b[0]instanceof jb)return{entityKey:b[0],remainingArgs:U(b,1)};if(b.length>=2){var c="string"==typeof b[0]?a.metadataStore._getEntityType(b[0],!1):b[0];return{entityKey:new jb(c,b[1]),remainingArgs:U(b,2)}}}catch(d){}throw new Error("Must supply an EntityKey OR an EntityType name or EntityType followed by a key value or an array of key values.")}function u(a,b){a.forEach(function(a){a.entityAspect.isBeingSaved=b})}function v(b,c){var d;c?(d={},c.forEach(function(a){var b=d[a.entityType.name];b||(b={},b.entityType=a.entityType,b._entities=[],d[a.entityType.name]=b),b._entities.push(a)})):d=b._entityGroupMap;var e=[],f={};return a(d,function(a,b){f[a]=y(b,e)}),{entityGroupMap:f,tempKeys:e}}function y(a,b){var c={},d=a.entityType,e=d.dataProperties,f=V(d),g=[];return a._entities.forEach(function(a){if(a){var c=A(a,e,f,b);g.push(c)}}),c.entities=g,c}function A(a,b,c,d){var e={};b.forEach(function(b){var d=b.name,f=a.getProperty(d);if(null!=f||null!=b.defaultValue){if(f&&b.isComplexProperty){var g=b.dataType.dataProperties;f=n(f,function(a){return A(a,g,c)})}else f=c?c(b,f):f,b.isUnmapped&&(f=k(f));void 0!==f&&(e[d]=f)}});var f,g;if(a.entityAspect){f=a.entityAspect;var h=f.entityState;g={tempNavPropNames:B(f,d),entityState:h.name},(h.isModified()||h.isDeleted())&&(g.originalValuesMap=f.originalValues),e.entityAspect=g}else f=a.complexAspect,g={},f.originalValues&&!G(f.originalValues)&&(g.originalValuesMap=f.originalValues),e.complexAspect=g;return e}function B(a,b){var c=a.entity;a.hasTempKey&&b.push(a.getKey().toJSON());var d;return c.entityType.navigationProperties.forEach(function(a){if(a.relatedDataProperties){var b=c.getProperty(a.name);b&&b.entityAspect.hasTempKey&&(d=d||[],d.push(a.name))}}),d}function C(a,b,c){var d=c.tempKeyMap,e=a.entityType,f=c.mergeStrategy,g=null,h=a.entityManager,i=h.entityChanged,j=[],k=tb.getRawValueFromClient;return b.entities.forEach(function(b){var c,l=b.entityAspect,m=e.getEntityKeyFromRawEntity(b,k),n=kb.fromName(l.entityState);if(n.isAdded()?(c=d[m.toString()],g=void 0===c?a.findEntityByKey(m):null):g=a.findEntityByKey(m),g)if(f===Mb.SkipMerge);else{if(f===Mb.Disallowed)throw new Error("A MergeStrategy of 'Disallowed' prevents "+m.toString()+" from being merged");var o=g.entityAspect.entityState.isUnchanged();(f===Mb.OverwriteChanges||o)&&(e._updateTargetFromRaw(g,b,k),g.entityAspect.entityState=n,i.publish({entityAction:gb.MergeOnImport,entity:g}),h._checkStateChange(g,o,n.isUnchanged()))}else g=e._createInstanceCore(),e._updateTargetFromRaw(g,b,k),void 0!==c&&(g.setProperty(e.keyProperties[0].name,c.values[0]),l.tempNavPropNames&&l.tempNavPropNames.forEach(function(a){var b=e.getNavigationProperty(a),c=b.relatedDataProperties[0].name,f=g.getProperty(c),h=new jb(b.entityType,[f]),i=d[h.toString()];g.setProperty(c,i.values[0])})),g=a.attachEntity(g,n),i.publish({entityAction:gb.AttachOnImport,entity:g}),n.isUnchanged()||h._notifyStateChange(g,!0);j.push(g)}),j}function D(a,b,c){return a=a.then(function(a){return b&&b(a),ob.resolve(a)},function(a){return c&&c(a),ob.reject(a)})}function E(a,b){var c;return c=b?b.filter(function(b){if(b.entityAspect.entityManager!==a)throw new Error("Only entities in this entityManager may be saved");return!b.entityAspect.entityState.isDetached()}):a.getChanges()}function F(a,b){a._inKeyFixup=!0,b.forEach(function(b){var c=a._entityGroupMap[b.entityTypeName];if(!c)throw new Error("Unable to locate the following fully qualified EntityType name: "+b.entityTypeName);c._fixupKey(b.tempValue,b.realValue)}),a._inKeyFixup=!1}function H(a,b){var c=a._entityGroupMap;return b?m(b).map(function(a){if(a instanceof rb)return c[a.name];throw new Error("The EntityManager.getChanges() 'entityTypes' parameter must be either an entityType or an array of entityTypes or null")}):f(c)}function I(a,b){var c=b.entityAspect.getKey(),d=r(b.entityType.keyProperties,c.values,function(a,b){return a.defaultValue===b?a:null}).filter(function(a){return null!==a});if(d.length)if(b.entityType.autoGeneratedKeyType!==vb.None)a.generateTempKeyValue(b);else if(d.length===c.values.length)throw new Error("Cannot attach an object of type ("+b.entityType.name+") to an EntityManager without first setting its key or setting its entityType 'AutoGeneratedKeyType' property to something other than 'None'")}function J(a,b){return b?(b=m(b),b.forEach(function(a){if(!kb.contains(a))throw new Error("The EntityManager.getChanges() 'entityStates' parameter must either be null, an entityState or an array of entityStates")}),b):null}function K(a,b,c,d){var e=b.entityType.navigationProperties;e.forEach(function(e){var f=b.getProperty(e.name);if(e.isScalar){if(!f)return;a.attachEntity(f,c,d)}else f.forEach(function(b){a.attachEntity(b,c,d)})})}function L(a,b,c,d){try{var e=a.metadataStore;if(e.isEmpty()&&d.hasServerMetadata)throw new Error("cannot execute _executeQueryCore until metadataStore is populated.");if(c.fetchStrategy===Nb.FromLocalCache)try{var f=a.executeQueryLocally(b);return ob.resolve({results:f,query:b})}catch(g){return ob.reject(g)}var h=new Rb({query:b,entityManager:a,dataService:d,mergeOptions:{mergeStrategy:c.mergeStrategy,noTracking:!!b.noTrackingEnabled}}),i=a.validationOptions.validateOnQuery;return d.adapterInstance.executeQuery(h).then(function(c){var e=x(function(){var b={isLoading:a.isLoading};return a.isLoading=!0,a._pendingPubs=[],b},function(c){a.isLoading=c.isLoading,a._pendingPubs.forEach(function(a){a()}),a._pendingPubs=null,a._hasChangesAction&&a._hasChangesAction(),b=null,h=null,c.error&&ob.reject(c.error)},function(){var e=d.jsonResultsAdapter.extractResults(c);e=m(e);var f=h.visitAndMerge(e,{nodeType:"root"});return i&&f.forEach(function(a){a.entityAspect&&a.entityAspect.validateEntity()}),h.processDeferred(),{results:f,query:b,entityManager:a,httpResponse:c.httpResponse,inlineCount:c.inlineCount}});return ob.resolve(e)},function(c){return c&&(c.query=b,c.entityManager=a),ob.reject(c)})}catch(g){return g&&(g.query=b),ob.reject(g)}}function M(a){var b=a.filter(function(a){return a.entityAspect.isBeingSaved=!0,a.entityAspect.entityState.isModified()&&a.entityType.concurrencyProperties.length>0});0!==b.length&&b.forEach(function(a){a.entityType.concurrencyProperties.forEach(function(b){N(a,b)})})}function N(a,b){if(!a.entityAspect.originalValues[b.name]){var c=a.getProperty(b.name);if(c||(c=b.dataType.defaultValue),b.dataType.isNumeric)a.setProperty(b.name,c+1);else if(b.dataType.isDate){for(var d=new Date,e=new Date;d.getTime()===e.getTime();)e=new Date;a.setProperty(b.name,e)}else{if(b.dataType!==lb.Guid){if(b.dataType===lb.Binary)return;throw new Error("Unable to update the value of concurrency property before saving: "+b.name)}a.setProperty(b.name,z())}}}function O(a,b){var c=a._entityGroupMap[b.name];return c||(c=new Pb(a,b),a._entityGroupMap[b.name]=c),c}function P(a,b){var c=b.getSelfAndSubtypes();return c.map(function(b){return O(a,b)})}function Q(a,b){var c={},d=a.entityType||a.complexType,e=V(d),f={};return d.dataProperties.forEach(function(d){if(d.isComplexProperty)c[d.nameOnServer]=n(a.getProperty(d.name),function(a){return Q(a,b)});else{var g=a.getProperty(d.name);if(g=b?b(d,g):g,void 0===g)return;g=e?e(d,g):g,void 0!==g&&(d.isUnmapped?f[d.name]=k(g):c[d.nameOnServer]=g)}}),G(f)||(c.__unmapped=f),c}function R(b,c,d){var e=b.entityType||b.complexType,f=b.entityAspect||b.complexAspect,g=c.namingConvention.clientPropertyNameToServer,h={};return a(f.originalValues,function(a,b){var c=e.getProperty(a);b=d?d(c,b):b,void 0!==b&&(h[g(a,c)]=b)}),e.complexProperties.forEach(function(a){var e=b.getProperty(a.name);if(a.isScalar){var f=R(e,c,d);G(f)||(h[g(a.name,a)]=f)}else{var i=e.map(function(a){return R(a,c,d)});h[g(a.name,a)]=i}}),h}function T(b,c,d){var e=b.entityType||b.complexType,f=V(e),g=b.entityAspect||b.complexAspect,h=c.namingConvention.clientPropertyNameToServer,i={};return a(g.originalValues,function(a){var c=e.getProperty(a),g=b.getProperty(a);g=d?d(c,g):g,void 0!==g&&(g=f?f(dp,g):g,void 0!==g&&(i[h(a,c)]=g))}),e.complexProperties.forEach(function(a){var e=b.getProperty(a.name);if(a.isScalar){var f=T(e,c,d);G(f)||(i[h(a.name,a)]=f)}else{var g=e.map(function(a){return T(a,c,d)});i[h(a.name,a)]=g}}),i}function V(a){return a.serializerFn||a.metadataStore&&a.metadataStore.serializerFn}function W(){this.map={}}var Y=function(a){if(arguments.length>1)throw new Error("The EntityManager ctor has a single optional argument that is either a 'serviceName' or a configuration object.");0===arguments.length?a={serviceName:""}:"string"==typeof a&&(a={serviceName:a}),b(this,a,!0),this.entityChanged=new _("entityChanged",this),this.validationErrorsChanged=new _("validationErrorsChanged",this),this.hasChangesChanged=new _("hasChangesChanged",this),this.clear()},$=Y.prototype;return $._$typeName="EntityManager",_.bubbleEvent($,null),$.setProperties=function(a){b(this,a,!1)},$.createEntity=function(a,b,c,d){X(a,"entityType").isString().or().isInstanceOf(rb).check(),X(c,"entityState").isEnumOf(kb).isOptional().check(),X(d,"mergeStrategy").isEnumOf(Mb).isOptional().check(),"string"==typeof a&&(a=this.metadataStore._getEntityType(a)),c=c||kb.Added;var e;return w(this,"isLoading",!0,function(){e=a.createEntity(b)}),c!==kb.Detached&&(e=this.attachEntity(e,c,d)),e},Y.importEntities=function(a,b){var c=new Qb;return c.importEntities(a,b),c},$.acceptChanges=function(){this.getChanges().forEach(function(a){a.entityAspect.acceptChanges()})},$.exportEntities=function(a,b){X(b,"includeMetadata").isBoolean().isOptional().check(),b=null==b?!0:b;var c=v(this,a),d=g({},c,["tempKeys","entityGroupMap"]);b?(d=g(d,this,["dataService","saveOptions","queryOptions","validationOptions"]),d.metadataStore=this.metadataStore.exportMetadata()):(d.metadataVersion=S.metadataVersion,d.metadataStoreName=this.metadataStore.name);var e=JSON.stringify(d,null,ab.stringifyPad);return e},$.importEntities=function(b,c){c=c||{},Z(c).whereParam("mergeStrategy").isEnumOf(Mb).isOptional().withDefault(this.queryOptions.mergeStrategy).whereParam("metadataVersionFn").isFunction().isOptional().applyAll(c);var d=this,e="string"==typeof b?JSON.parse(b):b;e.metadataStore?(this.metadataStore.importMetadata(e.metadataStore),this.dataService=e.dataService&&mb.fromJSON(e.dataService)||new mb({serviceName:e.serviceName}),this.saveOptions=new Sb(e.saveOptions),this.queryOptions=Ob.fromJSON(e.queryOptions),this.validationOptions=new fb(e.validationOptions)):c.metadataVersionFn&&c.metadataVersionFn({metadataVersion:e.metadataVersion,metadataStoreName:e.metadataStoreName});var f={};e.tempKeys.forEach(function(a){var b=jb.fromJSON(a,d.metadataStore);f[b.toString()]=new jb(b.entityType,d.keyGenerator.generateTempKeyValue(b.entityType,b.values[0]))});var g=[];return c.tempKeyMap=f,x(function(){d._pendingPubs=[]},function(){d._pendingPubs.forEach(function(a){a()}),d._pendingPubs=null,d._hasChangesAction&&d._hasChangesAction()},function(){a(e.entityGroupMap,function(a,b){var e=d.metadataStore._getEntityType(a,!0),f=O(d,e),h=C(f,b,c);Array.prototype.push.apply(g,h)}),g.forEach(function(a){d._linkRelatedEntities(a)})}),{entities:g,tempKeyMapping:f}},$.clear=function(){a(this._entityGroupMap,function(a,b){b._clear()}),this._entityGroupMap={},this._unattachedChildrenMap=new W,this.keyGenerator=new this.keyGeneratorCtor,this.entityChanged.publish({entityAction:gb.Clear}),this._setHasChanges(!1)},$.createEmptyCopy=function(){var a=new Y(g({},this,["dataService","metadataStore","queryOptions","saveOptions","validationOptions","keyGeneratorCtor"]));return a},$.addEntity=function(a){return this.attachEntity(a,kb.Added)},$.attachEntity=function(a,b,c){if(X(a,"entity").isRequired().check(),this.metadataStore._checkEntityType(a),b=X(b,"entityState").isEnumOf(kb).isOptional().check(kb.Unchanged),c=X(c,"mergeStrategy").isEnumOf(Mb).isOptional().check(Mb.Disallowed),a.entityType.metadataStore!==this.metadataStore)throw new Error("Cannot attach this entity because the EntityType ("+a.entityType.name+") and MetadataStore associated with this entity does not match this EntityManager's MetadataStore.");var d=a.entityAspect;if(d){if(d._inProcessEntity)return d._inProcessEntity}else d=new hb(a);var e=d.entityManager;if(e){if(e===this)return a;throw new Error("This entity already belongs to another EntityManager")}var f,g=this;return w(this,"isLoading",!0,function(){b.isAdded()&&I(g,a),f=g._attachEntityCore(a,b,c),d._inProcessEntity=f;try{K(g,a,b,c)}finally{d._inProcessEntity=null}}),this.validationOptions.validateOnAttach&&f.entityAspect.validateEntity(),b.isUnchanged()||this._notifyStateChange(f,!0),this.entityChanged.publish({entityAction:gb.Attach,entity:f}),f},$.detachEntity=function(a){X(a,"entity").isEntity().check();var b=a.entityAspect;if(!b)return!1;
if(b.entityManager!==this)throw new Error("This entity does not belong to this EntityManager.");return b.setDetached()},$.fetchMetadata=function(a,b,c){"function"==typeof a?(c=b,b=a,a=null):(X(a,"dataService").isInstanceOf(mb).isOptional().check(),X(b,"callback").isFunction().isOptional().check(),X(c,"errorCallback").isFunction().isOptional().check());var d=this.metadataStore.fetchMetadata(a||this.dataService);return D(d,b,c)},$.executeQuery=function(a,b,c){X(a,"query").isInstanceOf(zb).or().isString().check(),X(b,"callback").isFunction().isOptional().check(),X(c,"errorCallback").isFunction().isOptional().check();var d,e=Ob.resolve([a.queryOptions,this.queryOptions,Ob.defaultInstance]),f=mb.resolve([a.dataService,this.dataService]);if(!f.hasServerMetadata||this.metadataStore.hasMetadataFor(f.serviceName))d=L(this,a,e,f);else{var g=this;d=this.fetchMetadata(f).then(function(){return L(g,a,e,f)})}return D(d,b,c)},$.executeQueryLocally=function(a){X(a,"query").isInstanceOf(zb).check();var b=this.metadataStore,c=a._getFromEntityType(b,!0),d=P(this,c),e=a._toFilterFunction(c);if(e)var f=function(a){return a&&!a.entityAspect.entityState.isDeleted()&&e(a)};else var f=function(a){return a&&!a.entityAspect.entityState.isDeleted()};var g=[];d.forEach(function(a){g.push.apply(g,a._entities.filter(f))});var h=a._toOrderByComparer(c);h&&g.sort(h);var i=a.skipCount;i&&(g=g.slice(i));var j=a.takeCount;j&&(g=g.slice(0,j));var k=a.selectClause;if(k){var l=k.toFunction();g=g.map(function(a){return l(a)})}return g},$.saveChanges=function(a,b,f,g){function h(a){var b=t.entityManager,c=a.entities=t.processSavedEntities(a),d=l&&i(m,c)?!1:null;return b._setHasChanges(d),u(m,!1),f&&f(a),ob.resolve(a)}function j(a){var b=a.entities;if(0===b.length)return[];var c=a.keyMappings,d=t.entityManager;return F(d,c),w(d,"isLoading",!0,function(){var a=new Rb({query:null,entityManager:d,mergeOptions:{mergeStrategy:Mb.OverwriteChanges},dataService:s});b=a.visitAndMerge(b,{nodeType:"root"})}),b}function k(a){return u(m,!1),e(t,a),g&&g(a),ob.reject(a)}X(a,"entities").isOptional().isArray().isEntity().check(),X(b,"saveOptions").isInstanceOf(Sb).isOptional().check(),X(f,"callback").isFunction().isOptional().check(),X(g,"errorCallback").isFunction().isOptional().check(),b=b||this.saveOptions||Sb.defaultInstance;var l=null==a,m=E(this,a);if(0===m.length){var n={entities:[],keyMappings:[]};return f&&f(n),ob.resolve(n)}if(!b.allowConcurrentSaves){var o=m.some(function(a){return a.entityAspect.isBeingSaved});if(o){var p=new Error("Concurrent saves not allowed - SaveOptions.allowConcurrentSaves is false");return g&&g(p),ob.reject(p)}}if(c(m),this.validationOptions.validateOnSave){var q=m.filter(function(a){var b=a.entityAspect,c=b.entityState.isDeleted()||b.validateEntity();return!c});if(q.length>0){var r=new Error("Client side validation errors encountered - see the entityErrors collection on this object for more detail");return r.entityErrors=d(q),g&&g(r),ob.reject(r)}}var s=mb.resolve([b.dataService,this.dataService]),t={entityManager:this,dataService:s,processSavedEntities:j,resourceName:b.resourceName||this.saveOptions.resourceName||"SaveChanges"},v={entities:m,saveOptions:b};try{return M(m),s.adapterInstance.saveChanges(t,v).then(h).then(null,k)}catch(p){return u(m,!1),g&&g(p),ob.reject(p)}},$._findEntityGroup=function(a){return this._entityGroupMap[a.name]},$.getEntityByKey=function(){var a,b=s(this,arguments).entityKey,c=b._subtypes;if(!c)return a=this._findEntityGroup(b.entityType),a&&a.findEntityByKey(b);for(var d=0,e=c.length;e>d;d++){a=this._findEntityGroup(c[d]);var f=a&&a.findEntityByKey(b);if(f)return f}},$.fetchEntityByKey=function(){var a=mb.resolve([this.dataService]);if(!a.hasServerMetadata||this.metadataStore.hasMetadataFor(a.serviceName))return j(this,arguments);var b=this,c=arguments;return this.fetchMetadata(a).then(function(){return j(b,c)})},$.findEntityByKey=function(a){return this.getEntityByKey(a)},$.generateTempKeyValue=function(a){X(a,"entity").isEntity().check();var b=a.entityType,c=this.keyGenerator.generateTempKeyValue(b),d=b.keyProperties[0];return a.setProperty(d.name,c),a.entityAspect.hasTempKey=!0,c},$.hasChanges=function(a){return this._hasChanges?void 0===a?this._hasChanges:this._hasChangesCore(a):!1},$._hasChangesCore=function(a){a=l(this,a);var b=H(this,a);return b.some(function(a){return a.hasChanges()})},$.getChanges=function(a){a=l(this,a);var b=[kb.Added,kb.Modified,kb.Deleted];return p(this,a,b)},$.rejectChanges=function(){if(!this._hasChanges)return[];var a=[kb.Added,kb.Modified,kb.Deleted],b=p(this,null,a);return this._hasChanges=!1,b.forEach(function(a){a.entityAspect.rejectChanges()}),this.hasChangesChanged.publish({entityManager:this,hasChanges:!1}),b},$.getEntities=function(a,b){return a=l(this,a),X(b,"entityStates").isOptional().isEnumOf(kb).or().isNonEmptyArray().isEnumOf(kb).check(),b&&(b=J(this,b)),p(this,a,b)},$._checkStateChange=function(a,b,c){b?c||this._notifyStateChange(a,!0):c&&this._notifyStateChange(a,!1)},$._notifyStateChange=function(a,b){this.entityChanged.publish({entityAction:gb.EntityStateChange,entity:a}),b?this._hasChanges||this._setHasChanges(!0):this._hasChanges&&(this.isLoading?this._hasChangesAction=this._hasChangesAction||function(){this._setHasChanges(null)}.bind(this):this._setHasChanges(null))},$._setHasChanges=function(a){null==a&&(a=this._hasChangesCore());var b=this._hasChanges;this._hasChanges=a,a!=b&&this.hasChangesChanged.publish({entityManager:this,hasChanges:a}),this._hasChangesAction=null},$._linkRelatedEntities=function(a){var b=this,c=a.entityAspect;w(b,"isLoading",!0,function(){var d=b._unattachedChildrenMap,e=c.getKey(),f=d.getTuples(e);f&&f.forEach(function(b){var c,f,g=b.children.filter(function(a){return a.entityAspect.entityState!==kb.Detached}),h=b.navigationProperty;if(h.inverse)if(c=h,f=h.inverse,f.isScalar){var i=g[0];a.setProperty(f.name,i),i.setProperty(c.name,a)}else{var j=a.getProperty(f.name);g.forEach(function(b){j.push(b),b.setProperty(c.name,a)})}else if(h.parentType===a.entityType)if(f=h,f.isScalar)a.setProperty(f.name,g[0]);else{var j=a.getProperty(f.name);g.forEach(function(a){j._push(a)})}else c=h,g.forEach(function(b){b.setProperty(c.name,a)});d.removeChildren(e,c)}),a.entityType.navigationProperties.forEach(function(e){if(e.isScalar){var f=a.getProperty(e.name);if(f)return}var g=c.getParentKey(e);if(g){if(g._isEmpty())return;var h=b.findEntityByKey(g);h?a.setProperty(e.name,h):d.addChild(g,e,a)}}),a.entityType.foreignKeyProperties.forEach(function(c){var e=c.inverseNavigationProperty;if(e){var f=a.getProperty(c.name),g=new jb(e.parentType,[f]),h=b.findEntityByKey(g);h?e.isScalar?h.setProperty(e.name,a):b.isLoading?h.getProperty(e.name)._push(a):h.getProperty(e.name).push(a):d.addChild(g,e,a)}})})},$._attachEntityCore=function(a,b,c){var d=O(this,a.entityType),e=d.attachEntity(a,b,c);return this._linkRelatedEntities(e),e},$._updateFkVal=function(a,b,c){var d=this._entityGroupMap[a.parentType.name];d&&d._updateFkVal(a,b,c)},$.helper={unwrapInstance:Q,unwrapOriginalValues:R,unwrapChangedValues:T},W.prototype.addChild=function(a,b,c){var d=this.getTuple(a,b);d||(d={navigationProperty:b,children:[]},t(this.map,a.toString()).push(d)),d.children.push(c)},W.prototype.removeChildren=function(a,b){var c=this.map[a.toString()];c&&(q(c,function(a){return a.navigationProperty===b}),c.length||delete this.map[a.toString()])},W.prototype.getChildren=function(a,b){var c=this.getTuple(a,b);return c?c.children.filter(function(a){return!a.entityAspect.entityState.isDetached()}):null},W.prototype.getTuple=function(a,b){var c=this.map[a.toString()];if(!c)return null;var d=o(c,function(a){return a.navigationProperty===b});return d},W.prototype.getTuples=function(a){return this.map[a.toString()]},Y}();S.EntityManager=Qb;var Rb=function(){function b(a,b,e,g){if(e.ignore||null==b)return null;if(e.nodeRefId){var h=f(a,e.nodeRefId);return"function"==typeof h&&null!=g?(a.deferredFns.push(function(){g(h)}),void 0):h}if(e.entityType){var j=e.entityType;return a.mergeOptions.noTracking?(b=c(a,j,b),j.noTrackingFn&&(b=j.noTrackingFn(b,j)),e.nodeId&&(a.refMap[e.nodeId]=b),b):j.isComplexType?c(a,j,b):i(a,b,e)}return"object"!=typeof b||C(b)||(b=d(a,b)),e.nodeId&&(a.refMap[e.nodeId]=b),b}function c(a,b,d){var f={};return b.dataProperties.forEach(function(b){f[b.name]=b.isComplexProperty?n(d[b.nameOnServer],function(d){return c(a,b.dataType,d)}):u(d[b.nameOnServer],b.dataType)}),b.navigationProperties&&b.navigationProperties.forEach(function(b){var c={nodeType:"navProp",navigationProperty:b};e(d[b.nameOnServer],a,c,f,b.name)}),f}function d(b,c){var d=b.metadataStore.namingConvention.serverPropertyNameToClient,f={};return a(c,function(a,c){var g=d(a),h={nodeType:"anonProp",propertyName:g};e(c,b,h,f,g)}),f}function e(a,c,d,e,f){var g=c.jsonResultsAdapter,h=g.visitNode(a,c,d)||{};a=h.node||a,h.ignore||(Array.isArray(a)?(d.nodeType=d.nodeType+"Item",e[f]=a.map(function(a,i){return h=g.visitNode(a,c,d)||{},a=h.node||a,b(c,a,h,function(a){e[f][i]=a()})})):e[f]=b(c,a,h,function(a){e[f]=a()}))}function f(a,b){var c=a.refMap[b];return void 0===c?function(){return a.refMap[b]}:c}function h(a,b,c){var d=c._$meta.nodeId;null!=d&&(a.refMap[d]=b)}function i(a,b,c){b._$meta=c;var d=a.entityManager,e=c.entityType;"string"==typeof e&&(e=a.metadataStore._getEntityType(e,!1)),b.entityType=e;var f=a.mergeOptions.mergeStrategy,g=null==a.query,h=e.getEntityKeyFromRawEntity(b,a.rawValueFn),i=d.findEntityByKey(h);if(i){if(g&&i.entityAspect.entityState.isDeleted())return d.detachEntity(i),i;var l=i.entityAspect.entityState;if(f===Mb.Disallowed)throw new Error("A MergeStrategy of 'Disallowed' prevents "+h.toString()+" from being merged");if(f===Mb.SkipMerge)j(a,i,b);else if(f===Mb.OverwriteChanges||l.isUnchanged()){k(a,i,b),i.entityAspect.wasLoaded=!0,c.extra&&(i.entityAspect.extraMetadata=c.extra),i.entityAspect.entityState=kb.Unchanged,i.entityAspect.originalValues={},i.entityAspect.propertyChanged.publish({entity:i,propertyName:null});var m=g?gb.MergeOnSave:gb.MergeOnQuery;d.entityChanged.publish({entityAction:m,entity:i}),l.isUnchanged()||d._notifyStateChange(i,!1)}else j(a,i,b)}else i=e._createInstanceCore(),k(a,i,b),c.extra&&(i.entityAspect.extraMetadata=c.extra),d._attachEntityCore(i,kb.Unchanged,Mb.Disallowed),i.entityAspect.wasLoaded=!0,d.entityChanged.publish({entityAction:gb.AttachOnQuery,entity:i});return i}function j(a,b,c){h(a,b,c),c.entityType.navigationProperties.forEach(function(b){b.isScalar?o(a,c,b):p(a,c,b)})}function k(a,b,c){h(a,b,c);var d=b.entityType;d._updateTargetFromRaw(b,c,a.rawValueFn),d.navigationProperties.forEach(function(d){d.isScalar?l(a,d,b,c):m(a,d,b,c)})}function l(a,b,c,d){var e=o(a,d,b);null!=e&&("function"==typeof e?a.deferredFns.push(function(){e=e(),q(e,c,b)}):q(e,c,b))}function m(a,b,c,d){var e=p(a,d,b);if(null!=e){var f=b.inverse;if(f){var g=c.getProperty(b.name);g.wasLoaded=!0,e.forEach(function(b){"function"==typeof b?a.deferredFns.push(function(){b=b(),r(b,g,c,f)}):r(b,g,c,f)})}}}function o(a,b,c){var d=b[c.nameOnServer];if(!d)return null;var e=a.visitAndMerge(d,{nodeType:"navProp",navigationProperty:c});return e}function p(a,b,c){var d=b[c.nameOnServer];if(!d)return null;if(!Array.isArray(d)&&(d=d.results,!d))return null;var e=a.visitAndMerge(d,{nodeType:"navPropItem",navigationProperty:c});return e}function q(a,b,c){if(a){var d=c.name,e=b.getProperty(d);if(e!==a){b.setProperty(d,a);var f=c.inverse;if(!f)return;if(f.isScalar)a.setProperty(f.name,b);else{var g=a.getProperty(f.name);g.push(b)}}}}function r(a,b,c,d){if(a){var e=a.getProperty(d.name);e!==c&&(b.push(a),a.setProperty(d.name,c))}}var s=function(a){g(this,a,["query","entityManager","dataService","mergeOptions"]),this.refMap={},this.deferredFns=[],this.jsonResultsAdapter=this.dataService.jsonResultsAdapter,this.metadataStore=this.entityManager.metadataStore,this.rawValueFn=tb.getRawValueFromServer},t=s.prototype,u=lb.parseRawValue;return t._$typeName="MappingContext",t.getUrl=function(){return this.dataService.makeUrl(this.metadataStore.toQueryString(this.query))},t.visitAndMerge=function(a,c){var d=this.query,e=this.jsonResultsAdapter;c=c||{};var f=this;return n(a,function(a){if(null==d&&a.entityAspect)return a.entityAspect.entityState.isDeleted()?f.entityManager.detachEntity(a):a.entityAspect.acceptChanges(),a;var g=e.visitNode(a,f,c)||{};return a=g.node||a,d&&"root"===c.nodeType&&!g.entityType&&(g.entityType=d._getToEntityType&&d._getToEntityType(f.metadataStore)),b(f,a,g)})},t.processDeferred=function(){this.deferredFns.length>0&&this.deferredFns.forEach(function(a){a()})},s}(),Sb=function(){function a(a,b){return b&&Z(b).whereParam("resourceName").isOptional().isString().whereParam("dataService").isOptional().isInstanceOf(mb).whereParam("allowConcurrentSaves").isBoolean().isOptional().whereParam("tag").isOptional().applyAll(a),a}var b=function(b){a(this,b)},c=b.prototype;return c._$typeName="SaveOptions",c.setAsDefault=function(){return i(this,b)},c.using=function(b){return a(this,b)},b.defaultInstance=new b({allowConcurrentSaves:!1}),b}();S.SaveOptions=Sb,S.AbstractDataServiceAdapter=function(){function a(a,c,d){var e=b(c);return d&&(e.message=d+"; "+e.message),a.reject(e)}function b(a){var b=new Error;b.httpResponse=a,b.status=a.status;var e=a.data;if("string"==typeof e)try{e=JSON.parse(e)}catch(f){}if(e){var g=e.EntityErrors||e.entityErrors||e.Errors||e.errors;g&&a.saveContext?d(b,g,a.saveContext):b.message=c(e)}else b.message=a.error&&a.error.toString();return b}function c(a){for(;a.InnerException;)a=a.InnerException;return a.ExceptionMessage||a.Message||a.toString()}function d(a,b,c){a.message="Server side errors encountered - see the entityErrors collection on this object for more detail";var d=c.entityManager.metadataStore.namingConvention.serverPropertyNameToClient;a.entityErrors=b.map(function(a){return{errorName:a.ErrorName,entityTypeName:pb.normalizeTypeName(a.EntityTypeName),keyValues:a.KeyValues,propertyName:a.PropertyName&&d(a.PropertyName),errorMessage:a.ErrorMessage}})}var e,f=function(){};return f.prototype.checkForRecomposition=function(a){"ajax"===a.interfaceName&&a.isDefault&&this.initialize()},f.prototype.initialize=function(){if(e=S.config.getAdapterInstance("ajax"),!e||!e.ajax)throw new Error("Unable to find ajax adapter for dataservice adapter '"+(this.name||"")+"'.")},f.prototype.fetchMetadata=function(b,c){var d=c.serviceName,f=c.makeUrl("Metadata"),g=ob.defer();return e.ajax({type:"GET",url:f,dataType:"json",success:function(e){if(b.hasMetadataFor(d))return g.resolve("already fetched");var h=e.data;try{var i="string"==typeof h?JSON.parse(h):h;b.importMetadata(i)}catch(j){var k="Unable to either parse or import metadata: "+j.message;return a(g,e,"Metadata query failed for: "+f+". "+k)}b.hasMetadataFor(d)||b.addDataService(c),g.resolve(i)},error:function(b){a(g,b,"Metadata query failed for: "+f)}}),g.promise},f.prototype.executeQuery=function(b){var c=ob.defer(),d=b.getUrl(),f={type:"GET",url:d,params:b.query.parameters,dataType:"json",success:function(b){var d=b.data;try{var e;e=d&&d.Results?{results:d.Results,inlineCount:d.InlineCount,httpResponse:b}:{results:d,httpResponse:b},c.resolve(e)}catch(f){f instanceof Error?c.reject(f):a(b)}},error:function(b){a(c,b)}};return b.dataService.useJsonp&&(f.dataType="jsonp",f.crossDomain=!0),e.ajax(f),c.promise},f.prototype.saveChanges=function(b,c){var d=ob.defer();c=this._prepareSaveBundle(c,b);var f=JSON.stringify(c),g=b.dataService.makeUrl(b.resourceName),h=this;return e.ajax({type:"POST",url:g,dataType:"json",contentType:"application/json",data:f,success:function(c){var e=c.data;c.saveContext=b;var f=e.Errors||e.errors;if(f)a(d,c);else{var g=h._prepareSaveResult(b,e);d.resolve(g)}},error:function(c){c.saveContext=b,a(d,c)}}),d.promise},f.prototype._prepareSaveBundle=function(){throw new Error("Need a concrete implementation of _prepareSaveBundle")},f.prototype._prepareSaveResult=function(){throw new Error("Need a concrete implementation of _prepareSaveResult")},f.prototype.jsonResultsAdapter=new nb({name:"noop",visitNode:function(){return{}}}),f}(),S.config.initializeAdapterInstances({dataService:"webApi",ajax:"jQuery"});var Tb=v("ko");return Tb?S.config.initializeAdapterInstance("modelLibrary","ko"):S.config.initializeAdapterInstance("modelLibrary","backingStore"),this.window&&(this.window.breeze=S),S});