@nextgis/ngw-connector 1.18.21 → 1.19.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 +11 -0
- package/lib/ngw-connector.cjs.js +254 -254
- 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 +753 -753
- 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 +240 -240
- 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 +796 -796
- 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.
|
|
1
|
+
/** Bundle of @nextgis/ngw-connector; version: 1.19.0; author: NextGIS */
|
|
2
2
|
var NgwConnector = (function () {
|
|
3
3
|
'use strict';
|
|
4
4
|
|
|
@@ -573,663 +573,648 @@ var NgwConnector = (function () {
|
|
|
573
573
|
}
|
|
574
574
|
}
|
|
575
575
|
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
576
|
+
/**
|
|
577
|
+
* from https://github.com/CesiumGS/cesium/blob/master/Source/Core/defined.js
|
|
578
|
+
*
|
|
579
|
+
* @param val - The object.
|
|
580
|
+
* @returns Returns true if the object is defined, returns false otherwise.
|
|
581
|
+
*
|
|
582
|
+
* @example
|
|
583
|
+
* ```javascript
|
|
584
|
+
* if (defined(positions)) {
|
|
585
|
+
* doSomething();
|
|
586
|
+
* } else {
|
|
587
|
+
* doSomethingElse();
|
|
588
|
+
* }
|
|
589
|
+
* ```
|
|
590
|
+
*/
|
|
591
|
+
function defined(val) {
|
|
592
|
+
return val !== undefined && val !== null;
|
|
593
|
+
}
|
|
594
|
+
/**
|
|
595
|
+
* from https://github.com/CesiumGS/cesium/blob/master/Source/Core/defined.js
|
|
596
|
+
*
|
|
597
|
+
* @param val - The object.
|
|
598
|
+
* @returns Returns true if the object is defined and not empty string, returns false otherwise.
|
|
599
|
+
*
|
|
600
|
+
* @example
|
|
601
|
+
* ```javascript
|
|
602
|
+
* full('foo') // true
|
|
603
|
+
* full('') // false
|
|
604
|
+
* full(undefined) // false
|
|
605
|
+
* full(0) // true
|
|
606
|
+
* ```
|
|
607
|
+
*/
|
|
608
|
+
function full(val) {
|
|
609
|
+
return typeof val === 'string' ? !!val : defined(val);
|
|
610
|
+
}
|
|
586
611
|
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
if (
|
|
590
|
-
|
|
591
|
-
|
|
612
|
+
function isEqual(a, b, o, p) {
|
|
613
|
+
if (a instanceof Array) {
|
|
614
|
+
if (!(b instanceof Array))
|
|
615
|
+
return false;
|
|
616
|
+
//if (compareObjects(oVal, pVal === false) return false
|
|
617
|
+
//would work, too, and perhaps is a better fit, still, this is easy, too
|
|
618
|
+
return b.sort().join('') === a.sort().join('');
|
|
592
619
|
}
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
return
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
};
|
|
609
|
-
PromiseControl.prototype.add = function (promise, name) {
|
|
610
|
-
var _this = this;
|
|
611
|
-
var key = name ? name : promise;
|
|
612
|
-
var exist = this._promises.get(key);
|
|
613
|
-
if (this.options.onStart && !this.isLoaded) {
|
|
614
|
-
this.options.onStart();
|
|
620
|
+
else if (a instanceof Date) {
|
|
621
|
+
if (!(b instanceof Date))
|
|
622
|
+
return false;
|
|
623
|
+
return '' + a === '' + b;
|
|
624
|
+
}
|
|
625
|
+
else if (a instanceof Function) {
|
|
626
|
+
if (!(b instanceof Function))
|
|
627
|
+
return false;
|
|
628
|
+
//ignore functions, or check them regardless?
|
|
629
|
+
}
|
|
630
|
+
else if (a instanceof Object) {
|
|
631
|
+
if (!(b instanceof Object))
|
|
632
|
+
return false;
|
|
633
|
+
if (a === o) {
|
|
634
|
+
return b === p;
|
|
615
635
|
}
|
|
616
|
-
|
|
617
|
-
return
|
|
636
|
+
else {
|
|
637
|
+
return objectDeepEqual(a, b);
|
|
618
638
|
}
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
639
|
+
}
|
|
640
|
+
return a === b;
|
|
641
|
+
}
|
|
642
|
+
// based on https://stackoverflow.com/a/13143059
|
|
643
|
+
function objectDeepEqual(o, p) {
|
|
644
|
+
var keysO = Object.keys(o).sort();
|
|
645
|
+
var keysP = Object.keys(p).sort();
|
|
646
|
+
if (keysO.length !== keysP.length)
|
|
647
|
+
return false;
|
|
648
|
+
if (keysO.join('') !== keysP.join(''))
|
|
649
|
+
return false;
|
|
650
|
+
for (var i = 0; i < keysO.length; i++) {
|
|
651
|
+
var oVal = o[keysO[i]];
|
|
652
|
+
var pVal = p[keysP[i]];
|
|
653
|
+
if (!isEqual(oVal, pVal, o, p)) {
|
|
654
|
+
return false;
|
|
634
655
|
}
|
|
635
|
-
}
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
656
|
+
}
|
|
657
|
+
return true;
|
|
658
|
+
}
|
|
659
|
+
|
|
660
|
+
function objectRemoveEmpty(obj) {
|
|
661
|
+
var newObj = {};
|
|
662
|
+
Object.keys(obj).forEach(function (key) {
|
|
663
|
+
if (!(obj[key] instanceof Array) && obj[key] === Object(obj[key])) {
|
|
664
|
+
newObj[key] = objectRemoveEmpty(obj[key]);
|
|
642
665
|
}
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
PromiseControl.prototype.WaitForMe = function (name) {
|
|
646
|
-
if (name === void 0) { name = ''; }
|
|
647
|
-
var get = this.get.bind(this);
|
|
648
|
-
var add = this.add.bind(this);
|
|
649
|
-
return function (target, key, descriptor) {
|
|
650
|
-
var originalMethod = descriptor.value;
|
|
651
|
-
name = name || key;
|
|
652
|
-
descriptor.value = function () {
|
|
653
|
-
var args = [];
|
|
654
|
-
for (var _i = 0; _i < arguments.length; _i++) {
|
|
655
|
-
args[_i] = arguments[_i];
|
|
656
|
-
}
|
|
657
|
-
var exist = get(name);
|
|
658
|
-
if (exist) {
|
|
659
|
-
return exist;
|
|
660
|
-
}
|
|
661
|
-
var result = add(originalMethod.apply(this, args), name);
|
|
662
|
-
return result;
|
|
663
|
-
};
|
|
664
|
-
return descriptor;
|
|
665
|
-
};
|
|
666
|
-
};
|
|
667
|
-
/** @deprecated use {@link PromiseControl.WaitForMe } instead */
|
|
668
|
-
PromiseControl.prototype.GetOrCreateDecorator = function (name) {
|
|
669
|
-
if (name === void 0) { name = ''; }
|
|
670
|
-
return this.WaitForMe(name);
|
|
671
|
-
};
|
|
672
|
-
PromiseControl.prototype._onStop = function () {
|
|
673
|
-
if (this.options.onStop && !this.isLoaded) {
|
|
674
|
-
this.options.onStop();
|
|
666
|
+
else if (obj[key] !== undefined) {
|
|
667
|
+
newObj[key] = obj[key];
|
|
675
668
|
}
|
|
676
|
-
};
|
|
677
|
-
return
|
|
678
|
-
}
|
|
669
|
+
});
|
|
670
|
+
return newObj;
|
|
671
|
+
}
|
|
679
672
|
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
_this.name = 'TimeoutError';
|
|
685
|
-
Object.setPrototypeOf(_this, TimeoutError.prototype);
|
|
686
|
-
return _this;
|
|
687
|
-
}
|
|
688
|
-
return TimeoutError;
|
|
689
|
-
}(Error));
|
|
673
|
+
function fixUrlStr(url) {
|
|
674
|
+
// remove double slash
|
|
675
|
+
return url.replace(/([^:]\/)\/+/g, '$1');
|
|
676
|
+
}
|
|
690
677
|
|
|
691
|
-
var handleCallback = function (resolve, reject, callback, r) {
|
|
692
|
-
try {
|
|
693
|
-
resolve(callback(r));
|
|
694
|
-
}
|
|
695
|
-
catch (e) {
|
|
696
|
-
reject(e);
|
|
697
|
-
}
|
|
698
|
-
};
|
|
699
|
-
var ID$1 = 0;
|
|
700
678
|
/**
|
|
701
|
-
* Promise that can be canceled
|
|
702
|
-
*
|
|
703
679
|
* @example
|
|
704
|
-
* Catch `CancelError`
|
|
705
680
|
* ```javascript
|
|
706
|
-
*
|
|
681
|
+
* const cache1 = new Cache();
|
|
682
|
+
* cache1.add('foo', 'value');
|
|
707
683
|
*
|
|
708
|
-
* const
|
|
709
|
-
*
|
|
710
|
-
* }).catch((er) => {
|
|
711
|
-
* if (er.name === "CancelError") {
|
|
712
|
-
* // handle cancel error
|
|
713
|
-
* }
|
|
714
|
-
* throw er;
|
|
715
|
-
* });
|
|
684
|
+
* const cache2 = new Cache();
|
|
685
|
+
* cache2.match('foo'); // value
|
|
716
686
|
*
|
|
717
|
-
*
|
|
687
|
+
* const cache3 = new Cache({ namespace: 'foo' });
|
|
688
|
+
* cache3.match('foo'); // undefined
|
|
718
689
|
* ```
|
|
690
|
+
*
|
|
719
691
|
* @example
|
|
720
|
-
* Handle `onCancel` callback
|
|
721
692
|
* ```javascript
|
|
722
|
-
*
|
|
723
|
-
*
|
|
724
|
-
*
|
|
725
|
-
*
|
|
726
|
-
* xhr.open("GET", url, true);
|
|
727
|
-
* xhr.onload = () => {
|
|
728
|
-
* resolve(xhr.responseText);
|
|
729
|
-
* };
|
|
730
|
-
* xhr.onerror = (er) => {
|
|
731
|
-
* reject(er);
|
|
732
|
-
* };
|
|
733
|
-
*
|
|
734
|
-
* onCancel(() => {
|
|
735
|
-
* xhr.abort();
|
|
736
|
-
* });
|
|
737
|
-
*
|
|
738
|
-
* xhr.send();
|
|
693
|
+
* let COUNTER = 0;
|
|
694
|
+
* const createPromise = () => new Promise((res) => {
|
|
695
|
+
* COUNTER++
|
|
696
|
+
* setTimeout(() => res('Ok'), 300)
|
|
739
697
|
* });
|
|
740
698
|
*
|
|
741
|
-
*
|
|
699
|
+
* const cache = new Cache();
|
|
700
|
+
* for (let i = 0; i < 10; i++) {
|
|
701
|
+
* cache.add('foo', createPromise).then((data) => {
|
|
702
|
+
* console.log(data); // 'Ok'
|
|
703
|
+
* });
|
|
704
|
+
* }
|
|
705
|
+
* console.log(COUNTER); // 1
|
|
742
706
|
* ```
|
|
743
707
|
*/
|
|
744
|
-
var
|
|
745
|
-
function
|
|
746
|
-
|
|
747
|
-
|
|
748
|
-
this.
|
|
749
|
-
|
|
750
|
-
|
|
751
|
-
|
|
752
|
-
this._cancelPromise = new Promise(function (resolve_, reject_) {
|
|
753
|
-
_this._setCanceledCallback = function (er) { return resolve_(er || new CancelError()); };
|
|
754
|
-
});
|
|
755
|
-
var promises = [
|
|
756
|
-
this._cancelPromise,
|
|
757
|
-
new Promise(function (resolve, reject) {
|
|
758
|
-
var onResolve = function (value) {
|
|
759
|
-
if (value instanceof CancelablePromise) {
|
|
760
|
-
_this.attach(value);
|
|
761
|
-
}
|
|
762
|
-
else {
|
|
763
|
-
_this._isPending = false;
|
|
764
|
-
}
|
|
765
|
-
// TODO: fix types, `undefined` not allowed since 19.12.2020
|
|
766
|
-
resolve(value);
|
|
767
|
-
};
|
|
768
|
-
var onReject = function (error) {
|
|
769
|
-
_this._isPending = false;
|
|
770
|
-
reject(error);
|
|
771
|
-
};
|
|
772
|
-
var onCancel = function (handler) {
|
|
773
|
-
if (!_this._isPending) {
|
|
774
|
-
throw new Error('The `onCancel` handler was attached after the promise settled.');
|
|
775
|
-
}
|
|
776
|
-
_this._cancelHandlers.push(handler);
|
|
777
|
-
};
|
|
778
|
-
return executor(onResolve, onReject, onCancel);
|
|
779
|
-
}),
|
|
780
|
-
];
|
|
781
|
-
if (timeout) {
|
|
782
|
-
promises.push(new Promise(function (resolve, reject) {
|
|
783
|
-
setTimeout(function () {
|
|
784
|
-
if (_this._isPending) {
|
|
785
|
-
try {
|
|
786
|
-
_this.cancel();
|
|
787
|
-
}
|
|
788
|
-
finally {
|
|
789
|
-
reject(new TimeoutError());
|
|
790
|
-
}
|
|
791
|
-
}
|
|
792
|
-
}, timeout);
|
|
793
|
-
}));
|
|
708
|
+
var Cache$1 = /** @class */ (function () {
|
|
709
|
+
function Cache(options) {
|
|
710
|
+
if (options === void 0) { options = {}; }
|
|
711
|
+
var _a;
|
|
712
|
+
this.cache = [];
|
|
713
|
+
var namespace = (_a = options.namespace) !== null && _a !== void 0 ? _a : 'default';
|
|
714
|
+
if (Cache.instance[namespace]) {
|
|
715
|
+
return Cache.instance[namespace];
|
|
794
716
|
}
|
|
795
|
-
|
|
717
|
+
Cache.instance[namespace] = this;
|
|
718
|
+
return this;
|
|
796
719
|
}
|
|
797
|
-
|
|
798
|
-
|
|
720
|
+
Cache.prototype.clean = function () {
|
|
721
|
+
this.cache.length = 0;
|
|
799
722
|
};
|
|
800
|
-
|
|
801
|
-
return
|
|
723
|
+
Cache.prototype.all = function () {
|
|
724
|
+
return this.cache;
|
|
802
725
|
};
|
|
803
|
-
|
|
804
|
-
|
|
726
|
+
/**
|
|
727
|
+
* Caching only a non-empty value.
|
|
728
|
+
*
|
|
729
|
+
* Useful for get or create strategy
|
|
730
|
+
* @example
|
|
731
|
+
* ```javascript
|
|
732
|
+
* const cache = new Cache();
|
|
733
|
+
* const getItemFunc = () => fetch(url).then((data) => {
|
|
734
|
+
* return data.json(); // undefined
|
|
735
|
+
* });
|
|
736
|
+
* const item = await cache.addFull('foo', getItemFunc);
|
|
737
|
+
* if (!item) {
|
|
738
|
+
* await createItem(); // 'New item'
|
|
739
|
+
* }
|
|
740
|
+
*
|
|
741
|
+
* // somewhere else in the code
|
|
742
|
+
* const item = await cache.addFull('foo', getItemFunc).then((resp) => {
|
|
743
|
+
* console.log(resp); // 'New item'
|
|
744
|
+
* })
|
|
745
|
+
*
|
|
746
|
+
* ```
|
|
747
|
+
*/
|
|
748
|
+
Cache.prototype.addFull = function (key, valueToSet, props) {
|
|
749
|
+
return this.add(key, valueToSet, props, true);
|
|
805
750
|
};
|
|
806
|
-
|
|
751
|
+
Cache.prototype.add = function (key, valueToSet, props, onlyFull) {
|
|
807
752
|
var _this = this;
|
|
808
|
-
|
|
809
|
-
|
|
810
|
-
|
|
811
|
-
if (
|
|
812
|
-
|
|
813
|
-
|
|
814
|
-
|
|
815
|
-
|
|
816
|
-
|
|
817
|
-
|
|
753
|
+
var exist = this._find(key, props);
|
|
754
|
+
if (!exist) {
|
|
755
|
+
var value = void 0;
|
|
756
|
+
if (valueToSet instanceof Function) {
|
|
757
|
+
value = valueToSet();
|
|
758
|
+
}
|
|
759
|
+
else {
|
|
760
|
+
value = valueToSet;
|
|
761
|
+
}
|
|
762
|
+
var props_ = props && JSON.parse(JSON.stringify(objectRemoveEmpty(props)));
|
|
763
|
+
var cacheItem = {
|
|
764
|
+
key: key,
|
|
765
|
+
value: value,
|
|
766
|
+
props: props_,
|
|
767
|
+
// TODO: remove backward compatibility use only props
|
|
768
|
+
options: props_,
|
|
769
|
+
};
|
|
770
|
+
if (onlyFull && !full(value)) {
|
|
771
|
+
return value;
|
|
772
|
+
}
|
|
773
|
+
this.cache.push(cacheItem);
|
|
774
|
+
if (value instanceof Promise) {
|
|
775
|
+
value.catch(function (er) {
|
|
776
|
+
_this.delete(key, props);
|
|
777
|
+
throw er;
|
|
778
|
+
});
|
|
779
|
+
if (onlyFull) {
|
|
780
|
+
value.then(function (x) {
|
|
781
|
+
if (!full(x)) {
|
|
782
|
+
_this.delete(key, props);
|
|
783
|
+
}
|
|
784
|
+
return x;
|
|
785
|
+
});
|
|
818
786
|
}
|
|
787
|
+
return value;
|
|
819
788
|
}
|
|
820
|
-
|
|
821
|
-
});
|
|
822
|
-
};
|
|
823
|
-
CancelablePromise.prototype.attach = function (p) {
|
|
824
|
-
if (this._isCanceled) {
|
|
825
|
-
p.cancel();
|
|
789
|
+
return value;
|
|
826
790
|
}
|
|
827
791
|
else {
|
|
828
|
-
|
|
792
|
+
return exist.value;
|
|
829
793
|
}
|
|
830
794
|
};
|
|
831
|
-
|
|
832
|
-
var
|
|
833
|
-
|
|
834
|
-
|
|
835
|
-
var reject_1 = function (r) {
|
|
836
|
-
if (onrejected) {
|
|
837
|
-
handleCallback(resolve, reject, onrejected, r);
|
|
838
|
-
}
|
|
839
|
-
else {
|
|
840
|
-
reject(r);
|
|
841
|
-
}
|
|
842
|
-
};
|
|
843
|
-
_this._promise.then(function (r) {
|
|
844
|
-
if (_this._isCanceled) {
|
|
845
|
-
reject_1(r);
|
|
846
|
-
}
|
|
847
|
-
else {
|
|
848
|
-
if (onfulfilled) {
|
|
849
|
-
handleCallback(resolve, reject, onfulfilled, r);
|
|
850
|
-
}
|
|
851
|
-
else {
|
|
852
|
-
resolve(r);
|
|
853
|
-
}
|
|
854
|
-
}
|
|
855
|
-
}, reject_1);
|
|
856
|
-
}
|
|
857
|
-
});
|
|
858
|
-
p._parentPromise = this;
|
|
859
|
-
this._children.push(p);
|
|
860
|
-
return p;
|
|
861
|
-
};
|
|
862
|
-
CancelablePromise.prototype.catch = function (onrejected) {
|
|
863
|
-
if (this._isCanceled && onrejected) {
|
|
864
|
-
onrejected(new CancelError());
|
|
795
|
+
Cache.prototype.match = function (key, props) {
|
|
796
|
+
var cacheRecord = this._find(key, props);
|
|
797
|
+
if (cacheRecord) {
|
|
798
|
+
return cacheRecord.value;
|
|
865
799
|
}
|
|
866
|
-
return this.then(undefined, onrejected);
|
|
867
800
|
};
|
|
868
|
-
|
|
869
|
-
|
|
870
|
-
|
|
871
|
-
|
|
872
|
-
|
|
873
|
-
|
|
801
|
+
Cache.prototype.matchAll = function (key, props) {
|
|
802
|
+
var _this = this;
|
|
803
|
+
if (key) {
|
|
804
|
+
return this.cache
|
|
805
|
+
.filter(function (x) { return _this._filter(x, key, props); })
|
|
806
|
+
.map(function (x) { return x.value; });
|
|
874
807
|
}
|
|
875
|
-
return
|
|
808
|
+
return this.cache.map(function (x) { return x.value; });
|
|
876
809
|
};
|
|
877
|
-
|
|
878
|
-
|
|
879
|
-
|
|
880
|
-
|
|
881
|
-
|
|
882
|
-
this._isCanceled = true;
|
|
883
|
-
var parent = this._getTopParent();
|
|
884
|
-
if (parent) {
|
|
885
|
-
parent.cancel();
|
|
810
|
+
Cache.prototype.delete = function (keyOrItem, props) {
|
|
811
|
+
var _this = this;
|
|
812
|
+
var exist = [];
|
|
813
|
+
if (typeof keyOrItem === 'string') {
|
|
814
|
+
exist = this.cache.filter(function (x) { return _this._filter(x, keyOrItem, props); });
|
|
886
815
|
}
|
|
887
|
-
|
|
888
|
-
|
|
816
|
+
else {
|
|
817
|
+
exist.push(keyOrItem);
|
|
889
818
|
}
|
|
890
|
-
|
|
891
|
-
|
|
892
|
-
|
|
893
|
-
|
|
894
|
-
var handler = _a[_i];
|
|
895
|
-
handler();
|
|
896
|
-
}
|
|
897
|
-
}
|
|
898
|
-
catch (error) {
|
|
899
|
-
// this._setCanceledCallback(error);
|
|
900
|
-
}
|
|
901
|
-
}
|
|
902
|
-
if (this._setCanceledCallback) {
|
|
903
|
-
this._setCanceledCallback();
|
|
904
|
-
}
|
|
819
|
+
for (var _i = 0, exist_1 = exist; _i < exist_1.length; _i++) {
|
|
820
|
+
var e = exist_1[_i];
|
|
821
|
+
var index = this.cache.indexOf(e);
|
|
822
|
+
this.cache.splice(index, 1);
|
|
905
823
|
}
|
|
906
|
-
this._destroy();
|
|
907
|
-
return this;
|
|
908
824
|
};
|
|
909
|
-
|
|
910
|
-
var
|
|
911
|
-
|
|
912
|
-
|
|
913
|
-
|
|
914
|
-
|
|
915
|
-
|
|
916
|
-
|
|
917
|
-
|
|
918
|
-
|
|
825
|
+
Cache.prototype._find = function (key, props) {
|
|
826
|
+
var _this = this;
|
|
827
|
+
return this.cache.find(function (x) { return _this._filter(x, key, props); });
|
|
828
|
+
};
|
|
829
|
+
Cache.prototype._filter = function (item, key, props) {
|
|
830
|
+
if (item.key === key) {
|
|
831
|
+
if (props) {
|
|
832
|
+
// TODO: remove backward compatibility
|
|
833
|
+
var itemProps = item.props || item.options;
|
|
834
|
+
return objectDeepEqual(itemProps || {}, objectRemoveEmpty(props));
|
|
919
835
|
}
|
|
836
|
+
return true;
|
|
920
837
|
}
|
|
921
|
-
return
|
|
922
|
-
};
|
|
923
|
-
CancelablePromise.prototype._destroy = function () {
|
|
924
|
-
this._setCanceledCallback = undefined;
|
|
925
|
-
this._cancelPromise = undefined;
|
|
926
|
-
this._promise = undefined;
|
|
838
|
+
return false;
|
|
927
839
|
};
|
|
928
|
-
|
|
929
|
-
|
|
930
|
-
CancelablePromise.PromiseControl = PromiseControl;
|
|
931
|
-
return CancelablePromise;
|
|
840
|
+
Cache.instance = {};
|
|
841
|
+
return Cache;
|
|
932
842
|
}());
|
|
933
|
-
Object.setPrototypeOf(CancelablePromise$1.prototype, Promise.prototype);
|
|
934
|
-
|
|
935
|
-
/**
|
|
936
|
-
* A promise you can stop
|
|
937
|
-
*
|
|
938
|
-
* @packageDocumentation
|
|
939
|
-
* @module cancelable-promise
|
|
940
|
-
*/
|
|
941
|
-
var CancelablePromise = CancelablePromise$1;
|
|
942
843
|
|
|
943
|
-
/**
|
|
944
|
-
*
|
|
945
|
-
*
|
|
946
|
-
* @param val - The object.
|
|
947
|
-
* @returns Returns true if the object is defined, returns false otherwise.
|
|
948
|
-
*
|
|
949
|
-
* @example
|
|
950
|
-
* ```javascript
|
|
951
|
-
* if (defined(positions)) {
|
|
952
|
-
* doSomething();
|
|
953
|
-
* } else {
|
|
954
|
-
* doSomethingElse();
|
|
955
|
-
* }
|
|
956
|
-
* ```
|
|
957
|
-
*/
|
|
958
|
-
function defined(val) {
|
|
959
|
-
return val !== undefined && val !== null;
|
|
960
|
-
}
|
|
961
|
-
/**
|
|
962
|
-
* from https://github.com/CesiumGS/cesium/blob/master/Source/Core/defined.js
|
|
963
|
-
*
|
|
964
|
-
* @param val - The object.
|
|
965
|
-
* @returns Returns true if the object is defined and not empty string, returns false otherwise.
|
|
844
|
+
/**
|
|
845
|
+
* Caching for asynchronous functions
|
|
966
846
|
*
|
|
967
|
-
* @
|
|
968
|
-
*
|
|
969
|
-
* full('foo') // true
|
|
970
|
-
* full('') // false
|
|
971
|
-
* full(undefined) // false
|
|
972
|
-
* full(0) // true
|
|
973
|
-
* ```
|
|
847
|
+
* @packageDocumentation
|
|
848
|
+
* @module cache
|
|
974
849
|
*/
|
|
975
|
-
|
|
976
|
-
return typeof val === 'string' ? !!val : defined(val);
|
|
977
|
-
}
|
|
850
|
+
var Cache = Cache$1;
|
|
978
851
|
|
|
979
|
-
|
|
980
|
-
|
|
981
|
-
|
|
982
|
-
|
|
983
|
-
|
|
984
|
-
|
|
985
|
-
return
|
|
986
|
-
}
|
|
987
|
-
else if (a instanceof Date) {
|
|
988
|
-
if (!(b instanceof Date))
|
|
989
|
-
return false;
|
|
990
|
-
return '' + a === '' + b;
|
|
852
|
+
var CancelError = /** @class */ (function (_super) {
|
|
853
|
+
__extends(CancelError, _super);
|
|
854
|
+
function CancelError() {
|
|
855
|
+
var _this = _super.call(this) || this;
|
|
856
|
+
_this.name = 'CancelError';
|
|
857
|
+
Object.setPrototypeOf(_this, CancelError.prototype);
|
|
858
|
+
return _this;
|
|
991
859
|
}
|
|
992
|
-
|
|
993
|
-
|
|
994
|
-
|
|
995
|
-
|
|
860
|
+
return CancelError;
|
|
861
|
+
}(Error));
|
|
862
|
+
|
|
863
|
+
var PromiseControl = /** @class */ (function () {
|
|
864
|
+
function PromiseControl(options) {
|
|
865
|
+
if (options === void 0) { options = {}; }
|
|
866
|
+
this.options = options;
|
|
867
|
+
this._promises = new Map();
|
|
996
868
|
}
|
|
997
|
-
|
|
998
|
-
|
|
999
|
-
return
|
|
1000
|
-
|
|
1001
|
-
|
|
869
|
+
Object.defineProperty(PromiseControl.prototype, "isLoaded", {
|
|
870
|
+
get: function () {
|
|
871
|
+
return this._promises.size > 0;
|
|
872
|
+
},
|
|
873
|
+
enumerable: false,
|
|
874
|
+
configurable: true
|
|
875
|
+
});
|
|
876
|
+
PromiseControl.prototype.remove = function (promise) {
|
|
877
|
+
if (this._promises.has(promise)) {
|
|
878
|
+
this._promises.delete(promise);
|
|
879
|
+
this._onStop();
|
|
1002
880
|
}
|
|
1003
|
-
|
|
1004
|
-
|
|
881
|
+
};
|
|
882
|
+
PromiseControl.prototype.get = function (promise) {
|
|
883
|
+
return this._promises.get(promise);
|
|
884
|
+
};
|
|
885
|
+
PromiseControl.prototype.add = function (promise, name) {
|
|
886
|
+
var _this = this;
|
|
887
|
+
var key = name ? name : promise;
|
|
888
|
+
var exist = this._promises.get(key);
|
|
889
|
+
if (this.options.onStart && !this.isLoaded) {
|
|
890
|
+
this.options.onStart();
|
|
1005
891
|
}
|
|
1006
|
-
|
|
1007
|
-
|
|
1008
|
-
}
|
|
1009
|
-
// based on https://stackoverflow.com/a/13143059
|
|
1010
|
-
function objectDeepEqual(o, p) {
|
|
1011
|
-
var keysO = Object.keys(o).sort();
|
|
1012
|
-
var keysP = Object.keys(p).sort();
|
|
1013
|
-
if (keysO.length !== keysP.length)
|
|
1014
|
-
return false;
|
|
1015
|
-
if (keysO.join('') !== keysP.join(''))
|
|
1016
|
-
return false;
|
|
1017
|
-
for (var i = 0; i < keysO.length; i++) {
|
|
1018
|
-
var oVal = o[keysO[i]];
|
|
1019
|
-
var pVal = p[keysP[i]];
|
|
1020
|
-
if (!isEqual(oVal, pVal, o, p)) {
|
|
1021
|
-
return false;
|
|
892
|
+
if (exist) {
|
|
893
|
+
return exist;
|
|
1022
894
|
}
|
|
1023
|
-
|
|
1024
|
-
|
|
1025
|
-
|
|
1026
|
-
|
|
1027
|
-
|
|
1028
|
-
|
|
1029
|
-
|
|
1030
|
-
if (
|
|
1031
|
-
|
|
895
|
+
this._promises.set(key, promise);
|
|
896
|
+
promise.finally(function () {
|
|
897
|
+
_this.remove(key);
|
|
898
|
+
});
|
|
899
|
+
return promise;
|
|
900
|
+
};
|
|
901
|
+
PromiseControl.prototype.abort = function () {
|
|
902
|
+
if (this.isLoaded) {
|
|
903
|
+
this._promises.forEach(function (x) {
|
|
904
|
+
if (x.cancel) {
|
|
905
|
+
x.cancel();
|
|
906
|
+
}
|
|
907
|
+
});
|
|
908
|
+
this._promises.clear();
|
|
909
|
+
this._onStop();
|
|
1032
910
|
}
|
|
1033
|
-
|
|
1034
|
-
|
|
911
|
+
};
|
|
912
|
+
PromiseControl.prototype.waitFunc = function (func, name) {
|
|
913
|
+
if (name === void 0) { name = ''; }
|
|
914
|
+
name = name || func.name;
|
|
915
|
+
var exist = this.get(name);
|
|
916
|
+
if (exist) {
|
|
917
|
+
return exist;
|
|
1035
918
|
}
|
|
1036
|
-
|
|
1037
|
-
|
|
1038
|
-
|
|
919
|
+
return this.add(func(), name);
|
|
920
|
+
};
|
|
921
|
+
PromiseControl.prototype.WaitForMe = function (name) {
|
|
922
|
+
if (name === void 0) { name = ''; }
|
|
923
|
+
var get = this.get.bind(this);
|
|
924
|
+
var add = this.add.bind(this);
|
|
925
|
+
return function (target, key, descriptor) {
|
|
926
|
+
var originalMethod = descriptor.value;
|
|
927
|
+
name = name || key;
|
|
928
|
+
descriptor.value = function () {
|
|
929
|
+
var args = [];
|
|
930
|
+
for (var _i = 0; _i < arguments.length; _i++) {
|
|
931
|
+
args[_i] = arguments[_i];
|
|
932
|
+
}
|
|
933
|
+
var exist = get(name);
|
|
934
|
+
if (exist) {
|
|
935
|
+
return exist;
|
|
936
|
+
}
|
|
937
|
+
var result = add(originalMethod.apply(this, args), name);
|
|
938
|
+
return result;
|
|
939
|
+
};
|
|
940
|
+
return descriptor;
|
|
941
|
+
};
|
|
942
|
+
};
|
|
943
|
+
/** @deprecated use {@link PromiseControl.WaitForMe } instead */
|
|
944
|
+
PromiseControl.prototype.GetOrCreateDecorator = function (name) {
|
|
945
|
+
if (name === void 0) { name = ''; }
|
|
946
|
+
return this.WaitForMe(name);
|
|
947
|
+
};
|
|
948
|
+
PromiseControl.prototype._onStop = function () {
|
|
949
|
+
if (this.options.onStop && !this.isLoaded) {
|
|
950
|
+
this.options.onStop();
|
|
951
|
+
}
|
|
952
|
+
};
|
|
953
|
+
return PromiseControl;
|
|
954
|
+
}());
|
|
1039
955
|
|
|
1040
|
-
function
|
|
1041
|
-
|
|
1042
|
-
|
|
1043
|
-
|
|
956
|
+
var TimeoutError = /** @class */ (function (_super) {
|
|
957
|
+
__extends(TimeoutError, _super);
|
|
958
|
+
function TimeoutError() {
|
|
959
|
+
var _this = _super.call(this) || this;
|
|
960
|
+
_this.name = 'TimeoutError';
|
|
961
|
+
Object.setPrototypeOf(_this, TimeoutError.prototype);
|
|
962
|
+
return _this;
|
|
963
|
+
}
|
|
964
|
+
return TimeoutError;
|
|
965
|
+
}(Error));
|
|
1044
966
|
|
|
967
|
+
var handleCallback = function (resolve, reject, callback, r) {
|
|
968
|
+
try {
|
|
969
|
+
resolve(callback(r));
|
|
970
|
+
}
|
|
971
|
+
catch (e) {
|
|
972
|
+
reject(e);
|
|
973
|
+
}
|
|
974
|
+
};
|
|
975
|
+
var ID$1 = 0;
|
|
1045
976
|
/**
|
|
977
|
+
* Promise that can be canceled
|
|
978
|
+
*
|
|
1046
979
|
* @example
|
|
980
|
+
* Catch `CancelError`
|
|
1047
981
|
* ```javascript
|
|
1048
|
-
*
|
|
1049
|
-
* cache1.add('foo', 'value');
|
|
982
|
+
* import CancelablePromise from "@nextgis/cancelable-promise";
|
|
1050
983
|
*
|
|
1051
|
-
* const
|
|
1052
|
-
*
|
|
984
|
+
* const promise = new CancelablePromise((resolve, reject) => {
|
|
985
|
+
* setTimeout(() => resolve(), 100);
|
|
986
|
+
* }).catch((er) => {
|
|
987
|
+
* if (er.name === "CancelError") {
|
|
988
|
+
* // handle cancel error
|
|
989
|
+
* }
|
|
990
|
+
* throw er;
|
|
991
|
+
* });
|
|
1053
992
|
*
|
|
1054
|
-
*
|
|
1055
|
-
* cache3.match('foo'); // undefined
|
|
993
|
+
* promise.cancel();
|
|
1056
994
|
* ```
|
|
1057
|
-
*
|
|
1058
995
|
* @example
|
|
996
|
+
* Handle `onCancel` callback
|
|
1059
997
|
* ```javascript
|
|
1060
|
-
*
|
|
1061
|
-
* const createPromise = () => new Promise((res) => {
|
|
1062
|
-
* COUNTER++
|
|
1063
|
-
* setTimeout(() => res('Ok'), 300)
|
|
1064
|
-
* });
|
|
998
|
+
* import CancelablePromise from "@nextgis/cancelable-promise";
|
|
1065
999
|
*
|
|
1066
|
-
* const
|
|
1067
|
-
*
|
|
1068
|
-
*
|
|
1069
|
-
*
|
|
1000
|
+
* const promise = new CancelablePromise((resolve, reject, onCancel) => {
|
|
1001
|
+
* const xhr = new XMLHttpRequest();
|
|
1002
|
+
* xhr.open("GET", url, true);
|
|
1003
|
+
* xhr.onload = () => {
|
|
1004
|
+
* resolve(xhr.responseText);
|
|
1005
|
+
* };
|
|
1006
|
+
* xhr.onerror = (er) => {
|
|
1007
|
+
* reject(er);
|
|
1008
|
+
* };
|
|
1009
|
+
*
|
|
1010
|
+
* onCancel(() => {
|
|
1011
|
+
* xhr.abort();
|
|
1070
1012
|
* });
|
|
1071
|
-
*
|
|
1072
|
-
*
|
|
1013
|
+
*
|
|
1014
|
+
* xhr.send();
|
|
1015
|
+
* });
|
|
1016
|
+
*
|
|
1017
|
+
* promise.cancel();
|
|
1073
1018
|
* ```
|
|
1074
1019
|
*/
|
|
1075
|
-
var
|
|
1076
|
-
function
|
|
1077
|
-
|
|
1078
|
-
|
|
1079
|
-
this.
|
|
1080
|
-
|
|
1081
|
-
|
|
1082
|
-
|
|
1020
|
+
var CancelablePromise$1 = /** @class */ (function () {
|
|
1021
|
+
function CancelablePromise(executor, timeout) {
|
|
1022
|
+
var _this = this;
|
|
1023
|
+
this.id = ID$1++;
|
|
1024
|
+
this._isCanceled = false;
|
|
1025
|
+
this._isPending = true;
|
|
1026
|
+
this._cancelHandlers = [];
|
|
1027
|
+
this._children = [];
|
|
1028
|
+
this._cancelPromise = new Promise(function (resolve_, reject_) {
|
|
1029
|
+
_this._setCanceledCallback = function (er) { return resolve_(er || new CancelError()); };
|
|
1030
|
+
});
|
|
1031
|
+
var promises = [
|
|
1032
|
+
this._cancelPromise,
|
|
1033
|
+
new Promise(function (resolve, reject) {
|
|
1034
|
+
var onResolve = function (value) {
|
|
1035
|
+
if (value instanceof CancelablePromise) {
|
|
1036
|
+
_this.attach(value);
|
|
1037
|
+
}
|
|
1038
|
+
else {
|
|
1039
|
+
_this._isPending = false;
|
|
1040
|
+
}
|
|
1041
|
+
// TODO: fix types, `undefined` not allowed since 19.12.2020
|
|
1042
|
+
resolve(value);
|
|
1043
|
+
};
|
|
1044
|
+
var onReject = function (error) {
|
|
1045
|
+
_this._isPending = false;
|
|
1046
|
+
reject(error);
|
|
1047
|
+
};
|
|
1048
|
+
var onCancel = function (handler) {
|
|
1049
|
+
if (!_this._isPending) {
|
|
1050
|
+
throw new Error('The `onCancel` handler was attached after the promise settled.');
|
|
1051
|
+
}
|
|
1052
|
+
_this._cancelHandlers.push(handler);
|
|
1053
|
+
};
|
|
1054
|
+
return executor(onResolve, onReject, onCancel);
|
|
1055
|
+
}),
|
|
1056
|
+
];
|
|
1057
|
+
if (timeout) {
|
|
1058
|
+
promises.push(new Promise(function (resolve, reject) {
|
|
1059
|
+
setTimeout(function () {
|
|
1060
|
+
if (_this._isPending) {
|
|
1061
|
+
try {
|
|
1062
|
+
_this.cancel();
|
|
1063
|
+
}
|
|
1064
|
+
finally {
|
|
1065
|
+
reject(new TimeoutError());
|
|
1066
|
+
}
|
|
1067
|
+
}
|
|
1068
|
+
}, timeout);
|
|
1069
|
+
}));
|
|
1083
1070
|
}
|
|
1084
|
-
|
|
1085
|
-
return this;
|
|
1071
|
+
this._promise = Promise.race(promises);
|
|
1086
1072
|
}
|
|
1087
|
-
|
|
1088
|
-
|
|
1073
|
+
CancelablePromise.createControl = function (opt) {
|
|
1074
|
+
return new PromiseControl(opt);
|
|
1089
1075
|
};
|
|
1090
|
-
|
|
1091
|
-
return
|
|
1076
|
+
CancelablePromise.resolve = function (value) {
|
|
1077
|
+
return new CancelablePromise(function (resolve) { return resolve(value); });
|
|
1092
1078
|
};
|
|
1093
|
-
|
|
1094
|
-
|
|
1095
|
-
*
|
|
1096
|
-
* Useful for get or create strategy
|
|
1097
|
-
* @example
|
|
1098
|
-
* ```javascript
|
|
1099
|
-
* const cache = new Cache();
|
|
1100
|
-
* const getItemFunc = () => fetch(url).then((data) => {
|
|
1101
|
-
* return data.json(); // undefined
|
|
1102
|
-
* });
|
|
1103
|
-
* const item = await cache.addFull('foo', getItemFunc);
|
|
1104
|
-
* if (!item) {
|
|
1105
|
-
* await createItem(); // 'New item'
|
|
1106
|
-
* }
|
|
1107
|
-
*
|
|
1108
|
-
* // somewhere else in the code
|
|
1109
|
-
* const item = await cache.addFull('foo', getItemFunc).then((resp) => {
|
|
1110
|
-
* console.log(resp); // 'New item'
|
|
1111
|
-
* })
|
|
1112
|
-
*
|
|
1113
|
-
* ```
|
|
1114
|
-
*/
|
|
1115
|
-
Cache.prototype.addFull = function (key, valueToSet, props) {
|
|
1116
|
-
return this.add(key, valueToSet, props, true);
|
|
1079
|
+
CancelablePromise.reject = function (value) {
|
|
1080
|
+
return new CancelablePromise(function (resolve, reject) { return reject(value); });
|
|
1117
1081
|
};
|
|
1118
|
-
|
|
1082
|
+
CancelablePromise.all = function (values) {
|
|
1119
1083
|
var _this = this;
|
|
1120
|
-
|
|
1121
|
-
|
|
1122
|
-
|
|
1123
|
-
if (
|
|
1124
|
-
|
|
1125
|
-
|
|
1126
|
-
|
|
1127
|
-
|
|
1128
|
-
|
|
1129
|
-
|
|
1130
|
-
var cacheItem = {
|
|
1131
|
-
key: key,
|
|
1132
|
-
value: value,
|
|
1133
|
-
props: props_,
|
|
1134
|
-
// TODO: remove backward compatibility use only props
|
|
1135
|
-
options: props_,
|
|
1136
|
-
};
|
|
1137
|
-
if (onlyFull && !full(value)) {
|
|
1138
|
-
return value;
|
|
1139
|
-
}
|
|
1140
|
-
this.cache.push(cacheItem);
|
|
1141
|
-
if (value instanceof Promise) {
|
|
1142
|
-
value.catch(function (er) {
|
|
1143
|
-
_this.delete(key, props);
|
|
1144
|
-
throw er;
|
|
1145
|
-
});
|
|
1146
|
-
if (onlyFull) {
|
|
1147
|
-
value.then(function (x) {
|
|
1148
|
-
if (!full(x)) {
|
|
1149
|
-
_this.delete(key, props);
|
|
1150
|
-
}
|
|
1151
|
-
return x;
|
|
1152
|
-
});
|
|
1084
|
+
return new CancelablePromise(function (resolve, reject) {
|
|
1085
|
+
Promise.all(values).then(resolve).catch(reject);
|
|
1086
|
+
}).catch(function (er) {
|
|
1087
|
+
if (er instanceof _this.CancelError) {
|
|
1088
|
+
for (var _i = 0, values_1 = values; _i < values_1.length; _i++) {
|
|
1089
|
+
var v = values_1[_i];
|
|
1090
|
+
var v_ = v;
|
|
1091
|
+
if ('cancel' in v_) {
|
|
1092
|
+
v_.cancel();
|
|
1093
|
+
}
|
|
1153
1094
|
}
|
|
1154
|
-
return value;
|
|
1155
1095
|
}
|
|
1156
|
-
|
|
1096
|
+
throw er;
|
|
1097
|
+
});
|
|
1098
|
+
};
|
|
1099
|
+
CancelablePromise.prototype.attach = function (p) {
|
|
1100
|
+
if (this._isCanceled) {
|
|
1101
|
+
p.cancel();
|
|
1157
1102
|
}
|
|
1158
1103
|
else {
|
|
1159
|
-
|
|
1104
|
+
this._children.push(p);
|
|
1160
1105
|
}
|
|
1161
1106
|
};
|
|
1162
|
-
|
|
1163
|
-
var
|
|
1164
|
-
|
|
1165
|
-
|
|
1107
|
+
CancelablePromise.prototype.then = function (onfulfilled, onrejected) {
|
|
1108
|
+
var _this = this;
|
|
1109
|
+
var p = new CancelablePromise(function (resolve, reject) {
|
|
1110
|
+
if (_this._promise) {
|
|
1111
|
+
var reject_1 = function (r) {
|
|
1112
|
+
if (onrejected) {
|
|
1113
|
+
handleCallback(resolve, reject, onrejected, r);
|
|
1114
|
+
}
|
|
1115
|
+
else {
|
|
1116
|
+
reject(r);
|
|
1117
|
+
}
|
|
1118
|
+
};
|
|
1119
|
+
_this._promise.then(function (r) {
|
|
1120
|
+
if (_this._isCanceled) {
|
|
1121
|
+
reject_1(r);
|
|
1122
|
+
}
|
|
1123
|
+
else {
|
|
1124
|
+
if (onfulfilled) {
|
|
1125
|
+
handleCallback(resolve, reject, onfulfilled, r);
|
|
1126
|
+
}
|
|
1127
|
+
else {
|
|
1128
|
+
resolve(r);
|
|
1129
|
+
}
|
|
1130
|
+
}
|
|
1131
|
+
}, reject_1);
|
|
1132
|
+
}
|
|
1133
|
+
});
|
|
1134
|
+
p._parentPromise = this;
|
|
1135
|
+
this._children.push(p);
|
|
1136
|
+
return p;
|
|
1137
|
+
};
|
|
1138
|
+
CancelablePromise.prototype.catch = function (onrejected) {
|
|
1139
|
+
if (this._isCanceled && onrejected) {
|
|
1140
|
+
onrejected(new CancelError());
|
|
1166
1141
|
}
|
|
1142
|
+
return this.then(undefined, onrejected);
|
|
1167
1143
|
};
|
|
1168
|
-
|
|
1169
|
-
|
|
1170
|
-
|
|
1171
|
-
return this.cache
|
|
1172
|
-
.filter(function (x) { return _this._filter(x, key, props); })
|
|
1173
|
-
.map(function (x) { return x.value; });
|
|
1144
|
+
CancelablePromise.prototype.finally = function (onfinally) {
|
|
1145
|
+
if (this._promise) {
|
|
1146
|
+
return this._promise.finally(onfinally);
|
|
1174
1147
|
}
|
|
1175
|
-
|
|
1148
|
+
if (this._isCanceled) {
|
|
1149
|
+
return Promise.reject(new CancelError());
|
|
1150
|
+
}
|
|
1151
|
+
return Promise.reject(onfinally);
|
|
1176
1152
|
};
|
|
1177
|
-
|
|
1178
|
-
|
|
1179
|
-
|
|
1180
|
-
|
|
1181
|
-
exist = this.cache.filter(function (x) { return _this._filter(x, keyOrItem, props); });
|
|
1153
|
+
CancelablePromise.prototype.cancel = function () {
|
|
1154
|
+
// No reason to run cancel action if promise is already complete
|
|
1155
|
+
if (this._isCanceled || !this._isPending) {
|
|
1156
|
+
return this;
|
|
1182
1157
|
}
|
|
1183
|
-
|
|
1184
|
-
|
|
1158
|
+
this._isCanceled = true;
|
|
1159
|
+
var parent = this._getTopParent();
|
|
1160
|
+
if (parent) {
|
|
1161
|
+
parent.cancel();
|
|
1185
1162
|
}
|
|
1186
|
-
|
|
1187
|
-
|
|
1188
|
-
var index = this.cache.indexOf(e);
|
|
1189
|
-
this.cache.splice(index, 1);
|
|
1163
|
+
if (this._children) {
|
|
1164
|
+
this._children.forEach(function (x) { return x.cancel(); });
|
|
1190
1165
|
}
|
|
1166
|
+
if (this._isPending) {
|
|
1167
|
+
if (this._cancelHandlers.length) {
|
|
1168
|
+
try {
|
|
1169
|
+
for (var _i = 0, _a = this._cancelHandlers; _i < _a.length; _i++) {
|
|
1170
|
+
var handler = _a[_i];
|
|
1171
|
+
handler();
|
|
1172
|
+
}
|
|
1173
|
+
}
|
|
1174
|
+
catch (error) {
|
|
1175
|
+
// this._setCanceledCallback(error);
|
|
1176
|
+
}
|
|
1177
|
+
}
|
|
1178
|
+
if (this._setCanceledCallback) {
|
|
1179
|
+
this._setCanceledCallback();
|
|
1180
|
+
}
|
|
1181
|
+
}
|
|
1182
|
+
this._destroy();
|
|
1183
|
+
return this;
|
|
1191
1184
|
};
|
|
1192
|
-
|
|
1193
|
-
var
|
|
1194
|
-
|
|
1195
|
-
|
|
1196
|
-
|
|
1197
|
-
|
|
1198
|
-
|
|
1199
|
-
|
|
1200
|
-
|
|
1201
|
-
|
|
1185
|
+
CancelablePromise.prototype._getTopParent = function () {
|
|
1186
|
+
var parent = this._parentPromise;
|
|
1187
|
+
var hasParent = !!parent;
|
|
1188
|
+
while (hasParent) {
|
|
1189
|
+
if (parent && parent._parentPromise) {
|
|
1190
|
+
parent = parent._parentPromise;
|
|
1191
|
+
hasParent = !!parent;
|
|
1192
|
+
}
|
|
1193
|
+
else {
|
|
1194
|
+
hasParent = false;
|
|
1202
1195
|
}
|
|
1203
|
-
return true;
|
|
1204
1196
|
}
|
|
1205
|
-
return
|
|
1197
|
+
return parent;
|
|
1206
1198
|
};
|
|
1207
|
-
|
|
1208
|
-
|
|
1199
|
+
CancelablePromise.prototype._destroy = function () {
|
|
1200
|
+
this._setCanceledCallback = undefined;
|
|
1201
|
+
this._cancelPromise = undefined;
|
|
1202
|
+
this._promise = undefined;
|
|
1203
|
+
};
|
|
1204
|
+
CancelablePromise.CancelError = CancelError;
|
|
1205
|
+
CancelablePromise.TimeoutError = TimeoutError;
|
|
1206
|
+
CancelablePromise.PromiseControl = PromiseControl;
|
|
1207
|
+
return CancelablePromise;
|
|
1209
1208
|
}());
|
|
1209
|
+
Object.setPrototypeOf(CancelablePromise$1.prototype, Promise.prototype);
|
|
1210
1210
|
|
|
1211
1211
|
/**
|
|
1212
|
-
*
|
|
1212
|
+
* A promise you can stop
|
|
1213
1213
|
*
|
|
1214
1214
|
* @packageDocumentation
|
|
1215
|
-
* @module
|
|
1216
|
-
*/
|
|
1217
|
-
var Cache = Cache$1;
|
|
1218
|
-
|
|
1219
|
-
/**
|
|
1220
|
-
* Thrown when...
|
|
1215
|
+
* @module cancelable-promise
|
|
1221
1216
|
*/
|
|
1222
|
-
var
|
|
1223
|
-
__extends(NetworkError, _super);
|
|
1224
|
-
function NetworkError(url) {
|
|
1225
|
-
var _this = _super.call(this) || this;
|
|
1226
|
-
_this.name = 'NetworkError';
|
|
1227
|
-
Object.setPrototypeOf(_this, NetworkError.prototype);
|
|
1228
|
-
_this.message = "Unable to request ".concat(url, ".\n Possibly invalid NGW URL entered or CORS not configured to get request from ").concat(location.origin); // /control-panel/cors
|
|
1229
|
-
return _this;
|
|
1230
|
-
}
|
|
1231
|
-
return NetworkError;
|
|
1232
|
-
}(Error));
|
|
1217
|
+
var CancelablePromise = CancelablePromise$1;
|
|
1233
1218
|
|
|
1234
1219
|
/**
|
|
1235
1220
|
* Thrown when...
|
|
@@ -1246,195 +1231,6 @@ var NgwConnector = (function () {
|
|
|
1246
1231
|
return NgwError;
|
|
1247
1232
|
}(Error));
|
|
1248
1233
|
|
|
1249
|
-
function isObject(val) {
|
|
1250
|
-
return Object.prototype.toString.call(val) === '[object Object]';
|
|
1251
|
-
}
|
|
1252
|
-
|
|
1253
|
-
var loadData;
|
|
1254
|
-
// @ts-ignore
|
|
1255
|
-
{
|
|
1256
|
-
loadData = function (url, callback, options, error, onCancel) {
|
|
1257
|
-
if (options === void 0) { options = {}; }
|
|
1258
|
-
options.method = options.method || 'GET';
|
|
1259
|
-
var xhr = new XMLHttpRequest();
|
|
1260
|
-
xhr.open(options.method || 'GET', url, true); // true for asynchronous
|
|
1261
|
-
if (options.responseType === 'blob') {
|
|
1262
|
-
xhr.responseType = options.responseType;
|
|
1263
|
-
}
|
|
1264
|
-
var getResponseText = function () {
|
|
1265
|
-
try {
|
|
1266
|
-
return JSON.parse(xhr.responseText);
|
|
1267
|
-
}
|
|
1268
|
-
catch (er) {
|
|
1269
|
-
return xhr.responseText;
|
|
1270
|
-
}
|
|
1271
|
-
};
|
|
1272
|
-
var processingResponse = function (forError) {
|
|
1273
|
-
if (forError === void 0) { forError = false; }
|
|
1274
|
-
var cb = forError ? error : callback;
|
|
1275
|
-
if (options.responseType === 'blob') {
|
|
1276
|
-
cb(xhr.response);
|
|
1277
|
-
}
|
|
1278
|
-
else {
|
|
1279
|
-
if (xhr.responseText) {
|
|
1280
|
-
cb(getResponseText());
|
|
1281
|
-
}
|
|
1282
|
-
else {
|
|
1283
|
-
error({ message: '' });
|
|
1284
|
-
}
|
|
1285
|
-
}
|
|
1286
|
-
};
|
|
1287
|
-
xhr.onload = function () {
|
|
1288
|
-
if ([401, 403, 404, 422, 500].indexOf(xhr.status) !== -1) {
|
|
1289
|
-
error(new NgwError(getResponseText()));
|
|
1290
|
-
}
|
|
1291
|
-
processingResponse();
|
|
1292
|
-
};
|
|
1293
|
-
// xhr.onreadystatechange = () => {
|
|
1294
|
-
// if (
|
|
1295
|
-
// (xhr.readyState === 4 && xhr.status === 200) ||
|
|
1296
|
-
// (xhr.readyState === 3 && xhr.status === 201)
|
|
1297
|
-
// ) {
|
|
1298
|
-
// processingResponse();
|
|
1299
|
-
// } else if (xhr.readyState === 3 && xhr.status === 400) {
|
|
1300
|
-
// processingResponse();
|
|
1301
|
-
// } else if (xhr.readyState === 4 && xhr.status === 500) {
|
|
1302
|
-
// processingResponse();
|
|
1303
|
-
// } else if (xhr.readyState === 4 && xhr.status === 401) {
|
|
1304
|
-
// error(xhr.statusText);
|
|
1305
|
-
// } else if (xhr.readyState === 4) {
|
|
1306
|
-
// error('request error');
|
|
1307
|
-
// }
|
|
1308
|
-
// };
|
|
1309
|
-
xhr.onerror = function (er) {
|
|
1310
|
-
if (xhr.status === 0) {
|
|
1311
|
-
error(new NetworkError(url));
|
|
1312
|
-
}
|
|
1313
|
-
else {
|
|
1314
|
-
error(er);
|
|
1315
|
-
}
|
|
1316
|
-
};
|
|
1317
|
-
xhr.upload.onprogress = function (e) {
|
|
1318
|
-
if (e.lengthComputable) {
|
|
1319
|
-
var percentComplete = (e.loaded / e.total) * 100;
|
|
1320
|
-
if (options.onProgress) {
|
|
1321
|
-
options.onProgress(percentComplete, e);
|
|
1322
|
-
}
|
|
1323
|
-
// console.log(percentComplete + '% uploaded');
|
|
1324
|
-
}
|
|
1325
|
-
};
|
|
1326
|
-
var headers = options.headers;
|
|
1327
|
-
if (headers) {
|
|
1328
|
-
for (var h in headers) {
|
|
1329
|
-
var header = headers[h];
|
|
1330
|
-
if (typeof header === 'string') {
|
|
1331
|
-
xhr.setRequestHeader(h, header);
|
|
1332
|
-
}
|
|
1333
|
-
}
|
|
1334
|
-
}
|
|
1335
|
-
if (options.withCredentials !== undefined) {
|
|
1336
|
-
xhr.withCredentials = options.withCredentials;
|
|
1337
|
-
}
|
|
1338
|
-
var data;
|
|
1339
|
-
if (options.file) {
|
|
1340
|
-
data = new FormData();
|
|
1341
|
-
data.append('file', options.file);
|
|
1342
|
-
if (options.data) {
|
|
1343
|
-
for (var d in options.data) {
|
|
1344
|
-
data.append(d, data[d]);
|
|
1345
|
-
}
|
|
1346
|
-
}
|
|
1347
|
-
}
|
|
1348
|
-
else {
|
|
1349
|
-
data = options.data
|
|
1350
|
-
? typeof options.data === 'string'
|
|
1351
|
-
? options.data
|
|
1352
|
-
: JSON.stringify(options.data)
|
|
1353
|
-
: null;
|
|
1354
|
-
}
|
|
1355
|
-
if (onCancel) {
|
|
1356
|
-
onCancel(function () {
|
|
1357
|
-
xhr.abort();
|
|
1358
|
-
});
|
|
1359
|
-
}
|
|
1360
|
-
xhr.send(data);
|
|
1361
|
-
};
|
|
1362
|
-
}
|
|
1363
|
-
|
|
1364
|
-
// https://github.com/Leaflet/Leaflet/blob/b507e21c510b53cd704fb8d3f89bb46ea925c8eb/src/core/Util.js#L165
|
|
1365
|
-
var templateRe = /\{ *([\w_-]+) *\}/g;
|
|
1366
|
-
function template(str, data) {
|
|
1367
|
-
return str.replace(templateRe, function (s, key) {
|
|
1368
|
-
var value = data[key];
|
|
1369
|
-
if (value === undefined) {
|
|
1370
|
-
throw new Error('No value provided for letiable ' + s);
|
|
1371
|
-
}
|
|
1372
|
-
else if (typeof value === 'function') {
|
|
1373
|
-
value = value(data);
|
|
1374
|
-
}
|
|
1375
|
-
return value;
|
|
1376
|
-
});
|
|
1377
|
-
}
|
|
1378
|
-
|
|
1379
|
-
function apiRequest(opt) {
|
|
1380
|
-
var params = opt.params;
|
|
1381
|
-
return new CancelablePromise(function (resolve, reject) {
|
|
1382
|
-
opt.connector
|
|
1383
|
-
.connect()
|
|
1384
|
-
.then(function (apiItems) {
|
|
1385
|
-
var apiItem = apiItems && apiItems[opt.name];
|
|
1386
|
-
if (apiItem) {
|
|
1387
|
-
apiItem = __spreadArray([], apiItem, true);
|
|
1388
|
-
var url = apiItem.shift();
|
|
1389
|
-
if (apiItem.length) {
|
|
1390
|
-
var replaceParams = {};
|
|
1391
|
-
for (var fry = 0; fry < apiItem.length; fry++) {
|
|
1392
|
-
var arg = apiItem[fry];
|
|
1393
|
-
replaceParams[fry] = '{' + arg + '}';
|
|
1394
|
-
if (params[arg] === undefined) {
|
|
1395
|
-
throw new Error('`' + arg + '`' + ' url api argument is not specified');
|
|
1396
|
-
}
|
|
1397
|
-
}
|
|
1398
|
-
if (url) {
|
|
1399
|
-
url = template(url, replaceParams);
|
|
1400
|
-
}
|
|
1401
|
-
}
|
|
1402
|
-
// Transfer part of the parameters from `params` to the URL string
|
|
1403
|
-
if (params) {
|
|
1404
|
-
var paramArray_1 = [];
|
|
1405
|
-
var paramList = params.paramList;
|
|
1406
|
-
if (Array.isArray(paramList)) {
|
|
1407
|
-
delete params.paramList;
|
|
1408
|
-
paramList.forEach(function (x) {
|
|
1409
|
-
paramArray_1.push("".concat(x[0], "=").concat(x[1]));
|
|
1410
|
-
});
|
|
1411
|
-
}
|
|
1412
|
-
for (var p in params) {
|
|
1413
|
-
if (apiItem.indexOf(p) === -1) {
|
|
1414
|
-
paramArray_1.push("".concat(p, "=").concat(params[p]));
|
|
1415
|
-
}
|
|
1416
|
-
}
|
|
1417
|
-
if (paramArray_1.length) {
|
|
1418
|
-
url = url + '?' + paramArray_1.join('&');
|
|
1419
|
-
}
|
|
1420
|
-
}
|
|
1421
|
-
if (url) {
|
|
1422
|
-
resolve(opt.connector.makeQuery(url, params, opt.requestOptions));
|
|
1423
|
-
}
|
|
1424
|
-
else {
|
|
1425
|
-
reject(new Error('request url is not set'));
|
|
1426
|
-
}
|
|
1427
|
-
}
|
|
1428
|
-
else {
|
|
1429
|
-
resolve(undefined);
|
|
1430
|
-
}
|
|
1431
|
-
})
|
|
1432
|
-
.catch(function (er) {
|
|
1433
|
-
reject(er);
|
|
1434
|
-
});
|
|
1435
|
-
});
|
|
1436
|
-
}
|
|
1437
|
-
|
|
1438
1234
|
/**
|
|
1439
1235
|
* Thrown when ...
|
|
1440
1236
|
*/
|
|
@@ -1444,51 +1240,18 @@ var NgwConnector = (function () {
|
|
|
1444
1240
|
var _this = _super.call(this, obj) || this;
|
|
1445
1241
|
_this.name = 'ResourceNotFoundError';
|
|
1446
1242
|
_this.exception = 'nextgisweb.resource.exception.ResourceNotFound';
|
|
1447
|
-
Object.setPrototypeOf(_this, ResourceNotFoundError.prototype);
|
|
1448
|
-
return _this;
|
|
1449
|
-
}
|
|
1450
|
-
return ResourceNotFoundError;
|
|
1451
|
-
}(NgwError));
|
|
1452
|
-
|
|
1453
|
-
/**
|
|
1454
|
-
* Thrown when ...
|
|
1455
|
-
*/
|
|
1456
|
-
var InsufficientPermissionsError = /** @class */ (function (_super) {
|
|
1457
|
-
__extends(InsufficientPermissionsError, _super);
|
|
1458
|
-
function InsufficientPermissionsError(obj) {
|
|
1459
|
-
var _this = _super.call(this, obj) || this;
|
|
1460
|
-
_this.name = 'InsufficientPermissionsError';
|
|
1461
|
-
_this.exception = 'nextgisweb.core.exception.InsufficientPermissions';
|
|
1462
|
-
Object.setPrototypeOf(_this, InsufficientPermissionsError.prototype);
|
|
1463
|
-
return _this;
|
|
1464
|
-
}
|
|
1465
|
-
return InsufficientPermissionsError;
|
|
1466
|
-
}(NgwError));
|
|
1467
|
-
|
|
1468
|
-
var CONNECTORS = [];
|
|
1469
|
-
function addConnector(connector) {
|
|
1470
|
-
CONNECTORS.push(connector);
|
|
1471
|
-
}
|
|
1472
|
-
function findConnector(options) {
|
|
1473
|
-
return CONNECTORS.find(function (x) {
|
|
1474
|
-
if (x.options.baseUrl === options.baseUrl) {
|
|
1475
|
-
if (options.auth) {
|
|
1476
|
-
if (x.options.auth) {
|
|
1477
|
-
return objectDeepEqual(x.options.auth, options.auth);
|
|
1478
|
-
}
|
|
1479
|
-
}
|
|
1480
|
-
else {
|
|
1481
|
-
// if auth not in find options; use first connector with same url
|
|
1482
|
-
return true;
|
|
1483
|
-
}
|
|
1484
|
-
}
|
|
1485
|
-
});
|
|
1486
|
-
}
|
|
1487
|
-
function removeConnector(connector) {
|
|
1488
|
-
var index = CONNECTORS.indexOf(connector);
|
|
1489
|
-
if (index !== -1) {
|
|
1490
|
-
CONNECTORS.splice(index, 1);
|
|
1243
|
+
Object.setPrototypeOf(_this, ResourceNotFoundError.prototype);
|
|
1244
|
+
return _this;
|
|
1491
1245
|
}
|
|
1246
|
+
return ResourceNotFoundError;
|
|
1247
|
+
}(NgwError));
|
|
1248
|
+
|
|
1249
|
+
function isObject(val) {
|
|
1250
|
+
return Object.prototype.toString.call(val) === '[object Object]';
|
|
1251
|
+
}
|
|
1252
|
+
|
|
1253
|
+
function resourceCompare(res1, res2) {
|
|
1254
|
+
return objectDeepEqual(res1, res2);
|
|
1492
1255
|
}
|
|
1493
1256
|
|
|
1494
1257
|
var exclude = ['description'];
|
|
@@ -1526,10 +1289,6 @@ var NgwConnector = (function () {
|
|
|
1526
1289
|
return query;
|
|
1527
1290
|
}
|
|
1528
1291
|
|
|
1529
|
-
function resourceCompare(res1, res2) {
|
|
1530
|
-
return objectDeepEqual(res1, res2);
|
|
1531
|
-
}
|
|
1532
|
-
|
|
1533
1292
|
var ResourcesControl = /** @class */ (function () {
|
|
1534
1293
|
function ResourcesControl(connector) {
|
|
1535
1294
|
this.connector = connector;
|
|
@@ -1800,6 +1559,247 @@ var NgwConnector = (function () {
|
|
|
1800
1559
|
return ResourcesControl;
|
|
1801
1560
|
}());
|
|
1802
1561
|
|
|
1562
|
+
var CONNECTORS = [];
|
|
1563
|
+
function addConnector(connector) {
|
|
1564
|
+
CONNECTORS.push(connector);
|
|
1565
|
+
}
|
|
1566
|
+
function findConnector(options) {
|
|
1567
|
+
return CONNECTORS.find(function (x) {
|
|
1568
|
+
if (x.options.baseUrl === options.baseUrl) {
|
|
1569
|
+
if (options.auth) {
|
|
1570
|
+
if (x.options.auth) {
|
|
1571
|
+
return objectDeepEqual(x.options.auth, options.auth);
|
|
1572
|
+
}
|
|
1573
|
+
}
|
|
1574
|
+
else {
|
|
1575
|
+
// if auth not in find options; use first connector with same url
|
|
1576
|
+
return true;
|
|
1577
|
+
}
|
|
1578
|
+
}
|
|
1579
|
+
});
|
|
1580
|
+
}
|
|
1581
|
+
function removeConnector(connector) {
|
|
1582
|
+
var index = CONNECTORS.indexOf(connector);
|
|
1583
|
+
if (index !== -1) {
|
|
1584
|
+
CONNECTORS.splice(index, 1);
|
|
1585
|
+
}
|
|
1586
|
+
}
|
|
1587
|
+
|
|
1588
|
+
/**
|
|
1589
|
+
* Thrown when ...
|
|
1590
|
+
*/
|
|
1591
|
+
var InsufficientPermissionsError = /** @class */ (function (_super) {
|
|
1592
|
+
__extends(InsufficientPermissionsError, _super);
|
|
1593
|
+
function InsufficientPermissionsError(obj) {
|
|
1594
|
+
var _this = _super.call(this, obj) || this;
|
|
1595
|
+
_this.name = 'InsufficientPermissionsError';
|
|
1596
|
+
_this.exception = 'nextgisweb.core.exception.InsufficientPermissions';
|
|
1597
|
+
Object.setPrototypeOf(_this, InsufficientPermissionsError.prototype);
|
|
1598
|
+
return _this;
|
|
1599
|
+
}
|
|
1600
|
+
return InsufficientPermissionsError;
|
|
1601
|
+
}(NgwError));
|
|
1602
|
+
|
|
1603
|
+
// https://github.com/Leaflet/Leaflet/blob/b507e21c510b53cd704fb8d3f89bb46ea925c8eb/src/core/Util.js#L165
|
|
1604
|
+
var templateRe = /\{ *([\w_-]+) *\}/g;
|
|
1605
|
+
function template(str, data) {
|
|
1606
|
+
return str.replace(templateRe, function (s, key) {
|
|
1607
|
+
var value = data[key];
|
|
1608
|
+
if (value === undefined) {
|
|
1609
|
+
throw new Error('No value provided for letiable ' + s);
|
|
1610
|
+
}
|
|
1611
|
+
else if (typeof value === 'function') {
|
|
1612
|
+
value = value(data);
|
|
1613
|
+
}
|
|
1614
|
+
return value;
|
|
1615
|
+
});
|
|
1616
|
+
}
|
|
1617
|
+
|
|
1618
|
+
function apiRequest(opt) {
|
|
1619
|
+
var params = opt.params;
|
|
1620
|
+
return new CancelablePromise(function (resolve, reject) {
|
|
1621
|
+
opt.connector
|
|
1622
|
+
.connect()
|
|
1623
|
+
.then(function (apiItems) {
|
|
1624
|
+
var apiItem = apiItems && apiItems[opt.name];
|
|
1625
|
+
if (apiItem) {
|
|
1626
|
+
apiItem = __spreadArray([], apiItem, true);
|
|
1627
|
+
var url = apiItem.shift();
|
|
1628
|
+
if (apiItem.length) {
|
|
1629
|
+
var replaceParams = {};
|
|
1630
|
+
for (var fry = 0; fry < apiItem.length; fry++) {
|
|
1631
|
+
var arg = apiItem[fry];
|
|
1632
|
+
replaceParams[fry] = '{' + arg + '}';
|
|
1633
|
+
if (params[arg] === undefined) {
|
|
1634
|
+
throw new Error('`' + arg + '`' + ' url api argument is not specified');
|
|
1635
|
+
}
|
|
1636
|
+
}
|
|
1637
|
+
if (url) {
|
|
1638
|
+
url = template(url, replaceParams);
|
|
1639
|
+
}
|
|
1640
|
+
}
|
|
1641
|
+
// Transfer part of the parameters from `params` to the URL string
|
|
1642
|
+
if (params) {
|
|
1643
|
+
var paramArray_1 = [];
|
|
1644
|
+
var paramList = params.paramList;
|
|
1645
|
+
if (Array.isArray(paramList)) {
|
|
1646
|
+
delete params.paramList;
|
|
1647
|
+
paramList.forEach(function (x) {
|
|
1648
|
+
paramArray_1.push("".concat(x[0], "=").concat(x[1]));
|
|
1649
|
+
});
|
|
1650
|
+
}
|
|
1651
|
+
for (var p in params) {
|
|
1652
|
+
if (apiItem.indexOf(p) === -1) {
|
|
1653
|
+
paramArray_1.push("".concat(p, "=").concat(params[p]));
|
|
1654
|
+
}
|
|
1655
|
+
}
|
|
1656
|
+
if (paramArray_1.length) {
|
|
1657
|
+
url = url + '?' + paramArray_1.join('&');
|
|
1658
|
+
}
|
|
1659
|
+
}
|
|
1660
|
+
if (url) {
|
|
1661
|
+
resolve(opt.connector.makeQuery(url, params, opt.requestOptions));
|
|
1662
|
+
}
|
|
1663
|
+
else {
|
|
1664
|
+
reject(new Error('request url is not set'));
|
|
1665
|
+
}
|
|
1666
|
+
}
|
|
1667
|
+
else {
|
|
1668
|
+
resolve(undefined);
|
|
1669
|
+
}
|
|
1670
|
+
})
|
|
1671
|
+
.catch(function (er) {
|
|
1672
|
+
reject(er);
|
|
1673
|
+
});
|
|
1674
|
+
});
|
|
1675
|
+
}
|
|
1676
|
+
|
|
1677
|
+
/**
|
|
1678
|
+
* Thrown when...
|
|
1679
|
+
*/
|
|
1680
|
+
var NetworkError = /** @class */ (function (_super) {
|
|
1681
|
+
__extends(NetworkError, _super);
|
|
1682
|
+
function NetworkError(url) {
|
|
1683
|
+
var _this = _super.call(this) || this;
|
|
1684
|
+
_this.name = 'NetworkError';
|
|
1685
|
+
Object.setPrototypeOf(_this, NetworkError.prototype);
|
|
1686
|
+
_this.message = "Unable to request ".concat(url, ".\n Possibly invalid NGW URL entered or CORS not configured to get request from ").concat(location.origin); // /control-panel/cors
|
|
1687
|
+
return _this;
|
|
1688
|
+
}
|
|
1689
|
+
return NetworkError;
|
|
1690
|
+
}(Error));
|
|
1691
|
+
|
|
1692
|
+
var loadData;
|
|
1693
|
+
// @ts-ignore
|
|
1694
|
+
{
|
|
1695
|
+
loadData = function (url, callback, options, error, onCancel) {
|
|
1696
|
+
if (options === void 0) { options = {}; }
|
|
1697
|
+
options.method = options.method || 'GET';
|
|
1698
|
+
var xhr = new XMLHttpRequest();
|
|
1699
|
+
xhr.open(options.method || 'GET', url, true); // true for asynchronous
|
|
1700
|
+
if (options.responseType === 'blob') {
|
|
1701
|
+
xhr.responseType = options.responseType;
|
|
1702
|
+
}
|
|
1703
|
+
var getResponseText = function () {
|
|
1704
|
+
try {
|
|
1705
|
+
return JSON.parse(xhr.responseText);
|
|
1706
|
+
}
|
|
1707
|
+
catch (er) {
|
|
1708
|
+
return xhr.responseText;
|
|
1709
|
+
}
|
|
1710
|
+
};
|
|
1711
|
+
var processingResponse = function (forError) {
|
|
1712
|
+
if (forError === void 0) { forError = false; }
|
|
1713
|
+
var cb = forError ? error : callback;
|
|
1714
|
+
if (options.responseType === 'blob') {
|
|
1715
|
+
cb(xhr.response);
|
|
1716
|
+
}
|
|
1717
|
+
else {
|
|
1718
|
+
if (xhr.responseText) {
|
|
1719
|
+
cb(getResponseText());
|
|
1720
|
+
}
|
|
1721
|
+
else {
|
|
1722
|
+
error({ message: '' });
|
|
1723
|
+
}
|
|
1724
|
+
}
|
|
1725
|
+
};
|
|
1726
|
+
xhr.onload = function () {
|
|
1727
|
+
if ([401, 403, 404, 422, 500].indexOf(xhr.status) !== -1) {
|
|
1728
|
+
error(new NgwError(getResponseText()));
|
|
1729
|
+
}
|
|
1730
|
+
processingResponse();
|
|
1731
|
+
};
|
|
1732
|
+
// xhr.onreadystatechange = () => {
|
|
1733
|
+
// if (
|
|
1734
|
+
// (xhr.readyState === 4 && xhr.status === 200) ||
|
|
1735
|
+
// (xhr.readyState === 3 && xhr.status === 201)
|
|
1736
|
+
// ) {
|
|
1737
|
+
// processingResponse();
|
|
1738
|
+
// } else if (xhr.readyState === 3 && xhr.status === 400) {
|
|
1739
|
+
// processingResponse();
|
|
1740
|
+
// } else if (xhr.readyState === 4 && xhr.status === 500) {
|
|
1741
|
+
// processingResponse();
|
|
1742
|
+
// } else if (xhr.readyState === 4 && xhr.status === 401) {
|
|
1743
|
+
// error(xhr.statusText);
|
|
1744
|
+
// } else if (xhr.readyState === 4) {
|
|
1745
|
+
// error('request error');
|
|
1746
|
+
// }
|
|
1747
|
+
// };
|
|
1748
|
+
xhr.onerror = function (er) {
|
|
1749
|
+
if (xhr.status === 0) {
|
|
1750
|
+
error(new NetworkError(url));
|
|
1751
|
+
}
|
|
1752
|
+
else {
|
|
1753
|
+
error(er);
|
|
1754
|
+
}
|
|
1755
|
+
};
|
|
1756
|
+
xhr.upload.onprogress = function (e) {
|
|
1757
|
+
if (e.lengthComputable) {
|
|
1758
|
+
var percentComplete = (e.loaded / e.total) * 100;
|
|
1759
|
+
if (options.onProgress) {
|
|
1760
|
+
options.onProgress(percentComplete, e);
|
|
1761
|
+
}
|
|
1762
|
+
// console.log(percentComplete + '% uploaded');
|
|
1763
|
+
}
|
|
1764
|
+
};
|
|
1765
|
+
var headers = options.headers;
|
|
1766
|
+
if (headers) {
|
|
1767
|
+
for (var h in headers) {
|
|
1768
|
+
var header = headers[h];
|
|
1769
|
+
if (typeof header === 'string') {
|
|
1770
|
+
xhr.setRequestHeader(h, header);
|
|
1771
|
+
}
|
|
1772
|
+
}
|
|
1773
|
+
}
|
|
1774
|
+
if (options.withCredentials !== undefined) {
|
|
1775
|
+
xhr.withCredentials = options.withCredentials;
|
|
1776
|
+
}
|
|
1777
|
+
var data;
|
|
1778
|
+
if (options.file) {
|
|
1779
|
+
data = new FormData();
|
|
1780
|
+
data.append('file', options.file);
|
|
1781
|
+
if (options.data) {
|
|
1782
|
+
for (var d in options.data) {
|
|
1783
|
+
data.append(d, data[d]);
|
|
1784
|
+
}
|
|
1785
|
+
}
|
|
1786
|
+
}
|
|
1787
|
+
else {
|
|
1788
|
+
data = options.data
|
|
1789
|
+
? typeof options.data === 'string'
|
|
1790
|
+
? options.data
|
|
1791
|
+
: JSON.stringify(options.data)
|
|
1792
|
+
: null;
|
|
1793
|
+
}
|
|
1794
|
+
if (onCancel) {
|
|
1795
|
+
onCancel(function () {
|
|
1796
|
+
xhr.abort();
|
|
1797
|
+
});
|
|
1798
|
+
}
|
|
1799
|
+
xhr.send(data);
|
|
1800
|
+
};
|
|
1801
|
+
}
|
|
1802
|
+
|
|
1803
1803
|
var ID = 0;
|
|
1804
1804
|
var NgwConnector$1 = /** @class */ (function () {
|
|
1805
1805
|
function NgwConnector(options) {
|