@nextgis/geocoder 2.4.0 → 3.0.0-alpha.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,306 +1,4 @@
1
- /** Bundle of @nextgis/geocoder; version: 2.4.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, typeof key !== "symbol" ? key + "" : 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, typeof key !== "symbol" ? key + "" : 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, typeof key !== "symbol" ? key + "" : 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.0; author: NextGIS */
304
2
  function defined(val) {
305
3
  return val !== void 0 && val !== null;
306
4
  }
@@ -383,7 +81,7 @@ function objectRemoveEmpty(obj) {
383
81
  }
384
82
 
385
83
  function round(val, toFixed) {
386
- const n = toFixed ? Number("1e+" + toFixed) : 1;
84
+ const n = 1;
387
85
  return Math.round((val + Number.EPSILON) * n) / n;
388
86
  }
389
87
 
@@ -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, typeof key !== "symbol" ? key + "" : 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,64 +1271,96 @@ 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
 
1664
1361
  var __defProp$5 = Object.defineProperty;
1665
1362
  var __defNormalProp$5 = (obj, key, value) => key in obj ? __defProp$5(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
1666
- var __publicField$3 = (obj, key, value) => __defNormalProp$5(obj, typeof key !== "symbol" ? key + "" : key, value);
1363
+ var __publicField$3 = (obj, key, value) => __defNormalProp$5(obj, key + "" , value);
1667
1364
  class NetworkError extends Error {
1668
1365
  constructor(url) {
1669
1366
  super();
@@ -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;
@@ -1783,7 +1516,7 @@ class NgwConnector {
1783
1516
  __publicField$2(this, "resources");
1784
1517
  __publicField$2(this, "cache");
1785
1518
  __publicField$2(this, "routeStr", "/api/component/pyramid/route");
1786
- __publicField$2(this, "activeRequests", []);
1519
+ __publicField$2(this, "activeRequests", {});
1787
1520
  __publicField$2(this, "requestTransform");
1788
1521
  const exist = findConnector(options);
1789
1522
  this.cache = new Cache({ namespace: options.cacheId });
@@ -1840,29 +1573,27 @@ class NgwConnector {
1840
1573
  * ```
1841
1574
  */
1842
1575
  connect() {
1843
- const auth = this.options.auth;
1844
- const makeConnect = () => new CancelablePromise((resolve, reject) => {
1845
- const makeQuery = () => {
1846
- return this.makeQuery(this.routeStr, {}, {}).then((route) => {
1847
- resolve(route);
1848
- }).catch((er) => {
1849
- reject(er);
1850
- });
1851
- };
1576
+ return __async$2(this, null, function* () {
1577
+ const auth = this.options.auth;
1852
1578
  if (auth) {
1853
1579
  const { login, password } = auth;
1854
1580
  if (login && password) {
1855
- return this._login({ login, password }).then(() => {
1856
- return makeQuery();
1857
- }).catch((er) => reject(er));
1581
+ yield this._login({ login, password });
1858
1582
  }
1859
1583
  }
1860
- return makeQuery();
1861
- });
1862
- return this.cache.add("route", makeConnect, {
1863
- id: this.id,
1864
- auth,
1865
- baseUrl: this.options.baseUrl
1584
+ return yield this.makeQuery(
1585
+ this.routeStr,
1586
+ {},
1587
+ {
1588
+ cacheName: "route",
1589
+ cache: true,
1590
+ cacheProps: {
1591
+ id: this.id,
1592
+ auth,
1593
+ baseUrl: this.options.baseUrl
1594
+ }
1595
+ }
1596
+ );
1866
1597
  });
1867
1598
  }
1868
1599
  /**
@@ -1886,20 +1617,22 @@ class NgwConnector {
1886
1617
  this.emitter.emit("logout");
1887
1618
  }
1888
1619
  getUserInfo(credentials, options) {
1889
- if (this.user && this.user.id) {
1890
- return CancelablePromise.resolve(this.user);
1891
- }
1892
- if (credentials) {
1893
- this.options.auth = credentials;
1894
- }
1895
- const options_ = __spreadValues$3({
1896
- headers: this.getAuthorizationHeaders(credentials)
1897
- }, options);
1898
- return this.makeQuery(
1899
- "/api/component/auth/current_user",
1900
- {},
1901
- options_
1902
- );
1620
+ return __async$2(this, null, function* () {
1621
+ if (this.user && this.user.id) {
1622
+ return this.user;
1623
+ }
1624
+ if (credentials) {
1625
+ this.options.auth = credentials;
1626
+ }
1627
+ const options_ = __spreadValues$3({
1628
+ headers: this.getAuthorizationHeaders(credentials)
1629
+ }, options);
1630
+ return this.makeQuery(
1631
+ "/api/component/auth/current_user",
1632
+ {},
1633
+ options_
1634
+ );
1635
+ });
1903
1636
  }
1904
1637
  /**
1905
1638
  * Obtaining the required Headers for authentication of requests in the NGW.
@@ -1908,7 +1641,7 @@ class NgwConnector {
1908
1641
  const client = this.makeClientId(credentials);
1909
1642
  if (client) {
1910
1643
  return {
1911
- Authorization: "Basic " + client
1644
+ Authorization: `Basic ${client}`
1912
1645
  };
1913
1646
  }
1914
1647
  }
@@ -1916,21 +1649,22 @@ class NgwConnector {
1916
1649
  credentials = credentials || this.options.auth;
1917
1650
  if (credentials) {
1918
1651
  const { login, password } = credentials;
1919
- const str = unescape(encodeURIComponent(`${login}:${password}`));
1652
+ const str = `${login}:${password}`;
1653
+ const encodedStr = encodeURIComponent(str);
1920
1654
  {
1921
- return window.btoa(str);
1655
+ return window.btoa(encodedStr);
1922
1656
  }
1923
1657
  }
1924
1658
  }
1925
1659
  /** Stop all api requests */
1926
1660
  abort() {
1927
- for (const req of this.activeRequests) {
1928
- req.cancel();
1661
+ for (const abortController of Object.values(this.activeRequests)) {
1662
+ abortController.abort();
1929
1663
  }
1930
- this.activeRequests = [];
1664
+ this.activeRequests = {};
1931
1665
  }
1932
1666
  getActiveApiRequests() {
1933
- return [...this.activeRequests];
1667
+ return __spreadValues$3({}, this.activeRequests);
1934
1668
  }
1935
1669
  /**
1936
1670
  * Send request to NGW api router.
@@ -1962,23 +1696,10 @@ class NgwConnector {
1962
1696
  * ```
1963
1697
  */
1964
1698
  apiRequest(name, params_ = {}, requestOptions = {}) {
1965
- var _a, _b;
1966
- const { method, headers, withCredentials, responseType } = requestOptions;
1699
+ var _a;
1967
1700
  params_ = (_a = requestOptions.params) != null ? _a : params_;
1968
1701
  const params = objectRemoveEmpty(params_);
1969
- const makeApiRequest = () => apiRequest({ name, params, requestOptions, connector: this });
1970
- if (requestOptions.cache && method === "GET") {
1971
- return this.cache.add(name, makeApiRequest, __spreadValues$3({
1972
- params
1973
- }, objectRemoveEmpty({
1974
- headers,
1975
- withCredentials,
1976
- responseType,
1977
- baseUrl: this.options.baseUrl,
1978
- userId: (_b = this.user) == null ? void 0 : _b.id
1979
- })));
1980
- }
1981
- return makeApiRequest();
1702
+ return apiRequest({ name, params, requestOptions, connector: this });
1982
1703
  }
1983
1704
  /**
1984
1705
  * Shortcut method for send POST request to NGW.
@@ -2068,17 +1789,67 @@ class NgwConnector {
2068
1789
  * @param params - Query params
2069
1790
  * @param options - Request options
2070
1791
  */
2071
- makeQuery(url, params, options = {}) {
2072
- url = (this.options.baseUrl ? this.options.baseUrl : "") + url;
2073
- if (url) {
1792
+ makeQuery(_0, _1) {
1793
+ return __async$2(this, arguments, function* (url, params, options = {}) {
1794
+ var _b;
1795
+ url = (this.options.baseUrl ? this.options.baseUrl : "") + url;
1796
+ if (!url) {
1797
+ throw new Error("Empty `url` not allowed");
1798
+ }
2074
1799
  if (params) {
2075
- url = template(url, params);
1800
+ const _a = params, restParams = __objRest(_a, ["paramList"]);
1801
+ url = template(url, restParams);
2076
1802
  }
2077
1803
  url = encodeURI(fixUrlStr(url));
2078
- return this._loadData(url, options);
2079
- } else {
2080
- throw new Error("Empty `url` not allowed");
2081
- }
1804
+ const {
1805
+ cache,
1806
+ signal: externalSignal,
1807
+ method = "GET",
1808
+ headers,
1809
+ cacheName,
1810
+ cacheProps,
1811
+ responseType,
1812
+ withCredentials
1813
+ } = options;
1814
+ const internalAbortController = new AbortController();
1815
+ const internalSignal = internalAbortController.signal;
1816
+ if (externalSignal) {
1817
+ if (externalSignal.aborted) {
1818
+ throw new AbortError();
1819
+ }
1820
+ externalSignal.addEventListener("abort", () => {
1821
+ internalAbortController.abort();
1822
+ });
1823
+ }
1824
+ options.signal = internalSignal;
1825
+ const createPromise = () => __async$2(this, null, function* () {
1826
+ const id = REQUEST_ID++;
1827
+ this.activeRequests[id] = internalAbortController;
1828
+ try {
1829
+ return this._loadData(url, options);
1830
+ } finally {
1831
+ this._cleanActiveRequest(id);
1832
+ }
1833
+ });
1834
+ if (cache && method === "GET") {
1835
+ const cacheOptions = cacheProps ? cacheProps : __spreadProps$2(__spreadValues$3({}, objectRemoveEmpty({
1836
+ headers,
1837
+ withCredentials,
1838
+ responseType,
1839
+ baseUrl: this.options.baseUrl,
1840
+ userId: (_b = this.user) == null ? void 0 : _b.id
1841
+ })), {
1842
+ params
1843
+ });
1844
+ return this.cache.add(
1845
+ cacheName || url,
1846
+ createPromise,
1847
+ cacheOptions,
1848
+ false
1849
+ );
1850
+ }
1851
+ return createPromise();
1852
+ });
2082
1853
  }
2083
1854
  // -------------------------------------------------------------------------
2084
1855
  // Resource Methods
@@ -2160,10 +1931,8 @@ class NgwConnector {
2160
1931
  */
2161
1932
  _loadData(url, options) {
2162
1933
  options.responseType = options.responseType || "json";
2163
- if (options.signal && options.signal.aborted) {
2164
- return CancelablePromise.reject(new CancelablePromise.CancelError());
2165
- }
2166
- const request = new CancelablePromise((resolve, reject, onCancel) => {
1934
+ return new Promise((resolve, reject) => {
1935
+ var _a;
2167
1936
  if (this.user) {
2168
1937
  options = options || {};
2169
1938
  options.headers = __spreadValues$3(__spreadValues$3({}, this.getAuthorizationHeaders()), options.headers);
@@ -2173,13 +1942,18 @@ class NgwConnector {
2173
1942
  url = transUrl;
2174
1943
  options = transOptions;
2175
1944
  }
2176
- loadData(url, resolve, options, reject, onCancel);
2177
- }).then((resp) => {
2178
- this._cleanActiveRequests(request);
2179
- return resp;
1945
+ let runOnAbort = void 0;
1946
+ loadData(url, resolve, options, reject, (handler) => {
1947
+ runOnAbort = handler;
1948
+ });
1949
+ (_a = options.signal) == null ? void 0 : _a.addEventListener("abort", () => {
1950
+ if (runOnAbort !== void 0) {
1951
+ runOnAbort();
1952
+ }
1953
+ reject(new AbortError());
1954
+ });
2180
1955
  }).catch((httpError) => {
2181
- this._cleanActiveRequests(request);
2182
- if (httpError instanceof CancelablePromise.CancelError) ; else {
1956
+ if (httpError.name !== "AbortError") {
2183
1957
  {
2184
1958
  console.warn("DEV WARN", httpError);
2185
1959
  }
@@ -2188,31 +1962,24 @@ class NgwConnector {
2188
1962
  throw er;
2189
1963
  }
2190
1964
  }
1965
+ throw httpError;
2191
1966
  });
2192
- if (options.signal && typeof options.signal.addEventListener === "function") {
2193
- options.signal.addEventListener("abort", () => {
2194
- request.cancel();
2195
- this._cleanActiveRequests(request);
2196
- });
2197
- }
2198
- this.activeRequests.push(request);
2199
- return request;
2200
1967
  }
2201
1968
  _login(credentials, options) {
2202
- return this.getUserInfo(credentials, options).then((data) => {
2203
- this.user = data;
2204
- this.emitter.emit("login", data);
2205
- return data;
2206
- }).catch((er) => {
2207
- this.emitter.emit("login:error", er);
2208
- throw er;
1969
+ return __async$2(this, null, function* () {
1970
+ try {
1971
+ const data = yield this.getUserInfo(credentials, options);
1972
+ this.user = data;
1973
+ this.emitter.emit("login", data);
1974
+ return data;
1975
+ } catch (er) {
1976
+ this.emitter.emit("login:error", er);
1977
+ throw er;
1978
+ }
2209
1979
  });
2210
1980
  }
2211
- _cleanActiveRequests(request) {
2212
- const activeRequestIndex = this.activeRequests.indexOf(request);
2213
- if (activeRequestIndex !== -1) {
2214
- this.activeRequests.splice(activeRequestIndex, 1);
2215
- }
1981
+ _cleanActiveRequest(requestId) {
1982
+ delete this.activeRequests[requestId];
2216
1983
  }
2217
1984
  _handleHttpError(er) {
2218
1985
  if (er) {
@@ -2321,6 +2088,26 @@ var __spreadValues$2 = (a, b) => {
2321
2088
  return a;
2322
2089
  };
2323
2090
  var __spreadProps$1 = (a, b) => __defProps$1(a, __getOwnPropDescs$1(b));
2091
+ var __async$1 = (__this, __arguments, generator) => {
2092
+ return new Promise((resolve, reject) => {
2093
+ var fulfilled = (value) => {
2094
+ try {
2095
+ step(generator.next(value));
2096
+ } catch (e) {
2097
+ reject(e);
2098
+ }
2099
+ };
2100
+ var rejected = (value) => {
2101
+ try {
2102
+ step(generator.throw(value));
2103
+ } catch (e) {
2104
+ reject(e);
2105
+ }
2106
+ };
2107
+ var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
2108
+ step((generator = generator.apply(__this, __arguments)).next());
2109
+ });
2110
+ };
2324
2111
  const FEATURE_REQUEST_PARAMS = {
2325
2112
  srs: 4326,
2326
2113
  geom_format: "geojson"
@@ -2351,10 +2138,9 @@ function updateItemRequestParam(params, options) {
2351
2138
  }
2352
2139
  }
2353
2140
  function createFeatureFieldFilterQueries(opt) {
2354
- const queries = getQueries(
2355
- opt
2356
- );
2357
- return CancelablePromise.all(queries).then((itemsParts) => {
2141
+ return __async$1(this, null, function* () {
2142
+ const queries = getQueries(opt);
2143
+ const itemsParts = yield Promise.all(queries);
2358
2144
  const ids = [];
2359
2145
  const items = [];
2360
2146
  for (const part of itemsParts) {
@@ -2387,7 +2173,9 @@ function createParam(pf) {
2387
2173
  return [`${isFldStr}${field_}__${operation}`, v];
2388
2174
  }
2389
2175
  function getQueries(opt, _queries = [], _parentAllParams = []) {
2176
+ var _a;
2390
2177
  const { filters } = opt;
2178
+ const paramList = (_a = opt.paramList) != null ? _a : [];
2391
2179
  const logic = typeof filters[0] === "string" ? filters[0] : "all";
2392
2180
  const filters_ = filters.filter((x) => Array.isArray(x));
2393
2181
  if (logic === "any") {
@@ -2395,7 +2183,7 @@ function getQueries(opt, _queries = [], _parentAllParams = []) {
2395
2183
  if (isPropertyFilter(f)) {
2396
2184
  _queries.push(
2397
2185
  fetchNgwLayerItemsRequest(__spreadProps$1(__spreadValues$2({}, opt), {
2398
- paramList: [..._parentAllParams, createParam(f)]
2186
+ paramList: [..._parentAllParams, ...paramList, createParam(f)]
2399
2187
  }))
2400
2188
  );
2401
2189
  } else {
@@ -2431,7 +2219,7 @@ function getQueries(opt, _queries = [], _parentAllParams = []) {
2431
2219
  } else {
2432
2220
  _queries.push(
2433
2221
  fetchNgwLayerItemsRequest(__spreadProps$1(__spreadValues$2({}, opt), {
2434
- paramList: [..._parentAllParams, ...filters2]
2222
+ paramList: [..._parentAllParams, ...paramList, ...filters2]
2435
2223
  }))
2436
2224
  );
2437
2225
  }
@@ -2540,13 +2328,34 @@ var __spreadValues$1 = (a, b) => {
2540
2328
  return a;
2541
2329
  };
2542
2330
  var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
2331
+ var __async = (__this, __arguments, generator) => {
2332
+ return new Promise((resolve, reject) => {
2333
+ var fulfilled = (value) => {
2334
+ try {
2335
+ step(generator.next(value));
2336
+ } catch (e) {
2337
+ reject(e);
2338
+ }
2339
+ };
2340
+ var rejected = (value) => {
2341
+ try {
2342
+ step(generator.throw(value));
2343
+ } catch (e) {
2344
+ reject(e);
2345
+ }
2346
+ };
2347
+ var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
2348
+ step((generator = generator.apply(__this, __arguments)).next());
2349
+ });
2350
+ };
2543
2351
  function fetchNgwLayerItems(options) {
2544
- const filters = options.filters;
2545
- if (filters) {
2546
- return createFeatureFieldFilterQueries(__spreadProps(__spreadValues$1({}, options), {
2547
- filters
2548
- })).then((data) => {
2549
- var _a;
2352
+ return __async(this, null, function* () {
2353
+ var _a;
2354
+ const filters = options.filters;
2355
+ if (filters) {
2356
+ let data = yield createFeatureFieldFilterQueries(__spreadProps(__spreadValues$1({}, options), {
2357
+ filters
2358
+ }));
2550
2359
  const clientFilterValidate = (_a = options.clientFilterValidate) != null ? _a : isFilterWithAnyCase(filters);
2551
2360
  if (clientFilterValidate) {
2552
2361
  data = data.filter((y) => {
@@ -2558,10 +2367,10 @@ function fetchNgwLayerItems(options) {
2558
2367
  });
2559
2368
  }
2560
2369
  return data;
2561
- });
2562
- } else {
2563
- return fetchNgwLayerItemsRequest(options);
2564
- }
2370
+ } else {
2371
+ return fetchNgwLayerItemsRequest(options);
2372
+ }
2373
+ });
2565
2374
  }
2566
2375
  function isFilterWithAnyCase(filters) {
2567
2376
  if (filters[0] === "any") {
@@ -2778,14 +2587,14 @@ class NominatimProvider extends BaseProvider {
2778
2587
  constructor(options) {
2779
2588
  super(options);
2780
2589
  __publicField(this, "searchUrl", "https://nominatim.openstreetmap.org");
2781
- __publicField(this, "_requests", []);
2590
+ __publicField(this, "_abort", []);
2782
2591
  if (options && options.searchUrl) {
2783
2592
  this.searchUrl = options.searchUrl;
2784
2593
  }
2785
2594
  }
2786
2595
  abort() {
2787
- this._requests.forEach((x) => x.cancel());
2788
- this._requests = [];
2596
+ this._abort.forEach((x) => x());
2597
+ this._abort = [];
2789
2598
  }
2790
2599
  search(val) {
2791
2600
  return __asyncGenerator(this, null, function* () {
@@ -2793,39 +2602,34 @@ class NominatimProvider extends BaseProvider {
2793
2602
  // `${this.baseUrl}/search?format=geojson&polygon_geojson=1${window.locale === 'ru' ? '&accept-language=ru-RU,en-US' : ''}&q=${val}`
2794
2603
  `${this.searchUrl}/search?format=geojson&polygon_geojson=1&q=${val}`
2795
2604
  );
2796
- const request = new CancelablePromise(
2797
- (resolve, reject, onCancel) => {
2798
- const xhr = new XMLHttpRequest();
2799
- xhr.open("GET", url, true);
2800
- xhr.onload = () => {
2801
- try {
2802
- const geojson = JSON.parse(xhr.responseText);
2803
- const features = geojson.features.map((x) => {
2804
- return {
2805
- geom: x,
2806
- extent: x.bbox,
2807
- text: x.properties && x.properties.display_name,
2808
- query: val
2809
- };
2810
- });
2811
- resolve(features);
2812
- } catch (er) {
2813
- reject(er);
2814
- }
2815
- };
2816
- xhr.onerror = (er) => {
2605
+ const request = new Promise((resolve, reject) => {
2606
+ const xhr = new XMLHttpRequest();
2607
+ xhr.open("GET", url, true);
2608
+ xhr.onload = () => {
2609
+ try {
2610
+ const geojson = JSON.parse(xhr.responseText);
2611
+ const features = geojson.features.map((x) => {
2612
+ return {
2613
+ geom: x,
2614
+ extent: x.bbox,
2615
+ text: x.properties && x.properties.display_name,
2616
+ query: val
2617
+ };
2618
+ });
2619
+ resolve(features);
2620
+ } catch (er) {
2817
2621
  reject(er);
2818
- };
2819
- onCancel(() => {
2820
- xhr.abort();
2821
- });
2822
- xhr.send();
2823
- }
2824
- ).catch((er) => {
2622
+ }
2623
+ };
2624
+ xhr.onerror = (er) => {
2625
+ reject(er);
2626
+ };
2627
+ this._abort.push(xhr.abort);
2628
+ xhr.send();
2629
+ }).catch((er) => {
2825
2630
  if (er.name === "CancelError") ;
2826
2631
  throw er;
2827
2632
  });
2828
- this._requests.push(request);
2829
2633
  const items = yield new __await(request);
2830
2634
  if (items) {
2831
2635
  for (const i of items) {
@@ -2836,7 +2640,7 @@ class NominatimProvider extends BaseProvider {
2836
2640
  });
2837
2641
  }
2838
2642
  result(model) {
2839
- return CancelablePromise.resolve({
2643
+ return Promise.resolve({
2840
2644
  text: model.text,
2841
2645
  extent: model.extent || [],
2842
2646
  geom: model.geom
@@ -2848,38 +2652,33 @@ class NominatimProvider extends BaseProvider {
2848
2652
  const url = fixUrlStr(
2849
2653
  `${this.searchUrl}/reverse?format=geojson&lat=${lat}&lon=${lng}`
2850
2654
  );
2851
- const request = new CancelablePromise(
2852
- (resolve, reject, onCancel) => {
2853
- const xhr = new XMLHttpRequest();
2854
- xhr.open("GET", url, true);
2855
- xhr.onload = () => {
2856
- try {
2857
- const geojson = JSON.parse(xhr.responseText);
2858
- const feature = geojson.features[0];
2859
- const result = {
2860
- geom: feature,
2861
- extent: feature.bbox,
2862
- text: feature.properties && feature.properties.display_name,
2863
- query: `${lat}, ${lng}`
2864
- };
2865
- resolve(result);
2866
- } catch (er) {
2867
- reject(er);
2868
- }
2869
- };
2870
- xhr.onerror = (er) => {
2655
+ const request = new Promise((resolve, reject) => {
2656
+ const xhr = new XMLHttpRequest();
2657
+ xhr.open("GET", url, true);
2658
+ xhr.onload = () => {
2659
+ try {
2660
+ const geojson = JSON.parse(xhr.responseText);
2661
+ const feature = geojson.features[0];
2662
+ const result = {
2663
+ geom: feature,
2664
+ extent: feature.bbox,
2665
+ text: feature.properties && feature.properties.display_name,
2666
+ query: `${lat}, ${lng}`
2667
+ };
2668
+ resolve(result);
2669
+ } catch (er) {
2871
2670
  reject(er);
2872
- };
2873
- onCancel(() => {
2874
- xhr.abort();
2875
- });
2876
- xhr.send();
2877
- }
2878
- ).catch((er) => {
2671
+ }
2672
+ };
2673
+ xhr.onerror = (er) => {
2674
+ reject(er);
2675
+ };
2676
+ this._abort.push(xhr.abort);
2677
+ xhr.send();
2678
+ }).catch((er) => {
2879
2679
  if (er.name === "CancelError") ;
2880
2680
  throw er;
2881
2681
  });
2882
- this._requests.push(request);
2883
2682
  const item = yield new __await(request);
2884
2683
  if (item) {
2885
2684
  item.result = () => this.result(item);