@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,13 +1,10 @@
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 Geocoder = (function (exports) {
3
3
  'use strict';
4
4
 
5
5
  var __defProp$g = Object.defineProperty;
6
6
  var __defNormalProp$g = (obj, key, value) => key in obj ? __defProp$g(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
7
- var __publicField$e = (obj, key, value) => {
8
- __defNormalProp$g(obj, typeof key !== "symbol" ? key + "" : key, value);
9
- return value;
10
- };
7
+ var __publicField$e = (obj, key, value) => __defNormalProp$g(obj, typeof key !== "symbol" ? key + "" : key, value);
11
8
  class CancelError extends Error {
12
9
  constructor() {
13
10
  super();
@@ -18,10 +15,7 @@ var Geocoder = (function (exports) {
18
15
 
19
16
  var __defProp$f = Object.defineProperty;
20
17
  var __defNormalProp$f = (obj, key, value) => key in obj ? __defProp$f(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
21
- var __publicField$d = (obj, key, value) => {
22
- __defNormalProp$f(obj, typeof key !== "symbol" ? key + "" : key, value);
23
- return value;
24
- };
18
+ var __publicField$d = (obj, key, value) => __defNormalProp$f(obj, typeof key !== "symbol" ? key + "" : key, value);
25
19
  class PromiseControl {
26
20
  constructor(options = {}) {
27
21
  this.options = options;
@@ -103,10 +97,7 @@ var Geocoder = (function (exports) {
103
97
 
104
98
  var __defProp$e = Object.defineProperty;
105
99
  var __defNormalProp$e = (obj, key, value) => key in obj ? __defProp$e(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
106
- var __publicField$c = (obj, key, value) => {
107
- __defNormalProp$e(obj, typeof key !== "symbol" ? key + "" : key, value);
108
- return value;
109
- };
100
+ var __publicField$c = (obj, key, value) => __defNormalProp$e(obj, typeof key !== "symbol" ? key + "" : key, value);
110
101
  class TimeoutError extends Error {
111
102
  constructor() {
112
103
  super();
@@ -117,10 +108,7 @@ var Geocoder = (function (exports) {
117
108
 
118
109
  var __defProp$d = Object.defineProperty;
119
110
  var __defNormalProp$d = (obj, key, value) => key in obj ? __defProp$d(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
120
- var __publicField$b = (obj, key, value) => {
121
- __defNormalProp$d(obj, typeof key !== "symbol" ? key + "" : key, value);
122
- return value;
123
- };
111
+ var __publicField$b = (obj, key, value) => __defNormalProp$d(obj, typeof key !== "symbol" ? key + "" : key, value);
124
112
  var _a;
125
113
  const handleCallback = (resolve, reject, callback, r) => {
126
114
  try {
@@ -130,6 +118,7 @@ var Geocoder = (function (exports) {
130
118
  }
131
119
  };
132
120
  let ID$2 = 0;
121
+ _a = Symbol.toStringTag;
133
122
  const _CancelablePromise = class _CancelablePromise {
134
123
  constructor(executor, timeout) {
135
124
  // @ts-ignore
@@ -309,7 +298,6 @@ var Geocoder = (function (exports) {
309
298
  this._promise = void 0;
310
299
  }
311
300
  };
312
- _a = Symbol.toStringTag;
313
301
  __publicField$b(_CancelablePromise, "CancelError", CancelError);
314
302
  __publicField$b(_CancelablePromise, "TimeoutError", TimeoutError);
315
303
  __publicField$b(_CancelablePromise, "PromiseControl", PromiseControl);
@@ -353,19 +341,15 @@ var Geocoder = (function (exports) {
353
341
 
354
342
  function isEqual(a, b, o, p) {
355
343
  if (a instanceof Array) {
356
- if (!(b instanceof Array))
357
- return false;
344
+ if (!(b instanceof Array)) return false;
358
345
  return b.sort().join("") === a.sort().join("");
359
346
  } else if (a instanceof Date) {
360
- if (!(b instanceof Date))
361
- return false;
347
+ if (!(b instanceof Date)) return false;
362
348
  return "" + a === "" + b;
363
349
  } else if (a instanceof Function) {
364
- if (!(b instanceof Function))
365
- return false;
350
+ if (!(b instanceof Function)) return false;
366
351
  } else if (a instanceof Object) {
367
- if (!(b instanceof Object))
368
- return false;
352
+ if (!(b instanceof Object)) return false;
369
353
  if (a === o) {
370
354
  return b === p;
371
355
  } else {
@@ -377,10 +361,8 @@ var Geocoder = (function (exports) {
377
361
  function objectDeepEqual(o, p) {
378
362
  const keysO = Object.keys(o).sort();
379
363
  const keysP = Object.keys(p).sort();
380
- if (keysO.length !== keysP.length)
381
- return false;
382
- if (keysO.join("") !== keysP.join(""))
383
- return false;
364
+ if (keysO.length !== keysP.length) return false;
365
+ if (keysO.join("") !== keysP.join("")) return false;
384
366
  for (let i = 0; i < keysO.length; i++) {
385
367
  const oVal = o[keysO[i]];
386
368
  const pVal = p[keysP[i]];
@@ -433,9 +415,7 @@ var Geocoder = (function (exports) {
433
415
  var __getOwnPropSymbols$5 = Object.getOwnPropertySymbols;
434
416
  var __hasOwnProp$5 = Object.prototype.hasOwnProperty;
435
417
  var __propIsEnum$5 = Object.prototype.propertyIsEnumerable;
436
- var __knownSymbol$2 = (name, symbol) => {
437
- return (symbol = Symbol[name]) ? symbol : Symbol.for("Symbol." + name);
438
- };
418
+ var __knownSymbol$2 = (name, symbol) => (symbol = Symbol[name]) ? symbol : Symbol.for("Symbol." + name);
439
419
  var __defNormalProp$c = (obj, key, value) => key in obj ? __defProp$c(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
440
420
  var __spreadValues$5 = (a, b) => {
441
421
  for (var prop in b || (b = {}))
@@ -449,10 +429,7 @@ var Geocoder = (function (exports) {
449
429
  return a;
450
430
  };
451
431
  var __spreadProps$3 = (a, b) => __defProps$3(a, __getOwnPropDescs$3(b));
452
- var __publicField$a = (obj, key, value) => {
453
- __defNormalProp$c(obj, typeof key !== "symbol" ? key + "" : key, value);
454
- return value;
455
- };
432
+ var __publicField$a = (obj, key, value) => __defNormalProp$c(obj, typeof key !== "symbol" ? key + "" : key, value);
456
433
  var __async$1 = (__this, __arguments, generator) => {
457
434
  return new Promise((resolve, reject) => {
458
435
  var fulfilled = (value) => {
@@ -485,9 +462,7 @@ var Geocoder = (function (exports) {
485
462
  } catch (e) {
486
463
  no(e);
487
464
  }
488
- };
489
- var method = (k) => it[k] = (x) => new Promise((yes, no) => resume(k, x, yes, no));
490
- var it = {};
465
+ }, method = (k) => it[k] = (x) => new Promise((yes, no) => resume(k, x, yes, no)), it = {};
491
466
  return generator = generator.apply(__this, __arguments), it[__knownSymbol$2("asyncIterator")] = () => it, method("next"), method("throw"), method("return"), it;
492
467
  };
493
468
  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);
@@ -617,10 +592,7 @@ var Geocoder = (function (exports) {
617
592
 
618
593
  var __defProp$b = Object.defineProperty;
619
594
  var __defNormalProp$b = (obj, key, value) => key in obj ? __defProp$b(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
620
- var __publicField$9 = (obj, key, value) => {
621
- __defNormalProp$b(obj, typeof key !== "symbol" ? key + "" : key, value);
622
- return value;
623
- };
595
+ var __publicField$9 = (obj, key, value) => __defNormalProp$b(obj, typeof key !== "symbol" ? key + "" : key, value);
624
596
  class BaseProvider extends BaseGeocoder {
625
597
  constructor() {
626
598
  super(...arguments);
@@ -1111,10 +1083,7 @@ var Geocoder = (function (exports) {
1111
1083
 
1112
1084
  var __defProp$a = Object.defineProperty;
1113
1085
  var __defNormalProp$a = (obj, key, value) => key in obj ? __defProp$a(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
1114
- var __publicField$8 = (obj, key, value) => {
1115
- __defNormalProp$a(obj, typeof key !== "symbol" ? key + "" : key, value);
1116
- return value;
1117
- };
1086
+ var __publicField$8 = (obj, key, value) => __defNormalProp$a(obj, typeof key !== "symbol" ? key + "" : key, value);
1118
1087
  const _Cache = class _Cache {
1119
1088
  constructor(options = {}) {
1120
1089
  __publicField$8(this, "cache", []);
@@ -1241,10 +1210,7 @@ var Geocoder = (function (exports) {
1241
1210
 
1242
1211
  var __defProp$9 = Object.defineProperty;
1243
1212
  var __defNormalProp$9 = (obj, key, value) => key in obj ? __defProp$9(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
1244
- var __publicField$7 = (obj, key, value) => {
1245
- __defNormalProp$9(obj, typeof key !== "symbol" ? key + "" : key, value);
1246
- return value;
1247
- };
1213
+ var __publicField$7 = (obj, key, value) => __defNormalProp$9(obj, typeof key !== "symbol" ? key + "" : key, value);
1248
1214
  class NgwError extends Error {
1249
1215
  constructor(er) {
1250
1216
  super();
@@ -1263,10 +1229,7 @@ var Geocoder = (function (exports) {
1263
1229
 
1264
1230
  var __defProp$8 = Object.defineProperty;
1265
1231
  var __defNormalProp$8 = (obj, key, value) => key in obj ? __defProp$8(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
1266
- var __publicField$6 = (obj, key, value) => {
1267
- __defNormalProp$8(obj, typeof key !== "symbol" ? key + "" : key, value);
1268
- return value;
1269
- };
1232
+ var __publicField$6 = (obj, key, value) => __defNormalProp$8(obj, typeof key !== "symbol" ? key + "" : key, value);
1270
1233
  class ResourceNotFoundError extends NgwError {
1271
1234
  constructor(obj) {
1272
1235
  super(obj);
@@ -1324,10 +1287,7 @@ var Geocoder = (function (exports) {
1324
1287
  return a;
1325
1288
  };
1326
1289
  var __spreadProps$2 = (a, b) => __defProps$2(a, __getOwnPropDescs$2(b));
1327
- var __publicField$5 = (obj, key, value) => {
1328
- __defNormalProp$7(obj, typeof key !== "symbol" ? key + "" : key, value);
1329
- return value;
1330
- };
1290
+ var __publicField$5 = (obj, key, value) => __defNormalProp$7(obj, typeof key !== "symbol" ? key + "" : key, value);
1331
1291
  var __async = (__this, __arguments, generator) => {
1332
1292
  return new Promise((resolve, reject) => {
1333
1293
  var fulfilled = (value) => {
@@ -1349,9 +1309,14 @@ var Geocoder = (function (exports) {
1349
1309
  });
1350
1310
  };
1351
1311
  class ResourcesControl {
1352
- constructor(connector) {
1312
+ constructor({
1313
+ connector,
1314
+ cacheId
1315
+ }) {
1316
+ __publicField$5(this, "cache");
1317
+ __publicField$5(this, "connector");
1353
1318
  this.connector = connector;
1354
- __publicField$5(this, "cache", new Cache());
1319
+ this.cache = new Cache({ namespace: cacheId });
1355
1320
  }
1356
1321
  // -------------------------------------------------------------------------
1357
1322
  // Resource Methods
@@ -1364,7 +1329,7 @@ var Geocoder = (function (exports) {
1364
1329
  * Fetching resource would be cached to speed up next call
1365
1330
  */
1366
1331
  getOne(resource, requestOptions) {
1367
- const cache = new Cache();
1332
+ const cache = this.cache;
1368
1333
  const forCache = {};
1369
1334
  const opt = __spreadProps$2(__spreadValues$4({}, requestOptions), { cache: false });
1370
1335
  if (typeof resource === "string") {
@@ -1615,10 +1580,7 @@ var Geocoder = (function (exports) {
1615
1580
 
1616
1581
  var __defProp$6 = Object.defineProperty;
1617
1582
  var __defNormalProp$6 = (obj, key, value) => key in obj ? __defProp$6(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
1618
- var __publicField$4 = (obj, key, value) => {
1619
- __defNormalProp$6(obj, typeof key !== "symbol" ? key + "" : key, value);
1620
- return value;
1621
- };
1583
+ var __publicField$4 = (obj, key, value) => __defNormalProp$6(obj, typeof key !== "symbol" ? key + "" : key, value);
1622
1584
  class InsufficientPermissionsError extends NgwError {
1623
1585
  constructor(obj) {
1624
1586
  super(obj);
@@ -1698,10 +1660,7 @@ var Geocoder = (function (exports) {
1698
1660
 
1699
1661
  var __defProp$5 = Object.defineProperty;
1700
1662
  var __defNormalProp$5 = (obj, key, value) => key in obj ? __defProp$5(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
1701
- var __publicField$3 = (obj, key, value) => {
1702
- __defNormalProp$5(obj, typeof key !== "symbol" ? key + "" : key, value);
1703
- return value;
1704
- };
1663
+ var __publicField$3 = (obj, key, value) => __defNormalProp$5(obj, typeof key !== "symbol" ? key + "" : key, value);
1705
1664
  class NetworkError extends Error {
1706
1665
  constructor(url) {
1707
1666
  super();
@@ -1810,10 +1769,7 @@ var Geocoder = (function (exports) {
1810
1769
  }
1811
1770
  return a;
1812
1771
  };
1813
- var __publicField$2 = (obj, key, value) => {
1814
- __defNormalProp$4(obj, typeof key !== "symbol" ? key + "" : key, value);
1815
- return value;
1816
- };
1772
+ var __publicField$2 = (obj, key, value) => __defNormalProp$4(obj, typeof key !== "symbol" ? key + "" : key, value);
1817
1773
  let ID = 0;
1818
1774
  class NgwConnector {
1819
1775
  constructor(options) {
@@ -1822,10 +1778,12 @@ var Geocoder = (function (exports) {
1822
1778
  __publicField$2(this, "emitter", new EventEmitter());
1823
1779
  __publicField$2(this, "user");
1824
1780
  __publicField$2(this, "resources");
1781
+ __publicField$2(this, "cache");
1825
1782
  __publicField$2(this, "routeStr", "/api/component/pyramid/route");
1826
1783
  __publicField$2(this, "activeRequests", []);
1827
1784
  __publicField$2(this, "requestTransform");
1828
1785
  const exist = findConnector(options);
1786
+ this.cache = new Cache({ namespace: options.cacheId });
1829
1787
  if (exist) {
1830
1788
  return exist;
1831
1789
  } else {
@@ -1835,13 +1793,23 @@ var Geocoder = (function (exports) {
1835
1793
  if (this.options.requestTransform) {
1836
1794
  this.requestTransform = this.options.requestTransform;
1837
1795
  }
1838
- this.resources = new ResourcesControl(this);
1796
+ this.resources = new ResourcesControl({
1797
+ connector: this,
1798
+ cacheId: options.cacheId
1799
+ });
1839
1800
  addConnector(this);
1840
1801
  }
1841
1802
  }
1842
1803
  static create(options) {
1843
1804
  return new this(options);
1844
1805
  }
1806
+ /**
1807
+ * Clear the cache.
1808
+ */
1809
+ clearCache() {
1810
+ this.cache.clean();
1811
+ this.resources.cache.clean();
1812
+ }
1845
1813
  setRequestTransform(requestTransform) {
1846
1814
  this.requestTransform = requestTransform;
1847
1815
  }
@@ -1869,7 +1837,6 @@ var Geocoder = (function (exports) {
1869
1837
  * ```
1870
1838
  */
1871
1839
  connect() {
1872
- const cache = new Cache();
1873
1840
  const auth = this.options.auth;
1874
1841
  const makeConnect = () => new CancelablePromise((resolve, reject) => {
1875
1842
  const makeQuery = () => {
@@ -1889,7 +1856,7 @@ var Geocoder = (function (exports) {
1889
1856
  }
1890
1857
  return makeQuery();
1891
1858
  });
1892
- return cache.add("route", makeConnect, {
1859
+ return this.cache.add("route", makeConnect, {
1893
1860
  id: this.id,
1894
1861
  auth,
1895
1862
  baseUrl: this.options.baseUrl
@@ -1912,8 +1879,8 @@ var Geocoder = (function (exports) {
1912
1879
  removeConnector(this);
1913
1880
  this.options.auth = void 0;
1914
1881
  this.user = void 0;
1882
+ this.clearCache();
1915
1883
  this.emitter.emit("logout");
1916
- this.resources.cache.clean();
1917
1884
  }
1918
1885
  getUserInfo(credentials, options) {
1919
1886
  if (this.user && this.user.id) {
@@ -1998,8 +1965,7 @@ var Geocoder = (function (exports) {
1998
1965
  const params = objectRemoveEmpty(params_);
1999
1966
  const makeApiRequest = () => apiRequest({ name, params, requestOptions, connector: this });
2000
1967
  if (requestOptions.cache && method === "GET") {
2001
- const cache = new Cache();
2002
- return cache.add(name, makeApiRequest, __spreadValues$3({
1968
+ return this.cache.add(name, makeApiRequest, __spreadValues$3({
2003
1969
  params
2004
1970
  }, objectRemoveEmpty({
2005
1971
  headers,
@@ -2269,10 +2235,8 @@ var Geocoder = (function (exports) {
2269
2235
  function like(b, a, iLike) {
2270
2236
  a = String(a);
2271
2237
  b = String(b);
2272
- if (a === b)
2273
- return true;
2274
- if (iLike && a.toUpperCase() === b.toUpperCase())
2275
- return true;
2238
+ if (a === b) return true;
2239
+ if (iLike && a.toUpperCase() === b.toUpperCase()) return true;
2276
2240
  const re = `^${reEscape(a)}$`.replace(/%/g, ".*").replace("_", ".");
2277
2241
  return new RegExp(re, iLike ? "i" : "").exec(b) !== null;
2278
2242
  }
@@ -2616,9 +2580,7 @@ var Geocoder = (function (exports) {
2616
2580
  var __getOwnPropSymbols = Object.getOwnPropertySymbols;
2617
2581
  var __hasOwnProp = Object.prototype.hasOwnProperty;
2618
2582
  var __propIsEnum = Object.prototype.propertyIsEnumerable;
2619
- var __knownSymbol$1 = (name, symbol) => {
2620
- return (symbol = Symbol[name]) ? symbol : Symbol.for("Symbol." + name);
2621
- };
2583
+ var __knownSymbol$1 = (name, symbol) => (symbol = Symbol[name]) ? symbol : Symbol.for("Symbol." + name);
2622
2584
  var __defNormalProp$1 = (obj, key, value) => key in obj ? __defProp$1(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
2623
2585
  var __spreadValues = (a, b) => {
2624
2586
  for (var prop in b || (b = {}))
@@ -2631,10 +2593,7 @@ var Geocoder = (function (exports) {
2631
2593
  }
2632
2594
  return a;
2633
2595
  };
2634
- var __publicField$1 = (obj, key, value) => {
2635
- __defNormalProp$1(obj, typeof key !== "symbol" ? key + "" : key, value);
2636
- return value;
2637
- };
2596
+ var __publicField$1 = (obj, key, value) => __defNormalProp$1(obj, typeof key !== "symbol" ? key + "" : key, value);
2638
2597
  var __await$1 = function(promise, isYieldStar) {
2639
2598
  this[0] = promise;
2640
2599
  this[1] = isYieldStar;
@@ -2647,9 +2606,7 @@ var Geocoder = (function (exports) {
2647
2606
  } catch (e) {
2648
2607
  no(e);
2649
2608
  }
2650
- };
2651
- var method = (k) => it[k] = (x) => new Promise((yes, no) => resume(k, x, yes, no));
2652
- var it = {};
2609
+ }, method = (k) => it[k] = (x) => new Promise((yes, no) => resume(k, x, yes, no)), it = {};
2653
2610
  return generator = generator.apply(__this, __arguments), it[__knownSymbol$1("asyncIterator")] = () => it, method("next"), method("throw"), method("return"), it;
2654
2611
  };
2655
2612
  const _NgwProvider = class _NgwProvider extends BaseProvider {
@@ -2796,14 +2753,9 @@ var Geocoder = (function (exports) {
2796
2753
  let NgwProvider = _NgwProvider;
2797
2754
 
2798
2755
  var __defProp = Object.defineProperty;
2799
- var __knownSymbol = (name, symbol) => {
2800
- return (symbol = Symbol[name]) ? symbol : Symbol.for("Symbol." + name);
2801
- };
2756
+ var __knownSymbol = (name, symbol) => (symbol = Symbol[name]) ? symbol : Symbol.for("Symbol." + name);
2802
2757
  var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
2803
- var __publicField = (obj, key, value) => {
2804
- __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
2805
- return value;
2806
- };
2758
+ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
2807
2759
  var __await = function(promise, isYieldStar) {
2808
2760
  this[0] = promise;
2809
2761
  this[1] = isYieldStar;
@@ -2816,9 +2768,7 @@ var Geocoder = (function (exports) {
2816
2768
  } catch (e) {
2817
2769
  no(e);
2818
2770
  }
2819
- };
2820
- var method = (k) => it[k] = (x) => new Promise((yes, no) => resume(k, x, yes, no));
2821
- var it = {};
2771
+ }, method = (k) => it[k] = (x) => new Promise((yes, no) => resume(k, x, yes, no)), it = {};
2822
2772
  return generator = generator.apply(__this, __arguments), it[__knownSymbol("asyncIterator")] = () => it, method("next"), method("throw"), method("return"), it;
2823
2773
  };
2824
2774
  class NominatimProvider extends BaseProvider {