@nextgis/ngw-connector 2.5.0 → 3.0.0-alpha.1

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.5.0; author: NextGIS */
1
+ /** Bundle of @nextgis/ngw-connector; version: 3.0.0-alpha.1; 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, 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, 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, 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,39 +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
- if (requestOptions == null ? void 0 : requestOptions.cache) {
1111
- 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);
1112
782
  }
1113
- return makeRequest();
783
+ return Promise.resolve(void 0);
1114
784
  }
1115
785
  getOneOrFail(resource, requestOptions) {
1116
786
  return this.getOne(resource, requestOptions).then((res) => {
@@ -1132,7 +802,7 @@ class ResourcesControl {
1132
802
  */
1133
803
  getId(resource, requestOptions) {
1134
804
  if (typeof resource === "number") {
1135
- return CancelablePromise.resolve(resource);
805
+ return Promise.resolve(resource);
1136
806
  } else if (typeof resource === "string" || isObject(resource)) {
1137
807
  return this.getOne(resource, requestOptions).then((res) => {
1138
808
  if (res) {
@@ -1140,7 +810,7 @@ class ResourcesControl {
1140
810
  }
1141
811
  });
1142
812
  }
1143
- return CancelablePromise.resolve(void 0);
813
+ return Promise.resolve(void 0);
1144
814
  }
1145
815
  /**
1146
816
  * A fast way to retrieve resource ID for any resource definition.
@@ -1167,12 +837,12 @@ class ResourcesControl {
1167
837
  } else {
1168
838
  Object.assign(query, resourceToQuery(resource));
1169
839
  }
1170
- return this.connector.get("resource.search", requestOptions, __spreadValues$1({
840
+ return this.connector.get("resource.search", requestOptions, __spreadValues$2({
1171
841
  serialization: "full"
1172
842
  }, query)).then((resources) => {
1173
- if (resources) {
843
+ if ((requestOptions == null ? void 0 : requestOptions.cache) && resources) {
1174
844
  for (const x of resources) {
1175
- this.cache.add("resource.item", CancelablePromise.resolve(x), {
845
+ this.cache.add("resource.item", Promise.resolve(x), {
1176
846
  id: x.resource.id
1177
847
  });
1178
848
  }
@@ -1188,7 +858,7 @@ class ResourcesControl {
1188
858
  if (child) {
1189
859
  return this.getOne(child.resource.parent.id, requestOptions);
1190
860
  }
1191
- return CancelablePromise.resolve(void 0);
861
+ return Promise.resolve(void 0);
1192
862
  });
1193
863
  }
1194
864
  getChildrenOf(resource, requestOptions) {
@@ -1218,18 +888,16 @@ class ResourcesControl {
1218
888
  });
1219
889
  }
1220
890
  _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) => {
891
+ return this.connector.get("resource.collection", requestOptions, {
892
+ parent
893
+ }).then((items) => {
1228
894
  const recursivePromises = [];
1229
895
  for (const item of items) {
1230
- this.cache.add("resource.item", CancelablePromise.resolve(item), {
1231
- id: item.resource.id
1232
- });
896
+ if (requestOptions == null ? void 0 : requestOptions.cache) {
897
+ this.cache.add("resource.item", Promise.resolve(item), {
898
+ id: item.resource.id
899
+ });
900
+ }
1233
901
  _items.push(item);
1234
902
  if ((requestOptions == null ? void 0 : requestOptions.recursive) && item.resource.children) {
1235
903
  recursivePromises.push(
@@ -1238,7 +906,7 @@ class ResourcesControl {
1238
906
  }
1239
907
  }
1240
908
  if (recursivePromises.length) {
1241
- return CancelablePromise.all(recursivePromises).then(() => {
909
+ return Promise.all(recursivePromises).then(() => {
1242
910
  return _items;
1243
911
  });
1244
912
  }
@@ -1246,11 +914,12 @@ class ResourcesControl {
1246
914
  });
1247
915
  }
1248
916
  _cleanResourceItemCache(id) {
1249
- return __async(this, null, function* () {
917
+ return __async$2(this, null, function* () {
918
+ var _a;
1250
919
  const all = this.cache.all();
1251
920
  const toDelete = [];
1252
921
  for (const c of all) {
1253
- const cid = c.options && c.options.id;
922
+ const cid = (_a = c.props) == null ? void 0 : _a.id;
1254
923
  if (["resource.item", "resource"].includes(c.key) && cid !== void 0) {
1255
924
  if (typeof cid === "number") {
1256
925
  if (cid === id) {
@@ -1270,18 +939,7 @@ class ResourcesControl {
1270
939
  });
1271
940
  }
1272
941
  _fetchResourceById(id, requestOptions) {
1273
- const promise = () => this.connector.get("resource.item", requestOptions, { id });
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();
942
+ return this.connector.get("resource.item", requestOptions, { id });
1285
943
  }
1286
944
  _fetchResourceBy(resource, requestOptions) {
1287
945
  return this.getMany(resource, requestOptions).then((resources) => {
@@ -1289,7 +947,7 @@ class ResourcesControl {
1289
947
  });
1290
948
  }
1291
949
  _resourceCacheFilter(resource) {
1292
- return CancelablePromise.all(this.cache.matchAll("resource.item")).then(
950
+ return Promise.all(this.cache.matchAll("resource.item")).then(
1293
951
  (resources) => {
1294
952
  const items = [];
1295
953
  resources.filter((x) => {
@@ -1333,9 +991,16 @@ function removeConnector(connector) {
1333
991
  }
1334
992
  }
1335
993
 
1336
- var __defProp$2 = Object.defineProperty;
1337
- var __defNormalProp$2 = (obj, key, value) => key in obj ? __defProp$2(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
1338
- 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);
1339
1004
  class InsufficientPermissionsError extends NgwError {
1340
1005
  constructor(obj) {
1341
1006
  super(obj);
@@ -1358,58 +1023,90 @@ function template(str, data) {
1358
1023
  });
1359
1024
  }
1360
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
+ };
1361
1062
  function apiRequest(opt) {
1362
- const params = opt.params;
1363
- return new CancelablePromise((resolve, reject) => {
1364
- return opt.connector.connect().then((apiItems) => {
1365
- let apiItem = apiItems && apiItems[opt.name];
1366
- if (apiItem) {
1367
- apiItem = [...apiItem];
1368
- let url = apiItem.shift();
1369
- if (apiItem.length) {
1370
- const replaceParams = {};
1371
- for (let fry = 0; fry < apiItem.length; fry++) {
1372
- const arg = apiItem[fry];
1373
- replaceParams[fry] = "{" + arg + "}";
1374
- if (params[arg] === void 0) {
1375
- throw new Error(
1376
- "`" + arg + "` url api argument is not specified"
1377
- );
1378
- }
1379
- }
1380
- if (url) {
1381
- 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`);
1382
1077
  }
1383
1078
  }
1384
- if (params) {
1385
- const paramArray = [];
1386
- const paramList = params.paramList;
1387
- if (Array.isArray(paramList)) {
1388
- delete params.paramList;
1389
- paramList.forEach((x) => {
1390
- paramArray.push(`${x[0]}=${x[1]}`);
1391
- });
1392
- }
1393
- for (const p in params) {
1394
- if (apiItem.indexOf(p) === -1) {
1395
- paramArray.push(`${p}=${params[p]}`);
1396
- }
1397
- }
1398
- if (paramArray.length) {
1399
- 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]}`);
1400
1094
  }
1401
1095
  }
1402
- if (url) {
1403
- resolve(opt.connector.makeQuery(url, params, opt.requestOptions));
1404
- } else {
1405
- reject(new Error("request url is not set"));
1096
+ if (paramArray.length) {
1097
+ url = `${url}?${paramArray.join("&")}`;
1406
1098
  }
1099
+ }
1100
+ if (url) {
1101
+ return connector.makeQuery(url, params, __spreadValues$1({
1102
+ cacheName: name
1103
+ }, requestOptions));
1407
1104
  } else {
1408
- resolve(void 0);
1105
+ throw new Error("Request URL is not set");
1409
1106
  }
1410
- }).catch((er) => {
1411
- reject(er);
1412
- });
1107
+ } else {
1108
+ return void 0;
1109
+ }
1413
1110
  });
1414
1111
  }
1415
1112
 
@@ -1509,6 +1206,8 @@ let loadData;
1509
1206
  }
1510
1207
 
1511
1208
  var __defProp = Object.defineProperty;
1209
+ var __defProps = Object.defineProperties;
1210
+ var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
1512
1211
  var __getOwnPropSymbols = Object.getOwnPropertySymbols;
1513
1212
  var __hasOwnProp = Object.prototype.hasOwnProperty;
1514
1213
  var __propIsEnum = Object.prototype.propertyIsEnumerable;
@@ -1524,8 +1223,42 @@ var __spreadValues = (a, b) => {
1524
1223
  }
1525
1224
  return a;
1526
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
+ };
1527
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
+ };
1528
1260
  let ID = 0;
1261
+ let REQUEST_ID = 0;
1529
1262
  class NgwConnector {
1530
1263
  constructor(options) {
1531
1264
  this.options = options;
@@ -1536,7 +1269,7 @@ class NgwConnector {
1536
1269
  __publicField(this, "cache");
1537
1270
  __publicField(this, "withCredentials");
1538
1271
  __publicField(this, "routeStr", "/api/component/pyramid/route");
1539
- __publicField(this, "activeRequests", []);
1272
+ __publicField(this, "activeRequests", {});
1540
1273
  __publicField(this, "requestTransform");
1541
1274
  const exist = findConnector(options);
1542
1275
  this.cache = new Cache({ namespace: options.cacheId });
@@ -1597,29 +1330,27 @@ class NgwConnector {
1597
1330
  * ```
1598
1331
  */
1599
1332
  connect() {
1600
- const auth = this.options.auth;
1601
- const makeConnect = () => new CancelablePromise((resolve, reject) => {
1602
- const makeQuery = () => {
1603
- return this.makeQuery(this.routeStr, {}, {}).then((route) => {
1604
- resolve(route);
1605
- }).catch((er) => {
1606
- reject(er);
1607
- });
1608
- };
1333
+ return __async(this, null, function* () {
1334
+ const auth = this.options.auth;
1609
1335
  if (auth) {
1610
1336
  const { login, password } = auth;
1611
1337
  if (login && password) {
1612
- return this._login({ login, password }).then(() => {
1613
- return makeQuery();
1614
- }).catch((er) => reject(er));
1338
+ yield this._login({ login, password });
1615
1339
  }
1616
1340
  }
1617
- return makeQuery();
1618
- });
1619
- return this.cache.add("route", makeConnect, {
1620
- id: this.id,
1621
- auth,
1622
- baseUrl: this.options.baseUrl
1341
+ return yield this.makeQuery(
1342
+ this.routeStr,
1343
+ {},
1344
+ {
1345
+ cacheName: "route",
1346
+ cache: true,
1347
+ cacheProps: {
1348
+ id: this.id,
1349
+ auth,
1350
+ baseUrl: this.options.baseUrl
1351
+ }
1352
+ }
1353
+ );
1623
1354
  });
1624
1355
  }
1625
1356
  /**
@@ -1643,20 +1374,22 @@ class NgwConnector {
1643
1374
  this.emitter.emit("logout");
1644
1375
  }
1645
1376
  getUserInfo(credentials, options) {
1646
- if (this.user && this.user.id) {
1647
- return CancelablePromise.resolve(this.user);
1648
- }
1649
- if (credentials) {
1650
- this.options.auth = credentials;
1651
- }
1652
- const options_ = __spreadValues({
1653
- headers: this.getAuthorizationHeaders(credentials)
1654
- }, options);
1655
- return this.makeQuery(
1656
- "/api/component/auth/current_user",
1657
- {},
1658
- options_
1659
- );
1377
+ return __async(this, null, function* () {
1378
+ if (this.user && this.user.id) {
1379
+ return this.user;
1380
+ }
1381
+ if (credentials) {
1382
+ this.options.auth = credentials;
1383
+ }
1384
+ const options_ = __spreadValues({
1385
+ headers: this.getAuthorizationHeaders(credentials)
1386
+ }, options);
1387
+ return this.makeQuery(
1388
+ "/api/component/auth/current_user",
1389
+ {},
1390
+ options_
1391
+ );
1392
+ });
1660
1393
  }
1661
1394
  /**
1662
1395
  * Obtaining the required Headers for authentication of requests in the NGW.
@@ -1665,7 +1398,7 @@ class NgwConnector {
1665
1398
  const client = this.makeClientId(credentials);
1666
1399
  if (client) {
1667
1400
  return {
1668
- Authorization: "Basic " + client
1401
+ Authorization: `Basic ${client}`
1669
1402
  };
1670
1403
  }
1671
1404
  }
@@ -1673,21 +1406,22 @@ class NgwConnector {
1673
1406
  credentials = credentials || this.options.auth;
1674
1407
  if (credentials) {
1675
1408
  const { login, password } = credentials;
1676
- const str = unescape(encodeURIComponent(`${login}:${password}`));
1409
+ const str = `${login}:${password}`;
1410
+ const encodedStr = encodeURIComponent(str);
1677
1411
  {
1678
- return window.btoa(str);
1412
+ return window.btoa(encodedStr);
1679
1413
  }
1680
1414
  }
1681
1415
  }
1682
1416
  /** Stop all api requests */
1683
1417
  abort() {
1684
- for (const req of this.activeRequests) {
1685
- req.cancel();
1418
+ for (const abortController of Object.values(this.activeRequests)) {
1419
+ abortController.abort();
1686
1420
  }
1687
- this.activeRequests = [];
1421
+ this.activeRequests = {};
1688
1422
  }
1689
1423
  getActiveApiRequests() {
1690
- return [...this.activeRequests];
1424
+ return __spreadValues({}, this.activeRequests);
1691
1425
  }
1692
1426
  /**
1693
1427
  * Send request to NGW api router.
@@ -1719,26 +1453,10 @@ class NgwConnector {
1719
1453
  * ```
1720
1454
  */
1721
1455
  apiRequest(name, params_ = {}, requestOptions = {}) {
1722
- var _a, _b;
1723
- requestOptions = __spreadValues({
1724
- withCredentials: this.withCredentials
1725
- }, requestOptions);
1726
- const { method, headers, withCredentials, responseType } = requestOptions;
1456
+ var _a;
1727
1457
  params_ = (_a = requestOptions.params) != null ? _a : params_;
1728
1458
  const params = objectRemoveEmpty(params_);
1729
- const makeApiRequest = () => apiRequest({ name, params, requestOptions, connector: this });
1730
- if (requestOptions.cache && method === "GET") {
1731
- return this.cache.add(name, makeApiRequest, __spreadValues({
1732
- params
1733
- }, objectRemoveEmpty({
1734
- headers,
1735
- withCredentials,
1736
- responseType,
1737
- baseUrl: this.options.baseUrl,
1738
- userId: (_b = this.user) == null ? void 0 : _b.id
1739
- })));
1740
- }
1741
- return makeApiRequest();
1459
+ return apiRequest({ name, params, requestOptions, connector: this });
1742
1460
  }
1743
1461
  /**
1744
1462
  * Shortcut method for send POST request to NGW.
@@ -1828,17 +1546,68 @@ class NgwConnector {
1828
1546
  * @param params - Query params
1829
1547
  * @param options - Request options
1830
1548
  */
1831
- makeQuery(url, params, options = {}) {
1832
- url = (this.options.baseUrl ? this.options.baseUrl : "") + url;
1833
- if (url) {
1549
+ makeQuery(_0, _1) {
1550
+ return __async(this, arguments, function* (url, params, options = {}) {
1551
+ var _b;
1552
+ url = (this.options.baseUrl ? this.options.baseUrl : "") + url;
1553
+ if (!url) {
1554
+ throw new Error("Empty `url` not allowed");
1555
+ }
1834
1556
  if (params) {
1835
- url = template(url, params);
1557
+ const _a = params, restParams = __objRest(_a, ["paramList"]);
1558
+ url = template(url, restParams);
1836
1559
  }
1837
1560
  url = encodeURI(fixUrlStr(url));
1838
- return this._loadData(url, options);
1839
- } else {
1840
- throw new Error("Empty `url` not allowed");
1841
- }
1561
+ options = __spreadValues({ withCredentials: this.withCredentials }, options);
1562
+ const {
1563
+ cache,
1564
+ signal: externalSignal,
1565
+ method = "GET",
1566
+ headers,
1567
+ cacheName,
1568
+ cacheProps,
1569
+ responseType,
1570
+ withCredentials
1571
+ } = options;
1572
+ const internalAbortController = new AbortController();
1573
+ const internalSignal = internalAbortController.signal;
1574
+ if (externalSignal) {
1575
+ if (externalSignal.aborted) {
1576
+ throw new AbortError();
1577
+ }
1578
+ externalSignal.addEventListener("abort", () => {
1579
+ internalAbortController.abort();
1580
+ });
1581
+ }
1582
+ options.signal = internalSignal;
1583
+ const createPromise = () => __async(this, null, function* () {
1584
+ const id = REQUEST_ID++;
1585
+ this.activeRequests[id] = internalAbortController;
1586
+ try {
1587
+ return this._loadData(url, options);
1588
+ } finally {
1589
+ this._cleanActiveRequest(id);
1590
+ }
1591
+ });
1592
+ if (cache && method === "GET") {
1593
+ const cacheOptions = cacheProps ? cacheProps : __spreadProps(__spreadValues({}, objectRemoveEmpty({
1594
+ headers,
1595
+ withCredentials,
1596
+ responseType,
1597
+ baseUrl: this.options.baseUrl,
1598
+ userId: (_b = this.user) == null ? void 0 : _b.id
1599
+ })), {
1600
+ params
1601
+ });
1602
+ return this.cache.add(
1603
+ cacheName || url,
1604
+ createPromise,
1605
+ cacheOptions,
1606
+ false
1607
+ );
1608
+ }
1609
+ return createPromise();
1610
+ });
1842
1611
  }
1843
1612
  // -------------------------------------------------------------------------
1844
1613
  // Resource Methods
@@ -1920,10 +1689,8 @@ class NgwConnector {
1920
1689
  */
1921
1690
  _loadData(url, options) {
1922
1691
  options.responseType = options.responseType || "json";
1923
- if (options.signal && options.signal.aborted) {
1924
- return CancelablePromise.reject(new CancelablePromise.CancelError());
1925
- }
1926
- const request = new CancelablePromise((resolve, reject, onCancel) => {
1692
+ return new Promise((resolve, reject) => {
1693
+ var _a;
1927
1694
  if (this.user) {
1928
1695
  options = options || {};
1929
1696
  options.headers = __spreadValues(__spreadValues({}, this.getAuthorizationHeaders()), options.headers);
@@ -1933,13 +1700,18 @@ class NgwConnector {
1933
1700
  url = transUrl;
1934
1701
  options = transOptions;
1935
1702
  }
1936
- loadData(url, resolve, options, reject, onCancel);
1937
- }).then((resp) => {
1938
- this._cleanActiveRequests(request);
1939
- return resp;
1703
+ let runOnAbort = void 0;
1704
+ loadData(url, resolve, options, reject, (handler) => {
1705
+ runOnAbort = handler;
1706
+ });
1707
+ (_a = options.signal) == null ? void 0 : _a.addEventListener("abort", () => {
1708
+ if (runOnAbort !== void 0) {
1709
+ runOnAbort();
1710
+ }
1711
+ reject(new AbortError());
1712
+ });
1940
1713
  }).catch((httpError) => {
1941
- this._cleanActiveRequests(request);
1942
- if (httpError instanceof CancelablePromise.CancelError) ; else {
1714
+ if (httpError.name !== "AbortError") {
1943
1715
  {
1944
1716
  console.warn("DEV WARN", httpError);
1945
1717
  }
@@ -1948,31 +1720,24 @@ class NgwConnector {
1948
1720
  throw er;
1949
1721
  }
1950
1722
  }
1723
+ throw httpError;
1951
1724
  });
1952
- if (options.signal && typeof options.signal.addEventListener === "function") {
1953
- options.signal.addEventListener("abort", () => {
1954
- request.cancel();
1955
- this._cleanActiveRequests(request);
1956
- });
1957
- }
1958
- this.activeRequests.push(request);
1959
- return request;
1960
1725
  }
1961
1726
  _login(credentials, options) {
1962
- return this.getUserInfo(credentials, options).then((data) => {
1963
- this.user = data;
1964
- this.emitter.emit("login", data);
1965
- return data;
1966
- }).catch((er) => {
1967
- this.emitter.emit("login:error", er);
1968
- throw er;
1727
+ return __async(this, null, function* () {
1728
+ try {
1729
+ const data = yield this.getUserInfo(credentials, options);
1730
+ this.user = data;
1731
+ this.emitter.emit("login", data);
1732
+ return data;
1733
+ } catch (er) {
1734
+ this.emitter.emit("login:error", er);
1735
+ throw er;
1736
+ }
1969
1737
  });
1970
1738
  }
1971
- _cleanActiveRequests(request) {
1972
- const activeRequestIndex = this.activeRequests.indexOf(request);
1973
- if (activeRequestIndex !== -1) {
1974
- this.activeRequests.splice(activeRequestIndex, 1);
1975
- }
1739
+ _cleanActiveRequest(requestId) {
1740
+ delete this.activeRequests[requestId];
1976
1741
  }
1977
1742
  _handleHttpError(er) {
1978
1743
  if (er) {