breeze-client 2.1.6 → 2.1.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +1 -1
- package/breeze-client.metadata.json +1 -1
- package/bundles/breeze-client.umd.js +88 -38
- package/bundles/breeze-client.umd.js.map +1 -1
- package/bundles/breeze-client.umd.min.js +1 -1
- package/bundles/breeze-client.umd.min.js.map +1 -1
- package/esm2015/src/abstract-data-service-adapter.js +68 -37
- package/esm2015/src/entity-query.js +23 -4
- package/esm5/src/abstract-data-service-adapter.js +68 -37
- package/esm5/src/entity-query.js +23 -4
- package/fesm2015/breeze-client.js +88 -38
- package/fesm2015/breeze-client.js.map +1 -1
- package/fesm5/breeze-client.js +88 -38
- package/fesm5/breeze-client.js.map +1 -1
- package/package.json +1 -1
- package/src/abstract-data-service-adapter.d.ts +20 -0
- package/src/entity-query.d.ts +17 -3
|
@@ -12,5 +12,5 @@
|
|
|
12
12
|
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
|
13
13
|
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
|
14
14
|
PERFORMANCE OF THIS SOFTWARE.
|
|
15
|
-
***************************************************************************** */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(e){i={error:e}}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=P(Object.prototype.hasOwnProperty),s=P(Array.prototype.slice),u=function(){try{return!(!Object.getPrototypeOf||!Object.defineProperty({},"x",{}))}catch(e){return!1}}();function p(e,t){if(u){if(e.hasOwnProperty(t))return Object.getOwnPropertyDescriptor(e,t);var r=Object.getPrototypeOf(e);if(null!=r)return p(r,t)}}function c(e,t){for(var r in t)void 0===e[r]&&(e[r]=t[r]);return e}function y(e){var t=window||(global?global.window:void 0);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):void 0;try{return n(e)}catch(e){return}}}}var l=/[xy]/g;var f=/^P((\d+Y)?(\d+M)?(\d+D)?)?(T(\d+H)?(\d+M)?(\d+S)?)?$/,h=/[A-Za-z]+/g;function d(e){return null===e?"null":void 0===e?"undefined":Object.prototype.toString.call(e).slice(8,-1).toLowerCase()}var m=/^((\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)))$/;function g(e){return"function"===d(e)}var v=/^[a-fA-F\d]{8}-(?:[a-fA-F\d]{4}-){3}[a-fA-F\d]{12}$/;var w=/^(-|)?P[T]?[\d\.,\-]+[YMDTHS]/;var E=/([A-Z](?=[A-Z][a-z])|[^A-Z](?=[A-Z])|[a-zA-Z](?=[^a-zA-Z]))/g;function P(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 S={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];void 0!==i&&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(void 0!==o){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 e(t,r,n){if(!t||!r)return!1;if(t.length!==r.length)return!1;for(var i=0;i<t.length;i++)if(Array.isArray(t[i])){if(!e(t[i],r[i]))return!1}else if(n){if(!n(t[i],r[i]))return!1}else if(t[i]!==r[i])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=g(t)?t:void 0,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){if(!e)return n();var i=e[t];if(r===i)return n();e[t]=r;try{return n()}finally{void 0===i?delete e[t]:e[t]=i}},wrapExecution:function(e,t,r){var n;try{return n=e(),r()}catch(e){throw"object"==typeof n&&(n.error=e),e}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(l,(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=f.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(h,""):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"===d(e)&&!isNaN(e.getTime())},isDateString:function(e){return"string"==typeof e&&m.test(e)},isGuid:function(e){return"string"==typeof e&&v.test(e)},isDuration:function(e){return"string"==typeof e&&w.test(e)},isFunction:g,isEmpty:function(e){if(null==e)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(E,"$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),void 0===n||(r[i[0]]=n),!0)))}))};for(var i in t)n(i);return r},toJSONSafe:function e(t,r){if(t!==Object(t))return t;if(!t._$visited){if(t.toJSON){var n=t.toJSON();if(n!==Object(n))return n;if(n!==t)return e(n,r);t=n}var i;if(t._$visited=!0,t instanceof Array)i=t.map((function(t){return e(t,r)}));else if("function"==typeof t)i=void 0;else for(var a in i={},t)if("_$visited"!==a){var o=t[a];r&&void 0===(o=r(a,o))||void 0!==(o=e(o,r))&&(i[a]=o)}return delete t._$visited,i}},toJSONSafeReplacer:function(e,t){if("entityAspect"!==e&&"complexAspect"!==e&&"entityType"!==e&&"complexType"!==e&&"getProperty"!==e&&"setProperty"!==e&&"constructor"!==e&&"_"!==e.charAt(0)&&"$"!==e.charAt(0))return t},strings:{TO_TYPE:"Add 'EntityQuery.toType()' to your query, or call 'MetadataStore.setEntityTypeForResourceName()' to register an EntityType for this resourceName."}},T=function(){function e(e,t){this._applyOne=function(e){void 0!==this.v?e[this.name]=this.v:void 0!==this.defaultValue&&(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 V(this,{fn:O,msg:"must be a nonEmpty string"})},e.prototype.isTypeOf=function(e){return V(this,{fn:N,typeName:e,msg:"must be a '"+e+"'"})},e.prototype.isInstanceOf=function(e,t){return V(this,{fn:A,type:e,typeName:t=t||e.prototype._$typeName,msg:"must be an instance of '"+t+"'"})},e.prototype.hasProperty=function(e){return V(this,{fn:C,propertyName:e,msg:"must have a '"+e+"' property"})},e.prototype.isEnumOf=function(e){return V(this,{fn:b,enumType:e,msg:"must be an instance of the '"+(e.name||"unknown")+"' enumeration"})},e.prototype.isRequired=function(e){return void 0===e&&(e=!1),V(this,{fn:x,allowNull:e,msg:"is required"})},e.prototype.isOptional=function(){return V(this,{fn:F,prevContext:null,msg:D})},e.prototype.isNonEmptyArray=function(){return this.isArray(!0)},e.prototype.isArray=function(e){return V(this,{fn:M,mustNotBeEmpty:e,prevContext:null,msg:k})},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;return t.some((function(t){return!!t.fn&&t.fn(t,e.v)}))}(this);if(void 0!==t){if(!t)throw new Error(this.getMessage());return void 0!==this.v?this.v:e}},e.prototype._addContext=function(e){return V(this,e)},e.prototype.getMessage=function(){var e=this,t=this._contexts.map((function(t){return I(t,e.v)})).join(", or it ");return S.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=S.extend({},this.parent.config);if(this.parent.params.forEach((function(r){n||delete i[r.name];try{r.check()}catch(t){R(e,t.message)}!t&&r._applyOne(e)})),!n)for(var a in i)void 0!==i[a]&&R(e,S.formatString("Unknown property: '%1'.",a))},e}(),_=function(e,t){return new T(e,t)};function N(e,t){return null!=t&&typeof t===e.typeName}function O(e,t){return null!=t&&("string"==typeof t&&t.length>0)}function A(e,t){return null!=t&&null!=e.type&&t instanceof e.type}function b(e,t){return null!=t&&null!=e.enumType&&e.enumType.contains(t)}function C(e,t){return null!=t&&null!=e.propertyName&&void 0!==t[e.propertyName]}function x(e,t){return e.allowNull?void 0!==t:null!=t}function F(e,t){if(null==t)return!0;var r=e.prevContext;return!r||!r.fn||r.fn(r,t)}function D(e,t){var r=e.prevContext;return"is optional"+(r?" or it "+I(r,t):"")}function M(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 k(e,t){var r=e.mustNotBeEmpty?"a nonEmpty array":"an array",n=e.prevContext;return" must be "+r+(n?" where each element "+I(n,t):"")}function I(e,t){var r=e.msg;return"function"==typeof r&&(r=r(e,t)),r}function V(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 R(e,t){throw new Error(S.formatString("Error configuring an instance of '%1'. %2",e&&e._$typeName||"object",t))}var K=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 T(this.config[e],e);return t.parent=this,this.params.push(t),t},e}(),j=function(e){return new K(e)};function q(e,t,r){var n=e._subscribers;if(!n)return!0;n.forEach((function(n){try{n.callback(t)}catch(t){t.context="unable to publish on topic: "+e.name,r?r(t):e._defaultErrorCallback&&e._defaultErrorCallback(t)}}))}S.Param=T,S.assertParam=_,S.assertConfig=j;var B=function(){function e(t,r,n){this.unsubscribe=function(e){if(!this._subscribers)return!1;var t=this._subscribers,r=S.arrayIndexOf(t,(function(t){return t.unsubKey===e}));return-1!==r&&(t.splice(r,1),0===t.length&&(this._subscribers=null),!0)},_(t,"eventName").isNonEmptyString().check(),_(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(q,0,this,t,n):q(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){_(e,"eventName").isNonEmptyString().check(),_(t,"obj").isObject().check(),_(r,"isEnabled").isBoolean().isOptional().or().isFunction().check();var n=t;n._$eventMap||(n._$eventMap={}),n._$eventMap[e]=r},e.isEnabled=function(t,r){if(_(t,"eventName").isNonEmptyString().check(),_(r,"obj").isObject().check(),void 0===r._getEventParent)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}();S.Event=B;var L=function(){function e(e){this.name=e,this.defaultInstance=void 0,this._implMap={}}return e.prototype.registerCtor=function(e,t){this._implMap[e.toLowerCase()]={ctor:t,defaultInstance:void 0}},e.prototype.getImpl=function(e){return this._implMap[e.toLowerCase()]},e.prototype.getFirstImpl=function(){var e=S.objectFirst(this._implMap,(function(){return!0}));return e?e.value:null},e.prototype.getDefaultInstance=function(){return this.defaultInstance},e}(),U=function(){function e(){if(this.functionRegistry={},this.typeRegistry={},this.objectRegistry={},this.stringifyPad="",this.interfaceInitialized=new B("interfaceInitialized",this),void 0===this.noEval)try{Error.x=Function(""),this.noEval=!1}catch(e){this.noEval=!0}}return e.prototype.registerAdapter=function(e,t){_(e,"interfaceName").isNonEmptyString().check(),_(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=void 0===r||r,_(e,"interfaceName").isNonEmptyString().check(),_(t,"adapterName").isNonEmptyString().check(),_(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);if(r)return r.defaultInstance?r.defaultInstance:this._initializeAdapterInstanceCore(n,r,i)},e.prototype.registerFunction=function(e,t){_(e,"fn").isFunction().check(),_(t,"fnName").isString().check(),e.prototype&&(e.prototype._$fnName=t),this.functionRegistry[t]=e},e.prototype.registerType=function(e,t){_(e,"ctor").isFunction().check(),_(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=S.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){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}(),z=new U;S.config=z;var $=function(){function e(e){G(this,e)}return e.prototype.using=function(t){return t?G(new e(this),t):this},e.resolve=function(t){t.push({hasServerMetadata:!0,useJsonp:!1});var r=new e(S.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||z.getAdapterInstance("dataService",r.adapterName),r.jsonResultsAdapter=r.jsonResultsAdapter||r.adapterInstance.jsonResultsAdapter,r.uriBuilder=r.uriBuilder||z.getAdapterInstance("uriBuilder",r.uriBuilderName),r},e._normalizeServiceName=function(e){return"/"!==(e=e.trim()).substr(-1)?e+"/":e},e.prototype.toJSON=function(){return S.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=z._fetchObject(J,t.jsonResultsAdapter),new e(t)},e.prototype.qualifyUrl=function(e){if(e&&e.startsWith("http"))return e;var t=this.serviceName;return S.stringEndsWith(t,"/")&&(t=t.substr(0,t.length-1)),e="/"+e,S.stringEndsWith(t,e)||(t+=e),t},e}();function G(e,t){return t&&(j(t).whereParam("serviceName").isOptional().whereParam("adapterName").isString().isOptional().whereParam("uriBuilderName").isString().isOptional().whereParam("hasServerMetadata").isBoolean().isOptional().whereParam("jsonResultsAdapter").isInstanceOf(J).isOptional().whereParam("useJsonp").isBoolean().isOptional().applyAll(e),e.serviceName=e.serviceName&&$._normalizeServiceName(e.serviceName),e.adapterInstance=e.adapterName?z.getAdapterInstance("dataService",e.adapterName):void 0,e.uriBuilder=e.uriBuilderName?z.getAdapterInstance("uriBuilder",e.uriBuilderName):void 0),e}$.prototype._$typeName="DataService";var J=function(e){if(1!==arguments.length)throw new Error("The JsonResultsAdapter ctor should be called with a single argument that is a configuration object.");j(e).whereParam("name").isNonEmptyString().whereParam("extractResults").isFunction().isOptional().withDefault(Q).whereParam("extractSaveResults").isFunction().isOptional().withDefault(W).whereParam("extractKeyMappings").isFunction().isOptional().withDefault(Z).whereParam("extractDeletedKeys").isFunction().isOptional().withDefault(H).whereParam("visitNode").isFunction().applyAll(this),z._storeObject(this,"JsonResultsAdapter",this.name)};function Q(e){return e.results}function W(e){return e.entities||e.Entities||[]}function Z(e){return e.keyMappings||e.KeyMappings||[]}function H(e){return e.deletedKeys||e.DeletedKeys||[]}J.prototype._$typeName="JsonResultsAdapter";var Y={displayName:function(e){return e.property?e.property.resolveProperty("displayName")||e.propertyName||e.property.name:"Value"}},X=function(){function e(t,r,n){this._baseContext=n||{},this._baseContext.name=t,(n=S.extend(Object.create(Y),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?S.extend(Object.create(this.context),t):this.context,this.currentContext=r;try{return this.valFn(e,r)?null:(r.value=e,new ie(this,r,this.getMessage()))}catch(e){return new ie(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])?S.isFunction(i)?i(t):i:""})):e}(e.messageTemplate,e):"invalid value: "+(this.name||"{unnamed validator}")}catch(e){return"Unable to format error message"+e.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)}));if(t instanceof e)return t;var r="Validator."+t.name,n=z.getRegisteredFunction(r);if(!n)throw new Error("Unable to locate a validator named:"+t.name);return n(t)},e.register=function(e){z.registerFunction((function(){return e}),"Validator."+e.name)},e.registerFactory=function(e,t){z.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||S.isGuid(e)}))},e.duration=function(){return new e("duration",(function(e){return null==e||S.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 ee("int32",-2147483648,2147483647,e)()},e.int16=function(e){return ee("int16",-32768,32767,e)()},e.byte=function(e){return ee("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 S.isDate(e);try{return!isNaN(Date.parse(e))}catch(e){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))&&ne(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(e){throw new Error("Missing or invalid expression parameter to regExp validator")}}),t)},e.emailAddress=function(e){return te("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 te("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 te("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=te,e}();function ee(e,t,r,n){return n=n||{},void 0!==t&&(n.min=t),void 0!==r&&(n.max=r),n.messageTemplate||X.messageTemplates[e]||(X.messageTemplates[e]=S.formatString("'%displayName%' must be an integer between the values of %1 and %2",t,r)),function(){return new X(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 te(e,t,r,n){r&&(X.messageTemplates[e]=r);var i="string"==typeof t?new RegExp(t):t;return new X(e,(function(e){return null==e||""===e||"string"==typeof e&&i.test(e)}),n)}X.prototype._$typeName="Validator",Error.x=S.objectForEach(X,(function(e,t){"function"==typeof t&&"fromJSON"!==e&&"register"!==e&&"registerFactory"!==e&&"makeRegExpValidator"!==e&&z.registerFunction(t,"Validator."+e)}));var re,ne=(re=[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:re[t];return r%10==0}),ie=function(){function e(t,r,n,i){_(t,"validator").isOptional().isInstanceOf(X).check(),_(n,"errorMessage").isNonEmptyString().check(),_(i,"key").isOptional().isNonEmptyString().check(),this.validator=t||void 0,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}(),ae=/.\d{3}$/,oe=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&&S.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(S.isDate(e))return t.DateTime;switch(typeof e){case"string":return S.isGuid(e)?t.Guid:S.isDuration(e)&&e.length>3?t.Time:S.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=ae.test(e)?e+"Z":e);return e=new Date(Date.parse(e))},t.parseDateAsLocal=function(e){var r=t.parseDateAsUTC(e);return S.isDate(r)&&(r=new Date(r.getTime()+6e4*r.getTimezoneOffset())),r},t.toDateOnlyString=function(e){return e&&e.getTime&&new Date(e.getTime()-6e4*e.getTimezoneOffset()).toISOString().substring(0,10)||e},t.parseRawValue=function(e,t){if(void 0!==e)return 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:le,fmtOData:we,getNext:se}),t.Int64=new t({defaultValue:0,isNumeric:!0,isInteger:!0,quoteJsonOData:!0,parse:he,fmtOData:Pe("L"),getNext:ue}),t.Int32=new t({defaultValue:0,isNumeric:!0,isInteger:!0,parse:he,fmtOData:Ee,getNext:ue}),t.Int16=new t({defaultValue:0,isNumeric:!0,isInteger:!0,parse:he,fmtOData:Ee,getNext:ue}),t.Byte=new t({defaultValue:0,isNumeric:!0,isInteger:!0,parse:he,fmtOData:Ee}),t.Decimal=new t({defaultValue:0,isNumeric:!0,quoteJsonOData:!0,isFloat:!0,parse:de,fmtOData:Pe("m"),getNext:ue}),t.Double=new t({defaultValue:0,isNumeric:!0,isFloat:!0,parse:de,fmtOData:Pe("d"),getNext:ue}),t.Single=new t({defaultValue:0,isNumeric:!0,isFloat:!0,parse:de,fmtOData:Pe("f"),getNext:ue}),t.DateOnly=new t({defaultValue:new Date(1900,0,1),isDate:!0,parse:ge,parseRawValue:De,normalize:function(e){return e&&e.getTime&&new Date(e.getYear(),e.getMonth(),e.getDate()).getTime()},fmtOData:Te,getNext:ce,getConcurrencyValue:ye}),t.DateTime=new t({defaultValue:new Date(1900,0,1),isDate:!0,parse:me,parseRawValue:Fe,normalize:function(e){return e&&e.getTime&&e.getTime()},fmtOData:Se,getNext:ce,getConcurrencyValue:ye}),t.DateTimeOffset=new t({defaultValue:new Date(1900,0,1),isDate:!0,parse:me,parseRawValue:Fe,normalize:function(e){return e&&e.getTime&&e.getTime()},fmtOData:_e,getNext:ce,getConcurrencyValue:ye}),t.Time=new t({defaultValue:"PT0S",fmtOData:Ne,parseRawValue:t.parseTimeFromServer}),t.Boolean=new t({defaultValue:!1,parse:ve,fmtOData:Ae}),t.Guid=new t({defaultValue:"00000000-0000-0000-0000-000000000000",parse:fe,fmtOData:Oe,getNext:pe,parseRawValue:function(e){return e.toLowerCase()},getConcurrencyValue:S.getUuid}),t.Binary=new t({defaultValue:null,fmtOData:be,parseRawValue:Me}),t.Undefined=new t({defaultValue:void 0,fmtOData:Ce}),t}(a);function se(){return oe.constants.stringPrefix+ue().toString()}function ue(){var e=oe.constants.nextNumber;return oe.constants.nextNumber+=oe.constants.nextNumberIncrement,e}function pe(){return S.getUuid()}function ce(){return new Date}function ye(e){for(var t=new Date,r=new Date;t.getTime()===r.getTime();)r=new Date;return r}function le(e,t){return null==e?e:e.toString()}function fe(e,t){return"string"===t?e.trim().toLowerCase():e}function he(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 de(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 me(e,t){var r;if("string"===t){var n=e.trim();return""===n?null:(r=new Date(Date.parse(n)),S.isDate(r)?r:e)}return"number"===t?(r=new Date(e),S.isDate(r)?r:e):e}function ge(e,t){var r;if("string"===t){e.trim();return r=oe.parseDateAsLocal(r),S.isDate(r)?r:e}return"number"===t?(r=new Date(e),S.isDate(r)?r:e):e}function ve(e,t){if("string"===t){var r=e.trim().toLowerCase();return"false"!==r&&""!==r&&("true"===r||e)}return e}function we(e){return null==e?null:"'"+e.replace(/'/g,"''")+"'"}function Ee(e){return null==e?null:"string"==typeof e?parseInt(e,10):e}function Pe(e){return function(t){return null==t?null:("string"==typeof t&&(t=parseFloat(t)),t+e)}}function Se(e){if(null==e)return null;try{return"datetime'"+e.toISOString()+"'"}catch(t){xe("'%1' is not a valid dateTime",e)}}function Te(e){if(null==e)return null;try{return"date'"+e.toISOString().substring(0,10)+"'"}catch(t){xe("'%1' is not a valid dateTime",e)}}function _e(e){if(null==e)return null;try{return"datetimeoffset'"+e.toISOString()+"'"}catch(t){xe("'%1' is not a valid dateTime",e)}}function Ne(e){return null==e?null:(S.isDuration(e)||xe("'%1' is not a valid ISO 8601 duration",e),"time'"+e+"'")}function Oe(e){return null==e?null:(S.isGuid(e)||xe("'%1' is not a valid guid",e),"guid'"+e+"'")}function Ae(e){return null==e?null:"string"==typeof e?"true"===e.trim().toLowerCase():!!e}function be(e){return null==e?e:"binary'"+e+"'"}function Ce(e){return e}function xe(e,t){throw e=S.formatString(e,t),new Error(e)}function Fe(e){return S.isDate(e)||(e=oe.parseDateFromServer(e)),e}function De(e){return"string"==typeof e&&(e.length>10&&(e=e.substring(0,10)),e=oe.parseDateAsLocal(e)),e}function Me(e){return e&&void 0!==e.$value&&(e=e.$value),e}oe.prototype._$typeName="DataType",Error.x=oe._resetConstants(),Error.x=oe.resolveSymbols(),Error.x=oe.getSymbols().forEach((function(e){return e.validatorCtor=function(e){switch(e){case oe.String:return X.string;case oe.Int64:return X.int64;case oe.Int32:return X.int32;case oe.Int16:return X.int16;case oe.Decimal:case oe.Double:case oe.Single:return X.number;case oe.DateTime:case oe.DateTimeOffset:return X.date;case oe.Boolean:return X.bool;case oe.Guid:return X.guid;case oe.Byte:return X.byte;case oe.Binary:return X.none;case oe.Time:return X.duration;case oe.Undefined:return X.none}}(e)}));var ke=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.isDeletedOrDetached=function(){return this===t.Detached||this===t.Detached},t.prototype.isUnchangedOrModified=function(){return this===t.Unchanged||this===t.Modified},t.prototype.isAddedOrModified=function(){return this===t.Added||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);ke.prototype._$typeName="EntityState",Error.x=ke.resolveSymbols();var Ie=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);Ie.prototype._$typeName="EntityAction",Error.x=Ie.resolveSymbols();var Ve=function(){function e(t,r){_(t,"entityType").isInstanceOf(Gt).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===oe.Guid&&(r[t]=r[t]&&r[t].toLowerCase?r[t].toLowerCase():r[t])})),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&&S.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}();Ve.prototype._$typeName="EntityKey";var Re=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);Re.prototype._$typeName="MergeStrategy",Error.x=Re.resolveSymbols();var Ke=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);Ke.prototype._$typeName="FetchStrategy",Error.x=Ke.resolveSymbols();var je=function(){function e(t){e._updateWithConfig(this,t)}return e.resolve=function(t){return new e(S.resolveProperties(t,["fetchStrategy","mergeStrategy","includeDeleted"]))},e.prototype.using=function(t){if(!t)return this;var r=new e(this);return t instanceof Re?t={mergeStrategy:t}:t instanceof Ke&&(t={fetchStrategy:t}),e._updateWithConfig(r,t)},e.prototype.setAsDefault=function(){return S.setAsDefault(this,e)},e.prototype.toJSON=function(){return S.toJson(this,{fetchStrategy:null,mergeStrategy:null,includeDeleted:!1})},e.fromJSON=function(t){return new e({fetchStrategy:Ke.fromName(t.fetchStrategy),mergeStrategy:Re.fromName(t.mergeStrategy),includeDeleted:!0===t.includeDeleted})},e._updateWithConfig=function(e,t){return t&&j(t).whereParam("fetchStrategy").isEnumOf(Ke).isOptional().whereParam("mergeStrategy").isEnumOf(Re).isOptional().whereParam("includeDeleted").isBoolean().isOptional().applyAll(e),e},e.defaultInstance=new e({fetchStrategy:Ke.FromServer,mergeStrategy:Re.PreserveChanges,includeDeleted:!1}),e}();je.prototype._$typeName="QueryOptions";var qe=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]):Be(n):n instanceof e?n:"string"==typeof n?new $e(n):Le(n)}return Be(t)},e.prototype._validate=function(e,t){},e.and=function(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];var r=new Qe("and",e);return r},e.or=function(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];var r=new Qe("or",e);return r},e.not=function(e){return e.not()},e.extendFuncMap=function(e){for(var t in e||{}){var r=e[t];Xe._funcMap[t]=r}},e.prototype.and=function(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];return new Qe("and",Ue(this,e))},e.prototype.or=function(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];return new Qe("or",Ue(this,e))},e.prototype.not=function(){return new Ge("not",this)},e.prototype.toJSON=function(){return this.toJSONExt({entityType:this._entityType})},e.prototype.toJSONExt=function(e){return this.visit(e,pt)},e.prototype.toFunction=function(e){return this.visit(e,st)},e.prototype.toString=function(){return JSON.stringify(this)},e.prototype.visit=function(e,t){if(S.isEmpty(e))e={entityType:void 0};else if(e instanceof Gt)e={entityType:e};else if(!S.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)ze(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 Be(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]=Be(e.splice(2)),Le(t)}function Le(e){if(e instanceof qe)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(Qe.prototype._resolveOp(e,!0))return new Qe(e,t);if(Ge.prototype._resolveOp(e,!0))return new Ge(e,t);if("object"!=typeof t||null==t||S.isDate(t))return new Je("eq",e,t);if(S.hasOwnProperty(t,"value"))return new Je("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(We.prototype._resolveOp(e,!0))return new We(e,r,t[e]);if(Je.prototype._resolveOp(e,!0))return new Je(e,r,t[e]);if(S.hasOwnProperty(t[e],"value"))return new Je("eq",r,t[e]);var n=S.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 Qe("and",n)}(t,e[t])}));return 1===t.length?t[0]:new Qe("and",t)}function Ue(e,t){var r=t[0];return r instanceof qe?r=S.arraySlice(t):Array.isArray(r)||(r=[new qe(S.arraySlice(t))]),[e].concat(r)}function ze(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 $e=function(e){function t(t){var r=e.call(this)||this;return r.value=t,r}return r(t,e),t}(qe);Error.x=$e.prototype._initialize("passthruPredicate");var Ge=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 qe(r),i}return r(t,e),t.prototype._validate=function(e,t){this.pred._validate(e,t)},t}(qe);Error.x=Ge.prototype._initialize("unaryPredicate",{not:{aliases:["!","~"]}});var Je=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=it(this.expr1Source,r),null==this.expr1)throw new Error("Unable to validate 1st expression: "+this.expr1Source);if(this.expr1 instanceof He)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=S.extend(r,{isRHS:!0,dataType:this.expr1.dataType});if(this.expr2=it(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}(qe);Error.x=Je.prototype._initialize("binaryPredicate",{eq:{aliases:["==","equals","equal"]},ne:{aliases:["!=","~=","notequals","notequal"]},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 Qe=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 qe(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}(qe);Error.x=Qe.prototype._initialize("andOrPredicate",{and:{aliases:["&&"]},or:{aliases:["||"]}});var We=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 qe(n),i}return r(t,e),t.prototype._validate=function(e,t){this.expr=it(this.exprSource,{entityType:e,usesNameOnServer:t}),(null==e||e.isAnonymous)&&(this.expr.dataType=void 0),this.pred._validate(this.expr.dataType,t)},t}(qe);Error.x=We.prototype._initialize("anyAllPredicate",{any:{aliases:["some"]},all:{aliases:["every"]}});var Ze=function(){function e(e){this.visitorMethodName=e,this.visit=qe.prototype.visit}return e.prototype._validate=function(e,t){},e}(),He=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 oe)return e;if("string"==typeof e){var t=oe.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)||oe.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}(Ze);var Ye=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=S.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 tr?i.dataType:i.entityType}},t}(Ze),Xe=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:oe.String},tolower:{fn:function(e){return e.toLowerCase()},dataType:oe.String},substring:{fn:function(e,t,r){return e.substring(t,r)},dataType:oe.String},substringof:{fn:function(e,t){return t.indexOf(e)>=0},dataType:oe.Boolean},length:{fn:function(e){return e.length},dataType:oe.Int32},trim:{fn:function(e){return e.trim()},dataType:oe.String},concat:{fn:function(e,t){return e.concat(t)},dataType:oe.String},replace:{fn:function(e,t,r){return e.replace(t,r)},dataType:oe.String},startswith:{fn:function(e,t){return S.stringStartsWith(e,t)},dataType:oe.Boolean},endswith:{fn:function(e,t){return S.stringEndsWith(e,t)},dataType:oe.Boolean},indexof:{fn:function(e,t){return e.indexOf(t)},dataType:oe.Int32},round:{fn:function(e){return Math.round(e)},dataType:oe.Int32},ceiling:{fn:function(e){return Math.ceil(e)},dataType:oe.Int32},floor:{fn:function(e){return Math.floor(e)},dataType:oe.Int32},second:{fn:function(e){return e.getSeconds()},dataType:oe.Int32},minute:{fn:function(e){return e.getMinutes()},dataType:oe.Int32},hour:{fn:function(e){return e.getHours()},dataType:oe.Int32},day:{fn:function(e){return e.getDate()},dataType:oe.Int32},month:{fn:function(e){return e.getMonth()+1},dataType:oe.Int32},year:{fn:function(e){return e.getFullYear()},dataType:oe.Int32}},t}(Ze),et=/^[a-z_][\w.$]*$/i,tt=/('[^']*'|[^,]+)/g,rt=/("[^"]*"|[^,]+)/g,nt=String.fromCharCode(191);function it(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 He(e,t.dataType)}if("string"!=typeof e){if(null==e||"object"!=typeof e||e.toISOString)return new He(e,t.dataType);if(void 0===e.value)throw new Error("Unable to resolve an expression for: "+e+" on entityType: "+(r?r.name:"null"));return e.isProperty?new Ye(e.value):new He(e.value,e.dataType||t.dataType,!0)}if(t.isRHS)return null==r||r.isAnonymous?new He(e,t.dataType):ot(e,t);for(var n=/\([^()]*\)/,i=void 0,a=[],o=0;i=n.exec(e);){var s=i[0];a.push(s);var u=nt+o++;e=e.replace(s,u)}var p=at(e,a,t);return p._validate(r,t.usesNameOnServer),p}function at(e,t,r){var n=e.split(nt);return 1===n.length?ot(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?tt:rt,s=a.match(o),u=S.extend({},n);u.dataType=oe.Undefined,u.isFnArg=!0;var p=s.map((function(e){return at(e,r,u)}));return new Xe(i,p)}catch(e){throw e}}(e,n,t,r)}function ot(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 He(n,t.dataType||oe.String)}var i=t.entityType;return null==i||i.isAnonymous||et.test(e)&&null!=i.getPropertiesOnPath(e,null,!1)?new Ye(e):new He(e,t.dataType)}var st={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=oe.getComparableFn(t);switch(i.key){case"eq":n=function(e,t){return e&&"string"==typeof e?ut(e,t,r):a(e)===a(t)};break;case"ne":n=function(e,t){return e&&"string"==typeof e?!ut(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){r.isCaseSensitive||(e=(e||"").toLowerCase(),t=(t||"").toLowerCase());return S.stringStartsWith(e,t)}(e,t,r)};break;case"endswith":n=function(e,t){return function(e,t,r){r.isCaseSensitive||(e=(e||"").toLowerCase(),t=(t||"").toLowerCase());return S.stringEndsWith(e,t)}(e,t,r)};break;case"contains":n=function(e,t){return function(e,t,r){r.isCaseSensitive||(e=(e||"").toLowerCase(),t=(t||"").toLowerCase());return 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=S.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 Pt.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 ut(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 pt={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 Ye&&(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 e.or||"string"==typeof e}))||(t=r.reduce(ct)),null==t&&((t={})[this.op.key]=r),t):{}},anyAllPredicate:function(e){var t=this.expr.visit(e),r=S.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){var t=this.dataType===oe.DateOnly?oe.toDateOnlyString(this.value):this.value;return this.hasExplicitDataType||e.useExplicitDataType?{value:t,dataType:this.dataType.name}:t},propExpr:function(e){return e.toNameOnServer?e.entityType?e.entityType.clientPropertyPathToServer(this.propertyPath):(console.warn('No EntityType for propertyPath "'+this.propertyPath+'". '+S.strings.TO_TYPE),this.propertyPath):this.propertyPath},fnExpr:function(e){var t=this.exprs.map((function(t){return t.visit(e)}));return this.fnName+"("+t.join(",")+")"}};function ct(e,t){return Object.keys(t).every((function(r){if(e.hasOwnProperty(r)){if("object"!=typeof t[r])return!1;if(null==ct(e[r],t[r]))return!1}else{if("object"!=typeof e)return!1;e[r]=t[r]}return!0}))?e:null}var yt=function(){function e(e){if(null!=e&&"string"!=typeof e)return t=this,r=e,S.toJson(r,{"resourceName,from":null,"resultEntityType,toType":null,"wherePredicate,where":function(e){return e?new qe(e):void 0},"orderByClause,orderBy":function(e){return e?new gt(e):void 0},"selectClause,select":function(e){return e?new wt(e):void 0},"expandClause,expand":function(e){return e?new Et(e):void 0},"skipCount,skip":null,"takeCount,take":null,parameters:function(e){return S.isEmpty(e)?void 0:e},"inlineCountEnabled,inlineCount":!1,"noTrackingEnabled,noTracking":!1,queryOptions:function(e){return e?je.fromJSON(e):void 0}},t),t;var t,r;this.resourceName=e,this.fromEntityType=void 0,this.wherePredicate=void 0,this.orderByClause=void 0,this.selectClause=void 0,this.skipCount=void 0,this.takeCount=void 0,this.expandClause=void 0,this.parameters={},this.inlineCountEnabled=!1,this.noTrackingEnabled=!1,this.entityManager=void 0}return e.prototype.from=function(e){return _(e,"resourceName").isString().check(),lt(this,"resourceName",e)},e.from=function(t){return _(t,"resourceName").isString().check(),new e(t)},e.prototype.toType=function(e){return _(e,"entityType").isString().or().isInstanceOf(Gt).check(),lt(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=qe.create.apply(qe,i(t)),this.fromEntityType&&e._validate(this.fromEntityType),this.wherePredicate&&(e=this.wherePredicate.and(e))),lt(this,"wherePredicate",e)},e.prototype.orderBy=function(e,t){var r=null==e?null:new gt(ft(e),t);return this.orderByClause&&r&&(r=new gt([this.orderByClause,r])),lt(this,"orderByClause",r)},e.prototype.orderByDesc=function(e){return this.orderBy(e,!0)},e.prototype.select=function(e){return lt(this,"selectClause",null==e?null:new wt(ft(e)))},e.prototype.skip=function(e){return _(e,"count").isOptional().isNumber().check(),lt(this,"skipCount",null==e?null:e)},e.prototype.top=function(e){return this.take(e)},e.prototype.take=function(e){return _(e,"count").isOptional().isNumber().check(),lt(this,"takeCount",null==e?null:e)},e.prototype.expand=function(e){return lt(this,"expandClause",null==e?null:new Et(ft(e)))},e.prototype.withParameters=function(e){return _(e,"parameters").isObject().check(),lt(this,"parameters",e)},e.prototype.inlineCount=function(e){return _(e,"enabled").isBoolean().isOptional().check(),lt(this,"inlineCountEnabled",e=void 0===e||!!e)},e.prototype.useNameOnServer=function(e){return _(e,"usesNameOnServer").isBoolean().isOptional().check(),lt(this,"usesNameOnServer",e=void 0===e||!!e)},e.prototype.noTracking=function(e){return _(e,"enabled").isBoolean().isOptional().check(),lt(this,"noTrackingEnabled",e=void 0===e||!!e)},e.prototype.using=function(e){if(!e)return this;var t=lt(this);return function e(t,r,n,i){var o=n._$typeName||n instanceof a&&n.constructor.name,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=r[s];if(void 0===u)throw new Error("Invalid config property: "+s);null===u?t[s]=n:u(t,n)}else S.objectForEach(n,(function(n,i){e(t,r,i,n)}))}(t,{entityManager:null,dataService:null,queryOptions:null,fetchStrategy:function(e,t){e.queryOptions=(e.queryOptions||new je).using(t)},mergeStrategy:function(e,t){e.queryOptions=(e.queryOptions||new je).using(t)},jsonResultsAdapter:function(e,t){e.dataService=(e.dataService||new $).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):S.identity;var t=function(t){return t?t.toJSONExt(e):void 0};return S.toJson(this,{"from,resourceName":null,"toType,resultEntityType":function(e){return e?"string"==typeof e?e:e.name:void 0},"where,wherePredicate":t,"orderBy,orderByClause":t,"select,selectClause":t,"expand,expandClause":t,"skip,skipCount":null,"take,takeCount":null,parameters:function(e){return S.isEmpty(e)?void 0:e},"inlineCount,inlineCountEnabled":!1,"noTracking,noTrackingEnabled":!1,queryOptions:null})},e.fromEntities=function(t){_(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 qe.create(t.name,dt.Equals,e.getProperty(t.name))}));return qe.and(t)}(e)})),s=qe.or(o);a=a.where(s);var u=n.entityAspect.entityManager;return u&&(a=a.using(u)),a},e.fromEntityKey=function(t){_(t,"entityKey").isInstanceOf(Ve).check();var r=new e(t.entityType.defaultResourceName),n=ht(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?")}else{var i=e.getEntityTypeNameForResourceName(n);if(r=i?e._getStructuralType(i):this._getToEntityType(e,!0))return this.fromEntityType=r,r;if(t)throw new Error(S.formatString("Cannot find an entityType for resourceName: '%1'. ",n)+S.strings.TO_TYPE)}},e.prototype._getToEntityType=function(e,t){return this.resultEntityType instanceof Gt?this.resultEntityType:this.resultEntityType?(this.resultEntityType=e._getStructuralType(this.resultEntityType,!1),this.resultEntityType):void(t||this.selectClause||this._getFromEntityType(e,!1))},e.prototype._toUri=function(e){return $.resolve([e.dataService]).uriBuilder.buildUri(this,e.metadataStore)},e.fromEntityNavigation=function(t,r){_(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)}));return ht(new Ve(t.entityType,r))}var n=t.inverse,i=n?n.foreignKeyNames:t.invForeignKeyNames;if(0===i.length)return null;var a=e.entityAspect.getKey().values,o=S.arrayZip(i,a,(function(e,t){return qe.create(e,dt.Equals,t)}));return qe.and(o)}(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 lt(e,t,r){if(t&&e[t]===r)return e;var n=S.extend(new yt,e,["resourceName","fromEntityType","wherePredicate","orderByClause","selectClause","skipCount","takeCount","expandClause","inlineCountEnabled","noTrackingEnabled","usesNameOnServer","queryOptions","entityManager","dataService","resultEntityType"]);return n.parameters=S.extend({},e.parameters),t&&(n[t]=r),n}function ft(e){return _(e,"propertyPaths").isOptional().isString().or().isArray().isString().check(),"string"==typeof e&&(e=e.split(",")),e=e.map((function(e){return e.trim()}))}function ht(e){var t=e.entityType.keyProperties,r=S.arrayZip(t,e.values,(function(e,t){return qe.create(e.name,dt.Equals,t)}));return qe.and(r)}yt.prototype._$typeName="EntityQuery";var dt=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);dt.prototype._$typeName="FilterQueryOp",Error.x=dt.resolveSymbols();var mt=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);mt.prototype._$typeName="BooleanQueryOp",Error.x=mt.resolveSymbols();var gt=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=S.arrayFlatMap(n,(function(e){return e.items}))}else this.items=t.map((function(e){return new vt(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}(),vt=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=S.stringStartsWith(r[1].toLowerCase(),"desc"))&&!S.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=Pt.getPropertyPathValue(e,n),s=Pt.getPropertyPathValue(a,n),u=t||o&&oe.fromValue(o)||oe.fromValue(s);if(u===oe.String)r?(o=o||"",s=s||""):(o=(o||"").toLowerCase(),s=(s||"").toLowerCase());else{var p=oe.getComparableFn(u);o=p(o),s=p(s)}return o===s?0:o>s||void 0===s?i?-1:1:i?1:-1}},e}(),wt=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]]=Pt.getPropertyPathValue(t,n)})),r}},e.prototype.toJSONExt=function(e){return this.propertyPaths.map((function(t){return e.propertyPathFn(t)}))},e}(),Et=function(){function e(e){this.propertyPaths=e}return e.prototype.toJSONExt=function(e){return this.propertyPaths.map((function(t){return e.propertyPathFn(t)}))},e}(),Pt=function(){function e(e){if(this.setUnchanged=function(){return this.setEntityState(ke.Unchanged)},this.setModified=function(){return this.setEntityState(ke.Modified)},this.setDeleted=function(){return this.setEntityState(ke.Deleted)},this.setDetached=function(){return this.setEntityState(ke.Detached)},this.entity=e,this.entityGroup=void 0,this.entityManager=void 0,this.entityState=ke.Detached,this.isBeingSaved=!1,this.originalValues={},this.hasValidationErrors=!1,this._validationErrors={},this.validationErrorsChanged=new B("validationErrorsChanged",this),this.propertyChanged=new B("propertyChanged",this),null!=e){e.hasOwnProperty("entityType")&&delete e.entityType,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.getCtor();z.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=_(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 Ve(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:Ie.AcceptChanges,entity:this.entity})}},e.prototype.rejectChanges=function(){this._checkOperation("rejectChanges");var e=this.entity,t=this.entityManager;S.using(t,"isRejectingChanges",!0,(function(){St(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:Ie.RejectChanges,entity:e}))},e.prototype.getPropertyPath=function(e){return e},e.prototype.setAdded=function(){return this.setEntityState(ke.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===ke.Unchanged)bt(t),delete this.hasTempKey,n=!1;else if(e===ke.Added)bt(t);else if(e===ke.Deleted){if(this.entityState.isAdded())return this.setEntityState(ke.Detached),!0;this.entityState=ke.Deleted,Tt(t,ke.Deleted)}else if(e===ke.Modified);else if(e===ke.Detached){var i=this.entityGroup;if(!i)return!1;i.detachEntity(t),this.entityState=e,Tt(t,ke.Detached),this._detach(),r.entityChanged.publish({entityAction:Ie.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=yt.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||[],S.arrayAddItemUnique(this._loadedNps,e)},e.prototype.validateEntity=function(){var e=!0;return this._processValidationOpAndPublish((function(t){e=Ot(t.entity)})),e},e.prototype.validateProperty=function(e,t){var r=this.getPropertyValue(e);return r&&r.complexAspect?Ot(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){_(e,"property").isOptional().isEntityProperty().or().isString().check();var t=S.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){_(e,"validationError").isInstanceOf(ie).check(),this._processValidationOpAndPublish((function(t){t._addValidationError(e)}))},e.prototype.removeValidationError=function(e){_(e,"validationErrorOrKey").isString().or().isInstanceOf(ie).or().isInstanceOf(X).check();var t="string"==typeof e?e:e.key;this._processValidationOpAndPublish((function(e){e._removeValidationError(t)}))},e.prototype.clearValidationErrors=function(){this._processValidationOpAndPublish((function(e){S.objectForEach(e._validationErrors,(function(t,r){r&&(delete e._validationErrors[t],e._pendingValidationResult.removed.push(r))})),e.hasValidationErrors=!S.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 Ve(e.entityType,n)},e.prototype.getPropertyValue=function(e){var t;if(_(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 Gt))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=void 0,this.entityManager=void 0,this.entityState=ke.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=Nt(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=void 0}},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=!S.isEmpty(this._validationErrors),this._pendingValidationResult.removed.push(t))},e._nullInstance=new e,e}();function St(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?St(r):(r._rejectChanges(),r.forEach(St))}))}function Tt(e,t){t.isDeleted()?_t(e):S.using(e.entityAspect.entityManager,"isLoading",!0,(function(){_t(e)}))}function _t(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&&S.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 Nt(e,t,r,n){var i=t.validate(r,n);if(i)return e._addValidationError(i),!1;var a=ie.getKey(t,n?n.propertyName:null);return e._removeValidationError(a),!0}function Ot(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 void 0!==t&&(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?Ot(n)&&r:n.reduce((function(e,t,r){return Ot(t,r)&&e}),r))})),n.getAllValidators().forEach((function(t){r=Nt(a,t,e)&&r})),r}B.bubbleEvent(Pt.prototype,(function(){return this.entityManager}));var At=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();z.interfaceRegistry.modelLibrary.getDefaultInstance().startTracking(t,o.prototype)}return e.prototype.getEntityAspect=function(){var e=this.parent;if(!e)return new Pt;for(var t=e.entityAspect;e&&!t;)t=(e=e.complexAspect&&e.complexAspect.parent)&&e.entityAspect;return t||new Pt},e.prototype.getPropertyPath=function(e){var t=this.parent;return t?(t.complexAspect||t.entityAspect).getPropertyPath(this.parentProperty.name+"."+e):null},e}();function bt(e){(e.entityAspect||e.complexAspect).originalValues={},(e.entityType||e.complexType).complexProperties.forEach((function(t){var r=e.getProperty(t.name);t.isScalar?bt(r):(r._acceptChanges(),r.forEach(bt))}))}var Ct=function(){function e(e){j(e||{}).whereParam("name").isOptional().isString().whereParam("serverPropertyNameToClient").isFunction().whereParam("clientPropertyNameToServer").isFunction().applyAll(this),this.name||(this.name=S.getUuid()),z._storeObject(this,"NamingConvention",this.name)}return e.prototype.setAsDefault=function(){return S.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}();Ct.prototype._$typeName="NamingConvention";var xt=/Collection\((.*)\)/;function Ft(e,t,r,n,i){var a=t.key?S.toArray(t.key.propertyRef).map(S.pluck("name")):[];S.toArray(t.property).forEach((function(t){Dt(e,t,r,a)})),S.toArray(t.navigationProperty).forEach((function(t){!function(e,t,r,n){var i=function(e,t,r){var n=It(e.relationship,t),i=n.namespace,a=S.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 S.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=S.arrayFirst(i.end,(function(e){return e.role===t.toRole})),o="*"!==a.multiplicity,s=It(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=S.toArray(y.propertyRef).map(S.pluck("name"));t.fromRole===c.role?p.invForeignKeyNamesOnServer=l:p.foreignKeyNamesOnServer=l}var f=new rr(p);e._addPropertyCore(f)}(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){Ft(e.entityType,e.csdlEntityType,r,n,i)})),delete o[e.name])}function Dt(e,t,r,n){var i,a=t.type.split(".");return a[0].endsWith("Edm")&&2===a.length?i=Mt(e,t,n):!function(e,t){return t.enumType?function(e,t){var r=S.toArray(t.enumType),n=(Vt(e.type)||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=(Vt(e.type)||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=kt(t.type),i=It(Vt(t.type)||t.type,r).typeName;return new tr({nameOnServer:t.name,complexTypeName:i,isNullable:!1,isScalar:!n})}(0,t,r):(i=Mt(e,t,n))&&(i.enumType=t.type),i&&(e._addPropertyCore(i),function(e){var t;e.isNullable||e.validators.push(X.required());if(e.isComplexProperty)return;if(e.dataType===oe.String)if(e.maxLength){var r={maxLength:e.maxLength};t=X.maxLength(r)}else t=X.string();else{var n=e.dataType.validatorCtor;if(!n)return;t=n()}e.validators.push(t)}(i)),i}function Mt(e,t,r){var n=kt(t.type),i=Vt(t.type)||t.type,a=oe.fromEdmDataType(i);if(null!=a){var o="true"===t.nullable||null==t.nullable,s=null!=r&&r.indexOf(t.name)>=0;s&&e instanceof Gt&&e.autoGeneratedKeyType===ir.None&&function(e){var t=S.arrayFirst(Object.keys(e),(function(e){return e.indexOf("StoreGeneratedPattern")>=0}));if(t)return"Identity"===e[t];var r=e.extensions;return!!r&&!!S.arrayFirst(r,(function(e){return"StoreGeneratedPattern"===e.name&&"Identity"===e.value}))}(t)&&(e.autoGeneratedKeyType=ir.Identity);var u=t.maxLength;u=null==u||"Max"===u?null:parseInt(u,10);var p=new tr({nameOnServer:t.name,dataType:a,isNullable:o,isPartOfKey:s,isScalar:!n,maxLength:u,defaultValue:t.defaultValue,concurrencyMode:t.concurrencyMode});return a===oe.Undefined&&(p.rawTypeName=t.type),p}e.warnings.push("Unable to recognize DataType for property: "+t.name+" DateType: "+t.type)}function kt(e){return xt.test(e)}function It(e,t){var r=Lt.parseTypeName(e);if(t&&t.cSpaceOSpaceMapping){var n=Rt(r.shortTypeName,t);n&&(r=Lt.makeTypeHash(r.shortTypeName,n))}return r}function Vt(e){var t=e.match(xt);return t?t[1]:null}function Rt(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}var Kt={parse:function(e,t,r){e._entityTypeResourceMap={},(t=S.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&&S.toArray(r.entityContainer).forEach((function(t){S.toArray(t.entitySet).forEach((function(t){var n=It(t.entityType,r).typeName;e.setEntityTypeForResourceName(t.name,n),e._entityTypeResourceMap[n]=t.name}))})),r.complexType&&S.toArray(r.complexType).forEach((function(t){!function(e,t,r){var n=e.name,i=Rt(n,t),a=new er({shortName:n,namespace:i});S.toArray(e.property).forEach((function(e){Dt(a,e,t)})),r.addEntityType(a)}(t,r,e)})),r.entityType&&S.toArray(r.entityType).forEach((function(n){!function(e,t,r,n){var i=e.name,a=Rt(i,t),o=new Gt({shortName:i,namespace:a,isAbstract:e.abstract&&"true"===e.abstract});if(e.baseType){var s=It(e.baseType,t).typeName;if(o.baseTypeName=s,n._getStructuralType(s,!0))Ft(o,e,t,r,n);else{var u=n._deferredTypes[s];u||(u=[],n._deferredTypes[s]=u),u.push({entityType:o,csdlEntityType:e})}}else Ft(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}},jt=function(){function e(e){j(e||{}).whereParam("name").isOptional().isString().whereParam("isCaseSensitive").isOptional().isBoolean().whereParam("usesSql92CompliantStringComparison").isBoolean().applyAll(this),this.name||(this.name=S.getUuid()),z._storeObject(this,"LocalQueryComparisonOptions",this.name)}return e.prototype.setAsDefault=function(){return S.setAsDefault(this,e)},e.caseInsensitiveSQL=new e({name:"caseInsensitiveSQL",isCaseSensitive:!1,usesSql92CompliantStringComparison:!0}),e.defaultInstance=new e(e.caseInsensitiveSQL),e}();function qt(e,t,r){void 0===t&&(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||null===t&&void 0===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(S.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(S.formatString("You cannot set the '%1' property to null because its 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=Pt.isEntity(r)?r.entityAspect:r.complexAspect;void 0===p.originalValues[u]&&(p.originalValues[u]=void 0!==a?a:n.defaultValue)}if(n.isPartOfKey&&s&&!s.isLoading){var c=(E=r.entityType).keyProperties.map((function(e){return e===n?o:r.getProperty(e.name)})),y=new Ve(E,c);if(s.getEntityByKey(y))throw new Error("An entity with this key is already in the cache: "+y.toString());var l=r.entityAspect.getKey();s._findEntityGroup(E)._replaceKey(l,y)}var f=n.relatedNavigationProperty;if(f&&s)if(null!=o){var h=void 0,d=void 0;if(f.invForeignKeyNames.length){var m=new yt(f.entityType.defaultResourceName).where(f.invForeignKeyNames[0],"eq",o),g=s.executeQueryLocally(m);1===g.length&&(h=g[0])}else d=new Ve(f.entityType,[o]),h=s.getEntityByKey(d);h?r.setProperty(f.name,h):(d&&s._unattachedChildrenMap.addChild(d,f,r),r.setProperty(f.name,null))}else r.setProperty(f.name,null);else if(n.inverseNavigationProperty&&s&&!s._inKeyFixup){var v=n.inverseNavigationProperty;if(null!=a){d=new Ve(v.parentType,[a]);if(h=s.getEntityByKey(d))if(v.isScalar)h.setProperty(v.name,null);else{var w=h.getProperty(v.name);w.splice(w.indexOf(r),1)}}if(null!=o){d=new Ve(v.parentType,[o]);(h=s.getEntityByKey(d))?v.isScalar?h.setProperty(v.name,r):h.getProperty(v.name).push(r):s._unattachedChildrenMap.addChild(d,v,r)}}if(t(o),Bt(e),n.isPartOfKey){var E,P=(E=r.entityType).keyProperties.indexOf(n);if(E.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.slice(0).forEach((function(e){e.setProperty(a,o)}))}}})),s){for(var S=E.inverseForeignKeyProperties,T=E.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){if(!o.entityAspect)return;var p=o.entityAspect;if(s){if(p.entityState.isDetached())s.isLoading||s.attachEntity(o,ke.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,ke.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)o.getProperty(u.name).push(r)}else if(n.invForeignKeyNames&&s&&!s._inKeyFixup){var l=n.invForeignKeyNames;if(null!=o){var f=r.entityAspect.getKey().values;l.forEach((function(e,t){o.setProperty(e,f[t])}))}else null!=a&&l.forEach((function(e){a.entityType.getProperty(e).isPartOfKey||a.setProperty(e,null)}))}if(t(o),Bt(e),n.relatedDataProperties){var h=i.entityState;if(null==o&&(h.isDetached()||a.entityAspect.entityState.isDetached()))return;if(h.isDeleted())return;var d=n.invForeignKeyNames;d&&d.length||(d=n.entityType.keyProperties.map((function(e){return e.name}))),d.forEach((function(e,t){var i=n.relatedDataProperties[t];if(o||!i.isPartOfKey){var a=o?o.getProperty(e):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:Ie.PropertyChange,entity:n,args:i})):t.propertyChanged.publish(i)}(p)}finally{u.pop()}}}}function Bt(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})}}jt.prototype._$typeName="LocalQueryComparisonOptions";var Lt=function(){function e(t){j(t=t||{}).whereParam("namingConvention").isOptional().isInstanceOf(Ct).withDefault(Ct.defaultInstance).whereParam("localQueryComparisonOptions").isOptional().isInstanceOf(jt).withDefault(jt.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 B("metadataFetched",this)}return e.prototype.setProperties=function(e){j(e).whereParam("name").isString().isOptional().whereParam("serializerFn").isFunction().isOptional().applyAll(this)},e.prototype.addDataService=function(e,t){_(e,"dataService").isInstanceOf($).check(),_(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 S.arrayIndexOf(this.dataServices,(function(t){return t.serviceName===e}))},e.prototype.addEntityType=function(e){var t;if((t=e instanceof Gt||e instanceof er?e:e.isComplexType?new er(e):new Gt(e))instanceof Gt){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 Gt){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:S.objectMap(this._structuralTypeMap),resourceEntityTypeMap:this._resourceEntityTypeMap},null,z.stringifyPad)},e.prototype.importMetadata=function(t,r){var n=this;void 0===r&&(r=!1),_(r,"allowMerge").isOptional().isBoolean().check(),this._deferredTypes={};var i="string"==typeof t?t:JSON.stringify(t),a=JSON.parse(i);if(a.schema)return Kt.parse(this,a.schema,a.altMetadata);var o=a;if(o.metadataVersion&&o.metadataVersion!==e.metadataVersion){var s=S.formatString("Cannot import metadata with a different 'metadataVersion' (%1) than the current 'MetadataStore.metadataVersion' (%2) ",o.metadataVersion,e.metadataVersion);throw new Error(s)}var u=o.namingConvention,p=o.localQueryComparisonOptions;if(this.isEmpty())this.namingConvention=z._fetchObject(Ct,u)||this.namingConvention,this.localQueryComparisonOptions=z._fetchObject(jt,p)||this.localQueryComparisonOptions;else{if(u&&this.namingConvention.name!==u)throw new Error("Cannot import metadata with a different 'namingConvention' from the current MetadataStore");if(p&&this.localQueryComparisonOptions.name!==p)throw new Error("Cannot import metadata with different 'localQueryComparisonOptions' from the current MetadataStore")}return o.dataServices&&o.dataServices.forEach((function(e){var t=$.fromJSON(e);n.addDataService(t,!0)})),o.structuralTypes&&o.structuralTypes.forEach((function(e){!function(e,t,r){var n=pr(t.shortName,t.namespace),i=e._getStructuralType(n,!0);if(i)return r?function(e,t){t.custom&&(e.custom=t.custom);return Ut(e,t.dataProperties),Ut(e,t.navigationProperties),e}(i,t):i;var a={shortName:t.shortName,namespace:t.namespace,isAbstract:t.isAbstract,autoGeneratedKeyType:ir.fromName(t.autoGeneratedKeyType),defaultResourceName:t.defaultResourceName,custom:t.custom};if(i=t.isComplexType?new er(a):new Gt(a),t.baseTypeName&&i instanceof Gt){i.baseTypeName=t.baseTypeName,e._getStructuralType(t.baseTypeName,!0)?zt(e,t,i):S.getArray(e._deferredTypes,t.baseTypeName).push({json:t,stype:i})}else zt(e,t,i)}(n,e,r)})),S.extend(this._resourceEntityTypeMap,o.resourceEntityTypeMap),S.extend(this._incompleteTypeMap,o.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 _(e,"serviceName").isString().check(),e=$._normalizeServiceName(e),S.arrayFirst(this.dataServices,(function(t){return t.serviceName===e}))},e.prototype.fetchMetadata=function(e,t,r){var n=this;try{if(_(e,"dataService").isString().or().isInstanceOf($).check(),_(t,"callback").isFunction().isOptional().check(),_(r,"errorCallback").isFunction().isOptional().check(),"string"==typeof e&&(e=this.getDataService(e)||new $({serviceName:e})),e=$.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(e){return Promise.reject(e)}},e.prototype.trackUnmappedType=function(e,t){_(e,"entityCtor").isFunction().check(),_(t,"interceptor").isFunction().isOptional().check(),new Gt(this)._setCtor(e,t)},e.prototype.registerEntityTypeCtor=function(e,t,r,n){_(e,"structuralTypeName").isString().check(),_(t,"aCtor").isFunction().isOptional().check(),_(r,"initFn").isOptional().isFunction().or().isString().check(),_(n,"noTrackingFn").isOptional().isFunction().check();var i=$t(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 S.isEmpty(this._structuralTypeMap)},e.prototype.getAsEntityType=function(e,t){void 0===t&&(t=!1);var r=this.getStructuralType(e,t);if(r instanceof Gt)return r;if(t)return null;var n=S.formatString("Unable to locate an 'EntityType' by the name: '%1'. Be sure to execute a query or call fetchMetadata first.",e);throw new Error(n)},e.prototype.getAsComplexType=function(e,t){void 0===t&&(t=!1);var r=this.getStructuralType(e,t);if(r instanceof er)return r;if(t)return null;var n=S.formatString("Unable to locate an 'ComplexType' by the name: '%1'. Be sure to execute a query or call fetchMetadata first.",e);throw new Error(n)},e.prototype.getEntityType=function(e,t){return void 0===t&&(t=!1),this.getStructuralType(e,t)},e.prototype.getStructuralType=function(e,t){return void 0===t&&(t=!1),_(e,"typeName").isString().check(),_(t,"okIfNotFound").isBoolean().isOptional().check(!1),this._getStructuralType(e,t)},e.prototype._getStructuralType=function(e,t){void 0===t&&(t=!1);var r=$t(this,e,!1),n=this._structuralTypeMap[r];if(!n){if(t)return null;var i=S.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 S.objectMap(this._incompleteTypeMap,(function(e,t){return t}))},e.prototype.getEntityTypeNameForResourceName=function(e){return _(e,"resourceName").isString().check(),this._resourceEntityTypeMap[e]},e.prototype.setEntityTypeForResourceName=function(e,t){var r;_(e,"resourceName").isString().check(),_(t,"entityTypeOrName").isInstanceOf(Gt).or().isString().check(),r=t instanceof Gt?t.name:$t(this,t,!0),this._resourceEntityTypeMap[e]=r;var n=this._getStructuralType(r,!0);n&&n instanceof Gt&&!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(S.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:pr(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=S.memoize((function(t){return t&&e.parseTypeName(t).typeName})),e}();function Ut(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 zt(e,t,r){t.validators&&(r.validators=t.validators.map(X.fromJSON)),t.dataProperties.forEach((function(e){r._addPropertyCore(tr.fromJSON(e))})),!t.isComplexType&&t.navigationProperties&&t.navigationProperties.forEach((function(e){r._addPropertyCore(rr.fromJSON(e))})),e.addEntityType(r);var n=e._deferredTypes,i=n[r.name];i&&(i.forEach((function(t){zt(e,t.json,t.stype)})),delete n[r.name])}function $t(e,t,r){if(ur(t))return t;var n=e._shortNameMap[t];if(!n&&r)throw new Error("Unable to locate 'entityTypeName' of: "+t);return n}Lt.prototype._$typeName="MetadataStore",B.bubbleEvent(Lt.prototype);var Gt=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=void 0;"MetadataStore"===t._$typeName?(this.metadataStore=t,this.shortName="Anon_"+ ++e.__nextAnonIx,this.namespace="",this.isAnonymous=!0):(r=t,j(t).whereParam("shortName").isNonEmptyString().whereParam("namespace").isString().isOptional().withDefault("").whereParam("baseTypeName").isString().isOptional().whereParam("isAbstract").isBoolean().isOptional().withDefault(!1).whereParam("autoGeneratedKeyType").isEnumOf(ir).isOptional().withDefault(ir.None).whereParam("defaultResourceName").isNonEmptyString().isOptional().withDefault(null).whereParam("dataProperties").isOptional().whereParam("navigationProperties").isOptional().whereParam("serializerFn").isOptional().isFunction().whereParam("custom").isOptional().applyAll(this)),this.name=pr(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&&cr(this,r.dataProperties,tr),r&&r.navigationProperties&&cr(this,r.navigationProperties,rr)}return e.prototype.setProperties=function(e){j(e).whereParam("autoGeneratedKeyType").isEnumOf(ir).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){_(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){_(e,"property").isInstanceOf(tr).or().isInstanceOf(rr).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 rr(e),!0):t._addPropertyCore(new tr(e),!0))}))}return t},e.prototype._updateFromBase=function(e){var t=this;this.baseEntityType=e,this.autoGeneratedKeyType===ir.None&&(this.autoGeneratedKeyType=e.autoGeneratedKeyType),e.dataProperties.forEach((function(e){var r=new tr(e);r.validators=[],r.baseProperty=e,t._addPropertyCore(r)}),this),e.navigationProperties.forEach((function(e){var r=new rr(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 tr?this._addDataProperty(e):(this._addNavigationProperty(e),t&&n&&Yt(e,n)),!n||e.name&&e.nameOnServer||Qt(n.namingConvention,e,"name"),n&&this._extra&&this._extra.alreadyWrappedProps){var i=this._ctor.prototype;z.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,Jt),this.navigationProperties.forEach((function(r){var n,i=e[r.name];if(null!=i){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 Pt(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=this.metadataStore._ctorRegistry,r=t[this.name]||t[this.shortName]||{},n=r.ctor||this._ctor,i=n&&n.prototype&&(n.prototype.entityType||n.prototype.complexType);if(i&&i.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(r.ctor&&e&&(this._extra=void 0),!n){var a=z.interfaceRegistry.modelLibrary.getDefaultInstance().createCtor;n=a?a(this):function(e){if(z.noEval){return function(){}}var t=e.name.replace(/\W/g,"_");return Function("return function "+t+"(){}")()}(this)}return this.initFn=r.initFn,this.noTrackingFn=r.noTrackingFn,n.prototype._$typeName=this.name,this._setCtor(n),n},e.prototype._setCtor=function(e,t){var r=e.prototype;this._extra=this._extra||{},Xt(this,new e),"EntityType"===this._$typeName?r.entityType=this:r.complexType=this,r._$interceptor=t||qt,z.interfaceRegistry.modelLibrary.getDefaultInstance().initializeEntityPrototype(r),this._ctor=e},e.prototype.addValidator=function(e,t){(_(e,"validator").isInstanceOf(X).check(),_(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(S.pluck("name"))},e.prototype.getDataProperty=function(e){return S.arrayFirst(this.dataProperties,S.propEq("name",e))},e.prototype.getNavigationProperty=function(e){return S.arrayFirst(this.navigationProperties,S.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?S.propsEq("name","nameOnServer",e):S.propEq(a,e),n=S.arrayFirst(o.getProperties(),t);if(n)o=n instanceof rr?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 oe.parseRawValue(n,r.dataType)}));return new Ve(this,r)},e.prototype._updateTargetFromRaw=function(e,t,r){this.dataProperties.forEach((function(n){if(n.isSettable){var i=r(t,n);if(void 0!==i){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}));S.arrayEquals(a,u,Wt)||(a.length=0,u.forEach((function(e){a.push(e)})))}else a.length=0}else if(n.isScalar){u=oe.parseRawValue(i,o);e.setProperty(n.name,u)}else if(a=e.getProperty(n.name),Array.isArray(i)){u=i.map((function(e){return oe.parseRawValue(e,o)}));S.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=Pt.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 S.toJson(this,{shortName:null,namespace:null,baseTypeName:null,isAbstract:!1,autoGeneratedKeyType:null,defaultResourceName:null,dataProperties:Zt,navigationProperties:Zt,validators:null,custom:null})},e.prototype._updateNames=function(e){var t=this.metadataStore.namingConvention;Qt(t,e,"name"),e.isNavigationProperty&&(Qt(t,e,"foreignKeyNames"),Qt(t,e,"invForeignKeyNames"))},e.prototype._checkNavProperty=function(e){if(e instanceof rr){if(e.parentType!==this)throw new Error(S.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 rr)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),ur(e.entityTypeName)||(e.entityTypeName=pr(e.entityTypeName,this.namespace))},e.prototype._updateCps=function(){var e=this.metadataStore,t=e._incompleteComplexTypeMap;this.complexProperties.forEach((function(r){r.complexType||Ht(r,e)||S.getArray(t,r.complexTypeName).push(r)})),this.isComplexType&&((t[this.name]||[]).forEach((function(t){Ht(t,e)})),delete t[this.name])},e.prototype._updateNps=function(){var e=this.metadataStore;this.navigationProperties.forEach((function(t){Yt(t,e)}));var t=e._incompleteTypeMap;(t[this.name]||[]).forEach((function(t){Yt(t,e)})),delete t[this.name]},e.__nextAnonIx=0,e.qualifyTypeName=pr,e}();function Jt(e,t){return e.entityAspect||e.complexAspect?e.getProperty(t.name):e[t.name]}function Qt(e,t,r){var n=r+"OnServer",i=t[r];if(i&&i.length){var a=S.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=S.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 Wt(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 Wt(n,i);if(r.isComplexProperty&&!r.isScalar)return S.arrayEquals(n,i,Wt);var a=r.dataType;return n===i||a&&a.normalize&&n&&i&&a.normalize(n)===a.normalize(i)}))}function Zt(e){return e.filter((function(e){return null==e.baseProperty}))}function Ht(e,t){var r=t._getStructuralType(e.complexTypeName,!0);if(!r)return!1;if(!(r instanceof er))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 Yt(e,t){if(e.entityType)return!0;var r=t._getStructuralType(e.entityTypeName,!0);if(r)e.entityType=r,e._resolveNp();else{var n=S.getArray(t._incompleteTypeMap,e.entityTypeName);S.arrayAddItemUnique(n,e)}return!!r}function Xt(e,t){var r=e.getPropertyNames();z.interfaceRegistry.modelLibrary.getDefaultInstance().getTrackablePropertyNames(t).forEach((function(n){if(-1===r.indexOf(n)){var i=t[n];try{"function"==typeof i&&(i=i())}catch(e){}var a=oe.fromValue(i),o=new tr({name:n,dataType:a,isNullable:!0,isUnmapped:!0});o.isSettable=S.isSettable(t,n),e instanceof Gt&&null!=e.subtypes&&e.subtypes.length?e.getSelfAndSubtypes().forEach((function(e){e._addPropertyCore(new tr(o))})):e._addPropertyCore(o)}}))}Gt.prototype._$typeName="EntityType";var er=function(){function e(e){if(this.isComplexType=!0,this.getCtor=Gt.prototype.getCtor,this.createInstance=Gt.prototype.createEntity,this.addValidator=Gt.prototype.addValidator,this.getProperty=Gt.prototype.getProperty,this.getPropertiesOnPath=Gt.prototype.getPropertiesOnPath,this.getPropertyNames=Gt.prototype.getPropertyNames,this._addPropertyCore=Gt.prototype._addPropertyCore,this._addDataProperty=Gt.prototype._addDataProperty,this._updateNames=Gt.prototype._updateNames,this._updateCps=Gt.prototype._updateCps,this._initializeInstance=Gt.prototype._initializeInstance,this._updateTargetFromRaw=Gt.prototype._updateTargetFromRaw,this._setCtor=Gt.prototype._setCtor,arguments.length>1)throw new Error("The ComplexType ctor has a single argument that is a configuration object.");j(e).whereParam("shortName").isNonEmptyString().whereParam("namespace").isString().isOptional().withDefault("").whereParam("dataProperties").isOptional().whereParam("isComplexType").isOptional().isBoolean().whereParam("custom").isOptional().applyAll(this),this.name=pr(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&&cr(this,e.dataProperties,tr)}return e.prototype.setProperties=function(e){j(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 At(r,e,t),r},e.prototype.addProperty=function(e){return _(e,"dataProperty").isInstanceOf(tr).check(),this._addPropertyCore(e)},e.prototype.getProperties=function(){return this.dataProperties},e.prototype.toJSON=function(){return S.toJson(this,{shortName:null,namespace:null,isComplexType:null,dataProperties:null,validators:null,custom:null})},e}();er.prototype._$typeName="ComplexType",er.prototype.createInstance=Gt.prototype.createEntity;var tr=function(){function e(e){if(this.isDataProperty=!0,this.isNavigationProperty=!1,j(e).whereParam("name").isString().isOptional().whereParam("nameOnServer").isString().isOptional().whereParam("dataType").isEnumOf(oe).isOptional().or().isString().or().isInstanceOf(er).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(X).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=oe.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=oe.String);if(null==this.defaultValue)if(this.isNullable)this.defaultValue=null;else if(this.isComplexProperty);else if(this.dataType===oe.Binary)this.defaultValue="AAAAAAAAJ3U=";else{this.defaultValue=this.dataType.defaultValue;var r="A nonnullable DataProperty cannot have a null defaultValue. Name: "+(this.name||this.nameOnServer);if(null===this.defaultValue)throw new Error(r);null==this.defaultValue&&console.warn(r)}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 void 0!==r?r:t.defaultValue},e.getRawValueFromClient=function(e,t){var r=e[t.name];return void 0!==r?r:t.defaultValue},e.prototype.resolveProperty=function(e){for(var t=this[e],r=this.baseProperty;null==t&&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){j(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 S.toJson(this,{name:null,dataType:function(e){return e&&e instanceof oe?e.name:void 0},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=oe.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(X.fromJSON)),new e(t)},e}();tr.prototype._$typeName="DataProperty";var rr=function(){function e(e){if(this.isDataProperty=!1,this.isNavigationProperty=!0,this.formatName=tr.prototype.formatName,this.getAllValidators=tr.prototype.getAllValidators,this.resolveProperty=tr.prototype.resolveProperty,j(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(X).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,j(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 nr(this,"Unable to find inverse property: "+t);(this._inverse||r._inverse)&&nr(this,"It has already been set on one side or the other."),r.entityType!==this.parentType&&nr(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 S.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(X.fromJSON)),new e(t)},e.prototype._resolveNp=function(){var e=this,t=e.entityType,r=S.arrayFirst(t.navigationProperties,(function(t){return t.associationName===e.associationName&&(t.name!==e.name||t.entityTypeName!==e.entityTypeName)}));e._inverse=r||void 0,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=S.arrayFirst(a.navigationProperties,(function(e){return e.invForeignKeyNames&&e.invForeignKeyNames.indexOf(i.name)>=0&&e.entityType===i.parentType})),i.inverseNavigationProperty=r||void 0,S.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){S.arrayAddItemUnique(i,t),t.relatedNavigationProperty=e,S.arrayAddItemUnique(e.entityType.inverseForeignKeyProperties,t),e.relatedDataProperties?S.arrayAddItemUnique(e.relatedDataProperties,t):e.relatedDataProperties=[t]}))}(e)},e}();function nr(e,t){throw new Error("Cannot set the inverse property for: "+e.formatName()+". "+t)}rr.prototype._$typeName="NavigationProperty";var ir=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);ir.prototype._$typeName="AutoGeneratedKeyType",Error.x=ir.resolveSymbols();var ar=T.prototype;function or(e,t){return null!=t&&void 0!==t.entityType}function sr(e,t){return null!=t&&(t.isDataProperty||t.isNavigationProperty)}function ur(e){return e.indexOf(":#")>=0}function pr(e,t){return t&&t.length>0?e+":#"+t:e}function cr(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(S.hasOwnProperty(t,n)){var i=t[n];i.name=n;var a=new r(i);e._addPropertyCore(a)}}}ar.isEntity=function(){return this._addContext({fn:or,msg:" must be an entity"})},ar.isEntityProperty=function(){return this._addContext({fn:sr,msg:" must be either a DataProperty or a NavigationProperty"})};var yr=function(){function e(){this.changeRequestInterceptor=fr,this.jsonResultsAdapter=new J({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=z.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(e){var p="Unable to either parse or import metadata: "+e.message;lr(o,r,"Metadata query failed for: "+i+". "+p)}e.hasMetadataFor(n)||e.addDataService(t),a(s)},error:function(e){lr(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(e){e instanceof Error?n(e):lr(n,t)}},error:function(e){lr(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)lr(i,r);else{var o=n._prepareSaveResult(e,a);o.httpResponse=r,t(o)}},error:function(t){t.saveContext=e,lr(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=S.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 fr(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 lr(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(e){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:Lt.normalizeTypeName(e.EntityTypeName),keyValues:e.KeyValues,propertyName:e.PropertyName,errorMessage:e.ErrorMessage,custom:e.Custom}}))}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);yr._catchNoConnectionError(n),r&&(n.message=r+"; "+n.message),e(n)}var fr=function(){function e(e,t){}return e.prototype.getRequest=function(e,t,r){return e},e.prototype.done=function(e){},e}(),hr=function(){function e(e){dr(this,e)}return e.prototype.using=function(t){if(!t)return this;var r=new e(this);return dr(r,t),r},e.prototype.setAsDefault=function(){return S.setAsDefault(this,e)},e.defaultInstance=new e({validateOnAttach:!0,validateOnSave:!0,validateOnQuery:!1,validateOnPropertyChange:!0}),e}();function dr(e,t){return t&&j(t).whereParam("validateOnAttach").isBoolean().isOptional().whereParam("validateOnSave").isBoolean().isOptional().whereParam("validateOnQuery").isBoolean().isOptional().whereParam("validateOnPropertyChange").isBoolean().isOptional().applyAll(e),e}hr.prototype._$typeName="ValidationOptions";var mr=function(){function e(t){e._updateWithConfig(this,t)}return e.prototype.setAsDefault=function(){return S.setAsDefault(this,e)},e.prototype.using=function(t){return e._updateWithConfig(this,t)},e._updateWithConfig=function(e,t){return t&&j(t).whereParam("resourceName").isOptional().isString().whereParam("dataService").isOptional().isInstanceOf($).whereParam("allowConcurrentSaves").isBoolean().isOptional().whereParam("tag").isOptional().applyAll(e),e},e.defaultInstance=new e({allowConcurrentSaves:!1}),e}();mr.prototype._$typeName="SaveOptions";var gr=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)),void 0===n){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 Ve(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&&void 0!==n.keyMap[e.values[0].toString()]},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}();z.registerType(gr,"KeyGenerator");var vr=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===Re.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===Re.OverwriteChanges||r===Re.PreserveChanges&&s){var u=this.entityManager.helper.unwrapInstance(e);this.entityType._updateTargetFromRaw(o,u,tr.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(void 0===r)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 Ve?e._keyInGroup:Ve.createKeyString(e);var r=this._indexMap[t],n=void 0!==r?this._entities[r]:void 0;return null==n?void 0:n},e.prototype.hasChanges=function(){for(var e=this._entities,t=ke.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=ke.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(void 0===r)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 wr=function(){function e(e){this.rawValueFn=tr.getRawValueFromServer,S.extend(this,e,["query","entityManager","dataService","mergeOptions"]),this.refMap={},this.deferredFns=[],this.jsonResultsAdapter=this.dataService.jsonResultsAdapter,this.metadataStore=this.entityManager.metadataStore,this.rawValueFn=tr.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 yt))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,a=S.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 yt&&r._getToEntityType&&r._getToEntityType(i.metadataStore)),Er(i,e,a)}),this.mergeOptions.includeDeleted);return a.filter&&!this.mergeOptions.includeDeleted&&(a=a.filter((function(e){return e&&(!e.entityAspect||!e.entityAspect.entityState.isDeleted())}))),a},e.prototype.processDeferred=function(){this.deferredFns.length>0&&this.deferredFns.forEach((function(e){e()}))},e}();function Er(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 void 0===r?function(){return e.refMap[t]}:r}(e,r.nodeRefId);return"function"==typeof i&&null!=n?void e.deferredFns.push((function(){n(i)})):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.getEntityByKey(s);if(u){if(o&&u.entityAspect.entityState.isDeleted())return n.detachEntity(u),u;var p=u.entityAspect.entityState;if(a===Re.Disallowed)throw new Error("A MergeStrategy of 'Disallowed' prevents "+s.toString()+" from being merged");if(a===Re.SkipMerge)Nr(e,u,t);else if(a===Re.OverwriteChanges||p.isUnchanged()){Or(e,u,t),u.entityAspect.wasLoaded=!0,r.extraMetadata&&(u.entityAspect.extraMetadata=r.extraMetadata),u.entityAspect.entityState=ke.Unchanged,_r(u),u.entityAspect.propertyChanged.publish({entity:u,propertyName:null});var c=o?Ie.MergeOnSave:Ie.MergeOnQuery;n.entityChanged.publish({entityAction:c,entity:u}),p.isUnchanged()||n._notifyStateChange(u,!1)}else if(Nr(e,u,t),p===ke.Deleted&&!e.mergeOptions.includeDeleted)return null}else u=i._createInstanceCore(),Or(e,u,t),r.extraMetadata&&(u.entityAspect.extraMetadata=r.extraMetadata),n._attachEntityCore(u,ke.Unchanged,a),u.entityAspect.wasLoaded=!0,n.entityChanged.publish({entityAction:Ie.AttachOnQuery,entity:u});return u}(e,t,r)}return r.passThru||"object"!=typeof t||S.isDate(t)||(t=function(e,t){var r=e.metadataStore.namingConvention.serverPropertyNameToClient,n={};return S.objectForEach(t,(function(t,i){var a=r(t);Sr(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]=S.map(r[t.nameOnServer],(function(r){return Pr(e,t.dataType,r)})):n[t.name]=oe.parseRawValue(r[t.nameOnServer],t.dataType)})),t instanceof Gt&&t.navigationProperties.forEach((function(t){var i={nodeType:"navProp",navigationProperty:t};Sr(r[t.nameOnServer],e,i,n,t.name)})),n}function Sr(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,Er(t,e,o,(function(e){n[i][s]=e()}))}))):n[i]=Er(t,e,o,(function(e){n[i]=e()})))}function Tr(e,t,r){var n=r._$meta.nodeId;!n&&r._$meta.extraMetadata&&(n=r._$meta.extraMetadata.uriKey),null!=n&&(e.refMap[n]=t)}function _r(e){(e.entityAspect||e.complexAspect).originalValues={},(e.entityType||e.complexType).complexProperties.forEach((function(t){var r=e.getProperty(t.name);t.isScalar?_r(r):(r._acceptChanges(),r.forEach(_r))}))}function Nr(e,t,r){Tr(e,t,r),r.entityType.navigationProperties.forEach((function(t){t.isScalar?Ar(e,r,t):br(e,r,t)}))}function Or(e,t,r){Tr(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=Ar(e,n,t);if(null==i)return;"function"==typeof i?e.deferredFns.push((function(){Cr(i=i(),r,t)})):Cr(i,r,t)}(e,n,t,r):function(e,t,r,n){var i=br(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(),xr(e,t,o,r,a)})):xr(e,t,o,r,a)}))}(e,n,t,r)}))}function Ar(e,t,r){var n=t[r.nameOnServer];return n?e.visitAndMerge(n,{nodeType:"navProp",navigationProperty:r}):null}function br(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 Cr(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 xr(e,t,r,n,i){if(t){if(t.entityAspect.entityState===ke.Modified&&e.mergeOptions.mergeStrategy===Re.PreserveChanges){var a=t.entityAspect.originalValues;if(i.relatedDataProperties.some((function(e){return null!=a[e.name]})))return}t.getProperty(i.name)!==n&&(r.push(t),t.setProperty(i.name,n))}}wr.prototype._$typeName="MappingContext";var Fr=function(){function e(){this.map={}}return e.prototype.addChild=function(e,t,r){var n=this.getTuple(e,t);n||(n={navigationProperty:t,children:[]},S.getArray(this.map,e.toString()).push(n)),n.children.push(r)},e.prototype.removeChildren=function(e,t){var r=this.map[e];r&&(S.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?S.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:void 0},e.prototype.getTuplesByString=function(e){return this.map[e]},e}(),Dr=function(){function e(t){if(this.helper={unwrapInstance:$r,unwrapOriginalValues:Gr,unwrapChangedValues:Jr},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 B("entityChanged",this),this.validationErrorsChanged=new B("validationErrorsChanged",this),this.hasChangesChanged=new B("hasChangesChanged",this),this.clear()}return e.prototype.setProperties=function(t){e._updateWithConfig(this,t,!1)},e._updateWithConfig=function(e,t,r){var n=r?je.defaultInstance:e.queryOptions,i=r?mr.defaultInstance:e.saveOptions,a=r?hr.defaultInstance:e.validationOptions,o=j(t).whereParam("serviceName").isOptional().isString().whereParam("dataService").isOptional().isInstanceOf($).whereParam("queryOptions").isInstanceOf(je).isOptional().withDefault(n).whereParam("saveOptions").isInstanceOf(mr).isOptional().withDefault(i).whereParam("validationOptions").isInstanceOf(hr).isOptional().withDefault(a).whereParam("keyGeneratorCtor").isFunction().isOptional();r&&(o=o.whereParam("metadataStore").isInstanceOf(Lt).isOptional().withDefault(new Lt)),o.applyAll(e),S.updateWithDefaults(e.queryOptions,n),S.updateWithDefaults(e.saveOptions,i),S.updateWithDefaults(e.validationOptions,a),t.serviceName&&(e.dataService=new $({serviceName:e.serviceName})),e.serviceName=e.dataService&&e.dataService.serviceName,e.keyGeneratorCtor=e.keyGeneratorCtor||gr,(r||t.keyGeneratorCtor)&&(e.keyGenerator=new e.keyGeneratorCtor)},e.prototype.createEntity=function(e,t,r,n){_(e,"entityType").isString().or().isInstanceOf(Gt).check(),_(r,"entityState").isEnumOf(ke).isOptional().check(),_(n,"mergeStrategy").isEnumOf(Re).isOptional().check();var i="string"==typeof e?this.metadataStore._getStructuralType(e):e;r=r||ke.Added;var a={};return S.using(this,"isLoading",!0,(function(){a=i.createEntity(t)})),r!==ke.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){_(e,"entities").isArray().isEntity().or().isNonEmptyArray().isInstanceOf(Gt).or().isNonEmptyArray().isString().or().isOptional().check(),null==t?t={includeMetadata:!0,asString:!0}:"boolean"==typeof t&&(t={includeMetadata:t,asString:!0}),j(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){t.forEach((function(e){if(e.entityAspect.entityState===ke.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 i=kr(e,t);null!=i&&i.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 a=[],o={};return S.objectForEach(r,(function(e,t){o[e]=function(e,t){var r={},n=e.entityType,i=n.dataProperties,a=Hr(n),o=[];return e._entities.forEach((function(e){if(e){var r=function e(t,r,n,i){var a={};if(r.forEach((function(r){var i=r.name,o=t.getProperty(i);if(null!=o||null!=r.defaultValue){if(o&&r.isComplexProperty){var s=r.dataType.dataProperties;o=S.map(o,(function(t){return e(t,s,n)}))}else o=n?n(r,o):o,r.isUnmapped&&(o=S.toJSONSafe(o,S.toJSONSafeReplacer));void 0!==o&&(a[i]=o)}})),Pt.isEntity(t)){var o=(u=t.entityAspect).entityState,s={tempNavPropNames:Kr(u,i||[]),entityState:o.name};u.extraMetadata&&(s.extraMetadata=u.extraMetadata),(o.isModified()||o.isDeleted())&&(s.originalValuesMap=u.originalValues),a.entityAspect=s}else{var u=t.complexAspect;s={};u.originalValues&&!S.isEmpty(u.originalValues)&&(s.originalValuesMap=u.originalValues),a.complexAspect=s}return a}(e,i,a,t);o.push(r)}})),r.entities=o,r}(t,a)})),{entityGroupMap:o,tempKeys:a}}(this,e),n=S.extend({},r,["tempKeys","entityGroupMap"]);return t.includeMetadata?(n=S.extend(n,this,["dataService","saveOptions","queryOptions","validationOptions"])).metadataStore=this.metadataStore.exportMetadata():(n.metadataVersion=Lt.metadataVersion,n.metadataStoreName=this.metadataStore.name),t.asString?JSON.stringify(n,null,z.stringifyPad):n},e.prototype.importEntities=function(e,t){var r=this;j(t=t||{}).whereParam("mergeStrategy").isEnumOf(Re).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&&$.fromJSON(n.dataService)||new $({serviceName:n.serviceName}),this.saveOptions=new mr(n.saveOptions),this.queryOptions=je.fromJSON(n.queryOptions),this.validationOptions=new hr(n.validationOptions)):t.metadataVersionFn&&t.metadataVersionFn({metadataVersion:n.metadataVersion,metadataStoreName:n.metadataStoreName});var i={};n.tempKeys.forEach((function(e){var t=Ve.fromJSON(e,r.metadataStore);i[t.toString()]=new Ve(t.entityType,r.keyGenerator.generateTempKeyValue(t.entityType,t.values[0]))}));var a=[],o=t;return o.tempKeyMap=i,S.wrapExecution((function(){r._pendingPubs=[]}),(function(e){r._pendingPubs.forEach((function(e){return e()})),r._pendingPubs=void 0,r._hasChangesAction&&r._hasChangesAction()}),(function(){S.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=tr.getRawValueFromClient;return t.entities.forEach((function(t){var r=t.entityAspect,l=o.getEntityKeyFromRawEntity(t,y),f=ke.fromName(r.entityState);if(!f||f===ke.Detached)throw new Error("Only entities with a non detached entity state may be imported.");var h=!a&&f.isAdded()&&jr(i,l);if(n=h?void 0:e.findEntityByKey(l))if(s===Re.SkipMerge);else{if(s===Re.Disallowed)throw new Error("A MergeStrategy of 'Disallowed' prevents "+l.toString()+" from being merged");var d=n.entityAspect.entityState.isUnchanged();(s===Re.OverwriteChanges||d)&&(o._updateTargetFromRaw(n,t,y),n.entityAspect.setEntityState(f),p.publish({entityAction:Ie.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 Ve(t.entityType,[a]),u=jr(i,s);n.setProperty(r,u.values[0])}))),n=e.attachEntity(n,f),p.publish({entityAction:Ie.AttachOnImport,entity:n}),f.isUnchanged()||u._notifyStateChange(n,!0);c.push(n)})),c}(zr(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(){S.objectMap(this._entityGroupMap,(function(e,t){return t._checkOperation("clear")})).forEach((function(e){e._clear()})),this._entityGroupMap={},this._unattachedChildrenMap=new Fr,this.keyGenerator=new this.keyGeneratorCtor,this.entityChanged.publish({entityAction:Ie.Clear}),this._setHasChanges(!1)},e.prototype.createEmptyCopy=function(){return new e(S.extend({},this,["dataService","metadataStore","queryOptions","saveOptions","validationOptions","keyGeneratorCtor"]))},e.prototype.addEntity=function(e){return this.attachEntity(e,ke.Added)},e.prototype.attachEntity=function(e,t,r){var n=this;_(e,"entity").isRequired().check(),this.metadataStore._checkEntityType(e);var i=_(t,"entityState").isEnumOf(ke).isOptional().check(ke.Unchanged),a=_(r,"mergeStrategy").isEnumOf(Re).isOptional().check(Re.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 Pt(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 S.using(this,"isLoading",!0,(function(){i.isAdded()&&function(e,t){var r=t.entityAspect.getKey(),n=S.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!==ir.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=void 0}})),this.validationOptions.validateOnAttach&&u.entityAspect.validateEntity(),i.isUnchanged()||this._notifyStateChange(u,!0),this.entityChanged.publish({entityAction:Ie.Attach,entity:u}),u},e.prototype.detachEntity=function(e){_(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=void 0):(_(e,"dataService").isInstanceOf($).isOptional().check(),_(t,"callback").isFunction().isOptional().check(),_(r,"errorCallback").isFunction().isOptional().check()),qr(this.metadataStore.fetchMetadata(e||this.dataService),t,r)},e.prototype.executeQuery=function(e,t,r){var n=this;_(e,"query").isInstanceOf(yt).or().isString().check(),_(t,"callback").isFunction().isOptional().check(),_(r,"errorCallback").isFunction().isOptional().check();var i=je.resolve([e.queryOptions,this.queryOptions,je.defaultInstance]),a=$.resolve([e.dataService,this.dataService]);return qr(!a.hasServerMetadata||this.metadataStore.hasMetadataFor(a.serviceName)?Ur(this,e,i,a):this.fetchMetadata(a).then((function(){return Ur(n,e,i,a)})),t,r)},e.prototype.executeQueryLocally=function(e){return Wr(this,e).results},e.prototype.saveChanges=function(e,t,r,n){_(e,"entities").isOptional().isArray().isEntity().check(),_(t,"saveOptions").isInstanceOf(mr).isOptional().check(),_(r,"callback").isFunction().isOptional().check(),_(n,"errorCallback").isFunction().isOptional().check(),t=t||this.saveOptions||mr.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||void 0);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;S.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=$.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 Br(i,n),S.using(i,"isLoading",!0,(function(){var e=new wr({query:void 0,entityManager:i,mergeOptions:{mergeStrategy:Re.OverwriteChanges},dataService:u});t=e.visitAndMerge(t,{nodeType:"root"})})),r.forEach((function(e){var t=i.metadataStore._getStructuralType(e.entityTypeName),r=new Ve(t,e.keyValues),n=i.getEntityByKey(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===oe.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;Rr(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){Rr(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 Ve(t,e.keyValues);r=n.getEntityByKey(a)}if(t&&r){var o=e.propertyName?{propertyName:e.propertyName,property:t.getProperty(e.propertyName)}:{},s=ie.getKey(e.errorName||e.errorMessage,e.propertyName),u=new ie(null,o,e.errorMessage,s);u.isServerError=!0,r.entityAspect.addValidationError(u)}return S.extend({entity:r,isServerError:!0},e,["errorName","errorMessage","propertyName","custom"])}));return t.entityErrors=a,t}(p,e);n&&n(t);return Promise.reject(t)}))}catch(o){return Rr(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){S.objectForEach(e.entityAspect._validationErrors,(function(t,r){var i=S.extend({entity:e,errorName:r.validator.name},r,["errorMessage","propertyName","isServerError","custom"]);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=Vr(this,t).entityKey,a=i._subtypes||[i.entityType];return a.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=$.resolve([this.dataService]);return!n.hasServerMetadata||this.metadataStore.hasMetadataFor(n.serviceName)?Mr(this,t):this.fetchMetadata(n).then((function(){return Mr(e,t)}))},e.prototype.findEntityByKey=function(e){return this.getEntityByKey(e)},e.prototype.generateTempKeyValue=function(e){_(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&&(void 0===e?this._hasChanges:this._hasChangesCore(e))},e.prototype._hasChangesCore=function(e){return Lr(this,kr(this,e)).some((function(e){return e&&e.hasChanges()}))},e.prototype.getChanges=function(e){return Ir(this,kr(this,e))},e.prototype.rejectChanges=function(){if(!this._hasChanges)return[];var e=Ir(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=kr(this,e);return _(t,"entityStates").isOptional().isEnumOf(ke).or().isNonEmptyArray().isEnumOf(ke).check(),function(e,t,r){var n=Lr(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=S.toArray(t);return r.forEach((function(e){if(!(e instanceof ke))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:Ie.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=void 0},e.prototype._linkRelatedEntities=function(e){var t=this,r=e.entityAspect;S.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!==ke.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;if(i.invForeignKeyNames.length){var o=new yt(a.entityType.defaultResourceName).where(i.invForeignKeyNames[0],"eq",a.values[0]);if(1===(p=t.executeQueryLocally(o)).length){var s=p[0];e.setProperty(i.name,s)}}else{var u=t.getEntityByKey(a);u?e.setProperty(i.name,u):n.addChild(a,i,e)}}else if(i.inverse&&i.inverse.invForeignKeyNames.length){var p,c=e.getProperty(i.inverse.invForeignKeyNames[0]);o=new yt(i.entityType.defaultResourceName).where(i.invForeignKeyNames[0],"eq",c);(p=t.executeQueryLocally(o)).forEach((function(t){t.setProperty(i.inverse.name,e)}))}})),e.entityType.foreignKeyProperties.forEach((function(r){var i=r.inverseNavigationProperty;if(i){var a=e.getProperty(r.name),o=new Ve(i.parentType,[a]),s=t.getEntityByKey(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=zr(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 Mr(e,t){var r=Vr(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!==Re.OverwriteChanges)),o?Promise.resolve({entity:a||void 0,entityKey:n,fromCache:!0}):yt.fromEntityKey(n).using(e).execute().then((function(e){return a=0===e.results.length?null:e.results[0],Promise.resolve({entity:a||void 0,entityKey:n,fromCache:!1})}))}function kr(e,t){return _(t,"entityTypes").isString().isOptional().or().isNonEmptyArray().isString().or().isInstanceOf(Gt).or().isNonEmptyArray().isInstanceOf(Gt).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 Ir(e,t){var r=Lr(e,t),n=[];return r.forEach((function(e){if(e){var t=e.getChanges();n=n&&n.length?n.concat(t):t}})),n}function Vr(e,t){try{if(t[0]instanceof Ve)return{entityKey:t[0],remainingArgs:S.arraySlice(t,1)};if(t.length>=2){var r="string"==typeof t[0]?e.metadataStore._getStructuralType(t[0],!1):t[0];return{entityKey:new Ve(r,t[1]),remainingArgs:S.arraySlice(t,2)}}}catch(e){}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 Rr(e,t){e.forEach((function(e){e.entityAspect.isBeingSaved=t}))}function Kr(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 jr(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 qr(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 Br(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}function Lr(e,t){var r=e._entityGroupMap;return t?S.toArray(t).map((function(e){if(e instanceof Gt)return r[e.name];throw new Error("The EntityManager.getChanges() 'entityTypes' parameter must be either an entityType or an array of entityTypes or null")})):S.getOwnPropertyValues(r)}function Ur(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===Ke.FromLocalCache)try{if("string"==typeof t)throw new Error("cannot execute 'string' EntityQuery locally.");var a=Wr(e,t);return Promise.resolve({results:a.results,entityManager:e,inlineCount:a.inlineCount,query:t})}catch(e){return Promise.reject(e)}var o=new wr({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=S.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=void 0,e._hasChangesAction&&e._hasChangesAction(),o=void 0,t.error)return Promise.reject(t.error)}),(function(){var a=n.jsonResultsAdapter.extractResults(r);a=S.toArray(a),i=o.visitAndMerge(a,{nodeType:"root"}),s&&i.forEach((function(e){e.entityAspect&&e.entityAspect.validateEntity()})),o.processDeferred(),t instanceof yt&&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 e(t,r){var n=r[0];t.forEach((function(t){var i=t.entityAspect;if(i&&(i._markAsLoaded(n),1!==r.length)){var a=t.getProperty(n);a&&(a.arrayChanged||(a=[a]),e(a,r.slice(1)))}}))}(e,r)}))}(i,t);var u=S.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(e){return e&&(e.query=t),Promise.reject(e)}}function zr(e,t){var r=e._entityGroupMap[t.name];return r||(r=new vr(e,t),e._entityGroupMap[t.name]=r),r}function $r(e,t){var r={},n=Pt.isEntity(e)?e.entityType:e.complexType,i=Hr(n),a={};return n.dataProperties.forEach((function(n){if(n.isComplexProperty)r[n.nameOnServer]=S.map(e.getProperty(n.name),(function(e){return $r(e,t)}));else{var o=e.getProperty(n.name);if(void 0===(o=t?t(n,o):o))return;void 0!==(o=i?i(n,o):o)&&(n.isUnmapped?a[n.nameOnServer]=S.toJSONSafe(o,S.toJSONSafeReplacer):r[n.nameOnServer]=o)}})),S.isEmpty(a)||(r.__unmapped=a),r}function Gr(e,t,r){var n=Pt.isEntity(e)?e.entityType:e.complexType,i=Pt.isEntity(e)?e.entityAspect:e.complexAspect,a=t.namingConvention.clientPropertyNameToServer,o={};return S.objectForEach(i.originalValues,(function(e,t){var i=n.getProperty(e);void 0!==(t=r?r(i,t):t)&&(o[a(e,i)]=t)})),n.complexProperties.forEach((function(n){var i=e.getProperty(n.name);if(n.isScalar){var s=Gr(i,t,r);S.isEmpty(s)||(o[a(n.name,n)]=s)}else{var u=i.map((function(e){return Gr(e,t,r)}));o[a(n.name,n)]=u}})),o}function Jr(e,t,r){var n=e.entityType,i=Hr(n),a=t.namingConvention.clientPropertyNameToServer,o={};return S.objectForEach(e.entityAspect.originalValues,(function(t,s){var u=n.getProperty(t),p=e.getProperty(t);void 0!==(p=r?r(u,p):p)&&void 0!==(p=i?i(u,p):p)&&(o[a(t,u)]=p)})),n.complexProperties.forEach((function(t){if(Qr(e,t)){var n=e.getProperty(t.name);o[a(t.name,t)]=S.map(n,(function(e){return $r(e,r)}))}})),o}function Qr(e,t){var r=e.getProperty(t.name);return t.isScalar?Zr(r):!!r._origValues||r.some((function(e){return Zr(e)}))}function Wr(e,t){_(t,"query").isInstanceOf(yt).check();var r=e.metadataStore,n=t._getFromEntityType(r,!0),i=function(e,t){return t.getSelfAndSubtypes().map((function(t){return zr(e,t)}))}(e,n),a=t.wherePredicate&&t.wherePredicate.toFunction({entityType:n}),o=!0===je.resolve([t.queryOptions,e.queryOptions,je.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:void 0,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 Zr(e){return!S.isEmpty(e.complexAspect.originalValues)||e.complexType.complexProperties.some((function(t){return Qr(e,t)}))}function Hr(e){return e.serializerFn||e.metadataStore&&e.metadataStore.serializerFn}Dr.prototype._$typeName="EntityManager",B.bubbleEvent(Dr.prototype);var Yr=function(){this.ajax=new L("ajax"),this.modelLibrary=new L("modelLibrary"),this.dataService=new L("dataService"),this.uriBuilder=new L("uriBuilder")};z.interfaceRegistry=new Yr,z._interfaceRegistry=z.interfaceRegistry,z.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},z.initializeAdapterInstances=function(e){return j(e).whereParam("dataService").isOptional().whereParam("modelLibrary").isOptional().whereParam("ajax").isOptional().whereParam("uriBuilder").isOptional().applyAll(this,!1),S.objectMap(z,this.initializeAdapterInstance)};function Xr(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 en(e,t){e._processAdds(t),Xr(e,"arrayChanged",{array:e,added:t})}function tn(e,t){e._processRemoves(t),Xr(e,"arrayChanged",{array:e,removed:t})}var rn={mixin:{push:function(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];if(this._inProgress)return-1;var r,n=this._getGoodAdds(e);if(!n.length)return this.length;this._beforeChange();var i=Object.getPrototypeOf(this);return r=i.push?i.push.apply(this,n):Array.prototype.push.apply(this,n),en(this,n),r},_push:function(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];if(this._inProgress)return-1;var r,n=e;this._beforeChange();var i=Object.getPrototypeOf(this);return r=i.push?i.push.apply(this,n):Array.prototype.push.apply(this,n),en(this,n),r},unshift:function(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];var r,n=this._getGoodAdds(e);if(!n.length)return this.length;this._beforeChange();var i=Object.getPrototypeOf(this);return r=i.unshift?i.unshift.apply(this,n):Array.prototype.unshift.apply(this,n),en(this,n),r},pop:function(){var e;this._beforeChange();var t=Object.getPrototypeOf(this);return tn(this,[e=t.pop?t.pop.apply(this):Array.prototype.pop.apply(this)]),e},shift:function(){var e;this._beforeChange();var t=Object.getPrototypeOf(this);return tn(this,[e=t.shift?t.shift.apply(this):Array.prototype.shift.apply(this)]),e},splice:function(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];var r,n=this._getGoodAdds(S.arraySlice(e,2)),i=S.arraySlice(e,0,2).concat(n);this._beforeChange();var a=Object.getPrototypeOf(this);return tn(this,r=a.splice?a.splice.apply(this,i):Array.prototype.splice.apply(this,i)),n.length&&en(this,n),r},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:Xr,initializeParent:function(e,t,r){e.parent=t,e.parentProperty=r}},nn={load:function(e,t){var r=this.parentEntity,n=yt.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){return!(e._addsInProcess.indexOf(t)>=0)&&t.getProperty(a.name)!==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;return n.getProperty(i)!==t.getProperty(e)}))}))}return r}(e,t);if(!r.length)return r;var n=e.parentEntity.entityAspect.entityManager;n&&!n.isLoading&&r.forEach((function(t){if(t.entityAspect.entityState.isDetached()){e._inProgress=!0;try{n.attachEntity(t,ke.Added)}finally{e._inProgress=!1}}}));return 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 an(e,t,r){var n=e;return n.parentEntity=t,n.navigationProperty=r,n.arrayChanged=new B("arrayChanged",n),n._addsInProcess=[],S.extend(n,rn.mixin),S.extend(n,nn)}var on={_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(){rn.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){sn(t,e)}))}(this,e)},_rejectChanges:function(){if(this._origValues){var e=this;this.forEach((function(t){sn(t,e)})),this.length=0,this._origValues.forEach((function(t){e.push(t)}))}},_acceptChanges:function(){this._origValues=null}};function sn(e,t){var r=e.complexAspect;return r.parent!==t.parent?null:(r.parent=void 0,r.parentProperty=void 0,r)}function un(e,t,r){var n=e;return rn.initializeParent(n,t,r),n.arrayChanged=new B("arrayChanged",n),S.extend(n,rn.mixin),S.extend(n,on)}var pn={_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 cn(e,t,r){var n=e;return rn.initializeParent(n,t,r),n.arrayChanged=new B("arrayChanged",n),S.extend(n,rn.mixin),S.extend(n,pn)}var yn,ln={AbstractDataServiceAdapter:yr,assertConfig:null,assertParam:null,AutoGeneratedKeyType:ir,BooleanQueryOp:mt,ComplexAspect:At,ComplexType:er,config:z,core:S,DataProperty:tr,DataService:$,DataType:oe,EntityAction:Ie,EntityAspect:Pt,EntityKey:Ve,EntityManager:Dr,EntityQuery:yt,EntityState:ke,EntityType:Gt,Event:B,FetchStrategy:Ke,FilterQueryOp:dt,InterfaceRegistry:Yr,JsonResultsAdapter:J,KeyGenerator:gr,LocalQueryComparisonOptions:jt,makeComplexArray:un,makePrimitiveArray:cn,makeRelationArray:an,MergeStrategy:Re,MetadataStore:Lt,NamingConvention:Ct,NavigationProperty:rr,OrderByClause:gt,Param:T,Predicate:qe,QueryOptions:je,SaveOptions:mr,ValidationError:ie,ValidationOptions:hr,Validator:X,version:"2.1.5"};try{yn=window||(global?global.window:void 0)}catch(e){}yn&&(yn.breeze=ln),e.AbstractDataServiceAdapter=yr,e.AndOrPredicate=Qe,e.AnyAllPredicate=We,e.AutoGeneratedKeyType=ir,e.BinaryPredicate=Je,e.BreezeConfig=U,e.BreezeEnum=a,e.BreezeEvent=B,e.ComplexAspect=At,e.ComplexType=er,e.DataProperty=tr,e.DataService=$,e.DataType=oe,e.EntityAction=Ie,e.EntityAspect=Pt,e.EntityKey=Ve,e.EntityManager=Dr,e.EntityQuery=yt,e.EntityState=ke,e.EntityType=Gt,e.ExpandClause=Et,e.FetchStrategy=Ke,e.FilterQueryOp=dt,e.FnExpr=Xe,e.InterfaceRegistry=Yr,e.JsonResultsAdapter=J,e.KeyGenerator=gr,e.LitExpr=He,e.LocalQueryComparisonOptions=jt,e.MappingContext=wr,e.MergeStrategy=Re,e.MetadataStore=Lt,e.NamingConvention=Ct,e.NavigationProperty=rr,e.OrderByClause=gt,e.Predicate=qe,e.PropExpr=Ye,e.QueryOptions=je,e.SaveOptions=mr,e.SelectClause=wt,e.UnaryPredicate=Ge,e.ValidationError=ie,e.ValidationOptions=hr,e.Validator=X,e.assertConfig=j,e.assertParam=_,e.breeze=ln,e.config=z,e.core=S,e.makeComplexArray=un,e.makePrimitiveArray=cn,e.makeRelationArray=an,e.ɵa=Ze,e.ɵb=T,e.ɵc=pr,e.ɵd=mt,Object.defineProperty(e,"__esModule",{value:!0})}));
|
|
15
|
+
***************************************************************************** */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(e){i={error:e}}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=P(Object.prototype.hasOwnProperty),s=P(Array.prototype.slice),u=function(){try{return!(!Object.getPrototypeOf||!Object.defineProperty({},"x",{}))}catch(e){return!1}}();function p(e,t){if(u){if(e.hasOwnProperty(t))return Object.getOwnPropertyDescriptor(e,t);var r=Object.getPrototypeOf(e);if(null!=r)return p(r,t)}}function c(e,t){for(var r in t)void 0===e[r]&&(e[r]=t[r]);return e}function y(e){var t=window||(global?global.window:void 0);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):void 0;try{return n(e)}catch(e){return}}}}var l=/[xy]/g;var f=/^P((\d+Y)?(\d+M)?(\d+D)?)?(T(\d+H)?(\d+M)?(\d+S)?)?$/,h=/[A-Za-z]+/g;function d(e){return null===e?"null":void 0===e?"undefined":Object.prototype.toString.call(e).slice(8,-1).toLowerCase()}var m=/^((\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)))$/;function g(e){return"function"===d(e)}var v=/^[a-fA-F\d]{8}-(?:[a-fA-F\d]{4}-){3}[a-fA-F\d]{12}$/;var w=/^(-|)?P[T]?[\d\.,\-]+[YMDTHS]/;var E=/([A-Z](?=[A-Z][a-z])|[^A-Z](?=[A-Z])|[a-zA-Z](?=[^a-zA-Z]))/g;function P(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 S={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];void 0!==i&&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(void 0!==o){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 e(t,r,n){if(!t||!r)return!1;if(t.length!==r.length)return!1;for(var i=0;i<t.length;i++)if(Array.isArray(t[i])){if(!e(t[i],r[i]))return!1}else if(n){if(!n(t[i],r[i]))return!1}else if(t[i]!==r[i])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=g(t)?t:void 0,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){if(!e)return n();var i=e[t];if(r===i)return n();e[t]=r;try{return n()}finally{void 0===i?delete e[t]:e[t]=i}},wrapExecution:function(e,t,r){var n;try{return n=e(),r()}catch(e){throw"object"==typeof n&&(n.error=e),e}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(l,(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=f.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(h,""):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"===d(e)&&!isNaN(e.getTime())},isDateString:function(e){return"string"==typeof e&&m.test(e)},isGuid:function(e){return"string"==typeof e&&v.test(e)},isDuration:function(e){return"string"==typeof e&&w.test(e)},isFunction:g,isEmpty:function(e){if(null==e)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(E,"$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),void 0===n||(r[i[0]]=n),!0)))}))};for(var i in t)n(i);return r},toJSONSafe:function e(t,r){if(t!==Object(t))return t;if(!t._$visited){if(t.toJSON){var n=t.toJSON();if(n!==Object(n))return n;if(n!==t)return e(n,r);t=n}var i;if(t._$visited=!0,t instanceof Array)i=t.map((function(t){return e(t,r)}));else if("function"==typeof t)i=void 0;else for(var a in i={},t)if("_$visited"!==a){var o=t[a];r&&void 0===(o=r(a,o))||void 0!==(o=e(o,r))&&(i[a]=o)}return delete t._$visited,i}},toJSONSafeReplacer:function(e,t){if("entityAspect"!==e&&"complexAspect"!==e&&"entityType"!==e&&"complexType"!==e&&"getProperty"!==e&&"setProperty"!==e&&"constructor"!==e&&"_"!==e.charAt(0)&&"$"!==e.charAt(0))return t},strings:{TO_TYPE:"Add 'EntityQuery.toType()' to your query, or call 'MetadataStore.setEntityTypeForResourceName()' to register an EntityType for this resourceName."}},T=function(){function e(e,t){this._applyOne=function(e){void 0!==this.v?e[this.name]=this.v:void 0!==this.defaultValue&&(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 V(this,{fn:O,msg:"must be a nonEmpty string"})},e.prototype.isTypeOf=function(e){return V(this,{fn:N,typeName:e,msg:"must be a '"+e+"'"})},e.prototype.isInstanceOf=function(e,t){return V(this,{fn:A,type:e,typeName:t=t||e.prototype._$typeName,msg:"must be an instance of '"+t+"'"})},e.prototype.hasProperty=function(e){return V(this,{fn:C,propertyName:e,msg:"must have a '"+e+"' property"})},e.prototype.isEnumOf=function(e){return V(this,{fn:b,enumType:e,msg:"must be an instance of the '"+(e.name||"unknown")+"' enumeration"})},e.prototype.isRequired=function(e){return void 0===e&&(e=!1),V(this,{fn:x,allowNull:e,msg:"is required"})},e.prototype.isOptional=function(){return V(this,{fn:F,prevContext:null,msg:D})},e.prototype.isNonEmptyArray=function(){return this.isArray(!0)},e.prototype.isArray=function(e){return V(this,{fn:M,mustNotBeEmpty:e,prevContext:null,msg:k})},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;return t.some((function(t){return!!t.fn&&t.fn(t,e.v)}))}(this);if(void 0!==t){if(!t)throw new Error(this.getMessage());return void 0!==this.v?this.v:e}},e.prototype._addContext=function(e){return V(this,e)},e.prototype.getMessage=function(){var e=this,t=this._contexts.map((function(t){return I(t,e.v)})).join(", or it ");return S.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=S.extend({},this.parent.config);if(this.parent.params.forEach((function(r){n||delete i[r.name];try{r.check()}catch(t){R(e,t.message)}!t&&r._applyOne(e)})),!n)for(var a in i)void 0!==i[a]&&R(e,S.formatString("Unknown property: '%1'.",a))},e}(),_=function(e,t){return new T(e,t)};function N(e,t){return null!=t&&typeof t===e.typeName}function O(e,t){return null!=t&&("string"==typeof t&&t.length>0)}function A(e,t){return null!=t&&null!=e.type&&t instanceof e.type}function b(e,t){return null!=t&&null!=e.enumType&&e.enumType.contains(t)}function C(e,t){return null!=t&&null!=e.propertyName&&void 0!==t[e.propertyName]}function x(e,t){return e.allowNull?void 0!==t:null!=t}function F(e,t){if(null==t)return!0;var r=e.prevContext;return!r||!r.fn||r.fn(r,t)}function D(e,t){var r=e.prevContext;return"is optional"+(r?" or it "+I(r,t):"")}function M(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 k(e,t){var r=e.mustNotBeEmpty?"a nonEmpty array":"an array",n=e.prevContext;return" must be "+r+(n?" where each element "+I(n,t):"")}function I(e,t){var r=e.msg;return"function"==typeof r&&(r=r(e,t)),r}function V(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 R(e,t){throw new Error(S.formatString("Error configuring an instance of '%1'. %2",e&&e._$typeName||"object",t))}var K=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 T(this.config[e],e);return t.parent=this,this.params.push(t),t},e}(),j=function(e){return new K(e)};function q(e,t,r){var n=e._subscribers;if(!n)return!0;n.forEach((function(n){try{n.callback(t)}catch(t){t.context="unable to publish on topic: "+e.name,r?r(t):e._defaultErrorCallback&&e._defaultErrorCallback(t)}}))}S.Param=T,S.assertParam=_,S.assertConfig=j;var B=function(){function e(t,r,n){this.unsubscribe=function(e){if(!this._subscribers)return!1;var t=this._subscribers,r=S.arrayIndexOf(t,(function(t){return t.unsubKey===e}));return-1!==r&&(t.splice(r,1),0===t.length&&(this._subscribers=null),!0)},_(t,"eventName").isNonEmptyString().check(),_(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(q,0,this,t,n):q(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){_(e,"eventName").isNonEmptyString().check(),_(t,"obj").isObject().check(),_(r,"isEnabled").isBoolean().isOptional().or().isFunction().check();var n=t;n._$eventMap||(n._$eventMap={}),n._$eventMap[e]=r},e.isEnabled=function(t,r){if(_(t,"eventName").isNonEmptyString().check(),_(r,"obj").isObject().check(),void 0===r._getEventParent)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}();S.Event=B;var L=function(){function e(e){this.name=e,this.defaultInstance=void 0,this._implMap={}}return e.prototype.registerCtor=function(e,t){this._implMap[e.toLowerCase()]={ctor:t,defaultInstance:void 0}},e.prototype.getImpl=function(e){return this._implMap[e.toLowerCase()]},e.prototype.getFirstImpl=function(){var e=S.objectFirst(this._implMap,(function(){return!0}));return e?e.value:null},e.prototype.getDefaultInstance=function(){return this.defaultInstance},e}(),U=function(){function e(){if(this.functionRegistry={},this.typeRegistry={},this.objectRegistry={},this.stringifyPad="",this.interfaceInitialized=new B("interfaceInitialized",this),void 0===this.noEval)try{Error.x=Function(""),this.noEval=!1}catch(e){this.noEval=!0}}return e.prototype.registerAdapter=function(e,t){_(e,"interfaceName").isNonEmptyString().check(),_(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=void 0===r||r,_(e,"interfaceName").isNonEmptyString().check(),_(t,"adapterName").isNonEmptyString().check(),_(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);if(r)return r.defaultInstance?r.defaultInstance:this._initializeAdapterInstanceCore(n,r,i)},e.prototype.registerFunction=function(e,t){_(e,"fn").isFunction().check(),_(t,"fnName").isString().check(),e.prototype&&(e.prototype._$fnName=t),this.functionRegistry[t]=e},e.prototype.registerType=function(e,t){_(e,"ctor").isFunction().check(),_(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=S.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){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}(),z=new U;S.config=z;var $=function(){function e(e){G(this,e)}return e.prototype.using=function(t){return t?G(new e(this),t):this},e.resolve=function(t){t.push({hasServerMetadata:!0,useJsonp:!1});var r=new e(S.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||z.getAdapterInstance("dataService",r.adapterName),r.jsonResultsAdapter=r.jsonResultsAdapter||r.adapterInstance.jsonResultsAdapter,r.uriBuilder=r.uriBuilder||z.getAdapterInstance("uriBuilder",r.uriBuilderName),r},e._normalizeServiceName=function(e){return"/"!==(e=e.trim()).substr(-1)?e+"/":e},e.prototype.toJSON=function(){return S.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=z._fetchObject(J,t.jsonResultsAdapter),new e(t)},e.prototype.qualifyUrl=function(e){if(e&&e.startsWith("http"))return e;var t=this.serviceName;return S.stringEndsWith(t,"/")&&(t=t.substr(0,t.length-1)),e="/"+e,S.stringEndsWith(t,e)||(t+=e),t},e}();function G(e,t){return t&&(j(t).whereParam("serviceName").isOptional().whereParam("adapterName").isString().isOptional().whereParam("uriBuilderName").isString().isOptional().whereParam("hasServerMetadata").isBoolean().isOptional().whereParam("jsonResultsAdapter").isInstanceOf(J).isOptional().whereParam("useJsonp").isBoolean().isOptional().applyAll(e),e.serviceName=e.serviceName&&$._normalizeServiceName(e.serviceName),e.adapterInstance=e.adapterName?z.getAdapterInstance("dataService",e.adapterName):void 0,e.uriBuilder=e.uriBuilderName?z.getAdapterInstance("uriBuilder",e.uriBuilderName):void 0),e}$.prototype._$typeName="DataService";var J=function(e){if(1!==arguments.length)throw new Error("The JsonResultsAdapter ctor should be called with a single argument that is a configuration object.");j(e).whereParam("name").isNonEmptyString().whereParam("extractResults").isFunction().isOptional().withDefault(Q).whereParam("extractSaveResults").isFunction().isOptional().withDefault(W).whereParam("extractKeyMappings").isFunction().isOptional().withDefault(Z).whereParam("extractDeletedKeys").isFunction().isOptional().withDefault(H).whereParam("visitNode").isFunction().applyAll(this),z._storeObject(this,"JsonResultsAdapter",this.name)};function Q(e){return e.results}function W(e){return e.entities||e.Entities||[]}function Z(e){return e.keyMappings||e.KeyMappings||[]}function H(e){return e.deletedKeys||e.DeletedKeys||[]}J.prototype._$typeName="JsonResultsAdapter";var Y={displayName:function(e){return e.property?e.property.resolveProperty("displayName")||e.propertyName||e.property.name:"Value"}},X=function(){function e(t,r,n){this._baseContext=n||{},this._baseContext.name=t,(n=S.extend(Object.create(Y),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?S.extend(Object.create(this.context),t):this.context,this.currentContext=r;try{return this.valFn(e,r)?null:(r.value=e,new ie(this,r,this.getMessage()))}catch(e){return new ie(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])?S.isFunction(i)?i(t):i:""})):e}(e.messageTemplate,e):"invalid value: "+(this.name||"{unnamed validator}")}catch(e){return"Unable to format error message"+e.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)}));if(t instanceof e)return t;var r="Validator."+t.name,n=z.getRegisteredFunction(r);if(!n)throw new Error("Unable to locate a validator named:"+t.name);return n(t)},e.register=function(e){z.registerFunction((function(){return e}),"Validator."+e.name)},e.registerFactory=function(e,t){z.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||S.isGuid(e)}))},e.duration=function(){return new e("duration",(function(e){return null==e||S.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 ee("int32",-2147483648,2147483647,e)()},e.int16=function(e){return ee("int16",-32768,32767,e)()},e.byte=function(e){return ee("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 S.isDate(e);try{return!isNaN(Date.parse(e))}catch(e){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))&&ne(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(e){throw new Error("Missing or invalid expression parameter to regExp validator")}}),t)},e.emailAddress=function(e){return te("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 te("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 te("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=te,e}();function ee(e,t,r,n){return n=n||{},void 0!==t&&(n.min=t),void 0!==r&&(n.max=r),n.messageTemplate||X.messageTemplates[e]||(X.messageTemplates[e]=S.formatString("'%displayName%' must be an integer between the values of %1 and %2",t,r)),function(){return new X(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 te(e,t,r,n){r&&(X.messageTemplates[e]=r);var i="string"==typeof t?new RegExp(t):t;return new X(e,(function(e){return null==e||""===e||"string"==typeof e&&i.test(e)}),n)}X.prototype._$typeName="Validator",Error.x=S.objectForEach(X,(function(e,t){"function"==typeof t&&"fromJSON"!==e&&"register"!==e&&"registerFactory"!==e&&"makeRegExpValidator"!==e&&z.registerFunction(t,"Validator."+e)}));var re,ne=(re=[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:re[t];return r%10==0}),ie=function(){function e(t,r,n,i){_(t,"validator").isOptional().isInstanceOf(X).check(),_(n,"errorMessage").isNonEmptyString().check(),_(i,"key").isOptional().isNonEmptyString().check(),this.validator=t||void 0,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}(),ae=/.\d{3}$/,oe=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&&S.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(S.isDate(e))return t.DateTime;switch(typeof e){case"string":return S.isGuid(e)?t.Guid:S.isDuration(e)&&e.length>3?t.Time:S.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=ae.test(e)?e+"Z":e);return e=new Date(Date.parse(e))},t.parseDateAsLocal=function(e){var r=t.parseDateAsUTC(e);return S.isDate(r)&&(r=new Date(r.getTime()+6e4*r.getTimezoneOffset())),r},t.toDateOnlyString=function(e){return e&&e.getTime&&new Date(e.getTime()-6e4*e.getTimezoneOffset()).toISOString().substring(0,10)||e},t.parseRawValue=function(e,t){if(void 0!==e)return 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:le,fmtOData:we,getNext:se}),t.Int64=new t({defaultValue:0,isNumeric:!0,isInteger:!0,quoteJsonOData:!0,parse:he,fmtOData:Pe("L"),getNext:ue}),t.Int32=new t({defaultValue:0,isNumeric:!0,isInteger:!0,parse:he,fmtOData:Ee,getNext:ue}),t.Int16=new t({defaultValue:0,isNumeric:!0,isInteger:!0,parse:he,fmtOData:Ee,getNext:ue}),t.Byte=new t({defaultValue:0,isNumeric:!0,isInteger:!0,parse:he,fmtOData:Ee}),t.Decimal=new t({defaultValue:0,isNumeric:!0,quoteJsonOData:!0,isFloat:!0,parse:de,fmtOData:Pe("m"),getNext:ue}),t.Double=new t({defaultValue:0,isNumeric:!0,isFloat:!0,parse:de,fmtOData:Pe("d"),getNext:ue}),t.Single=new t({defaultValue:0,isNumeric:!0,isFloat:!0,parse:de,fmtOData:Pe("f"),getNext:ue}),t.DateOnly=new t({defaultValue:new Date(1900,0,1),isDate:!0,parse:ge,parseRawValue:De,normalize:function(e){return e&&e.getTime&&new Date(e.getYear(),e.getMonth(),e.getDate()).getTime()},fmtOData:Te,getNext:ce,getConcurrencyValue:ye}),t.DateTime=new t({defaultValue:new Date(1900,0,1),isDate:!0,parse:me,parseRawValue:Fe,normalize:function(e){return e&&e.getTime&&e.getTime()},fmtOData:Se,getNext:ce,getConcurrencyValue:ye}),t.DateTimeOffset=new t({defaultValue:new Date(1900,0,1),isDate:!0,parse:me,parseRawValue:Fe,normalize:function(e){return e&&e.getTime&&e.getTime()},fmtOData:_e,getNext:ce,getConcurrencyValue:ye}),t.Time=new t({defaultValue:"PT0S",fmtOData:Ne,parseRawValue:t.parseTimeFromServer}),t.Boolean=new t({defaultValue:!1,parse:ve,fmtOData:Ae}),t.Guid=new t({defaultValue:"00000000-0000-0000-0000-000000000000",parse:fe,fmtOData:Oe,getNext:pe,parseRawValue:function(e){return e.toLowerCase()},getConcurrencyValue:S.getUuid}),t.Binary=new t({defaultValue:null,fmtOData:be,parseRawValue:Me}),t.Undefined=new t({defaultValue:void 0,fmtOData:Ce}),t}(a);function se(){return oe.constants.stringPrefix+ue().toString()}function ue(){var e=oe.constants.nextNumber;return oe.constants.nextNumber+=oe.constants.nextNumberIncrement,e}function pe(){return S.getUuid()}function ce(){return new Date}function ye(e){for(var t=new Date,r=new Date;t.getTime()===r.getTime();)r=new Date;return r}function le(e,t){return null==e?e:e.toString()}function fe(e,t){return"string"===t?e.trim().toLowerCase():e}function he(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 de(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 me(e,t){var r;if("string"===t){var n=e.trim();return""===n?null:(r=new Date(Date.parse(n)),S.isDate(r)?r:e)}return"number"===t?(r=new Date(e),S.isDate(r)?r:e):e}function ge(e,t){var r;if("string"===t){e.trim();return r=oe.parseDateAsLocal(r),S.isDate(r)?r:e}return"number"===t?(r=new Date(e),S.isDate(r)?r:e):e}function ve(e,t){if("string"===t){var r=e.trim().toLowerCase();return"false"!==r&&""!==r&&("true"===r||e)}return e}function we(e){return null==e?null:"'"+e.replace(/'/g,"''")+"'"}function Ee(e){return null==e?null:"string"==typeof e?parseInt(e,10):e}function Pe(e){return function(t){return null==t?null:("string"==typeof t&&(t=parseFloat(t)),t+e)}}function Se(e){if(null==e)return null;try{return"datetime'"+e.toISOString()+"'"}catch(t){xe("'%1' is not a valid dateTime",e)}}function Te(e){if(null==e)return null;try{return"date'"+e.toISOString().substring(0,10)+"'"}catch(t){xe("'%1' is not a valid dateTime",e)}}function _e(e){if(null==e)return null;try{return"datetimeoffset'"+e.toISOString()+"'"}catch(t){xe("'%1' is not a valid dateTime",e)}}function Ne(e){return null==e?null:(S.isDuration(e)||xe("'%1' is not a valid ISO 8601 duration",e),"time'"+e+"'")}function Oe(e){return null==e?null:(S.isGuid(e)||xe("'%1' is not a valid guid",e),"guid'"+e+"'")}function Ae(e){return null==e?null:"string"==typeof e?"true"===e.trim().toLowerCase():!!e}function be(e){return null==e?e:"binary'"+e+"'"}function Ce(e){return e}function xe(e,t){throw e=S.formatString(e,t),new Error(e)}function Fe(e){return S.isDate(e)||(e=oe.parseDateFromServer(e)),e}function De(e){return"string"==typeof e&&(e.length>10&&(e=e.substring(0,10)),e=oe.parseDateAsLocal(e)),e}function Me(e){return e&&void 0!==e.$value&&(e=e.$value),e}oe.prototype._$typeName="DataType",Error.x=oe._resetConstants(),Error.x=oe.resolveSymbols(),Error.x=oe.getSymbols().forEach((function(e){return e.validatorCtor=function(e){switch(e){case oe.String:return X.string;case oe.Int64:return X.int64;case oe.Int32:return X.int32;case oe.Int16:return X.int16;case oe.Decimal:case oe.Double:case oe.Single:return X.number;case oe.DateTime:case oe.DateTimeOffset:return X.date;case oe.Boolean:return X.bool;case oe.Guid:return X.guid;case oe.Byte:return X.byte;case oe.Binary:return X.none;case oe.Time:return X.duration;case oe.Undefined:return X.none}}(e)}));var ke=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.isDeletedOrDetached=function(){return this===t.Detached||this===t.Detached},t.prototype.isUnchangedOrModified=function(){return this===t.Unchanged||this===t.Modified},t.prototype.isAddedOrModified=function(){return this===t.Added||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);ke.prototype._$typeName="EntityState",Error.x=ke.resolveSymbols();var Ie=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);Ie.prototype._$typeName="EntityAction",Error.x=Ie.resolveSymbols();var Ve=function(){function e(t,r){_(t,"entityType").isInstanceOf(Gt).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===oe.Guid&&(r[t]=r[t]&&r[t].toLowerCase?r[t].toLowerCase():r[t])})),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&&S.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}();Ve.prototype._$typeName="EntityKey";var Re=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);Re.prototype._$typeName="MergeStrategy",Error.x=Re.resolveSymbols();var Ke=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);Ke.prototype._$typeName="FetchStrategy",Error.x=Ke.resolveSymbols();var je=function(){function e(t){e._updateWithConfig(this,t)}return e.resolve=function(t){return new e(S.resolveProperties(t,["fetchStrategy","mergeStrategy","includeDeleted"]))},e.prototype.using=function(t){if(!t)return this;var r=new e(this);return t instanceof Re?t={mergeStrategy:t}:t instanceof Ke&&(t={fetchStrategy:t}),e._updateWithConfig(r,t)},e.prototype.setAsDefault=function(){return S.setAsDefault(this,e)},e.prototype.toJSON=function(){return S.toJson(this,{fetchStrategy:null,mergeStrategy:null,includeDeleted:!1})},e.fromJSON=function(t){return new e({fetchStrategy:Ke.fromName(t.fetchStrategy),mergeStrategy:Re.fromName(t.mergeStrategy),includeDeleted:!0===t.includeDeleted})},e._updateWithConfig=function(e,t){return t&&j(t).whereParam("fetchStrategy").isEnumOf(Ke).isOptional().whereParam("mergeStrategy").isEnumOf(Re).isOptional().whereParam("includeDeleted").isBoolean().isOptional().applyAll(e),e},e.defaultInstance=new e({fetchStrategy:Ke.FromServer,mergeStrategy:Re.PreserveChanges,includeDeleted:!1}),e}();je.prototype._$typeName="QueryOptions";var qe=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]):Be(n):n instanceof e?n:"string"==typeof n?new $e(n):Le(n)}return Be(t)},e.prototype._validate=function(e,t){},e.and=function(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];var r=new Qe("and",e);return r},e.or=function(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];var r=new Qe("or",e);return r},e.not=function(e){return e.not()},e.extendFuncMap=function(e){for(var t in e||{}){var r=e[t];Xe._funcMap[t]=r}},e.prototype.and=function(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];return new Qe("and",Ue(this,e))},e.prototype.or=function(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];return new Qe("or",Ue(this,e))},e.prototype.not=function(){return new Ge("not",this)},e.prototype.toJSON=function(){return this.toJSONExt({entityType:this._entityType})},e.prototype.toJSONExt=function(e){return this.visit(e,pt)},e.prototype.toFunction=function(e){return this.visit(e,st)},e.prototype.toString=function(){return JSON.stringify(this)},e.prototype.visit=function(e,t){if(S.isEmpty(e))e={entityType:void 0};else if(e instanceof Gt)e={entityType:e};else if(!S.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)ze(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 Be(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]=Be(e.splice(2)),Le(t)}function Le(e){if(e instanceof qe)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(Qe.prototype._resolveOp(e,!0))return new Qe(e,t);if(Ge.prototype._resolveOp(e,!0))return new Ge(e,t);if("object"!=typeof t||null==t||S.isDate(t))return new Je("eq",e,t);if(S.hasOwnProperty(t,"value"))return new Je("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(We.prototype._resolveOp(e,!0))return new We(e,r,t[e]);if(Je.prototype._resolveOp(e,!0))return new Je(e,r,t[e]);if(S.hasOwnProperty(t[e],"value"))return new Je("eq",r,t[e]);var n=S.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 Qe("and",n)}(t,e[t])}));return 1===t.length?t[0]:new Qe("and",t)}function Ue(e,t){var r=t[0];return r instanceof qe?r=S.arraySlice(t):Array.isArray(r)||(r=[new qe(S.arraySlice(t))]),[e].concat(r)}function ze(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 $e=function(e){function t(t){var r=e.call(this)||this;return r.value=t,r}return r(t,e),t}(qe);Error.x=$e.prototype._initialize("passthruPredicate");var Ge=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 qe(r),i}return r(t,e),t.prototype._validate=function(e,t){this.pred._validate(e,t)},t}(qe);Error.x=Ge.prototype._initialize("unaryPredicate",{not:{aliases:["!","~"]}});var Je=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=it(this.expr1Source,r),null==this.expr1)throw new Error("Unable to validate 1st expression: "+this.expr1Source);if(this.expr1 instanceof He)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=S.extend(r,{isRHS:!0,dataType:this.expr1.dataType});if(this.expr2=it(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}(qe);Error.x=Je.prototype._initialize("binaryPredicate",{eq:{aliases:["==","equals","equal"]},ne:{aliases:["!=","~=","notequals","notequal"]},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 Qe=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 qe(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}(qe);Error.x=Qe.prototype._initialize("andOrPredicate",{and:{aliases:["&&"]},or:{aliases:["||"]}});var We=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 qe(n),i}return r(t,e),t.prototype._validate=function(e,t){this.expr=it(this.exprSource,{entityType:e,usesNameOnServer:t}),(null==e||e.isAnonymous)&&(this.expr.dataType=void 0),this.pred._validate(this.expr.dataType,t)},t}(qe);Error.x=We.prototype._initialize("anyAllPredicate",{any:{aliases:["some"]},all:{aliases:["every"]}});var Ze=function(){function e(e){this.visitorMethodName=e,this.visit=qe.prototype.visit}return e.prototype._validate=function(e,t){},e}(),He=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 oe)return e;if("string"==typeof e){var t=oe.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)||oe.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}(Ze);var Ye=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=S.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 tr?i.dataType:i.entityType}},t}(Ze),Xe=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:oe.String},tolower:{fn:function(e){return e.toLowerCase()},dataType:oe.String},substring:{fn:function(e,t,r){return e.substring(t,r)},dataType:oe.String},substringof:{fn:function(e,t){return t.indexOf(e)>=0},dataType:oe.Boolean},length:{fn:function(e){return e.length},dataType:oe.Int32},trim:{fn:function(e){return e.trim()},dataType:oe.String},concat:{fn:function(e,t){return e.concat(t)},dataType:oe.String},replace:{fn:function(e,t,r){return e.replace(t,r)},dataType:oe.String},startswith:{fn:function(e,t){return S.stringStartsWith(e,t)},dataType:oe.Boolean},endswith:{fn:function(e,t){return S.stringEndsWith(e,t)},dataType:oe.Boolean},indexof:{fn:function(e,t){return e.indexOf(t)},dataType:oe.Int32},round:{fn:function(e){return Math.round(e)},dataType:oe.Int32},ceiling:{fn:function(e){return Math.ceil(e)},dataType:oe.Int32},floor:{fn:function(e){return Math.floor(e)},dataType:oe.Int32},second:{fn:function(e){return e.getSeconds()},dataType:oe.Int32},minute:{fn:function(e){return e.getMinutes()},dataType:oe.Int32},hour:{fn:function(e){return e.getHours()},dataType:oe.Int32},day:{fn:function(e){return e.getDate()},dataType:oe.Int32},month:{fn:function(e){return e.getMonth()+1},dataType:oe.Int32},year:{fn:function(e){return e.getFullYear()},dataType:oe.Int32}},t}(Ze),et=/^[a-z_][\w.$]*$/i,tt=/('[^']*'|[^,]+)/g,rt=/("[^"]*"|[^,]+)/g,nt=String.fromCharCode(191);function it(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 He(e,t.dataType)}if("string"!=typeof e){if(null==e||"object"!=typeof e||e.toISOString)return new He(e,t.dataType);if(void 0===e.value)throw new Error("Unable to resolve an expression for: "+e+" on entityType: "+(r?r.name:"null"));return e.isProperty?new Ye(e.value):new He(e.value,e.dataType||t.dataType,!0)}if(t.isRHS)return null==r||r.isAnonymous?new He(e,t.dataType):ot(e,t);for(var n=/\([^()]*\)/,i=void 0,a=[],o=0;i=n.exec(e);){var s=i[0];a.push(s);var u=nt+o++;e=e.replace(s,u)}var p=at(e,a,t);return p._validate(r,t.usesNameOnServer),p}function at(e,t,r){var n=e.split(nt);return 1===n.length?ot(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?tt:rt,s=a.match(o),u=S.extend({},n);u.dataType=oe.Undefined,u.isFnArg=!0;var p=s.map((function(e){return at(e,r,u)}));return new Xe(i,p)}catch(e){throw e}}(e,n,t,r)}function ot(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 He(n,t.dataType||oe.String)}var i=t.entityType;return null==i||i.isAnonymous||et.test(e)&&null!=i.getPropertiesOnPath(e,null,!1)?new Ye(e):new He(e,t.dataType)}var st={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=oe.getComparableFn(t);switch(i.key){case"eq":n=function(e,t){return e&&"string"==typeof e?ut(e,t,r):a(e)===a(t)};break;case"ne":n=function(e,t){return e&&"string"==typeof e?!ut(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){r.isCaseSensitive||(e=(e||"").toLowerCase(),t=(t||"").toLowerCase());return S.stringStartsWith(e,t)}(e,t,r)};break;case"endswith":n=function(e,t){return function(e,t,r){r.isCaseSensitive||(e=(e||"").toLowerCase(),t=(t||"").toLowerCase());return S.stringEndsWith(e,t)}(e,t,r)};break;case"contains":n=function(e,t){return function(e,t,r){r.isCaseSensitive||(e=(e||"").toLowerCase(),t=(t||"").toLowerCase());return 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=S.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 Pt.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 ut(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 pt={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 Ye&&(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 e.or||"string"==typeof e}))||(t=r.reduce(ct)),null==t&&((t={})[this.op.key]=r),t):{}},anyAllPredicate:function(e){var t=this.expr.visit(e),r=S.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){var t=this.dataType===oe.DateOnly?oe.toDateOnlyString(this.value):this.value;return this.hasExplicitDataType||e.useExplicitDataType?{value:t,dataType:this.dataType.name}:t},propExpr:function(e){return e.toNameOnServer?e.entityType?e.entityType.clientPropertyPathToServer(this.propertyPath):(console.warn('No EntityType for propertyPath "'+this.propertyPath+'". '+S.strings.TO_TYPE),this.propertyPath):this.propertyPath},fnExpr:function(e){var t=this.exprs.map((function(t){return t.visit(e)}));return this.fnName+"("+t.join(",")+")"}};function ct(e,t){return Object.keys(t).every((function(r){if(e.hasOwnProperty(r)){if("object"!=typeof t[r])return!1;if(null==ct(e[r],t[r]))return!1}else{if("object"!=typeof e)return!1;e[r]=t[r]}return!0}))?e:null}var yt=function(){function e(e){if(null!=e&&"string"!=typeof e)return t=this,r=e,S.toJson(r,{"resourceName,from":null,"resultEntityType,toType":null,"wherePredicate,where":function(e){return e?new qe(e):void 0},"orderByClause,orderBy":function(e){return e?new gt(e):void 0},"selectClause,select":function(e){return e?new wt(e):void 0},"expandClause,expand":function(e){return e?new Et(e):void 0},"skipCount,skip":null,"takeCount,take":null,parameters:function(e){return S.isEmpty(e)?void 0:e},"inlineCountEnabled,inlineCount":!1,"noTrackingEnabled,noTracking":!1,"usePostEnabled,usePost":!1,queryOptions:function(e){return e?je.fromJSON(e):void 0}},t),t;var t,r;this.resourceName=e,this.fromEntityType=void 0,this.wherePredicate=void 0,this.orderByClause=void 0,this.selectClause=void 0,this.skipCount=void 0,this.takeCount=void 0,this.expandClause=void 0,this.parameters={},this.inlineCountEnabled=!1,this.noTrackingEnabled=!1,this.usePostEnabled=!1,this.entityManager=void 0}return e.prototype.from=function(e){return _(e,"resourceName").isString().check(),lt(this,"resourceName",e)},e.from=function(t){return _(t,"resourceName").isString().check(),new e(t)},e.prototype.toType=function(e){return _(e,"entityType").isString().or().isInstanceOf(Gt).check(),lt(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=qe.create.apply(qe,i(t)),this.fromEntityType&&e._validate(this.fromEntityType),this.wherePredicate&&(e=this.wherePredicate.and(e))),lt(this,"wherePredicate",e)},e.prototype.orderBy=function(e,t){var r=null==e?null:new gt(ft(e),t);return this.orderByClause&&r&&(r=new gt([this.orderByClause,r])),lt(this,"orderByClause",r)},e.prototype.orderByDesc=function(e){return this.orderBy(e,!0)},e.prototype.select=function(e){return lt(this,"selectClause",null==e?null:new wt(ft(e)))},e.prototype.skip=function(e){return _(e,"count").isOptional().isNumber().check(),lt(this,"skipCount",null==e?null:e)},e.prototype.top=function(e){return this.take(e)},e.prototype.take=function(e){return _(e,"count").isOptional().isNumber().check(),lt(this,"takeCount",null==e?null:e)},e.prototype.expand=function(e){return lt(this,"expandClause",null==e?null:new Et(ft(e)))},e.prototype.withParameters=function(e){return _(e,"parameters").isObject().check(),lt(this,"parameters",e)},e.prototype.inlineCount=function(e){return _(e,"enabled").isBoolean().isOptional().check(),lt(this,"inlineCountEnabled",e=void 0===e||!!e)},e.prototype.useNameOnServer=function(e){return _(e,"usesNameOnServer").isBoolean().isOptional().check(),lt(this,"usesNameOnServer",e=void 0===e||!!e)},e.prototype.noTracking=function(e){return _(e,"enabled").isBoolean().isOptional().check(),lt(this,"noTrackingEnabled",e=void 0===e||!!e)},e.prototype.usePost=function(e){return _(e,"enabled").isBoolean().isOptional().check(),lt(this,"usePostEnabled",e=void 0===e||!!e)},e.prototype.using=function(e){if(!e)return this;var t=lt(this);return function e(t,r,n,i){var o=n._$typeName||n instanceof a&&n.constructor.name,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=r[s];if(void 0===u)throw new Error("Invalid config property: "+s);null===u?t[s]=n:u(t,n)}else S.objectForEach(n,(function(n,i){e(t,r,i,n)}))}(t,{entityManager:null,dataService:null,queryOptions:null,fetchStrategy:function(e,t){e.queryOptions=(e.queryOptions||new je).using(t)},mergeStrategy:function(e,t){e.queryOptions=(e.queryOptions||new je).using(t)},jsonResultsAdapter:function(e,t){e.dataService=(e.dataService||new $).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):S.identity;var t=function(t){return t?t.toJSONExt(e):void 0};return S.toJson(this,{"from,resourceName":null,"toType,resultEntityType":function(e){return e?"string"==typeof e?e:e.name:void 0},"where,wherePredicate":t,"orderBy,orderByClause":t,"select,selectClause":t,"expand,expandClause":t,"skip,skipCount":null,"take,takeCount":null,parameters:function(e){return S.isEmpty(e)?void 0:e},"inlineCount,inlineCountEnabled":!1,"noTracking,noTrackingEnabled":!1,queryOptions:null})},e.fromEntities=function(t){_(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 qe.create(t.name,dt.Equals,e.getProperty(t.name))}));return qe.and(t)}(e)})),s=qe.or(o);a=a.where(s);var u=n.entityAspect.entityManager;return u&&(a=a.using(u)),a},e.fromEntityKey=function(t){_(t,"entityKey").isInstanceOf(Ve).check();var r=new e(t.entityType.defaultResourceName),n=ht(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?")}else{var i=e.getEntityTypeNameForResourceName(n);if(r=i?e._getStructuralType(i):this._getToEntityType(e,!0))return this.fromEntityType=r,r;if(t)throw new Error(S.formatString("Cannot find an entityType for resourceName: '%1'. ",n)+S.strings.TO_TYPE)}},e.prototype._getToEntityType=function(e,t){return this.resultEntityType instanceof Gt?this.resultEntityType:this.resultEntityType?(this.resultEntityType=e._getStructuralType(this.resultEntityType,!1),this.resultEntityType):void(t||this.selectClause||this._getFromEntityType(e,!1))},e.prototype._toUri=function(e){return $.resolve([e.dataService]).uriBuilder.buildUri(this,e.metadataStore)},e.fromEntityNavigation=function(t,r){_(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)}));return ht(new Ve(t.entityType,r))}var n=t.inverse,i=n?n.foreignKeyNames:t.invForeignKeyNames;if(0===i.length)return null;var a=e.entityAspect.getKey().values,o=S.arrayZip(i,a,(function(e,t){return qe.create(e,dt.Equals,t)}));return qe.and(o)}(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 lt(e,t,r){if(t&&e[t]===r)return e;var n=S.extend(new yt,e,["resourceName","fromEntityType","wherePredicate","orderByClause","selectClause","skipCount","takeCount","expandClause","inlineCountEnabled","noTrackingEnabled","usePostEnabled","usesNameOnServer","queryOptions","entityManager","dataService","resultEntityType"]);return n.parameters=S.extend({},e.parameters),t&&(n[t]=r),n}function ft(e){return _(e,"propertyPaths").isOptional().isString().or().isArray().isString().check(),"string"==typeof e&&(e=e.split(",")),e=e.map((function(e){return e.trim()}))}function ht(e){var t=e.entityType.keyProperties,r=S.arrayZip(t,e.values,(function(e,t){return qe.create(e.name,dt.Equals,t)}));return qe.and(r)}yt.prototype._$typeName="EntityQuery";var dt=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);dt.prototype._$typeName="FilterQueryOp",Error.x=dt.resolveSymbols();var mt=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);mt.prototype._$typeName="BooleanQueryOp",Error.x=mt.resolveSymbols();var gt=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=S.arrayFlatMap(n,(function(e){return e.items}))}else this.items=t.map((function(e){return new vt(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}(),vt=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=S.stringStartsWith(r[1].toLowerCase(),"desc"))&&!S.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=Pt.getPropertyPathValue(e,n),s=Pt.getPropertyPathValue(a,n),u=t||o&&oe.fromValue(o)||oe.fromValue(s);if(u===oe.String)r?(o=o||"",s=s||""):(o=(o||"").toLowerCase(),s=(s||"").toLowerCase());else{var p=oe.getComparableFn(u);o=p(o),s=p(s)}return o===s?0:o>s||void 0===s?i?-1:1:i?1:-1}},e}(),wt=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]]=Pt.getPropertyPathValue(t,n)})),r}},e.prototype.toJSONExt=function(e){return this.propertyPaths.map((function(t){return e.propertyPathFn(t)}))},e}(),Et=function(){function e(e){this.propertyPaths=e}return e.prototype.toJSONExt=function(e){return this.propertyPaths.map((function(t){return e.propertyPathFn(t)}))},e}(),Pt=function(){function e(e){if(this.setUnchanged=function(){return this.setEntityState(ke.Unchanged)},this.setModified=function(){return this.setEntityState(ke.Modified)},this.setDeleted=function(){return this.setEntityState(ke.Deleted)},this.setDetached=function(){return this.setEntityState(ke.Detached)},this.entity=e,this.entityGroup=void 0,this.entityManager=void 0,this.entityState=ke.Detached,this.isBeingSaved=!1,this.originalValues={},this.hasValidationErrors=!1,this._validationErrors={},this.validationErrorsChanged=new B("validationErrorsChanged",this),this.propertyChanged=new B("propertyChanged",this),null!=e){e.hasOwnProperty("entityType")&&delete e.entityType,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.getCtor();z.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=_(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 Ve(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:Ie.AcceptChanges,entity:this.entity})}},e.prototype.rejectChanges=function(){this._checkOperation("rejectChanges");var e=this.entity,t=this.entityManager;S.using(t,"isRejectingChanges",!0,(function(){St(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:Ie.RejectChanges,entity:e}))},e.prototype.getPropertyPath=function(e){return e},e.prototype.setAdded=function(){return this.setEntityState(ke.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===ke.Unchanged)bt(t),delete this.hasTempKey,n=!1;else if(e===ke.Added)bt(t);else if(e===ke.Deleted){if(this.entityState.isAdded())return this.setEntityState(ke.Detached),!0;this.entityState=ke.Deleted,Tt(t,ke.Deleted)}else if(e===ke.Modified);else if(e===ke.Detached){var i=this.entityGroup;if(!i)return!1;i.detachEntity(t),this.entityState=e,Tt(t,ke.Detached),this._detach(),r.entityChanged.publish({entityAction:Ie.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=yt.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||[],S.arrayAddItemUnique(this._loadedNps,e)},e.prototype.validateEntity=function(){var e=!0;return this._processValidationOpAndPublish((function(t){e=Ot(t.entity)})),e},e.prototype.validateProperty=function(e,t){var r=this.getPropertyValue(e);return r&&r.complexAspect?Ot(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){_(e,"property").isOptional().isEntityProperty().or().isString().check();var t=S.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){_(e,"validationError").isInstanceOf(ie).check(),this._processValidationOpAndPublish((function(t){t._addValidationError(e)}))},e.prototype.removeValidationError=function(e){_(e,"validationErrorOrKey").isString().or().isInstanceOf(ie).or().isInstanceOf(X).check();var t="string"==typeof e?e:e.key;this._processValidationOpAndPublish((function(e){e._removeValidationError(t)}))},e.prototype.clearValidationErrors=function(){this._processValidationOpAndPublish((function(e){S.objectForEach(e._validationErrors,(function(t,r){r&&(delete e._validationErrors[t],e._pendingValidationResult.removed.push(r))})),e.hasValidationErrors=!S.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 Ve(e.entityType,n)},e.prototype.getPropertyValue=function(e){var t;if(_(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 Gt))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=void 0,this.entityManager=void 0,this.entityState=ke.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=Nt(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=void 0}},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=!S.isEmpty(this._validationErrors),this._pendingValidationResult.removed.push(t))},e._nullInstance=new e,e}();function St(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?St(r):(r._rejectChanges(),r.forEach(St))}))}function Tt(e,t){t.isDeleted()?_t(e):S.using(e.entityAspect.entityManager,"isLoading",!0,(function(){_t(e)}))}function _t(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&&S.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 Nt(e,t,r,n){var i=t.validate(r,n);if(i)return e._addValidationError(i),!1;var a=ie.getKey(t,n?n.propertyName:null);return e._removeValidationError(a),!0}function Ot(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 void 0!==t&&(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?Ot(n)&&r:n.reduce((function(e,t,r){return Ot(t,r)&&e}),r))})),n.getAllValidators().forEach((function(t){r=Nt(a,t,e)&&r})),r}B.bubbleEvent(Pt.prototype,(function(){return this.entityManager}));var At=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();z.interfaceRegistry.modelLibrary.getDefaultInstance().startTracking(t,o.prototype)}return e.prototype.getEntityAspect=function(){var e=this.parent;if(!e)return new Pt;for(var t=e.entityAspect;e&&!t;)t=(e=e.complexAspect&&e.complexAspect.parent)&&e.entityAspect;return t||new Pt},e.prototype.getPropertyPath=function(e){var t=this.parent;return t?(t.complexAspect||t.entityAspect).getPropertyPath(this.parentProperty.name+"."+e):null},e}();function bt(e){(e.entityAspect||e.complexAspect).originalValues={},(e.entityType||e.complexType).complexProperties.forEach((function(t){var r=e.getProperty(t.name);t.isScalar?bt(r):(r._acceptChanges(),r.forEach(bt))}))}var Ct=function(){function e(e){j(e||{}).whereParam("name").isOptional().isString().whereParam("serverPropertyNameToClient").isFunction().whereParam("clientPropertyNameToServer").isFunction().applyAll(this),this.name||(this.name=S.getUuid()),z._storeObject(this,"NamingConvention",this.name)}return e.prototype.setAsDefault=function(){return S.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}();Ct.prototype._$typeName="NamingConvention";var xt=/Collection\((.*)\)/;function Ft(e,t,r,n,i){var a=t.key?S.toArray(t.key.propertyRef).map(S.pluck("name")):[];S.toArray(t.property).forEach((function(t){Dt(e,t,r,a)})),S.toArray(t.navigationProperty).forEach((function(t){!function(e,t,r,n){var i=function(e,t,r){var n=It(e.relationship,t),i=n.namespace,a=S.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 S.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=S.arrayFirst(i.end,(function(e){return e.role===t.toRole})),o="*"!==a.multiplicity,s=It(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=S.toArray(y.propertyRef).map(S.pluck("name"));t.fromRole===c.role?p.invForeignKeyNamesOnServer=l:p.foreignKeyNamesOnServer=l}var f=new rr(p);e._addPropertyCore(f)}(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){Ft(e.entityType,e.csdlEntityType,r,n,i)})),delete o[e.name])}function Dt(e,t,r,n){var i,a=t.type.split(".");return a[0].endsWith("Edm")&&2===a.length?i=Mt(e,t,n):!function(e,t){return t.enumType?function(e,t){var r=S.toArray(t.enumType),n=(Vt(e.type)||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=(Vt(e.type)||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=kt(t.type),i=It(Vt(t.type)||t.type,r).typeName;return new tr({nameOnServer:t.name,complexTypeName:i,isNullable:!1,isScalar:!n})}(0,t,r):(i=Mt(e,t,n))&&(i.enumType=t.type),i&&(e._addPropertyCore(i),function(e){var t;e.isNullable||e.validators.push(X.required());if(e.isComplexProperty)return;if(e.dataType===oe.String)if(e.maxLength){var r={maxLength:e.maxLength};t=X.maxLength(r)}else t=X.string();else{var n=e.dataType.validatorCtor;if(!n)return;t=n()}e.validators.push(t)}(i)),i}function Mt(e,t,r){var n=kt(t.type),i=Vt(t.type)||t.type,a=oe.fromEdmDataType(i);if(null!=a){var o="true"===t.nullable||null==t.nullable,s=null!=r&&r.indexOf(t.name)>=0;s&&e instanceof Gt&&e.autoGeneratedKeyType===ir.None&&function(e){var t=S.arrayFirst(Object.keys(e),(function(e){return e.indexOf("StoreGeneratedPattern")>=0}));if(t)return"Identity"===e[t];var r=e.extensions;return!!r&&!!S.arrayFirst(r,(function(e){return"StoreGeneratedPattern"===e.name&&"Identity"===e.value}))}(t)&&(e.autoGeneratedKeyType=ir.Identity);var u=t.maxLength;u=null==u||"Max"===u?null:parseInt(u,10);var p=new tr({nameOnServer:t.name,dataType:a,isNullable:o,isPartOfKey:s,isScalar:!n,maxLength:u,defaultValue:t.defaultValue,concurrencyMode:t.concurrencyMode});return a===oe.Undefined&&(p.rawTypeName=t.type),p}e.warnings.push("Unable to recognize DataType for property: "+t.name+" DateType: "+t.type)}function kt(e){return xt.test(e)}function It(e,t){var r=Lt.parseTypeName(e);if(t&&t.cSpaceOSpaceMapping){var n=Rt(r.shortTypeName,t);n&&(r=Lt.makeTypeHash(r.shortTypeName,n))}return r}function Vt(e){var t=e.match(xt);return t?t[1]:null}function Rt(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}var Kt={parse:function(e,t,r){e._entityTypeResourceMap={},(t=S.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&&S.toArray(r.entityContainer).forEach((function(t){S.toArray(t.entitySet).forEach((function(t){var n=It(t.entityType,r).typeName;e.setEntityTypeForResourceName(t.name,n),e._entityTypeResourceMap[n]=t.name}))})),r.complexType&&S.toArray(r.complexType).forEach((function(t){!function(e,t,r){var n=e.name,i=Rt(n,t),a=new er({shortName:n,namespace:i});S.toArray(e.property).forEach((function(e){Dt(a,e,t)})),r.addEntityType(a)}(t,r,e)})),r.entityType&&S.toArray(r.entityType).forEach((function(n){!function(e,t,r,n){var i=e.name,a=Rt(i,t),o=new Gt({shortName:i,namespace:a,isAbstract:e.abstract&&"true"===e.abstract});if(e.baseType){var s=It(e.baseType,t).typeName;if(o.baseTypeName=s,n._getStructuralType(s,!0))Ft(o,e,t,r,n);else{var u=n._deferredTypes[s];u||(u=[],n._deferredTypes[s]=u),u.push({entityType:o,csdlEntityType:e})}}else Ft(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}},jt=function(){function e(e){j(e||{}).whereParam("name").isOptional().isString().whereParam("isCaseSensitive").isOptional().isBoolean().whereParam("usesSql92CompliantStringComparison").isBoolean().applyAll(this),this.name||(this.name=S.getUuid()),z._storeObject(this,"LocalQueryComparisonOptions",this.name)}return e.prototype.setAsDefault=function(){return S.setAsDefault(this,e)},e.caseInsensitiveSQL=new e({name:"caseInsensitiveSQL",isCaseSensitive:!1,usesSql92CompliantStringComparison:!0}),e.defaultInstance=new e(e.caseInsensitiveSQL),e}();function qt(e,t,r){void 0===t&&(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||null===t&&void 0===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(S.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(S.formatString("You cannot set the '%1' property to null because its 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=Pt.isEntity(r)?r.entityAspect:r.complexAspect;void 0===p.originalValues[u]&&(p.originalValues[u]=void 0!==a?a:n.defaultValue)}if(n.isPartOfKey&&s&&!s.isLoading){var c=(E=r.entityType).keyProperties.map((function(e){return e===n?o:r.getProperty(e.name)})),y=new Ve(E,c);if(s.getEntityByKey(y))throw new Error("An entity with this key is already in the cache: "+y.toString());var l=r.entityAspect.getKey();s._findEntityGroup(E)._replaceKey(l,y)}var f=n.relatedNavigationProperty;if(f&&s)if(null!=o){var h=void 0,d=void 0;if(f.invForeignKeyNames.length){var m=new yt(f.entityType.defaultResourceName).where(f.invForeignKeyNames[0],"eq",o),g=s.executeQueryLocally(m);1===g.length&&(h=g[0])}else d=new Ve(f.entityType,[o]),h=s.getEntityByKey(d);h?r.setProperty(f.name,h):(d&&s._unattachedChildrenMap.addChild(d,f,r),r.setProperty(f.name,null))}else r.setProperty(f.name,null);else if(n.inverseNavigationProperty&&s&&!s._inKeyFixup){var v=n.inverseNavigationProperty;if(null!=a){d=new Ve(v.parentType,[a]);if(h=s.getEntityByKey(d))if(v.isScalar)h.setProperty(v.name,null);else{var w=h.getProperty(v.name);w.splice(w.indexOf(r),1)}}if(null!=o){d=new Ve(v.parentType,[o]);(h=s.getEntityByKey(d))?v.isScalar?h.setProperty(v.name,r):h.getProperty(v.name).push(r):s._unattachedChildrenMap.addChild(d,v,r)}}if(t(o),Bt(e),n.isPartOfKey){var E,P=(E=r.entityType).keyProperties.indexOf(n);if(E.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.slice(0).forEach((function(e){e.setProperty(a,o)}))}}})),s){for(var S=E.inverseForeignKeyProperties,T=E.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){if(!o.entityAspect)return;var p=o.entityAspect;if(s){if(p.entityState.isDetached())s.isLoading||s.attachEntity(o,ke.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,ke.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)o.getProperty(u.name).push(r)}else if(n.invForeignKeyNames&&s&&!s._inKeyFixup){var l=n.invForeignKeyNames;if(null!=o){var f=r.entityAspect.getKey().values;l.forEach((function(e,t){o.setProperty(e,f[t])}))}else null!=a&&l.forEach((function(e){a.entityType.getProperty(e).isPartOfKey||a.setProperty(e,null)}))}if(t(o),Bt(e),n.relatedDataProperties){var h=i.entityState;if(null==o&&(h.isDetached()||a.entityAspect.entityState.isDetached()))return;if(h.isDeleted())return;var d=n.invForeignKeyNames;d&&d.length||(d=n.entityType.keyProperties.map((function(e){return e.name}))),d.forEach((function(e,t){var i=n.relatedDataProperties[t];if(o||!i.isPartOfKey){var a=o?o.getProperty(e):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:Ie.PropertyChange,entity:n,args:i})):t.propertyChanged.publish(i)}(p)}finally{u.pop()}}}}function Bt(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})}}jt.prototype._$typeName="LocalQueryComparisonOptions";var Lt=function(){function e(t){j(t=t||{}).whereParam("namingConvention").isOptional().isInstanceOf(Ct).withDefault(Ct.defaultInstance).whereParam("localQueryComparisonOptions").isOptional().isInstanceOf(jt).withDefault(jt.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 B("metadataFetched",this)}return e.prototype.setProperties=function(e){j(e).whereParam("name").isString().isOptional().whereParam("serializerFn").isFunction().isOptional().applyAll(this)},e.prototype.addDataService=function(e,t){_(e,"dataService").isInstanceOf($).check(),_(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 S.arrayIndexOf(this.dataServices,(function(t){return t.serviceName===e}))},e.prototype.addEntityType=function(e){var t;if((t=e instanceof Gt||e instanceof er?e:e.isComplexType?new er(e):new Gt(e))instanceof Gt){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 Gt){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:S.objectMap(this._structuralTypeMap),resourceEntityTypeMap:this._resourceEntityTypeMap},null,z.stringifyPad)},e.prototype.importMetadata=function(t,r){var n=this;void 0===r&&(r=!1),_(r,"allowMerge").isOptional().isBoolean().check(),this._deferredTypes={};var i="string"==typeof t?t:JSON.stringify(t),a=JSON.parse(i);if(a.schema)return Kt.parse(this,a.schema,a.altMetadata);var o=a;if(o.metadataVersion&&o.metadataVersion!==e.metadataVersion){var s=S.formatString("Cannot import metadata with a different 'metadataVersion' (%1) than the current 'MetadataStore.metadataVersion' (%2) ",o.metadataVersion,e.metadataVersion);throw new Error(s)}var u=o.namingConvention,p=o.localQueryComparisonOptions;if(this.isEmpty())this.namingConvention=z._fetchObject(Ct,u)||this.namingConvention,this.localQueryComparisonOptions=z._fetchObject(jt,p)||this.localQueryComparisonOptions;else{if(u&&this.namingConvention.name!==u)throw new Error("Cannot import metadata with a different 'namingConvention' from the current MetadataStore");if(p&&this.localQueryComparisonOptions.name!==p)throw new Error("Cannot import metadata with different 'localQueryComparisonOptions' from the current MetadataStore")}return o.dataServices&&o.dataServices.forEach((function(e){var t=$.fromJSON(e);n.addDataService(t,!0)})),o.structuralTypes&&o.structuralTypes.forEach((function(e){!function(e,t,r){var n=pr(t.shortName,t.namespace),i=e._getStructuralType(n,!0);if(i)return r?function(e,t){t.custom&&(e.custom=t.custom);return Ut(e,t.dataProperties),Ut(e,t.navigationProperties),e}(i,t):i;var a={shortName:t.shortName,namespace:t.namespace,isAbstract:t.isAbstract,autoGeneratedKeyType:ir.fromName(t.autoGeneratedKeyType),defaultResourceName:t.defaultResourceName,custom:t.custom};if(i=t.isComplexType?new er(a):new Gt(a),t.baseTypeName&&i instanceof Gt){i.baseTypeName=t.baseTypeName,e._getStructuralType(t.baseTypeName,!0)?zt(e,t,i):S.getArray(e._deferredTypes,t.baseTypeName).push({json:t,stype:i})}else zt(e,t,i)}(n,e,r)})),S.extend(this._resourceEntityTypeMap,o.resourceEntityTypeMap),S.extend(this._incompleteTypeMap,o.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 _(e,"serviceName").isString().check(),e=$._normalizeServiceName(e),S.arrayFirst(this.dataServices,(function(t){return t.serviceName===e}))},e.prototype.fetchMetadata=function(e,t,r){var n=this;try{if(_(e,"dataService").isString().or().isInstanceOf($).check(),_(t,"callback").isFunction().isOptional().check(),_(r,"errorCallback").isFunction().isOptional().check(),"string"==typeof e&&(e=this.getDataService(e)||new $({serviceName:e})),e=$.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(e){return Promise.reject(e)}},e.prototype.trackUnmappedType=function(e,t){_(e,"entityCtor").isFunction().check(),_(t,"interceptor").isFunction().isOptional().check(),new Gt(this)._setCtor(e,t)},e.prototype.registerEntityTypeCtor=function(e,t,r,n){_(e,"structuralTypeName").isString().check(),_(t,"aCtor").isFunction().isOptional().check(),_(r,"initFn").isOptional().isFunction().or().isString().check(),_(n,"noTrackingFn").isOptional().isFunction().check();var i=$t(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 S.isEmpty(this._structuralTypeMap)},e.prototype.getAsEntityType=function(e,t){void 0===t&&(t=!1);var r=this.getStructuralType(e,t);if(r instanceof Gt)return r;if(t)return null;var n=S.formatString("Unable to locate an 'EntityType' by the name: '%1'. Be sure to execute a query or call fetchMetadata first.",e);throw new Error(n)},e.prototype.getAsComplexType=function(e,t){void 0===t&&(t=!1);var r=this.getStructuralType(e,t);if(r instanceof er)return r;if(t)return null;var n=S.formatString("Unable to locate an 'ComplexType' by the name: '%1'. Be sure to execute a query or call fetchMetadata first.",e);throw new Error(n)},e.prototype.getEntityType=function(e,t){return void 0===t&&(t=!1),this.getStructuralType(e,t)},e.prototype.getStructuralType=function(e,t){return void 0===t&&(t=!1),_(e,"typeName").isString().check(),_(t,"okIfNotFound").isBoolean().isOptional().check(!1),this._getStructuralType(e,t)},e.prototype._getStructuralType=function(e,t){void 0===t&&(t=!1);var r=$t(this,e,!1),n=this._structuralTypeMap[r];if(!n){if(t)return null;var i=S.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 S.objectMap(this._incompleteTypeMap,(function(e,t){return t}))},e.prototype.getEntityTypeNameForResourceName=function(e){return _(e,"resourceName").isString().check(),this._resourceEntityTypeMap[e]},e.prototype.setEntityTypeForResourceName=function(e,t){var r;_(e,"resourceName").isString().check(),_(t,"entityTypeOrName").isInstanceOf(Gt).or().isString().check(),r=t instanceof Gt?t.name:$t(this,t,!0),this._resourceEntityTypeMap[e]=r;var n=this._getStructuralType(r,!0);n&&n instanceof Gt&&!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(S.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:pr(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=S.memoize((function(t){return t&&e.parseTypeName(t).typeName})),e}();function Ut(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 zt(e,t,r){t.validators&&(r.validators=t.validators.map(X.fromJSON)),t.dataProperties.forEach((function(e){r._addPropertyCore(tr.fromJSON(e))})),!t.isComplexType&&t.navigationProperties&&t.navigationProperties.forEach((function(e){r._addPropertyCore(rr.fromJSON(e))})),e.addEntityType(r);var n=e._deferredTypes,i=n[r.name];i&&(i.forEach((function(t){zt(e,t.json,t.stype)})),delete n[r.name])}function $t(e,t,r){if(ur(t))return t;var n=e._shortNameMap[t];if(!n&&r)throw new Error("Unable to locate 'entityTypeName' of: "+t);return n}Lt.prototype._$typeName="MetadataStore",B.bubbleEvent(Lt.prototype);var Gt=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=void 0;"MetadataStore"===t._$typeName?(this.metadataStore=t,this.shortName="Anon_"+ ++e.__nextAnonIx,this.namespace="",this.isAnonymous=!0):(r=t,j(t).whereParam("shortName").isNonEmptyString().whereParam("namespace").isString().isOptional().withDefault("").whereParam("baseTypeName").isString().isOptional().whereParam("isAbstract").isBoolean().isOptional().withDefault(!1).whereParam("autoGeneratedKeyType").isEnumOf(ir).isOptional().withDefault(ir.None).whereParam("defaultResourceName").isNonEmptyString().isOptional().withDefault(null).whereParam("dataProperties").isOptional().whereParam("navigationProperties").isOptional().whereParam("serializerFn").isOptional().isFunction().whereParam("custom").isOptional().applyAll(this)),this.name=pr(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&&cr(this,r.dataProperties,tr),r&&r.navigationProperties&&cr(this,r.navigationProperties,rr)}return e.prototype.setProperties=function(e){j(e).whereParam("autoGeneratedKeyType").isEnumOf(ir).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){_(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){_(e,"property").isInstanceOf(tr).or().isInstanceOf(rr).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 rr(e),!0):t._addPropertyCore(new tr(e),!0))}))}return t},e.prototype._updateFromBase=function(e){var t=this;this.baseEntityType=e,this.autoGeneratedKeyType===ir.None&&(this.autoGeneratedKeyType=e.autoGeneratedKeyType),e.dataProperties.forEach((function(e){var r=new tr(e);r.validators=[],r.baseProperty=e,t._addPropertyCore(r)}),this),e.navigationProperties.forEach((function(e){var r=new rr(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 tr?this._addDataProperty(e):(this._addNavigationProperty(e),t&&n&&Yt(e,n)),!n||e.name&&e.nameOnServer||Qt(n.namingConvention,e,"name"),n&&this._extra&&this._extra.alreadyWrappedProps){var i=this._ctor.prototype;z.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,Jt),this.navigationProperties.forEach((function(r){var n,i=e[r.name];if(null!=i){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 Pt(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=this.metadataStore._ctorRegistry,r=t[this.name]||t[this.shortName]||{},n=r.ctor||this._ctor,i=n&&n.prototype&&(n.prototype.entityType||n.prototype.complexType);if(i&&i.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(r.ctor&&e&&(this._extra=void 0),!n){var a=z.interfaceRegistry.modelLibrary.getDefaultInstance().createCtor;n=a?a(this):function(e){if(z.noEval){return function(){}}var t=e.name.replace(/\W/g,"_");return Function("return function "+t+"(){}")()}(this)}return this.initFn=r.initFn,this.noTrackingFn=r.noTrackingFn,n.prototype._$typeName=this.name,this._setCtor(n),n},e.prototype._setCtor=function(e,t){var r=e.prototype;this._extra=this._extra||{},Xt(this,new e),"EntityType"===this._$typeName?r.entityType=this:r.complexType=this,r._$interceptor=t||qt,z.interfaceRegistry.modelLibrary.getDefaultInstance().initializeEntityPrototype(r),this._ctor=e},e.prototype.addValidator=function(e,t){(_(e,"validator").isInstanceOf(X).check(),_(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(S.pluck("name"))},e.prototype.getDataProperty=function(e){return S.arrayFirst(this.dataProperties,S.propEq("name",e))},e.prototype.getNavigationProperty=function(e){return S.arrayFirst(this.navigationProperties,S.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?S.propsEq("name","nameOnServer",e):S.propEq(a,e),n=S.arrayFirst(o.getProperties(),t);if(n)o=n instanceof rr?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 oe.parseRawValue(n,r.dataType)}));return new Ve(this,r)},e.prototype._updateTargetFromRaw=function(e,t,r){this.dataProperties.forEach((function(n){if(n.isSettable){var i=r(t,n);if(void 0!==i){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}));S.arrayEquals(a,u,Wt)||(a.length=0,u.forEach((function(e){a.push(e)})))}else a.length=0}else if(n.isScalar){u=oe.parseRawValue(i,o);e.setProperty(n.name,u)}else if(a=e.getProperty(n.name),Array.isArray(i)){u=i.map((function(e){return oe.parseRawValue(e,o)}));S.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=Pt.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 S.toJson(this,{shortName:null,namespace:null,baseTypeName:null,isAbstract:!1,autoGeneratedKeyType:null,defaultResourceName:null,dataProperties:Zt,navigationProperties:Zt,validators:null,custom:null})},e.prototype._updateNames=function(e){var t=this.metadataStore.namingConvention;Qt(t,e,"name"),e.isNavigationProperty&&(Qt(t,e,"foreignKeyNames"),Qt(t,e,"invForeignKeyNames"))},e.prototype._checkNavProperty=function(e){if(e instanceof rr){if(e.parentType!==this)throw new Error(S.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 rr)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),ur(e.entityTypeName)||(e.entityTypeName=pr(e.entityTypeName,this.namespace))},e.prototype._updateCps=function(){var e=this.metadataStore,t=e._incompleteComplexTypeMap;this.complexProperties.forEach((function(r){r.complexType||Ht(r,e)||S.getArray(t,r.complexTypeName).push(r)})),this.isComplexType&&((t[this.name]||[]).forEach((function(t){Ht(t,e)})),delete t[this.name])},e.prototype._updateNps=function(){var e=this.metadataStore;this.navigationProperties.forEach((function(t){Yt(t,e)}));var t=e._incompleteTypeMap;(t[this.name]||[]).forEach((function(t){Yt(t,e)})),delete t[this.name]},e.__nextAnonIx=0,e.qualifyTypeName=pr,e}();function Jt(e,t){return e.entityAspect||e.complexAspect?e.getProperty(t.name):e[t.name]}function Qt(e,t,r){var n=r+"OnServer",i=t[r];if(i&&i.length){var a=S.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=S.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 Wt(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 Wt(n,i);if(r.isComplexProperty&&!r.isScalar)return S.arrayEquals(n,i,Wt);var a=r.dataType;return n===i||a&&a.normalize&&n&&i&&a.normalize(n)===a.normalize(i)}))}function Zt(e){return e.filter((function(e){return null==e.baseProperty}))}function Ht(e,t){var r=t._getStructuralType(e.complexTypeName,!0);if(!r)return!1;if(!(r instanceof er))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 Yt(e,t){if(e.entityType)return!0;var r=t._getStructuralType(e.entityTypeName,!0);if(r)e.entityType=r,e._resolveNp();else{var n=S.getArray(t._incompleteTypeMap,e.entityTypeName);S.arrayAddItemUnique(n,e)}return!!r}function Xt(e,t){var r=e.getPropertyNames();z.interfaceRegistry.modelLibrary.getDefaultInstance().getTrackablePropertyNames(t).forEach((function(n){if(-1===r.indexOf(n)){var i=t[n];try{"function"==typeof i&&(i=i())}catch(e){}var a=oe.fromValue(i),o=new tr({name:n,dataType:a,isNullable:!0,isUnmapped:!0});o.isSettable=S.isSettable(t,n),e instanceof Gt&&null!=e.subtypes&&e.subtypes.length?e.getSelfAndSubtypes().forEach((function(e){e._addPropertyCore(new tr(o))})):e._addPropertyCore(o)}}))}Gt.prototype._$typeName="EntityType";var er=function(){function e(e){if(this.isComplexType=!0,this.getCtor=Gt.prototype.getCtor,this.createInstance=Gt.prototype.createEntity,this.addValidator=Gt.prototype.addValidator,this.getProperty=Gt.prototype.getProperty,this.getPropertiesOnPath=Gt.prototype.getPropertiesOnPath,this.getPropertyNames=Gt.prototype.getPropertyNames,this._addPropertyCore=Gt.prototype._addPropertyCore,this._addDataProperty=Gt.prototype._addDataProperty,this._updateNames=Gt.prototype._updateNames,this._updateCps=Gt.prototype._updateCps,this._initializeInstance=Gt.prototype._initializeInstance,this._updateTargetFromRaw=Gt.prototype._updateTargetFromRaw,this._setCtor=Gt.prototype._setCtor,arguments.length>1)throw new Error("The ComplexType ctor has a single argument that is a configuration object.");j(e).whereParam("shortName").isNonEmptyString().whereParam("namespace").isString().isOptional().withDefault("").whereParam("dataProperties").isOptional().whereParam("isComplexType").isOptional().isBoolean().whereParam("custom").isOptional().applyAll(this),this.name=pr(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&&cr(this,e.dataProperties,tr)}return e.prototype.setProperties=function(e){j(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 At(r,e,t),r},e.prototype.addProperty=function(e){return _(e,"dataProperty").isInstanceOf(tr).check(),this._addPropertyCore(e)},e.prototype.getProperties=function(){return this.dataProperties},e.prototype.toJSON=function(){return S.toJson(this,{shortName:null,namespace:null,isComplexType:null,dataProperties:null,validators:null,custom:null})},e}();er.prototype._$typeName="ComplexType",er.prototype.createInstance=Gt.prototype.createEntity;var tr=function(){function e(e){if(this.isDataProperty=!0,this.isNavigationProperty=!1,j(e).whereParam("name").isString().isOptional().whereParam("nameOnServer").isString().isOptional().whereParam("dataType").isEnumOf(oe).isOptional().or().isString().or().isInstanceOf(er).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(X).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=oe.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=oe.String);if(null==this.defaultValue)if(this.isNullable)this.defaultValue=null;else if(this.isComplexProperty);else if(this.dataType===oe.Binary)this.defaultValue="AAAAAAAAJ3U=";else{this.defaultValue=this.dataType.defaultValue;var r="A nonnullable DataProperty cannot have a null defaultValue. Name: "+(this.name||this.nameOnServer);if(null===this.defaultValue)throw new Error(r);null==this.defaultValue&&console.warn(r)}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 void 0!==r?r:t.defaultValue},e.getRawValueFromClient=function(e,t){var r=e[t.name];return void 0!==r?r:t.defaultValue},e.prototype.resolveProperty=function(e){for(var t=this[e],r=this.baseProperty;null==t&&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){j(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 S.toJson(this,{name:null,dataType:function(e){return e&&e instanceof oe?e.name:void 0},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=oe.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(X.fromJSON)),new e(t)},e}();tr.prototype._$typeName="DataProperty";var rr=function(){function e(e){if(this.isDataProperty=!1,this.isNavigationProperty=!0,this.formatName=tr.prototype.formatName,this.getAllValidators=tr.prototype.getAllValidators,this.resolveProperty=tr.prototype.resolveProperty,j(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(X).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,j(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 nr(this,"Unable to find inverse property: "+t);(this._inverse||r._inverse)&&nr(this,"It has already been set on one side or the other."),r.entityType!==this.parentType&&nr(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 S.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(X.fromJSON)),new e(t)},e.prototype._resolveNp=function(){var e=this,t=e.entityType,r=S.arrayFirst(t.navigationProperties,(function(t){return t.associationName===e.associationName&&(t.name!==e.name||t.entityTypeName!==e.entityTypeName)}));e._inverse=r||void 0,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=S.arrayFirst(a.navigationProperties,(function(e){return e.invForeignKeyNames&&e.invForeignKeyNames.indexOf(i.name)>=0&&e.entityType===i.parentType})),i.inverseNavigationProperty=r||void 0,S.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){S.arrayAddItemUnique(i,t),t.relatedNavigationProperty=e,S.arrayAddItemUnique(e.entityType.inverseForeignKeyProperties,t),e.relatedDataProperties?S.arrayAddItemUnique(e.relatedDataProperties,t):e.relatedDataProperties=[t]}))}(e)},e}();function nr(e,t){throw new Error("Cannot set the inverse property for: "+e.formatName()+". "+t)}rr.prototype._$typeName="NavigationProperty";var ir=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);ir.prototype._$typeName="AutoGeneratedKeyType",Error.x=ir.resolveSymbols();var ar=T.prototype;function or(e,t){return null!=t&&void 0!==t.entityType}function sr(e,t){return null!=t&&(t.isDataProperty||t.isNavigationProperty)}function ur(e){return e.indexOf(":#")>=0}function pr(e,t){return t&&t.length>0?e+":#"+t:e}function cr(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(S.hasOwnProperty(t,n)){var i=t[n];i.name=n;var a=new r(i);e._addPropertyCore(a)}}}ar.isEntity=function(){return this._addContext({fn:or,msg:" must be an entity"})},ar.isEntityProperty=function(){return this._addContext({fn:sr,msg:" must be either a DataProperty or a NavigationProperty"})};var yr=function(){function e(){this.changeRequestInterceptor=fr,this.jsonResultsAdapter=new J({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=z.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(e){var p="Unable to either parse or import metadata: "+e.message;lr(o,r,"Metadata query failed for: "+i+". "+p)}e.hasMetadataFor(n)||e.addDataService(t),a(s)},error:function(e){lr(o,e,"Metadata query failed for: "+i)}})}))},e.prototype.executeQuery=function(e){var t=this;e.adapter=this;var r=e.query.usePostEnabled?this._makeQueryPostParams(e):this._makeQueryGetParams(e);return new Promise((function(n,i){r.success=function(t){var r=t.data;try{var a=void 0,o=r&&(r.results||r.Results);a=o?{results:o,inlineCount:r.inlineCount||r.InlineCount,httpResponse:t,query:e.query}:{results:r,httpResponse:t,query:e.query},n(a)}catch(e){e instanceof Error?i(e):lr(i,t)}},r.error=function(e){lr(i,e)},t.ajaxImpl.ajax(r)}))},e.prototype._makeQueryGetParams=function(e){var t={type:"GET",url:e.getUrl(),params:e.query.parameters,dataType:"json",crossDomain:!1};return e.dataService.useJsonp&&(t.dataType="jsonp",t.crossDomain=!0),t},e.prototype._makeQueryPostParams=function(e){var t=e.query,r=e.entityManager.metadataStore,n=e.dataService.qualifyUrl(t.resourceName),i=t._getFromEntityType(r,!1);i||(i=new Gt(r));var a=t.toJSONExt({entityType:i,toNameOnServer:!0});return a.from=void 0,a.queryOptions=void 0,{type:"POST",url:n,params:e.query.parameters,dataType:"json",processData:!1,contentType:"application/json; charset=UTF-8",data:JSON.stringify(a),crossDomain:!1}},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)lr(i,r);else{var o=n._prepareSaveResult(e,a);o.httpResponse=r,t(o)}},error:function(t){t.saveContext=e,lr(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=S.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 fr(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 lr(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(e){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:Lt.normalizeTypeName(e.EntityTypeName),keyValues:e.KeyValues,propertyName:e.PropertyName,errorMessage:e.ErrorMessage,custom:e.Custom}}))}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);yr._catchNoConnectionError(n),r&&(n.message=r+"; "+n.message),e(n)}var fr=function(){function e(e,t){}return e.prototype.getRequest=function(e,t,r){return e},e.prototype.done=function(e){},e}(),hr=function(){function e(e){dr(this,e)}return e.prototype.using=function(t){if(!t)return this;var r=new e(this);return dr(r,t),r},e.prototype.setAsDefault=function(){return S.setAsDefault(this,e)},e.defaultInstance=new e({validateOnAttach:!0,validateOnSave:!0,validateOnQuery:!1,validateOnPropertyChange:!0}),e}();function dr(e,t){return t&&j(t).whereParam("validateOnAttach").isBoolean().isOptional().whereParam("validateOnSave").isBoolean().isOptional().whereParam("validateOnQuery").isBoolean().isOptional().whereParam("validateOnPropertyChange").isBoolean().isOptional().applyAll(e),e}hr.prototype._$typeName="ValidationOptions";var mr=function(){function e(t){e._updateWithConfig(this,t)}return e.prototype.setAsDefault=function(){return S.setAsDefault(this,e)},e.prototype.using=function(t){return e._updateWithConfig(this,t)},e._updateWithConfig=function(e,t){return t&&j(t).whereParam("resourceName").isOptional().isString().whereParam("dataService").isOptional().isInstanceOf($).whereParam("allowConcurrentSaves").isBoolean().isOptional().whereParam("tag").isOptional().applyAll(e),e},e.defaultInstance=new e({allowConcurrentSaves:!1}),e}();mr.prototype._$typeName="SaveOptions";var gr=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)),void 0===n){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 Ve(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&&void 0!==n.keyMap[e.values[0].toString()]},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}();z.registerType(gr,"KeyGenerator");var vr=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===Re.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===Re.OverwriteChanges||r===Re.PreserveChanges&&s){var u=this.entityManager.helper.unwrapInstance(e);this.entityType._updateTargetFromRaw(o,u,tr.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(void 0===r)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 Ve?e._keyInGroup:Ve.createKeyString(e);var r=this._indexMap[t],n=void 0!==r?this._entities[r]:void 0;return null==n?void 0:n},e.prototype.hasChanges=function(){for(var e=this._entities,t=ke.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=ke.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(void 0===r)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 wr=function(){function e(e){this.rawValueFn=tr.getRawValueFromServer,S.extend(this,e,["query","entityManager","dataService","mergeOptions"]),this.refMap={},this.deferredFns=[],this.jsonResultsAdapter=this.dataService.jsonResultsAdapter,this.metadataStore=this.entityManager.metadataStore,this.rawValueFn=tr.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 yt))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,a=S.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 yt&&r._getToEntityType&&r._getToEntityType(i.metadataStore)),Er(i,e,a)}),this.mergeOptions.includeDeleted);return a.filter&&!this.mergeOptions.includeDeleted&&(a=a.filter((function(e){return e&&(!e.entityAspect||!e.entityAspect.entityState.isDeleted())}))),a},e.prototype.processDeferred=function(){this.deferredFns.length>0&&this.deferredFns.forEach((function(e){e()}))},e}();function Er(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 void 0===r?function(){return e.refMap[t]}:r}(e,r.nodeRefId);return"function"==typeof i&&null!=n?void e.deferredFns.push((function(){n(i)})):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.getEntityByKey(s);if(u){if(o&&u.entityAspect.entityState.isDeleted())return n.detachEntity(u),u;var p=u.entityAspect.entityState;if(a===Re.Disallowed)throw new Error("A MergeStrategy of 'Disallowed' prevents "+s.toString()+" from being merged");if(a===Re.SkipMerge)Nr(e,u,t);else if(a===Re.OverwriteChanges||p.isUnchanged()){Or(e,u,t),u.entityAspect.wasLoaded=!0,r.extraMetadata&&(u.entityAspect.extraMetadata=r.extraMetadata),u.entityAspect.entityState=ke.Unchanged,_r(u),u.entityAspect.propertyChanged.publish({entity:u,propertyName:null});var c=o?Ie.MergeOnSave:Ie.MergeOnQuery;n.entityChanged.publish({entityAction:c,entity:u}),p.isUnchanged()||n._notifyStateChange(u,!1)}else if(Nr(e,u,t),p===ke.Deleted&&!e.mergeOptions.includeDeleted)return null}else u=i._createInstanceCore(),Or(e,u,t),r.extraMetadata&&(u.entityAspect.extraMetadata=r.extraMetadata),n._attachEntityCore(u,ke.Unchanged,a),u.entityAspect.wasLoaded=!0,n.entityChanged.publish({entityAction:Ie.AttachOnQuery,entity:u});return u}(e,t,r)}return r.passThru||"object"!=typeof t||S.isDate(t)||(t=function(e,t){var r=e.metadataStore.namingConvention.serverPropertyNameToClient,n={};return S.objectForEach(t,(function(t,i){var a=r(t);Sr(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]=S.map(r[t.nameOnServer],(function(r){return Pr(e,t.dataType,r)})):n[t.name]=oe.parseRawValue(r[t.nameOnServer],t.dataType)})),t instanceof Gt&&t.navigationProperties.forEach((function(t){var i={nodeType:"navProp",navigationProperty:t};Sr(r[t.nameOnServer],e,i,n,t.name)})),n}function Sr(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,Er(t,e,o,(function(e){n[i][s]=e()}))}))):n[i]=Er(t,e,o,(function(e){n[i]=e()})))}function Tr(e,t,r){var n=r._$meta.nodeId;!n&&r._$meta.extraMetadata&&(n=r._$meta.extraMetadata.uriKey),null!=n&&(e.refMap[n]=t)}function _r(e){(e.entityAspect||e.complexAspect).originalValues={},(e.entityType||e.complexType).complexProperties.forEach((function(t){var r=e.getProperty(t.name);t.isScalar?_r(r):(r._acceptChanges(),r.forEach(_r))}))}function Nr(e,t,r){Tr(e,t,r),r.entityType.navigationProperties.forEach((function(t){t.isScalar?Ar(e,r,t):br(e,r,t)}))}function Or(e,t,r){Tr(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=Ar(e,n,t);if(null==i)return;"function"==typeof i?e.deferredFns.push((function(){Cr(i=i(),r,t)})):Cr(i,r,t)}(e,n,t,r):function(e,t,r,n){var i=br(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(),xr(e,t,o,r,a)})):xr(e,t,o,r,a)}))}(e,n,t,r)}))}function Ar(e,t,r){var n=t[r.nameOnServer];return n?e.visitAndMerge(n,{nodeType:"navProp",navigationProperty:r}):null}function br(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 Cr(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 xr(e,t,r,n,i){if(t){if(t.entityAspect.entityState===ke.Modified&&e.mergeOptions.mergeStrategy===Re.PreserveChanges){var a=t.entityAspect.originalValues;if(i.relatedDataProperties.some((function(e){return null!=a[e.name]})))return}t.getProperty(i.name)!==n&&(r.push(t),t.setProperty(i.name,n))}}wr.prototype._$typeName="MappingContext";var Fr=function(){function e(){this.map={}}return e.prototype.addChild=function(e,t,r){var n=this.getTuple(e,t);n||(n={navigationProperty:t,children:[]},S.getArray(this.map,e.toString()).push(n)),n.children.push(r)},e.prototype.removeChildren=function(e,t){var r=this.map[e];r&&(S.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?S.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:void 0},e.prototype.getTuplesByString=function(e){return this.map[e]},e}(),Dr=function(){function e(t){if(this.helper={unwrapInstance:$r,unwrapOriginalValues:Gr,unwrapChangedValues:Jr},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 B("entityChanged",this),this.validationErrorsChanged=new B("validationErrorsChanged",this),this.hasChangesChanged=new B("hasChangesChanged",this),this.clear()}return e.prototype.setProperties=function(t){e._updateWithConfig(this,t,!1)},e._updateWithConfig=function(e,t,r){var n=r?je.defaultInstance:e.queryOptions,i=r?mr.defaultInstance:e.saveOptions,a=r?hr.defaultInstance:e.validationOptions,o=j(t).whereParam("serviceName").isOptional().isString().whereParam("dataService").isOptional().isInstanceOf($).whereParam("queryOptions").isInstanceOf(je).isOptional().withDefault(n).whereParam("saveOptions").isInstanceOf(mr).isOptional().withDefault(i).whereParam("validationOptions").isInstanceOf(hr).isOptional().withDefault(a).whereParam("keyGeneratorCtor").isFunction().isOptional();r&&(o=o.whereParam("metadataStore").isInstanceOf(Lt).isOptional().withDefault(new Lt)),o.applyAll(e),S.updateWithDefaults(e.queryOptions,n),S.updateWithDefaults(e.saveOptions,i),S.updateWithDefaults(e.validationOptions,a),t.serviceName&&(e.dataService=new $({serviceName:e.serviceName})),e.serviceName=e.dataService&&e.dataService.serviceName,e.keyGeneratorCtor=e.keyGeneratorCtor||gr,(r||t.keyGeneratorCtor)&&(e.keyGenerator=new e.keyGeneratorCtor)},e.prototype.createEntity=function(e,t,r,n){_(e,"entityType").isString().or().isInstanceOf(Gt).check(),_(r,"entityState").isEnumOf(ke).isOptional().check(),_(n,"mergeStrategy").isEnumOf(Re).isOptional().check();var i="string"==typeof e?this.metadataStore._getStructuralType(e):e;r=r||ke.Added;var a={};return S.using(this,"isLoading",!0,(function(){a=i.createEntity(t)})),r!==ke.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){_(e,"entities").isArray().isEntity().or().isNonEmptyArray().isInstanceOf(Gt).or().isNonEmptyArray().isString().or().isOptional().check(),null==t?t={includeMetadata:!0,asString:!0}:"boolean"==typeof t&&(t={includeMetadata:t,asString:!0}),j(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){t.forEach((function(e){if(e.entityAspect.entityState===ke.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 i=kr(e,t);null!=i&&i.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 a=[],o={};return S.objectForEach(r,(function(e,t){o[e]=function(e,t){var r={},n=e.entityType,i=n.dataProperties,a=Hr(n),o=[];return e._entities.forEach((function(e){if(e){var r=function e(t,r,n,i){var a={};if(r.forEach((function(r){var i=r.name,o=t.getProperty(i);if(null!=o||null!=r.defaultValue){if(o&&r.isComplexProperty){var s=r.dataType.dataProperties;o=S.map(o,(function(t){return e(t,s,n)}))}else o=n?n(r,o):o,r.isUnmapped&&(o=S.toJSONSafe(o,S.toJSONSafeReplacer));void 0!==o&&(a[i]=o)}})),Pt.isEntity(t)){var o=(u=t.entityAspect).entityState,s={tempNavPropNames:Kr(u,i||[]),entityState:o.name};u.extraMetadata&&(s.extraMetadata=u.extraMetadata),(o.isModified()||o.isDeleted())&&(s.originalValuesMap=u.originalValues),a.entityAspect=s}else{var u=t.complexAspect;s={};u.originalValues&&!S.isEmpty(u.originalValues)&&(s.originalValuesMap=u.originalValues),a.complexAspect=s}return a}(e,i,a,t);o.push(r)}})),r.entities=o,r}(t,a)})),{entityGroupMap:o,tempKeys:a}}(this,e),n=S.extend({},r,["tempKeys","entityGroupMap"]);return t.includeMetadata?(n=S.extend(n,this,["dataService","saveOptions","queryOptions","validationOptions"])).metadataStore=this.metadataStore.exportMetadata():(n.metadataVersion=Lt.metadataVersion,n.metadataStoreName=this.metadataStore.name),t.asString?JSON.stringify(n,null,z.stringifyPad):n},e.prototype.importEntities=function(e,t){var r=this;j(t=t||{}).whereParam("mergeStrategy").isEnumOf(Re).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&&$.fromJSON(n.dataService)||new $({serviceName:n.serviceName}),this.saveOptions=new mr(n.saveOptions),this.queryOptions=je.fromJSON(n.queryOptions),this.validationOptions=new hr(n.validationOptions)):t.metadataVersionFn&&t.metadataVersionFn({metadataVersion:n.metadataVersion,metadataStoreName:n.metadataStoreName});var i={};n.tempKeys.forEach((function(e){var t=Ve.fromJSON(e,r.metadataStore);i[t.toString()]=new Ve(t.entityType,r.keyGenerator.generateTempKeyValue(t.entityType,t.values[0]))}));var a=[],o=t;return o.tempKeyMap=i,S.wrapExecution((function(){r._pendingPubs=[]}),(function(e){r._pendingPubs.forEach((function(e){return e()})),r._pendingPubs=void 0,r._hasChangesAction&&r._hasChangesAction()}),(function(){S.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=tr.getRawValueFromClient;return t.entities.forEach((function(t){var r=t.entityAspect,l=o.getEntityKeyFromRawEntity(t,y),f=ke.fromName(r.entityState);if(!f||f===ke.Detached)throw new Error("Only entities with a non detached entity state may be imported.");var h=!a&&f.isAdded()&&jr(i,l);if(n=h?void 0:e.findEntityByKey(l))if(s===Re.SkipMerge);else{if(s===Re.Disallowed)throw new Error("A MergeStrategy of 'Disallowed' prevents "+l.toString()+" from being merged");var d=n.entityAspect.entityState.isUnchanged();(s===Re.OverwriteChanges||d)&&(o._updateTargetFromRaw(n,t,y),n.entityAspect.setEntityState(f),p.publish({entityAction:Ie.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 Ve(t.entityType,[a]),u=jr(i,s);n.setProperty(r,u.values[0])}))),n=e.attachEntity(n,f),p.publish({entityAction:Ie.AttachOnImport,entity:n}),f.isUnchanged()||u._notifyStateChange(n,!0);c.push(n)})),c}(zr(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(){S.objectMap(this._entityGroupMap,(function(e,t){return t._checkOperation("clear")})).forEach((function(e){e._clear()})),this._entityGroupMap={},this._unattachedChildrenMap=new Fr,this.keyGenerator=new this.keyGeneratorCtor,this.entityChanged.publish({entityAction:Ie.Clear}),this._setHasChanges(!1)},e.prototype.createEmptyCopy=function(){return new e(S.extend({},this,["dataService","metadataStore","queryOptions","saveOptions","validationOptions","keyGeneratorCtor"]))},e.prototype.addEntity=function(e){return this.attachEntity(e,ke.Added)},e.prototype.attachEntity=function(e,t,r){var n=this;_(e,"entity").isRequired().check(),this.metadataStore._checkEntityType(e);var i=_(t,"entityState").isEnumOf(ke).isOptional().check(ke.Unchanged),a=_(r,"mergeStrategy").isEnumOf(Re).isOptional().check(Re.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 Pt(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 S.using(this,"isLoading",!0,(function(){i.isAdded()&&function(e,t){var r=t.entityAspect.getKey(),n=S.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!==ir.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=void 0}})),this.validationOptions.validateOnAttach&&u.entityAspect.validateEntity(),i.isUnchanged()||this._notifyStateChange(u,!0),this.entityChanged.publish({entityAction:Ie.Attach,entity:u}),u},e.prototype.detachEntity=function(e){_(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=void 0):(_(e,"dataService").isInstanceOf($).isOptional().check(),_(t,"callback").isFunction().isOptional().check(),_(r,"errorCallback").isFunction().isOptional().check()),qr(this.metadataStore.fetchMetadata(e||this.dataService),t,r)},e.prototype.executeQuery=function(e,t,r){var n=this;_(e,"query").isInstanceOf(yt).or().isString().check(),_(t,"callback").isFunction().isOptional().check(),_(r,"errorCallback").isFunction().isOptional().check();var i=je.resolve([e.queryOptions,this.queryOptions,je.defaultInstance]),a=$.resolve([e.dataService,this.dataService]);return qr(!a.hasServerMetadata||this.metadataStore.hasMetadataFor(a.serviceName)?Ur(this,e,i,a):this.fetchMetadata(a).then((function(){return Ur(n,e,i,a)})),t,r)},e.prototype.executeQueryLocally=function(e){return Wr(this,e).results},e.prototype.saveChanges=function(e,t,r,n){_(e,"entities").isOptional().isArray().isEntity().check(),_(t,"saveOptions").isInstanceOf(mr).isOptional().check(),_(r,"callback").isFunction().isOptional().check(),_(n,"errorCallback").isFunction().isOptional().check(),t=t||this.saveOptions||mr.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||void 0);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;S.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=$.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 Br(i,n),S.using(i,"isLoading",!0,(function(){var e=new wr({query:void 0,entityManager:i,mergeOptions:{mergeStrategy:Re.OverwriteChanges},dataService:u});t=e.visitAndMerge(t,{nodeType:"root"})})),r.forEach((function(e){var t=i.metadataStore._getStructuralType(e.entityTypeName),r=new Ve(t,e.keyValues),n=i.getEntityByKey(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===oe.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;Rr(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){Rr(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 Ve(t,e.keyValues);r=n.getEntityByKey(a)}if(t&&r){var o=e.propertyName?{propertyName:e.propertyName,property:t.getProperty(e.propertyName)}:{},s=ie.getKey(e.errorName||e.errorMessage,e.propertyName),u=new ie(null,o,e.errorMessage,s);u.isServerError=!0,r.entityAspect.addValidationError(u)}return S.extend({entity:r,isServerError:!0},e,["errorName","errorMessage","propertyName","custom"])}));return t.entityErrors=a,t}(p,e);n&&n(t);return Promise.reject(t)}))}catch(o){return Rr(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){S.objectForEach(e.entityAspect._validationErrors,(function(t,r){var i=S.extend({entity:e,errorName:r.validator.name},r,["errorMessage","propertyName","isServerError","custom"]);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=Vr(this,t).entityKey,a=i._subtypes||[i.entityType];return a.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=$.resolve([this.dataService]);return!n.hasServerMetadata||this.metadataStore.hasMetadataFor(n.serviceName)?Mr(this,t):this.fetchMetadata(n).then((function(){return Mr(e,t)}))},e.prototype.findEntityByKey=function(e){return this.getEntityByKey(e)},e.prototype.generateTempKeyValue=function(e){_(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&&(void 0===e?this._hasChanges:this._hasChangesCore(e))},e.prototype._hasChangesCore=function(e){return Lr(this,kr(this,e)).some((function(e){return e&&e.hasChanges()}))},e.prototype.getChanges=function(e){return Ir(this,kr(this,e))},e.prototype.rejectChanges=function(){if(!this._hasChanges)return[];var e=Ir(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=kr(this,e);return _(t,"entityStates").isOptional().isEnumOf(ke).or().isNonEmptyArray().isEnumOf(ke).check(),function(e,t,r){var n=Lr(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=S.toArray(t);return r.forEach((function(e){if(!(e instanceof ke))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:Ie.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=void 0},e.prototype._linkRelatedEntities=function(e){var t=this,r=e.entityAspect;S.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!==ke.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;if(i.invForeignKeyNames.length){var o=new yt(a.entityType.defaultResourceName).where(i.invForeignKeyNames[0],"eq",a.values[0]);if(1===(p=t.executeQueryLocally(o)).length){var s=p[0];e.setProperty(i.name,s)}}else{var u=t.getEntityByKey(a);u?e.setProperty(i.name,u):n.addChild(a,i,e)}}else if(i.inverse&&i.inverse.invForeignKeyNames.length){var p,c=e.getProperty(i.inverse.invForeignKeyNames[0]);o=new yt(i.entityType.defaultResourceName).where(i.invForeignKeyNames[0],"eq",c);(p=t.executeQueryLocally(o)).forEach((function(t){t.setProperty(i.inverse.name,e)}))}})),e.entityType.foreignKeyProperties.forEach((function(r){var i=r.inverseNavigationProperty;if(i){var a=e.getProperty(r.name),o=new Ve(i.parentType,[a]),s=t.getEntityByKey(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=zr(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 Mr(e,t){var r=Vr(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!==Re.OverwriteChanges)),o?Promise.resolve({entity:a||void 0,entityKey:n,fromCache:!0}):yt.fromEntityKey(n).using(e).execute().then((function(e){return a=0===e.results.length?null:e.results[0],Promise.resolve({entity:a||void 0,entityKey:n,fromCache:!1})}))}function kr(e,t){return _(t,"entityTypes").isString().isOptional().or().isNonEmptyArray().isString().or().isInstanceOf(Gt).or().isNonEmptyArray().isInstanceOf(Gt).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 Ir(e,t){var r=Lr(e,t),n=[];return r.forEach((function(e){if(e){var t=e.getChanges();n=n&&n.length?n.concat(t):t}})),n}function Vr(e,t){try{if(t[0]instanceof Ve)return{entityKey:t[0],remainingArgs:S.arraySlice(t,1)};if(t.length>=2){var r="string"==typeof t[0]?e.metadataStore._getStructuralType(t[0],!1):t[0];return{entityKey:new Ve(r,t[1]),remainingArgs:S.arraySlice(t,2)}}}catch(e){}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 Rr(e,t){e.forEach((function(e){e.entityAspect.isBeingSaved=t}))}function Kr(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 jr(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 qr(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 Br(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}function Lr(e,t){var r=e._entityGroupMap;return t?S.toArray(t).map((function(e){if(e instanceof Gt)return r[e.name];throw new Error("The EntityManager.getChanges() 'entityTypes' parameter must be either an entityType or an array of entityTypes or null")})):S.getOwnPropertyValues(r)}function Ur(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===Ke.FromLocalCache)try{if("string"==typeof t)throw new Error("cannot execute 'string' EntityQuery locally.");var a=Wr(e,t);return Promise.resolve({results:a.results,entityManager:e,inlineCount:a.inlineCount,query:t})}catch(e){return Promise.reject(e)}var o=new wr({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=S.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=void 0,e._hasChangesAction&&e._hasChangesAction(),o=void 0,t.error)return Promise.reject(t.error)}),(function(){var a=n.jsonResultsAdapter.extractResults(r);a=S.toArray(a),i=o.visitAndMerge(a,{nodeType:"root"}),s&&i.forEach((function(e){e.entityAspect&&e.entityAspect.validateEntity()})),o.processDeferred(),t instanceof yt&&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 e(t,r){var n=r[0];t.forEach((function(t){var i=t.entityAspect;if(i&&(i._markAsLoaded(n),1!==r.length)){var a=t.getProperty(n);a&&(a.arrayChanged||(a=[a]),e(a,r.slice(1)))}}))}(e,r)}))}(i,t);var u=S.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(e){return e&&(e.query=t),Promise.reject(e)}}function zr(e,t){var r=e._entityGroupMap[t.name];return r||(r=new vr(e,t),e._entityGroupMap[t.name]=r),r}function $r(e,t){var r={},n=Pt.isEntity(e)?e.entityType:e.complexType,i=Hr(n),a={};return n.dataProperties.forEach((function(n){if(n.isComplexProperty)r[n.nameOnServer]=S.map(e.getProperty(n.name),(function(e){return $r(e,t)}));else{var o=e.getProperty(n.name);if(void 0===(o=t?t(n,o):o))return;void 0!==(o=i?i(n,o):o)&&(n.isUnmapped?a[n.nameOnServer]=S.toJSONSafe(o,S.toJSONSafeReplacer):r[n.nameOnServer]=o)}})),S.isEmpty(a)||(r.__unmapped=a),r}function Gr(e,t,r){var n=Pt.isEntity(e)?e.entityType:e.complexType,i=Pt.isEntity(e)?e.entityAspect:e.complexAspect,a=t.namingConvention.clientPropertyNameToServer,o={};return S.objectForEach(i.originalValues,(function(e,t){var i=n.getProperty(e);void 0!==(t=r?r(i,t):t)&&(o[a(e,i)]=t)})),n.complexProperties.forEach((function(n){var i=e.getProperty(n.name);if(n.isScalar){var s=Gr(i,t,r);S.isEmpty(s)||(o[a(n.name,n)]=s)}else{var u=i.map((function(e){return Gr(e,t,r)}));o[a(n.name,n)]=u}})),o}function Jr(e,t,r){var n=e.entityType,i=Hr(n),a=t.namingConvention.clientPropertyNameToServer,o={};return S.objectForEach(e.entityAspect.originalValues,(function(t,s){var u=n.getProperty(t),p=e.getProperty(t);void 0!==(p=r?r(u,p):p)&&void 0!==(p=i?i(u,p):p)&&(o[a(t,u)]=p)})),n.complexProperties.forEach((function(t){if(Qr(e,t)){var n=e.getProperty(t.name);o[a(t.name,t)]=S.map(n,(function(e){return $r(e,r)}))}})),o}function Qr(e,t){var r=e.getProperty(t.name);return t.isScalar?Zr(r):!!r._origValues||r.some((function(e){return Zr(e)}))}function Wr(e,t){_(t,"query").isInstanceOf(yt).check();var r=e.metadataStore,n=t._getFromEntityType(r,!0),i=function(e,t){return t.getSelfAndSubtypes().map((function(t){return zr(e,t)}))}(e,n),a=t.wherePredicate&&t.wherePredicate.toFunction({entityType:n}),o=!0===je.resolve([t.queryOptions,e.queryOptions,je.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:void 0,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 Zr(e){return!S.isEmpty(e.complexAspect.originalValues)||e.complexType.complexProperties.some((function(t){return Qr(e,t)}))}function Hr(e){return e.serializerFn||e.metadataStore&&e.metadataStore.serializerFn}Dr.prototype._$typeName="EntityManager",B.bubbleEvent(Dr.prototype);var Yr=function(){this.ajax=new L("ajax"),this.modelLibrary=new L("modelLibrary"),this.dataService=new L("dataService"),this.uriBuilder=new L("uriBuilder")};z.interfaceRegistry=new Yr,z._interfaceRegistry=z.interfaceRegistry,z.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},z.initializeAdapterInstances=function(e){return j(e).whereParam("dataService").isOptional().whereParam("modelLibrary").isOptional().whereParam("ajax").isOptional().whereParam("uriBuilder").isOptional().applyAll(this,!1),S.objectMap(z,this.initializeAdapterInstance)};function Xr(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 en(e,t){e._processAdds(t),Xr(e,"arrayChanged",{array:e,added:t})}function tn(e,t){e._processRemoves(t),Xr(e,"arrayChanged",{array:e,removed:t})}var rn={mixin:{push:function(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];if(this._inProgress)return-1;var r,n=this._getGoodAdds(e);if(!n.length)return this.length;this._beforeChange();var i=Object.getPrototypeOf(this);return r=i.push?i.push.apply(this,n):Array.prototype.push.apply(this,n),en(this,n),r},_push:function(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];if(this._inProgress)return-1;var r,n=e;this._beforeChange();var i=Object.getPrototypeOf(this);return r=i.push?i.push.apply(this,n):Array.prototype.push.apply(this,n),en(this,n),r},unshift:function(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];var r,n=this._getGoodAdds(e);if(!n.length)return this.length;this._beforeChange();var i=Object.getPrototypeOf(this);return r=i.unshift?i.unshift.apply(this,n):Array.prototype.unshift.apply(this,n),en(this,n),r},pop:function(){var e;this._beforeChange();var t=Object.getPrototypeOf(this);return tn(this,[e=t.pop?t.pop.apply(this):Array.prototype.pop.apply(this)]),e},shift:function(){var e;this._beforeChange();var t=Object.getPrototypeOf(this);return tn(this,[e=t.shift?t.shift.apply(this):Array.prototype.shift.apply(this)]),e},splice:function(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];var r,n=this._getGoodAdds(S.arraySlice(e,2)),i=S.arraySlice(e,0,2).concat(n);this._beforeChange();var a=Object.getPrototypeOf(this);return tn(this,r=a.splice?a.splice.apply(this,i):Array.prototype.splice.apply(this,i)),n.length&&en(this,n),r},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:Xr,initializeParent:function(e,t,r){e.parent=t,e.parentProperty=r}},nn={load:function(e,t){var r=this.parentEntity,n=yt.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){return!(e._addsInProcess.indexOf(t)>=0)&&t.getProperty(a.name)!==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;return n.getProperty(i)!==t.getProperty(e)}))}))}return r}(e,t);if(!r.length)return r;var n=e.parentEntity.entityAspect.entityManager;n&&!n.isLoading&&r.forEach((function(t){if(t.entityAspect.entityState.isDetached()){e._inProgress=!0;try{n.attachEntity(t,ke.Added)}finally{e._inProgress=!1}}}));return 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 an(e,t,r){var n=e;return n.parentEntity=t,n.navigationProperty=r,n.arrayChanged=new B("arrayChanged",n),n._addsInProcess=[],S.extend(n,rn.mixin),S.extend(n,nn)}var on={_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(){rn.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){sn(t,e)}))}(this,e)},_rejectChanges:function(){if(this._origValues){var e=this;this.forEach((function(t){sn(t,e)})),this.length=0,this._origValues.forEach((function(t){e.push(t)}))}},_acceptChanges:function(){this._origValues=null}};function sn(e,t){var r=e.complexAspect;return r.parent!==t.parent?null:(r.parent=void 0,r.parentProperty=void 0,r)}function un(e,t,r){var n=e;return rn.initializeParent(n,t,r),n.arrayChanged=new B("arrayChanged",n),S.extend(n,rn.mixin),S.extend(n,on)}var pn={_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 cn(e,t,r){var n=e;return rn.initializeParent(n,t,r),n.arrayChanged=new B("arrayChanged",n),S.extend(n,rn.mixin),S.extend(n,pn)}var yn,ln={AbstractDataServiceAdapter:yr,assertConfig:null,assertParam:null,AutoGeneratedKeyType:ir,BooleanQueryOp:mt,ComplexAspect:At,ComplexType:er,config:z,core:S,DataProperty:tr,DataService:$,DataType:oe,EntityAction:Ie,EntityAspect:Pt,EntityKey:Ve,EntityManager:Dr,EntityQuery:yt,EntityState:ke,EntityType:Gt,Event:B,FetchStrategy:Ke,FilterQueryOp:dt,InterfaceRegistry:Yr,JsonResultsAdapter:J,KeyGenerator:gr,LocalQueryComparisonOptions:jt,makeComplexArray:un,makePrimitiveArray:cn,makeRelationArray:an,MergeStrategy:Re,MetadataStore:Lt,NamingConvention:Ct,NavigationProperty:rr,OrderByClause:gt,Param:T,Predicate:qe,QueryOptions:je,SaveOptions:mr,ValidationError:ie,ValidationOptions:hr,Validator:X,version:"2.1.5"};try{yn=window||(global?global.window:void 0)}catch(e){}yn&&(yn.breeze=ln),e.AbstractDataServiceAdapter=yr,e.AndOrPredicate=Qe,e.AnyAllPredicate=We,e.AutoGeneratedKeyType=ir,e.BinaryPredicate=Je,e.BreezeConfig=U,e.BreezeEnum=a,e.BreezeEvent=B,e.ComplexAspect=At,e.ComplexType=er,e.DataProperty=tr,e.DataService=$,e.DataType=oe,e.EntityAction=Ie,e.EntityAspect=Pt,e.EntityKey=Ve,e.EntityManager=Dr,e.EntityQuery=yt,e.EntityState=ke,e.EntityType=Gt,e.ExpandClause=Et,e.FetchStrategy=Ke,e.FilterQueryOp=dt,e.FnExpr=Xe,e.InterfaceRegistry=Yr,e.JsonResultsAdapter=J,e.KeyGenerator=gr,e.LitExpr=He,e.LocalQueryComparisonOptions=jt,e.MappingContext=wr,e.MergeStrategy=Re,e.MetadataStore=Lt,e.NamingConvention=Ct,e.NavigationProperty=rr,e.OrderByClause=gt,e.Predicate=qe,e.PropExpr=Ye,e.QueryOptions=je,e.SaveOptions=mr,e.SelectClause=wt,e.UnaryPredicate=Ge,e.ValidationError=ie,e.ValidationOptions=hr,e.Validator=X,e.assertConfig=j,e.assertParam=_,e.breeze=ln,e.config=z,e.core=S,e.makeComplexArray=un,e.makePrimitiveArray=cn,e.makeRelationArray=an,e.ɵa=Ze,e.ɵb=T,e.ɵc=pr,e.ɵd=mt,Object.defineProperty(e,"__esModule",{value:!0})}));
|
|
16
16
|
//# sourceMappingURL=breeze-client.umd.min.js.map
|