@nextgis/ngw-connector 2.4.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.4.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,39 +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
- if (requestOptions == null ? void 0 : requestOptions.cache) {
1114
- 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);
1115
785
  }
1116
- return makeRequest();
786
+ return Promise.resolve(void 0);
1117
787
  }
1118
788
  getOneOrFail(resource, requestOptions) {
1119
789
  return this.getOne(resource, requestOptions).then((res) => {
@@ -1135,7 +805,7 @@ var NgwConnector = (function () {
1135
805
  */
1136
806
  getId(resource, requestOptions) {
1137
807
  if (typeof resource === "number") {
1138
- return CancelablePromise.resolve(resource);
808
+ return Promise.resolve(resource);
1139
809
  } else if (typeof resource === "string" || isObject(resource)) {
1140
810
  return this.getOne(resource, requestOptions).then((res) => {
1141
811
  if (res) {
@@ -1143,7 +813,7 @@ var NgwConnector = (function () {
1143
813
  }
1144
814
  });
1145
815
  }
1146
- return CancelablePromise.resolve(void 0);
816
+ return Promise.resolve(void 0);
1147
817
  }
1148
818
  /**
1149
819
  * A fast way to retrieve resource ID for any resource definition.
@@ -1170,12 +840,12 @@ var NgwConnector = (function () {
1170
840
  } else {
1171
841
  Object.assign(query, resourceToQuery(resource));
1172
842
  }
1173
- return this.connector.get("resource.search", requestOptions, __spreadValues$1({
843
+ return this.connector.get("resource.search", requestOptions, __spreadValues$2({
1174
844
  serialization: "full"
1175
845
  }, query)).then((resources) => {
1176
- if (resources) {
846
+ if ((requestOptions == null ? void 0 : requestOptions.cache) && resources) {
1177
847
  for (const x of resources) {
1178
- this.cache.add("resource.item", CancelablePromise.resolve(x), {
848
+ this.cache.add("resource.item", Promise.resolve(x), {
1179
849
  id: x.resource.id
1180
850
  });
1181
851
  }
@@ -1191,7 +861,7 @@ var NgwConnector = (function () {
1191
861
  if (child) {
1192
862
  return this.getOne(child.resource.parent.id, requestOptions);
1193
863
  }
1194
- return CancelablePromise.resolve(void 0);
864
+ return Promise.resolve(void 0);
1195
865
  });
1196
866
  }
1197
867
  getChildrenOf(resource, requestOptions) {
@@ -1221,18 +891,16 @@ var NgwConnector = (function () {
1221
891
  });
1222
892
  }
1223
893
  _getChildrenOf(parent, requestOptions, _items = []) {
1224
- return this.connector.get(
1225
- "resource.collection",
1226
- __spreadValues$1({ cache: true }, requestOptions),
1227
- {
1228
- parent
1229
- }
1230
- ).then((items) => {
894
+ return this.connector.get("resource.collection", requestOptions, {
895
+ parent
896
+ }).then((items) => {
1231
897
  const recursivePromises = [];
1232
898
  for (const item of items) {
1233
- this.cache.add("resource.item", CancelablePromise.resolve(item), {
1234
- id: item.resource.id
1235
- });
899
+ if (requestOptions == null ? void 0 : requestOptions.cache) {
900
+ this.cache.add("resource.item", Promise.resolve(item), {
901
+ id: item.resource.id
902
+ });
903
+ }
1236
904
  _items.push(item);
1237
905
  if ((requestOptions == null ? void 0 : requestOptions.recursive) && item.resource.children) {
1238
906
  recursivePromises.push(
@@ -1241,7 +909,7 @@ var NgwConnector = (function () {
1241
909
  }
1242
910
  }
1243
911
  if (recursivePromises.length) {
1244
- return CancelablePromise.all(recursivePromises).then(() => {
912
+ return Promise.all(recursivePromises).then(() => {
1245
913
  return _items;
1246
914
  });
1247
915
  }
@@ -1249,11 +917,12 @@ var NgwConnector = (function () {
1249
917
  });
1250
918
  }
1251
919
  _cleanResourceItemCache(id) {
1252
- return __async(this, null, function* () {
920
+ return __async$2(this, null, function* () {
921
+ var _a;
1253
922
  const all = this.cache.all();
1254
923
  const toDelete = [];
1255
924
  for (const c of all) {
1256
- const cid = c.options && c.options.id;
925
+ const cid = (_a = c.props) == null ? void 0 : _a.id;
1257
926
  if (["resource.item", "resource"].includes(c.key) && cid !== void 0) {
1258
927
  if (typeof cid === "number") {
1259
928
  if (cid === id) {
@@ -1273,18 +942,7 @@ var NgwConnector = (function () {
1273
942
  });
1274
943
  }
1275
944
  _fetchResourceById(id, requestOptions) {
1276
- const promise = () => this.connector.get("resource.item", requestOptions, { id });
1277
- if (requestOptions == null ? void 0 : requestOptions.cache) {
1278
- return this.cache.add("resource.item", promise, {
1279
- id
1280
- }).catch((er) => {
1281
- if (!(er instanceof ResourceNotFoundError)) {
1282
- throw er;
1283
- }
1284
- return void 0;
1285
- });
1286
- }
1287
- return promise();
945
+ return this.connector.get("resource.item", requestOptions, { id });
1288
946
  }
1289
947
  _fetchResourceBy(resource, requestOptions) {
1290
948
  return this.getMany(resource, requestOptions).then((resources) => {
@@ -1292,7 +950,7 @@ var NgwConnector = (function () {
1292
950
  });
1293
951
  }
1294
952
  _resourceCacheFilter(resource) {
1295
- return CancelablePromise.all(this.cache.matchAll("resource.item")).then(
953
+ return Promise.all(this.cache.matchAll("resource.item")).then(
1296
954
  (resources) => {
1297
955
  const items = [];
1298
956
  resources.filter((x) => {
@@ -1336,9 +994,16 @@ var NgwConnector = (function () {
1336
994
  }
1337
995
  }
1338
996
 
1339
- var __defProp$2 = Object.defineProperty;
1340
- var __defNormalProp$2 = (obj, key, value) => key in obj ? __defProp$2(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
1341
- 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);
1342
1007
  class InsufficientPermissionsError extends NgwError {
1343
1008
  constructor(obj) {
1344
1009
  super(obj);
@@ -1361,64 +1026,96 @@ var NgwConnector = (function () {
1361
1026
  });
1362
1027
  }
1363
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
+ };
1364
1065
  function apiRequest(opt) {
1365
- const params = opt.params;
1366
- return new CancelablePromise((resolve, reject) => {
1367
- return opt.connector.connect().then((apiItems) => {
1368
- let apiItem = apiItems && apiItems[opt.name];
1369
- if (apiItem) {
1370
- apiItem = [...apiItem];
1371
- let url = apiItem.shift();
1372
- if (apiItem.length) {
1373
- const replaceParams = {};
1374
- for (let fry = 0; fry < apiItem.length; fry++) {
1375
- const arg = apiItem[fry];
1376
- replaceParams[fry] = "{" + arg + "}";
1377
- if (params[arg] === void 0) {
1378
- throw new Error(
1379
- "`" + arg + "` url api argument is not specified"
1380
- );
1381
- }
1382
- }
1383
- if (url) {
1384
- 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`);
1385
1080
  }
1386
1081
  }
1387
- if (params) {
1388
- const paramArray = [];
1389
- const paramList = params.paramList;
1390
- if (Array.isArray(paramList)) {
1391
- delete params.paramList;
1392
- paramList.forEach((x) => {
1393
- paramArray.push(`${x[0]}=${x[1]}`);
1394
- });
1395
- }
1396
- for (const p in params) {
1397
- if (apiItem.indexOf(p) === -1) {
1398
- paramArray.push(`${p}=${params[p]}`);
1399
- }
1400
- }
1401
- if (paramArray.length) {
1402
- 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]}`);
1403
1097
  }
1404
1098
  }
1405
- if (url) {
1406
- resolve(opt.connector.makeQuery(url, params, opt.requestOptions));
1407
- } else {
1408
- reject(new Error("request url is not set"));
1099
+ if (paramArray.length) {
1100
+ url = `${url}?${paramArray.join("&")}`;
1409
1101
  }
1102
+ }
1103
+ if (url) {
1104
+ return connector.makeQuery(url, params, __spreadValues$1({
1105
+ cacheName: name
1106
+ }, requestOptions));
1410
1107
  } else {
1411
- resolve(void 0);
1108
+ throw new Error("Request URL is not set");
1412
1109
  }
1413
- }).catch((er) => {
1414
- reject(er);
1415
- });
1110
+ } else {
1111
+ return void 0;
1112
+ }
1416
1113
  });
1417
1114
  }
1418
1115
 
1419
1116
  var __defProp$1 = Object.defineProperty;
1420
1117
  var __defNormalProp$1 = (obj, key, value) => key in obj ? __defProp$1(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
1421
- 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);
1422
1119
  class NetworkError extends Error {
1423
1120
  constructor(url) {
1424
1121
  super();
@@ -1512,6 +1209,8 @@ var NgwConnector = (function () {
1512
1209
  }
1513
1210
 
1514
1211
  var __defProp = Object.defineProperty;
1212
+ var __defProps = Object.defineProperties;
1213
+ var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
1515
1214
  var __getOwnPropSymbols = Object.getOwnPropertySymbols;
1516
1215
  var __hasOwnProp = Object.prototype.hasOwnProperty;
1517
1216
  var __propIsEnum = Object.prototype.propertyIsEnumerable;
@@ -1527,8 +1226,42 @@ var NgwConnector = (function () {
1527
1226
  }
1528
1227
  return a;
1529
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
+ };
1530
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
+ };
1531
1263
  let ID = 0;
1264
+ let REQUEST_ID = 0;
1532
1265
  class NgwConnector {
1533
1266
  constructor(options) {
1534
1267
  this.options = options;
@@ -1538,7 +1271,7 @@ var NgwConnector = (function () {
1538
1271
  __publicField(this, "resources");
1539
1272
  __publicField(this, "cache");
1540
1273
  __publicField(this, "routeStr", "/api/component/pyramid/route");
1541
- __publicField(this, "activeRequests", []);
1274
+ __publicField(this, "activeRequests", {});
1542
1275
  __publicField(this, "requestTransform");
1543
1276
  const exist = findConnector(options);
1544
1277
  this.cache = new Cache({ namespace: options.cacheId });
@@ -1595,29 +1328,27 @@ var NgwConnector = (function () {
1595
1328
  * ```
1596
1329
  */
1597
1330
  connect() {
1598
- const auth = this.options.auth;
1599
- const makeConnect = () => new CancelablePromise((resolve, reject) => {
1600
- const makeQuery = () => {
1601
- return this.makeQuery(this.routeStr, {}, {}).then((route) => {
1602
- resolve(route);
1603
- }).catch((er) => {
1604
- reject(er);
1605
- });
1606
- };
1331
+ return __async(this, null, function* () {
1332
+ const auth = this.options.auth;
1607
1333
  if (auth) {
1608
1334
  const { login, password } = auth;
1609
1335
  if (login && password) {
1610
- return this._login({ login, password }).then(() => {
1611
- return makeQuery();
1612
- }).catch((er) => reject(er));
1336
+ yield this._login({ login, password });
1613
1337
  }
1614
1338
  }
1615
- return makeQuery();
1616
- });
1617
- return this.cache.add("route", makeConnect, {
1618
- id: this.id,
1619
- auth,
1620
- 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
+ );
1621
1352
  });
1622
1353
  }
1623
1354
  /**
@@ -1641,20 +1372,22 @@ var NgwConnector = (function () {
1641
1372
  this.emitter.emit("logout");
1642
1373
  }
1643
1374
  getUserInfo(credentials, options) {
1644
- if (this.user && this.user.id) {
1645
- return CancelablePromise.resolve(this.user);
1646
- }
1647
- if (credentials) {
1648
- this.options.auth = credentials;
1649
- }
1650
- const options_ = __spreadValues({
1651
- headers: this.getAuthorizationHeaders(credentials)
1652
- }, options);
1653
- return this.makeQuery(
1654
- "/api/component/auth/current_user",
1655
- {},
1656
- options_
1657
- );
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
+ });
1658
1391
  }
1659
1392
  /**
1660
1393
  * Obtaining the required Headers for authentication of requests in the NGW.
@@ -1663,7 +1396,7 @@ var NgwConnector = (function () {
1663
1396
  const client = this.makeClientId(credentials);
1664
1397
  if (client) {
1665
1398
  return {
1666
- Authorization: "Basic " + client
1399
+ Authorization: `Basic ${client}`
1667
1400
  };
1668
1401
  }
1669
1402
  }
@@ -1671,21 +1404,22 @@ var NgwConnector = (function () {
1671
1404
  credentials = credentials || this.options.auth;
1672
1405
  if (credentials) {
1673
1406
  const { login, password } = credentials;
1674
- const str = unescape(encodeURIComponent(`${login}:${password}`));
1407
+ const str = `${login}:${password}`;
1408
+ const encodedStr = encodeURIComponent(str);
1675
1409
  {
1676
- return window.btoa(str);
1410
+ return window.btoa(encodedStr);
1677
1411
  }
1678
1412
  }
1679
1413
  }
1680
1414
  /** Stop all api requests */
1681
1415
  abort() {
1682
- for (const req of this.activeRequests) {
1683
- req.cancel();
1416
+ for (const abortController of Object.values(this.activeRequests)) {
1417
+ abortController.abort();
1684
1418
  }
1685
- this.activeRequests = [];
1419
+ this.activeRequests = {};
1686
1420
  }
1687
1421
  getActiveApiRequests() {
1688
- return [...this.activeRequests];
1422
+ return __spreadValues({}, this.activeRequests);
1689
1423
  }
1690
1424
  /**
1691
1425
  * Send request to NGW api router.
@@ -1717,23 +1451,10 @@ var NgwConnector = (function () {
1717
1451
  * ```
1718
1452
  */
1719
1453
  apiRequest(name, params_ = {}, requestOptions = {}) {
1720
- var _a, _b;
1721
- const { method, headers, withCredentials, responseType } = requestOptions;
1454
+ var _a;
1722
1455
  params_ = (_a = requestOptions.params) != null ? _a : params_;
1723
1456
  const params = objectRemoveEmpty(params_);
1724
- const makeApiRequest = () => apiRequest({ name, params, requestOptions, connector: this });
1725
- if (requestOptions.cache && method === "GET") {
1726
- return this.cache.add(name, makeApiRequest, __spreadValues({
1727
- params
1728
- }, objectRemoveEmpty({
1729
- headers,
1730
- withCredentials,
1731
- responseType,
1732
- baseUrl: this.options.baseUrl,
1733
- userId: (_b = this.user) == null ? void 0 : _b.id
1734
- })));
1735
- }
1736
- return makeApiRequest();
1457
+ return apiRequest({ name, params, requestOptions, connector: this });
1737
1458
  }
1738
1459
  /**
1739
1460
  * Shortcut method for send POST request to NGW.
@@ -1823,17 +1544,67 @@ var NgwConnector = (function () {
1823
1544
  * @param params - Query params
1824
1545
  * @param options - Request options
1825
1546
  */
1826
- makeQuery(url, params, options = {}) {
1827
- url = (this.options.baseUrl ? this.options.baseUrl : "") + url;
1828
- 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
+ }
1829
1554
  if (params) {
1830
- url = template(url, params);
1555
+ const _a = params, restParams = __objRest(_a, ["paramList"]);
1556
+ url = template(url, restParams);
1831
1557
  }
1832
1558
  url = encodeURI(fixUrlStr(url));
1833
- return this._loadData(url, options);
1834
- } else {
1835
- throw new Error("Empty `url` not allowed");
1836
- }
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
+ });
1837
1608
  }
1838
1609
  // -------------------------------------------------------------------------
1839
1610
  // Resource Methods
@@ -1915,10 +1686,8 @@ var NgwConnector = (function () {
1915
1686
  */
1916
1687
  _loadData(url, options) {
1917
1688
  options.responseType = options.responseType || "json";
1918
- if (options.signal && options.signal.aborted) {
1919
- return CancelablePromise.reject(new CancelablePromise.CancelError());
1920
- }
1921
- const request = new CancelablePromise((resolve, reject, onCancel) => {
1689
+ return new Promise((resolve, reject) => {
1690
+ var _a;
1922
1691
  if (this.user) {
1923
1692
  options = options || {};
1924
1693
  options.headers = __spreadValues(__spreadValues({}, this.getAuthorizationHeaders()), options.headers);
@@ -1928,13 +1697,18 @@ var NgwConnector = (function () {
1928
1697
  url = transUrl;
1929
1698
  options = transOptions;
1930
1699
  }
1931
- loadData(url, resolve, options, reject, onCancel);
1932
- }).then((resp) => {
1933
- this._cleanActiveRequests(request);
1934
- 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
+ });
1935
1710
  }).catch((httpError) => {
1936
- this._cleanActiveRequests(request);
1937
- if (httpError instanceof CancelablePromise.CancelError) ; else {
1711
+ if (httpError.name !== "AbortError") {
1938
1712
  {
1939
1713
  console.warn("DEV WARN", httpError);
1940
1714
  }
@@ -1943,31 +1717,24 @@ var NgwConnector = (function () {
1943
1717
  throw er;
1944
1718
  }
1945
1719
  }
1720
+ throw httpError;
1946
1721
  });
1947
- if (options.signal && typeof options.signal.addEventListener === "function") {
1948
- options.signal.addEventListener("abort", () => {
1949
- request.cancel();
1950
- this._cleanActiveRequests(request);
1951
- });
1952
- }
1953
- this.activeRequests.push(request);
1954
- return request;
1955
1722
  }
1956
1723
  _login(credentials, options) {
1957
- return this.getUserInfo(credentials, options).then((data) => {
1958
- this.user = data;
1959
- this.emitter.emit("login", data);
1960
- return data;
1961
- }).catch((er) => {
1962
- this.emitter.emit("login:error", er);
1963
- 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
+ }
1964
1734
  });
1965
1735
  }
1966
- _cleanActiveRequests(request) {
1967
- const activeRequestIndex = this.activeRequests.indexOf(request);
1968
- if (activeRequestIndex !== -1) {
1969
- this.activeRequests.splice(activeRequestIndex, 1);
1970
- }
1736
+ _cleanActiveRequest(requestId) {
1737
+ delete this.activeRequests[requestId];
1971
1738
  }
1972
1739
  _handleHttpError(er) {
1973
1740
  if (er) {