@nextgis/ngw-connector 2.2.3 → 2.4.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 +46 -40
- 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 +59 -77
- 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 +47 -44
- 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 +59 -77
- 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.4.0; author: NextGIS */
|
|
2
2
|
var NgwConnector = (function () {
|
|
3
3
|
'use strict';
|
|
4
4
|
|
|
@@ -483,19 +483,15 @@ var NgwConnector = (function () {
|
|
|
483
483
|
|
|
484
484
|
function isEqual(a, b, o, p) {
|
|
485
485
|
if (a instanceof Array) {
|
|
486
|
-
if (!(b instanceof Array))
|
|
487
|
-
return false;
|
|
486
|
+
if (!(b instanceof Array)) return false;
|
|
488
487
|
return b.sort().join("") === a.sort().join("");
|
|
489
488
|
} else if (a instanceof Date) {
|
|
490
|
-
if (!(b instanceof Date))
|
|
491
|
-
return false;
|
|
489
|
+
if (!(b instanceof Date)) return false;
|
|
492
490
|
return "" + a === "" + b;
|
|
493
491
|
} else if (a instanceof Function) {
|
|
494
|
-
if (!(b instanceof Function))
|
|
495
|
-
return false;
|
|
492
|
+
if (!(b instanceof Function)) return false;
|
|
496
493
|
} else if (a instanceof Object) {
|
|
497
|
-
if (!(b instanceof Object))
|
|
498
|
-
return false;
|
|
494
|
+
if (!(b instanceof Object)) return false;
|
|
499
495
|
if (a === o) {
|
|
500
496
|
return b === p;
|
|
501
497
|
} else {
|
|
@@ -507,10 +503,8 @@ var NgwConnector = (function () {
|
|
|
507
503
|
function objectDeepEqual(o, p) {
|
|
508
504
|
const keysO = Object.keys(o).sort();
|
|
509
505
|
const keysP = Object.keys(p).sort();
|
|
510
|
-
if (keysO.length !== keysP.length)
|
|
511
|
-
|
|
512
|
-
if (keysO.join("") !== keysP.join(""))
|
|
513
|
-
return false;
|
|
506
|
+
if (keysO.length !== keysP.length) return false;
|
|
507
|
+
if (keysO.join("") !== keysP.join("")) return false;
|
|
514
508
|
for (let i = 0; i < keysO.length; i++) {
|
|
515
509
|
const oVal = o[keysO[i]];
|
|
516
510
|
const pVal = p[keysP[i]];
|
|
@@ -539,10 +533,7 @@ var NgwConnector = (function () {
|
|
|
539
533
|
|
|
540
534
|
var __defProp$a = Object.defineProperty;
|
|
541
535
|
var __defNormalProp$a = (obj, key, value) => key in obj ? __defProp$a(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
542
|
-
var __publicField$a = (obj, key, value) =>
|
|
543
|
-
__defNormalProp$a(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
544
|
-
return value;
|
|
545
|
-
};
|
|
536
|
+
var __publicField$a = (obj, key, value) => __defNormalProp$a(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
546
537
|
const _Cache = class _Cache {
|
|
547
538
|
constructor(options = {}) {
|
|
548
539
|
__publicField$a(this, "cache", []);
|
|
@@ -669,10 +660,7 @@ var NgwConnector = (function () {
|
|
|
669
660
|
|
|
670
661
|
var __defProp$9 = Object.defineProperty;
|
|
671
662
|
var __defNormalProp$9 = (obj, key, value) => key in obj ? __defProp$9(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
672
|
-
var __publicField$9 = (obj, key, value) =>
|
|
673
|
-
__defNormalProp$9(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
674
|
-
return value;
|
|
675
|
-
};
|
|
663
|
+
var __publicField$9 = (obj, key, value) => __defNormalProp$9(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
676
664
|
class CancelError extends Error {
|
|
677
665
|
constructor() {
|
|
678
666
|
super();
|
|
@@ -683,10 +671,7 @@ var NgwConnector = (function () {
|
|
|
683
671
|
|
|
684
672
|
var __defProp$8 = Object.defineProperty;
|
|
685
673
|
var __defNormalProp$8 = (obj, key, value) => key in obj ? __defProp$8(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
686
|
-
var __publicField$8 = (obj, key, value) =>
|
|
687
|
-
__defNormalProp$8(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
688
|
-
return value;
|
|
689
|
-
};
|
|
674
|
+
var __publicField$8 = (obj, key, value) => __defNormalProp$8(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
690
675
|
class PromiseControl {
|
|
691
676
|
constructor(options = {}) {
|
|
692
677
|
this.options = options;
|
|
@@ -768,10 +753,7 @@ var NgwConnector = (function () {
|
|
|
768
753
|
|
|
769
754
|
var __defProp$7 = Object.defineProperty;
|
|
770
755
|
var __defNormalProp$7 = (obj, key, value) => key in obj ? __defProp$7(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
771
|
-
var __publicField$7 = (obj, key, value) =>
|
|
772
|
-
__defNormalProp$7(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
773
|
-
return value;
|
|
774
|
-
};
|
|
756
|
+
var __publicField$7 = (obj, key, value) => __defNormalProp$7(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
775
757
|
class TimeoutError extends Error {
|
|
776
758
|
constructor() {
|
|
777
759
|
super();
|
|
@@ -782,10 +764,7 @@ var NgwConnector = (function () {
|
|
|
782
764
|
|
|
783
765
|
var __defProp$6 = Object.defineProperty;
|
|
784
766
|
var __defNormalProp$6 = (obj, key, value) => key in obj ? __defProp$6(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
785
|
-
var __publicField$6 = (obj, key, value) =>
|
|
786
|
-
__defNormalProp$6(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
787
|
-
return value;
|
|
788
|
-
};
|
|
767
|
+
var __publicField$6 = (obj, key, value) => __defNormalProp$6(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
789
768
|
var _a;
|
|
790
769
|
const handleCallback = (resolve, reject, callback, r) => {
|
|
791
770
|
try {
|
|
@@ -795,6 +774,7 @@ var NgwConnector = (function () {
|
|
|
795
774
|
}
|
|
796
775
|
};
|
|
797
776
|
let ID$1 = 0;
|
|
777
|
+
_a = Symbol.toStringTag;
|
|
798
778
|
const _CancelablePromise = class _CancelablePromise {
|
|
799
779
|
constructor(executor, timeout) {
|
|
800
780
|
// @ts-ignore
|
|
@@ -974,7 +954,6 @@ var NgwConnector = (function () {
|
|
|
974
954
|
this._promise = void 0;
|
|
975
955
|
}
|
|
976
956
|
};
|
|
977
|
-
_a = Symbol.toStringTag;
|
|
978
957
|
__publicField$6(_CancelablePromise, "CancelError", CancelError);
|
|
979
958
|
__publicField$6(_CancelablePromise, "TimeoutError", TimeoutError);
|
|
980
959
|
__publicField$6(_CancelablePromise, "PromiseControl", PromiseControl);
|
|
@@ -983,10 +962,7 @@ var NgwConnector = (function () {
|
|
|
983
962
|
|
|
984
963
|
var __defProp$5 = Object.defineProperty;
|
|
985
964
|
var __defNormalProp$5 = (obj, key, value) => key in obj ? __defProp$5(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
986
|
-
var __publicField$5 = (obj, key, value) =>
|
|
987
|
-
__defNormalProp$5(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
988
|
-
return value;
|
|
989
|
-
};
|
|
965
|
+
var __publicField$5 = (obj, key, value) => __defNormalProp$5(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
990
966
|
class NgwError extends Error {
|
|
991
967
|
constructor(er) {
|
|
992
968
|
super();
|
|
@@ -1005,10 +981,7 @@ var NgwConnector = (function () {
|
|
|
1005
981
|
|
|
1006
982
|
var __defProp$4 = Object.defineProperty;
|
|
1007
983
|
var __defNormalProp$4 = (obj, key, value) => key in obj ? __defProp$4(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
1008
|
-
var __publicField$4 = (obj, key, value) =>
|
|
1009
|
-
__defNormalProp$4(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
1010
|
-
return value;
|
|
1011
|
-
};
|
|
984
|
+
var __publicField$4 = (obj, key, value) => __defNormalProp$4(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
1012
985
|
class ResourceNotFoundError extends NgwError {
|
|
1013
986
|
constructor(obj) {
|
|
1014
987
|
super(obj);
|
|
@@ -1066,10 +1039,7 @@ var NgwConnector = (function () {
|
|
|
1066
1039
|
return a;
|
|
1067
1040
|
};
|
|
1068
1041
|
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
1069
|
-
var __publicField$3 = (obj, key, value) =>
|
|
1070
|
-
__defNormalProp$3(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
1071
|
-
return value;
|
|
1072
|
-
};
|
|
1042
|
+
var __publicField$3 = (obj, key, value) => __defNormalProp$3(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
1073
1043
|
var __async = (__this, __arguments, generator) => {
|
|
1074
1044
|
return new Promise((resolve, reject) => {
|
|
1075
1045
|
var fulfilled = (value) => {
|
|
@@ -1091,9 +1061,14 @@ var NgwConnector = (function () {
|
|
|
1091
1061
|
});
|
|
1092
1062
|
};
|
|
1093
1063
|
class ResourcesControl {
|
|
1094
|
-
constructor(
|
|
1064
|
+
constructor({
|
|
1065
|
+
connector,
|
|
1066
|
+
cacheId
|
|
1067
|
+
}) {
|
|
1068
|
+
__publicField$3(this, "cache");
|
|
1069
|
+
__publicField$3(this, "connector");
|
|
1095
1070
|
this.connector = connector;
|
|
1096
|
-
|
|
1071
|
+
this.cache = new Cache({ namespace: cacheId });
|
|
1097
1072
|
}
|
|
1098
1073
|
// -------------------------------------------------------------------------
|
|
1099
1074
|
// Resource Methods
|
|
@@ -1106,7 +1081,7 @@ var NgwConnector = (function () {
|
|
|
1106
1081
|
* Fetching resource would be cached to speed up next call
|
|
1107
1082
|
*/
|
|
1108
1083
|
getOne(resource, requestOptions) {
|
|
1109
|
-
const cache =
|
|
1084
|
+
const cache = this.cache;
|
|
1110
1085
|
const forCache = {};
|
|
1111
1086
|
const opt = __spreadProps(__spreadValues$1({}, requestOptions), { cache: false });
|
|
1112
1087
|
if (typeof resource === "string") {
|
|
@@ -1135,7 +1110,10 @@ var NgwConnector = (function () {
|
|
|
1135
1110
|
}
|
|
1136
1111
|
return CancelablePromise.resolve(void 0);
|
|
1137
1112
|
};
|
|
1138
|
-
|
|
1113
|
+
if (requestOptions == null ? void 0 : requestOptions.cache) {
|
|
1114
|
+
return cache.addFull("resource", makeRequest, forCache);
|
|
1115
|
+
}
|
|
1116
|
+
return makeRequest();
|
|
1139
1117
|
}
|
|
1140
1118
|
getOneOrFail(resource, requestOptions) {
|
|
1141
1119
|
return this.getOne(resource, requestOptions).then((res) => {
|
|
@@ -1296,14 +1274,17 @@ var NgwConnector = (function () {
|
|
|
1296
1274
|
}
|
|
1297
1275
|
_fetchResourceById(id, requestOptions) {
|
|
1298
1276
|
const promise = () => this.connector.get("resource.item", requestOptions, { id });
|
|
1299
|
-
|
|
1300
|
-
|
|
1301
|
-
|
|
1302
|
-
|
|
1303
|
-
|
|
1304
|
-
|
|
1305
|
-
|
|
1306
|
-
|
|
1277
|
+
if (requestOptions == null ? void 0 : requestOptions.cache) {
|
|
1278
|
+
return this.cache.add("resource.item", promise, {
|
|
1279
|
+
id
|
|
1280
|
+
}).catch((er) => {
|
|
1281
|
+
if (!(er instanceof ResourceNotFoundError)) {
|
|
1282
|
+
throw er;
|
|
1283
|
+
}
|
|
1284
|
+
return void 0;
|
|
1285
|
+
});
|
|
1286
|
+
}
|
|
1287
|
+
return promise();
|
|
1307
1288
|
}
|
|
1308
1289
|
_fetchResourceBy(resource, requestOptions) {
|
|
1309
1290
|
return this.getMany(resource, requestOptions).then((resources) => {
|
|
@@ -1357,10 +1338,7 @@ var NgwConnector = (function () {
|
|
|
1357
1338
|
|
|
1358
1339
|
var __defProp$2 = Object.defineProperty;
|
|
1359
1340
|
var __defNormalProp$2 = (obj, key, value) => key in obj ? __defProp$2(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
1360
|
-
var __publicField$2 = (obj, key, value) =>
|
|
1361
|
-
__defNormalProp$2(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
1362
|
-
return value;
|
|
1363
|
-
};
|
|
1341
|
+
var __publicField$2 = (obj, key, value) => __defNormalProp$2(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
1364
1342
|
class InsufficientPermissionsError extends NgwError {
|
|
1365
1343
|
constructor(obj) {
|
|
1366
1344
|
super(obj);
|
|
@@ -1386,7 +1364,7 @@ var NgwConnector = (function () {
|
|
|
1386
1364
|
function apiRequest(opt) {
|
|
1387
1365
|
const params = opt.params;
|
|
1388
1366
|
return new CancelablePromise((resolve, reject) => {
|
|
1389
|
-
opt.connector.connect().then((apiItems) => {
|
|
1367
|
+
return opt.connector.connect().then((apiItems) => {
|
|
1390
1368
|
let apiItem = apiItems && apiItems[opt.name];
|
|
1391
1369
|
if (apiItem) {
|
|
1392
1370
|
apiItem = [...apiItem];
|
|
@@ -1440,10 +1418,7 @@ var NgwConnector = (function () {
|
|
|
1440
1418
|
|
|
1441
1419
|
var __defProp$1 = Object.defineProperty;
|
|
1442
1420
|
var __defNormalProp$1 = (obj, key, value) => key in obj ? __defProp$1(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
1443
|
-
var __publicField$1 = (obj, key, value) =>
|
|
1444
|
-
__defNormalProp$1(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
1445
|
-
return value;
|
|
1446
|
-
};
|
|
1421
|
+
var __publicField$1 = (obj, key, value) => __defNormalProp$1(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
1447
1422
|
class NetworkError extends Error {
|
|
1448
1423
|
constructor(url) {
|
|
1449
1424
|
super();
|
|
@@ -1552,10 +1527,7 @@ var NgwConnector = (function () {
|
|
|
1552
1527
|
}
|
|
1553
1528
|
return a;
|
|
1554
1529
|
};
|
|
1555
|
-
var __publicField = (obj, key, value) =>
|
|
1556
|
-
__defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
1557
|
-
return value;
|
|
1558
|
-
};
|
|
1530
|
+
var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
1559
1531
|
let ID = 0;
|
|
1560
1532
|
class NgwConnector {
|
|
1561
1533
|
constructor(options) {
|
|
@@ -1564,10 +1536,12 @@ var NgwConnector = (function () {
|
|
|
1564
1536
|
__publicField(this, "emitter", new EventEmitter());
|
|
1565
1537
|
__publicField(this, "user");
|
|
1566
1538
|
__publicField(this, "resources");
|
|
1539
|
+
__publicField(this, "cache");
|
|
1567
1540
|
__publicField(this, "routeStr", "/api/component/pyramid/route");
|
|
1568
1541
|
__publicField(this, "activeRequests", []);
|
|
1569
1542
|
__publicField(this, "requestTransform");
|
|
1570
1543
|
const exist = findConnector(options);
|
|
1544
|
+
this.cache = new Cache({ namespace: options.cacheId });
|
|
1571
1545
|
if (exist) {
|
|
1572
1546
|
return exist;
|
|
1573
1547
|
} else {
|
|
@@ -1577,13 +1551,23 @@ var NgwConnector = (function () {
|
|
|
1577
1551
|
if (this.options.requestTransform) {
|
|
1578
1552
|
this.requestTransform = this.options.requestTransform;
|
|
1579
1553
|
}
|
|
1580
|
-
this.resources = new ResourcesControl(
|
|
1554
|
+
this.resources = new ResourcesControl({
|
|
1555
|
+
connector: this,
|
|
1556
|
+
cacheId: options.cacheId
|
|
1557
|
+
});
|
|
1581
1558
|
addConnector(this);
|
|
1582
1559
|
}
|
|
1583
1560
|
}
|
|
1584
1561
|
static create(options) {
|
|
1585
1562
|
return new this(options);
|
|
1586
1563
|
}
|
|
1564
|
+
/**
|
|
1565
|
+
* Clear the cache.
|
|
1566
|
+
*/
|
|
1567
|
+
clearCache() {
|
|
1568
|
+
this.cache.clean();
|
|
1569
|
+
this.resources.cache.clean();
|
|
1570
|
+
}
|
|
1587
1571
|
setRequestTransform(requestTransform) {
|
|
1588
1572
|
this.requestTransform = requestTransform;
|
|
1589
1573
|
}
|
|
@@ -1611,7 +1595,6 @@ var NgwConnector = (function () {
|
|
|
1611
1595
|
* ```
|
|
1612
1596
|
*/
|
|
1613
1597
|
connect() {
|
|
1614
|
-
const cache = new Cache();
|
|
1615
1598
|
const auth = this.options.auth;
|
|
1616
1599
|
const makeConnect = () => new CancelablePromise((resolve, reject) => {
|
|
1617
1600
|
const makeQuery = () => {
|
|
@@ -1631,7 +1614,7 @@ var NgwConnector = (function () {
|
|
|
1631
1614
|
}
|
|
1632
1615
|
return makeQuery();
|
|
1633
1616
|
});
|
|
1634
|
-
return cache.add("route", makeConnect, {
|
|
1617
|
+
return this.cache.add("route", makeConnect, {
|
|
1635
1618
|
id: this.id,
|
|
1636
1619
|
auth,
|
|
1637
1620
|
baseUrl: this.options.baseUrl
|
|
@@ -1654,8 +1637,8 @@ var NgwConnector = (function () {
|
|
|
1654
1637
|
removeConnector(this);
|
|
1655
1638
|
this.options.auth = void 0;
|
|
1656
1639
|
this.user = void 0;
|
|
1640
|
+
this.clearCache();
|
|
1657
1641
|
this.emitter.emit("logout");
|
|
1658
|
-
this.resources.cache.clean();
|
|
1659
1642
|
}
|
|
1660
1643
|
getUserInfo(credentials, options) {
|
|
1661
1644
|
if (this.user && this.user.id) {
|
|
@@ -1740,8 +1723,7 @@ var NgwConnector = (function () {
|
|
|
1740
1723
|
const params = objectRemoveEmpty(params_);
|
|
1741
1724
|
const makeApiRequest = () => apiRequest({ name, params, requestOptions, connector: this });
|
|
1742
1725
|
if (requestOptions.cache && method === "GET") {
|
|
1743
|
-
|
|
1744
|
-
return cache.add(name, makeApiRequest, __spreadValues({
|
|
1726
|
+
return this.cache.add(name, makeApiRequest, __spreadValues({
|
|
1745
1727
|
params
|
|
1746
1728
|
}, objectRemoveEmpty({
|
|
1747
1729
|
headers,
|