@nextgis/ngw-connector 2.3.0 → 3.0.0-alpha.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.3.0; author: NextGIS */
1
+ /** Bundle of @nextgis/ngw-connector; version: 3.0.0-alpha.0; author: NextGIS */
2
2
  var domain;
3
3
 
4
4
  // This constructor is used to store event handlers. Instantiating this is
@@ -528,12 +528,12 @@ function fixUrlStr(url) {
528
528
  return url.replace(/([^:]\/)\/+/g, "$1");
529
529
  }
530
530
 
531
- var __defProp$a = Object.defineProperty;
532
- var __defNormalProp$a = (obj, key, value) => key in obj ? __defProp$a(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
533
- var __publicField$a = (obj, key, value) => __defNormalProp$a(obj, typeof key !== "symbol" ? key + "" : key, value);
531
+ var __defProp$7 = Object.defineProperty;
532
+ var __defNormalProp$7 = (obj, key, value) => key in obj ? __defProp$7(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
533
+ var __publicField$6 = (obj, key, value) => __defNormalProp$7(obj, typeof key !== "symbol" ? key + "" : key, value);
534
534
  const _Cache = class _Cache {
535
535
  constructor(options = {}) {
536
- __publicField$a(this, "cache", []);
536
+ __publicField$6(this, "cache", []);
537
537
  var _a;
538
538
  const namespace = (_a = options.namespace) != null ? _a : "default";
539
539
  if (_Cache.instance[namespace]) {
@@ -566,8 +566,7 @@ const _Cache = class _Cache {
566
566
  * // somewhere else in the code
567
567
  * const item = await cache.addFull('foo', getItemFunc).then((resp) => {
568
568
  * console.log(resp); // 'New item'
569
- * })
570
- *
569
+ * });
571
570
  * ```
572
571
  */
573
572
  addFull(key, valueToSet, props) {
@@ -582,13 +581,11 @@ const _Cache = class _Cache {
582
581
  } else {
583
582
  value = valueToSet;
584
583
  }
585
- const props_ = props && JSON.parse(JSON.stringify(objectRemoveEmpty(props)));
584
+ const nonEmptyProps = props && JSON.parse(JSON.stringify(objectRemoveEmpty(props)));
586
585
  const cacheItem = {
587
586
  key,
588
587
  value,
589
- props: props_,
590
- // TODO: remove backward compatibility use only props
591
- options: props_
588
+ props: nonEmptyProps
592
589
  };
593
590
  if (onlyFull && !full(value)) {
594
591
  return value;
@@ -597,7 +594,6 @@ const _Cache = class _Cache {
597
594
  if (value instanceof Promise) {
598
595
  value.catch((er) => {
599
596
  this.delete(key, props);
600
- throw er;
601
597
  });
602
598
  if (onlyFull) {
603
599
  value.then((x) => {
@@ -616,9 +612,7 @@ const _Cache = class _Cache {
616
612
  }
617
613
  match(key, props) {
618
614
  const cacheRecord = this._find(key, props);
619
- if (cacheRecord) {
620
- return cacheRecord.value;
621
- }
615
+ return cacheRecord == null ? void 0 : cacheRecord.value;
622
616
  }
623
617
  matchAll(key, props) {
624
618
  if (key) {
@@ -627,339 +621,30 @@ const _Cache = class _Cache {
627
621
  return this.cache.map((x) => x.value);
628
622
  }
629
623
  delete(keyOrItem, props) {
630
- let exist = [];
631
- if (typeof keyOrItem === "string") {
632
- exist = this.cache.filter((x) => this._filter(x, keyOrItem, props));
633
- } else {
634
- exist.push(keyOrItem);
635
- }
636
- for (const e of exist) {
637
- const index = this.cache.indexOf(e);
638
- this.cache.splice(index, 1);
624
+ const itemsToDelete = typeof keyOrItem === "string" ? this.cache.filter((x) => this._filter(x, keyOrItem, props)) : [keyOrItem];
625
+ for (const item of itemsToDelete) {
626
+ const index = this.cache.indexOf(item);
627
+ if (index !== -1) {
628
+ this.cache.splice(index, 1);
629
+ }
639
630
  }
640
631
  }
641
632
  _find(key, props) {
642
633
  return this.cache.find((x) => this._filter(x, key, props));
643
634
  }
644
635
  _filter(item, key, props) {
645
- if (item.key === key) {
646
- if (props) {
647
- const itemProps = item.props || item.options;
648
- return objectDeepEqual(itemProps || {}, objectRemoveEmpty(props));
649
- }
650
- return true;
651
- }
652
- return false;
636
+ if (item.key !== key) return false;
637
+ if (!props) return true;
638
+ const itemProps = item.props;
639
+ return objectDeepEqual(itemProps || {}, objectRemoveEmpty(props));
653
640
  }
654
641
  };
655
- __publicField$a(_Cache, "instance", {});
642
+ __publicField$6(_Cache, "instance", {});
656
643
  let Cache = _Cache;
657
644
 
658
- var __defProp$9 = Object.defineProperty;
659
- var __defNormalProp$9 = (obj, key, value) => key in obj ? __defProp$9(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
660
- var __publicField$9 = (obj, key, value) => __defNormalProp$9(obj, typeof key !== "symbol" ? key + "" : key, value);
661
- class CancelError extends Error {
662
- constructor() {
663
- super();
664
- __publicField$9(this, "name", "CancelError");
665
- Object.setPrototypeOf(this, CancelError.prototype);
666
- }
667
- }
668
-
669
- var __defProp$8 = Object.defineProperty;
670
- var __defNormalProp$8 = (obj, key, value) => key in obj ? __defProp$8(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
671
- var __publicField$8 = (obj, key, value) => __defNormalProp$8(obj, typeof key !== "symbol" ? key + "" : key, value);
672
- class PromiseControl {
673
- constructor(options = {}) {
674
- this.options = options;
675
- __publicField$8(this, "_promises", /* @__PURE__ */ new Map());
676
- }
677
- get isLoaded() {
678
- return this._promises.size > 0;
679
- }
680
- remove(promise) {
681
- if (this._promises.has(promise)) {
682
- this._promises.delete(promise);
683
- this._onStop();
684
- }
685
- }
686
- get(promise) {
687
- return this._promises.get(promise);
688
- }
689
- add(promise, name) {
690
- const key = name ? name : promise;
691
- const exist = this._promises.get(key);
692
- if (this.options.onStart && !this.isLoaded) {
693
- this.options.onStart();
694
- }
695
- if (exist) {
696
- return exist;
697
- }
698
- this._promises.set(key, promise);
699
- promise.finally(() => {
700
- this.remove(key);
701
- });
702
- return promise;
703
- }
704
- abort() {
705
- if (this.isLoaded) {
706
- this._promises.forEach((x) => {
707
- if (x.cancel) {
708
- x.cancel();
709
- }
710
- });
711
- this._promises.clear();
712
- this._onStop();
713
- }
714
- }
715
- waitFunc(func, name = "") {
716
- name = name || func.name;
717
- const exist = this.get(name);
718
- if (exist) {
719
- return exist;
720
- }
721
- return this.add(func(), name);
722
- }
723
- WaitForMe(name = "") {
724
- const get = this.get.bind(this);
725
- const add = this.add.bind(this);
726
- return function(target, key, descriptor) {
727
- const originalMethod = descriptor.value;
728
- name = name || key;
729
- descriptor.value = function(...args) {
730
- const exist = get(name);
731
- if (exist) {
732
- return exist;
733
- }
734
- const result = add(originalMethod.apply(this, args), name);
735
- return result;
736
- };
737
- return descriptor;
738
- };
739
- }
740
- /** @deprecated use {@link PromiseControl.WaitForMe } instead */
741
- GetOrCreateDecorator(name = "") {
742
- return this.WaitForMe(name);
743
- }
744
- _onStop() {
745
- if (this.options.onStop && !this.isLoaded) {
746
- this.options.onStop();
747
- }
748
- }
749
- }
750
-
751
- var __defProp$7 = Object.defineProperty;
752
- var __defNormalProp$7 = (obj, key, value) => key in obj ? __defProp$7(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
753
- var __publicField$7 = (obj, key, value) => __defNormalProp$7(obj, typeof key !== "symbol" ? key + "" : key, value);
754
- class TimeoutError extends Error {
755
- constructor() {
756
- super();
757
- __publicField$7(this, "name", "TimeoutError");
758
- Object.setPrototypeOf(this, TimeoutError.prototype);
759
- }
760
- }
761
-
762
645
  var __defProp$6 = Object.defineProperty;
763
646
  var __defNormalProp$6 = (obj, key, value) => key in obj ? __defProp$6(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
764
- var __publicField$6 = (obj, key, value) => __defNormalProp$6(obj, typeof key !== "symbol" ? key + "" : key, value);
765
- var _a;
766
- const handleCallback = (resolve, reject, callback, r) => {
767
- try {
768
- resolve(callback(r));
769
- } catch (e) {
770
- reject(e);
771
- }
772
- };
773
- let ID$1 = 0;
774
- _a = Symbol.toStringTag;
775
- const _CancelablePromise = class _CancelablePromise {
776
- constructor(executor, timeout) {
777
- // @ts-ignore
778
- __publicField$6(this, _a);
779
- __publicField$6(this, "id", ID$1++);
780
- __publicField$6(this, "_isCanceled", false);
781
- __publicField$6(this, "_isPending", true);
782
- __publicField$6(this, "_promise");
783
- __publicField$6(this, "_cancelPromise");
784
- __publicField$6(this, "_cancelHandlers", []);
785
- __publicField$6(this, "_setCanceledCallback");
786
- __publicField$6(this, "_parentPromise");
787
- __publicField$6(this, "_children", []);
788
- this._cancelPromise = new Promise((resolve_, reject_) => {
789
- this._setCanceledCallback = (er) => resolve_(er || new CancelError());
790
- });
791
- const promises = [
792
- this._cancelPromise,
793
- new Promise((resolve, reject) => {
794
- const onResolve = (value) => {
795
- if (value instanceof _CancelablePromise) {
796
- this.attach(value);
797
- } else {
798
- this._isPending = false;
799
- }
800
- resolve(value);
801
- };
802
- const onReject = (error) => {
803
- this._isPending = false;
804
- reject(error);
805
- };
806
- const onCancel = (handler) => {
807
- if (!this._isPending) {
808
- throw new Error(
809
- "The `onCancel` handler was attached after the promise settled."
810
- );
811
- }
812
- this._cancelHandlers.push(handler);
813
- };
814
- return executor(onResolve, onReject, onCancel);
815
- })
816
- ];
817
- if (timeout) {
818
- promises.push(
819
- new Promise((resolve, reject) => {
820
- setTimeout(() => {
821
- if (this._isPending) {
822
- try {
823
- this.cancel();
824
- } finally {
825
- reject(new TimeoutError());
826
- }
827
- }
828
- }, timeout);
829
- })
830
- );
831
- }
832
- this._promise = Promise.race(promises);
833
- }
834
- static createControl(opt) {
835
- return new PromiseControl(opt);
836
- }
837
- static resolve(value) {
838
- return new _CancelablePromise((resolve) => resolve(value));
839
- }
840
- static reject(value) {
841
- return new _CancelablePromise((resolve, reject) => reject(value));
842
- }
843
- static all(values) {
844
- return new _CancelablePromise((resolve, reject) => {
845
- Promise.all(values).then(resolve).catch(reject);
846
- }).catch((er) => {
847
- if (er instanceof this.CancelError) {
848
- for (const v of values) {
849
- const v_ = v;
850
- if ("cancel" in v_) {
851
- v_.cancel();
852
- }
853
- }
854
- }
855
- throw er;
856
- });
857
- }
858
- attach(p) {
859
- if (this._isCanceled) {
860
- p.cancel();
861
- } else {
862
- this._children.push(p);
863
- }
864
- }
865
- then(onfulfilled, onrejected) {
866
- const p = new _CancelablePromise((resolve, reject) => {
867
- if (this._promise) {
868
- const reject_ = (r) => {
869
- if (onrejected) {
870
- handleCallback(resolve, reject, onrejected, r);
871
- } else {
872
- reject(r);
873
- }
874
- };
875
- this._promise.then((r) => {
876
- if (this._isCanceled) {
877
- reject_(r);
878
- } else {
879
- if (onfulfilled) {
880
- handleCallback(resolve, reject, onfulfilled, r);
881
- } else {
882
- resolve(r);
883
- }
884
- }
885
- }, reject_);
886
- }
887
- });
888
- p._parentPromise = this;
889
- this._children.push(p);
890
- return p;
891
- }
892
- catch(onrejected) {
893
- if (this._isCanceled && onrejected) {
894
- onrejected(new CancelError());
895
- }
896
- return this.then(void 0, onrejected);
897
- }
898
- finally(onfinally) {
899
- if (this._promise) {
900
- return this._promise.finally(onfinally);
901
- }
902
- if (this._isCanceled) {
903
- return Promise.reject(new CancelError());
904
- }
905
- return Promise.reject(onfinally);
906
- }
907
- cancel() {
908
- if (this._isCanceled || !this._isPending) {
909
- return this;
910
- }
911
- this._isCanceled = true;
912
- const parent = this._getTopParent();
913
- if (parent) {
914
- parent.cancel();
915
- }
916
- if (this._children) {
917
- this._children.forEach((x) => x.cancel());
918
- }
919
- if (this._isPending) {
920
- if (this._cancelHandlers.length) {
921
- try {
922
- for (const handler of this._cancelHandlers) {
923
- handler();
924
- }
925
- } catch (error) {
926
- }
927
- }
928
- if (this._setCanceledCallback) {
929
- this._setCanceledCallback();
930
- }
931
- }
932
- this._destroy();
933
- return this;
934
- }
935
- _getTopParent() {
936
- let parent = this._parentPromise;
937
- let hasParent = !!parent;
938
- while (hasParent) {
939
- if (parent && parent._parentPromise) {
940
- parent = parent._parentPromise;
941
- hasParent = !!parent;
942
- } else {
943
- hasParent = false;
944
- }
945
- }
946
- return parent;
947
- }
948
- _destroy() {
949
- this._setCanceledCallback = void 0;
950
- this._cancelPromise = void 0;
951
- this._promise = void 0;
952
- }
953
- };
954
- __publicField$6(_CancelablePromise, "CancelError", CancelError);
955
- __publicField$6(_CancelablePromise, "TimeoutError", TimeoutError);
956
- __publicField$6(_CancelablePromise, "PromiseControl", PromiseControl);
957
- let CancelablePromise = _CancelablePromise;
958
- Object.setPrototypeOf(CancelablePromise.prototype, Promise.prototype);
959
-
960
- var __defProp$5 = Object.defineProperty;
961
- var __defNormalProp$5 = (obj, key, value) => key in obj ? __defProp$5(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
962
- var __publicField$5 = (obj, key, value) => __defNormalProp$5(obj, typeof key !== "symbol" ? key + "" : key, value);
647
+ var __publicField$5 = (obj, key, value) => __defNormalProp$6(obj, typeof key !== "symbol" ? key + "" : key, value);
963
648
  class NgwError extends Error {
964
649
  constructor(er) {
965
650
  super();
@@ -976,9 +661,9 @@ class NgwError extends Error {
976
661
  }
977
662
  }
978
663
 
979
- var __defProp$4 = Object.defineProperty;
980
- var __defNormalProp$4 = (obj, key, value) => key in obj ? __defProp$4(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
981
- var __publicField$4 = (obj, key, value) => __defNormalProp$4(obj, typeof key !== "symbol" ? key + "" : key, value);
664
+ var __defProp$5 = Object.defineProperty;
665
+ var __defNormalProp$5 = (obj, key, value) => key in obj ? __defProp$5(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
666
+ var __publicField$4 = (obj, key, value) => __defNormalProp$5(obj, typeof key !== "symbol" ? key + "" : key, value);
982
667
  class ResourceNotFoundError extends NgwError {
983
668
  constructor(obj) {
984
669
  super(obj);
@@ -1017,27 +702,24 @@ function resourceToQuery(resource, prefix = "") {
1017
702
  return query;
1018
703
  }
1019
704
 
1020
- var __defProp$3 = Object.defineProperty;
1021
- var __defProps = Object.defineProperties;
1022
- var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
1023
- var __getOwnPropSymbols$1 = Object.getOwnPropertySymbols;
1024
- var __hasOwnProp$1 = Object.prototype.hasOwnProperty;
1025
- var __propIsEnum$1 = Object.prototype.propertyIsEnumerable;
1026
- var __defNormalProp$3 = (obj, key, value) => key in obj ? __defProp$3(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
1027
- var __spreadValues$1 = (a, b) => {
705
+ var __defProp$4 = Object.defineProperty;
706
+ var __getOwnPropSymbols$2 = Object.getOwnPropertySymbols;
707
+ var __hasOwnProp$2 = Object.prototype.hasOwnProperty;
708
+ var __propIsEnum$2 = Object.prototype.propertyIsEnumerable;
709
+ var __defNormalProp$4 = (obj, key, value) => key in obj ? __defProp$4(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
710
+ var __spreadValues$2 = (a, b) => {
1028
711
  for (var prop in b || (b = {}))
1029
- if (__hasOwnProp$1.call(b, prop))
1030
- __defNormalProp$3(a, prop, b[prop]);
1031
- if (__getOwnPropSymbols$1)
1032
- for (var prop of __getOwnPropSymbols$1(b)) {
1033
- if (__propIsEnum$1.call(b, prop))
1034
- __defNormalProp$3(a, prop, b[prop]);
712
+ if (__hasOwnProp$2.call(b, prop))
713
+ __defNormalProp$4(a, prop, b[prop]);
714
+ if (__getOwnPropSymbols$2)
715
+ for (var prop of __getOwnPropSymbols$2(b)) {
716
+ if (__propIsEnum$2.call(b, prop))
717
+ __defNormalProp$4(a, prop, b[prop]);
1035
718
  }
1036
719
  return a;
1037
720
  };
1038
- var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
1039
- var __publicField$3 = (obj, key, value) => __defNormalProp$3(obj, typeof key !== "symbol" ? key + "" : key, value);
1040
- var __async = (__this, __arguments, generator) => {
721
+ var __publicField$3 = (obj, key, value) => __defNormalProp$4(obj, typeof key !== "symbol" ? key + "" : key, value);
722
+ var __async$2 = (__this, __arguments, generator) => {
1041
723
  return new Promise((resolve, reject) => {
1042
724
  var fulfilled = (value) => {
1043
725
  try {
@@ -1078,36 +760,27 @@ class ResourcesControl {
1078
760
  * Fetching resource would be cached to speed up next call
1079
761
  */
1080
762
  getOne(resource, requestOptions) {
1081
- const cache = this.cache;
1082
- const forCache = {};
1083
- const opt = __spreadProps(__spreadValues$1({}, requestOptions), { cache: false });
1084
- if (typeof resource === "string") {
1085
- forCache.keyname = resource;
1086
- } else if (typeof resource === "number") {
1087
- forCache.id = resource;
1088
- } else if (isObject(resource)) {
763
+ const opt = __spreadValues$2({}, requestOptions);
764
+ if (typeof resource === "string") ; else if (typeof resource === "number") ; else if (isObject(resource)) {
1089
765
  if (resource.id !== void 0) {
1090
- forCache.id = resource.id;
766
+ resource.id;
1091
767
  } else {
1092
768
  if (resource.keyname) {
1093
- forCache.keyname = resource.keyname;
769
+ resource.keyname;
1094
770
  }
1095
771
  if (resource.display_name) {
1096
- forCache.display_name = resource.display_name;
772
+ resource.display_name;
1097
773
  }
1098
774
  }
1099
775
  }
1100
- const makeRequest = () => {
1101
- if (typeof resource === "string") {
1102
- return this._fetchResourceBy({ keyname: resource }, opt);
1103
- } else if (typeof resource === "number") {
1104
- return this._fetchResourceById(resource, opt);
1105
- } else if (isObject(resource)) {
1106
- return this._fetchResourceBy(resource, opt);
1107
- }
1108
- return CancelablePromise.resolve(void 0);
1109
- };
1110
- return cache.addFull("resource", makeRequest, forCache);
776
+ if (typeof resource === "string") {
777
+ return this._fetchResourceBy({ keyname: resource }, opt);
778
+ } else if (typeof resource === "number") {
779
+ return this._fetchResourceById(resource, opt);
780
+ } else if (isObject(resource)) {
781
+ return this._fetchResourceBy(resource, opt);
782
+ }
783
+ return Promise.resolve(void 0);
1111
784
  }
1112
785
  getOneOrFail(resource, requestOptions) {
1113
786
  return this.getOne(resource, requestOptions).then((res) => {
@@ -1129,7 +802,7 @@ class ResourcesControl {
1129
802
  */
1130
803
  getId(resource, requestOptions) {
1131
804
  if (typeof resource === "number") {
1132
- return CancelablePromise.resolve(resource);
805
+ return Promise.resolve(resource);
1133
806
  } else if (typeof resource === "string" || isObject(resource)) {
1134
807
  return this.getOne(resource, requestOptions).then((res) => {
1135
808
  if (res) {
@@ -1137,7 +810,7 @@ class ResourcesControl {
1137
810
  }
1138
811
  });
1139
812
  }
1140
- return CancelablePromise.resolve(void 0);
813
+ return Promise.resolve(void 0);
1141
814
  }
1142
815
  /**
1143
816
  * A fast way to retrieve resource ID for any resource definition.
@@ -1164,12 +837,12 @@ class ResourcesControl {
1164
837
  } else {
1165
838
  Object.assign(query, resourceToQuery(resource));
1166
839
  }
1167
- return this.connector.get("resource.search", requestOptions, __spreadValues$1({
840
+ return this.connector.get("resource.search", requestOptions, __spreadValues$2({
1168
841
  serialization: "full"
1169
842
  }, query)).then((resources) => {
1170
- if (resources) {
843
+ if ((requestOptions == null ? void 0 : requestOptions.cache) && resources) {
1171
844
  for (const x of resources) {
1172
- this.cache.add("resource.item", CancelablePromise.resolve(x), {
845
+ this.cache.add("resource.item", Promise.resolve(x), {
1173
846
  id: x.resource.id
1174
847
  });
1175
848
  }
@@ -1185,7 +858,7 @@ class ResourcesControl {
1185
858
  if (child) {
1186
859
  return this.getOne(child.resource.parent.id, requestOptions);
1187
860
  }
1188
- return CancelablePromise.resolve(void 0);
861
+ return Promise.resolve(void 0);
1189
862
  });
1190
863
  }
1191
864
  getChildrenOf(resource, requestOptions) {
@@ -1215,18 +888,16 @@ class ResourcesControl {
1215
888
  });
1216
889
  }
1217
890
  _getChildrenOf(parent, requestOptions, _items = []) {
1218
- return this.connector.get(
1219
- "resource.collection",
1220
- __spreadValues$1({ cache: true }, requestOptions),
1221
- {
1222
- parent
1223
- }
1224
- ).then((items) => {
891
+ return this.connector.get("resource.collection", requestOptions, {
892
+ parent
893
+ }).then((items) => {
1225
894
  const recursivePromises = [];
1226
895
  for (const item of items) {
1227
- this.cache.add("resource.item", CancelablePromise.resolve(item), {
1228
- id: item.resource.id
1229
- });
896
+ if (requestOptions == null ? void 0 : requestOptions.cache) {
897
+ this.cache.add("resource.item", Promise.resolve(item), {
898
+ id: item.resource.id
899
+ });
900
+ }
1230
901
  _items.push(item);
1231
902
  if ((requestOptions == null ? void 0 : requestOptions.recursive) && item.resource.children) {
1232
903
  recursivePromises.push(
@@ -1235,7 +906,7 @@ class ResourcesControl {
1235
906
  }
1236
907
  }
1237
908
  if (recursivePromises.length) {
1238
- return CancelablePromise.all(recursivePromises).then(() => {
909
+ return Promise.all(recursivePromises).then(() => {
1239
910
  return _items;
1240
911
  });
1241
912
  }
@@ -1243,11 +914,12 @@ class ResourcesControl {
1243
914
  });
1244
915
  }
1245
916
  _cleanResourceItemCache(id) {
1246
- return __async(this, null, function* () {
917
+ return __async$2(this, null, function* () {
918
+ var _a;
1247
919
  const all = this.cache.all();
1248
920
  const toDelete = [];
1249
921
  for (const c of all) {
1250
- const cid = c.options && c.options.id;
922
+ const cid = (_a = c.props) == null ? void 0 : _a.id;
1251
923
  if (["resource.item", "resource"].includes(c.key) && cid !== void 0) {
1252
924
  if (typeof cid === "number") {
1253
925
  if (cid === id) {
@@ -1267,15 +939,7 @@ class ResourcesControl {
1267
939
  });
1268
940
  }
1269
941
  _fetchResourceById(id, requestOptions) {
1270
- const promise = () => this.connector.get("resource.item", requestOptions, { id });
1271
- return this.cache.add("resource.item", promise, {
1272
- id
1273
- }).catch((er) => {
1274
- if (!(er instanceof ResourceNotFoundError)) {
1275
- throw er;
1276
- }
1277
- return void 0;
1278
- });
942
+ return this.connector.get("resource.item", requestOptions, { id });
1279
943
  }
1280
944
  _fetchResourceBy(resource, requestOptions) {
1281
945
  return this.getMany(resource, requestOptions).then((resources) => {
@@ -1283,7 +947,7 @@ class ResourcesControl {
1283
947
  });
1284
948
  }
1285
949
  _resourceCacheFilter(resource) {
1286
- return CancelablePromise.all(this.cache.matchAll("resource.item")).then(
950
+ return Promise.all(this.cache.matchAll("resource.item")).then(
1287
951
  (resources) => {
1288
952
  const items = [];
1289
953
  resources.filter((x) => {
@@ -1327,9 +991,16 @@ function removeConnector(connector) {
1327
991
  }
1328
992
  }
1329
993
 
1330
- var __defProp$2 = Object.defineProperty;
1331
- var __defNormalProp$2 = (obj, key, value) => key in obj ? __defProp$2(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
1332
- var __publicField$2 = (obj, key, value) => __defNormalProp$2(obj, typeof key !== "symbol" ? key + "" : key, value);
994
+ class AbortError extends Error {
995
+ constructor(message = "AbortError") {
996
+ super(message);
997
+ this.name = "AbortError";
998
+ }
999
+ }
1000
+
1001
+ var __defProp$3 = Object.defineProperty;
1002
+ var __defNormalProp$3 = (obj, key, value) => key in obj ? __defProp$3(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
1003
+ var __publicField$2 = (obj, key, value) => __defNormalProp$3(obj, typeof key !== "symbol" ? key + "" : key, value);
1333
1004
  class InsufficientPermissionsError extends NgwError {
1334
1005
  constructor(obj) {
1335
1006
  super(obj);
@@ -1352,64 +1023,96 @@ function template(str, data) {
1352
1023
  });
1353
1024
  }
1354
1025
 
1026
+ var __defProp$2 = Object.defineProperty;
1027
+ var __getOwnPropSymbols$1 = Object.getOwnPropertySymbols;
1028
+ var __hasOwnProp$1 = Object.prototype.hasOwnProperty;
1029
+ var __propIsEnum$1 = Object.prototype.propertyIsEnumerable;
1030
+ var __defNormalProp$2 = (obj, key, value) => key in obj ? __defProp$2(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
1031
+ var __spreadValues$1 = (a, b) => {
1032
+ for (var prop in b || (b = {}))
1033
+ if (__hasOwnProp$1.call(b, prop))
1034
+ __defNormalProp$2(a, prop, b[prop]);
1035
+ if (__getOwnPropSymbols$1)
1036
+ for (var prop of __getOwnPropSymbols$1(b)) {
1037
+ if (__propIsEnum$1.call(b, prop))
1038
+ __defNormalProp$2(a, prop, b[prop]);
1039
+ }
1040
+ return a;
1041
+ };
1042
+ var __async$1 = (__this, __arguments, generator) => {
1043
+ return new Promise((resolve, reject) => {
1044
+ var fulfilled = (value) => {
1045
+ try {
1046
+ step(generator.next(value));
1047
+ } catch (e) {
1048
+ reject(e);
1049
+ }
1050
+ };
1051
+ var rejected = (value) => {
1052
+ try {
1053
+ step(generator.throw(value));
1054
+ } catch (e) {
1055
+ reject(e);
1056
+ }
1057
+ };
1058
+ var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
1059
+ step((generator = generator.apply(__this, __arguments)).next());
1060
+ });
1061
+ };
1355
1062
  function apiRequest(opt) {
1356
- const params = opt.params;
1357
- return new CancelablePromise((resolve, reject) => {
1358
- opt.connector.connect().then((apiItems) => {
1359
- let apiItem = apiItems && apiItems[opt.name];
1360
- if (apiItem) {
1361
- apiItem = [...apiItem];
1362
- let url = apiItem.shift();
1363
- if (apiItem.length) {
1364
- const replaceParams = {};
1365
- for (let fry = 0; fry < apiItem.length; fry++) {
1366
- const arg = apiItem[fry];
1367
- replaceParams[fry] = "{" + arg + "}";
1368
- if (params[arg] === void 0) {
1369
- throw new Error(
1370
- "`" + arg + "` url api argument is not specified"
1371
- );
1372
- }
1373
- }
1374
- if (url) {
1375
- url = template(url, replaceParams);
1063
+ return __async$1(this, null, function* () {
1064
+ const { params, name, connector, requestOptions } = opt;
1065
+ const apiItems = yield connector.connect();
1066
+ let apiItem = apiItems && apiItems[name];
1067
+ if (apiItem) {
1068
+ apiItem = [...apiItem];
1069
+ let url = apiItem.shift();
1070
+ if (apiItem.length) {
1071
+ const replaceParams = {};
1072
+ for (let fry = 0; fry < apiItem.length; fry++) {
1073
+ const arg = apiItem[fry];
1074
+ replaceParams[fry] = `{${arg}}`;
1075
+ if (params[arg] === void 0) {
1076
+ throw new Error(`\`${arg}\` URL API argument is not specified`);
1376
1077
  }
1377
1078
  }
1378
- if (params) {
1379
- const paramArray = [];
1380
- const paramList = params.paramList;
1381
- if (Array.isArray(paramList)) {
1382
- delete params.paramList;
1383
- paramList.forEach((x) => {
1384
- paramArray.push(`${x[0]}=${x[1]}`);
1385
- });
1386
- }
1387
- for (const p in params) {
1388
- if (apiItem.indexOf(p) === -1) {
1389
- paramArray.push(`${p}=${params[p]}`);
1390
- }
1391
- }
1392
- if (paramArray.length) {
1393
- url = url + "?" + paramArray.join("&");
1079
+ if (url) {
1080
+ url = template(url, replaceParams);
1081
+ }
1082
+ }
1083
+ if (params) {
1084
+ const paramArray = [];
1085
+ const paramList = params.paramList;
1086
+ if (Array.isArray(paramList)) {
1087
+ paramList.forEach(([key, value]) => {
1088
+ paramArray.push(`${key}=${value}`);
1089
+ });
1090
+ }
1091
+ for (const p in params) {
1092
+ if (apiItem.indexOf(p) === -1) {
1093
+ paramArray.push(`${p}=${params[p]}`);
1394
1094
  }
1395
1095
  }
1396
- if (url) {
1397
- resolve(opt.connector.makeQuery(url, params, opt.requestOptions));
1398
- } else {
1399
- reject(new Error("request url is not set"));
1096
+ if (paramArray.length) {
1097
+ url = `${url}?${paramArray.join("&")}`;
1400
1098
  }
1099
+ }
1100
+ if (url) {
1101
+ return connector.makeQuery(url, params, __spreadValues$1({
1102
+ cacheName: name
1103
+ }, requestOptions));
1401
1104
  } else {
1402
- resolve(void 0);
1105
+ throw new Error("Request URL is not set");
1403
1106
  }
1404
- }).catch((er) => {
1405
- reject(er);
1406
- });
1107
+ } else {
1108
+ return void 0;
1109
+ }
1407
1110
  });
1408
1111
  }
1409
1112
 
1410
1113
  var __defProp$1 = Object.defineProperty;
1411
1114
  var __defNormalProp$1 = (obj, key, value) => key in obj ? __defProp$1(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
1412
- var __publicField$1 = (obj, key, value) => __defNormalProp$1(obj, typeof key !== "symbol" ? key + "" : key, value);
1115
+ var __publicField$1 = (obj, key, value) => __defNormalProp$1(obj, key + "" , value);
1413
1116
  class NetworkError extends Error {
1414
1117
  constructor(url) {
1415
1118
  super();
@@ -1503,6 +1206,8 @@ let loadData;
1503
1206
  }
1504
1207
 
1505
1208
  var __defProp = Object.defineProperty;
1209
+ var __defProps = Object.defineProperties;
1210
+ var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
1506
1211
  var __getOwnPropSymbols = Object.getOwnPropertySymbols;
1507
1212
  var __hasOwnProp = Object.prototype.hasOwnProperty;
1508
1213
  var __propIsEnum = Object.prototype.propertyIsEnumerable;
@@ -1518,8 +1223,42 @@ var __spreadValues = (a, b) => {
1518
1223
  }
1519
1224
  return a;
1520
1225
  };
1226
+ var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
1227
+ var __objRest = (source, exclude) => {
1228
+ var target = {};
1229
+ for (var prop in source)
1230
+ if (__hasOwnProp.call(source, prop) && exclude.indexOf(prop) < 0)
1231
+ target[prop] = source[prop];
1232
+ if (source != null && __getOwnPropSymbols)
1233
+ for (var prop of __getOwnPropSymbols(source)) {
1234
+ if (exclude.indexOf(prop) < 0 && __propIsEnum.call(source, prop))
1235
+ target[prop] = source[prop];
1236
+ }
1237
+ return target;
1238
+ };
1521
1239
  var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
1240
+ var __async = (__this, __arguments, generator) => {
1241
+ return new Promise((resolve, reject) => {
1242
+ var fulfilled = (value) => {
1243
+ try {
1244
+ step(generator.next(value));
1245
+ } catch (e) {
1246
+ reject(e);
1247
+ }
1248
+ };
1249
+ var rejected = (value) => {
1250
+ try {
1251
+ step(generator.throw(value));
1252
+ } catch (e) {
1253
+ reject(e);
1254
+ }
1255
+ };
1256
+ var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
1257
+ step((generator = generator.apply(__this, __arguments)).next());
1258
+ });
1259
+ };
1522
1260
  let ID = 0;
1261
+ let REQUEST_ID = 0;
1523
1262
  class NgwConnector {
1524
1263
  constructor(options) {
1525
1264
  this.options = options;
@@ -1529,7 +1268,7 @@ class NgwConnector {
1529
1268
  __publicField(this, "resources");
1530
1269
  __publicField(this, "cache");
1531
1270
  __publicField(this, "routeStr", "/api/component/pyramid/route");
1532
- __publicField(this, "activeRequests", []);
1271
+ __publicField(this, "activeRequests", {});
1533
1272
  __publicField(this, "requestTransform");
1534
1273
  const exist = findConnector(options);
1535
1274
  this.cache = new Cache({ namespace: options.cacheId });
@@ -1586,29 +1325,27 @@ class NgwConnector {
1586
1325
  * ```
1587
1326
  */
1588
1327
  connect() {
1589
- const auth = this.options.auth;
1590
- const makeConnect = () => new CancelablePromise((resolve, reject) => {
1591
- const makeQuery = () => {
1592
- return this.makeQuery(this.routeStr, {}, {}).then((route) => {
1593
- resolve(route);
1594
- }).catch((er) => {
1595
- reject(er);
1596
- });
1597
- };
1328
+ return __async(this, null, function* () {
1329
+ const auth = this.options.auth;
1598
1330
  if (auth) {
1599
1331
  const { login, password } = auth;
1600
1332
  if (login && password) {
1601
- return this._login({ login, password }).then(() => {
1602
- return makeQuery();
1603
- }).catch((er) => reject(er));
1333
+ yield this._login({ login, password });
1604
1334
  }
1605
1335
  }
1606
- return makeQuery();
1607
- });
1608
- return this.cache.add("route", makeConnect, {
1609
- id: this.id,
1610
- auth,
1611
- baseUrl: this.options.baseUrl
1336
+ return yield this.makeQuery(
1337
+ this.routeStr,
1338
+ {},
1339
+ {
1340
+ cacheName: "route",
1341
+ cache: true,
1342
+ cacheProps: {
1343
+ id: this.id,
1344
+ auth,
1345
+ baseUrl: this.options.baseUrl
1346
+ }
1347
+ }
1348
+ );
1612
1349
  });
1613
1350
  }
1614
1351
  /**
@@ -1632,20 +1369,22 @@ class NgwConnector {
1632
1369
  this.emitter.emit("logout");
1633
1370
  }
1634
1371
  getUserInfo(credentials, options) {
1635
- if (this.user && this.user.id) {
1636
- return CancelablePromise.resolve(this.user);
1637
- }
1638
- if (credentials) {
1639
- this.options.auth = credentials;
1640
- }
1641
- const options_ = __spreadValues({
1642
- headers: this.getAuthorizationHeaders(credentials)
1643
- }, options);
1644
- return this.makeQuery(
1645
- "/api/component/auth/current_user",
1646
- {},
1647
- options_
1648
- );
1372
+ return __async(this, null, function* () {
1373
+ if (this.user && this.user.id) {
1374
+ return this.user;
1375
+ }
1376
+ if (credentials) {
1377
+ this.options.auth = credentials;
1378
+ }
1379
+ const options_ = __spreadValues({
1380
+ headers: this.getAuthorizationHeaders(credentials)
1381
+ }, options);
1382
+ return this.makeQuery(
1383
+ "/api/component/auth/current_user",
1384
+ {},
1385
+ options_
1386
+ );
1387
+ });
1649
1388
  }
1650
1389
  /**
1651
1390
  * Obtaining the required Headers for authentication of requests in the NGW.
@@ -1654,7 +1393,7 @@ class NgwConnector {
1654
1393
  const client = this.makeClientId(credentials);
1655
1394
  if (client) {
1656
1395
  return {
1657
- Authorization: "Basic " + client
1396
+ Authorization: `Basic ${client}`
1658
1397
  };
1659
1398
  }
1660
1399
  }
@@ -1662,21 +1401,22 @@ class NgwConnector {
1662
1401
  credentials = credentials || this.options.auth;
1663
1402
  if (credentials) {
1664
1403
  const { login, password } = credentials;
1665
- const str = unescape(encodeURIComponent(`${login}:${password}`));
1404
+ const str = `${login}:${password}`;
1405
+ const encodedStr = encodeURIComponent(str);
1666
1406
  {
1667
- return window.btoa(str);
1407
+ return window.btoa(encodedStr);
1668
1408
  }
1669
1409
  }
1670
1410
  }
1671
1411
  /** Stop all api requests */
1672
1412
  abort() {
1673
- for (const req of this.activeRequests) {
1674
- req.cancel();
1413
+ for (const abortController of Object.values(this.activeRequests)) {
1414
+ abortController.abort();
1675
1415
  }
1676
- this.activeRequests = [];
1416
+ this.activeRequests = {};
1677
1417
  }
1678
1418
  getActiveApiRequests() {
1679
- return [...this.activeRequests];
1419
+ return __spreadValues({}, this.activeRequests);
1680
1420
  }
1681
1421
  /**
1682
1422
  * Send request to NGW api router.
@@ -1708,23 +1448,10 @@ class NgwConnector {
1708
1448
  * ```
1709
1449
  */
1710
1450
  apiRequest(name, params_ = {}, requestOptions = {}) {
1711
- var _a, _b;
1712
- const { method, headers, withCredentials, responseType } = requestOptions;
1451
+ var _a;
1713
1452
  params_ = (_a = requestOptions.params) != null ? _a : params_;
1714
1453
  const params = objectRemoveEmpty(params_);
1715
- const makeApiRequest = () => apiRequest({ name, params, requestOptions, connector: this });
1716
- if (requestOptions.cache && method === "GET") {
1717
- return this.cache.add(name, makeApiRequest, __spreadValues({
1718
- params
1719
- }, objectRemoveEmpty({
1720
- headers,
1721
- withCredentials,
1722
- responseType,
1723
- baseUrl: this.options.baseUrl,
1724
- userId: (_b = this.user) == null ? void 0 : _b.id
1725
- })));
1726
- }
1727
- return makeApiRequest();
1454
+ return apiRequest({ name, params, requestOptions, connector: this });
1728
1455
  }
1729
1456
  /**
1730
1457
  * Shortcut method for send POST request to NGW.
@@ -1814,17 +1541,67 @@ class NgwConnector {
1814
1541
  * @param params - Query params
1815
1542
  * @param options - Request options
1816
1543
  */
1817
- makeQuery(url, params, options = {}) {
1818
- url = (this.options.baseUrl ? this.options.baseUrl : "") + url;
1819
- if (url) {
1544
+ makeQuery(_0, _1) {
1545
+ return __async(this, arguments, function* (url, params, options = {}) {
1546
+ var _b;
1547
+ url = (this.options.baseUrl ? this.options.baseUrl : "") + url;
1548
+ if (!url) {
1549
+ throw new Error("Empty `url` not allowed");
1550
+ }
1820
1551
  if (params) {
1821
- url = template(url, params);
1552
+ const _a = params, restParams = __objRest(_a, ["paramList"]);
1553
+ url = template(url, restParams);
1822
1554
  }
1823
1555
  url = encodeURI(fixUrlStr(url));
1824
- return this._loadData(url, options);
1825
- } else {
1826
- throw new Error("Empty `url` not allowed");
1827
- }
1556
+ const {
1557
+ cache,
1558
+ signal: externalSignal,
1559
+ method = "GET",
1560
+ headers,
1561
+ cacheName,
1562
+ cacheProps,
1563
+ responseType,
1564
+ withCredentials
1565
+ } = options;
1566
+ const internalAbortController = new AbortController();
1567
+ const internalSignal = internalAbortController.signal;
1568
+ if (externalSignal) {
1569
+ if (externalSignal.aborted) {
1570
+ throw new AbortError();
1571
+ }
1572
+ externalSignal.addEventListener("abort", () => {
1573
+ internalAbortController.abort();
1574
+ });
1575
+ }
1576
+ options.signal = internalSignal;
1577
+ const createPromise = () => __async(this, null, function* () {
1578
+ const id = REQUEST_ID++;
1579
+ this.activeRequests[id] = internalAbortController;
1580
+ try {
1581
+ return this._loadData(url, options);
1582
+ } finally {
1583
+ this._cleanActiveRequest(id);
1584
+ }
1585
+ });
1586
+ if (cache && method === "GET") {
1587
+ const cacheOptions = cacheProps ? cacheProps : __spreadProps(__spreadValues({}, objectRemoveEmpty({
1588
+ headers,
1589
+ withCredentials,
1590
+ responseType,
1591
+ baseUrl: this.options.baseUrl,
1592
+ userId: (_b = this.user) == null ? void 0 : _b.id
1593
+ })), {
1594
+ params
1595
+ });
1596
+ return this.cache.add(
1597
+ cacheName || url,
1598
+ createPromise,
1599
+ cacheOptions,
1600
+ false
1601
+ );
1602
+ }
1603
+ return createPromise();
1604
+ });
1828
1605
  }
1829
1606
  // -------------------------------------------------------------------------
1830
1607
  // Resource Methods
@@ -1906,10 +1683,8 @@ class NgwConnector {
1906
1683
  */
1907
1684
  _loadData(url, options) {
1908
1685
  options.responseType = options.responseType || "json";
1909
- if (options.signal && options.signal.aborted) {
1910
- return CancelablePromise.reject(new CancelablePromise.CancelError());
1911
- }
1912
- const request = new CancelablePromise((resolve, reject, onCancel) => {
1686
+ return new Promise((resolve, reject) => {
1687
+ var _a;
1913
1688
  if (this.user) {
1914
1689
  options = options || {};
1915
1690
  options.headers = __spreadValues(__spreadValues({}, this.getAuthorizationHeaders()), options.headers);
@@ -1919,13 +1694,18 @@ class NgwConnector {
1919
1694
  url = transUrl;
1920
1695
  options = transOptions;
1921
1696
  }
1922
- loadData(url, resolve, options, reject, onCancel);
1923
- }).then((resp) => {
1924
- this._cleanActiveRequests(request);
1925
- return resp;
1697
+ let runOnAbort = void 0;
1698
+ loadData(url, resolve, options, reject, (handler) => {
1699
+ runOnAbort = handler;
1700
+ });
1701
+ (_a = options.signal) == null ? void 0 : _a.addEventListener("abort", () => {
1702
+ if (runOnAbort !== void 0) {
1703
+ runOnAbort();
1704
+ }
1705
+ reject(new AbortError());
1706
+ });
1926
1707
  }).catch((httpError) => {
1927
- this._cleanActiveRequests(request);
1928
- if (httpError instanceof CancelablePromise.CancelError) ; else {
1708
+ if (httpError.name !== "AbortError") {
1929
1709
  {
1930
1710
  console.warn("DEV WARN", httpError);
1931
1711
  }
@@ -1934,31 +1714,24 @@ class NgwConnector {
1934
1714
  throw er;
1935
1715
  }
1936
1716
  }
1717
+ throw httpError;
1937
1718
  });
1938
- if (options.signal && typeof options.signal.addEventListener === "function") {
1939
- options.signal.addEventListener("abort", () => {
1940
- request.cancel();
1941
- this._cleanActiveRequests(request);
1942
- });
1943
- }
1944
- this.activeRequests.push(request);
1945
- return request;
1946
1719
  }
1947
1720
  _login(credentials, options) {
1948
- return this.getUserInfo(credentials, options).then((data) => {
1949
- this.user = data;
1950
- this.emitter.emit("login", data);
1951
- return data;
1952
- }).catch((er) => {
1953
- this.emitter.emit("login:error", er);
1954
- throw er;
1721
+ return __async(this, null, function* () {
1722
+ try {
1723
+ const data = yield this.getUserInfo(credentials, options);
1724
+ this.user = data;
1725
+ this.emitter.emit("login", data);
1726
+ return data;
1727
+ } catch (er) {
1728
+ this.emitter.emit("login:error", er);
1729
+ throw er;
1730
+ }
1955
1731
  });
1956
1732
  }
1957
- _cleanActiveRequests(request) {
1958
- const activeRequestIndex = this.activeRequests.indexOf(request);
1959
- if (activeRequestIndex !== -1) {
1960
- this.activeRequests.splice(activeRequestIndex, 1);
1961
- }
1733
+ _cleanActiveRequest(requestId) {
1734
+ delete this.activeRequests[requestId];
1962
1735
  }
1963
1736
  _handleHttpError(er) {
1964
1737
  if (er) {