@nextgis/geocoder 3.0.0-alpha.5 → 3.0.0-alpha.7

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.5; author: NextGIS */
1
+ /** Bundle of @nextgis/geocoder; version: 3.0.0-alpha.7; author: NextGIS */
2
2
  import { objectAssign, fixUrlStr } from '@nextgis/utils';
3
3
  import NgwConnector from '@nextgis/ngw-connector';
4
4
  import { fetchNgwLayerItems } from '@nextgis/ngw-kit';
@@ -1,4 +1,4 @@
1
- /** Bundle of @nextgis/geocoder; version: 3.0.0-alpha.5; author: NextGIS */
1
+ /** Bundle of @nextgis/geocoder; version: 3.0.0-alpha.7; author: NextGIS */
2
2
  var Geocoder = (function (exports) {
3
3
  'use strict';
4
4
 
@@ -820,10 +820,23 @@ var Geocoder = (function (exports) {
820
820
  * });
821
821
  * ```
822
822
  */
823
- addFull(key, valueToSet, props) {
824
- return this.add(key, valueToSet, props, true);
825
- }
826
- add(key, valueToSet, props, onlyFull) {
823
+ addFull(key, valueToSet, propsOrOptions, expirationTime) {
824
+ if (typeof propsOrOptions === "object" && "valueToSet" in propsOrOptions) {
825
+ propsOrOptions.onlyFull = true;
826
+ }
827
+ return this.add(key, valueToSet, propsOrOptions, true, expirationTime);
828
+ }
829
+ add(key, valueToSet, propsOrOptions, onlyFull, expirationTime) {
830
+ let opt;
831
+ let props;
832
+ if (typeof propsOrOptions === "object" && "valueToSet" in propsOrOptions) {
833
+ opt = propsOrOptions;
834
+ onlyFull = opt.onlyFull;
835
+ expirationTime = opt.expirationTime;
836
+ props = opt.props;
837
+ } else {
838
+ props = propsOrOptions;
839
+ }
827
840
  const exist = this._find(key, props);
828
841
  if (!exist) {
829
842
  let value;
@@ -833,10 +846,12 @@ var Geocoder = (function (exports) {
833
846
  value = valueToSet;
834
847
  }
835
848
  const nonEmptyProps = props && JSON.parse(JSON.stringify(objectRemoveEmpty(props)));
849
+ expirationTime = expirationTime ? Date.now() + expirationTime : void 0;
836
850
  const cacheItem = {
837
851
  key,
838
852
  value,
839
- props: nonEmptyProps
853
+ props: nonEmptyProps,
854
+ expirationTime
840
855
  };
841
856
  if (onlyFull && !full(value)) {
842
857
  return value;
@@ -863,9 +878,19 @@ var Geocoder = (function (exports) {
863
878
  }
864
879
  match(key, props) {
865
880
  const cacheRecord = this._find(key, props);
881
+ if (cacheRecord && cacheRecord.expirationTime && Date.now() > cacheRecord.expirationTime) {
882
+ this.delete(cacheRecord);
883
+ return void 0;
884
+ }
866
885
  return cacheRecord == null ? void 0 : cacheRecord.value;
867
886
  }
868
887
  matchAll(key, props) {
888
+ const now = Date.now();
889
+ this.cache.forEach((item) => {
890
+ if (item.expirationTime && now > item.expirationTime) {
891
+ this.delete(item);
892
+ }
893
+ });
869
894
  if (key) {
870
895
  return this.cache.filter((x) => this._filter(x, key, props)).map((x) => x.value);
871
896
  }
@@ -895,7 +920,7 @@ var Geocoder = (function (exports) {
895
920
 
896
921
  var pkg = {
897
922
  name: "@nextgis/ngw-connector",
898
- version: "3.0.0-alpha.5",
923
+ version: "3.0.0-alpha.7",
899
924
  _priority: 12,
900
925
  description: "A lightweight HTTP client optimized for use with NextGIS Web API",
901
926
  main: "index.js",
@@ -904,7 +929,7 @@ var Geocoder = (function (exports) {
904
929
  jsdelivr: "lib/ngw-connector.global.prod.js",
905
930
  types: "lib/index.d.ts",
906
931
  dependencies: {
907
- "@nextgis/cache": "^3.0.0-alpha.5",
932
+ "@nextgis/cache": "^3.0.0-alpha.7",
908
933
  "@nextgis/cancelable-promise": "^3.0.0-alpha.5",
909
934
  "@nextgis/utils": "^3.0.0-alpha.5",
910
935
  "@types/events": "^3.0.0",
@@ -1656,9 +1681,6 @@ var Geocoder = (function (exports) {
1656
1681
  addConnector(this);
1657
1682
  }
1658
1683
  }
1659
- static create(options) {
1660
- return new this(options);
1661
- }
1662
1684
  /**
1663
1685
  * Clear the cache.
1664
1686
  */
@@ -1839,7 +1861,7 @@ var Geocoder = (function (exports) {
1839
1861
  this._cleanActiveRequest(id);
1840
1862
  }
1841
1863
  });
1842
- if (cache && method === "GET") {
1864
+ if (method === "GET") {
1843
1865
  const cacheOptions = cacheProps ? cacheProps : __spreadProps$2(__spreadValues$5({}, objectRemoveEmpty({
1844
1866
  headers,
1845
1867
  withCredentials,
@@ -1849,12 +1871,10 @@ var Geocoder = (function (exports) {
1849
1871
  })), {
1850
1872
  params
1851
1873
  });
1852
- return this.cache.add(
1853
- cacheName || url,
1854
- createPromise,
1855
- cacheOptions,
1856
- false
1857
- );
1874
+ return this.cache.add(cacheName || url, createPromise, {
1875
+ props: cacheOptions,
1876
+ expirationTime: cache ? void 0 : 500
1877
+ });
1858
1878
  }
1859
1879
  return createPromise();
1860
1880
  });
@@ -2312,13 +2332,15 @@ var Geocoder = (function (exports) {
2312
2332
  class NgwConnectorExtended extends NgwConnector {
2313
2333
  constructor(options) {
2314
2334
  super(options);
2315
- this.options = options;
2316
2335
  __publicField$2(this, "resources");
2317
2336
  this.resources = new ResourcesControl({
2318
2337
  connector: this,
2319
2338
  cacheId: options.cacheId
2320
2339
  });
2321
2340
  }
2341
+ static create(options) {
2342
+ return new this(options);
2343
+ }
2322
2344
  /**
2323
2345
  * Clear the cache.
2324
2346
  */