@nextgis/ngw-connector 2.2.3 → 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.
- package/lib/index.d.ts +13 -4
- package/lib/ngw-connector.cjs.js +30 -30
- 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 +43 -67
- 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 -34
- 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 +43 -67
- 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 +6 -6
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
/** Bundle of @nextgis/ngw-connector; version: 2.
|
|
1
|
+
/** Bundle of @nextgis/ngw-connector; version: 2.3.0; author: NextGIS */
|
|
2
2
|
var domain;
|
|
3
3
|
|
|
4
4
|
// This constructor is used to store event handlers. Instantiating this is
|
|
@@ -480,19 +480,15 @@ function full(val) {
|
|
|
480
480
|
|
|
481
481
|
function isEqual(a, b, o, p) {
|
|
482
482
|
if (a instanceof Array) {
|
|
483
|
-
if (!(b instanceof Array))
|
|
484
|
-
return false;
|
|
483
|
+
if (!(b instanceof Array)) return false;
|
|
485
484
|
return b.sort().join("") === a.sort().join("");
|
|
486
485
|
} else if (a instanceof Date) {
|
|
487
|
-
if (!(b instanceof Date))
|
|
488
|
-
return false;
|
|
486
|
+
if (!(b instanceof Date)) return false;
|
|
489
487
|
return "" + a === "" + b;
|
|
490
488
|
} else if (a instanceof Function) {
|
|
491
|
-
if (!(b instanceof Function))
|
|
492
|
-
return false;
|
|
489
|
+
if (!(b instanceof Function)) return false;
|
|
493
490
|
} else if (a instanceof Object) {
|
|
494
|
-
if (!(b instanceof Object))
|
|
495
|
-
return false;
|
|
491
|
+
if (!(b instanceof Object)) return false;
|
|
496
492
|
if (a === o) {
|
|
497
493
|
return b === p;
|
|
498
494
|
} else {
|
|
@@ -504,10 +500,8 @@ function isEqual(a, b, o, p) {
|
|
|
504
500
|
function objectDeepEqual(o, p) {
|
|
505
501
|
const keysO = Object.keys(o).sort();
|
|
506
502
|
const keysP = Object.keys(p).sort();
|
|
507
|
-
if (keysO.length !== keysP.length)
|
|
508
|
-
|
|
509
|
-
if (keysO.join("") !== keysP.join(""))
|
|
510
|
-
return false;
|
|
503
|
+
if (keysO.length !== keysP.length) return false;
|
|
504
|
+
if (keysO.join("") !== keysP.join("")) return false;
|
|
511
505
|
for (let i = 0; i < keysO.length; i++) {
|
|
512
506
|
const oVal = o[keysO[i]];
|
|
513
507
|
const pVal = p[keysP[i]];
|
|
@@ -536,10 +530,7 @@ function fixUrlStr(url) {
|
|
|
536
530
|
|
|
537
531
|
var __defProp$a = Object.defineProperty;
|
|
538
532
|
var __defNormalProp$a = (obj, key, value) => key in obj ? __defProp$a(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
539
|
-
var __publicField$a = (obj, key, value) =>
|
|
540
|
-
__defNormalProp$a(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
541
|
-
return value;
|
|
542
|
-
};
|
|
533
|
+
var __publicField$a = (obj, key, value) => __defNormalProp$a(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
543
534
|
const _Cache = class _Cache {
|
|
544
535
|
constructor(options = {}) {
|
|
545
536
|
__publicField$a(this, "cache", []);
|
|
@@ -666,10 +657,7 @@ let Cache = _Cache;
|
|
|
666
657
|
|
|
667
658
|
var __defProp$9 = Object.defineProperty;
|
|
668
659
|
var __defNormalProp$9 = (obj, key, value) => key in obj ? __defProp$9(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
669
|
-
var __publicField$9 = (obj, key, value) =>
|
|
670
|
-
__defNormalProp$9(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
671
|
-
return value;
|
|
672
|
-
};
|
|
660
|
+
var __publicField$9 = (obj, key, value) => __defNormalProp$9(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
673
661
|
class CancelError extends Error {
|
|
674
662
|
constructor() {
|
|
675
663
|
super();
|
|
@@ -680,10 +668,7 @@ class CancelError extends Error {
|
|
|
680
668
|
|
|
681
669
|
var __defProp$8 = Object.defineProperty;
|
|
682
670
|
var __defNormalProp$8 = (obj, key, value) => key in obj ? __defProp$8(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
683
|
-
var __publicField$8 = (obj, key, value) =>
|
|
684
|
-
__defNormalProp$8(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
685
|
-
return value;
|
|
686
|
-
};
|
|
671
|
+
var __publicField$8 = (obj, key, value) => __defNormalProp$8(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
687
672
|
class PromiseControl {
|
|
688
673
|
constructor(options = {}) {
|
|
689
674
|
this.options = options;
|
|
@@ -765,10 +750,7 @@ class PromiseControl {
|
|
|
765
750
|
|
|
766
751
|
var __defProp$7 = Object.defineProperty;
|
|
767
752
|
var __defNormalProp$7 = (obj, key, value) => key in obj ? __defProp$7(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
768
|
-
var __publicField$7 = (obj, key, value) =>
|
|
769
|
-
__defNormalProp$7(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
770
|
-
return value;
|
|
771
|
-
};
|
|
753
|
+
var __publicField$7 = (obj, key, value) => __defNormalProp$7(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
772
754
|
class TimeoutError extends Error {
|
|
773
755
|
constructor() {
|
|
774
756
|
super();
|
|
@@ -779,10 +761,7 @@ class TimeoutError extends Error {
|
|
|
779
761
|
|
|
780
762
|
var __defProp$6 = Object.defineProperty;
|
|
781
763
|
var __defNormalProp$6 = (obj, key, value) => key in obj ? __defProp$6(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
782
|
-
var __publicField$6 = (obj, key, value) =>
|
|
783
|
-
__defNormalProp$6(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
784
|
-
return value;
|
|
785
|
-
};
|
|
764
|
+
var __publicField$6 = (obj, key, value) => __defNormalProp$6(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
786
765
|
var _a;
|
|
787
766
|
const handleCallback = (resolve, reject, callback, r) => {
|
|
788
767
|
try {
|
|
@@ -792,6 +771,7 @@ const handleCallback = (resolve, reject, callback, r) => {
|
|
|
792
771
|
}
|
|
793
772
|
};
|
|
794
773
|
let ID$1 = 0;
|
|
774
|
+
_a = Symbol.toStringTag;
|
|
795
775
|
const _CancelablePromise = class _CancelablePromise {
|
|
796
776
|
constructor(executor, timeout) {
|
|
797
777
|
// @ts-ignore
|
|
@@ -971,7 +951,6 @@ const _CancelablePromise = class _CancelablePromise {
|
|
|
971
951
|
this._promise = void 0;
|
|
972
952
|
}
|
|
973
953
|
};
|
|
974
|
-
_a = Symbol.toStringTag;
|
|
975
954
|
__publicField$6(_CancelablePromise, "CancelError", CancelError);
|
|
976
955
|
__publicField$6(_CancelablePromise, "TimeoutError", TimeoutError);
|
|
977
956
|
__publicField$6(_CancelablePromise, "PromiseControl", PromiseControl);
|
|
@@ -980,10 +959,7 @@ Object.setPrototypeOf(CancelablePromise.prototype, Promise.prototype);
|
|
|
980
959
|
|
|
981
960
|
var __defProp$5 = Object.defineProperty;
|
|
982
961
|
var __defNormalProp$5 = (obj, key, value) => key in obj ? __defProp$5(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
983
|
-
var __publicField$5 = (obj, key, value) =>
|
|
984
|
-
__defNormalProp$5(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
985
|
-
return value;
|
|
986
|
-
};
|
|
962
|
+
var __publicField$5 = (obj, key, value) => __defNormalProp$5(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
987
963
|
class NgwError extends Error {
|
|
988
964
|
constructor(er) {
|
|
989
965
|
super();
|
|
@@ -1002,10 +978,7 @@ class NgwError extends Error {
|
|
|
1002
978
|
|
|
1003
979
|
var __defProp$4 = Object.defineProperty;
|
|
1004
980
|
var __defNormalProp$4 = (obj, key, value) => key in obj ? __defProp$4(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
1005
|
-
var __publicField$4 = (obj, key, value) =>
|
|
1006
|
-
__defNormalProp$4(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
1007
|
-
return value;
|
|
1008
|
-
};
|
|
981
|
+
var __publicField$4 = (obj, key, value) => __defNormalProp$4(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
1009
982
|
class ResourceNotFoundError extends NgwError {
|
|
1010
983
|
constructor(obj) {
|
|
1011
984
|
super(obj);
|
|
@@ -1063,10 +1036,7 @@ var __spreadValues$1 = (a, b) => {
|
|
|
1063
1036
|
return a;
|
|
1064
1037
|
};
|
|
1065
1038
|
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
1066
|
-
var __publicField$3 = (obj, key, value) =>
|
|
1067
|
-
__defNormalProp$3(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
1068
|
-
return value;
|
|
1069
|
-
};
|
|
1039
|
+
var __publicField$3 = (obj, key, value) => __defNormalProp$3(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
1070
1040
|
var __async = (__this, __arguments, generator) => {
|
|
1071
1041
|
return new Promise((resolve, reject) => {
|
|
1072
1042
|
var fulfilled = (value) => {
|
|
@@ -1088,9 +1058,14 @@ var __async = (__this, __arguments, generator) => {
|
|
|
1088
1058
|
});
|
|
1089
1059
|
};
|
|
1090
1060
|
class ResourcesControl {
|
|
1091
|
-
constructor(
|
|
1061
|
+
constructor({
|
|
1062
|
+
connector,
|
|
1063
|
+
cacheId
|
|
1064
|
+
}) {
|
|
1065
|
+
__publicField$3(this, "cache");
|
|
1066
|
+
__publicField$3(this, "connector");
|
|
1092
1067
|
this.connector = connector;
|
|
1093
|
-
|
|
1068
|
+
this.cache = new Cache({ namespace: cacheId });
|
|
1094
1069
|
}
|
|
1095
1070
|
// -------------------------------------------------------------------------
|
|
1096
1071
|
// Resource Methods
|
|
@@ -1103,7 +1078,7 @@ class ResourcesControl {
|
|
|
1103
1078
|
* Fetching resource would be cached to speed up next call
|
|
1104
1079
|
*/
|
|
1105
1080
|
getOne(resource, requestOptions) {
|
|
1106
|
-
const cache =
|
|
1081
|
+
const cache = this.cache;
|
|
1107
1082
|
const forCache = {};
|
|
1108
1083
|
const opt = __spreadProps(__spreadValues$1({}, requestOptions), { cache: false });
|
|
1109
1084
|
if (typeof resource === "string") {
|
|
@@ -1354,10 +1329,7 @@ function removeConnector(connector) {
|
|
|
1354
1329
|
|
|
1355
1330
|
var __defProp$2 = Object.defineProperty;
|
|
1356
1331
|
var __defNormalProp$2 = (obj, key, value) => key in obj ? __defProp$2(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
1357
|
-
var __publicField$2 = (obj, key, value) =>
|
|
1358
|
-
__defNormalProp$2(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
1359
|
-
return value;
|
|
1360
|
-
};
|
|
1332
|
+
var __publicField$2 = (obj, key, value) => __defNormalProp$2(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
1361
1333
|
class InsufficientPermissionsError extends NgwError {
|
|
1362
1334
|
constructor(obj) {
|
|
1363
1335
|
super(obj);
|
|
@@ -1437,10 +1409,7 @@ function apiRequest(opt) {
|
|
|
1437
1409
|
|
|
1438
1410
|
var __defProp$1 = Object.defineProperty;
|
|
1439
1411
|
var __defNormalProp$1 = (obj, key, value) => key in obj ? __defProp$1(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
1440
|
-
var __publicField$1 = (obj, key, value) =>
|
|
1441
|
-
__defNormalProp$1(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
1442
|
-
return value;
|
|
1443
|
-
};
|
|
1412
|
+
var __publicField$1 = (obj, key, value) => __defNormalProp$1(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
1444
1413
|
class NetworkError extends Error {
|
|
1445
1414
|
constructor(url) {
|
|
1446
1415
|
super();
|
|
@@ -1549,10 +1518,7 @@ var __spreadValues = (a, b) => {
|
|
|
1549
1518
|
}
|
|
1550
1519
|
return a;
|
|
1551
1520
|
};
|
|
1552
|
-
var __publicField = (obj, key, value) =>
|
|
1553
|
-
__defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
1554
|
-
return value;
|
|
1555
|
-
};
|
|
1521
|
+
var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
1556
1522
|
let ID = 0;
|
|
1557
1523
|
class NgwConnector {
|
|
1558
1524
|
constructor(options) {
|
|
@@ -1561,10 +1527,12 @@ class NgwConnector {
|
|
|
1561
1527
|
__publicField(this, "emitter", new EventEmitter());
|
|
1562
1528
|
__publicField(this, "user");
|
|
1563
1529
|
__publicField(this, "resources");
|
|
1530
|
+
__publicField(this, "cache");
|
|
1564
1531
|
__publicField(this, "routeStr", "/api/component/pyramid/route");
|
|
1565
1532
|
__publicField(this, "activeRequests", []);
|
|
1566
1533
|
__publicField(this, "requestTransform");
|
|
1567
1534
|
const exist = findConnector(options);
|
|
1535
|
+
this.cache = new Cache({ namespace: options.cacheId });
|
|
1568
1536
|
if (exist) {
|
|
1569
1537
|
return exist;
|
|
1570
1538
|
} else {
|
|
@@ -1574,13 +1542,23 @@ class NgwConnector {
|
|
|
1574
1542
|
if (this.options.requestTransform) {
|
|
1575
1543
|
this.requestTransform = this.options.requestTransform;
|
|
1576
1544
|
}
|
|
1577
|
-
this.resources = new ResourcesControl(
|
|
1545
|
+
this.resources = new ResourcesControl({
|
|
1546
|
+
connector: this,
|
|
1547
|
+
cacheId: options.cacheId
|
|
1548
|
+
});
|
|
1578
1549
|
addConnector(this);
|
|
1579
1550
|
}
|
|
1580
1551
|
}
|
|
1581
1552
|
static create(options) {
|
|
1582
1553
|
return new this(options);
|
|
1583
1554
|
}
|
|
1555
|
+
/**
|
|
1556
|
+
* Clear the cache.
|
|
1557
|
+
*/
|
|
1558
|
+
clearCache() {
|
|
1559
|
+
this.cache.clean();
|
|
1560
|
+
this.resources.cache.clean();
|
|
1561
|
+
}
|
|
1584
1562
|
setRequestTransform(requestTransform) {
|
|
1585
1563
|
this.requestTransform = requestTransform;
|
|
1586
1564
|
}
|
|
@@ -1608,7 +1586,6 @@ class NgwConnector {
|
|
|
1608
1586
|
* ```
|
|
1609
1587
|
*/
|
|
1610
1588
|
connect() {
|
|
1611
|
-
const cache = new Cache();
|
|
1612
1589
|
const auth = this.options.auth;
|
|
1613
1590
|
const makeConnect = () => new CancelablePromise((resolve, reject) => {
|
|
1614
1591
|
const makeQuery = () => {
|
|
@@ -1628,7 +1605,7 @@ class NgwConnector {
|
|
|
1628
1605
|
}
|
|
1629
1606
|
return makeQuery();
|
|
1630
1607
|
});
|
|
1631
|
-
return cache.add("route", makeConnect, {
|
|
1608
|
+
return this.cache.add("route", makeConnect, {
|
|
1632
1609
|
id: this.id,
|
|
1633
1610
|
auth,
|
|
1634
1611
|
baseUrl: this.options.baseUrl
|
|
@@ -1651,8 +1628,8 @@ class NgwConnector {
|
|
|
1651
1628
|
removeConnector(this);
|
|
1652
1629
|
this.options.auth = void 0;
|
|
1653
1630
|
this.user = void 0;
|
|
1631
|
+
this.clearCache();
|
|
1654
1632
|
this.emitter.emit("logout");
|
|
1655
|
-
this.resources.cache.clean();
|
|
1656
1633
|
}
|
|
1657
1634
|
getUserInfo(credentials, options) {
|
|
1658
1635
|
if (this.user && this.user.id) {
|
|
@@ -1737,8 +1714,7 @@ class NgwConnector {
|
|
|
1737
1714
|
const params = objectRemoveEmpty(params_);
|
|
1738
1715
|
const makeApiRequest = () => apiRequest({ name, params, requestOptions, connector: this });
|
|
1739
1716
|
if (requestOptions.cache && method === "GET") {
|
|
1740
|
-
|
|
1741
|
-
return cache.add(name, makeApiRequest, __spreadValues({
|
|
1717
|
+
return this.cache.add(name, makeApiRequest, __spreadValues({
|
|
1742
1718
|
params
|
|
1743
1719
|
}, objectRemoveEmpty({
|
|
1744
1720
|
headers,
|