@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.
@@ -1,4 +1,4 @@
1
- /** Bundle of @nextgis/ngw-connector; version: 2.2.3; author: NextGIS */
1
+ /** Bundle of @nextgis/ngw-connector; version: 2.4.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
- return false;
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(connector) {
1061
+ constructor({
1062
+ connector,
1063
+ cacheId
1064
+ }) {
1065
+ __publicField$3(this, "cache");
1066
+ __publicField$3(this, "connector");
1092
1067
  this.connector = connector;
1093
- __publicField$3(this, "cache", new Cache());
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 = new 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") {
@@ -1132,7 +1107,10 @@ class ResourcesControl {
1132
1107
  }
1133
1108
  return CancelablePromise.resolve(void 0);
1134
1109
  };
1135
- return cache.addFull("resource", makeRequest, forCache);
1110
+ if (requestOptions == null ? void 0 : requestOptions.cache) {
1111
+ return cache.addFull("resource", makeRequest, forCache);
1112
+ }
1113
+ return makeRequest();
1136
1114
  }
1137
1115
  getOneOrFail(resource, requestOptions) {
1138
1116
  return this.getOne(resource, requestOptions).then((res) => {
@@ -1293,14 +1271,17 @@ class ResourcesControl {
1293
1271
  }
1294
1272
  _fetchResourceById(id, requestOptions) {
1295
1273
  const promise = () => this.connector.get("resource.item", requestOptions, { id });
1296
- return this.cache.add("resource.item", promise, {
1297
- id
1298
- }).catch((er) => {
1299
- if (!(er instanceof ResourceNotFoundError)) {
1300
- throw er;
1301
- }
1302
- return void 0;
1303
- });
1274
+ if (requestOptions == null ? void 0 : requestOptions.cache) {
1275
+ return this.cache.add("resource.item", promise, {
1276
+ id
1277
+ }).catch((er) => {
1278
+ if (!(er instanceof ResourceNotFoundError)) {
1279
+ throw er;
1280
+ }
1281
+ return void 0;
1282
+ });
1283
+ }
1284
+ return promise();
1304
1285
  }
1305
1286
  _fetchResourceBy(resource, requestOptions) {
1306
1287
  return this.getMany(resource, requestOptions).then((resources) => {
@@ -1354,10 +1335,7 @@ function removeConnector(connector) {
1354
1335
 
1355
1336
  var __defProp$2 = Object.defineProperty;
1356
1337
  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
- };
1338
+ var __publicField$2 = (obj, key, value) => __defNormalProp$2(obj, typeof key !== "symbol" ? key + "" : key, value);
1361
1339
  class InsufficientPermissionsError extends NgwError {
1362
1340
  constructor(obj) {
1363
1341
  super(obj);
@@ -1383,7 +1361,7 @@ function template(str, data) {
1383
1361
  function apiRequest(opt) {
1384
1362
  const params = opt.params;
1385
1363
  return new CancelablePromise((resolve, reject) => {
1386
- opt.connector.connect().then((apiItems) => {
1364
+ return opt.connector.connect().then((apiItems) => {
1387
1365
  let apiItem = apiItems && apiItems[opt.name];
1388
1366
  if (apiItem) {
1389
1367
  apiItem = [...apiItem];
@@ -1437,10 +1415,7 @@ function apiRequest(opt) {
1437
1415
 
1438
1416
  var __defProp$1 = Object.defineProperty;
1439
1417
  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
- };
1418
+ var __publicField$1 = (obj, key, value) => __defNormalProp$1(obj, typeof key !== "symbol" ? key + "" : key, value);
1444
1419
  class NetworkError extends Error {
1445
1420
  constructor(url) {
1446
1421
  super();
@@ -1549,10 +1524,7 @@ var __spreadValues = (a, b) => {
1549
1524
  }
1550
1525
  return a;
1551
1526
  };
1552
- var __publicField = (obj, key, value) => {
1553
- __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
1554
- return value;
1555
- };
1527
+ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
1556
1528
  let ID = 0;
1557
1529
  class NgwConnector {
1558
1530
  constructor(options) {
@@ -1561,10 +1533,12 @@ class NgwConnector {
1561
1533
  __publicField(this, "emitter", new EventEmitter());
1562
1534
  __publicField(this, "user");
1563
1535
  __publicField(this, "resources");
1536
+ __publicField(this, "cache");
1564
1537
  __publicField(this, "routeStr", "/api/component/pyramid/route");
1565
1538
  __publicField(this, "activeRequests", []);
1566
1539
  __publicField(this, "requestTransform");
1567
1540
  const exist = findConnector(options);
1541
+ this.cache = new Cache({ namespace: options.cacheId });
1568
1542
  if (exist) {
1569
1543
  return exist;
1570
1544
  } else {
@@ -1574,13 +1548,23 @@ class NgwConnector {
1574
1548
  if (this.options.requestTransform) {
1575
1549
  this.requestTransform = this.options.requestTransform;
1576
1550
  }
1577
- this.resources = new ResourcesControl(this);
1551
+ this.resources = new ResourcesControl({
1552
+ connector: this,
1553
+ cacheId: options.cacheId
1554
+ });
1578
1555
  addConnector(this);
1579
1556
  }
1580
1557
  }
1581
1558
  static create(options) {
1582
1559
  return new this(options);
1583
1560
  }
1561
+ /**
1562
+ * Clear the cache.
1563
+ */
1564
+ clearCache() {
1565
+ this.cache.clean();
1566
+ this.resources.cache.clean();
1567
+ }
1584
1568
  setRequestTransform(requestTransform) {
1585
1569
  this.requestTransform = requestTransform;
1586
1570
  }
@@ -1608,7 +1592,6 @@ class NgwConnector {
1608
1592
  * ```
1609
1593
  */
1610
1594
  connect() {
1611
- const cache = new Cache();
1612
1595
  const auth = this.options.auth;
1613
1596
  const makeConnect = () => new CancelablePromise((resolve, reject) => {
1614
1597
  const makeQuery = () => {
@@ -1628,7 +1611,7 @@ class NgwConnector {
1628
1611
  }
1629
1612
  return makeQuery();
1630
1613
  });
1631
- return cache.add("route", makeConnect, {
1614
+ return this.cache.add("route", makeConnect, {
1632
1615
  id: this.id,
1633
1616
  auth,
1634
1617
  baseUrl: this.options.baseUrl
@@ -1651,8 +1634,8 @@ class NgwConnector {
1651
1634
  removeConnector(this);
1652
1635
  this.options.auth = void 0;
1653
1636
  this.user = void 0;
1637
+ this.clearCache();
1654
1638
  this.emitter.emit("logout");
1655
- this.resources.cache.clean();
1656
1639
  }
1657
1640
  getUserInfo(credentials, options) {
1658
1641
  if (this.user && this.user.id) {
@@ -1737,8 +1720,7 @@ class NgwConnector {
1737
1720
  const params = objectRemoveEmpty(params_);
1738
1721
  const makeApiRequest = () => apiRequest({ name, params, requestOptions, connector: this });
1739
1722
  if (requestOptions.cache && method === "GET") {
1740
- const cache = new Cache();
1741
- return cache.add(name, makeApiRequest, __spreadValues({
1723
+ return this.cache.add(name, makeApiRequest, __spreadValues({
1742
1724
  params
1743
1725
  }, objectRemoveEmpty({
1744
1726
  headers,