@nextgis/ngw-connector 3.0.0-alpha.8 → 3.0.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,11 +1,111 @@
1
- /** Bundle of @nextgis/ngw-connector; version: 3.0.0-alpha.8; author: NextGIS */
2
- import { objectDeepEqual, objectRemoveEmpty, fixUrlStr, defined } from '@nextgis/utils';
3
- import { EventEmitter } from 'events';
1
+ /** Bundle of @nextgis/ngw-connector; version: 3.0.1; author: NextGIS */
2
+ import { isObject as isObject$1, objectRemoveEmpty, fixUrlStr, objectDeepEqual, defined } from '@nextgis/utils';
4
3
  import Cache from '@nextgis/cache';
4
+ import { EventEmitter } from 'events';
5
+
6
+ const templateRe = /\{ *([\w_-]+) *\}/g;
7
+ function template(str, data) {
8
+ return str.replace(templateRe, (s, key) => {
9
+ let value = data[key];
10
+ if (value === void 0) {
11
+ throw new Error("No value provided for letiable " + s);
12
+ } else if (typeof value === "function") {
13
+ value = value(data);
14
+ }
15
+ return value;
16
+ });
17
+ }
18
+
19
+ var __defProp$b = Object.defineProperty;
20
+ var __getOwnPropSymbols$4 = Object.getOwnPropertySymbols;
21
+ var __hasOwnProp$4 = Object.prototype.hasOwnProperty;
22
+ var __propIsEnum$4 = Object.prototype.propertyIsEnumerable;
23
+ var __defNormalProp$b = (obj, key, value) => key in obj ? __defProp$b(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
24
+ var __spreadValues$4 = (a, b) => {
25
+ for (var prop in b || (b = {}))
26
+ if (__hasOwnProp$4.call(b, prop))
27
+ __defNormalProp$b(a, prop, b[prop]);
28
+ if (__getOwnPropSymbols$4)
29
+ for (var prop of __getOwnPropSymbols$4(b)) {
30
+ if (__propIsEnum$4.call(b, prop))
31
+ __defNormalProp$b(a, prop, b[prop]);
32
+ }
33
+ return a;
34
+ };
35
+ var __async$4 = (__this, __arguments, generator) => {
36
+ return new Promise((resolve, reject) => {
37
+ var fulfilled = (value) => {
38
+ try {
39
+ step(generator.next(value));
40
+ } catch (e) {
41
+ reject(e);
42
+ }
43
+ };
44
+ var rejected = (value) => {
45
+ try {
46
+ step(generator.throw(value));
47
+ } catch (e) {
48
+ reject(e);
49
+ }
50
+ };
51
+ var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
52
+ step((generator = generator.apply(__this, __arguments)).next());
53
+ });
54
+ };
55
+ function apiRequest(opt) {
56
+ return __async$4(this, null, function* () {
57
+ const { params, name, connector, requestOptions } = opt;
58
+ const apiItems = yield connector.connect();
59
+ let apiItem = apiItems && apiItems[name];
60
+ if (apiItem) {
61
+ apiItem = [...apiItem];
62
+ let url = apiItem.shift();
63
+ if (apiItem.length) {
64
+ const replaceParams = {};
65
+ for (let fry = 0; fry < apiItem.length; fry++) {
66
+ const arg = apiItem[fry];
67
+ replaceParams[fry] = `{${arg}}`;
68
+ if (params[arg] === void 0) {
69
+ throw new Error(`\`${arg}\` URL API argument is not specified`);
70
+ }
71
+ }
72
+ if (url) {
73
+ url = template(url, replaceParams);
74
+ }
75
+ }
76
+ if (params) {
77
+ const paramArray = [];
78
+ const paramList = params.paramList;
79
+ if (Array.isArray(paramList)) {
80
+ paramList.forEach(([key, value]) => {
81
+ paramArray.push(`${key}=${value}`);
82
+ });
83
+ }
84
+ for (const p in params) {
85
+ if (apiItem.indexOf(p) === -1) {
86
+ paramArray.push(`${p}=${params[p]}`);
87
+ }
88
+ }
89
+ if (paramArray.length) {
90
+ url = `${url}?${paramArray.join("&")}`;
91
+ }
92
+ }
93
+ if (url) {
94
+ return connector.makeQuery(url, params, __spreadValues$4({
95
+ cacheName: name
96
+ }, requestOptions));
97
+ } else {
98
+ throw new Error("Request URL is not set");
99
+ }
100
+ } else {
101
+ return void 0;
102
+ }
103
+ });
104
+ }
5
105
 
6
106
  var pkg = {
7
107
  name: "@nextgis/ngw-connector",
8
- version: "3.0.0-alpha.8",
108
+ version: "3.0.1",
9
109
  _priority: 12,
10
110
  description: "A lightweight HTTP client optimized for use with NextGIS Web API",
11
111
  main: "index.js",
@@ -14,15 +114,15 @@ var pkg = {
14
114
  jsdelivr: "lib/ngw-connector.global.prod.js",
15
115
  types: "lib/index.d.ts",
16
116
  dependencies: {
17
- "@nextgis/cache": "^3.0.0-alpha.7",
18
- "@nextgis/cancelable-promise": "^3.0.0-alpha.5",
19
- "@nextgis/utils": "^3.0.0-alpha.5",
117
+ "@nextgis/cache": "3.0.0",
118
+ "@nextgis/cancelable-promise": "3.0.0",
119
+ "@nextgis/utils": "3.0.0",
20
120
  "@types/events": "^3.0.0",
21
121
  events: "*",
22
122
  "form-data": "^4.0.0"
23
123
  },
24
124
  devDependencies: {
25
- "@nextgis/build-tools": "^3.0.0-alpha.5"
125
+ "@nextgis/build-tools": "3.0.0"
26
126
  },
27
127
  scripts: {
28
128
  clean: "rimraf ./lib",
@@ -62,30 +162,6 @@ var pkg = {
62
162
  gitHead: "edc68033f914f6c95c4125b9738bba6d36e990b4"
63
163
  };
64
164
 
65
- const CONNECTORS = [];
66
- function addConnector(connector) {
67
- CONNECTORS.push(connector);
68
- }
69
- function findConnector(options) {
70
- return CONNECTORS.find((x) => {
71
- if (x.options.baseUrl === options.baseUrl) {
72
- if (options.auth) {
73
- if (x.options.auth) {
74
- return objectDeepEqual(x.options.auth, options.auth);
75
- }
76
- } else {
77
- return true;
78
- }
79
- }
80
- });
81
- }
82
- function removeConnector(connector) {
83
- const index = CONNECTORS.indexOf(connector);
84
- if (index !== -1) {
85
- CONNECTORS.splice(index, 1);
86
- }
87
- }
88
-
89
165
  class AbortError extends Error {
90
166
  constructor(message = "AbortError") {
91
167
  super(message);
@@ -95,18 +171,18 @@ class AbortError extends Error {
95
171
 
96
172
  var __defProp$a = Object.defineProperty;
97
173
  var __defNormalProp$a = (obj, key, value) => key in obj ? __defProp$a(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
98
- var __publicField$7 = (obj, key, value) => __defNormalProp$a(obj, typeof key !== "symbol" ? key + "" : key, value);
174
+ var __publicField$8 = (obj, key, value) => __defNormalProp$a(obj, typeof key !== "symbol" ? key + "" : key, value);
99
175
  class NgwError extends Error {
100
176
  constructor(er) {
101
177
  super();
102
- __publicField$7(this, "name", "NgwError");
103
- __publicField$7(this, "title");
104
- __publicField$7(this, "message");
105
- __publicField$7(this, "detail");
106
- __publicField$7(this, "exception");
107
- __publicField$7(this, "status_code");
108
- __publicField$7(this, "data");
109
- __publicField$7(this, "guru_meditation");
178
+ __publicField$8(this, "name", "NgwError");
179
+ __publicField$8(this, "title");
180
+ __publicField$8(this, "message");
181
+ __publicField$8(this, "detail");
182
+ __publicField$8(this, "exception");
183
+ __publicField$8(this, "status_code");
184
+ __publicField$8(this, "data");
185
+ __publicField$8(this, "guru_meditation");
110
186
  Object.assign(this, er);
111
187
  Object.setPrototypeOf(this, NgwError.prototype);
112
188
  }
@@ -114,35 +190,105 @@ class NgwError extends Error {
114
190
 
115
191
  var __defProp$9 = Object.defineProperty;
116
192
  var __defNormalProp$9 = (obj, key, value) => key in obj ? __defProp$9(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
117
- var __publicField$6 = (obj, key, value) => __defNormalProp$9(obj, typeof key !== "symbol" ? key + "" : key, value);
193
+ var __publicField$7 = (obj, key, value) => __defNormalProp$9(obj, typeof key !== "symbol" ? key + "" : key, value);
118
194
  class InsufficientPermissionsError extends NgwError {
119
195
  constructor(obj) {
120
196
  super(obj);
121
- __publicField$6(this, "name", "InsufficientPermissionsError");
122
- __publicField$6(this, "exception", "nextgisweb.core.exception.InsufficientPermissions");
197
+ __publicField$7(this, "name", "InsufficientPermissionsError");
198
+ __publicField$7(this, "exception", "nextgisweb.core.exception.InsufficientPermissions");
123
199
  Object.setPrototypeOf(this, InsufficientPermissionsError.prototype);
124
200
  }
125
201
  }
126
202
 
127
203
  var __defProp$8 = Object.defineProperty;
128
204
  var __defNormalProp$8 = (obj, key, value) => key in obj ? __defProp$8(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
129
- var __publicField$5 = (obj, key, value) => __defNormalProp$8(obj, typeof key !== "symbol" ? key + "" : key, value);
130
- class ResourceNotFoundError extends NgwError {
205
+ var __publicField$6 = (obj, key, value) => __defNormalProp$8(obj, typeof key !== "symbol" ? key + "" : key, value);
206
+ let NetworksResponseError$1 = class NetworksResponseError extends NgwError {
131
207
  constructor(obj) {
132
208
  super(obj);
133
- __publicField$5(this, "name", "ResourceNotFoundError");
134
- __publicField$5(this, "exception", "nextgisweb.resource.exception.ResourceNotFound");
135
- Object.setPrototypeOf(this, ResourceNotFoundError.prototype);
209
+ __publicField$6(this, "message", "There is no response from the server or problem connecting to server.");
210
+ __publicField$6(this, "title", "Network error");
211
+ __publicField$6(this, "detail", "Check network connectivity and try again later.");
212
+ Object.setPrototypeOf(this, NetworksResponseError.prototype);
213
+ }
214
+ };
215
+
216
+ function extractError(error) {
217
+ if (isObject$1(error)) {
218
+ if (error.name && error.message && error.title) {
219
+ return {
220
+ title: error.title,
221
+ message: error.message,
222
+ detail: error.detail || null,
223
+ data: error.data && error.data.data ? error.data.data : null
224
+ };
225
+ } else if (error.exception) {
226
+ if (error.status === void 0 || error.status === 0 || error.data === void 0) {
227
+ return new NetworksResponseError$1({
228
+ title: error.title,
229
+ status_code: error.status_code,
230
+ exception: error.exception
231
+ });
232
+ }
233
+ }
234
+ return {
235
+ title: typeof error.title === "string" ? error.title : "Unexpected error",
236
+ message: typeof error.message === "string" ? error.message : "Something went wrong."
237
+ };
136
238
  }
137
239
  }
138
240
 
241
+ function isError(error) {
242
+ if (isObject$1(error)) {
243
+ return error.status_code && error.exception && error.title;
244
+ }
245
+ return false;
246
+ }
247
+
139
248
  var __defProp$7 = Object.defineProperty;
140
249
  var __defNormalProp$7 = (obj, key, value) => key in obj ? __defProp$7(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
141
- var __publicField$4 = (obj, key, value) => __defNormalProp$7(obj, typeof key !== "symbol" ? key + "" : key, value);
250
+ var __publicField$5 = (obj, key, value) => __defNormalProp$7(obj, key + "" , value);
251
+ class NetworkError extends Error {
252
+ constructor(url) {
253
+ super();
254
+ __publicField$5(this, "name", "NetworkError");
255
+ Object.setPrototypeOf(this, NetworkError.prototype);
256
+ this.message = `Unable to request ${url}.
257
+ Possibly invalid NGW URL entered or CORS not configured to get request from ${location.origin}`;
258
+ }
259
+ }
260
+
261
+ var __defProp$6 = Object.defineProperty;
262
+ var __defNormalProp$6 = (obj, key, value) => key in obj ? __defProp$6(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
263
+ var __publicField$4 = (obj, key, value) => __defNormalProp$6(obj, typeof key !== "symbol" ? key + "" : key, value);
264
+ class ResourceNotFoundError extends NgwError {
265
+ constructor(obj) {
266
+ super(obj);
267
+ __publicField$4(this, "name", "ResourceNotFoundError");
268
+ __publicField$4(this, "exception", "nextgisweb.resource.exception.ResourceNotFound");
269
+ Object.setPrototypeOf(this, ResourceNotFoundError.prototype);
270
+ }
271
+ }
272
+
273
+ var errors = /*#__PURE__*/Object.freeze({
274
+ __proto__: null,
275
+ AbortError: AbortError,
276
+ InsufficientPermissionsError: InsufficientPermissionsError,
277
+ NetworkError: NetworkError,
278
+ NetworksResponseError: NetworksResponseError$1,
279
+ NgwError: NgwError,
280
+ ResourceNotFoundError: ResourceNotFoundError,
281
+ extractError: extractError,
282
+ isError: isError
283
+ });
284
+
285
+ var __defProp$5 = Object.defineProperty;
286
+ var __defNormalProp$5 = (obj, key, value) => key in obj ? __defProp$5(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
287
+ var __publicField$3 = (obj, key, value) => __defNormalProp$5(obj, typeof key !== "symbol" ? key + "" : key, value);
142
288
  class BaseAPIError extends Error {
143
289
  constructor(message) {
144
290
  super(message || "Something went wrong.");
145
- __publicField$4(this, "title");
291
+ __publicField$3(this, "title");
146
292
  this.name = "BaseAPIError";
147
293
  this.title = "Unknown API error";
148
294
  if (Error.captureStackTrace) {
@@ -154,7 +300,7 @@ class NetworksResponseError extends BaseAPIError {
154
300
  // prettier-ignore
155
301
  constructor(message) {
156
302
  super(message || "There is no response from the server or problem connecting to server.");
157
- __publicField$4(this, "detail");
303
+ __publicField$3(this, "detail");
158
304
  this.title = "Network error";
159
305
  this.detail = "Check network connectivity and try again later.";
160
306
  }
@@ -168,8 +314,8 @@ class InvalidResponseError extends BaseAPIError {
168
314
  class ServerResponseError extends BaseAPIError {
169
315
  constructor(data) {
170
316
  super(data.message);
171
- __publicField$4(this, "detail");
172
- __publicField$4(this, "data");
317
+ __publicField$3(this, "detail");
318
+ __publicField$3(this, "data");
173
319
  this.title = data.title || this.title;
174
320
  this.detail = data.detail || null;
175
321
  this.data = data;
@@ -179,8 +325,8 @@ class LunkwillError extends Error {
179
325
  // prettier-ignore
180
326
  constructor(message, data = {}) {
181
327
  super(message || "Unexpected error while processing long-running request.");
182
- __publicField$4(this, "title");
183
- __publicField$4(this, "data");
328
+ __publicField$3(this, "title");
329
+ __publicField$3(this, "data");
184
330
  this.name = "LunkwillError";
185
331
  this.title = "Long-running request error";
186
332
  this.data = data;
@@ -200,35 +346,35 @@ class LunkwillRequestFailed extends LunkwillError {
200
346
  }
201
347
  }
202
348
 
203
- var __defProp$6 = Object.defineProperty;
204
- var __getOwnPropSymbols$4 = Object.getOwnPropertySymbols;
205
- var __hasOwnProp$4 = Object.prototype.hasOwnProperty;
206
- var __propIsEnum$4 = Object.prototype.propertyIsEnumerable;
207
- var __defNormalProp$6 = (obj, key, value) => key in obj ? __defProp$6(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
208
- var __spreadValues$4 = (a, b) => {
349
+ var __defProp$4 = Object.defineProperty;
350
+ var __getOwnPropSymbols$3 = Object.getOwnPropertySymbols;
351
+ var __hasOwnProp$3 = Object.prototype.hasOwnProperty;
352
+ var __propIsEnum$3 = Object.prototype.propertyIsEnumerable;
353
+ var __defNormalProp$4 = (obj, key, value) => key in obj ? __defProp$4(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
354
+ var __spreadValues$3 = (a, b) => {
209
355
  for (var prop in b || (b = {}))
210
- if (__hasOwnProp$4.call(b, prop))
211
- __defNormalProp$6(a, prop, b[prop]);
212
- if (__getOwnPropSymbols$4)
213
- for (var prop of __getOwnPropSymbols$4(b)) {
214
- if (__propIsEnum$4.call(b, prop))
215
- __defNormalProp$6(a, prop, b[prop]);
356
+ if (__hasOwnProp$3.call(b, prop))
357
+ __defNormalProp$4(a, prop, b[prop]);
358
+ if (__getOwnPropSymbols$3)
359
+ for (var prop of __getOwnPropSymbols$3(b)) {
360
+ if (__propIsEnum$3.call(b, prop))
361
+ __defNormalProp$4(a, prop, b[prop]);
216
362
  }
217
363
  return a;
218
364
  };
219
365
  var __objRest$2 = (source, exclude) => {
220
366
  var target = {};
221
367
  for (var prop in source)
222
- if (__hasOwnProp$4.call(source, prop) && exclude.indexOf(prop) < 0)
368
+ if (__hasOwnProp$3.call(source, prop) && exclude.indexOf(prop) < 0)
223
369
  target[prop] = source[prop];
224
- if (source != null && __getOwnPropSymbols$4)
225
- for (var prop of __getOwnPropSymbols$4(source)) {
226
- if (exclude.indexOf(prop) < 0 && __propIsEnum$4.call(source, prop))
370
+ if (source != null && __getOwnPropSymbols$3)
371
+ for (var prop of __getOwnPropSymbols$3(source)) {
372
+ if (exclude.indexOf(prop) < 0 && __propIsEnum$3.call(source, prop))
227
373
  target[prop] = source[prop];
228
374
  }
229
375
  return target;
230
376
  };
231
- var __async$4 = (__this, __arguments, generator) => {
377
+ var __async$3 = (__this, __arguments, generator) => {
232
378
  return new Promise((resolve, reject) => {
233
379
  var fulfilled = (value) => {
234
380
  try {
@@ -253,7 +399,7 @@ function lunkwillCheckResponse(lwResp) {
253
399
  return ct !== void 0 && ct !== null && ct.includes("application/vnd.lunkwill.request-summary+json");
254
400
  }
255
401
  function responseJson(response) {
256
- return __async$4(this, null, function* () {
402
+ return __async$3(this, null, function* () {
257
403
  try {
258
404
  return response.json();
259
405
  } catch (e) {
@@ -262,7 +408,7 @@ function responseJson(response) {
262
408
  });
263
409
  }
264
410
  function lunkwillResponseUrl(lwResp) {
265
- return __async$4(this, null, function* () {
411
+ return __async$3(this, null, function* () {
266
412
  const lwData = yield responseJson(lwResp);
267
413
  let delay = lwData.delay_ms;
268
414
  const retry = lwData.retry_ms !== void 0 ? lwData.retry_ms : 2e3;
@@ -306,7 +452,7 @@ function lunkwillResponseUrl(lwResp) {
306
452
  });
307
453
  }
308
454
  function lunkwillFetch(lwRespUrl) {
309
- return __async$4(this, null, function* () {
455
+ return __async$3(this, null, function* () {
310
456
  try {
311
457
  return yield window.fetch(lwRespUrl, { credentials: "same-origin" });
312
458
  } catch (e) {
@@ -354,14 +500,14 @@ function generateUrl(path, query) {
354
500
  return path + urlParams;
355
501
  }
356
502
  function request(path, options, cacheEngine) {
357
- return __async$4(this, null, function* () {
358
- var _b;
503
+ return __async$3(this, null, function* () {
504
+ var _b, _c;
359
505
  const defaults = {
360
506
  method: "GET",
361
507
  credentials: "same-origin",
362
508
  headers: {}
363
509
  };
364
- const _a = __spreadValues$4(__spreadValues$4({}, defaults), options), {
510
+ const _a = __spreadValues$3(__spreadValues$3({}, defaults), options), {
365
511
  withCredentials,
366
512
  responseType,
367
513
  cacheProps,
@@ -380,6 +526,7 @@ function request(path, options, cacheEngine) {
380
526
  "query",
381
527
  "json"
382
528
  ]);
529
+ opt.method = (_b = opt.method) == null ? void 0 : _b.toUpperCase();
383
530
  if (withCredentials) {
384
531
  opt.credentials = "include";
385
532
  }
@@ -397,12 +544,12 @@ function request(path, options, cacheEngine) {
397
544
  opt.headers = headers;
398
545
  }
399
546
  const url = generateUrl(path, query);
400
- const makeRequest = () => __async$4(this, null, function* () {
547
+ const makeRequest = () => __async$3(null, null, function* () {
401
548
  let response;
402
549
  try {
403
550
  response = yield fetch(url, opt);
404
551
  } catch (e) {
405
- if (e.name === "AbortError") {
552
+ if (opt.signal && opt.signal.aborted) {
406
553
  throw e;
407
554
  }
408
555
  throw new NetworksResponseError();
@@ -437,49 +584,61 @@ function request(path, options, cacheEngine) {
437
584
  }
438
585
  return body;
439
586
  });
440
- if (cacheEngine && cache && ((_b = opt.method) == null ? void 0 : _b.toUpperCase()) === "GET") {
441
- const cacheOptions = cacheProps ? cacheProps : __spreadValues$4({}, objectRemoveEmpty({
442
- withCredentials,
443
- responseType
444
- }));
445
- return cacheEngine.add(cacheName || url, makeRequest, cacheOptions, false);
587
+ if (cacheEngine) {
588
+ if (((_c = opt.method) == null ? void 0 : _c.toUpperCase()) === "GET") {
589
+ if (cache !== false) {
590
+ const props = cacheProps ? cacheProps : __spreadValues$3({}, objectRemoveEmpty({
591
+ withCredentials,
592
+ responseType
593
+ }));
594
+ return cacheEngine.add(cacheName || url, makeRequest, {
595
+ props,
596
+ expirationTime: cache ? void 0 : 500
597
+ });
598
+ }
599
+ } else {
600
+ const ignoredForClean = ["api/feature_layer/identify"];
601
+ if (ignoredForClean.every((part) => !path.includes(part))) {
602
+ cacheEngine.clean();
603
+ }
604
+ }
446
605
  }
447
606
  return makeRequest();
448
607
  });
449
608
  }
450
609
 
451
- var __defProp$5 = Object.defineProperty;
452
- var __defProps$1 = Object.defineProperties;
453
- var __getOwnPropDescs$1 = Object.getOwnPropertyDescriptors;
454
- var __getOwnPropSymbols$3 = Object.getOwnPropertySymbols;
455
- var __hasOwnProp$3 = Object.prototype.hasOwnProperty;
456
- var __propIsEnum$3 = Object.prototype.propertyIsEnumerable;
457
- var __defNormalProp$5 = (obj, key, value) => key in obj ? __defProp$5(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
458
- var __spreadValues$3 = (a, b) => {
610
+ var __defProp$3 = Object.defineProperty;
611
+ var __defProps$2 = Object.defineProperties;
612
+ var __getOwnPropDescs$2 = Object.getOwnPropertyDescriptors;
613
+ var __getOwnPropSymbols$2 = Object.getOwnPropertySymbols;
614
+ var __hasOwnProp$2 = Object.prototype.hasOwnProperty;
615
+ var __propIsEnum$2 = Object.prototype.propertyIsEnumerable;
616
+ var __defNormalProp$3 = (obj, key, value) => key in obj ? __defProp$3(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
617
+ var __spreadValues$2 = (a, b) => {
459
618
  for (var prop in b || (b = {}))
460
- if (__hasOwnProp$3.call(b, prop))
461
- __defNormalProp$5(a, prop, b[prop]);
462
- if (__getOwnPropSymbols$3)
463
- for (var prop of __getOwnPropSymbols$3(b)) {
464
- if (__propIsEnum$3.call(b, prop))
465
- __defNormalProp$5(a, prop, b[prop]);
619
+ if (__hasOwnProp$2.call(b, prop))
620
+ __defNormalProp$3(a, prop, b[prop]);
621
+ if (__getOwnPropSymbols$2)
622
+ for (var prop of __getOwnPropSymbols$2(b)) {
623
+ if (__propIsEnum$2.call(b, prop))
624
+ __defNormalProp$3(a, prop, b[prop]);
466
625
  }
467
626
  return a;
468
627
  };
469
- var __spreadProps$1 = (a, b) => __defProps$1(a, __getOwnPropDescs$1(b));
628
+ var __spreadProps$2 = (a, b) => __defProps$2(a, __getOwnPropDescs$2(b));
470
629
  var __objRest$1 = (source, exclude) => {
471
630
  var target = {};
472
631
  for (var prop in source)
473
- if (__hasOwnProp$3.call(source, prop) && exclude.indexOf(prop) < 0)
632
+ if (__hasOwnProp$2.call(source, prop) && exclude.indexOf(prop) < 0)
474
633
  target[prop] = source[prop];
475
- if (source != null && __getOwnPropSymbols$3)
476
- for (var prop of __getOwnPropSymbols$3(source)) {
477
- if (exclude.indexOf(prop) < 0 && __propIsEnum$3.call(source, prop))
634
+ if (source != null && __getOwnPropSymbols$2)
635
+ for (var prop of __getOwnPropSymbols$2(source)) {
636
+ if (exclude.indexOf(prop) < 0 && __propIsEnum$2.call(source, prop))
478
637
  target[prop] = source[prop];
479
638
  }
480
639
  return target;
481
640
  };
482
- var __async$3 = (__this, __arguments, generator) => {
641
+ var __async$2 = (__this, __arguments, generator) => {
483
642
  return new Promise((resolve, reject) => {
484
643
  var fulfilled = (value) => {
485
644
  try {
@@ -530,7 +689,7 @@ function routeURL(name, baseUrl, routeData, ...rest) {
530
689
  }
531
690
  function route(name, connector, ...rest) {
532
691
  const result = {
533
- url: (opt) => __async$3(this, null, function* () {
692
+ url: (opt) => __async$2(null, null, function* () {
534
693
  var _a;
535
694
  const routeData = yield connector.connect();
536
695
  const template = routeURL(
@@ -544,45 +703,37 @@ function route(name, connector, ...rest) {
544
703
  };
545
704
  const methods = ["get", "post", "put", "delete", "patch"];
546
705
  for (const method of methods) {
547
- const methodResp = (requestOptions) => __async$3(this, null, function* () {
706
+ const methodResp = (requestOptions) => {
548
707
  var _b;
549
708
  const _a = requestOptions || {}, { headers: optHeaders } = _a, restOpt = __objRest$1(_a, ["headers"]);
550
- const routeData = yield connector.connect();
551
- const template = routeURL(
552
- name,
553
- (_b = connector.options.baseUrl) != null ? _b : "",
554
- routeData,
555
- ...rest
556
- );
557
- const headers = objectRemoveEmpty(__spreadValues$3(__spreadValues$3({}, connector.getAuthorizationHeaders()), optHeaders != null ? optHeaders : {}));
558
- return request(
559
- template,
560
- __spreadProps$1(__spreadValues$3({
561
- headers
562
- }, restOpt), {
563
- method
564
- }),
565
- connector.cache
566
- );
567
- });
709
+ if ((_b = requestOptions == null ? void 0 : requestOptions.signal) == null ? void 0 : _b.aborted) {
710
+ throw new AbortError();
711
+ }
712
+ return connector.connect().then((routeData) => {
713
+ var _a2;
714
+ const template = routeURL(
715
+ name,
716
+ (_a2 = connector.options.baseUrl) != null ? _a2 : "",
717
+ routeData,
718
+ ...rest
719
+ );
720
+ const headers = objectRemoveEmpty(__spreadValues$2(__spreadValues$2({}, connector.getAuthorizationHeaders()), optHeaders != null ? optHeaders : {}));
721
+ return request(
722
+ template,
723
+ __spreadProps$2(__spreadValues$2({
724
+ headers
725
+ }, restOpt), {
726
+ method
727
+ }),
728
+ connector.cache
729
+ );
730
+ });
731
+ };
568
732
  result[method] = methodResp;
569
733
  }
570
734
  return result;
571
735
  }
572
736
 
573
- var __defProp$4 = Object.defineProperty;
574
- var __defNormalProp$4 = (obj, key, value) => key in obj ? __defProp$4(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
575
- var __publicField$3 = (obj, key, value) => __defNormalProp$4(obj, key + "" , value);
576
- class NetworkError extends Error {
577
- constructor(url) {
578
- super();
579
- __publicField$3(this, "name", "NetworkError");
580
- Object.setPrototypeOf(this, NetworkError.prototype);
581
- this.message = `Unable to request ${url}.
582
- Possibly invalid NGW URL entered or CORS not configured to get request from ${location.origin}`;
583
- }
584
- }
585
-
586
737
  function isObject(val) {
587
738
  return Object.prototype.toString.call(val) === "[object Object]";
588
739
  }
@@ -599,7 +750,7 @@ let loadData;
599
750
  const getResponseText = () => {
600
751
  try {
601
752
  return JSON.parse(xhr.responseText);
602
- } catch (er) {
753
+ } catch (e) {
603
754
  return xhr.responseText;
604
755
  }
605
756
  };
@@ -669,52 +820,63 @@ let loadData;
669
820
  };
670
821
  }
671
822
 
672
- const templateRe = /\{ *([\w_-]+) *\}/g;
673
- function template(str, data) {
674
- return str.replace(templateRe, (s, key) => {
675
- let value = data[key];
676
- if (value === void 0) {
677
- throw new Error("No value provided for letiable " + s);
678
- } else if (typeof value === "function") {
679
- value = value(data);
823
+ const CONNECTORS = [];
824
+ function addConnector(connector) {
825
+ CONNECTORS.push(connector);
826
+ }
827
+ function findConnector(options) {
828
+ return CONNECTORS.find((x) => {
829
+ if (x.options.baseUrl === options.baseUrl) {
830
+ if (options.auth) {
831
+ if (x.options.auth) {
832
+ return objectDeepEqual(x.options.auth, options.auth);
833
+ }
834
+ } else {
835
+ return true;
836
+ }
680
837
  }
681
- return value;
682
838
  });
683
839
  }
840
+ function removeConnector(connector) {
841
+ const index = CONNECTORS.indexOf(connector);
842
+ if (index !== -1) {
843
+ CONNECTORS.splice(index, 1);
844
+ }
845
+ }
684
846
 
685
- var __defProp$3 = Object.defineProperty;
686
- var __defProps = Object.defineProperties;
687
- var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
688
- var __getOwnPropSymbols$2 = Object.getOwnPropertySymbols;
689
- var __hasOwnProp$2 = Object.prototype.hasOwnProperty;
690
- var __propIsEnum$2 = Object.prototype.propertyIsEnumerable;
691
- var __defNormalProp$3 = (obj, key, value) => key in obj ? __defProp$3(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
692
- var __spreadValues$2 = (a, b) => {
847
+ var __defProp$2 = Object.defineProperty;
848
+ var __defProps$1 = Object.defineProperties;
849
+ var __getOwnPropDescs$1 = Object.getOwnPropertyDescriptors;
850
+ var __getOwnPropSymbols$1 = Object.getOwnPropertySymbols;
851
+ var __hasOwnProp$1 = Object.prototype.hasOwnProperty;
852
+ var __propIsEnum$1 = Object.prototype.propertyIsEnumerable;
853
+ var __defNormalProp$2 = (obj, key, value) => key in obj ? __defProp$2(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
854
+ var __spreadValues$1 = (a, b) => {
693
855
  for (var prop in b || (b = {}))
694
- if (__hasOwnProp$2.call(b, prop))
695
- __defNormalProp$3(a, prop, b[prop]);
696
- if (__getOwnPropSymbols$2)
697
- for (var prop of __getOwnPropSymbols$2(b)) {
698
- if (__propIsEnum$2.call(b, prop))
699
- __defNormalProp$3(a, prop, b[prop]);
856
+ if (__hasOwnProp$1.call(b, prop))
857
+ __defNormalProp$2(a, prop, b[prop]);
858
+ if (__getOwnPropSymbols$1)
859
+ for (var prop of __getOwnPropSymbols$1(b)) {
860
+ if (__propIsEnum$1.call(b, prop))
861
+ __defNormalProp$2(a, prop, b[prop]);
700
862
  }
701
863
  return a;
702
864
  };
703
- var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
865
+ var __spreadProps$1 = (a, b) => __defProps$1(a, __getOwnPropDescs$1(b));
704
866
  var __objRest = (source, exclude) => {
705
867
  var target = {};
706
868
  for (var prop in source)
707
- if (__hasOwnProp$2.call(source, prop) && exclude.indexOf(prop) < 0)
869
+ if (__hasOwnProp$1.call(source, prop) && exclude.indexOf(prop) < 0)
708
870
  target[prop] = source[prop];
709
- if (source != null && __getOwnPropSymbols$2)
710
- for (var prop of __getOwnPropSymbols$2(source)) {
711
- if (exclude.indexOf(prop) < 0 && __propIsEnum$2.call(source, prop))
871
+ if (source != null && __getOwnPropSymbols$1)
872
+ for (var prop of __getOwnPropSymbols$1(source)) {
873
+ if (exclude.indexOf(prop) < 0 && __propIsEnum$1.call(source, prop))
712
874
  target[prop] = source[prop];
713
875
  }
714
876
  return target;
715
877
  };
716
- var __publicField$2 = (obj, key, value) => __defNormalProp$3(obj, typeof key !== "symbol" ? key + "" : key, value);
717
- var __async$2 = (__this, __arguments, generator) => {
878
+ var __publicField$2 = (obj, key, value) => __defNormalProp$2(obj, typeof key !== "symbol" ? key + "" : key, value);
879
+ var __async$1 = (__this, __arguments, generator) => {
718
880
  return new Promise((resolve, reject) => {
719
881
  var fulfilled = (value) => {
720
882
  try {
@@ -744,12 +906,16 @@ class NgwConnector {
744
906
  __publicField$2(this, "user");
745
907
  __publicField$2(this, "cache");
746
908
  __publicField$2(this, "withCredentials");
909
+ // Dedicated cache for route requests, as these are executed before any other requests.
910
+ // This cache does not need to be cleared during the session.
911
+ __publicField$2(this, "routeCache");
747
912
  __publicField$2(this, "client", `NextGIS-NGW-Connector/${pkg.version}`);
748
913
  __publicField$2(this, "routeStr", "/api/component/pyramid/route");
749
914
  __publicField$2(this, "activeRequests", {});
750
915
  __publicField$2(this, "requestTransform");
751
916
  const exist = findConnector(options);
752
917
  this.cache = new Cache({ namespace: options.cacheId });
918
+ this.routeCache = new Cache({ namespace: "routecache" });
753
919
  if (exist) {
754
920
  return exist;
755
921
  } else {
@@ -799,7 +965,9 @@ class NgwConnector {
799
965
  * ```
800
966
  */
801
967
  connect() {
802
- return __async$2(this, null, function* () {
968
+ return __async$1(this, arguments, function* ({
969
+ signal
970
+ } = {}) {
803
971
  const auth = this.options.auth;
804
972
  if (auth) {
805
973
  const { login, password } = auth;
@@ -808,18 +976,9 @@ class NgwConnector {
808
976
  }
809
977
  }
810
978
  const routeUrl = `${this.routeStr}?client=${this.client}`;
811
- return yield this.makeQuery(
812
- routeUrl,
813
- {},
814
- {
815
- cacheName: "route",
816
- cache: true,
817
- cacheProps: {
818
- id: this.id,
819
- auth,
820
- baseUrl: this.options.baseUrl
821
- }
822
- }
979
+ return this.routeCache.add(
980
+ this.options.baseUrl || String(this.id),
981
+ () => this.makeQuery(routeUrl, null, { signal, cache: false })
823
982
  );
824
983
  });
825
984
  }
@@ -840,18 +999,19 @@ class NgwConnector {
840
999
  removeConnector(this);
841
1000
  this.options.auth = void 0;
842
1001
  this.user = void 0;
1002
+ this.routeCache.clean();
843
1003
  this.clearCache();
844
1004
  this.emitter.emit("logout");
845
1005
  }
846
1006
  getUserInfo(credentials, options) {
847
- return __async$2(this, null, function* () {
1007
+ return __async$1(this, null, function* () {
848
1008
  if (this.user && this.user.id) {
849
1009
  return this.user;
850
1010
  }
851
1011
  if (credentials) {
852
1012
  this.options.auth = credentials;
853
1013
  }
854
- const options_ = __spreadValues$2({
1014
+ const options_ = __spreadValues$1({
855
1015
  headers: this.getAuthorizationHeaders(credentials),
856
1016
  cache: true
857
1017
  }, options);
@@ -878,7 +1038,7 @@ class NgwConnector {
878
1038
  credentials = credentials || this.options.auth;
879
1039
  if (credentials) {
880
1040
  const { login, password } = credentials;
881
- const encodedStr = [login, password].map(encodeURIComponent).join(":");
1041
+ const encodedStr = `${login}:${password}`;
882
1042
  {
883
1043
  return window.btoa(encodedStr);
884
1044
  }
@@ -892,7 +1052,7 @@ class NgwConnector {
892
1052
  this.activeRequests = {};
893
1053
  }
894
1054
  getActiveApiRequests() {
895
- return __spreadValues$2({}, this.activeRequests);
1055
+ return __spreadValues$1({}, this.activeRequests);
896
1056
  }
897
1057
  route(name, ...rest) {
898
1058
  return route(name, this, ...rest);
@@ -904,7 +1064,7 @@ class NgwConnector {
904
1064
  * @param options - Request options
905
1065
  */
906
1066
  makeQuery(_0, _1) {
907
- return __async$2(this, arguments, function* (url, params, options = {}) {
1067
+ return __async$1(this, arguments, function* (url, params, options = {}) {
908
1068
  var _b;
909
1069
  url = (this.options.baseUrl ? this.options.baseUrl : "") + url;
910
1070
  if (!url) {
@@ -915,7 +1075,7 @@ class NgwConnector {
915
1075
  url = template(url, restParams);
916
1076
  }
917
1077
  url = encodeURI(fixUrlStr(url));
918
- options = __spreadValues$2({ withCredentials: this.withCredentials }, options);
1078
+ options = __spreadValues$1({ withCredentials: this.withCredentials }, options);
919
1079
  const {
920
1080
  cache,
921
1081
  signal: externalSignal,
@@ -937,7 +1097,7 @@ class NgwConnector {
937
1097
  });
938
1098
  }
939
1099
  options.signal = internalSignal;
940
- const createPromise = () => __async$2(this, null, function* () {
1100
+ const createPromise = () => __async$1(this, null, function* () {
941
1101
  const id = REQUEST_ID++;
942
1102
  this.activeRequests[id] = internalAbortController;
943
1103
  try {
@@ -946,8 +1106,8 @@ class NgwConnector {
946
1106
  this._cleanActiveRequest(id);
947
1107
  }
948
1108
  });
949
- if (method === "GET") {
950
- const cacheOptions = cacheProps ? cacheProps : __spreadProps(__spreadValues$2({}, objectRemoveEmpty({
1109
+ if (method === "GET" && cache !== false) {
1110
+ const cacheOptions = cacheProps ? cacheProps : __spreadProps$1(__spreadValues$1({}, objectRemoveEmpty({
951
1111
  headers,
952
1112
  withCredentials,
953
1113
  responseType,
@@ -970,7 +1130,7 @@ class NgwConnector {
970
1130
  var _a;
971
1131
  if (this.user) {
972
1132
  options = options || {};
973
- options.headers = __spreadValues$2(__spreadValues$2({}, this.getAuthorizationHeaders()), options.headers);
1133
+ options.headers = __spreadValues$1(__spreadValues$1({}, this.getAuthorizationHeaders()), options.headers);
974
1134
  }
975
1135
  if (this.requestTransform) {
976
1136
  const [transUrl, transOptions] = this.requestTransform(url, options);
@@ -1001,7 +1161,7 @@ class NgwConnector {
1001
1161
  });
1002
1162
  }
1003
1163
  _login(credentials, options) {
1004
- return __async$2(this, null, function* () {
1164
+ return __async$1(this, null, function* () {
1005
1165
  try {
1006
1166
  const data = yield this.getUserInfo(credentials, options);
1007
1167
  this.user = data;
@@ -1029,10 +1189,7 @@ class NgwConnector {
1029
1189
  return er;
1030
1190
  }
1031
1191
  }
1032
- __publicField$2(NgwConnector, "errors", {
1033
- NgwError,
1034
- ResourceNotFoundError
1035
- });
1192
+ __publicField$2(NgwConnector, "errors", errors);
1036
1193
 
1037
1194
  function resourceCompare(res1, res2) {
1038
1195
  return objectDeepEqual(res1, res2);
@@ -1046,7 +1203,10 @@ function resourceToQuery(resource, prefix = "") {
1046
1203
  if (exclude.indexOf(key) === -1) {
1047
1204
  if (isObject(value)) {
1048
1205
  if (key === "owner_user") {
1049
- const children = resourceToQuery(value, key);
1206
+ const children = resourceToQuery(
1207
+ value,
1208
+ key
1209
+ );
1050
1210
  Object.assign(query, children);
1051
1211
  } else if (key === "parent" && "id" in value) {
1052
1212
  query.parent_id = value.id;
@@ -1059,24 +1219,27 @@ function resourceToQuery(resource, prefix = "") {
1059
1219
  return query;
1060
1220
  }
1061
1221
 
1062
- var __defProp$2 = Object.defineProperty;
1063
- var __getOwnPropSymbols$1 = Object.getOwnPropertySymbols;
1064
- var __hasOwnProp$1 = Object.prototype.hasOwnProperty;
1065
- var __propIsEnum$1 = Object.prototype.propertyIsEnumerable;
1066
- var __defNormalProp$2 = (obj, key, value) => key in obj ? __defProp$2(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
1067
- var __spreadValues$1 = (a, b) => {
1222
+ var __defProp$1 = Object.defineProperty;
1223
+ var __defProps = Object.defineProperties;
1224
+ var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
1225
+ var __getOwnPropSymbols = Object.getOwnPropertySymbols;
1226
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
1227
+ var __propIsEnum = Object.prototype.propertyIsEnumerable;
1228
+ var __defNormalProp$1 = (obj, key, value) => key in obj ? __defProp$1(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
1229
+ var __spreadValues = (a, b) => {
1068
1230
  for (var prop in b || (b = {}))
1069
- if (__hasOwnProp$1.call(b, prop))
1070
- __defNormalProp$2(a, prop, b[prop]);
1071
- if (__getOwnPropSymbols$1)
1072
- for (var prop of __getOwnPropSymbols$1(b)) {
1073
- if (__propIsEnum$1.call(b, prop))
1074
- __defNormalProp$2(a, prop, b[prop]);
1231
+ if (__hasOwnProp.call(b, prop))
1232
+ __defNormalProp$1(a, prop, b[prop]);
1233
+ if (__getOwnPropSymbols)
1234
+ for (var prop of __getOwnPropSymbols(b)) {
1235
+ if (__propIsEnum.call(b, prop))
1236
+ __defNormalProp$1(a, prop, b[prop]);
1075
1237
  }
1076
1238
  return a;
1077
1239
  };
1078
- var __publicField$1 = (obj, key, value) => __defNormalProp$2(obj, typeof key !== "symbol" ? key + "" : key, value);
1079
- var __async$1 = (__this, __arguments, generator) => {
1240
+ var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
1241
+ var __publicField$1 = (obj, key, value) => __defNormalProp$1(obj, typeof key !== "symbol" ? key + "" : key, value);
1242
+ var __async = (__this, __arguments, generator) => {
1080
1243
  return new Promise((resolve, reject) => {
1081
1244
  var fulfilled = (value) => {
1082
1245
  try {
@@ -1117,7 +1280,7 @@ class ResourcesControl {
1117
1280
  * Fetching resource would be cached to speed up next call
1118
1281
  */
1119
1282
  getOne(resource, requestOptions) {
1120
- const opt = __spreadValues$1({}, requestOptions);
1283
+ const opt = __spreadValues({}, requestOptions);
1121
1284
  if (typeof resource === "string") ; else if (typeof resource === "number") ; else if (isObject(resource)) {
1122
1285
  if (resource.id !== void 0) {
1123
1286
  resource.id;
@@ -1194,9 +1357,11 @@ class ResourcesControl {
1194
1357
  } else {
1195
1358
  Object.assign(query, resourceToQuery(resource));
1196
1359
  }
1197
- return this.connector.get("resource.search", requestOptions, __spreadValues$1({
1198
- serialization: "full"
1199
- }, query)).then((resources) => {
1360
+ return this.connector.route("resource.search").get(__spreadProps(__spreadValues({}, requestOptions), {
1361
+ query: __spreadValues({
1362
+ serialization: "full"
1363
+ }, query)
1364
+ })).then((resources) => {
1200
1365
  if ((requestOptions == null ? void 0 : requestOptions.cache) && resources) {
1201
1366
  for (const x of resources) {
1202
1367
  this.cache.add("resource.item", Promise.resolve(x), {
@@ -1212,7 +1377,8 @@ class ResourcesControl {
1212
1377
  }
1213
1378
  getParent(resource, requestOptions) {
1214
1379
  return this.getOne(resource, requestOptions).then((child) => {
1215
- if (child) {
1380
+ var _a, _b;
1381
+ if ((_b = (_a = child == null ? void 0 : child.resource) == null ? void 0 : _a.parent) == null ? void 0 : _b.id) {
1216
1382
  return this.getOne(child.resource.parent.id, requestOptions);
1217
1383
  }
1218
1384
  return Promise.resolve(void 0);
@@ -1244,10 +1410,21 @@ class ResourcesControl {
1244
1410
  }
1245
1411
  });
1246
1412
  }
1247
- _getChildrenOf(parent, requestOptions, _items = []) {
1248
- return this.connector.get("resource.collection", requestOptions, {
1249
- parent
1250
- }).then((items) => {
1413
+ _getChildrenOf(_0, _1) {
1414
+ return __async(this, arguments, function* (parentDef, requestOptions, _items = []) {
1415
+ let parent = void 0;
1416
+ if (typeof parentDef === "string") {
1417
+ parent = yield this.getId(parentDef, requestOptions);
1418
+ } else if (typeof parentDef === "object") {
1419
+ parent = parentDef.id;
1420
+ } else {
1421
+ parent = parentDef;
1422
+ }
1423
+ const items = yield this.connector.route("resource.collection").get(__spreadProps(__spreadValues({}, requestOptions), {
1424
+ query: {
1425
+ parent
1426
+ }
1427
+ }));
1251
1428
  const recursivePromises = [];
1252
1429
  for (const item of items) {
1253
1430
  if (requestOptions == null ? void 0 : requestOptions.cache) {
@@ -1271,7 +1448,7 @@ class ResourcesControl {
1271
1448
  });
1272
1449
  }
1273
1450
  _cleanResourceItemCache(id) {
1274
- return __async$1(this, null, function* () {
1451
+ return __async(this, null, function* () {
1275
1452
  var _a;
1276
1453
  const all = this.cache.all();
1277
1454
  const toDelete = [];
@@ -1296,7 +1473,7 @@ class ResourcesControl {
1296
1473
  });
1297
1474
  }
1298
1475
  _fetchResourceById(id, requestOptions) {
1299
- return this.connector.get("resource.item", requestOptions, { id });
1476
+ return this.connector.route("resource.item", { id }).get(requestOptions);
1300
1477
  }
1301
1478
  _fetchResourceBy(resource, requestOptions) {
1302
1479
  return this.getMany(resource, requestOptions).then((resources) => {
@@ -1324,93 +1501,6 @@ class ResourcesControl {
1324
1501
  }
1325
1502
  }
1326
1503
 
1327
- var __defProp$1 = Object.defineProperty;
1328
- var __getOwnPropSymbols = Object.getOwnPropertySymbols;
1329
- var __hasOwnProp = Object.prototype.hasOwnProperty;
1330
- var __propIsEnum = Object.prototype.propertyIsEnumerable;
1331
- var __defNormalProp$1 = (obj, key, value) => key in obj ? __defProp$1(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
1332
- var __spreadValues = (a, b) => {
1333
- for (var prop in b || (b = {}))
1334
- if (__hasOwnProp.call(b, prop))
1335
- __defNormalProp$1(a, prop, b[prop]);
1336
- if (__getOwnPropSymbols)
1337
- for (var prop of __getOwnPropSymbols(b)) {
1338
- if (__propIsEnum.call(b, prop))
1339
- __defNormalProp$1(a, prop, b[prop]);
1340
- }
1341
- return a;
1342
- };
1343
- var __async = (__this, __arguments, generator) => {
1344
- return new Promise((resolve, reject) => {
1345
- var fulfilled = (value) => {
1346
- try {
1347
- step(generator.next(value));
1348
- } catch (e) {
1349
- reject(e);
1350
- }
1351
- };
1352
- var rejected = (value) => {
1353
- try {
1354
- step(generator.throw(value));
1355
- } catch (e) {
1356
- reject(e);
1357
- }
1358
- };
1359
- var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
1360
- step((generator = generator.apply(__this, __arguments)).next());
1361
- });
1362
- };
1363
- function apiRequest(opt) {
1364
- return __async(this, null, function* () {
1365
- const { params, name, connector, requestOptions } = opt;
1366
- const apiItems = yield connector.connect();
1367
- let apiItem = apiItems && apiItems[name];
1368
- if (apiItem) {
1369
- apiItem = [...apiItem];
1370
- let url = apiItem.shift();
1371
- if (apiItem.length) {
1372
- const replaceParams = {};
1373
- for (let fry = 0; fry < apiItem.length; fry++) {
1374
- const arg = apiItem[fry];
1375
- replaceParams[fry] = `{${arg}}`;
1376
- if (params[arg] === void 0) {
1377
- throw new Error(`\`${arg}\` URL API argument is not specified`);
1378
- }
1379
- }
1380
- if (url) {
1381
- url = template(url, replaceParams);
1382
- }
1383
- }
1384
- if (params) {
1385
- const paramArray = [];
1386
- const paramList = params.paramList;
1387
- if (Array.isArray(paramList)) {
1388
- paramList.forEach(([key, value]) => {
1389
- paramArray.push(`${key}=${value}`);
1390
- });
1391
- }
1392
- for (const p in params) {
1393
- if (apiItem.indexOf(p) === -1) {
1394
- paramArray.push(`${p}=${params[p]}`);
1395
- }
1396
- }
1397
- if (paramArray.length) {
1398
- url = `${url}?${paramArray.join("&")}`;
1399
- }
1400
- }
1401
- if (url) {
1402
- return connector.makeQuery(url, params, __spreadValues({
1403
- cacheName: name
1404
- }, requestOptions));
1405
- } else {
1406
- throw new Error("Request URL is not set");
1407
- }
1408
- } else {
1409
- return void 0;
1410
- }
1411
- });
1412
- }
1413
-
1414
1504
  var __defProp = Object.defineProperty;
1415
1505
  var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
1416
1506
  var __publicField = (obj, key, value) => __defNormalProp(obj, key + "" , value);