@nextgis/ngw-connector 2.4.0 → 3.0.0-alpha.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,12 +1,11 @@
1
- /** Bundle of @nextgis/ngw-connector; version: 2.4.0; author: NextGIS */
1
+ /** Bundle of @nextgis/ngw-connector; version: 3.0.0-alpha.0; author: NextGIS */
2
2
  import { EventEmitter } from 'events';
3
3
  import Cache from '@nextgis/cache';
4
- import CancelablePromise from '@nextgis/cancelable-promise';
5
4
  import { objectDeepEqual, defined, objectRemoveEmpty, fixUrlStr } from '@nextgis/utils';
6
5
 
7
- var __defProp$5 = Object.defineProperty;
8
- var __defNormalProp$5 = (obj, key, value) => key in obj ? __defProp$5(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
9
- var __publicField$5 = (obj, key, value) => __defNormalProp$5(obj, typeof key !== "symbol" ? key + "" : key, value);
6
+ var __defProp$6 = Object.defineProperty;
7
+ var __defNormalProp$6 = (obj, key, value) => key in obj ? __defProp$6(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
8
+ var __publicField$5 = (obj, key, value) => __defNormalProp$6(obj, typeof key !== "symbol" ? key + "" : key, value);
10
9
  class NgwError extends Error {
11
10
  constructor(er) {
12
11
  super();
@@ -23,9 +22,9 @@ class NgwError extends Error {
23
22
  }
24
23
  }
25
24
 
26
- var __defProp$4 = Object.defineProperty;
27
- var __defNormalProp$4 = (obj, key, value) => key in obj ? __defProp$4(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
28
- var __publicField$4 = (obj, key, value) => __defNormalProp$4(obj, typeof key !== "symbol" ? key + "" : key, value);
25
+ var __defProp$5 = Object.defineProperty;
26
+ var __defNormalProp$5 = (obj, key, value) => key in obj ? __defProp$5(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
27
+ var __publicField$4 = (obj, key, value) => __defNormalProp$5(obj, typeof key !== "symbol" ? key + "" : key, value);
29
28
  class ResourceNotFoundError extends NgwError {
30
29
  constructor(obj) {
31
30
  super(obj);
@@ -64,27 +63,24 @@ function resourceToQuery(resource, prefix = "") {
64
63
  return query;
65
64
  }
66
65
 
67
- var __defProp$3 = Object.defineProperty;
68
- var __defProps = Object.defineProperties;
69
- var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
70
- var __getOwnPropSymbols$1 = Object.getOwnPropertySymbols;
71
- var __hasOwnProp$1 = Object.prototype.hasOwnProperty;
72
- var __propIsEnum$1 = Object.prototype.propertyIsEnumerable;
73
- var __defNormalProp$3 = (obj, key, value) => key in obj ? __defProp$3(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
74
- var __spreadValues$1 = (a, b) => {
66
+ var __defProp$4 = Object.defineProperty;
67
+ var __getOwnPropSymbols$2 = Object.getOwnPropertySymbols;
68
+ var __hasOwnProp$2 = Object.prototype.hasOwnProperty;
69
+ var __propIsEnum$2 = Object.prototype.propertyIsEnumerable;
70
+ var __defNormalProp$4 = (obj, key, value) => key in obj ? __defProp$4(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
71
+ var __spreadValues$2 = (a, b) => {
75
72
  for (var prop in b || (b = {}))
76
- if (__hasOwnProp$1.call(b, prop))
77
- __defNormalProp$3(a, prop, b[prop]);
78
- if (__getOwnPropSymbols$1)
79
- for (var prop of __getOwnPropSymbols$1(b)) {
80
- if (__propIsEnum$1.call(b, prop))
81
- __defNormalProp$3(a, prop, b[prop]);
73
+ if (__hasOwnProp$2.call(b, prop))
74
+ __defNormalProp$4(a, prop, b[prop]);
75
+ if (__getOwnPropSymbols$2)
76
+ for (var prop of __getOwnPropSymbols$2(b)) {
77
+ if (__propIsEnum$2.call(b, prop))
78
+ __defNormalProp$4(a, prop, b[prop]);
82
79
  }
83
80
  return a;
84
81
  };
85
- var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
86
- var __publicField$3 = (obj, key, value) => __defNormalProp$3(obj, typeof key !== "symbol" ? key + "" : key, value);
87
- var __async = (__this, __arguments, generator) => {
82
+ var __publicField$3 = (obj, key, value) => __defNormalProp$4(obj, typeof key !== "symbol" ? key + "" : key, value);
83
+ var __async$2 = (__this, __arguments, generator) => {
88
84
  return new Promise((resolve, reject) => {
89
85
  var fulfilled = (value) => {
90
86
  try {
@@ -125,39 +121,27 @@ class ResourcesControl {
125
121
  * Fetching resource would be cached to speed up next call
126
122
  */
127
123
  getOne(resource, requestOptions) {
128
- const cache = this.cache;
129
- const forCache = {};
130
- const opt = __spreadProps(__spreadValues$1({}, requestOptions), { cache: false });
131
- if (typeof resource === "string") {
132
- forCache.keyname = resource;
133
- } else if (typeof resource === "number") {
134
- forCache.id = resource;
135
- } else if (isObject(resource)) {
124
+ const opt = __spreadValues$2({}, requestOptions);
125
+ if (typeof resource === "string") ; else if (typeof resource === "number") ; else if (isObject(resource)) {
136
126
  if (resource.id !== void 0) {
137
- forCache.id = resource.id;
127
+ resource.id;
138
128
  } else {
139
129
  if (resource.keyname) {
140
- forCache.keyname = resource.keyname;
130
+ resource.keyname;
141
131
  }
142
132
  if (resource.display_name) {
143
- forCache.display_name = resource.display_name;
133
+ resource.display_name;
144
134
  }
145
135
  }
146
136
  }
147
- const makeRequest = () => {
148
- if (typeof resource === "string") {
149
- return this._fetchResourceBy({ keyname: resource }, opt);
150
- } else if (typeof resource === "number") {
151
- return this._fetchResourceById(resource, opt);
152
- } else if (isObject(resource)) {
153
- return this._fetchResourceBy(resource, opt);
154
- }
155
- return CancelablePromise.resolve(void 0);
156
- };
157
- if (requestOptions == null ? void 0 : requestOptions.cache) {
158
- return cache.addFull("resource", makeRequest, forCache);
137
+ if (typeof resource === "string") {
138
+ return this._fetchResourceBy({ keyname: resource }, opt);
139
+ } else if (typeof resource === "number") {
140
+ return this._fetchResourceById(resource, opt);
141
+ } else if (isObject(resource)) {
142
+ return this._fetchResourceBy(resource, opt);
159
143
  }
160
- return makeRequest();
144
+ return Promise.resolve(void 0);
161
145
  }
162
146
  getOneOrFail(resource, requestOptions) {
163
147
  return this.getOne(resource, requestOptions).then((res) => {
@@ -179,7 +163,7 @@ class ResourcesControl {
179
163
  */
180
164
  getId(resource, requestOptions) {
181
165
  if (typeof resource === "number") {
182
- return CancelablePromise.resolve(resource);
166
+ return Promise.resolve(resource);
183
167
  } else if (typeof resource === "string" || isObject(resource)) {
184
168
  return this.getOne(resource, requestOptions).then((res) => {
185
169
  if (res) {
@@ -187,7 +171,7 @@ class ResourcesControl {
187
171
  }
188
172
  });
189
173
  }
190
- return CancelablePromise.resolve(void 0);
174
+ return Promise.resolve(void 0);
191
175
  }
192
176
  /**
193
177
  * A fast way to retrieve resource ID for any resource definition.
@@ -214,12 +198,12 @@ class ResourcesControl {
214
198
  } else {
215
199
  Object.assign(query, resourceToQuery(resource));
216
200
  }
217
- return this.connector.get("resource.search", requestOptions, __spreadValues$1({
201
+ return this.connector.get("resource.search", requestOptions, __spreadValues$2({
218
202
  serialization: "full"
219
203
  }, query)).then((resources) => {
220
- if (resources) {
204
+ if ((requestOptions == null ? void 0 : requestOptions.cache) && resources) {
221
205
  for (const x of resources) {
222
- this.cache.add("resource.item", CancelablePromise.resolve(x), {
206
+ this.cache.add("resource.item", Promise.resolve(x), {
223
207
  id: x.resource.id
224
208
  });
225
209
  }
@@ -235,7 +219,7 @@ class ResourcesControl {
235
219
  if (child) {
236
220
  return this.getOne(child.resource.parent.id, requestOptions);
237
221
  }
238
- return CancelablePromise.resolve(void 0);
222
+ return Promise.resolve(void 0);
239
223
  });
240
224
  }
241
225
  getChildrenOf(resource, requestOptions) {
@@ -265,18 +249,16 @@ class ResourcesControl {
265
249
  });
266
250
  }
267
251
  _getChildrenOf(parent, requestOptions, _items = []) {
268
- return this.connector.get(
269
- "resource.collection",
270
- __spreadValues$1({ cache: true }, requestOptions),
271
- {
272
- parent
273
- }
274
- ).then((items) => {
252
+ return this.connector.get("resource.collection", requestOptions, {
253
+ parent
254
+ }).then((items) => {
275
255
  const recursivePromises = [];
276
256
  for (const item of items) {
277
- this.cache.add("resource.item", CancelablePromise.resolve(item), {
278
- id: item.resource.id
279
- });
257
+ if (requestOptions == null ? void 0 : requestOptions.cache) {
258
+ this.cache.add("resource.item", Promise.resolve(item), {
259
+ id: item.resource.id
260
+ });
261
+ }
280
262
  _items.push(item);
281
263
  if ((requestOptions == null ? void 0 : requestOptions.recursive) && item.resource.children) {
282
264
  recursivePromises.push(
@@ -285,7 +267,7 @@ class ResourcesControl {
285
267
  }
286
268
  }
287
269
  if (recursivePromises.length) {
288
- return CancelablePromise.all(recursivePromises).then(() => {
270
+ return Promise.all(recursivePromises).then(() => {
289
271
  return _items;
290
272
  });
291
273
  }
@@ -293,11 +275,12 @@ class ResourcesControl {
293
275
  });
294
276
  }
295
277
  _cleanResourceItemCache(id) {
296
- return __async(this, null, function* () {
278
+ return __async$2(this, null, function* () {
279
+ var _a;
297
280
  const all = this.cache.all();
298
281
  const toDelete = [];
299
282
  for (const c of all) {
300
- const cid = c.options && c.options.id;
283
+ const cid = (_a = c.props) == null ? void 0 : _a.id;
301
284
  if (["resource.item", "resource"].includes(c.key) && cid !== void 0) {
302
285
  if (typeof cid === "number") {
303
286
  if (cid === id) {
@@ -317,18 +300,7 @@ class ResourcesControl {
317
300
  });
318
301
  }
319
302
  _fetchResourceById(id, requestOptions) {
320
- const promise = () => this.connector.get("resource.item", requestOptions, { id });
321
- if (requestOptions == null ? void 0 : requestOptions.cache) {
322
- return this.cache.add("resource.item", promise, {
323
- id
324
- }).catch((er) => {
325
- if (!(er instanceof ResourceNotFoundError)) {
326
- throw er;
327
- }
328
- return void 0;
329
- });
330
- }
331
- return promise();
303
+ return this.connector.get("resource.item", requestOptions, { id });
332
304
  }
333
305
  _fetchResourceBy(resource, requestOptions) {
334
306
  return this.getMany(resource, requestOptions).then((resources) => {
@@ -336,7 +308,7 @@ class ResourcesControl {
336
308
  });
337
309
  }
338
310
  _resourceCacheFilter(resource) {
339
- return CancelablePromise.all(this.cache.matchAll("resource.item")).then(
311
+ return Promise.all(this.cache.matchAll("resource.item")).then(
340
312
  (resources) => {
341
313
  const items = [];
342
314
  resources.filter((x) => {
@@ -380,9 +352,16 @@ function removeConnector(connector) {
380
352
  }
381
353
  }
382
354
 
383
- var __defProp$2 = Object.defineProperty;
384
- var __defNormalProp$2 = (obj, key, value) => key in obj ? __defProp$2(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
385
- var __publicField$2 = (obj, key, value) => __defNormalProp$2(obj, typeof key !== "symbol" ? key + "" : key, value);
355
+ class AbortError extends Error {
356
+ constructor(message = "AbortError") {
357
+ super(message);
358
+ this.name = "AbortError";
359
+ }
360
+ }
361
+
362
+ var __defProp$3 = Object.defineProperty;
363
+ var __defNormalProp$3 = (obj, key, value) => key in obj ? __defProp$3(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
364
+ var __publicField$2 = (obj, key, value) => __defNormalProp$3(obj, typeof key !== "symbol" ? key + "" : key, value);
386
365
  class InsufficientPermissionsError extends NgwError {
387
366
  constructor(obj) {
388
367
  super(obj);
@@ -405,64 +384,96 @@ function template(str, data) {
405
384
  });
406
385
  }
407
386
 
387
+ var __defProp$2 = Object.defineProperty;
388
+ var __getOwnPropSymbols$1 = Object.getOwnPropertySymbols;
389
+ var __hasOwnProp$1 = Object.prototype.hasOwnProperty;
390
+ var __propIsEnum$1 = Object.prototype.propertyIsEnumerable;
391
+ var __defNormalProp$2 = (obj, key, value) => key in obj ? __defProp$2(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
392
+ var __spreadValues$1 = (a, b) => {
393
+ for (var prop in b || (b = {}))
394
+ if (__hasOwnProp$1.call(b, prop))
395
+ __defNormalProp$2(a, prop, b[prop]);
396
+ if (__getOwnPropSymbols$1)
397
+ for (var prop of __getOwnPropSymbols$1(b)) {
398
+ if (__propIsEnum$1.call(b, prop))
399
+ __defNormalProp$2(a, prop, b[prop]);
400
+ }
401
+ return a;
402
+ };
403
+ var __async$1 = (__this, __arguments, generator) => {
404
+ return new Promise((resolve, reject) => {
405
+ var fulfilled = (value) => {
406
+ try {
407
+ step(generator.next(value));
408
+ } catch (e) {
409
+ reject(e);
410
+ }
411
+ };
412
+ var rejected = (value) => {
413
+ try {
414
+ step(generator.throw(value));
415
+ } catch (e) {
416
+ reject(e);
417
+ }
418
+ };
419
+ var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
420
+ step((generator = generator.apply(__this, __arguments)).next());
421
+ });
422
+ };
408
423
  function apiRequest(opt) {
409
- const params = opt.params;
410
- return new CancelablePromise((resolve, reject) => {
411
- return opt.connector.connect().then((apiItems) => {
412
- let apiItem = apiItems && apiItems[opt.name];
413
- if (apiItem) {
414
- apiItem = [...apiItem];
415
- let url = apiItem.shift();
416
- if (apiItem.length) {
417
- const replaceParams = {};
418
- for (let fry = 0; fry < apiItem.length; fry++) {
419
- const arg = apiItem[fry];
420
- replaceParams[fry] = "{" + arg + "}";
421
- if (params[arg] === void 0) {
422
- throw new Error(
423
- "`" + arg + "` url api argument is not specified"
424
- );
425
- }
426
- }
427
- if (url) {
428
- url = template(url, replaceParams);
424
+ return __async$1(this, null, function* () {
425
+ const { params, name, connector, requestOptions } = opt;
426
+ const apiItems = yield connector.connect();
427
+ let apiItem = apiItems && apiItems[name];
428
+ if (apiItem) {
429
+ apiItem = [...apiItem];
430
+ let url = apiItem.shift();
431
+ if (apiItem.length) {
432
+ const replaceParams = {};
433
+ for (let fry = 0; fry < apiItem.length; fry++) {
434
+ const arg = apiItem[fry];
435
+ replaceParams[fry] = `{${arg}}`;
436
+ if (params[arg] === void 0) {
437
+ throw new Error(`\`${arg}\` URL API argument is not specified`);
429
438
  }
430
439
  }
431
- if (params) {
432
- const paramArray = [];
433
- const paramList = params.paramList;
434
- if (Array.isArray(paramList)) {
435
- delete params.paramList;
436
- paramList.forEach((x) => {
437
- paramArray.push(`${x[0]}=${x[1]}`);
438
- });
439
- }
440
- for (const p in params) {
441
- if (apiItem.indexOf(p) === -1) {
442
- paramArray.push(`${p}=${params[p]}`);
443
- }
444
- }
445
- if (paramArray.length) {
446
- url = url + "?" + paramArray.join("&");
440
+ if (url) {
441
+ url = template(url, replaceParams);
442
+ }
443
+ }
444
+ if (params) {
445
+ const paramArray = [];
446
+ const paramList = params.paramList;
447
+ if (Array.isArray(paramList)) {
448
+ paramList.forEach(([key, value]) => {
449
+ paramArray.push(`${key}=${value}`);
450
+ });
451
+ }
452
+ for (const p in params) {
453
+ if (apiItem.indexOf(p) === -1) {
454
+ paramArray.push(`${p}=${params[p]}`);
447
455
  }
448
456
  }
449
- if (url) {
450
- resolve(opt.connector.makeQuery(url, params, opt.requestOptions));
451
- } else {
452
- reject(new Error("request url is not set"));
457
+ if (paramArray.length) {
458
+ url = `${url}?${paramArray.join("&")}`;
453
459
  }
460
+ }
461
+ if (url) {
462
+ return connector.makeQuery(url, params, __spreadValues$1({
463
+ cacheName: name
464
+ }, requestOptions));
454
465
  } else {
455
- resolve(void 0);
466
+ throw new Error("Request URL is not set");
456
467
  }
457
- }).catch((er) => {
458
- reject(er);
459
- });
468
+ } else {
469
+ return void 0;
470
+ }
460
471
  });
461
472
  }
462
473
 
463
474
  var __defProp$1 = Object.defineProperty;
464
475
  var __defNormalProp$1 = (obj, key, value) => key in obj ? __defProp$1(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
465
- var __publicField$1 = (obj, key, value) => __defNormalProp$1(obj, typeof key !== "symbol" ? key + "" : key, value);
476
+ var __publicField$1 = (obj, key, value) => __defNormalProp$1(obj, key + "" , value);
466
477
  class NetworkError extends Error {
467
478
  constructor(url) {
468
479
  super();
@@ -556,6 +567,8 @@ let loadData;
556
567
  }
557
568
 
558
569
  var __defProp = Object.defineProperty;
570
+ var __defProps = Object.defineProperties;
571
+ var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
559
572
  var __getOwnPropSymbols = Object.getOwnPropertySymbols;
560
573
  var __hasOwnProp = Object.prototype.hasOwnProperty;
561
574
  var __propIsEnum = Object.prototype.propertyIsEnumerable;
@@ -571,8 +584,42 @@ var __spreadValues = (a, b) => {
571
584
  }
572
585
  return a;
573
586
  };
587
+ var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
588
+ var __objRest = (source, exclude) => {
589
+ var target = {};
590
+ for (var prop in source)
591
+ if (__hasOwnProp.call(source, prop) && exclude.indexOf(prop) < 0)
592
+ target[prop] = source[prop];
593
+ if (source != null && __getOwnPropSymbols)
594
+ for (var prop of __getOwnPropSymbols(source)) {
595
+ if (exclude.indexOf(prop) < 0 && __propIsEnum.call(source, prop))
596
+ target[prop] = source[prop];
597
+ }
598
+ return target;
599
+ };
574
600
  var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
601
+ var __async = (__this, __arguments, generator) => {
602
+ return new Promise((resolve, reject) => {
603
+ var fulfilled = (value) => {
604
+ try {
605
+ step(generator.next(value));
606
+ } catch (e) {
607
+ reject(e);
608
+ }
609
+ };
610
+ var rejected = (value) => {
611
+ try {
612
+ step(generator.throw(value));
613
+ } catch (e) {
614
+ reject(e);
615
+ }
616
+ };
617
+ var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
618
+ step((generator = generator.apply(__this, __arguments)).next());
619
+ });
620
+ };
575
621
  let ID = 0;
622
+ let REQUEST_ID = 0;
576
623
  class NgwConnector {
577
624
  constructor(options) {
578
625
  this.options = options;
@@ -582,7 +629,7 @@ class NgwConnector {
582
629
  __publicField(this, "resources");
583
630
  __publicField(this, "cache");
584
631
  __publicField(this, "routeStr", "/api/component/pyramid/route");
585
- __publicField(this, "activeRequests", []);
632
+ __publicField(this, "activeRequests", {});
586
633
  __publicField(this, "requestTransform");
587
634
  const exist = findConnector(options);
588
635
  this.cache = new Cache({ namespace: options.cacheId });
@@ -639,29 +686,27 @@ class NgwConnector {
639
686
  * ```
640
687
  */
641
688
  connect() {
642
- const auth = this.options.auth;
643
- const makeConnect = () => new CancelablePromise((resolve, reject) => {
644
- const makeQuery = () => {
645
- return this.makeQuery(this.routeStr, {}, {}).then((route) => {
646
- resolve(route);
647
- }).catch((er) => {
648
- reject(er);
649
- });
650
- };
689
+ return __async(this, null, function* () {
690
+ const auth = this.options.auth;
651
691
  if (auth) {
652
692
  const { login, password } = auth;
653
693
  if (login && password) {
654
- return this._login({ login, password }).then(() => {
655
- return makeQuery();
656
- }).catch((er) => reject(er));
694
+ yield this._login({ login, password });
657
695
  }
658
696
  }
659
- return makeQuery();
660
- });
661
- return this.cache.add("route", makeConnect, {
662
- id: this.id,
663
- auth,
664
- baseUrl: this.options.baseUrl
697
+ return yield this.makeQuery(
698
+ this.routeStr,
699
+ {},
700
+ {
701
+ cacheName: "route",
702
+ cache: true,
703
+ cacheProps: {
704
+ id: this.id,
705
+ auth,
706
+ baseUrl: this.options.baseUrl
707
+ }
708
+ }
709
+ );
665
710
  });
666
711
  }
667
712
  /**
@@ -685,20 +730,22 @@ class NgwConnector {
685
730
  this.emitter.emit("logout");
686
731
  }
687
732
  getUserInfo(credentials, options) {
688
- if (this.user && this.user.id) {
689
- return CancelablePromise.resolve(this.user);
690
- }
691
- if (credentials) {
692
- this.options.auth = credentials;
693
- }
694
- const options_ = __spreadValues({
695
- headers: this.getAuthorizationHeaders(credentials)
696
- }, options);
697
- return this.makeQuery(
698
- "/api/component/auth/current_user",
699
- {},
700
- options_
701
- );
733
+ return __async(this, null, function* () {
734
+ if (this.user && this.user.id) {
735
+ return this.user;
736
+ }
737
+ if (credentials) {
738
+ this.options.auth = credentials;
739
+ }
740
+ const options_ = __spreadValues({
741
+ headers: this.getAuthorizationHeaders(credentials)
742
+ }, options);
743
+ return this.makeQuery(
744
+ "/api/component/auth/current_user",
745
+ {},
746
+ options_
747
+ );
748
+ });
702
749
  }
703
750
  /**
704
751
  * Obtaining the required Headers for authentication of requests in the NGW.
@@ -707,7 +754,7 @@ class NgwConnector {
707
754
  const client = this.makeClientId(credentials);
708
755
  if (client) {
709
756
  return {
710
- Authorization: "Basic " + client
757
+ Authorization: `Basic ${client}`
711
758
  };
712
759
  }
713
760
  }
@@ -715,21 +762,22 @@ class NgwConnector {
715
762
  credentials = credentials || this.options.auth;
716
763
  if (credentials) {
717
764
  const { login, password } = credentials;
718
- const str = unescape(encodeURIComponent(`${login}:${password}`));
765
+ const str = `${login}:${password}`;
766
+ const encodedStr = encodeURIComponent(str);
719
767
  {
720
- return window.btoa(str);
768
+ return window.btoa(encodedStr);
721
769
  }
722
770
  }
723
771
  }
724
772
  /** Stop all api requests */
725
773
  abort() {
726
- for (const req of this.activeRequests) {
727
- req.cancel();
774
+ for (const abortController of Object.values(this.activeRequests)) {
775
+ abortController.abort();
728
776
  }
729
- this.activeRequests = [];
777
+ this.activeRequests = {};
730
778
  }
731
779
  getActiveApiRequests() {
732
- return [...this.activeRequests];
780
+ return __spreadValues({}, this.activeRequests);
733
781
  }
734
782
  /**
735
783
  * Send request to NGW api router.
@@ -761,23 +809,10 @@ class NgwConnector {
761
809
  * ```
762
810
  */
763
811
  apiRequest(name, params_ = {}, requestOptions = {}) {
764
- var _a, _b;
765
- const { method, headers, withCredentials, responseType } = requestOptions;
812
+ var _a;
766
813
  params_ = (_a = requestOptions.params) != null ? _a : params_;
767
814
  const params = objectRemoveEmpty(params_);
768
- const makeApiRequest = () => apiRequest({ name, params, requestOptions, connector: this });
769
- if (requestOptions.cache && method === "GET") {
770
- return this.cache.add(name, makeApiRequest, __spreadValues({
771
- params
772
- }, objectRemoveEmpty({
773
- headers,
774
- withCredentials,
775
- responseType,
776
- baseUrl: this.options.baseUrl,
777
- userId: (_b = this.user) == null ? void 0 : _b.id
778
- })));
779
- }
780
- return makeApiRequest();
815
+ return apiRequest({ name, params, requestOptions, connector: this });
781
816
  }
782
817
  /**
783
818
  * Shortcut method for send POST request to NGW.
@@ -867,17 +902,67 @@ class NgwConnector {
867
902
  * @param params - Query params
868
903
  * @param options - Request options
869
904
  */
870
- makeQuery(url, params, options = {}) {
871
- url = (this.options.baseUrl ? this.options.baseUrl : "") + url;
872
- if (url) {
905
+ makeQuery(_0, _1) {
906
+ return __async(this, arguments, function* (url, params, options = {}) {
907
+ var _b;
908
+ url = (this.options.baseUrl ? this.options.baseUrl : "") + url;
909
+ if (!url) {
910
+ throw new Error("Empty `url` not allowed");
911
+ }
873
912
  if (params) {
874
- url = template(url, params);
913
+ const _a = params, restParams = __objRest(_a, ["paramList"]);
914
+ url = template(url, restParams);
875
915
  }
876
916
  url = encodeURI(fixUrlStr(url));
877
- return this._loadData(url, options);
878
- } else {
879
- throw new Error("Empty `url` not allowed");
880
- }
917
+ const {
918
+ cache,
919
+ signal: externalSignal,
920
+ method = "GET",
921
+ headers,
922
+ cacheName,
923
+ cacheProps,
924
+ responseType,
925
+ withCredentials
926
+ } = options;
927
+ const internalAbortController = new AbortController();
928
+ const internalSignal = internalAbortController.signal;
929
+ if (externalSignal) {
930
+ if (externalSignal.aborted) {
931
+ throw new AbortError();
932
+ }
933
+ externalSignal.addEventListener("abort", () => {
934
+ internalAbortController.abort();
935
+ });
936
+ }
937
+ options.signal = internalSignal;
938
+ const createPromise = () => __async(this, null, function* () {
939
+ const id = REQUEST_ID++;
940
+ this.activeRequests[id] = internalAbortController;
941
+ try {
942
+ return this._loadData(url, options);
943
+ } finally {
944
+ this._cleanActiveRequest(id);
945
+ }
946
+ });
947
+ if (cache && method === "GET") {
948
+ const cacheOptions = cacheProps ? cacheProps : __spreadProps(__spreadValues({}, objectRemoveEmpty({
949
+ headers,
950
+ withCredentials,
951
+ responseType,
952
+ baseUrl: this.options.baseUrl,
953
+ userId: (_b = this.user) == null ? void 0 : _b.id
954
+ })), {
955
+ params
956
+ });
957
+ return this.cache.add(
958
+ cacheName || url,
959
+ createPromise,
960
+ cacheOptions,
961
+ false
962
+ );
963
+ }
964
+ return createPromise();
965
+ });
881
966
  }
882
967
  // -------------------------------------------------------------------------
883
968
  // Resource Methods
@@ -959,10 +1044,8 @@ class NgwConnector {
959
1044
  */
960
1045
  _loadData(url, options) {
961
1046
  options.responseType = options.responseType || "json";
962
- if (options.signal && options.signal.aborted) {
963
- return CancelablePromise.reject(new CancelablePromise.CancelError());
964
- }
965
- const request = new CancelablePromise((resolve, reject, onCancel) => {
1047
+ return new Promise((resolve, reject) => {
1048
+ var _a;
966
1049
  if (this.user) {
967
1050
  options = options || {};
968
1051
  options.headers = __spreadValues(__spreadValues({}, this.getAuthorizationHeaders()), options.headers);
@@ -972,13 +1055,18 @@ class NgwConnector {
972
1055
  url = transUrl;
973
1056
  options = transOptions;
974
1057
  }
975
- loadData(url, resolve, options, reject, onCancel);
976
- }).then((resp) => {
977
- this._cleanActiveRequests(request);
978
- return resp;
1058
+ let runOnAbort = void 0;
1059
+ loadData(url, resolve, options, reject, (handler) => {
1060
+ runOnAbort = handler;
1061
+ });
1062
+ (_a = options.signal) == null ? void 0 : _a.addEventListener("abort", () => {
1063
+ if (runOnAbort !== void 0) {
1064
+ runOnAbort();
1065
+ }
1066
+ reject(new AbortError());
1067
+ });
979
1068
  }).catch((httpError) => {
980
- this._cleanActiveRequests(request);
981
- if (httpError instanceof CancelablePromise.CancelError) ; else {
1069
+ if (httpError.name !== "AbortError") {
982
1070
  if (!!(process.env.NODE_ENV !== "production")) {
983
1071
  console.warn("DEV WARN", httpError);
984
1072
  }
@@ -987,31 +1075,24 @@ class NgwConnector {
987
1075
  throw er;
988
1076
  }
989
1077
  }
1078
+ throw httpError;
990
1079
  });
991
- if (options.signal && typeof options.signal.addEventListener === "function") {
992
- options.signal.addEventListener("abort", () => {
993
- request.cancel();
994
- this._cleanActiveRequests(request);
995
- });
996
- }
997
- this.activeRequests.push(request);
998
- return request;
999
1080
  }
1000
1081
  _login(credentials, options) {
1001
- return this.getUserInfo(credentials, options).then((data) => {
1002
- this.user = data;
1003
- this.emitter.emit("login", data);
1004
- return data;
1005
- }).catch((er) => {
1006
- this.emitter.emit("login:error", er);
1007
- throw er;
1082
+ return __async(this, null, function* () {
1083
+ try {
1084
+ const data = yield this.getUserInfo(credentials, options);
1085
+ this.user = data;
1086
+ this.emitter.emit("login", data);
1087
+ return data;
1088
+ } catch (er) {
1089
+ this.emitter.emit("login:error", er);
1090
+ throw er;
1091
+ }
1008
1092
  });
1009
1093
  }
1010
- _cleanActiveRequests(request) {
1011
- const activeRequestIndex = this.activeRequests.indexOf(request);
1012
- if (activeRequestIndex !== -1) {
1013
- this.activeRequests.splice(activeRequestIndex, 1);
1014
- }
1094
+ _cleanActiveRequest(requestId) {
1095
+ delete this.activeRequests[requestId];
1015
1096
  }
1016
1097
  _handleHttpError(er) {
1017
1098
  if (er) {