@nextgis/ngw-map 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/ngw-map; version: 3.0.0-alpha.6; author: NextGIS */
1
+ /** Bundle of @nextgis/ngw-map; version: 3.0.0-alpha.8; author: NextGIS */
2
2
  import { EventEmitter } from 'events';
3
3
  import { getIcon } from '@nextgis/icons';
4
4
  import { NgwKit, fetchNgwLayerItem, fetchNgwLayerItems, fetchNgwLayerFeature, fetchNgwLayerFeatureCollection, fetchIdentifyItem, fetchIdentifyGeoJson, createNgwLayerAdapter, fetchNgwExtent, sendIdentifyRequest, getCompanyLogo, getIdentifyItems, createIdentifyItem } from '@nextgis/ngw-kit';
@@ -1,4 +1,4 @@
1
- /** Bundle of @nextgis/ngw-map; version: 3.0.0-alpha.6; author: NextGIS */
1
+ /** Bundle of @nextgis/ngw-map; version: 3.0.0-alpha.8; author: NextGIS */
2
2
  var NgwMap = (function (exports) {
3
3
  'use strict';
4
4
 
@@ -868,10 +868,23 @@ var NgwMap = (function (exports) {
868
868
  * });
869
869
  * ```
870
870
  */
871
- addFull(key, valueToSet, props) {
872
- return this.add(key, valueToSet, props, true);
873
- }
874
- add(key, valueToSet, props, onlyFull) {
871
+ addFull(key, valueToSet, propsOrOptions, expirationTime) {
872
+ if (typeof propsOrOptions === "object" && "valueToSet" in propsOrOptions) {
873
+ propsOrOptions.onlyFull = true;
874
+ }
875
+ return this.add(key, valueToSet, propsOrOptions, true, expirationTime);
876
+ }
877
+ add(key, valueToSet, propsOrOptions, onlyFull, expirationTime) {
878
+ let opt;
879
+ let props;
880
+ if (typeof propsOrOptions === "object" && "valueToSet" in propsOrOptions) {
881
+ opt = propsOrOptions;
882
+ onlyFull = opt.onlyFull;
883
+ expirationTime = opt.expirationTime;
884
+ props = opt.props;
885
+ } else {
886
+ props = propsOrOptions;
887
+ }
875
888
  const exist = this._find(key, props);
876
889
  if (!exist) {
877
890
  let value;
@@ -881,10 +894,12 @@ var NgwMap = (function (exports) {
881
894
  value = valueToSet;
882
895
  }
883
896
  const nonEmptyProps = props && JSON.parse(JSON.stringify(objectRemoveEmpty(props)));
897
+ expirationTime = expirationTime ? Date.now() + expirationTime : void 0;
884
898
  const cacheItem = {
885
899
  key,
886
900
  value,
887
- props: nonEmptyProps
901
+ props: nonEmptyProps,
902
+ expirationTime
888
903
  };
889
904
  if (onlyFull && !full(value)) {
890
905
  return value;
@@ -911,9 +926,19 @@ var NgwMap = (function (exports) {
911
926
  }
912
927
  match(key, props) {
913
928
  const cacheRecord = this._find(key, props);
929
+ if (cacheRecord && cacheRecord.expirationTime && Date.now() > cacheRecord.expirationTime) {
930
+ this.delete(cacheRecord);
931
+ return void 0;
932
+ }
914
933
  return cacheRecord == null ? void 0 : cacheRecord.value;
915
934
  }
916
935
  matchAll(key, props) {
936
+ const now = Date.now();
937
+ this.cache.forEach((item) => {
938
+ if (item.expirationTime && now > item.expirationTime) {
939
+ this.delete(item);
940
+ }
941
+ });
917
942
  if (key) {
918
943
  return this.cache.filter((x) => this._filter(x, key, props)).map((x) => x.value);
919
944
  }
@@ -943,7 +968,7 @@ var NgwMap = (function (exports) {
943
968
 
944
969
  var pkg = {
945
970
  name: "@nextgis/ngw-connector",
946
- version: "3.0.0-alpha.6",
971
+ version: "3.0.0-alpha.8",
947
972
  _priority: 12,
948
973
  description: "A lightweight HTTP client optimized for use with NextGIS Web API",
949
974
  main: "index.js",
@@ -952,7 +977,7 @@ var NgwMap = (function (exports) {
952
977
  jsdelivr: "lib/ngw-connector.global.prod.js",
953
978
  types: "lib/index.d.ts",
954
979
  dependencies: {
955
- "@nextgis/cache": "^3.0.0-alpha.5",
980
+ "@nextgis/cache": "^3.0.0-alpha.7",
956
981
  "@nextgis/cancelable-promise": "^3.0.0-alpha.5",
957
982
  "@nextgis/utils": "^3.0.0-alpha.5",
958
983
  "@types/events": "^3.0.0",
@@ -1704,9 +1729,6 @@ var NgwMap = (function (exports) {
1704
1729
  addConnector(this);
1705
1730
  }
1706
1731
  }
1707
- static create(options) {
1708
- return new this(options);
1709
- }
1710
1732
  /**
1711
1733
  * Clear the cache.
1712
1734
  */
@@ -1887,7 +1909,7 @@ var NgwMap = (function (exports) {
1887
1909
  this._cleanActiveRequest(id);
1888
1910
  }
1889
1911
  });
1890
- if (cache && method === "GET") {
1912
+ if (method === "GET") {
1891
1913
  const cacheOptions = cacheProps ? cacheProps : __spreadProps$g(__spreadValues$v({}, objectRemoveEmpty({
1892
1914
  headers,
1893
1915
  withCredentials,
@@ -1897,12 +1919,10 @@ var NgwMap = (function (exports) {
1897
1919
  })), {
1898
1920
  params
1899
1921
  });
1900
- return this.cache.add(
1901
- cacheName || url,
1902
- createPromise,
1903
- cacheOptions,
1904
- false
1905
- );
1922
+ return this.cache.add(cacheName || url, createPromise, {
1923
+ props: cacheOptions,
1924
+ expirationTime: cache ? void 0 : 500
1925
+ });
1906
1926
  }
1907
1927
  return createPromise();
1908
1928
  });
@@ -2366,6 +2386,9 @@ var NgwMap = (function (exports) {
2366
2386
  cacheId: options.cacheId
2367
2387
  });
2368
2388
  }
2389
+ static create(options) {
2390
+ return new this(options);
2391
+ }
2369
2392
  /**
2370
2393
  * Clear the cache.
2371
2394
  */