@nextgis/geocoder 2.5.0 → 3.0.0-alpha.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,306 +1,4 @@
1
- /** Bundle of @nextgis/geocoder; version: 2.5.0; author: NextGIS */
2
- var __defProp$g = Object.defineProperty;
3
- var __defNormalProp$g = (obj, key, value) => key in obj ? __defProp$g(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
4
- var __publicField$e = (obj, key, value) => __defNormalProp$g(obj, key + "" , value);
5
- class CancelError extends Error {
6
- constructor() {
7
- super();
8
- __publicField$e(this, "name", "CancelError");
9
- Object.setPrototypeOf(this, CancelError.prototype);
10
- }
11
- }
12
-
13
- var __defProp$f = Object.defineProperty;
14
- var __defNormalProp$f = (obj, key, value) => key in obj ? __defProp$f(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
15
- var __publicField$d = (obj, key, value) => __defNormalProp$f(obj, key + "" , value);
16
- class PromiseControl {
17
- constructor(options = {}) {
18
- this.options = options;
19
- __publicField$d(this, "_promises", /* @__PURE__ */ new Map());
20
- }
21
- get isLoaded() {
22
- return this._promises.size > 0;
23
- }
24
- remove(promise) {
25
- if (this._promises.has(promise)) {
26
- this._promises.delete(promise);
27
- this._onStop();
28
- }
29
- }
30
- get(promise) {
31
- return this._promises.get(promise);
32
- }
33
- add(promise, name) {
34
- const key = name ? name : promise;
35
- const exist = this._promises.get(key);
36
- if (this.options.onStart && !this.isLoaded) {
37
- this.options.onStart();
38
- }
39
- if (exist) {
40
- return exist;
41
- }
42
- this._promises.set(key, promise);
43
- promise.finally(() => {
44
- this.remove(key);
45
- });
46
- return promise;
47
- }
48
- abort() {
49
- if (this.isLoaded) {
50
- this._promises.forEach((x) => {
51
- if (x.cancel) {
52
- x.cancel();
53
- }
54
- });
55
- this._promises.clear();
56
- this._onStop();
57
- }
58
- }
59
- waitFunc(func, name = "") {
60
- name = name || func.name;
61
- const exist = this.get(name);
62
- if (exist) {
63
- return exist;
64
- }
65
- return this.add(func(), name);
66
- }
67
- WaitForMe(name = "") {
68
- const get = this.get.bind(this);
69
- const add = this.add.bind(this);
70
- return function(target, key, descriptor) {
71
- const originalMethod = descriptor.value;
72
- name = name || key;
73
- descriptor.value = function(...args) {
74
- const exist = get(name);
75
- if (exist) {
76
- return exist;
77
- }
78
- const result = add(originalMethod.apply(this, args), name);
79
- return result;
80
- };
81
- return descriptor;
82
- };
83
- }
84
- /** @deprecated use {@link PromiseControl.WaitForMe } instead */
85
- GetOrCreateDecorator(name = "") {
86
- return this.WaitForMe(name);
87
- }
88
- _onStop() {
89
- if (this.options.onStop && !this.isLoaded) {
90
- this.options.onStop();
91
- }
92
- }
93
- }
94
-
95
- var __defProp$e = Object.defineProperty;
96
- var __defNormalProp$e = (obj, key, value) => key in obj ? __defProp$e(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
97
- var __publicField$c = (obj, key, value) => __defNormalProp$e(obj, key + "" , value);
98
- class TimeoutError extends Error {
99
- constructor() {
100
- super();
101
- __publicField$c(this, "name", "TimeoutError");
102
- Object.setPrototypeOf(this, TimeoutError.prototype);
103
- }
104
- }
105
-
106
- var __defProp$d = Object.defineProperty;
107
- var __defNormalProp$d = (obj, key, value) => key in obj ? __defProp$d(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
108
- var __publicField$b = (obj, key, value) => __defNormalProp$d(obj, typeof key !== "symbol" ? key + "" : key, value);
109
- var _a;
110
- const handleCallback = (resolve, reject, callback, r) => {
111
- try {
112
- resolve(callback(r));
113
- } catch (e) {
114
- reject(e);
115
- }
116
- };
117
- let ID$2 = 0;
118
- _a = Symbol.toStringTag;
119
- const _CancelablePromise = class _CancelablePromise {
120
- constructor(executor, timeout) {
121
- // @ts-ignore
122
- __publicField$b(this, _a);
123
- __publicField$b(this, "id", ID$2++);
124
- __publicField$b(this, "_isCanceled", false);
125
- __publicField$b(this, "_isPending", true);
126
- __publicField$b(this, "_promise");
127
- __publicField$b(this, "_cancelPromise");
128
- __publicField$b(this, "_cancelHandlers", []);
129
- __publicField$b(this, "_setCanceledCallback");
130
- __publicField$b(this, "_parentPromise");
131
- __publicField$b(this, "_children", []);
132
- this._cancelPromise = new Promise((resolve_, reject_) => {
133
- this._setCanceledCallback = (er) => resolve_(er || new CancelError());
134
- });
135
- const promises = [
136
- this._cancelPromise,
137
- new Promise((resolve, reject) => {
138
- const onResolve = (value) => {
139
- if (value instanceof _CancelablePromise) {
140
- this.attach(value);
141
- } else {
142
- this._isPending = false;
143
- }
144
- resolve(value);
145
- };
146
- const onReject = (error) => {
147
- this._isPending = false;
148
- reject(error);
149
- };
150
- const onCancel = (handler) => {
151
- if (!this._isPending) {
152
- throw new Error(
153
- "The `onCancel` handler was attached after the promise settled."
154
- );
155
- }
156
- this._cancelHandlers.push(handler);
157
- };
158
- return executor(onResolve, onReject, onCancel);
159
- })
160
- ];
161
- if (timeout) {
162
- promises.push(
163
- new Promise((resolve, reject) => {
164
- setTimeout(() => {
165
- if (this._isPending) {
166
- try {
167
- this.cancel();
168
- } finally {
169
- reject(new TimeoutError());
170
- }
171
- }
172
- }, timeout);
173
- })
174
- );
175
- }
176
- this._promise = Promise.race(promises);
177
- }
178
- static createControl(opt) {
179
- return new PromiseControl(opt);
180
- }
181
- static resolve(value) {
182
- return new _CancelablePromise((resolve) => resolve(value));
183
- }
184
- static reject(value) {
185
- return new _CancelablePromise((resolve, reject) => reject(value));
186
- }
187
- static all(values) {
188
- return new _CancelablePromise((resolve, reject) => {
189
- Promise.all(values).then(resolve).catch(reject);
190
- }).catch((er) => {
191
- if (er instanceof this.CancelError) {
192
- for (const v of values) {
193
- const v_ = v;
194
- if ("cancel" in v_) {
195
- v_.cancel();
196
- }
197
- }
198
- }
199
- throw er;
200
- });
201
- }
202
- attach(p) {
203
- if (this._isCanceled) {
204
- p.cancel();
205
- } else {
206
- this._children.push(p);
207
- }
208
- }
209
- then(onfulfilled, onrejected) {
210
- const p = new _CancelablePromise((resolve, reject) => {
211
- if (this._promise) {
212
- const reject_ = (r) => {
213
- if (onrejected) {
214
- handleCallback(resolve, reject, onrejected, r);
215
- } else {
216
- reject(r);
217
- }
218
- };
219
- this._promise.then((r) => {
220
- if (this._isCanceled) {
221
- reject_(r);
222
- } else {
223
- if (onfulfilled) {
224
- handleCallback(resolve, reject, onfulfilled, r);
225
- } else {
226
- resolve(r);
227
- }
228
- }
229
- }, reject_);
230
- }
231
- });
232
- p._parentPromise = this;
233
- this._children.push(p);
234
- return p;
235
- }
236
- catch(onrejected) {
237
- if (this._isCanceled && onrejected) {
238
- onrejected(new CancelError());
239
- }
240
- return this.then(void 0, onrejected);
241
- }
242
- finally(onfinally) {
243
- if (this._promise) {
244
- return this._promise.finally(onfinally);
245
- }
246
- if (this._isCanceled) {
247
- return Promise.reject(new CancelError());
248
- }
249
- return Promise.reject(onfinally);
250
- }
251
- cancel() {
252
- if (this._isCanceled || !this._isPending) {
253
- return this;
254
- }
255
- this._isCanceled = true;
256
- const parent = this._getTopParent();
257
- if (parent) {
258
- parent.cancel();
259
- }
260
- if (this._children) {
261
- this._children.forEach((x) => x.cancel());
262
- }
263
- if (this._isPending) {
264
- if (this._cancelHandlers.length) {
265
- try {
266
- for (const handler of this._cancelHandlers) {
267
- handler();
268
- }
269
- } catch (error) {
270
- }
271
- }
272
- if (this._setCanceledCallback) {
273
- this._setCanceledCallback();
274
- }
275
- }
276
- this._destroy();
277
- return this;
278
- }
279
- _getTopParent() {
280
- let parent = this._parentPromise;
281
- let hasParent = !!parent;
282
- while (hasParent) {
283
- if (parent && parent._parentPromise) {
284
- parent = parent._parentPromise;
285
- hasParent = !!parent;
286
- } else {
287
- hasParent = false;
288
- }
289
- }
290
- return parent;
291
- }
292
- _destroy() {
293
- this._setCanceledCallback = void 0;
294
- this._cancelPromise = void 0;
295
- this._promise = void 0;
296
- }
297
- };
298
- __publicField$b(_CancelablePromise, "CancelError", CancelError);
299
- __publicField$b(_CancelablePromise, "TimeoutError", TimeoutError);
300
- __publicField$b(_CancelablePromise, "PromiseControl", PromiseControl);
301
- let CancelablePromise = _CancelablePromise;
302
- Object.setPrototypeOf(CancelablePromise.prototype, Promise.prototype);
303
-
1
+ /** Bundle of @nextgis/geocoder; version: 3.0.0-alpha.1; author: NextGIS */
304
2
  function defined(val) {
305
3
  return val !== void 0 && val !== null;
306
4
  }
@@ -406,28 +104,28 @@ class BaseGeocoder {
406
104
  }
407
105
  }
408
106
 
409
- var __defProp$c = Object.defineProperty;
107
+ var __defProp$d = Object.defineProperty;
410
108
  var __defProps$3 = Object.defineProperties;
411
109
  var __getOwnPropDescs$3 = Object.getOwnPropertyDescriptors;
412
- var __getOwnPropSymbols$5 = Object.getOwnPropertySymbols;
413
- var __hasOwnProp$5 = Object.prototype.hasOwnProperty;
414
- var __propIsEnum$5 = Object.prototype.propertyIsEnumerable;
110
+ var __getOwnPropSymbols$6 = Object.getOwnPropertySymbols;
111
+ var __hasOwnProp$6 = Object.prototype.hasOwnProperty;
112
+ var __propIsEnum$6 = Object.prototype.propertyIsEnumerable;
415
113
  var __knownSymbol$2 = (name, symbol) => (symbol = Symbol[name]) ? symbol : Symbol.for("Symbol." + name);
416
- var __defNormalProp$c = (obj, key, value) => key in obj ? __defProp$c(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
417
- var __spreadValues$5 = (a, b) => {
114
+ var __defNormalProp$d = (obj, key, value) => key in obj ? __defProp$d(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
115
+ var __spreadValues$6 = (a, b) => {
418
116
  for (var prop in b || (b = {}))
419
- if (__hasOwnProp$5.call(b, prop))
420
- __defNormalProp$c(a, prop, b[prop]);
421
- if (__getOwnPropSymbols$5)
422
- for (var prop of __getOwnPropSymbols$5(b)) {
423
- if (__propIsEnum$5.call(b, prop))
424
- __defNormalProp$c(a, prop, b[prop]);
117
+ if (__hasOwnProp$6.call(b, prop))
118
+ __defNormalProp$d(a, prop, b[prop]);
119
+ if (__getOwnPropSymbols$6)
120
+ for (var prop of __getOwnPropSymbols$6(b)) {
121
+ if (__propIsEnum$6.call(b, prop))
122
+ __defNormalProp$d(a, prop, b[prop]);
425
123
  }
426
124
  return a;
427
125
  };
428
126
  var __spreadProps$3 = (a, b) => __defProps$3(a, __getOwnPropDescs$3(b));
429
- var __publicField$a = (obj, key, value) => __defNormalProp$c(obj, key + "" , value);
430
- var __async$1 = (__this, __arguments, generator) => {
127
+ var __publicField$a = (obj, key, value) => __defNormalProp$d(obj, key + "" , value);
128
+ var __async$5 = (__this, __arguments, generator) => {
431
129
  return new Promise((resolve, reject) => {
432
130
  var fulfilled = (value) => {
433
131
  try {
@@ -491,7 +189,7 @@ class Geocoder extends BaseGeocoder {
491
189
  for (var iter = __forAwait(results), more, temp, error; more = !(temp = yield new __await$2(iter.next())).done; more = false) {
492
190
  const r = temp.value;
493
191
  allProvidersFailed = false;
494
- yield __spreadProps$3(__spreadValues$5({}, r), { provider, _id: ID$1++ });
192
+ yield __spreadProps$3(__spreadValues$6({}, r), { provider, _id: ID$1++ });
495
193
  }
496
194
  } catch (temp) {
497
195
  error = [temp];
@@ -521,7 +219,7 @@ class Geocoder extends BaseGeocoder {
521
219
  if (item.provider) {
522
220
  return item.provider.result(item);
523
221
  }
524
- return CancelablePromise.resolve(void 0);
222
+ return Promise.resolve(void 0);
525
223
  }
526
224
  reverse(coordinates) {
527
225
  return __asyncGenerator$2(this, null, function* () {
@@ -534,7 +232,7 @@ class Geocoder extends BaseGeocoder {
534
232
  try {
535
233
  for (var iter = __forAwait(results), more, temp, error; more = !(temp = yield new __await$2(iter.next())).done; more = false) {
536
234
  const r = temp.value;
537
- yield __spreadProps$3(__spreadValues$5({}, r), { provider, _id: ID$1++ });
235
+ yield __spreadProps$3(__spreadValues$6({}, r), { provider, _id: ID$1++ });
538
236
  }
539
237
  } catch (temp) {
540
238
  error = [temp];
@@ -558,7 +256,7 @@ class Geocoder extends BaseGeocoder {
558
256
  * @returns A promise that resolves to the first reverse geocoding result, or undefined if no results are found.
559
257
  */
560
258
  reverseGeocodeFirstResult(coordinates) {
561
- return __async$1(this, null, function* () {
259
+ return __async$5(this, null, function* () {
562
260
  for (const provider of this.providers) {
563
261
  if (typeof provider.reverse === "function") {
564
262
  try {
@@ -587,9 +285,9 @@ class Geocoder extends BaseGeocoder {
587
285
  }
588
286
  }
589
287
 
590
- var __defProp$b = Object.defineProperty;
591
- var __defNormalProp$b = (obj, key, value) => key in obj ? __defProp$b(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
592
- var __publicField$9 = (obj, key, value) => __defNormalProp$b(obj, typeof key !== "symbol" ? key + "" : key, value);
288
+ var __defProp$c = Object.defineProperty;
289
+ var __defNormalProp$c = (obj, key, value) => key in obj ? __defProp$c(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
290
+ var __publicField$9 = (obj, key, value) => __defNormalProp$c(obj, typeof key !== "symbol" ? key + "" : key, value);
593
291
  class BaseProvider extends BaseGeocoder {
594
292
  constructor() {
595
293
  super(...arguments);
@@ -1078,9 +776,9 @@ function unwrapListeners(arr) {
1078
776
  return ret;
1079
777
  }
1080
778
 
1081
- var __defProp$a = Object.defineProperty;
1082
- var __defNormalProp$a = (obj, key, value) => key in obj ? __defProp$a(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
1083
- var __publicField$8 = (obj, key, value) => __defNormalProp$a(obj, typeof key !== "symbol" ? key + "" : key, value);
779
+ var __defProp$b = Object.defineProperty;
780
+ var __defNormalProp$b = (obj, key, value) => key in obj ? __defProp$b(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
781
+ var __publicField$8 = (obj, key, value) => __defNormalProp$b(obj, typeof key !== "symbol" ? key + "" : key, value);
1084
782
  const _Cache = class _Cache {
1085
783
  constructor(options = {}) {
1086
784
  __publicField$8(this, "cache", []);
@@ -1116,8 +814,7 @@ const _Cache = class _Cache {
1116
814
  * // somewhere else in the code
1117
815
  * const item = await cache.addFull('foo', getItemFunc).then((resp) => {
1118
816
  * console.log(resp); // 'New item'
1119
- * })
1120
- *
817
+ * });
1121
818
  * ```
1122
819
  */
1123
820
  addFull(key, valueToSet, props) {
@@ -1132,13 +829,11 @@ const _Cache = class _Cache {
1132
829
  } else {
1133
830
  value = valueToSet;
1134
831
  }
1135
- const props_ = props && JSON.parse(JSON.stringify(objectRemoveEmpty(props)));
832
+ const nonEmptyProps = props && JSON.parse(JSON.stringify(objectRemoveEmpty(props)));
1136
833
  const cacheItem = {
1137
834
  key,
1138
835
  value,
1139
- props: props_,
1140
- // TODO: remove backward compatibility use only props
1141
- options: props_
836
+ props: nonEmptyProps
1142
837
  };
1143
838
  if (onlyFull && !full(value)) {
1144
839
  return value;
@@ -1147,7 +842,6 @@ const _Cache = class _Cache {
1147
842
  if (value instanceof Promise) {
1148
843
  value.catch((er) => {
1149
844
  this.delete(key, props);
1150
- throw er;
1151
845
  });
1152
846
  if (onlyFull) {
1153
847
  value.then((x) => {
@@ -1166,9 +860,7 @@ const _Cache = class _Cache {
1166
860
  }
1167
861
  match(key, props) {
1168
862
  const cacheRecord = this._find(key, props);
1169
- if (cacheRecord) {
1170
- return cacheRecord.value;
1171
- }
863
+ return cacheRecord == null ? void 0 : cacheRecord.value;
1172
864
  }
1173
865
  matchAll(key, props) {
1174
866
  if (key) {
@@ -1177,37 +869,30 @@ const _Cache = class _Cache {
1177
869
  return this.cache.map((x) => x.value);
1178
870
  }
1179
871
  delete(keyOrItem, props) {
1180
- let exist = [];
1181
- if (typeof keyOrItem === "string") {
1182
- exist = this.cache.filter((x) => this._filter(x, keyOrItem, props));
1183
- } else {
1184
- exist.push(keyOrItem);
1185
- }
1186
- for (const e of exist) {
1187
- const index = this.cache.indexOf(e);
1188
- this.cache.splice(index, 1);
872
+ const itemsToDelete = typeof keyOrItem === "string" ? this.cache.filter((x) => this._filter(x, keyOrItem, props)) : [keyOrItem];
873
+ for (const item of itemsToDelete) {
874
+ const index = this.cache.indexOf(item);
875
+ if (index !== -1) {
876
+ this.cache.splice(index, 1);
877
+ }
1189
878
  }
1190
879
  }
1191
880
  _find(key, props) {
1192
881
  return this.cache.find((x) => this._filter(x, key, props));
1193
882
  }
1194
883
  _filter(item, key, props) {
1195
- if (item.key === key) {
1196
- if (props) {
1197
- const itemProps = item.props || item.options;
1198
- return objectDeepEqual(itemProps || {}, objectRemoveEmpty(props));
1199
- }
1200
- return true;
1201
- }
1202
- return false;
884
+ if (item.key !== key) return false;
885
+ if (!props) return true;
886
+ const itemProps = item.props;
887
+ return objectDeepEqual(itemProps || {}, objectRemoveEmpty(props));
1203
888
  }
1204
889
  };
1205
890
  __publicField$8(_Cache, "instance", {});
1206
891
  let Cache = _Cache;
1207
892
 
1208
- var __defProp$9 = Object.defineProperty;
1209
- var __defNormalProp$9 = (obj, key, value) => key in obj ? __defProp$9(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
1210
- var __publicField$7 = (obj, key, value) => __defNormalProp$9(obj, typeof key !== "symbol" ? key + "" : key, value);
893
+ var __defProp$a = Object.defineProperty;
894
+ var __defNormalProp$a = (obj, key, value) => key in obj ? __defProp$a(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
895
+ var __publicField$7 = (obj, key, value) => __defNormalProp$a(obj, typeof key !== "symbol" ? key + "" : key, value);
1211
896
  class NgwError extends Error {
1212
897
  constructor(er) {
1213
898
  super();
@@ -1224,9 +909,9 @@ class NgwError extends Error {
1224
909
  }
1225
910
  }
1226
911
 
1227
- var __defProp$8 = Object.defineProperty;
1228
- var __defNormalProp$8 = (obj, key, value) => key in obj ? __defProp$8(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
1229
- var __publicField$6 = (obj, key, value) => __defNormalProp$8(obj, typeof key !== "symbol" ? key + "" : key, value);
912
+ var __defProp$9 = Object.defineProperty;
913
+ var __defNormalProp$9 = (obj, key, value) => key in obj ? __defProp$9(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
914
+ var __publicField$6 = (obj, key, value) => __defNormalProp$9(obj, typeof key !== "symbol" ? key + "" : key, value);
1230
915
  class ResourceNotFoundError extends NgwError {
1231
916
  constructor(obj) {
1232
917
  super(obj);
@@ -1265,27 +950,24 @@ function resourceToQuery(resource, prefix = "") {
1265
950
  return query;
1266
951
  }
1267
952
 
1268
- var __defProp$7 = Object.defineProperty;
1269
- var __defProps$2 = Object.defineProperties;
1270
- var __getOwnPropDescs$2 = Object.getOwnPropertyDescriptors;
1271
- var __getOwnPropSymbols$4 = Object.getOwnPropertySymbols;
1272
- var __hasOwnProp$4 = Object.prototype.hasOwnProperty;
1273
- var __propIsEnum$4 = Object.prototype.propertyIsEnumerable;
1274
- var __defNormalProp$7 = (obj, key, value) => key in obj ? __defProp$7(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
1275
- var __spreadValues$4 = (a, b) => {
953
+ var __defProp$8 = Object.defineProperty;
954
+ var __getOwnPropSymbols$5 = Object.getOwnPropertySymbols;
955
+ var __hasOwnProp$5 = Object.prototype.hasOwnProperty;
956
+ var __propIsEnum$5 = Object.prototype.propertyIsEnumerable;
957
+ var __defNormalProp$8 = (obj, key, value) => key in obj ? __defProp$8(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
958
+ var __spreadValues$5 = (a, b) => {
1276
959
  for (var prop in b || (b = {}))
1277
- if (__hasOwnProp$4.call(b, prop))
1278
- __defNormalProp$7(a, prop, b[prop]);
1279
- if (__getOwnPropSymbols$4)
1280
- for (var prop of __getOwnPropSymbols$4(b)) {
1281
- if (__propIsEnum$4.call(b, prop))
1282
- __defNormalProp$7(a, prop, b[prop]);
960
+ if (__hasOwnProp$5.call(b, prop))
961
+ __defNormalProp$8(a, prop, b[prop]);
962
+ if (__getOwnPropSymbols$5)
963
+ for (var prop of __getOwnPropSymbols$5(b)) {
964
+ if (__propIsEnum$5.call(b, prop))
965
+ __defNormalProp$8(a, prop, b[prop]);
1283
966
  }
1284
967
  return a;
1285
968
  };
1286
- var __spreadProps$2 = (a, b) => __defProps$2(a, __getOwnPropDescs$2(b));
1287
- var __publicField$5 = (obj, key, value) => __defNormalProp$7(obj, typeof key !== "symbol" ? key + "" : key, value);
1288
- var __async = (__this, __arguments, generator) => {
969
+ var __publicField$5 = (obj, key, value) => __defNormalProp$8(obj, typeof key !== "symbol" ? key + "" : key, value);
970
+ var __async$4 = (__this, __arguments, generator) => {
1289
971
  return new Promise((resolve, reject) => {
1290
972
  var fulfilled = (value) => {
1291
973
  try {
@@ -1326,39 +1008,27 @@ class ResourcesControl {
1326
1008
  * Fetching resource would be cached to speed up next call
1327
1009
  */
1328
1010
  getOne(resource, requestOptions) {
1329
- const cache = this.cache;
1330
- const forCache = {};
1331
- const opt = __spreadProps$2(__spreadValues$4({}, requestOptions), { cache: false });
1332
- if (typeof resource === "string") {
1333
- forCache.keyname = resource;
1334
- } else if (typeof resource === "number") {
1335
- forCache.id = resource;
1336
- } else if (isObject(resource)) {
1011
+ const opt = __spreadValues$5({}, requestOptions);
1012
+ if (typeof resource === "string") ; else if (typeof resource === "number") ; else if (isObject(resource)) {
1337
1013
  if (resource.id !== void 0) {
1338
- forCache.id = resource.id;
1014
+ resource.id;
1339
1015
  } else {
1340
1016
  if (resource.keyname) {
1341
- forCache.keyname = resource.keyname;
1017
+ resource.keyname;
1342
1018
  }
1343
1019
  if (resource.display_name) {
1344
- forCache.display_name = resource.display_name;
1020
+ resource.display_name;
1345
1021
  }
1346
1022
  }
1347
1023
  }
1348
- const makeRequest = () => {
1349
- if (typeof resource === "string") {
1350
- return this._fetchResourceBy({ keyname: resource }, opt);
1351
- } else if (typeof resource === "number") {
1352
- return this._fetchResourceById(resource, opt);
1353
- } else if (isObject(resource)) {
1354
- return this._fetchResourceBy(resource, opt);
1355
- }
1356
- return CancelablePromise.resolve(void 0);
1357
- };
1358
- if (requestOptions == null ? void 0 : requestOptions.cache) {
1359
- return cache.addFull("resource", makeRequest, forCache);
1024
+ if (typeof resource === "string") {
1025
+ return this._fetchResourceBy({ keyname: resource }, opt);
1026
+ } else if (typeof resource === "number") {
1027
+ return this._fetchResourceById(resource, opt);
1028
+ } else if (isObject(resource)) {
1029
+ return this._fetchResourceBy(resource, opt);
1360
1030
  }
1361
- return makeRequest();
1031
+ return Promise.resolve(void 0);
1362
1032
  }
1363
1033
  getOneOrFail(resource, requestOptions) {
1364
1034
  return this.getOne(resource, requestOptions).then((res) => {
@@ -1380,7 +1050,7 @@ class ResourcesControl {
1380
1050
  */
1381
1051
  getId(resource, requestOptions) {
1382
1052
  if (typeof resource === "number") {
1383
- return CancelablePromise.resolve(resource);
1053
+ return Promise.resolve(resource);
1384
1054
  } else if (typeof resource === "string" || isObject(resource)) {
1385
1055
  return this.getOne(resource, requestOptions).then((res) => {
1386
1056
  if (res) {
@@ -1388,7 +1058,7 @@ class ResourcesControl {
1388
1058
  }
1389
1059
  });
1390
1060
  }
1391
- return CancelablePromise.resolve(void 0);
1061
+ return Promise.resolve(void 0);
1392
1062
  }
1393
1063
  /**
1394
1064
  * A fast way to retrieve resource ID for any resource definition.
@@ -1415,12 +1085,12 @@ class ResourcesControl {
1415
1085
  } else {
1416
1086
  Object.assign(query, resourceToQuery(resource));
1417
1087
  }
1418
- return this.connector.get("resource.search", requestOptions, __spreadValues$4({
1088
+ return this.connector.get("resource.search", requestOptions, __spreadValues$5({
1419
1089
  serialization: "full"
1420
1090
  }, query)).then((resources) => {
1421
- if (resources) {
1091
+ if ((requestOptions == null ? void 0 : requestOptions.cache) && resources) {
1422
1092
  for (const x of resources) {
1423
- this.cache.add("resource.item", CancelablePromise.resolve(x), {
1093
+ this.cache.add("resource.item", Promise.resolve(x), {
1424
1094
  id: x.resource.id
1425
1095
  });
1426
1096
  }
@@ -1436,7 +1106,7 @@ class ResourcesControl {
1436
1106
  if (child) {
1437
1107
  return this.getOne(child.resource.parent.id, requestOptions);
1438
1108
  }
1439
- return CancelablePromise.resolve(void 0);
1109
+ return Promise.resolve(void 0);
1440
1110
  });
1441
1111
  }
1442
1112
  getChildrenOf(resource, requestOptions) {
@@ -1466,18 +1136,16 @@ class ResourcesControl {
1466
1136
  });
1467
1137
  }
1468
1138
  _getChildrenOf(parent, requestOptions, _items = []) {
1469
- return this.connector.get(
1470
- "resource.collection",
1471
- __spreadValues$4({ cache: true }, requestOptions),
1472
- {
1473
- parent
1474
- }
1475
- ).then((items) => {
1139
+ return this.connector.get("resource.collection", requestOptions, {
1140
+ parent
1141
+ }).then((items) => {
1476
1142
  const recursivePromises = [];
1477
1143
  for (const item of items) {
1478
- this.cache.add("resource.item", CancelablePromise.resolve(item), {
1479
- id: item.resource.id
1480
- });
1144
+ if (requestOptions == null ? void 0 : requestOptions.cache) {
1145
+ this.cache.add("resource.item", Promise.resolve(item), {
1146
+ id: item.resource.id
1147
+ });
1148
+ }
1481
1149
  _items.push(item);
1482
1150
  if ((requestOptions == null ? void 0 : requestOptions.recursive) && item.resource.children) {
1483
1151
  recursivePromises.push(
@@ -1486,7 +1154,7 @@ class ResourcesControl {
1486
1154
  }
1487
1155
  }
1488
1156
  if (recursivePromises.length) {
1489
- return CancelablePromise.all(recursivePromises).then(() => {
1157
+ return Promise.all(recursivePromises).then(() => {
1490
1158
  return _items;
1491
1159
  });
1492
1160
  }
@@ -1494,11 +1162,12 @@ class ResourcesControl {
1494
1162
  });
1495
1163
  }
1496
1164
  _cleanResourceItemCache(id) {
1497
- return __async(this, null, function* () {
1165
+ return __async$4(this, null, function* () {
1166
+ var _a;
1498
1167
  const all = this.cache.all();
1499
1168
  const toDelete = [];
1500
1169
  for (const c of all) {
1501
- const cid = c.options && c.options.id;
1170
+ const cid = (_a = c.props) == null ? void 0 : _a.id;
1502
1171
  if (["resource.item", "resource"].includes(c.key) && cid !== void 0) {
1503
1172
  if (typeof cid === "number") {
1504
1173
  if (cid === id) {
@@ -1518,18 +1187,7 @@ class ResourcesControl {
1518
1187
  });
1519
1188
  }
1520
1189
  _fetchResourceById(id, requestOptions) {
1521
- const promise = () => this.connector.get("resource.item", requestOptions, { id });
1522
- if (requestOptions == null ? void 0 : requestOptions.cache) {
1523
- return this.cache.add("resource.item", promise, {
1524
- id
1525
- }).catch((er) => {
1526
- if (!(er instanceof ResourceNotFoundError)) {
1527
- throw er;
1528
- }
1529
- return void 0;
1530
- });
1531
- }
1532
- return promise();
1190
+ return this.connector.get("resource.item", requestOptions, { id });
1533
1191
  }
1534
1192
  _fetchResourceBy(resource, requestOptions) {
1535
1193
  return this.getMany(resource, requestOptions).then((resources) => {
@@ -1537,7 +1195,7 @@ class ResourcesControl {
1537
1195
  });
1538
1196
  }
1539
1197
  _resourceCacheFilter(resource) {
1540
- return CancelablePromise.all(this.cache.matchAll("resource.item")).then(
1198
+ return Promise.all(this.cache.matchAll("resource.item")).then(
1541
1199
  (resources) => {
1542
1200
  const items = [];
1543
1201
  resources.filter((x) => {
@@ -1581,9 +1239,16 @@ function removeConnector(connector) {
1581
1239
  }
1582
1240
  }
1583
1241
 
1584
- var __defProp$6 = Object.defineProperty;
1585
- var __defNormalProp$6 = (obj, key, value) => key in obj ? __defProp$6(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
1586
- var __publicField$4 = (obj, key, value) => __defNormalProp$6(obj, typeof key !== "symbol" ? key + "" : key, value);
1242
+ class AbortError extends Error {
1243
+ constructor(message = "AbortError") {
1244
+ super(message);
1245
+ this.name = "AbortError";
1246
+ }
1247
+ }
1248
+
1249
+ var __defProp$7 = Object.defineProperty;
1250
+ var __defNormalProp$7 = (obj, key, value) => key in obj ? __defProp$7(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
1251
+ var __publicField$4 = (obj, key, value) => __defNormalProp$7(obj, typeof key !== "symbol" ? key + "" : key, value);
1587
1252
  class InsufficientPermissionsError extends NgwError {
1588
1253
  constructor(obj) {
1589
1254
  super(obj);
@@ -1606,58 +1271,90 @@ function template(str, data) {
1606
1271
  });
1607
1272
  }
1608
1273
 
1274
+ var __defProp$6 = Object.defineProperty;
1275
+ var __getOwnPropSymbols$4 = Object.getOwnPropertySymbols;
1276
+ var __hasOwnProp$4 = Object.prototype.hasOwnProperty;
1277
+ var __propIsEnum$4 = Object.prototype.propertyIsEnumerable;
1278
+ var __defNormalProp$6 = (obj, key, value) => key in obj ? __defProp$6(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
1279
+ var __spreadValues$4 = (a, b) => {
1280
+ for (var prop in b || (b = {}))
1281
+ if (__hasOwnProp$4.call(b, prop))
1282
+ __defNormalProp$6(a, prop, b[prop]);
1283
+ if (__getOwnPropSymbols$4)
1284
+ for (var prop of __getOwnPropSymbols$4(b)) {
1285
+ if (__propIsEnum$4.call(b, prop))
1286
+ __defNormalProp$6(a, prop, b[prop]);
1287
+ }
1288
+ return a;
1289
+ };
1290
+ var __async$3 = (__this, __arguments, generator) => {
1291
+ return new Promise((resolve, reject) => {
1292
+ var fulfilled = (value) => {
1293
+ try {
1294
+ step(generator.next(value));
1295
+ } catch (e) {
1296
+ reject(e);
1297
+ }
1298
+ };
1299
+ var rejected = (value) => {
1300
+ try {
1301
+ step(generator.throw(value));
1302
+ } catch (e) {
1303
+ reject(e);
1304
+ }
1305
+ };
1306
+ var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
1307
+ step((generator = generator.apply(__this, __arguments)).next());
1308
+ });
1309
+ };
1609
1310
  function apiRequest(opt) {
1610
- const params = opt.params;
1611
- return new CancelablePromise((resolve, reject) => {
1612
- return opt.connector.connect().then((apiItems) => {
1613
- let apiItem = apiItems && apiItems[opt.name];
1614
- if (apiItem) {
1615
- apiItem = [...apiItem];
1616
- let url = apiItem.shift();
1617
- if (apiItem.length) {
1618
- const replaceParams = {};
1619
- for (let fry = 0; fry < apiItem.length; fry++) {
1620
- const arg = apiItem[fry];
1621
- replaceParams[fry] = "{" + arg + "}";
1622
- if (params[arg] === void 0) {
1623
- throw new Error(
1624
- "`" + arg + "` url api argument is not specified"
1625
- );
1626
- }
1627
- }
1628
- if (url) {
1629
- url = template(url, replaceParams);
1311
+ return __async$3(this, null, function* () {
1312
+ const { params, name, connector, requestOptions } = opt;
1313
+ const apiItems = yield connector.connect();
1314
+ let apiItem = apiItems && apiItems[name];
1315
+ if (apiItem) {
1316
+ apiItem = [...apiItem];
1317
+ let url = apiItem.shift();
1318
+ if (apiItem.length) {
1319
+ const replaceParams = {};
1320
+ for (let fry = 0; fry < apiItem.length; fry++) {
1321
+ const arg = apiItem[fry];
1322
+ replaceParams[fry] = `{${arg}}`;
1323
+ if (params[arg] === void 0) {
1324
+ throw new Error(`\`${arg}\` URL API argument is not specified`);
1630
1325
  }
1631
1326
  }
1632
- if (params) {
1633
- const paramArray = [];
1634
- const paramList = params.paramList;
1635
- if (Array.isArray(paramList)) {
1636
- delete params.paramList;
1637
- paramList.forEach((x) => {
1638
- paramArray.push(`${x[0]}=${x[1]}`);
1639
- });
1640
- }
1641
- for (const p in params) {
1642
- if (apiItem.indexOf(p) === -1) {
1643
- paramArray.push(`${p}=${params[p]}`);
1644
- }
1645
- }
1646
- if (paramArray.length) {
1647
- url = url + "?" + paramArray.join("&");
1327
+ if (url) {
1328
+ url = template(url, replaceParams);
1329
+ }
1330
+ }
1331
+ if (params) {
1332
+ const paramArray = [];
1333
+ const paramList = params.paramList;
1334
+ if (Array.isArray(paramList)) {
1335
+ paramList.forEach(([key, value]) => {
1336
+ paramArray.push(`${key}=${value}`);
1337
+ });
1338
+ }
1339
+ for (const p in params) {
1340
+ if (apiItem.indexOf(p) === -1) {
1341
+ paramArray.push(`${p}=${params[p]}`);
1648
1342
  }
1649
1343
  }
1650
- if (url) {
1651
- resolve(opt.connector.makeQuery(url, params, opt.requestOptions));
1652
- } else {
1653
- reject(new Error("request url is not set"));
1344
+ if (paramArray.length) {
1345
+ url = `${url}?${paramArray.join("&")}`;
1654
1346
  }
1347
+ }
1348
+ if (url) {
1349
+ return connector.makeQuery(url, params, __spreadValues$4({
1350
+ cacheName: name
1351
+ }, requestOptions));
1655
1352
  } else {
1656
- resolve(void 0);
1353
+ throw new Error("Request URL is not set");
1657
1354
  }
1658
- }).catch((er) => {
1659
- reject(er);
1660
- });
1355
+ } else {
1356
+ return void 0;
1357
+ }
1661
1358
  });
1662
1359
  }
1663
1360
 
@@ -1757,6 +1454,8 @@ let loadData;
1757
1454
  }
1758
1455
 
1759
1456
  var __defProp$4 = Object.defineProperty;
1457
+ var __defProps$2 = Object.defineProperties;
1458
+ var __getOwnPropDescs$2 = Object.getOwnPropertyDescriptors;
1760
1459
  var __getOwnPropSymbols$3 = Object.getOwnPropertySymbols;
1761
1460
  var __hasOwnProp$3 = Object.prototype.hasOwnProperty;
1762
1461
  var __propIsEnum$3 = Object.prototype.propertyIsEnumerable;
@@ -1772,8 +1471,42 @@ var __spreadValues$3 = (a, b) => {
1772
1471
  }
1773
1472
  return a;
1774
1473
  };
1474
+ var __spreadProps$2 = (a, b) => __defProps$2(a, __getOwnPropDescs$2(b));
1475
+ var __objRest = (source, exclude) => {
1476
+ var target = {};
1477
+ for (var prop in source)
1478
+ if (__hasOwnProp$3.call(source, prop) && exclude.indexOf(prop) < 0)
1479
+ target[prop] = source[prop];
1480
+ if (source != null && __getOwnPropSymbols$3)
1481
+ for (var prop of __getOwnPropSymbols$3(source)) {
1482
+ if (exclude.indexOf(prop) < 0 && __propIsEnum$3.call(source, prop))
1483
+ target[prop] = source[prop];
1484
+ }
1485
+ return target;
1486
+ };
1775
1487
  var __publicField$2 = (obj, key, value) => __defNormalProp$4(obj, typeof key !== "symbol" ? key + "" : key, value);
1488
+ var __async$2 = (__this, __arguments, generator) => {
1489
+ return new Promise((resolve, reject) => {
1490
+ var fulfilled = (value) => {
1491
+ try {
1492
+ step(generator.next(value));
1493
+ } catch (e) {
1494
+ reject(e);
1495
+ }
1496
+ };
1497
+ var rejected = (value) => {
1498
+ try {
1499
+ step(generator.throw(value));
1500
+ } catch (e) {
1501
+ reject(e);
1502
+ }
1503
+ };
1504
+ var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
1505
+ step((generator = generator.apply(__this, __arguments)).next());
1506
+ });
1507
+ };
1776
1508
  let ID = 0;
1509
+ let REQUEST_ID = 0;
1777
1510
  class NgwConnector {
1778
1511
  constructor(options) {
1779
1512
  this.options = options;
@@ -1784,7 +1517,7 @@ class NgwConnector {
1784
1517
  __publicField$2(this, "cache");
1785
1518
  __publicField$2(this, "withCredentials");
1786
1519
  __publicField$2(this, "routeStr", "/api/component/pyramid/route");
1787
- __publicField$2(this, "activeRequests", []);
1520
+ __publicField$2(this, "activeRequests", {});
1788
1521
  __publicField$2(this, "requestTransform");
1789
1522
  const exist = findConnector(options);
1790
1523
  this.cache = new Cache({ namespace: options.cacheId });
@@ -1845,29 +1578,27 @@ class NgwConnector {
1845
1578
  * ```
1846
1579
  */
1847
1580
  connect() {
1848
- const auth = this.options.auth;
1849
- const makeConnect = () => new CancelablePromise((resolve, reject) => {
1850
- const makeQuery = () => {
1851
- return this.makeQuery(this.routeStr, {}, {}).then((route) => {
1852
- resolve(route);
1853
- }).catch((er) => {
1854
- reject(er);
1855
- });
1856
- };
1581
+ return __async$2(this, null, function* () {
1582
+ const auth = this.options.auth;
1857
1583
  if (auth) {
1858
1584
  const { login, password } = auth;
1859
1585
  if (login && password) {
1860
- return this._login({ login, password }).then(() => {
1861
- return makeQuery();
1862
- }).catch((er) => reject(er));
1586
+ yield this._login({ login, password });
1863
1587
  }
1864
1588
  }
1865
- return makeQuery();
1866
- });
1867
- return this.cache.add("route", makeConnect, {
1868
- id: this.id,
1869
- auth,
1870
- baseUrl: this.options.baseUrl
1589
+ return yield this.makeQuery(
1590
+ this.routeStr,
1591
+ {},
1592
+ {
1593
+ cacheName: "route",
1594
+ cache: true,
1595
+ cacheProps: {
1596
+ id: this.id,
1597
+ auth,
1598
+ baseUrl: this.options.baseUrl
1599
+ }
1600
+ }
1601
+ );
1871
1602
  });
1872
1603
  }
1873
1604
  /**
@@ -1891,20 +1622,22 @@ class NgwConnector {
1891
1622
  this.emitter.emit("logout");
1892
1623
  }
1893
1624
  getUserInfo(credentials, options) {
1894
- if (this.user && this.user.id) {
1895
- return CancelablePromise.resolve(this.user);
1896
- }
1897
- if (credentials) {
1898
- this.options.auth = credentials;
1899
- }
1900
- const options_ = __spreadValues$3({
1901
- headers: this.getAuthorizationHeaders(credentials)
1902
- }, options);
1903
- return this.makeQuery(
1904
- "/api/component/auth/current_user",
1905
- {},
1906
- options_
1907
- );
1625
+ return __async$2(this, null, function* () {
1626
+ if (this.user && this.user.id) {
1627
+ return this.user;
1628
+ }
1629
+ if (credentials) {
1630
+ this.options.auth = credentials;
1631
+ }
1632
+ const options_ = __spreadValues$3({
1633
+ headers: this.getAuthorizationHeaders(credentials)
1634
+ }, options);
1635
+ return this.makeQuery(
1636
+ "/api/component/auth/current_user",
1637
+ {},
1638
+ options_
1639
+ );
1640
+ });
1908
1641
  }
1909
1642
  /**
1910
1643
  * Obtaining the required Headers for authentication of requests in the NGW.
@@ -1913,7 +1646,7 @@ class NgwConnector {
1913
1646
  const client = this.makeClientId(credentials);
1914
1647
  if (client) {
1915
1648
  return {
1916
- Authorization: "Basic " + client
1649
+ Authorization: `Basic ${client}`
1917
1650
  };
1918
1651
  }
1919
1652
  }
@@ -1921,21 +1654,22 @@ class NgwConnector {
1921
1654
  credentials = credentials || this.options.auth;
1922
1655
  if (credentials) {
1923
1656
  const { login, password } = credentials;
1924
- const str = unescape(encodeURIComponent(`${login}:${password}`));
1657
+ const str = `${login}:${password}`;
1658
+ const encodedStr = encodeURIComponent(str);
1925
1659
  {
1926
- return window.btoa(str);
1660
+ return window.btoa(encodedStr);
1927
1661
  }
1928
1662
  }
1929
1663
  }
1930
1664
  /** Stop all api requests */
1931
1665
  abort() {
1932
- for (const req of this.activeRequests) {
1933
- req.cancel();
1666
+ for (const abortController of Object.values(this.activeRequests)) {
1667
+ abortController.abort();
1934
1668
  }
1935
- this.activeRequests = [];
1669
+ this.activeRequests = {};
1936
1670
  }
1937
1671
  getActiveApiRequests() {
1938
- return [...this.activeRequests];
1672
+ return __spreadValues$3({}, this.activeRequests);
1939
1673
  }
1940
1674
  /**
1941
1675
  * Send request to NGW api router.
@@ -1967,26 +1701,10 @@ class NgwConnector {
1967
1701
  * ```
1968
1702
  */
1969
1703
  apiRequest(name, params_ = {}, requestOptions = {}) {
1970
- var _a, _b;
1971
- requestOptions = __spreadValues$3({
1972
- withCredentials: this.withCredentials
1973
- }, requestOptions);
1974
- const { method, headers, withCredentials, responseType } = requestOptions;
1704
+ var _a;
1975
1705
  params_ = (_a = requestOptions.params) != null ? _a : params_;
1976
1706
  const params = objectRemoveEmpty(params_);
1977
- const makeApiRequest = () => apiRequest({ name, params, requestOptions, connector: this });
1978
- if (requestOptions.cache && method === "GET") {
1979
- return this.cache.add(name, makeApiRequest, __spreadValues$3({
1980
- params
1981
- }, objectRemoveEmpty({
1982
- headers,
1983
- withCredentials,
1984
- responseType,
1985
- baseUrl: this.options.baseUrl,
1986
- userId: (_b = this.user) == null ? void 0 : _b.id
1987
- })));
1988
- }
1989
- return makeApiRequest();
1707
+ return apiRequest({ name, params, requestOptions, connector: this });
1990
1708
  }
1991
1709
  /**
1992
1710
  * Shortcut method for send POST request to NGW.
@@ -2076,17 +1794,68 @@ class NgwConnector {
2076
1794
  * @param params - Query params
2077
1795
  * @param options - Request options
2078
1796
  */
2079
- makeQuery(url, params, options = {}) {
2080
- url = (this.options.baseUrl ? this.options.baseUrl : "") + url;
2081
- if (url) {
1797
+ makeQuery(_0, _1) {
1798
+ return __async$2(this, arguments, function* (url, params, options = {}) {
1799
+ var _b;
1800
+ url = (this.options.baseUrl ? this.options.baseUrl : "") + url;
1801
+ if (!url) {
1802
+ throw new Error("Empty `url` not allowed");
1803
+ }
2082
1804
  if (params) {
2083
- url = template(url, params);
1805
+ const _a = params, restParams = __objRest(_a, ["paramList"]);
1806
+ url = template(url, restParams);
2084
1807
  }
2085
1808
  url = encodeURI(fixUrlStr(url));
2086
- return this._loadData(url, options);
2087
- } else {
2088
- throw new Error("Empty `url` not allowed");
2089
- }
1809
+ options = __spreadValues$3({ withCredentials: this.withCredentials }, options);
1810
+ const {
1811
+ cache,
1812
+ signal: externalSignal,
1813
+ method = "GET",
1814
+ headers,
1815
+ cacheName,
1816
+ cacheProps,
1817
+ responseType,
1818
+ withCredentials
1819
+ } = options;
1820
+ const internalAbortController = new AbortController();
1821
+ const internalSignal = internalAbortController.signal;
1822
+ if (externalSignal) {
1823
+ if (externalSignal.aborted) {
1824
+ throw new AbortError();
1825
+ }
1826
+ externalSignal.addEventListener("abort", () => {
1827
+ internalAbortController.abort();
1828
+ });
1829
+ }
1830
+ options.signal = internalSignal;
1831
+ const createPromise = () => __async$2(this, null, function* () {
1832
+ const id = REQUEST_ID++;
1833
+ this.activeRequests[id] = internalAbortController;
1834
+ try {
1835
+ return this._loadData(url, options);
1836
+ } finally {
1837
+ this._cleanActiveRequest(id);
1838
+ }
1839
+ });
1840
+ if (cache && method === "GET") {
1841
+ const cacheOptions = cacheProps ? cacheProps : __spreadProps$2(__spreadValues$3({}, objectRemoveEmpty({
1842
+ headers,
1843
+ withCredentials,
1844
+ responseType,
1845
+ baseUrl: this.options.baseUrl,
1846
+ userId: (_b = this.user) == null ? void 0 : _b.id
1847
+ })), {
1848
+ params
1849
+ });
1850
+ return this.cache.add(
1851
+ cacheName || url,
1852
+ createPromise,
1853
+ cacheOptions,
1854
+ false
1855
+ );
1856
+ }
1857
+ return createPromise();
1858
+ });
2090
1859
  }
2091
1860
  // -------------------------------------------------------------------------
2092
1861
  // Resource Methods
@@ -2168,10 +1937,8 @@ class NgwConnector {
2168
1937
  */
2169
1938
  _loadData(url, options) {
2170
1939
  options.responseType = options.responseType || "json";
2171
- if (options.signal && options.signal.aborted) {
2172
- return CancelablePromise.reject(new CancelablePromise.CancelError());
2173
- }
2174
- const request = new CancelablePromise((resolve, reject, onCancel) => {
1940
+ return new Promise((resolve, reject) => {
1941
+ var _a;
2175
1942
  if (this.user) {
2176
1943
  options = options || {};
2177
1944
  options.headers = __spreadValues$3(__spreadValues$3({}, this.getAuthorizationHeaders()), options.headers);
@@ -2181,13 +1948,18 @@ class NgwConnector {
2181
1948
  url = transUrl;
2182
1949
  options = transOptions;
2183
1950
  }
2184
- loadData(url, resolve, options, reject, onCancel);
2185
- }).then((resp) => {
2186
- this._cleanActiveRequests(request);
2187
- return resp;
1951
+ let runOnAbort = void 0;
1952
+ loadData(url, resolve, options, reject, (handler) => {
1953
+ runOnAbort = handler;
1954
+ });
1955
+ (_a = options.signal) == null ? void 0 : _a.addEventListener("abort", () => {
1956
+ if (runOnAbort !== void 0) {
1957
+ runOnAbort();
1958
+ }
1959
+ reject(new AbortError());
1960
+ });
2188
1961
  }).catch((httpError) => {
2189
- this._cleanActiveRequests(request);
2190
- if (httpError instanceof CancelablePromise.CancelError) ; else {
1962
+ if (httpError.name !== "AbortError") {
2191
1963
  {
2192
1964
  console.warn("DEV WARN", httpError);
2193
1965
  }
@@ -2196,31 +1968,24 @@ class NgwConnector {
2196
1968
  throw er;
2197
1969
  }
2198
1970
  }
1971
+ throw httpError;
2199
1972
  });
2200
- if (options.signal && typeof options.signal.addEventListener === "function") {
2201
- options.signal.addEventListener("abort", () => {
2202
- request.cancel();
2203
- this._cleanActiveRequests(request);
2204
- });
2205
- }
2206
- this.activeRequests.push(request);
2207
- return request;
2208
1973
  }
2209
1974
  _login(credentials, options) {
2210
- return this.getUserInfo(credentials, options).then((data) => {
2211
- this.user = data;
2212
- this.emitter.emit("login", data);
2213
- return data;
2214
- }).catch((er) => {
2215
- this.emitter.emit("login:error", er);
2216
- throw er;
1975
+ return __async$2(this, null, function* () {
1976
+ try {
1977
+ const data = yield this.getUserInfo(credentials, options);
1978
+ this.user = data;
1979
+ this.emitter.emit("login", data);
1980
+ return data;
1981
+ } catch (er) {
1982
+ this.emitter.emit("login:error", er);
1983
+ throw er;
1984
+ }
2217
1985
  });
2218
1986
  }
2219
- _cleanActiveRequests(request) {
2220
- const activeRequestIndex = this.activeRequests.indexOf(request);
2221
- if (activeRequestIndex !== -1) {
2222
- this.activeRequests.splice(activeRequestIndex, 1);
2223
- }
1987
+ _cleanActiveRequest(requestId) {
1988
+ delete this.activeRequests[requestId];
2224
1989
  }
2225
1990
  _handleHttpError(er) {
2226
1991
  if (er) {
@@ -2329,6 +2094,26 @@ var __spreadValues$2 = (a, b) => {
2329
2094
  return a;
2330
2095
  };
2331
2096
  var __spreadProps$1 = (a, b) => __defProps$1(a, __getOwnPropDescs$1(b));
2097
+ var __async$1 = (__this, __arguments, generator) => {
2098
+ return new Promise((resolve, reject) => {
2099
+ var fulfilled = (value) => {
2100
+ try {
2101
+ step(generator.next(value));
2102
+ } catch (e) {
2103
+ reject(e);
2104
+ }
2105
+ };
2106
+ var rejected = (value) => {
2107
+ try {
2108
+ step(generator.throw(value));
2109
+ } catch (e) {
2110
+ reject(e);
2111
+ }
2112
+ };
2113
+ var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
2114
+ step((generator = generator.apply(__this, __arguments)).next());
2115
+ });
2116
+ };
2332
2117
  const FEATURE_REQUEST_PARAMS = {
2333
2118
  srs: 4326,
2334
2119
  geom_format: "geojson"
@@ -2359,10 +2144,9 @@ function updateItemRequestParam(params, options) {
2359
2144
  }
2360
2145
  }
2361
2146
  function createFeatureFieldFilterQueries(opt) {
2362
- const queries = getQueries(
2363
- opt
2364
- );
2365
- return CancelablePromise.all(queries).then((itemsParts) => {
2147
+ return __async$1(this, null, function* () {
2148
+ const queries = getQueries(opt);
2149
+ const itemsParts = yield Promise.all(queries);
2366
2150
  const ids = [];
2367
2151
  const items = [];
2368
2152
  for (const part of itemsParts) {
@@ -2550,13 +2334,34 @@ var __spreadValues$1 = (a, b) => {
2550
2334
  return a;
2551
2335
  };
2552
2336
  var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
2337
+ var __async = (__this, __arguments, generator) => {
2338
+ return new Promise((resolve, reject) => {
2339
+ var fulfilled = (value) => {
2340
+ try {
2341
+ step(generator.next(value));
2342
+ } catch (e) {
2343
+ reject(e);
2344
+ }
2345
+ };
2346
+ var rejected = (value) => {
2347
+ try {
2348
+ step(generator.throw(value));
2349
+ } catch (e) {
2350
+ reject(e);
2351
+ }
2352
+ };
2353
+ var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
2354
+ step((generator = generator.apply(__this, __arguments)).next());
2355
+ });
2356
+ };
2553
2357
  function fetchNgwLayerItems(options) {
2554
- const filters = options.filters;
2555
- if (filters) {
2556
- return createFeatureFieldFilterQueries(__spreadProps(__spreadValues$1({}, options), {
2557
- filters
2558
- })).then((data) => {
2559
- var _a;
2358
+ return __async(this, null, function* () {
2359
+ var _a;
2360
+ const filters = options.filters;
2361
+ if (filters) {
2362
+ let data = yield createFeatureFieldFilterQueries(__spreadProps(__spreadValues$1({}, options), {
2363
+ filters
2364
+ }));
2560
2365
  const clientFilterValidate = (_a = options.clientFilterValidate) != null ? _a : isFilterWithAnyCase(filters);
2561
2366
  if (clientFilterValidate) {
2562
2367
  data = data.filter((y) => {
@@ -2568,10 +2373,10 @@ function fetchNgwLayerItems(options) {
2568
2373
  });
2569
2374
  }
2570
2375
  return data;
2571
- });
2572
- } else {
2573
- return fetchNgwLayerItemsRequest(options);
2574
- }
2376
+ } else {
2377
+ return fetchNgwLayerItemsRequest(options);
2378
+ }
2379
+ });
2575
2380
  }
2576
2381
  function isFilterWithAnyCase(filters) {
2577
2382
  if (filters[0] === "any") {
@@ -2788,14 +2593,14 @@ class NominatimProvider extends BaseProvider {
2788
2593
  constructor(options) {
2789
2594
  super(options);
2790
2595
  __publicField(this, "searchUrl", "https://nominatim.openstreetmap.org");
2791
- __publicField(this, "_requests", []);
2596
+ __publicField(this, "_abort", []);
2792
2597
  if (options && options.searchUrl) {
2793
2598
  this.searchUrl = options.searchUrl;
2794
2599
  }
2795
2600
  }
2796
2601
  abort() {
2797
- this._requests.forEach((x) => x.cancel());
2798
- this._requests = [];
2602
+ this._abort.forEach((x) => x());
2603
+ this._abort = [];
2799
2604
  }
2800
2605
  search(val) {
2801
2606
  return __asyncGenerator(this, null, function* () {
@@ -2803,39 +2608,34 @@ class NominatimProvider extends BaseProvider {
2803
2608
  // `${this.baseUrl}/search?format=geojson&polygon_geojson=1${window.locale === 'ru' ? '&accept-language=ru-RU,en-US' : ''}&q=${val}`
2804
2609
  `${this.searchUrl}/search?format=geojson&polygon_geojson=1&q=${val}`
2805
2610
  );
2806
- const request = new CancelablePromise(
2807
- (resolve, reject, onCancel) => {
2808
- const xhr = new XMLHttpRequest();
2809
- xhr.open("GET", url, true);
2810
- xhr.onload = () => {
2811
- try {
2812
- const geojson = JSON.parse(xhr.responseText);
2813
- const features = geojson.features.map((x) => {
2814
- return {
2815
- geom: x,
2816
- extent: x.bbox,
2817
- text: x.properties && x.properties.display_name,
2818
- query: val
2819
- };
2820
- });
2821
- resolve(features);
2822
- } catch (er) {
2823
- reject(er);
2824
- }
2825
- };
2826
- xhr.onerror = (er) => {
2611
+ const request = new Promise((resolve, reject) => {
2612
+ const xhr = new XMLHttpRequest();
2613
+ xhr.open("GET", url, true);
2614
+ xhr.onload = () => {
2615
+ try {
2616
+ const geojson = JSON.parse(xhr.responseText);
2617
+ const features = geojson.features.map((x) => {
2618
+ return {
2619
+ geom: x,
2620
+ extent: x.bbox,
2621
+ text: x.properties && x.properties.display_name,
2622
+ query: val
2623
+ };
2624
+ });
2625
+ resolve(features);
2626
+ } catch (er) {
2827
2627
  reject(er);
2828
- };
2829
- onCancel(() => {
2830
- xhr.abort();
2831
- });
2832
- xhr.send();
2833
- }
2834
- ).catch((er) => {
2628
+ }
2629
+ };
2630
+ xhr.onerror = (er) => {
2631
+ reject(er);
2632
+ };
2633
+ this._abort.push(xhr.abort);
2634
+ xhr.send();
2635
+ }).catch((er) => {
2835
2636
  if (er.name === "CancelError") ;
2836
2637
  throw er;
2837
2638
  });
2838
- this._requests.push(request);
2839
2639
  const items = yield new __await(request);
2840
2640
  if (items) {
2841
2641
  for (const i of items) {
@@ -2846,7 +2646,7 @@ class NominatimProvider extends BaseProvider {
2846
2646
  });
2847
2647
  }
2848
2648
  result(model) {
2849
- return CancelablePromise.resolve({
2649
+ return Promise.resolve({
2850
2650
  text: model.text,
2851
2651
  extent: model.extent || [],
2852
2652
  geom: model.geom
@@ -2858,38 +2658,33 @@ class NominatimProvider extends BaseProvider {
2858
2658
  const url = fixUrlStr(
2859
2659
  `${this.searchUrl}/reverse?format=geojson&lat=${lat}&lon=${lng}`
2860
2660
  );
2861
- const request = new CancelablePromise(
2862
- (resolve, reject, onCancel) => {
2863
- const xhr = new XMLHttpRequest();
2864
- xhr.open("GET", url, true);
2865
- xhr.onload = () => {
2866
- try {
2867
- const geojson = JSON.parse(xhr.responseText);
2868
- const feature = geojson.features[0];
2869
- const result = {
2870
- geom: feature,
2871
- extent: feature.bbox,
2872
- text: feature.properties && feature.properties.display_name,
2873
- query: `${lat}, ${lng}`
2874
- };
2875
- resolve(result);
2876
- } catch (er) {
2877
- reject(er);
2878
- }
2879
- };
2880
- xhr.onerror = (er) => {
2661
+ const request = new Promise((resolve, reject) => {
2662
+ const xhr = new XMLHttpRequest();
2663
+ xhr.open("GET", url, true);
2664
+ xhr.onload = () => {
2665
+ try {
2666
+ const geojson = JSON.parse(xhr.responseText);
2667
+ const feature = geojson.features[0];
2668
+ const result = {
2669
+ geom: feature,
2670
+ extent: feature.bbox,
2671
+ text: feature.properties && feature.properties.display_name,
2672
+ query: `${lat}, ${lng}`
2673
+ };
2674
+ resolve(result);
2675
+ } catch (er) {
2881
2676
  reject(er);
2882
- };
2883
- onCancel(() => {
2884
- xhr.abort();
2885
- });
2886
- xhr.send();
2887
- }
2888
- ).catch((er) => {
2677
+ }
2678
+ };
2679
+ xhr.onerror = (er) => {
2680
+ reject(er);
2681
+ };
2682
+ this._abort.push(xhr.abort);
2683
+ xhr.send();
2684
+ }).catch((er) => {
2889
2685
  if (er.name === "CancelError") ;
2890
2686
  throw er;
2891
2687
  });
2892
- this._requests.push(request);
2893
2688
  const item = yield new __await(request);
2894
2689
  if (item) {
2895
2690
  item.result = () => this.result(item);