@nextgis/geocoder 3.0.0-alpha.2 → 3.0.0-alpha.20
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/geocoder.cjs.js +98 -84
- package/lib/geocoder.cjs.js.map +1 -1
- package/lib/geocoder.cjs.prod.js +1 -1
- package/lib/geocoder.cjs.prod.js.map +1 -1
- package/lib/geocoder.esm-browser.js +1528 -960
- package/lib/geocoder.esm-browser.js.map +1 -1
- package/lib/geocoder.esm-browser.prod.js +1 -1
- package/lib/geocoder.esm-browser.prod.js.map +1 -1
- package/lib/geocoder.esm-bundler.js +98 -84
- package/lib/geocoder.esm-bundler.js.map +1 -1
- package/lib/geocoder.esm-bundler.prod.js +1 -1
- package/lib/geocoder.esm-bundler.prod.js.map +1 -1
- package/lib/geocoder.global.js +1528 -960
- package/lib/geocoder.global.js.map +1 -1
- package/lib/geocoder.global.prod.js +1 -1
- package/lib/geocoder.global.prod.js.map +1 -1
- package/lib/index.d.ts +40 -21
- package/package.json +7 -7
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
/** Bundle of @nextgis/geocoder; version: 3.0.0-alpha.
|
|
1
|
+
/** Bundle of @nextgis/geocoder; version: 3.0.0-alpha.20; author: NextGIS */
|
|
2
2
|
function defined(val) {
|
|
3
3
|
return val !== void 0 && val !== null;
|
|
4
4
|
}
|
|
@@ -6,14 +6,6 @@ function full(val) {
|
|
|
6
6
|
return typeof val === "string" ? !!val : defined(val);
|
|
7
7
|
}
|
|
8
8
|
|
|
9
|
-
function getBoundsCoordinates(b) {
|
|
10
|
-
const westNorth = [b[0], b[1]];
|
|
11
|
-
const eastNorth = [b[2], b[1]];
|
|
12
|
-
const eastSouth = [b[2], b[3]];
|
|
13
|
-
const westSouth = [b[0], b[3]];
|
|
14
|
-
return [westNorth, eastNorth, eastSouth, westSouth, westNorth];
|
|
15
|
-
}
|
|
16
|
-
|
|
17
9
|
function degrees2meters(lng, lat) {
|
|
18
10
|
lat = lat > 85.06 ? 85.06 : lat < -85.06 ? -85.06 : lat;
|
|
19
11
|
const x = lng * 2003750834e-2 / 180;
|
|
@@ -22,10 +14,23 @@ function degrees2meters(lng, lat) {
|
|
|
22
14
|
return [x, y];
|
|
23
15
|
}
|
|
24
16
|
|
|
17
|
+
function getBoundsCoordinates(b) {
|
|
18
|
+
const westNorth = [b[0], b[1]];
|
|
19
|
+
const eastNorth = [b[2], b[1]];
|
|
20
|
+
const eastSouth = [b[2], b[3]];
|
|
21
|
+
const westSouth = [b[0], b[3]];
|
|
22
|
+
return [westNorth, eastNorth, eastSouth, westSouth, westNorth];
|
|
23
|
+
}
|
|
24
|
+
|
|
25
25
|
function isLngLatBoundsArray(array) {
|
|
26
26
|
return Array.isArray(array) && array.length === 4 && array.every((x) => typeof x === "number");
|
|
27
27
|
}
|
|
28
28
|
|
|
29
|
+
function round(val, toFixed) {
|
|
30
|
+
const n = 1;
|
|
31
|
+
return Math.round((val + Number.EPSILON) * n) / n;
|
|
32
|
+
}
|
|
33
|
+
|
|
29
34
|
function objectAssign(target, ...sources) {
|
|
30
35
|
for (const source of sources) {
|
|
31
36
|
for (const prop of Object.getOwnPropertyNames(source)) {
|
|
@@ -80,11 +85,6 @@ function objectRemoveEmpty(obj) {
|
|
|
80
85
|
return newObj;
|
|
81
86
|
}
|
|
82
87
|
|
|
83
|
-
function round(val, toFixed) {
|
|
84
|
-
const n = 1;
|
|
85
|
-
return Math.round((val + Number.EPSILON) * n) / n;
|
|
86
|
-
}
|
|
87
|
-
|
|
88
88
|
function isObject$1(val) {
|
|
89
89
|
return Object.prototype.toString.call(val) === "[object Object]";
|
|
90
90
|
}
|
|
@@ -104,28 +104,28 @@ class BaseGeocoder {
|
|
|
104
104
|
}
|
|
105
105
|
}
|
|
106
106
|
|
|
107
|
-
var __defProp$
|
|
108
|
-
var __defProps$
|
|
109
|
-
var __getOwnPropDescs$
|
|
110
|
-
var __getOwnPropSymbols$
|
|
111
|
-
var __hasOwnProp$
|
|
112
|
-
var __propIsEnum$
|
|
107
|
+
var __defProp$i = Object.defineProperty;
|
|
108
|
+
var __defProps$5 = Object.defineProperties;
|
|
109
|
+
var __getOwnPropDescs$5 = Object.getOwnPropertyDescriptors;
|
|
110
|
+
var __getOwnPropSymbols$8 = Object.getOwnPropertySymbols;
|
|
111
|
+
var __hasOwnProp$8 = Object.prototype.hasOwnProperty;
|
|
112
|
+
var __propIsEnum$8 = Object.prototype.propertyIsEnumerable;
|
|
113
113
|
var __knownSymbol$2 = (name, symbol) => (symbol = Symbol[name]) ? symbol : Symbol.for("Symbol." + name);
|
|
114
|
-
var __defNormalProp$
|
|
115
|
-
var __spreadValues$
|
|
114
|
+
var __defNormalProp$i = (obj, key, value) => key in obj ? __defProp$i(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
115
|
+
var __spreadValues$8 = (a, b) => {
|
|
116
116
|
for (var prop in b || (b = {}))
|
|
117
|
-
if (__hasOwnProp$
|
|
118
|
-
__defNormalProp$
|
|
119
|
-
if (__getOwnPropSymbols$
|
|
120
|
-
for (var prop of __getOwnPropSymbols$
|
|
121
|
-
if (__propIsEnum$
|
|
122
|
-
__defNormalProp$
|
|
117
|
+
if (__hasOwnProp$8.call(b, prop))
|
|
118
|
+
__defNormalProp$i(a, prop, b[prop]);
|
|
119
|
+
if (__getOwnPropSymbols$8)
|
|
120
|
+
for (var prop of __getOwnPropSymbols$8(b)) {
|
|
121
|
+
if (__propIsEnum$8.call(b, prop))
|
|
122
|
+
__defNormalProp$i(a, prop, b[prop]);
|
|
123
123
|
}
|
|
124
124
|
return a;
|
|
125
125
|
};
|
|
126
|
-
var __spreadProps$
|
|
127
|
-
var __publicField$
|
|
128
|
-
var __async$
|
|
126
|
+
var __spreadProps$5 = (a, b) => __defProps$5(a, __getOwnPropDescs$5(b));
|
|
127
|
+
var __publicField$d = (obj, key, value) => __defNormalProp$i(obj, key + "" , value);
|
|
128
|
+
var __async$7 = (__this, __arguments, generator) => {
|
|
129
129
|
return new Promise((resolve, reject) => {
|
|
130
130
|
var fulfilled = (value) => {
|
|
131
131
|
try {
|
|
@@ -165,7 +165,7 @@ let ID$1 = 0;
|
|
|
165
165
|
class Geocoder extends BaseGeocoder {
|
|
166
166
|
constructor(options) {
|
|
167
167
|
super(options);
|
|
168
|
-
__publicField$
|
|
168
|
+
__publicField$d(this, "providers", []);
|
|
169
169
|
if (options && options.providers) {
|
|
170
170
|
this.providers = options.providers;
|
|
171
171
|
}
|
|
@@ -189,7 +189,7 @@ class Geocoder extends BaseGeocoder {
|
|
|
189
189
|
for (var iter = __forAwait(results), more, temp, error; more = !(temp = yield new __await$2(iter.next())).done; more = false) {
|
|
190
190
|
const r = temp.value;
|
|
191
191
|
allProvidersFailed = false;
|
|
192
|
-
yield __spreadProps$
|
|
192
|
+
yield __spreadProps$5(__spreadValues$8({}, r), { provider, _id: ID$1++ });
|
|
193
193
|
}
|
|
194
194
|
} catch (temp) {
|
|
195
195
|
error = [temp];
|
|
@@ -203,7 +203,7 @@ class Geocoder extends BaseGeocoder {
|
|
|
203
203
|
}
|
|
204
204
|
} catch (err) {
|
|
205
205
|
const er = err;
|
|
206
|
-
if (er.name !== "
|
|
206
|
+
if (er.name !== "AbortError") {
|
|
207
207
|
errors.push(er);
|
|
208
208
|
}
|
|
209
209
|
}
|
|
@@ -232,7 +232,7 @@ class Geocoder extends BaseGeocoder {
|
|
|
232
232
|
try {
|
|
233
233
|
for (var iter = __forAwait(results), more, temp, error; more = !(temp = yield new __await$2(iter.next())).done; more = false) {
|
|
234
234
|
const r = temp.value;
|
|
235
|
-
yield __spreadProps$
|
|
235
|
+
yield __spreadProps$5(__spreadValues$8({}, r), { provider, _id: ID$1++ });
|
|
236
236
|
}
|
|
237
237
|
} catch (temp) {
|
|
238
238
|
error = [temp];
|
|
@@ -244,7 +244,7 @@ class Geocoder extends BaseGeocoder {
|
|
|
244
244
|
throw error[0];
|
|
245
245
|
}
|
|
246
246
|
}
|
|
247
|
-
} catch (
|
|
247
|
+
} catch (e) {
|
|
248
248
|
}
|
|
249
249
|
}
|
|
250
250
|
});
|
|
@@ -256,7 +256,7 @@ class Geocoder extends BaseGeocoder {
|
|
|
256
256
|
* @returns A promise that resolves to the first reverse geocoding result, or undefined if no results are found.
|
|
257
257
|
*/
|
|
258
258
|
reverseGeocodeFirstResult(coordinates) {
|
|
259
|
-
return __async$
|
|
259
|
+
return __async$7(this, null, function* () {
|
|
260
260
|
for (const provider of this.providers) {
|
|
261
261
|
if (typeof provider.reverse === "function") {
|
|
262
262
|
try {
|
|
@@ -285,9 +285,9 @@ class Geocoder extends BaseGeocoder {
|
|
|
285
285
|
}
|
|
286
286
|
}
|
|
287
287
|
|
|
288
|
-
var __defProp$
|
|
289
|
-
var __defNormalProp$
|
|
290
|
-
var __publicField$
|
|
288
|
+
var __defProp$h = Object.defineProperty;
|
|
289
|
+
var __defNormalProp$h = (obj, key, value) => key in obj ? __defProp$h(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
290
|
+
var __publicField$c = (obj, key, value) => __defNormalProp$h(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
291
291
|
class BaseProvider extends BaseGeocoder {
|
|
292
292
|
constructor() {
|
|
293
293
|
super(...arguments);
|
|
@@ -295,15 +295,254 @@ class BaseProvider extends BaseGeocoder {
|
|
|
295
295
|
* URL endpoint for the search service.
|
|
296
296
|
* This is where queries will be sent to obtain search results.
|
|
297
297
|
*/
|
|
298
|
-
__publicField$
|
|
298
|
+
__publicField$c(this, "searchUrl");
|
|
299
299
|
/**
|
|
300
300
|
* Label to represent the provider.
|
|
301
301
|
* Useful for user interfaces to display the source of search results.
|
|
302
302
|
*/
|
|
303
|
-
__publicField$
|
|
303
|
+
__publicField$c(this, "label");
|
|
304
304
|
}
|
|
305
305
|
}
|
|
306
306
|
|
|
307
|
+
const templateRe = /\{ *([\w_-]+) *\}/g;
|
|
308
|
+
function template(str, data) {
|
|
309
|
+
return str.replace(templateRe, (s, key) => {
|
|
310
|
+
let value = data[key];
|
|
311
|
+
if (value === void 0) {
|
|
312
|
+
throw new Error("No value provided for letiable " + s);
|
|
313
|
+
} else if (typeof value === "function") {
|
|
314
|
+
value = value(data);
|
|
315
|
+
}
|
|
316
|
+
return value;
|
|
317
|
+
});
|
|
318
|
+
}
|
|
319
|
+
|
|
320
|
+
var __defProp$g = Object.defineProperty;
|
|
321
|
+
var __getOwnPropSymbols$7 = Object.getOwnPropertySymbols;
|
|
322
|
+
var __hasOwnProp$7 = Object.prototype.hasOwnProperty;
|
|
323
|
+
var __propIsEnum$7 = Object.prototype.propertyIsEnumerable;
|
|
324
|
+
var __defNormalProp$g = (obj, key, value) => key in obj ? __defProp$g(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
325
|
+
var __spreadValues$7 = (a, b) => {
|
|
326
|
+
for (var prop in b || (b = {}))
|
|
327
|
+
if (__hasOwnProp$7.call(b, prop))
|
|
328
|
+
__defNormalProp$g(a, prop, b[prop]);
|
|
329
|
+
if (__getOwnPropSymbols$7)
|
|
330
|
+
for (var prop of __getOwnPropSymbols$7(b)) {
|
|
331
|
+
if (__propIsEnum$7.call(b, prop))
|
|
332
|
+
__defNormalProp$g(a, prop, b[prop]);
|
|
333
|
+
}
|
|
334
|
+
return a;
|
|
335
|
+
};
|
|
336
|
+
var __async$6 = (__this, __arguments, generator) => {
|
|
337
|
+
return new Promise((resolve, reject) => {
|
|
338
|
+
var fulfilled = (value) => {
|
|
339
|
+
try {
|
|
340
|
+
step(generator.next(value));
|
|
341
|
+
} catch (e) {
|
|
342
|
+
reject(e);
|
|
343
|
+
}
|
|
344
|
+
};
|
|
345
|
+
var rejected = (value) => {
|
|
346
|
+
try {
|
|
347
|
+
step(generator.throw(value));
|
|
348
|
+
} catch (e) {
|
|
349
|
+
reject(e);
|
|
350
|
+
}
|
|
351
|
+
};
|
|
352
|
+
var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
|
|
353
|
+
step((generator = generator.apply(__this, __arguments)).next());
|
|
354
|
+
});
|
|
355
|
+
};
|
|
356
|
+
function apiRequest(opt) {
|
|
357
|
+
return __async$6(this, null, function* () {
|
|
358
|
+
const { params, name, connector, requestOptions } = opt;
|
|
359
|
+
const apiItems = yield connector.connect();
|
|
360
|
+
let apiItem = apiItems && apiItems[name];
|
|
361
|
+
if (apiItem) {
|
|
362
|
+
apiItem = [...apiItem];
|
|
363
|
+
let url = apiItem.shift();
|
|
364
|
+
if (apiItem.length) {
|
|
365
|
+
const replaceParams = {};
|
|
366
|
+
for (let fry = 0; fry < apiItem.length; fry++) {
|
|
367
|
+
const arg = apiItem[fry];
|
|
368
|
+
replaceParams[fry] = `{${arg}}`;
|
|
369
|
+
if (params[arg] === void 0) {
|
|
370
|
+
throw new Error(`\`${arg}\` URL API argument is not specified`);
|
|
371
|
+
}
|
|
372
|
+
}
|
|
373
|
+
if (url) {
|
|
374
|
+
url = template(url, replaceParams);
|
|
375
|
+
}
|
|
376
|
+
}
|
|
377
|
+
if (params) {
|
|
378
|
+
const paramArray = [];
|
|
379
|
+
const paramList = params.paramList;
|
|
380
|
+
if (Array.isArray(paramList)) {
|
|
381
|
+
paramList.forEach(([key, value]) => {
|
|
382
|
+
paramArray.push(`${key}=${value}`);
|
|
383
|
+
});
|
|
384
|
+
}
|
|
385
|
+
for (const p in params) {
|
|
386
|
+
if (apiItem.indexOf(p) === -1) {
|
|
387
|
+
paramArray.push(`${p}=${params[p]}`);
|
|
388
|
+
}
|
|
389
|
+
}
|
|
390
|
+
if (paramArray.length) {
|
|
391
|
+
url = `${url}?${paramArray.join("&")}`;
|
|
392
|
+
}
|
|
393
|
+
}
|
|
394
|
+
if (url) {
|
|
395
|
+
return connector.makeQuery(url, params, __spreadValues$7({
|
|
396
|
+
cacheName: name
|
|
397
|
+
}, requestOptions));
|
|
398
|
+
} else {
|
|
399
|
+
throw new Error("Request URL is not set");
|
|
400
|
+
}
|
|
401
|
+
} else {
|
|
402
|
+
return void 0;
|
|
403
|
+
}
|
|
404
|
+
});
|
|
405
|
+
}
|
|
406
|
+
|
|
407
|
+
var __defProp$f = Object.defineProperty;
|
|
408
|
+
var __defNormalProp$f = (obj, key, value) => key in obj ? __defProp$f(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
409
|
+
var __publicField$b = (obj, key, value) => __defNormalProp$f(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
410
|
+
const _Cache = class _Cache {
|
|
411
|
+
constructor(options = {}) {
|
|
412
|
+
__publicField$b(this, "cache", []);
|
|
413
|
+
var _a;
|
|
414
|
+
const namespace = (_a = options.namespace) != null ? _a : "default";
|
|
415
|
+
if (_Cache.instance[namespace]) {
|
|
416
|
+
return _Cache.instance[namespace];
|
|
417
|
+
}
|
|
418
|
+
_Cache.instance[namespace] = this;
|
|
419
|
+
return this;
|
|
420
|
+
}
|
|
421
|
+
clean() {
|
|
422
|
+
this.cache.length = 0;
|
|
423
|
+
}
|
|
424
|
+
all() {
|
|
425
|
+
return this.cache;
|
|
426
|
+
}
|
|
427
|
+
/**
|
|
428
|
+
* Caching only a non-empty value.
|
|
429
|
+
*
|
|
430
|
+
* Useful for get or create strategy
|
|
431
|
+
* @example
|
|
432
|
+
* ```javascript
|
|
433
|
+
* const cache = new Cache();
|
|
434
|
+
* const getItemFunc = () => fetch(url).then((data) => {
|
|
435
|
+
* return data.json(); // undefined
|
|
436
|
+
* });
|
|
437
|
+
* const item = await cache.addFull('foo', getItemFunc);
|
|
438
|
+
* if (!item) {
|
|
439
|
+
* await createItem(); // 'New item'
|
|
440
|
+
* }
|
|
441
|
+
*
|
|
442
|
+
* // somewhere else in the code
|
|
443
|
+
* const item = await cache.addFull('foo', getItemFunc).then((resp) => {
|
|
444
|
+
* console.log(resp); // 'New item'
|
|
445
|
+
* });
|
|
446
|
+
* ```
|
|
447
|
+
*/
|
|
448
|
+
addFull(key, valueToSet, propsOrOptions, expirationTime) {
|
|
449
|
+
if (typeof propsOrOptions === "object" && "valueToSet" in propsOrOptions) {
|
|
450
|
+
propsOrOptions.onlyFull = true;
|
|
451
|
+
}
|
|
452
|
+
return this.add(key, valueToSet, propsOrOptions, true, expirationTime);
|
|
453
|
+
}
|
|
454
|
+
add(key, valueToSet, propsOrOptions, onlyFull, expirationTime) {
|
|
455
|
+
let opt;
|
|
456
|
+
let props;
|
|
457
|
+
if (typeof propsOrOptions === "object" && "valueToSet" in propsOrOptions) {
|
|
458
|
+
opt = propsOrOptions;
|
|
459
|
+
onlyFull = opt.onlyFull;
|
|
460
|
+
expirationTime = opt.expirationTime;
|
|
461
|
+
props = opt.props;
|
|
462
|
+
} else {
|
|
463
|
+
props = propsOrOptions;
|
|
464
|
+
}
|
|
465
|
+
const exist = this._find(key, props);
|
|
466
|
+
if (!exist) {
|
|
467
|
+
let value;
|
|
468
|
+
if (valueToSet instanceof Function) {
|
|
469
|
+
value = valueToSet();
|
|
470
|
+
} else {
|
|
471
|
+
value = valueToSet;
|
|
472
|
+
}
|
|
473
|
+
const nonEmptyProps = props && JSON.parse(JSON.stringify(objectRemoveEmpty(props)));
|
|
474
|
+
expirationTime = expirationTime ? Date.now() + expirationTime : void 0;
|
|
475
|
+
const cacheItem = {
|
|
476
|
+
key,
|
|
477
|
+
value,
|
|
478
|
+
props: nonEmptyProps,
|
|
479
|
+
expirationTime
|
|
480
|
+
};
|
|
481
|
+
if (onlyFull && !full(value)) {
|
|
482
|
+
return value;
|
|
483
|
+
}
|
|
484
|
+
this.cache.push(cacheItem);
|
|
485
|
+
if (value instanceof Promise) {
|
|
486
|
+
value.catch(() => {
|
|
487
|
+
this.delete(key, props);
|
|
488
|
+
});
|
|
489
|
+
if (onlyFull) {
|
|
490
|
+
value.then((x) => {
|
|
491
|
+
if (!full(x)) {
|
|
492
|
+
this.delete(key, props);
|
|
493
|
+
}
|
|
494
|
+
return x;
|
|
495
|
+
});
|
|
496
|
+
}
|
|
497
|
+
return value;
|
|
498
|
+
}
|
|
499
|
+
return value;
|
|
500
|
+
} else {
|
|
501
|
+
return exist.value;
|
|
502
|
+
}
|
|
503
|
+
}
|
|
504
|
+
match(key, props) {
|
|
505
|
+
const cacheRecord = this._find(key, props);
|
|
506
|
+
if (cacheRecord && cacheRecord.expirationTime && Date.now() > cacheRecord.expirationTime) {
|
|
507
|
+
this.delete(cacheRecord);
|
|
508
|
+
return void 0;
|
|
509
|
+
}
|
|
510
|
+
return cacheRecord == null ? void 0 : cacheRecord.value;
|
|
511
|
+
}
|
|
512
|
+
matchAll(key, props) {
|
|
513
|
+
const now = Date.now();
|
|
514
|
+
this.cache.forEach((item) => {
|
|
515
|
+
if (item.expirationTime && now > item.expirationTime) {
|
|
516
|
+
this.delete(item);
|
|
517
|
+
}
|
|
518
|
+
});
|
|
519
|
+
if (key) {
|
|
520
|
+
return this.cache.filter((x) => this._filter(x, key, props)).map((x) => x.value);
|
|
521
|
+
}
|
|
522
|
+
return this.cache.map((x) => x.value);
|
|
523
|
+
}
|
|
524
|
+
delete(keyOrItem, props) {
|
|
525
|
+
const itemsToDelete = typeof keyOrItem === "string" ? this.cache.filter((x) => this._filter(x, keyOrItem, props)) : [keyOrItem];
|
|
526
|
+
for (const item of itemsToDelete) {
|
|
527
|
+
const index = this.cache.indexOf(item);
|
|
528
|
+
if (index !== -1) {
|
|
529
|
+
this.cache.splice(index, 1);
|
|
530
|
+
}
|
|
531
|
+
}
|
|
532
|
+
}
|
|
533
|
+
_find(key, props) {
|
|
534
|
+
return this.cache.find((x) => this._filter(x, key, props));
|
|
535
|
+
}
|
|
536
|
+
_filter(item, key, props) {
|
|
537
|
+
if (item.key !== key) return false;
|
|
538
|
+
if (!props) return true;
|
|
539
|
+
const itemProps = item.props;
|
|
540
|
+
return objectDeepEqual(itemProps || {}, objectRemoveEmpty(props));
|
|
541
|
+
}
|
|
542
|
+
};
|
|
543
|
+
__publicField$b(_Cache, "instance", {});
|
|
544
|
+
let Cache = _Cache;
|
|
545
|
+
|
|
307
546
|
var domain;
|
|
308
547
|
|
|
309
548
|
// This constructor is used to store event handlers. Instantiating this is
|
|
@@ -334,7 +573,7 @@ EventEmitter.init = function() {
|
|
|
334
573
|
this.domain = null;
|
|
335
574
|
if (EventEmitter.usingDomains) {
|
|
336
575
|
// if there is an active domain, then attach to it.
|
|
337
|
-
if (domain.active
|
|
576
|
+
if (domain.active) ;
|
|
338
577
|
}
|
|
339
578
|
|
|
340
579
|
if (!this._events || this._events === Object.getPrototypeOf(this)._events) {
|
|
@@ -776,123 +1015,9 @@ function unwrapListeners(arr) {
|
|
|
776
1015
|
return ret;
|
|
777
1016
|
}
|
|
778
1017
|
|
|
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);
|
|
782
|
-
const _Cache = class _Cache {
|
|
783
|
-
constructor(options = {}) {
|
|
784
|
-
__publicField$8(this, "cache", []);
|
|
785
|
-
var _a;
|
|
786
|
-
const namespace = (_a = options.namespace) != null ? _a : "default";
|
|
787
|
-
if (_Cache.instance[namespace]) {
|
|
788
|
-
return _Cache.instance[namespace];
|
|
789
|
-
}
|
|
790
|
-
_Cache.instance[namespace] = this;
|
|
791
|
-
return this;
|
|
792
|
-
}
|
|
793
|
-
clean() {
|
|
794
|
-
this.cache.length = 0;
|
|
795
|
-
}
|
|
796
|
-
all() {
|
|
797
|
-
return this.cache;
|
|
798
|
-
}
|
|
799
|
-
/**
|
|
800
|
-
* Caching only a non-empty value.
|
|
801
|
-
*
|
|
802
|
-
* Useful for get or create strategy
|
|
803
|
-
* @example
|
|
804
|
-
* ```javascript
|
|
805
|
-
* const cache = new Cache();
|
|
806
|
-
* const getItemFunc = () => fetch(url).then((data) => {
|
|
807
|
-
* return data.json(); // undefined
|
|
808
|
-
* });
|
|
809
|
-
* const item = await cache.addFull('foo', getItemFunc);
|
|
810
|
-
* if (!item) {
|
|
811
|
-
* await createItem(); // 'New item'
|
|
812
|
-
* }
|
|
813
|
-
*
|
|
814
|
-
* // somewhere else in the code
|
|
815
|
-
* const item = await cache.addFull('foo', getItemFunc).then((resp) => {
|
|
816
|
-
* console.log(resp); // 'New item'
|
|
817
|
-
* });
|
|
818
|
-
* ```
|
|
819
|
-
*/
|
|
820
|
-
addFull(key, valueToSet, props) {
|
|
821
|
-
return this.add(key, valueToSet, props, true);
|
|
822
|
-
}
|
|
823
|
-
add(key, valueToSet, props, onlyFull) {
|
|
824
|
-
const exist = this._find(key, props);
|
|
825
|
-
if (!exist) {
|
|
826
|
-
let value;
|
|
827
|
-
if (valueToSet instanceof Function) {
|
|
828
|
-
value = valueToSet();
|
|
829
|
-
} else {
|
|
830
|
-
value = valueToSet;
|
|
831
|
-
}
|
|
832
|
-
const nonEmptyProps = props && JSON.parse(JSON.stringify(objectRemoveEmpty(props)));
|
|
833
|
-
const cacheItem = {
|
|
834
|
-
key,
|
|
835
|
-
value,
|
|
836
|
-
props: nonEmptyProps
|
|
837
|
-
};
|
|
838
|
-
if (onlyFull && !full(value)) {
|
|
839
|
-
return value;
|
|
840
|
-
}
|
|
841
|
-
this.cache.push(cacheItem);
|
|
842
|
-
if (value instanceof Promise) {
|
|
843
|
-
value.catch((er) => {
|
|
844
|
-
this.delete(key, props);
|
|
845
|
-
});
|
|
846
|
-
if (onlyFull) {
|
|
847
|
-
value.then((x) => {
|
|
848
|
-
if (!full(x)) {
|
|
849
|
-
this.delete(key, props);
|
|
850
|
-
}
|
|
851
|
-
return x;
|
|
852
|
-
});
|
|
853
|
-
}
|
|
854
|
-
return value;
|
|
855
|
-
}
|
|
856
|
-
return value;
|
|
857
|
-
} else {
|
|
858
|
-
return exist.value;
|
|
859
|
-
}
|
|
860
|
-
}
|
|
861
|
-
match(key, props) {
|
|
862
|
-
const cacheRecord = this._find(key, props);
|
|
863
|
-
return cacheRecord == null ? void 0 : cacheRecord.value;
|
|
864
|
-
}
|
|
865
|
-
matchAll(key, props) {
|
|
866
|
-
if (key) {
|
|
867
|
-
return this.cache.filter((x) => this._filter(x, key, props)).map((x) => x.value);
|
|
868
|
-
}
|
|
869
|
-
return this.cache.map((x) => x.value);
|
|
870
|
-
}
|
|
871
|
-
delete(keyOrItem, props) {
|
|
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
|
-
}
|
|
878
|
-
}
|
|
879
|
-
}
|
|
880
|
-
_find(key, props) {
|
|
881
|
-
return this.cache.find((x) => this._filter(x, key, props));
|
|
882
|
-
}
|
|
883
|
-
_filter(item, key, props) {
|
|
884
|
-
if (item.key !== key) return false;
|
|
885
|
-
if (!props) return true;
|
|
886
|
-
const itemProps = item.props;
|
|
887
|
-
return objectDeepEqual(itemProps || {}, objectRemoveEmpty(props));
|
|
888
|
-
}
|
|
889
|
-
};
|
|
890
|
-
__publicField$8(_Cache, "instance", {});
|
|
891
|
-
let Cache = _Cache;
|
|
892
|
-
|
|
893
1018
|
var pkg = {
|
|
894
1019
|
name: "@nextgis/ngw-connector",
|
|
895
|
-
version: "3.0.0-alpha.
|
|
1020
|
+
version: "3.0.0-alpha.20",
|
|
896
1021
|
_priority: 12,
|
|
897
1022
|
description: "A lightweight HTTP client optimized for use with NextGIS Web API",
|
|
898
1023
|
main: "index.js",
|
|
@@ -901,15 +1026,15 @@ var pkg = {
|
|
|
901
1026
|
jsdelivr: "lib/ngw-connector.global.prod.js",
|
|
902
1027
|
types: "lib/index.d.ts",
|
|
903
1028
|
dependencies: {
|
|
904
|
-
"@nextgis/cache": "^3.0.0-alpha.
|
|
905
|
-
"@nextgis/cancelable-promise": "^3.0.0-alpha.
|
|
906
|
-
"@nextgis/utils": "^3.0.0-alpha.
|
|
1029
|
+
"@nextgis/cache": "^3.0.0-alpha.17",
|
|
1030
|
+
"@nextgis/cancelable-promise": "^3.0.0-alpha.17",
|
|
1031
|
+
"@nextgis/utils": "^3.0.0-alpha.17",
|
|
907
1032
|
"@types/events": "^3.0.0",
|
|
908
1033
|
events: "*",
|
|
909
1034
|
"form-data": "^4.0.0"
|
|
910
1035
|
},
|
|
911
1036
|
devDependencies: {
|
|
912
|
-
"@nextgis/build-tools": "^3.0.0-alpha.
|
|
1037
|
+
"@nextgis/build-tools": "^3.0.0-alpha.17"
|
|
913
1038
|
},
|
|
914
1039
|
scripts: {
|
|
915
1040
|
clean: "rimraf ./lib",
|
|
@@ -943,31 +1068,111 @@ var pkg = {
|
|
|
943
1068
|
type: "git",
|
|
944
1069
|
url: "git://github.com/nextgis/nextgis_frontend.git"
|
|
945
1070
|
},
|
|
1071
|
+
engines: {
|
|
1072
|
+
node: ">=18.20.4"
|
|
1073
|
+
},
|
|
946
1074
|
gitHead: "edc68033f914f6c95c4125b9738bba6d36e990b4"
|
|
947
1075
|
};
|
|
948
1076
|
|
|
949
|
-
|
|
950
|
-
|
|
951
|
-
|
|
1077
|
+
class AbortError extends Error {
|
|
1078
|
+
constructor(message = "AbortError") {
|
|
1079
|
+
super(message);
|
|
1080
|
+
this.name = "AbortError";
|
|
1081
|
+
}
|
|
1082
|
+
}
|
|
1083
|
+
|
|
1084
|
+
var __defProp$e = Object.defineProperty;
|
|
1085
|
+
var __defNormalProp$e = (obj, key, value) => key in obj ? __defProp$e(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
1086
|
+
var __publicField$a = (obj, key, value) => __defNormalProp$e(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
952
1087
|
class NgwError extends Error {
|
|
953
1088
|
constructor(er) {
|
|
954
1089
|
super();
|
|
955
|
-
__publicField$
|
|
956
|
-
__publicField$
|
|
957
|
-
__publicField$
|
|
958
|
-
__publicField$
|
|
959
|
-
__publicField$
|
|
960
|
-
__publicField$
|
|
961
|
-
__publicField$
|
|
962
|
-
__publicField$
|
|
1090
|
+
__publicField$a(this, "name", "NgwError");
|
|
1091
|
+
__publicField$a(this, "title");
|
|
1092
|
+
__publicField$a(this, "message");
|
|
1093
|
+
__publicField$a(this, "detail");
|
|
1094
|
+
__publicField$a(this, "exception");
|
|
1095
|
+
__publicField$a(this, "status_code");
|
|
1096
|
+
__publicField$a(this, "data");
|
|
1097
|
+
__publicField$a(this, "guru_meditation");
|
|
963
1098
|
Object.assign(this, er);
|
|
964
1099
|
Object.setPrototypeOf(this, NgwError.prototype);
|
|
965
1100
|
}
|
|
966
1101
|
}
|
|
967
1102
|
|
|
968
|
-
var __defProp$
|
|
969
|
-
var __defNormalProp$
|
|
970
|
-
var __publicField$
|
|
1103
|
+
var __defProp$d = Object.defineProperty;
|
|
1104
|
+
var __defNormalProp$d = (obj, key, value) => key in obj ? __defProp$d(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
1105
|
+
var __publicField$9 = (obj, key, value) => __defNormalProp$d(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
1106
|
+
class InsufficientPermissionsError extends NgwError {
|
|
1107
|
+
constructor(obj) {
|
|
1108
|
+
super(obj);
|
|
1109
|
+
__publicField$9(this, "name", "InsufficientPermissionsError");
|
|
1110
|
+
__publicField$9(this, "exception", "nextgisweb.core.exception.InsufficientPermissions");
|
|
1111
|
+
Object.setPrototypeOf(this, InsufficientPermissionsError.prototype);
|
|
1112
|
+
}
|
|
1113
|
+
}
|
|
1114
|
+
|
|
1115
|
+
var __defProp$c = Object.defineProperty;
|
|
1116
|
+
var __defNormalProp$c = (obj, key, value) => key in obj ? __defProp$c(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
1117
|
+
var __publicField$8 = (obj, key, value) => __defNormalProp$c(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
1118
|
+
let NetworksResponseError$1 = class NetworksResponseError extends NgwError {
|
|
1119
|
+
constructor(obj) {
|
|
1120
|
+
super(obj);
|
|
1121
|
+
__publicField$8(this, "message", "There is no response from the server or problem connecting to server.");
|
|
1122
|
+
__publicField$8(this, "title", "Network error");
|
|
1123
|
+
__publicField$8(this, "detail", "Check network connectivity and try again later.");
|
|
1124
|
+
Object.setPrototypeOf(this, NetworksResponseError.prototype);
|
|
1125
|
+
}
|
|
1126
|
+
};
|
|
1127
|
+
|
|
1128
|
+
function extractError(error) {
|
|
1129
|
+
if (isObject$1(error)) {
|
|
1130
|
+
if (error.name && error.message && error.title) {
|
|
1131
|
+
return {
|
|
1132
|
+
title: error.title,
|
|
1133
|
+
message: error.message,
|
|
1134
|
+
detail: error.detail || null,
|
|
1135
|
+
data: error.data && error.data.data ? error.data.data : null
|
|
1136
|
+
};
|
|
1137
|
+
} else if (error.exception) {
|
|
1138
|
+
if (error.status === void 0 || error.status === 0 || error.data === void 0) {
|
|
1139
|
+
return new NetworksResponseError$1({
|
|
1140
|
+
title: error.title,
|
|
1141
|
+
status_code: error.status_code,
|
|
1142
|
+
exception: error.exception
|
|
1143
|
+
});
|
|
1144
|
+
}
|
|
1145
|
+
}
|
|
1146
|
+
return {
|
|
1147
|
+
title: typeof error.title === "string" ? error.title : "Unexpected error",
|
|
1148
|
+
message: typeof error.message === "string" ? error.message : "Something went wrong."
|
|
1149
|
+
};
|
|
1150
|
+
}
|
|
1151
|
+
}
|
|
1152
|
+
|
|
1153
|
+
function isError(error) {
|
|
1154
|
+
if (isObject$1(error)) {
|
|
1155
|
+
return error.status_code && error.exception && error.title;
|
|
1156
|
+
}
|
|
1157
|
+
return false;
|
|
1158
|
+
}
|
|
1159
|
+
|
|
1160
|
+
var __defProp$b = Object.defineProperty;
|
|
1161
|
+
var __defNormalProp$b = (obj, key, value) => key in obj ? __defProp$b(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
1162
|
+
var __publicField$7 = (obj, key, value) => __defNormalProp$b(obj, key + "" , value);
|
|
1163
|
+
class NetworkError extends Error {
|
|
1164
|
+
constructor(url) {
|
|
1165
|
+
super();
|
|
1166
|
+
__publicField$7(this, "name", "NetworkError");
|
|
1167
|
+
Object.setPrototypeOf(this, NetworkError.prototype);
|
|
1168
|
+
this.message = `Unable to request ${url}.
|
|
1169
|
+
Possibly invalid NGW URL entered or CORS not configured to get request from ${location.origin}`;
|
|
1170
|
+
}
|
|
1171
|
+
}
|
|
1172
|
+
|
|
1173
|
+
var __defProp$a = Object.defineProperty;
|
|
1174
|
+
var __defNormalProp$a = (obj, key, value) => key in obj ? __defProp$a(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
1175
|
+
var __publicField$6 = (obj, key, value) => __defNormalProp$a(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
971
1176
|
class ResourceNotFoundError extends NgwError {
|
|
972
1177
|
constructor(obj) {
|
|
973
1178
|
super(obj);
|
|
@@ -977,53 +1182,111 @@ class ResourceNotFoundError extends NgwError {
|
|
|
977
1182
|
}
|
|
978
1183
|
}
|
|
979
1184
|
|
|
980
|
-
|
|
981
|
-
|
|
982
|
-
|
|
1185
|
+
var errors = /*#__PURE__*/Object.freeze({
|
|
1186
|
+
__proto__: null,
|
|
1187
|
+
AbortError: AbortError,
|
|
1188
|
+
InsufficientPermissionsError: InsufficientPermissionsError,
|
|
1189
|
+
NetworkError: NetworkError,
|
|
1190
|
+
NetworksResponseError: NetworksResponseError$1,
|
|
1191
|
+
NgwError: NgwError,
|
|
1192
|
+
ResourceNotFoundError: ResourceNotFoundError,
|
|
1193
|
+
extractError: extractError,
|
|
1194
|
+
isError: isError
|
|
1195
|
+
});
|
|
983
1196
|
|
|
984
|
-
|
|
985
|
-
|
|
1197
|
+
var __defProp$9 = Object.defineProperty;
|
|
1198
|
+
var __defNormalProp$9 = (obj, key, value) => key in obj ? __defProp$9(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
1199
|
+
var __publicField$5 = (obj, key, value) => __defNormalProp$9(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
1200
|
+
class BaseAPIError extends Error {
|
|
1201
|
+
constructor(message) {
|
|
1202
|
+
super(message || "Something went wrong.");
|
|
1203
|
+
__publicField$5(this, "title");
|
|
1204
|
+
this.name = "BaseAPIError";
|
|
1205
|
+
this.title = "Unknown API error";
|
|
1206
|
+
if (Error.captureStackTrace) {
|
|
1207
|
+
Error.captureStackTrace(this, BaseAPIError);
|
|
1208
|
+
}
|
|
1209
|
+
}
|
|
986
1210
|
}
|
|
987
|
-
|
|
988
|
-
|
|
989
|
-
|
|
990
|
-
|
|
991
|
-
|
|
992
|
-
|
|
993
|
-
|
|
994
|
-
|
|
995
|
-
|
|
996
|
-
|
|
997
|
-
|
|
998
|
-
|
|
999
|
-
|
|
1000
|
-
|
|
1001
|
-
|
|
1002
|
-
|
|
1003
|
-
|
|
1211
|
+
class NetworksResponseError extends BaseAPIError {
|
|
1212
|
+
// prettier-ignore
|
|
1213
|
+
constructor(message) {
|
|
1214
|
+
super(message || "There is no response from the server or problem connecting to server.");
|
|
1215
|
+
__publicField$5(this, "detail");
|
|
1216
|
+
this.title = "Network error";
|
|
1217
|
+
this.detail = "Check network connectivity and try again later.";
|
|
1218
|
+
}
|
|
1219
|
+
}
|
|
1220
|
+
class InvalidResponseError extends BaseAPIError {
|
|
1221
|
+
constructor(message) {
|
|
1222
|
+
super(message || "Something went wrong.");
|
|
1223
|
+
this.title = "Unexpected server response";
|
|
1224
|
+
}
|
|
1225
|
+
}
|
|
1226
|
+
class ServerResponseError extends BaseAPIError {
|
|
1227
|
+
constructor(data) {
|
|
1228
|
+
super(data.message);
|
|
1229
|
+
__publicField$5(this, "detail");
|
|
1230
|
+
__publicField$5(this, "data");
|
|
1231
|
+
this.title = data.title || this.title;
|
|
1232
|
+
this.detail = data.detail || null;
|
|
1233
|
+
this.data = data;
|
|
1234
|
+
}
|
|
1235
|
+
}
|
|
1236
|
+
class LunkwillError extends Error {
|
|
1237
|
+
// prettier-ignore
|
|
1238
|
+
constructor(message, data = {}) {
|
|
1239
|
+
super(message || "Unexpected error while processing long-running request.");
|
|
1240
|
+
__publicField$5(this, "title");
|
|
1241
|
+
__publicField$5(this, "data");
|
|
1242
|
+
this.name = "LunkwillError";
|
|
1243
|
+
this.title = "Long-running request error";
|
|
1244
|
+
this.data = data;
|
|
1245
|
+
if (Error.captureStackTrace) {
|
|
1246
|
+
Error.captureStackTrace(this, LunkwillError);
|
|
1004
1247
|
}
|
|
1005
1248
|
}
|
|
1006
|
-
|
|
1249
|
+
}
|
|
1250
|
+
class LunkwillRequestCancelled extends LunkwillError {
|
|
1251
|
+
constructor(data) {
|
|
1252
|
+
super("Long-running request was cancelled.", data);
|
|
1253
|
+
}
|
|
1254
|
+
}
|
|
1255
|
+
class LunkwillRequestFailed extends LunkwillError {
|
|
1256
|
+
constructor(data) {
|
|
1257
|
+
super(void 0, data);
|
|
1258
|
+
}
|
|
1007
1259
|
}
|
|
1008
1260
|
|
|
1009
1261
|
var __defProp$8 = Object.defineProperty;
|
|
1010
|
-
var __getOwnPropSymbols$
|
|
1011
|
-
var __hasOwnProp$
|
|
1012
|
-
var __propIsEnum$
|
|
1262
|
+
var __getOwnPropSymbols$6 = Object.getOwnPropertySymbols;
|
|
1263
|
+
var __hasOwnProp$6 = Object.prototype.hasOwnProperty;
|
|
1264
|
+
var __propIsEnum$6 = Object.prototype.propertyIsEnumerable;
|
|
1013
1265
|
var __defNormalProp$8 = (obj, key, value) => key in obj ? __defProp$8(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
1014
|
-
var __spreadValues$
|
|
1266
|
+
var __spreadValues$6 = (a, b) => {
|
|
1015
1267
|
for (var prop in b || (b = {}))
|
|
1016
|
-
if (__hasOwnProp$
|
|
1268
|
+
if (__hasOwnProp$6.call(b, prop))
|
|
1017
1269
|
__defNormalProp$8(a, prop, b[prop]);
|
|
1018
|
-
if (__getOwnPropSymbols$
|
|
1019
|
-
for (var prop of __getOwnPropSymbols$
|
|
1020
|
-
if (__propIsEnum$
|
|
1270
|
+
if (__getOwnPropSymbols$6)
|
|
1271
|
+
for (var prop of __getOwnPropSymbols$6(b)) {
|
|
1272
|
+
if (__propIsEnum$6.call(b, prop))
|
|
1021
1273
|
__defNormalProp$8(a, prop, b[prop]);
|
|
1022
1274
|
}
|
|
1023
1275
|
return a;
|
|
1024
1276
|
};
|
|
1025
|
-
var
|
|
1026
|
-
var
|
|
1277
|
+
var __objRest$2 = (source, exclude) => {
|
|
1278
|
+
var target = {};
|
|
1279
|
+
for (var prop in source)
|
|
1280
|
+
if (__hasOwnProp$6.call(source, prop) && exclude.indexOf(prop) < 0)
|
|
1281
|
+
target[prop] = source[prop];
|
|
1282
|
+
if (source != null && __getOwnPropSymbols$6)
|
|
1283
|
+
for (var prop of __getOwnPropSymbols$6(source)) {
|
|
1284
|
+
if (exclude.indexOf(prop) < 0 && __propIsEnum$6.call(source, prop))
|
|
1285
|
+
target[prop] = source[prop];
|
|
1286
|
+
}
|
|
1287
|
+
return target;
|
|
1288
|
+
};
|
|
1289
|
+
var __async$5 = (__this, __arguments, generator) => {
|
|
1027
1290
|
return new Promise((resolve, reject) => {
|
|
1028
1291
|
var fulfilled = (value) => {
|
|
1029
1292
|
try {
|
|
@@ -1043,307 +1306,251 @@ var __async$4 = (__this, __arguments, generator) => {
|
|
|
1043
1306
|
step((generator = generator.apply(__this, __arguments)).next());
|
|
1044
1307
|
});
|
|
1045
1308
|
};
|
|
1046
|
-
|
|
1047
|
-
|
|
1048
|
-
|
|
1049
|
-
|
|
1050
|
-
|
|
1051
|
-
|
|
1052
|
-
|
|
1053
|
-
|
|
1054
|
-
|
|
1055
|
-
|
|
1056
|
-
|
|
1057
|
-
|
|
1058
|
-
|
|
1059
|
-
|
|
1060
|
-
|
|
1061
|
-
|
|
1062
|
-
|
|
1063
|
-
|
|
1064
|
-
|
|
1065
|
-
|
|
1066
|
-
|
|
1067
|
-
|
|
1068
|
-
|
|
1069
|
-
|
|
1070
|
-
|
|
1071
|
-
|
|
1072
|
-
|
|
1073
|
-
|
|
1074
|
-
|
|
1075
|
-
|
|
1076
|
-
|
|
1077
|
-
|
|
1309
|
+
function lunkwillCheckResponse(lwResp) {
|
|
1310
|
+
const ct = lwResp.headers.get("content-type");
|
|
1311
|
+
return ct !== void 0 && ct !== null && ct.includes("application/vnd.lunkwill.request-summary+json");
|
|
1312
|
+
}
|
|
1313
|
+
function responseJson(response) {
|
|
1314
|
+
return __async$5(this, null, function* () {
|
|
1315
|
+
try {
|
|
1316
|
+
return response.json();
|
|
1317
|
+
} catch (e) {
|
|
1318
|
+
throw new Error();
|
|
1319
|
+
}
|
|
1320
|
+
});
|
|
1321
|
+
}
|
|
1322
|
+
function lunkwillResponseUrl(lwResp) {
|
|
1323
|
+
return __async$5(this, null, function* () {
|
|
1324
|
+
const lwData = yield responseJson(lwResp);
|
|
1325
|
+
let delay = lwData.delay_ms;
|
|
1326
|
+
const retry = lwData.retry_ms !== void 0 ? lwData.retry_ms : 2e3;
|
|
1327
|
+
const sum = `/api/lunkwill/${lwData.id}/summary`;
|
|
1328
|
+
const res = `/api/lunkwill/${lwData.id}/response`;
|
|
1329
|
+
const sleep = (msec) => new Promise((resolve) => setTimeout(resolve, msec));
|
|
1330
|
+
let failed = false;
|
|
1331
|
+
let ready = false;
|
|
1332
|
+
while (!ready) {
|
|
1333
|
+
yield sleep(failed ? retry : delay);
|
|
1334
|
+
failed = false;
|
|
1335
|
+
let lwResp2;
|
|
1336
|
+
let lwData2;
|
|
1337
|
+
try {
|
|
1338
|
+
lwResp2 = yield fetch(sum, { credentials: "same-origin" });
|
|
1339
|
+
lwData2 = yield lwResp2.json();
|
|
1340
|
+
} catch (e) {
|
|
1341
|
+
failed = true;
|
|
1342
|
+
continue;
|
|
1343
|
+
}
|
|
1344
|
+
switch (lwData2.status) {
|
|
1345
|
+
case void 0:
|
|
1346
|
+
throw new LunkwillError(void 0, lwData2);
|
|
1347
|
+
case "ready":
|
|
1348
|
+
ready = true;
|
|
1349
|
+
break;
|
|
1350
|
+
case "cancelled":
|
|
1351
|
+
throw new LunkwillRequestCancelled(lwData2);
|
|
1352
|
+
case "failed":
|
|
1353
|
+
throw new LunkwillRequestFailed(lwData2);
|
|
1354
|
+
case "spooled":
|
|
1355
|
+
case "processing":
|
|
1356
|
+
case "buffering":
|
|
1357
|
+
delay = lwData2.delay_ms;
|
|
1358
|
+
break;
|
|
1359
|
+
default:
|
|
1360
|
+
throw new LunkwillError(void 0, lwData2);
|
|
1078
1361
|
}
|
|
1079
1362
|
}
|
|
1080
|
-
|
|
1081
|
-
|
|
1082
|
-
|
|
1083
|
-
|
|
1084
|
-
|
|
1085
|
-
|
|
1363
|
+
return res;
|
|
1364
|
+
});
|
|
1365
|
+
}
|
|
1366
|
+
function lunkwillFetch(lwRespUrl) {
|
|
1367
|
+
return __async$5(this, null, function* () {
|
|
1368
|
+
try {
|
|
1369
|
+
return yield window.fetch(lwRespUrl, { credentials: "same-origin" });
|
|
1370
|
+
} catch (e) {
|
|
1371
|
+
throw new NetworksResponseError();
|
|
1086
1372
|
}
|
|
1087
|
-
|
|
1088
|
-
|
|
1089
|
-
|
|
1090
|
-
|
|
1091
|
-
|
|
1092
|
-
|
|
1093
|
-
|
|
1094
|
-
|
|
1095
|
-
|
|
1096
|
-
|
|
1097
|
-
|
|
1098
|
-
|
|
1099
|
-
|
|
1100
|
-
|
|
1101
|
-
|
|
1102
|
-
|
|
1103
|
-
|
|
1104
|
-
|
|
1105
|
-
|
|
1106
|
-
|
|
1107
|
-
|
|
1108
|
-
|
|
1109
|
-
|
|
1110
|
-
|
|
1111
|
-
|
|
1112
|
-
if (
|
|
1113
|
-
|
|
1373
|
+
});
|
|
1374
|
+
}
|
|
1375
|
+
const mediaContentTypes = [
|
|
1376
|
+
"application/pdf",
|
|
1377
|
+
"image/png",
|
|
1378
|
+
"image/jpeg",
|
|
1379
|
+
"image/tiff",
|
|
1380
|
+
"text/csv"
|
|
1381
|
+
];
|
|
1382
|
+
const mediaContentTypesRegex = new RegExp(mediaContentTypes.join("|"));
|
|
1383
|
+
function isMediaContentType(contentType) {
|
|
1384
|
+
return mediaContentTypesRegex.test(contentType);
|
|
1385
|
+
}
|
|
1386
|
+
function encodeQueryParams(value) {
|
|
1387
|
+
const result = [];
|
|
1388
|
+
for (const [k, v] of Object.entries(value)) {
|
|
1389
|
+
if (typeof v === "string" || typeof v === "number" || typeof v === "boolean") {
|
|
1390
|
+
result.push(`${k}=${encodeURIComponent(v)}`);
|
|
1391
|
+
} else if (Array.isArray(v)) {
|
|
1392
|
+
result.push(`${k}=${v.map(encodeURIComponent).join(",")}`);
|
|
1393
|
+
} else {
|
|
1394
|
+
for (const [sk, sv] of Object.entries(v)) {
|
|
1395
|
+
const ske = `${k}[${encodeURIComponent(sk)}]`;
|
|
1396
|
+
if (typeof sv === "string" || typeof sv === "number" || typeof sv === "boolean") {
|
|
1397
|
+
result.push(`${ske}=${encodeURIComponent(sv)}`);
|
|
1398
|
+
} else if (Array.isArray(sv)) {
|
|
1399
|
+
const sve = sv.map(encodeURIComponent);
|
|
1400
|
+
result.push(`${ske}=${sve.join(",")}`);
|
|
1114
1401
|
}
|
|
1115
|
-
}
|
|
1402
|
+
}
|
|
1116
1403
|
}
|
|
1117
|
-
return Promise.resolve(void 0);
|
|
1118
1404
|
}
|
|
1119
|
-
|
|
1120
|
-
|
|
1121
|
-
|
|
1122
|
-
|
|
1123
|
-
|
|
1124
|
-
|
|
1125
|
-
* To not make one more checks if the resource is definitely exists
|
|
1126
|
-
*/
|
|
1127
|
-
getIdOrFail(resource, requestOptions) {
|
|
1128
|
-
return this.getId(resource, requestOptions).then((resp) => {
|
|
1129
|
-
if (resp === void 0) {
|
|
1130
|
-
throw new Error();
|
|
1131
|
-
}
|
|
1132
|
-
return resp;
|
|
1133
|
-
});
|
|
1405
|
+
return result.join("&");
|
|
1406
|
+
}
|
|
1407
|
+
function generateUrl(path, query) {
|
|
1408
|
+
let urlParams = "";
|
|
1409
|
+
if (query !== void 0) {
|
|
1410
|
+
urlParams = "?" + encodeQueryParams(query);
|
|
1134
1411
|
}
|
|
1135
|
-
|
|
1136
|
-
|
|
1137
|
-
|
|
1138
|
-
|
|
1139
|
-
|
|
1140
|
-
|
|
1141
|
-
|
|
1142
|
-
|
|
1412
|
+
return path + urlParams;
|
|
1413
|
+
}
|
|
1414
|
+
function request(path, options, cacheEngine) {
|
|
1415
|
+
return __async$5(this, null, function* () {
|
|
1416
|
+
var _b, _c;
|
|
1417
|
+
const defaults = {
|
|
1418
|
+
method: "GET",
|
|
1419
|
+
credentials: "same-origin",
|
|
1420
|
+
headers: {}
|
|
1421
|
+
};
|
|
1422
|
+
const _a = __spreadValues$6(__spreadValues$6({}, defaults), options), {
|
|
1423
|
+
withCredentials,
|
|
1424
|
+
responseType,
|
|
1425
|
+
cacheProps,
|
|
1426
|
+
cacheName,
|
|
1427
|
+
lunkwill,
|
|
1428
|
+
cache,
|
|
1429
|
+
query,
|
|
1430
|
+
json
|
|
1431
|
+
} = _a, opt = __objRest$2(_a, [
|
|
1432
|
+
"withCredentials",
|
|
1433
|
+
"responseType",
|
|
1434
|
+
"cacheProps",
|
|
1435
|
+
"cacheName",
|
|
1436
|
+
"lunkwill",
|
|
1437
|
+
"cache",
|
|
1438
|
+
"query",
|
|
1439
|
+
"json"
|
|
1440
|
+
]);
|
|
1441
|
+
opt.method = (_b = opt.method) == null ? void 0 : _b.toUpperCase();
|
|
1442
|
+
if (withCredentials) {
|
|
1443
|
+
opt.credentials = "include";
|
|
1444
|
+
}
|
|
1445
|
+
let useLunkwill = false;
|
|
1446
|
+
if (lunkwill !== void 0) {
|
|
1447
|
+
lunkwill.toHeaders(opt.headers || {});
|
|
1448
|
+
useLunkwill = true;
|
|
1449
|
+
}
|
|
1450
|
+
const lunkwillReturnUrl = !!opt.lunkwillReturnUrl;
|
|
1451
|
+
delete opt.lunkwillReturnUrl;
|
|
1452
|
+
if (json !== void 0) {
|
|
1453
|
+
opt.body = JSON.stringify(json);
|
|
1454
|
+
const headers = opt.headers || {};
|
|
1455
|
+
headers["Content-Type"] = "application/json";
|
|
1456
|
+
opt.headers = headers;
|
|
1457
|
+
}
|
|
1458
|
+
const url = generateUrl(path, query);
|
|
1459
|
+
const makeRequest = () => __async$5(this, null, function* () {
|
|
1460
|
+
let response;
|
|
1461
|
+
try {
|
|
1462
|
+
response = yield fetch(url, opt);
|
|
1463
|
+
} catch (e) {
|
|
1464
|
+
if (opt.signal && opt.signal.aborted) {
|
|
1465
|
+
throw e;
|
|
1143
1466
|
}
|
|
1144
|
-
|
|
1145
|
-
serialization: "full"
|
|
1146
|
-
}, query)).then((resources) => {
|
|
1147
|
-
if ((requestOptions == null ? void 0 : requestOptions.cache) && resources) {
|
|
1148
|
-
for (const x of resources) {
|
|
1149
|
-
this.cache.add("resource.item", Promise.resolve(x), {
|
|
1150
|
-
id: x.resource.id
|
|
1151
|
-
});
|
|
1152
|
-
}
|
|
1153
|
-
}
|
|
1154
|
-
return resources;
|
|
1155
|
-
});
|
|
1156
|
-
}
|
|
1157
|
-
return items;
|
|
1158
|
-
});
|
|
1159
|
-
}
|
|
1160
|
-
getParent(resource, requestOptions) {
|
|
1161
|
-
return this.getOne(resource, requestOptions).then((child) => {
|
|
1162
|
-
if (child) {
|
|
1163
|
-
return this.getOne(child.resource.parent.id, requestOptions);
|
|
1164
|
-
}
|
|
1165
|
-
return Promise.resolve(void 0);
|
|
1166
|
-
});
|
|
1167
|
-
}
|
|
1168
|
-
getChildrenOf(resource, requestOptions) {
|
|
1169
|
-
return this.getIdOrFail(resource).then(
|
|
1170
|
-
(parent) => this._getChildrenOf(parent, requestOptions)
|
|
1171
|
-
);
|
|
1172
|
-
}
|
|
1173
|
-
update(resource, data) {
|
|
1174
|
-
return this.getId(resource).then((id) => {
|
|
1175
|
-
if (id !== void 0) {
|
|
1176
|
-
return this.connector.put("resource.item", { data }, { id });
|
|
1177
|
-
}
|
|
1178
|
-
});
|
|
1179
|
-
}
|
|
1180
|
-
/**
|
|
1181
|
-
* Fast way to delete resource from NGW and clean cache.
|
|
1182
|
-
* @param resource - Resource definition
|
|
1183
|
-
*/
|
|
1184
|
-
delete(resource) {
|
|
1185
|
-
return this.getId(resource).then((id) => {
|
|
1186
|
-
if (id !== void 0) {
|
|
1187
|
-
return this.connector.delete("resource.item", null, { id }).then(() => {
|
|
1188
|
-
this._cleanResourceItemCache(id);
|
|
1189
|
-
return void 0;
|
|
1190
|
-
});
|
|
1467
|
+
throw new NetworksResponseError();
|
|
1191
1468
|
}
|
|
1192
|
-
|
|
1193
|
-
|
|
1194
|
-
|
|
1195
|
-
|
|
1196
|
-
parent
|
|
1197
|
-
}).then((items) => {
|
|
1198
|
-
const recursivePromises = [];
|
|
1199
|
-
for (const item of items) {
|
|
1200
|
-
if (requestOptions == null ? void 0 : requestOptions.cache) {
|
|
1201
|
-
this.cache.add("resource.item", Promise.resolve(item), {
|
|
1202
|
-
id: item.resource.id
|
|
1203
|
-
});
|
|
1204
|
-
}
|
|
1205
|
-
_items.push(item);
|
|
1206
|
-
if ((requestOptions == null ? void 0 : requestOptions.recursive) && item.resource.children) {
|
|
1207
|
-
recursivePromises.push(
|
|
1208
|
-
this._getChildrenOf(item.resource.id, requestOptions, _items)
|
|
1209
|
-
);
|
|
1469
|
+
if (useLunkwill && lunkwillCheckResponse(response)) {
|
|
1470
|
+
const lwRespUrl = yield lunkwillResponseUrl(response);
|
|
1471
|
+
if (lunkwillReturnUrl) {
|
|
1472
|
+
return lwRespUrl;
|
|
1210
1473
|
}
|
|
1474
|
+
response = yield lunkwillFetch(lwRespUrl);
|
|
1211
1475
|
}
|
|
1212
|
-
|
|
1213
|
-
|
|
1214
|
-
|
|
1215
|
-
|
|
1216
|
-
|
|
1217
|
-
|
|
1218
|
-
|
|
1219
|
-
|
|
1220
|
-
|
|
1221
|
-
|
|
1222
|
-
|
|
1223
|
-
|
|
1224
|
-
|
|
1225
|
-
|
|
1226
|
-
|
|
1227
|
-
if (["resource.item", "resource"].includes(c.key) && cid !== void 0) {
|
|
1228
|
-
if (typeof cid === "number") {
|
|
1229
|
-
if (cid === id) {
|
|
1230
|
-
toDelete.push(c);
|
|
1231
|
-
}
|
|
1232
|
-
} else {
|
|
1233
|
-
const rid = yield this.getId(cid);
|
|
1234
|
-
if (rid === id) {
|
|
1235
|
-
toDelete.push(c);
|
|
1236
|
-
}
|
|
1237
|
-
}
|
|
1476
|
+
const respCType = response.headers.get("content-type");
|
|
1477
|
+
const respJSON = respCType && (respCType.includes("application/json") || respCType.includes("application/vnd.lunkwill.request-summary+json"));
|
|
1478
|
+
let body;
|
|
1479
|
+
try {
|
|
1480
|
+
const respMedia = respCType && isMediaContentType(respCType);
|
|
1481
|
+
if (responseType === "blob" || respMedia) {
|
|
1482
|
+
body = yield response.blob();
|
|
1483
|
+
} else if (respJSON) {
|
|
1484
|
+
body = yield response.json();
|
|
1485
|
+
} else {
|
|
1486
|
+
throw new InvalidResponseError();
|
|
1487
|
+
}
|
|
1488
|
+
} catch (e) {
|
|
1489
|
+
if (e.name === "AbortError" || e instanceof InvalidResponseError) {
|
|
1490
|
+
throw e;
|
|
1238
1491
|
}
|
|
1492
|
+
throw new InvalidResponseError();
|
|
1239
1493
|
}
|
|
1240
|
-
|
|
1241
|
-
|
|
1494
|
+
if (400 <= response.status && response.status <= 599) {
|
|
1495
|
+
throw new ServerResponseError(body);
|
|
1242
1496
|
}
|
|
1497
|
+
return body;
|
|
1243
1498
|
});
|
|
1244
|
-
|
|
1245
|
-
|
|
1246
|
-
|
|
1247
|
-
|
|
1248
|
-
|
|
1249
|
-
|
|
1250
|
-
|
|
1251
|
-
|
|
1252
|
-
|
|
1253
|
-
|
|
1254
|
-
|
|
1255
|
-
(resources) => {
|
|
1256
|
-
const items = [];
|
|
1257
|
-
resources.filter((x) => {
|
|
1258
|
-
if (x) {
|
|
1259
|
-
if (resource.keyname && x.resource.keyname) {
|
|
1260
|
-
return resource.keyname === x.resource.keyname;
|
|
1261
|
-
}
|
|
1262
|
-
if (defined(resource.id) && defined(x.resource.id)) {
|
|
1263
|
-
return resource.id === x.resource.id;
|
|
1264
|
-
}
|
|
1265
|
-
return resourceCompare(resource, x.resource);
|
|
1266
|
-
}
|
|
1267
|
-
});
|
|
1268
|
-
return items;
|
|
1269
|
-
}
|
|
1270
|
-
);
|
|
1271
|
-
}
|
|
1272
|
-
}
|
|
1273
|
-
|
|
1274
|
-
const CONNECTORS = [];
|
|
1275
|
-
function addConnector(connector) {
|
|
1276
|
-
CONNECTORS.push(connector);
|
|
1277
|
-
}
|
|
1278
|
-
function findConnector(options) {
|
|
1279
|
-
return CONNECTORS.find((x) => {
|
|
1280
|
-
if (x.options.baseUrl === options.baseUrl) {
|
|
1281
|
-
if (options.auth) {
|
|
1282
|
-
if (x.options.auth) {
|
|
1283
|
-
return objectDeepEqual(x.options.auth, options.auth);
|
|
1499
|
+
if (cacheEngine) {
|
|
1500
|
+
if (((_c = opt.method) == null ? void 0 : _c.toUpperCase()) === "GET") {
|
|
1501
|
+
if (cache !== false) {
|
|
1502
|
+
const props = cacheProps ? cacheProps : __spreadValues$6({}, objectRemoveEmpty({
|
|
1503
|
+
withCredentials,
|
|
1504
|
+
responseType
|
|
1505
|
+
}));
|
|
1506
|
+
return cacheEngine.add(cacheName || url, makeRequest, {
|
|
1507
|
+
props,
|
|
1508
|
+
expirationTime: cache ? void 0 : 500
|
|
1509
|
+
});
|
|
1284
1510
|
}
|
|
1285
1511
|
} else {
|
|
1286
|
-
|
|
1512
|
+
const ignoredForClean = ["api/feature_layer/identify"];
|
|
1513
|
+
if (ignoredForClean.every((part) => !path.includes(part))) {
|
|
1514
|
+
cacheEngine.clean();
|
|
1515
|
+
}
|
|
1287
1516
|
}
|
|
1288
1517
|
}
|
|
1518
|
+
return makeRequest();
|
|
1289
1519
|
});
|
|
1290
1520
|
}
|
|
1291
|
-
function removeConnector(connector) {
|
|
1292
|
-
const index = CONNECTORS.indexOf(connector);
|
|
1293
|
-
if (index !== -1) {
|
|
1294
|
-
CONNECTORS.splice(index, 1);
|
|
1295
|
-
}
|
|
1296
|
-
}
|
|
1297
|
-
|
|
1298
|
-
class AbortError extends Error {
|
|
1299
|
-
constructor(message = "AbortError") {
|
|
1300
|
-
super(message);
|
|
1301
|
-
this.name = "AbortError";
|
|
1302
|
-
}
|
|
1303
|
-
}
|
|
1304
1521
|
|
|
1305
1522
|
var __defProp$7 = Object.defineProperty;
|
|
1523
|
+
var __defProps$4 = Object.defineProperties;
|
|
1524
|
+
var __getOwnPropDescs$4 = Object.getOwnPropertyDescriptors;
|
|
1525
|
+
var __getOwnPropSymbols$5 = Object.getOwnPropertySymbols;
|
|
1526
|
+
var __hasOwnProp$5 = Object.prototype.hasOwnProperty;
|
|
1527
|
+
var __propIsEnum$5 = Object.prototype.propertyIsEnumerable;
|
|
1306
1528
|
var __defNormalProp$7 = (obj, key, value) => key in obj ? __defProp$7(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
1307
|
-
var
|
|
1308
|
-
class InsufficientPermissionsError extends NgwError {
|
|
1309
|
-
constructor(obj) {
|
|
1310
|
-
super(obj);
|
|
1311
|
-
__publicField$4(this, "name", "InsufficientPermissionsError");
|
|
1312
|
-
__publicField$4(this, "exception", "nextgisweb.core.exception.InsufficientPermissions");
|
|
1313
|
-
Object.setPrototypeOf(this, InsufficientPermissionsError.prototype);
|
|
1314
|
-
}
|
|
1315
|
-
}
|
|
1316
|
-
|
|
1317
|
-
const templateRe = /\{ *([\w_-]+) *\}/g;
|
|
1318
|
-
function template(str, data) {
|
|
1319
|
-
return str.replace(templateRe, (s, key) => {
|
|
1320
|
-
let value = data[key];
|
|
1321
|
-
if (value === void 0) {
|
|
1322
|
-
throw new Error("No value provided for letiable " + s);
|
|
1323
|
-
} else if (typeof value === "function") {
|
|
1324
|
-
value = value(data);
|
|
1325
|
-
}
|
|
1326
|
-
return value;
|
|
1327
|
-
});
|
|
1328
|
-
}
|
|
1329
|
-
|
|
1330
|
-
var __defProp$6 = Object.defineProperty;
|
|
1331
|
-
var __getOwnPropSymbols$4 = Object.getOwnPropertySymbols;
|
|
1332
|
-
var __hasOwnProp$4 = Object.prototype.hasOwnProperty;
|
|
1333
|
-
var __propIsEnum$4 = Object.prototype.propertyIsEnumerable;
|
|
1334
|
-
var __defNormalProp$6 = (obj, key, value) => key in obj ? __defProp$6(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
1335
|
-
var __spreadValues$4 = (a, b) => {
|
|
1529
|
+
var __spreadValues$5 = (a, b) => {
|
|
1336
1530
|
for (var prop in b || (b = {}))
|
|
1337
|
-
if (__hasOwnProp$
|
|
1338
|
-
__defNormalProp$
|
|
1339
|
-
if (__getOwnPropSymbols$
|
|
1340
|
-
for (var prop of __getOwnPropSymbols$
|
|
1341
|
-
if (__propIsEnum$
|
|
1342
|
-
__defNormalProp$
|
|
1531
|
+
if (__hasOwnProp$5.call(b, prop))
|
|
1532
|
+
__defNormalProp$7(a, prop, b[prop]);
|
|
1533
|
+
if (__getOwnPropSymbols$5)
|
|
1534
|
+
for (var prop of __getOwnPropSymbols$5(b)) {
|
|
1535
|
+
if (__propIsEnum$5.call(b, prop))
|
|
1536
|
+
__defNormalProp$7(a, prop, b[prop]);
|
|
1343
1537
|
}
|
|
1344
1538
|
return a;
|
|
1345
1539
|
};
|
|
1346
|
-
var
|
|
1540
|
+
var __spreadProps$4 = (a, b) => __defProps$4(a, __getOwnPropDescs$4(b));
|
|
1541
|
+
var __objRest$1 = (source, exclude) => {
|
|
1542
|
+
var target = {};
|
|
1543
|
+
for (var prop in source)
|
|
1544
|
+
if (__hasOwnProp$5.call(source, prop) && exclude.indexOf(prop) < 0)
|
|
1545
|
+
target[prop] = source[prop];
|
|
1546
|
+
if (source != null && __getOwnPropSymbols$5)
|
|
1547
|
+
for (var prop of __getOwnPropSymbols$5(source)) {
|
|
1548
|
+
if (exclude.indexOf(prop) < 0 && __propIsEnum$5.call(source, prop))
|
|
1549
|
+
target[prop] = source[prop];
|
|
1550
|
+
}
|
|
1551
|
+
return target;
|
|
1552
|
+
};
|
|
1553
|
+
var __async$4 = (__this, __arguments, generator) => {
|
|
1347
1554
|
return new Promise((resolve, reject) => {
|
|
1348
1555
|
var fulfilled = (value) => {
|
|
1349
1556
|
try {
|
|
@@ -1363,68 +1570,84 @@ var __async$3 = (__this, __arguments, generator) => {
|
|
|
1363
1570
|
step((generator = generator.apply(__this, __arguments)).next());
|
|
1364
1571
|
});
|
|
1365
1572
|
};
|
|
1366
|
-
function
|
|
1367
|
-
|
|
1368
|
-
|
|
1369
|
-
|
|
1370
|
-
|
|
1371
|
-
|
|
1372
|
-
|
|
1373
|
-
|
|
1374
|
-
|
|
1375
|
-
const replaceParams = {};
|
|
1376
|
-
for (let fry = 0; fry < apiItem.length; fry++) {
|
|
1377
|
-
const arg = apiItem[fry];
|
|
1378
|
-
replaceParams[fry] = `{${arg}}`;
|
|
1379
|
-
if (params[arg] === void 0) {
|
|
1380
|
-
throw new Error(`\`${arg}\` URL API argument is not specified`);
|
|
1381
|
-
}
|
|
1382
|
-
}
|
|
1383
|
-
if (url) {
|
|
1384
|
-
url = template(url, replaceParams);
|
|
1385
|
-
}
|
|
1386
|
-
}
|
|
1387
|
-
if (params) {
|
|
1388
|
-
const paramArray = [];
|
|
1389
|
-
const paramList = params.paramList;
|
|
1390
|
-
if (Array.isArray(paramList)) {
|
|
1391
|
-
paramList.forEach(([key, value]) => {
|
|
1392
|
-
paramArray.push(`${key}=${value}`);
|
|
1393
|
-
});
|
|
1394
|
-
}
|
|
1395
|
-
for (const p in params) {
|
|
1396
|
-
if (apiItem.indexOf(p) === -1) {
|
|
1397
|
-
paramArray.push(`${p}=${params[p]}`);
|
|
1398
|
-
}
|
|
1399
|
-
}
|
|
1400
|
-
if (paramArray.length) {
|
|
1401
|
-
url = `${url}?${paramArray.join("&")}`;
|
|
1402
|
-
}
|
|
1403
|
-
}
|
|
1404
|
-
if (url) {
|
|
1405
|
-
return connector.makeQuery(url, params, __spreadValues$4({
|
|
1406
|
-
cacheName: name
|
|
1407
|
-
}, requestOptions));
|
|
1408
|
-
} else {
|
|
1409
|
-
throw new Error("Request URL is not set");
|
|
1410
|
-
}
|
|
1411
|
-
} else {
|
|
1412
|
-
return void 0;
|
|
1573
|
+
function routeURL(name, baseUrl, routeData, ...rest) {
|
|
1574
|
+
const [template, ...params] = routeData[name];
|
|
1575
|
+
const first = rest[0];
|
|
1576
|
+
let sub;
|
|
1577
|
+
if (first === void 0) {
|
|
1578
|
+
sub = [];
|
|
1579
|
+
} else if (typeof first === "object" && first !== null) {
|
|
1580
|
+
if (rest.length > 1) {
|
|
1581
|
+
throw new Error("Too many arguments for route(name, object)!");
|
|
1413
1582
|
}
|
|
1414
|
-
|
|
1583
|
+
sub = [];
|
|
1584
|
+
for (const [p, v] of Object.entries(first)) {
|
|
1585
|
+
sub[params.indexOf(p)] = String(v);
|
|
1586
|
+
}
|
|
1587
|
+
} else {
|
|
1588
|
+
sub = rest.map((v) => String(v));
|
|
1589
|
+
}
|
|
1590
|
+
return fixUrlStr(
|
|
1591
|
+
baseUrl + template.replace(/\{(\w+)\}/g, function(m, a) {
|
|
1592
|
+
const idx = parseInt(a);
|
|
1593
|
+
const value = sub[idx];
|
|
1594
|
+
if (value === void 0) {
|
|
1595
|
+
const msg = `Undefined parameter ${idx} in "${template}".`;
|
|
1596
|
+
throw new Error(msg);
|
|
1597
|
+
}
|
|
1598
|
+
return String(value);
|
|
1599
|
+
})
|
|
1600
|
+
);
|
|
1415
1601
|
}
|
|
1416
|
-
|
|
1417
|
-
|
|
1418
|
-
|
|
1419
|
-
var
|
|
1420
|
-
|
|
1421
|
-
|
|
1422
|
-
|
|
1423
|
-
|
|
1424
|
-
|
|
1425
|
-
|
|
1426
|
-
|
|
1602
|
+
function route(name, connector, ...rest) {
|
|
1603
|
+
const result = {
|
|
1604
|
+
url: (opt) => __async$4(this, null, function* () {
|
|
1605
|
+
var _a;
|
|
1606
|
+
const routeData = yield connector.connect();
|
|
1607
|
+
const template = routeURL(
|
|
1608
|
+
name,
|
|
1609
|
+
(_a = connector.options.baseUrl) != null ? _a : "",
|
|
1610
|
+
routeData,
|
|
1611
|
+
...rest
|
|
1612
|
+
);
|
|
1613
|
+
return generateUrl(template, opt == null ? void 0 : opt.query);
|
|
1614
|
+
})
|
|
1615
|
+
};
|
|
1616
|
+
const methods = ["get", "post", "put", "delete", "patch"];
|
|
1617
|
+
for (const method of methods) {
|
|
1618
|
+
const methodResp = (requestOptions) => {
|
|
1619
|
+
var _b;
|
|
1620
|
+
const _a = requestOptions || {}, { headers: optHeaders } = _a, restOpt = __objRest$1(_a, ["headers"]);
|
|
1621
|
+
if ((_b = requestOptions == null ? void 0 : requestOptions.signal) == null ? void 0 : _b.aborted) {
|
|
1622
|
+
throw new AbortError();
|
|
1623
|
+
}
|
|
1624
|
+
return connector.connect().then((routeData) => {
|
|
1625
|
+
var _a2;
|
|
1626
|
+
const template = routeURL(
|
|
1627
|
+
name,
|
|
1628
|
+
(_a2 = connector.options.baseUrl) != null ? _a2 : "",
|
|
1629
|
+
routeData,
|
|
1630
|
+
...rest
|
|
1631
|
+
);
|
|
1632
|
+
const headers = objectRemoveEmpty(__spreadValues$5(__spreadValues$5({}, connector.getAuthorizationHeaders()), optHeaders != null ? optHeaders : {}));
|
|
1633
|
+
return request(
|
|
1634
|
+
template,
|
|
1635
|
+
__spreadProps$4(__spreadValues$5({
|
|
1636
|
+
headers
|
|
1637
|
+
}, restOpt), {
|
|
1638
|
+
method
|
|
1639
|
+
}),
|
|
1640
|
+
connector.cache
|
|
1641
|
+
);
|
|
1642
|
+
});
|
|
1643
|
+
};
|
|
1644
|
+
result[method] = methodResp;
|
|
1427
1645
|
}
|
|
1646
|
+
return result;
|
|
1647
|
+
}
|
|
1648
|
+
|
|
1649
|
+
function isObject(val) {
|
|
1650
|
+
return Object.prototype.toString.call(val) === "[object Object]";
|
|
1428
1651
|
}
|
|
1429
1652
|
|
|
1430
1653
|
let loadData;
|
|
@@ -1439,7 +1662,7 @@ let loadData;
|
|
|
1439
1662
|
const getResponseText = () => {
|
|
1440
1663
|
try {
|
|
1441
1664
|
return JSON.parse(xhr.responseText);
|
|
1442
|
-
} catch (
|
|
1665
|
+
} catch (e) {
|
|
1443
1666
|
return xhr.responseText;
|
|
1444
1667
|
}
|
|
1445
1668
|
};
|
|
@@ -1505,42 +1728,429 @@ let loadData;
|
|
|
1505
1728
|
xhr.abort();
|
|
1506
1729
|
});
|
|
1507
1730
|
}
|
|
1508
|
-
xhr.send(data);
|
|
1509
|
-
};
|
|
1731
|
+
xhr.send(data);
|
|
1732
|
+
};
|
|
1733
|
+
}
|
|
1734
|
+
|
|
1735
|
+
const CONNECTORS = [];
|
|
1736
|
+
function addConnector(connector) {
|
|
1737
|
+
CONNECTORS.push(connector);
|
|
1738
|
+
}
|
|
1739
|
+
function findConnector(options) {
|
|
1740
|
+
return CONNECTORS.find((x) => {
|
|
1741
|
+
if (x.options.baseUrl === options.baseUrl) {
|
|
1742
|
+
if (options.auth) {
|
|
1743
|
+
if (x.options.auth) {
|
|
1744
|
+
return objectDeepEqual(x.options.auth, options.auth);
|
|
1745
|
+
}
|
|
1746
|
+
} else {
|
|
1747
|
+
return true;
|
|
1748
|
+
}
|
|
1749
|
+
}
|
|
1750
|
+
});
|
|
1751
|
+
}
|
|
1752
|
+
function removeConnector(connector) {
|
|
1753
|
+
const index = CONNECTORS.indexOf(connector);
|
|
1754
|
+
if (index !== -1) {
|
|
1755
|
+
CONNECTORS.splice(index, 1);
|
|
1756
|
+
}
|
|
1757
|
+
}
|
|
1758
|
+
|
|
1759
|
+
var __defProp$6 = Object.defineProperty;
|
|
1760
|
+
var __defProps$3 = Object.defineProperties;
|
|
1761
|
+
var __getOwnPropDescs$3 = Object.getOwnPropertyDescriptors;
|
|
1762
|
+
var __getOwnPropSymbols$4 = Object.getOwnPropertySymbols;
|
|
1763
|
+
var __hasOwnProp$4 = Object.prototype.hasOwnProperty;
|
|
1764
|
+
var __propIsEnum$4 = Object.prototype.propertyIsEnumerable;
|
|
1765
|
+
var __defNormalProp$6 = (obj, key, value) => key in obj ? __defProp$6(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
1766
|
+
var __spreadValues$4 = (a, b) => {
|
|
1767
|
+
for (var prop in b || (b = {}))
|
|
1768
|
+
if (__hasOwnProp$4.call(b, prop))
|
|
1769
|
+
__defNormalProp$6(a, prop, b[prop]);
|
|
1770
|
+
if (__getOwnPropSymbols$4)
|
|
1771
|
+
for (var prop of __getOwnPropSymbols$4(b)) {
|
|
1772
|
+
if (__propIsEnum$4.call(b, prop))
|
|
1773
|
+
__defNormalProp$6(a, prop, b[prop]);
|
|
1774
|
+
}
|
|
1775
|
+
return a;
|
|
1776
|
+
};
|
|
1777
|
+
var __spreadProps$3 = (a, b) => __defProps$3(a, __getOwnPropDescs$3(b));
|
|
1778
|
+
var __objRest = (source, exclude) => {
|
|
1779
|
+
var target = {};
|
|
1780
|
+
for (var prop in source)
|
|
1781
|
+
if (__hasOwnProp$4.call(source, prop) && exclude.indexOf(prop) < 0)
|
|
1782
|
+
target[prop] = source[prop];
|
|
1783
|
+
if (source != null && __getOwnPropSymbols$4)
|
|
1784
|
+
for (var prop of __getOwnPropSymbols$4(source)) {
|
|
1785
|
+
if (exclude.indexOf(prop) < 0 && __propIsEnum$4.call(source, prop))
|
|
1786
|
+
target[prop] = source[prop];
|
|
1787
|
+
}
|
|
1788
|
+
return target;
|
|
1789
|
+
};
|
|
1790
|
+
var __publicField$4 = (obj, key, value) => __defNormalProp$6(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
1791
|
+
var __async$3 = (__this, __arguments, generator) => {
|
|
1792
|
+
return new Promise((resolve, reject) => {
|
|
1793
|
+
var fulfilled = (value) => {
|
|
1794
|
+
try {
|
|
1795
|
+
step(generator.next(value));
|
|
1796
|
+
} catch (e) {
|
|
1797
|
+
reject(e);
|
|
1798
|
+
}
|
|
1799
|
+
};
|
|
1800
|
+
var rejected = (value) => {
|
|
1801
|
+
try {
|
|
1802
|
+
step(generator.throw(value));
|
|
1803
|
+
} catch (e) {
|
|
1804
|
+
reject(e);
|
|
1805
|
+
}
|
|
1806
|
+
};
|
|
1807
|
+
var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
|
|
1808
|
+
step((generator = generator.apply(__this, __arguments)).next());
|
|
1809
|
+
});
|
|
1810
|
+
};
|
|
1811
|
+
let ID = 0;
|
|
1812
|
+
let REQUEST_ID = 0;
|
|
1813
|
+
class NgwConnector {
|
|
1814
|
+
constructor(options) {
|
|
1815
|
+
this.options = options;
|
|
1816
|
+
__publicField$4(this, "id", ID++);
|
|
1817
|
+
__publicField$4(this, "emitter", new EventEmitter());
|
|
1818
|
+
__publicField$4(this, "user");
|
|
1819
|
+
__publicField$4(this, "cache");
|
|
1820
|
+
__publicField$4(this, "withCredentials");
|
|
1821
|
+
// Dedicated cache for route requests, as these are executed before any other requests.
|
|
1822
|
+
// This cache does not need to be cleared during the session.
|
|
1823
|
+
__publicField$4(this, "routeCache");
|
|
1824
|
+
__publicField$4(this, "client", `NextGIS-NGW-Connector/${pkg.version}`);
|
|
1825
|
+
__publicField$4(this, "routeStr", "/api/component/pyramid/route");
|
|
1826
|
+
__publicField$4(this, "activeRequests", {});
|
|
1827
|
+
__publicField$4(this, "requestTransform");
|
|
1828
|
+
const exist = findConnector(options);
|
|
1829
|
+
this.cache = new Cache({ namespace: options.cacheId });
|
|
1830
|
+
this.routeCache = new Cache({ namespace: "routecache" });
|
|
1831
|
+
if (exist) {
|
|
1832
|
+
return exist;
|
|
1833
|
+
} else {
|
|
1834
|
+
const { route: route2, requestTransform, withCredentials } = this.options;
|
|
1835
|
+
if (route2) {
|
|
1836
|
+
this.routeStr = route2;
|
|
1837
|
+
}
|
|
1838
|
+
if (requestTransform) {
|
|
1839
|
+
this.requestTransform = requestTransform;
|
|
1840
|
+
}
|
|
1841
|
+
if (withCredentials !== void 0) {
|
|
1842
|
+
this.withCredentials = withCredentials;
|
|
1843
|
+
}
|
|
1844
|
+
addConnector(this);
|
|
1845
|
+
}
|
|
1846
|
+
}
|
|
1847
|
+
/**
|
|
1848
|
+
* Clear the cache.
|
|
1849
|
+
*/
|
|
1850
|
+
clearCache() {
|
|
1851
|
+
this.cache.clean();
|
|
1852
|
+
}
|
|
1853
|
+
setRequestTransform(requestTransform) {
|
|
1854
|
+
this.requestTransform = requestTransform;
|
|
1855
|
+
}
|
|
1856
|
+
/**
|
|
1857
|
+
* Fast way to specify the connection address to NextGIS Web.
|
|
1858
|
+
* The current connection will be severed.
|
|
1859
|
+
* @param baseUrl - NGW url
|
|
1860
|
+
*/
|
|
1861
|
+
setNgw(baseUrl) {
|
|
1862
|
+
this.logout();
|
|
1863
|
+
this.options.baseUrl = baseUrl;
|
|
1864
|
+
addConnector(this);
|
|
1865
|
+
}
|
|
1866
|
+
/**
|
|
1867
|
+
* Establishing a connection with NextGIS Web to fulfill all other requests.
|
|
1868
|
+
* @remarks
|
|
1869
|
+
* This method need not be called manually as it is used when forming a request in {@link apiRequest | apiRequest}.
|
|
1870
|
+
* Can be used to check connection.
|
|
1871
|
+
* @example
|
|
1872
|
+
* ```javascript
|
|
1873
|
+
* const connector = new NgwConnector({ baseUrl: 'https://demo.nextgis.com' });
|
|
1874
|
+
* connector.connect()
|
|
1875
|
+
* .then(() => console.log('Ok'))
|
|
1876
|
+
* .catch((er) => console.log('Connection problem', er));
|
|
1877
|
+
* ```
|
|
1878
|
+
*/
|
|
1879
|
+
connect() {
|
|
1880
|
+
return __async$3(this, arguments, function* ({
|
|
1881
|
+
signal
|
|
1882
|
+
} = {}) {
|
|
1883
|
+
const auth = this.options.auth;
|
|
1884
|
+
if (auth) {
|
|
1885
|
+
const { login, password } = auth;
|
|
1886
|
+
if (login && password) {
|
|
1887
|
+
yield this._login({ login, password });
|
|
1888
|
+
}
|
|
1889
|
+
}
|
|
1890
|
+
const routeUrl = `${this.routeStr}?client=${this.client}`;
|
|
1891
|
+
return this.routeCache.add(
|
|
1892
|
+
this.options.baseUrl || String(this.id),
|
|
1893
|
+
() => this.makeQuery(routeUrl, null, { signal, cache: false })
|
|
1894
|
+
);
|
|
1895
|
+
});
|
|
1896
|
+
}
|
|
1897
|
+
/**
|
|
1898
|
+
* Quick way to change NextGIS Web user.
|
|
1899
|
+
* @param credentials - New user credentials
|
|
1900
|
+
*/
|
|
1901
|
+
login(credentials, options) {
|
|
1902
|
+
this.logout();
|
|
1903
|
+
addConnector(this);
|
|
1904
|
+
return this._login(credentials, options);
|
|
1905
|
+
}
|
|
1906
|
+
/**
|
|
1907
|
+
* Disconnecting a user. Aborting all current requests
|
|
1908
|
+
*/
|
|
1909
|
+
logout() {
|
|
1910
|
+
this.abort();
|
|
1911
|
+
removeConnector(this);
|
|
1912
|
+
this.options.auth = void 0;
|
|
1913
|
+
this.user = void 0;
|
|
1914
|
+
this.routeCache.clean();
|
|
1915
|
+
this.clearCache();
|
|
1916
|
+
this.emitter.emit("logout");
|
|
1917
|
+
}
|
|
1918
|
+
getUserInfo(credentials, options) {
|
|
1919
|
+
return __async$3(this, null, function* () {
|
|
1920
|
+
if (this.user && this.user.id) {
|
|
1921
|
+
return this.user;
|
|
1922
|
+
}
|
|
1923
|
+
if (credentials) {
|
|
1924
|
+
this.options.auth = credentials;
|
|
1925
|
+
}
|
|
1926
|
+
const options_ = __spreadValues$4({
|
|
1927
|
+
headers: this.getAuthorizationHeaders(credentials),
|
|
1928
|
+
cache: true
|
|
1929
|
+
}, options);
|
|
1930
|
+
return this.makeQuery(
|
|
1931
|
+
"/api/component/auth/current_user",
|
|
1932
|
+
{},
|
|
1933
|
+
options_
|
|
1934
|
+
);
|
|
1935
|
+
});
|
|
1936
|
+
}
|
|
1937
|
+
/**
|
|
1938
|
+
* Obtaining the required Headers for authentication of requests in the NGW.
|
|
1939
|
+
*/
|
|
1940
|
+
getAuthorizationHeaders(credentials) {
|
|
1941
|
+
const client = this.makeClientId(credentials);
|
|
1942
|
+
if (client) {
|
|
1943
|
+
return {
|
|
1944
|
+
Authorization: `Basic ${client}`
|
|
1945
|
+
};
|
|
1946
|
+
}
|
|
1947
|
+
return {};
|
|
1948
|
+
}
|
|
1949
|
+
makeClientId(credentials) {
|
|
1950
|
+
credentials = credentials || this.options.auth;
|
|
1951
|
+
if (credentials) {
|
|
1952
|
+
const { login, password } = credentials;
|
|
1953
|
+
const encodedStr = [login, password].map(encodeURIComponent).join(":");
|
|
1954
|
+
{
|
|
1955
|
+
return window.btoa(encodedStr);
|
|
1956
|
+
}
|
|
1957
|
+
}
|
|
1958
|
+
}
|
|
1959
|
+
/** Stop all api requests */
|
|
1960
|
+
abort() {
|
|
1961
|
+
for (const abortController of Object.values(this.activeRequests)) {
|
|
1962
|
+
abortController.abort();
|
|
1963
|
+
}
|
|
1964
|
+
this.activeRequests = {};
|
|
1965
|
+
}
|
|
1966
|
+
getActiveApiRequests() {
|
|
1967
|
+
return __spreadValues$4({}, this.activeRequests);
|
|
1968
|
+
}
|
|
1969
|
+
route(name, ...rest) {
|
|
1970
|
+
return route(name, this, ...rest);
|
|
1971
|
+
}
|
|
1972
|
+
/**
|
|
1973
|
+
* Send request to NGW.
|
|
1974
|
+
* @param url - URL address to NGW
|
|
1975
|
+
* @param params - Query params
|
|
1976
|
+
* @param options - Request options
|
|
1977
|
+
*/
|
|
1978
|
+
makeQuery(_0, _1) {
|
|
1979
|
+
return __async$3(this, arguments, function* (url, params, options = {}) {
|
|
1980
|
+
var _b;
|
|
1981
|
+
url = (this.options.baseUrl ? this.options.baseUrl : "") + url;
|
|
1982
|
+
if (!url) {
|
|
1983
|
+
throw new Error("Empty `url` not allowed");
|
|
1984
|
+
}
|
|
1985
|
+
if (params) {
|
|
1986
|
+
const _a = params, restParams = __objRest(_a, ["paramList"]);
|
|
1987
|
+
url = template(url, restParams);
|
|
1988
|
+
}
|
|
1989
|
+
url = encodeURI(fixUrlStr(url));
|
|
1990
|
+
options = __spreadValues$4({ withCredentials: this.withCredentials }, options);
|
|
1991
|
+
const {
|
|
1992
|
+
cache,
|
|
1993
|
+
signal: externalSignal,
|
|
1994
|
+
method = "GET",
|
|
1995
|
+
headers,
|
|
1996
|
+
cacheName,
|
|
1997
|
+
cacheProps,
|
|
1998
|
+
responseType,
|
|
1999
|
+
withCredentials
|
|
2000
|
+
} = options;
|
|
2001
|
+
const internalAbortController = new AbortController();
|
|
2002
|
+
const internalSignal = internalAbortController.signal;
|
|
2003
|
+
if (externalSignal) {
|
|
2004
|
+
if (externalSignal.aborted) {
|
|
2005
|
+
throw new AbortError();
|
|
2006
|
+
}
|
|
2007
|
+
externalSignal.addEventListener("abort", () => {
|
|
2008
|
+
internalAbortController.abort();
|
|
2009
|
+
});
|
|
2010
|
+
}
|
|
2011
|
+
options.signal = internalSignal;
|
|
2012
|
+
const createPromise = () => __async$3(this, null, function* () {
|
|
2013
|
+
const id = REQUEST_ID++;
|
|
2014
|
+
this.activeRequests[id] = internalAbortController;
|
|
2015
|
+
try {
|
|
2016
|
+
return this._loadData(url, options);
|
|
2017
|
+
} finally {
|
|
2018
|
+
this._cleanActiveRequest(id);
|
|
2019
|
+
}
|
|
2020
|
+
});
|
|
2021
|
+
if (method === "GET" && cache !== false) {
|
|
2022
|
+
const cacheOptions = cacheProps ? cacheProps : __spreadProps$3(__spreadValues$4({}, objectRemoveEmpty({
|
|
2023
|
+
headers,
|
|
2024
|
+
withCredentials,
|
|
2025
|
+
responseType,
|
|
2026
|
+
baseUrl: this.options.baseUrl,
|
|
2027
|
+
userId: (_b = this.user) == null ? void 0 : _b.id
|
|
2028
|
+
})), {
|
|
2029
|
+
params
|
|
2030
|
+
});
|
|
2031
|
+
return this.cache.add(cacheName || url, createPromise, {
|
|
2032
|
+
props: cacheOptions,
|
|
2033
|
+
expirationTime: cache ? void 0 : 500
|
|
2034
|
+
});
|
|
2035
|
+
}
|
|
2036
|
+
return createPromise();
|
|
2037
|
+
});
|
|
2038
|
+
}
|
|
2039
|
+
_loadData(url, options) {
|
|
2040
|
+
options.responseType = options.responseType || "json";
|
|
2041
|
+
return new Promise((resolve, reject) => {
|
|
2042
|
+
var _a;
|
|
2043
|
+
if (this.user) {
|
|
2044
|
+
options = options || {};
|
|
2045
|
+
options.headers = __spreadValues$4(__spreadValues$4({}, this.getAuthorizationHeaders()), options.headers);
|
|
2046
|
+
}
|
|
2047
|
+
if (this.requestTransform) {
|
|
2048
|
+
const [transUrl, transOptions] = this.requestTransform(url, options);
|
|
2049
|
+
url = transUrl;
|
|
2050
|
+
options = transOptions;
|
|
2051
|
+
}
|
|
2052
|
+
let runOnAbort = void 0;
|
|
2053
|
+
loadData(url, resolve, options, reject, (handler) => {
|
|
2054
|
+
runOnAbort = handler;
|
|
2055
|
+
});
|
|
2056
|
+
(_a = options.signal) == null ? void 0 : _a.addEventListener("abort", () => {
|
|
2057
|
+
if (runOnAbort !== void 0) {
|
|
2058
|
+
runOnAbort();
|
|
2059
|
+
}
|
|
2060
|
+
reject(new AbortError());
|
|
2061
|
+
});
|
|
2062
|
+
}).catch((httpError) => {
|
|
2063
|
+
if (httpError.name !== "AbortError") {
|
|
2064
|
+
{
|
|
2065
|
+
console.warn("DEV WARN", httpError);
|
|
2066
|
+
}
|
|
2067
|
+
const er = this._handleHttpError(httpError);
|
|
2068
|
+
if (er) {
|
|
2069
|
+
throw er;
|
|
2070
|
+
}
|
|
2071
|
+
}
|
|
2072
|
+
throw httpError;
|
|
2073
|
+
});
|
|
2074
|
+
}
|
|
2075
|
+
_login(credentials, options) {
|
|
2076
|
+
return __async$3(this, null, function* () {
|
|
2077
|
+
try {
|
|
2078
|
+
const data = yield this.getUserInfo(credentials, options);
|
|
2079
|
+
this.user = data;
|
|
2080
|
+
this.emitter.emit("login", data);
|
|
2081
|
+
return data;
|
|
2082
|
+
} catch (er) {
|
|
2083
|
+
this.emitter.emit("login:error", er);
|
|
2084
|
+
throw er;
|
|
2085
|
+
}
|
|
2086
|
+
});
|
|
2087
|
+
}
|
|
2088
|
+
_cleanActiveRequest(requestId) {
|
|
2089
|
+
delete this.activeRequests[requestId];
|
|
2090
|
+
}
|
|
2091
|
+
_handleHttpError(er) {
|
|
2092
|
+
if (er) {
|
|
2093
|
+
if (er instanceof NgwError) {
|
|
2094
|
+
if (er.exception === "nextgisweb.resource.exception.ResourceNotFound") {
|
|
2095
|
+
throw new ResourceNotFoundError(er);
|
|
2096
|
+
} else if (er.exception === "nextgisweb.core.exception.InsufficientPermissions") {
|
|
2097
|
+
throw new InsufficientPermissionsError(er);
|
|
2098
|
+
}
|
|
2099
|
+
}
|
|
2100
|
+
}
|
|
2101
|
+
return er;
|
|
2102
|
+
}
|
|
2103
|
+
}
|
|
2104
|
+
__publicField$4(NgwConnector, "errors", errors);
|
|
2105
|
+
|
|
2106
|
+
function resourceCompare(res1, res2) {
|
|
2107
|
+
return objectDeepEqual(res1, res2);
|
|
2108
|
+
}
|
|
2109
|
+
|
|
2110
|
+
const exclude = ["description"];
|
|
2111
|
+
function resourceToQuery(resource, prefix = "") {
|
|
2112
|
+
prefix = prefix ? prefix + "__" : "";
|
|
2113
|
+
const query = {};
|
|
2114
|
+
for (const [key, value] of Object.entries(resource)) {
|
|
2115
|
+
if (exclude.indexOf(key) === -1) {
|
|
2116
|
+
if (isObject(value)) {
|
|
2117
|
+
if (key === "owner_user") {
|
|
2118
|
+
const children = resourceToQuery(
|
|
2119
|
+
value,
|
|
2120
|
+
key
|
|
2121
|
+
);
|
|
2122
|
+
Object.assign(query, children);
|
|
2123
|
+
} else if (key === "parent" && "id" in value) {
|
|
2124
|
+
query.parent_id = value.id;
|
|
2125
|
+
}
|
|
2126
|
+
} else if (defined(value)) {
|
|
2127
|
+
query[prefix + key] = value;
|
|
2128
|
+
}
|
|
2129
|
+
}
|
|
2130
|
+
}
|
|
2131
|
+
return query;
|
|
1510
2132
|
}
|
|
1511
2133
|
|
|
1512
|
-
var __defProp$
|
|
2134
|
+
var __defProp$5 = Object.defineProperty;
|
|
1513
2135
|
var __defProps$2 = Object.defineProperties;
|
|
1514
2136
|
var __getOwnPropDescs$2 = Object.getOwnPropertyDescriptors;
|
|
1515
2137
|
var __getOwnPropSymbols$3 = Object.getOwnPropertySymbols;
|
|
1516
2138
|
var __hasOwnProp$3 = Object.prototype.hasOwnProperty;
|
|
1517
2139
|
var __propIsEnum$3 = Object.prototype.propertyIsEnumerable;
|
|
1518
|
-
var __defNormalProp$
|
|
2140
|
+
var __defNormalProp$5 = (obj, key, value) => key in obj ? __defProp$5(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
1519
2141
|
var __spreadValues$3 = (a, b) => {
|
|
1520
2142
|
for (var prop in b || (b = {}))
|
|
1521
2143
|
if (__hasOwnProp$3.call(b, prop))
|
|
1522
|
-
__defNormalProp$
|
|
2144
|
+
__defNormalProp$5(a, prop, b[prop]);
|
|
1523
2145
|
if (__getOwnPropSymbols$3)
|
|
1524
2146
|
for (var prop of __getOwnPropSymbols$3(b)) {
|
|
1525
2147
|
if (__propIsEnum$3.call(b, prop))
|
|
1526
|
-
__defNormalProp$
|
|
2148
|
+
__defNormalProp$5(a, prop, b[prop]);
|
|
1527
2149
|
}
|
|
1528
2150
|
return a;
|
|
1529
2151
|
};
|
|
1530
2152
|
var __spreadProps$2 = (a, b) => __defProps$2(a, __getOwnPropDescs$2(b));
|
|
1531
|
-
var
|
|
1532
|
-
var target = {};
|
|
1533
|
-
for (var prop in source)
|
|
1534
|
-
if (__hasOwnProp$3.call(source, prop) && exclude.indexOf(prop) < 0)
|
|
1535
|
-
target[prop] = source[prop];
|
|
1536
|
-
if (source != null && __getOwnPropSymbols$3)
|
|
1537
|
-
for (var prop of __getOwnPropSymbols$3(source)) {
|
|
1538
|
-
if (exclude.indexOf(prop) < 0 && __propIsEnum$3.call(source, prop))
|
|
1539
|
-
target[prop] = source[prop];
|
|
1540
|
-
}
|
|
1541
|
-
return target;
|
|
1542
|
-
};
|
|
1543
|
-
var __publicField$2 = (obj, key, value) => __defNormalProp$4(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
2153
|
+
var __publicField$3 = (obj, key, value) => __defNormalProp$5(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
1544
2154
|
var __async$2 = (__this, __arguments, generator) => {
|
|
1545
2155
|
return new Promise((resolve, reject) => {
|
|
1546
2156
|
var fulfilled = (value) => {
|
|
@@ -1561,173 +2171,269 @@ var __async$2 = (__this, __arguments, generator) => {
|
|
|
1561
2171
|
step((generator = generator.apply(__this, __arguments)).next());
|
|
1562
2172
|
});
|
|
1563
2173
|
};
|
|
1564
|
-
|
|
1565
|
-
|
|
1566
|
-
|
|
1567
|
-
|
|
1568
|
-
|
|
1569
|
-
__publicField$
|
|
1570
|
-
__publicField$
|
|
1571
|
-
|
|
1572
|
-
|
|
1573
|
-
__publicField$2(this, "cache");
|
|
1574
|
-
__publicField$2(this, "withCredentials");
|
|
1575
|
-
__publicField$2(this, "client", `NextGIS-NGW-Connector/${pkg.version}`);
|
|
1576
|
-
__publicField$2(this, "routeStr", "/api/component/pyramid/route");
|
|
1577
|
-
__publicField$2(this, "activeRequests", {});
|
|
1578
|
-
__publicField$2(this, "requestTransform");
|
|
1579
|
-
const exist = findConnector(options);
|
|
1580
|
-
this.cache = new Cache({ namespace: options.cacheId });
|
|
1581
|
-
if (exist) {
|
|
1582
|
-
return exist;
|
|
1583
|
-
} else {
|
|
1584
|
-
const { route, requestTransform, withCredentials } = this.options;
|
|
1585
|
-
if (route) {
|
|
1586
|
-
this.routeStr = route;
|
|
1587
|
-
}
|
|
1588
|
-
if (requestTransform) {
|
|
1589
|
-
this.requestTransform = requestTransform;
|
|
1590
|
-
}
|
|
1591
|
-
if (withCredentials !== void 0) {
|
|
1592
|
-
this.withCredentials = withCredentials;
|
|
1593
|
-
}
|
|
1594
|
-
this.resources = new ResourcesControl({
|
|
1595
|
-
connector: this,
|
|
1596
|
-
cacheId: options.cacheId
|
|
1597
|
-
});
|
|
1598
|
-
addConnector(this);
|
|
1599
|
-
}
|
|
1600
|
-
}
|
|
1601
|
-
static create(options) {
|
|
1602
|
-
return new this(options);
|
|
2174
|
+
class ResourcesControl {
|
|
2175
|
+
constructor({
|
|
2176
|
+
connector,
|
|
2177
|
+
cacheId
|
|
2178
|
+
}) {
|
|
2179
|
+
__publicField$3(this, "cache");
|
|
2180
|
+
__publicField$3(this, "connector");
|
|
2181
|
+
this.connector = connector;
|
|
2182
|
+
this.cache = new Cache({ namespace: cacheId });
|
|
1603
2183
|
}
|
|
2184
|
+
// -------------------------------------------------------------------------
|
|
2185
|
+
// Resource Methods
|
|
2186
|
+
// -------------------------------------------------------------------------
|
|
1604
2187
|
/**
|
|
1605
|
-
*
|
|
2188
|
+
* Receive resource from NGW by id, keyname or search-object parameter.
|
|
2189
|
+
* @param resource - Resource id, keyname or search-object
|
|
2190
|
+
*
|
|
2191
|
+
* @remarks
|
|
2192
|
+
* Fetching resource would be cached to speed up next call
|
|
1606
2193
|
*/
|
|
1607
|
-
|
|
1608
|
-
|
|
1609
|
-
|
|
2194
|
+
getOne(resource, requestOptions) {
|
|
2195
|
+
const opt = __spreadValues$3({}, requestOptions);
|
|
2196
|
+
if (typeof resource === "string") ; else if (typeof resource === "number") ; else if (isObject(resource)) {
|
|
2197
|
+
if (resource.id !== void 0) {
|
|
2198
|
+
resource.id;
|
|
2199
|
+
} else {
|
|
2200
|
+
if (resource.keyname) {
|
|
2201
|
+
resource.keyname;
|
|
2202
|
+
}
|
|
2203
|
+
if (resource.display_name) {
|
|
2204
|
+
resource.display_name;
|
|
2205
|
+
}
|
|
2206
|
+
}
|
|
2207
|
+
}
|
|
2208
|
+
if (typeof resource === "string") {
|
|
2209
|
+
return this._fetchResourceBy({ keyname: resource }, opt);
|
|
2210
|
+
} else if (typeof resource === "number") {
|
|
2211
|
+
return this._fetchResourceById(resource, opt);
|
|
2212
|
+
} else if (isObject(resource)) {
|
|
2213
|
+
return this._fetchResourceBy(resource, opt);
|
|
2214
|
+
}
|
|
2215
|
+
return Promise.resolve(void 0);
|
|
1610
2216
|
}
|
|
1611
|
-
|
|
1612
|
-
this.
|
|
2217
|
+
getOneOrFail(resource, requestOptions) {
|
|
2218
|
+
return this.getOne(resource, requestOptions).then((res) => {
|
|
2219
|
+
if (res) {
|
|
2220
|
+
return res;
|
|
2221
|
+
}
|
|
2222
|
+
throw new ResourceNotFoundError();
|
|
2223
|
+
});
|
|
1613
2224
|
}
|
|
1614
2225
|
/**
|
|
1615
|
-
*
|
|
1616
|
-
*
|
|
1617
|
-
*
|
|
2226
|
+
* A fast way to retrieve resource ID for any resource definition.
|
|
2227
|
+
* @param resource - Any available resource definition
|
|
2228
|
+
*
|
|
2229
|
+
* @remarks
|
|
2230
|
+
* There are situations when exactly the resource id is needed
|
|
2231
|
+
* (for example, to compose the correct request to the api)
|
|
2232
|
+
* then this method will come in handy to facilitate the extraction of the identifier
|
|
2233
|
+
* if the resource is specified through a keyname or other parameters.
|
|
1618
2234
|
*/
|
|
1619
|
-
|
|
1620
|
-
|
|
1621
|
-
|
|
1622
|
-
|
|
2235
|
+
getId(resource, requestOptions) {
|
|
2236
|
+
if (typeof resource === "number") {
|
|
2237
|
+
return Promise.resolve(resource);
|
|
2238
|
+
} else if (typeof resource === "string" || isObject(resource)) {
|
|
2239
|
+
return this.getOne(resource, requestOptions).then((res) => {
|
|
2240
|
+
if (res) {
|
|
2241
|
+
return res.resource.id;
|
|
2242
|
+
}
|
|
2243
|
+
});
|
|
2244
|
+
}
|
|
2245
|
+
return Promise.resolve(void 0);
|
|
1623
2246
|
}
|
|
1624
2247
|
/**
|
|
1625
|
-
*
|
|
2248
|
+
* A fast way to retrieve resource ID for any resource definition.
|
|
2249
|
+
* @param resource - Any available resource definition
|
|
2250
|
+
*
|
|
1626
2251
|
* @remarks
|
|
1627
|
-
*
|
|
1628
|
-
*
|
|
1629
|
-
* @example
|
|
1630
|
-
* ```javascript
|
|
1631
|
-
* const connector = new NgwConnector({baseUrl: 'https://demo.nextgis.com'});
|
|
1632
|
-
* connector.connect()
|
|
1633
|
-
* .then(() => console.log('Ok'))
|
|
1634
|
-
* .catch((er) => console.log('Connection problem', er));
|
|
1635
|
-
* ```
|
|
2252
|
+
* Similar with {@link NgwConnector.getResourceId | getResourceId} but rise error if resource is not exist.
|
|
2253
|
+
* To not make one more checks if the resource is definitely exists
|
|
1636
2254
|
*/
|
|
1637
|
-
|
|
1638
|
-
return
|
|
1639
|
-
|
|
1640
|
-
|
|
1641
|
-
const { login, password } = auth;
|
|
1642
|
-
if (login && password) {
|
|
1643
|
-
yield this._login({ login, password });
|
|
1644
|
-
}
|
|
2255
|
+
getIdOrFail(resource, requestOptions) {
|
|
2256
|
+
return this.getId(resource, requestOptions).then((resp) => {
|
|
2257
|
+
if (resp === void 0) {
|
|
2258
|
+
throw new Error();
|
|
1645
2259
|
}
|
|
1646
|
-
|
|
1647
|
-
|
|
1648
|
-
|
|
1649
|
-
|
|
1650
|
-
|
|
1651
|
-
|
|
1652
|
-
|
|
1653
|
-
|
|
1654
|
-
|
|
1655
|
-
|
|
1656
|
-
|
|
1657
|
-
}
|
|
2260
|
+
return resp;
|
|
2261
|
+
});
|
|
2262
|
+
}
|
|
2263
|
+
getMany(resource, requestOptions) {
|
|
2264
|
+
return this._resourceCacheFilter(resource).then((items) => {
|
|
2265
|
+
if (!items.length) {
|
|
2266
|
+
const query = {};
|
|
2267
|
+
if (resource.keyname) {
|
|
2268
|
+
query.keyname = resource.keyname;
|
|
2269
|
+
} else {
|
|
2270
|
+
Object.assign(query, resourceToQuery(resource));
|
|
1658
2271
|
}
|
|
1659
|
-
|
|
2272
|
+
return this.connector.route("resource.search").get(__spreadProps$2(__spreadValues$3({}, requestOptions), {
|
|
2273
|
+
query: __spreadValues$3({
|
|
2274
|
+
serialization: "full"
|
|
2275
|
+
}, query)
|
|
2276
|
+
})).then((resources) => {
|
|
2277
|
+
if ((requestOptions == null ? void 0 : requestOptions.cache) && resources) {
|
|
2278
|
+
for (const x of resources) {
|
|
2279
|
+
this.cache.add("resource.item", Promise.resolve(x), {
|
|
2280
|
+
id: x.resource.id
|
|
2281
|
+
});
|
|
2282
|
+
}
|
|
2283
|
+
}
|
|
2284
|
+
return resources;
|
|
2285
|
+
});
|
|
2286
|
+
}
|
|
2287
|
+
return items;
|
|
1660
2288
|
});
|
|
1661
2289
|
}
|
|
1662
|
-
|
|
1663
|
-
|
|
1664
|
-
|
|
1665
|
-
|
|
1666
|
-
|
|
1667
|
-
|
|
1668
|
-
|
|
1669
|
-
|
|
2290
|
+
getParent(resource, requestOptions) {
|
|
2291
|
+
return this.getOne(resource, requestOptions).then((child) => {
|
|
2292
|
+
var _a, _b;
|
|
2293
|
+
if ((_b = (_a = child == null ? void 0 : child.resource) == null ? void 0 : _a.parent) == null ? void 0 : _b.id) {
|
|
2294
|
+
return this.getOne(child.resource.parent.id, requestOptions);
|
|
2295
|
+
}
|
|
2296
|
+
return Promise.resolve(void 0);
|
|
2297
|
+
});
|
|
2298
|
+
}
|
|
2299
|
+
getChildrenOf(resource, requestOptions) {
|
|
2300
|
+
return this.getIdOrFail(resource).then(
|
|
2301
|
+
(parent) => this._getChildrenOf(parent, requestOptions)
|
|
2302
|
+
);
|
|
2303
|
+
}
|
|
2304
|
+
update(resource, data) {
|
|
2305
|
+
return this.getId(resource).then((id) => {
|
|
2306
|
+
if (id !== void 0) {
|
|
2307
|
+
return this.connector.put("resource.item", { data }, { id });
|
|
2308
|
+
}
|
|
2309
|
+
});
|
|
1670
2310
|
}
|
|
1671
2311
|
/**
|
|
1672
|
-
*
|
|
2312
|
+
* Fast way to delete resource from NGW and clean cache.
|
|
2313
|
+
* @param resource - Resource definition
|
|
1673
2314
|
*/
|
|
1674
|
-
|
|
1675
|
-
this.
|
|
1676
|
-
|
|
1677
|
-
|
|
1678
|
-
|
|
1679
|
-
|
|
1680
|
-
|
|
2315
|
+
delete(resource) {
|
|
2316
|
+
return this.getId(resource).then((id) => {
|
|
2317
|
+
if (id !== void 0) {
|
|
2318
|
+
return this.connector.delete("resource.item", null, { id }).then(() => {
|
|
2319
|
+
this._cleanResourceItemCache(id);
|
|
2320
|
+
return void 0;
|
|
2321
|
+
});
|
|
2322
|
+
}
|
|
2323
|
+
});
|
|
1681
2324
|
}
|
|
1682
|
-
|
|
2325
|
+
_getChildrenOf(_0, _1) {
|
|
2326
|
+
return __async$2(this, arguments, function* (parentDef, requestOptions, _items = []) {
|
|
2327
|
+
let parent = void 0;
|
|
2328
|
+
if (typeof parentDef === "string") {
|
|
2329
|
+
parent = yield this.getId(parentDef, requestOptions);
|
|
2330
|
+
} else if (typeof parentDef === "object") {
|
|
2331
|
+
parent = parentDef.id;
|
|
2332
|
+
} else {
|
|
2333
|
+
parent = parentDef;
|
|
2334
|
+
}
|
|
2335
|
+
const items = yield this.connector.route("resource.collection").get(__spreadProps$2(__spreadValues$3({}, requestOptions), {
|
|
2336
|
+
query: {
|
|
2337
|
+
parent
|
|
2338
|
+
}
|
|
2339
|
+
}));
|
|
2340
|
+
const recursivePromises = [];
|
|
2341
|
+
for (const item of items) {
|
|
2342
|
+
if (requestOptions == null ? void 0 : requestOptions.cache) {
|
|
2343
|
+
this.cache.add("resource.item", Promise.resolve(item), {
|
|
2344
|
+
id: item.resource.id
|
|
2345
|
+
});
|
|
2346
|
+
}
|
|
2347
|
+
_items.push(item);
|
|
2348
|
+
if ((requestOptions == null ? void 0 : requestOptions.recursive) && item.resource.children) {
|
|
2349
|
+
recursivePromises.push(
|
|
2350
|
+
this._getChildrenOf(item.resource.id, requestOptions, _items)
|
|
2351
|
+
);
|
|
2352
|
+
}
|
|
2353
|
+
}
|
|
2354
|
+
if (recursivePromises.length) {
|
|
2355
|
+
return Promise.all(recursivePromises).then(() => {
|
|
2356
|
+
return _items;
|
|
2357
|
+
});
|
|
2358
|
+
}
|
|
2359
|
+
return _items;
|
|
2360
|
+
});
|
|
2361
|
+
}
|
|
2362
|
+
_cleanResourceItemCache(id) {
|
|
1683
2363
|
return __async$2(this, null, function* () {
|
|
1684
|
-
|
|
1685
|
-
|
|
2364
|
+
var _a;
|
|
2365
|
+
const all = this.cache.all();
|
|
2366
|
+
const toDelete = [];
|
|
2367
|
+
for (const c of all) {
|
|
2368
|
+
const cid = (_a = c.props) == null ? void 0 : _a.id;
|
|
2369
|
+
if (["resource.item", "resource"].includes(c.key) && cid !== void 0) {
|
|
2370
|
+
if (typeof cid === "number") {
|
|
2371
|
+
if (cid === id) {
|
|
2372
|
+
toDelete.push(c);
|
|
2373
|
+
}
|
|
2374
|
+
} else {
|
|
2375
|
+
const rid = yield this.getId(cid);
|
|
2376
|
+
if (rid === id) {
|
|
2377
|
+
toDelete.push(c);
|
|
2378
|
+
}
|
|
2379
|
+
}
|
|
2380
|
+
}
|
|
1686
2381
|
}
|
|
1687
|
-
|
|
1688
|
-
this.
|
|
2382
|
+
for (const d of toDelete) {
|
|
2383
|
+
this.cache.delete(d);
|
|
1689
2384
|
}
|
|
1690
|
-
const options_ = __spreadValues$3({
|
|
1691
|
-
headers: this.getAuthorizationHeaders(credentials)
|
|
1692
|
-
}, options);
|
|
1693
|
-
return this.makeQuery(
|
|
1694
|
-
"/api/component/auth/current_user",
|
|
1695
|
-
{},
|
|
1696
|
-
options_
|
|
1697
|
-
);
|
|
1698
2385
|
});
|
|
1699
2386
|
}
|
|
1700
|
-
|
|
1701
|
-
|
|
1702
|
-
*/
|
|
1703
|
-
getAuthorizationHeaders(credentials) {
|
|
1704
|
-
const client = this.makeClientId(credentials);
|
|
1705
|
-
if (client) {
|
|
1706
|
-
return {
|
|
1707
|
-
Authorization: `Basic ${client}`
|
|
1708
|
-
};
|
|
1709
|
-
}
|
|
2387
|
+
_fetchResourceById(id, requestOptions) {
|
|
2388
|
+
return this.connector.route("resource.item", { id }).get(requestOptions);
|
|
1710
2389
|
}
|
|
1711
|
-
|
|
1712
|
-
|
|
1713
|
-
|
|
1714
|
-
|
|
1715
|
-
|
|
1716
|
-
|
|
1717
|
-
|
|
1718
|
-
|
|
2390
|
+
_fetchResourceBy(resource, requestOptions) {
|
|
2391
|
+
return this.getMany(resource, requestOptions).then((resources) => {
|
|
2392
|
+
return resources[0];
|
|
2393
|
+
});
|
|
2394
|
+
}
|
|
2395
|
+
_resourceCacheFilter(resource) {
|
|
2396
|
+
return Promise.all(this.cache.matchAll("resource.item")).then(
|
|
2397
|
+
(resources) => {
|
|
2398
|
+
const items = [];
|
|
2399
|
+
resources.filter((x) => {
|
|
2400
|
+
if (x) {
|
|
2401
|
+
if (resource.keyname && x.resource.keyname) {
|
|
2402
|
+
return resource.keyname === x.resource.keyname;
|
|
2403
|
+
}
|
|
2404
|
+
if (defined(resource.id) && defined(x.resource.id)) {
|
|
2405
|
+
return resource.id === x.resource.id;
|
|
2406
|
+
}
|
|
2407
|
+
return resourceCompare(resource, x.resource);
|
|
2408
|
+
}
|
|
2409
|
+
});
|
|
2410
|
+
return items;
|
|
1719
2411
|
}
|
|
1720
|
-
|
|
2412
|
+
);
|
|
1721
2413
|
}
|
|
1722
|
-
|
|
1723
|
-
|
|
1724
|
-
|
|
1725
|
-
|
|
1726
|
-
|
|
1727
|
-
|
|
2414
|
+
}
|
|
2415
|
+
|
|
2416
|
+
var __defProp$4 = Object.defineProperty;
|
|
2417
|
+
var __defNormalProp$4 = (obj, key, value) => key in obj ? __defProp$4(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
2418
|
+
var __publicField$2 = (obj, key, value) => __defNormalProp$4(obj, key + "" , value);
|
|
2419
|
+
class NgwConnectorExtended extends NgwConnector {
|
|
2420
|
+
constructor(options) {
|
|
2421
|
+
super(options);
|
|
2422
|
+
__publicField$2(this, "resources");
|
|
2423
|
+
this.resources = new ResourcesControl({
|
|
2424
|
+
connector: this,
|
|
2425
|
+
cacheId: options.cacheId
|
|
2426
|
+
});
|
|
1728
2427
|
}
|
|
1729
|
-
|
|
1730
|
-
return
|
|
2428
|
+
static create(options) {
|
|
2429
|
+
return new this(options);
|
|
2430
|
+
}
|
|
2431
|
+
/**
|
|
2432
|
+
* Clear the cache.
|
|
2433
|
+
*/
|
|
2434
|
+
clearCache() {
|
|
2435
|
+
super.clearCache();
|
|
2436
|
+
this.resources.cache.clean();
|
|
1731
2437
|
}
|
|
1732
2438
|
/**
|
|
1733
2439
|
* Send request to NGW api router.
|
|
@@ -1846,75 +2552,6 @@ class NgwConnector {
|
|
|
1846
2552
|
options
|
|
1847
2553
|
);
|
|
1848
2554
|
}
|
|
1849
|
-
/**
|
|
1850
|
-
* Send request to NGW.
|
|
1851
|
-
* @param url - URL address to NGW
|
|
1852
|
-
* @param params - Query params
|
|
1853
|
-
* @param options - Request options
|
|
1854
|
-
*/
|
|
1855
|
-
makeQuery(_0, _1) {
|
|
1856
|
-
return __async$2(this, arguments, function* (url, params, options = {}) {
|
|
1857
|
-
var _b;
|
|
1858
|
-
url = (this.options.baseUrl ? this.options.baseUrl : "") + url;
|
|
1859
|
-
if (!url) {
|
|
1860
|
-
throw new Error("Empty `url` not allowed");
|
|
1861
|
-
}
|
|
1862
|
-
if (params) {
|
|
1863
|
-
const _a = params, restParams = __objRest(_a, ["paramList"]);
|
|
1864
|
-
url = template(url, restParams);
|
|
1865
|
-
}
|
|
1866
|
-
url = encodeURI(fixUrlStr(url));
|
|
1867
|
-
options = __spreadValues$3({ withCredentials: this.withCredentials }, options);
|
|
1868
|
-
const {
|
|
1869
|
-
cache,
|
|
1870
|
-
signal: externalSignal,
|
|
1871
|
-
method = "GET",
|
|
1872
|
-
headers,
|
|
1873
|
-
cacheName,
|
|
1874
|
-
cacheProps,
|
|
1875
|
-
responseType,
|
|
1876
|
-
withCredentials
|
|
1877
|
-
} = options;
|
|
1878
|
-
const internalAbortController = new AbortController();
|
|
1879
|
-
const internalSignal = internalAbortController.signal;
|
|
1880
|
-
if (externalSignal) {
|
|
1881
|
-
if (externalSignal.aborted) {
|
|
1882
|
-
throw new AbortError();
|
|
1883
|
-
}
|
|
1884
|
-
externalSignal.addEventListener("abort", () => {
|
|
1885
|
-
internalAbortController.abort();
|
|
1886
|
-
});
|
|
1887
|
-
}
|
|
1888
|
-
options.signal = internalSignal;
|
|
1889
|
-
const createPromise = () => __async$2(this, null, function* () {
|
|
1890
|
-
const id = REQUEST_ID++;
|
|
1891
|
-
this.activeRequests[id] = internalAbortController;
|
|
1892
|
-
try {
|
|
1893
|
-
return this._loadData(url, options);
|
|
1894
|
-
} finally {
|
|
1895
|
-
this._cleanActiveRequest(id);
|
|
1896
|
-
}
|
|
1897
|
-
});
|
|
1898
|
-
if (cache && method === "GET") {
|
|
1899
|
-
const cacheOptions = cacheProps ? cacheProps : __spreadProps$2(__spreadValues$3({}, objectRemoveEmpty({
|
|
1900
|
-
headers,
|
|
1901
|
-
withCredentials,
|
|
1902
|
-
responseType,
|
|
1903
|
-
baseUrl: this.options.baseUrl,
|
|
1904
|
-
userId: (_b = this.user) == null ? void 0 : _b.id
|
|
1905
|
-
})), {
|
|
1906
|
-
params
|
|
1907
|
-
});
|
|
1908
|
-
return this.cache.add(
|
|
1909
|
-
cacheName || url,
|
|
1910
|
-
createPromise,
|
|
1911
|
-
cacheOptions,
|
|
1912
|
-
false
|
|
1913
|
-
);
|
|
1914
|
-
}
|
|
1915
|
-
return createPromise();
|
|
1916
|
-
});
|
|
1917
|
-
}
|
|
1918
2555
|
// -------------------------------------------------------------------------
|
|
1919
2556
|
// Resource Methods
|
|
1920
2557
|
// -------------------------------------------------------------------------
|
|
@@ -1990,78 +2627,7 @@ class NgwConnector {
|
|
|
1990
2627
|
deleteResource(resource) {
|
|
1991
2628
|
return this.resources.delete(resource);
|
|
1992
2629
|
}
|
|
1993
|
-
/**
|
|
1994
|
-
* @internal
|
|
1995
|
-
*/
|
|
1996
|
-
_loadData(url, options) {
|
|
1997
|
-
options.responseType = options.responseType || "json";
|
|
1998
|
-
return new Promise((resolve, reject) => {
|
|
1999
|
-
var _a;
|
|
2000
|
-
if (this.user) {
|
|
2001
|
-
options = options || {};
|
|
2002
|
-
options.headers = __spreadValues$3(__spreadValues$3({}, this.getAuthorizationHeaders()), options.headers);
|
|
2003
|
-
}
|
|
2004
|
-
if (this.requestTransform) {
|
|
2005
|
-
const [transUrl, transOptions] = this.requestTransform(url, options);
|
|
2006
|
-
url = transUrl;
|
|
2007
|
-
options = transOptions;
|
|
2008
|
-
}
|
|
2009
|
-
let runOnAbort = void 0;
|
|
2010
|
-
loadData(url, resolve, options, reject, (handler) => {
|
|
2011
|
-
runOnAbort = handler;
|
|
2012
|
-
});
|
|
2013
|
-
(_a = options.signal) == null ? void 0 : _a.addEventListener("abort", () => {
|
|
2014
|
-
if (runOnAbort !== void 0) {
|
|
2015
|
-
runOnAbort();
|
|
2016
|
-
}
|
|
2017
|
-
reject(new AbortError());
|
|
2018
|
-
});
|
|
2019
|
-
}).catch((httpError) => {
|
|
2020
|
-
if (httpError.name !== "AbortError") {
|
|
2021
|
-
{
|
|
2022
|
-
console.warn("DEV WARN", httpError);
|
|
2023
|
-
}
|
|
2024
|
-
const er = this._handleHttpError(httpError);
|
|
2025
|
-
if (er) {
|
|
2026
|
-
throw er;
|
|
2027
|
-
}
|
|
2028
|
-
}
|
|
2029
|
-
throw httpError;
|
|
2030
|
-
});
|
|
2031
|
-
}
|
|
2032
|
-
_login(credentials, options) {
|
|
2033
|
-
return __async$2(this, null, function* () {
|
|
2034
|
-
try {
|
|
2035
|
-
const data = yield this.getUserInfo(credentials, options);
|
|
2036
|
-
this.user = data;
|
|
2037
|
-
this.emitter.emit("login", data);
|
|
2038
|
-
return data;
|
|
2039
|
-
} catch (er) {
|
|
2040
|
-
this.emitter.emit("login:error", er);
|
|
2041
|
-
throw er;
|
|
2042
|
-
}
|
|
2043
|
-
});
|
|
2044
|
-
}
|
|
2045
|
-
_cleanActiveRequest(requestId) {
|
|
2046
|
-
delete this.activeRequests[requestId];
|
|
2047
|
-
}
|
|
2048
|
-
_handleHttpError(er) {
|
|
2049
|
-
if (er) {
|
|
2050
|
-
if (er instanceof NgwError) {
|
|
2051
|
-
if (er.exception === "nextgisweb.resource.exception.ResourceNotFound") {
|
|
2052
|
-
throw new ResourceNotFoundError(er);
|
|
2053
|
-
} else if (er.exception === "nextgisweb.core.exception.InsufficientPermissions") {
|
|
2054
|
-
throw new InsufficientPermissionsError(er);
|
|
2055
|
-
}
|
|
2056
|
-
}
|
|
2057
|
-
}
|
|
2058
|
-
return er;
|
|
2059
|
-
}
|
|
2060
2630
|
}
|
|
2061
|
-
__publicField$2(NgwConnector, "errors", {
|
|
2062
|
-
NgwError,
|
|
2063
|
-
ResourceNotFoundError
|
|
2064
|
-
});
|
|
2065
2631
|
|
|
2066
2632
|
function reEscape(s) {
|
|
2067
2633
|
return s.replace(/[-/\\^$*+?.()|[\]{}]/g, "\\$&");
|
|
@@ -2174,19 +2740,17 @@ var __async$1 = (__this, __arguments, generator) => {
|
|
|
2174
2740
|
};
|
|
2175
2741
|
const FEATURE_REQUEST_PARAMS = {
|
|
2176
2742
|
srs: 4326,
|
|
2177
|
-
geom_format: "geojson"
|
|
2743
|
+
geom_format: "geojson",
|
|
2744
|
+
dt_format: "iso"
|
|
2178
2745
|
};
|
|
2179
2746
|
function updateItemRequestParam(params, options) {
|
|
2180
2747
|
const { extensions, geom, fields, srs, ilike, like } = options;
|
|
2181
|
-
|
|
2182
|
-
if (
|
|
2183
|
-
params.
|
|
2184
|
-
}
|
|
2185
|
-
if (fields !== void 0 && fields !== null) {
|
|
2186
|
-
params.fields = Array.isArray(fields) ? fields.join(",") : "";
|
|
2748
|
+
params.extensions = extensions ? extensions : [];
|
|
2749
|
+
if (fields) {
|
|
2750
|
+
params.fields = fields;
|
|
2187
2751
|
}
|
|
2188
2752
|
if (geom !== void 0) {
|
|
2189
|
-
params.geom = geom
|
|
2753
|
+
params.geom = geom;
|
|
2190
2754
|
if (!geom) {
|
|
2191
2755
|
delete params.srs;
|
|
2192
2756
|
delete params.geom_format;
|
|
@@ -2201,6 +2765,15 @@ function updateItemRequestParam(params, options) {
|
|
|
2201
2765
|
params.srs = srs;
|
|
2202
2766
|
}
|
|
2203
2767
|
}
|
|
2768
|
+
function paramListToQuery(paramList) {
|
|
2769
|
+
return paramList.reduce(
|
|
2770
|
+
(acc, [key, value]) => {
|
|
2771
|
+
acc[key] = value;
|
|
2772
|
+
return acc;
|
|
2773
|
+
},
|
|
2774
|
+
{}
|
|
2775
|
+
);
|
|
2776
|
+
}
|
|
2204
2777
|
function createFeatureFieldFilterQueries(opt) {
|
|
2205
2778
|
return __async$1(this, null, function* () {
|
|
2206
2779
|
const queries = getQueries(opt);
|
|
@@ -2251,13 +2824,7 @@ function getQueries(opt, _queries = [], _parentAllParams = []) {
|
|
|
2251
2824
|
}))
|
|
2252
2825
|
);
|
|
2253
2826
|
} else {
|
|
2254
|
-
getQueries(
|
|
2255
|
-
__spreadProps$1(__spreadValues$2({}, opt), {
|
|
2256
|
-
filters: f
|
|
2257
|
-
}),
|
|
2258
|
-
_queries,
|
|
2259
|
-
[..._parentAllParams]
|
|
2260
|
-
);
|
|
2827
|
+
getQueries(__spreadProps$1(__spreadValues$2({}, opt), { filters: f }), _queries, [..._parentAllParams]);
|
|
2261
2828
|
}
|
|
2262
2829
|
}
|
|
2263
2830
|
} else if (logic === "all") {
|
|
@@ -2272,13 +2839,10 @@ function getQueries(opt, _queries = [], _parentAllParams = []) {
|
|
|
2272
2839
|
}
|
|
2273
2840
|
if (propertiesFilterList.length) {
|
|
2274
2841
|
for (const x of propertiesFilterList) {
|
|
2275
|
-
getQueries(
|
|
2276
|
-
|
|
2277
|
-
|
|
2278
|
-
|
|
2279
|
-
_queries,
|
|
2280
|
-
[..._parentAllParams, ...filters2]
|
|
2281
|
-
);
|
|
2842
|
+
getQueries(__spreadProps$1(__spreadValues$2({}, opt), { filters: x }), _queries, [
|
|
2843
|
+
..._parentAllParams,
|
|
2844
|
+
...filters2
|
|
2845
|
+
]);
|
|
2282
2846
|
}
|
|
2283
2847
|
} else {
|
|
2284
2848
|
_queries.push(
|
|
@@ -2301,6 +2865,7 @@ function fetchNgwLayerItemsRequest(options) {
|
|
|
2301
2865
|
const params = __spreadValues$2({}, FEATURE_REQUEST_PARAMS);
|
|
2302
2866
|
const {
|
|
2303
2867
|
limit,
|
|
2868
|
+
query,
|
|
2304
2869
|
cache,
|
|
2305
2870
|
signal,
|
|
2306
2871
|
offset,
|
|
@@ -2311,12 +2876,8 @@ function fetchNgwLayerItemsRequest(options) {
|
|
|
2311
2876
|
intersects,
|
|
2312
2877
|
resourceId
|
|
2313
2878
|
} = options;
|
|
2314
|
-
if (limit) {
|
|
2315
|
-
|
|
2316
|
-
params.limit = limit;
|
|
2317
|
-
}
|
|
2318
|
-
} else {
|
|
2319
|
-
params.limit = 7e3;
|
|
2879
|
+
if (typeof limit === "number" && limit !== Number.POSITIVE_INFINITY) {
|
|
2880
|
+
params.limit = limit;
|
|
2320
2881
|
}
|
|
2321
2882
|
if (offset) {
|
|
2322
2883
|
params.offset = offset;
|
|
@@ -2335,16 +2896,9 @@ function fetchNgwLayerItemsRequest(options) {
|
|
|
2335
2896
|
params.intersects = intersects;
|
|
2336
2897
|
}
|
|
2337
2898
|
if (paramList) {
|
|
2338
|
-
params
|
|
2339
|
-
}
|
|
2340
|
-
|
|
2341
|
-
id: resourceId
|
|
2342
|
-
}, params);
|
|
2343
|
-
return connector.get(
|
|
2344
|
-
"feature_layer.feature.collection",
|
|
2345
|
-
{ cache, signal },
|
|
2346
|
-
reqParams
|
|
2347
|
-
);
|
|
2899
|
+
Object.assign(params, paramListToQuery(paramList));
|
|
2900
|
+
}
|
|
2901
|
+
return connector.route("feature_layer.feature.collection", { id: Number(resourceId) }).get({ query: __spreadValues$2(__spreadValues$2({}, params), query), cache, signal });
|
|
2348
2902
|
}
|
|
2349
2903
|
|
|
2350
2904
|
function prepareNgwFieldsToPropertiesFilter(fields) {
|
|
@@ -2497,7 +3051,7 @@ const _NgwProvider = class _NgwProvider extends BaseProvider {
|
|
|
2497
3051
|
"The `searchUrl` of `connectorOptions.baseUrl` are required"
|
|
2498
3052
|
);
|
|
2499
3053
|
}
|
|
2500
|
-
this.connector = options.connector || new
|
|
3054
|
+
this.connector = options.connector || new NgwConnectorExtended(__spreadValues({
|
|
2501
3055
|
baseUrl: this.searchUrl
|
|
2502
3056
|
}, options.connectorOptions));
|
|
2503
3057
|
this.searchResources = options.searchResources;
|
|
@@ -2546,7 +3100,7 @@ const _NgwProvider = class _NgwProvider extends BaseProvider {
|
|
|
2546
3100
|
yield item;
|
|
2547
3101
|
}
|
|
2548
3102
|
} catch (er) {
|
|
2549
|
-
if (er && "name" in er && er.name !== "
|
|
3103
|
+
if (er && "name" in er && er.name !== "AbortError") {
|
|
2550
3104
|
console.warn(er);
|
|
2551
3105
|
}
|
|
2552
3106
|
}
|
|
@@ -2555,15 +3109,16 @@ const _NgwProvider = class _NgwProvider extends BaseProvider {
|
|
|
2555
3109
|
}
|
|
2556
3110
|
result(item) {
|
|
2557
3111
|
const signal = this._makeSignal();
|
|
2558
|
-
const req = this.connector.
|
|
2559
|
-
|
|
2560
|
-
|
|
2561
|
-
|
|
2562
|
-
|
|
2563
|
-
|
|
2564
|
-
|
|
2565
|
-
|
|
2566
|
-
|
|
3112
|
+
const req = this.connector.route("feature_layer.feature.item_extent", {
|
|
3113
|
+
id: item.resourceId,
|
|
3114
|
+
fid: item.featureId
|
|
3115
|
+
}).get({ signal }).then((x) => {
|
|
3116
|
+
const e = x.extent || {
|
|
3117
|
+
minLon: 0,
|
|
3118
|
+
minLat: 0,
|
|
3119
|
+
maxLon: 0,
|
|
3120
|
+
maxLat: 0
|
|
3121
|
+
};
|
|
2567
3122
|
return {
|
|
2568
3123
|
text: item.text,
|
|
2569
3124
|
extent: [e.minLon, e.minLat, e.maxLon, e.maxLat]
|
|
@@ -2649,56 +3204,69 @@ var __asyncGenerator = (__this, __arguments, generator) => {
|
|
|
2649
3204
|
};
|
|
2650
3205
|
class NominatimProvider extends BaseProvider {
|
|
2651
3206
|
constructor(options) {
|
|
2652
|
-
super(
|
|
3207
|
+
super();
|
|
3208
|
+
this.options = options;
|
|
2653
3209
|
__publicField(this, "searchUrl", "https://nominatim.openstreetmap.org");
|
|
2654
|
-
__publicField(this, "
|
|
3210
|
+
__publicField(this, "_abortControllers", []);
|
|
2655
3211
|
if (options && options.searchUrl) {
|
|
2656
3212
|
this.searchUrl = options.searchUrl;
|
|
2657
3213
|
}
|
|
2658
3214
|
}
|
|
2659
3215
|
abort() {
|
|
2660
|
-
this.
|
|
2661
|
-
|
|
3216
|
+
this._abortControllers.forEach((controller) => {
|
|
3217
|
+
controller.abort();
|
|
3218
|
+
});
|
|
3219
|
+
this._abortControllers = [];
|
|
2662
3220
|
}
|
|
2663
3221
|
search(val) {
|
|
2664
3222
|
return __asyncGenerator(this, null, function* () {
|
|
2665
|
-
|
|
2666
|
-
|
|
2667
|
-
|
|
2668
|
-
|
|
2669
|
-
|
|
2670
|
-
|
|
2671
|
-
xhr.open("GET", url, true);
|
|
2672
|
-
xhr.onload = () => {
|
|
2673
|
-
try {
|
|
2674
|
-
const geojson = JSON.parse(xhr.responseText);
|
|
2675
|
-
const features = geojson.features.map((x) => {
|
|
2676
|
-
return {
|
|
2677
|
-
geom: x,
|
|
2678
|
-
extent: x.bbox,
|
|
2679
|
-
text: x.properties && x.properties.display_name,
|
|
2680
|
-
query: val
|
|
2681
|
-
};
|
|
2682
|
-
});
|
|
2683
|
-
resolve(features);
|
|
2684
|
-
} catch (er) {
|
|
2685
|
-
reject(er);
|
|
2686
|
-
}
|
|
2687
|
-
};
|
|
2688
|
-
xhr.onerror = (er) => {
|
|
2689
|
-
reject(er);
|
|
2690
|
-
};
|
|
2691
|
-
this._abort.push(xhr.abort);
|
|
2692
|
-
xhr.send();
|
|
2693
|
-
}).catch((er) => {
|
|
2694
|
-
if (er.name === "CancelError") ;
|
|
2695
|
-
throw er;
|
|
3223
|
+
var _a, _b, _c, _d, _e, _f, _g;
|
|
3224
|
+
const params = new URLSearchParams({
|
|
3225
|
+
format: "geojson",
|
|
3226
|
+
polygon_geojson: "1",
|
|
3227
|
+
q: val,
|
|
3228
|
+
limit: ((_b = (_a = this.options) == null ? void 0 : _a.limit) == null ? void 0 : _b.toString()) || "10"
|
|
2696
3229
|
});
|
|
2697
|
-
|
|
2698
|
-
|
|
2699
|
-
|
|
2700
|
-
|
|
2701
|
-
|
|
3230
|
+
if ((_c = this.options) == null ? void 0 : _c.countrycodes) {
|
|
3231
|
+
params.append("countrycodes", this.options.countrycodes);
|
|
3232
|
+
}
|
|
3233
|
+
if ((_d = this.options) == null ? void 0 : _d.addressdetails) {
|
|
3234
|
+
params.append("addressdetails", "1");
|
|
3235
|
+
}
|
|
3236
|
+
if ((_e = this.options) == null ? void 0 : _e.language) {
|
|
3237
|
+
params.append("accept-language", this.options.language);
|
|
3238
|
+
}
|
|
3239
|
+
if ((_f = this.options) == null ? void 0 : _f.bounded) {
|
|
3240
|
+
params.append("bounded", "1");
|
|
3241
|
+
}
|
|
3242
|
+
if ((_g = this.options) == null ? void 0 : _g.viewbox) {
|
|
3243
|
+
const [minLon, minLat, maxLon, maxLat] = this.options.viewbox;
|
|
3244
|
+
params.append("viewbox", `${minLon},${minLat},${maxLon},${maxLat}`);
|
|
3245
|
+
}
|
|
3246
|
+
const url = fixUrlStr(`${this.searchUrl}/search?${params.toString()}`);
|
|
3247
|
+
const controller = new AbortController();
|
|
3248
|
+
this._abortControllers.push(controller);
|
|
3249
|
+
try {
|
|
3250
|
+
const response = yield new __await(fetch(url, { signal: controller.signal }));
|
|
3251
|
+
if (!response.ok) {
|
|
3252
|
+
throw new Error(`Network response was not ok: ${response.statusText}`);
|
|
3253
|
+
}
|
|
3254
|
+
const geojson = yield new __await(response.json());
|
|
3255
|
+
const features = geojson.features.map((x) => {
|
|
3256
|
+
return {
|
|
3257
|
+
geom: x,
|
|
3258
|
+
extent: x.bbox,
|
|
3259
|
+
text: x.properties && x.properties.display_name,
|
|
3260
|
+
query: val
|
|
3261
|
+
};
|
|
3262
|
+
});
|
|
3263
|
+
for (const item of features) {
|
|
3264
|
+
item.result = () => this.result(item);
|
|
3265
|
+
yield item;
|
|
3266
|
+
}
|
|
3267
|
+
} catch (error) {
|
|
3268
|
+
if (error.name === "AbortError") ; else {
|
|
3269
|
+
throw error;
|
|
2702
3270
|
}
|
|
2703
3271
|
}
|
|
2704
3272
|
});
|
|
@@ -2712,41 +3280,41 @@ class NominatimProvider extends BaseProvider {
|
|
|
2712
3280
|
}
|
|
2713
3281
|
reverse(coordinates) {
|
|
2714
3282
|
return __asyncGenerator(this, null, function* () {
|
|
3283
|
+
var _a, _b;
|
|
2715
3284
|
const [lng, lat] = coordinates;
|
|
2716
|
-
const
|
|
2717
|
-
|
|
2718
|
-
|
|
2719
|
-
|
|
2720
|
-
const xhr = new XMLHttpRequest();
|
|
2721
|
-
xhr.open("GET", url, true);
|
|
2722
|
-
xhr.onload = () => {
|
|
2723
|
-
try {
|
|
2724
|
-
const geojson = JSON.parse(xhr.responseText);
|
|
2725
|
-
const feature = geojson.features[0];
|
|
2726
|
-
const result = {
|
|
2727
|
-
geom: feature,
|
|
2728
|
-
extent: feature.bbox,
|
|
2729
|
-
text: feature.properties && feature.properties.display_name,
|
|
2730
|
-
query: `${lat}, ${lng}`
|
|
2731
|
-
};
|
|
2732
|
-
resolve(result);
|
|
2733
|
-
} catch (er) {
|
|
2734
|
-
reject(er);
|
|
2735
|
-
}
|
|
2736
|
-
};
|
|
2737
|
-
xhr.onerror = (er) => {
|
|
2738
|
-
reject(er);
|
|
2739
|
-
};
|
|
2740
|
-
this._abort.push(xhr.abort);
|
|
2741
|
-
xhr.send();
|
|
2742
|
-
}).catch((er) => {
|
|
2743
|
-
if (er.name === "CancelError") ;
|
|
2744
|
-
throw er;
|
|
3285
|
+
const params = new URLSearchParams({
|
|
3286
|
+
format: "geojson",
|
|
3287
|
+
lat: lat.toString(),
|
|
3288
|
+
lon: lng.toString()
|
|
2745
3289
|
});
|
|
2746
|
-
|
|
2747
|
-
|
|
3290
|
+
if ((_a = this.options) == null ? void 0 : _a.addressdetails) {
|
|
3291
|
+
params.append("addressdetails", "1");
|
|
3292
|
+
}
|
|
3293
|
+
if ((_b = this.options) == null ? void 0 : _b.language) {
|
|
3294
|
+
params.append("accept-language", this.options.language);
|
|
3295
|
+
}
|
|
3296
|
+
const url = fixUrlStr(`${this.searchUrl}/reverse?${params.toString()}`);
|
|
3297
|
+
const controller = new AbortController();
|
|
3298
|
+
this._abortControllers.push(controller);
|
|
3299
|
+
try {
|
|
3300
|
+
const response = yield new __await(fetch(url, { signal: controller.signal }));
|
|
3301
|
+
if (!response.ok) {
|
|
3302
|
+
throw new Error(`Network response was not ok: ${response.statusText}`);
|
|
3303
|
+
}
|
|
3304
|
+
const geojson = yield new __await(response.json());
|
|
3305
|
+
const feature = geojson.features[0];
|
|
3306
|
+
const item = {
|
|
3307
|
+
geom: feature,
|
|
3308
|
+
extent: feature.bbox,
|
|
3309
|
+
text: feature.properties && feature.properties.display_name,
|
|
3310
|
+
query: `${lat}, ${lng}`
|
|
3311
|
+
};
|
|
2748
3312
|
item.result = () => this.result(item);
|
|
2749
3313
|
yield item;
|
|
3314
|
+
} catch (error) {
|
|
3315
|
+
if (error.name === "AbortError") ; else {
|
|
3316
|
+
throw error;
|
|
3317
|
+
}
|
|
2750
3318
|
}
|
|
2751
3319
|
});
|
|
2752
3320
|
}
|