@nextgis/geocoder 2.1.1 → 2.3.0

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.
@@ -1,10 +1,7 @@
1
- /** Bundle of @nextgis/geocoder; version: 2.1.1; author: NextGIS */
1
+ /** Bundle of @nextgis/geocoder; version: 2.3.0; author: NextGIS */
2
2
  var __defProp$g = Object.defineProperty;
3
3
  var __defNormalProp$g = (obj, key, value) => key in obj ? __defProp$g(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
4
- var __publicField$e = (obj, key, value) => {
5
- __defNormalProp$g(obj, typeof key !== "symbol" ? key + "" : key, value);
6
- return value;
7
- };
4
+ var __publicField$e = (obj, key, value) => __defNormalProp$g(obj, typeof key !== "symbol" ? key + "" : key, value);
8
5
  class CancelError extends Error {
9
6
  constructor() {
10
7
  super();
@@ -15,10 +12,7 @@ class CancelError extends Error {
15
12
 
16
13
  var __defProp$f = Object.defineProperty;
17
14
  var __defNormalProp$f = (obj, key, value) => key in obj ? __defProp$f(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
18
- var __publicField$d = (obj, key, value) => {
19
- __defNormalProp$f(obj, typeof key !== "symbol" ? key + "" : key, value);
20
- return value;
21
- };
15
+ var __publicField$d = (obj, key, value) => __defNormalProp$f(obj, typeof key !== "symbol" ? key + "" : key, value);
22
16
  class PromiseControl {
23
17
  constructor(options = {}) {
24
18
  this.options = options;
@@ -100,10 +94,7 @@ class PromiseControl {
100
94
 
101
95
  var __defProp$e = Object.defineProperty;
102
96
  var __defNormalProp$e = (obj, key, value) => key in obj ? __defProp$e(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
103
- var __publicField$c = (obj, key, value) => {
104
- __defNormalProp$e(obj, typeof key !== "symbol" ? key + "" : key, value);
105
- return value;
106
- };
97
+ var __publicField$c = (obj, key, value) => __defNormalProp$e(obj, typeof key !== "symbol" ? key + "" : key, value);
107
98
  class TimeoutError extends Error {
108
99
  constructor() {
109
100
  super();
@@ -114,10 +105,7 @@ class TimeoutError extends Error {
114
105
 
115
106
  var __defProp$d = Object.defineProperty;
116
107
  var __defNormalProp$d = (obj, key, value) => key in obj ? __defProp$d(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
117
- var __publicField$b = (obj, key, value) => {
118
- __defNormalProp$d(obj, typeof key !== "symbol" ? key + "" : key, value);
119
- return value;
120
- };
108
+ var __publicField$b = (obj, key, value) => __defNormalProp$d(obj, typeof key !== "symbol" ? key + "" : key, value);
121
109
  var _a;
122
110
  const handleCallback = (resolve, reject, callback, r) => {
123
111
  try {
@@ -127,6 +115,7 @@ const handleCallback = (resolve, reject, callback, r) => {
127
115
  }
128
116
  };
129
117
  let ID$2 = 0;
118
+ _a = Symbol.toStringTag;
130
119
  const _CancelablePromise = class _CancelablePromise {
131
120
  constructor(executor, timeout) {
132
121
  // @ts-ignore
@@ -306,7 +295,6 @@ const _CancelablePromise = class _CancelablePromise {
306
295
  this._promise = void 0;
307
296
  }
308
297
  };
309
- _a = Symbol.toStringTag;
310
298
  __publicField$b(_CancelablePromise, "CancelError", CancelError);
311
299
  __publicField$b(_CancelablePromise, "TimeoutError", TimeoutError);
312
300
  __publicField$b(_CancelablePromise, "PromiseControl", PromiseControl);
@@ -350,19 +338,15 @@ function objectAssign(target, ...sources) {
350
338
 
351
339
  function isEqual(a, b, o, p) {
352
340
  if (a instanceof Array) {
353
- if (!(b instanceof Array))
354
- return false;
341
+ if (!(b instanceof Array)) return false;
355
342
  return b.sort().join("") === a.sort().join("");
356
343
  } else if (a instanceof Date) {
357
- if (!(b instanceof Date))
358
- return false;
344
+ if (!(b instanceof Date)) return false;
359
345
  return "" + a === "" + b;
360
346
  } else if (a instanceof Function) {
361
- if (!(b instanceof Function))
362
- return false;
347
+ if (!(b instanceof Function)) return false;
363
348
  } else if (a instanceof Object) {
364
- if (!(b instanceof Object))
365
- return false;
349
+ if (!(b instanceof Object)) return false;
366
350
  if (a === o) {
367
351
  return b === p;
368
352
  } else {
@@ -374,10 +358,8 @@ function isEqual(a, b, o, p) {
374
358
  function objectDeepEqual(o, p) {
375
359
  const keysO = Object.keys(o).sort();
376
360
  const keysP = Object.keys(p).sort();
377
- if (keysO.length !== keysP.length)
378
- return false;
379
- if (keysO.join("") !== keysP.join(""))
380
- return false;
361
+ if (keysO.length !== keysP.length) return false;
362
+ if (keysO.join("") !== keysP.join("")) return false;
381
363
  for (let i = 0; i < keysO.length; i++) {
382
364
  const oVal = o[keysO[i]];
383
365
  const pVal = p[keysP[i]];
@@ -430,9 +412,7 @@ var __getOwnPropDescs$3 = Object.getOwnPropertyDescriptors;
430
412
  var __getOwnPropSymbols$5 = Object.getOwnPropertySymbols;
431
413
  var __hasOwnProp$5 = Object.prototype.hasOwnProperty;
432
414
  var __propIsEnum$5 = Object.prototype.propertyIsEnumerable;
433
- var __knownSymbol$2 = (name, symbol) => {
434
- return (symbol = Symbol[name]) ? symbol : Symbol.for("Symbol." + name);
435
- };
415
+ var __knownSymbol$2 = (name, symbol) => (symbol = Symbol[name]) ? symbol : Symbol.for("Symbol." + name);
436
416
  var __defNormalProp$c = (obj, key, value) => key in obj ? __defProp$c(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
437
417
  var __spreadValues$5 = (a, b) => {
438
418
  for (var prop in b || (b = {}))
@@ -446,10 +426,7 @@ var __spreadValues$5 = (a, b) => {
446
426
  return a;
447
427
  };
448
428
  var __spreadProps$3 = (a, b) => __defProps$3(a, __getOwnPropDescs$3(b));
449
- var __publicField$a = (obj, key, value) => {
450
- __defNormalProp$c(obj, typeof key !== "symbol" ? key + "" : key, value);
451
- return value;
452
- };
429
+ var __publicField$a = (obj, key, value) => __defNormalProp$c(obj, typeof key !== "symbol" ? key + "" : key, value);
453
430
  var __async$1 = (__this, __arguments, generator) => {
454
431
  return new Promise((resolve, reject) => {
455
432
  var fulfilled = (value) => {
@@ -482,9 +459,7 @@ var __asyncGenerator$2 = (__this, __arguments, generator) => {
482
459
  } catch (e) {
483
460
  no(e);
484
461
  }
485
- };
486
- var method = (k) => it[k] = (x) => new Promise((yes, no) => resume(k, x, yes, no));
487
- var it = {};
462
+ }, method = (k) => it[k] = (x) => new Promise((yes, no) => resume(k, x, yes, no)), it = {};
488
463
  return generator = generator.apply(__this, __arguments), it[__knownSymbol$2("asyncIterator")] = () => it, method("next"), method("throw"), method("return"), it;
489
464
  };
490
465
  var __forAwait = (obj, it, method) => (it = obj[__knownSymbol$2("asyncIterator")]) ? it.call(obj) : (obj = obj[__knownSymbol$2("iterator")](), it = {}, method = (key, fn) => (fn = obj[key]) && (it[key] = (arg) => new Promise((yes, no, done) => (arg = fn.call(obj, arg), done = arg.done, Promise.resolve(arg.value).then((value) => yes({ value, done }), no)))), method("next"), method("return"), it);
@@ -614,10 +589,7 @@ class Geocoder extends BaseGeocoder {
614
589
 
615
590
  var __defProp$b = Object.defineProperty;
616
591
  var __defNormalProp$b = (obj, key, value) => key in obj ? __defProp$b(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
617
- var __publicField$9 = (obj, key, value) => {
618
- __defNormalProp$b(obj, typeof key !== "symbol" ? key + "" : key, value);
619
- return value;
620
- };
592
+ var __publicField$9 = (obj, key, value) => __defNormalProp$b(obj, typeof key !== "symbol" ? key + "" : key, value);
621
593
  class BaseProvider extends BaseGeocoder {
622
594
  constructor() {
623
595
  super(...arguments);
@@ -1108,10 +1080,7 @@ function unwrapListeners(arr) {
1108
1080
 
1109
1081
  var __defProp$a = Object.defineProperty;
1110
1082
  var __defNormalProp$a = (obj, key, value) => key in obj ? __defProp$a(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
1111
- var __publicField$8 = (obj, key, value) => {
1112
- __defNormalProp$a(obj, typeof key !== "symbol" ? key + "" : key, value);
1113
- return value;
1114
- };
1083
+ var __publicField$8 = (obj, key, value) => __defNormalProp$a(obj, typeof key !== "symbol" ? key + "" : key, value);
1115
1084
  const _Cache = class _Cache {
1116
1085
  constructor(options = {}) {
1117
1086
  __publicField$8(this, "cache", []);
@@ -1238,10 +1207,7 @@ let Cache = _Cache;
1238
1207
 
1239
1208
  var __defProp$9 = Object.defineProperty;
1240
1209
  var __defNormalProp$9 = (obj, key, value) => key in obj ? __defProp$9(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
1241
- var __publicField$7 = (obj, key, value) => {
1242
- __defNormalProp$9(obj, typeof key !== "symbol" ? key + "" : key, value);
1243
- return value;
1244
- };
1210
+ var __publicField$7 = (obj, key, value) => __defNormalProp$9(obj, typeof key !== "symbol" ? key + "" : key, value);
1245
1211
  class NgwError extends Error {
1246
1212
  constructor(er) {
1247
1213
  super();
@@ -1260,10 +1226,7 @@ class NgwError extends Error {
1260
1226
 
1261
1227
  var __defProp$8 = Object.defineProperty;
1262
1228
  var __defNormalProp$8 = (obj, key, value) => key in obj ? __defProp$8(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
1263
- var __publicField$6 = (obj, key, value) => {
1264
- __defNormalProp$8(obj, typeof key !== "symbol" ? key + "" : key, value);
1265
- return value;
1266
- };
1229
+ var __publicField$6 = (obj, key, value) => __defNormalProp$8(obj, typeof key !== "symbol" ? key + "" : key, value);
1267
1230
  class ResourceNotFoundError extends NgwError {
1268
1231
  constructor(obj) {
1269
1232
  super(obj);
@@ -1321,10 +1284,7 @@ var __spreadValues$4 = (a, b) => {
1321
1284
  return a;
1322
1285
  };
1323
1286
  var __spreadProps$2 = (a, b) => __defProps$2(a, __getOwnPropDescs$2(b));
1324
- var __publicField$5 = (obj, key, value) => {
1325
- __defNormalProp$7(obj, typeof key !== "symbol" ? key + "" : key, value);
1326
- return value;
1327
- };
1287
+ var __publicField$5 = (obj, key, value) => __defNormalProp$7(obj, typeof key !== "symbol" ? key + "" : key, value);
1328
1288
  var __async = (__this, __arguments, generator) => {
1329
1289
  return new Promise((resolve, reject) => {
1330
1290
  var fulfilled = (value) => {
@@ -1346,9 +1306,14 @@ var __async = (__this, __arguments, generator) => {
1346
1306
  });
1347
1307
  };
1348
1308
  class ResourcesControl {
1349
- constructor(connector) {
1309
+ constructor({
1310
+ connector,
1311
+ cacheId
1312
+ }) {
1313
+ __publicField$5(this, "cache");
1314
+ __publicField$5(this, "connector");
1350
1315
  this.connector = connector;
1351
- __publicField$5(this, "cache", new Cache());
1316
+ this.cache = new Cache({ namespace: cacheId });
1352
1317
  }
1353
1318
  // -------------------------------------------------------------------------
1354
1319
  // Resource Methods
@@ -1361,7 +1326,7 @@ class ResourcesControl {
1361
1326
  * Fetching resource would be cached to speed up next call
1362
1327
  */
1363
1328
  getOne(resource, requestOptions) {
1364
- const cache = new Cache();
1329
+ const cache = this.cache;
1365
1330
  const forCache = {};
1366
1331
  const opt = __spreadProps$2(__spreadValues$4({}, requestOptions), { cache: false });
1367
1332
  if (typeof resource === "string") {
@@ -1612,10 +1577,7 @@ function removeConnector(connector) {
1612
1577
 
1613
1578
  var __defProp$6 = Object.defineProperty;
1614
1579
  var __defNormalProp$6 = (obj, key, value) => key in obj ? __defProp$6(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
1615
- var __publicField$4 = (obj, key, value) => {
1616
- __defNormalProp$6(obj, typeof key !== "symbol" ? key + "" : key, value);
1617
- return value;
1618
- };
1580
+ var __publicField$4 = (obj, key, value) => __defNormalProp$6(obj, typeof key !== "symbol" ? key + "" : key, value);
1619
1581
  class InsufficientPermissionsError extends NgwError {
1620
1582
  constructor(obj) {
1621
1583
  super(obj);
@@ -1695,10 +1657,7 @@ function apiRequest(opt) {
1695
1657
 
1696
1658
  var __defProp$5 = Object.defineProperty;
1697
1659
  var __defNormalProp$5 = (obj, key, value) => key in obj ? __defProp$5(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
1698
- var __publicField$3 = (obj, key, value) => {
1699
- __defNormalProp$5(obj, typeof key !== "symbol" ? key + "" : key, value);
1700
- return value;
1701
- };
1660
+ var __publicField$3 = (obj, key, value) => __defNormalProp$5(obj, typeof key !== "symbol" ? key + "" : key, value);
1702
1661
  class NetworkError extends Error {
1703
1662
  constructor(url) {
1704
1663
  super();
@@ -1807,10 +1766,7 @@ var __spreadValues$3 = (a, b) => {
1807
1766
  }
1808
1767
  return a;
1809
1768
  };
1810
- var __publicField$2 = (obj, key, value) => {
1811
- __defNormalProp$4(obj, typeof key !== "symbol" ? key + "" : key, value);
1812
- return value;
1813
- };
1769
+ var __publicField$2 = (obj, key, value) => __defNormalProp$4(obj, typeof key !== "symbol" ? key + "" : key, value);
1814
1770
  let ID = 0;
1815
1771
  class NgwConnector {
1816
1772
  constructor(options) {
@@ -1819,10 +1775,12 @@ class NgwConnector {
1819
1775
  __publicField$2(this, "emitter", new EventEmitter());
1820
1776
  __publicField$2(this, "user");
1821
1777
  __publicField$2(this, "resources");
1778
+ __publicField$2(this, "cache");
1822
1779
  __publicField$2(this, "routeStr", "/api/component/pyramid/route");
1823
1780
  __publicField$2(this, "activeRequests", []);
1824
1781
  __publicField$2(this, "requestTransform");
1825
1782
  const exist = findConnector(options);
1783
+ this.cache = new Cache({ namespace: options.cacheId });
1826
1784
  if (exist) {
1827
1785
  return exist;
1828
1786
  } else {
@@ -1832,13 +1790,23 @@ class NgwConnector {
1832
1790
  if (this.options.requestTransform) {
1833
1791
  this.requestTransform = this.options.requestTransform;
1834
1792
  }
1835
- this.resources = new ResourcesControl(this);
1793
+ this.resources = new ResourcesControl({
1794
+ connector: this,
1795
+ cacheId: options.cacheId
1796
+ });
1836
1797
  addConnector(this);
1837
1798
  }
1838
1799
  }
1839
1800
  static create(options) {
1840
1801
  return new this(options);
1841
1802
  }
1803
+ /**
1804
+ * Clear the cache.
1805
+ */
1806
+ clearCache() {
1807
+ this.cache.clean();
1808
+ this.resources.cache.clean();
1809
+ }
1842
1810
  setRequestTransform(requestTransform) {
1843
1811
  this.requestTransform = requestTransform;
1844
1812
  }
@@ -1866,7 +1834,6 @@ class NgwConnector {
1866
1834
  * ```
1867
1835
  */
1868
1836
  connect() {
1869
- const cache = new Cache();
1870
1837
  const auth = this.options.auth;
1871
1838
  const makeConnect = () => new CancelablePromise((resolve, reject) => {
1872
1839
  const makeQuery = () => {
@@ -1886,7 +1853,7 @@ class NgwConnector {
1886
1853
  }
1887
1854
  return makeQuery();
1888
1855
  });
1889
- return cache.add("route", makeConnect, {
1856
+ return this.cache.add("route", makeConnect, {
1890
1857
  id: this.id,
1891
1858
  auth,
1892
1859
  baseUrl: this.options.baseUrl
@@ -1909,8 +1876,8 @@ class NgwConnector {
1909
1876
  removeConnector(this);
1910
1877
  this.options.auth = void 0;
1911
1878
  this.user = void 0;
1879
+ this.clearCache();
1912
1880
  this.emitter.emit("logout");
1913
- this.resources.cache.clean();
1914
1881
  }
1915
1882
  getUserInfo(credentials, options) {
1916
1883
  if (this.user && this.user.id) {
@@ -1995,8 +1962,7 @@ class NgwConnector {
1995
1962
  const params = objectRemoveEmpty(params_);
1996
1963
  const makeApiRequest = () => apiRequest({ name, params, requestOptions, connector: this });
1997
1964
  if (requestOptions.cache && method === "GET") {
1998
- const cache = new Cache();
1999
- return cache.add(name, makeApiRequest, __spreadValues$3({
1965
+ return this.cache.add(name, makeApiRequest, __spreadValues$3({
2000
1966
  params
2001
1967
  }, objectRemoveEmpty({
2002
1968
  headers,
@@ -2266,10 +2232,8 @@ function reEscape(s) {
2266
2232
  function like(b, a, iLike) {
2267
2233
  a = String(a);
2268
2234
  b = String(b);
2269
- if (a === b)
2270
- return true;
2271
- if (iLike && a.toUpperCase() === b.toUpperCase())
2272
- return true;
2235
+ if (a === b) return true;
2236
+ if (iLike && a.toUpperCase() === b.toUpperCase()) return true;
2273
2237
  const re = `^${reEscape(a)}$`.replace(/%/g, ".*").replace("_", ".");
2274
2238
  return new RegExp(re, iLike ? "i" : "").exec(b) !== null;
2275
2239
  }
@@ -2613,9 +2577,7 @@ var __defProp$1 = Object.defineProperty;
2613
2577
  var __getOwnPropSymbols = Object.getOwnPropertySymbols;
2614
2578
  var __hasOwnProp = Object.prototype.hasOwnProperty;
2615
2579
  var __propIsEnum = Object.prototype.propertyIsEnumerable;
2616
- var __knownSymbol$1 = (name, symbol) => {
2617
- return (symbol = Symbol[name]) ? symbol : Symbol.for("Symbol." + name);
2618
- };
2580
+ var __knownSymbol$1 = (name, symbol) => (symbol = Symbol[name]) ? symbol : Symbol.for("Symbol." + name);
2619
2581
  var __defNormalProp$1 = (obj, key, value) => key in obj ? __defProp$1(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
2620
2582
  var __spreadValues = (a, b) => {
2621
2583
  for (var prop in b || (b = {}))
@@ -2628,10 +2590,7 @@ var __spreadValues = (a, b) => {
2628
2590
  }
2629
2591
  return a;
2630
2592
  };
2631
- var __publicField$1 = (obj, key, value) => {
2632
- __defNormalProp$1(obj, typeof key !== "symbol" ? key + "" : key, value);
2633
- return value;
2634
- };
2593
+ var __publicField$1 = (obj, key, value) => __defNormalProp$1(obj, typeof key !== "symbol" ? key + "" : key, value);
2635
2594
  var __await$1 = function(promise, isYieldStar) {
2636
2595
  this[0] = promise;
2637
2596
  this[1] = isYieldStar;
@@ -2644,9 +2603,7 @@ var __asyncGenerator$1 = (__this, __arguments, generator) => {
2644
2603
  } catch (e) {
2645
2604
  no(e);
2646
2605
  }
2647
- };
2648
- var method = (k) => it[k] = (x) => new Promise((yes, no) => resume(k, x, yes, no));
2649
- var it = {};
2606
+ }, method = (k) => it[k] = (x) => new Promise((yes, no) => resume(k, x, yes, no)), it = {};
2650
2607
  return generator = generator.apply(__this, __arguments), it[__knownSymbol$1("asyncIterator")] = () => it, method("next"), method("throw"), method("return"), it;
2651
2608
  };
2652
2609
  const _NgwProvider = class _NgwProvider extends BaseProvider {
@@ -2793,14 +2750,9 @@ __publicField$1(_NgwProvider, "limit", 300);
2793
2750
  let NgwProvider = _NgwProvider;
2794
2751
 
2795
2752
  var __defProp = Object.defineProperty;
2796
- var __knownSymbol = (name, symbol) => {
2797
- return (symbol = Symbol[name]) ? symbol : Symbol.for("Symbol." + name);
2798
- };
2753
+ var __knownSymbol = (name, symbol) => (symbol = Symbol[name]) ? symbol : Symbol.for("Symbol." + name);
2799
2754
  var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
2800
- var __publicField = (obj, key, value) => {
2801
- __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
2802
- return value;
2803
- };
2755
+ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
2804
2756
  var __await = function(promise, isYieldStar) {
2805
2757
  this[0] = promise;
2806
2758
  this[1] = isYieldStar;
@@ -2813,9 +2765,7 @@ var __asyncGenerator = (__this, __arguments, generator) => {
2813
2765
  } catch (e) {
2814
2766
  no(e);
2815
2767
  }
2816
- };
2817
- var method = (k) => it[k] = (x) => new Promise((yes, no) => resume(k, x, yes, no));
2818
- var it = {};
2768
+ }, method = (k) => it[k] = (x) => new Promise((yes, no) => resume(k, x, yes, no)), it = {};
2819
2769
  return generator = generator.apply(__this, __arguments), it[__knownSymbol("asyncIterator")] = () => it, method("next"), method("throw"), method("return"), it;
2820
2770
  };
2821
2771
  class NominatimProvider extends BaseProvider {