@nextgis/geocoder 1.18.19 → 1.19.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,4 +1,4 @@
1
- /** Bundle of @nextgis/geocoder; version: 1.18.19; author: NextGIS */
1
+ /** Bundle of @nextgis/geocoder; version: 1.19.0; author: NextGIS */
2
2
  class CancelError extends Error {
3
3
  constructor() {
4
4
  super();
@@ -1258,19 +1258,6 @@ Cache$1.instance = {};
1258
1258
  */
1259
1259
  var Cache = Cache$1;
1260
1260
 
1261
- /**
1262
- * Thrown when...
1263
- */
1264
- class NetworkError extends Error {
1265
- constructor(url) {
1266
- super();
1267
- this.name = 'NetworkError';
1268
- Object.setPrototypeOf(this, NetworkError.prototype);
1269
- this.message = `Unable to request ${url}.
1270
- Possibly invalid NGW URL entered or CORS not configured to get request from ${location.origin}`; // /control-panel/cors
1271
- }
1272
- }
1273
-
1274
1261
  /**
1275
1262
  * Thrown when...
1276
1263
  */
@@ -1283,193 +1270,6 @@ class NgwError extends Error {
1283
1270
  }
1284
1271
  }
1285
1272
 
1286
- function isObject(val) {
1287
- return Object.prototype.toString.call(val) === '[object Object]';
1288
- }
1289
-
1290
- let loadData;
1291
- // @ts-ignore
1292
- {
1293
- loadData = (url, callback, options = {}, error, onCancel) => {
1294
- options.method = options.method || 'GET';
1295
- const xhr = new XMLHttpRequest();
1296
- xhr.open(options.method || 'GET', url, true); // true for asynchronous
1297
- if (options.responseType === 'blob') {
1298
- xhr.responseType = options.responseType;
1299
- }
1300
- const getResponseText = () => {
1301
- try {
1302
- return JSON.parse(xhr.responseText);
1303
- }
1304
- catch (er) {
1305
- return xhr.responseText;
1306
- }
1307
- };
1308
- const processingResponse = (forError = false) => {
1309
- const cb = forError ? error : callback;
1310
- if (options.responseType === 'blob') {
1311
- cb(xhr.response);
1312
- }
1313
- else {
1314
- if (xhr.responseText) {
1315
- cb(getResponseText());
1316
- }
1317
- else {
1318
- error({ message: '' });
1319
- }
1320
- }
1321
- };
1322
- xhr.onload = () => {
1323
- if ([401, 403, 404, 422, 500].indexOf(xhr.status) !== -1) {
1324
- error(new NgwError(getResponseText()));
1325
- }
1326
- processingResponse();
1327
- };
1328
- // xhr.onreadystatechange = () => {
1329
- // if (
1330
- // (xhr.readyState === 4 && xhr.status === 200) ||
1331
- // (xhr.readyState === 3 && xhr.status === 201)
1332
- // ) {
1333
- // processingResponse();
1334
- // } else if (xhr.readyState === 3 && xhr.status === 400) {
1335
- // processingResponse();
1336
- // } else if (xhr.readyState === 4 && xhr.status === 500) {
1337
- // processingResponse();
1338
- // } else if (xhr.readyState === 4 && xhr.status === 401) {
1339
- // error(xhr.statusText);
1340
- // } else if (xhr.readyState === 4) {
1341
- // error('request error');
1342
- // }
1343
- // };
1344
- xhr.onerror = (er) => {
1345
- if (xhr.status === 0) {
1346
- error(new NetworkError(url));
1347
- }
1348
- else {
1349
- error(er);
1350
- }
1351
- };
1352
- xhr.upload.onprogress = function (e) {
1353
- if (e.lengthComputable) {
1354
- const percentComplete = (e.loaded / e.total) * 100;
1355
- if (options.onProgress) {
1356
- options.onProgress(percentComplete, e);
1357
- }
1358
- // console.log(percentComplete + '% uploaded');
1359
- }
1360
- };
1361
- const headers = options.headers;
1362
- if (headers) {
1363
- for (const h in headers) {
1364
- const header = headers[h];
1365
- if (typeof header === 'string') {
1366
- xhr.setRequestHeader(h, header);
1367
- }
1368
- }
1369
- }
1370
- if (options.withCredentials !== undefined) {
1371
- xhr.withCredentials = options.withCredentials;
1372
- }
1373
- let data;
1374
- if (options.file) {
1375
- data = new FormData();
1376
- data.append('file', options.file);
1377
- if (options.data) {
1378
- for (const d in options.data) {
1379
- data.append(d, data[d]);
1380
- }
1381
- }
1382
- }
1383
- else {
1384
- data = options.data
1385
- ? typeof options.data === 'string'
1386
- ? options.data
1387
- : JSON.stringify(options.data)
1388
- : null;
1389
- }
1390
- if (onCancel) {
1391
- onCancel(() => {
1392
- xhr.abort();
1393
- });
1394
- }
1395
- xhr.send(data);
1396
- };
1397
- }
1398
-
1399
- // https://github.com/Leaflet/Leaflet/blob/b507e21c510b53cd704fb8d3f89bb46ea925c8eb/src/core/Util.js#L165
1400
- const templateRe = /\{ *([\w_-]+) *\}/g;
1401
- function template(str, data) {
1402
- return str.replace(templateRe, (s, key) => {
1403
- let value = data[key];
1404
- if (value === undefined) {
1405
- throw new Error('No value provided for letiable ' + s);
1406
- }
1407
- else if (typeof value === 'function') {
1408
- value = value(data);
1409
- }
1410
- return value;
1411
- });
1412
- }
1413
-
1414
- function apiRequest(opt) {
1415
- const params = opt.params;
1416
- return new CancelablePromise((resolve, reject) => {
1417
- opt.connector
1418
- .connect()
1419
- .then((apiItems) => {
1420
- let apiItem = apiItems && apiItems[opt.name];
1421
- if (apiItem) {
1422
- apiItem = [...apiItem];
1423
- let url = apiItem.shift();
1424
- if (apiItem.length) {
1425
- const replaceParams = {};
1426
- for (let fry = 0; fry < apiItem.length; fry++) {
1427
- const arg = apiItem[fry];
1428
- replaceParams[fry] = '{' + arg + '}';
1429
- if (params[arg] === undefined) {
1430
- throw new Error('`' + arg + '`' + ' url api argument is not specified');
1431
- }
1432
- }
1433
- if (url) {
1434
- url = template(url, replaceParams);
1435
- }
1436
- }
1437
- // Transfer part of the parameters from `params` to the URL string
1438
- if (params) {
1439
- const paramArray = [];
1440
- const paramList = params.paramList;
1441
- if (Array.isArray(paramList)) {
1442
- delete params.paramList;
1443
- paramList.forEach((x) => {
1444
- paramArray.push(`${x[0]}=${x[1]}`);
1445
- });
1446
- }
1447
- for (const p in params) {
1448
- if (apiItem.indexOf(p) === -1) {
1449
- paramArray.push(`${p}=${params[p]}`);
1450
- }
1451
- }
1452
- if (paramArray.length) {
1453
- url = url + '?' + paramArray.join('&');
1454
- }
1455
- }
1456
- if (url) {
1457
- resolve(opt.connector.makeQuery(url, params, opt.requestOptions));
1458
- }
1459
- else {
1460
- reject(new Error('request url is not set'));
1461
- }
1462
- }
1463
- else {
1464
- resolve(undefined);
1465
- }
1466
- })
1467
- .catch((er) => {
1468
- reject(er);
1469
- });
1470
- });
1471
- }
1472
-
1473
1273
  /**
1474
1274
  * Thrown when ...
1475
1275
  */
@@ -1482,42 +1282,12 @@ class ResourceNotFoundError extends NgwError {
1482
1282
  }
1483
1283
  }
1484
1284
 
1485
- /**
1486
- * Thrown when ...
1487
- */
1488
- class InsufficientPermissionsError extends NgwError {
1489
- constructor(obj) {
1490
- super(obj);
1491
- this.name = 'InsufficientPermissionsError';
1492
- this.exception = 'nextgisweb.core.exception.InsufficientPermissions';
1493
- Object.setPrototypeOf(this, InsufficientPermissionsError.prototype);
1494
- }
1285
+ function isObject(val) {
1286
+ return Object.prototype.toString.call(val) === '[object Object]';
1495
1287
  }
1496
1288
 
1497
- const CONNECTORS = [];
1498
- function addConnector(connector) {
1499
- CONNECTORS.push(connector);
1500
- }
1501
- function findConnector(options) {
1502
- return CONNECTORS.find((x) => {
1503
- if (x.options.baseUrl === options.baseUrl) {
1504
- if (options.auth) {
1505
- if (x.options.auth) {
1506
- return objectDeepEqual(x.options.auth, options.auth);
1507
- }
1508
- }
1509
- else {
1510
- // if auth not in find options; use first connector with same url
1511
- return true;
1512
- }
1513
- }
1514
- });
1515
- }
1516
- function removeConnector(connector) {
1517
- const index = CONNECTORS.indexOf(connector);
1518
- if (index !== -1) {
1519
- CONNECTORS.splice(index, 1);
1520
- }
1289
+ function resourceCompare(res1, res2) {
1290
+ return objectDeepEqual(res1, res2);
1521
1291
  }
1522
1292
 
1523
1293
  const exclude = ['description'];
@@ -1553,10 +1323,6 @@ function resourceToQuery(resource, prefix = '') {
1553
1323
  return query;
1554
1324
  }
1555
1325
 
1556
- function resourceCompare(res1, res2) {
1557
- return objectDeepEqual(res1, res2);
1558
- }
1559
-
1560
1326
  class ResourcesControl {
1561
1327
  constructor(connector) {
1562
1328
  this.connector = connector;
@@ -1797,6 +1563,240 @@ class ResourcesControl {
1797
1563
  }
1798
1564
  }
1799
1565
 
1566
+ const CONNECTORS = [];
1567
+ function addConnector(connector) {
1568
+ CONNECTORS.push(connector);
1569
+ }
1570
+ function findConnector(options) {
1571
+ return CONNECTORS.find((x) => {
1572
+ if (x.options.baseUrl === options.baseUrl) {
1573
+ if (options.auth) {
1574
+ if (x.options.auth) {
1575
+ return objectDeepEqual(x.options.auth, options.auth);
1576
+ }
1577
+ }
1578
+ else {
1579
+ // if auth not in find options; use first connector with same url
1580
+ return true;
1581
+ }
1582
+ }
1583
+ });
1584
+ }
1585
+ function removeConnector(connector) {
1586
+ const index = CONNECTORS.indexOf(connector);
1587
+ if (index !== -1) {
1588
+ CONNECTORS.splice(index, 1);
1589
+ }
1590
+ }
1591
+
1592
+ /**
1593
+ * Thrown when ...
1594
+ */
1595
+ class InsufficientPermissionsError extends NgwError {
1596
+ constructor(obj) {
1597
+ super(obj);
1598
+ this.name = 'InsufficientPermissionsError';
1599
+ this.exception = 'nextgisweb.core.exception.InsufficientPermissions';
1600
+ Object.setPrototypeOf(this, InsufficientPermissionsError.prototype);
1601
+ }
1602
+ }
1603
+
1604
+ // https://github.com/Leaflet/Leaflet/blob/b507e21c510b53cd704fb8d3f89bb46ea925c8eb/src/core/Util.js#L165
1605
+ const templateRe = /\{ *([\w_-]+) *\}/g;
1606
+ function template(str, data) {
1607
+ return str.replace(templateRe, (s, key) => {
1608
+ let value = data[key];
1609
+ if (value === undefined) {
1610
+ throw new Error('No value provided for letiable ' + s);
1611
+ }
1612
+ else if (typeof value === 'function') {
1613
+ value = value(data);
1614
+ }
1615
+ return value;
1616
+ });
1617
+ }
1618
+
1619
+ function apiRequest(opt) {
1620
+ const params = opt.params;
1621
+ return new CancelablePromise((resolve, reject) => {
1622
+ opt.connector
1623
+ .connect()
1624
+ .then((apiItems) => {
1625
+ let apiItem = apiItems && apiItems[opt.name];
1626
+ if (apiItem) {
1627
+ apiItem = [...apiItem];
1628
+ let url = apiItem.shift();
1629
+ if (apiItem.length) {
1630
+ const replaceParams = {};
1631
+ for (let fry = 0; fry < apiItem.length; fry++) {
1632
+ const arg = apiItem[fry];
1633
+ replaceParams[fry] = '{' + arg + '}';
1634
+ if (params[arg] === undefined) {
1635
+ throw new Error('`' + arg + '`' + ' url api argument is not specified');
1636
+ }
1637
+ }
1638
+ if (url) {
1639
+ url = template(url, replaceParams);
1640
+ }
1641
+ }
1642
+ // Transfer part of the parameters from `params` to the URL string
1643
+ if (params) {
1644
+ const paramArray = [];
1645
+ const paramList = params.paramList;
1646
+ if (Array.isArray(paramList)) {
1647
+ delete params.paramList;
1648
+ paramList.forEach((x) => {
1649
+ paramArray.push(`${x[0]}=${x[1]}`);
1650
+ });
1651
+ }
1652
+ for (const p in params) {
1653
+ if (apiItem.indexOf(p) === -1) {
1654
+ paramArray.push(`${p}=${params[p]}`);
1655
+ }
1656
+ }
1657
+ if (paramArray.length) {
1658
+ url = url + '?' + paramArray.join('&');
1659
+ }
1660
+ }
1661
+ if (url) {
1662
+ resolve(opt.connector.makeQuery(url, params, opt.requestOptions));
1663
+ }
1664
+ else {
1665
+ reject(new Error('request url is not set'));
1666
+ }
1667
+ }
1668
+ else {
1669
+ resolve(undefined);
1670
+ }
1671
+ })
1672
+ .catch((er) => {
1673
+ reject(er);
1674
+ });
1675
+ });
1676
+ }
1677
+
1678
+ /**
1679
+ * Thrown when...
1680
+ */
1681
+ class NetworkError extends Error {
1682
+ constructor(url) {
1683
+ super();
1684
+ this.name = 'NetworkError';
1685
+ Object.setPrototypeOf(this, NetworkError.prototype);
1686
+ this.message = `Unable to request ${url}.
1687
+ Possibly invalid NGW URL entered or CORS not configured to get request from ${location.origin}`; // /control-panel/cors
1688
+ }
1689
+ }
1690
+
1691
+ let loadData;
1692
+ // @ts-ignore
1693
+ {
1694
+ loadData = (url, callback, options = {}, error, onCancel) => {
1695
+ options.method = options.method || 'GET';
1696
+ const xhr = new XMLHttpRequest();
1697
+ xhr.open(options.method || 'GET', url, true); // true for asynchronous
1698
+ if (options.responseType === 'blob') {
1699
+ xhr.responseType = options.responseType;
1700
+ }
1701
+ const getResponseText = () => {
1702
+ try {
1703
+ return JSON.parse(xhr.responseText);
1704
+ }
1705
+ catch (er) {
1706
+ return xhr.responseText;
1707
+ }
1708
+ };
1709
+ const processingResponse = (forError = false) => {
1710
+ const cb = forError ? error : callback;
1711
+ if (options.responseType === 'blob') {
1712
+ cb(xhr.response);
1713
+ }
1714
+ else {
1715
+ if (xhr.responseText) {
1716
+ cb(getResponseText());
1717
+ }
1718
+ else {
1719
+ error({ message: '' });
1720
+ }
1721
+ }
1722
+ };
1723
+ xhr.onload = () => {
1724
+ if ([401, 403, 404, 422, 500].indexOf(xhr.status) !== -1) {
1725
+ error(new NgwError(getResponseText()));
1726
+ }
1727
+ processingResponse();
1728
+ };
1729
+ // xhr.onreadystatechange = () => {
1730
+ // if (
1731
+ // (xhr.readyState === 4 && xhr.status === 200) ||
1732
+ // (xhr.readyState === 3 && xhr.status === 201)
1733
+ // ) {
1734
+ // processingResponse();
1735
+ // } else if (xhr.readyState === 3 && xhr.status === 400) {
1736
+ // processingResponse();
1737
+ // } else if (xhr.readyState === 4 && xhr.status === 500) {
1738
+ // processingResponse();
1739
+ // } else if (xhr.readyState === 4 && xhr.status === 401) {
1740
+ // error(xhr.statusText);
1741
+ // } else if (xhr.readyState === 4) {
1742
+ // error('request error');
1743
+ // }
1744
+ // };
1745
+ xhr.onerror = (er) => {
1746
+ if (xhr.status === 0) {
1747
+ error(new NetworkError(url));
1748
+ }
1749
+ else {
1750
+ error(er);
1751
+ }
1752
+ };
1753
+ xhr.upload.onprogress = function (e) {
1754
+ if (e.lengthComputable) {
1755
+ const percentComplete = (e.loaded / e.total) * 100;
1756
+ if (options.onProgress) {
1757
+ options.onProgress(percentComplete, e);
1758
+ }
1759
+ // console.log(percentComplete + '% uploaded');
1760
+ }
1761
+ };
1762
+ const headers = options.headers;
1763
+ if (headers) {
1764
+ for (const h in headers) {
1765
+ const header = headers[h];
1766
+ if (typeof header === 'string') {
1767
+ xhr.setRequestHeader(h, header);
1768
+ }
1769
+ }
1770
+ }
1771
+ if (options.withCredentials !== undefined) {
1772
+ xhr.withCredentials = options.withCredentials;
1773
+ }
1774
+ let data;
1775
+ if (options.file) {
1776
+ data = new FormData();
1777
+ data.append('file', options.file);
1778
+ if (options.data) {
1779
+ for (const d in options.data) {
1780
+ data.append(d, data[d]);
1781
+ }
1782
+ }
1783
+ }
1784
+ else {
1785
+ data = options.data
1786
+ ? typeof options.data === 'string'
1787
+ ? options.data
1788
+ : JSON.stringify(options.data)
1789
+ : null;
1790
+ }
1791
+ if (onCancel) {
1792
+ onCancel(() => {
1793
+ xhr.abort();
1794
+ });
1795
+ }
1796
+ xhr.send(data);
1797
+ };
1798
+ }
1799
+
1800
1800
  let ID = 0;
1801
1801
  class NgwConnector$1 {
1802
1802
  constructor(options) {
@@ -2334,7 +2334,7 @@ const FEATURE_REQUEST_PARAMS = {
2334
2334
  function updateItemRequestParam(params, options) {
2335
2335
  const { extensions, geom, fields, srs, ilike, like } = options;
2336
2336
  // Empty extesions by default
2337
- let extensionsStr = extensions ? extensions.join(',') : '';
2337
+ const extensionsStr = extensions ? extensions.join(',') : '';
2338
2338
  // Use character * to set all extensions
2339
2339
  if (extensionsStr !== '*') {
2340
2340
  params.extensions = extensionsStr;