@nextgis/geocoder 3.0.0-alpha.6 → 3.0.0-alpha.8

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,4 +1,4 @@
1
- /** Bundle of @nextgis/geocoder; version: 3.0.0-alpha.6; author: NextGIS */
1
+ /** Bundle of @nextgis/geocoder; version: 3.0.0-alpha.8; 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: 3.0.0-alpha.6; author: NextGIS */
1
+ /** Bundle of @nextgis/geocoder; version: 3.0.0-alpha.8; author: NextGIS */
2
2
  function defined(val) {
3
3
  return val !== void 0 && val !== null;
4
4
  }
@@ -817,10 +817,23 @@ const _Cache = class _Cache {
817
817
  * });
818
818
  * ```
819
819
  */
820
- addFull(key, valueToSet, props) {
821
- return this.add(key, valueToSet, props, true);
822
- }
823
- add(key, valueToSet, props, onlyFull) {
820
+ addFull(key, valueToSet, propsOrOptions, expirationTime) {
821
+ if (typeof propsOrOptions === "object" && "valueToSet" in propsOrOptions) {
822
+ propsOrOptions.onlyFull = true;
823
+ }
824
+ return this.add(key, valueToSet, propsOrOptions, true, expirationTime);
825
+ }
826
+ add(key, valueToSet, propsOrOptions, onlyFull, expirationTime) {
827
+ let opt;
828
+ let props;
829
+ if (typeof propsOrOptions === "object" && "valueToSet" in propsOrOptions) {
830
+ opt = propsOrOptions;
831
+ onlyFull = opt.onlyFull;
832
+ expirationTime = opt.expirationTime;
833
+ props = opt.props;
834
+ } else {
835
+ props = propsOrOptions;
836
+ }
824
837
  const exist = this._find(key, props);
825
838
  if (!exist) {
826
839
  let value;
@@ -830,10 +843,12 @@ const _Cache = class _Cache {
830
843
  value = valueToSet;
831
844
  }
832
845
  const nonEmptyProps = props && JSON.parse(JSON.stringify(objectRemoveEmpty(props)));
846
+ expirationTime = expirationTime ? Date.now() + expirationTime : void 0;
833
847
  const cacheItem = {
834
848
  key,
835
849
  value,
836
- props: nonEmptyProps
850
+ props: nonEmptyProps,
851
+ expirationTime
837
852
  };
838
853
  if (onlyFull && !full(value)) {
839
854
  return value;
@@ -860,9 +875,19 @@ const _Cache = class _Cache {
860
875
  }
861
876
  match(key, props) {
862
877
  const cacheRecord = this._find(key, props);
878
+ if (cacheRecord && cacheRecord.expirationTime && Date.now() > cacheRecord.expirationTime) {
879
+ this.delete(cacheRecord);
880
+ return void 0;
881
+ }
863
882
  return cacheRecord == null ? void 0 : cacheRecord.value;
864
883
  }
865
884
  matchAll(key, props) {
885
+ const now = Date.now();
886
+ this.cache.forEach((item) => {
887
+ if (item.expirationTime && now > item.expirationTime) {
888
+ this.delete(item);
889
+ }
890
+ });
866
891
  if (key) {
867
892
  return this.cache.filter((x) => this._filter(x, key, props)).map((x) => x.value);
868
893
  }
@@ -892,7 +917,7 @@ let Cache = _Cache;
892
917
 
893
918
  var pkg = {
894
919
  name: "@nextgis/ngw-connector",
895
- version: "3.0.0-alpha.6",
920
+ version: "3.0.0-alpha.8",
896
921
  _priority: 12,
897
922
  description: "A lightweight HTTP client optimized for use with NextGIS Web API",
898
923
  main: "index.js",
@@ -901,7 +926,7 @@ var pkg = {
901
926
  jsdelivr: "lib/ngw-connector.global.prod.js",
902
927
  types: "lib/index.d.ts",
903
928
  dependencies: {
904
- "@nextgis/cache": "^3.0.0-alpha.5",
929
+ "@nextgis/cache": "^3.0.0-alpha.7",
905
930
  "@nextgis/cancelable-promise": "^3.0.0-alpha.5",
906
931
  "@nextgis/utils": "^3.0.0-alpha.5",
907
932
  "@types/events": "^3.0.0",
@@ -1653,9 +1678,6 @@ class NgwConnector {
1653
1678
  addConnector(this);
1654
1679
  }
1655
1680
  }
1656
- static create(options) {
1657
- return new this(options);
1658
- }
1659
1681
  /**
1660
1682
  * Clear the cache.
1661
1683
  */
@@ -1836,7 +1858,7 @@ class NgwConnector {
1836
1858
  this._cleanActiveRequest(id);
1837
1859
  }
1838
1860
  });
1839
- if (cache && method === "GET") {
1861
+ if (method === "GET") {
1840
1862
  const cacheOptions = cacheProps ? cacheProps : __spreadProps$2(__spreadValues$5({}, objectRemoveEmpty({
1841
1863
  headers,
1842
1864
  withCredentials,
@@ -1846,12 +1868,10 @@ class NgwConnector {
1846
1868
  })), {
1847
1869
  params
1848
1870
  });
1849
- return this.cache.add(
1850
- cacheName || url,
1851
- createPromise,
1852
- cacheOptions,
1853
- false
1854
- );
1871
+ return this.cache.add(cacheName || url, createPromise, {
1872
+ props: cacheOptions,
1873
+ expirationTime: cache ? void 0 : 500
1874
+ });
1855
1875
  }
1856
1876
  return createPromise();
1857
1877
  });
@@ -2315,6 +2335,9 @@ class NgwConnectorExtended extends NgwConnector {
2315
2335
  cacheId: options.cacheId
2316
2336
  });
2317
2337
  }
2338
+ static create(options) {
2339
+ return new this(options);
2340
+ }
2318
2341
  /**
2319
2342
  * Clear the cache.
2320
2343
  */