@nextgis/geocoder 1.12.0 → 1.13.5

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/index.js CHANGED
@@ -1,7 +1,7 @@
1
1
  'use strict';
2
2
 
3
- if (process.env.NODE_ENV === 'production') {
4
- module.exports = require('./lib/geocoder.cjs.prod.js');
5
- } else {
3
+ if (process.env.NODE_ENV === 'development') {
6
4
  module.exports = require('./lib/geocoder.cjs.js');
5
+ } else {
6
+ module.exports = require('./lib/geocoder.cjs.prod.js');
7
7
  }
@@ -1,4 +1,4 @@
1
- /** Bundle of @nextgis/geocoder; version: 1.12.0; author: NextGIS */
1
+ /** Bundle of @nextgis/geocoder; version: 1.13.5; author: NextGIS */
2
2
  'use strict';
3
3
 
4
4
  Object.defineProperty(exports, '__esModule', { value: true });
@@ -1,4 +1,4 @@
1
- /** Bundle of @nextgis/geocoder; version: 1.12.0; author: NextGIS */
1
+ /** Bundle of @nextgis/geocoder; version: 1.13.5; author: NextGIS */
2
2
  /*! *****************************************************************************
3
3
  Copyright (c) Microsoft Corporation.
4
4
 
@@ -1370,31 +1370,31 @@ var Cache = Cache$1;
1370
1370
  /**
1371
1371
  * Thrown when...
1372
1372
  */
1373
- var NgwError = /** @class */ (function (_super) {
1374
- __extends(NgwError, _super);
1375
- function NgwError(er) {
1373
+ var NetworkError = /** @class */ (function (_super) {
1374
+ __extends(NetworkError, _super);
1375
+ function NetworkError(url) {
1376
1376
  var _this = _super.call(this) || this;
1377
- _this.name = 'NgwError';
1378
- Object.assign(_this, er);
1379
- Object.setPrototypeOf(_this, NgwError.prototype);
1377
+ _this.name = 'NetworkError';
1378
+ Object.setPrototypeOf(_this, NetworkError.prototype);
1379
+ _this.message = "Unable to request ".concat(url, ".\n Possibly invalid NGW URL entered or CORS not configured to get request from ").concat(location.origin); // /control-panel/cors
1380
1380
  return _this;
1381
1381
  }
1382
- return NgwError;
1382
+ return NetworkError;
1383
1383
  }(Error));
1384
1384
 
1385
1385
  /**
1386
1386
  * Thrown when...
1387
1387
  */
1388
- var NetworkError = /** @class */ (function (_super) {
1389
- __extends(NetworkError, _super);
1390
- function NetworkError(url) {
1388
+ var NgwError = /** @class */ (function (_super) {
1389
+ __extends(NgwError, _super);
1390
+ function NgwError(er) {
1391
1391
  var _this = _super.call(this) || this;
1392
- _this.name = 'NetworkError';
1393
- Object.setPrototypeOf(_this, NetworkError.prototype);
1394
- _this.message = "Unable to request ".concat(url, ".\n Possibly invalid NGW URL entered or CORS not configured to get request from ").concat(location.origin); // /control-panel/cors
1392
+ _this.name = 'NgwError';
1393
+ Object.assign(_this, er);
1394
+ Object.setPrototypeOf(_this, NgwError.prototype);
1395
1395
  return _this;
1396
1396
  }
1397
- return NetworkError;
1397
+ return NgwError;
1398
1398
  }(Error));
1399
1399
 
1400
1400
  function isObject(val) {
@@ -1649,7 +1649,12 @@ var ResourcesControl = /** @class */ (function () {
1649
1649
  forCache.id = resource;
1650
1650
  }
1651
1651
  else if (isObject(resource)) {
1652
- forCache.id = resource.id;
1652
+ if (resource.id !== undefined) {
1653
+ forCache.id = resource.id;
1654
+ }
1655
+ else if (resource.keyname) {
1656
+ forCache.keyname = resource.keyname;
1657
+ }
1653
1658
  }
1654
1659
  var makeRequest = function () {
1655
1660
  if (typeof resource === 'string') {
@@ -1751,20 +1756,35 @@ var ResourcesControl = /** @class */ (function () {
1751
1756
  };
1752
1757
  ResourcesControl.prototype.getChildrenOf = function (resource, requestOptions) {
1753
1758
  var _this = this;
1754
- return this.getId(resource).then(function (parent) {
1755
- return _this.connector
1756
- .get('resource.collection', __assign({ cache: true }, requestOptions), {
1757
- parent: parent,
1758
- })
1759
- .then(function (items) {
1760
- for (var _i = 0, items_1 = items; _i < items_1.length; _i++) {
1761
- var i = items_1[_i];
1762
- _this.cache.add('resource.item', CancelablePromise.resolve(i), {
1763
- id: i.resource.id,
1764
- });
1759
+ return this.getIdOrFail(resource).then(function (parent) {
1760
+ return _this._getChildrenOf(parent, requestOptions);
1761
+ });
1762
+ };
1763
+ ResourcesControl.prototype._getChildrenOf = function (parent, requestOptions, _items) {
1764
+ var _this = this;
1765
+ if (_items === void 0) { _items = []; }
1766
+ return this.connector
1767
+ .get('resource.collection', __assign({ cache: true }, requestOptions), {
1768
+ parent: parent,
1769
+ })
1770
+ .then(function (items) {
1771
+ var recursivePromises = [];
1772
+ for (var _i = 0, items_1 = items; _i < items_1.length; _i++) {
1773
+ var item = items_1[_i];
1774
+ _this.cache.add('resource.item', CancelablePromise.resolve(item), {
1775
+ id: item.resource.id,
1776
+ });
1777
+ _items.push(item);
1778
+ if ((requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.recursive) && item.resource.children) {
1779
+ recursivePromises.push(_this._getChildrenOf(item.resource.id, requestOptions, _items));
1765
1780
  }
1766
- return items;
1767
- });
1781
+ }
1782
+ if (recursivePromises.length) {
1783
+ return CancelablePromise.all(recursivePromises).then(function () {
1784
+ return _items;
1785
+ });
1786
+ }
1787
+ return _items;
1768
1788
  });
1769
1789
  };
1770
1790
  ResourcesControl.prototype.update = function (resource, data) {
@@ -1938,6 +1958,7 @@ var NgwConnector$1 = /** @class */ (function () {
1938
1958
  this.id = ID++;
1939
1959
  this.emitter = new events.exports.EventEmitter();
1940
1960
  this.routeStr = '/api/component/pyramid/route';
1961
+ this.activeRequests = [];
1941
1962
  var exist = findConnector(options);
1942
1963
  if (exist) {
1943
1964
  return exist;
@@ -2023,6 +2044,7 @@ var NgwConnector$1 = /** @class */ (function () {
2023
2044
  * Disconnecting a user. Aborting all current requests
2024
2045
  */
2025
2046
  NgwConnector.prototype.logout = function () {
2047
+ this.abort();
2026
2048
  removeConnector(this);
2027
2049
  this.options.auth = undefined;
2028
2050
  this.user = undefined;
@@ -2075,6 +2097,17 @@ var NgwConnector$1 = /** @class */ (function () {
2075
2097
  }
2076
2098
  }
2077
2099
  };
2100
+ /** Stop all api requests */
2101
+ NgwConnector.prototype.abort = function () {
2102
+ for (var _i = 0, _a = this.activeRequests; _i < _a.length; _i++) {
2103
+ var req = _a[_i];
2104
+ req.cancel();
2105
+ }
2106
+ this.activeRequests = [];
2107
+ };
2108
+ NgwConnector.prototype.getActiveApiRequests = function () {
2109
+ return __spreadArray([], this.activeRequests, true);
2110
+ };
2078
2111
  /**
2079
2112
  * Send request to NGW api router.
2080
2113
  * @param name - NGW route name from {@link https://docs.nextgis.com/docs_ngweb_dev/doc/developer/resource.html#routes | routes}
@@ -2289,14 +2322,20 @@ var NgwConnector$1 = /** @class */ (function () {
2289
2322
  NgwConnector.prototype._loadData = function (url, options) {
2290
2323
  var _this = this;
2291
2324
  options.responseType = options.responseType || 'json';
2292
- return new CancelablePromise(function (resolve, reject, onCancel) {
2325
+ var request = new CancelablePromise(function (resolve, reject, onCancel) {
2293
2326
  if (_this.user) {
2294
2327
  options = options || {};
2295
2328
  // options.withCredentials = true;
2296
2329
  options.headers = __assign(__assign({}, _this.getAuthorizationHeaders()), options.headers);
2297
2330
  }
2298
2331
  loadData(url, resolve, options, reject, onCancel);
2299
- }).catch(function (httpError) {
2332
+ })
2333
+ .then(function (resp) {
2334
+ _this._cleanActiveRequests(request);
2335
+ return resp;
2336
+ })
2337
+ .catch(function (httpError) {
2338
+ _this._cleanActiveRequests(request);
2300
2339
  if (httpError instanceof CancelablePromise.CancelError) ;
2301
2340
  else {
2302
2341
  // @ts-ignore
@@ -2309,6 +2348,20 @@ var NgwConnector$1 = /** @class */ (function () {
2309
2348
  }
2310
2349
  }
2311
2350
  });
2351
+ if (options.signal &&
2352
+ typeof options.signal.addEventListener === 'function') {
2353
+ options.signal.addEventListener('abort', function () {
2354
+ request.cancel();
2355
+ });
2356
+ }
2357
+ this.activeRequests.push(request);
2358
+ return request;
2359
+ };
2360
+ NgwConnector.prototype._cleanActiveRequests = function (request) {
2361
+ var activeRequestIndex = this.activeRequests.indexOf(request);
2362
+ if (activeRequestIndex !== -1) {
2363
+ this.activeRequests.splice(activeRequestIndex, 1);
2364
+ }
2312
2365
  };
2313
2366
  NgwConnector.prototype._handleHttpError = function (er) {
2314
2367
  if (er) {