pailingual-odata
Version:
TypeScript client for OData v4 services
1 lines • 28.7 kB
JavaScript
!function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e():"function"==typeof define&&define.amd?define([],e):"object"==typeof exports?exports["pailingual-odata"]=e():t["pailingual-odata"]=e()}(window,function(){return function(t){var e={};function n(r){if(e[r])return e[r].exports;var a=e[r]={i:r,l:!1,exports:{}};return t[r].call(a.exports,a,a.exports,n),a.l=!0,a.exports}return n.m=t,n.c=e,n.d=function(t,e,r){n.o(t,e)||Object.defineProperty(t,e,{enumerable:!0,get:r})},n.r=function(t){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})},n.t=function(t,e){if(1&e&&(t=n(t)),8&e)return t;if(4&e&&"object"==typeof t&&t&&t.__esModule)return t;var r=Object.create(null);if(n.r(r),Object.defineProperty(r,"default",{enumerable:!0,value:t}),2&e&&"string"!=typeof t)for(var a in t)n.d(r,a,function(e){return t[e]}.bind(null,a));return r},n.n=function(t){var e=t&&t.__esModule?function(){return t.default}:function(){return t};return n.d(e,"a",e),e},n.o=function(t,e){return Object.prototype.hasOwnProperty.call(t,e)},n.p="",n(n.s=0)}([function(t,e,n){"use strict";n.r(e);var r={};n.r(r),n.d(r,"addFormatter",function(){return s}),n.d(r,"getFormatter",function(){return p}),n.d(r,"serializeValue",function(){return c});var a={};n.r(a),n.d(a,"EdmTypes",function(){return D}),n.d(a,"EdmEntityType",function(){return U}),n.d(a,"EdmComplexType",function(){return R}),n.d(a,"EdmEnumType",function(){return L}),n.d(a,"EdmEntityTypeReference",function(){return V}),n.d(a,"EdmTypeReference",function(){return G}),n.d(a,"OperationMetadata",function(){return X}),n.d(a,"Namespace",function(){return W}),n.d(a,"loadMetadata",function(){return Q}),n.d(a,"ApiMetadata",function(){return Y});var o=/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i,i={"Edm.String":{toEdm:function(t,e){return e?"'"+t.toString().replace("'","''").replace("/","%2F")+"'":t}},"Edm.Guid":{toEdm:function(t){if(t.match(o))return t;throw new Error("Value '"+t+"' not parsed as Guid")}},"Edm.DateTimeOffset":{toEdm:function(t){return t.toISOString()},fromEdm:function(t){return new Date(t)}},"Edm.Boolean":{toEdm:function(t){return t?"true":"false"}}},u={};function s(t){if(!(t&&t.contentType&&t.serialize&&t.deserialize))throw new Error("All formatter properties is required");u[t.contentType]=t}function p(t){var e=u[t];if(!e)throw new Error("Not supported format: "+t);return e}function c(t,e,n,r){return null==t?n?"null":null:f(t,e,n,r)||t.toString()}function f(t,e,n,r){if(void 0===r&&(r={}),null==t)return null;if(e instanceof L){var a=function(t,e){for(var n in t.members)if(t.members[n]===e)return n}(e,t);if(a)return n&&(a="'"+a+"'",r.enumPrefixFree||(a=e.getFullName()+a)),a;throw new Error("Value '"+t+"' not found in enum '"+e.name+" '")}var o=i[e];return o&&o.toEdm?o.toEdm(t,n,r):null}s({contentType:"application/json",serialize:function(t,e,n){void 0===n&&(n={});var r=new _;r.set(t,e);var a=new U("$$~~openType~~$$",{});return a.openType=!0,JSON.stringify(t,function(t,e){if(!t||Array.isArray(this))return e;var n=r.get(this);if(null!=n){var o=n.properties[t]||n.navProperties[t],i=o&&o.type||(n.openType?a:void 0);if(!i)throw new Error("Property '"+t+"' not found in metadata");if(i instanceof U){if(Array.isArray(e))for(var u=0,s=e;u<s.length;u++){var p=s[u];r.set(p,i)}else null!=e&&r.set(e,i);return e}return f(this[t],o.type,!1)||e}throw new Error("Metadata for object not found")})},deserialize:function(t,e,n){var r=JSON.parse(t),a=r[l];if(a){a=a.split("#")[1];var o=r[y],i=k(a,"$entity"),u=function(t,e){C(t,"Collection")&&(t=t.substring("Collection".length+1,t.length-1));var n=t.indexOf("(");n>-1&&(t=t.substring(0,n));var r=t.split("/");t=r[r.length-1];var a=e.entitySets[t];if(!a){var o=t.lastIndexOf(".");if(o>-1){var i=t.substr(0,o),u=t.substr(o+1);if("Edm"==i)return t;var s=e.namespaces[i];if(s&&s.types[u])return s.types[u]}}return a}(a=a.replace(/\/\$entity$/,""),e);if(!i&&Array.isArray(r.value)){var s=r.value.map(function(t){return d(t,u,e,n)});return null!=o?{count:o,value:s}:s}return d(r,u,e,n)}}});var l="@odata.context",y="@odata.count",h="@odata.type";function d(t,e,n,r){if(null!=t){if(Array.isArray(t))return t.map(function(t){return d(t,e,n,r)});if(t[h]){var a=t[h].substr(1);if(null==(e=n.getEdmTypeMetadata(a)))throw new Error("Metadata for type '"+a+"' not found.")}if("string"==typeof e)return"object"==typeof t&&(t=t.value),function(t,e,n){var r=i[e];return r&&r.fromEdm?r.fromEdm(t,n):null}(t,e,r)||t;var o=void 0;if(e instanceof L){var u=e.members[t];if(!u)throw new Error("Member '"+t+"' not found in enum '"+e.name+"'");return u}var s=e;o={};var p=function t(e){var n=e.baseType?t(e.baseType):{};for(var r in e.properties)n[r]=e.properties[r].type;for(var r in e.navProperties)n[r]=e.navProperties[r].type;return n}(s);for(var c in t){var f=p[c];f?o[c]=d(t[c],f,n,r):C(c,"@")||1!=s.openType||(o[c]=t[c])}return o}return null}var m,_=function(){function t(){this.__keys=[],this.__values=[]}return t.prototype.get=function(t){if(t){var e=this.__keys.indexOf(t);if(e>-1)return this.__values[e]}},t.prototype.set=function(t,e){if(null==t)throw new Error("Key must be set");var n=this.__keys.indexOf(t);-1==n&&(n=this.__keys.push(t)-1),this.__values[n]=e},t}(),v=(m=function(t,e){return(m=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var n in e)e.hasOwnProperty(n)&&(t[n]=e[n])})(t,e)},function(t,e){function n(){this.constructor=t}m(t,e),t.prototype=null===e?Object.create(e):(n.prototype=e.prototype,new n)}),g=function(){function t(t,e,n){this._apiMetadata=t,this._entityMetadata=e,this._options=n,this._segments=[],this.params={},this._method="get"}return t.create=function(e,n,r){return new t(e,n,r)._freeze()},t.prototype._clone=function(e){var n=new t(this._apiMetadata,this._entityMetadata,this._options);n._segments=this._segments.slice();for(var r,a=0,o=Object.getOwnPropertyNames(this.params);a<o.length;a++){var i=o[a],u=this.params[i];null!=u&&(n.params[i]=Array.isArray(u)?(r=u)?r.slice():null:u)}return n._method=this._method,n._payload=this._payload,e&&e(n),n._freeze()},t.prototype._freeze=function(){var t=this;return this._segments=Object.freeze(this._segments),Object.getOwnPropertyNames(this.params).forEach(function(e){var n=t.params[e];null!==n&&"object"==typeof n&&Object.freeze(n)}),this.params=Object.freeze(this.params),this._payload=Object.freeze(this._payload),Object.freeze(this)},t.prototype._action=function(t,e){return this._clone(function(n){if(n._segments.push(new T(t)),n._method="post",n._entityMetadata=t.returnType&&t.returnType.type,e&&e.length>0){var r={},a={};if(t.parameters)for(var o=0;o<e.length;o++){var i=t.parameters[o];r[i.name]=e[o],a[i.name]=i.type}n._entityMetadata=new U("",a),n._payload=r}})},t.prototype._func=function(t,e){return this._clone(function(n){n._entityMetadata=t.returnType&&t.returnType.type,n._segments.push(new M(t,e))})},t.prototype.byKey=function(t){return this._clone(function(e){var n=e._segments.length;e._segments[n-1]instanceof x&&n--,e._segments.splice(n,0,new E(t))})},t.prototype.cast=function(t){return this._clone(function(e){return e._segments.push(new x(t))})},t.prototype.navigate=function(t,e){return this._clone(function(n){n._entityMetadata=e,n._segments.push(new b(t))})},t.prototype.operation=function(t,e){return t.isAction?this._action(t,e):this._func(t,e)},t.prototype.count=function(t){return void 0===t&&(t={inline:!1}),this._clone(function(e){t.inline?e.params.count=!0:e._segments.push(new O)})},t.prototype.delete=function(){return this._clone(function(t){t._method="delete"})},t.prototype.expand=function(t,e){return this._clone(function(n){(null==n.params.expand?n.params.expand=[]:n.params.expand).push({expand:t,expr:e})})},t.prototype.filter=function(t){return this._clone(function(e){(null==e.params.filter?e.params.filter=new Array:e.params.filter).push(t)})},t.prototype.insert=function(t){return this._clone(function(e){e._payload=t,e._method="post"})},t.prototype.orderBy=function(t){return this._clone(function(e){var n;t&&(e.params.orderBy||(e.params.orderBy=[]),(n=e.params.orderBy).push.apply(n,t))})},t.prototype.search=function(t){return this._clone(function(e){e.params.search||(e.params.search=[]),e.params.search.push(t)})},t.prototype.select=function(t){return this._clone(function(e){return e.params.select=t})},t.prototype.skip=function(t){return this._clone(function(e){return e.params.skip=t})},t.prototype.top=function(t){return this._clone(function(e){return e.params.top=t})},t.prototype.update=function(t,e){return this._clone(function(n){n._payload=t,n._method=e?"put":"patch"})},t.prototype.url=function(t,e){void 0===t&&(t=!0);var n=this._apiMetadata&&this._apiMetadata.apiRoot||"",r=t?this.params:void 0,a=Object.assign({},this._options,e),o=n+this._segments.map(function(t){return t.toUrlFragment(a)}).join("");if(r){var i=this.buildParams(a,"&");if(i)return o+"?"+i}return o},t.prototype.buildParams=function(t,e){var n=this;return void 0===e&&(e="&"),Object.getOwnPropertyNames(this.params).map(function(e){return n.params[e]&&n.processParameter(e,n.params[e],t)}).filter(function(t){return t}).join(e)},t.prototype.processParameter=function(t,e,n){var r=this;switch(t){case"select":return"$select="+e.join(",");case"expand":return"$expand="+e.map(function(t){return r.expandToString(t,n)}).join(",");case"filter":return"$filter="+e.join(" and ");case"orderBy":return"$orderby="+e.join(",");case"skip":return"$skip="+e;case"top":return"$top="+e;case"count":return!0===e?"$count=true":void 0;case"search":return"$search="+e.join(" AND ")}},t.prototype.expandToString=function(t,e){return t.expr?function(t,e,n,r,a){var o=r.navProperties[t];if(null==o)throw new Error("Expand support navigation properties only");var i=o.type,u=g.create(n,i,a),s=function(t,e,n,r){void 0===r&&(r=",");var a=e();return(a=t(a)).query.buildParams(n,r)}(e,function(){return o.collection?new A(i,n,u):new q(i,n,u)},a,";");return s?t+"("+s+")":t}(t.expand,t.expr,this._apiMetadata,this._entityMetadata,e):t.expand},t.prototype.exec=function(t){var e=Object.assign({},this._options,t),n=this.url(!0,e);return this._fetchData(n,e)},t.prototype._fetchData=function(t,e){var n=this,r=e&&e.fetch||fetch,a=p(e.format||"application/json"),o=this._payload?a.serialize(this._payload,this._entityMetadata,e):null;return r(t,{method:this._method,body:o,headers:{"Content-Type":a.contentType,"X-Requested-With":"XMLHttpRequest"},credentials:e.credentials}).then(function(t){return new Promise(function(e,n){t.body?t.text().then(function(n){return e({response:t,body:n})},n):e({response:t})})}).then(function(t){var r=t.body,a=t.response,o=a.headers.get("Content-Type");if(a.ok)return r&&r.length>0?(o?o=o.split(";")[0].trim():C(r,"{")&&(o="application/json"),p(o).deserialize(r,n._apiMetadata,e)):null;try{var i=r&&JSON.parse(r)}catch(t){}var u=i&&i.error||a.statusText;throw{status:a.status,error:u}})},t}(),w=function(){return function(){}}(),b=function(t){function e(e){var n=t.call(this)||this;return n.property=e,n}return v(e,t),e.prototype.toUrlFragment=function(){return"/"+this.property},e}(w),E=function(t){function e(e){var n=t.call(this)||this;return n.key=e,n}return v(e,t),e.prototype.toUrlFragment=function(){return"("+this.key+")"},e}(w),T=function(t){function e(e){var n=t.call(this)||this;return n._metadata=e,n}return v(e,t),e.prototype.toUrlFragment=function(t){return"/"+(this._metadata.bindingTo&&1!=t.enableUnqualifiedNameCall?this._metadata.getFullName():this._metadata.name)},e}(w),M=function(t){function e(e,n){var r=t.call(this)||this;return r.__metadata=e,r.__args=n,r}return v(e,t),e.prototype.toUrlFragment=function(t){var e=this,n=this.__metadata.bindingTo&&1!=t.enableUnqualifiedNameCall?this.__metadata.getFullName():this.__metadata.name,r=this.__args.map(function(t,r){if(e.__metadata.parameters){var a=e.__metadata.parameters[r];if(null!=a){var o=c(t,a.type.type,!0);return[a.name,o].join("=")}}throw new Error("Parameter '"+r+"', for function '"+n+"', not defined in metadata")});return"/"+n+"("+r.join(",")+")"},e}(w),O=function(t){function e(){return null!==t&&t.apply(this,arguments)||this}return v(e,t),e.prototype.toUrlFragment=function(){return"/$count"},e}(w),x=function(t){function e(e){var n=t.call(this)||this;return n.__fullTypeName=e,n}return v(e,t),e.prototype.toUrlFragment=function(){return"/"+this.__fullTypeName},e}(w),P=function(){var t=function(e,n){return(t=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var n in e)e.hasOwnProperty(n)&&(t[n]=e[n])})(e,n)};return function(e,n){function r(){this.constructor=e}t(e,n),e.prototype=null===n?Object.create(n):(r.prototype=n.prototype,new r)}}(),S=function(){function t(t){this.query=t}return t.prototype.$exec=function(t){return this.query.exec(t)},t.prototype.$url=function(t){return this.query.url(!t||0!=t.queryParams,t)},t}(),j=function(t){function e(){return null!==t&&t.apply(this,arguments)||this}return P(e,t),e.prototype.$execWithCount=function(t){return this.query.count({inline:!0}).exec(t)},e}(S),$=function(){var t=function(e,n){return(t=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var n in e)e.hasOwnProperty(n)&&(t[n]=e[n])})(e,n)};return function(e,n){function r(){this.constructor=e}t(e,n),e.prototype=null===n?Object.create(n):(r.prototype=n.prototype,new r)}}(),q=function(t){function e(e,n,r){var a=t.call(this,r)||this;return a.__metadata=e,a.__apiMetadata=n,a.generatePropertyImplementation(),a}return $(e,t),e.prototype.generatePropertyImplementation=function(){var t=this.query,n=function(n){var a=r.__metadata.navProperties[n];Object.defineProperty(r,n,{get:function(){var r=t.navigate(n,a.type);return a.collection?new A(a.type,this.__apiMetadata,r):new e(a.type,this.__apiMetadata,r)}})},r=this;for(var a in this.__metadata.navProperties)n(a);var o=function(t){var n=i.__metadata.properties[t];Object.defineProperty(i,t,{get:function(){var r=this.query.navigate(t);return new e(n.type,this.__apiMetadata,r)}})},i=this;for(var a in this.__metadata.properties)o(a);F(this,function(){return t},this.__apiMetadata,this.__metadata)},e.prototype.$cast=function(t){var n=this.__apiMetadata.getEdmTypeMetadata(t);if(!n)throw new Error("EntitType '"+t+"' not found.");var r=this.query.cast(t);return new e(n,this.__apiMetadata,r)},e.prototype.$select=function(){for(var t=[],n=0;n<arguments.length;n++)t[n]=arguments[n];var r=this.query.select(t);return new e(this.__metadata,this.__apiMetadata,r)},e.prototype.$expand=function(t,n){return new e(this.__metadata,this.__apiMetadata,this.query.expand(t,n))},e.prototype.$delete=function(){var t=this.query.delete();return new S(t)},e.prototype.$patch=function(t){return this.$update(t,!1)},e.prototype.$unsafeExpand=function(t){return this.$expand(t)},e.prototype.$update=function(t,e){void 0===e&&(e=!0);var n=this.query.update(t,e);return new S(n)},e}(S),N=function(){var t=function(e,n){return(t=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var n in e)e.hasOwnProperty(n)&&(t[n]=e[n])})(e,n)};return function(e,n){function r(){this.constructor=e}t(e,n),e.prototype=null===n?Object.create(n):(r.prototype=n.prototype,new r)}}(),A=function(t){function e(e,n,r){var a=t.call(this,r)||this;return a.__metadata=e,a.__apiMetadata=n,a._generateOperationsProperties(),a}return N(e,t),e.prototype._generateOperationsProperties=function(){var t=this;this.__apiMetadata&&F(this,function(){return t.query},this.__apiMetadata,this.__metadata,!0)},e.prototype.$byKey=function(t){var e="object"!=typeof t||t instanceof Date?this.getExpressionByKeyValue(t):this.getExpressionByValues(t),n=this.query.byKey(e);return new q(this.__metadata,this.__apiMetadata,n)},e.prototype.getExpressionByKeyValue=function(t){for(var e=this.__metadata,n=this.__metadata.keys;e.baseType&&!n;)n=(e=e.baseType).keys;if(!n)throw new Error("Metadata: Keys not defined for entity type '"+e.name+"'");if(n.length>1)throw new Error("For entity with composite key use named parameters");var r=c(t,e.properties[n[0]].type,!0);if(!r)throw new Error("Key must be not null value");return r},e.prototype.getExpressionByValues=function(t){var e=new Array;for(var n in t){var r=this.__metadata.properties[n];if(!r)throw new Error("Property '"+n+"' for entity '"+this.__metadata.name+"' not found.");var a=n+"="+c(t[n],r.type,!0);e.push(a)}return e.join(",")},e.prototype.$cast=function(t){var n=this.__apiMetadata.getEdmTypeMetadata(t);if(!n)throw new Error("EntityType '"+t+"' not found.");var r=this.query.cast(t);return new e(n,this.__apiMetadata,r)},e.prototype.$count=function(){var t=this.query.count();return new S(t)},e.prototype.$delete=function(t){return this.$byKey(t).$delete()},e.prototype.$expand=function(t,n){var r=this.query.expand(t,n);return new e(this.__metadata,this.__apiMetadata,r)},e.prototype.$filter=function(t){var n=this.query.filter(t);return new e(this.__metadata,this.__apiMetadata,n)},e.prototype.$orderBy=function(){for(var t=[],e=0;e<arguments.length;e++)t[e]=arguments[e];return this.orderByImpl(t)},e.prototype.$orderByDesc=function(){for(var t=[],e=0;e<arguments.length;e++)t[e]=arguments[e];return this.orderByImpl(t,!0)},e.prototype.orderByImpl=function(t,n){var r=this;void 0===n&&(n=!1);var a=t.map(function(t){var e,a,o,i,u,s="string"==typeof t?t:(e=t,a=r.__metadata,o=r.__apiMetadata,i=new q(a,o,g.create(null,a,void 0)),C(u=(i=e(i)).query.url(!1),"/")?u.substr(1):u);return n&&(s+=" desc"),s}),o=this.query.orderBy(a);return new e(this.__metadata,this.__apiMetadata,o)},e.prototype.$insert=function(t){var e=this.query.insert(t);return new S(e)},e.prototype.$patch=function(t,e){return this.$byKey(t).$patch(e)},e.prototype.$top=function(t){var n=this.query.top(t);return new e(this.__metadata,this.__apiMetadata,n)},e.prototype.$skip=function(t){var n=this.query.skip(t);return new e(this.__metadata,this.__apiMetadata,n)},e.prototype.$search=function(t){var n=this.query.search(t);return new e(this.__metadata,this.__apiMetadata,n)},e.prototype.$select=function(){for(var t=[],n=0;n<arguments.length;n++)t[n]=arguments[n];var r=this.query.select(t);return new e(this.__metadata,this.__apiMetadata,r)},e.prototype.$unsafeExpand=function(t){return this.$expand(t)},e.prototype.$update=function(t,e){return this.$byKey(t).$update(e)},e.prototype.$urlWithCount=function(){return this.query.count({inline:!0}).url()},e}(j);function F(t,e,n,r,a){for(var o in void 0===a&&(a=!1),n.namespaces)for(var i=function(o){(null==o.bindingTo&&null==r||o.bindingTo&&(o.bindingTo.collection||!1)==a&&o.bindingTo.type==r)&&Object.defineProperty(t,o.name,{get:function(){return function(){for(var t=[],r=0;r<arguments.length;r++)t[r]=arguments[r];var a=e().operation(o,t);return o.returnType&&o.returnType.collection?new A(o.returnType.type,n,a):new S(a)}}})},u=0,s=n.namespaces[o].operations;u<s.length;u++){i(s[u])}}function C(t,e,n){return void 0===n&&(n=0),t.indexOf(e,n)==n}function k(t,e,n){(void 0===n||n>t.length)&&(n=t.length),n-=e.length;var r=t.indexOf(e,n);return-1!==r&&r===n}function B(t,e){if(e){var n=function(){var n=t.prototype[r],a=e[r];t.prototype[r]=function(){return a.apply(this,[n&&n.bind(this)].concat(Array.from(arguments)))}};for(var r in e)n()}}var D,I=function(){var t=function(e,n){return(t=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var n in e)e.hasOwnProperty(n)&&(t[n]=e[n])})(e,n)};return function(e,n){function r(){this.constructor=e}t(e,n),e.prototype=null===n?Object.create(n):(r.prototype=n.prototype,new r)}}(),z=function(t,e,n,r){return new(n||(n=Promise))(function(a,o){function i(t){try{s(r.next(t))}catch(t){o(t)}}function u(t){try{s(r.throw(t))}catch(t){o(t)}}function s(t){t.done?a(t.value):new n(function(e){e(t.value)}).then(i,u)}s((r=r.apply(t,e||[])).next())})},K=function(t,e){var n,r,a,o,i={label:0,sent:function(){if(1&a[0])throw a[1];return a[1]},trys:[],ops:[]};return o={next:u(0),throw:u(1),return:u(2)},"function"==typeof Symbol&&(o[Symbol.iterator]=function(){return this}),o;function u(o){return function(u){return function(o){if(n)throw new TypeError("Generator is already executing.");for(;i;)try{if(n=1,r&&(a=2&o[0]?r.return:o[0]?r.throw||((a=r.return)&&a.call(r),0):r.next)&&!(a=a.call(r,o[1])).done)return a;switch(r=0,a&&(o=[2&o[0],a.value]),o[0]){case 0:case 1:a=o;break;case 4:return i.label++,{value:o[1],done:!1};case 5:i.label++,r=o[1],o=[0];continue;case 7:o=i.ops.pop(),i.trys.pop();continue;default:if(!(a=(a=i.trys).length>0&&a[a.length-1])&&(6===o[0]||2===o[0])){i=0;continue}if(3===o[0]&&(!a||o[1]>a[0]&&o[1]<a[3])){i.label=o[1];break}if(6===o[0]&&i.label<a[1]){i.label=a[1],a=o;break}if(a&&i.label<a[2]){i.label=a[2],i.ops.push(o);break}a[2]&&i.ops.pop(),i.trys.pop();continue}o=e.call(t,i)}catch(t){o=[6,t],r=0}finally{n=a=0}if(5&o[0])throw o[1];return{value:o[0]?o[1]:void 0,done:!0}}([o,u])}}};!function(t){t.Int32="Edm.Int32",t.Int16="Edm.Int16",t.Boolean="Edm.Boolean",t.String="Edm.String",t.Single="Edm.Single",t.Guid="Edm.Guid",t.DateTimeOffset="Edm.DateTimeOffset",t.Date="Edm.Date",t.Double="Edm.Double",t.TimeOfDay="Edm.TimeOfDay",t.Decimal="Edm.Decimal",t.Unknown="Unknown"}(D||(D={}));var U=function(){return function(t,e,n,r,a,o){void 0===n&&(n={});var i=this;this.name=t,this.properties=e,this.navProperties=n,this.keys=r,this.baseType=a,this.openType=o,this.getFullName=function(){return J(i)}}}(),R=function(t){function e(){return null!==t&&t.apply(this,arguments)||this}return I(e,t),e}(U),L=function(){return function(t,e){var n=this;this.name=t,this.members=e,this.getFullName=function(){return J(n)}}}(),V=function(){function t(t,e,n){void 0===e&&(e=!0),void 0===n&&(n=!1),this.type=t,this.nullable=e,this.collection=n}return t.fromTypeReference=function(t){if(t.type instanceof U)return t;throw new Error("Instance must be reference to EdmEntityType")},t}(),G=function(){return function(t,e,n){void 0===e&&(e=!0),void 0===n&&(n=!1),this.type=t,this.nullable=e,this.collection=n}}(),X=function(){return function(t,e,n,r,a){var o=this;this.name=t,this.isAction=e,this.parameters=n,this.returnType=r,this.bindingTo=a,this.getFullName=function(){return J(o)}}}();function J(t){return t.namespace?[t.namespace.name,t.name].join("."):t.name}var W=function(){function t(t){this.name=t,this.operations=[],this.types={}}return t.prototype.addTypes=function(){for(var t=[],e=0;e<arguments.length;e++)t[e]=arguments[e];for(var n=0,r=t;n<r.length;n++){var a=r[n];a.namespace=this,this.types[a.name]=a}},t.prototype.addOperations=function(){for(var t=[],e=0;e<arguments.length;e++)t[e]=arguments[e];for(var n=0,r=t;n<r.length;n++){var a=r[n];a.namespace=this,this.operations.push(a)}},t}(),H={};function Q(t,e,n){void 0===n&&(n=!0),k(t,"/")&&(t=t.substr(0,t.length-1));var r=t.toLowerCase(),a=H[r];return null!=a&&n?Promise.resolve(a):Y.loadAsync(t,e).then(function(t){return n&&(H[r]=t),t})}var Y=function(){function t(t,e,n,r,a){void 0===n&&(n={}),void 0===r&&(r={}),void 0===a&&(a={}),this.apiRoot=t,this.containerName=e,this.namespaces=n,this.entitySets=r,this.singletons=a}return t.loadFromXml=function(e,n){var r=(new DOMParser).parseFromString(n,"text/xml"),a=t.parseEntityTypes(r),o={},i={},u=r.querySelector("Schema>EntityContainer"),s=u&&Z(u,"Name");if(u)for(var p=u.querySelectorAll("EntitySet,Singleton"),c=0;c<p.length;c++){var f="SINGLETON"===(d=p.item(c)).tagName.toUpperCase(),l=Z(d,"Name"),y=Z(d,f?"Type":"EntityType");(f?i:o)[l]=t.getEntitySetMetadata(y,a)}var h=r.querySelectorAll("Schema>Function,Schema>Action");for(c=0;c<h.length;c++){var d=h.item(c),m=t.parseOperationMetadata(d,a),_=Z(d.parentElement,"Namespace");a[_]||(a[_]=new W(_)),a[_].addOperations(m)}return new t(e,s,a,o,i)},t.loadAsync=function(t,e){return z(this,void 0,void 0,function(){var n,r,a,o,i,u,s;return K(this,function(p){switch(p.label){case 0:return n=t+"/$metadata",a=(r=e||{}).fetch||fetch,o=r.credentials,[4,a(n,{credentials:o})];case 1:return i=p.sent(),u=this.loadFromXml,s=[t],[4,i.text()];case 2:return[2,u.apply(this,s.concat([p.sent()]))]}})})},t.parseEntityTypes=function(e){for(var n={},r=[],a=e.querySelectorAll("Schema>ComplexType,Schema>EntityType,Schema>EnumType"),o=function(){var e=a.item(i),o=function(t,r){var a=n[t];a||(n[t]=a=new W(t));var o=a.types[r];return o||(o="complextype"==e.tagName.toLowerCase()?new R(r,{}):new U(r,{}),a.addTypes(o)),o},u=Z(e.parentElement,"Namespace"),s=Z(e,"Name");if(u in n||(n[u]=new W(u)),"enumtype"===e.tagName.toLowerCase()){var p=new L(s,t.parseEnumMembers(e));n[u].addTypes(p)}else{var c=o(u,s);c.openType=tt(e,"OpenType");var f=et(e,"BaseType");if(f){var l=f.substring(0,f.lastIndexOf(".")),y=o(l,f.substr(l.length+1));c.baseType=y}r.push({element:e,typeMetadata:c})}},i=0;i<a.length;i++)o();for(var u=0,s=r;u<s.length;u++){var p=s[u];Object.assign(p.typeMetadata,t.getEntityTypeProperties(p.element,n)),p.typeMetadata.keys=this.parseEntityKeys(p.element)}return n},t.parseEntityKeys=function(t){for(var e=new Array,n=t.querySelectorAll("Key>PropertyRef"),r=0;r<n.length;r++)e.push(Z(n.item(r),"Name"));return e},t.parseEnumMembers=function(t){for(var e={},n=t.querySelectorAll("Member"),r=0;r<n.length;r++){var a=n.item(r),o=Z(a,"Name"),i=Z(a,"Value");e[o]=i.match(/\d/)?parseInt(i):i}return e},t.getEntityTypeProperties=function(e,n){for(var r={},a={},o=e.querySelectorAll("Property,NavigationProperty"),i=0;i<o.length;i++){var u=o.item(i),s=Z(u,"Name"),p=t.parseType(u,n);"property"==u.tagName.toLowerCase()?r[s]=p:a[s]=V.fromTypeReference(p)}return{properties:r,navProperties:a}},t.prototype.getEntitySetMetadata=function(e){return t.getEntitySetMetadata(e,this.namespaces)},t.getEntitySetMetadata=function(e,n){var r=t.getEdmTypeMetadata(e,n);if(r instanceof U)return r;throw new Error("EntitySet item type must be entity")},t.prototype.getEdmTypeMetadata=function(e){return t.getEdmTypeMetadata(e,this.namespaces)},t.getEdmTypeMetadata=function(t,e){C(t,"Collection(")&&(t=t.substring("Collection(".length,t.length-1));var n=t.substring(0,t.lastIndexOf(".")),r=t.substr(n.length+1);if("Edm"==n){var a=D[r];if(!a)throw new Error("Not registred Edm type: "+r);return a}var o=e[n];if(!o)throw new Error("Namespace '"+n+"' not found");return o.types[r]},t.parseOperationMetadata=function(e,n){for(var r,a="action"===e.tagName.toLowerCase(),o=Z(e,"Name"),i=e.querySelector("ReturnType"),u=i?t.parseType(i,n):void 0,s=new Array,p=e.querySelectorAll("Parameter"),c=0;c<p.length;c++){var f=p.item(c),l=t.parseType(f,n),y=Z(f,"Name");tt(e,"IsBound")&&!r?r=V.fromTypeReference(l):s.push({name:y,type:l})}return new X(o,a,s,u,r)},t.parseType=function(e,n){var r=Z(e,"Type"),a=C(r,"Collection(");a&&(r=r.substring("Collection(".length,r.length-1));var o=t.getEdmTypeMetadata(r,n),i=new G(o,!0,a);return i.nullable=0!=tt(e,"Nullable"),i},t}();function Z(t,e){return et(t,e)||function(){throw new Error("Metadata: Attribute '"+e+"' in element '"+t.tagName+"' not found ")}()}function tt(t,e){var n=et(t,e);if(null!=n)return"true"==n.toLowerCase()}function et(t,e){var n=t.attributes.getNamedItem(e);if(n)return n.value}var nt=function(){function t(t,e){this.__metadata=t,this.__options=e,this.generate()}return t.prototype.generate=function(){var t=this.__metadata,e=this.__options,n=function(n){var a=t.entitySets[n];Object.defineProperty(r,n,{get:function(){var r=g.create(t,a,e);return r=r.navigate(n,a),new A(a,t,r)}})},r=this;for(var a in t.entitySets)n(a);var o=function(n){var r=t.singletons[n];Object.defineProperty(i,n,{get:function(){var a=g.create(t,r,e).navigate(n,r);return new q(r,t,a)}})},i=this;for(var a in t.singletons)o(a);F(this,function(){return g.create(t,null,e)},t,void 0)},t}();n.d(e,"Pailingual",function(){return rt}),n.d(e,"ApiContextFactory",function(){return at}),n.d(e,"loadMetadata",function(){return Q}),n.d(e,"metadata",function(){return a}),n.d(e,"serialization",function(){return r}),n.d(e,"CollectionSource",function(){return A}),n.d(e,"SingleSource",function(){return q}),n.d(e,"Query",function(){return g});var rt=function(){function t(){}return t.use=function(t){if(t){var e=t.register();e&&(e.apiContextFn&&B(nt,e.apiContextFn),e.collectionSourceFn&&B(A,e.collectionSourceFn),e.singleSourceFn&&B(q,e.singleSourceFn),e.queryFn&&B(g,e.queryFn))}},t.createApiContext=function(t,e){if("string"==typeof t)return Q(t).then(function(t){return new nt(t,e)});if(t instanceof Y)return new nt(t,e);throw new Error("First parameter must be api url or metadata object")},t.loadMetadata=function(t,e,n){return Q(t,e,n)},t}(),at=(e.default=rt,rt.createApiContext)}])});