@nextgis/ngw-connector 3.0.0-alpha.13 → 3.0.0-alpha.16
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.
- package/lib/index.d.ts +71 -14
- package/lib/ngw-connector.cjs.js +33 -28
- package/lib/ngw-connector.cjs.js.map +1 -1
- package/lib/ngw-connector.cjs.prod.js +1 -1
- package/lib/ngw-connector.cjs.prod.js.map +1 -1
- package/lib/ngw-connector.esm-browser.js +31 -26
- package/lib/ngw-connector.esm-browser.js.map +1 -1
- package/lib/ngw-connector.esm-browser.prod.js +1 -1
- package/lib/ngw-connector.esm-browser.prod.js.map +1 -1
- package/lib/ngw-connector.esm-bundler.js +31 -26
- package/lib/ngw-connector.esm-bundler.js.map +1 -1
- package/lib/ngw-connector.esm-bundler.prod.js +1 -1
- package/lib/ngw-connector.esm-bundler.prod.js.map +1 -1
- package/lib/ngw-connector.global.js +31 -26
- package/lib/ngw-connector.global.js.map +1 -1
- package/lib/ngw-connector.global.prod.js +1 -1
- package/lib/ngw-connector.global.prod.js.map +1 -1
- package/package.json +2 -2
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
/** Bundle of @nextgis/ngw-connector; version: 3.0.0-alpha.
|
|
1
|
+
/** Bundle of @nextgis/ngw-connector; version: 3.0.0-alpha.16; author: NextGIS */
|
|
2
2
|
import { isObject as isObject$1, objectRemoveEmpty, fixUrlStr, objectDeepEqual, defined } from '@nextgis/utils';
|
|
3
3
|
import Cache from '@nextgis/cache';
|
|
4
4
|
import { EventEmitter } from 'events';
|
|
@@ -105,7 +105,7 @@ function apiRequest(opt) {
|
|
|
105
105
|
|
|
106
106
|
var pkg = {
|
|
107
107
|
name: "@nextgis/ngw-connector",
|
|
108
|
-
version: "3.0.0-alpha.
|
|
108
|
+
version: "3.0.0-alpha.16",
|
|
109
109
|
_priority: 12,
|
|
110
110
|
description: "A lightweight HTTP client optimized for use with NextGIS Web API",
|
|
111
111
|
main: "index.js",
|
|
@@ -501,7 +501,7 @@ function generateUrl(path, query) {
|
|
|
501
501
|
}
|
|
502
502
|
function request(path, options, cacheEngine) {
|
|
503
503
|
return __async$3(this, null, function* () {
|
|
504
|
-
var _b;
|
|
504
|
+
var _b, _c;
|
|
505
505
|
const defaults = {
|
|
506
506
|
method: "GET",
|
|
507
507
|
credentials: "same-origin",
|
|
@@ -526,6 +526,7 @@ function request(path, options, cacheEngine) {
|
|
|
526
526
|
"query",
|
|
527
527
|
"json"
|
|
528
528
|
]);
|
|
529
|
+
opt.method = (_b = opt.method) == null ? void 0 : _b.toUpperCase();
|
|
529
530
|
if (withCredentials) {
|
|
530
531
|
opt.credentials = "include";
|
|
531
532
|
}
|
|
@@ -583,15 +584,24 @@ function request(path, options, cacheEngine) {
|
|
|
583
584
|
}
|
|
584
585
|
return body;
|
|
585
586
|
});
|
|
586
|
-
if (cacheEngine
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
587
|
+
if (cacheEngine) {
|
|
588
|
+
if (((_c = opt.method) == null ? void 0 : _c.toUpperCase()) === "GET") {
|
|
589
|
+
if (cache !== false) {
|
|
590
|
+
const props = cacheProps ? cacheProps : __spreadValues$3({}, objectRemoveEmpty({
|
|
591
|
+
withCredentials,
|
|
592
|
+
responseType
|
|
593
|
+
}));
|
|
594
|
+
return cacheEngine.add(cacheName || url, makeRequest, {
|
|
595
|
+
props,
|
|
596
|
+
expirationTime: cache ? void 0 : 500
|
|
597
|
+
});
|
|
598
|
+
}
|
|
599
|
+
} else {
|
|
600
|
+
const ignoredForClean = ["api/feature_layer/identify"];
|
|
601
|
+
if (ignoredForClean.every((part) => !path.includes(part))) {
|
|
602
|
+
cacheEngine.clean();
|
|
603
|
+
}
|
|
604
|
+
}
|
|
595
605
|
}
|
|
596
606
|
return makeRequest();
|
|
597
607
|
});
|
|
@@ -896,12 +906,16 @@ class NgwConnector {
|
|
|
896
906
|
__publicField$2(this, "user");
|
|
897
907
|
__publicField$2(this, "cache");
|
|
898
908
|
__publicField$2(this, "withCredentials");
|
|
909
|
+
// Dedicated cache for route requests, as these are executed before any other requests.
|
|
910
|
+
// This cache does not need to be cleared during the session.
|
|
911
|
+
__publicField$2(this, "routeCache");
|
|
899
912
|
__publicField$2(this, "client", `NextGIS-NGW-Connector/${pkg.version}`);
|
|
900
913
|
__publicField$2(this, "routeStr", "/api/component/pyramid/route");
|
|
901
914
|
__publicField$2(this, "activeRequests", {});
|
|
902
915
|
__publicField$2(this, "requestTransform");
|
|
903
916
|
const exist = findConnector(options);
|
|
904
917
|
this.cache = new Cache({ namespace: options.cacheId });
|
|
918
|
+
this.routeCache = new Cache({ namespace: "routecache" });
|
|
905
919
|
if (exist) {
|
|
906
920
|
return exist;
|
|
907
921
|
} else {
|
|
@@ -962,19 +976,9 @@ class NgwConnector {
|
|
|
962
976
|
}
|
|
963
977
|
}
|
|
964
978
|
const routeUrl = `${this.routeStr}?client=${this.client}`;
|
|
965
|
-
return this.
|
|
966
|
-
|
|
967
|
-
{}
|
|
968
|
-
{
|
|
969
|
-
cacheName: "route",
|
|
970
|
-
signal,
|
|
971
|
-
cache: true,
|
|
972
|
-
cacheProps: {
|
|
973
|
-
id: this.id,
|
|
974
|
-
auth,
|
|
975
|
-
baseUrl: this.options.baseUrl
|
|
976
|
-
}
|
|
977
|
-
}
|
|
979
|
+
return this.routeCache.add(
|
|
980
|
+
this.options.baseUrl || String(this.id),
|
|
981
|
+
() => this.makeQuery(routeUrl, null, { signal, cache: false })
|
|
978
982
|
);
|
|
979
983
|
});
|
|
980
984
|
}
|
|
@@ -995,6 +999,7 @@ class NgwConnector {
|
|
|
995
999
|
removeConnector(this);
|
|
996
1000
|
this.options.auth = void 0;
|
|
997
1001
|
this.user = void 0;
|
|
1002
|
+
this.routeCache.clean();
|
|
998
1003
|
this.clearCache();
|
|
999
1004
|
this.emitter.emit("logout");
|
|
1000
1005
|
}
|
|
@@ -1101,7 +1106,7 @@ class NgwConnector {
|
|
|
1101
1106
|
this._cleanActiveRequest(id);
|
|
1102
1107
|
}
|
|
1103
1108
|
});
|
|
1104
|
-
if (method === "GET") {
|
|
1109
|
+
if (method === "GET" && cache !== false) {
|
|
1105
1110
|
const cacheOptions = cacheProps ? cacheProps : __spreadProps$1(__spreadValues$1({}, objectRemoveEmpty({
|
|
1106
1111
|
headers,
|
|
1107
1112
|
withCredentials,
|