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