@nextgis/ngw-connector 1.8.4 → 1.9.2

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.
@@ -12,5 +12,5 @@ var NgwConnector=function(){"use strict";
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 e=function(t,n){return(e=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,t){e.__proto__=t}||function(e,t){for(var n in t)Object.prototype.hasOwnProperty.call(t,n)&&(e[n]=t[n])})(t,n)};function t(t,n){if("function"!=typeof n&&null!==n)throw new TypeError("Class extends value "+String(n)+" is not a constructor or null");function r(){this.constructor=t}e(t,n),t.prototype=null===n?Object.create(n):(r.prototype=n.prototype,new r)}var n=function(){return(n=Object.assign||function(e){for(var t,n=1,r=arguments.length;n<r;n++)for(var o in t=arguments[n])Object.prototype.hasOwnProperty.call(t,o)&&(e[o]=t[o]);return e}).apply(this,arguments)};var r,o={exports:{}},i="object"==typeof Reflect?Reflect:null,s=i&&"function"==typeof i.apply?i.apply:function(e,t,n){return Function.prototype.apply.call(e,t,n)};r=i&&"function"==typeof i.ownKeys?i.ownKeys:Object.getOwnPropertySymbols?function(e){return Object.getOwnPropertyNames(e).concat(Object.getOwnPropertySymbols(e))}:function(e){return Object.getOwnPropertyNames(e)};var u=Number.isNaN||function(e){return e!=e};function c(){c.init.call(this)}o.exports=c,o.exports.once=function(e,t){return new Promise((function(n,r){function o(n){e.removeListener(t,i),r(n)}function i(){"function"==typeof e.removeListener&&e.removeListener("error",o),n([].slice.call(arguments))}g(e,t,i,{once:!0}),"error"!==t&&function(e,t,n){"function"==typeof e.on&&g(e,"error",t,n)}(e,o,{once:!0})}))},c.EventEmitter=c,c.prototype._events=void 0,c.prototype._eventsCount=0,c.prototype._maxListeners=void 0;var a=10;function f(e){if("function"!=typeof e)throw new TypeError('The "listener" argument must be of type Function. Received type '+typeof e)}function h(e){return void 0===e._maxListeners?c.defaultMaxListeners:e._maxListeners}function p(e,t,n,r){var o,i,s,u;if(f(n),void 0===(i=e._events)?(i=e._events=Object.create(null),e._eventsCount=0):(void 0!==i.newListener&&(e.emit("newListener",t,n.listener?n.listener:n),i=e._events),s=i[t]),void 0===s)s=i[t]=n,++e._eventsCount;else if("function"==typeof s?s=i[t]=r?[n,s]:[s,n]:r?s.unshift(n):s.push(n),(o=h(e))>0&&s.length>o&&!s.warned){s.warned=!0;var c=new Error("Possible EventEmitter memory leak detected. "+s.length+" "+String(t)+" listeners added. Use emitter.setMaxListeners() to increase limit");c.name="MaxListenersExceededWarning",c.emitter=e,c.type=t,c.count=s.length,u=c,console&&console.warn&&console.warn(u)}return e}function l(){if(!this.fired)return this.target.removeListener(this.type,this.wrapFn),this.fired=!0,0===arguments.length?this.listener.call(this.target):this.listener.apply(this.target,arguments)}function d(e,t,n){var r={fired:!1,wrapFn:void 0,target:e,type:t,listener:n},o=l.bind(r);return o.listener=n,r.wrapFn=o,o}function v(e,t,n){var r=e._events;if(void 0===r)return[];var o=r[t];return void 0===o?[]:"function"==typeof o?n?[o.listener||o]:[o]:n?function(e){for(var t=new Array(e.length),n=0;n<t.length;++n)t[n]=e[n].listener||e[n];return t}(o):m(o,o.length)}function y(e){var t=this._events;if(void 0!==t){var n=t[e];if("function"==typeof n)return 1;if(void 0!==n)return n.length}return 0}function m(e,t){for(var n=new Array(t),r=0;r<t;++r)n[r]=e[r];return n}function g(e,t,n,r){if("function"==typeof e.on)r.once?e.once(t,n):e.on(t,n);else{if("function"!=typeof e.addEventListener)throw new TypeError('The "emitter" argument must be of type EventEmitter. Received type '+typeof e);e.addEventListener(t,(function o(i){r.once&&e.removeEventListener(t,o),n(i)}))}}Object.defineProperty(c,"defaultMaxListeners",{enumerable:!0,get:function(){return a},set:function(e){if("number"!=typeof e||e<0||u(e))throw new RangeError('The value of "defaultMaxListeners" is out of range. It must be a non-negative number. Received '+e+".");a=e}}),c.init=function(){void 0!==this._events&&this._events!==Object.getPrototypeOf(this)._events||(this._events=Object.create(null),this._eventsCount=0),this._maxListeners=this._maxListeners||void 0},c.prototype.setMaxListeners=function(e){if("number"!=typeof e||e<0||u(e))throw new RangeError('The value of "n" is out of range. It must be a non-negative number. Received '+e+".");return this._maxListeners=e,this},c.prototype.getMaxListeners=function(){return h(this)},c.prototype.emit=function(e){for(var t=[],n=1;n<arguments.length;n++)t.push(arguments[n]);var r="error"===e,o=this._events;if(void 0!==o)r=r&&void 0===o.error;else if(!r)return!1;if(r){var i;if(t.length>0&&(i=t[0]),i instanceof Error)throw i;var u=new Error("Unhandled error."+(i?" ("+i.message+")":""));throw u.context=i,u}var c=o[e];if(void 0===c)return!1;if("function"==typeof c)s(c,this,t);else{var a=c.length,f=m(c,a);for(n=0;n<a;++n)s(f[n],this,t)}return!0},c.prototype.on=c.prototype.addListener=function(e,t){return p(this,e,t,!1)},c.prototype.prependListener=function(e,t){return p(this,e,t,!0)},c.prototype.once=function(e,t){return f(t),this.on(e,d(this,e,t)),this},c.prototype.prependOnceListener=function(e,t){return f(t),this.prependListener(e,d(this,e,t)),this},c.prototype.off=c.prototype.removeListener=function(e,t){var n,r,o,i,s;if(f(t),void 0===(r=this._events))return this;if(void 0===(n=r[e]))return this;if(n===t||n.listener===t)0==--this._eventsCount?this._events=Object.create(null):(delete r[e],r.removeListener&&this.emit("removeListener",e,n.listener||t));else if("function"!=typeof n){for(o=-1,i=n.length-1;i>=0;i--)if(n[i]===t||n[i].listener===t){s=n[i].listener,o=i;break}if(o<0)return this;0===o?n.shift():function(e,t){for(;t+1<e.length;t++)e[t]=e[t+1];e.pop()}(n,o),1===n.length&&(r[e]=n[0]),void 0!==r.removeListener&&this.emit("removeListener",e,s||t)}return this},c.prototype.removeAllListeners=function(e){var t,n,r;if(void 0===(n=this._events))return this;if(void 0===n.removeListener)return 0===arguments.length?(this._events=Object.create(null),this._eventsCount=0):void 0!==n[e]&&(0==--this._eventsCount?this._events=Object.create(null):delete n[e]),this;if(0===arguments.length){var o,i=Object.keys(n);for(r=0;r<i.length;++r)"removeListener"!==(o=i[r])&&this.removeAllListeners(o);return this.removeAllListeners("removeListener"),this._events=Object.create(null),this._eventsCount=0,this}if("function"==typeof(t=n[e]))this.removeListener(e,t);else if(void 0!==t)for(r=t.length-1;r>=0;r--)this.removeListener(e,t[r]);return this},c.prototype.listeners=function(e){return v(this,e,!0)},c.prototype.rawListeners=function(e){return v(this,e,!1)},c.listenerCount=function(e,t){return"function"==typeof e.listenerCount?e.listenerCount(t):y.call(e,t)},c.prototype.listenerCount=y,c.prototype.eventNames=function(){return this._eventsCount>0?r(this._events):[]};var _=function(e){function n(){var t=e.call(this)||this;return t.name="CancelError",Object.setPrototypeOf(t,n.prototype),t}return t(n,e),n}(Error),w=function(){function e(e){void 0===e&&(e={}),this.options=e,this._promises=new Map}return Object.defineProperty(e.prototype,"isLoaded",{get:function(){return this._promises.size>0},enumerable:!1,configurable:!0}),e.prototype.remove=function(e){this._promises.has(e)&&(this._promises.delete(e),this._onStop())},e.prototype.get=function(e){return this._promises.get(e)},e.prototype.add=function(e,t){var n=this,r=t||e,o=this._promises.get(r);return this.options.onStart&&!this.isLoaded&&this.options.onStart(),o||(this._promises.set(r,e),e.finally((function(){n.remove(r)})),e)},e.prototype.abort=function(){this.isLoaded&&(this._promises.forEach((function(e){e.cancel&&e.cancel()})),this._promises.clear(),this._onStop())},e.prototype.waitFunc=function(e,t){void 0===t&&(t="");var n=this.get(t=t||e.name);return n||this.add(e(),t)},e.prototype.WaitForMe=function(e){void 0===e&&(e="");var t=this.get.bind(this),n=this.add.bind(this);return function(r,o,i){var s=i.value;return e=e||o,i.value=function(){for(var r=[],o=0;o<arguments.length;o++)r[o]=arguments[o];var i=t(e);if(i)return i;var u=n(s.apply(this,r),e);return u},i}},e.prototype.GetOrCreateDecorator=function(e){return void 0===e&&(e=""),this.WaitForMe(e)},e.prototype._onStop=function(){this.options.onStop&&!this.isLoaded&&this.options.onStop()},e}(),b=function(e){function n(){var t=e.call(this)||this;return t.name="TimeoutError",Object.setPrototypeOf(t,n.prototype),t}return t(n,e),n}(Error),O=function(e,t,n,r){try{e(n(r))}catch(e){t(e)}},E=0,P=function(){function e(t,n){var r=this;this.id=E++,this._isCanceled=!1,this._isPending=!0,this._cancelHandlers=[],this._children=[],this._cancelPromise=new Promise((function(e,t){r._setCanceledCallback=function(t){return e(t||new _)}}));var o=[this._cancelPromise,new Promise((function(n,o){return t((function(t){t instanceof e?r.attach(t):r._isPending=!1,n(t)}),(function(e){r._isPending=!1,o(e)}),(function(e){if(!r._isPending)throw new Error("The `onCancel` handler was attached after the promise settled.");r._cancelHandlers.push(e)}))}))];n&&o.push(new Promise((function(e,t){setTimeout((function(){if(r._isPending)try{r.cancel()}finally{t(new b)}}),n)}))),this._promise=Promise.race(o)}return e.createControl=function(e){return new w(e)},e.resolve=function(t){return new e((function(e){return e(t)}))},e.reject=function(t){return new e((function(e,n){return n(t)}))},e.all=function(t){var n=this;return new e((function(e,n){Promise.all(t).then(e).catch(n)})).catch((function(e){if(e instanceof n.CancelError)for(var r=0,o=t;r<o.length;r++){var i=o[r];"cancel"in i&&i.cancel()}throw e}))},e.prototype.attach=function(e){this._isCanceled?e.cancel():this._children.push(e)},e.prototype.then=function(t,n){var r=this,o=new e((function(e,o){if(r._promise){var i=function(t){n?O(e,o,n,t):o(t)};r._promise.then((function(n){r._isCanceled?i(n):t?O(e,o,t,n):e(n)}),i)}}));return o._parentPromise=this,this._children.push(o),o},e.prototype.catch=function(e){return this._isCanceled&&e&&e(new _),this.then(void 0,e)},e.prototype.finally=function(e){return this._promise?this._promise.finally(e):Promise.reject(this._isCanceled?new _:e)},e.prototype.cancel=function(){if(this._isCanceled||!this._isPending)return this;this._isCanceled=!0;var e=this._getTopParent();if(e&&e.cancel(),this._children&&this._children.forEach((function(e){return e.cancel()})),this._isPending){if(this._cancelHandlers.length)try{for(var t=0,n=this._cancelHandlers;t<n.length;t++){(0,n[t])()}}catch(e){}this._setCanceledCallback&&this._setCanceledCallback()}return this._destroy(),this},e.prototype._getTopParent=function(){for(var e=this._parentPromise,t=!!e;t;)t=!(!e||!e._parentPromise)&&!!(e=e._parentPromise);return e},e.prototype._destroy=function(){this._setCanceledCallback=void 0,this._cancelPromise=void 0,this._promise=void 0},e.CancelError=_,e.TimeoutError=b,e.PromiseControl=w,e}();Object.setPrototypeOf(P.prototype,Promise.prototype);var C=P;function L(e){return null!=e}function j(e,t,n,r){if(e instanceof Array)return t instanceof Array&&t.sort().join("")===e.sort().join("");if(e instanceof Date)return t instanceof Date&&""+e==""+t;if(e instanceof Function){if(!(t instanceof Function))return!1}else if(e instanceof Object)return t instanceof Object&&(e===n?t===r:R(e,t));return e===t}function R(e,t){var n=Object.keys(e).sort(),r=Object.keys(t).sort();if(n.length!==r.length)return!1;if(n.join("")!==r.join(""))return!1;for(var o=0;o<n.length;o++){if(!j(e[n[o]],t[r[o]],e,t))return!1}return!0}function x(e){var t={};return Object.keys(e).forEach((function(n){e[n]instanceof Array||e[n]!==Object(e[n])?void 0!==e[n]&&(t[n]=e[n]):t[n]=x(e[n])})),t}var T,k=function(){function e(){return this.cache=[],e.instance?e.instance:(e.instance=this,this)}return e.prototype.clean=function(){this.cache.length=0},e.prototype.all=function(){return this.cache},e.prototype.add=function(e,t,n){var r=this,o=this._find(e,n);if(o)return o.value;var i=void 0;i=t instanceof Function?t():t;var s=n&&JSON.parse(JSON.stringify(x(n)));return this.cache.push({key:e,value:i,options:s}),i instanceof Promise?(i.catch((function(t){throw r.delete(e,n),t})),i):i},e.prototype.match=function(e,t){var n=this._find(e,t);if(n)return n.value},e.prototype.matchAll=function(e,t){var n=this;return e?this.cache.filter((function(r){return n._filter(r,e,t)})).map((function(e){return e.value})):this.cache.map((function(e){return e.value}))},e.prototype.delete=function(e,t){for(var n=this,r=0,o=this.cache.filter((function(r){return n._filter(r,e,t)}));r<o.length;r++){var i=this.cache.indexOf(o[r]);this.cache.splice(i,1)}},e.prototype._find=function(e,t){var n=this;return this.cache.find((function(r){return n._filter(r,e,t)}))},e.prototype._filter=function(e,t,n){return e.key===t&&(!n||R(e.options||{},x(n)))},e}(),F=function(e){function n(t){var r=e.call(this)||this;return r.name="NgwError",Object.assign(r,t),Object.setPrototypeOf(r,n.prototype),r}return t(n,e),n}(Error),I=function(e){function n(t){var r=e.call(this)||this;return r.name="NetworkError",Object.setPrototypeOf(r,n.prototype),r.message="Unable to request "+t+".\n Possibly invalid NGW URL entered or CORS not configured to get request from "+location.origin,r}return t(n,e),n}(Error);T=function(e,t,n,r,o){void 0===n&&(n={}),n.method=n.method||"GET";var i=new XMLHttpRequest;i.open(n.method||"GET",e,!0),"blob"===n.responseType&&(i.responseType=n.responseType);var s=function(){try{return JSON.parse(i.responseText)}catch(e){return i.responseText}};i.onload=function(){-1!==[401,403,404,500].indexOf(i.status)&&r(new F(s())),function(e){void 0===e&&(e=!1);var o=e?r:t;"blob"===n.responseType?o(i.response):i.responseText?o(s()):r({message:""})}()},i.onerror=function(t){r(0===i.status?new I(e):t)},i.upload.onprogress=function(e){e.lengthComputable&&(n.onProgress&&n.onProgress(e.loaded/e.total*100,e))};var u,c=n.headers;if(c)for(var a in c){var f=c[a];"string"==typeof f&&i.setRequestHeader(a,f)}if(void 0!==n.withCredentials&&(i.withCredentials=n.withCredentials),n.file){if((u=new FormData).append("file",n.file),n.data)for(var h in u)u.append(h,u[h])}else u=n.data?"string"==typeof n.data?n.data:JSON.stringify(n.data):null;o&&o((function(){i.abort()})),i.send(u)};var N=/\{ *([\w_-]+) *\}/g;function S(e,t){return e.replace(N,(function(e,n){var r=t[n];if(void 0===r)throw new Error("No value provided for letiable "+e);return"function"==typeof r&&(r=r(t)),r}))}var A=function(e){function n(t){var r=e.call(this,t)||this;return r.name="ResourceNotFoundError",r.exception="nextgisweb.resource.exception.ResourceNotFound",Object.setPrototypeOf(r,n.prototype),r}return t(n,e),n}(F),U=function(e){function n(t){var r=e.call(this,t)||this;return r.name="InsufficientPermissionsError",r.exception="nextgisweb.core.exception.InsufficientPermissions",Object.setPrototypeOf(r,n.prototype),r}return t(n,e),n}(F),M=[];function q(e){M.push(e)}function H(e){return"[object Object]"===Object.prototype.toString.call(e)}function B(e,t){void 0===t&&(t=""),t=t?t+"__":"";var n={};return Object.entries(e).forEach((function(e){var r=e[0],o=e[1];if(H(o)){var i=B(o,r);Object.assign(n,i)}else L(o)&&(n[t+r]=o)})),n}var D=function(){function e(e){this.connector=e,this.cache=new k}return e.prototype.getOne=function(e,t){var n=this;return(new k).add("resource",(function(){return"string"==typeof e?n._fetchResourceBy({keyname:e},t):"number"==typeof e?n._fetchResourceById(e,t):H(e)?n._fetchResourceBy(e,t):C.resolve(void 0)}),{resource:e})},e.prototype.getOneOrFail=function(e){return this.getOne(e).then((function(e){if(e)return e;throw new A}))},e.prototype.getId=function(e){return"number"==typeof e?C.resolve(e):"string"==typeof e||H(e)?this.getOne(e).then((function(e){if(e)return e.resource.id})):C.resolve(void 0)},e.prototype.getIdOrFail=function(e){return this.getId(e).then((function(e){if(void 0===e)throw new Error;return e}))},e.prototype.getMany=function(e,t){var r=this;return this._resourceCacheFilter(e).then((function(o){if(!o.length){var i={};return e.keyname?i.keyname=e.keyname:Object.assign(i,B(e)),r.connector.get("resource.search",t,n({serialization:"full"},i)).then((function(e){return e&&e.forEach((function(e){r.cache.add("resource.item",C.resolve(e),{id:e.resource.id})})),e}))}return o}))},e.prototype.getParent=function(e){var t=this;return this.connector.getResource(e).then((function(e){return e?t.connector.getResource(e.resource.parent.id):C.resolve(void 0)}))},e.prototype.getChildrenOf=function(e){var t=this;return this.getId(e).then((function(e){return t.connector.get("resource.collection",{cache:!0},{parent:e}).then((function(e){for(var n=0,r=e;n<r.length;n++){var o=r[n];t.cache.add("resource.item",C.resolve(o),{id:o.resource.id})}return e}))}))},e.prototype.update=function(e,t){var n=this;return this.getId(e).then((function(e){if(void 0!==e)return n.connector.put("resource.item",{data:t},{id:e})}))},e.prototype.delete=function(e){var t=this;return this.getId(e).then((function(e){if(void 0!==e)return t.connector.delete("resource.item",null,{id:e}).then((function(){t.cache.delete("resource.item",{id:e})}))}))},e.prototype._fetchResourceById=function(e,t){var n=this;return this.cache.add("resource.item",(function(){return n.connector.get("resource.item",t,{id:e})}),{id:e}).catch((function(e){if(!(e instanceof A))throw e}))},e.prototype._fetchResourceBy=function(e,t){return this.getMany(e,t).then((function(e){return e[0]}))},e.prototype._resourceCacheFilter=function(e){return C.all(this.cache.matchAll("resource.item")).then((function(t){return t.filter((function(t){if(t)return e.keyname&&t.resource.keyname?e.keyname===t.resource.keyname:L(e.id)&&L(t.resource.id)?e.id===t.resource.id:R(e,t.resource)})),[]}))},e}();var z=0;return function(){function e(e){this.options=e,this.id=z++,this.emitter=new o.exports.EventEmitter,this.routeStr="/api/component/pyramid/route";var t=function(e){return M.find((function(t){if(t.options.baseUrl===e.baseUrl){if(!e.auth)return!0;if(t.options.auth)return R(t.options.auth,e.auth)}}))}(e);if(t)return t;this.options.route&&(this.routeStr=this.options.route),this.resources=new D(this),q(this)}return e.create=function(e){return new this(e)},e.prototype.setNgw=function(e){this.logout(),this.options.baseUrl=e,q(this)},e.prototype.connect=function(){var e=this,t=new k,n=this.options.auth;return t.add("route",(function(){return new C((function(t,r){var o=function(){return e.makeQuery(e.routeStr,{},{}).then((function(e){t(e)})).catch((function(e){r(e)}))};if(n){var i=n.login,s=n.password;if(i&&s)return e.getUserInfo({login:i,password:s}).then((function(){o()})).catch((function(e){return r(e)}))}return o()}))}),{id:this.id,auth:n,baseUrl:this.options.baseUrl})},e.prototype.login=function(e){return this.logout(),q(this),this.getUserInfo(e)},e.prototype.logout=function(){var e;-1!==(e=M.indexOf(this))&&M.splice(e,1),this.options.auth=void 0,this.user=void 0,this.emitter.emit("logout"),this.resources.cache.clean()},e.prototype.getUserInfo=function(e){var t=this;if(this.user&&this.user.id)return C.resolve(this.user);e&&(this.options.auth=e);var n={headers:this.getAuthorizationHeaders(e)};return this.makeQuery("/api/component/auth/current_user",{},n).then((function(e){return t.user=e,t.emitter.emit("login",e),e})).catch((function(e){throw t.emitter.emit("login:error",e),e}))},e.prototype.getAuthorizationHeaders=function(e){var t=this.makeClientId(e);if(t)return{Authorization:"Basic "+t}},e.prototype.makeClientId=function(e){if(e=e||this.options.auth){var t=unescape(encodeURIComponent(e.login+":"+e.password));return window.btoa(t)}},e.prototype.apiRequest=function(e,t,r){var o=this;void 0===t&&(t={}),void 0===r&&(r={});var i=r.method,s=r.headers,u=r.withCredentials,c=r.responseType,a=x(t),f=function(){return function(e){var t=e.params;return new C((function(n,r){e.connector.connect().then((function(o){var i=o&&o[e.name];if(i){var s=(i=function(e,t){for(var n=0,r=t.length,o=e.length;n<r;n++,o++)e[o]=t[n];return e}([],i)).shift();if(i.length){for(var u={},c=0;c<i.length;c++){var a=i[c];if(u[c]="{"+a+"}",void 0===t[a])throw new Error("`"+a+"` url api argument is not specified")}s&&(s=S(s,u))}if(t){var f=[],h=t.paramList;for(var p in Array.isArray(h)&&(delete t.paramList,h.forEach((function(e){f.push(e[0]+"="+e[1])}))),t)-1===i.indexOf(p)&&f.push(p+"="+t[p]);f.length&&(s=s+"?"+f.join("&"))}s?n(e.connector.makeQuery(s,t,e.requestOptions)):r(new Error("request url is not set"))}else n(void 0)})).catch((function(e){r(e)}))}))}({name:e,params:a,requestOptions:r,connector:o})};return r.cache&&"GET"===i?(new k).add(e,f,n({params:a},x({headers:s,withCredentials:u,responseType:c,baseUrl:this.options.baseUrl,auth:this.options.auth}))):f()},e.prototype.post=function(e,t,n){return(t=t||{}).method="POST",this.apiRequest(e,n,t)},e.prototype.get=function(e,t,n){return(t=t||{}).method="GET",this.apiRequest(e,n,t)},e.prototype.patch=function(e,t,n){return(t=t||{}).method="PATCH",this.apiRequest(e,n,t)},e.prototype.put=function(e,t,n){return(t=t||{}).method="PUT",this.apiRequest(e,n,t)},e.prototype.delete=function(e,t,n){return(t=t||{}).method="DELETE",this.apiRequest(e,n,t)},e.prototype.makeQuery=function(e,t,n){if(void 0===n&&(n={}),e=(this.options.baseUrl?this.options.baseUrl:"")+e)return t&&(e=S(e,t)),e=function(e){return e.replace(/([^:]\/)\/+/g,"$1")}(e),this._loadData(e,n);throw new Error("Empty `url` not allowed")},e.prototype.getResource=function(e){return this.resources.getOne(e)},e.prototype.getResourceOrFail=function(e){return this.resources.getOneOrFail(e)},e.prototype.getResourceBy=function(e){return this.resources.getOne(e)},e.prototype.getResourceByKeyname=function(e){return this.resources.getOne(e)},e.prototype.getResourceById=function(e){return this.resources.getOne(e)},e.prototype.getResourceId=function(e){return this.resources.getId(e)},e.prototype.getResourceIdOrFail=function(e){return this.resources.getIdOrFail(e)},e.prototype.getResourcesBy=function(e){return this.resources.getMany(e)},e.prototype.getResourceParent=function(e){return this.resources.getParent(e)},e.prototype.getResourceChildren=function(e){return this.resources.getChildrenOf(e)},e.prototype.updateResource=function(e,t){return this.resources.update(e,t)},e.prototype.deleteResource=function(e){return this.resources.delete(e)},e.prototype._loadData=function(e,t){var r=this;return t.responseType=t.responseType||"json",new C((function(o,i,s){r.user&&((t=t||{}).headers=n(n({},r.getAuthorizationHeaders()),t.headers)),T(e,o,t,i,s)})).catch((function(e){if(e instanceof C.CancelError);else{var t=r._handleHttpError(e);if(t)throw t}}))},e.prototype._handleHttpError=function(e){if(e&&e instanceof F){if("nextgisweb.resource.exception.ResourceNotFound"===e.exception)throw new A(e);if("nextgisweb.core.exception.InsufficientPermissions"===e.exception)throw new U(e)}return e},e.errors={NgwError:F,ResourceNotFoundError:A},e}()}();
15
+ ***************************************************************************** */var e=function(t,n){return(e=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,t){e.__proto__=t}||function(e,t){for(var n in t)Object.prototype.hasOwnProperty.call(t,n)&&(e[n]=t[n])})(t,n)};function t(t,n){if("function"!=typeof n&&null!==n)throw new TypeError("Class extends value "+String(n)+" is not a constructor or null");function r(){this.constructor=t}e(t,n),t.prototype=null===n?Object.create(n):(r.prototype=n.prototype,new r)}var n=function(){return(n=Object.assign||function(e){for(var t,n=1,r=arguments.length;n<r;n++)for(var o in t=arguments[n])Object.prototype.hasOwnProperty.call(t,o)&&(e[o]=t[o]);return e}).apply(this,arguments)};var r,o={exports:{}},i="object"==typeof Reflect?Reflect:null,s=i&&"function"==typeof i.apply?i.apply:function(e,t,n){return Function.prototype.apply.call(e,t,n)};r=i&&"function"==typeof i.ownKeys?i.ownKeys:Object.getOwnPropertySymbols?function(e){return Object.getOwnPropertyNames(e).concat(Object.getOwnPropertySymbols(e))}:function(e){return Object.getOwnPropertyNames(e)};var u=Number.isNaN||function(e){return e!=e};function c(){c.init.call(this)}o.exports=c,o.exports.once=function(e,t){return new Promise((function(n,r){function o(n){e.removeListener(t,i),r(n)}function i(){"function"==typeof e.removeListener&&e.removeListener("error",o),n([].slice.call(arguments))}g(e,t,i,{once:!0}),"error"!==t&&function(e,t,n){"function"==typeof e.on&&g(e,"error",t,n)}(e,o,{once:!0})}))},c.EventEmitter=c,c.prototype._events=void 0,c.prototype._eventsCount=0,c.prototype._maxListeners=void 0;var a=10;function f(e){if("function"!=typeof e)throw new TypeError('The "listener" argument must be of type Function. Received type '+typeof e)}function h(e){return void 0===e._maxListeners?c.defaultMaxListeners:e._maxListeners}function p(e,t,n,r){var o,i,s,u;if(f(n),void 0===(i=e._events)?(i=e._events=Object.create(null),e._eventsCount=0):(void 0!==i.newListener&&(e.emit("newListener",t,n.listener?n.listener:n),i=e._events),s=i[t]),void 0===s)s=i[t]=n,++e._eventsCount;else if("function"==typeof s?s=i[t]=r?[n,s]:[s,n]:r?s.unshift(n):s.push(n),(o=h(e))>0&&s.length>o&&!s.warned){s.warned=!0;var c=new Error("Possible EventEmitter memory leak detected. "+s.length+" "+String(t)+" listeners added. Use emitter.setMaxListeners() to increase limit");c.name="MaxListenersExceededWarning",c.emitter=e,c.type=t,c.count=s.length,u=c,console&&console.warn&&console.warn(u)}return e}function l(){if(!this.fired)return this.target.removeListener(this.type,this.wrapFn),this.fired=!0,0===arguments.length?this.listener.call(this.target):this.listener.apply(this.target,arguments)}function d(e,t,n){var r={fired:!1,wrapFn:void 0,target:e,type:t,listener:n},o=l.bind(r);return o.listener=n,r.wrapFn=o,o}function v(e,t,n){var r=e._events;if(void 0===r)return[];var o=r[t];return void 0===o?[]:"function"==typeof o?n?[o.listener||o]:[o]:n?function(e){for(var t=new Array(e.length),n=0;n<t.length;++n)t[n]=e[n].listener||e[n];return t}(o):m(o,o.length)}function y(e){var t=this._events;if(void 0!==t){var n=t[e];if("function"==typeof n)return 1;if(void 0!==n)return n.length}return 0}function m(e,t){for(var n=new Array(t),r=0;r<t;++r)n[r]=e[r];return n}function g(e,t,n,r){if("function"==typeof e.on)r.once?e.once(t,n):e.on(t,n);else{if("function"!=typeof e.addEventListener)throw new TypeError('The "emitter" argument must be of type EventEmitter. Received type '+typeof e);e.addEventListener(t,(function o(i){r.once&&e.removeEventListener(t,o),n(i)}))}}Object.defineProperty(c,"defaultMaxListeners",{enumerable:!0,get:function(){return a},set:function(e){if("number"!=typeof e||e<0||u(e))throw new RangeError('The value of "defaultMaxListeners" is out of range. It must be a non-negative number. Received '+e+".");a=e}}),c.init=function(){void 0!==this._events&&this._events!==Object.getPrototypeOf(this)._events||(this._events=Object.create(null),this._eventsCount=0),this._maxListeners=this._maxListeners||void 0},c.prototype.setMaxListeners=function(e){if("number"!=typeof e||e<0||u(e))throw new RangeError('The value of "n" is out of range. It must be a non-negative number. Received '+e+".");return this._maxListeners=e,this},c.prototype.getMaxListeners=function(){return h(this)},c.prototype.emit=function(e){for(var t=[],n=1;n<arguments.length;n++)t.push(arguments[n]);var r="error"===e,o=this._events;if(void 0!==o)r=r&&void 0===o.error;else if(!r)return!1;if(r){var i;if(t.length>0&&(i=t[0]),i instanceof Error)throw i;var u=new Error("Unhandled error."+(i?" ("+i.message+")":""));throw u.context=i,u}var c=o[e];if(void 0===c)return!1;if("function"==typeof c)s(c,this,t);else{var a=c.length,f=m(c,a);for(n=0;n<a;++n)s(f[n],this,t)}return!0},c.prototype.on=c.prototype.addListener=function(e,t){return p(this,e,t,!1)},c.prototype.prependListener=function(e,t){return p(this,e,t,!0)},c.prototype.once=function(e,t){return f(t),this.on(e,d(this,e,t)),this},c.prototype.prependOnceListener=function(e,t){return f(t),this.prependListener(e,d(this,e,t)),this},c.prototype.off=c.prototype.removeListener=function(e,t){var n,r,o,i,s;if(f(t),void 0===(r=this._events))return this;if(void 0===(n=r[e]))return this;if(n===t||n.listener===t)0==--this._eventsCount?this._events=Object.create(null):(delete r[e],r.removeListener&&this.emit("removeListener",e,n.listener||t));else if("function"!=typeof n){for(o=-1,i=n.length-1;i>=0;i--)if(n[i]===t||n[i].listener===t){s=n[i].listener,o=i;break}if(o<0)return this;0===o?n.shift():function(e,t){for(;t+1<e.length;t++)e[t]=e[t+1];e.pop()}(n,o),1===n.length&&(r[e]=n[0]),void 0!==r.removeListener&&this.emit("removeListener",e,s||t)}return this},c.prototype.removeAllListeners=function(e){var t,n,r;if(void 0===(n=this._events))return this;if(void 0===n.removeListener)return 0===arguments.length?(this._events=Object.create(null),this._eventsCount=0):void 0!==n[e]&&(0==--this._eventsCount?this._events=Object.create(null):delete n[e]),this;if(0===arguments.length){var o,i=Object.keys(n);for(r=0;r<i.length;++r)"removeListener"!==(o=i[r])&&this.removeAllListeners(o);return this.removeAllListeners("removeListener"),this._events=Object.create(null),this._eventsCount=0,this}if("function"==typeof(t=n[e]))this.removeListener(e,t);else if(void 0!==t)for(r=t.length-1;r>=0;r--)this.removeListener(e,t[r]);return this},c.prototype.listeners=function(e){return v(this,e,!0)},c.prototype.rawListeners=function(e){return v(this,e,!1)},c.listenerCount=function(e,t){return"function"==typeof e.listenerCount?e.listenerCount(t):y.call(e,t)},c.prototype.listenerCount=y,c.prototype.eventNames=function(){return this._eventsCount>0?r(this._events):[]};var _=function(e){function n(){var t=e.call(this)||this;return t.name="CancelError",Object.setPrototypeOf(t,n.prototype),t}return t(n,e),n}(Error),w=function(){function e(e){void 0===e&&(e={}),this.options=e,this._promises=new Map}return Object.defineProperty(e.prototype,"isLoaded",{get:function(){return this._promises.size>0},enumerable:!1,configurable:!0}),e.prototype.remove=function(e){this._promises.has(e)&&(this._promises.delete(e),this._onStop())},e.prototype.get=function(e){return this._promises.get(e)},e.prototype.add=function(e,t){var n=this,r=t||e,o=this._promises.get(r);return this.options.onStart&&!this.isLoaded&&this.options.onStart(),o||(this._promises.set(r,e),e.finally((function(){n.remove(r)})),e)},e.prototype.abort=function(){this.isLoaded&&(this._promises.forEach((function(e){e.cancel&&e.cancel()})),this._promises.clear(),this._onStop())},e.prototype.waitFunc=function(e,t){void 0===t&&(t="");var n=this.get(t=t||e.name);return n||this.add(e(),t)},e.prototype.WaitForMe=function(e){void 0===e&&(e="");var t=this.get.bind(this),n=this.add.bind(this);return function(r,o,i){var s=i.value;return e=e||o,i.value=function(){for(var r=[],o=0;o<arguments.length;o++)r[o]=arguments[o];var i=t(e);if(i)return i;var u=n(s.apply(this,r),e);return u},i}},e.prototype.GetOrCreateDecorator=function(e){return void 0===e&&(e=""),this.WaitForMe(e)},e.prototype._onStop=function(){this.options.onStop&&!this.isLoaded&&this.options.onStop()},e}(),b=function(e){function n(){var t=e.call(this)||this;return t.name="TimeoutError",Object.setPrototypeOf(t,n.prototype),t}return t(n,e),n}(Error),O=function(e,t,n,r){try{e(n(r))}catch(e){t(e)}},E=0,P=function(){function e(t,n){var r=this;this.id=E++,this._isCanceled=!1,this._isPending=!0,this._cancelHandlers=[],this._children=[],this._cancelPromise=new Promise((function(e,t){r._setCanceledCallback=function(t){return e(t||new _)}}));var o=[this._cancelPromise,new Promise((function(n,o){return t((function(t){t instanceof e?r.attach(t):r._isPending=!1,n(t)}),(function(e){r._isPending=!1,o(e)}),(function(e){if(!r._isPending)throw new Error("The `onCancel` handler was attached after the promise settled.");r._cancelHandlers.push(e)}))}))];n&&o.push(new Promise((function(e,t){setTimeout((function(){if(r._isPending)try{r.cancel()}finally{t(new b)}}),n)}))),this._promise=Promise.race(o)}return e.createControl=function(e){return new w(e)},e.resolve=function(t){return new e((function(e){return e(t)}))},e.reject=function(t){return new e((function(e,n){return n(t)}))},e.all=function(t){var n=this;return new e((function(e,n){Promise.all(t).then(e).catch(n)})).catch((function(e){if(e instanceof n.CancelError)for(var r=0,o=t;r<o.length;r++){var i=o[r];"cancel"in i&&i.cancel()}throw e}))},e.prototype.attach=function(e){this._isCanceled?e.cancel():this._children.push(e)},e.prototype.then=function(t,n){var r=this,o=new e((function(e,o){if(r._promise){var i=function(t){n?O(e,o,n,t):o(t)};r._promise.then((function(n){r._isCanceled?i(n):t?O(e,o,t,n):e(n)}),i)}}));return o._parentPromise=this,this._children.push(o),o},e.prototype.catch=function(e){return this._isCanceled&&e&&e(new _),this.then(void 0,e)},e.prototype.finally=function(e){return this._promise?this._promise.finally(e):Promise.reject(this._isCanceled?new _:e)},e.prototype.cancel=function(){if(this._isCanceled||!this._isPending)return this;this._isCanceled=!0;var e=this._getTopParent();if(e&&e.cancel(),this._children&&this._children.forEach((function(e){return e.cancel()})),this._isPending){if(this._cancelHandlers.length)try{for(var t=0,n=this._cancelHandlers;t<n.length;t++){(0,n[t])()}}catch(e){}this._setCanceledCallback&&this._setCanceledCallback()}return this._destroy(),this},e.prototype._getTopParent=function(){for(var e=this._parentPromise,t=!!e;t;)t=!(!e||!e._parentPromise)&&!!(e=e._parentPromise);return e},e.prototype._destroy=function(){this._setCanceledCallback=void 0,this._cancelPromise=void 0,this._promise=void 0},e.CancelError=_,e.TimeoutError=b,e.PromiseControl=w,e}();Object.setPrototypeOf(P.prototype,Promise.prototype);var C=P;function L(e){return null!=e}function j(e,t,n,r){if(e instanceof Array)return t instanceof Array&&t.sort().join("")===e.sort().join("");if(e instanceof Date)return t instanceof Date&&""+e==""+t;if(e instanceof Function){if(!(t instanceof Function))return!1}else if(e instanceof Object)return t instanceof Object&&(e===n?t===r:R(e,t));return e===t}function R(e,t){var n=Object.keys(e).sort(),r=Object.keys(t).sort();if(n.length!==r.length)return!1;if(n.join("")!==r.join(""))return!1;for(var o=0;o<n.length;o++){if(!j(e[n[o]],t[r[o]],e,t))return!1}return!0}function x(e){var t={};return Object.keys(e).forEach((function(n){e[n]instanceof Array||e[n]!==Object(e[n])?void 0!==e[n]&&(t[n]=e[n]):t[n]=x(e[n])})),t}var T,k=function(){function e(){return this.cache=[],e.instance?e.instance:(e.instance=this,this)}return e.prototype.clean=function(){this.cache.length=0},e.prototype.all=function(){return this.cache},e.prototype.add=function(e,t,n){var r=this,o=this._find(e,n);if(o)return o.value;var i=void 0;i=t instanceof Function?t():t;var s=n&&JSON.parse(JSON.stringify(x(n)));return this.cache.push({key:e,value:i,options:s}),i instanceof Promise?(i.catch((function(t){throw r.delete(e,n),t})),i):i},e.prototype.match=function(e,t){var n=this._find(e,t);if(n)return n.value},e.prototype.matchAll=function(e,t){var n=this;return e?this.cache.filter((function(r){return n._filter(r,e,t)})).map((function(e){return e.value})):this.cache.map((function(e){return e.value}))},e.prototype.delete=function(e,t){for(var n=this,r=0,o=this.cache.filter((function(r){return n._filter(r,e,t)}));r<o.length;r++){var i=this.cache.indexOf(o[r]);this.cache.splice(i,1)}},e.prototype._find=function(e,t){var n=this;return this.cache.find((function(r){return n._filter(r,e,t)}))},e.prototype._filter=function(e,t,n){return e.key===t&&(!n||R(e.options||{},x(n)))},e}(),F=function(e){function n(t){var r=e.call(this)||this;return r.name="NgwError",Object.assign(r,t),Object.setPrototypeOf(r,n.prototype),r}return t(n,e),n}(Error),I=function(e){function n(t){var r=e.call(this)||this;return r.name="NetworkError",Object.setPrototypeOf(r,n.prototype),r.message="Unable to request "+t+".\n Possibly invalid NGW URL entered or CORS not configured to get request from "+location.origin,r}return t(n,e),n}(Error);T=function(e,t,n,r,o){void 0===n&&(n={}),n.method=n.method||"GET";var i=new XMLHttpRequest;i.open(n.method||"GET",e,!0),"blob"===n.responseType&&(i.responseType=n.responseType);var s=function(){try{return JSON.parse(i.responseText)}catch(e){return i.responseText}};i.onload=function(){-1!==[401,403,404,500].indexOf(i.status)&&r(new F(s())),function(e){void 0===e&&(e=!1);var o=e?r:t;"blob"===n.responseType?o(i.response):i.responseText?o(s()):r({message:""})}()},i.onerror=function(t){r(0===i.status?new I(e):t)},i.upload.onprogress=function(e){e.lengthComputable&&(n.onProgress&&n.onProgress(e.loaded/e.total*100,e))};var u,c=n.headers;if(c)for(var a in c){var f=c[a];"string"==typeof f&&i.setRequestHeader(a,f)}if(void 0!==n.withCredentials&&(i.withCredentials=n.withCredentials),n.file){if((u=new FormData).append("file",n.file),n.data)for(var h in u)u.append(h,u[h])}else u=n.data?"string"==typeof n.data?n.data:JSON.stringify(n.data):null;o&&o((function(){i.abort()})),i.send(u)};var N=/\{ *([\w_-]+) *\}/g;function S(e,t){return e.replace(N,(function(e,n){var r=t[n];if(void 0===r)throw new Error("No value provided for letiable "+e);return"function"==typeof r&&(r=r(t)),r}))}var A=function(e){function n(t){var r=e.call(this,t)||this;return r.name="ResourceNotFoundError",r.exception="nextgisweb.resource.exception.ResourceNotFound",Object.setPrototypeOf(r,n.prototype),r}return t(n,e),n}(F),U=function(e){function n(t){var r=e.call(this,t)||this;return r.name="InsufficientPermissionsError",r.exception="nextgisweb.core.exception.InsufficientPermissions",Object.setPrototypeOf(r,n.prototype),r}return t(n,e),n}(F),M=[];function q(e){M.push(e)}function H(e){return"[object Object]"===Object.prototype.toString.call(e)}function B(e,t){void 0===t&&(t=""),t=t?t+"__":"";var n={};return Object.entries(e).forEach((function(e){var r=e[0],o=e[1];if(H(o)){var i=B(o,r);Object.assign(n,i)}else L(o)&&(n[t+r]=o)})),n}var D=function(){function e(e){this.connector=e,this.cache=new k}return e.prototype.getOne=function(e,t){var n=this;return(new k).add("resource",(function(){return"string"==typeof e?n._fetchResourceBy({keyname:e},t):"number"==typeof e?n._fetchResourceById(e,t):H(e)?n._fetchResourceBy(e,t):C.resolve(void 0)}),{resource:e})},e.prototype.getOneOrFail=function(e,t){return this.getOne(e,t).then((function(e){if(e)return e;throw new A}))},e.prototype.getId=function(e,t){return"number"==typeof e?C.resolve(e):"string"==typeof e||H(e)?this.getOne(e,t).then((function(e){if(e)return e.resource.id})):C.resolve(void 0)},e.prototype.getIdOrFail=function(e,t){return this.getId(e,t).then((function(e){if(void 0===e)throw new Error;return e}))},e.prototype.getMany=function(e,t){var r=this;return this._resourceCacheFilter(e).then((function(o){if(!o.length){var i={};return e.keyname?i.keyname=e.keyname:Object.assign(i,B(e)),r.connector.get("resource.search",t,n({serialization:"full"},i)).then((function(e){return e&&e.forEach((function(e){r.cache.add("resource.item",C.resolve(e),{id:e.resource.id})})),e}))}return o}))},e.prototype.getParent=function(e,t){var n=this;return this.getOne(e,t).then((function(e){return e?n.getOne(e.resource.parent.id,t):C.resolve(void 0)}))},e.prototype.getChildrenOf=function(e,t){var r=this;return this.getId(e).then((function(e){return r.connector.get("resource.collection",n({cache:!0},t),{parent:e}).then((function(e){for(var t=0,n=e;t<n.length;t++){var o=n[t];r.cache.add("resource.item",C.resolve(o),{id:o.resource.id})}return e}))}))},e.prototype.update=function(e,t){var n=this;return this.getId(e).then((function(e){if(void 0!==e)return n.connector.put("resource.item",{data:t},{id:e})}))},e.prototype.delete=function(e){var t=this;return this.getId(e).then((function(e){if(void 0!==e)return t.connector.delete("resource.item",null,{id:e}).then((function(){t.cache.delete("resource.item",{id:e})}))}))},e.prototype._fetchResourceById=function(e,t){var n=this;return this.cache.add("resource.item",(function(){return n.connector.get("resource.item",t,{id:e})}),{id:e}).catch((function(e){if(!(e instanceof A))throw e}))},e.prototype._fetchResourceBy=function(e,t){return this.getMany(e,t).then((function(e){return e[0]}))},e.prototype._resourceCacheFilter=function(e){return C.all(this.cache.matchAll("resource.item")).then((function(t){return t.filter((function(t){if(t)return e.keyname&&t.resource.keyname?e.keyname===t.resource.keyname:L(e.id)&&L(t.resource.id)?e.id===t.resource.id:R(e,t.resource)})),[]}))},e}();var z=0;return function(){function e(e){this.options=e,this.id=z++,this.emitter=new o.exports.EventEmitter,this.routeStr="/api/component/pyramid/route";var t=function(e){return M.find((function(t){if(t.options.baseUrl===e.baseUrl){if(!e.auth)return!0;if(t.options.auth)return R(t.options.auth,e.auth)}}))}(e);if(t)return t;this.options.route&&(this.routeStr=this.options.route),this.resources=new D(this),q(this)}return e.create=function(e){return new this(e)},e.prototype.setNgw=function(e){this.logout(),this.options.baseUrl=e,q(this)},e.prototype.connect=function(){var e=this,t=new k,n=this.options.auth;return t.add("route",(function(){return new C((function(t,r){var o=function(){return e.makeQuery(e.routeStr,{},{}).then((function(e){t(e)})).catch((function(e){r(e)}))};if(n){var i=n.login,s=n.password;if(i&&s)return e.getUserInfo({login:i,password:s}).then((function(){o()})).catch((function(e){return r(e)}))}return o()}))}),{id:this.id,auth:n,baseUrl:this.options.baseUrl})},e.prototype.login=function(e){return this.logout(),q(this),this.getUserInfo(e)},e.prototype.logout=function(){var e;-1!==(e=M.indexOf(this))&&M.splice(e,1),this.options.auth=void 0,this.user=void 0,this.emitter.emit("logout"),this.resources.cache.clean()},e.prototype.getUserInfo=function(e){var t=this;if(this.user&&this.user.id)return C.resolve(this.user);e&&(this.options.auth=e);var n={headers:this.getAuthorizationHeaders(e)};return this.makeQuery("/api/component/auth/current_user",{},n).then((function(e){return t.user=e,t.emitter.emit("login",e),e})).catch((function(e){throw t.emitter.emit("login:error",e),e}))},e.prototype.getAuthorizationHeaders=function(e){var t=this.makeClientId(e);if(t)return{Authorization:"Basic "+t}},e.prototype.makeClientId=function(e){if(e=e||this.options.auth){var t=unescape(encodeURIComponent(e.login+":"+e.password));return window.btoa(t)}},e.prototype.apiRequest=function(e,t,r){var o=this;void 0===t&&(t={}),void 0===r&&(r={});var i=r.method,s=r.headers,u=r.withCredentials,c=r.responseType,a=x(t),f=function(){return function(e){var t=e.params;return new C((function(n,r){e.connector.connect().then((function(o){var i=o&&o[e.name];if(i){var s=(i=function(e,t){for(var n=0,r=t.length,o=e.length;n<r;n++,o++)e[o]=t[n];return e}([],i)).shift();if(i.length){for(var u={},c=0;c<i.length;c++){var a=i[c];if(u[c]="{"+a+"}",void 0===t[a])throw new Error("`"+a+"` url api argument is not specified")}s&&(s=S(s,u))}if(t){var f=[],h=t.paramList;for(var p in Array.isArray(h)&&(delete t.paramList,h.forEach((function(e){f.push(e[0]+"="+e[1])}))),t)-1===i.indexOf(p)&&f.push(p+"="+t[p]);f.length&&(s=s+"?"+f.join("&"))}s?n(e.connector.makeQuery(s,t,e.requestOptions)):r(new Error("request url is not set"))}else n(void 0)})).catch((function(e){r(e)}))}))}({name:e,params:a,requestOptions:r,connector:o})};return r.cache&&"GET"===i?(new k).add(e,f,n({params:a},x({headers:s,withCredentials:u,responseType:c,baseUrl:this.options.baseUrl,auth:this.options.auth}))):f()},e.prototype.post=function(e,t,n){return(t=t||{}).method="POST",this.apiRequest(e,n,t)},e.prototype.get=function(e,t,n){return(t=t||{}).method="GET",this.apiRequest(e,n,t)},e.prototype.patch=function(e,t,n){return(t=t||{}).method="PATCH",this.apiRequest(e,n,t)},e.prototype.put=function(e,t,n){return(t=t||{}).method="PUT",this.apiRequest(e,n,t)},e.prototype.delete=function(e,t,n){return(t=t||{}).method="DELETE",this.apiRequest(e,n,t)},e.prototype.makeQuery=function(e,t,n){if(void 0===n&&(n={}),e=(this.options.baseUrl?this.options.baseUrl:"")+e)return t&&(e=S(e,t)),e=function(e){return e.replace(/([^:]\/)\/+/g,"$1")}(e),this._loadData(e,n);throw new Error("Empty `url` not allowed")},e.prototype.getResource=function(e,t){return this.resources.getOne(e,t)},e.prototype.getResourceOrFail=function(e,t){return this.resources.getOneOrFail(e,t)},e.prototype.getResourceBy=function(e){return this.resources.getOne(e)},e.prototype.getResourceByKeyname=function(e){return this.resources.getOne(e)},e.prototype.getResourceById=function(e){return this.resources.getOne(e)},e.prototype.getResourceId=function(e,t){return this.resources.getId(e,t)},e.prototype.getResourceIdOrFail=function(e,t){return this.resources.getIdOrFail(e,t)},e.prototype.getResourcesBy=function(e,t){return this.resources.getMany(e,t)},e.prototype.getResourceParent=function(e,t){return this.resources.getParent(e,t)},e.prototype.getResourceChildren=function(e,t){return this.resources.getChildrenOf(e,t)},e.prototype.updateResource=function(e,t){return this.resources.update(e,t)},e.prototype.deleteResource=function(e){return this.resources.delete(e)},e.prototype._loadData=function(e,t){var r=this;return t.responseType=t.responseType||"json",new C((function(o,i,s){r.user&&((t=t||{}).headers=n(n({},r.getAuthorizationHeaders()),t.headers)),T(e,o,t,i,s)})).catch((function(e){if(e instanceof C.CancelError);else{var t=r._handleHttpError(e);if(t)throw t}}))},e.prototype._handleHttpError=function(e){if(e&&e instanceof F){if("nextgisweb.resource.exception.ResourceNotFound"===e.exception)throw new A(e);if("nextgisweb.core.exception.InsufficientPermissions"===e.exception)throw new U(e)}return e},e.errors={NgwError:F,ResourceNotFoundError:A},e}()}();
16
16
  //# sourceMappingURL=ngw-connector.global.prod.js.map