@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.
- package/lib/index.d.ts +36 -35
- package/lib/ngw-connector.cjs.js +194 -194
- 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 -555
- 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 -224
- 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 -555
- 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.1; 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$
|
|
535
|
-
var __defNormalProp$
|
|
536
|
-
var __publicField$
|
|
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$
|
|
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
|
|
587
|
+
const nonEmptyProps = props && JSON.parse(JSON.stringify(objectRemoveEmpty(props)));
|
|
589
588
|
const cacheItem = {
|
|
590
589
|
key,
|
|
591
590
|
value,
|
|
592
|
-
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
|
-
|
|
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
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
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
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
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$
|
|
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, 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, 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, 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$
|
|
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$
|
|
983
|
-
var __defNormalProp$
|
|
984
|
-
var __publicField$4 = (obj, key, value) => __defNormalProp$
|
|
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$
|
|
1024
|
-
var
|
|
1025
|
-
var
|
|
1026
|
-
var
|
|
1027
|
-
var
|
|
1028
|
-
var
|
|
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$
|
|
1033
|
-
__defNormalProp$
|
|
1034
|
-
if (__getOwnPropSymbols$
|
|
1035
|
-
for (var prop of __getOwnPropSymbols$
|
|
1036
|
-
if (__propIsEnum$
|
|
1037
|
-
__defNormalProp$
|
|
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
|
|
1042
|
-
var
|
|
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
|
|
1085
|
-
|
|
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
|
-
|
|
769
|
+
resource.id;
|
|
1094
770
|
} else {
|
|
1095
771
|
if (resource.keyname) {
|
|
1096
|
-
|
|
772
|
+
resource.keyname;
|
|
1097
773
|
}
|
|
1098
774
|
if (resource.display_name) {
|
|
1099
|
-
|
|
775
|
+
resource.display_name;
|
|
1100
776
|
}
|
|
1101
777
|
}
|
|
1102
778
|
}
|
|
1103
|
-
|
|
1104
|
-
|
|
1105
|
-
|
|
1106
|
-
|
|
1107
|
-
|
|
1108
|
-
|
|
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
|
|
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
|
|
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
|
|
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$
|
|
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",
|
|
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
|
|
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
|
-
|
|
1226
|
-
|
|
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
|
-
|
|
1234
|
-
|
|
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
|
|
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.
|
|
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
|
-
|
|
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
|
|
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
|
-
|
|
1340
|
-
|
|
1341
|
-
|
|
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,58 +1026,90 @@ 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
|
-
|
|
1366
|
-
|
|
1367
|
-
|
|
1368
|
-
|
|
1369
|
-
|
|
1370
|
-
|
|
1371
|
-
|
|
1372
|
-
|
|
1373
|
-
|
|
1374
|
-
|
|
1375
|
-
|
|
1376
|
-
|
|
1377
|
-
|
|
1378
|
-
|
|
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 (
|
|
1388
|
-
|
|
1389
|
-
|
|
1390
|
-
|
|
1391
|
-
|
|
1392
|
-
|
|
1393
|
-
|
|
1394
|
-
|
|
1395
|
-
|
|
1396
|
-
|
|
1397
|
-
|
|
1398
|
-
|
|
1399
|
-
|
|
1400
|
-
|
|
1401
|
-
|
|
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 (
|
|
1406
|
-
|
|
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
|
-
|
|
1108
|
+
throw new Error("Request URL is not set");
|
|
1412
1109
|
}
|
|
1413
|
-
}
|
|
1414
|
-
|
|
1415
|
-
}
|
|
1110
|
+
} else {
|
|
1111
|
+
return void 0;
|
|
1112
|
+
}
|
|
1416
1113
|
});
|
|
1417
1114
|
}
|
|
1418
1115
|
|
|
@@ -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;
|
|
@@ -1539,7 +1272,7 @@ var NgwConnector = (function () {
|
|
|
1539
1272
|
__publicField(this, "cache");
|
|
1540
1273
|
__publicField(this, "withCredentials");
|
|
1541
1274
|
__publicField(this, "routeStr", "/api/component/pyramid/route");
|
|
1542
|
-
__publicField(this, "activeRequests",
|
|
1275
|
+
__publicField(this, "activeRequests", {});
|
|
1543
1276
|
__publicField(this, "requestTransform");
|
|
1544
1277
|
const exist = findConnector(options);
|
|
1545
1278
|
this.cache = new Cache({ namespace: options.cacheId });
|
|
@@ -1600,29 +1333,27 @@ var NgwConnector = (function () {
|
|
|
1600
1333
|
* ```
|
|
1601
1334
|
*/
|
|
1602
1335
|
connect() {
|
|
1603
|
-
|
|
1604
|
-
|
|
1605
|
-
const makeQuery = () => {
|
|
1606
|
-
return this.makeQuery(this.routeStr, {}, {}).then((route) => {
|
|
1607
|
-
resolve(route);
|
|
1608
|
-
}).catch((er) => {
|
|
1609
|
-
reject(er);
|
|
1610
|
-
});
|
|
1611
|
-
};
|
|
1336
|
+
return __async(this, null, function* () {
|
|
1337
|
+
const auth = this.options.auth;
|
|
1612
1338
|
if (auth) {
|
|
1613
1339
|
const { login, password } = auth;
|
|
1614
1340
|
if (login && password) {
|
|
1615
|
-
|
|
1616
|
-
return makeQuery();
|
|
1617
|
-
}).catch((er) => reject(er));
|
|
1341
|
+
yield this._login({ login, password });
|
|
1618
1342
|
}
|
|
1619
1343
|
}
|
|
1620
|
-
return makeQuery(
|
|
1621
|
-
|
|
1622
|
-
|
|
1623
|
-
|
|
1624
|
-
|
|
1625
|
-
|
|
1344
|
+
return yield this.makeQuery(
|
|
1345
|
+
this.routeStr,
|
|
1346
|
+
{},
|
|
1347
|
+
{
|
|
1348
|
+
cacheName: "route",
|
|
1349
|
+
cache: true,
|
|
1350
|
+
cacheProps: {
|
|
1351
|
+
id: this.id,
|
|
1352
|
+
auth,
|
|
1353
|
+
baseUrl: this.options.baseUrl
|
|
1354
|
+
}
|
|
1355
|
+
}
|
|
1356
|
+
);
|
|
1626
1357
|
});
|
|
1627
1358
|
}
|
|
1628
1359
|
/**
|
|
@@ -1646,20 +1377,22 @@ var NgwConnector = (function () {
|
|
|
1646
1377
|
this.emitter.emit("logout");
|
|
1647
1378
|
}
|
|
1648
1379
|
getUserInfo(credentials, options) {
|
|
1649
|
-
|
|
1650
|
-
|
|
1651
|
-
|
|
1652
|
-
|
|
1653
|
-
|
|
1654
|
-
|
|
1655
|
-
|
|
1656
|
-
|
|
1657
|
-
|
|
1658
|
-
|
|
1659
|
-
|
|
1660
|
-
|
|
1661
|
-
|
|
1662
|
-
|
|
1380
|
+
return __async(this, null, function* () {
|
|
1381
|
+
if (this.user && this.user.id) {
|
|
1382
|
+
return this.user;
|
|
1383
|
+
}
|
|
1384
|
+
if (credentials) {
|
|
1385
|
+
this.options.auth = credentials;
|
|
1386
|
+
}
|
|
1387
|
+
const options_ = __spreadValues({
|
|
1388
|
+
headers: this.getAuthorizationHeaders(credentials)
|
|
1389
|
+
}, options);
|
|
1390
|
+
return this.makeQuery(
|
|
1391
|
+
"/api/component/auth/current_user",
|
|
1392
|
+
{},
|
|
1393
|
+
options_
|
|
1394
|
+
);
|
|
1395
|
+
});
|
|
1663
1396
|
}
|
|
1664
1397
|
/**
|
|
1665
1398
|
* Obtaining the required Headers for authentication of requests in the NGW.
|
|
@@ -1668,7 +1401,7 @@ var NgwConnector = (function () {
|
|
|
1668
1401
|
const client = this.makeClientId(credentials);
|
|
1669
1402
|
if (client) {
|
|
1670
1403
|
return {
|
|
1671
|
-
Authorization:
|
|
1404
|
+
Authorization: `Basic ${client}`
|
|
1672
1405
|
};
|
|
1673
1406
|
}
|
|
1674
1407
|
}
|
|
@@ -1676,21 +1409,22 @@ var NgwConnector = (function () {
|
|
|
1676
1409
|
credentials = credentials || this.options.auth;
|
|
1677
1410
|
if (credentials) {
|
|
1678
1411
|
const { login, password } = credentials;
|
|
1679
|
-
const str =
|
|
1412
|
+
const str = `${login}:${password}`;
|
|
1413
|
+
const encodedStr = encodeURIComponent(str);
|
|
1680
1414
|
{
|
|
1681
|
-
return window.btoa(
|
|
1415
|
+
return window.btoa(encodedStr);
|
|
1682
1416
|
}
|
|
1683
1417
|
}
|
|
1684
1418
|
}
|
|
1685
1419
|
/** Stop all api requests */
|
|
1686
1420
|
abort() {
|
|
1687
|
-
for (const
|
|
1688
|
-
|
|
1421
|
+
for (const abortController of Object.values(this.activeRequests)) {
|
|
1422
|
+
abortController.abort();
|
|
1689
1423
|
}
|
|
1690
|
-
this.activeRequests =
|
|
1424
|
+
this.activeRequests = {};
|
|
1691
1425
|
}
|
|
1692
1426
|
getActiveApiRequests() {
|
|
1693
|
-
return
|
|
1427
|
+
return __spreadValues({}, this.activeRequests);
|
|
1694
1428
|
}
|
|
1695
1429
|
/**
|
|
1696
1430
|
* Send request to NGW api router.
|
|
@@ -1722,26 +1456,10 @@ var NgwConnector = (function () {
|
|
|
1722
1456
|
* ```
|
|
1723
1457
|
*/
|
|
1724
1458
|
apiRequest(name, params_ = {}, requestOptions = {}) {
|
|
1725
|
-
var _a
|
|
1726
|
-
requestOptions = __spreadValues({
|
|
1727
|
-
withCredentials: this.withCredentials
|
|
1728
|
-
}, requestOptions);
|
|
1729
|
-
const { method, headers, withCredentials, responseType } = requestOptions;
|
|
1459
|
+
var _a;
|
|
1730
1460
|
params_ = (_a = requestOptions.params) != null ? _a : params_;
|
|
1731
1461
|
const params = objectRemoveEmpty(params_);
|
|
1732
|
-
|
|
1733
|
-
if (requestOptions.cache && method === "GET") {
|
|
1734
|
-
return this.cache.add(name, makeApiRequest, __spreadValues({
|
|
1735
|
-
params
|
|
1736
|
-
}, objectRemoveEmpty({
|
|
1737
|
-
headers,
|
|
1738
|
-
withCredentials,
|
|
1739
|
-
responseType,
|
|
1740
|
-
baseUrl: this.options.baseUrl,
|
|
1741
|
-
userId: (_b = this.user) == null ? void 0 : _b.id
|
|
1742
|
-
})));
|
|
1743
|
-
}
|
|
1744
|
-
return makeApiRequest();
|
|
1462
|
+
return apiRequest({ name, params, requestOptions, connector: this });
|
|
1745
1463
|
}
|
|
1746
1464
|
/**
|
|
1747
1465
|
* Shortcut method for send POST request to NGW.
|
|
@@ -1831,17 +1549,68 @@ var NgwConnector = (function () {
|
|
|
1831
1549
|
* @param params - Query params
|
|
1832
1550
|
* @param options - Request options
|
|
1833
1551
|
*/
|
|
1834
|
-
makeQuery(
|
|
1835
|
-
|
|
1836
|
-
|
|
1552
|
+
makeQuery(_0, _1) {
|
|
1553
|
+
return __async(this, arguments, function* (url, params, options = {}) {
|
|
1554
|
+
var _b;
|
|
1555
|
+
url = (this.options.baseUrl ? this.options.baseUrl : "") + url;
|
|
1556
|
+
if (!url) {
|
|
1557
|
+
throw new Error("Empty `url` not allowed");
|
|
1558
|
+
}
|
|
1837
1559
|
if (params) {
|
|
1838
|
-
|
|
1560
|
+
const _a = params, restParams = __objRest(_a, ["paramList"]);
|
|
1561
|
+
url = template(url, restParams);
|
|
1839
1562
|
}
|
|
1840
1563
|
url = encodeURI(fixUrlStr(url));
|
|
1841
|
-
|
|
1842
|
-
|
|
1843
|
-
|
|
1844
|
-
|
|
1564
|
+
options = __spreadValues({ withCredentials: this.withCredentials }, options);
|
|
1565
|
+
const {
|
|
1566
|
+
cache,
|
|
1567
|
+
signal: externalSignal,
|
|
1568
|
+
method = "GET",
|
|
1569
|
+
headers,
|
|
1570
|
+
cacheName,
|
|
1571
|
+
cacheProps,
|
|
1572
|
+
responseType,
|
|
1573
|
+
withCredentials
|
|
1574
|
+
} = options;
|
|
1575
|
+
const internalAbortController = new AbortController();
|
|
1576
|
+
const internalSignal = internalAbortController.signal;
|
|
1577
|
+
if (externalSignal) {
|
|
1578
|
+
if (externalSignal.aborted) {
|
|
1579
|
+
throw new AbortError();
|
|
1580
|
+
}
|
|
1581
|
+
externalSignal.addEventListener("abort", () => {
|
|
1582
|
+
internalAbortController.abort();
|
|
1583
|
+
});
|
|
1584
|
+
}
|
|
1585
|
+
options.signal = internalSignal;
|
|
1586
|
+
const createPromise = () => __async(this, null, function* () {
|
|
1587
|
+
const id = REQUEST_ID++;
|
|
1588
|
+
this.activeRequests[id] = internalAbortController;
|
|
1589
|
+
try {
|
|
1590
|
+
return this._loadData(url, options);
|
|
1591
|
+
} finally {
|
|
1592
|
+
this._cleanActiveRequest(id);
|
|
1593
|
+
}
|
|
1594
|
+
});
|
|
1595
|
+
if (cache && method === "GET") {
|
|
1596
|
+
const cacheOptions = cacheProps ? cacheProps : __spreadProps(__spreadValues({}, objectRemoveEmpty({
|
|
1597
|
+
headers,
|
|
1598
|
+
withCredentials,
|
|
1599
|
+
responseType,
|
|
1600
|
+
baseUrl: this.options.baseUrl,
|
|
1601
|
+
userId: (_b = this.user) == null ? void 0 : _b.id
|
|
1602
|
+
})), {
|
|
1603
|
+
params
|
|
1604
|
+
});
|
|
1605
|
+
return this.cache.add(
|
|
1606
|
+
cacheName || url,
|
|
1607
|
+
createPromise,
|
|
1608
|
+
cacheOptions,
|
|
1609
|
+
false
|
|
1610
|
+
);
|
|
1611
|
+
}
|
|
1612
|
+
return createPromise();
|
|
1613
|
+
});
|
|
1845
1614
|
}
|
|
1846
1615
|
// -------------------------------------------------------------------------
|
|
1847
1616
|
// Resource Methods
|
|
@@ -1923,10 +1692,8 @@ var NgwConnector = (function () {
|
|
|
1923
1692
|
*/
|
|
1924
1693
|
_loadData(url, options) {
|
|
1925
1694
|
options.responseType = options.responseType || "json";
|
|
1926
|
-
|
|
1927
|
-
|
|
1928
|
-
}
|
|
1929
|
-
const request = new CancelablePromise((resolve, reject, onCancel) => {
|
|
1695
|
+
return new Promise((resolve, reject) => {
|
|
1696
|
+
var _a;
|
|
1930
1697
|
if (this.user) {
|
|
1931
1698
|
options = options || {};
|
|
1932
1699
|
options.headers = __spreadValues(__spreadValues({}, this.getAuthorizationHeaders()), options.headers);
|
|
@@ -1936,13 +1703,18 @@ var NgwConnector = (function () {
|
|
|
1936
1703
|
url = transUrl;
|
|
1937
1704
|
options = transOptions;
|
|
1938
1705
|
}
|
|
1939
|
-
|
|
1940
|
-
|
|
1941
|
-
|
|
1942
|
-
|
|
1706
|
+
let runOnAbort = void 0;
|
|
1707
|
+
loadData(url, resolve, options, reject, (handler) => {
|
|
1708
|
+
runOnAbort = handler;
|
|
1709
|
+
});
|
|
1710
|
+
(_a = options.signal) == null ? void 0 : _a.addEventListener("abort", () => {
|
|
1711
|
+
if (runOnAbort !== void 0) {
|
|
1712
|
+
runOnAbort();
|
|
1713
|
+
}
|
|
1714
|
+
reject(new AbortError());
|
|
1715
|
+
});
|
|
1943
1716
|
}).catch((httpError) => {
|
|
1944
|
-
|
|
1945
|
-
if (httpError instanceof CancelablePromise.CancelError) ; else {
|
|
1717
|
+
if (httpError.name !== "AbortError") {
|
|
1946
1718
|
{
|
|
1947
1719
|
console.warn("DEV WARN", httpError);
|
|
1948
1720
|
}
|
|
@@ -1951,31 +1723,24 @@ var NgwConnector = (function () {
|
|
|
1951
1723
|
throw er;
|
|
1952
1724
|
}
|
|
1953
1725
|
}
|
|
1726
|
+
throw httpError;
|
|
1954
1727
|
});
|
|
1955
|
-
if (options.signal && typeof options.signal.addEventListener === "function") {
|
|
1956
|
-
options.signal.addEventListener("abort", () => {
|
|
1957
|
-
request.cancel();
|
|
1958
|
-
this._cleanActiveRequests(request);
|
|
1959
|
-
});
|
|
1960
|
-
}
|
|
1961
|
-
this.activeRequests.push(request);
|
|
1962
|
-
return request;
|
|
1963
1728
|
}
|
|
1964
1729
|
_login(credentials, options) {
|
|
1965
|
-
return this
|
|
1966
|
-
|
|
1967
|
-
|
|
1968
|
-
|
|
1969
|
-
|
|
1970
|
-
|
|
1971
|
-
|
|
1730
|
+
return __async(this, null, function* () {
|
|
1731
|
+
try {
|
|
1732
|
+
const data = yield this.getUserInfo(credentials, options);
|
|
1733
|
+
this.user = data;
|
|
1734
|
+
this.emitter.emit("login", data);
|
|
1735
|
+
return data;
|
|
1736
|
+
} catch (er) {
|
|
1737
|
+
this.emitter.emit("login:error", er);
|
|
1738
|
+
throw er;
|
|
1739
|
+
}
|
|
1972
1740
|
});
|
|
1973
1741
|
}
|
|
1974
|
-
|
|
1975
|
-
|
|
1976
|
-
if (activeRequestIndex !== -1) {
|
|
1977
|
-
this.activeRequests.splice(activeRequestIndex, 1);
|
|
1978
|
-
}
|
|
1742
|
+
_cleanActiveRequest(requestId) {
|
|
1743
|
+
delete this.activeRequests[requestId];
|
|
1979
1744
|
}
|
|
1980
1745
|
_handleHttpError(er) {
|
|
1981
1746
|
if (er) {
|