!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define("cdt-breeze-client",["exports"],t):t((e=e||self)["cdt-breeze-client"]={})}(this,function(e){"use strict";var t=function(e,r){return(t=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,t){e.__proto__=t}||function(e,t){for(var r in t)t.hasOwnProperty(r)&&(e[r]=t[r])})(e,r)};function r(e,r){function n(){this.constructor=e}t(e,r),e.prototype=null===r?Object.create(r):(n.prototype=r.prototype,new n)}function n(e,t){var r="function"==typeof Symbol&&e[Symbol.iterator];if(!r)return e;var n,i,a=r.call(e),o=[];try{for(;(void 0===t||t-- >0)&&!(n=a.next()).done;)o.push(n.value)}catch(s){i={error:s}}finally{try{n&&!n.done&&(r=a["return"])&&r.call(a)}finally{if(i)throw i.error}}return o}function i(){for(var e=[],t=0;t<arguments.length;t++)e=e.concat(n(arguments[t]));return e}var a=function(){function e(e){var t=this;e&&Object.keys(e).forEach(function(r){return t[r]=e[r]})}return e.getSymbols=function(){return this.resolveSymbols().map(function(e){return e.symbol})},e.getNames=function(){return this.resolveSymbols().map(function(e){return e.name})},e.fromName=function(e){return this[e]},e.resolveSymbols=function(){if(this._resolvedNamesAndSymbols)return this._resolvedNamesAndSymbols;var t=[];for(var r in this)if(this.hasOwnProperty(r)){var n=this[r];n instanceof e&&(t.push({name:r,symbol:n}),this[r]=n,n.name=r)}return this._resolvedNamesAndSymbols=t,t},e.contains=function(t){return t instanceof e&&null!=this[t.name]},e.prototype.toString=function(){return this.name},e.prototype.toJSON=function(){return{_$typeName:this._$typeName||this.constructor.name,name:this.name}},e}(),o=d(Object.prototype.hasOwnProperty),s=d(Array.prototype.slice),u=function(){try{return!(!Object.getPrototypeOf||!Object.defineProperty({},"x",{}))}catch(e){return!1}}();function p(e,t){if(!u)return undefined;if(e.hasOwnProperty(t))return Object.getOwnPropertyDescriptor(e,t);var r=Object.getPrototypeOf(e);return null==r?undefined:p(r,t)}function c(e,t){for(var r in t)e[r]===undefined&&(e[r]=t[r]);return e}function y(e){var t=window||(global?global.window:undefined);if(t){var r=t[e];if(r)return r;var n=t.require;if(n){if(n.defined)return n.defined(e)?n(e):undefined;try{return n(e)}catch(i){return}}}}function l(e){return null===e?"null":e===undefined?"undefined":Object.prototype.toString.call(e).slice(8,-1).toLowerCase()}function f(e){return"function"===l(e)}var h=/([A-Z](?=[A-Z][a-z])|[^A-Z](?=[A-Z])|[a-zA-Z](?=[^a-zA-Z]))/g;function d(e){var t=Function.call;return function(){return t.apply(e,arguments)}}Object.create||(Object.create=function(e){var t=function(){};return t.prototype=e,new t});var m={isES5Supported:u,hasOwnProperty:o,getOwnPropertyValues:function(e){var t=[];for(var r in e)o(e,r)&&t.push(e[r]);return t},getPropertyDescriptor:p,objectForEach:function(e,t){for(var r in e)o(e,r)&&t(r,e[r])},objectFirst:function(e,t){for(var r in e)if(o(e,r)){var n=e[r];if(t(r,n))return{key:r,value:n}}return null},objectMap:function(e,t){var r=[];for(var n in e)if(o(e,n)){var i=t?t(n,e[n]):e[n];i!==undefined&&r.push(i)}return r},extend:function(e,t,r){if(!t)return e;if(r)r.forEach(function(r){e[r]=t[r]});else for(var n in t)o(t,n)&&(e[n]=t[n]);return e},propEq:function(e,t){return function(r){return r[e]===t}},propsEq:function(e,t,r){return function(n){return n[e]===r||n[t]===r}},pluck:function(e){return function(t){return t[e]}},map:function(e,t,r){if(r=null==r||r,null==e)return e;if(Array.isArray(e)){var n=[];return e.forEach(function(e,i){var a=t(e,i);(null!=a||r)&&(n[i]=a)}),n}return t(e)},resolveProperties:function(e,t){var r={},n=e.length;return t.forEach(function(t){for(var i=0;i<n;i++){var a=e[i];if(a){var o=a[t];if(o!==undefined){r[t]=o;break}}}}),r},setAsDefault:function(e,t){return t.defaultInstance=c(new t(e),t.defaultInstance),e},updateWithDefaults:c,getArray:function(e,t){var r=e[t];return r||(r=[],e[t]=r),r},toArray:function(e){return null==e?[]:Array.isArray(e)?e:[e]},arrayEquals:function en(e,t,r){if(!e||!t)return!1;if(e.length!==t.length)return!1;for(var n=0;n<e.length;n++)if(Array.isArray(e[n])){if(!en(e[n],t[n]))return!1}else if(r){if(!r(e[n],t[n]))return!1}else if(e[n]!==t[n])return!1;return!0},arraySlice:s,arrayFirst:function(e,t){for(var r=0,n=e.length;r<n;r++)if(t(e[r]))return e[r];return null},arrayIndexOf:function(e,t){for(var r=0,n=e.length;r<n;r++)if(t(e[r]))return r;return-1},arrayRemoveItem:function(e,t,r){for(var n=f(t)?t:undefined,i=!1,a=e.length-1;a>=0;a--)if((n?n(e[a]):e[a]===t)&&(e.splice(a,1),i=!0,!r))return!0;return i},arrayZip:function(e,t,r){for(var n=[],i=Math.min(e.length,t.length),a=0;a<i;++a)n.push(r(e[a],t[a]));return n},arrayAddItemUnique:function(e,t){-1===e.indexOf(t)&&e.push(t)},arrayFlatMap:function(e,t){return Array.prototype.concat.apply([],e.map(t))},requireLib:function(e,t){for(var r=e.split(";"),n=0,i=r.length;n<i;n++){var a=y(r[n]);if(a)return a}if(t)throw new Error("Unable to initialize "+e+".  "+t)},using:function(e,t,r,n){var i=e[t];if(r===i)return n();e[t]=r;try{return n()}finally{i===undefined?delete e[t]:e[t]=i}},wrapExecution:function(e,t,r){var n;try{return n=e(),r()}catch(i){throw"object"==typeof n&&(n.error=i),i}finally{t(n)}},memoize:function(e){return function(){for(var t=s(arguments),r="",n=t.length,i=null;n--;)r+=(i=t[n])===Object(i)?JSON.stringify(i):i,e.memoize||(e.memoize={});return r in e.memoize?e.memoize[r]:e.memoize[r]=e.apply(this,t)}},getUuid:function(){return"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,function(e){var t=16*Math.random()|0;return("x"==e?t:3&t|8).toString(16)})},durationToSeconds:function(e){if("string"!=typeof e)throw new Error("Invalid ISO8601 duration '"+e+"'");var t=/^P((\d+Y)?(\d+M)?(\d+D)?)?(T(\d+H)?(\d+M)?(\d+S)?)?$/.exec(e);if(!t)throw new Error("Invalid ISO8601 duration '"+e+"'");for(var r=[2,3,4,6,7,8],n=[31104e3,2592e3,86400,3600,60,1],i=0,a=0;a<6;a++){var o=t[r[a]];i+=(o=o?+o.replace(/[A-Za-z]+/g,""):0)*n[a]}return i},isSettable:function(e,t){var r=p(e,t);return null==r||!(!r.writable&&!r.set)},isDate:function(e){return"date"===l(e)&&!isNaN(e.getTime())},isDateString:function(e){return"string"==typeof e&&/^((\d{4}-[01]\d-[0-3]\dT[0-2]\d:[0-5]\d:[0-5]\d\.\d+([+-][0-2]\d:[0-5]\d|Z))|(\d{4}-[01]\d-[0-3]\dT[0-2]\d:[0-5]\d:[0-5]\d([+-][0-2]\d:[0-5]\d|Z))|(\d{4}-[01]\d-[0-3]\dT[0-2]\d:[0-5]\d([+-][0-2]\d:[0-5]\d|Z)))$/.test(e)},isGuid:function(e){return"string"==typeof e&&/[a-fA-F\d]{8}-(?:[a-fA-F\d]{4}-){3}[a-fA-F\d]{12}/.test(e)},isDuration:function(e){return"string"==typeof e&&/^(-|)?P[T]?[\d\.,\-]+[YMDTHS]/.test(e)},isFunction:f,isEmpty:function(e){if(null===e||e===undefined)return!0;for(var t in e)if(o(e,t))return!1;return!0},isNumeric:function(e){return!isNaN(parseFloat(e))&&isFinite(e)},identity:function(e){return e},noop:function(){},stringStartsWith:function(e,t){return!!e&&(""===t||null==t||0===e.indexOf(t,0))},stringEndsWith:function(e,t){return!!e&&(""===t||null==t||-1!==e.indexOf(t,e.length-t.length))},formatString:function(e){for(var t=[],r=1;r<arguments.length;r++)t[r-1]=arguments[r];var n=arguments,i=RegExp("%([1-"+(arguments.length-1)+"])","g");return e.replace(i,function(e,t){return n[t]})},titleCase:function(e){return e=(e=e.replace(h,"$1 ")).charAt(0).toUpperCase()+e.slice(1)},toJson:function(e,t,r){void 0===r&&(r={});var n=function(n){var i=n.split(","),o=t[n];i.some(function(t){if(!(t in e))return!1;var n=e[t];return!("function"==typeof n||n!=o&&(!Array.isArray(n)||0!==n.length)&&("function"==typeof o?n=o(n):"object"==typeof n&&n&&n instanceof a&&(n=n.name),n!==undefined&&(r[i[0]]=n,0)))})};for(var i in t)n(i);return r},toJSONSafe:function tn(e,t){if(e!==Object(e))return e;if(e._$visited)return undefined;if(e.toJSON){var r=e.toJSON();if(r!==Object(r))return r;if(r!==e)return tn(r,t);e=r}var n;if(e._$visited=!0,e instanceof Array)n=e.map(function(e){return tn(e,t)});else if("function"==typeof e)n=undefined;else for(var i in n={},e)if("_$visited"!==i){var a=e[i];t&&(a=t(i,a))===undefined||(a=tn(a,t))!==undefined&&(n[i]=a)}return delete e._$visited,n},toJSONSafeReplacer:function(e,t){if("entityAspect"!==e&&"complexAspect"!==e&&"entityType"!==e&&"complexType"!==e&&"constructor"!==e&&"_"!==e.charAt(0)&&"$"!==e.charAt(0))return t}},g=function(){function e(e,t){this._applyOne=function(e){this.v!==undefined?e[this.name]=this.v:this.defaultValue!==undefined&&(e[this.name]=this.defaultValue)},this.MESSAGE_PREFIX="The '%1' parameter ",this.v=e,this.name=t,this._contexts=[null]}return e.prototype.isObject=function(){return this.isTypeOf("object")},e.prototype.isBoolean=function(){return this.isTypeOf("boolean")},e.prototype.isString=function(){return this.isTypeOf("string")},e.prototype.isNumber=function(){return this.isTypeOf("number")},e.prototype.isFunction=function(){return this.isTypeOf("function")},e.prototype.isNonEmptyString=function(){return x(this,{fn:E,msg:"must be a nonEmpty string"})},e.prototype.isTypeOf=function(e){return x(this,{fn:w,typeName:e,msg:"must be a '"+e+"'"})},e.prototype.isInstanceOf=function(e,t){return x(this,{fn:P,type:e,typeName:t=t||e.prototype._$typeName,msg:"must be an instance of '"+t+"'"})},e.prototype.hasProperty=function(e){return x(this,{fn:T,propertyName:e,msg:"must have a '"+e+"' property"})},e.prototype.isEnumOf=function(e){return x(this,{fn:S,enumType:e,msg:"must be an instance of the '"+(e.name||"unknown")+"' enumeration"})},e.prototype.isRequired=function(e){return void 0===e&&(e=!1),x(this,{fn:_,allowNull:e,msg:"is required"})},e.prototype.isOptional=function(){return x(this,{fn:N,prevContext:null,msg:A})},e.prototype.isNonEmptyArray=function(){return this.isArray(!0)},e.prototype.isArray=function(e){return x(this,{fn:O,mustNotBeEmpty:e,prevContext:null,msg:b})},e.prototype.or=function(){return this._contexts.push(null),this._context=null,this},e.prototype.check=function(e){var t=function(e){var t=e._contexts;null==t[t.length-1]&&t.pop();if(0===t.length)return undefined;return t.some(function(t){return!!t.fn&&t.fn(t,e.v)})}(this);if(t!==undefined){if(!t)throw new Error(this.getMessage());return this.v!==undefined?this.v:e}},e.prototype._addContext=function(e){return x(this,e)},e.prototype.getMessage=function(){var e=this,t=this._contexts.map(function(t){return C(t,e.v)}).join(", or it ");return m.formatString(this.MESSAGE_PREFIX,this.name)+" "+t},e.prototype.withDefault=function(e){return this.defaultValue=e,this},e.prototype.whereParam=function(e){return this.parent.whereParam(e)},e.prototype.applyAll=function(e,t){void 0===t&&(t=!1);var r=e._$typeName,n=r&&this.parent.config._$typeName===r,i=m.extend({},this.parent.config);if(this.parent.params.forEach(function(r){n||delete i[r.name];try{r.check()}catch(a){F(e,a.message)}!t&&r._applyOne(e)}),!n)for(var a in i)i[a]!==undefined&&F(e,m.formatString("Unknown property: '%1'.",a))},e}(),v=function(e,t){return new g(e,t)};function w(e,t){return null!=t&&typeof t===e.typeName}function E(e,t){return null!=t&&("string"==typeof t&&t.length>0)}function P(e,t){return null!=t&&null!=e.type&&t instanceof e.type}function S(e,t){return null!=t&&null!=e.enumType&&e.enumType.contains(t)}function T(e,t){return null!=t&&null!=e.propertyName&&t[e.propertyName]!==undefined}function _(e,t){return e.allowNull?t!==undefined:null!=t}function N(e,t){if(null==t)return!0;var r=e.prevContext;return!r||!r.fn||r.fn(r,t)}function A(e,t){var r=e.prevContext;return"is optional"+(r?" or it "+C(r,t):"")}function O(e,t){if(!Array.isArray(t))return!1;if(e.mustNotBeEmpty&&0===t.length)return!1;var r=e.prevContext;if(!r)return!0;var n=r;return t.every(function(e){return n.fn&&n.fn(n,e)})}function b(e,t){var r=e.mustNotBeEmpty?"a nonEmpty array":"an array",n=e.prevContext;return" must be "+r+(n?" where each element "+C(n,t):"")}function C(e,t){var r=e.msg;return"function"==typeof r&&(r=r(e,t)),r}function x(e,t){if(e._context){for(var r=e._context;null!=r.prevContext;)r=r.prevContext;if(null===r.prevContext)return r.prevContext=t,e;if(null!=t.prevContext)throw new Error("Illegal construction - use 'or' to combine checks");t.prevContext=e._context}return function(e,t){return e._contexts[e._contexts.length-1]=t,e._context=t,e}(e,t)}function F(e,t){throw new Error(m.formatString("Error configuring an instance of '%1'. %2",e&&e._$typeName||"object",t))}var M=function(){function e(e){if("object"!=typeof e)throw new Error("Configuration parameter should be an object, instead it is a: "+typeof e);this.config=e,this.params=[]}return e.prototype.whereParam=function(e){var t=new g(this.config[e],e);return t.parent=this,this.params.push(t),t},e}(),D=function(e){return new M(e)};function k(e,t,r){var n=e._subscribers;if(!n)return!0;n.forEach(function(n){try{n.callback(t)}catch(i){i.context="unable to publish on topic: "+e.name,r?r(i):e._defaultErrorCallback&&e._defaultErrorCallback(i)}})}m.Param=g,m.assertParam=v,m.assertConfig=D;var I=function(){function e(t,r,n){this.unsubscribe=function(e){if(!this._subscribers)return!1;var t=this._subscribers,r=m.arrayIndexOf(t,function(t){return t.unsubKey===e});return-1!==r&&(t.splice(r,1),0===t.length&&(this._subscribers=null),!0)},v(t,"eventName").isNonEmptyString().check(),v(r,"publisher").isObject().check(),this.name=t,e.__eventNameMap[t]=!0,this.publisher=r,n&&(this._defaultErrorCallback=n)}return e.prototype.publish=function(t,r,n){return void 0===r&&(r=!1),!!e._isEnabled(this.name,this.publisher)&&(!0===r?setTimeout(k,0,this,t,n):k(this,t,n),!0)},e.prototype.publishAsync=function(e,t){this.publish(e,!0,t)},e.prototype.subscribe=function(t){this._subscribers||(this._subscribers=[]);var r=e.__nextUnsubKey;return this._subscribers.push({unsubKey:r,callback:t}),++e.__nextUnsubKey,r},e.prototype.clear=function(){this._subscribers=null},e.bubbleEvent=function(e,t){e._getEventParent=t||null},e.enable=function(e,t,r){v(e,"eventName").isNonEmptyString().check(),v(t,"obj").isObject().check(),v(r,"isEnabled").isBoolean().isOptional().or().isFunction().check();var n=t;n._$eventMap||(n._$eventMap={}),n._$eventMap[e]=r},e.isEnabled=function(t,r){if(v(t,"eventName").isNonEmptyString().check(),v(r,"obj").isObject().check(),r._getEventParent===undefined)throw new Error("This object does not support event enabling/disabling");return e._isEnabled(t,3)},e.__eventNameMap={},e.__nextUnsubKey=1,e._isEnabled=function(e,t){var r=null,n=t,i=n._$eventMap;if(i&&(r=i[e]),null!=r)return"function"==typeof r?r(t):!!r;var a=n._getEventParent&&n._getEventParent();return!a||this._isEnabled(e,a)},e}();m.Event=I;var V=function(){function e(e){this.name=e,this.defaultInstance=undefined,this._implMap={}}return e.prototype.registerCtor=function(e,t){this._implMap[e.toLowerCase()]={ctor:t,defaultInstance:undefined}},e.prototype.getImpl=function(e){return this._implMap[e.toLowerCase()]},e.prototype.getFirstImpl=function(){var e=m.objectFirst(this._implMap,function(){return!0});return e?e.value:null},e.prototype.getDefaultInstance=function(){return this.defaultInstance},e}(),R=function(){function e(){this.functionRegistry={},this.typeRegistry={},this.objectRegistry={},this.stringifyPad="",this.interfaceInitialized=new I("interfaceInitialized",this)}return e.prototype.registerAdapter=function(e,t){v(e,"interfaceName").isNonEmptyString().check(),v(t,"adapterCtor").isFunction().check();var r=(new t).name;if(!r)throw new Error("Unable to locate a 'name' property on the constructor passed into the 'registerAdapter' call.");this.getInterfaceDef(e).registerCtor(r,t)},e.prototype.getAdapter=function(e,t){var r=this.getInterfaceDef(e);if(t){var n=r.getImpl(t);return n?n.ctor:null}return r.defaultInstance?r.defaultInstance._$impl.ctor:null},e.prototype.initializeAdapterInstance=function(e,t,r){void 0===r&&(r=!0),r=r===undefined||r,v(e,"interfaceName").isNonEmptyString().check(),v(t,"adapterName").isNonEmptyString().check(),v(r,"isDefault").isBoolean().check();var n=this.getInterfaceDef(e),i=n.getImpl(t);if(!i)throw new Error("Unregistered adapter.  Interface: "+e+" AdapterName: "+t);return this._initializeAdapterInstanceCore(n,i,r)},e.prototype.getAdapterInstance=function(e,t){var r,n=this.getInterfaceDef(e),i=null==t||""===t;if(i){if(n.defaultInstance)return n.defaultInstance;r=n.getFirstImpl()}else r=n.getImpl(t);return r?r.defaultInstance?r.defaultInstance:this._initializeAdapterInstanceCore(n,r,i):undefined},e.prototype.registerFunction=function(e,t){v(e,"fn").isFunction().check(),v(t,"fnName").isString().check(),e.prototype&&(e.prototype._$fnName=t),this.functionRegistry[t]=e},e.prototype.registerType=function(e,t){v(e,"ctor").isFunction().check(),v(t,"typeName").isString().check(),e.prototype&&(e.prototype._$typeName=t),this.typeRegistry[t]=e},e.prototype.getRegisteredFunction=function(e){return this.functionRegistry[e]},e.prototype.getInterfaceDef=function(e){var t=e.toLowerCase(),r=m.objectFirst(this._interfaceRegistry||{},function(e,r){return e.toLowerCase()===t});if(!r)throw new Error("Unknown interface name: "+e);return r.value},e.prototype.setQ=function(e){console&&console.warn("setQ does nothing; ES6 Promise support is required - use a shim if necessary.")},e.prototype._storeObject=function(e,t,r){var n=("string"==typeof t?t:t.prototype._$typeName)+"."+r;this.objectRegistry[n]=e},e.prototype._fetchObject=function(e,t){if(!t)return undefined;var r=("string"==typeof e?e:e.prototype._$typeName)+"."+t,n=this.objectRegistry[r];if(!n)throw new Error("Unable to locate a registered object by the name: "+r);return n},e.prototype._initializeAdapterInstanceCore=function(e,t,r){var n,i=t.defaultInstance;return i?n=i:(n=new t.ctor,t.defaultInstance=n,n._$impl=t),n.initialize(),r&&(e.defaultInstance=n),this.interfaceInitialized.publish({interfaceName:e.name,instance:n,isDefault:!0}),null!=n.checkForRecomposition&&this.interfaceInitialized.subscribe(function(e){n.checkForRecomposition(e)}),n},e}(),K=new R;m.config=K;var j=function(){function e(e){q(this,e)}return e.prototype.using=function(t){return t?q(new e(this),t):this},e.resolve=function(t){t.push({hasServerMetadata:!0,useJsonp:!1});var r=new e(m.resolveProperties(t,["serviceName","adapterName","uriBuilderName","hasServerMetadata","jsonResultsAdapter","useJsonp"]));if(!r.serviceName)throw new Error("Unable to resolve a 'serviceName' for this dataService");return r.adapterInstance=r.adapterInstance||K.getAdapterInstance("dataService",r.adapterName),r.jsonResultsAdapter=r.jsonResultsAdapter||r.adapterInstance.jsonResultsAdapter,r.uriBuilder=r.uriBuilder||K.getAdapterInstance("uriBuilder",r.uriBuilderName),r},e._normalizeServiceName=function(e){return"/"!==(e=e.trim()).substr(-1)?e+"/":e},e.prototype.toJSON=function(){return m.toJson(this,{serviceName:null,adapterName:null,uriBuilderName:null,hasServerMetadata:null,jsonResultsAdapter:function(e){return e&&e.name},useJsonp:null})},e.fromJSON=function(t){return t.jsonResultsAdapter=K._fetchObject(B,t.jsonResultsAdapter),new e(t)},e.prototype.qualifyUrl=function(e){var t=this.serviceName;return m.stringEndsWith(t,"/")&&(t=t.substr(0,t.length-1)),e="/"+e,m.stringEndsWith(t,e)||(t+=e),t},e}();function q(e,t){return t&&(D(t).whereParam("serviceName").isOptional().whereParam("adapterName").isString().isOptional().whereParam("uriBuilderName").isString().isOptional().whereParam("hasServerMetadata").isBoolean().isOptional().whereParam("jsonResultsAdapter").isInstanceOf(B).isOptional().whereParam("useJsonp").isBoolean().isOptional().applyAll(e),e.serviceName=e.serviceName&&j._normalizeServiceName(e.serviceName),e.adapterInstance=e.adapterName?K.getAdapterInstance("dataService",e.adapterName):undefined,e.uriBuilder=e.uriBuilderName?K.getAdapterInstance("uriBuilder",e.uriBuilderName):undefined),e}j.prototype._$typeName="DataService";var B=function(){return function(e){if(1!==arguments.length)throw new Error("The JsonResultsAdapter ctor should be called with a single argument that is a configuration object.");D(e).whereParam("name").isNonEmptyString().whereParam("extractResults").isFunction().isOptional().withDefault(L).whereParam("extractSaveResults").isFunction().isOptional().withDefault(U).whereParam("extractKeyMappings").isFunction().isOptional().withDefault(z).whereParam("extractDeletedKeys").isFunction().isOptional().withDefault(G).whereParam("visitNode").isFunction().applyAll(this),K._storeObject(this,"JsonResultsAdapter",this.name)}}();function L(e){return e.results}function U(e){return e.entities||e.Entities||[]}function z(e){return e.keyMappings||e.KeyMappings||[]}function G(e){return e.deletedKeys||e.DeletedKeys||[]}B.prototype._$typeName="JsonResultsAdapter";var $={displayName:function(e){return e.property?e.property.resolveProperty("displayName")||e.propertyName||e.property.name:"Value"}},J=function(){function e(t,r,n){this._baseContext=n||{},this._baseContext.name=t,(n=m.extend(Object.create($),this._baseContext)).messageTemplate=n.messageTemplate||e.messageTemplates[t],this.name=t,this.valFn=r,this.context=n}return e.prototype.validate=function(e,t){var r;r=t?m.extend(Object.create(this.context),t):this.context,this.currentContext=r;try{return this.valFn(e,r)?null:(r.value=e,new Y(this,r,this.getMessage()))}catch(n){return new Y(this,r,"Exception occured while executing this validator: "+this.name)}},e.prototype.getMessage=function(){try{var e=this.currentContext,t=e.message;return t?"function"==typeof t?t(e):t:e.messageTemplate?function(e,t,r){void 0===r&&(r=!1);return t?e.replace(/%([^%]+)%/g,function(e,n){var i;return null!=(i=r?t.hasOwnProperty(n)?t[n]:"":t[n])?m.isFunction(i)?i(t):i:""}):e}(e.messageTemplate,e):"invalid value: "+(this.name||"{unnamed validator}")}catch(r){return"Unable to format error message"+r.toString()}},e.prototype.toJSON=function(){return this._baseContext},e.fromJSON=function(t){if(Array.isArray(t))return t.map(function(t){return e.fromJSON(t)});var r="Validator."+t.name,n=K.getRegisteredFunction(r);if(!n)throw new Error("Unable to locate a validator named:"+t.name);return n(t)},e.register=function(e){K.registerFunction(function(){return e},"Validator."+e.name)},e.registerFactory=function(e,t){K.registerFunction(e,"Validator."+t)},e.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"},e.required=function(t){return new e("required",function(e,t){return"string"==typeof e?!(!t||!t.allowEmptyStrings)||e.length>0:null!=e},t)},e.maxLength=function(t){return new e("maxLength",function(e,t){return null==e||"string"==typeof e&&e.length<=t.maxLength},t)},e.stringLength=function(t){return new e("stringLength",function(e,t){return!(null!=e&&("string"!=typeof e||null!=t.minLength&&e.length<t.minLength||null!=t.maxLength&&e.length>t.maxLength))},t)},e.string=function(){return new e("string",function(e){return null==e||"string"==typeof e})},e.guid=function(){return new e("guid",function(e){return null==e||m.isGuid(e)})},e.duration=function(){return new e("duration",function(e){return null==e||m.isDuration(e)})},e.number=function(t){return new e("number",function(e,t){return null==e||("string"==typeof e&&t&&t.allowString&&(e=parseFloat(e)),"number"==typeof e&&!isNaN(e))},t)},e.double=e.number,e.single=e.number,e.integer=function(t){return new e("integer",function(e,t){return null==e||("string"==typeof e&&t&&t.allowString&&(e=parseInt(e,10)),"number"==typeof e&&!isNaN(e)&&Math.floor(e)===e)},t)},e.int64=e.integer,e.int32=function(e){return Q("int32",-2147483648,2147483647,e)()},e.int16=function(e){return Q("int16",-32768,32767,e)()},e.byte=function(e){return Q("byte",0,255,e)()},e.bool=function(){return new e("bool",function(e){return null==e||!0===e||!1===e})},e.none=function(){return new e("none",function(e){return!0})},e.date=function(){return new e("date",function(e){if(null==e)return!0;if("string"!=typeof e)return m.isDate(e);try{return!isNaN(Date.parse(e))}catch(t){return!1}})},e.creditCard=function(t){return new e("creditCard",function(e){return null==e||""===e||"string"==typeof e&&!(!(e=e.replace(/(\-|\s)/g,""))||/\D/.test(e))&&H(e)},t)},e.regularExpression=function(t){return new e("regularExpression",function(e,t){if(null==e||""===e)return!0;if("string"!=typeof e)return!1;try{return new RegExp(t.expression).test(e)}catch(r){throw new Error("Missing or invalid expression parameter to regExp validator")}},t)},e.emailAddress=function(e){return Z("emailAddress",/^((([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])))\.?$/i,null,e)},e.phone=function(e){return Z("phone",/^((\+|(0(\d+)?[-\/.\s]?))[1-9]\d{0,2}[-\/.\s]?)?((\(\d{1,6}\)|\d{1,6})[-\/.\s]?)?(\d+[-\/.\s]?)+\d+$/,null,e)},e.url=function(e){return Z("url",/^(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})|[!\$&'\(\)\*\+,;=]|:|@)|\/|\?)*)?$/,null,e)},e.makeRegExpValidator=Z,e}();function Q(e,t,r,n){return n=n||{},t!==undefined&&(n.min=t),r!==undefined&&(n.max=r),n.messageTemplate||J.messageTemplates[e]||(J.messageTemplates[e]=m.formatString("'%displayName%' must be an integer between the values of %1 and %2",t,r)),function(){return new J(e,function(e,n){return null==e||("string"==typeof e&&n&&n.allowString&&(e=parseInt(e,0)),!("number"!=typeof e||isNaN(e)||Math.floor(e)!==e||null!=t&&e<t||null!=r&&e>r))},n)}}function Z(e,t,r,n){r&&(J.messageTemplates[e]=r);var i="string"==typeof t?new RegExp(t):t;return new J(e,function(e){return null==e||""===e||"string"==typeof e&&i.test(e)},n)}J.prototype._$typeName="Validator",globalThis.x=m.objectForEach(J,function(e,t){"function"==typeof t&&"fromJSON"!==e&&"register"!==e&&"registerFactory"!==e&&"makeRegExpValidator"!==e&&K.registerFunction(t,"Validator."+e)});var W,H=(W=[0,2,4,6,8,1,3,5,7,9],function(e){var t,r=0,n=!1,i=String(e).replace(/[^\d]/g,"");if(0===i.length)return!1;for(var a=i.length-1;a>=0;--a)t=parseInt(i.charAt(a),10),r+=(n=!n)?t:W[t];return r%10==0}),Y=function(){function e(t,r,n,i){v(t,"validator").isOptional().isInstanceOf(J).check(),v(n,"errorMessage").isNonEmptyString().check(),v(i,"key").isOptional().isNonEmptyString().check(),this.validator=t||undefined,r=r||{},this.context=r,this.errorMessage=n,this.property=r.property,this.propertyName=r.propertyName||r.property&&r.property.name,this.key=i||e.getKey(t||n,this.propertyName),this.isServerError=!1}return e.getKey=function(e,t){return("string"==typeof e?e:e.name)+(t?":"+t:"")},e}(),X=/.\d{3}$/,ee=function(e){function t(){return null!==e&&e.apply(this,arguments)||this}return r(t,e),t.getComparableFn=function(e){return e&&e.normalize?e.normalize:e===t.Time?function(e){return e&&m.durationToSeconds(e)}:function(e){return e}},t.fromEdmDataType=function(e){var r,n=e.split(".");if(n.length>1){var i=n[1];r="image"===i?t.Byte:2===n.length?t.fromName(i)||t.Undefined:t.String}return r},t.fromValue=function(e){if(m.isDate(e))return t.DateTime;switch(typeof e){case"string":return m.isGuid(e)?t.Guid:m.isDuration(e)&&e.length>3?t.Time:m.isDateString(e)?t.DateTime:t.String;case"boolean":return t.Boolean;case"number":return t.Double}return t.Undefined},t.parseTimeFromServer=function(e){return"string"==typeof e?e:e&&"Edm.Time"===e.__edmType?"PT"+Math.floor(e.ms/1e3)+"S":e},t.parseDateAsUTC=function(e){"string"==typeof e&&(e=X.test(e)?e+"Z":e);return e=new Date(Date.parse(e))},t.parseRawValue=function(e,t){return e===undefined?undefined:e?(t&&t.parseRawValue&&(e=t.parseRawValue(e)),e):e},t._resetConstants=function(){t.constants={stringPrefix:"K_",nextNumber:-1,nextNumberIncrement:-1}},t.parseDateFromServer=function(e){return t.parseDateAsUTC(e)},t.String=new t({defaultValue:"",parse:oe,fmtOData:le,getNext:te}),t.Int64=new t({defaultValue:0,isNumeric:!0,isInteger:!0,quoteJsonOData:!0,parse:ue,fmtOData:he("L"),getNext:re}),t.Int32=new t({defaultValue:0,isNumeric:!0,isInteger:!0,parse:ue,fmtOData:fe,getNext:re}),t.Int16=new t({defaultValue:0,isNumeric:!0,isInteger:!0,parse:ue,fmtOData:fe,getNext:re}),t.Byte=new t({defaultValue:0,isNumeric:!0,isInteger:!0,parse:ue,fmtOData:fe}),t.Decimal=new t({defaultValue:0,isNumeric:!0,quoteJsonOData:!0,isFloat:!0,parse:pe,fmtOData:he("m"),getNext:re}),t.Double=new t({defaultValue:0,isNumeric:!0,isFloat:!0,parse:pe,fmtOData:he("d"),getNext:re}),t.Single=new t({defaultValue:0,isNumeric:!0,isFloat:!0,parse:pe,fmtOData:he("f"),getNext:re}),t.DateTime=new t({defaultValue:new Date(1900,0,1),isDate:!0,parse:ce,parseRawValue:Te,normalize:function(e){return e&&e.getTime&&e.getTime()},fmtOData:de,getNext:ie,getConcurrencyValue:ae}),t.DateTimeOffset=new t({defaultValue:new Date(1900,0,1),isDate:!0,parse:ce,parseRawValue:Te,normalize:function(e){return e&&e.getTime&&e.getTime()},fmtOData:me,getNext:ie,getConcurrencyValue:ae}),t.Time=new t({defaultValue:"PT0S",fmtOData:ge,parseRawValue:t.parseTimeFromServer}),t.Boolean=new t({defaultValue:!1,parse:ye,fmtOData:we}),t.Guid=new t({defaultValue:"00000000-0000-0000-0000-000000000000",parse:se,fmtOData:ve,getNext:ne,parseRawValue:function(e){return e.toLowerCase()},getConcurrencyValue:m.getUuid}),t.Binary=new t({defaultValue:null,fmtOData:Ee,parseRawValue:_e}),t.Undefined=new t({defaultValue:undefined,fmtOData:Pe}),t}(a);function te(){return ee.constants.stringPrefix+re().toString()}function re(){var e=ee.constants.nextNumber;return ee.constants.nextNumber+=ee.constants.nextNumberIncrement,e}function ne(){return m.getUuid()}function ie(){return new Date}function ae(e){for(var t=new Date,r=new Date;t.getTime()===r.getTime();)r=new Date;return r}function oe(e,t){return null==e?e:e.toString()}function se(e,t){return"string"===t?e.trim().toLowerCase():e}function ue(e,t){if("string"===t){var r=e.trim();if(""===r)return null;var n=parseInt(r,10);return isNaN(n)?e:n}return"number"===t?Math.round(e):e}function pe(e,t){if("string"===t){var r=e.trim();if(""===r)return null;var n=parseFloat(r);return isNaN(n)?e:n}return e}function ce(e,t){var r;if("string"===t){var n=e.trim();return""===n?null:(r=new Date(Date.parse(n)),m.isDate(r)?r:e)}return"number"===t?(r=new Date(e),m.isDate(r)?r:e):e}function ye(e,t){if("string"===t){var r=e.trim().toLowerCase();return"false"!==r&&""!==r&&("true"===r||e)}return e}function le(e){return null==e?null:"'"+e.replace(/'/g,"''")+"'"}function fe(e){return null==e?null:"string"==typeof e?parseInt(e,10):e}function he(e){return function(t){return null==t?null:("string"==typeof t&&(t=parseFloat(t)),t+e)}}function de(e){if(null==e)return null;try{return"datetime'"+e.toISOString()+"'"}catch(t){Se("'%1' is not a valid dateTime",e)}}function me(e){if(null==e)return null;try{return"datetimeoffset'"+e.toISOString()+"'"}catch(t){Se("'%1' is not a valid dateTime",e)}}function ge(e){return null==e?null:(m.isDuration(e)||Se("'%1' is not a valid ISO 8601 duration",e),"time'"+e+"'")}function ve(e){return null==e?null:(m.isGuid(e)||Se("'%1' is not a valid guid",e),"guid'"+e+"'")}function we(e){return null==e?null:"string"==typeof e?"true"===e.trim().toLowerCase():!!e}function Ee(e){return null==e?e:"binary'"+e+"'"}function Pe(e){return e}function Se(e,t){throw e=m.formatString(e,t),new Error(e)}function Te(e){return m.isDate(e)||(e=ee.parseDateFromServer(e)),e}function _e(e){return e&&e.$value!==undefined&&(e=e.$value),e}ee.prototype._$typeName="DataType",globalThis.x=ee._resetConstants(),globalThis.x=ee.resolveSymbols(),globalThis.x=ee.getSymbols().forEach(function(e){return e.validatorCtor=function(e){switch(e){case ee.String:return J.string;case ee.Int64:return J.int64;case ee.Int32:return J.int32;case ee.Int16:return J.int16;case ee.Decimal:case ee.Double:case ee.Single:return J.number;case ee.DateTime:case ee.DateTimeOffset:return J.date;case ee.Boolean:return J.bool;case ee.Guid:return J.guid;case ee.Byte:return J.byte;case ee.Binary:return J.none;case ee.Time:return J.duration;case ee.Undefined:return J.none}}(e)});var Ne=function(e){function t(){return null!==e&&e.apply(this,arguments)||this}return r(t,e),t.prototype.isUnchanged=function(){return this===t.Unchanged},t.prototype.isAdded=function(){return this===t.Added},t.prototype.isModified=function(){return this===t.Modified},t.prototype.isDeleted=function(){return this===t.Deleted},t.prototype.isDetached=function(){return this===t.Detached},t.prototype.isUnchangedOrModified=function(){return this===t.Unchanged||this===t.Modified},t.prototype.isAddedModifiedOrDeleted=function(){return this===t.Added||this===t.Modified||this===t.Deleted},t.Unchanged=new t,t.Added=new t,t.Modified=new t,t.Deleted=new t,t.Detached=new t,t}(a);Ne.prototype._$typeName="EntityState",globalThis.x=Ne.resolveSymbols();var Ae=function(e){function t(){return null!==e&&e.apply(this,arguments)||this}return r(t,e),t.prototype.isAttach=function(){return!!this._isAttach},t.prototype.isDetach=function(){return!!this._isDetach},t.prototype.isModification=function(){return!!this._isModification},t.Attach=new t({_isAttach:!0}),t.AttachOnQuery=new t({_isAttach:!0}),t.AttachOnImport=new t({_isAttach:!0}),t.Detach=new t({_isDetach:!0}),t.MergeOnQuery=new t({_isModification:!0}),t.MergeOnImport=new t({_isModification:!0}),t.MergeOnSave=new t({_isModification:!0}),t.PropertyChange=new t({_isModification:!0}),t.EntityStateChange=new t,t.AcceptChanges=new t,t.RejectChanges=new t({_isModification:!0}),t.Clear=new t({_isDetach:!0}),t}(a);Ae.prototype._$typeName="EntityAction",globalThis.x=Ae.resolveSymbols();var Oe=function(){function e(t,r){v(t,"entityType").isInstanceOf(kt).check();var n=t.getSelfAndSubtypes();n.length>1&&(this._subtypes=n.filter(function(e){return!1===e.isAbstract})),Array.isArray(r)||(r=[r]),this.entityType=t,t.keyProperties.forEach(function(e,t){e.dataType===ee.Guid&&(r[t]=r[t]&&r[t].toLowerCase())}),this.values=r,this._keyInGroup=e.createKeyString(r)}return e.prototype.toJSON=function(){return{entityType:this.entityType.name,values:this.values}},e.fromJSON=function(t,r){return new e(r._getStructuralType(t.entityType,!0),t.values)},e.prototype.equals=function(t){return t instanceof e&&(this.entityType===t.entityType&&m.arrayEquals(this.values,t.values))},e.prototype.toString=function(e){return(e||this.entityType).name+"-"+this._keyInGroup},e.equals=function(t,r){return t instanceof e&&t.equals(r)},e.prototype._isEmpty=function(){return 0===this.values.join("").length},e.createKeyString=function(t){return t.join(e.ENTITY_KEY_DELIMITER)},e.ENTITY_KEY_DELIMITER=":::",e}();Oe.prototype._$typeName="EntityKey";var be=function(e){function t(){return null!==e&&e.apply(this,arguments)||this}return r(t,e),t.PreserveChanges=new t,t.OverwriteChanges=new t,t.SkipMerge=new t,t.Disallowed=new t,t}(a);be.prototype._$typeName="MergeStrategy",globalThis.x=be.resolveSymbols();var Ce=function(e){function t(){return null!==e&&e.apply(this,arguments)||this}return r(t,e),t.FromServer=new t,t.FromLocalCache=new t,t}(a);Ce.prototype._$typeName="FetchStrategy",globalThis.x=Ce.resolveSymbols();var xe=function(){function e(t){e._updateWithConfig(this,t)}return e.resolve=function(t){return new e(m.resolveProperties(t,["fetchStrategy","mergeStrategy","includeDeleted"]))},e.prototype.using=function(t){if(!t)return this;var r=new e(this);return t instanceof be?t={mergeStrategy:t}:t instanceof Ce&&(t={fetchStrategy:t}),e._updateWithConfig(r,t)},e.prototype.setAsDefault=function(){return m.setAsDefault(this,e)},e.prototype.toJSON=function(){return m.toJson(this,{fetchStrategy:null,mergeStrategy:null,includeDeleted:!1})},e.fromJSON=function(t){return new e({fetchStrategy:Ce.fromName(t.fetchStrategy),mergeStrategy:be.fromName(t.mergeStrategy),includeDeleted:!0===t.includeDeleted})},e._updateWithConfig=function(e,t){return t&&D(t).whereParam("fetchStrategy").isEnumOf(Ce).isOptional().whereParam("mergeStrategy").isEnumOf(be).isOptional().whereParam("includeDeleted").isBoolean().isOptional().applyAll(e),e},e.defaultInstance=new e({fetchStrategy:Ce.FromServer,mergeStrategy:be.PreserveChanges,includeDeleted:!1}),e}();xe.prototype._$typeName="QueryOptions";var Fe=function(){function e(){for(var t=[],r=0;r<arguments.length;r++)t[r]=arguments[r];if(0!==t.length)return this instanceof e?e.create.apply(e,i(t)):new(e.bind.apply(e,i([void 0],t)))}return e.create=function(){for(var t=[],r=0;r<arguments.length;r++)t[r]=arguments[r];if(0===t.length)return new e;if(1===t.length){var n=arguments[0];return Array.isArray(n)?1===n.length?new e(n[0]):Me(n):n instanceof e?n:"string"==typeof n?new Ve(n):De(n)}return Me(t)},e.prototype._validate=function(e,t){},e.and=function(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];return new je("and",e)},e.or=function(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];return new je("or",e)},e.not=function(e){return e.not()},e.prototype.and=function(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];return new je("and",ke(this,e))},e.prototype.or=function(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];return new je("or",ke(this,e))},e.prototype.not=function(){return new Re("not",this)},e.prototype.toJSON=function(){return this.toJSONExt({entityType:this._entityType})},e.prototype.toJSONExt=function(e){return this.visit(e,et)},e.prototype.toFunction=function(e){return this.visit(e,Ye)},e.prototype.toString=function(){return JSON.stringify(this)},e.prototype.visit=function(e,t){if(m.isEmpty(e))e={entityType:undefined};else if(e instanceof kt)e={entityType:e};else if(!m.hasOwnProperty(e,"entityType"))throw new Error("All visitor methods must be called with a context object containing at least an 'entityType' property");t&&(e.visitor=t);var r=(t||e.visitor)[this.visitorMethodName];if(null==r)throw new Error("Unable to locate method: "+this.visitorMethodName+" on visitor");var n=e.entityType;return!this._validate||null!=n&&this._entityType===n||(this._validate(n,e.toNameOnServer),this._entityType=n),r.call(this,e)},e.prototype._initialize=function(e,t){void 0===t&&(t={}),this.visitorMethodName=e;var r=this.aliasMap={};for(var n in t)Ie(r,n,t[n])},e.prototype._resolveOp=function(e,t){var r="string"==typeof e?e:e.operator,n=this.aliasMap[r.toLowerCase()];if(!n&&!t)throw new Error("Unable to resolve operator: "+r);return n},e}();function Me(e){var t={},r={};t[e[0]]=r;var n=e[1];return n=n.operator||n,3===e.length?r[n]=e[2]:r[n]=Me(e.splice(2)),De(t)}function De(e){if(e instanceof Fe)return e;if("object"!=typeof e)throw new Error("Unable to convert to a Predicate: "+e);var t=Object.keys(e).map(function(t){return function(e,t){if(je.prototype._resolveOp(e,!0))return new je(e,t);if(Re.prototype._resolveOp(e,!0))return new Re(e,t);if("object"!=typeof t||null==t||m.isDate(t))return new Ke("eq",e,t);if(m.hasOwnProperty(t,"value"))return new Ke("eq",e,t);if(Array.isArray(t))throw new Error("Unable to resolve predicate after the phrase: "+e);var r=e,n=Object.keys(t).map(function(e){if(qe.prototype._resolveOp(e,!0))return new qe(e,r,t[e]);if(Ke.prototype._resolveOp(e,!0))return new Ke(e,r,t[e]);if(m.hasOwnProperty(t[e],"value"))return new Ke("eq",r,t[e]);var n=m.formatString("Unable to resolve predicate after the phrase: '%1' for operator: '%2'  and value: '%3'",r,e,t[e]);throw new Error(n)});return 1===n.length?n[0]:new je("and",n)}(t,e[t])});return 1===t.length?t[0]:new je("and",t)}function ke(e,t){var r=t[0];return r instanceof Fe?r=m.arraySlice(t):Array.isArray(r)||(r=[new Fe(m.arraySlice(t))]),[e].concat(r)}function Ie(e,t,r){var n=t.toLowerCase();r.key=n,e[n]=r,r.aliases&&r.aliases.forEach(function(t){e[t.toLowerCase()]=r})}var Ve=function(e){function t(t){var r=e.call(this)||this;return r.value=t,r}return r(t,e),t}(Fe);globalThis.x=Ve.prototype._initialize("passthruPredicate");var Re=function(e){function t(t){for(var r=[],n=1;n<arguments.length;n++)r[n-1]=arguments[n];var i=e.call(this)||this;return i.op=i._resolveOp(t),i.pred=new Fe(r),i}return r(t,e),t.prototype._validate=function(e,t){this.pred._validate(e,t)},t}(Fe);globalThis.x=Re.prototype._initialize("unaryPredicate",{not:{aliases:["!","~"]}});var Ke=function(e){function t(t,r,n){var i=e.call(this)||this;return i.op=i._resolveOp(t),i.expr1Source=r,i.expr2Source=n,i}return r(t,e),t.prototype._validate=function(e,t){var r={entityType:e,usesNameOnServer:t};if(this.expr1=Ze(this.expr1Source,r),null==this.expr1)throw new Error("Unable to validate 1st expression: "+this.expr1Source);if(this.expr1 instanceof Le)throw new Error("The left hand side of a binary predicate cannot be a literal expression, it must be a valid property or functional predicate expression: "+this.expr1Source);if("in"===this.op.key&&!Array.isArray(this.expr2Source))throw new Error("The 'in' operator requires that its right hand argument be an array");var n=m.extend(r,{isRHS:!0,dataType:this.expr1.dataType});if(this.expr2=Ze(this.expr2Source,n),null==this.expr2)throw new Error("Unable to validate 2nd expression: "+this.expr2Source);null==this.expr1.dataType&&(this.expr1.dataType=this.expr2.dataType)},t}(Fe);globalThis.x=Ke.prototype._initialize("binaryPredicate",{eq:{aliases:["==","equals"]},ne:{aliases:["!=","~=","notequals"]},lt:{aliases:["<","lessthan"]},le:{aliases:["<=","lessthanorequal"]},gt:{aliases:[">","greaterthan"]},ge:{aliases:[">=","greaterthanorequal"]},startswith:{isFunction:!0},endswith:{isFunction:!0},contains:{aliases:["substringof"],isFunction:!0},"in":{}});var je=function(e){function t(t,r){var n=e.call(this)||this;return n.op=n._resolveOp(t),1===r.length&&Array.isArray(r[0])&&(r=r[0]),n.preds=r.filter(function(e){return null!=e}).map(function(e){return new Fe(e)}),1===n.preds.length?n.preds[0]:n}return r(t,e),t.prototype._validate=function(e,t){this.preds.forEach(function(r){r._validate(e,t)})},t}(Fe);globalThis.x=je.prototype._initialize("andOrPredicate",{and:{aliases:["&&"]},or:{aliases:["||"]}});var qe=function(e){function t(t,r,n){var i=e.call(this)||this;return i.op=i._resolveOp(t),i.exprSource=r,i.pred=new Fe(n),i}return r(t,e),t.prototype._validate=function(e,t){this.expr=Ze(this.exprSource,{entityType:e,usesNameOnServer:t}),(null==e||e.isAnonymous)&&(this.expr.dataType=undefined),this.pred._validate(this.expr.dataType,t)},t}(Fe);globalThis.x=qe.prototype._initialize("anyAllPredicate",{any:{aliases:["some"]},all:{aliases:["every"]}});var Be=function(){function e(e){this.visitorMethodName=e,this.visit=Fe.prototype.visit}return e.prototype._validate=function(e,t){},e}(),Le=function(e){function t(t,r,n){var i=e.call(this,"litExpr")||this,a=function(e){if(null==e)return e;if(e instanceof ee)return e;if("string"==typeof e){var t=ee.fromName(e);if(t)return t;throw new Error("Unable to resolve a dataType named: "+e)}throw new Error("The dataType parameter passed into this literal expression is not a 'DataType'"+e)}(r)||ee.fromValue(t);return a.parse?Array.isArray(t)?i.value=t.map(function(e){return a.parse(e,typeof e)}):i.value=a.parse(t,typeof t):i.value=t,i.dataType=a,i.hasExplicitDataType=!!n,i}return r(t,e),t.prototype.toString=function(){return" LitExpr - value: "+this.value.toString()+" dataType: "+this.dataType.toString()},t}(Be);var Ue=function(e){function t(t){var r=e.call(this,"propExpr")||this;return r.propertyPath=t,r}return r(t,e),t.prototype.toString=function(){return" PropExpr - "+this.propertyPath},t.prototype._validate=function(e,t){if(null!=e&&!e.isAnonymous){var r=e.getPropertiesOnPath(this.propertyPath,null,!1);if(!r){var n=m.formatString("Unable to resolve propertyPath.  EntityType: '%1'   PropertyPath: '%2'",e.name,this.propertyPath);throw new Error(n)}var i=r[r.length-1];this.dataType=i instanceof Ut?i.dataType:i.entityType}},t}(Be),ze=function(e){function t(r,n){var i=e.call(this,"fnExpr")||this;i.fnName=r,i.exprs=n;var a=t._funcMap[r];if(null==a)throw new Error("Unknown function: "+r);return i.localFn=a.fn,i.dataType=a.dataType,i}return r(t,e),t.prototype.toString=function(){var e=this.exprs.map(function(e){e.toString()}).toString();return"FnExpr - "+this.fnName+"("+e+")"},t.prototype._validate=function(e,t){this.exprs.forEach(function(r){r._validate(e,t)})},t._funcMap={toupper:{fn:function(e){return e.toUpperCase()},dataType:ee.String},tolower:{fn:function(e){return e.toLowerCase()},dataType:ee.String},substring:{fn:function(e,t,r){return e.substring(t,r)},dataType:ee.String},substringof:{fn:function(e,t){return t.indexOf(e)>=0},dataType:ee.Boolean},length:{fn:function(e){return e.length},dataType:ee.Int32},trim:{fn:function(e){return e.trim()},dataType:ee.String},concat:{fn:function(e,t){return e.concat(t)},dataType:ee.String},replace:{fn:function(e,t,r){return e.replace(t,r)},dataType:ee.String},startswith:{fn:function(e,t){return m.stringStartsWith(e,t)},dataType:ee.Boolean},endswith:{fn:function(e,t){return m.stringEndsWith(e,t)},dataType:ee.Boolean},indexof:{fn:function(e,t){return e.indexOf(t)},dataType:ee.Int32},round:{fn:function(e){return Math.round(e)},dataType:ee.Int32},ceiling:{fn:function(e){return Math.ceil(e)},dataType:ee.Int32},floor:{fn:function(e){return Math.floor(e)},dataType:ee.Int32},second:{fn:function(e){return e.getSeconds()},dataType:ee.Int32},minute:{fn:function(e){return e.getMinutes()},dataType:ee.Int32},day:{fn:function(e){return e.getDate()},dataType:ee.Int32},month:{fn:function(e){return e.getMonth()+1},dataType:ee.Int32},year:{fn:function(e){return e.getFullYear()},dataType:ee.Int32}},t}(Be),Ge=/^[a-z_][\w.$]*$/i,$e=/('[^']*'|[^,]+)/g,Je=/("[^"]*"|[^,]+)/g,Qe=String.fromCharCode(191);function Ze(e,t){var r=t.entityType;if(Array.isArray(e)){if(!t.isRHS)throw new Error("Array expressions are only permitted on the right hand side of a BinaryPredicate");return new Le(e,t.dataType)}if("string"!=typeof e){if(null==e||"object"!=typeof e||e.toISOString)return new Le(e,t.dataType);if(e.value===undefined)throw new Error("Unable to resolve an expression for: "+e+" on entityType: "+(r?r.name:"null"));return e.isProperty?new Ue(e.value):new Le(e.value,e.dataType||t.dataType,!0)}if(t.isRHS)return null==r||r.isAnonymous?new Le(e,t.dataType):He(e,t);for(var n=/\([^()]*\)/,i=void 0,a=[],o=0;i=n.exec(e);){var s=i[0];a.push(s);var u=Qe+o++;e=e.replace(s,u)}var p=We(e,a,t);return p._validate(r,t.usesNameOnServer),p}function We(e,t,r){var n=e.split(Qe);return 1===n.length?He(n[0],r):function(e,t,r,n){try{var i=t[0].trim().toLowerCase(),a=r[t[1]].trim();"("===a.substr(0,1)&&(a=a.substr(1,a.length-2));var o=e.indexOf("'")>=0?$e:Je,s=a.match(o),u=m.extend({},n);u.dataType=ee.Undefined,u.isFnArg=!0;var p=s.map(function(e){return We(e,r,u)});return new ze(i,p)}catch(c){throw c}}(e,n,t,r)}function He(e,t){var r=(e=e.trim()).substr(0,1);if(("'"===r||'"'===r)&&e.length>1&&e.substr(e.length-1)===r){var n=e.substr(1,e.length-2);return new Le(n,t.dataType||ee.String)}var i=t.entityType;return null==i||i.isAnonymous?new Ue(e):Ge.test(e)&&null!=i.getPropertiesOnPath(e,null,!1)?new Ue(e):new Le(e,t.dataType)}var Ye={isExtended:!1,passthruPredicate:function(){throw new Error("Cannot execute an PassthruPredicate expression against the local cache: "+this.value)},unaryPredicate:function(e){var t=this.pred.visit(e);switch(this.op.key){case"not":return function(e){return!t(e)};default:throw new Error("Invalid unary operator:"+this.op.key)}},binaryPredicate:function(e){var t=this.expr1.visit(e),r=this.expr2.visit(e),n=function(e,t,r){var n,i=e.op,a=ee.getComparableFn(t);switch(i.key){case"eq":n=function(e,t){return e&&"string"==typeof e?Xe(e,t,r):a(e)===a(t)};break;case"ne":n=function(e,t){return e&&"string"==typeof e?!Xe(e,t,r):a(e)!==a(t)};break;case"gt":n=function(e,t){return a(e)>a(t)};break;case"ge":n=function(e,t){return a(e)>=a(t)};break;case"lt":n=function(e,t){return a(e)<a(t)};break;case"le":n=function(e,t){return a(e)<=a(t)};break;case"startswith":n=function(e,t){return function(e,t,r){return r.isCaseSensitive||(e=(e||"").toLowerCase(),t=(t||"").toLowerCase()),m.stringStartsWith(e,t)}(e,t,r)};break;case"endswith":n=function(e,t){return function(e,t,r){return r.isCaseSensitive||(e=(e||"").toLowerCase(),t=(t||"").toLowerCase()),m.stringEndsWith(e,t)}(e,t,r)};break;case"contains":n=function(e,t){return function(e,t,r){return r.isCaseSensitive||(e=(e||"").toLowerCase(),t=(t||"").toLowerCase()),e.indexOf(t)>=0}(e,t,r)};break;case"in":n=function(e,t){return e=a(e),(t=t.map(function(e){return a(e)})).indexOf(e)>=0};break;default:return null}return n}(this,this.expr1.dataType||this.expr2.dataType,e.entityType.metadataStore.localQueryComparisonOptions);if(null==n)throw new Error("Invalid binaryPredicate operator:"+this.op.key);return function(e){return n(t(e),r(e))}},andOrPredicate:function(e){var t=this.preds.map(function(t){return t.visit(e)});switch(this.op.key){case"and":return function(e){return t.reduce(function(t,r){return t&&r(e)},!0)};case"or":return function(e){return t.reduce(function(t,r){return t||r(e)},!1)};default:throw new Error("Invalid boolean operator:"+this.op.key)}},anyAllPredicate:function(e){var t=this.expr.visit(e),r=m.extend({},e);r.entityType=this.expr.dataType;var n=this.pred.visit(r),i=function(e){switch(e.key){case"any":return function(e,t){return e.some(function(e){return t(e)})};case"all":return function(e,t){return e.every(function(e){return t(e)})};default:throw new Error("Unknown operator: "+e.key)}}(this.op);return function(e){return i(t(e),n)}},litExpr:function(){var e=this.value;return function(t){return e}},propExpr:function(){var e=this.propertyPath,t=e.split(".");return 1===t.length?function(t){return t.getProperty(e)}:function(e){return lt.getPropertyPathValue(e,t)}},fnExpr:function(e){var t=this.exprs.map(function(t){return t.visit(e)}),r=this;return function(e){var n=t.map(function(t){return t(e)});return r.localFn.apply(null,n)}}};function Xe(e,t,r){return null!=t&&("string"!=typeof t&&(t=t.toString()),r.usesSql92CompliantStringComparison&&(e=(e||"").trim(),t=(t||"").trim()),r.isCaseSensitive||(e=(e||"").toLowerCase(),t=(t||"").toLowerCase()),e===t)}var et={passthruPredicate:function(){return this.value},unaryPredicate:function(e){var t=this.pred.visit(e),r={};return r[this.op.key]=t,r},binaryPredicate:function(e){var t=this.expr1.visit(e),r=this.expr2.visit(e),n={};if(this.expr2 instanceof Ue&&(r={value:r,isProperty:!0}),"eq"===this.op.key)n[t]=r;else{var i={};n[t]=i,i[this.op.key]=r}return n},andOrPredicate:function(e){var t,r=this.preds.map(function(t){return t.visit(e)});return r&&r.length?("and"!==this.op.key||2!==r.length||r.some(function(e){return"string"==typeof e})||(t=r.reduce(tt)),null==t&&((t={})[this.op.key]=r),t):{}},anyAllPredicate:function(e){var t=this.expr.visit(e),r=m.extend({},e);r.entityType=this.expr.dataType;var n=this.pred.visit(r),i={},a={};return a[this.op.key]=n,i[t]=a,i},litExpr:function(e){return this.hasExplicitDataType||e.useExplicitDataType?{value:this.value,dataType:this.dataType.name}:this.value},propExpr:function(e){return e.toNameOnServer?e.entityType.clientPropertyPathToServer(this.propertyPath):this.propertyPath},fnExpr:function(e){var t=this.exprs.map(function(t){return t.visit(e)});return this.fnName+"("+t.join(",")+")"}};function tt(e,t){return Object.keys(t).every(function(r){if(e.hasOwnProperty(r)){if("object"!=typeof t[r])return!1;if(null==tt(e[r],t[r]))return!1}else e[r]=t[r];return!0})?e:null}var rt=function(){function e(e){if(null!=e&&"string"!=typeof e)return t=this,r=e,m.toJson(r,{"resourceName,from":null,"resultEntityType,toType":null,"wherePredicate,where":function(e){return e?new Fe(e):undefined},"orderByClause,orderBy":function(e){return e?new ut(e):undefined},"selectClause,select":function(e){return e?new ct(e):undefined},"expandClause,expand":function(e){return e?new yt(e):undefined},"skipCount,skip":null,"takeCount,take":null,parameters:function(e){return m.isEmpty(e)?undefined:e},"inlineCountEnabled,inlineCount":!1,"noTrackingEnabled,noTracking":!1,queryOptions:function(e){return e?xe.fromJSON(e):undefined}},t),t;var t,r;this.resourceName=e,this.fromEntityType=undefined,this.wherePredicate=undefined,this.orderByClause=undefined,this.selectClause=undefined,this.skipCount=undefined,this.takeCount=undefined,this.expandClause=undefined,this.parameters={},this.inlineCountEnabled=!1,this.noTrackingEnabled=!1,this.entityManager=undefined}return e.prototype.from=function(e){return v(e,"resourceName").isString().check(),nt(this,"resourceName",e)},e.from=function(t){return v(t,"resourceName").isString().check(),new e(t)},e.prototype.toType=function(e){return v(e,"entityType").isString().or().isInstanceOf(kt).check(),nt(this,"resultEntityType",e)},e.prototype.where=function(){for(var e,t=[],r=0;r<arguments.length;r++)t[r]=arguments[r];return t.length>0&&null!=t[0]&&(e=Fe.create.apply(Fe,i(t)),this.fromEntityType&&e._validate(this.fromEntityType),this.wherePredicate&&(e=this.wherePredicate.and(e))),nt(this,"wherePredicate",e)},e.prototype.orderBy=function(e,t){var r=null==e?null:new ut(it(e),t);return this.orderByClause&&r&&(r=new ut([this.orderByClause,r])),nt(this,"orderByClause",r)},e.prototype.orderByDesc=function(e){return this.orderBy(e,!0)},e.prototype.select=function(e){return nt(this,"selectClause",null==e?null:new ct(it(e)))},e.prototype.skip=function(e){return v(e,"count").isOptional().isNumber().check(),nt(this,"skipCount",null==e?null:e)},e.prototype.top=function(e){return this.take(e)},e.prototype.take=function(e){return v(e,"count").isOptional().isNumber().check(),nt(this,"takeCount",null==e?null:e)},e.prototype.expand=function(e){return nt(this,"expandClause",null==e?null:new yt(it(e)))},e.prototype.withParameters=function(e){return v(e,"parameters").isObject().check(),nt(this,"parameters",e)},e.prototype.inlineCount=function(e){return v(e,"enabled").isBoolean().isOptional().check(),nt(this,"inlineCountEnabled",e=e===undefined||!!e)},e.prototype.useNameOnServer=function(e){return v(e,"usesNameOnServer").isBoolean().isOptional().check(),nt(this,"usesNameOnServer",e=e===undefined||!!e)},e.prototype.noTracking=function(e){return v(e,"enabled").isBoolean().isOptional().check(),nt(this,"noTrackingEnabled",e=e===undefined||!!e)},e.prototype.using=function(e){if(!e)return this;var t=nt(this);return function r(e,t,n,i){var o=n._$typeName||n instanceof a&&n.constructor.name;var s=o&&o.substr(0,1).toLowerCase()+o.substr(1);if(i&&s!==i)throw new Error("Invalid value for property: "+i);if(s){var u=t[s];if(u===undefined)throw new Error("Invalid config property: "+s);null===u?e[s]=n:u(e,n)}else m.objectForEach(n,function(n,i){r(e,t,i,n)})}(t,{entityManager:null,dataService:null,queryOptions:null,fetchStrategy:function(e,t){e.queryOptions=(e.queryOptions||new xe).using(t)},mergeStrategy:function(e,t){e.queryOptions=(e.queryOptions||new xe).using(t)},jsonResultsAdapter:function(e,t){e.dataService=(e.dataService||new j).using({jsonResultsAdapter:t})}},e),t},e.prototype.execute=function(e,t){if(!this.entityManager)throw new Error("An EntityQuery must have its EntityManager property set before calling 'execute'");return this.entityManager.executeQuery(this,e,t)},e.prototype.executeLocally=function(){if(!this.entityManager)throw new Error("An EntityQuery must have its EntityManager property set before calling 'executeLocally'");return this.entityManager.executeQueryLocally(this)},e.prototype.toJSON=function(){return this.toJSONExt()},e.prototype.toJSONExt=function(e){(e=e||{}).entityType=e.entityType||this.fromEntityType,e.propertyPathFn=e.toNameOnServer?e.entityType.clientPropertyPathToServer.bind(e.entityType):m.identity;var t=function(t){return t?t.toJSONExt(e):undefined};return m.toJson(this,{"from,resourceName":null,"toType,resultEntityType":function(e){return e?"string"==typeof e?e:e.name:undefined},"where,wherePredicate":t,"orderBy,orderByClause":t,"select,selectClause":t,"expand,expandClause":t,"skip,skipCount":null,"take,takeCount":null,parameters:function(e){return m.isEmpty(e)?undefined:e},"inlineCount,inlineCountEnabled":!1,"noTracking,noTrackingEnabled":!1,queryOptions:null})},e.fromEntities=function(t){v(t,"entities").isEntity().or().isNonEmptyArray().isEntity().check();var r=Array.isArray(t)?t:[t],n=r[0],i=n.entityType;if(r.some(function(e){return e.entityType!==i}))throw new Error("All 'fromEntities' must be the same type; at least one is not of type "+i.name);var a=new e(i.defaultResourceName),o=r.map(function(e){return function(e){var t=e.entityType.keyProperties.map(function(t){return Fe.create(t.name,ot.Equals,e.getProperty(t.name))});return Fe.and(t)}(e)}),s=Fe.or(o);a=a.where(s);var u=n.entityAspect.entityManager;return u&&(a=a.using(u)),a},e.fromEntityKey=function(t){v(t,"entityKey").isInstanceOf(Oe).check();var r=new e(t.entityType.defaultResourceName),n=at(t);return r=r.where(n).toType(t.entityType)},e.prototype._getFromEntityType=function(e,t){var r=this.fromEntityType;if(r)return r;var n=this.resourceName;if(!n)throw new Error("There is no resourceName for this query");if(e.isEmpty()){if(t)throw new Error("There is no metadata available for this query. Are you querying the local cache before you've fetched metadata?");return undefined}var i=e.getEntityTypeNameForResourceName(n);if(!(r=i?e._getStructuralType(i):this._getToEntityType(e,!0))){if(t)throw new Error(m.formatString("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.",n));return undefined}return this.fromEntityType=r,r},e.prototype._getToEntityType=function(e,t){return this.resultEntityType instanceof kt?this.resultEntityType:this.resultEntityType?(this.resultEntityType=e._getStructuralType(this.resultEntityType,!1),this.resultEntityType):t||this.selectClause?undefined:void this._getFromEntityType(e,!1)},e.prototype._toUri=function(e){return j.resolve([e.dataService]).uriBuilder.buildUri(this,e.metadataStore)},e.fromEntityNavigation=function(t,r){v(t,"entity").isEntity().check();var n=t.entityType._checkNavProperty(r),i=new e(n.entityType.defaultResourceName),a=function(e,t){if(t.isScalar){if(0===t.foreignKeyNames.length)return null;var r=t.foreignKeyNames.map(function(t){return e.getProperty(t)}),n=new Oe(t.entityType,r);return at(n)}var i=t.inverse,a=i?i.foreignKeyNames:t.invForeignKeyNames;if(0===a.length)return null;var o=e.entityAspect.getKey().values,s=m.arrayZip(a,o,function(e,t){return Fe.create(e,ot.Equals,t)});return Fe.and(s)}(t,n);if(null==a)throw new Error("Unable to create a NavigationQuery for navigationProperty: "+n.name);i=i.where(a);var o=t.entityAspect.entityManager;return o?i.using(o):i},e}();function nt(e,t,r){if(t&&e[t]===r)return e;var n=m.extend(new rt,e,["resourceName","fromEntityType","wherePredicate","orderByClause","selectClause","skipCount","takeCount","expandClause","inlineCountEnabled","noTrackingEnabled","usesNameOnServer","queryOptions","entityManager","dataService","resultEntityType"]);return n.parameters=m.extend({},e.parameters),t&&(n[t]=r),n}function it(e){return v(e,"propertyPaths").isOptional().isString().or().isArray().isString().check(),"string"==typeof e&&(e=e.split(",")),e=e.map(function(e){return e.trim()})}function at(e){var t=e.entityType.keyProperties,r=m.arrayZip(t,e.values,function(e,t){return Fe.create(e.name,ot.Equals,t)});return Fe.and(r)}rt.prototype._$typeName="EntityQuery";var ot=function(e){function t(){return null!==e&&e.apply(this,arguments)||this}return r(t,e),t.Equals=new t({operator:"eq"}),t.NotEquals=new t({operator:"ne"}),t.GreaterThan=new t({operator:"gt"}),t.LessThan=new t({operator:"lt"}),t.GreaterThanOrEqual=new t({operator:"ge"}),t.LessThanOrEqual=new t({operator:"le"}),t.Contains=new t({operator:"contains"}),t.StartsWith=new t({operator:"startswith"}),t.EndsWith=new t({operator:"endswith"}),t.Any=new t({operator:"any"}),t.All=new t({operator:"all"}),t.In=new t({operator:"in"}),t.IsTypeOf=new t({operator:"isof"}),t}(a);ot.prototype._$typeName="FilterQueryOp",globalThis.x=ot.resolveSymbols();var st=function(e){function t(){return null!==e&&e.apply(this,arguments)||this}return r(t,e),t.And=new t({operator:"and"}),t.Or=new t({operator:"or"}),t.Not=new t({operator:"not"}),t}(a);st.prototype._$typeName="BooleanQueryOp",globalThis.x=st.resolveSymbols();var ut=function(){function e(t,r){if(0===t.length)throw new Error("OrderByClause cannot be empty");if(t[0]instanceof e){var n=t;this.items=m.arrayFlatMap(n,function(e){return e.items})}else this.items=t.map(function(e){return new pt(e,r)})}return e.prototype.validate=function(e){null==e||e.isAnonymous||this.items.forEach(function(t){t.validate(e)})},e.prototype.getComparer=function(e){var t=this.items.map(function(t){return t.getComparer(e)});return function(e,r){for(var n=0;n<t.length;n++){var i=t[n](e,r);if(0!==i)return i}return 0}},e.prototype.toJSONExt=function(e){return this.items.map(function(t){return e.propertyPathFn(t.propertyPath)+(t.isDesc?" desc":"")})},e}(),pt=function(){function e(e,t){if("string"!=typeof e)throw new Error("propertyPath is not a string");var r=(e=e.trim()).split(" ");if(r.length>1&&null==t&&(!(t=m.stringStartsWith(r[1].toLowerCase(),"desc"))&&!m.stringStartsWith(r[1].toLowerCase(),"asc")))throw new Error("the second word in the propertyPath must begin with 'desc' or 'asc'");this.propertyPath=r[0],this.isDesc=t||!1}return e.prototype.validate=function(e){if(null!=e&&!e.isAnonymous)return this.lastProperty=e.getProperty(this.propertyPath,!0),this.lastProperty},e.prototype.getComparer=function(e){var t,r;this.lastProperty||this.validate(e),this.lastProperty&&(t=this.lastProperty.dataType,r=this.lastProperty.parentType.metadataStore.localQueryComparisonOptions.isCaseSensitive);var n=this.propertyPath,i=this.isDesc;return function(e,a){var o=lt.getPropertyPathValue(e,n),s=lt.getPropertyPathValue(a,n),u=t||o&&ee.fromValue(o)||ee.fromValue(s);if(u===ee.String)r?(o=o||"",s=s||""):(o=(o||"").toLowerCase(),s=(s||"").toLowerCase());else{var p=ee.getComparableFn(u);o=p(o),s=p(s)}return o===s?0:o>s||s===undefined?i?-1:1:i?1:-1}},e}(),ct=function(){function e(e){this.propertyPaths=e,this._pathNames=e.map(function(e){return e.replace(".","_")})}return e.prototype.validate=function(e){null==e||e.isAnonymous||this.propertyPaths.forEach(function(t){e.getProperty(t,!0)})},e.prototype.toFunction=function(){var e=this;return function(t){var r={};return e.propertyPaths.forEach(function(n,i){r[e._pathNames[i]]=lt.getPropertyPathValue(t,n)}),r}},e.prototype.toJSONExt=function(e){return this.propertyPaths.map(function(t){return e.propertyPathFn(t)})},e}(),yt=function(){function e(e){this.propertyPaths=e}return e.prototype.toJSONExt=function(e){return this.propertyPaths.map(function(t){return e.propertyPathFn(t)})},e}(),lt=function(){function e(e){if(this.setUnchanged=function(){return this.setEntityState(Ne.Unchanged)},this.setModified=function(){return this.setEntityState(Ne.Modified)},this.setDeleted=function(){return this.setEntityState(Ne.Deleted)},this.setDetached=function(){return this.setEntityState(Ne.Detached)},this.entity=e,this.entityGroup=undefined,this.entityManager=undefined,this.entityState=Ne.Detached,this.isBeingSaved=!1,this.originalValues={},this.hasValidationErrors=!1,this._validationErrors={},this.validationErrorsChanged=new I("validationErrorsChanged",this),this.propertyChanged=new I("propertyChanged",this),null!=e){e.entityAspect=this;var t=e.entityType||e._$entityType;if(!t){var r=e.prototype._$typeName;throw r?new Error("Metadata for this entityType has not yet been resolved: "+r):new Error("This entity is not registered as a valid EntityType")}var n=t.getEntityCtor();K.interfaceRegistry.modelLibrary.getDefaultInstance().startTracking(e,n.prototype)}}return e.isEntity=function(e){return null!=e.entityAspect},e.getPropertyPathValue=function(e,t){var r=Array.isArray(t)?t:t.split(".");if(1===r.length)return e.getProperty(t);var n=e;return r.some(function(e){return null==(n=n.getProperty(e))}),n},e.prototype.getKey=function(e){if(void 0===e&&(e=!1),(e=v(e,"forceRefresh").isBoolean().isOptional().check(!1))||!this._entityKey){var t=this.entity.entityType,r=t.keyProperties.map(function(e){return this.entity.getProperty(e.name)},this);this._entityKey=new Oe(t,r)}return this._entityKey},e.prototype.acceptChanges=function(){if(this.entity){this._checkOperation("acceptChanges");var e=this.entityManager;this.entityState.isDeleted()?e.detachEntity(this.entity):this.setUnchanged(),e.entityChanged.publish({entityAction:Ae.AcceptChanges,entity:this.entity})}},e.prototype.rejectChanges=function(){this._checkOperation("rejectChanges");var e=this.entity,t=this.entityManager;m.using(t,"isRejectingChanges",!0,function(){ft(e)}),this.entityState.isAdded()?(t.detachEntity(e),t._notifyStateChange(e,!1)):(this.entityState.isDeleted()&&t._linkRelatedEntities(e),this.setUnchanged(),this.propertyChanged.publish({entity:e,propertyName:null}),t.entityChanged.publish({entityAction:Ae.RejectChanges,entity:e}))},e.prototype.getPropertyPath=function(e){return e},e.prototype.setAdded=function(){return this.setEntityState(Ne.Added)},e.prototype.setEntityState=function(e){if(this.entityState===e)return!1;if(this._checkOperation("setEntityState"),this.entityState.isDetached())throw new Error("You cannot set the 'entityState' of an entity when it is detached - except by first attaching it to an EntityManager");var t=this.entity,r=this.entityManager,n=!0;if(e===Ne.Unchanged)wt(t),delete this.hasTempKey,n=!1;else if(e===Ne.Added)wt(t);else if(e===Ne.Deleted){if(this.entityState.isAdded())return this.setEntityState(Ne.Detached),!0;this.entityState=Ne.Deleted,ht(t,Ne.Deleted)}else if(e===Ne.Modified);else if(e===Ne.Detached){var i=this.entityGroup;if(!i)return!1;i.detachEntity(t),this.entityState=e,ht(t,Ne.Detached),this._detach(),r.entityChanged.publish({entityAction:Ae.Detach,entity:t}),n=!1}return this.entityState=e,r._notifyStateChange(t,n),!0},e.prototype.loadNavigationProperty=function(e,t,r){var n=this,i=this.entity,a=i.entityType._checkNavProperty(e),o=rt.fromEntityNavigation(i,a);return i.entityAspect.entityManager.executeQuery(o).then(function(e){return n._markAsLoaded(a.name),t&&t(e),Promise.resolve(e)},function(e){return r&&r(e),Promise.reject(e)})},e.prototype.markNavigationPropertyAsLoaded=function(e){if(this.entity){var t=this.entity.entityType._checkNavProperty(e);this._markAsLoaded(t.name)}},e.prototype.isNavigationPropertyLoaded=function(e){if(this.entity){var t=this.entity.entityType._checkNavProperty(e);return!(!t.isScalar||null==this.entity.getProperty(t.name))||this._loadedNps&&this._loadedNps.indexOf(t.name)>=0}},e.prototype._markAsLoaded=function(e){this._loadedNps=this._loadedNps||[],m.arrayAddItemUnique(this._loadedNps,e)},e.prototype.validateEntity=function(){var e=!0;return this._processValidationOpAndPublish(function(t){e=gt(t.entity)}),e},e.prototype.validateProperty=function(e,t){var r=this.getPropertyValue(e);return r&&r.complexAspect?gt(r):((t=t||{}).entity=this.entity,"string"==typeof e?(t.property=this.entity.entityType.getProperty(e,!0),t.propertyName=e):(t.property=e,t.propertyName=e.name),this._validateProperty(r,t))},e.prototype.getValidationErrors=function(e){v(e,"property").isOptional().isEntityProperty().or().isString().check();var t=m.getOwnPropertyValues(this._validationErrors);if(e){var r="string"==typeof e?e:e.name;t=t.filter(function(e){return e.property&&(e.property.name===r||-1!==r.indexOf(".")&&e.propertyName===r)})}return t},e.prototype.addValidationError=function(e){v(e,"validationError").isInstanceOf(Y).check(),this._processValidationOpAndPublish(function(t){t._addValidationError(e)})},e.prototype.removeValidationError=function(e){v(e,"validationErrorOrKey").isString().or().isInstanceOf(Y).or().isInstanceOf(J).check();var t="string"==typeof e?e:e.key;this._processValidationOpAndPublish(function(e){e._removeValidationError(t)})},e.prototype.clearValidationErrors=function(){this._processValidationOpAndPublish(function(e){m.objectForEach(e._validationErrors,function(t,r){r&&(delete e._validationErrors[t],e._pendingValidationResult.removed.push(r))}),e.hasValidationErrors=!m.isEmpty(e._validationErrors)})},e.prototype.getParentKey=function(e){if(!this.entity)return null;var t=e.foreignKeyNames;if(0===t.length)return null;var r=this,n=t.map(function(e){return r.entity.getProperty(e)});return new Oe(e.entityType,n)},e.prototype.getPropertyValue=function(e){var t;if(v(e,"property").isString().or().isEntityProperty().check(),"string"==typeof e){var r=e.trim().split("."),n=r.shift();for(t=(t=this.entity).getProperty(n);r.length>0;)n=r.shift(),t=t.getProperty(n)}else{if(!(e.parentType instanceof kt))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 ");t=this.entity.getProperty(e.name)}return t},e.prototype._checkOperation=function(e){if(this.isBeingSaved)throw new Error("Cannot perform a '"+e+"' on an entity that is in the process of being saved");return this},e.prototype._detach=function(){this.entityGroup=undefined,this.entityManager=undefined,this.entityState=Ne.Detached,this.originalValues={},this._validationErrors={},this.hasValidationErrors=!1,this.validationErrorsChanged.clear(),this.propertyChanged.clear()},e.prototype._validateProperty=function(e,t){var r=!0;return this._processValidationOpAndPublish(function(n){t.property.getAllValidators().forEach(function(i){r=mt(n,i,e,t)&&r})}),r},e.prototype._processValidationOpAndPublish=function(e){if(this._pendingValidationResult)e(this);else try{this._pendingValidationResult={entity:this.entity,added:[],removed:[]},e(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=undefined}},e.prototype._addValidationError=function(e){this._validationErrors[e.key]=e,this.hasValidationErrors=!0,this._pendingValidationResult.added.push(e)},e.prototype._removeValidationError=function(e){var t=this._validationErrors[e];t&&(delete this._validationErrors[e],this.hasValidationErrors=!m.isEmpty(this._validationErrors),this._pendingValidationResult.removed.push(t))},e._nullInstance=new e,e}();function ft(e){var t=e.entityAspect||e.complexAspect,r=e.entityType||e.complexType,n=t.originalValues;for(var i in n)e.setProperty(i,n[i]);r.complexProperties.forEach(function(t){var r=e.getProperty(t.name);t.isScalar?ft(r):(r._rejectChanges(),r.forEach(ft))})}function ht(e,t){t.isDeleted()?dt(e):m.using(e.entityAspect.entityManager,"isLoading",!0,function(){dt(e)})}function dt(e){e.entityType.navigationProperties.forEach(function(t){var r=t.inverse,n=e.getProperty(t.name);if(t.isScalar){if(n){if(r)if(r.isScalar)n.setProperty(r.name,null);else{var i=n.getProperty(r.name);i.length&&m.arrayRemoveItem(i,e)}e.setProperty(t.name,null)}}else null!=r&&n.slice(0).forEach(function(e){r.isScalar&&e.setProperty(r.name,null)}),n.length=0})}function mt(e,t,r,n){var i=t.validate(r,n);if(i)return e._addValidationError(i),!1;var a=Y.getKey(t,n?n.propertyName:null);return e._removeValidationError(a),!0}function gt(e,t){var r=!0,n=e.entityType||e.complexType,i=e.entityAspect||e.complexAspect,a=e.entityAspect||e.complexAspect.getEntityAspect(),o={entity:a.entity};return t!==undefined&&(o.index=t),n.getProperties().forEach(function(t){var n=e.getProperty(t.name);t.getAllValidators().length>0&&(o.property=t,o.propertyName=i.getPropertyPath(t.name),r=a._validateProperty(n,o)&&r),t.isComplexProperty&&(r=t.isScalar?gt(n)&&r:n.reduce(function(e,t,r){return gt(t,r)&&e},r))}),n.getAllValidators().forEach(function(t){r=mt(a,t,e)&&r}),r}I.bubbleEvent(lt.prototype,function(){return this.entityManager});var vt=function(){function e(t,r,n){if(!t)throw new Error("The  ComplexAspect ctor requires an entity as its only argument.");if(t.complexAspect)return t.complexAspect;if(!(this instanceof e))return new e(t,r,n);this.complexObject=t,t.complexAspect=this,this.originalValues={},null!=r&&(this.parent=r,this.parentProperty=n);var i=t.complexType;if(!i){var a=t.prototype._$typeName;throw a?new Error("Metadata for this complexType has not yet been resolved: "+a):new Error("This entity is not registered as a valid ComplexType")}var o=i.getCtor();K.interfaceRegistry.modelLibrary.getDefaultInstance().startTracking(t,o.prototype)}return e.prototype.getEntityAspect=function(){var e=this.parent;if(!e)return new lt;for(var t=e.entityAspect;e&&!t;)t=(e=e.complexAspect&&e.complexAspect.parent)&&e.entityAspect;return t||new lt},e.prototype.getPropertyPath=function(e){var t=this.parent;return t?(t.complexAspect||t.entityAspect).getPropertyPath(this.parentProperty.name+"."+e):null},e}();function wt(e){(e.entityAspect||e.complexAspect).originalValues={},(e.entityType||e.complexType).complexProperties.forEach(function(t){var r=e.getProperty(t.name);t.isScalar?wt(r):(r._acceptChanges(),r.forEach(wt))})}var Et=function(){function e(e){D(e||{}).whereParam("name").isOptional().isString().whereParam("serverPropertyNameToClient").isFunction().whereParam("clientPropertyNameToServer").isFunction().applyAll(this),this.name||(this.name=m.getUuid()),K._storeObject(this,"NamingConvention",this.name)}return e.prototype.setAsDefault=function(){return m.setAsDefault(this,e)},e.none=new e({name:"noChange",serverPropertyNameToClient:function(e){return e},clientPropertyNameToServer:function(e){return e}}),e.camelCase=new e({name:"camelCase",serverPropertyNameToClient:function(e){return e.substr(0,1).toLowerCase()+e.substr(1)},clientPropertyNameToServer:function(e){return e.substr(0,1).toUpperCase()+e.substr(1)}}),e.defaultInstance=new e(e.none),e}();function Pt(e,t,r,n,i){var a=t.key?m.toArray(t.key.propertyRef).map(m.pluck("name")):[];m.toArray(t.property).forEach(function(t){St(e,t,r,a)}),m.toArray(t.navigationProperty).forEach(function(t){!function(e,t,r,n){var i=function(e,t,r){var n=_t(e.relationship,t),i=n.namespace,a=m.arrayFirst(r,function(e){return e.namespace===i});if(!a)return null;var o=n.shortTypeName,s=a.association;if(!s)return null;Array.isArray(s)||(s=[s]);return m.arrayFirst(s,function(e){return e.name===o})}(t,r,n);if(!i)throw new Error("Unable to resolve Foreign Key Association: "+t.relationship);var a=m.arrayFirst(i.end,function(e){return e.role===t.toRole}),o="*"!==a.multiplicity,s=_t(a.type,r).typeName,u=i.referentialConstraint;if(!u&&"*"===i.end[0].multiplicity&&"*"===i.end[1].multiplicity)return;var p={nameOnServer:t.name,entityTypeName:s,isScalar:o,associationName:i.name};if(u){var c=u.principal,y=u.dependent,l=m.toArray(y.propertyRef),f=l.map(m.pluck("name"));t.fromRole===c.role?p.invForeignKeyNamesOnServer=f:p.foreignKeyNamesOnServer=f}var h=new zt(p);e._addPropertyCore(h)}(e,t,r,n)}),i.addEntityType(e),e.defaultResourceName=i._entityTypeResourceMap[e.name];var o=i._deferredTypes,s=o[e.name];s&&(s.forEach(function(e){Pt(e.entityType,e.csdlEntityType,r,n,i)}),delete o[e.name])}function St(e,t,r,n){var i,a=t.type.split(".");return"Edm"===a[0]&&2===a.length?i=Tt(e,t,n):!function(e,t){return t.enumType?function(e,t){var r=m.toArray(t.enumType),n=e.type.split("."),i=n[n.length-1];return r.some(function(e){return e.name===i})}(e,t):!!t.extensions&&function(e,t){var r=t.extensions.filter(function(e){return"EnumType"===e.name}),n=e.type.split("."),i=n[n.length-1];return r.some(function(e){return e.attributes.some(function(e){return"Name"===e.name&&e.value===i})})}(e,t)}(t,r)?i=function(e,t,r){var n=_t(t.type,r).typeName;return new Ut({nameOnServer:t.name,complexTypeName:n,isNullable:!1})}(0,t,r):(i=Tt(e,t,n))&&(i.enumType=t.type),i&&(e._addPropertyCore(i),function(e){var t;e.isNullable||e.validators.push(J.required());if(e.isComplexProperty)return;if(e.dataType===ee.String)if(e.maxLength){var r={maxLength:e.maxLength};t=J.maxLength(r)}else t=J.string();else{var n=e.dataType.validatorCtor;if(!n)return;t=n()}e.validators.push(t)}(i)),i}function Tt(e,t,r){var n=ee.fromEdmDataType(t.type);if(null==n)return e.warnings.push("Unable to recognize DataType for property: "+t.name+" DateType: "+t.type),undefined;var i="true"===t.nullable||null==t.nullable,a=null!=r&&r.indexOf(t.name)>=0;a&&e instanceof kt&&e.autoGeneratedKeyType===$t.None&&function(e){var t=m.arrayFirst(Object.keys(e),function(e){return e.indexOf("StoreGeneratedPattern")>=0});if(t)return"Identity"===e[t];var r=e.extensions;if(!r)return!1;var n=m.arrayFirst(r,function(e){return"StoreGeneratedPattern"===e.name&&"Identity"===e.value});return!!n}(t)&&(e.autoGeneratedKeyType=$t.Identity);var o=t.maxLength;o=null==o||"Max"===o?null:parseInt(o,10);var s=new Ut({nameOnServer:t.name,dataType:n,isNullable:i,isPartOfKey:a,maxLength:o,defaultValue:t.defaultValue,concurrencyMode:t.concurrencyMode});return n===ee.Undefined&&(s.rawTypeName=t.type),s}function _t(e,t){var r=xt.parseTypeName(e);if(t&&t.cSpaceOSpaceMapping){var n=Nt(r.shortTypeName,t);n&&(r=xt.makeTypeHash(r.shortTypeName,n))}return r}function Nt(e,t){var r,n=t.cSpaceOSpaceMapping;if(n){var i=n[t.namespace+"."+e];if(r=i&&i.substr(0,i.length-(e.length+1)))return r}return t.entityType||"Default"!==t.namespace?t.namespace:null}Et.prototype._$typeName="NamingConvention";var At={parse:function(e,t,r){e._entityTypeResourceMap={},(t=m.toArray(t)).forEach(function(r){if(r.cSpaceOSpaceMapping){var n=JSON.parse(r.cSpaceOSpaceMapping),i={};n.forEach(function(e){i[e[0]]=e[1]}),r.cSpaceOSpaceMapping=i}r.entityContainer&&m.toArray(r.entityContainer).forEach(function(t){m.toArray(t.entitySet).forEach(function(t){var n=_t(t.entityType,r).typeName;e.setEntityTypeForResourceName(t.name,n),e._entityTypeResourceMap[n]=t.name})}),r.complexType&&m.toArray(r.complexType).forEach(function(t){!function(e,t,r){var n=e.name,i=Nt(n,t),a=new Lt({shortName:n,namespace:i});m.toArray(e.property).forEach(function(e){St(a,e,t)}),r.addEntityType(a)}(t,r,e)}),r.entityType&&m.toArray(r.entityType).forEach(function(n){!function(e,t,r,n){var i=e.name,a=Nt(i,t),o=new kt({shortName:i,namespace:a,isAbstract:e.abstract&&"true"===e.abstract});if(e.baseType){var s=_t(e.baseType,t).typeName;o.baseTypeName=s;var u=n._getStructuralType(s,!0);if(u)Pt(o,e,t,r,n);else{var p=n._deferredTypes[s];p||(p=[],n._deferredTypes[s]=p),p.push({entityType:o,csdlEntityType:e})}}else Pt(o,e,t,r,n)}(n,r,t,e)})});var n=e.getIncompleteNavigationProperties();if(n.length>0){var i=n.map(function(e){return Array.isArray(e)?e.map(function(e){return e.parentType.name+":"+e.name}).join(", "):e.parentType.name+":"+e.name}).join(", ");throw new Error("Incomplete navigation properties: "+i)}return r&&e.importMetadata(r,!0),e}},Ot=function(){function e(e){D(e||{}).whereParam("name").isOptional().isString().whereParam("isCaseSensitive").isOptional().isBoolean().whereParam("usesSql92CompliantStringComparison").isBoolean().applyAll(this),this.name||(this.name=m.getUuid()),K._storeObject(this,"LocalQueryComparisonOptions",this.name)}return e.prototype.setAsDefault=function(){return m.setAsDefault(this,e)},e.caseInsensitiveSQL=new e({name:"caseInsensitiveSQL",isCaseSensitive:!1,usesSql92CompliantStringComparison:!0}),e.defaultInstance=new e(e.caseInsensitiveSQL),e}();function bt(e,t,r){t===undefined&&(t=null);var n=r(),i=e.dataType;if(i&&i.parse&&(t=Array.isArray(t)&&!e.isScalar?t.map(function(e){return i.parse(e,typeof e)}):i.parse(t,typeof t)),!(t===n||i&&i.normalize&&t&&n&&i.normalize(t)===i.normalize(n))){var a,o=this.entityAspect;if(o)a=e.name;else{var s=this.complexAspect;if(!s)return void r(t);o=s.getEntityAspect(),a=s.getPropertyPath(e.name)}var u=o._inProcess=o._inProcess||[];if(!(u.indexOf(e)>=0)){u.push(e);try{var p={parent:this,property:e,newValue:t,oldValue:n,propertyName:a,entityAspect:o};e.isComplexProperty?function(e,t){var r=e.property,n=e.oldValue,i=e.newValue,a=r.dataType;if(!r.isScalar)throw new Error(m.formatString("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.",r.name,r.parentType.name));if(!i)throw new Error(m.formatString("You cannot set the '%1' property to null because it's datatype is the ComplexType: '%2'",r.name,r.dataType.name));if(!n){var o=a.getCtor();n=new o,t(n)}a.dataProperties.forEach(function(e){var t=e.name,r=i.getProperty(t);n.setProperty(t,r)})}(p,r):e.isDataProperty?function(e,t){var r=e.parent,n=e.property,i=e.entityAspect,a=e.oldValue,o=e.newValue,s=i.entityManager;if(!n.isScalar)throw new Error("Nonscalar data properties are readonly - items may be added or removed but the collection may not be changed.");if(i.entityState.isUnchangedOrModified()){var u=n.name,p=lt.isEntity(r)?r.entityAspect:r.complexAspect;p.originalValues[u]===undefined&&(p.originalValues[u]=a!==undefined?a:n.defaultValue)}if(n.isPartOfKey&&s&&!s.isLoading){var c=r.entityType,y=c.keyProperties,l=y.map(function(e){return e===n?o:r.getProperty(e.name)}),f=new Oe(c,l);if(s.findEntityByKey(f))throw new Error("An entity with this key is already in the cache: "+f.toString());var h=r.entityAspect.getKey(),d=s._findEntityGroup(c);d._replaceKey(h,f)}var m=n.relatedNavigationProperty;if(m&&s)if(null!=o){var g=new Oe(m.entityType,[o]),v=s.findEntityByKey(g);v?r.setProperty(m.name,v):(s._unattachedChildrenMap.addChild(g,m,r),r.setProperty(m.name,null))}else r.setProperty(m.name,null);else if(n.inverseNavigationProperty&&s&&!s._inKeyFixup){var w=n.inverseNavigationProperty;if(null!=a){var g=new Oe(w.parentType,[a]),v=s.findEntityByKey(g);if(v)if(w.isScalar)v.setProperty(w.name,null);else{var E=v.getProperty(w.name);E.splice(E.indexOf(r),1)}}if(null!=o){var g=new Oe(w.parentType,[o]),v=s.findEntityByKey(g);v?w.isScalar?v.setProperty(w.name,r):v.getProperty(w.name).push(r):s._unattachedChildrenMap.addChild(g,w,r)}}if(t(o),Ct(e),n.isPartOfKey){var c=r.entityType,P=c.keyProperties.indexOf(n);if(c.navigationProperties.forEach(function(e){var t=e.inverse,n=t?t.foreignKeyNames:e.invForeignKeyNames;if(0!==n.length){var i=r.getProperty(e.name);if(i){var a=n[P];e.isScalar?i.setProperty(a,o):i.forEach(function(e){e.setProperty(a,o)})}}}),s){for(var S=c.inverseForeignKeyProperties,T=c.baseEntityType;T;)S=S.concat(T.inverseForeignKeyProperties),T=T.baseEntityType;S.forEach(function(e){null==e.relatedNavigationProperty.inverse&&s._updateFkVal(e,a,o)})}i.getKey(!0)}}(p,r):function(e,t){var r=e.parent,n=e.property,i=e.entityAspect,a=e.oldValue,o=e.newValue;if(!n.isScalar)throw new Error("Nonscalar navigation properties are readonly - entities can be added or removed but the collection may not be changed.");var s=i.entityManager,u=n.inverse;if(null!=o){var p=o.entityAspect;if(s){if(p.entityState.isDetached())s.isLoading||s.attachEntity(o,Ne.Added);else if(p.entityManager!==s)throw new Error("An Entity cannot be attached to an entity in another EntityManager. One of the two entities must be detached first.")}else p&&p.entityManager&&((s=p.entityManager).isLoading||s.attachEntity(i.entity,Ne.Added))}if(u)if(u.isScalar)null!=a&&a.setProperty(u.name,null),null!=o&&o.setProperty(u.name,r);else{if(null!=a){var c=a.getProperty(u.name),y=c.indexOf(r);-1!==y&&c.splice(y,1)}if(null!=o){var l=o.getProperty(u.name);l.push(r)}}else if(n.invForeignKeyNames&&s&&!s._inKeyFixup){var f=n.invForeignKeyNames;if(null!=o){var h=r.entityAspect.getKey().values;f.forEach(function(e,t){o.setProperty(e,h[t])})}else null!=a&&f.forEach(function(e){var t=a.entityType.getProperty(e);t.isPartOfKey||a.setProperty(e,null)})}if(t(o),Ct(e),n.relatedDataProperties){var d=i.entityState;if(null==o&&(d.isDetached()||a.entityAspect.entityState.isDetached()))return;if(d.isDeleted())return;var m=n.entityType.keyProperties;m.forEach(function(e,t){var i=n.relatedDataProperties[t];if(o||!i.isPartOfKey){var a=o?o.getProperty(e.name):i.defaultValue;r.setProperty(i.name,a)}})}}(p,r),function(e){var t=e.entityAspect,r=t.entityManager,n=t.entity,i={entity:n,parent:e.parent,property:e.property,propertyName:e.propertyName,oldValue:e.oldValue,newValue:e.newValue};r?r.isLoading||r.isRejectingChanges||(t.propertyChanged.publish(i),r.entityChanged.publish({entityAction:Ae.PropertyChange,entity:n,args:i})):t.propertyChanged.publish(i)}(p)}finally{u.pop()}}}}function Ct(e){var t=e.entityAspect,r=t.entityManager;if(null!=r&&!r.isLoading){var n=e.property;t.entityState.isUnchanged()&&!n.isUnmapped&&t.setModified(),r.validationOptions.validateOnPropertyChange&&t._validateProperty(e.newValue,{entity:t.entity,property:n,propertyName:e.propertyName,oldValue:e.oldValue})}}Ot.prototype._$typeName="LocalQueryComparisonOptions";var xt=function(){function e(t){D(t=t||{}).whereParam("namingConvention").isOptional().isInstanceOf(Et).withDefault(Et.defaultInstance).whereParam("localQueryComparisonOptions").isOptional().isInstanceOf(Ot).withDefault(Ot.defaultInstance).whereParam("serializerFn").isOptional().isFunction().applyAll(this),this.dataServices=[],this._resourceEntityTypeMap={},this._structuralTypeMap={},this._shortNameMap={},this._ctorRegistry={},this._incompleteTypeMap={},this._incompleteComplexTypeMap={},this._id=e.__id++,this.metadataFetched=new I("metadataFetched",this)}return e.prototype.setProperties=function(e){D(e).whereParam("name").isString().isOptional().whereParam("serializerFn").isFunction().isOptional().applyAll(this)},e.prototype.addDataService=function(e,t){v(e,"dataService").isInstanceOf(j).check(),v(t,"shouldOverwrite").isBoolean().isOptional().check();var r=this._getDataServiceIndex(e.serviceName);if(r>=0){if(!t)throw new Error("A dataService with this name '"+e.serviceName+"' already exists in this MetadataStore");this.dataServices[r]=e}else this.dataServices.push(e)},e.prototype._getDataServiceIndex=function(e){return m.arrayIndexOf(this.dataServices,function(t){return t.serviceName===e})},e.prototype.addEntityType=function(e){var t;if((t=e instanceof kt||e instanceof Lt?e:e.isComplexType?new Lt(e):new kt(e))instanceof kt){if(t.baseTypeName&&!t.baseEntityType){var r=this._getStructuralType(t.baseTypeName,!0);t._updateFromBase(r)}if(0===t.keyProperties.length&&!t.isAbstract)throw new Error("Unable to add "+t.name+" to this MetadataStore.  An EntityType must have at least one property designated as a key property - See the 'DataProperty.isPartOfKey' property.")}if(t.metadataStore=this,!t.isAnonymous){if(this._structuralTypeMap[t.name])throw new Error("Type "+t.name+" already exists in this MetadataStore.");this._structuralTypeMap[t.name]=t,this._shortNameMap[t.shortName]=t.name}if(t.getProperties().forEach(function(e){t._updateNames(e),e.isUnmapped||t._mappedPropertiesCount++}),t._updateCps(),t instanceof kt){t._updateNps();var n=t.defaultResourceName||t.baseEntityType&&t.baseEntityType.defaultResourceName;n&&!this.getEntityTypeNameForResourceName(n)&&this.setEntityTypeForResourceName(n,t.name),t.defaultResourceName=n,t.getEntityCtor()}},e.prototype.exportMetadata=function(){return JSON.stringify({metadataVersion:e.metadataVersion,name:this.name,namingConvention:this.namingConvention.name,localQueryComparisonOptions:this.localQueryComparisonOptions.name,dataServices:this.dataServices,structuralTypes:m.objectMap(this._structuralTypeMap),resourceEntityTypeMap:this._resourceEntityTypeMap},null,K.stringifyPad)},e.prototype.importMetadata=function(t,r){var n=this;void 0===r&&(r=!1),v(r,"allowMerge").isOptional().isBoolean().check(),this._deferredTypes={};var i="string"==typeof t?JSON.parse(t):t;if(i.schema)return At.parse(this,i.schema,i.altMetadata);var a=i;if(a.metadataVersion&&a.metadataVersion!==e.metadataVersion){var o=m.formatString("Cannot import metadata with a different 'metadataVersion' (%1) than the current 'MetadataStore.metadataVersion' (%2) ",a.metadataVersion,e.metadataVersion);throw new Error(o)}var s=a.namingConvention,u=a.localQueryComparisonOptions;if(this.isEmpty())this.namingConvention=K._fetchObject(Et,s)||this.namingConvention,this.localQueryComparisonOptions=K._fetchObject(Ot,u)||this.localQueryComparisonOptions;else{if(s&&this.namingConvention.name!==s)throw new Error("Cannot import metadata with a different 'namingConvention' from the current MetadataStore");if(u&&this.localQueryComparisonOptions.name!==u)throw new Error("Cannot import metadata with different 'localQueryComparisonOptions' from the current MetadataStore")}return a.dataServices&&a.dataServices.forEach(function(e){var t=j.fromJSON(e);n.addDataService(t,!0)}),a.structuralTypes&&a.structuralTypes.forEach(function(e){!function(e,t,r){var n=Ht(t.shortName,t.namespace),i=e._getStructuralType(n,!0);if(i)return r?function(e,t){t.custom&&(e.custom=t.custom);return Ft(e,t.dataProperties),Ft(e,t.navigationProperties),e}(i,t):i;var a={shortName:t.shortName,namespace:t.namespace,isAbstract:t.isAbstract,autoGeneratedKeyType:$t.fromName(t.autoGeneratedKeyType),defaultResourceName:t.defaultResourceName,custom:t.custom};if(i=t.isComplexType?new Lt(a):new kt(a),t.baseTypeName&&i instanceof kt){i.baseTypeName=t.baseTypeName;var o=e._getStructuralType(t.baseTypeName,!0);o?Mt(e,t,i):m.getArray(e._deferredTypes,t.baseTypeName).push({json:t,stype:i})}else Mt(e,t,i)}(n,e,r)}),m.extend(this._resourceEntityTypeMap,a.resourceEntityTypeMap),m.extend(this._incompleteTypeMap,a.incompleteTypeMap),this},e.importMetadata=function(t){var r=new e;return r.importMetadata(t),r},e.prototype.hasMetadataFor=function(e){return!!this.getDataService(e)},e.prototype.getDataService=function(e){return v(e,"serviceName").isString().check(),e=j._normalizeServiceName(e),m.arrayFirst(this.dataServices,function(t){return t.serviceName===e})},e.prototype.fetchMetadata=function(e,t,r){var n=this;try{if(v(e,"dataService").isString().or().isInstanceOf(j).check(),v(t,"callback").isFunction().isOptional().check(),v(r,"errorCallback").isFunction().isOptional().check(),"string"==typeof e&&(e=this.getDataService(e)||new j({serviceName:e})),e=j.resolve([e]),this.hasMetadataFor(e.serviceName))throw new Error("Metadata for a specific serviceName may only be fetched once per MetadataStore. ServiceName: "+e.serviceName);return e.adapterInstance.fetchMetadata(this,e).then(function(r){return n.metadataFetched.publish({metadataStore:n,dataService:e,rawMetadata:r}),t&&t(r),Promise.resolve(r)},function(e){return r&&r(e),Promise.reject(e)})}catch(i){return Promise.reject(i)}},e.prototype.trackUnmappedType=function(e,t){v(e,"entityCtor").isFunction().check(),v(t,"interceptor").isFunction().isOptional().check(),new kt(this)._setCtor(e,t)},e.prototype.registerEntityTypeCtor=function(e,t,r,n){v(e,"structuralTypeName").isString().check(),v(t,"aCtor").isFunction().isOptional().check(),v(r,"initFn").isOptional().isFunction().or().isString().check(),v(n,"noTrackingFn").isOptional().isFunction().check();var i=Dt(this,e,!1),a=i||e;if(t&&(t._$typeName&&t._$typeName!==a&&console.warn("Registering a constructor for "+a+" that is already used for "+t._$typeName+"."),t._$typeName=a),this._ctorRegistry[a]={ctor:t,initFn:r,noTrackingFn:n},i){var o=this._structuralTypeMap[i];o&&o.getCtor(!0)}},e.prototype.isEmpty=function(){return m.isEmpty(this._structuralTypeMap)},e.prototype.getEntityType=function(e,t){return void 0===t&&(t=!1),v(e,"structuralTypeName").isString().check(),v(t,"okIfNotFound").isBoolean().isOptional().check(!1),this._getStructuralType(e,t)},e.prototype._getStructuralType=function(e,t){void 0===t&&(t=!1);var r=Dt(this,e,!1),n=this._structuralTypeMap[r];if(!n){if(t)return null;var i=m.formatString("Unable to locate a 'Type' by the name: '%1'. Be sure to execute a query or call fetchMetadata first.",e);throw new Error(i)}return n},e.prototype.getEntityTypes=function(){return function(e){var t=[];for(var r in e){var n=e[r];r===n.name&&t.push(e[r])}return t}(this._structuralTypeMap)},e.prototype.getIncompleteNavigationProperties=function(){return m.objectMap(this._incompleteTypeMap,function(e,t){return t})},e.prototype.getEntityTypeNameForResourceName=function(e){return v(e,"resourceName").isString().check(),this._resourceEntityTypeMap[e]},e.prototype.setEntityTypeForResourceName=function(e,t){var r;v(e,"resourceName").isString().check(),v(t,"entityTypeOrName").isInstanceOf(kt).or().isString().check(),r=t instanceof kt?t.name:Dt(this,t,!0),this._resourceEntityTypeMap[e]=r;var n=this._getStructuralType(r,!0);n&&n instanceof kt&&!n.defaultResourceName&&(n.defaultResourceName=e)},e.parseTypeName=function(t){var r=t.split(":#");if(r.length>1)return e.makeTypeHash(r[0],r[1]);if(m.stringStartsWith(t,e.ANONTYPE_PREFIX)){var n=e.makeTypeHash(t);return n.isAnonymous=!0,n}if((r=t.split(",")[0].split(".")).length>1){var i=r[r.length-1],a=r.slice(0,r.length-1).join(".");return e.makeTypeHash(i,a)}return e.makeTypeHash(t)},e.makeTypeHash=function(e,t){return{shortTypeName:e,namespace:t,typeName:Ht(e,t)}},e.prototype._checkEntityType=function(e){if(!e.entityType){var t=e.prototype._$typeName;if(!t)throw new Error("This entity has not been registered. See the MetadataStore.registerEntityTypeCtor method");var r=this._getStructuralType(t);r&&(e.entityType=r)}},e.__id=0,e.ANONTYPE_PREFIX="_IB_",e.metadataVersion="1.0.5",e.normalizeTypeName=m.memoize(function(t){return t&&e.parseTypeName(t).typeName}),e}();function Ft(e,t){t&&t.forEach(function(t){var r=t.name;if(!r){if(!t.nameOnServer){throw new Error("Unable to complete 'importMetadata' - cannot locate a 'name' or 'nameOnServer' for one of the imported property nodes")}r=e.metadataStore.namingConvention.serverPropertyNameToClient(t.nameOnServer,{})}t.custom&&(e.getProperty(r,!0).custom=t.custom)})}function Mt(e,t,r){t.validators&&(r.validators=t.validators.map(J.fromJSON)),t.dataProperties.forEach(function(e){r._addPropertyCore(Ut.fromJSON(e))}),!t.isComplexType&&t.navigationProperties&&t.navigationProperties.forEach(function(e){r._addPropertyCore(zt.fromJSON(e))}),e.addEntityType(r);var n=e._deferredTypes,i=n[r.name];i&&(i.forEach(function(t){Mt(e,t.json,t.stype)}),delete n[r.name])}function Dt(e,t,r){if(Wt(t))return t;var n=e._shortNameMap[t];if(!n&&r)throw new Error("Unable to locate 'entityTypeName' of: "+t);return n}xt.prototype._$typeName="MetadataStore",I.bubbleEvent(xt.prototype);var kt=function(){function e(t){if(this.isComplexType=!1,this.getEntityCtor=this.getCtor,arguments.length>1)throw new Error("The EntityType ctor has a single argument that is either a 'MetadataStore' or a configuration object.");var r=undefined;"MetadataStore"===t._$typeName?(this.metadataStore=t,this.shortName="Anon_"+ ++e.__nextAnonIx,this.namespace="",this.isAnonymous=!0):(r=t,D(t).whereParam("shortName").isNonEmptyString().whereParam("namespace").isString().isOptional().withDefault("").whereParam("baseTypeName").isString().isOptional().whereParam("isAbstract").isBoolean().isOptional().withDefault(!1).whereParam("autoGeneratedKeyType").isEnumOf($t).isOptional().withDefault($t.None).whereParam("defaultResourceName").isNonEmptyString().isOptional().withDefault(null).whereParam("dataProperties").isOptional().whereParam("navigationProperties").isOptional().whereParam("serializerFn").isOptional().isFunction().whereParam("custom").isOptional().applyAll(this)),this.name=Ht(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=[],r&&r.dataProperties&&Yt(this,r.dataProperties,Ut),r&&r.navigationProperties&&Yt(this,r.navigationProperties,zt)}return e.prototype.setProperties=function(e){D(e).whereParam("autoGeneratedKeyType").isEnumOf($t).isOptional().whereParam("defaultResourceName").isString().isOptional().whereParam("serializerFn").isFunction().isOptional().whereParam("custom").isOptional().applyAll(this),e.defaultResourceName&&(this.defaultResourceName=e.defaultResourceName)},e.prototype.isSubtypeOf=function(t){v(t,"entityType").isInstanceOf(e).check();var r=this;do{if(r===t)return!0;r=r.baseEntityType}while(r);return!1},e.prototype.getSelfAndSubtypes=function(){var e=[this];return this.subtypes.forEach(function(t){var r=t.getSelfAndSubtypes();e.push.apply(e,r)}),e},e.prototype.getAllValidators=function(){for(var e=this.validators.slice(0),t=this.baseEntityType;t;)e.push.apply(e,t.validators),t=t.baseEntityType;return e},e.prototype.addProperty=function(e){v(e,"property").isInstanceOf(Ut).or().isInstanceOf(zt).check();var t=this._addPropertyCore(e,!0);if(this.subtypes&&this.subtypes.length){var r=this;r.getSelfAndSubtypes().forEach(function(t){t!==r&&(e.isNavigationProperty?t._addPropertyCore(new zt(e),!0):t._addPropertyCore(new Ut(e),!0))})}return t},e.prototype._updateFromBase=function(e){var t=this;this.baseEntityType=e,this.autoGeneratedKeyType===$t.None&&(this.autoGeneratedKeyType=e.autoGeneratedKeyType),e.dataProperties.forEach(function(e){var r=new Ut(e);r.validators=[],r.baseProperty=e,t._addPropertyCore(r)},this),e.navigationProperties.forEach(function(e){var r=new zt(e);r.validators=[],r.baseProperty=e,t._addPropertyCore(r)},this),e.subtypes.push(this)},e.prototype._addPropertyCore=function(e,t){if(void 0===t&&(t=!1),this.isFrozen)throw new Error("The '"+this.name+"' EntityType/ComplexType has been frozen. You can only add properties to an EntityType/ComplexType before any instances of that type have been created and attached to an entityManager.");var r=e.parentType;if(r){if(r!==this)throw new Error("This property: "+e.name+" has already been added to "+e.parentType.name)}else{e.parentType=this;var n=this.metadataStore;if(e instanceof Ut?this._addDataProperty(e):(this._addNavigationProperty(e),t&&n&&qt(e,n)),!n||e.name&&e.nameOnServer||Vt(n.namingConvention,e,"name"),n&&this._extra&&this._extra.alreadyWrappedProps){var i=this._ctor.prototype;K.interfaceRegistry.modelLibrary.getDefaultInstance().initializeEntityPrototype(i)}}},e.prototype.createEntity=function(e){if(e&&e._$eref&&!e._$eref.entityAspect.entityManager)return e._$eref;var t=this._createInstanceCore();return e&&(this.keyProperties.every(function(t){return null!=e[t.name]})&&(e._$eref=t),this._updateTargetFromRaw(t,e,It),this.navigationProperties.forEach(function(r){var n,i=e[r.name];if(i!=undefined){var a=r.entityType;if(r.isScalar)n=i.entityAspect?i:a.createEntity(i),t.setProperty(r.name,n);else{var o=t.getProperty(r.name);i.forEach(function(e){n=e.entityAspect?e:a.createEntity(e),o.push(n)})}}})),this._initializeInstance(t),t},e.prototype._createInstanceCore=function(){var e=new(this.getCtor());return new lt(e),e},e.prototype._initializeInstance=function(e){this.baseEntityType&&this.baseEntityType._initializeInstance(e);var t=this.initFn;t&&("string"==typeof t?e[t]:t)(e);this.complexProperties&&this.complexProperties.forEach(function(t){var r=t.dataType,n=e.getProperty(t.name);Array.isArray(n)?n.forEach(function(e){r._initializeInstance(e)}):r._initializeInstance(n)}),e.entityAspect&&(e.entityAspect._initialized=!0)},e.prototype.getCtor=function(e){if(void 0===e&&(e=!1),this._ctor&&!e)return this._ctor;var t,r=this.metadataStore._ctorRegistry,n=r[this.name]||r[this.shortName]||{},i=n.ctor||this._ctor,a=i&&i.prototype&&(i.prototype.entityType||i.prototype.complexType);if(a&&a.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(n.ctor&&e&&(this._extra=undefined),!i){var o=K.interfaceRegistry.modelLibrary.getDefaultInstance().createCtor;i=o?o(this):(t=this.name.replace(/\W/g,"_"),Function("return function "+t+"(){}")())}return this.initFn=n.initFn,this.noTrackingFn=n.noTrackingFn,i.prototype._$typeName=this.name,this._setCtor(i),i},e.prototype._setCtor=function(e,t){var r=e.prototype;this._extra=this._extra||{},Bt(this,new e),"EntityType"===this._$typeName?r.entityType=this:r.complexType=this,r._$interceptor=t||bt,K.interfaceRegistry.modelLibrary.getDefaultInstance().initializeEntityPrototype(r),this._ctor=e},e.prototype.addValidator=function(e,t){(v(e,"validator").isInstanceOf(J).check(),v(t,"property").isOptional().isString().or().isEntityProperty().check(),null!=t)?("string"==typeof t?this.getProperty(t,!0):t).validators.push(e):this.validators.push(e)},e.prototype.getProperties=function(){return this.dataProperties.concat(this.navigationProperties)},e.prototype.getPropertyNames=function(){return this.getProperties().map(m.pluck("name"))},e.prototype.getDataProperty=function(e){return m.arrayFirst(this.dataProperties,m.propEq("name",e))},e.prototype.getNavigationProperty=function(e){return m.arrayFirst(this.navigationProperties,m.propEq("name",e))},e.prototype.getProperty=function(e,t){void 0===t&&(t=!1);var r=this.getPropertiesOnPath(e,!1,t);return r&&r.length>0?r[r.length-1]:null},e.prototype.getPropertiesOnPath=function(e,t,r){void 0===r&&(r=!1);var n=Array.isArray(e)?e:e.trim().split("."),i=!0,a=!0===t?"nameOnServer":!1===t?"name":null,o=this,s=n.map(function(e){var t=null===a?m.propsEq("name","nameOnServer",e):m.propEq(a,e),n=m.arrayFirst(o.getProperties(),t);if(n)o=n instanceof zt?n.entityType:n.dataType;else{if(r)throw new Error("unable to locate property: "+e+" on entityType: "+o.name);i=!1}return n});return i?s:null},e.prototype.clientPropertyPathToServer=function(e,t){var r;if(void 0===t&&(t="."),this.isAnonymous){var n=this.metadataStore.namingConvention.clientPropertyNameToServer;r=e.split(".").map(function(e){return n(e)})}else{r=this.getPropertiesOnPath(e,!1,!0).map(function(e){return e.nameOnServer})}return r.join(t)},e.prototype.getEntityKeyFromRawEntity=function(e,t){var r=this.keyProperties.map(function(r){var n=t(e,r);return ee.parseRawValue(n,r.dataType)});return new Oe(this,r)},e.prototype._updateTargetFromRaw=function(e,t,r){this.dataProperties.forEach(function(n){if(n.isSettable){var i=r(t,n);if(i!==undefined){var a,o=n.dataType;if(n.isComplexProperty){var s=n.dataType;if(null===i)return;if(a=e.getProperty(n.name),n.isScalar)s._updateTargetFromRaw(a,i,r);else if(Array.isArray(i)){var u=i.map(function(t){var i=s._createInstanceCore(e,n);return s._updateTargetFromRaw(i,t,r),s._initializeInstance(i),i});m.arrayEquals(a,u,Rt)||(a.length=0,u.forEach(function(e){a.push(e)}))}else a.length=0}else if(n.isScalar){u=ee.parseRawValue(i,o);e.setProperty(n.name,u)}else if(a=e.getProperty(n.name),Array.isArray(i)){u=i.map(function(e){return ee.parseRawValue(e,o)});m.arrayEquals(a,u)||(a.length=0,u.forEach(function(e){a.push(e)}))}else a.length=0}}});var n=t.entityAspect||t.complexAspect;if(n){var i=lt.isEntity(e)?e.entityAspect:e.complexAspect;n.originalValuesMap&&(i.originalValues=n.originalValuesMap),n.extraMetadata&&(i.extraMetadata=n.extraMetadata)}},e.prototype.toString=function(){return this.name},e.prototype.toJSON=function(){return m.toJson(this,{shortName:null,namespace:null,baseTypeName:null,isAbstract:!1,autoGeneratedKeyType:null,defaultResourceName:null,dataProperties:Kt,navigationProperties:Kt,validators:null,custom:null})},e.prototype._updateNames=function(e){var t=this.metadataStore.namingConvention;Vt(t,e,"name"),e.isNavigationProperty&&(Vt(t,e,"foreignKeyNames"),Vt(t,e,"invForeignKeyNames"))},e.prototype._checkNavProperty=function(e){if(e instanceof zt){if(e.parentType!==this)throw new Error(m.formatString("The navigationProperty '%1' is not a property of entity type '%2'",e.name,this.name));return e}if("string"==typeof e){var t=this.getProperty(e);if(t&&t instanceof zt)return t}throw new Error("The 'navigationProperty' parameter must either be a NavigationProperty or the name of a NavigationProperty")},e.prototype._addDataProperty=function(e){this.dataProperties.push(e),e.isPartOfKey&&this.keyProperties.push(e),e.isComplexProperty&&this.complexProperties.push(e),e.concurrencyMode&&"None"!==e.concurrencyMode&&this.concurrencyProperties.push(e),e.isUnmapped&&this.unmappedProperties.push(e)},e.prototype._addNavigationProperty=function(e){this.navigationProperties.push(e),Wt(e.entityTypeName)||(e.entityTypeName=Ht(e.entityTypeName,this.namespace))},e.prototype._updateCps=function(){var e=this.metadataStore,t=e._incompleteComplexTypeMap;this.complexProperties.forEach(function(r){r.complexType||jt(r,e)||m.getArray(t,r.complexTypeName).push(r)}),this.isComplexType&&((t[this.name]||[]).forEach(function(t){jt(t,e)}),delete t[this.name])},e.prototype._updateNps=function(){var e=this.metadataStore;this.navigationProperties.forEach(function(t){qt(t,e)});var t=e._incompleteTypeMap;(t[this.name]||[]).forEach(function(t){qt(t,e)}),delete t[this.name]},e.__nextAnonIx=0,e.qualifyTypeName=Ht,e}();function It(e,t){return e.entityAspect||e.complexAspect?e.getProperty(t.name):e[t.name]}function Vt(e,t,r){var n=r+"OnServer",i=t[r];if(i&&i.length){var a=m.toArray(i).map(function(r){var n=e.clientPropertyNameToServer(r,t),i=e.serverPropertyNameToClient(n,t);if(r!==i)throw new Error("NamingConvention for this client property name does not roundtrip properly:"+r+"--\x3e"+i);return n});t[n]=Array.isArray(i)?a:a[0]}else{var o=t[n];if(!o||0===o.length)return;var s=m.toArray(o).map(function(r){var n=e.serverPropertyNameToClient(r,t),i=e.clientPropertyNameToServer(n,t);if(r!==i)throw new Error("NamingConvention for this server property name does not roundtrip properly:"+r+"--\x3e"+i);return n});t[r]=Array.isArray(o)?s:s[0]}}function Rt(e,t){return e.complexAspect.parentProperty.dataType.dataProperties.every(function(r){if(!r.isSettable)return!0;var n=e.getProperty(r.name),i=t.getProperty(r.name);if(r.isComplexProperty&&r.isScalar)return Rt(n,i);if(r.isComplexProperty&&!r.isScalar)return m.arrayEquals(n,i,Rt);var a=r.dataType;return n===i||a&&a.normalize&&n&&i&&a.normalize(n)===a.normalize(i)})}function Kt(e){return e.filter(function(e){return null==e.baseProperty})}function jt(e,t){var r=t._getStructuralType(e.complexTypeName,!0);if(!r)return!1;if(!(r instanceof Lt))throw new Error("Unable to resolve ComplexType with the name: "+e.complexTypeName+" for the property: "+e.name);return e.dataType=r,e.defaultValue=null,!0}function qt(e,t){if(e.entityType)return!0;var r=t._getStructuralType(e.entityTypeName,!0);if(r)e.entityType=r,e._resolveNp();else{var n=m.getArray(t._incompleteTypeMap,e.entityTypeName);m.arrayAddItemUnique(n,e)}return!!r}function Bt(e,t){var r=e.getPropertyNames();K.interfaceRegistry.modelLibrary.getDefaultInstance().getTrackablePropertyNames(t).forEach(function(n){if(-1===r.indexOf(n)){var i=t[n];try{"function"==typeof i&&(i=i())}catch(s){}var a=ee.fromValue(i),o=new Ut({name:n,dataType:a,isNullable:!0,isUnmapped:!0});o.isSettable=m.isSettable(t,n),e instanceof kt&&null!=e.subtypes&&e.subtypes.length?e.getSelfAndSubtypes().forEach(function(e){e._addPropertyCore(new Ut(o))}):e._addPropertyCore(o)}})}kt.prototype._$typeName="EntityType";var Lt=function(){function e(e){if(this.isComplexType=!0,this.getCtor=kt.prototype.getCtor,this.createInstance=kt.prototype.createEntity,this.addValidator=kt.prototype.addValidator,this.getProperty=kt.prototype.getProperty,this.getPropertiesOnPath=kt.prototype.getPropertiesOnPath,this.getPropertyNames=kt.prototype.getPropertyNames,this._addPropertyCore=kt.prototype._addPropertyCore,this._addDataProperty=kt.prototype._addDataProperty,this._updateNames=kt.prototype._updateNames,this._updateCps=kt.prototype._updateCps,this._initializeInstance=kt.prototype._initializeInstance,this._updateTargetFromRaw=kt.prototype._updateTargetFromRaw,this._setCtor=kt.prototype._setCtor,arguments.length>1)throw new Error("The ComplexType ctor has a single argument that is a configuration object.");D(e).whereParam("shortName").isNonEmptyString().whereParam("namespace").isString().isOptional().withDefault("").whereParam("dataProperties").isOptional().whereParam("isComplexType").isOptional().isBoolean().whereParam("custom").isOptional().applyAll(this),this.name=Ht(this.shortName,this.namespace),this.isComplexType=!0,this.dataProperties=[],this.complexProperties=[],this.validators=[],this.concurrencyProperties=[],this.unmappedProperties=[],this._mappedPropertiesCount=0,this.navigationProperties=[],this.keyProperties=[],e.dataProperties&&Yt(this,e.dataProperties,Ut)}return e.prototype.setProperties=function(e){D(e).whereParam("custom").isOptional().applyAll(this)},e.prototype.getAllValidators=function(){return this.validators},e.prototype._createInstanceCore=function(e,t){var r=new(this.getCtor());return new vt(r,e,t),r},e.prototype.addProperty=function(e){return v(e,"dataProperty").isInstanceOf(Ut).check(),this._addPropertyCore(e)},e.prototype.getProperties=function(){return this.dataProperties},e.prototype.toJSON=function(){return m.toJson(this,{shortName:null,namespace:null,isComplexType:null,dataProperties:null,validators:null,custom:null})},e}();Lt.prototype._$typeName="ComplexType",Lt.prototype.createInstance=kt.prototype.createEntity;var Ut=function(){function e(e){if(this.isDataProperty=!0,this.isNavigationProperty=!1,D(e).whereParam("name").isString().isOptional().whereParam("nameOnServer").isString().isOptional().whereParam("dataType").isEnumOf(ee).isOptional().or().isString().or().isInstanceOf(Lt).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("isSettable").isBoolean().isOptional().withDefault(!0).whereParam("concurrencyMode").isString().isOptional().whereParam("maxLength").isNumber().isOptional().whereParam("validators").isInstanceOf(J).isArray().isOptional().withDefault([]).whereParam("displayName").isOptional().whereParam("enumType").isOptional().whereParam("rawTypeName").isOptional().whereParam("custom").isOptional().applyAll(this),!!(!this.name&&!this.nameOnServer))throw new Error("A DataProperty must be instantiated with either a 'name' or a 'nameOnServer' property");if(this.complexTypeName)this.isComplexProperty=!0;else if("string"==typeof this.dataType){var t=ee.fromName(this.dataType);if(!t)throw new Error("Unable to find a DataType enumeration by the name of: "+this.dataType);this.dataType=t}else this.dataType||(this.dataType=ee.String);if(null==this.defaultValue){if(this.isNullable)this.defaultValue=null;else if(this.isComplexProperty);else if(this.dataType===ee.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))}else this.dataType.isNumeric&&"string"==typeof this.defaultValue&&(this.defaultValue=parseFloat(this.defaultValue));this.isComplexProperty&&(this.isScalar=null==this.isScalar||!0===this.isScalar)}return e.getRawValueFromServer=function(e,t){if(t.isUnmapped)return e[t.nameOnServer||t.name];var r=e[t.nameOnServer];return r!==undefined?r:t.defaultValue},e.getRawValueFromClient=function(e,t){var r=e[t.name];return r!==undefined?r:t.defaultValue},e.prototype.resolveProperty=function(e){for(var t=this[e],r=this.baseProperty;t==undefined&&null!=r;)t=r[e],r=r.baseProperty;return t},e.prototype.formatName=function(){return this.parentType.name+"--"+this.name},e.prototype.setProperties=function(e){D(e).whereParam("displayName").isOptional().whereParam("custom").isOptional().applyAll(this)},e.prototype.getAllValidators=function(){for(var e=this.validators.slice(0),t=this.baseProperty;t;)e.push.apply(e,t.validators),t=t.baseProperty;return e},e.prototype.toJSON=function(){return m.toJson(this,{name:null,dataType:function(e){return e&&e instanceof ee?e.name:undefined},complexTypeName:null,isNullable:!0,defaultValue:null,isPartOfKey:!1,isUnmapped:!1,isSettable:!0,concurrencyMode:null,maxLength:null,validators:null,displayName:null,enumType:null,rawTypeName:null,isScalar:!0,custom:null})},e.fromJSON=function(t){return t.dataType=ee.fromName(t.dataType),t.defaultValue&&t.dataType&&t.dataType.parse&&(t.defaultValue=t.dataType.parse(t.defaultValue,typeof t.defaultValue)),t.validators&&(t.validators=t.validators.map(J.fromJSON)),new e(t)},e}();Ut.prototype._$typeName="DataProperty";var zt=function(){function e(e){if(this.isDataProperty=!1,this.isNavigationProperty=!0,this.formatName=Ut.prototype.formatName,this.getAllValidators=Ut.prototype.getAllValidators,this.resolveProperty=Ut.prototype.resolveProperty,D(e).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(J).isArray().isOptional().withDefault([]).whereParam("displayName").isOptional().whereParam("custom").isOptional().applyAll(this),!!(!this.name&&!this.nameOnServer))throw new Error("A Navigation property must be instantiated with either a 'name' or a 'nameOnServer' property")}return e.prototype.setProperties=function(e){if(!this.parentType)throw new Error("Cannot call NavigationProperty.setProperties until the parent EntityType of the NavigationProperty has been set.");var t=e.inverse;t&&delete e.inverse,D(e).whereParam("displayName").isOptional().whereParam("foreignKeyNames").isArray().isString().isOptional().withDefault([]).whereParam("invForeignKeyNames").isArray().isString().isOptional().withDefault([]).whereParam("custom").isOptional().applyAll(this),this.parentType._updateNames(this),this._resolveNp(),t&&this.setInverse(t)},Object.defineProperty(e.prototype,"inverse",{get:function(){return this.getInverse()},enumerable:!0,configurable:!0}),e.prototype.getInverse=function(){for(var e=this;!e._inverse&&e.baseProperty;)e=e.baseProperty;return e._inverse},e.prototype.setInverse=function(t){var r=t instanceof e?t:this.entityType.getNavigationProperty(t);if(!r)throw Gt(this,"Unable to find inverse property: "+t);(this._inverse||r._inverse)&&Gt(this,"It has already been set on one side or the other."),r.entityType!==this.parentType&&Gt(this,r.formatName+" is not a valid inverse property for this."),this.associationName?r.associationName=this.associationName:(r.associationName||(r.associationName=this.formatName()+"_"+r.formatName()),this.associationName=r.associationName),this._resolveNp(),r._resolveNp()},e.prototype.toJSON=function(){return m.toJson(this,{name:null,entityTypeName:null,isScalar:null,associationName:null,validators:null,displayName:null,foreignKeyNames:null,invForeignKeyNames:null,custom:null})},e.fromJSON=function(t){return t.validators&&(t.validators=t.validators.map(J.fromJSON)),new e(t)},e.prototype._resolveNp=function(){var e=this,t=e.entityType,r=m.arrayFirst(t.navigationProperties,function(t){return t.associationName===e.associationName&&(t.name!==e.name||t.entityTypeName!==e.entityTypeName)});e._inverse=r||undefined,r||e.invForeignKeyNames.forEach(function(n){var i=t.getDataProperty(n);if(null==i)throw new Error("EntityType '"+e.entityTypeName+"' has no foreign key matching '"+n+"'");var a=e.parentType;r=m.arrayFirst(a.navigationProperties,function(e){return e.invForeignKeyNames&&e.invForeignKeyNames.indexOf(i.name)>=0&&e.entityType===i.parentType}),i.inverseNavigationProperty=r||undefined,m.arrayAddItemUnique(t.foreignKeyProperties,i)}),function(e){var t=e.foreignKeyNames;if(0===t.length)return;var r=e.parentType,n=t.map(function(e){return r.getDataProperty(e)}),i=r.foreignKeyProperties;n.forEach(function(t){m.arrayAddItemUnique(i,t),t.relatedNavigationProperty=e,m.arrayAddItemUnique(e.entityType.inverseForeignKeyProperties,t),e.relatedDataProperties?m.arrayAddItemUnique(e.relatedDataProperties,t):e.relatedDataProperties=[t]})}(e)},e}();function Gt(e,t){throw new Error("Cannot set the inverse property for: "+e.formatName()+". "+t)}zt.prototype._$typeName="NavigationProperty";var $t=function(e){function t(){return null!==e&&e.apply(this,arguments)||this}return r(t,e),t.None=new t,t.Identity=new t,t.KeyGenerator=new t,t}(a);$t.prototype._$typeName="AutoGeneratedKeyType",globalThis.x=$t.resolveSymbols();var Jt=g.prototype;function Qt(e,t){return null!=t&&t.entityType!==undefined}function Zt(e,t){return null!=t&&(t.isDataProperty||t.isNavigationProperty)}function Wt(e){return e.indexOf(":#")>=0}function Ht(e,t){return t&&t.length>0?e+":#"+t:e}function Yt(e,t,r){if(null!=t)if(Array.isArray(t))t.forEach(e._addPropertyCore.bind(e));else{if("object"!=typeof t)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 n in t)if(m.hasOwnProperty(t,n)){var i=t[n];i.name=n;var a=new r(i);e._addPropertyCore(a)}}}Jt.isEntity=function(){return this._addContext({fn:Qt,msg:" must be an entity"})},Jt.isEntityProperty=function(){return this._addContext({fn:Zt,msg:" must be either a DataProperty or a NavigationProperty"})};var Xt=function(){function e(){this.changeRequestInterceptor=tr,this.jsonResultsAdapter=new B({name:"noop",visitNode:function(){return{}}})}return e.prototype.checkForRecomposition=function(e){"ajax"===e.interfaceName&&e.isDefault&&this.initialize()},e.prototype.initialize=function(){if(this.ajaxImpl=K.getAdapterInstance("ajax"),!this.ajaxImpl||!this.ajaxImpl.ajax)throw new Error("Unable to find ajax adapter for dataservice adapter '"+(this.name||"")+"'.")},e.prototype.fetchMetadata=function(e,t){var r=this,n=t.serviceName,i=t.qualifyUrl("Metadata");return new Promise(function(a,o){r.ajaxImpl.ajax({type:"GET",url:i,dataType:"json",success:function(r){if(e.hasMetadataFor(n))return a("already fetched");var s,u=r.data;try{s="string"==typeof u?JSON.parse(u):u,e.importMetadata(s)}catch(c){var p="Unable to either parse or import metadata: "+c.message;er(o,r,"Metadata query failed for: "+i+". "+p)}e.hasMetadataFor(n)||e.addDataService(t),a(s)},error:function(e){er(o,e,"Metadata query failed for: "+i)}})})},e.prototype.executeQuery=function(e){var t=this;return e.adapter=this,new Promise(function(r,n){var i={type:"GET",url:e.getUrl(),params:e.query.parameters,dataType:"json",success:function(t){var i=t.data;try{var a=void 0,o=i&&(i.results||i.Results);a=o?{results:o,inlineCount:i.inlineCount||i.InlineCount,httpResponse:t,query:e.query}:{results:i,httpResponse:t,query:e.query},r(a)}catch(s){s instanceof Error?n(s):er(n,t)}},error:function(e){er(n,e)},crossDomain:!1};e.dataService.useJsonp&&(i.dataType="jsonp",i.crossDomain=!0),t.ajaxImpl.ajax(i)})},e.prototype.saveChanges=function(e,t){var r=this,n=e.adapter=this,i=n._prepareSaveBundle(e,t),a=JSON.stringify(i),o=e.dataService.qualifyUrl(e.resourceName);return new Promise(function(t,i){r.ajaxImpl.ajax({type:"POST",url:o,dataType:"json",contentType:"application/json",data:a,success:function(r){r.saveContext=e;var a=r.data;if(a.Errors||a.errors)er(i,r);else{var o=n._prepareSaveResult(e,a);o.httpResponse=r,t(o)}},error:function(t){t.saveContext=e,er(i,t)}})})},e.prototype._prepareSaveBundle=function(e,t){throw new Error("Need a concrete implementation of _prepareSaveBundle")},e.prototype._createChangeRequestInterceptor=function(e,t){var r=e.adapter,n=r.changeRequestInterceptor,i=m.isFunction;if(i(n)){var a=r.name+" DataServiceAdapter's ChangeRequestInterceptor",o=" is missing or not a function.",s=new n(e,t);if(!i(s.getRequest))throw new Error(a+".getRequest"+o);if(!i(s.done))throw new Error(a+".done"+o);return s}return new tr(e,t)},e.prototype._prepareSaveResult=function(e,t){throw new Error("Need a concrete implementation of _prepareSaveResult")},e._catchNoConnectionError=function(e){0===e.status&&null==e.message&&(e.message="HTTP response status 0 and no message.  Likely did not or could not reach server. Is the server running?")},e}();function er(e,t,r){var n=function(e){var t=new Error;t.httpResponse=e,t.status=e.status;var r=e.data;if(!r)return t.message=e.error&&e.error.toString(),t;if("string"==typeof r)try{r=JSON.parse(r)}catch(u){return t.message=r,t}var n,i,a=e.saveContext;if(r.Message||r.ExceptionMessage||r.EntityErrors||r.Errors){var o=r;do{n=o.ExceptionMessage||o.Message,o=o.InnerException}while(o);i=(i=r.Errors||r.EntityErrors)&&i.map(function(e){return{errorName:e.ErrorName,entityTypeName:xt.normalizeTypeName(e.EntityTypeName),keyValues:e.KeyValues,propertyName:e.PropertyName,errorMessage:e.ErrorMessage}})}else n=r.message,i=r.errors||r.entityErrors;if(a&&i){var s=a.entityManager.metadataStore.namingConvention.serverPropertyNameToClient;i.forEach(function(e){e.propertyName=e.propertyName&&s(e.propertyName)}),t.entityErrors=i}return t.message=n||"Server side errors encountered - see the entityErrors collection on this object for more detail",t}(t);Xt._catchNoConnectionError(n),r&&(n.message=r+"; "+n.message),e(n)}var tr=function(){function e(e,t){}return e.prototype.getRequest=function(e,t,r){return e},e.prototype.done=function(e){},e}(),rr=function(){function e(e){nr(this,e)}return e.prototype.using=function(t){if(!t)return this;var r=new e(this);return nr(r,t),r},e.prototype.setAsDefault=function(){return m.setAsDefault(this,e)},e.defaultInstance=new e({validateOnAttach:!0,validateOnSave:!0,validateOnQuery:!1,validateOnPropertyChange:!0}),e}();function nr(e,t){return t&&D(t).whereParam("validateOnAttach").isBoolean().isOptional().whereParam("validateOnSave").isBoolean().isOptional().whereParam("validateOnQuery").isBoolean().isOptional().whereParam("validateOnPropertyChange").isBoolean().isOptional().applyAll(e),e}rr.prototype._$typeName="ValidationOptions";var ir=function(){function e(t){e._updateWithConfig(this,t)}return e.prototype.setAsDefault=function(){return m.setAsDefault(this,e)},e.prototype.using=function(t){return e._updateWithConfig(this,t)},e._updateWithConfig=function(e,t){return t&&D(t).whereParam("resourceName").isOptional().isString().whereParam("dataService").isOptional().isInstanceOf(j).whereParam("allowConcurrentSaves").isBoolean().isOptional().whereParam("tag").isOptional().applyAll(e),e},e.defaultInstance=new e({allowConcurrentSaves:!1}),e}();ir.prototype._$typeName="SaveOptions";var ar=function(){function e(){this._tempIdMap={}}return e.prototype.generateTempKeyValue=function(e,t){var r=e.keyProperties;if(r.length>1)throw new Error("Ids can not be autogenerated for entities with multipart keys");var n,i=r[0],a=this._getPropEntry(i,!0);if(null!=t&&(a.keyMap[t.toString()]||(n=t)),n===undefined){var o=i.dataType,s=o.getNext;if(!s)throw new Error("Cannot use a property with a dataType of: "+o.toString()+" for id generation");for(n=s(this);null!=a.keyMap[n.toString()];)n=s(this)}return a.keyMap[n.toString()]=!0,n},e.prototype.getTempKeys=function(){var e=[];for(var t in this._tempIdMap){var r=this._tempIdMap[t],n=r.entityType;for(var i in r.keyMap)e.push(new Oe(n,[i]))}return e},e.prototype.isTempKey=function(e){var t=e.entityType.keyProperties;if(t.length>1)return!1;var r=t[0],n=this._getPropEntry(r);return!!n&&n.keyMap[e.values[0].toString()]!==undefined},e.prototype._getPropEntry=function(e,t){void 0===t&&(t=!1);var r=e.name+".."+e.parentType.name,n=this._tempIdMap[r];return n||t&&(n={entityType:e.parentType,propertyName:e.name,keyMap:{}},this._tempIdMap[r]=n),n},e}();K.registerType(ar,"KeyGenerator");var or=function(){function e(e,t){this.entityManager=e,this.entityType=t,this.entityType.isFrozen=!0,this._indexMap={},this._entities=[],this._emptyIndexes=[]}return e.prototype.attachEntity=function(e,t,r){var n=e.entityAspect;n._initialized||this.entityType._initializeInstance(e),delete n._initialized;var i=n.getKey()._keyInGroup,a=this._indexMap[i];if(a>=0){var o=this._entities[a],s=o.entityAspect.entityState.isUnchanged();if(o===e)n.entityState=t;else{if(r===be.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: "+n.getKey());if(r===be.OverwriteChanges||r===be.PreserveChanges&&s){var u=this.entityManager.helper.unwrapInstance(e);this.entityType._updateTargetFromRaw(o,u,Ut.getRawValueFromServer),o.entityAspect.setEntityState(t)}}return o}return 0===this._emptyIndexes.length?a=this._entities.push(e)-1:(a=this._emptyIndexes.pop(),this._entities[a]=e),this._indexMap[i]=a,n.entityState=t,n.entityGroup=this,n.entityManager=this.entityManager,e},e.prototype.detachEntity=function(e){var t=e.entityAspect.getKey()._keyInGroup,r=this._indexMap[t];if(r===undefined)throw new Error("internal error - entity cannot be found in group");return delete this._indexMap[t],this._emptyIndexes.push(r),this._entities[r]=null,e},e.prototype.findEntityByKey=function(e){var t;t=e instanceof Oe?e._keyInGroup:Oe.createKeyString(e);var r=this._indexMap[t],n=r!==undefined?this._entities[r]:undefined;return null==n?undefined:n},e.prototype.hasChanges=function(){for(var e=this._entities,t=Ne.Unchanged,r=0,n=e.length;r<n;r++){var i=e[r];if(i&&i.entityAspect.entityState!==t)return!0}return!1},e.prototype.getChanges=function(){for(var e=this._entities,t=Ne.Unchanged,r=[],n=0,i=e.length;n<i;n++){var a=e[n];a&&a.entityAspect.entityState!==t&&r.push(a)}return r},e.prototype.getEntities=function(e){var t=function(e){if(0===e.length)return function(e){return!!e};if(1===e.length){var t=e[0];return function(e){return!!e&&e.entityAspect.entityState===t}}return function(t){return!!t&&-1!==e.indexOf(t.entityAspect.entityState)}}(e);return this._entities.filter(t)},e.prototype._checkOperation=function(e){return this._entities.forEach(function(t){t&&t.entityAspect._checkOperation(e)}),this},e.prototype._clear=function(){this._entities.forEach(function(e){null!=e&&e.entityAspect._detach()}),this._entities=null,this._indexMap=null,this._emptyIndexes=null},e.prototype._updateFkVal=function(e,t,r){var n=e.name;this._entities.forEach(function(e){null!=e&&e.getProperty(n)===t&&e.setProperty(n,r)})},e.prototype._fixupKey=function(e,t){var r=this._indexMap[e];if(r===undefined)throw new Error("Internal Error in key fixup - unable to locate entity");var n=this._entities[r],i=n.entityType.keyProperties[0].name;n.setProperty(i,t),delete n.entityAspect.hasTempKey,delete this._indexMap[e],this._indexMap[t]=r},e.prototype._replaceKey=function(e,t){var r=this._indexMap[e._keyInGroup];delete this._indexMap[e._keyInGroup],this._indexMap[t._keyInGroup]=r},e}();var sr=function(){function e(e){this.rawValueFn=Ut.getRawValueFromServer,m.extend(this,e,["query","entityManager","dataService","mergeOptions"]),this.refMap={},this.deferredFns=[],this.jsonResultsAdapter=this.dataService.jsonResultsAdapter,this.metadataStore=this.entityManager.metadataStore,this.rawValueFn=Ut.getRawValueFromServer}return e.prototype.getUrl=function(){var e,t=this.query;if(!t)throw new Error("query cannot be empty");if("string"==typeof t)e=t;else{if(!(t instanceof rt))throw new Error("unable to recognize query parameter as either a string or an EntityQuery");e=this.dataService.uriBuilder.buildUri(t,this.metadataStore)}return this.dataService.qualifyUrl(e)},e.prototype.visitAndMerge=function(e,t){var r=this.query,n=this.jsonResultsAdapter;t=t||{};var i=this;return m.map(e,function(e){if(null==r&&e.entityAspect)return e.entityAspect.entityState.isDeleted()?i.entityManager.detachEntity(e):e.entityAspect.acceptChanges(),e;var a=n.visitNode(e,i,t)||{};return e=a.node||e,r&&"root"===t.nodeType&&!a.entityType&&(a.entityType=r instanceof rt&&r._getToEntityType&&r._getToEntityType(i.metadataStore)),ur(i,e,a)},this.mergeOptions.includeDeleted)},e.prototype.processDeferred=function(){this.deferredFns.length>0&&this.deferredFns.forEach(function(e){e()})},e}();function ur(e,t,r,n){if(r.ignore||null==t)return null;if(r.nodeRefId){var i=function(e,t){var r=e.refMap[t];return r===undefined?function(){return e.refMap[t]}:r}(e,r.nodeRefId);return"function"==typeof i&&null!=n?(e.deferredFns.push(function(){n(i)}),undefined):i}if(r.entityType){var a=r.entityType;return e.mergeOptions.noTracking?(t=pr(e,a,t),a.noTrackingFn&&(t=a.noTrackingFn(t,a)),r.nodeId&&(e.refMap[r.nodeId]=t),t):a.isComplexType?pr(e,a,t):function(e,t,r){t._$meta=r;var n=e.entityManager,i=r.entityType;"string"==typeof i&&(i=e.metadataStore._getStructuralType(i,!1));t.entityType=i;var a=e.mergeOptions.mergeStrategy,o=null==e.query,s=i.getEntityKeyFromRawEntity(t,e.rawValueFn),u=n.findEntityByKey(s);if(u){if(o&&u.entityAspect.entityState.isDeleted())return n.detachEntity(u),u;var p=u.entityAspect.entityState;if(a===be.Disallowed)throw new Error("A MergeStrategy of 'Disallowed' prevents "+s.toString()+" from being merged");if(a===be.SkipMerge)fr(e,u,t);else if(a===be.OverwriteChanges||p.isUnchanged()){hr(e,u,t),u.entityAspect.wasLoaded=!0,r.extraMetadata&&(u.entityAspect.extraMetadata=r.extraMetadata),u.entityAspect.entityState=Ne.Unchanged,lr(u),u.entityAspect.propertyChanged.publish({entity:u,propertyName:null});var c=o?Ae.MergeOnSave:Ae.MergeOnQuery;n.entityChanged.publish({entityAction:c,entity:u}),p.isUnchanged()||n._notifyStateChange(u,!1)}else{if(p===Ne.Deleted&&!e.mergeOptions.includeDeleted)return null;fr(e,u,t)}}else u=i._createInstanceCore(),hr(e,u,t),r.extraMetadata&&(u.entityAspect.extraMetadata=r.extraMetadata),n._attachEntityCore(u,Ne.Unchanged,a),u.entityAspect.wasLoaded=!0,n.entityChanged.publish({entityAction:Ae.AttachOnQuery,entity:u});return u}(e,t,r)}return r.passThru||"object"!=typeof t||m.isDate(t)||(t=function(e,t){var r=e.metadataStore.namingConvention.serverPropertyNameToClient,n={};return m.objectForEach(t,function(t,i){var a=r(t);cr(i,e,{nodeType:"anonProp",propertyName:a},n,a)}),n}(e,t)),r.nodeId&&(e.refMap[r.nodeId]=t),t}function pr(e,t,r){var n={};return t.dataProperties.forEach(function(t){t.isComplexProperty?n[t.name]=m.map(r[t.nameOnServer],function(r){return pr(e,t.dataType,r)}):n[t.name]=ee.parseRawValue(r[t.nameOnServer],t.dataType)}),t instanceof kt&&t.navigationProperties.forEach(function(t){var i={nodeType:"navProp",navigationProperty:t};cr(r[t.nameOnServer],e,i,n,t.name)}),n}function cr(e,t,r,n,i){var a=t.jsonResultsAdapter,o=a.visitNode(e,t,r)||{};if(e=o.node||e,!o.ignore)return o.passThru?e:void(Array.isArray(e)?(r.nodeType=r.nodeType+"Item",n[i]=e.map(function(e,s){return e=(o=a.visitNode(e,t,r)||{}).node||e,ur(t,e,o,function(e){n[i][s]=e()})})):n[i]=ur(t,e,o,function(e){n[i]=e()}))}function yr(e,t,r){var n=r._$meta.nodeId;!n&&r._$meta.extraMetadata&&(n=r._$meta.extraMetadata.uriKey),null!=n&&(e.refMap[n]=t)}function lr(e){(e.entityAspect||e.complexAspect).originalValues={},(e.entityType||e.complexType).complexProperties.forEach(function(t){var r=e.getProperty(t.name);t.isScalar?lr(r):(r._acceptChanges(),r.forEach(lr))})}function fr(e,t,r){yr(e,t,r),r.entityType.navigationProperties.forEach(function(t){t.isScalar?dr(e,r,t):mr(e,r,t)})}function hr(e,t,r){yr(e,t,r);var n=t.entityType;n._updateTargetFromRaw(t,r,e.rawValueFn),n.navigationProperties.forEach(function(n){n.isScalar?function(e,t,r,n){var i=dr(e,n,t);if(null==i)return;"function"==typeof i?e.deferredFns.push(function(){gr(i=i(),r,t)}):gr(i,r,t)}(e,n,t,r):function(e,t,r,n){var i=mr(e,n,t);if(null==i)return;var a=t.inverse;if(!a)return;var o=r.getProperty(t.name);o.wasLoaded=!0,i.forEach(function(t){"function"==typeof t?e.deferredFns.push(function(){t=t(),vr(e,t,o,r,a)}):vr(e,t,o,r,a)})}(e,n,t,r)})}function dr(e,t,r){var n=t[r.nameOnServer];return n?e.visitAndMerge(n,{nodeType:"navProp",navigationProperty:r}):null}function mr(e,t,r){var n=t[r.nameOnServer];return n&&(Array.isArray(n)||(n=n.results))?e.visitAndMerge(n,{nodeType:"navPropItem",navigationProperty:r}):null}function gr(e,t,r){if(e){var n=r.name;if(t.getProperty(n)!==e){t.setProperty(n,e);var i=r.inverse;if(!i)return;if(i.isScalar)e.setProperty(i.name,t);else e.getProperty(i.name).push(t)}}}function vr(e,t,r,n,i){if(t){if(t.entityAspect.entityState===Ne.Modified&&e.mergeOptions.mergeStrategy===be.PreserveChanges){var a=t.entityAspect.originalValues;if(i.relatedDataProperties.some(function(e){return a[e.name]!=undefined}))return}t.getProperty(i.name)!==n&&(r.push(t),t.setProperty(i.name,n))}}sr.prototype._$typeName="MappingContext";var wr=function(){function e(){this.map={}}return e.prototype.addChild=function(e,t,r){var n=this.getTuple(e,t);n||(n={navigationProperty:t,children:[]},m.getArray(this.map,e.toString()).push(n)),n.children.push(r)},e.prototype.removeChildren=function(e,t){var r=this.map[e];r&&(m.arrayRemoveItem(r,function(e){return e.navigationProperty===t}),r.length||delete this.map[e])},e.prototype.getTuple=function(e,t){var r=this.getTuples(e);return r?m.arrayFirst(r,function(e){return e.navigationProperty===t}):null},e.prototype.getTuples=function(e){var t=[],r=this.map[e.toString()];r&&(t=t.concat(r));for(var n=e.entityType;n.baseEntityType;){n=n.baseEntityType;var i=e.toString(n);(r=this.map[i])&&(t=t.concat(r))}return t.length?t:undefined},e.prototype.getTuplesByString=function(e){return this.map[e]},e}(),Er=function(){function e(t){if(this.helper={unwrapInstance:Mr,unwrapOriginalValues:Dr,unwrapChangedValues:kr},arguments.length>1)throw new Error("The EntityManager ctor has a single optional argument that is either a 'serviceName' or a configuration object.");var r;r=0===arguments.length?{serviceName:""}:"string"==typeof t?{serviceName:t}:t||{},e._updateWithConfig(this,r,!0),this.entityChanged=new I("entityChanged",this),this.validationErrorsChanged=new I("validationErrorsChanged",this),this.hasChangesChanged=new I("hasChangesChanged",this),this.clear()}return e.prototype.getEntityGraph=function(e,t){if(e instanceof rt){var r=this.executeQueryLocally(e);return this._getEntityGraphCore(r,t||e.expandClause)}return this._getEntityGraphCore(e,t)},e.prototype._getEntityGraphCore=function(e,t){var r,n,i=[];return a(e=Array.isArray(e)?e:[e]),(e=i.slice()).length&&(function(){var t;function i(e,t){return new Error("'getEntityGraph' root["+e+"] "+t)}e.forEach(function(e,a){var o;if(!e||!(o=e.entityAspect))throw i(a,"is not an entity");if(o.entityState===Ne.Detached)throw i(a,"is a detached entity");var s=o.entityManager;if(r){if(r!==s._entityGroupMap)throw i(a,"has a different 'EntityManager' than other roots")}else r=s._entityGroupMap;!function(e,r){var a=e.entityType;if(!n)return void(n=a);if(n===a)return;var o=n;do{if((t=t||o.getSelfAndSubtypes()).indexOf(a)>-1)return void(n=o);o=o.baseEntityType,t=null}while(o);o=a;do{if((t=o.getSelfAndSubtypes()).indexOf(n)>-1)return void(n=o);o=o.baseEntityType}while(o);throw i(r,"is not EntityType-compatible with other roots")}(e,a)})}(),function(){try{if(t?"string"==typeof t&&(t=(new rt).expand(t).expandClause):t=[],t.propertyPaths)t=t.propertyPaths;else{if(!Array.isArray(t))throw"";if(!t.every(function(e){return"string"==typeof e}))throw""}}catch(e){throw new Error("expand must be an expand string, array of string paths, or a query expand clause")}}(),function(){if(t&&t.length){var r=t.map(o);r.forEach(function(t){t(e)})}}()),i;function a(e){e.forEach(function(e){e&&i.indexOf(e)<0&&i.push(e)})}function o(e){for(var t=[],r=e.split("."),i=n,o=0,u=r.length;o<u;o++){var p=s(i,r[o]);i=p.navType,t.push(p)}return function(e){for(var r=0,n=t.length;r<n;r++){var i=e.length;if(0===i)return;for(var o=t[r],s=[],u=0;u<i;u++)s=s.concat(o(e[u]));if(a(s),r>=n-1)return;e=[];for(var p=0,c=s.length;p<c;p++){var y=s[p];e.indexOf(y)<0&&e.push(y)}}}}function s(e,t){var n,i,a=undefined;try{n=e.name;var o=e.getNavigationProperty(t),s=o.foreignKeyNames[0];if(!o)throw new Error(t+" is not a navigation property of "+n);var u=(i=o.entityType).getSelfAndSubtypes(),p=[];u.forEach(function(e){var t=r[e.name];t&&t._entities.length>0&&p.push(t)});var c=p.length;if(0===c)a=function(){return[]};else if(s)a=function(e){var t=null;try{for(var r=e.getProperty(s),n=0;n<c&&!(t=p[n]._entities[p[n]._indexMap[r]]);n+=1);}catch(i){y(i)}return t};else{if(!(s=o.inverse?o.inverse.foreignKeyNames[0]:o.invForeignKeyNames[0]))throw new Error("No inverse keys");a=function(e){var t=[];try{var r=e.entityAspect.getKey().values[0];p.forEach(function(e){t=t.concat(e._entities.filter(function(e){return e&&e.getProperty(s)===r}))})}catch(n){y(n)}return t}}a.navType=i,a.path=t}catch(l){y(l)}return a;function y(r){new Error("'getEntityGraph' can't expand '"+t+"' for "+(n||e));throw r}}},e.prototype.setProperties=function(t){e._updateWithConfig(this,t,!1)},e._updateWithConfig=function(e,t,r){var n=r?xe.defaultInstance:e.queryOptions,i=r?ir.defaultInstance:e.saveOptions,a=r?rr.defaultInstance:e.validationOptions,o=D(t).whereParam("serviceName").isOptional().isString().whereParam("dataService").isOptional().isInstanceOf(j).whereParam("queryOptions").isInstanceOf(xe).isOptional().withDefault(n).whereParam("saveOptions").isInstanceOf(ir).isOptional().withDefault(i).whereParam("validationOptions").isInstanceOf(rr).isOptional().withDefault(a).whereParam("keyGeneratorCtor").isFunction().isOptional();r&&(o=o.whereParam("metadataStore").isInstanceOf(xt).isOptional().withDefault(new xt)),o.applyAll(e),m.updateWithDefaults(e.queryOptions,n),m.updateWithDefaults(e.saveOptions,i),m.updateWithDefaults(e.validationOptions,a),t.serviceName&&(e.dataService=new j({serviceName:e.serviceName})),e.serviceName=e.dataService&&e.dataService.serviceName,e.keyGeneratorCtor=e.keyGeneratorCtor||ar,(r||t.keyGeneratorCtor)&&(e.keyGenerator=new e.keyGeneratorCtor)},e.prototype.createEntity=function(e,t,r,n){v(e,"entityType").isString().or().isInstanceOf(kt).check(),v(r,"entityState").isEnumOf(Ne).isOptional().check(),v(n,"mergeStrategy").isEnumOf(be).isOptional().check();var i="string"==typeof e?this.metadataStore._getStructuralType(e):e;r=r||Ne.Added;var a={};return m.using(this,"isLoading",!0,function(){a=i.createEntity(t)}),r!==Ne.Detached&&(a=this.attachEntity(a,r,n)),a},e.importEntities=function(t,r){var n=new e;return n.importEntities(t,r),n},e.prototype.acceptChanges=function(){this.getChanges().map(function(e){return e.entityAspect._checkOperation("acceptChanges")}).forEach(function(e){e.acceptChanges()})},e.prototype.exportEntities=function(e,t){v(e,"entities").isArray().isEntity().or().isNonEmptyArray().isInstanceOf(kt).or().isNonEmptyArray().isString().or().isOptional().check(),null==t?t={includeMetadata:!0,asString:!0}:"boolean"==typeof t&&(t={includeMetadata:t,asString:!0}),D(t).whereParam("asString").isBoolean().isOptional().withDefault(!0).whereParam("includeMetadata").isBoolean().isOptional().withDefault(!0).applyAll(t);var r=function(e,t){var r,n=t&&t[0];if(n)if(r={},n.entityType){var i=t;i.forEach(function(e){if(e.entityAspect.entityState===Ne.Detached)throw new Error("Unable to export an entity with an EntityState of 'Detached'");var t=r[e.entityType.name];t||((t={}).entityType=e.entityType,t._entities=[],r[e.entityType.name]=t),t._entities.push(e)})}else{var a=Sr(e,t);null!=a&&a.forEach(function(t){var n=e._entityGroupMap[t.name];n&&n._entities.length&&(r[t.name]=n)})}else r=t&&0===t.length?{}:e._entityGroupMap;var o=[],s={};return m.objectForEach(r,function(e,t){s[e]=function(e,t){var r={},n=e.entityType,i=n.dataProperties,a=Kr(n),o=[];return e._entities.forEach(function(e){if(e){var r=function n(e,t,r,i){var a={};if(t.forEach(function(t){var i=t.name,o=e.getProperty(i);if(null!=o||null!=t.defaultValue){if(o&&t.isComplexProperty){var s=t.dataType.dataProperties;o=m.map(o,function(e){return n(e,s,r)})}else o=r?r(t,o):o,t.isUnmapped&&(o=m.toJSONSafe(o));o!==undefined&&(a[i]=o)}}),lt.isEntity(e)){var o=e.entityAspect,s=o.entityState,u={tempNavPropNames:Ar(o,i||[]),entityState:s.name};o.extraMetadata&&(u.extraMetadata=o.extraMetadata),(s.isModified()||s.isDeleted())&&(u.originalValuesMap=o.originalValues),a.entityAspect=u}else{var o=e.complexAspect,u={};o.originalValues&&!m.isEmpty(o.originalValues)&&(u.originalValuesMap=o.originalValues),a.complexAspect=u}return a}(e,i,a,t);o.push(r)}}),r.entities=o,r}(t,o)}),{entityGroupMap:s,tempKeys:o}}(this,e),n=m.extend({},r,["tempKeys","entityGroupMap"]);return t.includeMetadata?(n=m.extend(n,this,["dataService","saveOptions","queryOptions","validationOptions"])).metadataStore=this.metadataStore.exportMetadata():(n.metadataVersion=xt.metadataVersion,n.metadataStoreName=this.metadataStore.name),t.asString?JSON.stringify(n,null,K.stringifyPad):n},e.prototype.importEntities=function(e,t){var r=this;D(t=t||{}).whereParam("mergeStrategy").isEnumOf(be).isOptional().withDefault(this.queryOptions.mergeStrategy).whereParam("metadataVersionFn").isFunction().isOptional().whereParam("mergeAdds").isBoolean().isOptional().applyAll(t);var n="string"==typeof e?JSON.parse(e):e;n.metadataStore?(this.metadataStore.importMetadata(n.metadataStore),this.dataService=n.dataService&&j.fromJSON(n.dataService)||new j({serviceName:n.serviceName}),this.saveOptions=new ir(n.saveOptions),this.queryOptions=xe.fromJSON(n.queryOptions),this.validationOptions=new rr(n.validationOptions)):t.metadataVersionFn&&t.metadataVersionFn({metadataVersion:n.metadataVersion,metadataStoreName:n.metadataStoreName});var i={};n.tempKeys.forEach(function(e){var t=Oe.fromJSON(e,r.metadataStore);i[t.toString()]=new Oe(t.entityType,r.keyGenerator.generateTempKeyValue(t.entityType,t.values[0]))});var a=[],o=t;return o.tempKeyMap=i,m.wrapExecution(function(){r._pendingPubs=[]},function(e){r._pendingPubs.forEach(function(e){return e()}),r._pendingPubs=undefined,r._hasChangesAction&&r._hasChangesAction()},function(){m.objectForEach(n.entityGroupMap,function(e,t){var n=r.metadataStore._getStructuralType(e,!1),i=function(e,t,r){var n,i=r.tempKeyMap,a=!!r.mergeAdds,o=e.entityType,s=r.mergeStrategy,u=e.entityManager,p=u.entityChanged,c=[],y=Ut.getRawValueFromClient;return t.entities.forEach(function(t){var r=t.entityAspect,l=o.getEntityKeyFromRawEntity(t,y),f=Ne.fromName(r.entityState);if(!f||f===Ne.Detached)throw new Error("Only entities with a non detached entity state may be imported.");var h=!a&&f.isAdded()&&Or(i,l);if(n=h?undefined:e.findEntityByKey(l))if(s===be.SkipMerge);else{if(s===be.Disallowed)throw new Error("A MergeStrategy of 'Disallowed' prevents "+l.toString()+" from being merged");var d=n.entityAspect.entityState.isUnchanged();(s===be.OverwriteChanges||d)&&(o._updateTargetFromRaw(n,t,y),n.entityAspect.setEntityState(f),p.publish({entityAction:Ae.MergeOnImport,entity:n}))}else n=o._createInstanceCore(),o._updateTargetFromRaw(n,t,y),h&&(n.entityAspect.hasTempKey=!0,n.setProperty(o.keyProperties[0].name,h.values[0]),r.tempNavPropNames&&r.tempNavPropNames.forEach(function(e){var t=o.getNavigationProperty(e),r=t.relatedDataProperties[0].name,a=n.getProperty(r),s=new Oe(t.entityType,[a]),u=Or(i,s);n.setProperty(r,u.values[0])})),n=e.attachEntity(n,f),p.publish({entityAction:Ae.AttachOnImport,entity:n}),f.isUnchanged()||u._notifyStateChange(n,!0);c.push(n)}),c}(Fr(r,n),t,o);i&&i.length&&(a=a.concat(i))}),a.forEach(function(e){e.entityAspect.entityState.isDeleted()||r._linkRelatedEntities(e)})}),{entities:a,tempKeyMapping:i}},e.prototype.clear=function(){m.objectMap(this._entityGroupMap,function(e,t){return t._checkOperation("clear")}).forEach(function(e){e._clear()}),this._entityGroupMap={},this._unattachedChildrenMap=new wr,this.keyGenerator=new this.keyGeneratorCtor,this.entityChanged.publish({entityAction:Ae.Clear}),this._setHasChanges(!1)},e.prototype.createEmptyCopy=function(){return new e(m.extend({},this,["dataService","metadataStore","queryOptions","saveOptions","validationOptions","keyGeneratorCtor"]))},e.prototype.addEntity=function(e){return this.attachEntity(e,Ne.Added)},e.prototype.attachEntity=function(e,t,r){var n=this;v(e,"entity").isRequired().check(),this.metadataStore._checkEntityType(e);var i=v(t,"entityState").isEnumOf(Ne).isOptional().check(Ne.Unchanged),a=v(r,"mergeStrategy").isEnumOf(be).isOptional().check(be.Disallowed);if(e.entityType.metadataStore!==this.metadataStore)throw new Error("Cannot attach this entity because the EntityType ("+e.entityType.name+") and MetadataStore associated with this entity does not match this EntityManager's MetadataStore.");var o=e.entityAspect;if(o){if(o._inProcessEntity)return o._inProcessEntity}else o=new lt(e);var s=o.entityManager;if(s){if(s===this)return e;throw new Error("This entity already belongs to another EntityManager")}var u={};return m.using(this,"isLoading",!0,function(){i.isAdded()&&function(e,t){var r=t.entityAspect.getKey(),n=m.arrayZip(t.entityType.keyProperties,r.values,function(e,t){return e.defaultValue===t?e:null}).filter(function(e){return null!==e});if(n.length)if(t.entityType.autoGeneratedKeyType!==$t.None)e.generateTempKeyValue(t);else if(n.length===r.values.length)throw new Error("Cannot attach an object of type  ("+t.entityType.name+") to an EntityManager without first setting its key or setting its entityType 'AutoGeneratedKeyType' property to something other than 'None'")}(n,e),u=n._attachEntityCore(e,i,a),o._inProcessEntity=u;try{!function(e,t,r,n){t.entityType.navigationProperties.forEach(function(i){var a=t.getProperty(i.name);if(i.isScalar){if(!a)return;e.attachEntity(a,r,n)}else a.forEach(function(t){e.attachEntity(t,r,n)})})}(n,e,i,a)}finally{o._inProcessEntity=undefined}}),this.validationOptions.validateOnAttach&&u.entityAspect.validateEntity(),i.isUnchanged()||this._notifyStateChange(u,!0),this.entityChanged.publish({entityAction:Ae.Attach,entity:u}),u},e.prototype.detachEntity=function(e){v(e,"entity").isEntity().check();var t=e.entityAspect;if(!t)return!1;if(t.entityManager!==this)throw new Error("This entity does not belong to this EntityManager.");return t.setDetached()},e.prototype.fetchMetadata=function(e,t,r){return"function"==typeof e?(r=t,t=e,e=undefined):(v(e,"dataService").isInstanceOf(j).isOptional().check(),v(t,"callback").isFunction().isOptional().check(),v(r,"errorCallback").isFunction().isOptional().check()),br(this.metadataStore.fetchMetadata(e||this.dataService),t,r)},e.prototype.executeQuery=function(e,t,r){var n=this;v(e,"query").isInstanceOf(rt).or().isString().check(),v(t,"callback").isFunction().isOptional().check(),v(r,"errorCallback").isFunction().isOptional().check();var i=xe.resolve([e.queryOptions,this.queryOptions,xe.defaultInstance]),a=j.resolve([e.dataService,this.dataService]);return br(!a.hasServerMetadata||this.metadataStore.hasMetadataFor(a.serviceName)?xr(this,e,i,a):this.fetchMetadata(a).then(function(){return xr(n,e,i,a)}),t,r)},e.prototype.executeQueryLocally=function(e){return Vr(this,e).results},e.prototype.saveChanges=function(e,t,r,n){v(e,"entities").isOptional().isArray().isEntity().check(),v(t,"saveOptions").isInstanceOf(ir).isOptional().check(),v(r,"callback").isFunction().isOptional().check(),v(n,"errorCallback").isFunction().isOptional().check(),t=t||this.saveOptions||ir.defaultInstance;var i=function(e,t){var r;r=t?t.filter(function(t){if(t.entityAspect.entityManager!==e)throw new Error("Only entities in this entityManager may be saved");return!t.entityAspect.entityState.isDetached()}):e.getChanges();return r}(this,e||undefined);if(0===i.length){var a={entities:[],keyMappings:[]};return r&&r(a),Promise.resolve(a)}if(!t.allowConcurrentSaves&&i.some(function(e){return e.entityAspect.isBeingSaved})){var o=new Error("Concurrent saves not allowed - SaveOptions.allowConcurrentSaves is false");return n&&n(o),Promise.reject(o)}!function(e){e.forEach(function(e){var t=[],r=e.entityAspect;m.objectForEach(r._validationErrors,function(e,r){r.isServerError&&t.push(e)}),0!==t.length&&r._processValidationOpAndPublish(function(){t.forEach(function(e){r._removeValidationError(e)})})})}(i);var s=this.saveChangesValidateOnClient(i);if(s)return n&&n(s),Promise.reject(s);var u=j.resolve([t.dataService,this.dataService]),p={entityManager:this,dataService:u,processSavedEntities:function(e){var t=e.entities,r=e.deletedKeys||[];if(0===t.length&&0===r.length)return[];var n=e.keyMappings,i=p.entityManager;return function(e,t){e._inKeyFixup=!0,t.forEach(function(t){var r=e._entityGroupMap[t.entityTypeName];if(!r)throw new Error("Unable to locate the following fully qualified EntityType name: "+t.entityTypeName);r._fixupKey(t.tempValue,t.realValue)}),e._inKeyFixup=!1}(i,n),m.using(i,"isLoading",!0,function(){var e=new sr({query:undefined,entityManager:i,mergeOptions:{mergeStrategy:be.OverwriteChanges},dataService:u});t=e.visitAndMerge(t,{nodeType:"root"})}),r.forEach(function(e){var t=i.metadataStore._getStructuralType(e.entityTypeName),r=new Oe(t,e.keyValues),n=i.findEntityByKey(r);n&&n.entityAspect.setDetached()}),t},resourceName:t.resourceName||this.saveOptions.resourceName||"SaveChanges"},c={entities:i,saveOptions:t};try{return function(e){var t=e.filter(function(e){return e.entityAspect.isBeingSaved=!0,e.entityAspect.entityState.isModified()&&e.entityType.concurrencyProperties.length>0});if(0===t.length)return;t.forEach(function(e){e.entityType.concurrencyProperties.forEach(function(t){!function(e,t){if(e.entityAspect.originalValues[t.name])return;var r=e.getProperty(t.name),n=t.dataType;r||(r=n.defaultValue);if(n.isNumeric)e.setProperty(t.name,r+1);else{if(!n.getConcurrencyValue){if(n===ee.Binary)return;throw new Error("Unable to update the value of concurrency property before saving: "+t.name)}var i=n.getConcurrencyValue(r);e.setProperty(t.name,i)}}(e,t)})})}(i),u.adapterInstance.saveChanges(p,c).then(function(e){var t=p.entityManager;Nr(i,!1);var n=p.processSavedEntities(e);e.entities=n,t._setHasChanges(),r&&r(e);return Promise.resolve(e)}).then(function(e){return e},function(e){Nr(i,!1);var t=function(e,t){var r=t.entityErrors;if(!r)return t;var n=e.entityManager,i=n.metadataStore,a=r.map(function(e){var t,r=null;if(e.keyValues){t=i._getStructuralType(e.entityTypeName);var a=new Oe(t,e.keyValues);r=n.findEntityByKey(a)}if(t&&r){var o=e.propertyName?{propertyName:e.propertyName,property:t.getProperty(e.propertyName)}:{},s=Y.getKey(e.errorName||e.errorMessage,e.propertyName),u=new Y(null,o,e.errorMessage,s);u.isServerError=!0,r.entityAspect.addValidationError(u)}var p=m.extend({entity:r,isServerError:!0},e,["errorName","errorMessage","propertyName"]);return p});return t.entityErrors=a,t}(p,e);n&&n(t);return Promise.reject(t)})}catch(o){return Nr(i,!1),n&&n(o),Promise.reject(o)}},e.prototype.saveChangesValidateOnClient=function(e){if(this.validationOptions.validateOnSave){var t=e.filter(function(e){var t=e.entityAspect;return!(t.entityState.isDeleted()||t.validateEntity())});if(t.length>0){var r=new Error("Client side validation errors encountered - see the entityErrors collection on this object for more detail");return r.entityErrors=(n=[],t.forEach(function(e){m.objectForEach(e.entityAspect._validationErrors,function(t,r){var i=m.extend({entity:e,errorName:r.validator.name},r,["errorMessage","propertyName","isServerError"]);n.push(i)})}),n),r}}var n;return null},e.prototype._findEntityGroup=function(e){return this._entityGroupMap[e.name]},e.prototype.getEntityByKey=function(){for(var e=this,t=[],r=0;r<arguments.length;r++)t[r]=arguments[r];var n,i=_r(this,t).entityKey;return(i._subtypes||[i.entityType]).some(function(t){var r=e._findEntityGroup(t);return null!=(n=r&&r.findEntityByKey(i))}),n||null},e.prototype.fetchEntityByKey=function(){for(var e=this,t=[],r=0;r<arguments.length;r++)t[r]=arguments[r];var n=j.resolve([this.dataService]);return!n.hasServerMetadata||this.metadataStore.hasMetadataFor(n.serviceName)?Pr(this,t):this.fetchMetadata(n).then(function(){return Pr(e,t)})},e.prototype.findEntityByKey=function(e){return this.getEntityByKey(e)},e.prototype.generateTempKeyValue=function(e){v(e,"entity").isEntity().check();var t=e.entityType,r=this.keyGenerator.generateTempKeyValue(t),n=t.keyProperties[0];return e.setProperty(n.name,r),e.entityAspect.hasTempKey=!0,r},e.prototype.hasChanges=function(e){return!!this._hasChanges&&(e===undefined?this._hasChanges:this._hasChangesCore(e))},e.prototype._hasChangesCore=function(e){return Cr(this,Sr(this,e)).some(function(e){return e&&e.hasChanges()})},e.prototype.getChanges=function(e){return Tr(this,Sr(this,e))},e.prototype.rejectChanges=function(){if(!this._hasChanges)return[];var e=Tr(this),t=e.map(function(e){return e.entityAspect._checkOperation("rejectChanges")});return this._hasChanges=!1,t.forEach(function(e){e.rejectChanges()}),this.hasChangesChanged.publish({entityManager:this,hasChanges:!1}),e},e.prototype.getEntities=function(e,t){var r=Sr(this,e);return v(t,"entityStates").isOptional().isEnumOf(Ne).or().isNonEmptyArray().isEnumOf(Ne).check(),function(e,t,r){var n=Cr(e,t),i=[];return n.forEach(function(e){if(e){var t=e.getEntities(r);i=i&&i.length?i.concat(t):t}}),i}(this,r,function(e,t){if(!t)return[];var r=m.toArray(t);return r.forEach(function(e){if(!(e instanceof Ne))throw new Error("The EntityManager.getChanges() 'entityStates' parameter must either be null, an entityState or an array of entityStates")}),r}(0,t))},e.prototype._notifyStateChange=function(e,t){var r={entityAction:Ae.EntityStateChange,entity:e};if(t)this._hasChanges||this._setHasChanges(!0);else if(this._hasChanges){if(this.isLoading)return void(this._hasChangesAction=this._hasChangesAction||function(){this._setHasChanges(null),this.entityChanged.publish(r)}.bind(this));this._setHasChanges()}this.entityChanged.publish(r)},e.prototype._setHasChanges=function(e){null==e&&(e=this._hasChangesCore());var t=this._hasChanges;this._hasChanges=e,e!==t&&this.hasChangesChanged.publish({entityManager:this,hasChanges:e}),this._hasChangesAction=undefined},e.prototype._linkRelatedEntities=function(e){var t=this,r=e.entityAspect;m.using(t,"isLoading",!0,function(){for(var n=t._unattachedChildrenMap,i=r.getKey(),a=i.entityType,o=function(){var t=i.toString(a),r=n.getTuplesByString(t);r&&r.slice(0).forEach(function(r){var i,a,o=r.children.filter(function(e){return e.entityAspect.entityState!==Ne.Detached}),s=r.navigationProperty,u=s.inverse;if(u){if(i=s,(a=u).isScalar){var p=o[0];e.setProperty(a.name,p),p.setProperty(i.name,e)}else{var c=e.getProperty(a.name);o.forEach(function(t){c.push(t),t.setProperty(i.name,e)})}n.removeChildren(t,i)}else if(s.isScalar)i=s,o.forEach(function(t){t.setProperty(i.name,e)}),n.removeChildren(t,i);else{a=s;var y=e.getProperty(a.name);o.forEach(function(e){y._push(e)})}}),a=a.baseEntityType};a;)o();e.entityType.navigationProperties.forEach(function(i){if(i.isScalar&&e.getProperty(i.name))return;var a=r.getParentKey(i);if(a){if(a._isEmpty())return;var o=t.findEntityByKey(a);o?e.setProperty(i.name,o):n.addChild(a,i,e)}}),e.entityType.foreignKeyProperties.forEach(function(r){var i=r.inverseNavigationProperty;if(i){var a=e.getProperty(r.name),o=new Oe(i.parentType,[a]),s=t.findEntityByKey(o);s?i.isScalar?s.setProperty(i.name,e):t.isLoading?s.getProperty(i.name)._push(e):s.getProperty(i.name).push(e):n.addChild(o,i,e)}})})},e.prototype._attachEntityCore=function(e,t,r){var n=Fr(this,e.entityType).attachEntity(e,t,r);return this._linkRelatedEntities(n),n},e.prototype._updateFkVal=function(e,t,r){var n=this._entityGroupMap[e.parentType.name];n&&n._updateFkVal(e,t,r)},e}();function Pr(e,t){var r=_r(e,t),n=r.entityKey,i=0!==r.remainingArgs.length&&!!r.remainingArgs[0],a=null,o=!1;return i&&(o=null!=(a=e.getEntityByKey(n)),null!=a&&!e.queryOptions.includeDeleted&&a.entityAspect.entityState.isDeleted()&&(a=null,o=e.queryOptions.mergeStrategy!==be.OverwriteChanges)),o?Promise.resolve({entity:a||undefined,entityKey:n,fromCache:!0}):rt.fromEntityKey(n).using(e).execute().then(function(e){return a=0===e.results.length?null:e.results[0],Promise.resolve({entity:a||undefined,entityKey:n,fromCache:!1})})}function Sr(e,t){return v(t,"entityTypes").isString().isOptional().or().isNonEmptyArray().isString().or().isInstanceOf(kt).or().isNonEmptyArray().isInstanceOf(kt).check(),"string"==typeof t?e.metadataStore._getStructuralType(t,!1):Array.isArray(t)&&"string"==typeof t[0]?t.map(function(t){return e.metadataStore._getStructuralType(t,!1)}):t}function Tr(e,t){var r=Cr(e,t),n=[];return r.forEach(function(e){if(e){var t=e.getChanges();n=n&&n.length?n.concat(t):t}}),n}function _r(e,t){try{if(t[0]instanceof Oe)return{entityKey:t[0],remainingArgs:m.arraySlice(t,1)};if(t.length>=2){var r="string"==typeof t[0]?e.metadataStore._getStructuralType(t[0],!1):t[0];return{entityKey:new Oe(r,t[1]),remainingArgs:m.arraySlice(t,2)}}}catch(n){}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 Nr(e,t){e.forEach(function(e){e.entityAspect.isBeingSaved=t})}function Ar(e,t){var r=e.entity;e.hasTempKey&&t.push(e.getKey().toJSON());var n=[];return r.entityType.navigationProperties.forEach(function(e){if(e.relatedDataProperties){var t=r.getProperty(e.name);t&&t.entityAspect.hasTempKey&&n.push(e.name)}}),n}function Or(e,t){var r=e[t.toString()];if(r)return r;var n=t._subtypes;if(!n)return null;for(var i=0,a=n.length;i<a;i++)if(r=e[t.toString(n[i])])return r;return null}function br(e,t,r){return e=e.then(function(e){return t&&t(e),Promise.resolve(e)},function(e){return r&&r(e),Promise.reject(e)})}function Cr(e,t){var r=e._entityGroupMap;return t?m.toArray(t).map(function(e){if(e instanceof kt)return r[e.name];throw new Error("The EntityManager.getChanges() 'entityTypes' parameter must be either an entityType or an array of entityTypes or null")}):m.getOwnPropertyValues(r)}function xr(e,t,r,n){try{var i;if(e.metadataStore.isEmpty()&&n.hasServerMetadata)throw new Error("cannot execute _executeQueryCore until metadataStore is populated.");if(r.fetchStrategy===Ce.FromLocalCache)try{if("string"==typeof t)throw new Error("cannot execute 'string' EntityQuery locally.");var a=Vr(e,t);return Promise.resolve({results:a.results,entityManager:e,inlineCount:a.inlineCount,query:t})}catch(u){return Promise.reject(u)}var o=new sr({query:t,entityManager:e,dataService:n,mergeOptions:{mergeStrategy:r.mergeStrategy,noTracking:!!t.noTrackingEnabled,includeDeleted:r.includeDeleted}}),s=e.validationOptions.validateOnQuery;return n.adapterInstance.executeQuery(o).then(function(r){var a=m.wrapExecution(function(){var t={isLoading:e.isLoading};return e.isLoading=!0,e._pendingPubs=[],t},function(t){if(e.isLoading=t.isLoading,e._pendingPubs.forEach(function(e){e()}),e._pendingPubs=undefined,e._hasChangesAction&&e._hasChangesAction(),o=undefined,t.error)return Promise.reject(t.error)},function(){var a=n.jsonResultsAdapter.extractResults(r);a=m.toArray(a),i=o.visitAndMerge(a,{nodeType:"root"}),s&&i.forEach(function(e){e.entityAspect&&e.entityAspect.validateEntity()}),o.processDeferred(),t instanceof rt&&function(e,t){if(t.noTrackingEnabled)return;var r=t.expandClause;if(null==r)return;r.propertyPaths.forEach(function(t){var r=t.split(".");!function n(e,t){var r=t[0];e.forEach(function(e){var i=e.entityAspect;if(i&&(i._markAsLoaded(r),1!==t.length)){var a=e.getProperty(r);a&&(a.arrayChanged||(a=[a]),n(a,t.slice(1)))}})}(e,r)})}(i,t);var u=m.objectMap(o.refMap);return{results:i,query:t,entityManager:e,httpResponse:r.httpResponse,inlineCount:r.inlineCount,retrievedEntities:u}});return Promise.resolve(a)},function(r){return r&&(r.query=t,r.entityManager=e),Promise.reject(r)})}catch(u){return u&&(u.query=t),Promise.reject(u)}}function Fr(e,t){var r=e._entityGroupMap[t.name];return r||(r=new or(e,t),e._entityGroupMap[t.name]=r),r}function Mr(e,t){var r={},n=lt.isEntity(e)?e.entityType:e.complexType,i=Kr(n),a={};return n.dataProperties.forEach(function(n){if(n.isComplexProperty)r[n.nameOnServer]=m.map(e.getProperty(n.name),function(e){return Mr(e,t)});else{var o=e.getProperty(n.name);if((o=t?t(n,o):o)===undefined)return;(o=i?i(n,o):o)!==undefined&&(n.isUnmapped?a[n.nameOnServer]=m.toJSONSafe(o):r[n.nameOnServer]=o)}}),m.isEmpty(a)||(r.__unmapped=a),r}function Dr(e,t,r){var n=lt.isEntity(e)?e.entityType:e.complexType,i=lt.isEntity(e)?e.entityAspect:e.complexAspect,a=t.namingConvention.clientPropertyNameToServer,o={};return m.objectForEach(i.originalValues,function(e,t){var i=n.getProperty(e);(t=r?r(i,t):t)!==undefined&&(o[a(e,i)]=t)}),n.complexProperties.forEach(function(n){var i=e.getProperty(n.name);if(n.isScalar){var s=Dr(i,t,r);m.isEmpty(s)||(o[a(n.name,n)]=s)}else{var u=i.map(function(e){return Dr(e,t,r)});o[a(n.name,n)]=u}}),o}function kr(e,t,r){var n=e.entityType,i=Kr(n),a=t.namingConvention.clientPropertyNameToServer,o={};return m.objectForEach(e.entityAspect.originalValues,function(t,s){var u=n.getProperty(t),p=e.getProperty(t);(p=r?r(u,p):p)!==undefined&&(p=i?i(u,p):p)!==undefined&&(o[a(t,u)]=p)}),n.complexProperties.forEach(function(t){if(Ir(e,t)){var n=e.getProperty(t.name);o[a(t.name,t)]=m.map(n,function(e){return Mr(e,r)})}}),o}function Ir(e,t){var r=e.getProperty(t.name);return t.isScalar?Rr(r):!!r._origValues||r.some(function(e){return Rr(e)})}function Vr(e,t){v(t,"query").isInstanceOf(rt).check();var r=e.metadataStore,n=t._getFromEntityType(r,!0),i=function(e,t){return t.getSelfAndSubtypes().map(function(t){return Fr(e,t)})}(e,n),a=t.wherePredicate&&t.wherePredicate.toFunction({entityType:n}),o=!0===xe.resolve([t.queryOptions,e.queryOptions,xe.defaultInstance]).includeDeleted,s=function(e){return e&&(o||!e.entityAspect.entityState.isDeleted())&&(!a||a(e))},u=[];i.forEach(function(e){var t=e._entities.filter(s);t.length&&(u=u.length?u.concat(t):t)});var p=t.orderByClause&&t.orderByClause.getComparer(n);p&&u.sort(p);var c=t.inlineCountEnabled?u.length:undefined,y=t.skipCount;y&&(u=u.slice(y));var l=t.takeCount;l&&(u=u.slice(0,l));var f=t.selectClause;if(f){var h=f.toFunction();u=u.map(h)}return{results:u,inlineCount:c}}function Rr(e){return!m.isEmpty(e.complexAspect.originalValues)||e.complexType.complexProperties.some(function(t){return Ir(e,t)})}function Kr(e){return e.serializerFn||e.metadataStore&&e.metadataStore.serializerFn}Er.prototype._$typeName="EntityManager",I.bubbleEvent(Er.prototype);var jr=function(){return function(){this.ajax=new V("ajax"),this.modelLibrary=new V("modelLibrary"),this.dataService=new V("dataService"),this.uriBuilder=new V("uriBuilder")}}();K.interfaceRegistry=new jr,K._interfaceRegistry=K.interfaceRegistry,K.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},K.initializeAdapterInstances=function(e){return D(e).whereParam("dataService").isOptional().whereParam("modelLibrary").isOptional().whereParam("ajax").isOptional().whereParam("uriBuilder").isOptional().applyAll(this,!1),m.objectMap(K,this.initializeAdapterInstance)};function qr(e,t,r){var n=e._getPendingPubs();n?e._pendingArgs?function(e,t){for(var r in t)if("array"!==r&&e.hasOwnProperty(r)){var n=t[r],i=e[r];if(i){if(!Array.isArray(i))throw new Error("Cannot combine non array args");Array.prototype.push.apply(i,n)}else e[r]=n}}(e._pendingArgs,r):(e._pendingArgs=r,n.push(function(){e[t].publish(e._pendingArgs),e._pendingArgs=null})):e[t].publish(r)}function Br(e,t){e._processAdds(t),qr(e,"arrayChanged",{array:e,added:t})}function Lr(e,t){e._processRemoves(t),qr(e,"arrayChanged",{array:e,removed:t})}var Ur={mixin:{push:function(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];if(this._inProgress)return-1;var r=this._getGoodAdds(e);if(!r.length)return this.length;this._beforeChange();var n=Array.prototype.push.apply(this,r);return Br(this,r),n},_push:function(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];if(this._inProgress)return-1;var r=e;this._beforeChange();var n=Array.prototype.push.apply(this,r);return Br(this,r),n},unshift:function(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];var r=this._getGoodAdds(e);if(!r.length)return this.length;this._beforeChange();var n=Array.prototype.unshift.apply(this,r);return Br(this,r),n},pop:function(){this._beforeChange();var e=Array.prototype.pop.apply(this);return Lr(this,[e]),e},shift:function(){this._beforeChange();var e=Array.prototype.shift.apply(this);return Lr(this,[e]),e},splice:function(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];var r=this._getGoodAdds(m.arraySlice(e,2)),n=m.arraySlice(e,0,2).concat(r);this._beforeChange();var i=Array.prototype.splice.apply(this,n);return Lr(this,i),r.length&&Br(this,r),i},getEntityAspect:function(){return this.parent.entityAspect||this.parent.complexAspect.getEntityAspect()},_getEventParent:function(){return this.getEntityAspect()},_getPendingPubs:function(){var e=this.getEntityAspect().entityManager;return e&&e._pendingPubs},_beforeChange:function(){}},updateEntityState:function(e){var t=e.getEntityAspect();t.entityState.isUnchanged()&&t.setModified(),t.entityState.isModified()&&!e._origValues&&(e._origValues=e.slice(0))},publish:qr,initializeParent:function(e,t,r){e.parent=t,e.parentProperty=r}},zr={load:function(e,t){var r=this.parentEntity,n=rt.fromEntityNavigation(this.parentEntity,this.navigationProperty);return r.entityAspect.entityManager.executeQuery(n,e,t)},_getEventParent:function(){return this.parentEntity.entityAspect},_getPendingPubs:function(){var e=this.parentEntity.entityAspect.entityManager;return e&&e._pendingPubs},_getGoodAdds:function(e){return function(e,t){var r=function(e,t){var r,n=e.parentEntity,i=e.navigationProperty,a=i.inverse;if(a)r=t.filter(function(t){if(e._addsInProcess.indexOf(t)>=0)return!1;var r=t.getProperty(a.name);return r!==n});else{var o=i.invForeignKeyNames,s=n.entityType.keyProperties;r=t.filter(function(t){return!(e._addsInProcess.indexOf(t)>=0)&&o.some(function(e,r){var i=s[r].name,a=n.getProperty(i),o=t.getProperty(e);return a!==o})})}return r}(e,t);if(!r.length)return r;var n=e.parentEntity.entityAspect.entityManager;return n&&!n.isLoading&&r.forEach(function(t){if(t.entityAspect.entityState.isDetached()){e._inProgress=!0;try{n.attachEntity(t,Ne.Added)}finally{e._inProgress=!1}}}),r}(this,e)},_processAdds:function(e){!function(e,t){var r=e.parentEntity,n=e.navigationProperty,i=e._addsInProcess,a=n.inverse,o=i.length;try{t.forEach(function(e){if(i.push(e),a)e.setProperty(a.name,r);else{var t=r.entityType.keyProperties;n.invForeignKeyNames.forEach(function(n,i){e.setProperty(n,r.getProperty(t[i].name))})}})}finally{i.splice(o,t.length)}}(this,e)},_processRemoves:function(e){!function(e,t){var r=e.navigationProperty.inverse;r&&t.forEach(function(e){e.setProperty(r.name,null)})}(this,e)}};function Gr(e,t,r){var n=e;return n.parentEntity=t,n.navigationProperty=r,n.arrayChanged=new I("arrayChanged",n),n._addsInProcess=[],m.extend(n,Ur.mixin),m.extend(n,zr)}var $r={_getGoodAdds:function(e){return function(e,t){return t.filter(function(t){return null==t.complexAspect||t.complexAspect.parent!==e.parent})}(this,e)},_beforeChange:function(){Ur.updateEntityState(this)},_processAdds:function(e){!function(e,t){t.forEach(function(t){if(t.complexAspect&&null!=t.complexAspect.parent)throw new Error("The complexObject is already attached. Either clone it or remove it from its current owner");var r,n;r=e,(n=t.complexAspect).parent!==r.parent&&(n.parent=r.parent,n.parentProperty=r.parentProperty)})}(this,e)},_processRemoves:function(e){!function(e,t){t.forEach(function(t){Jr(t,e)})}(this,e)},_rejectChanges:function(){if(this._origValues){var e=this;this.forEach(function(t){Jr(t,e)}),this.length=0,this._origValues.forEach(function(t){e.push(t)})}},_acceptChanges:function(){this._origValues=null}};function Jr(e,t){var r=e.complexAspect;return r.parent!==t.parent?null:(r.parent=undefined,r.parentProperty=undefined,r)}function Qr(e,t,r){var n=e;return Ur.initializeParent(n,t,r),n.arrayChanged=new I("arrayChanged",n),m.extend(n,Ur.mixin),m.extend(n,$r)}var Zr={_getGoodAdds:function(e){return e},_beforeChange:function(){var e=this.getEntityAspect();e.entityState.isUnchanged()&&e.setModified(),e.entityState.isModified()&&!this._origValues&&(this._origValues=this.slice(0))},_processAdds:function(e){},_processRemoves:function(e){},_rejectChanges:function(){this._origValues&&(this.length=0,Array.prototype.push.apply(this,this._origValues))},_acceptChanges:function(){this._origValues=null}};function Wr(e,t,r){var n=e;return Ur.initializeParent(n,t,r),n.arrayChanged=new I("arrayChanged",n),m.extend(n,Ur.mixin),m.extend(n,Zr)}var Hr,Yr={AbstractDataServiceAdapter:Xt,AutoGeneratedKeyType:$t,BooleanQueryOp:st,ComplexAspect:vt,ComplexType:Lt,DataProperty:Ut,DataService:j,DataType:ee,EntityAction:Ae,EntityAspect:lt,EntityKey:Oe,EntityManager:Er,EntityQuery:rt,EntityState:Ne,EntityType:kt,Event:I,FetchStrategy:Ce,FilterQueryOp:ot,InterfaceRegistry:jr,JsonResultsAdapter:B,KeyGenerator:ar,LocalQueryComparisonOptions:Ot,MergeStrategy:be,MetadataStore:xt,NamingConvention:Et,NavigationProperty:zt,OrderByClause:ut,Predicate:Fe,QueryOptions:xe,SaveOptions:ir,ValidationError:Y,ValidationOptions:rr,Validator:J,assertConfig:null,assertParam:null,config:K,core:m,makeComplexArray:Qr,makePrimitiveArray:Wr,makeRelationArray:Gr,version:"2.0.0-alpha.13"};try{Hr=window||(global?global.window:undefined)}catch(Xr){}Hr&&(Hr.breeze=Yr),e.AbstractDataServiceAdapter=Xt,e.AndOrPredicate=je,e.AnyAllPredicate=qe,e.AutoGeneratedKeyType=$t,e.BinaryPredicate=Ke,e.BreezeConfig=R,e.ComplexAspect=vt,e.ComplexType=Lt,e.DataProperty=Ut,e.DataService=j,e.DataType=ee,e.EntityAction=Ae,e.EntityAspect=lt,e.EntityKey=Oe,e.EntityManager=Er,e.EntityQuery=rt,e.EntityState=Ne,e.EntityType=kt,e.ExpandClause=yt,e.FetchStrategy=Ce,e.FilterQueryOp=ot,e.FnExpr=ze,e.InterfaceRegistry=jr,e.JsonResultsAdapter=B,e.KeyGenerator=ar,e.LitExpr=Le,e.LocalQueryComparisonOptions=Ot,e.MappingContext=sr,e.MergeStrategy=be,e.MetadataStore=xt,e.NamingConvention=Et,e.NavigationProperty=zt,e.OrderByClause=ut,e.Predicate=Fe,e.PropExpr=Ue,e.QueryOptions=xe,e.SaveOptions=ir,e.SelectClause=ct,e.UnaryPredicate=Re,e.ValidationError=Y,e.ValidationOptions=rr,e.Validator=J,e.breeze=Yr,e.config=K,e.core=m,e.makeComplexArray=Qr,e.makePrimitiveArray=Wr,e.makeRelationArray=Gr,e.ɵa=Be,e.ɵb=Ht,e.ɵc=st,e.ɵd=a,e.ɵe=I,Object.defineProperty(e,"__esModule",{value:!0})});
//# sourceMappingURL=cdt-breeze-client.umd.min.js.map