@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.
- package/lib/index.d.ts +45 -37
- package/lib/ngw-connector.cjs.js +193 -190
- package/lib/ngw-connector.cjs.js.map +1 -1
- package/lib/ngw-connector.cjs.prod.js +1 -1
- package/lib/ngw-connector.cjs.prod.js.map +1 -1
- package/lib/ngw-connector.esm-browser.js +320 -553
- package/lib/ngw-connector.esm-browser.js.map +1 -1
- package/lib/ngw-connector.esm-browser.prod.js +1 -1
- package/lib/ngw-connector.esm-browser.prod.js.map +1 -1
- package/lib/ngw-connector.esm-bundler.js +303 -222
- package/lib/ngw-connector.esm-bundler.js.map +1 -1
- package/lib/ngw-connector.esm-bundler.prod.js +1 -1
- package/lib/ngw-connector.esm-bundler.prod.js.map +1 -1
- package/lib/ngw-connector.global.js +320 -553
- package/lib/ngw-connector.global.js.map +1 -1
- package/lib/ngw-connector.global.prod.js +1 -1
- package/lib/ngw-connector.global.prod.js.map +1 -1
- package/package.json +6 -6
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
/** Bundle of @nextgis/ngw-connector; version:
|
|
1
|
+
/** Bundle of @nextgis/ngw-connector; version: 3.0.0-alpha.0; author: NextGIS */
|
|
2
2
|
var domain;
|
|
3
3
|
|
|
4
4
|
// This constructor is used to store event handlers. Instantiating this is
|
|
@@ -528,12 +528,12 @@ function fixUrlStr(url) {
|
|
|
528
528
|
return url.replace(/([^:]\/)\/+/g, "$1");
|
|
529
529
|
}
|
|
530
530
|
|
|
531
|
-
var __defProp$
|
|
532
|
-
var __defNormalProp$
|
|
533
|
-
var __publicField$
|
|
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$
|
|
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
|
|
584
|
+
const nonEmptyProps = props && JSON.parse(JSON.stringify(objectRemoveEmpty(props)));
|
|
586
585
|
const cacheItem = {
|
|
587
586
|
key,
|
|
588
587
|
value,
|
|
589
|
-
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
|
-
|
|
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
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
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
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
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$
|
|
642
|
+
__publicField$6(_Cache, "instance", {});
|
|
656
643
|
let Cache = _Cache;
|
|
657
644
|
|
|
658
|
-
var __defProp$9 = Object.defineProperty;
|
|
659
|
-
var __defNormalProp$9 = (obj, key, value) => key in obj ? __defProp$9(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
660
|
-
var __publicField$9 = (obj, key, value) => __defNormalProp$9(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
661
|
-
class CancelError extends Error {
|
|
662
|
-
constructor() {
|
|
663
|
-
super();
|
|
664
|
-
__publicField$9(this, "name", "CancelError");
|
|
665
|
-
Object.setPrototypeOf(this, CancelError.prototype);
|
|
666
|
-
}
|
|
667
|
-
}
|
|
668
|
-
|
|
669
|
-
var __defProp$8 = Object.defineProperty;
|
|
670
|
-
var __defNormalProp$8 = (obj, key, value) => key in obj ? __defProp$8(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
671
|
-
var __publicField$8 = (obj, key, value) => __defNormalProp$8(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
672
|
-
class PromiseControl {
|
|
673
|
-
constructor(options = {}) {
|
|
674
|
-
this.options = options;
|
|
675
|
-
__publicField$8(this, "_promises", /* @__PURE__ */ new Map());
|
|
676
|
-
}
|
|
677
|
-
get isLoaded() {
|
|
678
|
-
return this._promises.size > 0;
|
|
679
|
-
}
|
|
680
|
-
remove(promise) {
|
|
681
|
-
if (this._promises.has(promise)) {
|
|
682
|
-
this._promises.delete(promise);
|
|
683
|
-
this._onStop();
|
|
684
|
-
}
|
|
685
|
-
}
|
|
686
|
-
get(promise) {
|
|
687
|
-
return this._promises.get(promise);
|
|
688
|
-
}
|
|
689
|
-
add(promise, name) {
|
|
690
|
-
const key = name ? name : promise;
|
|
691
|
-
const exist = this._promises.get(key);
|
|
692
|
-
if (this.options.onStart && !this.isLoaded) {
|
|
693
|
-
this.options.onStart();
|
|
694
|
-
}
|
|
695
|
-
if (exist) {
|
|
696
|
-
return exist;
|
|
697
|
-
}
|
|
698
|
-
this._promises.set(key, promise);
|
|
699
|
-
promise.finally(() => {
|
|
700
|
-
this.remove(key);
|
|
701
|
-
});
|
|
702
|
-
return promise;
|
|
703
|
-
}
|
|
704
|
-
abort() {
|
|
705
|
-
if (this.isLoaded) {
|
|
706
|
-
this._promises.forEach((x) => {
|
|
707
|
-
if (x.cancel) {
|
|
708
|
-
x.cancel();
|
|
709
|
-
}
|
|
710
|
-
});
|
|
711
|
-
this._promises.clear();
|
|
712
|
-
this._onStop();
|
|
713
|
-
}
|
|
714
|
-
}
|
|
715
|
-
waitFunc(func, name = "") {
|
|
716
|
-
name = name || func.name;
|
|
717
|
-
const exist = this.get(name);
|
|
718
|
-
if (exist) {
|
|
719
|
-
return exist;
|
|
720
|
-
}
|
|
721
|
-
return this.add(func(), name);
|
|
722
|
-
}
|
|
723
|
-
WaitForMe(name = "") {
|
|
724
|
-
const get = this.get.bind(this);
|
|
725
|
-
const add = this.add.bind(this);
|
|
726
|
-
return function(target, key, descriptor) {
|
|
727
|
-
const originalMethod = descriptor.value;
|
|
728
|
-
name = name || key;
|
|
729
|
-
descriptor.value = function(...args) {
|
|
730
|
-
const exist = get(name);
|
|
731
|
-
if (exist) {
|
|
732
|
-
return exist;
|
|
733
|
-
}
|
|
734
|
-
const result = add(originalMethod.apply(this, args), name);
|
|
735
|
-
return result;
|
|
736
|
-
};
|
|
737
|
-
return descriptor;
|
|
738
|
-
};
|
|
739
|
-
}
|
|
740
|
-
/** @deprecated use {@link PromiseControl.WaitForMe } instead */
|
|
741
|
-
GetOrCreateDecorator(name = "") {
|
|
742
|
-
return this.WaitForMe(name);
|
|
743
|
-
}
|
|
744
|
-
_onStop() {
|
|
745
|
-
if (this.options.onStop && !this.isLoaded) {
|
|
746
|
-
this.options.onStop();
|
|
747
|
-
}
|
|
748
|
-
}
|
|
749
|
-
}
|
|
750
|
-
|
|
751
|
-
var __defProp$7 = Object.defineProperty;
|
|
752
|
-
var __defNormalProp$7 = (obj, key, value) => key in obj ? __defProp$7(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
753
|
-
var __publicField$7 = (obj, key, value) => __defNormalProp$7(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
754
|
-
class TimeoutError extends Error {
|
|
755
|
-
constructor() {
|
|
756
|
-
super();
|
|
757
|
-
__publicField$7(this, "name", "TimeoutError");
|
|
758
|
-
Object.setPrototypeOf(this, TimeoutError.prototype);
|
|
759
|
-
}
|
|
760
|
-
}
|
|
761
|
-
|
|
762
645
|
var __defProp$6 = Object.defineProperty;
|
|
763
646
|
var __defNormalProp$6 = (obj, key, value) => key in obj ? __defProp$6(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
764
|
-
var __publicField$
|
|
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$
|
|
980
|
-
var __defNormalProp$
|
|
981
|
-
var __publicField$4 = (obj, key, value) => __defNormalProp$
|
|
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$
|
|
1021
|
-
var
|
|
1022
|
-
var
|
|
1023
|
-
var
|
|
1024
|
-
var
|
|
1025
|
-
var
|
|
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$
|
|
1030
|
-
__defNormalProp$
|
|
1031
|
-
if (__getOwnPropSymbols$
|
|
1032
|
-
for (var prop of __getOwnPropSymbols$
|
|
1033
|
-
if (__propIsEnum$
|
|
1034
|
-
__defNormalProp$
|
|
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
|
|
1039
|
-
var
|
|
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
|
|
1082
|
-
|
|
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
|
-
|
|
766
|
+
resource.id;
|
|
1091
767
|
} else {
|
|
1092
768
|
if (resource.keyname) {
|
|
1093
|
-
|
|
769
|
+
resource.keyname;
|
|
1094
770
|
}
|
|
1095
771
|
if (resource.display_name) {
|
|
1096
|
-
|
|
772
|
+
resource.display_name;
|
|
1097
773
|
}
|
|
1098
774
|
}
|
|
1099
775
|
}
|
|
1100
|
-
|
|
1101
|
-
|
|
1102
|
-
|
|
1103
|
-
|
|
1104
|
-
|
|
1105
|
-
|
|
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
|
|
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
|
|
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
|
|
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$
|
|
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",
|
|
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
|
|
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
|
-
|
|
1223
|
-
|
|
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
|
-
|
|
1231
|
-
|
|
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
|
|
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.
|
|
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
|
-
|
|
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
|
|
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
|
-
|
|
1337
|
-
|
|
1338
|
-
|
|
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,64 +1023,96 @@ 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
|
-
|
|
1363
|
-
|
|
1364
|
-
|
|
1365
|
-
|
|
1366
|
-
|
|
1367
|
-
|
|
1368
|
-
|
|
1369
|
-
|
|
1370
|
-
|
|
1371
|
-
|
|
1372
|
-
|
|
1373
|
-
|
|
1374
|
-
|
|
1375
|
-
|
|
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 (
|
|
1385
|
-
|
|
1386
|
-
|
|
1387
|
-
|
|
1388
|
-
|
|
1389
|
-
|
|
1390
|
-
|
|
1391
|
-
|
|
1392
|
-
|
|
1393
|
-
|
|
1394
|
-
|
|
1395
|
-
|
|
1396
|
-
|
|
1397
|
-
|
|
1398
|
-
|
|
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 (
|
|
1403
|
-
|
|
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
|
-
|
|
1105
|
+
throw new Error("Request URL is not set");
|
|
1409
1106
|
}
|
|
1410
|
-
}
|
|
1411
|
-
|
|
1412
|
-
}
|
|
1107
|
+
} else {
|
|
1108
|
+
return void 0;
|
|
1109
|
+
}
|
|
1413
1110
|
});
|
|
1414
1111
|
}
|
|
1415
1112
|
|
|
1416
1113
|
var __defProp$1 = Object.defineProperty;
|
|
1417
1114
|
var __defNormalProp$1 = (obj, key, value) => key in obj ? __defProp$1(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
1418
|
-
var __publicField$1 = (obj, key, value) => __defNormalProp$1(obj,
|
|
1115
|
+
var __publicField$1 = (obj, key, value) => __defNormalProp$1(obj, key + "" , value);
|
|
1419
1116
|
class NetworkError extends Error {
|
|
1420
1117
|
constructor(url) {
|
|
1421
1118
|
super();
|
|
@@ -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;
|
|
@@ -1535,7 +1268,7 @@ class NgwConnector {
|
|
|
1535
1268
|
__publicField(this, "resources");
|
|
1536
1269
|
__publicField(this, "cache");
|
|
1537
1270
|
__publicField(this, "routeStr", "/api/component/pyramid/route");
|
|
1538
|
-
__publicField(this, "activeRequests",
|
|
1271
|
+
__publicField(this, "activeRequests", {});
|
|
1539
1272
|
__publicField(this, "requestTransform");
|
|
1540
1273
|
const exist = findConnector(options);
|
|
1541
1274
|
this.cache = new Cache({ namespace: options.cacheId });
|
|
@@ -1592,29 +1325,27 @@ class NgwConnector {
|
|
|
1592
1325
|
* ```
|
|
1593
1326
|
*/
|
|
1594
1327
|
connect() {
|
|
1595
|
-
|
|
1596
|
-
|
|
1597
|
-
const makeQuery = () => {
|
|
1598
|
-
return this.makeQuery(this.routeStr, {}, {}).then((route) => {
|
|
1599
|
-
resolve(route);
|
|
1600
|
-
}).catch((er) => {
|
|
1601
|
-
reject(er);
|
|
1602
|
-
});
|
|
1603
|
-
};
|
|
1328
|
+
return __async(this, null, function* () {
|
|
1329
|
+
const auth = this.options.auth;
|
|
1604
1330
|
if (auth) {
|
|
1605
1331
|
const { login, password } = auth;
|
|
1606
1332
|
if (login && password) {
|
|
1607
|
-
|
|
1608
|
-
return makeQuery();
|
|
1609
|
-
}).catch((er) => reject(er));
|
|
1333
|
+
yield this._login({ login, password });
|
|
1610
1334
|
}
|
|
1611
1335
|
}
|
|
1612
|
-
return makeQuery(
|
|
1613
|
-
|
|
1614
|
-
|
|
1615
|
-
|
|
1616
|
-
|
|
1617
|
-
|
|
1336
|
+
return yield this.makeQuery(
|
|
1337
|
+
this.routeStr,
|
|
1338
|
+
{},
|
|
1339
|
+
{
|
|
1340
|
+
cacheName: "route",
|
|
1341
|
+
cache: true,
|
|
1342
|
+
cacheProps: {
|
|
1343
|
+
id: this.id,
|
|
1344
|
+
auth,
|
|
1345
|
+
baseUrl: this.options.baseUrl
|
|
1346
|
+
}
|
|
1347
|
+
}
|
|
1348
|
+
);
|
|
1618
1349
|
});
|
|
1619
1350
|
}
|
|
1620
1351
|
/**
|
|
@@ -1638,20 +1369,22 @@ class NgwConnector {
|
|
|
1638
1369
|
this.emitter.emit("logout");
|
|
1639
1370
|
}
|
|
1640
1371
|
getUserInfo(credentials, options) {
|
|
1641
|
-
|
|
1642
|
-
|
|
1643
|
-
|
|
1644
|
-
|
|
1645
|
-
|
|
1646
|
-
|
|
1647
|
-
|
|
1648
|
-
|
|
1649
|
-
|
|
1650
|
-
|
|
1651
|
-
|
|
1652
|
-
|
|
1653
|
-
|
|
1654
|
-
|
|
1372
|
+
return __async(this, null, function* () {
|
|
1373
|
+
if (this.user && this.user.id) {
|
|
1374
|
+
return this.user;
|
|
1375
|
+
}
|
|
1376
|
+
if (credentials) {
|
|
1377
|
+
this.options.auth = credentials;
|
|
1378
|
+
}
|
|
1379
|
+
const options_ = __spreadValues({
|
|
1380
|
+
headers: this.getAuthorizationHeaders(credentials)
|
|
1381
|
+
}, options);
|
|
1382
|
+
return this.makeQuery(
|
|
1383
|
+
"/api/component/auth/current_user",
|
|
1384
|
+
{},
|
|
1385
|
+
options_
|
|
1386
|
+
);
|
|
1387
|
+
});
|
|
1655
1388
|
}
|
|
1656
1389
|
/**
|
|
1657
1390
|
* Obtaining the required Headers for authentication of requests in the NGW.
|
|
@@ -1660,7 +1393,7 @@ class NgwConnector {
|
|
|
1660
1393
|
const client = this.makeClientId(credentials);
|
|
1661
1394
|
if (client) {
|
|
1662
1395
|
return {
|
|
1663
|
-
Authorization:
|
|
1396
|
+
Authorization: `Basic ${client}`
|
|
1664
1397
|
};
|
|
1665
1398
|
}
|
|
1666
1399
|
}
|
|
@@ -1668,21 +1401,22 @@ class NgwConnector {
|
|
|
1668
1401
|
credentials = credentials || this.options.auth;
|
|
1669
1402
|
if (credentials) {
|
|
1670
1403
|
const { login, password } = credentials;
|
|
1671
|
-
const str =
|
|
1404
|
+
const str = `${login}:${password}`;
|
|
1405
|
+
const encodedStr = encodeURIComponent(str);
|
|
1672
1406
|
{
|
|
1673
|
-
return window.btoa(
|
|
1407
|
+
return window.btoa(encodedStr);
|
|
1674
1408
|
}
|
|
1675
1409
|
}
|
|
1676
1410
|
}
|
|
1677
1411
|
/** Stop all api requests */
|
|
1678
1412
|
abort() {
|
|
1679
|
-
for (const
|
|
1680
|
-
|
|
1413
|
+
for (const abortController of Object.values(this.activeRequests)) {
|
|
1414
|
+
abortController.abort();
|
|
1681
1415
|
}
|
|
1682
|
-
this.activeRequests =
|
|
1416
|
+
this.activeRequests = {};
|
|
1683
1417
|
}
|
|
1684
1418
|
getActiveApiRequests() {
|
|
1685
|
-
return
|
|
1419
|
+
return __spreadValues({}, this.activeRequests);
|
|
1686
1420
|
}
|
|
1687
1421
|
/**
|
|
1688
1422
|
* Send request to NGW api router.
|
|
@@ -1714,23 +1448,10 @@ class NgwConnector {
|
|
|
1714
1448
|
* ```
|
|
1715
1449
|
*/
|
|
1716
1450
|
apiRequest(name, params_ = {}, requestOptions = {}) {
|
|
1717
|
-
var _a
|
|
1718
|
-
const { method, headers, withCredentials, responseType } = requestOptions;
|
|
1451
|
+
var _a;
|
|
1719
1452
|
params_ = (_a = requestOptions.params) != null ? _a : params_;
|
|
1720
1453
|
const params = objectRemoveEmpty(params_);
|
|
1721
|
-
|
|
1722
|
-
if (requestOptions.cache && method === "GET") {
|
|
1723
|
-
return this.cache.add(name, makeApiRequest, __spreadValues({
|
|
1724
|
-
params
|
|
1725
|
-
}, objectRemoveEmpty({
|
|
1726
|
-
headers,
|
|
1727
|
-
withCredentials,
|
|
1728
|
-
responseType,
|
|
1729
|
-
baseUrl: this.options.baseUrl,
|
|
1730
|
-
userId: (_b = this.user) == null ? void 0 : _b.id
|
|
1731
|
-
})));
|
|
1732
|
-
}
|
|
1733
|
-
return makeApiRequest();
|
|
1454
|
+
return apiRequest({ name, params, requestOptions, connector: this });
|
|
1734
1455
|
}
|
|
1735
1456
|
/**
|
|
1736
1457
|
* Shortcut method for send POST request to NGW.
|
|
@@ -1820,17 +1541,67 @@ class NgwConnector {
|
|
|
1820
1541
|
* @param params - Query params
|
|
1821
1542
|
* @param options - Request options
|
|
1822
1543
|
*/
|
|
1823
|
-
makeQuery(
|
|
1824
|
-
|
|
1825
|
-
|
|
1544
|
+
makeQuery(_0, _1) {
|
|
1545
|
+
return __async(this, arguments, function* (url, params, options = {}) {
|
|
1546
|
+
var _b;
|
|
1547
|
+
url = (this.options.baseUrl ? this.options.baseUrl : "") + url;
|
|
1548
|
+
if (!url) {
|
|
1549
|
+
throw new Error("Empty `url` not allowed");
|
|
1550
|
+
}
|
|
1826
1551
|
if (params) {
|
|
1827
|
-
|
|
1552
|
+
const _a = params, restParams = __objRest(_a, ["paramList"]);
|
|
1553
|
+
url = template(url, restParams);
|
|
1828
1554
|
}
|
|
1829
1555
|
url = encodeURI(fixUrlStr(url));
|
|
1830
|
-
|
|
1831
|
-
|
|
1832
|
-
|
|
1833
|
-
|
|
1556
|
+
const {
|
|
1557
|
+
cache,
|
|
1558
|
+
signal: externalSignal,
|
|
1559
|
+
method = "GET",
|
|
1560
|
+
headers,
|
|
1561
|
+
cacheName,
|
|
1562
|
+
cacheProps,
|
|
1563
|
+
responseType,
|
|
1564
|
+
withCredentials
|
|
1565
|
+
} = options;
|
|
1566
|
+
const internalAbortController = new AbortController();
|
|
1567
|
+
const internalSignal = internalAbortController.signal;
|
|
1568
|
+
if (externalSignal) {
|
|
1569
|
+
if (externalSignal.aborted) {
|
|
1570
|
+
throw new AbortError();
|
|
1571
|
+
}
|
|
1572
|
+
externalSignal.addEventListener("abort", () => {
|
|
1573
|
+
internalAbortController.abort();
|
|
1574
|
+
});
|
|
1575
|
+
}
|
|
1576
|
+
options.signal = internalSignal;
|
|
1577
|
+
const createPromise = () => __async(this, null, function* () {
|
|
1578
|
+
const id = REQUEST_ID++;
|
|
1579
|
+
this.activeRequests[id] = internalAbortController;
|
|
1580
|
+
try {
|
|
1581
|
+
return this._loadData(url, options);
|
|
1582
|
+
} finally {
|
|
1583
|
+
this._cleanActiveRequest(id);
|
|
1584
|
+
}
|
|
1585
|
+
});
|
|
1586
|
+
if (cache && method === "GET") {
|
|
1587
|
+
const cacheOptions = cacheProps ? cacheProps : __spreadProps(__spreadValues({}, objectRemoveEmpty({
|
|
1588
|
+
headers,
|
|
1589
|
+
withCredentials,
|
|
1590
|
+
responseType,
|
|
1591
|
+
baseUrl: this.options.baseUrl,
|
|
1592
|
+
userId: (_b = this.user) == null ? void 0 : _b.id
|
|
1593
|
+
})), {
|
|
1594
|
+
params
|
|
1595
|
+
});
|
|
1596
|
+
return this.cache.add(
|
|
1597
|
+
cacheName || url,
|
|
1598
|
+
createPromise,
|
|
1599
|
+
cacheOptions,
|
|
1600
|
+
false
|
|
1601
|
+
);
|
|
1602
|
+
}
|
|
1603
|
+
return createPromise();
|
|
1604
|
+
});
|
|
1834
1605
|
}
|
|
1835
1606
|
// -------------------------------------------------------------------------
|
|
1836
1607
|
// Resource Methods
|
|
@@ -1912,10 +1683,8 @@ class NgwConnector {
|
|
|
1912
1683
|
*/
|
|
1913
1684
|
_loadData(url, options) {
|
|
1914
1685
|
options.responseType = options.responseType || "json";
|
|
1915
|
-
|
|
1916
|
-
|
|
1917
|
-
}
|
|
1918
|
-
const request = new CancelablePromise((resolve, reject, onCancel) => {
|
|
1686
|
+
return new Promise((resolve, reject) => {
|
|
1687
|
+
var _a;
|
|
1919
1688
|
if (this.user) {
|
|
1920
1689
|
options = options || {};
|
|
1921
1690
|
options.headers = __spreadValues(__spreadValues({}, this.getAuthorizationHeaders()), options.headers);
|
|
@@ -1925,13 +1694,18 @@ class NgwConnector {
|
|
|
1925
1694
|
url = transUrl;
|
|
1926
1695
|
options = transOptions;
|
|
1927
1696
|
}
|
|
1928
|
-
|
|
1929
|
-
|
|
1930
|
-
|
|
1931
|
-
|
|
1697
|
+
let runOnAbort = void 0;
|
|
1698
|
+
loadData(url, resolve, options, reject, (handler) => {
|
|
1699
|
+
runOnAbort = handler;
|
|
1700
|
+
});
|
|
1701
|
+
(_a = options.signal) == null ? void 0 : _a.addEventListener("abort", () => {
|
|
1702
|
+
if (runOnAbort !== void 0) {
|
|
1703
|
+
runOnAbort();
|
|
1704
|
+
}
|
|
1705
|
+
reject(new AbortError());
|
|
1706
|
+
});
|
|
1932
1707
|
}).catch((httpError) => {
|
|
1933
|
-
|
|
1934
|
-
if (httpError instanceof CancelablePromise.CancelError) ; else {
|
|
1708
|
+
if (httpError.name !== "AbortError") {
|
|
1935
1709
|
{
|
|
1936
1710
|
console.warn("DEV WARN", httpError);
|
|
1937
1711
|
}
|
|
@@ -1940,31 +1714,24 @@ class NgwConnector {
|
|
|
1940
1714
|
throw er;
|
|
1941
1715
|
}
|
|
1942
1716
|
}
|
|
1717
|
+
throw httpError;
|
|
1943
1718
|
});
|
|
1944
|
-
if (options.signal && typeof options.signal.addEventListener === "function") {
|
|
1945
|
-
options.signal.addEventListener("abort", () => {
|
|
1946
|
-
request.cancel();
|
|
1947
|
-
this._cleanActiveRequests(request);
|
|
1948
|
-
});
|
|
1949
|
-
}
|
|
1950
|
-
this.activeRequests.push(request);
|
|
1951
|
-
return request;
|
|
1952
1719
|
}
|
|
1953
1720
|
_login(credentials, options) {
|
|
1954
|
-
return this
|
|
1955
|
-
|
|
1956
|
-
|
|
1957
|
-
|
|
1958
|
-
|
|
1959
|
-
|
|
1960
|
-
|
|
1721
|
+
return __async(this, null, function* () {
|
|
1722
|
+
try {
|
|
1723
|
+
const data = yield this.getUserInfo(credentials, options);
|
|
1724
|
+
this.user = data;
|
|
1725
|
+
this.emitter.emit("login", data);
|
|
1726
|
+
return data;
|
|
1727
|
+
} catch (er) {
|
|
1728
|
+
this.emitter.emit("login:error", er);
|
|
1729
|
+
throw er;
|
|
1730
|
+
}
|
|
1961
1731
|
});
|
|
1962
1732
|
}
|
|
1963
|
-
|
|
1964
|
-
|
|
1965
|
-
if (activeRequestIndex !== -1) {
|
|
1966
|
-
this.activeRequests.splice(activeRequestIndex, 1);
|
|
1967
|
-
}
|
|
1733
|
+
_cleanActiveRequest(requestId) {
|
|
1734
|
+
delete this.activeRequests[requestId];
|
|
1968
1735
|
}
|
|
1969
1736
|
_handleHttpError(er) {
|
|
1970
1737
|
if (er) {
|