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