@nextgis/geocoder 3.0.0-alpha.1 → 3.0.0-alpha.12

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: 3.0.0-alpha.1; author: NextGIS */
1
+ /** Bundle of @nextgis/geocoder; version: 3.0.0-alpha.9; author: NextGIS */
2
2
  var Geocoder = (function (exports) {
3
3
  'use strict';
4
4
 
@@ -107,28 +107,28 @@ var Geocoder = (function (exports) {
107
107
  }
108
108
  }
109
109
 
110
- var __defProp$d = Object.defineProperty;
111
- var __defProps$3 = Object.defineProperties;
112
- var __getOwnPropDescs$3 = Object.getOwnPropertyDescriptors;
113
- var __getOwnPropSymbols$6 = Object.getOwnPropertySymbols;
114
- var __hasOwnProp$6 = Object.prototype.hasOwnProperty;
115
- var __propIsEnum$6 = Object.prototype.propertyIsEnumerable;
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$d = (obj, key, value) => key in obj ? __defProp$d(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
118
- var __spreadValues$6 = (a, b) => {
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$6.call(b, prop))
121
- __defNormalProp$d(a, prop, b[prop]);
122
- if (__getOwnPropSymbols$6)
123
- for (var prop of __getOwnPropSymbols$6(b)) {
124
- if (__propIsEnum$6.call(b, prop))
125
- __defNormalProp$d(a, prop, b[prop]);
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$3 = (a, b) => __defProps$3(a, __getOwnPropDescs$3(b));
130
- var __publicField$a = (obj, key, value) => __defNormalProp$d(obj, key + "" , value);
131
- var __async$5 = (__this, __arguments, generator) => {
129
+ var __spreadProps$5 = (a, b) => __defProps$5(a, __getOwnPropDescs$5(b));
130
+ var __publicField$d = (obj, key, value) => __defNormalProp$i(obj, 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$a(this, "providers", []);
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$3(__spreadValues$6({}, r), { provider, _id: ID$1++ });
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 !== "CancelError") {
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$3(__spreadValues$6({}, r), { provider, _id: ID$1++ });
238
+ yield __spreadProps$5(__spreadValues$8({}, r), { provider, _id: ID$1++ });
239
239
  }
240
240
  } catch (temp) {
241
241
  error = [temp];
@@ -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$5(this, null, function* () {
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$c = Object.defineProperty;
292
- var __defNormalProp$c = (obj, key, value) => key in obj ? __defProp$c(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
293
- var __publicField$9 = (obj, key, value) => __defNormalProp$c(obj, typeof key !== "symbol" ? key + "" : key, value);
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,12 +298,12 @@ 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$9(this, "searchUrl");
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$9(this, "label");
306
+ __publicField$c(this, "label");
307
307
  }
308
308
  }
309
309
 
@@ -337,7 +337,7 @@ var Geocoder = (function (exports) {
337
337
  this.domain = null;
338
338
  if (EventEmitter.usingDomains) {
339
339
  // if there is an active domain, then attach to it.
340
- if (domain.active ) ;
340
+ if (domain.active) ;
341
341
  }
342
342
 
343
343
  if (!this._events || this._events === Object.getPrototypeOf(this)._events) {
@@ -779,12 +779,12 @@ var Geocoder = (function (exports) {
779
779
  return ret;
780
780
  }
781
781
 
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);
782
+ var __defProp$g = Object.defineProperty;
783
+ var __defNormalProp$g = (obj, key, value) => key in obj ? __defProp$g(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
784
+ var __publicField$b = (obj, key, value) => __defNormalProp$g(obj, typeof key !== "symbol" ? key + "" : key, value);
785
785
  const _Cache = class _Cache {
786
786
  constructor(options = {}) {
787
- __publicField$8(this, "cache", []);
787
+ __publicField$b(this, "cache", []);
788
788
  var _a;
789
789
  const namespace = (_a = options.namespace) != null ? _a : "default";
790
790
  if (_Cache.instance[namespace]) {
@@ -820,10 +820,23 @@ var Geocoder = (function (exports) {
820
820
  * });
821
821
  * ```
822
822
  */
823
- addFull(key, valueToSet, props) {
824
- return this.add(key, valueToSet, props, true);
825
- }
826
- add(key, valueToSet, props, onlyFull) {
823
+ addFull(key, valueToSet, propsOrOptions, expirationTime) {
824
+ if (typeof propsOrOptions === "object" && "valueToSet" in propsOrOptions) {
825
+ propsOrOptions.onlyFull = true;
826
+ }
827
+ return this.add(key, valueToSet, propsOrOptions, true, expirationTime);
828
+ }
829
+ add(key, valueToSet, propsOrOptions, onlyFull, expirationTime) {
830
+ let opt;
831
+ let props;
832
+ if (typeof propsOrOptions === "object" && "valueToSet" in propsOrOptions) {
833
+ opt = propsOrOptions;
834
+ onlyFull = opt.onlyFull;
835
+ expirationTime = opt.expirationTime;
836
+ props = opt.props;
837
+ } else {
838
+ props = propsOrOptions;
839
+ }
827
840
  const exist = this._find(key, props);
828
841
  if (!exist) {
829
842
  let value;
@@ -833,10 +846,12 @@ var Geocoder = (function (exports) {
833
846
  value = valueToSet;
834
847
  }
835
848
  const nonEmptyProps = props && JSON.parse(JSON.stringify(objectRemoveEmpty(props)));
849
+ expirationTime = expirationTime ? Date.now() + expirationTime : void 0;
836
850
  const cacheItem = {
837
851
  key,
838
852
  value,
839
- props: nonEmptyProps
853
+ props: nonEmptyProps,
854
+ expirationTime
840
855
  };
841
856
  if (onlyFull && !full(value)) {
842
857
  return value;
@@ -863,9 +878,19 @@ var Geocoder = (function (exports) {
863
878
  }
864
879
  match(key, props) {
865
880
  const cacheRecord = this._find(key, props);
881
+ if (cacheRecord && cacheRecord.expirationTime && Date.now() > cacheRecord.expirationTime) {
882
+ this.delete(cacheRecord);
883
+ return void 0;
884
+ }
866
885
  return cacheRecord == null ? void 0 : cacheRecord.value;
867
886
  }
868
887
  matchAll(key, props) {
888
+ const now = Date.now();
889
+ this.cache.forEach((item) => {
890
+ if (item.expirationTime && now > item.expirationTime) {
891
+ this.delete(item);
892
+ }
893
+ });
869
894
  if (key) {
870
895
  return this.cache.filter((x) => this._filter(x, key, props)).map((x) => x.value);
871
896
  }
@@ -890,31 +915,159 @@ var Geocoder = (function (exports) {
890
915
  return objectDeepEqual(itemProps || {}, objectRemoveEmpty(props));
891
916
  }
892
917
  };
893
- __publicField$8(_Cache, "instance", {});
918
+ __publicField$b(_Cache, "instance", {});
894
919
  let Cache = _Cache;
895
920
 
896
- var __defProp$a = Object.defineProperty;
897
- var __defNormalProp$a = (obj, key, value) => key in obj ? __defProp$a(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
898
- var __publicField$7 = (obj, key, value) => __defNormalProp$a(obj, typeof key !== "symbol" ? key + "" : key, value);
921
+ var pkg = {
922
+ name: "@nextgis/ngw-connector",
923
+ version: "3.0.0-alpha.8",
924
+ _priority: 12,
925
+ description: "A lightweight HTTP client optimized for use with NextGIS Web API",
926
+ main: "index.js",
927
+ module: "lib/ngw-connector.esm-bundler.js",
928
+ unpkg: "lib/ngw-connector.global.prod.js",
929
+ jsdelivr: "lib/ngw-connector.global.prod.js",
930
+ types: "lib/index.d.ts",
931
+ dependencies: {
932
+ "@nextgis/cache": "^3.0.0-alpha.7",
933
+ "@nextgis/cancelable-promise": "^3.0.0-alpha.5",
934
+ "@nextgis/utils": "^3.0.0-alpha.5",
935
+ "@types/events": "^3.0.0",
936
+ events: "*",
937
+ "form-data": "^4.0.0"
938
+ },
939
+ devDependencies: {
940
+ "@nextgis/build-tools": "^3.0.0-alpha.5"
941
+ },
942
+ scripts: {
943
+ clean: "rimraf ./lib",
944
+ dev: "node ../build-tools/lib/build.js",
945
+ prod: "npm run dev -- --release",
946
+ lint: "eslint ./src/**/*.ts --fix --c ../../.eslintrc",
947
+ watch: "npm run dev -- --watch",
948
+ "gen:types": "node ./scripts/generator"
949
+ },
950
+ buildOptions: {
951
+ name: "NgwConnector",
952
+ formats: [
953
+ "esm-bundler",
954
+ "esm-browser",
955
+ "cjs",
956
+ "global"
957
+ ]
958
+ },
959
+ keywords: [
960
+ "NextGIS",
961
+ "MAP"
962
+ ],
963
+ author: "NextGIS",
964
+ files: [
965
+ "index.js",
966
+ "lib"
967
+ ],
968
+ license: "MIT",
969
+ homepage: "https://github.com/nextgis/nextgis_frontend/tree/master/packages/ngw-connector#readme",
970
+ repository: {
971
+ type: "git",
972
+ url: "git://github.com/nextgis/nextgis_frontend.git"
973
+ },
974
+ engines: {
975
+ node: ">=18.20.4"
976
+ },
977
+ gitHead: "edc68033f914f6c95c4125b9738bba6d36e990b4"
978
+ };
979
+
980
+ const CONNECTORS = [];
981
+ function addConnector(connector) {
982
+ CONNECTORS.push(connector);
983
+ }
984
+ function findConnector(options) {
985
+ return CONNECTORS.find((x) => {
986
+ if (x.options.baseUrl === options.baseUrl) {
987
+ if (options.auth) {
988
+ if (x.options.auth) {
989
+ return objectDeepEqual(x.options.auth, options.auth);
990
+ }
991
+ } else {
992
+ return true;
993
+ }
994
+ }
995
+ });
996
+ }
997
+ function removeConnector(connector) {
998
+ const index = CONNECTORS.indexOf(connector);
999
+ if (index !== -1) {
1000
+ CONNECTORS.splice(index, 1);
1001
+ }
1002
+ }
1003
+
1004
+ class AbortError extends Error {
1005
+ constructor(message = "AbortError") {
1006
+ super(message);
1007
+ this.name = "AbortError";
1008
+ }
1009
+ }
1010
+
1011
+ var __defProp$f = Object.defineProperty;
1012
+ var __defNormalProp$f = (obj, key, value) => key in obj ? __defProp$f(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
1013
+ var __publicField$a = (obj, key, value) => __defNormalProp$f(obj, typeof key !== "symbol" ? key + "" : key, value);
899
1014
  class NgwError extends Error {
900
1015
  constructor(er) {
901
1016
  super();
902
- __publicField$7(this, "name", "NgwError");
903
- __publicField$7(this, "title");
904
- __publicField$7(this, "message");
905
- __publicField$7(this, "detail");
906
- __publicField$7(this, "exception");
907
- __publicField$7(this, "status_code");
908
- __publicField$7(this, "data");
909
- __publicField$7(this, "guru_meditation");
1017
+ __publicField$a(this, "name", "NgwError");
1018
+ __publicField$a(this, "title");
1019
+ __publicField$a(this, "message");
1020
+ __publicField$a(this, "detail");
1021
+ __publicField$a(this, "exception");
1022
+ __publicField$a(this, "status_code");
1023
+ __publicField$a(this, "data");
1024
+ __publicField$a(this, "guru_meditation");
910
1025
  Object.assign(this, er);
911
1026
  Object.setPrototypeOf(this, NgwError.prototype);
912
1027
  }
913
1028
  }
914
1029
 
915
- var __defProp$9 = Object.defineProperty;
916
- var __defNormalProp$9 = (obj, key, value) => key in obj ? __defProp$9(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
917
- var __publicField$6 = (obj, key, value) => __defNormalProp$9(obj, typeof key !== "symbol" ? key + "" : key, value);
1030
+ var __defProp$e = Object.defineProperty;
1031
+ var __defNormalProp$e = (obj, key, value) => key in obj ? __defProp$e(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
1032
+ var __publicField$9 = (obj, key, value) => __defNormalProp$e(obj, typeof key !== "symbol" ? key + "" : key, value);
1033
+ class InsufficientPermissionsError extends NgwError {
1034
+ constructor(obj) {
1035
+ super(obj);
1036
+ __publicField$9(this, "name", "InsufficientPermissionsError");
1037
+ __publicField$9(this, "exception", "nextgisweb.core.exception.InsufficientPermissions");
1038
+ Object.setPrototypeOf(this, InsufficientPermissionsError.prototype);
1039
+ }
1040
+ }
1041
+
1042
+ var __defProp$d = Object.defineProperty;
1043
+ var __defNormalProp$d = (obj, key, value) => key in obj ? __defProp$d(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
1044
+ var __publicField$8 = (obj, key, value) => __defNormalProp$d(obj, key + "" , value);
1045
+ class NetworkError extends Error {
1046
+ constructor(url) {
1047
+ super();
1048
+ __publicField$8(this, "name", "NetworkError");
1049
+ Object.setPrototypeOf(this, NetworkError.prototype);
1050
+ this.message = `Unable to request ${url}.
1051
+ Possibly invalid NGW URL entered or CORS not configured to get request from ${location.origin}`;
1052
+ }
1053
+ }
1054
+
1055
+ var __defProp$c = Object.defineProperty;
1056
+ var __defNormalProp$c = (obj, key, value) => key in obj ? __defProp$c(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
1057
+ var __publicField$7 = (obj, key, value) => __defNormalProp$c(obj, typeof key !== "symbol" ? key + "" : key, value);
1058
+ let NetworksResponseError$1 = class NetworksResponseError extends NgwError {
1059
+ constructor(obj) {
1060
+ super(obj);
1061
+ __publicField$7(this, "message", "There is no response from the server or problem connecting to server.");
1062
+ __publicField$7(this, "title", "Network error");
1063
+ __publicField$7(this, "detail", "Check network connectivity and try again later.");
1064
+ Object.setPrototypeOf(this, NetworksResponseError.prototype);
1065
+ }
1066
+ };
1067
+
1068
+ var __defProp$b = Object.defineProperty;
1069
+ var __defNormalProp$b = (obj, key, value) => key in obj ? __defProp$b(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
1070
+ var __publicField$6 = (obj, key, value) => __defNormalProp$b(obj, typeof key !== "symbol" ? key + "" : key, value);
918
1071
  class ResourceNotFoundError extends NgwError {
919
1072
  constructor(obj) {
920
1073
  super(obj);
@@ -924,53 +1077,143 @@ var Geocoder = (function (exports) {
924
1077
  }
925
1078
  }
926
1079
 
927
- function isObject(val) {
928
- return Object.prototype.toString.call(val) === "[object Object]";
1080
+ function isError(error) {
1081
+ if (isObject$1(error)) {
1082
+ return error.status_code && error.exception && error.title;
1083
+ }
1084
+ return false;
929
1085
  }
930
1086
 
931
- function resourceCompare(res1, res2) {
932
- return objectDeepEqual(res1, res2);
1087
+ function extractError(error) {
1088
+ if (isObject$1(error)) {
1089
+ if (error.name && error.message && error.title) {
1090
+ return {
1091
+ title: error.title,
1092
+ message: error.message,
1093
+ detail: error.detail || null,
1094
+ data: error.data && error.data.data ? error.data.data : null
1095
+ };
1096
+ } else if (error.exception) {
1097
+ if (error.status === void 0 || error.status === 0 || error.data === void 0) {
1098
+ return new NetworksResponseError$1({
1099
+ title: error.title,
1100
+ status_code: error.status_code,
1101
+ exception: error.exception
1102
+ });
1103
+ }
1104
+ }
1105
+ return {
1106
+ title: typeof error.title === "string" ? error.title : "Unexpected error",
1107
+ message: typeof error.message === "string" ? error.message : "Something went wrong."
1108
+ };
1109
+ }
933
1110
  }
934
1111
 
935
- const exclude = ["description"];
936
- function resourceToQuery(resource, prefix = "") {
937
- prefix = prefix ? prefix + "__" : "";
938
- const query = {};
939
- for (const [key, value] of Object.entries(resource)) {
940
- if (exclude.indexOf(key) === -1) {
941
- if (isObject(value)) {
942
- if (key === "owner_user") {
943
- const children = resourceToQuery(value, key);
944
- Object.assign(query, children);
945
- } else if (key === "parent" && "id" in value) {
946
- query.parent_id = value.id;
947
- }
948
- } else if (defined(value)) {
949
- query[prefix + key] = value;
950
- }
1112
+ var errors = /*#__PURE__*/Object.freeze({
1113
+ __proto__: null,
1114
+ AbortError: AbortError,
1115
+ InsufficientPermissionsError: InsufficientPermissionsError,
1116
+ NetworkError: NetworkError,
1117
+ NetworksResponseError: NetworksResponseError$1,
1118
+ NgwError: NgwError,
1119
+ ResourceNotFoundError: ResourceNotFoundError,
1120
+ extractError: extractError,
1121
+ isError: isError
1122
+ });
1123
+
1124
+ var __defProp$a = Object.defineProperty;
1125
+ var __defNormalProp$a = (obj, key, value) => key in obj ? __defProp$a(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
1126
+ var __publicField$5 = (obj, key, value) => __defNormalProp$a(obj, typeof key !== "symbol" ? key + "" : key, value);
1127
+ class BaseAPIError extends Error {
1128
+ constructor(message) {
1129
+ super(message || "Something went wrong.");
1130
+ __publicField$5(this, "title");
1131
+ this.name = "BaseAPIError";
1132
+ this.title = "Unknown API error";
1133
+ if (Error.captureStackTrace) {
1134
+ Error.captureStackTrace(this, BaseAPIError);
951
1135
  }
952
1136
  }
953
- return query;
1137
+ }
1138
+ class NetworksResponseError extends BaseAPIError {
1139
+ // prettier-ignore
1140
+ constructor(message) {
1141
+ super(message || "There is no response from the server or problem connecting to server.");
1142
+ __publicField$5(this, "detail");
1143
+ this.title = "Network error";
1144
+ this.detail = "Check network connectivity and try again later.";
1145
+ }
1146
+ }
1147
+ class InvalidResponseError extends BaseAPIError {
1148
+ constructor(message) {
1149
+ super(message || "Something went wrong.");
1150
+ this.title = "Unexpected server response";
1151
+ }
1152
+ }
1153
+ class ServerResponseError extends BaseAPIError {
1154
+ constructor(data) {
1155
+ super(data.message);
1156
+ __publicField$5(this, "detail");
1157
+ __publicField$5(this, "data");
1158
+ this.title = data.title || this.title;
1159
+ this.detail = data.detail || null;
1160
+ this.data = data;
1161
+ }
1162
+ }
1163
+ class LunkwillError extends Error {
1164
+ // prettier-ignore
1165
+ constructor(message, data = {}) {
1166
+ super(message || "Unexpected error while processing long-running request.");
1167
+ __publicField$5(this, "title");
1168
+ __publicField$5(this, "data");
1169
+ this.name = "LunkwillError";
1170
+ this.title = "Long-running request error";
1171
+ this.data = data;
1172
+ if (Error.captureStackTrace) {
1173
+ Error.captureStackTrace(this, LunkwillError);
1174
+ }
1175
+ }
1176
+ }
1177
+ class LunkwillRequestCancelled extends LunkwillError {
1178
+ constructor(data) {
1179
+ super("Long-running request was cancelled.", data);
1180
+ }
1181
+ }
1182
+ class LunkwillRequestFailed extends LunkwillError {
1183
+ constructor(data) {
1184
+ super(void 0, data);
1185
+ }
954
1186
  }
955
1187
 
956
- var __defProp$8 = Object.defineProperty;
957
- var __getOwnPropSymbols$5 = Object.getOwnPropertySymbols;
958
- var __hasOwnProp$5 = Object.prototype.hasOwnProperty;
959
- var __propIsEnum$5 = Object.prototype.propertyIsEnumerable;
960
- var __defNormalProp$8 = (obj, key, value) => key in obj ? __defProp$8(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
961
- var __spreadValues$5 = (a, b) => {
1188
+ var __defProp$9 = Object.defineProperty;
1189
+ var __getOwnPropSymbols$7 = Object.getOwnPropertySymbols;
1190
+ var __hasOwnProp$7 = Object.prototype.hasOwnProperty;
1191
+ var __propIsEnum$7 = Object.prototype.propertyIsEnumerable;
1192
+ var __defNormalProp$9 = (obj, key, value) => key in obj ? __defProp$9(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
1193
+ var __spreadValues$7 = (a, b) => {
962
1194
  for (var prop in b || (b = {}))
963
- if (__hasOwnProp$5.call(b, prop))
964
- __defNormalProp$8(a, prop, b[prop]);
965
- if (__getOwnPropSymbols$5)
966
- for (var prop of __getOwnPropSymbols$5(b)) {
967
- if (__propIsEnum$5.call(b, prop))
968
- __defNormalProp$8(a, prop, b[prop]);
1195
+ if (__hasOwnProp$7.call(b, prop))
1196
+ __defNormalProp$9(a, prop, b[prop]);
1197
+ if (__getOwnPropSymbols$7)
1198
+ for (var prop of __getOwnPropSymbols$7(b)) {
1199
+ if (__propIsEnum$7.call(b, prop))
1200
+ __defNormalProp$9(a, prop, b[prop]);
969
1201
  }
970
1202
  return a;
971
1203
  };
972
- var __publicField$5 = (obj, key, value) => __defNormalProp$8(obj, typeof key !== "symbol" ? key + "" : key, value);
973
- var __async$4 = (__this, __arguments, generator) => {
1204
+ var __objRest$2 = (source, exclude) => {
1205
+ var target = {};
1206
+ for (var prop in source)
1207
+ if (__hasOwnProp$7.call(source, prop) && exclude.indexOf(prop) < 0)
1208
+ target[prop] = source[prop];
1209
+ if (source != null && __getOwnPropSymbols$7)
1210
+ for (var prop of __getOwnPropSymbols$7(source)) {
1211
+ if (exclude.indexOf(prop) < 0 && __propIsEnum$7.call(source, prop))
1212
+ target[prop] = source[prop];
1213
+ }
1214
+ return target;
1215
+ };
1216
+ var __async$6 = (__this, __arguments, generator) => {
974
1217
  return new Promise((resolve, reject) => {
975
1218
  var fulfilled = (value) => {
976
1219
  try {
@@ -990,94 +1233,935 @@ var Geocoder = (function (exports) {
990
1233
  step((generator = generator.apply(__this, __arguments)).next());
991
1234
  });
992
1235
  };
993
- class ResourcesControl {
994
- constructor({
995
- connector,
996
- cacheId
997
- }) {
998
- __publicField$5(this, "cache");
999
- __publicField$5(this, "connector");
1000
- this.connector = connector;
1001
- this.cache = new Cache({ namespace: cacheId });
1002
- }
1003
- // -------------------------------------------------------------------------
1004
- // Resource Methods
1005
- // -------------------------------------------------------------------------
1006
- /**
1007
- * Receive resource from NGW by id, keyname or search-object parameter.
1008
- * @param resource - Resource id, keyname or search-object
1009
- *
1010
- * @remarks
1011
- * Fetching resource would be cached to speed up next call
1012
- */
1013
- getOne(resource, requestOptions) {
1014
- const opt = __spreadValues$5({}, requestOptions);
1015
- if (typeof resource === "string") ; else if (typeof resource === "number") ; else if (isObject(resource)) {
1016
- if (resource.id !== void 0) {
1017
- resource.id;
1018
- } else {
1019
- if (resource.keyname) {
1020
- resource.keyname;
1021
- }
1022
- if (resource.display_name) {
1023
- resource.display_name;
1024
- }
1236
+ function lunkwillCheckResponse(lwResp) {
1237
+ const ct = lwResp.headers.get("content-type");
1238
+ return ct !== void 0 && ct !== null && ct.includes("application/vnd.lunkwill.request-summary+json");
1239
+ }
1240
+ function responseJson(response) {
1241
+ return __async$6(this, null, function* () {
1242
+ try {
1243
+ return response.json();
1244
+ } catch (e) {
1245
+ throw new Error();
1246
+ }
1247
+ });
1248
+ }
1249
+ function lunkwillResponseUrl(lwResp) {
1250
+ return __async$6(this, null, function* () {
1251
+ const lwData = yield responseJson(lwResp);
1252
+ let delay = lwData.delay_ms;
1253
+ const retry = lwData.retry_ms !== void 0 ? lwData.retry_ms : 2e3;
1254
+ const sum = `/api/lunkwill/${lwData.id}/summary`;
1255
+ const res = `/api/lunkwill/${lwData.id}/response`;
1256
+ const sleep = (msec) => new Promise((resolve) => setTimeout(resolve, msec));
1257
+ let failed = false;
1258
+ let ready = false;
1259
+ while (!ready) {
1260
+ yield sleep(failed ? retry : delay);
1261
+ failed = false;
1262
+ let lwResp2;
1263
+ let lwData2;
1264
+ try {
1265
+ lwResp2 = yield fetch(sum, { credentials: "same-origin" });
1266
+ lwData2 = yield lwResp2.json();
1267
+ } catch (e) {
1268
+ failed = true;
1269
+ continue;
1270
+ }
1271
+ switch (lwData2.status) {
1272
+ case void 0:
1273
+ throw new LunkwillError(void 0, lwData2);
1274
+ case "ready":
1275
+ ready = true;
1276
+ break;
1277
+ case "cancelled":
1278
+ throw new LunkwillRequestCancelled(lwData2);
1279
+ case "failed":
1280
+ throw new LunkwillRequestFailed(lwData2);
1281
+ case "spooled":
1282
+ case "processing":
1283
+ case "buffering":
1284
+ delay = lwData2.delay_ms;
1285
+ break;
1286
+ default:
1287
+ throw new LunkwillError(void 0, lwData2);
1025
1288
  }
1026
1289
  }
1027
- if (typeof resource === "string") {
1028
- return this._fetchResourceBy({ keyname: resource }, opt);
1029
- } else if (typeof resource === "number") {
1030
- return this._fetchResourceById(resource, opt);
1031
- } else if (isObject(resource)) {
1032
- return this._fetchResourceBy(resource, opt);
1290
+ return res;
1291
+ });
1292
+ }
1293
+ function lunkwillFetch(lwRespUrl) {
1294
+ return __async$6(this, null, function* () {
1295
+ try {
1296
+ return yield window.fetch(lwRespUrl, { credentials: "same-origin" });
1297
+ } catch (e) {
1298
+ throw new NetworksResponseError();
1033
1299
  }
1034
- return Promise.resolve(void 0);
1035
- }
1036
- getOneOrFail(resource, requestOptions) {
1037
- return this.getOne(resource, requestOptions).then((res) => {
1038
- if (res) {
1039
- return res;
1040
- }
1041
- throw new ResourceNotFoundError();
1042
- });
1043
- }
1044
- /**
1045
- * A fast way to retrieve resource ID for any resource definition.
1046
- * @param resource - Any available resource definition
1047
- *
1048
- * @remarks
1049
- * There are situations when exactly the resource id is needed
1050
- * (for example, to compose the correct request to the api)
1051
- * then this method will come in handy to facilitate the extraction of the identifier
1052
- * if the resource is specified through a keyname or other parameters.
1053
- */
1054
- getId(resource, requestOptions) {
1055
- if (typeof resource === "number") {
1056
- return Promise.resolve(resource);
1057
- } else if (typeof resource === "string" || isObject(resource)) {
1058
- return this.getOne(resource, requestOptions).then((res) => {
1059
- if (res) {
1060
- return res.resource.id;
1300
+ });
1301
+ }
1302
+ const mediaContentTypes = [
1303
+ "application/pdf",
1304
+ "image/png",
1305
+ "image/jpeg",
1306
+ "image/tiff",
1307
+ "text/csv"
1308
+ ];
1309
+ const mediaContentTypesRegex = new RegExp(mediaContentTypes.join("|"));
1310
+ function isMediaContentType(contentType) {
1311
+ return mediaContentTypesRegex.test(contentType);
1312
+ }
1313
+ function encodeQueryParams(value) {
1314
+ const result = [];
1315
+ for (const [k, v] of Object.entries(value)) {
1316
+ if (typeof v === "string" || typeof v === "number" || typeof v === "boolean") {
1317
+ result.push(`${k}=${encodeURIComponent(v)}`);
1318
+ } else if (Array.isArray(v)) {
1319
+ result.push(`${k}=${v.map(encodeURIComponent).join(",")}`);
1320
+ } else {
1321
+ for (const [sk, sv] of Object.entries(v)) {
1322
+ const ske = `${k}[${encodeURIComponent(sk)}]`;
1323
+ if (typeof sv === "string" || typeof sv === "number" || typeof sv === "boolean") {
1324
+ result.push(`${ske}=${encodeURIComponent(sv)}`);
1325
+ } else if (Array.isArray(sv)) {
1326
+ const sve = sv.map(encodeURIComponent);
1327
+ result.push(`${ske}=${sve.join(",")}`);
1061
1328
  }
1062
- });
1329
+ }
1063
1330
  }
1064
- return Promise.resolve(void 0);
1065
1331
  }
1066
- /**
1067
- * A fast way to retrieve resource ID for any resource definition.
1068
- * @param resource - Any available resource definition
1069
- *
1070
- * @remarks
1071
- * Similar with {@link NgwConnector.getResourceId | getResourceId} but rise error if resource is not exist.
1072
- * To not make one more checks if the resource is definitely exists
1073
- */
1074
- getIdOrFail(resource, requestOptions) {
1075
- return this.getId(resource, requestOptions).then((resp) => {
1076
- if (resp === void 0) {
1077
- throw new Error();
1078
- }
1079
- return resp;
1080
- });
1332
+ return result.join("&");
1333
+ }
1334
+ function generateUrl(path, query) {
1335
+ let urlParams = "";
1336
+ if (query !== void 0) {
1337
+ urlParams = "?" + encodeQueryParams(query);
1338
+ }
1339
+ return path + urlParams;
1340
+ }
1341
+ function request(path, options, cacheEngine) {
1342
+ return __async$6(this, null, function* () {
1343
+ var _b;
1344
+ const defaults = {
1345
+ method: "GET",
1346
+ credentials: "same-origin",
1347
+ headers: {}
1348
+ };
1349
+ const _a = __spreadValues$7(__spreadValues$7({}, defaults), options), {
1350
+ withCredentials,
1351
+ responseType,
1352
+ cacheProps,
1353
+ cacheName,
1354
+ lunkwill,
1355
+ cache,
1356
+ query,
1357
+ json
1358
+ } = _a, opt = __objRest$2(_a, [
1359
+ "withCredentials",
1360
+ "responseType",
1361
+ "cacheProps",
1362
+ "cacheName",
1363
+ "lunkwill",
1364
+ "cache",
1365
+ "query",
1366
+ "json"
1367
+ ]);
1368
+ if (withCredentials) {
1369
+ opt.credentials = "include";
1370
+ }
1371
+ let useLunkwill = false;
1372
+ if (lunkwill !== void 0) {
1373
+ lunkwill.toHeaders(opt.headers || {});
1374
+ useLunkwill = true;
1375
+ }
1376
+ const lunkwillReturnUrl = !!opt.lunkwillReturnUrl;
1377
+ delete opt.lunkwillReturnUrl;
1378
+ if (json !== void 0) {
1379
+ opt.body = JSON.stringify(json);
1380
+ const headers = opt.headers || {};
1381
+ headers["Content-Type"] = "application/json";
1382
+ opt.headers = headers;
1383
+ }
1384
+ const url = generateUrl(path, query);
1385
+ const makeRequest = () => __async$6(this, null, function* () {
1386
+ let response;
1387
+ try {
1388
+ response = yield fetch(url, opt);
1389
+ } catch (e) {
1390
+ if (opt.signal && opt.signal.aborted) {
1391
+ throw e;
1392
+ }
1393
+ throw new NetworksResponseError();
1394
+ }
1395
+ if (useLunkwill && lunkwillCheckResponse(response)) {
1396
+ const lwRespUrl = yield lunkwillResponseUrl(response);
1397
+ if (lunkwillReturnUrl) {
1398
+ return lwRespUrl;
1399
+ }
1400
+ response = yield lunkwillFetch(lwRespUrl);
1401
+ }
1402
+ const respCType = response.headers.get("content-type");
1403
+ const respJSON = respCType && (respCType.includes("application/json") || respCType.includes("application/vnd.lunkwill.request-summary+json"));
1404
+ let body;
1405
+ try {
1406
+ const respMedia = respCType && isMediaContentType(respCType);
1407
+ if (responseType === "blob" || respMedia) {
1408
+ body = yield response.blob();
1409
+ } else if (respJSON) {
1410
+ body = yield response.json();
1411
+ } else {
1412
+ throw new InvalidResponseError();
1413
+ }
1414
+ } catch (e) {
1415
+ if (e.name === "AbortError" || e instanceof InvalidResponseError) {
1416
+ throw e;
1417
+ }
1418
+ throw new InvalidResponseError();
1419
+ }
1420
+ if (400 <= response.status && response.status <= 599) {
1421
+ throw new ServerResponseError(body);
1422
+ }
1423
+ return body;
1424
+ });
1425
+ if (cacheEngine && ((_b = opt.method) == null ? void 0 : _b.toUpperCase()) === "GET") {
1426
+ const props = cacheProps ? cacheProps : __spreadValues$7({}, objectRemoveEmpty({
1427
+ withCredentials,
1428
+ responseType
1429
+ }));
1430
+ return cacheEngine.add(cacheName || url, makeRequest, {
1431
+ props,
1432
+ expirationTime: cache ? void 0 : 500
1433
+ });
1434
+ }
1435
+ return makeRequest();
1436
+ });
1437
+ }
1438
+
1439
+ var __defProp$8 = Object.defineProperty;
1440
+ var __defProps$4 = Object.defineProperties;
1441
+ var __getOwnPropDescs$4 = Object.getOwnPropertyDescriptors;
1442
+ var __getOwnPropSymbols$6 = Object.getOwnPropertySymbols;
1443
+ var __hasOwnProp$6 = Object.prototype.hasOwnProperty;
1444
+ var __propIsEnum$6 = Object.prototype.propertyIsEnumerable;
1445
+ var __defNormalProp$8 = (obj, key, value) => key in obj ? __defProp$8(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
1446
+ var __spreadValues$6 = (a, b) => {
1447
+ for (var prop in b || (b = {}))
1448
+ if (__hasOwnProp$6.call(b, prop))
1449
+ __defNormalProp$8(a, prop, b[prop]);
1450
+ if (__getOwnPropSymbols$6)
1451
+ for (var prop of __getOwnPropSymbols$6(b)) {
1452
+ if (__propIsEnum$6.call(b, prop))
1453
+ __defNormalProp$8(a, prop, b[prop]);
1454
+ }
1455
+ return a;
1456
+ };
1457
+ var __spreadProps$4 = (a, b) => __defProps$4(a, __getOwnPropDescs$4(b));
1458
+ var __objRest$1 = (source, exclude) => {
1459
+ var target = {};
1460
+ for (var prop in source)
1461
+ if (__hasOwnProp$6.call(source, prop) && exclude.indexOf(prop) < 0)
1462
+ target[prop] = source[prop];
1463
+ if (source != null && __getOwnPropSymbols$6)
1464
+ for (var prop of __getOwnPropSymbols$6(source)) {
1465
+ if (exclude.indexOf(prop) < 0 && __propIsEnum$6.call(source, prop))
1466
+ target[prop] = source[prop];
1467
+ }
1468
+ return target;
1469
+ };
1470
+ var __async$5 = (__this, __arguments, generator) => {
1471
+ return new Promise((resolve, reject) => {
1472
+ var fulfilled = (value) => {
1473
+ try {
1474
+ step(generator.next(value));
1475
+ } catch (e) {
1476
+ reject(e);
1477
+ }
1478
+ };
1479
+ var rejected = (value) => {
1480
+ try {
1481
+ step(generator.throw(value));
1482
+ } catch (e) {
1483
+ reject(e);
1484
+ }
1485
+ };
1486
+ var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
1487
+ step((generator = generator.apply(__this, __arguments)).next());
1488
+ });
1489
+ };
1490
+ function routeURL(name, baseUrl, routeData, ...rest) {
1491
+ const [template, ...params] = routeData[name];
1492
+ const first = rest[0];
1493
+ let sub;
1494
+ if (first === void 0) {
1495
+ sub = [];
1496
+ } else if (typeof first === "object" && first !== null) {
1497
+ if (rest.length > 1) {
1498
+ throw new Error("Too many arguments for route(name, object)!");
1499
+ }
1500
+ sub = [];
1501
+ for (const [p, v] of Object.entries(first)) {
1502
+ sub[params.indexOf(p)] = String(v);
1503
+ }
1504
+ } else {
1505
+ sub = rest.map((v) => String(v));
1506
+ }
1507
+ return fixUrlStr(
1508
+ baseUrl + template.replace(/\{(\w+)\}/g, function(m, a) {
1509
+ const idx = parseInt(a);
1510
+ const value = sub[idx];
1511
+ if (value === void 0) {
1512
+ const msg = `Undefined parameter ${idx} in "${template}".`;
1513
+ throw new Error(msg);
1514
+ }
1515
+ return String(value);
1516
+ })
1517
+ );
1518
+ }
1519
+ function route(name, connector, ...rest) {
1520
+ const result = {
1521
+ url: (opt) => __async$5(this, null, function* () {
1522
+ var _a;
1523
+ const routeData = yield connector.connect();
1524
+ const template = routeURL(
1525
+ name,
1526
+ (_a = connector.options.baseUrl) != null ? _a : "",
1527
+ routeData,
1528
+ ...rest
1529
+ );
1530
+ return generateUrl(template, opt == null ? void 0 : opt.query);
1531
+ })
1532
+ };
1533
+ const methods = ["get", "post", "put", "delete", "patch"];
1534
+ for (const method of methods) {
1535
+ const methodResp = (requestOptions) => __async$5(this, null, function* () {
1536
+ var _b;
1537
+ const _a = requestOptions || {}, { headers: optHeaders } = _a, restOpt = __objRest$1(_a, ["headers"]);
1538
+ const routeData = yield connector.connect();
1539
+ const template = routeURL(
1540
+ name,
1541
+ (_b = connector.options.baseUrl) != null ? _b : "",
1542
+ routeData,
1543
+ ...rest
1544
+ );
1545
+ const headers = objectRemoveEmpty(__spreadValues$6(__spreadValues$6({}, connector.getAuthorizationHeaders()), optHeaders != null ? optHeaders : {}));
1546
+ return request(
1547
+ template,
1548
+ __spreadProps$4(__spreadValues$6({
1549
+ headers
1550
+ }, restOpt), {
1551
+ method
1552
+ }),
1553
+ connector.cache
1554
+ );
1555
+ });
1556
+ result[method] = methodResp;
1557
+ }
1558
+ return result;
1559
+ }
1560
+
1561
+ function isObject(val) {
1562
+ return Object.prototype.toString.call(val) === "[object Object]";
1563
+ }
1564
+
1565
+ let loadData;
1566
+ {
1567
+ loadData = (url, callback, options = {}, error, onCancel) => {
1568
+ options.method = options.method || "GET";
1569
+ const xhr = new XMLHttpRequest();
1570
+ xhr.open(options.method || "GET", url, true);
1571
+ if (options.responseType === "blob") {
1572
+ xhr.responseType = options.responseType;
1573
+ }
1574
+ const getResponseText = () => {
1575
+ try {
1576
+ return JSON.parse(xhr.responseText);
1577
+ } catch (er) {
1578
+ return xhr.responseText;
1579
+ }
1580
+ };
1581
+ const processingResponse = (forError = false) => {
1582
+ const cb = forError ? error : callback;
1583
+ if (options.responseType === "blob") {
1584
+ cb(xhr.response);
1585
+ } else {
1586
+ if (xhr.responseText) {
1587
+ cb(getResponseText());
1588
+ } else {
1589
+ error({ message: "" });
1590
+ }
1591
+ }
1592
+ };
1593
+ xhr.onload = () => {
1594
+ if ([401, 403, 404, 422, 500].indexOf(xhr.status) !== -1) {
1595
+ error(new NgwError(getResponseText()));
1596
+ }
1597
+ processingResponse();
1598
+ };
1599
+ xhr.onerror = (er) => {
1600
+ if (xhr.status === 0) {
1601
+ error(new NetworkError(url));
1602
+ } else {
1603
+ error(er);
1604
+ }
1605
+ };
1606
+ xhr.upload.onprogress = function(e) {
1607
+ if (e.lengthComputable) {
1608
+ const percentComplete = e.loaded / e.total * 100;
1609
+ if (options.onProgress) {
1610
+ options.onProgress(percentComplete, e);
1611
+ }
1612
+ }
1613
+ };
1614
+ const headers = options.headers;
1615
+ if (headers) {
1616
+ for (const h in headers) {
1617
+ const header = headers[h];
1618
+ if (typeof header === "string") {
1619
+ xhr.setRequestHeader(h, header);
1620
+ }
1621
+ }
1622
+ }
1623
+ if (options.withCredentials !== void 0) {
1624
+ xhr.withCredentials = options.withCredentials;
1625
+ }
1626
+ let data;
1627
+ if (options.file) {
1628
+ data = new FormData();
1629
+ data.append("file", options.file);
1630
+ if (options.data) {
1631
+ for (const d in options.data) {
1632
+ data.append(d, data[d]);
1633
+ }
1634
+ }
1635
+ } else {
1636
+ data = options.data ? typeof options.data === "string" ? options.data : JSON.stringify(options.data) : null;
1637
+ }
1638
+ if (onCancel) {
1639
+ onCancel(() => {
1640
+ xhr.abort();
1641
+ });
1642
+ }
1643
+ xhr.send(data);
1644
+ };
1645
+ }
1646
+
1647
+ const templateRe = /\{ *([\w_-]+) *\}/g;
1648
+ function template(str, data) {
1649
+ return str.replace(templateRe, (s, key) => {
1650
+ let value = data[key];
1651
+ if (value === void 0) {
1652
+ throw new Error("No value provided for letiable " + s);
1653
+ } else if (typeof value === "function") {
1654
+ value = value(data);
1655
+ }
1656
+ return value;
1657
+ });
1658
+ }
1659
+
1660
+ var __defProp$7 = Object.defineProperty;
1661
+ var __defProps$3 = Object.defineProperties;
1662
+ var __getOwnPropDescs$3 = Object.getOwnPropertyDescriptors;
1663
+ var __getOwnPropSymbols$5 = Object.getOwnPropertySymbols;
1664
+ var __hasOwnProp$5 = Object.prototype.hasOwnProperty;
1665
+ var __propIsEnum$5 = Object.prototype.propertyIsEnumerable;
1666
+ var __defNormalProp$7 = (obj, key, value) => key in obj ? __defProp$7(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
1667
+ var __spreadValues$5 = (a, b) => {
1668
+ for (var prop in b || (b = {}))
1669
+ if (__hasOwnProp$5.call(b, prop))
1670
+ __defNormalProp$7(a, prop, b[prop]);
1671
+ if (__getOwnPropSymbols$5)
1672
+ for (var prop of __getOwnPropSymbols$5(b)) {
1673
+ if (__propIsEnum$5.call(b, prop))
1674
+ __defNormalProp$7(a, prop, b[prop]);
1675
+ }
1676
+ return a;
1677
+ };
1678
+ var __spreadProps$3 = (a, b) => __defProps$3(a, __getOwnPropDescs$3(b));
1679
+ var __objRest = (source, exclude) => {
1680
+ var target = {};
1681
+ for (var prop in source)
1682
+ if (__hasOwnProp$5.call(source, prop) && exclude.indexOf(prop) < 0)
1683
+ target[prop] = source[prop];
1684
+ if (source != null && __getOwnPropSymbols$5)
1685
+ for (var prop of __getOwnPropSymbols$5(source)) {
1686
+ if (exclude.indexOf(prop) < 0 && __propIsEnum$5.call(source, prop))
1687
+ target[prop] = source[prop];
1688
+ }
1689
+ return target;
1690
+ };
1691
+ var __publicField$4 = (obj, key, value) => __defNormalProp$7(obj, typeof key !== "symbol" ? key + "" : key, value);
1692
+ var __async$4 = (__this, __arguments, generator) => {
1693
+ return new Promise((resolve, reject) => {
1694
+ var fulfilled = (value) => {
1695
+ try {
1696
+ step(generator.next(value));
1697
+ } catch (e) {
1698
+ reject(e);
1699
+ }
1700
+ };
1701
+ var rejected = (value) => {
1702
+ try {
1703
+ step(generator.throw(value));
1704
+ } catch (e) {
1705
+ reject(e);
1706
+ }
1707
+ };
1708
+ var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
1709
+ step((generator = generator.apply(__this, __arguments)).next());
1710
+ });
1711
+ };
1712
+ let ID = 0;
1713
+ let REQUEST_ID = 0;
1714
+ class NgwConnector {
1715
+ constructor(options) {
1716
+ this.options = options;
1717
+ __publicField$4(this, "id", ID++);
1718
+ __publicField$4(this, "emitter", new EventEmitter());
1719
+ __publicField$4(this, "user");
1720
+ __publicField$4(this, "cache");
1721
+ __publicField$4(this, "withCredentials");
1722
+ __publicField$4(this, "client", `NextGIS-NGW-Connector/${pkg.version}`);
1723
+ __publicField$4(this, "routeStr", "/api/component/pyramid/route");
1724
+ __publicField$4(this, "activeRequests", {});
1725
+ __publicField$4(this, "requestTransform");
1726
+ const exist = findConnector(options);
1727
+ this.cache = new Cache({ namespace: options.cacheId });
1728
+ if (exist) {
1729
+ return exist;
1730
+ } else {
1731
+ const { route: route2, requestTransform, withCredentials } = this.options;
1732
+ if (route2) {
1733
+ this.routeStr = route2;
1734
+ }
1735
+ if (requestTransform) {
1736
+ this.requestTransform = requestTransform;
1737
+ }
1738
+ if (withCredentials !== void 0) {
1739
+ this.withCredentials = withCredentials;
1740
+ }
1741
+ addConnector(this);
1742
+ }
1743
+ }
1744
+ /**
1745
+ * Clear the cache.
1746
+ */
1747
+ clearCache() {
1748
+ this.cache.clean();
1749
+ }
1750
+ setRequestTransform(requestTransform) {
1751
+ this.requestTransform = requestTransform;
1752
+ }
1753
+ /**
1754
+ * Fast way to specify the connection address to NextGIS Web.
1755
+ * The current connection will be severed.
1756
+ * @param baseUrl - NGW url
1757
+ */
1758
+ setNgw(baseUrl) {
1759
+ this.logout();
1760
+ this.options.baseUrl = baseUrl;
1761
+ addConnector(this);
1762
+ }
1763
+ /**
1764
+ * Establishing a connection with NextGIS Web to fulfill all other requests.
1765
+ * @remarks
1766
+ * This method need not be called manually as it is used when forming a request in {@link apiRequest | apiRequest}.
1767
+ * Can be used to check connection.
1768
+ * @example
1769
+ * ```javascript
1770
+ * const connector = new NgwConnector({ baseUrl: 'https://demo.nextgis.com' });
1771
+ * connector.connect()
1772
+ * .then(() => console.log('Ok'))
1773
+ * .catch((er) => console.log('Connection problem', er));
1774
+ * ```
1775
+ */
1776
+ connect() {
1777
+ return __async$4(this, null, function* () {
1778
+ const auth = this.options.auth;
1779
+ if (auth) {
1780
+ const { login, password } = auth;
1781
+ if (login && password) {
1782
+ yield this._login({ login, password });
1783
+ }
1784
+ }
1785
+ const routeUrl = `${this.routeStr}?client=${this.client}`;
1786
+ return yield this.makeQuery(
1787
+ routeUrl,
1788
+ {},
1789
+ {
1790
+ cacheName: "route",
1791
+ cache: true,
1792
+ cacheProps: {
1793
+ id: this.id,
1794
+ auth,
1795
+ baseUrl: this.options.baseUrl
1796
+ }
1797
+ }
1798
+ );
1799
+ });
1800
+ }
1801
+ /**
1802
+ * Quick way to change NextGIS Web user.
1803
+ * @param credentials - New user credentials
1804
+ */
1805
+ login(credentials, options) {
1806
+ this.logout();
1807
+ addConnector(this);
1808
+ return this._login(credentials, options);
1809
+ }
1810
+ /**
1811
+ * Disconnecting a user. Aborting all current requests
1812
+ */
1813
+ logout() {
1814
+ this.abort();
1815
+ removeConnector(this);
1816
+ this.options.auth = void 0;
1817
+ this.user = void 0;
1818
+ this.clearCache();
1819
+ this.emitter.emit("logout");
1820
+ }
1821
+ getUserInfo(credentials, options) {
1822
+ return __async$4(this, null, function* () {
1823
+ if (this.user && this.user.id) {
1824
+ return this.user;
1825
+ }
1826
+ if (credentials) {
1827
+ this.options.auth = credentials;
1828
+ }
1829
+ const options_ = __spreadValues$5({
1830
+ headers: this.getAuthorizationHeaders(credentials),
1831
+ cache: true
1832
+ }, options);
1833
+ return this.makeQuery(
1834
+ "/api/component/auth/current_user",
1835
+ {},
1836
+ options_
1837
+ );
1838
+ });
1839
+ }
1840
+ /**
1841
+ * Obtaining the required Headers for authentication of requests in the NGW.
1842
+ */
1843
+ getAuthorizationHeaders(credentials) {
1844
+ const client = this.makeClientId(credentials);
1845
+ if (client) {
1846
+ return {
1847
+ Authorization: `Basic ${client}`
1848
+ };
1849
+ }
1850
+ return {};
1851
+ }
1852
+ makeClientId(credentials) {
1853
+ credentials = credentials || this.options.auth;
1854
+ if (credentials) {
1855
+ const { login, password } = credentials;
1856
+ const encodedStr = [login, password].map(encodeURIComponent).join(":");
1857
+ {
1858
+ return window.btoa(encodedStr);
1859
+ }
1860
+ }
1861
+ }
1862
+ /** Stop all api requests */
1863
+ abort() {
1864
+ for (const abortController of Object.values(this.activeRequests)) {
1865
+ abortController.abort();
1866
+ }
1867
+ this.activeRequests = {};
1868
+ }
1869
+ getActiveApiRequests() {
1870
+ return __spreadValues$5({}, this.activeRequests);
1871
+ }
1872
+ route(name, ...rest) {
1873
+ return route(name, this, ...rest);
1874
+ }
1875
+ /**
1876
+ * Send request to NGW.
1877
+ * @param url - URL address to NGW
1878
+ * @param params - Query params
1879
+ * @param options - Request options
1880
+ */
1881
+ makeQuery(_0, _1) {
1882
+ return __async$4(this, arguments, function* (url, params, options = {}) {
1883
+ var _b;
1884
+ url = (this.options.baseUrl ? this.options.baseUrl : "") + url;
1885
+ if (!url) {
1886
+ throw new Error("Empty `url` not allowed");
1887
+ }
1888
+ if (params) {
1889
+ const _a = params, restParams = __objRest(_a, ["paramList"]);
1890
+ url = template(url, restParams);
1891
+ }
1892
+ url = encodeURI(fixUrlStr(url));
1893
+ options = __spreadValues$5({ withCredentials: this.withCredentials }, options);
1894
+ const {
1895
+ cache,
1896
+ signal: externalSignal,
1897
+ method = "GET",
1898
+ headers,
1899
+ cacheName,
1900
+ cacheProps,
1901
+ responseType,
1902
+ withCredentials
1903
+ } = options;
1904
+ const internalAbortController = new AbortController();
1905
+ const internalSignal = internalAbortController.signal;
1906
+ if (externalSignal) {
1907
+ if (externalSignal.aborted) {
1908
+ throw new AbortError();
1909
+ }
1910
+ externalSignal.addEventListener("abort", () => {
1911
+ internalAbortController.abort();
1912
+ });
1913
+ }
1914
+ options.signal = internalSignal;
1915
+ const createPromise = () => __async$4(this, null, function* () {
1916
+ const id = REQUEST_ID++;
1917
+ this.activeRequests[id] = internalAbortController;
1918
+ try {
1919
+ return this._loadData(url, options);
1920
+ } finally {
1921
+ this._cleanActiveRequest(id);
1922
+ }
1923
+ });
1924
+ if (method === "GET") {
1925
+ const cacheOptions = cacheProps ? cacheProps : __spreadProps$3(__spreadValues$5({}, objectRemoveEmpty({
1926
+ headers,
1927
+ withCredentials,
1928
+ responseType,
1929
+ baseUrl: this.options.baseUrl,
1930
+ userId: (_b = this.user) == null ? void 0 : _b.id
1931
+ })), {
1932
+ params
1933
+ });
1934
+ return this.cache.add(cacheName || url, createPromise, {
1935
+ props: cacheOptions,
1936
+ expirationTime: cache ? void 0 : 500
1937
+ });
1938
+ }
1939
+ return createPromise();
1940
+ });
1941
+ }
1942
+ _loadData(url, options) {
1943
+ options.responseType = options.responseType || "json";
1944
+ return new Promise((resolve, reject) => {
1945
+ var _a;
1946
+ if (this.user) {
1947
+ options = options || {};
1948
+ options.headers = __spreadValues$5(__spreadValues$5({}, this.getAuthorizationHeaders()), options.headers);
1949
+ }
1950
+ if (this.requestTransform) {
1951
+ const [transUrl, transOptions] = this.requestTransform(url, options);
1952
+ url = transUrl;
1953
+ options = transOptions;
1954
+ }
1955
+ let runOnAbort = void 0;
1956
+ loadData(url, resolve, options, reject, (handler) => {
1957
+ runOnAbort = handler;
1958
+ });
1959
+ (_a = options.signal) == null ? void 0 : _a.addEventListener("abort", () => {
1960
+ if (runOnAbort !== void 0) {
1961
+ runOnAbort();
1962
+ }
1963
+ reject(new AbortError());
1964
+ });
1965
+ }).catch((httpError) => {
1966
+ if (httpError.name !== "AbortError") {
1967
+ {
1968
+ console.warn("DEV WARN", httpError);
1969
+ }
1970
+ const er = this._handleHttpError(httpError);
1971
+ if (er) {
1972
+ throw er;
1973
+ }
1974
+ }
1975
+ throw httpError;
1976
+ });
1977
+ }
1978
+ _login(credentials, options) {
1979
+ return __async$4(this, null, function* () {
1980
+ try {
1981
+ const data = yield this.getUserInfo(credentials, options);
1982
+ this.user = data;
1983
+ this.emitter.emit("login", data);
1984
+ return data;
1985
+ } catch (er) {
1986
+ this.emitter.emit("login:error", er);
1987
+ throw er;
1988
+ }
1989
+ });
1990
+ }
1991
+ _cleanActiveRequest(requestId) {
1992
+ delete this.activeRequests[requestId];
1993
+ }
1994
+ _handleHttpError(er) {
1995
+ if (er) {
1996
+ if (er instanceof NgwError) {
1997
+ if (er.exception === "nextgisweb.resource.exception.ResourceNotFound") {
1998
+ throw new ResourceNotFoundError(er);
1999
+ } else if (er.exception === "nextgisweb.core.exception.InsufficientPermissions") {
2000
+ throw new InsufficientPermissionsError(er);
2001
+ }
2002
+ }
2003
+ }
2004
+ return er;
2005
+ }
2006
+ }
2007
+ __publicField$4(NgwConnector, "errors", errors);
2008
+
2009
+ function resourceCompare(res1, res2) {
2010
+ return objectDeepEqual(res1, res2);
2011
+ }
2012
+
2013
+ const exclude = ["description"];
2014
+ function resourceToQuery(resource, prefix = "") {
2015
+ prefix = prefix ? prefix + "__" : "";
2016
+ const query = {};
2017
+ for (const [key, value] of Object.entries(resource)) {
2018
+ if (exclude.indexOf(key) === -1) {
2019
+ if (isObject(value)) {
2020
+ if (key === "owner_user") {
2021
+ const children = resourceToQuery(
2022
+ value,
2023
+ key
2024
+ );
2025
+ Object.assign(query, children);
2026
+ } else if (key === "parent" && "id" in value) {
2027
+ query.parent_id = value.id;
2028
+ }
2029
+ } else if (defined(value)) {
2030
+ query[prefix + key] = value;
2031
+ }
2032
+ }
2033
+ }
2034
+ return query;
2035
+ }
2036
+
2037
+ var __defProp$6 = Object.defineProperty;
2038
+ var __defProps$2 = Object.defineProperties;
2039
+ var __getOwnPropDescs$2 = Object.getOwnPropertyDescriptors;
2040
+ var __getOwnPropSymbols$4 = Object.getOwnPropertySymbols;
2041
+ var __hasOwnProp$4 = Object.prototype.hasOwnProperty;
2042
+ var __propIsEnum$4 = Object.prototype.propertyIsEnumerable;
2043
+ var __defNormalProp$6 = (obj, key, value) => key in obj ? __defProp$6(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
2044
+ var __spreadValues$4 = (a, b) => {
2045
+ for (var prop in b || (b = {}))
2046
+ if (__hasOwnProp$4.call(b, prop))
2047
+ __defNormalProp$6(a, prop, b[prop]);
2048
+ if (__getOwnPropSymbols$4)
2049
+ for (var prop of __getOwnPropSymbols$4(b)) {
2050
+ if (__propIsEnum$4.call(b, prop))
2051
+ __defNormalProp$6(a, prop, b[prop]);
2052
+ }
2053
+ return a;
2054
+ };
2055
+ var __spreadProps$2 = (a, b) => __defProps$2(a, __getOwnPropDescs$2(b));
2056
+ var __publicField$3 = (obj, key, value) => __defNormalProp$6(obj, typeof key !== "symbol" ? key + "" : key, value);
2057
+ var __async$3 = (__this, __arguments, generator) => {
2058
+ return new Promise((resolve, reject) => {
2059
+ var fulfilled = (value) => {
2060
+ try {
2061
+ step(generator.next(value));
2062
+ } catch (e) {
2063
+ reject(e);
2064
+ }
2065
+ };
2066
+ var rejected = (value) => {
2067
+ try {
2068
+ step(generator.throw(value));
2069
+ } catch (e) {
2070
+ reject(e);
2071
+ }
2072
+ };
2073
+ var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
2074
+ step((generator = generator.apply(__this, __arguments)).next());
2075
+ });
2076
+ };
2077
+ class ResourcesControl {
2078
+ constructor({
2079
+ connector,
2080
+ cacheId
2081
+ }) {
2082
+ __publicField$3(this, "cache");
2083
+ __publicField$3(this, "connector");
2084
+ this.connector = connector;
2085
+ this.cache = new Cache({ namespace: cacheId });
2086
+ }
2087
+ // -------------------------------------------------------------------------
2088
+ // Resource Methods
2089
+ // -------------------------------------------------------------------------
2090
+ /**
2091
+ * Receive resource from NGW by id, keyname or search-object parameter.
2092
+ * @param resource - Resource id, keyname or search-object
2093
+ *
2094
+ * @remarks
2095
+ * Fetching resource would be cached to speed up next call
2096
+ */
2097
+ getOne(resource, requestOptions) {
2098
+ const opt = __spreadValues$4({}, requestOptions);
2099
+ if (typeof resource === "string") ; else if (typeof resource === "number") ; else if (isObject(resource)) {
2100
+ if (resource.id !== void 0) {
2101
+ resource.id;
2102
+ } else {
2103
+ if (resource.keyname) {
2104
+ resource.keyname;
2105
+ }
2106
+ if (resource.display_name) {
2107
+ resource.display_name;
2108
+ }
2109
+ }
2110
+ }
2111
+ if (typeof resource === "string") {
2112
+ return this._fetchResourceBy({ keyname: resource }, opt);
2113
+ } else if (typeof resource === "number") {
2114
+ return this._fetchResourceById(resource, opt);
2115
+ } else if (isObject(resource)) {
2116
+ return this._fetchResourceBy(resource, opt);
2117
+ }
2118
+ return Promise.resolve(void 0);
2119
+ }
2120
+ getOneOrFail(resource, requestOptions) {
2121
+ return this.getOne(resource, requestOptions).then((res) => {
2122
+ if (res) {
2123
+ return res;
2124
+ }
2125
+ throw new ResourceNotFoundError();
2126
+ });
2127
+ }
2128
+ /**
2129
+ * A fast way to retrieve resource ID for any resource definition.
2130
+ * @param resource - Any available resource definition
2131
+ *
2132
+ * @remarks
2133
+ * There are situations when exactly the resource id is needed
2134
+ * (for example, to compose the correct request to the api)
2135
+ * then this method will come in handy to facilitate the extraction of the identifier
2136
+ * if the resource is specified through a keyname or other parameters.
2137
+ */
2138
+ getId(resource, requestOptions) {
2139
+ if (typeof resource === "number") {
2140
+ return Promise.resolve(resource);
2141
+ } else if (typeof resource === "string" || isObject(resource)) {
2142
+ return this.getOne(resource, requestOptions).then((res) => {
2143
+ if (res) {
2144
+ return res.resource.id;
2145
+ }
2146
+ });
2147
+ }
2148
+ return Promise.resolve(void 0);
2149
+ }
2150
+ /**
2151
+ * A fast way to retrieve resource ID for any resource definition.
2152
+ * @param resource - Any available resource definition
2153
+ *
2154
+ * @remarks
2155
+ * Similar with {@link NgwConnector.getResourceId | getResourceId} but rise error if resource is not exist.
2156
+ * To not make one more checks if the resource is definitely exists
2157
+ */
2158
+ getIdOrFail(resource, requestOptions) {
2159
+ return this.getId(resource, requestOptions).then((resp) => {
2160
+ if (resp === void 0) {
2161
+ throw new Error();
2162
+ }
2163
+ return resp;
2164
+ });
1081
2165
  }
1082
2166
  getMany(resource, requestOptions) {
1083
2167
  return this._resourceCacheFilter(resource).then((items) => {
@@ -1088,9 +2172,11 @@ var Geocoder = (function (exports) {
1088
2172
  } else {
1089
2173
  Object.assign(query, resourceToQuery(resource));
1090
2174
  }
1091
- return this.connector.get("resource.search", requestOptions, __spreadValues$5({
1092
- serialization: "full"
1093
- }, query)).then((resources) => {
2175
+ return this.connector.route("resource.search").get(__spreadProps$2(__spreadValues$4({}, requestOptions), {
2176
+ query: __spreadValues$4({
2177
+ serialization: "full"
2178
+ }, query)
2179
+ })).then((resources) => {
1094
2180
  if ((requestOptions == null ? void 0 : requestOptions.cache) && resources) {
1095
2181
  for (const x of resources) {
1096
2182
  this.cache.add("resource.item", Promise.resolve(x), {
@@ -1106,7 +2192,8 @@ var Geocoder = (function (exports) {
1106
2192
  }
1107
2193
  getParent(resource, requestOptions) {
1108
2194
  return this.getOne(resource, requestOptions).then((child) => {
1109
- if (child) {
2195
+ var _a, _b;
2196
+ if ((_b = (_a = child == null ? void 0 : child.resource) == null ? void 0 : _a.parent) == null ? void 0 : _b.id) {
1110
2197
  return this.getOne(child.resource.parent.id, requestOptions);
1111
2198
  }
1112
2199
  return Promise.resolve(void 0);
@@ -1138,10 +2225,21 @@ var Geocoder = (function (exports) {
1138
2225
  }
1139
2226
  });
1140
2227
  }
1141
- _getChildrenOf(parent, requestOptions, _items = []) {
1142
- return this.connector.get("resource.collection", requestOptions, {
1143
- parent
1144
- }).then((items) => {
2228
+ _getChildrenOf(_0, _1) {
2229
+ return __async$3(this, arguments, function* (parentDef, requestOptions, _items = []) {
2230
+ let parent = void 0;
2231
+ if (typeof parentDef === "string") {
2232
+ parent = yield this.getId(parentDef, requestOptions);
2233
+ } else if (typeof parentDef === "object") {
2234
+ parent = parentDef.id;
2235
+ } else {
2236
+ parent = parentDef;
2237
+ }
2238
+ const items = yield this.connector.route("resource.collection").get(__spreadProps$2(__spreadValues$4({}, requestOptions), {
2239
+ query: {
2240
+ parent
2241
+ }
2242
+ }));
1145
2243
  const recursivePromises = [];
1146
2244
  for (const item of items) {
1147
2245
  if (requestOptions == null ? void 0 : requestOptions.cache) {
@@ -1165,7 +2263,7 @@ var Geocoder = (function (exports) {
1165
2263
  });
1166
2264
  }
1167
2265
  _cleanResourceItemCache(id) {
1168
- return __async$4(this, null, function* () {
2266
+ return __async$3(this, null, function* () {
1169
2267
  var _a;
1170
2268
  const all = this.cache.all();
1171
2269
  const toDelete = [];
@@ -1190,7 +2288,7 @@ var Geocoder = (function (exports) {
1190
2288
  });
1191
2289
  }
1192
2290
  _fetchResourceById(id, requestOptions) {
1193
- return this.connector.get("resource.item", requestOptions, { id });
2291
+ return this.connector.route("resource.item", { id }).get(requestOptions);
1194
2292
  }
1195
2293
  _fetchResourceBy(resource, requestOptions) {
1196
2294
  return this.getMany(resource, requestOptions).then((resources) => {
@@ -1218,79 +2316,23 @@ var Geocoder = (function (exports) {
1218
2316
  }
1219
2317
  }
1220
2318
 
1221
- const CONNECTORS = [];
1222
- function addConnector(connector) {
1223
- CONNECTORS.push(connector);
1224
- }
1225
- function findConnector(options) {
1226
- return CONNECTORS.find((x) => {
1227
- if (x.options.baseUrl === options.baseUrl) {
1228
- if (options.auth) {
1229
- if (x.options.auth) {
1230
- return objectDeepEqual(x.options.auth, options.auth);
1231
- }
1232
- } else {
1233
- return true;
1234
- }
1235
- }
1236
- });
1237
- }
1238
- function removeConnector(connector) {
1239
- const index = CONNECTORS.indexOf(connector);
1240
- if (index !== -1) {
1241
- CONNECTORS.splice(index, 1);
1242
- }
1243
- }
1244
-
1245
- class AbortError extends Error {
1246
- constructor(message = "AbortError") {
1247
- super(message);
1248
- this.name = "AbortError";
1249
- }
1250
- }
1251
-
1252
- var __defProp$7 = Object.defineProperty;
1253
- var __defNormalProp$7 = (obj, key, value) => key in obj ? __defProp$7(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
1254
- var __publicField$4 = (obj, key, value) => __defNormalProp$7(obj, typeof key !== "symbol" ? key + "" : key, value);
1255
- class InsufficientPermissionsError extends NgwError {
1256
- constructor(obj) {
1257
- super(obj);
1258
- __publicField$4(this, "name", "InsufficientPermissionsError");
1259
- __publicField$4(this, "exception", "nextgisweb.core.exception.InsufficientPermissions");
1260
- Object.setPrototypeOf(this, InsufficientPermissionsError.prototype);
1261
- }
1262
- }
1263
-
1264
- const templateRe = /\{ *([\w_-]+) *\}/g;
1265
- function template(str, data) {
1266
- return str.replace(templateRe, (s, key) => {
1267
- let value = data[key];
1268
- if (value === void 0) {
1269
- throw new Error("No value provided for letiable " + s);
1270
- } else if (typeof value === "function") {
1271
- value = value(data);
1272
- }
1273
- return value;
1274
- });
1275
- }
1276
-
1277
- var __defProp$6 = Object.defineProperty;
1278
- var __getOwnPropSymbols$4 = Object.getOwnPropertySymbols;
1279
- var __hasOwnProp$4 = Object.prototype.hasOwnProperty;
1280
- var __propIsEnum$4 = Object.prototype.propertyIsEnumerable;
1281
- var __defNormalProp$6 = (obj, key, value) => key in obj ? __defProp$6(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
1282
- var __spreadValues$4 = (a, b) => {
2319
+ var __defProp$5 = Object.defineProperty;
2320
+ var __getOwnPropSymbols$3 = Object.getOwnPropertySymbols;
2321
+ var __hasOwnProp$3 = Object.prototype.hasOwnProperty;
2322
+ var __propIsEnum$3 = Object.prototype.propertyIsEnumerable;
2323
+ var __defNormalProp$5 = (obj, key, value) => key in obj ? __defProp$5(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
2324
+ var __spreadValues$3 = (a, b) => {
1283
2325
  for (var prop in b || (b = {}))
1284
- if (__hasOwnProp$4.call(b, prop))
1285
- __defNormalProp$6(a, prop, b[prop]);
1286
- if (__getOwnPropSymbols$4)
1287
- for (var prop of __getOwnPropSymbols$4(b)) {
1288
- if (__propIsEnum$4.call(b, prop))
1289
- __defNormalProp$6(a, prop, b[prop]);
2326
+ if (__hasOwnProp$3.call(b, prop))
2327
+ __defNormalProp$5(a, prop, b[prop]);
2328
+ if (__getOwnPropSymbols$3)
2329
+ for (var prop of __getOwnPropSymbols$3(b)) {
2330
+ if (__propIsEnum$3.call(b, prop))
2331
+ __defNormalProp$5(a, prop, b[prop]);
1290
2332
  }
1291
2333
  return a;
1292
2334
  };
1293
- var __async$3 = (__this, __arguments, generator) => {
2335
+ var __async$2 = (__this, __arguments, generator) => {
1294
2336
  return new Promise((resolve, reject) => {
1295
2337
  var fulfilled = (value) => {
1296
2338
  try {
@@ -1311,7 +2353,7 @@ var Geocoder = (function (exports) {
1311
2353
  });
1312
2354
  };
1313
2355
  function apiRequest(opt) {
1314
- return __async$3(this, null, function* () {
2356
+ return __async$2(this, null, function* () {
1315
2357
  const { params, name, connector, requestOptions } = opt;
1316
2358
  const apiItems = yield connector.connect();
1317
2359
  let apiItem = apiItems && apiItems[name];
@@ -1340,339 +2382,48 @@ var Geocoder = (function (exports) {
1340
2382
  });
1341
2383
  }
1342
2384
  for (const p in params) {
1343
- if (apiItem.indexOf(p) === -1) {
1344
- paramArray.push(`${p}=${params[p]}`);
1345
- }
1346
- }
1347
- if (paramArray.length) {
1348
- url = `${url}?${paramArray.join("&")}`;
1349
- }
1350
- }
1351
- if (url) {
1352
- return connector.makeQuery(url, params, __spreadValues$4({
1353
- cacheName: name
1354
- }, requestOptions));
1355
- } else {
1356
- throw new Error("Request URL is not set");
1357
- }
1358
- } else {
1359
- return void 0;
1360
- }
1361
- });
1362
- }
1363
-
1364
- var __defProp$5 = Object.defineProperty;
1365
- var __defNormalProp$5 = (obj, key, value) => key in obj ? __defProp$5(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
1366
- var __publicField$3 = (obj, key, value) => __defNormalProp$5(obj, key + "" , value);
1367
- class NetworkError extends Error {
1368
- constructor(url) {
1369
- super();
1370
- __publicField$3(this, "name", "NetworkError");
1371
- Object.setPrototypeOf(this, NetworkError.prototype);
1372
- this.message = `Unable to request ${url}.
1373
- Possibly invalid NGW URL entered or CORS not configured to get request from ${location.origin}`;
1374
- }
1375
- }
1376
-
1377
- let loadData;
1378
- {
1379
- loadData = (url, callback, options = {}, error, onCancel) => {
1380
- options.method = options.method || "GET";
1381
- const xhr = new XMLHttpRequest();
1382
- xhr.open(options.method || "GET", url, true);
1383
- if (options.responseType === "blob") {
1384
- xhr.responseType = options.responseType;
1385
- }
1386
- const getResponseText = () => {
1387
- try {
1388
- return JSON.parse(xhr.responseText);
1389
- } catch (er) {
1390
- return xhr.responseText;
1391
- }
1392
- };
1393
- const processingResponse = (forError = false) => {
1394
- const cb = forError ? error : callback;
1395
- if (options.responseType === "blob") {
1396
- cb(xhr.response);
1397
- } else {
1398
- if (xhr.responseText) {
1399
- cb(getResponseText());
1400
- } else {
1401
- error({ message: "" });
1402
- }
1403
- }
1404
- };
1405
- xhr.onload = () => {
1406
- if ([401, 403, 404, 422, 500].indexOf(xhr.status) !== -1) {
1407
- error(new NgwError(getResponseText()));
1408
- }
1409
- processingResponse();
1410
- };
1411
- xhr.onerror = (er) => {
1412
- if (xhr.status === 0) {
1413
- error(new NetworkError(url));
1414
- } else {
1415
- error(er);
1416
- }
1417
- };
1418
- xhr.upload.onprogress = function(e) {
1419
- if (e.lengthComputable) {
1420
- const percentComplete = e.loaded / e.total * 100;
1421
- if (options.onProgress) {
1422
- options.onProgress(percentComplete, e);
1423
- }
1424
- }
1425
- };
1426
- const headers = options.headers;
1427
- if (headers) {
1428
- for (const h in headers) {
1429
- const header = headers[h];
1430
- if (typeof header === "string") {
1431
- xhr.setRequestHeader(h, header);
1432
- }
1433
- }
1434
- }
1435
- if (options.withCredentials !== void 0) {
1436
- xhr.withCredentials = options.withCredentials;
1437
- }
1438
- let data;
1439
- if (options.file) {
1440
- data = new FormData();
1441
- data.append("file", options.file);
1442
- if (options.data) {
1443
- for (const d in options.data) {
1444
- data.append(d, data[d]);
1445
- }
1446
- }
1447
- } else {
1448
- data = options.data ? typeof options.data === "string" ? options.data : JSON.stringify(options.data) : null;
1449
- }
1450
- if (onCancel) {
1451
- onCancel(() => {
1452
- xhr.abort();
1453
- });
1454
- }
1455
- xhr.send(data);
1456
- };
1457
- }
1458
-
1459
- var __defProp$4 = Object.defineProperty;
1460
- var __defProps$2 = Object.defineProperties;
1461
- var __getOwnPropDescs$2 = Object.getOwnPropertyDescriptors;
1462
- var __getOwnPropSymbols$3 = Object.getOwnPropertySymbols;
1463
- var __hasOwnProp$3 = Object.prototype.hasOwnProperty;
1464
- var __propIsEnum$3 = Object.prototype.propertyIsEnumerable;
1465
- var __defNormalProp$4 = (obj, key, value) => key in obj ? __defProp$4(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
1466
- var __spreadValues$3 = (a, b) => {
1467
- for (var prop in b || (b = {}))
1468
- if (__hasOwnProp$3.call(b, prop))
1469
- __defNormalProp$4(a, prop, b[prop]);
1470
- if (__getOwnPropSymbols$3)
1471
- for (var prop of __getOwnPropSymbols$3(b)) {
1472
- if (__propIsEnum$3.call(b, prop))
1473
- __defNormalProp$4(a, prop, b[prop]);
1474
- }
1475
- return a;
1476
- };
1477
- var __spreadProps$2 = (a, b) => __defProps$2(a, __getOwnPropDescs$2(b));
1478
- var __objRest = (source, exclude) => {
1479
- var target = {};
1480
- for (var prop in source)
1481
- if (__hasOwnProp$3.call(source, prop) && exclude.indexOf(prop) < 0)
1482
- target[prop] = source[prop];
1483
- if (source != null && __getOwnPropSymbols$3)
1484
- for (var prop of __getOwnPropSymbols$3(source)) {
1485
- if (exclude.indexOf(prop) < 0 && __propIsEnum$3.call(source, prop))
1486
- target[prop] = source[prop];
1487
- }
1488
- return target;
1489
- };
1490
- var __publicField$2 = (obj, key, value) => __defNormalProp$4(obj, typeof key !== "symbol" ? key + "" : key, value);
1491
- var __async$2 = (__this, __arguments, generator) => {
1492
- return new Promise((resolve, reject) => {
1493
- var fulfilled = (value) => {
1494
- try {
1495
- step(generator.next(value));
1496
- } catch (e) {
1497
- reject(e);
1498
- }
1499
- };
1500
- var rejected = (value) => {
1501
- try {
1502
- step(generator.throw(value));
1503
- } catch (e) {
1504
- reject(e);
1505
- }
1506
- };
1507
- var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
1508
- step((generator = generator.apply(__this, __arguments)).next());
1509
- });
1510
- };
1511
- let ID = 0;
1512
- let REQUEST_ID = 0;
1513
- class NgwConnector {
1514
- constructor(options) {
1515
- this.options = options;
1516
- __publicField$2(this, "id", ID++);
1517
- __publicField$2(this, "emitter", new EventEmitter());
1518
- __publicField$2(this, "user");
1519
- __publicField$2(this, "resources");
1520
- __publicField$2(this, "cache");
1521
- __publicField$2(this, "withCredentials");
1522
- __publicField$2(this, "routeStr", "/api/component/pyramid/route");
1523
- __publicField$2(this, "activeRequests", {});
1524
- __publicField$2(this, "requestTransform");
1525
- const exist = findConnector(options);
1526
- this.cache = new Cache({ namespace: options.cacheId });
1527
- if (exist) {
1528
- return exist;
1529
- } else {
1530
- const { route, requestTransform, withCredentials } = this.options;
1531
- if (route) {
1532
- this.routeStr = route;
1533
- }
1534
- if (requestTransform) {
1535
- this.requestTransform = requestTransform;
1536
- }
1537
- if (withCredentials !== void 0) {
1538
- this.withCredentials = withCredentials;
1539
- }
1540
- this.resources = new ResourcesControl({
1541
- connector: this,
1542
- cacheId: options.cacheId
1543
- });
1544
- addConnector(this);
1545
- }
1546
- }
1547
- static create(options) {
1548
- return new this(options);
1549
- }
1550
- /**
1551
- * Clear the cache.
1552
- */
1553
- clearCache() {
1554
- this.cache.clean();
1555
- this.resources.cache.clean();
1556
- }
1557
- setRequestTransform(requestTransform) {
1558
- this.requestTransform = requestTransform;
1559
- }
1560
- /**
1561
- * Fast way to specify the connection address to NextGIS Web.
1562
- * The current connection will be severed.
1563
- * @param baseUrl - NGW url
1564
- */
1565
- setNgw(baseUrl) {
1566
- this.logout();
1567
- this.options.baseUrl = baseUrl;
1568
- addConnector(this);
1569
- }
1570
- /**
1571
- * Establishing a connection with NextGIS Web to fulfill all other requests.
1572
- * @remarks
1573
- * This method need not be called manually as it is used when forming a request in {@link apiRequest | apiRequest}.
1574
- * Can be used to check connection.
1575
- * @example
1576
- * ```javascript
1577
- * const connector = new NgwConnector({baseUrl: 'https://demo.nextgis.com'});
1578
- * connector.connect()
1579
- * .then(() => console.log('Ok'))
1580
- * .catch((er) => console.log('Connection problem', er));
1581
- * ```
1582
- */
1583
- connect() {
1584
- return __async$2(this, null, function* () {
1585
- const auth = this.options.auth;
1586
- if (auth) {
1587
- const { login, password } = auth;
1588
- if (login && password) {
1589
- yield this._login({ login, password });
1590
- }
1591
- }
1592
- return yield this.makeQuery(
1593
- this.routeStr,
1594
- {},
1595
- {
1596
- cacheName: "route",
1597
- cache: true,
1598
- cacheProps: {
1599
- id: this.id,
1600
- auth,
1601
- baseUrl: this.options.baseUrl
2385
+ if (apiItem.indexOf(p) === -1) {
2386
+ paramArray.push(`${p}=${params[p]}`);
1602
2387
  }
1603
2388
  }
1604
- );
1605
- });
1606
- }
1607
- /**
1608
- * Quick way to change NextGIS Web user.
1609
- * @param credentials - New user credentials
1610
- */
1611
- login(credentials, options) {
1612
- this.logout();
1613
- addConnector(this);
1614
- return this._login(credentials, options);
1615
- }
1616
- /**
1617
- * Disconnecting a user. Aborting all current requests
1618
- */
1619
- logout() {
1620
- this.abort();
1621
- removeConnector(this);
1622
- this.options.auth = void 0;
1623
- this.user = void 0;
1624
- this.clearCache();
1625
- this.emitter.emit("logout");
1626
- }
1627
- getUserInfo(credentials, options) {
1628
- return __async$2(this, null, function* () {
1629
- if (this.user && this.user.id) {
1630
- return this.user;
2389
+ if (paramArray.length) {
2390
+ url = `${url}?${paramArray.join("&")}`;
2391
+ }
1631
2392
  }
1632
- if (credentials) {
1633
- this.options.auth = credentials;
2393
+ if (url) {
2394
+ return connector.makeQuery(url, params, __spreadValues$3({
2395
+ cacheName: name
2396
+ }, requestOptions));
2397
+ } else {
2398
+ throw new Error("Request URL is not set");
1634
2399
  }
1635
- const options_ = __spreadValues$3({
1636
- headers: this.getAuthorizationHeaders(credentials)
1637
- }, options);
1638
- return this.makeQuery(
1639
- "/api/component/auth/current_user",
1640
- {},
1641
- options_
1642
- );
2400
+ } else {
2401
+ return void 0;
2402
+ }
2403
+ });
2404
+ }
2405
+
2406
+ var __defProp$4 = Object.defineProperty;
2407
+ var __defNormalProp$4 = (obj, key, value) => key in obj ? __defProp$4(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
2408
+ var __publicField$2 = (obj, key, value) => __defNormalProp$4(obj, key + "" , value);
2409
+ class NgwConnectorExtended extends NgwConnector {
2410
+ constructor(options) {
2411
+ super(options);
2412
+ __publicField$2(this, "resources");
2413
+ this.resources = new ResourcesControl({
2414
+ connector: this,
2415
+ cacheId: options.cacheId
1643
2416
  });
1644
2417
  }
2418
+ static create(options) {
2419
+ return new this(options);
2420
+ }
1645
2421
  /**
1646
- * Obtaining the required Headers for authentication of requests in the NGW.
2422
+ * Clear the cache.
1647
2423
  */
1648
- getAuthorizationHeaders(credentials) {
1649
- const client = this.makeClientId(credentials);
1650
- if (client) {
1651
- return {
1652
- Authorization: `Basic ${client}`
1653
- };
1654
- }
1655
- }
1656
- makeClientId(credentials) {
1657
- credentials = credentials || this.options.auth;
1658
- if (credentials) {
1659
- const { login, password } = credentials;
1660
- const str = `${login}:${password}`;
1661
- const encodedStr = encodeURIComponent(str);
1662
- {
1663
- return window.btoa(encodedStr);
1664
- }
1665
- }
1666
- }
1667
- /** Stop all api requests */
1668
- abort() {
1669
- for (const abortController of Object.values(this.activeRequests)) {
1670
- abortController.abort();
1671
- }
1672
- this.activeRequests = {};
1673
- }
1674
- getActiveApiRequests() {
1675
- return __spreadValues$3({}, this.activeRequests);
2424
+ clearCache() {
2425
+ super.clearCache();
2426
+ this.resources.cache.clean();
1676
2427
  }
1677
2428
  /**
1678
2429
  * Send request to NGW api router.
@@ -1791,75 +2542,6 @@ var Geocoder = (function (exports) {
1791
2542
  options
1792
2543
  );
1793
2544
  }
1794
- /**
1795
- * Send request to NGW.
1796
- * @param url - URL address to NGW
1797
- * @param params - Query params
1798
- * @param options - Request options
1799
- */
1800
- makeQuery(_0, _1) {
1801
- return __async$2(this, arguments, function* (url, params, options = {}) {
1802
- var _b;
1803
- url = (this.options.baseUrl ? this.options.baseUrl : "") + url;
1804
- if (!url) {
1805
- throw new Error("Empty `url` not allowed");
1806
- }
1807
- if (params) {
1808
- const _a = params, restParams = __objRest(_a, ["paramList"]);
1809
- url = template(url, restParams);
1810
- }
1811
- url = encodeURI(fixUrlStr(url));
1812
- options = __spreadValues$3({ withCredentials: this.withCredentials }, options);
1813
- const {
1814
- cache,
1815
- signal: externalSignal,
1816
- method = "GET",
1817
- headers,
1818
- cacheName,
1819
- cacheProps,
1820
- responseType,
1821
- withCredentials
1822
- } = options;
1823
- const internalAbortController = new AbortController();
1824
- const internalSignal = internalAbortController.signal;
1825
- if (externalSignal) {
1826
- if (externalSignal.aborted) {
1827
- throw new AbortError();
1828
- }
1829
- externalSignal.addEventListener("abort", () => {
1830
- internalAbortController.abort();
1831
- });
1832
- }
1833
- options.signal = internalSignal;
1834
- const createPromise = () => __async$2(this, null, function* () {
1835
- const id = REQUEST_ID++;
1836
- this.activeRequests[id] = internalAbortController;
1837
- try {
1838
- return this._loadData(url, options);
1839
- } finally {
1840
- this._cleanActiveRequest(id);
1841
- }
1842
- });
1843
- if (cache && method === "GET") {
1844
- const cacheOptions = cacheProps ? cacheProps : __spreadProps$2(__spreadValues$3({}, objectRemoveEmpty({
1845
- headers,
1846
- withCredentials,
1847
- responseType,
1848
- baseUrl: this.options.baseUrl,
1849
- userId: (_b = this.user) == null ? void 0 : _b.id
1850
- })), {
1851
- params
1852
- });
1853
- return this.cache.add(
1854
- cacheName || url,
1855
- createPromise,
1856
- cacheOptions,
1857
- false
1858
- );
1859
- }
1860
- return createPromise();
1861
- });
1862
- }
1863
2545
  // -------------------------------------------------------------------------
1864
2546
  // Resource Methods
1865
2547
  // -------------------------------------------------------------------------
@@ -1935,78 +2617,7 @@ var Geocoder = (function (exports) {
1935
2617
  deleteResource(resource) {
1936
2618
  return this.resources.delete(resource);
1937
2619
  }
1938
- /**
1939
- * @internal
1940
- */
1941
- _loadData(url, options) {
1942
- options.responseType = options.responseType || "json";
1943
- return new Promise((resolve, reject) => {
1944
- var _a;
1945
- if (this.user) {
1946
- options = options || {};
1947
- options.headers = __spreadValues$3(__spreadValues$3({}, this.getAuthorizationHeaders()), options.headers);
1948
- }
1949
- if (this.requestTransform) {
1950
- const [transUrl, transOptions] = this.requestTransform(url, options);
1951
- url = transUrl;
1952
- options = transOptions;
1953
- }
1954
- let runOnAbort = void 0;
1955
- loadData(url, resolve, options, reject, (handler) => {
1956
- runOnAbort = handler;
1957
- });
1958
- (_a = options.signal) == null ? void 0 : _a.addEventListener("abort", () => {
1959
- if (runOnAbort !== void 0) {
1960
- runOnAbort();
1961
- }
1962
- reject(new AbortError());
1963
- });
1964
- }).catch((httpError) => {
1965
- if (httpError.name !== "AbortError") {
1966
- {
1967
- console.warn("DEV WARN", httpError);
1968
- }
1969
- const er = this._handleHttpError(httpError);
1970
- if (er) {
1971
- throw er;
1972
- }
1973
- }
1974
- throw httpError;
1975
- });
1976
- }
1977
- _login(credentials, options) {
1978
- return __async$2(this, null, function* () {
1979
- try {
1980
- const data = yield this.getUserInfo(credentials, options);
1981
- this.user = data;
1982
- this.emitter.emit("login", data);
1983
- return data;
1984
- } catch (er) {
1985
- this.emitter.emit("login:error", er);
1986
- throw er;
1987
- }
1988
- });
1989
- }
1990
- _cleanActiveRequest(requestId) {
1991
- delete this.activeRequests[requestId];
1992
- }
1993
- _handleHttpError(er) {
1994
- if (er) {
1995
- if (er instanceof NgwError) {
1996
- if (er.exception === "nextgisweb.resource.exception.ResourceNotFound") {
1997
- throw new ResourceNotFoundError(er);
1998
- } else if (er.exception === "nextgisweb.core.exception.InsufficientPermissions") {
1999
- throw new InsufficientPermissionsError(er);
2000
- }
2001
- }
2002
- }
2003
- return er;
2004
- }
2005
2620
  }
2006
- __publicField$2(NgwConnector, "errors", {
2007
- NgwError,
2008
- ResourceNotFoundError
2009
- });
2010
2621
 
2011
2622
  function reEscape(s) {
2012
2623
  return s.replace(/[-/\\^$*+?.()|[\]{}]/g, "\\$&");
@@ -2078,6 +2689,10 @@ var Geocoder = (function (exports) {
2078
2689
  return logic === "any" ? filters_.some(filterFunction) : filters_.every(filterFunction);
2079
2690
  }
2080
2691
 
2692
+ const config = {
2693
+ defaultRequestLimit: 7e3
2694
+ };
2695
+
2081
2696
  var __defProp$3 = Object.defineProperty;
2082
2697
  var __defProps$1 = Object.defineProperties;
2083
2698
  var __getOwnPropDescs$1 = Object.getOwnPropertyDescriptors;
@@ -2123,15 +2738,12 @@ var Geocoder = (function (exports) {
2123
2738
  };
2124
2739
  function updateItemRequestParam(params, options) {
2125
2740
  const { extensions, geom, fields, srs, ilike, like } = options;
2126
- const extensionsStr = extensions ? extensions.join(",") : "";
2127
- if (extensionsStr !== "*") {
2128
- params.extensions = extensionsStr;
2129
- }
2130
- if (fields !== void 0) {
2131
- params.fields = Array.isArray(fields) ? fields.join(",") : "";
2741
+ params.extensions = extensions ? extensions : [];
2742
+ if (fields) {
2743
+ params.fields = fields;
2132
2744
  }
2133
2745
  if (geom !== void 0) {
2134
- params.geom = geom ? "yes" : "no";
2746
+ params.geom = geom;
2135
2747
  if (!geom) {
2136
2748
  delete params.srs;
2137
2749
  delete params.geom_format;
@@ -2146,6 +2758,15 @@ var Geocoder = (function (exports) {
2146
2758
  params.srs = srs;
2147
2759
  }
2148
2760
  }
2761
+ function paramListToQuery(paramList) {
2762
+ return paramList.reduce(
2763
+ (acc, [key, value]) => {
2764
+ acc[key] = value;
2765
+ return acc;
2766
+ },
2767
+ {}
2768
+ );
2769
+ }
2149
2770
  function createFeatureFieldFilterQueries(opt) {
2150
2771
  return __async$1(this, null, function* () {
2151
2772
  const queries = getQueries(opt);
@@ -2246,6 +2867,7 @@ var Geocoder = (function (exports) {
2246
2867
  const params = __spreadValues$2({}, FEATURE_REQUEST_PARAMS);
2247
2868
  const {
2248
2869
  limit,
2870
+ query,
2249
2871
  cache,
2250
2872
  signal,
2251
2873
  offset,
@@ -2256,12 +2878,10 @@ var Geocoder = (function (exports) {
2256
2878
  intersects,
2257
2879
  resourceId
2258
2880
  } = options;
2259
- if (limit) {
2260
- if (limit !== Number.POSITIVE_INFINITY) {
2261
- params.limit = limit;
2262
- }
2881
+ if (limit && limit !== Number.POSITIVE_INFINITY) {
2882
+ params.limit = limit;
2263
2883
  } else {
2264
- params.limit = 7e3;
2884
+ params.limit = config.defaultRequestLimit;
2265
2885
  }
2266
2886
  if (offset) {
2267
2887
  params.offset = offset;
@@ -2280,16 +2900,9 @@ var Geocoder = (function (exports) {
2280
2900
  params.intersects = intersects;
2281
2901
  }
2282
2902
  if (paramList) {
2283
- params.paramList = paramList;
2284
- }
2285
- const reqParams = __spreadValues$2({
2286
- id: resourceId
2287
- }, params);
2288
- return connector.get(
2289
- "feature_layer.feature.collection",
2290
- { cache, signal },
2291
- reqParams
2292
- );
2903
+ Object.assign(params, paramListToQuery(paramList));
2904
+ }
2905
+ return connector.route("feature_layer.feature.collection", { id: Number(resourceId) }).get({ query: __spreadValues$2(__spreadValues$2({}, params), query), cache, signal });
2293
2906
  }
2294
2907
 
2295
2908
  function prepareNgwFieldsToPropertiesFilter(fields) {
@@ -2442,7 +3055,7 @@ var Geocoder = (function (exports) {
2442
3055
  "The `searchUrl` of `connectorOptions.baseUrl` are required"
2443
3056
  );
2444
3057
  }
2445
- this.connector = options.connector || new NgwConnector(__spreadValues({
3058
+ this.connector = options.connector || new NgwConnectorExtended(__spreadValues({
2446
3059
  baseUrl: this.searchUrl
2447
3060
  }, options.connectorOptions));
2448
3061
  this.searchResources = options.searchResources;
@@ -2491,7 +3104,7 @@ var Geocoder = (function (exports) {
2491
3104
  yield item;
2492
3105
  }
2493
3106
  } catch (er) {
2494
- if (er && "name" in er && er.name !== "CancelError") {
3107
+ if (er && "name" in er && er.name !== "AbortError") {
2495
3108
  console.warn(er);
2496
3109
  }
2497
3110
  }
@@ -2500,14 +3113,10 @@ var Geocoder = (function (exports) {
2500
3113
  }
2501
3114
  result(item) {
2502
3115
  const signal = this._makeSignal();
2503
- const req = this.connector.get(
2504
- "feature_layer.feature.item_extent",
2505
- { signal },
2506
- {
2507
- id: item.resourceId,
2508
- fid: item.featureId
2509
- }
2510
- ).then((x) => {
3116
+ const req = this.connector.route("feature_layer.feature.item_extent", {
3117
+ id: item.resourceId,
3118
+ fid: item.featureId
3119
+ }).get({ signal }).then((x) => {
2511
3120
  const e = x.extent;
2512
3121
  return {
2513
3122
  text: item.text,
@@ -2594,56 +3203,69 @@ var Geocoder = (function (exports) {
2594
3203
  };
2595
3204
  class NominatimProvider extends BaseProvider {
2596
3205
  constructor(options) {
2597
- super(options);
3206
+ super();
3207
+ this.options = options;
2598
3208
  __publicField(this, "searchUrl", "https://nominatim.openstreetmap.org");
2599
- __publicField(this, "_abort", []);
3209
+ __publicField(this, "_abortControllers", []);
2600
3210
  if (options && options.searchUrl) {
2601
3211
  this.searchUrl = options.searchUrl;
2602
3212
  }
2603
3213
  }
2604
3214
  abort() {
2605
- this._abort.forEach((x) => x());
2606
- this._abort = [];
3215
+ this._abortControllers.forEach((controller) => {
3216
+ controller.abort();
3217
+ });
3218
+ this._abortControllers = [];
2607
3219
  }
2608
3220
  search(val) {
2609
3221
  return __asyncGenerator(this, null, function* () {
2610
- const url = fixUrlStr(
2611
- // `${this.baseUrl}/search?format=geojson&polygon_geojson=1${window.locale === 'ru' ? '&accept-language=ru-RU,en-US' : ''}&q=${val}`
2612
- `${this.searchUrl}/search?format=geojson&polygon_geojson=1&q=${val}`
2613
- );
2614
- const request = new Promise((resolve, reject) => {
2615
- const xhr = new XMLHttpRequest();
2616
- xhr.open("GET", url, true);
2617
- xhr.onload = () => {
2618
- try {
2619
- const geojson = JSON.parse(xhr.responseText);
2620
- const features = geojson.features.map((x) => {
2621
- return {
2622
- geom: x,
2623
- extent: x.bbox,
2624
- text: x.properties && x.properties.display_name,
2625
- query: val
2626
- };
2627
- });
2628
- resolve(features);
2629
- } catch (er) {
2630
- reject(er);
2631
- }
2632
- };
2633
- xhr.onerror = (er) => {
2634
- reject(er);
2635
- };
2636
- this._abort.push(xhr.abort);
2637
- xhr.send();
2638
- }).catch((er) => {
2639
- if (er.name === "CancelError") ;
2640
- throw er;
3222
+ var _a, _b, _c, _d, _e, _f, _g;
3223
+ const params = new URLSearchParams({
3224
+ format: "geojson",
3225
+ polygon_geojson: "1",
3226
+ q: val,
3227
+ limit: ((_b = (_a = this.options) == null ? void 0 : _a.limit) == null ? void 0 : _b.toString()) || "10"
2641
3228
  });
2642
- const items = yield new __await(request);
2643
- if (items) {
2644
- for (const i of items) {
2645
- i.result = () => this.result(i);
2646
- yield i;
3229
+ if ((_c = this.options) == null ? void 0 : _c.countrycodes) {
3230
+ params.append("countrycodes", this.options.countrycodes);
3231
+ }
3232
+ if ((_d = this.options) == null ? void 0 : _d.addressdetails) {
3233
+ params.append("addressdetails", "1");
3234
+ }
3235
+ if ((_e = this.options) == null ? void 0 : _e.language) {
3236
+ params.append("accept-language", this.options.language);
3237
+ }
3238
+ if ((_f = this.options) == null ? void 0 : _f.bounded) {
3239
+ params.append("bounded", "1");
3240
+ }
3241
+ if ((_g = this.options) == null ? void 0 : _g.viewbox) {
3242
+ const [minLon, minLat, maxLon, maxLat] = this.options.viewbox;
3243
+ params.append("viewbox", `${minLon},${minLat},${maxLon},${maxLat}`);
3244
+ }
3245
+ const url = fixUrlStr(`${this.searchUrl}/search?${params.toString()}`);
3246
+ const controller = new AbortController();
3247
+ this._abortControllers.push(controller);
3248
+ try {
3249
+ const response = yield new __await(fetch(url, { signal: controller.signal }));
3250
+ if (!response.ok) {
3251
+ throw new Error(`Network response was not ok: ${response.statusText}`);
3252
+ }
3253
+ const geojson = yield new __await(response.json());
3254
+ const features = geojson.features.map((x) => {
3255
+ return {
3256
+ geom: x,
3257
+ extent: x.bbox,
3258
+ text: x.properties && x.properties.display_name,
3259
+ query: val
3260
+ };
3261
+ });
3262
+ for (const item of features) {
3263
+ item.result = () => this.result(item);
3264
+ yield item;
3265
+ }
3266
+ } catch (error) {
3267
+ if (error.name === "AbortError") ; else {
3268
+ throw error;
2647
3269
  }
2648
3270
  }
2649
3271
  });
@@ -2657,41 +3279,41 @@ var Geocoder = (function (exports) {
2657
3279
  }
2658
3280
  reverse(coordinates) {
2659
3281
  return __asyncGenerator(this, null, function* () {
3282
+ var _a, _b;
2660
3283
  const [lng, lat] = coordinates;
2661
- const url = fixUrlStr(
2662
- `${this.searchUrl}/reverse?format=geojson&lat=${lat}&lon=${lng}`
2663
- );
2664
- const request = new Promise((resolve, reject) => {
2665
- const xhr = new XMLHttpRequest();
2666
- xhr.open("GET", url, true);
2667
- xhr.onload = () => {
2668
- try {
2669
- const geojson = JSON.parse(xhr.responseText);
2670
- const feature = geojson.features[0];
2671
- const result = {
2672
- geom: feature,
2673
- extent: feature.bbox,
2674
- text: feature.properties && feature.properties.display_name,
2675
- query: `${lat}, ${lng}`
2676
- };
2677
- resolve(result);
2678
- } catch (er) {
2679
- reject(er);
2680
- }
2681
- };
2682
- xhr.onerror = (er) => {
2683
- reject(er);
2684
- };
2685
- this._abort.push(xhr.abort);
2686
- xhr.send();
2687
- }).catch((er) => {
2688
- if (er.name === "CancelError") ;
2689
- throw er;
3284
+ const params = new URLSearchParams({
3285
+ format: "geojson",
3286
+ lat: lat.toString(),
3287
+ lon: lng.toString()
2690
3288
  });
2691
- const item = yield new __await(request);
2692
- if (item) {
3289
+ if ((_a = this.options) == null ? void 0 : _a.addressdetails) {
3290
+ params.append("addressdetails", "1");
3291
+ }
3292
+ if ((_b = this.options) == null ? void 0 : _b.language) {
3293
+ params.append("accept-language", this.options.language);
3294
+ }
3295
+ const url = fixUrlStr(`${this.searchUrl}/reverse?${params.toString()}`);
3296
+ const controller = new AbortController();
3297
+ this._abortControllers.push(controller);
3298
+ try {
3299
+ const response = yield new __await(fetch(url, { signal: controller.signal }));
3300
+ if (!response.ok) {
3301
+ throw new Error(`Network response was not ok: ${response.statusText}`);
3302
+ }
3303
+ const geojson = yield new __await(response.json());
3304
+ const feature = geojson.features[0];
3305
+ const item = {
3306
+ geom: feature,
3307
+ extent: feature.bbox,
3308
+ text: feature.properties && feature.properties.display_name,
3309
+ query: `${lat}, ${lng}`
3310
+ };
2693
3311
  item.result = () => this.result(item);
2694
3312
  yield item;
3313
+ } catch (error) {
3314
+ if (error.name === "AbortError") ; else {
3315
+ throw error;
3316
+ }
2695
3317
  }
2696
3318
  });
2697
3319
  }